@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
@@ -0,0 +1,124 @@
1
+ import { addKeyword, defineVocabulary, loadDialect } from "../lib/keywords.js";
2
+ import { addSchema } from "../lib/core.js";
3
+
4
+ import metaSchema from "./schema.js";
5
+ import coreMetaSchema from "./meta/core.js";
6
+ import applicatorMetaSchema from "./meta/applicator.js";
7
+ import validationMetaSchema from "./meta/validation.js";
8
+ import metaDataMetaSchema from "./meta/meta-data.js";
9
+ import formatAnnotationMetaSchema from "./meta/format-annotation.js";
10
+ import formatAssertionMetaSchema from "./meta/format-assertion.js";
11
+ import contentMetaSchema from "./meta/content.js";
12
+ import unevaluatedMetaSchema from "./meta/unevaluated.js";
13
+
14
+ import contains from "../draft-2019-09/contains.js";
15
+ import dynamicAnchor from "./dynamicAnchor.js";
16
+ import dynamicRef from "./dynamicRef.js";
17
+
18
+
19
+ addKeyword(contains);
20
+ addKeyword(dynamicRef);
21
+ addKeyword(dynamicAnchor);
22
+
23
+ defineVocabulary("https://json-schema.org/draft/2020-12/vocab/core", {
24
+ "$anchor": "https://json-schema.org/keyword/anchor",
25
+ "$comment": "https://json-schema.org/keyword/comment",
26
+ "$defs": "https://json-schema.org/keyword/definitions",
27
+ "$dynamicAnchor": "https://json-schema.org/keyword/draft-2020-12/dynamicAnchor",
28
+ "$dynamicRef": "https://json-schema.org/keyword/draft-2020-12/dynamicRef",
29
+ "$id": "https://json-schema.org/keyword/id",
30
+ "$ref": "https://json-schema.org/keyword/ref",
31
+ "$vocabulary": "https://json-schema.org/keyword/vocabulary"
32
+ });
33
+
34
+ defineVocabulary("https://json-schema.org/draft/2020-12/vocab/applicator", {
35
+ "additionalProperties": "https://json-schema.org/keyword/additionalProperties",
36
+ "allOf": "https://json-schema.org/keyword/allOf",
37
+ "anyOf": "https://json-schema.org/keyword/anyOf",
38
+ "contains": "https://json-schema.org/keyword/draft-2019-09/contains",
39
+ "dependentSchemas": "https://json-schema.org/keyword/dependentSchemas",
40
+ "if": "https://json-schema.org/keyword/if",
41
+ "then": "https://json-schema.org/keyword/then",
42
+ "else": "https://json-schema.org/keyword/else",
43
+ "items": "https://json-schema.org/keyword/items",
44
+ "not": "https://json-schema.org/keyword/not",
45
+ "oneOf": "https://json-schema.org/keyword/oneOf",
46
+ "patternProperties": "https://json-schema.org/keyword/patternProperties",
47
+ "prefixItems": "https://json-schema.org/keyword/prefixItems",
48
+ "properties": "https://json-schema.org/keyword/properties",
49
+ "propertyNames": "https://json-schema.org/keyword/propertyNames"
50
+ });
51
+
52
+ defineVocabulary("https://json-schema.org/draft/2020-12/vocab/validation", {
53
+ "const": "https://json-schema.org/keyword/const",
54
+ "dependentRequired": "https://json-schema.org/keyword/dependentRequired",
55
+ "enum": "https://json-schema.org/keyword/enum",
56
+ "exclusiveMaximum": "https://json-schema.org/keyword/exclusiveMaximum",
57
+ "exclusiveMinimum": "https://json-schema.org/keyword/exclusiveMinimum",
58
+ "maxContains": "https://json-schema.org/keyword/maxContains",
59
+ "maxItems": "https://json-schema.org/keyword/maxItems",
60
+ "maxLength": "https://json-schema.org/keyword/maxLength",
61
+ "maxProperties": "https://json-schema.org/keyword/maxProperties",
62
+ "maximum": "https://json-schema.org/keyword/maximum",
63
+ "minContains": "https://json-schema.org/keyword/minContains",
64
+ "minItems": "https://json-schema.org/keyword/minItems",
65
+ "minLength": "https://json-schema.org/keyword/minLength",
66
+ "minProperties": "https://json-schema.org/keyword/minProperties",
67
+ "minimum": "https://json-schema.org/keyword/minimum",
68
+ "multipleOf": "https://json-schema.org/keyword/multipleOf",
69
+ "pattern": "https://json-schema.org/keyword/pattern",
70
+ "required": "https://json-schema.org/keyword/required",
71
+ "type": "https://json-schema.org/keyword/type",
72
+ "uniqueItems": "https://json-schema.org/keyword/uniqueItems"
73
+ });
74
+
75
+ defineVocabulary("https://json-schema.org/draft/2020-12/vocab/meta-data", {
76
+ "default": "https://json-schema.org/keyword/default",
77
+ "deprecated": "https://json-schema.org/keyword/deprecated",
78
+ "description": "https://json-schema.org/keyword/description",
79
+ "examples": "https://json-schema.org/keyword/examples",
80
+ "readOnly": "https://json-schema.org/keyword/readOnly",
81
+ "title": "https://json-schema.org/keyword/title",
82
+ "writeOnly": "https://json-schema.org/keyword/writeOnly"
83
+ });
84
+
85
+ defineVocabulary("https://json-schema.org/draft/2020-12/vocab/format-annotation", {
86
+ "format": "https://json-schema.org/keyword/format"
87
+ });
88
+
89
+ defineVocabulary("https://json-schema.org/draft/2020-12/vocab/format-assertion", {
90
+ "format": "https://json-schema.org/keyword/format-assertion"
91
+ });
92
+
93
+ defineVocabulary("https://json-schema.org/draft/2020-12/vocab/content", {
94
+ "contentEncoding": "https://json-schema.org/keyword/contentEncoding",
95
+ "contentMediaType": "https://json-schema.org/keyword/contentMediaType",
96
+ "contentSchema": "https://json-schema.org/keyword/contentSchema"
97
+ });
98
+
99
+ defineVocabulary("https://json-schema.org/draft/2020-12/vocab/unevaluated", {
100
+ "unevaluatedItems": "https://json-schema.org/keyword/unevaluatedItems",
101
+ "unevaluatedProperties": "https://json-schema.org/keyword/unevaluatedProperties"
102
+ });
103
+
104
+ loadDialect("https://json-schema.org/draft/2020-12/schema", {
105
+ "https://json-schema.org/draft/2020-12/vocab/core": true,
106
+ "https://json-schema.org/draft/2020-12/vocab/applicator": true,
107
+ "https://json-schema.org/draft/2020-12/vocab/validation": true,
108
+ "https://json-schema.org/draft/2020-12/vocab/meta-data": true,
109
+ "https://json-schema.org/draft/2020-12/vocab/format-annotation": true,
110
+ "https://json-schema.org/draft/2020-12/vocab/content": true,
111
+ "https://json-schema.org/draft/2020-12/vocab/unevaluated": true
112
+ }, true);
113
+
114
+ addSchema(metaSchema);
115
+ addSchema(coreMetaSchema);
116
+ addSchema(applicatorMetaSchema);
117
+ addSchema(validationMetaSchema);
118
+ addSchema(metaDataMetaSchema);
119
+ addSchema(formatAnnotationMetaSchema);
120
+ addSchema(formatAssertionMetaSchema);
121
+ addSchema(contentMetaSchema);
122
+ addSchema(unevaluatedMetaSchema);
123
+
124
+ export * from "../lib/index.js";
@@ -0,0 +1,46 @@
1
+ export default {
2
+ "$id": "https://json-schema.org/draft/2020-12/meta/applicator",
3
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4
+ "$dynamicAnchor": "meta",
5
+
6
+ "title": "Applicator vocabulary meta-schema",
7
+ "type": ["object", "boolean"],
8
+ "properties": {
9
+ "prefixItems": { "$ref": "#/$defs/schemaArray" },
10
+ "items": { "$dynamicRef": "#meta" },
11
+ "contains": { "$dynamicRef": "#meta" },
12
+ "additionalProperties": { "$dynamicRef": "#meta" },
13
+ "properties": {
14
+ "type": "object",
15
+ "additionalProperties": { "$dynamicRef": "#meta" },
16
+ "default": {}
17
+ },
18
+ "patternProperties": {
19
+ "type": "object",
20
+ "additionalProperties": { "$dynamicRef": "#meta" },
21
+ "propertyNames": { "format": "regex" },
22
+ "default": {}
23
+ },
24
+ "dependentSchemas": {
25
+ "type": "object",
26
+ "additionalProperties": {
27
+ "$dynamicRef": "#meta"
28
+ }
29
+ },
30
+ "propertyNames": { "$dynamicRef": "#meta" },
31
+ "if": { "$dynamicRef": "#meta" },
32
+ "then": { "$dynamicRef": "#meta" },
33
+ "else": { "$dynamicRef": "#meta" },
34
+ "allOf": { "$ref": "#/$defs/schemaArray" },
35
+ "anyOf": { "$ref": "#/$defs/schemaArray" },
36
+ "oneOf": { "$ref": "#/$defs/schemaArray" },
37
+ "not": { "$dynamicRef": "#meta" }
38
+ },
39
+ "$defs": {
40
+ "schemaArray": {
41
+ "type": "array",
42
+ "minItems": 1,
43
+ "items": { "$dynamicRef": "#meta" }
44
+ }
45
+ }
46
+ };
@@ -0,0 +1,14 @@
1
+ export default {
2
+ "$id": "https://json-schema.org/draft/2020-12/meta/content",
3
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4
+ "$dynamicAnchor": "meta",
5
+
6
+ "title": "Content vocabulary meta-schema",
7
+
8
+ "type": ["object", "boolean"],
9
+ "properties": {
10
+ "contentMediaType": { "type": "string" },
11
+ "contentEncoding": { "type": "string" },
12
+ "contentSchema": { "$dynamicRef": "#meta" }
13
+ }
14
+ };
@@ -0,0 +1,54 @@
1
+ export default {
2
+ "$id": "https://json-schema.org/draft/2020-12/meta/core",
3
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4
+ "$dynamicAnchor": "meta",
5
+
6
+ "title": "Core vocabulary meta-schema",
7
+ "type": ["object", "boolean"],
8
+ "properties": {
9
+ "$id": {
10
+ "type": "string",
11
+ "format": "uri-reference",
12
+ "$comment": "Non-empty fragments not allowed.",
13
+ "pattern": "^[^#]*#?$"
14
+ },
15
+ "$schema": {
16
+ "type": "string",
17
+ "format": "uri"
18
+ },
19
+ "$anchor": {
20
+ "type": "string",
21
+ "pattern": "^[A-Za-z_][-A-Za-z0-9._]*$"
22
+ },
23
+ "$ref": {
24
+ "type": "string",
25
+ "format": "uri-reference"
26
+ },
27
+ "$dynamicRef": {
28
+ "type": "string",
29
+ "format": "uri-reference"
30
+ },
31
+ "$dynamicAnchor": {
32
+ "type": "string",
33
+ "pattern": "^[A-Za-z_][-A-Za-z0-9._]*$"
34
+ },
35
+ "$vocabulary": {
36
+ "type": "object",
37
+ "propertyNames": {
38
+ "type": "string",
39
+ "format": "uri"
40
+ },
41
+ "additionalProperties": {
42
+ "type": "boolean"
43
+ }
44
+ },
45
+ "$comment": {
46
+ "type": "string"
47
+ },
48
+ "$defs": {
49
+ "type": "object",
50
+ "additionalProperties": { "$dynamicRef": "#meta" },
51
+ "default": {}
52
+ }
53
+ }
54
+ };
@@ -0,0 +1,11 @@
1
+ export default {
2
+ "$id": "https://json-schema.org/draft/2020-12/meta/format-annotation",
3
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4
+ "$dynamicAnchor": "meta",
5
+
6
+ "title": "Format vocabulary meta-schema for annotation results",
7
+ "type": ["object", "boolean"],
8
+ "properties": {
9
+ "format": { "type": "string" }
10
+ }
11
+ };
@@ -0,0 +1,11 @@
1
+ export default {
2
+ "$id": "https://json-schema.org/draft/2020-12/meta/format-assertion",
3
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4
+ "$dynamicAnchor": "meta",
5
+
6
+ "title": "Format vocabulary meta-schema for assertion results",
7
+ "type": ["object", "boolean"],
8
+ "properties": {
9
+ "format": { "type": "string" }
10
+ }
11
+ };
@@ -0,0 +1,34 @@
1
+ export default {
2
+ "$id": "https://json-schema.org/draft/2020-12/meta/meta-data",
3
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4
+ "$dynamicAnchor": "meta",
5
+
6
+ "title": "Meta-data vocabulary meta-schema",
7
+
8
+ "type": ["object", "boolean"],
9
+ "properties": {
10
+ "title": {
11
+ "type": "string"
12
+ },
13
+ "description": {
14
+ "type": "string"
15
+ },
16
+ "default": true,
17
+ "deprecated": {
18
+ "type": "boolean",
19
+ "default": false
20
+ },
21
+ "readOnly": {
22
+ "type": "boolean",
23
+ "default": false
24
+ },
25
+ "writeOnly": {
26
+ "type": "boolean",
27
+ "default": false
28
+ },
29
+ "examples": {
30
+ "type": "array",
31
+ "items": true
32
+ }
33
+ }
34
+ };
@@ -0,0 +1,12 @@
1
+ export default {
2
+ "$id": "https://json-schema.org/draft/2020-12/meta/unevaluated",
3
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4
+ "$dynamicAnchor": "meta",
5
+
6
+ "title": "Unevaluated applicator vocabulary meta-schema",
7
+ "type": ["object", "boolean"],
8
+ "properties": {
9
+ "unevaluatedItems": { "$dynamicRef": "#meta" },
10
+ "unevaluatedProperties": { "$dynamicRef": "#meta" }
11
+ }
12
+ };
@@ -0,0 +1,95 @@
1
+ export default {
2
+ "$id": "https://json-schema.org/draft/2020-12/meta/validation",
3
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
4
+ "$dynamicAnchor": "meta",
5
+
6
+ "title": "Validation vocabulary meta-schema",
7
+ "type": ["object", "boolean"],
8
+ "properties": {
9
+ "multipleOf": {
10
+ "type": "number",
11
+ "exclusiveMinimum": 0
12
+ },
13
+ "maximum": {
14
+ "type": "number"
15
+ },
16
+ "exclusiveMaximum": {
17
+ "type": "number"
18
+ },
19
+ "minimum": {
20
+ "type": "number"
21
+ },
22
+ "exclusiveMinimum": {
23
+ "type": "number"
24
+ },
25
+ "maxLength": { "$ref": "#/$defs/nonNegativeInteger" },
26
+ "minLength": { "$ref": "#/$defs/nonNegativeIntegerDefault0" },
27
+ "pattern": {
28
+ "type": "string",
29
+ "format": "regex"
30
+ },
31
+ "maxItems": { "$ref": "#/$defs/nonNegativeInteger" },
32
+ "minItems": { "$ref": "#/$defs/nonNegativeIntegerDefault0" },
33
+ "uniqueItems": {
34
+ "type": "boolean",
35
+ "default": false
36
+ },
37
+ "maxContains": { "$ref": "#/$defs/nonNegativeInteger" },
38
+ "minContains": {
39
+ "$ref": "#/$defs/nonNegativeInteger",
40
+ "default": 1
41
+ },
42
+ "maxProperties": { "$ref": "#/$defs/nonNegativeInteger" },
43
+ "minProperties": { "$ref": "#/$defs/nonNegativeIntegerDefault0" },
44
+ "required": { "$ref": "#/$defs/stringArray" },
45
+ "dependentRequired": {
46
+ "type": "object",
47
+ "additionalProperties": {
48
+ "$ref": "#/$defs/stringArray"
49
+ }
50
+ },
51
+ "const": true,
52
+ "enum": {
53
+ "type": "array",
54
+ "items": true
55
+ },
56
+ "type": {
57
+ "anyOf": [
58
+ { "$ref": "#/$defs/simpleTypes" },
59
+ {
60
+ "type": "array",
61
+ "items": { "$ref": "#/$defs/simpleTypes" },
62
+ "minItems": 1,
63
+ "uniqueItems": true
64
+ }
65
+ ]
66
+ }
67
+ },
68
+ "$defs": {
69
+ "nonNegativeInteger": {
70
+ "type": "integer",
71
+ "minimum": 0
72
+ },
73
+ "nonNegativeIntegerDefault0": {
74
+ "$ref": "#/$defs/nonNegativeInteger",
75
+ "default": 0
76
+ },
77
+ "simpleTypes": {
78
+ "enum": [
79
+ "array",
80
+ "boolean",
81
+ "integer",
82
+ "null",
83
+ "number",
84
+ "object",
85
+ "string"
86
+ ]
87
+ },
88
+ "stringArray": {
89
+ "type": "array",
90
+ "items": { "type": "string" },
91
+ "uniqueItems": true,
92
+ "default": []
93
+ }
94
+ }
95
+ };
@@ -0,0 +1,44 @@
1
+ export default {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://json-schema.org/draft/2020-12/schema",
4
+ "$vocabulary": {
5
+ "https://json-schema.org/draft/2020-12/vocab/core": true,
6
+ "https://json-schema.org/draft/2020-12/vocab/applicator": true,
7
+ "https://json-schema.org/draft/2020-12/vocab/unevaluated": true,
8
+ "https://json-schema.org/draft/2020-12/vocab/validation": true,
9
+ "https://json-schema.org/draft/2020-12/vocab/meta-data": true,
10
+ "https://json-schema.org/draft/2020-12/vocab/format-annotation": true,
11
+ "https://json-schema.org/draft/2020-12/vocab/content": true
12
+ },
13
+ "$dynamicAnchor": "meta",
14
+
15
+ "title": "Core and Validation specifications meta-schema",
16
+ "allOf": [
17
+ { "$ref": "meta/core" },
18
+ { "$ref": "meta/applicator" },
19
+ { "$ref": "meta/unevaluated" },
20
+ { "$ref": "meta/validation" },
21
+ { "$ref": "meta/meta-data" },
22
+ { "$ref": "meta/format-annotation" },
23
+ { "$ref": "meta/content" }
24
+ ],
25
+ "type": ["object", "boolean"],
26
+ "properties": {
27
+ "definitions": {
28
+ "$comment": "While no longer an official keyword as it is replaced by $defs, this keyword is retained in the meta-schema to prevent incompatible extensions as it remains in common use.",
29
+ "type": "object",
30
+ "additionalProperties": { "$dynamicRef": "#meta" },
31
+ "default": {}
32
+ },
33
+ "dependencies": {
34
+ "$comment": "\"dependencies\" is no longer a keyword, but schema authors should avoid redefining it to facilitate a smooth transition to \"dependentSchemas\" and \"dependentRequired\"",
35
+ "type": "object",
36
+ "additionalProperties": {
37
+ "anyOf": [
38
+ { "$dynamicRef": "#meta" },
39
+ { "$ref": "meta/validation#/$defs/stringArray" }
40
+ ]
41
+ }
42
+ }
43
+ }
44
+ };
package/lib/common.d.ts CHANGED
@@ -1 +1,5 @@
1
- export type JsonSchemaType = "object" | "array" | "string" | "number" | "integer" | "boolean" | "null";
1
+ export type JsonType = "object" | "array" | "string" | "number" | "boolean" | "null";
2
+ export type JsonSchemaType = JsonType | "integer";
3
+
4
+ type PathRelative = (from: string, to: string) => string;
5
+ export const pathRelative: PathRelative;
package/lib/common.js CHANGED
@@ -1,13 +1,84 @@
1
1
  const isObject = (value) => typeof value === "object" && !Array.isArray(value) && value !== null;
