@prisma/query-plan-executor 8.1.0-dev.10 → 8.1.0-dev.12

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/index.d.ts CHANGED
@@ -3275,6 +3275,12 @@ declare interface TracingHelper {
3275
3275
  runInChildSpan<R>(nameOrOptions: string | ExtendedSpanOptions, callback: SpanCallback<R>): R;
3276
3276
  }
3277
3277
 
3278
+ /**
3279
+ * A transaction on one connection. The caller calls either `commit()` or `rollback()`, once,
3280
+ * and sends nothing on the transaction afterwards. `commit()` is called only when no statement is
3281
+ * running. `rollback()`, `rollbackToSavepoint()`, `releaseSavepoint()` and a `ROLLBACK` sent through
3282
+ * `executeRaw` may be called while one is.
3283
+ */
3278
3284
  declare interface Transaction extends AdapterInfo, SqlQueryable {
3279
3285
  /**
3280
3286
  * Transaction options.
@@ -3329,7 +3335,14 @@ export declare class TransactionManager {
3329
3335
  startTransaction(options?: TransactionOptions_2): Promise<TransactionInfo>;
3330
3336
  commitTransaction(transactionId: string): Promise<void>;
3331
3337
  rollbackTransaction(transactionId: string): Promise<void>;
3332
- getTransaction(txInfo: TransactionInfo, operation: string): Promise<Transaction>;
3338
+ /**
3339
+ * Returns a handle for running statements in the transaction. The handle rejects every
3340
+ * statement issued after the transaction has started to close, or after the nested transaction
3341
+ * that is innermost now has started to roll back. A commit of that nested transaction never
3342
+ * closes the handle: it runs its statements in the enclosing transaction from then on,
3343
+ * including one issued while the commit waits to release the savepoint.
3344
+ */
3345
+ getTransaction(txInfo: TransactionInfo, operation: string): Promise<SqlQueryable>;
3333
3346
  cancelAllTransactions(): Promise<void>;
3334
3347
  }
3335
3348
 
