vsrepo 1.3.1 → 1.3.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.
@@ -239,12 +239,21 @@ type SelectedModel<M extends Prisma.ModelName, S, SelectModels, IM = never, Incl
239
239
  ? PrecomputedIncludes<M, IncludeModels>[IM]
240
240
  : FullModelType<M>;
241
241
 
242
+ /**
243
+ * Strips the `Distinct{Fields}` suffix used by read methods (e.g. `findManyDistinctIdadeAndCargo`).
244
+ * The distinct fields are resolved from the method name at build time, so they never
245
+ * become part of the runtime `where` fields extracted by `ExtractFields`.
246
+ */
247
+ type StripDistinctFields<R extends string> =
248
+ R extends `${infer F}Distinct${string}` ? F : R;
249
+
242
250
  type CleanFields<R extends string> =
243
- R extends `${infer F}PaginatedAndOrdered` ? F :
244
- R extends `${infer F}OrderedAndPaginated` ? F :
245
- R extends `${infer F}Paginated` ? F :
246
- R extends `${infer F}Ordered` ? F :
247
- R extends `${infer F}SkipDuplicates` ? F : R;
251
+ R extends `${infer F}PaginatedAndOrdered` ? StripDistinctFields<F> :
252
+ R extends `${infer F}OrderedAndPaginated` ? StripDistinctFields<F> :
253
+ R extends `${infer F}Paginated` ? StripDistinctFields<F> :
254
+ R extends `${infer F}Ordered` ? StripDistinctFields<F> :
255
+ R extends `${infer F}SkipDuplicates` ? StripDistinctFields<F> :
256
+ StripDistinctFields<R>;
248
257
 
