Initial commit
[yaffs-website] / 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 }
5
6 declare namespace ajv {
7   interface Ajv {
8     /**
9     * Validate data using schema
10     * Schema will be compiled and cached (using serialized JSON as key. [json-stable-stringify](https://github.com/substack/json-stable-stringify) is used to serialize.
11     * @param  {String|Object} schemaKeyRef key, ref or schema object
12     * @param  {Any} data to be validated
13     * @return {Boolean} validation result. Errors from the last validation will be available in `ajv.errors` (and also in compiled schema: `schema.errors`).
14     */
15     validate(schemaKeyRef: Object | string, data: any): boolean;
16     /**
17     * Create validating function for passed schema.
18     * @param  {Object} schema schema object
19     * @return {Function} validating function
20     */
21     compile(schema: Object): ValidateFunction;
22     /**
23     * Creates validating function for passed schema with asynchronous loading of missing schemas.
24     * `loadSchema` option should be a function that accepts schema uri and node-style callback.
25     * @this  Ajv
26     * @param {Object}   schema schema object
27     * @param {Function} callback node-style callback, it is always called with 2 parameters: error (or null) and validating function.
28     */
29     compileAsync(schema: Object, callback: (err: Error, validate: ValidateFunction) => any): void;
30     /**
31     * Adds schema to the instance.
32     * @param {Object|Array} schema schema or array of schemas. If array is passed, `key` and other parameters will be ignored.
33     * @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`.
34     */
35     addSchema(schema: Array<Object> | Object, key?: string): void;
36     /**
37     * Add schema that will be used to validate other schemas
38     * options in META_IGNORE_OPTIONS are alway set to false
39     * @param {Object} schema schema object
40     * @param {String} key optional schema key
41     */
42     addMetaSchema(schema: Object, key?: string): void;
43     /**
44     * Validate schema
45     * @param {Object} schema schema to validate
46     * @return {Boolean} true if schema is valid
47     */
48     validateSchema(schema: Object): boolean;
49     /**
50     * Get compiled schema from the instance by `key` or `ref`.
51     * @param  {String} keyRef `key` that was passed to `addSchema` or full schema reference (`schema.id` or resolved id).
52     * @return {Function} schema validating function (with property `schema`).
53     */
54     getSchema(keyRef: string): ValidateFunction;
55     /**
56     * Remove cached schema(s).
57     * If no parameter is passed all schemas but meta-schemas are removed.
58     * If RegExp is passed all schemas with key/id matching pattern but meta-schemas are removed.
59     * Even if schema is referenced by other schemas it still can be removed as other schemas have local references.
60     * @param  {String|Object|RegExp} schemaKeyRef key, ref, pattern to match key/ref or schema object
61     */
62     removeSchema(schemaKeyRef?: Object | string | RegExp): void;
63     /**
64     * Add custom format
65     * @param {String} name format name
66     * @param {String|RegExp|Function} format string is converted to RegExp; function should return boolean (true when valid)
67     */
68     addFormat(name: string, format: FormatValidator | FormatDefinition): void;
69     /**
70     * Define custom keyword
71     * @this  Ajv
72     * @param {String} keyword custom keyword, should be a valid identifier, should be different from all standard, custom and macro keywords.
73     * @param {Object} definition keyword definition object with properties `type` (type(s) which the keyword applies to), `validate` or `compile`.
74     */
75     addKeyword(keyword: string, definition: KeywordDefinition): void;
76     /**
77     * Get keyword definition
78     * @this  Ajv
79     * @param {String} keyword pre-defined or custom keyword.
80     * @return {Object|Boolean} custom keyword definition, `true` if it is a predefined keyword, `false` otherwise.
81     */
82     getKeyword(keyword: string): Object | boolean;
83     /**
84     * Remove keyword
85     * @this  Ajv
86     * @param {String} keyword pre-defined or custom keyword.
87     */
88     removeKeyword(keyword: string): void;
89     /**
90     * Convert array of error message objects to string
91     * @param  {Array<Object>} errors optional array of validation errors, if not passed errors from the instance are used.
92     * @param  {Object} options optional options with properties `separator` and `dataVar`.
93     * @return {String} human readable string with all errors descriptions
94     */
95     errorsText(errors?: Array<ErrorObject>, options?: ErrorsTextOptions): string;
96     errors?: Array<ErrorObject>;
97   }
98
99   interface Thenable <R> {
100     then <U> (onFulfilled?: (value: R) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>): Thenable<U>;
101   }
102
103   interface ValidateFunction {
104     (
105       data: any,
106       dataPath?: string,
107       parentData?: Object | Array<any>,
108       parentDataProperty?: string | number,
109       rootData?: Object | Array<any>
110     ): boolean | Thenable<boolean>;
111     errors?: Array<ErrorObject>;
112     schema?: Object;
113   }
114
115   interface Options {
116     v5?: boolean;
117     allErrors?: boolean;
118     verbose?: boolean;
119     jsonPointers?: boolean;
120     uniqueItems?: boolean;
121     unicode?: boolean;
122     format?: string;
123     formats?: Object;
124     unknownFormats?: boolean | string | Array<string>;
125     schemas?: Array<Object> | Object;
126     ownProperties?: boolean;
127     missingRefs?: boolean | string;
128     loadSchema?: (uri: string, cb: (err: Error, schema: Object) => any) => any;
129     removeAdditional?: boolean | string;
130     useDefaults?: boolean | string;
131     coerceTypes?: boolean | string;
132     async?: boolean | string;
133     transpile?: string | ((code: string) => string);
134     meta?: boolean | Object;
135     validateSchema?: boolean | string;
136     addUsedSchema?: boolean;
137     inlineRefs?: boolean | number;
138     passContext?: boolean;
139     loopRequired?: number;
140     multipleOfPrecision?: number;
141     errorDataPath?: string;
142     messages?: boolean;
143     beautify?: boolean | Object;
144     cache?: Object;
145   }
146
147   type FormatValidator = string | RegExp | ((data: string) => boolean);
148
149   interface FormatDefinition {
150     validate: FormatValidator;
151     compare: (data1: string, data2: string) => number;
152     async?: boolean;
153   }
154
155   interface KeywordDefinition {
156     type?: string | Array<string>;
157     async?: boolean;
158     errors?: boolean | string;
159     // schema: false makes validate not to expect schema (ValidateFunction)
160     schema?: boolean;
161     modifying?: boolean;
162     valid?: boolean;
163     // one and only one of the following properties should be present
164     validate?: ValidateFunction | SchemaValidateFunction;
165     compile?: (schema: Object, parentSchema: Object) => ValidateFunction;
166     macro?: (schema: Object, parentSchema: Object) => Object;
167     inline?: (it: Object, keyword: string, schema: Object, parentSchema: Object) => string;
168   }
169
170   interface SchemaValidateFunction {
171     (
172       schema: Object,
173       data: any,
174       parentSchema?: Object,
175       dataPath?: string,
176       parentData?: Object | Array<any>,
177       parentDataProperty?: string | number
178     ): boolean | Thenable<boolean>;
179     errors?: Array<ErrorObject>;
180   }
181
182   interface ErrorsTextOptions {
183     separator?: string;
184     dataVar?: string;
185   }
186
187   interface ErrorObject {
188     keyword: string;
189     dataPath: string;
190     schemaPath: string;
191     params: ErrorParameters;
192     // Excluded if messages set to false.
193     message?: string;
194     // These are added with the `verbose` option.
195     schema?: Object;
196     parentSchema?: Object;
197     data?: any;
198   }
199
200   type ErrorParameters = RefParams | LimitParams | AdditionalPropertiesParams |
201                           DependenciesParams | FormatParams | ComparisonParams |
202                           MultipleOfParams | PatternParams | RequiredParams |
203                           TypeParams | UniqueItemsParams | CustomParams |
204                           PatternGroupsParams | PatternRequiredParams |
205                           SwitchParams | NoParams | EnumParams;
206
207   interface RefParams {
208     ref: string;
209   }
210
211   interface LimitParams {
212     limit: number;
213   }
214
215   interface AdditionalPropertiesParams {
216     additionalProperty: string;
217   }
218
219   interface DependenciesParams {
220     property: string;
221     missingProperty: string;
222     depsCount: number;
223     deps: string;
224   }
225
226   interface FormatParams {
227     format: string
228   }
229
230   interface ComparisonParams {
231     comparison: string;
232     limit: number | string;
233     exclusive: boolean;
234   }
235
236   interface MultipleOfParams {
237     multipleOf: number;
238   }
239
240   interface PatternParams {
241     pattern: string;
242   }
243
244   interface RequiredParams {
245     missingProperty: string;
246   }
247
248   interface TypeParams {
249     type: string;
250   }
251
252   interface UniqueItemsParams {
253     i: number;
254     j: number;
255   }
256
257   interface CustomParams {
258     keyword: string;
259   }
260
261   interface PatternGroupsParams {
262     reason: string;
263     limit: number;
264     pattern: string;
265   }
266
267   interface PatternRequiredParams {
268     missingPattern: string;
269   }
270
271   interface SwitchParams {
272     caseIndex: number;
273   }
274
275   interface NoParams {}
276
277   interface EnumParams {
278     allowedValues: Array<any>;
279   }
280 }
281
282 export = ajv;