@hyperjump/json-schema 1.14.0 → 1.14.1
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const isCompatible: (compatibility: string | undefined, versionUnderTest: number) => boolean;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export const isCompatible = (compatibility, versionUnderTest) => {
|
|
2
|
+
if (compatibility === undefined) {
|
|
3
|
+
return true;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const constraints = compatibility.split(",");
|
|
7
|
+
for (const constraint of constraints) {
|
|
8
|
+
const matches = /(?<operator><=|>=|=)?(?<version>\d+)/.exec(constraint);
|
|
9
|
+
if (!matches) {
|
|
10
|
+
throw Error(`Invalid compatibility string: ${compatibility}`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const operator = matches[1] ?? ">=";
|
|
14
|
+
const version = parseInt(matches[2], 10);
|
|
15
|
+
|
|
16
|
+
switch (operator) {
|
|
17
|
+
case ">=":
|
|
18
|
+
if (versionUnderTest < version) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
break;
|
|
22
|
+
case "<=":
|
|
23
|
+
if (versionUnderTest > version) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
break;
|
|
27
|
+
case "=":
|
|
28
|
+
if (versionUnderTest !== version) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
break;
|
|
32
|
+
default:
|
|
33
|
+
throw Error(`Unsupported contraint operator: ${operator}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return true;
|
|
38
|
+
};
|
package/draft-04/dependencies.js
CHANGED
|
@@ -16,21 +16,21 @@ const compile = (schema, ast) => pipe(
|
|
|
16
16
|
);
|
|
17
17
|
|
|
18
18
|
const interpret = (dependencies, instance, context) => {
|
|
19
|
-
|
|
19
|
+
if (Instance.typeOf(instance) !== "object") {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
20
22
|
|
|
21
|
-
return
|
|
22
|
-
if (!(propertyName
|
|
23
|
+
return dependencies.every(([propertyName, dependency]) => {
|
|
24
|
+
if (!Instance.has(propertyName, instance)) {
|
|
23
25
|
return true;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
if (Array.isArray(dependency)) {
|
|
27
|
-
return dependency.every((key) => key
|
|
29
|
+
return dependency.every((key) => Instance.has(key, instance));
|
|
28
30
|
} else {
|
|
29
31
|
return Validation.interpret(dependency, instance, context);
|
|
30
32
|
}
|
|
31
33
|
});
|
|
32
34
|
};
|
|
33
35
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
export default { id, compile, interpret, simpleApplicator };
|
|
36
|
+
export default { id, compile, interpret };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { canonicalUri } from "../schema.js";
|
|
2
1
|
import * as Browser from "@hyperjump/browser";
|
|
3
2
|
import * as Instance from "../instance.js";
|
|
4
3
|
import { getKeywordName } from "../keywords.js";
|
|
@@ -9,13 +8,17 @@ const id = "https://json-schema.org/keyword/contentSchema";
|
|
|
9
8
|
const compile = async (contentSchema, _ast, parentSchema) => {
|
|
10
9
|
const contentMediaTypeKeyword = getKeywordName(contentSchema.document.dialectId, "https://json-schema.org/keyword/contentMediaType");
|
|
11
10
|
const contentMediaType = await Browser.step(contentMediaTypeKeyword, parentSchema);
|
|
12
|
-
|
|
11
|
+
if (Browser.value(contentMediaType) === undefined) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return Browser.value(contentSchema);
|
|
13
16
|
};
|
|
14
17
|
|
|
15
18
|
const interpret = () => true;
|
|
16
19
|
|
|
17
20
|
const annotation = (contentSchema, instance) => {
|
|
18
|
-
if (Instance.typeOf(instance) !== "string") {
|
|
21
|
+
if (!contentSchema || Instance.typeOf(instance) !== "string") {
|
|
19
22
|
return;
|
|
20
23
|
}
|
|
21
24
|
|
package/package.json
CHANGED