Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fnflow

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fnflow - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

15

lib/fnFlow.js

@@ -18,9 +18,16 @@ var async = require('async');

var newTasks;
if(data) newTasks = us.object(Object.keys(data), us.map(Object.keys(data), function(key){ return function(cb){ cb(null, data[key]); } }))
if(tasks) us.extend(newTasks, us.object(Object.keys(tasks), us.map(Object.keys(tasks), function(key){ return flowCall(tasks[key], key, tasks, data); } )));
return async.auto(newTasks, callback);
if (data instanceof Array) {
return async.map(data, function (dataItem, cb) {flowGo(dataItem, tasks, cb)}, callback);
} else {
return flowGo(data, tasks, callback);
}
}
}
var flowGo = function flowGo(data, tasks, callback) {
var newTasks;
if(data) newTasks = us.object(Object.keys(data), us.map(Object.keys(data), function(key){ return function(cb){ cb(null, data[key]); } }))
if(tasks) us.extend(newTasks, us.object(Object.keys(tasks), us.map(Object.keys(tasks), function(key){ return flowCall(tasks[key], key, tasks, data); } )));
return async.auto(newTasks, callback);
}

@@ -27,0 +34,0 @@ var flowCall = function flowCall(taskArgs, taskName, tasks, data) {

@@ -6,3 +6,3 @@ {

"author": "David Fenster <david@dfenster.com>",
"version": "0.0.2",
"version": "0.1.0",
"repository": {

@@ -44,2 +44,2 @@ "type": "git",

}
}
}

@@ -26,6 +26,5 @@ fnFlow

* data - An optional object literal containing a set of static data. The key used for each data value is used when specifying parameters in tasks.
* tasks - An object literal containing named functions or named arrays of
parameters or requirements, with the function itself somewhere in the array. Specify requirements to the left of the function and parameters to the right. The key used for each function or array is used when specifying parameters or requirements to other tasks. When called, the task function receives the results of the named parameters as arguments as well as a final callback(err, result) argument which must be called when finished, passing an error (which can be null) and the result of the function's execution. The task function may optionally be the name of a function to perform on the result of the last named requirement (the item directly to the left).
* callback(err, results) - An optional callback which is called when all the
* data (optional) - Either an object literal containing a set of static data, or an array of such objects. The key used for each data value is used when specifying parameters in tasks. If an array is specified, the tasks will execute in parallel for each data item in the array, and the callback will be passed an array or results.
* tasks - An object literal containing named functions or named arrays of parameters or requirements, with the function itself somewhere in the array. Specify requirements to the left of the function and parameters to the right. The key used for each function or array is used when specifying parameters or requirements to other tasks. When called, the task function receives the results of the named parameters as arguments as well as a final callback(err, result) argument which must be called when finished, passing an error (which can be null) and the result of the function's execution. The task function may optionally be the name of a function to perform on the result of the last named requirement (the item directly to the left).
* callback(err, results) (optional) - An optional callback which is called when all the
tasks have been completed. The callback will receive an error as an argument

@@ -97,2 +96,26 @@ if any tasks pass an error to their callback. Results will always be passed

__Running Multple Sets of Tasks in Parallel__
```js
fnFlow.flow([
{ authorName: 'Brandon Sanderson',
genreName: 'Fantasy'
},
{ authorName: 'Jack Vance',
genreName: 'Fantasy'
}
], {
getAuthor: [Author.getByName, 'authorName'],
getGenre: [Genre.getByName, 'genreName'],
assertGenreExistence: [Genre.assertExistence, 'getGenre'],
getBooks: ['assertGenreExistence', 'getGenre', 'findBooksByAuthor', 'getAuthor']
}, function(err, results) {
if(err) return console.error(err); //genre probably didn't exist.
results.forEach(function (result) {
console.log('Number of books for ' + result.getAutor.name + ':', results.getBooks.length);
});
});
```
This does the exact same thing as the above example, but does it once for Brandon Sanderson and once for Jack Vance, in parallel.
## Authors

@@ -99,0 +122,0 @@

@@ -217,2 +217,3 @@ var util = require('util');

