1 export { Format, FormatDefinition, AsyncFormatDefinition, KeywordDefinition, KeywordErrorDefinition, CodeKeywordDefinition, MacroKeywordDefinition, FuncKeywordDefinition, Vocabulary, Schema, SchemaObject, AnySchemaObject, AsyncSchema, AnySchema, ValidateFunction, AsyncValidateFunction, AnyValidateFunction, ErrorObject, ErrorNoParams, } from "./types";
2 export { SchemaCxt, SchemaObjCxt } from "./compile";
3 export interface Plugin<Opts> {
4 (ajv: Ajv, options?: Opts): Ajv;
7 export { KeywordCxt } from "./compile/validate";
8 export { DefinedError } from "./vocabularies/errors";
9 export { JSONType } from "./compile/rules";
10 export { JSONSchemaType } from "./types/json-schema";
11 export { JTDSchemaType } from "./types/jtd-schema";
12 export { _, str, stringify, nil, Name, Code, CodeGen, CodeGenOptions } from "./compile/codegen";
13 import type { Schema, AnySchema, AnySchemaObject, SchemaObject, AsyncSchema, Vocabulary, KeywordDefinition, AddedKeywordDefinition, AnyValidateFunction, ValidateFunction, AsyncValidateFunction, ErrorObject, Format, AddedFormat } from "./types";
14 import type { JSONSchemaType } from "./types/json-schema";
15 import type { JTDSchemaType } from "./types/jtd-schema";
16 import ValidationError from "./runtime/validation_error";
17 import MissingRefError from "./compile/ref_error";
18 import { ValidationRules } from "./compile/rules";
19 import { SchemaEnv } from "./compile";
20 import { Code, ValueScope } from "./compile/codegen";
21 export declare type Options = CurrentOptions & DeprecatedOptions;
22 export interface CurrentOptions {
23 strict?: boolean | "log";
24 strictSchema?: boolean | "log";
25 strictNumbers?: boolean | "log";
26 strictTypes?: boolean | "log";
27 strictTuples?: boolean | "log";
28 strictRequired?: boolean | "log";
29 allowMatchingProperties?: boolean;
30 allowUnionTypes?: boolean;
31 validateFormats?: boolean;
35 discriminator?: boolean;
36 $comment?: true | ((comment: string, schemaPath?: string, rootSchema?: AnySchemaObject) => unknown);
38 [Name in string]?: Format;
40 keywords?: Vocabulary;
41 schemas?: AnySchema[] | {
42 [Key in string]?: AnySchema;
44 logger?: Logger | false;
45 loadSchema?: (uri: string) => Promise<AnySchemaObject>;
46 removeAdditional?: boolean | "all" | "failing";
47 useDefaults?: boolean | "empty";
48 coerceTypes?: boolean | "array";
50 unevaluated?: boolean;
53 meta?: SchemaObject | boolean;
54 defaultMeta?: string | AnySchemaObject;
55 validateSchema?: boolean | "log";
56 addUsedSchema?: boolean;
57 inlineRefs?: boolean | number;
58 passContext?: boolean;
59 loopRequired?: number;
61 ownProperties?: boolean;
62 multipleOfPrecision?: number;
66 export interface CodeOptions {
69 optimize?: boolean | number;
72 process?: (code: string, schema?: SchemaEnv) => string;
74 interface InstanceCodeOptions extends CodeOptions {
77 interface DeprecatedOptions {
79 ignoreKeywordsWithRef?: boolean;
81 jsPropertySyntax?: boolean;
85 declare type RequiredInstanceOptions = {
86 [K in "strictSchema" | "strictNumbers" | "strictTypes" | "strictTuples" | "strictRequired" | "inlineRefs" | "loopRequired" | "loopEnum" | "meta" | "messages" | "addUsedSchema" | "validateSchema" | "validateFormats"]: NonNullable<Options[K]>;
88 code: InstanceCodeOptions;
90 export declare type InstanceOptions = Options & RequiredInstanceOptions;
91 export interface Logger {
92 log(...args: unknown[]): unknown;
93 warn(...args: unknown[]): unknown;
94 error(...args: unknown[]): unknown;
96 export default class Ajv {
97 opts: InstanceOptions;
98 errors?: ErrorObject[] | null;
100 readonly scope: ValueScope;
102 [Key in string]?: SchemaEnv;
105 [Ref in string]?: SchemaEnv | string;
108 [Name in string]?: AddedFormat;
110 readonly RULES: ValidationRules;
111 readonly _compilations: Set<SchemaEnv>;
112 private readonly _loading;
113 private readonly _cache;
114 private readonly _metaOpts;
115 static ValidationError: typeof ValidationError;
116 static MissingRefError: typeof MissingRefError;
117 constructor(opts?: Options);
118 _addVocabularies(): void;
119 _addDefaultMetaSchema(): void;
120 defaultMeta(): string | AnySchemaObject | undefined;
121 validate(schema: Schema | string, data: unknown): boolean;
122 validate(schemaKeyRef: AnySchema | string, data: unknown): boolean | Promise<unknown>;
123 validate<T>(schema: Schema | JSONSchemaType<T> | string, data: unknown): data is T;
124 validate<T>(schema: JTDSchemaType<T>, data: unknown): data is T;
125 validate<T>(schema: AsyncSchema, data: unknown | T): Promise<T>;
126 validate<T>(schemaKeyRef: AnySchema | string, data: unknown): data is T | Promise<T>;
127 compile<T = unknown>(schema: Schema | JSONSchemaType<T>, _meta?: boolean): ValidateFunction<T>;
128 compile<T = unknown>(schema: JTDSchemaType<T>, _meta?: boolean): ValidateFunction<T>;
129 compile<T = unknown>(schema: AsyncSchema, _meta?: boolean): AsyncValidateFunction<T>;
130 compile<T = unknown>(schema: AnySchema, _meta?: boolean): AnyValidateFunction<T>;
131 compileAsync<T = unknown>(schema: SchemaObject | JSONSchemaType<T>, _meta?: boolean): Promise<ValidateFunction<T>>;
132 compileAsync<T = unknown>(schema: JTDSchemaType<T>, _meta?: boolean): Promise<ValidateFunction<T>>;
133 compileAsync<T = unknown>(schema: AsyncSchema, meta?: boolean): Promise<AsyncValidateFunction<T>>;
134 compileAsync<T = unknown>(schema: AnySchemaObject, meta?: boolean): Promise<AnyValidateFunction<T>>;
135 addSchema(schema: AnySchema | AnySchema[], // If array is passed, `key` will be ignored
136 key?: string, // 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`.
137 _meta?: boolean, // true if schema is a meta-schema. Used internally, addMetaSchema should be used instead.
138 _validateSchema?: boolean | "log"): Ajv;
139 addMetaSchema(schema: AnySchemaObject, key?: string, // schema key
140 _validateSchema?: boolean | "log"): Ajv;
141 validateSchema(schema: AnySchema, throwOrLogError?: boolean): boolean | Promise<unknown>;
142 getSchema<T = unknown>(keyRef: string): AnyValidateFunction<T> | undefined;
143 removeSchema(schemaKeyRef?: AnySchema | string | RegExp): Ajv;
144 addVocabulary(definitions: Vocabulary): Ajv;
145 addKeyword(kwdOrDef: string | KeywordDefinition, def?: KeywordDefinition): Ajv;
146 getKeyword(keyword: string): AddedKeywordDefinition | boolean;
147 removeKeyword(keyword: string): Ajv;
148 addFormat(name: string, format: Format): Ajv;
149 errorsText(errors?: ErrorObject[] | null | undefined, // optional array of validation errors
150 { separator, dataVar }?: ErrorsTextOptions): string;
151 $dataMetaSchema(metaSchema: AnySchemaObject, keywordsJsonPointers: string[]): AnySchemaObject;
152 private _removeAllSchemas;
153 _addSchema(schema: AnySchema, meta?: boolean, baseId?: string, validateSchema?: boolean | "log", addSchema?: boolean): SchemaEnv;
154 private _checkUnique;
155 private _compileSchemaEnv;
156 private _compileMetaSchema;
158 export interface ErrorsTextOptions {