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,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveUglyWhere = resolveUglyWhere;
|
|
4
|
+
const uncapitalize_util_1 = require("../utils/uncapitalize.util");
|
|
5
|
+
function resolveUglyWhere(keySplitedAnd) {
|
|
6
|
+
const uglyWhere = { name: "", pushProperty: "$$$" };
|
|
7
|
+
let nullMode = undefined;
|
|
8
|
+
if (keySplitedAnd.includes("IsNull")) {
|
|
9
|
+
uglyWhere.pushProperty = "$$$";
|
|
10
|
+
uglyWhere.autoInjectVal = null;
|
|
11
|
+
nullMode = "is";
|
|
12
|
+
keySplitedAnd = keySplitedAnd.replace("IsNull", "");
|
|
13
|
+
}
|
|
14
|
+
else if (keySplitedAnd.includes("IsNotNull")) {
|
|
15
|
+
uglyWhere.pushProperty = "not";
|
|
16
|
+
uglyWhere.autoInjectVal = null;
|
|
17
|
+
nullMode = "not";
|
|
18
|
+
keySplitedAnd = keySplitedAnd.replace("IsNotNull", "");
|
|
19
|
+
}
|
|
20
|
+
else if (keySplitedAnd.includes("IsTrue")) {
|
|
21
|
+
uglyWhere.pushProperty = "$$$";
|
|
22
|
+
uglyWhere.autoInjectVal = true;
|
|
23
|
+
keySplitedAnd = keySplitedAnd.replace("IsTrue", "");
|
|
24
|
+
}
|
|
25
|
+
else if (keySplitedAnd.includes("IsFalse")) {
|
|
26
|
+
uglyWhere.pushProperty = "$$$";
|
|
27
|
+
uglyWhere.autoInjectVal = false;
|
|
28
|
+
keySplitedAnd = keySplitedAnd.replace("IsFalse", "");
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
if (keySplitedAnd.includes("Insensitive")) {
|
|
32
|
+
uglyWhere.properties = {};
|
|
33
|
+
uglyWhere.properties.mode = "insensitive";
|
|
34
|
+
keySplitedAnd = keySplitedAnd.replace("Insensitive", "");
|
|
35
|
+
}
|
|
36
|
+
if (keySplitedAnd.includes("Optional")) {
|
|
37
|
+
keySplitedAnd = keySplitedAnd.replace("Optional", "");
|
|
38
|
+
}
|
|
39
|
+
if (keySplitedAnd.includes("NotBetween")) {
|
|
40
|
+
uglyWhere.pushProperty = "not";
|
|
41
|
+
uglyWhere.betweenMode = true;
|
|
42
|
+
keySplitedAnd = keySplitedAnd.replace("NotBetween", "");
|
|
43
|
+
}
|
|
44
|
+
else if (keySplitedAnd.includes("Between")) {
|
|
45
|
+
uglyWhere.pushProperty = "$$$";
|
|
46
|
+
uglyWhere.betweenMode = true;
|
|
47
|
+
keySplitedAnd = keySplitedAnd.replace("Between", "");
|
|
48
|
+
}
|
|
49
|
+
else if (keySplitedAnd.includes("NotStartsWith")) {
|
|
50
|
+
uglyWhere.pushProperty = "not.startsWith";
|
|
51
|
+
keySplitedAnd = keySplitedAnd.replace("NotStartsWith", "");
|
|
52
|
+
}
|
|
53
|
+
else if (keySplitedAnd.includes("StartsWith")) {
|
|
54
|
+
uglyWhere.pushProperty = "startsWith";
|
|
55
|
+
keySplitedAnd = keySplitedAnd.replace("StartsWith", "");
|
|
56
|
+
}
|
|
57
|
+
else if (keySplitedAnd.includes("NotEndsWith")) {
|
|
58
|
+
uglyWhere.pushProperty = "not.endsWith";
|
|
59
|
+
keySplitedAnd = keySplitedAnd.replace("NotEndsWith", "");
|
|
60
|
+
}
|
|
61
|
+
else if (keySplitedAnd.includes("EndsWith")) {
|
|
62
|
+
uglyWhere.pushProperty = "endsWith";
|
|
63
|
+
keySplitedAnd = keySplitedAnd.replace("EndsWith", "");
|
|
64
|
+
}
|
|
65
|
+
else if (keySplitedAnd.includes("NotContains")) {
|
|
66
|
+
uglyWhere.pushProperty = "not.contains";
|
|
67
|
+
keySplitedAnd = keySplitedAnd.replace("NotContains", "");
|
|
68
|
+
}
|
|
69
|
+
else if (keySplitedAnd.includes("Contains")) {
|
|
70
|
+
uglyWhere.pushProperty = "contains";
|
|
71
|
+
keySplitedAnd = keySplitedAnd.replace("Contains", "");
|
|
72
|
+
}
|
|
73
|
+
else if (keySplitedAnd.includes("LessThanEqual")) {
|
|
74
|
+
uglyWhere.pushProperty = "lte";
|
|
75
|
+
keySplitedAnd = keySplitedAnd.replace("LessThanEqual", "");
|
|
76
|
+
}
|
|
77
|
+
else if (keySplitedAnd.includes("LessThan")) {
|
|
78
|
+
uglyWhere.pushProperty = "lt";
|
|
79
|
+
keySplitedAnd = keySplitedAnd.replace("LessThan", "");
|
|
80
|
+
}
|
|
81
|
+
else if (keySplitedAnd.includes("GreaterThanEqual")) {
|
|
82
|
+
uglyWhere.pushProperty = "gte";
|
|
83
|
+
keySplitedAnd = keySplitedAnd.replace("GreaterThanEqual", "");
|
|
84
|
+
}
|
|
85
|
+
else if (keySplitedAnd.includes("GreaterThan")) {
|
|
86
|
+
uglyWhere.pushProperty = "gt";
|
|
87
|
+
keySplitedAnd = keySplitedAnd.replace("GreaterThan", "");
|
|
88
|
+
}
|
|
89
|
+
else if (keySplitedAnd.includes("NotIn")) {
|
|
90
|
+
uglyWhere.pushProperty = "notIn";
|
|
91
|
+
keySplitedAnd = keySplitedAnd.replace("NotIn", "");
|
|
92
|
+
}
|
|
93
|
+
else if (keySplitedAnd.includes("In")) {
|
|
94
|
+
uglyWhere.pushProperty = "in";
|
|
95
|
+
keySplitedAnd = keySplitedAnd.replace("In", "");
|
|
96
|
+
}
|
|
97
|
+
else if (keySplitedAnd.includes("Not")) {
|
|
98
|
+
uglyWhere.pushProperty = "not";
|
|
99
|
+
keySplitedAnd = keySplitedAnd.replace("Not", "");
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
uglyWhere.pushProperty = "$$$";
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (keySplitedAnd.includes("Without")) {
|
|
106
|
+
const keySplitedConector = keySplitedAnd.split("Without");
|
|
107
|
+
const specificField = keySplitedConector[1];
|
|
108
|
+
if (!specificField) {
|
|
109
|
+
if (nullMode) {
|
|
110
|
+
uglyWhere.pushProperty = nullMode === "not" ? "is" : "isNot";
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
uglyWhere.pushProperty = "isNot";
|
|
114
|
+
uglyWhere.autoInjectVal = {};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
uglyWhere.pushProperty = `isNot.${(0, uncapitalize_util_1.uncapitalize)(specificField)}${uglyWhere.pushProperty === "$$$" ? "" : `.${uglyWhere.pushProperty}`}`;
|
|
119
|
+
}
|
|
120
|
+
keySplitedAnd = keySplitedConector[0];
|
|
121
|
+
}
|
|
122
|
+
else if (keySplitedAnd.includes("With")) {
|
|
123
|
+
const keySplitedConector = keySplitedAnd.split("With");
|
|
124
|
+
const specificField = keySplitedConector[1];
|
|
125
|
+
if (!specificField) {
|
|
126
|
+
if (nullMode) {
|
|
127
|
+
uglyWhere.pushProperty = nullMode === "not" ? "isNot" : "is";
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
uglyWhere.pushProperty = "is";
|
|
131
|
+
uglyWhere.autoInjectVal = {};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
uglyWhere.pushProperty = `is.${(0, uncapitalize_util_1.uncapitalize)(specificField)}${uglyWhere.pushProperty === "$$$" ? "" : `.${uglyWhere.pushProperty}`}`;
|
|
136
|
+
}
|
|
137
|
+
keySplitedAnd = keySplitedConector[0];
|
|
138
|
+
}
|
|
139
|
+
else if (keySplitedAnd.includes("Some")) {
|
|
140
|
+
const keySplitedConector = keySplitedAnd.split("Some");
|
|
141
|
+
const specificField = keySplitedConector[1];
|
|
142
|
+
if (!specificField) {
|
|
143
|
+
uglyWhere.pushProperty = "some";
|
|
144
|
+
uglyWhere.autoInjectVal = {};
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
uglyWhere.pushProperty = `some.${(0, uncapitalize_util_1.uncapitalize)(specificField)}${uglyWhere.pushProperty === "$$$" ? "" : `.${uglyWhere.pushProperty}`}`;
|
|
148
|
+
}
|
|
149
|
+
keySplitedAnd = keySplitedConector[0];
|
|
150
|
+
}
|
|
151
|
+
else if (keySplitedAnd.includes("Every")) {
|
|
152
|
+
const keySplitedConector = keySplitedAnd.split("Every");
|
|
153
|
+
const specificField = keySplitedConector[1];
|
|
154
|
+
if (!specificField) {
|
|
155
|
+
uglyWhere.pushProperty = "every";
|
|
156
|
+
uglyWhere.autoInjectVal = {};
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
uglyWhere.pushProperty = `every.${(0, uncapitalize_util_1.uncapitalize)(specificField)}${uglyWhere.pushProperty === "$$$" ? "" : `.${uglyWhere.pushProperty}`}`;
|
|
160
|
+
}
|
|
161
|
+
keySplitedAnd = keySplitedConector[0];
|
|
162
|
+
}
|
|
163
|
+
else if (keySplitedAnd.includes("None")) {
|
|
164
|
+
const keySplitedConector = keySplitedAnd.split("None");
|
|
165
|
+
const specificField = keySplitedConector[1];
|
|
166
|
+
if (!specificField) {
|
|
167
|
+
uglyWhere.pushProperty = "none";
|
|
168
|
+
uglyWhere.autoInjectVal = {};
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
uglyWhere.pushProperty = `none.${(0, uncapitalize_util_1.uncapitalize)(specificField)}${uglyWhere.pushProperty === "$$$" ? "" : `.${uglyWhere.pushProperty}`}`;
|
|
172
|
+
}
|
|
173
|
+
keySplitedAnd = keySplitedConector[0];
|
|
174
|
+
}
|
|
175
|
+
keySplitedAnd = (0, uncapitalize_util_1.uncapitalize)(keySplitedAnd);
|
|
176
|
+
uglyWhere.name = keySplitedAnd;
|
|
177
|
+
return uglyWhere;
|
|
178
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logger = logger;
|
|
4
|
+
exports.performanceLoggerStart = performanceLoggerStart;
|
|
5
|
+
exports.performanceLoggerEnd = performanceLoggerEnd;
|
|
6
|
+
function logger(message, moment, tableName, obj) {
|
|
7
|
+
console.log(`[VSRepository] (${tableName ?? "unknown"}: ${moment}) ${message}`);
|
|
8
|
+
if (obj)
|
|
9
|
+
console.log(JSON.stringify(obj, null, 2));
|
|
10
|
+
}
|
|
11
|
+
function performanceLoggerStart(tableName, operation, prismaArgs) {
|
|
12
|
+
logger(`Executing ${operation}.`, "runtime", tableName);
|
|
13
|
+
if (prismaArgs)
|
|
14
|
+
logger(`Built arguments to ${operation}:`, "runtime", tableName, prismaArgs);
|
|
15
|
+
return performance.now();
|
|
16
|
+
}
|
|
17
|
+
function performanceLoggerEnd(tableName, operation, start) {
|
|
18
|
+
const end = performance.now();
|
|
19
|
+
const duration = (end - start).toFixed(2);
|
|
20
|
+
logger(`Executed ${operation} (took: ${duration}ms).`, "runtime", tableName);
|
|
21
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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.booleanSchema = exports.objectSchema = exports.stringSchema = void 0;
|
|
7
|
+
const zod_1 = __importDefault(require("zod"));
|
|
8
|
+
exports.stringSchema = zod_1.default.string().trim().nonempty();
|
|
9
|
+
exports.objectSchema = zod_1.default.looseObject({});
|
|
10
|
+
exports.booleanSchema = zod_1.default.boolean();
|
|
@@ -0,0 +1,84 @@
|
|
|
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.validateBuildConfig = validateBuildConfig;
|
|
7
|
+
const zod_1 = __importDefault(require("zod"));
|
|
8
|
+
const schemas_util_1 = require("../utils/schemas.util");
|
|
9
|
+
const vs_repo_error_1 = require("../errors/vs-repo.error");
|
|
10
|
+
const defaultBaseMethodConfig = {
|
|
11
|
+
active: true,
|
|
12
|
+
ignoreRequiredWhere: false,
|
|
13
|
+
};
|
|
14
|
+
const defaultBaseMethods = {
|
|
15
|
+
get: defaultBaseMethodConfig,
|
|
16
|
+
getOrThrow: defaultBaseMethodConfig,
|
|
17
|
+
getAll: defaultBaseMethodConfig,
|
|
18
|
+
remove: defaultBaseMethodConfig,
|
|
19
|
+
save: defaultBaseMethodConfig,
|
|
20
|
+
patch: defaultBaseMethodConfig,
|
|
21
|
+
removeList: defaultBaseMethodConfig,
|
|
22
|
+
total: defaultBaseMethodConfig,
|
|
23
|
+
has: defaultBaseMethodConfig,
|
|
24
|
+
merge: defaultBaseMethodConfig,
|
|
25
|
+
getList: defaultBaseMethodConfig,
|
|
26
|
+
saveList: defaultBaseMethodConfig,
|
|
27
|
+
softRemove: defaultBaseMethodConfig,
|
|
28
|
+
restore: defaultBaseMethodConfig,
|
|
29
|
+
softRemoveList: defaultBaseMethodConfig,
|
|
30
|
+
restoreList: defaultBaseMethodConfig,
|
|
31
|
+
patchList: defaultBaseMethodConfig,
|
|
32
|
+
};
|
|
33
|
+
function validateBuildConfig(config, buildInstance) {
|
|
34
|
+
const defaultSelectSchema = buildInstance.selectModels
|
|
35
|
+
? zod_1.default.enum(Object.keys(buildInstance.selectModels)).optional()
|
|
36
|
+
: zod_1.default.never("can only be passed if you have configured 'selectModels'.").optional();
|
|
37
|
+
const activeSchema = schemas_util_1.booleanSchema.default(true);
|
|
38
|
+
const ignoreRequiredWhereSchema = schemas_util_1.booleanSchema.default(false);
|
|
39
|
+
const baseMethodSchema = zod_1.default
|
|
40
|
+
.strictObject({
|
|
41
|
+
active: activeSchema,
|
|
42
|
+
ignoreRequiredWhere: ignoreRequiredWhereSchema,
|
|
43
|
+
})
|
|
44
|
+
.default(defaultBaseMethodConfig);
|
|
45
|
+
const baseMethodWithSelectSchema = zod_1.default
|
|
46
|
+
.strictObject({
|
|
47
|
+
active: activeSchema,
|
|
48
|
+
defaultSelect: defaultSelectSchema,
|
|
49
|
+
ignoreRequiredWhere: ignoreRequiredWhereSchema,
|
|
50
|
+
})
|
|
51
|
+
.default(defaultBaseMethodConfig);
|
|
52
|
+
const buildConfigSchema = zod_1.default.strictObject({
|
|
53
|
+
freeze: schemas_util_1.booleanSchema.default(true),
|
|
54
|
+
showWorking: schemas_util_1.booleanSchema.default(false),
|
|
55
|
+
baseMethods: zod_1.default
|
|
56
|
+
.strictObject({
|
|
57
|
+
get: baseMethodWithSelectSchema,
|
|
58
|
+
getOrThrow: baseMethodWithSelectSchema,
|
|
59
|
+
getAll: baseMethodWithSelectSchema,
|
|
60
|
+
remove: baseMethodWithSelectSchema,
|
|
61
|
+
save: baseMethodWithSelectSchema,
|
|
62
|
+
patch: baseMethodWithSelectSchema,
|
|
63
|
+
removeList: baseMethodSchema,
|
|
64
|
+
total: baseMethodSchema,
|
|
65
|
+
has: baseMethodSchema,
|
|
66
|
+
merge: baseMethodWithSelectSchema,
|
|
67
|
+
getList: baseMethodWithSelectSchema,
|
|
68
|
+
saveList: baseMethodWithSelectSchema,
|
|
69
|
+
softRemove: baseMethodWithSelectSchema,
|
|
70
|
+
restore: baseMethodWithSelectSchema,
|
|
71
|
+
softRemoveList: baseMethodWithSelectSchema,
|
|
72
|
+
restoreList: baseMethodWithSelectSchema,
|
|
73
|
+
patchList: baseMethodWithSelectSchema,
|
|
74
|
+
})
|
|
75
|
+
.default(defaultBaseMethods),
|
|
76
|
+
});
|
|
77
|
+
const buildConfigParsed = buildConfigSchema.safeParse(config);
|
|
78
|
+
if (!buildConfigParsed.success) {
|
|
79
|
+
const firstIssue = buildConfigParsed.error.issues[0];
|
|
80
|
+
const path = firstIssue?.path.length ? firstIssue.path.join(".") : "config";
|
|
81
|
+
throw new vs_repo_error_1.VSRepoBuildError(`[VSRepository] (${buildInstance.tableName}: build) ${path}: ${firstIssue?.message}`);
|
|
82
|
+
}
|
|
83
|
+
return buildConfigParsed.data;
|
|
84
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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.validateConstructorConfig = validateConstructorConfig;
|
|
7
|
+
const zod_1 = __importDefault(require("zod"));
|
|
8
|
+
const schemas_util_1 = require("../utils/schemas.util");
|
|
9
|
+
const vs_repo_error_1 = require("../errors/vs-repo.error");
|
|
10
|
+
function validateConstructorConfig(config) {
|
|
11
|
+
const configSchema = zod_1.default
|
|
12
|
+
.strictObject({
|
|
13
|
+
tableName: schemas_util_1.stringSchema,
|
|
14
|
+
pkName: schemas_util_1.stringSchema,
|
|
15
|
+
softRemovekName: schemas_util_1.stringSchema.optional(),
|
|
16
|
+
selectModels: zod_1.default.record(schemas_util_1.stringSchema, schemas_util_1.objectSchema).optional(),
|
|
17
|
+
defaultSelectModel: schemas_util_1.stringSchema.optional(),
|
|
18
|
+
requiredWhere: schemas_util_1.objectSchema.optional(),
|
|
19
|
+
relations: zod_1.default
|
|
20
|
+
.record(schemas_util_1.stringSchema, zod_1.default.strictObject({
|
|
21
|
+
mode: zod_1.default.enum(["otm", "mtm", "mto", "oto"]),
|
|
22
|
+
restriction: zod_1.default.enum(["set", "add"]),
|
|
23
|
+
pk: schemas_util_1.stringSchema,
|
|
24
|
+
nullAble: schemas_util_1.booleanSchema.optional(),
|
|
25
|
+
nullable: schemas_util_1.booleanSchema.optional(),
|
|
26
|
+
}))
|
|
27
|
+
.optional(),
|
|
28
|
+
methods: zod_1.default
|
|
29
|
+
.record(schemas_util_1.stringSchema, zod_1.default.strictObject({
|
|
30
|
+
map: schemas_util_1.booleanSchema,
|
|
31
|
+
selectModel: schemas_util_1.stringSchema.or(zod_1.default.literal(false)).optional(),
|
|
32
|
+
whereType: zod_1.default.enum(["overwrite", "extending"]).optional(),
|
|
33
|
+
proxyTo: schemas_util_1.stringSchema.optional(),
|
|
34
|
+
pushWhere: schemas_util_1.objectSchema.optional(),
|
|
35
|
+
fbMode: zod_1.default.enum(["one", "list"]).optional(),
|
|
36
|
+
injectOrdenation: schemas_util_1.objectSchema.or(zod_1.default.array(schemas_util_1.objectSchema)).optional(),
|
|
37
|
+
injectPagination: schemas_util_1.objectSchema.optional(),
|
|
38
|
+
}))
|
|
39
|
+
.optional(),
|
|
40
|
+
})
|
|
41
|
+
.superRefine((config, ctx) => {
|
|
42
|
+
if (config.defaultSelectModel && !config.selectModels?.[config.defaultSelectModel]) {
|
|
43
|
+
ctx.addIssue({
|
|
44
|
+
code: "custom",
|
|
45
|
+
path: ["defaultSelectModel"],
|
|
46
|
+
message: "must be a valid key of 'selectModels'",
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (config.methods) {
|
|
50
|
+
for (const [key, method] of Object.entries(config.methods)) {
|
|
51
|
+
if (method.selectModel && !config.selectModels?.[method.selectModel]) {
|
|
52
|
+
ctx.addIssue({
|
|
53
|
+
code: "custom",
|
|
54
|
+
path: ["methods", key, "selectModel"],
|
|
55
|
+
message: "must be a valid key of 'selectModels'",
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
const configParsed = configSchema.safeParse(config);
|
|
62
|
+
if (!configParsed.success) {
|
|
63
|
+
const firstIssue = configParsed.error.issues[0];
|
|
64
|
+
const path = firstIssue?.path.length ? firstIssue.path.join(".") : "config";
|
|
65
|
+
throw new vs_repo_error_1.VSRepoConfigError(`[VSRepository] (unknown: config) ${path}: ${firstIssue?.message}`);
|
|
66
|
+
}
|
|
67
|
+
return configParsed.data;
|
|
68
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateExtension = validateExtension;
|
|
4
|
+
const VSRepository_1 = require("../../VSRepository");
|
|
5
|
+
const is_object_validate_1 = require("./is-object.validate");
|
|
6
|
+
function validateExtension(extensionFunc, repo) {
|
|
7
|
+
if (typeof extensionFunc !== "function") {
|
|
8
|
+
throw new VSRepository_1.VSRepoExtendError(`[VSRepository] (${repo.tableName}: extend) 'extensionFunc' must be a valid function.`);
|
|
9
|
+
}
|
|
10
|
+
const extension = extensionFunc(repo);
|
|
11
|
+
if (!(0, is_object_validate_1.isObject)(extension)) {
|
|
12
|
+
throw new VSRepository_1.VSRepoExtendError(`[VSRepository] (${repo.tableName}: extend) The return of the 'extensionFunc' must be a valid object.`);
|
|
13
|
+
}
|
|
14
|
+
return extension;
|
|
15
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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.validateMethodOptions = validateMethodOptions;
|
|
7
|
+
const zod_1 = __importDefault(require("zod"));
|
|
8
|
+
const schemas_util_1 = require("../utils/schemas.util");
|
|
9
|
+
const vs_repo_error_1 = require("../errors/vs-repo.error");
|
|
10
|
+
function validateMethodOptions(options, instance) {
|
|
11
|
+
const optionsSchema = zod_1.default.strictObject({
|
|
12
|
+
db: schemas_util_1.objectSchema.optional(),
|
|
13
|
+
selectModel: zod_1.default
|
|
14
|
+
.literal(false)
|
|
15
|
+
.or(zod_1.default.enum(Object.keys(instance.selectModels ?? {})))
|
|
16
|
+
.optional(),
|
|
17
|
+
see: zod_1.default.enum(["active", "removed", "all"]).default("active"),
|
|
18
|
+
});
|
|
19
|
+
const optionsParsed = optionsSchema.safeParse(options ?? {});
|
|
20
|
+
if (!optionsParsed.success) {
|
|
21
|
+
const firstIssue = optionsParsed.error.issues[0];
|
|
22
|
+
const path = firstIssue?.path.length ? firstIssue.path.join(".") : "options";
|
|
23
|
+
throw new vs_repo_error_1.VSRepoRuntimeError(`[VSRepository] (${instance.tableName}: runtime) ${path}: ${firstIssue?.message}`);
|
|
24
|
+
}
|
|
25
|
+
return optionsParsed.data;
|
|
26
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateObjWithRelations = validateObjWithRelations;
|
|
4
|
+
const vs_repo_error_1 = require("../errors/vs-repo.error");
|
|
5
|
+
const is_object_validate_1 = require("./is-object.validate");
|
|
6
|
+
function validateObjWithRelations(instance, obj, relationsKeys) {
|
|
7
|
+
const relations = instance.relations;
|
|
8
|
+
if (!relations)
|
|
9
|
+
return;
|
|
10
|
+
for (let i = 0; i < relationsKeys.length; i++) {
|
|
11
|
+
const key = relationsKeys[i];
|
|
12
|
+
if (obj[key] === undefined)
|
|
13
|
+
continue;
|
|
14
|
+
const relation = relations[key];
|
|
15
|
+
if (relation.mode === "mtm" || relation.mode === "otm") {
|
|
16
|
+
if (obj[key] === null) {
|
|
17
|
+
throw new vs_repo_error_1.VSRepoRuntimeError(`[VSRepository] (${instance.tableName}: runtime) '${key}' cannot be 'null' when relation mode is "mtm" or "otm", use an empty array instead.`);
|
|
18
|
+
}
|
|
19
|
+
else if (!Array.isArray(obj[key]) || obj[key].some(val => !(0, is_object_validate_1.isObject)(val))) {
|
|
20
|
+
throw new vs_repo_error_1.VSRepoRuntimeError(`[VSRepository] (${instance.tableName}: runtime) '${key}' must be a valid array of objects when relation mode is "mtm" or "otm".`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
if (obj[key] === null) {
|
|
25
|
+
if (relation.mode === "oto" && relation.restriction !== "set") {
|
|
26
|
+
throw new vs_repo_error_1.VSRepoRuntimeError(`[VSRepository] (${instance.tableName}: runtime) '${key}' can be 'null' only if the relation restriction is "set" and mode is "oto".`);
|
|
27
|
+
}
|
|
28
|
+
else if (relation.mode === "mto" && !relation.nullable && !relation.nullAble) {
|
|
29
|
+
throw new vs_repo_error_1.VSRepoRuntimeError(`[VSRepository] (${instance.tableName}: runtime) '${key}' can be 'null' only if the relation 'nullable' is 'true' and mode is "mto".`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else if (!(0, is_object_validate_1.isObject)(obj[key])) {
|
|
33
|
+
throw new vs_repo_error_1.VSRepoRuntimeError(`[VSRepository] (${instance.tableName}: runtime) '${key}' must be a valid object when relation mode is "oto" or "mto".`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validatePrismaClient = validatePrismaClient;
|
|
4
|
+
const VSRepository_1 = require("../../VSRepository");
|
|
5
|
+
const is_object_validate_1 = require("./is-object.validate");
|
|
6
|
+
function validatePrismaClient(prisma, repo) {
|
|
7
|
+
if (!(0, is_object_validate_1.isObject)(prisma) || prisma["$transaction"] === undefined) {
|
|
8
|
+
throw new VSRepository_1.VSRepoBuildError(`[VSRepository] (${repo.tableName}: build) 'prisma' must be a valid Prisma Client.`);
|
|
9
|
+
}
|
|
10
|
+
}
|
package/package.json
CHANGED
|
@@ -1,70 +1,72 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "vsrepo",
|
|
3
|
-
"version": "1.2.
|
|
4
|
-
"description": "Uma biblioteca de repository pattern para Prisma",
|
|
5
|
-
"homepage": "https://github.com/jaobrabo123/VSRepository#readme",
|
|
6
|
-
"repository": {
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/jaobrabo123/VSRepository.git"
|
|
9
|
-
},
|
|
10
|
-
"main": "./
|
|
11
|
-
"types": "./
|
|
12
|
-
"exports": {
|
|
13
|
-
".": {
|
|
14
|
-
"types": "./
|
|
15
|
-
"import": "./
|
|
16
|
-
"require": "./
|
|
17
|
-
},
|
|
18
|
-
"./VSRepository": {
|
|
19
|
-
"types": "./
|
|
20
|
-
"import": "./
|
|
21
|
-
"require": "./
|
|
22
|
-
},
|
|
23
|
-
"./VSRepoError": {
|
|
24
|
-
"types": "./
|
|
25
|
-
"import": "./
|
|
26
|
-
"require": "./
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
"type": "
|
|
30
|
-
"files": [
|
|
31
|
-
"
|
|
32
|
-
"scripts"
|
|
33
|
-
],
|
|
34
|
-
"bin": {
|
|
35
|
-
"vsrepo": "scripts/configure-prisma-import.mjs"
|
|
36
|
-
},
|
|
37
|
-
"engines": {
|
|
38
|
-
"node": ">=18"
|
|
39
|
-
},
|
|
40
|
-
"scripts": {
|
|
41
|
-
"vsrepo": "node ./scripts/configure-prisma-import.mjs"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"@prisma/
|
|
61
|
-
"@
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "vsrepo",
|
|
3
|
+
"version": "1.2.7",
|
|
4
|
+
"description": "Uma biblioteca de repository pattern para Prisma",
|
|
5
|
+
"homepage": "https://github.com/jaobrabo123/VSRepository#readme",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/jaobrabo123/VSRepository.git"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"require": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./VSRepository": {
|
|
19
|
+
"types": "./dist/VSRepository.d.ts",
|
|
20
|
+
"import": "./dist/VSRepository.js",
|
|
21
|
+
"require": "./dist/VSRepository.js"
|
|
22
|
+
},
|
|
23
|
+
"./VSRepoError": {
|
|
24
|
+
"types": "./dist/VSRepoError.d.ts",
|
|
25
|
+
"import": "./dist/VSRepoError.js",
|
|
26
|
+
"require": "./dist/VSRepoError.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"type": "commonjs",
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"scripts"
|
|
33
|
+
],
|
|
34
|
+
"bin": {
|
|
35
|
+
"vsrepo": "scripts/configure-prisma-import.mjs"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=18"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"vsrepo": "node ./scripts/configure-prisma-import.mjs",
|
|
42
|
+
"build": "tsc -p tsconfig.build.json && node ./scripts/copy-types.mjs",
|
|
43
|
+
"prepack": "pnpm build"
|
|
44
|
+
},
|
|
45
|
+
"keywords": [
|
|
46
|
+
"prisma",
|
|
47
|
+
"repository",
|
|
48
|
+
"orm",
|
|
49
|
+
"typescript",
|
|
50
|
+
"vsrepo",
|
|
51
|
+
"vsrepository",
|
|
52
|
+
"jparepository"
|
|
53
|
+
],
|
|
54
|
+
"author": "João Pedro Azevedo Freire Mecenas",
|
|
55
|
+
"license": "MIT",
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"@prisma/client": "^7.8.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@prisma/adapter-pg": "^7.8.0",
|
|
61
|
+
"@prisma/client": "^7.8.0",
|
|
62
|
+
"@types/node": "^25.6.0",
|
|
63
|
+
"dotenv": "^17.4.2",
|
|
64
|
+
"prisma": "^7.8.0",
|
|
65
|
+
"tsx": "^4.22.3",
|
|
66
|
+
"typescript": "^6.0.3"
|
|
67
|
+
},
|
|
68
|
+
"dependencies": {
|
|
69
|
+
"deepmerge": "^4.3.1",
|
|
70
|
+
"zod": "^4.4.3"
|
|
71
|
+
}
|
|
72
|
+
}
|