@hyperjump/json-schema 1.6.7 → 1.7.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 (104) hide show
  1. package/README.md +247 -255
  2. package/annotations/annotated-instance.js +3 -3
  3. package/annotations/index.d.ts +7 -1
  4. package/annotations/index.js +3 -3
  5. package/bundle/index.d.ts +1 -5
  6. package/bundle/index.js +112 -156
  7. package/draft-04/additionalItems.js +6 -7
  8. package/draft-04/dependencies.js +5 -5
  9. package/draft-04/index.js +2 -2
  10. package/draft-04/items.js +5 -5
  11. package/draft-04/maximum.js +8 -8
  12. package/draft-04/minimum.js +8 -8
  13. package/draft-06/contains.js +2 -2
  14. package/draft-06/index.js +3 -2
  15. package/draft-07/index.js +3 -2
  16. package/draft-2019-09/index.js +9 -11
  17. package/draft-2020-12/dynamicRef.js +5 -5
  18. package/draft-2020-12/index.js +11 -13
  19. package/lib/common.d.ts +1 -1
  20. package/lib/common.js +44 -60
  21. package/lib/configuration.js +0 -6
  22. package/lib/core.js +32 -30
  23. package/lib/experimental.d.ts +75 -5
  24. package/lib/experimental.js +2 -2
  25. package/lib/index.d.ts +43 -11
  26. package/lib/index.js +11 -11
  27. package/lib/instance.d.ts +1 -17
  28. package/lib/instance.js +3 -3
  29. package/lib/keywords/additionalProperties.js +12 -13
  30. package/lib/keywords/allOf.js +3 -3
  31. package/lib/keywords/anyOf.js +3 -3
  32. package/lib/keywords/conditional.js +6 -7
  33. package/lib/keywords/const.js +2 -2
  34. package/lib/keywords/contains.js +14 -35
  35. package/lib/keywords/contentSchema.js +1 -1
  36. package/lib/keywords/definitions.js +2 -2
  37. package/lib/keywords/dependentRequired.js +4 -4
  38. package/lib/keywords/dependentSchemas.js +5 -5
  39. package/lib/keywords/dynamicRef.js +10 -5
  40. package/lib/keywords/else.js +5 -6
  41. package/lib/keywords/enum.js +4 -4
  42. package/lib/keywords/exclusiveMaximum.js +3 -3
  43. package/lib/keywords/exclusiveMinimum.js +3 -3
  44. package/lib/keywords/if.js +1 -1
  45. package/lib/keywords/itemPattern.js +17 -14
  46. package/lib/keywords/items.js +6 -7
  47. package/lib/keywords/maxItems.js +3 -3
  48. package/lib/keywords/maxLength.js +3 -3
  49. package/lib/keywords/maxProperties.js +3 -3
  50. package/lib/keywords/maximum.js +3 -3
  51. package/lib/keywords/meta-data.js +1 -1
  52. package/lib/keywords/minItems.js +3 -3
  53. package/lib/keywords/minLength.js +3 -3
  54. package/lib/keywords/minProperties.js +3 -3
  55. package/lib/keywords/minimum.js +3 -3
  56. package/lib/keywords/multipleOf.js +3 -3
  57. package/lib/keywords/not.js +1 -1
  58. package/lib/keywords/oneOf.js +3 -3
  59. package/lib/keywords/pattern.js +3 -3
  60. package/lib/keywords/patternProperties.js +5 -5
  61. package/lib/keywords/prefixItems.js +5 -5
  62. package/lib/keywords/properties.js +5 -5
  63. package/lib/keywords/propertyDependencies.js +6 -7
  64. package/lib/keywords/propertyNames.js +2 -2
  65. package/lib/keywords/ref.js +2 -7
  66. package/lib/keywords/requireAllExcept.js +8 -9
  67. package/lib/keywords/required.js +3 -3
  68. package/lib/keywords/then.js +5 -5
  69. package/lib/keywords/type.js +9 -3
  70. package/lib/keywords/unevaluatedItems.js +4 -4
  71. package/lib/keywords/unevaluatedProperties.js +4 -5
  72. package/lib/keywords/uniqueItems.js +3 -3
  73. package/lib/keywords/validation.js +11 -23
  74. package/lib/keywords.js +27 -14
  75. package/lib/openapi.js +19 -6
  76. package/lib/schema.js +236 -227
  77. package/openapi-3-0/index.js +5 -5
  78. package/openapi-3-0/type.js +13 -7
  79. package/openapi-3-1/index.js +22 -21
  80. package/openapi-3-1/{schema-base/2022-10-07.js → schema-base.js} +12 -2
  81. package/openapi-3-1/schema-draft-04.js +33 -0
  82. package/openapi-3-1/schema-draft-06.js +33 -0
  83. package/openapi-3-1/schema-draft-07.js +33 -0
  84. package/openapi-3-1/schema-draft-2019-09.js +33 -0
  85. package/openapi-3-1/schema-draft-2020-12.js +33 -0
  86. package/package.json +11 -11
  87. package/stable/index.js +10 -10
  88. package/annotations/validation-error.d.ts +0 -8
  89. package/draft-2019-09/contains.js +0 -44
  90. package/lib/configuration.d.ts +0 -9
  91. package/lib/context-uri.browser.js +0 -1
  92. package/lib/context-uri.js +0 -4
  93. package/lib/core.d.ts +0 -48
  94. package/lib/fetch.browser.js +0 -1
  95. package/lib/fetch.js +0 -20
  96. package/lib/invalid-schema-error.d.ts +0 -8
  97. package/lib/keywords.d.ts +0 -19
  98. package/lib/media-types.d.ts +0 -11
  99. package/lib/media-types.js +0 -48
  100. package/lib/reference.d.ts +0 -11
  101. package/lib/reference.js +0 -11
  102. package/lib/schema.d.ts +0 -60
  103. /package/openapi-3-0/{schema/2021-09-28.js → schema.js} +0 -0
  104. /package/openapi-3-1/{schema/2022-10-07.js → schema.js} +0 -0
