@prisma/client-engine-runtime 6.4.0-dev.48 → 6.4.0-dev.50
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/QueryPlan.d.ts +75 -0
- package/dist/events.d.ts +6 -0
- package/dist/index.d.mts +21 -213
- package/dist/index.d.ts +21 -213
- package/dist/index.js +100 -310
- package/dist/index.mjs +652 -0
- package/dist/interpreter/QueryInterpreter.d.ts +14 -0
- package/dist/interpreter/renderQuery.d.ts +4 -0
- package/dist/interpreter/renderQueryTemplate.d.ts +10 -0
- package/dist/interpreter/renderQueryTemplate.test.d.ts +1 -0
- package/dist/interpreter/scope.d.ts +13 -0
- package/dist/interpreter/serialize.d.ts +2 -0
- package/dist/interpreter/serialize.test.d.ts +1 -0
- package/dist/transactionManager/Transaction.d.ts +15 -0
- package/dist/transactionManager/TransactionManager.d.ts +20 -0
- package/dist/transactionManager/TransactionManager.test.d.ts +1 -0
- package/dist/transactionManager/TransactionManagerErrors.d.ts +35 -0
- package/dist/utils.d.ts +1 -0
- package/package.json +26 -4
package/dist/index.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
1
3
|
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
2
8
|
var __typeError = (msg) => {
|
|
3
9
|
throw TypeError(msg);
|
|
4
10
|
};
|
|
@@ -6,28 +12,46 @@ var __export = (target, all) => {
|
|
|
6
12
|
for (var name in all)
|
|
7
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
14
|
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
9
32
|
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
10
33
|
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
11
34
|
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);
|
|
12
35
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
13
36
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
14
37
|
|
|
15
|
-
// src/
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
})
|
|
38
|
+
// src/index.ts
|
|
39
|
+
var index_exports = {};
|
|
40
|
+
__export(index_exports, {
|
|
41
|
+
IsolationLevel: () => IsolationLevel,
|
|
42
|
+
QueryInterpreter: () => QueryInterpreter,
|
|
43
|
+
TransactionManager: () => TransactionManager,
|
|
44
|
+
TransactionManagerError: () => TransactionManagerError,
|
|
45
|
+
isPrismaValuePlaceholder: () => isPrismaValuePlaceholder
|
|
46
|
+
});
|
|
47
|
+
module.exports = __toCommonJS(index_exports);
|
|
24
48
|
|
|
25
|
-
// src/
|
|
49
|
+
// src/QueryPlan.ts
|
|
26
50
|
function isPrismaValuePlaceholder(value) {
|
|
27
51
|
return typeof value === "object" && value !== null && value["prisma__type"] === "param";
|
|
28
52
|
}
|
|
29
53
|
|
|
30
|
-
// src/
|
|
54
|
+
// src/interpreter/renderQueryTemplate.ts
|
|
31
55
|
var BEGIN_REPEAT = "/* prisma-comma-repeatable-start */";
|
|
32
56
|
var END_REPEAT = "/* prisma-comma-repeatable-end */";
|
|
33
57
|
function renderQueryTemplate({
|
|
@@ -125,7 +149,7 @@ function renderQueryTemplate({
|
|
|
125
149
|
};
|
|
126
150
|
}
|
|
127
151
|
|
|
128
|
-
// src/
|
|
152
|
+
// src/interpreter/renderQuery.ts
|
|
129
153
|
function renderQuery({ query, params }, scope) {
|
|
130
154
|
const substitutedParams = params.map((param) => {
|
|
131
155
|
if (!isPrismaValuePlaceholder(param)) {
|
|
@@ -187,7 +211,7 @@ function placeholderTypeToArgType(type) {
|
|
|
187
211
|
return mappedType;
|
|
188
212
|
}
|
|
189
213
|
|
|
190
|
-
// src/
|
|
214
|
+
// src/interpreter/serialize.ts
|
|
191
215
|
function serialize(resultSet) {
|
|
192
216
|
return resultSet.rows.map(
|
|
193
217
|
(row) => row.reduce((acc, value, index) => {
|
|
@@ -209,7 +233,7 @@ function serialize(resultSet) {
|
|
|
209
233
|
);
|
|
210
234
|
}
|
|
211
235
|
|
|
212
|
-
// src/
|
|
236
|
+
// src/interpreter/QueryInterpreter.ts
|
|
213
237
|
var _queryable, _placeholderValues, _onQuery, _QueryInterpreter_instances, withQueryEvent_fn;
|
|
214
238
|
var QueryInterpreter = class {
|
|
215
239
|
constructor({ queryable, placeholderValues, onQuery }) {
|
|
@@ -343,16 +367,7 @@ withQueryEvent_fn = async function(query, execute) {
|
|
|
343
367
|
timestamp,
|
|
344
368
|
duration: endInstant - startInstant,
|
|
345
369
|
query: query.sql,
|
|
346
|
-
|
|
347
|
-
params: JSON.stringify(query.args),
|
|
348
|
-
// TODO: this field only exists for historical reasons as we grandfathered it from the time
|
|
349
|
-
// when we emitted `tracing` events to stdout in the engine unchanged, and then described
|
|
350
|
-
// them in the public API as TS types. Thus this field used to contain the name of the Rust
|
|
351
|
-
// module in which an event originated. When using library engine, which uses a different
|
|
352
|
-
// mechanism with a JavaScript callback for logs, it's normally just an empty string instead.
|
|
353
|
-
// This field is definitely not useful and should be removed from the public types (but it's
|
|
354
|
-
// technically a breaking change, even if a tiny and inconsequential one).
|
|
355
|
-
target: "QueryInterpreter"
|
|
370
|
+
params: query.args
|
|
356
371
|
});
|
|
357
372
|
return result;
|
|
358
373
|
};
|
|
@@ -412,292 +427,80 @@ function childRecordMatchesParent(childRecord, parentRecord, joinExpr) {
|
|
|
412
427
|
return true;
|
|
413
428
|
}
|
|
414
429
|
|
|
415
|
-
//
|
|
416
|
-
var
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
bgRed: () => bgRed,
|
|
425
|
-
bgWhite: () => bgWhite,
|
|
426
|
-
bgYellow: () => bgYellow,
|
|
427
|
-
black: () => black,
|
|
428
|
-
blue: () => blue,
|
|
429
|
-
bold: () => bold,
|
|
430
|
-
cyan: () => cyan,
|
|
431
|
-
dim: () => dim,
|
|
432
|
-
gray: () => gray,
|
|
433
|
-
green: () => green,
|
|
434
|
-
grey: () => grey,
|
|
435
|
-
hidden: () => hidden,
|
|
436
|
-
inverse: () => inverse,
|
|
437
|
-
italic: () => italic,
|
|
438
|
-
magenta: () => magenta,
|
|
439
|
-
red: () => red,
|
|
440
|
-
reset: () => reset,
|
|
441
|
-
strikethrough: () => strikethrough,
|
|
442
|
-
underline: () => underline,
|
|
443
|
-
white: () => white,
|
|
444
|
-
yellow: () => yellow
|
|
445
|
-
});
|
|
446
|
-
var FORCE_COLOR;
|
|
447
|
-
var NODE_DISABLE_COLORS;
|
|
448
|
-
var NO_COLOR;
|
|
449
|
-
var TERM;
|
|
450
|
-
var isTTY = true;
|
|
451
|
-
if (typeof process !== "undefined") {
|
|
452
|
-
({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env || {});
|
|
453
|
-
isTTY = process.stdout && process.stdout.isTTY;
|
|
454
|
-
}
|
|
455
|
-
var $ = {
|
|
456
|
-
enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== "dumb" && (FORCE_COLOR != null && FORCE_COLOR !== "0" || isTTY)
|
|
457
|
-
};
|
|
458
|
-
function init(x, y) {
|
|
459
|
-
let rgx = new RegExp(`\\x1b\\[${y}m`, "g");
|
|
460
|
-
let open = `\x1B[${x}m`, close = `\x1B[${y}m`;
|
|
461
|
-
return function(txt) {
|
|
462
|
-
if (!$.enabled || txt == null) return txt;
|
|
463
|
-
return open + (!!~("" + txt).indexOf(close) ? txt.replace(rgx, close + open) : txt) + close;
|
|
464
|
-
};
|
|
465
|
-
}
|
|
466
|
-
var reset = init(0, 0);
|
|
467
|
-
var bold = init(1, 22);
|
|
468
|
-
var dim = init(2, 22);
|
|
469
|
-
var italic = init(3, 23);
|
|
470
|
-
var underline = init(4, 24);
|
|
471
|
-
var inverse = init(7, 27);
|
|
472
|
-
var hidden = init(8, 28);
|
|
473
|
-
var strikethrough = init(9, 29);
|
|
474
|
-
var black = init(30, 39);
|
|
475
|
-
var red = init(31, 39);
|
|
476
|
-
var green = init(32, 39);
|
|
477
|
-
var yellow = init(33, 39);
|
|
478
|
-
var blue = init(34, 39);
|
|
479
|
-
var magenta = init(35, 39);
|
|
480
|
-
var cyan = init(36, 39);
|
|
481
|
-
var white = init(37, 39);
|
|
482
|
-
var gray = init(90, 39);
|
|
483
|
-
var grey = init(90, 39);
|
|
484
|
-
var bgBlack = init(40, 49);
|
|
485
|
-
var bgRed = init(41, 49);
|
|
486
|
-
var bgGreen = init(42, 49);
|
|
487
|
-
var bgYellow = init(43, 49);
|
|
488
|
-
var bgBlue = init(44, 49);
|
|
489
|
-
var bgMagenta = init(45, 49);
|
|
490
|
-
var bgCyan = init(46, 49);
|
|
491
|
-
var bgWhite = init(47, 49);
|
|
492
|
-
|
|
493
|
-
// ../debug/src/index.ts
|
|
494
|
-
var MAX_ARGS_HISTORY = 100;
|
|
495
|
-
var COLORS = ["green", "yellow", "blue", "magenta", "cyan", "red"];
|
|
496
|
-
var argsHistory = [];
|
|
497
|
-
var lastTimestamp = Date.now();
|
|
498
|
-
var lastColor = 0;
|
|
499
|
-
var processEnv = typeof process !== "undefined" ? process.env : {};
|
|
500
|
-
globalThis.DEBUG ??= processEnv.DEBUG ?? "";
|
|
501
|
-
globalThis.DEBUG_COLORS ??= processEnv.DEBUG_COLORS ? processEnv.DEBUG_COLORS === "true" : true;
|
|
502
|
-
var topProps = {
|
|
503
|
-
enable(namespace) {
|
|
504
|
-
if (typeof namespace === "string") {
|
|
505
|
-
globalThis.DEBUG = namespace;
|
|
506
|
-
}
|
|
507
|
-
},
|
|
508
|
-
disable() {
|
|
509
|
-
const prev = globalThis.DEBUG;
|
|
510
|
-
globalThis.DEBUG = "";
|
|
511
|
-
return prev;
|
|
512
|
-
},
|
|
513
|
-
// this is the core logic to check if logging should happen or not
|
|
514
|
-
enabled(namespace) {
|
|
515
|
-
const listenedNamespaces = globalThis.DEBUG.split(",").map((s) => {
|
|
516
|
-
return s.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
|
|
517
|
-
});
|
|
518
|
-
const isListened = listenedNamespaces.some((listenedNamespace) => {
|
|
519
|
-
if (listenedNamespace === "" || listenedNamespace[0] === "-") return false;
|
|
520
|
-
return namespace.match(RegExp(listenedNamespace.split("*").join(".*") + "$"));
|
|
521
|
-
});
|
|
522
|
-
const isExcluded = listenedNamespaces.some((listenedNamespace) => {
|
|
523
|
-
if (listenedNamespace === "" || listenedNamespace[0] !== "-") return false;
|
|
524
|
-
return namespace.match(RegExp(listenedNamespace.slice(1).split("*").join(".*") + "$"));
|
|
525
|
-
});
|
|
526
|
-
return isListened && !isExcluded;
|
|
527
|
-
},
|
|
528
|
-
log: (...args) => {
|
|
529
|
-
const [namespace, format, ...rest] = args;
|
|
530
|
-
const logWithFormatting = console.warn ?? console.log;
|
|
531
|
-
logWithFormatting(`${namespace} ${format}`, ...rest);
|
|
532
|
-
},
|
|
533
|
-
formatters: {}
|
|
534
|
-
// not implemented
|
|
535
|
-
};
|
|
536
|
-
function debugCreate(namespace) {
|
|
537
|
-
const instanceProps = {
|
|
538
|
-
color: COLORS[lastColor++ % COLORS.length],
|
|
539
|
-
enabled: topProps.enabled(namespace),
|
|
540
|
-
namespace,
|
|
541
|
-
log: topProps.log,
|
|
542
|
-
extend: () => {
|
|
543
|
-
}
|
|
544
|
-
// not implemented
|
|
545
|
-
};
|
|
546
|
-
const debugCall = (...args) => {
|
|
547
|
-
const { enabled, namespace: namespace2, color, log } = instanceProps;
|
|
548
|
-
if (args.length !== 0) {
|
|
549
|
-
argsHistory.push([namespace2, ...args]);
|
|
550
|
-
}
|
|
551
|
-
if (argsHistory.length > MAX_ARGS_HISTORY) {
|
|
552
|
-
argsHistory.shift();
|
|
553
|
-
}
|
|
554
|
-
if (topProps.enabled(namespace2) || enabled) {
|
|
555
|
-
const stringArgs = args.map((arg) => {
|
|
556
|
-
if (typeof arg === "string") {
|
|
557
|
-
return arg;
|
|
558
|
-
}
|
|
559
|
-
return safeStringify(arg);
|
|
560
|
-
});
|
|
561
|
-
const ms = `+${Date.now() - lastTimestamp}ms`;
|
|
562
|
-
lastTimestamp = Date.now();
|
|
563
|
-
if (globalThis.DEBUG_COLORS) {
|
|
564
|
-
log(colors_exports[color](bold(namespace2)), ...stringArgs, colors_exports[color](ms));
|
|
565
|
-
} else {
|
|
566
|
-
log(namespace2, ...stringArgs, ms);
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
};
|
|
570
|
-
return new Proxy(debugCall, {
|
|
571
|
-
get: (_, prop) => instanceProps[prop],
|
|
572
|
-
set: (_, prop, value) => instanceProps[prop] = value
|
|
573
|
-
});
|
|
574
|
-
}
|
|
575
|
-
var Debug = new Proxy(debugCreate, {
|
|
576
|
-
get: (_, prop) => topProps[prop],
|
|
577
|
-
set: (_, prop, value) => topProps[prop] = value
|
|
578
|
-
});
|
|
579
|
-
function safeStringify(value, indent = 2) {
|
|
580
|
-
const cache = /* @__PURE__ */ new Set();
|
|
581
|
-
return JSON.stringify(
|
|
582
|
-
value,
|
|
583
|
-
(key, value2) => {
|
|
584
|
-
if (typeof value2 === "object" && value2 !== null) {
|
|
585
|
-
if (cache.has(value2)) {
|
|
586
|
-
return `[Circular *]`;
|
|
587
|
-
}
|
|
588
|
-
cache.add(value2);
|
|
589
|
-
} else if (typeof value2 === "bigint") {
|
|
590
|
-
return value2.toString();
|
|
591
|
-
}
|
|
592
|
-
return value2;
|
|
593
|
-
},
|
|
594
|
-
indent
|
|
595
|
-
);
|
|
596
|
-
}
|
|
597
|
-
var src_default = Debug;
|
|
430
|
+
// src/transactionManager/Transaction.ts
|
|
431
|
+
var IsolationLevel = /* @__PURE__ */ ((IsolationLevel2) => {
|
|
432
|
+
IsolationLevel2["ReadUncommitted"] = "ReadUncommitted";
|
|
433
|
+
IsolationLevel2["ReadCommitted"] = "ReadCommitted";
|
|
434
|
+
IsolationLevel2["RepeatableRead"] = "RepeatableRead";
|
|
435
|
+
IsolationLevel2["Snapshot"] = "Snapshot";
|
|
436
|
+
IsolationLevel2["Serializable"] = "Serializable";
|
|
437
|
+
return IsolationLevel2;
|
|
438
|
+
})(IsolationLevel || {});
|
|
598
439
|
|
|
599
|
-
//
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
}
|
|
440
|
+
// src/transactionManager/TransactionManager.ts
|
|
441
|
+
var import_node_crypto = __toESM(require("node:crypto"));
|
|
442
|
+
var import_debug = __toESM(require("@prisma/debug"));
|
|
603
443
|
|
|
604
|
-
//
|
|
605
|
-
function
|
|
606
|
-
|
|
607
|
-
value: name,
|
|
608
|
-
configurable: true
|
|
609
|
-
});
|
|
444
|
+
// src/utils.ts
|
|
445
|
+
function assertNever(_, message) {
|
|
446
|
+
throw new Error(message);
|
|
610
447
|
}
|
|
611
448
|
|
|
612
|
-
// src/
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
var PrismaClientKnownRequestError = class extends Error {
|
|
617
|
-
constructor(message, { code, clientVersion, meta, batchRequestIdx }) {
|
|
618
|
-
super(message);
|
|
619
|
-
this.name = "PrismaClientKnownRequestError";
|
|
620
|
-
this.code = code;
|
|
621
|
-
this.clientVersion = clientVersion;
|
|
449
|
+
// src/transactionManager/TransactionManagerErrors.ts
|
|
450
|
+
var TransactionManagerError = class extends Error {
|
|
451
|
+
constructor(message, meta) {
|
|
452
|
+
super("Transaction API error: " + message);
|
|
622
453
|
this.meta = meta;
|
|
623
|
-
|
|
624
|
-
value: batchRequestIdx,
|
|
625
|
-
enumerable: false,
|
|
626
|
-
writable: true
|
|
627
|
-
});
|
|
628
|
-
}
|
|
629
|
-
get [Symbol.toStringTag]() {
|
|
630
|
-
return "PrismaClientKnownRequestError";
|
|
631
|
-
}
|
|
632
|
-
};
|
|
633
|
-
setClassName(PrismaClientKnownRequestError, "PrismaClientKnownRequestError");
|
|
634
|
-
|
|
635
|
-
// src/runtime/core/engines/client/transactionManager/TransactionManagerErrors.ts
|
|
636
|
-
var TransactionManagerError = class extends PrismaClientKnownRequestError {
|
|
637
|
-
constructor(message, {
|
|
638
|
-
clientVersion,
|
|
639
|
-
meta
|
|
640
|
-
}) {
|
|
641
|
-
super("Transaction API error: " + message, {
|
|
642
|
-
code: "P2028",
|
|
643
|
-
clientVersion,
|
|
644
|
-
meta
|
|
645
|
-
});
|
|
454
|
+
this.code = "P2028";
|
|
646
455
|
}
|
|
647
456
|
};
|
|
648
457
|
var TransactionDriverAdapterError = class extends TransactionManagerError {
|
|
649
458
|
constructor(message, errorParams) {
|
|
650
|
-
super(`Error from Driver Adapter: ${message}`, {
|
|
651
|
-
clientVersion: errorParams.clientVersion,
|
|
652
|
-
meta: {
|
|
653
|
-
...errorParams.driverAdapterError
|
|
654
|
-
}
|
|
655
|
-
});
|
|
459
|
+
super(`Error from Driver Adapter: ${message}`, { ...errorParams.driverAdapterError });
|
|
656
460
|
}
|
|
657
461
|
};
|
|
658
462
|
var TransactionNotFoundError = class extends TransactionManagerError {
|
|
659
|
-
constructor(
|
|
463
|
+
constructor() {
|
|
660
464
|
super(
|
|
661
|
-
"Transaction not found. Transaction ID is invalid, refers to an old closed transaction Prisma doesn't have information about anymore, or was obtained before disconnecting."
|
|
662
|
-
errorParams
|
|
465
|
+
"Transaction not found. Transaction ID is invalid, refers to an old closed transaction Prisma doesn't have information about anymore, or was obtained before disconnecting."
|
|
663
466
|
);
|
|
664
467
|
}
|
|
665
468
|
};
|
|
666
469
|
var TransactionClosedError = class extends TransactionManagerError {
|
|
667
|
-
constructor(operation
|
|
668
|
-
super(`Transaction already closed: A ${operation} cannot be executed on a committed transaction
|
|
470
|
+
constructor(operation) {
|
|
471
|
+
super(`Transaction already closed: A ${operation} cannot be executed on a committed transaction`);
|
|
669
472
|
}
|
|
670
473
|
};
|
|
671
474
|
var TransactionRolledBackError = class extends TransactionManagerError {
|
|
672
|
-
constructor(operation
|
|
673
|
-
super(`Transaction already closed: A ${operation} cannot be executed on a committed transaction
|
|
475
|
+
constructor(operation) {
|
|
476
|
+
super(`Transaction already closed: A ${operation} cannot be executed on a committed transaction`);
|
|
674
477
|
}
|
|
675
478
|
};
|
|
676
479
|
var TransactionStartTimoutError = class extends TransactionManagerError {
|
|
677
|
-
constructor(
|
|
678
|
-
super("Unable to start a transaction in the given time."
|
|
480
|
+
constructor() {
|
|
481
|
+
super("Unable to start a transaction in the given time.");
|
|
679
482
|
}
|
|
680
483
|
};
|
|
681
484
|
var TransactionExecutionTimeoutError = class extends TransactionManagerError {
|
|
682
|
-
constructor(operation, {
|
|
485
|
+
constructor(operation, { timeout, timeTaken }) {
|
|
683
486
|
super(
|
|
684
487
|
`A ${operation} cannot be executed on an expired transaction. The timeout for this transaction was ${timeout} ms, however ${timeTaken} ms passed since the start of the transaction. Consider increasing the interactive transaction timeout or doing less work in the transaction`,
|
|
685
|
-
{
|
|
488
|
+
{ operation, timeout, timeTaken }
|
|
686
489
|
);
|
|
687
490
|
}
|
|
688
491
|
};
|
|
689
492
|
var TransactionInternalConsistencyError = class extends TransactionManagerError {
|
|
690
|
-
constructor(message
|
|
691
|
-
super(`Internal Consistency Error: ${message}
|
|
493
|
+
constructor(message) {
|
|
494
|
+
super(`Internal Consistency Error: ${message}`);
|
|
692
495
|
}
|
|
693
496
|
};
|
|
694
497
|
var InvalidTransactionIsolationLevelError = class extends TransactionManagerError {
|
|
695
|
-
constructor(isolationLevel
|
|
696
|
-
super(`Invalid isolation level: ${isolationLevel}`,
|
|
498
|
+
constructor(isolationLevel) {
|
|
499
|
+
super(`Invalid isolation level: ${isolationLevel}`, { isolationLevel });
|
|
697
500
|
}
|
|
698
501
|
};
|
|
699
502
|
|
|
700
|
-
// src/
|
|
503
|
+
// src/transactionManager/TransactionManager.ts
|
|
701
504
|
var MAX_CLOSED_TRANSACTIONS = 100;
|
|
702
505
|
var isolationLevelMap = {
|
|
703
506
|
ReadUncommitted: "READ UNCOMMITTED",
|
|
@@ -706,7 +509,7 @@ var isolationLevelMap = {
|
|
|
706
509
|
Snapshot: "SNAPSHOT",
|
|
707
510
|
Serializable: "SERIALIZABLE"
|
|
708
511
|
};
|
|
709
|
-
var debug =
|
|
512
|
+
var debug = (0, import_debug.default)("prisma:client:transactionManager");
|
|
710
513
|
var COMMIT_QUERY = () => ({ sql: "COMMIT", args: [], argTypes: [] });
|
|
711
514
|
var ROLLBACK_QUERY = () => ({ sql: "ROLLBACK", args: [], argTypes: [] });
|
|
712
515
|
var ISOLATION_LEVEL_QUERY = (isolationLevel) => ({
|
|
@@ -715,19 +518,18 @@ var ISOLATION_LEVEL_QUERY = (isolationLevel) => ({
|
|
|
715
518
|
argTypes: []
|
|
716
519
|
});
|
|
717
520
|
var TransactionManager = class {
|
|
718
|
-
constructor({ driverAdapter
|
|
521
|
+
constructor({ driverAdapter }) {
|
|
719
522
|
// The map of active transactions.
|
|
720
523
|
this.transactions = /* @__PURE__ */ new Map();
|
|
721
524
|
// List of last closed transactions. Max MAX_CLOSED_TRANSACTIONS entries.
|
|
722
525
|
// Used to provide better error messages than a generic "transaction not found".
|
|
723
526
|
this.closedTransactions = [];
|
|
724
527
|
this.driverAdapter = driverAdapter;
|
|
725
|
-
this.clientVersion = clientVersion;
|
|
726
528
|
}
|
|
727
529
|
async startTransaction(options) {
|
|
728
530
|
const validatedOptions = this.validateOptions(options);
|
|
729
531
|
const transaction = {
|
|
730
|
-
id:
|
|
532
|
+
id: import_node_crypto.default.randomUUID(),
|
|
731
533
|
status: "waiting",
|
|
732
534
|
timer: void 0,
|
|
733
535
|
timeout: validatedOptions.timeout,
|
|
@@ -739,8 +541,7 @@ var TransactionManager = class {
|
|
|
739
541
|
const txContext = await this.driverAdapter.transactionContext();
|
|
740
542
|
if (!txContext.ok)
|
|
741
543
|
throw new TransactionDriverAdapterError("Failed to start transaction.", {
|
|
742
|
-
driverAdapterError: txContext.error
|
|
743
|
-
clientVersion: this.clientVersion
|
|
544
|
+
driverAdapterError: txContext.error
|
|
744
545
|
});
|
|
745
546
|
if (this.requiresSettingIsolationLevelFirst() && validatedOptions.isolationLevel) {
|
|
746
547
|
await txContext.value.executeRaw(ISOLATION_LEVEL_QUERY(validatedOptions.isolationLevel));
|
|
@@ -748,8 +549,7 @@ var TransactionManager = class {
|
|
|
748
549
|
const startedTransaction = await txContext.value.startTransaction();
|
|
749
550
|
if (!startedTransaction.ok)
|
|
750
551
|
throw new TransactionDriverAdapterError("Failed to start transaction.", {
|
|
751
|
-
driverAdapterError: startedTransaction.error
|
|
752
|
-
clientVersion: this.clientVersion
|
|
552
|
+
driverAdapterError: startedTransaction.error
|
|
753
553
|
});
|
|
754
554
|
if (!startedTransaction.value.options.usePhantomQuery) {
|
|
755
555
|
await startedTransaction.value.executeRaw({ sql: "BEGIN", args: [], argTypes: [] });
|
|
@@ -764,17 +564,14 @@ var TransactionManager = class {
|
|
|
764
564
|
transaction.timer = void 0;
|
|
765
565
|
transaction.status = "running";
|
|
766
566
|
transaction.timer = this.startTransactionTimeout(transaction.id, validatedOptions.timeout);
|
|
767
|
-
return { id: transaction.id
|
|
567
|
+
return { id: transaction.id };
|
|
768
568
|
case "timed_out":
|
|
769
|
-
throw new TransactionStartTimoutError(
|
|
569
|
+
throw new TransactionStartTimoutError();
|
|
770
570
|
case "running":
|
|
771
571
|
case "committed":
|
|
772
572
|
case "rolled_back":
|
|
773
573
|
throw new TransactionInternalConsistencyError(
|
|
774
|
-
`Transaction in invalid state ${transaction.status} although it just finished startup
|
|
775
|
-
{
|
|
776
|
-
clientVersion: this.clientVersion
|
|
777
|
-
}
|
|
574
|
+
`Transaction in invalid state ${transaction.status} although it just finished startup.`
|
|
778
575
|
);
|
|
779
576
|
default:
|
|
780
577
|
assertNever(transaction.status, "Unknown transaction status.");
|
|
@@ -790,7 +587,7 @@ var TransactionManager = class {
|
|
|
790
587
|
}
|
|
791
588
|
getTransaction(txInfo, operation) {
|
|
792
589
|
const tx = this.getActiveTransaction(txInfo.id, operation);
|
|
793
|
-
if (!tx.transaction) throw new TransactionNotFoundError(
|
|
590
|
+
if (!tx.transaction) throw new TransactionNotFoundError();
|
|
794
591
|
return tx.transaction;
|
|
795
592
|
}
|
|
796
593
|
getActiveTransaction(transactionId, operation) {
|
|
@@ -802,29 +599,24 @@ var TransactionManager = class {
|
|
|
802
599
|
switch (closedTransaction.status) {
|
|
803
600
|
case "waiting":
|
|
804
601
|
case "running":
|
|
805
|
-
throw new TransactionInternalConsistencyError("Active transaction found in closed transactions list."
|
|
806
|
-
clientVersion: this.clientVersion
|
|
807
|
-
});
|
|
602
|
+
throw new TransactionInternalConsistencyError("Active transaction found in closed transactions list.");
|
|
808
603
|
case "committed":
|
|
809
|
-
throw new TransactionClosedError(operation
|
|
604
|
+
throw new TransactionClosedError(operation);
|
|
810
605
|
case "rolled_back":
|
|
811
|
-
throw new TransactionRolledBackError(operation
|
|
606
|
+
throw new TransactionRolledBackError(operation);
|
|
812
607
|
case "timed_out":
|
|
813
608
|
throw new TransactionExecutionTimeoutError(operation, {
|
|
814
609
|
timeout: closedTransaction.timeout,
|
|
815
|
-
timeTaken: Date.now() - closedTransaction.startedAt
|
|
816
|
-
clientVersion: this.clientVersion
|
|
610
|
+
timeTaken: Date.now() - closedTransaction.startedAt
|
|
817
611
|
});
|
|
818
612
|
}
|
|
819
613
|
} else {
|
|
820
614
|
debug(`Transaction not found.`, transactionId);
|
|
821
|
-
throw new TransactionNotFoundError(
|
|
615
|
+
throw new TransactionNotFoundError();
|
|
822
616
|
}
|
|
823
617
|
}
|
|
824
618
|
if (["committed", "rolled_back", "timed_out"].includes(transaction.status)) {
|
|
825
|
-
throw new TransactionInternalConsistencyError("Closed transaction found in active transactions map."
|
|
826
|
-
clientVersion: this.clientVersion
|
|
827
|
-
});
|
|
619
|
+
throw new TransactionInternalConsistencyError("Closed transaction found in active transactions map.");
|
|
828
620
|
}
|
|
829
621
|
return transaction;
|
|
830
622
|
}
|
|
@@ -850,8 +642,7 @@ var TransactionManager = class {
|
|
|
850
642
|
const result = await tx.transaction.commit();
|
|
851
643
|
if (!result.ok)
|
|
852
644
|
throw new TransactionDriverAdapterError("Failed to commit transaction.", {
|
|
853
|
-
driverAdapterError: result.error
|
|
854
|
-
clientVersion: this.clientVersion
|
|
645
|
+
driverAdapterError: result.error
|
|
855
646
|
});
|
|
856
647
|
if (!tx.transaction.options.usePhantomQuery) {
|
|
857
648
|
await tx.transaction.executeRaw(COMMIT_QUERY());
|
|
@@ -860,8 +651,7 @@ var TransactionManager = class {
|
|
|
860
651
|
const result = await tx.transaction.rollback();
|
|
861
652
|
if (!result.ok)
|
|
862
653
|
throw new TransactionDriverAdapterError("Failed to rollback transaction.", {
|
|
863
|
-
driverAdapterError: result.error
|
|
864
|
-
clientVersion: this.clientVersion
|
|
654
|
+
driverAdapterError: result.error
|
|
865
655
|
});
|
|
866
656
|
if (!tx.transaction.options.usePhantomQuery) {
|
|
867
657
|
await tx.transaction.executeRaw(ROLLBACK_QUERY());
|
|
@@ -876,14 +666,12 @@ var TransactionManager = class {
|
|
|
876
666
|
}
|
|
877
667
|
}
|
|
878
668
|
validateOptions(options) {
|
|
879
|
-
if (!options.timeout)
|
|
880
|
-
|
|
881
|
-
if (!options.maxWait)
|
|
882
|
-
throw new TransactionManagerError("maxWait is required", { clientVersion: this.clientVersion });
|
|
669
|
+
if (!options.timeout) throw new TransactionManagerError("timeout is required");
|
|
670
|
+
if (!options.maxWait) throw new TransactionManagerError("maxWait is required");
|
|
883
671
|
if (options.isolationLevel === "Snapshot" /* Snapshot */)
|
|
884
|
-
throw new InvalidTransactionIsolationLevelError(options.isolationLevel
|
|
672
|
+
throw new InvalidTransactionIsolationLevelError(options.isolationLevel);
|
|
885
673
|
if (this.driverAdapter.provider === "sqlite" && options.isolationLevel && options.isolationLevel !== "Serializable" /* Serializable */)
|
|
886
|
-
throw new InvalidTransactionIsolationLevelError(options.isolationLevel
|
|
674
|
+
throw new InvalidTransactionIsolationLevelError(options.isolationLevel);
|
|
887
675
|
return {
|
|
888
676
|
...options,
|
|
889
677
|
timeout: options.timeout,
|
|
@@ -894,9 +682,11 @@ var TransactionManager = class {
|
|
|
894
682
|
return this.driverAdapter.provider === "mysql";
|
|
895
683
|
}
|
|
896
684
|
};
|
|
897
|
-
export
|
|
685
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
686
|
+
0 && (module.exports = {
|
|
898
687
|
IsolationLevel,
|
|
899
688
|
QueryInterpreter,
|
|
900
689
|
TransactionManager,
|
|
690
|
+
TransactionManagerError,
|
|
901
691
|
isPrismaValuePlaceholder
|
|
902
|
-
};
|
|
692
|
+
});
|