@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.
Files changed (143) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -0
  3. package/dist/coverage.d.ts +30 -0
  4. package/dist/coverage.d.ts.map +1 -0
  5. package/dist/coverage.js +81 -0
  6. package/dist/coverage.js.map +1 -0
  7. package/dist/cursor.d.ts +16 -0
  8. package/dist/cursor.d.ts.map +1 -0
  9. package/dist/cursor.js +28 -0
  10. package/dist/cursor.js.map +1 -0
  11. package/dist/dialect.d.ts +316 -0
  12. package/dist/dialect.d.ts.map +1 -0
  13. package/dist/dialect.js +135 -0
  14. package/dist/dialect.js.map +1 -0
  15. package/dist/engine.d.ts +203 -0
  16. package/dist/engine.d.ts.map +1 -0
  17. package/dist/engine.js +493 -0
  18. package/dist/engine.js.map +1 -0
  19. package/dist/index.d.ts +182 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +370 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/json.d.ts +49 -0
  24. package/dist/json.d.ts.map +1 -0
  25. package/dist/json.js +128 -0
  26. package/dist/json.js.map +1 -0
  27. package/dist/keywords/applicator.d.ts +57 -0
  28. package/dist/keywords/applicator.d.ts.map +1 -0
  29. package/dist/keywords/applicator.js +789 -0
  30. package/dist/keywords/applicator.js.map +1 -0
  31. package/dist/keywords/core.d.ts +42 -0
  32. package/dist/keywords/core.d.ts.map +1 -0
  33. package/dist/keywords/core.js +139 -0
  34. package/dist/keywords/core.js.map +1 -0
  35. package/dist/keywords/format.d.ts +43 -0
  36. package/dist/keywords/format.d.ts.map +1 -0
  37. package/dist/keywords/format.js +101 -0
  38. package/dist/keywords/format.js.map +1 -0
  39. package/dist/keywords/metaschemas2019.d.ts +3 -0
  40. package/dist/keywords/metaschemas2019.d.ts.map +1 -0
  41. package/dist/keywords/metaschemas2019.js +406 -0
  42. package/dist/keywords/metaschemas2019.js.map +1 -0
  43. package/dist/keywords/metaschemas2020.d.ts +3 -0
  44. package/dist/keywords/metaschemas2020.d.ts.map +1 -0
  45. package/dist/keywords/metaschemas2020.js +441 -0
  46. package/dist/keywords/metaschemas2020.js.map +1 -0
  47. package/dist/keywords/metaschemas6.d.ts +3 -0
  48. package/dist/keywords/metaschemas6.d.ts.map +1 -0
  49. package/dist/keywords/metaschemas6.js +221 -0
  50. package/dist/keywords/metaschemas6.js.map +1 -0
  51. package/dist/keywords/metaschemas7.d.ts +3 -0
  52. package/dist/keywords/metaschemas7.d.ts.map +1 -0
  53. package/dist/keywords/metaschemas7.js +248 -0
  54. package/dist/keywords/metaschemas7.js.map +1 -0
  55. package/dist/keywords/unevaluated.d.ts +14 -0
  56. package/dist/keywords/unevaluated.d.ts.map +1 -0
  57. package/dist/keywords/unevaluated.js +296 -0
  58. package/dist/keywords/unevaluated.js.map +1 -0
  59. package/dist/keywords/validation.d.ts +21 -0
  60. package/dist/keywords/validation.d.ts.map +1 -0
  61. package/dist/keywords/validation.js +332 -0
  62. package/dist/keywords/validation.js.map +1 -0
  63. package/dist/keywords/vocab2019.d.ts +36 -0
  64. package/dist/keywords/vocab2019.d.ts.map +1 -0
  65. package/dist/keywords/vocab2019.js +585 -0
  66. package/dist/keywords/vocab2019.js.map +1 -0
  67. package/dist/keywords/vocab2020.d.ts +20 -0
  68. package/dist/keywords/vocab2020.d.ts.map +1 -0
  69. package/dist/keywords/vocab2020.js +55 -0
  70. package/dist/keywords/vocab2020.js.map +1 -0
  71. package/dist/keywords/vocab7.d.ts +46 -0
  72. package/dist/keywords/vocab7.d.ts.map +1 -0
  73. package/dist/keywords/vocab7.js +305 -0
  74. package/dist/keywords/vocab7.js.map +1 -0
  75. package/dist/loader.d.ts +41 -0
  76. package/dist/loader.d.ts.map +1 -0
  77. package/dist/loader.js +13 -0
  78. package/dist/loader.js.map +1 -0
  79. package/dist/lowering.d.ts +371 -0
  80. package/dist/lowering.d.ts.map +1 -0
  81. package/dist/lowering.js +59 -0
  82. package/dist/lowering.js.map +1 -0
  83. package/dist/output.d.ts +251 -0
  84. package/dist/output.d.ts.map +1 -0
  85. package/dist/output.js +357 -0
  86. package/dist/output.js.map +1 -0
  87. package/dist/records.d.ts +71 -0
  88. package/dist/records.d.ts.map +1 -0
  89. package/dist/records.js +150 -0
  90. package/dist/records.js.map +1 -0
  91. package/dist/ref.d.ts +10 -0
  92. package/dist/ref.d.ts.map +1 -0
  93. package/dist/ref.js +5 -0
  94. package/dist/ref.js.map +1 -0
  95. package/dist/regex.d.ts +45 -0
  96. package/dist/regex.d.ts.map +1 -0
  97. package/dist/regex.js +163 -0
  98. package/dist/regex.js.map +1 -0
  99. package/dist/registry.d.ts +141 -0
  100. package/dist/registry.d.ts.map +1 -0
  101. package/dist/registry.js +407 -0
  102. package/dist/registry.js.map +1 -0
  103. package/dist/result.d.ts +109 -0
  104. package/dist/result.d.ts.map +1 -0
  105. package/dist/result.js +112 -0
  106. package/dist/result.js.map +1 -0
  107. package/dist/uri.d.ts +18 -0
  108. package/dist/uri.d.ts.map +1 -0
  109. package/dist/uri.js +27 -0
  110. package/dist/uri.js.map +1 -0
  111. package/dist/walk.d.ts +25 -0
  112. package/dist/walk.d.ts.map +1 -0
  113. package/dist/walk.js +65 -0
  114. package/dist/walk.js.map +1 -0
  115. package/package.json +32 -0
  116. package/src/coverage.ts +88 -0
  117. package/src/cursor.ts +42 -0
  118. package/src/dialect.ts +428 -0
  119. package/src/engine.ts +741 -0
  120. package/src/index.ts +699 -0
  121. package/src/json.ts +137 -0
  122. package/src/keywords/applicator.ts +895 -0
  123. package/src/keywords/core.ts +168 -0
  124. package/src/keywords/format.ts +143 -0
  125. package/src/keywords/metaschemas2019.ts +410 -0
  126. package/src/keywords/metaschemas2020.ts +443 -0
  127. package/src/keywords/metaschemas6.ts +226 -0
  128. package/src/keywords/metaschemas7.ts +253 -0
  129. package/src/keywords/unevaluated.ts +329 -0
  130. package/src/keywords/validation.ts +627 -0
  131. package/src/keywords/vocab2019.ts +676 -0
  132. package/src/keywords/vocab2020.ts +82 -0
  133. package/src/keywords/vocab7.ts +393 -0
  134. package/src/loader.ts +60 -0
  135. package/src/lowering.ts +414 -0
  136. package/src/output.ts +651 -0
  137. package/src/records.ts +226 -0
  138. package/src/ref.ts +14 -0
  139. package/src/regex.ts +171 -0
  140. package/src/registry.ts +481 -0
  141. package/src/result.ts +252 -0
  142. package/src/uri.ts +35 -0
  143. package/src/walk.ts +88 -0
