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