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

dat-middleware

Package Overview
Dependencies
Maintainers
2
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dat-middleware - npm Package Compare versions

Comparing version 1.10.3 to 1.10.4

4

lib/errorHandler.js

@@ -1,3 +0,3 @@

var pick = require('map-utils').pick;
var exists = require('map-utils').exists;
var pick = require('101/pick');
var exists = require('101/exists');
var NODE_ENV = process.env.NODE_ENV;

@@ -4,0 +4,0 @@

@@ -5,2 +5,3 @@ var Boom = require('boom');

var error = require('./error');
var exists = require('101/exists');
var flow = require('middleware-flow');

@@ -13,3 +14,2 @@ var isFunction = require('101/is-function');

var pluck = require('101/pluck');
var utils = require('map-utils');
var unset = require('./utils/unset');

@@ -37,5 +37,2 @@ var emptyString = function (thing) {

var or = utils.or;
var ternary = utils.ternary;
var series = utils.series;
var validations = require('./validations');

@@ -68,3 +65,3 @@

RequestData.prototype.keypath = function (key) {
return [this.dataType, key].filter(utils.exists).join('.');
return [this.dataType, key].filter(exists).join('.');
};

@@ -71,0 +68,0 @@ /**

@@ -31,2 +31,2 @@ var replaceKeypaths = require('./utils/replaceKeypaths');

module.exports = res;
module.exports = res;

@@ -1,3 +0,3 @@

var utils = require('map-utils');
var error = require('./error');
var exists = require('101/exists');

@@ -27,3 +27,3 @@ module.exports = {

return function (val) {
if (!utils.exists(val)) {
if (!exists(val)) {
var err = error('is required');

@@ -30,0 +30,0 @@ err.val = val;

{
"name": "dat-middleware",
"version": "1.10.3",
"version": "1.10.4",
"description": "common request, response, body, query, and param validation, transformation, and flow control middleware",

@@ -39,17 +39,16 @@ "main": "index.js",

"callback-count": "0.0.3",
"fn-object": "^0.2.2",
"keypather": "^1.8.1",
"map-utils": "~0.4.0",
"middleware-flow": "^0.6.1"
},
"devDependencies": {
"body-parser": "^1.12.2",
"express": "^4.12.3",
"methods": "~0.1.0",
"mocha": "~1.17.1",
"express": "~3.4.8",
"supertest": "~0.9.0",
"nodemon": "^1.0.15",
"object-loops": "^0.5.1",
"should": "~3.1.2",
"methods": "~0.1.0",
"nodemon": "^1.0.15",
"fn-object": "^0.2.1",
"function-proxy": "~0.5.1"
"sinon": "^1.17.2",
"supertest": "~0.9.0"
}
}

@@ -1,6 +0,10 @@

# dat-middleware [![Build Status](https://travis-ci.org/tjmehta/dat-middleware.png?branch=master)](https://travis-ci.org/tjmehta/dat-middleware)
dat-middleware
==============
[![Build Status][ci_img]][ci_lnk]
[![dependency status][depend_img]][depend_lnk]
[![dev dependency status][devdepend_img]][devdepend_lnk]
Common request, response, body, query, and param validation, transformation, and flow control middleware
# Installation
## Installation
```bash

@@ -10,7 +14,7 @@ npm install dat-middleware

# Examples
## Examples
# Validations:
## Validations:
## require()
### require()

@@ -35,3 +39,3 @@ requires the keys specified, and nexts a 400 error if one does not exist

## string()
### string()

@@ -46,3 +50,3 @@ requires the keys are strings (if they exist), and nexts a 400 error if one is not

## number()
### number()

@@ -57,3 +61,3 @@ requires the keys are numbers (if they exist), and nexts a 400 error if one is not

## object()
### object()

@@ -68,3 +72,3 @@ requires the keys are objects (if they exist), and nexts a 400 error if one is not

## function()
### function()

@@ -79,3 +83,3 @@ requires the keys are functions (if they exist), and nexts a 400 error if one is not

## boolean()
### boolean()

@@ -90,3 +94,3 @@ requires the keys are booleans (if they exist), and nexts a 400 error if one is not

## array()
### array()

@@ -117,3 +121,3 @@ requires the keys are arrays (if they exist), and nexts a 400 error if one is not

## instanceOf(Class)
### instanceOf(Class)

@@ -132,3 +136,3 @@ requires the keys are an instance of the specified class (if they exist), and nexts a 400 error if one is not

## matches(regexp)
### matches(regexp)

@@ -147,3 +151,3 @@ requires the keys are an instance of the specified class (if they exist), and nexts a 400 error if one is not

## validate(validation)
### validate(validation)

@@ -168,5 +172,5 @@ requires the keys pass the validation (if they exist), and nexts a 400 error if one is not

# Transformations:
## Transformations:
## mapValues(transformation)
### mapValues(transformation)

@@ -186,3 +190,3 @@ transforms the values of the keys specified using the transformation function

## transform(transformation)
### transform(transformation)

@@ -204,3 +208,3 @@ transforms the entire dataType object using the transformation function

## pick()
### pick()

@@ -217,3 +221,3 @@ picks the keys specified and ignores the rest. a way of filtering data values by key.

## set()
### set()

@@ -236,3 +240,3 @@ sets the keys and values on the data type.

## unset()
### unset()

@@ -249,5 +253,5 @@ deletes the keys on the data type.

# Flow Control
## Flow Control
## each()
### each()

@@ -272,7 +276,7 @@ iterates through a series of middlewares (in parallel) for each item in an array

# Conditionals (flow control):
## Conditionals (flow control):
for more flow control checkout [middleware-flow](http://github.com/tjmehta/middleware-flow)
## [validation chain].then(middlewares...).else(middlewares)
### [validation chain].then(middlewares...).else(middlewares)

@@ -291,3 +295,3 @@ ```js

# Chaining: chained methods will run in order
## Chaining: chained methods will run in order

@@ -312,3 +316,10 @@ note: conditionals do not chain before validations and transformations

# License
### MIT
## License
**MIT**
[ci_img]: https://travis-ci.org/tjmehta/dat-middleware.png
[ci_lnk]: https://travis-ci.org/tjmehta/dat-middleware
[depend_img]: https://david-dm.org/tjmehta/dat-middleware.png
[depend_lnk]: https://david-dm.org/tjmehta/dat-middleware
[devdepend_img]: https://david-dm.org/tjmehta/dat-middleware/dev-status.png
[devdepend_lnk]: https://david-dm.org/tjmehta/dat-middleware#info=devDependencies
var createAppWithMiddleware = require('./fixtures/createAppWithMiddleware');
var mw = require('../index');
var fno = require('fn-object');
var createCounter = require('callback-count');

@@ -68,2 +67,2 @@ var request = require('./lib/superdupertest');

};
}
}
var express = require('express');
var bodyParser = require('body-parser');
var mw = require('../../index');

@@ -9,6 +10,4 @@ var next = function (req, res, next) {next();};

var app = express();
app.use(express.json());
app.use(express.urlencoded());
app.use(app.router);
app.use(mw.errorHandler({ showStack: true, log: false }));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.all('/',

@@ -42,2 +41,3 @@ middleware,

mw.params().send());
app.use(mw.errorHandler({ showStack: true, log: false }));
return app;

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

var createAppWithMiddleware = require('./fixtures/createAppWithMiddleware');
var createCount = require('callback-count');
var mw = require('../index');
var request = require('./lib/superdupertest');
var series = require('middleware-flow').series;
var request = require('./lib/superdupertest');
var spyOnMethod = require('function-proxy').spyOnMethod;
var createCount = require('callback-count');
var sinon = require('sinon');

@@ -18,6 +18,7 @@ describe('log', function() {

var count = createCount(2, done);
spyOnMethod(console, 'log', function () {
sinon.stub(console, 'log', function () {
var args = Array.prototype.slice.call(arguments);
if (args[0] === 'hello') {
['hello', 10, 'world'].should.eql(args);
console.log.restore();
count.next();

@@ -42,9 +43,9 @@ }

var count = createCount(2, done);
spyOnMethod(console, 'log', function () {
sinon.stub(console, 'log', function () {
var args = Array.prototype.slice.call(arguments);
if (typeof args[0] === 'object' && args[0].foo) {
args[0].should.eql({ foo: 'bar' });
console.log.restore();
count.next();
}
count.next();
});

@@ -58,2 +59,2 @@ request(this.app)

});
});
});
var createAppWithMiddleware = require('./fixtures/createAppWithMiddleware');
var mw = require('../index');
var fno = require('fn-object');
var objectMap = require('object-loops/map');
var createCounter = require('callback-count');

@@ -38,3 +38,3 @@ var request = require('./lib/superdupertest');

data[this.key] = value;
var transformedData = fno(data).vals.map(transformation).val();
var transformedData = objectMap(data, transformation);
var body = dataType === 'body' ? data : {};

@@ -68,3 +68,3 @@ var query = dataType === 'query' ? data : {};

data[this.keys[1]] = value;
var transformedData = fno(data).vals.map(transformation).val();
var transformedData = objectMap(data, transformation);
var body = dataType === 'body' ? data : {};

@@ -83,2 +83,2 @@ var query = dataType === 'query' ? data : {};

};
}
}
var createAppWithMiddleware = require('./fixtures/createAppWithMiddleware');
var createCount = require('callback-count');
var mw = require('../index');
var request = require('./lib/superdupertest');
var series = require('middleware-flow').series;
var request = require('./lib/superdupertest');
var spyOnMethod = require('function-proxy').spyOnMethod;
var createCount = require('callback-count');

@@ -43,2 +42,2 @@ describe('next', function() {

});
});
});
var createAppWithMiddleware = require('./fixtures/createAppWithMiddleware');
var mw = require('../index');
var fno = require('fn-object');
var createCounter = require('callback-count');

@@ -78,2 +77,2 @@ var request = require('./lib/superdupertest');

};
}
}

@@ -8,12 +8,27 @@ var createAppWithMiddleware = require('./fixtures/createAppWithMiddleware');

describe('send', function() {
beforeEach(function () {
this.app = createAppWithMiddleware(
mw.res.send(201, 'hello')
);
describe('code, string', function () {
beforeEach(function () {
this.app = createAppWithMiddleware(
mw.res.send(201, 'hello')
);
});
it('should work like res.send', function (done) {
request(this.app)
.get('/')
.expect(201, 'hello')
.end(done);
});
});
it('should work like res.send', function (done) {
request(this.app)
.get('/')
.expect(201, 'hello')
.end(done);
describe('array', function () {
beforeEach(function () {
this.app = createAppWithMiddleware(
mw.res.send([])
);
});
it('should work like res.send', function (done) {
request(this.app)
.get('/')
.expect(200, [])
.end(done);
});
});

@@ -138,2 +153,2 @@ });

});
});
});
var clone = require('101/clone');
var createAppWithMiddleware = require('./fixtures/createAppWithMiddleware');
var createCounter = require('callback-count');
var fno = require('fn-object');
var isFunction = require('101/is-function');

@@ -6,0 +5,0 @@ var isString = require('101/is-string');

var createAppWithMiddleware = require('./fixtures/createAppWithMiddleware');
var mw = require('../index');
var fno = require('fn-object');
var createCounter = require('callback-count');

@@ -47,2 +46,2 @@ var request = require('./lib/superdupertest');

};
}
}
var createAppWithMiddleware = require('./fixtures/createAppWithMiddleware');
var mw = require('../index');
var fno = require('fn-object');
var createCounter = require('callback-count');

@@ -5,0 +4,0 @@ var request = require('./lib/superdupertest');

var createAppWithMiddleware = require('./fixtures/createAppWithMiddleware');
var mw = require('../index');
var fno = require('fn-object');
var createCounter = require('callback-count');

@@ -116,2 +115,2 @@ var request = require('./lib/superdupertest');

};
}
}

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