@prisma/query-plan-executor 7.10.0-dev.37 → 7.10.0-dev.39

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.
Files changed (2) hide show
  1. package/dist/index.js +99 -65
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -92936,7 +92936,7 @@ __export(index_exports, {
92936
92936
  module.exports = __toCommonJS(index_exports);
92937
92937
 
92938
92938
  // package.json
92939
- var version = "7.10.0-dev.37";
92939
+ var version = "7.10.0-dev.39";
92940
92940
 
92941
92941
  // ../../node_modules/.pnpm/temporal-polyfill@0.3.0/node_modules/temporal-polyfill/chunks/internal.js
92942
92942
  function clampProp(e2, n2, t2, o2, r2) {
@@ -104290,6 +104290,7 @@ function getErrorCode2(error44) {
104290
104290
  assertNever(error44, `Unknown error identifier: ${error44}`);
104291
104291
  }
104292
104292
  }
104293
+ var debug3 = Debug("prisma:client:queryInterpreter");
104293
104294
  var QueryInterpreter = class _QueryInterpreter {
104294
104295
  #onQuery;
104295
104296
  #generators = new GeneratorRegistry();
@@ -104380,42 +104381,46 @@ var QueryInterpreter = class _QueryInterpreter {
104380
104381
  }
104381
104382
  case "execute": {
104382
104383
  const queries = renderQuery(node.args, context4.scope, context4.generators, this.#maxChunkSize());
104383
- let sum2 = 0;
104384
- for (const query2 of queries) {
104385
- const commentedQuery = applyComments(query2, context4.sqlCommenter);
104386
- sum2 += await this.#withQuerySpanAndEvent(
104387
- commentedQuery,
104388
- context4.queryable,
104389
- () => context4.queryable.executeRaw(cloneObject(commentedQuery)).catch(
104390
- (err) => node.args.type === "rawSql" ? rethrowAsUserFacingRawError(err) : rethrowAsUserFacing(err)
104391
- )
104392
- );
104393
- }
104394
- return { value: sum2 };
104384
+ return this.#withChunkTransaction(queries.length, context4, async (context22) => {
104385
+ let sum2 = 0;
104386
+ for (const query2 of queries) {
104387
+ const commentedQuery = applyComments(query2, context22.sqlCommenter);
104388
+ sum2 += await this.#withQuerySpanAndEvent(
104389
+ commentedQuery,
104390
+ context22.queryable,
104391
+ () => context22.queryable.executeRaw(cloneObject(commentedQuery)).catch(
104392
+ (err) => node.args.type === "rawSql" ? rethrowAsUserFacingRawError(err) : rethrowAsUserFacing(err)
104393
+ )
104394
+ );
104395
+ }
104396
+ return { value: sum2 };
104397
+ });
104395
104398
  }
104396
104399
  case "query": {
104397
104400
  const queries = renderQuery(node.args, context4.scope, context4.generators, this.#maxChunkSize());
104398
- let results;
104399
- for (const query2 of queries) {
104400
- const commentedQuery = applyComments(query2, context4.sqlCommenter);
104401
- const result = await this.#withQuerySpanAndEvent(
104402
- commentedQuery,
104403
- context4.queryable,
104404
- () => context4.queryable.queryRaw(cloneObject(commentedQuery)).catch(
104405
- (err) => node.args.type === "rawSql" ? rethrowAsUserFacingRawError(err) : rethrowAsUserFacing(err)
104406
- )
104407
- );
104408
- if (results === void 0) {
104409
- results = result;
104410
- } else {
104411
- appendToArray(results.rows, result.rows);
104412
- results.lastInsertId = result.lastInsertId;
104401
+ return this.#withChunkTransaction(queries.length, context4, async (context22) => {
104402
+ let results;
104403
+ for (const query2 of queries) {
104404
+ const commentedQuery = applyComments(query2, context22.sqlCommenter);
104405
+ const result = await this.#withQuerySpanAndEvent(
104406
+ commentedQuery,
104407
+ context22.queryable,
104408
+ () => context22.queryable.queryRaw(cloneObject(commentedQuery)).catch(
104409
+ (err) => node.args.type === "rawSql" ? rethrowAsUserFacingRawError(err) : rethrowAsUserFacing(err)
104410
+ )
104411
+ );
104412
+ if (results === void 0) {
104413
+ results = result;
104414
+ } else {
104415
+ appendToArray(results.rows, result.rows);
104416
+ results.lastInsertId = result.lastInsertId;
104417
+ }
104413
104418
  }
104414
- }
104415
- return {
104416
- value: node.args.type === "rawSql" ? this.#rawSerializer(results) : this.#serializer(results),
104417
- lastInsertId: results?.lastInsertId
104418
- };
104419
+ return {
104420
+ value: node.args.type === "rawSql" ? this.#rawSerializer(results) : this.#serializer(results),
104421
+ lastInsertId: results?.lastInsertId
104422
+ };
104423
+ });
104419
104424
  }
104420
104425
  case "reverse": {
104421
104426
  const { value, lastInsertId } = await this.interpretNode(node.args, context4);
@@ -104456,20 +104461,7 @@ var QueryInterpreter = class _QueryInterpreter {
104456
104461
  return { value: attachChildrenToParents(parent, children, node.args.canAssumeStrictEquality), lastInsertId };
104457
104462
  }
104458
104463
  case "transaction": {
104459
- if (!context4.transactionManager.enabled) {
104460
- return this.interpretNode(node.args, context4);
104461
- }
104462
- const transactionManager = context4.transactionManager.manager;
104463
- const transactionInfo = await transactionManager.startInternalTransaction();
104464
- const transaction = await transactionManager.getTransaction(transactionInfo, "query");
104465
- try {
104466
- const value = await this.interpretNode(node.args, { ...context4, queryable: transaction });
104467
- await transactionManager.commitTransaction(transactionInfo.id);
104468
- return value;
104469
- } catch (e2) {
104470
- await transactionManager.rollbackTransaction(transactionInfo.id);
104471
- throw e2;
104472
- }
104464
+ return this.#withInternalTransaction(context4, (context22) => this.interpretNode(node.args, context22));
104473
104465
  }
104474
104466
  case "dataMap": {
104475
104467
  const { value, lastInsertId } = await this.interpretNode(node.args.expr, context4);
@@ -104654,6 +104646,48 @@ var QueryInterpreter = class _QueryInterpreter {
104654
104646
  assertNever(node, `Unexpected node type: ${node.type}`);
104655
104647
  }
104656
104648
  }
104649
+ /**
104650
+ * Runs the statements of a `query` or `execute` node via `fn`, wrapping them in a
104651
+ * transaction when a chunkable statement was split into multiple queries at render time,
104652
+ * so that a partially applied write cannot be observed or left behind if a later chunk
104653
+ * fails. A single statement is atomic on its own, so it runs on the current context.
104654
+ */
104655
+ #withChunkTransaction(statementCount, context4, fn2) {
104656
+ if (statementCount <= 1) {
104657
+ return fn2(context4);
104658
+ }
104659
+ return this.#withInternalTransaction(context4, fn2);
104660
+ }
104661
+ /**
104662
+ * Runs `fn` with a context whose queryable is guaranteed to be a transaction, starting a
104663
+ * new internal transaction and committing or rolling it back around the call.
104664
+ *
104665
+ * A disabled transaction manager means the queryable already is a transaction: executors
104666
+ * pass `{ enabled: false }` when the plan runs inside an interactive transaction, and the
104667
+ * context handed to `fn` carries it for the duration of an internal transaction. In that
104668
+ * case `fn` runs on the current context, since the statements it issues are already
104669
+ * covered by the surrounding transaction.
104670
+ */
104671
+ async #withInternalTransaction(context4, fn2) {
104672
+ if (!context4.transactionManager.enabled) {
104673
+ return fn2(context4);
104674
+ }
104675
+ const transactionManager = context4.transactionManager.manager;
104676
+ const transactionInfo = await transactionManager.startInternalTransaction();
104677
+ const transaction = await transactionManager.getTransaction(transactionInfo, "query");
104678
+ try {
104679
+ const result = await fn2({ ...context4, queryable: transaction, transactionManager: { enabled: false } });
104680
+ await transactionManager.commitTransaction(transactionInfo.id);
104681
+ return result;
104682
+ } catch (e2) {
104683
+ try {
104684
+ await transactionManager.rollbackTransaction(transactionInfo.id);
104685
+ } catch (rollbackError) {
104686
+ debug3("failed to roll back an internal transaction", rollbackError);
104687
+ }
104688
+ throw e2;
104689
+ }
104690
+ }
104657
104691
  #maxChunkSize() {
104658
104692
  if (this.#connectionInfo?.maxBindValues !== void 0) {
104659
104693
  return this.#connectionInfo.maxBindValues;
@@ -105032,7 +105066,7 @@ function trackStartingTransaction() {
105032
105066
  });
105033
105067
  return { abortController: new AbortController(), settled, markSettled };
105034
105068
  }
105035
- var debug3 = Debug("prisma:client:transactionManager");
105069
+ var debug22 = Debug("prisma:client:transactionManager");
105036
105070
  var COMMIT_QUERY = () => ({ sql: "COMMIT", args: [], argTypes: [] });
105037
105071
  var ROLLBACK_QUERY = () => ({ sql: "ROLLBACK", args: [], argTypes: [] });
105038
105072
  var PHANTOM_COMMIT_QUERY = () => ({
@@ -105201,7 +105235,7 @@ var TransactionManager = class {
105201
105235
  }
105202
105236
  }
105203
105237
  } catch (e2) {
105204
- debug3("error in discarded transaction:", e2);
105238
+ debug22("error in discarded transaction:", e2);
105205
105239
  }
105206
105240
  }
105207
105241
  async commitTransaction(transactionId) {
@@ -105265,7 +105299,7 @@ var TransactionManager = class {
105265
105299
  if (!transaction) {
105266
105300
  const closedTransaction = this.closedTransactions.find((tx) => tx.id === transactionId);
105267
105301
  if (closedTransaction) {
105268
- debug3("Transaction already closed.", { transactionId, status: closedTransaction.status });
105302
+ debug22("Transaction already closed.", { transactionId, status: closedTransaction.status });
105269
105303
  switch (closedTransaction.status) {
105270
105304
  case "closing":
105271
105305
  case "waiting":
@@ -105282,7 +105316,7 @@ var TransactionManager = class {
105282
105316
  });
105283
105317
  }
105284
105318
  } else {
105285
- debug3(`Transaction not found.`, transactionId);
105319
+ debug22(`Transaction not found.`, transactionId);
105286
105320
  throw new TransactionNotFoundError();
105287
105321
  }
105288
105322
  }
@@ -105333,13 +105367,13 @@ var TransactionManager = class {
105333
105367
  }
105334
105368
  }
105335
105369
  #debugTransactionAlreadyClosedOnTimeout(transactionId) {
105336
- debug3("Transaction already committed or rolled back when timeout happened.", transactionId);
105370
+ debug22("Transaction already committed or rolled back when timeout happened.", transactionId);
105337
105371
  }
105338
105372
  #startTransactionTimeout(transactionId, timeout) {
105339
105373
  const timeoutStartedAt = Date.now();
105340
105374
  const timer = createTimeoutIfDefined(async () => {
105341
105375
  try {
105342
- debug3("Transaction timed out.", { transactionId, timeoutStartedAt, timeout });
105376
+ debug22("Transaction timed out.", { transactionId, timeoutStartedAt, timeout });
105343
105377
  const tx = this.transactions.get(transactionId);
105344
105378
  if (!tx) {
105345
105379
  this.#debugTransactionAlreadyClosedOnTimeout(transactionId);
@@ -105354,7 +105388,7 @@ var TransactionManager = class {
105354
105388
  }
105355
105389
  });
105356
105390
  } catch (error44) {
105357
- debug3("Error while closing timed-out transaction.", { transactionId, error: error44 });
105391
+ debug22("Error while closing timed-out transaction.", { transactionId, error: error44 });
105358
105392
  }
105359
105393
  }, timeout);
105360
105394
  timer?.unref?.();
@@ -105387,7 +105421,7 @@ var TransactionManager = class {
105387
105421
  }
105388
105422
  async #closeTransaction(tx, status) {
105389
105423
  const createClosingPromise = async () => {
105390
- debug3("Closing transaction.", { transactionId: tx.id, status });
105424
+ debug22("Closing transaction.", { transactionId: tx.id, status });
105391
105425
  try {
105392
105426
  if (tx.transaction && status === "committed") {
105393
105427
  if (tx.transaction.options.usePhantomQuery) {
@@ -108997,7 +109031,7 @@ function mapDriverError2(error44) {
108997
109031
  function isDriverError2(error44) {
108998
109032
  return typeof error44.message === "string" && typeof error44.code === "string" && typeof error44.number === "number";
108999
109033
  }
109000
- var debug22 = Debug("prisma:driver-adapter:mssql");
109034
+ var debug23 = Debug("prisma:driver-adapter:mssql");
109001
109035
  var MssqlQueryable = class {
109002
109036
  constructor(conn) {
109003
109037
  this.conn = conn;
@@ -109006,7 +109040,7 @@ var MssqlQueryable = class {
109006
109040
  adapterName = name4;
109007
109041
  async queryRaw(query2) {
109008
109042
  const tag2 = "[js::query_raw]";
109009
- debug22(`${tag2} %O`, query2);
109043
+ debug23(`${tag2} %O`, query2);
109010
109044
  const { recordset, columns: columnsList } = await this.performIO(query2);
109011
109045
  const columns = columnsList?.[0];
109012
109046
  return {
@@ -109017,7 +109051,7 @@ var MssqlQueryable = class {
109017
109051
  }
109018
109052
  async executeRaw(query2) {
109019
109053
  const tag2 = "[js::execute_raw]";
109020
- debug22(`${tag2} %O`, query2);
109054
+ debug23(`${tag2} %O`, query2);
109021
109055
  return (await this.performIO(query2)).rowsAffected?.[0] ?? 0;
109022
109056
  }
109023
109057
  async performIO(query2) {
@@ -109039,7 +109073,7 @@ var MssqlQueryable = class {
109039
109073
  }
109040
109074
  }
109041
109075
  onError(error44) {
109042
- debug22("Error in performIO: %O", error44);
109076
+ debug23("Error in performIO: %O", error44);
109043
109077
  throw new DriverAdapterError(convertDriverError2(error44));
109044
109078
  }
109045
109079
  };
@@ -109061,7 +109095,7 @@ var MssqlTransaction = class extends MssqlQueryable {
109061
109095
  }
109062
109096
  }
109063
109097
  async commit() {
109064
- debug22(`[js::commit]`);
109098
+ debug23(`[js::commit]`);
109065
109099
  const release = await this.#mutex.acquire();
109066
109100
  try {
109067
109101
  await this.transaction.commit();
@@ -109070,12 +109104,12 @@ var MssqlTransaction = class extends MssqlQueryable {
109070
109104
  }
109071
109105
  }
109072
109106
  async rollback() {
109073
- debug22(`[js::rollback]`);
109107
+ debug23(`[js::rollback]`);
109074
109108
  const release = await this.#mutex.acquire();
109075
109109
  try {
109076
109110
  await this.transaction.rollback().catch((e2) => {
109077
109111
  if (e2.code === "EABORT") {
109078
- debug22(`[js::rollback] Transaction already aborted`);
109112
+ debug23(`[js::rollback] Transaction already aborted`);
109079
109113
  return;
109080
109114
  }
109081
109115
  throw e2;
@@ -109105,10 +109139,10 @@ var PrismaMssqlAdapter = class extends MssqlQueryable {
109105
109139
  usePhantomQuery: true
109106
109140
  };
109107
109141
  const tag2 = "[js::startTransaction]";
109108
- debug22("%s options: %O", tag2, options);
109142
+ debug23("%s options: %O", tag2, options);
109109
109143
  const tx = this.pool.transaction();
109110
109144
  tx.on("error", (err) => {
109111
- debug22("Error from pool connection: %O", err);
109145
+ debug23("Error from pool connection: %O", err);
109112
109146
  this.options?.onConnectionError?.(err);
109113
109147
  });
109114
109148
  try {
@@ -109153,7 +109187,7 @@ var PrismaMssqlAdapterFactory = class {
109153
109187
  async connect() {
109154
109188
  const pool2 = new import_mssql.default.ConnectionPool(this.#config);
109155
109189
  pool2.on("error", (err) => {
109156
- debug22("Error from pool client: %O", err);
109190
+ debug23("Error from pool client: %O", err);
109157
109191
  this.#options?.onPoolError?.(err);
109158
109192
  });
109159
109193
  await pool2.connect();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/query-plan-executor",
3
- "version": "7.10.0-dev.37",
3
+ "version": "7.10.0-dev.39",
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": "7.10.0-dev.37",
23
- "@prisma/adapter-mariadb": "7.10.0-dev.37",
24
- "@prisma/adapter-mssql": "7.10.0-dev.37",
25
- "@prisma/client-engine-runtime": "7.10.0-dev.37",
26
- "@prisma/driver-adapter-utils": "7.10.0-dev.37"
22
+ "@prisma/adapter-pg": "7.10.0-dev.39",
23
+ "@prisma/adapter-mariadb": "7.10.0-dev.39",
24
+ "@prisma/adapter-mssql": "7.10.0-dev.39",
25
+ "@prisma/client-engine-runtime": "7.10.0-dev.39",
26
+ "@prisma/driver-adapter-utils": "7.10.0-dev.39"
27
27
  },
28
28
  "files": [
29
29
  "dist"