@hyperjump/json-schema 1.12.0 → 1.13.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/README.md +1 -1
- package/annotations/annotated-instance.d.ts +1 -1
- package/annotations/annotated-instance.js +3 -32
- package/draft-04/additionalItems.js +3 -1
- package/draft-04/dependencies.js +3 -1
- package/draft-04/items.js +3 -1
- package/draft-06/index.d.ts +4 -2
- package/draft-2019-09/index.d.ts +2 -1
- package/draft-2020-12/dynamicRef.js +3 -1
- package/draft-2020-12/index.d.ts +2 -1
- package/lib/experimental.d.ts +3 -2
- package/lib/keywords/contentEncoding.js +9 -1
- package/lib/keywords/contentMediaType.js +9 -1
- package/lib/keywords/contentSchema.js +17 -2
- package/lib/keywords/validation.js +7 -4
- package/package.json +1 -1
- package/stable/index.d.ts +2 -0
package/README.md
CHANGED
|
@@ -800,7 +800,7 @@ following functions are available in addition to the functions available in the
|
|
|
800
800
|
* **annotation**: (instance: JsonNode, keyword: string, dialect?: string): any[];
|
|
801
801
|
|
|
802
802
|
Get the annotations for a keyword for the value represented by the JsonNode.
|
|
803
|
-
* **annotatedWith**: (instance: JsonNode, keyword: string, dialect?: string): JsonNode
|
|
803
|
+
* **annotatedWith**: (instance: JsonNode, keyword: string, dialect?: string): Generator<JsonNode>;
|
|
804
804
|
|
|
805
805
|
Get all JsonNodes that are annotated with the given keyword.
|
|
806
806
|
* **setAnnotation**: (instance: JsonNode, keywordId: string, value: any) => JsonNode
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export const annotation: <A>(instance: JsonNode, keyword: string, dialectUri?: string) => A[];
|
|
2
|
-
export const annotatedWith: <A extends JsonNode>(instance: A, keyword: string, dialectUri?: string) => A
|
|
2
|
+
export const annotatedWith: <A extends JsonNode>(instance: A, keyword: string, dialectUri?: string) => Generator<A>;
|
|
3
3
|
|
|
4
4
|
export * from "../lib/instance.js";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as JsonPointer from "@hyperjump/json-pointer";
|
|
2
1
|
import * as Instance from "../lib/instance.js";
|
|
3
2
|
import { getKeywordId } from "../lib/keywords.js";
|
|
4
3
|
|
|
@@ -7,43 +6,15 @@ const defaultDialectId = "https://json-schema.org/validation";
|
|
|
7
6
|
|
|
8
7
|
export const annotation = (node, keyword, dialect = defaultDialectId) => {
|
|
9
8
|
const keywordUri = getKeywordId(keyword, dialect);
|
|
10
|
-
|
|
11
|
-
let currentNode = node.root;
|
|
12
|
-
const errors = [...invalidSchemas(currentNode)];
|
|
13
|
-
for (let segment of JsonPointer.pointerSegments(node.pointer)) {
|
|
14
|
-
segment = segment === "-" && Instance.typeOf(currentNode) === "array" ? Instance.length(currentNode) : segment;
|
|
15
|
-
currentNode = Instance.step(segment, currentNode);
|
|
16
|
-
errors.push(...invalidSchemas(currentNode));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const annotations = [];
|
|
20
|
-
for (const schemaLocation in node.annotations[keywordUri]) {
|
|
21
|
-
if (!errors.some((error) => schemaLocation.startsWith(error))) {
|
|
22
|
-
annotations.unshift(node.annotations[keywordUri][schemaLocation]);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return annotations;
|
|
9
|
+
return node.annotations[keywordUri] ?? [];
|
|
27
10
|
};
|
|
28
11
|
|
|
29
|
-
const
|
|
30
|
-
for (const error in node.errors) {
|
|
31
|
-
if (node.errors[error] === "https://json-schema.org/evaluation/validate") {
|
|
32
|
-
yield error;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export const annotatedWith = (instance, keyword, dialectId = defaultDialectId) => {
|
|
38
|
-
const nodes = [];
|
|
39
|
-
|
|
12
|
+
export const annotatedWith = function* (instance, keyword, dialectId = defaultDialectId) {
|
|
40
13
|
for (const node of Instance.allNodes(instance)) {
|
|
41
14
|
if (annotation(node, keyword, dialectId).length > 0) {
|
|
42
|
-
|
|
15
|
+
yield node;
|
|
43
16
|
}
|
|
44
17
|
}
|
|
45
|
-
|
|
46
|
-
return nodes;
|
|
47
18
|
};
|
|
48
19
|
|
|
49
20
|
export * from "../lib/instance.js";
|
|
@@ -26,6 +26,8 @@ const interpret = ([numberOfItems, additionalItems], instance, context) => {
|
|
|
26
26
|
);
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
+
const simpleApplicator = true;
|
|
30
|
+
|
|
29
31
|
const collectEvaluatedItems = (keywordValue, instance, context) => {
|
|
30
32
|
if (!interpret(keywordValue, instance, context)) {
|
|
31
33
|
return false;
|
|
@@ -39,4 +41,4 @@ const collectEvaluatedItems = (keywordValue, instance, context) => {
|
|
|
39
41
|
return evaluatedIndexes;
|
|
40
42
|
};
|
|
41
43
|
|
|
42
|
-
export default { id, compile, interpret, collectEvaluatedItems };
|
|
44
|
+
export default { id, compile, interpret, simpleApplicator, collectEvaluatedItems };
|
package/draft-04/dependencies.js
CHANGED
package/draft-04/items.js
CHANGED
|
@@ -34,10 +34,12 @@ const interpret = (items, instance, context) => {
|
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
const simpleApplicator = true;
|
|
38
|
+
|
|
37
39
|
const collectEvaluatedItems = (items, instance, context) => {
|
|
38
40
|
return interpret(items, instance, context) && (typeof items === "string"
|
|
39
41
|
? collectSet(range(0, Instance.length(instance)))
|
|
40
42
|
: collectSet(range(0, items.length)));
|
|
41
43
|
};
|
|
42
44
|
|
|
43
|
-
export default { id, compile, interpret, collectEvaluatedItems };
|
|
45
|
+
export default { id, compile, interpret, simpleApplicator, collectEvaluatedItems };
|
package/draft-06/index.d.ts
CHANGED
|
@@ -2,9 +2,10 @@ import type { Json } from "@hyperjump/json-pointer";
|
|
|
2
2
|
import type { JsonSchemaType } from "../lib/common.js";
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
export type
|
|
5
|
+
export type JsonSchemaDraft06Ref = {
|
|
6
6
|
$ref: string;
|
|
7
|
-
}
|
|
7
|
+
};
|
|
8
|
+
export type JsonSchemaDraft06Object = {
|
|
8
9
|
$schema?: "http://json-schema.org/draft-06/schema#";
|
|
9
10
|
$id?: string;
|
|
10
11
|
title?: string;
|
|
@@ -43,5 +44,6 @@ export type JsonSchemaDraft06 = boolean | {
|
|
|
43
44
|
oneOf?: JsonSchemaDraft06[];
|
|
44
45
|
not?: JsonSchemaDraft06;
|
|
45
46
|
};
|
|
47
|
+
export type JsonSchemaDraft06 = boolean | JsonSchemaDraft06Ref | JsonSchemaDraft06Object;
|
|
46
48
|
|
|
47
49
|
export * from "../lib/index.js";
|
package/draft-2019-09/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Json } from "@hyperjump/json-pointer";
|
|
|
2
2
|
import type { JsonSchemaType } from "../lib/common.js";
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
export type
|
|
5
|
+
export type JsonSchemaDraft201909Object = {
|
|
6
6
|
$schema?: "https://json-schema.org/draft/2019-09/schema";
|
|
7
7
|
$id?: string;
|
|
8
8
|
$anchor?: string;
|
|
@@ -61,5 +61,6 @@ export type JsonSchemaDraft201909 = boolean | {
|
|
|
61
61
|
contentEncoding?: string;
|
|
62
62
|
contentSchema?: JsonSchemaDraft201909;
|
|
63
63
|
};
|
|
64
|
+
export type JsonSchemaDraft201909 = boolean | JsonSchemaDraft201909Object;
|
|
64
65
|
|
|
65
66
|
export * from "../lib/index.js";
|
|
@@ -21,8 +21,10 @@ const evaluate = (strategy, [id, fragment, ref], instance, context) => {
|
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
+
const simpleApplicator = true;
|
|
25
|
+
|
|
24
26
|
const interpret = (...args) => evaluate(Validation.interpret, ...args);
|
|
25
27
|
const collectEvaluatedProperties = (...args) => evaluate(Validation.collectEvaluatedProperties, ...args);
|
|
26
28
|
const collectEvaluatedItems = (...args) => evaluate(Validation.collectEvaluatedItems, ...args);
|
|
27
29
|
|
|
28
|
-
export default { id, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
|
|
30
|
+
export default { id, compile, interpret, simpleApplicator, collectEvaluatedProperties, collectEvaluatedItems };
|
package/draft-2020-12/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Json } from "@hyperjump/json-pointer";
|
|
|
2
2
|
import type { JsonSchemaType } from "../lib/common.js";
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
export type
|
|
5
|
+
export type JsonSchemaDraft202012Object = {
|
|
6
6
|
$schema?: "https://json-schema.org/draft/2020-12/schema";
|
|
7
7
|
$id?: string;
|
|
8
8
|
$anchor?: string;
|
|
@@ -62,5 +62,6 @@ export type JsonSchemaDraft202012 = boolean | {
|
|
|
62
62
|
contentEncoding?: string;
|
|
63
63
|
contentSchema?: JsonSchemaDraft202012;
|
|
64
64
|
};
|
|
65
|
+
export type JsonSchemaDraft202012 = boolean | JsonSchemaDraft202012Object;
|
|
65
66
|
|
|
66
67
|
export * from "../lib/index.js";
|
package/lib/experimental.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export type CompiledSchema = {
|
|
|
18
18
|
|
|
19
19
|
type AST = {
|
|
20
20
|
metaData: Record<string, MetaData>;
|
|
21
|
-
} & Record<string, Node<
|
|
21
|
+
} & Record<string, Node<unknown>[] | boolean>;
|
|
22
22
|
|
|
23
23
|
type Node<A> = [keywordId: string, schemaUri: string, keywordValue: A];
|
|
24
24
|
|
|
@@ -73,7 +73,7 @@ export type Keyword<A> = {
|
|
|
73
73
|
collectEvaluatedProperties?: (compiledKeywordValue: A, instance: JsonNode, context: ValidationContext, isTop?: boolean) => Set<string> | false;
|
|
74
74
|
collectEvaluatedItems?: (compiledKeywordValue: A, instance: JsonNode, context: ValidationContext, isTop?: boolean) => Set<number> | false;
|
|
75
75
|
collectExternalIds?: (visited: Set<string>, parentSchema: Browser<SchemaDocument>, schema: Browser<SchemaDocument>) => Promise<Set<string>>;
|
|
76
|
-
annotation?: <B>(compiledKeywordValue: A) => B;
|
|
76
|
+
annotation?: <B>(compiledKeywordValue: A, instance: JsonNode) => B | undefined;
|
|
77
77
|
};
|
|
78
78
|
|
|
79
79
|
export type ValidationContext = {
|
|
@@ -81,6 +81,7 @@ export type ValidationContext = {
|
|
|
81
81
|
dynamicAnchors: Anchors;
|
|
82
82
|
errors: OutputUnit[];
|
|
83
83
|
annotations: OutputUnit[];
|
|
84
|
+
outputFormat: OutputFormat;
|
|
84
85
|
};
|
|
85
86
|
|
|
86
87
|
export const Validation: Keyword<string>;
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import * as Browser from "@hyperjump/browser";
|
|
2
|
+
import * as Instance from "../instance.js";
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
const id = "https://json-schema.org/keyword/contentEncoding";
|
|
5
6
|
|
|
6
7
|
const compile = (schema) => Browser.value(schema);
|
|
7
8
|
const interpret = () => true;
|
|
8
|
-
|
|
9
|
+
|
|
10
|
+
const annotation = (contentEncoding, instance) => {
|
|
11
|
+
if (Instance.typeOf(instance) !== "string") {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return contentEncoding;
|
|
16
|
+
};
|
|
9
17
|
|
|
10
18
|
export default { id, compile, interpret, annotation };
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import * as Browser from "@hyperjump/browser";
|
|
2
|
+
import * as Instance from "../instance.js";
|
|
2
3
|
|
|
3
4
|
|
|
4
5
|
const id = "https://json-schema.org/keyword/contentMediaType";
|
|
5
6
|
|
|
6
7
|
const compile = (schema) => Browser.value(schema);
|
|
7
8
|
const interpret = () => true;
|
|
8
|
-
|
|
9
|
+
|
|
10
|
+
const annotation = (contentMediaType, instance) => {
|
|
11
|
+
if (Instance.typeOf(instance) !== "string") {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return contentMediaType;
|
|
16
|
+
};
|
|
9
17
|
|
|
10
18
|
export default { id, compile, interpret, annotation };
|
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
import { canonicalUri } from "../schema.js";
|
|
2
|
+
import * as Browser from "@hyperjump/browser";
|
|
3
|
+
import * as Instance from "../instance.js";
|
|
4
|
+
import { getKeywordName } from "../keywords.js";
|
|
2
5
|
|
|
3
6
|
|
|
4
7
|
const id = "https://json-schema.org/keyword/contentSchema";
|
|
5
8
|
|
|
6
|
-
const compile = (contentSchema) =>
|
|
9
|
+
const compile = async (contentSchema, _ast, parentSchema) => {
|
|
10
|
+
const contentMediaTypeKeyword = getKeywordName(contentSchema.document.dialectId, "https://json-schema.org/keyword/contentMediaType");
|
|
11
|
+
const contentMediaType = await Browser.step(contentMediaTypeKeyword, parentSchema);
|
|
12
|
+
return Browser.value(contentMediaType) && canonicalUri(contentSchema);
|
|
13
|
+
};
|
|
14
|
+
|
|
7
15
|
const interpret = () => true;
|
|
8
|
-
|
|
16
|
+
|
|
17
|
+
const annotation = (contentSchema, instance) => {
|
|
18
|
+
if (Instance.typeOf(instance) !== "string") {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return contentSchema;
|
|
23
|
+
};
|
|
9
24
|
|
|
10
25
|
export default { id, compile, interpret, annotation };
|
|
@@ -85,15 +85,18 @@ const interpret = (url, instance, { ast, dynamicAnchors, errors, annotations, ou
|
|
|
85
85
|
}
|
|
86
86
|
errors.push(...context.errors);
|
|
87
87
|
} else {
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
const annotation = keywordHandler.annotation?.(keywordValue, instance);
|
|
89
|
+
if (annotation !== undefined) {
|
|
90
|
+
schemaAnnotations.unshift({
|
|
90
91
|
keyword: keywordId,
|
|
91
92
|
absoluteKeywordLocation: schemaUri,
|
|
92
93
|
instanceLocation: Instance.uri(instance),
|
|
93
|
-
annotation:
|
|
94
|
+
annotation: annotation
|
|
94
95
|
});
|
|
95
96
|
}
|
|
96
|
-
|
|
97
|
+
for (const contextAnnotation of context.annotations) {
|
|
98
|
+
schemaAnnotations.unshift(contextAnnotation);
|
|
99
|
+
}
|
|
97
100
|
}
|
|
98
101
|
break;
|
|
99
102
|
case DETAILED: {
|
package/package.json
CHANGED
package/stable/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import type { Json } from "@hyperjump/json-pointer";
|
|
|
2
2
|
import type { JsonSchemaType } from "../lib/common.js";
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
export type JsonSchemaType = JsonSchemaType;
|
|
6
|
+
|
|
5
7
|
export type JsonSchema = boolean | {
|
|
6
8
|
$schema?: "https://json-schema.org/validation";
|
|
7
9
|
$id?: string;
|