Skip to content

Commit f4b7807

Browse files
committed
Convert unevaluated and dynamic into evaluation plugins
1 parent 64d8a2e commit f4b7807

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+527
-580
lines changed

annotations/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import { FLAG } from "../lib/index.js";
22
import { ValidationError } from "./validation-error.js";
3-
import { getSchema, compile, BASIC, DETAILED } from "../lib/experimental.js";
3+
import {
4+
getSchema,
5+
compile,
6+
BASIC,
7+
DETAILED,
8+
annotationsPlugin,
9+
basicOutputPlugin,
10+
detailedOutputPlugin
11+
} from "../lib/experimental.js";
412
import Validation from "../lib/keywords/validation.js";
513
import * as Instance from "../lib/instance.js";
6-
import { annotationsPlugin } from "../lib/evaluation-plugins/annotations.js";
7-
import { basicOutputPlugin } from "../lib/evaluation-plugins/basic-output.js";
8-
import { detailedOutputPlugin } from "../lib/evaluation-plugins/detailed-output.js";
914

1015

1116
export const annotate = async (schemaUri, json = undefined, outputFormat = undefined) => {
@@ -17,7 +22,7 @@ export const annotate = async (schemaUri, json = undefined, outputFormat = undef
1722
};
1823

1924
export const interpret = ({ ast, schemaUri }, instance, outputFormat = BASIC) => {
20-
const context = { ast, plugins: [annotationsPlugin], dynamicAnchors: {} };
25+
const context = { ast, plugins: [annotationsPlugin, ...ast.plugins] };
2126

2227
switch (outputFormat) {
2328
case FLAG:

bundle/generate-snapshots.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import { writeFile, mkdir, rm } from "node:fs/promises";
22
import { isCompatible, md5, loadSchemas, testSuite, unloadSchemas } from "./test-utils.js";
3-
import { compile, getSchema, Validation } from "../lib/experimental.js";
3+
import { annotationsPlugin, compile, detailedOutputPlugin, getSchema, Validation } from "../lib/experimental.js";
44
import "../stable/index.js";
55
import "../draft-2020-12/index.js";
66
import "../draft-2019-09/index.js";
77
import "../draft-07/index.js";
88
import "../draft-06/index.js";
99
import "../draft-04/index.js";
1010
import * as Instance from "../lib/instance.js";
11-
import { detailedOutputPlugin } from "../lib/evaluation-plugins/detailed-output.js";
12-
import { annotationsPlugin } from "../lib/evaluation-plugins/annotations.js";
1311

1412

1513
const suite = testSuite("./bundle/tests");
@@ -30,11 +28,7 @@ const snapshotGenerator = async (version, dialect) => {
3028
const { ast, schemaUri } = await compile(schema);
3129

3230
const instance = Instance.fromJs(test.instance);
33-
const context = {
34-
ast,
35-
plugins: [detailedOutputPlugin, annotationsPlugin],
36-
dynamicAnchors: {}
37-
};
31+
const context = { ast, plugins: [detailedOutputPlugin, annotationsPlugin, ...ast.plugins] };
3832
const valid = Validation.interpret(schemaUri, instance, context);
3933

4034
const expectedOutput = {

bundle/snapshots/7870eeab5f8ca9101ad59356ae80d8cf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
{
1010
"keyword": "https://json-schema.org/keyword/ref",
1111
"absoluteKeywordLocation": "https://bundler.hyperjump.io/main#/propertyNames/$ref",
12-
"instanceLocation": "#/foobar",
12+
"instanceLocation": "#*/foobar",
1313
"errors": [
1414
{
1515
"keyword": "https://json-schema.org/keyword/maxLength",
1616
"absoluteKeywordLocation": "https://test.json-schema.org/short-string#/maxLength",
17-
"instanceLocation": "#/foobar"
17+
"instanceLocation": "#*/foobar"
1818
}
1919
]
2020
}

bundle/snapshots/a08a7afd39db6237f476bcc7a0aea1fc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{
1010
"keyword": "https://json-schema.org/keyword/maxLength",
1111
"absoluteKeywordLocation": "https://test.json-schema.org/short-string#/maxLength",
12-
"instanceLocation": "#/foobar"
12+
"instanceLocation": "#*/foobar"
1313
}
1414
]
1515
}

bundle/snapshots/ab51f0cdf303246217f87ce8de260742

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{
1010
"keyword": "https://json-schema.org/keyword/maxLength",
1111
"absoluteKeywordLocation": "https://test.json-schema.org/short-string#/maxLength",
12-
"instanceLocation": "#/foobar"
12+
"instanceLocation": "#*/foobar"
1313
}
1414
]
1515
}

bundle/snapshots/ca63dcc3736aca6a5a2f7b31dd6c7807

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
{
1010
"keyword": "https://json-schema.org/keyword/ref",
1111
"absoluteKeywordLocation": "https://bundler.hyperjump.io/main#/propertyNames/$ref",
12-
"instanceLocation": "#/foobar",
12+
"instanceLocation": "#*/foobar",
1313
"errors": [
1414
{
1515
"keyword": "https://json-schema.org/keyword/maxLength",
1616
"absoluteKeywordLocation": "https://test.json-schema.org/short-string#/maxLength",
17-
"instanceLocation": "#/foobar"
17+
"instanceLocation": "#*/foobar"
1818
}
1919
]
2020
}

bundle/snapshots/e35a3f6c92398728f6100e796bc47b97

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
{
1010
"keyword": "https://json-schema.org/keyword/ref",
1111
"absoluteKeywordLocation": "https://bundler.hyperjump.io/main#/propertyNames/$ref",
12-
"instanceLocation": "#/foobar",
12+
"instanceLocation": "#*/foobar",
1313
"errors": [
1414
{
1515
"keyword": "https://json-schema.org/keyword/maxLength",
1616
"absoluteKeywordLocation": "https://test.json-schema.org/short-string#/maxLength",
17-
"instanceLocation": "#/foobar"
17+
"instanceLocation": "#*/foobar"
1818
}
1919
]
2020
}

bundle/test-suite.spec.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ const testRunner = (version: number, dialect: string) => {
6868
const instance = Instance.fromJs(test.instance);
6969
const context = {
7070
ast,
71-
plugins: [detailedOutputPlugin, annotationsPlugin],
72-
dynamicAnchors: {},
73-
errors: [],
74-
annotations: []
71+
plugins: [detailedOutputPlugin, annotationsPlugin, ...ast.plugins]
7572
} as ValidationContext & ErrorsContext & AnnotationsContext;
7673
const valid = Validation.interpret(schemaUri, instance, context);
7774

draft-04/additionalItems.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { pipe, drop, every } from "@hyperjump/pact";
1+
import { drop } from "@hyperjump/pact";
22
import * as Browser from "@hyperjump/browser";
33
import * as Instance from "../lib/instance.js";
44
import { getKeywordName, Validation } from "../lib/experimental.js";
@@ -19,26 +19,20 @@ const interpret = ([numberOfItems, additionalItems], instance, context) => {
1919
return true;
2020
}
2121

22-
return pipe(
23-
Instance.iter(instance),
24-
drop(numberOfItems),
25-
every((item) => Validation.interpret(additionalItems, item, context))
26-
);
27-
};
28-
29-
const simpleApplicator = true;
22+
let isValid = true;
23+
let index = numberOfItems;
24+
for (const item of drop(numberOfItems, Instance.iter(instance))) {
25+
if (!Validation.interpret(additionalItems, item, context)) {
26+
isValid = false;
27+
}
3028

31-
const collectEvaluatedItems = (keywordValue, instance, context) => {
32-
if (!interpret(keywordValue, instance, context)) {
33-
return false;
29+
context.evaluatedItems?.add(index);
30+
index++;
3431
}
3532

36-
const evaluatedIndexes = new Set();
37-
for (let ndx = keywordValue[0]; ndx < Instance.length(instance); ndx++) {
38-
evaluatedIndexes.add(ndx);
39-
}
40-
41-
return evaluatedIndexes;
33+
return isValid;
4234
};
4335

44-
export default { id, compile, interpret, simpleApplicator, collectEvaluatedItems };
36+
const simpleApplicator = true;
37+
38+
export default { id, compile, interpret, simpleApplicator };

draft-04/items.js

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { pipe, asyncMap, asyncCollectArray, every, zip, take, range, collectSet } from "@hyperjump/pact";
1+
import { pipe, asyncMap, asyncCollectArray, zip } from "@hyperjump/pact";
22
import * as Browser from "@hyperjump/browser";
33
import * as Instance from "../lib/instance.js";
44
import { Validation } from "../lib/experimental.js";
@@ -23,23 +23,35 @@ const interpret = (items, instance, context) => {
2323
return true;
2424
}
2525

26+
let isValid = true;
27+
let index = 0;
28+
2629
if (typeof items === "string") {
27-
return every((itemValue) => Validation.interpret(items, itemValue, context), Instance.iter(instance));
30+
for (const item of Instance.iter(instance)) {
31+
if (!Validation.interpret(items, item, context)) {
32+
isValid = false;
33+
}
34+
35+
context.evaluatedItems?.add(index++);
36+
}
2837
} else {
29-
return pipe(
30-
zip(items, Instance.iter(instance)),
31-
take(Instance.length(instance)),
32-
every(([prefixItem, item]) => Validation.interpret(prefixItem, item, context))
33-
);
38+
for (const [tupleItem, tupleInstance] of zip(items, Instance.iter(instance))) {
39+
if (!tupleInstance) {
40+
break;
41+
}
42+
43+
if (!Validation.interpret(tupleItem, tupleInstance, context)) {
44+
isValid = false;
45+
}
46+
47+
context.evaluatedItems?.add(index);
48+
index++;
49+
}
3450
}
51+
52+
return isValid;
3553
};
3654

3755
const simpleApplicator = true;
3856

39-
const collectEvaluatedItems = (items, instance, context) => {
40-
return interpret(items, instance, context) && (typeof items === "string"
41-
? collectSet(range(0, Instance.length(instance)))
42-
: collectSet(range(0, items.length)));
43-
};
44-
45-
export default { id, compile, interpret, simpleApplicator, collectEvaluatedItems };
57+
export default { id, compile, interpret, simpleApplicator };

0 commit comments

Comments
 (0)