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;
|
5 | [prop: string]: any;
|
6 | }
|
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, SomeJTDSchemaType, JTDDataType } 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, RegExpEngine, UriResolver } from "./types";
|
14 | import type { JSONSchemaType } from "./types/json-schema";
|
15 | import type { JTDSchemaType, SomeJTDSchemaType, JTDDataType } 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 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;
|
32 | $data?: boolean;
|
33 | allErrors?: boolean;
|
34 | verbose?: boolean;
|
35 | discriminator?: boolean;
|
36 | unicodeRegExp?: boolean;
|
37 | timestamp?: "string" | "date";
|
38 | parseDate?: boolean;
|
39 | allowDate?: boolean;
|
40 | $comment?: true | ((comment: string, schemaPath?: string, rootSchema?: AnySchemaObject) => unknown);
|
41 | formats?: {
|
42 | [Name in string]?: Format;
|
43 | };
|
44 | keywords?: Vocabulary;
|
45 | schemas?: AnySchema[] | {
|
46 | [Key in string]?: AnySchema;
|
47 | };
|
48 | logger?: Logger | false;
|
49 | loadSchema?: (uri: string) => Promise<AnySchemaObject>;
|
50 | removeAdditional?: boolean | "all" | "failing";
|
51 | useDefaults?: boolean | "empty";
|
52 | coerceTypes?: boolean | "array";
|
53 | next?: boolean;
|
54 | unevaluated?: boolean;
|
55 | dynamicRef?: boolean;
|
56 | schemaId?: "id" | "$id";
|
57 | jtd?: boolean;
|
58 | meta?: SchemaObject | boolean;
|
59 | defaultMeta?: string | AnySchemaObject;
|
60 | validateSchema?: boolean | "log";
|
61 | addUsedSchema?: boolean;
|
62 | inlineRefs?: boolean | number;
|
63 | passContext?: boolean;
|
64 | loopRequired?: number;
|
65 | loopEnum?: number;
|
66 | ownProperties?: boolean;
|
67 | multipleOfPrecision?: number;
|
68 | int32range?: boolean;
|
69 | messages?: boolean;
|
70 | code?: CodeOptions;
|
71 | uriResolver?: UriResolver;
|
72 | }
|
73 | export interface CodeOptions {
|
74 | es5?: boolean;
|
75 | esm?: boolean;
|
76 | lines?: boolean;
|
77 | optimize?: boolean | number;
|
78 | formats?: Code;
|
79 | source?: boolean;
|
80 | process?: (code: string, schema?: SchemaEnv) => string;
|
81 | regExp?: RegExpEngine;
|
82 | }
|
83 | interface InstanceCodeOptions extends CodeOptions {
|
84 | regExp: RegExpEngine;
|
85 | optimize: number;
|
86 | }
|
87 | interface DeprecatedOptions {
|
88 |
|
89 | ignoreKeywordsWithRef?: boolean;
|
90 |
|
91 | jsPropertySyntax?: boolean;
|
92 |
|
93 | unicode?: boolean;
|
94 | }
|
95 | type RequiredInstanceOptions = {
|
96 | [K in "strictSchema" | "strictNumbers" | "strictTypes" | "strictTuples" | "strictRequired" | "inlineRefs" | "loopRequired" | "loopEnum" | "meta" | "messages" | "schemaId" | "addUsedSchema" | "validateSchema" | "validateFormats" | "int32range" | "unicodeRegExp" | "uriResolver"]: NonNullable<Options[K]>;
|
97 | } & {
|
98 | code: InstanceCodeOptions;
|
99 | };
|
100 | export type InstanceOptions = Options & RequiredInstanceOptions;
|
101 | export interface Logger {
|
102 | log(...args: unknown[]): unknown;
|
103 | warn(...args: unknown[]): unknown;
|
104 | error(...args: unknown[]): unknown;
|
105 | }
|
106 | export default class Ajv {
|
107 | opts: InstanceOptions;
|
108 | errors?: ErrorObject[] | null;
|
109 | logger: Logger;
|
110 | readonly scope: ValueScope;
|
111 | readonly schemas: {
|
112 | [Key in string]?: SchemaEnv;
|
113 | };
|
114 | readonly refs: {
|
115 | [Ref in string]?: SchemaEnv | string;
|
116 | };
|
117 | readonly formats: {
|
118 | [Name in string]?: AddedFormat;
|
119 | };
|
120 | readonly RULES: ValidationRules;
|
121 | readonly _compilations: Set<SchemaEnv>;
|
122 | private readonly _loading;
|
123 | private readonly _cache;
|
124 | private readonly _metaOpts;
|
125 | static ValidationError: typeof ValidationError;
|
126 | static MissingRefError: typeof MissingRefError;
|
127 | constructor(opts?: Options);
|
128 | _addVocabularies(): void;
|
129 | _addDefaultMetaSchema(): void;
|
130 | defaultMeta(): string | AnySchemaObject | undefined;
|
131 | validate(schema: Schema | string, data: unknown): boolean;
|
132 | validate(schemaKeyRef: AnySchema | string, data: unknown): boolean | Promise<unknown>;
|
133 | validate<T>(schema: Schema | JSONSchemaType<T> | string, data: unknown): data is T;
|
134 | validate<T>(schema: JTDSchemaType<T>, data: unknown): data is T;
|
135 | validate<N extends never, T extends SomeJTDSchemaType>(schema: T, data: unknown): data is JTDDataType<T>;
|
136 | validate<T>(schema: AsyncSchema, data: unknown | T): Promise<T>;
|
137 | validate<T>(schemaKeyRef: AnySchema | string, data: unknown): data is T | Promise<T>;
|
138 | compile<T = unknown>(schema: Schema | JSONSchemaType<T>, _meta?: boolean): ValidateFunction<T>;
|
139 | compile<T = unknown>(schema: JTDSchemaType<T>, _meta?: boolean): ValidateFunction<T>;
|
140 | compile<N extends never, T extends SomeJTDSchemaType>(schema: T, _meta?: boolean): ValidateFunction<JTDDataType<T>>;
|
141 | compile<T = unknown>(schema: AsyncSchema, _meta?: boolean): AsyncValidateFunction<T>;
|
142 | compile<T = unknown>(schema: AnySchema, _meta?: boolean): AnyValidateFunction<T>;
|
143 | compileAsync<T = unknown>(schema: SchemaObject | JSONSchemaType<T>, _meta?: boolean): Promise<ValidateFunction<T>>;
|
144 | compileAsync<T = unknown>(schema: JTDSchemaType<T>, _meta?: boolean): Promise<ValidateFunction<T>>;
|
145 | compileAsync<T = unknown>(schema: AsyncSchema, meta?: boolean): Promise<AsyncValidateFunction<T>>;
|
146 | compileAsync<T = unknown>(schema: AnySchemaObject, meta?: boolean): Promise<AnyValidateFunction<T>>;
|
147 | addSchema(schema: AnySchema | AnySchema[],
|
148 | key?: string,
|
149 | _meta?: boolean,
|
150 | _validateSchema?: boolean | "log"): Ajv;
|
151 | addMetaSchema(schema: AnySchemaObject, key?: string,
|
152 | _validateSchema?: boolean | "log"): Ajv;
|
153 | validateSchema(schema: AnySchema, throwOrLogError?: boolean): boolean | Promise<unknown>;
|
154 | getSchema<T = unknown>(keyRef: string): AnyValidateFunction<T> | undefined;
|
155 | removeSchema(schemaKeyRef?: AnySchema | string | RegExp): Ajv;
|
156 | addVocabulary(definitions: Vocabulary): Ajv;
|
157 | addKeyword(kwdOrDef: string | KeywordDefinition, def?: KeywordDefinition): Ajv;
|
158 | getKeyword(keyword: string): AddedKeywordDefinition | boolean;
|
159 | removeKeyword(keyword: string): Ajv;
|
160 | addFormat(name: string, format: Format): Ajv;
|
161 | errorsText(errors?: ErrorObject[] | null | undefined,
|
162 | { separator, dataVar }?: ErrorsTextOptions): string;
|
163 | $dataMetaSchema(metaSchema: AnySchemaObject, keywordsJsonPointers: string[]): AnySchemaObject;
|
164 | private _removeAllSchemas;
|
165 | _addSchema(schema: AnySchema, meta?: boolean, baseId?: string, validateSchema?: boolean | "log", addSchema?: boolean): SchemaEnv;
|
166 | private _checkUnique;
|
167 | private _compileSchemaEnv;
|
168 | private _compileMetaSchema;
|
169 | }
|
170 | export interface ErrorsTextOptions {
|
171 | separator?: string;
|
172 | dataVar?: string;
|
173 | }
|