litedbmodel 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +83 -0
- package/dist/decorators.js.map +1 -1
- package/dist/drivers/mysql.d.ts.map +1 -1
- package/dist/drivers/mysql.js +6 -2
- package/dist/drivers/mysql.js.map +1 -1
- package/dist/drivers/postgres.d.ts.map +1 -1
- package/dist/drivers/postgres.js +6 -2
- package/dist/drivers/postgres.js.map +1 -1
- package/dist/drivers/sqlite.d.ts.map +1 -1
- package/dist/drivers/sqlite.js +12 -2
- 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 +26 -1
- package/dist/scp/coltype.d.ts.map +1 -1
- package/dist/scp/coltype.js +82 -15
- 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 +6814 -15731
- package/dist/scp/index.d.cts +1 -0
- package/dist/scp/index.d.mts +1 -0
- package/dist/scp/index.d.ts +47 -49
- package/dist/scp/index.d.ts.map +1 -1
- package/dist/scp/index.js +174 -152
- package/dist/scp/index.js.map +1 -1
- package/dist/scp/index.mjs +5561 -3704
- 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 -9
- package/dist/scp/makesql/index.d.ts.map +1 -1
- package/dist/scp/makesql/index.js +17 -28
- 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 +15 -18
- 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 +40 -54
- package/dist/scp/makesql/outtype.d.ts.map +1 -1
- package/dist/scp/makesql/outtype.js +46 -204
- package/dist/scp/makesql/outtype.js.map +1 -1
- package/dist/scp/makesql/pool-executor.d.ts +86 -34
- package/dist/scp/makesql/pool-executor.d.ts.map +1 -1
- package/dist/scp/makesql/pool-executor.js +179 -39
- 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 +4 -4
- package/dist/scp/makesql/writeouttype.d.ts.map +1 -1
- package/dist/scp/makesql/writeouttype.js +5 -3
- 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 +65 -8
- package/dist/scp/relation.d.ts.map +1 -1
- package/dist/scp/relation.js +154 -93
- 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/design/phase-a-execution-context.md +139 -0
- package/package.json +14 -13
- 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 -218
- package/dist/scp/authoring.d.ts.map +0 -1
- package/dist/scp/authoring.js +0 -351
- package/dist/scp/authoring.js.map +0 -1
- package/dist/scp/catalog.d.ts +0 -95
- package/dist/scp/catalog.d.ts.map +0 -1
- package/dist/scp/catalog.js +0 -245
- package/dist/scp/catalog.js.map +0 -1
- package/dist/scp/codegen.d.ts +0 -201
- package/dist/scp/codegen.d.ts.map +0 -1
- package/dist/scp/codegen.js +0 -605
- 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 -140
- 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 -505
- package/dist/scp/makesql/authoring-compile.js.map +0 -1
- package/dist/scp/makesql/static-bundle.d.ts +0 -196
- package/dist/scp/makesql/static-bundle.d.ts.map +0 -1
- package/dist/scp/makesql/static-bundle.js +0 -1244
- package/dist/scp/makesql/static-bundle.js.map +0 -1
- package/dist/scp/runtime.d.ts +0 -243
- package/dist/scp/runtime.d.ts.map +0 -1
- package/dist/scp/runtime.js +0 -422
- package/dist/scp/runtime.js.map +0 -1
|
@@ -1,77 +1,33 @@
|
|
|
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
20
|
exports.parseProjectionColumn = parseProjectionColumn;
|
|
23
|
-
exports.
|
|
24
|
-
exports.
|
|
25
|
-
exports.deriveReadOutTypes = deriveReadOutTypes;
|
|
21
|
+
exports.deriveReadRow = deriveReadRow;
|
|
22
|
+
exports.outputType = outputType;
|
|
26
23
|
const coltype_1 = require("../coltype");
|
|
27
24
|
const tx_1 = require("./tx");
|
|
28
|
-
/**
|
|
29
|
-
* Narrow a {@link BcScalar} to a bc {@link PortableScalarType}. `BcScalar`'s members
|
|
30
|
-
* (`string|int|float|bool|null`) are exactly bc 0.3.0's portable scalar notation, so this is an
|
|
31
|
-
* identity narrow. DATE/TIMESTAMP columns map to `string` at the `sqlTypeToBcScalar` layer (spec
|
|
32
|
-
* §4.1 owner decision; bc has no `date` scalar — behavior-contracts#84 deferred), so no `date`
|
|
33
|
-
* scalar ever reaches here.
|
|
34
|
-
*/
|
|
35
|
-
function toPortableScalar(scalar, _table, _column) {
|
|
36
|
-
return scalar;
|
|
37
|
-
}
|
|
38
|
-
function isMap(n) {
|
|
39
|
-
return 'map' in n;
|
|
40
|
-
}
|
|
41
|
-
/** The `{component, ports}` of a body node (unwrapping a `.map`). */
|
|
42
|
-
function nodeRef(n) {
|
|
43
|
-
return isMap(n) ? { component: n.map.component, ports: n.map.ports } : { component: n.component, ports: n.ports };
|
|
44
|
-
}
|
|
45
25
|
function opKey(node) {
|
|
46
26
|
if (node === null || typeof node !== 'object' || Array.isArray(node))
|
|
47
27
|
return undefined;
|
|
48
28
|
const keys = Object.keys(node);
|
|
49
29
|
return keys.length === 1 ? keys[0] : undefined;
|
|
50
30
|
}
|
|
51
|
-
/** Read a required literal string port, or throw (the projection SoT must be a literal in the IR). */
|
|
52
|
-
function stringPort(ports, name) {
|
|
53
|
-
const v = ports[name];
|
|
54
|
-
if (v === undefined)
|
|
55
|
-
return undefined;
|
|
56
|
-
if (typeof v !== 'string') {
|
|
57
|
-
throw new Error(`outtype: port '${name}' must be a literal string in the IR (got ${JSON.stringify(v)})`);
|
|
58
|
-
}
|
|
59
|
-
return v;
|
|
60
|
-
}
|
|
61
|
-
/** Read a literal `{arr:[str,…]}` string-list port (the SELECT projection). */
|
|
62
|
-
function stringArrayPort(ports, name) {
|
|
63
|
-
const v = ports[name];
|
|
64
|
-
if (v === undefined)
|
|
65
|
-
return undefined;
|
|
66
|
-
if (typeof v === 'object' && v !== null && 'arr' in v && Array.isArray(v.arr)) {
|
|
67
|
-
return v.arr.map((e) => {
|
|
68
|
-
if (typeof e !== 'string')
|
|
69
|
-
throw new Error(`outtype: '${name}' entries must be literal strings (got ${JSON.stringify(e)})`);
|
|
70
|
-
return e;
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
throw new Error(`outtype: port '${name}' must be an {arr:[…]} literal in the IR (got ${JSON.stringify(v)})`);
|
|
74
|
-
}
|
|
75
31
|
/**
|
|
76
32
|
* The SINGLE projection-column parser (issue #59) — shared by BOTH the codegen `outType` derivation
|
|
77
33
|
* and the TS read-path materializer derivation so the two CANNOT diverge (the recurring source of
|
|
@@ -116,76 +72,47 @@ function parseProjectionColumn(col, table, at) {
|
|
|
116
72
|
return { kind: 'computed', text: raw };
|
|
117
73
|
}
|
|
118
74
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
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".
|
|
127
88
|
*/
|
|
128
|
-
function
|
|
129
|
-
if (projection === undefined || projection.length === 0) {
|
|
130
|
-
throw new Error(`outtype: ${at}: SELECT on '${table}' has no explicit column projection ('*' / empty). A typed ` +
|
|
131
|
-
`de-box needs the concrete column list to build the row struct — spec §4.1 is column-typed. ` +
|
|
132
|
-
`Project explicit columns (no-assume, no-fallback).`);
|
|
133
|
-
}
|
|
89
|
+
function deriveReadRow(table, projection, resolveColumnType, at) {
|
|
134
90
|
const obj = {};
|
|
91
|
+
const materializers = {};
|
|
135
92
|
for (const col of projection) {
|
|
136
|
-
const entry = parseProjectionColumn(col, table, at);
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (entry.kind === 'computed') {
|
|
140
|
-
throw new Error(`outtype: ${at}: projected expression '${entry.text}' on '${table}' is computed (function / ` +
|
|
141
|
-
`aggregate / cast / literal) and cannot be typed into a concrete row struct field. Typed ` +
|
|
142
|
-
`de-box (spec §4.1) requires bare/qualified/aliased schema columns. No-assume, no-fallback.`);
|
|
143
|
-
}
|
|
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
|
|
144
96
|
const { underlying, outputKey, qualifier } = entry;
|
|
145
|
-
if (outputKey in obj)
|
|
146
|
-
throw new Error(`outtype: ${at}: duplicate projected column key '${outputKey}' on '${table}'`);
|
|
147
|
-
// Resolve against the qualifier's table (a JOIN column) if present, else the node's base table.
|
|
148
97
|
const owner = qualifier ?? table;
|
|
149
|
-
|
|
150
|
-
//
|
|
151
|
-
//
|
|
152
|
-
|
|
153
|
-
|
|
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 };
|
|
154
111
|
const klass = (0, coltype_1.sqlTypeToMaterializeClass)(sqlType);
|
|
155
112
|
if (klass !== 'passthrough')
|
|
156
113
|
materializers[outputKey] = klass; // omit passthrough (no-op coercion)
|
|
157
114
|
}
|
|
158
|
-
return { obj };
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* The outType + read-path materializers of ONE read body node — derived from the SINGLE column-type
|
|
162
|
-
* resolution ({@link rowObjType}). A `Select` returns a ROW LIST → `{arr:rowObj}`; a `Count` a single
|
|
163
|
-
* `int` (a scalar, no per-column map). A `.map` node wraps its per-element Select result. An
|
|
164
|
-
* unrecognized component throws (typed read de-box covers only the SQL read catalog).
|
|
165
|
-
*/
|
|
166
|
-
function nodeTypes(node, resolveColumnType) {
|
|
167
|
-
const { component, ports } = nodeRef(node);
|
|
168
|
-
const at = `node '${node.id}'`;
|
|
169
|
-
if (component === 'Count')
|
|
170
|
-
return { outType: 'int', materializers: {} };
|
|
171
|
-
if (component === 'Select') {
|
|
172
|
-
const table = stringPort(ports, 'table');
|
|
173
|
-
if (table === undefined)
|
|
174
|
-
throw new Error(`outtype: ${at}: Select node requires a literal 'table' port`);
|
|
175
|
-
const projection = stringArrayPort(ports, 'select');
|
|
176
|
-
const materializers = {};
|
|
177
|
-
const row = rowObjType(table, projection, resolveColumnType, at, materializers);
|
|
178
|
-
// A `.map` node iterates a list and invokes the inner component per element (row LIST per element
|
|
179
|
-
// → `{arr:{arr:rowObj}}`); a plain Select node returns the row list `{arr:rowObj}`.
|
|
180
|
-
const outType = isMap(node) ? { arr: { arr: row } } : { arr: row };
|
|
181
|
-
return { outType, materializers };
|
|
182
|
-
}
|
|
183
|
-
throw new Error(`outtype: ${at}: component '${component}' has no typed outType (typed read de-box covers Select/Count only). ` +
|
|
184
|
-
`A write / unknown node cannot be de-boxed here — no-assume, no-fallback.`);
|
|
185
|
-
}
|
|
186
|
-
/** The outType of ONE read body node (thin wrapper over {@link nodeTypes} for external callers). */
|
|
187
|
-
function nodeOutType(node, resolveColumnType) {
|
|
188
|
-
return nodeTypes(node, resolveColumnType).outType;
|
|
115
|
+
return { outType: { arr: { obj } }, materializers };
|
|
189
116
|
}
|
|
190
117
|
/**
|
|
191
118
|
* Derive the component `outputType` by walking the `output` Φ-expression against a `nodeId →
|
|
@@ -240,89 +167,4 @@ function outputType(output, byNode, at) {
|
|
|
240
167
|
`(ref / obj / arr / opt of node results). The typed de-box path does not build a dynamic ` +
|
|
241
168
|
`Value output tree — no-assume, no-fallback.`);
|
|
242
169
|
}
|
|
243
|
-
/**
|
|
244
|
-
* PRE-COMPILE node-output type (bc 0.8.0 SA5 / #12): the determined `PortableType` a litedbmodel CRUD
|
|
245
|
-
* leaf annotates its authored node with, via bc's `.as(t)` recording API, so `compileBehaviors`'
|
|
246
|
-
* all-nodes-typed gate (`UNTYPED_NODE`) passes. Computed from the RAW authored ports (a plain `table`
|
|
247
|
-
* string + a plain `select` / `returning` column list — the same projection SoT `deriveReadOutTypes`
|
|
248
|
-
* reads post-compile, just moved to authoring time) + the model's inline `static columns` resolver.
|
|
249
|
-
*
|
|
250
|
-
* - `Select` → the row LIST `{arr:{obj:{outKey:<scalar>,…}}}` from the `select` projection. This is
|
|
251
|
-
* the value `.as` takes in BOTH positions: a top-level Select node's `outType` is this list; a
|
|
252
|
-
* mapped Select's `.as` records it as the map ELEMENT type (bc convention — the per-parent row list).
|
|
253
|
-
* - `Count` → NOT handled here: its output is the static `int` catalog `elemType` (no `.as`).
|
|
254
|
-
* - `Insert`/`Update`/`Delete` → the RETURNING row list `{arr:{obj:…}}` from the `returning` port
|
|
255
|
-
* (bare-column list). No `returning` → an EMPTY row list `{arr:{obj:{}}}` (the write surfaces rows
|
|
256
|
-
* only via RETURNING; a no-RETURNING write yields empty rows — mirrors `writeouttype.ts`).
|
|
257
|
-
*
|
|
258
|
-
* Schema columns are parsed by the SAME {@link parseProjectionColumn} the read/codegen paths use and
|
|
259
|
-
* typed via the resolver (an undeclared column fails closed here at authoring — earlier than the
|
|
260
|
-
* post-compile derivation). A COMPUTED projected column (`COUNT(*) as n`, a cast, a literal) is OMITTED
|
|
261
|
-
* from the typed row struct — the read path leaves a computed column RAW (#59: "the read path leaves it
|
|
262
|
-
* raw; the codegen path rejects it"), so its field is absent from the de-box row type. This keeps the
|
|
263
|
-
* node's outType DETERMINED (gate passes) while preserving #59's raw-computed read behavior; the typed
|
|
264
|
-
* codegen path independently rejects a computed projection later (it needs every field typed). The
|
|
265
|
-
* value is the OUTPUT-row type only; SQL stays opaque text on the makeSQL leaf (types the node OUTPUT,
|
|
266
|
-
* never the SQL).
|
|
267
|
-
*/
|
|
268
|
-
function crudNodeAsType(component, ports, resolveColumnType, at) {
|
|
269
|
-
const table = ports['table'];
|
|
270
|
-
if (typeof table !== 'string') {
|
|
271
|
-
throw new Error(`outtype: ${at}: ${component} node requires a literal 'table' string port to type its output (got ${JSON.stringify(table)})`);
|
|
272
|
-
}
|
|
273
|
-
if (component === 'Select') {
|
|
274
|
-
const select = ports['select'];
|
|
275
|
-
if (!Array.isArray(select) || select.length === 0) {
|
|
276
|
-
throw new Error(`outtype: ${at}: Select has no explicit column projection ('*' / empty). A typed de-box needs the ` +
|
|
277
|
-
`concrete column list to build the row struct — spec §4.1 is column-typed. Project explicit columns.`);
|
|
278
|
-
}
|
|
279
|
-
const obj = {};
|
|
280
|
-
for (const raw of select) {
|
|
281
|
-
if (typeof raw !== 'string')
|
|
282
|
-
throw new Error(`outtype: ${at}: Select 'select' entries must be literal strings (got ${JSON.stringify(raw)})`);
|
|
283
|
-
const parsed = parseProjectionColumn(raw, table, at);
|
|
284
|
-
if (parsed.kind === 'computed')
|
|
285
|
-
continue; // computed column: read raw, omitted from the typed row (SA5-determined without it)
|
|
286
|
-
const { underlying, outputKey, qualifier } = parsed;
|
|
287
|
-
if (outputKey in obj)
|
|
288
|
-
throw new Error(`outtype: ${at}: duplicate projected column key '${outputKey}' on '${table}'`);
|
|
289
|
-
obj[outputKey] = toPortableScalar((0, coltype_1.sqlTypeToBcScalar)(resolveColumnType(qualifier ?? table, underlying)), qualifier ?? table, underlying);
|
|
290
|
-
}
|
|
291
|
-
return { arr: { obj } };
|
|
292
|
-
}
|
|
293
|
-
if (component === 'Insert' || component === 'Update' || component === 'Delete') {
|
|
294
|
-
// The RETURNING port is a single comma-separated bare-column string (`'id, author_id'`) or absent.
|
|
295
|
-
const returning = ports['returning'];
|
|
296
|
-
if (returning === undefined)
|
|
297
|
-
return { arr: { obj: {} } };
|
|
298
|
-
if (typeof returning !== 'string') {
|
|
299
|
-
throw new Error(`outtype: ${at}: ${component} 'returning' port must be a literal string (got ${JSON.stringify(returning)})`);
|
|
300
|
-
}
|
|
301
|
-
const cols = returning.split(',').map((c) => c.trim()).filter((c) => c.length > 0);
|
|
302
|
-
if (cols.length === 0)
|
|
303
|
-
return { arr: { obj: {} } };
|
|
304
|
-
return { arr: rowObjType(table, cols, resolveColumnType, at, {}) };
|
|
305
|
-
}
|
|
306
|
-
throw new Error(`outtype: ${at}: no pre-compile output type for component '${component}' (typed CRUD covers Select/Insert/Update/Delete; Count is static via catalog elemType).`);
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Per-node `outType` (keyed by body node id) + the component `outputType`, derived for a READ
|
|
310
|
-
* component (spec §4.1). `cond` nodes are skipped for the per-node map but a `cond` at the OUTPUT
|
|
311
|
-
* position (a shared-branch merge) would be handled by {@link outputType} if reached — the bench's
|
|
312
|
-
* read outputs are ref / obj compositions of Select nodes. Any ambiguity throws (fail-closed).
|
|
313
|
-
*/
|
|
314
|
-
function deriveReadOutTypes(component, resolveColumnType) {
|
|
315
|
-
const byNode = new Map();
|
|
316
|
-
const materializersByNode = new Map();
|
|
317
|
-
for (const n of component.body) {
|
|
318
|
-
if ('cond' in n)
|
|
319
|
-
continue; // a cond node carries no SELECT projection; it is typed by its branch
|
|
320
|
-
// ONE resolution per node → the outType (codegen) AND the read-path materializers (runtime).
|
|
321
|
-
const t = nodeTypes(n, resolveColumnType);
|
|
322
|
-
byNode.set(n.id, t.outType);
|
|
323
|
-
if (Object.keys(t.materializers).length > 0)
|
|
324
|
-
materializersByNode.set(n.id, t.materializers);
|
|
325
|
-
}
|
|
326
|
-
return { byNode, outputType: outputType(component.output, byNode, `component '${component.name}' output`), materializersByNode };
|
|
327
|
-
}
|
|
328
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,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACjD,CAAC;AAsBD;;;;;;;;;;;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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,8 @@
|
|
|
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';
|
|
20
21
|
/** The minimal `pg.types` surface: register a per-OID text parser. */
|
|
21
22
|
export interface PgTypesLike {
|
|
22
23
|
setTypeParser(oid: number, parser: (value: string) => unknown): void;
|
|
@@ -24,8 +25,8 @@ export interface PgTypesLike {
|
|
|
24
25
|
/**
|
|
25
26
|
* Register `pg` type parsers so the read-path de-box (issue #59) gets coercible values: the
|
|
26
27
|
* DATE/TIMESTAMP/TIMESTAMPTZ/TIME family is returned as its NATIVE TEXTUAL string (NOT a JS Date),
|
|
27
|
-
* honoring the `date→string` outType and carrying the TZ for timestamptz
|
|
28
|
-
*
|
|
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
|
|
29
30
|
* the consumer that owns the `pg` module (`import { types } from 'pg'; configurePgDeboxTypeParsers(types)`).
|
|
30
31
|
*
|
|
31
32
|
* WHY the GLOBAL parser (a documented, deliberate exception): `pg`'s default DATE parser builds a JS
|
|
@@ -48,7 +49,21 @@ export declare const mysqlDeboxPoolOptions: {
|
|
|
48
49
|
readonly supportBigNumbers: true;
|
|
49
50
|
readonly bigNumberStrings: true;
|
|
50
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;
|
|
51
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
|
+
}
|
|
52
67
|
/** The minimal `pg.Pool` surface we need: `query(text, values)` resolving `{ rows }`. */
|
|
53
68
|
export interface PgPoolLike {
|
|
54
69
|
query(text: string, values?: unknown[]): Promise<{
|
|
@@ -59,15 +74,6 @@ export interface PgPoolLike {
|
|
|
59
74
|
export interface MysqlPoolLike {
|
|
60
75
|
query(sql: string, values?: unknown[]): Promise<[Record<string, unknown>[], unknown]>;
|
|
61
76
|
}
|
|
62
|
-
/**
|
|
63
|
-
* Adapt a `pg.Pool` to the async executor seam. Each `exec` runs `pool.query`, which acquires a
|
|
64
|
-
* pooled connection, runs the query, and releases it — so N concurrent siblings run on N pooled
|
|
65
|
-
* connections in parallel. The graph renders `$N` placeholders for the `postgres` dialect, so the
|
|
66
|
-
* `sql` is already in `pg`'s native form.
|
|
67
|
-
*
|
|
68
|
-
* Recommend constructing the pool with `max` ≥ the plan's `concurrency` (default 16).
|
|
69
|
-
*/
|
|
70
|
-
export declare function pgPoolExecutor(pool: PgPoolLike): SqlExecutorAsync;
|
|
71
77
|
/**
|
|
72
78
|
* Adapt a `mysql2/promise` pool to the async executor seam. `pool.query` acquires + releases a
|
|
73
79
|
* pooled connection per call, so concurrent siblings run in parallel. The graph renders `?`
|
|
@@ -88,30 +94,76 @@ export interface Mysql2ModuleLike {
|
|
|
88
94
|
end?: () => Promise<void>;
|
|
89
95
|
};
|
|
90
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
|
+
}
|
|
91
109
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* `executeBehaviorAsync`. This is the production async path's de-box-correct entry (no hand-spread
|
|
96
|
-
* options).
|
|
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.
|
|
97
113
|
*/
|
|
98
|
-
export declare function
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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>;
|
|
103
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
|
+
}
|
|
104
140
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* `
|
|
108
|
-
*
|
|
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).
|
|
109
149
|
*/
|
|
110
|
-
export declare function
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
exec: SqlExecutorAsync;
|
|
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>;
|
|
115
154
|
};
|
|
116
|
-
|
|
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;
|
|
117
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,
|
|
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,U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