litedbmodel 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/scp/authoring-sql.d.ts +78 -0
- package/dist/scp/authoring-sql.d.ts.map +1 -1
- package/dist/scp/authoring-sql.js +110 -2
- package/dist/scp/authoring-sql.js.map +1 -1
- package/dist/scp/catalog.d.ts +1 -1
- package/dist/scp/catalog.d.ts.map +1 -1
- package/dist/scp/catalog.js +27 -0
- package/dist/scp/catalog.js.map +1 -1
- package/dist/scp/codegen.d.ts +46 -82
- package/dist/scp/codegen.d.ts.map +1 -1
- package/dist/scp/codegen.js +37 -80
- package/dist/scp/codegen.js.map +1 -1
- package/dist/scp/find-filter-guard.d.ts +68 -0
- package/dist/scp/find-filter-guard.d.ts.map +1 -0
- package/dist/scp/find-filter-guard.js +88 -0
- package/dist/scp/find-filter-guard.js.map +1 -0
- package/dist/scp/fragment/assemble.d.ts +61 -0
- package/dist/scp/fragment/assemble.d.ts.map +1 -0
- package/dist/scp/fragment/assemble.js +148 -0
- package/dist/scp/fragment/assemble.js.map +1 -0
- package/dist/scp/fragment/compile-pg.d.ts +107 -0
- package/dist/scp/fragment/compile-pg.d.ts.map +1 -0
- package/dist/scp/fragment/compile-pg.js +142 -0
- package/dist/scp/fragment/compile-pg.js.map +1 -0
- package/dist/scp/fragment/index.d.ts +16 -0
- package/dist/scp/fragment/index.d.ts.map +1 -0
- package/dist/scp/fragment/index.js +34 -0
- package/dist/scp/fragment/index.js.map +1 -0
- package/dist/scp/fragment/model.d.ts +119 -0
- package/dist/scp/fragment/model.d.ts.map +1 -0
- package/dist/scp/fragment/model.js +66 -0
- package/dist/scp/fragment/model.js.map +1 -0
- package/dist/scp/fragment/pg-array-type.d.ts +13 -0
- package/dist/scp/fragment/pg-array-type.d.ts.map +1 -0
- package/dist/scp/fragment/pg-array-type.js +34 -0
- package/dist/scp/fragment/pg-array-type.js.map +1 -0
- package/dist/scp/guard.d.ts +2 -6
- package/dist/scp/guard.d.ts.map +1 -1
- package/dist/scp/guard.js +19 -22
- package/dist/scp/guard.js.map +1 -1
- package/dist/scp/index.cjs +11284 -3826
- package/dist/scp/index.d.ts +38 -23
- package/dist/scp/index.d.ts.map +1 -1
- package/dist/scp/index.js +119 -45
- package/dist/scp/index.js.map +1 -1
- package/dist/scp/index.mjs +4231 -1412
- package/dist/scp/makesql/authoring-compile.d.ts +90 -0
- package/dist/scp/makesql/authoring-compile.d.ts.map +1 -0
- package/dist/scp/makesql/authoring-compile.js +494 -0
- package/dist/scp/makesql/authoring-compile.js.map +1 -0
- package/dist/scp/makesql/compile-crud.d.ts +133 -0
- package/dist/scp/makesql/compile-crud.d.ts.map +1 -0
- package/dist/scp/makesql/compile-crud.js +288 -0
- package/dist/scp/makesql/compile-crud.js.map +1 -0
- package/dist/scp/makesql/compile-relation.d.ts +157 -0
- package/dist/scp/makesql/compile-relation.d.ts.map +1 -0
- package/dist/scp/makesql/compile-relation.js +425 -0
- package/dist/scp/makesql/compile-relation.js.map +1 -0
- package/dist/scp/makesql/compile-select.d.ts +45 -0
- package/dist/scp/makesql/compile-select.d.ts.map +1 -0
- package/dist/scp/makesql/compile-select.js +58 -0
- package/dist/scp/makesql/compile-select.js.map +1 -0
- package/dist/scp/makesql/compile.d.ts +63 -0
- package/dist/scp/makesql/compile.d.ts.map +1 -0
- package/dist/scp/makesql/compile.js +99 -0
- package/dist/scp/makesql/compile.js.map +1 -0
- package/dist/scp/makesql/handler.d.ts +58 -0
- package/dist/scp/makesql/handler.d.ts.map +1 -0
- package/dist/scp/makesql/handler.js +113 -0
- package/dist/scp/makesql/handler.js.map +1 -0
- package/dist/scp/makesql/index.d.ts +33 -0
- package/dist/scp/makesql/index.d.ts.map +1 -0
- package/dist/scp/makesql/index.js +114 -0
- package/dist/scp/makesql/index.js.map +1 -0
- package/dist/scp/makesql/ir.d.ts +42 -0
- package/dist/scp/makesql/ir.d.ts.map +1 -0
- package/dist/scp/makesql/ir.js +66 -0
- package/dist/scp/makesql/ir.js.map +1 -0
- package/dist/scp/makesql/json-array.d.ts +84 -0
- package/dist/scp/makesql/json-array.d.ts.map +1 -0
- package/dist/scp/makesql/json-array.js +118 -0
- package/dist/scp/makesql/json-array.js.map +1 -0
- package/dist/scp/makesql/json-batch.d.ts +102 -0
- package/dist/scp/makesql/json-batch.d.ts.map +1 -0
- package/dist/scp/makesql/json-batch.js +269 -0
- package/dist/scp/makesql/json-batch.js.map +1 -0
- package/dist/scp/makesql/makesql.d.ts +99 -0
- package/dist/scp/makesql/makesql.d.ts.map +1 -0
- package/dist/scp/makesql/makesql.js +122 -0
- package/dist/scp/makesql/makesql.js.map +1 -0
- package/dist/scp/makesql/pool-executor.d.ts +47 -0
- package/dist/scp/makesql/pool-executor.d.ts.map +1 -0
- package/dist/scp/makesql/pool-executor.js +50 -0
- package/dist/scp/makesql/pool-executor.js.map +1 -0
- package/dist/scp/makesql/static-bundle.d.ts +185 -0
- package/dist/scp/makesql/static-bundle.d.ts.map +1 -0
- package/dist/scp/makesql/static-bundle.js +1024 -0
- package/dist/scp/makesql/static-bundle.js.map +1 -0
- package/dist/scp/makesql/tx.d.ts +216 -0
- package/dist/scp/makesql/tx.d.ts.map +1 -0
- package/dist/scp/makesql/tx.js +743 -0
- package/dist/scp/makesql/tx.js.map +1 -0
- package/dist/scp/relation.d.ts +86 -74
- package/dist/scp/relation.d.ts.map +1 -1
- package/dist/scp/relation.js +186 -120
- package/dist/scp/relation.js.map +1 -1
- package/dist/scp/runtime.d.ts +146 -210
- package/dist/scp/runtime.d.ts.map +1 -1
- package/dist/scp/runtime.js +228 -512
- package/dist/scp/runtime.js.map +1 -1
- package/dist/scp/typed-object.d.ts +12 -1
- package/dist/scp/typed-object.d.ts.map +1 -1
- package/dist/scp/typed-object.js +25 -4
- package/dist/scp/typed-object.js.map +1 -1
- package/docs/proposal/v0-coverage-matrix.md +157 -0
- package/docs/proposal/v2-completeness-plan.md +90 -0
- package/docs/proposal/v2-sql-parity-checklist.md +162 -0
- package/package.json +3 -3
- package/dist/scp/bridge.d.ts +0 -64
- package/dist/scp/bridge.d.ts.map +0 -1
- package/dist/scp/bridge.js +0 -329
- package/dist/scp/bridge.js.map +0 -1
- package/dist/scp/compile-dialect.d.ts +0 -39
- package/dist/scp/compile-dialect.d.ts.map +0 -1
- package/dist/scp/compile-dialect.js +0 -62
- package/dist/scp/compile-dialect.js.map +0 -1
- package/dist/scp/compile-sqlite.d.ts +0 -114
- package/dist/scp/compile-sqlite.d.ts.map +0 -1
- package/dist/scp/compile-sqlite.js +0 -149
- package/dist/scp/compile-sqlite.js.map +0 -1
- package/dist/scp/ir.d.ts +0 -92
- package/dist/scp/ir.d.ts.map +0 -1
- package/dist/scp/ir.js +0 -28
- package/dist/scp/ir.js.map +0 -1
- package/dist/scp/render.d.ts +0 -40
- package/dist/scp/render.d.ts.map +0 -1
- package/dist/scp/render.js +0 -170
- package/dist/scp/render.js.map +0 -1
- package/dist/scp/write-plan.d.ts +0 -161
- package/dist/scp/write-plan.d.ts.map +0 -1
- package/dist/scp/write-plan.js +0 -528
- package/dist/scp/write-plan.js.map +0 -1
- package/dist/scp/write-runtime.d.ts +0 -80
- package/dist/scp/write-runtime.d.ts.map +0 -1
- package/dist/scp/write-runtime.js +0 -167
- 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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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,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* litedbmodel v2 SCP — pooled async `SqlExecutorAsync` factories for PG / MySQL (#40).
|
|
3
|
+
*
|
|
4
|
+
* The read-graph async execution model (`executeReadGraphAsync`) 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"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* litedbmodel v2 SCP — the STATIC, PORTABLE `makeSQL` bundle + its runtime (epic #43/#45
|
|
3
|
+
* Phase B; design #45 owner-confirmed static-bundle decision).
|
|
4
|
+
*
|
|
5
|
+
* This is the SOLE read/compile path of the makeSQL SCP model, expressed as a compile step
|
|
6
|
+
* that is **symbolic** (no concrete input needed) and a runtime that evaluates value-specs +
|
|
7
|
+
* skip PER-INPUT via behavior-contracts. It REPLACES the reduced-spine `../runtime.ts`
|
|
8
|
+
* `SqlBundle`/`compileBundle`/`executeBundle` for the read path.
|
|
9
|
+
*
|
|
10
|
+
* ## The static bundle shape (design #45)
|
|
11
|
+
*
|
|
12
|
+
* A compiled behavior method is a bundle of ordered {@link StaticStatement} — each a
|
|
13
|
+
* `makeSQL` TEMPLATE:
|
|
14
|
+
* - `sql` — tuned dialect SQL text (`?` placeholders), COMPLETE and value-independent
|
|
15
|
+
* (compiled ONCE; the single-JSON-param array forms + PG `= ANY`/UNNEST keep
|
|
16
|
+
* the text fixed regardless of the runtime array length — no per-input text).
|
|
17
|
+
* - `params` — value-specs = bc Expression IR (`{ref:[…]}` / small ops / literals), 1:1 with
|
|
18
|
+
* the top-level `?`, evaluated AT RUNTIME by bc `evaluateExpression`.
|
|
19
|
+
* - `skip?` — a bc presence expression, evaluated at runtime; when truthy the whole
|
|
20
|
+
* statement (its `sql` and `params`) drops (contributes NOTHING).
|
|
21
|
+
*
|
|
22
|
+
* So the compile step emits a reusable portable artifact; the runtime (this module's
|
|
23
|
+
* {@link executeStaticBundle}) evaluates skip + params per-input via bc, assembles present
|
|
24
|
+
* fragments, renders placeholders, and executes. This unifies read/write/codegen on ONE
|
|
25
|
+
* `SqlBundle` shape and enables multi-language IR-reference execution.
|
|
26
|
+
*
|
|
27
|
+
* ## Symbolic compile — reuses `authoring-compile`'s port decoding, defers evaluation
|
|
28
|
+
*
|
|
29
|
+
* Phase A's `authoring-compile.ts` compiled per-input EAGERLY (it called `evaluateExpression`
|
|
30
|
+
* on every value slot to produce concrete `{sql, params}`). Here we keep the SAME closed-set
|
|
31
|
+
* port decoding (`../bridge.ts` operators, IN-sentinel, SKIP-`cond` collapse) but DEFER the
|
|
32
|
+
* value/skip evaluation to the runtime: a where-member's value operand stays as its raw bc
|
|
33
|
+
* Expression IR, a SKIP-`cond` guard becomes the statement's `skip` expression, and the SQL
|
|
34
|
+
* text is emitted once.
|
|
35
|
+
*/
|
|
36
|
+
import { type Scope, type Value, type ComponentGraphIR } from 'behavior-contracts';
|
|
37
|
+
import type { ComponentRefNode, MapNode, BehaviorModelContract } from '../authoring';
|
|
38
|
+
import { type Dialect } from './handler';
|
|
39
|
+
/** A closed-set bc Expression IR node used as a deferred value-spec or a skip expression. */
|
|
40
|
+
export type ValueSpec = unknown;
|
|
41
|
+
/**
|
|
42
|
+
* One statement of a static bundle — a `makeSQL` TEMPLATE. `sql` is the complete tuned SQL
|
|
43
|
+
* text (`?` placeholders, value-independent); `params` are deferred value-specs (bc
|
|
44
|
+
* Expression IR) evaluated at runtime; `skip`, when present, is a bc presence expression
|
|
45
|
+
* evaluated at runtime (truthy ⇒ drop the whole statement).
|
|
46
|
+
*/
|
|
47
|
+
export interface StaticStatement {
|
|
48
|
+
/** Complete tuned SQL text (`?` placeholders). */
|
|
49
|
+
readonly sql: string;
|
|
50
|
+
/** Deferred value-specs — closed-set bc Expression IR, 1:1 with the top-level `?`. */
|
|
51
|
+
readonly params: readonly ValueSpec[];
|
|
52
|
+
/** Optional bc presence expression; truthy ⇒ the whole statement drops. */
|
|
53
|
+
readonly skip?: ValueSpec;
|
|
54
|
+
/**
|
|
55
|
+
* A WHERE-clause fragment: its `sql` is a bare predicate body (no leading connector). The
|
|
56
|
+
* runtime prepends ` WHERE ` to the FIRST present fragment and ` AND ` to each later one, so
|
|
57
|
+
* a skipped fragment never leaves a dangling connector. A statement WITHOUT this flag emits
|
|
58
|
+
* its `sql` verbatim.
|
|
59
|
+
*/
|
|
60
|
+
readonly whereFragment?: true;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The static, portable compiled artifact of ONE authored behavior method (the read path).
|
|
64
|
+
* Pure JSON — every statement's `sql` is fixed text and its `params`/`skip` are bc Expression
|
|
65
|
+
* IR, so `JSON.stringify` round-trips losslessly and a per-language runtime can execute it
|
|
66
|
+
* with bc + a SQL driver alone.
|
|
67
|
+
*/
|
|
68
|
+
export interface StaticBundle {
|
|
69
|
+
readonly dialect: Dialect;
|
|
70
|
+
/** The behavior (component) name. */
|
|
71
|
+
readonly name: string;
|
|
72
|
+
/** Ordered `makeSQL` statement templates composed into the read query. */
|
|
73
|
+
readonly statements: readonly StaticStatement[];
|
|
74
|
+
/** Input heads normalized to present-as-null (absent-key SKIP; SSoT-driven). */
|
|
75
|
+
readonly optionalHeads: readonly string[];
|
|
76
|
+
}
|
|
77
|
+
type RefLike = ComponentRefNode | MapNode;
|
|
78
|
+
/**
|
|
79
|
+
* Compile ONE authored `Select` node into its static `makeSQL` statement templates:
|
|
80
|
+
* the head `SELECT … FROM t` fragment plus one guarded WHERE fragment per member, then the
|
|
81
|
+
* trailing GROUP BY / ORDER BY / LIMIT / OFFSET tail. The head + GROUP BY + ORDER BY TEXT is
|
|
82
|
+
* produced by the ORIGINAL `compileSelect` (which reproduces `_buildSelectSQL` byte-for-byte),
|
|
83
|
+
* never a v2 hand-roll. LIMIT/OFFSET are INLINE literals in v1; for the static bundle they are
|
|
84
|
+
* deferred value-specs bound as `?` (a portable equivalent a per-language runtime renders
|
|
85
|
+
* identically) — evaluated at runtime.
|
|
86
|
+
*/
|
|
87
|
+
export declare function compileSelectNode(node: RefLike, dialect: Dialect): StaticStatement[];
|
|
88
|
+
/**
|
|
89
|
+
* Compile the primary CRUD query of an authored behavior method into a {@link StaticBundle}.
|
|
90
|
+
* Relation `.map` nodes are NOT part of the primary bundle (they are the read-relations concern
|
|
91
|
+
* — step 3, still on the reduced spine). The compile is SYMBOLIC (no concrete input); the runtime
|
|
92
|
+
* ({@link executeStaticBundle} for reads / {@link executeStaticWrite} for writes) evaluates skip +
|
|
93
|
+
* value-specs per-input.
|
|
94
|
+
*/
|
|
95
|
+
export declare function compileStaticBundle(contract: BehaviorModelContract, dialect: Dialect, entry?: string): StaticBundle;
|
|
96
|
+
/** The minimal synchronous SQLite driver surface (better-sqlite3 `Database`). */
|
|
97
|
+
export interface SqliteDb {
|
|
98
|
+
prepare(sql: string): {
|
|
99
|
+
all(...params: unknown[]): unknown[];
|
|
100
|
+
run(...params: unknown[]): {
|
|
101
|
+
changes: number;
|
|
102
|
+
lastInsertRowid: number | bigint;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Execute a {@link StaticBundle} read query end-to-end against real SQLite: normalize optional
|
|
108
|
+
* heads, evaluate skip + value-specs per-input, assemble present fragments, render, and run the
|
|
109
|
+
* SELECT. Returns the row list.
|
|
110
|
+
*/
|
|
111
|
+
export declare function executeStaticBundle(bundle: StaticBundle, input: Scope, db: SqliteDb): Record<string, unknown>[];
|
|
112
|
+
/**
|
|
113
|
+
* Execute a single-statement WRITE {@link StaticBundle} (Insert/Update/Delete) against real
|
|
114
|
+
* SQLite: evaluate the deferred value-specs per-input, render, and run the statement. A statement
|
|
115
|
+
* with a RETURNING tail returns its rows; a non-returning write returns a single-row summary
|
|
116
|
+
* `[{ changes, lastInsertRowid }]`. A driver error maps to a {@link SqlFailure} at the boundary.
|
|
117
|
+
* (A Command with write-time relations rides the tx-DAG plan of `./tx`, not this path.)
|
|
118
|
+
*/
|
|
119
|
+
export declare function executeStaticWrite(bundle: StaticBundle, input: Scope, db: SqliteDb): Record<string, unknown>[];
|
|
120
|
+
/**
|
|
121
|
+
* The compiled, portable READ graph of a behavior method: the surrogate bc `ComponentGraphIR`
|
|
122
|
+
* (each SQL node → a `makeSQL` node with one `__scope` port; wiring / map / Φ output preserved)
|
|
123
|
+
* plus the per-node static statement templates and the optional heads. Pure JSON —
|
|
124
|
+
* `JSON.stringify` round-trips, so a per-language runtime executes it with bc + a SQL driver.
|
|
125
|
+
*/
|
|
126
|
+
export interface ReadGraph {
|
|
127
|
+
readonly dialect: Dialect;
|
|
128
|
+
readonly name: string;
|
|
129
|
+
/** The surrogate bc IR (catalog nodes → `makeSQL` `__scope`-port nodes). */
|
|
130
|
+
readonly ir: ComponentGraphIR;
|
|
131
|
+
/** Per-node static `makeSQL` statement templates, keyed by body node id. */
|
|
132
|
+
readonly statementsById: Record<string, readonly StaticStatement[]>;
|
|
133
|
+
/** Input heads normalized to present-as-null (absent-key SKIP; SSoT-driven). */
|
|
134
|
+
readonly optionalHeads: readonly string[];
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Compile a READ behavior method into a portable {@link ReadGraph}: rewrite each authored SQL
|
|
138
|
+
* body node to a `makeSQL` node carrying a synthetic `__scope` port (bc evaluates it in-scope),
|
|
139
|
+
* and compile each node's static statements ONCE. SYMBOLIC — no concrete input. bc will own map
|
|
140
|
+
* iteration / wire binding / Φ output at execute time; the handler renders each node's statements.
|
|
141
|
+
*/
|
|
142
|
+
export declare function compileReadGraph(contract: BehaviorModelContract, dialect: Dialect, entry?: string): ReadGraph;
|
|
143
|
+
/**
|
|
144
|
+
* Execute a compiled {@link ReadGraph} via bc `runBehavior` + a makeSQL handler: bc drives map
|
|
145
|
+
* iteration / wire binding / Φ output; the handler renders each node's static statements against
|
|
146
|
+
* the evaluated `__scope` and runs REAL SQLite. Returns the component's Φ output. This is the
|
|
147
|
+
* design's "bc composes, makeSQL executes" — the SAME path a per-language runtime follows.
|
|
148
|
+
*/
|
|
149
|
+
export declare function executeReadGraph(graph: ReadGraph, input: Scope, db: SqliteDb): Value;
|
|
150
|
+
/** An async driver seam: run a rendered `{ sql, params }` and resolve to result rows (#40). */
|
|
151
|
+
export type SqlExecutorAsync = (sql: string, params: unknown[]) => Promise<Record<string, unknown>[]>;
|
|
152
|
+
/**
|
|
153
|
+
* Async twin of {@link executeReadGraph} — the PG / MySQL execution model (#40).
|
|
154
|
+
*
|
|
155
|
+
* Byte-identical composition (SAME IR, SAME per-node SQL text + params, SAME Φ output), but bc's
|
|
156
|
+
* `runBehaviorAsync` drives it: the makeSQL handler returns a Promise, and bc dispatches the
|
|
157
|
+
* INDEPENDENT sibling nodes of a plan stage on `runPlanAsync`'s bounded-parallel path (bc#23),
|
|
158
|
+
* bounded by the plan's `concurrency` (default 16). Against a pooled async driver (`pg` / `mysql2`,
|
|
159
|
+
* each `exec` call resolving on its own pooled connection), that becomes REAL parallel read-relation
|
|
160
|
+
* DB I/O — the plan's declared concurrency finally cashes out as concurrent dispatch. The result is
|
|
161
|
+
* deterministic (bc commits stage outcomes in declaration order), so it equals the serial
|
|
162
|
+
* `executeReadGraph` output exactly; only the wall-clock changes.
|
|
163
|
+
*
|
|
164
|
+
* The conformance bar stays on the SYNC in-proc better-sqlite3 path (`executeReadGraph`); this async
|
|
165
|
+
* path is the live PG/MySQL execution model and is proven by the latency-injecting concurrency test.
|
|
166
|
+
*/
|
|
167
|
+
export declare function executeReadGraphAsync(graph: ReadGraph, input: Scope, exec: SqlExecutorAsync): Promise<Value>;
|
|
168
|
+
/**
|
|
169
|
+
* Convenience: compile + execute a READ behavior method whose output may be a Φ-merge of SQL
|
|
170
|
+
* nodes (including relation `.map` nodes). Equivalent to `executeReadGraph(compileReadGraph(...))`.
|
|
171
|
+
*/
|
|
172
|
+
export declare function executeReadBehavior(contract: BehaviorModelContract, input: Scope, dialect: Dialect, db: SqliteDb, entry?: string): Value;
|
|
173
|
+
/**
|
|
174
|
+
* Render the PRIMARY read node's statements of a {@link ReadGraph} against an input scope to its
|
|
175
|
+
* dialect SQL text + bound params (the render axis for conformance golden). The primary node is
|
|
176
|
+
* the first non-map body node (the root SELECT the relations map over). Optional heads are
|
|
177
|
+
* normalized to present-as-null first (absent-key SKIP), so an omitted optional head renders the
|
|
178
|
+
* SAME text a runtime would produce.
|
|
179
|
+
*/
|
|
180
|
+
export declare function renderReadPrimary(graph: ReadGraph, input: Scope): {
|
|
181
|
+
sql: string;
|
|
182
|
+
params: unknown[];
|
|
183
|
+
};
|
|
184
|
+
export {};
|
|
185
|
+
//# sourceMappingURL=static-bundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static-bundle.d.ts","sourceRoot":"","sources":["../../../src/scp/makesql/static-bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAIL,KAAK,KAAK,EACV,KAAK,KAAK,EAEV,KAAK,gBAAgB,EAKtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAa,gBAAgB,EAAE,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAGhG,OAAO,EAAsB,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AAqB7D,6FAA6F;AAC7F,MAAM,MAAM,SAAS,GAAG,OAAO,CAAC;AAEhC;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,kDAAkD;IAClD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,sFAAsF;IACtF,QAAQ,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC;IACtC,2EAA2E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