package/dist/index.js CHANGED
@@ -72089,7 +72089,7 @@ __export(index_exports, {
72089
72089
  module.exports = __toCommonJS(index_exports);
72090
72090
 
72091
72091
  // package.json
72092
- var version = "8.1.0-dev.10";
72092
+ var version = "8.1.0-dev.12";
72093
72093
 
72094
72094
  // ../../node_modules/.pnpm/temporal-polyfill@0.3.0/node_modules/temporal-polyfill/chunks/internal.js
72095
72095
  function clampProp(e2, n2, t2, o2, r2) {
@@ -84197,6 +84197,13 @@ var TransactionRolledBackError = class extends TransactionManagerError {
84197
84197
  super(`Transaction already closed: A ${operation} cannot be executed on a transaction that was rolled back.`);
84198
84198
  }
84199
84199
  };
84200
+ var NestedTransactionRolledBackError = class extends TransactionManagerError {
84201
+ constructor(operation) {
84202
+ super(
84203
+ `Nested transaction already closed: A ${operation} cannot be executed on a nested transaction that was rolled back.`
84204
+ );
84205
+ }
84206
+ };
84200
84207
  var TransactionStartTimeoutError = class extends TransactionManagerError {
84201
84208
  constructor() {
84202
84209
  super("Unable to start a transaction in the given time.");
@@ -84221,7 +84228,23 @@ var InvalidTransactionIsolationLevelError = class extends TransactionManagerErro
84221
84228
  }
84222
84229
  };
84223
84230
  var MAX_CLOSED_TRANSACTIONS = 100;
84224
- var CANCEL_ROLLBACK_GRACE_MS = 2e3;
84231
+ var ROLLBACK_GRACE_MS = 2e3;
84232
+ function createScope(savepoint) {
84233
+ return { savepoint, closingReason: void 0, runningStatements: /* @__PURE__ */ new Set() };
84234
+ }
84235
+ function isNested(scope) {
84236
+ return scope.savepoint !== void 0;
84237
+ }
84238
+ function currentScope(scope) {
84239
+ return scope.mergedInto ? currentScope(scope.mergedInto) : scope;
84240
+ }
84241
+ function createCommitInterruption() {
84242
+ let interruptCommit;
84243
+ const commitInterrupted = new Promise((resolve) => {
84244
+ interruptCommit = resolve;
84245
+ });
84246
+ return { commitInterrupted, interruptCommit };
84247
+ }
84225
84248
  function trackStartingTransaction() {
84226
84249
  let markSettled;
84227
84250
  const settled = new Promise((resolve) => {
@@ -84301,16 +84324,9 @@ var TransactionManager = class {
84301
84324
  `Transaction missing underlying driver transaction when starting a nested transaction.`
84302
84325
  );
84303
84326
  }
84304
- existing.depth += 1;
84305
84327
  const savepointName = this.#nextSavepointName(existing);
84306
- existing.savepoints.push(savepointName);
84307
- try {
84308
- await this.#requiredCreateSavepoint(existing.transaction)(savepointName);
84309
- } catch (e2) {
84310
- existing.depth -= 1;
84311
- existing.savepoints.pop();
84312
- throw e2;
84313
- }
84328
+ await this.#requiredCreateSavepoint(existing.transaction)(savepointName);
84329
+ existing.scopes.push(createScope(savepointName));
84314
84330
  return { id: existing.id };
84315
84331
  });
84316
84332
  }
@@ -84327,9 +84343,9 @@ var TransactionManager = class {
84327
84343
  startedAt: Date.now(),
84328
84344
  transaction: void 0,
84329
84345
  operationQueue: Promise.resolve(),
84330
- depth: 1,
84331
- savepoints: [],
84332
- savepointCounter: 0
84346
+ savepointCounter: 0,
84347
+ scopes: [createScope(void 0)],
84348
+ ...createCommitInterruption()
84333
84349
  };
84334
84350
  if (abortController.signal.aborted) {
84335
84351
  throw new TransactionStartTimeoutError();
@@ -84404,43 +84420,38 @@ var TransactionManager = class {
84404
84420
  async commitTransaction(transactionId) {
84405
84421
  return await this.tracingHelper.runInChildSpan("commit_transaction", async () => {
84406
84422
  await this.#withActiveTransactionLock(transactionId, "commit", async (txw) => {
84407
- if (txw.depth > 1) {
84423
+ const scope = innermostScope(txw);
84424
+ if (isNested(scope)) {
84408
84425
  if (!txw.transaction) throw new TransactionNotFoundError();
84409
- const savepointName = txw.savepoints.at(-1);
84410
- if (!savepointName) {
84411
- throw new TransactionInternalConsistencyError(
84412
- `Missing savepoint for nested commit. Depth: ${txw.depth}, transactionId: ${txw.id}`
84413
- );
84426
+ const outcome2 = await statementsSettledOrCommitInterrupted(txw, [...scope.runningStatements]);
84427
+ if (outcome2 !== "committed") {
84428
+ await this.#closeTransaction(txw, outcome2);
84429
+ throw closedTransactionError(txw, outcome2, "commit");
84414
84430
  }
84415
84431
  try {
84416
- await this.#releaseSavepoint(txw.transaction, savepointName);
84432
+ await this.#releaseSavepoint(txw.transaction, scope.savepoint);
84417
84433
  } finally {
84418
- txw.savepoints.pop();
84419
- txw.depth -= 1;
84434
+ mergeInnermostScope(txw);
84420
84435
  }
84421
84436
  return;
84422
84437
  }
84423
- await this.#closeTransaction(txw, "committed");
84438
+ const outcome = await this.#closeTransaction(txw, "committed");
84439
+ if (outcome !== "committed") throw closedTransactionError(txw, outcome, "commit");
84424
84440
  });
84425
84441
  });
84426
84442
  }
84427
84443
  async rollbackTransaction(transactionId) {
84428
84444
  return await this.tracingHelper.runInChildSpan("rollback_transaction", async () => {
84429
84445
  await this.#withActiveTransactionLock(transactionId, "rollback", async (txw) => {
84430
- if (txw.depth > 1) {
84431
- if (!txw.transaction) throw new TransactionNotFoundError();
84432
- const savepointName = txw.savepoints.at(-1);
84433
- if (!savepointName) {
84434
- throw new TransactionInternalConsistencyError(
84435
- `Missing savepoint for nested rollback. Depth: ${txw.depth}, transactionId: ${txw.id}`
84436
- );
84437
- }
84446
+ const scope = innermostScope(txw);
84447
+ if (isNested(scope)) {
84438
84448
  try {
84439
- await this.#requiredRollbackToSavepoint(txw.transaction)(savepointName);
84440
- await this.#releaseSavepoint(txw.transaction, savepointName);
84449
+ await this.#closeScopes(txw, [scope], "nested_rolled_back");
84450
+ if (!txw.transaction) throw new TransactionNotFoundError();
84451
+ await this.#requiredRollbackToSavepoint(txw.transaction)(scope.savepoint);
84452
+ await this.#releaseSavepoint(txw.transaction, scope.savepoint);
84441
84453
  } finally {
84442
- txw.savepoints.pop();
84443
- txw.depth -= 1;
84454
+ popRolledBackScope(txw);
84444
84455
  }
84445
84456
  return;
84446
84457
  }
@@ -84448,14 +84459,68 @@ var TransactionManager = class {
84448
84459
  });
84449
84460
  });
84450
84461
  }
84451
- async getTransaction(txInfo, operation) {
84452
- let tx = this.#getActiveOrClosingTransaction(txInfo.id, operation);
84453
- if (tx.status === "closing") {
84454
- await tx.closing;
84455
- tx = this.#getActiveOrClosingTransaction(txInfo.id, operation);
84456
- }
84462
+ /**
84463
+ * Returns a handle for running statements in the transaction. The handle rejects every
84464
+ * statement issued after the transaction has started to close, or after the nested transaction
84465
+ * that is innermost now has started to roll back. A commit of that nested transaction never
84466
+ * closes the handle: it runs its statements in the enclosing transaction from then on,
84467
+ * including one issued while the commit waits to release the savepoint.
84468
+ */
84469
+ getTransaction(txInfo, operation) {
84470
+ return new Promise((resolve) => resolve(this.#issueHandle(txInfo, operation)));
84471
+ }
84472
+ #issueHandle(txInfo, operation) {
84473
+ const tx = this.#getActiveOrClosingTransaction(txInfo.id, operation);
84474
+ const scope = innermostScope(tx);
84475
+ if (scope.closingReason !== void 0) throw closedTransactionError(tx, scope.closingReason, operation);
84457
84476
  if (!tx.transaction) throw new TransactionNotFoundError();
84458
- return tx.transaction;
84477
+ return this.#guardedQueryable(tx, tx.transaction, scope, operation);
84478
+ }
84479
+ #guardedQueryable(tx, transaction, scope, operation) {
84480
+ return {
84481
+ provider: transaction.provider,
84482
+ adapterName: transaction.adapterName,
84483
+ queryRaw: (query2) => this.#runStatement(tx, scope, operation, () => transaction.queryRaw(query2)),
84484
+ executeRaw: (query2) => this.#runStatement(tx, scope, operation, () => transaction.executeRaw(query2))
84485
+ };
84486
+ }
84487
+ async #runStatement(tx, issuedIn, operation, execute) {
84488
+ const scope = currentScope(issuedIn);
84489
+ if (scope.closingReason !== void 0) {
84490
+ throw closedTransactionError(tx, scope.closingReason, operation);
84491
+ }
84492
+ let markSettled;
84493
+ const settled = new Promise((resolve) => {
84494
+ markSettled = resolve;
84495
+ });
84496
+ scope.runningStatements.add(settled);
84497
+ try {
84498
+ return await execute();
84499
+ } finally {
84500
+ currentScope(issuedIn).runningStatements.delete(settled);
84501
+ markSettled();
84502
+ }
84503
+ }
84504
+ /**
84505
+ * Stops `scopes` from accepting statements, then waits for the ones already running. A commit
84506
+ * waits until they settle or the timeout or a disconnect interrupts it, and then becomes a
84507
+ * rollback. A rollback waits at most {@link ROLLBACK_GRACE_MS}. Resolves with how the
84508
+ * transaction is to be closed.
84509
+ */
84510
+ async #closeScopes(tx, scopes, reason) {
84511
+ markClosing(scopes, reason);
84512
+ const running = scopes.flatMap((scope) => [...scope.runningStatements]);
84513
+ if (running.length === 0) return reason;
84514
+ let outcome = reason;
84515
+ if (reason === "committed") {
84516
+ outcome = await statementsSettledOrCommitInterrupted(tx, running);
84517
+ if (outcome === "committed") return outcome;
84518
+ markClosing(scopes, outcome);
84519
+ }
84520
+ const allSettled = Promise.all(running).then(() => {
84521
+ });
84522
+ await settleWithin(allSettled, ROLLBACK_GRACE_MS);
84523
+ return outcome;
84459
84524
  }
84460
84525
  #getActiveOrClosingTransaction(transactionId, operation) {
84461
84526
  const transaction = this.transactions.get(transactionId);
@@ -84468,15 +84533,8 @@ var TransactionManager = class {
84468
84533
  case "waiting":
84469
84534
  case "running":
84470
84535
  throw new TransactionInternalConsistencyError("Active transaction found in closed transactions list.");
84471
- case "committed":
84472
- throw new TransactionClosedError(operation);
84473
- case "rolled_back":
84474
- throw new TransactionRolledBackError(operation);
84475
- case "timed_out":
84476
- throw new TransactionExecutionTimeoutError(operation, {
84477
- timeout: closedTransaction.timeout,
84478
- timeTaken: Date.now() - closedTransaction.startedAt
84479
- });
84536
+ default:
84537
+ throw closedTransactionError(closedTransaction, closedTransaction.status, operation);
84480
84538
  }
84481
84539
  } else {
84482
84540
  debug22(`Transaction not found.`, transactionId);
@@ -84493,6 +84551,9 @@ var TransactionManager = class {
84493
84551
  for (const { abortController } of starting) {
84494
84552
  abortController.abort();
84495
84553
  }
84554
+ for (const tx of this.transactions.values()) {
84555
+ tx.interruptCommit("rolled_back");
84556
+ }
84496
84557
  await Promise.allSettled([
84497
84558
  ...[...this.transactions.values()].map(
84498
84559
  (tx) => this.#runSerialized(tx, async () => {
@@ -84502,7 +84563,7 @@ var TransactionManager = class {
84502
84563
  }
84503
84564
  })
84504
84565
  ),
84505
- ...starting.map(({ settled }) => settleWithin(settled, CANCEL_ROLLBACK_GRACE_MS))
84566
+ ...starting.map(({ settled }) => settleWithin(settled, ROLLBACK_GRACE_MS))
84506
84567
  ]);
84507
84568
  }
