dat-middleware
Advanced tools
Comparing version 1.8.1 to 1.9.0
@@ -378,2 +378,27 @@ var error = require('./error'); | ||
/** | ||
* delete keys from data object | ||
* @param {...key} string - keys on the request data to delete. | ||
*/ | ||
RequestData.prototype.each = function (/* middlewares */) { | ||
var self = this; | ||
var req = require('../index').req; | ||
if (this._keys.length > 1) { | ||
throw new Error('cannot be used with multiple keys'); | ||
} | ||
var key = this._keys[0]; | ||
var middlewares = Array.prototype.slice.call(arguments); | ||
if (middlewares.length === 0) { | ||
throw new Error('atleast one middleware is required'); | ||
} | ||
return function (req, res, next) { | ||
var arr = keypather.get(req, self.keypath(key)); | ||
if (!Array.isArray(arr)) { | ||
throw new Error('keypath "'+key+'" is not an array'); | ||
} | ||
var args = [arr].concat(middlewares); | ||
flow.each.apply(flow, args)(req, res, next); | ||
}; | ||
}; | ||
/*************** CONDITIONALS ***************/ | ||
@@ -380,0 +405,0 @@ /*************** CONDITIONALS ***************/ |
{ | ||
"name": "dat-middleware", | ||
"version": "1.8.1", | ||
"version": "1.9.0", | ||
"description": "common request, response, body, query, and param validation, transformation, and flow control middleware", | ||
@@ -42,3 +42,3 @@ "main": "index.js", | ||
"map-utils": "~0.4.0", | ||
"middleware-flow": "^0.5.0" | ||
"middleware-flow": "^0.6.0" | ||
}, | ||
@@ -45,0 +45,0 @@ "devDependencies": { |
@@ -229,2 +229,24 @@ # dat-middleware [![Build Status](https://travis-ci.org/tjmehta/dat-middleware.png?branch=master)](https://travis-ci.org/tjmehta/dat-middleware) | ||
# Flow Control | ||
## each() | ||
iterates through a series of middlewares (in parallel) for each item in an array | ||
```js | ||
var mw = require('dat-middleware'); | ||
var app = require('express')(); | ||
// a body of { arr: [1,2,3] } | ||
app.use(mw.body('arr').each( | ||
function (eachReq, res, next) { | ||
// eachReq prototypically inherits from the original req | ||
// (get gets from req, set only sets to eachReq) | ||
}, | ||
function (item, req, eachReq, res, next) { | ||
// if five arguments are accepted the current item and the origin req are passed | ||
} | ||
)); | ||
``` | ||
# Conditionals (flow control): | ||
@@ -231,0 +253,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72887
33
2028
290
+ Addedmiddleware-flow@0.6.1(transitive)
- Removedmiddleware-flow@0.5.1(transitive)
Updatedmiddleware-flow@^0.6.0