@hyperjump/json-schema 1.11.0 → 1.12.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.
Files changed (56) hide show
  1. package/README.md +24 -7
  2. package/annotations/annotated-instance.d.ts +0 -1
  3. package/annotations/annotated-instance.js +0 -7
  4. package/annotations/index.js +19 -3
  5. package/draft-04/additionalItems.js +4 -4
  6. package/draft-04/dependencies.js +2 -2
  7. package/draft-04/items.js +5 -5
  8. package/draft-06/contains.js +3 -2
  9. package/draft-2020-12/dynamicRef.js +5 -5
  10. package/lib/core.js +5 -4
  11. package/lib/experimental.d.ts +12 -3
  12. package/lib/experimental.js +1 -1
  13. package/lib/index.d.ts +2 -1
  14. package/lib/instance.d.ts +0 -2
  15. package/lib/instance.js +0 -2
  16. package/lib/keywords/additionalProperties.js +7 -5
  17. package/lib/keywords/allOf.js +7 -5
  18. package/lib/keywords/anyOf.js +4 -4
  19. package/lib/keywords/conditional.js +9 -9
  20. package/lib/keywords/contains.js +5 -5
  21. package/lib/keywords/contentEncoding.js +3 -7
  22. package/lib/keywords/contentMediaType.js +3 -7
  23. package/lib/keywords/contentSchema.js +3 -7
  24. package/lib/keywords/default.js +3 -7
  25. package/lib/keywords/dependentSchemas.js +7 -5
  26. package/lib/keywords/deprecated.js +3 -7
  27. package/lib/keywords/description.js +3 -7
  28. package/lib/keywords/dynamicRef.js +6 -4
  29. package/lib/keywords/else.js +13 -10
  30. package/lib/keywords/examples.js +3 -7
  31. package/lib/keywords/format.js +3 -7
  32. package/lib/keywords/if.js +6 -6
  33. package/lib/keywords/itemPattern.js +7 -7
  34. package/lib/keywords/items.js +7 -5
  35. package/lib/keywords/oneOf.js +6 -6
  36. package/lib/keywords/patternProperties.js +7 -5
  37. package/lib/keywords/prefixItems.js +7 -5
  38. package/lib/keywords/properties.js +7 -5
  39. package/lib/keywords/propertyDependencies.js +7 -5
  40. package/lib/keywords/propertyNames.js +5 -3
  41. package/lib/keywords/readOnly.js +3 -7
  42. package/lib/keywords/ref.js +3 -1
  43. package/lib/keywords/then.js +14 -12
  44. package/lib/keywords/title.js +3 -7
  45. package/lib/keywords/unevaluatedItems.js +11 -8
  46. package/lib/keywords/unevaluatedProperties.js +11 -7
  47. package/lib/keywords/unknown.js +3 -7
  48. package/lib/keywords/validation.js +83 -28
  49. package/lib/keywords/writeOnly.js +3 -7
  50. package/openapi-3-0/discriminator.js +3 -7
  51. package/openapi-3-0/example.js +3 -7
  52. package/openapi-3-0/externalDocs.js +3 -7
  53. package/openapi-3-0/index.d.ts +1 -1
  54. package/openapi-3-0/xml.js +3 -7
  55. package/package.json +1 -1
  56. package/lib/output.js +0 -41
@@ -1,14 +1,10 @@
1
1
  import * as Browser from "@hyperjump/browser";
2
- import * as Instance from "../../annotations/annotated-instance.js";
3
2
 
4
3
 
5
4
  const id = "https://json-schema.org/keyword/deprecated";
6
5
 
7
6
  const compile = (schema) => Browser.value(schema);
7
+ const interpret = () => true;
8
+ const annotation = (deprecated) => deprecated;
8
9
 
9
- const interpret = (deprecated, instance, _ast, _dynamicAnchors, _quiet, schemaLocation) => {
10
- Instance.setAnnotation(instance, id, schemaLocation, deprecated);
11
- return true;
12
- };
13
-
14
- export default { id, compile, interpret };
10
+ export default { id, compile, interpret, annotation };
@@ -1,14 +1,10 @@
1
1
  import * as Browser from "@hyperjump/browser";
2
- import * as Instance from "../../annotations/annotated-instance.js";
3
2
 
4
3
 
5
4
  const id = "https://json-schema.org/keyword/description";
6
5
 
7
6
  const compile = (schema) => Browser.value(schema);
7
+ const interpret = () => true;
8
+ const annotation = (description) => description;
8
9
 
