@hyperjump/json-schema 0.23.3 → 1.0.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 (202) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +459 -120
  3. package/draft-04/additionalItems.js +29 -0
  4. package/{lib/keywords → draft-04}/dependencies.js +9 -5
  5. package/draft-04/exclusiveMaximum.js +5 -0
  6. package/draft-04/exclusiveMinimum.js +5 -0
  7. package/draft-04/id.js +1 -0
  8. package/draft-04/index.d.ts +43 -0
  9. package/draft-04/index.js +69 -0
  10. package/draft-04/items.js +35 -0
  11. package/draft-04/maximum.js +26 -0
  12. package/draft-04/minimum.js +25 -0
  13. package/draft-04/ref.js +1 -0
  14. package/draft-04/schema.js +149 -0
  15. package/draft-06/contains.js +13 -0
  16. package/draft-06/index.d.ts +47 -0
  17. package/draft-06/index.js +66 -0
  18. package/draft-06/schema.js +154 -0
  19. package/{lib/draft-07.d.ts → draft-07/index.d.ts} +21 -19
  20. package/draft-07/index.js +72 -0
  21. package/draft-07/schema.js +172 -0
  22. package/{lib/keywords/contains-minContains-maxContains.js → draft-2019-09/contains.js} +14 -7
  23. package/{lib/draft-2019-09.d.ts → draft-2019-09/index.d.ts} +24 -22
  24. package/draft-2019-09/index.js +117 -0
  25. package/draft-2019-09/meta/applicator.js +55 -0
  26. package/draft-2019-09/meta/content.js +17 -0
  27. package/draft-2019-09/meta/core.js +57 -0
  28. package/draft-2019-09/meta/format.js +14 -0
  29. package/draft-2019-09/meta/meta-data.js +37 -0
  30. package/draft-2019-09/meta/validation.js +98 -0
  31. package/draft-2019-09/recursiveAnchor.js +1 -0
  32. package/draft-2019-09/recursiveRef.js +19 -0
  33. package/draft-2019-09/schema.js +42 -0
  34. package/draft-2020-12/dynamicAnchor.js +1 -0
  35. package/draft-2020-12/dynamicRef.js +35 -0
  36. package/draft-2020-12/index.d.ts +66 -0
  37. package/draft-2020-12/index.js +124 -0
  38. package/draft-2020-12/meta/applicator.js +46 -0
  39. package/draft-2020-12/meta/content.js +14 -0
  40. package/draft-2020-12/meta/core.js +54 -0
  41. package/draft-2020-12/meta/format-annotation.js +11 -0
  42. package/draft-2020-12/meta/format-assertion.js +11 -0
  43. package/draft-2020-12/meta/meta-data.js +34 -0
  44. package/draft-2020-12/meta/unevaluated.js +12 -0
  45. package/draft-2020-12/meta/validation.js +95 -0
  46. package/draft-2020-12/schema.js +44 -0
  47. package/lib/common.d.ts +5 -1
  48. package/lib/common.js +80 -9
  49. package/lib/configuration.d.ts +9 -0
  50. package/lib/configuration.js +18 -0
  51. package/lib/core.d.ts +48 -0
  52. package/lib/core.js +102 -0
  53. package/lib/experimental.d.ts +8 -0
  54. package/lib/experimental.js +4 -0
  55. package/lib/fetch.browser.js +1 -0
  56. package/lib/fetch.js +19 -0
  57. package/lib/index.d.ts +11 -42
  58. package/lib/index.js +130 -23
  59. package/lib/instance.d.ts +75 -0
  60. package/lib/instance.js +58 -0
  61. package/lib/invalid-schema-error.d.ts +8 -0
  62. package/lib/invalid-schema-error.js +7 -0
  63. package/lib/keywords/additionalProperties.js +19 -17
  64. package/lib/keywords/allOf.js +10 -7
  65. package/lib/keywords/anchor.js +1 -0
  66. package/lib/keywords/anyOf.js +10 -7
  67. package/lib/keywords/comment.js +4 -0
  68. package/lib/keywords/const.js +6 -3
  69. package/lib/keywords/contains.js +48 -5
  70. package/lib/keywords/contentEncoding.js +4 -0
  71. package/lib/keywords/contentMediaType.js +4 -0
  72. package/lib/keywords/contentSchema.js +4 -0
  73. package/lib/keywords/default.js +4 -0
  74. package/lib/keywords/definitions.js +7 -4
  75. package/lib/keywords/dependentRequired.js +6 -3
  76. package/lib/keywords/dependentSchemas.js +10 -6
  77. package/lib/keywords/deprecated.js +4 -0
  78. package/lib/keywords/description.js +4 -0
  79. package/lib/keywords/dynamicAnchor.js +1 -0
  80. package/lib/keywords/dynamicRef.js +13 -17
  81. package/lib/keywords/else.js +16 -11
  82. package/lib/keywords/enum.js +6 -3
  83. package/lib/keywords/examples.js +4 -0
  84. package/lib/keywords/exclusiveMaximum.js +5 -2
  85. package/lib/keywords/exclusiveMinimum.js +5 -2
  86. package/lib/keywords/format.js +4 -0
  87. package/lib/keywords/id.js +1 -0
  88. package/lib/keywords/if.js +8 -6
  89. package/lib/keywords/items.js +17 -19
  90. package/lib/keywords/maxContains.js +4 -0
  91. package/lib/keywords/maxItems.js +5 -2
  92. package/lib/keywords/maxLength.js +5 -2
  93. package/lib/keywords/maxProperties.js +5 -2
  94. package/lib/keywords/maximum.js +5 -2
  95. package/lib/keywords/meta-data.js +4 -0
  96. package/lib/keywords/minContains.js +4 -0
  97. package/lib/keywords/minItems.js +5 -2
  98. package/lib/keywords/minLength.js +5 -2
  99. package/lib/keywords/minProperties.js +5 -2
  100. package/lib/keywords/minimum.js +5 -2
  101. package/lib/keywords/multipleOf.js +5 -2
  102. package/lib/keywords/not.js +6 -4
  103. package/lib/keywords/oneOf.js +9 -6
  104. package/lib/keywords/pattern.js +5 -2
  105. package/lib/keywords/patternProperties.js +9 -5
  106. package/lib/keywords/prefixItems.js +28 -0
  107. package/lib/keywords/properties.js +11 -6
  108. package/lib/keywords/propertyDependencies.js +49 -0
  109. package/lib/keywords/propertyNames.js +7 -4
  110. package/lib/keywords/readOnly.js +4 -0
  111. package/lib/keywords/ref.js +9 -6
  112. package/lib/keywords/requireAllExcept.js +24 -0
  113. package/lib/keywords/required.js +5 -2
  114. package/lib/keywords/then.js +16 -11
  115. package/lib/keywords/title.js +4 -0
  116. package/lib/keywords/type.js +5 -2
  117. package/lib/keywords/unevaluatedItems.js +9 -5
  118. package/lib/keywords/unevaluatedProperties.js +9 -5
  119. package/lib/keywords/uniqueItems.js +6 -3
  120. package/lib/keywords/validation.js +123 -0
  121. package/lib/keywords/vocabulary.js +1 -0
  122. package/lib/keywords/writeOnly.js +4 -0
  123. package/lib/keywords.d.ts +19 -0
  124. package/lib/keywords.js +59 -0
  125. package/lib/media-types.d.ts +9 -0
  126. package/lib/media-types.js +26 -0
  127. package/lib/pubsub.js +42 -0
  128. package/lib/reference.d.ts +11 -0
  129. package/lib/reference.js +11 -0
  130. package/lib/schema.d.ts +64 -0
  131. package/lib/schema.js +308 -0
  132. package/package.json +31 -22
  133. package/{lib/draft-2020-12.d.ts → stable/index.d.ts} +26 -24
  134. package/stable/index.js +118 -0
  135. package/stable/meta/applicator.js +49 -0
  136. package/stable/meta/content.js +12 -0
  137. package/stable/meta/core.js +49 -0
  138. package/stable/meta/format-annotation.js +10 -0
  139. package/stable/meta/format-assertion.js +10 -0
  140. package/stable/meta/meta-data.js +16 -0
  141. package/stable/meta/unevaluated.js +11 -0
  142. package/stable/meta/validation.js +67 -0
  143. package/stable/validation.js +24 -0
  144. package/dist/json-schema-amd.js +0 -6602
  145. package/dist/json-schema-amd.js.map +0 -1
  146. package/dist/json-schema-amd.min.js +0 -3
  147. package/dist/json-schema-amd.min.js.map +0 -1
  148. package/dist/json-schema-cjs.js +0 -6600
  149. package/dist/json-schema-cjs.js.map +0 -1
  150. package/dist/json-schema-cjs.min.js +0 -3
  151. package/dist/json-schema-cjs.min.js.map +0 -1
  152. package/dist/json-schema-esm.js +0 -6596
  153. package/dist/json-schema-esm.js.map +0 -1
  154. package/dist/json-schema-esm.min.js +0 -3
  155. package/dist/json-schema-esm.min.js.map +0 -1
  156. package/dist/json-schema-iife.js +0 -6605
  157. package/dist/json-schema-iife.js.map +0 -1
  158. package/dist/json-schema-iife.min.js +0 -3
  159. package/dist/json-schema-iife.min.js.map +0 -1
  160. package/dist/json-schema-system.js +0 -6603
  161. package/dist/json-schema-system.js.map +0 -1
  162. package/dist/json-schema-system.min.js +0 -3
  163. package/dist/json-schema-system.min.js.map +0 -1
  164. package/dist/json-schema-umd.js +0 -6606
  165. package/dist/json-schema-umd.js.map +0 -1
  166. package/dist/json-schema-umd.min.js +0 -3
  167. package/dist/json-schema-umd.min.js.map +0 -1
  168. package/lib/draft-04.d.ts +0 -41
  169. package/lib/draft-04.js +0 -46
  170. package/lib/draft-06.d.ts +0 -45
  171. package/lib/draft-06.js +0 -51
  172. package/lib/draft-07.js +0 -55
  173. package/lib/draft-2019-09.js +0 -92
  174. package/lib/draft-2020-12.js +0 -103
  175. package/lib/index.mjs +0 -19
  176. package/lib/keywords/additionalItems.js +0 -27
  177. package/lib/keywords/additionalItems6.js +0 -23
  178. package/lib/keywords/additionalProperties6.js +0 -28
  179. package/lib/keywords/index.js +0 -53
  180. package/lib/keywords/items202012.js +0 -23
  181. package/lib/keywords/maximum-exclusiveMaximum.js +0 -20
  182. package/lib/keywords/minimum-exclusiveMinimum.js +0 -20
  183. package/lib/keywords/tupleItems.js +0 -24
  184. package/meta/draft/2019-09/meta/applicator.js +0 -55
  185. package/meta/draft/2019-09/meta/content.js +0 -17
  186. package/meta/draft/2019-09/meta/core.js +0 -57
  187. package/meta/draft/2019-09/meta/format.js +0 -14
  188. package/meta/draft/2019-09/meta/meta-data.js +0 -37
  189. package/meta/draft/2019-09/meta/validation.js +0 -98
  190. package/meta/draft/2019-09/schema.js +0 -42
  191. package/meta/draft/2020-12/meta/applicator.js +0 -49
  192. package/meta/draft/2020-12/meta/content.js +0 -17
  193. package/meta/draft/2020-12/meta/core.js +0 -57
  194. package/meta/draft/2020-12/meta/format-annotation.js +0 -14
  195. package/meta/draft/2020-12/meta/format-assertion.js +0 -14
  196. package/meta/draft/2020-12/meta/meta-data.js +0 -37
  197. package/meta/draft/2020-12/meta/unevaluated.js +0 -15
  198. package/meta/draft/2020-12/meta/validation.js +0 -98
  199. package/meta/draft/2020-12/schema.js +0 -44
  200. package/meta/draft-04/schema.js +0 -149
  201. package/meta/draft-06/schema.js +0 -154
  202. package/meta/draft-07/schema.js +0 -172
