json-schema-library 10.5.4 → 11.0.1
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/README.md +128 -14
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +42 -19
- package/dist/index.d.mts +42 -19
- package/dist/index.mjs +1 -1
- package/dist/jlib.js +2 -2
- package/index.ts +8 -4
- package/package.json +6 -6
- package/src/Keyword.ts +8 -3
- package/src/SchemaNode.ts +46 -10
- package/src/compileSchema.validate.test.ts +89 -54
- package/src/draft04.ts +10 -8
- package/src/draft06.ts +10 -8
- package/src/draft07.ts +10 -8
- package/src/draft2019-09/keywords/additionalItems.ts +2 -2
- package/src/draft2019-09/keywords/items.ts +2 -2
- package/src/draft2019-09/keywords/unevaluatedItems.ts +12 -6
- package/src/draft2019.ts +10 -8
- package/src/draft2020.ts +8 -6
- package/src/errors/errors.ts +3 -1
- package/src/formats/formats.ts +2 -6
- package/src/keywords/additionalProperties.ts +2 -2
- package/src/keywords/allOf.ts +2 -2
- package/src/keywords/dependencies.ts +5 -6
- package/src/keywords/dependentRequired.ts +2 -2
- package/src/keywords/dependentSchemas.ts +4 -3
- package/src/keywords/deprecated.ts +18 -0
- package/src/keywords/items.ts +2 -2
- package/src/keywords/oneOf.test.ts +150 -15
- package/src/keywords/oneOf.ts +64 -4
- package/src/keywords/patternProperties.ts +2 -2
- package/src/keywords/prefixItems.ts +2 -11
- package/src/keywords/properties.ts +2 -2
- package/src/keywords/unevaluatedItems.ts +2 -2
- package/src/keywords/unevaluatedProperties.ts +2 -2
- package/src/methods/getData.test.ts +1779 -1781
- package/src/types.ts +32 -18
- package/src/utils/sanitizeErrors.ts +9 -8
- package/src/validateNode.ts +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -25,7 +25,10 @@ interface JsonSchemaResolver {
|
|
|
25
25
|
order?: number;
|
|
26
26
|
(options: JsonSchemaResolverParams): SchemaNode | JsonError | undefined;
|
|
27
27
|
}
|
|
28
|
-
type
|
|
28
|
+
type Maybe<T> = T | undefined;
|
|
29
|
+
type ValidationAnnotation = JsonError | JsonAnnotation | Promise<Maybe<ValidationAnnotation>[]>;
|
|
30
|
+
type ValidationResult = Maybe<ValidationAnnotation>;
|
|
31
|
+
type ValidationReturnType = ValidationResult | ValidationResult[];
|
|
29
32
|
type JsonSchemaValidatorParams = {
|
|
30
33
|
pointer: string;
|
|
31
34
|
data: unknown;
|
|
@@ -35,7 +38,7 @@ type JsonSchemaValidatorParams = {
|
|
|
35
38
|
interface JsonSchemaValidator {
|
|
36
39
|
toJSON?: () => string;
|
|
37
40
|
order?: number;
|
|
38
|
-
(options: JsonSchemaValidatorParams):
|
|
41
|
+
(options: JsonSchemaValidatorParams): ValidationReturnType;
|
|
39
42
|
}
|
|
40
43
|
type Keyword = {
|
|
41
44
|
id: string; /** unique keyword corresponding to JSON Schema keywords (or custom) */
|
|
@@ -192,6 +195,7 @@ declare const errors: {
|
|
|
192
195
|
"unique-items-error": string;
|
|
193
196
|
"unknown-property-error": string;
|
|
194
197
|
"value-not-empty-error": string;
|
|
198
|
+
"deprecated-warning": string;
|
|
195
199
|
};
|
|
196
200
|
//#endregion
|
|
197
201
|
//#region src/SchemaNode.d.ts
|
|
@@ -310,7 +314,8 @@ interface SchemaNode extends SchemaNodeMethodsType {
|
|
|
310
314
|
*/
|
|
311
315
|
interface SchemaNodeMethodsType {
|
|
312
316
|
compileSchema(schema: JsonSchema, evaluationPath?: string, schemaLocation?: string, dynamicId?: string): SchemaNode;
|
|
313
|
-
createError<T extends string = DefaultErrors>(code: T, data:
|
|
317
|
+
createError<T extends string = DefaultErrors>(code: T, data: AnnotationData, message?: string): JsonError;
|
|
318
|
+
createAnnotation<T extends string = DefaultErrors>(code: T, data: AnnotationData, message?: string): JsonAnnotation;
|
|
314
319
|
createSchema(data?: unknown): JsonSchema;
|
|
315
320
|
getNode(pointer: string, data: unknown, options: {
|
|
316
321
|
withSchemaWarning: true;
|
|
@@ -330,7 +335,7 @@ interface SchemaNodeMethodsType {
|
|
|
330
335
|
getNodeRef($ref: string): SchemaNode | undefined;
|
|
331
336
|
getNodeRoot(): SchemaNode;
|
|
332
337
|
getDraftVersion(): string;
|
|
333
|
-
getData(data?: unknown, options?: TemplateOptions):
|
|
338
|
+
getData(data?: unknown, options?: TemplateOptions): any;
|
|
334
339
|
reduceNode(data: unknown, options?: {
|
|
335
340
|
key?: string | number;
|
|
336
341
|
pointer?: string;
|
|
@@ -372,10 +377,14 @@ type ValidateReturnType = {
|
|
|
372
377
|
* List of validation errors or empty
|
|
373
378
|
*/
|
|
374
379
|
errors: JsonError[];
|
|
380
|
+
/**
|
|
381
|
+
* List of annotations from validators
|
|
382
|
+
*/
|
|
383
|
+
annotations: JsonAnnotation[];
|
|
375
384
|
/**
|
|
376
385
|
* List of Promises resolving to `JsonError|undefined` or empty.
|
|
377
386
|
*/
|
|
378
|
-
errorsAsync: Promise<
|
|
387
|
+
errorsAsync: Promise<Maybe<ValidationAnnotation>[]>[];
|
|
379
388
|
};
|
|
380
389
|
//#endregion
|
|
381
390
|
//#region src/types.d.ts
|
|
@@ -383,8 +392,20 @@ interface JsonSchema {
|
|
|
383
392
|
[keyword: string]: any;
|
|
384
393
|
}
|
|
385
394
|
type JsonPointer = string;
|
|
395
|
+
type AnnotationData<D extends Record<string, unknown> = Record<string, unknown>> = D & {
|
|
396
|
+
pointer: string;
|
|
397
|
+
schema: JsonSchema;
|
|
398
|
+
value: unknown;
|
|
399
|
+
};
|
|
400
|
+
type Annotation<T = string, D extends AnnotationData = AnnotationData, S = string> = {
|
|
401
|
+
type: T;
|
|
402
|
+
code: S;
|
|
403
|
+
message: string;
|
|
404
|
+
data: D;
|
|
405
|
+
[p: string]: unknown;
|
|
406
|
+
};
|
|
386
407
|
type DefaultErrors = keyof typeof errors;
|
|
387
|
-
type ErrorConfig = Record<DefaultErrors | string, string | ((error:
|
|
408
|
+
type ErrorConfig = Record<DefaultErrors | string, string | ((error: AnnotationData) => void)>;
|
|
388
409
|
type OptionalNodeOrError = {
|
|
389
410
|
node?: SchemaNode;
|
|
390
411
|
error: undefined;
|
|
@@ -399,18 +420,14 @@ type NodeOrError = {
|
|
|
399
420
|
node: undefined;
|
|
400
421
|
error: JsonError;
|
|
401
422
|
};
|
|
402
|
-
type
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
message: string;
|
|
411
|
-
data: T;
|
|
412
|
-
[p: string]: unknown;
|
|
413
|
-
};
|
|
423
|
+
type JsonError<D extends AnnotationData = AnnotationData> = Annotation<"error", D, ErrorConfig | string>;
|
|
424
|
+
type JsonAnnotation<D extends AnnotationData = AnnotationData> = Annotation<"annotation", D>;
|
|
425
|
+
declare function isAnnotation(value: any): value is Annotation;
|
|
426
|
+
/**
|
|
427
|
+
* ts type guard for json error
|
|
428
|
+
* @returns true if passed type is a JsonError
|
|
429
|
+
*/
|
|
430
|
+
declare function isJsonAnnotation(error: unknown): error is JsonAnnotation;
|
|
414
431
|
/**
|
|
415
432
|
* ts type guard for json error
|
|
416
433
|
* @returns true if passed type is a JsonError
|
|
@@ -580,8 +597,14 @@ type SchemaType = (typeof SCHEMA_TYPES)[number];
|
|
|
580
597
|
*/
|
|
581
598
|
declare function getSchemaType(node: SchemaNode, data: unknown): SchemaType | undefined;
|
|
582
599
|
//#endregion
|
|
600
|
+
//#region src/utils/sanitizeErrors.d.ts
|
|
601
|
+
/**
|
|
602
|
+
* Flattens nested validation array results and filters items to only include errors, annotations and promises
|
|
603
|
+
*/
|
|
604
|
+
declare function sanitizeErrors(list: ValidationReturnType | ValidationReturnType[] | ValidationAnnotation[], result?: ValidationAnnotation[]): ValidationAnnotation[];
|
|
605
|
+
//#endregion
|
|
583
606
|
//#region remotes/index.d.ts
|
|
584
607
|
/** remote meta-schema stored by schema $id */
|
|
585
608
|
declare const remotes: Record<string, any>;
|
|
586
609
|
//#endregion
|
|
587
|
-
export { type CompileOptions, type Context, type DataNode, type Draft, type DraftVersion, type ErrorConfig, type
|
|
610
|
+
export { type Annotation, type AnnotationData, type CompileOptions, type Context, type DataNode, type Draft, type DraftVersion, type ErrorConfig, type GetNodeOptions, type JsonAnnotation, type JsonError, type JsonPointer, type JsonSchema, type JsonSchemaReducer, type JsonSchemaReducerParams, type JsonSchemaResolver, type JsonSchemaResolverParams, type JsonSchemaValidator, type JsonSchemaValidatorParams, type Keyword, type Maybe, type NodeOrError, type OptionalNodeOrError, type SchemaNode, type ValidateReturnType, type ValidationAnnotation, type ValidationPath, type ValidationReturnType, addKeywords, compileSchema, draft04, draft06, draft07, draft2019, draft2020, draftEditor, extendDraft, getSchemaType, getTypeOf, isAnnotation, isJsonAnnotation, isJsonError, isReduceable, isSchemaNode, mergeNode, mergeSchema, oneOfFuzzyKeyword, oneOfKeyword, remotes, render, sanitizeErrors, _default as settings };
|
package/dist/index.d.mts
CHANGED
|
@@ -25,7 +25,10 @@ interface JsonSchemaResolver {
|
|
|
25
25
|
order?: number;
|
|
26
26
|
(options: JsonSchemaResolverParams): SchemaNode | JsonError | undefined;
|
|
27
27
|
}
|
|
28
|
-
type
|
|
28
|
+
type Maybe<T> = T | undefined;
|
|
29
|
+
type ValidationAnnotation = JsonError | JsonAnnotation | Promise<Maybe<ValidationAnnotation>[]>;
|
|
30
|
+
type ValidationResult = Maybe<ValidationAnnotation>;
|
|
31
|
+
type ValidationReturnType = ValidationResult | ValidationResult[];
|
|
29
32
|
type JsonSchemaValidatorParams = {
|
|
30
33
|
pointer: string;
|
|
31
34
|
data: unknown;
|
|
@@ -35,7 +38,7 @@ type JsonSchemaValidatorParams = {
|
|
|
35
38
|
interface JsonSchemaValidator {
|
|
36
39
|
toJSON?: () => string;
|
|
37
40
|
order?: number;
|
|
38
|
-
(options: JsonSchemaValidatorParams):
|
|
41
|
+
(options: JsonSchemaValidatorParams): ValidationReturnType;
|
|
39
42
|
}
|
|
40
43
|
type Keyword = {
|
|
41
44
|
id: string; /** unique keyword corresponding to JSON Schema keywords (or custom) */
|
|
@@ -192,6 +195,7 @@ declare const errors: {
|
|
|
192
195
|
"unique-items-error": string;
|
|
193
196
|
"unknown-property-error": string;
|
|
194
197
|
"value-not-empty-error": string;
|
|
198
|
+
"deprecated-warning": string;
|
|
195
199
|
};
|
|
196
200
|
//#endregion
|
|
197
201
|
//#region src/SchemaNode.d.ts
|
|
@@ -310,7 +314,8 @@ interface SchemaNode extends SchemaNodeMethodsType {
|
|
|
310
314
|
*/
|
|
311
315
|
interface SchemaNodeMethodsType {
|
|
312
316
|
compileSchema(schema: JsonSchema, evaluationPath?: string, schemaLocation?: string, dynamicId?: string): SchemaNode;
|
|
313
|
-
createError<T extends string = DefaultErrors>(code: T, data:
|
|
317
|
+
createError<T extends string = DefaultErrors>(code: T, data: AnnotationData, message?: string): JsonError;
|
|
318
|
+
createAnnotation<T extends string = DefaultErrors>(code: T, data: AnnotationData, message?: string): JsonAnnotation;
|
|
314
319
|
createSchema(data?: unknown): JsonSchema;
|
|
315
320
|
getNode(pointer: string, data: unknown, options: {
|
|
316
321
|
withSchemaWarning: true;
|
|
@@ -330,7 +335,7 @@ interface SchemaNodeMethodsType {
|
|
|
330
335
|
getNodeRef($ref: string): SchemaNode | undefined;
|
|
331
336
|
getNodeRoot(): SchemaNode;
|
|
332
337
|
getDraftVersion(): string;
|
|
333
|
-
getData(data?: unknown, options?: TemplateOptions):
|
|
338
|
+
getData(data?: unknown, options?: TemplateOptions): any;
|
|
334
339
|
reduceNode(data: unknown, options?: {
|
|
335
340
|
key?: string | number;
|
|
336
341
|
pointer?: string;
|
|
@@ -372,10 +377,14 @@ type ValidateReturnType = {
|
|
|
372
377
|
* List of validation errors or empty
|
|
373
378
|
*/
|
|
374
379
|
errors: JsonError[];
|
|
380
|
+
/**
|
|
381
|
+
* List of annotations from validators
|
|
382
|
+
*/
|
|
383
|
+
annotations: JsonAnnotation[];
|
|
375
384
|
/**
|
|
376
385
|
* List of Promises resolving to `JsonError|undefined` or empty.
|
|
377
386
|
*/
|
|
378
|
-
errorsAsync: Promise<
|
|
387
|
+
errorsAsync: Promise<Maybe<ValidationAnnotation>[]>[];
|
|
379
388
|
};
|
|
380
389
|
//#endregion
|
|
381
390
|
//#region src/types.d.ts
|
|
@@ -383,8 +392,20 @@ interface JsonSchema {
|
|
|
383
392
|
[keyword: string]: any;
|
|
384
393
|
}
|
|
385
394
|
type JsonPointer = string;
|
|
395
|
+
type AnnotationData<D extends Record<string, unknown> = Record<string, unknown>> = D & {
|
|
396
|
+
pointer: string;
|
|
397
|
+
schema: JsonSchema;
|
|
398
|
+
value: unknown;
|
|
399
|
+
};
|
|
400
|
+
type Annotation<T = string, D extends AnnotationData = AnnotationData, S = string> = {
|
|
401
|
+
type: T;
|
|
402
|
+
code: S;
|
|
403
|
+
message: string;
|
|
404
|
+
data: D;
|
|
405
|
+
[p: string]: unknown;
|
|
406
|
+
};
|
|
386
407
|
type DefaultErrors = keyof typeof errors;
|
|
387
|
-
type ErrorConfig = Record<DefaultErrors | string, string | ((error:
|
|
408
|
+
type ErrorConfig = Record<DefaultErrors | string, string | ((error: AnnotationData) => void)>;
|
|
388
409
|
type OptionalNodeOrError = {
|
|
389
410
|
node?: SchemaNode;
|
|
390
411
|
error: undefined;
|
|
@@ -399,18 +420,14 @@ type NodeOrError = {
|
|
|
399
420
|
node: undefined;
|
|
400
421
|
error: JsonError;
|
|
401
422
|
};
|
|
402
|
-
type
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
message: string;
|
|
411
|
-
data: T;
|
|
412
|
-
[p: string]: unknown;
|
|
413
|
-
};
|
|
423
|
+
type JsonError<D extends AnnotationData = AnnotationData> = Annotation<"error", D, ErrorConfig | string>;
|
|
424
|
+
type JsonAnnotation<D extends AnnotationData = AnnotationData> = Annotation<"annotation", D>;
|
|
425
|
+
declare function isAnnotation(value: any): value is Annotation;
|
|
426
|
+
/**
|
|
427
|
+
* ts type guard for json error
|
|
428
|
+
* @returns true if passed type is a JsonError
|
|
429
|
+
*/
|
|
430
|
+
declare function isJsonAnnotation(error: unknown): error is JsonAnnotation;
|
|
414
431
|
/**
|
|
415
432
|
* ts type guard for json error
|
|
416
433
|
* @returns true if passed type is a JsonError
|
|
@@ -580,8 +597,14 @@ type SchemaType = (typeof SCHEMA_TYPES)[number];
|
|
|
580
597
|
*/
|
|
581
598
|
declare function getSchemaType(node: SchemaNode, data: unknown): SchemaType | undefined;
|
|
582
599
|
//#endregion
|
|
600
|
+
//#region src/utils/sanitizeErrors.d.ts
|
|
601
|
+
/**
|
|
602
|
+
* Flattens nested validation array results and filters items to only include errors, annotations and promises
|
|
603
|
+
*/
|
|
604
|
+
declare function sanitizeErrors(list: ValidationReturnType | ValidationReturnType[] | ValidationAnnotation[], result?: ValidationAnnotation[]): ValidationAnnotation[];
|
|
605
|
+
//#endregion
|
|
583
606
|
//#region remotes/index.d.ts
|
|
584
607
|
/** remote meta-schema stored by schema $id */
|
|
585
608
|
declare const remotes: Record<string, any>;
|
|
586
609
|
//#endregion
|
|
587
|
-
export { type CompileOptions, type Context, type DataNode, type Draft, type DraftVersion, type ErrorConfig, type
|
|
610
|
+
export { type Annotation, type AnnotationData, type CompileOptions, type Context, type DataNode, type Draft, type DraftVersion, type ErrorConfig, type GetNodeOptions, type JsonAnnotation, type JsonError, type JsonPointer, type JsonSchema, type JsonSchemaReducer, type JsonSchemaReducerParams, type JsonSchemaResolver, type JsonSchemaResolverParams, type JsonSchemaValidator, type JsonSchemaValidatorParams, type Keyword, type Maybe, type NodeOrError, type OptionalNodeOrError, type SchemaNode, type ValidateReturnType, type ValidationAnnotation, type ValidationPath, type ValidationReturnType, addKeywords, compileSchema, draft04, draft06, draft07, draft2019, draft2020, draftEditor, extendDraft, getSchemaType, getTypeOf, isAnnotation, isJsonAnnotation, isJsonError, isReduceable, isSchemaNode, mergeNode, mergeSchema, oneOfFuzzyKeyword, oneOfKeyword, remotes, render, sanitizeErrors, _default as settings };
|