2
- const escapeRegExp = (string) => string.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
3
-
4
- const splitUrl = (url) => {
5
- const indexOfHash = url.indexOf("#");
6
- const ndx = indexOfHash === -1 ? url.length : indexOfHash;
7
- const urlReference = url.slice(0, ndx);
8
- const urlFragment = url.slice(ndx + 1);
2
+ const isType = {
3
+ null: (value) => value === null,
4
+ boolean: (value) => typeof value === "boolean",
5
+ object: isObject,
6
+ array: (value) => Array.isArray(value),
7
+ number: (value) => typeof value === "number",
8
+ integer: (value) => Number.isInteger(value),
9
+ string: (value) => typeof value === "string"
10
+ };
11
+ export const jsonTypeOf = (value, type) => isType[type](value);
9
12
 
10
- return [decodeURI(urlReference), decodeURI(urlFragment)];
13
+ export const resolveUrl = (url, baseUri = undefined) => {
14
+ const resolved = new URL(url, baseUri);
15
+ if (baseUri && new URL("", baseUri).protocol !== "file:" && resolved.protocol === "file:") {
16
+ throw Error(`Can't access file '${resolved.href}' resource from network context '${baseUri}'`);
17
+ }
18
+ return resolved.href;
11
19
  };
12
20
 
13
- module.exports = { isObject, escapeRegExp, splitUrl };
21
+ export const urlFragment = (url) => decodeURIComponent(new URL(url).hash.slice(1));
22
+
23
+ const CHAR_BACKWARD_SLASH = 47;
24
+
25
+ export const pathRelative = (from, to) => {
26
+ if (from === to) {
27
+ return "";
28
+ }
29
+
30
+ let toStart = 1;
31
+ const fromLen = from.length - 1;
32
+ const toLen = to.length - toStart;
33
+
34
+ // Compare paths to find the longest common path from root
35
+ const length = fromLen < toLen ? fromLen : toLen;
36
+ let lastCommonSep = -1;
37
+ let i = 0;
38
+ for (; i < length; i++) {
39
+ const fromCode = from.charCodeAt(i + 1);
40
+ if (fromCode !== to.charCodeAt(toStart + i)) {
41
+ break;
42
+ } else if (fromCode === CHAR_BACKWARD_SLASH) {
43
+ lastCommonSep = i;
44
+ }
45
+ }
46
+
47
+ if (toLen > length) {
48
+ if (to.charCodeAt(toStart + i) === CHAR_BACKWARD_SLASH) {
49
+ return to.slice(toStart + i + 1);
50
+ }
51
+ if (i === 0) {
52
+ return to.slice(toStart + i);
53
+ }
54
+ }
55
+ if (fromLen > length) {
56
+ if (from.charCodeAt(i + 1) === CHAR_BACKWARD_SLASH) {
57
+ lastCommonSep = i;
58
+ } else if (length === 0) {
59
+ lastCommonSep = 0;
60
+ }
61
+ }
62
+
63
+ let out = "";
64
+ // Generate the relative path based on the path difference between `to` and `from`
65
+ for (i = lastCommonSep + 2; i <= from.length; ++i) {
66
+ if (i === from.length || from.charCodeAt(i) === CHAR_BACKWARD_SLASH) {
67
+ out += out.length === 0 ? ".." : "/..";
68
+ }
69
+ }
70
+
71
+ toStart += lastCommonSep;
72
+
73
+ // Lastly, append the rest of the destination (`to`) path that comes after
74
+ // the common path parts
75
+ if (out.length > 0) {
76
+ return `${out}${to.slice(toStart, to.length)}`;
77
+ }
78
+
79
+ if (to.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) {
80
+ ++toStart;
81
+ }
82
+
83
+ return to.slice(toStart, to.length);
84
+ };
@@ -0,0 +1,9 @@
1
+ import type { OutputFormat } from "./core.js";
2
+
3
+
4
+ export const setMetaSchemaOutputFormat: (format: OutputFormat) => void;
5
+ export const getMetaSchemaOutputFormat: () => OutputFormat;
6
+ export const setShouldValidateSchema: (isEnabled: boolean) => void;
7
+ export const getShouldValidateSchema: () => boolean;
8
+ export const setExperimentalKeywordEnabled: (keywordId: string, isEnabled: boolean) => void;
9
+ export const isExperimentalKeywordEnabled: (keywordId: string) => boolean;
@@ -0,0 +1,18 @@
1
+ let metaSchemaOutputFormat;
2
+ let shouldValidateSchema = true;
3
+ let enabledExperimentalKeywords = {};
4
+
5
+ export const getMetaSchemaOutputFormat = () => metaSchemaOutputFormat;
6
+ export const setMetaSchemaOutputFormat = (format) => {
7
+ metaSchemaOutputFormat = format;
8
+ };
9
+
10
+ export const getShouldValidateSchema = () => shouldValidateSchema;
11
+ export const setShouldValidateSchema = (isEnabled) => {
12
+ shouldValidateSchema = isEnabled;
13
+ };
14
+
15
+ export const isExperimentalKeywordEnabled = (keywordId) => enabledExperimentalKeywords[keywordId];
16
+ export const setExperimentalKeywordEnabled = (keywordId, isEnabled) => {
17
+ enabledExperimentalKeywords[keywordId] = isEnabled;
18
+ };
package/lib/core.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ import type { add, Anchors } from "./schema.js";
2
+
3
+
4
+ export const validate: (
5
+ (url: string, value: unknown, outputFormat?: OutputFormat) => Promise<OutputUnit>
6
+ ) & (
7
+ (url: string) => Promise<Validator>
8
+ );
9
+ export const compile: (url: string) => Promise<CompiledSchema>;
10
+ export const interpret: (
11
+ (compiledSchema: CompiledSchema, value: unknown, outputFormat?: OutputFormat) => OutputUnit
12
+ ) & (
13
+ (compiledSchema: CompiledSchema) => Validator
14
+ );
15
+ export const FLAG: "FLAG";
16
+ export const BASIC: "BASIC";
17
+ export const DETAILED: "DETAILED";
18
+ export const VERBOSE: "VERBOSE";
19
+ export const addSchema: typeof add;
20
+
21
+ export type Validator = (value: unknown, outputFormat?: OutputFormat) => OutputUnit;
22
+
23
+ export type OutputFormat = "FLAG" | "BASIC" | "DETAILED" | "VERBOSE" | string;
24
+
25
+ export type OutputUnit = {
26
+ keyword: string;
27
+ absoluteKeywordLocation: string;
28
+ instanceLocation: string;
29
+ valid: boolean;
30
+ errors?: OutputUnit[];
31
+ };
32
+
33
+ export type CompiledSchema = {
34
+ schemaUri: string;
35
+ ast: AST;
36
+ };
37
+
38
+ type AST = {
39
+ metaData: Record<string, MetaData>;
40
+ } & Record<string, Node<Node<unknown>[] | boolean>>;
41
+
42
+ type Node<A> = [keywordId: string, schemaUri: string, keywordValue: A];
43
+
44
+ type MetaData = {
45
+ id: string;
46
+ dynamicAnchors: Anchors;
47
+ anchors: Anchors;
48
+ };