@hyperjump/json-schema 1.9.0 → 1.9.2
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 +4 -0
- package/annotations/annotated-instance.js +1 -1
- package/lib/instance.d.ts +10 -0
- package/lib/instance.js +1 -1
- package/lib/output.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -631,6 +631,10 @@ working with generators and async generators.
|
|
|
631
631
|
* **fromJs**: (value: any, uri?: string) => JsonNode
|
|
632
632
|
|
|
633
633
|
Construct a JsonNode from a JavaScript value.
|
|
634
|
+
* **cons**: (baseUri: string, pointer: string, value: any, type: string, children: JsonNode[], parent?: JsonNode) => JsonNode
|
|
635
|
+
|
|
636
|
+
Construct a JsonNode. This is used internally. You probably want `fromJs`
|
|
637
|
+
instead.
|
|
634
638
|
* **get**: (url: string, instance: JsonNode) => JsonNode
|
|
635
639
|
|
|
636
640
|
Apply a same-resource reference to a JsonNode.
|
|
@@ -18,7 +18,7 @@ export const annotation = (node, keyword, dialect = defaultDialectId) => {
|
|
|
18
18
|
let currentNode = node.root;
|
|
19
19
|
const errors = Object.keys(node.root.errors);
|
|
20
20
|
for (let segment of JsonPointer.pointerSegments(node.pointer)) {
|
|
21
|
-
segment = segment === "-" &&
|
|
21
|
+
segment = segment === "-" && Instance.typeOf(currentNode) === "array" ? Instance.length(currentNode) : segment;
|
|
22
22
|
currentNode = Instance.step(segment, currentNode);
|
|
23
23
|
errors.push(...Object.keys(currentNode.errors));
|
|
24
24
|
}
|
package/lib/instance.d.ts
CHANGED
|
@@ -3,6 +3,14 @@ import type { Json } from "@hyperjump/json-pointer";
|
|
|
3
3
|
|
|
4
4
|
export const fromJs: (value: Json, uri?: string) => JsonNode;
|
|
5
5
|
|
|
6
|
+
export const cons: (
|
|
7
|
+
baseUri: string,
|
|
8
|
+
pointer: string,
|
|
9
|
+
value: Json,
|
|
10
|
+
type: JsonNodeType,
|
|
11
|
+
children: JsonNode[],
|
|
12
|
+
parent?: JsonNode
|
|
13
|
+
) => JsonNode;
|
|
6
14
|
export const get: (url: string, context: JsonNode) => JsonNode | undefined;
|
|
7
15
|
export const uri: (node: JsonNode) => string;
|
|
8
16
|
export const value: <A>(node: JsonNode) => A;
|
|
@@ -25,6 +33,8 @@ export type JsonNode = {
|
|
|
25
33
|
parent: JsonNode;
|
|
26
34
|
root: JsonNode;
|
|
27
35
|
valid: boolean;
|
|
36
|
+
errors: Record<string, string>;
|
|
37
|
+
annotations: Record<string, Record<string, unknown>>;
|
|
28
38
|
};
|
|
29
39
|
|
|
30
40
|
type JsonNodeType = "object" | "array" | "string" | "number" | "boolean" | "null" | "property";
|
package/lib/instance.js
CHANGED
|
@@ -40,7 +40,7 @@ export const fromJs = (value, uri = "", pointer = "", parent = undefined) => {
|
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
const cons = (baseUri, pointer, value, type, children, parent) => {
|
|
43
|
+
export const cons = (baseUri, pointer, value, type, children, parent) => {
|
|
44
44
|
const node = {
|
|
45
45
|
baseUri: baseUri ? toAbsoluteIri(baseUri) : "",
|
|
46
46
|
pointer: pointer,
|
package/lib/output.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as Instance from "./instance.js";
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
const outputFormats = {};
|
|
@@ -23,13 +23,13 @@ outputFormats.BASIC = (instance) => {
|
|
|
23
23
|
if (!instance.valid) {
|
|
24
24
|
output.errors = [];
|
|
25
25
|
|
|
26
|
-
for (const child of allNodes(instance)) {
|
|
26
|
+
for (const child of Instance.allNodes(instance)) {
|
|
27
27
|
for (const [absoluteKeywordLocation, keyword] of Object.entries(child.errors).reverse()) {
|
|
28
28
|
if (!child.valid) {
|
|
29
29
|
output.errors.unshift({
|
|
30
30
|
keyword,
|
|
31
31
|
absoluteKeywordLocation,
|
|
32
|
-
instanceLocation:
|
|
32
|
+
instanceLocation: Instance.uri(child),
|
|
33
33
|
valid: child.valid
|
|
34
34
|
});
|
|
35
35
|
}
|