1 | import * as Joi from "@hapi/joi";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | export declare class SchemaBuilder {
|
8 | keys: any;
|
9 | lastKey: string;
|
10 | constructor();
|
11 | /**
|
12 | * Generate the final Joi Object Schema
|
13 | */
|
14 | build(): Joi.ObjectSchema;
|
15 | /**
|
16 | * General method, that can be used with the Joi functions
|
17 | */
|
18 | general(key: string, spec: any): SchemaBuilder;
|
19 | /**
|
20 | * Add an optional string to the Schema
|
21 | * @param key the key
|
22 | * @param min minimum length of the string
|
23 | * @param max maximum length of the string
|
24 | * @return the schema builder
|
25 | */
|
26 | stringOptional(key: string, min?: number, max?: number): SchemaBuilder;
|
27 | /**
|
28 | * Add a required string to the Schema
|
29 | * @param key the key
|
30 | * @param min minimum length of the string
|
31 | * @param max maximum length of the string
|
32 | * @return the schema builder
|
33 | */
|
34 | string(key: string, min?: number, max?: number): SchemaBuilder;
|
35 | /**
|
36 | * Add a required email to the Schema
|
37 | * @param key the key
|
38 | * @return the schema builder
|
39 | */
|
40 | email(key: string): SchemaBuilder;
|
41 | /**
|
42 | * Add an optional email to the Schema
|
43 | * @param key the key
|
44 | * @return the schema builder
|
45 | */
|
46 | emailOptional(key: string): SchemaBuilder;
|
47 | /**
|
48 | * Add a required password to the Schema.
|
49 | * The password will be validated using the following regex:
|
50 | * ^[0-9a-zA-Z\|\!\"\£\$\%\&\/\(\)\=\?\^\,\;\.\:\-\_\\\~]{6,}$
|
51 | * @param key the key
|
52 | * @return the schema builder
|
53 | */
|
54 | password(key: string): SchemaBuilder;
|
55 | |
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | passwordOptional(key: string): SchemaBuilder;
|
63 | |
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 | numberOptional(key: string, min?: number, max?: number): SchemaBuilder;
|
71 | |
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 | number(key: string, min?: number, max?: number): SchemaBuilder;
|
79 | |
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | integerOptional(key: string, min?: number, max?: number): SchemaBuilder;
|
87 | |
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | integer(key: string, min?: number, max?: number): SchemaBuilder;
|
95 | |
96 |
|
97 |
|
98 |
|
99 |
|
100 | dateOptional(key: string): SchemaBuilder;
|
101 | |
102 |
|
103 |
|
104 |
|
105 |
|
106 | date(key: string): SchemaBuilder;
|
107 | arrayOfStrings(key: string): SchemaBuilder;
|
108 | arrayOfStringsOptional(key: string): SchemaBuilder;
|
109 | |
110 |
|
111 |
|
112 |
|
113 |
|
114 | withLabel(label: string): SchemaBuilder;
|
115 | }
|
116 |
|
117 |
|
118 |
|
119 | export interface ValidationError {
|
120 | name: string;
|
121 | message: string;
|
122 | }
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 | export declare class ValidateObject<T> {
|
129 | private _obj;
|
130 | private schema;
|
131 | private valid;
|
132 | |
133 |
|
134 |
|
135 |
|
136 |
|
137 | constructor(obj: any, schema: Joi.Schema, locales: string[]);
|
138 | private validate;
|
139 | /**
|
140 | * Verify that the object respect the schema.
|
141 | * @return true if the object is valid, false otherwise.
|
142 | */
|
143 | get isValid(): boolean;
|
144 | /**
|
145 | * Unwrap the object (can be valid or not!)
|
146 | * @return the unwrapped object
|
147 | */
|
148 | get obj(): T;
|
149 | /**
|
150 | * Getter that returns an array of validation errors.
|
151 | * @return an array of validation errors. It can not be null.
|
152 | */
|
153 | get errors(): ValidationError[];
|
154 | /**
|
155 | * Getter that returns a map of errors. This prop contains the save information
|
156 | * as the `errors` prop, but with a different format.
|
157 | * @return a map or localized errors.
|
158 | */
|
159 | get errorsMap(): any;
|
160 | }
|