litedbmodel 2.0.0 → 2.0.2

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 (163) 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 +5 -2
  6. package/dist/scp/catalog.d.ts.map +1 -1
  7. package/dist/scp/catalog.js +32 -1
  8. package/dist/scp/catalog.js.map +1 -1
  9. package/dist/scp/codegen.d.ts +143 -85
  10. package/dist/scp/codegen.d.ts.map +1 -1
  11. package/dist/scp/codegen.js +374 -90
  12. package/dist/scp/codegen.js.map +1 -1
  13. package/dist/scp/coltype.d.ts +41 -0
  14. package/dist/scp/coltype.d.ts.map +1 -0
  15. package/dist/scp/coltype.js +188 -0
  16. package/dist/scp/coltype.js.map +1 -0
  17. package/dist/scp/dialect.d.ts +12 -3
  18. package/dist/scp/dialect.d.ts.map +1 -1
  19. package/dist/scp/dialect.js +12 -3
  20. package/dist/scp/dialect.js.map +1 -1
  21. package/dist/scp/find-filter-guard.d.ts +68 -0
  22. package/dist/scp/find-filter-guard.d.ts.map +1 -0
  23. package/dist/scp/find-filter-guard.js +88 -0
  24. package/dist/scp/find-filter-guard.js.map +1 -0
  25. package/dist/scp/fragment/assemble.d.ts +61 -0
  26. package/dist/scp/fragment/assemble.d.ts.map +1 -0
  27. package/dist/scp/fragment/assemble.js +156 -0
  28. package/dist/scp/fragment/assemble.js.map +1 -0
  29. package/dist/scp/fragment/compile-pg.d.ts +107 -0
  30. package/dist/scp/fragment/compile-pg.d.ts.map +1 -0
  31. package/dist/scp/fragment/compile-pg.js +142 -0
  32. package/dist/scp/fragment/compile-pg.js.map +1 -0
  33. package/dist/scp/fragment/index.d.ts +16 -0
  34. package/dist/scp/fragment/index.d.ts.map +1 -0
  35. package/dist/scp/fragment/index.js +34 -0
  36. package/dist/scp/fragment/index.js.map +1 -0
  37. package/dist/scp/fragment/model.d.ts +119 -0
  38. package/dist/scp/fragment/model.d.ts.map +1 -0
  39. package/dist/scp/fragment/model.js +66 -0
  40. package/dist/scp/fragment/model.js.map +1 -0
  41. package/dist/scp/fragment/pg-array-type.d.ts +13 -0
  42. package/dist/scp/fragment/pg-array-type.d.ts.map +1 -0
  43. package/dist/scp/fragment/pg-array-type.js +34 -0
  44. package/dist/scp/fragment/pg-array-type.js.map +1 -0
  45. package/dist/scp/guard.d.ts +2 -6
  46. package/dist/scp/guard.d.ts.map +1 -1
  47. package/dist/scp/guard.js +19 -22
  48. package/dist/scp/guard.js.map +1 -1
  49. package/dist/scp/index.cjs +18695 -3921
  50. package/dist/scp/index.d.ts +41 -24
  51. package/dist/scp/index.d.ts.map +1 -1
  52. package/dist/scp/index.js +134 -49
  53. package/dist/scp/index.js.map +1 -1
  54. package/dist/scp/index.mjs +4830 -1432
  55. package/dist/scp/makesql/authoring-compile.d.ts +90 -0
  56. package/dist/scp/makesql/authoring-compile.d.ts.map +1 -0
  57. package/dist/scp/makesql/authoring-compile.js +494 -0
  58. package/dist/scp/makesql/authoring-compile.js.map +1 -0
  59. package/dist/scp/makesql/compile-crud.d.ts +133 -0
  60. package/dist/scp/makesql/compile-crud.d.ts.map +1 -0
  61. package/dist/scp/makesql/compile-crud.js +288 -0
  62. package/dist/scp/makesql/compile-crud.js.map +1 -0
  63. package/dist/scp/makesql/compile-relation.d.ts +157 -0
  64. package/dist/scp/makesql/compile-relation.d.ts.map +1 -0
  65. package/dist/scp/makesql/compile-relation.js +425 -0
  66. package/dist/scp/makesql/compile-relation.js.map +1 -0
  67. package/dist/scp/makesql/compile-select.d.ts +52 -0
  68. package/dist/scp/makesql/compile-select.d.ts.map +1 -0
  69. package/dist/scp/makesql/compile-select.js +58 -0
  70. package/dist/scp/makesql/compile-select.js.map +1 -0
  71. package/dist/scp/makesql/compile.d.ts +63 -0
  72. package/dist/scp/makesql/compile.d.ts.map +1 -0
  73. package/dist/scp/makesql/compile.js +99 -0
  74. package/dist/scp/makesql/compile.js.map +1 -0
  75. package/dist/scp/makesql/handler.d.ts +58 -0
  76. package/dist/scp/makesql/handler.d.ts.map +1 -0
  77. package/dist/scp/makesql/handler.js +113 -0
  78. package/dist/scp/makesql/handler.js.map +1 -0
  79. package/dist/scp/makesql/index.d.ts +33 -0
  80. package/dist/scp/makesql/index.d.ts.map +1 -0
  81. package/dist/scp/makesql/index.js +114 -0
  82. package/dist/scp/makesql/index.js.map +1 -0
  83. package/dist/scp/makesql/ir.d.ts +42 -0
  84. package/dist/scp/makesql/ir.d.ts.map +1 -0
  85. package/dist/scp/makesql/ir.js +66 -0
  86. package/dist/scp/makesql/ir.js.map +1 -0
  87. package/dist/scp/makesql/json-array.d.ts +84 -0
  88. package/dist/scp/makesql/json-array.d.ts.map +1 -0
  89. package/dist/scp/makesql/json-array.js +118 -0
  90. package/dist/scp/makesql/json-array.js.map +1 -0
  91. package/dist/scp/makesql/json-batch.d.ts +102 -0
  92. package/dist/scp/makesql/json-batch.d.ts.map +1 -0
  93. package/dist/scp/makesql/json-batch.js +269 -0
  94. package/dist/scp/makesql/json-batch.js.map +1 -0
  95. package/dist/scp/makesql/makesql.d.ts +99 -0
  96. package/dist/scp/makesql/makesql.d.ts.map +1 -0
  97. package/dist/scp/makesql/makesql.js +122 -0
  98. package/dist/scp/makesql/makesql.js.map +1 -0
  99. package/dist/scp/makesql/outtype.d.ts +44 -0
  100. package/dist/scp/makesql/outtype.d.ts.map +1 -0
  101. package/dist/scp/makesql/outtype.js +197 -0
  102. package/dist/scp/makesql/outtype.js.map +1 -0
  103. package/dist/scp/makesql/pool-executor.d.ts +47 -0
  104. package/dist/scp/makesql/pool-executor.d.ts.map +1 -0
  105. package/dist/scp/makesql/pool-executor.js +50 -0
  106. package/dist/scp/makesql/pool-executor.js.map +1 -0
  107. package/dist/scp/makesql/static-bundle.d.ts +187 -0
  108. package/dist/scp/makesql/static-bundle.d.ts.map +1 -0
  109. package/dist/scp/makesql/static-bundle.js +1113 -0
  110. package/dist/scp/makesql/static-bundle.js.map +1 -0
  111. package/dist/scp/makesql/tx.d.ts +216 -0
  112. package/dist/scp/makesql/tx.d.ts.map +1 -0
  113. package/dist/scp/makesql/tx.js +788 -0
  114. package/dist/scp/makesql/tx.js.map +1 -0
  115. package/dist/scp/makesql/writeouttype.d.ts +66 -0
  116. package/dist/scp/makesql/writeouttype.d.ts.map +1 -0
  117. package/dist/scp/makesql/writeouttype.js +195 -0
  118. package/dist/scp/makesql/writeouttype.js.map +1 -0
  119. package/dist/scp/relation.d.ts +86 -74
  120. package/dist/scp/relation.d.ts.map +1 -1
  121. package/dist/scp/relation.js +186 -120
  122. package/dist/scp/relation.js.map +1 -1
  123. package/dist/scp/runtime.d.ts +158 -211
  124. package/dist/scp/runtime.d.ts.map +1 -1
  125. package/dist/scp/runtime.js +250 -515
  126. package/dist/scp/runtime.js.map +1 -1
  127. package/dist/scp/typed-object.d.ts +12 -1
  128. package/dist/scp/typed-object.d.ts.map +1 -1
  129. package/dist/scp/typed-object.js +25 -4
  130. package/dist/scp/typed-object.js.map +1 -1
  131. package/docs/proposal/litedbmodel-v2-scp-architecture.md +51 -0
  132. package/docs/proposal/v0-coverage-matrix.md +157 -0
  133. package/docs/proposal/v2-completeness-plan.md +90 -0
  134. package/docs/proposal/v2-sql-parity-checklist.md +162 -0
  135. package/package.json +3 -3
  136. package/dist/scp/bridge.d.ts +0 -64
  137. package/dist/scp/bridge.d.ts.map +0 -1
  138. package/dist/scp/bridge.js +0 -329
  139. package/dist/scp/bridge.js.map +0 -1
  140. package/dist/scp/compile-dialect.d.ts +0 -39
  141. package/dist/scp/compile-dialect.d.ts.map +0 -1
  142. package/dist/scp/compile-dialect.js +0 -62
  143. package/dist/scp/compile-dialect.js.map +0 -1
  144. package/dist/scp/compile-sqlite.d.ts +0 -114
  145. package/dist/scp/compile-sqlite.d.ts.map +0 -1
  146. package/dist/scp/compile-sqlite.js +0 -149
  147. package/dist/scp/compile-sqlite.js.map +0 -1
  148. package/dist/scp/ir.d.ts +0 -92
  149. package/dist/scp/ir.d.ts.map +0 -1
  150. package/dist/scp/ir.js +0 -28
  151. package/dist/scp/ir.js.map +0 -1
  152. package/dist/scp/render.d.ts +0 -40
  153. package/dist/scp/render.d.ts.map +0 -1
  154. package/dist/scp/render.js +0 -170
  155. package/dist/scp/render.js.map +0 -1
  156. package/dist/scp/write-plan.d.ts +0 -161
  157. package/dist/scp/write-plan.d.ts.map +0 -1
  158. package/dist/scp/write-plan.js +0 -528
  159. package/dist/scp/write-plan.js.map +0 -1
  160. package/dist/scp/write-runtime.d.ts +0 -80
  161. package/dist/scp/write-runtime.d.ts.map +0 -1
  162. package/dist/scp/write-runtime.js +0 -167
  163. package/dist/scp/write-runtime.js.map +0 -1
