@prisma/client-engine-runtime 6.14.0-dev.36 → 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.
@@ -0,0 +1,19 @@
1
+ import { QueryPlanNode } from './query-plan';
2
+ export type BatchResponse = MultiBatchResponse | CompactedBatchResponse;
3
+ export type MultiBatchResponse = {
4
+ type: 'multi';
5
+ plans: QueryPlanNode[];
6
+ };
7
+ export type CompactedBatchResponse = {
8
+ type: 'compacted';
9
+ plan: QueryPlanNode;
10
+ arguments: Record<string, {}>[];
11
+ nestedSelection: string[];
12
+ keys: string[];
13
+ expectNonEmpty: boolean;
14
+ };
15
+ /**
16
+ * Converts the result of a compacted query back to result objects analogous to what queries
17
+ * would return when executed individually.
18
+ */
19
+ export declare function convertCompactedRows(rows: {}[], compiledBatch: CompactedBatchResponse): unknown[];
package/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { ConnectionInfo } from '@prisma/driver-adapter-utils';
2
2
  import { Context } from '@opentelemetry/api';
3
+ import { Decimal } from 'decimal.js';
3
4
  import type { IsolationLevel } from '@prisma/driver-adapter-utils';
4
5
  import { Span } from '@opentelemetry/api';
5
6
  import { SpanOptions } from '@opentelemetry/api';
@@ -8,6 +9,8 @@ import { SqlQueryable } from '@prisma/driver-adapter-utils';
8
9
  import { SqlResultSet } from '@prisma/driver-adapter-utils';
9
10
  import { Transaction } from '@prisma/driver-adapter-utils';
10
11
 
