litedbmodel 2.0.2 → 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.
- package/README.md +7 -0
- package/dist/DBConditions.d.ts.map +1 -1
- package/dist/DBConditions.js +16 -1
- package/dist/DBConditions.js.map +1 -1
- package/dist/DBHandler.d.ts.map +1 -1
- package/dist/DBHandler.js +6 -0
- package/dist/DBHandler.js.map +1 -1
- package/dist/DBModel.d.ts +84 -2
- package/dist/DBModel.d.ts.map +1 -1
- package/dist/DBModel.js +312 -29
- package/dist/DBModel.js.map +1 -1
- package/dist/decorators.d.ts +52 -0
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +127 -24
- package/dist/decorators.js.map +1 -1
- package/dist/drivers/mysql.d.ts.map +1 -1
- package/dist/drivers/mysql.js +12 -2
- package/dist/drivers/mysql.js.map +1 -1
- package/dist/drivers/postgres.d.ts.map +1 -1
- package/dist/drivers/postgres.js +13 -2
- package/dist/drivers/postgres.js.map +1 -1
- package/dist/drivers/sqlite.d.ts +2 -0
- package/dist/drivers/sqlite.d.ts.map +1 -1
- package/dist/drivers/sqlite.js +49 -4
- package/dist/drivers/sqlite.js.map +1 -1
- package/dist/index.cjs +10741 -0
- package/dist/index.d.cts +1 -0
- package/dist/scp/coltype.d.ts +108 -0
- package/dist/scp/coltype.d.ts.map +1 -1
- package/dist/scp/coltype.js +293 -6
- package/dist/scp/coltype.js.map +1 -1
- package/dist/scp/connection-routing.d.ts +312 -0
- package/dist/scp/connection-routing.d.ts.map +1 -0
- package/dist/scp/connection-routing.js +394 -0
- package/dist/scp/connection-routing.js.map +1 -0
- package/dist/scp/dbmodel-runtime.d.ts +101 -0
- package/dist/scp/dbmodel-runtime.d.ts.map +1 -0
- package/dist/scp/dbmodel-runtime.js +174 -0
- package/dist/scp/dbmodel-runtime.js.map +1 -0
- package/dist/scp/decorator-adapter.d.ts +196 -0
- package/dist/scp/decorator-adapter.d.ts.map +1 -0
- package/dist/scp/decorator-adapter.js +286 -0
- package/dist/scp/decorator-adapter.js.map +1 -0
- package/dist/scp/emit/emitter.d.ts +108 -0
- package/dist/scp/emit/emitter.d.ts.map +1 -0
- package/dist/scp/emit/emitter.js +782 -0
- package/dist/scp/emit/emitter.js.map +1 -0
- package/dist/scp/emit/endpoint.d.ts +248 -0
- package/dist/scp/emit/endpoint.d.ts.map +1 -0
- package/dist/scp/emit/endpoint.js +20 -0
- package/dist/scp/emit/endpoint.js.map +1 -0
- package/dist/scp/emit/index.d.ts +11 -0
- package/dist/scp/emit/index.d.ts.map +1 -0
- package/dist/scp/emit/index.js +13 -0
- package/dist/scp/emit/index.js.map +1 -0
- package/dist/scp/errors.d.ts +45 -1
- package/dist/scp/errors.d.ts.map +1 -1
- package/dist/scp/errors.js +47 -1
- package/dist/scp/errors.js.map +1 -1
- package/dist/scp/exec-context.d.ts +390 -0
- package/dist/scp/exec-context.d.ts.map +1 -0
- package/dist/scp/exec-context.js +540 -0
- package/dist/scp/exec-context.js.map +1 -0
- package/dist/scp/grouping.d.ts +32 -0
- package/dist/scp/grouping.d.ts.map +1 -0
- package/dist/scp/grouping.js +0 -0
- package/dist/scp/grouping.js.map +1 -0
- package/dist/scp/index.cjs +6432 -17579
- package/dist/scp/index.d.cts +1 -0
- package/dist/scp/index.d.mts +1 -0
- package/dist/scp/index.d.ts +51 -52
- package/dist/scp/index.d.ts.map +1 -1
- package/dist/scp/index.js +189 -152
- package/dist/scp/index.js.map +1 -1
- package/dist/scp/index.mjs +6067 -3659
- package/dist/scp/leaf-transport.d.ts +50 -0
- package/dist/scp/leaf-transport.d.ts.map +1 -0
- package/dist/scp/leaf-transport.js +92 -0
- package/dist/scp/leaf-transport.js.map +1 -0
- package/dist/scp/leaves.d.ts +174 -0
- package/dist/scp/leaves.d.ts.map +1 -0
- package/dist/scp/leaves.js +287 -0
- package/dist/scp/leaves.js.map +1 -0
- package/dist/scp/limit-config.d.ts +118 -0
- package/dist/scp/limit-config.d.ts.map +1 -0
- package/dist/scp/limit-config.js +126 -0
- package/dist/scp/limit-config.js.map +1 -0
- package/dist/scp/makesql/compile-relation.d.ts +49 -23
- package/dist/scp/makesql/compile-relation.d.ts.map +1 -1
- package/dist/scp/makesql/compile-relation.js +101 -76
- package/dist/scp/makesql/compile-relation.js.map +1 -1
- package/dist/scp/makesql/compile-select.d.ts +45 -10
- package/dist/scp/makesql/compile-select.d.ts.map +1 -1
- package/dist/scp/makesql/compile-select.js +50 -10
- package/dist/scp/makesql/compile-select.js.map +1 -1
- package/dist/scp/makesql/handler.d.ts +1 -1
- package/dist/scp/makesql/handler.d.ts.map +1 -1
- package/dist/scp/makesql/index.d.ts +7 -10
- package/dist/scp/makesql/index.d.ts.map +1 -1
- package/dist/scp/makesql/index.js +19 -30
- package/dist/scp/makesql/index.js.map +1 -1
- package/dist/scp/makesql/json-array.d.ts +65 -0
- package/dist/scp/makesql/json-array.d.ts.map +1 -1
- package/dist/scp/makesql/json-array.js +99 -10
- package/dist/scp/makesql/json-array.js.map +1 -1
- package/dist/scp/makesql/json-batch.d.ts.map +1 -1
- package/dist/scp/makesql/json-batch.js +21 -19
- package/dist/scp/makesql/json-batch.js.map +1 -1
- package/dist/scp/makesql/makesql.d.ts +1 -1
- package/dist/scp/makesql/makesql.d.ts.map +1 -1
- package/dist/scp/makesql/mysql-returning.d.ts +93 -0
- package/dist/scp/makesql/mysql-returning.d.ts.map +1 -0
- package/dist/scp/makesql/mysql-returning.js +215 -0
- package/dist/scp/makesql/mysql-returning.js.map +1 -0
- package/dist/scp/makesql/outtype.d.ts +75 -34
- package/dist/scp/makesql/outtype.d.ts.map +1 -1
- package/dist/scp/makesql/outtype.js +91 -118
- package/dist/scp/makesql/outtype.js.map +1 -1
- package/dist/scp/makesql/pool-executor.d.ts +135 -13
- package/dist/scp/makesql/pool-executor.d.ts.map +1 -1
- package/dist/scp/makesql/pool-executor.js +229 -21
- package/dist/scp/makesql/pool-executor.js.map +1 -1
- package/dist/scp/makesql/tx.d.ts +107 -22
- package/dist/scp/makesql/tx.d.ts.map +1 -1
- package/dist/scp/makesql/tx.js +451 -97
- package/dist/scp/makesql/tx.js.map +1 -1
- package/dist/scp/makesql/writeouttype.d.ts +7 -8
- package/dist/scp/makesql/writeouttype.d.ts.map +1 -1
- package/dist/scp/makesql/writeouttype.js +8 -7
- package/dist/scp/makesql/writeouttype.js.map +1 -1
- package/dist/scp/middleware.d.ts +287 -0
- package/dist/scp/middleware.d.ts.map +1 -0
- package/dist/scp/middleware.js +358 -0
- package/dist/scp/middleware.js.map +1 -0
- package/dist/scp/relation.d.ts +80 -9
- package/dist/scp/relation.d.ts.map +1 -1
- package/dist/scp/relation.js +198 -78
- package/dist/scp/relation.js.map +1 -1
- package/dist/scp/tx-options.d.ts +136 -0
- package/dist/scp/tx-options.d.ts.map +1 -0
- package/dist/scp/tx-options.js +184 -0
- package/dist/scp/tx-options.js.map +1 -0
- package/dist/scp/write-bundle.d.ts +131 -0
- package/dist/scp/write-bundle.d.ts.map +1 -0
- package/dist/scp/write-bundle.js +160 -0
- package/dist/scp/write-bundle.js.map +1 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/docs/BENCHMARK.md +58 -56
- package/docs/benchmark-chart.svg +166 -166
- package/docs/design/phase-a-execution-context.md +139 -0
- package/package.json +16 -9
- package/dist/scp/authoring-sql.d.ts +0 -134
- package/dist/scp/authoring-sql.d.ts.map +0 -1
- package/dist/scp/authoring-sql.js +0 -191
- package/dist/scp/authoring-sql.js.map +0 -1
- package/dist/scp/authoring.d.ts +0 -155
- package/dist/scp/authoring.d.ts.map +0 -1
- package/dist/scp/authoring.js +0 -162
- package/dist/scp/authoring.js.map +0 -1
- package/dist/scp/catalog.d.ts +0 -94
- package/dist/scp/catalog.d.ts.map +0 -1
- package/dist/scp/catalog.js +0 -234
- package/dist/scp/catalog.js.map +0 -1
- package/dist/scp/codegen.d.ts +0 -189
- package/dist/scp/codegen.d.ts.map +0 -1
- package/dist/scp/codegen.js +0 -421
- package/dist/scp/codegen.js.map +0 -1
- package/dist/scp/find-filter-guard.d.ts +0 -68
- package/dist/scp/find-filter-guard.d.ts.map +0 -1
- package/dist/scp/find-filter-guard.js +0 -88
- package/dist/scp/find-filter-guard.js.map +0 -1
- package/dist/scp/guard.d.ts +0 -43
- package/dist/scp/guard.d.ts.map +0 -1
- package/dist/scp/guard.js +0 -134
- package/dist/scp/guard.js.map +0 -1
- package/dist/scp/makesql/authoring-compile.d.ts +0 -90
- package/dist/scp/makesql/authoring-compile.d.ts.map +0 -1
- package/dist/scp/makesql/authoring-compile.js +0 -494
- package/dist/scp/makesql/authoring-compile.js.map +0 -1
- package/dist/scp/makesql/ir.d.ts +0 -42
- package/dist/scp/makesql/ir.d.ts.map +0 -1
- package/dist/scp/makesql/ir.js +0 -66
- package/dist/scp/makesql/ir.js.map +0 -1
- package/dist/scp/makesql/static-bundle.d.ts +0 -187
- package/dist/scp/makesql/static-bundle.d.ts.map +0 -1
- package/dist/scp/makesql/static-bundle.js +0 -1113
- package/dist/scp/makesql/static-bundle.js.map +0 -1
- package/dist/scp/runtime.d.ts +0 -242
- package/dist/scp/runtime.d.ts.map +0 -1
- package/dist/scp/runtime.js +0 -400
- package/dist/scp/runtime.js.map +0 -1
|
@@ -1,130 +1,118 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* litedbmodel v2 SCP —
|
|
3
|
+
* litedbmodel v2 SCP — read-row de-box type derivation (spec §4.1; issues #58/#59).
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* notation). WITHOUT them the emitter hard-fails ("nothing to de-box") — the correct fail-closed
|
|
8
|
-
* behavior. This module derives those annotations for a READ component from:
|
|
5
|
+
* The read-column coverage + de-box SSoT for the op-independent leaf path. It resolves a read's
|
|
6
|
+
* projection ONCE into two projections of the SAME column-type resolution:
|
|
9
7
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
8
|
+
* - {@link deriveReadRow} — the read ROW `{arr:{obj:{outputKey: <read-de-boxed scalar>}}}` (the
|
|
9
|
+
* bc `outType` bc's native emitter reads for the typed de-box, #154) PLUS the TS-leaf
|
|
10
|
+
* `materializers` coercion map. Array columns read as `{arr:<element>}` (the SSoT array split
|
|
11
|
+
* {@link import('../coltype').arrayElementType}); the element rides the SAME de-box scalar.
|
|
12
|
+
* - {@link outputType} — composes the component `outputType` by walking the `output` Φ-expression
|
|
13
|
+
* against a `nodeId → outType` map.
|
|
16
14
|
*
|
|
17
|
-
* Spec §4.1 discipline: an ambiguous/unmappable projection is a HARD ERROR (no-assume,
|
|
18
|
-
*
|
|
19
|
-
* THROWS
|
|
15
|
+
* Spec §4.1 discipline: an ambiguous/unmappable projection is a HARD ERROR (no-assume, no-fallback)
|
|
16
|
+
* — a `*` projection, a computed column (typed reads only), or an undeclared/unknown-type column
|
|
17
|
+
* THROWS via {@link parseProjectionColumn} + the coltype SSoT; never a boxed/untyped output.
|
|
20
18
|
*/
|
|
21
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.
|
|
23
|
-
exports.
|
|
20
|
+
exports.parseProjectionColumn = parseProjectionColumn;
|
|
21
|
+
exports.deriveReadRow = deriveReadRow;
|
|
22
|
+
exports.outputType = outputType;
|
|
24
23
|
const coltype_1 = require("../coltype");
|
|
25
24
|
const tx_1 = require("./tx");
|
|
26
|
-
/**
|
|
27
|
-
* Narrow a {@link BcScalar} to a bc {@link PortableScalarType}. `BcScalar`'s members
|
|
28
|
-
* (`string|int|float|bool|null`) are exactly bc 0.3.0's portable scalar notation, so this is an
|
|
29
|
-
* identity narrow. DATE/TIMESTAMP columns map to `string` at the `sqlTypeToBcScalar` layer (spec
|
|
30
|
-
* §4.1 owner decision; bc has no `date` scalar — behavior-contracts#84 deferred), so no `date`
|
|
31
|
-
* scalar ever reaches here.
|
|
32
|
-
*/
|
|
33
|
-
function toPortableScalar(scalar, _table, _column) {
|
|
34
|
-
return scalar;
|
|
35
|
-
}
|
|
36
|
-
function isMap(n) {
|
|
37
|
-
return 'map' in n;
|
|
38
|
-
}
|
|
39
|
-
/** The `{component, ports}` of a body node (unwrapping a `.map`). */
|
|
40
|
-
function nodeRef(n) {
|
|
41
|
-
return isMap(n) ? { component: n.map.component, ports: n.map.ports } : { component: n.component, ports: n.ports };
|
|
42
|
-
}
|
|
43
25
|
function opKey(node) {
|
|
44
26
|
if (node === null || typeof node !== 'object' || Array.isArray(node))
|
|
45
27
|
return undefined;
|
|
46
28
|
const keys = Object.keys(node);
|
|
47
29
|
return keys.length === 1 ? keys[0] : undefined;
|
|
48
30
|
}
|
|
49
|
-
/** Read a required literal string port, or throw (the projection SoT must be a literal in the IR). */
|
|
50
|
-
function stringPort(ports, name) {
|
|
51
|
-
const v = ports[name];
|
|
52
|
-
if (v === undefined)
|
|
53
|
-
return undefined;
|
|
54
|
-
if (typeof v !== 'string') {
|
|
55
|
-
throw new Error(`outtype: port '${name}' must be a literal string in the IR (got ${JSON.stringify(v)})`);
|
|
56
|
-
}
|
|
57
|
-
return v;
|
|
58
|
-
}
|
|
59
|
-
/** Read a literal `{arr:[str,…]}` string-list port (the SELECT projection). */
|
|
60
|
-
function stringArrayPort(ports, name) {
|
|
61
|
-
const v = ports[name];
|
|
62
|
-
if (v === undefined)
|
|
63
|
-
return undefined;
|
|
64
|
-
if (typeof v === 'object' && v !== null && 'arr' in v && Array.isArray(v.arr)) {
|
|
65
|
-
return v.arr.map((e) => {
|
|
66
|
-
if (typeof e !== 'string')
|
|
67
|
-
throw new Error(`outtype: '${name}' entries must be literal strings (got ${JSON.stringify(e)})`);
|
|
68
|
-
return e;
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
throw new Error(`outtype: port '${name}' must be an {arr:[…]} literal in the IR (got ${JSON.stringify(v)})`);
|
|
72
|
-
}
|
|
73
31
|
/**
|
|
74
|
-
* The
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
32
|
+
* The SINGLE projection-column parser (issue #59) — shared by BOTH the codegen `outType` derivation
|
|
33
|
+
* and the TS read-path materializer derivation so the two CANNOT diverge (the recurring source of
|
|
34
|
+
* silent-rounding leaks). Classifies ONE `select`-list entry:
|
|
35
|
+
* - bare `col` → `{ kind:'column', underlying:'col', outputKey:'col' }`.
|
|
36
|
+
* - qualified `t.col` → strip qualifier → `underlying:'col', outputKey:'col'`.
|
|
37
|
+
* - aliased `col AS b` / `t.col AS b` → `underlying:'col', outputKey:'b'` (the driver row key).
|
|
38
|
+
* - computed `COUNT(*)`, `NOW()`, `x::uuid`, `x+1`, aliased or not → `{ kind:'computed', text }`.
|
|
39
|
+
* - `*` / `t.*` → HARD ERROR (the concrete column list is unknown).
|
|
40
|
+
* A SCHEMA-column entry MUST be typed against the declaration (a caller resolves + fail-closes on an
|
|
41
|
+
* undeclared column → never a silent rounded-i64 leak). A COMPUTED entry has no schema column to
|
|
42
|
+
* round: the read path leaves it raw; the codegen path (which needs every struct field typed) rejects
|
|
43
|
+
* it. This ONE parser guarantees every shape is classified identically for both paths.
|
|
78
44
|
*/
|
|
79
|
-
function
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
45
|
+
function parseProjectionColumn(col, table, at) {
|
|
46
|
+
const raw = col.trim();
|
|
47
|
+
if (raw === '*' || raw.endsWith('.*')) {
|
|
48
|
+
throw new Error(`outtype: ${at}: SELECT on '${table}' projects '${raw}' (a wildcard). A typed de-box needs the ` +
|
|
49
|
+
`concrete column list to build the row struct + type each column — spec §4.1 is column-typed. ` +
|
|
83
50
|
`Project explicit columns (no-assume, no-fallback).`);
|
|
84
51
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
`to a SQL type. No-assume, no-fallback.`);
|
|
93
|
-
}
|
|
94
|
-
if (col in obj)
|
|
95
|
-
throw new Error(`outtype: ${at}: duplicate projected column '${col}' on '${table}'`);
|
|
96
|
-
// sqlTypeToBcScalar throws on an unknown/ambiguous SQL type — fail-closed by construction.
|
|
97
|
-
obj[col] = toPortableScalar((0, coltype_1.sqlTypeToBcScalar)(resolveColumnType(table, col)), table, col);
|
|
52
|
+
// Split off an `AS <alias>` (case-insensitive; alias must be a bare identifier).
|
|
53
|
+
let expr = raw;
|
|
54
|
+
let alias;
|
|
55
|
+
const asMatch = /^(.*?)\s+AS\s+([A-Za-z_][A-Za-z0-9_]*)$/i.exec(raw);
|
|
56
|
+
if (asMatch !== null) {
|
|
57
|
+
expr = asMatch[1].trim();
|
|
58
|
+
alias = asMatch[2];
|
|
98
59
|
}
|
|
99
|
-
|
|
60
|
+
// A bare or qualified column reference — `col` or `qual.col` (identifiers only) — is a SCHEMA
|
|
61
|
+
// column. The qualifier (if present) names the column's OWNER table (a JOIN column), against which
|
|
62
|
+
// its type resolves; without a qualifier the column belongs to the node's base table.
|
|
63
|
+
const refMatch = /^(?:([A-Za-z_][A-Za-z0-9_]*)\.)?([A-Za-z_][A-Za-z0-9_]*)$/.exec(expr);
|
|
64
|
+
if (refMatch !== null) {
|
|
65
|
+
const qualifier = refMatch[1];
|
|
66
|
+
const underlying = refMatch[2];
|
|
67
|
+
return { kind: 'column', underlying, outputKey: alias ?? underlying, ...(qualifier !== undefined ? { qualifier } : {}) };
|
|
68
|
+
}
|
|
69
|
+
// Anything else (a function call `f(x)`, an aggregate `COUNT(*)`, a cast `x::uuid`, arithmetic, a
|
|
70
|
+
// literal) is a COMPUTED expression — no underlying schema column, so it cannot round an i64. The
|
|
71
|
+
// read path leaves it raw; the codegen path rejects it (it needs a concrete field type).
|
|
72
|
+
return { kind: 'computed', text: raw };
|
|
100
73
|
}
|
|
101
74
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
75
|
+
* Derive the read ROW from a projection (#141 SSoT + #59 op-builder guard). Resolves each projected
|
|
76
|
+
* column ONCE via the SHARED {@link parseProjectionColumn} + the coltype SSoT, producing BOTH:
|
|
77
|
+
* - `outType` — `{arr:{obj:{outputKey: keyArrayElemScalar(sqlType)}}}`, the READ-DE-BOXED scalar
|
|
78
|
+
* (int32→`float`(number) / BIGINT→`string` / BOOLEAN→`bool` / DATE→`string` / text/uuid→`string`).
|
|
79
|
+
* This is the ONE row-type representation: bc's native emitter reads it for the typed de-box
|
|
80
|
+
* (#154), and it is the conform target the TS leaf coercion below produces.
|
|
81
|
+
* - `materializers` — the TS-leaf coercion map ({@link sqlTypeToMaterializeClass}); the leaf coerces
|
|
82
|
+
* each driver cell (BIGINT→exact string / DATE→string / BOOLEAN→boolean) so the row MATCHES `outType`
|
|
83
|
+
* before bc conforms it (bc conform VALIDATES, does not coerce). Derived from the SAME resolution as
|
|
84
|
+
* `outType`, so the coerced JS form always equals the declared read scalar — no second row type.
|
|
85
|
+
* This IS the #59 read-column coverage guard: `*`/`t.*` throws (unknown column list), an undeclared
|
|
86
|
+
* column or unknown SQL type throws. A COMPUTED projection (`COUNT(*)`, cast, literal) is left RAW
|
|
87
|
+
* (omitted from BOTH) — #59: "the read path leaves it raw".
|
|
107
88
|
*/
|
|
108
|
-
function
|
|
109
|
-
const
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
//
|
|
120
|
-
//
|
|
121
|
-
//
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
89
|
+
function deriveReadRow(table, projection, resolveColumnType, at) {
|
|
90
|
+
const obj = {};
|
|
91
|
+
const materializers = {};
|
|
92
|
+
for (const col of projection) {
|
|
93
|
+
const entry = parseProjectionColumn(col, table, at); // throws on `*` / `t.*`
|
|
94
|
+
if (entry.kind === 'computed')
|
|
95
|
+
continue; // computed column: read raw (no de-box / no typed field), #59
|
|
96
|
+
const { underlying, outputKey, qualifier } = entry;
|
|
97
|
+
const owner = qualifier ?? table;
|
|
98
|
+
const sqlType = resolveColumnType(owner, underlying); // undeclared → throw
|
|
99
|
+
// A read cell is nullable UNLESS `static columns` declares the column `NOT NULL` — a driver column
|
|
100
|
+
// may be NULL, so the read scalar rides under `opt` (bc conforms `null`/absent OR the de-boxed
|
|
101
|
+
// scalar). A `NOT NULL` column is non-null by SQL contract → the raw scalar (no `opt`), so a
|
|
102
|
+
// RETURNING primary key can be consumed in a value position (a `.map` param) without an
|
|
103
|
+
// optional-narrowing coalesce (spec §4.1 nullability — the SSoT is the declared column constraint).
|
|
104
|
+
// Array-aware (F2 #105): a projected ARRAY column reads as a `{arr:<de-boxed element>}` list (the
|
|
105
|
+
// driver hands over a JS array; the whole value is passthrough — see `sqlTypeToMaterializeClass`),
|
|
106
|
+
// a scalar column as its read-de-boxed scalar. SSoT array split ({@link arrayElementType}); the
|
|
107
|
+
// element rides the SAME `keyArrayElemScalar` de-box as a scalar column (throws on unknown type).
|
|
108
|
+
const element = (0, coltype_1.arrayElementType)(sqlType);
|
|
109
|
+
const scalar = element !== null ? { arr: (0, coltype_1.keyArrayElemScalar)(element) } : (0, coltype_1.keyArrayElemScalar)(sqlType);
|
|
110
|
+
obj[outputKey] = (0, coltype_1.sqlTypeIsNotNull)(sqlType) ? scalar : { opt: scalar };
|
|
111
|
+
const klass = (0, coltype_1.sqlTypeToMaterializeClass)(sqlType);
|
|
112
|
+
if (klass !== 'passthrough')
|
|
113
|
+
materializers[outputKey] = klass; // omit passthrough (no-op coercion)
|
|
125
114
|
}
|
|
126
|
-
|
|
127
|
-
`A write / unknown node cannot be de-boxed here — no-assume, no-fallback.`);
|
|
115
|
+
return { outType: { arr: { obj } }, materializers };
|
|
128
116
|
}
|
|
129
117
|
/**
|
|
130
118
|
* Derive the component `outputType` by walking the `output` Φ-expression against a `nodeId →
|
|
@@ -179,19 +167,4 @@ function outputType(output, byNode, at) {
|
|
|
179
167
|
`(ref / obj / arr / opt of node results). The typed de-box path does not build a dynamic ` +
|
|
180
168
|
`Value output tree — no-assume, no-fallback.`);
|
|
181
169
|
}
|
|
182
|
-
/**
|
|
183
|
-
* Per-node `outType` (keyed by body node id) + the component `outputType`, derived for a READ
|
|
184
|
-
* component (spec §4.1). `cond` nodes are skipped for the per-node map but a `cond` at the OUTPUT
|
|
185
|
-
* position (a shared-branch merge) would be handled by {@link outputType} if reached — the bench's
|
|
186
|
-
* read outputs are ref / obj compositions of Select nodes. Any ambiguity throws (fail-closed).
|
|
187
|
-
*/
|
|
188
|
-
function deriveReadOutTypes(component, resolveColumnType) {
|
|
189
|
-
const byNode = new Map();
|
|
190
|
-
for (const n of component.body) {
|
|
191
|
-
if ('cond' in n)
|
|
192
|
-
continue; // a cond node carries no SELECT projection; it is typed by its branch
|
|
193
|
-
byNode.set(n.id, nodeOutType(n, resolveColumnType));
|
|
194
|
-
}
|
|
195
|
-
return { byNode, outputType: outputType(component.output, byNode, `component '${component.name}' output`) };
|
|
196
|
-
}
|
|
197
170
|
//# sourceMappingURL=outtype.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outtype.js","sourceRoot":"","sources":["../../../src/scp/makesql/outtype.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"outtype.js","sourceRoot":"","sources":["../../../src/scp/makesql/outtype.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;AA+CH,sDA8BC;AA0BD,sCA8BC;AASD,gCA6CC;AAxLD,wCAA+J;AAC/J,6BAAmC;AAGnC,SAAS,KAAK,CAAC,IAAa;IAC1B,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;QAAE,OAAO,SAAS,CAAC;IACvF,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAc,CAAC,CAAC;IACzC,OAAO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MAA2B,CAAC,GAAG,CAAC;QAC/C,OAAO,EAAE,GAAG,EAAE,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,CAAC;IACzD,CAAC;IACD,MAAM,IAAI,KAAK,CACb,YAAY,EAAE,uBAAuB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,8BAA8B;QACvF,0FAA0F;QAC1F,6CAA6C,CAChD,CAAC;AACJ,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* litedbmodel v2 SCP — pooled async `
|
|
2
|
+
* litedbmodel v2 SCP — pooled async `SqlExecutor` factories for PG / MySQL (#40).
|
|
3
3
|
*
|
|
4
4
|
* The read-graph async execution model (`executeReadGraphAsync`) dispatches independent sibling
|
|
5
5
|
* relations in bounded parallel via bc `runBehaviorAsync`. For that concurrency to become REAL
|
|
6
6
|
* parallel DB I/O the driver seam must be an async CONNECTION POOL — each concurrent `exec` call
|
|
7
7
|
* checks out a DISTINCT pooled connection. These factories adapt a `pg.Pool` / `mysql2` pool to the
|
|
8
|
-
* {@link
|
|
8
|
+
* {@link SqlExecutor} seam.
|
|
9
9
|
*
|
|
10
10
|
* The read graph already renders the dialect placeholder form (`$N` for postgres, `?` for
|
|
11
11
|
* MySQL/SQLite, via `renderPlaceholders`) and flattens params 1:1, so each executor is a THIN
|
|
@@ -16,7 +16,54 @@
|
|
|
16
16
|
* `pg` / `mysql2` are optional peer dependencies loaded dynamically — importing this module does not
|
|
17
17
|
* force either into a consumer that only uses the sync better-sqlite3 conformance path.
|
|
18
18
|
*/
|
|
19
|
-
import type {
|
|
19
|
+
import type { AsyncConnectionPool } from '../exec-context';
|
|
20
|
+
import type { PoolFactory } from '../connection-routing';
|
|
21
|
+
/** The minimal `pg.types` surface: register a per-OID text parser. */
|
|
22
|
+
export interface PgTypesLike {
|
|
23
|
+
setTypeParser(oid: number, parser: (value: string) => unknown): void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Register `pg` type parsers so the read-path de-box (issue #59) gets coercible values: the
|
|
27
|
+
* DATE/TIMESTAMP/TIMESTAMPTZ/TIME family is returned as its NATIVE TEXTUAL string (NOT a JS Date),
|
|
28
|
+
* honoring the `date→string` outType and carrying the TZ for timestamptz; and the int2/int4/int8 family
|
|
29
|
+
* as a BigInt, the TS plane's `int` value model. Idempotent. Call ONCE, before building the pool, from
|
|
30
|
+
* the consumer that owns the `pg` module (`import { types } from 'pg'; configurePgDeboxTypeParsers(types)`).
|
|
31
|
+
*
|
|
32
|
+
* WHY the GLOBAL parser (a documented, deliberate exception): `pg`'s default DATE parser builds a JS
|
|
33
|
+
* `Date` at LOCAL midnight, which shifts the UTC CALENDAR DAY (e.g. `2026-07-14` → a Date whose UTC
|
|
34
|
+
* day is `2026-07-13`). That loss happens INSIDE the driver, BEFORE the materializer sees the value —
|
|
35
|
+
* so materializer-side coercion CANNOT recover the correct calendar day from the already-shifted
|
|
36
|
+
* Date. Reading the native text (this parser) is the only lossless option, and `pg` exposes type
|
|
37
|
+
* parsers only at module (process-global) scope. It is set ONCE at pool creation, not per read. The
|
|
38
|
+
* materializer's `Date → ISO string` path remains as a defensive fallback for any driver/config that
|
|
39
|
+
* still slips a Date through, but the correct-day guarantee for pg DATE comes from this parser.
|
|
40
|
+
*/
|
|
41
|
+
export declare function configurePgDeboxTypeParsers(types: PgTypesLike): void;
|
|
42
|
+
/**
|
|
43
|
+
* The `mysql2` pool options the read-path de-box (issue #59) requires: `supportBigNumbers` +
|
|
44
|
+
* `bigNumberStrings` so BIGINT arrives as an EXACT string (→ bigint; a plain number would already
|
|
45
|
+
* have rounded it), and `dateStrings` so the DATE/TIMESTAMP/DATETIME family arrives as its native
|
|
46
|
+
* textual string (→ the `date→string` outType, NOT a JS Date). Spread into `mysql.createPool(...)`.
|
|
47
|
+
*/
|
|
48
|
+
export declare const mysqlDeboxPoolOptions: {
|
|
49
|
+
readonly supportBigNumbers: true;
|
|
50
|
+
readonly bigNumberStrings: true;
|
|
51
|
+
readonly dateStrings: true;
|
|
52
|
+
/**
|
|
53
|
+
* An INTEGER column must arrive in bc's `int` value model — a BigInt on the TS plane. `mysql2` hands
|
|
54
|
+
* back a JS number for TINY/SHORT/INT24/LONG (only BIGINT becomes a string, via `bigNumberStrings`),
|
|
55
|
+
* and bc classifies a JS number as FLOAT, so a column declared `Int` failed its outType check with
|
|
56
|
+
* `expected int, got float`. The FIELD TYPE decides, never the value: a DOUBLE/DECIMAL column whose
|
|
57
|
+
* value happens to be integral still arrives as a float. sqlite gets the same guarantee from
|
|
58
|
+
* better-sqlite3's `safeIntegers`, PostgreSQL from {@link configurePgDeboxTypeParsers}'s int OIDs.
|
|
59
|
+
*/
|
|
60
|
+
readonly typeCast: (field: MysqlFieldLike, next: () => unknown) => unknown;
|
|
61
|
+
};
|
|
62
|
+
/** The `mysql2` field surface `typeCast` reads: the column's declared type and its raw text. */
|
|
63
|
+
export interface MysqlFieldLike {
|
|
64
|
+
readonly type: string;
|
|
65
|
+
string(): string | null;
|
|
66
|
+
}
|
|
20
67
|
/** The minimal `pg.Pool` surface we need: `query(text, values)` resolving `{ rows }`. */
|
|
21
68
|
export interface PgPoolLike {
|
|
22
69
|
query(text: string, values?: unknown[]): Promise<{
|
|
@@ -27,15 +74,6 @@ export interface PgPoolLike {
|
|
|
27
74
|
export interface MysqlPoolLike {
|
|
28
75
|
query(sql: string, values?: unknown[]): Promise<[Record<string, unknown>[], unknown]>;
|
|
29
76
|
}
|
|
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
77
|
/**
|
|
40
78
|
* Adapt a `mysql2/promise` pool to the async executor seam. `pool.query` acquires + releases a
|
|
41
79
|
* pooled connection per call, so concurrent siblings run in parallel. The graph renders `?`
|
|
@@ -43,5 +81,89 @@ export declare function pgPoolExecutor(pool: PgPoolLike): SqlExecutorAsync;
|
|
|
43
81
|
*
|
|
44
82
|
* Recommend `connectionLimit` ≥ the plan's `concurrency` (default 16).
|
|
45
83
|
*/
|
|
46
|
-
|
|
84
|
+
/** Minimal `pg` module surface: a `Pool` ctor + the global `types.setTypeParser`. */
|
|
85
|
+
export interface PgModuleLike {
|
|
86
|
+
Pool: new (config: Record<string, unknown>) => PgPoolLike & {
|
|
87
|
+
end?: () => Promise<void>;
|
|
88
|
+
};
|
|
89
|
+
types: PgTypesLike;
|
|
90
|
+
}
|
|
91
|
+
/** Minimal `mysql2/promise` module surface: `createPool`. */
|
|
92
|
+
export interface Mysql2ModuleLike {
|
|
93
|
+
createPool(config: Record<string, unknown>): MysqlPoolLike & {
|
|
94
|
+
end?: () => Promise<void>;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** A pg `Pool` that hands out an owned `PoolClient` (`connect()` → `release()`). */
|
|
98
|
+
export interface PgOwnedPoolLike {
|
|
99
|
+
connect(): Promise<PgPoolClientLike>;
|
|
100
|
+
}
|
|
101
|
+
/** The pg `PoolClient`: parameterized `query`, and `release(destroy?)` back to the pool. */
|
|
102
|
+
export interface PgPoolClientLike {
|
|
103
|
+
query(text: string, values?: unknown[]): Promise<{
|
|
104
|
+
rows: Record<string, unknown>[];
|
|
105
|
+
rowCount?: number | null;
|
|
106
|
+
}>;
|
|
107
|
+
release(destroy?: boolean): void;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Adapt a pg `Pool` to the {@link AsyncConnectionPool} contract — `acquire` checks out an owned
|
|
111
|
+
* `PoolClient`, `release` returns it (destroyed on a poisoned tx). Feed this to
|
|
112
|
+
* `withTransactionAsync` for per-execution connection ownership.
|
|
113
|
+
*/
|
|
114
|
+
export declare function pgConnectionPool(pool: PgOwnedPoolLike): AsyncConnectionPool;
|
|
115
|
+
/** A mysql2/promise `Pool` that hands out an owned connection (`getConnection()` → `release()`). */
|
|
116
|
+
export interface MysqlOwnedPoolLike {
|
|
117
|
+
getConnection(): Promise<MysqlPoolConnLike>;
|
|
118
|
+
}
|
|
119
|
+
/** A mysql2/promise pooled connection: `query`, and `release()` back to the pool. */
|
|
120
|
+
export interface MysqlPoolConnLike {
|
|
121
|
+
query(sql: string, values?: unknown[]): Promise<[unknown, unknown]>;
|
|
122
|
+
release(): void;
|
|
123
|
+
destroy(): void;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Adapt a mysql2/promise `Pool` to the {@link AsyncConnectionPool} contract — `acquire` checks out
|
|
127
|
+
* an owned connection, `release` returns it (or `destroy`s a poisoned one). Feed this to
|
|
128
|
+
* `withTransactionAsync` for per-execution connection ownership.
|
|
129
|
+
*/
|
|
130
|
+
export declare function mysqlConnectionPool(pool: MysqlOwnedPoolLike): AsyncConnectionPool;
|
|
131
|
+
/** A pg `Pool` the factory constructs: owned-connection surface + `end()` (the closer). */
|
|
132
|
+
export type PgOwnedPoolWithEnd = PgOwnedPoolLike & {
|
|
133
|
+
end(): Promise<void>;
|
|
134
|
+
};
|
|
135
|
+
/** The `pg` module surface the pool factory needs: an OWNED-connection `Pool` ctor + `types`. */
|
|
136
|
+
export interface PgFactoryModuleLike {
|
|
137
|
+
Pool: new (config: Record<string, unknown>) => PgOwnedPoolWithEnd;
|
|
138
|
+
types: PgTypesLike;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* A {@link PoolFactory} for `pg`: constructs a `new pg.Pool(...)` from a {@link ResolvedConnectionConfig},
|
|
142
|
+
* applying the pool SIZING (`max` = `maxPool`, `min` = `minPool`) and `keepAlive` /
|
|
143
|
+
* `keepAliveInitialDelayMillis` AT CONSTRUCTION — the config is the sole source of the cap. Connection
|
|
144
|
+
* params (host/port/database/user/password) also flow from the config. Registers the read-path de-box
|
|
145
|
+
* type parsers (issue #59, global, idempotent) once. Returns the owned-connection adapter + closer.
|
|
146
|
+
*
|
|
147
|
+
* `role` is accepted for the reader/writer replica split; the caller may vary host per role via the
|
|
148
|
+
* config it passes. `Pool` is the `pg.Pool` ctor (peer dep, passed in — this module imports no driver).
|
|
149
|
+
*/
|
|
150
|
+
export declare function pgPoolFactory(pg: PgFactoryModuleLike): PoolFactory;
|
|
151
|
+
/** A mysql2 `Pool` the factory constructs: owned-connection surface + `end()` (the closer). */
|
|
152
|
+
export type MysqlOwnedPoolWithEnd = MysqlOwnedPoolLike & {
|
|
153
|
+
end(): Promise<void>;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* A {@link PoolFactory} for `mysql2/promise`: constructs a `mysql2.createPool(...)` from a
|
|
157
|
+
* {@link ResolvedConnectionConfig}, applying the pool SIZING (`connectionLimit` = `maxPool`) +
|
|
158
|
+
* `enableKeepAlive` / `keepAliveInitialDelay` AT CONSTRUCTION (the config is the sole source of the
|
|
159
|
+
* cap) plus the read-path de-box options ({@link mysqlDeboxPoolOptions}). Connection params flow from
|
|
160
|
+
* the config. Returns the owned-connection adapter + closer.
|
|
161
|
+
*
|
|
162
|
+
* NB: mysql2 has no `min` idle floor — `minPool` is a no-op there (a documented per-driver deviation;
|
|
163
|
+
* the SIZING CAP that matters — `maxPool` → `connectionLimit` — is honored). `createPool` is the
|
|
164
|
+
* `mysql2/promise` factory (peer dep, passed in).
|
|
165
|
+
*/
|
|
166
|
+
export declare function mysqlPoolFactory(mysql2: {
|
|
167
|
+
createPool(config: Record<string, unknown>): MysqlOwnedPoolWithEnd;
|
|
168
|
+
}): PoolFactory;
|
|
47
169
|
//# sourceMappingURL=pool-executor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool-executor.d.ts","sourceRoot":"","sources":["../../../src/scp/makesql/pool-executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"pool-executor.d.ts","sourceRoot":"","sources":["../../../src/scp/makesql/pool-executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAmB,mBAAmB,EAAiB,MAAM,iBAAiB,CAAC;AAC3F,OAAO,KAAK,EAA4B,WAAW,EAAc,MAAM,uBAAuB,CAAC;AAoB/F,sEAAsE;AACtE,MAAM,WAAW,WAAW;IAC1B,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,GAAG,IAAI,CAAC;CACtE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAiBpE;AAED;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB;;;;IAIhC;;;;;;;OAOG;+BACa,cAAc,QAAQ,MAAM,OAAO,KAAG,OAAO;CAOrD,CAAC;AAEX,gGAAgG;AAChG,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,MAAM,IAAI,MAAM,GAAG,IAAI,CAAC;CACzB;AAQD,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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