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,95 +0,0 @@
1
- /**
2
- * litedbmodel v2 SCP catalog — WS1 (#21).
3
- *
4
- * `LITEDBMODEL_CATALOG` is the behavior-contracts–typed `Catalog` that IS the whole
5
- * per-DSL difference litedbmodel supplies as a SQL-backend consumer (bc C2: "the only
6
- * per-DSL difference is the catalog"). It mirrors the SHAPE of graphddb's
7
- * `GRAPHDDB_CATALOG` (`src/spec/catalog.ts`) exactly: compact `PortSchema` constructors,
8
- * an `entry()` helper, per-primitive `inputPorts`, an `output.shape`, and a
9
- * `portableToIR` flag. The effect implementation (SQL execution + row→model assembly) is
10
- * bound separately in the handler registry (WS3, C4 — catalog declares, registry binds).
11
- *
12
- * ## Catalog names (spec §1 / §11 item 1)
13
- *
14
- * `Select` / `Insert` / `Update` / `Delete` are the CRUD leaf components. `Fragment` is
15
- * the dynamic WHERE/SET fragment-tree component (SKIP → fragment existence rules, §8);
16
- * `Tx` is the multi-statement transaction envelope. As in graphddb, the transaction
17
- * envelope (`Tx`) is `portableToIR: false` — a transaction is emitted as a Component
18
- * whose body references the per-statement CRUD primitives; the atomic BEGIN/COMMIT
19
- * envelope is the runtime's execution concern (WS3), never a portable-IR node.
20
- *
21
- * ## Port schema conventions
22
- *
23
- * A `CatalogEntry.inputPorts` names the STATIC ports of the emitted wiring. Two families
24
- * are dynamic by construction and are validated by {@link assertComponentsInCatalog}
25
- * against documented patterns instead of being statically enumerable:
26
- *
27
- * - **`where`/`set`/`values` records**: one port per model field, flattened one-port-
28
- * per-field under a `<group>.<field>` key ({@link WRITE_PORT_FAMILIES}). These carry
29
- * Expression IR (the field's value/condition), from the closed operator set only.
30
- *
31
- * The CRUD entries carry `additionalPorts: true` (bc#26) so bc's shared port check
32
- * (`checkPortNames` / `buildComponentDefinition`) accepts the dynamic families; every
33
- * DECLARED port keeps bc's required/type checks regardless of the opt-in. `Tx`'s single
34
- * port is static, so it keeps bc's fail-closed default.
35
- */
36
- import { type Catalog, type CatalogEntry } from 'behavior-contracts';
37
- import type { Component } from './authoring';
38
- /**
39
- * The catalog-name literal union — one entry per SQL primitive litedbmodel declares:
40
- * the CRUD leaves (`Select` / `Insert` / `Update` / `Delete`), the dynamic WHERE/SET
41
- * fragment-tree component (`Fragment`), and the multi-statement transaction envelope
42
- * (`Tx`).
43
- */
44
- export type CatalogName = 'Select' | 'Count' | 'Insert' | 'Update' | 'Delete' | 'Fragment' | 'Tx';
45
- /**
46
- * litedbmodel's specific-component catalog (spec §11 item 1) — the behavior-contracts
47
- * `Catalog`-typed source of truth. Each entry declares the Port schema of one SQL
48
- * primitive AS THE BACKEND COMPILE WIRES IT; the effect implementation is bound
49
- * separately in the handler registry (WS3, C4). All entries except `Tx` may appear in
50
- * the portable IR.
51
- */
52
- export declare const LITEDBMODEL_CATALOG: Catalog;
53
- /** Look up a catalog entry by name (undefined for an unknown primitive). */
54
- export declare function catalogEntry(name: string): CatalogEntry | undefined;
55
- /** The catalog names litedbmodel declares (the C2 per-DSL surface). */
56
- export declare const CATALOG_NAMES: readonly CatalogName[];
57
- /**
58
- * The CQRS write catalog: the names whose presence in a component body makes the
59
- * component a COMMAND (spec §2.4 — effect is derived from the graph, not authored).
60
- * `Select`/`Fragment` are read-side; `Insert`/`Update`/`Delete`/`Tx` are write-side.
61
- */
62
- export declare const WRITE_CATALOG_NAMES: readonly CatalogName[];
63
- /**
64
- * The dynamic per-field write-port families (`<group>.<field>` — the flattened record
65
- * convention; longest-prefix wins). A `values.<field>` (Insert) or `set.<field>`
66
- * (Update) port carries the field's Expression IR value; a `sqlCast.<field>` port carries
67
- * the field's PostgreSQL cast type (a literal string, e.g. `jsonb`/`uuid`/`int[]`) that drives
68
- * the v1 per-column `?::<sqlCast>` on Postgres (`DBModel._insert`/`_update`). `sqlCast.` ports are
69
- * INERT on MySQL/SQLite (v1's dialect-aware cast formatter is identity there).
70
- */
71
- export declare const WRITE_PORT_FAMILIES: readonly string[];
72
- /**
73
- * The emitter's catalog validation (loud; a violation is a BUILD error), mirrored from
74
- * graphddb's `assertComponentsInCatalog`. Every `componentRef` / `map` body node of every
75
- * emitted component must:
76
- *
77
- * 1. reference a declared catalog name;
78
- * 2. wire every `required` port of that entry;
79
- * 3. wire ONLY declared ports — a port is declared if it is a static `inputPorts` name or
80
- * a write record-family port ({@link WRITE_PORT_FAMILIES}, write entries only).
81
- *
82
- * All violations are collected and thrown as one error. `cond` nodes carry no component
83
- * reference and are skipped.
84
- */
85
- export declare function assertComponentsInCatalog(components: readonly Component[]): void;
86
- /** litedbmodel's CQRS effect vocabulary, mapped 1:1 from bc's `BehaviorEffect`. */
87
- export type ContractEffect = 'query' | 'command';
88
- /**
89
- * Derive one component's Query/Command classification FROM THE GRAPH: behavior-contracts'
90
- * `classifyBehaviorEffect` over {@link WRITE_CATALOG_NAMES} — a component is a `'command'`
91
- * iff its body references a write-catalog primitive, else a `'query'` (spec §2.4: effect
92
- * is derived, never authored).
93
- */
94
- export declare function deriveContractEffect(component: Component): ContractEffect;
95
- //# sourceMappingURL=catalog.d.ts.map
@@ -1 +0,0 @@
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,EAAmB,MAAM,oBAAoB,CAAC;AAI9G,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GACnB,QAAQ,GACR,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,UAAU,GACV,IAAI,CAAC;AAwET;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,EAAE,OA2BjC,CAAC;AAEF,4EAA4E;AAC5E,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAEnE;AAED,uEAAuE;AACvE,eAAO,MAAM,aAAa,EAAE,SAAS,WAAW,EAQ/C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,WAAW,EAKrD,CAAC;AAIF;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAIhD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,GAAG,IAAI,CAoChF;AAGD,mFAAmF;AACnF,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,SAAS,CAAC;AAEjD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,SAAS,GAAG,cAAc,CAEzE"}
@@ -1,245 +0,0 @@
1
- "use strict";
2
- /**
3
- * litedbmodel v2 SCP catalog — WS1 (#21).
4
- *
5
- * `LITEDBMODEL_CATALOG` is the behavior-contracts–typed `Catalog` that IS the whole
6
- * per-DSL difference litedbmodel supplies as a SQL-backend consumer (bc C2: "the only
7
- * per-DSL difference is the catalog"). It mirrors the SHAPE of graphddb's
8
- * `GRAPHDDB_CATALOG` (`src/spec/catalog.ts`) exactly: compact `PortSchema` constructors,
9
- * an `entry()` helper, per-primitive `inputPorts`, an `output.shape`, and a
10
- * `portableToIR` flag. The effect implementation (SQL execution + row→model assembly) is
11
- * bound separately in the handler registry (WS3, C4 — catalog declares, registry binds).
12
- *
13
- * ## Catalog names (spec §1 / §11 item 1)
14
- *
15
- * `Select` / `Insert` / `Update` / `Delete` are the CRUD leaf components. `Fragment` is
16
- * the dynamic WHERE/SET fragment-tree component (SKIP → fragment existence rules, §8);
17
- * `Tx` is the multi-statement transaction envelope. As in graphddb, the transaction
18
- * envelope (`Tx`) is `portableToIR: false` — a transaction is emitted as a Component
19
- * whose body references the per-statement CRUD primitives; the atomic BEGIN/COMMIT
20
- * envelope is the runtime's execution concern (WS3), never a portable-IR node.
21
- *
22
- * ## Port schema conventions
23
- *
24
- * A `CatalogEntry.inputPorts` names the STATIC ports of the emitted wiring. Two families
25
- * are dynamic by construction and are validated by {@link assertComponentsInCatalog}
26
- * against documented patterns instead of being statically enumerable:
27
- *
28
- * - **`where`/`set`/`values` records**: one port per model field, flattened one-port-
29
- * per-field under a `<group>.<field>` key ({@link WRITE_PORT_FAMILIES}). These carry
30
- * Expression IR (the field's value/condition), from the closed operator set only.
31
- *
32
- * The CRUD entries carry `additionalPorts: true` (bc#26) so bc's shared port check
33
- * (`checkPortNames` / `buildComponentDefinition`) accepts the dynamic families; every
34
- * DECLARED port keeps bc's required/type checks regardless of the opt-in. `Tx`'s single
35
- * port is static, so it keeps bc's fail-closed default.
36
- */
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.WRITE_PORT_FAMILIES = exports.WRITE_CATALOG_NAMES = exports.CATALOG_NAMES = exports.LITEDBMODEL_CATALOG = void 0;
39
- exports.catalogEntry = catalogEntry;
40
- exports.assertComponentsInCatalog = assertComponentsInCatalog;
41
- exports.deriveContractEffect = deriveContractEffect;
42
- const behavior_contracts_1 = require("behavior-contracts");
43
- // Compact schema constructors (the IR bundle is size-budgeted — graphddb convention).
44
- const P = (type, required) => (required ? { type, required } : { type });
45
- /**
46
- * The shared read-port surface for `Select`: `table` always; the optional
47
- * `where` (a fragment-tree reference — see `Fragment`), `order`, `limit`, `offset`,
48
- * `group` wiring, and the always-emitted `select` projection.
49
- *
50
- * `where` is typed `fragment` (not `expr`): a Select's dynamic WHERE is a fragment tree
51
- * (§8), NOT a single Expression — the SKIP existence rules live on the tree, outside the
52
- * Expression IR vocabulary (bc `expression-ir.md` §4: SKIP is OUTSIDE Expression IR).
53
- * `limit` / `offset` are `expr` (they may be an input-ref or a `coalesce` default, §8).
54
- */
55
- const SELECT_PORTS = {
56
- table: P('string', true),
57
- select: P('string[]', true),
58
- where: P('fragment'),
59
- order: P('string'),
60
- limit: P('expr'),
61
- offset: P('expr'),
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'),
78
- };
79
- /**
80
- * The shared write-port surface for `Insert`/`Update`/`Delete`: `table` always;
81
- * `where` (fragment tree — required existence enforced by the compiler, not here, since a
82
- * Select may legitimately omit it); `returning` projection; `onConflict` wiring for
83
- * Insert. The per-field value/set ports (`values.<field>` / `set.<field>`) are dynamic
84
- * ({@link WRITE_PORT_FAMILIES}) and each carries an Expression IR value.
85
- */
86
- const WRITE_PORTS = {
87
- table: P('string', true),
88
- where: P('fragment'),
89
- returning: P('string'),
90
- onConflict: P('string'),
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'),
98
- };
99
- const entry = (name, inputPorts, shape, portableToIR) => ({
100
- name,
101
- inputPorts,
102
- output: { shape },
103
- portableToIR,
104
- // Dynamic port families (where/set/values record ports) are validated by
105
- // assertComponentsInCatalog, not statically enumerable. Tx overrides back to
106
- // fail-closed (its one port is static).
107
- additionalPorts: true,
108
- });
109
- /**
110
- * litedbmodel's specific-component catalog (spec §11 item 1) — the behavior-contracts
111
- * `Catalog`-typed source of truth. Each entry declares the Port schema of one SQL
112
- * primitive AS THE BACKEND COMPILE WIRES IT; the effect implementation is bound
113
- * separately in the handler registry (WS3, C4). All entries except `Tx` may appear in
114
- * the portable IR.
115
- */
116
- exports.LITEDBMODEL_CATALOG = {
117
- // Read: `items` (a Select root yields a row list; per-row collapse to `item` is the
118
- // consumer's cardinality concern, mirrored from graphddb Query's `cardinality` port).
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
- // bc 0.8.0 (SA5): Count's output element type is STATICALLY determined (`int` — the counted rows),
125
- // so it declares a catalog `elemType` and needs no per-call `.as` (unlike Select, whose row shape is
126
- // per-projection). `baseOutTypeFromEntry` bakes node.outType = {arr:'int'} (items shape) at record.
127
- Count: { ...entry('Count', { table: P('string', true), where: P('fragment') }, 'items', true), elemType: 'int' },
128
- // Writes yield the RETURNING row list (`items`); a single-row write collapses at the
129
- // consumer boundary, same as reads.
130
- Insert: entry('Insert', WRITE_PORTS, 'items', true),
131
- Update: entry('Update', WRITE_PORTS, 'items', true),
132
- Delete: entry('Delete', WRITE_PORTS, 'items', true),
133
- // The dynamic WHERE/SET fragment-tree component (§8). Its ports carry the fragment
134
- // tree; the compiler resolves SKIP/AND-OR structure to fragment existence rules.
135
- Fragment: entry('Fragment', { tree: P('fragment', true) }, 'item', true),
136
- // The runtime-side atomic envelope: never referenced by the portable IR (a transaction
137
- // IS a component over the CRUD primitives) — runtime-only. Its single port is static,
138
- // so it keeps bc's fail-closed default (no additionalPorts opt-in).
139
- Tx: {
140
- ...entry('Tx', { statements: P('map[]', true) }, 'item', false),
141
- additionalPorts: false,
142
- },
143
- };
144
- /** Look up a catalog entry by name (undefined for an unknown primitive). */
145
- function catalogEntry(name) {
146
- return exports.LITEDBMODEL_CATALOG[name];
147
- }
148
- /** The catalog names litedbmodel declares (the C2 per-DSL surface). */
149
- exports.CATALOG_NAMES = [
150
- 'Select',
151
- 'Count',
152
- 'Insert',
153
- 'Update',
154
- 'Delete',
155
- 'Fragment',
156
- 'Tx',
157
- ];
158
- /**
159
- * The CQRS write catalog: the names whose presence in a component body makes the
160
- * component a COMMAND (spec §2.4 — effect is derived from the graph, not authored).
161
- * `Select`/`Fragment` are read-side; `Insert`/`Update`/`Delete`/`Tx` are write-side.
162
- */
163
- exports.WRITE_CATALOG_NAMES = [
164
- 'Insert',
165
- 'Update',
166
- 'Delete',
167
- 'Tx',
168
- ];
169
- const WRITE_SET = new Set(exports.WRITE_CATALOG_NAMES);
170
- /**
171
- * The dynamic per-field write-port families (`<group>.<field>` — the flattened record
172
- * convention; longest-prefix wins). A `values.<field>` (Insert) or `set.<field>`
173
- * (Update) port carries the field's Expression IR value; a `sqlCast.<field>` port carries
174
- * the field's PostgreSQL cast type (a literal string, e.g. `jsonb`/`uuid`/`int[]`) that drives
175
- * the v1 per-column `?::<sqlCast>` on Postgres (`DBModel._insert`/`_update`). `sqlCast.` ports are
176
- * INERT on MySQL/SQLite (v1's dialect-aware cast formatter is identity there).
177
- */
178
- exports.WRITE_PORT_FAMILIES = [
179
- 'values.',
180
- 'set.',
181
- 'sqlCast.',
182
- ];
183
- /**
184
- * The emitter's catalog validation (loud; a violation is a BUILD error), mirrored from
185
- * graphddb's `assertComponentsInCatalog`. Every `componentRef` / `map` body node of every
186
- * emitted component must:
187
- *
188
- * 1. reference a declared catalog name;
189
- * 2. wire every `required` port of that entry;
190
- * 3. wire ONLY declared ports — a port is declared if it is a static `inputPorts` name or
191
- * a write record-family port ({@link WRITE_PORT_FAMILIES}, write entries only).
192
- *
193
- * All violations are collected and thrown as one error. `cond` nodes carry no component
194
- * reference and are skipped.
195
- */
196
- function assertComponentsInCatalog(components) {
197
- const errs = [];
198
- for (const c of components) {
199
- for (const n of c.body) {
200
- if ('cond' in n)
201
- continue;
202
- if ('fanout' in n) {
203
- // bc 0.7.3+ `FanoutNode` (connection fan-out / batched BatchGet). litedbmodel authors
204
- // only Select/Count/map/cond via LITEDBMODEL_CATALOG and never emits fanout, so a
205
- // fanout node here means an unsupported graph reached the emitter — reject fail-closed
206
- // rather than mis-validate it as a component ref.
207
- errs.push(`${c.name}/${n.id}: fanout node is not supported by litedbmodel (bc FanoutNode)`);
208
- continue;
209
- }
210
- const ref = 'map' in n ? n.map : n;
211
- const entryDef = exports.LITEDBMODEL_CATALOG[ref.component];
212
- if (entryDef === undefined) {
213
- errs.push(`${c.name}/${n.id}: references '${ref.component}', not a LITEDBMODEL_CATALOG entry (known: ${exports.CATALOG_NAMES.join(', ')})`);
214
- continue;
215
- }
216
- const ports = ref.ports;
217
- for (const [p, s] of Object.entries(entryDef.inputPorts)) {
218
- if (s.required === true && !(p in ports)) {
219
- errs.push(`${c.name}/${n.id} (${ref.component}): required port '${p}' is not wired`);
220
- }
221
- }
222
- const isWriteItem = WRITE_SET.has(ref.component);
223
- for (const p of Object.keys(ports)) {
224
- if (p in entryDef.inputPorts)
225
- continue;
226
- if (isWriteItem && exports.WRITE_PORT_FAMILIES.some((f) => p.startsWith(f)))
227
- continue;
228
- errs.push(`${c.name}/${n.id} (${ref.component}): port '${p}' is not declared by the catalog entry (nor a write record-family port)`);
229
- }
230
- }
231
- }
232
- if (errs.length > 0) {
233
- throw new Error(`litedbmodel catalog validation failed (${errs.length} violation${errs.length === 1 ? '' : 's'}):\n - ${errs.join('\n - ')}`);
234
- }
235
- }
236
- /**
237
- * Derive one component's Query/Command classification FROM THE GRAPH: behavior-contracts'
238
- * `classifyBehaviorEffect` over {@link WRITE_CATALOG_NAMES} — a component is a `'command'`
239
- * iff its body references a write-catalog primitive, else a `'query'` (spec §2.4: effect
240
- * is derived, never authored).
241
- */
242
- function deriveContractEffect(component) {
243
- return (0, behavior_contracts_1.classifyBehaviorEffect)(component, exports.WRITE_CATALOG_NAMES) === 'writing' ? 'command' : 'query';
244
- }
245
- //# sourceMappingURL=catalog.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../src/scp/catalog.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;;;AAkIH,oCAEC;AAsDD,8DAoCC;AAYD,oDAEC;AA1OD,2DAA8G;AAqB9G,sFAAsF;AACtF,MAAM,CAAC,GAAG,CAAC,IAAY,EAAE,QAAe,EAAc,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;AAEpG;;;;;;;;;GASG;AACH,MAAM,YAAY,GAA+B;IAC/C,KAAK,EAAE,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC;IACxB,MAAM,EAAE,CAAC,CAAC,UAAU,EAAE,IAAI,CAAC;IAC3B,KAAK,EAAE,CAAC,CAAC,UAAU,CAAC;IACpB,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC;IAClB,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC;IAChB,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC;IACjB,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC;IAClB,sFAAsF;IACtF,6FAA6F;IAC7F,iFAAiF;IACjF,sFAAsF;IACtF,4FAA4F;IAC5F,uFAAuF;IACvF,4FAA4F;IAC5F,iCAAiC;IACjC,oFAAoF;IACpF,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC;IACtB,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC;IACjB,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC;IACvB,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC;IACb,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC;IACtB,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC;CACpB,CAAC;AAEF;;;;;;G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W,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YACjD,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;gBACnC,IAAI,CAAC,IAAI,QAAQ,CAAC,UAAU;oBAAE,SAAS;gBACvC,IAAI,WAAW,IAAI,2BAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;oBAAE,SAAS;gBAC9E,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,SAAS,YAAY,CAAC,yEAAyE,CAAC,CAAC;YACvI,CAAC;QACH,CAAC;IACH,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,0CAA0C,IAAI,CAAC,MAAM,aAAa,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,UAAU,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAChJ,CAAC;AACH,CAAC;AAMD;;;;;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,201 +0,0 @@
1
- /**
2
- * litedbmodel v2 SCP — mode-3 codegen (WS7f, #35; spec §9 exec-mode 3 / §10 / §11; makeSQL flip,
3
- * epic #43/#45 Phase B; #60 milestone 1 — typed-NATIVE READ codegen, bc#77/#90).
4
- *
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
- *
9
- * 1. **Behavior module** — bc's SHARED generator run over the bundle's portable IR through bc's
10
- * de-interpreted, RUNTIME-FREE emitter. For a READ bundle covered by bc's typed-NATIVE
11
- * endpoint (`rust-typed-native` / `go-typed-native`, bc#77/#90 — the 1.0 read de-box: fully
12
- * concrete `HandlerNR<Comp>`/`InNR<Comp>`/`PortsNR<Comp><node>`/`RawRowNR<Comp><node>` structs,
13
- * ZERO boxed `Value`/`RawValue`, ZERO IR baked into the module), the CODEGEN-ONLY lowering
14
- * below ({@link lowerReadGraphForTypedNative}) makes the read's shape structurally ELIGIBLE
15
- * (derives each real Select-node's referenced heads from its statements → individual scalar ref
16
- * ports + types the component's `inputPorts` from the schema) before handing it to bc. For a WRITE bundle, or a
17
- * READ shape typed-native does not (yet) cover, codegen uses bc's existing de-interpreted
18
- * STRAIGHT-LINE endpoint (`<lang>-straightline`, bc#75) — see {@link typedEmitterFor}.
19
- * 2. **SQL catalog companion** — the pure-JSON STATIC makeSQL catalog (per-node statement
20
- * templates / relations / transaction). A codegen consumer's thin SQL layer reads it to
21
- * evaluate skip + value-specs → assemble → render → execute (identically to the mode-2 runtime).
22
- *
23
- * ## #60 milestone 1 scope (CODEGEN-PATH ONLY)
24
- *
25
- * This lowering exists SOLELY for the codegen emitter call — it builds a NEW, separate
26
- * `ComponentGraphIR` from the bundle's `readGraph`; it never mutates `SqlBundle`/`ReadGraph` and
27
- * never touches the shared `readGraph`/`executeReadGraph` the native exec surface (and the
28
- * frozen conformance corpus) depend on. Those keep consuming the REAL Select-node
29
- * `readGraph.ir`, completely unaffected by anything in this file.
30
- *
31
- * ## Behavior-identical to the thin-runtime (mode-2), by construction
32
- *
33
- * The generated module is observationally equivalent to `runBehavior` (same values, same emitted
34
- * op sequence, same Failure code/message), and the companion IS the bundle, so a codegen runtime
35
- * that drives it follows the IDENTICAL static-makeSQL render/execute path {@link executeBundle}
36
- * uses — SQL text (all dialects) and results are identical, not approximately equal. The TS leg
37
- * PROVES this by executing via the artifact and asserting exact equality vs {@link executeBundle}
38
- * (see {@link codegenExecuteBundleForTest}).
39
- *
40
- * ## No literal-bake / no boxed fallback
41
- *
42
- * typed-native fails CLOSED on an uncovered shape (a `map`/`cond` relation kind it does not cover,
43
- * or an input head that cannot lower to a native port). Such a shape is NOT silently regenerated on
44
- * the boxed `-typed`/`-typed-raw` emitter — it THROWS, naming the exact gap, so it can be tracked as
45
- * a bc coverage gap rather than masked.
46
- *
47
- * IN-list / array-bound WHERE heads (the `whereIn` `{__jsonArray:{ref:[head]},dialect}` param) are
48
- * now COVERED via bc#110 (native array/list port for a componentRef input port): the lowering
49
- * resolves the IN-list column's element scalar and emits a native ARRAY input port
50
- * (`{type:'array', elemType}` → `Vec<ElemT>`/`[]ElemT`), so `complexWhere`/`inList` reach the
51
- * zero-boxing native hot path (no serde_json/encoding-json, no boxed `Value`). They no longer
52
- * fail closed as a bc#86/coverage gap.
53
- */
54
- import { type GeneratedModule, type Scope, type Value } from 'behavior-contracts';
55
- import type { ComponentGraphIR } from './authoring';
56
- import type { SqlBundle, SqliteDb } from './runtime';
57
- import type { DialectName } from './dialect';
58
- import type { RelationOp } from './relation';
59
- import type { ReadGraph } from './makesql/static-bundle';
60
- import type { TransactionPlan } from './makesql/tx';
61
- import { type ColumnTypeResolver } from './coltype';
62
- /**
63
- * The languages litedbmodel mode-3 codegen supports — exactly the set bc's shared generator
64
- * registers (bc#13 SP1 typescript/python + SP2 go/rust/php). {@link codegenEmitterFor}
65
- * verifies against the LIVE registry so a bc capability drift is caught loudly.
66
- */
67
- export declare const CODEGEN_LANGUAGES: readonly ["typescript", "python", "go", "rust", "php"];
68
- export type CodegenLanguage = (typeof CODEGEN_LANGUAGES)[number];
69
- /**
70
- * The bc READ emitter litedbmodel drives for each codegen target (#60 milestone 1): the
71
- * **de-interpreted, RUNTIME-FREE typed-NATIVE** endpoint (bc#77/#90) for go/rust — ZERO boxed
72
- * `Value`/`RawValue`, ZERO IR baked into the module, concrete `HandlerNR`/`InNR`/`PortsNR`/
73
- * `RawRowNR` structs. There is **NO literal / straight-line / boxed-typed fallback** for a read: an
74
- * unspec'd fallback is INVALID (it silently swallows the "this shape can't be natively codegen'd"
75
- * signal) — a read shape typed-native does not cover MUST fail loudly at generation, naming the gap
76
- * (report it as a bc#86 coverage gap), never silently regenerate on `-typed`/`-typed-raw`.
77
- *
78
- * `-typed-raw` (bc#76, the boxed-wire intermediate) and `-typed` (the boxed-Value intermediate) are
79
- * RETIRED from litedbmodel's codegen surface entirely (#60 milestone 1) — typed-native supersedes
80
- * both for every read shape it covers (bc#77/#90: single-componentRef reads AND the `map`
81
- * relationKind:single|connection shape, bc#86 part 2).
82
- *
83
- * - ts: **no typed-native endpoint registered yet** (bc has not shipped `typescript-typed-native`).
84
- * TS stays on its existing `typescript-typed` (boxed) endpoint until bc adds one — a DECLARED,
85
- * reported gap (not silently mirrored to go/rust's retirement), tracked as a bc#77 TS follow-up.
86
- * - **python/php: NOT present.** bc registers no de-boxed typed endpoint for them (capability limit).
87
- * litedbmodel does NOT substitute the literal (≈ir) emitter — that would be an unspec'd fallback.
88
- * Codegen for py/php is a bc capability gap that ERRORS (ESCALATE to bc), never a silent literal.
89
- *
90
- * WRITES (batchInsert / gate-first tx) are NOT reads — they are NOT routed through this table at
91
- * all (#60 milestone 1): a write bundle stays on the existing write/tx execution path
92
- * (`executeTransactionBundle` / the native adapter's hand-written tx mirror), never a codegen
93
- * module, boxed or typed-raw. {@link generateCodegenArtifact} throws if asked to codegen a write.
94
- */
95
- export declare const CODEGEN_EMITTER: Partial<Record<CodegenLanguage, string>>;
96
- /**
97
- * The SQL catalog companion (spec §9): the STATIC makeSQL bundle fields the codegen consumer's
98
- * thin SQL layer reads to evaluate + render + execute. Pure JSON — round-trips losslessly.
99
- */
100
- export interface SqlCatalogCompanion {
101
- /** Target SQL dialect (`sqlite`/`postgres`/`mysql`) — compiled once, TS-side (spec §10). */
102
- readonly dialect: DialectName;
103
- /** READ bundles: the portable read graph (surrogate IR + per-node makeSQL statements). */
104
- readonly readGraph?: ReadGraph;
105
- /** WRITE bundles: the single base-write makeSQL statement template. */
106
- readonly statement?: {
107
- readonly sql: string;
108
- readonly params: readonly unknown[];
109
- readonly skip?: unknown;
110
- };
111
- /** Input heads normalized to present-as-null (absent-key SKIP) — mirrors the bundle. */
112
- readonly optionalHeads: readonly string[];
113
- /** Pre-compiled STATIC read-relation batch ops (spec §5/§8), keyed by relation name. */
114
- readonly relations: Record<string, RelationOp>;
115
- /** Derived gate-first write-time-relations transaction plan (spec §6/§8), for a Command bundle. */
116
- readonly transaction?: TransactionPlan;
117
- /**
118
- * WRITE bundles: the codegen typed-de-box `outputType` (the TransactionResult typed shape). Rides
119
- * the companion so a codegen consumer that reassembles the bundle from the artifact round-trips it
120
- * losslessly (the read de-box carries its outType/outputType inside `readGraph.ir` instead).
121
- */
122
- readonly outputType?: unknown;
123
- }
124
- /** The full codegen artifact for one bundle × one language. */
125
- export interface CodegenArtifact {
126
- /** The target language. */
127
- readonly language: CodegenLanguage;
128
- /** The generated behavior module (bc's SHARED STRAIGHT-LINE generator output — real static code). */
129
- readonly module: GeneratedModule;
130
- /** The SQL catalog companion sidecar (the STATIC makeSQL execution catalog). */
131
- readonly companion: SqlCatalogCompanion;
132
- /** The originating bundle (so the equivalence leg re-executes the SAME static bundle). */
133
- readonly bundle: SqlBundle;
134
- }
135
- /**
136
- * The portable {@link ComponentGraphIR} view of a §8 READ bundle: `compileBehaviors`' real-node
137
- * read-graph IR (the de-surrogated `Select`/`Count`/map nodes; #12) — the SAME IR the native exec
138
- * surface (`executeReadGraph`) walks (via `bundle.readGraph.ir` directly). litedbmodel constructs NO
139
- * `ComponentGraphIR` literal here; it returns the compiler's own output. {@link generateCodegenArtifact}
140
- * does NOT use this for a typed-native READ target (that uses the codegen-only lowered form,
141
- * {@link lowerReadGraphForTypedNative}); this is the portable IR for a boxed READ endpoint / fingerprint.
142
- *
143
- * WRITE bundles have NO portable component-graph IR (they carry a single compiled `statement`, not a
144
- * component graph — and are NOT codegen-module cases: {@link generateCodegenArtifact} rejects them).
145
- * There is therefore no hand-built `makeSQL` write surrogate anymore (#12) — a write bundle throws.
146
- */
147
- export declare function bundleToPortableIR(bundle: SqlBundle): ComponentGraphIR;
148
- /** A head could not be typed for typed-native codegen — the read is NOT typed-native-coverable. */
149
- export declare class TypedNativeCoverageError extends Error {
150
- readonly component: string;
151
- readonly reasons: readonly string[];
152
- constructor(component: string, reasons: readonly string[]);
153
- }
154
- /**
155
- * Lower a read bundle's REAL Select-node `ComponentGraphIR` into a NEW, CODEGEN-ONLY IR eligible
156
- * for bc's typed-native endpoint (#60 milestone 1): derive each node's referenced heads from its
157
- * `statementsById` fragments and emit individual native-scalar `{ref:[head]}` ports, typing the
158
- * component's `inputPorts` from the schema (via {@link deriveHeadTypesFromStatements}). Throws
159
- * {@link TypedNativeCoverageError} if any referenced head cannot be natively typed (e.g. an IN-list's
160
- * array head) — NO silent `unknown` port, NO fallback. Does NOT mutate `bundle`/`bundle.readGraph`
161
- * (a fresh IR object is returned); the native `executeReadGraph` keeps consuming the real `readGraph.ir`.
162
- *
163
- * Scope: bc's typed-native predicate itself still governs `map`/`cond`/relationKind/policy
164
- * coverage (this lowering does not special-case those — `generateModule` fails closed on them with
165
- * its own detailed diagnostic, which this function does not need to duplicate).
166
- */
167
- export declare function lowerReadGraphForTypedNative(readGraph: ReadGraph, resolveColumnType: ColumnTypeResolver): ComponentGraphIR;
168
- /**
169
- * Resolve the READ codegen emitter for a target language, or throw. No fallback: a language
170
- * without a registered endpoint is a bc capability gap that fails LOUDLY (never a silent
171
- * substitution of the literal/interpreter/boxed emitter — an unspec'd fallback is invalid).
172
- */
173
- export declare function typedEmitterFor(language: string, registered: readonly string[]): string;
174
- /**
175
- * Shape-INDEPENDENT emitter resolution — identical to {@link typedEmitterFor} now that there is
176
- * exactly one READ endpoint per language (kept as a distinct export for callers that historically
177
- * used the shape-independent form; both resolve the SAME table).
178
- */
179
- export declare function codegenEmitterFor(language: string, registered: readonly string[]): string;
180
- /**
181
- * Generate the mode-3 READ codegen artifact for ONE §8 READ bundle in ONE target language. Lowers
182
- * the bundle's real Select-node read graph into the native-scalar-port IR
183
- * ({@link lowerReadGraphForTypedNative}) FIRST — for go/rust's typed-NATIVE endpoint (bc#77/#90,
184
- * RUNTIME-FREE) AND for TS's boxed `typescript-typed` endpoint alike. Both consume the SAME
185
- * genuine-bound-head shape: the lowering derives each node's ports from its compiled
186
- * `statementsById` fragments, so a WHERE COLUMN-NAME MARKER head (`whereGe($.created_at, $.since)`
187
- * — `$.created_at` names the column, is never bound) is EXCLUDED from the emitted ports/input
188
- * struct, exactly as go/rust already handled it (#12 regression: TS previously fed the raw IR and
189
- * emitted a stray `created_at` binding → `unknown binding: created_at` at execution).
190
- *
191
- * WRITE bundles are OUT OF SCOPE (#60 milestone 1: writes stay on the existing write/tx execution
192
- * path, never a codegen module) — throws if `bundle.readGraph` is absent.
193
- */
194
- export declare function generateCodegenArtifact(bundle: SqlBundle, language: string, registeredLanguages: readonly string[], resolveColumnType: ColumnTypeResolver, runtimeImport?: string): CodegenArtifact;
195
- /**
196
- * The TS codegen EXECUTION path used to PROVE behavior-identity: a codegen runtime reads the SQL
197
- * catalog companion (the STATIC makeSQL bundle) and evaluates skip + value-specs → assemble →
198
- * render → execute — which is EXACTLY {@link executeBundle} over the SAME bundle.
199
- */
200
- export declare function codegenExecuteBundleForTest(artifact: CodegenArtifact, input: Scope, db: SqliteDb): Value;
201
- //# sourceMappingURL=codegen.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../src/scp/codegen.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAEH,OAAO,EAAkC,KAAK,eAAe,EAAE,KAAK,KAAK,EAAE,KAA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