@hyperjump/json-schema 0.18.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 +21 -0
- package/README.md +176 -0
- package/dist/json-schema-amd.js +4710 -0
- package/dist/json-schema-amd.js.map +1 -0
- package/dist/json-schema-amd.min.js +2 -0
- package/dist/json-schema-amd.min.js.map +1 -0
- package/dist/json-schema-cjs.js +4708 -0
- package/dist/json-schema-cjs.js.map +1 -0
- package/dist/json-schema-cjs.min.js +2 -0
- package/dist/json-schema-cjs.min.js.map +1 -0
- package/dist/json-schema-esm.js +4691 -0
- package/dist/json-schema-esm.js.map +1 -0
- package/dist/json-schema-esm.min.js +2 -0
- package/dist/json-schema-esm.min.js.map +1 -0
- package/dist/json-schema-iife.js +4713 -0
- package/dist/json-schema-iife.js.map +1 -0
- package/dist/json-schema-iife.min.js +2 -0
- package/dist/json-schema-iife.min.js.map +1 -0
- package/dist/json-schema-system.js +4698 -0
- package/dist/json-schema-system.js.map +1 -0
- package/dist/json-schema-system.min.js +2 -0
- package/dist/json-schema-system.min.js.map +1 -0
- package/dist/json-schema-umd.js +4714 -0
- package/dist/json-schema-umd.js.map +1 -0
- package/dist/json-schema-umd.min.js +2 -0
- package/dist/json-schema-umd.min.js.map +1 -0
- package/lib/common.js +13 -0
- package/lib/draft-04.d.ts +40 -0
- package/lib/draft-04.js +94 -0
- package/lib/draft-06.d.ts +44 -0
- package/lib/draft-06.js +51 -0
- package/lib/draft-07.d.ts +52 -0
- package/lib/draft-07.js +55 -0
- package/lib/draft-2019-09.d.ts +62 -0
- package/lib/draft-2019-09.js +92 -0
- package/lib/draft-2020-12.d.ts +62 -0
- package/lib/draft-2020-12.js +103 -0
- package/lib/index.d.ts +28 -0
- package/lib/index.js +26 -0
- package/lib/index.mjs +18 -0
- package/lib/keywords/additionalItems.js +27 -0
- package/lib/keywords/additionalItems6.js +23 -0
- package/lib/keywords/additionalProperties.js +33 -0
- package/lib/keywords/additionalProperties6.js +28 -0
- package/lib/keywords/allOf.js +28 -0
- package/lib/keywords/anyOf.js +29 -0
- package/lib/keywords/const.js +8 -0
- package/lib/keywords/contains-minContains-maxContains.js +33 -0
- package/lib/keywords/contains.js +10 -0
- package/lib/keywords/definitions.js +15 -0
- package/lib/keywords/dependencies.js +29 -0
- package/lib/keywords/dependentRequired.js +19 -0
- package/lib/keywords/dependentSchemas.js +30 -0
- package/lib/keywords/dynamicRef.js +24 -0
- package/lib/keywords/else.js +43 -0
- package/lib/keywords/enum.js +8 -0
- package/lib/keywords/exclusiveMaximum.js +7 -0
- package/lib/keywords/exclusiveMinimum.js +7 -0
- package/lib/keywords/if.js +19 -0
- package/lib/keywords/index.js +55 -0
- package/lib/keywords/items.js +31 -0
- package/lib/keywords/items202012.js +23 -0
- package/lib/keywords/maxItems.js +7 -0
- package/lib/keywords/maxLength.js +7 -0
- package/lib/keywords/maxLength6.js +7 -0
- package/lib/keywords/maxProperties.js +7 -0
- package/lib/keywords/maximum-exclusiveMaximum.js +20 -0
- package/lib/keywords/maximum.js +7 -0
- package/lib/keywords/minItems.js +7 -0
- package/lib/keywords/minLength.js +7 -0
- package/lib/keywords/minLength6.js +7 -0
- package/lib/keywords/minProperties.js +7 -0
- package/lib/keywords/minimum-exclusiveMinimum.js +20 -0
- package/lib/keywords/minimum.js +7 -0
- package/lib/keywords/multipleOf.js +17 -0
- package/lib/keywords/not.js +7 -0
- package/lib/keywords/oneOf.js +48 -0
- package/lib/keywords/pattern.js +7 -0
- package/lib/keywords/patternProperties.js +23 -0
- package/lib/keywords/properties.js +25 -0
- package/lib/keywords/propertyNames.js +11 -0
- package/lib/keywords/ref.js +13 -0
- package/lib/keywords/required.js +10 -0
- package/lib/keywords/then.js +43 -0
- package/lib/keywords/tupleItems.js +24 -0
- package/lib/keywords/type.js +7 -0
- package/lib/keywords/unevaluatedItems.js +23 -0
- package/lib/keywords/unevaluatedProperties.js +24 -0
- package/lib/keywords/uniqueItems.js +16 -0
- package/meta/draft/2019-09/meta/applicator.js +55 -0
- package/meta/draft/2019-09/meta/content.js +17 -0
- package/meta/draft/2019-09/meta/core.js +57 -0
- package/meta/draft/2019-09/meta/format.js +14 -0
- package/meta/draft/2019-09/meta/meta-data.js +37 -0
- package/meta/draft/2019-09/meta/validation.js +98 -0
- package/meta/draft/2019-09/schema.js +42 -0
- package/meta/draft/2020-12/meta/applicator.js +49 -0
- package/meta/draft/2020-12/meta/content.js +17 -0
- package/meta/draft/2020-12/meta/core.js +57 -0
- package/meta/draft/2020-12/meta/format-annotation.js +14 -0
- package/meta/draft/2020-12/meta/format-assertion.js +14 -0
- package/meta/draft/2020-12/meta/meta-data.js +37 -0
- package/meta/draft/2020-12/meta/unevaluated.js +15 -0
- package/meta/draft/2020-12/meta/validation.js +98 -0
- package/meta/draft/2020-12/schema.js +44 -0
- package/meta/draft-04/hyper-schema.js +136 -0
- package/meta/draft-04/schema.js +149 -0
- package/meta/draft-06/schema.js +154 -0
- package/meta/draft-07/schema.js +172 -0
- package/package.json +57 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const { Schema, Instance } = require("@hyperjump/json-schema-core");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const compile = (schema) => Schema.value(schema);
|
|
5
|
+
const interpret = (maxProperties, instance) => !Instance.typeOf(instance, "object") || Instance.keys(instance).length <= maxProperties;
|
|
6
|
+
|
|
7
|
+
module.exports = { compile, interpret };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const { Schema, Instance } = require("@hyperjump/json-schema-core");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const compile = async (schema, ast, parentSchema) => {
|
|
5
|
+
const exclusiveMaximum = await Schema.step("exclusiveMaximum", parentSchema);
|
|
6
|
+
const isExclusive = Schema.value(exclusiveMaximum);
|
|
7
|
+
|
|
8
|
+
return [Schema.value(schema), isExclusive];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const interpret = ([maximum, isExclusive], instance) => {
|
|
12
|
+
if (!Instance.typeOf(instance, "number")) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const value = Instance.value(instance);
|
|
17
|
+
return isExclusive ? value < maximum : value <= maximum;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
module.exports = { compile, interpret };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const { Schema, Instance } = require("@hyperjump/json-schema-core");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const compile = async (schema) => Schema.value(schema);
|
|
5
|
+
const interpret = (maximum, instance) => !Instance.typeOf(instance, "number") || Instance.value(instance) <= maximum;
|
|
6
|
+
|
|
7
|
+
module.exports = { compile, interpret };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const { Schema, Instance } = require("@hyperjump/json-schema-core");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const compile = (schema) => Schema.value(schema);
|
|
5
|
+
const interpret = (minItems, instance) => !Instance.typeOf(instance, "array") || Instance.length(instance) >= minItems;
|
|
6
|
+
|
|
7
|
+
module.exports = { compile, interpret };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const { Schema, Instance } = require("@hyperjump/json-schema-core");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const compile = (schema) => Schema.value(schema);
|
|
5
|
+
const interpret = (minLength, instance) => !Instance.typeOf(instance, "string") || Instance.length(instance) >= minLength;
|
|
6
|
+
|
|
7
|
+
module.exports = { compile, interpret };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const { Schema, Instance } = require("@hyperjump/json-schema-core");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const compile = (schema) => Schema.value(schema);
|
|
5
|
+
const interpret = (minLength, instance) => !Instance.typeOf(instance, "string") || [...Instance.value(instance)].length >= minLength;
|
|
6
|
+
|
|
7
|
+
module.exports = { compile, interpret };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const { Schema, Instance } = require("@hyperjump/json-schema-core");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const compile = (schema) => Schema.value(schema);
|
|
5
|
+
const interpret = (minProperties, instance) => !Instance.typeOf(instance, "object") || Instance.keys(instance).length >= minProperties;
|
|
6
|
+
|
|
7
|
+
module.exports = { compile, interpret };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const { Schema, Instance } = require("@hyperjump/json-schema-core");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const compile = async (schema, ast, parentSchema) => {
|
|
5
|
+
const exclusiveMinimum = await Schema.step("exclusiveMinimum", parentSchema);
|
|
6
|
+
const isExclusive = Schema.value(exclusiveMinimum);
|
|
7
|
+
|
|
8
|
+
return [Schema.value(schema), isExclusive];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const interpret = ([minimum, isExclusive], instance) => {
|
|
12
|
+
if (!Instance.typeOf(instance, "number")) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const value = Instance.value(instance);
|
|
17
|
+
return isExclusive ? value > minimum : value >= minimum;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
module.exports = { compile, interpret };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const { Schema, Instance } = require("@hyperjump/json-schema-core");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const compile = async (schema) => Schema.value(schema);
|
|
5
|
+
const interpret = (minimum, instance) => !Instance.typeOf(instance, "number") || Instance.value(instance) >= minimum;
|
|
6
|
+
|
|
7
|
+
module.exports = { compile, interpret };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const { Schema, Instance } = require("@hyperjump/json-schema-core");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const compile = (schema) => Schema.value(schema);
|
|
5
|
+
|
|
6
|
+
const interpret = (multipleOf, instance) => {
|
|
7
|
+
if (!Instance.typeOf(instance, "number")) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const remainder = Instance.value(instance) % multipleOf;
|
|
12
|
+
return numberEqual(0, remainder) || numberEqual(multipleOf, remainder);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const numberEqual = (a, b) => Math.abs(a - b) < 1.19209290e-7;
|
|
16
|
+
|
|
17
|
+
module.exports = { compile, interpret };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const { Core, Schema } = require("@hyperjump/json-schema-core");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const compile = async (schema, ast) => {
|
|
5
|
+
const oneOf = await Schema.map((itemSchema) => Core.compileSchema(itemSchema, ast), schema);
|
|
6
|
+
return Promise.all(oneOf);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const interpret = (oneOf, instance, ast, dynamicAnchors) => {
|
|
10
|
+
let validCount = 0;
|
|
11
|
+
for (const schemaUrl of oneOf) {
|
|
12
|
+
if (Core.interpretSchema(schemaUrl, instance, ast, dynamicAnchors)) {
|
|
13
|
+
validCount++;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (validCount > 1) {
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return validCount === 1;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const collectEvaluatedProperties = (oneOf, instance, ast, dynamicAnchors) => {
|
|
25
|
+
let validCount = 0;
|
|
26
|
+
return oneOf.reduce((acc, schemaUrl) => {
|
|
27
|
+
if (validCount > 1) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const propertyNames = Core.collectEvaluatedProperties(schemaUrl, instance, ast, dynamicAnchors);
|
|
32
|
+
return propertyNames ? validCount++ === 0 && propertyNames : acc;
|
|
33
|
+
}, false);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const collectEvaluatedItems = (oneOf, instance, ast, dynamicAnchors) => {
|
|
37
|
+
let validCount = 0;
|
|
38
|
+
return oneOf.reduce((acc, schemaUrl) => {
|
|
39
|
+
if (validCount > 1) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const itemIndexes = Core.collectEvaluatedItems(schemaUrl, instance, ast, dynamicAnchors);
|
|
44
|
+
return itemIndexes ? validCount++ === 0 && itemIndexes : acc;
|
|
45
|
+
}, false);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
module.exports = { compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const { Schema, Instance } = require("@hyperjump/json-schema-core");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const compile = (schema) => new RegExp(Schema.value(schema), "u");
|
|
5
|
+
const interpret = (pattern, instance) => !Instance.typeOf(instance, "string") || pattern.test(Instance.value(instance));
|
|
6
|
+
|
|
7
|
+
module.exports = { compile, interpret };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const { Core, Schema, Instance } = require("@hyperjump/json-schema-core");
|
|
2
|
+
const Pact = require("@hyperjump/pact");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const compile = (schema, ast) => Pact.pipeline([
|
|
6
|
+
Schema.entries,
|
|
7
|
+
Pact.map(async ([pattern, propertySchema]) => [new RegExp(pattern, "u"), await Core.compileSchema(propertySchema, ast)]),
|
|
8
|
+
Pact.all
|
|
9
|
+
], schema);
|
|
10
|
+
|
|
11
|
+
const interpret = (patternProperties, instance, ast, dynamicAnchors) => {
|
|
12
|
+
return !Instance.typeOf(instance, "object") || patternProperties.every(([pattern, schemaUrl]) => {
|
|
13
|
+
return Instance.entries(instance)
|
|
14
|
+
.filter(([propertyName]) => pattern.test(propertyName))
|
|
15
|
+
.every(([, propertyValue]) => Core.interpretSchema(schemaUrl, propertyValue, ast, dynamicAnchors));
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const collectEvaluatedProperties = (patternProperties, instance, ast, dynamicAnchors) => {
|
|
20
|
+
return interpret(patternProperties, instance, ast, dynamicAnchors) && patternProperties.map(([pattern]) => pattern);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
module.exports = { compile, interpret, collectEvaluatedProperties };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const { Core, Schema, Instance } = require("@hyperjump/json-schema-core");
|
|
2
|
+
const Pact = require("@hyperjump/pact");
|
|
3
|
+
const { escapeRegExp } = require("../common");
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const compile = (schema, ast) => Pact.pipeline([
|
|
7
|
+
Schema.entries,
|
|
8
|
+
Pact.reduce(async (acc, [propertyName, propertySchema]) => {
|
|
9
|
+
acc[propertyName] = await Core.compileSchema(propertySchema, ast);
|
|
10
|
+
return acc;
|
|
11
|
+
}, Object.create(null))
|
|
12
|
+
], schema);
|
|
13
|
+
|
|
14
|
+
const interpret = (properties, instance, ast, dynamicAnchors) => {
|
|
15
|
+
return !Instance.typeOf(instance, "object") || Instance.entries(instance)
|
|
16
|
+
.filter(([propertyName]) => propertyName in properties)
|
|
17
|
+
.every(([propertyName, schemaUrl]) => Core.interpretSchema(properties[propertyName], schemaUrl, ast, dynamicAnchors));
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const collectEvaluatedProperties = (properties, instance, ast, dynamicAnchors) => {
|
|
21
|
+
return interpret(properties, instance, ast, dynamicAnchors) && Object.keys(properties)
|
|
22
|
+
.map((propertyName) => new RegExp(`^${escapeRegExp(propertyName)}$`));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
module.exports = { compile, interpret, collectEvaluatedProperties };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const { Core, Instance } = require("@hyperjump/json-schema-core");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const compile = (schema, ast) => Core.compileSchema(schema, ast);
|
|
5
|
+
|
|
6
|
+
const interpret = (propertyNames, instance, ast, dynamicAnchors) => {
|
|
7
|
+
return !Instance.typeOf(instance, "object") || Instance.keys(instance)
|
|
8
|
+
.every((key) => Core.interpretSchema(propertyNames, Instance.cons(key), ast, dynamicAnchors));
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
module.exports = { compile, interpret };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const { Core, Schema } = require("@hyperjump/json-schema-core");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const compile = async (ref, ast) => {
|
|
5
|
+
const referencedSchema = await Schema.get(Schema.value(ref), ref);
|
|
6
|
+
return Core.compileSchema(referencedSchema, ast);
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const interpret = Core.interpretSchema;
|
|
10
|
+
const collectEvaluatedProperties = Core.collectEvaluatedProperties;
|
|
11
|
+
const collectEvaluatedItems = Core.collectEvaluatedItems;
|
|
12
|
+
|
|
13
|
+
module.exports = { compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const { Schema, Instance } = require("@hyperjump/json-schema-core");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const compile = (schema) => Schema.value(schema);
|
|
5
|
+
|
|
6
|
+
const interpret = (required, instance) => {
|
|
7
|
+
return !Instance.typeOf(instance, "object") || required.every((propertyName) => Object.prototype.hasOwnProperty.call(Instance.value(instance), propertyName));
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
module.exports = { compile, interpret };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const { Core, Schema } = require("@hyperjump/json-schema-core");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const compile = async (schema, ast, parentSchema) => {
|
|
5
|
+
if (Schema.has("if", parentSchema)) {
|
|
6
|
+
const ifSchema = await Schema.step("if", parentSchema);
|
|
7
|
+
return [await Core.compileSchema(ifSchema, ast), await Core.compileSchema(schema, ast)];
|
|
8
|
+
} else {
|
|
9
|
+
return [];
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const interpret = ([guard, block], instance, ast, dynamicAnchors) => {
|
|
14
|
+
return guard === undefined || !quietInterpretSchema(guard, instance, ast, dynamicAnchors) || Core.interpretSchema(block, instance, ast, dynamicAnchors);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// Interpret a schema without events being emitted
|
|
18
|
+
const quietInterpretSchema = (uri, instance, ast, dynamicAnchors) => {
|
|
19
|
+
const nodes = ast[uri][2];
|
|
20
|
+
|
|
21
|
+
return typeof nodes === "boolean" ? nodes : nodes
|
|
22
|
+
.every(([keywordId, , keywordValue]) => {
|
|
23
|
+
return Core.getKeyword(keywordId).interpret(keywordValue, instance, ast, dynamicAnchors);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const collectEvaluatedProperties = ([guard, block], instance, ast, dynamicAnchors) => {
|
|
28
|
+
if (guard === undefined || !quietInterpretSchema(guard, instance, ast, dynamicAnchors)) {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return Core.collectEvaluatedProperties(block, instance, ast, dynamicAnchors);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const collectEvaluatedItems = ([guard, block], instance, ast, dynamicAnchors) => {
|
|
36
|
+
if (guard === undefined || !quietInterpretSchema(guard, instance, ast, dynamicAnchors)) {
|
|
37
|
+
return new Set();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return Core.collectEvaluatedItems(block, instance, ast, dynamicAnchors);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
module.exports = { compile, interpret, collectEvaluatedProperties, collectEvaluatedItems };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const { Core, Schema, Instance } = require("@hyperjump/json-schema-core");
|
|
2
|
+
const Pact = require("@hyperjump/pact");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const compile = (schema, ast) => {
|
|
6
|
+
return Pact.pipeline([
|
|
7
|
+
Schema.map((itemSchema) => Core.compileSchema(itemSchema, ast)),
|
|
8
|
+
Pact.all
|
|
9
|
+
], schema);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const interpret = (items, instance, ast, dynamicAnchors) => {
|
|
13
|
+
if (!Instance.typeOf(instance, "array")) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return Instance.every((item, ndx) => !(ndx in items) || Core.interpretSchema(items[ndx], item, ast, dynamicAnchors), instance);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const collectEvaluatedItems = (items, instance, ast, dynamicAnchors) => {
|
|
21
|
+
return interpret(items, instance, ast, dynamicAnchors) && new Set(items.map((item, ndx) => ndx));
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
module.exports = { compile, interpret, collectEvaluatedItems };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const { Schema, Instance } = require("@hyperjump/json-schema-core");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const compile = (schema) => Schema.value(schema);
|
|
5
|
+
const interpret = (type, instance) => typeof type === "string" ? Instance.typeOf(instance, type) : type.some(Instance.typeOf(instance));
|
|
6
|
+
|
|
7
|
+
module.exports = { compile, interpret };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const { Core, Schema, Instance } = require("@hyperjump/json-schema-core");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const compile = async (schema, ast, parentSchema) => {
|
|
5
|
+
return [Schema.uri(parentSchema), await Core.compileSchema(schema, ast)];
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const interpret = ([schemaUrl, unevaluatedItems], instance, ast, dynamicAnchors) => {
|
|
9
|
+
if (!Instance.typeOf(instance, "array")) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const itemIndexes = Core.collectEvaluatedItems(schemaUrl, instance, ast, dynamicAnchors, true);
|
|
14
|
+
return itemIndexes === false || Instance.every((item, itemIndex) => {
|
|
15
|
+
return itemIndexes.has(itemIndex) || Core.interpretSchema(unevaluatedItems, Instance.step(itemIndex, instance), ast, dynamicAnchors);
|
|
16
|
+
}, instance);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const collectEvaluatedItems = (keywordValue, instance, ast, dynamicAnchors) => {
|
|
20
|
+
return interpret(keywordValue, instance, ast, dynamicAnchors) && new Set(Instance.map((item, ndx) => ndx, instance));
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
module.exports = { compile, interpret, collectEvaluatedItems };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const { Core, Schema, Instance } = require("@hyperjump/json-schema-core");
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const compile = async (schema, ast, parentSchema) => {
|
|
5
|
+
return [Schema.uri(parentSchema), await Core.compileSchema(schema, ast)];
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
const interpret = ([schemaUrl, unevaluatedProperties], instance, ast, dynamicAnchors) => {
|
|
9
|
+
if (!Instance.typeOf(instance, "object")) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const evaluatedPropertyNames = Core.collectEvaluatedProperties(schemaUrl, instance, ast, dynamicAnchors, true);
|
|
14
|
+
|
|
15
|
+
return !evaluatedPropertyNames || Instance.entries(instance)
|
|
16
|
+
.filter(([propertyName]) => !evaluatedPropertyNames.some((pattern) => propertyName.match(pattern)))
|
|
17
|
+
.every(([, property]) => Core.interpretSchema(unevaluatedProperties, property, ast, dynamicAnchors));
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const collectEvaluatedProperties = (keywordValue, instance, ast, dynamicAnchors) =>{
|
|
21
|
+
return interpret(keywordValue, instance, ast, dynamicAnchors) && [new RegExp("")];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
module.exports = { compile, interpret, collectEvaluatedProperties };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const { Schema, Instance } = require("@hyperjump/json-schema-core");
|
|
2
|
+
const jsonStringify = require("fastest-stable-stringify");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const compile = (schema) => Schema.value(schema);
|
|
6
|
+
|
|
7
|
+
const interpret = (uniqueItems, instance) => {
|
|
8
|
+
if (!Instance.typeOf(instance, "array") || uniqueItems === false) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const normalizedItems = Instance.map((item) => jsonStringify(Instance.value(item)), instance);
|
|
13
|
+
return new Set(normalizedItems).size === normalizedItems.length;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
module.exports = { compile, interpret };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module.exports = `{
|
|
2
|
+
"$id": "https://json-schema.org/draft/2019-09/meta/applicator",
|
|
3
|
+
"$schema": "https://json-schema.org/draft/2019-09/schema",
|
|
4
|
+
"$vocabulary": {
|
|
5
|
+
"https://json-schema.org/draft/2019-09/vocab/applicator": true
|
|
6
|
+
},
|
|
7
|
+
"$recursiveAnchor": true,
|
|
8
|
+
|
|
9
|
+
"title": "Applicator vocabulary meta-schema",
|
|
10
|
+
"properties": {
|
|
11
|
+
"additionalItems": { "$recursiveRef": "#" },
|
|
12
|
+
"unevaluatedItems": { "$recursiveRef": "#" },
|
|
13
|
+
"items": {
|
|
14
|
+
"anyOf": [
|
|
15
|
+
{ "$recursiveRef": "#" },
|
|
16
|
+
{ "$ref": "#/$defs/schemaArray" }
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
"contains": { "$recursiveRef": "#" },
|
|
20
|
+
"additionalProperties": { "$recursiveRef": "#" },
|
|
21
|
+
"unevaluatedProperties": { "$recursiveRef": "#" },
|
|
22
|
+
"properties": {
|
|
23
|
+
"type": "object",
|
|
24
|
+
"additionalProperties": { "$recursiveRef": "#" },
|
|
25
|
+
"default": {}
|
|
26
|
+
},
|
|
27
|
+
"patternProperties": {
|
|
28
|
+
"type": "object",
|
|
29
|
+
"additionalProperties": { "$recursiveRef": "#" },
|
|
30
|
+
"propertyNames": { "format": "regex" },
|
|
31
|
+
"default": {}
|
|
32
|
+
},
|
|
33
|
+
"dependentSchemas": {
|
|
34
|
+
"type": "object",
|
|
35
|
+
"additionalProperties": {
|
|
36
|
+
"$recursiveRef": "#"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"propertyNames": { "$recursiveRef": "#" },
|
|
40
|
+
"if": { "$recursiveRef": "#" },
|
|
41
|
+
"then": { "$recursiveRef": "#" },
|
|
42
|
+
"else": { "$recursiveRef": "#" },
|
|
43
|
+
"allOf": { "$ref": "#/$defs/schemaArray" },
|
|
44
|
+
"anyOf": { "$ref": "#/$defs/schemaArray" },
|
|
45
|
+
"oneOf": { "$ref": "#/$defs/schemaArray" },
|
|
46
|
+
"not": { "$recursiveRef": "#" }
|
|
47
|
+
},
|
|
48
|
+
"$defs": {
|
|
49
|
+
"schemaArray": {
|
|
50
|
+
"type": "array",
|
|
51
|
+
"minItems": 1,
|
|
52
|
+
"items": { "$recursiveRef": "#" }
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}`;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module.exports = `{
|
|
2
|
+
"$id": "https://json-schema.org/draft/2019-09/meta/content",
|
|
3
|
+
"$schema": "https://json-schema.org/draft/2019-09/schema",
|
|
4
|
+
"$vocabulary": {
|
|
5
|
+
"https://json-schema.org/draft/2019-09/vocab/content": true
|
|
6
|
+
},
|
|
7
|
+
"$recursiveAnchor": true,
|
|
8
|
+
|
|
9
|
+
"title": "Content vocabulary meta-schema",
|
|
10
|
+
|
|
11
|
+
"type": ["object", "boolean"],
|
|
12
|
+
"properties": {
|
|
13
|
+
"contentMediaType": { "type": "string" },
|
|
14
|
+
"contentEncoding": { "type": "string" },
|
|
15
|
+
"contentSchema": { "$recursiveRef": "#" }
|
|
16
|
+
}
|
|
17
|
+
}`;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
module.exports = `{
|
|
2
|
+
"$id": "https://json-schema.org/draft/2019-09/meta/core",
|
|
3
|
+
"$schema": "https://json-schema.org/draft/2019-09/schema",
|
|
4
|
+
"$vocabulary": {
|
|
5
|
+
"https://json-schema.org/draft/2019-09/vocab/core": true
|
|
6
|
+
},
|
|
7
|
+
"$recursiveAnchor": true,
|
|
8
|
+
|
|
9
|
+
"title": "Core vocabulary meta-schema",
|
|
10
|
+
"type": ["object", "boolean"],
|
|
11
|
+
"properties": {
|
|
12
|
+
"$id": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"format": "uri-reference",
|
|
15
|
+
"$comment": "Non-empty fragments not allowed.",
|
|
16
|
+
"pattern": "^[^#]*#?$"
|
|
17
|
+
},
|
|
18
|
+
"$schema": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"format": "uri"
|
|
21
|
+
},
|
|
22
|
+
"$anchor": {
|
|
23
|
+
"type": "string",
|
|
24
|
+
"pattern": "^[A-Za-z][-A-Za-z0-9.:_]*$"
|
|
25
|
+
},
|
|
26
|
+
"$ref": {
|
|
27
|
+
"type": "string",
|
|
28
|
+
"format": "uri-reference"
|
|
29
|
+
},
|
|
30
|
+
"$recursiveRef": {
|
|
31
|
+
"type": "string",
|
|
32
|
+
"format": "uri-reference"
|
|
33
|
+
},
|
|
34
|
+
"$recursiveAnchor": {
|
|
35
|
+
"type": "boolean",
|
|
36
|
+
"default": false
|
|
37
|
+
},
|
|
38
|
+
"$vocabulary": {
|
|
39
|
+
"type": "object",
|
|
40
|
+
"propertyNames": {
|
|
41
|
+
"type": "string",
|
|
42
|
+
"format": "uri"
|
|
43
|
+
},
|
|
44
|
+
"additionalProperties": {
|
|
45
|
+
"type": "boolean"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"$comment": {
|
|
49
|
+
"type": "string"
|
|
50
|
+
},
|
|
51
|
+
"$defs": {
|
|
52
|
+
"type": "object",
|
|
53
|
+
"additionalProperties": { "$recursiveRef": "#" },
|
|
54
|
+
"default": {}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}`;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module.exports = `{
|
|
2
|
+
"$id": "https://json-schema.org/draft/2019-09/meta/format",
|
|
3
|
+
"$schema": "https://json-schema.org/draft/2019-09/schema",
|
|
4
|
+
"$vocabulary": {
|
|
5
|
+
"https://json-schema.org/draft/2019-09/vocab/format": true
|
|
6
|
+
},
|
|
7
|
+
"$recursiveAnchor": true,
|
|
8
|
+
|
|
9
|
+
"title": "Format vocabulary meta-schema",
|
|
10
|
+
"type": ["object", "boolean"],
|
|
11
|
+
"properties": {
|
|
12
|
+
"format": { "type": "string" }
|
|
13
|
+
}
|
|
14
|
+
}`;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module.exports = `{
|
|
2
|
+
"$id": "https://json-schema.org/draft/2019-09/meta/meta-data",
|
|
3
|
+
"$schema": "https://json-schema.org/draft/2019-09/schema",
|
|
4
|
+
"$vocabulary": {
|
|
5
|
+
"https://json-schema.org/draft/2019-09/vocab/meta-data": true
|
|
6
|
+
},
|
|
7
|
+
"$recursiveAnchor": true,
|
|
8
|
+
|
|
9
|
+
"title": "Meta-data vocabulary meta-schema",
|
|
10
|
+
|
|
11
|
+
"type": ["object", "boolean"],
|
|
12
|
+
"properties": {
|
|
13
|
+
"title": {
|
|
14
|
+
"type": "string"
|
|
15
|
+
},
|
|
16
|
+
"description": {
|
|
17
|
+
"type": "string"
|
|
18
|
+
},
|
|
19
|
+
"default": true,
|
|
20
|
+
"deprecated": {
|
|
21
|
+
"type": "boolean",
|
|
22
|
+
"default": false
|
|
23
|
+
},
|
|
24
|
+
"readOnly": {
|
|
25
|
+
"type": "boolean",
|
|
26
|
+
"default": false
|
|
27
|
+
},
|
|
28
|
+
"writeOnly": {
|
|
29
|
+
"type": "boolean",
|
|
30
|
+
"default": false
|
|
31
|
+
},
|
|
32
|
+
"examples": {
|
|
33
|
+
"type": "array",
|
|
34
|
+
"items": true
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}`;
|