@hyperjump/json-schema 1.6.7 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/README.md +247 -255
  2. package/annotations/annotated-instance.js +3 -3
  3. package/annotations/index.d.ts +7 -1
  4. package/annotations/index.js +3 -3
  5. package/bundle/index.d.ts +1 -5
  6. package/bundle/index.js +112 -156
  7. package/draft-04/additionalItems.js +6 -7
  8. package/draft-04/dependencies.js +5 -5
  9. package/draft-04/index.js +2 -2
  10. package/draft-04/items.js +5 -5
  11. package/draft-04/maximum.js +8 -8
  12. package/draft-04/minimum.js +8 -8
  13. package/draft-06/contains.js +2 -2
  14. package/draft-06/index.js +3 -2
  15. package/draft-07/index.js +3 -2
  16. package/draft-2019-09/index.js +9 -11
  17. package/draft-2020-12/dynamicRef.js +5 -5
  18. package/draft-2020-12/index.js +11 -13
  19. package/lib/common.d.ts +1 -1
  20. package/lib/common.js +44 -60
  21. package/lib/configuration.js +0 -6
  22. package/lib/core.js +32 -30
  23. package/lib/experimental.d.ts +75 -5
  24. package/lib/experimental.js +2 -2
  25. package/lib/index.d.ts +43 -11
  26. package/lib/index.js +11 -11
  27. package/lib/instance.d.ts +1 -17
  28. package/lib/instance.js +3 -3
  29. package/lib/keywords/additionalProperties.js +12 -13
  30. package/lib/keywords/allOf.js +3 -3
  31. package/lib/keywords/anyOf.js +3 -3
  32. package/lib/keywords/conditional.js +6 -7
  33. package/lib/keywords/const.js +2 -2
  34. package/lib/keywords/contains.js +14 -35
  35. package/lib/keywords/contentSchema.js +1 -1
  36. package/lib/keywords/definitions.js +2 -2
  37. package/lib/keywords/dependentRequired.js +4 -4
  38. package/lib/keywords/dependentSchemas.js +5 -5
  39. package/lib/keywords/dynamicRef.js +10 -5
  40. package/lib/keywords/else.js +5 -6
  41. package/lib/keywords/enum.js +4 -4
  42. package/lib/keywords/exclusiveMaximum.js +3 -3
  43. package/lib/keywords/exclusiveMinimum.js +3 -3
  44. package/lib/keywords/if.js +1 -1
  45. package/lib/keywords/itemPattern.js +17 -14
  46. package/lib/keywords/items.js +6 -7
  47. package/lib/keywords/maxItems.js +3 -3
  48. package/lib/keywords/maxLength.js +3 -3
  49. package/lib/keywords/maxProperties.js +3 -3
  50. package/lib/keywords/maximum.js +3 -3
  51. package/lib/keywords/meta-data.js +1 -1
  52. package/lib/keywords/minItems.js +3 -3
  53. package/lib/keywords/minLength.js +3 -3
  54. package/lib/keywords/minProperties.js +3 -3
  55. package/lib/keywords/minimum.js +3 -3
  56. package/lib/keywords/multipleOf.js +3 -3
  57. package/lib/keywords/not.js +1 -1
  58. package/lib/keywords/oneOf.js +3 -3
  59. package/lib/keywords/pattern.js +3 -3
  60. package/lib/keywords/patternProperties.js +5 -5
  61. package/lib/keywords/prefixItems.js +5 -5
  62. package/lib/keywords/properties.js +5 -5
  63. package/lib/keywords/propertyDependencies.js +6 -7
  64. package/lib/keywords/propertyNames.js +2 -2
  65. package/lib/keywords/ref.js +2 -7
  66. package/lib/keywords/requireAllExcept.js +8 -9
  67. package/lib/keywords/required.js +3 -3
  68. package/lib/keywords/then.js +5 -5
  69. package/lib/keywords/type.js +9 -3
  70. package/lib/keywords/unevaluatedItems.js +4 -4
  71. package/lib/keywords/unevaluatedProperties.js +4 -5
  72. package/lib/keywords/uniqueItems.js +3 -3
  73. package/lib/keywords/validation.js +11 -23
  74. package/lib/keywords.js +27 -14
  75. package/lib/openapi.js +19 -6
  76. package/lib/schema.js +236 -227
  77. package/openapi-3-0/index.js +5 -5
  78. package/openapi-3-0/type.js +13 -7
  79. package/openapi-3-1/index.js +22 -21
  80. package/openapi-3-1/{schema-base/2022-10-07.js → schema-base.js} +12 -2
  81. package/openapi-3-1/schema-draft-04.js +33 -0
  82. package/openapi-3-1/schema-draft-06.js +33 -0
  83. package/openapi-3-1/schema-draft-07.js +33 -0
  84. package/openapi-3-1/schema-draft-2019-09.js +33 -0
  85. package/openapi-3-1/schema-draft-2020-12.js +33 -0
  86. package/package.json +11 -11
  87. package/stable/index.js +10 -10
  88. package/annotations/validation-error.d.ts +0 -8
  89. package/draft-2019-09/contains.js +0 -44
  90. package/lib/configuration.d.ts +0 -9
  91. package/lib/context-uri.browser.js +0 -1
  92. package/lib/context-uri.js +0 -4
  93. package/lib/core.d.ts +0 -48
  94. package/lib/fetch.browser.js +0 -1
  95. package/lib/fetch.js +0 -20
  96. package/lib/invalid-schema-error.d.ts +0 -8
  97. package/lib/keywords.d.ts +0 -19
  98. package/lib/media-types.d.ts +0 -11
  99. package/lib/media-types.js +0 -48
  100. package/lib/reference.d.ts +0 -11
  101. package/lib/reference.js +0 -11
  102. package/lib/schema.d.ts +0 -60
  103. /package/openapi-3-0/{schema/2021-09-28.js → schema.js} +0 -0
  104. /package/openapi-3-1/{schema/2022-10-07.js → schema.js} +0 -0
