litedbmodel 2.1.0 → 2.2.0

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 (186) hide show
  1. package/README.md +7 -0
  2. package/dist/DBConditions.d.ts.map +1 -1
  3. package/dist/DBConditions.js +16 -1
  4. package/dist/DBConditions.js.map +1 -1
  5. package/dist/DBHandler.d.ts.map +1 -1
  6. package/dist/DBHandler.js +6 -0
  7. package/dist/DBHandler.js.map +1 -1
  8. package/dist/DBModel.d.ts +84 -2
  9. package/dist/DBModel.d.ts.map +1 -1
  10. package/dist/DBModel.js +312 -29
  11. package/dist/DBModel.js.map +1 -1
  12. package/dist/decorators.d.ts +52 -0
  13. package/dist/decorators.d.ts.map +1 -1
  14. package/dist/decorators.js +83 -0
  15. package/dist/decorators.js.map +1 -1
  16. package/dist/drivers/mysql.d.ts.map +1 -1
  17. package/dist/drivers/mysql.js +6 -2
  18. package/dist/drivers/mysql.js.map +1 -1
  19. package/dist/drivers/postgres.d.ts.map +1 -1
  20. package/dist/drivers/postgres.js +6 -2
  21. package/dist/drivers/postgres.js.map +1 -1
  22. package/dist/drivers/sqlite.d.ts.map +1 -1
  23. package/dist/drivers/sqlite.js +12 -2
  24. package/dist/drivers/sqlite.js.map +1 -1
  25. package/dist/index.cjs +10741 -0
  26. package/dist/index.d.cts +1 -0
  27. package/dist/scp/coltype.d.ts +26 -1
  28. package/dist/scp/coltype.d.ts.map +1 -1
  29. package/dist/scp/coltype.js +82 -15
  30. package/dist/scp/coltype.js.map +1 -1
  31. package/dist/scp/connection-routing.d.ts +312 -0
  32. package/dist/scp/connection-routing.d.ts.map +1 -0
  33. package/dist/scp/connection-routing.js +394 -0
  34. package/dist/scp/connection-routing.js.map +1 -0
  35. package/dist/scp/dbmodel-runtime.d.ts +101 -0
  36. package/dist/scp/dbmodel-runtime.d.ts.map +1 -0
  37. package/dist/scp/dbmodel-runtime.js +174 -0
  38. package/dist/scp/dbmodel-runtime.js.map +1 -0
  39. package/dist/scp/decorator-adapter.d.ts +196 -0
  40. package/dist/scp/decorator-adapter.d.ts.map +1 -0
  41. package/dist/scp/decorator-adapter.js +286 -0
  42. package/dist/scp/decorator-adapter.js.map +1 -0
  43. package/dist/scp/emit/emitter.d.ts +108 -0
  44. package/dist/scp/emit/emitter.d.ts.map +1 -0
  45. package/dist/scp/emit/emitter.js +782 -0
  46. package/dist/scp/emit/emitter.js.map +1 -0
  47. package/dist/scp/emit/endpoint.d.ts +248 -0
  48. package/dist/scp/emit/endpoint.d.ts.map +1 -0
  49. package/dist/scp/emit/endpoint.js +20 -0
  50. package/dist/scp/emit/endpoint.js.map +1 -0
  51. package/dist/scp/emit/index.d.ts +11 -0
  52. package/dist/scp/emit/index.d.ts.map +1 -0
  53. package/dist/scp/emit/index.js +13 -0
  54. package/dist/scp/emit/index.js.map +1 -0
  55. package/dist/scp/errors.d.ts +45 -1
  56. package/dist/scp/errors.d.ts.map +1 -1
  57. package/dist/scp/errors.js +47 -1
  58. package/dist/scp/errors.js.map +1 -1
  59. package/dist/scp/exec-context.d.ts +390 -0
  60. package/dist/scp/exec-context.d.ts.map +1 -0
  61. package/dist/scp/exec-context.js +540 -0
  62. package/dist/scp/exec-context.js.map +1 -0
  63. package/dist/scp/grouping.d.ts +32 -0
  64. package/dist/scp/grouping.d.ts.map +1 -0
  65. package/dist/scp/grouping.js +0 -0
  66. package/dist/scp/grouping.js.map +1 -0
  67. package/dist/scp/index.cjs +6814 -15731
  68. package/dist/scp/index.d.cts +1 -0
  69. package/dist/scp/index.d.mts +1 -0
  70. package/dist/scp/index.d.ts +47 -49
  71. package/dist/scp/index.d.ts.map +1 -1
  72. package/dist/scp/index.js +174 -152
  73. package/dist/scp/index.js.map +1 -1
  74. package/dist/scp/index.mjs +5561 -3704
  75. package/dist/scp/leaf-transport.d.ts +50 -0
  76. package/dist/scp/leaf-transport.d.ts.map +1 -0
  77. package/dist/scp/leaf-transport.js +92 -0
  78. package/dist/scp/leaf-transport.js.map +1 -0
  79. package/dist/scp/leaves.d.ts +174 -0
  80. package/dist/scp/leaves.d.ts.map +1 -0
  81. package/dist/scp/leaves.js +287 -0
  82. package/dist/scp/leaves.js.map +1 -0
  83. package/dist/scp/limit-config.d.ts +118 -0
  84. package/dist/scp/limit-config.d.ts.map +1 -0
  85. package/dist/scp/limit-config.js +126 -0
  86. package/dist/scp/limit-config.js.map +1 -0
  87. package/dist/scp/makesql/compile-relation.d.ts +49 -23
  88. package/dist/scp/makesql/compile-relation.d.ts.map +1 -1
  89. package/dist/scp/makesql/compile-relation.js +101 -76
  90. package/dist/scp/makesql/compile-relation.js.map +1 -1
  91. package/dist/scp/makesql/compile-select.d.ts +45 -10
  92. package/dist/scp/makesql/compile-select.d.ts.map +1 -1
  93. package/dist/scp/makesql/compile-select.js +50 -10
  94. package/dist/scp/makesql/compile-select.js.map +1 -1
  95. package/dist/scp/makesql/handler.d.ts +1 -1
  96. package/dist/scp/makesql/handler.d.ts.map +1 -1
  97. package/dist/scp/makesql/index.d.ts +7 -9
  98. package/dist/scp/makesql/index.d.ts.map +1 -1
  99. package/dist/scp/makesql/index.js +17 -28
  100. package/dist/scp/makesql/index.js.map +1 -1
  101. package/dist/scp/makesql/json-array.d.ts +65 -0
  102. package/dist/scp/makesql/json-array.d.ts.map +1 -1
  103. package/dist/scp/makesql/json-array.js +99 -10
  104. package/dist/scp/makesql/json-array.js.map +1 -1
  105. package/dist/scp/makesql/json-batch.d.ts.map +1 -1
  106. package/dist/scp/makesql/json-batch.js +15 -18
  107. package/dist/scp/makesql/json-batch.js.map +1 -1
  108. package/dist/scp/makesql/makesql.d.ts +1 -1
  109. package/dist/scp/makesql/makesql.d.ts.map +1 -1
  110. package/dist/scp/makesql/mysql-returning.d.ts +93 -0
  111. package/dist/scp/makesql/mysql-returning.d.ts.map +1 -0
  112. package/dist/scp/makesql/mysql-returning.js +215 -0
  113. package/dist/scp/makesql/mysql-returning.js.map +1 -0
  114. package/dist/scp/makesql/outtype.d.ts +40 -54
  115. package/dist/scp/makesql/outtype.d.ts.map +1 -1
  116. package/dist/scp/makesql/outtype.js +46 -204
  117. package/dist/scp/makesql/outtype.js.map +1 -1
  118. package/dist/scp/makesql/pool-executor.d.ts +86 -34
  119. package/dist/scp/makesql/pool-executor.d.ts.map +1 -1
  120. package/dist/scp/makesql/pool-executor.js +179 -39
  121. package/dist/scp/makesql/pool-executor.js.map +1 -1
  122. package/dist/scp/makesql/tx.d.ts +107 -22
  123. package/dist/scp/makesql/tx.d.ts.map +1 -1
  124. package/dist/scp/makesql/tx.js +451 -97
  125. package/dist/scp/makesql/tx.js.map +1 -1
  126. package/dist/scp/makesql/writeouttype.d.ts +4 -4
  127. package/dist/scp/makesql/writeouttype.d.ts.map +1 -1
  128. package/dist/scp/makesql/writeouttype.js +5 -3
  129. package/dist/scp/makesql/writeouttype.js.map +1 -1
  130. package/dist/scp/middleware.d.ts +287 -0
  131. package/dist/scp/middleware.d.ts.map +1 -0
  132. package/dist/scp/middleware.js +358 -0
  133. package/dist/scp/middleware.js.map +1 -0
  134. package/dist/scp/relation.d.ts +65 -8
  135. package/dist/scp/relation.d.ts.map +1 -1
  136. package/dist/scp/relation.js +154 -93
  137. package/dist/scp/relation.js.map +1 -1
  138. package/dist/scp/tx-options.d.ts +136 -0
  139. package/dist/scp/tx-options.d.ts.map +1 -0
  140. package/dist/scp/tx-options.js +184 -0
  141. package/dist/scp/tx-options.js.map +1 -0
  142. package/dist/scp/write-bundle.d.ts +131 -0
  143. package/dist/scp/write-bundle.d.ts.map +1 -0
  144. package/dist/scp/write-bundle.js +160 -0
  145. package/dist/scp/write-bundle.js.map +1 -0
  146. package/dist/types.d.ts +7 -0
  147. package/dist/types.d.ts.map +1 -1
  148. package/dist/types.js.map +1 -1
  149. package/docs/design/phase-a-execution-context.md +139 -0
  150. package/package.json +14 -13
  151. package/dist/scp/authoring-sql.d.ts +0 -134
  152. package/dist/scp/authoring-sql.d.ts.map +0 -1
  153. package/dist/scp/authoring-sql.js +0 -191
  154. package/dist/scp/authoring-sql.js.map +0 -1
  155. package/dist/scp/authoring.d.ts +0 -218
  156. package/dist/scp/authoring.d.ts.map +0 -1
  157. package/dist/scp/authoring.js +0 -351
  158. package/dist/scp/authoring.js.map +0 -1
  159. package/dist/scp/catalog.d.ts +0 -95
  160. package/dist/scp/catalog.d.ts.map +0 -1
  161. package/dist/scp/catalog.js +0 -245
  162. package/dist/scp/catalog.js.map +0 -1
  163. package/dist/scp/codegen.d.ts +0 -201
  164. package/dist/scp/codegen.d.ts.map +0 -1
  165. package/dist/scp/codegen.js +0 -605
  166. package/dist/scp/codegen.js.map +0 -1
  167. package/dist/scp/find-filter-guard.d.ts +0 -68
  168. package/dist/scp/find-filter-guard.d.ts.map +0 -1
  169. package/dist/scp/find-filter-guard.js +0 -88
  170. package/dist/scp/find-filter-guard.js.map +0 -1
  171. package/dist/scp/guard.d.ts +0 -43
  172. package/dist/scp/guard.d.ts.map +0 -1
  173. package/dist/scp/guard.js +0 -140
  174. package/dist/scp/guard.js.map +0 -1
  175. package/dist/scp/makesql/authoring-compile.d.ts +0 -90
  176. package/dist/scp/makesql/authoring-compile.d.ts.map +0 -1
  177. package/dist/scp/makesql/authoring-compile.js +0 -505
  178. package/dist/scp/makesql/authoring-compile.js.map +0 -1
  179. package/dist/scp/makesql/static-bundle.d.ts +0 -196
  180. package/dist/scp/makesql/static-bundle.d.ts.map +0 -1
  181. package/dist/scp/makesql/static-bundle.js +0 -1244
  182. package/dist/scp/makesql/static-bundle.js.map +0 -1
  183. package/dist/scp/runtime.d.ts +0 -243
  184. package/dist/scp/runtime.d.ts.map +0 -1
  185. package/dist/scp/runtime.js +0 -422
  186. package/dist/scp/runtime.js.map +0 -1