9
- const interpret = (description, instance, _ast, _dynamicAnchors, _quiet, schemaLocation) => {
10
- Instance.setAnnotation(instance, id, schemaLocation, description);
11
- return true;
12
- };
13
-
14
- export default { id, compile, interpret };
10
+ export default { id, compile, interpret, annotation };
@@ -12,15 +12,17 @@ const compile = async (schema, ast) => {
12
12
  return reference;
13
13
  };
14
14
 
15
- const evaluate = (strategy, fragment, instance, ast, dynamicAnchors, quiet) => {
16
- if (!(fragment in dynamicAnchors)) {
15
+ const evaluate = (strategy, fragment, instance, context) => {
16
+ if (!(fragment in context.dynamicAnchors)) {
17
17
  throw Error(`No dynamic anchor found for "${fragment}"`);
18
18
  }
19
- return strategy(dynamicAnchors[fragment], instance, ast, dynamicAnchors, quiet);
19
+ return strategy(context.dynamicAnchors[fragment], instance, context);
20
20
  };
21
21
 
22
+ const simpleApplicator = true;
23
+
22
24
  const interpret = (...args) => evaluate(Validation.interpret, ...args);
23
25
  const collectEvaluatedProperties = (...args) => evaluate(Validation.collectEvaluatedProperties, ...args);
24
26
  const collectEvaluatedItems = (...args) => evaluate(Validation.collectEvaluatedItems, ...args);
25
27
 
26
- export default { id, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
28
+ export default { id, compile, interpret, simpleApplicator, collectEvaluatedProperties, collectEvaluatedItems };
@@ -1,4 +1,5 @@
1
1
  import * as Browser from "@hyperjump/browser";
2
+ import { FLAG } from "../index.js";
2
3
  import { getKeywordName, Validation } from "../experimental.js";
3
4
 
4
5
 
@@ -14,26 +15,28 @@ const compile = async (schema, ast, parentSchema) => {
14
15
  }
15
16
  };
16
17
 
17
- const interpret = ([ifSchema, elseSchema], instance, ast, dynamicAnchors, quiet) => {
18
+ const interpret = ([ifSchema, elseSchema], instance, context) => {
18
19
  return ifSchema === undefined
19
- || Validation.interpret(ifSchema, instance, ast, dynamicAnchors, true)
20
- || Validation.interpret(elseSchema, instance, ast, dynamicAnchors, quiet);
20
+ || Validation.interpret(ifSchema, instance, { ...context, errors: [], annotations: [], oututFormat: FLAG })
21
+ || Validation.interpret(elseSchema, instance, context);
21
22
  };
22
23
 
23
- const collectEvaluatedProperties = ([ifSchema, elseSchema], instance, ast, dynamicAnchors) => {
24
- if (ifSchema === undefined || Validation.interpret(ifSchema, instance, ast, dynamicAnchors, true)) {
24
+ const simpleApplicator = true;
25
+
26
+ const collectEvaluatedProperties = ([ifSchema, elseSchema], instance, context) => {
27
+ if (ifSchema === undefined || Validation.interpret(ifSchema, instance, context)) {
25
28
  return new Set();
26
29
  }
27
30
 
28
- return Validation.collectEvaluatedProperties(elseSchema, instance, ast, dynamicAnchors);
31
+ return Validation.collectEvaluatedProperties(elseSchema, instance, context);
29
32
  };
30
33
 
31
- const collectEvaluatedItems = ([ifSchema, elseSchema], instance, ast, dynamicAnchors) => {
32
- if (ifSchema === undefined || Validation.interpret(ifSchema, instance, ast, dynamicAnchors, true)) {
34
+ const collectEvaluatedItems = ([ifSchema, elseSchema], instance, context) => {
35
+ if (ifSchema === undefined || Validation.interpret(ifSchema, instance, context)) {
33
36
  return new Set();
34
37
  }
35
38
 
36
- return Validation.collectEvaluatedItems(elseSchema, instance, ast, dynamicAnchors);
39
+ return Validation.collectEvaluatedItems(elseSchema, instance, context);
37
40
  };
38
41
 
39
- export default { id, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
42
+ export default { id, compile, interpret, simpleApplicator, collectEvaluatedProperties, collectEvaluatedItems };
@@ -1,14 +1,10 @@
1
1
  import * as Browser from "@hyperjump/browser";
2
- import * as Instance from "../../annotations/annotated-instance.js";
3
2
 
4
3
 
5
4
  const id = "https://json-schema.org/keyword/examples";
6
5
 
7
6
  const compile = (schema) => Browser.value(schema);
7
+ const interpret = () => true;
8
+ const annotation = (examples) => examples;
8
9
 
9
- const interpret = (examples, instance, _ast, _dynamicAnchors, _quiet, schemaLocation) => {
10
- Instance.setAnnotation(instance, id, schemaLocation, examples);
11
- return true;
12
- };
13
-
14
- export default { id, compile, interpret };
10
+ export default { id, compile, interpret, annotation };
@@ -1,14 +1,10 @@
1
1
  import * as Browser from "@hyperjump/browser";
2
- import * as Instance from "../../annotations/annotated-instance.js";
3
2
 
4
3
 
5
4
  const id = "https://json-schema.org/keyword/format";
6
5
 
7
6
  const compile = (schema) => Browser.value(schema);
7
+ const interpret = () => true;
8
+ const annotation = (format) => format;
8
9
 
9
- const interpret = (format, instance, _ast, _dynamicAnchors, _quiet, schemaLocation) => {
10
- Instance.setAnnotation(instance, id, schemaLocation, format);
11
- return true;
12
- };
13
-
14
- export default { id, compile, interpret };
10
+ export default { id, compile, interpret, annotation };
@@ -5,17 +5,17 @@ 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) => {
9
- Validation.interpret(ifSchema, instance, ast, dynamicAnchors, true);
8
+ const interpret = (ifSchema, instance, context) => {
9
+ Validation.interpret(ifSchema, instance, context);
10
10
  return true;
11
11
  };
12
12
 
13
- const collectEvaluatedProperties = (ifSchema, instance, ast, dynamicAnchors) => {
14
- return Validation.collectEvaluatedProperties(ifSchema, instance, ast, dynamicAnchors) || [];
13
+ const collectEvaluatedProperties = (ifSchema, instance, context) => {
14
+ return Validation.collectEvaluatedProperties(ifSchema, instance, context) || new Set();
15
15
  };
16
16
 
17
- const collectEvaluatedItems = (ifSchema, instance, ast, dynamicAnchors) => {
18
- return Validation.collectEvaluatedItems(ifSchema, instance, ast, dynamicAnchors) || new Set();
17
+ const collectEvaluatedItems = (ifSchema, instance, context) => {
18
+ return Validation.collectEvaluatedItems(ifSchema, instance, context) || new Set();
19
19
  };
20
20
 
21
21
  export default { id, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
@@ -39,7 +39,7 @@ const compile = async (schema, ast) => {
39
39
  .reduce(union);
40
40
  };
41
41
 
42
- const evaluate = (strategy) => (nfa, instance, ast, dynamicAnchors, quiet) => {
42
+ const evaluate = (strategy, nfa, instance, context) => {
43
43
  if (Instance.typeOf(instance) !== "array") {
44
44
  return true;
45
45
  }
@@ -51,7 +51,7 @@ const evaluate = (strategy) => (nfa, instance, ast, dynamicAnchors, quiet) => {
51
51
  const nextStates = [];
52
52
 
53
53
  for (const state of currentStates) {
54
- const nextState = transition(strategy, state.transition, item, ast, dynamicAnchors, quiet);
54
+ const nextState = transition(strategy, state.transition, item, context);
55
55
  if (nextState) {
56
56
  addNextState(nextState, nextStates, []);
57
57
  }
@@ -76,16 +76,16 @@ const addNextState = (state, nextStates, visited) => {
76
76
  }
77
77
  };
78
78
 
79
- const transition = (strategy, transitions, instance, ast, dynamicAnchors, quiet) => {
79
+ const transition = (strategy, transitions, instance, context) => {
80
80
  for (const schema in transitions) {
81
- if (strategy(schema, instance, ast, dynamicAnchors, quiet)) {
81
+ if (strategy(schema, instance, context)) {
82
82
  return transitions[schema];
83
83
  }
84
84
  }
85
85
  };
86
86
 
87
- const interpret = evaluate(Validation.interpret);
88
- const collectEvalatedProperties = evaluate(Validation.collectEvaluatedProperties);
89
- const collectEvalatedItems = evaluate(Validation.collectEvaluatedItems);
87
+ const interpret = (...args) => evaluate(Validation.interpret, ...args);
88
+ const collectEvalatedProperties = (...args) => evaluate(Validation.collectEvaluatedProperties, ...args);
89
+ const collectEvalatedItems = (...args) => evaluate(Validation.collectEvaluatedItems, ...args);
90
90
 
91
91
  export default { id, compile, interpret, collectEvalatedProperties, collectEvalatedItems };
@@ -14,14 +14,14 @@ const compile = async (schema, ast, parentSchema) => {
14
14
  return [numberOfPrefixItems, await Validation.compile(schema, ast)];
15
15
  };
16
16
 
17
- const interpret = ([numberOfPrefixItems, items], instance, ast, dynamicAnchors, quiet) => {
17
+ const interpret = ([numberOfPrefixItems, items], instance, context) => {
18
18
  if (Instance.typeOf(instance) !== "array") {
19
19
  return true;
20
20
  }
21
21
 
22
22
  let isValid = true;
23
23
  for (const item of drop(numberOfPrefixItems, Instance.iter(instance))) {
24
- if (!Validation.interpret(items, item, ast, dynamicAnchors, quiet)) {
24
+ if (!Validation.interpret(items, item, context)) {
25
25
  isValid = false;
26
26
  }
27
27
  }
@@ -29,8 +29,10 @@ const interpret = ([numberOfPrefixItems, items], instance, ast, dynamicAnchors,
29
29
  return isValid;
30
30
  };
31
31
 
32
- const collectEvaluatedItems = (keywordValue, instance, ast, dynamicAnchors) => {
33
- if (!interpret(keywordValue, instance, ast, dynamicAnchors, true)) {
32
+ const simpleApplicator = true;
33
+
34
+ const collectEvaluatedItems = (keywordValue, instance, context) => {
35
+ if (!interpret(keywordValue, instance, context)) {
34
36
  return false;
35
37
  }
36
38
 
@@ -42,4 +44,4 @@ const collectEvaluatedItems = (keywordValue, instance, ast, dynamicAnchors) => {
42
44
  return evaluatedIndexes;
43
45
  };
44
46
 
45
- export default { id, compile, interpret, collectEvaluatedItems };
47
+ export default { id, compile, interpret, simpleApplicator, collectEvaluatedItems };
@@ -11,10 +11,10 @@ const compile = (schema, ast) => pipe(
11
11
  asyncCollectArray
12
12
  );
13
13
 
14
- const interpret = (oneOf, instance, ast, dynamicAnchors, quiet) => {
14
+ const interpret = (oneOf, instance, context) => {
15
15
  let validCount = 0;
16
16
  for (const schemaUrl of oneOf) {
17
- if (Validation.interpret(schemaUrl, instance, ast, dynamicAnchors, quiet)) {
17
+ if (Validation.interpret(schemaUrl, instance, context)) {
18
18
  validCount++;
19
19
  }
20
20
  }
@@ -22,10 +22,10 @@ const interpret = (oneOf, instance, ast, dynamicAnchors, quiet) => {
22
22
  return validCount === 1;
23
23
  };
24
24
 
25
- const collectEvaluatedProperties = (oneOf, instance, ast, dynamicAnchors) => {
25
+ const collectEvaluatedProperties = (oneOf, instance, context) => {
26
26
  let evaluatedProperties = false;
27
27
  for (const schemaUrl of oneOf) {
28
- const propertyNames = Validation.collectEvaluatedProperties(schemaUrl, instance, ast, dynamicAnchors);
28
+ const propertyNames = Validation.collectEvaluatedProperties(schemaUrl, instance, context);
29
29
  if (propertyNames) {
30
30
  if (evaluatedProperties) {
31
31
  return false;
@@ -38,10 +38,10 @@ const collectEvaluatedProperties = (oneOf, instance, ast, dynamicAnchors) => {
38
38
  return evaluatedProperties;
39
39
  };
40
40
 
41
- const collectEvaluatedItems = (oneOf, instance, ast, dynamicAnchors) => {
41
+ const collectEvaluatedItems = (oneOf, instance, context) => {
42
42
  let evaluatedItemIndexes = false;
43
43
  for (const schemaUrl of oneOf) {
44
- const itemIndexes = Validation.collectEvaluatedItems(schemaUrl, instance, ast, dynamicAnchors);
44
+ const itemIndexes = Validation.collectEvaluatedItems(schemaUrl, instance, context);
45
45
  if (itemIndexes) {
46
46
  if (evaluatedItemIndexes) {
47
47
  return false;
@@ -15,7 +15,7 @@ const compile = (schema, ast) => pipe(
15
15
  asyncCollectArray
16
16
  );
17
17
 
18
- const interpret = (patternProperties, instance, ast, dynamicAnchors, quiet) => {
18
+ const interpret = (patternProperties, instance, context) => {
19
19
  if (Instance.typeOf(instance) !== "object") {
20
20
  return true;
21
21
  }
@@ -24,7 +24,7 @@ const interpret = (patternProperties, instance, ast, dynamicAnchors, quiet) => {
24
24
  for (const [pattern, schemaUri] of patternProperties) {
25
25
  for (const [propertyNameNode, propertyValue] of Instance.entries(instance)) {
26
26
  const propertyName = Instance.value(propertyNameNode);
27
- if (pattern.test(propertyName) && !Validation.interpret(schemaUri, propertyValue, ast, dynamicAnchors, quiet)) {
27
+ if (pattern.test(propertyName) && !Validation.interpret(schemaUri, propertyValue, context)) {
28
28
  isValid = false;
29
29
  }
30
30
  }
@@ -33,7 +33,9 @@ const interpret = (patternProperties, instance, ast, dynamicAnchors, quiet) => {
33
33
  return isValid;
34
34
  };
35
35
 
36
- const collectEvaluatedProperties = (patternProperties, instance, ast, dynamicAnchors) => {
36
+ const simpleApplicator = true;
37
+
38
+ const collectEvaluatedProperties = (patternProperties, instance, context) => {
37
39
  if (Instance.typeOf(instance) !== "object") {
38
40
  return false;
39
41
  }
@@ -43,7 +45,7 @@ const collectEvaluatedProperties = (patternProperties, instance, ast, dynamicAnc
43
45
  for (const [propertyNameNode, property] of Instance.entries(instance)) {
44
46
  const propertyName = Instance.value(propertyNameNode);
45
47
  if (pattern.test(propertyName)) {
46
- if (!Validation.interpret(propertySchema, property, ast, dynamicAnchors, true)) {
48
+ if (!Validation.interpret(propertySchema, property, context)) {
47
49
  return false;
48
50
  }
49
51
 
@@ -55,4 +57,4 @@ const collectEvaluatedProperties = (patternProperties, instance, ast, dynamicAnc
55
57
  return evaluatedPropertyNames;
56
58
  };
57
59
 
58
- export default { id, compile, interpret, collectEvaluatedProperties };
60
+ export default { id, compile, interpret, simpleApplicator, collectEvaluatedProperties };
@@ -12,7 +12,7 @@ const compile = (schema, ast) => pipe(
12
12
  asyncCollectArray
13
13
  );
14
14
 
15
- const interpret = (prefixItems, instance, ast, dynamicAnchors, quiet) => {
15
+ const interpret = (prefixItems, instance, context) => {
16
16
  if (Instance.typeOf(instance) !== "array") {
17
17
  return true;
18
18
  }
@@ -25,7 +25,7 @@ const interpret = (prefixItems, instance, ast, dynamicAnchors, quiet) => {
25
25
  break;
26
26
  }
27
27
 
28
- if (!Validation.interpret(schemaUri, item, ast, dynamicAnchors, quiet)) {
28
+ if (!Validation.interpret(schemaUri, item, context)) {
29
29
  isValid = false;
30
30
  }
31
31
 
@@ -35,8 +35,10 @@ const interpret = (prefixItems, instance, ast, dynamicAnchors, quiet) => {
35
35
  return isValid;
36
36
  };
37
37
 
38
- const collectEvaluatedItems = (items, instance, ast, dynamicAnchors) => {
39
- return interpret(items, instance, ast, dynamicAnchors, true) && new Set(items.map((_item, ndx) => ndx));
38
+ const simpleApplicator = true;
39
+
40
+ const collectEvaluatedItems = (items, instance, context) => {
41
+ return interpret(items, instance, context) && new Set(items.map((_item, ndx) => ndx));
40
42
  };
41
43
 
42
- export default { id, compile, interpret, collectEvaluatedItems };
44
+ export default { id, compile, interpret, simpleApplicator, collectEvaluatedItems };
@@ -12,7 +12,7 @@ const compile = (schema, ast) => pipe(
12
12
  asyncCollectObject
13
13
  );
14
14
 
15
- const interpret = (properties, instance, ast, dynamicAnchors, quiet) => {
15
+ const interpret = (properties, instance, context) => {
16
16
  if (Instance.typeOf(instance) !== "object") {
17
17
  return true;
18
18
  }
@@ -20,7 +20,7 @@ const interpret = (properties, instance, ast, dynamicAnchors, quiet) => {
20
20
  let isValid = true;
21
21
  for (const [propertyNameNode, property] of Instance.entries(instance)) {
22
22
  const propertyName = Instance.value(propertyNameNode);
23
- if (propertyName in properties && !Validation.interpret(properties[propertyName], property, ast, dynamicAnchors, quiet)) {
23
+ if (propertyName in properties && !Validation.interpret(properties[propertyName], property, context)) {
24
24
  isValid = false;
25
25
  }
26
26
  }
@@ -28,7 +28,9 @@ const interpret = (properties, instance, ast, dynamicAnchors, quiet) => {
28
28
  return isValid;
29
29
  };
30
30
 
31
- const collectEvaluatedProperties = (properties, instance, ast, dynamicAnchors) => {
31
+ const simpleApplicator = true;
32
+
33
+ const collectEvaluatedProperties = (properties, instance, context) => {
32
34
  if (Instance.typeOf(instance) !== "object") {
33
35
  return false;
34
36
  }
@@ -37,7 +39,7 @@ const collectEvaluatedProperties = (properties, instance, ast, dynamicAnchors) =
37
39
  for (const [propertyNameNode, property] of Instance.entries(instance)) {
38
40
  const propertyName = Instance.value(propertyNameNode);
39
41
  if (propertyName in properties) {
40
- if (!Validation.interpret(properties[propertyName], property, ast, dynamicAnchors, true)) {
42
+ if (!Validation.interpret(properties[propertyName], property, context)) {
41
43
  return false;
42
44
  }
43
45
 
@@ -48,4 +50,4 @@ const collectEvaluatedProperties = (properties, instance, ast, dynamicAnchors) =
48
50
  return evaluatedPropertyNames;
49
51
  };
50
52
 
51
- export default { id, compile, interpret, collectEvaluatedProperties };
53
+ export default { id, compile, interpret, simpleApplicator, collectEvaluatedProperties };
@@ -20,7 +20,7 @@ const compile = (schema, ast) => {
20
20
  );
21
21
  };
22
22
 
23
- const interpret = (propertyDependencies, instance, ast, dynamicAnchors, quiet) => {
23
+ const interpret = (propertyDependencies, instance, context) => {
24
24
  if (Instance.typeOf(instance) !== "object") {
25
25
  return true;
26
26
  }
@@ -32,7 +32,7 @@ const interpret = (propertyDependencies, instance, ast, dynamicAnchors, quiet) =
32
32
  if (
33
33
  Instance.has(propertyName, instance)
34
34
  && propertyValue in valueMappings
35
- && !Validation.interpret(valueMappings[propertyValue], instance, ast, dynamicAnchors, quiet)
35
+ && !Validation.interpret(valueMappings[propertyValue], instance, context)
36
36
  ) {
37
37
  isValid = false;
38
38
  }
@@ -41,14 +41,16 @@ const interpret = (propertyDependencies, instance, ast, dynamicAnchors, quiet) =
41
41
  return isValid;
42
42
  };
43
43
 
44
- const collectEvaluatedProperties = (propertyDependencies, instance, ast, dynamicAnchors) => {
44
+ const simpleApplicator = true;
45
+
46
+ const collectEvaluatedProperties = (propertyDependencies, instance, context) => {
45
47
  const evaluatedPropertyNames = new Set();
46
48
  for (const propertyName in propertyDependencies) {
47
49
  const propertyValue = Instance.value(instance)[propertyName];
48
50
 
49
51
  const valueMappings = propertyDependencies[propertyName];
50
52
  if (Instance.has(propertyName, instance) && propertyValue in valueMappings) {
51
- const propertyNames = Validation.collectEvaluatedProperties(valueMappings[propertyValue], instance, ast, dynamicAnchors);
53
+ const propertyNames = Validation.collectEvaluatedProperties(valueMappings[propertyValue], instance, context);
52
54
  if (!propertyNames) {
53
55
  return false;
54
56
  }
@@ -60,4 +62,4 @@ const collectEvaluatedProperties = (propertyDependencies, instance, ast, dynamic
60
62
  return evaluatedPropertyNames;
61
63
  };
62
64
 
63
- export default { id, compile, interpret, collectEvaluatedProperties };
65
+ export default { id, compile, interpret, simpleApplicator, collectEvaluatedProperties };
@@ -6,14 +6,14 @@ const id = "https://json-schema.org/keyword/propertyNames";
6
6
 
7
7
  const compile = (schema, ast) => Validation.compile(schema, ast);
8
8
 
9
- const interpret = (propertyNames, instance, ast, dynamicAnchors) => {
9
+ const interpret = (propertyNames, instance, context) => {
10
10
  if (Instance.typeOf(instance) !== "object") {
11
11
  return true;
12
12
  }
13
13
 
14
14
  let isValid = true;
15
15
  for (const key of Instance.keys(instance)) {
16
- if (!Validation.interpret(propertyNames, key, ast, dynamicAnchors, true)) {
16
+ if (!Validation.interpret(propertyNames, key, { ...context, annotations: [] })) {
17
17
  isValid = false;
18
18
  }
19
19
  }
@@ -21,4 +21,6 @@ const interpret = (propertyNames, instance, ast, dynamicAnchors) => {
21
21
  return isValid;
22
22
  };
23
23
 
24
- export default { id, compile, interpret };
24
+ const simpleApplicator = true;
25
+
26
+ export default { id, compile, interpret, simpleApplicator };
@@ -1,14 +1,10 @@
1
1
  import * as Browser from "@hyperjump/browser";
2
- import * as Instance from "../../annotations/annotated-instance.js";
3
2
 
4
3
 
5
4
  const id = "https://json-schema.org/keyword/readOnly";
6
5
 
7
6
  const compile = (schema) => Browser.value(schema);
7
+ const interpret = () => true;
8
+ const annotation = (readOnly) => readOnly;
8
9
 
9
- const interpret = (readOnly, instance, _ast, _dynamicAnchors, _quiet, schemaLocation) => {
10
- Instance.setAnnotation(instance, id, schemaLocation, readOnly);
11
- return true;
12
- };
13
-
14
- export default { id, compile, interpret };
10
+ export default { id, compile, interpret, annotation };
@@ -8,4 +8,6 @@ const interpret = (...args) => Validation.interpret(...args);
8
8
  const collectEvaluatedProperties = (...args) => Validation.collectEvaluatedProperties(...args);
9
9
  const collectEvaluatedItems = (...args) => Validation.collectEvaluatedItems(...args);
10
10
 
11
- export default { id, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
11
+ const simpleApplicator = true;
12
+
13
+ export default { id, compile, interpret, simpleApplicator, collectEvaluatedProperties, collectEvaluatedItems };
@@ -1,6 +1,6 @@
1
1
  import * as Browser from "@hyperjump/browser";
2
- import { getKeywordName } from "../keywords.js";
3
- import { Validation } from "../experimental.js";
2
+ import { FLAG } from "../index.js";
3
+ import { getKeywordName, Validation } from "../experimental.js";
4
4
 
5
5
 
6
6
  const id = "https://json-schema.org/keyword/then";
@@ -15,26 +15,28 @@ const compile = async (schema, ast, parentSchema) => {
15
15
  }
16
16
  };
17
17
 
18
- const interpret = ([ifSchema, thenSchema], instance, ast, dynamicAnchors, quiet) => {
18
+ const interpret = ([ifSchema, thenSchema], instance, context) => {
19
19
  return ifSchema === undefined
20
- || !Validation.interpret(ifSchema, instance, ast, dynamicAnchors, true)
21
- || Validation.interpret(thenSchema, instance, ast, dynamicAnchors, quiet);
20
+ || !Validation.interpret(ifSchema, instance, { ...context, errors: [], annotations: [], outputFormat: FLAG })
21
+ || Validation.interpret(thenSchema, instance, context);
22
22
  };
23
23
 
24
- const collectEvaluatedProperties = ([ifSchema, thenSchema], instance, ast, dynamicAnchors) => {
25
- if (ifSchema === undefined || !Validation.interpret(ifSchema, instance, ast, dynamicAnchors, true)) {
24
+ const simpleApplicator = true;
25
+
26
+ const collectEvaluatedProperties = ([ifSchema, thenSchema], instance, context) => {
27
+ if (ifSchema === undefined || !Validation.interpret(ifSchema, instance, context)) {
26
28
  return new Set();
27
29
  }
28
30
 
29
- return Validation.collectEvaluatedProperties(thenSchema, instance, ast, dynamicAnchors);
31
+ return Validation.collectEvaluatedProperties(thenSchema, instance, context);
30
32
  };
31
33
 
32
- const collectEvaluatedItems = ([ifSchema, thenSchema], instance, ast, dynamicAnchors) => {
33
- if (ifSchema === undefined || !Validation.interpret(ifSchema, instance, ast, dynamicAnchors, true)) {
34
+ const collectEvaluatedItems = ([ifSchema, thenSchema], instance, context) => {
35
+ if (ifSchema === undefined || !Validation.interpret(ifSchema, instance, context)) {
34
36
  return new Set();
35
37
  }
36
38
 
37
- return Validation.collectEvaluatedItems(thenSchema, instance, ast, dynamicAnchors);
39
+ return Validation.collectEvaluatedItems(thenSchema, instance, context);
38
40
  };
39
41
 
40
- export default { id, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
42
+ export default { id, compile, interpret, simpleApplicator, collectEvaluatedProperties, collectEvaluatedItems };
@@ -1,14 +1,10 @@
1
1
  import * as Browser from "@hyperjump/browser";
2
- import * as Instance from "../../annotations/annotated-instance.js";
3
2
 
4
3
 
5
4
  const id = "https://json-schema.org/keyword/title";
6
5
 
7
6
  const compile = (schema) => Browser.value(schema);
7
+ const interpret = () => true;
8
+ const annotation = (title) => title;
8
9
 
9
- const interpret = (title, instance, _ast, _dynamicAnchors, _quiet, schemaLocation) => {
10
- Instance.setAnnotation(instance, id, schemaLocation, title);
11
- return true;
12
- };
13
-
14
- export default { id, compile, interpret };
10
+ export default { id, compile, interpret, annotation };
@@ -1,7 +1,7 @@
1
1
  import { zip, range } from "@hyperjump/pact";
2
+ import { FLAG } from "../index.js";
3
+ import { canonicalUri, Validation } from "../experimental.js";
2
4
  import * as Instance from "../instance.js";
3
- import { canonicalUri } from "../schema.js";
4
- import { Validation } from "../experimental.js";
5
5
 
6
6
 
7
7
  const id = "https://json-schema.org/keyword/unevaluatedItems";
@@ -10,19 +10,20 @@ const compile = async (schema, ast, parentSchema) => {
10
10
  return [canonicalUri(parentSchema), await Validation.compile(schema, ast)];
11
11
  };
12
12
 
13
- const interpret = ([schemaUrl, unevaluatedItems], instance, ast, dynamicAnchors, quiet) => {
13
+ const interpret = ([schemaUrl, unevaluatedItems], instance, context) => {
14
14
  if (Instance.typeOf(instance) !== "array") {
15
15
  return true;
16
16
  }
17
17
 
18
- const itemIndexes = Validation.collectEvaluatedItems(schemaUrl, instance, ast, dynamicAnchors, true);
18
+ const keywordContext = { ...context, errors: [], annotations: [], outputFormat: FLAG };
19
+ const itemIndexes = Validation.collectEvaluatedItems(schemaUrl, instance, keywordContext, true);
19
20
  if (itemIndexes === false) {
20
21
  return true;
21
22
  }
22
23
 
23
24
  let isValid = true;
24
25
  for (const [item, index] of zip(Instance.iter(instance), range(0))) {
25
- if (!itemIndexes.has(index) && !Validation.interpret(unevaluatedItems, item, ast, dynamicAnchors, quiet)) {
26
+ if (!itemIndexes.has(index) && !Validation.interpret(unevaluatedItems, item, context)) {
26
27
  isValid = false;
27
28
  }
28
29
  }
@@ -30,8 +31,10 @@ const interpret = ([schemaUrl, unevaluatedItems], instance, ast, dynamicAnchors,
30
31
  return isValid;
31
32
  };
32
33
 
33
- const collectEvaluatedItems = (keywordValue, instance, ast, dynamicAnchors) => {
34
- const itemIndexes = Validation.collectEvaluatedItems(keywordValue[0], instance, ast, dynamicAnchors, true);
34
+ const simpleApplicator = true;
35
+
36
+ const collectEvaluatedItems = (keywordValue, instance, context) => {
37
+ const itemIndexes = Validation.collectEvaluatedItems(keywordValue[0], instance, context, true);
35
38
  if (!itemIndexes) {
36
39
  return false;
37
40
  }
@@ -45,4 +48,4 @@ const collectEvaluatedItems = (keywordValue, instance, ast, dynamicAnchors) => {
45
48
  return evaluatedIndexes;
46
49
  };
47
50
 
48
- export default { id, compile, interpret, collectEvaluatedItems };
51
+ export default { id, compile, interpret, simpleApplicator, collectEvaluatedItems };