@prisma/client-engine-runtime 6.14.0-dev.35 → 6.14.0-dev.37
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/batch.d.ts +19 -0
- package/dist/index.d.mts +29 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +311 -244
- package/dist/index.mjs +309 -244
- package/dist/interpreter/{DataMapper.d.ts → data-mapper.d.ts} +1 -1
- package/dist/interpreter/in-memory-processing.d.ts +1 -1
- package/dist/interpreter/{QueryInterpreter.d.ts → query-interpreter.d.ts} +2 -2
- package/dist/interpreter/{renderQuery.d.ts → render-query.d.ts} +1 -1
- package/dist/interpreter/validation.d.ts +1 -1
- package/dist/json-protocol.d.ts +5 -0
- package/dist/{transactionManager/TransactionManagerErrors.d.ts → transaction-manager/transaction-manager-error.d.ts} +1 -1
- package/dist/{transactionManager/TransactionManager.d.ts → transaction-manager/transaction-manager.d.ts} +1 -1
- package/dist/transaction-manager/transaction-manager.test.d.ts +1 -0
- package/package.json +3 -3
- /package/dist/interpreter/{renderQuery.test.d.ts → render-query.test.d.ts} +0 -0
- /package/dist/interpreter/{serializeSql.d.ts → serialize-sql.d.ts} +0 -0
- /package/dist/interpreter/{serializeSql.test.d.ts → serialize-sql.test.d.ts} +0 -0
- /package/dist/{transactionManager/TransactionManager.test.d.ts → json-protocol.test.d.ts} +0 -0
- /package/dist/{QueryPlan.d.ts → query-plan.d.ts} +0 -0
- /package/dist/{transactionManager/Transaction.d.ts → transaction-manager/transaction.d.ts} +0 -0
- /package/dist/{UserFacingError.d.ts → user-facing-error.d.ts} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
import Decimal2 from "decimal.js";
|
|
1
|
+
// src/json-protocol.ts
|
|
2
|
+
import { Decimal as Decimal2 } from "decimal.js";
|
|
3
3
|
|
|
4
4
|
// src/utils.ts
|
|
5
5
|
import Decimal from "decimal.js";
|
|
@@ -93,7 +93,303 @@ function safeJsonStringify(obj) {
|
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
// src/
|
|
96
|
+
// src/json-protocol.ts
|
|
97
|
+
function normalizeJsonProtocolValues(result) {
|
|
98
|
+
if (result === null) {
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
if (Array.isArray(result)) {
|
|
102
|
+
return result.map(normalizeJsonProtocolValues);
|
|
103
|
+
}
|
|
104
|
+
if (typeof result === "object") {
|
|
105
|
+
if (isTaggedValue(result)) {
|
|
106
|
+
return normalizeTaggedValue(result);
|
|
107
|
+
}
|
|
108
|
+
if (result.constructor !== null && result.constructor.name !== "Object") {
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
return mapObjectValues(result, normalizeJsonProtocolValues);
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
function isTaggedValue(value) {
|
|
116
|
+
return value !== null && typeof value == "object" && typeof value["$type"] === "string";
|
|
117
|
+
}
|
|
118
|
+
function normalizeTaggedValue({ $type, value }) {
|
|
119
|
+
switch ($type) {
|
|
120
|
+
case "BigInt":
|
|
121
|
+
return { $type, value: String(value) };
|
|
122
|
+
case "Bytes":
|
|
123
|
+
return { $type, value };
|
|
124
|
+
case "DateTime":
|
|
125
|
+
return { $type, value: new Date(value).toISOString() };
|
|
126
|
+
case "Decimal":
|
|
127
|
+
return { $type, value: String(new Decimal2(value)) };
|
|
128
|
+
case "Json":
|
|
129
|
+
return { $type, value: JSON.stringify(JSON.parse(value)) };
|
|
130
|
+
default:
|
|
131
|
+
assertNever(value, "Unknown tagged value");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function mapObjectValues(object, mapper) {
|
|
135
|
+
const result = {};
|
|
136
|
+
for (const key of Object.keys(object)) {
|
|
137
|
+
result[key] = mapper(object[key], key);
|
|
138
|
+
}
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
function deserializeJsonResponse(result) {
|
|
142
|
+
if (result === null) {
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
if (Array.isArray(result)) {
|
|
146
|
+
return result.map(deserializeJsonResponse);
|
|
147
|
+
}
|
|
148
|
+
if (typeof result === "object") {
|
|
149
|
+
if (isTaggedValue(result)) {
|
|
150
|
+
return deserializeTaggedValue(result);
|
|
151
|
+
}
|
|
152
|
+
if (result.constructor !== null && result.constructor.name !== "Object") {
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
return mapObjectValues(result, deserializeJsonResponse);
|
|
156
|
+
}
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
function deserializeTaggedValue({ $type, value }) {
|
|
160
|
+
switch ($type) {
|
|
161
|
+
case "BigInt":
|
|
162
|
+
return BigInt(value);
|
|
163
|
+
case "Bytes": {
|
|
164
|
+
const { buffer, byteOffset, byteLength } = Buffer.from(value, "base64");
|
|
165
|
+
return new Uint8Array(buffer, byteOffset, byteLength);
|
|
166
|
+
}
|
|
167
|
+
case "DateTime":
|
|
168
|
+
return new Date(value);
|
|
169
|
+
case "Decimal":
|
|
170
|
+
return new Decimal2(value);
|
|
171
|
+
case "Json":
|
|
172
|
+
return JSON.parse(value);
|
|
173
|
+
default:
|
|
174
|
+
assertNever(value, "Unknown tagged value");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// src/user-facing-error.ts
|
|
179
|
+
import { isDriverAdapterError } from "@prisma/driver-adapter-utils";
|
|
180
|
+
var UserFacingError = class extends Error {
|
|
181
|
+
name = "UserFacingError";
|
|
182
|
+
code;
|
|
183
|
+
meta;
|
|
184
|
+
constructor(message, code, meta) {
|
|
185
|
+
super(message);
|
|
186
|
+
this.code = code;
|
|
187
|
+
this.meta = meta ?? {};
|
|
188
|
+
}
|
|
189
|
+
toQueryResponseErrorObject() {
|
|
190
|
+
return {
|
|
191
|
+
error: this.message,
|
|
192
|
+
user_facing_error: {
|
|
193
|
+
is_panic: false,
|
|
194
|
+
message: this.message,
|
|
195
|
+
meta: this.meta,
|
|
196
|
+
error_code: this.code
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
function rethrowAsUserFacing(error) {
|
|
202
|
+
if (!isDriverAdapterError(error)) {
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
const code = getErrorCode(error);
|
|
206
|
+
const message = renderErrorMessage(error);
|
|
207
|
+
if (!code || !message) {
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
throw new UserFacingError(message, code, { driverAdapterError: error });
|
|
211
|
+
}
|
|
212
|
+
function rethrowAsUserFacingRawError(error) {
|
|
213
|
+
if (!isDriverAdapterError(error)) {
|
|
214
|
+
throw error;
|
|
215
|
+
}
|
|
216
|
+
throw new UserFacingError(
|
|
217
|
+
`Raw query failed. Code: \`${error.cause.originalCode ?? "N/A"}\`. Message: \`${error.cause.originalMessage ?? renderErrorMessage(error)}\``,
|
|
218
|
+
"P2010",
|
|
219
|
+
{ driverAdapterError: error }
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
function getErrorCode(err) {
|
|
223
|
+
switch (err.cause.kind) {
|
|
224
|
+
case "AuthenticationFailed":
|
|
225
|
+
return "P1000";
|
|
226
|
+
case "DatabaseNotReachable":
|
|
227
|
+
return "P1001";
|
|
228
|
+
case "DatabaseDoesNotExist":
|
|
229
|
+
return "P1003";
|
|
230
|
+
case "SocketTimeout":
|
|
231
|
+
return "P1008";
|
|
232
|
+
case "DatabaseAlreadyExists":
|
|
233
|
+
return "P1009";
|
|
234
|
+
case "DatabaseAccessDenied":
|
|
235
|
+
return "P1010";
|
|
236
|
+
case "TlsConnectionError":
|
|
237
|
+
return "P1011";
|
|
238
|
+
case "ConnectionClosed":
|
|
239
|
+
return "P1017";
|
|
240
|
+
case "TransactionAlreadyClosed":
|
|
241
|
+
return "P1018";
|
|
242
|
+
case "LengthMismatch":
|
|
243
|
+
return "P2000";
|
|
244
|
+
case "UniqueConstraintViolation":
|
|
245
|
+
return "P2002";
|
|
246
|
+
case "ForeignKeyConstraintViolation":
|
|
247
|
+
return "P2003";
|
|
248
|
+
case "UnsupportedNativeDataType":
|
|
249
|
+
return "P2010";
|
|
250
|
+
case "NullConstraintViolation":
|
|
251
|
+
return "P2011";
|
|
252
|
+
case "ValueOutOfRange":
|
|
253
|
+
return "P2020";
|
|
254
|
+
case "TableDoesNotExist":
|
|
255
|
+
return "P2021";
|
|
256
|
+
case "ColumnNotFound":
|
|
257
|
+
return "P2022";
|
|
258
|
+
case "InvalidIsolationLevel":
|
|
259
|
+
case "InconsistentColumnData":
|
|
260
|
+
return "P2023";
|
|
261
|
+
case "MissingFullTextSearchIndex":
|
|
262
|
+
return "P2030";
|
|
263
|
+
case "TransactionWriteConflict":
|
|
264
|
+
return "P2034";
|
|
265
|
+
case "GenericJs":
|
|
266
|
+
return "P2036";
|
|
267
|
+
case "TooManyConnections":
|
|
268
|
+
return "P2037";
|
|
269
|
+
case "postgres":
|
|
270
|
+
case "sqlite":
|
|
271
|
+
case "mysql":
|
|
272
|
+
case "mssql":
|
|
273
|
+
return;
|
|
274
|
+
default:
|
|
275
|
+
assertNever(err.cause, `Unknown error: ${err.cause}`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function renderErrorMessage(err) {
|
|
279
|
+
switch (err.cause.kind) {
|
|
280
|
+
case "AuthenticationFailed": {
|
|
281
|
+
const user = err.cause.user ?? "(not available)";
|
|
282
|
+
return `Authentication failed against the database server, the provided database credentials for \`${user}\` are not valid`;
|
|
283
|
+
}
|
|
284
|
+
case "DatabaseNotReachable": {
|
|
285
|
+
const address = err.cause.host && err.cause.port ? `${err.cause.host}:${err.cause.port}` : err.cause.host;
|
|
286
|
+
return `Can't reach database server${address ? ` at ${address}` : ""}`;
|
|
287
|
+
}
|
|
288
|
+
case "DatabaseDoesNotExist": {
|
|
289
|
+
const db = err.cause.db ?? "(not available)";
|
|
290
|
+
return `Database \`${db}\` does not exist on the database server`;
|
|
291
|
+
}
|
|
292
|
+
case "SocketTimeout":
|
|
293
|
+
return `Operation has timed out`;
|
|
294
|
+
case "DatabaseAlreadyExists": {
|
|
295
|
+
const db = err.cause.db ?? "(not available)";
|
|
296
|
+
return `Database \`${db}\` already exists on the database server`;
|
|
297
|
+
}
|
|
298
|
+
case "DatabaseAccessDenied": {
|
|
299
|
+
const db = err.cause.db ?? "(not available)";
|
|
300
|
+
return `User was denied access on the database \`${db}\``;
|
|
301
|
+
}
|
|
302
|
+
case "TlsConnectionError": {
|
|
303
|
+
return `Error opening a TLS connection: ${err.cause.reason}`;
|
|
304
|
+
}
|
|
305
|
+
case "ConnectionClosed": {
|
|
306
|
+
return "Server has closed the connection.";
|
|
307
|
+
}
|
|
308
|
+
case "TransactionAlreadyClosed":
|
|
309
|
+
return err.cause.cause;
|
|
310
|
+
case "LengthMismatch": {
|
|
311
|
+
const column = err.cause.column ?? "(not available)";
|
|
312
|
+
return `The provided value for the column is too long for the column's type. Column: ${column}`;
|
|
313
|
+
}
|
|
314
|
+
case "UniqueConstraintViolation":
|
|
315
|
+
return `Unique constraint failed on the ${renderConstraint(err.cause.constraint)}`;
|
|
316
|
+
case "ForeignKeyConstraintViolation":
|
|
317
|
+
return `Foreign key constraint violated on the ${renderConstraint(err.cause.constraint)}`;
|
|
318
|
+
case "UnsupportedNativeDataType":
|
|
319
|
+
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\`.`;
|
|
320
|
+
case "NullConstraintViolation":
|
|
321
|
+
return `Null constraint violation on the ${renderConstraint(err.cause.constraint)}`;
|
|
322
|
+
case "ValueOutOfRange":
|
|
323
|
+
return `Value out of range for the type: ${err.cause.cause}`;
|
|
324
|
+
case "TableDoesNotExist": {
|
|
325
|
+
const table = err.cause.table ?? "(not available)";
|
|
326
|
+
return `The table \`${table}\` does not exist in the current database.`;
|
|
327
|
+
}
|
|
328
|
+
case "ColumnNotFound": {
|
|
329
|
+
const column = err.cause.column ?? "(not available)";
|
|
330
|
+
return `The column \`${column}\` does not exist in the current database.`;
|
|
331
|
+
}
|
|
332
|
+
case "InvalidIsolationLevel":
|
|
333
|
+
return `Error in connector: Conversion error: ${err.cause.level}`;
|
|
334
|
+
case "InconsistentColumnData":
|
|
335
|
+
return `Inconsistent column data: ${err.cause.cause}`;
|
|
336
|
+
case "MissingFullTextSearchIndex":
|
|
337
|
+
return "Cannot find a fulltext index to use for the native search, try adding a @@fulltext([Fields...]) to your schema";
|
|
338
|
+
case "TransactionWriteConflict":
|
|
339
|
+
return `Transaction failed due to a write conflict or a deadlock. Please retry your transaction`;
|
|
340
|
+
case "GenericJs":
|
|
341
|
+
return `Error in external connector (id ${err.cause.id})`;
|
|
342
|
+
case "TooManyConnections":
|
|
343
|
+
return `Too many database connections opened: ${err.cause.cause}`;
|
|
344
|
+
case "sqlite":
|
|
345
|
+
case "postgres":
|
|
346
|
+
case "mysql":
|
|
347
|
+
case "mssql":
|
|
348
|
+
return;
|
|
349
|
+
default:
|
|
350
|
+
assertNever(err.cause, `Unknown error: ${err.cause}`);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
function renderConstraint(constraint) {
|
|
354
|
+
if (constraint && "fields" in constraint) {
|
|
355
|
+
return `fields: (${constraint.fields.map((field) => `\`${field}\``).join(", ")})`;
|
|
356
|
+
} else if (constraint && "index" in constraint) {
|
|
357
|
+
return `constraint: \`${constraint.index}\``;
|
|
358
|
+
} else if (constraint && "foreignKey" in constraint) {
|
|
359
|
+
return `foreign key`;
|
|
360
|
+
}
|
|
361
|
+
return "(not available)";
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// src/batch.ts
|
|
365
|
+
function convertCompactedRows(rows, compiledBatch) {
|
|
366
|
+
const keysPerRow = rows.map(
|
|
367
|
+
(item) => compiledBatch.keys.reduce((acc, key) => {
|
|
368
|
+
acc[key] = deserializeJsonResponse(item[key]);
|
|
369
|
+
return acc;
|
|
370
|
+
}, {})
|
|
371
|
+
);
|
|
372
|
+
const selection = new Set(compiledBatch.nestedSelection);
|
|
373
|
+
return compiledBatch.arguments.map((args) => {
|
|
374
|
+
const rowIndex = keysPerRow.findIndex((rowKeys) => doKeysMatch(rowKeys, args));
|
|
375
|
+
if (rowIndex === -1) {
|
|
376
|
+
if (compiledBatch.expectNonEmpty) {
|
|
377
|
+
return new UserFacingError(
|
|
378
|
+
"An operation failed because it depends on one or more records that were required but not found",
|
|
379
|
+
"P2025"
|
|
380
|
+
);
|
|
381
|
+
} else {
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
} else {
|
|
385
|
+
const selected = Object.entries(rows[rowIndex]).filter(([k]) => selection.has(k));
|
|
386
|
+
return Object.fromEntries(selected);
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// src/interpreter/data-mapper.ts
|
|
392
|
+
import Decimal3 from "decimal.js";
|
|
97
393
|
var DataMapperError = class extends Error {
|
|
98
394
|
name = "DataMapperError";
|
|
99
395
|
};
|
|
@@ -248,7 +544,7 @@ function mapValue(value, columnName, resultType, enums) {
|
|
|
248
544
|
throw new DataMapperError(`Expected a boolean in column '${columnName}', got ${typeof value}: ${value}`);
|
|
249
545
|
}
|
|
250
546
|
case "Decimal":
|
|
251
|
-
if (typeof value !== "number" && typeof value !== "string" && !
|
|
547
|
+
if (typeof value !== "number" && typeof value !== "string" && !Decimal3.isDecimal(value)) {
|
|
252
548
|
throw new DataMapperError(`Expected a decimal in column '${columnName}', got ${typeof value}: ${value}`);
|
|
253
549
|
}
|
|
254
550
|
return { $type: "Decimal", value };
|
|
@@ -372,192 +668,6 @@ async function withQuerySpanAndEvent({
|
|
|
372
668
|
);
|
|
373
669
|
}
|
|
374
670
|
|
|
375
|
-
// src/UserFacingError.ts
|
|
376
|
-
import { isDriverAdapterError } from "@prisma/driver-adapter-utils";
|
|
377
|
-
var UserFacingError = class extends Error {
|
|
378
|
-
name = "UserFacingError";
|
|
379
|
-
code;
|
|
380
|
-
meta;
|
|
381
|
-
constructor(message, code, meta) {
|
|
382
|
-
super(message);
|
|
383
|
-
this.code = code;
|
|
384
|
-
this.meta = meta ?? {};
|
|
385
|
-
}
|
|
386
|
-
toQueryResponseErrorObject() {
|
|
387
|
-
return {
|
|
388
|
-
error: this.message,
|
|
389
|
-
user_facing_error: {
|
|
390
|
-
is_panic: false,
|
|
391
|
-
message: this.message,
|
|
392
|
-
meta: this.meta,
|
|
393
|
-
error_code: this.code
|
|
394
|
-
}
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
};
|
|
398
|
-
function rethrowAsUserFacing(error) {
|
|
399
|
-
if (!isDriverAdapterError(error)) {
|
|
400
|
-
throw error;
|
|
401
|
-
}
|
|
402
|
-
const code = getErrorCode(error);
|
|
403
|
-
const message = renderErrorMessage(error);
|
|
404
|
-
if (!code || !message) {
|
|
405
|
-
throw error;
|
|
406
|
-
}
|
|
407
|
-
throw new UserFacingError(message, code, { driverAdapterError: error });
|
|
408
|
-
}
|
|
409
|
-
function rethrowAsUserFacingRawError(error) {
|
|
410
|
-
if (!isDriverAdapterError(error)) {
|
|
411
|
-
throw error;
|
|
412
|
-
}
|
|
413
|
-
throw new UserFacingError(
|
|
414
|
-
`Raw query failed. Code: \`${error.cause.originalCode ?? "N/A"}\`. Message: \`${error.cause.originalMessage ?? renderErrorMessage(error)}\``,
|
|
415
|
-
"P2010",
|
|
416
|
-
{ driverAdapterError: error }
|
|
417
|
-
);
|
|
418
|
-
}
|
|
419
|
-
function getErrorCode(err) {
|
|
420
|
-
switch (err.cause.kind) {
|
|
421
|
-
case "AuthenticationFailed":
|
|
422
|
-
return "P1000";
|
|
423
|
-
case "DatabaseNotReachable":
|
|
424
|
-
return "P1001";
|
|
425
|
-
case "DatabaseDoesNotExist":
|
|
426
|
-
return "P1003";
|
|
427
|
-
case "SocketTimeout":
|
|
428
|
-
return "P1008";
|
|
429
|
-
case "DatabaseAlreadyExists":
|
|
430
|
-
return "P1009";
|
|
431
|
-
case "DatabaseAccessDenied":
|
|
432
|
-
return "P1010";
|
|
433
|
-
case "TlsConnectionError":
|
|
434
|
-
return "P1011";
|
|
435
|
-
case "ConnectionClosed":
|
|
436
|
-
return "P1017";
|
|
437
|
-
case "TransactionAlreadyClosed":
|
|
438
|
-
return "P1018";
|
|
439
|
-
case "LengthMismatch":
|
|
440
|
-
return "P2000";
|
|
441
|
-
case "UniqueConstraintViolation":
|
|
442
|
-
return "P2002";
|
|
443
|
-
case "ForeignKeyConstraintViolation":
|
|
444
|
-
return "P2003";
|
|
445
|
-
case "UnsupportedNativeDataType":
|
|
446
|
-
return "P2010";
|
|
447
|
-
case "NullConstraintViolation":
|
|
448
|
-
return "P2011";
|
|
449
|
-
case "ValueOutOfRange":
|
|
450
|
-
return "P2020";
|
|
451
|
-
case "TableDoesNotExist":
|
|
452
|
-
return "P2021";
|
|
453
|
-
case "ColumnNotFound":
|
|
454
|
-
return "P2022";
|
|
455
|
-
case "InvalidIsolationLevel":
|
|
456
|
-
case "InconsistentColumnData":
|
|
457
|
-
return "P2023";
|
|
458
|
-
case "MissingFullTextSearchIndex":
|
|
459
|
-
return "P2030";
|
|
460
|
-
case "TransactionWriteConflict":
|
|
461
|
-
return "P2034";
|
|
462
|
-
case "GenericJs":
|
|
463
|
-
return "P2036";
|
|
464
|
-
case "TooManyConnections":
|
|
465
|
-
return "P2037";
|
|
466
|
-
case "postgres":
|
|
467
|
-
case "sqlite":
|
|
468
|
-
case "mysql":
|
|
469
|
-
case "mssql":
|
|
470
|
-
return;
|
|
471
|
-
default:
|
|
472
|
-
assertNever(err.cause, `Unknown error: ${err.cause}`);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
function renderErrorMessage(err) {
|
|
476
|
-
switch (err.cause.kind) {
|
|
477
|
-
case "AuthenticationFailed": {
|
|
478
|
-
const user = err.cause.user ?? "(not available)";
|
|
479
|
-
return `Authentication failed against the database server, the provided database credentials for \`${user}\` are not valid`;
|
|
480
|
-
}
|
|
481
|
-
case "DatabaseNotReachable": {
|
|
482
|
-
const address = err.cause.host && err.cause.port ? `${err.cause.host}:${err.cause.port}` : err.cause.host;
|
|
483
|
-
return `Can't reach database server${address ? ` at ${address}` : ""}`;
|
|
484
|
-
}
|
|
485
|
-
case "DatabaseDoesNotExist": {
|
|
486
|
-
const db = err.cause.db ?? "(not available)";
|
|
487
|
-
return `Database \`${db}\` does not exist on the database server`;
|
|
488
|
-
}
|
|
489
|
-
case "SocketTimeout":
|
|
490
|
-
return `Operation has timed out`;
|
|
491
|
-
case "DatabaseAlreadyExists": {
|
|
492
|
-
const db = err.cause.db ?? "(not available)";
|
|
493
|
-
return `Database \`${db}\` already exists on the database server`;
|
|
494
|
-
}
|
|
495
|
-
case "DatabaseAccessDenied": {
|
|
496
|
-
const db = err.cause.db ?? "(not available)";
|
|
497
|
-
return `User was denied access on the database \`${db}\``;
|
|
498
|
-
}
|
|
499
|
-
case "TlsConnectionError": {
|
|
500
|
-
return `Error opening a TLS connection: ${err.cause.reason}`;
|
|
501
|
-
}
|
|
502
|
-
case "ConnectionClosed": {
|
|
503
|
-
return "Server has closed the connection.";
|
|
504
|
-
}
|
|
505
|
-
case "TransactionAlreadyClosed":
|
|
506
|
-
return err.cause.cause;
|
|
507
|
-
case "LengthMismatch": {
|
|
508
|
-
const column = err.cause.column ?? "(not available)";
|
|
509
|
-
return `The provided value for the column is too long for the column's type. Column: ${column}`;
|
|
510
|
-
}
|
|
511
|
-
case "UniqueConstraintViolation":
|
|
512
|
-
return `Unique constraint failed on the ${renderConstraint(err.cause.constraint)}`;
|
|
513
|
-
case "ForeignKeyConstraintViolation":
|
|
514
|
-
return `Foreign key constraint violated on the ${renderConstraint(err.cause.constraint)}`;
|
|
515
|
-
case "UnsupportedNativeDataType":
|
|
516
|
-
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\`.`;
|
|
517
|
-
case "NullConstraintViolation":
|
|
518
|
-
return `Null constraint violation on the ${renderConstraint(err.cause.constraint)}`;
|
|
519
|
-
case "ValueOutOfRange":
|
|
520
|
-
return `Value out of range for the type: ${err.cause.cause}`;
|
|
521
|
-
case "TableDoesNotExist": {
|
|
522
|
-
const table = err.cause.table ?? "(not available)";
|
|
523
|
-
return `The table \`${table}\` does not exist in the current database.`;
|
|
524
|
-
}
|
|
525
|
-
case "ColumnNotFound": {
|
|
526
|
-
const column = err.cause.column ?? "(not available)";
|
|
527
|
-
return `The column \`${column}\` does not exist in the current database.`;
|
|
528
|
-
}
|
|
529
|
-
case "InvalidIsolationLevel":
|
|
530
|
-
return `Error in connector: Conversion error: ${err.cause.level}`;
|
|
531
|
-
case "InconsistentColumnData":
|
|
532
|
-
return `Inconsistent column data: ${err.cause.cause}`;
|
|
533
|
-
case "MissingFullTextSearchIndex":
|
|
534
|
-
return "Cannot find a fulltext index to use for the native search, try adding a @@fulltext([Fields...]) to your schema";
|
|
535
|
-
case "TransactionWriteConflict":
|
|
536
|
-
return `Transaction failed due to a write conflict or a deadlock. Please retry your transaction`;
|
|
537
|
-
case "GenericJs":
|
|
538
|
-
return `Error in external connector (id ${err.cause.id})`;
|
|
539
|
-
case "TooManyConnections":
|
|
540
|
-
return `Too many database connections opened: ${err.cause.cause}`;
|
|
541
|
-
case "sqlite":
|
|
542
|
-
case "postgres":
|
|
543
|
-
case "mysql":
|
|
544
|
-
case "mssql":
|
|
545
|
-
return;
|
|
546
|
-
default:
|
|
547
|
-
assertNever(err.cause, `Unknown error: ${err.cause}`);
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
function renderConstraint(constraint) {
|
|
551
|
-
if (constraint && "fields" in constraint) {
|
|
552
|
-
return `fields: (${constraint.fields.map((field) => `\`${field}\``).join(", ")})`;
|
|
553
|
-
} else if (constraint && "index" in constraint) {
|
|
554
|
-
return `constraint: \`${constraint.index}\``;
|
|
555
|
-
} else if (constraint && "foreignKey" in constraint) {
|
|
556
|
-
return `foreign key`;
|
|
557
|
-
}
|
|
558
|
-
return "(not available)";
|
|
559
|
-
}
|
|
560
|
-
|
|
561
671
|
// src/interpreter/generators.ts
|
|
562
672
|
import cuid1 from "@bugsnag/cuid";
|
|
563
673
|
import { createId as cuid2 } from "@paralleldrive/cuid2";
|
|
@@ -750,7 +860,7 @@ function getRecordKey(record, fields) {
|
|
|
750
860
|
return JSON.stringify(fields.map((field) => record[field]));
|
|
751
861
|
}
|
|
752
862
|
|
|
753
|
-
// src/
|
|
863
|
+
// src/query-plan.ts
|
|
754
864
|
function isPrismaValuePlaceholder(value) {
|
|
755
865
|
return typeof value === "object" && value !== null && value["prisma__type"] === "param";
|
|
756
866
|
}
|
|
@@ -764,7 +874,7 @@ function isPrismaValueBigInt(value) {
|
|
|
764
874
|
return typeof value === "object" && value !== null && value["prisma__type"] === "bigint";
|
|
765
875
|
}
|
|
766
876
|
|
|
767
|
-
// src/interpreter/
|
|
877
|
+
// src/interpreter/render-query.ts
|
|
768
878
|
function renderQuery(dbQuery, scope, generators, maxChunkSize) {
|
|
769
879
|
const queryType = dbQuery.type;
|
|
770
880
|
const params = evaluateParams(dbQuery.params, scope, generators);
|
|
@@ -1017,7 +1127,7 @@ function chunkArray(array, chunkSize) {
|
|
|
1017
1127
|
return result;
|
|
1018
1128
|
}
|
|
1019
1129
|
|
|
1020
|
-
// src/interpreter/
|
|
1130
|
+
// src/interpreter/serialize-sql.ts
|
|
1021
1131
|
import { ColumnTypeEnum } from "@prisma/driver-adapter-utils";
|
|
1022
1132
|
function serializeSql(resultSet) {
|
|
1023
1133
|
const mappers = resultSet.columnTypes.map((type) => {
|
|
@@ -1276,7 +1386,7 @@ function getErrorCode2(error) {
|
|
|
1276
1386
|
}
|
|
1277
1387
|
}
|
|
1278
1388
|
|
|
1279
|
-
// src/interpreter/
|
|
1389
|
+
// src/interpreter/query-interpreter.ts
|
|
1280
1390
|
var QueryInterpreter = class _QueryInterpreter {
|
|
1281
1391
|
#transactionManager;
|
|
1282
1392
|
#placeholderValues;
|
|
@@ -1654,53 +1764,6 @@ function evalFieldOperation(op, value, scope, generators) {
|
|
|
1654
1764
|
}
|
|
1655
1765
|
}
|
|
1656
1766
|
|
|
1657
|
-
// src/json-protocol.ts
|
|
1658
|
-
import { Decimal as Decimal3 } from "decimal.js";
|
|
1659
|
-
function normalizeJsonProtocolValues(result) {
|
|
1660
|
-
if (result === null) {
|
|
1661
|
-
return result;
|
|
1662
|
-
}
|
|
1663
|
-
if (Array.isArray(result)) {
|
|
1664
|
-
return result.map(normalizeJsonProtocolValues);
|
|
1665
|
-
}
|
|
1666
|
-
if (typeof result === "object") {
|
|
1667
|
-
if (isTaggedValue(result)) {
|
|
1668
|
-
return normalizeTaggedValue(result);
|
|
1669
|
-
}
|
|
1670
|
-
if (result.constructor !== null && result.constructor.name !== "Object") {
|
|
1671
|
-
return result;
|
|
1672
|
-
}
|
|
1673
|
-
return mapObjectValues(result, normalizeJsonProtocolValues);
|
|
1674
|
-
}
|
|
1675
|
-
return result;
|
|
1676
|
-
}
|
|
1677
|
-
function isTaggedValue(value) {
|
|
1678
|
-
return value !== null && typeof value == "object" && typeof value["$type"] === "string";
|
|
1679
|
-
}
|
|
1680
|
-
function normalizeTaggedValue({ $type, value }) {
|
|
1681
|
-
switch ($type) {
|
|
1682
|
-
case "BigInt":
|
|
1683
|
-
return { $type, value: String(value) };
|
|
1684
|
-
case "Bytes":
|
|
1685
|
-
return { $type, value };
|
|
1686
|
-
case "DateTime":
|
|
1687
|
-
return { $type, value: new Date(value).toISOString() };
|
|
1688
|
-
case "Decimal":
|
|
1689
|
-
return { $type, value: String(new Decimal3(value)) };
|
|
1690
|
-
case "Json":
|
|
1691
|
-
return { $type, value: JSON.stringify(JSON.parse(value)) };
|
|
1692
|
-
default:
|
|
1693
|
-
assertNever(value, "Unknown tagged value");
|
|
1694
|
-
}
|
|
1695
|
-
}
|
|
1696
|
-
function mapObjectValues(object, mapper) {
|
|
1697
|
-
const result = {};
|
|
1698
|
-
for (const key of Object.keys(object)) {
|
|
1699
|
-
result[key] = mapper(object[key], key);
|
|
1700
|
-
}
|
|
1701
|
-
return result;
|
|
1702
|
-
}
|
|
1703
|
-
|
|
1704
1767
|
// src/raw-json-protocol.ts
|
|
1705
1768
|
import Decimal4 from "decimal.js";
|
|
1706
1769
|
function normalizeRawJsonProtocolResponse(response) {
|
|
@@ -1730,7 +1793,7 @@ function normalizeValue(type, value) {
|
|
|
1730
1793
|
}
|
|
1731
1794
|
}
|
|
1732
1795
|
|
|
1733
|
-
// src/
|
|
1796
|
+
// src/transaction-manager/transaction-manager.ts
|
|
1734
1797
|
import { Debug } from "@prisma/debug";
|
|
1735
1798
|
|
|
1736
1799
|
// src/crypto.ts
|
|
@@ -1742,7 +1805,7 @@ async function randomUUID() {
|
|
|
1742
1805
|
return crypto.randomUUID();
|
|
1743
1806
|
}
|
|
1744
1807
|
|
|
1745
|
-
// src/
|
|
1808
|
+
// src/transaction-manager/transaction-manager-error.ts
|
|
1746
1809
|
var TransactionManagerError = class extends UserFacingError {
|
|
1747
1810
|
name = "TransactionManagerError";
|
|
1748
1811
|
constructor(message, meta) {
|
|
@@ -1795,7 +1858,7 @@ var InvalidTransactionIsolationLevelError = class extends TransactionManagerErro
|
|
|
1795
1858
|
}
|
|
1796
1859
|
};
|
|
1797
1860
|
|
|
1798
|
-
// src/
|
|
1861
|
+
// src/transaction-manager/transaction-manager.ts
|
|
1799
1862
|
var MAX_CLOSED_TRANSACTIONS = 100;
|
|
1800
1863
|
var debug = Debug("prisma:client:transactionManager");
|
|
1801
1864
|
var COMMIT_QUERY = () => ({ sql: "COMMIT", args: [], argTypes: [] });
|
|
@@ -1997,6 +2060,8 @@ export {
|
|
|
1997
2060
|
TransactionManager,
|
|
1998
2061
|
TransactionManagerError,
|
|
1999
2062
|
UserFacingError,
|
|
2063
|
+
convertCompactedRows,
|
|
2064
|
+
deserializeJsonResponse,
|
|
2000
2065
|
doKeysMatch,
|
|
2001
2066
|
isDeepStrictEqual,
|
|
2002
2067
|
isPrismaValueBigInt,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ConnectionInfo, SqlQueryable, SqlResultSet } from '@prisma/driver-adapter-utils';
|
|
2
2
|
import { QueryEvent } from '../events';
|
|
3
|
-
import { QueryPlanNode } from '../
|
|
3
|
+
import { QueryPlanNode } from '../query-plan';
|
|
4
4
|
import { type SchemaProvider } from '../schema';
|
|
5
5
|
import { type TracingHelper } from '../tracing';
|
|
6
|
-
import { type TransactionManager } from '../
|
|
6
|
+
import { type TransactionManager } from '../transaction-manager/transaction-manager';
|
|
7
7
|
import { Value } from './scope';
|
|
8
8
|
export type QueryInterpreterTransactionManager = {
|
|
9
9
|
enabled: true;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SqlQuery } from '@prisma/driver-adapter-utils';
|
|
2
|
-
import type { PrismaValue, QueryPlanDbQuery } from '../
|
|
2
|
+
import type { PrismaValue, QueryPlanDbQuery } from '../query-plan';
|
|
3
3
|
import { GeneratorRegistrySnapshot } from './generators';
|
|
4
4
|
import { ScopeBindings } from './scope';
|
|
5
5
|
export declare function renderQuery(dbQuery: QueryPlanDbQuery, scope: ScopeBindings, generators: GeneratorRegistrySnapshot, maxChunkSize?: number): SqlQuery[];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { DataRule, ValidationError } from '../
|
|
1
|
+
import { DataRule, ValidationError } from '../query-plan';
|
|
2
2
|
export declare function performValidation(data: unknown, rules: DataRule[], error: ValidationError): void;
|
|
3
3
|
export declare function doesSatisfyRule(data: unknown, rule: DataRule): boolean;
|
package/dist/json-protocol.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Decimal } from 'decimal.js';
|
|
1
2
|
export type DateTaggedValue = {
|
|
2
3
|
$type: 'DateTime';
|
|
3
4
|
value: string;
|
|
@@ -30,4 +31,8 @@ export type JsonTaggedValue = {
|
|
|
30
31
|
};
|
|
31
32
|
export type JsonInputTaggedValue = DateTaggedValue | DecimalTaggedValue | BytesTaggedValue | BigIntTaggedValue | FieldRefTaggedValue | JsonTaggedValue | EnumTaggedValue;
|
|
32
33
|
export type JsonOutputTaggedValue = DateTaggedValue | DecimalTaggedValue | BytesTaggedValue | BigIntTaggedValue | JsonTaggedValue;
|
|
34
|
+
export type JsOutputValue = null | string | number | boolean | bigint | Uint8Array | Date | Decimal | JsOutputValue[] | {
|
|
35
|
+
[key: string]: JsOutputValue;
|
|
36
|
+
};
|
|
33
37
|
export declare function normalizeJsonProtocolValues(result: unknown): unknown;
|
|
38
|
+
export declare function deserializeJsonResponse(result: unknown): unknown;
|