vsrepo 1.2.6 → 1.2.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 +296 -437
- package/{VSRepository → dist}/VSRepoError.d.ts +1 -1
- package/dist/VSRepoError.js +17 -0
- package/{VSRepository → dist}/VSRepository.d.ts +937 -907
- package/dist/VSRepository.js +204 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/dist/internal/errors/types/vs-repo-error-type.type.js +2 -0
- package/dist/internal/errors/vs-repo.error.js +27 -0
- package/dist/internal/resolvers/base-methods.resolve.js +535 -0
- package/dist/internal/resolvers/create-update-payloads-with-relations.resolve.js +143 -0
- package/dist/internal/resolvers/data-payload-with-relations.resolve.js +60 -0
- package/dist/internal/resolvers/dbAndPrismaArgs.resolve.js +46 -0
- package/dist/internal/resolvers/dinamic-method-customization.resolve.js +45 -0
- package/dist/internal/resolvers/dinamic-method-info.resolve.js +265 -0
- package/dist/internal/resolvers/merge-wheres.resolve.js +22 -0
- package/dist/internal/resolvers/pretty-wheres.resolve.js +87 -0
- package/dist/internal/resolvers/select.resolve.js +7 -0
- package/dist/internal/resolvers/specific-where.resolve.js +77 -0
- package/dist/internal/resolvers/types/base-method-function.type.js +2 -0
- package/dist/internal/resolvers/types/dinamic-method-customization.type.js +2 -0
- package/dist/internal/resolvers/types/dinamic-method-info.type.js +2 -0
- package/dist/internal/resolvers/types/dinamic-method-where-ops.type.js +2 -0
- package/dist/internal/resolvers/types/pretty-where.type.js +2 -0
- package/dist/internal/resolvers/types/prisma-args.type.js +2 -0
- package/dist/internal/resolvers/types/repository-build-instance.type.js +2 -0
- package/dist/internal/resolvers/types/resolve-db-and-prisma-args-data.type.js +2 -0
- package/dist/internal/resolvers/types/ugly-where.type.js +2 -0
- package/dist/internal/resolvers/ugly-where.resolve.js +178 -0
- package/dist/internal/utils/logger.util.js +21 -0
- package/dist/internal/utils/schemas.util.js +10 -0
- package/dist/internal/utils/uncapitalize.util.js +6 -0
- package/dist/internal/validation/build-config.validate.js +84 -0
- package/dist/internal/validation/constructor-config.validate.js +68 -0
- package/dist/internal/validation/extension.validate.js +15 -0
- package/dist/internal/validation/is-object.validate.js +6 -0
- package/dist/internal/validation/method-options.validate.js +26 -0
- package/dist/internal/validation/obj-with-relations.validate.js +37 -0
- package/dist/internal/validation/prisma-client.validate.js +10 -0
- package/dist/internal/validation/types/base-methods.type.js +2 -0
- package/dist/internal/validation/types/build-config.type.js +2 -0
- package/dist/internal/validation/types/constructor-config.type.js +2 -0
- package/dist/internal/validation/types/method-options.type.js +2 -0
- package/dist/internal/validation/types/method.type.js +2 -0
- package/dist/internal/validation/types/pagination.type.js +2 -0
- package/dist/internal/validation/types/relation.type.js +2 -0
- package/dist/internal/validation/types/see-mode.type.js +2 -0
- package/package.json +72 -70
- package/scripts/configure-prisma-import.mjs +3 -3
- package/scripts/copy-types.mjs +24 -0
- package/VSRepository/VSRepoError.js +0 -33
- package/VSRepository/VSRepoUtils.js +0 -155
- package/VSRepository/VSRepository.js +0 -1445
- package/VSRepository/index.d.ts +0 -2
- package/VSRepository/index.js +0 -2
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveDataPayloadWithRelations = resolveDataPayloadWithRelations;
|
|
4
|
+
function resolveDataPayloadWithRelations(instance, obj, relationsKeys) {
|
|
5
|
+
const relations = instance.relations;
|
|
6
|
+
if (!relations)
|
|
7
|
+
return obj;
|
|
8
|
+
const dataPayload = {};
|
|
9
|
+
const objKeys = Object.keys(obj);
|
|
10
|
+
for (let i = 0; i < objKeys.length; i++) {
|
|
11
|
+
const key = objKeys[i];
|
|
12
|
+
const field = obj[key];
|
|
13
|
+
if (field === undefined)
|
|
14
|
+
continue;
|
|
15
|
+
if (relationsKeys.includes(key)) {
|
|
16
|
+
if (field === null)
|
|
17
|
+
continue;
|
|
18
|
+
const relation = relations[key];
|
|
19
|
+
if (relation.mode === "otm" || relation.mode === "mtm") {
|
|
20
|
+
const dataWithPk = [];
|
|
21
|
+
const dataWithoutPk = [];
|
|
22
|
+
field.forEach((data) => {
|
|
23
|
+
if (data[relation.pk] !== undefined) {
|
|
24
|
+
dataWithPk.push(data);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
dataWithoutPk.push(data);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
dataPayload[key] = {
|
|
31
|
+
create: dataWithoutPk,
|
|
32
|
+
connectOrCreate: dataWithPk.map(data => ({
|
|
33
|
+
where: { [relation.pk]: data[relation.pk] },
|
|
34
|
+
create: data,
|
|
35
|
+
})),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const relationFieldPk = field[relation.pk];
|
|
40
|
+
if (relationFieldPk != null) {
|
|
41
|
+
dataPayload[key] = {
|
|
42
|
+
connectOrCreate: {
|
|
43
|
+
where: { [relation.pk]: relationFieldPk },
|
|
44
|
+
create: field,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
dataPayload[key] = {
|
|
50
|
+
create: field,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
dataPayload[key] = field;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return dataPayload;
|
|
60
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveDbAndPrismaArgs = resolveDbAndPrismaArgs;
|
|
4
|
+
const method_options_validate_1 = require("../validation/method-options.validate");
|
|
5
|
+
const merge_wheres_resolve_1 = require("./merge-wheres.resolve");
|
|
6
|
+
const select_resolve_1 = require("./select.resolve");
|
|
7
|
+
function resolveDbAndPrismaArgs(data) {
|
|
8
|
+
const { baseConfig, instance, options, wherePkValue, withoutSelect, withoutWhere, specificSelect, dataPayload, createPayload, updatePayload, alreadyValidatedOptions, specificWhere, pushWhere, ordenation, pagination, skipDuplicates, forceSeeMode, } = data;
|
|
9
|
+
const validatedOptions = (alreadyValidatedOptions && options)
|
|
10
|
+
? options
|
|
11
|
+
: (0, method_options_validate_1.validateMethodOptions)(options, instance);
|
|
12
|
+
const db = validatedOptions.db ?? instance.prisma;
|
|
13
|
+
const prismaArgs = {};
|
|
14
|
+
if (!withoutWhere) {
|
|
15
|
+
prismaArgs.where = (0, merge_wheres_resolve_1.resolveMergeWheres)({
|
|
16
|
+
respectRequired: !baseConfig.ignoreRequiredWhere,
|
|
17
|
+
see: forceSeeMode ?? validatedOptions.see,
|
|
18
|
+
}, wherePkValue != undefined ? { [instance.pkName]: wherePkValue } : specificWhere, pushWhere, instance.requiredWhere, instance.softRemovekName);
|
|
19
|
+
}
|
|
20
|
+
if (!withoutSelect) {
|
|
21
|
+
prismaArgs.select =
|
|
22
|
+
specificSelect ??
|
|
23
|
+
(0, select_resolve_1.resolveSelect)(instance, validatedOptions.selectModel, baseConfig.defaultSelect);
|
|
24
|
+
}
|
|
25
|
+
if (dataPayload) {
|
|
26
|
+
prismaArgs.data = dataPayload;
|
|
27
|
+
}
|
|
28
|
+
if (createPayload) {
|
|
29
|
+
prismaArgs.create = createPayload;
|
|
30
|
+
}
|
|
31
|
+
if (updatePayload) {
|
|
32
|
+
prismaArgs.update = updatePayload;
|
|
33
|
+
}
|
|
34
|
+
if (ordenation) {
|
|
35
|
+
prismaArgs.orderBy = ordenation;
|
|
36
|
+
}
|
|
37
|
+
if (pagination) {
|
|
38
|
+
prismaArgs.skip = pagination.skip;
|
|
39
|
+
prismaArgs.take = pagination.take;
|
|
40
|
+
prismaArgs.cursor = pagination.cursor;
|
|
41
|
+
}
|
|
42
|
+
if (skipDuplicates !== undefined) {
|
|
43
|
+
prismaArgs.skipDuplicates = skipDuplicates;
|
|
44
|
+
}
|
|
45
|
+
return { db, prismaArgs };
|
|
46
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveDinamicMethodCustomization = resolveDinamicMethodCustomization;
|
|
4
|
+
function resolveDinamicMethodCustomization(instance, dinamicMethodInfo, originalKey) {
|
|
5
|
+
const dinamicMethodCustomization = {};
|
|
6
|
+
if (!dinamicMethodInfo.ignoreSkipDuplicates) {
|
|
7
|
+
if (dinamicMethodInfo.keyToMapReplaced.endsWith("SkipDuplicates")) {
|
|
8
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethodInfo.keyToMapReplaced.replace("SkipDuplicates", "");
|
|
9
|
+
dinamicMethodCustomization.skipDuplicates = true;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
if (!dinamicMethodInfo.ignoreOrderByAndPagination) {
|
|
13
|
+
dinamicMethodCustomization.injectOrdenation = instance.methods?.[originalKey]?.injectOrdenation;
|
|
14
|
+
dinamicMethodCustomization.injectPagination = instance.methods?.[originalKey]?.injectPagination;
|
|
15
|
+
if (dinamicMethodInfo.keyToMapReplaced.endsWith("PaginatedAndOrdered")) {
|
|
16
|
+
dinamicMethodCustomization.orderPosition = -2;
|
|
17
|
+
dinamicMethodCustomization.paginationPosition = -3;
|
|
18
|
+
dinamicMethodInfo.otherParams.push("pagination");
|
|
19
|
+
dinamicMethodInfo.otherParams.push("order");
|
|
20
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethodInfo.keyToMapReplaced.replace("PaginatedAndOrdered", "");
|
|
21
|
+
dinamicMethodInfo.argsCount += 2;
|
|
22
|
+
}
|
|
23
|
+
else if (dinamicMethodInfo.keyToMapReplaced.endsWith("OrderedAndPaginated")) {
|
|
24
|
+
dinamicMethodCustomization.orderPosition = -3;
|
|
25
|
+
dinamicMethodCustomization.paginationPosition = -2;
|
|
26
|
+
dinamicMethodInfo.otherParams.push("order");
|
|
27
|
+
dinamicMethodInfo.otherParams.push("pagination");
|
|
28
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethodInfo.keyToMapReplaced.replace("OrderedAndPaginated", "");
|
|
29
|
+
dinamicMethodInfo.argsCount += 2;
|
|
30
|
+
}
|
|
31
|
+
else if (dinamicMethodInfo.keyToMapReplaced.endsWith("Paginated")) {
|
|
32
|
+
dinamicMethodCustomization.paginationPosition = -2;
|
|
33
|
+
dinamicMethodInfo.otherParams.push("pagination");
|
|
34
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethodInfo.keyToMapReplaced.replace("Paginated", "");
|
|
35
|
+
dinamicMethodInfo.argsCount++;
|
|
36
|
+
}
|
|
37
|
+
else if (dinamicMethodInfo.keyToMapReplaced.endsWith("Ordered")) {
|
|
38
|
+
dinamicMethodCustomization.orderPosition = -2;
|
|
39
|
+
dinamicMethodInfo.otherParams.push("order");
|
|
40
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethodInfo.keyToMapReplaced.replace("Ordered", "");
|
|
41
|
+
dinamicMethodInfo.argsCount++;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return dinamicMethodCustomization;
|
|
45
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveDinamicMethodInfo = resolveDinamicMethodInfo;
|
|
4
|
+
const vs_repo_error_1 = require("../errors/vs-repo.error");
|
|
5
|
+
function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
|
|
6
|
+
const dinamicMethodInfo = {
|
|
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
|
+
};
|
|
19
|
+
if (dinamicMethod === "aggregate") {
|
|
20
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("aggregate", "");
|
|
21
|
+
dinamicMethodInfo.ignoreSelect = true;
|
|
22
|
+
dinamicMethodInfo.ignoreWhere = true;
|
|
23
|
+
dinamicMethodInfo.method = "aggregate";
|
|
24
|
+
dinamicMethodInfo.prismaArgsIndex = 0;
|
|
25
|
+
dinamicMethodInfo.otherParams.push("prismaArgs");
|
|
26
|
+
dinamicMethodInfo.argsCount++;
|
|
27
|
+
}
|
|
28
|
+
else if (dinamicMethod === "groupBy") {
|
|
29
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("groupBy", "");
|
|
30
|
+
dinamicMethodInfo.ignoreSelect = true;
|
|
31
|
+
dinamicMethodInfo.ignoreWhere = true;
|
|
32
|
+
dinamicMethodInfo.method = "groupBy";
|
|
33
|
+
dinamicMethodInfo.prismaArgsIndex = 0;
|
|
34
|
+
dinamicMethodInfo.otherParams.push("prismaArgs");
|
|
35
|
+
dinamicMethodInfo.argsCount++;
|
|
36
|
+
}
|
|
37
|
+
else if (dinamicMethod.startsWith("findUniqueOrThrowBy")) {
|
|
38
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findUniqueOrThrowBy", "");
|
|
39
|
+
dinamicMethodInfo.method = "findUniqueOrThrow";
|
|
40
|
+
}
|
|
41
|
+
else if (dinamicMethod.startsWith("findUniqueBy")) {
|
|
42
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findUniqueBy", "");
|
|
43
|
+
dinamicMethodInfo.method = "findUnique";
|
|
44
|
+
}
|
|
45
|
+
else if (dinamicMethod.startsWith("findFirstOrThrowBy")) {
|
|
46
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findFirstOrThrowBy", "");
|
|
47
|
+
dinamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
48
|
+
dinamicMethodInfo.method = "findFirstOrThrow";
|
|
49
|
+
}
|
|
50
|
+
else if (dinamicMethod.startsWith("findFirstOrThrow")) {
|
|
51
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findFirstOrThrow", "");
|
|
52
|
+
dinamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
53
|
+
dinamicMethodInfo.ignoreWhere = true;
|
|
54
|
+
dinamicMethodInfo.onlyBaseWheres = true;
|
|
55
|
+
dinamicMethodInfo.method = "findFirstOrThrow";
|
|
56
|
+
}
|
|
57
|
+
else if (dinamicMethod.startsWith("findFirstBy")) {
|
|
58
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findFirstBy", "");
|
|
59
|
+
dinamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
60
|
+
dinamicMethodInfo.method = "findFirst";
|
|
61
|
+
}
|
|
62
|
+
else if (dinamicMethod.startsWith("findFirst")) {
|
|
63
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findFirst", "");
|
|
64
|
+
dinamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
65
|
+
dinamicMethodInfo.ignoreWhere = true;
|
|
66
|
+
dinamicMethodInfo.onlyBaseWheres = true;
|
|
67
|
+
dinamicMethodInfo.method = "findFirst";
|
|
68
|
+
}
|
|
69
|
+
else if (dinamicMethod.startsWith("countBy")) {
|
|
70
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("countBy", "");
|
|
71
|
+
dinamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
72
|
+
dinamicMethodInfo.ignoreSelect = true;
|
|
73
|
+
dinamicMethodInfo.method = "count";
|
|
74
|
+
}
|
|
75
|
+
else if (dinamicMethod.startsWith("countWhere")) {
|
|
76
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("countWhere", "");
|
|
77
|
+
dinamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
78
|
+
dinamicMethodInfo.ignoreWhere = true;
|
|
79
|
+
dinamicMethodInfo.onlyBaseWheres = true;
|
|
80
|
+
dinamicMethodInfo.ignoreSelect = true;
|
|
81
|
+
dinamicMethodInfo.method = "count";
|
|
82
|
+
dinamicMethodInfo.whereIndex = 0;
|
|
83
|
+
dinamicMethodInfo.otherParams.push("where");
|
|
84
|
+
dinamicMethodInfo.argsCount += 1;
|
|
85
|
+
}
|
|
86
|
+
else if (dinamicMethod.startsWith("count")) {
|
|
87
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("count", "");
|
|
88
|
+
dinamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
89
|
+
dinamicMethodInfo.ignoreSelect = true;
|
|
90
|
+
dinamicMethodInfo.ignoreWhere = true;
|
|
91
|
+
dinamicMethodInfo.onlyBaseWheres = true;
|
|
92
|
+
dinamicMethodInfo.method = "count";
|
|
93
|
+
}
|
|
94
|
+
else if (dinamicMethod.startsWith("existsBy")) {
|
|
95
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("existsBy", "");
|
|
96
|
+
dinamicMethodInfo.ignoreSelect = true;
|
|
97
|
+
dinamicMethodInfo.existsMode = true;
|
|
98
|
+
dinamicMethodInfo.method = "findFirst";
|
|
99
|
+
}
|
|
100
|
+
else if (dinamicMethod.startsWith("existsWhere")) {
|
|
101
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("existsWhere", "");
|
|
102
|
+
dinamicMethodInfo.ignoreSelect = true;
|
|
103
|
+
dinamicMethodInfo.existsMode = true;
|
|
104
|
+
dinamicMethodInfo.ignoreWhere = true;
|
|
105
|
+
dinamicMethodInfo.onlyBaseWheres = true;
|
|
106
|
+
dinamicMethodInfo.method = "findFirst";
|
|
107
|
+
dinamicMethodInfo.whereIndex = 0;
|
|
108
|
+
dinamicMethodInfo.otherParams.push("where");
|
|
109
|
+
dinamicMethodInfo.argsCount += 1;
|
|
110
|
+
}
|
|
111
|
+
else if (dinamicMethod.startsWith("findManyBy")) {
|
|
112
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findManyBy", "");
|
|
113
|
+
dinamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
114
|
+
dinamicMethodInfo.method = "findMany";
|
|
115
|
+
}
|
|
116
|
+
else if (dinamicMethod.startsWith("findMany")) {
|
|
117
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findMany", "");
|
|
118
|
+
dinamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
119
|
+
dinamicMethodInfo.ignoreWhere = true;
|
|
120
|
+
dinamicMethodInfo.onlyBaseWheres = true;
|
|
121
|
+
dinamicMethodInfo.method = "findMany";
|
|
122
|
+
}
|
|
123
|
+
else if (dinamicMethod.startsWith("createManyAndReturn")) {
|
|
124
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("createManyAndReturn", "");
|
|
125
|
+
dinamicMethodInfo.ignoreWhere = true;
|
|
126
|
+
dinamicMethodInfo.ignoreSkipDuplicates = false;
|
|
127
|
+
dinamicMethodInfo.method = "createManyAndReturn";
|
|
128
|
+
dinamicMethodInfo.dataIndex = 0;
|
|
129
|
+
dinamicMethodInfo.otherParams.push("data");
|
|
130
|
+
dinamicMethodInfo.argsCount++;
|
|
131
|
+
}
|
|
132
|
+
else if (dinamicMethod.startsWith("createMany")) {
|
|
133
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("createMany", "");
|
|
134
|
+
dinamicMethodInfo.ignoreWhere = true;
|
|
135
|
+
dinamicMethodInfo.ignoreSelect = true;
|
|
136
|
+
dinamicMethodInfo.ignoreSkipDuplicates = false;
|
|
137
|
+
dinamicMethodInfo.method = "createMany";
|
|
138
|
+
dinamicMethodInfo.dataIndex = 0;
|
|
139
|
+
dinamicMethodInfo.otherParams.push("data");
|
|
140
|
+
dinamicMethodInfo.argsCount++;
|
|
141
|
+
}
|
|
142
|
+
else if (dinamicMethod.startsWith("create")) {
|
|
143
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("create", "");
|
|
144
|
+
dinamicMethodInfo.ignoreWhere = true;
|
|
145
|
+
dinamicMethodInfo.method = "create";
|
|
146
|
+
dinamicMethodInfo.dataIndex = 0;
|
|
147
|
+
dinamicMethodInfo.otherParams.push("data");
|
|
148
|
+
dinamicMethodInfo.argsCount++;
|
|
149
|
+
}
|
|
150
|
+
else if (dinamicMethod.startsWith("updateManyAndReturnBy")) {
|
|
151
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("updateManyAndReturnBy", "");
|
|
152
|
+
dinamicMethodInfo.method = "updateManyAndReturn";
|
|
153
|
+
dinamicMethodInfo.dataIndex = -2;
|
|
154
|
+
dinamicMethodInfo.otherParams.push("data");
|
|
155
|
+
dinamicMethodInfo.argsCount++;
|
|
156
|
+
}
|
|
157
|
+
else if (dinamicMethod.startsWith("updateManyAndReturnWhere")) {
|
|
158
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("updateManyAndReturnWhere", "");
|
|
159
|
+
dinamicMethodInfo.ignoreWhere = true;
|
|
160
|
+
dinamicMethodInfo.onlyBaseWheres = true;
|
|
161
|
+
dinamicMethodInfo.method = "updateManyAndReturn";
|
|
162
|
+
dinamicMethodInfo.dataIndex = -2;
|
|
163
|
+
dinamicMethodInfo.whereIndex = 0;
|
|
164
|
+
dinamicMethodInfo.otherParams.push("where", "data");
|
|
165
|
+
dinamicMethodInfo.argsCount += 2;
|
|
166
|
+
}
|
|
167
|
+
else if (dinamicMethod.startsWith("updateManyBy")) {
|
|
168
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("updateManyBy", "");
|
|
169
|
+
dinamicMethodInfo.ignoreSelect = true;
|
|
170
|
+
dinamicMethodInfo.method = "updateMany";
|
|
171
|
+
dinamicMethodInfo.dataIndex = -2;
|
|
172
|
+
dinamicMethodInfo.otherParams.push("data");
|
|
173
|
+
dinamicMethodInfo.argsCount++;
|
|
174
|
+
}
|
|
175
|
+
else if (dinamicMethod.startsWith("updateManyWhere")) {
|
|
176
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("updateManyWhere", "");
|
|
177
|
+
dinamicMethodInfo.ignoreSelect = true;
|
|
178
|
+
dinamicMethodInfo.ignoreWhere = true;
|
|
179
|
+
dinamicMethodInfo.onlyBaseWheres = true;
|
|
180
|
+
dinamicMethodInfo.method = "updateMany";
|
|
181
|
+
dinamicMethodInfo.dataIndex = -2;
|
|
182
|
+
dinamicMethodInfo.whereIndex = 0;
|
|
183
|
+
dinamicMethodInfo.otherParams.push("where", "data");
|
|
184
|
+
dinamicMethodInfo.argsCount += 2;
|
|
185
|
+
}
|
|
186
|
+
else if (dinamicMethod.startsWith("updateBy")) {
|
|
187
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("updateBy", "");
|
|
188
|
+
dinamicMethodInfo.method = "update";
|
|
189
|
+
dinamicMethodInfo.dataIndex = -2;
|
|
190
|
+
dinamicMethodInfo.otherParams.push("data");
|
|
191
|
+
dinamicMethodInfo.argsCount++;
|
|
192
|
+
}
|
|
193
|
+
else if (dinamicMethod.startsWith("upsertBy")) {
|
|
194
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("upsertBy", "");
|
|
195
|
+
dinamicMethodInfo.method = "upsert";
|
|
196
|
+
dinamicMethodInfo.createIndex = -2;
|
|
197
|
+
dinamicMethodInfo.updateIndex = -3;
|
|
198
|
+
dinamicMethodInfo.otherParams.push("update");
|
|
199
|
+
dinamicMethodInfo.otherParams.push("create");
|
|
200
|
+
dinamicMethodInfo.argsCount += 2;
|
|
201
|
+
}
|
|
202
|
+
else if (dinamicMethod.startsWith("deleteManyBy")) {
|
|
203
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("deleteManyBy", "");
|
|
204
|
+
dinamicMethodInfo.ignoreSelect = true;
|
|
205
|
+
dinamicMethodInfo.method = "deleteMany";
|
|
206
|
+
}
|
|
207
|
+
else if (dinamicMethod.startsWith("deleteManyWhere")) {
|
|
208
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("deleteManyWhere", "");
|
|
209
|
+
dinamicMethodInfo.ignoreSelect = true;
|
|
210
|
+
dinamicMethodInfo.ignoreWhere = true;
|
|
211
|
+
dinamicMethodInfo.onlyBaseWheres = true;
|
|
212
|
+
dinamicMethodInfo.method = "deleteMany";
|
|
213
|
+
dinamicMethodInfo.whereIndex = 0;
|
|
214
|
+
dinamicMethodInfo.otherParams.push("where");
|
|
215
|
+
dinamicMethodInfo.argsCount += 1;
|
|
216
|
+
}
|
|
217
|
+
else if (dinamicMethod.startsWith("deleteBy")) {
|
|
218
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("deleteBy", "");
|
|
219
|
+
dinamicMethodInfo.method = "delete";
|
|
220
|
+
}
|
|
221
|
+
else if (dinamicMethod.startsWith("findWhere")) {
|
|
222
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findWhere", "");
|
|
223
|
+
dinamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
224
|
+
dinamicMethodInfo.ignoreWhere = true;
|
|
225
|
+
dinamicMethodInfo.onlyBaseWheres = true;
|
|
226
|
+
dinamicMethodInfo.method = "findFirst";
|
|
227
|
+
dinamicMethodInfo.whereIndex = 0;
|
|
228
|
+
dinamicMethodInfo.otherParams.push("where");
|
|
229
|
+
dinamicMethodInfo.argsCount += 1;
|
|
230
|
+
}
|
|
231
|
+
else if (dinamicMethod.startsWith("findOneWhere")) {
|
|
232
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findOneWhere", "");
|
|
233
|
+
dinamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
234
|
+
dinamicMethodInfo.ignoreWhere = true;
|
|
235
|
+
dinamicMethodInfo.onlyBaseWheres = true;
|
|
236
|
+
dinamicMethodInfo.method = "findFirst";
|
|
237
|
+
dinamicMethodInfo.whereIndex = 0;
|
|
238
|
+
dinamicMethodInfo.otherParams.push("where");
|
|
239
|
+
dinamicMethodInfo.argsCount += 1;
|
|
240
|
+
}
|
|
241
|
+
else if (dinamicMethod.startsWith("findListWhere")) {
|
|
242
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findListWhere", "");
|
|
243
|
+
dinamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
244
|
+
dinamicMethodInfo.ignoreWhere = true;
|
|
245
|
+
dinamicMethodInfo.onlyBaseWheres = true;
|
|
246
|
+
dinamicMethodInfo.method = "findMany";
|
|
247
|
+
dinamicMethodInfo.whereIndex = 0;
|
|
248
|
+
dinamicMethodInfo.otherParams.push("where");
|
|
249
|
+
dinamicMethodInfo.argsCount += 1;
|
|
250
|
+
}
|
|
251
|
+
else if (dinamicMethod.startsWith("findOneBy")) {
|
|
252
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findOneBy", "");
|
|
253
|
+
dinamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
254
|
+
dinamicMethodInfo.method = "findFirst";
|
|
255
|
+
}
|
|
256
|
+
else if (dinamicMethod.startsWith("findBy")) {
|
|
257
|
+
dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findBy", "");
|
|
258
|
+
dinamicMethodInfo.ignoreOrderByAndPagination = false;
|
|
259
|
+
dinamicMethodInfo.method = instance.methods?.[originalKey]?.fbMode === "one" ? "findFirst" : "findMany";
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
throw new vs_repo_error_1.VSRepoBuildError(`[VSRepository] (${instance.tableName}: build) Unknown method: ${dinamicMethod}.`);
|
|
263
|
+
}
|
|
264
|
+
return dinamicMethodInfo;
|
|
265
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveMergeWheres = resolveMergeWheres;
|
|
7
|
+
const deepmerge_1 = __importDefault(require("deepmerge"));
|
|
8
|
+
function resolveMergeWheres(config, provided, pushed, required, softRemovekName) {
|
|
9
|
+
const objectsToMerge = [];
|
|
10
|
+
if (provided)
|
|
11
|
+
objectsToMerge.push(provided);
|
|
12
|
+
if (pushed)
|
|
13
|
+
objectsToMerge.push(pushed);
|
|
14
|
+
if (required && config.respectRequired)
|
|
15
|
+
objectsToMerge.push(required);
|
|
16
|
+
if (softRemovekName && config.see !== "all")
|
|
17
|
+
objectsToMerge.push({ [softRemovekName]: config.see === "active" ? null : { not: null } });
|
|
18
|
+
const whereResolved = deepmerge_1.default.all(objectsToMerge, {
|
|
19
|
+
arrayMerge: (target, source) => source.concat(target),
|
|
20
|
+
});
|
|
21
|
+
return whereResolved;
|
|
22
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolvePrettyWheres = resolvePrettyWheres;
|
|
4
|
+
const ugly_where_resolve_1 = require("./ugly-where.resolve");
|
|
5
|
+
function resolvePrettyWheres(dinamicMethodInfo, dinamicMethodWhereOps) {
|
|
6
|
+
let ANDMode = false;
|
|
7
|
+
let keysSplitedAND = dinamicMethodInfo.keyToMapReplaced.split("AND");
|
|
8
|
+
if (keysSplitedAND.length > 1) {
|
|
9
|
+
ANDMode = true;
|
|
10
|
+
}
|
|
11
|
+
keysSplitedAND.forEach((keySplitedAND, idx) => {
|
|
12
|
+
let orMode = false;
|
|
13
|
+
let keysSplitedOr = idx === 0 ? keySplitedAND.split("Or") : [keySplitedAND];
|
|
14
|
+
if (keysSplitedOr.length > 1) {
|
|
15
|
+
orMode = true;
|
|
16
|
+
}
|
|
17
|
+
for (let i = 0; i < keysSplitedOr.length; i++) {
|
|
18
|
+
if (keysSplitedOr[i] === "")
|
|
19
|
+
continue;
|
|
20
|
+
const keysSplitedAnd = keysSplitedOr[i].split("And");
|
|
21
|
+
for (const keySplitedAnd of keysSplitedAnd) {
|
|
22
|
+
if (keySplitedAnd === "")
|
|
23
|
+
continue;
|
|
24
|
+
const uglyWhere = (0, ugly_where_resolve_1.resolveUglyWhere)(keySplitedAnd);
|
|
25
|
+
if (!orMode) {
|
|
26
|
+
if (idx === 1 && ANDMode) {
|
|
27
|
+
uglyWhere.name = `AND.${i}idx.${uglyWhere.name}`;
|
|
28
|
+
}
|
|
29
|
+
dinamicMethodWhereOps.uglyWheres.push(uglyWhere);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
uglyWhere.name = `OR.${i}idx.${uglyWhere.name}`;
|
|
33
|
+
dinamicMethodWhereOps.uglyWheres.push(uglyWhere);
|
|
34
|
+
}
|
|
35
|
+
if (uglyWhere.autoInjectVal === undefined)
|
|
36
|
+
dinamicMethodInfo.argsCount++;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const prettyWheres = dinamicMethodWhereOps.uglyWheres.map(arg => {
|
|
41
|
+
let context = [];
|
|
42
|
+
let otherProps = undefined;
|
|
43
|
+
let argName = arg.name;
|
|
44
|
+
const agrNameSplitedOr = argName.split("OR.");
|
|
45
|
+
if (agrNameSplitedOr.length > 1) {
|
|
46
|
+
const agrNameSplitedOrIdx = agrNameSplitedOr[1].split("idx.");
|
|
47
|
+
context.push("OR");
|
|
48
|
+
context.push(Number(agrNameSplitedOrIdx[0]));
|
|
49
|
+
argName = agrNameSplitedOrIdx[1];
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const agrNameSplitedAND = argName.split("AND.");
|
|
53
|
+
if (agrNameSplitedAND.length > 1) {
|
|
54
|
+
const agrNameSplitedANDIdx = agrNameSplitedAND[1].split("idx.");
|
|
55
|
+
context.push("AND");
|
|
56
|
+
context.push(Number(agrNameSplitedANDIdx[0]));
|
|
57
|
+
argName = agrNameSplitedANDIdx[1];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
context.push(argName);
|
|
61
|
+
if (arg.pushProperty !== "$$$") {
|
|
62
|
+
const pushProperty = arg.pushProperty;
|
|
63
|
+
const pushPropertySplitedDot = pushProperty.split(".");
|
|
64
|
+
pushPropertySplitedDot.forEach(prop => context.push(prop));
|
|
65
|
+
}
|
|
66
|
+
if (arg.properties !== undefined) {
|
|
67
|
+
const propertiesKeys = Object.keys(arg.properties);
|
|
68
|
+
otherProps = {};
|
|
69
|
+
for (let i = 0; i < propertiesKeys.length; i++) {
|
|
70
|
+
const key = propertiesKeys[i];
|
|
71
|
+
otherProps[key] = arg.properties[key];
|
|
72
|
+
}
|
|
73
|
+
if (arg.pushProperty === "$$$") {
|
|
74
|
+
context.push("equals");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
dinamicMethodInfo.whereParams.push(argName);
|
|
78
|
+
return {
|
|
79
|
+
context,
|
|
80
|
+
otherProps,
|
|
81
|
+
argName,
|
|
82
|
+
autoVal: arg.autoInjectVal,
|
|
83
|
+
betweenMode: arg.betweenMode,
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
dinamicMethodWhereOps.prettyWheres = prettyWheres;
|
|
87
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveSelect = resolveSelect;
|
|
4
|
+
function resolveSelect(instance, provided, pushed) {
|
|
5
|
+
const selectModelKey = provided ?? pushed ?? instance.defaultSelectModel;
|
|
6
|
+
return selectModelKey ? instance.selectModels?.[selectModelKey] : undefined;
|
|
7
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveSpecificWhere = resolveSpecificWhere;
|
|
4
|
+
function resolveSpecificWhere(args, prettyWheres) {
|
|
5
|
+
const specificWhere = {};
|
|
6
|
+
let OR;
|
|
7
|
+
let AND;
|
|
8
|
+
let adjust = 0;
|
|
9
|
+
for (let j = 0; j < prettyWheres.length; j++) {
|
|
10
|
+
let path = {};
|
|
11
|
+
let current = path;
|
|
12
|
+
let ormode = false;
|
|
13
|
+
let andmode = false;
|
|
14
|
+
let modeIdx;
|
|
15
|
+
const currentWhereRslvd = prettyWheres[j];
|
|
16
|
+
const context = currentWhereRslvd.context;
|
|
17
|
+
const contextLength = context.length;
|
|
18
|
+
const contextLengthM1 = contextLength - 1;
|
|
19
|
+
for (let i = 0; i < contextLength; i++) {
|
|
20
|
+
if (i < contextLengthM1) {
|
|
21
|
+
if (context[i] === "OR") {
|
|
22
|
+
ormode = true;
|
|
23
|
+
}
|
|
24
|
+
else if (context[i] === "AND") {
|
|
25
|
+
andmode = true;
|
|
26
|
+
}
|
|
27
|
+
else if (typeof context[i] === "number") {
|
|
28
|
+
modeIdx = context[i];
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
if (!current[context[i]])
|
|
32
|
+
current[context[i]] = {};
|
|
33
|
+
current = current[context[i]];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
if (currentWhereRslvd.autoVal !== undefined) {
|
|
38
|
+
current[context[i]] = currentWhereRslvd.autoVal;
|
|
39
|
+
adjust++;
|
|
40
|
+
}
|
|
41
|
+
else if (currentWhereRslvd.betweenMode && args[j - adjust] !== undefined) {
|
|
42
|
+
current[context[i]] = {};
|
|
43
|
+
current[context[i]]["gte"] = args[j - adjust][0];
|
|
44
|
+
current[context[i]]["lte"] = args[j - adjust][1];
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
current[context[i]] = args[j - adjust];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (currentWhereRslvd.otherProps !== undefined) {
|
|
52
|
+
Object.assign(path[currentWhereRslvd.argName], currentWhereRslvd.otherProps);
|
|
53
|
+
}
|
|
54
|
+
if (ormode) {
|
|
55
|
+
if (!OR)
|
|
56
|
+
OR = [];
|
|
57
|
+
if (!OR[modeIdx])
|
|
58
|
+
OR[modeIdx] = {};
|
|
59
|
+
Object.assign(OR[modeIdx], path);
|
|
60
|
+
}
|
|
61
|
+
else if (andmode) {
|
|
62
|
+
if (!AND)
|
|
63
|
+
AND = [];
|
|
64
|
+
if (!AND[modeIdx])
|
|
65
|
+
AND[modeIdx] = {};
|
|
66
|
+
Object.assign(AND[modeIdx], path);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
Object.assign(specificWhere, path);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (OR)
|
|
73
|
+
specificWhere.OR = OR.filter(x => x !== undefined);
|
|
74
|
+
if (AND)
|
|
75
|
+
specificWhere.AND = AND.filter(x => x !== undefined);
|
|
76
|
+
return specificWhere;
|
|
77
|
+
}
|