node-workflows
Simple and fast implementation of action-driven workflows for Node.js written in TypeScript.
Install
npm install node-workflows --save
Usage
Import
var Workflows = ;
The TypeScript way:
;
Examples
Workflowsstart { // ACTION #0 console; // will be available in // 'previousValue' property // of the next action ctxnextValue = 'MK'; // result of the workflow ctxresult = 23979;} { // ACTION #1 console; // run "async" return { try // ctx.previousValue == 'MK' // ctx.result == 23979 ; catch e ; };} // ACTION #2 // use an object // with an 'execute()' method // instead a function { console; // ctx.previousValue == 'TM' // ctx.result == 23979 // ctx.value == 19861222 (at first time) // ctx.value == 1781 (at 2nd time) ctxresult = 5979; // set a result value // for the workflow } { // ACTION #3 console; // ctx.previousValue == undefined // ctx.result == 5979 if 1781 !== ctxvalue // ctx.value == 19861222 ctxvalue = 1781; // mark 'ACTION #2' // as next action ctx; };
Jump / skip
var workflow = Workflows; workflow; workflowstart;
Logging
var workflow = Workflows; // add loggers by function ...workflow;// ... and by objectworkflow; workflowstart;
Share values
// create workflow WITHOUT starting itvar newWorkflow = Workflows; // STARTnewWorkflowstart'PZ';
States
// WORKFLOW #1Workflowsstart { // will be available for all // actions while the current execution ctxglobals'action0' = 'MK'; // is availabe ONLY FOR THIS ACTION // and is availabe while the execution // of the underlying workflow ctxstate = 23979; // will be available for all // actions of all workflows // and is stored permanent ctxpermanentGlobals'workflow1_action0' = 'A global value';} { // ACTION #1 // ctx.globals.action0 == 'MK'; // ctx.state == undefined ctxstate = 5979; //TODO}; // WORKFLOW #2Workflowsstart { // ctx.permanentGlobals['workflow1_action0'] == 'A global value'};
Events
var workflow = Workflows; // workflow events ...workflow;workflow;workflow;workflow;workflow;workflow;workflow;workflow;workflow;workflow;workflow;workflow; // custom events for the executionworkflownext { // <= alias for 'then()' // ACTION #1 // invokes event in 'ACTION #0' ctxevents; ctxevents;}next { // ACTION #2 ctxevents; // invokes event in 'ACTION #1' ctxevents; // DOES NOT invoke event in 'ACTION #1' // because it has already been invoked // s. below ctxglobalEvents; ctxglobalEvents; // not invoked ctxworkflowEvents; ctxworkflowEvents;}; // a global eventWorkflowsEVENTS; // a custom workflow eventworkflow; // STARTworkflowstart;
Other information
Workflowsstart { // ctx.count => the total number of all actions of that workflow // ctx.current => the context of the current executing action // ctx.executions => the number of action executions // ctx.index => zero based index of THAT ACTION // ctx.isBetween => is between first AND last action or not // ctx.isFirst => is FIRST action or not // ctx.isLast => is LAST action or not // ctx.previousEndTime => the end time of the PREVIOUS action // ctx.previousIndex => zero based index of the PREVIOUS action // ctx.previousStartTime => the start time of the PREVIOUS action // ctx.startTime => the start time of the workflow // ctx.time => the start time of that action // ctx.workflowExecutions => the number workflow executions};
Documentation
The full API documentation can be found here.