Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: guidesmiths/worksmith
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: db75bcc5efa15005a7a35645470735f8523702aa
Choose a base ref
...
head repository: guidesmiths/worksmith
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8df693ee6553718e8e854d83a6981c4380613543
Choose a head ref

Commits on Jul 2, 2015

  1. Copy the full SHA
    b2aa04e View commit details
  2. 0.2.0

    PeterAronZentai committed Jul 2, 2015
    Copy the full SHA
    c6e5928 View commit details

Commits on Jul 5, 2015

  1. Copy the full SHA
    bfefc83 View commit details
  2. Copy the full SHA
    77210f3 View commit details
  3. Copy the full SHA
    99c2136 View commit details
  4. Copy the full SHA
    0999674 View commit details
  5. Copy the full SHA
    cc91732 View commit details
  6. 0.2.1

    PeterAronZentai committed Jul 5, 2015
    Copy the full SHA
    875a15f View commit details

Commits on Jul 6, 2015

  1. Copy the full SHA
    d8e9e8a View commit details

Commits on Jul 7, 2015

  1. Copy the full SHA
    a02a6d1 View commit details
  2. Copy the full SHA
    2a152b5 View commit details
  3. Copy the full SHA
    0792852 View commit details
  4. 0.2.2

    PeterAronZentai committed Jul 7, 2015
    Copy the full SHA
    d317c9a View commit details

Commits on Jul 8, 2015

  1. Copy the full SHA
    132cd0a View commit details
  2. 0.2.3

    PeterAronZentai committed Jul 8, 2015
    Copy the full SHA
    3aa138b View commit details
  3. Update README.md

    PeterAronZentai committed Jul 8, 2015
    Copy the full SHA
    e513ddb View commit details
  4. 0.2.4

    PeterAronZentai committed Jul 8, 2015
    Copy the full SHA
    783920e View commit details

Commits on Jul 9, 2015

  1. Copy the full SHA
    6a7aa5f View commit details
  2. Copy the full SHA
    4a6bc16 View commit details
  3. 0.2.5

    PeterAronZentai committed Jul 9, 2015
    Copy the full SHA
    a1a3ed7 View commit details

Commits on Jul 13, 2015

  1. Copy the full SHA
    60a42bd View commit details
  2. 0.2.6

    feliun committed Jul 13, 2015
    Copy the full SHA
    adb5bd0 View commit details
  3. Copy the full SHA
    ab4c2c7 View commit details
  4. 0.2.7

    feliun committed Jul 13, 2015
    Copy the full SHA
    0245e52 View commit details

Commits on Jul 14, 2015

  1. Copy the full SHA
    7e8cb32 View commit details
  2. Copy the full SHA
    19da0b5 View commit details

Commits on Jul 15, 2015

  1. Copy the full SHA
    9734bfb View commit details

Commits on Jul 16, 2015

  1. Copy the full SHA
    d3373e1 View commit details
  2. Copy the full SHA
    62c381b View commit details

Commits on Jul 17, 2015

  1. Copy the full SHA
    3a42089 View commit details
  2. Copy the full SHA
    70d6c35 View commit details

Commits on Aug 18, 2015

  1. Copy the full SHA
    ee21d8e View commit details
  2. replace crlf to lf

    PeterAronZentai committed Aug 18, 2015
    Copy the full SHA
    1b74e72 View commit details
  3. 0.2.8

    PeterAronZentai committed Aug 18, 2015
    Copy the full SHA
    f40e8b1 View commit details

Commits on Aug 27, 2015

  1. Copy the full SHA
    68437ae View commit details

Commits on Feb 29, 2016

  1. Copy the full SHA
    b1e2339 View commit details
  2. 0.2.10

    PeterAronZentai committed Feb 29, 2016
    Copy the full SHA
    f9ffa94 View commit details

Commits on Jan 22, 2019

  1. Copy the full SHA
    1dad0c1 View commit details
  2. Update code with latest lodash

    gabceb committed Jan 22, 2019
    Copy the full SHA
    f58780f View commit details
  3. Copy the full SHA
    5848bc7 View commit details

