Socket
Socket
Sign inDemoInstall

express-promise

Package Overview
Dependencies
0
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 0.3.0

test/skip_rule.js

27

lib/express_promise.js

@@ -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');

});
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc