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
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* litedbmodel v2 SCP — the DBModel ActiveRecord ↔ SCP RUNTIME bridge (Phase F-2, epic #74, issue #105).
|
|
4
|
+
*
|
|
5
|
+
* The runtime glue that puts `DBModel`'s pooled execution on the Phase A-E substrate
|
|
6
|
+
* (`exec-context.ts` / `connection-routing.ts` / `middleware.ts` / `tx-options.ts`). It owns two
|
|
7
|
+
* concerns:
|
|
8
|
+
*
|
|
9
|
+
* 1. **Connection wiring** ({@link buildContextFromConfig}) — a v1 `DBConfig` (+ `writerConfig` /
|
|
10
|
+
* writer-sticky options) → a {@link PooledAsyncContext} over REAL pg / mysql2 pools (via
|
|
11
|
+
* `pgPoolFactory` / `mysqlPoolFactory` + `buildRoutingConfig`) and a `close()`. This is the C3
|
|
12
|
+
* `setConfig → ConnectionRegistry → pool` path. Every statement DBModel issues — a v1-built SELECT
|
|
13
|
+
* as much as a compiled write bundle — goes through this ONE ctx, so routing, middleware and an
|
|
14
|
+
* ambient transaction pin apply uniformly.
|
|
15
|
+
*
|
|
16
|
+
* 2. **Write execution** ({@link executeWriteAsync}) — run a compiled write bundle's transaction plan
|
|
17
|
+
* on the writer through the SCP tx runtime (write=tx guard).
|
|
18
|
+
*
|
|
19
|
+
* There is NO runtime read-compile here. A read whose SHAPE is fixed is declared on the `@behavior` /
|
|
20
|
+
* `@leaf` authoring surface and lowered by `bc generate`; a read whose shape is only known per request
|
|
21
|
+
* (`find({where:{age:{gt:x}}})`) runs the v1 imperative builder — compile-free — and reaches the DB
|
|
22
|
+
* through the SAME ctx seam via `DBModel.execute`.
|
|
23
|
+
*
|
|
24
|
+
* The public API + README code are UNCHANGED: `DBModel`'s method signatures / return shapes are
|
|
25
|
+
* identical; this module is an INTERNAL execution substrate.
|
|
26
|
+
*/
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.compileDeleteBundle = exports.compileUpdateBundle = exports.compileCreateBundle = void 0;
|
|
29
|
+
exports.buildContextFromConfig = buildContextFromConfig;
|
|
30
|
+
exports.scpRuntimeGeneration = scpRuntimeGeneration;
|
|
31
|
+
exports.closeAllScpRuntimes = closeAllScpRuntimes;
|
|
32
|
+
exports.executeWriteAsync = executeWriteAsync;
|
|
33
|
+
exports.renderRawSql = renderRawSql;
|
|
34
|
+
require("reflect-metadata");
|
|
35
|
+
const connection_routing_1 = require("./connection-routing");
|
|
36
|
+
const exec_context_1 = require("./exec-context");
|
|
37
|
+
const pool_executor_1 = require("./makesql/pool-executor");
|
|
38
|
+
const tx_1 = require("./makesql/tx");
|
|
39
|
+
const decorator_adapter_1 = require("./decorator-adapter");
|
|
40
|
+
Object.defineProperty(exports, "compileCreateBundle", { enumerable: true, get: function () { return decorator_adapter_1.compileCreateBundle; } });
|
|
41
|
+
Object.defineProperty(exports, "compileUpdateBundle", { enumerable: true, get: function () { return decorator_adapter_1.compileUpdateBundle; } });
|
|
42
|
+
Object.defineProperty(exports, "compileDeleteBundle", { enumerable: true, get: function () { return decorator_adapter_1.compileDeleteBundle; } });
|
|
43
|
+
const handler_1 = require("./makesql/handler");
|
|
44
|
+
/** Map a {@link RuntimeDbConfig} to the C3 {@link ConnectionConfig} pool-construction knobs. */
|
|
45
|
+
function toConnectionConfig(config) {
|
|
46
|
+
return {
|
|
47
|
+
...(config.host !== undefined ? { host: config.host } : {}),
|
|
48
|
+
...(config.port !== undefined ? { port: config.port } : {}),
|
|
49
|
+
...(config.database !== undefined ? { database: config.database } : {}),
|
|
50
|
+
...(config.user !== undefined ? { user: config.user } : {}),
|
|
51
|
+
...(config.password !== undefined ? { password: config.password } : {}),
|
|
52
|
+
...(config.max !== undefined ? { maxPool: config.max } : {}),
|
|
53
|
+
...(config.keepAlive !== undefined ? { keepAlive: config.keepAlive } : {}),
|
|
54
|
+
...(config.keepAliveInitialDelayMillis !== undefined ? { keepAliveInitialDelayMillis: config.keepAliveInitialDelayMillis } : {}),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** Lazily `require` the pg module (optional peer dep). */
|
|
58
|
+
function requirePg() {
|
|
59
|
+
return require('pg');
|
|
60
|
+
}
|
|
61
|
+
/** Lazily `require` the mysql2/promise module (optional peer dep). */
|
|
62
|
+
function requireMysql2() {
|
|
63
|
+
return require('mysql2/promise');
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A {@link PoolFactory} that builds the reader pool from the primary config and (when the setup asks
|
|
67
|
+
* for `separateWriter`) the writer pool from `writerConfig` — a genuine reader/writer replica split on
|
|
68
|
+
* distinct hosts. `buildRoutingConfig` calls this with the resolved config so sizing/keepAlive/de-box
|
|
69
|
+
* options land at pool construction; the writer role overlays the `writerConfig` connection params.
|
|
70
|
+
*/
|
|
71
|
+
function splitPoolFactory(baseFactory, writerConfig) {
|
|
72
|
+
return (resolved, role) => {
|
|
73
|
+
if (role === 'writer' && writerConfig !== undefined) {
|
|
74
|
+
const overlaid = { ...resolved, ...toConnectionConfig(writerConfig) };
|
|
75
|
+
return baseFactory(overlaid, 'writer');
|
|
76
|
+
}
|
|
77
|
+
return baseFactory(resolved, role);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Build a Phase A-E {@link PooledAsyncContext} + reader executor from a v1 `DBConfig` (the
|
|
82
|
+
* `setConfig → ConnectionRegistry → pool` wiring). Constructs a REAL pg / mysql2 pool via
|
|
83
|
+
* `buildRoutingConfig` + the driver pool factory (sizing/keepAlive applied at pool construction), wires
|
|
84
|
+
* the default connection, and — when `writerConfig` is present — a distinct writer pool (reader/writer
|
|
85
|
+
* replica split). The writer-sticky clock is armed per `useWriterAfterTransaction` / `writerStickyDuration`.
|
|
86
|
+
*
|
|
87
|
+
* `sqlite` is NOT routed here (it keeps the v1 in-proc path). Throws for an unsupported driver.
|
|
88
|
+
*/
|
|
89
|
+
function buildContextFromConfig(config, options = {}) {
|
|
90
|
+
const driver = config.driver ?? 'postgres';
|
|
91
|
+
if (driver === 'sqlite') {
|
|
92
|
+
throw new Error('scp dbmodel-runtime: the sqlite dialect is not routed through the async SCP runtime (v1 in-proc path).');
|
|
93
|
+
}
|
|
94
|
+
const dialect = driver === 'mysql' ? 'mysql' : 'postgres';
|
|
95
|
+
const stickyOpts = {
|
|
96
|
+
...(options.useWriterAfterTransaction !== undefined ? { useWriterAfterTransaction: options.useWriterAfterTransaction } : {}),
|
|
97
|
+
...(options.writerStickyDuration !== undefined ? { writerStickyDuration: options.writerStickyDuration } : {}),
|
|
98
|
+
};
|
|
99
|
+
const baseFactory = dialect === 'mysql' ? (0, pool_executor_1.mysqlPoolFactory)(requireMysql2()) : (0, pool_executor_1.pgPoolFactory)(requirePg());
|
|
100
|
+
const hasWriter = options.writerConfig !== undefined;
|
|
101
|
+
const built = (0, connection_routing_1.buildRoutingConfig)([{
|
|
102
|
+
config: toConnectionConfig(config),
|
|
103
|
+
poolFactory: hasWriter ? splitPoolFactory(baseFactory, options.writerConfig) : baseFactory,
|
|
104
|
+
separateWriter: hasWriter,
|
|
105
|
+
}], stickyOpts);
|
|
106
|
+
const ctx = new exec_context_1.PooledAsyncContext(built.routing);
|
|
107
|
+
// The `ctx` (PooledAsyncContext) IS the async read/write seam — there is no separate reader executor.
|
|
108
|
+
// The closer is REGISTERED as well as returned: a caller that drops its `RuntimeContext` without
|
|
109
|
+
// awaiting `close()` (which `DBModel.setConfig` does on every reconfigure) would otherwise leak the
|
|
110
|
+
// pools with no handle left to reach them. `closeAllScpRuntimes` is the drain.
|
|
111
|
+
const runtime = {
|
|
112
|
+
ctx,
|
|
113
|
+
dialect,
|
|
114
|
+
close: async () => {
|
|
115
|
+
liveClosers.delete(built.close);
|
|
116
|
+
await built.close();
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
liveClosers.add(built.close);
|
|
120
|
+
return runtime;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Every pool set this module has constructed and not yet closed.
|
|
124
|
+
*
|
|
125
|
+
* The same shape `src/drivers/mysql.ts` uses for the v1 pools: the module that CREATES the pools owns
|
|
126
|
+
* the registry that can close them. Without it, `closeAllPools()` closed the v1 caches only and the
|
|
127
|
+
* routed SCP pools stayed open — `closeAllPools()` resolved in 0ms with three live sockets, and a
|
|
128
|
+
* consumer process could not exit.
|
|
129
|
+
*/
|
|
130
|
+
const liveClosers = new Set();
|
|
131
|
+
/**
|
|
132
|
+
* Bumped every time {@link closeAllScpRuntimes} closes the pools. `DBModel` caches its `RuntimeContext`
|
|
133
|
+
* per (sub)class; that cache holds pools this generation counter invalidates — after a `closeAllPools()`,
|
|
134
|
+
* a cached runtime points at a CLOSED pool, and the next op must rebuild rather than reuse it (#182). The
|
|
135
|
+
* counter is the seam: the closer lives here (this module owns the pools), the cache lives on `DBModel`,
|
|
136
|
+
* and they agree through this monotonically increasing token.
|
|
137
|
+
*/
|
|
138
|
+
let scpRuntimeGen = 0;
|
|
139
|
+
/** The current SCP-runtime generation; a cached runtime built at an older generation is stale (#182). */
|
|
140
|
+
function scpRuntimeGeneration() {
|
|
141
|
+
return scpRuntimeGen;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Close every pool set {@link buildContextFromConfig} has constructed — including runtimes their owner
|
|
145
|
+
* discarded without closing. Part of the v1 `closeAllPools()` teardown, alongside the per-driver caches.
|
|
146
|
+
* Bumps {@link scpRuntimeGeneration} so `DBModel`'s cached runtimes rebuild instead of reusing a now-closed
|
|
147
|
+
* pool (#182).
|
|
148
|
+
*/
|
|
149
|
+
async function closeAllScpRuntimes() {
|
|
150
|
+
const closers = [...liveClosers];
|
|
151
|
+
liveClosers.clear();
|
|
152
|
+
scpRuntimeGen++;
|
|
153
|
+
for (const close of closers)
|
|
154
|
+
await close();
|
|
155
|
+
}
|
|
156
|
+
// ── 2. Write execution (bundle → executeTransactionAsync) ───────────────────────────────────────
|
|
157
|
+
/** Run a write bundle's transaction plan on the writer through the SCP tx runtime (write=tx guard). */
|
|
158
|
+
function executeWriteAsync(bundle, input, ctx, options = {}) {
|
|
159
|
+
if (bundle.transaction === undefined) {
|
|
160
|
+
throw new Error(`scp dbmodel-runtime: write bundle '${bundle.name}' carries no transaction plan`);
|
|
161
|
+
}
|
|
162
|
+
return (0, tx_1.executeTransactionAsync)(ctx.ctx, bundle.transaction, input, ctx.dialect, options);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Render a v1-built raw SQL string (with `?` placeholders) to the ctx dialect's placeholder form for
|
|
166
|
+
* the escape-hatch seam path: `postgres` renumbers `?`→`$N` (string-literal-aware, via the SAME
|
|
167
|
+
* `renderPlaceholders` the makesql render uses); `mysql` keeps `?`. v1's DBHandler did this `?`→`$N`
|
|
168
|
+
* conversion on the imperative path — the SCP seam passes SQL verbatim to the driver, so the raw path
|
|
169
|
+
* must renumber here to stay byte-equivalent. Phase F-2 (#105).
|
|
170
|
+
*/
|
|
171
|
+
function renderRawSql(sql, dialect) {
|
|
172
|
+
return (0, handler_1.renderPlaceholders)(sql, dialect === 'postgres' ? 'postgres' : dialect === 'mysql' ? 'mysql' : 'sqlite');
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=dbmodel-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dbmodel-runtime.js","sourceRoot":"","sources":["../../src/scp/dbmodel-runtime.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;AAsHH,wDAsCC;AAsBD,oDAEC;AAQD,kDAKC;AAKD,8CAUC;AASD,oCAEC;AAzND,4BAA0B;AAC1B,6DAM8B;AAC9B,iDAAoD;AACpD,2DAGiC;AAEjC,qCAA+E;AAE/E,2DAM6B;AAsMpB,oGA3MP,uCAAmB,OA2MO;AAAE,oGA1M5B,uCAAmB,OA0M4B;AAAE,oGAzMjD,uCAAmB,OAyMiD;AArMtE,+CAAuD;AA4CvD,gGAAgG;AAChG,SAAS,kBAAkB,CAAC,MAAuB;IACjD,OAAO;QACL,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3D,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3D,GAAG,CAAC,MAAM,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACv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EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC3F,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,YAAY,CAAC,GAAW,EAAE,OAAoB;IAC5D,OAAO,IAAA,4BAAkB,EAAC,GAAG,EAAE,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;AACjH,CAAC"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* litedbmodel v2 SCP — the decorator METADATA adapter (Phase F-1, epic #74, issue #104).
|
|
3
|
+
*
|
|
4
|
+
* litedbmodel's decorators are metadata-only COLLECTORS: `@column` / `@hasMany` / … record
|
|
5
|
+
* `ColumnMeta` / `RelationMeta` / `TABLE_NAME` on the class (`src/decorators.ts`, via `reflect-metadata`
|
|
6
|
+
* + `_columnMeta` / `_relationMeta`). This module READS that registry and translates it into the SCP-level
|
|
7
|
+
* facts the rest of the stack consumes, plus the write bundles a decorated model compiles to. It builds
|
|
8
|
+
* NO SQL structure of its own and holds NO authoring vocabulary — the decorator never emits IR, and the
|
|
9
|
+
* adapter never re-implements composition.
|
|
10
|
+
*
|
|
11
|
+
* ## What the adapter translates
|
|
12
|
+
*
|
|
13
|
+
* 1. **Columns** (the one real translation): `@column.*` `ColumnMeta` (the decorator already knows the
|
|
14
|
+
* type family — bigint / date / boolean / uuid / json / array / …) → the SCP column SoT
|
|
15
|
+
* ({@link ModelColumns}: the SQL-type token per column, validated by `coltype.ts`). See
|
|
16
|
+
* {@link deriveModelColumns} + {@link COLUMN_FAMILY_SQL_TYPE}. The typed-read `outType` and the
|
|
17
|
+
* relation key-array element type both resolve against exactly this SoT.
|
|
18
|
+
* 2. **Relations**: `@hasMany` / `@belongsTo` / `@hasOne` `RelationMeta` → {@link RelationDecl} →
|
|
19
|
+
* `compileRelationOp` (single + composite keys, per-parent `limit` window + `hardLimit`).
|
|
20
|
+
* 3. **Write bundles**: `createMany` (and a `create` WITH `onConflict`) / `updateMany` / `deleteMany` →
|
|
21
|
+
* `compileCreateManyBundle` / `compileUpdateManyBundle` / `compileDeleteManyBundle`, with the
|
|
22
|
+
* model's column SoT threaded as the write de-box resolver.
|
|
23
|
+
*
|
|
24
|
+
* READS are NOT compiled here. A read endpoint is DECLARED on the `@behavior` / `@leaf` authoring
|
|
25
|
+
* surface and lowered by `bc generate`; an ad-hoc runtime-shaped query runs the v1 imperative path.
|
|
26
|
+
*/
|
|
27
|
+
import { type SqlBundle } from './write-bundle';
|
|
28
|
+
import { type RelationDecl, type RelationOp } from './relation';
|
|
29
|
+
import { type BcScalar, type ColumnTypeResolver } from './coltype';
|
|
30
|
+
import type { DialectName } from './dialect';
|
|
31
|
+
import type { InsertManyBuildOptions } from './makesql/compile-crud';
|
|
32
|
+
import type { UpdateManyBuildOptions } from '../drivers/types';
|
|
33
|
+
import { type ColumnMeta, type RelationMeta } from '../decorators';
|
|
34
|
+
/**
|
|
35
|
+
* The model's inline typed-column declaration: `table → (column → SQL type token)` — the consumer-inline
|
|
36
|
+
* column-type SoT (bc never infers types; the author annotates them). SQL type tokens are the §4.1
|
|
37
|
+
* vocabulary (`INTEGER`/`INT`/`BIGINT`/`REAL`/`DOUBLE`/`DECIMAL(…)`/`TEXT`/`VARCHAR(…)`/`BOOLEAN`/
|
|
38
|
+
* `DATE`/`TIMESTAMP`/`JSON`/`JSONB`/`UUID`/…).
|
|
39
|
+
*/
|
|
40
|
+
export type ModelColumns = Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
41
|
+
/**
|
|
42
|
+
* Resolve the de-box bc element scalar of a relation's parent-key column ((table, column) → bc scalar),
|
|
43
|
+
* so a relation key array carries the type the READ-materialized key value actually holds
|
|
44
|
+
* (INT→`float` / BIGINT→`string` / text/uuid→`string`) — see {@link keyArrayElemScalar}.
|
|
45
|
+
*/
|
|
46
|
+
export type KeyTypeResolver = (table: string, column: string) => BcScalar;
|
|
47
|
+
/**
|
|
48
|
+
* The decorator's `ColumnMeta.sqlCast` type-family token → the canonical §4.1 SQL-type token the SCP
|
|
49
|
+
* `static columns` SoT carries (validated by `coltype.ts`). The decorator ALREADY knows the family
|
|
50
|
+
* (it set `sqlCast` from the `@column.*` variant / the `design:type` inference — `src/decorators.ts`),
|
|
51
|
+
* so this is a pure token normalization, no inference. `coltype.ts` accepts every RHS here:
|
|
52
|
+
* BOOLEAN/BIGINT/TIMESTAMP/DATE/UUID/JSONB are scalar; the array tokens de-box as `passthrough`
|
|
53
|
+
* (`sqlTypeToMaterializeClass`).
|
|
54
|
+
*
|
|
55
|
+
* The RHS matches the decorator families 1:1:
|
|
56
|
+
* - `boolean` → `BOOLEAN` (`@column.boolean()` / auto `Boolean`)
|
|
57
|
+
* - `bigint` → `BIGINT` (`@column.bigint()` / auto `BigInt` — read de-box: exact string)
|
|
58
|
+
* - `timestamp` → `TIMESTAMP` (`@column.datetime()` / auto `Date` — read de-box: TZ string)
|
|
59
|
+
* - `date` → `DATE` (`@column.date()` — read de-box: YYYY-MM-DD string)
|
|
60
|
+
* - `uuid` → `UUID` (`@column.uuid()`)
|
|
61
|
+
* - `jsonb` → `JSONB` (`@column.json()`)
|
|
62
|
+
* - `text[]` / `int[]` / `numeric[]` / `boolean[]` → the array token (`@column.*Array()`)
|
|
63
|
+
*/
|
|
64
|
+
export declare const COLUMN_FAMILY_SQL_TYPE: Readonly<Record<string, string>>;
|
|
65
|
+
/**
|
|
66
|
+
* The LAST-RESORT SQL type for a column that carries NO `sqlCast` family, NO `baseSqlType` (its
|
|
67
|
+
* `design:type` is absent — no `emitDecoratorMetadata` — or is an Array/Object family), and NO
|
|
68
|
+
* `columnTypes` override. Phase F-2 (#105 option B) made {@link columnSqlType} consult the decorator's
|
|
69
|
+
* `baseSqlType` (derived from the field's TS `design:type`: String→TEXT / Number→INTEGER / Boolean→
|
|
70
|
+
* BOOLEAN / Date→TIMESTAMP / BigInt→BIGINT) BEFORE this default, so a bare `@column() name: string`
|
|
71
|
+
* types as `TEXT` (not `INTEGER`) — the fix for F1's blanket-INTEGER read-de-box defect (it threw
|
|
72
|
+
* `materialize int32` on a live string column). This default now only applies when `design:type` is
|
|
73
|
+
* genuinely unavailable; a REAL/DECIMAL column (a `Number` that is not INT) is pinned via
|
|
74
|
+
* {@link DeriveColumnsOptions.columnTypes} (the escape hatch, unchanged from F1).
|
|
75
|
+
*/
|
|
76
|
+
export declare const DEFAULT_UNCAST_SQL_TYPE = "INTEGER";
|
|
77
|
+
/** Options for {@link deriveModelColumns}. */
|
|
78
|
+
export interface DeriveColumnsOptions {
|
|
79
|
+
/**
|
|
80
|
+
* Per-column SQL-type OVERRIDES (property name → §4.1 SQL type token), for columns whose decorator
|
|
81
|
+
* family is ambiguous (a bare `Number` that is actually REAL/DECIMAL) or that need a non-default
|
|
82
|
+
* width. Takes precedence over the family-derived token. The escape hatch for the no-INT-vs-REAL
|
|
83
|
+
* decorator gap — no assumption is baked into the engine.
|
|
84
|
+
*/
|
|
85
|
+
readonly columnTypes?: Readonly<Record<string, string>>;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Translate ONE column's {@link ColumnMeta} to its §4.1 SQL-type token. Precedence (Phase F-2 / #105
|
|
89
|
+
* option B):
|
|
90
|
+
* 1. an explicit `columnTypes` override (the REAL/DECIMAL/width escape hatch) wins;
|
|
91
|
+
* 2. else the family token from {@link COLUMN_FAMILY_SQL_TYPE} (an explicit `@column.*` `sqlCast`);
|
|
92
|
+
* 3. else the decorator's `baseSqlType` — derived from the field's TS `design:type` (String→TEXT /
|
|
93
|
+
* Number→INTEGER / Boolean→BOOLEAN / Date→TIMESTAMP / BigInt→BIGINT), so a bare `@column()` types
|
|
94
|
+
* correctly for the SCP typed-read de-box (the fix for F1's blanket-INTEGER default);
|
|
95
|
+
* 4. else {@link DEFAULT_UNCAST_SQL_TYPE} (only when `design:type` is unavailable).
|
|
96
|
+
* Fail-closed: a family token the mapping does not know, or a produced token `coltype.ts` rejects,
|
|
97
|
+
* THROWS (naming the column) — never a silent skip (no-assume, no-fallback).
|
|
98
|
+
*/
|
|
99
|
+
export declare function columnSqlType(propKey: string, meta: ColumnMeta, override?: string): string;
|
|
100
|
+
/**
|
|
101
|
+
* Derive the SCP `static columns` ({@link ModelColumns}) for a decorated model class from its
|
|
102
|
+
* `@column` `ColumnMeta` registry (the decorator IS the type SoT for v1/v2's decorator surface). The
|
|
103
|
+
* table is the model's `TABLE_NAME` (or the model-name lowercased, matching the decorator's
|
|
104
|
+
* `effectiveTableName`). Each column keys by its DB `columnName` (what a SELECT projects), mapping to
|
|
105
|
+
* its §4.1 SQL type. A model with no `@column` declarations yields no table entry.
|
|
106
|
+
*
|
|
107
|
+
* This is the ONE real translation in the adapter — the read-path de-box (INT→number / BIGINT→string /
|
|
108
|
+
* DATE→string / BOOLEAN→boolean) and the codegen `outType` both consult exactly this SoT.
|
|
109
|
+
*/
|
|
110
|
+
export declare function deriveModelColumns(modelClass: ModelClassLike, options?: DeriveColumnsOptions): ModelColumns;
|
|
111
|
+
/** The decorated model class shape the adapter reads (a `@model`-decorated `DBModel` subclass). */
|
|
112
|
+
export interface ModelClassLike {
|
|
113
|
+
readonly name: string;
|
|
114
|
+
readonly TABLE_NAME?: string;
|
|
115
|
+
}
|
|
116
|
+
/** The effective table name (v1 `@model` rule): explicit `TABLE_NAME`, else the model name lowercased. */
|
|
117
|
+
export declare function tableNameOf(modelClass: ModelClassLike): string;
|
|
118
|
+
/**
|
|
119
|
+
* Compile a decorated model's `createMany` — and a `create` WITH `onConflict` (upsert) — into a batch
|
|
120
|
+
* write {@link SqlBundle} via `compileCreateManyBundle`. This is the UPSERT carry: `onConflict` /
|
|
121
|
+
* `onConflictUpdate` / `onConflictIgnore` are `compileInsertMany` BUILD options (not authored ports),
|
|
122
|
+
* so they carry end-to-end here with NO SCP authoring addition — exactly as v1's `create` and
|
|
123
|
+
* `createMany` share the ONE `DBModel._insert` grouping path (`buildInsert` handles ON CONFLICT for
|
|
124
|
+
* both a single record and a batch). A single-record `records` array is a one-group createMany that
|
|
125
|
+
* emits the SAME statement `_insert` does for a single upsert.
|
|
126
|
+
*
|
|
127
|
+
* Parity scope (the v1/v2 SQL-parity rule, per dialect — NOT a blanket "byte-identical to v1"): on
|
|
128
|
+
* **Postgres** the emitted upsert INSERT is byte-identical to v1 (`compileInsertMany` copies the v1
|
|
129
|
+
* `buildInsert` verbatim; PG stays base-class tuple/placeholder form). On **MySQL / SQLite** the v2
|
|
130
|
+
* form is the JSON-array single-param shape (`json_each` / `JSON_TABLE`), which is DELIBERATELY NOT
|
|
131
|
+
* byte-identical to v1's per-row placeholder expansion — it is the established v2 shape the conformance
|
|
132
|
+
* corpus freezes (#64/#65), executing to the same rows. So: pg = v1-byte-identical; mysql/sqlite = the
|
|
133
|
+
* v2 JSON-array form (equivalent result, distinct text).
|
|
134
|
+
*
|
|
135
|
+
* @param options the `compileCreateManyBundle` options (records / rawRecords / sqlCastMap / onConflict /
|
|
136
|
+
* onConflictUpdate / onConflictIgnore / returning / pk) — already serialized as `DBModel._insert`
|
|
137
|
+
* holds them.
|
|
138
|
+
*/
|
|
139
|
+
export declare function compileCreateBundle(modelClass: ModelClassLike, name: string, options: InsertManyBuildOptions & {
|
|
140
|
+
pk?: {
|
|
141
|
+
columns: readonly string[];
|
|
142
|
+
autoInc: string | null;
|
|
143
|
+
};
|
|
144
|
+
}, dialect?: DialectName, columnsOptions?: DeriveColumnsOptions): SqlBundle;
|
|
145
|
+
/** Compile a decorated model's `updateMany` into a batch write {@link SqlBundle} (`compileUpdateManyBundle`). */
|
|
146
|
+
export declare function compileUpdateBundle(name: string, options: UpdateManyBuildOptions, dialect?: DialectName): SqlBundle;
|
|
147
|
+
/**
|
|
148
|
+
* Compile a decorated model's `deleteMany` into a batch write {@link SqlBundle} (`compileDeleteManyBundle`):
|
|
149
|
+
* a PK-set IN-list DELETE (single key) or one DELETE per composite-key group. `keyColumns` +
|
|
150
|
+
* `returning` carry straight through.
|
|
151
|
+
*/
|
|
152
|
+
export declare function compileDeleteBundle(name: string, options: {
|
|
153
|
+
tableName: string;
|
|
154
|
+
keyColumns: string[];
|
|
155
|
+
keys: Record<string, unknown>[];
|
|
156
|
+
returning?: string;
|
|
157
|
+
}, dialect?: DialectName): SqlBundle;
|
|
158
|
+
/**
|
|
159
|
+
* Build a {@link KeyTypeResolver} from a decorated model's `static columns` SoT — `(table, column) →`
|
|
160
|
+
* the de-box bc scalar of that key column ({@link import('./coltype').keyArrayElemScalar}). Threaded into
|
|
161
|
+
* {@link relationReadAuthoring} so each relation's `pluck` key array is stamped with the type its
|
|
162
|
+
* READ-materialized key value carries. Returns `undefined` when the model declares no columns.
|
|
163
|
+
*/
|
|
164
|
+
export declare function relationKeyTypeResolver(modelClass: ModelClassLike, columnsOptions?: DeriveColumnsOptions): KeyTypeResolver | undefined;
|
|
165
|
+
/** The fail-closed column-type resolver for a decorated model (its `static columns` SoT), or `undefined` if it has no columns. */
|
|
166
|
+
export declare function modelColumnResolver(modelClass: ModelClassLike, columnsOptions?: DeriveColumnsOptions): ColumnTypeResolver | undefined;
|
|
167
|
+
/**
|
|
168
|
+
* Translate a decorated model's `@hasMany` / `@belongsTo` / `@hasOne` {@link RelationMeta} registry
|
|
169
|
+
* into SCP {@link RelationDecl}s. Single AND composite keys are supported: the decorator's
|
|
170
|
+
* `keysFactory` resolves lazily (forward refs) to `[srcCol, tgtCol]` (single) or `[[…],[…]]`
|
|
171
|
+
* (composite); the target table + projection come from the target model's `@column` metadata (the
|
|
172
|
+
* relation projects the child's OWN columns). Per-parent `order` / `limit` (hasMany window) and
|
|
173
|
+
* `hardLimit` carry from the decorator `options`.
|
|
174
|
+
*
|
|
175
|
+
* @param modelClass the parent (source) `@model` class.
|
|
176
|
+
* @param resolveTargetModel model NAME → the target `@model` class (the decorator records the target
|
|
177
|
+
* model NAME on the key column; the caller supplies the registry — same lazy-resolution shape v1's
|
|
178
|
+
* `_loadRelation` uses).
|
|
179
|
+
*/
|
|
180
|
+
export declare function deriveRelationDecls(modelClass: ModelClassLike, resolveTargetModel: (modelName: string) => ModelClassLike, dialect?: DialectName): RelationDecl[];
|
|
181
|
+
/**
|
|
182
|
+
* Translate ONE {@link RelationMeta} → a {@link RelationDecl} (single or composite key) AND the
|
|
183
|
+
* resolved target model (so a caller can bake the child's de-box materializers from the TARGET
|
|
184
|
+
* model's `static columns` — the relation projects the child's own columns).
|
|
185
|
+
*/
|
|
186
|
+
export declare function relationDeclOf(rel: RelationMeta, resolveTargetModel: (modelName: string) => ModelClassLike, dialect?: DialectName): {
|
|
187
|
+
decl: RelationDecl;
|
|
188
|
+
targetModel: ModelClassLike;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Compile a decorated model's relation registry into ready {@link RelationOp}s (one per relation). Each
|
|
192
|
+
* op's child-column de-box materializers are baked from the TARGET model's `static columns` (the same
|
|
193
|
+
* resolution the primary read uses) — ZERO per-read introspection.
|
|
194
|
+
*/
|
|
195
|
+
export declare function compileRelationOps(modelClass: ModelClassLike, resolveTargetModel: (modelName: string) => ModelClassLike, dialect?: DialectName, columnsOptions?: DeriveColumnsOptions): Record<string, RelationOp>;
|
|
196
|
+
//# sourceMappingURL=decorator-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator-adapter.d.ts","sourceRoot":"","sources":["../../src/scp/decorator-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAqB,KAAK,YAAY,EAAqB,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AACtG,OAAO,EAAkF,KAAK,QAAQ,EAAE,KAAK,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACnJ,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,O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