@prisma/orm-family-sql 8.0.0-rc.24-dev.18 → 8.0.0-rc.24-dev.20

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.
@@ -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-cGSgYmrd.mjs
21
+ //#region ../../../2-sql-family/5-runtime/dist/exports-BE9wmKAn.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) {
@@ -1248,6 +1248,364 @@ function resolvePreparedSlotValues(ps, userParams) {
1248
1248
  async function encodePreparedParams(ps, userParams, ctx, contractCodecs) {
1249
1249
  return encodeParamsWithMetadata(resolvePreparedSlotValues(ps, userParams), ps.paramMetadata, ctx, contractCodecs);
1250
1250
  }
1251
+ var TransactionStack = class {
1252
+ #entries = [];
1253
+ #savepoints = 0;
1254
+ #invalidated = false;
1255
+ push(entry) {
1256
+ this.#entries.push(entry);
1257
+ }
1258
+ pop() {
1259
+ const entry = this.#entries.pop();
1260
+ invariant(entry !== void 0, "The transaction stack is empty");
1261
+ return entry;
1262
+ }
1263
+ get top() {
1264
+ return this.#entries.at(-1);
1265
+ }
1266
+ includes(entry) {
1267
+ return this.#entries.includes(entry);
1268
+ }
1269
+ nextSavepointName() {
1270
+ this.#savepoints += 1;
1271
+ return `sp_${this.#savepoints}`;
1272
+ }
1273
+ invalidate() {
1274
+ this.#invalidated = true;
1275
+ }
1276
+ get invalidated() {
1277
+ return this.#invalidated;
1278
+ }
1279
+ };
1280
+ var TransactionBase = class {
1281
+ [activitySource];
1282
+ runtime;
1283
+ driverTx;
1284
+ activity;
1285
+ stack;
1286
+ entry;
1287
+ openTransaction;
1288
+ route;
1289
+ constructor(runtime, driverTx, activity, stack, entry) {
1290
+ this.runtime = runtime;
1291
+ this.driverTx = driverTx;
1292
+ this.activity = activity;
1293
+ this.stack = stack;
1294
+ this.entry = entry;
1295
+ this.route = runtime.route(driverTx, activity);
1296
+ this.openTransaction = {
1297
+ activity,
1298
+ assertAcceptsStatements: () => this.assertAcceptsStatements(),
1299
+ assertBeforeDeadline: () => this.assertBeforeDeadline()
1300
+ };
1301
+ runtime.register(driverTx, this.openTransaction);
1302
+ this[activitySource] = {
1303
+ startActivity: (clientActivity) => runtime.startActivity(this.route, clientActivity),
1304
+ planContentHash: (plan) => runtime.planContentHash(plan, activity)
1305
+ };
1306
+ }
1307
+ query(plan, options) {
1308
+ return this.route.query(plan, { ...options });
1309
+ }
1310
+ execute(plan, options) {
1311
+ return this.route.execute(plan, { ...options });
1312
+ }
1313
+ [preparedStatementQuery](ps, params, options) {
1314
+ return this.route.preparedQuery(blindCast(ps), params, { ...options });
1315
+ }
1316
+ [preparedStatementExecute](ps, params, options) {
1317
+ return this.route.preparedExecute(blindCast(ps), params, { ...options });
1318
+ }
1319
+ async transaction() {
1320
+ if (this.isClosed) throw transactionClosedError();
1321
+ this.assertAcceptsStatements();
1322
+ const name = this.stack.nextSavepointName();
1323
+ const entry = {
1324
+ name,
1325
+ activity: void 0,
1326
+ commitEnding: void 0,
1327
+ state: "open"
1328
+ };
1329
+ this.stack.push(entry);
1330
+ let activity;
1331
+ try {
1332
+ activity = await this.runtime.startTransactionActivity(this.activity);
1333
+ } catch (error) {
1334
+ this.stack.pop();
1335
+ throw error;
1336
+ }
1337
+ entry.activity = activity;
1338
+ let driverSavepoint;
1339
+ try {
1340
+ driverSavepoint = await this.runtime.trackInFlight(() => this.driverTx.savepoint(name));
1341
+ } catch (error) {
1342
+ this.stack.pop();
1343
+ await activity.end({
1344
+ by: "rollback",
1345
+ outcome: "failed",
1346
+ commitAttempted: false
1347
+ });
1348
+ throw error;
1349
+ }
1350
+ this.runtime.markHeld(this.driverTx, driverSavepoint);
1351
+ return new Savepoint(this.runtime, driverSavepoint, activity, this.stack, entry, this.rootTransaction);
1352
+ }
1353
+ };
1354
+ var OuterTransaction = class extends TransactionBase {
1355
+ signal;
1356
+ [transactionSettlement];
1357
+ controller = new AbortController();
1358
+ connection;
1359
+ endTransactionWork;
1360
+ timeout;
1361
+ deadline;
1362
+ closed = false;
1363
+ timer;
1364
+ commitAttempted = false;
1365
+ self = this;
1366
+ constructor(runtime, connection, driverTx, activity, endTransactionWork, timeout) {
1367
+ const entry = {
1368
+ name: void 0,
1369
+ activity,
1370
+ commitEnding: void 0,
1371
+ state: "open"
1372
+ };
1373
+ super(runtime, driverTx, activity, new TransactionStack(), entry);
1374
+ this.stack.push(entry);
1375
+ this.signal = this.controller.signal;
1376
+ this.endTransactionWork = endTransactionWork;
1377
+ this.timeout = timeout;
1378
+ this.deadline = performance.now() + (timeout ?? Number.POSITIVE_INFINITY);
1379
+ this.connection = connection;
1380
+ 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
+ if (timeout !== void 0) {
1391
+ this.timer = setTimeout(() => this.expire(), timeout);
1392
+ runtime.onConnectionReleased(connection, () => this.releaseConnection());
1393
+ }
1394
+ }
1395
+ get isClosed() {
1396
+ return this.closed || this.stack.invalidated;
1397
+ }
1398
+ get rootTransaction() {
1399
+ return this.self;
1400
+ }
1401
+ assertBeforeDeadline() {
1402
+ if (this.timeout === void 0) return;
1403
+ if (!this.closed && performance.now() >= this.deadline) this.expire();
1404
+ this.signal.throwIfAborted();
1405
+ if (this.closed) throw transactionClosedError();
1406
+ }
1407
+ assertAcceptsStatements() {
1408
+ if (this.stack.invalidated) throw transactionClosedError();
1409
+ if (!this.closed && this.stack.top !== this.entry) throw transactionSuspendedError(this.stack);
1410
+ }
1411
+ async commit() {
1412
+ this.assertBeforeDeadline();
1413
+ this.assertAcceptsStatements();
1414
+ this.stopDeadline();
1415
+ this.commitAttempted = true;
1416
+ this.stopAcceptingChildren();
1417
+ try {
1418
+ await this.runtime.trackInFlight(() => this.driverTx.commit());
1419
+ } catch (error) {
1420
+ this.endTransactionWork();
1421
+ await this.activity.end({
1422
+ by: "commit",
1423
+ outcome: "failed"
1424
+ });
1425
+ throw error;
1426
+ }
1427
+ this.entry.state = "committed";
1428
+ this.entry.commitEnding = this.activity.end({
1429
+ by: "commit",
1430
+ outcome: "succeeded"
1431
+ });
1432
+ try {
1433
+ await this.entry.commitEnding;
1434
+ } finally {
1435
+ this.endTransactionWork();
1436
+ }
1437
+ }
1438
+ async rollback() {
1439
+ if (this.stack.invalidated) return this.refuseInvalidatedRollback();
1440
+ if (this.stack.top !== this.entry && !this.signal.aborted) throw transactionSuspendedError(this.stack);
1441
+ this.stopDeadline();
1442
+ this.stopAcceptingChildren();
1443
+ if (this.entry.commitEnding !== void 0) {
1444
+ await this.entry.commitEnding.catch(() => void 0);
1445
+ return;
1446
+ }
1447
+ if (this.entry.state === "rolled-back") return;
1448
+ try {
1449
+ await this.runtime.trackInFlight(() => this.driverTx.rollback());
1450
+ } catch (error) {
1451
+ this.endTransactionWork();
1452
+ await this.activity.end({
1453
+ by: "rollback",
1454
+ outcome: "failed",
1455
+ commitAttempted: this.commitAttempted
1456
+ });
1457
+ throw error;
1458
+ }
1459
+ this.entry.state = "rolled-back";
1460
+ try {
1461
+ await this.activity.end({
1462
+ by: "rollback",
1463
+ outcome: "succeeded",
1464
+ commitAttempted: this.commitAttempted
1465
+ });
1466
+ } finally {
1467
+ this.endTransactionWork();
1468
+ }
1469
+ }
1470
+ async refuseInvalidatedRollback() {
1471
+ this.stopDeadline();
1472
+ this.stopAcceptingChildren();
1473
+ this.endTransactionWork();
1474
+ await this.activity.end({
1475
+ by: "rollback",
1476
+ outcome: "failed",
1477
+ commitAttempted: this.commitAttempted
1478
+ });
1479
+ throw transactionClosedError();
1480
+ }
1481
+ async releaseConnection() {
1482
+ this.stopDeadline();
1483
+ this.stopAcceptingChildren();
1484
+ try {
1485
+ if (this.entry.state !== "committed" && this.entry.state !== "rolled-back") {
1486
+ this.entry.state = "rolled-back";
1487
+ await this.activity.end({
1488
+ by: "rollback",
1489
+ outcome: "failed",
1490
+ commitAttempted: this.commitAttempted
1491
+ });
1492
+ }
1493
+ } catch (error) {
1494
+ this.logDroppedError(error);
1495
+ } finally {
1496
+ this.endTransactionWork();
1497
+ }
1498
+ }
1499
+ stopDeadline() {
1500
+ clearTimeout(this.timer);
1501
+ this.timer = void 0;
1502
+ this.closed = true;
1503
+ }
1504
+ expire() {
1505
+ if (this.closed) return;
1506
+ this.stopDeadline();
1507
+ this.activity.stopAcceptingChildren();
1508
+ this.controller.abort(runtimeError$1("RUNTIME.TRANSACTION_TIMEOUT", "Transaction callback exceeded its timeout", { timeout: this.timeout }));
1509
+ }
1510
+ stopAcceptingChildren() {
1511
+ this.activity.stopAcceptingChildren();
1512
+ if (this.timeout === void 0) this.openTransaction.activity = void 0;
1513
+ this.runtime.unregister(this.connection, this.openTransaction);
1514
+ }
1515
+ logDroppedError(error) {
1516
+ try {
1517
+ this.activity.ctx.log.error({
1518
+ event: "middleware.activityEnded.error",
1519
+ error
1520
+ });
1521
+ } catch {}
1522
+ }
1523
+ };
1524
+ var Savepoint = class extends TransactionBase {
1525
+ root;
1526
+ constructor(runtime, driverTx, activity, stack, entry, root) {
1527
+ super(runtime, driverTx, activity, stack, entry);
1528
+ this.root = root;
1529
+ }
1530
+ get signal() {
1531
+ return this.root.signal;
1532
+ }
1533
+ get isClosed() {
1534
+ return this.root.isClosed || !this.stack.includes(this.entry);
1535
+ }
1536
+ get rootTransaction() {
1537
+ return this.root;
1538
+ }
1539
+ assertBeforeDeadline() {
1540
+ this.root.assertBeforeDeadline();
1541
+ }
1542
+ assertAcceptsStatements() {
1543
+ if (this.isClosed) throw transactionClosedError();
1544
+ if (this.stack.top !== this.entry) throw transactionSuspendedError(this.stack);
1545
+ }
1546
+ async commit() {
1547
+ this.assertAcceptsStatements();
1548
+ try {
1549
+ await this.runtime.trackInFlight(() => this.driverTx.commit());
1550
+ } catch (error) {
1551
+ this.entry.state = "commit-failed";
1552
+ throw error;
1553
+ }
1554
+ this.stack.pop();
1555
+ this.entry.state = "committed";
1556
+ this.entry.commitEnding = this.activity.end({
1557
+ by: "release",
1558
+ outcome: "succeeded"
1559
+ });
1560
+ await this.entry.commitEnding;
1561
+ }
1562
+ async rollback() {
1563
+ if (this.entry.commitEnding !== void 0) {
1564
+ await this.entry.commitEnding.catch(() => void 0);
1565
+ return;
1566
+ }
1567
+ const commitAttempted = this.entry.state === "commit-failed";
1568
+ if (this.isClosed) {
1569
+ await this.activity.end({
1570
+ by: "rollback",
1571
+ outcome: "failed",
1572
+ commitAttempted
1573
+ });
1574
+ throw transactionClosedError();
1575
+ }
1576
+ if (this.stack.top !== this.entry) throw transactionSuspendedError(this.stack);
1577
+ try {
1578
+ await this.runtime.trackInFlight(() => this.driverTx.rollback());
1579
+ } catch (error) {
1580
+ this.stack.invalidate();
1581
+ await this.activity.end({
1582
+ by: "rollback",
1583
+ outcome: "failed",
1584
+ commitAttempted
1585
+ });
1586
+ throw error;
1587
+ }
1588
+ this.stack.pop();
1589
+ this.entry.state = "rolled-back";
1590
+ await this.activity.end({
1591
+ by: "rollback",
1592
+ outcome: "succeeded",
1593
+ commitAttempted
1594
+ });
1595
+ }
1596
+ };
1597
+ function transactionClosedError() {
1598
+ return runtimeError$1("RUNTIME.TRANSACTION_CLOSED", "Cannot use a transaction operation after the transaction has ended. Consume query results and await execute calls inside the transaction callback.", {});
1599
+ }
1600
+ function openSavepointOf(stack) {
1601
+ const { top } = stack;
1602
+ invariant(top !== void 0, "A transaction below the top of the stack has a savepoint above it");
1603
+ return top;
1604
+ }
1605
+ function transactionSuspendedError(stack) {
1606
+ const open = openSavepointOf(stack);
1607
+ return runtimeError$1("RUNTIME.TRANSACTION_SUSPENDED", `Savepoint ${open.name} is open on this transaction; commit or roll it back before using the transaction again.`, { savepointId: open.activity?.activity.id });
1608
+ }
1251
1609
  var SqlFamilyAdapter = class {
1252
1610
  contract;
1253
1611
  markerReader;
@@ -1319,13 +1677,42 @@ var SqlRuntimeBase = class extends RuntimeCore {
1319
1677
  #inFlight = new InFlightOperations();
1320
1678
  #openTransactionWork = new InFlightOperations();
1321
1679
  #transactionWorkOn = /* @__PURE__ */ new WeakMap();
1322
- #transactionChecks = /* @__PURE__ */ new WeakMap();
1323
1680
  #openActivityHandles = 0;
1324
1681
  #refusing = false;
1325
1682
  #heldQueryables = /* @__PURE__ */ new WeakSet();
1326
1683
  #preparedStatementHandles = /* @__PURE__ */ new WeakMap();
1327
1684
  #holdFinishedChildren;
1328
- #openTransactions = /* @__PURE__ */ new WeakMap();
1685
+ #transactions = /* @__PURE__ */ new WeakMap();
1686
+ #transactionRuntime = {
1687
+ route: (driverTx, activity) => this.queryableRoute(driverTx, "transaction", () => activity, {
1688
+ transaction: void 0,
1689
+ runtimeWork: false
1690
+ }),
1691
+ startActivity: (route, activity) => this.startActivityOnRoute(route, activity, void 0),
1692
+ planContentHash: (plan, parent) => this.planContentHashFor(plan, "transaction", parent),
1693
+ startTransactionActivity: (parent) => startTransactionActivity({
1694
+ middleware: this.middleware,
1695
+ context: {
1696
+ ...this.sqlCtx,
1697
+ scope: "transaction"
1698
+ },
1699
+ parent,
1700
+ holdFinishedChildren: this.#holdFinishedChildren
1701
+ }),
1702
+ trackInFlight: (operation) => this.#inFlight.track(operation),
1703
+ register: (queryable, transaction) => {
1704
+ this.#transactions.set(queryable, transaction);
1705
+ },
1706
+ unregister: (queryable, transaction) => {
1707
+ if (this.#transactions.get(queryable) === transaction) this.#transactions.delete(queryable);
1708
+ },
1709
+ markHeld: (driverTx, driverSavepoint) => {
1710
+ if (this.#heldQueryables.has(driverTx)) this.#heldQueryables.add(driverSavepoint);
1711
+ },
1712
+ onConnectionReleased: (connection, teardown) => {
1713
+ this.#transactionWorkOn.set(connection, teardown);
1714
+ }
1715
+ };
1329
1716
  codecRegistryValidated;
1330
1717
  _telemetry;
1331
1718
  constructor(options) {
@@ -1529,14 +1916,14 @@ var SqlRuntimeBase = class extends RuntimeCore {
1529
1916
  }
1530
1917
  /** The activity route of a held connection that `owner` wraps: its statements run on `connection`, and its transactions begin there. */
1531
1918
  connectionRoute(connection, owner) {
1532
- const openTransaction = this.#openTransactions.get(connection);
1919
+ const openTransaction = this.#transactions.get(connection)?.activity;
1533
1920
  return this.queryableRoute(connection, "connection", () => openTransaction, {
1534
1921
  transaction: openTransaction === void 0 ? (parent, options) => this.beginTransactionBeneathOn(connection, owner, parent, options) : void 0,
1535
1922
  runtimeWork: false
1536
1923
  });
1537
1924
  }
1538
1925
  beginTransactionBeneathOn(connection, owner, parent, options) {
1539
- const openTransaction = this.#openTransactions.get(connection);
1926
+ const openTransaction = this.#transactions.get(connection)?.activity;
1540
1927
  if (openTransaction !== void 0) return Promise.reject(transactionAlreadyOpenError(parent, openTransaction));
1541
1928
  return this.beginTransactionOn(connection, owner, parent, options);
1542
1929
  }
@@ -1544,7 +1931,7 @@ var SqlRuntimeBase = class extends RuntimeCore {
1544
1931
  connectionActivitySource(connection, owner) {
1545
1932
  return {
1546
1933
  startActivity: (activity) => this.startActivityOnRoute(this.connectionRoute(connection, owner()), activity, void 0),
1547
- planContentHash: (plan) => this.planContentHashFor(plan, "connection", this.#openTransactions.get(connection))
1934
+ planContentHash: (plan) => this.planContentHashFor(plan, "connection", this.#transactions.get(connection)?.activity)
1548
1935
  };
1549
1936
  }
1550
1937
  activityHandle(run, route, endWork) {
@@ -1697,7 +2084,9 @@ var SqlRuntimeBase = class extends RuntimeCore {
1697
2084
  return this.#inFlight.begin();
1698
2085
  }
1699
2086
  parentOf(queryable, options) {
1700
- const openTransaction = this.#openTransactions.get(queryable);
2087
+ const transaction = this.#transactions.get(queryable);
2088
+ transaction?.assertAcceptsStatements?.();
2089
+ const openTransaction = transaction?.activity;
1701
2090
  const activityParent = options?.activityParent;
1702
2091
  if (activityParent === void 0) return openTransaction;
1703
2092
  if (openTransaction !== void 0 && !activityParent.ctx.inTransaction()) throw activityOutsideTransactionError(activityParent, openTransaction);
@@ -1713,7 +2102,7 @@ var SqlRuntimeBase = class extends RuntimeCore {
1713
2102
  let telemetryOutcome = null;
1714
2103
  try {
1715
2104
  const iterator = run.runQuery(exec, () => {
1716
- this.#transactionChecks.get(queryable)?.();
2105
+ this.#transactions.get(queryable)?.assertBeforeDeadline?.();
1717
2106
  return driverCall();
1718
2107
  })[Symbol.asyncIterator]();
1719
2108
  let answered = false;
@@ -1832,7 +2221,7 @@ var SqlRuntimeBase = class extends RuntimeCore {
1832
2221
  let telemetryOutcome = "success";
1833
2222
  try {
1834
2223
  return await run.runExecute(exec, () => {
1835
- this.#transactionChecks.get(queryable)?.();
2224
+ this.#transactions.get(queryable)?.assertBeforeDeadline?.();
1836
2225
  return driverCall();
1837
2226
  });
1838
2227
  } catch (error) {
@@ -2046,164 +2435,7 @@ var SqlRuntimeBase = class extends RuntimeCore {
2046
2435
  throw error;
2047
2436
  }
2048
2437
  if (this.#heldQueryables.has(connection)) this.#heldQueryables.add(driverTx);
2049
- return this.wrapTransaction(driverTx, connection, activity, endTransactionWork, timeout);
2050
- }
2051
- wrapTransaction(driverTx, connection, activity, endTransactionWork, timeout) {
2052
- this.#openTransactions.set(driverTx, activity);
2053
- this.#openTransactions.set(connection, activity);
2054
- const stopAcceptingChildren = () => {
2055
- activity.stopAcceptingChildren();
2056
- for (const queryable of timeout === void 0 ? [driverTx, connection] : [connection]) if (this.#openTransactions.get(queryable) === activity) this.#openTransactions.delete(queryable);
2057
- };
2058
- let commitAttempted = false;
2059
- const settlement = {
2060
- committed: false,
2061
- rolledBack: false,
2062
- logDroppedError(error) {
2063
- try {
2064
- activity.ctx.log.error({
2065
- event: "middleware.activityEnded.error",
2066
- error
2067
- });
2068
- } catch {}
2069
- }
2070
- };
2071
- let commitEnding;
2072
- const controller = new AbortController();
2073
- const deadline = performance.now() + (timeout ?? Number.POSITIVE_INFINITY);
2074
- let closed = false;
2075
- let timer;
2076
- const stopDeadline = () => {
2077
- clearTimeout(timer);
2078
- timer = void 0;
2079
- closed = true;
2080
- };
2081
- const expire = () => {
2082
- if (closed) return;
2083
- stopDeadline();
2084
- activity.stopAcceptingChildren();
2085
- controller.abort(runtimeError$1("RUNTIME.TRANSACTION_TIMEOUT", "Transaction callback exceeded its timeout", { timeout }));
2086
- };
2087
- const check = () => {
2088
- if (timeout === void 0) return;
2089
- if (!closed && performance.now() >= deadline) expire();
2090
- controller.signal.throwIfAborted();
2091
- if (closed) throw transactionClosedError();
2092
- };
2093
- if (timeout !== void 0) {
2094
- timer = setTimeout(expire, timeout);
2095
- this.#transactionChecks.set(driverTx, check);
2096
- this.#transactionWorkOn.set(connection, async () => {
2097
- stopDeadline();
2098
- stopAcceptingChildren();
2099
- try {
2100
- if (!settlement.committed && !settlement.rolledBack) {
2101
- settlement.rolledBack = true;
2102
- await activity.end({
2103
- by: "rollback",
2104
- outcome: "failed",
2105
- commitAttempted
2106
- });
2107
- }
2108
- } catch (error) {
2109
- settlement.logDroppedError(error);
2110
- } finally {
2111
- endTransactionWork();
2112
- }
2113
- });
2114
- }
2115
- const self = this;
2116
- return {
2117
- [transactionSettlement]: settlement,
2118
- signal: controller.signal,
2119
- async commit() {
2120
- check();
2121
- stopDeadline();
2122
- commitAttempted = true;
2123
- stopAcceptingChildren();
2124
- try {
2125
- await self.#inFlight.track(() => driverTx.commit());
2126
- } catch (error) {
2127
- endTransactionWork();
2128
- await activity.end({
2129
- by: "commit",
2130
- outcome: "failed"
2131
- });
2132
- throw error;
2133
- }
2134
- settlement.committed = true;
2135
- commitEnding = activity.end({
2136
- by: "commit",
2137
- outcome: "succeeded"
2138
- });
2139
- try {
2140
- await commitEnding;
2141
- } finally {
2142
- endTransactionWork();
2143
- }
2144
- },
2145
- async rollback() {
2146
- stopDeadline();
2147
- stopAcceptingChildren();
2148
- if (settlement.committed) {
2149
- await commitEnding?.catch(() => void 0);
2150
- return;
2151
- }
2152
- if (settlement.rolledBack) return;
2153
- try {
2154
- await self.#inFlight.track(() => driverTx.rollback());
2155
- } catch (error) {
2156
- endTransactionWork();
2157
- await activity.end({
2158
- by: "rollback",
2159
- outcome: "failed",
2160
- commitAttempted
2161
- });
2162
- throw error;
2163
- }
2164
- settlement.rolledBack = true;
2165
- try {
2166
- await activity.end({
2167
- by: "rollback",
2168
- outcome: "succeeded",
2169
- commitAttempted
2170
- });
2171
- } finally {
2172
- endTransactionWork();
2173
- }
2174
- },
2175
- [activitySource]: {
2176
- startActivity: (clientActivity) => self.startActivityOnRoute(self.queryableRoute(driverTx, "transaction", () => activity, {
2177
- transaction: void 0,
2178
- runtimeWork: false
2179
- }), clientActivity, void 0),
2180
- planContentHash: (plan) => self.planContentHashFor(plan, "transaction", activity)
2181
- },
2182
- query(plan, options) {
2183
- return self.queryAgainstQueryable(plan, driverTx, {
2184
- ...options,
2185
- scope: "transaction"
2186
- });
2187
- },
2188
- execute(plan, options) {
2189
- return self.executeStatisticsAgainstQueryable(plan, driverTx, {
2190
- ...options,
2191
- scope: "transaction"
2192
- });
2193
- },
2194
- [preparedStatementQuery](ps, params, options) {
2195
- return self.runPreparedQueryAgainstQueryable(blindCast(ps), params, driverTx, {
2196
- ...options,
2197
- scope: "transaction"
2198
- });
2199
- },
2200
- [preparedStatementExecute](ps, params, options) {
2201
- return self.runPreparedExecuteAgainstQueryable(blindCast(ps), params, driverTx, {
2202
- ...options,
2203
- scope: "transaction"
2204
- });
2205
- }
2206
- };
2438
+ return new OuterTransaction(this.#transactionRuntime, connection, driverTx, activity, endTransactionWork, timeout);
2207
2439
  }
2208
2440
  telemetry() {
2209
2441
  return this._telemetry;
@@ -2350,9 +2582,6 @@ var RowsBeneath = class {
2350
2582
  await this.return();
2351
2583
  }
2352
2584
  };
2353
- function transactionClosedError() {
2354
- return runtimeError$1("RUNTIME.TRANSACTION_CLOSED", "Cannot use a transaction operation after the transaction has ended. Consume query results and await execute calls inside the transaction callback.", {});
2355
- }
2356
2585
  /**
2357
2586
  * Adds a client's members to the context `withTransaction` passes. The context is the prototype, not spread, so live accessors such as `invalidated` keep reading the transaction's state; spreading would copy their value once.
2358
2587
  */
@@ -2507,4 +2736,4 @@ function createToSql(stack, contract) {
2507
2736
  //#endregion
2508
2737
  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 };
2509
2738
 
2510
- //# sourceMappingURL=exports-cGSgYmrd-BADpxA8G.mjs.map
2739
+ //# sourceMappingURL=exports-BE9wmKAn-DI9rC9jC.mjs.map