@@ -1,8 +1,11 @@
1
- const { Schema, Instance } = require("@hyperjump/json-schema-core");
2
- const jsonStringify = require("fastest-stable-stringify");
1
+ import jsonStringify from "fastest-stable-stringify";
2
+ import * as Schema from "../schema.js";
3
+ import * as Instance from "../instance.js";
3
4
 
4
5
 
6
+ const id = "https://json-schema.org/keyword/const";
7
+
5
8
  const compile = (schema) => jsonStringify(Schema.value(schema));
6
9
  const interpret = (const_, instance) => jsonStringify(Instance.value(instance)) === const_;
7
10
 
8
- module.exports = { compile, interpret };
11
+ export default { id, compile, interpret };
@@ -1,10 +1,53 @@
1
- const { Core, Instance } = require("@hyperjump/json-schema-core");
1
+ import * as Schema from "../schema.js";
2
+ import * as Instance from "../instance.js";
3
+ import { getKeywordName } from "../keywords.js";
4
+ import Validation from "./validation.js";
2
5
 
3
6
 
4
- const compile = (schema, ast) => Core.compileSchema(schema, ast);
7
+ const id = "https://json-schema.org/keyword/contains";
5
8
 
6
- const interpret = (contains, instance, ast, dynamicAnchors) => {
7
- return !Instance.typeOf(instance, "array") || Instance.some((item) => Core.interpretSchema(contains, item, ast, dynamicAnchors), instance);
9
+ const compile = async (schema, ast, parentSchema) => {
10
+ const contains = await Validation.compile(schema, ast);
11
+
12
+ const minContainsKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/minContains");
13
+ const minContainsSchema = await Schema.step(minContainsKeyword, parentSchema);
14
+ const minContains = Schema.typeOf(minContainsSchema, "number") ? Schema.value(minContainsSchema) : 1;
15
+
16
+ const maxContainsKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/maxContains");
17
+ const maxContainsSchema = await Schema.step(maxContainsKeyword, parentSchema);
18
+ const maxContains = Schema.typeOf(maxContainsSchema, "number") ? Schema.value(maxContainsSchema) : Number.MAX_SAFE_INTEGER;
19
+
20
+ return { contains, minContains, maxContains };
21
+ };
22
+
23
+ const interpret = ({ contains, minContains, maxContains }, instance, ast, dynamicAnchors) => {
24
+ if (!Instance.typeOf(instance, "array") && !Instance.typeOf(instance, "object")) {
25
+ return true;
26
+ }
27
+
28
+ const matches = Instance.entries(instance).reduce((matches, [, item]) => {
29
+ return Validation.interpret(contains, item, ast, dynamicAnchors) ? matches + 1 : matches;
30
+ }, 0);
31
+ return matches >= minContains && matches <= maxContains;
32
+ };
33
+
34
+ const collectEvaluatedItems = (keywordValue, instance, ast, dynamicAnchors) => {
35
+ return interpret(keywordValue, instance, ast, dynamicAnchors) &&
36
+ Instance.typeOf(instance, "array") &&
37
+ Instance.reduce((matchedIndexes, item, itemIndex) => {
38
+ return Validation.interpret(keywordValue.contains, item, ast, dynamicAnchors) ? matchedIndexes.add(itemIndex) : matchedIndexes;
39
+ }, new Set(), instance);
40
+ };
41
+
42
+ const collectEvaluatedProperties = (keywordValue, instance, ast, dynamicAnchors) => {
43
+ return interpret(keywordValue, instance, ast, dynamicAnchors) &&
44
+ Instance.typeOf(instance, "object") &&
45
+ Instance.entries(instance).reduce((matchedPropertyNames, [propertyName, item]) => {
46
+ if (Validation.interpret(keywordValue.contains, item, ast, dynamicAnchors)) {
47
+ matchedPropertyNames.push(propertyName);
48
+ }
49
+ return matchedPropertyNames;
50
+ }, [], instance);
8
51
  };
9
52
 
10
- module.exports = { compile, interpret };
53
+ export default { id, compile, interpret, collectEvaluatedItems, collectEvaluatedProperties };
@@ -0,0 +1,4 @@
1
+ import metaData from "./meta-data.js";
2
+
3
+
4
+ export default { id: "https://json-schema.org/keyword/contentEncoding", ...metaData };
@@ -0,0 +1,4 @@
1
+ import metaData from "./meta-data.js";
2
+
3
+
4
+ export default { id: "https://json-schema.org/keyword/contentMediaType", ...metaData };
@@ -0,0 +1,4 @@
1
+ import metaData from "./meta-data.js";
2
+
3
+
4
+ export default { id: "https://json-schema.org/keyword/contentSchema", ...metaData };
@@ -0,0 +1,4 @@
1
+ import metaData from "./meta-data.js";
2
+
3
+
4
+ export default { id: "https://json-schema.org/keyword/default", ...metaData };
@@ -1,15 +1,18 @@
1
- const { Core, Schema } = require("@hyperjump/json-schema-core");
2
- const Pact = require("@hyperjump/pact");
1
+ import * as Pact from "@hyperjump/pact";
2
+ import * as Schema from "../schema.js";
3
+ import Validation from "./validation.js";
3
4
 
4
5
 
6
+ const id = "https://json-schema.org/keyword/definitions";
7
+
5
8
  const compile = async (schema, ast) => {
6
9
  await Pact.pipeline([
7
10
  Schema.entries,
8
- Pact.map(([, definitionSchema]) => Core.compileSchema(definitionSchema, ast)),
11
+ Pact.map(([, definitionSchema]) => Validation.compile(definitionSchema, ast)),
9
12
  Pact.all
10
13
  ], schema);
11
14
  };
12
15
 
13
16
  const interpret = () => true;
14
17
 
15
- module.exports = { compile, interpret };
18
+ export default { id, compile, interpret };
@@ -1,7 +1,10 @@
1
- const { Schema, Instance } = require("@hyperjump/json-schema-core");
2
- const Pact = require("@hyperjump/pact");
1
+ import * as Pact from "@hyperjump/pact";
2
+ import * as Schema from "../schema.js";
3
+ import * as Instance from "../instance.js";
3
4
 
4
5
 
6
+ const id = "https://json-schema.org/keyword/dependentRequired";
7
+
5
8
  const compile = (schema) => Pact.pipeline([
6
9
  Schema.entries,
7
10
  Pact.map(([key, dependentRequired]) => [key, Schema.value(dependentRequired)]),
@@ -16,4 +19,4 @@ const interpret = (dependentRequired, instance) => {
16
19
  });
17
20
  };
18
21
 
19
- module.exports = { compile, interpret };
22
+ export default { id, compile, interpret };
@@ -1,10 +1,14 @@
1
- const { Core, Schema, Instance } = require("@hyperjump/json-schema-core");
2
- const Pact = require("@hyperjump/pact");
1
+ import * as Pact from "@hyperjump/pact";
2
+ import * as Schema from "../schema.js";
3
+ import * as Instance from "../instance.js";
4
+ import Validation from "./validation.js";
3
5
 
4
6
 
7
+ const id = "https://json-schema.org/keyword/dependentSchemas";
8
+
5
9
  const compile = (schema, ast) => Pact.pipeline([
6
10
  Schema.entries,
7
- Pact.map(async ([key, dependentSchema]) => [key, await Core.compileSchema(dependentSchema, ast)]),
11
+ Pact.map(async ([key, dependentSchema]) => [key, await Validation.compile(dependentSchema, ast)]),
8
12
  Pact.all
9
13
  ], schema);
10
14
 
@@ -12,7 +16,7 @@ const interpret = (dependentSchemas, instance, ast, dynamicAnchors) => {
12
16
  const value = Instance.value(instance);
13
17
 
14
18
  return !Instance.typeOf(instance, "object") || dependentSchemas.every(([propertyName, dependentSchema]) => {
15
- return !(propertyName in value) || Core.interpretSchema(dependentSchema, instance, ast, dynamicAnchors);
19
+ return !(propertyName in value) || Validation.interpret(dependentSchema, instance, ast, dynamicAnchors);
16
20
  });
17
21
  };
18
22
 
@@ -22,9 +26,9 @@ const collectEvaluatedProperties = (dependentSchemas, instance, ast, dynamicAnch
22
26
  return acc;
23
27
  }
24
28
 
25
- const propertyNames = Core.collectEvaluatedProperties(dependentSchema, instance, ast, dynamicAnchors);
29
+ const propertyNames = Validation.collectEvaluatedProperties(dependentSchema, instance, ast, dynamicAnchors);
26
30
  return propertyNames !== false && acc.concat(propertyNames);
27
31
  }, []);
