express-promise
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -9,5 +9,3 @@ var isPromise = function(v) { | ||
var MAX_PROMISE = 10; | ||
var resolveAsync = function(object, callback, count) { | ||
var resolveAsync = function(object, callback, count, options) { | ||
if (!object || typeof object !== 'object') { | ||
@@ -17,6 +15,4 @@ return callback(null, object); | ||
/* Maintain count on how many promises to attempt to resolve */ | ||
count = count || MAX_PROMISE; | ||
if (count === 0) { | ||
return callback(new Error('Max promises (' + MAX_PROMISE + ') reached')); | ||
return callback(new Error('Max promises (' + options.maxPromise + ') reached')); | ||
} | ||
@@ -27,3 +23,3 @@ | ||
if (isPromise(result)) { | ||
resolveAsync(result, callback, count - 1); | ||
resolveAsync(result, callback, count - 1, options); | ||
} else { | ||
@@ -37,2 +33,6 @@ callback(null, result); | ||
if (options.skipTraverse && options.skipTraverse(object)) { | ||
return callback(null, object); | ||
} | ||
if (typeof object.toJSON === 'function') { | ||
@@ -83,3 +83,3 @@ object = object.toJSON(); | ||
} else { | ||
resolveAsync(object[item.key], handleDone); | ||
resolveAsync(object[item.key], handleDone, count - 1, options); | ||
} | ||
@@ -91,3 +91,4 @@ }); | ||
var defaultOptions = { | ||
methods: ['json', 'render', 'send'] | ||
methods: ['json', 'render', 'send'], | ||
maxPromise: 20 | ||
}; | ||
@@ -130,3 +131,3 @@ | ||
} | ||
}); | ||
}, options.maxPromise, options); | ||
}; | ||
@@ -151,3 +152,3 @@ } | ||
originalResRender(view, result); | ||
}); | ||
}, options.maxPromise, options); | ||
return; | ||
@@ -160,3 +161,3 @@ } | ||
originalResRender(view, result, fn); | ||
}); | ||
}, options.maxPromise, options); | ||
}; | ||
@@ -190,3 +191,3 @@ } | ||
} | ||
}); | ||
}, options.maxPromise, options); | ||
} else { | ||
@@ -193,0 +194,0 @@ if (status) { |
{ | ||
"name": "express-promise", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "test": "mocha -R spec" |
@@ -97,2 +97,16 @@ # express-promise | ||
### Skip traverse | ||
As a gesture to performance, when traverse an object, we call `toJSON` on it to reduce the properties we need to traverse recursively. However that's measure has some negative effects. For instance, all the methods will be removed from the object so you can't use them in the template. | ||
If you want to skip calling `toJSON` on an object(as well as stop traverse it recursively), you can use the `skipTraverse` option. If the function return `true`, express-promise will skip the object. | ||
app.use(require('express-promise')({ | ||
skipTraverse: function(object) { | ||
if (object.hasOwnProperty('method')) { | ||
return true; | ||
} | ||
} | ||
})) | ||
## Libraries | ||
@@ -99,0 +113,0 @@ express-promise works well with some ODM/ORM libraries such as [Mongoose](http://mongoosejs.com) and [Sequelize](http://sequelizejs.com). There are some examples in the /examples folder. |
@@ -36,3 +36,1 @@ require('./spec_helper'); | ||
}); | ||
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
165
2
2
23264
26
543