z-schema 12.0.4 → 12.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/z-schema +7 -2
- package/cjs/index.d.ts +541 -530
- package/cjs/index.js +3963 -7740
- package/dist/errors.d.mts +64 -0
- package/dist/errors.mjs +67 -0
- package/dist/format-validators.d.mts +14 -0
- package/dist/format-validators.mjs +261 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.mjs +7 -0
- package/dist/json-schema-versions.d.mts +137 -0
- package/dist/json-schema-versions.mjs +11 -0
- package/dist/json-schema.d.mts +61 -0
- package/dist/json-schema.mjs +53 -0
- package/dist/json-validation.mjs +441 -0
- package/dist/report.d.mts +97 -0
- package/dist/report.mjs +194 -0
- package/dist/schema-cache.d.mts +23 -0
- package/dist/schema-cache.mjs +144 -0
- package/dist/schema-compiler.d.mts +23 -0
- package/dist/schema-compiler.mjs +265 -0
- package/dist/schema-validator.d.mts +15 -0
- package/dist/schema-validator.mjs +446 -0
- package/dist/schemas/draft-04-schema.mjs +125 -0
- package/dist/schemas/draft-06-schema.mjs +126 -0
- package/dist/schemas/draft-07-schema.mjs +141 -0
- package/dist/schemas/draft-2019-09-meta-applicator.mjs +46 -0
- package/dist/schemas/draft-2019-09-meta-content.mjs +15 -0
- package/dist/schemas/draft-2019-09-meta-core.mjs +52 -0
- package/dist/schemas/draft-2019-09-meta-format.mjs +11 -0
- package/dist/schemas/draft-2019-09-meta-meta-data.mjs +31 -0
- package/dist/schemas/draft-2019-09-meta-validation.mjs +80 -0
- package/dist/schemas/draft-2019-09-schema.mjs +39 -0
- package/dist/schemas/draft-2020-12-meta-applicator.mjs +45 -0
- package/dist/schemas/draft-2020-12-meta-content.mjs +15 -0
- package/dist/schemas/draft-2020-12-meta-core.mjs +46 -0
- package/dist/schemas/draft-2020-12-meta-format-annotation.mjs +11 -0
- package/dist/schemas/draft-2020-12-meta-format-assertion.mjs +11 -0
- package/dist/schemas/draft-2020-12-meta-meta-data.mjs +31 -0
- package/dist/schemas/draft-2020-12-meta-unevaluated.mjs +14 -0
- package/dist/schemas/draft-2020-12-meta-validation.mjs +80 -0
- package/dist/schemas/draft-2020-12-schema.mjs +55 -0
- package/dist/utils/array.mjs +54 -0
- package/dist/utils/base64.mjs +21 -0
- package/dist/utils/clone.mjs +42 -0
- package/dist/utils/constants.mjs +16 -0
- package/dist/utils/date.mjs +19 -0
- package/dist/utils/hostname.mjs +73 -0
- package/dist/utils/json.mjs +34 -0
- package/dist/utils/properties.mjs +11 -0
- package/dist/utils/schema-regex.mjs +49 -0
- package/dist/utils/symbols.mjs +5 -0
- package/dist/utils/time.mjs +42 -0
- package/dist/utils/unicode.mjs +12 -0
- package/dist/utils/uri.mjs +12 -0
- package/dist/utils/what-is.mjs +23 -0
- package/dist/validation/array.mjs +57 -0
- package/dist/validation/combinators.mjs +62 -0
- package/dist/validation/numeric.mjs +38 -0
- package/dist/validation/object.mjs +109 -0
- package/dist/validation/ref.mjs +49 -0
- package/dist/validation/shared.mjs +97 -0
- package/dist/validation/string.mjs +88 -0
- package/dist/validation/type.mjs +32 -0
- package/dist/z-schema-base.d.mts +85 -0
- package/dist/z-schema-base.mjs +230 -0
- package/dist/z-schema-options.d.mts +35 -0
- package/dist/z-schema-options.mjs +55 -0
- package/dist/z-schema-reader.d.mts +6 -0
- package/dist/z-schema-reader.mjs +10 -0
- package/dist/z-schema-versions.mjs +67 -0
- package/dist/z-schema.d.mts +193 -0
- package/dist/z-schema.mjs +300 -0
- package/package.json +49 -64
- package/src/index.ts +3 -3
- package/src/schema-compiler.ts +30 -10
- package/src/schema-validator.ts +1 -1
- package/src/utils/schema-regex.ts +13 -2
- package/src/z-schema-base.ts +1 -1
- package/src/z-schema-versions.ts +1 -2
- package/src/z-schema.ts +0 -1
- package/umd/ZSchema.js +5934 -8110
- package/umd/ZSchema.min.js +2 -1
- package/dist/errors.js +0 -72
- package/dist/format-validators.js +0 -392
- package/dist/index.js +0 -5
- package/dist/json-schema-versions.js +0 -8
- package/dist/json-schema.js +0 -84
- package/dist/json-validation.js +0 -728
- package/dist/package.json +0 -3
- package/dist/report.js +0 -265
- package/dist/schema-cache.js +0 -211
- package/dist/schema-compiler.js +0 -415
- package/dist/schema-validator.js +0 -721
- package/dist/schemas/draft-04-schema.json +0 -149
- package/dist/schemas/draft-06-schema.json +0 -155
- package/dist/schemas/draft-07-schema.json +0 -172
- package/dist/schemas/draft-2019-09-meta-applicator.json +0 -52
- package/dist/schemas/draft-2019-09-meta-content.json +0 -12
- package/dist/schemas/draft-2019-09-meta-core.json +0 -53
- package/dist/schemas/draft-2019-09-meta-format.json +0 -10
- package/dist/schemas/draft-2019-09-meta-meta-data.json +0 -32
- package/dist/schemas/draft-2019-09-meta-validation.json +0 -94
- package/dist/schemas/draft-2019-09-schema.json +0 -41
- package/dist/schemas/draft-2020-12-meta-applicator.json +0 -44
- package/dist/schemas/draft-2020-12-meta-content.json +0 -12
- package/dist/schemas/draft-2020-12-meta-core.json +0 -47
- package/dist/schemas/draft-2020-12-meta-format-annotation.json +0 -10
- package/dist/schemas/draft-2020-12-meta-format-assertion.json +0 -10
- package/dist/schemas/draft-2020-12-meta-meta-data.json +0 -32
- package/dist/schemas/draft-2020-12-meta-unevaluated.json +0 -11
- package/dist/schemas/draft-2020-12-meta-validation.json +0 -94
- package/dist/schemas/draft-2020-12-schema.json +0 -57
- package/dist/types/errors.d.ts +0 -64
- package/dist/types/format-validators.d.ts +0 -11
- package/dist/types/index.d.ts +0 -14
- package/dist/types/json-schema-versions.d.ts +0 -142
- package/dist/types/json-schema.d.ts +0 -66
- package/dist/types/json-validation.d.ts +0 -6
- package/dist/types/report.d.ts +0 -94
- package/dist/types/schema-cache.d.ts +0 -27
- package/dist/types/schema-compiler.d.ts +0 -31
- package/dist/types/schema-validator.d.ts +0 -10
- package/dist/types/utils/array.d.ts +0 -9
- package/dist/types/utils/base64.d.ts +0 -2
- package/dist/types/utils/clone.d.ts +0 -2
- package/dist/types/utils/constants.d.ts +0 -19
- package/dist/types/utils/date.d.ts +0 -1
- package/dist/types/utils/hostname.d.ts +0 -2
- package/dist/types/utils/json.d.ts +0 -9
- package/dist/types/utils/properties.d.ts +0 -1
- package/dist/types/utils/schema-regex.d.ts +0 -10
- package/dist/types/utils/symbols.d.ts +0 -2
- package/dist/types/utils/time.d.ts +0 -12
- package/dist/types/utils/unicode.d.ts +0 -5
- package/dist/types/utils/uri.d.ts +0 -4
- package/dist/types/utils/what-is.d.ts +0 -4
- package/dist/types/validation/array.d.ts +0 -12
- package/dist/types/validation/combinators.d.ts +0 -10
- package/dist/types/validation/numeric.d.ts +0 -8
- package/dist/types/validation/object.d.ts +0 -13
- package/dist/types/validation/ref.d.ts +0 -11
- package/dist/types/validation/shared.d.ts +0 -26
- package/dist/types/validation/string.d.ts +0 -9
- package/dist/types/validation/type.d.ts +0 -6
- package/dist/types/z-schema-base.d.ts +0 -87
- package/dist/types/z-schema-options.d.ts +0 -35
- package/dist/types/z-schema-reader.d.ts +0 -4
- package/dist/types/z-schema-versions.d.ts +0 -1
- package/dist/types/z-schema.d.ts +0 -191
- package/dist/utils/array.js +0 -69
- package/dist/utils/base64.js +0 -29
- package/dist/utils/clone.js +0 -59
- package/dist/utils/constants.js +0 -19
- package/dist/utils/date.js +0 -21
- package/dist/utils/hostname.js +0 -146
- package/dist/utils/json.js +0 -70
- package/dist/utils/properties.js +0 -10
- package/dist/utils/schema-regex.js +0 -52
- package/dist/utils/symbols.js +0 -2
- package/dist/utils/time.js +0 -50
- package/dist/utils/unicode.js +0 -12
- package/dist/utils/uri.js +0 -15
- package/dist/utils/what-is.js +0 -32
- package/dist/validation/array.js +0 -127
- package/dist/validation/combinators.js +0 -106
- package/dist/validation/numeric.js +0 -97
- package/dist/validation/object.js +0 -237
- package/dist/validation/ref.js +0 -70
- package/dist/validation/shared.js +0 -136
- package/dist/validation/string.js +0 -170
- package/dist/validation/type.js +0 -55
- package/dist/z-schema-base.js +0 -286
- package/dist/z-schema-options.js +0 -99
- package/dist/z-schema-reader.js +0 -7
- package/dist/z-schema-versions.js +0 -110
- package/dist/z-schema.js +0 -287
package/cjs/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
//#region src/format-validators.d.ts
|
|
1
2
|
type FormatValidatorFn = (input: unknown) => boolean | Promise<boolean>;
|
|
2
3
|
interface FormatValidatorsOptions {
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
strictUris?: boolean;
|
|
5
|
+
customFormats?: Record<string, FormatValidatorFn | null>;
|
|
5
6
|
}
|
|
6
7
|
declare function getFormatValidators(options?: FormatValidatorsOptions): Record<string, FormatValidatorFn>;
|
|
7
8
|
declare function registerFormat(name: string, validatorFunction: FormatValidatorFn): void;
|
|
@@ -9,82 +10,84 @@ declare function unregisterFormat(name: string): void;
|
|
|
9
10
|
declare function getSupportedFormats(customFormats?: Record<string, FormatValidatorFn | null>): string[];
|
|
10
11
|
declare function isFormatSupported(name: string, customFormats?: Record<string, FormatValidatorFn | null>): boolean;
|
|
11
12
|
declare function getRegisteredFormats(): string[];
|
|
12
|
-
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/z-schema-options.d.ts
|
|
13
15
|
interface ZSchemaOptions {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
16
|
+
version?: JsonSchemaVersion | 'none';
|
|
17
|
+
asyncTimeout?: number;
|
|
18
|
+
forceAdditional?: boolean;
|
|
19
|
+
assumeAdditional?: boolean | string[];
|
|
20
|
+
enumCaseInsensitiveComparison?: boolean;
|
|
21
|
+
forceItems?: boolean;
|
|
22
|
+
forceMinItems?: boolean;
|
|
23
|
+
forceMaxItems?: boolean;
|
|
24
|
+
forceMinLength?: boolean;
|
|
25
|
+
forceMaxLength?: boolean;
|
|
26
|
+
forceProperties?: boolean;
|
|
27
|
+
ignoreUnresolvableReferences?: boolean;
|
|
28
|
+
noExtraKeywords?: boolean;
|
|
29
|
+
noTypeless?: boolean;
|
|
30
|
+
noEmptyStrings?: boolean;
|
|
31
|
+
noEmptyArrays?: boolean;
|
|
32
|
+
strictUris?: boolean;
|
|
33
|
+
strictMode?: boolean;
|
|
34
|
+
reportPathAsArray?: boolean;
|
|
35
|
+
breakOnFirstError?: boolean;
|
|
36
|
+
pedanticCheck?: boolean;
|
|
37
|
+
ignoreUnknownFormats?: boolean;
|
|
38
|
+
formatAssertions?: boolean | null;
|
|
39
|
+
customValidator?: (report: Report, schema: unknown, json: unknown) => void;
|
|
40
|
+
customFormats?: Record<string, FormatValidatorFn | null>;
|
|
41
|
+
maxRecursionDepth?: number;
|
|
40
42
|
}
|
|
41
|
-
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/report.d.ts
|
|
42
45
|
interface SchemaErrorDetail {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Example: "Expected type string but found type array"
|
|
48
|
+
*/
|
|
49
|
+
message: string;
|
|
50
|
+
/**
|
|
51
|
+
* An error identifier that can be used to format a custom error message.
|
|
52
|
+
* Example: "INVALID_TYPE"
|
|
53
|
+
*/
|
|
54
|
+
code: string;
|
|
55
|
+
/**
|
|
56
|
+
* Format parameters that can be used to format a custom error message.
|
|
57
|
+
* Example: ["string","array"]
|
|
58
|
+
*/
|
|
59
|
+
params: ErrorParam[];
|
|
60
|
+
/**
|
|
61
|
+
* A JSON path indicating the location of the error.
|
|
62
|
+
* Example: "#/projects/1"
|
|
63
|
+
*/
|
|
64
|
+
path: string | Array<string | number>;
|
|
65
|
+
/**
|
|
66
|
+
* A JSON path indicating the location in the schema where the constraint is defined.
|
|
67
|
+
* Example: ["properties", "name", "type"]
|
|
68
|
+
*/
|
|
69
|
+
schemaPath?: Array<string | number>;
|
|
70
|
+
/**
|
|
71
|
+
* The schema rule description, which is included for certain errors where
|
|
72
|
+
* this information is useful (e.g. to describe a constraint).
|
|
73
|
+
*/
|
|
74
|
+
title?: string;
|
|
75
|
+
description?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Returns details for sub-schemas that failed to match. For example, if the schema
|
|
78
|
+
* uses the "oneOf" constraint to accept several alternative possibilities, each
|
|
79
|
+
* alternative will have its own inner detail object explaining why it failed to match.
|
|
80
|
+
*/
|
|
81
|
+
inner?: SchemaErrorDetail[];
|
|
82
|
+
schemaId?: string;
|
|
83
|
+
/**
|
|
84
|
+
* The schema keyword that caused this validation error.
|
|
85
|
+
* Example: "required", "type", "minLength"
|
|
86
|
+
*/
|
|
87
|
+
keyword?: keyof JsonSchemaAll;
|
|
85
88
|
}
|
|
86
89
|
interface ReportOptions {
|
|
87
|
-
|
|
90
|
+
maxErrors?: number;
|
|
88
91
|
}
|
|
89
92
|
type TaskResult = unknown;
|
|
90
93
|
type TaskFn = (...args: unknown[]) => TaskResult;
|
|
@@ -92,274 +95,281 @@ type TaskFnArgs = Parameters<TaskFn>;
|
|
|
92
95
|
type TaskProcessFn = (result: ReturnType<TaskFn>) => void;
|
|
93
96
|
type AsyncTask = [TaskFn, TaskFnArgs, TaskProcessFn];
|
|
94
97
|
declare class Report {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
98
|
+
asyncTasks: AsyncTask[];
|
|
99
|
+
commonErrorMessage?: string;
|
|
100
|
+
__$recursiveAnchorStack: JsonSchemaInternal[];
|
|
101
|
+
__$dynamicScopeStack: JsonSchemaInternal[];
|
|
102
|
+
__validationResultCache: Map<unknown, Map<unknown, boolean>>;
|
|
103
|
+
errors: SchemaErrorDetail[];
|
|
104
|
+
json?: unknown;
|
|
105
|
+
path: Array<number | string>;
|
|
106
|
+
schemaPath: Array<number | string>;
|
|
107
|
+
rootSchema?: JsonSchemaInternal;
|
|
108
|
+
parentReport?: Report;
|
|
109
|
+
options: ZSchemaOptions;
|
|
110
|
+
reportOptions: ReportOptions;
|
|
111
|
+
validateOptions: ValidateOptions;
|
|
112
|
+
constructor(zschemaOptions: ZSchemaOptions, validateOptions?: ValidateOptions);
|
|
113
|
+
constructor(parentReport: Report, validateOptions?: ValidateOptions);
|
|
114
|
+
constructor(parentReport: Report, reportOptions: ReportOptions, validateOptions?: ValidateOptions);
|
|
115
|
+
isValid(): boolean;
|
|
116
|
+
addAsyncTask<FV, FN extends (...args: any[]) => FV>(fn: FN, args: Parameters<FN>, asyncTaskResultProcessFn: (result: ReturnType<FN>) => void): void;
|
|
117
|
+
/**
|
|
118
|
+
* Like {@link addAsyncTask}, but automatically saves the current `path` and
|
|
119
|
+
* restores it around `processFn`. This eliminates the manual
|
|
120
|
+
* path-save/restore boilerplate that every async-aware validator would
|
|
121
|
+
* otherwise need.
|
|
122
|
+
*/
|
|
123
|
+
addAsyncTaskWithPath(fn: (...args: any[]) => any, args: any[], processFn: (result: any) => void): void;
|
|
124
|
+
getAncestor(id: string): Report | undefined;
|
|
125
|
+
processAsyncTasks(timeout: number | undefined, callback: ValidateCallback): void;
|
|
126
|
+
getPath(returnPathAsString?: boolean): string | (string | number)[];
|
|
127
|
+
getSchemaPath(): Array<string | number>;
|
|
128
|
+
getSchemaId(): string | undefined;
|
|
129
|
+
hasError(errCode: string, errParams: Array<any>): boolean;
|
|
130
|
+
addError(errCode: ErrorCode, errParams?: ErrorParam[], subReports?: Report | Report[], schema?: JsonSchema | boolean, keyword?: keyof JsonSchemaAll): void;
|
|
131
|
+
getJson(): unknown;
|
|
132
|
+
addCustomError(errorCode: ErrorCode, errorMessage: string, params?: ErrorParam[], subReports?: Report | Report[], schema?: JsonSchema | boolean, keyword?: keyof JsonSchemaAll): void;
|
|
130
133
|
}
|
|
131
|
-
|
|
134
|
+
//#endregion
|
|
135
|
+
//#region src/errors.d.ts
|
|
132
136
|
type ErrorCode = keyof typeof Errors;
|
|
133
137
|
type ErrorParam = string | number | Array<string | number>;
|
|
134
138
|
declare const Errors: {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
139
|
+
INVALID_TYPE: string;
|
|
140
|
+
INVALID_FORMAT: string;
|
|
141
|
+
ENUM_MISMATCH: string;
|
|
142
|
+
ENUM_CASE_MISMATCH: string;
|
|
143
|
+
ANY_OF_MISSING: string;
|
|
144
|
+
ONE_OF_MISSING: string;
|
|
145
|
+
ONE_OF_MULTIPLE: string;
|
|
146
|
+
NOT_PASSED: string;
|
|
147
|
+
ARRAY_LENGTH_SHORT: string;
|
|
148
|
+
ARRAY_LENGTH_LONG: string;
|
|
149
|
+
ARRAY_UNIQUE: string;
|
|
150
|
+
ARRAY_ADDITIONAL_ITEMS: string;
|
|
151
|
+
ARRAY_UNEVALUATED_ITEMS: string;
|
|
152
|
+
MULTIPLE_OF: string;
|
|
153
|
+
MINIMUM: string;
|
|
154
|
+
MINIMUM_EXCLUSIVE: string;
|
|
155
|
+
MAXIMUM: string;
|
|
156
|
+
MAXIMUM_EXCLUSIVE: string;
|
|
157
|
+
OBJECT_PROPERTIES_MINIMUM: string;
|
|
158
|
+
OBJECT_PROPERTIES_MAXIMUM: string;
|
|
159
|
+
OBJECT_MISSING_REQUIRED_PROPERTY: string;
|
|
160
|
+
OBJECT_ADDITIONAL_PROPERTIES: string;
|
|
161
|
+
OBJECT_UNEVALUATED_PROPERTIES: string;
|
|
162
|
+
OBJECT_DEPENDENCY_KEY: string;
|
|
163
|
+
MIN_LENGTH: string;
|
|
164
|
+
MAX_LENGTH: string;
|
|
165
|
+
PATTERN: string;
|
|
166
|
+
KEYWORD_TYPE_EXPECTED: string;
|
|
167
|
+
KEYWORD_UNDEFINED_STRICT: string;
|
|
168
|
+
KEYWORD_UNEXPECTED: string;
|
|
169
|
+
KEYWORD_MUST_BE: string;
|
|
170
|
+
KEYWORD_DEPENDENCY: string;
|
|
171
|
+
KEYWORD_PATTERN: string;
|
|
172
|
+
KEYWORD_VALUE_TYPE: string;
|
|
173
|
+
UNKNOWN_FORMAT: string;
|
|
174
|
+
CUSTOM_MODE_FORCE_PROPERTIES: string;
|
|
175
|
+
REF_UNRESOLVED: string;
|
|
176
|
+
UNRESOLVABLE_REFERENCE: string;
|
|
177
|
+
SCHEMA_NOT_REACHABLE: string;
|
|
178
|
+
SCHEMA_TYPE_EXPECTED: string;
|
|
179
|
+
SCHEMA_NOT_AN_OBJECT: string;
|
|
180
|
+
ASYNC_TIMEOUT: string;
|
|
181
|
+
PARENT_SCHEMA_VALIDATION_FAILED: string;
|
|
182
|
+
REMOTE_NOT_VALID: string;
|
|
183
|
+
SCHEMA_IS_FALSE: string;
|
|
184
|
+
CONST: string;
|
|
185
|
+
CONTAINS: string;
|
|
186
|
+
PROPERTY_NAMES: string;
|
|
187
|
+
COLLECT_EVALUATED_DEPTH_EXCEEDED: string;
|
|
188
|
+
MAX_RECURSION_DEPTH_EXCEEDED: string;
|
|
185
189
|
};
|
|
186
190
|
declare class ValidateError extends Error {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
191
|
+
name: string;
|
|
192
|
+
details?: SchemaErrorDetail[];
|
|
193
|
+
constructor(message: string, details?: SchemaErrorDetail[]);
|
|
190
194
|
}
|
|
191
|
-
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/schema-cache.d.ts
|
|
192
197
|
type SchemaCacheStorage = Record<string, JsonSchemaInternal>;
|
|
193
198
|
declare class SchemaCache {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
199
|
+
private validator;
|
|
200
|
+
static global_cache: SchemaCacheStorage;
|
|
201
|
+
cache: SchemaCacheStorage;
|
|
202
|
+
constructor(validator: ZSchemaBase);
|
|
203
|
+
static cacheSchemaByUri(uri: string, schema: JsonSchemaInternal): void;
|
|
204
|
+
cacheSchemaByUri(uri: string, schema: JsonSchemaInternal): void;
|
|
205
|
+
removeFromCacheByUri(uri: string): void;
|
|
206
|
+
checkCacheForUri(uri: string): boolean;
|
|
207
|
+
getSchema(report: Report, refOrSchema: string): JsonSchemaInternal | undefined;
|
|
208
|
+
getSchema(report: Report, refOrSchema: JsonSchema): JsonSchemaInternal;
|
|
209
|
+
getSchema(report: Report, refOrSchema: JsonSchema[]): JsonSchemaInternal[];
|
|
210
|
+
fromCache(path: string): JsonSchemaInternal | undefined;
|
|
211
|
+
getSchemaByUri(report: Report, uri: string, root?: JsonSchemaInternal): JsonSchemaInternal | undefined;
|
|
207
212
|
}
|
|
208
|
-
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region src/schema-validator.d.ts
|
|
209
215
|
declare class SchemaValidator {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
216
|
+
private validator;
|
|
217
|
+
constructor(validator: ZSchemaBase);
|
|
218
|
+
get options(): ZSchemaOptions;
|
|
219
|
+
validateArrayOfSchemas(report: Report, arr: Array<JsonSchemaInternal | boolean>): boolean;
|
|
220
|
+
validateSchema(report: Report, schema: JsonSchemaInternal | boolean | Array<JsonSchemaInternal | boolean>): boolean;
|
|
215
221
|
}
|
|
216
|
-
|
|
222
|
+
//#endregion
|
|
223
|
+
//#region src/z-schema-base.d.ts
|
|
217
224
|
interface ValidateOptions {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
225
|
+
schemaPath?: string;
|
|
226
|
+
includeErrors?: Array<keyof typeof Errors>;
|
|
227
|
+
excludeErrors?: Array<keyof typeof Errors>;
|
|
221
228
|
}
|
|
222
229
|
type ValidateResponse = {
|
|
223
|
-
|
|
224
|
-
|
|
230
|
+
valid: boolean;
|
|
231
|
+
err?: ValidateError;
|
|
225
232
|
};
|
|
226
233
|
type ValidateCallback = (err: ValidateResponse['err'], valid: ValidateResponse['valid']) => void;
|
|
227
234
|
declare class ZSchemaBase {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
235
|
+
scache: SchemaCache;
|
|
236
|
+
sc: SchemaCompiler;
|
|
237
|
+
sv: SchemaValidator;
|
|
238
|
+
validateOptions: ValidateOptions;
|
|
239
|
+
options: ZSchemaOptions;
|
|
240
|
+
constructor(options: ZSchemaOptions | undefined, token: symbol);
|
|
241
|
+
/**
|
|
242
|
+
* Internal recursive JSON validation — delegates to the `validate` function
|
|
243
|
+
* in `json-validation.ts`. Exposed as a method so that per-keyword validator
|
|
244
|
+
* modules (array, combinators, object) can call back into the core validator
|
|
245
|
+
* via `this` without importing `json-validation.ts` directly (which would
|
|
246
|
+
* create a circular dependency).
|
|
247
|
+
*/
|
|
248
|
+
_jsonValidate(report: Report, schema: boolean | JsonSchemaInternal, json: unknown): boolean;
|
|
249
|
+
getDefaultSchemaId(): string;
|
|
250
|
+
_validate(json: unknown, schema: JsonSchema | string, options: ValidateOptions, callback: ValidateCallback): void;
|
|
251
|
+
_validate(json: unknown, schema: JsonSchema | string, callback: ValidateCallback): void;
|
|
252
|
+
_validate(json: unknown, schema: JsonSchema | string, options: ValidateOptions): true;
|
|
253
|
+
_validate(json: unknown, schema: JsonSchema | string): true;
|
|
254
|
+
_validateSchema(schemaOrArr: JsonSchema | JsonSchema[]): true;
|
|
255
|
+
/**
|
|
256
|
+
* Register a format validator on this instance only (does not affect other instances or the global registry).
|
|
257
|
+
* @param name - The format name.
|
|
258
|
+
* @param validatorFunction - A sync or async function `(value: unknown) => boolean | Promise<boolean>`.
|
|
259
|
+
*/
|
|
260
|
+
registerFormat(name: string, validatorFunction: FormatValidatorFn): void;
|
|
261
|
+
/**
|
|
262
|
+
* Unregister an instance-scoped format validator.
|
|
263
|
+
* @param name - The format name to unregister.
|
|
264
|
+
*/
|
|
265
|
+
unregisterFormat(name: string): void;
|
|
266
|
+
/** Returns the names of format validators registered on this instance. */
|
|
267
|
+
getRegisteredFormats(): string[];
|
|
268
|
+
/** Returns all supported format names (global + instance-registered). */
|
|
269
|
+
getSupportedFormats(): string[];
|
|
270
|
+
/**
|
|
271
|
+
* Register a remote schema in this instance's cache so `$ref` can resolve to it.
|
|
272
|
+
* @param uri - The URI the schema will be known by.
|
|
273
|
+
* @param schema - The schema object or JSON string.
|
|
274
|
+
* @param validationOptions - Optional options used for schema preparation.
|
|
275
|
+
*/
|
|
276
|
+
setRemoteReference(uri: string, schema: string | JsonSchema, validationOptions?: ZSchemaOptions): void;
|
|
277
|
+
/**
|
|
278
|
+
* Extract unresolvable `$ref` URIs from a validation error.
|
|
279
|
+
* @param err - A `ValidateError` from a failed validation.
|
|
280
|
+
* @returns An array of unresolvable reference URIs.
|
|
281
|
+
*/
|
|
282
|
+
getMissingReferences(err: ValidateError): string[];
|
|
283
|
+
/**
|
|
284
|
+
* Extract unresolvable **remote** `$ref` URIs from a validation error (local fragment-only refs are excluded).
|
|
285
|
+
* @param err - A `ValidateError` from a failed validation.
|
|
286
|
+
* @returns An array of remote reference base URIs.
|
|
287
|
+
*/
|
|
288
|
+
getMissingRemoteReferences(err: ValidateError): string[];
|
|
289
|
+
/**
|
|
290
|
+
* Resolve a previously compiled schema by its `$id` / `id`, cleaning up internal bookkeeping properties
|
|
291
|
+
* and inlining resolved `$ref` targets.
|
|
292
|
+
* @param schemaId - The schema identifier to look up.
|
|
293
|
+
* @returns A clean, resolved copy of the schema, or `undefined` if not found.
|
|
294
|
+
*/
|
|
295
|
+
getResolvedSchema(schemaId: string): JsonSchema | undefined;
|
|
289
296
|
}
|
|
290
|
-
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region src/schema-compiler.d.ts
|
|
291
299
|
interface Reference {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
300
|
+
ref: string;
|
|
301
|
+
key: '$ref' | '$schema' | '$recursiveRef' | '$dynamicRef';
|
|
302
|
+
obj: JsonSchemaInternal;
|
|
303
|
+
path: Array<string | number>;
|
|
296
304
|
}
|
|
297
305
|
declare class SchemaCompiler {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
+
private validator;
|
|
307
|
+
constructor(validator: ZSchemaBase);
|
|
308
|
+
collectAndCacheIds(schema: JsonSchemaInternal): void;
|
|
309
|
+
compileSchema(report: Report, schema: JsonSchemaInternal | JsonSchemaInternal[], options?: {
|
|
310
|
+
noCache?: boolean;
|
|
311
|
+
}): boolean;
|
|
312
|
+
compileArrayOfSchemas(report: Report, arr: JsonSchemaInternal[]): boolean;
|
|
313
|
+
compileArrayOfSchemasLoop(mainReport: Report, arr: JsonSchemaInternal[]): number;
|
|
306
314
|
}
|
|
307
|
-
|
|
315
|
+
//#endregion
|
|
316
|
+
//#region src/json-schema.d.ts
|
|
308
317
|
/**
|
|
309
318
|
* Properties present in ALL JSON Schema drafts (04 through 2020-12) with
|
|
310
319
|
* identical types. Draft-specific additions live on the individual draft
|
|
311
320
|
* interfaces in `json-schema-versions.ts`.
|
|
312
321
|
*/
|
|
313
322
|
interface JsonSchemaCommon {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
323
|
+
$ref?: string;
|
|
324
|
+
$schema?: string;
|
|
325
|
+
title?: string;
|
|
326
|
+
description?: string;
|
|
327
|
+
default?: unknown;
|
|
328
|
+
type?: string | string[];
|
|
329
|
+
enum?: Array<unknown>;
|
|
330
|
+
format?: string;
|
|
331
|
+
multipleOf?: number;
|
|
332
|
+
minimum?: number;
|
|
333
|
+
maximum?: number;
|
|
334
|
+
/** Draft-04: `boolean` modifier on `minimum`/`maximum`. Draft-06+: standalone `number`. */
|
|
335
|
+
exclusiveMinimum?: boolean | number;
|
|
336
|
+
/** Draft-04: `boolean` modifier on `minimum`/`maximum`. Draft-06+: standalone `number`. */
|
|
337
|
+
exclusiveMaximum?: boolean | number;
|
|
338
|
+
minLength?: number;
|
|
339
|
+
maxLength?: number;
|
|
340
|
+
pattern?: string;
|
|
341
|
+
items?: JsonSchema | boolean | Array<JsonSchema | boolean>;
|
|
342
|
+
additionalItems?: boolean | JsonSchema;
|
|
343
|
+
minItems?: number;
|
|
344
|
+
maxItems?: number;
|
|
345
|
+
uniqueItems?: boolean;
|
|
346
|
+
properties?: Record<string, JsonSchema | boolean>;
|
|
347
|
+
patternProperties?: Record<string, JsonSchema>;
|
|
348
|
+
additionalProperties?: boolean | JsonSchema;
|
|
349
|
+
required?: string[];
|
|
350
|
+
minProperties?: number;
|
|
351
|
+
maxProperties?: number;
|
|
352
|
+
dependencies?: Record<string, string[] | JsonSchema>;
|
|
353
|
+
allOf?: JsonSchema[];
|
|
354
|
+
anyOf?: JsonSchema[];
|
|
355
|
+
oneOf?: JsonSchema[];
|
|
356
|
+
not?: JsonSchema;
|
|
357
|
+
definitions?: Record<string, JsonSchema>;
|
|
349
358
|
}
|
|
350
359
|
type JsonSchemaType = 'array' | 'boolean' | 'integer' | 'null' | 'number' | 'object' | 'string';
|
|
351
360
|
interface ZSchemaInternalProperties {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
+
__$compiled?: unknown;
|
|
362
|
+
__$missingReferences?: Reference[];
|
|
363
|
+
__$refResolved?: JsonSchema;
|
|
364
|
+
__$dynamicRefResolved?: JsonSchema;
|
|
365
|
+
__$recursiveRefResolved?: JsonSchema;
|
|
366
|
+
__$resourceRoot?: JsonSchemaInternal;
|
|
367
|
+
__$schemaResolved?: unknown;
|
|
368
|
+
__$validated?: boolean;
|
|
369
|
+
__$validationOptions?: ZSchemaOptions;
|
|
361
370
|
}
|
|
362
|
-
|
|
371
|
+
//#endregion
|
|
372
|
+
//#region src/json-schema-versions.d.ts
|
|
363
373
|
type JsonSchemaVersion = 'draft-04' | 'draft-06' | 'draft-07' | 'draft2019-09' | 'draft2020-12';
|
|
364
374
|
/** Union of all draft-specific schema interfaces — the public API type. */
|
|
365
375
|
type JsonSchema = JsonSchemaDraft4 | JsonSchemaDraft6 | JsonSchemaDraft7 | JsonSchemaDraft201909 | JsonSchemaDraft202012;
|
|
@@ -372,33 +382,33 @@ type JsonSchema = JsonSchemaDraft4 | JsonSchemaDraft6 | JsonSchemaDraft7 | JsonS
|
|
|
372
382
|
* Draft-06+, which would yield `never` in a plain intersection.
|
|
373
383
|
*/
|
|
374
384
|
interface JsonSchemaAll extends JsonSchemaCommon {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
385
|
+
/** Pre-`$id` identifier (draft-04 only). */
|
|
386
|
+
id?: string;
|
|
387
|
+
/** Schema identifier (replaces `id` from draft-06 onward). */
|
|
388
|
+
$id?: string;
|
|
389
|
+
const?: unknown;
|
|
390
|
+
contains?: JsonSchema;
|
|
391
|
+
propertyNames?: JsonSchema;
|
|
392
|
+
examples?: unknown[];
|
|
393
|
+
if?: JsonSchema | boolean;
|
|
394
|
+
then?: JsonSchema | boolean;
|
|
395
|
+
else?: JsonSchema | boolean;
|
|
396
|
+
contentEncoding?: string;
|
|
397
|
+
contentMediaType?: string;
|
|
398
|
+
$defs?: Record<string, JsonSchema>;
|
|
399
|
+
$anchor?: string;
|
|
400
|
+
$vocabulary?: Record<string, boolean>;
|
|
401
|
+
$recursiveAnchor?: boolean;
|
|
402
|
+
$recursiveRef?: string;
|
|
403
|
+
dependentSchemas?: Record<string, JsonSchema>;
|
|
404
|
+
dependentRequired?: Record<string, string[]>;
|
|
405
|
+
unevaluatedItems?: JsonSchema | boolean;
|
|
406
|
+
unevaluatedProperties?: JsonSchema | boolean;
|
|
407
|
+
maxContains?: number;
|
|
408
|
+
minContains?: number;
|
|
409
|
+
$dynamicAnchor?: string;
|
|
410
|
+
$dynamicRef?: string;
|
|
411
|
+
prefixItems?: Array<JsonSchema | boolean>;
|
|
402
412
|
}
|
|
403
413
|
/**
|
|
404
414
|
* Internal schema type used throughout the validator. Based on `JsonSchemaAll`
|
|
@@ -417,8 +427,8 @@ type JsonSchemaInternal = JsonSchemaAll & ZSchemaInternalProperties;
|
|
|
417
427
|
* @see https://json-schema.org/draft-04/draft-zyp-json-schema-04
|
|
418
428
|
*/
|
|
419
429
|
interface JsonSchemaDraft4 extends JsonSchemaCommon {
|
|
420
|
-
|
|
421
|
-
|
|
430
|
+
/** Schema identifier (draft-04). Replaced by `$id` in draft-06+. */
|
|
431
|
+
id?: string;
|
|
422
432
|
}
|
|
423
433
|
/**
|
|
424
434
|
* JSON Schema Draft-06.
|
|
@@ -431,11 +441,11 @@ interface JsonSchemaDraft4 extends JsonSchemaCommon {
|
|
|
431
441
|
* @see https://json-schema.org/draft-06/draft-wright-json-schema-validation-01
|
|
432
442
|
*/
|
|
433
443
|
interface JsonSchemaDraft6 extends JsonSchemaCommon {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
444
|
+
$id?: string;
|
|
445
|
+
const?: unknown;
|
|
446
|
+
contains?: JsonSchema;
|
|
447
|
+
propertyNames?: JsonSchema;
|
|
448
|
+
examples?: unknown[];
|
|
439
449
|
}
|
|
440
450
|
/**
|
|
441
451
|
* JSON Schema Draft-07.
|
|
@@ -447,11 +457,11 @@ interface JsonSchemaDraft6 extends JsonSchemaCommon {
|
|
|
447
457
|
* @see https://json-schema.org/draft-07/draft-handrews-json-schema-validation-01
|
|
448
458
|
*/
|
|
449
459
|
interface JsonSchemaDraft7 extends JsonSchemaDraft6 {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
460
|
+
if?: JsonSchema | boolean;
|
|
461
|
+
then?: JsonSchema | boolean;
|
|
462
|
+
else?: JsonSchema | boolean;
|
|
463
|
+
contentEncoding?: string;
|
|
464
|
+
contentMediaType?: string;
|
|
455
465
|
}
|
|
456
466
|
/**
|
|
457
467
|
* JSON Schema Draft 2019-09.
|
|
@@ -466,17 +476,17 @@ interface JsonSchemaDraft7 extends JsonSchemaDraft6 {
|
|
|
466
476
|
* @see https://json-schema.org/draft/2019-09/release-notes
|
|
467
477
|
*/
|
|
468
478
|
interface JsonSchemaDraft201909 extends JsonSchemaDraft7 {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
479
|
+
$defs?: Record<string, JsonSchema>;
|
|
480
|
+
$anchor?: string;
|
|
481
|
+
$vocabulary?: Record<string, boolean>;
|
|
482
|
+
$recursiveAnchor?: boolean;
|
|
483
|
+
$recursiveRef?: string;
|
|
484
|
+
dependentSchemas?: Record<string, JsonSchema>;
|
|
485
|
+
dependentRequired?: Record<string, string[]>;
|
|
486
|
+
unevaluatedItems?: JsonSchema | boolean;
|
|
487
|
+
unevaluatedProperties?: JsonSchema | boolean;
|
|
488
|
+
maxContains?: number;
|
|
489
|
+
minContains?: number;
|
|
480
490
|
}
|
|
481
491
|
/**
|
|
482
492
|
* JSON Schema Draft 2020-12.
|
|
@@ -488,197 +498,198 @@ interface JsonSchemaDraft201909 extends JsonSchemaDraft7 {
|
|
|
488
498
|
* @see https://json-schema.org/draft/2020-12/release-notes
|
|
489
499
|
*/
|
|
490
500
|
interface JsonSchemaDraft202012 extends JsonSchemaDraft201909 {
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
501
|
+
$dynamicAnchor?: string;
|
|
502
|
+
$dynamicRef?: string;
|
|
503
|
+
prefixItems?: Array<JsonSchema | boolean>;
|
|
494
504
|
}
|
|
495
|
-
|
|
505
|
+
//#endregion
|
|
506
|
+
//#region src/z-schema-reader.d.ts
|
|
496
507
|
type SchemaReader = (uri: string) => JsonSchema;
|
|
497
|
-
|
|
508
|
+
//#endregion
|
|
509
|
+
//#region src/z-schema.d.ts
|
|
498
510
|
declare class ZSchema extends ZSchemaBase {
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
511
|
+
/** @internal Use ZSchema.create() instead. */
|
|
512
|
+
constructor(options: ZSchemaOptions | undefined, token: symbol);
|
|
513
|
+
/**
|
|
514
|
+
* Register a global format validator available to all instances.
|
|
515
|
+
* @param name - The format name (e.g. `'email'`, `'date'`).
|
|
516
|
+
* @param validatorFunction - A sync or async function `(value: unknown) => boolean | Promise<boolean>`.
|
|
517
|
+
*/
|
|
518
|
+
static registerFormat(name: string, validatorFunction: FormatValidatorFn): void;
|
|
519
|
+
/**
|
|
520
|
+
* Remove a globally registered format validator.
|
|
521
|
+
* @param name - The format name to unregister.
|
|
522
|
+
*/
|
|
523
|
+
static unregisterFormat(name: string): void;
|
|
524
|
+
/** Returns the names of all globally registered format validators. */
|
|
525
|
+
static getRegisteredFormats(): string[];
|
|
526
|
+
/** Returns a deep clone of the default options. */
|
|
527
|
+
static getDefaultOptions(): ZSchemaOptions;
|
|
528
|
+
/**
|
|
529
|
+
* Register a remote schema in the global cache so any instance can resolve `$ref` to it.
|
|
530
|
+
* @param uri - The URI the schema will be known by.
|
|
531
|
+
* @param schema - The schema object or JSON string.
|
|
532
|
+
* @param validationOptions - Optional options used for schema preparation.
|
|
533
|
+
*/
|
|
534
|
+
static setRemoteReference(uri: string, schema: string | JsonSchema, validationOptions?: ZSchemaOptions): void;
|
|
535
|
+
/** Returns the current global schema reader, or `undefined` if none is set. */
|
|
536
|
+
static getSchemaReader(): SchemaReader | undefined;
|
|
537
|
+
/**
|
|
538
|
+
* Set a global schema reader function used to resolve remote `$ref` URIs.
|
|
539
|
+
* @param schemaReader - A function `(uri: string) => JsonSchema | undefined`, or `undefined` to clear.
|
|
540
|
+
*/
|
|
541
|
+
static setSchemaReader(schemaReader: SchemaReader | undefined): void;
|
|
542
|
+
static schemaSymbol: symbol;
|
|
543
|
+
static jsonSymbol: symbol;
|
|
544
|
+
/**
|
|
545
|
+
* Create a validator instance.
|
|
546
|
+
*
|
|
547
|
+
* The returned type depends on the `async` and `safe` options:
|
|
548
|
+
* - `{}` → `ZSchema` — `validate()` returns `true` or throws.
|
|
549
|
+
* - `{ safe: true }` → `ZSchemaSafe` — `validate()` returns `{ valid, err? }`.
|
|
550
|
+
* - `{ async: true }` → `ZSchemaAsync` — `validate()` returns `Promise<true>` or rejects.
|
|
551
|
+
* - `{ async: true, safe: true }` → `ZSchemaAsyncSafe` — `validate()` returns `Promise<{ valid, err? }>`.
|
|
552
|
+
*
|
|
553
|
+
* @param options - Validator configuration. See `ZSchemaOptions` for all available settings.
|
|
554
|
+
* @returns A validator instance of the appropriate variant.
|
|
555
|
+
*
|
|
556
|
+
* @example
|
|
557
|
+
* ```ts
|
|
558
|
+
* const validator = ZSchema.create();
|
|
559
|
+
* validator.validate(data, schema); // throws on error
|
|
560
|
+
*
|
|
561
|
+
* const safe = ZSchema.create({ safe: true });
|
|
562
|
+
* const result = safe.validate(data, schema); // { valid, err? }
|
|
563
|
+
* ```
|
|
564
|
+
*/
|
|
565
|
+
static create(options: ZSchemaOptions & {
|
|
566
|
+
async: true;
|
|
567
|
+
safe: true;
|
|
568
|
+
}): ZSchemaAsyncSafe;
|
|
569
|
+
static create(options: ZSchemaOptions & {
|
|
570
|
+
async: true;
|
|
571
|
+
}): ZSchemaAsync;
|
|
572
|
+
static create(options: ZSchemaOptions & {
|
|
573
|
+
safe: true;
|
|
574
|
+
}): ZSchemaSafe;
|
|
575
|
+
static create(options?: ZSchemaOptions): ZSchema;
|
|
576
|
+
/**
|
|
577
|
+
* Validate JSON data against a schema.
|
|
578
|
+
* @param json - The data to validate.
|
|
579
|
+
* @param schema - A JSON Schema object or a schema id string (previously registered via `validateSchema`).
|
|
580
|
+
* @param options - Per-call options (`schemaPath`, `includeErrors`, `excludeErrors`).
|
|
581
|
+
* @returns `true` if valid.
|
|
582
|
+
* @throws {@link ValidateError} if validation fails, with a `details` array of structured errors.
|
|
583
|
+
*/
|
|
584
|
+
validate(json: unknown, schema: JsonSchema | string, options?: ValidateOptions): true;
|
|
585
|
+
/**
|
|
586
|
+
* Validate JSON data against a schema, returning a result object instead of throwing.
|
|
587
|
+
* @param json - The data to validate.
|
|
588
|
+
* @param schema - A JSON Schema object or a schema id string.
|
|
589
|
+
* @param options - Per-call options.
|
|
590
|
+
* @returns `{ valid: true }` on success, or `{ valid: false, err: ValidateError }` on failure.
|
|
591
|
+
*/
|
|
592
|
+
validateSafe(json: unknown, schema: JsonSchema | string, options?: ValidateOptions): ValidateResponse;
|
|
593
|
+
/**
|
|
594
|
+
* Validate JSON data against a schema asynchronously (supports async format validators).
|
|
595
|
+
* @param json - The data to validate.
|
|
596
|
+
* @param schema - A JSON Schema object or a schema id string.
|
|
597
|
+
* @param options - Per-call options.
|
|
598
|
+
* @returns A promise that resolves to `true` if valid.
|
|
599
|
+
* @throws {@link ValidateError} if validation fails (the promise rejects).
|
|
600
|
+
*/
|
|
601
|
+
validateAsync(json: unknown, schema: JsonSchema | string, options?: ValidateOptions): Promise<true>;
|
|
602
|
+
/**
|
|
603
|
+
* Validate JSON data against a schema asynchronously, returning a result object.
|
|
604
|
+
* The promise always resolves (never rejects).
|
|
605
|
+
* @param json - The data to validate.
|
|
606
|
+
* @param schema - A JSON Schema object or a schema id string.
|
|
607
|
+
* @param options - Per-call options.
|
|
608
|
+
* @returns A promise resolving to `{ valid: true }` or `{ valid: false, err: ValidateError }`.
|
|
609
|
+
*/
|
|
610
|
+
validateAsyncSafe(json: unknown, schema: JsonSchema | string, options?: ValidateOptions): Promise<ValidateResponse>;
|
|
611
|
+
/**
|
|
612
|
+
* Validate one or more JSON Schemas, compiling and caching them for later use with `validate()`.
|
|
613
|
+
* @param schemaOrArr - A single schema or an array of schemas (for cross-referencing).
|
|
614
|
+
* @returns `true` if all schemas are valid.
|
|
615
|
+
* @throws {@link ValidateError} if any schema is invalid.
|
|
616
|
+
*/
|
|
617
|
+
validateSchema(schemaOrArr: JsonSchema | JsonSchema[]): true;
|
|
618
|
+
/**
|
|
619
|
+
* Validate one or more JSON Schemas, returning a result object instead of throwing.
|
|
620
|
+
* @param schemaOrArr - A single schema or an array of schemas.
|
|
621
|
+
* @returns `{ valid: true }` on success, or `{ valid: false, err: ValidateError }` on failure.
|
|
622
|
+
*/
|
|
623
|
+
validateSchemaSafe(schemaOrArr: JsonSchema | JsonSchema[]): ValidateResponse;
|
|
612
624
|
}
|
|
613
625
|
/**
|
|
614
626
|
* Synchronous safe validator — `validate()` returns `{ valid, err? }` instead of throwing.
|
|
615
627
|
* Created via `ZSchema.create({ safe: true })`.
|
|
616
628
|
*/
|
|
617
629
|
declare class ZSchemaSafe extends ZSchemaBase {
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
630
|
+
/** @internal Use ZSchema.create() instead. */
|
|
631
|
+
constructor(options: ZSchemaOptions | undefined, token: symbol);
|
|
632
|
+
/**
|
|
633
|
+
* Validate JSON data against a schema.
|
|
634
|
+
* @param json - The data to validate.
|
|
635
|
+
* @param schema - A JSON Schema object or a schema id string.
|
|
636
|
+
* @param options - Per-call options.
|
|
637
|
+
* @returns `{ valid: true }` on success, or `{ valid: false, err: ValidateError }` on failure.
|
|
638
|
+
*/
|
|
639
|
+
validate(json: unknown, schema: JsonSchema | string, options?: ValidateOptions): ValidateResponse;
|
|
640
|
+
/**
|
|
641
|
+
* Validate one or more JSON Schemas.
|
|
642
|
+
* @param schemaOrArr - A single schema or an array of schemas.
|
|
643
|
+
* @returns `{ valid: true }` on success, or `{ valid: false, err: ValidateError }` on failure.
|
|
644
|
+
*/
|
|
645
|
+
validateSchema(schemaOrArr: JsonSchema | JsonSchema[]): ValidateResponse;
|
|
634
646
|
}
|
|
635
647
|
/**
|
|
636
648
|
* Asynchronous throw validator — `validate()` returns `Promise<true>` or rejects.
|
|
637
649
|
* Created via `ZSchema.create({ async: true })`.
|
|
638
650
|
*/
|
|
639
651
|
declare class ZSchemaAsync extends ZSchemaBase {
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
652
|
+
/** @internal Use ZSchema.create() instead. */
|
|
653
|
+
constructor(options: ZSchemaOptions | undefined, token: symbol);
|
|
654
|
+
/**
|
|
655
|
+
* Validate JSON data against a schema asynchronously.
|
|
656
|
+
* @param json - The data to validate.
|
|
657
|
+
* @param schema - A JSON Schema object or a schema id string.
|
|
658
|
+
* @param options - Per-call options.
|
|
659
|
+
* @returns A promise that resolves to `true` if valid.
|
|
660
|
+
* @throws {@link ValidateError} if validation fails (the promise rejects).
|
|
661
|
+
*/
|
|
662
|
+
validate(json: unknown, schema: JsonSchema | string, options?: ValidateOptions): Promise<true>;
|
|
663
|
+
/**
|
|
664
|
+
* Validate one or more JSON Schemas (synchronous, throws on error).
|
|
665
|
+
* @param schemaOrArr - A single schema or an array of schemas.
|
|
666
|
+
* @returns `true` if all schemas are valid.
|
|
667
|
+
* @throws {@link ValidateError} if any schema is invalid.
|
|
668
|
+
*/
|
|
669
|
+
validateSchema(schemaOrArr: JsonSchema | JsonSchema[]): true;
|
|
658
670
|
}
|
|
659
671
|
/**
|
|
660
672
|
* Asynchronous safe validator — `validate()` returns `Promise<{ valid, err? }>` (never rejects).
|
|
661
673
|
* Created via `ZSchema.create({ async: true, safe: true })`.
|
|
662
674
|
*/
|
|
663
675
|
declare class ZSchemaAsyncSafe extends ZSchemaBase {
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
676
|
+
/** @internal Use ZSchema.create() instead. */
|
|
677
|
+
constructor(options: ZSchemaOptions | undefined, token: symbol);
|
|
678
|
+
/**
|
|
679
|
+
* Validate JSON data against a schema asynchronously.
|
|
680
|
+
* The promise always resolves (never rejects).
|
|
681
|
+
* @param json - The data to validate.
|
|
682
|
+
* @param schema - A JSON Schema object or a schema id string.
|
|
683
|
+
* @param options - Per-call options.
|
|
684
|
+
* @returns A promise resolving to `{ valid: true }` or `{ valid: false, err: ValidateError }`.
|
|
685
|
+
*/
|
|
686
|
+
validate(json: unknown, schema: JsonSchema | string, options?: ValidateOptions): Promise<ValidateResponse>;
|
|
687
|
+
/**
|
|
688
|
+
* Validate one or more JSON Schemas.
|
|
689
|
+
* @param schemaOrArr - A single schema or an array of schemas.
|
|
690
|
+
* @returns `{ valid: true }` on success, or `{ valid: false, err: ValidateError }` on failure.
|
|
691
|
+
*/
|
|
692
|
+
validateSchema(schemaOrArr: JsonSchema | JsonSchema[]): ValidateResponse;
|
|
681
693
|
}
|
|
682
|
-
|
|
683
|
-
export { Errors, Report,
|
|
684
|
-
export type { ErrorCode, ErrorParam, FormatValidatorFn, FormatValidatorsOptions, JsonSchema, JsonSchemaCommon, JsonSchemaDraft201909, JsonSchemaDraft202012, JsonSchemaDraft4, JsonSchemaDraft6, JsonSchemaDraft7, JsonSchemaType, JsonSchemaVersion, SchemaErrorDetail, SchemaReader, ValidateOptions, ValidateResponse, ZSchemaOptions };
|
|
694
|
+
//#endregion
|
|
695
|
+
export { type ErrorCode, type ErrorParam, type Errors, type FormatValidatorFn, type FormatValidatorsOptions, type JsonSchema, type JsonSchemaCommon, type JsonSchemaDraft201909, type JsonSchemaDraft202012, type JsonSchemaDraft4, type JsonSchemaDraft6, type JsonSchemaDraft7, type JsonSchemaType, type JsonSchemaVersion, type Report, type SchemaErrorDetail, type SchemaReader, ValidateError, type ValidateOptions, type ValidateResponse, type ZSchema, ZSchema as default, type ZSchemaAsync, type ZSchemaAsyncSafe, type ZSchemaOptions, type ZSchemaSafe, getFormatValidators, getRegisteredFormats, getSupportedFormats, isFormatSupported, registerFormat, unregisterFormat };
|