@@ -1,11 +1,16 @@
1
- import { addKeyword, defineVocabulary, loadDialect } from "../lib/keywords.js";
2
- import { addSchema } from "../lib/core.js";
1
+ import { addKeyword, defineVocabulary } from "../lib/keywords.js";
2
+ import { registerSchema } from "../lib/index.js";
3
3
  import "../lib/openapi.js";
4
4
 
5
5
  import dialectSchema from "./dialect/base.js";
6
6
  import vocabularySchema from "./meta/base.js";
7
- import schema20221007 from "./schema/2022-10-07.js";
8
- import schemaBase20221007 from "./schema-base/2022-10-07.js";
7
+ import schema from "./schema.js";
8
+ import schemaBase from "./schema-base.js";
9
+ import schemaDraft2020 from "./schema-draft-2020-12.js";
10
+ import schemaDraft2019 from "./schema-draft-2019-09.js";
11
+ import schemaDraft07 from "./schema-draft-07.js";
12
+ import schemaDraft06 from "./schema-draft-06.js";
13
+ import schemaDraft04 from "./schema-draft-04.js";
9
14
 
10
15
  import discriminator from "../openapi-3-0/discriminator.js";
11
16
  import example from "../openapi-3-0/example.js";
@@ -25,24 +30,20 @@ defineVocabulary("https://spec.openapis.org/oas/3.1/vocab/base", {
25
30
  "xml": "https://spec.openapis.org/oas/3.0/keyword/xml"
26
31
  });
27
32
 
28
- loadDialect("https://spec.openapis.org/oas/3.1/schema-base", {
29
- "https://json-schema.org/draft/2020-12/vocab/core": true,
30
- "https://json-schema.org/draft/2020-12/vocab/applicator": true,
31
- "https://json-schema.org/draft/2020-12/vocab/validation": true,
32
- "https://json-schema.org/draft/2020-12/vocab/meta-data": true,
33
- "https://json-schema.org/draft/2020-12/vocab/format-annotation": true,
34
- "https://json-schema.org/draft/2020-12/vocab/content": true,
35
- "https://json-schema.org/draft/2020-12/vocab/unevaluated": true,
36
- "https://spec.openapis.org/oas/3.1/vocab/base": false
37
- }, true);
38
-
39
- addSchema(vocabularySchema);
40
- addSchema(dialectSchema);
33
+ registerSchema(vocabularySchema);
34
+ registerSchema(dialectSchema);
41
35
 
