1 | declare var ajv: {
|
---|
2 | (options?: ajv.Options): ajv.Ajv;
|
---|
3 | new(options?: ajv.Options): ajv.Ajv;
|
---|
4 | ValidationError: typeof AjvErrors.ValidationError;
|
---|
5 | MissingRefError: typeof AjvErrors.MissingRefError;
|
---|
6 | $dataMetaSchema: object;
|
---|
7 | }
|
---|
8 |
|
---|
9 | declare namespace AjvErrors {
|
---|
10 | class ValidationError extends Error {
|
---|
11 | constructor(errors: Array<ajv.ErrorObject>);
|
---|
12 |
|
---|
13 | message: string;
|
---|
14 | errors: Array<ajv.ErrorObject>;
|
---|
15 | ajv: true;
|
---|
16 | validation: true;
|
---|
17 | }
|
---|
18 |
|
---|
19 | class MissingRefError extends Error {
|
---|
20 | constructor(baseId: string, ref: string, message?: string);
|
---|
21 | static message: (baseId: string, ref: string) => string;
|
---|
22 |
|
---|
23 | message: string;
|
---|
24 | missingRef: string;
|
---|
25 | missingSchema: string;
|
---|
26 | }
|
---|
27 | }
|
---|
28 |
|
---|
29 | declare namespace ajv {
|
---|
30 | type ValidationError = AjvErrors.ValidationError;
|
---|
31 |
|
---|
32 | type MissingRefError = AjvErrors.MissingRefError;
|
---|
33 |
|
---|
34 | interface Ajv {
|
---|
35 | /**
|
---|
36 | * Validate data using schema
|
---|
37 | * Schema will be compiled and cached (using serialized JSON as key, [fast-json-stable-stringify](https://github.com/epoberezkin/fast-json-stable-stringify) is used to serialize by default).
|
---|
38 | * @param {string|object|Boolean} schemaKeyRef key, ref or schema object
|
---|
39 | * @param {Any} data to be validated
|
---|
40 | * @return {Boolean} validation result. Errors from the last validation will be available in `ajv.errors` (and also in compiled schema: `schema.errors`).
|
---|
41 | */
|
---|
42 | validate(schemaKeyRef: object | string | boolean, data: any): boolean | PromiseLike<any>;
|
---|
43 | /**
|
---|
44 | * Create validating function for passed schema.
|
---|
45 | * @param {object|Boolean} schema schema object
|
---|
46 | * @return {Function} validating function
|
---|
47 | */
|
---|
48 | compile(schema: object | boolean): ValidateFunction;
|
---|
49 | /**
|
---|
50 | * Creates validating function for passed schema with asynchronous loading of missing schemas.
|
---|
51 | * `loadSchema` option should be a function that accepts schema uri and node-style callback.
|
---|
52 | * @this Ajv
|
---|
53 | * @param {object|Boolean} schema schema object
|
---|
54 | * @param {Boolean} meta optional true to compile meta-schema; this parameter can be skipped
|
---|
55 | * @param {Function} callback optional node-style callback, it is always called with 2 parameters: error (or null) and validating function.
|
---|
56 | * @return {PromiseLike<ValidateFunction>} validating function
|
---|
57 | */
|
---|
58 | compileAsync(schema: object | boolean, meta?: Boolean, callback?: (err: Error, validate: ValidateFunction) => any): PromiseLike<ValidateFunction>;
|
---|
59 | /**
|
---|
60 | * Adds schema to the instance.
|
---|
61 | * @param {object|Array} schema schema or array of schemas. If array is passed, `key` and other parameters will be ignored.
|
---|
62 | * @param {string} key Optional schema key. Can be passed to `validate` method instead of schema object or id/ref. One schema per instance can have empty `id` and `key`.
|
---|
63 | * @return {Ajv} this for method chaining
|
---|
64 | */
|
---|
65 | addSchema(schema: Array<object> | object, key?: string): Ajv;
|
---|
66 | /**
|
---|
67 | * Add schema that will be used to validate other schemas
|
---|
68 | * options in META_IGNORE_OPTIONS are alway set to false
|
---|
69 | * @param {object} schema schema object
|
---|
70 | * @param {string} key optional schema key
|
---|
71 | * @return {Ajv} this for method chaining
|
---|
72 | */
|
---|
73 | addMetaSchema(schema: object, key?: string): Ajv;
|
---|
74 | /**
|
---|
75 | * Validate schema
|
---|
76 | * @param {object|Boolean} schema schema to validate
|
---|
77 | * @return {Boolean} true if schema is valid
|
---|
78 | */
|
---|
79 | validateSchema(schema: object | boolean): boolean;
|
---|
80 | /**
|
---|
81 | * Get compiled schema from the instance by `key` or `ref`.
|
---|
82 | * @param {string} keyRef `key` that was passed to `addSchema` or full schema reference (`schema.id` or resolved id).
|
---|
83 | * @return {Function} schema validating function (with property `schema`). Returns undefined if keyRef can't be resolved to an existing schema.
|
---|
84 | */
|
---|
85 | getSchema(keyRef: string): ValidateFunction | undefined;
|
---|
86 | /**
|
---|
87 | * Remove cached schema(s).
|
---|
88 | * If no parameter is passed all schemas but meta-schemas are removed.
|
---|
89 | * If RegExp is passed all schemas with key/id matching pattern but meta-schemas are removed.
|
---|
90 | * Even if schema is referenced by other schemas it still can be removed as other schemas have local references.
|
---|
91 | * @param {string|object|RegExp|Boolean} schemaKeyRef key, ref, pattern to match key/ref or schema object
|
---|
92 | * @return {Ajv} this for method chaining
|
---|
93 | */
|
---|
94 | removeSchema(schemaKeyRef?: object | string | RegExp | boolean): Ajv;
|
---|
95 | /**
|
---|
96 | * Add custom format
|
---|
97 | * @param {string} name format name
|
---|
98 | * @param {string|RegExp|Function} format string is converted to RegExp; function should return boolean (true when valid)
|
---|
99 | * @return {Ajv} this for method chaining
|
---|
100 | */
|
---|
101 | addFormat(name: string, format: FormatValidator | FormatDefinition): Ajv;
|
---|
102 | /**
|
---|
103 | * Define custom keyword
|
---|
104 | * @this Ajv
|
---|
105 | * @param {string} keyword custom keyword, should be a valid identifier, should be different from all standard, custom and macro keywords.
|
---|
106 | * @param {object} definition keyword definition object with properties `type` (type(s) which the keyword applies to), `validate` or `compile`.
|
---|
107 | * @return {Ajv} this for method chaining
|
---|
108 | */
|
---|
109 | addKeyword(keyword: string, definition: KeywordDefinition): Ajv;
|
---|
110 | /**
|
---|
111 | * Get keyword definition
|
---|
112 | * @this Ajv
|
---|
113 | * @param {string} keyword pre-defined or custom keyword.
|
---|
114 | * @return {object|Boolean} custom keyword definition, `true` if it is a predefined keyword, `false` otherwise.
|
---|
115 | */
|
---|
116 | getKeyword(keyword: string): object | boolean;
|
---|
117 | /**
|
---|
118 | * Remove keyword
|
---|
119 | * @this Ajv
|
---|
120 | * @param {string} keyword pre-defined or custom keyword.
|
---|
121 | * @return {Ajv} this for method chaining
|
---|
122 | */
|
---|
123 | removeKeyword(keyword: string): Ajv;
|
---|
124 | /**
|
---|
125 | * Validate keyword
|
---|
126 | * @this Ajv
|
---|
127 | * @param {object} definition keyword definition object
|
---|
128 | * @param {boolean} throwError true to throw exception if definition is invalid
|
---|
129 | * @return {boolean} validation result
|
---|
130 | */
|
---|
131 | validateKeyword(definition: KeywordDefinition, throwError: boolean): boolean;
|
---|
132 | /**
|
---|
133 | * Convert array of error message objects to string
|
---|
134 | * @param {Array<object>} errors optional array of validation errors, if not passed errors from the instance are used.
|
---|
135 | * @param {object} options optional options with properties `separator` and `dataVar`.
|
---|
136 | * @return {string} human readable string with all errors descriptions
|
---|
137 | */
|
---|
138 | errorsText(errors?: Array<ErrorObject> | null, options?: ErrorsTextOptions): string;
|
---|
139 | errors?: Array<ErrorObject> | null;
|
---|
140 | _opts: Options;
|
---|
141 | }
|
---|
142 |
|
---|
143 | interface CustomLogger {
|
---|
144 | log(...args: any[]): any;
|
---|
145 | warn(...args: any[]): any;
|
---|
146 | error(...args: any[]): any;
|
---|
147 | }
|
---|
148 |
|
---|
149 | interface ValidateFunction {
|
---|
150 | (
|
---|
151 | data: any,
|
---|
152 | dataPath?: string,
|
---|
153 | parentData?: object | Array<any>,
|
---|
154 | parentDataProperty?: string | number,
|
---|
155 | rootData?: object | Array<any>
|
---|
156 | ): boolean | PromiseLike<any>;
|
---|
157 | schema?: object | boolean;
|
---|
158 | errors?: null | Array<ErrorObject>;
|
---|
159 | refs?: object;
|
---|
160 | refVal?: Array<any>;
|
---|
161 | root?: ValidateFunction | object;
|
---|
162 | $async?: true;
|
---|
163 | source?: object;
|
---|
164 | }
|
---|
165 |
|
---|
166 | interface Options {
|
---|
167 | $data?: boolean;
|
---|
168 | allErrors?: boolean;
|
---|
169 | verbose?: boolean;
|
---|
170 | jsonPointers?: boolean;
|
---|
171 | uniqueItems?: boolean;
|
---|
172 | unicode?: boolean;
|
---|
173 | format?: false | string;
|
---|
174 | formats?: object;
|
---|
175 | keywords?: object;
|
---|
176 | unknownFormats?: true | string[] | 'ignore';
|
---|
177 | schemas?: Array<object> | object;
|
---|
178 | schemaId?: '$id' | 'id' | 'auto';
|
---|
179 | missingRefs?: true | 'ignore' | 'fail';
|
---|
180 | extendRefs?: true | 'ignore' | 'fail';
|
---|
181 | loadSchema?: (uri: string, cb?: (err: Error, schema: object) => void) => PromiseLike<object | boolean>;
|
---|
182 | removeAdditional?: boolean | 'all' | 'failing';
|
---|
183 | useDefaults?: boolean | 'empty' | 'shared';
|
---|
184 | coerceTypes?: boolean | 'array';
|
---|
185 | strictDefaults?: boolean | 'log';
|
---|
186 | strictKeywords?: boolean | 'log';
|
---|
187 | strictNumbers?: boolean;
|
---|
188 | async?: boolean | string;
|
---|
189 | transpile?: string | ((code: string) => string);
|
---|
190 | meta?: boolean | object;
|
---|
191 | validateSchema?: boolean | 'log';
|
---|
192 | addUsedSchema?: boolean;
|
---|
193 | inlineRefs?: boolean | number;
|
---|
194 | passContext?: boolean;
|
---|
195 | loopRequired?: number;
|
---|
196 | ownProperties?: boolean;
|
---|
197 | multipleOfPrecision?: boolean | number;
|
---|
198 | errorDataPath?: string,
|
---|
199 | messages?: boolean;
|
---|
200 | sourceCode?: boolean;
|
---|
201 | processCode?: (code: string, schema: object) => string;
|
---|
202 | cache?: object;
|
---|
203 | logger?: CustomLogger | false;
|
---|
204 | nullable?: boolean;
|
---|
205 | serialize?: ((schema: object | boolean) => any) | false;
|
---|
206 | }
|
---|
207 |
|
---|
208 | type FormatValidator = string | RegExp | ((data: string) => boolean | PromiseLike<any>);
|
---|
209 | type NumberFormatValidator = ((data: number) => boolean | PromiseLike<any>);
|
---|
210 |
|
---|
211 | interface NumberFormatDefinition {
|
---|
212 | type: "number",
|
---|
213 | validate: NumberFormatValidator;
|
---|
214 | compare?: (data1: number, data2: number) => number;
|
---|
215 | async?: boolean;
|
---|
216 | }
|
---|
217 |
|
---|
218 | interface StringFormatDefinition {
|
---|
219 | type?: "string",
|
---|
220 | validate: FormatValidator;
|
---|
221 | compare?: (data1: string, data2: string) => number;
|
---|
222 | async?: boolean;
|
---|
223 | }
|
---|
224 |
|
---|
225 | type FormatDefinition = NumberFormatDefinition | StringFormatDefinition;
|
---|
226 |
|
---|
227 | interface KeywordDefinition {
|
---|
228 | type?: string | Array<string>;
|
---|
229 | async?: boolean;
|
---|
230 | $data?: boolean;
|
---|
231 | errors?: boolean | string;
|
---|
232 | metaSchema?: object;
|
---|
233 | // schema: false makes validate not to expect schema (ValidateFunction)
|
---|
234 | schema?: boolean;
|
---|
235 | statements?: boolean;
|
---|
236 | dependencies?: Array<string>;
|
---|
237 | modifying?: boolean;
|
---|
238 | valid?: boolean;
|
---|
239 | // one and only one of the following properties should be present
|
---|
240 | validate?: SchemaValidateFunction | ValidateFunction;
|
---|
241 | compile?: (schema: any, parentSchema: object, it: CompilationContext) => ValidateFunction;
|
---|
242 | macro?: (schema: any, parentSchema: object, it: CompilationContext) => object | boolean;
|
---|
243 | inline?: (it: CompilationContext, keyword: string, schema: any, parentSchema: object) => string;
|
---|
244 | }
|
---|
245 |
|
---|
246 | interface CompilationContext {
|
---|
247 | level: number;
|
---|
248 | dataLevel: number;
|
---|
249 | dataPathArr: string[];
|
---|
250 | schema: any;
|
---|
251 | schemaPath: string;
|
---|
252 | baseId: string;
|
---|
253 | async: boolean;
|
---|
254 | opts: Options;
|
---|
255 | formats: {
|
---|
256 | [index: string]: FormatDefinition | undefined;
|
---|
257 | };
|
---|
258 | keywords: {
|
---|
259 | [index: string]: KeywordDefinition | undefined;
|
---|
260 | };
|
---|
261 | compositeRule: boolean;
|
---|
262 | validate: (schema: object) => boolean;
|
---|
263 | util: {
|
---|
264 | copy(obj: any, target?: any): any;
|
---|
265 | toHash(source: string[]): { [index: string]: true | undefined };
|
---|
266 | equal(obj: any, target: any): boolean;
|
---|
267 | getProperty(str: string): string;
|
---|
268 | schemaHasRules(schema: object, rules: any): string;
|
---|
269 | escapeQuotes(str: string): string;
|
---|
270 | toQuotedString(str: string): string;
|
---|
271 | getData(jsonPointer: string, dataLevel: number, paths: string[]): string;
|
---|
272 | escapeJsonPointer(str: string): string;
|
---|
273 | unescapeJsonPointer(str: string): string;
|
---|
274 | escapeFragment(str: string): string;
|
---|
275 | unescapeFragment(str: string): string;
|
---|
276 | };
|
---|
277 | self: Ajv;
|
---|
278 | }
|
---|
279 |
|
---|
280 | interface SchemaValidateFunction {
|
---|
281 | (
|
---|
282 | schema: any,
|
---|
283 | data: any,
|
---|
284 | parentSchema?: object,
|
---|
285 | dataPath?: string,
|
---|
286 | parentData?: object | Array<any>,
|
---|
287 | parentDataProperty?: string | number,
|
---|
288 | rootData?: object | Array<any>
|
---|
289 | ): boolean | PromiseLike<any>;
|
---|
290 | errors?: Array<ErrorObject>;
|
---|
291 | }
|
---|
292 |
|
---|
293 | interface ErrorsTextOptions {
|
---|
294 | separator?: string;
|
---|
295 | dataVar?: string;
|
---|
296 | }
|
---|
297 |
|
---|
298 | interface ErrorObject {
|
---|
299 | keyword: string;
|
---|
300 | dataPath: string;
|
---|
301 | schemaPath: string;
|
---|
302 | params: ErrorParameters;
|
---|
303 | // Added to validation errors of propertyNames keyword schema
|
---|
304 | propertyName?: string;
|
---|
305 | // Excluded if messages set to false.
|
---|
306 | message?: string;
|
---|
307 | // These are added with the `verbose` option.
|
---|
308 | schema?: any;
|
---|
309 | parentSchema?: object;
|
---|
310 | data?: any;
|
---|
311 | }
|
---|
312 |
|
---|
313 | type ErrorParameters = RefParams | LimitParams | AdditionalPropertiesParams |
|
---|
314 | DependenciesParams | FormatParams | ComparisonParams |
|
---|
315 | MultipleOfParams | PatternParams | RequiredParams |
|
---|
316 | TypeParams | UniqueItemsParams | CustomParams |
|
---|
317 | PatternRequiredParams | PropertyNamesParams |
|
---|
318 | IfParams | SwitchParams | NoParams | EnumParams;
|
---|
319 |
|
---|
320 | interface RefParams {
|
---|
321 | ref: string;
|
---|
322 | }
|
---|
323 |
|
---|
324 | interface LimitParams {
|
---|
325 | limit: number;
|
---|
326 | }
|
---|
327 |
|
---|
328 | interface AdditionalPropertiesParams {
|
---|
329 | additionalProperty: string;
|
---|
330 | }
|
---|
331 |
|
---|
332 | interface DependenciesParams {
|
---|
333 | property: string;
|
---|
334 | missingProperty: string;
|
---|
335 | depsCount: number;
|
---|
336 | deps: string;
|
---|
337 | }
|
---|
338 |
|
---|
339 | interface FormatParams {
|
---|
340 | format: string
|
---|
341 | }
|
---|
342 |
|
---|
343 | interface ComparisonParams {
|
---|
344 | comparison: string;
|
---|
345 | limit: number | string;
|
---|
346 | exclusive: boolean;
|
---|
347 | }
|
---|
348 |
|
---|
349 | interface MultipleOfParams {
|
---|
350 | multipleOf: number;
|
---|
351 | }
|
---|
352 |
|
---|
353 | interface PatternParams {
|
---|
354 | pattern: string;
|
---|
355 | }
|
---|
356 |
|
---|
357 | interface RequiredParams {
|
---|
358 | missingProperty: string;
|
---|
359 | }
|
---|
360 |
|
---|
361 | interface TypeParams {
|
---|
362 | type: string;
|
---|
363 | }
|
---|
364 |
|
---|
365 | interface UniqueItemsParams {
|
---|
366 | i: number;
|
---|
367 | j: number;
|
---|
368 | }
|
---|
369 |
|
---|
370 | interface CustomParams {
|
---|
371 | keyword: string;
|
---|
372 | }
|
---|
373 |
|
---|
374 | interface PatternRequiredParams {
|
---|
375 | missingPattern: string;
|
---|
376 | }
|
---|
377 |
|
---|
378 | interface PropertyNamesParams {
|
---|
379 | propertyName: string;
|
---|
380 | }
|
---|
381 |
|
---|
382 | interface IfParams {
|
---|
383 | failingKeyword: string;
|
---|
384 | }
|
---|
385 |
|
---|
386 | interface SwitchParams {
|
---|
387 | caseIndex: number;
|
---|
388 | }
|
---|
389 |
|
---|
390 | interface NoParams { }
|
---|
391 |
|
---|
392 | interface EnumParams {
|
---|
393 | allowedValues: Array<any>;
|
---|
394 | }
|
---|
395 | }
|
---|
396 |
|
---|
397 | export = ajv;
|
---|