@prisma/client-engine-runtime 6.7.0-dev.2 → 6.7.0-dev.4
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/UserFacingError.d.ts +16 -0
- package/dist/index.d.mts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +157 -30
- package/dist/index.mjs +156 -30
- package/dist/transactionManager/TransactionManagerErrors.d.ts +1 -7
- package/package.json +3 -3
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare class UserFacingError extends Error {
|
|
2
|
+
name: string;
|
|
3
|
+
code: string;
|
|
4
|
+
meta: unknown;
|
|
5
|
+
constructor(message: string, code: string, meta?: unknown);
|
|
6
|
+
toQueryResponseErrorObject(): {
|
|
7
|
+
error: string;
|
|
8
|
+
user_facing_error: {
|
|
9
|
+
is_panic: boolean;
|
|
10
|
+
message: string;
|
|
11
|
+
meta: unknown;
|
|
12
|
+
error_code: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare function rethrowAsUserFacing(error: any): never;
|
package/dist/index.d.mts
CHANGED
|
@@ -181,4 +181,20 @@ export declare type TransactionOptions = {
|
|
|
181
181
|
isolationLevel?: IsolationLevel;
|
|
182
182
|
};
|
|
183
183
|
|
|
184
|
+
export declare class UserFacingError extends Error {
|
|
185
|
+
name: string;
|
|
186
|
+
code: string;
|
|
187
|
+
meta: unknown;
|
|
188
|
+
constructor(message: string, code: string, meta?: unknown);
|
|
189
|
+
toQueryResponseErrorObject(): {
|
|
190
|
+
error: string;
|
|
191
|
+
user_facing_error: {
|
|
192
|
+
is_panic: boolean;
|
|
193
|
+
message: string;
|
|
194
|
+
meta: unknown;
|
|
195
|
+
error_code: string;
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
184
200
|
export { }
|
package/dist/index.d.ts
CHANGED
|
@@ -181,4 +181,20 @@ export declare type TransactionOptions = {
|
|
|
181
181
|
isolationLevel?: IsolationLevel;
|
|
182
182
|
};
|
|
183
183
|
|
|
184
|
+
export declare class UserFacingError extends Error {
|
|
185
|
+
name: string;
|
|
186
|
+
code: string;
|
|
187
|
+
meta: unknown;
|
|
188
|
+
constructor(message: string, code: string, meta?: unknown);
|
|
189
|
+
toQueryResponseErrorObject(): {
|
|
190
|
+
error: string;
|
|
191
|
+
user_facing_error: {
|
|
192
|
+
is_panic: boolean;
|
|
193
|
+
message: string;
|
|
194
|
+
meta: unknown;
|
|
195
|
+
error_code: string;
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
184
200
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -33,11 +33,159 @@ __export(index_exports, {
|
|
|
33
33
|
QueryInterpreter: () => QueryInterpreter,
|
|
34
34
|
TransactionManager: () => TransactionManager,
|
|
35
35
|
TransactionManagerError: () => TransactionManagerError,
|
|
36
|
+
UserFacingError: () => UserFacingError,
|
|
36
37
|
isPrismaValueGenerator: () => isPrismaValueGenerator,
|
|
37
38
|
isPrismaValuePlaceholder: () => isPrismaValuePlaceholder
|
|
38
39
|
});
|
|
39
40
|
module.exports = __toCommonJS(index_exports);
|
|
40
41
|
|
|
42
|
+
// src/UserFacingError.ts
|
|
43
|
+
var import_driver_adapter_utils = require("@prisma/driver-adapter-utils");
|
|
44
|
+
var UserFacingError = class extends Error {
|
|
45
|
+
name = "UserFacingError";
|
|
46
|
+
code;
|
|
47
|
+
meta;
|
|
48
|
+
constructor(message, code, meta) {
|
|
49
|
+
super(message);
|
|
50
|
+
this.code = code;
|
|
51
|
+
this.meta = meta;
|
|
52
|
+
}
|
|
53
|
+
toQueryResponseErrorObject() {
|
|
54
|
+
return {
|
|
55
|
+
error: this.message,
|
|
56
|
+
user_facing_error: {
|
|
57
|
+
is_panic: false,
|
|
58
|
+
message: this.message,
|
|
59
|
+
meta: this.meta,
|
|
60
|
+
error_code: this.code
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
function rethrowAsUserFacing(error) {
|
|
66
|
+
if (!(0, import_driver_adapter_utils.isDriverAdapterError)(error)) {
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
const code = getErrorCode(error);
|
|
70
|
+
const message = renderErrorMessage(error);
|
|
71
|
+
if (!code || !message) {
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
throw new UserFacingError(message, code, error);
|
|
75
|
+
}
|
|
76
|
+
function getErrorCode(err) {
|
|
77
|
+
switch (err.cause.kind) {
|
|
78
|
+
case "AuthenticationFailed":
|
|
79
|
+
return "P1000";
|
|
80
|
+
case "DatabaseDoesNotExist":
|
|
81
|
+
return "P1003";
|
|
82
|
+
case "SocketTimeout":
|
|
83
|
+
return "P1008";
|
|
84
|
+
case "DatabaseAlreadyExists":
|
|
85
|
+
return "P1009";
|
|
86
|
+
case "DatabaseAccessDenied":
|
|
87
|
+
return "P1010";
|
|
88
|
+
case "LengthMismatch":
|
|
89
|
+
return "P2000";
|
|
90
|
+
case "UniqueConstraintViolation":
|
|
91
|
+
return "P2002";
|
|
92
|
+
case "ForeignKeyConstraintViolation":
|
|
93
|
+
return "P2003";
|
|
94
|
+
case "UnsupportedNativeDataType":
|
|
95
|
+
return "P2010";
|
|
96
|
+
case "NullConstraintViolation":
|
|
97
|
+
return "P2011";
|
|
98
|
+
case "TableDoesNotExist":
|
|
99
|
+
return "P2021";
|
|
100
|
+
case "ColumnNotFound":
|
|
101
|
+
return "P2022";
|
|
102
|
+
case "InvalidIsolationLevel":
|
|
103
|
+
return "P2023";
|
|
104
|
+
case "TransactionWriteConflict":
|
|
105
|
+
return "P2034";
|
|
106
|
+
case "GenericJs":
|
|
107
|
+
return "P2036";
|
|
108
|
+
case "TooManyConnections":
|
|
109
|
+
return "P2037";
|
|
110
|
+
case "postgres":
|
|
111
|
+
case "sqlite":
|
|
112
|
+
case "mysql":
|
|
113
|
+
return;
|
|
114
|
+
default: {
|
|
115
|
+
const cause = err.cause;
|
|
116
|
+
throw new Error(`Unknown error: ${cause}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function renderErrorMessage(err) {
|
|
121
|
+
switch (err.cause.kind) {
|
|
122
|
+
case "AuthenticationFailed": {
|
|
123
|
+
const user = err.cause.user ?? "(not available)";
|
|
124
|
+
return `Authentication failed against the database server, the provided database credentials for \`${user}\` are not valid`;
|
|
125
|
+
}
|
|
126
|
+
case "DatabaseDoesNotExist": {
|
|
127
|
+
const db = err.cause.db ?? "(not available)";
|
|
128
|
+
return `Database \`${db}\` does not exist on the database server`;
|
|
129
|
+
}
|
|
130
|
+
case "SocketTimeout":
|
|
131
|
+
return `Operation has timed out`;
|
|
132
|
+
case "DatabaseAlreadyExists": {
|
|
133
|
+
const db = err.cause.db ?? "(not available)";
|
|
134
|
+
return `Database \`${db}\` already exists on the database server`;
|
|
135
|
+
}
|
|
136
|
+
case "DatabaseAccessDenied": {
|
|
137
|
+
const db = err.cause.db ?? "(not available)";
|
|
138
|
+
return `User was denied access on the database \`${db}\``;
|
|
139
|
+
}
|
|
140
|
+
case "LengthMismatch": {
|
|
141
|
+
const column = err.cause.column ?? "(not available)";
|
|
142
|
+
return `The provided value for the column is too long for the column's type. Column: ${column}`;
|
|
143
|
+
}
|
|
144
|
+
case "UniqueConstraintViolation":
|
|
145
|
+
return `Unique constraint failed on the ${renderConstraint({ fields: err.cause.fields })}`;
|
|
146
|
+
case "ForeignKeyConstraintViolation":
|
|
147
|
+
return `Foreign key constraint violated on the ${renderConstraint(err.cause.constraint)}`;
|
|
148
|
+
case "UnsupportedNativeDataType":
|
|
149
|
+
return `Failed to deserialize column of type '${err.cause.type}'. If you're using $queryRaw and this column is explicitly marked as \`Unsupported\` in your Prisma schema, try casting this column to any supported Prisma type such as \`String\`.`;
|
|
150
|
+
case "NullConstraintViolation":
|
|
151
|
+
return `Null constraint violation on the ${renderConstraint({ fields: err.cause.fields })}`;
|
|
152
|
+
case "TableDoesNotExist": {
|
|
153
|
+
const table = err.cause.table ?? "(not available)";
|
|
154
|
+
return `The table \`${table}\` does not exist in the current database.`;
|
|
155
|
+
}
|
|
156
|
+
case "ColumnNotFound": {
|
|
157
|
+
const column = err.cause.column ?? "(not available)";
|
|
158
|
+
return `The column \`${column}\` does not exist in the current database.`;
|
|
159
|
+
}
|
|
160
|
+
case "InvalidIsolationLevel":
|
|
161
|
+
return `Invalid isolation level \`${err.cause.level}\``;
|
|
162
|
+
case "TransactionWriteConflict":
|
|
163
|
+
return `Transaction failed due to a write conflict or a deadlock. Please retry your transaction`;
|
|
164
|
+
case "GenericJs":
|
|
165
|
+
return `Error in external connector (id ${err.cause.id})`;
|
|
166
|
+
case "TooManyConnections":
|
|
167
|
+
return `Too many database connections opened: ${err.cause.cause}`;
|
|
168
|
+
case "sqlite":
|
|
169
|
+
case "postgres":
|
|
170
|
+
case "mysql":
|
|
171
|
+
return;
|
|
172
|
+
default: {
|
|
173
|
+
const cause = err.cause;
|
|
174
|
+
throw new Error(`Unknown error: ${cause}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function renderConstraint(constraint) {
|
|
179
|
+
if (constraint && "fields" in constraint) {
|
|
180
|
+
return `fields: (${constraint.fields.map((field) => `\`${field}\``).join(", ")})`;
|
|
181
|
+
} else if (constraint && "index" in constraint) {
|
|
182
|
+
return `constraint: \`${constraint.index}\``;
|
|
183
|
+
} else if (constraint && "foreignKey" in constraint) {
|
|
184
|
+
return `foreign key`;
|
|
185
|
+
}
|
|
186
|
+
return "(not available)";
|
|
187
|
+
}
|
|
188
|
+
|
|
41
189
|
// src/interpreter/generators.ts
|
|
42
190
|
var import_cuid = __toESM(require("@bugsnag/cuid"));
|
|
43
191
|
var import_cuid2 = require("@paralleldrive/cuid2");
|
|
@@ -284,7 +432,9 @@ var QueryInterpreter = class {
|
|
|
284
432
|
this.#onQuery = onQuery;
|
|
285
433
|
}
|
|
286
434
|
async run(queryPlan, queryable) {
|
|
287
|
-
return this.interpretNode(queryPlan, queryable, this.#placeholderValues, this.#generators.snapshot())
|
|
435
|
+
return this.interpretNode(queryPlan, queryable, this.#placeholderValues, this.#generators.snapshot()).catch(
|
|
436
|
+
(e) => rethrowAsUserFacing(e)
|
|
437
|
+
);
|
|
288
438
|
}
|
|
289
439
|
async interpretNode(node, queryable, scope, generators) {
|
|
290
440
|
switch (node.type) {
|
|
@@ -486,11 +636,6 @@ var TransactionManagerError = class extends Error {
|
|
|
486
636
|
}
|
|
487
637
|
code = "P2028";
|
|
488
638
|
};
|
|
489
|
-
var TransactionDriverAdapterError = class extends TransactionManagerError {
|
|
490
|
-
constructor(message, errorParams) {
|
|
491
|
-
super(`Error from Driver Adapter: ${message}`, { ...errorParams.driverAdapterError });
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
639
|
var TransactionNotFoundError = class extends TransactionManagerError {
|
|
495
640
|
constructor() {
|
|
496
641
|
super(
|
|
@@ -508,7 +653,7 @@ var TransactionRolledBackError = class extends TransactionManagerError {
|
|
|
508
653
|
super(`Transaction already closed: A ${operation} cannot be executed on a committed transaction`);
|
|
509
654
|
}
|
|
510
655
|
};
|
|
511
|
-
var
|
|
656
|
+
var TransactionStartTimeoutError = class extends TransactionManagerError {
|
|
512
657
|
constructor() {
|
|
513
658
|
super("Unable to start a transaction in the given time.");
|
|
514
659
|
}
|
|
@@ -561,14 +706,7 @@ var TransactionManager = class {
|
|
|
561
706
|
};
|
|
562
707
|
this.transactions.set(transaction.id, transaction);
|
|
563
708
|
transaction.timer = this.startTransactionTimeout(transaction.id, validatedOptions.maxWait);
|
|
564
|
-
|
|
565
|
-
try {
|
|
566
|
-
startedTransaction = await this.driverAdapter.startTransaction(validatedOptions.isolationLevel);
|
|
567
|
-
} catch (error) {
|
|
568
|
-
throw new TransactionDriverAdapterError("Failed to start transaction.", {
|
|
569
|
-
driverAdapterError: error
|
|
570
|
-
});
|
|
571
|
-
}
|
|
709
|
+
const startedTransaction = await this.driverAdapter.startTransaction(validatedOptions.isolationLevel);
|
|
572
710
|
switch (transaction.status) {
|
|
573
711
|
case "waiting":
|
|
574
712
|
transaction.transaction = startedTransaction;
|
|
@@ -578,7 +716,7 @@ var TransactionManager = class {
|
|
|
578
716
|
transaction.timer = this.startTransactionTimeout(transaction.id, validatedOptions.timeout);
|
|
579
717
|
return { id: transaction.id };
|
|
580
718
|
case "timed_out":
|
|
581
|
-
throw new
|
|
719
|
+
throw new TransactionStartTimeoutError();
|
|
582
720
|
case "running":
|
|
583
721
|
case "committed":
|
|
584
722
|
case "rolled_back":
|
|
@@ -651,24 +789,12 @@ var TransactionManager = class {
|
|
|
651
789
|
debug("Closing transaction.", { transactionId: tx.id, status });
|
|
652
790
|
tx.status = status;
|
|
653
791
|
if (tx.transaction && status === "committed") {
|
|
654
|
-
|
|
655
|
-
await tx.transaction.commit();
|
|
656
|
-
} catch (error) {
|
|
657
|
-
throw new TransactionDriverAdapterError("Failed to commit transaction.", {
|
|
658
|
-
driverAdapterError: error
|
|
659
|
-
});
|
|
660
|
-
}
|
|
792
|
+
await tx.transaction.commit();
|
|
661
793
|
if (!tx.transaction.options.usePhantomQuery) {
|
|
662
794
|
await tx.transaction.executeRaw(COMMIT_QUERY());
|
|
663
795
|
}
|
|
664
796
|
} else if (tx.transaction) {
|
|
665
|
-
|
|
666
|
-
await tx.transaction.rollback();
|
|
667
|
-
} catch (error) {
|
|
668
|
-
throw new TransactionDriverAdapterError("Failed to rollback transaction.", {
|
|
669
|
-
driverAdapterError: error
|
|
670
|
-
});
|
|
671
|
-
}
|
|
797
|
+
await tx.transaction.rollback();
|
|
672
798
|
if (!tx.transaction.options.usePhantomQuery) {
|
|
673
799
|
await tx.transaction.executeRaw(ROLLBACK_QUERY());
|
|
674
800
|
}
|
|
@@ -697,6 +823,7 @@ var TransactionManager = class {
|
|
|
697
823
|
QueryInterpreter,
|
|
698
824
|
TransactionManager,
|
|
699
825
|
TransactionManagerError,
|
|
826
|
+
UserFacingError,
|
|
700
827
|
isPrismaValueGenerator,
|
|
701
828
|
isPrismaValuePlaceholder
|
|
702
829
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,150 @@
|
|
|
1
|
+
// src/UserFacingError.ts
|
|
2
|
+
import { isDriverAdapterError } from "@prisma/driver-adapter-utils";
|
|
3
|
+
var UserFacingError = class extends Error {
|
|
4
|
+
name = "UserFacingError";
|
|
5
|
+
code;
|
|
6
|
+
meta;
|
|
7
|
+
constructor(message, code, meta) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.meta = meta;
|
|
11
|
+
}
|
|
12
|
+
toQueryResponseErrorObject() {
|
|
13
|
+
return {
|
|
14
|
+
error: this.message,
|
|
15
|
+
user_facing_error: {
|
|
16
|
+
is_panic: false,
|
|
17
|
+
message: this.message,
|
|
18
|
+
meta: this.meta,
|
|
19
|
+
error_code: this.code
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
function rethrowAsUserFacing(error) {
|
|
25
|
+
if (!isDriverAdapterError(error)) {
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
const code = getErrorCode(error);
|
|
29
|
+
const message = renderErrorMessage(error);
|
|
30
|
+
if (!code || !message) {
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
throw new UserFacingError(message, code, error);
|
|
34
|
+
}
|
|
35
|
+
function getErrorCode(err) {
|
|
36
|
+
switch (err.cause.kind) {
|
|
37
|
+
case "AuthenticationFailed":
|
|
38
|
+
return "P1000";
|
|
39
|
+
case "DatabaseDoesNotExist":
|
|
40
|
+
return "P1003";
|
|
41
|
+
case "SocketTimeout":
|
|
42
|
+
return "P1008";
|
|
43
|
+
case "DatabaseAlreadyExists":
|
|
44
|
+
return "P1009";
|
|
45
|
+
case "DatabaseAccessDenied":
|
|
46
|
+
return "P1010";
|
|
47
|
+
case "LengthMismatch":
|
|
48
|
+
return "P2000";
|
|
49
|
+
case "UniqueConstraintViolation":
|
|
50
|
+
return "P2002";
|
|
51
|
+
case "ForeignKeyConstraintViolation":
|
|
52
|
+
return "P2003";
|
|
53
|
+
case "UnsupportedNativeDataType":
|
|
54
|
+
return "P2010";
|
|
55
|
+
case "NullConstraintViolation":
|
|
56
|
+
return "P2011";
|
|
57
|
+
case "TableDoesNotExist":
|
|
58
|
+
return "P2021";
|
|
59
|
+
case "ColumnNotFound":
|
|
60
|
+
return "P2022";
|
|
61
|
+
case "InvalidIsolationLevel":
|
|
62
|
+
return "P2023";
|
|
63
|
+
case "TransactionWriteConflict":
|
|
64
|
+
return "P2034";
|
|
65
|
+
case "GenericJs":
|
|
66
|
+
return "P2036";
|
|
67
|
+
case "TooManyConnections":
|
|
68
|
+
return "P2037";
|
|
69
|
+
case "postgres":
|
|
70
|
+
case "sqlite":
|
|
71
|
+
case "mysql":
|
|
72
|
+
return;
|
|
73
|
+
default: {
|
|
74
|
+
const cause = err.cause;
|
|
75
|
+
throw new Error(`Unknown error: ${cause}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function renderErrorMessage(err) {
|
|
80
|
+
switch (err.cause.kind) {
|
|
81
|
+
case "AuthenticationFailed": {
|
|
82
|
+
const user = err.cause.user ?? "(not available)";
|
|
83
|
+
return `Authentication failed against the database server, the provided database credentials for \`${user}\` are not valid`;
|
|
84
|
+
}
|
|
85
|
+
case "DatabaseDoesNotExist": {
|
|
86
|
+
const db = err.cause.db ?? "(not available)";
|
|
87
|
+
return `Database \`${db}\` does not exist on the database server`;
|
|
88
|
+
}
|
|
89
|
+
case "SocketTimeout":
|
|
90
|
+
return `Operation has timed out`;
|
|
91
|
+
case "DatabaseAlreadyExists": {
|
|
92
|
+
const db = err.cause.db ?? "(not available)";
|
|
93
|
+
return `Database \`${db}\` already exists on the database server`;
|
|
94
|
+
}
|
|
95
|
+
case "DatabaseAccessDenied": {
|
|
96
|
+
const db = err.cause.db ?? "(not available)";
|
|
97
|
+
return `User was denied access on the database \`${db}\``;
|
|
98
|
+
}
|
|
99
|
+
case "LengthMismatch": {
|
|
100
|
+
const column = err.cause.column ?? "(not available)";
|
|
101
|
+
return `The provided value for the column is too long for the column's type. Column: ${column}`;
|
|
102
|
+
}
|
|
103
|
+
case "UniqueConstraintViolation":
|
|
104
|
+
return `Unique constraint failed on the ${renderConstraint({ fields: err.cause.fields })}`;
|
|
105
|
+
case "ForeignKeyConstraintViolation":
|
|
106
|
+
return `Foreign key constraint violated on the ${renderConstraint(err.cause.constraint)}`;
|
|
107
|
+
case "UnsupportedNativeDataType":
|
|
108
|
+
return `Failed to deserialize column of type '${err.cause.type}'. If you're using $queryRaw and this column is explicitly marked as \`Unsupported\` in your Prisma schema, try casting this column to any supported Prisma type such as \`String\`.`;
|
|
109
|
+
case "NullConstraintViolation":
|
|
110
|
+
return `Null constraint violation on the ${renderConstraint({ fields: err.cause.fields })}`;
|
|
111
|
+
case "TableDoesNotExist": {
|
|
112
|
+
const table = err.cause.table ?? "(not available)";
|
|
113
|
+
return `The table \`${table}\` does not exist in the current database.`;
|
|
114
|
+
}
|
|
115
|
+
case "ColumnNotFound": {
|
|
116
|
+
const column = err.cause.column ?? "(not available)";
|
|
117
|
+
return `The column \`${column}\` does not exist in the current database.`;
|
|
118
|
+
}
|
|
119
|
+
case "InvalidIsolationLevel":
|
|
120
|
+
return `Invalid isolation level \`${err.cause.level}\``;
|
|
121
|
+
case "TransactionWriteConflict":
|
|
122
|
+
return `Transaction failed due to a write conflict or a deadlock. Please retry your transaction`;
|
|
123
|
+
case "GenericJs":
|
|
124
|
+
return `Error in external connector (id ${err.cause.id})`;
|
|
125
|
+
case "TooManyConnections":
|
|
126
|
+
return `Too many database connections opened: ${err.cause.cause}`;
|
|
127
|
+
case "sqlite":
|
|
128
|
+
case "postgres":
|
|
129
|
+
case "mysql":
|
|
130
|
+
return;
|
|
131
|
+
default: {
|
|
132
|
+
const cause = err.cause;
|
|
133
|
+
throw new Error(`Unknown error: ${cause}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function renderConstraint(constraint) {
|
|
138
|
+
if (constraint && "fields" in constraint) {
|
|
139
|
+
return `fields: (${constraint.fields.map((field) => `\`${field}\``).join(", ")})`;
|
|
140
|
+
} else if (constraint && "index" in constraint) {
|
|
141
|
+
return `constraint: \`${constraint.index}\``;
|
|
142
|
+
} else if (constraint && "foreignKey" in constraint) {
|
|
143
|
+
return `foreign key`;
|
|
144
|
+
}
|
|
145
|
+
return "(not available)";
|
|
146
|
+
}
|
|
147
|
+
|
|
1
148
|
// src/interpreter/generators.ts
|
|
2
149
|
import cuid1 from "@bugsnag/cuid";
|
|
3
150
|
import { createId as cuid2 } from "@paralleldrive/cuid2";
|
|
@@ -244,7 +391,9 @@ var QueryInterpreter = class {
|
|
|
244
391
|
this.#onQuery = onQuery;
|
|
245
392
|
}
|
|
246
393
|
async run(queryPlan, queryable) {
|
|
247
|
-
return this.interpretNode(queryPlan, queryable, this.#placeholderValues, this.#generators.snapshot())
|
|
394
|
+
return this.interpretNode(queryPlan, queryable, this.#placeholderValues, this.#generators.snapshot()).catch(
|
|
395
|
+
(e) => rethrowAsUserFacing(e)
|
|
396
|
+
);
|
|
248
397
|
}
|
|
249
398
|
async interpretNode(node, queryable, scope, generators) {
|
|
250
399
|
switch (node.type) {
|
|
@@ -446,11 +595,6 @@ var TransactionManagerError = class extends Error {
|
|
|
446
595
|
}
|
|
447
596
|
code = "P2028";
|
|
448
597
|
};
|
|
449
|
-
var TransactionDriverAdapterError = class extends TransactionManagerError {
|
|
450
|
-
constructor(message, errorParams) {
|
|
451
|
-
super(`Error from Driver Adapter: ${message}`, { ...errorParams.driverAdapterError });
|
|
452
|
-
}
|
|
453
|
-
};
|
|
454
598
|
var TransactionNotFoundError = class extends TransactionManagerError {
|
|
455
599
|
constructor() {
|
|
456
600
|
super(
|
|
@@ -468,7 +612,7 @@ var TransactionRolledBackError = class extends TransactionManagerError {
|
|
|
468
612
|
super(`Transaction already closed: A ${operation} cannot be executed on a committed transaction`);
|
|
469
613
|
}
|
|
470
614
|
};
|
|
471
|
-
var
|
|
615
|
+
var TransactionStartTimeoutError = class extends TransactionManagerError {
|
|
472
616
|
constructor() {
|
|
473
617
|
super("Unable to start a transaction in the given time.");
|
|
474
618
|
}
|
|
@@ -521,14 +665,7 @@ var TransactionManager = class {
|
|
|
521
665
|
};
|
|
522
666
|
this.transactions.set(transaction.id, transaction);
|
|
523
667
|
transaction.timer = this.startTransactionTimeout(transaction.id, validatedOptions.maxWait);
|
|
524
|
-
|
|
525
|
-
try {
|
|
526
|
-
startedTransaction = await this.driverAdapter.startTransaction(validatedOptions.isolationLevel);
|
|
527
|
-
} catch (error) {
|
|
528
|
-
throw new TransactionDriverAdapterError("Failed to start transaction.", {
|
|
529
|
-
driverAdapterError: error
|
|
530
|
-
});
|
|
531
|
-
}
|
|
668
|
+
const startedTransaction = await this.driverAdapter.startTransaction(validatedOptions.isolationLevel);
|
|
532
669
|
switch (transaction.status) {
|
|
533
670
|
case "waiting":
|
|
534
671
|
transaction.transaction = startedTransaction;
|
|
@@ -538,7 +675,7 @@ var TransactionManager = class {
|
|
|
538
675
|
transaction.timer = this.startTransactionTimeout(transaction.id, validatedOptions.timeout);
|
|
539
676
|
return { id: transaction.id };
|
|
540
677
|
case "timed_out":
|
|
541
|
-
throw new
|
|
678
|
+
throw new TransactionStartTimeoutError();
|
|
542
679
|
case "running":
|
|
543
680
|
case "committed":
|
|
544
681
|
case "rolled_back":
|
|
@@ -611,24 +748,12 @@ var TransactionManager = class {
|
|
|
611
748
|
debug("Closing transaction.", { transactionId: tx.id, status });
|
|
612
749
|
tx.status = status;
|
|
613
750
|
if (tx.transaction && status === "committed") {
|
|
614
|
-
|
|
615
|
-
await tx.transaction.commit();
|
|
616
|
-
} catch (error) {
|
|
617
|
-
throw new TransactionDriverAdapterError("Failed to commit transaction.", {
|
|
618
|
-
driverAdapterError: error
|
|
619
|
-
});
|
|
620
|
-
}
|
|
751
|
+
await tx.transaction.commit();
|
|
621
752
|
if (!tx.transaction.options.usePhantomQuery) {
|
|
622
753
|
await tx.transaction.executeRaw(COMMIT_QUERY());
|
|
623
754
|
}
|
|
624
755
|
} else if (tx.transaction) {
|
|
625
|
-
|
|
626
|
-
await tx.transaction.rollback();
|
|
627
|
-
} catch (error) {
|
|
628
|
-
throw new TransactionDriverAdapterError("Failed to rollback transaction.", {
|
|
629
|
-
driverAdapterError: error
|
|
630
|
-
});
|
|
631
|
-
}
|
|
756
|
+
await tx.transaction.rollback();
|
|
632
757
|
if (!tx.transaction.options.usePhantomQuery) {
|
|
633
758
|
await tx.transaction.executeRaw(ROLLBACK_QUERY());
|
|
634
759
|
}
|
|
@@ -656,6 +781,7 @@ export {
|
|
|
656
781
|
QueryInterpreter,
|
|
657
782
|
TransactionManager,
|
|
658
783
|
TransactionManagerError,
|
|
784
|
+
UserFacingError,
|
|
659
785
|
isPrismaValueGenerator,
|
|
660
786
|
isPrismaValuePlaceholder
|
|
661
787
|
};
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import { Error as DriverAdapterError } from '@prisma/driver-adapter-utils';
|
|
2
1
|
export declare class TransactionManagerError extends Error {
|
|
3
2
|
meta?: Record<string, unknown> | undefined;
|
|
4
3
|
code: string;
|
|
5
4
|
constructor(message: string, meta?: Record<string, unknown> | undefined);
|
|
6
5
|
}
|
|
7
|
-
export declare class TransactionDriverAdapterError extends TransactionManagerError {
|
|
8
|
-
constructor(message: string, errorParams: {
|
|
9
|
-
driverAdapterError: DriverAdapterError;
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
6
|
export declare class TransactionNotFoundError extends TransactionManagerError {
|
|
13
7
|
constructor();
|
|
14
8
|
}
|
|
@@ -18,7 +12,7 @@ export declare class TransactionClosedError extends TransactionManagerError {
|
|
|
18
12
|
export declare class TransactionRolledBackError extends TransactionManagerError {
|
|
19
13
|
constructor(operation: string);
|
|
20
14
|
}
|
|
21
|
-
export declare class
|
|
15
|
+
export declare class TransactionStartTimeoutError extends TransactionManagerError {
|
|
22
16
|
constructor();
|
|
23
17
|
}
|
|
24
18
|
export declare class TransactionExecutionTimeoutError extends TransactionManagerError {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma/client-engine-runtime",
|
|
3
|
-
"version": "6.7.0-dev.
|
|
3
|
+
"version": "6.7.0-dev.4",
|
|
4
4
|
"description": "This package is intended for Prisma's internal use",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"nanoid": "5.1.5",
|
|
30
30
|
"ulid": "3.0.0",
|
|
31
31
|
"uuid": "11.1.0",
|
|
32
|
-
"@prisma/debug": "6.7.0-dev.
|
|
33
|
-
"@prisma/driver-adapter-utils": "6.7.0-dev.
|
|
32
|
+
"@prisma/debug": "6.7.0-dev.4",
|
|
33
|
+
"@prisma/driver-adapter-utils": "6.7.0-dev.4"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/jest": "29.5.14",
|