249
258
  /**
250
259
  * Additional options accepted by repository methods.
@@ -144,6 +144,7 @@ class VSRepository {
144
144
  ? args.at(dinamicMethodInfo.updateIndex)
145
145
  : undefined,
146
146
  withOrdenationAndPagination: !dinamicMethodInfo.ignoreOrderByAndPagination,
147
+ distinctKeys: dinamicMethodCustomization.distinctKeys,
147
148
  };
148
149
  if (!dinamicMethodInfo.ignoreWhere) {
149
150
  resolveDbAndPrismaArgsData.specificWhere = (0, specific_where_resolve_1.resolveSpecificWhere)(args, dinamicMethodWhereOps.prettyWheres);
@@ -5,7 +5,7 @@ const method_options_validate_1 = require("../validation/method-options.validate
5
5
  const merge_wheres_resolve_1 = require("./merge-wheres.resolve");
6
6
  const select_resolve_1 = require("./select.resolve");
7
7
  function resolveDbAndPrismaArgs(data) {
8
- const { baseConfig, instance, options, wherePkValue, withoutSelect, withoutWhere, specificSelect, dataPayload, createPayload, updatePayload, alreadyValidatedOptions, specificWhere, pushWhere, ordenation, pagination, skipDuplicates, forceSeeMode, withOrdenationAndPagination, } = data;
8
+ const { baseConfig, instance, options, wherePkValue, withoutSelect, withoutWhere, specificSelect, dataPayload, createPayload, updatePayload, alreadyValidatedOptions, specificWhere, pushWhere, ordenation, pagination, skipDuplicates, forceSeeMode, withOrdenationAndPagination, distinctKeys, } = data;
9
9
  const validatedOptions = alreadyValidatedOptions && options
10
10
  ? options
11
11
  : (0, method_options_validate_1.validateMethodOptions)(options, instance);
@@ -50,5 +50,8 @@ function resolveDbAndPrismaArgs(data) {
50
50
  if (skipDuplicates !== undefined) {
51
51
  prismaArgs.skipDuplicates = skipDuplicates;
52
52
  }
53
+ if (distinctKeys !== undefined) {
54
+ prismaArgs.distinct = distinctKeys;
55
+ }
53
56
  return { db, prismaArgs };
54
57
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveDinamicMethodCustomization = resolveDinamicMethodCustomization;
4
+ const uncapitalize_util_1 = require("../utils/uncapitalize.util");
4
5
  function resolveDinamicMethodCustomization(instance, dinamicMethodInfo, originalKey) {
5
6
  const dinamicMethodCustomization = {};
6
7
  if (!dinamicMethodInfo.ignoreSkipDuplicates) {
@@ -10,8 +11,10 @@ function resolveDinamicMethodCustomization(instance, dinamicMethodInfo, original
10
11
  }
11
12
  }
12
13
  if (!dinamicMethodInfo.ignoreOrderByAndPagination) {
13
- dinamicMethodCustomization.injectOrdenation = instance.methods?.[originalKey]?.injectOrdenation;
14
- dinamicMethodCustomization.injectPagination = instance.methods?.[originalKey]?.injectPagination;
14
+ dinamicMethodCustomization.injectOrdenation =
15
+ instance.methods?.[originalKey]?.injectOrdenation;
16
+ dinamicMethodCustomization.injectPagination =
17
+ instance.methods?.[originalKey]?.injectPagination;
15
18
  if (dinamicMethodInfo.keyToMapReplaced.endsWith("PaginatedAndOrdered")) {
16
19
  dinamicMethodCustomization.orderPosition = -2;
17
20
  dinamicMethodCustomization.paginationPosition = -3;
@@ -41,5 +44,14 @@ function resolveDinamicMethodCustomization(instance, dinamicMethodInfo, original
41
44
  dinamicMethodInfo.argsCount++;
42
45
  }
43
46
  }
47
+ if (!dinamicMethodInfo.ignoreDistinct) {
48
+ const keySplitedDistinct = dinamicMethodInfo.keyToMapReplaced.split("Distinct");
49
+ if (keySplitedDistinct[1]) {
50
+ dinamicMethodCustomization.distinctKeys = keySplitedDistinct[1]
51
+ .split("And")
52
+ .map(uncapitalize_util_1.uncapitalize);
53
+ }
54
+ dinamicMethodInfo.keyToMapReplaced = keySplitedDistinct[0];
55
+ }
44
56
  return dinamicMethodCustomization;
45
57
  }
@@ -15,6 +15,7 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
15
15
  ignoreSkipDuplicates: true,
16
16
  whereParams: [],
17
17
  otherParams: [],
18
+ ignoreDistinct: true,
18
19
  };
19
20
  if (dinamicMethod === "aggregate") {
20
21
  dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("aggregate", "");
@@ -45,6 +46,7 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
45
46
  else if (dinamicMethod.startsWith("findFirstOrThrowBy")) {
46
47
  dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findFirstOrThrowBy", "");
47
48
  dinamicMethodInfo.ignoreOrderByAndPagination = false;
49
+ dinamicMethodInfo.ignoreDistinct = false;
48
50
  dinamicMethodInfo.method = "findFirstOrThrow";
49
51
  }
50
52
  else if (dinamicMethod.startsWith("findFirstOrThrow")) {
@@ -52,11 +54,13 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
52
54
  dinamicMethodInfo.ignoreOrderByAndPagination = false;
53
55
  dinamicMethodInfo.ignoreWhere = true;
54
56
  dinamicMethodInfo.onlyBaseWheres = true;
57
+ dinamicMethodInfo.ignoreDistinct = false;
55
58
  dinamicMethodInfo.method = "findFirstOrThrow";
56
59
  }
57
60
  else if (dinamicMethod.startsWith("findFirstBy")) {
58
61
  dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findFirstBy", "");
59
62
  dinamicMethodInfo.ignoreOrderByAndPagination = false;
63
+ dinamicMethodInfo.ignoreDistinct = false;
60
64
  dinamicMethodInfo.method = "findFirst";
61
65
  }
62
66
  else if (dinamicMethod.startsWith("findFirst")) {
@@ -64,6 +68,7 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
64
68
  dinamicMethodInfo.ignoreOrderByAndPagination = false;
65
69
  dinamicMethodInfo.ignoreWhere = true;
66
70
  dinamicMethodInfo.onlyBaseWheres = true;
71
+ dinamicMethodInfo.ignoreDistinct = false;
67
72
  dinamicMethodInfo.method = "findFirst";
68
73
  }
69
74
  else if (dinamicMethod.startsWith("countBy")) {
@@ -95,6 +100,7 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
95
100
  dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("existsBy", "");
96
101
  dinamicMethodInfo.ignoreSelect = true;
97
102
  dinamicMethodInfo.existsMode = true;
103
+ dinamicMethodInfo.ignoreDistinct = false;
98
104
  dinamicMethodInfo.method = "findFirst";
99
105
  }
100
106
  else if (dinamicMethod.startsWith("existsWhere")) {
@@ -103,6 +109,7 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
103
109
  dinamicMethodInfo.existsMode = true;
104
110
  dinamicMethodInfo.ignoreWhere = true;
105
111
  dinamicMethodInfo.onlyBaseWheres = true;
112
+ dinamicMethodInfo.ignoreDistinct = false;
106
113
  dinamicMethodInfo.method = "findFirst";
107
114
  dinamicMethodInfo.whereIndex = 0;
108
115
  dinamicMethodInfo.otherParams.push("where");
@@ -111,6 +118,7 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
111
118
  else if (dinamicMethod.startsWith("findManyBy")) {
112
119
  dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findManyBy", "");
113
120
  dinamicMethodInfo.ignoreOrderByAndPagination = false;
121
+ dinamicMethodInfo.ignoreDistinct = false;
114
122
  dinamicMethodInfo.method = "findMany";
115
123
  }
116
124
  else if (dinamicMethod.startsWith("findMany")) {
@@ -118,6 +126,7 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
118
126
  dinamicMethodInfo.ignoreOrderByAndPagination = false;
119
127
  dinamicMethodInfo.ignoreWhere = true;
120
128
  dinamicMethodInfo.onlyBaseWheres = true;
129
+ dinamicMethodInfo.ignoreDistinct = false;
121
130
  dinamicMethodInfo.method = "findMany";
122
131
  }
123
132
  else if (dinamicMethod.startsWith("createManyAndReturn")) {
@@ -223,6 +232,7 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
223
232
  dinamicMethodInfo.ignoreOrderByAndPagination = false;
224
233
  dinamicMethodInfo.ignoreWhere = true;
225
234
  dinamicMethodInfo.onlyBaseWheres = true;
235
+ dinamicMethodInfo.ignoreDistinct = false;
226
236
  dinamicMethodInfo.method = "findFirst";
227
237
  dinamicMethodInfo.whereIndex = 0;
228
238
  dinamicMethodInfo.otherParams.push("where");
@@ -233,6 +243,7 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
233
243
  dinamicMethodInfo.ignoreOrderByAndPagination = false;
234
244
  dinamicMethodInfo.ignoreWhere = true;
235
245
  dinamicMethodInfo.onlyBaseWheres = true;
246
+ dinamicMethodInfo.ignoreDistinct = false;
236
247
  dinamicMethodInfo.method = "findFirst";
237
248
  dinamicMethodInfo.whereIndex = 0;
238
249
  dinamicMethodInfo.otherParams.push("where");
@@ -243,6 +254,7 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
243
254
  dinamicMethodInfo.ignoreOrderByAndPagination = false;
244
255
  dinamicMethodInfo.ignoreWhere = true;
245
256
  dinamicMethodInfo.onlyBaseWheres = true;
257
+ dinamicMethodInfo.ignoreDistinct = false;
246
258
  dinamicMethodInfo.method = "findMany";
247
259
  dinamicMethodInfo.whereIndex = 0;
248
260
  dinamicMethodInfo.otherParams.push("where");
@@ -251,11 +263,13 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
251
263
  else if (dinamicMethod.startsWith("findOneBy")) {
252
264
  dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findOneBy", "");
253
265
  dinamicMethodInfo.ignoreOrderByAndPagination = false;
266
+ dinamicMethodInfo.ignoreDistinct = false;
254
267
  dinamicMethodInfo.method = "findFirst";
255
268
  }
256
269
  else if (dinamicMethod.startsWith("findBy")) {
257
270
  dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findBy", "");
258
271
  dinamicMethodInfo.ignoreOrderByAndPagination = false;
272
+ dinamicMethodInfo.ignoreDistinct = false;
259
273
  dinamicMethodInfo.method = instance.methods?.[originalKey]?.fbMode === "one" ? "findFirst" : "findMany";
260
274
  }
261
275
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vsrepo",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Uma biblioteca de repository pattern para Prisma",
5
5
  "homepage": "https://github.com/jaobrabo123/VSRepository#readme",
6
6
  "repository": {