84508
84569
  #nextSavepointName(transaction) {
@@ -84542,6 +84603,7 @@ var TransactionManager = class {
84542
84603
  this.#debugTransactionAlreadyClosedOnTimeout(transactionId);
84543
84604
  return;
84544
84605
  }
84606
+ tx.interruptCommit("timed_out");
84545
84607
  await this.#runSerialized(tx, async () => {
84546
84608
  const current = this.transactions.get(transactionId);
84547
84609
  if (current && ["running", "waiting"].includes(current.status)) {
@@ -84558,7 +84620,7 @@ var TransactionManager = class {
84558
84620
  return timer;
84559
84621
  }
84560
84622
  // Any operation that mutates or closes a transaction must run through this lock so
84561
- // status/savepoint/depth checks and updates happen against a stable view of state.
84623
+ // status/scope checks and updates happen against a stable view of state.
84562
84624
  async #withActiveTransactionLock(transactionId, operation, callback) {
84563
84625
  const tx = this.#getActiveOrClosingTransaction(transactionId, operation);
84564
84626
  return await this.#runSerialized(tx, async () => {
@@ -84567,7 +84629,7 @@ var TransactionManager = class {
84567
84629
  });
84568
84630
  }
84569
84631
  // Serializes operations per transaction id to prevent interleaving across awaits.
