@json-schema-engine/compiler 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 +47 -0
- package/dist/emit.d.ts +52 -0
- package/dist/emit.d.ts.map +1 -0
- package/dist/emit.js +166 -0
- package/dist/emit.js.map +1 -0
- package/dist/explain.d.ts +28 -0
- package/dist/explain.d.ts.map +1 -0
- package/dist/explain.js +42 -0
- package/dist/explain.js.map +1 -0
- package/dist/index.d.ts +132 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +169 -0
- package/dist/index.js.map +1 -0
- package/dist/plan.d.ts +83 -0
- package/dist/plan.d.ts.map +1 -0
- package/dist/plan.js +385 -0
- package/dist/plan.js.map +1 -0
- package/dist/runtime-compile.d.ts +30 -0
- package/dist/runtime-compile.d.ts.map +1 -0
- package/dist/runtime-compile.js +29 -0
- package/dist/runtime-compile.js.map +1 -0
- package/dist/runtime.d.ts +157 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +336 -0
- package/dist/runtime.js.map +1 -0
- package/dist/serialize/apply.d.ts +28 -0
- package/dist/serialize/apply.d.ts.map +1 -0
- package/dist/serialize/apply.js +211 -0
- package/dist/serialize/apply.js.map +1 -0
- package/dist/serialize/context.d.ts +143 -0
- package/dist/serialize/context.d.ts.map +1 -0
- package/dist/serialize/context.js +93 -0
- package/dist/serialize/context.js.map +1 -0
- package/dist/serialize/expressions.d.ts +7 -0
- package/dist/serialize/expressions.d.ts.map +1 -0
- package/dist/serialize/expressions.js +177 -0
- package/dist/serialize/expressions.js.map +1 -0
- package/dist/serialize/guards.d.ts +7 -0
- package/dist/serialize/guards.d.ts.map +1 -0
- package/dist/serialize/guards.js +19 -0
- package/dist/serialize/guards.js.map +1 -0
- package/dist/serialize/index.d.ts +7 -0
- package/dist/serialize/index.d.ts.map +1 -0
- package/dist/serialize/index.js +266 -0
- package/dist/serialize/index.js.map +1 -0
- package/dist/serialize/keywords.d.ts +32 -0
- package/dist/serialize/keywords.d.ts.map +1 -0
- package/dist/serialize/keywords.js +131 -0
- package/dist/serialize/keywords.js.map +1 -0
- package/dist/serialize/messages.d.ts +36 -0
- package/dist/serialize/messages.d.ts.map +1 -0
- package/dist/serialize/messages.js +100 -0
- package/dist/serialize/messages.js.map +1 -0
- package/dist/serialize/names.d.ts +47 -0
- package/dist/serialize/names.d.ts.map +1 -0
- package/dist/serialize/names.js +115 -0
- package/dist/serialize/names.js.map +1 -0
- package/dist/serialize/spans.d.ts +34 -0
- package/dist/serialize/spans.d.ts.map +1 -0
- package/dist/serialize/spans.js +61 -0
- package/dist/serialize/spans.js.map +1 -0
- package/dist/serialize/statements.d.ts +16 -0
- package/dist/serialize/statements.d.ts.map +1 -0
- package/dist/serialize/statements.js +396 -0
- package/dist/serialize/statements.js.map +1 -0
- package/dist/serialize/unit.d.ts +8 -0
- package/dist/serialize/unit.d.ts.map +1 -0
- package/dist/serialize/unit.js +107 -0
- package/dist/serialize/unit.js.map +1 -0
- package/dist/standalone.d.ts +24 -0
- package/dist/standalone.d.ts.map +1 -0
- package/dist/standalone.js +166 -0
- package/dist/standalone.js.map +1 -0
- package/package.json +38 -0
- package/src/emit.ts +196 -0
- package/src/explain.ts +67 -0
- package/src/index.ts +366 -0
- package/src/plan.ts +496 -0
- package/src/runtime-compile.ts +90 -0
- package/src/runtime.ts +599 -0
- package/src/serialize/apply.ts +251 -0
- package/src/serialize/context.ts +161 -0
- package/src/serialize/expressions.ts +202 -0
- package/src/serialize/guards.ts +20 -0
- package/src/serialize/index.ts +432 -0
- package/src/serialize/keywords.ts +144 -0
- package/src/serialize/messages.ts +120 -0
- package/src/serialize/names.ts +136 -0
- package/src/serialize/spans.ts +88 -0
- package/src/serialize/statements.ts +531 -0
- package/src/serialize/unit.ts +118 -0
- package/src/standalone.ts +187 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// LowerExpr rendering: instance access, type tests, helper calls, and the
|
|
2
|
+
// coverage-fold membership tests of region emission.
|
|
3
|
+
import { id, join, js, raw, str, json } from "../emit.js";
|
|
4
|
+
import { bindingVar, regexConst, formatConst } from "./names.js";
|
|
5
|
+
import { SerializeError } from "./context.js";
|
|
6
|
+
import { ensureObjGuard } from "./guards.js";
|
|
7
|
+
import { applyCall } from "./apply.js";
|
|
8
|
+
export function expr(ctx, e) {
|
|
9
|
+
switch (e.kind) {
|
|
10
|
+
case "instance":
|
|
11
|
+
return ctx.valueVar;
|
|
12
|
+
case "const":
|
|
13
|
+
return json(e.value);
|
|
14
|
+
case "member":
|
|
15
|
+
return js `${expr(ctx, e.target)}[${str(e.key)}]`;
|
|
16
|
+
case "item":
|
|
17
|
+
return js `${expr(ctx, e.target)}[${expr(ctx, e.index)}]`;
|
|
18
|
+
case "binding":
|
|
19
|
+
return bindingVar(e.id);
|
|
20
|
+
case "typeIs":
|
|
21
|
+
return typeTest(ctx, e.target, e.types);
|
|
22
|
+
case "hasOwn": {
|
|
23
|
+
// Plain-data instance contract (DESIGN §7, M6.5): for JSON data,
|
|
24
|
+
// presence-of-own-key is `key in obj` — plain data has no inherited
|
|
25
|
+
// enumerables, so the prototype chain `in` walks holds nothing but
|
|
26
|
+
// Object.prototype's own names. Keys that live there (constructor,
|
|
27
|
+
// toString, …) or are "__proto__" would false-positive through that
|
|
28
|
+
// chain, so those keep an explicit own-check.
|
|
29
|
+
//
|
|
30
|
+
// `in` with a constant key is the only probe fast on both record
|
|
31
|
+
// shapes (E12, bench/corpora records-*, 2000 records): on uniform
|
|
32
|
+
// records it ties the `obj[key] !== undefined` load it replaces
|
|
33
|
+
// (0.033 ms), while on sparse records — where a value load goes
|
|
34
|
+
// megamorphic over differing shapes — it costs 4.1 ms against that
|
|
35
|
+
// load's 22.7 ms. The own-check forms measure the other way round:
|
|
36
|
+
// ~2.8 ms sparse but ~1.7 ms uniform, a ~50x uniform regression.
|
|
37
|
+
if (typeof e.key === "string") {
|
|
38
|
+
const dangerous = e.key === "__proto__" || e.key in Object.prototype;
|
|
39
|
+
if (ctx.flags.plainData && !dangerous) {
|
|
40
|
+
return js `(${str(e.key)} in ${expr(ctx, e.target)})`;
|
|
41
|
+
}
|
|
42
|
+
return js `${id("h_hop")}.call(${expr(ctx, e.target)}, ${str(e.key)})`;
|
|
43
|
+
}
|
|
44
|
+
return js `${id("h_hop")}.call(${expr(ctx, e.target)}, ${expr(ctx, e.key)})`;
|
|
45
|
+
}
|
|
46
|
+
case "cmp":
|
|
47
|
+
return js `(${expr(ctx, e.left)} ${raw(e.op)} ${expr(ctx, e.right)})`;
|
|
48
|
+
case "helper":
|
|
49
|
+
return helperCall(ctx, e.helper, e.args);
|
|
50
|
+
case "regexTest": {
|
|
51
|
+
let idx = ctx.plan.patterns.indexOf(e.source);
|
|
52
|
+
if (idx === -1) {
|
|
53
|
+
// Coverage patterns can first appear here; the prologue is built
|
|
54
|
+
// after all units serialize, so late additions still hoist.
|
|
55
|
+
idx = ctx.plan.patterns.push(e.source) - 1;
|
|
56
|
+
}
|
|
57
|
+
return js `${regexConst(idx)}.test(${expr(ctx, e.target)})`;
|
|
58
|
+
}
|
|
59
|
+
case "formatTest": {
|
|
60
|
+
let idx = ctx.plan.formats.indexOf(e.name);
|
|
61
|
+
if (idx === -1) {
|
|
62
|
+
// The prologue hoists after all units serialize (as with regexTest),
|
|
63
|
+
// so a name first seen here still gets its lookup const.
|
|
64
|
+
idx = ctx.plan.formats.push(e.name) - 1;
|
|
65
|
+
}
|
|
66
|
+
return js `${formatConst(idx)}.test(${expr(ctx, e.target)})`;
|
|
67
|
+
}
|
|
68
|
+
case "not":
|
|
69
|
+
return js `!(${expr(ctx, e.expr)})`;
|
|
70
|
+
case "logic": {
|
|
71
|
+
const op = e.op === "and" ? " && " : " || ";
|
|
72
|
+
return js `(${join(op, e.parts.map((p) => expr(ctx, p)))})`;
|
|
73
|
+
}
|
|
74
|
+
case "tally":
|
|
75
|
+
case "tallyList":
|
|
76
|
+
throw new SerializeError("'" + e.kind + "' is only meaningful inside a combineCheck message");
|
|
77
|
+
case "applyExpr":
|
|
78
|
+
// The two legal applyExpr positions (`if`'s condition, contains'
|
|
79
|
+
// probe) are intercepted at the statement level so their span can
|
|
80
|
+
// mark/truncate. Reaching here in annotation mode means an
|
|
81
|
+
// unrecognized shape whose records could not be discarded — fail
|
|
82
|
+
// loud rather than lose annotations silently.
|
|
83
|
+
// Region mode intercepts the two legal applyExpr positions at the
|
|
84
|
+
// statement level (if-condition, contains-probe) so their channel span
|
|
85
|
+
// can mark/truncate; reaching here means an unmarkable position.
|
|
86
|
+
if (ctx.annMode || ctx.regionMode) {
|
|
87
|
+
throw new SerializeError("applyExpr in an unmarkable position for keyword '" +
|
|
88
|
+
ctx.currentKeyword +
|
|
89
|
+
"' (" +
|
|
90
|
+
(ctx.annMode ? "annotation" : "region") +
|
|
91
|
+
" mode)");
|
|
92
|
+
}
|
|
93
|
+
// Same call expression an `apply` statement builds; `fold` on this
|
|
94
|
+
// apply is not consulted here (it governs how a wrapping statement
|
|
95
|
+
// uses the value, not how the call itself is rendered).
|
|
96
|
+
return applyCall(ctx, e.apply);
|
|
97
|
+
case "coverageCovers": {
|
|
98
|
+
// Test the folded channel bound by a preceding coverageFold (rule 6):
|
|
99
|
+
// set membership for names, prefix-or-index membership for indexes.
|
|
100
|
+
if (!ctx.regionMode) {
|
|
101
|
+
throw new SerializeError("coverageCovers requires region emission (phase B)");
|
|
102
|
+
}
|
|
103
|
+
const fold = ctx.coverageFolds.get(e.fold);
|
|
104
|
+
if (!fold) {
|
|
105
|
+
throw new SerializeError("coverageCovers without a preceding coverageFold");
|
|
106
|
+
}
|
|
107
|
+
const target = expr(ctx, e.target);
|
|
108
|
+
if (fold.half === "names")
|
|
109
|
+
return js `${fold.var}.has(${target})`;
|
|
110
|
+
return js `(${target} < ${fold.var}.coveredPrefix || ${fold.var}.coveredIdx.has(${target}))`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export function typeTest(ctx, target, types) {
|
|
115
|
+
const x = expr(ctx, target);
|
|
116
|
+
const tests = types.map((t) => {
|
|
117
|
+
switch (t) {
|
|
118
|
+
case "object":
|
|
119
|
+
// Inline (no helper call); CSE'd into one guard per unit value —
|
|
120
|
+
// repeated per-property object tests dominated flag-mode profiles.
|
|
121
|
+
if (x.text === ctx.valueVar.text && types.length === 1) {
|
|
122
|
+
return ensureObjGuard(ctx);
|
|
123
|
+
}
|
|
124
|
+
return js `(typeof ${x} === "object" && ${x} !== null && !Array.isArray(${x}))`;
|
|
125
|
+
case "array":
|
|
126
|
+
return js `Array.isArray(${x})`;
|
|
127
|
+
case "null":
|
|
128
|
+
return js `(${x} === null)`;
|
|
129
|
+
case "integer":
|
|
130
|
+
return js `(typeof ${x} === "number" && Number.isInteger(${x}))`;
|
|
131
|
+
case "string":
|
|
132
|
+
case "boolean":
|
|
133
|
+
return js `(typeof ${x} === ${str(t)})`;
|
|
134
|
+
case "number":
|
|
135
|
+
return js `(typeof ${x} === ${str("number")})`;
|
|
136
|
+
default:
|
|
137
|
+
throw new SerializeError("unknown type test '" + t + "'");
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
return tests.length === 1 ? tests[0] : js `(${join(" || ", tests)})`;
|
|
141
|
+
}
|
|
142
|
+
export function helperCall(ctx, helper, args) {
|
|
143
|
+
if (helper === "jsonEqual") {
|
|
144
|
+
const prim = args.find((a) => a.kind === "const" && (a.value === null || typeof a.value !== "object"));
|
|
145
|
+
const other = args.find((a) => a !== prim);
|
|
146
|
+
if (prim && other) {
|
|
147
|
+
return js `(${expr(ctx, other)} === ${expr(ctx, prim)})`;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const rendered = args.map((a) => expr(ctx, a));
|
|
151
|
+
const hoisted = {
|
|
152
|
+
codePointLength: "h_cpl",
|
|
153
|
+
jsonEqual: "h_eq",
|
|
154
|
+
canonicalKey: "h_ck",
|
|
155
|
+
escapeSegment: "h_esc",
|
|
156
|
+
isMultipleOf: "h_mof",
|
|
157
|
+
hasDuplicateItems: "h_dup",
|
|
158
|
+
firstDuplicatePair: "h_fdp",
|
|
159
|
+
};
|
|
160
|
+
switch (helper) {
|
|
161
|
+
case "keysOf":
|
|
162
|
+
return js `Object.keys(${rendered[0]})`;
|
|
163
|
+
case "lengthOf":
|
|
164
|
+
return js `${rendered[0]}.length`;
|
|
165
|
+
case "codePointLength":
|
|
166
|
+
case "jsonEqual":
|
|
167
|
+
case "canonicalKey":
|
|
168
|
+
case "escapeSegment":
|
|
169
|
+
case "isMultipleOf":
|
|
170
|
+
case "hasDuplicateItems":
|
|
171
|
+
case "firstDuplicatePair":
|
|
172
|
+
return js `${id(hoisted[helper])}(${join(", ", rendered)})`;
|
|
173
|
+
default:
|
|
174
|
+
throw new SerializeError("helper '" + helper + "' is not supported");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=expressions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expressions.js","sourceRoot":"","sources":["../../src/serialize/expressions.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,qDAAqD;AAGrD,OAAO,EAAkB,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAAe,cAAc,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,MAAM,UAAU,IAAI,CAAC,GAAgB,EAAE,CAAY;IACjD,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC;QACf,KAAK,UAAU;YACb,OAAO,GAAG,CAAC,QAAQ,CAAC;QACtB,KAAK,OAAO;YACV,OAAO,IAAI,CAAC,CAAC,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0,0 +1,7 @@
|
|
|
1
|
+
import { type CodeChunk } from "../emit.js";
|
|
2
|
+
import { UnitContext } from "./context.js";
|
|
3
|
+
/** The CSE'd object-test variable for this unit's own value. */
|
|
4
|
+
export declare function ensureObjGuard(ctx: UnitContext): CodeChunk;
|
|
5
|
+
/** Declaration for the guard, when any statement used it. */
|
|
6
|
+
export declare function guardDecl(ctx: UnitContext): CodeChunk | null;
|
|
7
|
+
//# sourceMappingURL=guards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/serialize/guards.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,SAAS,EAAU,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,gEAAgE;AAChE,wBAAgB,cAAc,CAAC,GAAG,EAAE,WAAW,GAAG,SAAS,CAK1D;AAED,6DAA6D;AAC7D,wBAAgB,SAAS,CAAC,GAAG,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,CAI5D"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Object-guard CSE: one typeof/null/array test per unit value, shared by an
|
|
2
|
+
// inlined here-cursor child with its parent.
|
|
3
|
+
import { id, js } from "../emit.js";
|
|
4
|
+
/** The CSE'd object-test variable for this unit's own value. */
|
|
5
|
+
export function ensureObjGuard(ctx) {
|
|
6
|
+
if (ctx.guardParent)
|
|
7
|
+
return ensureObjGuard(ctx.guardParent);
|
|
8
|
+
ctx.objGuardVar ??= id("g" + String(ctx.counters.temp++));
|
|
9
|
+
ctx.objGuardUsed = true;
|
|
10
|
+
return ctx.objGuardVar;
|
|
11
|
+
}
|
|
12
|
+
/** Declaration for the guard, when any statement used it. */
|
|
13
|
+
export function guardDecl(ctx) {
|
|
14
|
+
if (ctx.guardParent || !ctx.objGuardUsed || !ctx.objGuardVar)
|
|
15
|
+
return null;
|
|
16
|
+
const x = ctx.valueVar;
|
|
17
|
+
return js `const ${ctx.objGuardVar} = (typeof ${x} === "object" && ${x} !== null && !Array.isArray(${x}));`;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=guards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../src/serialize/guards.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,6CAA6C;AAE7C,OAAO,EAAkB,EAAE,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAGpD,gEAAgE;AAChE,MAAM,UAAU,cAAc,CAAC,GAAgB;IAC7C,IAAI,GAAG,CAAC,WAAW;QAAE,OAAO,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAC5D,GAAG,CAAC,WAAW,KAAK,EAAE,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC1D,GAAG,CAAC,YAAY,GAAG,IAAI,CAAC;IACxB,OAAO,GAAG,CAAC,WAAW,CAAC;AACzB,CAAC;AAED,6DAA6D;AAC7D,MAAM,UAAU,SAAS,CAAC,GAAgB;IACxC,IAAI,GAAG,CAAC,WAAW,IAAI,CAAC,GAAG,CAAC,YAAY,IAAI,CAAC,GAAG,CAAC,WAAW;QAAE,OAAO,IAAI,CAAC;IAC1E,MAAM,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAC;IACvB,OAAO,EAAE,CAAA,SAAS,GAAG,CAAC,WAAW,cAAc,CAAC,oBAAoB,CAAC,+BAA+B,CAAC,KAAK,CAAC;AAC7G,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type SchemaRegistry } from "@json-schema-engine/core";
|
|
2
|
+
import type { CompilationPlan } from "../plan.js";
|
|
3
|
+
import { type SerializeOptions } from "./context.js";
|
|
4
|
+
export type { AnnotateOptions, EmitFlags, EmitMode, EmitOutput, SerializeOptions, } from "./context.js";
|
|
5
|
+
/** Serializes one compilation plan into artifact source. */
|
|
6
|
+
export declare function serializePlan(plan: CompilationPlan, registry: SchemaRegistry, options?: SerializeOptions): string;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/serialize/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,YAAY,CAAC;AAqB/D,OAAO,EAML,KAAK,gBAAgB,EACtB,MAAM,cAAc,CAAC;AAItB,YAAY,EACV,eAAe,EACf,SAAS,EACT,QAAQ,EACR,UAAU,EACV,gBAAgB,GACjB,MAAM,cAAc,CAAC;AAkHtB,4DAA4D;AAC5D,wBAAgB,aAAa,CAC3B,IAAI,EAAE,eAAe,EACrB,QAAQ,EAAE,cAAc,EACxB,OAAO,GAAE,gBAAqB,GAC7B,MAAM,CA+HR"}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
// IR serializer (M6.2): planned units + keyword lower() IR → artifact
|
|
2
|
+
// source. Flag-mode semantics: fail-fast within a unit (verdict-only),
|
|
3
|
+
// annotations elided, anyOf short-circuit licensed because the planner
|
|
4
|
+
// interprets any node whose channel could be observed (slice licensing;
|
|
5
|
+
// DESIGN §7). All text assembly goes through the gated formatter (emit.ts).
|
|
6
|
+
import { makeRecordPredicate, } from "@json-schema-engine/core";
|
|
7
|
+
import { frag, id, join, js, num, raw, str } from "../emit.js";
|
|
8
|
+
import { V, D, S, R, T, EV, EP, IP, ST, TP, TN, unitFn, unitFnRegion, regexConst, formatConst, channelArgs, fragHelper, } from "./names.js";
|
|
9
|
+
import { UnitContext, SerializeError, DEFAULT_FLAGS, } from "./context.js";
|
|
10
|
+
import { guardDecl } from "./guards.js";
|
|
11
|
+
import { unitBody } from "./unit.js";
|
|
12
|
+
/** The root application call the footer wraps: static function or trampoline, per mode. */
|
|
13
|
+
function rootCallChunk(plan, fnIndex, tableIndex, shape) {
|
|
14
|
+
const root = plan.units.get(plan.rootKey);
|
|
15
|
+
// The root's prefixes are empty; under trace emission its parent is the
|
|
16
|
+
// state's holder node.
|
|
17
|
+
const args = channelArgs(shape, () => [str(""), str("")], js `${ST}.hold`, false);
|
|
18
|
+
if (root.kind === "static") {
|
|
19
|
+
const fn = unitFn(fnIndex.get(root.key));
|
|
20
|
+
return js `${fn}(${join(", ", [V, num(0), id("h_s0"), ...args])})`;
|
|
21
|
+
}
|
|
22
|
+
const slot = num(tableIndex.get(root.key));
|
|
23
|
+
const helper = fragHelper(shape, false);
|
|
24
|
+
return js `${helper}(${join(", ", [js `${T}[${slot}]`, V, id("h_s0"), num(0), ...args])})`;
|
|
25
|
+
}
|
|
26
|
+
/** Helper bindings, the depth bound, and the hoisted regex/format consts (D9f). */
|
|
27
|
+
function prologueChunks(plan, mode, shape, hasRegion) {
|
|
28
|
+
const { output, annMode, trace } = shape;
|
|
29
|
+
// Prologue hoists (D9f): helper bindings, the depth bound, and one const
|
|
30
|
+
// per regex source — property/table lookups move out of the hot path.
|
|
31
|
+
// Standalone mode: the module preamble (standalone.ts) already defines the
|
|
32
|
+
// h_-named helpers; only the regex consts are emitted here, built through
|
|
33
|
+
// the preamble's u-flag-with-fallback constructor.
|
|
34
|
+
const prologue = [];
|
|
35
|
+
if (mode === "runtime") {
|
|
36
|
+
prologue.push(js `const { isObject: h_obj, isInteger: h_int, jsonEqual: h_eq, canonicalKey: h_ck, codePointLength: h_cpl, escapeSegment: h_esc, isMultipleOf: h_mof, hasDuplicateItems: h_dup, firstDuplicatePair: h_fdp, frag: h_frag, fragList: h_fragl, tooDeep: h_deep } = ${R};`, js `const h_maxd = ${R}.maxDepth;`,
|
|
37
|
+
// Shared empty dynamic scope: units append-by-copy, never mutate.
|
|
38
|
+
js `const h_s0 = [];`, js `const h_hop = Object.prototype.hasOwnProperty;`);
|
|
39
|
+
if (annMode && !trace) {
|
|
40
|
+
prologue.push(js `const h_fragla = ${R}.fragListAnn;`);
|
|
41
|
+
}
|
|
42
|
+
// Trace emission records through the runtime: node creation, the record
|
|
43
|
+
// pushes that name their application, the level-dependent cuts, and the
|
|
44
|
+
// traced island trampoline.
|
|
45
|
+
if (trace) {
|
|
46
|
+
prologue.push(js `const { traceState: h_tstate, traceNode: h_tnode, traceError: h_err, traceAnn: h_ann, cutErrors: h_cutE, cutAnns: h_cutA, fragTrace: h_fragt } = ${R};`);
|
|
47
|
+
}
|
|
48
|
+
// Region emission (phase B) helpers: the two channel folds, plus the
|
|
49
|
+
// coverage-harvesting island trampoline in flag mode (list islands go
|
|
50
|
+
// through the list trampolines' trailing-`ev` overloads instead). Only
|
|
51
|
+
// bound when a tracked/region unit exists, so consumer-free artifacts
|
|
52
|
+
// keep their prologue unchanged.
|
|
53
|
+
if (hasRegion) {
|
|
54
|
+
prologue.push(output === "flag"
|
|
55
|
+
? js `const h_covN = ${R}.foldNameCoverage, h_covI = ${R}.foldIndexCoverage, h_fragc = ${R}.fragCov;`
|
|
56
|
+
: js `const h_covN = ${R}.foldNameCoverage, h_covI = ${R}.foldIndexCoverage;`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
plan.patterns.forEach((source, i) => {
|
|
60
|
+
prologue.push(mode === "runtime"
|
|
61
|
+
? js `const ${regexConst(i)} = ${R}.re[${str(source)}];`
|
|
62
|
+
: js `const ${regexConst(i)} = ${id("h_rx")}(${str(source)});`);
|
|
63
|
+
});
|
|
64
|
+
// One format-definition lookup per used name (runtime mode only). Standalone
|
|
65
|
+
// never reaches a format-bearing plan — emitStandalone rejects plan.formats
|
|
66
|
+
// (a format predicate like IDNA cannot be duplicated into a zero-import
|
|
67
|
+
// module), so plan.formats is empty here in that mode.
|
|
68
|
+
plan.formats.forEach((name, i) => {
|
|
69
|
+
prologue.push(js `const ${formatConst(i)} = ${R}.formats[${str(name)}];`);
|
|
70
|
+
});
|
|
71
|
+
return prologue;
|
|
72
|
+
}
|
|
73
|
+
/** The artifact's entry function, per output and mode. */
|
|
74
|
+
function footerChunk(mode, shape, rootCall) {
|
|
75
|
+
const { output, annMode, trace } = shape;
|
|
76
|
+
const ERRS = id("errs");
|
|
77
|
+
const ANNS = id("anns");
|
|
78
|
+
if (trace) {
|
|
79
|
+
// The state carries the flat channels with their owners and the tree;
|
|
80
|
+
// the artifact wrapper turns it into a Result.
|
|
81
|
+
return js `\nreturn function evaluateTrace(${V}) { const ${ST} = ${id("h_tstate")}(); const ok = ${rootCall}; ${ST}.valid = ok; return ${ST}; };\n`;
|
|
82
|
+
}
|
|
83
|
+
const footer = annMode
|
|
84
|
+
? js `\nreturn function evaluateList(${V}) { const ${ERRS} = []; const ${ANNS} = []; const ok = ${rootCall}; return { valid: ok, errors: ${ERRS}, annotations: ${ANNS} }; };\n`
|
|
85
|
+
: output === "list"
|
|
86
|
+
? js `\nreturn function evaluateList(${V}) { const ${ERRS} = []; const ok = ${rootCall}; return { valid: ok, errors: ${ERRS} }; };\n`
|
|
87
|
+
: mode === "runtime"
|
|
88
|
+
? js `\nreturn function validate(${V}) { return ${rootCall}; };\n`
|
|
89
|
+
: js `\nexport default function validate(${V}) { return ${rootCall}; };\n`;
|
|
90
|
+
return footer;
|
|
91
|
+
}
|
|
92
|
+
/** Serializes one compilation plan into artifact source. */
|
|
93
|
+
export function serializePlan(plan, registry, options = {}) {
|
|
94
|
+
const { mode = "runtime", flags = DEFAULT_FLAGS, output = "flag", listParams = false, annotate, trace = false, } = options;
|
|
95
|
+
if (output === "list" && mode === "standalone") {
|
|
96
|
+
throw new SerializeError("standalone emission is flag-only (M6.5 scope)");
|
|
97
|
+
}
|
|
98
|
+
if (trace && output !== "list") {
|
|
99
|
+
throw new SerializeError("trace emission is a list-mode variant");
|
|
100
|
+
}
|
|
101
|
+
// Runtime coverage tracking (COMPILED-CONSUMERS.md) composes with flag AND
|
|
102
|
+
// list/annotation outputs — list plans track every consumer (plan.ts), so
|
|
103
|
+
// region emission there is the normal case. Standalone stays out of scope.
|
|
104
|
+
const hasRegion = [...plan.units.values()].some((u) => u.tracking === true || u.inRegion === true);
|
|
105
|
+
if (hasRegion && mode === "standalone") {
|
|
106
|
+
throw new SerializeError("standalone emission does not support runtime coverage tracking (phase B)");
|
|
107
|
+
}
|
|
108
|
+
// The coverage producers a consumer observes: a region producer pushes its
|
|
109
|
+
// raw dependency data onto the channel only when a consumer reads it and
|
|
110
|
+
// the data is coverage-shaped (rule 5; SchemaRegistry.coverageIds).
|
|
111
|
+
const coverageIds = registry.coverageIds();
|
|
112
|
+
// Annotation collection is a list-mode variant: it reuses the list plan and
|
|
113
|
+
// fail-open, no-short-circuit discipline, adding a flat `anns` channel with
|
|
114
|
+
// mark/truncate at every application boundary (channel rule 3).
|
|
115
|
+
const annMode = annotate !== undefined && output === "list";
|
|
116
|
+
const shape = { output, annMode, trace };
|
|
117
|
+
// Static selection: the annotate/unknown-keyword allow/deny decision, applied
|
|
118
|
+
// at emit time so ruled-out annotations never emit. `keep` is deferred.
|
|
119
|
+
const annKeep = annMode
|
|
120
|
+
? makeRecordPredicate(annotate.selection ?? true)
|
|
121
|
+
: null;
|
|
122
|
+
// List mode disables inlining and boolean-literal folding: shared units
|
|
123
|
+
// carry the evaluation-path/instance-pointer parameters, and a `false`
|
|
124
|
+
// subschema must report "schema is false" rather than fold away.
|
|
125
|
+
const effFlags = output === "list" ? { ...flags, inline: false } : flags;
|
|
126
|
+
// Assign function indexes to static units, table slots to interpreted.
|
|
127
|
+
const fnIndex = new Map();
|
|
128
|
+
const tableIndex = new Map();
|
|
129
|
+
let nextFn = 0;
|
|
130
|
+
for (const unit of plan.units.values()) {
|
|
131
|
+
if (unit.kind === "static")
|
|
132
|
+
fnIndex.set(unit.key, nextFn++);
|
|
133
|
+
}
|
|
134
|
+
plan.targets.forEach((u, i) => tableIndex.set(u.key, i));
|
|
135
|
+
const rendered = [];
|
|
136
|
+
for (const unit of plan.units.values()) {
|
|
137
|
+
if (unit.kind !== "static")
|
|
138
|
+
continue;
|
|
139
|
+
rendered.push(serializeUnit(unit, plan, registry, fnIndex, tableIndex, effFlags, shape, listParams, annKeep, coverageIds, false));
|
|
140
|
+
// A region member carries a second emission whose signature takes the
|
|
141
|
+
// coverage channel; the plain variant above still serves child-cursor
|
|
142
|
+
// and non-region callers (phase B).
|
|
143
|
+
if (unit.inRegion) {
|
|
144
|
+
rendered.push(serializeUnit(unit, plan, registry, fnIndex, tableIndex, effFlags, shape, listParams, annKeep, coverageIds, true));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// Drop dead functions: units expanded into their caller (D9c) and boolean
|
|
148
|
+
// units (their applications folded to literals). The root always stays.
|
|
149
|
+
// Region variants are always retained (correctness first; an uncalled one is
|
|
150
|
+
// inert declaration bytes, phase B size note).
|
|
151
|
+
const inlinedEverywhere = new Set();
|
|
152
|
+
for (const r of rendered)
|
|
153
|
+
for (const k of r.inlined)
|
|
154
|
+
inlinedEverywhere.add(k);
|
|
155
|
+
// List mode calls boolean-false units (they report "schema is false"),
|
|
156
|
+
// so their functions survive the dead-function filter there.
|
|
157
|
+
const functions = rendered
|
|
158
|
+
.filter((r) => r.region ||
|
|
159
|
+
r.key === plan.rootKey ||
|
|
160
|
+
(!inlinedEverywhere.has(r.key) && (!r.boolean || output === "list")))
|
|
161
|
+
.map((r) => r.chunk);
|
|
162
|
+
const rootCall = rootCallChunk(plan, fnIndex, tableIndex, shape);
|
|
163
|
+
const prologue = prologueChunks(plan, mode, shape, hasRegion);
|
|
164
|
+
const footer = footerChunk(mode, shape, rootCall);
|
|
165
|
+
return frag(raw(mode === "runtime" ? '"use strict";\n' : ""), join("\n", prologue), raw("\n"), join("\n", functions), footer).text;
|
|
166
|
+
}
|
|
167
|
+
function serializeUnit(unit, plan, registry, fnIndex, tableIndex, flags, shape, listParams, annKeep, coverageIds,
|
|
168
|
+
/** emitting the channel-threaded region variant of an inRegion unit */
|
|
169
|
+
regionVariant) {
|
|
170
|
+
// Region emission (phase B) applies to a tracked unit's body (a local
|
|
171
|
+
// channel `const ev = []`) and to an inRegion unit's region variant (the
|
|
172
|
+
// channel is a trailing parameter). A tracked unit is never inRegion (nested
|
|
173
|
+
// tracked consumers island), so the two never coincide.
|
|
174
|
+
const regionMode = regionVariant || unit.tracking === true;
|
|
175
|
+
if (regionVariant && unit.tracking) {
|
|
176
|
+
throw new SerializeError("a tracked unit cannot also be a region member");
|
|
177
|
+
}
|
|
178
|
+
const fn = regionVariant
|
|
179
|
+
? unitFnRegion(fnIndex.get(unit.key))
|
|
180
|
+
: unitFn(fnIndex.get(unit.key));
|
|
181
|
+
const node = unit.ref.node;
|
|
182
|
+
const { output, annMode, trace } = shape;
|
|
183
|
+
const sloc = str(unit.ref.baseUri + "#" + unit.ref.pointer);
|
|
184
|
+
// Trace emission: every application, boolean schemas included, is a node.
|
|
185
|
+
const enterNode = js `const ${TN} = ${id("h_tnode")}(${TP}, ${EP}, ${sloc}, ${IP});`;
|
|
186
|
+
// The unit signature carries the channels of the emission (channelArgs); a
|
|
187
|
+
// region variant appends the coverage channel after every other parameter.
|
|
188
|
+
const sig = js `(${join(", ", [V, D, S, ...channelArgs(shape, () => [EP, IP], TP, regionVariant)])})`;
|
|
189
|
+
if (typeof node === "boolean") {
|
|
190
|
+
// List mode: `false` reports the interpreter's boolean-schema error
|
|
191
|
+
// (keywordName null — no keyword suffix on either location).
|
|
192
|
+
// Structured-params mode: keywordName is null here, so the unit gets
|
|
193
|
+
// empty params and no keyword field (renderError's includeParams shape).
|
|
194
|
+
// A `false` schema never produces an annotation; the `anns` parameter is
|
|
195
|
+
// carried only to match the call signature.
|
|
196
|
+
const falseParams = listParams ? js `, params: {}` : js ``;
|
|
197
|
+
const falseUnit = js `{ evaluationPath: ${id("ep")}, schemaLocation: ${sloc}, inputLocation: ${id("ip")}, error: "schema is false"${falseParams} }`;
|
|
198
|
+
const chunk = trace
|
|
199
|
+
? node
|
|
200
|
+
? js `function ${fn}${sig} { ${id("h_tnode")}(${TP}, ${EP}, ${sloc}, ${IP}); return true; }`
|
|
201
|
+
: js `function ${fn}${sig} { ${enterNode} ${TN}.valid = false; ${id("h_err")}(${ST}, ${TN}, ${falseUnit}); return false; }`
|
|
202
|
+
: output === "list" && !node
|
|
203
|
+
? js `function ${fn}${sig} { ${id("errs")}.push(${falseUnit}); return false; }`
|
|
204
|
+
: js `function ${fn}() { return ${raw(String(node))}; }`;
|
|
205
|
+
return {
|
|
206
|
+
key: unit.key,
|
|
207
|
+
boolean: true,
|
|
208
|
+
chunk,
|
|
209
|
+
inlined: new Set(),
|
|
210
|
+
region: false,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const body = [];
|
|
214
|
+
if (unit.reachesInterpreted) {
|
|
215
|
+
// Dynamic-scope contribution: appended once per application, duplicates
|
|
216
|
+
// harmless (outermost-first resolution). Only threaded where a fragment
|
|
217
|
+
// can consume it.
|
|
218
|
+
body.push(js `${S} = [...${S}, ${str(unit.ref.baseUri)}];`);
|
|
219
|
+
}
|
|
220
|
+
if (trace)
|
|
221
|
+
body.push(enterNode);
|
|
222
|
+
// A unit that participates in region emission (a tracked unit, or an
|
|
223
|
+
// inRegion unit — through EITHER variant) never inlines: a single-use child
|
|
224
|
+
// inlined into the plain variant would be dropped by the dead-function
|
|
225
|
+
// filter yet still called by the region variant (which does not inline).
|
|
226
|
+
const unitFlags = regionMode || unit.inRegion === true ? { ...flags, inline: false } : flags;
|
|
227
|
+
const ctx = new UnitContext(unit, plan, registry, fnIndex, tableIndex, V, { binding: 0, tally: 0, temp: 0 }, new Set([unit.key]), null, unitFlags, output, listParams, annMode, annKeep, regionMode, coverageIds, shape.trace);
|
|
228
|
+
const unitStmts = unitBody(ctx);
|
|
229
|
+
// Depth guard (D20 combined budget) only where a chain can grow: a
|
|
230
|
+
// function that calls no unit/fragment cannot recurse, and its own entry
|
|
231
|
+
// was budgeted by every caller on the way down.
|
|
232
|
+
if (ctx.calledUnit) {
|
|
233
|
+
body.unshift(js `if (${D} >= ${id("h_maxd")}) ${id("h_deep")}(); ${D}++;`);
|
|
234
|
+
}
|
|
235
|
+
const guard = guardDecl(ctx);
|
|
236
|
+
if (guard)
|
|
237
|
+
body.push(guard);
|
|
238
|
+
if (output === "list")
|
|
239
|
+
body.push(js `let ok = true;`);
|
|
240
|
+
// A tracked unit owns its channel locally (it is entered like any plain
|
|
241
|
+
// unit); a region variant receives the caller's channel as `ev`.
|
|
242
|
+
if (regionMode && !regionVariant)
|
|
243
|
+
body.push(js `const ${EV} = [];`);
|
|
244
|
+
body.push(...unitStmts);
|
|
245
|
+
if (output === "list") {
|
|
246
|
+
if (trace)
|
|
247
|
+
body.push(js `${TN}.valid = ok;`);
|
|
248
|
+
body.push(js `return ok;`);
|
|
249
|
+
return {
|
|
250
|
+
key: unit.key,
|
|
251
|
+
boolean: false,
|
|
252
|
+
chunk: js `function ${fn}${sig} { ${join("\n", body)} }`,
|
|
253
|
+
inlined: ctx.inlinedKeys,
|
|
254
|
+
region: regionVariant,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
body.push(js `return true;`);
|
|
258
|
+
return {
|
|
259
|
+
key: unit.key,
|
|
260
|
+
boolean: false,
|
|
261
|
+
chunk: js `function ${fn}${sig} { ${join("\n", body)} }`,
|
|
262
|
+
inlined: ctx.inlinedKeys,
|
|
263
|
+
region: regionVariant,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/serialize/index.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,uEAAuE;AACvE,uEAAuE;AACvE,wEAAwE;AACxE,4EAA4E;AAE5E,OAAO,EACL,mBAAmB,GAGpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAkB,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,YAAY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CAAC,CAAC;IAExB,IAAI,MAAM,KAAK,MAAM,EAAE,CAAC;QACtB,IAAI,KAAK;YAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA,GAAG,EAAE,cAAc,CAAC,CAAC;QAC5C,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA,YAAY,CAAC,CAAC;QAC1B,OAAO;YACL,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,EAAE,CAAA,YAAY,EAAE,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI;YACvD,OAAO,EAAE,GAAG,CAAC,WAAW;YACxB,MAAM,EAAE,aAAa;SACtB,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA,cAAc,CAAC,CAAC;IAC5B,OAAO;QACL,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,EAAE,CAAA,YAAY,EAAE,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI;QACvD,OAAO,EAAE,GAAG,CAAC,WAAW;QACxB,MAAM,EAAE,aAAa;KACtB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type LowerCursor, type LowerProduceValue, type LowerStmt } from "@json-schema-engine/core";
|
|
2
|
+
import { type CodeChunk } from "../emit.js";
|
|
3
|
+
import { UnitContext } from "./context.js";
|
|
4
|
+
/**
|
|
5
|
+
* Prepare the keyword currently being emitted: decide whether its annotate
|
|
6
|
+
* survives the static retention lists, whether its produce feeds the
|
|
7
|
+
* coverage channel, and allocate the produce's accumulator (declared by the
|
|
8
|
+
* returned chunks). No-op outside annotation and region modes.
|
|
9
|
+
*/
|
|
10
|
+
export declare function beginKeyword(ctx: UnitContext, stmts: readonly LowerStmt[]): CodeChunk[];
|
|
11
|
+
/**
|
|
12
|
+
* The annotation-unit object literal for the current keyword: constant
|
|
13
|
+
* keyword/vocabulary/schemaLocation, runtime evaluationPath (`ep` suffix)
|
|
14
|
+
* and inputLocation (`ip`), key order matching core's renderAnnotation.
|
|
15
|
+
* `vocabulary` is omitted when null (unknown keywords only).
|
|
16
|
+
*/
|
|
17
|
+
export declare function annUnit(ctx: UnitContext, valueExpr: CodeChunk): CodeChunk;
|
|
18
|
+
/**
|
|
19
|
+
* Record an attempted child-of-here application's segment into the current
|
|
20
|
+
* keyword's produce accumulator (before the verdict — the segment is
|
|
21
|
+
* "attempted", not "succeeded"). Non-child-of-here cursors, and keywords
|
|
22
|
+
* without an active accumulator, record nothing.
|
|
23
|
+
*/
|
|
24
|
+
export declare function annRecordSegment(ctx: UnitContext, cursor: LowerCursor): CodeChunk | null;
|
|
25
|
+
/**
|
|
26
|
+
* Push a consumed producer's dependency data onto the runtime coverage
|
|
27
|
+
* channel (rule 5), writing the value the interpreter would produce. The
|
|
28
|
+
* "has data" guards match the interpreter's produce conditions so the
|
|
29
|
+
* channel carries exactly what a consumer's visible-records fold sees.
|
|
30
|
+
*/
|
|
31
|
+
export declare function produceChannel(ctx: UnitContext, value: LowerProduceValue): CodeChunk;
|
|
32
|
+
//# sourceMappingURL=keywords.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keywords.d.ts","sourceRoot":"","sources":["../../src/serialize/keywords.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,SAAS,EAAoB,MAAM,YAAY,CAAC;AAE9D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG3C;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE,SAAS,SAAS,EAAE,GAC1B,SAAS,EAAE,CA4Cb;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,GAAG,SAAS,CAQzE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,WAAW,GAClB,SAAS,GAAG,IAAI,CAqBlB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE,iBAAiB,GACvB,SAAS,CAiBX"}
|