UNPKG

2.01 kBTypeScriptView Raw
1/**
2 * Validation schema is a decorator-free way of validation of your objects.
3 * Also using validation schemas makes this library to be easily used with es6/es5.
4 */
5export interface ValidationSchema {
6 /**
7 * Schema name. This is required, because we tell validator to validate by this schema using its name.
8 */
9 name: string;
10 /**
11 * Validated properties.
12 */
13 properties: {
14 /**
15 * Name of the object's property to be validated which holds an array of validation constraints.
16 */
17 [propertyName: string]: {
18 /**
19 * Validation type. Should be one of the ValidationTypes value.
20 */
21 type: string;
22 /**
23 * Constraints set by validation type.
24 */
25 constraints?: any[];
26 /**
27 * Error message used to be used on validation fail.
28 * You can use "$value" to use value that was failed by validation.
29 * You can use "$constraint1" and "$constraint2" keys in the message string,
30 * and they will be replaced with constraint values if they exist.
31 * Message can be either string, either a function that returns a string.
32 * Second option allows to use values and custom messages depend of them.
33 */
34 message?: string | ((value?: any, constraint1?: any, constraint2?: any) => string);
35 /**
36 * Specifies if validated value is an array and each of its item must be validated.
37 */
38 each?: boolean;
39 /**
40 * Indicates if validation must be performed always, no matter of validation groups used.
41 */
42 always?: boolean;
43 /**
44 * Validation groups used for this validation.
45 */
46 groups?: string[];
47 /**
48 * Specific validation type options.
49 */
50 options?: any;
51 }[];
52 };
53}
54
\No newline at end of file