84570
- // This avoids races where one operation mutates savepoint/depth state while another
84632
+ // This avoids races where one operation mutates scope state while another
84571
84633
  // operation is suspended, which could otherwise corrupt cleanup logic.
84572
84634
  async #runSerialized(tx, callback) {
84573
84635
  const previousOperation = tx.operationQueue;
@@ -84582,11 +84644,13 @@ var TransactionManager = class {
84582
84644
  releaseOperationLock();
84583
84645
  }
84584
84646
  }
84585
- async #closeTransaction(tx, status) {
84586
- const createClosingPromise = async () => {
84587
- debug22("Closing transaction.", { transactionId: tx.id, status });
84647
+ /** Resolves with how the transaction was closed, which differs from `requested` for an interrupted commit. */
84648
+ async #closeTransaction(tx, requested) {
84649
+ const createClosingPromise = async (scopesClosed2) => {
84650
+ debug22("Closing transaction.", { transactionId: tx.id, requested });
84651
+ const outcome = await scopesClosed2;
84588
84652
  try {
84589
- if (tx.transaction && status === "committed") {
84653
+ if (tx.transaction && outcome === "committed") {
84590
84654
  if (tx.transaction.options.usePhantomQuery) {
84591
84655
  await this.#withQuerySpanAndEvent(PHANTOM_COMMIT_QUERY(), tx.transaction, () => tx.transaction.commit());
84592
84656
  } else {
@@ -84616,7 +84680,7 @@ var TransactionManager = class {
84616
84680
  }
84617
84681
  }
84618
84682
  } finally {
84619
- tx.status = status;
84683
+ tx.status = outcome;
84620
84684
  clearTimeout(tx.timer);
84621
84685
  tx.timer = void 0;
84622
84686
  this.transactions.delete(tx.id);
@@ -84625,17 +84689,18 @@ var TransactionManager = class {
84625
84689
  this.closedTransactions.shift();
84626
84690
  }
84627
84691
  }
84692
+ return outcome;
84628
84693
  };
84629
84694
  if (tx.status === "closing") {
84630
84695
  await tx.closing;
84631
- this.#getActiveOrClosingTransaction(tx.id, status === "committed" ? "commit" : "rollback");
84632
- } else {
84633
- await Object.assign(tx, {
84634
- status: "closing",
84635
- reason: status,
84636
- closing: createClosingPromise()
84637
- }).closing;
84696
+ this.#getActiveOrClosingTransaction(tx.id, requested === "committed" ? "commit" : "rollback");
84697
+ throw new TransactionInternalConsistencyError("Transaction still active after it was closed.");
84638
84698
  }
84699
+ const scopesClosed = this.#closeScopes(tx, tx.scopes, requested);
84700
+ return await Object.assign(tx, {
84701
+ status: "closing",
84702
+ closing: createClosingPromise(scopesClosed)
84703
+ }).closing;
84639
84704
  }
84640
84705
  #validateOptions(options) {
84641
84706
  if (!options.timeout) throw new TransactionManagerError("timeout is required");
@@ -84657,6 +84722,56 @@ var TransactionManager = class {
84657
84722
  });
84658
84723
  }