@@ -1,77 +1,33 @@
1
1
  "use strict";
2
2
  /**
3
- * litedbmodel v2 SCP — codegen `outType` derivation (spec §4.1; issues #58/#56).
3
+ * litedbmodel v2 SCP — read-row de-box type derivation (spec §4.1; issues #58/#59).
4
4
  *
5
- * bc's TYPED-RAW de-box emitters (`rust-typed-raw` / `go-typed-raw` / `typescript-typed`) require
6
- * each read node to carry an `outType` and the component an `outputType` (bc portable type
7
- * notation). WITHOUT them the emitter hard-fails ("nothing to de-box") — the correct fail-closed
8
- * behavior. This module derives those annotations for a READ component from:
5
+ * The read-column coverage + de-box SSoT for the op-independent leaf path. It resolves a read's
6
+ * projection ONCE into two projections of the SAME column-type resolution:
9
7
  *
10
- * 1. the per-node SELECT projection (`table` + `select` ports) → a row `obj` type, each column's
11
- * bc scalar resolved from its SQL type (the schema/DDL SoT) via {@link sqlTypeToBcScalar};
12
- * 2. the node cardinality (a Select node returns a row LIST → `{arr:rowObj}`; a Count → `int`; a
13
- * `.map` node wraps its per-element handler result → `{arr:<elem>}`);
14
- * 3. the component `output` Φ-expression, walked to compose the `outputType` from the node types
15
- * (`{ref:[nodeId]}` → that node's outType; `{obj:{…}}`/`{arr:…}`/`{opt:…}` recurse).
8
+ * - {@link deriveReadRow} — the read ROW `{arr:{obj:{outputKey: <read-de-boxed scalar>}}}` (the
9
+ * bc `outType` bc's native emitter reads for the typed de-box, #154) PLUS the TS-leaf
10
+ * `materializers` coercion map. Array columns read as `{arr:<element>}` (the SSoT array split
11
+ * {@link import('../coltype').arrayElementType}); the element rides the SAME de-box scalar.
12
+ * - {@link outputType} — composes the component `outputType` by walking the `output` Φ-expression
13
+ * against a `nodeId → outType` map.
16
14
  *
17
- * Spec §4.1 discipline: an ambiguous/unmappable projection is a HARD ERROR (no-assume,
18
- * no-fallback) — a `*` projection, a computed/aliased column, or a column with no schema type
19
- * THROWS. It is NEVER degraded to a boxed/untyped output; that would silently defeat the de-box.
15
+ * Spec §4.1 discipline: an ambiguous/unmappable projection is a HARD ERROR (no-assume, no-fallback)
16
+ * — a `*` projection, a computed column (typed reads only), or an undeclared/unknown-type column
17
+ * THROWS via {@link parseProjectionColumn} + the coltype SSoT; never a boxed/untyped output.
20
18
  */
