UNPKG

2.03 kBTypeScriptView Raw
1import { Sanitizers } from '../chain/sanitizers';
2import { Validators } from '../chain/validators';
3import { CustomValidator, DynamicMessageCreator, Location, Request } from '../base';
4import { ValidationChain } from '../chain';
5import { Optional } from '../context';
6import { ResultWithContext } from '../chain/context-runner-impl';
7declare type ValidatorSchemaOptions<K extends keyof Validators<any>> = true | {
8 options?: Parameters<Validators<any>[K]> | Parameters<Validators<any>[K]>[0];
9 errorMessage?: DynamicMessageCreator | any;
10 negated?: boolean;
11 bail?: boolean;
12 if?: CustomValidator | ValidationChain | CustomValidator;
13};
14export declare type ValidatorsSchema = {
15 [K in keyof Validators<any>]?: ValidatorSchemaOptions<K>;
16};
17declare type SanitizerSchemaOptions<K extends keyof Sanitizers<any>> = true | {
18 options?: Parameters<Sanitizers<any>[K]> | Parameters<Sanitizers<any>[K]>[0];
19};
20export declare type SanitizersSchema = {
21 [K in keyof Sanitizers<any>]?: SanitizerSchemaOptions<K>;
22};
23declare type InternalParamSchema = ValidatorsSchema & SanitizersSchema;
24/**
25 * Defines a schema of validations/sanitizations plus a general validation error message
26 * and possible field locations.
27 */
28export declare type ParamSchema = InternalParamSchema & {
29 in?: Location | Location[];
30 errorMessage?: DynamicMessageCreator | any;
31 optional?: true | {
32 options?: Partial<Optional>;
33 };
34};
35/**
36 * @deprecated Only here for v5 compatibility. Please use ParamSchema instead.
37 */
38export declare type ValidationParamSchema = ParamSchema;
39/**
40 * Defines a mapping from field name to a validations/sanitizations schema.
41 */
42export declare type Schema = Record<string, ParamSchema>;
43/**
44 * @deprecated Only here for v5 compatibility. Please use Schema instead.
45 */
46export declare type ValidationSchema = Schema;
47export declare function checkSchema(schema: Schema, defaultLocations?: Location[]): ValidationChain[] & {
48 run: (req: Request) => Promise<ResultWithContext[]>;
49};
50export {};