Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Commit 1abb7d2

Browse files
committed
support for composer 0.3.0 and composer.mask
Fixes #904
1 parent fc15e8b commit 1abb7d2

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-1
lines changed

app/plugins/modules/composer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"license": "Apache-2.0",
1414
"dependencies": {
15-
"@ibm-functions/composer": "^0.2.2",
15+
"@ibm-functions/composer": "^0.3.0",
1616
"chokidar": "^2.0.3"
1717
}
1818
}

app/plugins/modules/editor/lib/languages/composer-javascript.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ const strings = {
4444
detail: 'var=value; task1 -> task2',
4545
args: ['variable', 'value', 'task1', 'task2']
4646
},
47+
mask: {
48+
documentation: 'Execute a given composition masking any enclosing variable bindings',
49+
detail: 'mask enclosing variable bindings',
50+
args: ['composition']
51+
},
4752
while: {
4853
documentation: 'While a condition holds, execute a task',
4954
detail: 'while (cond) task',

app/plugins/modules/wskflow/lib/fsm2graph.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,23 @@ function ir2graph(ir, gm, id, prevId, options={}){ // ir and graph model
486486
let lastBodyNode = ir2graph(ir.body, gm, `${id}-body`, prevId, undefined, options);
487487
return ir2graph(ir.finalizer, gm, `${id}-finalizer`, lastBodyNode, undefined, options);
488488
}
489+
else if(typeof ir.body === 'object'){
490+
// generic handler for any subgraph-via-body node
491+
const body = drawNodeNew(id, ir.type, ir.type, undefined, options)
492+
body.children = []
493+
body.edges = []
494+
gm.children.push(body);
495+
496+
if(prevId)
497+
prevId.forEach(pid => gm.edges.push(drawEdgeNew(pid, id, gm)));
498+
499+
ir2graph(ir.body, body, `${id}-body`, undefined, options)
500+
501+
return [id]
502+
503+
} else {
504+
console.error('wskflow warning! unsupported node type', ir)
505+
}
489506
}
490507
}
491508

tests/data/composer-source/mask.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
composer.mask(composer.sequence('echo1', 'echo2'))

tests/tests/passes/07/composer-viz.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const fsm = input('fsm.json'), fsmStruct = JSON.parse(fs.readFileSync(fsm.path).
4646
retry5Times = composerInput('retry-5-times.js'),
4747
demo = composerInput('demo.js'),
4848
demoRetain = composerInput('demo-retain.js'),
49+
mask = composerInput('mask.js'),
4950
addSubscription = composerErrorInput('addSubscription.js')
5051

5152
/**
@@ -228,6 +229,14 @@ describe('show the composer visualization without creating openwhisk assets', fu
228229
.then(verifyOutgoingEdgeExists('DivideByTwo'))
229230
.catch(common.oops(this)))
230231

232+
/** test: from the openwhisk-composer/samples directory */
233+
it(`show visualization from javascript source ${mask.path}`, () => cli.do(`app viz ${mask.path}`, this.app)
234+
.then(verifyTheBasicStuff(mask.file, 'composerLib'))
235+
.then(verifyNodeExists('echo1'))
236+
.then(verifyNodeExists('echo2'))
237+
.then(verifyEdgeExists('echo1', 'echo2'))
238+
.catch(common.oops(this)))
239+
231240
it(`fail to show visualization for addSubscription without -e for env var assignment`, () => cli.do(`preview ${addSubscription.path}`, this.app)
232241
.then(cli.expectError(0, 'SLACK_TOKEN required in environment'))
233242
.catch(common.oops(this)))

0 commit comments

Comments
 (0)