2018-04-18 22:13:21 +03:00
declare var ajv : {
2016-08-05 05:41:17 +03:00
( options? : ajv.Options ) : ajv . Ajv ;
2018-12-13 12:57:52 +03:00
new ( options? : ajv.Options ) : ajv . Ajv ;
ValidationError : typeof AjvErrors . ValidationError ;
MissingRefError : typeof AjvErrors . MissingRefError ;
2017-12-08 21:22:45 +03:00
$dataMetaSchema : object ;
2016-08-05 05:41:17 +03:00
}
2016-04-15 22:20:35 +03:00
2018-12-13 12:57:52 +03:00
declare namespace AjvErrors {
class ValidationError extends Error {
constructor ( errors : Array < ajv.ErrorObject > ) ;
message : string ;
errors : Array < ajv.ErrorObject > ;
ajv : true ;
validation : true ;
}
class MissingRefError extends Error {
constructor ( baseId : string , ref : string , message? : string ) ;
static message : ( baseId : string , ref : string ) = > string ;
message : string ;
missingRef : string ;
missingSchema : string ;
}
}
2016-04-15 22:20:35 +03:00
declare namespace ajv {
2018-12-13 12:57:52 +03:00
type ValidationError = AjvErrors . ValidationError ;
type MissingRefError = AjvErrors . MissingRefError ;
2016-04-15 22:20:35 +03:00
interface Ajv {
2016-05-10 12:25:18 +03:00
/ * *
* Validate data using schema
2017-10-24 20:52:13 +03:00
* 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).
2017-12-08 21:22:45 +03:00
* @param { string | object | Boolean } schemaKeyRef key , ref or schema object
2016-05-10 12:25:18 +03:00
* @param { Any } data to be validated
* @return { Boolean } validation result . Errors from the last validation will be available in ` ajv.errors ` ( and also in compiled schema : ` schema.errors ` ) .
* /
2019-01-03 23:34:39 +03:00
validate ( schemaKeyRef : object | string | boolean , data : any ) : boolean | PromiseLike < any > ;
2016-05-10 12:25:18 +03:00
/ * *
* Create validating function for passed schema .
2017-12-08 21:22:45 +03:00
* @param { object | Boolean } schema schema object
2016-05-10 12:25:18 +03:00
* @return { Function } validating function
* /
2017-12-08 21:22:45 +03:00
compile ( schema : object | boolean ) : ValidateFunction ;
2016-05-10 12:25:18 +03:00
/ * *
* Creates validating function for passed schema with asynchronous loading of missing schemas .
* ` loadSchema ` option should be a function that accepts schema uri and node - style callback .
* @this Ajv
2017-12-08 21:22:45 +03:00
* @param { object | Boolean } schema schema object
2016-12-26 00:39:36 +03:00
* @param { Boolean } meta optional true to compile meta - schema ; this parameter can be skipped
2016-10-19 11:52:58 +03:00
* @param { Function } callback optional node - style callback , it is always called with 2 parameters : error ( or null ) and validating function .
2018-03-05 13:00:23 +03:00
* @return { PromiseLike < ValidateFunction > } validating function
2016-05-10 12:25:18 +03:00
* /
2018-03-05 13:00:23 +03:00
compileAsync ( schema : object | boolean , meta? : Boolean , callback ? : ( err : Error , validate : ValidateFunction ) = > any ) : PromiseLike < ValidateFunction > ;
2016-05-10 12:25:18 +03:00
/ * *
* Adds schema to the instance .
2017-12-08 21:22:45 +03:00
* @param { object | Array } schema schema or array of schemas . If array is passed , ` key ` and other parameters will be ignored .
* @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 ` .
2017-11-22 10:37:42 +03:00
* @return { Ajv } this for method chaining
2016-05-10 12:25:18 +03:00
* /
2017-12-08 21:22:45 +03:00
addSchema ( schema : Array < object > | object , key? : string ) : Ajv ;
2016-05-10 12:25:18 +03:00
/ * *
* Add schema that will be used to validate other schemas
* options in META_IGNORE_OPTIONS are alway set to false
2017-12-08 21:22:45 +03:00
* @param { object } schema schema object
* @param { string } key optional schema key
2017-11-22 10:37:42 +03:00
* @return { Ajv } this for method chaining
2016-05-10 12:25:18 +03:00
* /
2017-12-08 21:22:45 +03:00
addMetaSchema ( schema : object , key? : string ) : Ajv ;
2016-05-10 12:25:18 +03:00
/ * *
* Validate schema
2017-12-08 21:22:45 +03:00
* @param { object | Boolean } schema schema to validate
2016-05-10 12:25:18 +03:00
* @return { Boolean } true if schema is valid
* /
2017-12-08 21:22:45 +03:00
validateSchema ( schema : object | boolean ) : boolean ;
2016-05-10 12:25:18 +03:00
/ * *
* Get compiled schema from the instance by ` key ` or ` ref ` .
2017-12-08 21:22:45 +03:00
* @param { string } keyRef ` key ` that was passed to ` addSchema ` or full schema reference ( ` schema.id ` or resolved id ) .
2016-05-10 12:25:18 +03:00
* @return { Function } schema validating function ( with property ` schema ` ) .
* /
2016-04-19 00:11:26 +03:00
getSchema ( keyRef : string ) : ValidateFunction ;
2016-05-10 12:25:18 +03:00
/ * *
* Remove cached schema ( s ) .
* If no parameter is passed all schemas but meta - schemas are removed .
* If RegExp is passed all schemas with key / id matching pattern but meta - schemas are removed .
* Even if schema is referenced by other schemas it still can be removed as other schemas have local references .
2017-12-08 21:22:45 +03:00
* @param { string | object | RegExp | Boolean } schemaKeyRef key , ref , pattern to match key / ref or schema object
2017-11-22 10:37:42 +03:00
* @return { Ajv } this for method chaining
2016-05-10 12:25:18 +03:00
* /
2017-12-08 21:22:45 +03:00
removeSchema ( schemaKeyRef? : object | string | RegExp | boolean ) : Ajv ;
2016-05-10 12:25:18 +03:00
/ * *
* Add custom format
2017-12-08 21:22:45 +03:00
* @param { string } name format name
* @param { string | RegExp | Function } format string is converted to RegExp ; function should return boolean ( true when valid )
2017-11-22 10:37:42 +03:00
* @return { Ajv } this for method chaining
2016-05-10 12:25:18 +03:00
* /
2017-11-22 10:37:42 +03:00
addFormat ( name : string , format : FormatValidator | FormatDefinition ) : Ajv ;
2016-05-10 12:25:18 +03:00
/ * *
* Define custom keyword
* @this Ajv
2017-12-08 21:22:45 +03:00
* @param { string } keyword custom keyword , should be a valid identifier , should be different from all standard , custom and macro keywords .
* @param { object } definition keyword definition object with properties ` type ` ( type ( s ) which the keyword applies to ) , ` validate ` or ` compile ` .
2017-11-22 10:37:42 +03:00
* @return { Ajv } this for method chaining
2016-05-10 12:25:18 +03:00
* /
2017-11-22 10:37:42 +03:00
addKeyword ( keyword : string , definition : KeywordDefinition ) : Ajv ;
2016-05-10 12:25:18 +03:00
/ * *
2016-12-11 15:37:43 +03:00
* Get keyword definition
* @this Ajv
2017-12-08 21:22:45 +03:00
* @param { string } keyword pre - defined or custom keyword .
* @return { object | Boolean } custom keyword definition , ` true ` if it is a predefined keyword , ` false ` otherwise .
2016-12-11 15:37:43 +03:00
* /
2017-12-08 21:22:45 +03:00
getKeyword ( keyword : string ) : object | boolean ;
2016-12-11 15:37:43 +03:00
/ * *
* Remove keyword
* @this Ajv
2017-12-08 21:22:45 +03:00
* @param { string } keyword pre - defined or custom keyword .
2017-11-22 10:37:42 +03:00
* @return { Ajv } this for method chaining
2016-12-11 15:37:43 +03:00
* /
2017-11-22 10:37:42 +03:00
removeKeyword ( keyword : string ) : Ajv ;
2016-12-11 15:37:43 +03:00
/ * *
2019-02-22 14:16:30 +03:00
* Validate keyword
* @this Ajv
* @param { object } definition keyword definition object
* @param { boolean } throwError true to throw exception if definition is invalid
* @return { boolean } validation result
* /
validateKeyword ( definition : KeywordDefinition , throwError : boolean ) : boolean ;
/ * *
2016-05-10 12:25:18 +03:00
* Convert array of error message objects to string
2017-12-08 21:22:45 +03:00
* @param { Array < object > } errors optional array of validation errors , if not passed errors from the instance are used .
* @param { object } options optional options with properties ` separator ` and ` dataVar ` .
* @return { string } human readable string with all errors descriptions
2016-05-10 12:25:18 +03:00
* /
2018-08-17 12:50:08 +03:00
errorsText ( errors? : Array < ErrorObject > | null , options? : ErrorsTextOptions ) : string ;
2018-11-11 14:06:11 +03:00
errors? : Array < ErrorObject > | null ;
2016-04-22 03:29:55 +03:00
}
2018-10-03 07:43:53 +03:00
interface CustomLogger {
log ( . . . args : any [ ] ) : any ;
warn ( . . . args : any [ ] ) : any ;
error ( . . . args : any [ ] ) : any ;
}
2016-04-15 22:20:35 +03:00
interface ValidateFunction {
2019-01-03 23:34:39 +03:00
(
data : any ,
2016-04-17 22:07:00 +03:00
dataPath? : string ,
2017-12-08 21:22:45 +03:00
parentData? : object | Array < any > ,
2016-09-19 14:49:37 +03:00
parentDataProperty? : string | number ,
2017-12-08 21:22:45 +03:00
rootData? : object | Array < any >
2019-01-03 23:34:39 +03:00
) : boolean | PromiseLike < any > ;
2017-12-08 21:22:45 +03:00
schema? : object | boolean ;
2017-10-15 20:30:12 +03:00
errors? : null | Array < ErrorObject > ;
2017-12-08 21:22:45 +03:00
refs? : object ;
2017-10-24 12:47:13 +03:00
refVal? : Array < any > ;
2017-12-08 21:22:45 +03:00
root? : ValidateFunction | object ;
2017-10-15 20:30:12 +03:00
$async? : true ;
2017-12-08 21:22:45 +03:00
source? : object ;
2016-04-15 22:20:35 +03:00
}
interface Options {
2016-12-26 19:57:06 +03:00
$data? : boolean ;
2016-04-15 22:20:35 +03:00
allErrors? : boolean ;
verbose? : boolean ;
2016-04-17 21:37:40 +03:00
jsonPointers? : boolean ;
uniqueItems? : boolean ;
unicode? : boolean ;
2016-04-15 22:20:35 +03:00
format? : string ;
2017-12-08 21:22:45 +03:00
formats? : object ;
2016-11-30 23:25:39 +03:00
unknownFormats? : true | string [ ] | 'ignore' ;
2017-12-08 21:22:45 +03:00
schemas? : Array < object > | object ;
2018-01-29 15:22:57 +03:00
schemaId ? : '$id' | 'id' | 'auto' ;
2016-11-30 23:25:39 +03:00
missingRefs? : true | 'ignore' | 'fail' ;
extendRefs? : true | 'ignore' | 'fail' ;
2018-03-05 13:00:23 +03:00
loadSchema ? : ( uri : string , cb ? : ( err : Error , schema : object ) = > void ) = > PromiseLike < object | boolean > ;
2016-11-30 23:25:39 +03:00
removeAdditional? : boolean | 'all' | 'failing' ;
useDefaults? : boolean | 'shared' ;
coerceTypes? : boolean | 'array' ;
2019-03-01 10:19:12 +03:00
invalidDefaults? : boolean | 'log' ;
2016-04-17 21:37:40 +03:00
async ? : boolean | string ;
2016-04-20 22:55:43 +03:00
transpile? : string | ( ( code : string ) = > string ) ;
2017-12-08 21:22:45 +03:00
meta? : boolean | object ;
2016-11-30 23:25:39 +03:00
validateSchema? : boolean | 'log' ;
2016-04-15 22:20:35 +03:00
addUsedSchema? : boolean ;
2016-04-17 21:37:40 +03:00
inlineRefs? : boolean | number ;
passContext? : boolean ;
2016-04-15 22:20:35 +03:00
loopRequired? : number ;
2016-11-30 06:53:52 +03:00
ownProperties? : boolean ;
multipleOfPrecision? : boolean | number ;
errorDataPath? : string ,
2016-04-15 22:20:35 +03:00
messages? : boolean ;
2016-12-26 19:57:06 +03:00
sourceCode? : boolean ;
processCode ? : ( code : string ) = > string ;
2017-12-08 21:22:45 +03:00
cache? : object ;
2018-11-11 00:03:51 +03:00
logger? : CustomLogger | false ;
nullable? : boolean ;
2018-11-11 00:28:01 +03:00
serialize ? : ( ( schema : object | boolean ) = > any ) | false ;
2016-04-15 22:20:35 +03:00
}
2018-03-05 13:00:23 +03:00
type FormatValidator = string | RegExp | ( ( data : string ) = > boolean | PromiseLike < any > ) ;
2018-04-18 22:13:21 +03:00
type NumberFormatValidator = ( ( data : number ) = > boolean | PromiseLike < any > ) ;
2016-04-19 00:11:26 +03:00
2018-04-18 22:13:21 +03:00
interface NumberFormatDefinition {
type : "number" ,
validate : NumberFormatValidator ;
compare ? : ( data1 : number , data2 : number ) = > number ;
async ? : boolean ;
}
interface StringFormatDefinition {
type ? : "string" ,
2016-04-19 00:11:26 +03:00
validate : FormatValidator ;
2018-04-18 22:13:21 +03:00
compare ? : ( data1 : string , data2 : string ) = > number ;
2016-04-17 22:07:00 +03:00
async ? : boolean ;
}
2018-04-18 22:13:21 +03:00
type FormatDefinition = NumberFormatDefinition | StringFormatDefinition ;
2016-04-17 22:07:00 +03:00
interface KeywordDefinition {
type ? : string | Array < string > ;
async ? : boolean ;
2016-12-26 00:39:36 +03:00
$data? : boolean ;
2016-04-17 22:07:00 +03:00
errors? : boolean | string ;
2017-12-08 21:22:45 +03:00
metaSchema? : object ;
2016-04-17 22:07:00 +03:00
// schema: false makes validate not to expect schema (ValidateFunction)
schema? : boolean ;
2019-02-22 14:16:30 +03:00
statements? : boolean ;
dependencies? : Array < string > ;
2017-01-21 02:25:45 +03:00
modifying? : boolean ;
valid? : boolean ;
2016-04-17 22:07:00 +03:00
// one and only one of the following properties should be present
2017-01-21 02:39:27 +03:00
validate? : SchemaValidateFunction | ValidateFunction ;
2017-12-08 21:22:45 +03:00
compile ? : ( schema : any , parentSchema : object , it : CompilationContext ) = > ValidateFunction ;
macro ? : ( schema : any , parentSchema : object , it : CompilationContext ) = > object | boolean ;
inline ? : ( it : CompilationContext , keyword : string , schema : any , parentSchema : object ) = > string ;
}
interface CompilationContext {
level : number ;
dataLevel : number ;
schema : any ;
schemaPath : string ;
baseId : string ;
async : boolean ;
opts : Options ;
formats : {
[ index : string ] : FormatDefinition | undefined ;
} ;
compositeRule : boolean ;
validate : ( schema : object ) = > boolean ;
util : {
copy ( obj : any , target? : any ) : any ;
toHash ( source : string [ ] ) : { [ index : string ] : true | undefined } ;
equal ( obj : any , target : any ) : boolean ;
getProperty ( str : string ) : string ;
schemaHasRules ( schema : object , rules : any ) : string ;
escapeQuotes ( str : string ) : string ;
toQuotedString ( str : string ) : string ;
getData ( jsonPointer : string , dataLevel : number , paths : string [ ] ) : string ;
escapeJsonPointer ( str : string ) : string ;
unescapeJsonPointer ( str : string ) : string ;
escapeFragment ( str : string ) : string ;
unescapeFragment ( str : string ) : string ;
} ;
self : Ajv ;
2016-04-17 22:07:00 +03:00
}
interface SchemaValidateFunction {
(
2016-12-26 00:39:36 +03:00
schema : any ,
2016-04-17 22:07:00 +03:00
data : any ,
2017-12-08 21:22:45 +03:00
parentSchema? : object ,
2016-04-17 22:07:00 +03:00
dataPath? : string ,
2017-12-08 21:22:45 +03:00
parentData? : object | Array < any > ,
2016-12-26 00:39:36 +03:00
parentDataProperty? : string | number ,
2017-12-08 21:22:45 +03:00
rootData? : object | Array < any >
2018-03-05 13:00:23 +03:00
) : boolean | PromiseLike < any > ;
2016-04-17 22:07:00 +03:00
errors? : Array < ErrorObject > ;
}
2016-04-17 21:37:40 +03:00
interface ErrorsTextOptions {
2016-04-15 22:20:35 +03:00
separator? : string ;
dataVar? : string ;
}
interface ErrorObject {
keyword : string ;
dataPath : string ;
schemaPath : string ;
params : ErrorParameters ;
2016-12-26 00:39:36 +03:00
// Added to validation errors of propertyNames keyword schema
propertyName? : string ;
2016-04-15 22:20:35 +03:00
// Excluded if messages set to false.
message? : string ;
// These are added with the `verbose` option.
2016-12-26 00:39:36 +03:00
schema? : any ;
2017-12-08 21:22:45 +03:00
parentSchema? : object ;
2016-04-17 21:37:40 +03:00
data? : any ;
2016-04-15 22:20:35 +03:00
}
2016-04-19 00:11:26 +03:00
type ErrorParameters = RefParams | LimitParams | AdditionalPropertiesParams |
2018-12-13 12:57:52 +03:00
DependenciesParams | FormatParams | ComparisonParams |
MultipleOfParams | PatternParams | RequiredParams |
TypeParams | UniqueItemsParams | CustomParams |
PatternRequiredParams | PropertyNamesParams |
IfParams | SwitchParams | NoParams | EnumParams ;
2016-04-15 22:20:35 +03:00
2016-04-19 00:11:26 +03:00
interface RefParams {
ref : string ;
2016-04-15 22:20:35 +03:00
}
2016-04-19 00:11:26 +03:00
interface LimitParams {
2016-04-15 22:20:35 +03:00
limit : number ;
}
2016-04-19 00:11:26 +03:00
interface AdditionalPropertiesParams {
additionalProperty : string ;
}
interface DependenciesParams {
2016-04-15 22:20:35 +03:00
property : string ;
missingProperty : string ;
depsCount : number ;
2016-04-19 00:11:26 +03:00
deps : string ;
2016-04-15 22:20:35 +03:00
}
2016-04-19 00:11:26 +03:00
interface FormatParams {
format : string
}
interface ComparisonParams {
2016-04-15 22:20:35 +03:00
comparison : string ;
2016-04-19 00:11:26 +03:00
limit : number | string ;
exclusive : boolean ;
2016-04-15 22:20:35 +03:00
}
2016-04-19 00:11:26 +03:00
interface MultipleOfParams {
multipleOf : number ;
2016-04-15 22:20:35 +03:00
}
2016-04-19 00:11:26 +03:00
interface PatternParams {
pattern : string ;
2016-04-15 22:20:35 +03:00
}
2016-04-19 00:11:26 +03:00
interface RequiredParams {
2016-04-15 22:20:35 +03:00
missingProperty : string ;
}
2016-04-19 00:11:26 +03:00
interface TypeParams {
2016-04-15 22:20:35 +03:00
type : string ;
}
2016-04-19 00:11:26 +03:00
interface UniqueItemsParams {
2016-04-15 22:20:35 +03:00
i : number ;
j : number ;
}
2016-04-19 00:11:26 +03:00
interface CustomParams {
keyword : string ;
2016-04-15 22:20:35 +03:00
}
2016-04-19 00:11:26 +03:00
interface PatternRequiredParams {
missingPattern : string ;
}
2016-12-26 00:39:36 +03:00
interface PropertyNamesParams {
propertyName : string ;
}
2017-11-26 13:32:41 +03:00
interface IfParams {
failingKeyword : string ;
}
2016-04-19 00:11:26 +03:00
interface SwitchParams {
caseIndex : number ;
}
2018-12-13 12:57:52 +03:00
interface NoParams { }
2017-02-21 16:55:57 +03:00
interface EnumParams {
allowedValues : Array < any > ;
}
2016-04-15 22:20:35 +03:00
}
export = ajv ;