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

middlewarify

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

middlewarify - npm Package Compare versions

Comparing version 0.3.4 to 0.3.5

38

middlewarify.js

@@ -75,4 +75,3 @@ /**

* @param {*...} varArgs Any number of arguments
* @param {Function=} optCb last argument is callback
* @return {Object} the -master- callback using done(fn).
* @return {Promise} A promise.
* @private

@@ -83,4 +82,2 @@ */

return new Promise(function(resolve, reject) {
var deferred = Promise.defer();
deferred.promise.then(resolve, reject);
var midds;

@@ -95,5 +92,11 @@ if (middObj.params.beforeAfter) {

}
middlewarify._fetchAndInvoke(midds, args, deferred, {
var store = {
mainCallbackReturnValue: null,
});
};
var deferred = {
resolve: resolve,
reject: reject,
};
middlewarify._fetchAndInvoke(midds, args, store, deferred);
});

@@ -105,16 +108,15 @@ };

*
* @param {Array.<Function>} midds The array with the middleware.
* @param {Array.<Function>} midds The middleware.
* @param {Array} args An array of arbitrary arguments, can be empty.
* @param {Promise.Defer} deferred Deferred object.
* @param {Object} store A map, helper for main cb return value.
* @param {Object} store use as store.
* @param {Object} deferred contains resolve, reject fns.
* @return {Promise} A promise.
* @private
*/
middlewarify._fetchAndInvoke = function(midds, args, deferred, store) {
if (midds.length === 0) {
middlewarify._fetchAndInvoke = function(midds, args, store, deferred) {
if (!midds.length) {
return deferred.resolve(store.mainCallbackReturnValue);
}
var midd = midds.shift();
// Promise.try(function(){return midd.apply(null, args);})
Promise.try(midd.bind.apply(midd, [null].concat(args)))
Promise.try(midd, args)
.then(function(val) {

@@ -125,4 +127,8 @@ if (midd.isMain) {

}
middlewarify._fetchAndInvoke(midds, args, deferred, store);
}, deferred.reject.bind(deferred));
middlewarify._fetchAndInvoke(midds, args, store, deferred);
})
.catch(function(err) {
deferred.reject(err);
});
};

@@ -129,0 +135,0 @@

{
"name": "middlewarify",
"description": "Apply the middleware pattern to any function.",
"version": "0.3.4",
"version": "0.3.5",
"homepage": "https://github.com/thanpolas/middlewarify",

@@ -35,3 +35,3 @@ "author": {

"async": "~0.2.10",
"bluebird": "~1.0.5"
"bluebird": "~1.0.7"
},

@@ -38,0 +38,0 @@ "devDependencies": {

@@ -274,2 +274,5 @@ # Middlewarify

## Release History
- **v0.3.5**, *02 Mar 2014*
- Optimizations and better handling of errors.
- Updated to latest Bluebird, now suppresses unhandled errors.
- **v0.3.4**, *19 Feb 2014*

@@ -276,0 +279,0 @@ - Update dependencies to latest.

@@ -112,4 +112,3 @@ /**

var bar = {b: 2};
obj.create(1, foo, bar).then(function(err){
assert.notOk(err, 'error should not be truthy');
obj.create(1, foo, bar).then(function() {
assert.ok(firstMidd.alwaysCalledWith(1, foo, bar), 'firstMidd should be invoked with these arguments');

@@ -258,1 +257,53 @@ assert.ok(secondMidd.alwaysCalledWith(1, foo, bar), 'secondMidd should be invoked with these arguments');

});
suite('6.7 Unhandled errors', function() {
var obj;
setup(function(){
obj = Object.create(null);
});
test('6.7.1 Throwing errors does not cause Unhandled exceptions', function(done) {
Promise.onPossiblyUnhandledRejection(done);
midd.make(obj, 'create', Promise.method(function() {
throw new Error('Boo');
}), {beforeAfter: true});
obj.create().catch(function(err) {
assert.equal(err.message, 'Boo');
assert.instanceOf(err, Error);
}).then(done, done);
});
test('6.7.2 Throwing errors does not cause Unhandled exceptions', function(done) {
Promise.onPossiblyUnhandledRejection(done);
function prom() {
return new Promise(function(resolve) {
setTimeout(resolve, 1000);
});
}
midd.make(obj, 'create', Promise.method(function() {
return prom().then(function() {
throw new Error('Boo');
});
}), {beforeAfter: true});
obj.create().catch(function(err) {
assert.equal(err.message, 'Boo');
assert.instanceOf(err, Error);
}).then(done, done);
});
test('6.7.3 Rejecting promise does not cause Unhandled exceptions', function(done) {
Promise.onPossiblyUnhandledRejection(done);
midd.make(obj, 'create', function() {
return new Promise(function(resolve, reject) {
setTimeout(function() {
reject('lol');
});
});
}, {beforeAfter: true});
obj.create().catch(function(err) {
assert.equal(err, 'lol');
}).then(done, done);
});
});

@@ -48,6 +48,11 @@ /**

return new Promise(function(resolve, reject) {
reject();
setTimeout(function() {
reject('poop');
});
});
});
thing.create().then(noop, done.bind(null, null));
thing.create()
.catch(function(err) {
done();
});

@@ -58,9 +63,10 @@ });

return new Promise(function(resolve, reject) {
reject('Error');
setTimeout(function() {
reject('Error');
});
});
});
thing.create().then(null, function(err) {
thing.create().catch(function(err) {
assert.equal(err, 'Error');
done();
}).then(null, done);
}).then(done, done);
});

@@ -156,3 +162,5 @@ test('7.' + num + '.4 arguments propagate', function(done) {

return new Promise(function(resolve, reject) {
reject('Error');
setTimeout(function() {
reject('Error');
});
});

@@ -159,0 +167,0 @@ });

Sorry, the diff of this file is not supported yet

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