@prisma/client-engine-runtime 6.11.0-dev.4 → 6.11.0-dev.41

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.
@@ -59,7 +59,7 @@ export type ResultNode = {
59
59
  } | {
60
60
  type: 'Object';
61
61
  fields: Record<string, ResultNode>;
62
- flattened: boolean;
62
+ serializedName: string | null;
63
63
  } | {
64
64
  type: 'Value';
65
65
  dbName: string;
package/dist/index.d.mts CHANGED
@@ -336,7 +336,7 @@ export declare type ResultNode = {
336
336
  } | {
337
337
  type: 'Object';
338
338
  fields: Record<string, ResultNode>;
339
- flattened: boolean;
339
+ serializedName: string | null;
340
340
  } | {
341
341
  type: 'Value';
342
342
  dbName: string;
package/dist/index.d.ts CHANGED
@@ -336,7 +336,7 @@ export declare type ResultNode = {
336
336
  } | {
337
337
  type: 'Object';
338
338
  fields: Record<string, ResultNode>;
339
- flattened: boolean;
339
+ serializedName: string | null;
340
340
  } | {
341
341
  type: 'Value';
342
342
  dbName: string;
package/dist/index.js CHANGED
@@ -140,12 +140,12 @@ function mapObject(data, fields, enums) {
140
140
  throw new DataMapperError(`Unexpected 'AffectedRows' node in data mapping for field '${name}'`);
141
141
  }
142
142
  case "Object": {
143
- if (!node.flattened && !Object.hasOwn(data, name)) {
143
+ if (node.serializedName !== null && !Object.hasOwn(data, node.serializedName)) {
144
144
  throw new DataMapperError(
145
145
  `Missing data field (Object): '${name}'; node: ${JSON.stringify(node)}; data: ${JSON.stringify(data)}`
146
146
  );
147
147
  }
148
- const target = node.flattened ? data : data[name];
148
+ const target = node.serializedName !== null ? data[node.serializedName] : data;
149
149
  result[name] = mapArrayOrObject(target, node.fields, enums);
150
150
  break;
151
151
  }
@@ -230,6 +230,12 @@ function mapValue(value, columnName, resultType, enums) {
230
230
  throw new DataMapperError(`Expected a boolean in column '${columnName}', got ${typeof value}: ${value}`);
231
231
  }
232
232
  }
233
+ if (value instanceof Uint8Array) {
234
+ for (const byte of value) {
235
+ if (byte !== 0) return true;
236
+ }
237
+ return false;
238
+ }
233
239
  throw new DataMapperError(`Expected a boolean in column '${columnName}', got ${typeof value}: ${value}`);
234
240
  }
235
241
  case "Decimal":
@@ -267,6 +273,9 @@ function mapValue(value, columnName, resultType, enums) {
267
273
  if (Array.isArray(value)) {
268
274
  return { $type: "Bytes", value: Buffer.from(value).toString("base64") };
269
275
  }
276
+ if (value instanceof Uint8Array) {
277
+ return { $type: "Bytes", value: Buffer.from(value).toString("base64") };
278
+ }
270
279
  throw new DataMapperError(`Expected a byte array in column '${columnName}', got ${typeof value}: ${value}`);
271
280
  }
272
281
  case "Enum": {
@@ -468,7 +477,7 @@ function renderErrorMessage(err) {
468
477
  case "NullConstraintViolation":
469
478
  return `Null constraint violation on the ${renderConstraint(err.cause.constraint)}`;
470
479
  case "ValueOutOfRange":
471
- return `Value out of range for the type. ${err.cause.cause}`;
480
+ return `Value out of range for the type: ${err.cause.cause}`;
472
481
  case "TableDoesNotExist": {
473
482
  const table = err.cause.table ?? "(not available)";
474
483
  return `The table \`${table}\` does not exist in the current database.`;
@@ -764,8 +773,16 @@ function doesRequireEvaluation(param) {
764
773
  // src/interpreter/serializeSql.ts
765
774
  var import_driver_adapter_utils2 = require("@prisma/driver-adapter-utils");
766
775
  function serializeSql(resultSet) {
776
+ const mappers = resultSet.columnTypes.map((type) => {
777
+ switch (type) {
778
+ case import_driver_adapter_utils2.ColumnTypeEnum.Bytes:
779
+ return (value) => Array.isArray(value) ? new Uint8Array(value) : value;
780
+ default:
781
+ return (value) => value;
782
+ }
783
+ });
767
784
  return resultSet.rows.map(
768
- (row) => row.reduce((acc, value, index) => {
785
+ (row) => row.map((value, index) => mappers[index](value)).reduce((acc, value, index) => {
769
786
  const splitByDot = resultSet.columnNames[index].split(".");
770
787
  let nested = acc;
771
788
  for (let i = 0; i < splitByDot.length; i++) {
@@ -787,6 +804,8 @@ function serializeRawSql(resultSet) {
787
804
  const types = resultSet.columnTypes.map((type) => serializeColumnType(type));
788
805
  const mappers = types.map((type) => {
789
806
  switch (type) {
807
+ case "bytes":
808
+ return (value) => Array.isArray(value) ? new Uint8Array(value) : value;
790
809
  case "int":
791
810
  return (value) => value === null ? null : typeof value === "number" ? value : parseInt(`${value}`, 10);
792
811
  case "bigint":
@@ -1424,17 +1443,16 @@ var TransactionManager = class {
1424
1443
  transaction: void 0
1425
1444
  };
1426
1445
  this.transactions.set(transaction.id, transaction);
1427
- transaction.timer = this.startTransactionTimeout(transaction.id, validatedOptions.maxWait);
1428
- const startedTransaction = await this.driverAdapter.startTransaction(validatedOptions.isolationLevel);
1446
+ const startTimer = setTimeout(() => transaction.status = "timed_out", validatedOptions.maxWait);
1447
+ transaction.transaction = await this.driverAdapter.startTransaction(validatedOptions.isolationLevel);
1448
+ clearTimeout(startTimer);
1429
1449
  switch (transaction.status) {
1430
1450
  case "waiting":
1431
- transaction.transaction = startedTransaction;
1432
- clearTimeout(transaction.timer);
1433
- transaction.timer = void 0;
1434
1451
  transaction.status = "running";
1435
1452
  transaction.timer = this.startTransactionTimeout(transaction.id, validatedOptions.timeout);
1436
1453
  return { id: transaction.id };
1437
1454
  case "timed_out":
1455
+ await this.closeTransaction(transaction, "timed_out");
1438
1456
  throw new TransactionStartTimeoutError();
1439
1457
  case "running":
1440
1458
  case "committed":
@@ -1511,30 +1529,33 @@ var TransactionManager = class {
1511
1529
  async closeTransaction(tx, status) {
1512
1530
  debug("Closing transaction.", { transactionId: tx.id, status });
1513
1531
  tx.status = status;
1514
- if (tx.transaction && status === "committed") {
1515
- if (tx.transaction.options.usePhantomQuery) {
1516
- await this.#withQuerySpanAndEvent(PHANTOM_COMMIT_QUERY(), tx.transaction, () => tx.transaction.commit());
1517
- } else {
1518
- await tx.transaction.commit();
1519
- const query = COMMIT_QUERY();
1520
- await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query));
1532
+ try {
1533
+ if (tx.transaction && status === "committed") {
1534
+ if (tx.transaction.options.usePhantomQuery) {
1535
+ await this.#withQuerySpanAndEvent(PHANTOM_COMMIT_QUERY(), tx.transaction, () => tx.transaction.commit());
1536
+ } else {
1537
+ const query = COMMIT_QUERY();
1538
+ await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query));
1539
+ await tx.transaction.commit();
1540
+ }
1541
+ } else if (tx.transaction) {
1542
+ if (tx.transaction.options.usePhantomQuery) {
1543
+ await this.#withQuerySpanAndEvent(PHANTOM_ROLLBACK_QUERY(), tx.transaction, () => tx.transaction.rollback());
1544
+ } else {
1545
+ const query = ROLLBACK_QUERY();
1546
+ await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query));
1547
+ await tx.transaction.rollback();
1548
+ }
1521
1549
  }
1522
- } else if (tx.transaction) {
1523
- if (tx.transaction.options.usePhantomQuery) {
1524
- await this.#withQuerySpanAndEvent(PHANTOM_ROLLBACK_QUERY(), tx.transaction, () => tx.transaction.rollback());
1525
- } else {
1526
- await tx.transaction.rollback();
1527
- const query = ROLLBACK_QUERY();
1528
- await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query));
1550
+ } finally {
1551
+ clearTimeout(tx.timer);
1552
+ tx.timer = void 0;
1553
+ this.transactions.delete(tx.id);
1554
+ this.closedTransactions.push(tx);
1555
+ if (this.closedTransactions.length > MAX_CLOSED_TRANSACTIONS) {
1556
+ this.closedTransactions.shift();
1529
1557
  }
1530
1558
  }
1531
- clearTimeout(tx.timer);
1532
- tx.timer = void 0;
1533
- this.transactions.delete(tx.id);
1534
- this.closedTransactions.push(tx);
1535
- if (this.closedTransactions.length > MAX_CLOSED_TRANSACTIONS) {
1536
- this.closedTransactions.shift();
1537
- }
1538
1559
  }
1539
1560
  validateOptions(options) {
1540
1561
  if (!options.timeout) throw new TransactionManagerError("timeout is required");
package/dist/index.mjs CHANGED
@@ -92,12 +92,12 @@ function mapObject(data, fields, enums) {
92
92
  throw new DataMapperError(`Unexpected 'AffectedRows' node in data mapping for field '${name}'`);
93
93
  }
94
94
  case "Object": {
95
- if (!node.flattened && !Object.hasOwn(data, name)) {
95
+ if (node.serializedName !== null && !Object.hasOwn(data, node.serializedName)) {
96
96
  throw new DataMapperError(
97
97
  `Missing data field (Object): '${name}'; node: ${JSON.stringify(node)}; data: ${JSON.stringify(data)}`
98
98
  );
99
99
  }
100
- const target = node.flattened ? data : data[name];
100
+ const target = node.serializedName !== null ? data[node.serializedName] : data;
101
101
  result[name] = mapArrayOrObject(target, node.fields, enums);
102
102
  break;
103
103
  }
@@ -182,6 +182,12 @@ function mapValue(value, columnName, resultType, enums) {
182
182
  throw new DataMapperError(`Expected a boolean in column '${columnName}', got ${typeof value}: ${value}`);
183
183
  }
184
184
  }
185
+ if (value instanceof Uint8Array) {
186
+ for (const byte of value) {
187
+ if (byte !== 0) return true;
188
+ }
189
+ return false;
190
+ }
185
191
  throw new DataMapperError(`Expected a boolean in column '${columnName}', got ${typeof value}: ${value}`);
186
192
  }
187
193
  case "Decimal":
@@ -219,6 +225,9 @@ function mapValue(value, columnName, resultType, enums) {
219
225
  if (Array.isArray(value)) {
220
226
  return { $type: "Bytes", value: Buffer.from(value).toString("base64") };
221
227
  }
228
+ if (value instanceof Uint8Array) {
229
+ return { $type: "Bytes", value: Buffer.from(value).toString("base64") };
230
+ }
222
231
  throw new DataMapperError(`Expected a byte array in column '${columnName}', got ${typeof value}: ${value}`);
223
232
  }
224
233
  case "Enum": {
@@ -420,7 +429,7 @@ function renderErrorMessage(err) {
420
429
  case "NullConstraintViolation":
421
430
  return `Null constraint violation on the ${renderConstraint(err.cause.constraint)}`;
422
431
  case "ValueOutOfRange":
423
- return `Value out of range for the type. ${err.cause.cause}`;
432
+ return `Value out of range for the type: ${err.cause.cause}`;
424
433
  case "TableDoesNotExist": {
425
434
  const table = err.cause.table ?? "(not available)";
426
435
  return `The table \`${table}\` does not exist in the current database.`;
@@ -716,8 +725,16 @@ function doesRequireEvaluation(param) {
716
725
  // src/interpreter/serializeSql.ts
717
726
  import { ColumnTypeEnum } from "@prisma/driver-adapter-utils";
718
727
  function serializeSql(resultSet) {
728
+ const mappers = resultSet.columnTypes.map((type) => {
729
+ switch (type) {
730
+ case ColumnTypeEnum.Bytes:
731
+ return (value) => Array.isArray(value) ? new Uint8Array(value) : value;
732
+ default:
733
+ return (value) => value;
734
+ }
735
+ });
719
736
  return resultSet.rows.map(
720
- (row) => row.reduce((acc, value, index) => {
737
+ (row) => row.map((value, index) => mappers[index](value)).reduce((acc, value, index) => {
721
738
  const splitByDot = resultSet.columnNames[index].split(".");
722
739
  let nested = acc;
723
740
  for (let i = 0; i < splitByDot.length; i++) {
@@ -739,6 +756,8 @@ function serializeRawSql(resultSet) {
739
756
  const types = resultSet.columnTypes.map((type) => serializeColumnType(type));
740
757
  const mappers = types.map((type) => {
741
758
  switch (type) {
759
+ case "bytes":
760
+ return (value) => Array.isArray(value) ? new Uint8Array(value) : value;
742
761
  case "int":
743
762
  return (value) => value === null ? null : typeof value === "number" ? value : parseInt(`${value}`, 10);
744
763
  case "bigint":
@@ -1376,17 +1395,16 @@ var TransactionManager = class {
1376
1395
  transaction: void 0
1377
1396
  };
1378
1397
  this.transactions.set(transaction.id, transaction);
1379
- transaction.timer = this.startTransactionTimeout(transaction.id, validatedOptions.maxWait);
1380
- const startedTransaction = await this.driverAdapter.startTransaction(validatedOptions.isolationLevel);
1398
+ const startTimer = setTimeout(() => transaction.status = "timed_out", validatedOptions.maxWait);
1399
+ transaction.transaction = await this.driverAdapter.startTransaction(validatedOptions.isolationLevel);
1400
+ clearTimeout(startTimer);
1381
1401
  switch (transaction.status) {
1382
1402
  case "waiting":
1383
- transaction.transaction = startedTransaction;
1384
- clearTimeout(transaction.timer);
1385
- transaction.timer = void 0;
1386
1403
  transaction.status = "running";
1387
1404
  transaction.timer = this.startTransactionTimeout(transaction.id, validatedOptions.timeout);
1388
1405
  return { id: transaction.id };
1389
1406
  case "timed_out":
1407
+ await this.closeTransaction(transaction, "timed_out");
1390
1408
  throw new TransactionStartTimeoutError();
1391
1409
  case "running":
1392
1410
  case "committed":
@@ -1463,30 +1481,33 @@ var TransactionManager = class {
1463
1481
  async closeTransaction(tx, status) {
1464
1482
  debug("Closing transaction.", { transactionId: tx.id, status });
1465
1483
  tx.status = status;
1466
- if (tx.transaction && status === "committed") {
1467
- if (tx.transaction.options.usePhantomQuery) {
1468
- await this.#withQuerySpanAndEvent(PHANTOM_COMMIT_QUERY(), tx.transaction, () => tx.transaction.commit());
1469
- } else {
1470
- await tx.transaction.commit();
1471
- const query = COMMIT_QUERY();
1472
- await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query));
1484
+ try {
1485
+ if (tx.transaction && status === "committed") {
1486
+ if (tx.transaction.options.usePhantomQuery) {
1487
+ await this.#withQuerySpanAndEvent(PHANTOM_COMMIT_QUERY(), tx.transaction, () => tx.transaction.commit());
1488
+ } else {
1489
+ const query = COMMIT_QUERY();
1490
+ await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query));
1491
+ await tx.transaction.commit();
1492
+ }
1493
+ } else if (tx.transaction) {
1494
+ if (tx.transaction.options.usePhantomQuery) {
1495
+ await this.#withQuerySpanAndEvent(PHANTOM_ROLLBACK_QUERY(), tx.transaction, () => tx.transaction.rollback());
1496
+ } else {
1497
+ const query = ROLLBACK_QUERY();
1498
+ await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query));
1499
+ await tx.transaction.rollback();
1500
+ }
1473
1501
  }
1474
- } else if (tx.transaction) {
1475
- if (tx.transaction.options.usePhantomQuery) {
1476
- await this.#withQuerySpanAndEvent(PHANTOM_ROLLBACK_QUERY(), tx.transaction, () => tx.transaction.rollback());
1477
- } else {
1478
- await tx.transaction.rollback();
1479
- const query = ROLLBACK_QUERY();
1480
- await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query));
1502
+ } finally {
1503
+ clearTimeout(tx.timer);
1504
+ tx.timer = void 0;
1505
+ this.transactions.delete(tx.id);
1506
+ this.closedTransactions.push(tx);
1507
+ if (this.closedTransactions.length > MAX_CLOSED_TRANSACTIONS) {
1508
+ this.closedTransactions.shift();
1481
1509
  }
1482
1510
  }
1483
- clearTimeout(tx.timer);
1484
- tx.timer = void 0;
1485
- this.transactions.delete(tx.id);
1486
- this.closedTransactions.push(tx);
1487
- if (this.closedTransactions.length > MAX_CLOSED_TRANSACTIONS) {
1488
- this.closedTransactions.shift();
1489
- }
1490
1511
  }
1491
1512
  validateOptions(options) {
1492
1513
  if (!options.timeout) throw new TransactionManagerError("timeout is required");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/client-engine-runtime",
3
- "version": "6.11.0-dev.4",
3
+ "version": "6.11.0-dev.41",
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.11.0-dev.4",
35
- "@prisma/driver-adapter-utils": "6.11.0-dev.4"
34
+ "@prisma/debug": "6.11.0-dev.41",
35
+ "@prisma/driver-adapter-utils": "6.11.0-dev.41"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/jest": "29.5.14",