@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.
- package/LICENSE +1 -1
- package/README.md +459 -120
- package/draft-04/additionalItems.js +29 -0
- package/{lib/keywords → draft-04}/dependencies.js +9 -5
- package/draft-04/exclusiveMaximum.js +5 -0
- package/draft-04/exclusiveMinimum.js +5 -0
- package/draft-04/id.js +1 -0
- package/draft-04/index.d.ts +43 -0
- package/draft-04/index.js +69 -0
- package/draft-04/items.js +35 -0
- package/draft-04/maximum.js +26 -0
- package/draft-04/minimum.js +25 -0
- package/draft-04/ref.js +1 -0
- package/draft-04/schema.js +149 -0
- package/draft-06/contains.js +13 -0
- package/draft-06/index.d.ts +47 -0
- package/draft-06/index.js +66 -0
- package/draft-06/schema.js +154 -0
- package/{lib/draft-07.d.ts → draft-07/index.d.ts} +21 -19
- package/draft-07/index.js +72 -0
- package/draft-07/schema.js +172 -0
- package/{lib/keywords/contains-minContains-maxContains.js → draft-2019-09/contains.js} +14 -7
- package/{lib/draft-2019-09.d.ts → draft-2019-09/index.d.ts} +24 -22
- package/draft-2019-09/index.js +117 -0
- package/draft-2019-09/meta/applicator.js +55 -0
- package/draft-2019-09/meta/content.js +17 -0
- package/draft-2019-09/meta/core.js +57 -0
- package/draft-2019-09/meta/format.js +14 -0
- package/draft-2019-09/meta/meta-data.js +37 -0
- package/draft-2019-09/meta/validation.js +98 -0
- package/draft-2019-09/recursiveAnchor.js +1 -0
- package/draft-2019-09/recursiveRef.js +19 -0
- package/draft-2019-09/schema.js +42 -0
- package/draft-2020-12/dynamicAnchor.js +1 -0
- package/draft-2020-12/dynamicRef.js +35 -0
- package/draft-2020-12/index.d.ts +66 -0
- package/draft-2020-12/index.js +124 -0
- package/draft-2020-12/meta/applicator.js +46 -0
- package/draft-2020-12/meta/content.js +14 -0
- package/draft-2020-12/meta/core.js +54 -0
- package/draft-2020-12/meta/format-annotation.js +11 -0
- package/draft-2020-12/meta/format-assertion.js +11 -0
- package/draft-2020-12/meta/meta-data.js +34 -0
- package/draft-2020-12/meta/unevaluated.js +12 -0
- package/draft-2020-12/meta/validation.js +95 -0
- package/draft-2020-12/schema.js +44 -0
- package/lib/common.d.ts +5 -1
- package/lib/common.js +80 -9
- package/lib/configuration.d.ts +9 -0
- package/lib/configuration.js +18 -0
- package/lib/core.d.ts +48 -0
- package/lib/core.js +102 -0
- package/lib/experimental.d.ts +8 -0
- package/lib/experimental.js +4 -0
- package/lib/fetch.browser.js +1 -0
- package/lib/fetch.js +19 -0
- package/lib/index.d.ts +11 -42
- package/lib/index.js +130 -23
- package/lib/instance.d.ts +75 -0
- package/lib/instance.js +58 -0
- package/lib/invalid-schema-error.d.ts +8 -0
- package/lib/invalid-schema-error.js +7 -0
- package/lib/keywords/additionalProperties.js +19 -17
- package/lib/keywords/allOf.js +10 -7
- package/lib/keywords/anchor.js +1 -0
- package/lib/keywords/anyOf.js +10 -7
- package/lib/keywords/comment.js +4 -0
- package/lib/keywords/const.js +6 -3
- package/lib/keywords/contains.js +48 -5
- package/lib/keywords/contentEncoding.js +4 -0
- package/lib/keywords/contentMediaType.js +4 -0
- package/lib/keywords/contentSchema.js +4 -0
- package/lib/keywords/default.js +4 -0
- package/lib/keywords/definitions.js +7 -4
- package/lib/keywords/dependentRequired.js +6 -3
- package/lib/keywords/dependentSchemas.js +10 -6
- package/lib/keywords/deprecated.js +4 -0
- package/lib/keywords/description.js +4 -0
- package/lib/keywords/dynamicAnchor.js +1 -0
- package/lib/keywords/dynamicRef.js +13 -17
- package/lib/keywords/else.js +16 -11
- package/lib/keywords/enum.js +6 -3
- package/lib/keywords/examples.js +4 -0
- package/lib/keywords/exclusiveMaximum.js +5 -2
- package/lib/keywords/exclusiveMinimum.js +5 -2
- package/lib/keywords/format.js +4 -0
- package/lib/keywords/id.js +1 -0
- package/lib/keywords/if.js +8 -6
- package/lib/keywords/items.js +17 -19
- package/lib/keywords/maxContains.js +4 -0
- package/lib/keywords/maxItems.js +5 -2
- package/lib/keywords/maxLength.js +5 -2
- package/lib/keywords/maxProperties.js +5 -2
- package/lib/keywords/maximum.js +5 -2
- package/lib/keywords/meta-data.js +4 -0
- package/lib/keywords/minContains.js +4 -0
- package/lib/keywords/minItems.js +5 -2
- package/lib/keywords/minLength.js +5 -2
- package/lib/keywords/minProperties.js +5 -2
- package/lib/keywords/minimum.js +5 -2
- package/lib/keywords/multipleOf.js +5 -2
- package/lib/keywords/not.js +6 -4
- package/lib/keywords/oneOf.js +9 -6
- package/lib/keywords/pattern.js +5 -2
- package/lib/keywords/patternProperties.js +9 -5
- package/lib/keywords/prefixItems.js +28 -0
- package/lib/keywords/properties.js +11 -6
- package/lib/keywords/propertyDependencies.js +49 -0
- package/lib/keywords/propertyNames.js +7 -4
- package/lib/keywords/readOnly.js +4 -0
- package/lib/keywords/ref.js +9 -6
- package/lib/keywords/requireAllExcept.js +24 -0
- package/lib/keywords/required.js +5 -2
- package/lib/keywords/then.js +16 -11
- package/lib/keywords/title.js +4 -0
- package/lib/keywords/type.js +5 -2
- package/lib/keywords/unevaluatedItems.js +9 -5
- package/lib/keywords/unevaluatedProperties.js +9 -5
- package/lib/keywords/uniqueItems.js +6 -3
- package/lib/keywords/validation.js +123 -0
- package/lib/keywords/vocabulary.js +1 -0
- package/lib/keywords/writeOnly.js +4 -0
- package/lib/keywords.d.ts +19 -0
- package/lib/keywords.js +59 -0
- package/lib/media-types.d.ts +9 -0
- package/lib/media-types.js +26 -0
- package/lib/pubsub.js +42 -0
- package/lib/reference.d.ts +11 -0
- package/lib/reference.js +11 -0
- package/lib/schema.d.ts +64 -0
- package/lib/schema.js +308 -0
- package/package.json +31 -22
- package/{lib/draft-2020-12.d.ts → stable/index.d.ts} +26 -24
- package/stable/index.js +118 -0
- package/stable/meta/applicator.js +49 -0
- package/stable/meta/content.js +12 -0
- package/stable/meta/core.js +49 -0
- package/stable/meta/format-annotation.js +10 -0
- package/stable/meta/format-assertion.js +10 -0
- package/stable/meta/meta-data.js +16 -0
- package/stable/meta/unevaluated.js +11 -0
- package/stable/meta/validation.js +67 -0
- package/stable/validation.js +24 -0
- package/dist/json-schema-amd.js +0 -6602
- package/dist/json-schema-amd.js.map +0 -1
- package/dist/json-schema-amd.min.js +0 -3
- package/dist/json-schema-amd.min.js.map +0 -1
- package/dist/json-schema-cjs.js +0 -6600
- package/dist/json-schema-cjs.js.map +0 -1
- package/dist/json-schema-cjs.min.js +0 -3
- package/dist/json-schema-cjs.min.js.map +0 -1
- package/dist/json-schema-esm.js +0 -6596
- package/dist/json-schema-esm.js.map +0 -1
- package/dist/json-schema-esm.min.js +0 -3
- package/dist/json-schema-esm.min.js.map +0 -1
- package/dist/json-schema-iife.js +0 -6605
- package/dist/json-schema-iife.js.map +0 -1
- package/dist/json-schema-iife.min.js +0 -3
- package/dist/json-schema-iife.min.js.map +0 -1
- package/dist/json-schema-system.js +0 -6603
- package/dist/json-schema-system.js.map +0 -1
- package/dist/json-schema-system.min.js +0 -3
- package/dist/json-schema-system.min.js.map +0 -1
- package/dist/json-schema-umd.js +0 -6606
- package/dist/json-schema-umd.js.map +0 -1
- package/dist/json-schema-umd.min.js +0 -3
- package/dist/json-schema-umd.min.js.map +0 -1
- package/lib/draft-04.d.ts +0 -41
- package/lib/draft-04.js +0 -46
- package/lib/draft-06.d.ts +0 -45
- package/lib/draft-06.js +0 -51
- package/lib/draft-07.js +0 -55
- package/lib/draft-2019-09.js +0 -92
- package/lib/draft-2020-12.js +0 -103
- package/lib/index.mjs +0 -19
- package/lib/keywords/additionalItems.js +0 -27
- package/lib/keywords/additionalItems6.js +0 -23
- package/lib/keywords/additionalProperties6.js +0 -28
- package/lib/keywords/index.js +0 -53
- package/lib/keywords/items202012.js +0 -23
- package/lib/keywords/maximum-exclusiveMaximum.js +0 -20
- package/lib/keywords/minimum-exclusiveMinimum.js +0 -20
- package/lib/keywords/tupleItems.js +0 -24
- package/meta/draft/2019-09/meta/applicator.js +0 -55
- package/meta/draft/2019-09/meta/content.js +0 -17
- package/meta/draft/2019-09/meta/core.js +0 -57
- package/meta/draft/2019-09/meta/format.js +0 -14
- package/meta/draft/2019-09/meta/meta-data.js +0 -37
- package/meta/draft/2019-09/meta/validation.js +0 -98
- package/meta/draft/2019-09/schema.js +0 -42
- package/meta/draft/2020-12/meta/applicator.js +0 -49
- package/meta/draft/2020-12/meta/content.js +0 -17
- package/meta/draft/2020-12/meta/core.js +0 -57
- package/meta/draft/2020-12/meta/format-annotation.js +0 -14
- package/meta/draft/2020-12/meta/format-assertion.js +0 -14
- package/meta/draft/2020-12/meta/meta-data.js +0 -37
- package/meta/draft/2020-12/meta/unevaluated.js +0 -15
- package/meta/draft/2020-12/meta/validation.js +0 -98
- package/meta/draft/2020-12/schema.js +0 -44
- package/meta/draft-04/schema.js +0 -149
- package/meta/draft-06/schema.js +0 -154
- package/meta/draft-07/schema.js +0 -172
package/lib/keywords/const.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import jsonStringify from "fastest-stable-stringify";
|
|
2
|
+
import * as Schema from "../schema.js";
|
|
3
|
+
import * as Instance from "../instance.js";
|
|
3
4
|
|
|
4
5
|
|
|
6
|
+
const id = "https://json-schema.org/keyword/const";
|
|
7
|
+
|
|
5
8
|
const compile = (schema) => jsonStringify(Schema.value(schema));
|
|
6
9
|
const interpret = (const_, instance) => jsonStringify(Instance.value(instance)) === const_;
|
|
7
10
|
|
|
8
|
-
|
|
11
|
+
export default { id, compile, interpret };
|
package/lib/keywords/contains.js
CHANGED
|
@@ -1,10 +1,53 @@
|
|
|
1
|
-
|
|
1
|
+
import * as Schema from "../schema.js";
|
|
2
|
+
import * as Instance from "../instance.js";
|
|
3
|
+
import { getKeywordName } from "../keywords.js";
|
|
4
|
+
import Validation from "./validation.js";
|
|
2
5
|
|
|
3
6
|
|
|
4
|
-
const
|
|
7
|
+
const id = "https://json-schema.org/keyword/contains";
|
|
5
8
|
|
|
6
|
-
const
|
|
7
|
-
|
|
9
|
+
const compile = async (schema, ast, parentSchema) => {
|
|
10
|
+
const contains = await Validation.compile(schema, ast);
|
|
11
|
+
|
|
12
|
+
const minContainsKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/minContains");
|
|
13
|
+
const minContainsSchema = await Schema.step(minContainsKeyword, parentSchema);
|
|
14
|
+
const minContains = Schema.typeOf(minContainsSchema, "number") ? Schema.value(minContainsSchema) : 1;
|
|
15
|
+
|
|
16
|
+
const maxContainsKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/maxContains");
|
|
17
|
+
const maxContainsSchema = await Schema.step(maxContainsKeyword, parentSchema);
|
|
18
|
+
const maxContains = Schema.typeOf(maxContainsSchema, "number") ? Schema.value(maxContainsSchema) : Number.MAX_SAFE_INTEGER;
|
|
19
|
+
|
|
20
|
+
return { contains, minContains, maxContains };
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const interpret = ({ contains, minContains, maxContains }, instance, ast, dynamicAnchors) => {
|
|
24
|
+
if (!Instance.typeOf(instance, "array") && !Instance.typeOf(instance, "object")) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const matches = Instance.entries(instance).reduce((matches, [, item]) => {
|
|
29
|
+
return Validation.interpret(contains, item, ast, dynamicAnchors) ? matches + 1 : matches;
|
|
30
|
+
}, 0);
|
|
31
|
+
return matches >= minContains && matches <= maxContains;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const collectEvaluatedItems = (keywordValue, instance, ast, dynamicAnchors) => {
|
|
35
|
+
return interpret(keywordValue, instance, ast, dynamicAnchors) &&
|
|
36
|
+
Instance.typeOf(instance, "array") &&
|
|
37
|
+
Instance.reduce((matchedIndexes, item, itemIndex) => {
|
|
38
|
+
return Validation.interpret(keywordValue.contains, item, ast, dynamicAnchors) ? matchedIndexes.add(itemIndex) : matchedIndexes;
|
|
39
|
+
}, new Set(), instance);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const collectEvaluatedProperties = (keywordValue, instance, ast, dynamicAnchors) => {
|
|
43
|
+
return interpret(keywordValue, instance, ast, dynamicAnchors) &&
|
|
44
|
+
Instance.typeOf(instance, "object") &&
|
|
45
|
+
Instance.entries(instance).reduce((matchedPropertyNames, [propertyName, item]) => {
|
|
46
|
+
if (Validation.interpret(keywordValue.contains, item, ast, dynamicAnchors)) {
|
|
47
|
+
matchedPropertyNames.push(propertyName);
|
|
48
|
+
}
|
|
49
|
+
return matchedPropertyNames;
|
|
50
|
+
}, [], instance);
|
|
8
51
|
};
|
|
9
52
|
|
|
10
|
-
|
|
53
|
+
export default { id, compile, interpret, collectEvaluatedItems, collectEvaluatedProperties };
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as Pact from "@hyperjump/pact";
|
|
2
|
+
import * as Schema from "../schema.js";
|
|
3
|
+
import Validation from "./validation.js";
|
|
3
4
|
|
|
4
5
|
|
|
6
|
+
const id = "https://json-schema.org/keyword/definitions";
|
|
7
|
+
|
|
5
8
|
const compile = async (schema, ast) => {
|
|
6
9
|
await Pact.pipeline([
|
|
7
10
|
Schema.entries,
|
|
8
|
-
Pact.map(([, definitionSchema]) =>
|
|
11
|
+
Pact.map(([, definitionSchema]) => Validation.compile(definitionSchema, ast)),
|
|
9
12
|
Pact.all
|
|
10
13
|
], schema);
|
|
11
14
|
};
|
|
12
15
|
|
|
13
16
|
const interpret = () => true;
|
|
14
17
|
|
|
15
|
-
|
|
18
|
+
export default { id, compile, interpret };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as Pact from "@hyperjump/pact";
|
|
2
|
+
import * as Schema from "../schema.js";
|
|
3
|
+
import * as Instance from "../instance.js";
|
|
3
4
|
|
|
4
5
|
|
|
6
|
+
const id = "https://json-schema.org/keyword/dependentRequired";
|
|
7
|
+
|
|
5
8
|
const compile = (schema) => Pact.pipeline([
|
|
6
9
|
Schema.entries,
|
|
7
10
|
Pact.map(([key, dependentRequired]) => [key, Schema.value(dependentRequired)]),
|
|
@@ -16,4 +19,4 @@ const interpret = (dependentRequired, instance) => {
|
|
|
16
19
|
});
|
|
17
20
|
};
|
|
18
21
|
|
|
19
|
-
|
|
22
|
+
export default { id, compile, interpret };
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as Pact from "@hyperjump/pact";
|
|
2
|
+
import * as Schema from "../schema.js";
|
|
3
|
+
import * as Instance from "../instance.js";
|
|
4
|
+
import Validation from "./validation.js";
|
|
3
5
|
|
|
4
6
|
|
|
7
|
+
const id = "https://json-schema.org/keyword/dependentSchemas";
|
|
8
|
+
|
|
5
9
|
const compile = (schema, ast) => Pact.pipeline([
|
|
6
10
|
Schema.entries,
|
|
7
|
-
Pact.map(async ([key, dependentSchema]) => [key, await
|
|
11
|
+
Pact.map(async ([key, dependentSchema]) => [key, await Validation.compile(dependentSchema, ast)]),
|
|
8
12
|
Pact.all
|
|
9
13
|
], schema);
|
|
10
14
|
|
|
@@ -12,7 +16,7 @@ const interpret = (dependentSchemas, instance, ast, dynamicAnchors) => {
|
|
|
12
16
|
const value = Instance.value(instance);
|
|
13
17
|
|
|
14
18
|
return !Instance.typeOf(instance, "object") || dependentSchemas.every(([propertyName, dependentSchema]) => {
|
|
15
|
-
return !(propertyName in value) ||
|
|
19
|
+
return !(propertyName in value) || Validation.interpret(dependentSchema, instance, ast, dynamicAnchors);
|
|
16
20
|
});
|
|
17
21
|
};
|
|
18
22
|
|
|
@@ -22,9 +26,9 @@ const collectEvaluatedProperties = (dependentSchemas, instance, ast, dynamicAnch
|
|
|
22
26
|
return acc;
|
|
23
27
|
}
|
|
24
28
|
|
|
25
|
-
const propertyNames =
|
|
29
|
+
const propertyNames = Validation.collectEvaluatedProperties(dependentSchema, instance, ast, dynamicAnchors);
|
|
26
30
|
return propertyNames !== false && acc.concat(propertyNames);
|
|
27
31
|
}, []);
|
|
28
32
|
};
|
|
29
33
|
|
|
30
|
-
|
|
34
|
+
export default { id, compile, interpret, collectEvaluatedProperties };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default { id: "https://json-schema.org/keyword/dynamicAnchor" };
|
|
@@ -1,24 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as Schema from "../schema.js";
|
|
2
|
+
import Validation from "./validation.js";
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return [referencedSchema.id, fragment];
|
|
10
|
-
};
|
|
5
|
+
const id = "https://json-schema.org/keyword/dynamicRef";
|
|
6
|
+
const experimental = true;
|
|
7
|
+
|
|
8
|
+
const compile = Schema.value;
|
|
11
9
|
|
|
12
|
-
const interpret = (
|
|
13
|
-
if (fragment in
|
|
14
|
-
|
|
15
|
-
} else {
|
|
16
|
-
const pointer = Schema.getAnchorPointer(ast.metaData[id], fragment);
|
|
17
|
-
return Core.interpretSchema(`${id}#${encodeURI(pointer)}`, instance, ast, dynamicAnchors);
|
|
10
|
+
const interpret = (fragment, instance, ast, dynamicAnchors) => {
|
|
11
|
+
if (!(fragment in dynamicAnchors)) {
|
|
12
|
+
throw Error(`No dynamic anchor found for "${fragment}"`);
|
|
18
13
|
}
|
|
14
|
+
return Validation.interpret(dynamicAnchors[fragment], instance, ast, dynamicAnchors);
|
|
19
15
|
};
|
|
20
16
|
|
|
21
|
-
const collectEvaluatedProperties =
|
|
22
|
-
const collectEvaluatedItems =
|
|
17
|
+
const collectEvaluatedProperties = Validation.collectEvaluatedProperties;
|
|
18
|
+
const collectEvaluatedItems = Validation.collectEvaluatedItems;
|
|
23
19
|
|
|
24
|
-
|
|
20
|
+
export default { id, experimental, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
|
package/lib/keywords/else.js
CHANGED
|
@@ -1,26 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
import * as Schema from "../schema.js";
|
|
2
|
+
import { getKeywordName, getKeyword } from "../keywords.js";
|
|
3
|
+
import Validation from "./validation.js";
|
|
2
4
|
|
|
3
5
|
|
|
6
|
+
const id = "https://json-schema.org/keyword/else";
|
|
7
|
+
|
|
4
8
|
const compile = async (schema, ast, parentSchema) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
const ifKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/if");
|
|
10
|
+
if (Schema.has(ifKeyword, parentSchema)) {
|
|
11
|
+
const ifSchema = await Schema.step(ifKeyword, parentSchema);
|
|
12
|
+
return [await Validation.compile(ifSchema, ast), await Validation.compile(schema, ast)];
|
|
8
13
|
} else {
|
|
9
14
|
return [];
|
|
10
15
|
}
|
|
11
16
|
};
|
|
12
17
|
|
|
13
18
|
const interpret = ([guard, block], instance, ast, dynamicAnchors) => {
|
|
14
|
-
return guard === undefined || quietInterpretSchema(guard, instance, ast, dynamicAnchors) ||
|
|
19
|
+
return guard === undefined || quietInterpretSchema(guard, instance, ast, dynamicAnchors) || Validation.interpret(block, instance, ast, dynamicAnchors);
|
|
15
20
|
};
|
|
16
21
|
|
|
17
22
|
// Interpret a schema without events being emitted
|
|
18
|
-
const quietInterpretSchema = (
|
|
19
|
-
const nodes = ast[
|
|
23
|
+
const quietInterpretSchema = (url, instance, ast, dynamicAnchors) => {
|
|
24
|
+
const nodes = ast[url][2];
|
|
20
25
|
|
|
21
26
|
return typeof nodes === "boolean" ? nodes : nodes
|
|
22
27
|
.every(([keywordId, , keywordValue]) => {
|
|
23
|
-
return
|
|
28
|
+
return getKeyword(keywordId).interpret(keywordValue, instance, ast, dynamicAnchors);
|
|
24
29
|
});
|
|
25
30
|
};
|
|
26
31
|
|
|
@@ -29,7 +34,7 @@ const collectEvaluatedProperties = ([guard, block], instance, ast, dynamicAnchor
|
|
|
29
34
|
return [];
|
|
30
35
|
}
|
|
31
36
|
|
|
32
|
-
return
|
|
37
|
+
return Validation.collectEvaluatedProperties(block, instance, ast, dynamicAnchors);
|
|
33
38
|
};
|
|
34
39
|
|
|
35
40
|
const collectEvaluatedItems = ([guard, block], instance, ast, dynamicAnchors) => {
|
|
@@ -37,7 +42,7 @@ const collectEvaluatedItems = ([guard, block], instance, ast, dynamicAnchors) =>
|
|
|
37
42
|
return new Set();
|
|
38
43
|
}
|
|
39
44
|
|
|
40
|
-
return
|
|
45
|
+
return Validation.collectEvaluatedItems(block, instance, ast, dynamicAnchors);
|
|
41
46
|
};
|
|
42
47
|
|
|
43
|
-
|
|
48
|
+
export default { id, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
|
package/lib/keywords/enum.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import jsonStringify from "fastest-stable-stringify";
|
|
2
|
+
import * as Schema from "../schema.js";
|
|
3
|
+
import * as Instance from "../instance.js";
|
|
3
4
|
|
|
4
5
|
|
|
6
|
+
const id = "https://json-schema.org/keyword/enum";
|
|
7
|
+
|
|
5
8
|
const compile = (schema) => Schema.value(schema).map(jsonStringify);
|
|
6
9
|
const interpret = (enum_, instance) => enum_.some((enumValue) => jsonStringify(Instance.value(instance)) === enumValue);
|
|
7
10
|
|
|
8
|
-
|
|
11
|
+
export default { id, compile, interpret };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import * as Schema from "../schema.js";
|
|
2
|
+
import * as Instance from "../instance.js";
|
|
2
3
|
|
|
3
4
|
|
|
5
|
+
const id = "https://json-schema.org/keyword/exclusiveMaximum";
|
|
6
|
+
|
|
4
7
|
const compile = async (schema) => Schema.value(schema);
|
|
5
8
|
const interpret = (exclusiveMaximum, instance) => !Instance.typeOf(instance, "number") || Instance.value(instance) < exclusiveMaximum;
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
export default { id, compile, interpret };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import * as Schema from "../schema.js";
|
|
2
|
+
import * as Instance from "../instance.js";
|
|
2
3
|
|
|
3
4
|
|
|
5
|
+
const id = "https://json-schema.org/keyword/exclusiveMinimum";
|
|
6
|
+
|
|
4
7
|
const compile = async (schema) => Schema.value(schema);
|
|
5
8
|
const interpret = (exclusiveMinimum, instance) => !Instance.typeOf(instance, "number") || Instance.value(instance) > exclusiveMinimum;
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
export default { id, compile, interpret };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default { id: "https://json-schema.org/keyword/id" };
|
package/lib/keywords/if.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
import Validation from "./validation.js";
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const id = "https://json-schema.org/keyword/if";
|
|
5
|
+
|
|
6
|
+
const compile = (schema, ast) => Validation.compile(schema, ast);
|
|
5
7
|
|
|
6
8
|
const interpret = (ifSchema, instance, ast, dynamicAnchors) => {
|
|
7
|
-
|
|
9
|
+
Validation.interpret(ifSchema, instance, ast, dynamicAnchors);
|
|
8
10
|
return true;
|
|
9
11
|
};
|
|
10
12
|
|
|
11
13
|
const collectEvaluatedProperties = (ifSchema, instance, ast, dynamicAnchors) => {
|
|
12
|
-
return
|
|
14
|
+
return Validation.collectEvaluatedProperties(ifSchema, instance, ast, dynamicAnchors) || [];
|
|
13
15
|
};
|
|
14
16
|
|
|
15
17
|
const collectEvaluatedItems = (ifSchema, instance, ast, dynamicAnchors) => {
|
|
16
|
-
return
|
|
18
|
+
return Validation.collectEvaluatedItems(ifSchema, instance, ast, dynamicAnchors) || new Set();
|
|
17
19
|
};
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
export default { id, compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
|
package/lib/keywords/items.js
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
import * as Schema from "../schema.js";
|
|
2
|
+
import * as Instance from "../instance.js";
|
|
3
|
+
import { getKeywordName } from "../keywords.js";
|
|
4
|
+
import Validation from "./validation.js";
|
|
2
5
|
|
|
3
6
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const id = "https://json-schema.org/keyword/items";
|
|
8
|
+
|
|
9
|
+
const compile = async (schema, ast, parentSchema) => {
|
|
10
|
+
const prefixItemKeyword = getKeywordName(schema.dialectId, "https://json-schema.org/keyword/prefixItems");
|
|
11
|
+
const items = await Schema.step(prefixItemKeyword, parentSchema);
|
|
12
|
+
const numberOfPrefixItems = Schema.typeOf(items, "array") ? Schema.length(items) : 0;
|
|
13
|
+
|
|
14
|
+
return [numberOfPrefixItems, await Validation.compile(schema, ast)];
|
|
11
15
|
};
|
|
12
16
|
|
|
13
|
-
const interpret = (items, instance, ast, dynamicAnchors) => {
|
|
17
|
+
const interpret = ([numberOfPrefixItems, items], instance, ast, dynamicAnchors) => {
|
|
14
18
|
if (!Instance.typeOf(instance, "array")) {
|
|
15
19
|
return true;
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
return Instance.every((itemValue) => Core.interpretSchema(items, itemValue, ast, dynamicAnchors), instance);
|
|
20
|
-
} else {
|
|
21
|
-
return Instance.every((item, ndx) => !(ndx in items) || Core.interpretSchema(items[ndx], item, ast, dynamicAnchors), instance);
|
|
22
|
-
}
|
|
22
|
+
return Instance.every((item, ndx) => ndx < numberOfPrefixItems || Validation.interpret(items, item, ast, dynamicAnchors), instance);
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
-
const collectEvaluatedItems = (
|
|
26
|
-
return interpret(
|
|
27
|
-
? new Set(Instance.map((item, itemIndex) => itemIndex, instance))
|
|
28
|
-
: new Set(items.map((item, itemIndex) => itemIndex)));
|
|
25
|
+
const collectEvaluatedItems = (keywordValue, instance, ast, dynamicAnchors) => {
|
|
26
|
+
return interpret(keywordValue, instance, ast, dynamicAnchors) && new Set(Instance.map((item, ndx) => ndx, instance));
|
|
29
27
|
};
|
|
30
28
|
|
|
31
|
-
|
|
29
|
+
export default { id, compile, interpret, collectEvaluatedItems };
|
package/lib/keywords/maxItems.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import * as Schema from "../schema.js";
|
|
2
|
+
import * as Instance from "../instance.js";
|
|
2
3
|
|
|
3
4
|
|
|
5
|
+
const id = "https://json-schema.org/keyword/maxItems";
|
|
6
|
+
|
|
4
7
|
const compile = (schema) => Schema.value(schema);
|
|
5
8
|
const interpret = (maxItems, instance) => !Instance.typeOf(instance, "array") || Instance.length(instance) <= maxItems;
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
export default { id, compile, interpret };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import * as Schema from "../schema.js";
|
|
2
|
+
import * as Instance from "../instance.js";
|
|
2
3
|
|
|
3
4
|
|
|
5
|
+
const id = "https://json-schema.org/keyword/maxLength";
|
|
6
|
+
|
|
4
7
|
const compile = (schema) => Schema.value(schema);
|
|
5
8
|
const interpret = (maxLength, instance) => !Instance.typeOf(instance, "string") || [...Instance.value(instance)].length <= maxLength;
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
export default { id, compile, interpret };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import * as Schema from "../schema.js";
|
|
2
|
+
import * as Instance from "../instance.js";
|
|
2
3
|
|
|
3
4
|
|
|
5
|
+
const id = "https://json-schema.org/keyword/maxProperties";
|
|
6
|
+
|
|
4
7
|
const compile = (schema) => Schema.value(schema);
|
|
5
8
|
const interpret = (maxProperties, instance) => !Instance.typeOf(instance, "object") || Instance.keys(instance).length <= maxProperties;
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
export default { id, compile, interpret };
|
package/lib/keywords/maximum.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import * as Schema from "../schema.js";
|
|
2
|
+
import * as Instance from "../instance.js";
|
|
2
3
|
|
|
3
4
|
|
|
5
|
+
const id = "https://json-schema.org/keyword/maximum";
|
|
6
|
+
|
|
4
7
|
const compile = async (schema) => Schema.value(schema);
|
|
5
8
|
const interpret = (maximum, instance) => !Instance.typeOf(instance, "number") || Instance.value(instance) <= maximum;
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
export default { id, compile, interpret };
|
package/lib/keywords/minItems.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import * as Schema from "../schema.js";
|
|
2
|
+
import * as Instance from "../instance.js";
|
|
2
3
|
|
|
3
4
|
|
|
5
|
+
const id = "https://json-schema.org/keyword/minItems";
|
|
6
|
+
|
|
4
7
|
const compile = (schema) => Schema.value(schema);
|
|
5
8
|
const interpret = (minItems, instance) => !Instance.typeOf(instance, "array") || Instance.length(instance) >= minItems;
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
export default { id, compile, interpret };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import * as Schema from "../schema.js";
|
|
2
|
+
import * as Instance from "../instance.js";
|
|
2
3
|
|
|
3
4
|
|
|
5
|
+
const id = "https://json-schema.org/keyword/minLength";
|
|
6
|
+
|
|
4
7
|
const compile = (schema) => Schema.value(schema);
|
|
5
8
|
const interpret = (minLength, instance) => !Instance.typeOf(instance, "string") || [...Instance.value(instance)].length >= minLength;
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
export default { id, compile, interpret };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import * as Schema from "../schema.js";
|
|
2
|
+
import * as Instance from "../instance.js";
|
|
2
3
|
|
|
3
4
|
|
|
5
|
+
const id = "https://json-schema.org/keyword/minProperties";
|
|
6
|
+
|
|
4
7
|
const compile = (schema) => Schema.value(schema);
|
|
5
8
|
const interpret = (minProperties, instance) => !Instance.typeOf(instance, "object") || Instance.keys(instance).length >= minProperties;
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
export default { id, compile, interpret };
|
package/lib/keywords/minimum.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import * as Schema from "../schema.js";
|
|
2
|
+
import * as Instance from "../instance.js";
|
|
2
3
|
|
|
3
4
|
|
|
5
|
+
const id = "https://json-schema.org/keyword/minimum";
|
|
6
|
+
|
|
4
7
|
const compile = async (schema) => Schema.value(schema);
|
|
5
8
|
const interpret = (minimum, instance) => !Instance.typeOf(instance, "number") || Instance.value(instance) >= minimum;
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
export default { id, compile, interpret };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import * as Schema from "../schema.js";
|
|
2
|
+
import * as Instance from "../instance.js";
|
|
2
3
|
|
|
3
4
|
|
|
5
|
+
const id = "https://json-schema.org/keyword/multipleOf";
|
|
6
|
+
|
|
4
7
|
const compile = (schema) => Schema.value(schema);
|
|
5
8
|
|
|
6
9
|
const interpret = (multipleOf, instance) => {
|
|
@@ -14,4 +17,4 @@ const interpret = (multipleOf, instance) => {
|
|
|
14
17
|
|
|
15
18
|
const numberEqual = (a, b) => Math.abs(a - b) < 1.19209290e-7;
|
|
16
19
|
|
|
17
|
-
|
|
20
|
+
export default { id, compile, interpret };
|
package/lib/keywords/not.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import Validation from "./validation.js";
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
const interpret = (not, instance, ast, dynamicAnchors) => !Core.interpretSchema(not, instance, ast, dynamicAnchors);
|
|
4
|
+
const id = "https://json-schema.org/keyword/not";
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
const compile = Validation.compile;
|
|
7
|
+
const interpret = (not, instance, ast, dynamicAnchors) => !Validation.interpret(not, instance, ast, dynamicAnchors);
|
|
8
|
+
|
|
9
|
+
export default { id, compile, interpret };
|