json-schema-library 10.4.2 → 10.5.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/dist/index.d.mts +12 -13
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/jlib.js +2 -2
- package/package.json +1 -1
- package/src/SchemaNode.ts +2 -1
- package/src/draft2019-09/keywords/$ref.ts +1 -1
- package/src/draft2019-09/methods/getData.ts +3 -3
- package/src/keywords/enum.test.ts +19 -0
- package/src/keywords/enum.ts +2 -1
- package/src/utils/getSchemaType.test.ts +108 -0
- package/src/utils/getSchemaType.ts +26 -15
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
|
|
3
|
-
//#region rolldown:runtime
|
|
4
|
-
//#endregion
|
|
5
1
|
//#region src/Keyword.d.ts
|
|
6
2
|
type ValidationPath = {
|
|
7
3
|
pointer: string;
|
|
@@ -213,6 +209,8 @@ declare const errors: {
|
|
|
213
209
|
"unknown-property-error": string;
|
|
214
210
|
"value-not-empty-error": string;
|
|
215
211
|
};
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/getNode.d.ts
|
|
216
214
|
declare function getNode(pointer: string, data: unknown, options: {
|
|
217
215
|
withSchemaWarning: true;
|
|
218
216
|
} & GetNodeOptions): NodeOrError;
|
|
@@ -395,7 +393,7 @@ declare const SchemaNodeMethods: {
|
|
|
395
393
|
* @returns SchemaNode representing the passed JSON Schema
|
|
396
394
|
*/
|
|
397
395
|
readonly compileSchema: (schema: JsonSchema, evaluationPath?: string, schemaLocation?: string, dynamicId?: string) => SchemaNode;
|
|
398
|
-
readonly createError: <T
|
|
396
|
+
readonly createError: <T extends string = "additional-items-error" | "additional-properties-error" | "all-of-error" | "any-of-error" | "const-error" | "contains-any-error" | "contains-array-error" | "contains-error" | "contains-min-error" | "contains-max-error" | "enum-error" | "exclusive-maximum-error" | "exclusive-minimum-error" | "forbidden-property-error" | "format-date-error" | "format-date-time-error" | "format-duration-error" | "format-email-error" | "format-hostname-error" | "format-ipv4-error" | "format-ipv4-leading-zero-error" | "format-ipv6-error" | "format-ipv6-leading-zero-error" | "format-json-pointer-error" | "format-regex-error" | "format-time-error" | "format-uri-error" | "format-uri-reference-error" | "format-uri-template-error" | "format-url-error" | "format-uuid-error" | "invalid-data-error" | "invalid-property-name-error" | "maximum-error" | "max-items-error" | "max-length-error" | "max-properties-error" | "minimum-error" | "min-items-error" | "min-items-one-error" | "min-length-error" | "min-length-one-error" | "missing-one-of-declarator-error" | "min-properties-error" | "missing-array-item-error" | "missing-dependency-error" | "missing-one-of-property-error" | "multiple-of-error" | "multiple-one-of-error" | "no-additional-properties-error" | "not-error" | "one-of-error" | "one-of-property-error" | "pattern-error" | "pattern-properties-error" | "required-property-error" | "schema-warning" | "type-error" | "undefined-value-error" | "unevaluated-property-error" | "unevaluated-items-error" | "unique-items-error" | "unknown-property-error" | "value-not-empty-error">(code: T, data: ErrorData, message?: string) => JsonError;
|
|
399
397
|
readonly createSchema: typeof createSchema;
|
|
400
398
|
readonly getChildSelection: (property: string | number) => JsonError | SchemaNode[];
|
|
401
399
|
readonly getNode: typeof getNode;
|
|
@@ -437,7 +435,7 @@ declare const SchemaNodeMethods: {
|
|
|
437
435
|
/**
|
|
438
436
|
* @returns a list of values (including objects and arrays) and their corresponding JSON Schema as SchemaNode
|
|
439
437
|
*/
|
|
440
|
-
readonly toDataNodes: (data: unknown, pointer?: string) =>
|
|
438
|
+
readonly toDataNodes: (data: unknown, pointer?: string) => DataNode[];
|
|
441
439
|
readonly toJSON: () => any;
|
|
442
440
|
};
|
|
443
441
|
//#endregion
|
|
@@ -462,18 +460,18 @@ type NodeOrError = {
|
|
|
462
460
|
node: undefined;
|
|
463
461
|
error: JsonError;
|
|
464
462
|
};
|
|
465
|
-
type ErrorData<T
|
|
463
|
+
type ErrorData<T extends Record<string, unknown> = {
|
|
466
464
|
[p: string]: unknown;
|
|
467
|
-
}> = T
|
|
465
|
+
}> = T & {
|
|
468
466
|
pointer: string;
|
|
469
467
|
schema: JsonSchema;
|
|
470
468
|
value: unknown;
|
|
471
469
|
};
|
|
472
|
-
type JsonError<T
|
|
470
|
+
type JsonError<T extends ErrorData = ErrorData> = {
|
|
473
471
|
type: "error";
|
|
474
472
|
code: ErrorConfig | string;
|
|
475
473
|
message: string;
|
|
476
|
-
data: T
|
|
474
|
+
data: T;
|
|
477
475
|
[p: string]: unknown;
|
|
478
476
|
};
|
|
479
477
|
/**
|
|
@@ -635,16 +633,17 @@ declare function getTypeOf(value: unknown): JSType;
|
|
|
635
633
|
declare function mergeNode(a: SchemaNode, b?: SchemaNode, ...omit: string[]): SchemaNode | undefined;
|
|
636
634
|
//#endregion
|
|
637
635
|
//#region src/utils/mergeSchema.d.ts
|
|
638
|
-
declare function mergeSchema<T
|
|
636
|
+
declare function mergeSchema<T extends JsonSchema>(a: T, b: T, ...omit: string[]): T;
|
|
639
637
|
//#endregion
|
|
640
638
|
//#region src/utils/getSchemaType.d.ts
|
|
641
|
-
declare const SCHEMA_TYPES: string
|
|
639
|
+
declare const SCHEMA_TYPES: readonly ["string", "number", "integer", "boolean", "null", "array", "object"];
|
|
640
|
+
type SchemaType = (typeof SCHEMA_TYPES)[number];
|
|
642
641
|
/**
|
|
643
642
|
* @helper for getData
|
|
644
643
|
* returns schema type, which might be an educated guess based on defined schema
|
|
645
644
|
* properties if an exact type cannot be retried from type.
|
|
646
645
|
*/
|
|
647
|
-
declare function getSchemaType(node: SchemaNode, data: unknown):
|
|
646
|
+
declare function getSchemaType(node: SchemaNode, data: unknown): SchemaType | undefined;
|
|
648
647
|
//#endregion
|
|
649
648
|
//#region remotes/index.d.ts
|
|
650
649
|
/** remote meta-schema stored by schema $id */
|
package/dist/index.d.ts
CHANGED
|
@@ -435,7 +435,7 @@ declare const SchemaNodeMethods: {
|
|
|
435
435
|
/**
|
|
436
436
|
* @returns a list of values (including objects and arrays) and their corresponding JSON Schema as SchemaNode
|
|
437
437
|
*/
|
|
438
|
-
readonly toDataNodes: (data: unknown, pointer?: string) =>
|
|
438
|
+
readonly toDataNodes: (data: unknown, pointer?: string) => DataNode[];
|
|
439
439
|
readonly toJSON: () => any;
|
|
440
440
|
};
|
|
441
441
|
//#endregion
|
|
@@ -636,13 +636,14 @@ declare function mergeNode(a: SchemaNode, b?: SchemaNode, ...omit: string[]): Sc
|
|
|
636
636
|
declare function mergeSchema<T extends JsonSchema>(a: T, b: T, ...omit: string[]): T;
|
|
637
637
|
//#endregion
|
|
638
638
|
//#region src/utils/getSchemaType.d.ts
|
|
639
|
-
declare const SCHEMA_TYPES: string
|
|
639
|
+
declare const SCHEMA_TYPES: readonly ["string", "number", "integer", "boolean", "null", "array", "object"];
|
|
640
|
+
type SchemaType = (typeof SCHEMA_TYPES)[number];
|
|
640
641
|
/**
|
|
641
642
|
* @helper for getData
|
|
642
643
|
* returns schema type, which might be an educated guess based on defined schema
|
|
643
644
|
* properties if an exact type cannot be retried from type.
|
|
644
645
|
*/
|
|
645
|
-
declare function getSchemaType(node: SchemaNode, data: unknown):
|
|
646
|
+
declare function getSchemaType(node: SchemaNode, data: unknown): SchemaType | undefined;
|
|
646
647
|
//#endregion
|
|
647
648
|
//#region remotes/index.d.ts
|
|
648
649
|
/** remote meta-schema stored by schema $id */
|