json-schema-library 11.0.1 → 11.0.3
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/.vscode/launch.json +37 -0
- package/README.md +17 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +34 -7
- package/dist/index.d.mts +34 -7
- package/dist/index.mjs +1 -1
- package/dist/jlib.js +2 -2
- package/index.ts +2 -2
- package/package.json +7 -2
- package/src/SchemaNode.ts +37 -9
- package/src/compileSchema.ts +5 -5
- package/src/draftEditor.ts +4 -4
- package/src/errors/errors.ts +3 -2
- package/src/getNode.oneOfProperty.test.ts +43 -0
- package/src/{compileSchema.getNode.test.ts → getNode.test.ts} +1 -1
- package/src/getNode.ts +16 -3
- package/src/getNodeChild.ts +34 -28
- package/src/keywords/oneOf.test.ts +40 -17
- package/src/keywords/oneOf.ts +23 -8
- package/src/methods/getChildSelection.test.ts +18 -0
- package/src/methods/getChildSelection.ts +1 -1
- package/src/{compileSchema.reduceSchema.test.ts → reduceNode.test.ts} +0 -1
- package/src/types.ts +7 -0
- /package/src/{compileSchema.getChild.test.ts → getChildNode.test.ts} +0 -0
- /package/src/{compileSchema.validate.test.ts → validate.test.ts} +0 -0
package/dist/index.d.cts
CHANGED
|
@@ -74,7 +74,7 @@ declare function toDataNodes(node: SchemaNode, data: unknown, pointer?: string,
|
|
|
74
74
|
* could be added at the given property (e.g. item-index), thus an array of options is returned. In all other cases
|
|
75
75
|
* a list with a single item will be returned
|
|
76
76
|
*/
|
|
77
|
-
declare function getChildSelection(node: SchemaNode, property: string | number): SchemaNode[]
|
|
77
|
+
declare function getChildSelection(node: SchemaNode, property: string | number): JsonError | SchemaNode[];
|
|
78
78
|
//#endregion
|
|
79
79
|
//#region src/methods/getData.d.ts
|
|
80
80
|
type TemplateOptions = {
|
|
@@ -313,10 +313,26 @@ interface SchemaNode extends SchemaNodeMethodsType {
|
|
|
313
313
|
* Fixed SchemaNode mixin methods
|
|
314
314
|
*/
|
|
315
315
|
interface SchemaNodeMethodsType {
|
|
316
|
-
compileSchema(schema: JsonSchema, evaluationPath?: string, schemaLocation?: string, dynamicId?: string): SchemaNode;
|
|
316
|
+
compileSchema(schema: JsonSchema | BooleanSchema, evaluationPath?: string, schemaLocation?: string, dynamicId?: string): SchemaNode;
|
|
317
317
|
createError<T extends string = DefaultErrors>(code: T, data: AnnotationData, message?: string): JsonError;
|
|
318
318
|
createAnnotation<T extends string = DefaultErrors>(code: T, data: AnnotationData, message?: string): JsonAnnotation;
|
|
319
319
|
createSchema(data?: unknown): JsonSchema;
|
|
320
|
+
/**
|
|
321
|
+
* Returns a node matching the given location (pointer) in data
|
|
322
|
+
*
|
|
323
|
+
* - the returned node will have a **reduced schema** based on given input data
|
|
324
|
+
* - return returned node $ref is resolved
|
|
325
|
+
*
|
|
326
|
+
* To resolve dynamic schema where the type of JSON Schema is evaluated by
|
|
327
|
+
* its value, a data object has to be passed in options.
|
|
328
|
+
*
|
|
329
|
+
* Per default this function will return `undefined` schema for valid properties
|
|
330
|
+
* that do not have a defined schema. Use the option `withSchemaWarning: true` to
|
|
331
|
+
* receive an error with `code: schema-warning` containing the location of its
|
|
332
|
+
* last evaluated json-schema.
|
|
333
|
+
*
|
|
334
|
+
* @returns { node } or { error } where node can also be undefined (valid but undefined)
|
|
335
|
+
*/
|
|
320
336
|
getNode(pointer: string, data: unknown, options: {
|
|
321
337
|
withSchemaWarning: true;
|
|
322
338
|
} & GetNodeOptions): NodeOrError;
|
|
@@ -324,6 +340,14 @@ interface SchemaNodeMethodsType {
|
|
|
324
340
|
createSchema: true;
|
|
325
341
|
} & GetNodeOptions): NodeOrError;
|
|
326
342
|
getNode(pointer: string, data?: unknown, options?: GetNodeOptions): OptionalNodeOrError;
|
|
343
|
+
/**
|
|
344
|
+
* Returns the child for the given property-name or array-index
|
|
345
|
+
*
|
|
346
|
+
* - the returned child node is **not reduced**
|
|
347
|
+
* - a child node $ref is resolved
|
|
348
|
+
*
|
|
349
|
+
* @returns { node } or { error } where node can also be undefined (valid but undefined)
|
|
350
|
+
*/
|
|
327
351
|
getNodeChild(key: string | number, data: unknown, options: {
|
|
328
352
|
withSchemaWarning: true;
|
|
329
353
|
} & GetNodeOptions): NodeOrError;
|
|
@@ -346,7 +370,7 @@ interface SchemaNodeMethodsType {
|
|
|
346
370
|
path?: ValidationPath;
|
|
347
371
|
}) => SchemaNode;
|
|
348
372
|
validate(data: unknown, pointer?: string, path?: ValidationPath): ValidateReturnType;
|
|
349
|
-
addRemoteSchema(url: string, schema: JsonSchema): SchemaNode;
|
|
373
|
+
addRemoteSchema(url: string, schema: JsonSchema | BooleanSchema): SchemaNode;
|
|
350
374
|
toSchemaNodes(): SchemaNode[];
|
|
351
375
|
toDataNodes(data: unknown, pointer?: string): DataNode[];
|
|
352
376
|
toJSON(): unknown;
|
|
@@ -388,9 +412,12 @@ type ValidateReturnType = {
|
|
|
388
412
|
};
|
|
389
413
|
//#endregion
|
|
390
414
|
//#region src/types.d.ts
|
|
415
|
+
type BooleanSchema = boolean;
|
|
391
416
|
interface JsonSchema {
|
|
392
417
|
[keyword: string]: any;
|
|
393
418
|
}
|
|
419
|
+
declare function isJsonSchema(value: unknown): value is JsonSchema;
|
|
420
|
+
declare function isBooleanSchema(value: unknown): value is BooleanSchema;
|
|
394
421
|
type JsonPointer = string;
|
|
395
422
|
type AnnotationData<D extends Record<string, unknown> = Record<string, unknown>> = D & {
|
|
396
423
|
pointer: string;
|
|
@@ -446,7 +473,7 @@ type CompileOptions = {
|
|
|
446
473
|
* wrapping each schema with utilities and as much preevaluation as possible. Each
|
|
447
474
|
* node will be reused for each task, but will create a compiledNode for bound data.
|
|
448
475
|
*/
|
|
449
|
-
declare function compileSchema(schema: JsonSchema, options?: CompileOptions): SchemaNode;
|
|
476
|
+
declare function compileSchema(schema: JsonSchema | BooleanSchema, options?: CompileOptions): SchemaNode;
|
|
450
477
|
//#endregion
|
|
451
478
|
//#region src/settings.d.ts
|
|
452
479
|
declare const _default: {
|
|
@@ -564,9 +591,9 @@ declare const draft2020: Draft;
|
|
|
564
591
|
//#endregion
|
|
565
592
|
//#region src/draftEditor.d.ts
|
|
566
593
|
/**
|
|
567
|
-
* @draft-editor https://json-schema.org/draft/
|
|
594
|
+
* @draft-editor https://json-schema.org/draft/2020-12/release-notes
|
|
568
595
|
*
|
|
569
|
-
* Uses Draft
|
|
596
|
+
* Uses Draft 2020-12 and changes resolveOneOf to be fuzzy
|
|
570
597
|
*/
|
|
571
598
|
declare const draftEditor: Draft;
|
|
572
599
|
//#endregion
|
|
@@ -607,4 +634,4 @@ declare function sanitizeErrors(list: ValidationReturnType | ValidationReturnTyp
|
|
|
607
634
|
/** remote meta-schema stored by schema $id */
|
|
608
635
|
declare const remotes: Record<string, any>;
|
|
609
636
|
//#endregion
|
|
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 };
|
|
637
|
+
export { type Annotation, type AnnotationData, type BooleanSchema, 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, isBooleanSchema, isJsonAnnotation, isJsonError, isJsonSchema, isReduceable, isSchemaNode, mergeNode, mergeSchema, oneOfFuzzyKeyword, oneOfKeyword, remotes, render, sanitizeErrors, _default as settings };
|
package/dist/index.d.mts
CHANGED
|
@@ -74,7 +74,7 @@ declare function toDataNodes(node: SchemaNode, data: unknown, pointer?: string,
|
|
|
74
74
|
* could be added at the given property (e.g. item-index), thus an array of options is returned. In all other cases
|
|
75
75
|
* a list with a single item will be returned
|
|
76
76
|
*/
|
|
77
|
-
declare function getChildSelection(node: SchemaNode, property: string | number): SchemaNode[]
|
|
77
|
+
declare function getChildSelection(node: SchemaNode, property: string | number): JsonError | SchemaNode[];
|
|
78
78
|
//#endregion
|
|
79
79
|
//#region src/methods/getData.d.ts
|
|
80
80
|
type TemplateOptions = {
|
|
@@ -313,10 +313,26 @@ interface SchemaNode extends SchemaNodeMethodsType {
|
|
|
313
313
|
* Fixed SchemaNode mixin methods
|
|
314
314
|
*/
|
|
315
315
|
interface SchemaNodeMethodsType {
|
|
316
|
-
compileSchema(schema: JsonSchema, evaluationPath?: string, schemaLocation?: string, dynamicId?: string): SchemaNode;
|
|
316
|
+
compileSchema(schema: JsonSchema | BooleanSchema, evaluationPath?: string, schemaLocation?: string, dynamicId?: string): SchemaNode;
|
|
317
317
|
createError<T extends string = DefaultErrors>(code: T, data: AnnotationData, message?: string): JsonError;
|
|
318
318
|
createAnnotation<T extends string = DefaultErrors>(code: T, data: AnnotationData, message?: string): JsonAnnotation;
|
|
319
319
|
createSchema(data?: unknown): JsonSchema;
|
|
320
|
+
/**
|
|
321
|
+
* Returns a node matching the given location (pointer) in data
|
|
322
|
+
*
|
|
323
|
+
* - the returned node will have a **reduced schema** based on given input data
|
|
324
|
+
* - return returned node $ref is resolved
|
|
325
|
+
*
|
|
326
|
+
* To resolve dynamic schema where the type of JSON Schema is evaluated by
|
|
327
|
+
* its value, a data object has to be passed in options.
|
|
328
|
+
*
|
|
329
|
+
* Per default this function will return `undefined` schema for valid properties
|
|
330
|
+
* that do not have a defined schema. Use the option `withSchemaWarning: true` to
|
|
331
|
+
* receive an error with `code: schema-warning` containing the location of its
|
|
332
|
+
* last evaluated json-schema.
|
|
333
|
+
*
|
|
334
|
+
* @returns { node } or { error } where node can also be undefined (valid but undefined)
|
|
335
|
+
*/
|
|
320
336
|
getNode(pointer: string, data: unknown, options: {
|
|
321
337
|
withSchemaWarning: true;
|
|
322
338
|
} & GetNodeOptions): NodeOrError;
|
|
@@ -324,6 +340,14 @@ interface SchemaNodeMethodsType {
|
|
|
324
340
|
createSchema: true;
|
|
325
341
|
} & GetNodeOptions): NodeOrError;
|
|
326
342
|
getNode(pointer: string, data?: unknown, options?: GetNodeOptions): OptionalNodeOrError;
|
|
343
|
+
/**
|
|
344
|
+
* Returns the child for the given property-name or array-index
|
|
345
|
+
*
|
|
346
|
+
* - the returned child node is **not reduced**
|
|
347
|
+
* - a child node $ref is resolved
|
|
348
|
+
*
|
|
349
|
+
* @returns { node } or { error } where node can also be undefined (valid but undefined)
|
|
350
|
+
*/
|
|
327
351
|
getNodeChild(key: string | number, data: unknown, options: {
|
|
328
352
|
withSchemaWarning: true;
|
|
329
353
|
} & GetNodeOptions): NodeOrError;
|
|
@@ -346,7 +370,7 @@ interface SchemaNodeMethodsType {
|
|
|
346
370
|
path?: ValidationPath;
|
|
347
371
|
}) => SchemaNode;
|
|
348
372
|
validate(data: unknown, pointer?: string, path?: ValidationPath): ValidateReturnType;
|
|
349
|
-
addRemoteSchema(url: string, schema: JsonSchema): SchemaNode;
|
|
373
|
+
addRemoteSchema(url: string, schema: JsonSchema | BooleanSchema): SchemaNode;
|
|
350
374
|
toSchemaNodes(): SchemaNode[];
|
|
351
375
|
toDataNodes(data: unknown, pointer?: string): DataNode[];
|
|
352
376
|
toJSON(): unknown;
|
|
@@ -388,9 +412,12 @@ type ValidateReturnType = {
|
|
|
388
412
|
};
|
|
389
413
|
//#endregion
|
|
390
414
|
//#region src/types.d.ts
|
|
415
|
+
type BooleanSchema = boolean;
|
|
391
416
|
interface JsonSchema {
|
|
392
417
|
[keyword: string]: any;
|
|
393
418
|
}
|
|
419
|
+
declare function isJsonSchema(value: unknown): value is JsonSchema;
|
|
420
|
+
declare function isBooleanSchema(value: unknown): value is BooleanSchema;
|
|
394
421
|
type JsonPointer = string;
|
|
395
422
|
type AnnotationData<D extends Record<string, unknown> = Record<string, unknown>> = D & {
|
|
396
423
|
pointer: string;
|
|
@@ -446,7 +473,7 @@ type CompileOptions = {
|
|
|
446
473
|
* wrapping each schema with utilities and as much preevaluation as possible. Each
|
|
447
474
|
* node will be reused for each task, but will create a compiledNode for bound data.
|
|
448
475
|
*/
|
|
449
|
-
declare function compileSchema(schema: JsonSchema, options?: CompileOptions): SchemaNode;
|
|
476
|
+
declare function compileSchema(schema: JsonSchema | BooleanSchema, options?: CompileOptions): SchemaNode;
|
|
450
477
|
//#endregion
|
|
451
478
|
//#region src/settings.d.ts
|
|
452
479
|
declare const _default: {
|
|
@@ -564,9 +591,9 @@ declare const draft2020: Draft;
|
|
|
564
591
|
//#endregion
|
|
565
592
|
//#region src/draftEditor.d.ts
|
|
566
593
|
/**
|
|
567
|
-
* @draft-editor https://json-schema.org/draft/
|
|
594
|
+
* @draft-editor https://json-schema.org/draft/2020-12/release-notes
|
|
568
595
|
*
|
|
569
|
-
* Uses Draft
|
|
596
|
+
* Uses Draft 2020-12 and changes resolveOneOf to be fuzzy
|
|
570
597
|
*/
|
|
571
598
|
declare const draftEditor: Draft;
|
|
572
599
|
//#endregion
|
|
@@ -607,4 +634,4 @@ declare function sanitizeErrors(list: ValidationReturnType | ValidationReturnTyp
|
|
|
607
634
|
/** remote meta-schema stored by schema $id */
|
|
608
635
|
declare const remotes: Record<string, any>;
|
|
609
636
|
//#endregion
|
|
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 };
|
|
637
|
+
export { type Annotation, type AnnotationData, type BooleanSchema, 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, isBooleanSchema, isJsonAnnotation, isJsonError, isJsonSchema, isReduceable, isSchemaNode, mergeNode, mergeSchema, oneOfFuzzyKeyword, oneOfKeyword, remotes, render, sanitizeErrors, _default as settings };
|