[6a3a178] | 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 {
|
---|
| 7 | id?: string;
|
---|
| 8 | $id?: string;
|
---|
| 9 | $schema?: string;
|
---|
| 10 | [x: string]: any;
|
---|
| 11 | }
|
---|
| 12 | export interface SchemaObject extends _SchemaObject {
|
---|
| 13 | id?: string;
|
---|
| 14 | $id?: string;
|
---|
| 15 | $schema?: string;
|
---|
| 16 | $async?: false;
|
---|
| 17 | [x: string]: any;
|
---|
| 18 | }
|
---|
| 19 | export interface AsyncSchema extends _SchemaObject {
|
---|
| 20 | $async: true;
|
---|
| 21 | }
|
---|
| 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;
|
---|
| 27 | };
|
---|
| 28 | export interface SourceCode {
|
---|
| 29 | validateName: ValueScopeName;
|
---|
| 30 | validateCode: string;
|
---|
| 31 | scopeValues: ScopeValueSets;
|
---|
| 32 | evaluated?: Code;
|
---|
| 33 | }
|
---|
| 34 | export interface DataValidationCxt<T extends string | number = string | number> {
|
---|
| 35 | instancePath: string;
|
---|
| 36 | parentData: {
|
---|
| 37 | [K in T]: any;
|
---|
| 38 | };
|
---|
| 39 | parentDataProperty: T;
|
---|
| 40 | rootData: Record<string, any> | any[];
|
---|
| 41 | dynamicAnchors: {
|
---|
| 42 | [Ref in string]?: ValidateFunction;
|
---|
| 43 | };
|
---|
| 44 | }
|
---|
| 45 | export interface ValidateFunction<T = unknown> {
|
---|
| 46 | (this: Ajv | any, data: any, dataCxt?: DataValidationCxt): data is T;
|
---|
| 47 | errors?: null | ErrorObject[];
|
---|
| 48 | evaluated?: Evaluated;
|
---|
| 49 | schema: AnySchema;
|
---|
| 50 | schemaEnv: SchemaEnv;
|
---|
| 51 | source?: SourceCode;
|
---|
| 52 | }
|
---|
| 53 | export interface JTDParser<T = unknown> {
|
---|
| 54 | (json: string): T | undefined;
|
---|
| 55 | message?: string;
|
---|
| 56 | position?: number;
|
---|
| 57 | }
|
---|
| 58 | export declare type EvaluatedProperties = {
|
---|
| 59 | [K in string]?: true;
|
---|
| 60 | } | true;
|
---|
| 61 | export declare type EvaluatedItems = number | true;
|
---|
| 62 | export interface Evaluated {
|
---|
| 63 | props?: EvaluatedProperties;
|
---|
| 64 | items?: EvaluatedItems;
|
---|
| 65 | dynamicProps: boolean;
|
---|
| 66 | dynamicItems: boolean;
|
---|
| 67 | }
|
---|
| 68 | export interface AsyncValidateFunction<T = unknown> extends ValidateFunction<T> {
|
---|
| 69 | (...args: Parameters<ValidateFunction<T>>): Promise<T>;
|
---|
| 70 | $async: true;
|
---|
| 71 | }
|
---|
| 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> {
|
---|
| 74 | keyword: K;
|
---|
| 75 | instancePath: string;
|
---|
| 76 | schemaPath: string;
|
---|
| 77 | params: P;
|
---|
| 78 | propertyName?: string;
|
---|
| 79 | message?: string;
|
---|
| 80 | schema?: S;
|
---|
| 81 | parentSchema?: AnySchemaObject;
|
---|
| 82 | data?: unknown;
|
---|
| 83 | }
|
---|
| 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;
|
---|
| 90 | $data?: boolean;
|
---|
| 91 | implements?: string[];
|
---|
| 92 | before?: string;
|
---|
| 93 | post?: boolean;
|
---|
| 94 | metaSchema?: AnySchemaObject;
|
---|
| 95 | validateSchema?: AnyValidateFunction;
|
---|
| 96 | dependencies?: string[];
|
---|
| 97 | error?: KeywordErrorDefinition;
|
---|
| 98 | $dataError?: KeywordErrorDefinition;
|
---|
| 99 | }
|
---|
| 100 | export interface CodeKeywordDefinition extends _KeywordDef {
|
---|
| 101 | code: (cxt: KeywordCxt, ruleType?: string) => void;
|
---|
| 102 | trackErrors?: boolean;
|
---|
| 103 | }
|
---|
| 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>[];
|
---|
| 109 | }
|
---|
| 110 | export interface SchemaValidateFunction {
|
---|
| 111 | (schema: any, data: any, parentSchema?: AnySchemaObject, dataCxt?: DataValidationCxt): boolean | Promise<any>;
|
---|
| 112 | errors?: Partial<ErrorObject>[];
|
---|
| 113 | }
|
---|
| 114 | export interface FuncKeywordDefinition extends _KeywordDef {
|
---|
| 115 | validate?: SchemaValidateFunction | DataValidateFunction;
|
---|
| 116 | compile?: CompileKeywordFunc;
|
---|
| 117 | schema?: boolean;
|
---|
| 118 | modifying?: boolean;
|
---|
| 119 | async?: boolean;
|
---|
| 120 | valid?: boolean;
|
---|
| 121 | errors?: boolean | "full";
|
---|
| 122 | }
|
---|
| 123 | export interface MacroKeywordDefinition extends FuncKeywordDefinition {
|
---|
| 124 | macro: MacroKeywordFunc;
|
---|
| 125 | }
|
---|
| 126 | export declare type KeywordDefinition = CodeKeywordDefinition | FuncKeywordDefinition | MacroKeywordDefinition;
|
---|
| 127 | export declare type AddedKeywordDefinition = KeywordDefinition & {
|
---|
| 128 | type: JSONType[];
|
---|
| 129 | schemaType: JSONType[];
|
---|
| 130 | };
|
---|
| 131 | export interface KeywordErrorDefinition {
|
---|
| 132 | message: string | Code | ((cxt: KeywordErrorCxt) => string | Code);
|
---|
| 133 | params?: Code | ((cxt: KeywordErrorCxt) => Code);
|
---|
| 134 | }
|
---|
| 135 | export declare type Vocabulary = (KeywordDefinition | string)[];
|
---|
| 136 | export interface KeywordErrorCxt {
|
---|
| 137 | gen: CodeGen;
|
---|
| 138 | keyword: string;
|
---|
| 139 | data: Name;
|
---|
| 140 | $data?: string | false;
|
---|
| 141 | schema: any;
|
---|
| 142 | parentSchema?: AnySchemaObject;
|
---|
| 143 | schemaCode: Code | number | boolean;
|
---|
| 144 | schemaValue: Code | number | boolean;
|
---|
| 145 | schemaType?: JSONType[];
|
---|
| 146 | errsCount?: Name;
|
---|
| 147 | params: KeywordCxtParams;
|
---|
| 148 | it: SchemaCxt;
|
---|
| 149 | }
|
---|
| 150 | export declare type KeywordCxtParams = {
|
---|
| 151 | [P in string]?: Code | string | number;
|
---|
| 152 | };
|
---|
| 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>;
|
---|
| 161 | }
|
---|
| 162 | export interface AsyncFormatDefinition<T extends string | number> {
|
---|
| 163 | type?: T extends string ? "string" | undefined : "number";
|
---|
| 164 | validate: AsyncFormatValidator<T>;
|
---|
| 165 | async: true;
|
---|
| 166 | compare?: FormatCompare<T>;
|
---|
| 167 | }
|
---|
| 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 {};
|
---|