@hyperjump/json-schema 0.23.4 → 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 -6644
  145. package/dist/json-schema-amd.js.map +0 -1
  146. package/dist/json-schema-amd.min.js +0 -2
  147. package/dist/json-schema-amd.min.js.map +0 -1
  148. package/dist/json-schema-cjs.js +0 -6642
  149. package/dist/json-schema-cjs.js.map +0 -1
  150. package/dist/json-schema-cjs.min.js +0 -2
  151. package/dist/json-schema-cjs.min.js.map +0 -1
  152. package/dist/json-schema-esm.js +0 -6638
  153. package/dist/json-schema-esm.js.map +0 -1
  154. package/dist/json-schema-esm.min.js +0 -2
  155. package/dist/json-schema-esm.min.js.map +0 -1
  156. package/dist/json-schema-iife.js +0 -6647
  157. package/dist/json-schema-iife.js.map +0 -1
  158. package/dist/json-schema-iife.min.js +0 -2
  159. package/dist/json-schema-iife.min.js.map +0 -1
  160. package/dist/json-schema-system.js +0 -6645
  161. package/dist/json-schema-system.js.map +0 -1
  162. package/dist/json-schema-system.min.js +0 -2
  163. package/dist/json-schema-system.min.js.map +0 -1
  164. package/dist/json-schema-umd.js +0 -6648
  165. package/dist/json-schema-umd.js.map +0 -1
  166. package/dist/json-schema-umd.min.js +0 -2
  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
@@ -0,0 +1,29 @@
1
+ import * as Instance from "../lib/instance.js";
2
+ import * as Schema from "../lib/schema.js";
3
+ import Validation from "../lib/keywords/validation.js";
4
+ import { getKeywordName } from "../lib/keywords.js";
5
+
6
+
7
+ const id = "https://json-schema.org/keyword/draft-04/additionalItems";
8
+
9
+ const compile = async (schema, ast, parentSchema) => {
10
+ const itemsKeywordName = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/draft-04/items");
11
+ const items = await Schema.step(itemsKeywordName, parentSchema);
12
+ const numberOfItems = Schema.typeOf(items, "array") ? Schema.length(items) : Number.MAX_SAFE_INTEGER;
13
+
14
+ return [numberOfItems, await Validation.compile(schema, ast)];
15
+ };
16
+
17
+ const interpret = ([numberOfItems, additionalItems], instance, ast, dynamicAnchors) => {
18
+ if (!Instance.typeOf(instance, "array")) {
19
+ return true;
20
+ }
21
+
22
+ return Instance.every((item, ndx) => ndx < numberOfItems || Validation.interpret(additionalItems, item, ast, dynamicAnchors), instance);
23
+ };
24
+
25
+ const collectEvaluatedItems = (keywordValue, instance, ast, dynamicAnchors) => {
26
+ return interpret(keywordValue, instance, ast, dynamicAnchors) && new Set(Instance.map((item, ndx) => ndx, instance));
27
+ };
28
+
29
+ export default { id, compile, interpret, collectEvaluatedItems };
@@ -1,11 +1,15 @@
1
- const { Core, Schema, Instance } = require("@hyperjump/json-schema-core");
2
- const Pact = require("@hyperjump/pact");
1
+ import * as Instance from "../lib/instance.js";
2
+ import * as Schema from "../lib/schema.js";
3
+ import Validation from "../lib/keywords/validation.js";
4
+ import * as Pact from "@hyperjump/pact";
3
5
 
4
6
 
7
+ const id = "https://json-schema.org/keyword/draft-04/dependencies";
8
+
5
9
  const compile = (schema, ast) => Pact.pipeline([
6
10
  Schema.entries,
7
11
  Pact.map(async ([key, dependency]) => {
8
- return [key, Schema.typeOf(dependency, "array") ? Schema.value(dependency) : await Core.compileSchema(dependency, ast)];
12
+ return [key, Schema.typeOf(dependency, "array") ? Schema.value(dependency) : await Validation.compile(dependency, ast)];
9
13
  }),
10
14
  Pact.all
11
15
  ], schema);
@@ -21,9 +25,9 @@ const interpret = (dependencies, instance, ast, dynamicAnchors) => {
21
25
  if (Array.isArray(dependency)) {
22
26
  return dependency.every((key) => key in value);
23
27
  } else {
24
- return Core.interpretSchema(dependency, instance, ast, dynamicAnchors);
28
+ return Validation.interpret(dependency, instance, ast, dynamicAnchors);
25
29
  }
26
30
  });
