litedbmodel 2.0.0 → 2.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 (146) hide show
  1. package/dist/scp/authoring-sql.d.ts +78 -0
  2. package/dist/scp/authoring-sql.d.ts.map +1 -1
  3. package/dist/scp/authoring-sql.js +110 -2
  4. package/dist/scp/authoring-sql.js.map +1 -1
  5. package/dist/scp/catalog.d.ts +1 -1
  6. package/dist/scp/catalog.d.ts.map +1 -1
  7. package/dist/scp/catalog.js +27 -0
  8. package/dist/scp/catalog.js.map +1 -1
  9. package/dist/scp/codegen.d.ts +46 -82
  10. package/dist/scp/codegen.d.ts.map +1 -1
  11. package/dist/scp/codegen.js +37 -80
  12. package/dist/scp/codegen.js.map +1 -1
  13. package/dist/scp/find-filter-guard.d.ts +68 -0
  14. package/dist/scp/find-filter-guard.d.ts.map +1 -0
  15. package/dist/scp/find-filter-guard.js +88 -0
  16. package/dist/scp/find-filter-guard.js.map +1 -0
  17. package/dist/scp/fragment/assemble.d.ts +61 -0
  18. package/dist/scp/fragment/assemble.d.ts.map +1 -0
  19. package/dist/scp/fragment/assemble.js +148 -0
  20. package/dist/scp/fragment/assemble.js.map +1 -0
  21. package/dist/scp/fragment/compile-pg.d.ts +107 -0
  22. package/dist/scp/fragment/compile-pg.d.ts.map +1 -0
  23. package/dist/scp/fragment/compile-pg.js +142 -0
  24. package/dist/scp/fragment/compile-pg.js.map +1 -0
  25. package/dist/scp/fragment/index.d.ts +16 -0
  26. package/dist/scp/fragment/index.d.ts.map +1 -0
  27. package/dist/scp/fragment/index.js +34 -0
  28. package/dist/scp/fragment/index.js.map +1 -0
  29. package/dist/scp/fragment/model.d.ts +119 -0
  30. package/dist/scp/fragment/model.d.ts.map +1 -0
  31. package/dist/scp/fragment/model.js +66 -0
  32. package/dist/scp/fragment/model.js.map +1 -0
  33. package/dist/scp/fragment/pg-array-type.d.ts +13 -0
  34. package/dist/scp/fragment/pg-array-type.d.ts.map +1 -0
  35. package/dist/scp/fragment/pg-array-type.js +34 -0
  36. package/dist/scp/fragment/pg-array-type.js.map +1 -0
  37. package/dist/scp/guard.d.ts +2 -6
  38. package/dist/scp/guard.d.ts.map +1 -1
  39. package/dist/scp/guard.js +19 -22
  40. package/dist/scp/guard.js.map +1 -1
  41. package/dist/scp/index.cjs +11284 -3826
  42. package/dist/scp/index.d.ts +38 -23
  43. package/dist/scp/index.d.ts.map +1 -1
  44. package/dist/scp/index.js +119 -45
  45. package/dist/scp/index.js.map +1 -1
  46. package/dist/scp/index.mjs +4231 -1412
  47. package/dist/scp/makesql/authoring-compile.d.ts +90 -0
  48. package/dist/scp/makesql/authoring-compile.d.ts.map +1 -0
  49. package/dist/scp/makesql/authoring-compile.js +494 -0
  50. package/dist/scp/makesql/authoring-compile.js.map +1 -0
  51. package/dist/scp/makesql/compile-crud.d.ts +133 -0
  52. package/dist/scp/makesql/compile-crud.d.ts.map +1 -0
  53. package/dist/scp/makesql/compile-crud.js +288 -0
  54. package/dist/scp/makesql/compile-crud.js.map +1 -0
  55. package/dist/scp/makesql/compile-relation.d.ts +157 -0
  56. package/dist/scp/makesql/compile-relation.d.ts.map +1 -0
  57. package/dist/scp/makesql/compile-relation.js +425 -0
  58. package/dist/scp/makesql/compile-relation.js.map +1 -0
  59. package/dist/scp/makesql/compile-select.d.ts +45 -0
  60. package/dist/scp/makesql/compile-select.d.ts.map +1 -0
  61. package/dist/scp/makesql/compile-select.js +58 -0
  62. package/dist/scp/makesql/compile-select.js.map +1 -0
  63. package/dist/scp/makesql/compile.d.ts +63 -0
  64. package/dist/scp/makesql/compile.d.ts.map +1 -0
  65. package/dist/scp/makesql/compile.js +99 -0
  66. package/dist/scp/makesql/compile.js.map +1 -0
  67. package/dist/scp/makesql/handler.d.ts +58 -0
  68. package/dist/scp/makesql/handler.d.ts.map +1 -0
  69. package/dist/scp/makesql/handler.js +113 -0
  70. package/dist/scp/makesql/handler.js.map +1 -0
  71. package/dist/scp/makesql/index.d.ts +33 -0
  72. package/dist/scp/makesql/index.d.ts.map +1 -0
  73. package/dist/scp/makesql/index.js +114 -0
  74. package/dist/scp/makesql/index.js.map +1 -0
  75. package/dist/scp/makesql/ir.d.ts +42 -0
  76. package/dist/scp/makesql/ir.d.ts.map +1 -0
  77. package/dist/scp/makesql/ir.js +66 -0
  78. package/dist/scp/makesql/ir.js.map +1 -0
  79. package/dist/scp/makesql/json-array.d.ts +84 -0
  80. package/dist/scp/makesql/json-array.d.ts.map +1 -0
  81. package/dist/scp/makesql/json-array.js +118 -0
  82. package/dist/scp/makesql/json-array.js.map +1 -0
  83. package/dist/scp/makesql/json-batch.d.ts +102 -0
  84. package/dist/scp/makesql/json-batch.d.ts.map +1 -0
  85. package/dist/scp/makesql/json-batch.js +269 -0
  86. package/dist/scp/makesql/json-batch.js.map +1 -0
  87. package/dist/scp/makesql/makesql.d.ts +99 -0
  88. package/dist/scp/makesql/makesql.d.ts.map +1 -0
  89. package/dist/scp/makesql/makesql.js +122 -0
  90. package/dist/scp/makesql/makesql.js.map +1 -0
  91. package/dist/scp/makesql/pool-executor.d.ts +47 -0
  92. package/dist/scp/makesql/pool-executor.d.ts.map +1 -0
  93. package/dist/scp/makesql/pool-executor.js +50 -0
  94. package/dist/scp/makesql/pool-executor.js.map +1 -0
  95. package/dist/scp/makesql/static-bundle.d.ts +185 -0
  96. package/dist/scp/makesql/static-bundle.d.ts.map +1 -0
  97. package/dist/scp/makesql/static-bundle.js +1024 -0
  98. package/dist/scp/makesql/static-bundle.js.map +1 -0
  99. package/dist/scp/makesql/tx.d.ts +216 -0
  100. package/dist/scp/makesql/tx.d.ts.map +1 -0
  101. package/dist/scp/makesql/tx.js +743 -0
  102. package/dist/scp/makesql/tx.js.map +1 -0
  103. package/dist/scp/relation.d.ts +86 -74
  104. package/dist/scp/relation.d.ts.map +1 -1
  105. package/dist/scp/relation.js +186 -120
  106. package/dist/scp/relation.js.map +1 -1
  107. package/dist/scp/runtime.d.ts +146 -210
  108. package/dist/scp/runtime.d.ts.map +1 -1
  109. package/dist/scp/runtime.js +228 -512
  110. package/dist/scp/runtime.js.map +1 -1
  111. package/dist/scp/typed-object.d.ts +12 -1
  112. package/dist/scp/typed-object.d.ts.map +1 -1
  113. package/dist/scp/typed-object.js +25 -4
  114. package/dist/scp/typed-object.js.map +1 -1
  115. package/docs/proposal/v0-coverage-matrix.md +157 -0
  116. package/docs/proposal/v2-completeness-plan.md +90 -0
  117. package/docs/proposal/v2-sql-parity-checklist.md +162 -0
  118. package/package.json +3 -3
  119. package/dist/scp/bridge.d.ts +0 -64
  120. package/dist/scp/bridge.d.ts.map +0 -1
  121. package/dist/scp/bridge.js +0 -329
  122. package/dist/scp/bridge.js.map +0 -1
  123. package/dist/scp/compile-dialect.d.ts +0 -39
  124. package/dist/scp/compile-dialect.d.ts.map +0 -1
  125. package/dist/scp/compile-dialect.js +0 -62
  126. package/dist/scp/compile-dialect.js.map +0 -1
  127. package/dist/scp/compile-sqlite.d.ts +0 -114
  128. package/dist/scp/compile-sqlite.d.ts.map +0 -1
  129. package/dist/scp/compile-sqlite.js +0 -149
  130. package/dist/scp/compile-sqlite.js.map +0 -1
  131. package/dist/scp/ir.d.ts +0 -92
  132. package/dist/scp/ir.d.ts.map +0 -1
  133. package/dist/scp/ir.js +0 -28
  134. package/dist/scp/ir.js.map +0 -1
  135. package/dist/scp/render.d.ts +0 -40
  136. package/dist/scp/render.d.ts.map +0 -1
  137. package/dist/scp/render.js +0 -170
  138. package/dist/scp/render.js.map +0 -1
  139. package/dist/scp/write-plan.d.ts +0 -161
  140. package/dist/scp/write-plan.d.ts.map +0 -1
  141. package/dist/scp/write-plan.js +0 -528
  142. package/dist/scp/write-plan.js.map +0 -1
  143. package/dist/scp/write-runtime.d.ts +0 -80
  144. package/dist/scp/write-runtime.d.ts.map +0 -1
  145. package/dist/scp/write-runtime.js +0 -167
  146. package/dist/scp/write-runtime.js.map +0 -1