84659
84724
  };
84725
+ function innermostScope(tx) {
84726
+ return tx.scopes[tx.scopes.length - 1];
84727
+ }
84728
+ function popInnermostScope(tx) {
84729
+ const child = innermostScope(tx);
84730
+ tx.scopes.pop();
84731
+ const parent = innermostScope(tx);
84732
+ const moved = [...child.runningStatements];
84733
+ for (const statement of moved) {
84734
+ parent.runningStatements.add(statement);
84735
+ }
84736
+ child.runningStatements.clear();
84737
+ return { child, parent, moved };
84738
+ }
84739
+ function mergeInnermostScope(tx) {
84740
+ const { child, parent } = popInnermostScope(tx);
84741
+ child.mergedInto = parent;
84742
+ }
84743
+ function popRolledBackScope(tx) {
84744
+ const { parent, moved } = popInnermostScope(tx);
84745
+ for (const statement of moved) {
84746
+ void statement.then(() => currentScope(parent).runningStatements.delete(statement));
84747
+ }
84748
+ }
84749
+ function markClosing(scopes, reason) {
84750
+ for (const scope of scopes) {
84751
+ scope.closingReason = reason;
84752
+ }
84753
+ }
84754
+ async function statementsSettledOrCommitInterrupted(tx, running) {
84755
+ if (running.length === 0) return "committed";
84756
+ return await Promise.race([Promise.all(running).then(() => "committed"), tx.commitInterrupted]);
84757
+ }
84758
+ function closedTransactionError(tx, reason, operation) {
84759
+ switch (reason) {
84760
+ case "committed":
84761
+ return new TransactionClosedError(operation);
84762
+ case "rolled_back":
84763
+ return new TransactionRolledBackError(operation);
84764
+ case "nested_rolled_back":
84765
+ return new NestedTransactionRolledBackError(operation);
84766
+ case "timed_out":
84767
+ return new TransactionExecutionTimeoutError(operation, {
84768
+ timeout: tx.timeout,
84769
+ timeTaken: Date.now() - tx.startedAt
84770
+ });
84771
+ default:
84772
+ return assertNever(reason, "Unknown closing reason.");
84773
+ }
84774
+ }
84660
84775
  function createTimeoutIfDefined(cb, ms) {
84661
84776
  return ms !== void 0 ? setTimeout(cb, ms) : void 0;
84662
84777
  }