21
19
  Object.defineProperty(exports, "__esModule", { value: true });
22
20
  exports.parseProjectionColumn = parseProjectionColumn;
23
- exports.nodeOutType = nodeOutType;
24
- exports.crudNodeAsType = crudNodeAsType;
25
- exports.deriveReadOutTypes = deriveReadOutTypes;
21
+ exports.deriveReadRow = deriveReadRow;
22
+ exports.outputType = outputType;
26
23
  const coltype_1 = require("../coltype");
27
24
  const tx_1 = require("./tx");
28
- /**
29
- * Narrow a {@link BcScalar} to a bc {@link PortableScalarType}. `BcScalar`'s members
30
- * (`string|int|float|bool|null`) are exactly bc 0.3.0's portable scalar notation, so this is an
31
- * identity narrow. DATE/TIMESTAMP columns map to `string` at the `sqlTypeToBcScalar` layer (spec
32
- * §4.1 owner decision; bc has no `date` scalar — behavior-contracts#84 deferred), so no `date`
33
- * scalar ever reaches here.
34
- */
35
- function toPortableScalar(scalar, _table, _column) {
36
- return scalar;
37
- }
38
- function isMap(n) {
39
- return 'map' in n;
40
- }
41
- /** The `{component, ports}` of a body node (unwrapping a `.map`). */
42
- function nodeRef(n) {
43
- return isMap(n) ? { component: n.map.component, ports: n.map.ports } : { component: n.component, ports: n.ports };
44
- }
45
25
  function opKey(node) {
46
26
  if (node === null || typeof node !== 'object' || Array.isArray(node))
47
27
  return undefined;
48
28
  const keys = Object.keys(node);
49
29
  return keys.length === 1 ? keys[0] : undefined;
50
30
  }