42
36
  // Current Schemas
43
- addSchema(schema20221007, "https://spec.openapis.org/oas/3.1/schema");
44
- addSchema(schema20221007, "https://spec.openapis.org/oas/3.1/schema/latest");
45
- addSchema(schemaBase20221007, "https://spec.openapis.org/oas/3.1/schema-base");
46
- addSchema(schemaBase20221007, "https://spec.openapis.org/oas/3.1/schema-base/latest");
37
+ registerSchema(schema, "https://spec.openapis.org/oas/3.1/schema");
38
+ registerSchema(schema, "https://spec.openapis.org/oas/3.1/schema/latest");
39
+ registerSchema(schemaBase, "https://spec.openapis.org/oas/3.1/schema-base");
40
+ registerSchema(schemaBase, "https://spec.openapis.org/oas/3.1/schema-base/latest");
41
+
42
+ // Alternative dialect schemas
43
+ registerSchema(schemaDraft2020, "https://spec.openapis.org/oas/3.1/schema-draft-2020-12");
44
+ registerSchema(schemaDraft2019, "https://spec.openapis.org/oas/3.1/schema-draft-2019-09");
45
+ registerSchema(schemaDraft07, "https://spec.openapis.org/oas/3.1/schema-draft-07");
46
+ registerSchema(schemaDraft06, "https://spec.openapis.org/oas/3.1/schema-draft-06");
47
+ registerSchema(schemaDraft04, "https://spec.openapis.org/oas/3.1/schema-draft-04");
47
48
 
48
49
  export * from "../draft-2020-12/index.js";
@@ -1,10 +1,20 @@
1
1
  export default {
2
- "$id": "https://spec.openapis.org/oas/3.1/schema-base/2022-10-07",
3
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
4
3
 
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
+ "https://spec.openapis.org/oas/3.1/vocab/base": false
13
+ },
14
+
5
15
  "description": "The description of OpenAPI v3.1.x documents using the OpenAPI JSON Schema dialect, as defined by https://spec.openapis.org/oas/v3.1.0",
6
16
 
7
- "$ref": "https://spec.openapis.org/oas/3.1/schema/2022-10-07",
17
+ "$ref": "https://spec.openapis.org/oas/3.1/schema",
8
18
  "properties": {
9
19
  "jsonSchemaDialect": { "$ref": "#/$defs/dialect" }
10
20
  },
