1 import type { CodeGen, Code, Name, ScopeValueSets, ValueScopeName } from "../compile/codegen";
2 import type { SchemaEnv, SchemaCxt, SchemaObjCxt } from "../compile";
3 import type { JSONType } from "../compile/rules";
4 import type { KeywordCxt } from "../compile/validate";
5 import type Ajv from "../core";
6 interface _SchemaObject {
12 export interface SchemaObject extends _SchemaObject {
19 export interface AsyncSchema extends _SchemaObject {
22 export declare type AnySchemaObject = SchemaObject | AsyncSchema;
23 export declare type Schema = SchemaObject | boolean;
24 export declare type AnySchema = Schema | AsyncSchema;
25 export declare type SchemaMap = {
26 [Key in string]?: AnySchema;
28 export interface SourceCode {
29 validateName: ValueScopeName;
31 scopeValues: ScopeValueSets;
34 export interface DataValidationCxt<T extends string | number = string | number> {
39 parentDataProperty: T;
40 rootData: Record<string, any> | any[];
42 [Ref in string]?: ValidateFunction;
45 export interface ValidateFunction<T = unknown> {
46 (this: Ajv | any, data: any, dataCxt?: DataValidationCxt): data is T;
47 errors?: null | ErrorObject[];
48 evaluated?: Evaluated;
53 export interface JTDParser<T = unknown> {
54 (json: string): T | undefined;
58 export declare type EvaluatedProperties = {
61 export declare type EvaluatedItems = number | true;
62 export interface Evaluated {
63 props?: EvaluatedProperties;
64 items?: EvaluatedItems;
65 dynamicProps: boolean;
66 dynamicItems: boolean;
68 export interface AsyncValidateFunction<T = unknown> extends ValidateFunction<T> {
69 (...args: Parameters<ValidateFunction<T>>): Promise<T>;
72 export declare type AnyValidateFunction<T = any> = ValidateFunction<T> | AsyncValidateFunction<T>;
73 export interface ErrorObject<K extends string = string, P = Record<string, any>, S = unknown> {
78 propertyName?: string;
81 parentSchema?: AnySchemaObject;
84 export declare type ErrorNoParams<K extends string, S = unknown> = ErrorObject<K, Record<string, never>, S>;
85 interface _KeywordDef {
86 keyword: string | string[];
87 type?: JSONType | JSONType[];
88 schemaType?: JSONType | JSONType[];
89 allowUndefined?: boolean;
91 implements?: string[];
94 metaSchema?: AnySchemaObject;
95 validateSchema?: AnyValidateFunction;
96 dependencies?: string[];
97 error?: KeywordErrorDefinition;
98 $dataError?: KeywordErrorDefinition;
100 export interface CodeKeywordDefinition extends _KeywordDef {
101 code: (cxt: KeywordCxt, ruleType?: string) => void;
102 trackErrors?: boolean;
104 export declare type MacroKeywordFunc = (schema: any, parentSchema: AnySchemaObject, it: SchemaCxt) => AnySchema;
105 export declare type CompileKeywordFunc = (schema: any, parentSchema: AnySchemaObject, it: SchemaObjCxt) => DataValidateFunction;
106 export interface DataValidateFunction {
107 (...args: Parameters<ValidateFunction>): boolean | Promise<any>;
108 errors?: Partial<ErrorObject>[];
110 export interface SchemaValidateFunction {
111 (schema: any, data: any, parentSchema?: AnySchemaObject, dataCxt?: DataValidationCxt): boolean | Promise<any>;
112 errors?: Partial<ErrorObject>[];
114 export interface FuncKeywordDefinition extends _KeywordDef {
115 validate?: SchemaValidateFunction | DataValidateFunction;
116 compile?: CompileKeywordFunc;
121 errors?: boolean | "full";
123 export interface MacroKeywordDefinition extends FuncKeywordDefinition {
124 macro: MacroKeywordFunc;
126 export declare type KeywordDefinition = CodeKeywordDefinition | FuncKeywordDefinition | MacroKeywordDefinition;
127 export declare type AddedKeywordDefinition = KeywordDefinition & {
129 schemaType: JSONType[];
131 export interface KeywordErrorDefinition {
132 message: string | Code | ((cxt: KeywordErrorCxt) => string | Code);
133 params?: Code | ((cxt: KeywordErrorCxt) => Code);
135 export declare type Vocabulary = (KeywordDefinition | string)[];
136 export interface KeywordErrorCxt {
140 $data?: string | false;
142 parentSchema?: AnySchemaObject;
143 schemaCode: Code | number | boolean;
144 schemaValue: Code | number | boolean;
145 schemaType?: JSONType[];
147 params: KeywordCxtParams;
150 export declare type KeywordCxtParams = {
151 [P in string]?: Code | string | number;
153 export declare type FormatValidator<T extends string | number> = (data: T) => boolean;
154 export declare type FormatCompare<T extends string | number> = (data1: T, data2: T) => number | undefined;
155 export declare type AsyncFormatValidator<T extends string | number> = (data: T) => Promise<boolean>;
156 export interface FormatDefinition<T extends string | number> {
157 type?: T extends string ? "string" | undefined : "number";
158 validate: FormatValidator<T> | (T extends string ? string | RegExp : never);
159 async?: false | undefined;
160 compare?: FormatCompare<T>;
162 export interface AsyncFormatDefinition<T extends string | number> {
163 type?: T extends string ? "string" | undefined : "number";
164 validate: AsyncFormatValidator<T>;
166 compare?: FormatCompare<T>;
168 export declare type AddedFormat = true | RegExp | FormatValidator<string> | FormatDefinition<string> | FormatDefinition<number> | AsyncFormatDefinition<string> | AsyncFormatDefinition<number>;
169 export declare type Format = AddedFormat | string;
170 export interface RegExpEngine {
171 (pattern: string, u: string): RegExpLike;
174 export interface RegExpLike {
175 test: (s: string) => boolean;