@json-schema-engine/core 0.0.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.
- package/LICENSE +21 -0
- package/README.md +50 -0
- package/dist/coverage.d.ts +30 -0
- package/dist/coverage.d.ts.map +1 -0
- package/dist/coverage.js +81 -0
- package/dist/coverage.js.map +1 -0
- package/dist/cursor.d.ts +16 -0
- package/dist/cursor.d.ts.map +1 -0
- package/dist/cursor.js +28 -0
- package/dist/cursor.js.map +1 -0
- package/dist/dialect.d.ts +316 -0
- package/dist/dialect.d.ts.map +1 -0
- package/dist/dialect.js +135 -0
- package/dist/dialect.js.map +1 -0
- package/dist/engine.d.ts +203 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +493 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +182 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +370 -0
- package/dist/index.js.map +1 -0
- package/dist/json.d.ts +49 -0
- package/dist/json.d.ts.map +1 -0
- package/dist/json.js +128 -0
- package/dist/json.js.map +1 -0
- package/dist/keywords/applicator.d.ts +57 -0
- package/dist/keywords/applicator.d.ts.map +1 -0
- package/dist/keywords/applicator.js +789 -0
- package/dist/keywords/applicator.js.map +1 -0
- package/dist/keywords/core.d.ts +42 -0
- package/dist/keywords/core.d.ts.map +1 -0
- package/dist/keywords/core.js +139 -0
- package/dist/keywords/core.js.map +1 -0
- package/dist/keywords/format.d.ts +43 -0
- package/dist/keywords/format.d.ts.map +1 -0
- package/dist/keywords/format.js +101 -0
- package/dist/keywords/format.js.map +1 -0
- package/dist/keywords/metaschemas2019.d.ts +3 -0
- package/dist/keywords/metaschemas2019.d.ts.map +1 -0
- package/dist/keywords/metaschemas2019.js +406 -0
- package/dist/keywords/metaschemas2019.js.map +1 -0
- package/dist/keywords/metaschemas2020.d.ts +3 -0
- package/dist/keywords/metaschemas2020.d.ts.map +1 -0
- package/dist/keywords/metaschemas2020.js +441 -0
- package/dist/keywords/metaschemas2020.js.map +1 -0
- package/dist/keywords/metaschemas6.d.ts +3 -0
- package/dist/keywords/metaschemas6.d.ts.map +1 -0
- package/dist/keywords/metaschemas6.js +221 -0
- package/dist/keywords/metaschemas6.js.map +1 -0
- package/dist/keywords/metaschemas7.d.ts +3 -0
- package/dist/keywords/metaschemas7.d.ts.map +1 -0
- package/dist/keywords/metaschemas7.js +248 -0
- package/dist/keywords/metaschemas7.js.map +1 -0
- package/dist/keywords/unevaluated.d.ts +14 -0
- package/dist/keywords/unevaluated.d.ts.map +1 -0
- package/dist/keywords/unevaluated.js +296 -0
- package/dist/keywords/unevaluated.js.map +1 -0
- package/dist/keywords/validation.d.ts +21 -0
- package/dist/keywords/validation.d.ts.map +1 -0
- package/dist/keywords/validation.js +332 -0
- package/dist/keywords/validation.js.map +1 -0
- package/dist/keywords/vocab2019.d.ts +36 -0
- package/dist/keywords/vocab2019.d.ts.map +1 -0
- package/dist/keywords/vocab2019.js +585 -0
- package/dist/keywords/vocab2019.js.map +1 -0
- package/dist/keywords/vocab2020.d.ts +20 -0
- package/dist/keywords/vocab2020.d.ts.map +1 -0
- package/dist/keywords/vocab2020.js +55 -0
- package/dist/keywords/vocab2020.js.map +1 -0
- package/dist/keywords/vocab7.d.ts +46 -0
- package/dist/keywords/vocab7.d.ts.map +1 -0
- package/dist/keywords/vocab7.js +305 -0
- package/dist/keywords/vocab7.js.map +1 -0
- package/dist/loader.d.ts +41 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +13 -0
- package/dist/loader.js.map +1 -0
- package/dist/lowering.d.ts +371 -0
- package/dist/lowering.d.ts.map +1 -0
- package/dist/lowering.js +59 -0
- package/dist/lowering.js.map +1 -0
- package/dist/output.d.ts +251 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +357 -0
- package/dist/output.js.map +1 -0
- package/dist/records.d.ts +71 -0
- package/dist/records.d.ts.map +1 -0
- package/dist/records.js +150 -0
- package/dist/records.js.map +1 -0
- package/dist/ref.d.ts +10 -0
- package/dist/ref.d.ts.map +1 -0
- package/dist/ref.js +5 -0
- package/dist/ref.js.map +1 -0
- package/dist/regex.d.ts +45 -0
- package/dist/regex.d.ts.map +1 -0
- package/dist/regex.js +163 -0
- package/dist/regex.js.map +1 -0
- package/dist/registry.d.ts +141 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +407 -0
- package/dist/registry.js.map +1 -0
- package/dist/result.d.ts +109 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/result.js +112 -0
- package/dist/result.js.map +1 -0
- package/dist/uri.d.ts +18 -0
- package/dist/uri.d.ts.map +1 -0
- package/dist/uri.js +27 -0
- package/dist/uri.js.map +1 -0
- package/dist/walk.d.ts +25 -0
- package/dist/walk.d.ts.map +1 -0
- package/dist/walk.js +65 -0
- package/dist/walk.js.map +1 -0
- package/package.json +32 -0
- package/src/coverage.ts +88 -0
- package/src/cursor.ts +42 -0
- package/src/dialect.ts +428 -0
- package/src/engine.ts +741 -0
- package/src/index.ts +699 -0
- package/src/json.ts +137 -0
- package/src/keywords/applicator.ts +895 -0
- package/src/keywords/core.ts +168 -0
- package/src/keywords/format.ts +143 -0
- package/src/keywords/metaschemas2019.ts +410 -0
- package/src/keywords/metaschemas2020.ts +443 -0
- package/src/keywords/metaschemas6.ts +226 -0
- package/src/keywords/metaschemas7.ts +253 -0
- package/src/keywords/unevaluated.ts +329 -0
- package/src/keywords/validation.ts +627 -0
- package/src/keywords/vocab2019.ts +676 -0
- package/src/keywords/vocab2020.ts +82 -0
- package/src/keywords/vocab7.ts +393 -0
- package/src/loader.ts +60 -0
- package/src/lowering.ts +414 -0
- package/src/output.ts +651 -0
- package/src/records.ts +226 -0
- package/src/ref.ts +14 -0
- package/src/regex.ts +171 -0
- package/src/registry.ts +481 -0
- package/src/result.ts +252 -0
- package/src/uri.ts +35 -0
- package/src/walk.ts +88 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Henry Andrews
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# @json-schema-engine/core
|
|
2
|
+
|
|
3
|
+
Interpreter core for JSON Schema: a registry, dialects, evaluation, annotations, and output rendering for draft 2020-12, draft 2019-09, draft-07, and draft-06. Install this package on its own for validation and annotation collection; add `@json-schema-engine/compiler`, `@json-schema-engine/formats`, or `@json-schema-engine/dialect-draft04` alongside it when you need compiled artifacts, format assertions, or draft-04 support.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @json-schema-engine/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Example
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import assert from "node:assert";
|
|
15
|
+
import { createEngine } from "@json-schema-engine/core";
|
|
16
|
+
|
|
17
|
+
const engine = createEngine();
|
|
18
|
+
const uri = engine.registerSchema(
|
|
19
|
+
{
|
|
20
|
+
type: "object",
|
|
21
|
+
properties: {
|
|
22
|
+
id: { type: "integer" },
|
|
23
|
+
tags: { type: "array", items: { type: "string" } },
|
|
24
|
+
},
|
|
25
|
+
required: ["id"],
|
|
26
|
+
},
|
|
27
|
+
"https://example.com/item",
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const result = engine.evaluate(uri, { tags: [2] }, { output: "basic" });
|
|
31
|
+
assert.equal(result.valid, false);
|
|
32
|
+
assert.ok(result.errors && result.errors.length > 0);
|
|
33
|
+
assert.equal(engine.evaluate(uri, { id: 1, tags: ["a"] }).valid, true);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Status
|
|
37
|
+
|
|
38
|
+
Version 0.0.1 is published for initial public feedback on both the functionality and the documentation. APIs may change before 1.0. [STATUS.md](https://github.com/handrews/json-schema-engine/blob/main/STATUS.md) is the authoritative statement of what is built and what is staged.
|
|
39
|
+
|
|
40
|
+
## Documentation
|
|
41
|
+
|
|
42
|
+
- [User guide](https://github.com/handrews/json-schema-engine/blob/main/docs/guide/index.md)
|
|
43
|
+
- [Validation](https://github.com/handrews/json-schema-engine/blob/main/docs/guide/validation.md)
|
|
44
|
+
- [Annotations](https://github.com/handrews/json-schema-engine/blob/main/docs/guide/annotations.md)
|
|
45
|
+
- [Conformance](https://github.com/handrews/json-schema-engine/blob/main/docs/conformance.md)
|
|
46
|
+
- [Repository](https://github.com/handrews/json-schema-engine)
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
|
|
50
|
+
MIT
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { DependencyRecord } from "./engine.js";
|
|
2
|
+
import { Cursor } from "./cursor.js";
|
|
3
|
+
/**
|
|
4
|
+
* Folded name coverage: the set of evaluated property names. Ports
|
|
5
|
+
* `unevaluatedProperties.evaluate`'s seen-set union — every `string[]` entry
|
|
6
|
+
* contributes its names; other shapes are ignored.
|
|
7
|
+
*/
|
|
8
|
+
export declare function foldNameCoverage(channel: readonly unknown[]): Set<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Folded index coverage over an array of the given length. Ports
|
|
11
|
+
* `unevaluatedItems.evaluate`'s coveredPrefix/coveredIdx computation: `true`
|
|
12
|
+
* covers the whole array, a `number` extends the covered prefix to value+1
|
|
13
|
+
* (max-folded), a `number[]` marks individual indexes.
|
|
14
|
+
*/
|
|
15
|
+
export declare function foldIndexCoverage(channel: readonly unknown[], length: number): {
|
|
16
|
+
coveredPrefix: number;
|
|
17
|
+
coveredIdx: Set<number>;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Channel entries a fragment (interpreted island) contributes: the data of
|
|
21
|
+
* coverage-producer dependency records at the island's root cursor.
|
|
22
|
+
* `evaluateFragment` returns root-frame surviving records with cursor
|
|
23
|
+
* identity intact; filtering to the fragment's root `cursor` keeps coverage
|
|
24
|
+
* per-instance-location, and filtering to `coverageIds`
|
|
25
|
+
* (SchemaRegistry.coverageIds) keeps only the producers whose data the
|
|
26
|
+
* shape-dispatching folds above understand — other dependency data (an
|
|
27
|
+
* `if` outcome, say) never reaches the channel. Data passes through untouched.
|
|
28
|
+
*/
|
|
29
|
+
export declare function harvestCoverage(dependencies: readonly DependencyRecord[], cursor: Cursor, coverageIds: ReadonlySet<string>): unknown[];
|
|
30
|
+
//# sourceMappingURL=coverage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coverage.d.ts","sourceRoot":"","sources":["../src/coverage.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,SAAS,OAAO,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAUzE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,SAAS,OAAO,EAAE,EAC3B,MAAM,EAAE,MAAM,GACb;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CAAE,CAgBpD;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EAAE,SAAS,gBAAgB,EAAE,EACzC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,GAC/B,OAAO,EAAE,CAMX"}
|
package/dist/coverage.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Compiled-tier port of the consumer keywords' channel-reading semantics
|
|
2
|
+
// (COMPILED-CONSUMERS.md). The runtime coverage channel is a flat array of
|
|
3
|
+
// RAW DEPENDENCY DATA — the same values `ctx.produce` yields — merged with
|
|
4
|
+
// mark/truncate at application boundaries by the serializer (phase B). These
|
|
5
|
+
// helpers fold that channel exactly as the interpreter's `unevaluated*`
|
|
6
|
+
// evaluate() folds visible dependency records, dispatching on VALUE SHAPE
|
|
7
|
+
// (the shape is unambiguous, so one mixed names+indexes channel is sound):
|
|
8
|
+
//
|
|
9
|
+
// - `string[]` evaluated property names (properties/patternProperties/
|
|
10
|
+
// additionalProperties/unevaluatedProperties values); folds
|
|
11
|
+
// into name coverage. Empty array is a no-op.
|
|
12
|
+
// - `true` full index coverage (items / contains-all /
|
|
13
|
+
// prefixItems-covered-whole-array / unevaluatedItems values).
|
|
14
|
+
// - `number` n prefix coverage of indexes 0..n, i.e. coveredPrefix = n+1
|
|
15
|
+
// (prefixItems' largest-applied-index value).
|
|
16
|
+
// - `number[]` individual covered indexes (contains' matched list).
|
|
17
|
+
//
|
|
18
|
+
// Name folding ignores non-`string[]` entries; index folding ignores
|
|
19
|
+
// `string[]` entries; `[]` is a no-op for both.
|
|
20
|
+
/**
|
|
21
|
+
* Folded name coverage: the set of evaluated property names. Ports
|
|
22
|
+
* `unevaluatedProperties.evaluate`'s seen-set union — every `string[]` entry
|
|
23
|
+
* contributes its names; other shapes are ignored.
|
|
24
|
+
*/
|
|
25
|
+
export function foldNameCoverage(channel) {
|
|
26
|
+
const seen = new Set();
|
|
27
|
+
for (const entry of channel) {
|
|
28
|
+
if (Array.isArray(entry)) {
|
|
29
|
+
for (const el of entry) {
|
|
30
|
+
if (typeof el === "string")
|
|
31
|
+
seen.add(el);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return seen;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Folded index coverage over an array of the given length. Ports
|
|
39
|
+
* `unevaluatedItems.evaluate`'s coveredPrefix/coveredIdx computation: `true`
|
|
40
|
+
* covers the whole array, a `number` extends the covered prefix to value+1
|
|
41
|
+
* (max-folded), a `number[]` marks individual indexes.
|
|
42
|
+
*/
|
|
43
|
+
export function foldIndexCoverage(channel, length) {
|
|
44
|
+
let coveredPrefix = 0;
|
|
45
|
+
const coveredIdx = new Set();
|
|
46
|
+
for (const entry of channel) {
|
|
47
|
+
if (entry === true) {
|
|
48
|
+
coveredPrefix = length;
|
|
49
|
+
}
|
|
50
|
+
else if (typeof entry === "number") {
|
|
51
|
+
coveredPrefix = Math.max(coveredPrefix, entry + 1);
|
|
52
|
+
}
|
|
53
|
+
else if (Array.isArray(entry)) {
|
|
54
|
+
// number[] (contains' matched list); string[] contributes no indexes.
|
|
55
|
+
for (const el of entry) {
|
|
56
|
+
if (typeof el === "number")
|
|
57
|
+
coveredIdx.add(el);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { coveredPrefix, coveredIdx };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Channel entries a fragment (interpreted island) contributes: the data of
|
|
65
|
+
* coverage-producer dependency records at the island's root cursor.
|
|
66
|
+
* `evaluateFragment` returns root-frame surviving records with cursor
|
|
67
|
+
* identity intact; filtering to the fragment's root `cursor` keeps coverage
|
|
68
|
+
* per-instance-location, and filtering to `coverageIds`
|
|
69
|
+
* (SchemaRegistry.coverageIds) keeps only the producers whose data the
|
|
70
|
+
* shape-dispatching folds above understand — other dependency data (an
|
|
71
|
+
* `if` outcome, say) never reaches the channel. Data passes through untouched.
|
|
72
|
+
*/
|
|
73
|
+
export function harvestCoverage(dependencies, cursor, coverageIds) {
|
|
74
|
+
const out = [];
|
|
75
|
+
for (const d of dependencies) {
|
|
76
|
+
if (d.cursor === cursor && coverageIds.has(d.behaviorId))
|
|
77
|
+
out.push(d.data);
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=coverage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coverage.js","sourceRoot":"","sources":["../src/coverage.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,2EAA2E;AAC3E,2EAA2E;AAC3E,6EAA6E;AAC7E,wEAAwE;AACxE,0EAA0E;AAC1E,2EAA2E;AAC3E,EAAE;AACF,wEAAwE;AACxE,0EAA0E;AAC1E,4DAA4D;AAC5D,4DAA4D;AAC5D,4EAA4E;AAC5E,0EAA0E;AAC1E,4DAA4D;AAC5D,qEAAqE;AACrE,EAAE;AACF,qEAAqE;AACrE,gDAAgD;AAKhD;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAA2B;IAC1D,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACzB,KAAK,MAAM,EAAE,IAAI,KAAK,EAAE,CAAC;gBACvB,IAAI,OAAO,EAAE,KAAK,QAAQ;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dist/cursor.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { JsonValue } from "./json.js";
|
|
2
|
+
/** A parent-linked position in the instance document. */
|
|
3
|
+
export interface Cursor {
|
|
4
|
+
readonly value: JsonValue;
|
|
5
|
+
readonly parent: Cursor | null;
|
|
6
|
+
readonly segment: string | number | null;
|
|
7
|
+
/** Lazily cached JSON Pointer; use {@link instancePointer}. */
|
|
8
|
+
ptr?: string;
|
|
9
|
+
}
|
|
10
|
+
/** Creates a cursor at the instance document root. */
|
|
11
|
+
export declare const rootCursor: (value: JsonValue) => Cursor;
|
|
12
|
+
/** Creates a cursor for a named or indexed child of `parent`. */
|
|
13
|
+
export declare const childCursor: (parent: Cursor, segment: string | number, value: JsonValue) => Cursor;
|
|
14
|
+
/** Computes the JSON Pointer for a cursor's instance location, caching the result. */
|
|
15
|
+
export declare function instancePointer(cursor: Cursor): string;
|
|
16
|
+
//# sourceMappingURL=cursor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cursor.d.ts","sourceRoot":"","sources":["../src/cursor.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,SAAS,EAAiB,MAAM,WAAW,CAAC;AAErD,yDAAyD;AACzD,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACzC,+DAA+D;IAC/D,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,sDAAsD;AACtD,eAAO,MAAM,UAAU,GAAI,OAAO,SAAS,KAAG,MAI5C,CAAC;AAEH,iEAAiE;AACjE,eAAO,MAAM,WAAW,GACtB,QAAQ,MAAM,EACd,SAAS,MAAM,GAAG,MAAM,EACxB,OAAO,SAAS,KACf,MAAsC,CAAC;AAE1C,sFAAsF;AACtF,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAOtD"}
|
package/dist/cursor.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Instance cursor: a parent-linked position in the instance document.
|
|
2
|
+
//
|
|
3
|
+
// Cursor identity carries semantic weight: in-place applicators ($ref, allOf,
|
|
4
|
+
// if, ...) apply subschemas to the *same* cursor object, while child
|
|
5
|
+
// applicators (properties, items, ...) create child cursors. The channel's
|
|
6
|
+
// visibility query keys on this identity (engine.ts). JSON Pointer strings
|
|
7
|
+
// are materialized lazily, only when output units escape.
|
|
8
|
+
import { escapeSegment } from "./json.js";
|
|
9
|
+
/** Creates a cursor at the instance document root. */
|
|
10
|
+
export const rootCursor = (value) => ({
|
|
11
|
+
value,
|
|
12
|
+
parent: null,
|
|
13
|
+
segment: null,
|
|
14
|
+
});
|
|
15
|
+
/** Creates a cursor for a named or indexed child of `parent`. */
|
|
16
|
+
export const childCursor = (parent, segment, value) => ({ value, parent, segment });
|
|
17
|
+
/** Computes the JSON Pointer for a cursor's instance location, caching the result. */
|
|
18
|
+
export function instancePointer(cursor) {
|
|
19
|
+
if (cursor.ptr !== undefined)
|
|
20
|
+
return cursor.ptr;
|
|
21
|
+
if (cursor.parent === null)
|
|
22
|
+
return (cursor.ptr = "");
|
|
23
|
+
return (cursor.ptr =
|
|
24
|
+
instancePointer(cursor.parent) +
|
|
25
|
+
"/" +
|
|
26
|
+
escapeSegment(String(cursor.segment)));
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=cursor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cursor.js","sourceRoot":"","sources":["../src/cursor.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,EAAE;AACF,8EAA8E;AAC9E,qEAAqE;AACrE,2EAA2E;AAC3E,2EAA2E;AAC3E,0DAA0D;AAE1D,OAAO,EAAa,aAAa,EAAE,MAAM,WAAW,CAAC;AAWrD,sDAAsD;AACtD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAgB,EAAU,EAAE,CAAC,CAAC;IACvD,KAAK;IACL,MAAM,EAAE,IAAI;IACZ,OAAO,EAAE,IAAI;CACd,CAAC,CAAC;AAEH,iEAAiE;AACjE,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,MAAc,EACd,OAAwB,EACxB,KAAgB,EACR,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AAE1C,sFAAsF;AACtF,MAAM,UAAU,eAAe,CAAC,MAAc;IAC5C,IAAI,MAAM,CAAC,GAAG,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC,GAAG,CAAC;IAChD,IAAI,MAAM,CAAC,MAAM,KAAK,IAAI;QAAE,OAAO,CAAC,MAAM,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC;IACrD,OAAO,CAAC,MAAM,CAAC,GAAG;QAChB,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC;YAC9B,GAAG;YACH,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { JsonValue } from "./json.js";
|
|
2
|
+
import { Cursor } from "./cursor.js";
|
|
3
|
+
import { SchemaRef } from "./ref.js";
|
|
4
|
+
import { CompiledRegex } from "./regex.js";
|
|
5
|
+
import { LoweringContext } from "./lowering.js";
|
|
6
|
+
/**
|
|
7
|
+
* Static contribution of one keyword to the evaluated-property-name set of
|
|
8
|
+
* its schema object (D9a). A coverage is a *predicate description*, not
|
|
9
|
+
* necessarily a finite set: `patterns` still lowers (hoisted regexes in the
|
|
10
|
+
* sweep test); only `dynamic` forces runtime evaluated-set tracking.
|
|
11
|
+
*/
|
|
12
|
+
export type NameCoverage = {
|
|
13
|
+
kind: "names";
|
|
14
|
+
names: readonly string[];
|
|
15
|
+
} | {
|
|
16
|
+
kind: "patterns";
|
|
17
|
+
patterns: readonly string[];
|
|
18
|
+
} | {
|
|
19
|
+
kind: "all";
|
|
20
|
+
} | {
|
|
21
|
+
kind: "dynamic";
|
|
22
|
+
};
|
|
23
|
+
/** Static contribution to the evaluated-index coverage of an array (D9a). */
|
|
24
|
+
export type IndexCoverage = {
|
|
25
|
+
kind: "prefix";
|
|
26
|
+
count: number;
|
|
27
|
+
} | {
|
|
28
|
+
kind: "allFrom";
|
|
29
|
+
start: number;
|
|
30
|
+
} | {
|
|
31
|
+
kind: "all";
|
|
32
|
+
} | {
|
|
33
|
+
kind: "dynamic";
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* How a keyword applies one subschema — the compilation planner's edge
|
|
37
|
+
* facts, richer than `subschemas` (which only says where children live and
|
|
38
|
+
* keeps driving the registration walk).
|
|
39
|
+
*/
|
|
40
|
+
export interface SubschemaApplication {
|
|
41
|
+
/** position relative to the keyword's value; [] is the value itself. A leading "../name" is expressed via `sibling` instead. */
|
|
42
|
+
path: readonly (string | number)[];
|
|
43
|
+
/** set when the applied subschema is a sibling keyword's value (if → then/else) */
|
|
44
|
+
sibling?: string;
|
|
45
|
+
/** for reference keywords: the reference value, resolved against the lexical base at plan time (path is ignored) */
|
|
46
|
+
ref?: string;
|
|
47
|
+
mode: "inPlace" | "childByKey" | "childByIndex" | "childSweep" | "propertyName";
|
|
48
|
+
/** application depends on runtime branching (anyOf/oneOf alternatives, if-guarded), not merely instance shape */
|
|
49
|
+
conditional: boolean;
|
|
50
|
+
/** the subschema's verdict feeds this keyword's verdict (false for if's condition role and contains' per-item probes) */
|
|
51
|
+
asserts: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* The verdict feeds NEGATED (`not`): subschema success fails the keyword.
|
|
54
|
+
* Coverage analysis (D9a) skips inverted edges — their records never
|
|
55
|
+
* survive into the parent on the parent-success path (success fails the
|
|
56
|
+
* node; failure discards the frame).
|
|
57
|
+
*/
|
|
58
|
+
inverted?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Static facts about one keyword occurrence, derived from its value alone.
|
|
62
|
+
* This is the compiler tier's entire window into keyword semantics (D1), and
|
|
63
|
+
* it also drives the registry's schema-position walk.
|
|
64
|
+
*/
|
|
65
|
+
export interface StaticFacts {
|
|
66
|
+
/** paths to child schemas, relative to the keyword's value */
|
|
67
|
+
subschemas?: readonly (readonly (string | number)[])[];
|
|
68
|
+
/**
|
|
69
|
+
* reference URIs this keyword's value points at (relative to the lexical
|
|
70
|
+
* base); drives transitive resource loading (D7)
|
|
71
|
+
*/
|
|
72
|
+
references?: readonly string[];
|
|
73
|
+
/**
|
|
74
|
+
* behavior ids of dependency records this keyword can emit — its own id;
|
|
75
|
+
* `produce()` refuses an undeclared producer (engine.ts
|
|
76
|
+
* UndeclaredProductionError). Annotation keywords declare nothing.
|
|
77
|
+
*/
|
|
78
|
+
produces?: readonly string[];
|
|
79
|
+
/** behavior ids of dependency records this keyword reads from the channel */
|
|
80
|
+
consumes?: readonly string[];
|
|
81
|
+
/**
|
|
82
|
+
* regular-expression values this keyword compiles (e.g. `pattern`, the
|
|
83
|
+
* property-name patterns of `patternProperties`); screened by
|
|
84
|
+
* `rejectUnsafeRegex` at registration (see regex.ts)
|
|
85
|
+
*/
|
|
86
|
+
regexes?: readonly string[];
|
|
87
|
+
/**
|
|
88
|
+
* format names this keyword needs a table entry for (the compiler hoists
|
|
89
|
+
* one lookup per name); screened by `UnknownFormatError` at registration
|
|
90
|
+
* under the refuse-unknown posture (see keywords/format.ts)
|
|
91
|
+
*/
|
|
92
|
+
formats?: readonly string[];
|
|
93
|
+
/** participates in dynamic scope resolution ($dynamicRef and friends) */
|
|
94
|
+
dynamicScopeSensitive?: boolean;
|
|
95
|
+
/** static evaluated-name contribution (D9a; see {@link NameCoverage}) */
|
|
96
|
+
evaluatesNames?: NameCoverage;
|
|
97
|
+
/** static evaluated-index contribution (D9a; see {@link IndexCoverage}) */
|
|
98
|
+
evaluatesIndexes?: IndexCoverage;
|
|
99
|
+
/**
|
|
100
|
+
* how this keyword applies its subschemas — planner edge facts
|
|
101
|
+
* ({@link SubschemaApplication}); `subschemas` remains the registration
|
|
102
|
+
* walk's position list
|
|
103
|
+
*/
|
|
104
|
+
applications?: readonly SubschemaApplication[];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Context for {@link KeywordBehavior.analyze}: the keyword's containing
|
|
108
|
+
* schema object, for sibling-dependent facts (`items` starts after
|
|
109
|
+
* `prefixItems`; `if` declares applications for sibling `then`/`else`) —
|
|
110
|
+
* the same sibling reads `evaluate()` performs through `ctx.schema`.
|
|
111
|
+
*/
|
|
112
|
+
export interface AnalyzeContext {
|
|
113
|
+
readonly schema: Readonly<Record<string, JsonValue>>;
|
|
114
|
+
}
|
|
115
|
+
/** Minimal view of a dependency record, for consumer keywords. */
|
|
116
|
+
export interface DependencyView {
|
|
117
|
+
behaviorId: string;
|
|
118
|
+
data: unknown;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The engine services available to one keyword application. This is the only
|
|
122
|
+
* path to subschema application, the channel, and error reporting — the
|
|
123
|
+
* engine owns path/scope/frame bookkeeping in exactly one place (DESIGN.md
|
|
124
|
+
* §3), which is what makes locations compile-time constants for the M6
|
|
125
|
+
* compiler.
|
|
126
|
+
*/
|
|
127
|
+
/**
|
|
128
|
+
* Structured data about one failure, keyed per keyword (D13). Values are
|
|
129
|
+
* plain JSON so downstream mappers (ajv-compat) consume them mechanically
|
|
130
|
+
* instead of parsing message strings.
|
|
131
|
+
*/
|
|
132
|
+
export type ErrorParams = Readonly<Record<string, JsonValue>>;
|
|
133
|
+
export interface KeywordContext {
|
|
134
|
+
/** the current schema object (this keyword's siblings included) */
|
|
135
|
+
readonly schema: Record<string, JsonValue>;
|
|
136
|
+
readonly cursor: Cursor;
|
|
137
|
+
/** apply the subschema at `segments` (relative to the current schema object) */
|
|
138
|
+
apply(segments: readonly (string | number)[], cursor: Cursor): boolean;
|
|
139
|
+
/** resolve a reference against the current lexical base */
|
|
140
|
+
resolveRef(ref: string): SchemaRef;
|
|
141
|
+
/** resolve a `$dynamicRef`-class reference, with dynamic-scope rebinding (D8; see engine.ts resolveDynamic) */
|
|
142
|
+
resolveDynamic(ref: string): SchemaRef;
|
|
143
|
+
/** resolve a 2019-09 `$recursiveRef`, D8's degenerate case (see engine.ts resolveRecursive) */
|
|
144
|
+
resolveRecursive(ref: string): SchemaRef;
|
|
145
|
+
/** apply a resolved reference target at the current cursor */
|
|
146
|
+
applyResolved(target: SchemaRef): boolean;
|
|
147
|
+
/** compile a `pattern`/`patternProperties` regex through the engine's regex engine and cache (see regex.ts) */
|
|
148
|
+
compileRegex(pattern: string): CompiledRegex;
|
|
149
|
+
/**
|
|
150
|
+
* record this keyword's value as an annotation at the current cursor —
|
|
151
|
+
* the annotation value is the keyword value (draft-03 §12.9), so there is
|
|
152
|
+
* nothing to pass
|
|
153
|
+
*/
|
|
154
|
+
annotate(): void;
|
|
155
|
+
/**
|
|
156
|
+
* communicate computed dependency data to other keywords at the current
|
|
157
|
+
* cursor; never output. `analyze().produces` must list this keyword's id.
|
|
158
|
+
*/
|
|
159
|
+
produce(data: unknown): void;
|
|
160
|
+
/**
|
|
161
|
+
* dependency records visible at the current cursor from the listed
|
|
162
|
+
* behaviors; `analyze().consumes` must list them. Draft-03 §12.3 allows a
|
|
163
|
+
* dependency on the same dynamic scope or on successful subscopes: `"all"`
|
|
164
|
+
* (default) sees both — this schema object's keywords plus records merged
|
|
165
|
+
* from successful in-place sub-applications, what `unevaluated*` needs;
|
|
166
|
+
* `"adjacent"` sees only this schema object's own keywords, what `then`
|
|
167
|
+
* and `else` need from `if`.
|
|
168
|
+
*/
|
|
169
|
+
visible(behaviorIds: readonly string[], scope?: "all" | "adjacent"): readonly DependencyView[];
|
|
170
|
+
/** report an assertion failure for this keyword, with optional structured params (D13) */
|
|
171
|
+
error(message: string, params?: ErrorParams): void;
|
|
172
|
+
}
|
|
173
|
+
/** A keyword's static analysis and evaluation semantics. */
|
|
174
|
+
export interface KeywordBehavior {
|
|
175
|
+
/** keyword URI — the stable identity, independent of its name in a dialect */
|
|
176
|
+
readonly id: string;
|
|
177
|
+
/**
|
|
178
|
+
* Evaluation phase within a schema object: phase 1 keywords (unevaluated*)
|
|
179
|
+
* run after all phase 0 keywords have merged their records.
|
|
180
|
+
*/
|
|
181
|
+
readonly phase?: 0 | 1;
|
|
182
|
+
/**
|
|
183
|
+
* An identifier or reserved-location keyword (`$id`, `$defs`, `$comment`,
|
|
184
|
+
* ...): it evaluates to nothing and appears in no output unit (IETF
|
|
185
|
+
* draft-03 §12.6, §12.10), so a trace records no keyword entry for it.
|
|
186
|
+
*/
|
|
187
|
+
readonly structural?: boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Static facts; also drives the registration walk's descent. The context
|
|
190
|
+
* (sibling access) is supplied by every caller; implementations that need
|
|
191
|
+
* no sibling facts ignore it.
|
|
192
|
+
*/
|
|
193
|
+
analyze?(value: JsonValue, context?: AnalyzeContext): StaticFacts;
|
|
194
|
+
/**
|
|
195
|
+
* Evaluates the keyword at `cursor`. A keyword that reports an error
|
|
196
|
+
* through `ctx.error()` must return `false`: the engine drops the errors
|
|
197
|
+
* of an accepting keyword's sub-evaluations (draft-03 §12.2) and throws
|
|
198
|
+
* `KeywordContractError` when the keyword itself reported one.
|
|
199
|
+
*/
|
|
200
|
+
evaluate(value: JsonValue, cursor: Cursor, ctx: KeywordContext): boolean;
|
|
201
|
+
/**
|
|
202
|
+
* Optional compiler lowering (D1/D9): describe this keyword's compiled
|
|
203
|
+
* form as IR through the {@link LoweringContext} — never JavaScript text.
|
|
204
|
+
* Absent ⇒ schema objects containing this keyword become interpreted
|
|
205
|
+
* units (the trampoline fallback). Keep `lower` beside `evaluate` and
|
|
206
|
+
* share their error-message builders: the differential gate compares
|
|
207
|
+
* error text.
|
|
208
|
+
*/
|
|
209
|
+
lower?(value: JsonValue, lctx: LoweringContext): void;
|
|
210
|
+
}
|
|
211
|
+
/** A keyword's binding within one dialect: its name there, behavior, and owning vocabulary. */
|
|
212
|
+
export interface DialectKeyword {
|
|
213
|
+
name: string;
|
|
214
|
+
behavior: KeywordBehavior;
|
|
215
|
+
vocabularyUri: string;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Identifiers found in one schema object, per the dialect's identifier
|
|
219
|
+
* syntax (D18; see {@link IdentifierExtractor}).
|
|
220
|
+
*/
|
|
221
|
+
export interface IdentifierFacts {
|
|
222
|
+
/** value that changes the lexical base (and starts a schema resource) */
|
|
223
|
+
baseId?: string;
|
|
224
|
+
/** plain-name anchors minted at this schema object */
|
|
225
|
+
anchors?: readonly string[];
|
|
226
|
+
/** anchor participating in $dynamicRef rebinding (D8) */
|
|
227
|
+
dynamicAnchor?: string;
|
|
228
|
+
/** 2019-09 $recursiveAnchor; effective at a resource root */
|
|
229
|
+
recursiveAnchor?: boolean;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Extracts identifier facts from a schema object. Identifier syntax varies
|
|
233
|
+
* by draft (D18): 2020-12 has `$id`/`$anchor`/`$dynamicAnchor`; 2019-09
|
|
234
|
+
* replaces the dynamic pair with boolean `$recursiveAnchor`; draft-07/06
|
|
235
|
+
* mint anchors from plain-fragment `$id` and have no anchor keywords at all.
|
|
236
|
+
* The extractor is dialect data consumed by the registry's walk and pointer
|
|
237
|
+
* navigation — keyword behaviors stay syntax-free.
|
|
238
|
+
*/
|
|
239
|
+
export type IdentifierExtractor = (node: Record<string, JsonValue>) => IdentifierFacts;
|
|
240
|
+
/** Identifier syntax for the 2020-12 dialect: `$id`/`$anchor`/`$dynamicAnchor`. */
|
|
241
|
+
export declare const identifiers2020: IdentifierExtractor;
|
|
242
|
+
/** Identifier syntax for the 2019-09 dialect: `$id`/`$anchor`/boolean `$recursiveAnchor`. */
|
|
243
|
+
export declare const identifiers2019: IdentifierExtractor;
|
|
244
|
+
/**
|
|
245
|
+
* Identifier syntax for legacy draft-07/06 dialects: a schema object
|
|
246
|
+
* containing `$ref` has no identifiers at all (the suite's "`$ref` prevents
|
|
247
|
+
* a sibling `$id` from changing the base uri"), and a plain-fragment `$id`
|
|
248
|
+
* is an anchor rather than a base change.
|
|
249
|
+
*/
|
|
250
|
+
export declare const identifiersLegacy: IdentifierExtractor;
|
|
251
|
+
/** An ordered set of vocabularies with identifier and `$ref` semantics (D18). */
|
|
252
|
+
export interface Dialect {
|
|
253
|
+
uri: string;
|
|
254
|
+
/** name -\> entry */
|
|
255
|
+
keywords: ReadonlyMap<string, DialectKeyword>;
|
|
256
|
+
/** evaluation order: phase 0 entries then phase 1 entries */
|
|
257
|
+
ordered: readonly DialectKeyword[];
|
|
258
|
+
/** the vocabularies this dialect was assembled from, in order */
|
|
259
|
+
vocabularyUris: readonly string[];
|
|
260
|
+
allowUnknownKeywords: boolean;
|
|
261
|
+
identifiers: IdentifierExtractor;
|
|
262
|
+
/** draft-07/06: siblings of $ref are treated as if absent */
|
|
263
|
+
refIgnoresSiblings: boolean;
|
|
264
|
+
}
|
|
265
|
+
/** Options for {@link DialectRegistry.registerDialect}. */
|
|
266
|
+
export interface DialectOptions {
|
|
267
|
+
/** unknown keywords are collected as annotations (spec SHOULD); default true */
|
|
268
|
+
allowUnknownKeywords?: boolean;
|
|
269
|
+
/** identifier syntax for this dialect (D18); default 2020-12 */
|
|
270
|
+
identifiers?: IdentifierExtractor;
|
|
271
|
+
/** draft-07/06 $ref semantics: siblings are ignored, not evaluated */
|
|
272
|
+
refIgnoresSiblings?: boolean;
|
|
273
|
+
}
|
|
274
|
+
/** Thrown when a dialect or vocabulary URI has no registered entry. */
|
|
275
|
+
export declare class UnknownDialectError extends Error {
|
|
276
|
+
}
|
|
277
|
+
/** Thrown when a `$vocabulary` URI is required but not registered. */
|
|
278
|
+
export declare class UnknownVocabularyError extends Error {
|
|
279
|
+
}
|
|
280
|
+
/** Thrown when a registry snapshot (a read-only view) is asked to register. */
|
|
281
|
+
export declare class ReadOnlyRegistryError extends Error {
|
|
282
|
+
}
|
|
283
|
+
/** Registry of vocabularies and the dialects assembled from them. */
|
|
284
|
+
export declare class DialectRegistry {
|
|
285
|
+
private vocabularies;
|
|
286
|
+
private dialects;
|
|
287
|
+
private shared;
|
|
288
|
+
private readOnly;
|
|
289
|
+
/**
|
|
290
|
+
* A read-only view of the current registrations. Later registrations on
|
|
291
|
+
* this registry are invisible to the view, and registering into the view
|
|
292
|
+
* throws {@link ReadOnlyRegistryError}. A compiled artifact binds to one
|
|
293
|
+
* so that a compilation boundary cannot change dialect lookups.
|
|
294
|
+
*/
|
|
295
|
+
snapshot(): DialectRegistry;
|
|
296
|
+
private mutable;
|
|
297
|
+
/** Registers a vocabulary's keyword behaviors under its URI. */
|
|
298
|
+
registerVocabulary(uri: string, keywords: Readonly<Record<string, KeywordBehavior>>): void;
|
|
299
|
+
/**
|
|
300
|
+
* Assembles a dialect from already-registered vocabularies.
|
|
301
|
+
* @throws UnknownDialectError if a listed vocabulary is not registered.
|
|
302
|
+
*/
|
|
303
|
+
registerDialect(uri: string, vocabularyUris: readonly string[], options?: DialectOptions): void;
|
|
304
|
+
/**
|
|
305
|
+
* Looks up a registered dialect by URI.
|
|
306
|
+
* @throws UnknownDialectError if the URI has no registered dialect.
|
|
307
|
+
*/
|
|
308
|
+
getDialect(uri: string): Dialect;
|
|
309
|
+
/** True if a dialect is registered under this URI. */
|
|
310
|
+
hasDialect(uri: string): boolean;
|
|
311
|
+
/** True if a vocabulary is registered under this URI. */
|
|
312
|
+
hasVocabulary(uri: string): boolean;
|
|
313
|
+
}
|
|
314
|
+
/** Behavior id for annotations from keywords the dialect doesn't know. */
|
|
315
|
+
export declare const unknownKeywordId: (name: string) => string;
|
|
316
|
+
//# sourceMappingURL=dialect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dialect.d.ts","sourceRoot":"","sources":["../src/dialect.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,W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