@prisma/client-engine-runtime 6.11.0-dev.2 → 6.11.0-dev.20
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 +76 -58
- package/dist/index.mjs +76 -58
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -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": {
|
|
@@ -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++) {
|
|
@@ -1093,13 +1110,7 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1093
1110
|
childRecords: (await this.interpretNode(joinExpr.child, queryable, scope, generators)).value
|
|
1094
1111
|
}))
|
|
1095
1112
|
);
|
|
1096
|
-
|
|
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 };
|
|
1113
|
+
return { value: attachChildrenToParents(parent, children), lastInsertId };
|
|
1103
1114
|
}
|
|
1104
1115
|
case "transaction": {
|
|
1105
1116
|
if (!this.#transactionManager.enabled) {
|
|
@@ -1241,34 +1252,39 @@ function mapField(value, field) {
|
|
|
1241
1252
|
}
|
|
1242
1253
|
return value;
|
|
1243
1254
|
}
|
|
1244
|
-
function
|
|
1255
|
+
function attachChildrenToParents(parentRecords, children) {
|
|
1245
1256
|
for (const { joinExpr, childRecords } of children) {
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
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
|
+
}
|
|
1257
1272
|
}
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
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
|
+
}
|
|
1269
1285
|
}
|
|
1270
1286
|
}
|
|
1271
|
-
return
|
|
1287
|
+
return parentRecords;
|
|
1272
1288
|
}
|
|
1273
1289
|
function paginate(list, { cursor, skip, take }) {
|
|
1274
1290
|
const cursorIndex = cursor !== null ? list.findIndex((item) => doKeysMatch(item, cursor)) : 0;
|
|
@@ -1425,17 +1441,16 @@ var TransactionManager = class {
|
|
|
1425
1441
|
transaction: void 0
|
|
1426
1442
|
};
|
|
1427
1443
|
this.transactions.set(transaction.id, transaction);
|
|
1428
|
-
|
|
1429
|
-
|
|
1444
|
+
const startTimer = setTimeout(() => transaction.status = "timed_out", validatedOptions.maxWait);
|
|
1445
|
+
transaction.transaction = await this.driverAdapter.startTransaction(validatedOptions.isolationLevel);
|
|
1446
|
+
clearTimeout(startTimer);
|
|
1430
1447
|
switch (transaction.status) {
|
|
1431
1448
|
case "waiting":
|
|
1432
|
-
transaction.transaction = startedTransaction;
|
|
1433
|
-
clearTimeout(transaction.timer);
|
|
1434
|
-
transaction.timer = void 0;
|
|
1435
1449
|
transaction.status = "running";
|
|
1436
1450
|
transaction.timer = this.startTransactionTimeout(transaction.id, validatedOptions.timeout);
|
|
1437
1451
|
return { id: transaction.id };
|
|
1438
1452
|
case "timed_out":
|
|
1453
|
+
await this.closeTransaction(transaction, "timed_out");
|
|
1439
1454
|
throw new TransactionStartTimeoutError();
|
|
1440
1455
|
case "running":
|
|
1441
1456
|
case "committed":
|
|
@@ -1512,30 +1527,33 @@ var TransactionManager = class {
|
|
|
1512
1527
|
async closeTransaction(tx, status) {
|
|
1513
1528
|
debug("Closing transaction.", { transactionId: tx.id, status });
|
|
1514
1529
|
tx.status = status;
|
|
1515
|
-
|
|
1516
|
-
if (tx.transaction
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
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
|
+
}
|
|
1522
1547
|
}
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
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();
|
|
1530
1555
|
}
|
|
1531
1556
|
}
|
|
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
|
-
}
|
|
1539
1557
|
}
|
|
1540
1558
|
validateOptions(options) {
|
|
1541
1559
|
if (!options.timeout) throw new TransactionManagerError("timeout is required");
|
package/dist/index.mjs
CHANGED
|
@@ -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": {
|
|
@@ -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++) {
|
|
@@ -1045,13 +1062,7 @@ var QueryInterpreter = class _QueryInterpreter {
|
|
|
1045
1062
|
childRecords: (await this.interpretNode(joinExpr.child, queryable, scope, generators)).value
|
|
1046
1063
|
}))
|
|
1047
1064
|
);
|
|
1048
|
-
|
|
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 };
|
|
1065
|
+
return { value: attachChildrenToParents(parent, children), lastInsertId };
|
|
1055
1066
|
}
|
|
1056
1067
|
case "transaction": {
|
|
1057
1068
|
if (!this.#transactionManager.enabled) {
|
|
@@ -1193,34 +1204,39 @@ function mapField(value, field) {
|
|
|
1193
1204
|
}
|
|
1194
1205
|
return value;
|
|
1195
1206
|
}
|
|
1196
|
-
function
|
|
1207
|
+
function attachChildrenToParents(parentRecords, children) {
|
|
1197
1208
|
for (const { joinExpr, childRecords } of children) {
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
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
|
+
}
|
|
1209
1224
|
}
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
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
|
+
}
|
|
1221
1237
|
}
|
|
1222
1238
|
}
|
|
1223
|
-
return
|
|
1239
|
+
return parentRecords;
|
|
1224
1240
|
}
|
|
1225
1241
|
function paginate(list, { cursor, skip, take }) {
|
|
1226
1242
|
const cursorIndex = cursor !== null ? list.findIndex((item) => doKeysMatch(item, cursor)) : 0;
|
|
@@ -1377,17 +1393,16 @@ var TransactionManager = class {
|
|
|
1377
1393
|
transaction: void 0
|
|
1378
1394
|
};
|
|
1379
1395
|
this.transactions.set(transaction.id, transaction);
|
|
1380
|
-
|
|
1381
|
-
|
|
1396
|
+
const startTimer = setTimeout(() => transaction.status = "timed_out", validatedOptions.maxWait);
|
|
1397
|
+
transaction.transaction = await this.driverAdapter.startTransaction(validatedOptions.isolationLevel);
|
|
1398
|
+
clearTimeout(startTimer);
|
|
1382
1399
|
switch (transaction.status) {
|
|
1383
1400
|
case "waiting":
|
|
1384
|
-
transaction.transaction = startedTransaction;
|
|
1385
|
-
clearTimeout(transaction.timer);
|
|
1386
|
-
transaction.timer = void 0;
|
|
1387
1401
|
transaction.status = "running";
|
|
1388
1402
|
transaction.timer = this.startTransactionTimeout(transaction.id, validatedOptions.timeout);
|
|
1389
1403
|
return { id: transaction.id };
|
|
1390
1404
|
case "timed_out":
|
|
1405
|
+
await this.closeTransaction(transaction, "timed_out");
|
|
1391
1406
|
throw new TransactionStartTimeoutError();
|
|
1392
1407
|
case "running":
|
|
1393
1408
|
case "committed":
|
|
@@ -1464,30 +1479,33 @@ var TransactionManager = class {
|
|
|
1464
1479
|
async closeTransaction(tx, status) {
|
|
1465
1480
|
debug("Closing transaction.", { transactionId: tx.id, status });
|
|
1466
1481
|
tx.status = status;
|
|
1467
|
-
|
|
1468
|
-
if (tx.transaction
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
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
|
+
}
|
|
1474
1499
|
}
|
|
1475
|
-
}
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
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();
|
|
1482
1507
|
}
|
|
1483
1508
|
}
|
|
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
|
-
}
|
|
1491
1509
|
}
|
|
1492
1510
|
validateOptions(options) {
|
|
1493
1511
|
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.
|
|
3
|
+
"version": "6.11.0-dev.20",
|
|
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.
|
|
35
|
-
"@prisma/driver-adapter-utils": "6.11.0-dev.
|
|
34
|
+
"@prisma/debug": "6.11.0-dev.20",
|
|
35
|
+
"@prisma/driver-adapter-utils": "6.11.0-dev.20"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/jest": "29.5.14",
|