@@ -24,6 +24,24 @@
24
24
  import { type Recorded } from 'behavior-contracts';
25
25
  /** A recorded `$`-reference (column or value) or a literal value usable in a builder. */
26
26
  type Operand = Recorded | unknown;
27
+ /**
28
+ * The sentinel ref-path heads that mark the ADDITIVE where-primitives (V0 R2/R3) so the live
29
+ * compile (`static-bundle.lowerWhereMember`) can decode them into the EXACT v1 `ConditionObject`
30
+ * and drive the ORIGINAL `DBConditions.compile()` for byte-true text — never a hand-roll. Each is
31
+ * encoded with the closed-set `eq(<sentinel ref>, <value>)` shape (the SAME trick {@link whereIn}
32
+ * uses for IN-lists), so no opcode outside bc's closed set is invented. Structural metadata (the
33
+ * column name, the SQL cast type, the LIKE keyword, the tuple column list, the subquery text)
34
+ * rides as extra STRING segments in the sentinel ref path; the runtime value operands ride as the
35
+ * `eq` RHS and are deferred as value-specs 1:1 with the placeholders in the v1-produced text.
36
+ */
37
+ export declare const BETWEEN_SENTINEL = "@between";
38
+ export declare const LIKE_SENTINEL = "@like";
39
+ export declare const CAST_SENTINEL = "@cast";
40
+ export declare const DYNAMIC_SENTINEL = "@dynamic";
41
+ export declare const IMMEDIATE_SENTINEL = "@immediate";
42
+ export declare const TUPLE_SENTINEL = "@tuple";
43
+ export declare const SUBQUERY_SENTINEL = "@subquery";
44
+ export declare const EXISTS_SENTINEL = "@exists";
27
45
  /** `col = value` — equality fragment (`{eq:[colRef, value]}`). */
28
46
  export declare function whereEq(col: Recorded, value: Operand): Recorded;
29
47
  /** `col <> value` — inequality fragment. */
