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 {
11 export interface SchemaObject extends _SchemaObject {
17 export interface AsyncSchema extends _SchemaObject {
20 export declare type AnySchemaObject = SchemaObject | AsyncSchema;
21 export declare type Schema = SchemaObject | boolean;
22 export declare type AnySchema = Schema | AsyncSchema;
23 export declare type SchemaMap = {
24 [Key in string]?: AnySchema;
26 export interface SourceCode {
27 validateName: ValueScopeName;
29 scopeValues: ScopeValueSets;
32 export interface DataValidationCxt<T extends string | number = string | number> {
37 parentDataProperty: T;
38 rootData: Record<string, any> | any[];
40 [Ref in string]?: ValidateFunction;
43 export interface ValidateFunction<T = unknown> {
44 (this: Ajv | any, data: any, dataCxt?: DataValidationCxt): data is T;
45 errors?: null | ErrorObject[];
46 evaluated?: Evaluated;
51 export interface JTDParser<T = unknown> {
52 (json: string): T | undefined;
56 export declare type EvaluatedProperties = {
59 export declare type EvaluatedItems = number | true;
60 export interface Evaluated {
61 props?: EvaluatedProperties;
62 items?: EvaluatedItems;
63 dynamicProps: boolean;
64 dynamicItems: boolean;
66 export interface AsyncValidateFunction<T = unknown> extends ValidateFunction<T> {
67 (...args: Parameters<ValidateFunction<T>>): Promise<T>;
70 export declare type AnyValidateFunction<T = any> = ValidateFunction<T> | AsyncValidateFunction<T>;
71 export interface ErrorObject<K extends string = string, P = Record<string, any>, S = unknown> {
76 propertyName?: string;
79 parentSchema?: AnySchemaObject;
82 export declare type ErrorNoParams<K extends string, S = unknown> = ErrorObject<K, Record<string, never>, S>;
83 interface _KeywordDef {
84 keyword: string | string[];
85 type?: JSONType | JSONType[];
86 schemaType?: JSONType | JSONType[];
87 allowUndefined?: boolean;
89 implements?: string[];
92 metaSchema?: AnySchemaObject;
93 validateSchema?: AnyValidateFunction;
94 dependencies?: string[];
95 error?: KeywordErrorDefinition;
96 $dataError?: KeywordErrorDefinition;
98 export interface CodeKeywordDefinition extends _KeywordDef {
99 code: (cxt: KeywordCxt, ruleType?: string) => void;
100 trackErrors?: boolean;
102 export declare type MacroKeywordFunc = (schema: any, parentSchema: AnySchemaObject, it: SchemaCxt) => AnySchema;
103 export declare type CompileKeywordFunc = (schema: any, parentSchema: AnySchemaObject, it: SchemaObjCxt) => DataValidateFunction;
104 export interface DataValidateFunction {
105 (...args: Parameters<ValidateFunction>): boolean | Promise<any>;
106 errors?: Partial<ErrorObject>[];
108 export interface SchemaValidateFunction {
109 (schema: any, data: any, parentSchema?: AnySchemaObject, dataCxt?: DataValidationCxt): boolean | Promise<any>;
110 errors?: Partial<ErrorObject>[];
112 export interface FuncKeywordDefinition extends _KeywordDef {
113 validate?: SchemaValidateFunction | DataValidateFunction;
114 compile?: CompileKeywordFunc;
119 errors?: boolean | "full";
121 export interface MacroKeywordDefinition extends FuncKeywordDefinition {
122 macro: MacroKeywordFunc;
124 export declare type KeywordDefinition = CodeKeywordDefinition | FuncKeywordDefinition | MacroKeywordDefinition;
125 export declare type AddedKeywordDefinition = KeywordDefinition & {
127 schemaType: JSONType[];
129 export interface KeywordErrorDefinition {
130 message: string | Code | ((cxt: KeywordErrorCxt) => string | Code);
131 params?: Code | ((cxt: KeywordErrorCxt) => Code);
133 export declare type Vocabulary = (KeywordDefinition | string)[];
134 export interface KeywordErrorCxt {
138 $data?: string | false;
140 parentSchema?: AnySchemaObject;
141 schemaCode: Code | number | boolean;
142 schemaValue: Code | number | boolean;
143 schemaType?: JSONType[];
145 params: KeywordCxtParams;
148 export declare type KeywordCxtParams = {
149 [P in string]?: Code | string | number;
151 export declare type FormatValidator<T extends string | number> = (data: T) => boolean;
152 export declare type FormatCompare<T extends string | number> = (data1: T, data2: T) => number | undefined;
153 export declare type AsyncFormatValidator<T extends string | number> = (data: T) => Promise<boolean>;
154 export interface FormatDefinition<T extends string | number> {
155 type?: T extends string ? "string" | undefined : "number";
156 validate: FormatValidator<T> | (T extends string ? string | RegExp : never);
157 async?: false | undefined;
158 compare?: FormatCompare<T>;
160 export interface AsyncFormatDefinition<T extends string | number> {
161 type?: T extends string ? "string" | undefined : "number";
162 validate: AsyncFormatValidator<T>;
164 compare?: FormatCompare<T>;
166 export declare type AddedFormat = true | RegExp | FormatValidator<string> | FormatDefinition<string> | FormatDefinition<number> | AsyncFormatDefinition<string> | AsyncFormatDefinition<number>;
167 export declare type Format = AddedFormat | string;