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