@@ -0,0 +1,371 @@
1
+ import { JsonValue, JsonType } from "./json.js";
2
+ /** A value-producing IR expression. */
3
+ export type LowerExpr =
4
+ /** the instance value under evaluation at the lowering site */
5
+ {
6
+ readonly kind: "instance";
7
+ }
8
+ /** a hoisted JSON constant (emitted via the gated formatter's json()) */
9
+ | {
10
+ readonly kind: "const";
11
+ readonly value: JsonValue;
12
+ }
13
+ /** object member access by schema-derived key (bracket notation, escaped) */
14
+ | {
15
+ readonly kind: "member";
16
+ readonly target: LowerExpr;
17
+ readonly key: string;
18
+ }
19
+ /** array element access */
20
+ | {
21
+ readonly kind: "item";
22
+ readonly target: LowerExpr;
23
+ readonly index: LowerExpr;
24
+ }
25
+ /** a loop binding introduced by forEachKey/forEachIndex */
26
+ | {
27
+ readonly kind: "binding";
28
+ readonly id: number;
29
+ }
30
+ /** JSON type test, including the "integer" refinement */
31
+ | {
32
+ readonly kind: "typeIs";
33
+ readonly target: LowerExpr;
34
+ readonly types: readonly (JsonType | "integer")[];
35
+ }
36
+ /** Object.hasOwn(target, key) — the only permitted membership test */
37
+ | {
38
+ readonly kind: "hasOwn";
39
+ readonly target: LowerExpr;
40
+ readonly key: LowerExpr | string;
41
+ }
42
+ /** numeric/string comparison of two expressions */
43
+ | {
44
+ readonly kind: "cmp";
45
+ readonly op: "<" | "<=" | ">" | ">=" | "===" | "!==";
46
+ readonly left: LowerExpr;
47
+ readonly right: LowerExpr;
48
+ }
49
+ /** call into the closed helper registry (never arbitrary code) */
50
+ | {
51
+ readonly kind: "helper";
52
+ readonly helper: LowerHelper;
53
+ readonly args: readonly LowerExpr[];
54
+ }
55
+ /** test a hoisted regex (compiled through the engine's RegexCache) */
56
+ | {
57
+ readonly kind: "regexTest";
58
+ readonly source: string;
59
+ readonly target: LowerExpr;
60
+ }
61
+ /** test a hoisted format definition (compiled through the engine's format table) */
62
+ | {
63
+ readonly kind: "formatTest";
64
+ readonly name: string;
65
+ readonly target: LowerExpr;
66
+ } | {
67
+ readonly kind: "not";
68
+ readonly expr: LowerExpr;
69
+ } | {
70
+ readonly kind: "logic";
71
+ readonly op: "and" | "or";
72
+ readonly parts: readonly LowerExpr[];
73
+ }
74
+ /** the active combine-group tally (oneOf's match count) in a combineCheck message */
75
+ | {
76
+ readonly kind: "tally";
77
+ }
78
+ /**
79
+ * The passing branch INDEXES of the active combine group, as an array —
80
+ * combineCheck params only (oneOf reports which branches matched, not
81
+ * just how many; the ajv-compat mapping needs the indexes).
82
+ */
83
+ | {
84
+ readonly kind: "tallyList";
85
+ }
86
+ /**
87
+ * A subschema application used as a boolean expression rather than a
88
+ * statement (M6.4): `if`'s condition, `not`'s single negated apply, and
89
+ * `contains`'/`oneOf`'s per-branch probes all need the verdict as a value,
90
+ * not a verdict-folding statement. The serializer renders it as the same
91
+ * call expression `apply` statements use; `apply.fold` still governs how a
92
+ * caller that wraps this in a statement folds the result (e.g. `negate`,
93
+ * `exactlyOne`), while a bare `applyExpr` used purely for its value (e.g.
94
+ * as a `forEachIndex` counter guard) carries `fold: "discard"`.
95
+ */
96
+ | {
97
+ readonly kind: "applyExpr";
98
+ readonly apply: LowerApply;
99
+ }
100
+ /**
101
+ * True when the folded coverage bound by a preceding `coverageFold`
102
+ * (identified by `fold`, its binding id) covers `target` — the swept
103
+ * property name (names half: set membership) or array index (indexes half:
104
+ * index below coveredPrefix, or index in coveredIdx). The consumer keyword's
105
+ * runtime sweep applies its subschema exactly where this is false, matching
106
+ * the interpreter's "skip already-evaluated" loop.
107
+ */
108
+ | {
109
+ readonly kind: "coverageCovers";
110
+ readonly fold: number;
111
+ readonly target: LowerExpr;
112
+ };
113
+ /**
114
+ * The closed set of runtime helpers emitted code may call. All are imported
115
+ * from the compiler's runtime module (re-exports of core functions) — never
116
+ * re-emitted per artifact, so compiled and interpreted tiers share one
117
+ * implementation of each semantic.
118
+ */
119
+ export type LowerHelper = "codePointLength" | "jsonEqual" | "canonicalKey" | "escapeSegment" | "keysOf" | "lengthOf" | "isMultipleOf" | "hasDuplicateItems" | "firstDuplicatePair";
120
+ /** A statement-level IR node. */
121
+ export type LowerStmt = {
122
+ readonly kind: "if";
123
+ readonly cond: LowerExpr;
124
+ readonly then: readonly LowerStmt[];
125
+ readonly else?: readonly LowerStmt[];
126
+ }
127
+ /** iterate own enumerable keys (Object.keys) binding each name */
128
+ | {
129
+ readonly kind: "forEachKey";
130
+ readonly target: LowerExpr;
131
+ readonly binding: number;
132
+ readonly body: readonly LowerStmt[];
133
+ }
134
+ /** iterate array indexes 0..length-1 (optionally from a constant start) */
135
+ | {
136
+ readonly kind: "forEachIndex";
137
+ readonly target: LowerExpr;
138
+ readonly binding: number;
139
+ readonly start?: number;
140
+ readonly body: readonly LowerStmt[];
141
+ }
142
+ /** report this keyword's assertion failure at the current cursor */
143
+ | {
144
+ readonly kind: "fail";
145
+ readonly message: LowerMessage;
146
+ readonly params?: LowerParams;
147
+ }
148
+ /**
149
+ * record this keyword's value as an annotation (channel rule 2); the
150
+ * serializer emits the schema constant, so the node carries no payload
151
+ */
152
+ | {
153
+ readonly kind: "annotate";
154
+ }
155
+ /** emit this keyword's dependency data (channel rule 2) */
156
+ | {
157
+ readonly kind: "produce";
158
+ readonly value: LowerProduceValue;
159
+ }
160
+ /**
161
+ * Bind the folded coverage of the unit's runtime channel (consumer
162
+ * keywords only). The serializer supplies the channel — the flat array of
163
+ * raw dependency data from consumed producers, merged with mark/truncate
164
+ * at application boundaries — and folds it per `half`: "names" yields the
165
+ * evaluated-name set (foldNameCoverage), "indexes" yields the coveredPrefix/
166
+ * coveredIdx summary over the CURRENT instance array's length
167
+ * (foldIndexCoverage). The result is held in `binding` for a following
168
+ * `coverageCovers` to test. The compiled tier's alternative to
169
+ * `staticCoverage()`: emitted only when the planner licensed runtime
170
+ * evaluated-set tracking (LoweringContext.runtimeCoverage()).
171
+ */
172
+ | {
173
+ readonly kind: "coverageFold";
174
+ readonly half: "names" | "indexes";
175
+ readonly binding: number;
176
+ }
177
+ /**
178
+ * Apply a subschema and fold its verdict into the keyword verdict per
179
+ * `fold`. EAGER combine semantics (header note 2). `apply.cursor`
180
+ * identifies the instance position; the compiler owns frames, locations,
181
+ * and scope threading, exactly as the engine does for the interpreter.
182
+ */
183
+ | {
184
+ readonly kind: "apply";
185
+ readonly apply: LowerApply;
186
+ }
187
+ /**
188
+ * Closes the immediately preceding run of anyMayPass/exactlyOne applies:
189
+ * the keyword fails (with `message`) when the run's combined verdict
190
+ * fails. Emitted by the keyword's lower() so failure text stays keyword
191
+ * knowledge (D1); the serializer folds it into the grouped check.
192
+ */
193
+ | {
194
+ readonly kind: "combineCheck";
195
+ readonly message: LowerMessage;
196
+ readonly params?: LowerParams;
197
+ }
198
+ /**
199
+ * `contains`'s shape: iterate array indexes 0..length-1 (like
200
+ * `forEachIndex`, binding each index), counting the iterations where
201
+ * `countWhen` holds true, then fail the keyword when the final count
202
+ * falls outside `[min, max]`. Every index is probed unconditionally (no
203
+ * short-circuit on reaching `max`), matching evaluate()'s full sweep.
204
+ * `countWhen` is typically an `applyExpr` with `fold: "discard"` (the
205
+ * per-item probe verdict feeds the count, never the keyword verdict
206
+ * directly — a failed probe is not itself a `contains` failure).
207
+ */
208
+ | {
209
+ readonly kind: "countRange";
210
+ readonly target: LowerExpr;
211
+ readonly binding: number;
212
+ readonly countWhen: LowerExpr;
213
+ /** accumulate the counted indexes for a following produce (contains' dependency data) */
214
+ readonly collectIndexes?: boolean;
215
+ readonly min: number;
216
+ readonly max: number;
217
+ readonly outOfRangeMessage: LowerMessage;
218
+ readonly outOfRangeParams?: LowerParams;
219
+ };
220
+ /** How a keyword's lowered body applies one subschema. */
221
+ export interface LowerApply {
222
+ /** subschema position relative to the keyword's schema object (matches StaticFacts.applications[].path, with loop bindings for dynamic segments) */
223
+ readonly path: readonly (string | number | {
224
+ binding: number;
225
+ })[];
226
+ /**
227
+ * Set when the applied subschema is a sibling keyword's value (`if` →
228
+ * `then`/`else`), mirroring {@link SubschemaApplication.sibling} — the
229
+ * planner already resolves the edge this way (plan.ts); the serializer
230
+ * matches an apply back to its planned edge by keyword + sibling + path
231
+ * identity, so a keyword emitting more than one apply at the same `path`
232
+ * (e.g. `if`'s condition vs. its `then` edge, both `path: []`) MUST set
233
+ * this to disambiguate.
234
+ */
235
+ readonly sibling?: string;
236
+ /**
237
+ * For reference keywords: the reference value. The compiler resolves it
238
+ * at plan time against the unit's lexical base; `path` is ignored.
239
+ */
240
+ readonly ref?: string;
241
+ /** instance cursor for the application */
242
+ readonly cursor: LowerCursor;
243
+ /** failure message for folds that assert with their own error (negate) */
244
+ readonly message?: LowerMessage;
245
+ /** structured params accompanying `message` (D13) */
246
+ readonly params?: LowerParams;
247
+ /** how the application verdict folds into the keyword verdict */
248
+ readonly fold: "allMustPass" | "anyMayPass" | "exactlyOne" | "negate" | "discard";
249
+ }
250
+ /** Instance cursor IR: the current node or a child of one. */
251
+ export type LowerCursor = {
252
+ readonly kind: "here";
253
+ } | {
254
+ readonly kind: "child";
255
+ readonly of: LowerCursor;
256
+ readonly segment: LowerExpr | string | number;
257
+ }
258
+ /**
259
+ * `propertyNames`: the current loop binding's KEY STRING is the instance
260
+ * under evaluation, not a child of the object being iterated (there is no
261
+ * parent cursor to descend from — the property name itself is the value).
262
+ */
263
+ | {
264
+ readonly kind: "key";
265
+ readonly binding: number;
266
+ };
267
+ /**
268
+ * An error message: literal parts joined with expression parts, escaped by
269
+ * the serializer. Mirrors the interpreter's message-builder output so the
270
+ * differential gate can compare error text exactly.
271
+ */
272
+ export type LowerMessage = readonly (string | LowerExpr)[];
273
+ /**
274
+ * Structured failure params (D13): each value is an expression so runtime
275
+ * pieces (a swept key, a tally, a duplicate pair) sit next to compile-time
276
+ * constants (`lowerIR.constant`). Mirrors the interpreter's
277
+ * `ctx.error(message, params)` so the differential gate can compare params
278
+ * exactly.
279
+ */
280
+ export type LowerParams = Readonly<Record<string, LowerExpr>>;
281
+ /**
282
+ * A dependency-data recipe: what a keyword's lowered body communicates to
283
+ * consumer keywords.
284
+ *
285
+ * Recipes read the accumulation the keyword's statements build against the
286
+ * instance. Within one keyword's lowered statement list, each executed
287
+ * child-of-here application (an `apply` or `applyExpr` whose cursor is
288
+ * `{kind:"child", of:{kind:"here"}, segment}`) contributes its segment —
289
+ * string segments to a name accumulation, numeric segments to an index
290
+ * accumulation — in execution order, deduplicated keeping the first
291
+ * occurrence. Applications count when ATTEMPTED, regardless of the
292
+ * subschema's verdict (the interpreter records the segment before applying).
293
+ */
294
+ export type LowerProduceValue =
295
+ /**
296
+ * The accumulated (deduped) name array, possibly empty. Object-shaped
297
+ * producers emit an empty array for an object and nothing for a non-object,
298
+ * so lower() must gate this produce behind an instance object-type check.
299
+ */
300
+ {
301
+ readonly kind: "collectedNames";
302
+ }
303
+ /**
304
+ * The accumulated index array, rendered per `render`:
305
+ *
306
+ * - `"largestOrTrue"`: no accumulated indexes yields no production;
307
+ * otherwise `true` when the largest index + 1 equals the instance array
308
+ * length, else the largest accumulated index (a number).
309
+ * - `"appliedTrue"`: any accumulated index yields `true`; none yields no
310
+ * production.
311
+ * - `"matchedOrAllTrue"`: reads the keyword's countRange-counted indexes
312
+ * (see `collectIndexes`) — empty yields no production; a count equal to
313
+ * the instance array length yields `true`; otherwise the ascending index
314
+ * array.
315
+ */
316
+ | {
317
+ readonly kind: "collectedIndexes";
318
+ readonly render: "largestOrTrue" | "appliedTrue" | "matchedOrAllTrue";
319
+ };
320
+ /**
321
+ * Services available to one keyword's `lower()` (mirror of KeywordContext,
322
+ * D3): the only path to subschema application, hoisting, and the channel.
323
+ * Implemented by the compiler package; core defines the contract so keyword
324
+ * modules never import the compiler.
325
+ */
326
+ export interface LoweringContext {
327
+ /** the instance expression at this lowering site */
328
+ readonly instance: LowerExpr;
329
+ /** the keyword's containing schema object (plan-time data) */
330
+ readonly schema: Readonly<Record<string, JsonValue>>;
331
+ /**
332
+ * The static evaluated-coverage result for this schema object (D9a),
333
+ * for `unevaluated*` lowerings: null when any contributor is dynamic —
334
+ * the lowering must then fall back to runtime evaluated-set tracking.
335
+ */
336
+ staticCoverage(): {
337
+ names: readonly string[];
338
+ patterns: readonly string[];
339
+ coversAllNames: boolean;
340
+ prefixCount: number;
341
+ coversAllIndexes: boolean;
342
+ } | null;
343
+ /**
344
+ * True when the planner licensed RUNTIME evaluated-set tracking for this
345
+ * unit's consumer keywords: coverage flows through the unit's runtime
346
+ * channel and the keyword must emit coverageFold/coverageCovers instead of
347
+ * reading staticCoverage(). Exactly one of the two paths applies.
348
+ */
349
+ runtimeCoverage(): boolean;
350
+ /** append statements to the keyword's lowered body */
351
+ emit(...stmts: LowerStmt[]): void;
352
+ /** allocate a loop binding id for forEachKey/forEachIndex */
353
+ binding(): number;
354
+ }
355
+ /** Constructor shorthands for the common IR shapes. */
356
+ export declare const lowerIR: {
357
+ instance: LowerExpr;
358
+ constant: (value: JsonValue) => LowerExpr;
359
+ typeIs: (target: LowerExpr, ...types: readonly (JsonType | "integer")[]) => LowerExpr;
360
+ not: (expr: LowerExpr) => LowerExpr;
361
+ and: (...parts: readonly LowerExpr[]) => LowerExpr;
362
+ or: (...parts: readonly LowerExpr[]) => LowerExpr;
363
+ regexTest: (source: string, target: LowerExpr) => LowerExpr;
364
+ formatTest: (name: string, target: LowerExpr) => LowerExpr;
365
+ helper: (helper: LowerHelper, ...args: readonly LowerExpr[]) => LowerExpr;
366
+ cmp: (op: "<" | "<=" | ">" | ">=" | "===" | "!==", left: LowerExpr, right: LowerExpr) => LowerExpr;
367
+ fail: (...message: LowerMessage) => LowerStmt;
368
+ failWith: (params: LowerParams, ...message: LowerMessage) => LowerStmt;
369
+ when: (cond: LowerExpr, then: readonly LowerStmt[], elseStmts?: readonly LowerStmt[]) => LowerStmt;
370
+ };
371
+ //# sourceMappingURL=lowering.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lowering.d.ts","sourceRoot":"","sources":["../src/lowering.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEhD,uCAAuC;AACvC,MAAM,MAAM,SAAS;AACnB,+DAA+D;AAC7D;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAA;CAAE;AAC/B,yEAAyE;GACvE;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;CAAE;AACvD,6EAA6E;GAC3E;IACE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AACH,2BAA2B;GACzB;IACE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;CAC3B;AACH,2DAA2D;GACzD;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;CAAE;AACnD,yDAAyD;GACvD;IACE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,EAAE,CAAC;CACnD;AACH,sEAAsE;GACpE;IACE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;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AAI,GAAG,KAAK,GAAG,KAAK,QACrC,SAAS,SACR,SAAS,KACf,SAAS;uBACO,YAAY,KAAG,SAAS;uBACxB,WAAW,cAAc,YAAY,KAAG,SAAS;iBAM5D,SAAS,QACT,SAAS,SAAS,EAAE,cACd,SAAS,SAAS,EAAE,KAC/B,SAAS;CACb,CAAC"}
@@ -0,0 +1,59 @@
1
+ // Compiler lowering IR (D1/D9, M6.1): the type vocabulary keyword behaviors
2
+ // use to describe their compiled form, and the LoweringContext service
3
+ // interface the compiler implements. Types only — core carries no compiler
4
+ // runtime. Keyword modules depend on this file, never on @json-schema-engine/compiler, so
5
+ // keyword knowledge stays in exactly one module per keyword.
6
+ //
7
+ // Two properties are load-bearing for security and semantics:
8
+ //
9
+ // 1. No IR node carries raw JavaScript text. Schema-derived data enters only
10
+ // as data nodes (constants, property keys, regex sources), which the
11
+ // compiler's gated serializer escapes. Injection is unrepresentable
12
+ // upstream of the serializer (D20/M6).
13
+ //
14
+ // 2. `combine` is EAGER: every part is evaluated, then the verdicts fold.
15
+ // This is channel rule 6 (DESIGN.md §4) in the IR contract — branches
16
+ // cannot short-circuit while a consumer or retained annotation could
17
+ // observe them. The serializer may emit short-circuits only where the
18
+ // compilation plan proves the region verdict-only.
19
+ /** Constructor shorthands for the common IR shapes. */
20
+ export const lowerIR = {
21
+ instance: { kind: "instance" },
22
+ constant: (value) => ({ kind: "const", value }),
23
+ typeIs: (target, ...types) => ({ kind: "typeIs", target, types }),
24
+ not: (expr) => ({ kind: "not", expr }),
25
+ and: (...parts) => ({
26
+ kind: "logic",
27
+ op: "and",
28
+ parts,
29
+ }),
30
+ or: (...parts) => ({
31
+ kind: "logic",
32
+ op: "or",
33
+ parts,
34
+ }),
35
+ regexTest: (source, target) => ({
36
+ kind: "regexTest",
37
+ source,
38
+ target,
39
+ }),
40
+ formatTest: (name, target) => ({
41
+ kind: "formatTest",
42
+ name,
43
+ target,
44
+ }),
45
+ helper: (helper, ...args) => ({
46
+ kind: "helper",
47
+ helper,
48
+ args,
49
+ }),
50
+ cmp: (op, left, right) => ({ kind: "cmp", op, left, right }),
51
+ fail: (...message) => ({ kind: "fail", message }),
52
+ failWith: (params, ...message) => ({
53
+ kind: "fail",
54
+ message,
55
+ params,
56
+ }),
57
+ when: (cond, then, elseStmts) => ({ kind: "if", cond, then, else: elseStmts }),
58
+ };
59
+ //# sourceMappingURL=lowering.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lowering.js","sourceRoot":"","sources":["../src/lowering.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,uEAAuE;AACvE,2EAA2E;AAC3E,0FAA0F;AAC1F,6DAA6D;AAC7D,EAAE;AACF,8DAA8D;AAC9D,EAAE;AACF,6EAA6E;AAC7E,wEAAwE;AACxE,uEAAuE;AACvE,0CAA0C;AAC1C,EAAE;AACF,0EAA0E;AAC1E,yEAAyE;AACzE,wEAAwE;AACxE,yEAAyE;AACzE,sDAAsD;AA0VtD,uDAAuD;AACvD,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,QAAQ,EAAE,EAAE,IAAI,EAAE,UAAU,EAAe;IAC3C,QAAQ,EAAE,CAAC,KAAgB,EAAa,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IACrE,MAAM,EAAE,CACN,MAAiB,EACjB,GAAG,KAAwC,EAChC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IACnD,GAAG,EAAE,CAAC,IAAe,EAAa,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAC5D,GAAG,EAAE,CAAC,GAAG,KAA2B,EAAa,EAAE,CAAC,CAAC;QACnD,IAAI,EAAE,OAAO;QACb,EAAE,EAAE,KAAK;QACT,KAAK;KACN,CAAC;IACF,EAAE,EAAE,CAAC,GAAG,KAA2B,EAAa,EAAE,CAAC,CAAC;QAClD,I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