vsrepo 1.3.5 → 1.3.7
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 +147 -137
- package/README.pt-BR.md +154 -144
- package/dist/DynamicRepository.d.ts +24 -7
- package/dist/VSRepoError.d.ts +21 -1
- package/dist/VSRepository.d.ts +36 -12
- 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 +3 -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 +4 -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/package.json +1 -1
- package/scripts/configure-prisma-import.mjs +23 -10
- 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];
|
package/package.json
CHANGED
|
@@ -206,7 +206,8 @@ export type * from './DynamicRepository.types';
|
|
|
206
206
|
VSRepoConfigError,
|
|
207
207
|
VSRepoBuildError,
|
|
208
208
|
VSRepoExtendError,
|
|
209
|
-
VSRepoRuntimeError
|
|
209
|
+
VSRepoRuntimeError,
|
|
210
|
+
VSRepoDecoratorError
|
|
210
211
|
} from './VSRepoError.js';
|
|
211
212
|
|
|
212
213
|
export {
|
|
@@ -235,16 +236,28 @@ for (const file of tsFiles) {
|
|
|
235
236
|
console.log(`Gerado: ${path.relative(workspaceRoot, targetFile)}`);
|
|
236
237
|
}
|
|
237
238
|
|
|
238
|
-
// Copia
|
|
239
|
-
|
|
240
|
-
|
|
239
|
+
// Copia os READMEs da raiz do projeto para a pasta 'docs' do diretório de output
|
|
240
|
+
const readmeFiles = [
|
|
241
|
+
'README.md',
|
|
242
|
+
'README.pt-BR.md',
|
|
243
|
+
'README-DynamicRepo.md',
|
|
244
|
+
'README-DynamicRepo.pt-BR.md',
|
|
245
|
+
];
|
|
246
|
+
|
|
247
|
+
const readmeOutputDir = path.join(outputDir, 'docs');
|
|
248
|
+
fs.mkdirSync(readmeOutputDir, { recursive: true });
|
|
249
|
+
|
|
250
|
+
for (const fileName of readmeFiles) {
|
|
251
|
+
const readmeSource = path.join(workspaceRoot, fileName);
|
|
252
|
+
const readmeTarget = path.join(readmeOutputDir, fileName);
|
|
241
253
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
254
|
+
if (fs.existsSync(readmeSource)) {
|
|
255
|
+
fs.copyFileSync(readmeSource, readmeTarget);
|
|
256
|
+
console.log(`Gerado: ${path.relative(workspaceRoot, readmeTarget)}`);
|
|
257
|
+
} else {
|
|
258
|
+
console.warn(`README nao encontrado em: ${path.relative(workspaceRoot, readmeSource)}. Ignorando a copia.`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
248
261
|
|
|
249
262
|
console.log('\nVSRepository gerado com tipagem do Prisma.');
|
|
250
263
|
console.log(`Output: ${path.relative(workspaceRoot, outputDir)}`);
|
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
|
-
}
|