Comparing version 0.1.7 to 0.1.8
@@ -61,4 +61,5 @@ var async = require('async'); | ||
if(taskArgs instanceof SubFlow) { | ||
var subFlow = taskArgs; | ||
var interpretSubFlow = function(subFlow){ | ||
if(fn) throw new FlowTaskError(taskName, "A task may have a SubFlow (index " + i + ") or a function call (index " + i + "), but not both. " + fnIndex + " and " + i + ")."); | ||
if(Array.isArray(taskArgs) && i < taskArgs.length - 1) throw new FlowTaskError(taskName, "SubFlows must be the at the last index."); | ||
if(!tasks.hasOwnProperty(subFlow.dataName) && (!data || !data.hasOwnProperty(subFlow.dataName)) || subFlow.dataName == taskName) throw new FlowTaskError(taskName, "SubFlow data '" + subFlow.dataName + "' does not exist. Provide the name of a task or data from the parent flow. Possible values include: " + Object.keys(tasks).concat(Object.keys(data)).filter(function(name){ return name != taskName }).join(', ')); | ||
@@ -69,2 +70,6 @@ fn = { receiverName: subFlow.dataName, tasks: subFlow.tasks }; | ||
autoTask = autoTask.concat(Object.keys(prereqs)); | ||
} | ||
if(taskArgs instanceof SubFlow) { | ||
interpretSubFlow(taskArgs); | ||
} else if(typeof taskArgs == 'function') { | ||
@@ -80,20 +85,21 @@ fn = taskArgs; | ||
} else if(taskArg instanceof SubFlow) { | ||
var subFlow = taskArg; | ||
if(fn) throw new FlowTaskError(taskName, "A task may have a SubFlow (index " + i + ") or a function call (index " + i + "), but not both. " + fnIndex + " and " + i + ")."); | ||
if(i < taskArgs.length - 1) throw new FlowTaskError(taskName, "SubFlows must be the at the last index."); | ||
if(!tasks.hasOwnProperty(subFlow.dataName) && (!data || !data.hasOwnProperty(subFlow.dataName)) || subFlow.dataName == taskName) throw new FlowTaskError(taskName, "SubFlow data '" + subFlow.dataName + "' does not exist. Provide the name of a task or data from the parent flow. Possible values include: " + Object.keys(tasks).concat(Object.keys(data)).filter(function(name){ return name != taskName }).join(', ')); | ||
fn = { receiverName: subFlow.dataName, tasks: subFlow.tasks }; | ||
interpretSubFlow(taskArg); | ||
fnIndex = i; | ||
var prereqs = scanForPrereqs(subFlow.tasks, us.extend({}, data, tasks)); | ||
autoTask.push(subFlow.dataName); | ||
autoTask = autoTask.concat(Object.keys(prereqs)); | ||
} else if((tasks.hasOwnProperty(taskArg) || data && data.hasOwnProperty(taskArg) || context && context.hasOwnProperty(taskArg) && typeof context[taskArg] != 'function') && taskArg != taskName) { | ||
if(fn) args.push(taskArg); | ||
autoTask.push(taskArg); | ||
} else { | ||
if(fn) throw new FlowTaskError(taskName, "More than one function specified (at index " + fnIndex + " and " + i + ")."); | ||
fn = { name: taskArg, receiverName: taskArgs[i - 1] }; | ||
fnIndex = i; | ||
if(!fn.receiverName) throw new FlowTaskError(taskName, "Unknown symbol at index '" + i + "' must be either the name of a task, the name of data, or be the name of a function on the result of a task or data"); | ||
} | ||
} else if(typeof taskArg == 'string') { | ||
var taskArgParts = taskArg.split('.'); | ||
taskArg = taskArgParts[0]; | ||
if((tasks.hasOwnProperty(taskArg) || data && data.hasOwnProperty(taskArg) || context && context.hasOwnProperty(taskArg) && typeof context[taskArg] != 'function') && taskArg != taskName) { | ||
if(fn) args.push(taskArgParts); | ||
else if(taskArgParts.length > 1) { | ||
fn = { name: taskArgParts.pop(), receiverName: taskArgParts }; | ||
fnIndex = i; | ||
} | ||
autoTask.push(taskArg); | ||
} else if(fn) throw new FlowTaskError(taskName, "More than one function specified (at index " + fnIndex + " and " + i + ")."); | ||
else if(taskArgParts.length > 1 || !taskArgs[i - 1]) throw new FlowTaskError(taskName, "Unknown symbol at index '" + i + "' must be either the name of a task, the name of data, or be the name of a function on the result of a task or data"); | ||
else { | ||
fn = { name: taskArg, receiverName: taskArgs[i - 1] }; | ||
fnIndex = i; | ||
} | ||
} else throw new FlowTaskError(taskName, "Unknown symbol at index '" + i + "' must be either the name of a task, the name of data, or be the name of a function on the result of a task or data"); | ||
} | ||
@@ -123,3 +129,3 @@ if(!fn) throw new FlowTaskError(taskName, "Function required."); | ||
return newDataItem; | ||
}); | ||
}); | ||
} else { | ||
@@ -136,3 +142,9 @@ var newData = us.extend({}, results); | ||
var arg = args[i]; | ||
fnArgs[i] = results[arg]; | ||
if(Array.isArray(arg)) { | ||
var result = results; | ||
arg.forEach(function(arg){ | ||
result = result[arg]; | ||
}); | ||
fnArgs[i] = result; | ||
} else fnArgs[i] = results[arg]; | ||
} | ||
@@ -174,4 +186,7 @@ fnArgs.push(cb); | ||
} else if(typeof taskArg == 'function') { | ||
} else if(allTasks.hasOwnProperty(taskArg)) { | ||
prereqs[taskArg] = true; | ||
} else if(typeof taskArg == 'string') { | ||
taskArg = taskArg.split('.')[0]; | ||
if(allTasks.hasOwnProperty(taskArg)) { | ||
prereqs[taskArg] = true; | ||
} | ||
} else { | ||
@@ -178,0 +193,0 @@ } |
@@ -6,3 +6,3 @@ { | ||
"author": "David Fenster <david@dfenster.com>", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"repository": { | ||
@@ -9,0 +9,0 @@ "type": "git", |
@@ -77,3 +77,3 @@ var util = require('util'); | ||
Genre.all = { | ||
1: us.extend(new Genre(), {id: 1, name: "Fantasy"}), | ||
1: us.extend(new Genre(), {id: 1, name: "Fantasy", book_ids: [7,8,9,10,11]}), | ||
2: us.extend(new Genre(), {id: 2, name: "Romance"}), | ||
@@ -308,3 +308,45 @@ 3: us.extend(new Genre(), {id: 3, name: "Fiction"}), | ||
module.exports["instance task execution with dot notation parameter"] = function(test){ | ||
flow({ | ||
authorName: 'Dan Brown', | ||
genreName: 'Fiction' | ||
}, { | ||
getAuthor: [Author.getByName, 'authorName'], | ||
getGenre: [Genre.getByName, 'genreName'], | ||
getBooks: ['getGenre', 'findBooksByAuthor', 'getAuthor.id'] | ||
}, function(err, results){ | ||
test.ok(!err); | ||
test.deepEqual(results, { | ||
authorName: 'Dan Brown', | ||
genreName: 'Fiction', | ||
getAuthor: Author.all[4], | ||
getGenre: Genre.all[3], | ||
getBooks: [Book.all[6]] | ||
}); | ||
test.done(); | ||
}); | ||
} | ||
module.exports["instance task execution with dot notation function"] = function(test){ | ||
flow({ | ||
authorName: 'Dan Brown', | ||
genreName: 'Fiction' | ||
}, { | ||
getAuthor: [Author.getByName, 'authorName'], | ||
getGenre: [Genre.getByName, 'genreName'], | ||
getBooks: ['getGenre.findBooksByAuthor', 'getAuthor'] | ||
}, function(err, results){ | ||
test.ok(!err); | ||
test.deepEqual(results, { | ||
authorName: 'Dan Brown', | ||
genreName: 'Fiction', | ||
getAuthor: Author.all[4], | ||
getGenre: Genre.all[3], | ||
getBooks: [Book.all[6]] | ||
}); | ||
test.done(); | ||
}); | ||
} | ||
module.exports["multiple asyncronus tasks with prerequisite task execution"] = function(test){ | ||
@@ -335,3 +377,3 @@ flow( [ | ||
getAuthor: { id: 1, name: 'Patricia Briggs' }, | ||
getGenre: { id: 1, name: 'Fantasy' }, | ||
getGenre: Genre.all[1], | ||
assertGenreExistence: true, | ||
@@ -396,3 +438,3 @@ getBooks: [] }] | ||
getAuthor: { id: 1, name: 'Patricia Briggs' }, | ||
getGenre: { id: 1, name: 'Fantasy' }, | ||
getGenre: Genre.all[1], | ||
assertGenreExistence: true, | ||
@@ -869,2 +911,36 @@ getBooks: [] } | ||
module.exports["subflow with prereqs and dot notation"] = function(test){ | ||
flow({ | ||
genreName: 'Fantasy', | ||
authorName: 'Barbara Hambly' | ||
}, { | ||
getGenre: [Genre.getByName, 'genreName'], | ||
getBooksByGenre: ['getGenre', 'getBooks'], | ||
getAuthors: flow.subFlow('getBooksByGenre', { | ||
getHambly2: [Author.getById, 'getHambly.id'] | ||
}), | ||
getHambly: [Author.getByName, 'authorName'] | ||
}, function(err, results){ | ||
test.ok(!err, 'no error'); | ||
test.deepEqual(results, { | ||
genreName: 'Fantasy', | ||
authorName: 'Barbara Hambly', | ||
getGenre: Genre.all[1], | ||
getBooksByGenre: [Book.all[7], Book.all[8], Book.all[9], Book.all[10], Book.all[11]], | ||
getHambly: Author.all[6], | ||
getAuthors: [{ | ||
getHambly2: Author.all[6] | ||
}, { | ||
getHambly2: Author.all[6] | ||
}, { | ||
getHambly2: Author.all[6] | ||
}, { | ||
getHambly2: Author.all[6] | ||
}, { | ||
getHambly2: Author.all[6] | ||
}] | ||
}); | ||
test.done(); | ||
}); | ||
} | ||
@@ -1108,3 +1184,34 @@ module.exports["subflow with empty name"] = function(test){ | ||
module.exports["subflow with dot notation for parameter"] = function(test){ | ||
flow({ | ||
genreName: 'Fantasy' | ||
}, { | ||
getGenre: [Genre.getByName, 'genreName'], | ||
getBooksByGenre: ['getGenre', 'getBooks'], | ||
getAuthors: flow.subFlow('getBooksByGenre', { | ||
getBookAuthor: [Author.getById, 'getBooksByGenre.authorId'] | ||
}) | ||
}, function(err, results){ | ||
test.ok(!err, 'no error'); | ||
test.deepEqual(results, { | ||
genreName: 'Fantasy', | ||
getGenre: Genre.all[1], | ||
getBooksByGenre: [Book.all[7], Book.all[8], Book.all[9], Book.all[10], Book.all[11]], | ||
getAuthors: [{ | ||
getBookAuthor: Author.all[6] | ||
}, { | ||
getBookAuthor: Author.all[6] | ||
}, { | ||
getBookAuthor: Author.all[5] | ||
}, { | ||
getBookAuthor: Author.all[5] | ||
}, { | ||
getBookAuthor: Author.all[5] | ||
}] | ||
}); | ||
test.done(); | ||
}); | ||
} | ||
// module.exports["array result data execution"] = function(test){ | ||
@@ -1111,0 +1218,0 @@ // var authors, fantasyAuthors; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57194
1370