@hyperjump/json-schema 1.9.3 → 1.9.5

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022 Jason Desrosiers
3
+ Copyright (c) 2022 Hyperjump Software, LLC
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -16,11 +16,11 @@ export const annotation = (node, keyword, dialect = defaultDialectId) => {
16
16
  const keywordUri = getKeywordId(keyword, dialect);
17
17
 
18
18
  let currentNode = node.root;
19
- const errors = Object.keys(node.root.errors);
19
+ const errors = [...invalidSchemas(currentNode)];
20
20
  for (let segment of JsonPointer.pointerSegments(node.pointer)) {
21
21
  segment = segment === "-" && Instance.typeOf(currentNode) === "array" ? Instance.length(currentNode) : segment;
22
22
  currentNode = Instance.step(segment, currentNode);
23
- errors.push(...Object.keys(currentNode.errors));
23
+ errors.push(...invalidSchemas(currentNode));
24
24
  }
25
25
 
26
26
  const annotations = [];
@@ -33,6 +33,14 @@ export const annotation = (node, keyword, dialect = defaultDialectId) => {
33
33
  return annotations;
34
34
  };
35
35
 
36
+ const invalidSchemas = function* (node) {
37
+ for (const error in node.errors) {
38
+ if (node.errors[error] === "https://json-schema.org/evaluation/validate") {
39
+ yield error;
40
+ }
41
+ }
42
+ };
43
+
36
44
  export const annotatedWith = (instance, keyword, dialectId = defaultDialectId) => {
37
45
  const nodes = [];
38
46
 
package/lib/instance.d.ts CHANGED
@@ -23,14 +23,14 @@ export const values: (node: JsonNode) => Generator<JsonNode>;
23
23
  export const entries: (node: JsonNode) => Generator<[JsonNode, JsonNode]>;
24
24
  export const length: (node: JsonNode) => number;
25
25
 
26
- export const allNodes: (node) => Generator<JsonNode>;
26
+ export const allNodes: (node: JsonNode) => Generator<JsonNode>;
27
27
 
28
28
  export type JsonNode = {
29
29
  baseUri: string;
30
30
  pointer: string;
31
31
  type: JsonNodeType;
32
32
  children: JsonNode[];
33
- parent: JsonNode;
33
+ parent?: JsonNode;
34
34
  root: JsonNode;
35
35
  valid: boolean;
36
36
  errors: Record<string, string>;
package/lib/instance.js CHANGED
@@ -118,7 +118,9 @@ export const values = function* (node) {
118
118
  }
119
119
 
120
120
  for (const property of node.children) {
121
- yield property.children[1];
121
+ if (property.children[1]) {
122
+ yield property.children[1];
123
+ }
122
124
  }
123
125
  };
124
126
 
@@ -128,7 +130,9 @@ export const entries = function* (node) {
128
130
  }
129
131
 
130
132
  for (const property of node.children) {
131
- yield property.children;
133
+ if (property.children.length === 2) {
134
+ yield property.children;
135
+ }
132
136
  }
133
137
  };
134
138
 
@@ -5,8 +5,8 @@ const id = "https://json-schema.org/keyword/if";
5
5
 
6
6
  const compile = (schema, ast) => Validation.compile(schema, ast);
7
7
 
8
- const interpret = (ifSchema, instance, ast, dynamicAnchors, quiet) => {
9
- Validation.interpret(ifSchema, instance, ast, dynamicAnchors, quiet);
8
+ const interpret = (ifSchema, instance, ast, dynamicAnchors) => {
9
+ Validation.interpret(ifSchema, instance, ast, dynamicAnchors, true);
10
10
  return true;
11
11
  };
12
12
 
@@ -1,13 +1,18 @@
1
1
  import * as Browser from "@hyperjump/browser";
2
2
  import * as Instance from "../../annotations/annotated-instance.js";
3
+ import { pointerSegments } from "@hyperjump/json-pointer";
3
4
 
4
5
 
5
6
  const id = "https://json-schema.org/keyword/unknown";
6
7
 
7
- const compile = (schema) => Browser.value(schema);
8
+ const compile = (schema) => {
9
+ const keywordName = [...pointerSegments(schema.cursor)].pop();
10
+ return [keywordName, Browser.value(schema)];
11
+ };
8
12
 
9
- const interpret = (value, instance, _ast, _dynamicAnchors, _quiet, schemaLocation) => {
10
- Instance.setAnnotation(instance, id, schemaLocation, value);
13
+ const interpret = ([keywordName, value], instance, _ast, _dynamicAnchors, _quiet, schemaLocation) => {
14
+ const keywordId = `${id}#${keywordName}`;
15
+ Instance.setAnnotation(instance, keywordId, schemaLocation, value);
11
16
  return true;
12
17
  };
13
18
 
@@ -62,9 +62,7 @@ const interpret = (url, instance, ast, dynamicAnchors, quiet = false) => {
62
62
  }
63
63
 
64
64
  if (!isSchemaValid) {
65
- if (!quiet) {
66
- instance.errors[url] = id;
67
- }
65
+ instance.errors[url] = id;
68
66
  }
69
67
 
70
68
  instance.valid = isSchemaValid;
package/lib/output.js CHANGED
@@ -25,7 +25,7 @@ outputFormats.BASIC = (instance) => {
25
25
 
26
26
  for (const child of Instance.allNodes(instance)) {
27
27
  for (const [absoluteKeywordLocation, keyword] of Object.entries(child.errors).reverse()) {
28
- if (!child.valid) {
28
+ if (keyword !== "https://json-schema.org/evaluation/validate" && !child.valid) {
29
29
  output.errors.unshift({
30
30
  keyword,
31
31
  absoluteKeywordLocation,
@@ -35,8 +35,6 @@ outputFormats.BASIC = (instance) => {
35
35
  }
36
36
  }
37
37
  }
38
-
39
- output.errors.pop();
40
38
  }
41
39
 
42
40
  return output;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperjump/json-schema",
3
- "version": "1.9.3",
3
+ "version": "1.9.5",
4
4
  "description": "A JSON Schema validator with support for custom keywords, vocabularies, and dialects",
5
5
  "type": "module",
6
6
  "main": "./stable/index.js",