27
31
  };
28
32
 
29
- module.exports = { compile, interpret };
33
+ export default { id, compile, interpret };
@@ -0,0 +1,5 @@
1
+ const id = "https://json-schema.org/keyword/draft-04/exclusiveMaximum";
2
+ const compile = (schema) => schema.value;
3
+ const interpret = () => true;
4
+
5
+ export default { id, compile, interpret };
@@ -0,0 +1,5 @@
1
+ const id = "https://json-schema.org/keyword/draft-04/exclusiveMinimum";
2
+ const compile = (schema) => schema.value;
3
+ const interpret = () => true;
4
+
5
+ export default { id, compile, interpret };
package/draft-04/id.js ADDED
@@ -0,0 +1 @@
1
+ export default { id: "https://json-schema.org/keyword/draft-04/id" };
@@ -0,0 +1,43 @@
1
+ import type { Json } from "@hyperjump/json-pointer";
2
+ import type { JsonSchemaType } from "../lib/common.js";
3
+
4
+
5
+ export type JsonSchemaDraft04 = {
6
+ $ref: string;
7
+ } | {
8
+ $schema?: "http://json-schema.org/draft-04/schema#";
9
+ id?: string;
10
+ title?: string;
11
+ description?: string;
12
+ default?: Json;
13
+ multipleOf?: number;
14
+ maximum?: number;
15
+ exclusiveMaximum?: boolean;
16
+ minimum?: number;
17
+ exclusiveMinimum?: boolean;
18
+ maxLength?: number;
19
+ minLength?: number;
20
+ pattern?: string;
21
+ additionalItems?: boolean | JsonSchemaDraft04;
22
+ items?: JsonSchemaDraft04 | JsonSchemaDraft04[];
23
+ maxItems?: number;
24
+ minItems?: number;
25
+ uniqueItems?: boolean;
26
+ maxProperties?: number;
27
+ minProperties?: number;
28
+ required?: string[];
29
+ additionalProperties?: boolean | JsonSchemaDraft04;
30
+ definitions?: Record<string, JsonSchemaDraft04>;
31
+ properties?: Record<string, JsonSchemaDraft04>;
32
+ patternProperties?: Record<string, JsonSchemaDraft04>;
33
+ dependencies?: Record<string, JsonSchemaDraft04 | string[]>;
34
+ enum?: Json[];
35
+ type?: JsonSchemaType | JsonSchemaType[];
36
+ format?: "date-time" | "email" | "hostname" | "ipv4" | "ipv6" | "uri";
37
+ allOf?: JsonSchemaDraft04[];
38
+ anyOf?: JsonSchemaDraft04[];
39
+ oneOf?: JsonSchemaDraft04[];
40
+ not?: JsonSchemaDraft04;
41
+ };
42
+
43
+ export * from "../lib/index.js";
@@ -0,0 +1,69 @@
1
+ import { addKeyword, defineVocabulary, loadDialect } from "../lib/keywords.js";
2
+ import { addSchema } from "../lib/core.js";
3
+ import metaSchema from "./schema.js";
4
+ import additionalItems from "./additionalItems.js";
5
+ import dependencies from "./dependencies.js";
6
+ import exclusiveMaximum from "./exclusiveMaximum.js";
7
+ import exclusiveMinimum from "./exclusiveMinimum.js";
8
+ import id from "./id.js";
9
+ import items from "./items.js";
10
+ import maximum from "./maximum.js";
11
+ import minimum from "./minimum.js";
12
+ import ref from "./ref.js";
13
+
14
+
15
+ addKeyword(additionalItems);
16
+ addKeyword(dependencies);
17
+ addKeyword(exclusiveMaximum);
18
+ addKeyword(exclusiveMinimum);
19
+ addKeyword(maximum);
20
+ addKeyword(minimum);
21
+ addKeyword(id);
22
+ addKeyword(items);
23
+ addKeyword(ref);
24
+
25
+ const jsonSchemaVersion = "http://json-schema.org/draft-04/schema";
26
+
27
+ defineVocabulary(jsonSchemaVersion, {
28
+ "id": "https://json-schema.org/keyword/draft-04/id",
29
+ "$ref": "https://json-schema.org/keyword/draft-04/ref",
30
+ "additionalItems": "https://json-schema.org/keyword/draft-04/additionalItems",
31
+ "additionalProperties": "https://json-schema.org/keyword/additionalProperties",
32
+ "allOf": "https://json-schema.org/keyword/allOf",
33
+ "anyOf": "https://json-schema.org/keyword/anyOf",
34
+ "default": "https://json-schema.org/keyword/default",
35
+ "definitions": "https://json-schema.org/keyword/definitions",
36
+ "dependencies": "https://json-schema.org/keyword/draft-04/dependencies",
37
+ "description": "https://json-schema.org/keyword/description",
38
+ "enum": "https://json-schema.org/keyword/enum",
39
+ "exclusiveMaximum": "https://json-schema.org/keyword/draft-04/exclusiveMaximum",
40
+ "exclusiveMinimum": "https://json-schema.org/keyword/draft-04/exclusiveMinimum",
41
+ "format": "https://json-schema.org/keyword/format",
42
+ "items": "https://json-schema.org/keyword/draft-04/items",
43
+ "maxItems": "https://json-schema.org/keyword/maxItems",
44
+ "maxLength": "https://json-schema.org/keyword/maxLength",
45
+ "maxProperties": "https://json-schema.org/keyword/maxProperties",
46
+ "maximum": "https://json-schema.org/keyword/draft-04/maximum",
47
+ "minItems": "https://json-schema.org/keyword/minItems",
48
+ "minLength": "https://json-schema.org/keyword/minLength",
49
+ "minProperties": "https://json-schema.org/keyword/minProperties",
50
+ "minimum": "https://json-schema.org/keyword/draft-04/minimum",
51
+ "multipleOf": "https://json-schema.org/keyword/multipleOf",
52
+ "not": "https://json-schema.org/keyword/not",
53
+ "oneOf": "https://json-schema.org/keyword/oneOf",
54
+ "pattern": "https://json-schema.org/keyword/pattern",
55
+ "patternProperties": "https://json-schema.org/keyword/patternProperties",
56
+ "properties": "https://json-schema.org/keyword/properties",
57
+ "required": "https://json-schema.org/keyword/required",
58
+ "title": "https://json-schema.org/keyword/title",
59
+ "type": "https://json-schema.org/keyword/type",
60
+ "uniqueItems": "https://json-schema.org/keyword/uniqueItems"
61
+ });
62
+
63
+ loadDialect(jsonSchemaVersion, {
64
+ [jsonSchemaVersion]: true
65
+ }, true);
66
+
67
+ addSchema(metaSchema);
68
+
69
+ export * from "../lib/index.js";
@@ -0,0 +1,35 @@
1
+ import * as Instance from "../lib/instance.js";
2
+ import * as Schema from "../lib/schema.js";
3
+ import Validation from "../lib/keywords/validation.js";
4
+
5
+
6
+ const id = "https://json-schema.org/keyword/draft-04/items";
7
+
8
+ const compile = async (schema, ast) => {
9
+ if (Schema.typeOf(schema, "array")) {
10
+ const tupleItems = await Schema.map((itemSchema) => Validation.compile(itemSchema, ast), schema);
11
+ return Promise.all(tupleItems);
12
+ } else {
13
+ return Validation.compile(schema, ast);
14
+ }
15
+ };
16
+
17
+ const interpret = (items, instance, ast, dynamicAnchors) => {
18
+ if (!Instance.typeOf(instance, "array")) {
19
+ return true;
20
+ }
21
+
22
+ if (typeof items === "string") {
23
+ return Instance.every((itemValue) => Validation.interpret(items, itemValue, ast, dynamicAnchors), instance);
24
+ } else {
25
+ return Instance.every((item, ndx) => !(ndx in items) || Validation.interpret(items[ndx], item, ast, dynamicAnchors), instance);
26
+ }
27
+ };
28
+
29
+ const collectEvaluatedItems = (items, instance, ast, dynamicAnchors) => {
30
+ return interpret(items, instance, ast, dynamicAnchors) && (typeof items === "string"
31
+ ? new Set(Instance.map((item, itemIndex) => itemIndex, instance))
32
+ : new Set(items.map((item, itemIndex) => itemIndex)));
33
+ };
34
+
35
+ export default { id, compile, interpret, collectEvaluatedItems };
@@ -0,0 +1,26 @@
1
+ import * as Instance from "../lib/instance.js";
2
+ import * as Schema from "../lib/schema.js";
3
+ import { getKeywordName } from "../lib/keywords.js";
4
+
5
+
6
+ const id = "https://json-schema.org/keyword/draft-04/maximum";
7
+
8
+ const compile = async (schema, ast, parentSchema) => {
9
+ const exclusiveMaximumKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/draft-04/exclusiveMaximum");
10
+ console.log(exclusiveMaximumKeyword);
11
+ const exclusiveMaximum = await Schema.step(exclusiveMaximumKeyword, parentSchema);
12
+ const isExclusive = Schema.value(exclusiveMaximum);
13
+
14
+ return [Schema.value(schema), isExclusive];
15
+ };
16
+
17
+ const interpret = ([maximum, isExclusive], instance) => {
18
+ if (!Instance.typeOf(instance, "number")) {
19
+ return true;
20
+ }
21
+
22
+ const value = Instance.value(instance);
23
+ return isExclusive ? value < maximum : value <= maximum;
24
+ };
25
+
26
+ export default { id, compile, interpret };
@@ -0,0 +1,25 @@
1
+ import * as Instance from "../lib/instance.js";
2
+ import * as Schema from "../lib/schema.js";
3
+ import { getKeywordName } from "../lib/keywords.js";
4
+
5
+
6
+ const id = "https://json-schema.org/keyword/draft-04/minimum";
7
+
8
+ const compile = async (schema, ast, parentSchema) => {
9
+ const exclusiveMinimumKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/draft-04/exclusiveMinimum");
10
+ const exclusiveMinimum = await Schema.step(exclusiveMinimumKeyword, parentSchema);
11
+ const isExclusive = Schema.value(exclusiveMinimum);
12
+
13
+ return [Schema.value(schema), isExclusive];
14
+ };
15
+
16
+ const interpret = ([minimum, isExclusive], instance) => {
17
+ if (!Instance.typeOf(instance, "number")) {
18
+ return true;
19
+ }
20
+
21
+ const value = Instance.value(instance);
22
+ return isExclusive ? value > minimum : value >= minimum;
23
+ };
24
+
25
+ export default { id, compile, interpret };
@@ -0,0 +1 @@
1
+ export default { id: "https://json-schema.org/keyword/draft-04/ref" };
@@ -0,0 +1,149 @@
1
+ export default {
2
+ "id": "http://json-schema.org/draft-04/schema#",
3
+ "$schema": "http://json-schema.org/draft-04/schema#",
4
+ "description": "Core schema meta-schema",
5
+ "definitions": {
6
+ "schemaArray": {
7
+ "type": "array",
8
+ "minItems": 1,
9
+ "items": { "$ref": "#" }
10
+ },
11
+ "positiveInteger": {
12
+ "type": "integer",
13
+ "minimum": 0
14
+ },
15
+ "positiveIntegerDefault0": {
16
+ "allOf": [{ "$ref": "#/definitions/positiveInteger" }, { "default": 0 }]
17
+ },
18
+ "simpleTypes": {
19
+ "enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
20
+ },
21
+ "stringArray": {
22
+ "type": "array",
23
+ "items": { "type": "string" },
24
+ "minItems": 1,
25
+ "uniqueItems": true
26
+ }
27
+ },
28
+ "type": "object",
29
+ "properties": {
30
+ "id": {
31
+ "type": "string"
32
+ },
33
+ "$schema": {
34
+ "type": "string"
35
+ },
36
+ "title": {
37
+ "type": "string"
38
+ },
39
+ "description": {
40
+ "type": "string"
41
+ },
42
+ "default": {},
43
+ "multipleOf": {
44
+ "type": "number",
45
+ "minimum": 0,
46
+ "exclusiveMinimum": true
47
+ },
48
+ "maximum": {
49
+ "type": "number"
50
+ },
51
+ "exclusiveMaximum": {
52
+ "type": "boolean",
53
+ "default": false
54
+ },
55
+ "minimum": {
56
+ "type": "number"
57
+ },
58
+ "exclusiveMinimum": {
59
+ "type": "boolean",
60
+ "default": false
61
+ },
62
+ "maxLength": { "$ref": "#/definitions/positiveInteger" },
63
+ "minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
64
+ "pattern": {
65
+ "type": "string",
66
+ "format": "regex"
67
+ },
68
+ "additionalItems": {
69
+ "anyOf": [
70
+ { "type": "boolean" },
71
+ { "$ref": "#" }
72
+ ],
73
+ "default": {}
74
+ },
75
+ "items": {
76
+ "anyOf": [
77
+ { "$ref": "#" },
78
+ { "$ref": "#/definitions/schemaArray" }
79
+ ],
80
+ "default": {}
81
+ },
82
+ "maxItems": { "$ref": "#/definitions/positiveInteger" },
83
+ "minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
84
+ "uniqueItems": {
85
+ "type": "boolean",
86
+ "default": false
87
+ },
88
+ "maxProperties": { "$ref": "#/definitions/positiveInteger" },
89
+ "minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
90
+ "required": { "$ref": "#/definitions/stringArray" },
91
+ "additionalProperties": {
92
+ "anyOf": [
93
+ { "type": "boolean" },
94
+ { "$ref": "#" }
95
+ ],
96
+ "default": {}
97
+ },
98
+ "definitions": {
99
+ "type": "object",
100
+ "additionalProperties": { "$ref": "#" },
101
+ "default": {}
102
+ },
103
+ "properties": {
104
+ "type": "object",
105
+ "additionalProperties": { "$ref": "#" },
106
+ "default": {}
107
+ },
108
+ "patternProperties": {
109
+ "type": "object",
110
+ "additionalProperties": { "$ref": "#" },
111
+ "default": {}
112
+ },
113
+ "dependencies": {
114
+ "type": "object",
115
+ "additionalProperties": {
116
+ "anyOf": [
117
+ { "$ref": "#" },
118
+ { "$ref": "#/definitions/stringArray" }
119
+ ]
120
+ }
121
+ },
122
+ "enum": {
123
+ "type": "array",
124
+ "minItems": 1,
125
+ "uniqueItems": true
126
+ },
127
+ "type": {
128
+ "anyOf": [
129
+ { "$ref": "#/definitions/simpleTypes" },
130
+ {
131
+ "type": "array",
132
+ "items": { "$ref": "#/definitions/simpleTypes" },
133
+ "minItems": 1,
134
+ "uniqueItems": true
135
+ }
136
+ ]
137
+ },
138
+ "format": { "type": "string" },
139
+ "allOf": { "$ref": "#/definitions/schemaArray" },
140
+ "anyOf": { "$ref": "#/definitions/schemaArray" },
141
+ "oneOf": { "$ref": "#/definitions/schemaArray" },
142
+ "not": { "$ref": "#" }
143
+ },
144
+ "dependencies": {
145
+ "exclusiveMaximum": ["maximum"],
146
+ "exclusiveMinimum": ["minimum"]
147
+ },
148
+ "default": {}
149
+ };
@@ -0,0 +1,13 @@
1
+ import * as Instance from "../lib/instance.js";
2
+ import Validation from "../lib/keywords/validation.js";
3
+
4
+
5
+ const id = "https://json-schema.org/keyword/draft-06/contains";
6
+
7
+ const compile = (schema, ast) => Validation.compile(schema, ast);
8
+
9
+ const interpret = (contains, instance, ast, dynamicAnchors) => {
10
+ return !Instance.typeOf(instance, "array") || Instance.some((item) => Validation.interpret(contains, item, ast, dynamicAnchors), instance);
11
+ };
12
+
13
+ export default { id, compile, interpret };
@@ -0,0 +1,47 @@
1
+ import type { Json } from "@hyperjump/json-pointer";
2
+ import type { JsonSchemaType } from "../lib/common.js";
3
+
4
+
5
+ export type JsonSchemaDraft06 = boolean | {
6
+ $ref: string;
7
+ } | {
8
+ $schema?: "http://json-schema.org/draft-06/schema#";
9
+ $id?: string;
10
+ title?: string;
11
+ description?: string;
12
+ default?: Json;
13
+ examples?: Json[];
14
+ multipleOf?: number;
15
+ maximum?: number;
16
+ exclusiveMaximum?: number;
17
+ minimum?: number;
18
+ exclusiveMinimum?: number;
19
+ maxLength?: number;
20
+ minLength?: number;
21
+ pattern?: string;
22
+ additionalItems?: JsonSchemaDraft06;
23
+ items?: JsonSchemaDraft06 | JsonSchemaDraft06[];
24
+ maxItems?: number;
25
+ minItems?: number;
26
+ uniqueItems?: boolean;
27
+ contains?: JsonSchemaDraft06;
28
+ maxProperties?: number;
29
+ minProperties?: number;
30
+ required?: string[];
31
+ additionalProperties?: JsonSchemaDraft06;
32
+ definitions?: Record<string, JsonSchemaDraft06>;
33
+ properties?: Record<string, JsonSchemaDraft06>;
34
+ patternProperties?: Record<string, JsonSchemaDraft06>;
35
+ dependencies?: Record<string, JsonSchemaDraft06 | string[]>;
36
+ propertyNames?: JsonSchemaDraft06;
37
+ const?: Json;
38
+ enum?: Json[];
39
+ type?: JsonSchemaType | JsonSchemaType[];
40
+ format?: "date-time" | "email" | "hostname" | "ipv4" | "ipv6" | "uri" | "uri-reference" | "uri-template" | "json-pointer";
41
+ allOf?: JsonSchemaDraft06[];
42
+ anyOf?: JsonSchemaDraft06[];
43
+ oneOf?: JsonSchemaDraft06[];
44
+ not?: JsonSchemaDraft06;
45
+ };
46
+
47
+ export * from "../lib/index.js";
@@ -0,0 +1,66 @@
1
+ import { addKeyword, defineVocabulary, loadDialect } from "../lib/keywords.js";
2
+ import { addSchema } from "../lib/core.js";
3
+ import metaSchema from "./schema.js";
4
+ import additionalItems from "../draft-04/additionalItems.js";
5
+ import contains from "./contains.js";
6
+ import dependencies from "../draft-04/dependencies.js";
7
+ import id from "../draft-04/id.js";
8
+ import items from "../draft-04/items.js";
9
+ import ref from "../draft-04/ref.js";
10
+
11
+
12
+ addKeyword(additionalItems);
13
+ addKeyword(dependencies);
14
+ addKeyword(contains);
15
+ addKeyword(id);
16
+ addKeyword(items);
17
+ addKeyword(ref);
18
+
19
+ const jsonSchemaVersion = "http://json-schema.org/draft-06/schema";
20
+
21
+ defineVocabulary(jsonSchemaVersion, {
22
+ "$id": "https://json-schema.org/keyword/draft-04/id",
23
+ "$ref": "https://json-schema.org/keyword/draft-04/ref",
24
+ "additionalItems": "https://json-schema.org/keyword/draft-04/additionalItems",
25
+ "additionalProperties": "https://json-schema.org/keyword/additionalProperties",
26
+ "allOf": "https://json-schema.org/keyword/allOf",
27
+ "anyOf": "https://json-schema.org/keyword/anyOf",
28
+ "const": "https://json-schema.org/keyword/const",
29
+ "contains": "https://json-schema.org/keyword/draft-06/contains",
30
+ "default": "https://json-schema.org/keyword/default",
31
+ "definitions": "https://json-schema.org/keyword/definitions",
32
+ "dependencies": "https://json-schema.org/keyword/draft-04/dependencies",
33
+ "description": "https://json-schema.org/keyword/description",
34
+ "enum": "https://json-schema.org/keyword/enum",
35
+ "exclusiveMaximum": "https://json-schema.org/keyword/exclusiveMaximum",
36
+ "exclusiveMinimum": "https://json-schema.org/keyword/exclusiveMinimum",
37
+ "format": "https://json-schema.org/keyword/format",
38
+ "items": "https://json-schema.org/keyword/draft-04/items",
39
+ "maxItems": "https://json-schema.org/keyword/maxItems",
40
+ "maxLength": "https://json-schema.org/keyword/maxLength",
41
+ "maxProperties": "https://json-schema.org/keyword/maxProperties",
42
+ "maximum": "https://json-schema.org/keyword/maximum",
43
+ "minItems": "https://json-schema.org/keyword/minItems",
44
+ "minLength": "https://json-schema.org/keyword/minLength",
45
+ "minProperties": "https://json-schema.org/keyword/minProperties",
46
+ "minimum": "https://json-schema.org/keyword/minimum",
47
+ "multipleOf": "https://json-schema.org/keyword/multipleOf",
48
+ "not": "https://json-schema.org/keyword/not",
49
+ "oneOf": "https://json-schema.org/keyword/oneOf",
50
+ "pattern": "https://json-schema.org/keyword/pattern",
51
+ "patternProperties": "https://json-schema.org/keyword/patternProperties",
52
+ "properties": "https://json-schema.org/keyword/properties",
53
+ "propertyNames": "https://json-schema.org/keyword/propertyNames",
54
+ "required": "https://json-schema.org/keyword/required",
55
+ "title": "https://json-schema.org/keyword/title",
56
+ "type": "https://json-schema.org/keyword/type",
57
+ "uniqueItems": "https://json-schema.org/keyword/uniqueItems"
58
+ });
59
+
60
+ loadDialect(jsonSchemaVersion, {
61
+ [jsonSchemaVersion]: true
62
+ }, true);
63
+
64
+ addSchema(metaSchema);
65
+
66
+ export * from "../lib/index.js";