@@ -0,0 +1,33 @@
1
+ export default {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+
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
+ "https://spec.openapis.org/oas/3.1/vocab/base": false
13
+ },
14
+
15
+ "description": "OpenAPI v3.1.x documents using draft-04 JSON Schemas",
16
+
17
+ "$ref": "https://spec.openapis.org/oas/3.1/schema",
18
+ "properties": {
19
+ "jsonSchemaDialect": { "$ref": "#/$defs/dialect" }
20
+ },
21
+
22
+ "$defs": {
23
+ "dialect": { "const": "http://json-schema.org/draft-04/schema#" },
24
+
25
+ "schema": {
26
+ "$dynamicAnchor": "meta",
27
+ "$ref": "https://spec.openapis.org/oas/3.1/dialect/base",
28
+ "properties": {
29
+ "$schema": { "$ref": "#/$defs/dialect" }
30
+ }
31
+ }
32
+ }
33
+ };
@@ -0,0 +1,33 @@
1
+ export default {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+
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
+ "https://spec.openapis.org/oas/3.1/vocab/base": false
13
+ },
14
+
15
+ "description": "OpenAPI v3.1.x documents using draft-06 JSON Schemas",
16
+
17
+ "$ref": "https://spec.openapis.org/oas/3.1/schema",
18
+ "properties": {
19
+ "jsonSchemaDialect": { "$ref": "#/$defs/dialect" }
20
+ },
21
+
22
+ "$defs": {
23
+ "dialect": { "const": "http://json-schema.org/draft-06/schema#" },
24
+
25
+ "schema": {
26
+ "$dynamicAnchor": "meta",
27
+ "$ref": "https://spec.openapis.org/oas/3.1/dialect/base",
28
+ "properties": {
29
+ "$schema": { "$ref": "#/$defs/dialect" }
30
+ }
31
+ }
32
+ }
33
+ };
@@ -0,0 +1,33 @@
1
+ export default {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+
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
+ "https://spec.openapis.org/oas/3.1/vocab/base": false
13
+ },
14
+
15
+ "description": "OpenAPI v3.1.x documents using draft-07 JSON Schemas",
16
+
17
+ "$ref": "https://spec.openapis.org/oas/3.1/schema",
18
+ "properties": {
19
+ "jsonSchemaDialect": { "$ref": "#/$defs/dialect" }
20
+ },
21
+
22
+ "$defs": {
23
+ "dialect": { "const": "http://json-schema.org/draft-07/schema#" },
24
+
25
+ "schema": {
26
+ "$dynamicAnchor": "meta",
27
+ "$ref": "https://spec.openapis.org/oas/3.1/dialect/base",
28
+ "properties": {
29
+ "$schema": { "$ref": "#/$defs/dialect" }
30
+ }
31
+ }
32
+ }
33
+ };
@@ -0,0 +1,33 @@
1
+ export default {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+
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
+ "https://spec.openapis.org/oas/3.1/vocab/base": false
13
+ },
14
+
15
+ "description": "openapi v3.1.x documents using 2019-09 json schemas",
16
+
17
+ "$ref": "https://spec.openapis.org/oas/3.1/schema",
18
+ "properties": {
19
+ "jsonschemadialect": { "$ref": "#/$defs/dialect" }
20
+ },
21
+
22
+ "$defs": {
23
+ "dialect": { "const": "https://json-schema.org/draft/2019-09/schema" },
24
+
25
+ "schema": {
26
+ "$dynamicanchor": "meta",
27
+ "$ref": "https://spec.openapis.org/oas/3.1/dialect/base",
28
+ "properties": {
29
+ "$schema": { "$ref": "#/$defs/dialect" }
30
+ }
31
+ }
32
+ }
33
+ };
@@ -0,0 +1,33 @@
1
+ export default {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+
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
+ "https://spec.openapis.org/oas/3.1/vocab/base": false
13
+ },
14
+
15
+ "description": "openapi v3.1.x documents using 2020-12 json schemas",
16
+
17
+ "$ref": "https://spec.openapis.org/oas/3.1/schema",
18
+ "properties": {
19
+ "jsonschemadialect": { "$ref": "#/$defs/dialect" }
20
+ },
21
+
22
+ "$defs": {
23
+ "dialect": { "const": "https://json-schema.org/draft/2020-12/schema" },
24
+
25
+ "schema": {
26
+ "$dynamicanchor": "meta",
27
+ "$ref": "https://spec.openapis.org/oas/3.1/dialect/base",
28
+ "properties": {
29
+ "$schema": { "$ref": "#/$defs/dialect" }
30
+ }
31
+ }
32
+ }
33
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperjump/json-schema",
3
- "version": "1.6.7",
3
+ "version": "1.7.0",
4
4
  "description": "A JSON Schema validator with support for custom keywords, vocabularies, and dialects",
5
5
  "type": "module",
6
6
  "main": "./stable/index.js",
@@ -14,22 +14,20 @@
14
14
  "./openapi-3-0": "./openapi-3-0/index.js",
15
15
  "./openapi-3-1": "./openapi-3-1/index.js",
16
16
  "./experimental": "./lib/experimental.js",
17
- "./schema/experimental": "./lib/schema.js",
18
17
  "./instance/experimental": "./lib/instance.js",
19
18
  "./annotations/experimental": "./annotations/index.js",
20
19
  "./annotated-instance/experimental": "./annotations/annotated-instance.js",
21
20
  "./bundle": "./bundle/index.js"
22
21
  },
23
- "browser": {
24
- "./lib/fetch.js": "./lib/fetch.browser.js",
25
- "./lib/context-uri.js": "./lib/context-uri.browser.js"
26
- },
27
22
  "scripts": {
28
23
  "clean": "xargs -a .gitignore rm -rf",
29
24
  "lint": "eslint lib stable draft-* openapi-* bundle annotations",
30
25
  "test": "vitest --watch=false"
31
26
  },
