litedbmodel 2.2.2 → 2.2.4
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 +2 -1
- package/dist/DBModel.d.ts.map +1 -1
- package/dist/DBModel.js +3 -0
- package/dist/DBModel.js.map +1 -1
- package/dist/Middleware.d.ts +19 -2
- package/dist/Middleware.d.ts.map +1 -1
- package/dist/Middleware.js +1 -0
- package/dist/Middleware.js.map +1 -1
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +8 -0
- package/dist/decorators.js.map +1 -1
- package/dist/drivers/MysqlHelper.d.ts +1 -1
- package/dist/drivers/MysqlHelper.d.ts.map +1 -1
- package/dist/drivers/MysqlHelper.js.map +1 -1
- package/dist/drivers/PostgresHelper.d.ts +1 -1
- package/dist/drivers/PostgresHelper.d.ts.map +1 -1
- package/dist/drivers/PostgresHelper.js.map +1 -1
- package/dist/drivers/SqliteHelper.d.ts +1 -1
- package/dist/drivers/SqliteHelper.d.ts.map +1 -1
- package/dist/drivers/SqliteHelper.js.map +1 -1
- package/dist/index.cjs +105 -74
- package/dist/scp/connection-routing.d.ts +38 -1
- package/dist/scp/connection-routing.d.ts.map +1 -1
- package/dist/scp/connection-routing.js +64 -5
- package/dist/scp/connection-routing.js.map +1 -1
- package/dist/scp/dbmodel-runtime.d.ts +2 -1
- package/dist/scp/dbmodel-runtime.d.ts.map +1 -1
- package/dist/scp/dbmodel-runtime.js +2 -1
- package/dist/scp/dbmodel-runtime.js.map +1 -1
- package/dist/scp/decorator-adapter.d.ts +22 -0
- package/dist/scp/decorator-adapter.d.ts.map +1 -1
- package/dist/scp/decorator-adapter.js +26 -0
- package/dist/scp/decorator-adapter.js.map +1 -1
- package/dist/scp/emit/emitter.d.ts +21 -10
- package/dist/scp/emit/emitter.d.ts.map +1 -1
- package/dist/scp/emit/emitter.js +119 -51
- package/dist/scp/emit/emitter.js.map +1 -1
- package/dist/scp/emit/endpoint.d.ts +3 -8
- package/dist/scp/emit/endpoint.d.ts.map +1 -1
- package/dist/scp/exec-context.d.ts +39 -17
- package/dist/scp/exec-context.d.ts.map +1 -1
- package/dist/scp/exec-context.js +69 -35
- package/dist/scp/exec-context.js.map +1 -1
- package/dist/scp/grouping.d.ts.map +1 -1
- package/dist/scp/grouping.js +0 -0
- package/dist/scp/grouping.js.map +1 -1
- package/dist/scp/index.cjs +257 -670
- package/dist/scp/index.d.ts +6 -11
- package/dist/scp/index.d.ts.map +1 -1
- package/dist/scp/index.js +10 -28
- package/dist/scp/index.js.map +1 -1
- package/dist/scp/index.mjs +257 -658
- package/dist/scp/leaf-transport.d.ts +127 -39
- package/dist/scp/leaf-transport.d.ts.map +1 -1
- package/dist/scp/leaf-transport.js +30 -24
- package/dist/scp/leaf-transport.js.map +1 -1
- package/dist/scp/leaves.d.ts +57 -20
- package/dist/scp/leaves.d.ts.map +1 -1
- package/dist/scp/leaves.js +224 -65
- package/dist/scp/leaves.js.map +1 -1
- package/dist/scp/makesql/compile-select.d.ts +28 -1
- package/dist/scp/makesql/compile-select.d.ts.map +1 -1
- package/dist/scp/makesql/compile-select.js +19 -17
- package/dist/scp/makesql/compile-select.js.map +1 -1
- package/dist/scp/makesql/index.d.ts +2 -2
- package/dist/scp/makesql/index.d.ts.map +1 -1
- package/dist/scp/makesql/index.js +4 -6
- package/dist/scp/makesql/index.js.map +1 -1
- package/dist/scp/makesql/tx.d.ts +43 -89
- package/dist/scp/makesql/tx.d.ts.map +1 -1
- package/dist/scp/makesql/tx.js +45 -496
- package/dist/scp/makesql/tx.js.map +1 -1
- package/dist/scp/makesql/writeouttype.d.ts +5 -7
- package/dist/scp/makesql/writeouttype.d.ts.map +1 -1
- package/dist/scp/makesql/writeouttype.js +13 -19
- package/dist/scp/makesql/writeouttype.js.map +1 -1
- package/dist/scp/middleware.d.ts +4 -4
- package/dist/scp/middleware.d.ts.map +1 -1
- package/dist/scp/middleware.js +2 -2
- package/dist/scp/middleware.js.map +1 -1
- package/dist/scp/relation.d.ts +31 -12
- package/dist/scp/relation.d.ts.map +1 -1
- package/dist/scp/relation.js +16 -6
- package/dist/scp/relation.js.map +1 -1
- package/dist/scp/typed-object.d.ts +23 -19
- package/dist/scp/typed-object.d.ts.map +1 -1
- package/dist/scp/typed-object.js +24 -30
- package/dist/scp/typed-object.js.map +1 -1
- package/dist/scp/write-bundle.d.ts +21 -70
- package/dist/scp/write-bundle.d.ts.map +1 -1
- package/dist/scp/write-bundle.js +16 -80
- package/dist/scp/write-bundle.js.map +1 -1
- package/dist/types.d.ts +12 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/docs/BENCHMARK.md +26 -22
- package/docs/COMPARISON.md +8 -4
- package/docs/api/README.md +1 -1
- package/docs/api/classes/Conditions.md +10 -10
- package/docs/api/classes/DBHandler.md +17 -17
- package/docs/api/classes/DBModel.md +111 -104
- package/docs/api/classes/LimitExceededError.md +8 -8
- package/docs/api/classes/Middleware.md +18 -18
- package/docs/api/classes/SqlRaw.md +6 -6
- package/docs/api/classes/SqlRef.md +7 -7
- package/docs/api/classes/Values.md +6 -6
- package/docs/api/classes/WriteInReadOnlyContextError.md +5 -5
- package/docs/api/classes/WriteOutsideTransactionError.md +5 -5
- package/docs/api/functions/belongsTo.md +2 -2
- package/docs/api/functions/closeAllPools.md +2 -2
- package/docs/api/functions/condsToRecord.md +2 -2
- package/docs/api/functions/createMiddleware.md +2 -2
- package/docs/api/functions/createPostgresDriver.md +2 -2
- package/docs/api/functions/createSqliteDriver.md +2 -2
- package/docs/api/functions/dbCast.md +3 -3
- package/docs/api/functions/dbCastIn.md +2 -2
- package/docs/api/functions/dbDynamic.md +3 -3
- package/docs/api/functions/dbFalse.md +2 -2
- package/docs/api/functions/dbImmediate.md +2 -2
- package/docs/api/functions/dbIn.md +2 -2
- package/docs/api/functions/dbNotNull.md +2 -2
- package/docs/api/functions/dbNow.md +2 -2
- package/docs/api/functions/dbNull.md +2 -2
- package/docs/api/functions/dbRaw.md +2 -2
- package/docs/api/functions/dbTrue.md +2 -2
- package/docs/api/functions/dbUuid.md +3 -3
- package/docs/api/functions/dbUuidIn.md +2 -2
- package/docs/api/functions/formatLocalDate.md +25 -0
- package/docs/api/functions/formatUTCDate.md +25 -0
- package/docs/api/functions/getDBConfig.md +2 -2
- package/docs/api/functions/getDBHandler.md +2 -2
- package/docs/api/functions/getTransactionConnection.md +2 -2
- package/docs/api/functions/getTransactionContext.md +2 -2
- package/docs/api/functions/hasMany.md +2 -2
- package/docs/api/functions/hasOne.md +2 -2
- package/docs/api/functions/initDBHandler.md +2 -2
- package/docs/api/functions/isAnySqlFragment.md +2 -2
- package/docs/api/functions/isConnectionError.md +26 -0
- package/docs/api/functions/isSqlCondition.md +2 -2
- package/docs/api/functions/isSqlFragment.md +2 -2
- package/docs/api/functions/isSqlRaw.md +2 -2
- package/docs/api/functions/isSqlRef.md +2 -2
- package/docs/api/functions/isSqlTypedFragment.md +2 -2
- package/docs/api/functions/model.md +6 -42
- package/docs/api/functions/parentRef.md +2 -2
- package/docs/api/functions/sql.md +7 -7
- package/docs/api/globals.md +57 -22
- package/docs/api/interfaces/Column.md +31 -31
- package/docs/api/interfaces/ColumnOptions.md +5 -4
- package/docs/api/interfaces/CreatedMiddlewareClass.md +7 -7
- package/docs/api/interfaces/DBConfig.md +13 -11
- package/docs/api/interfaces/DBConfigOptions.md +8 -8
- package/docs/api/interfaces/DeleteOptions.md +4 -4
- package/docs/api/interfaces/InsertOptions.md +8 -8
- package/docs/api/interfaces/LimitConfig.md +4 -4
- package/docs/api/interfaces/MiddlewareConfig.md +15 -15
- package/docs/api/interfaces/ModelOptions.md +8 -7
- package/docs/api/interfaces/PkeyResult.md +4 -4
- package/docs/api/interfaces/SelectOptions.md +17 -16
- package/docs/api/interfaces/SqlCondition.md +6 -6
- package/docs/api/interfaces/SqlFragment.md +5 -5
- package/docs/api/interfaces/SqlTypedFragment.md +7 -7
- package/docs/api/interfaces/TransactionOptions.md +7 -7
- package/docs/api/interfaces/UpdateManyOptions.md +4 -4
- package/docs/api/interfaces/UpdateOptions.md +4 -4
- package/docs/architecture.md +452 -0
- package/docs/benchmark-chart.svg +225 -249
- package/docs/design/phase-a-execution-context.md +2 -0
- package/package.json +20 -5
- package/dist/scp/writes.d.ts +0 -251
- package/dist/scp/writes.d.ts.map +0 -1
- package/dist/scp/writes.js +0 -176
- package/dist/scp/writes.js.map +0 -1
- package/docs/proposal/contracts-architecture-feasibility.md +0 -328
- package/docs/proposal/contracts-architecture.md +0 -579
- package/docs/proposal/litedbmodel-v2-scp-architecture.md +0 -433
- package/docs/proposal/sql-dynamic-expansion-spec.md +0 -175
- package/docs/proposal/v0-coverage-matrix.md +0 -157
- package/docs/proposal/v2-completeness-plan.md +0 -90
- package/docs/proposal/v2-sql-parity-checklist.md +0 -162
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
* catalog leaf + handler + compile. Pure-JSON bundle, multi-language ready.
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.
|
|
14
|
-
exports.mysqlPoolFactory = exports.pgPoolFactory = exports.mysqlConnectionPool = exports.pgConnectionPool = exports.mysqlDeboxPoolOptions = exports.configurePgDeboxTypeParsers = exports.bindReselect = exports.buildMysqlReselect = exports.stripMysqlPkHint = exports.mysqlPkHint = exports.IN_SENTINEL = exports.
|
|
13
|
+
exports.pgTypeSpecimen = exports.compileWriteNode = exports.renderTxStatement = exports.executeTransactionAsync = exports.literalize = exports.deriveBatchPlan = exports.rowsHaveDbToken = exports.mysqlJsonTableColumn = exports.sqliteUpdateManyJson = exports.mysqlUpdateManyJson = exports.sqliteInsertJson = exports.mysqlInsertJson = exports.conditionsFor = exports.JsonArrayConditions = exports.encodeJsonArrayParam = exports.inListPredicate = exports.inListJson = exports.compileCompositeKeyStaticLimited = exports.compileCompositeKeyLimited = exports.compileCompositeKeyStaticUnlimited = exports.compileCompositeKeyUnlimited = exports.compileSingleKeyLimited = exports.compileSingleKeyUnlimited = exports.PG_ARRAY_CAST_TOKEN = exports.resolvePgArrayCast = exports.inferPgArrayType = exports.compileDeleteMany = exports.compileDelete = exports.compileUpdateSingle = exports.compileUpdateMany = exports.compileInsertMany = exports.compileInsert = exports.builderFor = exports.compileSelect = exports.noCastFormatter = exports.pgCastFormatter = exports.formatterFor = exports.andTrailing = exports.whereClause = exports.compileWhere = exports.makeSqlHandlerSync = exports.makeSqlHandler = exports.renderPorts = exports.renderPlaceholders = exports.composeMakeSQL = exports.assembleMakeSQL = exports.isMakeSQL = exports.LITEDBMODEL_MAKESQL_CATALOG = exports.makeSqlCatalogEntry = exports.MAKESQL = void 0;
|
|
14
|
+
exports.mysqlPoolFactory = exports.pgPoolFactory = exports.mysqlConnectionPool = exports.pgConnectionPool = exports.mysqlDeboxPoolOptions = exports.configurePgDeboxTypeParsers = exports.bindReselect = exports.buildMysqlReselect = exports.stripMysqlPkHint = exports.mysqlPkHint = exports.IN_SENTINEL = exports.ENTITY_ROOT = void 0;
|
|
15
15
|
// Catalog leaf + assembly core.
|
|
16
16
|
var makesql_1 = require("./makesql");
|
|
17
17
|
Object.defineProperty(exports, "MAKESQL", { enumerable: true, get: function () { return makesql_1.MAKESQL; } });
|
|
@@ -72,17 +72,15 @@ Object.defineProperty(exports, "mysqlUpdateManyJson", { enumerable: true, get: f
|
|
|
72
72
|
Object.defineProperty(exports, "sqliteUpdateManyJson", { enumerable: true, get: function () { return json_batch_1.sqliteUpdateManyJson; } });
|
|
73
73
|
Object.defineProperty(exports, "mysqlJsonTableColumn", { enumerable: true, get: function () { return json_batch_1.mysqlJsonTableColumn; } });
|
|
74
74
|
Object.defineProperty(exports, "rowsHaveDbToken", { enumerable: true, get: function () { return json_batch_1.rowsHaveDbToken; } });
|
|
75
|
-
// Write
|
|
75
|
+
// Write descriptor → makeSQL statement, batch plan derivation, and the live async 1-tx runtime.
|
|
76
76
|
var tx_1 = require("./tx");
|
|
77
|
-
Object.defineProperty(exports, "deriveTransactionPlan", { enumerable: true, get: function () { return tx_1.deriveTransactionPlan; } });
|
|
78
77
|
Object.defineProperty(exports, "deriveBatchPlan", { enumerable: true, get: function () { return tx_1.deriveBatchPlan; } });
|
|
79
78
|
Object.defineProperty(exports, "literalize", { enumerable: true, get: function () { return tx_1.literalize; } });
|
|
80
|
-
Object.defineProperty(exports, "executeTransaction", { enumerable: true, get: function () { return tx_1.executeTransaction; } });
|
|
81
79
|
Object.defineProperty(exports, "executeTransactionAsync", { enumerable: true, get: function () { return tx_1.executeTransactionAsync; } });
|
|
82
|
-
Object.defineProperty(exports, "countingDriver", { enumerable: true, get: function () { return tx_1.countingDriver; } });
|
|
83
80
|
Object.defineProperty(exports, "renderTxStatement", { enumerable: true, get: function () { return tx_1.renderTxStatement; } });
|
|
84
81
|
Object.defineProperty(exports, "compileWriteNode", { enumerable: true, get: function () { return tx_1.compileWriteNode; } });
|
|
85
82
|
Object.defineProperty(exports, "pgTypeSpecimen", { enumerable: true, get: function () { return tx_1.pgTypeSpecimen; } });
|
|
83
|
+
Object.defineProperty(exports, "ENTITY_ROOT", { enumerable: true, get: function () { return tx_1.ENTITY_ROOT; } });
|
|
86
84
|
Object.defineProperty(exports, "IN_SENTINEL", { enumerable: true, get: function () { return tx_1.IN_SENTINEL; } });
|
|
87
85
|
// MySQL has no RETURNING: the pk-hint format + the write→re-select derivation the mysql connection
|
|
88
86
|
// adapter (and the 4 native driver ports) share. ONE home for "MySQL cannot RETURN rows".
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scp/makesql/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;AAEH,gCAAgC;AAChC,qCAOmB;AANjB,kGAAA,OAAO,OAAA;AACP,8GAAA,mBAAmB,OAAA;AACnB,sHAAA,2BAA2B,OAAA;AAC3B,oGAAA,SAAS,OAAA;AACT,0GAAA,eAAe,OAAA;AACf,yGAAA,cAAc,OAAA;AAIhB,wCAAwC;AACxC,qC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BAAoB,OAAA;AAAE,iHAAA,mBAAmB,OAAA;AAAE,2GAAA,aAAa,OAAA;AAC9F,2CAOsB;AANpB,6GAAA,eAAe,OAAA;AACf,8GAAA,gBAAgB,OAAA;AAChB,iHAAA,mBAAmB,OAAA;AACnB,kHAAA,oBAAoB,OAAA;AACpB,kHAAA,oBAAoB,OAAA;AACpB,6GAAA,eAAe,OAAA;AAGjB,gGAAgG;AAChG,2BASc;AARZ,qGAAA,eAAe,OAAA;AACf,gGAAA,UAAU,OAAA;AACV,6GAAA,uBAAuB,OAAA;AACvB,uGAAA,iBAAiB,OAAA;AACjB,sGAAA,gBAAgB,OAAA;AAChB,oGAAA,cAAc,OAAA;AACd,iGAAA,WAAW,OAAA;AACX,iGAAA,WAAW,OAAA;AAGb,mGAAmG;AACnG,0FAA0F;AAC1F,qDAAoG;AAA3F,8GAAA,WAAW,OAAA;AAAE,mHAAA,gBAAgB,OAAA;AAAE,qHAAA,kBAAkB,OAAA;AAAE,+GAAA,YAAY,OAAA;AAaxE,mGAAmG;AACnG,oDAAoD;AACpD,iDAA6J;AAApJ,4HAAA,2BAA2B,OAAA;AAAE,sHAAA,qBAAqB,OAAA;AAAE,iHAAA,gBAAgB,OAAA;AAAE,oHAAA,mBAAmB,OAAA;AAAE,8GAAA,aAAa,OAAA;AAAE,iHAAA,gBAAgB,OAAA"}
|
package/dist/scp/makesql/tx.d.ts
CHANGED
|
@@ -1,42 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* litedbmodel v2 SCP — write
|
|
3
|
-
* the
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* bc Expression IR refs resolved at execute time against the accumulated transaction scope.
|
|
2
|
+
* litedbmodel v2 SCP — the write descriptor → makeSQL statement compiler ({@link compileWriteNode}),
|
|
3
|
+
* the BATCH transaction-plan derivation ({@link deriveBatchPlan}), and the live async 1-tx runtime
|
|
4
|
+
* ({@link executeTransactionAsync}). No reduced IR is emitted anywhere: every statement's SQL is
|
|
5
|
+
* COMPLETE tuned text (byte-identical to what the v1 write path sends — `INSERT … ON CONFLICT DO
|
|
6
|
+
* NOTHING`, `UPDATE … SET c = ?`, `DELETE FROM … WHERE …`), and its `params` are closed-set bc
|
|
7
|
+
* Expression IR refs resolved at execute time against the transaction scope.
|
|
9
8
|
*
|
|
10
9
|
* A statement op is exactly a `makeSQL` template: `{ sql, params }` where `sql` carries `?`
|
|
11
10
|
* placeholders and `params` are Expression IR (`{ref:[…]}` / a literal / a `{obj:{…}}` payload)
|
|
12
11
|
* that bc evaluates per statement — then the concrete values assemble + render + bind through
|
|
13
12
|
* the SAME `assembleMakeSQL` / `renderPlaceholders` the read path uses.
|
|
14
13
|
*
|
|
15
|
-
*
|
|
14
|
+
* A BATCH write (createMany / updateMany / deleteMany) is ONE logical op that produces N grouped
|
|
15
|
+
* statements; {@link deriveBatchPlan} lowers those into a gate-free {@link TransactionPlan}
|
|
16
|
+
* (`entityFrom` null, every statement `role:'body'`), run in the declared order as ONE transaction.
|
|
17
|
+
* The single-row and read paths are lowered by `bc generate` into a native module per language and
|
|
18
|
+
* never reach this runtime; there is no runtime read-compile and no runtime single-write compile.
|
|
16
19
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* ## Path lowering (spec §6) — `$.input.*` / `$.entity.*` / `$.ref.<w>.*` → closed-set refs
|
|
21
|
-
*
|
|
22
|
-
* `$.input.<f>` → `{ref:['<f>']}` (bc flat input scope)
|
|
23
|
-
* `$.entity.<f>` → `{ref:['__entity','<f>']}` (the sole body write's RETURNING row)
|
|
24
|
-
* `$.ref.<w>.<f>` → `{ref:['<w>','<f>']}` (a named upstream write's RETURNING row)
|
|
25
|
-
*
|
|
26
|
-
* ## tx-DAG derivation (spec §6 / §14) — gate-first + data-dependency topo order
|
|
27
|
-
*
|
|
28
|
-
* Statements form a data-dependency DAG (`$.ref.<w>.*` consumes an earlier write's RETURNING
|
|
29
|
-
* row via `TxStatement.binds`) with a gate-first constraint. A deterministic Kahn topo sort
|
|
30
|
-
* (stable ascending declaration `seq` tie-break) orders them into a single-transaction plan.
|
|
31
|
-
* Underivable shapes (cycle, dangling `$.ref`, referenced write without RETURNING, duplicate
|
|
32
|
-
* bind, composite `$.entity`) are LOUD rejects — never a silently mis-ordered plan.
|
|
20
|
+
* Every statement executes: a plan either commits or raises. There is no gate that inspects a
|
|
21
|
+
* statement's result and short-circuits the rest — no plan in this repository ever carried one, so
|
|
22
|
+
* the interpretation was removed rather than kept as a path nothing reaches (#256).
|
|
33
23
|
*/
|
|
34
24
|
import { type Scope } from 'behavior-contracts/runtime';
|
|
35
25
|
import { type ColumnTypeResolver } from '../coltype';
|
|
36
26
|
import { type Dialect as MakeSQLDialect } from './handler';
|
|
37
|
-
import { type
|
|
27
|
+
import { type PooledAsyncContext } from '../exec-context';
|
|
38
28
|
import { type TransactionOptions } from '../tx-options';
|
|
39
|
-
import { type LifecycleContract, type LifecycleEffects, type WriteLifecyclePhase } from '../writes';
|
|
40
29
|
/** A closed-set bc Expression IR node used as a `makeSQL` deferred param (ref / literal / obj). */
|
|
41
30
|
export type TxExpr = unknown;
|
|
42
31
|
/**
|
|
@@ -106,10 +95,19 @@ export interface TxOp {
|
|
|
106
95
|
readonly batch?: boolean;
|
|
107
96
|
};
|
|
108
97
|
}
|
|
109
|
-
/** The role a transaction statement plays (drives the runtime's
|
|
110
|
-
export type StatementRole = '
|
|
111
|
-
/**
|
|
112
|
-
|
|
98
|
+
/** The role a transaction statement plays (drives the runtime's §6 derivation order). */
|
|
99
|
+
export type StatementRole = 'body' | 'derive' | 'edge' | 'emit';
|
|
100
|
+
/**
|
|
101
|
+
* The write intent a {@link TransactionPlan} carries. It labels the plan the BATCH compilers derive
|
|
102
|
+
* (`createMany` ⇒ `create`, `updateMany` ⇒ `update`, `deleteMany` ⇒ `remove`) so a consumer can tell
|
|
103
|
+
* the three apart without re-reading the SQL.
|
|
104
|
+
*/
|
|
105
|
+
export type WriteLifecyclePhase = 'create' | 'update' | 'remove';
|
|
106
|
+
/**
|
|
107
|
+
* The reserved scope key the tx runtime binds the plan's `entityFrom` row under, so a later statement
|
|
108
|
+
* that references the written row resolves against it. Reserved: no input field may use this name.
|
|
109
|
+
*/
|
|
110
|
+
export declare const ENTITY_ROOT = "__entity";
|
|
113
111
|
/** One ordered statement of a transaction plan (pure JSON — a makeSQL template + its role). */
|
|
114
112
|
export interface TxStatement {
|
|
115
113
|
/** Stable statement id (ordering key + diagnostics). */
|
|
@@ -118,23 +116,28 @@ export interface TxStatement {
|
|
|
118
116
|
readonly role: StatementRole;
|
|
119
117
|
/** The compiled makeSQL op (complete `sql` + deferred Expression-IR `params`). */
|
|
120
118
|
readonly op: TxOp;
|
|
121
|
-
/** For a gate statement: the short-circuit rule. Absent for body/derive/edge/emit. */
|
|
122
|
-
readonly gate?: GateRule;
|
|
123
119
|
/** For a composite body statement: the name under which this RETURNING row is exposed. */
|
|
124
120
|
readonly binds?: string;
|
|
125
121
|
/** Human label (diagnostics; e.g. `requires users`, `derive users.post_count`). */
|
|
126
122
|
readonly label: string;
|
|
127
123
|
}
|
|
128
|
-
/**
|
|
129
|
-
export type IdempotentHitPolicy = 'rollback';
|
|
130
|
-
/** A derived write-time-relations transaction plan (pure JSON — ordered gate-first statements). */
|
|
124
|
+
/** A derived write-time-relations transaction plan (pure JSON — ordered statements). */
|
|
131
125
|
export interface TransactionPlan {
|
|
132
126
|
readonly phase: WriteLifecyclePhase;
|
|
133
127
|
readonly entityFrom: string | null;
|
|
134
128
|
readonly statements: readonly TxStatement[];
|
|
135
|
-
readonly onIdempotentHit: IdempotentHitPolicy;
|
|
136
129
|
}
|
|
137
|
-
/**
|
|
130
|
+
/**
|
|
131
|
+
* Is this plan a BATCH (createMany / updateMany / deleteMany) rather than a single/composite Command?
|
|
132
|
+
* A batch is ref-free: nothing exposes a row for a later statement to read, so `entityFrom` is null and
|
|
133
|
+
* every statement is a plain `body` with no `binds`.
|
|
134
|
+
*
|
|
135
|
+
* It decides two things that MUST agree, which is why it is ONE function and not a test each side
|
|
136
|
+
* spells for itself: the runtime accumulates `returnedRows` only for a batch, and the codegen out-type
|
|
137
|
+
* ({@link ./writeouttype}) includes the `returnedRows` field only for a batch. Two spellings that drift
|
|
138
|
+
* would type a field the runtime does not fill, or drop one it does (#259).
|
|
139
|
+
*/
|
|
140
|
+
export declare function isBatchPlan(plan: TransactionPlan): boolean;
|
|
138
141
|
export declare const IN_SENTINEL = "@in";
|
|
139
142
|
type WriteComponent = 'Insert' | 'Update' | 'Delete' | 'Select';
|
|
140
143
|
interface WriteNodeLike {
|
|
@@ -171,22 +174,6 @@ export declare function pkPort(ports: Record<string, unknown>): {
|
|
|
171
174
|
* are CANONICAL (alphabetical) sorted — the v2 write-path SSoT (matches `DBModel._insert`).
|
|
172
175
|
*/
|
|
173
176
|
export declare function compileWriteNode(node: WriteNodeLike, dialect?: MakeSQLDialect, resolveColumnType?: ColumnTypeResolver): TxOp;
|
|
174
|
-
/** The base write op the Command declares (`Insert`/`Update`/`Delete` with `onWrite`). */
|
|
175
|
-
export interface BaseWrite {
|
|
176
|
-
/** The compiled base write makeSQL op (complete `sql` + deferred Expression-IR `params`). */
|
|
177
|
-
readonly op: TxOp;
|
|
178
|
-
readonly label: string;
|
|
179
|
-
/** The write's stable NAME (composite scope) — referenced downstream as `$.ref.<name>.*`. */
|
|
180
|
-
readonly name?: string;
|
|
181
|
-
/** The write's OWN save-contract effects (composite scope). */
|
|
182
|
-
readonly effects?: LifecycleEffects;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Derive the ORDERED, gate-first {@link TransactionPlan} from a Command's base write(s) + its
|
|
186
|
-
* lifecycle save contract (spec §6 / §14). Single base write = fixed §6 group; multiple named
|
|
187
|
-
* base writes = a topologically-ordered gate-first tx DAG (`$.ref.<name>.*` data dependencies).
|
|
188
|
-
*/
|
|
189
|
-
export declare function deriveTransactionPlan(phase: WriteLifecyclePhase, bases: readonly BaseWrite[], lifecycle: LifecycleContract, dialect?: MakeSQLDialect): TransactionPlan;
|
|
190
177
|
/**
|
|
191
178
|
* Lower a list of CONCRETE batch-write ops (createMany / updateMany / deleteMany — each already
|
|
192
179
|
* compiled by driving the v1 builders in `compile-crud`, so its `sql` is byte-identical to v1 and
|
|
@@ -205,53 +192,20 @@ export declare function deriveBatchPlan(phase: WriteLifecyclePhase, ops: readonl
|
|
|
205
192
|
params: readonly unknown[];
|
|
206
193
|
label?: string;
|
|
207
194
|
}[]): TransactionPlan;
|
|
208
|
-
/**
|
|
209
|
-
* The minimal synchronous SQLite driver surface the tx runtime needs (better-sqlite3) — the
|
|
210
|
-
* backward-compat public seam. Internally the tx runs through the {@link ExecutionContext} seam
|
|
211
|
-
* (`../exec-context`); a raw driver passed here is wrapped via {@link contextForDriver}. Aliased to
|
|
212
|
-
* {@link SqliteDriver}.
|
|
213
|
-
*/
|
|
214
|
-
export type SqliteDb = SqliteDriver;
|
|
215
|
-
/** A tx entry accepts either a raw {@link SqliteDb} or a full {@link ExecutionContext}. */
|
|
216
|
-
export type DbOrContext = SqliteDb | ExecutionContext;
|
|
217
|
-
/** Why a transaction did not commit (a gate short-circuit outcome; not a driver error). */
|
|
218
|
-
export type ShortCircuitReason = 'requires_absent' | 'unique_collision' | 'idempotent_duplicate';
|
|
219
195
|
/** The structured outcome of executing a {@link TransactionPlan}. */
|
|
220
196
|
export interface TransactionResult {
|
|
221
197
|
readonly committed: boolean;
|
|
222
|
-
readonly shortCircuit?: {
|
|
223
|
-
readonly statementId: string;
|
|
224
|
-
readonly reason: ShortCircuitReason;
|
|
225
|
-
};
|
|
226
198
|
readonly entity: Record<string, unknown> | null;
|
|
227
199
|
readonly executed: readonly string[];
|
|
228
200
|
/**
|
|
229
201
|
* For a BATCH write (createMany/updateMany/deleteMany — a gate-free plan with `entityFrom:null`):
|
|
230
202
|
* the RETURNING rows of every body statement, ordered by statement. Present ONLY when a body
|
|
231
|
-
* statement RETURNED rows and the plan has no `$.entity` (batch mode); absent for a
|
|
203
|
+
* statement RETURNED rows and the plan has no `$.entity` (batch mode); absent for a
|
|
232
204
|
* single/composite Command (which exposes its written row via `entity`). This carries v1
|
|
233
205
|
* `createMany`'s "all created rows" result across the multi-statement batch.
|
|
234
206
|
*/
|
|
235
207
|
readonly returnedRows?: readonly (readonly Record<string, unknown>[])[];
|
|
236
208
|
}
|
|
237
|
-
/**
|
|
238
|
-
* Execute a derived {@link TransactionPlan} as ONE real SQLite transaction with gate-first
|
|
239
|
-
* short-circuit. Accepts a raw {@link SqliteDb} (wrapped via {@link contextForDriver}) or a full
|
|
240
|
-
* {@link ExecutionContext}. The transaction derives a tx-scoped ctx (`withConnection(conn, true)`)
|
|
241
|
-
* that PINS one connection so BEGIN, every body statement, and COMMIT/ROLLBACK all run on the SAME
|
|
242
|
-
* connection (§3, per-execution ownership). For the single-DB SQLite driver the pinned connection
|
|
243
|
-
* is the sole connection; the ownership shows its teeth on the pooled async path
|
|
244
|
-
* ({@link import('../exec-context').withTransactionAsync}), which this mirrors.
|
|
245
|
-
*/
|
|
246
|
-
export declare function executeTransaction(db: DbOrContext, plan: TransactionPlan, input: Scope, dialect?: MakeSQLDialect): TransactionResult;
|
|
247
|
-
/**
|
|
248
|
-
* A counting {@link SqliteDb} wrapper: forwards every call to the wrapped driver but records
|
|
249
|
-
* each PREPARED SQL string. Tests use it to PROVE gate-first short-circuit.
|
|
250
|
-
*/
|
|
251
|
-
export declare function countingDriver(db: SqliteDb): {
|
|
252
|
-
db: SqliteDb;
|
|
253
|
-
prepared: string[];
|
|
254
|
-
};
|
|
255
209
|
/** Render one statement op to its dialect SQL text + params (exposed for golden tests). */
|
|
256
210
|
export declare function renderTxStatement(op: TxOp, scope: Scope, dialect?: MakeSQLDialect): {
|
|
257
211
|
sql: string;
|
|
@@ -273,8 +227,8 @@ export interface WriteExecOptions extends TransactionOptions {
|
|
|
273
227
|
readonly guard?: boolean;
|
|
274
228
|
}
|
|
275
229
|
/**
|
|
276
|
-
* Execute a derived {@link TransactionPlan} on a live PG / MySQL connection with
|
|
277
|
-
*
|
|
230
|
+
* Execute a derived {@link TransactionPlan} on a live PG / MySQL connection with **per-execution
|
|
231
|
+
* connection ownership** (§3). The live-DB WRITE entry (#86).
|
|
278
232
|
*
|
|
279
233
|
* ## Ambient-tx JOIN vs. its own envelope (the #86 core)
|
|
280
234
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tx.d.ts","sourceRoot":"","sources":["../../../src/scp/makesql/tx.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"tx.d.ts","sourceRoot":"","sources":["../../../src/scp/makesql/tx.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAsB,KAAK,KAAK,EAAc,MAAM,4BAA4B,CAAC;AAKxF,OAAO,EAAgD,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACnG,OAAO,EAAsB,KAAK,OAAO,IAAI,cAAc,EAAE,MAAM,WAAW,CAAC;AAM/E,OAAO,EAEL,KAAK,kBAAkB,EAExB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,KAAK,kBAAkB,EAAqB,MAAM,eAAe,CAAC;AAM3E,mGAAmG;AACnG,MAAM,MAAM,MAAM,GAAG,OAAO,CAAC;AAE7B;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAkBjD;AAED;;;;;;GAMG;AACH,MAAM,WAAW,IAAI;IACnB,kDAAkD;IAClD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,yFAAyF;IACzF,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;QAAC,QAAQ,CAAC,O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