litedbmodel 2.0.1 → 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.
- package/dist/scp/catalog.d.ts +4 -1
- package/dist/scp/catalog.d.ts.map +1 -1
- package/dist/scp/catalog.js +5 -1
- package/dist/scp/catalog.js.map +1 -1
- package/dist/scp/codegen.d.ts +118 -24
- package/dist/scp/codegen.d.ts.map +1 -1
- package/dist/scp/codegen.js +360 -33
- package/dist/scp/codegen.js.map +1 -1
- package/dist/scp/coltype.d.ts +41 -0
- package/dist/scp/coltype.d.ts.map +1 -0
- package/dist/scp/coltype.js +188 -0
- package/dist/scp/coltype.js.map +1 -0
- package/dist/scp/dialect.d.ts +12 -3
- package/dist/scp/dialect.d.ts.map +1 -1
- package/dist/scp/dialect.js +12 -3
- package/dist/scp/dialect.js.map +1 -1
- package/dist/scp/fragment/assemble.d.ts.map +1 -1
- package/dist/scp/fragment/assemble.js +10 -2
- package/dist/scp/fragment/assemble.js.map +1 -1
- package/dist/scp/fragment/compile-pg.js +4 -4
- package/dist/scp/index.cjs +8132 -816
- package/dist/scp/index.d.ts +3 -1
- package/dist/scp/index.d.ts.map +1 -1
- package/dist/scp/index.js +17 -6
- package/dist/scp/index.js.map +1 -1
- package/dist/scp/index.mjs +660 -81
- package/dist/scp/makesql/compile-select.d.ts +8 -1
- package/dist/scp/makesql/compile-select.d.ts.map +1 -1
- package/dist/scp/makesql/compile-select.js +1 -1
- package/dist/scp/makesql/compile-select.js.map +1 -1
- package/dist/scp/makesql/outtype.d.ts +44 -0
- package/dist/scp/makesql/outtype.d.ts.map +1 -0
- package/dist/scp/makesql/outtype.js +197 -0
- package/dist/scp/makesql/outtype.js.map +1 -0
- package/dist/scp/makesql/static-bundle.d.ts +3 -1
- package/dist/scp/makesql/static-bundle.d.ts.map +1 -1
- package/dist/scp/makesql/static-bundle.js +95 -6
- package/dist/scp/makesql/static-bundle.js.map +1 -1
- package/dist/scp/makesql/tx.d.ts +1 -1
- package/dist/scp/makesql/tx.d.ts.map +1 -1
- package/dist/scp/makesql/tx.js +48 -3
- package/dist/scp/makesql/tx.js.map +1 -1
- package/dist/scp/makesql/writeouttype.d.ts +66 -0
- package/dist/scp/makesql/writeouttype.d.ts.map +1 -0
- package/dist/scp/makesql/writeouttype.js +195 -0
- package/dist/scp/makesql/writeouttype.js.map +1 -0
- package/dist/scp/runtime.d.ts +14 -3
- package/dist/scp/runtime.d.ts.map +1 -1
- package/dist/scp/runtime.js +28 -9
- package/dist/scp/runtime.js.map +1 -1
- package/docs/proposal/litedbmodel-v2-scp-architecture.md +51 -0
- package/package.json +2 -2
package/dist/scp/codegen.js
CHANGED
|
@@ -1,53 +1,125 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* litedbmodel v2 SCP — mode-3 codegen (WS7f, #35; spec §9 exec-mode 3 / §10 / §11; makeSQL flip,
|
|
4
|
-
* epic #43/#45 Phase B).
|
|
4
|
+
* epic #43/#45 Phase B; #60 milestone 1 — typed-NATIVE READ codegen, bc#77/#90).
|
|
5
5
|
*
|
|
6
6
|
* The static-codegen execution mode ("Codegen・静的(全言語)— IR → 各言語ソース生成 runtime≈0,
|
|
7
7
|
* 入力は可搬IRのみ, bc#13 共有 generator に SQL catalog を供給" — spec §9). It takes a §8 STATIC
|
|
8
8
|
* makeSQL {@link SqlBundle} and, per target language, emits:
|
|
9
9
|
*
|
|
10
|
-
* 1. **Behavior module** — bc's SHARED generator
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* `
|
|
10
|
+
* 1. **Behavior module** — bc's SHARED generator run over the bundle's portable IR through bc's
|
|
11
|
+
* de-interpreted, RUNTIME-FREE emitter. For a READ bundle covered by bc's typed-NATIVE
|
|
12
|
+
* endpoint (`rust-typed-native` / `go-typed-native`, bc#77/#90 — the 1.0 read de-box: fully
|
|
13
|
+
* concrete `HandlerNR<Comp>`/`InNR<Comp>`/`PortsNR<Comp><node>`/`RawRowNR<Comp><node>` structs,
|
|
14
|
+
* ZERO boxed `Value`/`RawValue`, ZERO IR baked into the module), the CODEGEN-ONLY lowering
|
|
15
|
+
* below ({@link lowerReadGraphForTypedNative}) makes the read's shape structurally ELIGIBLE
|
|
16
|
+
* (splits the surrogate `__scope` boxed-obj port into individual scalar ref ports + types the
|
|
17
|
+
* component's `inputPorts` from the schema) before handing it to bc. For a WRITE bundle, or a
|
|
18
|
+
* READ shape typed-native does not (yet) cover, codegen uses bc's existing de-interpreted
|
|
19
|
+
* STRAIGHT-LINE endpoint (`<lang>-straightline`, bc#75) — see {@link typedEmitterFor}.
|
|
14
20
|
* 2. **SQL catalog companion** — the pure-JSON STATIC makeSQL catalog (per-node statement
|
|
15
21
|
* templates / relations / transaction). A codegen consumer's thin SQL layer reads it to
|
|
16
22
|
* evaluate skip + value-specs → assemble → render → execute (identically to the mode-2 runtime).
|
|
17
23
|
*
|
|
18
|
-
* ##
|
|
24
|
+
* ## #60 milestone 1 scope (CODEGEN-PATH ONLY)
|
|
19
25
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
26
|
+
* This lowering exists SOLELY for the codegen emitter call — it builds a NEW, separate
|
|
27
|
+
* `ComponentGraphIR` from the bundle's `readGraph`; it never mutates `SqlBundle`/`ReadGraph` and
|
|
28
|
+
* never touches the shared `readGraph`/`executeReadGraph` the ir/interpret exec surface (and the
|
|
29
|
+
* frozen conformance corpus) depend on. Those keep consuming the ORIGINAL boxed-`__scope`-port
|
|
30
|
+
* surrogate IR ({@link bundleToPortableIR}), completely unaffected by anything in this file.
|
|
31
|
+
*
|
|
32
|
+
* ## Behavior-identical to the thin-runtime (mode-2), by construction
|
|
33
|
+
*
|
|
34
|
+
* The generated module is observationally equivalent to `runBehavior` (same values, same emitted
|
|
35
|
+
* op sequence, same Failure code/message), and the companion IS the bundle, so a codegen runtime
|
|
36
|
+
* that drives it follows the IDENTICAL static-makeSQL render/execute path {@link executeBundle}
|
|
37
|
+
* uses — SQL text (all dialects) and results are identical, not approximately equal. The TS leg
|
|
38
|
+
* PROVES this by executing via the artifact and asserting exact equality vs {@link executeBundle}
|
|
39
|
+
* (see {@link codegenExecuteBundleForTest}).
|
|
40
|
+
*
|
|
41
|
+
* ## No literal-bake / no boxed fallback
|
|
42
|
+
*
|
|
43
|
+
* typed-native fails CLOSED on an uncovered shape (a `map`/`cond` relation kind it does not cover,
|
|
44
|
+
* or an input head that cannot lower to a native scalar — e.g. an IN-list's array-typed head).
|
|
45
|
+
* Such a shape is NOT silently regenerated on the boxed `-typed`/`-typed-raw` emitter — it THROWS,
|
|
46
|
+
* naming the exact gap, so it can be tracked as a bc coverage gap (bc#86) rather than masked.
|
|
24
47
|
*/
|
|
25
48
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.CODEGEN_LANGUAGES = void 0;
|
|
49
|
+
exports.TypedNativeCoverageError = exports.CODEGEN_EMITTER = exports.CODEGEN_LANGUAGES = void 0;
|
|
27
50
|
exports.bundleToPortableIR = bundleToPortableIR;
|
|
28
|
-
exports.
|
|
51
|
+
exports.lowerReadGraphForTypedNative = lowerReadGraphForTypedNative;
|
|
52
|
+
exports.typedEmitterFor = typedEmitterFor;
|
|
53
|
+
exports.codegenEmitterFor = codegenEmitterFor;
|
|
29
54
|
exports.generateCodegenArtifact = generateCodegenArtifact;
|
|
30
55
|
exports.codegenExecuteBundleForTest = codegenExecuteBundleForTest;
|
|
31
56
|
const behavior_contracts_1 = require("behavior-contracts");
|
|
32
57
|
const runtime_1 = require("./runtime");
|
|
33
58
|
const ir_1 = require("./makesql/ir");
|
|
59
|
+
const coltype_1 = require("./coltype");
|
|
34
60
|
/**
|
|
35
61
|
* The languages litedbmodel mode-3 codegen supports — exactly the set bc's shared generator
|
|
36
|
-
* registers (bc#13 SP1 typescript/python + SP2 go/rust/php). {@link
|
|
62
|
+
* registers (bc#13 SP1 typescript/python + SP2 go/rust/php). {@link codegenEmitterFor}
|
|
37
63
|
* verifies against the LIVE registry so a bc capability drift is caught loudly.
|
|
38
64
|
*/
|
|
39
65
|
exports.CODEGEN_LANGUAGES = ['typescript', 'python', 'go', 'rust', 'php'];
|
|
66
|
+
/**
|
|
67
|
+
* The bc READ emitter litedbmodel drives for each codegen target (#60 milestone 1): the
|
|
68
|
+
* **de-interpreted, RUNTIME-FREE typed-NATIVE** endpoint (bc#77/#90) for go/rust — ZERO boxed
|
|
69
|
+
* `Value`/`RawValue`, ZERO IR baked into the module, concrete `HandlerNR`/`InNR`/`PortsNR`/
|
|
70
|
+
* `RawRowNR` structs. There is **NO literal / straight-line / boxed-typed fallback** for a read: an
|
|
71
|
+
* unspec'd fallback is INVALID (it silently swallows the "this shape can't be natively codegen'd"
|
|
72
|
+
* signal) — a read shape typed-native does not cover MUST fail loudly at generation, naming the gap
|
|
73
|
+
* (report it as a bc#86 coverage gap), never silently regenerate on `-typed`/`-typed-raw`.
|
|
74
|
+
*
|
|
75
|
+
* `-typed-raw` (bc#76, the boxed-wire intermediate) and `-typed` (the boxed-Value intermediate) are
|
|
76
|
+
* RETIRED from litedbmodel's codegen surface entirely (#60 milestone 1) — typed-native supersedes
|
|
77
|
+
* both for every read shape it covers (bc#77/#90: single-componentRef reads AND the `map`
|
|
78
|
+
* relationKind:single|connection shape, bc#86 part 2).
|
|
79
|
+
*
|
|
80
|
+
* - ts: **no typed-native endpoint registered yet** (bc has not shipped `typescript-typed-native`).
|
|
81
|
+
* TS stays on its existing `typescript-typed` (boxed) endpoint until bc adds one — a DECLARED,
|
|
82
|
+
* reported gap (not silently mirrored to go/rust's retirement), tracked as a bc#77 TS follow-up.
|
|
83
|
+
* - **python/php: NOT present.** bc registers no de-boxed typed endpoint for them (capability limit).
|
|
84
|
+
* litedbmodel does NOT substitute the literal (≈ir) emitter — that would be an unspec'd fallback.
|
|
85
|
+
* Codegen for py/php is a bc capability gap that ERRORS (ESCALATE to bc), never a silent literal.
|
|
86
|
+
*
|
|
87
|
+
* WRITES (batchInsert / gate-first tx) are NOT reads — they are NOT routed through this table at
|
|
88
|
+
* all (#60 milestone 1): a write bundle stays on the existing write/tx execution path
|
|
89
|
+
* (`executeTransactionBundle` / the native adapter's hand-written tx mirror), never a codegen
|
|
90
|
+
* module, boxed or typed-raw. {@link generateCodegenArtifact} throws if asked to codegen a write.
|
|
91
|
+
*/
|
|
92
|
+
exports.CODEGEN_EMITTER = {
|
|
93
|
+
typescript: 'typescript-typed',
|
|
94
|
+
go: 'go-typed-native',
|
|
95
|
+
rust: 'rust-typed-native',
|
|
96
|
+
};
|
|
40
97
|
/**
|
|
41
98
|
* The portable {@link ComponentGraphIR} view of a §8 bundle: a read bundle's surrogate IR (each
|
|
42
|
-
* SQL node → a `makeSQL` node), or the single `makeSQL` component IR for a write.
|
|
43
|
-
*
|
|
99
|
+
* SQL node → a `makeSQL` node), or the single `makeSQL` component IR for a write. This is the
|
|
100
|
+
* ORIGINAL boxed-`__scope`-port form the ir/interpret exec surface's `executeReadGraph` also
|
|
101
|
+
* consumes (via `bundle.readGraph.ir` directly) — {@link generateCodegenArtifact} does NOT use
|
|
102
|
+
* this for a READ bundle (it uses the codegen-only lowered form, {@link lowerReadGraphForTypedNative});
|
|
103
|
+
* this function is kept for callers that want the untouched portable IR (e.g. diagnostics, the
|
|
104
|
+
* write path, or a future straight-line fallback caller).
|
|
44
105
|
*/
|
|
45
106
|
function bundleToPortableIR(bundle) {
|
|
46
107
|
if (bundle.readGraph !== undefined)
|
|
47
108
|
return bundle.readGraph.ir;
|
|
48
|
-
|
|
109
|
+
const ir = (0, ir_1.makeSqlComponentIR)(bundle.name);
|
|
110
|
+
// A WRITE bundle's typed de-box (spec §4.1/§9): attach the derived `outputType` (the
|
|
111
|
+
// TransactionResult typed shape) to the single `makeSQL` node's `outType` + the component's
|
|
112
|
+
// `outputType` — exactly how the read graph annotates its surrogate IR. Without it, bc's typed
|
|
113
|
+
// emitters would hard-fail ("nothing to de-box"), which is the correct fail-closed signal; a
|
|
114
|
+
// resolver-less write bundle (no `outputType`) stays un-annotated (interpret/boxed only, as before).
|
|
115
|
+
if (bundle.outputType === undefined)
|
|
116
|
+
return ir;
|
|
117
|
+
const c = ir.components[0];
|
|
118
|
+
const body = c.body.map((n, i) => (i === 0 ? { ...n, outType: bundle.outputType } : n));
|
|
119
|
+
const component = { ...c, body, outputType: bundle.outputType };
|
|
120
|
+
return { ...ir, components: [component] };
|
|
49
121
|
}
|
|
50
|
-
/** The STATIC makeSQL execution catalog carried alongside the
|
|
122
|
+
/** The STATIC makeSQL execution catalog carried alongside the generated module. */
|
|
51
123
|
function companionOf(bundle) {
|
|
52
124
|
const base = {
|
|
53
125
|
dialect: bundle.dialect,
|
|
@@ -55,36 +127,291 @@ function companionOf(bundle) {
|
|
|
55
127
|
relations: bundle.relations,
|
|
56
128
|
...(bundle.readGraph !== undefined ? { readGraph: bundle.readGraph } : {}),
|
|
57
129
|
...(bundle.statement !== undefined ? { statement: bundle.statement } : {}),
|
|
130
|
+
...(bundle.outputType !== undefined ? { outputType: bundle.outputType } : {}),
|
|
58
131
|
};
|
|
59
132
|
return bundle.transaction === undefined ? base : { ...base, transaction: bundle.transaction };
|
|
60
133
|
}
|
|
134
|
+
// ═══════════════════════════════════════════════════════════════════════════════════════════
|
|
135
|
+
// #60 milestone 1 — CODEGEN-ONLY typed-native lowering.
|
|
136
|
+
//
|
|
137
|
+
// bc's typed-native coverage predicate (`coverageRejectReason`, bc#86/#89) requires EVERY
|
|
138
|
+
// componentRef port to be STATICALLY resolvable to a native scalar/string-array/number-literal —
|
|
139
|
+
// the surrogate read graph's single `__scope: {obj:{...}}` port is a BOXED obj literal, which is
|
|
140
|
+
// never statically resolvable (it fails `portIsStatic`), so bc hard-fails ("does not lower to a
|
|
141
|
+
// native Rust type") on EVERY read, covered or not, before this lowering. Splitting `__scope` into
|
|
142
|
+
// individual scalar ref ports (one per referenced head) makes the shape ELIGIBLE; typing the
|
|
143
|
+
// component's `inputPorts` (bc's authoring default is `unknown` for every scanned `$.head`) then
|
|
144
|
+
// lets each port lower to a CONCRETE Rust/Go field instead of falling through to `Value`.
|
|
145
|
+
//
|
|
146
|
+
// This is a NEW, throwaway `ComponentGraphIR` built FROM the bundle's `readGraph` fields
|
|
147
|
+
// (`ir`/`statementsById`, both already computed by the EXISTING `compileReadGraph` — untouched
|
|
148
|
+
// here) — it is never written back onto `SqlBundle`/`ReadGraph`, never serialized, and the
|
|
149
|
+
// ir/interpret exec surface (`executeReadGraph`) never sees it (it keeps reading `readGraph.ir`,
|
|
150
|
+
// the boxed-`__scope` form, directly). Purely a generation-time input to `generateModule`.
|
|
151
|
+
// ═══════════════════════════════════════════════════════════════════════════════════════════
|
|
152
|
+
/** The makeSQL surrogate node's synthetic port name (mirrors `static-bundle.ts`'s private `SCOPE_PORT`
|
|
153
|
+
* — duplicated as a literal here rather than exported, keeping this a codegen-only concern). */
|
|
154
|
+
const SCOPE_PORT = '__scope';
|
|
155
|
+
/** A head could not be typed for typed-native codegen — the read is NOT typed-native-coverable. */
|
|
156
|
+
class TypedNativeCoverageError extends Error {
|
|
157
|
+
component;
|
|
158
|
+
reasons;
|
|
159
|
+
constructor(component, reasons) {
|
|
160
|
+
super(`litedbmodel codegen (#60 m1): component '${component}' is not typed-native-coverable:\n` +
|
|
161
|
+
reasons.map((r) => ` - ${r}`).join('\n') +
|
|
162
|
+
`\n\nbc's typed-native endpoint (bc#77/#90) fails closed on an uncovered shape — this is NOT ` +
|
|
163
|
+
`regenerated on the boxed '-typed'/'-typed-raw' emitter (retired from litedbmodel's codegen ` +
|
|
164
|
+
`surface, #60 milestone 1). Report this as a bc#86 coverage gap (array-typed / non-scalar ` +
|
|
165
|
+
`input heads have no native port type yet), or exclude this case from native-codegen benching.`);
|
|
166
|
+
this.component = component;
|
|
167
|
+
this.reasons = reasons;
|
|
168
|
+
this.name = 'TypedNativeCoverageError';
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.TypedNativeCoverageError = TypedNativeCoverageError;
|
|
172
|
+
/** Extract the `{table, column}` a where-fragment statement's leading SQL token names, for the
|
|
173
|
+
* closed set of fragment shapes `compileSelectNode`/`lowerWhereMember` emit: `<col> <op> ?`
|
|
174
|
+
* (eq/cmp/LIKE/ILIKE). Returns undefined for any other shape (head-count / SQL text mismatch) —
|
|
175
|
+
* the caller treats that head as NOT resolvable (fail-closed), never guesses. */
|
|
176
|
+
const WHERE_FRAGMENT_COLUMN = /^([A-Za-z_][A-Za-z0-9_]*)\s+(?:=|<>|<=|>=|<|>|LIKE|ILIKE)\s*\?$/;
|
|
177
|
+
/** Extract the table name from the head `SELECT … FROM <table>` statement (dialect-tuned, but the
|
|
178
|
+
* `FROM <table>` token is stable across dialects/CTEs — `compileSelectNode`'s head always ends
|
|
179
|
+
* ` FROM <table>[ …]`; a JOIN/CTE-shaped head is out of scope for this narrow codegen deriver and
|
|
180
|
+
* reported as unresolvable rather than mis-parsed). */
|
|
181
|
+
const SELECT_FROM_TABLE = /\bFROM\s+([A-Za-z_][A-Za-z0-9_]*)\b/i;
|
|
182
|
+
/**
|
|
183
|
+
* Derive each input head's bc scalar type from a read node's compiled {@link StaticStatement}s
|
|
184
|
+
* (spec §4.1 schema SoT), for bc's typed-native codegen (#60 m1). Works from the ALREADY-COMPILED
|
|
185
|
+
* statement templates (available on `ReadGraph.statementsById`, which codegen already carries)
|
|
186
|
+
* instead of re-walking the authored component — so this lowering needs NO extra input beyond
|
|
187
|
+
* what `SqlBundle`/`ReadGraph` already expose (no change to `compileReadGraph`/`ReadGraph`).
|
|
188
|
+
*
|
|
189
|
+
* Returns the typed heads found, PLUS `unresolved` — heads referenced by a param that is NOT a
|
|
190
|
+
* bare single-segment `{ref:[head]}` (e.g. `whereIn`'s `{__jsonArray:{ref:[…]},dialect}` array
|
|
191
|
+
* param) or whose owning fragment's SQL text isn't the closed `<col> <op> ?` shape. A non-empty
|
|
192
|
+
* `unresolved` means the read is NOT typed-native-coverable (fail-closed at the caller).
|
|
193
|
+
*/
|
|
194
|
+
function deriveHeadTypesFromStatements(statements, resolveColumnType) {
|
|
195
|
+
const byHead = new Map();
|
|
196
|
+
const unresolved = new Map();
|
|
197
|
+
// The head statement (`SELECT … FROM <table>`) — always statements[0] (compileSelectNode always
|
|
198
|
+
// pushes it first); its table name resolves every WHERE fragment's column type.
|
|
199
|
+
const head = statements[0];
|
|
200
|
+
const tableMatch = head === undefined ? null : SELECT_FROM_TABLE.exec(head.sql);
|
|
201
|
+
const table = tableMatch?.[1];
|
|
202
|
+
for (const stmt of statements) {
|
|
203
|
+
if (stmt.whereFragment !== true)
|
|
204
|
+
continue;
|
|
205
|
+
for (const param of stmt.params) {
|
|
206
|
+
const path = refPathOf(param);
|
|
207
|
+
if (path === undefined || path.length !== 1) {
|
|
208
|
+
// Not a bare single-segment ref (e.g. the `whereIn` `__jsonArray` array param, or a nested
|
|
209
|
+
// literal): if it names a head at all, surface it; otherwise it simply isn't head-typable
|
|
210
|
+
// here (a literal has no head to report).
|
|
211
|
+
const named = headNameOf(param);
|
|
212
|
+
if (named !== undefined) {
|
|
213
|
+
unresolved.set(named, `input head '${named}' is bound by a non-scalar param shape (${JSON.stringify(param)}) — bc's ` +
|
|
214
|
+
`typed-native emitter has no native port type for it (string/int/float/bool scalars only).`);
|
|
215
|
+
}
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
const headName = path[0];
|
|
219
|
+
if (table === undefined) {
|
|
220
|
+
unresolved.set(headName, `input head '${headName}': could not resolve the owning table from the SELECT head SQL ('${head?.sql ?? '<none>'}')`);
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
const m = WHERE_FRAGMENT_COLUMN.exec(stmt.sql.trim());
|
|
224
|
+
if (m === null) {
|
|
225
|
+
unresolved.set(headName, `input head '${headName}': WHERE fragment SQL '${stmt.sql}' is not the closed '<col> <op> ?' shape this codegen-only deriver covers`);
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
const column = m[1];
|
|
229
|
+
const sqlType = resolveColumnType(table, column);
|
|
230
|
+
const scalar = (0, coltype_1.sqlTypeToBcScalar)(sqlType);
|
|
231
|
+
const prior = byHead.get(headName);
|
|
232
|
+
if (prior !== undefined && prior !== scalar) {
|
|
233
|
+
unresolved.set(headName, `input head '${headName}' resolves to conflicting scalar types ('${prior}' vs '${scalar}') across statements`);
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
byHead.set(headName, scalar);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return { byHead, unresolved };
|
|
240
|
+
}
|
|
241
|
+
/** A statement param's bare ref path (`{ref:[…]}`/`{refOpt:[…]}`), or undefined if it isn't one. */
|
|
242
|
+
function refPathOf(param) {
|
|
243
|
+
if (param === null || typeof param !== 'object' || Array.isArray(param))
|
|
244
|
+
return undefined;
|
|
245
|
+
const keys = Object.keys(param);
|
|
246
|
+
if (keys.length !== 1 || (keys[0] !== 'ref' && keys[0] !== 'refOpt'))
|
|
247
|
+
return undefined;
|
|
248
|
+
const path = param[keys[0]];
|
|
249
|
+
if (!Array.isArray(path) || path.length === 0 || !path.every((s) => typeof s === 'string'))
|
|
250
|
+
return undefined;
|
|
251
|
+
return path;
|
|
252
|
+
}
|
|
253
|
+
/** The head name a non-bare-ref param shape still names (e.g. `{__jsonArray:{ref:[head]},…}`), for
|
|
254
|
+
* a clearer diagnostic — undefined when no head can be identified at all (a plain literal). */
|
|
255
|
+
function headNameOf(param) {
|
|
256
|
+
if (param === null || typeof param !== 'object' || Array.isArray(param))
|
|
257
|
+
return undefined;
|
|
258
|
+
const obj = param;
|
|
259
|
+
if ('__jsonArray' in obj) {
|
|
260
|
+
const inner = refPathOf(obj.__jsonArray);
|
|
261
|
+
return inner?.[0];
|
|
262
|
+
}
|
|
263
|
+
return undefined;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Lower a read bundle's surrogate `ComponentGraphIR` into a NEW, CODEGEN-ONLY IR eligible for bc's
|
|
267
|
+
* typed-native endpoint (#60 milestone 1): split the single `__scope: {obj:{...}}` boxed port into
|
|
268
|
+
* individual scalar `{ref:[head]}` ports, and type the component's `inputPorts` from the schema
|
|
269
|
+
* (via {@link deriveHeadTypesFromStatements}). Throws {@link TypedNativeCoverageError} if any
|
|
270
|
+
* referenced head cannot be natively typed (e.g. an IN-list's array head) — NO silent `unknown`
|
|
271
|
+
* port, NO fallback. Does NOT mutate `bundle`/`bundle.readGraph` (a fresh IR object is returned);
|
|
272
|
+
* the ir/interpret exec surface's `executeReadGraph` keeps consuming the ORIGINAL `readGraph.ir`.
|
|
273
|
+
*
|
|
274
|
+
* Scope: bc's typed-native predicate itself still governs `map`/`cond`/relationKind/policy
|
|
275
|
+
* coverage (this lowering does not special-case those — `generateModule` fails closed on them with
|
|
276
|
+
* its own detailed diagnostic, which this function does not need to duplicate).
|
|
277
|
+
*/
|
|
278
|
+
function lowerReadGraphForTypedNative(readGraph, resolveColumnType) {
|
|
279
|
+
const ir = readGraph.ir;
|
|
280
|
+
const reasons = [];
|
|
281
|
+
const components = ir.components.map((c) => {
|
|
282
|
+
const inputPortTypes = new Map();
|
|
283
|
+
const body = c.body.map((n) => {
|
|
284
|
+
if ('cond' in n)
|
|
285
|
+
return n;
|
|
286
|
+
const isMapNode = 'map' in n;
|
|
287
|
+
const ref = isMapNode ? n.map : n;
|
|
288
|
+
const scopeVal = ref.ports[SCOPE_PORT];
|
|
289
|
+
if (scopeVal === undefined || typeof scopeVal !== 'object' || scopeVal === null || !('obj' in scopeVal)) {
|
|
290
|
+
// Not the makeSQL surrogate shape this lowering targets (defensive — every read-graph body
|
|
291
|
+
// node IS this shape by construction) — leave the node untouched; bc's own coverage check
|
|
292
|
+
// will report it if it is genuinely uncovered.
|
|
293
|
+
return n;
|
|
294
|
+
}
|
|
295
|
+
const obj = scopeVal.obj;
|
|
296
|
+
const stmts = readGraph.statementsById[n.id] ?? [];
|
|
297
|
+
const { byHead, unresolved } = deriveHeadTypesFromStatements(stmts, resolveColumnType);
|
|
298
|
+
for (const [, reason] of unresolved)
|
|
299
|
+
reasons.push(`node '${n.id}': ${reason}`);
|
|
300
|
+
for (const [head, scalar] of byHead) {
|
|
301
|
+
const prior = inputPortTypes.get(head);
|
|
302
|
+
if (prior !== undefined && prior !== scalar) {
|
|
303
|
+
reasons.push(`input head '${head}' resolves to conflicting scalar types ('${prior}' vs '${scalar}') across nodes`);
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
inputPortTypes.set(head, scalar);
|
|
307
|
+
}
|
|
308
|
+
// Every head the surrogate scope references must have been typed above (byHead) — a head
|
|
309
|
+
// present in `obj` but absent from `byHead`/`unresolved` indicates a param shape this
|
|
310
|
+
// deriver's statement walk did not visit (e.g. a non-WHERE port); report it too rather than
|
|
311
|
+
// silently emitting an untyped scalar ref port.
|
|
312
|
+
const newPorts = {};
|
|
313
|
+
for (const head of Object.keys(obj)) {
|
|
314
|
+
if (!byHead.has(head) && !unresolved.has(head)) {
|
|
315
|
+
reasons.push(`node '${n.id}': input head '${head}' referenced by the surrogate scope but not resolved by any WHERE fragment — cannot type it for native codegen`);
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
newPorts[head] = { ref: [head] };
|
|
319
|
+
}
|
|
320
|
+
return isMapNode
|
|
321
|
+
? { ...n, map: { ...n.map, ports: newPorts } }
|
|
322
|
+
: { ...n, ports: newPorts };
|
|
323
|
+
});
|
|
324
|
+
if (reasons.length > 0)
|
|
325
|
+
throw new TypedNativeCoverageError(c.name, reasons);
|
|
326
|
+
// Only emit an `inputPorts` entry for a head the COVERED plane actually references (a
|
|
327
|
+
// native-scalar port on some node's lowered ports). bc's authoring layer registers an
|
|
328
|
+
// `inputPorts` entry for every `$.head` the authored method SOURCE accesses — including a
|
|
329
|
+
// head used ONLY as a WHERE-fragment's LHS COLUMN-name marker (e.g. `whereGe($.created_at,
|
|
330
|
+
// $.since)` accesses `$.created_at` to name the column, never as a bound RHS value), which
|
|
331
|
+
// never appears in the surrogate `__scope` obj at all. Keeping such a stray entry with its
|
|
332
|
+
// original `unknown` schema type would emit an unresolvable `InNR<Comp>.field: Value` (bc's
|
|
333
|
+
// typed-native `InNR` struct declares a field for EVERY declared inputPort) — a compile error,
|
|
334
|
+
// since the covered module imports no `Value` type. Dropping it is sound: the covered plane
|
|
335
|
+
// never reads it (no lowered port references it), so omitting the `InNR` field changes nothing
|
|
336
|
+
// observable — every REAL WHERE-bound head is still typed + present (typed above, in `byHead`).
|
|
337
|
+
const inputPorts = {};
|
|
338
|
+
for (const [name, scalar] of inputPortTypes) {
|
|
339
|
+
const schema = (c.inputPorts ?? {})[name];
|
|
340
|
+
inputPorts[name] = schema === undefined ? { required: true, type: scalar } : { ...schema, type: scalar };
|
|
341
|
+
}
|
|
342
|
+
return { ...c, body, inputPorts };
|
|
343
|
+
});
|
|
344
|
+
return { ...ir, components };
|
|
345
|
+
}
|
|
61
346
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
347
|
+
* Resolve the READ codegen emitter for a target language, or throw. No fallback: a language
|
|
348
|
+
* without a registered endpoint is a bc capability gap that fails LOUDLY (never a silent
|
|
349
|
+
* substitution of the literal/interpreter/boxed emitter — an unspec'd fallback is invalid).
|
|
64
350
|
*/
|
|
65
|
-
function
|
|
351
|
+
function typedEmitterFor(language, registered) {
|
|
66
352
|
if (!exports.CODEGEN_LANGUAGES.includes(language)) {
|
|
67
353
|
throw new Error(`litedbmodel codegen: language '${language}' is not a supported target (supported: ${exports.CODEGEN_LANGUAGES.join(', ')})`);
|
|
68
354
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
`
|
|
355
|
+
const emitter = exports.CODEGEN_EMITTER[language];
|
|
356
|
+
if (emitter === undefined) {
|
|
357
|
+
throw new Error(`litedbmodel codegen: no READ codegen endpoint for '${language}'. litedbmodel codegen is STATIC ` +
|
|
358
|
+
`de-interpreted codegen (spec §9) with NO literal/interpreter/boxed fallback (an unspec'd fallback ` +
|
|
359
|
+
`is invalid). bc registers a READ endpoint only for ${Object.keys(exports.CODEGEN_EMITTER).join('/')} — a ` +
|
|
360
|
+
`'${language}' endpoint is a bc capability gap. ESCALATE to bc (bc#22 pattern); never substitute ` +
|
|
361
|
+
`the literal emitter.`);
|
|
73
362
|
}
|
|
363
|
+
if (!registered.includes(emitter)) {
|
|
364
|
+
throw new Error(`litedbmodel codegen: bc's shared generator does not register the '${emitter}' emitter for '${language}' ` +
|
|
365
|
+
`(bc registered: ${[...registered].sort().join(', ')}). ESCALATE to bc (bc#22 pattern), never fork locally.`);
|
|
366
|
+
}
|
|
367
|
+
return emitter;
|
|
74
368
|
}
|
|
75
369
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
370
|
+
* Shape-INDEPENDENT emitter resolution — identical to {@link typedEmitterFor} now that there is
|
|
371
|
+
* exactly one READ endpoint per language (kept as a distinct export for callers that historically
|
|
372
|
+
* used the shape-independent form; both resolve the SAME table).
|
|
79
373
|
*/
|
|
80
|
-
function
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
374
|
+
function codegenEmitterFor(language, registered) {
|
|
375
|
+
return typedEmitterFor(language, registered);
|
|
376
|
+
}
|
|
377
|
+
/** Does a resolved emitter id end in bc's typed-native suffix (`-typed-native`)? Only THOSE
|
|
378
|
+
* emitters need (and are eligible for) the `__scope`-obj-splitting lowering — a boxed endpoint
|
|
379
|
+
* (`typescript-typed`) accepts the ORIGINAL surrogate IR just fine (it consumes a boxed `Value`
|
|
380
|
+
* port either way), so lowering it would needlessly narrow TS's coverage (e.g. `whereIn`'s
|
|
381
|
+
* array-typed head, which typed-native cannot cover but the boxed TS endpoint handles today). */
|
|
382
|
+
function isTypedNativeEmitter(emitter) {
|
|
383
|
+
return emitter.endsWith('-typed-native');
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Generate the mode-3 READ codegen artifact for ONE §8 READ bundle in ONE target language. For a
|
|
387
|
+
* typed-NATIVE target (go/rust, bc#77/#90), lowers the bundle's surrogate read graph into the
|
|
388
|
+
* typed-native-eligible IR ({@link lowerReadGraphForTypedNative}) first — REAL static native
|
|
389
|
+
* source, RUNTIME-FREE, no baked-IR interpret path. For any OTHER registered endpoint (currently
|
|
390
|
+
* only TS's boxed `typescript-typed`, which has no typed-native counterpart yet), the ORIGINAL
|
|
391
|
+
* portable IR ({@link bundleToPortableIR}) is used unchanged — the lowering is typed-native-only
|
|
392
|
+
* and would needlessly narrow a boxed endpoint's existing coverage. litedbmodel supplies the
|
|
393
|
+
* input (portable IR + catalog); bc owns the emitter.
|
|
394
|
+
*
|
|
395
|
+
* WRITE bundles are OUT OF SCOPE (#60 milestone 1: writes stay on the existing write/tx execution
|
|
396
|
+
* path, never a codegen module) — throws if `bundle.readGraph` is absent.
|
|
397
|
+
*/
|
|
398
|
+
function generateCodegenArtifact(bundle, language, registeredLanguages, resolveColumnType, runtimeImport) {
|
|
399
|
+
if (bundle.readGraph === undefined) {
|
|
400
|
+
throw new Error(`litedbmodel codegen (#60 m1): bundle '${bundle.name}' has no readGraph — WRITE bundles are not ` +
|
|
401
|
+
`codegen-module cases (they stay on the existing write/tx execution path). Only READ bundles ` +
|
|
402
|
+
`are generated through generateCodegenArtifact.`);
|
|
403
|
+
}
|
|
404
|
+
const emitter = typedEmitterFor(language, registeredLanguages);
|
|
405
|
+
// The portable IR exists ONLY transiently here as the generator's input — it is NOT part of the
|
|
406
|
+
// codegen OUTPUT (no artifact field, no file, no binary; the codegen path never reads IR data).
|
|
407
|
+
const ir = isTypedNativeEmitter(emitter)
|
|
408
|
+
? lowerReadGraphForTypedNative(bundle.readGraph, resolveColumnType)
|
|
409
|
+
: bundleToPortableIR(bundle);
|
|
410
|
+
const module = (0, behavior_contracts_1.generateModule)(ir, runtimeImport === undefined ? { language: emitter } : { language: emitter, runtimeImport });
|
|
411
|
+
return { language: language, module, companion: companionOf(bundle), bundle };
|
|
85
412
|
}
|
|
86
413
|
/**
|
|
87
|
-
* The TS codegen EXECUTION path used to PROVE
|
|
414
|
+
* The TS codegen EXECUTION path used to PROVE behavior-identity: a codegen runtime reads the SQL
|
|
88
415
|
* catalog companion (the STATIC makeSQL bundle) and evaluates skip + value-specs → assemble →
|
|
89
416
|
* render → execute — which is EXACTLY {@link executeBundle} over the SAME bundle.
|
|
90
417
|
*/
|
package/dist/scp/codegen.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../src/scp/codegen.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAyDH,gDAGC;AAkBD,0DAaC;AAOD,0DAUC;AAOD,kEAEC;AAnHD,2DAAyH;AAEzH,uCAA0C;AAC1C,qCAAkD;AAMlD;;;;GAIG;AACU,QAAA,iBAAiB,GAAG,CAAC,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAU,CAAC;AAoCxF;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,MAAiB;IAClD,IAAI,MAAM,CAAC,SAAS,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;IAC/D,OAAO,IAAA,uBAAkB,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACzC,CAAC;AAED,sFAAsF;AACtF,SAAS,WAAW,CAAC,MAAiB;IACpC,MAAM,IAAI,GAAwB;QAChC,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,aAAa,EAAE,MAAM,CAAC,aAAa;QACnC,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,GAAG,CAAC,MAAM,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1E,GAAG,CAAC,MAAM,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC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MAAM,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CACb,yCAAyC,MAAM,CAAC,IAAI,6CAA6C;YAC/F,8FAA8F;YAC9F,gDAAgD,CACnD,CAAC;IACJ,CAAC;IACD,MAAM,OAAO,GAAG,eAAe,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAC;IAC/D,gGAAgG;IAChG,gGAAgG;IAChG,MAAM,EAAE,GAAG,oBAAoB,CAAC,OAAO,CAAC;QACtC,CAAC,CAAC,4BAA4B,CAAC,MAAM,CAAC,SAAS,EAAE,iBAAiB,CAAC;QACnE,CAAC,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC/B,MAAM,MAAM,GAAG,IAAA,mCAAc,EAAC,EAAE,EAAE,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,CAAC;IAC9H,OAAO,EAAE,QAAQ,EAAE,QAA2B,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;AACnG,CAAC;AAED;;;;GAIG;AACH,SAAgB,2BAA2B,CAAC,QAAyB,EAAE,KAAY,EAAE,EAAY;IAC/F,OAAO,IAAA,uBAAa,EAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* litedbmodel v2 型システム(SCP アーキ spec §4.1): SQL 型 → bc outType スカラの正規変換。
|
|
3
|
+
*
|
|
4
|
+
* litedbmodel は SQL バックエンド consumer なので **SQL 型を型の SoT** とする(TS の `number` は
|
|
5
|
+
* INTEGER/REAL を区別できないため型の権威にしない)。typed codegen(bc typed-raw 脱box)の `outType`
|
|
6
|
+
* 注記はこの変換で決まる。**曖昧/未知は error(no-assume・no-fallback)** — 既定値へ潰さない。
|
|
7
|
+
*
|
|
8
|
+
* 返すのは bc の scalar 型名(`typed.ts` の scalar union `"string"|"int"|"float"|"bool"|"null"`)。
|
|
9
|
+
* 行/リレーションの構造型(`obj`/`arr`/`opt`)は列型ではなくクエリ由来なので本変換の対象外。
|
|
10
|
+
*/
|
|
11
|
+
/** bc typed outType のスカラ型(bc 0.3.0 の portable notation と一致;date 型は無い)。 */
|
|
12
|
+
export type BcScalar = 'string' | 'int' | 'float' | 'bool' | 'null';
|
|
13
|
+
/**
|
|
14
|
+
* SQL 型(DDL のトークン。`DECIMAL(10,2)` 等の括弧やサイズは無視)→ bc outType スカラ。
|
|
15
|
+
* spec §4.1 の正規表に一致。未知/曖昧は throw(fail-closed)。
|
|
16
|
+
*/
|
|
17
|
+
export declare function sqlTypeToBcScalar(sqlType: string): BcScalar;
|
|
18
|
+
/**
|
|
19
|
+
* A column-type resolver: `(table, column) → SQL type token`. It is the SoT (spec §4.1: the
|
|
20
|
+
* `schema.sql` DDL) a codegen `outType` derivation consults to type each SELECT projection column.
|
|
21
|
+
* MUST throw (never return a default) when a `table.column` is unknown — an unmappable column is a
|
|
22
|
+
* hard error (no-assume, no-fallback), never a silent boxed fallback.
|
|
23
|
+
*/
|
|
24
|
+
export type ColumnTypeResolver = (table: string, column: string) => string;
|
|
25
|
+
/**
|
|
26
|
+
* Parse a list of `CREATE TABLE` DDL statements into a `table → (column → SQL type)` map. This is
|
|
27
|
+
* the spec §4.1 SoT: the physical SQL type of each column, from which `sqlTypeToBcScalar` derives
|
|
28
|
+
* the bc `outType` scalar for typed codegen. Only the base column definitions are read; table-level
|
|
29
|
+
* constraints (`PRIMARY KEY (…)`, `FOREIGN KEY …`, `UNIQUE (…)`, `CHECK …`) are skipped. A column's
|
|
30
|
+
* type is its first token after the name (e.g. `id INTEGER PRIMARY KEY` → `INTEGER`). Column names
|
|
31
|
+
* quoted with `"`/`` ` ``/`[]` are unquoted. Non-`CREATE TABLE` statements (INSERT seed rows, etc.)
|
|
32
|
+
* are ignored, so a mixed schema+seed list is accepted as-is.
|
|
33
|
+
*/
|
|
34
|
+
export declare function parseSchemaColumnTypes(ddl: readonly string[]): Map<string, Map<string, string>>;
|
|
35
|
+
/**
|
|
36
|
+
* Build a {@link ColumnTypeResolver} from CREATE TABLE DDL (spec §4.1 SoT). The resolver throws
|
|
37
|
+
* (no default) for any `table.column` the DDL does not declare — an unknown column is a hard error
|
|
38
|
+
* (no-assume, no-fallback), so a codegen `outType` derivation can never silently box an untyped row.
|
|
39
|
+
*/
|
|
40
|
+
export declare function schemaColumnTypeResolver(ddl: readonly string[]): ColumnTypeResolver;
|
|
41
|
+
//# sourceMappingURL=coltype.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coltype.d.ts","sourceRoot":"","sources":["../../src/scp/coltype.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,0EAA0E;AAC1E,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;AAEpE;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,CA+D3D;AAED;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;AAE3E;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAwB/F;AAyCD;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,kBAAkB,CAqBnF"}
|