@@ -52,5 +70,65 @@ export declare function whereIn(col: Recorded, value: Operand): Recorded;
52
70
  * treats `name` as the physical column (a membership fragment, not an equality).
53
71
  */
54
72
  export declare function inColumn($: Recorded, name: string): Recorded;
73
+ /**
74
+ * `col BETWEEN ? AND ?` (V0 R3). Encoded `eq($[@between][col], [lo, hi])`; the live compile builds
75
+ * the v1 custom-op `ConditionObject` `{'<col> BETWEEN ? AND ?': [lo, hi]}` and defers both bounds.
76
+ * `lo`/`hi` are recorded refs or literals.
77
+ */
78
+ export declare function whereBetween($: Recorded, col: string, lo: Operand, hi: Operand): Recorded;
79
+ /**
80
+ * `col LIKE ?` (V0 R3). Encoded `eq($[@like][col], pattern)` → v1 `{'<col> LIKE ?': pattern}`.
81
+ * The pattern is a recorded ref or literal.
82
+ */
83
+ export declare function whereLike($: Recorded, col: string, pattern: Operand): Recorded;
84
+ /**
85
+ * `col ILIKE ?` (V0 R3, PG case-insensitive; on MySQL/SQLite v1 emits the raw `ILIKE` keyword —
86
+ * this reproduces v1 verbatim, not a portability rewrite). Encoded `eq($[@like][col][ILIKE], p)`.
87
+ */
88
+ export declare function whereILike($: Recorded, col: string, pattern: Operand): Recorded;
89
+ /**
90
+ * `col <op> ?::type` (V0 R3, dialect-gated cast — `dbCast`). Encoded
91
+ * `eq($[@cast][col][type][op], value)`; the live compile drives v1 `dbCast(value, type, op)` so the
92
+ * PG `::type` cast (and the MySQL/SQLite no-cast) is byte-true. `op` defaults to `=`.
93
+ */
94
+ export declare function whereCast($: Recorded, col: string, sqlType: string, value: Operand, op?: string): Recorded;
95
+ /**
96
+ * `col = fn(?)` (V0 R3, `dbDynamic`) — a function-call template with `?` placeholders bound to the
97
+ * value list. Encoded `eq($[@dynamic][col][template], values)`; drives v1 `dbDynamic(template, vals)`.
98
+ * `template` is the raw function SQL (e.g. `to_tsvector('en', ?)`).
99
+ */
100
+ export declare function whereDynamic($: Recorded, col: string, template: string, values: Operand): Recorded;
101
+ /**
102
+ * `col = <sql>` (V0 R3, `dbImmediate` — an inline SQL expression, NO bound param, e.g. `NOW()`).
103
+ * Encoded `eq($[@immediate][col][sql], null)`; drives v1 `dbImmediate(sql)`. No value-spec.
104
+ */
105
+ export declare function whereImmediate($: Recorded, col: string, sql: string): Recorded;
106
+ /**
107
+ * `(a, b, …) IN ((?, ?), …)` (V0 R3, `dbTupleIn` composite membership). Encoded
108
+ * `eq($[@tuple][a][b]…, tuples)` where `tuples` is an array-of-tuples value; drives v1
109
+ * `dbTupleIn(columns, tuples)`. `columns` is the tuple column list.
110
+ */
111
+ export declare function whereTupleIn($: Recorded, columns: readonly string[], tuples: Operand): Recorded;
112
+ /**
113
+ * `lhs IN (SELECT …)` / `lhs NOT IN (SELECT …)` (V0 R2). The subquery is authored as a NESTED
114
+ * makeSQL Fragment carried in the param slot (spec §2 補足): `sub` is a `{ sql, params? }` where
115
+ * `sql` is the inner SELECT text (already dialect-tuned, v1-sourced) and `params` its bound
116
+ * value-specs. Encoded `eq($[@subquery][lhsCol][kw], sub)`; the live compile splices the inner
117
+ * `sql` into the v1 `DBSubquery`-shaped predicate `<lhs> <kw> (<sub.sql>)` and appends `sub.params`.
118
+ */
119
+ export declare function whereInSubquery($: Recorded, lhs: string, sub: {
120
+ sql: string;
121
+ params?: readonly Operand[];
122
+ }, not?: boolean): Recorded;
123
+ /**
124
+ * `EXISTS (SELECT 1 …)` / `NOT EXISTS (…)` (V0 R2). Like {@link whereInSubquery}, the correlated
125
+ * subquery rides as a nested makeSQL Fragment in the param slot: `sub.sql` is the inner
126
+ * `SELECT 1 FROM … WHERE …` (correlation refs already rendered as literal column paths, v1-sourced).
127
+ * Encoded `eq($[@exists][kw], sub)`; the live compile emits `<kw> (<sub.sql>)` + `sub.params`.
128
+ */
129
+ export declare function whereExists($: Recorded, sub: {
130
+ sql: string;
131
+ params?: readonly Operand[];
132
+ }, not?: boolean): Recorded;
55
133
  export {};
56
134
  //# sourceMappingURL=authoring-sql.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"authoring-sql.d.ts","sourceRoot":"","sources":["../../src/scp/authoring-sql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAA0B,KAAK,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAG3E,yFAAyF;AACzF,KAAK,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;AAElC,kEAAkE;AAClE,wBAAgB,OAAO,CAAC,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,GAAG,QAAQ,CAE/D;AAED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QAAQ,CAEV"}
@@ -23,6 +23,7 @@
23
23
  * recorded reference, a literal, or any closed-set builder expression (`coalesce`, `add`, …).
24
24
  */
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.EXISTS_SENTINEL = exports.SUBQUERY_SENTINEL = exports.TUPLE_SENTINEL = exports.IMMEDIATE_SENTINEL = exports.DYNAMIC_SENTINEL = exports.CAST_SENTINEL = exports.LIKE_SENTINEL = exports.BETWEEN_SENTINEL = void 0;
26
27
  exports.whereEq = whereEq;