Commits on Feb 8, 2019

  1. Merge pull request #16 from gabceb/master

    Update dependencies due to security vulnerabilities
    John Hustler authored Feb 8, 2019
    Copy the full SHA
    9aa31f9 View commit details

Commits on Feb 25, 2019

  1. Updated depenencies

    Stephen Cresswell committed Feb 25, 2019
    Copy the full SHA
    32b1649 View commit details
  2. 1.0.0

    Stephen Cresswell committed Feb 25, 2019
    Copy the full SHA
    8df693e View commit details
2 changes: 2 additions & 0 deletions Interpolation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#worksmith interpolation guide

23 changes: 22 additions & 1 deletion ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
# Worksmith release notes
## 0.2.3
An array in place of a task or workflow variable means an implicit "sequence" task
```javascript
var wf = worksmith([
{ task: "set", name:"p1", value:"hello" },
{ task:"log" },
{ task:"eachSeries", item:[1,2,3], subflow: [
{ task:"log" message:"@item" },
{task:"delay", duration:"[eval]item * 250[/eval]" }
]}
]);
wf({}, function(err, res) { });
```

## 0.2.2
Totally revamped interpolation logic, deep tree interpolation, array interpolation

tag support to drive interpolation mode: {{hbs}} and {{eval}} are support out of the box

## 0.1.7
eachSeriesActivity and whileActivity

## 0.1.5
Terminate a workflow or sequence from code (a programmable alternative to conditional="predicate" attribute)
@@ -41,4 +62,4 @@ connect existing functionality into a workflow using worksmith.use + worksmith.c
assert.equal(context.myresult[0], context.items[0])
done();
});
```
```
113 changes: 53 additions & 60 deletions index.js
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@ var settings = {
logger: console
}

var interpolate = require('./src/interpolation').interpolate

var worksmith

function wfLoader(wf) {
@@ -23,6 +25,12 @@ function wfLoader(wf) {
debug("loading workflow file: %s", wf)
wf = require(wf);
}
if(Array.isArray(wf)) {
wf = {
task: "sequence",
items: wf
}
}
return worksmith.define(wf);
}

