litedbmodel 2.0.2 → 2.1.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/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +44 -24
- package/dist/decorators.js.map +1 -1
- package/dist/drivers/mysql.d.ts.map +1 -1
- package/dist/drivers/mysql.js +6 -0
- package/dist/drivers/mysql.js.map +1 -1
- package/dist/drivers/postgres.d.ts.map +1 -1
- package/dist/drivers/postgres.js +7 -0
- 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 +37 -2
- package/dist/drivers/sqlite.js.map +1 -1
- package/dist/scp/authoring.d.ts +66 -3
- package/dist/scp/authoring.d.ts.map +1 -1
- package/dist/scp/authoring.js +194 -5
- package/dist/scp/authoring.js.map +1 -1
- package/dist/scp/catalog.d.ts +2 -1
- package/dist/scp/catalog.d.ts.map +1 -1
- package/dist/scp/catalog.js +12 -1
- package/dist/scp/catalog.js.map +1 -1
- package/dist/scp/codegen.d.ts +43 -31
- package/dist/scp/codegen.d.ts.map +1 -1
- package/dist/scp/codegen.js +279 -95
- package/dist/scp/codegen.js.map +1 -1
- package/dist/scp/coltype.d.ts +83 -0
- package/dist/scp/coltype.d.ts.map +1 -1
- package/dist/scp/coltype.js +220 -0
- package/dist/scp/coltype.js.map +1 -1
- package/dist/scp/guard.d.ts +1 -1
- package/dist/scp/guard.d.ts.map +1 -1
- package/dist/scp/guard.js +6 -0
- package/dist/scp/guard.js.map +1 -1
- package/dist/scp/index.cjs +7149 -9379
- package/dist/scp/index.d.ts +7 -6
- package/dist/scp/index.d.ts.map +1 -1
- package/dist/scp/index.js +21 -6
- package/dist/scp/index.js.map +1 -1
- package/dist/scp/index.mjs +729 -178
- package/dist/scp/makesql/authoring-compile.d.ts.map +1 -1
- package/dist/scp/makesql/authoring-compile.js +11 -0
- package/dist/scp/makesql/authoring-compile.js.map +1 -1
- package/dist/scp/makesql/index.d.ts +2 -3
- package/dist/scp/makesql/index.d.ts.map +1 -1
- package/dist/scp/makesql/index.js +6 -6
- package/dist/scp/makesql/index.js.map +1 -1
- package/dist/scp/makesql/json-batch.d.ts.map +1 -1
- package/dist/scp/makesql/json-batch.js +6 -1
- package/dist/scp/makesql/json-batch.js.map +1 -1
- package/dist/scp/makesql/outtype.d.ts +61 -6
- package/dist/scp/makesql/outtype.d.ts.map +1 -1
- package/dist/scp/makesql/outtype.js +164 -33
- package/dist/scp/makesql/outtype.js.map +1 -1
- package/dist/scp/makesql/pool-executor.d.ts +70 -0
- package/dist/scp/makesql/pool-executor.d.ts.map +1 -1
- package/dist/scp/makesql/pool-executor.js +73 -5
- package/dist/scp/makesql/pool-executor.js.map +1 -1
- package/dist/scp/makesql/static-bundle.d.ts +39 -30
- package/dist/scp/makesql/static-bundle.d.ts.map +1 -1
- package/dist/scp/makesql/static-bundle.js +269 -138
- package/dist/scp/makesql/static-bundle.js.map +1 -1
- package/dist/scp/makesql/writeouttype.d.ts +5 -6
- package/dist/scp/makesql/writeouttype.d.ts.map +1 -1
- package/dist/scp/makesql/writeouttype.js +5 -6
- package/dist/scp/makesql/writeouttype.js.map +1 -1
- package/dist/scp/relation.d.ts +15 -1
- package/dist/scp/relation.d.ts.map +1 -1
- package/dist/scp/relation.js +61 -2
- package/dist/scp/relation.js.map +1 -1
- package/dist/scp/runtime.d.ts +6 -5
- package/dist/scp/runtime.d.ts.map +1 -1
- package/dist/scp/runtime.js +27 -5
- package/dist/scp/runtime.js.map +1 -1
- package/docs/BENCHMARK.md +58 -56
- package/docs/benchmark-chart.svg +166 -166
- package/package.json +8 -2
- 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/coltype.d.ts
CHANGED
|
@@ -15,6 +15,53 @@ export type BcScalar = 'string' | 'int' | 'float' | 'bool' | 'null';
|
|
|
15
15
|
* spec §4.1 の正規表に一致。未知/曖昧は throw(fail-closed)。
|
|
16
16
|
*/
|
|
17
17
|
export declare function sqlTypeToBcScalar(sqlType: string): BcScalar;
|
|
18
|
+
/**
|
|
19
|
+
* The TS read-path MATERIALIZATION class for a SQL column (issue #59, owner-approved
|
|
20
|
+
* type-honoring de-box). The bc `outType` scalar (`int`/`float`/`string`/`bool`) is the PORTABLE
|
|
21
|
+
* type the native codegen materializes; but on the TS/driver read path we additionally split the
|
|
22
|
+
* `int` scalar by SQL WIDTH and coerce `date`/`bool` to their exact JS form, because a JS `number`
|
|
23
|
+
* cannot hold an i64 and the drivers otherwise return a JS `Date` / `0|1` that violate the
|
|
24
|
+
* declared `string`/`bool` outType. A materialization class is:
|
|
25
|
+
*
|
|
26
|
+
* - `'int32'` — 32-bit int family (INT/INTEGER/SMALLINT/TINYINT/MEDIUMINT/INT2/INT4). Its full
|
|
27
|
+
* range fits in a JS `number` exactly, so it materializes to `number` (fast,
|
|
28
|
+
* arith/JSON-friendly). This is the UNCHANGED, already-correct behavior.
|
|
29
|
+
* - `'int64'` — 64-bit int (BIGINT/INT8). Exceeds `Number.MAX_SAFE_INTEGER`, so a JS `number`
|
|
30
|
+
* would round it. Materializes to a value-preserving decimal STRING (e.g.
|
|
31
|
+
* `"9223372036854775807"`) — EXACT and JSON-safe (a JS `bigint` throws in
|
|
32
|
+
* `JSON.stringify`, so string is the JSON-friendly exact form, mirroring the
|
|
33
|
+
* decimal→string / date→string mappings). This is the ONLY int class whose JS
|
|
34
|
+
* type changes (#59 fix).
|
|
35
|
+
* - `'date'` — DATE/TIMESTAMP/TIMESTAMPTZ/DATETIME/TIME. The bc outType is `string`; drivers
|
|
36
|
+
* return a JS `Date` (TZ-shifted). Materializes to a TZ-attached STRING (the
|
|
37
|
+
* driver's textual form), honoring the `string` outType (#59 fix; overrides the
|
|
38
|
+
* old v2 "date→JS Date on TS" mapping).
|
|
39
|
+
* - `'bool'` — BOOLEAN/BOOL. Drivers may return `0`/`1`; materializes to a JS `boolean`.
|
|
40
|
+
* - `'passthrough'` — every other class (float, text, decimal-as-string, json, uuid): the driver
|
|
41
|
+
* value already matches the outType, so no coercion.
|
|
42
|
+
*/
|
|
43
|
+
export type MaterializeClass = 'int32' | 'int64' | 'date' | 'bool' | 'passthrough';
|
|
44
|
+
/**
|
|
45
|
+
* Derive the TS read-path {@link MaterializeClass} for a SQL type (spec §4.1 owner de-box). Uses
|
|
46
|
+
* the SAME normalization + closed-set discipline as {@link sqlTypeToBcScalar} (unknown ⇒ throw),
|
|
47
|
+
* so a column that types for the bc scalar also types for materialization (and vice-versa). The
|
|
48
|
+
* `int` scalar splits int32/int64 by width; `date`/`bool` get their own class; everything else is
|
|
49
|
+
* `passthrough`.
|
|
50
|
+
*/
|
|
51
|
+
export declare function sqlTypeToMaterializeClass(sqlType: string): MaterializeClass;
|
|
52
|
+
/**
|
|
53
|
+
* Coerce ONE raw driver cell to the JS form its {@link MaterializeClass} declares (issue #59 TS
|
|
54
|
+
* read-path de-box). NULL passes through (nullable columns). This is driver-agnostic: it accepts
|
|
55
|
+
* whatever form each driver returned for the class and normalizes it —
|
|
56
|
+
* - `int64`: a string (pg int8 / mysql2 bigNumberStrings), a bigint (better-sqlite3 safeIntegers),
|
|
57
|
+
* or a safe JS number → an EXACT decimal STRING (JSON-safe, value-preserving). An
|
|
58
|
+
* already-rounded unsafe JS number is a hard error (precision was lost upstream).
|
|
59
|
+
* - `int32`: a bigint (a driver in safe-integer mode) or string → `number`; a number stays.
|
|
60
|
+
* - `date` : a JS Date → its textual form; a string stays (already the textual form).
|
|
61
|
+
* - `bool` : `0`/`1`/`0n`/`1n` → boolean; a boolean stays.
|
|
62
|
+
* - `passthrough`: unchanged.
|
|
63
|
+
*/
|
|
64
|
+
export declare function materializeCell(value: unknown, klass: MaterializeClass): unknown;
|
|
18
65
|
/**
|
|
19
66
|
* A column-type resolver: `(table, column) → SQL type token`. It is the SoT (spec §4.1: the
|
|
20
67
|
* `schema.sql` DDL) a codegen `outType` derivation consults to type each SELECT projection column.
|
|
@@ -22,6 +69,42 @@ export declare function sqlTypeToBcScalar(sqlType: string): BcScalar;
|
|
|
22
69
|
* hard error (no-assume, no-fallback), never a silent boxed fallback.
|
|
23
70
|
*/
|
|
24
71
|
export type ColumnTypeResolver = (table: string, column: string) => string;
|
|
72
|
+
/**
|
|
73
|
+
* A resolver that yields the TS read-path {@link MaterializeClass} of a `(table, column)`, or
|
|
74
|
+
* `undefined` when the column's type is unknown/untypeable. Unlike {@link ColumnTypeResolver} this
|
|
75
|
+
* is TOLERANT (never throws for an unknown column) — it drives the ALWAYS-ON production read-path
|
|
76
|
+
* materialization (issue #59), which must degrade to leaving an untyped column as the raw driver
|
|
77
|
+
* value rather than failing a real read. It is derived automatically from the DB's own schema (the
|
|
78
|
+
* live column-type SoT), so it fires for EVERY production read with no caller-supplied resolver.
|
|
79
|
+
*/
|
|
80
|
+
export type MaterializeResolver = (table: string, column: string) => MaterializeClass | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* A `table → (column → SQL type)` map → a TOLERANT {@link MaterializeResolver}: an unknown
|
|
83
|
+
* `(table, column)` or an un-mappable SQL type resolves to `undefined` (the raw driver value is
|
|
84
|
+
* kept). Retained for callers that WANT tolerance (e.g. optional/introspection contexts). The
|
|
85
|
+
* ALWAYS-ON registration path uses the FAIL-CLOSED variant below instead.
|
|
86
|
+
*/
|
|
87
|
+
export declare function materializeResolverFromColumnMap(columnTypes: ReadonlyMap<string, ReadonlyMap<string, string>>): MaterializeResolver;
|
|
88
|
+
/**
|
|
89
|
+
* A `table → (column → SQL type)` map → a FAIL-CLOSED {@link MaterializeResolver} (issue #59 audit):
|
|
90
|
+
* an undeclared `(table, column)` THROWS (naming the model/table/column) — reconciled with the
|
|
91
|
+
* codegen resolver so the TS read path can NEVER silently skip de-box for an undeclared projected
|
|
92
|
+
* column (which would leak a rounded i64). A DECLARED column returns its materialize class (incl.
|
|
93
|
+
* `passthrough` for float/text/decimal/json — a no-op coercion, but it WAS type-checked). This is the
|
|
94
|
+
* resolver the registration precomputes ONCE from the model's INLINE `columns` declaration and
|
|
95
|
+
* carries on the contract — pure in-memory lookups, ZERO per-read DB introspection.
|
|
96
|
+
*/
|
|
97
|
+
export declare function failClosedMaterializeResolverFromColumnMap(columnTypes: ReadonlyMap<string, ReadonlyMap<string, string>>): MaterializeResolver;
|
|
98
|
+
/**
|
|
99
|
+
* A `table → (column → SQL type)` map → a fail-closed {@link ColumnTypeResolver} (the codegen
|
|
100
|
+
* `outType` SoT). THROWS for an unknown `table`/`column` (no-assume, no-fallback — a typed-native
|
|
101
|
+
* read must not silently box an untyped column). Built from the model's INLINE `columns` declaration
|
|
102
|
+
* at registration, it replaces the external `schemaColumnTypeResolver(ddl)` as the codegen type
|
|
103
|
+
* source, so `deriveReadOutTypes` reads the declared types.
|
|
104
|
+
*/
|
|
105
|
+
export declare function columnTypeResolverFromColumnMap(columnTypes: ReadonlyMap<string, ReadonlyMap<string, string>>): ColumnTypeResolver;
|
|
106
|
+
/** {@link sqlTypeToMaterializeClass} but TOLERANT: returns `undefined` for an unknown SQL type. */
|
|
107
|
+
export declare function materializeClassOrUndefined(sqlType: string): MaterializeClass | undefined;
|
|
25
108
|
/**
|
|
26
109
|
* Parse a list of `CREATE TABLE` DDL statements into a `table → (column → SQL type)` map. This is
|
|
27
110
|
* the spec §4.1 SoT: the physical SQL type of each column, from which `sqlTypeToBcScalar` derives
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coltype.d.ts","sourceRoot":"","sources":["../../src/scp/coltype.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,0EAA0E;AAC1E,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;AAEpE;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,G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,KAAK,gBAAgB,GAAG,SAAS,CAAC;AAElG;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAC9C,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAC5D,mBAAmB,CAKrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,0CAA0C,CACxD,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAC5D,mBAAmB,CAQrB;AAED;;;;;;GAMG;AACH,wBAAgB,+BAA+B,CAC7C,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAC5D,kBAAkB,CAmBpB;AAED,mGAAmG;AACnG,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAMzF;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAwB/F;AAyCD;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,GAAG,kBAAkB,CAqBnF"}
|
package/dist/scp/coltype.js
CHANGED
|
@@ -11,6 +11,12 @@
|
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.sqlTypeToBcScalar = sqlTypeToBcScalar;
|
|
14
|
+
exports.sqlTypeToMaterializeClass = sqlTypeToMaterializeClass;
|
|
15
|
+
exports.materializeCell = materializeCell;
|
|
16
|
+
exports.materializeResolverFromColumnMap = materializeResolverFromColumnMap;
|
|
17
|
+
exports.failClosedMaterializeResolverFromColumnMap = failClosedMaterializeResolverFromColumnMap;
|
|
18
|
+
exports.columnTypeResolverFromColumnMap = columnTypeResolverFromColumnMap;
|
|
19
|
+
exports.materializeClassOrUndefined = materializeClassOrUndefined;
|
|
14
20
|
exports.parseSchemaColumnTypes = parseSchemaColumnTypes;
|
|
15
21
|
exports.schemaColumnTypeResolver = schemaColumnTypeResolver;
|
|
16
22
|
/**
|
|
@@ -79,6 +85,220 @@ function sqlTypeToBcScalar(sqlType) {
|
|
|
79
85
|
`are a hard error (no-assume, no-fallback), never defaulted.`);
|
|
80
86
|
}
|
|
81
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Derive the TS read-path {@link MaterializeClass} for a SQL type (spec §4.1 owner de-box). Uses
|
|
90
|
+
* the SAME normalization + closed-set discipline as {@link sqlTypeToBcScalar} (unknown ⇒ throw),
|
|
91
|
+
* so a column that types for the bc scalar also types for materialization (and vice-versa). The
|
|
92
|
+
* `int` scalar splits int32/int64 by width; `date`/`bool` get their own class; everything else is
|
|
93
|
+
* `passthrough`.
|
|
94
|
+
*/
|
|
95
|
+
function sqlTypeToMaterializeClass(sqlType) {
|
|
96
|
+
const t = sqlType
|
|
97
|
+
.trim()
|
|
98
|
+
.toUpperCase()
|
|
99
|
+
.replace(/\(.*\)/, '')
|
|
100
|
+
.replace(/\b(UNSIGNED|ZEROFILL|PRECISION)\b/g, '')
|
|
101
|
+
.replace(/\s+/g, ' ')
|
|
102
|
+
.trim();
|
|
103
|
+
switch (t) {
|
|
104
|
+
// 32-bit int family: JS number holds the full range exactly.
|
|
105
|
+
case 'INTEGER':
|
|
106
|
+
case 'INT':
|
|
107
|
+
case 'SMALLINT':
|
|
108
|
+
case 'TINYINT':
|
|
109
|
+
case 'MEDIUMINT':
|
|
110
|
+
case 'INT2':
|
|
111
|
+
case 'INT4':
|
|
112
|
+
return 'int32';
|
|
113
|
+
// 64-bit int: needs JS bigint for exactness.
|
|
114
|
+
case 'BIGINT':
|
|
115
|
+
case 'INT8':
|
|
116
|
+
return 'int64';
|
|
117
|
+
case 'BOOLEAN':
|
|
118
|
+
case 'BOOL':
|
|
119
|
+
return 'bool';
|
|
120
|
+
case 'DATE':
|
|
121
|
+
case 'TIMESTAMP':
|
|
122
|
+
case 'TIMESTAMPTZ':
|
|
123
|
+
case 'DATETIME':
|
|
124
|
+
case 'TIME':
|
|
125
|
+
return 'date';
|
|
126
|
+
// float / decimal(→string) / text / json / uuid — driver value already matches the outType.
|
|
127
|
+
case 'REAL':
|
|
128
|
+
case 'FLOAT':
|
|
129
|
+
case 'DOUBLE':
|
|
130
|
+
case 'FLOAT4':
|
|
131
|
+
case 'FLOAT8':
|
|
132
|
+
case 'DECIMAL':
|
|
133
|
+
case 'NUMERIC':
|
|
134
|
+
case 'MONEY':
|
|
135
|
+
case 'TEXT':
|
|
136
|
+
case 'VARCHAR':
|
|
137
|
+
case 'CHAR':
|
|
138
|
+
case 'CHARACTER':
|
|
139
|
+
case 'CHARACTER VARYING':
|
|
140
|
+
case 'CLOB':
|
|
141
|
+
case 'UUID':
|
|
142
|
+
case 'JSON':
|
|
143
|
+
case 'JSONB':
|
|
144
|
+
return 'passthrough';
|
|
145
|
+
default:
|
|
146
|
+
throw new Error(`litedbmodel type system (spec §4.1): no materialization class for SQL type '${sqlType}' ` +
|
|
147
|
+
`(normalized '${t}'). Add it to the §4.1 table or fix the column — ambiguous/unknown types ` +
|
|
148
|
+
`are a hard error (no-assume, no-fallback), never defaulted.`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Coerce ONE raw driver cell to the JS form its {@link MaterializeClass} declares (issue #59 TS
|
|
153
|
+
* read-path de-box). NULL passes through (nullable columns). This is driver-agnostic: it accepts
|
|
154
|
+
* whatever form each driver returned for the class and normalizes it —
|
|
155
|
+
* - `int64`: a string (pg int8 / mysql2 bigNumberStrings), a bigint (better-sqlite3 safeIntegers),
|
|
156
|
+
* or a safe JS number → an EXACT decimal STRING (JSON-safe, value-preserving). An
|
|
157
|
+
* already-rounded unsafe JS number is a hard error (precision was lost upstream).
|
|
158
|
+
* - `int32`: a bigint (a driver in safe-integer mode) or string → `number`; a number stays.
|
|
159
|
+
* - `date` : a JS Date → its textual form; a string stays (already the textual form).
|
|
160
|
+
* - `bool` : `0`/`1`/`0n`/`1n` → boolean; a boolean stays.
|
|
161
|
+
* - `passthrough`: unchanged.
|
|
162
|
+
*/
|
|
163
|
+
function materializeCell(value, klass) {
|
|
164
|
+
if (value === null || value === undefined)
|
|
165
|
+
return value;
|
|
166
|
+
switch (klass) {
|
|
167
|
+
case 'int64': {
|
|
168
|
+
// BIGINT → a value-preserving decimal STRING (exact + JSON-safe; a JS bigint throws in
|
|
169
|
+
// JSON.stringify, a JS number rounds past 2^53). Accept each driver's exact form.
|
|
170
|
+
if (typeof value === 'bigint')
|
|
171
|
+
return value.toString();
|
|
172
|
+
if (typeof value === 'string') {
|
|
173
|
+
if (!/^-?\d+$/.test(value))
|
|
174
|
+
throw new Error(`materialize int64: driver returned a non-integer string '${value}'`);
|
|
175
|
+
return value; // already the exact decimal string (pg int8 / mysql2 bigNumberStrings)
|
|
176
|
+
}
|
|
177
|
+
if (typeof value === 'number') {
|
|
178
|
+
if (!Number.isInteger(value))
|
|
179
|
+
throw new Error(`materialize int64: driver returned a non-integer number ${value} for a 64-bit int column`);
|
|
180
|
+
// A JS number past 2^53 already lost precision at the driver boundary; that is exactly the
|
|
181
|
+
// hole this de-box closes, so a number here means the driver was NOT put in exact mode.
|
|
182
|
+
if (!Number.isSafeInteger(value)) {
|
|
183
|
+
throw new Error(`materialize int64: driver returned an UNSAFE JS number ${value} for a 64-bit int column — ` +
|
|
184
|
+
`precision was already lost before materialization (the driver must return int8 as string/bigint, ` +
|
|
185
|
+
`not a rounded double). Configure the driver (better-sqlite3 safeIntegers / mysql2 supportBigNumbers+bigNumberStrings / pg int8-as-string).`);
|
|
186
|
+
}
|
|
187
|
+
return value.toString(); // a small BIGINT value that fit safely — stringify for a uniform exact string
|
|
188
|
+
}
|
|
189
|
+
throw new Error(`materialize int64: unexpected driver JS type ${typeof value}`);
|
|
190
|
+
}
|
|
191
|
+
case 'int32': {
|
|
192
|
+
if (typeof value === 'number')
|
|
193
|
+
return value;
|
|
194
|
+
if (typeof value === 'bigint')
|
|
195
|
+
return Number(value);
|
|
196
|
+
if (typeof value === 'string' && /^-?\d+$/.test(value))
|
|
197
|
+
return Number(value);
|
|
198
|
+
throw new Error(`materialize int32: unexpected driver JS type ${typeof value} (${String(value)})`);
|
|
199
|
+
}
|
|
200
|
+
case 'date': {
|
|
201
|
+
if (typeof value === 'string')
|
|
202
|
+
return value;
|
|
203
|
+
if (value instanceof Date)
|
|
204
|
+
return dateToTzString(value);
|
|
205
|
+
throw new Error(`materialize date: unexpected driver JS type ${typeof value}`);
|
|
206
|
+
}
|
|
207
|
+
case 'bool': {
|
|
208
|
+
if (typeof value === 'boolean')
|
|
209
|
+
return value;
|
|
210
|
+
if (typeof value === 'number')
|
|
211
|
+
return value !== 0;
|
|
212
|
+
if (typeof value === 'bigint')
|
|
213
|
+
return value !== 0n;
|
|
214
|
+
// A driver in TEXT mode (or the legacy v1 DBModel read path, issue #9) may hand a BOOLEAN over as
|
|
215
|
+
// its textual form: pg's `t`/`f`, or `true`/`false`/`1`/`0`. Normalize those to a JS boolean too,
|
|
216
|
+
// so a single coercion path serves both the v2 native-driver read and the v1 text-mode read.
|
|
217
|
+
if (typeof value === 'string') {
|
|
218
|
+
const s = value.trim().toLowerCase();
|
|
219
|
+
if (s === 't' || s === 'true' || s === '1')
|
|
220
|
+
return true;
|
|
221
|
+
if (s === 'f' || s === 'false' || s === '0')
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
throw new Error(`materialize bool: unexpected driver JS type ${typeof value} (${String(value)})`);
|
|
225
|
+
}
|
|
226
|
+
case 'passthrough':
|
|
227
|
+
return value;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Render a JS `Date` (a driver that was NOT configured for date-as-string) to a TZ-attached
|
|
232
|
+
* string. A `Date` has no calendar-vs-timestamp distinction, so we emit the full ISO-8601 instant
|
|
233
|
+
* (UTC, `Z`-suffixed) — a lossless, TZ-carrying textual form. The PREFERRED path is to configure
|
|
234
|
+
* the driver to return the native textual form directly (pg `setTypeParser`, mysql2 `dateStrings`);
|
|
235
|
+
* this fallback guarantees a STRING is returned even if a driver slips a Date through.
|
|
236
|
+
*/
|
|
237
|
+
function dateToTzString(d) {
|
|
238
|
+
return d.toISOString();
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* A `table → (column → SQL type)` map → a TOLERANT {@link MaterializeResolver}: an unknown
|
|
242
|
+
* `(table, column)` or an un-mappable SQL type resolves to `undefined` (the raw driver value is
|
|
243
|
+
* kept). Retained for callers that WANT tolerance (e.g. optional/introspection contexts). The
|
|
244
|
+
* ALWAYS-ON registration path uses the FAIL-CLOSED variant below instead.
|
|
245
|
+
*/
|
|
246
|
+
function materializeResolverFromColumnMap(columnTypes) {
|
|
247
|
+
return (table, column) => {
|
|
248
|
+
const sqlType = columnTypes.get(table)?.get(column);
|
|
249
|
+
return sqlType === undefined ? undefined : materializeClassOrUndefined(sqlType);
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* A `table → (column → SQL type)` map → a FAIL-CLOSED {@link MaterializeResolver} (issue #59 audit):
|
|
254
|
+
* an undeclared `(table, column)` THROWS (naming the model/table/column) — reconciled with the
|
|
255
|
+
* codegen resolver so the TS read path can NEVER silently skip de-box for an undeclared projected
|
|
256
|
+
* column (which would leak a rounded i64). A DECLARED column returns its materialize class (incl.
|
|
257
|
+
* `passthrough` for float/text/decimal/json — a no-op coercion, but it WAS type-checked). This is the
|
|
258
|
+
* resolver the registration precomputes ONCE from the model's INLINE `columns` declaration and
|
|
259
|
+
* carries on the contract — pure in-memory lookups, ZERO per-read DB introspection.
|
|
260
|
+
*/
|
|
261
|
+
function failClosedMaterializeResolverFromColumnMap(columnTypes) {
|
|
262
|
+
const resolveSqlType = columnTypeResolverFromColumnMap(columnTypes); // throws on undeclared
|
|
263
|
+
return (table, column) => {
|
|
264
|
+
const sqlType = resolveSqlType(table, column); // fail-closed: throws for an undeclared column
|
|
265
|
+
// A declared column's SQL type must map to a known materialize class (the §4.1 closed set); an
|
|
266
|
+
// unknown token on a DECLARED column is a hard error too (never a silent skip).
|
|
267
|
+
return sqlTypeToMaterializeClass(sqlType);
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* A `table → (column → SQL type)` map → a fail-closed {@link ColumnTypeResolver} (the codegen
|
|
272
|
+
* `outType` SoT). THROWS for an unknown `table`/`column` (no-assume, no-fallback — a typed-native
|
|
273
|
+
* read must not silently box an untyped column). Built from the model's INLINE `columns` declaration
|
|
274
|
+
* at registration, it replaces the external `schemaColumnTypeResolver(ddl)` as the codegen type
|
|
275
|
+
* source, so `deriveReadOutTypes` reads the declared types.
|
|
276
|
+
*/
|
|
277
|
+
function columnTypeResolverFromColumnMap(columnTypes) {
|
|
278
|
+
return (table, column) => {
|
|
279
|
+
const cols = columnTypes.get(table);
|
|
280
|
+
if (cols === undefined) {
|
|
281
|
+
throw new Error(`litedbmodel type system (spec §4.1): table '${table}' has no inline column-type declaration ` +
|
|
282
|
+
`(the model's \`columns\` map). Declare it (\`static columns = { ${table}: { … } }\`) so its ` +
|
|
283
|
+
`SELECT projection can be typed. Known tables: ${[...columnTypes.keys()].join(', ') || '<none>'}. No-assume, no-fallback.`);
|
|
284
|
+
}
|
|
285
|
+
const sqlType = cols.get(column);
|
|
286
|
+
if (sqlType === undefined) {
|
|
287
|
+
throw new Error(`litedbmodel type system (spec §4.1): column '${column}' not declared on table '${table}' ` +
|
|
288
|
+
`(declared: ${[...cols.keys()].join(', ')}). Add it to the model's inline \`columns\`. No-assume, no-fallback.`);
|
|
289
|
+
}
|
|
290
|
+
return sqlType;
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
/** {@link sqlTypeToMaterializeClass} but TOLERANT: returns `undefined` for an unknown SQL type. */
|
|
294
|
+
function materializeClassOrUndefined(sqlType) {
|
|
295
|
+
try {
|
|
296
|
+
return sqlTypeToMaterializeClass(sqlType);
|
|
297
|
+
}
|
|
298
|
+
catch {
|
|
299
|
+
return undefined;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
82
302
|
/**
|
|
83
303
|
* Parse a list of `CREATE TABLE` DDL statements into a `table → (column → SQL type)` map. This is
|
|
84
304
|
* the spec §4.1 SoT: the physical SQL type of each column, from which `sqlTypeToBcScalar` derives
|
package/dist/scp/coltype.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coltype.js","sourceRoot":"","sources":["../../src/scp/coltype.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AASH,8CA+DC;
|
|
1
|
+
{"version":3,"file":"coltype.js","sourceRoot":"","sources":["../../src/scp/coltype.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AASH,8CA+DC;AAoCD,8DAyDC;AAcD,0CAsDC;AAqCD,4EAOC;AAWD,gGAUC;AASD,0EAqBC;AAGD,kEAMC;AAWD,wDAwBC;AA8CD,4DAqBC;AAlbD;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,OAAe;IAC/C,yCAAyC;IACzC,MAAM,CAAC,GAAG,OAAO;SACd,IAAI,EAAE;SACN,WAAW,EAAE;SACb,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;SACrB,OAAO,CAAC,oCAAoC,EAAE,EAAE,CAAC;SACjD,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,IAAI,EAAE,CAAC;IACV,QAAQ,CAAC,EAAE,CAAC;QACV,4EAA4E;QAC5E,KAAK,SAAS,CAAC;QACf,KAAK,KAAK,CAAC;QACX,KAAK,QAAQ,CAAC;QACd,KAAK,UAAU,CAAC;QAChB,KAAK,SAAS,CAAC;QACf,KAAK,WAAW,CAAC;QACjB,KAAK,MAAM,CAAC;QACZ,KAAK,MAAM,CAAC;QACZ,KAAK,MAAM;YACT,OAAO,KAAK,C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CACb,6DAA6D,KAAK,sBAAsB;gBACtF,uFAAuF;gBACvF,WAAW,CAAC,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,QAAQ,4BAA4B,CACnF,CAAC;QACJ,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACjC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CACb,gDAAgD,MAAM,4BAA4B,KAAK,IAAI;gBACzF,mBAAmB,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,4CAA4C;gBAC1F,+DAA+D,CAClE,CAAC;QACJ,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/scp/guard.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* a fake opcode. This wraps bc's `assertPortable` (no functions/Date/Promise residue)
|
|
9
9
|
* plus the operator-set check.
|
|
10
10
|
*/
|
|
11
|
-
import {
|
|
11
|
+
import type { Component, ComponentGraphIR } from './authoring';
|
|
12
12
|
/** A bc Expression IR node (closed operator set). Structural alias — a JSON expression tree. */
|
|
13
13
|
export type ExprNode = unknown;
|
|
14
14
|
/**
|
package/dist/scp/guard.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../../src/scp/guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../../src/scp/guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/D,gGAAgG;AAChG,MAAM,MAAM,QAAQ,GAAG,OAAO,CAAC;AAE/B;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,SAAM,GAAG,IAAI,CAGnE;AAgDD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,CAqBlE;AAoBD;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,EAAE,EAAE,gBAAgB,GAAG,IAAI,CAEvE"}
|
package/dist/scp/guard.js
CHANGED
|
@@ -98,6 +98,12 @@ function assertComponentPortable(component) {
|
|
|
98
98
|
assertExprPortable(n.cond.then, `${at}/${n.id}.cond.then`);
|
|
99
99
|
assertExprPortable(n.cond.else, `${at}/${n.id}.cond.else`);
|
|
100
100
|
}
|
|
101
|
+
else if ('fanout' in n) {
|
|
102
|
+
// bc 0.7.3+ `FanoutNode` (connection fan-out). litedbmodel never emits fanout, so a
|
|
103
|
+
// fanout node here is an unsupported graph — reject fail-closed rather than treat it as
|
|
104
|
+
// a component ref with `.ports`.
|
|
105
|
+
throw new Error(`${at}/${n.id}: fanout node is not supported by litedbmodel (bc FanoutNode)`);
|
|
106
|
+
}
|
|
101
107
|
else {
|
|
102
108
|
assertPortsPortable(n.ports, `${at}/${n.id}.ports`);
|
|
103
109
|
}
|
package/dist/scp/guard.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guard.js","sourceRoot":"","sources":["../../src/scp/guard.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;
|
|
1
|
+
{"version":3,"file":"guard.js","sourceRoot":"","sources":["../../src/scp/guard.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;AAuBH,gDAGC;AAwDD,0DAqBC;AA0BD,oEAEC;AAjID,2DAAqH;AASrH;;;;;;;;;;;GAWG;AACH,SAAgB,kBAAkB,CAAC,IAAc,EAAE,IAAI,GAAG,GAAG;IAC3D,IAAA,mCAAc,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC3B,QA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