source: frontend/node_modules/ajv/lib/ajv.d.ts

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 13.0 KB
Line 
1declare 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
9declare 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
29declare 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 regExp?: (pattern: string) => RegExpLike;
207 }
208
209 interface RegExpLike {
210 test: (s: string) => boolean;
211 }
212
213 type FormatValidator = string | RegExp | ((data: string) => boolean | PromiseLike<any>);
214 type NumberFormatValidator = ((data: number) => boolean | PromiseLike<any>);
215
216 interface NumberFormatDefinition {
217 type: "number",
218 validate: NumberFormatValidator;
219 compare?: (data1: number, data2: number) => number;
220 async?: boolean;
221 }
222
223 interface StringFormatDefinition {
224 type?: "string",
225 validate: FormatValidator;
226 compare?: (data1: string, data2: string) => number;
227 async?: boolean;
228 }
229
230 type FormatDefinition = NumberFormatDefinition | StringFormatDefinition;
231
232 interface KeywordDefinition {
233 type?: string | Array<string>;
234 async?: boolean;
235 $data?: boolean;
236 errors?: boolean | string;
237 metaSchema?: object;
238 // schema: false makes validate not to expect schema (ValidateFunction)
239 schema?: boolean;
240 statements?: boolean;
241 dependencies?: Array<string>;
242 modifying?: boolean;
243 valid?: boolean;
244 // one and only one of the following properties should be present
245 validate?: SchemaValidateFunction | ValidateFunction;
246 compile?: (schema: any, parentSchema: object, it: CompilationContext) => ValidateFunction;
247 macro?: (schema: any, parentSchema: object, it: CompilationContext) => object | boolean;
248 inline?: (it: CompilationContext, keyword: string, schema: any, parentSchema: object) => string;
249 }
250
251 interface CompilationContext {
252 level: number;
253 dataLevel: number;
254 dataPathArr: string[];
255 schema: any;
256 schemaPath: string;
257 baseId: string;
258 async: boolean;
259 opts: Options;
260 formats: {
261 [index: string]: FormatDefinition | undefined;
262 };
263 keywords: {
264 [index: string]: KeywordDefinition | undefined;
265 };
266 compositeRule: boolean;
267 validate: (schema: object) => boolean;
268 util: {
269 copy(obj: any, target?: any): any;
270 toHash(source: string[]): { [index: string]: true | undefined };
271 equal(obj: any, target: any): boolean;
272 getProperty(str: string): string;
273 schemaHasRules(schema: object, rules: any): string;
274 escapeQuotes(str: string): string;
275 toQuotedString(str: string): string;
276 getData(jsonPointer: string, dataLevel: number, paths: string[]): string;
277 escapeJsonPointer(str: string): string;
278 unescapeJsonPointer(str: string): string;
279 escapeFragment(str: string): string;
280 unescapeFragment(str: string): string;
281 };
282 self: Ajv;
283 }
284
285 interface SchemaValidateFunction {
286 (
287 schema: any,
288 data: any,
289 parentSchema?: object,
290 dataPath?: string,
291 parentData?: object | Array<any>,
292 parentDataProperty?: string | number,
293 rootData?: object | Array<any>
294 ): boolean | PromiseLike<any>;
295 errors?: Array<ErrorObject>;
296 }
297
298 interface ErrorsTextOptions {
299 separator?: string;
300 dataVar?: string;
301 }
302
303 interface ErrorObject {
304 keyword: string;
305 dataPath: string;
306 schemaPath: string;
307 params: ErrorParameters;
308 // Added to validation errors of propertyNames keyword schema
309 propertyName?: string;
310 // Excluded if messages set to false.
311 message?: string;
312 // These are added with the `verbose` option.
313 schema?: any;
314 parentSchema?: object;
315 data?: any;
316 }
317
318 type ErrorParameters = RefParams | LimitParams | AdditionalPropertiesParams |
319 DependenciesParams | FormatParams | ComparisonParams |
320 MultipleOfParams | PatternParams | RequiredParams |
321 TypeParams | UniqueItemsParams | CustomParams |
322 PatternRequiredParams | PropertyNamesParams |
323 IfParams | SwitchParams | NoParams | EnumParams;
324
325 interface RefParams {
326 ref: string;
327 }
328
329 interface LimitParams {
330 limit: number;
331 }
332
333 interface AdditionalPropertiesParams {
334 additionalProperty: string;
335 }
336
337 interface DependenciesParams {
338 property: string;
339 missingProperty: string;
340 depsCount: number;
341 deps: string;
342 }
343
344 interface FormatParams {
345 format: string
346 }
347
348 interface ComparisonParams {
349 comparison: string;
350 limit: number | string;
351 exclusive: boolean;
352 }
353
354 interface MultipleOfParams {
355 multipleOf: number;
356 }
357
358 interface PatternParams {
359 pattern: string;
360 }
361
362 interface RequiredParams {
363 missingProperty: string;
364 }
365
366 interface TypeParams {
367 type: string;
368 }
369
370 interface UniqueItemsParams {
371 i: number;
372 j: number;
373 }
374
375 interface CustomParams {
376 keyword: string;
377 }
378
379 interface PatternRequiredParams {
380 missingPattern: string;
381 }
382
383 interface PropertyNamesParams {
384 propertyName: string;
385 }
386
387 interface IfParams {
388 failingKeyword: string;
389 }
390
391 interface SwitchParams {
392 caseIndex: number;
393 }
394
395 interface NoParams { }
396
397 interface EnumParams {
398 allowedValues: Array<any>;
399 }
400}
401
402export = ajv;
Note: See TracBrowser for help on using the repository browser.