32
- "repository": "github:hyperjump-io/json-schema",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/hyperjump-io/json-schema.git"
30
+ },
33
31
  "keywords": [
34
32
  "JSON Schema",
35
33
  "json-schema",
@@ -51,10 +49,12 @@
51
49
  "url": "https://github.com/sponsors/jdesrosiers"
52
50
  },
53
51
  "devDependencies": {
52
+ "@types/content-type": "*",
54
53
  "@types/node": "*",
54
+ "@types/uuid": "*",
55
55
  "@typescript-eslint/eslint-plugin": "*",
56
56
  "@typescript-eslint/parser": "*",
57
- "@vitest/coverage-v8": "^1.0.4",
57
+ "@vitest/coverage-v8": "*",
58
58
  "eslint": "*",
59
59
  "eslint-import-resolver-exports": "*",
60
60
  "eslint-import-resolver-node": "*",
@@ -62,6 +62,7 @@
62
62
  "eslint-plugin-import": "*",
63
63
  "json-schema-test-suite": "github:json-schema-org/JSON-Schema-Test-Suite",
64
64
  "typescript": "*",
65
+ "undici": "*",
65
66
  "vitest": "*",
66
67
  "yaml": "*"
67
68
  },
@@ -72,10 +73,9 @@
72
73
  "content-type": "^1.0.4",
73
74
  "fastest-stable-stringify": "^2.0.2",
74
75
  "just-curry-it": "^5.3.0",
75
- "undici": "^5.19.1",
76
76
  "uuid": "^9.0.0"
77
77
  },
78
- "engines": {
79
- "node": ">=18.0.0"
78
+ "peerDependencies": {
79
+ "@hyperjump/browser": "^1.1.0"
80
80
  }
81
81
  }
package/stable/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { defineVocabulary, loadDialect } from "../lib/keywords.js";
2
- import { addSchema } from "../lib/core.js";
2
+ import { registerSchema } from "../lib/index.js";
3
3
 
4
4
  import metaSchema from "./validation.js";
5
5
  import coreMetaSchema from "./meta/core.js";
@@ -108,14 +108,14 @@ loadDialect(dialectId, {
108
108
  "https://json-schema.org/vocab/unevaluated": true
109
109
  });
110
110
 
111
- addSchema(metaSchema, dialectId);
112
- addSchema(coreMetaSchema, "https://json-schema.org/meta/core");
113
- addSchema(applicatorMetaSchema, "https://json-schema.org/meta/applicator");
114
- addSchema(validationMetaSchema, "https://json-schema.org/meta/validation");
115
- addSchema(metaDataMetaSchema, "https://json-schema.org/meta/meta-data");
116
- addSchema(formatAnnotationMetaSchema, "https://json-schema.org/meta/format-annotation");
117
- addSchema(formatAssertionMetaSchema, "https://json-schema.org/meta/format-assertion");
118
- addSchema(contentMetaSchema, "https://json-schema.org/meta/content");
119
- addSchema(unevaluatedMetaSchema, "https://json-schema.org/meta/unevaluated");
111
+ registerSchema(metaSchema, dialectId);
112
+ registerSchema(coreMetaSchema, "https://json-schema.org/meta/core");
113
+ registerSchema(applicatorMetaSchema, "https://json-schema.org/meta/applicator");
114
+ registerSchema(validationMetaSchema, "https://json-schema.org/meta/validation");
115
+ registerSchema(metaDataMetaSchema, "https://json-schema.org/meta/meta-data");
116
+ registerSchema(formatAnnotationMetaSchema, "https://json-schema.org/meta/format-annotation");
117
+ registerSchema(formatAssertionMetaSchema, "https://json-schema.org/meta/format-assertion");
118
+ registerSchema(contentMetaSchema, "https://json-schema.org/meta/content");
119
+ registerSchema(unevaluatedMetaSchema, "https://json-schema.org/meta/unevaluated");
120
120
 
121
121
  export * from "../lib/index.js";
