@prisma/client-engine-runtime 6.14.0-dev.21 → 6.14.0-dev.23

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.
@@ -193,18 +193,6 @@ export type QueryPlanNode = {
193
193
  from: QueryPlanNode;
194
194
  to: QueryPlanNode;
195
195
  };
196
- } | {
197
- type: 'distinctBy';
198
- args: {
199
- expr: QueryPlanNode;
200
- fields: string[];
201
- };
202
- } | {
203
- type: 'paginate';
204
- args: {
205
- expr: QueryPlanNode;
206
- pagination: Pagination;
207
- };
208
196
  } | {
209
197
  type: 'initializeRecord';
210
198
  args: {
@@ -217,6 +205,12 @@ export type QueryPlanNode = {
217
205
  expr: QueryPlanNode;
218
206
  fields: Record<string, FieldOperation>;
219
207
  };
208
+ } | {
209
+ type: 'process';
210
+ args: {
211
+ expr: QueryPlanNode;
212
+ operations: InMemoryOps;
213
+ };
220
214
  };
221
215
  export type FieldInitializer = {
222
216
  type: 'value';
@@ -244,7 +238,13 @@ export type Pagination = {
244
238
  cursor: Record<string, PrismaValue> | null;
245
239
  take: number | null;
246
240
  skip: number | null;
241
+ };
242
+ export type InMemoryOps = {
243
+ pagination: Pagination | null;
244
+ distinct: string[] | null;
245
+ reverse: boolean;
247
246
  linkingFields: string[] | null;
247
+ nested: Record<string, InMemoryOps>;
248
248
  };
249
249
  export type DataRule = {
250
250
  type: 'rowCountEq';
package/dist/index.d.mts CHANGED
@@ -107,6 +107,14 @@ export declare type Fragment = {
107
107
  groupSeparator: string;
108
108
  };
109
109
 
110
+ export declare type InMemoryOps = {
111
+ pagination: Pagination | null;
112
+ distinct: string[] | null;
113
+ reverse: boolean;
114
+ linkingFields: string[] | null;
115
+ nested: Record<string, InMemoryOps>;
116
+ };
117
+
110
118
  /**
111
119
  * Checks if two objects are deeply equal, recursively checking all properties for strict equality.
112
120
  */
@@ -146,7 +154,6 @@ export declare type Pagination = {
146
154
  cursor: Record<string, PrismaValue> | null;
147
155
  take: number | null;
148
156
  skip: number | null;
149
- linkingFields: string[] | null;
150
157
  };
151
158
 
152
159
  export declare interface PlaceholderFormat {
@@ -358,18 +365,6 @@ export declare type QueryPlanNode = {
358
365
  from: QueryPlanNode;
359
366
  to: QueryPlanNode;
360
367
  };
361
- } | {
362
- type: 'distinctBy';
363
- args: {
364
- expr: QueryPlanNode;
365
- fields: string[];
366
- };
367
- } | {
368
- type: 'paginate';
369
- args: {
370
- expr: QueryPlanNode;
371
- pagination: Pagination;
372
- };
373
368
  } | {
374
369
  type: 'initializeRecord';
375
370
  args: {
@@ -382,6 +377,12 @@ export declare type QueryPlanNode = {
382
377
  expr: QueryPlanNode;
383
378
  fields: Record<string, FieldOperation>;
384
379
  };
380
+ } | {
381
+ type: 'process';
382
+ args: {
383
+ expr: QueryPlanNode;
384
+ operations: InMemoryOps;
385
+ };
385
386
  };
386
387
 
387
388
  export declare type RawResponse = {
package/dist/index.d.ts CHANGED
@@ -107,6 +107,14 @@ export declare type Fragment = {
107
107
  groupSeparator: string;
108
108
  };
109
109
 
110
+ export declare type InMemoryOps = {
111
+ pagination: Pagination | null;
112
+ distinct: string[] | null;
113
+ reverse: boolean;
114
+ linkingFields: string[] | null;
115
+ nested: Record<string, InMemoryOps>;
116
+ };
117
+
110
118
  /**
111
119
  * Checks if two objects are deeply equal, recursively checking all properties for strict equality.
112
120
  */
@@ -146,7 +154,6 @@ export declare type Pagination = {
146
154
  cursor: Record<string, PrismaValue> | null;
147
155
  take: number | null;
148
156
  skip: number | null;
149
- linkingFields: string[] | null;
150
157
  };
151
158
 
152
159
  export declare interface PlaceholderFormat {
@@ -358,18 +365,6 @@ export declare type QueryPlanNode = {
358
365
  from: QueryPlanNode;
359
366
  to: QueryPlanNode;
360
367
  };
361
- } | {
362
- type: 'distinctBy';
363
- args: {
364
- expr: QueryPlanNode;
365
- fields: string[];
366
- };
367
- } | {
368
- type: 'paginate';
369
- args: {
370
- expr: QueryPlanNode;
371
- pagination: Pagination;
372
- };
373
368
  } | {
374
369
  type: 'initializeRecord';
375
370
  args: {
@@ -382,6 +377,12 @@ export declare type QueryPlanNode = {
382
377
  expr: QueryPlanNode;
383
378
  fields: Record<string, FieldOperation>;
384
379
  };
380
+ } | {
381
+ type: 'process';
382
+ args: {
383
+ expr: QueryPlanNode;
384
+ operations: InMemoryOps;
385
+ };
385
386
  };
386
387
 
387
388
  export declare type RawResponse = {
package/dist/index.js CHANGED
@@ -706,6 +706,97 @@ var ProductGenerator = class {
706
706
  }
707
707
  };
708
708
 
709
+ // src/interpreter/in-memory-processing.ts
710
+ function processRecords(value, ops) {
711
+ if (value == null) {
712
+ return value;
713
+ }
714
+ if (typeof value === "string") {
715
+ return processRecords(JSON.parse(value), ops);
716
+ }
717
+ if (Array.isArray(value)) {
718
+ return processManyRecords(value, ops);
719
+ }
720
+ return processOneRecord(value, ops);
721
+ }
722
+ function processOneRecord(record, ops) {
723
+ if (ops.pagination) {
724
+ const { skip, take, cursor } = ops.pagination;
725
+ if (skip !== null && skip > 0) {
726
+ return null;
727
+ }
728
+ if (take === 0) {
729
+ return null;
730
+ }
731
+ if (cursor !== null && !doKeysMatch(record, cursor)) {
732
+ return null;
733
+ }
734
+ }
735
+ return processNestedRecords(record, ops.nested);
736
+ }
737
+ function processNestedRecords(record, opsMap) {
738
+ for (const [key, ops] of Object.entries(opsMap)) {
739
+ record[key] = processRecords(record[key], ops);
740
+ }
741
+ return record;
742
+ }
743
+ function processManyRecords(records, ops) {
744
+ if (ops.distinct !== null) {
745
+ const fields = ops.linkingFields !== null ? [...ops.distinct, ...ops.linkingFields] : ops.distinct;
746
+ records = distinctBy(records, fields);
747
+ }
748
+ if (ops.pagination) {
749
+ records = paginate(records, ops.pagination, ops.linkingFields);
750
+ }
751
+ if (ops.reverse) {
752
+ records.reverse();
753
+ }
754
+ if (Object.keys(ops.nested).length === 0) {
755
+ return records;
756
+ }
757
+ return records.map((record) => processNestedRecords(record, ops.nested));
758
+ }
759
+ function distinctBy(records, fields) {
760
+ const seen = /* @__PURE__ */ new Set();
761
+ const result = [];
762
+ for (const record of records) {
763
+ const key = getRecordKey(record, fields);
764
+ if (!seen.has(key)) {
765
+ seen.add(key);
766
+ result.push(record);
767
+ }
768
+ }
769
+ return result;
770
+ }
771
+ function paginate(records, pagination, linkingFields) {
772
+ if (linkingFields === null) {
773
+ return paginateSingleList(records, pagination);
774
+ }
775
+ const groupedByParent = /* @__PURE__ */ new Map();
776
+ for (const record of records) {
777
+ const parentKey = getRecordKey(record, linkingFields);
778
+ if (!groupedByParent.has(parentKey)) {
779
+ groupedByParent.set(parentKey, []);
780
+ }
781
+ groupedByParent.get(parentKey).push(record);
782
+ }
783
+ const groupList = Array.from(groupedByParent.entries());
784
+ groupList.sort(([aId], [bId]) => aId < bId ? -1 : aId > bId ? 1 : 0);
785
+ return groupList.flatMap(([, elems]) => paginateSingleList(elems, pagination));
786
+ }
787
+ function paginateSingleList(list, { cursor, skip, take }) {
788
+ const cursorIndex = cursor !== null ? list.findIndex((item) => doKeysMatch(item, cursor)) : 0;
789
+ if (cursorIndex === -1) {
790
+ return [];
791
+ }
792
+ const start = cursorIndex + (skip ?? 0);
793
+ const end = take !== null ? start + take : list.length;
794
+ return list.slice(start, end);
795
+ }
796
+ function getRecordKey(record, fields) {
797
+ return JSON.stringify(fields.map((field) => record[field]));
798
+ }
799
+
709
800
  // src/QueryPlan.ts
710
801
  function isPrismaValuePlaceholder(value) {
711
802
  return typeof value === "object" && value !== null && value["prisma__type"] === "param";
@@ -1448,40 +1539,9 @@ var QueryInterpreter = class _QueryInterpreter {
1448
1539
  const toSet = new Set(asList(to));
1449
1540
  return { value: asList(from).filter((item) => !toSet.has(item)) };
1450
1541
  }
1451
- case "distinctBy": {
1452
- const { value, lastInsertId } = await this.interpretNode(node.args.expr, queryable, scope, generators);
1453
- const seen = /* @__PURE__ */ new Set();
1454
- const result = [];
1455
- for (const item of asList(value)) {
1456
- const key = getRecordKey(item, node.args.fields);
1457
- if (!seen.has(key)) {
1458
- seen.add(key);
1459
- result.push(item);
1460
- }
1461
- }
1462
- return { value: result, lastInsertId };
1463
- }
1464
- case "paginate": {
1542
+ case "process": {
1465
1543
  const { value, lastInsertId } = await this.interpretNode(node.args.expr, queryable, scope, generators);
1466
- const list = asList(value);
1467
- const linkingFields = node.args.pagination.linkingFields;
1468
- if (linkingFields !== null) {
1469
- const groupedByParent = /* @__PURE__ */ new Map();
1470
- for (const item of list) {
1471
- const parentKey = getRecordKey(item, linkingFields);
1472
- if (!groupedByParent.has(parentKey)) {
1473
- groupedByParent.set(parentKey, []);
1474
- }
1475
- groupedByParent.get(parentKey).push(item);
1476
- }
1477
- const groupList = Array.from(groupedByParent.entries());
1478
- groupList.sort(([aId], [bId]) => aId < bId ? -1 : aId > bId ? 1 : 0);
1479
- return {
1480
- value: groupList.flatMap(([, elems]) => paginate(elems, node.args.pagination)),
1481
- lastInsertId
1482
- };
1483
- }
1484
- return { value: paginate(list, node.args.pagination), lastInsertId };
1544
+ return { value: processRecords(value, node.args.operations), lastInsertId };
1485
1545
  }
1486
1546
  case "initializeRecord": {
1487
1547
  const { lastInsertId } = await this.interpretNode(node.args.expr, queryable, scope, generators);
@@ -1608,18 +1668,6 @@ function attachChildrenToParents(parentRecords, children) {
1608
1668
  }
1609
1669
  return parentRecords;
1610
1670
  }
1611
- function paginate(list, { cursor, skip, take }) {
1612
- const cursorIndex = cursor !== null ? list.findIndex((item) => doKeysMatch(item, cursor)) : 0;
1613
- if (cursorIndex === -1) {
1614
- return [];
1615
- }
1616
- const start = cursorIndex + (skip ?? 0);
1617
- const end = take !== null ? start + take : list.length;
1618
- return list.slice(start, end);
1619
- }
1620
- function getRecordKey(record, fields) {
1621
- return JSON.stringify(fields.map((field) => record[field]));
1622
- }
1623
1671
  function evalFieldInitializer(initializer, lastInsertId, scope, generators) {
1624
1672
  switch (initializer.type) {
1625
1673
  case "value":
package/dist/index.mjs CHANGED
@@ -656,6 +656,97 @@ var ProductGenerator = class {
656
656
  }
657
657
  };
658
658
 
659
+ // src/interpreter/in-memory-processing.ts
660
+ function processRecords(value, ops) {
661
+ if (value == null) {
662
+ return value;
663
+ }
664
+ if (typeof value === "string") {
665
+ return processRecords(JSON.parse(value), ops);
666
+ }
667
+ if (Array.isArray(value)) {
668
+ return processManyRecords(value, ops);
669
+ }
670
+ return processOneRecord(value, ops);
671
+ }
672
+ function processOneRecord(record, ops) {
673
+ if (ops.pagination) {
674
+ const { skip, take, cursor } = ops.pagination;
675
+ if (skip !== null && skip > 0) {
676
+ return null;
677
+ }
678
+ if (take === 0) {
679
+ return null;
680
+ }
681
+ if (cursor !== null && !doKeysMatch(record, cursor)) {
682
+ return null;
683
+ }
684
+ }
685
+ return processNestedRecords(record, ops.nested);
686
+ }
687
+ function processNestedRecords(record, opsMap) {
688
+ for (const [key, ops] of Object.entries(opsMap)) {
689
+ record[key] = processRecords(record[key], ops);
690
+ }
691
+ return record;
692
+ }
693
+ function processManyRecords(records, ops) {
694
+ if (ops.distinct !== null) {
695
+ const fields = ops.linkingFields !== null ? [...ops.distinct, ...ops.linkingFields] : ops.distinct;
696
+ records = distinctBy(records, fields);
697
+ }
698
+ if (ops.pagination) {
699
+ records = paginate(records, ops.pagination, ops.linkingFields);
700
+ }
701
+ if (ops.reverse) {
702
+ records.reverse();
703
+ }
704
+ if (Object.keys(ops.nested).length === 0) {
705
+ return records;
706
+ }
707
+ return records.map((record) => processNestedRecords(record, ops.nested));
708
+ }
709
+ function distinctBy(records, fields) {
710
+ const seen = /* @__PURE__ */ new Set();
711
+ const result = [];
712
+ for (const record of records) {
713
+ const key = getRecordKey(record, fields);
714
+ if (!seen.has(key)) {
715
+ seen.add(key);
716
+ result.push(record);
717
+ }
718
+ }
719
+ return result;
720
+ }
721
+ function paginate(records, pagination, linkingFields) {
722
+ if (linkingFields === null) {
723
+ return paginateSingleList(records, pagination);
724
+ }
725
+ const groupedByParent = /* @__PURE__ */ new Map();
726
+ for (const record of records) {
727
+ const parentKey = getRecordKey(record, linkingFields);
728
+ if (!groupedByParent.has(parentKey)) {
729
+ groupedByParent.set(parentKey, []);
730
+ }
731
+ groupedByParent.get(parentKey).push(record);
732
+ }
733
+ const groupList = Array.from(groupedByParent.entries());
734
+ groupList.sort(([aId], [bId]) => aId < bId ? -1 : aId > bId ? 1 : 0);
735
+ return groupList.flatMap(([, elems]) => paginateSingleList(elems, pagination));
736
+ }
737
+ function paginateSingleList(list, { cursor, skip, take }) {
738
+ const cursorIndex = cursor !== null ? list.findIndex((item) => doKeysMatch(item, cursor)) : 0;
739
+ if (cursorIndex === -1) {
740
+ return [];
741
+ }
742
+ const start = cursorIndex + (skip ?? 0);
743
+ const end = take !== null ? start + take : list.length;
744
+ return list.slice(start, end);
745
+ }
746
+ function getRecordKey(record, fields) {
747
+ return JSON.stringify(fields.map((field) => record[field]));
748
+ }
749
+
659
750
  // src/QueryPlan.ts
660
751
  function isPrismaValuePlaceholder(value) {
661
752
  return typeof value === "object" && value !== null && value["prisma__type"] === "param";
@@ -1398,40 +1489,9 @@ var QueryInterpreter = class _QueryInterpreter {
1398
1489
  const toSet = new Set(asList(to));
1399
1490
  return { value: asList(from).filter((item) => !toSet.has(item)) };
1400
1491
  }
1401
- case "distinctBy": {
1402
- const { value, lastInsertId } = await this.interpretNode(node.args.expr, queryable, scope, generators);
1403
- const seen = /* @__PURE__ */ new Set();
1404
- const result = [];
1405
- for (const item of asList(value)) {
1406
- const key = getRecordKey(item, node.args.fields);
1407
- if (!seen.has(key)) {
1408
- seen.add(key);
1409
- result.push(item);
1410
- }
1411
- }
1412
- return { value: result, lastInsertId };
1413
- }
1414
- case "paginate": {
1492
+ case "process": {
1415
1493
  const { value, lastInsertId } = await this.interpretNode(node.args.expr, queryable, scope, generators);
1416
- const list = asList(value);
1417
- const linkingFields = node.args.pagination.linkingFields;
1418
- if (linkingFields !== null) {
1419
- const groupedByParent = /* @__PURE__ */ new Map();
1420
- for (const item of list) {
1421
- const parentKey = getRecordKey(item, linkingFields);
1422
- if (!groupedByParent.has(parentKey)) {
1423
- groupedByParent.set(parentKey, []);
1424
- }
1425
- groupedByParent.get(parentKey).push(item);
1426
- }
1427
- const groupList = Array.from(groupedByParent.entries());
1428
- groupList.sort(([aId], [bId]) => aId < bId ? -1 : aId > bId ? 1 : 0);
1429
- return {
1430
- value: groupList.flatMap(([, elems]) => paginate(elems, node.args.pagination)),
1431
- lastInsertId
1432
- };
1433
- }
1434
- return { value: paginate(list, node.args.pagination), lastInsertId };
1494
+ return { value: processRecords(value, node.args.operations), lastInsertId };
1435
1495
  }
1436
1496
  case "initializeRecord": {
1437
1497
  const { lastInsertId } = await this.interpretNode(node.args.expr, queryable, scope, generators);
@@ -1558,18 +1618,6 @@ function attachChildrenToParents(parentRecords, children) {
1558
1618
  }
1559
1619
  return parentRecords;
1560
1620
  }
1561
- function paginate(list, { cursor, skip, take }) {
1562
- const cursorIndex = cursor !== null ? list.findIndex((item) => doKeysMatch(item, cursor)) : 0;
1563
- if (cursorIndex === -1) {
1564
- return [];
1565
- }
1566
- const start = cursorIndex + (skip ?? 0);
1567
- const end = take !== null ? start + take : list.length;
1568
- return list.slice(start, end);
1569
- }
1570
- function getRecordKey(record, fields) {
1571
- return JSON.stringify(fields.map((field) => record[field]));
1572
- }
1573
1621
  function evalFieldInitializer(initializer, lastInsertId, scope, generators) {
1574
1622
  switch (initializer.type) {
1575
1623
  case "value":
@@ -0,0 +1,3 @@
1
+ import { InMemoryOps } from '../QueryPlan';
2
+ export declare function processRecords(value: unknown, ops: InMemoryOps): unknown;
3
+ export declare function getRecordKey(record: {}, fields: string[]): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/client-engine-runtime",
3
- "version": "6.14.0-dev.21",
3
+ "version": "6.14.0-dev.23",
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/driver-adapter-utils": "6.14.0-dev.21",
35
- "@prisma/debug": "6.14.0-dev.21"
34
+ "@prisma/debug": "6.14.0-dev.23",
35
+ "@prisma/driver-adapter-utils": "6.14.0-dev.23"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/jest": "29.5.14",