@@ -31,8 +39,8 @@ worksmith = wfLoader
function getStepName(step) {
if (step.name) { return step.name }
var name = step.name || step.task;
if ("function" === typeof name) {
name = "<Anonymous>" + name.name
if ("function" === typeof name) {
name = "<Anonymous>" + name.name
}
return step.name = name;
}
@@ -42,17 +50,14 @@ var workflow = {
use: function(ns, taskLibrary) {
resolvers[ns] = taskLibrary;
},

createAdapter: function(object) {
return function getType(name) {
var method = object[name];
return function define(step) {
return function build(context) {
return function execute(done) {
var args = (context.get(step.arguments) || [])
.map(function(arg) {
return context.get(arg);
})
var result = method.apply(object, args)
done(undefined, result);
}
@@ -61,9 +66,13 @@ var workflow = {
}
},
configure: function(options) {
_.extend(settings, options);
_.assignIn(settings, options);
},


hasLogLevel: function(level) {
return settings.logger[level] !== undefined
},

log: function() {
var level = arguments[0]
settings.logger[level].apply(settings.logger, Array.prototype.slice.call(arguments,1))
@@ -89,8 +98,8 @@ var workflow = {
if ("string" === typeof task) return workflow.getTaskType(task);
return task;
},



define: function (workflowDefinition) {

@@ -115,11 +124,11 @@ var workflow = {

function initializeContext(context) {
if (!context.initialized) {
context.get = function(name) {
return workflow.readValue(name, context)
context.get = function(name, interpolate) {
return workflow.readValue(name, this, interpolate)
},
context.set = function(name, value) {
return workflow.setValue(context, name, value)
return workflow.setValue(this, name, value)
}
context.initialized = true;
}
@@ -132,11 +141,17 @@ var workflow = {
var annotations = execute.annotations || build.annotations || WorkflowType.annotations;
annotations = annotations || {};
execute.inject && (annotations.inject = execute.inject);
annotations.inject && annotations.inject.forEach(function(name) {
annotations.inject && annotations.inject.forEach(function(injectable) {
if ("string" === typeof injectable) {
injectable = {
name: injectable,
interpolationPolicy: true,
}
}
var arg;
switch(name[0]) {
case '@': arg = context.get(name); break;
default: arg = context.get(workflowDefinition[name]); break;
switch(injectable.name[0]) {
case '@': arg = context.get(injectable.name); break;
default: arg = context.get(workflowDefinition[injectable.name],injectable.interpolationPolicy); break;
}
args.push(arg)
})
@@ -151,7 +166,7 @@ var workflow = {
initializeContext(context)
var decorated = wfInstance(context)
debug("preparing: %s", getStepName(workflowDefinition))


var markWorkflowTerminate = function(done) {
context.completionStack = context.completionStack || []
@@ -161,15 +176,15 @@ var workflow = {
}
}


return function execute(done) {
var wfStartTime = new Date().getTime()


if (!checkCondition(context))
return done()

markWorkflowTerminate(done)

function invokeDecorated(err, res, next) {
function createExecutionThisContext() {
return {
@@ -187,7 +202,7 @@ var workflow = {
}
}
}

var args = getArgumentsFromAnnotations(context, decorated, wfInstance)
args.push(next)
try {
@@ -202,7 +217,7 @@ var workflow = {
var errorWfDef = context.get(workflowDefinition.onError);
var errorWf = workflow.define(errorWfDef);
context.error = err;
errorWf(context, function(errHandlerErr, errRes) {
errorWf(context, function(errHandlerErr, errRes) {
if (errorWfDef.handleError) err = errHandlerErr;
next(err, res);
})
@@ -225,14 +240,14 @@ var workflow = {
}
next(err, result)
}

function setWorkflowResultTo(err, result, next) {
if (err) { return next(err, result) }
process.env.WSDEBUGPARAMS && debug("...result is", result)
context.set(workflowDefinition.resultTo, result)
next(err, result)
}

function buildUpMicroworkflow() {
var tasks = [invokeDecorated];
workflowDefinition.onError && tasks.push(onError)
@@ -243,56 +258,34 @@ var workflow = {
}

var tasks = buildUpMicroworkflow();

function executeNextThunkOrComplete(err, res) {
var thunk = tasks.shift();
if (thunk) {
return thunk( err, res, executeNextThunkOrComplete)
}

debug("Finished executing WF %s", getStepName(workflowDefinition))
if (context.$$$stats) {
context.$$$stats.push(getStepName(workflowDefinition) + " execution time: " + (new Date().getTime() - wfStartTime) +"ms")
}
var originalDone = context.originalTerminate || done;
var donePosition = context.completionStack.indexOf(originalDone);
context.completionStack.splice(donePosition, 1)
done(err, res, context)
setImmediate(function() {
done(err, res, context)
})
}

debug("Executing WF %s", getStepName(workflowDefinition))
return executeNextThunkOrComplete()

}
}
},

readContextPath: function (context, path) {
path = path.replace(/\[/g, ".").replace(/\]/g, "")
var parts = path.split('.');
var data = context;
var part;

while (part = parts.shift()) {
data = data[part];
if (data === undefined) {
return undefined;
}
}

return data;
},

readValue: function (pathOrValue, context) {
if ("@" == pathOrValue) return context;

if ("string" === typeof pathOrValue && pathOrValue[0] == '@') {
return module.exports.readContextPath(context, pathOrValue.slice(1))
}

if ("object" === typeof pathOrValue && "template" in pathOrValue) {
var template = pathOrValue.template;
var compiled = handlebars.compile(template);
return compiled(context);
}
return pathOrValue;
readValue: function(pathOrValue, context, interpolationPolicy) {
return interpolate(context, pathOrValue, interpolationPolicy)
},

setValue: function (object, path, value) {
@@ -313,6 +306,6 @@ var workflow = {
}


_.extend(wfLoader, workflow);
_.assignIn(wfLoader, workflow);

module.exports = wfLoader;
Loading