express-validator
Advanced tools
Comparing version 3.2.0 to 3.2.1
@@ -8,21 +8,16 @@ // Type definitions for express-validator 3.0.0 | ||
///<reference types="bluebird"/> | ||
import * as express from 'express'; | ||
// Add RequestValidation Interface on to Express's Request Interface. | ||
declare namespace Express { | ||
interface Request extends ExpressValidator.RequestValidation {} | ||
declare global { | ||
namespace Express { | ||
interface Request extends ExpressValidator.RequestValidation { } | ||
} | ||
} | ||
// External express-validator module. | ||
declare module "express-validator" { | ||
import express = require('express'); | ||
/** | ||
* @param options see: https://github.com/ctavan/express-validator#middleware-options | ||
* @constructor | ||
*/ | ||
function ExpressValidator(options?: ExpressValidator.Options.ExpressValidatorOptions): express.RequestHandler; | ||
export = ExpressValidator; | ||
} | ||
export as namespace ExpressValidator; | ||
/** | ||
* @param options see: https://github.com/ctavan/express-validator#middleware-options | ||
* @constructor | ||
*/ | ||
declare function ExpressValidator(options?: ExpressValidator.Options.ExpressValidatorOptions): express.RequestHandler; | ||
export = ExpressValidator; | ||
// Internal Module. | ||
@@ -41,5 +36,5 @@ declare namespace ExpressValidator { | ||
[param: string]: | ||
ExpressValidator.Options.ValidationSchemaParamOptions // standard validators | ||
| // or | ||
{ [customValidator: string]: ExpressValidator.Options.ValidatorSchemaOptions } // custom ones | ||
ExpressValidator.Options.ValidationSchemaParamOptions // standard validators | ||
| // or | ||
{ [customValidator: string]: ExpressValidator.Options.ValidatorSchemaOptions } // custom ones | ||
} | ||
@@ -267,5 +262,5 @@ | ||
*/ | ||
trim(chars: string): Sanitizer; | ||
ltrim(chars: string): Sanitizer; | ||
rtrim(chars: string): Sanitizer; | ||
trim(chars?: string): Sanitizer; | ||
ltrim(chars?: string): Sanitizer; | ||
rtrim(chars?: string): Sanitizer; | ||
/** | ||
@@ -301,3 +296,3 @@ * Remove characters with a numerical value < 32 and 127, mostly control characters. | ||
export interface ExpressValidatorOptions { | ||
customValidators?: { [validatorName: string]: (...value: any[]) => boolean } | ||
customValidators?: { [validatorName: string]: (...value: any[]) => boolean | Promise<any> } | ||
customSanitizers?: { [sanitizername: string]: (value: any) => any } | ||
@@ -304,0 +299,0 @@ errorFormatter?: (param?: string, msg?: string, value?: any) => any |
@@ -0,1 +1,2 @@ | ||
var deprecate = require('util').deprecate; | ||
var validator = require('validator'); | ||
@@ -6,2 +7,33 @@ var _ = require('lodash'); | ||
// Because req.validationErrors and req.asyncValidationErrors are build dynamically, | ||
// these warnings would appear everytime a new request comes in. | ||
// Therefore the best solution to show the warning is to create a stub function, | ||
// and invoke it inside the deprecated functions. | ||
var warnValidationErrors = deprecate( | ||
function () {}, | ||
'req.validationErrors() may be removed in a future version. Use req.getValidationResult() instead.' | ||
); | ||
var warnAsyncValidationErrors = deprecate( | ||
function () {}, | ||
'req.asyncValidationErrors() may be removed in a future version. Use req.getValidationResult() instead.' | ||
); | ||
/** | ||
* display warnings once per each validator | ||
* which returns null or undefined as a validation | ||
* result | ||
*/ | ||
var warnValidatorNilReturn = (function() { | ||
var warned = {}; | ||
return function(methodName, returnedValue) { | ||
if (warned[methodName]) { | ||
return; | ||
} | ||
warned[methodName] = true; | ||
console.warn('WARNING: unexpected return value: `' + returnedValue + '` returned by `' + methodName + '` validator'); | ||
} | ||
}()); | ||
// When validator upgraded to v5, they removed automatic string coercion | ||
@@ -291,2 +323,3 @@ // The next few methods (up to validator.init()) restores that functionality | ||
req.validationErrors = function(mapped, promisesResolved) { | ||
warnValidationErrors(); | ||
if (!promisesResolved && req._asyncValidationErrors.length > 0) { | ||
@@ -309,2 +342,3 @@ console.warn('WARNING: You have asynchronous validators but you have not used asyncValidateErrors to check for errors.'); | ||
req.asyncValidationErrors = function(mapped) { | ||
warnAsyncValidationErrors(); | ||
return new Promise(function(resolve, reject) { | ||
@@ -480,3 +514,9 @@ var promises = req._asyncValidationErrors; | ||
if (isValid.then) { | ||
var isNilValue = isValid === undefined || isValid === null | ||
if (isNilValue) { | ||
warnValidatorNilReturn(methodName, isValid); | ||
} | ||
if (!isNilValue && isValid.then) { | ||
var promise = isValid.catch(function() { | ||
@@ -570,4 +610,5 @@ return Promise.reject(error); | ||
module.exports = expressValidator; | ||
module.exports.validator = validator; | ||
module.exports.utils = utils; |
@@ -14,3 +14,3 @@ { | ||
], | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"homepage": "https://github.com/ctavan/express-validator", | ||
@@ -34,3 +34,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"@types/bluebird": "~3.0.36", | ||
"@types/bluebird": "^3.4.0", | ||
"@types/express": "~4.0.34", | ||
@@ -51,3 +51,3 @@ "bluebird": "^3.4.0", | ||
"supertest": "0.15.0", | ||
"typescript": "~2.0.10" | ||
"typescript": "^2.3.4" | ||
}, | ||
@@ -54,0 +54,0 @@ "keywords": [ |
@@ -43,3 +43,3 @@ # express-validator | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.bodyParser({ extended: true })); | ||
app.use(expressValidator([options])); // this line must be immediately after any of the bodyParser middlewares! | ||
@@ -81,4 +81,4 @@ | ||
urlparam: req.params.urlparam, | ||
getparam: req.params.getparam, | ||
postparam: req.params.postparam | ||
getparam: req.query.getparam, | ||
postparam: req.body.postparam | ||
}); | ||
@@ -85,0 +85,0 @@ }); |
@@ -17,4 +17,4 @@ { | ||
}, | ||
"files": [ "index.d.ts", "./test/typeDefinitionTest.ts" ], | ||
"files": [ "index.d.ts", "./test/type-definition.spec.ts" ], | ||
"exclude": [ "node_modules", "coverage" ] | ||
} |
Sorry, the diff of this file is not supported yet
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
97261
17
2035
+ Added@types/bluebird@3.5.42(transitive)
- Removed@types/bluebird@3.0.37(transitive)
Updated@types/bluebird@^3.4.0