Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var testFunction = function(book, cb){
cb(new errors.ArgumentNull('book'));
};
var testFunction = function(book, cb){
cb(new errors.ArgumentNull('book'));
};
var Task = module.exports = function(fn, args){
if(!fn) throw new errors.ArgumentNull('fn');
if(!/^(string|function)$/.test(typeof fn)) throw new TypeError('Task fn must be a string or a function');
args = Array.prototype.slice.call(arguments, 1);
for(var i=0; i
Flow.prototype.execute = function execute(data, callback) {
if(arguments.length == 1) {
callback = data, data = {};
}
if(!callback) throw new errors.ArgumentNull('callback');
return Execution.launch(this, data, callback);
}
var cb = function(err, result){
if(err && err.name == "ArgumentNullError" && flow.tasks[err.argumentName]) err.message = "Not Found: " + flow.tasks[err.argumentName].toString(results)
if(err) return callback(err);
if(arguments.length > 2) result = Array.prototype.slice.call(arguments, 1);
return Task.complete.call(task, result, results, callback);
};
var fnArgs;
try {
//we will generate the list of args to apply to the fn.
fnArgs = plan.args.map(function(arg){
return evalMessages(results, arg, self.name);
});
} catch(e) {
if(e.name == "FlowTaskArgumentNullError") {
e = new errors.ArgumentNull(e.receiver_name);
e.message = "Not Found During Flow: " + flow.tasks[self.name].toString(results, e.argumentName);
}
return callback(e);
}
if(!self.is_sync) fnArgs.push(cb);
var fn = plan.fn;
var receiver;
if(typeof plan.fn != 'function') {
var fnName = plan.fn.name;
var receiverName = plan.fn.receiverName;
try {
receiver = evalMessages(results, receiverName, self.name);
} catch(e) {
if(e.name == "FlowTaskArgumentNullError") e.message = "Not Found During Flow: " + self.tasks[self.name].toString(results, e.argumentName);
return callback(e);
var Execution = module.exports = function Execution(flow, data) {
if(!flow) throw new errors.ArgumentNull('flow');
if(!data) throw new errors.ArgumentNull('data');
this.flow = flow;
this.data = data;
var context = this.context = flow.parent ? data[flow.context_name] : null;
}
Execution.launch = function launch(flow, data, callback) {
if(!flow) return new errors.ArgumentNull('flow');
if(!data) return new errors.ArgumentNull('data');
if(data instanceof Array) {
var execs = data.map(function(data, cb){ return new Execution(flow, data); });
return async.map(execs, function(e, cb){ e.exec(cb); }, callback);
} else {
return new Execution(flow, data).exec(callback);
}
}
self._initialize = function _initialize(){
if(self.parent) {
if(!context_name) throw new errors.ArgumentNull('context_name');
} else {
if(args.length == 1) tasks = context_name, context_name = undefined;
}
self.context_name = context_name;
self.tasks = us.extend(self.tasks, tasks || {});
self._initialize_tasks();
}
}
if(!self.is_sync) fnArgs.push(cb);
var fn = plan.fn;
var receiver;
if(typeof plan.fn != 'function') {
var fnName = plan.fn.name;
var receiverName = plan.fn.receiverName;
try {
receiver = evalMessages(results, receiverName, self.name);
} catch(e) {
if(e.name == "FlowTaskArgumentNullError") e.message = "Not Found During Flow: " + self.tasks[self.name].toString(results, e.argumentName);
return callback(e);
}
if(!receiver) {
var err = new errors.ArgumentNull(receiverName.join('.'));
if(flow.tasks[receiverName[0]]) err.message = "Not Found: " + flow.tasks[receiverName[0]].toString(results, err.argumentName);
return callback(err)
}
fn = receiver[fnName];
if(!fn) return callback(new FlowTaskError(self.name, "Unknown symbol '" + fnName + "' must be either the name of a task, the name of data, or the name of a function on '" + receiverName + "'"));
if(typeof fn != 'function') return callback(new FlowTaskError(self.name, "Not a function: " + (receiverName.length ? (receiverName.join('.') + ".") : '') + fnName));
}
try {
var return_value = fn.apply(receiver, fnArgs);
if(self.is_sync) cb(null, return_value);
} catch(e){
return callback(new FlowTaskError(self.name, "Error during execution of function.", e));
}
});
Task.prototype.requires = function requires(task_names) {
if(!task_names) throw new errors.ArgumentNull('task_names');
if(typeof task_names == 'string') this._explicit_reqs.push(task_names);
else if(task_names instanceof Array) Array.prototype.push.apply(this._explicit_reqs, task_names);
return this;
}