27
28
  exports.whereNe = whereNe;
28
29
  exports.whereLt = whereLt;
@@ -32,8 +33,42 @@ exports.whereGe = whereGe;
32
33
  exports.whereIsNull = whereIsNull;
33
34
  exports.whereIn = whereIn;
34
35
  exports.inColumn = inColumn;
36
+ exports.whereBetween = whereBetween;
37
+ exports.whereLike = whereLike;
38
+ exports.whereILike = whereILike;
39
+ exports.whereCast = whereCast;
40
+ exports.whereDynamic = whereDynamic;
41
+ exports.whereImmediate = whereImmediate;
42
+ exports.whereTupleIn = whereTupleIn;
43
+ exports.whereInSubquery = whereInSubquery;
44
+ exports.whereExists = whereExists;
35
45
  const behavior_contracts_1 = require("behavior-contracts");
36
- const bridge_1 = require("./bridge");
46
+ const makesql_1 = require("./makesql");
47
+ /**
48
+ * The sentinel ref-path heads that mark the ADDITIVE where-primitives (V0 R2/R3) so the live
49
+ * compile (`static-bundle.lowerWhereMember`) can decode them into the EXACT v1 `ConditionObject`
50
+ * and drive the ORIGINAL `DBConditions.compile()` for byte-true text — never a hand-roll. Each is
51
+ * encoded with the closed-set `eq(<sentinel ref>, <value>)` shape (the SAME trick {@link whereIn}
52
+ * uses for IN-lists), so no opcode outside bc's closed set is invented. Structural metadata (the
53
+ * column name, the SQL cast type, the LIKE keyword, the tuple column list, the subquery text)
54
+ * rides as extra STRING segments in the sentinel ref path; the runtime value operands ride as the
55
+ * `eq` RHS and are deferred as value-specs 1:1 with the placeholders in the v1-produced text.
56
+ */
57
+ exports.BETWEEN_SENTINEL = '@between';
58
+ exports.LIKE_SENTINEL = '@like';
59
+ exports.CAST_SENTINEL = '@cast';
60
+ exports.DYNAMIC_SENTINEL = '@dynamic';
61
+ exports.IMMEDIATE_SENTINEL = '@immediate';
62
+ exports.TUPLE_SENTINEL = '@tuple';
63
+ exports.SUBQUERY_SENTINEL = '@subquery';
64
+ exports.EXISTS_SENTINEL = '@exists';
65
+ /** Build a sentinel column ref: `$[HEAD][seg0][seg1]…` → a recorded ref with that path. */
66
+ function sentinelRef($, head, segs) {
67
+ let node = $[head];
68
+ for (const s of segs)
69
+ node = node[s];
70
+ return node;
71
+ }
37
72
  /** `col = value` — equality fragment (`{eq:[colRef, value]}`). */