@@ -102701,36 +102816,62 @@ var MariaDbTransaction = class extends MariaDbQueryable {
102701
102816
  this.options = options;
102702
102817
  this.cleanup = cleanup;
102703
102818
  }
102819
+ /**
102820
+ * Set on entry to `commit()` or `rollback()`, before either sends SQL. Once the pool has lent the
102821
+ * connection to a new owner, a second close would send `COMMIT` or `ROLLBACK` into that owner's
102822
+ * session and release the connection twice, so the transaction closes at most once and sends
102823
+ * nothing afterwards.
102824
+ */
102825
+ closed = false;
102826
+ async performIO(query2) {
102827
+ this.assertOpen();
102828
+ return await super.performIO(query2);
102829
+ }
102704
102830
  async commit() {
102705
102831
  debug4(`[js::commit]`);
102706
- try {
102707
- await this.client.query({ sql: "COMMIT" });
102708
- } catch (err) {
102709
- this.onError(err);
102710
- } finally {
102711
- this.cleanup?.();
102712
- await releaseConnection(this.client);
102713
- }
102832
+ await this.close("COMMIT");
102714
102833
  }
102715
102834
  async rollback() {
102716
102835
  debug4(`[js::rollback]`);
102836
+ await this.close("ROLLBACK");
102837
+ }
102838
+ async createSavepoint(name22) {
102839
+ await this.sendTransactionControl(`SAVEPOINT ${name22}`);
102840
+ }
102841
+ async rollbackToSavepoint(name22) {
102842
+ await this.sendTransactionControl(`ROLLBACK TO ${name22}`);
102843
+ }
102844
+ async releaseSavepoint(name22) {
102845
+ await this.sendTransactionControl(`RELEASE SAVEPOINT ${name22}`);
102846
+ }
102847
+ async close(sql4) {
102848
+ if (this.closed) {
102849
+ return;
102850
+ }
102851
+ this.closed = true;
102717
102852
  try {
102718
- await this.client.query({ sql: "ROLLBACK" });
102853
+ await this.client.query({ sql: sql4 });
102719
102854
  } catch (err) {
102720
102855
  this.onError(err);
102721
102856
  } finally {
102722
- this.cleanup?.();
102723
- await releaseConnection(this.client);
102857
+ try {
102858
+ this.cleanup?.();
102859
+ } finally {
102860
+ await releaseConnection(this.client);
102861
+ }
102724
102862
  }
102725
102863
  }