@@ -1,8 +0,0 @@
1
- import type { OutputUnit } from "../lib/core.js";
2
-
3
-
4
- export class ValidationError extends Error {
5
- public output: OutputUnit;
6
-
7
- public constructor(output: OutputUnit);
8
- }
@@ -1,44 +0,0 @@
1
- import { pipe, filter, reduce, zip, range, map, collectSet } from "@hyperjump/pact";
2
- import * as Instance from "../lib/instance.js";
3
- import * as Schema from "../lib/schema.js";
4
- import { getKeywordName } from "../lib/keywords.js";
5
- import Validation from "../lib/keywords/validation.js";
6
-
7
-
8
- const id = "https://json-schema.org/keyword/draft-2019-09/contains";
9
-
10
- const compile = async (schema, ast, parentSchema) => {
11
- const contains = await Validation.compile(schema, ast);
12
-
13
- const minContainsKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/minContains");
14
- const minContainsSchema = await Schema.step(minContainsKeyword, parentSchema);
15
- const minContains = Schema.typeOf(minContainsSchema, "number") ? Schema.value(minContainsSchema) : 1;
16
-
17
- const maxContainsKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/maxContains");
18
- const maxContainsSchema = await Schema.step(maxContainsKeyword, parentSchema);
19
- const maxContains = Schema.typeOf(maxContainsSchema, "number") ? Schema.value(maxContainsSchema) : Number.MAX_SAFE_INTEGER;
20
-
21
- return { contains, minContains, maxContains };
22
- };
23
-
24
- const interpret = ({ contains, minContains, maxContains }, instance, ast, dynamicAnchors, quiet) => {
25
- const matches = !Instance.typeOf(instance, "array") || pipe(
26
- Instance.iter(instance),
27
- filter((item) => Validation.interpret(contains, item, ast, dynamicAnchors, quiet)),
28
- reduce((matches) => matches + 1, 0)
29
- );
30
- return matches >= minContains && matches <= maxContains;
31
- };
32
-
33
- const collectEvaluatedItems = (keywordValue, instance, ast, dynamicAnchors) => {
34
- return interpret(keywordValue, instance, ast, dynamicAnchors, true)
35
- && Instance.typeOf(instance, "array")
36
- && pipe(
37
- zip(Instance.iter(instance), range(0)),
38
- filter(([item]) => Validation.interpret(keywordValue.contains, item, ast, dynamicAnchors, true)),
39
- map(([, itemIndex]) => itemIndex),
40
- collectSet
41
- );
42
- };
43
-
44
- export default { id, compile, interpret, collectEvaluatedItems };
@@ -1,9 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export const contextUri = () => document.location.toString();
@@ -1,4 +0,0 @@
1
- import { cwd } from "node:process";
2
-
3
-
4
- export const contextUri = () => `file://${cwd()}/`;
package/lib/core.d.ts DELETED
@@ -1,48 +0,0 @@
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";
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
- };
@@ -1 +0,0 @@
1
- export default fetch;
package/lib/fetch.js DELETED
@@ -1,20 +0,0 @@
1
- import { createReadStream } from "node:fs";
2
- import { Readable } from "node:stream";
3
- import { fileURLToPath } from "node:url";
4
- import { fetch, Response } from "undici";
5
- import * as MediaTypes from "./media-types.js";
6
-
7
-
8
- export default (url, options) => {
9
- if (url.startsWith("file://")) {
10
- const filePath = fileURLToPath(url);
11
- const stream = createReadStream(filePath);
12
- const response = new Response(Readable.toWeb(stream), {
13
- headers: { "Content-Type": MediaTypes.getContentType(filePath) }
14
- });
15
- Object.defineProperty(response, "url", { value: url });
16
- return response;
17
- } else {
18
- return fetch(url, options);
19
- }
20
- };
@@ -1,8 +0,0 @@
1
- import type { OutputUnit } from "./core.js";
2
-
3
-
4
- export class InvalidSchemaError extends Error {
5
- public output: OutputUnit;
6
-
7
- public constructor(output: OutputUnit);
8
- }
package/lib/keywords.d.ts DELETED
@@ -1,19 +0,0 @@
1
- import type { AST } from "./core.js";
2
- import type { JsonDocument } from "./instance.js";
3
- import type { SchemaDocument, Anchors } from "./schema.js";
4
-
5
-
6
- export const addKeyword: <A>(keywordHandler: Keyword<A>) => void;
7
- export const getKeywordName: (dialectId: string, keywordId: string) => string;
8
- export const getKeyword: <A>(id: string) => Keyword<A>;
9
- export const defineVocabulary: (id: string, keywords: { [keyword: string]: string }) => void;
10
- export const loadDialect: (dialectId: string, dialect: { [vocabularyId: string]: boolean }, allowUnknownKeywords?: boolean) => void;
11
-
12
- export type Keyword<A> = {
13
- id: string;
14
- experimental?: boolean;
15
- compile: (schema: SchemaDocument, ast: AST, parentSchema: SchemaDocument) => Promise<A>;
16
- interpret: (compiledKeywordValue: A, instance: JsonDocument, ast: AST, dynamicAnchors: Anchors) => boolean;
17
- collectEvaluatedProperties?: (compiledKeywordValue: A, instance: JsonDocument, ast: AST, dynamicAnchors: Anchors, isTop?: boolean) => string[] | false;
18
- collectEvaluatedItems?: (compiledKeywordValue: A, instance: JsonDocument, ast: AST, dynamicAnchors: Anchors, isTop?: boolean) => Set<number> | false;
19
- };
@@ -1,11 +0,0 @@
1
- import type { SchemaObject } from "./schema.js";
2
- import type { Response } from "undici";
3
-
4
-
5
- export const addMediaTypePlugin: (contentType: string, plugin: MediaTypePlugin) => void;
6
-
7
- export type MediaTypePlugin = {
8
- parse: (response: Response, mediaTypeParameters: { [parameter: string]: string }) => Promise<[SchemaObject, string | undefined]>;
9
- matcher: (path: string) => boolean;
10
- quality?: string;
11
- };
@@ -1,48 +0,0 @@
1
- import contentTypeParser from "content-type";
2
-
3
-
4
- const mediaTypePlugins = {};
5
-
6
- export const addMediaTypePlugin = (contentType, plugin) => {
7
- mediaTypePlugins[contentType] = plugin;
8
- };
9
-
10
- export const parseResponse = (response) => {
11
- const contentType = contentTypeParser.parse(response.headers.get("content-type"));
12
- if (!(contentType.type in mediaTypePlugins)) {
13
- throw Error(`${response.url} is not a schema. Found a document with media type: ${contentType.type}`);
14
- }
15
- return mediaTypePlugins[contentType.type].parse(response, contentType.parameters);
16
- };
17
-
18
- export const getContentType = (path) => {
19
- for (const contentType in mediaTypePlugins) {
20
- if (mediaTypePlugins[contentType].matcher(path)) {
21
- return contentType;
22
- }
23
- }
24
-
25
- return "application/octet-stream";
26
- };
27
-
28
- export const acceptableMediaTypes = () => {
29
- let accept = "";
30
-
31
- for (const contentType in mediaTypePlugins) {
32
- accept = addAcceptableMediaType(accept, contentType, mediaTypePlugins[contentType].quality);
33
- }
34
-
35
- return addAcceptableMediaType(accept, "*/*", "0.1");
36
- };
37
-
38
- const addAcceptableMediaType = (accept, contentType, quality) => {
39
- if (accept.length > 0) {
40
- accept += ", ";
41
- }
42
- accept += contentType;
43
- if (quality) {
44
- accept += `; q=${quality}`;
45
- }
46
-
47
- return accept;
48
- };
@@ -1,11 +0,0 @@
1
- export const cons: (href: string, value: unknown) => Ref;
2
- export const isReference: (ref: unknown) => ref is Ref;
3
- export const href: (ref: Ref) => string;
4
- export const value: <A>(ref: Ref) => A;
5
-
6
- declare const $__value: unique symbol;
7
- declare const $__href: unique symbol;
8
- export type Ref = {
9
- [$__href]: string;
10
- [$__value]: unknown;
11
- };
package/lib/reference.js DELETED
@@ -1,11 +0,0 @@
1
- const $__value = Symbol("$__value");
2
- const $__href = Symbol("$__href");
3
-
4
- export const cons = (href, value) => ({
5
- [$__href]: href,
6
- [$__value]: value
7
- });
8
-
9
- export const isReference = (ref) => ref && ref[$__href] !== undefined;
10
- export const href = (ref) => ref[$__href];
11
- export const value = (ref) => ref[$__value];