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.3.0 to 0.4.0

19

lib/task.js

@@ -22,2 +22,9 @@ var util = require('util');

Task.prototype.defaultTo = function(value) {
this.onComplete(function(result, results){
if(result.value === null || result.value === undefined) result.value = value;
});
return this;
}
Task.prototype.assertExists = function assertExists(){

@@ -27,5 +34,5 @@ var self = this;

var err;
if(result === null || result === undefined) {
if(result.value === null || result.value === undefined) {
err = new errors.ArgumentNull(self.name);
err.message = 'Not Found: ' + self.toString(results);
err.message = 'Not Found: ' + self.toString(results.value);
throw err;

@@ -170,7 +177,11 @@ }

Task.complete = function(result, results, callback){
result = { value: result };
results = { value: results };
var err;
try {
if(this.emitter) this.emitter.emit('complete', result, results);
if(this.emitter) {
this.emitter.emit('complete', result, results);
}
} catch(e) { err = e; }
callback(err, result);
callback(err, result.value);
}

@@ -177,0 +188,0 @@

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

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

@@ -9,0 +9,0 @@ "type": "git",

@@ -116,2 +116,25 @@ fnflow

### task.defaultTo(value)
Default the result of a task to a specified value if it did not yield one (undefined or null).
__Example__
```js
var flow = new Flow({
book: new Task(Book.findByTitle, 'title'),
author_name: new Task(Author.getNameById, 'book.author_id').defaultTo('unknown')
});
flow.execute({ title: 'Beowulf' }, function(err, results){
if(err) return console.error(err);
console.log(results.author_name + " wrote " + results.title); //prints "unknown wrote Beowulf"
});
```
...which translates to the following workflow:
* Get the book asynchronously by title.
* After retrieving the book, get the name of the author by id. If the author name retrieved is _null_ or _undefined_, set it to "_unkown_".
### task.requires(task_names)

@@ -118,0 +141,0 @@

@@ -18,2 +18,26 @@ var Flow = require('../lib/fnFlow').Flow, Task = Flow.Task;

module.exports["flow task defaults"] = function(test){
new Flow({
book: new Task(Book.getById, 'bookId').defaultTo("none")
}).execute({
bookId: 100
}, function(err, results){
test.ok(!err, 'no error');
test.deepEqual(results.book, 'none');
test.done();
});
}
module.exports["flow task no defaults"] = function(test){
new Flow({
book: new Task(Book.getById, 'bookId').defaultTo("none")
}).execute({
bookId: 1
}, function(err, results){
test.ok(!err, 'no error');
test.deepEqual(results.book, Book.all[1]);
test.done();
});
}
module.exports["flow task assert exists"] = function(test){

@@ -20,0 +44,0 @@ new Flow({

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