@prisma/client-engine-runtime 6.11.0-dev.18 → 6.11.0-dev.2

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/index.js CHANGED
@@ -230,12 +230,6 @@ 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
- }
239
233
  throw new DataMapperError(`Expected a boolean in column '${columnName}', got ${typeof value}: ${value}`);
240
234
  }
241
235
  case "Decimal":
@@ -273,9 +267,6 @@ function mapValue(value, columnName, resultType, enums) {
273
267
  if (Array.isArray(value)) {
274
268
  return { $type: "Bytes", value: Buffer.from(value).toString("base64") };
275
269
  }
276
- if (value instanceof Uint8Array) {
277
- return { $type: "Bytes", value: Buffer.from(value).toString("base64") };
278
- }
279
270
  throw new DataMapperError(`Expected a byte array in column '${columnName}', got ${typeof value}: ${value}`);
280
271
  }
281
272
  case "Enum": {
@@ -773,16 +764,8 @@ function doesRequireEvaluation(param) {
773
764
  // src/interpreter/serializeSql.ts
774
765
  var import_driver_adapter_utils2 = require("@prisma/driver-adapter-utils");
775
766
  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
- });
784
767
  return resultSet.rows.map(
785
- (row) => row.map((value, index) => mappers[index](value)).reduce((acc, value, index) => {
768
+ (row) => row.reduce((acc, value, index) => {
786
769
  const splitByDot = resultSet.columnNames[index].split(".");
787
770
  let nested = acc;
788
771
  for (let i = 0; i < splitByDot.length; i++) {
@@ -1110,7 +1093,13 @@ var QueryInterpreter = class _QueryInterpreter {
1110
1093
  childRecords: (await this.interpretNode(joinExpr.child, queryable, scope, generators)).value
1111
1094
  }))
1112
1095
  );
1113
- return { value: attachChildrenToParents(parent, children), lastInsertId };
1096
+ if (Array.isArray(parent)) {
1097
+ for (const record of parent) {
1098
+ attachChildrenToParent(asRecord(record), children);
1099
+ }
1100
+ return { value: parent, lastInsertId };
1101
+ }
1102
+ return { value: attachChildrenToParent(asRecord(parent), children), lastInsertId };
1114
1103
  }
1115
1104
  case "transaction": {
1116
1105
  if (!this.#transactionManager.enabled) {
@@ -1252,39 +1241,34 @@ function mapField(value, field) {
1252
1241
  }
1253
1242
  return value;
1254
1243
  }
1255
- function attachChildrenToParents(parentRecords, children) {
1244
+ function attachChildrenToParent(parentRecord, children) {
1256
1245
  for (const { joinExpr, childRecords } of children) {
1257
- const parentKeys = joinExpr.on.map(([k]) => k);
1258
- const childKeys = joinExpr.on.map(([, k]) => k);
1259
- const parentMap = {};
1260
- for (const parent of Array.isArray(parentRecords) ? parentRecords : [parentRecords]) {
1261
- const parentRecord = asRecord(parent);
1262
- const key = getRecordKey(parentRecord, parentKeys);
1263
- if (!parentMap[key]) {
1264
- parentMap[key] = [];
1265
- }
1266
- parentMap[key].push(parentRecord);
1267
- if (joinExpr.isRelationUnique) {
1268
- parentRecord[joinExpr.parentField] = null;
1269
- } else {
1270
- parentRecord[joinExpr.parentField] = [];
1271
- }
1246
+ parentRecord[joinExpr.parentField] = filterChildRecords(childRecords, parentRecord, joinExpr);
1247
+ }
1248
+ return parentRecord;
1249
+ }
1250
+ function filterChildRecords(records, parentRecord, joinExpr) {
1251
+ if (Array.isArray(records)) {
1252
+ const filtered = records.filter((record) => childRecordMatchesParent(asRecord(record), parentRecord, joinExpr));
1253
+ if (joinExpr.isRelationUnique) {
1254
+ return filtered.length > 0 ? filtered[0] : null;
1255
+ } else {
1256
+ return filtered;
1272
1257
  }
1273
- for (const childRecord of Array.isArray(childRecords) ? childRecords : [childRecords]) {
1274
- if (childRecord === null) {
1275
- continue;
1276
- }
1277
- const key = getRecordKey(asRecord(childRecord), childKeys);
1278
- for (const parentRecord of parentMap[key] ?? []) {
1279
- if (joinExpr.isRelationUnique) {
1280
- parentRecord[joinExpr.parentField] = childRecord;
1281
- } else {
1282
- parentRecord[joinExpr.parentField].push(childRecord);
1283
- }
1284
- }
1258
+ } else if (records === null) {
1259
+ return null;
1260
+ } else {
1261
+ const record = asRecord(records);
1262
+ return childRecordMatchesParent(record, parentRecord, joinExpr) ? record : null;
1263
+ }
1264
+ }
1265
+ function childRecordMatchesParent(childRecord, parentRecord, joinExpr) {
1266
+ for (const [parentField, childField] of joinExpr.on) {
1267
+ if (parentRecord[parentField] !== childRecord[childField]) {
1268
+ return false;
1285
1269
  }
1286
1270
  }
1287
- return parentRecords;
1271
+ return true;
1288
1272
  }
1289
1273
  function paginate(list, { cursor, skip, take }) {
1290
1274
  const cursorIndex = cursor !== null ? list.findIndex((item) => doKeysMatch(item, cursor)) : 0;
@@ -1441,16 +1425,17 @@ var TransactionManager = class {
1441
1425
  transaction: void 0
1442
1426
  };
1443
1427
  this.transactions.set(transaction.id, transaction);
1444
- const startTimer = setTimeout(() => transaction.status = "timed_out", validatedOptions.maxWait);
1445
- transaction.transaction = await this.driverAdapter.startTransaction(validatedOptions.isolationLevel);
1446
- clearTimeout(startTimer);
1428
+ transaction.timer = this.startTransactionTimeout(transaction.id, validatedOptions.maxWait);
1429
+ const startedTransaction = await this.driverAdapter.startTransaction(validatedOptions.isolationLevel);
1447
1430
  switch (transaction.status) {
1448
1431
  case "waiting":
1432
+ transaction.transaction = startedTransaction;
1433
+ clearTimeout(transaction.timer);
1434
+ transaction.timer = void 0;
1449
1435
  transaction.status = "running";
1450
1436
  transaction.timer = this.startTransactionTimeout(transaction.id, validatedOptions.timeout);
1451
1437
  return { id: transaction.id };
1452
1438
  case "timed_out":
1453
- await this.closeTransaction(transaction, "timed_out");
1454
1439
  throw new TransactionStartTimeoutError();
1455
1440
  case "running":
1456
1441
  case "committed":
@@ -1527,33 +1512,30 @@ var TransactionManager = class {
1527
1512
  async closeTransaction(tx, status) {
1528
1513
  debug("Closing transaction.", { transactionId: tx.id, status });
1529
1514
  tx.status = status;
1530
- try {
1531
- if (tx.transaction && status === "committed") {
1532
- if (tx.transaction.options.usePhantomQuery) {
1533
- await this.#withQuerySpanAndEvent(PHANTOM_COMMIT_QUERY(), tx.transaction, () => tx.transaction.commit());
1534
- } else {
1535
- const query = COMMIT_QUERY();
1536
- await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query));
1537
- await tx.transaction.commit();
1538
- }
1539
- } else if (tx.transaction) {
1540
- if (tx.transaction.options.usePhantomQuery) {
1541
- await this.#withQuerySpanAndEvent(PHANTOM_ROLLBACK_QUERY(), tx.transaction, () => tx.transaction.rollback());
1542
- } else {
1543
- const query = ROLLBACK_QUERY();
1544
- await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query));
1545
- await tx.transaction.rollback();
1546
- }
1515
+ if (tx.transaction && status === "committed") {
1516
+ if (tx.transaction.options.usePhantomQuery) {
1517
+ await this.#withQuerySpanAndEvent(PHANTOM_COMMIT_QUERY(), tx.transaction, () => tx.transaction.commit());
1518
+ } else {
1519
+ await tx.transaction.commit();
1520
+ const query = COMMIT_QUERY();
1521
+ await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query));
1547
1522
  }
1548
- } finally {
1549
- clearTimeout(tx.timer);
1550
- tx.timer = void 0;
1551
- this.transactions.delete(tx.id);
1552
- this.closedTransactions.push(tx);
1553
- if (this.closedTransactions.length > MAX_CLOSED_TRANSACTIONS) {
1554
- this.closedTransactions.shift();
1523
+ } else if (tx.transaction) {
1524
+ if (tx.transaction.options.usePhantomQuery) {
1525
+ await this.#withQuerySpanAndEvent(PHANTOM_ROLLBACK_QUERY(), tx.transaction, () => tx.transaction.rollback());
1526
+ } else {
1527
+ await tx.transaction.rollback();
1528
+ const query = ROLLBACK_QUERY();
1529
+ await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query));
1555
1530
  }
1556
1531
  }
1532
+ clearTimeout(tx.timer);
1533
+ tx.timer = void 0;
1534
+ this.transactions.delete(tx.id);
1535
+ this.closedTransactions.push(tx);
1536
+ if (this.closedTransactions.length > MAX_CLOSED_TRANSACTIONS) {
1537
+ this.closedTransactions.shift();
1538
+ }
1557
1539
  }
1558
1540
  validateOptions(options) {
1559
1541
  if (!options.timeout) throw new TransactionManagerError("timeout is required");
package/dist/index.mjs CHANGED
@@ -182,12 +182,6 @@ 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
- }
191
185
  throw new DataMapperError(`Expected a boolean in column '${columnName}', got ${typeof value}: ${value}`);
192
186
  }
193
187
  case "Decimal":
@@ -225,9 +219,6 @@ function mapValue(value, columnName, resultType, enums) {
225
219
  if (Array.isArray(value)) {
226
220
  return { $type: "Bytes", value: Buffer.from(value).toString("base64") };
227
221
  }
228
- if (value instanceof Uint8Array) {
229
- return { $type: "Bytes", value: Buffer.from(value).toString("base64") };
230
- }
231
222
  throw new DataMapperError(`Expected a byte array in column '${columnName}', got ${typeof value}: ${value}`);
232
223
  }
233
224
  case "Enum": {
@@ -725,16 +716,8 @@ function doesRequireEvaluation(param) {
725
716
  // src/interpreter/serializeSql.ts
726
717
  import { ColumnTypeEnum } from "@prisma/driver-adapter-utils";
727
718
  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
- });
736
719
  return resultSet.rows.map(
737
- (row) => row.map((value, index) => mappers[index](value)).reduce((acc, value, index) => {
720
+ (row) => row.reduce((acc, value, index) => {
738
721
  const splitByDot = resultSet.columnNames[index].split(".");
739
722
  let nested = acc;
740
723
  for (let i = 0; i < splitByDot.length; i++) {
@@ -1062,7 +1045,13 @@ var QueryInterpreter = class _QueryInterpreter {
1062
1045
  childRecords: (await this.interpretNode(joinExpr.child, queryable, scope, generators)).value
1063
1046
  }))
1064
1047
  );
1065
- return { value: attachChildrenToParents(parent, children), lastInsertId };
1048
+ if (Array.isArray(parent)) {
1049
+ for (const record of parent) {
1050
+ attachChildrenToParent(asRecord(record), children);
1051
+ }
1052
+ return { value: parent, lastInsertId };
1053
+ }
1054
+ return { value: attachChildrenToParent(asRecord(parent), children), lastInsertId };
1066
1055
  }
1067
1056
  case "transaction": {
1068
1057
  if (!this.#transactionManager.enabled) {
@@ -1204,39 +1193,34 @@ function mapField(value, field) {
1204
1193
  }
1205
1194
  return value;
1206
1195
  }
1207
- function attachChildrenToParents(parentRecords, children) {
1196
+ function attachChildrenToParent(parentRecord, children) {
1208
1197
  for (const { joinExpr, childRecords } of children) {
1209
- const parentKeys = joinExpr.on.map(([k]) => k);
1210
- const childKeys = joinExpr.on.map(([, k]) => k);
1211
- const parentMap = {};
1212
- for (const parent of Array.isArray(parentRecords) ? parentRecords : [parentRecords]) {
1213
- const parentRecord = asRecord(parent);
1214
- const key = getRecordKey(parentRecord, parentKeys);
1215
- if (!parentMap[key]) {
1216
- parentMap[key] = [];
1217
- }
1218
- parentMap[key].push(parentRecord);
1219
- if (joinExpr.isRelationUnique) {
1220
- parentRecord[joinExpr.parentField] = null;
1221
- } else {
1222
- parentRecord[joinExpr.parentField] = [];
1223
- }
1198
+ parentRecord[joinExpr.parentField] = filterChildRecords(childRecords, parentRecord, joinExpr);
1199
+ }
1200
+ return parentRecord;
1201
+ }
1202
+ function filterChildRecords(records, parentRecord, joinExpr) {
1203
+ if (Array.isArray(records)) {
1204
+ const filtered = records.filter((record) => childRecordMatchesParent(asRecord(record), parentRecord, joinExpr));
1205
+ if (joinExpr.isRelationUnique) {
1206
+ return filtered.length > 0 ? filtered[0] : null;
1207
+ } else {
1208
+ return filtered;
1224
1209
  }
1225
- for (const childRecord of Array.isArray(childRecords) ? childRecords : [childRecords]) {
1226
- if (childRecord === null) {
1227
- continue;
1228
- }
1229
- const key = getRecordKey(asRecord(childRecord), childKeys);
1230
- for (const parentRecord of parentMap[key] ?? []) {
1231
- if (joinExpr.isRelationUnique) {
1232
- parentRecord[joinExpr.parentField] = childRecord;
1233
- } else {
1234
- parentRecord[joinExpr.parentField].push(childRecord);
1235
- }
1236
- }
1210
+ } else if (records === null) {
1211
+ return null;
1212
+ } else {
1213
+ const record = asRecord(records);
1214
+ return childRecordMatchesParent(record, parentRecord, joinExpr) ? record : null;
1215
+ }
1216
+ }
1217
+ function childRecordMatchesParent(childRecord, parentRecord, joinExpr) {
1218
+ for (const [parentField, childField] of joinExpr.on) {
1219
+ if (parentRecord[parentField] !== childRecord[childField]) {
1220
+ return false;
1237
1221
  }
1238
1222
  }
1239
- return parentRecords;
1223
+ return true;
1240
1224
  }
1241
1225
  function paginate(list, { cursor, skip, take }) {
1242
1226
  const cursorIndex = cursor !== null ? list.findIndex((item) => doKeysMatch(item, cursor)) : 0;
@@ -1393,16 +1377,17 @@ var TransactionManager = class {
1393
1377
  transaction: void 0
1394
1378
  };
1395
1379
  this.transactions.set(transaction.id, transaction);
1396
- const startTimer = setTimeout(() => transaction.status = "timed_out", validatedOptions.maxWait);
1397
- transaction.transaction = await this.driverAdapter.startTransaction(validatedOptions.isolationLevel);
1398
- clearTimeout(startTimer);
1380
+ transaction.timer = this.startTransactionTimeout(transaction.id, validatedOptions.maxWait);
1381
+ const startedTransaction = await this.driverAdapter.startTransaction(validatedOptions.isolationLevel);
1399
1382
  switch (transaction.status) {
1400
1383
  case "waiting":
1384
+ transaction.transaction = startedTransaction;
1385
+ clearTimeout(transaction.timer);
1386
+ transaction.timer = void 0;
1401
1387
  transaction.status = "running";
1402
1388
  transaction.timer = this.startTransactionTimeout(transaction.id, validatedOptions.timeout);
1403
1389
  return { id: transaction.id };
1404
1390
  case "timed_out":
1405
- await this.closeTransaction(transaction, "timed_out");
1406
1391
  throw new TransactionStartTimeoutError();
1407
1392
  case "running":
1408
1393
  case "committed":
@@ -1479,33 +1464,30 @@ var TransactionManager = class {
1479
1464
  async closeTransaction(tx, status) {
1480
1465
  debug("Closing transaction.", { transactionId: tx.id, status });
1481
1466
  tx.status = status;
1482
- try {
1483
- if (tx.transaction && status === "committed") {
1484
- if (tx.transaction.options.usePhantomQuery) {
1485
- await this.#withQuerySpanAndEvent(PHANTOM_COMMIT_QUERY(), tx.transaction, () => tx.transaction.commit());
1486
- } else {
1487
- const query = COMMIT_QUERY();
1488
- await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query));
1489
- await tx.transaction.commit();
1490
- }
1491
- } else if (tx.transaction) {
1492
- if (tx.transaction.options.usePhantomQuery) {
1493
- await this.#withQuerySpanAndEvent(PHANTOM_ROLLBACK_QUERY(), tx.transaction, () => tx.transaction.rollback());
1494
- } else {
1495
- const query = ROLLBACK_QUERY();
1496
- await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query));
1497
- await tx.transaction.rollback();
1498
- }
1467
+ if (tx.transaction && status === "committed") {
1468
+ if (tx.transaction.options.usePhantomQuery) {
1469
+ await this.#withQuerySpanAndEvent(PHANTOM_COMMIT_QUERY(), tx.transaction, () => tx.transaction.commit());
1470
+ } else {
1471
+ await tx.transaction.commit();
1472
+ const query = COMMIT_QUERY();
1473
+ await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query));
1499
1474
  }
1500
- } finally {
1501
- clearTimeout(tx.timer);
1502
- tx.timer = void 0;
1503
- this.transactions.delete(tx.id);
1504
- this.closedTransactions.push(tx);
1505
- if (this.closedTransactions.length > MAX_CLOSED_TRANSACTIONS) {
1506
- this.closedTransactions.shift();
1475
+ } else if (tx.transaction) {
1476
+ if (tx.transaction.options.usePhantomQuery) {
1477
+ await this.#withQuerySpanAndEvent(PHANTOM_ROLLBACK_QUERY(), tx.transaction, () => tx.transaction.rollback());
1478
+ } else {
1479
+ await tx.transaction.rollback();
1480
+ const query = ROLLBACK_QUERY();
1481
+ await this.#withQuerySpanAndEvent(query, tx.transaction, () => tx.transaction.executeRaw(query));
1507
1482
  }
1508
1483
  }
1484
+ clearTimeout(tx.timer);
1485
+ tx.timer = void 0;
1486
+ this.transactions.delete(tx.id);
1487
+ this.closedTransactions.push(tx);
1488
+ if (this.closedTransactions.length > MAX_CLOSED_TRANSACTIONS) {
1489
+ this.closedTransactions.shift();
1490
+ }
1509
1491
  }
1510
1492
  validateOptions(options) {
1511
1493
  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.18",
3
+ "version": "6.11.0-dev.2",
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.18",
35
- "@prisma/driver-adapter-utils": "6.11.0-dev.18"
34
+ "@prisma/debug": "6.11.0-dev.2",
35
+ "@prisma/driver-adapter-utils": "6.11.0-dev.2"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/jest": "29.5.14",