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

dat-middleware

Package Overview
Dependencies
Maintainers
1
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.5.4 to 1.5.5

17

lib/res.js

@@ -7,13 +7,20 @@ var isString = require('101/is-string');

return args.map(function (arg) {
var kpArgs;
if (isString(arg)) {
var keypathVal = keypather.get(req, arg);
return exists(keypathVal) ? keypathVal : arg;
kpArgs = [arg];
}
else if (Array.isArray(arg)) {
kpArgs = arg;
}
else {
return arg;
}
kpArgs = [req].concat(kpArgs);
var keypathVal = keypather.get.apply(keypather, kpArgs);
return exists(keypathVal) ? keypathVal : arg;
});
}
var endMethods = ['send', 'json', 'end'];
var endMethods = ['send', 'json', 'end', 'redirect'];
function middlewarizeResMethod (method) {

@@ -23,3 +30,5 @@ return function (/* keypathArgs */) {

return function (req, res, next) {
var args = replaceKeypaths(req, keypathArgs);
var args = keypathArgs[2]? // if exact=true, dont replace keypaths
keypathArgs.slice(0,2):
replaceKeypaths(req, keypathArgs.slice(0,2));
res[method].apply(res, args);

@@ -26,0 +35,0 @@ if (!~endMethods.indexOf(method)) {

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

@@ -38,3 +38,3 @@ "main": "index.js",

"fn-object": "^0.2.2",
"keypather": "^1.1.0",
"keypather": "^1.6.0",
"middleware-flow": "^0.2.0",

@@ -41,0 +41,0 @@ "map-utils": "~0.4.0"

var express = require('express');
var mw = require('../../index');
module.exports = function createAppWithMiddleware (middleware) {
module.exports = function createAppWithMiddleware (middleware, middleware2) {
middleware2 = middleware2 || function (req, res, next) {next();};
var app = express();

@@ -11,3 +12,4 @@ app.use(express.json());

app.all('/',
middleware);
middleware,
middleware2);
app.all('/body',

@@ -14,0 +16,0 @@ // inspect,

@@ -32,2 +32,50 @@ var createAppWithMiddleware = require('./fixtures/createAppWithMiddleware');

});
describe('keypaths', function() {
beforeEach(function () {
this.app = createAppWithMiddleware(
mw.res.json(201, 'body')
);
});
it('should support req keypaths', function (done) {
request(this.app)
.post('/')
.send({ foo: 'bar' })
.expect(201, {foo:'bar'})
.end(done);
});
describe('keypath functions', function() {
beforeEach(function () {
this.app = createAppWithMiddleware(
mw.body().set('func', function (a) {
return a;
}),
mw.res.json(201, ['body.func(%)', { result: true }])
);
});
it('should support req keypaths', function (done) {
request(this.app)
.post('/')
.send({ foo: 'bar' })
.expect(201, {result:true})
.end(done);
});
describe('keypaths false', function() {
beforeEach(function () {
this.app = createAppWithMiddleware(
mw.body().set('func', function (a) {
return a;
}),
mw.res.json(201, ['body.func(%)', { result: true }], true)
);
});
it('should support req keypaths keypaths=false option', function (done) {
request(this.app)
.post('/')
.send({ foo: 'bar' })
.expect(201, ['body.func(%)', { result: true }])
.end(done);
});
});
});
});
});

@@ -34,0 +82,0 @@ describe('status, write, and end', function() {

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