Path: blob/master/node_modules/ajv/lib/ajv.d.ts
2591 views
declare var ajv: {1(options?: ajv.Options): ajv.Ajv;2new(options?: ajv.Options): ajv.Ajv;3ValidationError: typeof AjvErrors.ValidationError;4MissingRefError: typeof AjvErrors.MissingRefError;5$dataMetaSchema: object;6}78declare namespace AjvErrors {9class ValidationError extends Error {10constructor(errors: Array<ajv.ErrorObject>);1112message: string;13errors: Array<ajv.ErrorObject>;14ajv: true;15validation: true;16}1718class MissingRefError extends Error {19constructor(baseId: string, ref: string, message?: string);20static message: (baseId: string, ref: string) => string;2122message: string;23missingRef: string;24missingSchema: string;25}26}2728declare namespace ajv {29type ValidationError = AjvErrors.ValidationError;3031type MissingRefError = AjvErrors.MissingRefError;3233interface Ajv {34/**35* Validate data using schema36* 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).37* @param {string|object|Boolean} schemaKeyRef key, ref or schema object38* @param {Any} data to be validated39* @return {Boolean} validation result. Errors from the last validation will be available in `ajv.errors` (and also in compiled schema: `schema.errors`).40*/41validate(schemaKeyRef: object | string | boolean, data: any): boolean | PromiseLike<any>;42/**43* Create validating function for passed schema.44* @param {object|Boolean} schema schema object45* @return {Function} validating function46*/47compile(schema: object | boolean): ValidateFunction;48/**49* Creates validating function for passed schema with asynchronous loading of missing schemas.50* `loadSchema` option should be a function that accepts schema uri and node-style callback.51* @this Ajv52* @param {object|Boolean} schema schema object53* @param {Boolean} meta optional true to compile meta-schema; this parameter can be skipped54* @param {Function} callback optional node-style callback, it is always called with 2 parameters: error (or null) and validating function.55* @return {PromiseLike<ValidateFunction>} validating function56*/57compileAsync(schema: object | boolean, meta?: Boolean, callback?: (err: Error, validate: ValidateFunction) => any): PromiseLike<ValidateFunction>;58/**59* Adds schema to the instance.60* @param {object|Array} schema schema or array of schemas. If array is passed, `key` and other parameters will be ignored.61* @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`.62* @return {Ajv} this for method chaining63*/64addSchema(schema: Array<object> | object, key?: string): Ajv;65/**66* Add schema that will be used to validate other schemas67* options in META_IGNORE_OPTIONS are alway set to false68* @param {object} schema schema object69* @param {string} key optional schema key70* @return {Ajv} this for method chaining71*/72addMetaSchema(schema: object, key?: string): Ajv;73/**74* Validate schema75* @param {object|Boolean} schema schema to validate76* @return {Boolean} true if schema is valid77*/78validateSchema(schema: object | boolean): boolean;79/**80* Get compiled schema from the instance by `key` or `ref`.81* @param {string} keyRef `key` that was passed to `addSchema` or full schema reference (`schema.id` or resolved id).82* @return {Function} schema validating function (with property `schema`). Returns undefined if keyRef can't be resolved to an existing schema.83*/84getSchema(keyRef: string): ValidateFunction | undefined;85/**86* Remove cached schema(s).87* If no parameter is passed all schemas but meta-schemas are removed.88* If RegExp is passed all schemas with key/id matching pattern but meta-schemas are removed.89* Even if schema is referenced by other schemas it still can be removed as other schemas have local references.90* @param {string|object|RegExp|Boolean} schemaKeyRef key, ref, pattern to match key/ref or schema object91* @return {Ajv} this for method chaining92*/93removeSchema(schemaKeyRef?: object | string | RegExp | boolean): Ajv;94/**95* Add custom format96* @param {string} name format name97* @param {string|RegExp|Function} format string is converted to RegExp; function should return boolean (true when valid)98* @return {Ajv} this for method chaining99*/100addFormat(name: string, format: FormatValidator | FormatDefinition): Ajv;101/**102* Define custom keyword103* @this Ajv104* @param {string} keyword custom keyword, should be a valid identifier, should be different from all standard, custom and macro keywords.105* @param {object} definition keyword definition object with properties `type` (type(s) which the keyword applies to), `validate` or `compile`.106* @return {Ajv} this for method chaining107*/108addKeyword(keyword: string, definition: KeywordDefinition): Ajv;109/**110* Get keyword definition111* @this Ajv112* @param {string} keyword pre-defined or custom keyword.113* @return {object|Boolean} custom keyword definition, `true` if it is a predefined keyword, `false` otherwise.114*/115getKeyword(keyword: string): object | boolean;116/**117* Remove keyword118* @this Ajv119* @param {string} keyword pre-defined or custom keyword.120* @return {Ajv} this for method chaining121*/122removeKeyword(keyword: string): Ajv;123/**124* Validate keyword125* @this Ajv126* @param {object} definition keyword definition object127* @param {boolean} throwError true to throw exception if definition is invalid128* @return {boolean} validation result129*/130validateKeyword(definition: KeywordDefinition, throwError: boolean): boolean;131/**132* Convert array of error message objects to string133* @param {Array<object>} errors optional array of validation errors, if not passed errors from the instance are used.134* @param {object} options optional options with properties `separator` and `dataVar`.135* @return {string} human readable string with all errors descriptions136*/137errorsText(errors?: Array<ErrorObject> | null, options?: ErrorsTextOptions): string;138errors?: Array<ErrorObject> | null;139_opts: Options;140}141142interface CustomLogger {143log(...args: any[]): any;144warn(...args: any[]): any;145error(...args: any[]): any;146}147148interface ValidateFunction {149(150data: any,151dataPath?: string,152parentData?: object | Array<any>,153parentDataProperty?: string | number,154rootData?: object | Array<any>155): boolean | PromiseLike<any>;156schema?: object | boolean;157errors?: null | Array<ErrorObject>;158refs?: object;159refVal?: Array<any>;160root?: ValidateFunction | object;161$async?: true;162source?: object;163}164165interface Options {166$data?: boolean;167allErrors?: boolean;168verbose?: boolean;169jsonPointers?: boolean;170uniqueItems?: boolean;171unicode?: boolean;172format?: false | string;173formats?: object;174keywords?: object;175unknownFormats?: true | string[] | 'ignore';176schemas?: Array<object> | object;177schemaId?: '$id' | 'id' | 'auto';178missingRefs?: true | 'ignore' | 'fail';179extendRefs?: true | 'ignore' | 'fail';180loadSchema?: (uri: string, cb?: (err: Error, schema: object) => void) => PromiseLike<object | boolean>;181removeAdditional?: boolean | 'all' | 'failing';182useDefaults?: boolean | 'empty' | 'shared';183coerceTypes?: boolean | 'array';184strictDefaults?: boolean | 'log';185strictKeywords?: boolean | 'log';186strictNumbers?: boolean;187async?: boolean | string;188transpile?: string | ((code: string) => string);189meta?: boolean | object;190validateSchema?: boolean | 'log';191addUsedSchema?: boolean;192inlineRefs?: boolean | number;193passContext?: boolean;194loopRequired?: number;195ownProperties?: boolean;196multipleOfPrecision?: boolean | number;197errorDataPath?: string,198messages?: boolean;199sourceCode?: boolean;200processCode?: (code: string, schema: object) => string;201cache?: object;202logger?: CustomLogger | false;203nullable?: boolean;204serialize?: ((schema: object | boolean) => any) | false;205}206207type FormatValidator = string | RegExp | ((data: string) => boolean | PromiseLike<any>);208type NumberFormatValidator = ((data: number) => boolean | PromiseLike<any>);209210interface NumberFormatDefinition {211type: "number",212validate: NumberFormatValidator;213compare?: (data1: number, data2: number) => number;214async?: boolean;215}216217interface StringFormatDefinition {218type?: "string",219validate: FormatValidator;220compare?: (data1: string, data2: string) => number;221async?: boolean;222}223224type FormatDefinition = NumberFormatDefinition | StringFormatDefinition;225226interface KeywordDefinition {227type?: string | Array<string>;228async?: boolean;229$data?: boolean;230errors?: boolean | string;231metaSchema?: object;232// schema: false makes validate not to expect schema (ValidateFunction)233schema?: boolean;234statements?: boolean;235dependencies?: Array<string>;236modifying?: boolean;237valid?: boolean;238// one and only one of the following properties should be present239validate?: SchemaValidateFunction | ValidateFunction;240compile?: (schema: any, parentSchema: object, it: CompilationContext) => ValidateFunction;241macro?: (schema: any, parentSchema: object, it: CompilationContext) => object | boolean;242inline?: (it: CompilationContext, keyword: string, schema: any, parentSchema: object) => string;243}244245interface CompilationContext {246level: number;247dataLevel: number;248dataPathArr: string[];249schema: any;250schemaPath: string;251baseId: string;252async: boolean;253opts: Options;254formats: {255[index: string]: FormatDefinition | undefined;256};257keywords: {258[index: string]: KeywordDefinition | undefined;259};260compositeRule: boolean;261validate: (schema: object) => boolean;262util: {263copy(obj: any, target?: any): any;264toHash(source: string[]): { [index: string]: true | undefined };265equal(obj: any, target: any): boolean;266getProperty(str: string): string;267schemaHasRules(schema: object, rules: any): string;268escapeQuotes(str: string): string;269toQuotedString(str: string): string;270getData(jsonPointer: string, dataLevel: number, paths: string[]): string;271escapeJsonPointer(str: string): string;272unescapeJsonPointer(str: string): string;273escapeFragment(str: string): string;274unescapeFragment(str: string): string;275};276self: Ajv;277}278279interface SchemaValidateFunction {280(281schema: any,282data: any,283parentSchema?: object,284dataPath?: string,285parentData?: object | Array<any>,286parentDataProperty?: string | number,287rootData?: object | Array<any>288): boolean | PromiseLike<any>;289errors?: Array<ErrorObject>;290}291292interface ErrorsTextOptions {293separator?: string;294dataVar?: string;295}296297interface ErrorObject {298keyword: string;299dataPath: string;300schemaPath: string;301params: ErrorParameters;302// Added to validation errors of propertyNames keyword schema303propertyName?: string;304// Excluded if messages set to false.305message?: string;306// These are added with the `verbose` option.307schema?: any;308parentSchema?: object;309data?: any;310}311312type ErrorParameters = RefParams | LimitParams | AdditionalPropertiesParams |313DependenciesParams | FormatParams | ComparisonParams |314MultipleOfParams | PatternParams | RequiredParams |315TypeParams | UniqueItemsParams | CustomParams |316PatternRequiredParams | PropertyNamesParams |317IfParams | SwitchParams | NoParams | EnumParams;318319interface RefParams {320ref: string;321}322323interface LimitParams {324limit: number;325}326327interface AdditionalPropertiesParams {328additionalProperty: string;329}330331interface DependenciesParams {332property: string;333missingProperty: string;334depsCount: number;335deps: string;336}337338interface FormatParams {339format: string340}341342interface ComparisonParams {343comparison: string;344limit: number | string;345exclusive: boolean;346}347348interface MultipleOfParams {349multipleOf: number;350}351352interface PatternParams {353pattern: string;354}355356interface RequiredParams {357missingProperty: string;358}359360interface TypeParams {361type: string;362}363364interface UniqueItemsParams {365i: number;366j: number;367}368369interface CustomParams {370keyword: string;371}372373interface PatternRequiredParams {374missingPattern: string;375}376377interface PropertyNamesParams {378propertyName: string;379}380381interface IfParams {382failingKeyword: string;383}384385interface SwitchParams {386caseIndex: number;387}388389interface NoParams { }390391interface EnumParams {392allowedValues: Array<any>;393}394}395396export = ajv;397398399