package/lib/instance.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { append as pointerAppend, get as pointerGet } from "@hyperjump/json-pointer";
2
2
  import { toAbsoluteIri } from "@hyperjump/uri";
3
- import curry from "just-curry-it";
4
3
  import { jsonTypeOf } from "./common.js";
4
+ import { Reference } from "@hyperjump/browser/jref";
5
5
 
6
6
 
7
7
  export const nil = { id: undefined, pointer: "", instance: undefined, value: undefined };
@@ -26,9 +26,9 @@ export const get = (url, instance = nil) => {
26
26
  };
27
27
 
28
28
  export const uri = (doc) => `${doc.id || ""}#${encodeURI(doc.pointer)}`;
29
- export const value = (doc) => doc.value;
29
+ export const value = (doc) => doc.value instanceof Reference ? doc.value.toJSON() : doc.value;
30
30
  export const has = (key, doc) => key in value(doc);
31
- export const typeOf = curry((doc, type) => jsonTypeOf(value(doc), type));
31
+ export const typeOf = (doc) => jsonTypeOf(value(doc));
32
32
 
33
33
  export const step = (key, doc) => ({
34
34
  ...doc,
@@ -1,23 +1,22 @@
1
1
  import { concat, join, empty, map, filter, every, pipe } from "@hyperjump/pact";
2
- import * as Schema from "../schema.js";
2
+ import * as Browser from "@hyperjump/browser";
3
3
  import * as Instance from "../instance.js";
4
- import { getKeywordName } from "../keywords.js";
5
- import Validation from "./validation.js";
4
+ import { getKeywordName, Validation } from "../experimental.js";
6
5
 
7
6
 
8
7
  const id = "https://json-schema.org/keyword/additionalProperties";
9
8
 
10
9
  const compile = async (schema, ast, parentSchema) => {
11
- const propertiesKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/properties");
12
- const propertiesSchema = await Schema.step(propertiesKeyword, parentSchema);
13
- const propertyPatterns = Schema.typeOf(propertiesSchema, "object")
14
- ? map((propertyName) => "^" + regexEscape(propertyName) + "$", Schema.keys(propertiesSchema))
10
+ const propertiesKeyword = getKeywordName(schema.document.dialectId, "https://json-schema.org/keyword/properties");
11
+ const propertiesSchema = await Browser.step(propertiesKeyword, parentSchema);
12
+ const propertyPatterns = Browser.typeOf(propertiesSchema) === "object"
13
+ ? map((propertyName) => "^" + regexEscape(propertyName) + "$", Browser.keys(propertiesSchema))
15
14
  : empty();
16
15
 
17
- const patternPropertiesKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/patternProperties");
18
- const patternProperties = await Schema.step(patternPropertiesKeyword, parentSchema);
19
- const patternPropertyPatterns = Schema.typeOf(patternProperties, "object")
20
- ? Schema.keys(patternProperties)
16
+ const patternPropertiesKeyword = getKeywordName(schema.document.dialectId, "https://json-schema.org/keyword/patternProperties");
17
+ const patternProperties = await Browser.step(patternPropertiesKeyword, parentSchema);
18
+ const patternPropertyPatterns = Browser.typeOf(patternProperties) === "object"
19
+ ? Browser.keys(patternProperties)
21
20
  : empty();
22
21
 
23
22
  const pattern = pipe(
@@ -33,7 +32,7 @@ const regexEscape = (string) => string
33
32
  .replace(/-/g, "\\x2d");
34
33
 
35
34
  const interpret = ([isDefinedProperty, additionalProperties], instance, ast, dynamicAnchors, quiet) => {
36
- if (!Instance.typeOf(instance, "object")) {
35
+ if (Instance.typeOf(instance) !== "object") {
37
36
  return true;
38
37
  }
39
38
 
@@ -45,7 +44,7 @@ const interpret = ([isDefinedProperty, additionalProperties], instance, ast, dyn
45
44
  };
46
45
 
47
46
  const collectEvaluatedProperties = ([isDefinedProperty, additionalProperties], instance, ast, dynamicAnchors) => {
48
- if (!Instance.typeOf(instance, "object")) {
47
+ if (Instance.typeOf(instance) !== "object") {
49
48
  return true;
50
49
  }
51
50
 
@@ -1,12 +1,12 @@
1
1
  import { pipe, asyncMap, asyncCollectArray } from "@hyperjump/pact";
2
- import * as Schema from "../schema.js";
3
- import Validation from "./validation.js";
2
+ import * as Browser from "@hyperjump/browser";
3
+ import { Validation } from "../experimental.js";
4
4
 
5
5
 
6
6
  const id = "https://json-schema.org/keyword/allOf";
7
7
 
8
8
  const compile = (schema, ast) => pipe(
9
- Schema.iter(schema),
9
+ Browser.iter(schema),
10
10
  asyncMap((itemSchema) => Validation.compile(itemSchema, ast)),
11
11
  asyncCollectArray
12
12
  );
@@ -1,12 +1,12 @@
1
1
  import { pipe, asyncMap, asyncCollectArray } from "@hyperjump/pact";
2
- import * as Schema from "../schema.js";
3
- import Validation from "./validation.js";
2
+ import * as Browser from "@hyperjump/browser";
3
+ import { Validation } from "../experimental.js";
4
4
 
5
5
 
6
6
  const id = "https://json-schema.org/keyword/anyOf";
7
7
 
8
8
  const compile = (schema, ast) => pipe(
9
- Schema.iter(schema),
9
+ Browser.iter(schema),
10
10
  asyncMap((itemSchema) => Validation.compile(itemSchema, ast)),
11
11
  asyncCollectArray
12
12
  );
@@ -1,13 +1,12 @@
1
1
  import { pipe, asyncMap, asyncCollectArray } from "@hyperjump/pact";
2
- import * as Schema from "../schema.js";
3
- import Validation from "./validation.js";
2
+ import * as Browser from "@hyperjump/browser";
3
+ import { Validation } from "../experimental.js";
4
4
 
5
5
 
6
6
  const id = "https://json-schema.org/keyword/conditional";
7
- const experimental = true;
8
7
 
9
8
  const compile = (schema, ast) => pipe(
10
- Schema.iter(schema),
9
+ Browser.iter(schema),
11
10
  schemaFlatten,
12
11
  asyncMap((subSchema) => Validation.compile(subSchema, ast)),
13
12
  asyncCollectArray
@@ -54,12 +53,12 @@ const collectEvaluatedItems = (conditional, instance, ast, dynamicAnchors) => {
54
53
 
55
54
  const schemaFlatten = async function* (iter, depth = 1) {
56
55
  for await (const n of iter) {
57
- if (depth > 0 && Schema.typeOf(n, "array")) {
58
- yield* schemaFlatten(Schema.iter(n), depth - 1);
56
+ if (depth > 0 && Browser.typeOf(n) === "array") {
57
+ yield* schemaFlatten(Browser.iter(n), depth - 1);
59
58
  } else {
60
59
  yield n;
61
60
  }
62
61
  }
63
62
  };
64
63
 
65
- export default { id, experimental, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
64
+ export default { id, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
@@ -1,11 +1,11 @@
1
1
  import jsonStringify from "fastest-stable-stringify";
2
- import * as Schema from "../schema.js";
2
+ import * as Browser from "@hyperjump/browser";
3
3
  import * as Instance from "../instance.js";
4
4
 
5
5
 
6
6
  const id = "https://json-schema.org/keyword/const";
7
7
 
8
- const compile = (schema) => jsonStringify(Schema.value(schema));
8
+ const compile = (schema) => jsonStringify(Browser.value(schema));
9
9
  const interpret = (const_, instance) => jsonStringify(Instance.value(instance)) === const_;
10
10
 
11
11
  export default { id, compile, interpret };
@@ -1,8 +1,7 @@
1
- import { pipe, map, filter, count, collectSet, zip, range } from "@hyperjump/pact";
2
- import * as Schema from "../schema.js";
1
+ import { pipe, filter, reduce, zip, range, map, collectSet } from "@hyperjump/pact";
2
+ import * as Browser from "@hyperjump/browser";
3
3
  import * as Instance from "../instance.js";
4
- import { getKeywordName } from "../keywords.js";
5
- import Validation from "./validation.js";
4
+ import { getKeywordName, Validation } from "../experimental.js";
6
5
 
7
6
 
8
7
  const id = "https://json-schema.org/keyword/contains";
@@ -10,49 +9,29 @@ const id = "https://json-schema.org/keyword/contains";
10
9
  const compile = async (schema, ast, parentSchema) => {
11
10
  const contains = await Validation.compile(schema, ast);
12
11
 
13
- const minContainsKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/minContains");
14
- const minContainsSchema = await Schema.step(minContainsKeyword, parentSchema);
15
- const minContains = Schema.typeOf(minContainsSchema, "number") ? Schema.value(minContainsSchema) : 1;
12
+ const minContainsKeyword = getKeywordName(schema.document.dialectId, "https://json-schema.org/keyword/minContains");
13
+ const minContainsSchema = await Browser.step(minContainsKeyword, parentSchema);
14
+ const minContains = Browser.typeOf(minContainsSchema) === "number" ? Browser.value(minContainsSchema) : 1;
16
15
 
17
- const maxContainsKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/maxContains");
18
- const maxContainsSchema = await Schema.step(maxContainsKeyword, parentSchema);
19
- const maxContains = Schema.typeOf(maxContainsSchema, "number") ? Schema.value(maxContainsSchema) : Number.MAX_SAFE_INTEGER;
16
+ const maxContainsKeyword = getKeywordName(schema.document.dialectId, "https://json-schema.org/keyword/maxContains");
17
+ const maxContainsSchema = await Browser.step(maxContainsKeyword, parentSchema);
18
+ const maxContains = Browser.typeOf(maxContainsSchema) === "number" ? Browser.value(maxContainsSchema) : Number.MAX_SAFE_INTEGER;
20
19
 
21
20
  return { contains, minContains, maxContains };
22
21
  };
23
22
 
24
23
  const interpret = ({ contains, minContains, maxContains }, instance, ast, dynamicAnchors, quiet) => {
25
- let iterator;
26
- if (Instance.typeOf(instance, "array")) {
27
- iterator = Instance.iter(instance);
28
- } else if (Instance.typeOf(instance, "object")) {
29
- iterator = Instance.values(instance);
30
- } else {
31
- return true;
32
- }
33
-
34
- const matches = pipe(
35
- iterator,
24
+ const matches = Instance.typeOf(instance) !== "array" || pipe(
25
+ Instance.iter(instance),
36
26
  filter((item) => Validation.interpret(contains, item, ast, dynamicAnchors, quiet)),
37
- count
27
+ reduce((matches) => matches + 1, 0)
38
28
  );
39
29
  return matches >= minContains && matches <= maxContains;
40
30
  };
41
31
 
42
- const collectEvaluatedProperties = (keywordValue, instance, ast, dynamicAnchors) => {
43
- return interpret(keywordValue, instance, ast, dynamicAnchors, true)
44
- && Instance.typeOf(instance, "object")
45
- && pipe(
46
- Instance.entries(instance),
47
- filter(([, item]) => Validation.interpret(keywordValue.contains, item, ast, dynamicAnchors, true)),
48
- map(([propertyName]) => propertyName),
49
- collectSet
50
- );
51
- };
52
-
53
32
  const collectEvaluatedItems = (keywordValue, instance, ast, dynamicAnchors) => {
54
33
  return interpret(keywordValue, instance, ast, dynamicAnchors, true)
55
- && Instance.typeOf(instance, "array")
34
+ && Instance.typeOf(instance) === "array"
56
35
  && pipe(
57
36
  zip(Instance.iter(instance), range(0)),
58
37
  filter(([item]) => Validation.interpret(keywordValue.contains, item, ast, dynamicAnchors, true)),
@@ -61,4 +40,4 @@ const collectEvaluatedItems = (keywordValue, instance, ast, dynamicAnchors) => {
61
40
  );
62
41
  };
63
42
 
64
- export default { id, compile, interpret, collectEvaluatedItems, collectEvaluatedProperties };
43
+ export default { id, compile, interpret, collectEvaluatedItems };
@@ -3,7 +3,7 @@ import * as Schema from "../schema.js";
3
3
 
4
4
  const id = "https://json-schema.org/keyword/contentSchema";
5
5
 
6
- const compile = (contentSchema) => Schema.uri(contentSchema);
6
+ const compile = (contentSchema) => Schema.canonicalUri(contentSchema);
7
7
  const interpret = () => true;
8
8
 
9
9
  export default { id, compile, interpret };
@@ -1,12 +1,12 @@
1
+ import * as Browser from "@hyperjump/browser";
1
2
  import { pipe, asyncMap, asyncCollectArray } from "@hyperjump/pact";
2
- import * as Schema from "../schema.js";
3
3
  import Validation from "./validation.js";
4
4
 
5
5
 
6
6
  const id = "https://json-schema.org/keyword/definitions";
7
7
 
8
8
  const compile = (schema, ast) => pipe(
9
- Schema.values(schema),
9
+ Browser.values(schema),
10
10
  asyncMap((definitionSchema) => Validation.compile(definitionSchema, ast)),
11
11
  asyncCollectArray
12
12
  );
@@ -1,18 +1,18 @@
1
1
  import { pipe, asyncMap, asyncCollectArray } from "@hyperjump/pact";
2
- import * as Schema from "../schema.js";
2
+ import * as Browser from "@hyperjump/browser";
3
3
  import * as Instance from "../instance.js";
4
4
 
5
5
 
6
6
  const id = "https://json-schema.org/keyword/dependentRequired";
7
7
 
8
8
  const compile = (schema) => pipe(
9
- Schema.entries(schema),
10
- asyncMap(([key, dependentRequired]) => [key, Schema.value(dependentRequired)]),
9
+ Browser.entries(schema),
10
+ asyncMap(([key, dependentRequired]) => [key, Browser.value(dependentRequired)]),
11
11
  asyncCollectArray
12
12
  );
13
13
 
14
14
  const interpret = (dependentRequired, instance) => {
15
- return !Instance.typeOf(instance, "object") || dependentRequired.every(([propertyName, required]) => {
15
+ return Instance.typeOf(instance) !== "object" || dependentRequired.every(([propertyName, required]) => {
16
16
  return !Instance.has(propertyName, instance) || required.every((key) => Instance.has(key, instance));
17
17
  });
18
18
  };
@@ -1,25 +1,25 @@
1
1
  import { pipe, asyncMap, asyncCollectArray } from "@hyperjump/pact";
2
- import * as Schema from "../schema.js";
2
+ import * as Browser from "@hyperjump/browser";
3
3
  import * as Instance from "../instance.js";
4
- import Validation from "./validation.js";
4
+ import { Validation } from "../experimental.js";
5
5
 
6
6
 
7
7
  const id = "https://json-schema.org/keyword/dependentSchemas";
8
8
 
9
9
  const compile = (schema, ast) => pipe(
10
- Schema.entries(schema),
10
+ Browser.entries(schema),
11
11
  asyncMap(async ([key, dependentSchema]) => [key, await Validation.compile(dependentSchema, ast)]),
12
12
  asyncCollectArray
13
13
  );
14
14
 
15
15
  const interpret = (dependentSchemas, instance, ast, dynamicAnchors, quiet) => {
16
- return !Instance.typeOf(instance, "object") || dependentSchemas.every(([propertyName, dependentSchema]) => {
16
+ return Instance.typeOf(instance) !== "object" || dependentSchemas.every(([propertyName, dependentSchema]) => {
17
17
  return !Instance.has(propertyName, instance) || Validation.interpret(dependentSchema, instance, ast, dynamicAnchors, quiet);
18
18
  });
19
19
  };
20
20
 
21
21
  const collectEvaluatedProperties = (dependentSchemas, instance, ast, dynamicAnchors) => {
22
- if (!Instance.typeOf(instance, "object")) {
22
+ if (Instance.typeOf(instance) !== "object") {
23
23
  return false;
24
24
  }
25
25
 
@@ -1,11 +1,16 @@
1
- import * as Schema from "../schema.js";
2
- import Validation from "./validation.js";
1
+ import * as Browser from "@hyperjump/browser";
2
+ import { Validation } from "../experimental.js";
3
3
 
4
4
 
5
5
  const id = "https://json-schema.org/keyword/dynamicRef";
6
- const experimental = true;
7
6
 
8
- const compile = Schema.value;
7
+ const compile = async (schema, ast) => {
8
+ const reference = Browser.value(schema);
9
+ const self = await Browser.get(schema.document.baseUri, schema);
10
+ await Validation.compile(self, ast);
11
+
12
+ return reference;
13
+ };
9
14
 
10
15
  const evaluate = (strategy) => (fragment, instance, ast, dynamicAnchors, quiet) => {
11
16
  if (!(fragment in dynamicAnchors)) {
@@ -18,4 +23,4 @@ const interpret = evaluate(Validation.interpret);
18
23
  const collectEvaluatedProperties = evaluate(Validation.collectEvaluatedProperties);
19
24
  const collectEvaluatedItems = evaluate(Validation.collectEvaluatedItems);
20
25
 
21
- export default { id, experimental, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
26
+ export default { id, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
@@ -1,14 +1,13 @@
1
- import * as Schema from "../schema.js";
2
- import { getKeywordName } from "../keywords.js";
3
- import Validation from "./validation.js";
1
+ import * as Browser from "@hyperjump/browser";
2
+ import { getKeywordName, Validation } from "../experimental.js";
4
3
 
5
4
 
6
5
  const id = "https://json-schema.org/keyword/else";
7
6
 
8
7
  const compile = async (schema, ast, parentSchema) => {
9
- const ifKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/if");
10
- if (Schema.has(ifKeyword, parentSchema)) {
11
- const ifSchema = await Schema.step(ifKeyword, parentSchema);
8
+ const ifKeyword = getKeywordName(schema.document.dialectId, "https://json-schema.org/keyword/if");
9
+ if (Browser.has(ifKeyword, parentSchema)) {
10
+ const ifSchema = await Browser.step(ifKeyword, parentSchema);
12
11
  return [await Validation.compile(ifSchema, ast), await Validation.compile(schema, ast)];
13
12
  } else {
14
13
  return [];
@@ -1,14 +1,14 @@
1
- import { pipe, asyncMap, asyncCollectArray } from "@hyperjump/pact";
2
1
  import jsonStringify from "fastest-stable-stringify";
3
- import * as Schema from "../schema.js";
2
+ import { pipe, asyncMap, asyncCollectArray } from "@hyperjump/pact";
3
+ import * as Browser from "@hyperjump/browser";
4
4
  import * as Instance from "../instance.js";
5
5
 
6
6
 
7
7
  const id = "https://json-schema.org/keyword/enum";
8
8
 
9
9
  const compile = (schema) => pipe(
10
- Schema.iter(schema),
11
- asyncMap(Schema.value),
10
+ Browser.iter(schema),
11
+ asyncMap(Browser.value),
12
12
  asyncMap(jsonStringify),
13
13
  asyncCollectArray
14
14
  );
@@ -1,10 +1,10 @@
1
- import * as Schema from "../schema.js";
1
+ import * as Browser from "@hyperjump/browser";
2
2
  import * as Instance from "../instance.js";
3
3
 
4
4
 
5
5
  const id = "https://json-schema.org/keyword/exclusiveMaximum";
6
6
 
7
- const compile = (schema) => Schema.value(schema);
8
- const interpret = (exclusiveMaximum, instance) => !Instance.typeOf(instance, "number") || Instance.value(instance) < exclusiveMaximum;
7
+ const compile = (schema) => Browser.value(schema);
8
+ const interpret = (exclusiveMaximum, instance) => Instance.typeOf(instance) !== "number" || Instance.value(instance) < exclusiveMaximum;
9
9
 
10
10
  export default { id, compile, interpret };
@@ -1,10 +1,10 @@
1
- import * as Schema from "../schema.js";
1
+ import * as Browser from "@hyperjump/browser";
2
2
  import * as Instance from "../instance.js";
3
3
 
4
4
 
5
5
  const id = "https://json-schema.org/keyword/exclusiveMinimum";
6
6
 
7
- const compile = (schema) => Schema.value(schema);
8
- const interpret = (exclusiveMinimum, instance) => !Instance.typeOf(instance, "number") || Instance.value(instance) > exclusiveMinimum;
7
+ const compile = (schema) => Browser.value(schema);
8
+ const interpret = (exclusiveMinimum, instance) => Instance.typeOf(instance) !== "number" || Instance.value(instance) > exclusiveMinimum;
9
9
 
10
10
  export default { id, compile, interpret };
@@ -1,4 +1,4 @@
1
- import Validation from "./validation.js";
1
+ import { Validation } from "../experimental.js";
2
2
 
3
3
 
4
4
  const id = "https://json-schema.org/keyword/if";
@@ -1,19 +1,18 @@
1
- import * as Schema from "../schema.js";
1
+ import * as Browser from "@hyperjump/browser";
2
2
  import * as Instance from "../instance.js";
3
- import Validation from "./validation.js";
3
+ import { Validation } from "../experimental.js";
4
4
  import { fromEpsilon, fromSchema, closure, zeroOrOne, oneOrMore, concat, union } from "../nfa.js";
5
5
 
6
6
 
7
7
  const id = "https://json-schema.org/keyword/itemPattern";
8
- const experimental = true;
9
8
 
10
9
  const compile = async (schema, ast) => {
11
10
  const groups = [[]];
12
11
  let group = groups[0];
13
12
 
14
- for await (const rule of Schema.iter(schema)) {
15
- if (Schema.typeOf(rule, "string")) {
16
- const operator = Schema.value(rule);
13
+ for await (const rule of Browser.iter(schema)) {
14
+ if (Browser.typeOf(rule) === "string") {
15
+ const operator = Browser.value(rule);
17
16
 
18
17
  if (operator === "*") {
19
18
  group.push(closure(group.pop()));
@@ -28,20 +27,20 @@ const compile = async (schema, ast) => {
28
27
  throw Error(`Unsupported pattern syntax: ${operator}`);
29
28
  }
30
29
  } else {
31
- const node = Schema.typeOf(rule, "array")
30
+ const node = Browser.typeOf(rule) === "array"
32
31
  ? compile(rule, ast)
33
32
  : fromSchema(await Validation.compile(rule, ast));
34
33
  group.push(await node);
35
34
  }
36
35
  }
37
36
 
38
- return Schema.length(schema) === 0 ? fromEpsilon() : groups
37
+ return Browser.length(schema) === 0 ? fromEpsilon() : groups
39
38
  .map((group) => group.reduce(concat))
40
39
  .reduce(union);
41
40
  };
42
41
 
43
- const interpret = (nfa, instance, ast, dynamicAnchors, quiet) => {
44
- if (!Instance.typeOf(instance, "array")) {
42
+ const evaluate = (strategy) => (nfa, instance, ast, dynamicAnchors, quiet) => {
43
+ if (Instance.typeOf(instance) !== "array") {
45
44
  return true;
46
45
  }
47
46
 
@@ -52,7 +51,7 @@ const interpret = (nfa, instance, ast, dynamicAnchors, quiet) => {
52
51
  const nextStates = [];
53
52
 
54
53
  for (const state of currentStates) {
55
- const nextState = transition(state.transition, item, ast, dynamicAnchors, quiet);
54
+ const nextState = transition(strategy, state.transition, item, ast, dynamicAnchors, quiet);
56
55
  if (nextState) {
57
56
  addNextState(nextState, nextStates, []);
58
57
  }
@@ -77,12 +76,16 @@ const addNextState = (state, nextStates, visited) => {
77
76
  }
78
77
  };
79
78
 
80
- const transition = (transitions, instance, ast, dynamicAnchors, quiet) => {
79
+ const transition = (strategy, transitions, instance, ast, dynamicAnchors, quiet) => {
81
80
  for (const schema in transitions) {
82
- if (Validation.interpret(schema, instance, ast, dynamicAnchors, quiet)) {
81
+ if (strategy(schema, instance, ast, dynamicAnchors, quiet)) {
83
82
  return transitions[schema];
84
83
  }
85
84
  }
86
85
  };
87
86
 
88
- export default { id, experimental, compile, interpret };
87
+ const interpret = evaluate(Validation.interpret);
88
+ const collectEvalatedProperties = evaluate(Validation.collectEvaluatedProperties);
89
+ const collectEvalatedItems = evaluate(Validation.collectEvaluatedItems);
90
+
91
+ export default { id, compile, interpret, collectEvalatedProperties, collectEvalatedItems };
@@ -1,22 +1,21 @@
1
1
  import { pipe, drop, every } from "@hyperjump/pact";
2
- import * as Schema from "../schema.js";
2
+ import * as Browser from "@hyperjump/browser";
3
3
  import * as Instance from "../instance.js";
4
- import { getKeywordName } from "../keywords.js";
5
- import Validation from "./validation.js";
4
+ import { getKeywordName, Validation } from "../experimental.js";
6
5
 
7
6
 
8
7
  const id = "https://json-schema.org/keyword/items";
9
8
 
10
9
  const compile = async (schema, ast, parentSchema) => {
11
- const prefixItemKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/prefixItems");
12
- const prefixItems = await Schema.step(prefixItemKeyword, parentSchema);
13
- const numberOfPrefixItems = Schema.typeOf(prefixItems, "array") ? Schema.length(prefixItems) : 0;
10
+ const prefixItemKeyword = getKeywordName(schema.document.dialectId, "https://json-schema.org/keyword/prefixItems");
11
+ const prefixItems = await Browser.step(prefixItemKeyword, parentSchema);
12
+ const numberOfPrefixItems = Browser.typeOf(prefixItems) === "array" ? Browser.length(prefixItems) : 0;
14
13
 
15
14
  return [numberOfPrefixItems, await Validation.compile(schema, ast)];
16
15
  };
17
16
 
18
17
  const interpret = ([numberOfPrefixItems, items], instance, ast, dynamicAnchors, quiet) => {
19
- if (!Instance.typeOf(instance, "array")) {
18
+ if (Instance.typeOf(instance) !== "array") {
20
19
  return true;
21
20
  }
22
21
 
@@ -1,10 +1,10 @@
1
- import * as Schema from "../schema.js";
1
+ import * as Browser from "@hyperjump/browser";
2
2
  import * as Instance from "../instance.js";
3
3
 
4
4
 
5
5
  const id = "https://json-schema.org/keyword/maxItems";
6
6
 
7
- const compile = (schema) => Schema.value(schema);
8
- const interpret = (maxItems, instance) => !Instance.typeOf(instance, "array") || Instance.length(instance) <= maxItems;
7
+ const compile = (schema) => Browser.value(schema);
8
+ const interpret = (maxItems, instance) => Instance.typeOf(instance) !== "array" || Instance.length(instance) <= maxItems;
9
9
 
10
10
  export default { id, compile, interpret };
@@ -1,10 +1,10 @@
1
- import * as Schema from "../schema.js";
1
+ import * as Browser from "@hyperjump/browser";
2
2
  import * as Instance from "../instance.js";
3
3
 
4
4
 
5
5
  const id = "https://json-schema.org/keyword/maxLength";
6
6
 
7
- const compile = (schema) => Schema.value(schema);
8
- const interpret = (maxLength, instance) => !Instance.typeOf(instance, "string") || [...Instance.value(instance)].length <= maxLength;
7
+ const compile = (schema) => Browser.value(schema);
8
+ const interpret = (maxLength, instance) => Instance.typeOf(instance) !== "string" || [...Instance.value(instance)].length <= maxLength;
9
9
 
10
10
  export default { id, compile, interpret };
@@ -1,12 +1,12 @@
1
- import * as Schema from "../schema.js";
1
+ import * as Browser from "@hyperjump/browser";
2
2
  import * as Instance from "../instance.js";
3
3
 
4
4
 
5
5
  const id = "https://json-schema.org/keyword/maxProperties";
6
6
 
7
- const compile = (schema) => Schema.value(schema);
7
+ const compile = (schema) => Browser.value(schema);
8
8
  const interpret = (maxProperties, instance) => {
9
- return !Instance.typeOf(instance, "object") || [...Instance.keys(instance)].length <= maxProperties;
9
+ return Instance.typeOf(instance) !== "object" || [...Instance.keys(instance)].length <= maxProperties;
10
10
  };
11
11
 
12
12
  export default { id, compile, interpret };
@@ -1,10 +1,10 @@
1
- import * as Schema from "../schema.js";
1
+ import * as Browser from "@hyperjump/browser";
2
2
  import * as Instance from "../instance.js";
3
3
 
4
4
 
5
5
  const id = "https://json-schema.org/keyword/maximum";
6
6
 
7
- const compile = (schema) => Schema.value(schema);
8
- const interpret = (maximum, instance) => !Instance.typeOf(instance, "number") || Instance.value(instance) <= maximum;
7
+ const compile = (schema) => Browser.value(schema);
8
+ const interpret = (maximum, instance) => Instance.typeOf(instance) !== "number" || Instance.value(instance) <= maximum;
9
9
 
10
10
  export default { id, compile, interpret };
@@ -1,4 +1,4 @@
1
- import { value } from "../schema.js";
1
+ import { value } from "@hyperjump/browser";
2
2
 
3
3
 
4
4
  const compile = value;
@@ -1,10 +1,10 @@
1
- import * as Schema from "../schema.js";
1
+ import * as Browser from "@hyperjump/browser";
2
2
  import * as Instance from "../instance.js";
3
3
 
4
4
 
5
5
  const id = "https://json-schema.org/keyword/minItems";
6
6
 
7
- const compile = (schema) => Schema.value(schema);
8
- const interpret = (minItems, instance) => !Instance.typeOf(instance, "array") || Instance.length(instance) >= minItems;
7
+ const compile = (schema) => Browser.value(schema);
8
+ const interpret = (minItems, instance) => Instance.typeOf(instance) !== "array" || Instance.length(instance) >= minItems;
9
9
 
10
10
  export default { id, compile, interpret };
@@ -1,10 +1,10 @@
1
- import * as Schema from "../schema.js";
1
+ import * as Browser from "@hyperjump/browser";
2
2
  import * as Instance from "../instance.js";
3
3
 
4
4
 
5
5
  const id = "https://json-schema.org/keyword/minLength";
6
6
 
7
- const compile = (schema) => Schema.value(schema);
8
- const interpret = (minLength, instance) => !Instance.typeOf(instance, "string") || [...Instance.value(instance)].length >= minLength;
7
+ const compile = (schema) => Browser.value(schema);
8
+ const interpret = (minLength, instance) => Instance.typeOf(instance) !== "string" || [...Instance.value(instance)].length >= minLength;
9
9
 
10
10
  export default { id, compile, interpret };