vsrepo 1.3.4 → 1.3.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.
- package/README.md +181 -137
- package/README.pt-BR.md +188 -144
- package/dist/DynamicRepository.d.ts +36 -15
- package/dist/VSRepoError.d.ts +21 -1
- package/dist/VSRepository.d.ts +126 -87
- package/dist/VSRepository.js +49 -49
- package/dist/internal/constants/dynamic-methods-key.constant.js +4 -0
- package/dist/internal/decorators/dynamic-method.decorator.js +4 -4
- package/dist/internal/decorators/query-method.decorator.js +7 -3
- package/dist/internal/entities/dynamic-method-metadata.entity.js +3 -3
- package/dist/internal/resolvers/base-methods.resolve.js +2 -2
- package/dist/internal/resolvers/dbAndPrismaArgs.resolve.js +7 -4
- package/dist/internal/resolvers/dynamic-method-customization.resolve.js +57 -0
- package/dist/internal/resolvers/dynamic-method-info.resolve.js +279 -0
- package/dist/internal/resolvers/dynamic-methods-metadata.resolve.js +2 -2
- package/dist/internal/resolvers/pretty-wheres.resolve.js +8 -8
- package/dist/internal/resolvers/types/dynamic-method-where-ops.type.js +2 -0
- package/dist/internal/utils/schemas.util.js +8 -2
- package/dist/internal/validation/constructor-config.validate.js +7 -4
- package/dist/internal/validation/method-options.validate.js +10 -3
- package/package.json +11 -2
- package/scripts/configure-prisma-import.mjs +12 -8
- package/scripts/copy-types.mjs +16 -16
- package/dist/internal/constants/dinamic-methods-key.constant.js +0 -4
- package/dist/internal/resolvers/dinamic-method-customization.resolve.js +0 -57
- package/dist/internal/resolvers/dinamic-method-info.resolve.js +0 -279
- /package/dist/internal/{resolvers/types/dinamic-method-customization.type.js → errors/types/vs-repo-runtime-error-code.type.js} +0 -0
- /package/dist/internal/resolvers/types/{dinamic-method-info.type.js → dynamic-method-customization.type.js} +0 -0
- /package/dist/internal/resolvers/types/{dinamic-method-where-ops.type.js → dynamic-method-info.type.js} +0 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveDynamicMethodInfo = resolveDynamicMethodInfo;
|
|
4
|
+
const vs_repo_error_1 = require("../errors/vs-repo.error");
|
|
5
|
+
function resolveDynamicMethodInfo(instance, dynamicMethod, originalKey) {
|
|
6
|
+
const dynamicMethodInfo = {
|
|
7
|
+
onlyBaseWheres: false,
|
|
8
|
+
ignoreWhere: false,
|
|
9
|
+
ignoreOrderByAndPagination: true,
|
|
10
|
+
ignoreSelect: false,
|
|
11
|
+
keyToMapReplaced: "",
|
|
12
|
+
argsCount: 0,
|
|
13
|
+
method: "unknown",
|
|
14
|
+
existsMode: false,
|
|
15
|
+
ignoreSkipDuplicates: true,
|
|
16
|
+
whereParams: [],
|
|
17
|
+
otherParams: [],
|
|
18
|
+
ignoreDistinct: true,
|
|
19
|
+
};
|
|
20
|
+
if (dynamicMethod === "aggregate") {
|
|
21
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("aggregate", "");
|
|
22
|
+
dynamicMethodInfo.ignoreSelect = true;
|
|
23
|
+
dynamicMethodInfo.ignoreWhere = true;
|
|
24
|
+
dynamicMethodInfo.method = "aggregate";
|
|
25
|
+
dynamicMethodInfo.prismaArgsIndex = 0;
|
|
26
|
+
dynamicMethodInfo.otherParams.push("prismaArgs");
|
|
27
|
+
dynamicMethodInfo.argsCount++;
|
|
28
|
+
}
|
|
29
|
+
else if (dynamicMethod === "groupBy") {
|
|
30
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("groupBy", "");
|
|
31
|
+
dynamicMethodInfo.ignoreSelect = true;
|
|
32
|
+
dynamicMethodInfo.ignoreWhere = true;
|
|
33
|
+
dynamicMethodInfo.method = "groupBy";
|
|
34
|
+
dynamicMethodInfo.prismaArgsIndex = 0;
|
|
35
|
+
dynamicMethodInfo.otherParams.push("prismaArgs");
|
|
36
|
+
dynamicMethodInfo.argsCount++;
|
|
37
|
+
}
|
|
38
|
+
else if (dynamicMethod.startsWith("findUniqueOrThrowBy")) {
|
|
39
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("findUniqueOrThrowBy", "");
|
|
40
|
+
dynamicMethodInfo.method = "findUniqueOrThrow";
|
|
41
|
+
}
|
|
42
|
+
else if (dynamicMethod.startsWith("findUniqueBy")) {
|
|
43
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("findUniqueBy", "");
|
|
44
|
+
dynamicMethodInfo.method = "findUnique";
|
|
45
|
+
}
|
|
46
|
+
else if (dynamicMethod.startsWith("findFirstOrThrowBy")) {
|
|
47
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("findFirstOrThrowBy", "");
|
|
48
|
+
dynamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
49
|
+
dynamicMethodInfo.ignoreDistinct = false;
|
|
50
|
+
dynamicMethodInfo.method = "findFirstOrThrow";
|
|
51
|
+
}
|
|
52
|
+
else if (dynamicMethod.startsWith("findFirstOrThrow")) {
|
|
53
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("findFirstOrThrow", "");
|
|
54
|
+
dynamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
55
|
+
dynamicMethodInfo.ignoreWhere = true;
|
|
56
|
+
dynamicMethodInfo.onlyBaseWheres = true;
|
|
57
|
+
dynamicMethodInfo.ignoreDistinct = false;
|
|
58
|
+
dynamicMethodInfo.method = "findFirstOrThrow";
|
|
59
|
+
}
|
|
60
|
+
else if (dynamicMethod.startsWith("findFirstBy")) {
|
|
61
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("findFirstBy", "");
|
|
62
|
+
dynamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
63
|
+
dynamicMethodInfo.ignoreDistinct = false;
|
|
64
|
+
dynamicMethodInfo.method = "findFirst";
|
|
65
|
+
}
|
|
66
|
+
else if (dynamicMethod.startsWith("findFirst")) {
|
|
67
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("findFirst", "");
|
|
68
|
+
dynamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
69
|
+
dynamicMethodInfo.ignoreWhere = true;
|
|
70
|
+
dynamicMethodInfo.onlyBaseWheres = true;
|
|
71
|
+
dynamicMethodInfo.ignoreDistinct = false;
|
|
72
|
+
dynamicMethodInfo.method = "findFirst";
|
|
73
|
+
}
|
|
74
|
+
else if (dynamicMethod.startsWith("countBy")) {
|
|
75
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("countBy", "");
|
|
76
|
+
dynamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
77
|
+
dynamicMethodInfo.ignoreSelect = true;
|
|
78
|
+
dynamicMethodInfo.method = "count";
|
|
79
|
+
}
|
|
80
|
+
else if (dynamicMethod.startsWith("countWhere")) {
|
|
81
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("countWhere", "");
|
|
82
|
+
dynamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
83
|
+
dynamicMethodInfo.ignoreWhere = true;
|
|
84
|
+
dynamicMethodInfo.onlyBaseWheres = true;
|
|
85
|
+
dynamicMethodInfo.ignoreSelect = true;
|
|
86
|
+
dynamicMethodInfo.method = "count";
|
|
87
|
+
dynamicMethodInfo.whereIndex = 0;
|
|
88
|
+
dynamicMethodInfo.otherParams.push("where");
|
|
89
|
+
dynamicMethodInfo.argsCount += 1;
|
|
90
|
+
}
|
|
91
|
+
else if (dynamicMethod.startsWith("count")) {
|
|
92
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("count", "");
|
|
93
|
+
dynamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
94
|
+
dynamicMethodInfo.ignoreSelect = true;
|
|
95
|
+
dynamicMethodInfo.ignoreWhere = true;
|
|
96
|
+
dynamicMethodInfo.onlyBaseWheres = true;
|
|
97
|
+
dynamicMethodInfo.method = "count";
|
|
98
|
+
}
|
|
99
|
+
else if (dynamicMethod.startsWith("existsBy")) {
|
|
100
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("existsBy", "");
|
|
101
|
+
dynamicMethodInfo.ignoreSelect = true;
|
|
102
|
+
dynamicMethodInfo.existsMode = true;
|
|
103
|
+
dynamicMethodInfo.ignoreDistinct = false;
|
|
104
|
+
dynamicMethodInfo.method = "findFirst";
|
|
105
|
+
}
|
|
106
|
+
else if (dynamicMethod.startsWith("existsWhere")) {
|
|
107
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("existsWhere", "");
|
|
108
|
+
dynamicMethodInfo.ignoreSelect = true;
|
|
109
|
+
dynamicMethodInfo.existsMode = true;
|
|
110
|
+
dynamicMethodInfo.ignoreWhere = true;
|
|
111
|
+
dynamicMethodInfo.onlyBaseWheres = true;
|
|
112
|
+
dynamicMethodInfo.ignoreDistinct = false;
|
|
113
|
+
dynamicMethodInfo.method = "findFirst";
|
|
114
|
+
dynamicMethodInfo.whereIndex = 0;
|
|
115
|
+
dynamicMethodInfo.otherParams.push("where");
|
|
116
|
+
dynamicMethodInfo.argsCount += 1;
|
|
117
|
+
}
|
|
118
|
+
else if (dynamicMethod.startsWith("findManyBy")) {
|
|
119
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("findManyBy", "");
|
|
120
|
+
dynamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
121
|
+
dynamicMethodInfo.ignoreDistinct = false;
|
|
122
|
+
dynamicMethodInfo.method = "findMany";
|
|
123
|
+
}
|
|
124
|
+
else if (dynamicMethod.startsWith("findMany")) {
|
|
125
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("findMany", "");
|
|
126
|
+
dynamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
127
|
+
dynamicMethodInfo.ignoreWhere = true;
|
|
128
|
+
dynamicMethodInfo.onlyBaseWheres = true;
|
|
129
|
+
dynamicMethodInfo.ignoreDistinct = false;
|
|
130
|
+
dynamicMethodInfo.method = "findMany";
|
|
131
|
+
}
|
|
132
|
+
else if (dynamicMethod.startsWith("createManyAndReturn")) {
|
|
133
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("createManyAndReturn", "");
|
|
134
|
+
dynamicMethodInfo.ignoreWhere = true;
|
|
135
|
+
dynamicMethodInfo.ignoreSkipDuplicates = false;
|
|
136
|
+
dynamicMethodInfo.method = "createManyAndReturn";
|
|
137
|
+
dynamicMethodInfo.dataIndex = 0;
|
|
138
|
+
dynamicMethodInfo.otherParams.push("data");
|
|
139
|
+
dynamicMethodInfo.argsCount++;
|
|
140
|
+
}
|
|
141
|
+
else if (dynamicMethod.startsWith("createMany")) {
|
|
142
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("createMany", "");
|
|
143
|
+
dynamicMethodInfo.ignoreWhere = true;
|
|
144
|
+
dynamicMethodInfo.ignoreSelect = true;
|
|
145
|
+
dynamicMethodInfo.ignoreSkipDuplicates = false;
|
|
146
|
+
dynamicMethodInfo.method = "createMany";
|
|
147
|
+
dynamicMethodInfo.dataIndex = 0;
|
|
148
|
+
dynamicMethodInfo.otherParams.push("data");
|
|
149
|
+
dynamicMethodInfo.argsCount++;
|
|
150
|
+
}
|
|
151
|
+
else if (dynamicMethod.startsWith("create")) {
|
|
152
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("create", "");
|
|
153
|
+
dynamicMethodInfo.ignoreWhere = true;
|
|
154
|
+
dynamicMethodInfo.method = "create";
|
|
155
|
+
dynamicMethodInfo.dataIndex = 0;
|
|
156
|
+
dynamicMethodInfo.otherParams.push("data");
|
|
157
|
+
dynamicMethodInfo.argsCount++;
|
|
158
|
+
}
|
|
159
|
+
else if (dynamicMethod.startsWith("updateManyAndReturnBy")) {
|
|
160
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("updateManyAndReturnBy", "");
|
|
161
|
+
dynamicMethodInfo.method = "updateManyAndReturn";
|
|
162
|
+
dynamicMethodInfo.dataIndex = -2;
|
|
163
|
+
dynamicMethodInfo.otherParams.push("data");
|
|
164
|
+
dynamicMethodInfo.argsCount++;
|
|
165
|
+
}
|
|
166
|
+
else if (dynamicMethod.startsWith("updateManyAndReturnWhere")) {
|
|
167
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("updateManyAndReturnWhere", "");
|
|
168
|
+
dynamicMethodInfo.ignoreWhere = true;
|
|
169
|
+
dynamicMethodInfo.onlyBaseWheres = true;
|
|
170
|
+
dynamicMethodInfo.method = "updateManyAndReturn";
|
|
171
|
+
dynamicMethodInfo.dataIndex = -2;
|
|
172
|
+
dynamicMethodInfo.whereIndex = 0;
|
|
173
|
+
dynamicMethodInfo.otherParams.push("where", "data");
|
|
174
|
+
dynamicMethodInfo.argsCount += 2;
|
|
175
|
+
}
|
|
176
|
+
else if (dynamicMethod.startsWith("updateManyBy")) {
|
|
177
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("updateManyBy", "");
|
|
178
|
+
dynamicMethodInfo.ignoreSelect = true;
|
|
179
|
+
dynamicMethodInfo.method = "updateMany";
|
|
180
|
+
dynamicMethodInfo.dataIndex = -2;
|
|
181
|
+
dynamicMethodInfo.otherParams.push("data");
|
|
182
|
+
dynamicMethodInfo.argsCount++;
|
|
183
|
+
}
|
|
184
|
+
else if (dynamicMethod.startsWith("updateManyWhere")) {
|
|
185
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("updateManyWhere", "");
|
|
186
|
+
dynamicMethodInfo.ignoreSelect = true;
|
|
187
|
+
dynamicMethodInfo.ignoreWhere = true;
|
|
188
|
+
dynamicMethodInfo.onlyBaseWheres = true;
|
|
189
|
+
dynamicMethodInfo.method = "updateMany";
|
|
190
|
+
dynamicMethodInfo.dataIndex = -2;
|
|
191
|
+
dynamicMethodInfo.whereIndex = 0;
|
|
192
|
+
dynamicMethodInfo.otherParams.push("where", "data");
|
|
193
|
+
dynamicMethodInfo.argsCount += 2;
|
|
194
|
+
}
|
|
195
|
+
else if (dynamicMethod.startsWith("updateBy")) {
|
|
196
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("updateBy", "");
|
|
197
|
+
dynamicMethodInfo.method = "update";
|
|
198
|
+
dynamicMethodInfo.dataIndex = -2;
|
|
199
|
+
dynamicMethodInfo.otherParams.push("data");
|
|
200
|
+
dynamicMethodInfo.argsCount++;
|
|
201
|
+
}
|
|
202
|
+
else if (dynamicMethod.startsWith("upsertBy")) {
|
|
203
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("upsertBy", "");
|
|
204
|
+
dynamicMethodInfo.method = "upsert";
|
|
205
|
+
dynamicMethodInfo.createIndex = -2;
|
|
206
|
+
dynamicMethodInfo.updateIndex = -3;
|
|
207
|
+
dynamicMethodInfo.otherParams.push("update");
|
|
208
|
+
dynamicMethodInfo.otherParams.push("create");
|
|
209
|
+
dynamicMethodInfo.argsCount += 2;
|
|
210
|
+
}
|
|
211
|
+
else if (dynamicMethod.startsWith("deleteManyBy")) {
|
|
212
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("deleteManyBy", "");
|
|
213
|
+
dynamicMethodInfo.ignoreSelect = true;
|
|
214
|
+
dynamicMethodInfo.method = "deleteMany";
|
|
215
|
+
}
|
|
216
|
+
else if (dynamicMethod.startsWith("deleteManyWhere")) {
|
|
217
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("deleteManyWhere", "");
|
|
218
|
+
dynamicMethodInfo.ignoreSelect = true;
|
|
219
|
+
dynamicMethodInfo.ignoreWhere = true;
|
|
220
|
+
dynamicMethodInfo.onlyBaseWheres = true;
|
|
221
|
+
dynamicMethodInfo.method = "deleteMany";
|
|
222
|
+
dynamicMethodInfo.whereIndex = 0;
|
|
223
|
+
dynamicMethodInfo.otherParams.push("where");
|
|
224
|
+
dynamicMethodInfo.argsCount += 1;
|
|
225
|
+
}
|
|
226
|
+
else if (dynamicMethod.startsWith("deleteBy")) {
|
|
227
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("deleteBy", "");
|
|
228
|
+
dynamicMethodInfo.method = "delete";
|
|
229
|
+
}
|
|
230
|
+
else if (dynamicMethod.startsWith("findWhere")) {
|
|
231
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("findWhere", "");
|
|
232
|
+
dynamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
233
|
+
dynamicMethodInfo.ignoreWhere = true;
|
|
234
|
+
dynamicMethodInfo.onlyBaseWheres = true;
|
|
235
|
+
dynamicMethodInfo.ignoreDistinct = false;
|
|
236
|
+
dynamicMethodInfo.method = "findFirst";
|
|
237
|
+
dynamicMethodInfo.whereIndex = 0;
|
|
238
|
+
dynamicMethodInfo.otherParams.push("where");
|
|
239
|
+
dynamicMethodInfo.argsCount += 1;
|
|
240
|
+
}
|
|
241
|
+
else if (dynamicMethod.startsWith("findOneWhere")) {
|
|
242
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("findOneWhere", "");
|
|
243
|
+
dynamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
244
|
+
dynamicMethodInfo.ignoreWhere = true;
|
|
245
|
+
dynamicMethodInfo.onlyBaseWheres = true;
|
|
246
|
+
dynamicMethodInfo.ignoreDistinct = false;
|
|
247
|
+
dynamicMethodInfo.method = "findFirst";
|
|
248
|
+
dynamicMethodInfo.whereIndex = 0;
|
|
249
|
+
dynamicMethodInfo.otherParams.push("where");
|
|
250
|
+
dynamicMethodInfo.argsCount += 1;
|
|
251
|
+
}
|
|
252
|
+
else if (dynamicMethod.startsWith("findListWhere")) {
|
|
253
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("findListWhere", "");
|
|
254
|
+
dynamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
255
|
+
dynamicMethodInfo.ignoreWhere = true;
|
|
256
|
+
dynamicMethodInfo.onlyBaseWheres = true;
|
|
257
|
+
dynamicMethodInfo.ignoreDistinct = false;
|
|
258
|
+
dynamicMethodInfo.method = "findMany";
|
|
259
|
+
dynamicMethodInfo.whereIndex = 0;
|
|
260
|
+
dynamicMethodInfo.otherParams.push("where");
|
|
261
|
+
dynamicMethodInfo.argsCount += 1;
|
|
262
|
+
}
|
|
263
|
+
else if (dynamicMethod.startsWith("findOneBy")) {
|
|
264
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("findOneBy", "");
|
|
265
|
+
dynamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
266
|
+
dynamicMethodInfo.ignoreDistinct = false;
|
|
267
|
+
dynamicMethodInfo.method = "findFirst";
|
|
268
|
+
}
|
|
269
|
+
else if (dynamicMethod.startsWith("findBy")) {
|
|
270
|
+
dynamicMethodInfo.keyToMapReplaced = dynamicMethod.replace("findBy", "");
|
|
271
|
+
dynamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
272
|
+
dynamicMethodInfo.ignoreDistinct = false;
|
|
273
|
+
dynamicMethodInfo.method = instance.methods?.[originalKey]?.fbMode === "one" ? "findFirst" : "findMany";
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
throw new vs_repo_error_1.VSRepoBuildError(`[VSRepository] (${instance.tableName}: build) Unknown method: ${dynamicMethod}.`);
|
|
277
|
+
}
|
|
278
|
+
return dynamicMethodInfo;
|
|
279
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveDynamicMethodsMetadata = resolveDynamicMethodsMetadata;
|
|
4
|
-
const
|
|
4
|
+
const dynamic_methods_key_constant_1 = require("../constants/dynamic-methods-key.constant");
|
|
5
5
|
function resolveDynamicMethodsMetadata(prototype) {
|
|
6
|
-
const methods = Reflect.getMetadata(
|
|
6
|
+
const methods = Reflect.getMetadata(dynamic_methods_key_constant_1.DYNAMIC_METHODS_KEY, prototype);
|
|
7
7
|
const methodsRecord = {};
|
|
8
8
|
if (!methods)
|
|
9
9
|
return methodsRecord;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolvePrettyWheres = resolvePrettyWheres;
|
|
4
4
|
const ugly_where_resolve_1 = require("./ugly-where.resolve");
|
|
5
|
-
function resolvePrettyWheres(
|
|
5
|
+
function resolvePrettyWheres(dynamicMethodInfo, dynamicMethodWhereOps) {
|
|
6
6
|
let ANDMode = false;
|
|
7
|
-
let keysSplitedAND =
|
|
7
|
+
let keysSplitedAND = dynamicMethodInfo.keyToMapReplaced.split("AND");
|
|
8
8
|
if (keysSplitedAND.length > 1) {
|
|
9
9
|
ANDMode = true;
|
|
10
10
|
}
|
|
@@ -26,18 +26,18 @@ function resolvePrettyWheres(dinamicMethodInfo, dinamicMethodWhereOps) {
|
|
|
26
26
|
if (idx === 1 && ANDMode) {
|
|
27
27
|
uglyWhere.name = `AND.${i}idx.${uglyWhere.name}`;
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
dynamicMethodWhereOps.uglyWheres.push(uglyWhere);
|
|
30
30
|
}
|
|
31
31
|
else {
|
|
32
32
|
uglyWhere.name = `OR.${i}idx.${uglyWhere.name}`;
|
|
33
|
-
|
|
33
|
+
dynamicMethodWhereOps.uglyWheres.push(uglyWhere);
|
|
34
34
|
}
|
|
35
35
|
if (uglyWhere.autoInjectVal === undefined)
|
|
36
|
-
|
|
36
|
+
dynamicMethodInfo.argsCount++;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
|
-
const prettyWheres =
|
|
40
|
+
const prettyWheres = dynamicMethodWhereOps.uglyWheres.map(arg => {
|
|
41
41
|
let context = [];
|
|
42
42
|
let otherProps = undefined;
|
|
43
43
|
let argName = arg.name;
|
|
@@ -74,7 +74,7 @@ function resolvePrettyWheres(dinamicMethodInfo, dinamicMethodWhereOps) {
|
|
|
74
74
|
context.push("equals");
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
dynamicMethodInfo.whereParams.push(argName);
|
|
78
78
|
return {
|
|
79
79
|
context,
|
|
80
80
|
otherProps,
|
|
@@ -83,5 +83,5 @@ function resolvePrettyWheres(dinamicMethodInfo, dinamicMethodWhereOps) {
|
|
|
83
83
|
betweenMode: arg.betweenMode,
|
|
84
84
|
};
|
|
85
85
|
});
|
|
86
|
-
|
|
86
|
+
dynamicMethodWhereOps.prettyWheres = prettyWheres;
|
|
87
87
|
}
|
|
@@ -12,7 +12,8 @@ exports.queryOptionsSchema = zod_1.default.strictObject({
|
|
|
12
12
|
value: exports.stringSchema,
|
|
13
13
|
modifying: exports.booleanSchema.default(false),
|
|
14
14
|
});
|
|
15
|
-
exports.methodSchema = zod_1.default
|
|
15
|
+
exports.methodSchema = zod_1.default
|
|
16
|
+
.strictObject({
|
|
16
17
|
map: exports.booleanSchema,
|
|
17
18
|
selectModel: exports.stringSchema.or(zod_1.default.literal(false)).optional(),
|
|
18
19
|
whereType: zod_1.default.enum(["overwrite", "extending"]).optional(),
|
|
@@ -20,6 +21,11 @@ exports.methodSchema = zod_1.default.strictObject({
|
|
|
20
21
|
pushWhere: exports.objectSchema.optional(),
|
|
21
22
|
fbMode: zod_1.default.enum(["one", "list"]).optional(),
|
|
22
23
|
injectOrdenation: exports.objectSchema.or(zod_1.default.array(exports.objectSchema)).optional(),
|
|
24
|
+
injectOrdering: exports.objectSchema.or(zod_1.default.array(exports.objectSchema)).optional(),
|
|
23
25
|
injectPagination: exports.objectSchema.optional(),
|
|
24
26
|
query: exports.queryOptionsSchema.optional(),
|
|
25
|
-
})
|
|
27
|
+
})
|
|
28
|
+
.transform(({ injectOrdenation, injectOrdering, ...value }) => ({
|
|
29
|
+
...value,
|
|
30
|
+
injectOrdering: injectOrdering ?? injectOrdenation,
|
|
31
|
+
}));
|
|
@@ -26,10 +26,9 @@ function validateConstructorConfig(config) {
|
|
|
26
26
|
nullable: schemas_util_1.booleanSchema.optional(),
|
|
27
27
|
}))
|
|
28
28
|
.optional(),
|
|
29
|
-
methods: zod_1.default
|
|
30
|
-
.record(schemas_util_1.stringSchema, schemas_util_1.methodSchema)
|
|
31
|
-
.optional(),
|
|
29
|
+
methods: zod_1.default.record(schemas_util_1.stringSchema, schemas_util_1.methodSchema).optional(),
|
|
32
30
|
defaultOrdenation: schemas_util_1.objectSchema.or(zod_1.default.array(schemas_util_1.objectSchema)).optional(),
|
|
31
|
+
defaultOrdering: schemas_util_1.objectSchema.or(zod_1.default.array(schemas_util_1.objectSchema)).optional(),
|
|
33
32
|
})
|
|
34
33
|
.superRefine((config, ctx) => {
|
|
35
34
|
if (config.defaultSelectModel && !config.selectModels?.[config.defaultSelectModel]) {
|
|
@@ -50,7 +49,11 @@ function validateConstructorConfig(config) {
|
|
|
50
49
|
}
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
|
-
})
|
|
52
|
+
})
|
|
53
|
+
.transform(({ defaultOrdenation, defaultOrdering, ...value }) => ({
|
|
54
|
+
...value,
|
|
55
|
+
defaultOrdering: defaultOrdering ?? defaultOrdenation,
|
|
56
|
+
}));
|
|
54
57
|
const configParsed = configSchema.safeParse(config);
|
|
55
58
|
if (!configParsed.success) {
|
|
56
59
|
const firstIssue = configParsed.error.issues[0];
|
|
@@ -18,12 +18,19 @@ function validateMethodOptions(options, instance) {
|
|
|
18
18
|
includeModel: zod_1.default.enum(Object.keys(instance.includeModels ?? {})).optional(),
|
|
19
19
|
see: zod_1.default.enum(["active", "removed", "all"]).default("active"),
|
|
20
20
|
include: schemas_util_1.objectSchema.optional(),
|
|
21
|
+
select: schemas_util_1.objectSchema.optional(),
|
|
21
22
|
})
|
|
22
23
|
.refine(data => {
|
|
23
|
-
|
|
24
|
+
const provided = [
|
|
25
|
+
data.select !== undefined,
|
|
26
|
+
data.selectModel !== undefined,
|
|
27
|
+
data.include !== undefined,
|
|
28
|
+
data.includeModel !== undefined,
|
|
29
|
+
].filter(Boolean).length;
|
|
30
|
+
return provided <= 1;
|
|
24
31
|
}, {
|
|
25
|
-
message: "
|
|
26
|
-
path: ["
|
|
32
|
+
message: "'select', 'selectModel', 'include' and 'includeModel' are mutually exclusive — only one can be provided.",
|
|
33
|
+
path: ["options"],
|
|
27
34
|
});
|
|
28
35
|
const optionsParsed = optionsSchema.safeParse(options ?? {});
|
|
29
36
|
if (!optionsParsed.success) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vsrepo",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.6",
|
|
4
4
|
"description": "A repository pattern library for Prisma",
|
|
5
5
|
"homepage": "https://github.com/jaobrabo123/VSRepository#readme",
|
|
6
6
|
"repository": {
|
|
@@ -45,7 +45,11 @@
|
|
|
45
45
|
"scripts": {
|
|
46
46
|
"vsrepo": "node ./scripts/configure-prisma-import.mjs",
|
|
47
47
|
"build": "tsc -p tsconfig.build.json && node ./scripts/copy-types.mjs",
|
|
48
|
-
"prepack": "pnpm build"
|
|
48
|
+
"prepack": "pnpm build",
|
|
49
|
+
"test": "npm run test:typing && npm run test:implementation",
|
|
50
|
+
"test:implementation": "cross-env NODE_OPTIONS=--experimental-vm-modules jest",
|
|
51
|
+
"test:implementation:watch": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --watch",
|
|
52
|
+
"test:typing": "tsc --noEmit -p test/typing/tsconfig.json"
|
|
49
53
|
},
|
|
50
54
|
"keywords": [
|
|
51
55
|
"prisma",
|
|
@@ -62,11 +66,16 @@
|
|
|
62
66
|
"@prisma/client": "^7.8.0"
|
|
63
67
|
},
|
|
64
68
|
"devDependencies": {
|
|
69
|
+
"@jest/globals": "^30.4.1",
|
|
65
70
|
"@prisma/adapter-pg": "^7.8.0",
|
|
66
71
|
"@prisma/client": "^7.8.0",
|
|
72
|
+
"@types/jest": "^30.0.0",
|
|
67
73
|
"@types/node": "^25.6.0",
|
|
74
|
+
"cross-env": "^10.1.0",
|
|
68
75
|
"dotenv": "^17.4.2",
|
|
76
|
+
"jest": "^30.4.2",
|
|
69
77
|
"prisma": "^7.8.0",
|
|
78
|
+
"ts-jest": "^29.4.12",
|
|
70
79
|
"tsx": "^4.22.3",
|
|
71
80
|
"typescript": "^6.0.3"
|
|
72
81
|
},
|
|
@@ -137,7 +137,8 @@ const tsFiles = [
|
|
|
137
137
|
VSRepoConfigError as VSRepoConfigErrorRuntime,
|
|
138
138
|
VSRepoBuildError as VSRepoBuildErrorRuntime,
|
|
139
139
|
VSRepoExtendError as VSRepoExtendErrorRuntime,
|
|
140
|
-
VSRepoRuntimeError as VSRepoRuntimeErrorRuntime
|
|
140
|
+
VSRepoRuntimeError as VSRepoRuntimeErrorRuntime,
|
|
141
|
+
VSRepoDecoratorError as VSRepoDecoratorErrorRuntime,
|
|
141
142
|
} from 'vsrepo/VSRepoError';
|
|
142
143
|
|
|
143
144
|
import type {
|
|
@@ -145,14 +146,16 @@ import type {
|
|
|
145
146
|
VSRepoConfigError as VSRepoConfigErrorType,
|
|
146
147
|
VSRepoBuildError as VSRepoBuildErrorType,
|
|
147
148
|
VSRepoExtendError as VSRepoExtendErrorType,
|
|
148
|
-
VSRepoRuntimeError as VSRepoRuntimeErrorType
|
|
149
|
+
VSRepoRuntimeError as VSRepoRuntimeErrorType,
|
|
150
|
+
VSRepoDecoratorError as VSRepoDecoratorErrorType,
|
|
149
151
|
} from './VSRepoError.types';
|
|
150
152
|
|
|
151
|
-
export const VSRepoError
|
|
152
|
-
export const VSRepoConfigError
|
|
153
|
-
export const VSRepoBuildError
|
|
154
|
-
export const VSRepoExtendError
|
|
155
|
-
export const VSRepoRuntimeError
|
|
153
|
+
export const VSRepoError = VSRepoErrorRuntime as typeof VSRepoErrorType;
|
|
154
|
+
export const VSRepoConfigError = VSRepoConfigErrorRuntime as typeof VSRepoConfigErrorType;
|
|
155
|
+
export const VSRepoBuildError = VSRepoBuildErrorRuntime as typeof VSRepoBuildErrorType;
|
|
156
|
+
export const VSRepoExtendError = VSRepoExtendErrorRuntime as typeof VSRepoExtendErrorType;
|
|
157
|
+
export const VSRepoRuntimeError = VSRepoRuntimeErrorRuntime as typeof VSRepoRuntimeErrorType;
|
|
158
|
+
export const VSRepoDecoratorError = VSRepoDecoratorErrorRuntime as typeof VSRepoDecoratorErrorType;
|
|
156
159
|
|
|
157
160
|
export type * from './VSRepoError.types';
|
|
158
161
|
`,
|
|
@@ -203,7 +206,8 @@ export type * from './DynamicRepository.types';
|
|
|
203
206
|
VSRepoConfigError,
|
|
204
207
|
VSRepoBuildError,
|
|
205
208
|
VSRepoExtendError,
|
|
206
|
-
VSRepoRuntimeError
|
|
209
|
+
VSRepoRuntimeError,
|
|
210
|
+
VSRepoDecoratorError
|
|
207
211
|
} from './VSRepoError.js';
|
|
208
212
|
|
|
209
213
|
export {
|
package/scripts/copy-types.mjs
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import fs from
|
|
3
|
-
import path from
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
4
|
|
|
5
|
-
const srcDir =
|
|
6
|
-
const distDir =
|
|
5
|
+
const srcDir = "./src";
|
|
6
|
+
const distDir = "./dist";
|
|
7
7
|
|
|
8
8
|
function copyDefs(dir) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
const files = fs.readdirSync(dir);
|
|
10
|
+
for (const file of files) {
|
|
11
|
+
const fullPath = path.join(dir, file);
|
|
12
|
+
if (fs.statSync(fullPath).isDirectory()) {
|
|
13
|
+
copyDefs(fullPath);
|
|
14
|
+
} else if (file.endsWith(".d.ts")) {
|
|
15
|
+
const relativePath = path.relative(srcDir, fullPath);
|
|
16
|
+
const destPath = path.join(distDir, relativePath);
|
|
17
|
+
fs.mkdirSync(path.dirname(destPath), { recursive: true });
|
|
18
|
+
fs.copyFileSync(fullPath, destPath);
|
|
19
|
+
}
|
|
19
20
|
}
|
|
20
|
-
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
copyDefs(srcDir);
|
|
24
|
-
console.log(
|
|
24
|
+
console.log("Arquivos .d.ts copiados para a pasta dist.");
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveDinamicMethodCustomization = resolveDinamicMethodCustomization;
|
|
4
|
-
const uncapitalize_util_1 = require("../utils/uncapitalize.util");
|
|
5
|
-
function resolveDinamicMethodCustomization(instance, dinamicMethodInfo, originalKey) {
|
|
6
|
-
const dinamicMethodCustomization = {};
|
|
7
|
-
if (!dinamicMethodInfo.ignoreSkipDuplicates) {
|
|
8
|
-
if (dinamicMethodInfo.keyToMapReplaced.endsWith("SkipDuplicates")) {
|
|
9
|
-
dinamicMethodInfo.keyToMapReplaced = dinamicMethodInfo.keyToMapReplaced.replace("SkipDuplicates", "");
|
|
10
|
-
dinamicMethodCustomization.skipDuplicates = true;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
if (!dinamicMethodInfo.ignoreOrderByAndPagination) {
|
|
14
|
-
dinamicMethodCustomization.injectOrdenation =
|
|
15
|
-
instance.methods?.[originalKey]?.injectOrdenation;
|
|
16
|
-
dinamicMethodCustomization.injectPagination =
|
|
17
|
-
instance.methods?.[originalKey]?.injectPagination;
|
|
18
|
-
if (dinamicMethodInfo.keyToMapReplaced.endsWith("PaginatedAndOrdered")) {
|
|
19
|
-
dinamicMethodCustomization.orderPosition = -2;
|
|
20
|
-
dinamicMethodCustomization.paginationPosition = -3;
|
|
21
|
-
dinamicMethodInfo.otherParams.push("pagination");
|
|
22
|
-
dinamicMethodInfo.otherParams.push("order");
|
|
23
|
-
dinamicMethodInfo.keyToMapReplaced = dinamicMethodInfo.keyToMapReplaced.replace("PaginatedAndOrdered", "");
|
|
24
|
-
dinamicMethodInfo.argsCount += 2;
|
|
25
|
-
}
|
|
26
|
-
else if (dinamicMethodInfo.keyToMapReplaced.endsWith("OrderedAndPaginated")) {
|
|
27
|
-
dinamicMethodCustomization.orderPosition = -3;
|
|
28
|
-
dinamicMethodCustomization.paginationPosition = -2;
|
|
29
|
-
dinamicMethodInfo.otherParams.push("order");
|
|
30
|
-
dinamicMethodInfo.otherParams.push("pagination");
|
|
31
|
-
dinamicMethodInfo.keyToMapReplaced = dinamicMethodInfo.keyToMapReplaced.replace("OrderedAndPaginated", "");
|
|
32
|
-
dinamicMethodInfo.argsCount += 2;
|
|
33
|
-
}
|
|
34
|
-
else if (dinamicMethodInfo.keyToMapReplaced.endsWith("Paginated")) {
|
|
35
|
-
dinamicMethodCustomization.paginationPosition = -2;
|
|
36
|
-
dinamicMethodInfo.otherParams.push("pagination");
|
|
37
|
-
dinamicMethodInfo.keyToMapReplaced = dinamicMethodInfo.keyToMapReplaced.replace("Paginated", "");
|
|
38
|
-
dinamicMethodInfo.argsCount++;
|
|
39
|
-
}
|
|
40
|
-
else if (dinamicMethodInfo.keyToMapReplaced.endsWith("Ordered")) {
|
|
41
|
-
dinamicMethodCustomization.orderPosition = -2;
|
|
42
|
-
dinamicMethodInfo.otherParams.push("order");
|
|
43
|
-
dinamicMethodInfo.keyToMapReplaced = dinamicMethodInfo.keyToMapReplaced.replace("Ordered", "");
|
|
44
|
-
dinamicMethodInfo.argsCount++;
|
|
45
|
-
}
|
|
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
|
-
}
|
|
56
|
-
return dinamicMethodCustomization;
|
|
57
|
-
}
|