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.7 to 0.3.8

9

middlewarify.js

@@ -16,2 +16,3 @@ /**

AFTER: 'after',
LAST: 'last',
USE: 'use',

@@ -63,4 +64,6 @@ };

middObj.afterMidds = [];
middObj.lastMidds = [];
obj[prop].before = middlewarify._use.bind(null, middObj, middlewarify.Type.BEFORE);
obj[prop].after = middlewarify._use.bind(null, middObj, middlewarify.Type.AFTER);
obj[prop].last = middlewarify._use.bind(null, middObj, middlewarify.Type.LAST);
} else {

@@ -87,2 +90,3 @@ middObj.midds = [];

* Invokes all the middleware.
*
* @param {Object} middObj Internal midd object.

@@ -100,3 +104,3 @@ * @param {*...} varArgs Any number of arguments

midds.push(middObj.mainCallback);
midds = midds.concat(middObj.afterMidds);
midds = midds.concat(middObj.afterMidds, middObj.lastMidds);
} else {

@@ -177,2 +181,5 @@ midds = Array.prototype.slice.call(middObj.midds);

break;
case middlewarify.Type.LAST:
middObj.lastMidds.push(fn);
break;
case middlewarify.Type.USE:

@@ -179,0 +186,0 @@ middObj.midds.push(fn);

14

package.json
{
"name": "middlewarify",
"description": "Apply the middleware pattern to any function.",
"version": "0.3.7",
"version": "0.3.8",
"homepage": "https://github.com/thanpolas/middlewarify",

@@ -34,10 +34,10 @@ "author": {

"lodash": "~2.4.1",
"async": "~0.2.10",
"bluebird": "~1.0.7"
"async": "~0.9.0",
"bluebird": "~2.2.2"
},
"devDependencies": {
"sinon": "~1.8.2",
"mocha": "~1.17.1",
"chai": "~1.9.0",
"grunt": "~0.4.2",
"sinon": "~1.10.3",
"mocha": "~1.21.0",
"chai": "~1.9.1",
"grunt": "~0.4.5",
"grunt-release": "~0.7.0"

@@ -44,0 +44,0 @@ },

@@ -16,3 +16,3 @@ # Middlewarify

## Quick Start
## Documentation

@@ -24,3 +24,3 @@ ### Quick Start Example

```js
var midd = require('middlewarify');
var middlewarify = require('middlewarify');

@@ -37,3 +37,3 @@ var tasks = module.exports = {};

// Make the'create' Middleware Container.
midd.make(tasks, 'create', createTask);
middlewarify.make(tasks, 'create', createTask);
```

@@ -91,8 +91,18 @@

#### Using the Before / After Middleware type
### Using the Before / After / Last Middleware types
To use the Before/After hook types all you need to do is pass an option to Middlewarify's `make()` method.
To use the Before/After/Last hook types all you need to do is pass the `{beforeAfter: true}` option to Middlewarify's `make()` method.
When using the `beforeAfter` option instead of the typical `use()` method three different methods are created on the resulting middleware method:
* `midd.before()` Hook functions to be invoked **before** the main middleware function.
* `midd.after()` Hook functions to be invoked **after** the main middleware function.
* `midd.last()` Hook functions to be invoked **last**, after the main middleware and all middleware functions have been executed.
> All added hooks are invoked in the order they were added.
#### Before / After / Last Middleware Example
```js
var midd = require('middlewarify');
var middlewarify = require('middlewarify');

@@ -110,3 +120,3 @@ var tasks = module.exports = {};

// Make the'create' Middleware Container using before/after hooks
midd.make(tasks, 'create', createTask, {beforeAfter: true});
middlewarify.make(tasks, 'create', createTask, {beforeAfter: true});

@@ -122,5 +132,10 @@ /** ... */

tasks.create.after(function() {
console.log('Invoked Third and last');
console.log('Invoked Third');
});
// add an always LAST hook, will always invoke last
task.create.last(function() {
console.log('Will always invoke last');
});
/** ... */

@@ -135,3 +150,2 @@

});
```

@@ -283,2 +297,4 @@

- **v0.3.8**, *24 Jul 2014*
- Implemented `.last()` middleware type in beforeAfter family.
- **v0.3.7**, *03 Mar 2014*

@@ -312,3 +328,3 @@ - Added `catchAll` option for cases where invocations have no error handlers.

## License
Copyright 2013 Thanasis Polychronakis
Copyright 2014 Thanasis Polychronakis

@@ -315,0 +331,0 @@ Licensed under the [MIT License](LICENSE-MIT)

@@ -30,2 +30,3 @@ /**

assert.isFunction(obj.create.after, 'obj.create.after should be a function');
assert.isFunction(obj.create.last, 'obj.create.last should be a function');
assert.notProperty(obj.create, 'use', 'obj.create should NOT have a use fn');

@@ -38,3 +39,3 @@ assert.isFunction(obj.create().then, 'obj.create().then should be a Function');

suite('6.2. middleware before/after Sequence of invocation', function() {
var obj, midd1, midd2, midd3, midd4, midd5, midd6, fnPayload;
var obj, midd1, midd2, midd3, midd4, midd5, midd6, middFinal, fnPayload;

@@ -49,2 +50,3 @@ setup(function() {

midd6 = sinon.spy();
middFinal = sinon.spy();
fnPayload = sinon.spy();

@@ -62,2 +64,3 @@ midd.make(obj, 'create', fnPayload, {beforeAfter: true});

assert.ok(midd6.calledOnce, 'midd6 called only once, called: ' + midd6.callCount);
assert.ok(middFinal.calledOnce, 'middFinal called only once, called: ' + middFinal.callCount);
assert.ok(fnPayload.calledOnce, 'fnPayload called only once');

@@ -71,2 +74,3 @@

assert.ok(midd5.calledBefore(midd6), '"midd5" called before "midd6"');
assert.ok(midd6.calledBefore(middFinal), '"midd6" called before "middFinal"');
}).then(done, done);

@@ -77,5 +81,7 @@ });

obj.create.before(midd1, midd2, midd3);
obj.create.last(middFinal);
obj.create.after(midd4, midd5, midd6);
});
test('6.2.2 Multiple calls', function() {
obj.create.last(middFinal);
obj.create.before(midd1);

@@ -90,2 +96,3 @@ obj.create.before(midd2);

obj.create.before([midd1, midd2, midd3]);
obj.create.last([middFinal]);
obj.create.after([midd4, midd5, midd6]);

@@ -95,2 +102,3 @@ });

obj.create.before([midd1, midd2], midd3);
obj.create.last(middFinal);
obj.create.after([midd4, midd5], midd6);

@@ -101,3 +109,3 @@ });

suite('6.3. middleware() argument piping', function() {
var obj, mainMidd, firstMidd, secondMidd, thirdMidd;
var obj, mainMidd, firstMidd, secondMidd, thirdMidd, lastMidd;
setup(function() {

@@ -115,5 +123,7 @@ });

thirdMidd = sinon.spy();
lastMidd = sinon.spy();
midd.make(obj, 'create', mainMidd, {beforeAfter: true});
obj.create.before(firstMidd, secondMidd);
obj.create.after(thirdMidd);
obj.create.last(lastMidd);

@@ -127,2 +137,3 @@ var foo = {a: 1};

assert.ok(mainMidd.alwaysCalledWith(1, foo, bar), 'mainMidd should be invoked with these arguments');
assert.ok(lastMidd.alwaysCalledWith(1, foo, bar), 'lastMidd should be invoked with these arguments');
done();

@@ -129,0 +140,0 @@ }, done).then(null, 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