forked from express-validator/express-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
112 lines (101 loc) · 5.04 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Type definitions for express-validator 3.0.0
// Project: https://github.com/ctavan/express-validator
// Definitions by: Ayman Nedjmeddine <https://github.com/IOAyman>, Nathan Ridley <https://github.com/axefrog/>, Jonathan Häberle <http://dreampulse.de>, Peter Harris <https://github.com/codeanimal/>, Kacper Polak <[email protected]>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
///<reference types="express"/>
import * as express from 'express';
import {
Dictionary,
Result,
MappedError,
Options,
Sanitizer,
Validator as BaseValidator
} from './shared-typings';
// Add RequestValidation Interface on to Express's Request Interface.
declare global {
namespace Express {
interface Request extends ExpressValidator.RequestValidation { }
}
}
export as namespace ExpressValidator;
/**
* @param options see: https://github.com/ctavan/express-validator#middleware-options
* @constructor
*/
declare function ExpressValidator(options?: Options.ExpressValidatorOptions): express.RequestHandler;
export = ExpressValidator;
// Internal Module.
declare namespace ExpressValidator {
export type URLProtocol = 'http' | 'https' | 'ftp'
export type UUIDVersion = 3 | 4 | 5 | 'all'
export type IPVersion = 4 | 6
export type AlphaLocale = 'ar' | 'ar-AE' | 'ar-BH' | 'ar-DZ' | 'ar-EG' | 'ar-IQ' | 'ar-JO' | 'ar-KW' | 'ar-LB' | 'ar-LY' | 'ar-MA' | 'ar-QA' | 'ar-QM' | 'ar-SA' | 'ar-SD' | 'ar-SY' | 'ar-TN' | 'ar-YE' | 'cs-CZ' | 'da-DK' | 'de-DE' | 'en-AU' | 'en-GB' | 'en-HK' | 'en-IN' | 'en-NZ' | 'en-US' | 'en-ZA' | 'en-ZM' | 'es-ES' | 'fr-FR' | 'hu-HU' | 'nl-NL' | 'pl-PL' | 'pt-BR' | 'pt-PT' | 'ru-RU' | 'sr-RS' | 'sr-RS@latin' | 'tr-TR' | 'uk-UA'
export type AlphanumericLocale = 'ar' | 'ar-AE' | 'ar-BH' | 'ar-DZ' | 'ar-EG' | 'ar-IQ' | 'ar-JO' | 'ar-KW' | 'ar-LB' | 'ar-LY' | 'ar-MA' | 'ar-QA' | 'ar-QM' | 'ar-SA' | 'ar-SD' | 'ar-SY' | 'ar-TN' | 'ar-YE' | 'cs-CZ' | 'da-DK' | 'de-DE' | 'en-AU' | 'en-GB' | 'en-HK' | 'en-IN' | 'en-NZ' | 'en-US' | 'en-ZA' | 'en-ZM' | 'es-ES' | 'fr-FR' | 'fr-BE' | 'hu-HU' | 'nl-BE' | 'nl-NL' | 'pl-PL' | 'pt-BR' | 'pt-PT' | 'ru-RU' | 'sr-RS' | 'sr-RS@latin' | 'tr-TR' | 'uk-UA'
export type MobilePhoneLocal = 'ar-DZ' | 'ar-SA' | 'ar-SY' | 'cs-CZ' | 'de-DE' | 'da-DK' | 'el-GR' | 'en-AU' | 'en-GB' | 'en-HK' | 'en-IN' | 'en-NZ' | 'en-US' | 'en-CA' | 'en-ZA' | 'en-ZM' | 'es-ES' | 'fi-FI' | 'fr-FR' | 'hu-HU' | 'it-IT' | 'ja-JP' | 'ms-MY' | 'nb-NO' | 'nn-NO' | 'pl-PL' | 'pt-PT' | 'ru-RU' | 'sr-RS' | 'tr-TR' | 'vi-VN' | 'zh-CN' | 'zh-TW'
export type Location = 'body' | 'params' | 'query' | 'headers' // TODO add cookies if #292 is accepted
export type ValidationSchema = {
[param: string]:
Options.ValidationSchemaParamOptions // standard validators
| // or
{ [customValidator: string]: Options.ValidatorSchemaOptions } // custom ones
}
interface ValidatorFunction {
(item: string | string[], message?: any): Validator;
(schema: {}): Validator;
}
/**
* This one's used for RegexRoutes
* @see https://github.com/ctavan/express-validator#regex-routes
*/
interface ValidatorFunctionRegExp extends ValidatorFunction { (matchIndex: number, message?: string): Validator; }
interface SanitizerFunction { (item: string): Sanitizer; }
export interface RequestValidation {
assert: ValidatorFunctionRegExp;
validate: ValidatorFunctionRegExp;
check: ValidatorFunctionRegExp;
checkBody: ValidatorFunction;
checkCookies: ValidatorFunction;
checkHeaders: ValidatorFunction;
checkParams: ValidatorFunction;
checkQuery: ValidatorFunction;
filter: SanitizerFunction;
sanitize: SanitizerFunction;
sanitizeBody: SanitizerFunction;
sanitizeQuery: SanitizerFunction;
sanitizeParams: SanitizerFunction;
sanitizeHeaders: SanitizerFunction;
sanitizeCookies: SanitizerFunction;
/**
* @deprecated
* @param mapped Will cause the validator to return an object that maps parameter to error.
* @return Synchronous errors in the form of an array. If there are no errors, the returned value is false.
*/
validationErrors(mapped?: boolean): Dictionary<MappedError> | MappedError[];
/**
* @deprecated
* @param mapped Will cause the validator to return an object that maps parameter to error.
* @return Synchronous errors in the form of an array. If there are no errors, the returned value is false.
*/
validationErrors<T>(mapped?: boolean): Dictionary<T> | T[];
/**
* @deprecated
* @param mapped Whether to map parameters to errors or not.
*/
asyncValidationErrors(mapped?: boolean): Promise<MappedError[] | Dictionary<MappedError>>;
/**
* @deprecated
* @param mapped Whether to map parameters to errors or not.
*/
asyncValidationErrors<T>(mapped?: boolean): Promise<T[] | Dictionary<T>>;
/**
* @return Promise<Result> A Promise which resolves to a result object.
*/
getValidationResult(): Promise<Result>
}
export interface Validator extends BaseValidator {
// Additional legacy validators
notEmpty(): this;
len(options: Options.MinMaxOptions): this;
}
}