cc2881b33bb36be496535a6c10fb54929521116d
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / ajv / lib / ajv.d.ts
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   }
141
142   interface CustomLogger {
143     log(...args: any[]): any;
144     warn(...args: any[]): any;
145     error(...args: any[]): any;
146   }
147
148   interface ValidateFunction {
149     (
150       data: any,
151       dataPath?: string,
152       parentData?: object | Array<any>,
153       parentDataProperty?: string | number,
154       rootData?: object | Array<any>
155     ): boolean | PromiseLike<any>;
156     schema?: object | boolean;
157     errors?: null | Array<ErrorObject>;
158     refs?: object;
159     refVal?: Array<any>;
160     root?: ValidateFunction | object;
161     $async?: true;
162     source?: object;
163   }
164
165   interface Options {
166     $data?: boolean;
167     allErrors?: boolean;
168     verbose?: boolean;
169     jsonPointers?: boolean;
170     uniqueItems?: boolean;
171     unicode?: boolean;
172     format?: false | string;
173     formats?: object;
174     keywords?: object;
175     unknownFormats?: true | string[] | 'ignore';
176     schemas?: Array<object> | object;
177     schemaId?: '$id' | 'id' | 'auto';
178     missingRefs?: true | 'ignore' | 'fail';
179     extendRefs?: true | 'ignore' | 'fail';
180     loadSchema?: (uri: string, cb?: (err: Error, schema: object) => void) => PromiseLike<object | boolean>;
181     removeAdditional?: boolean | 'all' | 'failing';
182     useDefaults?: boolean | 'empty' | 'shared';
183     coerceTypes?: boolean | 'array';
184     strictDefaults?: boolean | 'log';
185     strictKeywords?: boolean | 'log';
186     strictNumbers?: boolean;
187     async?: boolean | string;
188     transpile?: string | ((code: string) => string);
189     meta?: boolean | object;
190     validateSchema?: boolean | 'log';
191     addUsedSchema?: boolean;
192     inlineRefs?: boolean | number;
193     passContext?: boolean;
194     loopRequired?: number;
195     ownProperties?: boolean;
196     multipleOfPrecision?: boolean | number;
197     errorDataPath?: string,
198     messages?: boolean;
199     sourceCode?: boolean;
200     processCode?: (code: string, schema: object) => string;
201     cache?: object;
202     logger?: CustomLogger | false;
203     nullable?: boolean;
204     serialize?: ((schema: object | boolean) => any) | false;
205   }
206
207   type FormatValidator = string | RegExp | ((data: string) => boolean | PromiseLike<any>);
208   type NumberFormatValidator = ((data: number) => boolean | PromiseLike<any>);
209
210   interface NumberFormatDefinition {
211     type: "number",
212     validate: NumberFormatValidator;
213     compare?: (data1: number, data2: number) => number;
214     async?: boolean;
215   }
216
217   interface StringFormatDefinition {
218     type?: "string",
219     validate: FormatValidator;
220     compare?: (data1: string, data2: string) => number;
221     async?: boolean;
222   }
223
224   type FormatDefinition = NumberFormatDefinition | StringFormatDefinition;
225
226   interface KeywordDefinition {
227     type?: string | Array<string>;
228     async?: boolean;
229     $data?: boolean;
230     errors?: boolean | string;
231     metaSchema?: object;
232     // schema: false makes validate not to expect schema (ValidateFunction)
233     schema?: boolean;
234     statements?: boolean;
235     dependencies?: Array<string>;
236     modifying?: boolean;
237     valid?: boolean;
238     // one and only one of the following properties should be present
239     validate?: SchemaValidateFunction | ValidateFunction;
240     compile?: (schema: any, parentSchema: object, it: CompilationContext) => ValidateFunction;
241     macro?: (schema: any, parentSchema: object, it: CompilationContext) => object | boolean;
242     inline?: (it: CompilationContext, keyword: string, schema: any, parentSchema: object) => string;
243   }
244
245   interface CompilationContext {
246     level: number;
247     dataLevel: number;
248     dataPathArr: string[];
249     schema: any;
250     schemaPath: string;
251     baseId: string;
252     async: boolean;
253     opts: Options;
254     formats: {
255       [index: string]: FormatDefinition | undefined;
256     };
257     keywords: {
258       [index: string]: KeywordDefinition | undefined;
259     };
260     compositeRule: boolean;
261     validate: (schema: object) => boolean;
262     util: {
263       copy(obj: any, target?: any): any;
264       toHash(source: string[]): { [index: string]: true | undefined };
265       equal(obj: any, target: any): boolean;
266       getProperty(str: string): string;
267       schemaHasRules(schema: object, rules: any): string;
268       escapeQuotes(str: string): string;
269       toQuotedString(str: string): string;
270       getData(jsonPointer: string, dataLevel: number, paths: string[]): string;
271       escapeJsonPointer(str: string): string;
272       unescapeJsonPointer(str: string): string;
273       escapeFragment(str: string): string;
274       unescapeFragment(str: string): string;
275     };
276     self: Ajv;
277   }
278
279   interface SchemaValidateFunction {
280     (
281       schema: any,
282       data: any,
283       parentSchema?: object,
284       dataPath?: string,
285       parentData?: object | Array<any>,
286       parentDataProperty?: string | number,
287       rootData?: object | Array<any>
288     ): boolean | PromiseLike<any>;
289     errors?: Array<ErrorObject>;
290   }
291
292   interface ErrorsTextOptions {
293     separator?: string;
294     dataVar?: string;
295   }
296
297   interface ErrorObject {
298     keyword: string;
299     dataPath: string;
300     schemaPath: string;
301     params: ErrorParameters;
302     // Added to validation errors of propertyNames keyword schema
303     propertyName?: string;
304     // Excluded if messages set to false.
305     message?: string;
306     // These are added with the `verbose` option.
307     schema?: any;
308     parentSchema?: object;
309     data?: any;
310   }
311
312   type ErrorParameters = RefParams | LimitParams | AdditionalPropertiesParams |
313     DependenciesParams | FormatParams | ComparisonParams |
314     MultipleOfParams | PatternParams | RequiredParams |
315     TypeParams | UniqueItemsParams | CustomParams |
316     PatternRequiredParams | PropertyNamesParams |
317     IfParams | SwitchParams | NoParams | EnumParams;
318
319   interface RefParams {
320     ref: string;
321   }
322
323   interface LimitParams {
324     limit: number;
325   }
326
327   interface AdditionalPropertiesParams {
328     additionalProperty: string;
329   }
330
331   interface DependenciesParams {
332     property: string;
333     missingProperty: string;
334     depsCount: number;
335     deps: string;
336   }
337
338   interface FormatParams {
339     format: string
340   }
341
342   interface ComparisonParams {
343     comparison: string;
344     limit: number | string;
345     exclusive: boolean;
346   }
347
348   interface MultipleOfParams {
349     multipleOf: number;
350   }
351
352   interface PatternParams {
353     pattern: string;
354   }
355
356   interface RequiredParams {
357     missingProperty: string;
358   }
359
360   interface TypeParams {
361     type: string;
362   }
363
364   interface UniqueItemsParams {
365     i: number;
366     j: number;
367   }
368
369   interface CustomParams {
370     keyword: string;
371   }
372
373   interface PatternRequiredParams {
374     missingPattern: string;
375   }
376
377   interface PropertyNamesParams {
378     propertyName: string;
379   }
380
381   interface IfParams {
382     failingKeyword: string;
383   }
384
385   interface SwitchParams {
386     caseIndex: number;
387   }
388
389   interface NoParams { }
390
391   interface EnumParams {
392     allowedValues: Array<any>;
393   }
394 }
395
396 export = ajv;