@prisma/orm-family-sql 8.0.0-rc.24-dev.27 → 8.0.0-rc.24-dev.29
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/{aggregate-descriptor-registry-DM1hmlq-.mjs → aggregate-descriptor-registry-oSsBuRHQ.mjs} +2 -2
- package/dist/{aggregate-descriptor-registry-DM1hmlq-.mjs.map → aggregate-descriptor-registry-oSsBuRHQ.mjs.map} +1 -1
- package/dist/{ast-BO3Wgbrl.mjs → ast-BpFfUmb_.mjs} +2 -2
- package/dist/{ast-BO3Wgbrl.mjs.map → ast-BpFfUmb_.mjs.map} +1 -1
- package/dist/{ast-D0yJ7Yf0.d.mts → ast-DvD53wSW.d.mts} +3 -3
- package/dist/{ast-D0yJ7Yf0.d.mts.map → ast-DvD53wSW.d.mts.map} +1 -1
- package/dist/{attribute-specs-DL1btx0j.d.mts → attribute-specs-DgYb4op9.d.mts} +3 -3
- package/dist/{attribute-specs-DL1btx0j.d.mts.map → attribute-specs-DgYb4op9.d.mts.map} +1 -1
- package/dist/{authoring-entity-types-CgKIgWq5-BqNs-56x.d.mts → authoring-entity-types-CgKIgWq5-C3GyB8Hj.d.mts} +2 -2
- package/dist/{authoring-entity-types-CgKIgWq5-BqNs-56x.d.mts.map → authoring-entity-types-CgKIgWq5-C3GyB8Hj.d.mts.map} +1 -1
- package/dist/builder.d.mts +3 -3
- package/dist/builder__runtime.d.mts +7 -7
- package/dist/builder__runtime.mjs +26 -12
- package/dist/builder__runtime.mjs.map +1 -1
- package/dist/builder__types.d.mts +5 -5
- package/dist/{collection-methods-CN0GIWWR-BSJvP4Kc.d.mts → collection-methods-As4pXm7B-3xgTSoyU.d.mts} +3 -3
- package/dist/{collection-methods-CN0GIWWR-BSJvP4Kc.d.mts.map → collection-methods-As4pXm7B-3xgTSoyU.d.mts.map} +1 -1
- package/dist/collection-methods-CS1e16Ij.d.mts +1 -0
- package/dist/config-types-BVrGV95W.mjs +147 -0
- package/dist/config-types-BVrGV95W.mjs.map +1 -0
- package/dist/{config-types-Ce1tAJ0B.d.mts → config-types-DVRid5jV.d.mts} +15 -3
- package/dist/config-types-DVRid5jV.d.mts.map +1 -0
- package/dist/{contract-builder-BfPC4mQK.d.mts → contract-builder-fyzIdWqX.d.mts} +77 -2
- package/dist/{contract-builder-BfPC4mQK.d.mts.map → contract-builder-fyzIdWqX.d.mts.map} +1 -1
- package/dist/{contract-builder-Dbo5LeXs.mjs → contract-builder-q2-4IVcW.mjs} +3 -3
- package/dist/contract-builder-q2-4IVcW.mjs.map +1 -0
- package/dist/contract-emitter.d.mts +3 -2
- package/dist/contract-emitter.d.mts.map +1 -1
- package/dist/contract-emitter.mjs +1 -1
- package/dist/contract-prisma7__provider.mjs +6 -6
- package/dist/contract-psl.d.mts +1 -1
- package/dist/contract-psl.mjs +1 -1
- package/dist/contract-psl__attribute-specs.d.mts +1 -1
- package/dist/contract-psl__attribute-specs.mjs +1 -1
- package/dist/contract-psl__provider.mjs +22 -19
- package/dist/contract-psl__provider.mjs.map +1 -1
- package/dist/contract-ts.d.mts +3 -3
- package/dist/contract-ts.mjs +4 -4
- package/dist/contract-ts__config-types.d.mts +2 -2
- package/dist/contract-ts__config-types.mjs +2 -2
- package/dist/contract-ts__contract-builder.d.mts +2 -2
- package/dist/contract-ts__contract-builder.mjs +3 -3
- package/dist/contract.d.mts +2 -2
- package/dist/contract.mjs +4 -4
- package/dist/contract__foreign-key-materialization.d.mts +2 -2
- package/dist/contract__foreign-key-materialization.mjs +3 -3
- package/dist/contract__validators.mjs +1 -1
- package/dist/{control-Cb6YoQ8j.d.mts → control-L4h4N5uy.d.mts} +158 -42
- package/dist/control-L4h4N5uy.d.mts.map +1 -0
- package/dist/{control-kHFMtE8A.mjs → control-Mh99W3HI.mjs} +2117 -1315
- package/dist/control-Mh99W3HI.mjs.map +1 -0
- package/dist/{control-adapter-0z3ce44U-CLj4kqLI.d.mts → control-adapter-0z3ce44U-BQ26ercw.d.mts} +4 -4
- package/dist/{control-adapter-0z3ce44U-CLj4kqLI.d.mts.map → control-adapter-0z3ce44U-BQ26ercw.d.mts.map} +1 -1
- package/dist/{control-adapter-DIwBUSs6.d.mts → control-adapter-DRLco_j0.d.mts} +2 -2
- package/dist/{control-adapter-DIwBUSs6.d.mts.map → control-adapter-DRLco_j0.d.mts.map} +1 -1
- package/dist/{db-DfYeGVcu-B99ycjaC.d.mts → db-by-MuHF2-B7uz_0VW.d.mts} +27 -18
- package/dist/db-by-MuHF2-B7uz_0VW.d.mts.map +1 -0
- package/dist/{ddl-types-D22OYeFy-Be5-W-5z.d.mts → ddl-types-D93zTpm9-DhSkpX0K.d.mts} +3 -3
- package/dist/{ddl-types-D22OYeFy-Be5-W-5z.d.mts.map → ddl-types-D93zTpm9-DhSkpX0K.d.mts.map} +1 -1
- package/dist/{derived-checks-BWg0DOyz-7O0x1Tgn.mjs → derived-checks-BoHNzt-a-CK4ceMbs.mjs} +228 -10
- package/dist/derived-checks-BoHNzt-a-CK4ceMbs.mjs.map +1 -0
- package/dist/{diff-DbkXUf4C.d.mts → diff-DZHlisyY.d.mts} +2 -2
- package/dist/{diff-DbkXUf4C.d.mts.map → diff-DZHlisyY.d.mts.map} +1 -1
- package/dist/{dist-BJjqJT_M.mjs → dist-C-Gi4VUC.mjs} +20 -14
- package/dist/dist-C-Gi4VUC.mjs.map +1 -0
- package/dist/{exports-BR5ctYYI-C_-aedbr.mjs → exports-kqOXg2OT-D3lo7jnX.mjs} +168 -162
- package/dist/exports-kqOXg2OT-D3lo7jnX.mjs.map +1 -0
- package/dist/expression-Bz8uEh8W.d.mts +2 -0
- package/dist/{expression-D8c3t2Dx-CCHt1OdT.d.mts → expression-DYRYmkMl-BMKxN8Wf.d.mts} +64 -43
- package/dist/expression-DYRYmkMl-BMKxN8Wf.d.mts.map +1 -0
- package/dist/{expression-DL7L8You-C9BAeM2d.d.mts → expression-VJWwxbUB-BtNDaTCt.d.mts} +5 -5
- package/dist/expression-VJWwxbUB-BtNDaTCt.d.mts.map +1 -0
- package/dist/{expression-impl-DHdjzqE3-Cd9gP7oC.mjs → expression-impl-C5Ha-fXs-CxXn8gDo.mjs} +7 -5
- package/dist/expression-impl-C5Ha-fXs-CxXn8gDo.mjs.map +1 -0
- package/dist/family.d.mts +8 -8
- package/dist/family.mjs +6 -6
- package/dist/family__control-adapter.d.mts +2 -2
- package/dist/family__control.d.mts +3 -3
- package/dist/family__control.mjs +3 -3
- package/dist/family__diff.d.mts +1 -1
- package/dist/family__ir.mjs +1 -1
- package/dist/family__migration.d.mts +1 -1
- package/dist/family__pack.d.mts +1 -1
- package/dist/family__pack.mjs +2 -2
- package/dist/family__psl-infer.mjs +1 -1
- package/dist/{foreign-key-materialization-C53nVQuD.d.mts → foreign-key-materialization-Dntzsl64.d.mts} +8 -2
- package/dist/foreign-key-materialization-Dntzsl64.d.mts.map +1 -0
- package/dist/{foreign-key-materialization-CCHAR789.mjs → foreign-key-materialization-pYirysH0.mjs} +2 -2
- package/dist/foreign-key-materialization-pYirysH0.mjs.map +1 -0
- package/dist/{functions-Cl_egJ2w.mjs → functions-DGketpiK.mjs} +3 -3
- package/dist/{functions-Cl_egJ2w.mjs.map → functions-DGketpiK.mjs.map} +1 -1
- package/dist/functions-gl3PL1so.d.mts +1 -0
- package/dist/{generator-functions-Bze9nVHL-Cetbgui3.mjs → generator-functions-Bze9nVHL-q4YmMS5B.mjs} +3 -3
- package/dist/{generator-functions-Bze9nVHL-Cetbgui3.mjs.map → generator-functions-Bze9nVHL-q4YmMS5B.mjs.map} +1 -1
- package/dist/{index-equivalence-DswCiq5l-9GNm8oG9.mjs → index-equivalence-eC2jGpOp-SkExsiy1.mjs} +3 -3
- package/dist/{index-equivalence-DswCiq5l-9GNm8oG9.mjs.map → index-equivalence-eC2jGpOp-SkExsiy1.mjs.map} +1 -1
- package/dist/{index-DA1EEz4y.d.mts → index-nW0rAUTr.d.mts} +28 -30
- package/dist/index-nW0rAUTr.d.mts.map +1 -0
- package/dist/{index-reference-CSrhOgZL-PIYy9LTA.d.mts → index-reference-CjvRzUh1-CG0Ouv6i.d.mts} +3 -3
- package/dist/{index-reference-CSrhOgZL-PIYy9LTA.d.mts.map → index-reference-CjvRzUh1-CG0Ouv6i.d.mts.map} +1 -1
- package/dist/index-reference-X_kA2mV8.d.mts +1 -0
- package/dist/{interpreter-CVd521dx-wWck8W93.mjs → interpreter-DoQwVOyS-DXYLj31g.mjs} +209 -29
- package/dist/interpreter-DoQwVOyS-DXYLj31g.mjs.map +1 -0
- package/dist/middleware-CcDThETr.d.mts +1 -0
- package/dist/{middleware-4P5tDL8a-C1UaoUUN.d.mts → middleware-DzFPUERE-C6RrGmcp.d.mts} +3 -3
- package/dist/{middleware-4P5tDL8a-C1UaoUUN.d.mts.map → middleware-DzFPUERE-C6RrGmcp.d.mts.map} +1 -1
- package/dist/{migration-DctFInNJ.d.mts → migration-BUWF9_Tx.d.mts} +2 -2
- package/dist/{migration-DctFInNJ.d.mts.map → migration-BUWF9_Tx.d.mts.map} +1 -1
- package/dist/orm-client.d.mts +113 -69
- package/dist/orm-client.d.mts.map +1 -1
- package/dist/orm-client.mjs +391 -121
- package/dist/orm-client.mjs.map +1 -1
- package/dist/{pack-BBsFyTEv.d.mts → pack-CbYm5Bfz.d.mts} +3 -3
- package/dist/{pack-BBsFyTEv.d.mts.map → pack-CbYm5Bfz.d.mts.map} +1 -1
- package/dist/plan-BjX90QC6.d.mts +2 -0
- package/dist/{plan-49sl7WSN-C22ZPSE9.d.mts → plan-Dv6v5_y4-CGWEjfCv.d.mts} +3 -3
- package/dist/{plan-49sl7WSN-C22ZPSE9.d.mts.map → plan-Dv6v5_y4-CGWEjfCv.d.mts.map} +1 -1
- package/dist/{psl-column-resolution-Bv_-TDHZ-Cuu5X_9o.d.mts → psl-column-resolution-Bv_-TDHZ-C9foRNXV.d.mts} +2 -2
- package/dist/{psl-column-resolution-Bv_-TDHZ-Cuu5X_9o.d.mts.map → psl-column-resolution-Bv_-TDHZ-C9foRNXV.d.mts.map} +1 -1
- package/dist/{psl-field-resolution-GN4iup8d-DjlZymdL.mjs → psl-field-resolution-CpxUePg1-COJnJkDs.mjs} +9 -5
- package/dist/psl-field-resolution-CpxUePg1-COJnJkDs.mjs.map +1 -0
- package/dist/{psl-infer-C9kVS9ma.mjs → psl-infer-Ckg3t4Kr.mjs} +2 -2
- package/dist/{psl-infer-C9kVS9ma.mjs.map → psl-infer-Ckg3t4Kr.mjs.map} +1 -1
- package/dist/{query-lane-context-DIJU7Owj-CAZQq4AD.d.mts → query-lane-context-BetHj4j--D3S5nucp.d.mts} +5 -5
- package/dist/{query-lane-context-DIJU7Owj-CAZQq4AD.d.mts.map → query-lane-context-BetHj4j--D3S5nucp.d.mts.map} +1 -1
- package/dist/query-lane-context-DgxWaKr-.d.mts +1 -0
- package/dist/relational-core.d.mts +13 -13
- package/dist/relational-core.mjs +3 -3
- package/dist/relational-core__aggregate-descriptor-registry.d.mts +1 -1
- package/dist/relational-core__aggregate-descriptor-registry.mjs +1 -1
- package/dist/relational-core__ast.d.mts +3 -3
- package/dist/relational-core__ast.mjs +2 -2
- package/dist/relational-core__codec-descriptor-registry.d.mts +2 -2
- package/dist/relational-core__collection-methods.d.mts +2 -2
- package/dist/relational-core__contract-free.d.mts +2 -2
- package/dist/relational-core__contract-free.mjs +1 -1
- package/dist/relational-core__contract-free.mjs.map +1 -1
- package/dist/relational-core__expression.d.mts +4 -4
- package/dist/relational-core__expression.mjs +1 -1
- package/dist/relational-core__functions.d.mts +2 -2
- package/dist/relational-core__functions.mjs +1 -1
- package/dist/relational-core__index-reference.d.mts +2 -2
- package/dist/relational-core__middleware.d.mts +2 -2
- package/dist/relational-core__plan.d.mts +3 -3
- package/dist/relational-core__query-lane-context.d.mts +2 -2
- package/dist/relational-core__types.d.mts +2 -2
- package/dist/runtime.d.mts +4 -4
- package/dist/runtime.mjs +1 -1
- package/dist/runtime__internal__prepared-query.d.mts +1 -1
- package/dist/{sql-contract-serializer-sMY3prTx-D_K7uFJk.mjs → sql-contract-serializer-sMY3prTx-CIDal1t1.mjs} +2 -2
- package/dist/{sql-contract-serializer-sMY3prTx-D_K7uFJk.mjs.map → sql-contract-serializer-sMY3prTx-CIDal1t1.mjs.map} +1 -1
- package/dist/{sql-execution-plan-BeuM3CeD-DIzyMDsA.d.mts → sql-execution-plan-4OFBeONp-CLkDqMdz.d.mts} +3 -3
- package/dist/sql-execution-plan-4OFBeONp-CLkDqMdz.d.mts.map +1 -0
- package/dist/{transaction-state-CEe4TlC1-C8vX6Ror.d.mts → transaction-state-B4FVsvO7-DpvKYHSB.d.mts} +12 -10
- package/dist/{transaction-state-CEe4TlC1-C8vX6Ror.d.mts.map → transaction-state-B4FVsvO7-DpvKYHSB.d.mts.map} +1 -1
- package/dist/types-BFCrGkhG.d.mts +1 -0
- package/dist/{types-C6r7Myrr-3WL0WDKF.d.mts → types-CGr02DOy-CQsUdKCe.d.mts} +6 -6
- package/dist/{types-C6r7Myrr-3WL0WDKF.d.mts.map → types-CGr02DOy-CQsUdKCe.d.mts.map} +1 -1
- package/dist/{types-CWvmfrfd-DLQYhSUx.d.mts → types-CWvmfrfd-HPIh55bi.d.mts} +2 -2
- package/dist/{types-CWvmfrfd-DLQYhSUx.d.mts.map → types-CWvmfrfd-HPIh55bi.d.mts.map} +1 -1
- package/dist/{types-DeimCJiI-CVQS7KCu.d.mts → types-DEbNJhyS-CY7Ye2vN.d.mts} +5 -5
- package/dist/{types-DeimCJiI-CVQS7KCu.d.mts.map → types-DEbNJhyS-CY7Ye2vN.d.mts.map} +1 -1
- package/dist/{types-wn1bXh0b-CJPAJi22.mjs → types-DzQmUrUm-ColHE4Av.mjs} +18 -5
- package/dist/types-DzQmUrUm-ColHE4Av.mjs.map +1 -0
- package/dist/{validators-CWcdf_jZ.mjs → validators-DbCIebZb.mjs} +2 -2
- package/dist/{validators-CWcdf_jZ.mjs.map → validators-DbCIebZb.mjs.map} +1 -1
- package/package.json +18 -18
- package/dist/collection-methods-B-md3Mu9.d.mts +0 -1
- package/dist/config-types-BVAADwjp.mjs +0 -68
- package/dist/config-types-BVAADwjp.mjs.map +0 -1
- package/dist/config-types-Ce1tAJ0B.d.mts.map +0 -1
- package/dist/contract-builder-Dbo5LeXs.mjs.map +0 -1
- package/dist/control-Cb6YoQ8j.d.mts.map +0 -1
- package/dist/control-kHFMtE8A.mjs.map +0 -1
- package/dist/db-DfYeGVcu-B99ycjaC.d.mts.map +0 -1
- package/dist/derived-checks-BWg0DOyz-7O0x1Tgn.mjs.map +0 -1
- package/dist/dist-BJjqJT_M.mjs.map +0 -1
- package/dist/exports-BR5ctYYI-C_-aedbr.mjs.map +0 -1
- package/dist/expression-D8c3t2Dx-CCHt1OdT.d.mts.map +0 -1
- package/dist/expression-DL7L8You-C9BAeM2d.d.mts.map +0 -1
- package/dist/expression-Voyb-zN0.d.mts +0 -2
- package/dist/expression-impl-DHdjzqE3-Cd9gP7oC.mjs.map +0 -1
- package/dist/foreign-key-materialization-C53nVQuD.d.mts.map +0 -1
- package/dist/foreign-key-materialization-CCHAR789.mjs.map +0 -1
- package/dist/functions-zPzQYOjW.d.mts +0 -1
- package/dist/index-DA1EEz4y.d.mts.map +0 -1
- package/dist/index-reference-DuQ-0Da9.d.mts +0 -1
- package/dist/interpreter-CVd521dx-wWck8W93.mjs.map +0 -1
- package/dist/middleware-DDOdMwm4.d.mts +0 -1
- package/dist/plan-BEnXVtn1.d.mts +0 -2
- package/dist/psl-field-resolution-GN4iup8d-DjlZymdL.mjs.map +0 -1
- package/dist/query-lane-context-Dm5f9VAQ.d.mts +0 -1
- package/dist/sql-execution-plan-BeuM3CeD-DIzyMDsA.d.mts.map +0 -1
- package/dist/types-ChjF67Fc.d.mts +0 -1
- package/dist/types-wn1bXh0b-CJPAJi22.mjs.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as createSqlOperationRegistry } from "./dist-CHz1hF8M.mjs";
|
|
2
|
-
import { j as PreparedParamRef, q as isQueryAst } from "./types-
|
|
2
|
+
import { j as PreparedParamRef, q as isQueryAst } from "./types-DzQmUrUm-ColHE4Av.mjs";
|
|
3
3
|
import { t as collectOrderedParamRefs } from "./util-DixeJBri-Cad7x5ec.mjs";
|
|
4
4
|
import { t as createSqlParamRefMutator } from "./middleware-qY3R0WsS-8GWtk_Bf.mjs";
|
|
5
|
-
import { t as buildSqlAggregateDescriptorRegistry } from "./aggregate-descriptor-registry-
|
|
5
|
+
import { t as buildSqlAggregateDescriptorRegistry } from "./aggregate-descriptor-registry-oSsBuRHQ.mjs";
|
|
6
6
|
import { t as buildCodecDescriptorRegistry } from "./codec-descriptor-registry-UiFDvDj4.mjs";
|
|
7
7
|
import { a as runPreparedQuery, c as transactionStart, i as runPreparedExecute, l as wasRefusedBeforeBegin, n as preparedStatementExecute, o as settlementOf, r as preparedStatementQuery, s as transactionSettlement, t as createTransactionStart } from "./transaction-state-BfXhs7D7-DhmbySW9.mjs";
|
|
8
8
|
import { isStructuredError, structuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
@@ -18,7 +18,7 @@ import { checkContractComponentRequirements, mergeCapabilityMatrices } from "@pr
|
|
|
18
18
|
import { AsyncIterableResult, RuntimeCore, applyMutationDefaults, assertMutationDefaultGeneratorsAvailable, checkAborted, checkMiddlewareCompatibility, collectMutationDefaultGenerators, createContextBeneath, executeStatement, raceAgainstAbort, runtimeError as runtimeError$1, startClientActivity, startTransactionActivity, streamStatement } from "@prisma/orm-framework/components/runtime";
|
|
19
19
|
import { createExecutionStack } from "@prisma/orm-framework/components/execution";
|
|
20
20
|
import { hashContent } from "@prisma/orm-framework/utils/hash-content";
|
|
21
|
-
//#region ../../../2-sql-family/5-runtime/dist/exports-
|
|
21
|
+
//#region ../../../2-sql-family/5-runtime/dist/exports-kqOXg2OT.mjs
|
|
22
22
|
/** The symbol-keyed member through which a runtime, connection, transaction, `withTransaction` context or activity handle starts activities; user-facing types do not show it. */
|
|
23
23
|
const activitySource = Symbol("activitySource");
|
|
24
24
|
function hasActivitySourceMember(target) {
|
|
@@ -853,16 +853,19 @@ function rawQueryDecodeContext(ast, contractCodecs) {
|
|
|
853
853
|
if (ast.result.kind === "affected-count") return undecodedContext();
|
|
854
854
|
const aliases = [];
|
|
855
855
|
const codecs = /* @__PURE__ */ new Map();
|
|
856
|
+
const manyAliases = /* @__PURE__ */ new Set();
|
|
856
857
|
for (const [name, column] of Object.entries(ast.result.columns)) {
|
|
857
858
|
aliases.push(name);
|
|
858
|
-
|
|
859
|
+
const codec = column.codec ?? { codecId: column.codecId };
|
|
860
|
+
if (contractCodecs) codecs.set(name, contractCodecs.forCodecRef(codec));
|
|
861
|
+
if (codec.many) manyAliases.add(name);
|
|
859
862
|
}
|
|
860
863
|
return {
|
|
861
864
|
aliases,
|
|
862
865
|
codecs,
|
|
863
866
|
columnRefs: /* @__PURE__ */ new Map(),
|
|
864
867
|
includeAliases: EMPTY_INCLUDE_ALIASES,
|
|
865
|
-
manyAliases
|
|
868
|
+
manyAliases,
|
|
866
869
|
aliasSource: "row-spec"
|
|
867
870
|
};
|
|
868
871
|
}
|
|
@@ -1138,60 +1141,6 @@ async function runBeforeCompileChain(middleware, initial, ctx) {
|
|
|
1138
1141
|
}
|
|
1139
1142
|
return current;
|
|
1140
1143
|
}
|
|
1141
|
-
/**
|
|
1142
|
-
* Begins a transaction on a connection the transaction owns. The connection is released once the transaction has committed or rolled back, and destroyed after a failed rollback or a failed start other than a refusal before `BEGIN`. After a failed commit it stays held for the rollback that follows. A release that fails after the transaction settled is passed to `log.error`, and `commit()` or `rollback()` keeps its own outcome.
|
|
1143
|
-
*/
|
|
1144
|
-
async function beginOwnedTransaction(connection, begin, log) {
|
|
1145
|
-
let transaction;
|
|
1146
|
-
try {
|
|
1147
|
-
transaction = await begin();
|
|
1148
|
-
} catch (error) {
|
|
1149
|
-
if (wasRefusedBeforeBegin(connection)) await connection.release().catch(() => void 0);
|
|
1150
|
-
else await connection.destroy(error).catch(() => void 0);
|
|
1151
|
-
throw error;
|
|
1152
|
-
}
|
|
1153
|
-
let disposed = false;
|
|
1154
|
-
const dispose = async (destroyReason) => {
|
|
1155
|
-
if (disposed) return;
|
|
1156
|
-
disposed = true;
|
|
1157
|
-
if (destroyReason !== void 0) {
|
|
1158
|
-
await connection.destroy(destroyReason.reason).catch(() => void 0);
|
|
1159
|
-
return;
|
|
1160
|
-
}
|
|
1161
|
-
try {
|
|
1162
|
-
await connection.release();
|
|
1163
|
-
} catch (error) {
|
|
1164
|
-
try {
|
|
1165
|
-
log.error({
|
|
1166
|
-
event: "runtime.connection.release.error",
|
|
1167
|
-
error
|
|
1168
|
-
});
|
|
1169
|
-
} catch {}
|
|
1170
|
-
}
|
|
1171
|
-
};
|
|
1172
|
-
return Object.assign(castAs(Object.create(transaction)), {
|
|
1173
|
-
async commit() {
|
|
1174
|
-
try {
|
|
1175
|
-
await transaction.commit();
|
|
1176
|
-
} catch (error) {
|
|
1177
|
-
if (settlementOf(transaction)?.committed === true) await dispose();
|
|
1178
|
-
throw error;
|
|
1179
|
-
}
|
|
1180
|
-
await dispose();
|
|
1181
|
-
},
|
|
1182
|
-
async rollback() {
|
|
1183
|
-
try {
|
|
1184
|
-
await transaction.rollback();
|
|
1185
|
-
} catch (error) {
|
|
1186
|
-
const settlement = settlementOf(transaction);
|
|
1187
|
-
const settled = settlement?.rolledBack === true || settlement?.committed === true;
|
|
1188
|
-
await dispose(settled ? void 0 : { reason: error });
|
|
1189
|
-
throw error;
|
|
1190
|
-
}
|
|
1191
|
-
await dispose();
|
|
1192
|
-
}
|
|
1193
|
-
});
|
|
1194
|
-
}
|
|
1195
1144
|
function normalizeSpec(spec) {
|
|
1196
1145
|
if (typeof spec === "string") return {
|
|
1197
1146
|
codec: { codecId: spec },
|
|
@@ -1279,6 +1228,7 @@ var TransactionStack = class {
|
|
|
1279
1228
|
};
|
|
1280
1229
|
var TransactionBase = class {
|
|
1281
1230
|
[activitySource];
|
|
1231
|
+
[transactionSettlement];
|
|
1282
1232
|
runtime;
|
|
1283
1233
|
driverTx;
|
|
1284
1234
|
activity;
|
|
@@ -1303,6 +1253,23 @@ var TransactionBase = class {
|
|
|
1303
1253
|
startActivity: (clientActivity) => runtime.startActivity(this.route, clientActivity),
|
|
1304
1254
|
planContentHash: (plan) => runtime.planContentHash(plan, activity)
|
|
1305
1255
|
};
|
|
1256
|
+
const isClosed = () => this.isClosed;
|
|
1257
|
+
this[transactionSettlement] = {
|
|
1258
|
+
get closed() {
|
|
1259
|
+
return isClosed();
|
|
1260
|
+
},
|
|
1261
|
+
get committed() {
|
|
1262
|
+
return entry.state === "committed";
|
|
1263
|
+
},
|
|
1264
|
+
get rolledBack() {
|
|
1265
|
+
return entry.state === "rolled-back";
|
|
1266
|
+
},
|
|
1267
|
+
logDroppedError: (error) => this.logDroppedError(error),
|
|
1268
|
+
abandon: async () => {
|
|
1269
|
+
stack.invalidate();
|
|
1270
|
+
await this.rollback().catch(() => void 0);
|
|
1271
|
+
}
|
|
1272
|
+
};
|
|
1306
1273
|
}
|
|
1307
1274
|
query(plan, options) {
|
|
1308
1275
|
return this.route.query(plan, { ...options });
|
|
@@ -1350,10 +1317,17 @@ var TransactionBase = class {
|
|
|
1350
1317
|
this.runtime.markHeld(this.driverTx, driverSavepoint);
|
|
1351
1318
|
return new Savepoint(this.runtime, driverSavepoint, activity, this.stack, entry, this.rootTransaction);
|
|
1352
1319
|
}
|
|
1320
|
+
logDroppedError(error) {
|
|
1321
|
+
try {
|
|
1322
|
+
this.activity.ctx.log.error({
|
|
1323
|
+
event: "middleware.activityEnded.error",
|
|
1324
|
+
error
|
|
1325
|
+
});
|
|
1326
|
+
} catch {}
|
|
1327
|
+
}
|
|
1353
1328
|
};
|
|
1354
1329
|
var OuterTransaction = class extends TransactionBase {
|
|
1355
1330
|
signal;
|
|
1356
|
-
[transactionSettlement];
|
|
1357
1331
|
controller = new AbortController();
|
|
1358
1332
|
connection;
|
|
1359
1333
|
endTransactionWork;
|
|
@@ -1362,7 +1336,6 @@ var OuterTransaction = class extends TransactionBase {
|
|
|
1362
1336
|
closed = false;
|
|
1363
1337
|
timer;
|
|
1364
1338
|
commitAttempted = false;
|
|
1365
|
-
self = this;
|
|
1366
1339
|
constructor(runtime, connection, driverTx, activity, endTransactionWork, timeout) {
|
|
1367
1340
|
const entry = {
|
|
1368
1341
|
name: void 0,
|
|
@@ -1378,15 +1351,6 @@ var OuterTransaction = class extends TransactionBase {
|
|
|
1378
1351
|
this.deadline = performance.now() + (timeout ?? Number.POSITIVE_INFINITY);
|
|
1379
1352
|
this.connection = connection;
|
|
1380
1353
|
runtime.register(connection, this.openTransaction);
|
|
1381
|
-
this[transactionSettlement] = {
|
|
1382
|
-
get committed() {
|
|
1383
|
-
return entry.state === "committed";
|
|
1384
|
-
},
|
|
1385
|
-
get rolledBack() {
|
|
1386
|
-
return entry.state === "rolled-back";
|
|
1387
|
-
},
|
|
1388
|
-
logDroppedError: (error) => this.logDroppedError(error)
|
|
1389
|
-
};
|
|
1390
1354
|
if (timeout !== void 0) {
|
|
1391
1355
|
this.timer = setTimeout(() => this.expire(), timeout);
|
|
1392
1356
|
runtime.onConnectionReleased(connection, () => this.releaseConnection());
|
|
@@ -1396,7 +1360,7 @@ var OuterTransaction = class extends TransactionBase {
|
|
|
1396
1360
|
return this.closed || this.stack.invalidated;
|
|
1397
1361
|
}
|
|
1398
1362
|
get rootTransaction() {
|
|
1399
|
-
return this
|
|
1363
|
+
return this;
|
|
1400
1364
|
}
|
|
1401
1365
|
assertOpen() {
|
|
1402
1366
|
if (!this.closed && performance.now() >= this.deadline) this.expire();
|
|
@@ -1441,7 +1405,7 @@ var OuterTransaction = class extends TransactionBase {
|
|
|
1441
1405
|
this.stopAcceptingChildren();
|
|
1442
1406
|
if (this.entry.commitEnding !== void 0) {
|
|
1443
1407
|
await this.entry.commitEnding.catch(() => void 0);
|
|
1444
|
-
|
|
1408
|
+
throw transactionClosedError();
|
|
1445
1409
|
}
|
|
1446
1410
|
if (this.entry.state === "rolled-back") return;
|
|
1447
1411
|
try {
|
|
@@ -1510,14 +1474,6 @@ var OuterTransaction = class extends TransactionBase {
|
|
|
1510
1474
|
this.activity.stopAcceptingChildren();
|
|
1511
1475
|
this.runtime.unregister(this.connection, this.openTransaction);
|
|
1512
1476
|
}
|
|
1513
|
-
logDroppedError(error) {
|
|
1514
|
-
try {
|
|
1515
|
-
this.activity.ctx.log.error({
|
|
1516
|
-
event: "middleware.activityEnded.error",
|
|
1517
|
-
error
|
|
1518
|
-
});
|
|
1519
|
-
} catch {}
|
|
1520
|
-
}
|
|
1521
1477
|
};
|
|
1522
1478
|
var Savepoint = class extends TransactionBase {
|
|
1523
1479
|
root;
|
|
@@ -1561,7 +1517,7 @@ var Savepoint = class extends TransactionBase {
|
|
|
1561
1517
|
async rollback() {
|
|
1562
1518
|
if (this.entry.commitEnding !== void 0) {
|
|
1563
1519
|
await this.entry.commitEnding.catch(() => void 0);
|
|
1564
|
-
|
|
1520
|
+
throw transactionClosedError();
|
|
1565
1521
|
}
|
|
1566
1522
|
const commitAttempted = this.entry.state === "commit-failed";
|
|
1567
1523
|
if (this.isClosed) {
|
|
@@ -1682,6 +1638,7 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
1682
1638
|
#preparedStatementHandles = /* @__PURE__ */ new WeakMap();
|
|
1683
1639
|
#holdFinishedChildren;
|
|
1684
1640
|
#transactions = /* @__PURE__ */ new WeakMap();
|
|
1641
|
+
#startingTransactions = /* @__PURE__ */ new WeakSet();
|
|
1685
1642
|
#transactionRuntime = {
|
|
1686
1643
|
route: (driverTx, activity) => this.queryableRoute(driverTx, "transaction", () => activity, {
|
|
1687
1644
|
transaction: void 0,
|
|
@@ -1713,7 +1670,8 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
1713
1670
|
}
|
|
1714
1671
|
};
|
|
1715
1672
|
codecRegistryValidated;
|
|
1716
|
-
|
|
1673
|
+
_pendingTelemetry;
|
|
1674
|
+
_telemetryCache;
|
|
1717
1675
|
constructor(options) {
|
|
1718
1676
|
const { context, adapter, driver, verifyMarker, middleware, mode, log, closeRefusal, ownsDriver } = options;
|
|
1719
1677
|
if (middleware) for (const mw of middleware) checkMiddlewareCompatibility(mw, "sql", context.contract.target);
|
|
@@ -1743,7 +1701,8 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
1743
1701
|
this.verifyMarkerPromise = this.verifyMarkerOption === false ? Promise.resolve() : null;
|
|
1744
1702
|
this.closePromise = null;
|
|
1745
1703
|
this.ownsDriver = ownsDriver ?? true;
|
|
1746
|
-
this.
|
|
1704
|
+
this._pendingTelemetry = null;
|
|
1705
|
+
this._telemetryCache = null;
|
|
1747
1706
|
}
|
|
1748
1707
|
/**
|
|
1749
1708
|
* Lower a `SqlQueryPlan` (AST + meta) into a `SqlExecutionPlan`
|
|
@@ -1833,7 +1792,7 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
1833
1792
|
[activitySource] = {
|
|
1834
1793
|
startActivity: (activity) => {
|
|
1835
1794
|
this.#runtimeRoute ??= this.queryableRoute(this.driver, "runtime", () => void 0, {
|
|
1836
|
-
transaction: (parent, options) => this
|
|
1795
|
+
transaction: (parent, fn, options) => withTransaction(this, fn, options, parent),
|
|
1837
1796
|
runtimeWork: true
|
|
1838
1797
|
});
|
|
1839
1798
|
return this.startActivityOnRoute(this.#runtimeRoute, activity, void 0);
|
|
@@ -1917,14 +1876,25 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
1917
1876
|
connectionRoute(connection, owner) {
|
|
1918
1877
|
const openTransaction = this.#transactions.get(connection)?.activity;
|
|
1919
1878
|
return this.queryableRoute(connection, "connection", () => openTransaction, {
|
|
1920
|
-
transaction: openTransaction === void 0 ? (parent, options) => this.
|
|
1879
|
+
transaction: openTransaction === void 0 ? (parent, fn, options) => this.transactionOnHeldConnection(connection, owner, parent, fn, options) : void 0,
|
|
1921
1880
|
runtimeWork: false
|
|
1922
1881
|
});
|
|
1923
1882
|
}
|
|
1924
|
-
|
|
1925
|
-
const openTransaction = this.#transactions.get(connection)
|
|
1926
|
-
if (openTransaction !== void 0
|
|
1927
|
-
|
|
1883
|
+
async transactionOnHeldConnection(connection, owner, parent, fn, options) {
|
|
1884
|
+
const openTransaction = this.#transactions.get(connection);
|
|
1885
|
+
if (openTransaction !== void 0 || this.#startingTransactions.has(connection)) throw transactionAlreadyOpenError(parent, openTransaction?.activity);
|
|
1886
|
+
const state = {
|
|
1887
|
+
clean: true,
|
|
1888
|
+
reason: void 0
|
|
1889
|
+
};
|
|
1890
|
+
try {
|
|
1891
|
+
return await runTransactionOn({
|
|
1892
|
+
[transactionStart]: owner[transactionStart],
|
|
1893
|
+
transaction: (start) => this.beginTransactionOn(connection, owner, parent, start)
|
|
1894
|
+
}, fn, options, state);
|
|
1895
|
+
} finally {
|
|
1896
|
+
if (!state.clean) await connection.destroy(state.reason).catch(() => void 0);
|
|
1897
|
+
}
|
|
1928
1898
|
}
|
|
1929
1899
|
/** The `activitySource` member of a held connection that `owner()` wraps. */
|
|
1930
1900
|
connectionActivitySource(connection, owner) {
|
|
@@ -1985,23 +1955,13 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
1985
1955
|
});
|
|
1986
1956
|
}
|
|
1987
1957
|
};
|
|
1988
|
-
const
|
|
1989
|
-
if (
|
|
1990
|
-
return Object.assign(handle, { transaction: async (options) => {
|
|
1958
|
+
const transaction = route.transaction;
|
|
1959
|
+
if (transaction === void 0) return handle;
|
|
1960
|
+
return Object.assign(handle, { transaction: async (fn, options) => {
|
|
1991
1961
|
run.assertAcceptsChildren();
|
|
1992
|
-
|
|
1993
|
-
return beginTransaction(run, options);
|
|
1962
|
+
return transaction(run, fn, options);
|
|
1994
1963
|
} });
|
|
1995
1964
|
}
|
|
1996
|
-
async beginOwnedTransactionBeneath(parent, options) {
|
|
1997
|
-
validateTransactionTimeout(options?.timeout);
|
|
1998
|
-
const { driverConnection, connection } = await this.openConnection({ activityParent: parent });
|
|
1999
|
-
return this.ownTransaction(connection, () => this.beginTransactionOn(driverConnection, connection, parent, options));
|
|
2000
|
-
}
|
|
2001
|
-
/** Begins a transaction with `begin` on a connection the transaction owns; see `beginOwnedTransaction`. */
|
|
2002
|
-
ownTransaction(connection, begin) {
|
|
2003
|
-
return beginOwnedTransaction(connection, begin, this.sqlCtx.log);
|
|
2004
|
-
}
|
|
2005
1965
|
/**
|
|
2006
1966
|
* Returns a raw driver connection. SQL issued on it runs below the middleware/codec/telemetry pipeline. It carries its own lifecycle (`release`/`destroy`/`beginTransaction`); the caller owns disposal. It follows the runtime's close rule for connections: see {@link Runtime.close}. Pass the `activityParent` of the activity it is acquired for, so it is admitted after `close()` while that activity is open.
|
|
2007
1967
|
*/
|
|
@@ -2045,7 +2005,8 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
2045
2005
|
}
|
|
2046
2006
|
async setupDriverExecution(exec, queryable) {
|
|
2047
2007
|
this.familyAdapter.validatePlan(exec, this.contract);
|
|
2048
|
-
this.
|
|
2008
|
+
this._pendingTelemetry = null;
|
|
2009
|
+
this._telemetryCache = null;
|
|
2049
2010
|
if (this.verifyMarkerPromise === null) {
|
|
2050
2011
|
const markerQueryable = this.#heldQueryables.has(queryable) ? queryable : this.driver;
|
|
2051
2012
|
this.verifyMarkerPromise = this.verifyMarker(markerQueryable).catch((error) => {
|
|
@@ -2354,17 +2315,18 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
2354
2315
|
};
|
|
2355
2316
|
return this.executeEncodedPlan(run, exec, queryable, transaction, codecCtx, () => queryable.execute(request));
|
|
2356
2317
|
}
|
|
2357
|
-
async connection() {
|
|
2358
|
-
return
|
|
2318
|
+
async connection(options) {
|
|
2319
|
+
return this.openConnection(options);
|
|
2359
2320
|
}
|
|
2360
2321
|
async openConnection(options) {
|
|
2322
|
+
const parent = options?.activityParent;
|
|
2361
2323
|
const driverConn = await this.acquireRawConnection(options);
|
|
2362
2324
|
this.#heldQueryables.add(driverConn);
|
|
2363
2325
|
const self = this;
|
|
2364
2326
|
const wrappedConnection = {
|
|
2365
2327
|
[transactionStart]: createTransactionStart(),
|
|
2366
2328
|
transaction(options) {
|
|
2367
|
-
return self.beginTransactionOn(driverConn, wrappedConnection,
|
|
2329
|
+
return self.beginTransactionOn(driverConn, wrappedConnection, parent, options);
|
|
2368
2330
|
},
|
|
2369
2331
|
[activitySource]: self.connectionActivitySource(driverConn, () => wrappedConnection),
|
|
2370
2332
|
release: () => driverConn.release(),
|
|
@@ -2394,10 +2356,7 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
2394
2356
|
});
|
|
2395
2357
|
}
|
|
2396
2358
|
};
|
|
2397
|
-
return
|
|
2398
|
-
driverConnection: driverConn,
|
|
2399
|
-
connection: wrappedConnection
|
|
2400
|
-
};
|
|
2359
|
+
return wrappedConnection;
|
|
2401
2360
|
}
|
|
2402
2361
|
/**
|
|
2403
2362
|
* Begins a transaction on `connection`, which `owner` wraps, as a transaction activity. When the transaction's `activityStarted` hooks refuse the start, no `BEGIN` is sent, `owner` is recorded as clean, and `withTransaction` releases it; after any other start failure it destroys it. The transaction's `activityStarted` hooks run before `BEGIN`. Every statement sent on the transaction, or on `connection`, from the end of `BEGIN` until `commit()` or `rollback()` is called is the transaction's child, and is finalized when the transaction ends, with its outcome. Once `commit()` or `rollback()` is called, a statement sent on the transaction is refused when it starts, and one started earlier that has not reached the driver yet is refused with `RUNTIME.TRANSACTION_CLOSED`, so neither runs after the `COMMIT` or `ROLLBACK`. `commit()` and `rollback()` resolve after every finalization hook has run. A subclass that holds its own connection begins its transactions here.
|
|
@@ -2409,6 +2368,7 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
2409
2368
|
owner[transactionStart].refusedBeforeBegin = false;
|
|
2410
2369
|
const endTransactionWork = this.#openTransactionWork.begin();
|
|
2411
2370
|
this.#transactionWorkOn.set(connection, endTransactionWork);
|
|
2371
|
+
this.#startingTransactions.add(connection);
|
|
2412
2372
|
let activity;
|
|
2413
2373
|
try {
|
|
2414
2374
|
activity = await startTransactionActivity({
|
|
@@ -2422,6 +2382,7 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
2422
2382
|
});
|
|
2423
2383
|
} catch (error) {
|
|
2424
2384
|
endTransactionWork();
|
|
2385
|
+
this.#startingTransactions.delete(connection);
|
|
2425
2386
|
owner[transactionStart].refusedBeforeBegin = true;
|
|
2426
2387
|
throw error;
|
|
2427
2388
|
}
|
|
@@ -2430,6 +2391,7 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
2430
2391
|
driverTx = await connection.beginTransaction(options === void 0 ? void 0 : driverOptions);
|
|
2431
2392
|
} catch (error) {
|
|
2432
2393
|
endTransactionWork();
|
|
2394
|
+
this.#startingTransactions.delete(connection);
|
|
2433
2395
|
await activity.end({
|
|
2434
2396
|
by: "rollback",
|
|
2435
2397
|
outcome: "failed",
|
|
@@ -2438,10 +2400,21 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
2438
2400
|
throw error;
|
|
2439
2401
|
}
|
|
2440
2402
|
if (this.#heldQueryables.has(connection)) this.#heldQueryables.add(driverTx);
|
|
2441
|
-
|
|
2403
|
+
const transaction = new OuterTransaction(this.#transactionRuntime, connection, driverTx, activity, endTransactionWork, timeout);
|
|
2404
|
+
this.#startingTransactions.delete(connection);
|
|
2405
|
+
return transaction;
|
|
2442
2406
|
}
|
|
2443
2407
|
telemetry() {
|
|
2444
|
-
|
|
2408
|
+
const pending = this._pendingTelemetry;
|
|
2409
|
+
if (pending === null) return null;
|
|
2410
|
+
if (this._telemetryCache === null) this._telemetryCache = Object.freeze({
|
|
2411
|
+
lane: pending.lane,
|
|
2412
|
+
target: pending.target,
|
|
2413
|
+
fingerprint: computeSqlFingerprint(pending.sql),
|
|
2414
|
+
outcome: pending.outcome,
|
|
2415
|
+
...ifDefined("durationMs", pending.durationMs)
|
|
2416
|
+
});
|
|
2417
|
+
return this._telemetryCache;
|
|
2445
2418
|
}
|
|
2446
2419
|
close() {
|
|
2447
2420
|
this.closePromise ??= this.closeDriverAfterWork();
|
|
@@ -2510,14 +2483,14 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
2510
2483
|
});
|
|
2511
2484
|
}
|
|
2512
2485
|
recordTelemetry(plan, outcome, durationMs) {
|
|
2513
|
-
|
|
2514
|
-
this._telemetry = Object.freeze({
|
|
2486
|
+
this._pendingTelemetry = {
|
|
2515
2487
|
lane: plan.meta.lane,
|
|
2516
|
-
target: contract.target,
|
|
2517
|
-
|
|
2488
|
+
target: this.contract.target,
|
|
2489
|
+
sql: plan.sql,
|
|
2518
2490
|
outcome,
|
|
2519
|
-
|
|
2520
|
-
}
|
|
2491
|
+
durationMs
|
|
2492
|
+
};
|
|
2493
|
+
this._telemetryCache = null;
|
|
2521
2494
|
}
|
|
2522
2495
|
};
|
|
2523
2496
|
function activityOutsideTransactionError(parent, openTransaction) {
|
|
@@ -2531,7 +2504,7 @@ function transactionAlreadyOpenError(parent, openTransaction) {
|
|
|
2531
2504
|
return runtimeError$1("RUNTIME.TRANSACTION_ALREADY_OPEN", `A transaction is already open on this connection; a '${parent.activity.kind}' activity cannot begin another until it commits or rolls back.`, {
|
|
2532
2505
|
kind: parent.activity.kind,
|
|
2533
2506
|
id: parent.activity.id,
|
|
2534
|
-
transactionId: openTransaction
|
|
2507
|
+
transactionId: openTransaction?.activity.id
|
|
2535
2508
|
});
|
|
2536
2509
|
}
|
|
2537
2510
|
function noWork() {}
|
|
@@ -2591,36 +2564,60 @@ var RowsBeneath = class {
|
|
|
2591
2564
|
function withTransactionMembers(txCtx, members) {
|
|
2592
2565
|
return Object.assign(castAs(Object.create(txCtx)), members);
|
|
2593
2566
|
}
|
|
2594
|
-
async function withTransaction(runtime, fn, options) {
|
|
2567
|
+
async function withTransaction(runtime, fn, options, parent) {
|
|
2568
|
+
validateTransactionTimeout(options?.timeout);
|
|
2569
|
+
const connection = await runtime.connection(parent === void 0 ? void 0 : { activityParent: parent });
|
|
2570
|
+
const state = {
|
|
2571
|
+
clean: true,
|
|
2572
|
+
reason: void 0
|
|
2573
|
+
};
|
|
2574
|
+
try {
|
|
2575
|
+
return await runTransactionOn(connection, fn, options, state);
|
|
2576
|
+
} finally {
|
|
2577
|
+
if (!state.clean) await connection.destroy(state.reason).catch(() => void 0);
|
|
2578
|
+
else if (wasRefusedBeforeBegin(connection)) await connection.release().catch(() => void 0);
|
|
2579
|
+
else await connection.release();
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
async function runTransactionOn(connection, fn, options, state) {
|
|
2595
2583
|
validateTransactionTimeout(options?.timeout);
|
|
2596
|
-
let invalidated = false;
|
|
2597
|
-
const connection = await runtime.connection();
|
|
2598
2584
|
let transaction;
|
|
2599
2585
|
try {
|
|
2600
2586
|
transaction = await connection.transaction(options);
|
|
2601
2587
|
} catch (error) {
|
|
2602
|
-
if (wasRefusedBeforeBegin(connection))
|
|
2603
|
-
|
|
2588
|
+
if (!wasRefusedBeforeBegin(connection)) {
|
|
2589
|
+
state.clean = false;
|
|
2590
|
+
state.reason = error;
|
|
2591
|
+
}
|
|
2604
2592
|
throw error;
|
|
2605
2593
|
}
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
}
|
|
2616
|
-
|
|
2617
|
-
|
|
2594
|
+
try {
|
|
2595
|
+
return await runAndSettleTransaction(transaction, fn);
|
|
2596
|
+
} catch (error) {
|
|
2597
|
+
const settlement = settlementOf(transaction);
|
|
2598
|
+
if (settlement?.committed !== true && settlement?.rolledBack !== true) {
|
|
2599
|
+
state.clean = false;
|
|
2600
|
+
state.reason = error;
|
|
2601
|
+
}
|
|
2602
|
+
throw error;
|
|
2603
|
+
}
|
|
2604
|
+
}
|
|
2605
|
+
async function runInSavepoint(transaction, fn) {
|
|
2606
|
+
const savepoint = await transaction.transaction();
|
|
2607
|
+
try {
|
|
2608
|
+
return await runAndSettleTransaction(savepoint, fn);
|
|
2609
|
+
} catch (error) {
|
|
2610
|
+
if (savepoint.signal.aborted && error === savepoint.signal.reason) await savepoint.rollback().catch(() => void 0);
|
|
2611
|
+
throw error;
|
|
2612
|
+
}
|
|
2613
|
+
}
|
|
2614
|
+
function guardedTransactionContext(transaction, isClosed) {
|
|
2618
2615
|
async function* guardedStream(open) {
|
|
2619
|
-
if (
|
|
2616
|
+
if (isClosed()) throw transactionClosedError();
|
|
2620
2617
|
for await (const row of open()) {
|
|
2621
|
-
if (
|
|
2618
|
+
if (isClosed()) throw transactionClosedError();
|
|
2622
2619
|
yield row;
|
|
2623
|
-
if (
|
|
2620
|
+
if (isClosed()) throw transactionClosedError();
|
|
2624
2621
|
}
|
|
2625
2622
|
}
|
|
2626
2623
|
function guardedQueryable(target) {
|
|
@@ -2629,14 +2626,14 @@ async function withTransaction(runtime, fn, options) {
|
|
|
2629
2626
|
return new AsyncIterableResult(guardedStream(() => target.query(plan, options)));
|
|
2630
2627
|
},
|
|
2631
2628
|
async execute(plan, options) {
|
|
2632
|
-
if (
|
|
2629
|
+
if (isClosed()) throw transactionClosedError();
|
|
2633
2630
|
return target.execute(plan, options);
|
|
2634
2631
|
},
|
|
2635
2632
|
[preparedStatementQuery](ps, params, options) {
|
|
2636
2633
|
return new AsyncIterableResult(guardedStream(() => runPreparedQuery(target, ps, params, options)));
|
|
2637
2634
|
},
|
|
2638
2635
|
async [preparedStatementExecute](ps, params, options) {
|
|
2639
|
-
if (
|
|
2636
|
+
if (isClosed()) throw transactionClosedError();
|
|
2640
2637
|
return runPreparedExecute(target, ps, params, options);
|
|
2641
2638
|
}
|
|
2642
2639
|
};
|
|
@@ -2644,7 +2641,7 @@ async function withTransaction(runtime, fn, options) {
|
|
|
2644
2641
|
function guardedSource(target) {
|
|
2645
2642
|
return {
|
|
2646
2643
|
async startActivity(activity) {
|
|
2647
|
-
if (
|
|
2644
|
+
if (isClosed()) throw transactionClosedError();
|
|
2648
2645
|
return guardedHandle(await startActivityOn(target, activity));
|
|
2649
2646
|
},
|
|
2650
2647
|
planContentHash(plan) {
|
|
@@ -2665,19 +2662,34 @@ async function withTransaction(runtime, fn, options) {
|
|
|
2665
2662
|
end: (end) => handle.end(end)
|
|
2666
2663
|
};
|
|
2667
2664
|
}
|
|
2668
|
-
|
|
2665
|
+
return {
|
|
2669
2666
|
...guardedQueryable(transaction),
|
|
2670
2667
|
get invalidated() {
|
|
2671
|
-
return
|
|
2668
|
+
return isClosed();
|
|
2672
2669
|
},
|
|
2673
|
-
[activitySource]: guardedSource(transaction)
|
|
2670
|
+
[activitySource]: guardedSource(transaction),
|
|
2671
|
+
async transaction(fn) {
|
|
2672
|
+
if (isClosed()) throw transactionClosedError();
|
|
2673
|
+
return runInSavepoint(transaction, fn);
|
|
2674
|
+
}
|
|
2674
2675
|
};
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2676
|
+
}
|
|
2677
|
+
async function runAndSettleTransaction(transaction, fn) {
|
|
2678
|
+
let invalidated = false;
|
|
2679
|
+
const signal = transaction.signal;
|
|
2680
|
+
let rejectAbort = (_reason) => {};
|
|
2681
|
+
const aborted = new Promise((_, reject) => {
|
|
2682
|
+
rejectAbort = reject;
|
|
2683
|
+
});
|
|
2684
|
+
aborted.catch(() => void 0);
|
|
2685
|
+
const onAbort = () => {
|
|
2686
|
+
invalidated = true;
|
|
2687
|
+
rejectAbort(signal.reason);
|
|
2680
2688
|
};
|
|
2689
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
2690
|
+
if (signal.aborted) onAbort();
|
|
2691
|
+
const settlement = settlementOf(transaction);
|
|
2692
|
+
const txContext = guardedTransactionContext(transaction, () => invalidated || settlement?.closed === true);
|
|
2681
2693
|
let commitRequested = false;
|
|
2682
2694
|
try {
|
|
2683
2695
|
signal.throwIfAborted();
|
|
@@ -2687,35 +2699,30 @@ async function withTransaction(runtime, fn, options) {
|
|
|
2687
2699
|
await transaction.commit();
|
|
2688
2700
|
return result;
|
|
2689
2701
|
} catch (error) {
|
|
2690
|
-
if (signal.aborted)
|
|
2691
|
-
await destroyConnection(signal.reason);
|
|
2692
|
-
throw signal.reason;
|
|
2693
|
-
}
|
|
2702
|
+
if (signal.aborted) throw signal.reason;
|
|
2694
2703
|
if (!commitRequested) {
|
|
2695
2704
|
const selected = error;
|
|
2696
2705
|
invalidated = true;
|
|
2697
2706
|
try {
|
|
2698
2707
|
await transaction.rollback();
|
|
2699
2708
|
} catch (rollbackError) {
|
|
2700
|
-
const settlement = settlementOf(transaction);
|
|
2701
2709
|
if (settlement?.rolledBack === true) {
|
|
2702
2710
|
settlement.logDroppedError(rollbackError);
|
|
2703
2711
|
throw selected;
|
|
2704
2712
|
}
|
|
2705
|
-
await
|
|
2713
|
+
await settlement?.abandon();
|
|
2706
2714
|
const wrapped = runtimeError$1("RUNTIME.TRANSACTION_ROLLBACK_FAILED", "Transaction rollback failed after callback error", { rollbackError });
|
|
2707
2715
|
wrapped.cause = selected;
|
|
2708
2716
|
throw wrapped;
|
|
2709
2717
|
}
|
|
2710
2718
|
throw selected;
|
|
2711
2719
|
}
|
|
2712
|
-
if (
|
|
2720
|
+
if (settlement?.committed === true) throw error;
|
|
2713
2721
|
try {
|
|
2714
2722
|
await transaction.rollback();
|
|
2715
2723
|
} catch (rollbackError) {
|
|
2716
|
-
const settlement = settlementOf(transaction);
|
|
2717
2724
|
if (settlement?.rolledBack === true) settlement.logDroppedError(rollbackError);
|
|
2718
|
-
else await
|
|
2725
|
+
else await settlement?.abandon();
|
|
2719
2726
|
}
|
|
2720
2727
|
const wrapped = runtimeError$1("RUNTIME.TRANSACTION_COMMIT_FAILED", "Transaction commit failed", { commitError: error });
|
|
2721
2728
|
wrapped.cause = error;
|
|
@@ -2723,7 +2730,6 @@ async function withTransaction(runtime, fn, options) {
|
|
|
2723
2730
|
} finally {
|
|
2724
2731
|
invalidated = true;
|
|
2725
2732
|
signal.removeEventListener("abort", onAbort);
|
|
2726
|
-
if (!connectionDisposed) await connection.release();
|
|
2727
2733
|
}
|
|
2728
2734
|
}
|
|
2729
2735
|
function createToSql(stack, contract) {
|
|
@@ -2741,4 +2747,4 @@ function createToSql(stack, contract) {
|
|
|
2741
2747
|
//#endregion
|
|
2742
2748
|
export { validateContractCodecMappings as C, validateCodecRegistryCompleteness as S, withTransactionMembers as T, lints as _, budgets as a, startActivityOn as b, createSqlExecutionStack as c, delegatingRuntime as d, deriveParamMetadata as f, lazyActivitySource as g, findActivitySource as h, activitySource as i, createToSql as l, extractCodecIds as m, PreparedStatementImpl as n, createAstCodecRegistry as o, encodeParamsWithMetadata as p, SqlRuntimeBase as r, createExecutionContext as s, PreparedExecutionImpl as t, delegatingActivitySource as u, lowerSqlPlan as v, withTransaction as w, toRuntimeOptions as x, planContentHashOn as y };
|
|
2743
2749
|
|
|
2744
|
-
//# sourceMappingURL=exports-
|
|
2750
|
+
//# sourceMappingURL=exports-kqOXg2OT-D3lo7jnX.mjs.map
|