51
- /** Read a required literal string port, or throw (the projection SoT must be a literal in the IR). */
52
- function stringPort(ports, name) {
53
- const v = ports[name];
54
- if (v === undefined)
55
- return undefined;
56
- if (typeof v !== 'string') {
57
- throw new Error(`outtype: port '${name}' must be a literal string in the IR (got ${JSON.stringify(v)})`);
58
- }
59
- return v;
60
- }
61
- /** Read a literal `{arr:[str,…]}` string-list port (the SELECT projection). */
62
- function stringArrayPort(ports, name) {
63
- const v = ports[name];
64
- if (v === undefined)
65
- return undefined;
66
- if (typeof v === 'object' && v !== null && 'arr' in v && Array.isArray(v.arr)) {
67
- return v.arr.map((e) => {
68
- if (typeof e !== 'string')
69
- throw new Error(`outtype: '${name}' entries must be literal strings (got ${JSON.stringify(e)})`);
70
- return e;
71
- });
72
- }
73
- throw new Error(`outtype: port '${name}' must be an {arr:[…]} literal in the IR (got ${JSON.stringify(v)})`);
74
- }
75
31
  /**
76
32
  * The SINGLE projection-column parser (issue #59) — shared by BOTH the codegen `outType` derivation
77
33
  * and the TS read-path materializer derivation so the two CANNOT diverge (the recurring source of
@@ -116,76 +72,47 @@ function parseProjectionColumn(col, table, at) {
116
72
  return { kind: 'computed', text: raw };
117
73
  }
118
74
  /**
119
- * The row `obj` type of a SELECT projection: `{obj:{outputKey: <bcScalar>, …}}`. Each column is
120
- * resolved ONCE via the SHARED {@link parseProjectionColumn} (bare / qualified / aliased) and its SQL
121
- * type (from the schema SoT) yields BOTH the bc scalar (this outType, for codegen) AND — written into
122
- * the `materializers` accumulator — the TS read-path {@link MaterializeClass} (INT32/INT64/date/bool).
123
- * This is the SINGLE column-type resolution the whole read pipeline consumes: codegen reads the
124
- * `obj`; the runtime read path reads `materializers`. They cannot diverge — they are two projections
125
- * of the ONE resolution. A `*` / absent projection, a computed column, a duplicate OUTPUT key, or an
126
- * undeclared underlying column is a HARD ERROR (no-assume, no-fallback) — for BOTH consumers.
75
+ * Derive the read ROW from a projection (#141 SSoT + #59 op-builder guard). Resolves each projected
76
+ * column ONCE via the SHARED {@link parseProjectionColumn} + the coltype SSoT, producing BOTH:
77
+ * - `outType` — `{arr:{obj:{outputKey: keyArrayElemScalar(sqlType)}}}`, the READ-DE-BOXED scalar
78
+ * (int32→`float`(number) / BIGINT→`string` / BOOLEAN→`bool` / DATE→`string` / text/uuid→`string`).
79
+ * This is the ONE row-type representation: bc's native emitter reads it for the typed de-box
80
+ * (#154), and it is the conform target the TS leaf coercion below produces.
81
+ * - `materializers` — the TS-leaf coercion map ({@link sqlTypeToMaterializeClass}); the leaf coerces
82
+ * each driver cell (BIGINT→exact string / DATE→string / BOOLEAN→boolean) so the row MATCHES `outType`
83
+ * before bc conforms it (bc conform VALIDATES, does not coerce). Derived from the SAME resolution as
84
+ * `outType`, so the coerced JS form always equals the declared read scalar — no second row type.
85
+ * This IS the #59 read-column coverage guard: `*`/`t.*` throws (unknown column list), an undeclared
86
+ * column or unknown SQL type throws. A COMPUTED projection (`COUNT(*)`, cast, literal) is left RAW
87
+ * (omitted from BOTH) — #59: "the read path leaves it raw".
127
88
  */