@@ -0,0 +1,99 @@
1
+ /**
2
+ * litedbmodel v2 SCP — the LOCKED minimal bc integration: ONE catalog component
3
+ * **`makeSQL(sql, params, skip?)`** (a behavior-contracts catalog leaf, exactly like
4
+ * graphddb's `GetItem`/`Query`).
5
+ *
6
+ * ## The locked model (owner-specified — nothing else exists)
7
+ *
8
+ * - bc integration = ONE catalog component `makeSQL`. Ports:
9
+ * - `sql` — tuned dialect SQL text (a string; `?` placeholders).
10
+ * - `params` — value list. Each element is EITHER a bound value (an opaque SQL
11
+ * value: number/string/bool/null/Date/array/…) OR a **nested
12
+ * `makeSQL`** (a `{ sql, params, skip? }` object) whose `sql` is
13
+ * spliced at the corresponding `?` and whose params flow inline.
14
+ * A subquery / sub-expression is a nested `makeSQL` in a param slot.
15
+ * - `skip?` — presence condition. When satisfied, the component contributes
16
+ * NOTHING (its `sql` and its `params` both drop).
17
+ * - A query = a composition of `makeSQL` components. bc composes; present ones
18
+ * concatenate. There is NO relation-op / operator / "kind" for SQL structure.
19
+ * - `= ANY`, `CROSS JOIN LATERAL`, `UNNEST`, cast, subquery, batch shapes are ALL
20
+ * TEXT inside `sql`. Never modeled.
21
+ * - An array/rows param binds as ONE value with STATIC text on EVERY dialect
22
+ * (epic #43/#45): PostgreSQL `= ANY(?::t[])` / `UNNEST`, MySQL/SQLite a single JSON
23
+ * param expanded server-side (`MEMBER OF` / `JSON_TABLE` / `json_each`). There is no
24
+ * array placeholder-count-expansion anywhere anymore.
25
+ *
26
+ * litedbmodel supplies (spec §11): the `makeSQL` catalog entry, its **handler**
27
+ * (bind params → execute SQL), and the **compile** step that emits the tuned dialect
28
+ * SQL text (by REUSING the original tuned builders — see `compile-*.ts`). bc supplies
29
+ * composition / value-eval / envelope / plan (it comes free once queries are `makeSQL`
30
+ * components). The bundle stays pure JSON (multi-language ready).
31
+ */
32
+ import type { CatalogEntry } from 'behavior-contracts';
33
+ /** The single catalog leaf name. Everything SQL is a `makeSQL`. */
34
+ export declare const MAKESQL: "makeSQL";
35
+ /**
36
+ * A bound SQL param value OR a nested `makeSQL` (subquery / sub-expression).
37
+ *
38
+ * A nested `makeSQL` in a param slot is how subqueries are represented: its `sql`
39
+ * splices into the parent's `?` position and its params flow into the parent's param
40
+ * stream in order. This is the ONLY recursion; there is no other SQL-structure
41
+ * vocabulary.
42
+ */
43
+ export type SqlParam = unknown | MakeSQL;
44
+ /**
45
+ * The `makeSQL` port bundle — the ONLY structural type.
46
+ *
47
+ * `sql` is complete tuned SQL text with `?` placeholders (leading connector included
48
+ * where the composition needs it, exactly as the original builder emits). `params`
49
+ * are 1:1 with the top-level `?` (a bound value fills one `?`; a nested `makeSQL`
50
+ * param splices its own `sql`, which may contain further `?`). `skip`, when `true`,
51
+ * omits the whole component (sql AND params).
52
+ */
53
+ export interface MakeSQL {
54
+ sql: string;
55
+ params: SqlParam[];
56
+ /** Presence condition already resolved to a boolean at bind/eval time. */
57
+ skip?: boolean;
58
+ }
59
+ /** Structural guard: a nested-`makeSQL` param has a string `sql`; a bound value does not. */
60
+ export declare function isMakeSQL(p: SqlParam): p is MakeSQL;
61
+ /**
62
+ * The `makeSQL` catalog entry (bc `CatalogEntry`). A leaf Specialty Component: name +
63
+ * Port contract + output shape. The handler implementation is separate (see
64
+ * `handler.ts`) — the IR carries only the reference name + port wiring (C4).
65
+ *
66
+ * `params` is a dynamic-arity port family (the value list length is query-specific),
67
+ * so `additionalPorts` is not needed: `params` is a single arr-typed port, `sql` a
68
+ * string, `skip` an optional bool. `output.shape = 'items'` (a SELECT yields rows; a
69
+ * write yields RETURNING rows or `[]`).
70
+ */
71
+ export declare const makeSqlCatalogEntry: CatalogEntry;
72
+ /** The litedbmodel catalog — a single leaf, `makeSQL`. */
73
+ export declare const LITEDBMODEL_MAKESQL_CATALOG: Record<string, CatalogEntry>;
74
+ /** A fully-assembled statement: complete SQL text (`?`) + a flat ordered value list. */
75
+ export interface AssembledSql {
76
+ sql: string;
77
+ params: unknown[];
78
+ }
79
+ /**
80
+ * Assemble one `makeSQL` into `{ sql, params }`.
81
+ *
82
+ * - If `skip` is true, this component contributes nothing: returns empty text + no
83
+ * params (the caller composes over the survivors).
84
+ * - Otherwise interleave the literal `sql` (split on `?`) with each param: a bound
85
+ * value emits a single `?` and contributes its value; a nested `makeSQL` splices
86
+ * its assembled `sql` and contributes its assembled params (recursively). A nested
87
+ * `makeSQL` that is itself skipped contributes empty text + no params.
88
+ */
89
+ export declare function assembleMakeSQL(node: MakeSQL): AssembledSql;
90
+ /**
91
+ * Compose an ordered list of `makeSQL` components into one statement: concatenate the
92
+ * assembled `sql` of every PRESENT component and their params in order (the locked
93
+ * model's "present ones concatenate"). Skipped components drop entirely.
94
+ *
95
+ * Each component's `sql` already carries whatever connector text the tuned builder
96
+ * emits for that position, so concatenation is byte-faithful for every skip subset.
97
+ */
98
+ export declare function composeMakeSQL(nodes: MakeSQL[]): AssembledSql;
99
+ //# sourceMappingURL=makesql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"makesql.d.ts","sourceRoot":"","sources":["../../../src/scp/makesql/makesql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,mEAAmE;AACnE,eAAO,MAAM,OAAO,EAAG,SAAkB,CAAC;AAE1C;;;;;;;GAOG;AACH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC;AAEzC;;;;;;;;GAQG;AACH,MAAM,WAAW,OAAO;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,QAAQ,EAAE,CAAC;IACnB,0EAA0E;IAC1E,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,6FAA6F;AAC7F,wBAAgB,SAAS,CAAC,CAAC,EAAE,QAAQ,GAAG,CAAC,IAAI,OAAO,CAOnD;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,EAAE,YASjC,CAAC;AAEF,0DAA0D;AAC1D,eAAO,MAAM,2BAA2B,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAEpE,CAAC;AAWF,wFAAwF;AACxF,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,OAAO,EAAE,CAAC;CACnB;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,YAAY,CAwB3D;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,YAAY,CAS7D"}
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ /**
3
+ * litedbmodel v2 SCP — the LOCKED minimal bc integration: ONE catalog component
4
+ * **`makeSQL(sql, params, skip?)`** (a behavior-contracts catalog leaf, exactly like
5
+ * graphddb's `GetItem`/`Query`).
6
+ *
7
+ * ## The locked model (owner-specified — nothing else exists)
8
+ *
9
+ * - bc integration = ONE catalog component `makeSQL`. Ports:
10
+ * - `sql` — tuned dialect SQL text (a string; `?` placeholders).
11
+ * - `params` — value list. Each element is EITHER a bound value (an opaque SQL
12
+ * value: number/string/bool/null/Date/array/…) OR a **nested
13
+ * `makeSQL`** (a `{ sql, params, skip? }` object) whose `sql` is
14
+ * spliced at the corresponding `?` and whose params flow inline.
15
+ * A subquery / sub-expression is a nested `makeSQL` in a param slot.
16
+ * - `skip?` — presence condition. When satisfied, the component contributes
17
+ * NOTHING (its `sql` and its `params` both drop).
18
+ * - A query = a composition of `makeSQL` components. bc composes; present ones
19
+ * concatenate. There is NO relation-op / operator / "kind" for SQL structure.
20
+ * - `= ANY`, `CROSS JOIN LATERAL`, `UNNEST`, cast, subquery, batch shapes are ALL
21
+ * TEXT inside `sql`. Never modeled.
22
+ * - An array/rows param binds as ONE value with STATIC text on EVERY dialect
23
+ * (epic #43/#45): PostgreSQL `= ANY(?::t[])` / `UNNEST`, MySQL/SQLite a single JSON
24
+ * param expanded server-side (`MEMBER OF` / `JSON_TABLE` / `json_each`). There is no
25
+ * array placeholder-count-expansion anywhere anymore.
26
+ *
27
+ * litedbmodel supplies (spec §11): the `makeSQL` catalog entry, its **handler**
28
+ * (bind params → execute SQL), and the **compile** step that emits the tuned dialect
29
+ * SQL text (by REUSING the original tuned builders — see `compile-*.ts`). bc supplies
30
+ * composition / value-eval / envelope / plan (it comes free once queries are `makeSQL`
31
+ * components). The bundle stays pure JSON (multi-language ready).
32
+ */
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ exports.LITEDBMODEL_MAKESQL_CATALOG = exports.makeSqlCatalogEntry = exports.MAKESQL = void 0;
35
+ exports.isMakeSQL = isMakeSQL;
36
+ exports.assembleMakeSQL = assembleMakeSQL;
37
+ exports.composeMakeSQL = composeMakeSQL;
38
+ /** The single catalog leaf name. Everything SQL is a `makeSQL`. */
39
+ exports.MAKESQL = 'makeSQL';
40
+ /** Structural guard: a nested-`makeSQL` param has a string `sql`; a bound value does not. */
41
+ function isMakeSQL(p) {
42
+ return (typeof p === 'object' &&
43
+ p !== null &&
44
+ typeof p.sql === 'string' &&
45
+ Array.isArray(p.params));
46
+ }
47
+ /**
48
+ * The `makeSQL` catalog entry (bc `CatalogEntry`). A leaf Specialty Component: name +
49
+ * Port contract + output shape. The handler implementation is separate (see
50
+ * `handler.ts`) — the IR carries only the reference name + port wiring (C4).
51
+ *
52
+ * `params` is a dynamic-arity port family (the value list length is query-specific),
53
+ * so `additionalPorts` is not needed: `params` is a single arr-typed port, `sql` a
54
+ * string, `skip` an optional bool. `output.shape = 'items'` (a SELECT yields rows; a
55
+ * write yields RETURNING rows or `[]`).
56
+ */
57
+ exports.makeSqlCatalogEntry = {
58
+ name: exports.MAKESQL,
59
+ inputPorts: {
60
+ sql: { type: 'string', required: true },
61
+ params: { type: 'arr' },
62
+ skip: { type: 'bool' },
63
+ },
64
+ output: { shape: 'items' },
65
+ portableToIR: true,
66
+ };
67
+ /** The litedbmodel catalog — a single leaf, `makeSQL`. */
68
+ exports.LITEDBMODEL_MAKESQL_CATALOG = {
69
+ [exports.MAKESQL]: exports.makeSqlCatalogEntry,
70
+ };
71
+ /**
72
+ * Assemble one `makeSQL` into `{ sql, params }`.
73
+ *
74
+ * - If `skip` is true, this component contributes nothing: returns empty text + no
75
+ * params (the caller composes over the survivors).
76
+ * - Otherwise interleave the literal `sql` (split on `?`) with each param: a bound
77
+ * value emits a single `?` and contributes its value; a nested `makeSQL` splices
78
+ * its assembled `sql` and contributes its assembled params (recursively). A nested
79
+ * `makeSQL` that is itself skipped contributes empty text + no params.
80
+ */
81
+ function assembleMakeSQL(node) {
82
+ if (node.skip === true)
83
+ return { sql: '', params: [] };
84
+ const chunks = node.sql.split('?');
85
+ if (chunks.length - 1 !== node.params.length) {
86
+ throw new Error(`makeSQL placeholder/param mismatch: ${chunks.length - 1} '?' vs ${node.params.length} params in ${JSON.stringify(node.sql)}`);
87
+ }
88
+ let sql = chunks[0];
89
+ const params = [];
90
+ for (let i = 0; i < node.params.length; i++) {
91
+ const p = node.params[i];
92
+ if (isMakeSQL(p)) {
93
+ const inner = assembleMakeSQL(p);
94
+ sql += inner.sql + chunks[i + 1];
95
+ params.push(...inner.params);
96
+ }
97
+ else {
98
+ sql += '?' + chunks[i + 1];
99
+ params.push(p);
100
+ }
101
+ }
102
+ return { sql, params };
103
+ }
104
+ /**
105
+ * Compose an ordered list of `makeSQL` components into one statement: concatenate the
106
+ * assembled `sql` of every PRESENT component and their params in order (the locked
107
+ * model's "present ones concatenate"). Skipped components drop entirely.
108
+ *
109
+ * Each component's `sql` already carries whatever connector text the tuned builder
110
+ * emits for that position, so concatenation is byte-faithful for every skip subset.
111
+ */
112
+ function composeMakeSQL(nodes) {
113
+ let sql = '';
114
+ const params = [];
115
+ for (const node of nodes) {
116
+ const r = assembleMakeSQL(node);
117
+ sql += r.sql;
118
+ params.push(...r.params);
119
+ }
120
+ return { sql, params };
121
+ }
122
+ //# sourceMappingURL=makesql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"makesql.js","sourceRoot":"","sources":["../../../src/scp/makesql/makesql.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;;;AAkCH,8BAOC;AAqDD,0CAwBC;AAUD,wCASC;AArID,mEAAmE;AACtD,QAAA,OAAO,GAAG,SAAkB,CAAC;AA4B1C,6FAA6F;AAC7F,SAAgB,SAAS,CAAC,CAAW;IACnC,OAAO,CACL,OAAO,CAAC,KAAK,QAAQ;QACrB,CAAC,KAAK,IAAI;QACV,OAAQ,CAAa,CAAC,GAAG,KAAK,QAAQ;QACtC,KAAK,CAAC,OAAO,CAAE,CAAa,CAAC,MAAM,CAAC,CACrC,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACU,QAAA,mBAAmB,GAAiB;IAC/C,IAAI,EAAE,eAAO;IACb,UAAU,EAAE;QACV,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE;QACvC,MAAM,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE;QACvB,IAAI,EAAE,EAAE,IAAI,EAAE,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AAM,CAAC,CAAC;QAC/B,CAAC;aAAM,CAAC;YACN,GAAG,IAAI,GAAG,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAC3B,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACjB,CAAC;IACH,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;AACzB,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,KAAgB;IAC7C,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,MAAM,MAAM,GAAc,EAAE,CAAC;IAC7B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,CAAC,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;QAChC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC;QACb,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;AACzB,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * litedbmodel v2 SCP — codegen `outType` derivation (spec §4.1; issues #58/#56).
3
+ *
4
+ * bc's TYPED-RAW de-box emitters (`rust-typed-raw` / `go-typed-raw` / `typescript-typed`) require
5
+ * each read node to carry an `outType` and the component an `outputType` (bc portable type
6
+ * notation). WITHOUT them the emitter hard-fails ("nothing to de-box") — the correct fail-closed
7
+ * behavior. This module derives those annotations for a READ component from:
8
+ *
9
+ * 1. the per-node SELECT projection (`table` + `select` ports) → a row `obj` type, each column's
10
+ * bc scalar resolved from its SQL type (the schema/DDL SoT) via {@link sqlTypeToBcScalar};
11
+ * 2. the node cardinality (a Select node returns a row LIST → `{arr:rowObj}`; a Count → `int`; a
12
+ * `.map` node wraps its per-element handler result → `{arr:<elem>}`);
13
+ * 3. the component `output` Φ-expression, walked to compose the `outputType` from the node types
14
+ * (`{ref:[nodeId]}` → that node's outType; `{obj:{…}}`/`{arr:…}`/`{opt:…}` recurse).
15
+ *
16
+ * Spec §4.1 discipline: an ambiguous/unmappable projection is a HARD ERROR (no-assume,
17
+ * no-fallback) — a `*` projection, a computed/aliased column, or a column with no schema type
18
+ * THROWS. It is NEVER degraded to a boxed/untyped output; that would silently defeat the de-box.
19
+ */
20
+ import type { PortableType } from 'behavior-contracts';
21
+ import type { Component, ComponentRefNode, MapNode } from '../authoring';
22
+ import { type ColumnTypeResolver } from '../coltype';
23
+ /** A body node that is a component ref or a map (a cond node has no SELECT projection). */
24
+ type RefLike = ComponentRefNode | MapNode;
25
+ /**
26
+ * The `outType` of ONE read body node. A `Select` returns a ROW LIST → `{arr:rowObj}`. A `Count`
27
+ * returns a single `int`. A `.map` node runs its inner component PER element of the iterated list,
28
+ * so its result is `{arr:<per-element outType>}` (the per-element type being the inner node's own
29
+ * outType — for a `.map` over a Select-per-element that is `{arr:{arr:rowObj}}`). An unrecognized
30
+ * component throws (typed codegen covers only the SQL read catalog).
31
+ */
32
+ export declare function nodeOutType(node: RefLike, resolveColumnType: ColumnTypeResolver): PortableType;
33
+ /**
34
+ * Per-node `outType` (keyed by body node id) + the component `outputType`, derived for a READ
35
+ * component (spec §4.1). `cond` nodes are skipped for the per-node map but a `cond` at the OUTPUT
36
+ * position (a shared-branch merge) would be handled by {@link outputType} if reached — the bench's
37
+ * read outputs are ref / obj compositions of Select nodes. Any ambiguity throws (fail-closed).
38
+ */
39
+ export declare function deriveReadOutTypes(component: Component, resolveColumnType: ColumnTypeResolver): {
40
+ byNode: Map<string, PortableType>;
41
+ outputType: PortableType;
42
+ };
43
+ export {};
44
+ //# sourceMappingURL=outtype.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outtype.d.ts","sourceRoot":"","sources":["../../../src/scp/makesql/outtype.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAsB,MAAM,oBAAoB,CAAC;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACzE,OAAO,EAAoC,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAcvF,2FAA2F;AAC3F,KAAK,OAAO,GAAG,gBAAgB,GAAG,OAAO,CAAC;AAwE1C;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,GAAG,YAAY,CAmB9F;AAwDD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,SAAS,EACpB,iBAAiB,EAAE,kBAAkB,GACpC;IAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAAC,UAAU,EAAE,YAAY,CAAA;CAAE,CAOjE"}
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ /**
3
+ * litedbmodel v2 SCP — codegen `outType` derivation (spec §4.1; issues #58/#56).
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:
9
+ *
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).
16
+ *
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.
20
+ */
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.nodeOutType = nodeOutType;
23
+ exports.deriveReadOutTypes = deriveReadOutTypes;
24
+ const coltype_1 = require("../coltype");
25
+ const tx_1 = require("./tx");
26
+ /**
27
+ * Narrow a {@link BcScalar} to a bc {@link PortableScalarType}. `BcScalar`'s members
28
+ * (`string|int|float|bool|null`) are exactly bc 0.3.0's portable scalar notation, so this is an
29
+ * identity narrow. DATE/TIMESTAMP columns map to `string` at the `sqlTypeToBcScalar` layer (spec
30
+ * §4.1 owner decision; bc has no `date` scalar — behavior-contracts#84 deferred), so no `date`
31
+ * scalar ever reaches here.
32
+ */
33
+ function toPortableScalar(scalar, _table, _column) {
34
+ return scalar;
35
+ }
36
+ function isMap(n) {
37
+ return 'map' in n;
38
+ }
39
+ /** The `{component, ports}` of a body node (unwrapping a `.map`). */
40
+ function nodeRef(n) {
41
+ return isMap(n) ? { component: n.map.component, ports: n.map.ports } : { component: n.component, ports: n.ports };
42
+ }
43
+ function opKey(node) {
44
+ if (node === null || typeof node !== 'object' || Array.isArray(node))
45
+ return undefined;
46
+ const keys = Object.keys(node);
47
+ return keys.length === 1 ? keys[0] : undefined;
48
+ }
49
+ /** Read a required literal string port, or throw (the projection SoT must be a literal in the IR). */
50
+ function stringPort(ports, name) {
51
+ const v = ports[name];
52
+ if (v === undefined)
53
+ return undefined;
54
+ if (typeof v !== 'string') {
55
+ throw new Error(`outtype: port '${name}' must be a literal string in the IR (got ${JSON.stringify(v)})`);
56
+ }
57
+ return v;
58
+ }
59
+ /** Read a literal `{arr:[str,…]}` string-list port (the SELECT projection). */
60
+ function stringArrayPort(ports, name) {
61
+ const v = ports[name];
62
+ if (v === undefined)
63
+ return undefined;
64
+ if (typeof v === 'object' && v !== null && 'arr' in v && Array.isArray(v.arr)) {
65
+ return v.arr.map((e) => {
66
+ if (typeof e !== 'string')
67
+ throw new Error(`outtype: '${name}' entries must be literal strings (got ${JSON.stringify(e)})`);
68
+ return e;
69
+ });
70
+ }
71
+ throw new Error(`outtype: port '${name}' must be an {arr:[…]} literal in the IR (got ${JSON.stringify(v)})`);
72
+ }
73
+ /**
74
+ * The row `obj` type of a SELECT projection: `{obj:{col: <bcScalar>, …}}`. Each column is typed by
75
+ * resolving its SQL type from the schema SoT and mapping via {@link sqlTypeToBcScalar}. A `*` or
76
+ * absent projection, a computed/aliased/qualified column, or a duplicate column is a HARD ERROR —
77
+ * such a projection cannot be de-boxed into a concrete struct (no-assume, no-fallback).
78
+ */
79
+ function rowObjType(table, projection, resolveColumnType, at) {
80
+ if (projection === undefined || projection.length === 0) {
81
+ throw new Error(`outtype: ${at}: SELECT on '${table}' has no explicit column projection ('*' / empty). A typed ` +
82
+ `de-box needs the concrete column list to build the row struct — spec §4.1 is column-typed. ` +
83
+ `Project explicit columns (no-assume, no-fallback).`);
84
+ }
85
+ const obj = {};
86
+ for (const col of projection) {
87
+ // Reject anything that is not a bare column name — an alias (`x AS y`), a qualified name
88
+ // (`t.c`), or a computed expression cannot be typed from the schema alone.
89
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(col)) {
90
+ throw new Error(`outtype: ${at}: projected column '${col}' on '${table}' is not a bare column name (alias / ` +
91
+ `qualified / computed). Typed de-box (spec §4.1) requires bare schema columns so each maps ` +
92
+ `to a SQL type. No-assume, no-fallback.`);
93
+ }
94
+ if (col in obj)
95
+ throw new Error(`outtype: ${at}: duplicate projected column '${col}' on '${table}'`);
96
+ // sqlTypeToBcScalar throws on an unknown/ambiguous SQL type — fail-closed by construction.
97
+ obj[col] = toPortableScalar((0, coltype_1.sqlTypeToBcScalar)(resolveColumnType(table, col)), table, col);
98
+ }
99
+ return { obj };
100
+ }
101
+ /**
102
+ * The `outType` of ONE read body node. A `Select` returns a ROW LIST → `{arr:rowObj}`. A `Count`
103
+ * returns a single `int`. A `.map` node runs its inner component PER element of the iterated list,
104
+ * so its result is `{arr:<per-element outType>}` (the per-element type being the inner node's own
105
+ * outType — for a `.map` over a Select-per-element that is `{arr:{arr:rowObj}}`). An unrecognized
106
+ * component throws (typed codegen covers only the SQL read catalog).
107
+ */
108
+ function nodeOutType(node, resolveColumnType) {
109
+ const { component, ports } = nodeRef(node);
110
+ const at = `node '${node.id}'`;
111
+ if (component === 'Count')
112
+ return 'int';
113
+ if (component === 'Select') {
114
+ const table = stringPort(ports, 'table');
115
+ if (table === undefined)
116
+ throw new Error(`outtype: ${at}: Select node requires a literal 'table' port`);
117
+ const projection = stringArrayPort(ports, 'select');
118
+ const row = rowObjType(table, projection, resolveColumnType, at);
119
+ // A `.map` node iterates a list and invokes the inner component per element; the node result is
120
+ // the list of per-element results. Here the inner is a Select → per element a row LIST, so the
121
+ // map node's outType is `{arr:{arr:rowObj}}`. A non-map Select node returns the row list `{arr:rowObj}`.
122
+ if (isMap(node))
123
+ return { arr: { arr: row } };
124
+ return { arr: row };
125
+ }
126
+ throw new Error(`outtype: ${at}: component '${component}' has no typed outType (typed read codegen covers Select/Count only). ` +
127
+ `A write / unknown node cannot be de-boxed here — no-assume, no-fallback.`);
128
+ }
129
+ /**
130
+ * Derive the component `outputType` by walking the `output` Φ-expression against a `nodeId →
131
+ * outType` map. `{ref:[id]}` resolves to that node's outType; `{obj:{k:expr,…}}` /
132
+ * `{arr:expr}` / `{opt:expr}` recurse structurally. A `ref` to an unknown id, or an operator the
133
+ * typed output path does not cover, is a HARD ERROR (no-assume, no-fallback) — the output must be
134
+ * a pure composition of typed node results, never a boxed dynamic tree.
135
+ */
136
+ function outputType(output, byNode, at) {
137
+ const op = opKey(output);
138
+ if (op === 'ref' || op === 'refOpt') {
139
+ const path = output[op];
140
+ if (!Array.isArray(path) || path.length === 0 || typeof path[0] !== 'string') {
141
+ throw new Error(`outtype: ${at}: a '${op}' output must reference a node id`);
142
+ }
143
+ // A node-result ref is a single-segment path `[nodeId]`. A deeper path (field access on a node
144
+ // result) cannot be typed here without walking into the row struct — out of the bench's scope.
145
+ if (path.length !== 1 || path[0].startsWith('$') || path[0] === tx_1.IN_SENTINEL) {
146
+ throw new Error(`outtype: ${at}: output ref path ${JSON.stringify(path)} is not a bare node-result reference; ` +
147
+ `field access / input refs at the output position are not supported by the typed de-box path. No-assume, no-fallback.`);
148
+ }
149
+ const t = byNode.get(path[0]);
150
+ if (t === undefined)
151
+ throw new Error(`outtype: ${at}: output references node '${path[0]}' which has no derived outType`);
152
+ return t;
153
+ }
154
+ if (op === 'obj') {
155
+ const obj = output.obj;
156
+ if (obj === null || typeof obj !== 'object' || Array.isArray(obj))
157
+ throw new Error(`outtype: ${at}: 'obj' output must be a record`);
158
+ const out = {};
159
+ for (const [k, expr] of Object.entries(obj)) {
160
+ if (k === '__proto__')
161
+ throw new Error(`outtype: ${at}: '__proto__' key forbidden in output obj`);
162
+ out[k] = outputType(expr, byNode, `${at}.obj.${k}`);
163
+ }
164
+ return { obj: out };
165
+ }
166
+ if (op === 'arr') {
167
+ const arr = output.arr;
168
+ // An `{arr:<expr>}` output whose single element expr types the element (the typed corpus uses
169
+ // homogeneous arrays). An `{arr:[…]}` literal list is not a typed homogeneous array here.
170
+ if (Array.isArray(arr))
171
+ throw new Error(`outtype: ${at}: an '{arr:[…]}' literal list output cannot be typed as a homogeneous array. No-assume, no-fallback.`);
172
+ return { arr: outputType(arr, byNode, `${at}.arr`) };
173
+ }
174
+ if (op === 'opt') {
175
+ const inner = output.opt;
176
+ return { opt: outputType(inner, byNode, `${at}.opt`) };
177
+ }
178
+ throw new Error(`outtype: ${at}: output expression ${JSON.stringify(output)} is not a typed composition ` +
179
+ `(ref / obj / arr / opt of node results). The typed de-box path does not build a dynamic ` +
180
+ `Value output tree — no-assume, no-fallback.`);
181
+ }
182
+ /**
183
+ * Per-node `outType` (keyed by body node id) + the component `outputType`, derived for a READ
184
+ * component (spec §4.1). `cond` nodes are skipped for the per-node map but a `cond` at the OUTPUT
185
+ * position (a shared-branch merge) would be handled by {@link outputType} if reached — the bench's
186
+ * read outputs are ref / obj compositions of Select nodes. Any ambiguity throws (fail-closed).
187
+ */
188
+ function deriveReadOutTypes(component, resolveColumnType) {
189
+ const byNode = new Map();
190
+ for (const n of component.body) {
191
+ if ('cond' in n)
192
+ continue; // a cond node carries no SELECT projection; it is typed by its branch
193
+ byNode.set(n.id, nodeOutType(n, resolveColumnType));
194
+ }
195
+ return { byNode, outputType: outputType(component.output, byNode, `component '${component.name}' output`) };
196
+ }
197
+ //# sourceMappingURL=outtype.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outtype.js","sourceRoot":"","sources":["../../../src/scp/makesql/outtype.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;AAkGH,kCAmBC;AA8DD,gDAUC;AAzLD,wCAAuF;AACvF,6BAAmC;AAEnC;;;;;;GAMG;AACH,SAAS,gBAAgB,CAAC,MAAgB,EAAE,MAAc,EAAE,OAAe;IACzE,OAAO,MAAM,CAAC;AAChB,CAAC;AAKD,SAAS,KAAK,CAAC,CAA4B;IACzC,OAAO,KAAK,IAAI,CAAC,CAAC;AACpB,CAAC;AAED,qEAAqE;AACrE,SAAS,OAAO,CAAC,CAAU;IACzB,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;AACpH,CAAC;AAED,SAAS,KAAK,CAAC,IAAa;IAC1B,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,OAAO,SAAS,CAAC;IACvF,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAc,CAAC,CAA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Async`) dispatches independent sibling
5
+ * relations in bounded parallel via bc `runBehaviorAsync`. For that concurrency to become REAL
6
+ * parallel DB I/O the driver seam must be an async CONNECTION POOL — each concurrent `exec` call
7
+ * checks out a DISTINCT pooled connection. These factories adapt a `pg.Pool` / `mysql2` pool to the
8
+ * {@link SqlExecutorAsync} seam.
9
+ *
10
+ * The read graph already renders the dialect placeholder form (`$N` for postgres, `?` for
11
+ * MySQL/SQLite, via `renderPlaceholders`) and flattens params 1:1, so each executor is a THIN
12
+ * adapter — it passes the already-rendered `{ sql, params }` straight to the pool. The pool sizing
13
+ * should be aligned with the plan's `concurrency` (default 16) so `concurrency` sibling relations
14
+ * can each hold a live connection without queueing.
15
+ *
16
+ * `pg` / `mysql2` are optional peer dependencies loaded dynamically — importing this module does not
17
+ * force either into a consumer that only uses the sync better-sqlite3 conformance path.
18
+ */
19
+ import type { SqlExecutorAsync } from './static-bundle';
20
+ /** The minimal `pg.Pool` surface we need: `query(text, values)` resolving `{ rows }`. */
21
+ export interface PgPoolLike {
22
+ query(text: string, values?: unknown[]): Promise<{
23
+ rows: Record<string, unknown>[];
24
+ }>;
25
+ }
26
+ /** The minimal `mysql2/promise` pool surface: `query(sql, values)` resolving `[rows, fields]`. */
27
+ export interface MysqlPoolLike {
28
+ query(sql: string, values?: unknown[]): Promise<[Record<string, unknown>[], unknown]>;
29
+ }
30
+ /**
31
+ * Adapt a `pg.Pool` to the async executor seam. Each `exec` runs `pool.query`, which acquires a
32
+ * pooled connection, runs the query, and releases it — so N concurrent siblings run on N pooled
33
+ * connections in parallel. The graph renders `$N` placeholders for the `postgres` dialect, so the
34
+ * `sql` is already in `pg`'s native form.
35
+ *
36
+ * Recommend constructing the pool with `max` ≥ the plan's `concurrency` (default 16).
37
+ */
38
+ export declare function pgPoolExecutor(pool: PgPoolLike): SqlExecutorAsync;
39
+ /**
40
+ * Adapt a `mysql2/promise` pool to the async executor seam. `pool.query` acquires + releases a
41
+ * pooled connection per call, so concurrent siblings run in parallel. The graph renders `?`
42
+ * placeholders for the `mysql` dialect — `mysql2`'s native form.
43
+ *
44
+ * Recommend `connectionLimit` ≥ the plan's `concurrency` (default 16).
45
+ */
46
+ export declare function mysqlPoolExecutor(pool: MysqlPoolLike): SqlExecutorAsync;
47
+ //# sourceMappingURL=pool-executor.d.ts.map
@@ -0,0 +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;AAExD,yFAAyF;AACzF,MAAM,WAAW,UAAU;IACzB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;KAAE,CAAC,CAAC;CACvF;AAED,kGAAkG;AAClG,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;CACvF;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,GAAG,gBAAgB,CAKjE;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,aAAa,GAAG,gBAAgB,CAKvE"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ /**
3
+ * litedbmodel v2 SCP — pooled async `SqlExecutorAsync` factories for PG / MySQL (#40).
4
+ *
5
+ * The read-graph async execution model (`executeReadGraphAsync`) dispatches independent sibling
6
+ * relations in bounded parallel via bc `runBehaviorAsync`. For that concurrency to become REAL
7
+ * parallel DB I/O the driver seam must be an async CONNECTION POOL — each concurrent `exec` call
8
+ * checks out a DISTINCT pooled connection. These factories adapt a `pg.Pool` / `mysql2` pool to the
9
+ * {@link SqlExecutorAsync} seam.
10
+ *
11
+ * The read graph already renders the dialect placeholder form (`$N` for postgres, `?` for
12
+ * MySQL/SQLite, via `renderPlaceholders`) and flattens params 1:1, so each executor is a THIN
13
+ * adapter — it passes the already-rendered `{ sql, params }` straight to the pool. The pool sizing
14
+ * should be aligned with the plan's `concurrency` (default 16) so `concurrency` sibling relations
15
+ * can each hold a live connection without queueing.
16
+ *
17
+ * `pg` / `mysql2` are optional peer dependencies loaded dynamically — importing this module does not
18
+ * force either into a consumer that only uses the sync better-sqlite3 conformance path.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.pgPoolExecutor = pgPoolExecutor;
22
+ exports.mysqlPoolExecutor = mysqlPoolExecutor;
23
+ /**
24
+ * Adapt a `pg.Pool` to the async executor seam. Each `exec` runs `pool.query`, which acquires a
25
+ * pooled connection, runs the query, and releases it — so N concurrent siblings run on N pooled
26
+ * connections in parallel. The graph renders `$N` placeholders for the `postgres` dialect, so the
27
+ * `sql` is already in `pg`'s native form.
28
+ *
29
+ * Recommend constructing the pool with `max` ≥ the plan's `concurrency` (default 16).
30
+ */
31
+ function pgPoolExecutor(pool) {
32
+ return async (sql, params) => {
33
+ const result = await pool.query(sql, params);
34
+ return result.rows;
35
+ };
36
+ }
37
+ /**
38
+ * Adapt a `mysql2/promise` pool to the async executor seam. `pool.query` acquires + releases a
39
+ * pooled connection per call, so concurrent siblings run in parallel. The graph renders `?`
40
+ * placeholders for the `mysql` dialect — `mysql2`'s native form.
41
+ *
42
+ * Recommend `connectionLimit` ≥ the plan's `concurrency` (default 16).
43
+ */
44
+ function mysqlPoolExecutor(pool) {
45
+ return async (sql, params) => {
46
+ const [rows] = await pool.query(sql, params);
47
+ return rows;
48
+ };
49
+ }
50
+ //# sourceMappingURL=pool-executor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pool-executor.js","sourceRoot":"","sources":["../../../src/scp/makesql/pool-executor.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;AAsBH,wCAKC;AASD,8CAKC;AA3BD;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAC,IAAgB;IAC7C,OAAO,KAAK,EAAE,GAAW,EAAE,MAAiB,EAAsC,EAAE;QAClF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC7C,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAAC,IAAmB;IACnD,OAAO,KAAK,EAAE,GAAW,EAAE,MAAiB,EAAsC,EAAE;QAClF,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAC7C,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC"}