102726
- async createSavepoint(name22) {
102727
- await this.client.query({ sql: `SAVEPOINT ${name22}` }).catch(this.onError.bind(this));
102728
- }
102729
- async rollbackToSavepoint(name22) {
102730
- await this.client.query({ sql: `ROLLBACK TO ${name22}` }).catch(this.onError.bind(this));
102864
+ async sendTransactionControl(sql4) {
102865
+ this.assertOpen();
102866
+ await this.client.query({ sql: sql4 }).catch(this.onError.bind(this));
102731
102867
  }
102732
- async releaseSavepoint(name22) {
102733
- await this.client.query({ sql: `RELEASE SAVEPOINT ${name22}` }).catch(this.onError.bind(this));
102868
+ assertOpen() {
102869
+ if (this.closed) {
102870
+ throw new DriverAdapterError({
102871
+ kind: "TransactionAlreadyClosed",
102872
+ cause: "The transaction has already been committed or rolled back"
102873
+ });
102874
+ }
102734
102875
  }
102735
102876
  };
102736
102877
  var PrismaMariaDbAdapter = class extends MariaDbQueryable {
@@ -104577,15 +104718,50 @@ var PgTransaction = class extends PgQueryable {
104577
104718
  this.pgOptions = pgOptions;
104578
104719
  this.cleanup = cleanup;
104579
104720
  }
104721
+ closed = false;
104722
+ runningStatements = 0;
104723
+ async performIO(query2) {
104724
+ if (this.closed) {
104725
+ throw new DriverAdapterError({
104726
+ kind: "TransactionAlreadyClosed",
104727
+ cause: "The transaction has already been committed or rolled back"
104728
+ });
104729
+ }
104730
+ this.runningStatements++;
104731
+ try {
104732
+ return await super.performIO(query2);
104733
+ } finally {
104734
+ this.runningStatements--;
104735
+ }
104736
+ }
104737
+ /**
104738
+ * Closes the transaction at most once. Once the pool has lent the client to
104739
+ * a new owner, a second `release()` would corrupt the pool's bookkeeping, so
104740
+ * it is skipped. A client with a statement still running is released with an
104741
+ * error so the pool destroys it instead of lending out a busy connection.
104742
+ */
104743
+ close() {
104744
+ if (this.closed) {
104745
+ return;
104746
+ }
104747
+ this.closed = true;
104748
+ try {
104749
+ this.cleanup?.();
104750
+ } finally {
104751
+ if (this.runningStatements > 0) {
104752
+ this.client.release(new Error("Transaction closed with a statement still running"));
104753
+ } else {
104754
+ this.client.release();
104755
+ }
104756
+ }
104757
+ }
104580
104758
  async commit() {
104581
104759
  debug6(`[js::commit]`);
104582
- this.cleanup?.();
104583
- this.client.release();
104760
+ this.close();
104584
104761
  }
104585
104762
  async rollback() {
104586
104763
  debug6(`[js::rollback]`);
104587
- this.cleanup?.();
104588
- this.client.release();
104764
+ this.close();
104589
104765
  }
104590
104766
  async createSavepoint(name22) {
104591
104767
  await this.executeRaw({ sql: `SAVEPOINT ${name22}`, args: [], argTypes: [] });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/query-plan-executor",
3
- "version": "8.1.0-dev.10",
3
+ "version": "8.1.0-dev.12",
4
4
  "description": "This package is intended for Prisma's internal use",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,11 +19,11 @@
19
19
  "hono": "^4.12.23",
20
20
  "temporal-polyfill": "0.3.0",
21
21
  "zod": "4.1.3",
22
- "@prisma/adapter-pg": "8.1.0-dev.10",
23
- "@prisma/adapter-mssql": "8.1.0-dev.10",
24
- "@prisma/driver-adapter-utils": "8.1.0-dev.10",
25
- "@prisma/adapter-mariadb": "8.1.0-dev.10",
26
- "@prisma/client-engine-runtime": "8.1.0-dev.10"
22
+ "@prisma/adapter-pg": "8.1.0-dev.12",
23
+ "@prisma/client-engine-runtime": "8.1.0-dev.12",
24
+ "@prisma/driver-adapter-utils": "8.1.0-dev.12",
25
+ "@prisma/adapter-mssql": "8.1.0-dev.12",
26
+ "@prisma/adapter-mariadb": "8.1.0-dev.12"
27
27
  },
28
28
  "files": [
29
29
  "dist"