128
- function rowObjType(table, projection, resolveColumnType, at, materializers) {
129
- if (projection === undefined || projection.length === 0) {
130
- throw new Error(`outtype: ${at}: SELECT on '${table}' has no explicit column projection ('*' / empty). A typed ` +
131
- `de-box needs the concrete column list to build the row struct — spec §4.1 is column-typed. ` +
132
- `Project explicit columns (no-assume, no-fallback).`);
133
- }
89
+ function deriveReadRow(table, projection, resolveColumnType, at) {
134
90
  const obj = {};
91
+ const materializers = {};
135
92
  for (const col of projection) {
136
- const entry = parseProjectionColumn(col, table, at);
137
- // A computed expression has no concrete struct field type — HARD ERROR (spec §4.1 no-assume).
138
- // The read path never reaches a separate lenient pass now; `*`/computed fail here for BOTH.
139
- if (entry.kind === 'computed') {
140
- throw new Error(`outtype: ${at}: projected expression '${entry.text}' on '${table}' is computed (function / ` +
141
- `aggregate / cast / literal) and cannot be typed into a concrete row struct field. Typed ` +
142
- `de-box (spec §4.1) requires bare/qualified/aliased schema columns. No-assume, no-fallback.`);
143
- }
93
+ const entry = parseProjectionColumn(col, table, at); // throws on `*` / `t.*`
94
+ if (entry.kind === 'computed')
95
+ continue; // computed column: read raw (no de-box / no typed field), #59
144
96
  const { underlying, outputKey, qualifier } = entry;
145
- if (outputKey in obj)
146
- throw new Error(`outtype: ${at}: duplicate projected column key '${outputKey}' on '${table}'`);
147
- // Resolve against the qualifier's table (a JOIN column) if present, else the node's base table.
148
97
  const owner = qualifier ?? table;
149
- // ONE resolution of the SQL type → both the bc scalar AND the materialize class. resolveColumnType
150
- // throws on an undeclared column, sqlType* throw on an unknown SQL type — fail-closed by
151
- // construction on the UNDERLYING column, keyed by the OUTPUT column (the driver's row key).
152
- const sqlType = resolveColumnType(owner, underlying);
153
- obj[outputKey] = toPortableScalar((0, coltype_1.sqlTypeToBcScalar)(sqlType), owner, underlying);
98
+ const sqlType = resolveColumnType(owner, underlying); // undeclared → throw
99
+ // A read cell is nullable UNLESS `static columns` declares the column `NOT NULL` — a driver column
100
+ // may be NULL, so the read scalar rides under `opt` (bc conforms `null`/absent OR the de-boxed
101
+ // scalar). A `NOT NULL` column is non-null by SQL contract → the raw scalar (no `opt`), so a
102
+ // RETURNING primary key can be consumed in a value position (a `.map` param) without an
103
+ // optional-narrowing coalesce (spec §4.1 nullability — the SSoT is the declared column constraint).
104
+ // Array-aware (F2 #105): a projected ARRAY column reads as a `{arr:<de-boxed element>}` list (the
105
+ // driver hands over a JS array; the whole value is passthrough — see `sqlTypeToMaterializeClass`),
106
+ // a scalar column as its read-de-boxed scalar. SSoT array split ({@link arrayElementType}); the
107
+ // element rides the SAME `keyArrayElemScalar` de-box as a scalar column (throws on unknown type).
108
+ const element = (0, coltype_1.arrayElementType)(sqlType);
109
+ const scalar = element !== null ? { arr: (0, coltype_1.keyArrayElemScalar)(element) } : (0, coltype_1.keyArrayElemScalar)(sqlType);
110
+ obj[outputKey] = (0, coltype_1.sqlTypeIsNotNull)(sqlType) ? scalar : { opt: scalar };
154
111
  const klass = (0, coltype_1.sqlTypeToMaterializeClass)(sqlType);
155
112
  if (klass !== 'passthrough')
156
113
  materializers[outputKey] = klass; // omit passthrough (no-op coercion)
157
114
  }
158
- return { obj };
159
- }
160
- /**
161
- * The outType + read-path materializers of ONE read body node — derived from the SINGLE column-type
162
- * resolution ({@link rowObjType}). A `Select` returns a ROW LIST → `{arr:rowObj}`; a `Count` a single
163
- * `int` (a scalar, no per-column map). A `.map` node wraps its per-element Select result. An
164
- * unrecognized component throws (typed read de-box covers only the SQL read catalog).
165
- */
166
- function nodeTypes(node, resolveColumnType) {
167
- const { component, ports } = nodeRef(node);
168
- const at = `node '${node.id}'`;
169
- if (component === 'Count')
170
- return { outType: 'int', materializers: {} };
171
- if (component === 'Select') {
172
- const table = stringPort(ports, 'table');
173
- if (table === undefined)
174
- throw new Error(`outtype: ${at}: Select node requires a literal 'table' port`);
175
- const projection = stringArrayPort(ports, 'select');
176
- const materializers = {};
177
- const row = rowObjType(table, projection, resolveColumnType, at, materializers);
178
- // A `.map` node iterates a list and invokes the inner component per element (row LIST per element
179
- // → `{arr:{arr:rowObj}}`); a plain Select node returns the row list `{arr:rowObj}`.
180
- const outType = isMap(node) ? { arr: { arr: row } } : { arr: row };
181
- return { outType, materializers };
182
- }
183
- throw new Error(`outtype: ${at}: component '${component}' has no typed outType (typed read de-box covers Select/Count only). ` +
184
- `A write / unknown node cannot be de-boxed here — no-assume, no-fallback.`);
185
- }
186
- /** The outType of ONE read body node (thin wrapper over {@link nodeTypes} for external callers). */
187
- function nodeOutType(node, resolveColumnType) {
188
- return nodeTypes(node, resolveColumnType).outType;
115
+ return { outType: { arr: { obj } }, materializers };
189
116
  }
190
117
  /**
191
118
  * Derive the component `outputType` by walking the `output` Φ-expression against a `nodeId →
@@ -240,89 +167,4 @@ function outputType(output, byNode, at) {
240
167
  `(ref / obj / arr / opt of node results). The typed de-box path does not build a dynamic ` +
241
168
  `Value output tree — no-assume, no-fallback.`);
242
169
  }
243
- /**
244
- * PRE-COMPILE node-output type (bc 0.8.0 SA5 / #12): the determined `PortableType` a litedbmodel CRUD
245
- * leaf annotates its authored node with, via bc's `.as(t)` recording API, so `compileBehaviors`'
246
- * all-nodes-typed gate (`UNTYPED_NODE`) passes. Computed from the RAW authored ports (a plain `table`
247
- * string + a plain `select` / `returning` column list — the same projection SoT `deriveReadOutTypes`
248
- * reads post-compile, just moved to authoring time) + the model's inline `static columns` resolver.
249
- *
250
- * - `Select` → the row LIST `{arr:{obj:{outKey:<scalar>,…}}}` from the `select` projection. This is
251
- * the value `.as` takes in BOTH positions: a top-level Select node's `outType` is this list; a
252
- * mapped Select's `.as` records it as the map ELEMENT type (bc convention — the per-parent row list).
253
- * - `Count` → NOT handled here: its output is the static `int` catalog `elemType` (no `.as`).
254
- * - `Insert`/`Update`/`Delete` → the RETURNING row list `{arr:{obj:…}}` from the `returning` port
255
- * (bare-column list). No `returning` → an EMPTY row list `{arr:{obj:{}}}` (the write surfaces rows
256
- * only via RETURNING; a no-RETURNING write yields empty rows — mirrors `writeouttype.ts`).
257
- *
258
- * Schema columns are parsed by the SAME {@link parseProjectionColumn} the read/codegen paths use and
259
- * typed via the resolver (an undeclared column fails closed here at authoring — earlier than the
260
- * post-compile derivation). A COMPUTED projected column (`COUNT(*) as n`, a cast, a literal) is OMITTED
261
- * from the typed row struct — the read path leaves a computed column RAW (#59: "the read path leaves it
262
- * raw; the codegen path rejects it"), so its field is absent from the de-box row type. This keeps the
263
- * node's outType DETERMINED (gate passes) while preserving #59's raw-computed read behavior; the typed
264
- * codegen path independently rejects a computed projection later (it needs every field typed). The
265
- * value is the OUTPUT-row type only; SQL stays opaque text on the makeSQL leaf (types the node OUTPUT,
266
- * never the SQL).
267
- */
268
- function crudNodeAsType(component, ports, resolveColumnType, at) {
269
- const table = ports['table'];
270
- if (typeof table !== 'string') {
271
- throw new Error(`outtype: ${at}: ${component} node requires a literal 'table' string port to type its output (got ${JSON.stringify(table)})`);
272
- }
273
- if (component === 'Select') {
274
- const select = ports['select'];
275
- if (!Array.isArray(select) || select.length === 0) {
276
- throw new Error(`outtype: ${at}: Select has no explicit column projection ('*' / empty). A typed de-box needs the ` +
277
- `concrete column list to build the row struct — spec §4.1 is column-typed. Project explicit columns.`);
278
- }
279
- const obj = {};
280
- for (const raw of select) {
281
- if (typeof raw !== 'string')
282
- throw new Error(`outtype: ${at}: Select 'select' entries must be literal strings (got ${JSON.stringify(raw)})`);
283
- const parsed = parseProjectionColumn(raw, table, at);
284
- if (parsed.kind === 'computed')
285
- continue; // computed column: read raw, omitted from the typed row (SA5-determined without it)
286
- const { underlying, outputKey, qualifier } = parsed;
287
- if (outputKey in obj)
288
- throw new Error(`outtype: ${at}: duplicate projected column key '${outputKey}' on '${table}'`);
289
- obj[outputKey] = toPortableScalar((0, coltype_1.sqlTypeToBcScalar)(resolveColumnType(qualifier ?? table, underlying)), qualifier ?? table, underlying);
290
- }
291
- return { arr: { obj } };
292
- }
293
- if (component === 'Insert' || component === 'Update' || component === 'Delete') {
294
- // The RETURNING port is a single comma-separated bare-column string (`'id, author_id'`) or absent.
295
- const returning = ports['returning'];
296
- if (returning === undefined)
297
- return { arr: { obj: {} } };
298
- if (typeof returning !== 'string') {
299
- throw new Error(`outtype: ${at}: ${component} 'returning' port must be a literal string (got ${JSON.stringify(returning)})`);
300
- }
301
- const cols = returning.split(',').map((c) => c.trim()).filter((c) => c.length > 0);
302
- if (cols.length === 0)
303
- return { arr: { obj: {} } };
304
- return { arr: rowObjType(table, cols, resolveColumnType, at, {}) };
305
- }
306
- throw new Error(`outtype: ${at}: no pre-compile output type for component '${component}' (typed CRUD covers Select/Insert/Update/Delete; Count is static via catalog elemType).`);
307
- }
308
- /**
309
- * Per-node `outType` (keyed by body node id) + the component `outputType`, derived for a READ
310
- * component (spec §4.1). `cond` nodes are skipped for the per-node map but a `cond` at the OUTPUT
311
- * position (a shared-branch merge) would be handled by {@link outputType} if reached — the bench's
312
- * read outputs are ref / obj compositions of Select nodes. Any ambiguity throws (fail-closed).
313
- */
314
- function deriveReadOutTypes(component, resolveColumnType) {
315
- const byNode = new Map();
316
- const materializersByNode = new Map();
317
- for (const n of component.body) {
318
- if ('cond' in n)
319
- continue; // a cond node carries no SELECT projection; it is typed by its branch
320
- // ONE resolution per node → the outType (codegen) AND the read-path materializers (runtime).
321
- const t = nodeTypes(n, resolveColumnType);
322
- byNode.set(n.id, t.outType);
323
- if (Object.keys(t.materializers).length > 0)
324
- materializersByNode.set(n.id, t.materializers);
325
- }
326
- return { byNode, outputType: outputType(component.output, byNode, `component '${component.name}' output`), materializersByNode };
327
- }
328
170
  //# sourceMappingURL=outtype.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"outtype.js","sourceRoot":"","sources":["../../../src/scp/makesql/outtype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AAS,CAAC,MAAM,CAAC,8BAA8B;QACvF,0FAA0F;QAC1F,6CAA6C,CAChD,CAAC;AACJ,CAAC"}
@@ -1,11 +1,11 @@
1
1
  /**
2
- * litedbmodel v2 SCP — pooled async `SqlExecutorAsync` factories for PG / MySQL (#40).
2
+ * litedbmodel v2 SCP — pooled async `SqlExecutor` factories for PG / MySQL (#40).
3
3
  *
4
4
  * The read-graph async execution model (`executeReadGraphAsync`) dispatches independent sibling
5
5
  * relations in bounded parallel via bc `runBehaviorAsync`. For that concurrency to become REAL
6
6
  * parallel DB I/O the driver seam must be an async CONNECTION POOL — each concurrent `exec` call
7
7
  * checks out a DISTINCT pooled connection. These factories adapt a `pg.Pool` / `mysql2` pool to the
8
- * {@link SqlExecutorAsync} seam.
8
+ * {@link SqlExecutor} seam.
9
9
  *
10
10
  * The read graph already renders the dialect placeholder form (`$N` for postgres, `?` for
11
11
  * MySQL/SQLite, via `renderPlaceholders`) and flattens params 1:1, so each executor is a THIN
@@ -16,7 +16,8 @@
16
16
  * `pg` / `mysql2` are optional peer dependencies loaded dynamically — importing this module does not
17
17
  * force either into a consumer that only uses the sync better-sqlite3 conformance path.
18
18
  */
19
- import type { SqlExecutorAsync } from './static-bundle';
19
+ import type { AsyncConnectionPool } from '../exec-context';
20
+ import type { PoolFactory } from '../connection-routing';
20
21
  /** The minimal `pg.types` surface: register a per-OID text parser. */
21
22
  export interface PgTypesLike {
22
23
  setTypeParser(oid: number, parser: (value: string) => unknown): void;
@@ -24,8 +25,8 @@ export interface PgTypesLike {
24
25
  /**
25
26
  * Register `pg` type parsers so the read-path de-box (issue #59) gets coercible values: the
26
27
  * DATE/TIMESTAMP/TIMESTAMPTZ/TIME family is returned as its NATIVE TEXTUAL string (NOT a JS Date),
27
- * honoring the `date→string` outType and carrying the TZ for timestamptz. int8 already arrives as a
28
- * string (pg default), so it needs no parser. Idempotent. Call ONCE, before building the pool, from
28
+ * honoring the `date→string` outType and carrying the TZ for timestamptz; and the int2/int4/int8 family
29
+ * as a BigInt, the TS plane's `int` value model. Idempotent. Call ONCE, before building the pool, from
29
30
  * the consumer that owns the `pg` module (`import { types } from 'pg'; configurePgDeboxTypeParsers(types)`).
30
31
  *
31
32
  * WHY the GLOBAL parser (a documented, deliberate exception): `pg`'s default DATE parser builds a JS
@@ -48,7 +49,21 @@ export declare const mysqlDeboxPoolOptions: {
48
49
  readonly supportBigNumbers: true;
49
50
  readonly bigNumberStrings: true;
50
51
  readonly dateStrings: true;
52
+ /**
53
+ * An INTEGER column must arrive in bc's `int` value model — a BigInt on the TS plane. `mysql2` hands
54
+ * back a JS number for TINY/SHORT/INT24/LONG (only BIGINT becomes a string, via `bigNumberStrings`),
55
+ * and bc classifies a JS number as FLOAT, so a column declared `Int` failed its outType check with
56
+ * `expected int, got float`. The FIELD TYPE decides, never the value: a DOUBLE/DECIMAL column whose
57
+ * value happens to be integral still arrives as a float. sqlite gets the same guarantee from
58
+ * better-sqlite3's `safeIntegers`, PostgreSQL from {@link configurePgDeboxTypeParsers}'s int OIDs.
59
+ */
60
+ readonly typeCast: (field: MysqlFieldLike, next: () => unknown) => unknown;
51
61
  };
62
+ /** The `mysql2` field surface `typeCast` reads: the column's declared type and its raw text. */
63
+ export interface MysqlFieldLike {
64
+ readonly type: string;
65
+ string(): string | null;
66
+ }
52
67
  /** The minimal `pg.Pool` surface we need: `query(text, values)` resolving `{ rows }`. */
53
68
  export interface PgPoolLike {
54
69
  query(text: string, values?: unknown[]): Promise<{
@@ -59,15 +74,6 @@ export interface PgPoolLike {
59
74
  export interface MysqlPoolLike {
60
75
  query(sql: string, values?: unknown[]): Promise<[Record<string, unknown>[], unknown]>;
61
76
  }
62
- /**
63
- * Adapt a `pg.Pool` to the async executor seam. Each `exec` runs `pool.query`, which acquires a
64
- * pooled connection, runs the query, and releases it — so N concurrent siblings run on N pooled
65
- * connections in parallel. The graph renders `$N` placeholders for the `postgres` dialect, so the
66
- * `sql` is already in `pg`'s native form.
67
- *
68
- * Recommend constructing the pool with `max` ≥ the plan's `concurrency` (default 16).
69
- */
70
- export declare function pgPoolExecutor(pool: PgPoolLike): SqlExecutorAsync;
71
77
  /**
72
78
  * Adapt a `mysql2/promise` pool to the async executor seam. `pool.query` acquires + releases a
73
79
  * pooled connection per call, so concurrent siblings run in parallel. The graph renders `?`
@@ -88,30 +94,76 @@ export interface Mysql2ModuleLike {
88
94
  end?: () => Promise<void>;
89
95
  };
90
96
  }
97
+ /** A pg `Pool` that hands out an owned `PoolClient` (`connect()` → `release()`). */
98
+ export interface PgOwnedPoolLike {
99
+ connect(): Promise<PgPoolClientLike>;
100
+ }
101
+ /** The pg `PoolClient`: parameterized `query`, and `release(destroy?)` back to the pool. */
102
+ export interface PgPoolClientLike {
103
+ query(text: string, values?: unknown[]): Promise<{
104
+ rows: Record<string, unknown>[];
105
+ rowCount?: number | null;
106
+ }>;
107
+ release(destroy?: boolean): void;
108
+ }
91
109
  /**
92
- * Build a PG pool + executor with the read-path de-box wired IN (issue #59): registers the pg date
93
- * type parsers (DATE/TIMESTAMP family → native textual string) globally, then builds the pool.
94
- * int8 already arrives as a string on pg. Returns `{ pool, exec }` — pass `exec` to
95
- * `executeBehaviorAsync`. This is the production async path's de-box-correct entry (no hand-spread
96
- * options).
110
+ * Adapt a pg `Pool` to the {@link AsyncConnectionPool} contract — `acquire` checks out an owned
111
+ * `PoolClient`, `release` returns it (destroyed on a poisoned tx). Feed this to
112
+ * `withTransactionAsync` for per-execution connection ownership.
97
113
  */
98
- export declare function pgDeboxExecutor(pg: PgModuleLike, config: Record<string, unknown>): {
99
- pool: PgPoolLike & {
100
- end?: () => Promise<void>;
101
- };
102
- exec: SqlExecutorAsync;
114
+ export declare function pgConnectionPool(pool: PgOwnedPoolLike): AsyncConnectionPool;
115
+ /** A mysql2/promise `Pool` that hands out an owned connection (`getConnection()` → `release()`). */
116
+ export interface MysqlOwnedPoolLike {
117
+ getConnection(): Promise<MysqlPoolConnLike>;
118
+ }
119
+ /** A mysql2/promise pooled connection: `query`, and `release()` back to the pool. */
120
+ export interface MysqlPoolConnLike {
121
+ query(sql: string, values?: unknown[]): Promise<[unknown, unknown]>;
122
+ release(): void;
123
+ destroy(): void;
124
+ }
125
+ /**
126
+ * Adapt a mysql2/promise `Pool` to the {@link AsyncConnectionPool} contract — `acquire` checks out
127
+ * an owned connection, `release` returns it (or `destroy`s a poisoned one). Feed this to
128
+ * `withTransactionAsync` for per-execution connection ownership.
129
+ */
130
+ export declare function mysqlConnectionPool(pool: MysqlOwnedPoolLike): AsyncConnectionPool;
131
+ /** A pg `Pool` the factory constructs: owned-connection surface + `end()` (the closer). */
132
+ export type PgOwnedPoolWithEnd = PgOwnedPoolLike & {
133
+ end(): Promise<void>;
103
134
  };
135
+ /** The `pg` module surface the pool factory needs: an OWNED-connection `Pool` ctor + `types`. */
136
+ export interface PgFactoryModuleLike {
137
+ Pool: new (config: Record<string, unknown>) => PgOwnedPoolWithEnd;
138
+ types: PgTypesLike;
139
+ }
104
140
  /**
105
- * Build a MySQL pool + executor with the read-path de-box wired IN (issue #59): the pool carries
106
- * {@link mysqlDeboxPoolOptions} (`supportBigNumbers + bigNumberStrings` so BIGINT → exact string,
107
- * `dateStrings` so the date family → string) — options that MUST be set at pool construction (a
108
- * rounded BIGINT cannot be un-rounded post-hoc). Returns `{ pool, exec }` for `executeBehaviorAsync`.
141
+ * A {@link PoolFactory} for `pg`: constructs a `new pg.Pool(...)` from a {@link ResolvedConnectionConfig},
142
+ * applying the pool SIZING (`max` = `maxPool`, `min` = `minPool`) and `keepAlive` /
143
+ * `keepAliveInitialDelayMillis` AT CONSTRUCTION — the config is the sole source of the cap. Connection
144
+ * params (host/port/database/user/password) also flow from the config. Registers the read-path de-box
145
+ * type parsers (issue #59, global, idempotent) once. Returns the owned-connection adapter + closer.
146
+ *
147
+ * `role` is accepted for the reader/writer replica split; the caller may vary host per role via the
148
+ * config it passes. `Pool` is the `pg.Pool` ctor (peer dep, passed in — this module imports no driver).
109
149
  */
110
- export declare function mysqlDeboxExecutor(mysql2: Mysql2ModuleLike, config: Record<string, unknown>): {
111
- pool: MysqlPoolLike & {
112
- end?: () => Promise<void>;
113
- };
114
- exec: SqlExecutorAsync;
150
+ export declare function pgPoolFactory(pg: PgFactoryModuleLike): PoolFactory;
151
+ /** A mysql2 `Pool` the factory constructs: owned-connection surface + `end()` (the closer). */
152
+ export type MysqlOwnedPoolWithEnd = MysqlOwnedPoolLike & {
153
+ end(): Promise<void>;
115
154
  };
116
- export declare function mysqlPoolExecutor(pool: MysqlPoolLike): SqlExecutorAsync;
155
+ /**
156
+ * A {@link PoolFactory} for `mysql2/promise`: constructs a `mysql2.createPool(...)` from a
157
+ * {@link ResolvedConnectionConfig}, applying the pool SIZING (`connectionLimit` = `maxPool`) +
158
+ * `enableKeepAlive` / `keepAliveInitialDelay` AT CONSTRUCTION (the config is the sole source of the
159
+ * cap) plus the read-path de-box options ({@link mysqlDeboxPoolOptions}). Connection params flow from
160
+ * the config. Returns the owned-connection adapter + closer.
161
+ *
162
+ * NB: mysql2 has no `min` idle floor — `minPool` is a no-op there (a documented per-driver deviation;
163
+ * the SIZING CAP that matters — `maxPool` → `connectionLimit` — is honored). `createPool` is the
164
+ * `mysql2/promise` factory (peer dep, passed in).
165
+ */
166
+ export declare function mysqlPoolFactory(mysql2: {
167
+ createPool(config: Record<string, unknown>): MysqlOwnedPoolWithEnd;
168
+ }): PoolFactory;
117
169
  //# sourceMappingURL=pool-executor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pool-executor.d.ts","sourceRoot":"","sources":["../../../src/scp/makesql/pool-executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAkBxD,sEAAsE;AACtE,MAAM,WAAW,WAAW;IAC1B,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,GAAG,IAAI,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