module.exports["prerequisite task execution with short circuit error"] = function(test){

@@ -290,1 +291,121 @@ flow({

module.exports["multiple asyncronus tasks with prerequisite task execution"] = function(test){
flow( [
{ authorName: 'Dan Brown',
genreName: 'Fiction'
},
{ authorName: 'Patricia Briggs',
genreName: 'Fantasy'
}
], {
getAuthor: [Author.getByName, 'authorName'],
getGenre: [Genre.getByName, 'genreName'],
assertGenreExistence: [Genre.assertExistence, 'getGenre'],
getBooks: ['assertGenreExistence', Book.findByGenreAndAuthor, 'getGenre', 'getAuthor']
}, function(err, results){
test.ok(!err);
test.deepEqual(results, [
{ authorName: 'Dan Brown',
genreName: 'Fiction',
getAuthor: { id: 4, name: 'Dan Brown' },
getGenre: { id: 3, name: 'Fiction' },
assertGenreExistence: true,
getBooks: [ { id: 6, title: 'Inferno', authorId: 4, genreId: 3 } ] },
{ authorName: 'Patricia Briggs',
genreName: 'Fantasy',
getAuthor: { id: 1, name: 'Patricia Briggs' },
getGenre: { id: 1, name: 'Fantasy' },
assertGenreExistence: true,
getBooks: [] }]
);
test.done();
});
}
module.exports["multiple asyncronus tasks with prerequisite task execution (error)"] = function(test){
flow([
{ authorName: 'Dan Brown',
genreName: 'Fiction'
},
{ authorName: 'Patricia Briggs',
genreName: 'Robot Romance Novels'
}
], {
getAuthor: [Author.getByName, 'authorName'],
getGenre: [Genre.getByName, 'genreName'],
assertGenreExistence: [Genre.assertExistence, 'getGenre'],
getBooks: ['assertGenreExistence', Book.findByGenreAndAuthor, 'getGenre', 'getAuthor']
}, function(err, results){
test.ok(err);
test.equal(results[0], undefined);
test.deepEqual(results[1], {
authorName: 'Patricia Briggs',
genreName: 'Robot Romance Novels',
getAuthor: { id: 1, name: 'Patricia Briggs' },
getGenre: undefined,
assertGenreExistence: undefined
});
test.done();
});
}
module.exports["multiple asyncronus tasks with prerequisite instance task execution"] = function(test){
flow([
{ authorName: 'Dan Brown',
genreName: 'Fiction'
},
{ authorName: 'Patricia Briggs',
genreName: 'Fantasy'
}
], {
getAuthor: [Author.getByName, 'authorName'],
getGenre: [Genre.getByName, 'genreName'],
assertGenreExistence: [Genre.assertExistence, 'getGenre'],
getBooks: ['assertGenreExistence', 'getGenre', 'findBooksByAuthor', 'getAuthor']
}, function(err, results){
test.ok(!err);
test.deepEqual(results, [
{ authorName: 'Dan Brown',
genreName: 'Fiction',
getAuthor: { id: 4, name: 'Dan Brown' },
getGenre: { id: 3, name: 'Fiction' },
assertGenreExistence: true,
getBooks: [ { id: 6, title: 'Inferno', authorId: 4, genreId: 3 } ] },
{ authorName: 'Patricia Briggs',
genreName: 'Fantasy',
getAuthor: { id: 1, name: 'Patricia Briggs' },
getGenre: { id: 1, name: 'Fantasy' },
assertGenreExistence: true,
getBooks: [] }
]);
test.done();
});
}
module.exports["multiple asyncronus tasks with prerequisite instance task execution (error)"] = function(test){
flow([
{ authorName: 'Dan Brown',
genreName: 'Fiction'
},
{ authorName: 'Patricia Briggs',
genreName: 'Robot Romance Novels'
}
], {
getAuthor: [Author.getByName, 'authorName'],
getGenre: [Genre.getByName, 'genreName'],
assertGenreExistence: [Genre.assertExistence, 'getGenre'],
getBooks: ['assertGenreExistence', 'getGenre', 'findBooksByAuthor', 'getAuthor']
}, function(err, results){
test.ok(err);
test.equal(results[0], undefined);
test.deepEqual(results[1], {
authorName: 'Patricia Briggs',
genreName: 'Robot Romance Novels',
getAuthor: { id: 1, name: 'Patricia Briggs' },
getGenre: undefined,
assertGenreExistence: undefined
});
test.done();
});
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc