@prisma/client-engine-runtime 6.6.0-dev.6 → 6.6.0-dev.61

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.
@@ -0,0 +1 @@
1
+ export declare function randomUUID(): Promise<string>;
package/dist/index.d.mts CHANGED
@@ -1,14 +1,7 @@
1
- import { ErrorCapturingSqlConnection } from '@prisma/driver-adapter-utils';
2
- import { ErrorCapturingSqlQueryable } from '@prisma/driver-adapter-utils';
3
- import { ErrorCapturingTransaction } from '@prisma/driver-adapter-utils';
4
-
5
- export declare const enum IsolationLevel {
6
- ReadUncommitted = "ReadUncommitted",
7
- ReadCommitted = "ReadCommitted",
8
- RepeatableRead = "RepeatableRead",
9
- Snapshot = "Snapshot",
10
- Serializable = "Serializable"
11
- }
1
+ import type { IsolationLevel } from '@prisma/driver-adapter-utils';
2
+ import { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
3
+ import { SqlQueryable } from '@prisma/driver-adapter-utils';
4
+ import { Transaction } from '@prisma/driver-adapter-utils';
12
5
 
13
6
  export declare function isPrismaValuePlaceholder(value: unknown): value is PrismaValuePlaceholder;
14
7
 
@@ -43,7 +36,7 @@ export declare class QueryInterpreter {
43
36
  }
44
37
 
45
38
  export declare type QueryInterpreterOptions = {
46
- queryable: ErrorCapturingSqlQueryable;
39
+ queryable: SqlQueryable;
47
40
  placeholderValues: Record<string, unknown>;
48
41
  onQuery?: (event: QueryEvent) => void;
49
42
  };
@@ -121,18 +114,17 @@ export declare class TransactionManager {
121
114
  private closedTransactions;
122
115
  private readonly driverAdapter;
123
116
  constructor({ driverAdapter }: {
124
- driverAdapter: ErrorCapturingSqlConnection;
117
+ driverAdapter: SqlDriverAdapter;
125
118
  });
126
119
  startTransaction(options: TransactionOptions): Promise<TransactionInfo>;
127
120
  commitTransaction(transactionId: string): Promise<void>;
128
121
  rollbackTransaction(transactionId: string): Promise<void>;
129
- getTransaction(txInfo: TransactionInfo, operation: string): ErrorCapturingTransaction;
122
+ getTransaction(txInfo: TransactionInfo, operation: string): Transaction;
130
123
  private getActiveTransaction;
131
124
  cancelAllTransactions(): Promise<void>;
132
125
  private startTransactionTimeout;
133
126
  private closeTransaction;
134
127
  private validateOptions;
135
- private requiresSettingIsolationLevelFirst;
136
128
  }
137
129
 
138
130
  export declare class TransactionManagerError extends Error {
package/dist/index.d.ts CHANGED
@@ -1,14 +1,7 @@
1
- import { ErrorCapturingSqlConnection } from '@prisma/driver-adapter-utils';
2
- import { ErrorCapturingSqlQueryable } from '@prisma/driver-adapter-utils';
3
- import { ErrorCapturingTransaction } from '@prisma/driver-adapter-utils';
4
-
5
- export declare const enum IsolationLevel {
6
- ReadUncommitted = "ReadUncommitted",
7
- ReadCommitted = "ReadCommitted",
8
- RepeatableRead = "RepeatableRead",
9
- Snapshot = "Snapshot",
10
- Serializable = "Serializable"
11
- }
1
+ import type { IsolationLevel } from '@prisma/driver-adapter-utils';
2
+ import { SqlDriverAdapter } from '@prisma/driver-adapter-utils';
3
+ import { SqlQueryable } from '@prisma/driver-adapter-utils';
4
+ import { Transaction } from '@prisma/driver-adapter-utils';
12
5
 
13
6
  export declare function isPrismaValuePlaceholder(value: unknown): value is PrismaValuePlaceholder;
14
7
 
@@ -43,7 +36,7 @@ export declare class QueryInterpreter {
43
36
  }
44
37
 
45
38
  export declare type QueryInterpreterOptions = {
46
- queryable: ErrorCapturingSqlQueryable;
39
+ queryable: SqlQueryable;
47
40
  placeholderValues: Record<string, unknown>;
48
41
  onQuery?: (event: QueryEvent) => void;
49
42
  };
@@ -121,18 +114,17 @@ export declare class TransactionManager {
121
114
  private closedTransactions;
122
115
  private readonly driverAdapter;
123
116
  constructor({ driverAdapter }: {
124
- driverAdapter: ErrorCapturingSqlConnection;
117
+ driverAdapter: SqlDriverAdapter;
125
118
  });
126
119
  startTransaction(options: TransactionOptions): Promise<TransactionInfo>;
127
120
  commitTransaction(transactionId: string): Promise<void>;
128
121
  rollbackTransaction(transactionId: string): Promise<void>;
129
- getTransaction(txInfo: TransactionInfo, operation: string): ErrorCapturingTransaction;
122
+ getTransaction(txInfo: TransactionInfo, operation: string): Transaction;
130
123
  private getActiveTransaction;
131
124
  cancelAllTransactions(): Promise<void>;
132
125
  private startTransactionTimeout;
133
126
  private closeTransaction;
134
127
  private validateOptions;
135
- private requiresSettingIsolationLevelFirst;
136
128
  }
137
129
 
138
130
  export declare class TransactionManagerError extends Error {
package/dist/index.js CHANGED
@@ -5,10 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __typeError = (msg) => {
9
- throw TypeError(msg);
10
- };
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
8
  var __export = (target, all) => {
13
9
  for (var name in all)
14
10
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -30,17 +26,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
26
  mod
31
27
  ));
32
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
34
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
35
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
36
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
37
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
38
- var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
39
29
 
40
30
  // src/index.ts
41
31
  var index_exports = {};
42
32
  __export(index_exports, {
43
- IsolationLevel: () => IsolationLevel,
44
33
  QueryInterpreter: () => QueryInterpreter,
45
34
  TransactionManager: () => TransactionManager,
46
35
  TransactionManagerError: () => TransactionManagerError,
@@ -236,19 +225,17 @@ function serialize(resultSet) {
236
225
  }
237
226
 
238
227
  // src/interpreter/QueryInterpreter.ts
239
- var _queryable, _placeholderValues, _onQuery, _QueryInterpreter_instances, withQueryEvent_fn;
240
228
  var QueryInterpreter = class {
229
+ #queryable;
230
+ #placeholderValues;
231
+ #onQuery;
241
232
  constructor({ queryable, placeholderValues, onQuery }) {
242
- __privateAdd(this, _QueryInterpreter_instances);
243
- __privateAdd(this, _queryable);
244
- __privateAdd(this, _placeholderValues);
245
- __privateAdd(this, _onQuery);
246
- __privateSet(this, _queryable, queryable);
247
- __privateSet(this, _placeholderValues, placeholderValues);
248
- __privateSet(this, _onQuery, onQuery);
233
+ this.#queryable = queryable;
234
+ this.#placeholderValues = placeholderValues;
235
+ this.#onQuery = onQuery;
249
236
  }
250
237
  async run(queryPlan) {
251
- return this.interpretNode(queryPlan, __privateGet(this, _placeholderValues));
238
+ return this.interpretNode(queryPlan, this.#placeholderValues);
252
239
  }
253
240
  async interpretNode(node, scope) {
254
241
  switch (node.type) {
@@ -287,24 +274,14 @@ var QueryInterpreter = class {
287
274
  }
288
275
  case "execute": {
289
276
  const query = renderQuery(node.args, scope);
290
- return __privateMethod(this, _QueryInterpreter_instances, withQueryEvent_fn).call(this, query, async () => {
291
- const result = await __privateGet(this, _queryable).executeRaw(query);
292
- if (result.ok) {
293
- return result.value;
294
- } else {
295
- throw result.error;
296
- }
277
+ return this.#withQueryEvent(query, async () => {
278
+ return await this.#queryable.executeRaw(query);
297
279
  });
298
280
  }
299
281
  case "query": {
300
282
  const query = renderQuery(node.args, scope);
301
- return __privateMethod(this, _QueryInterpreter_instances, withQueryEvent_fn).call(this, query, async () => {
302
- const result = await __privateGet(this, _queryable).queryRaw(query);
303
- if (result.ok) {
304
- return serialize(result.value);
305
- } else {
306
- throw result.error;
307
- }
283
+ return this.#withQueryEvent(query, async () => {
284
+ return serialize(await this.#queryable.queryRaw(query));
308
285
  });
309
286
  }
310
287
  case "reverse": {
@@ -354,24 +331,19 @@ var QueryInterpreter = class {
354
331
  }
355
332
  }
356
333
  }
357
- };
358
- _queryable = new WeakMap();
359
- _placeholderValues = new WeakMap();
360
- _onQuery = new WeakMap();
361
- _QueryInterpreter_instances = new WeakSet();
362
- withQueryEvent_fn = async function(query, execute) {
363
- var _a;
364
- const timestamp = /* @__PURE__ */ new Date();
365
- const startInstant = performance.now();
366
- const result = await execute();
367
- const endInstant = performance.now();
368
- (_a = __privateGet(this, _onQuery)) == null ? void 0 : _a.call(this, {
369
- timestamp,
370
- duration: endInstant - startInstant,
371
- query: query.sql,
372
- params: query.args
373
- });
374
- return result;
334
+ async #withQueryEvent(query, execute) {
335
+ const timestamp = /* @__PURE__ */ new Date();
336
+ const startInstant = performance.now();
337
+ const result = await execute();
338
+ const endInstant = performance.now();
339
+ this.#onQuery?.({
340
+ timestamp,
341
+ duration: endInstant - startInstant,
342
+ query: query.sql,
343
+ params: query.args
344
+ });
345
+ return result;
346
+ }
375
347
  };
376
348
  function isEmpty(value) {
377
349
  if (Array.isArray(value)) {
@@ -429,19 +401,18 @@ function childRecordMatchesParent(childRecord, parentRecord, joinExpr) {
429
401
  return true;
430
402
  }
431
403
 
432
- // src/transactionManager/Transaction.ts
433
- var IsolationLevel = /* @__PURE__ */ ((IsolationLevel2) => {
434
- IsolationLevel2["ReadUncommitted"] = "ReadUncommitted";
435
- IsolationLevel2["ReadCommitted"] = "ReadCommitted";
436
- IsolationLevel2["RepeatableRead"] = "RepeatableRead";
437
- IsolationLevel2["Snapshot"] = "Snapshot";
438
- IsolationLevel2["Serializable"] = "Serializable";
439
- return IsolationLevel2;
440
- })(IsolationLevel || {});
441
-
442
404
  // src/transactionManager/TransactionManager.ts
443
405
  var import_debug = __toESM(require("@prisma/debug"));
444
406
 
407
+ // src/crypto.ts
408
+ async function getCrypto() {
409
+ return globalThis.crypto ?? await import("node:crypto");
410
+ }
411
+ async function randomUUID() {
412
+ const crypto = await getCrypto();
413
+ return crypto.randomUUID();
414
+ }
415
+
445
416
  // src/utils.ts
446
417
  function assertNever(_, message) {
447
418
  throw new Error(message);
@@ -452,8 +423,8 @@ var TransactionManagerError = class extends Error {
452
423
  constructor(message, meta) {
453
424
  super("Transaction API error: " + message);
454
425
  this.meta = meta;
455
- __publicField(this, "code", "P2028");
456
426
  }
427
+ code = "P2028";
457
428
  };
458
429
  var TransactionDriverAdapterError = class extends TransactionManagerError {
459
430
  constructor(message, errorParams) {
@@ -503,35 +474,23 @@ var InvalidTransactionIsolationLevelError = class extends TransactionManagerErro
503
474
 
504
475
  // src/transactionManager/TransactionManager.ts
505
476
  var MAX_CLOSED_TRANSACTIONS = 100;
506
- var isolationLevelMap = {
507
- ReadUncommitted: "READ UNCOMMITTED",
508
- ReadCommitted: "READ COMMITTED",
509
- RepeatableRead: "REPEATABLE READ",
510
- Snapshot: "SNAPSHOT",
511
- Serializable: "SERIALIZABLE"
512
- };
513
477
  var debug = (0, import_debug.default)("prisma:client:transactionManager");
514
478
  var COMMIT_QUERY = () => ({ sql: "COMMIT", args: [], argTypes: [] });
515
479
  var ROLLBACK_QUERY = () => ({ sql: "ROLLBACK", args: [], argTypes: [] });
516
- var ISOLATION_LEVEL_QUERY = (isolationLevel) => ({
517
- sql: "SET TRANSACTION ISOLATION LEVEL " + isolationLevelMap[isolationLevel],
518
- args: [],
519
- argTypes: []
520
- });
521
480
  var TransactionManager = class {
481
+ // The map of active transactions.
482
+ transactions = /* @__PURE__ */ new Map();
483
+ // List of last closed transactions. Max MAX_CLOSED_TRANSACTIONS entries.
484
+ // Used to provide better error messages than a generic "transaction not found".
485
+ closedTransactions = [];
486
+ driverAdapter;
522
487
  constructor({ driverAdapter }) {
523
- // The map of active transactions.
524
- __publicField(this, "transactions", /* @__PURE__ */ new Map());
525
- // List of last closed transactions. Max MAX_CLOSED_TRANSACTIONS entries.
526
- // Used to provide better error messages than a generic "transaction not found".
527
- __publicField(this, "closedTransactions", []);
528
- __publicField(this, "driverAdapter");
529
488
  this.driverAdapter = driverAdapter;
530
489
  }
531
490
  async startTransaction(options) {
532
491
  const validatedOptions = this.validateOptions(options);
533
492
  const transaction = {
534
- id: globalThis.crypto.randomUUID(),
493
+ id: await randomUUID(),
535
494
  status: "waiting",
536
495
  timer: void 0,
537
496
  timeout: validatedOptions.timeout,
@@ -540,28 +499,17 @@ var TransactionManager = class {
540
499
  };
541
500
  this.transactions.set(transaction.id, transaction);
542
501
  transaction.timer = this.startTransactionTimeout(transaction.id, validatedOptions.maxWait);
543
- const txContext = await this.driverAdapter.transactionContext();
544
- if (!txContext.ok)
502
+ let startedTransaction;
503
+ try {
504
+ startedTransaction = await this.driverAdapter.startTransaction(validatedOptions.isolationLevel);
505
+ } catch (error) {
545
506
  throw new TransactionDriverAdapterError("Failed to start transaction.", {
546
- driverAdapterError: txContext.error
507
+ driverAdapterError: error
547
508
  });
548
- if (this.requiresSettingIsolationLevelFirst() && validatedOptions.isolationLevel) {
549
- await txContext.value.executeRaw(ISOLATION_LEVEL_QUERY(validatedOptions.isolationLevel));
550
- }
551
- const startedTransaction = await txContext.value.startTransaction();
552
- if (!startedTransaction.ok)
553
- throw new TransactionDriverAdapterError("Failed to start transaction.", {
554
- driverAdapterError: startedTransaction.error
555
- });
556
- if (!startedTransaction.value.options.usePhantomQuery) {
557
- await startedTransaction.value.executeRaw({ sql: "BEGIN", args: [], argTypes: [] });
558
- if (!this.requiresSettingIsolationLevelFirst() && validatedOptions.isolationLevel) {
559
- await txContext.value.executeRaw(ISOLATION_LEVEL_QUERY(validatedOptions.isolationLevel));
560
- }
561
509
  }
562
510
  switch (transaction.status) {
563
511
  case "waiting":
564
- transaction.transaction = startedTransaction.value;
512
+ transaction.transaction = startedTransaction;
565
513
  clearTimeout(transaction.timer);
566
514
  transaction.timer = void 0;
567
515
  transaction.status = "running";
@@ -641,20 +589,24 @@ var TransactionManager = class {
641
589
  debug("Closing transaction.", { transactionId: tx.id, status });
642
590
  tx.status = status;
643
591
  if (tx.transaction && status === "committed") {
644
- const result = await tx.transaction.commit();
645
- if (!result.ok)
592
+ try {
593
+ await tx.transaction.commit();
594
+ } catch (error) {
646
595
  throw new TransactionDriverAdapterError("Failed to commit transaction.", {
647
- driverAdapterError: result.error
596
+ driverAdapterError: error
648
597
  });
598
+ }
649
599
  if (!tx.transaction.options.usePhantomQuery) {
650
600
  await tx.transaction.executeRaw(COMMIT_QUERY());
651
601
  }
652
602
  } else if (tx.transaction) {
653
- const result = await tx.transaction.rollback();
654
- if (!result.ok)
603
+ try {
604
+ await tx.transaction.rollback();
605
+ } catch (error) {
655
606
  throw new TransactionDriverAdapterError("Failed to rollback transaction.", {
656
- driverAdapterError: result.error
607
+ driverAdapterError: error
657
608
  });
609
+ }
658
610
  if (!tx.transaction.options.usePhantomQuery) {
659
611
  await tx.transaction.executeRaw(ROLLBACK_QUERY());
660
612
  }
@@ -670,23 +622,16 @@ var TransactionManager = class {
670
622
  validateOptions(options) {
671
623
  if (!options.timeout) throw new TransactionManagerError("timeout is required");
672
624
  if (!options.maxWait) throw new TransactionManagerError("maxWait is required");
673
- if (options.isolationLevel === "Snapshot" /* Snapshot */)
674
- throw new InvalidTransactionIsolationLevelError(options.isolationLevel);
675
- if (this.driverAdapter.provider === "sqlite" && options.isolationLevel && options.isolationLevel !== "Serializable" /* Serializable */)
676
- throw new InvalidTransactionIsolationLevelError(options.isolationLevel);
625
+ if (options.isolationLevel === "SNAPSHOT") throw new InvalidTransactionIsolationLevelError(options.isolationLevel);
677
626
  return {
678
627
  ...options,
679
628
  timeout: options.timeout,
680
629
  maxWait: options.maxWait
681
630
  };
682
631
  }
683
- requiresSettingIsolationLevelFirst() {
684
- return this.driverAdapter.provider === "mysql";
685
- }
686
632
  };
687
633
  // Annotate the CommonJS export names for ESM import in node:
688
634
  0 && (module.exports = {
689
- IsolationLevel,
690
635
  QueryInterpreter,
691
636
  TransactionManager,
692
637
  TransactionManagerError,
package/dist/index.mjs CHANGED
@@ -1,15 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __typeError = (msg) => {
3
- throw TypeError(msg);
4
- };
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
8
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
9
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
10
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
11
- var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
12
-
13
1
  // src/QueryPlan.ts
14
2
  function isPrismaValuePlaceholder(value) {
15
3
  return typeof value === "object" && value !== null && value["prisma__type"] === "param";
@@ -198,19 +186,17 @@ function serialize(resultSet) {
198
186
  }
199
187
 
200
188
  // src/interpreter/QueryInterpreter.ts
201
- var _queryable, _placeholderValues, _onQuery, _QueryInterpreter_instances, withQueryEvent_fn;
202
189
  var QueryInterpreter = class {
190
+ #queryable;
191
+ #placeholderValues;
192
+ #onQuery;
203
193
  constructor({ queryable, placeholderValues, onQuery }) {
204
- __privateAdd(this, _QueryInterpreter_instances);
205
- __privateAdd(this, _queryable);
206
- __privateAdd(this, _placeholderValues);
207
- __privateAdd(this, _onQuery);
208
- __privateSet(this, _queryable, queryable);
209
- __privateSet(this, _placeholderValues, placeholderValues);
210
- __privateSet(this, _onQuery, onQuery);
194
+ this.#queryable = queryable;
195
+ this.#placeholderValues = placeholderValues;
196
+ this.#onQuery = onQuery;
211
197
  }
212
198
  async run(queryPlan) {
213
- return this.interpretNode(queryPlan, __privateGet(this, _placeholderValues));
199
+ return this.interpretNode(queryPlan, this.#placeholderValues);
214
200
  }
215
201
  async interpretNode(node, scope) {
216
202
  switch (node.type) {
@@ -249,24 +235,14 @@ var QueryInterpreter = class {
249
235
  }
250
236
  case "execute": {
251
237
  const query = renderQuery(node.args, scope);
252
- return __privateMethod(this, _QueryInterpreter_instances, withQueryEvent_fn).call(this, query, async () => {
253
- const result = await __privateGet(this, _queryable).executeRaw(query);
254
- if (result.ok) {
255
- return result.value;
256
- } else {
257
- throw result.error;
258
- }
238
+ return this.#withQueryEvent(query, async () => {
239
+ return await this.#queryable.executeRaw(query);
259
240
  });
260
241
  }
261
242
  case "query": {
262
243
  const query = renderQuery(node.args, scope);
263
- return __privateMethod(this, _QueryInterpreter_instances, withQueryEvent_fn).call(this, query, async () => {
264
- const result = await __privateGet(this, _queryable).queryRaw(query);
265
- if (result.ok) {
266
- return serialize(result.value);
267
- } else {
268
- throw result.error;
269
- }
244
+ return this.#withQueryEvent(query, async () => {
245
+ return serialize(await this.#queryable.queryRaw(query));
270
246
  });
271
247
  }
272
248
  case "reverse": {
@@ -316,24 +292,19 @@ var QueryInterpreter = class {
316
292
  }
317
293
  }
318
294
  }
319
- };
320
- _queryable = new WeakMap();
321
- _placeholderValues = new WeakMap();
322
- _onQuery = new WeakMap();
323
- _QueryInterpreter_instances = new WeakSet();
324
- withQueryEvent_fn = async function(query, execute) {
325
- var _a;
326
- const timestamp = /* @__PURE__ */ new Date();
327
- const startInstant = performance.now();
328
- const result = await execute();
329
- const endInstant = performance.now();
330
- (_a = __privateGet(this, _onQuery)) == null ? void 0 : _a.call(this, {
331
- timestamp,
332
- duration: endInstant - startInstant,
333
- query: query.sql,
334
- params: query.args
335
- });
336
- return result;
295
+ async #withQueryEvent(query, execute) {
296
+ const timestamp = /* @__PURE__ */ new Date();
297
+ const startInstant = performance.now();
298
+ const result = await execute();
299
+ const endInstant = performance.now();
300
+ this.#onQuery?.({
301
+ timestamp,
302
+ duration: endInstant - startInstant,
303
+ query: query.sql,
304
+ params: query.args
305
+ });
306
+ return result;
307
+ }
337
308
  };
338
309
  function isEmpty(value) {
339
310
  if (Array.isArray(value)) {
@@ -391,19 +362,18 @@ function childRecordMatchesParent(childRecord, parentRecord, joinExpr) {
391
362
  return true;
392
363
  }
393
364
 
394
- // src/transactionManager/Transaction.ts
395
- var IsolationLevel = /* @__PURE__ */ ((IsolationLevel2) => {
396
- IsolationLevel2["ReadUncommitted"] = "ReadUncommitted";
397
- IsolationLevel2["ReadCommitted"] = "ReadCommitted";
398
- IsolationLevel2["RepeatableRead"] = "RepeatableRead";
399
- IsolationLevel2["Snapshot"] = "Snapshot";
400
- IsolationLevel2["Serializable"] = "Serializable";
401
- return IsolationLevel2;
402
- })(IsolationLevel || {});
403
-
404
365
  // src/transactionManager/TransactionManager.ts
405
366
  import Debug from "@prisma/debug";
406
367
 
368
+ // src/crypto.ts
369
+ async function getCrypto() {
370
+ return globalThis.crypto ?? await import("node:crypto");
371
+ }
372
+ async function randomUUID() {
373
+ const crypto = await getCrypto();
374
+ return crypto.randomUUID();
375
+ }
376
+
407
377
  // src/utils.ts
408
378
  function assertNever(_, message) {
409
379
  throw new Error(message);
@@ -414,8 +384,8 @@ var TransactionManagerError = class extends Error {
414
384
  constructor(message, meta) {
415
385
  super("Transaction API error: " + message);
416
386
  this.meta = meta;
417
- __publicField(this, "code", "P2028");
418
387
  }
388
+ code = "P2028";
419
389
  };
420
390
  var TransactionDriverAdapterError = class extends TransactionManagerError {
421
391
  constructor(message, errorParams) {
@@ -465,35 +435,23 @@ var InvalidTransactionIsolationLevelError = class extends TransactionManagerErro
465
435
 
466
436
  // src/transactionManager/TransactionManager.ts
467
437
  var MAX_CLOSED_TRANSACTIONS = 100;
468
- var isolationLevelMap = {
469
- ReadUncommitted: "READ UNCOMMITTED",
470
- ReadCommitted: "READ COMMITTED",
471
- RepeatableRead: "REPEATABLE READ",
472
- Snapshot: "SNAPSHOT",
473
- Serializable: "SERIALIZABLE"
474
- };
475
438
  var debug = Debug("prisma:client:transactionManager");
476
439
  var COMMIT_QUERY = () => ({ sql: "COMMIT", args: [], argTypes: [] });
477
440
  var ROLLBACK_QUERY = () => ({ sql: "ROLLBACK", args: [], argTypes: [] });
478
- var ISOLATION_LEVEL_QUERY = (isolationLevel) => ({
479
- sql: "SET TRANSACTION ISOLATION LEVEL " + isolationLevelMap[isolationLevel],
480
- args: [],
481
- argTypes: []
482
- });
483
441
  var TransactionManager = class {
442
+ // The map of active transactions.
443
+ transactions = /* @__PURE__ */ new Map();
444
+ // List of last closed transactions. Max MAX_CLOSED_TRANSACTIONS entries.
445
+ // Used to provide better error messages than a generic "transaction not found".
446
+ closedTransactions = [];
447
+ driverAdapter;
484
448
  constructor({ driverAdapter }) {
485
- // The map of active transactions.
486
- __publicField(this, "transactions", /* @__PURE__ */ new Map());
487
- // List of last closed transactions. Max MAX_CLOSED_TRANSACTIONS entries.
488
- // Used to provide better error messages than a generic "transaction not found".
489
- __publicField(this, "closedTransactions", []);
490
- __publicField(this, "driverAdapter");
491
449
  this.driverAdapter = driverAdapter;
492
450
  }
493
451
  async startTransaction(options) {
494
452
  const validatedOptions = this.validateOptions(options);
495
453
  const transaction = {
496
- id: globalThis.crypto.randomUUID(),
454
+ id: await randomUUID(),
497
455
  status: "waiting",
498
456
  timer: void 0,
499
457
  timeout: validatedOptions.timeout,
@@ -502,28 +460,17 @@ var TransactionManager = class {
502
460
  };
503
461
  this.transactions.set(transaction.id, transaction);
504
462
  transaction.timer = this.startTransactionTimeout(transaction.id, validatedOptions.maxWait);
505
- const txContext = await this.driverAdapter.transactionContext();
506
- if (!txContext.ok)
463
+ let startedTransaction;
464
+ try {
465
+ startedTransaction = await this.driverAdapter.startTransaction(validatedOptions.isolationLevel);
466
+ } catch (error) {
507
467
  throw new TransactionDriverAdapterError("Failed to start transaction.", {
508
- driverAdapterError: txContext.error
468
+ driverAdapterError: error
509
469
  });
510
- if (this.requiresSettingIsolationLevelFirst() && validatedOptions.isolationLevel) {
511
- await txContext.value.executeRaw(ISOLATION_LEVEL_QUERY(validatedOptions.isolationLevel));
512
- }
513
- const startedTransaction = await txContext.value.startTransaction();
514
- if (!startedTransaction.ok)
515
- throw new TransactionDriverAdapterError("Failed to start transaction.", {
516
- driverAdapterError: startedTransaction.error
517
- });
518
- if (!startedTransaction.value.options.usePhantomQuery) {
519
- await startedTransaction.value.executeRaw({ sql: "BEGIN", args: [], argTypes: [] });
520
- if (!this.requiresSettingIsolationLevelFirst() && validatedOptions.isolationLevel) {
521
- await txContext.value.executeRaw(ISOLATION_LEVEL_QUERY(validatedOptions.isolationLevel));
522
- }
523
470
  }
524
471
  switch (transaction.status) {
525
472
  case "waiting":
526
- transaction.transaction = startedTransaction.value;
473
+ transaction.transaction = startedTransaction;
527
474
  clearTimeout(transaction.timer);
528
475
  transaction.timer = void 0;
529
476
  transaction.status = "running";
@@ -603,20 +550,24 @@ var TransactionManager = class {
603
550
  debug("Closing transaction.", { transactionId: tx.id, status });
604
551
  tx.status = status;
605
552
  if (tx.transaction && status === "committed") {
606
- const result = await tx.transaction.commit();
607
- if (!result.ok)
553
+ try {
554
+ await tx.transaction.commit();
555
+ } catch (error) {
608
556
  throw new TransactionDriverAdapterError("Failed to commit transaction.", {
609
- driverAdapterError: result.error
557
+ driverAdapterError: error
610
558
  });
559
+ }
611
560
  if (!tx.transaction.options.usePhantomQuery) {
612
561
  await tx.transaction.executeRaw(COMMIT_QUERY());
613
562
  }
614
563
  } else if (tx.transaction) {
615
- const result = await tx.transaction.rollback();
616
- if (!result.ok)
564
+ try {
565
+ await tx.transaction.rollback();
566
+ } catch (error) {
617
567
  throw new TransactionDriverAdapterError("Failed to rollback transaction.", {
618
- driverAdapterError: result.error
568
+ driverAdapterError: error
619
569
  });
570
+ }
620
571
  if (!tx.transaction.options.usePhantomQuery) {
621
572
  await tx.transaction.executeRaw(ROLLBACK_QUERY());
622
573
  }
@@ -632,22 +583,15 @@ var TransactionManager = class {
632
583
  validateOptions(options) {
633
584
  if (!options.timeout) throw new TransactionManagerError("timeout is required");
634
585
  if (!options.maxWait) throw new TransactionManagerError("maxWait is required");
635
- if (options.isolationLevel === "Snapshot" /* Snapshot */)
636
- throw new InvalidTransactionIsolationLevelError(options.isolationLevel);
637
- if (this.driverAdapter.provider === "sqlite" && options.isolationLevel && options.isolationLevel !== "Serializable" /* Serializable */)
638
- throw new InvalidTransactionIsolationLevelError(options.isolationLevel);
586
+ if (options.isolationLevel === "SNAPSHOT") throw new InvalidTransactionIsolationLevelError(options.isolationLevel);
639
587
  return {
640
588
  ...options,
641
589
  timeout: options.timeout,
642
590
  maxWait: options.maxWait
643
591
  };
644
592
  }
645
- requiresSettingIsolationLevelFirst() {
646
- return this.driverAdapter.provider === "mysql";
647
- }
648
593
  };
649
594
  export {
650
- IsolationLevel,
651
595
  QueryInterpreter,
652
596
  TransactionManager,
653
597
  TransactionManagerError,
@@ -1,8 +1,8 @@
1
- import { ErrorCapturingSqlQueryable } from '@prisma/driver-adapter-utils';
1
+ import { SqlQueryable } from '@prisma/driver-adapter-utils';
2
2
  import { QueryEvent } from '../events';
3
3
  import { QueryPlanNode } from '../QueryPlan';
4
4
  export type QueryInterpreterOptions = {
5
- queryable: ErrorCapturingSqlQueryable;
5
+ queryable: SqlQueryable;
6
6
  placeholderValues: Record<string, unknown>;
7
7
  onQuery?: (event: QueryEvent) => void;
8
8
  };
@@ -1,10 +1,4 @@
1
- export declare const enum IsolationLevel {
2
- ReadUncommitted = "ReadUncommitted",
3
- ReadCommitted = "ReadCommitted",
4
- RepeatableRead = "RepeatableRead",
5
- Snapshot = "Snapshot",
6
- Serializable = "Serializable"
7
- }
1
+ import type { IsolationLevel } from '@prisma/driver-adapter-utils';
8
2
  export type Options = {
9
3
  maxWait?: number;
10
4
  timeout?: number;
@@ -1,20 +1,19 @@
1
- import { ErrorCapturingSqlConnection, ErrorCapturingTransaction } from '@prisma/driver-adapter-utils';
1
+ import { SqlDriverAdapter, Transaction } from '@prisma/driver-adapter-utils';
2
2
  import { Options, TransactionInfo } from './Transaction';
3
3
  export declare class TransactionManager {
4
4
  private transactions;
5
5
  private closedTransactions;
6
6
  private readonly driverAdapter;
7
7
  constructor({ driverAdapter }: {
8
- driverAdapter: ErrorCapturingSqlConnection;
8
+ driverAdapter: SqlDriverAdapter;
9
9
  });
10
10
  startTransaction(options: Options): Promise<TransactionInfo>;
11
11
  commitTransaction(transactionId: string): Promise<void>;
12
12
  rollbackTransaction(transactionId: string): Promise<void>;
13
- getTransaction(txInfo: TransactionInfo, operation: string): ErrorCapturingTransaction;
13
+ getTransaction(txInfo: TransactionInfo, operation: string): Transaction;
14
14
  private getActiveTransaction;
15
15
  cancelAllTransactions(): Promise<void>;
16
16
  private startTransactionTimeout;
17
17
  private closeTransaction;
18
18
  private validateOptions;
19
- private requiresSettingIsolationLevelFirst;
20
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/client-engine-runtime",
3
- "version": "6.6.0-dev.6",
3
+ "version": "6.6.0-dev.61",
4
4
  "description": "This package is intended for Prisma's internal use",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -20,12 +20,12 @@
20
20
  "repository": {
21
21
  "type": "git",
22
22
  "url": "https://github.com/prisma/prisma.git",
23
- "directory": "packages/accelerate-contract"
23
+ "directory": "packages/client-engine-runtime"
24
24
  },
25
25
  "license": "Apache-2.0",
26
26
  "dependencies": {
27
- "@prisma/debug": "6.6.0-dev.6",
28
- "@prisma/driver-adapter-utils": "6.6.0-dev.6"
27
+ "@prisma/debug": "6.6.0-dev.61",
28
+ "@prisma/driver-adapter-utils": "6.6.0-dev.61"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/jest": "29.5.14",