28
32
  };
29
33
 
30
- module.exports = { compile, interpret, collectEvaluatedProperties };
34
+ export default { id, compile, interpret, collectEvaluatedProperties };
@@ -0,0 +1,4 @@
1
+ import metaData from "./meta-data.js";
2
+
3
+
4
+ export default { id: "https://json-schema.org/keyword/deprecated", ...metaData };
@@ -0,0 +1,4 @@
1
+ import metaData from "./meta-data.js";
2
+
3
+
4
+ export default { id: "https://json-schema.org/keyword/description", ...metaData };
@@ -0,0 +1 @@
1
+ export default { id: "https://json-schema.org/keyword/dynamicAnchor" };
@@ -1,24 +1,20 @@
1
- const { Core, Schema } = require("@hyperjump/json-schema-core");
2
- const { splitUrl } = require("../common");
1
+ import * as Schema from "../schema.js";
2
+ import Validation from "./validation.js";
3
3
 
4
4
 
5
- const compile = async (dynamicRef, ast) => {
6
- const [, fragment] = splitUrl(Schema.value(dynamicRef));
7
- const referencedSchema = await Schema.get(Schema.value(dynamicRef), dynamicRef);
8
- await Core.compileSchema(referencedSchema, ast);
9
- return [referencedSchema.id, fragment];
10
- };
5
+ const id = "https://json-schema.org/keyword/dynamicRef";
6
+ const experimental = true;
7
+
8
+ const compile = Schema.value;
11
9
 