38
73
  function whereEq(col, value) {
39
74
  return (0, behavior_contracts_1.eq)(col, value);
@@ -78,6 +113,79 @@ function whereIn(col, value) {
78
113
  * treats `name` as the physical column (a membership fragment, not an equality).
79
114
  */
80
115
  function inColumn($, name) {
81
- return $[bridge_1.IN_SENTINEL][name];
116
+ return $[makesql_1.IN_SENTINEL][name];
117
+ }
118
+ // ── Additive where-primitives (V0 R2/R3) — all v1-sourced at compile, live-reachable ──────────
119
+ /**
120
+ * `col BETWEEN ? AND ?` (V0 R3). Encoded `eq($[@between][col], [lo, hi])`; the live compile builds
121
+ * the v1 custom-op `ConditionObject` `{'<col> BETWEEN ? AND ?': [lo, hi]}` and defers both bounds.
122
+ * `lo`/`hi` are recorded refs or literals.
123
+ */
124
+ function whereBetween($, col, lo, hi) {
125
+ return (0, behavior_contracts_1.eq)(sentinelRef($, exports.BETWEEN_SENTINEL, [col]), [lo, hi]);
126
+ }
127
+ /**
128
+ * `col LIKE ?` (V0 R3). Encoded `eq($[@like][col], pattern)` → v1 `{'<col> LIKE ?': pattern}`.
129
+ * The pattern is a recorded ref or literal.
130
+ */
131
+ function whereLike($, col, pattern) {
132
+ return (0, behavior_contracts_1.eq)(sentinelRef($, exports.LIKE_SENTINEL, [col, 'LIKE']), pattern);
133
+ }
134
+ /**
135
+ * `col ILIKE ?` (V0 R3, PG case-insensitive; on MySQL/SQLite v1 emits the raw `ILIKE` keyword —
136
+ * this reproduces v1 verbatim, not a portability rewrite). Encoded `eq($[@like][col][ILIKE], p)`.
137
+ */
138
+ function whereILike($, col, pattern) {
139
+ return (0, behavior_contracts_1.eq)(sentinelRef($, exports.LIKE_SENTINEL, [col, 'ILIKE']), pattern);
140
+ }
141
+ /**
142
+ * `col <op> ?::type` (V0 R3, dialect-gated cast — `dbCast`). Encoded
143
+ * `eq($[@cast][col][type][op], value)`; the live compile drives v1 `dbCast(value, type, op)` so the
144
+ * PG `::type` cast (and the MySQL/SQLite no-cast) is byte-true. `op` defaults to `=`.
145
+ */
146
+ function whereCast($, col, sqlType, value, op = '=') {
147
+ return (0, behavior_contracts_1.eq)(sentinelRef($, exports.CAST_SENTINEL, [col, sqlType, op]), value);
148
+ }
149
+ /**
150
+ * `col = fn(?)` (V0 R3, `dbDynamic`) — a function-call template with `?` placeholders bound to the
151
+ * value list. Encoded `eq($[@dynamic][col][template], values)`; drives v1 `dbDynamic(template, vals)`.
152
+ * `template` is the raw function SQL (e.g. `to_tsvector('en', ?)`).
153
+ */
154
+ function whereDynamic($, col, template, values) {
155
+ return (0, behavior_contracts_1.eq)(sentinelRef($, exports.DYNAMIC_SENTINEL, [col, template]), values);
156
+ }
157
+ /**
158
+ * `col = <sql>` (V0 R3, `dbImmediate` — an inline SQL expression, NO bound param, e.g. `NOW()`).
159
+ * Encoded `eq($[@immediate][col][sql], null)`; drives v1 `dbImmediate(sql)`. No value-spec.
160
+ */
161
+ function whereImmediate($, col, sql) {
162
+ return (0, behavior_contracts_1.eq)(sentinelRef($, exports.IMMEDIATE_SENTINEL, [col, sql]), null);
163
+ }
164
+ /**
165
+ * `(a, b, …) IN ((?, ?), …)` (V0 R3, `dbTupleIn` composite membership). Encoded
166
+ * `eq($[@tuple][a][b]…, tuples)` where `tuples` is an array-of-tuples value; drives v1
167
+ * `dbTupleIn(columns, tuples)`. `columns` is the tuple column list.
168
+ */
169
+ function whereTupleIn($, columns, tuples) {
170
+ return (0, behavior_contracts_1.eq)(sentinelRef($, exports.TUPLE_SENTINEL, columns), tuples);
171
+ }
172
+ /**
173
+ * `lhs IN (SELECT …)` / `lhs NOT IN (SELECT …)` (V0 R2). The subquery is authored as a NESTED
174
+ * makeSQL Fragment carried in the param slot (spec §2 補足): `sub` is a `{ sql, params? }` where
175
+ * `sql` is the inner SELECT text (already dialect-tuned, v1-sourced) and `params` its bound
176
+ * value-specs. Encoded `eq($[@subquery][lhsCol][kw], sub)`; the live compile splices the inner
177
+ * `sql` into the v1 `DBSubquery`-shaped predicate `<lhs> <kw> (<sub.sql>)` and appends `sub.params`.
178
+ */
179
+ function whereInSubquery($, lhs, sub, not = false) {
180
+ return (0, behavior_contracts_1.eq)(sentinelRef($, exports.SUBQUERY_SENTINEL, [lhs, not ? 'NOT IN' : 'IN']), sub);
181
+ }
182
+ /**
183
+ * `EXISTS (SELECT 1 …)` / `NOT EXISTS (…)` (V0 R2). Like {@link whereInSubquery}, the correlated
184
+ * subquery rides as a nested makeSQL Fragment in the param slot: `sub.sql` is the inner
185
+ * `SELECT 1 FROM … WHERE …` (correlation refs already rendered as literal column paths, v1-sourced).
186
+ * Encoded `eq($[@exists][kw], sub)`; the live compile emits `<kw> (<sub.sql>)` + `sub.params`.
187
+ */
188
+ function whereExists($, sub, not = false) {
189
+ return (0, behavior_contracts_1.eq)(sentinelRef($, exports.EXISTS_SENTINEL, [not ? 'NOT EXISTS' : 'EXISTS']), sub);
82
190
  }
83
191
  //# sourceMappingURL=authoring-sql.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"authoring-sql.js","sourceRoot":"","sources":["../../src/scp/authoring-sql.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;AASH,0BAEC;AAGD,0BAEC;AAGD,0BAEC;AAGD,0BAEC;AAGD,0BAEC;AAGD,0BAEC;AAGD,kCAEC;AASD,0BAEC;AAOD,4BAEC;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ED;;;;;;GAMG;AACH,SAAgB,eAAe,CAC7B,CAAW,EACX,GAAW,EACX,GAAiD,EACjD,GAAG,GAAG,KAAK;IAEX,OAAO,IAAA,uBAAE,EAAC,WAAW,CAAC,CAAC,EAAE,yBAAiB,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,CAAwB,CAAC;AACzG,CAAC;AAED;;;;;GAKG;AACH,SAAgB,WAAW,CACzB,CAAW,EACX,GAAiD,EACjD,GAAG,GAAG,KAAK;IAEX,OAAO,IAAA,uBAAE,EAAC,WAAW,CAAC,CAAC,EAAE,uBAAe,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAwB,CAAC;AAC1G,CAAC"}
@@ -40,7 +40,7 @@ import { type Catalog, type CatalogEntry, type Component } from 'behavior-contra
40
40
  * fragment-tree component (`Fragment`), and the multi-statement transaction envelope
41
41
  * (`Tx`).
42
42
  */
43
- export type CatalogName = 'Select' | 'Insert' | 'Update' | 'Delete' | 'Fragment' | 'Tx';
43
+ export type CatalogName = 'Select' | 'Count' | 'Insert' | 'Update' | 'Delete' | 'Fragment' | 'Tx';
44
44
  /**
45
45
  * litedbmodel's specific-component catalog (spec §11 item 1) — the behavior-contracts
46
46
  * `Catalog`-typed source of truth. Each entry declares the Port schema of one SQL
@@ -1 +1 @@
1
- {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/scp/catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAA0B,KAAK,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,SAAS,EAAmB,MAAM,oBAAoB,CAAC;AAE9H;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GACnB,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,QAA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C;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,WAAW,EAKrD,CAAC;AAIF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAGhD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,GAAG,IAAI,CA4BhF;AAGD,mFAAmF;AACnF,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,SAAS,CAAC;AAEjD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,SAAS,GAAG,cAAc,CAEzE"}
@@ -60,6 +60,21 @@ const SELECT_PORTS = {
60
60
  limit: P('expr'),
61
61
  offset: P('expr'),
62
62
  group: P('string'),
63
+ // Additive read-tail/head ports (V0 R3/R4/R5/R6). SQL is v1-sourced from the matching
64
+ // `SelectDesc` fields via `compileSelect` (`_buildSelectSQL`), wired in `compileSelectNode`:
65
+ // - `forUpdate` (R3): a literal `'true'` string toggles the ` FOR UPDATE` tail.
66
+ // - `join`/`joinParams` (R5): a literal JOIN clause text (`JOIN t ON …`) + its bound
67
+ // value-specs (`expr[]`), spliced after `FROM <t>` (v1 `_buildSelectSQL` JOIN position).
68
+ // - `cte`/`cteParams` (R4): a WITH-CTE `{name, sql}` literal + its bound value-specs,
69
+ // prefixed as `WITH <name> AS (<sql>) ` (v1 WITH-wrap). `cteParams` bind FIRST (v1 param
70
+ // order: CTE → JOIN → WHERE).
71
+ // - `append` (R6): a raw trailing clause text (e.g. `HAVING …`) appended verbatim.
72
+ forUpdate: P('string'),
73
+ join: P('string'),
74
+ joinParams: P('expr[]'),
75
+ cte: P('map'),
76
+ cteParams: P('expr[]'),
77
+ append: P('string'),
63
78
  };
64
79
  /**
65
80
  * The shared write-port surface for `Insert`/`Update`/`Delete`: `table` always;
@@ -74,6 +89,12 @@ const WRITE_PORTS = {
74
89
  returning: P('string'),
75
90
  onConflict: P('string'),
76
91
  onConflictAction: P('string'),
92
+ // PRIMARY KEY descriptor for the MySQL RETURNING emulation (INSERT…RETURNING): `pk` is a
93
+ // comma-separated PK column list, `autoInc` names the single AUTO_INCREMENT column (absent for a
94
+ // client-supplied PK). Consumed by compileWriteNode → mysqlPkHint so the emulation re-selects by
95
+ // the REAL PK. Inert on PG/SQLite (native RETURNING).
96
+ pk: P('string'),
97
+ autoInc: P('string'),
77
98
  };
78
99
  const entry = (name, inputPorts, shape, portableToIR) => ({
79
100
  name,
@@ -96,6 +117,11 @@ exports.LITEDBMODEL_CATALOG = {
96
117
  // Read: `items` (a Select root yields a row list; per-row collapse to `item` is the
97
118
  // consumer's cardinality concern, mirrored from graphddb Query's `cardinality` port).
98
119
  Select: entry('Select', { ...SELECT_PORTS, cardinality: P('string') }, 'items', true),
120
+ // COUNT(*) aggregate read (v1 `DBModel._count`): `SELECT COUNT(*) as count FROM t[ WHERE …]`.
121
+ // Only `table` (required) + the optional `where` fragment tree — v1's count carries no
122
+ // projection/order/limit/offset (it counts the filtered rows). Output is a one-row `[{count}]`
123
+ // list (the `items` shape, like every read); the consumer reads `count` — v1's `parseInt(count)`.
124
+ Count: entry('Count', { table: P('string', true), where: P('fragment') }, 'items', true),
99
125
  // Writes yield the RETURNING row list (`items`); a single-row write collapses at the
100
126
  // consumer boundary, same as reads.
101
127
  Insert: entry('Insert', WRITE_PORTS, 'items', true),
@@ -119,6 +145,7 @@ function catalogEntry(name) {
119
145
  /** The catalog names litedbmodel declares (the C2 per-DSL surface). */
120
146
  exports.CATALOG_NAMES = [
121
147
  'Select',
148
+ 'Count',
122
149
  'Insert',
123
150
  'Update',
124
151
  'Delete',
@@ -1 +1 @@
1
- {"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../src/scp/catalog.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;;;AAgGH,oCAEC;AAiDD,8DA4BC;AAYD,oDAEC;AA3LD,2DAA8H;AAgB9H,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GAKG;AACH,SAAgB,oBAAoB,CAAC,SAAoB;IACvD,OAAO,IAAA,2CAAsB,EAAC,SAAS,EAAE,2BAAmB,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;AACpG,CAAC"}
@@ -1,74 +1,57 @@
1
1
  /**
2
- * litedbmodel v2 SCP — mode-3 codegen (WS7f, #35; spec §9 exec-mode 3 / §10 / §11).
2
+ * litedbmodel v2 SCP — mode-3 codegen (WS7f, #35; spec §9 exec-mode 3 / §10 / §11; makeSQL flip,
3
+ * epic #43/#45 Phase B).
3
4
  *
4
- * The static-codegen execution mode ("Codegen・静的(全言語)— IR → 各言語ソース生成
5
- * runtime≈0, 入力は可搬IRのみ, bc#13 共有 generator に SQL catalog を供給" — spec §9). It
6
- * takes a §8 {@link SqlBundle} (already Backend-Compiled TS-side, WS1↔WS3) and, per target
7
- * language, emits:
5
+ * The static-codegen execution mode ("Codegen・静的(全言語)— IR → 各言語ソース生成 runtime≈0,
6
+ * 入力は可搬IRのみ, bc#13 共有 generator に SQL catalog を供給" — spec §9). It takes a §8 STATIC
7
+ * makeSQL {@link SqlBundle} and, per target language, emits:
8
8
  *
9
- * 1. **Behavior module** — bc's SHARED generator (`generateModule`, bc#13) run over the
10
- * bundle's SURROGATE component wrapped as a portable {@link ComponentGraphIR}. The generator
11
- * bakes that IR as a language-native LITERAL (no runtime JSON parse) and emits a `bind(handlers)`
12
- * accessor that delegates to the EXISTING runtime-core `runBehavior`. litedbmodel writes NO
13
- * execution logic here — codegen is upstream-owned (bc), we only SUPPLY the input.
14
- * 2. **SQL catalog companion** — a pure-JSON sidecar carrying the litedbmodel-specific bundle
15
- * fields that are OUTSIDE bc's portable-IR vocabulary (`operations` / `dialect` /
16
- * `optionalHeads` / `relations` / `transaction`). This is the "SQL catalog supplied to the
17
- * shared generator" (§9): a codegen consumer's thin SQL-handler layer reads it to render →
18
- * execute, exactly as the mode-2 thin-runtime handler does. It is byte-identical to the bundle
19
- * minus the (now baked-as-literal) `component`/`irVersion`/`exprVersion`.
9
+ * 1. **Behavior module** — bc's SHARED generator (`generateModule`, bc#13) run over the bundle's
10
+ * portable IR (a read bundle's surrogate `ComponentGraphIR`, or the `makeSQL` component IR for
11
+ * a write), baked as a language-native LITERAL with a `bind(handlers)` accessor delegating to
12
+ * `runBehavior`. litedbmodel writes NO execution logic here — codegen is upstream-owned (bc).
13
+ * 2. **SQL catalog companion** — the pure-JSON STATIC makeSQL catalog (per-node statement
14
+ * templates / relations / transaction). A codegen consumer's thin SQL layer reads it to
15
+ * evaluate skip + value-specs → assemble → render → execute (identically to the mode-2 runtime).
20
16
  *
21
- * ## Why this is byte-identical to the thin-runtime (mode-2), by construction
17
+ * ## Byte-identical to the thin-runtime (mode-2), by construction
22
18
  *
23
- * The mode-2 thin-runtime ({@link executeBundle}) computes
24
- * `runBehavior({components:[bundle.component]}, buildHandlers(db, operations, dialect),
25
- * normalizeInput(...), name)`. The generated module bakes `IR === bundle.component` (proven by
26
- * the FNV-1a fingerprint the generator embeds and re-checks at load) and its `bind(handlers)`
27
- * calls the SAME `runBehavior(IR, handlers, input, name)`. So when a codegen runtime pairs the
28
- * generated `bind` with the SAME {@link buildHandlers} + {@link normalizeInput} (from the SQL
29
- * catalog companion), it drives the identical core over the identical IR and handlers — the SQL
30
- * text (all dialects) and the results are identical, NOT approximately equal. The TS leg PROVES
31
- * this by executing the generated module and asserting exact equality vs `executeBundle` AND vs
32
- * the frozen conformance vector (see `codegenExecuteBundleForTest`).
33
- *
34
- * ## Language support (bc#13 capability — the honest scope boundary)
35
- *
36
- * bc's shared generator registers emitters for FIVE languages
37
- * ({@link CODEGEN_LANGUAGES}); Go IS among them (bc#13 SP2 `emit-go.ts`). So litedbmodel mode-3
38
- * codegen covers all five — TS/Python/Go/Rust/PHP. If a future litedbmodel construct needed an
39
- * emitter bc does not provide, the honest move is to ESCALATE to bc (bc#22 pattern), never to
40
- * fork a parallel litedbmodel-local generator (that would defeat the "codegen は上流所有" design).
19
+ * The companion IS the bundle, so a codegen runtime that evaluates it drives the IDENTICAL
20
+ * static-makeSQL render/execute path {@link executeBundle} uses — SQL text (all dialects) and
21
+ * results are identical, not approximately equal. The TS leg PROVES this by executing via the
22
+ * artifact and asserting exact equality vs {@link executeBundle} (see {@link codegenExecuteBundleForTest}).
41
23
  */
42
24
  import { type ComponentGraphIR, type GeneratedModule, type Scope, type Value } from 'behavior-contracts';
43
25
  import type { SqlBundle, SqliteDb } from './runtime';
44
- import { type DialectName } from './dialect';
45
- import type { CompiledOperation } from './ir';
26
+ import type { DialectName } from './dialect';
46
27
  import type { RelationOp } from './relation';
47
- import type { TransactionPlan } from './write-plan';
28
+ import type { ReadGraph } from './makesql/static-bundle';
29
+ import type { TransactionPlan } from './makesql/tx';
48
30
  /**
49
31
  * The languages litedbmodel mode-3 codegen supports — exactly the set bc's shared generator
50
- * registers (bc#13 SP1 typescript/python + SP2 go/rust/php). This is a FIXED capability the
51
- * generator advertises via `registeredLanguages()`; {@link assertLanguageSupported} verifies the
52
- * requested language against the LIVE registry so a bc capability change is caught loudly rather
53
- * than silently drifting from this constant.
32
+ * registers (bc#13 SP1 typescript/python + SP2 go/rust/php). {@link assertLanguageSupported}
33
+ * verifies against the LIVE registry so a bc capability drift is caught loudly.
54
34
  */
55
35
  export declare const CODEGEN_LANGUAGES: readonly ["typescript", "python", "go", "rust", "php"];
56
36
  export type CodegenLanguage = (typeof CODEGEN_LANGUAGES)[number];
57
37
  /**
58
- * The SQL catalog companion (spec §9 — the "SQL catalog supplied to the shared generator"): the
59
- * litedbmodel-specific §8 bundle fields that live OUTSIDE bc's portable-IR vocabulary and so are
60
- * NOT baked into the generated behavior module. A codegen consumer's thin SQL-handler layer reads
61
- * this sidecar to render → bind → execute (identically to the mode-2 handler). Pure JSON —
62
- * round-trips losslessly (proven by the codegen conformance leg).
38
+ * The SQL catalog companion (spec §9): the STATIC makeSQL bundle fields the codegen consumer's
39
+ * thin SQL layer reads to evaluate + render + execute. Pure JSON — round-trips losslessly.
63
40
  */
64
41
  export interface SqlCatalogCompanion {
65
- /** Backend-Compiled SQL IR per catalog node id (§8) — `sql` + fragment tree + closed-set params. */
66
- readonly operations: Record<string, CompiledOperation>;
67
42
  /** Target SQL dialect (`sqlite`/`postgres`/`mysql`) — compiled once, TS-side (spec §10). */
68
43
  readonly dialect: DialectName;
44
+ /** READ bundles: the portable read graph (surrogate IR + per-node makeSQL statements). */
45
+ readonly readGraph?: ReadGraph;
46
+ /** WRITE bundles: the single base-write makeSQL statement template. */
47
+ readonly statement?: {
48
+ readonly sql: string;
49
+ readonly params: readonly unknown[];
50
+ readonly skip?: unknown;
51
+ };
69
52
  /** Input heads normalized to present-as-null (absent-key SKIP) — mirrors the bundle. */
70
53
  readonly optionalHeads: readonly string[];
71
- /** Pre-compiled read-relation batch ops (spec §5/§8), keyed by relation name. */
54
+ /** Pre-compiled STATIC read-relation batch ops (spec §5/§8), keyed by relation name. */
72
55
  readonly relations: Record<string, RelationOp>;
73
56
  /** Derived gate-first write-time-relations transaction plan (spec §6/§8), for a Command bundle. */
74
57
  readonly transaction?: TransactionPlan;
@@ -79,53 +62,34 @@ export interface CodegenArtifact {
79
62
  readonly language: CodegenLanguage;
80
63
  /** The generated behavior module (bc's shared generator output — IR baked as a native literal). */
81
64
  readonly module: GeneratedModule;
82
- /** The SQL catalog companion sidecar (the litedbmodel-specific execution catalog). */
65
+ /** The SQL catalog companion sidecar (the STATIC makeSQL execution catalog). */
83
66
  readonly companion: SqlCatalogCompanion;
84
- /**
85
- * The portable IR that WAS baked into {@link module} (the surrogate component + envelope). Kept
86
- * on the artifact so the in-process TS equivalence check drives the IDENTICAL IR the emitted
87
- * source embeds — the generator's fingerprint (checked at the emitted module's load) proves the
88
- * baked literal equals this object.
89
- */
67
+ /** The portable IR baked into {@link module}. */
90
68
  readonly ir: ComponentGraphIR;
69
+ /** The originating bundle (so the equivalence leg re-executes the SAME static bundle). */
70
+ readonly bundle: SqlBundle;
91
71
  }
92
72
  /**
93
- * The portable {@link ComponentGraphIR} view of a §8 bundle: the surrogate component (wiring /
94
- * plan / output / `__scope` ports only — every SQL-structural port already collapsed to portable
95
- * Expression IR TS-side) wrapped with the bundle's IR envelope. This is EXACTLY the IR
96
- * {@link executeBundle} feeds `runBehavior`, so baking it is what makes codegen equivalent.
73
+ * The portable {@link ComponentGraphIR} view of a §8 bundle: a read bundle's surrogate IR (each
74
+ * SQL node → a `makeSQL` node), or the single `makeSQL` component IR for a write. Baking THIS is
75
+ * what makes the generated module a genuine bc artifact; the static SQL catalog rides the companion.
97
76
  */
98
77
  export declare function bundleToPortableIR(bundle: SqlBundle): ComponentGraphIR;
99
78
  /**
100
- * Assert the requested language is one bc's shared generator can actually emit — checked against
101
- * the LIVE generator registry, not just the {@link CODEGEN_LANGUAGES} constant, so a bc capability
102
- * drift (an emitter removed/renamed upstream) fails LOUDLY here instead of surfacing as a broken
103
- * generated module. `generateModule` itself also fail-closes on an unknown language; this is the
104
- * earlier, litedbmodel-scoped guard with the honest "bc supports X" message.
79
+ * Assert the requested language is one bc's shared generator can emit — checked against the LIVE
80
+ * registry, not just the {@link CODEGEN_LANGUAGES} constant, so a bc capability drift fails LOUDLY.
105
81
  */
106
82
  export declare function assertLanguageSupported(language: string, registered: readonly string[]): asserts language is CodegenLanguage;
107
83
  /**
108
84
  * Generate the mode-3 codegen artifact for ONE §8 bundle in ONE target language: bc's SHARED
109
- * generator bakes the surrogate IR literal + emits `bind(handlers)`, and we attach the SQL catalog
85
+ * generator bakes the IR literal + emits `bind(handlers)`, and we attach the STATIC SQL catalog
110
86
  * companion. litedbmodel supplies the input (IR + catalog); bc owns the emitter.
111
- *
112
- * @param registeredLanguages the live `registeredLanguages()` from bc (injected so the guard sees
113
- * the actual generator capability; the caller passes `bc.registeredLanguages()`).
114
- * @param runtimeImport optional runtime-core import specifier override (test/vendored layouts);
115
- * forwarded verbatim to the generator so the generated code stays deterministic.
116
87
  */
117
88
  export declare function generateCodegenArtifact(bundle: SqlBundle, language: string, registeredLanguages: readonly string[], runtimeImport?: string): CodegenArtifact;
118
89
  /**
119
- * The TS codegen EXECUTION path used to PROVE byte-identity: reconstruct the exact call the
120
- * generated TS module's `bind(handlers)` makes — `runBehavior(IR, handlers, normalizedInput,
121
- * name)` — where `IR` is the baked portable IR and `handlers` are the SAME SQL handlers the SQL
122
- * catalog companion drives ({@link buildHandlers}). Executing this and comparing to
123
- * {@link executeBundle} is a REAL byte-identity check on the codegen path (the generated TS module
124
- * is separately IMPORTED and run in the conformance leg to prove the emitted source itself agrees).
125
- *
126
- * This mirrors {@link executeBundle} field-for-field, but drives the components/handlers via the
127
- * codegen ARTIFACT (baked IR + companion) rather than the raw bundle — so a divergence between the
128
- * codegen artifact and the bundle would surface as a mismatch.
90
+ * The TS codegen EXECUTION path used to PROVE byte-identity: a codegen runtime reads the SQL
91
+ * catalog companion (the STATIC makeSQL bundle) and evaluates skip + value-specs → assemble →
92
+ * render → execute — which is EXACTLY {@link executeBundle} over the SAME bundle.
129
93
  */
130
94
  export declare function codegenExecuteBundleForTest(artifact: CodegenArtifact, input: Scope, db: SqliteDb): Value;
131
95
  //# sourceMappingURL=codegen.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../src/scp/codegen.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,EAAkB,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAE,KAAK,KAAK,EAAE,KAAK,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACzH,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAGrD,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,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