@prisma/client-engine-runtime 6.10.1-dev.1 → 6.10.1

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
@@ -1093,13 +1093,7 @@ var QueryInterpreter = class _QueryInterpreter {
1093
1093
  childRecords: (await this.interpretNode(joinExpr.child, queryable, scope, generators)).value
1094
1094
  }))
1095
1095
  );
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 };
1096
+ return { value: attachChildrenToParents(parent, children), lastInsertId };
1103
1097
  }
1104
1098
  case "transaction": {
1105
1099
  if (!this.#transactionManager.enabled) {
@@ -1241,34 +1235,39 @@ function mapField(value, field) {
1241
1235
  }
1242
1236
  return value;
1243
1237
  }
1244
- function attachChildrenToParent(parentRecord, children) {
1238
+ function attachChildrenToParents(parentRecords, children) {
1245
1239
  for (const { joinExpr, childRecords } of children) {
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;
1240
+ const parentKeys = joinExpr.on.map(([k]) => k);
1241
+ const childKeys = joinExpr.on.map(([, k]) => k);
1242
+ const parentMap = {};
1243
+ for (const parent of Array.isArray(parentRecords) ? parentRecords : [parentRecords]) {
1244
+ const parentRecord = asRecord(parent);
1245
+ const key = getRecordKey(parentRecord, parentKeys);
1246
+ if (!parentMap[key]) {
1247
+ parentMap[key] = [];
1248
+ }
1249
+ parentMap[key].push(parentRecord);
1250
+ if (joinExpr.isRelationUnique) {
1251
+ parentRecord[joinExpr.parentField] = null;
1252
+ } else {
1253
+ parentRecord[joinExpr.parentField] = [];
1254
+ }
1257
1255
  }
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;
1256
+ for (const childRecord of Array.isArray(childRecords) ? childRecords : [childRecords]) {
1257
+ if (childRecord === null) {
1258
+ continue;
1259
+ }
1260
+ const key = getRecordKey(asRecord(childRecord), childKeys);
1261
+ for (const parentRecord of parentMap[key] ?? []) {
1262
+ if (joinExpr.isRelationUnique) {
1263
+ parentRecord[joinExpr.parentField] = childRecord;
1264
+ } else {
1265
+ parentRecord[joinExpr.parentField].push(childRecord);
1266
+ }
1267
+ }
1269
1268
  }
1270
1269
  }
1271
- return true;
1270
+ return parentRecords;
1272
1271
  }
1273
1272
  function paginate(list, { cursor, skip, take }) {
1274
1273
  const cursorIndex = cursor !== null ? list.findIndex((item) => doKeysMatch(item, cursor)) : 0;
package/dist/index.mjs CHANGED
@@ -1045,13 +1045,7 @@ var QueryInterpreter = class _QueryInterpreter {
1045
1045
  childRecords: (await this.interpretNode(joinExpr.child, queryable, scope, generators)).value
1046
1046
  }))
1047
1047
  );
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 };
1048
+ return { value: attachChildrenToParents(parent, children), lastInsertId };
1055
1049
  }
1056
1050
  case "transaction": {
1057
1051
  if (!this.#transactionManager.enabled) {
@@ -1193,34 +1187,39 @@ function mapField(value, field) {
1193
1187
  }
1194
1188
  return value;
1195
1189
  }
1196
- function attachChildrenToParent(parentRecord, children) {
1190
+ function attachChildrenToParents(parentRecords, children) {
1197
1191
  for (const { joinExpr, childRecords } of children) {
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;
1192
+ const parentKeys = joinExpr.on.map(([k]) => k);
1193
+ const childKeys = joinExpr.on.map(([, k]) => k);
1194
+ const parentMap = {};
1195
+ for (const parent of Array.isArray(parentRecords) ? parentRecords : [parentRecords]) {
1196
+ const parentRecord = asRecord(parent);
1197
+ const key = getRecordKey(parentRecord, parentKeys);
1198
+ if (!parentMap[key]) {
1199
+ parentMap[key] = [];
1200
+ }
1201
+ parentMap[key].push(parentRecord);
1202
+ if (joinExpr.isRelationUnique) {
1203
+ parentRecord[joinExpr.parentField] = null;
1204
+ } else {
1205
+ parentRecord[joinExpr.parentField] = [];
1206
+ }
1209
1207
  }
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;
1208
+ for (const childRecord of Array.isArray(childRecords) ? childRecords : [childRecords]) {
1209
+ if (childRecord === null) {
1210
+ continue;
1211
+ }
1212
+ const key = getRecordKey(asRecord(childRecord), childKeys);
1213
+ for (const parentRecord of parentMap[key] ?? []) {
1214
+ if (joinExpr.isRelationUnique) {
1215
+ parentRecord[joinExpr.parentField] = childRecord;
1216
+ } else {
1217
+ parentRecord[joinExpr.parentField].push(childRecord);
1218
+ }
1219
+ }
1221
1220
  }
1222
1221
  }
1223
- return true;
1222
+ return parentRecords;
1224
1223
  }
1225
1224
  function paginate(list, { cursor, skip, take }) {
1226
1225
  const cursorIndex = cursor !== null ? list.findIndex((item) => doKeysMatch(item, cursor)) : 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/client-engine-runtime",
3
- "version": "6.10.1-dev.1",
3
+ "version": "6.10.1",
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.10.1-dev.1",
35
- "@prisma/driver-adapter-utils": "6.10.1-dev.1"
34
+ "@prisma/debug": "6.10.1",
35
+ "@prisma/driver-adapter-utils": "6.10.1"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/jest": "29.5.14",