1 | import { CustomSanitizer, CustomValidator, ErrorMessage, FieldMessageFactory, Location, Request } from '../base';
|
2 | import { BailOptions, OptionalOptions, ValidationChain, ValidationChainLike } from '../chain';
|
3 | import { ResultWithContext } from '../chain/context-runner';
|
4 | import { Sanitizers } from '../chain/sanitizers';
|
5 | import { Validators } from '../chain/validators';
|
6 | type BaseValidatorSchemaOptions = {
|
7 | |
8 |
|
9 |
|
10 |
|
11 | errorMessage?: FieldMessageFactory | ErrorMessage;
|
12 | |
13 |
|
14 |
|
15 | negated?: boolean;
|
16 | |
17 |
|
18 |
|
19 | bail?: boolean | BailOptions;
|
20 | |
21 |
|
22 |
|
23 |
|
24 | if?: CustomValidator | ValidationChain;
|
25 | };
|
26 | type ValidatorSchemaOptions<K extends keyof Validators<any>> = boolean | (BaseValidatorSchemaOptions & {
|
27 | |
28 |
|
29 |
|
30 | options?: Parameters<Validators<any>[K]> | Parameters<Validators<any>[K]>[0];
|
31 | });
|
32 | type CustomValidatorSchemaOptions = BaseValidatorSchemaOptions & {
|
33 | |
34 |
|
35 |
|
36 | custom: CustomValidator;
|
37 | };
|
38 | export type ExtensionValidatorSchemaOptions = boolean | BaseValidatorSchemaOptions;
|
39 | export type ValidatorsSchema = {
|
40 | [K in Exclude<keyof Validators<any>, 'not' | 'withMessage'>]?: ValidatorSchemaOptions<K>;
|
41 | };
|
42 | type SanitizerSchemaOptions<K extends keyof Sanitizers<any>> = boolean | {
|
43 | |
44 |
|
45 |
|
46 | options?: Parameters<Sanitizers<any>[K]> | Parameters<Sanitizers<any>[K]>[0];
|
47 | };
|
48 | type CustomSanitizerSchemaOptions = {
|
49 | |
50 |
|
51 |
|
52 | customSanitizer: CustomSanitizer;
|
53 | };
|
54 | export type ExtensionSanitizerSchemaOptions = true;
|
55 | export type SanitizersSchema = {
|
56 | [K in keyof Sanitizers<any>]?: SanitizerSchemaOptions<K>;
|
57 | };
|
58 | type BaseParamSchema = {
|
59 | |
60 |
|
61 |
|
62 |
|
63 | in?: Location | Location[];
|
64 | |
65 |
|
66 |
|
67 |
|
68 | errorMessage?: FieldMessageFactory | any;
|
69 | |
70 |
|
71 |
|
72 | optional?: boolean | {
|
73 | options?: OptionalOptions;
|
74 | };
|
75 | };
|
76 | export type DefaultSchemaKeys = keyof BaseParamSchema | keyof ValidatorsSchema | keyof SanitizersSchema;
|
77 |
|
78 |
|
79 |
|
80 | export type ParamSchema<T extends string = DefaultSchemaKeys> = BaseParamSchema & ValidatorsSchema & SanitizersSchema & {
|
81 | [K in T]?: K extends keyof BaseParamSchema ? BaseParamSchema[K] : K extends keyof ValidatorsSchema ? ValidatorsSchema[K] : K extends keyof SanitizersSchema ? SanitizersSchema[K] : CustomValidatorSchemaOptions | CustomSanitizerSchemaOptions;
|
82 | };
|
83 |
|
84 |
|
85 |
|
86 | export type Schema<T extends string = DefaultSchemaKeys> = Record<string, ParamSchema<T>>;
|
87 |
|
88 |
|
89 |
|
90 | export type RunnableValidationChains<C extends ValidationChainLike> = C[] & {
|
91 | run(req: Request): Promise<ResultWithContext[]>;
|
92 | };
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | export declare function createCheckSchema<C extends ValidationChainLike>(createChain: (fields?: string | string[], locations?: Location[], errorMessage?: any) => C, extraValidators?: (keyof C)[], extraSanitizers?: (keyof C)[]): <T extends string = DefaultSchemaKeys>(schema: Schema<T>, defaultLocations?: Location[]) => RunnableValidationChains<C>;
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 | export declare const checkSchema: <T extends string = DefaultSchemaKeys>(schema: Schema<T>, defaultLocations?: Location[]) => RunnableValidationChains<ValidationChain>;
|
108 | export {};
|