12
+ export declare type BatchResponse = MultiBatchResponse | CompactedBatchResponse;
13
+
11
14
  export declare type BigIntTaggedValue = {
12
15
  $type: 'BigInt';
13
16
  value: string;
@@ -18,6 +21,21 @@ export declare type BytesTaggedValue = {
18
21
  value: string;
19
22
  };
20
23
 
24
+ export declare type CompactedBatchResponse = {
25
+ type: 'compacted';
26
+ plan: QueryPlanNode;
27
+ arguments: Record<string, {}>[];
28
+ nestedSelection: string[];
29
+ keys: string[];
30
+ expectNonEmpty: boolean;
31
+ };
32
+
33
+ /**
34
+ * Converts the result of a compacted query back to result objects analogous to what queries
35
+ * would return when executed individually.
36
+ */
37
+ export declare function convertCompactedRows(rows: {}[], compiledBatch: CompactedBatchResponse): unknown[];
38
+
21
39
  export declare class DataMapperError extends Error {
22
40
  name: string;
23
41
  }
@@ -45,6 +63,8 @@ export declare type DecimalTaggedValue = {
45
63
  value: string;
46
64
  };
47
65
 
66
+ export declare function deserializeJsonResponse(result: unknown): unknown;
67
+
48
68
  /**
49
69
  * Checks if two objects representing the names and values of key columns match. A match is
50
70
  * defined by one of the sets of keys being a subset of the other. This function also
@@ -144,6 +164,15 @@ export declare type JsonTaggedValue = {
144
164
  value: string;
145
165
  };
146
166
 
167
+ export declare type JsOutputValue = null | string | number | boolean | bigint | Uint8Array | Date | Decimal | JsOutputValue[] | {
168
+ [key: string]: JsOutputValue;
169
+ };
170
+
171
+ export declare type MultiBatchResponse = {
172
+ type: 'multi';
173
+ plans: QueryPlanNode[];
174
+ };
175
+
147
176
  export declare const noopTracingHelper: TracingHelper;
148
177
 
149
178
  export declare function normalizeJsonProtocolValues(result: unknown): unknown;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { ConnectionInfo } from '@prisma/driver-adapter-utils';
2
2
  import { Context } from '@opentelemetry/api';
3
+ import { Decimal } from 'decimal.js';
3
4
  import type { IsolationLevel } from '@prisma/driver-adapter-utils';
4
5
  import { Span } from '@opentelemetry/api';
5
6
  import { SpanOptions } from '@opentelemetry/api';
@@ -8,6 +9,8 @@ import { SqlQueryable } from '@prisma/driver-adapter-utils';
8
9
  import { SqlResultSet } from '@prisma/driver-adapter-utils';
9
10
  import { Transaction } from '@prisma/driver-adapter-utils';
10
11
 
12
+ export declare type BatchResponse = MultiBatchResponse | CompactedBatchResponse;
13
+
11
14
  export declare type BigIntTaggedValue = {
12
15
  $type: 'BigInt';
13
16
  value: string;
@@ -18,6 +21,21 @@ export declare type BytesTaggedValue = {
18
21
  value: string;
19
22
  };
20
23
 
24
+ export declare type CompactedBatchResponse = {
25
+ type: 'compacted';
26
+ plan: QueryPlanNode;
27
+ arguments: Record<string, {}>[];
28
+ nestedSelection: string[];
29
+ keys: string[];
30
+ expectNonEmpty: boolean;
31
+ };
32
+
33
+ /**
34
+ * Converts the result of a compacted query back to result objects analogous to what queries
35
+ * would return when executed individually.
36
+ */
37
+ export declare function convertCompactedRows(rows: {}[], compiledBatch: CompactedBatchResponse): unknown[];
38
+
21
39
  export declare class DataMapperError extends Error {
22
40
  name: string;
23
41
  }
@@ -45,6 +63,8 @@ export declare type DecimalTaggedValue = {
45
63
  value: string;
46
64
  };
47
65
 
66
+ export declare function deserializeJsonResponse(result: unknown): unknown;
67
+
48
68
  /**
49
69
  * Checks if two objects representing the names and values of key columns match. A match is
50
70
  * defined by one of the sets of keys being a subset of the other. This function also
@@ -144,6 +164,15 @@ export declare type JsonTaggedValue = {
144
164
  value: string;
145
165
  };
146
166
 
167
+ export declare type JsOutputValue = null | string | number | boolean | bigint | Uint8Array | Date | Decimal | JsOutputValue[] | {
168
+ [key: string]: JsOutputValue;
169
+ };
170
+
171
+ export declare type MultiBatchResponse = {
172
+ type: 'multi';
173
+ plans: QueryPlanNode[];
174
+ };
175
+
147
176
  export declare const noopTracingHelper: TracingHelper;
148
177
 
149
178
  export declare function normalizeJsonProtocolValues(result: unknown): unknown;
package/dist/index.js CHANGED
@@ -35,6 +35,8 @@ __export(index_exports, {
35
35
  TransactionManager: () => TransactionManager,
36
36
  TransactionManagerError: () => TransactionManagerError,
37
37
  UserFacingError: () => UserFacingError,
38
+ convertCompactedRows: () => convertCompactedRows,
39
+ deserializeJsonResponse: () => deserializeJsonResponse,
38
40
  doKeysMatch: () => doKeysMatch,
39
41
  isDeepStrictEqual: () => isDeepStrictEqual,
40
42
  isPrismaValueBigInt: () => isPrismaValueBigInt,
@@ -48,8 +50,8 @@ __export(index_exports, {
48
50
  });
49
51
  module.exports = __toCommonJS(index_exports);
50
52
 
51
- // src/interpreter/data-mapper.ts
52
- var import_decimal2 = __toESM(require("decimal.js"));
53
+ // src/json-protocol.ts
54
+ var import_decimal2 = require("decimal.js");
53
55
 
54
56
  // src/utils.ts
55
57
  var import_decimal = __toESM(require("decimal.js"));
@@ -143,7 +145,303 @@ function safeJsonStringify(obj) {
143
145
  });
144
146
  }
145
147
 
148
+ // src/json-protocol.ts
149
+ function normalizeJsonProtocolValues(result) {
150
+ if (result === null) {
151
+ return result;
152
+ }
153
+ if (Array.isArray(result)) {
154
+ return result.map(normalizeJsonProtocolValues);
155
+ }
156
+ if (typeof result === "object") {
157
+ if (isTaggedValue(result)) {
158
+ return normalizeTaggedValue(result);
159
+ }
160
+ if (result.constructor !== null && result.constructor.name !== "Object") {
161
+ return result;
162
+ }
163
+ return mapObjectValues(result, normalizeJsonProtocolValues);
164
+ }
165
+ return result;
166
+ }
167
+ function isTaggedValue(value) {
168
+ return value !== null && typeof value == "object" && typeof value["$type"] === "string";
169
+ }
170
+ function normalizeTaggedValue({ $type, value }) {
171
+ switch ($type) {
172
+ case "BigInt":
173
+ return { $type, value: String(value) };
174
+ case "Bytes":
175
+ return { $type, value };
176
+ case "DateTime":
177
+ return { $type, value: new Date(value).toISOString() };
178
+ case "Decimal":
179
+ return { $type, value: String(new import_decimal2.Decimal(value)) };
180
+ case "Json":
181
+ return { $type, value: JSON.stringify(JSON.parse(value)) };
182
+ default:
183
+ assertNever(value, "Unknown tagged value");
184
+ }
185
+ }
186
+ function mapObjectValues(object, mapper) {
187
+ const result = {};
188
+ for (const key of Object.keys(object)) {
189
+ result[key] = mapper(object[key], key);
190
+ }
191
+ return result;
192
+ }
193
+ function deserializeJsonResponse(result) {
194
+ if (result === null) {
195
+ return result;
196
+ }
197
+ if (Array.isArray(result)) {
198
+ return result.map(deserializeJsonResponse);
199
+ }
200
+ if (typeof result === "object") {
201
+ if (isTaggedValue(result)) {
202
+ return deserializeTaggedValue(result);
203
+ }
204
+ if (result.constructor !== null && result.constructor.name !== "Object") {
205
+ return result;
206
+ }
207
+ return mapObjectValues(result, deserializeJsonResponse);
208
+ }
209
+ return result;
210
+ }
211
+ function deserializeTaggedValue({ $type, value }) {
212
+ switch ($type) {
213
+ case "BigInt":
214
+ return BigInt(value);
215
+ case "Bytes": {
216
+ const { buffer, byteOffset, byteLength } = Buffer.from(value, "base64");
217
+ return new Uint8Array(buffer, byteOffset, byteLength);
218
+ }
219
+ case "DateTime":
220
+ return new Date(value);
221
+ case "Decimal":
222
+ return new import_decimal2.Decimal(value);
223
+ case "Json":
224
+ return JSON.parse(value);
225
+ default:
226
+ assertNever(value, "Unknown tagged value");
227
+ }
228
+ }
229
+
230
+ // src/user-facing-error.ts
231
+ var import_driver_adapter_utils = require("@prisma/driver-adapter-utils");
232
+ var UserFacingError = class extends Error {
233
+ name = "UserFacingError";
234
+ code;
235
+ meta;
236
+ constructor(message, code, meta) {
237
+ super(message);
238
+ this.code = code;
239
+ this.meta = meta ?? {};
240
+ }
241
+ toQueryResponseErrorObject() {
242
+ return {
243
+ error: this.message,
244
+ user_facing_error: {
245
+ is_panic: false,
246
+ message: this.message,
247
+ meta: this.meta,
248
+ error_code: this.code
249
+ }
250
+ };
251
+ }
252
+ };
253
+ function rethrowAsUserFacing(error) {
254
+ if (!(0, import_driver_adapter_utils.isDriverAdapterError)(error)) {
255
+ throw error;
256
+ }
257
+ const code = getErrorCode(error);
258
+ const message = renderErrorMessage(error);
259
+ if (!code || !message) {
260
+ throw error;
261
+ }
262
+ throw new UserFacingError(message, code, { driverAdapterError: error });
263
+ }
264
+ function rethrowAsUserFacingRawError(error) {
265
+ if (!(0, import_driver_adapter_utils.isDriverAdapterError)(error)) {
266
+ throw error;
267
+ }
268
+ throw new UserFacingError(
269
+ `Raw query failed. Code: \`${error.cause.originalCode ?? "N/A"}\`. Message: \`${error.cause.originalMessage ?? renderErrorMessage(error)}\``,
270
+ "P2010",
271
+ { driverAdapterError: error }
272
+ );
273
+ }
274
+ function getErrorCode(err) {
275
+ switch (err.cause.kind) {
276
+ case "AuthenticationFailed":
277
+ return "P1000";
278
+ case "DatabaseNotReachable":
279
+ return "P1001";
280
+ case "DatabaseDoesNotExist":
281
+ return "P1003";
282
+ case "SocketTimeout":
283
+ return "P1008";
284
+ case "DatabaseAlreadyExists":
285
+ return "P1009";
286
+ case "DatabaseAccessDenied":
287
+ return "P1010";
288
+ case "TlsConnectionError":
289
+ return "P1011";
290
+ case "ConnectionClosed":
291
+ return "P1017";
292
+ case "TransactionAlreadyClosed":
293
+ return "P1018";
294
+ case "LengthMismatch":
295
+ return "P2000";
296
+ case "UniqueConstraintViolation":
297
+ return "P2002";
298
+ case "ForeignKeyConstraintViolation":
299
+ return "P2003";
300
+ case "UnsupportedNativeDataType":
301
+ return "P2010";
302
+ case "NullConstraintViolation":
303
+ return "P2011";
304
+ case "ValueOutOfRange":
305
+ return "P2020";
306
+ case "TableDoesNotExist":
307
+ return "P2021";
308
+ case "ColumnNotFound":
309
+ return "P2022";
310
+ case "InvalidIsolationLevel":
311
+ case "InconsistentColumnData":
312
+ return "P2023";
313
+ case "MissingFullTextSearchIndex":
314
+ return "P2030";
315
+ case "TransactionWriteConflict":
316
+ return "P2034";
317
+ case "GenericJs":
318
+ return "P2036";
319
+ case "TooManyConnections":
320
+ return "P2037";
321
+ case "postgres":
322
+ case "sqlite":
323
+ case "mysql":
324
+ case "mssql":
325
+ return;
326
+ default:
327
+ assertNever(err.cause, `Unknown error: ${err.cause}`);
328
+ }
329
+ }
330
+ function renderErrorMessage(err) {
331
+ switch (err.cause.kind) {
332
+ case "AuthenticationFailed": {
333
+ const user = err.cause.user ?? "(not available)";
334
+ return `Authentication failed against the database server, the provided database credentials for \`${user}\` are not valid`;
335
+ }
336
+ case "DatabaseNotReachable": {
337
+ const address = err.cause.host && err.cause.port ? `${err.cause.host}:${err.cause.port}` : err.cause.host;
338
+ return `Can't reach database server${address ? ` at ${address}` : ""}`;
339
+ }
340
+ case "DatabaseDoesNotExist": {
341
+ const db = err.cause.db ?? "(not available)";
342
+ return `Database \`${db}\` does not exist on the database server`;
343
+ }
344
+ case "SocketTimeout":
345
+ return `Operation has timed out`;
346
+ case "DatabaseAlreadyExists": {
347
+ const db = err.cause.db ?? "(not available)";
348
+ return `Database \`${db}\` already exists on the database server`;
349
+ }
350
+ case "DatabaseAccessDenied": {
351
+ const db = err.cause.db ?? "(not available)";
352
+ return `User was denied access on the database \`${db}\``;
353
+ }
354
+ case "TlsConnectionError": {
355
+ return `Error opening a TLS connection: ${err.cause.reason}`;
356
+ }
357
+ case "ConnectionClosed": {
358
+ return "Server has closed the connection.";
359
+ }
360
+ case "TransactionAlreadyClosed":
361
+ return err.cause.cause;
362
+ case "LengthMismatch": {
363
+ const column = err.cause.column ?? "(not available)";
364
+ return `The provided value for the column is too long for the column's type. Column: ${column}`;
365
+ }
366
+ case "UniqueConstraintViolation":
367
+ return `Unique constraint failed on the ${renderConstraint(err.cause.constraint)}`;
368
+ case "ForeignKeyConstraintViolation":
369
+ return `Foreign key constraint violated on the ${renderConstraint(err.cause.constraint)}`;
370
+ case "UnsupportedNativeDataType":
371
+ 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\`.`;
372
+ case "NullConstraintViolation":
373
+ return `Null constraint violation on the ${renderConstraint(err.cause.constraint)}`;
374
+ case "ValueOutOfRange":
375
+ return `Value out of range for the type: ${err.cause.cause}`;
376
+ case "TableDoesNotExist": {
377
+ const table = err.cause.table ?? "(not available)";
378
+ return `The table \`${table}\` does not exist in the current database.`;
379
+ }
380
+ case "ColumnNotFound": {
381
+ const column = err.cause.column ?? "(not available)";
382
+ return `The column \`${column}\` does not exist in the current database.`;
383
+ }
384
+ case "InvalidIsolationLevel":
385
+ return `Error in connector: Conversion error: ${err.cause.level}`;
386
+ case "InconsistentColumnData":
387
+ return `Inconsistent column data: ${err.cause.cause}`;
388
+ case "MissingFullTextSearchIndex":
389
+ return "Cannot find a fulltext index to use for the native search, try adding a @@fulltext([Fields...]) to your schema";
390
+ case "TransactionWriteConflict":
391
+ return `Transaction failed due to a write conflict or a deadlock. Please retry your transaction`;
392
+ case "GenericJs":
393
+ return `Error in external connector (id ${err.cause.id})`;
394
+ case "TooManyConnections":
395
+ return `Too many database connections opened: ${err.cause.cause}`;
396
+ case "sqlite":
397
+ case "postgres":
398
+ case "mysql":
399
+ case "mssql":
400
+ return;
401
+ default:
402
+ assertNever(err.cause, `Unknown error: ${err.cause}`);
403
+ }
404
+ }
405
+ function renderConstraint(constraint) {
406
+ if (constraint && "fields" in constraint) {
407
+ return `fields: (${constraint.fields.map((field) => `\`${field}\``).join(", ")})`;
408
+ } else if (constraint && "index" in constraint) {
409
+ return `constraint: \`${constraint.index}\``;
410
+ } else if (constraint && "foreignKey" in constraint) {
411
+ return `foreign key`;
412
+ }
413
+ return "(not available)";
414
+ }
415
+
416
+ // src/batch.ts
417
+ function convertCompactedRows(rows, compiledBatch) {
418
+ const keysPerRow = rows.map(
419
+ (item) => compiledBatch.keys.reduce((acc, key) => {
420
+ acc[key] = deserializeJsonResponse(item[key]);
421
+ return acc;
422
+ }, {})
423
+ );
424
+ const selection = new Set(compiledBatch.nestedSelection);
425
+ return compiledBatch.arguments.map((args) => {
426
+ const rowIndex = keysPerRow.findIndex((rowKeys) => doKeysMatch(rowKeys, args));
427
+ if (rowIndex === -1) {
428
+ if (compiledBatch.expectNonEmpty) {
429
+ return new UserFacingError(
430
+ "An operation failed because it depends on one or more records that were required but not found",
431
+ "P2025"
432
+ );
433
+ } else {
434
+ return null;
435
+ }
436
+ } else {
437
+ const selected = Object.entries(rows[rowIndex]).filter(([k]) => selection.has(k));
438
+ return Object.fromEntries(selected);
439
+ }
440
+ });
441
+ }
442
+
146
443
  // src/interpreter/data-mapper.ts
444
+ var import_decimal3 = __toESM(require("decimal.js"));
147
445
  var DataMapperError = class extends Error {
148
446
  name = "DataMapperError";
149
447
  };
@@ -298,7 +596,7 @@ function mapValue(value, columnName, resultType, enums) {
298
596
  throw new DataMapperError(`Expected a boolean in column '${columnName}', got ${typeof value}: ${value}`);
299
597
  }
300
598
  case "Decimal":
301
- if (typeof value !== "number" && typeof value !== "string" && !import_decimal2.default.isDecimal(value)) {
599
+ if (typeof value !== "number" && typeof value !== "string" && !import_decimal3.default.isDecimal(value)) {
302
600
  throw new DataMapperError(`Expected a decimal in column '${columnName}', got ${typeof value}: ${value}`);
303
601
  }
304
602
  return { $type: "Decimal", value };
@@ -422,192 +720,6 @@ async function withQuerySpanAndEvent({
422
720
  );
423
721
  }
424
722
 
425
- // src/user-facing-error.ts
426
- var import_driver_adapter_utils = require("@prisma/driver-adapter-utils");
427
- var UserFacingError = class extends Error {
428
- name = "UserFacingError";
429
- code;
430
- meta;
431
- constructor(message, code, meta) {
432
- super(message);
433
- this.code = code;
434
- this.meta = meta ?? {};
435
- }
436
- toQueryResponseErrorObject() {
437
- return {
438
- error: this.message,
439
- user_facing_error: {
440
- is_panic: false,
441
- message: this.message,
442
- meta: this.meta,
443
- error_code: this.code
444
- }
445
- };
446
- }
447
- };
448
- function rethrowAsUserFacing(error) {
449
- if (!(0, import_driver_adapter_utils.isDriverAdapterError)(error)) {
450
- throw error;
451
- }
452
- const code = getErrorCode(error);
453
- const message = renderErrorMessage(error);
454
- if (!code || !message) {
455
- throw error;
456
- }
457
- throw new UserFacingError(message, code, { driverAdapterError: error });
458
- }
459
- function rethrowAsUserFacingRawError(error) {
460
- if (!(0, import_driver_adapter_utils.isDriverAdapterError)(error)) {
461
- throw error;
462
- }
463
- throw new UserFacingError(
464
- `Raw query failed. Code: \`${error.cause.originalCode ?? "N/A"}\`. Message: \`${error.cause.originalMessage ?? renderErrorMessage(error)}\``,
465
- "P2010",
466
- { driverAdapterError: error }
467
- );
468
- }
469
- function getErrorCode(err) {
470
- switch (err.cause.kind) {
471
- case "AuthenticationFailed":
472
- return "P1000";
473
- case "DatabaseNotReachable":
474
- return "P1001";
475
- case "DatabaseDoesNotExist":
476
- return "P1003";
477
- case "SocketTimeout":
478
- return "P1008";
479
- case "DatabaseAlreadyExists":
480
- return "P1009";
481
- case "DatabaseAccessDenied":
482
- return "P1010";
483
- case "TlsConnectionError":
484
- return "P1011";
485
- case "ConnectionClosed":
486
- return "P1017";
487
- case "TransactionAlreadyClosed":
488
- return "P1018";
489
- case "LengthMismatch":
490
- return "P2000";
491
- case "UniqueConstraintViolation":
492
- return "P2002";
493
- case "ForeignKeyConstraintViolation":
494
- return "P2003";
495
- case "UnsupportedNativeDataType":
496
- return "P2010";
497
- case "NullConstraintViolation":
498
- return "P2011";
499
- case "ValueOutOfRange":
500
- return "P2020";
501
- case "TableDoesNotExist":
502
- return "P2021";
503
- case "ColumnNotFound":
504
- return "P2022";
505
- case "InvalidIsolationLevel":
506
- case "InconsistentColumnData":
507
- return "P2023";
508
- case "MissingFullTextSearchIndex":
509
- return "P2030";
510
- case "TransactionWriteConflict":
511
- return "P2034";
512
- case "GenericJs":
513
- return "P2036";
514
- case "TooManyConnections":
515
- return "P2037";
516
- case "postgres":
517
- case "sqlite":
518
- case "mysql":
519
- case "mssql":
520
- return;
521
- default:
522
- assertNever(err.cause, `Unknown error: ${err.cause}`);
523
- }
524
- }
525
- function renderErrorMessage(err) {
526
- switch (err.cause.kind) {
527
- case "AuthenticationFailed": {
528
- const user = err.cause.user ?? "(not available)";
529
- return `Authentication failed against the database server, the provided database credentials for \`${user}\` are not valid`;
530
- }
531
- case "DatabaseNotReachable": {
532
- const address = err.cause.host && err.cause.port ? `${err.cause.host}:${err.cause.port}` : err.cause.host;
533
- return `Can't reach database server${address ? ` at ${address}` : ""}`;
534
- }
535
- case "DatabaseDoesNotExist": {
536
- const db = err.cause.db ?? "(not available)";
537
- return `Database \`${db}\` does not exist on the database server`;
538
- }
539
- case "SocketTimeout":
540
- return `Operation has timed out`;
541
- case "DatabaseAlreadyExists": {
542
- const db = err.cause.db ?? "(not available)";
543
- return `Database \`${db}\` already exists on the database server`;
544
- }
545
- case "DatabaseAccessDenied": {
546
- const db = err.cause.db ?? "(not available)";
547
- return `User was denied access on the database \`${db}\``;
548
- }
549
- case "TlsConnectionError": {
550
- return `Error opening a TLS connection: ${err.cause.reason}`;
551
- }
552
- case "ConnectionClosed": {
553
- return "Server has closed the connection.";
554
- }
555
- case "TransactionAlreadyClosed":
556
- return err.cause.cause;
557
- case "LengthMismatch": {
558
- const column = err.cause.column ?? "(not available)";
559
- return `The provided value for the column is too long for the column's type. Column: ${column}`;
560
- }
561
- case "UniqueConstraintViolation":
562
- return `Unique constraint failed on the ${renderConstraint(err.cause.constraint)}`;
563
- case "ForeignKeyConstraintViolation":
564
- return `Foreign key constraint violated on the ${renderConstraint(err.cause.constraint)}`;
565
- case "UnsupportedNativeDataType":
566
- 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\`.`;
567
- case "NullConstraintViolation":
568
- return `Null constraint violation on the ${renderConstraint(err.cause.constraint)}`;
569
- case "ValueOutOfRange":
570
- return `Value out of range for the type: ${err.cause.cause}`;
571
- case "TableDoesNotExist": {
572
- const table = err.cause.table ?? "(not available)";
573
- return `The table \`${table}\` does not exist in the current database.`;
574
- }
575
- case "ColumnNotFound": {
576
- const column = err.cause.column ?? "(not available)";
577
- return `The column \`${column}\` does not exist in the current database.`;
578
- }
579
- case "InvalidIsolationLevel":
580
- return `Error in connector: Conversion error: ${err.cause.level}`;
581
- case "InconsistentColumnData":
582
- return `Inconsistent column data: ${err.cause.cause}`;
583
- case "MissingFullTextSearchIndex":
584
- return "Cannot find a fulltext index to use for the native search, try adding a @@fulltext([Fields...]) to your schema";
585
- case "TransactionWriteConflict":
586
- return `Transaction failed due to a write conflict or a deadlock. Please retry your transaction`;
587
- case "GenericJs":
588
- return `Error in external connector (id ${err.cause.id})`;
589
- case "TooManyConnections":
590
- return `Too many database connections opened: ${err.cause.cause}`;
591
- case "sqlite":
592
- case "postgres":
593
- case "mysql":
594
- case "mssql":
595
- return;
596
- default:
597
- assertNever(err.cause, `Unknown error: ${err.cause}`);
598
- }
599
- }
600
- function renderConstraint(constraint) {
601
- if (constraint && "fields" in constraint) {
602
- return `fields: (${constraint.fields.map((field) => `\`${field}\``).join(", ")})`;
603
- } else if (constraint && "index" in constraint) {
604
- return `constraint: \`${constraint.index}\``;
605
- } else if (constraint && "foreignKey" in constraint) {
606
- return `foreign key`;
607
- }
608
- return "(not available)";
609
- }
610
-
611
723
  // src/interpreter/generators.ts
612
724
  var import_cuid = __toESM(require("@bugsnag/cuid"));
613
725
  var import_cuid2 = require("@paralleldrive/cuid2");
@@ -1704,53 +1816,6 @@ function evalFieldOperation(op, value, scope, generators) {
1704
1816
  }
1705
1817
  }
1706
1818
 
1707
- // src/json-protocol.ts
1708
- var import_decimal3 = require("decimal.js");
1709
- function normalizeJsonProtocolValues(result) {
1710
- if (result === null) {
1711
- return result;
1712
- }
1713
- if (Array.isArray(result)) {
1714
- return result.map(normalizeJsonProtocolValues);
1715
- }
1716
- if (typeof result === "object") {
1717
- if (isTaggedValue(result)) {
1718
- return normalizeTaggedValue(result);
1719
- }
1720
- if (result.constructor !== null && result.constructor.name !== "Object") {
1721
- return result;
1722
- }
1723
- return mapObjectValues(result, normalizeJsonProtocolValues);
1724
- }
1725
- return result;
1726
- }
1727
- function isTaggedValue(value) {
1728
- return value !== null && typeof value == "object" && typeof value["$type"] === "string";
1729
- }
1730
- function normalizeTaggedValue({ $type, value }) {
1731
- switch ($type) {
1732
- case "BigInt":
1733
- return { $type, value: String(value) };
1734
- case "Bytes":
1735
- return { $type, value };
1736
- case "DateTime":
1737
- return { $type, value: new Date(value).toISOString() };
1738
- case "Decimal":
1739
- return { $type, value: String(new import_decimal3.Decimal(value)) };
1740
- case "Json":
1741
- return { $type, value: JSON.stringify(JSON.parse(value)) };
1742
- default:
1743
- assertNever(value, "Unknown tagged value");
1744
- }
1745
- }
1746
- function mapObjectValues(object, mapper) {
1747
- const result = {};
1748
- for (const key of Object.keys(object)) {
1749
- result[key] = mapper(object[key], key);
1750
- }
1751
- return result;
1752
- }
1753
-
1754
1819
  // src/raw-json-protocol.ts
1755
1820
  var import_decimal4 = __toESM(require("decimal.js"));
1756
1821
  function normalizeRawJsonProtocolResponse(response) {
@@ -2048,6 +2113,8 @@ var TransactionManager = class {
2048
2113
  TransactionManager,
2049
2114
  TransactionManagerError,
2050
2115
  UserFacingError,
2116
+ convertCompactedRows,
2117
+ deserializeJsonResponse,
2051
2118
  doKeysMatch,
2052
2119
  isDeepStrictEqual,
2053
2120
  isPrismaValueBigInt,
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- // src/interpreter/data-mapper.ts
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/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
+
96
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" && !Decimal2.isDecimal(value)) {
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/user-facing-error.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";
@@ -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) {
@@ -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,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;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/client-engine-runtime",
3
- "version": "6.14.0-dev.36",
3
+ "version": "6.14.0-dev.37",
4
4
  "description": "This package is intended for Prisma's internal use",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -31,8 +31,8 @@
31
31
  "nanoid": "5.1.5",
32
32
  "ulid": "3.0.0",
33
33
  "uuid": "11.1.0",
34
- "@prisma/debug": "6.14.0-dev.36",
35
- "@prisma/driver-adapter-utils": "6.14.0-dev.36"
34
+ "@prisma/debug": "6.14.0-dev.37",
35
+ "@prisma/driver-adapter-utils": "6.14.0-dev.37"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/jest": "29.5.14",