ajv/lib/ajv.d.ts

192 lines
5.0 KiB
TypeScript
Raw Normal View History

2016-04-15 22:20:35 +03:00
declare function ajv (options?: ajv.Options): ajv.Ajv;
declare namespace ajv {
interface Ajv {
2016-04-19 00:11:26 +03:00
validate(schemaKeyRef: Object | string, data: any): boolean;
2016-04-15 22:20:35 +03:00
compile(schema: Object): ValidateFunction;
2016-04-19 00:11:26 +03:00
compileAsync(schema: Object, callback: (err: Error, validate: ValidateFunction) => any): void;
2016-04-15 22:20:35 +03:00
addSchema(schema: Array<Object> | Object, key?: string): void;
addMetaSchema(schema: Object, key?: string): void;
validateSchema(schema: Object): boolean;
2016-04-19 00:11:26 +03:00
getSchema(keyRef: string): ValidateFunction;
removeSchema(schemaKeyRef?: Object | string | RegExp): void;
2016-04-19 00:11:26 +03:00
addFormat(name: string, format: FormatValidator | FormatDefinition): void;
addKeyword(keyword: string, definition: KeywordDefinition): void;
errorsText(errors?: Array<ErrorObject>, options?: ErrorsTextOptions): string;
}
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 {
(
data: any,
dataPath?: string,
parentData?: Object | Array<any>,
parentDataProperty?: string | number
): boolean | Thenable<boolean>;
2016-04-15 22:20:35 +03:00
errors?: Array<ErrorObject>;
}
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-04-17 21:37:40 +03:00
schemas?: Array<Object> | Object;
missingRefs?: boolean | string;
loadSchema?: (uri: string, cb: (err: Error, schema: Object) => any) => any;
2016-04-17 21:37:40 +03:00
removeAdditional?: boolean | string;
useDefaults?: boolean | string;
coerceTypes?: boolean;
async?: boolean | string;
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
}
type FormatValidator = string | RegExp | ((data: string) => boolean);
2016-04-19 00:11:26 +03:00
interface FormatDefinition {
2016-04-19 00:11:26 +03:00
validate: FormatValidator;
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,
parentData?: Object | Array<any>,
parentDataProperty?: string | number
): boolean | Thenable<boolean>;
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;