2016-08-05 05:41:17 +03:00
declare var ajv : {
( options? : ajv.Options ) : ajv . Ajv ;
new ( options? : ajv.Options ) : ajv . Ajv ;
}
2016-04-15 22:20:35 +03:00
declare namespace ajv {
interface Ajv {
2016-05-10 12:25:18 +03:00
/ * *
* Validate data using schema
* 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.
* @param { String | Object } schemaKeyRef key , ref or schema object
* @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 ` ) .
* /
2016-04-19 00:11:26 +03:00
validate ( schemaKeyRef : Object | string , data : any ) : boolean ;
2016-05-10 12:25:18 +03:00
/ * *
* Create validating function for passed schema .
* @param { Object } schema schema object
* @return { Function } validating function
* /
2016-04-15 22:20:35 +03:00
compile ( schema : Object ) : 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
* @param { Object } schema schema object
* @param { Function } callback node - style callback , it is always called with 2 parameters : error ( or null ) and validating function .
* /
2016-04-19 00:11:26 +03:00
compileAsync ( schema : Object , callback : ( err : Error , validate : ValidateFunction ) = > any ) : void ;
2016-05-10 12:25:18 +03:00
/ * *
* Adds schema to the instance .
* @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 ` .
* /
2016-04-15 22:20:35 +03:00
addSchema ( schema : Array < Object > | Object , key? : string ) : void ;
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
* @param { Object } schema schema object
* @param { String } key optional schema key
* /
2016-04-15 22:20:35 +03:00
addMetaSchema ( schema : Object , key? : string ) : void ;
2016-05-10 12:25:18 +03:00
/ * *
* Validate schema
* @param { Object } schema schema to validate
* @return { Boolean } true if schema is valid
* /
2016-04-15 22:20:35 +03:00
validateSchema ( schema : Object ) : boolean ;
2016-05-10 12:25:18 +03:00
/ * *
* Get compiled schema from the instance by ` key ` or ` ref ` .
* @param { String } keyRef ` key ` that was passed to ` addSchema ` or full schema reference ( ` schema.id ` or resolved id ) .
* @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 .
* @param { String | Object | RegExp } schemaKeyRef key , ref , pattern to match key / ref or schema object
* /
2016-04-22 03:29:55 +03:00
removeSchema ( schemaKeyRef? : Object | string | RegExp ) : void ;
2016-05-10 12:25:18 +03:00
/ * *
* Add custom format
* @param { String } name format name
* @param { String | RegExp | Function } format string is converted to RegExp ; function should return boolean ( true when valid )
* /
2016-04-19 00:11:26 +03:00
addFormat ( name : string , format : FormatValidator | FormatDefinition ) : void ;
2016-05-10 12:25:18 +03:00
/ * *
* Define custom keyword
* @this Ajv
* @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 ` .
* /
2016-04-17 22:07:00 +03:00
addKeyword ( keyword : string , definition : KeywordDefinition ) : void ;
2016-05-10 12:25:18 +03:00
/ * *
2016-12-11 15:37:43 +03:00
* Get keyword definition
* @this Ajv
* @param { String } keyword pre - defined or custom keyword .
* @return { Object | Boolean } custom keyword definition , ` true ` if it is a predefined keyword , ` false ` otherwise .
* /
getKeyword ( keyword : string ) : Object | boolean ;
/ * *
* Remove keyword
* @this Ajv
* @param { String } keyword pre - defined or custom keyword .
* /
removeKeyword ( keyword : string ) : void ;
/ * *
2016-05-10 12:25:18 +03:00
* Convert array of error message objects to string
* @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-04-22 03:29:55 +03:00
errorsText ( errors? : Array < ErrorObject > , options? : ErrorsTextOptions ) : string ;
2016-05-13 01:54:18 +03:00
errors? : Array < ErrorObject > ;
2016-04-22 03:29:55 +03:00
}
interface Thenable < R > {
then < U > ( onFulfilled ? : ( value : R ) = > U | Thenable < U > , onRejected ? : ( error : any ) = > U | Thenable < U > ) : Thenable < U > ;
2016-04-15 22:20:35 +03:00
}
interface ValidateFunction {
2016-04-17 22:07:00 +03:00
(
data : any ,
dataPath? : string ,
2016-04-20 22:55:43 +03:00
parentData? : Object | Array < any > ,
2016-09-19 14:49:37 +03:00
parentDataProperty? : string | number ,
rootData? : Object | Array < any >
2016-04-22 03:29:55 +03:00
) : boolean | Thenable < boolean > ;
2016-04-15 22:20:35 +03:00
errors? : Array < ErrorObject > ;
2016-06-26 23:00:23 +03:00
schema? : Object ;
2016-04-15 22:20:35 +03:00
}
interface Options {
2016-04-17 21:37:40 +03:00
v5? : 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 ;
formats? : Object ;
2016-10-20 02:29:10 +03:00
unknownFormats? : boolean | string | Array < string > ;
2016-04-17 21:37:40 +03:00
schemas? : Array < Object > | Object ;
2016-05-26 05:23:06 +03:00
ownProperties? : boolean ;
2016-04-17 21:37:40 +03:00
missingRefs? : boolean | string ;
2016-04-22 03:29:55 +03:00
loadSchema ? : ( uri : string , cb : ( err : Error , schema : Object ) = > any ) = > any ;
2016-04-17 21:37:40 +03:00
removeAdditional? : boolean | string ;
useDefaults? : boolean | string ;
2016-07-23 03:07:10 +03:00
coerceTypes? : boolean | string ;
2016-04-17 21:37:40 +03:00
async ? : boolean | string ;
2016-04-20 22:55:43 +03:00
transpile? : string | ( ( code : string ) = > string ) ;
2016-04-17 21:37:40 +03:00
meta? : boolean | Object ;
validateSchema? : boolean | string ;
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-04-17 21:37:40 +03:00
multipleOfPrecision? : number ;
2016-04-15 22:20:35 +03:00
errorDataPath? : string ;
messages? : boolean ;
2016-04-17 21:37:40 +03:00
beautify? : boolean | Object ;
cache? : Object ;
2016-04-15 22:20:35 +03:00
}
2016-04-20 22:55:43 +03:00
type FormatValidator = string | RegExp | ( ( data : string ) = > boolean ) ;
2016-04-19 00:11:26 +03:00
2016-04-17 22:07:00 +03:00
interface FormatDefinition {
2016-04-19 00:11:26 +03:00
validate : FormatValidator ;
2016-04-17 22:07:00 +03:00
compare : ( data1 : string , data2 : string ) = > number ;
async ? : boolean ;
}
interface KeywordDefinition {
type ? : string | Array < string > ;
async ? : boolean ;
errors? : boolean | string ;
// schema: false makes validate not to expect schema (ValidateFunction)
schema? : boolean ;
// one and only one of the following properties should be present
validate? : ValidateFunction | SchemaValidateFunction ;
compile ? : ( schema : Object , parentSchema : Object ) = > ValidateFunction ;
macro ? : ( schema : Object , parentSchema : Object ) = > Object ;
inline ? : ( it : Object , keyword : string , schema : Object , parentSchema : Object ) = > string ;
}
interface SchemaValidateFunction {
(
schema : Object ,
data : any ,
parentSchema? : Object ,
dataPath? : string ,
2016-04-20 22:55:43 +03:00
parentData? : Object | Array < any > ,
2016-04-17 22:07:00 +03:00
parentDataProperty? : string | number
2016-04-22 03:29:55 +03:00
) : boolean | Thenable < boolean > ;
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 ;
// Excluded if messages set to false.
message? : string ;
// These are added with the `verbose` option.
schema? : Object ;
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 |
DependenciesParams | FormatParams | ComparisonParams |
MultipleOfParams | PatternParams | RequiredParams |
TypeParams | UniqueItemsParams | CustomParams |
PatternGroupsParams | PatternRequiredParams |
SwitchParams | NoParams ;
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 PatternGroupsParams {
reason : string ;
limit : number ;
pattern : string ;
}
interface PatternRequiredParams {
missingPattern : string ;
}
interface SwitchParams {
caseIndex : number ;
}
interface NoParams { }
2016-04-15 22:20:35 +03:00
}
export = ajv ;