z-schema 8.1.0 → 8.3.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/cjs/index.d.ts +12 -5
- package/cjs/index.js +123 -108
- package/dist/json-validation.js +28 -28
- package/dist/report.js +20 -5
- package/dist/schema-validator.js +74 -74
- package/dist/types/report.d.ts +12 -6
- package/dist/types/z-schema.d.ts +1 -0
- package/dist/z-schema.js +1 -1
- package/package.json +1 -1
- package/src/json-validation.ts +46 -28
- package/src/report.ts +43 -11
- package/src/schema-validator.ts +122 -74
- package/src/z-schema.ts +2 -1
- package/umd/ZSchema.js +123 -108
- package/umd/ZSchema.min.js +1 -1
package/cjs/index.d.ts
CHANGED
|
@@ -160,6 +160,11 @@ interface SchemaErrorDetail {
|
|
|
160
160
|
*/
|
|
161
161
|
inner?: SchemaErrorDetail[];
|
|
162
162
|
schemaId?: string;
|
|
163
|
+
/**
|
|
164
|
+
* The schema keyword that caused this validation error.
|
|
165
|
+
* Example: "required", "type", "minLength"
|
|
166
|
+
*/
|
|
167
|
+
keyword?: keyof JsonSchema;
|
|
163
168
|
}
|
|
164
169
|
interface ReportOptions {
|
|
165
170
|
maxErrors?: number;
|
|
@@ -179,9 +184,10 @@ declare class Report {
|
|
|
179
184
|
parentReport?: Report;
|
|
180
185
|
options: ZSchemaOptions;
|
|
181
186
|
reportOptions: ReportOptions;
|
|
182
|
-
|
|
183
|
-
constructor(
|
|
184
|
-
constructor(parentReport: Report,
|
|
187
|
+
validateOptions: ValidateOptions;
|
|
188
|
+
constructor(zschemaOptions: ZSchemaOptions, validateOptions?: ValidateOptions);
|
|
189
|
+
constructor(parentReport: Report, validateOptions?: ValidateOptions);
|
|
190
|
+
constructor(parentReport: Report, reportOptions: ReportOptions, validateOptions?: ValidateOptions);
|
|
185
191
|
isValid(): boolean;
|
|
186
192
|
addAsyncTask<FV, FN extends (...args: any[]) => FV>(fn: FN, args: Parameters<FN>, asyncTaskResultProcessFn: (result: ReturnType<FN>) => void): void;
|
|
187
193
|
getAncestor(id: string): Report | undefined;
|
|
@@ -189,9 +195,9 @@ declare class Report {
|
|
|
189
195
|
getPath(returnPathAsString?: boolean): string | (string | number)[];
|
|
190
196
|
getSchemaId(): string | undefined;
|
|
191
197
|
hasError(errCode: string, errParams: Array<any>): boolean;
|
|
192
|
-
addError(errCode: ErrorCode, errParams?: ErrorParam[], subReports?: Report | Report[], schema?: JsonSchema): void;
|
|
198
|
+
addError(errCode: ErrorCode, errParams?: ErrorParam[], subReports?: Report | Report[], schema?: JsonSchema, keyword?: keyof JsonSchema): void;
|
|
193
199
|
getJson(): unknown;
|
|
194
|
-
addCustomError(errorCode:
|
|
200
|
+
addCustomError(errorCode: ErrorCode, errorMessage: string, params?: ErrorParam[], subReports?: Report | Report[], schema?: JsonSchema, keyword?: keyof JsonSchema): void;
|
|
195
201
|
}
|
|
196
202
|
|
|
197
203
|
type FormatValidatorFn = (input: unknown) => boolean;
|
|
@@ -262,6 +268,7 @@ interface ZSchemaOptions {
|
|
|
262
268
|
interface ValidateOptions {
|
|
263
269
|
schemaPath?: string;
|
|
264
270
|
includeErrors?: Array<keyof typeof Errors>;
|
|
271
|
+
excludeErrors?: Array<keyof typeof Errors>;
|
|
265
272
|
}
|
|
266
273
|
type ValidateCallback = (e: Error | SchemaErrorDetail[] | null, valid: boolean) => void;
|
|
267
274
|
type SchemaReader = (uri: string) => JsonSchema;
|