12
- const interpret = ([id, fragment], instance, ast, dynamicAnchors) => {
13
- if (fragment in ast.metaData[id].dynamicAnchors) {
14
- return Core.interpretSchema(dynamicAnchors[fragment], instance, ast, dynamicAnchors);
15
- } else {
16
- const pointer = Schema.getAnchorPointer(ast.metaData[id], fragment);
17
- return Core.interpretSchema(`${id}#${encodeURI(pointer)}`, instance, ast, dynamicAnchors);
10
+ const interpret = (fragment, instance, ast, dynamicAnchors) => {
11
+ if (!(fragment in dynamicAnchors)) {
12
+ throw Error(`No dynamic anchor found for "${fragment}"`);
18
13
  }
14
+ return Validation.interpret(dynamicAnchors[fragment], instance, ast, dynamicAnchors);
19
15
  };
20
16
 
21
- const collectEvaluatedProperties = Core.collectEvaluatedProperties;
22
- const collectEvaluatedItems = Core.collectEvaluatedItems;
17
+ const collectEvaluatedProperties = Validation.collectEvaluatedProperties;
18
+ const collectEvaluatedItems = Validation.collectEvaluatedItems;
23
19
 
24
- module.exports = { compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
20
+ export default { id, experimental, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
@@ -1,26 +1,31 @@
1
- const { Core, Schema } = require("@hyperjump/json-schema-core");
1
+ import * as Schema from "../schema.js";
2
+ import { getKeywordName, getKeyword } from "../keywords.js";
3
+ import Validation from "./validation.js";
2
4
 
3
5
 
6
+ const id = "https://json-schema.org/keyword/else";
7
+
4
8
  const compile = async (schema, ast, parentSchema) => {
5
- if (Schema.has("if", parentSchema)) {
6
- const ifSchema = await Schema.step("if", parentSchema);
7
- return [await Core.compileSchema(ifSchema, ast), await Core.compileSchema(schema, ast)];
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);
12
+ return [await Validation.compile(ifSchema, ast), await Validation.compile(schema, ast)];
8
13
  } else {
9
14
  return [];
10
15
  }
11
16
  };
12
17
 
13
18
  const interpret = ([guard, block], instance, ast, dynamicAnchors) => {
14
- return guard === undefined || quietInterpretSchema(guard, instance, ast, dynamicAnchors) || Core.interpretSchema(block, instance, ast, dynamicAnchors);
19
+ return guard === undefined || quietInterpretSchema(guard, instance, ast, dynamicAnchors) || Validation.interpret(block, instance, ast, dynamicAnchors);
15
20
  };
16
21
 
17
22
  // Interpret a schema without events being emitted
18
- const quietInterpretSchema = (uri, instance, ast, dynamicAnchors) => {
19
- const nodes = ast[uri][2];
23
+ const quietInterpretSchema = (url, instance, ast, dynamicAnchors) => {
24
+ const nodes = ast[url][2];
20
25
 
21
26
  return typeof nodes === "boolean" ? nodes : nodes
22
27
  .every(([keywordId, , keywordValue]) => {
23
- return Core.getKeyword(keywordId).interpret(keywordValue, instance, ast, dynamicAnchors);
28
+ return getKeyword(keywordId).interpret(keywordValue, instance, ast, dynamicAnchors);
24
29
  });
25
30
  };
26
31
 
@@ -29,7 +34,7 @@ const collectEvaluatedProperties = ([guard, block], instance, ast, dynamicAnchor
29
34
  return [];
30
35
  }
31
36
 
32
- return Core.collectEvaluatedProperties(block, instance, ast, dynamicAnchors);
37
+ return Validation.collectEvaluatedProperties(block, instance, ast, dynamicAnchors);
33
38
  };
34
39
 
35
40
  const collectEvaluatedItems = ([guard, block], instance, ast, dynamicAnchors) => {
@@ -37,7 +42,7 @@ const collectEvaluatedItems = ([guard, block], instance, ast, dynamicAnchors) =>
37
42
  return new Set();
38
43
  }
39
44
 
40
- return Core.collectEvaluatedItems(block, instance, ast, dynamicAnchors);
45
+ return Validation.collectEvaluatedItems(block, instance, ast, dynamicAnchors);
41
46
  };
42
47
 
43
- module.exports = { compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
48
+ export default { id, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
@@ -1,8 +1,11 @@
1
- const { Schema, Instance } = require("@hyperjump/json-schema-core");
2
- const jsonStringify = require("fastest-stable-stringify");
1
+ import jsonStringify from "fastest-stable-stringify";
2
+ import * as Schema from "../schema.js";
3
+ import * as Instance from "../instance.js";
3
4
 
4
5
 
6
+ const id = "https://json-schema.org/keyword/enum";
7
+
5
8
  const compile = (schema) => Schema.value(schema).map(jsonStringify);
6
9
  const interpret = (enum_, instance) => enum_.some((enumValue) => jsonStringify(Instance.value(instance)) === enumValue);
7
10
 
8
- module.exports = { compile, interpret };
11
+ export default { id, compile, interpret };
@@ -0,0 +1,4 @@
1
+ import metaData from "./meta-data.js";
2
+
3
+
4
+ export default { id: "https://json-schema.org/keyword/examples", ...metaData };
@@ -1,7 +1,10 @@
1
- const { Schema, Instance } = require("@hyperjump/json-schema-core");
1
+ import * as Schema from "../schema.js";
2
+ import * as Instance from "../instance.js";
2
3
 
3
4
 
5
+ const id = "https://json-schema.org/keyword/exclusiveMaximum";
6
+
4
7
  const compile = async (schema) => Schema.value(schema);
5
8
  const interpret = (exclusiveMaximum, instance) => !Instance.typeOf(instance, "number") || Instance.value(instance) < exclusiveMaximum;
6
9
 
7
- module.exports = { compile, interpret };
10
+ export default { id, compile, interpret };
@@ -1,7 +1,10 @@
1
- const { Schema, Instance } = require("@hyperjump/json-schema-core");
1
+ import * as Schema from "../schema.js";
2
+ import * as Instance from "../instance.js";
2
3
 
3
4
 
5
+ const id = "https://json-schema.org/keyword/exclusiveMinimum";
6
+
4
7
  const compile = async (schema) => Schema.value(schema);
5
8
  const interpret = (exclusiveMinimum, instance) => !Instance.typeOf(instance, "number") || Instance.value(instance) > exclusiveMinimum;
6
9
 
7
- module.exports = { compile, interpret };
10
+ export default { id, compile, interpret };
@@ -0,0 +1,4 @@
1
+ import metaData from "./meta-data.js";
2
+
3
+
4
+ export default { id: "https://json-schema.org/keyword/format", ...metaData };
@@ -0,0 +1 @@
1
+ export default { id: "https://json-schema.org/keyword/id" };
@@ -1,19 +1,21 @@
1
- const { Core } = require("@hyperjump/json-schema-core");
1
+ import Validation from "./validation.js";
2
2
 
3
3
 
4
- const compile = (schema, ast) => Core.compileSchema(schema, ast);
4
+ const id = "https://json-schema.org/keyword/if";
5
+
6
+ const compile = (schema, ast) => Validation.compile(schema, ast);
5
7
 
6
8
  const interpret = (ifSchema, instance, ast, dynamicAnchors) => {
7
- Core.interpretSchema(ifSchema, instance, ast, dynamicAnchors);
9
+ Validation.interpret(ifSchema, instance, ast, dynamicAnchors);
8
10
  return true;
9
11
  };
10
12
 
11
13
  const collectEvaluatedProperties = (ifSchema, instance, ast, dynamicAnchors) => {
12
- return Core.collectEvaluatedProperties(ifSchema, instance, ast, dynamicAnchors) || [];
14
+ return Validation.collectEvaluatedProperties(ifSchema, instance, ast, dynamicAnchors) || [];
13
15
  };
14
16
 
15
17
  const collectEvaluatedItems = (ifSchema, instance, ast, dynamicAnchors) => {
16
- return Core.collectEvaluatedItems(ifSchema, instance, ast, dynamicAnchors) || new Set();
18
+ return Validation.collectEvaluatedItems(ifSchema, instance, ast, dynamicAnchors) || new Set();
17
19
  };
18
20
 
19
- module.exports = { compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
21
+ export default { id, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
@@ -1,31 +1,29 @@
1
- const { Core, Schema, Instance } = require("@hyperjump/json-schema-core");
1
+ import * as Schema from "../schema.js";
2
+ import * as Instance from "../instance.js";
3
+ import { getKeywordName } from "../keywords.js";
4
+ import Validation from "./validation.js";
2
5
 
3
6
 
4
- const compile = async (schema, ast) => {
5
- if (Schema.typeOf(schema, "array")) {
6
- const tupleItems = await Schema.map((itemSchema) => Core.compileSchema(itemSchema, ast), schema);
7
- return Promise.all(tupleItems);
8
- } else {
9
- return Core.compileSchema(schema, ast);
10
- }
7
+ const id = "https://json-schema.org/keyword/items";
8
+
9
+ const compile = async (schema, ast, parentSchema) => {
10
+ const prefixItemKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/prefixItems");
11
+ const items = await Schema.step(prefixItemKeyword, parentSchema);
12
+ const numberOfPrefixItems = Schema.typeOf(items, "array") ? Schema.length(items) : 0;
13
+
14
+ return [numberOfPrefixItems, await Validation.compile(schema, ast)];
11
15
  };
12
16
 
13
- const interpret = (items, instance, ast, dynamicAnchors) => {
17
+ const interpret = ([numberOfPrefixItems, items], instance, ast, dynamicAnchors) => {
14
18
  if (!Instance.typeOf(instance, "array")) {
15
19
  return true;
16
20
  }
17
21
 
18
- if (typeof items === "string") {
19
- return Instance.every((itemValue) => Core.interpretSchema(items, itemValue, ast, dynamicAnchors), instance);
20
- } else {
21
- return Instance.every((item, ndx) => !(ndx in items) || Core.interpretSchema(items[ndx], item, ast, dynamicAnchors), instance);
22
- }
22
+ return Instance.every((item, ndx) => ndx < numberOfPrefixItems || Validation.interpret(items, item, ast, dynamicAnchors), instance);
23
23
  };
24
24
 
25
- const collectEvaluatedItems = (items, instance, ast, dynamicAnchors) => {
26
- return interpret(items, instance, ast, dynamicAnchors) && (typeof items === "string"
27
- ? new Set(Instance.map((item, itemIndex) => itemIndex, instance))
28
- : new Set(items.map((item, itemIndex) => itemIndex)));
25
+ const collectEvaluatedItems = (keywordValue, instance, ast, dynamicAnchors) => {
26
+ return interpret(keywordValue, instance, ast, dynamicAnchors) && new Set(Instance.map((item, ndx) => ndx, instance));
29
27
  };
30
28
 
31
- module.exports = { compile, interpret, collectEvaluatedItems };
29
+ export default { id, compile, interpret, collectEvaluatedItems };
@@ -0,0 +1,4 @@
1
+ import metaData from "./meta-data.js";
2
+
3
+
4
+ export default { id: "https://json-schema.org/keyword/maxContains", ...metaData };
@@ -1,7 +1,10 @@
1
- const { Schema, Instance } = require("@hyperjump/json-schema-core");
1
+ import * as Schema from "../schema.js";
2
+ import * as Instance from "../instance.js";
2
3
 
3
4
 
5
+ const id = "https://json-schema.org/keyword/maxItems";
6
+
4
7
  const compile = (schema) => Schema.value(schema);
5
8
  const interpret = (maxItems, instance) => !Instance.typeOf(instance, "array") || Instance.length(instance) <= maxItems;
6
9
 
7
- module.exports = { compile, interpret };
10
+ export default { id, compile, interpret };
@@ -1,7 +1,10 @@
1
- const { Schema, Instance } = require("@hyperjump/json-schema-core");
1
+ import * as Schema from "../schema.js";
2
+ import * as Instance from "../instance.js";
2
3
 
3
4
 
5
+ const id = "https://json-schema.org/keyword/maxLength";
6
+
4
7
  const compile = (schema) => Schema.value(schema);
5
8
  const interpret = (maxLength, instance) => !Instance.typeOf(instance, "string") || [...Instance.value(instance)].length <= maxLength;
6
9
 
7
- module.exports = { compile, interpret };
10
+ export default { id, compile, interpret };
@@ -1,7 +1,10 @@
1
- const { Schema, Instance } = require("@hyperjump/json-schema-core");
1
+ import * as Schema from "../schema.js";
2
+ import * as Instance from "../instance.js";
2
3
 
3
4
 
5
+ const id = "https://json-schema.org/keyword/maxProperties";
6
+
4
7
  const compile = (schema) => Schema.value(schema);
5
8
  const interpret = (maxProperties, instance) => !Instance.typeOf(instance, "object") || Instance.keys(instance).length <= maxProperties;
6
9
 
7
- module.exports = { compile, interpret };
10
+ export default { id, compile, interpret };
@@ -1,7 +1,10 @@
1
- const { Schema, Instance } = require("@hyperjump/json-schema-core");
1
+ import * as Schema from "../schema.js";
2
+ import * as Instance from "../instance.js";
2
3
 
3
4
 
5
+ const id = "https://json-schema.org/keyword/maximum";
6
+
4
7
  const compile = async (schema) => Schema.value(schema);
5
8
  const interpret = (maximum, instance) => !Instance.typeOf(instance, "number") || Instance.value(instance) <= maximum;
6
9
 
7
- module.exports = { compile, interpret };
10
+ export default { id, compile, interpret };
@@ -0,0 +1,4 @@
1
+ const compile = (schema) => schema.value;
2
+ const interpret = () => true;
3
+
4
+ export default { compile, interpret };
@@ -0,0 +1,4 @@
1
+ import metaData from "./meta-data.js";
2
+
3
+
4
+ export default { id: "https://json-schema.org/keyword/minContains", ...metaData };
@@ -1,7 +1,10 @@
1
- const { Schema, Instance } = require("@hyperjump/json-schema-core");
1
+ import * as Schema from "../schema.js";
2
+ import * as Instance from "../instance.js";
2
3
 
3
4
 
5
+ const id = "https://json-schema.org/keyword/minItems";
6
+
4
7
  const compile = (schema) => Schema.value(schema);
5
8
  const interpret = (minItems, instance) => !Instance.typeOf(instance, "array") || Instance.length(instance) >= minItems;
6
9
 
7
- module.exports = { compile, interpret };
10
+ export default { id, compile, interpret };
@@ -1,7 +1,10 @@
1
- const { Schema, Instance } = require("@hyperjump/json-schema-core");
1
+ import * as Schema from "../schema.js";
2
+ import * as Instance from "../instance.js";
2
3
 
3
4
 
5
+ const id = "https://json-schema.org/keyword/minLength";
6
+
4
7
  const compile = (schema) => Schema.value(schema);
5
8
  const interpret = (minLength, instance) => !Instance.typeOf(instance, "string") || [...Instance.value(instance)].length >= minLength;
6
9
 
7
- module.exports = { compile, interpret };
10
+ export default { id, compile, interpret };
@@ -1,7 +1,10 @@
1
- const { Schema, Instance } = require("@hyperjump/json-schema-core");
1
+ import * as Schema from "../schema.js";
2
+ import * as Instance from "../instance.js";
2
3
 
3
4
 
5
+ const id = "https://json-schema.org/keyword/minProperties";
6
+
4
7
  const compile = (schema) => Schema.value(schema);
5
8
  const interpret = (minProperties, instance) => !Instance.typeOf(instance, "object") || Instance.keys(instance).length >= minProperties;
6
9
 
7
- module.exports = { compile, interpret };
10
+ export default { id, compile, interpret };
@@ -1,7 +1,10 @@
1
- const { Schema, Instance } = require("@hyperjump/json-schema-core");
1
+ import * as Schema from "../schema.js";
2
+ import * as Instance from "../instance.js";
2
3
 
3
4
 
5
+ const id = "https://json-schema.org/keyword/minimum";
6
+
4
7
  const compile = async (schema) => Schema.value(schema);
5
8
  const interpret = (minimum, instance) => !Instance.typeOf(instance, "number") || Instance.value(instance) >= minimum;
6
9
 
7
- module.exports = { compile, interpret };
10
+ export default { id, compile, interpret };
@@ -1,6 +1,9 @@
1
- const { Schema, Instance } = require("@hyperjump/json-schema-core");
1
+ import * as Schema from "../schema.js";
2
+ import * as Instance from "../instance.js";
2
3
 
3
4
 
5
+ const id = "https://json-schema.org/keyword/multipleOf";
6
+
4
7
  const compile = (schema) => Schema.value(schema);
5
8
 
6
9
  const interpret = (multipleOf, instance) => {
@@ -14,4 +17,4 @@ const interpret = (multipleOf, instance) => {
14
17
 
15
18
  const numberEqual = (a, b) => Math.abs(a - b) < 1.19209290e-7;
16
19
 
17
- module.exports = { compile, interpret };
20
+ export default { id, compile, interpret };
@@ -1,7 +1,9 @@
1
- const { Core } = require("@hyperjump/json-schema-core");
1
+ import Validation from "./validation.js";
2
2
 
3
3
 
4
- const compile = Core.compileSchema;
5
- const interpret = (not, instance, ast, dynamicAnchors) => !Core.interpretSchema(not, instance, ast, dynamicAnchors);
4
+ const id = "https://json-schema.org/keyword/not";
6
5
 
7
- module.exports = { compile, interpret };
6
+ const compile = Validation.compile;
7
+ const interpret = (not, instance, ast, dynamicAnchors) => !Validation.interpret(not, instance, ast, dynamicAnchors);
8
+
9
+ export default { id, compile, interpret };