@prisma/client-engine-runtime 6.9.0-dev.4 → 6.9.0-dev.6

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.
@@ -169,6 +169,24 @@ export type QueryPlanNode = {
169
169
  from: QueryPlanNode;
170
170
  to: QueryPlanNode;
171
171
  };
172
+ } | {
173
+ type: 'distinctBy';
174
+ args: {
175
+ expr: QueryPlanNode;
176
+ fields: string[];
177
+ };
178
+ } | {
179
+ type: 'paginate';
180
+ args: {
181
+ expr: QueryPlanNode;
182
+ pagination: Pagination;
183
+ };
184
+ };
185
+ export type Pagination = {
186
+ cursor: Record<string, PrismaValue> | null;
187
+ take: number | null;
188
+ skip: number | null;
189
+ linkingFields: string[] | null;
172
190
  };
173
191
  export type DataRule = {
174
192
  type: 'rowCountEq';
package/dist/index.d.mts CHANGED
@@ -32,6 +32,11 @@ export declare type Fragment = {
32
32
  type: 'parameterTupleList';
33
33
  };
34
34
 
35
+ /**
36
+ * Checks if two objects are deeply equal, recursively checking all properties for strict equality.
37
+ */
38
+ export declare function isDeepStrictEqual(a: unknown, b: unknown): boolean;
39
+
35
40
  export declare function isPrismaValueBytes(value: unknown): value is PrismaValueBytes;
36
41
 
37
42
  export declare function isPrismaValueGenerator(value: unknown): value is PrismaValueGenerator;
@@ -46,6 +51,13 @@ export declare type JoinExpression = {
46
51
 
47
52
  export declare const noopTracingHelper: TracingHelper;
48
53
 
54
+ export declare type Pagination = {
55
+ cursor: Record<string, PrismaValue> | null;
56
+ take: number | null;
57
+ skip: number | null;
58
+ linkingFields: string[] | null;
59
+ };
60
+
49
61
  export declare interface PlaceholderFormat {
50
62
  prefix: string;
51
63
  hasNumbering: boolean;
@@ -233,6 +245,18 @@ export declare type QueryPlanNode = {
233
245
  from: QueryPlanNode;
234
246
  to: QueryPlanNode;
235
247
  };
248
+ } | {
249
+ type: 'distinctBy';
250
+ args: {
251
+ expr: QueryPlanNode;
252
+ fields: string[];
253
+ };
254
+ } | {
255
+ type: 'paginate';
256
+ args: {
257
+ expr: QueryPlanNode;
258
+ pagination: Pagination;
259
+ };
236
260
  };
237
261
 
238
262
  export declare type ResultNode = {
package/dist/index.d.ts CHANGED
@@ -32,6 +32,11 @@ export declare type Fragment = {
32
32
  type: 'parameterTupleList';
33
33
  };
34
34
 
35
+ /**
36
+ * Checks if two objects are deeply equal, recursively checking all properties for strict equality.
37
+ */
38
+ export declare function isDeepStrictEqual(a: unknown, b: unknown): boolean;
39
+
35
40
  export declare function isPrismaValueBytes(value: unknown): value is PrismaValueBytes;
36
41
 
37
42
  export declare function isPrismaValueGenerator(value: unknown): value is PrismaValueGenerator;
@@ -46,6 +51,13 @@ export declare type JoinExpression = {
46
51
 
47
52
  export declare const noopTracingHelper: TracingHelper;
48
53
 
54
+ export declare type Pagination = {
55
+ cursor: Record<string, PrismaValue> | null;
56
+ take: number | null;
57
+ skip: number | null;
58
+ linkingFields: string[] | null;
59
+ };
60
+
49
61
  export declare interface PlaceholderFormat {
50
62
  prefix: string;
51
63
  hasNumbering: boolean;
@@ -233,6 +245,18 @@ export declare type QueryPlanNode = {
233
245
  from: QueryPlanNode;
234
246
  to: QueryPlanNode;
235
247
  };
248
+ } | {
249
+ type: 'distinctBy';
250
+ args: {
251
+ expr: QueryPlanNode;
252
+ fields: string[];
253
+ };
254
+ } | {
255
+ type: 'paginate';
256
+ args: {
257
+ expr: QueryPlanNode;
258
+ pagination: Pagination;
259
+ };
236
260
  };
237
261
 
238
262
  export declare type ResultNode = {
package/dist/index.js CHANGED
@@ -34,6 +34,7 @@ __export(index_exports, {
34
34
  TransactionManager: () => TransactionManager,
35
35
  TransactionManagerError: () => TransactionManagerError,
36
36
  UserFacingError: () => UserFacingError,
37
+ isDeepStrictEqual: () => isDeepStrictEqual,
37
38
  isPrismaValueBytes: () => isPrismaValueBytes,
38
39
  isPrismaValueGenerator: () => isPrismaValueGenerator,
39
40
  isPrismaValuePlaceholder: () => isPrismaValuePlaceholder,
@@ -48,6 +49,9 @@ var import_api = require("@opentelemetry/api");
48
49
  function assertNever(_, message) {
49
50
  throw new Error(message);
50
51
  }
52
+ function isDeepStrictEqual(a, b) {
53
+ return a === b || a !== null && b !== null && typeof a === "object" && typeof b === "object" && Object.keys(a).length === Object.keys(b).length && Object.keys(a).every((key) => isDeepStrictEqual(a[key], b[key]));
54
+ }
51
55
 
52
56
  // src/tracing.ts
53
57
  var noopTracingHelper = {
@@ -791,6 +795,38 @@ var QueryInterpreter = class _QueryInterpreter {
791
795
  const toSet = new Set(asList(to));
792
796
  return asList(from).filter((item) => !toSet.has(item));
793
797
  }
798
+ case "distinctBy": {
799
+ const value = await this.interpretNode(node.args.expr, queryable, scope, generators);
800
+ const seen = /* @__PURE__ */ new Set();
801
+ const result = [];
802
+ for (const item of asList(value)) {
803
+ const key = getRecordKey(item, node.args.fields);
804
+ if (!seen.has(key)) {
805
+ seen.add(key);
806
+ result.push(item);
807
+ }
808
+ }
809
+ return result;
810
+ }
811
+ case "paginate": {
812
+ const value = await this.interpretNode(node.args.expr, queryable, scope, generators);
813
+ const list = asList(value);
814
+ const linkingFields = node.args.pagination.linkingFields;
815
+ if (linkingFields !== null) {
816
+ const groupedByParent = /* @__PURE__ */ new Map();
817
+ for (const item of list) {
818
+ const parentKey = getRecordKey(item, linkingFields);
819
+ if (!groupedByParent.has(parentKey)) {
820
+ groupedByParent.set(parentKey, []);
821
+ }
822
+ groupedByParent.get(parentKey).push(item);
823
+ }
824
+ const groupList = Array.from(groupedByParent.entries());
825
+ groupList.sort(([aId], [bId]) => aId < bId ? -1 : aId > bId ? 1 : 0);
826
+ return groupList.flatMap(([, elems]) => paginate(elems, node.args.pagination));
827
+ }
828
+ return paginate(list, node.args.pagination);
829
+ }
794
830
  default:
795
831
  assertNever(node, `Unexpected node type: ${node.type}`);
796
832
  }
@@ -878,6 +914,26 @@ function childRecordMatchesParent(childRecord, parentRecord, joinExpr) {
878
914
  }
879
915
  return true;
880
916
  }
917
+ function paginate(list, { cursor, skip, take }) {
918
+ const cursorIndex = cursor !== null ? list.findIndex((item) => doesMatchCursor(item, cursor)) : 0;
919
+ if (cursorIndex === -1) {
920
+ return [];
921
+ }
922
+ const start = cursorIndex + (skip ?? 0);
923
+ const end = take !== null ? start + take : list.length;
924
+ return list.slice(start, end);
925
+ }
926
+ function getRecordKey(record, fields) {
927
+ return JSON.stringify(fields.map((field) => record[field]));
928
+ }
929
+ function doesMatchCursor(item, cursor) {
930
+ return Object.keys(cursor).every((key) => {
931
+ if (typeof item[key] !== typeof cursor[key] && (typeof item[key] === "number" || typeof cursor[key] === "number")) {
932
+ return `${item[key]}` === `${cursor[key]}`;
933
+ }
934
+ return isDeepStrictEqual(cursor[key], item[key]);
935
+ });
936
+ }
881
937
 
882
938
  // src/transactionManager/TransactionManager.ts
883
939
  var import_debug = require("@prisma/debug");
@@ -1100,6 +1156,7 @@ var TransactionManager = class {
1100
1156
  TransactionManager,
1101
1157
  TransactionManagerError,
1102
1158
  UserFacingError,
1159
+ isDeepStrictEqual,
1103
1160
  isPrismaValueBytes,
1104
1161
  isPrismaValueGenerator,
1105
1162
  isPrismaValuePlaceholder,
package/dist/index.mjs CHANGED
@@ -5,6 +5,9 @@ import { SpanKind } from "@opentelemetry/api";
5
5
  function assertNever(_, message) {
6
6
  throw new Error(message);
7
7
  }
8
+ function isDeepStrictEqual(a, b) {
9
+ return a === b || a !== null && b !== null && typeof a === "object" && typeof b === "object" && Object.keys(a).length === Object.keys(b).length && Object.keys(a).every((key) => isDeepStrictEqual(a[key], b[key]));
10
+ }
8
11
 
9
12
  // src/tracing.ts
10
13
  var noopTracingHelper = {
@@ -748,6 +751,38 @@ var QueryInterpreter = class _QueryInterpreter {
748
751
  const toSet = new Set(asList(to));
749
752
  return asList(from).filter((item) => !toSet.has(item));
750
753
  }
754
+ case "distinctBy": {
755
+ const value = await this.interpretNode(node.args.expr, queryable, scope, generators);
756
+ const seen = /* @__PURE__ */ new Set();
757
+ const result = [];
758
+ for (const item of asList(value)) {
759
+ const key = getRecordKey(item, node.args.fields);
760
+ if (!seen.has(key)) {
761
+ seen.add(key);
762
+ result.push(item);
763
+ }
764
+ }
765
+ return result;
766
+ }
767
+ case "paginate": {
768
+ const value = await this.interpretNode(node.args.expr, queryable, scope, generators);
769
+ const list = asList(value);
770
+ const linkingFields = node.args.pagination.linkingFields;
771
+ if (linkingFields !== null) {
772
+ const groupedByParent = /* @__PURE__ */ new Map();
773
+ for (const item of list) {
774
+ const parentKey = getRecordKey(item, linkingFields);
775
+ if (!groupedByParent.has(parentKey)) {
776
+ groupedByParent.set(parentKey, []);
777
+ }
778
+ groupedByParent.get(parentKey).push(item);
779
+ }
780
+ const groupList = Array.from(groupedByParent.entries());
781
+ groupList.sort(([aId], [bId]) => aId < bId ? -1 : aId > bId ? 1 : 0);
782
+ return groupList.flatMap(([, elems]) => paginate(elems, node.args.pagination));
783
+ }
784
+ return paginate(list, node.args.pagination);
785
+ }
751
786
  default:
752
787
  assertNever(node, `Unexpected node type: ${node.type}`);
753
788
  }
@@ -835,6 +870,26 @@ function childRecordMatchesParent(childRecord, parentRecord, joinExpr) {
835
870
  }
836
871
  return true;
837
872
  }
873
+ function paginate(list, { cursor, skip, take }) {
874
+ const cursorIndex = cursor !== null ? list.findIndex((item) => doesMatchCursor(item, cursor)) : 0;
875
+ if (cursorIndex === -1) {
876
+ return [];
877
+ }
878
+ const start = cursorIndex + (skip ?? 0);
879
+ const end = take !== null ? start + take : list.length;
880
+ return list.slice(start, end);
881
+ }
882
+ function getRecordKey(record, fields) {
883
+ return JSON.stringify(fields.map((field) => record[field]));
884
+ }
885
+ function doesMatchCursor(item, cursor) {
886
+ return Object.keys(cursor).every((key) => {
887
+ if (typeof item[key] !== typeof cursor[key] && (typeof item[key] === "number" || typeof cursor[key] === "number")) {
888
+ return `${item[key]}` === `${cursor[key]}`;
889
+ }
890
+ return isDeepStrictEqual(cursor[key], item[key]);
891
+ });
892
+ }
838
893
 
839
894
  // src/transactionManager/TransactionManager.ts
840
895
  import { Debug } from "@prisma/debug";
@@ -1056,6 +1111,7 @@ export {
1056
1111
  TransactionManager,
1057
1112
  TransactionManagerError,
1058
1113
  UserFacingError,
1114
+ isDeepStrictEqual,
1059
1115
  isPrismaValueBytes,
1060
1116
  isPrismaValueGenerator,
1061
1117
  isPrismaValuePlaceholder,
package/dist/utils.d.ts CHANGED
@@ -1 +1,5 @@
1
1
  export declare function assertNever(_: never, message: string): never;
2
+ /**
3
+ * Checks if two objects are deeply equal, recursively checking all properties for strict equality.
4
+ */
5
+ export declare function isDeepStrictEqual(a: unknown, b: unknown): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/client-engine-runtime",
3
- "version": "6.9.0-dev.4",
3
+ "version": "6.9.0-dev.6",
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.9.0-dev.4",
35
- "@prisma/driver-adapter-utils": "6.9.0-dev.4"
34
+ "@prisma/debug": "6.9.0-dev.6",
35
+ "@prisma/driver-adapter-utils": "6.9.0-dev.6"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/jest": "29.5.14",