vsrepo 1.3.1 → 1.3.3

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.
@@ -63,9 +63,9 @@ class VSRepository {
63
63
  }
64
64
  return extended;
65
65
  }
66
- build(prisma, config) {
66
+ build(prisma, config, useInstance) {
67
67
  (0, prisma_client_validate_1.validatePrismaClient)(prisma, this);
68
- const buildInstance = Object.create(this);
68
+ const buildInstance = useInstance ?? Object.create(this);
69
69
  buildInstance.prisma = prisma;
70
70
  if (buildInstance.softRemovekName &&
71
71
  prisma[buildInstance.tableName]["fields"][buildInstance.softRemovekName]["typeName"] !==
@@ -93,19 +93,27 @@ class VSRepository {
93
93
  };
94
94
  if (!dinamicMethodInfo.ignoreWhere) {
95
95
  (0, pretty_wheres_resolve_1.resolvePrettyWheres)(dinamicMethodInfo, dinamicMethodWhereOps);
96
- if (showWorking) {
97
- const argsSimulation = [];
98
- for (let x = 0; x < dinamicMethodInfo.argsCount; x++) {
99
- argsSimulation[x] = "00";
100
- }
101
- (0, logger_util_1.logger)(`Where object resolved to ${methodToMap}:`, "build", buildInstance.tableName, (0, specific_where_resolve_1.resolveSpecificWhere)(argsSimulation, dinamicMethodWhereOps.prettyWheres));
102
- // logger(
103
- // `Where object resolved to ${methodToMap}:`,
104
- // "build",
105
- // buildInstance.tableName,
106
- // dinamicMethodWhereOps.prettyWheres,
107
- // );
108
- }
96
+ // if (showWorking) {
97
+ // const argsSimulation: any[] = [];
98
+ // for (let x = 0; x < dinamicMethodInfo.argsCount; x++) {
99
+ // argsSimulation[x] = "00";
100
+ // }
101
+ // logger(
102
+ // `Where object resolved to ${methodToMap}:`,
103
+ // "build",
104
+ // buildInstance.tableName,
105
+ // resolveSpecificWhere(
106
+ // argsSimulation,
107
+ // dinamicMethodWhereOps.prettyWheres,
108
+ // ),
109
+ // );
110
+ // // logger(
111
+ // // `Where object resolved to ${methodToMap}:`,
112
+ // // "build",
113
+ // // buildInstance.tableName,
114
+ // // dinamicMethodWhereOps.prettyWheres,
115
+ // // );
116
+ // }
109
117
  }
110
118
  let select = undefined;
111
119
  if (dinamicMethodInfo.existsMode) {
@@ -123,7 +131,7 @@ class VSRepository {
123
131
  defaultSelect: methods[originalKey]?.selectModel,
124
132
  ignoreRequiredWhere: dinamicMethodWhereOps.whereType === "overwrite",
125
133
  },
126
- withoutWhere: dinamicMethodInfo.ignoreWhere,
134
+ withoutWhere: dinamicMethodInfo.ignoreWhere && !dinamicMethodInfo.onlyBaseWheres,
127
135
  specificSelect: select,
128
136
  pushWhere: dinamicMethodWhereOps.pushWhere,
129
137
  withoutSelect: dinamicMethodInfo.ignoreSelect,
@@ -144,6 +152,7 @@ class VSRepository {
144
152
  ? args.at(dinamicMethodInfo.updateIndex)
145
153
  : undefined,
146
154
  withOrdenationAndPagination: !dinamicMethodInfo.ignoreOrderByAndPagination,
155
+ distinctKeys: dinamicMethodCustomization.distinctKeys,
147
156
  };
148
157
  if (!dinamicMethodInfo.ignoreWhere) {
149
158
  resolveDbAndPrismaArgsData.specificWhere = (0, specific_where_resolve_1.resolveSpecificWhere)(args, dinamicMethodWhereOps.prettyWheres);
@@ -157,6 +166,11 @@ class VSRepository {
157
166
  const { prismaArgs } = (0, dbAndPrismaArgs_resolve_1.resolveDbAndPrismaArgs)(resolveDbAndPrismaArgsData);
158
167
  return prismaArgs;
159
168
  });
169
+ if (showWorking) {
170
+ const argsSimulation = new Array(dinamicMethodInfo.argsCount).fill("00");
171
+ const prismaArgs = buildInstance.vsrepocache.get(originalKey)(argsSimulation);
172
+ (0, logger_util_1.logger)(`PrismaArgs preview for ${methodToMap}:`, "build", buildInstance.tableName, prismaArgs);
173
+ }
160
174
  buildInstance[originalKey] = async (...args) => {
161
175
  let db = buildInstance.prisma;
162
176
  let methodOptions = undefined;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DINAMIC_METHODS_KEY = void 0;
4
+ exports.DINAMIC_METHODS_KEY = Symbol("dynamic-methods-key");
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DynamicMethod = DynamicMethod;
4
+ const dinamic_methods_key_constant_1 = require("../constants/dinamic-methods-key.constant");
5
+ const dynamic_method_metadata_entity_1 = require("../entities/dynamic-method-metadata.entity");
6
+ const dynamic_method_config_validate_1 = require("../validation/dynamic-method-config.validate");
7
+ function DynamicMethod(config) {
8
+ const validatedConfig = config ? (0, dynamic_method_config_validate_1.validateDynamicMethodConfig)(config) : undefined;
9
+ return (target, propertyKey) => {
10
+ const methods = Reflect.getMetadata(dinamic_methods_key_constant_1.DINAMIC_METHODS_KEY, target) ?? [];
11
+ methods.push(new dynamic_method_metadata_entity_1.DynamicMethodMetadata(propertyKey, validatedConfig?.map ?? true, validatedConfig?.proxyTo, validatedConfig?.whereType, validatedConfig?.pushWhere, validatedConfig?.fbMode, validatedConfig?.injectOrdenation, validatedConfig?.injectPagination));
12
+ Reflect.defineMetadata(dinamic_methods_key_constant_1.DINAMIC_METHODS_KEY, methods, target);
13
+ };
14
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DynamicMethodMetadata = void 0;
4
+ class DynamicMethodMetadata {
5
+ propertyKey;
6
+ map;
7
+ proxyTo;
8
+ whereType;
9
+ pushWhere;
10
+ fbMode;
11
+ injectOrdenation;
12
+ injectPagination;
13
+ constructor(propertyKey, map, proxyTo, whereType, pushWhere, fbMode, injectOrdenation, injectPagination) {
14
+ this.propertyKey = propertyKey;
15
+ this.map = map;
16
+ this.proxyTo = proxyTo;
17
+ this.whereType = whereType;
18
+ this.pushWhere = pushWhere;
19
+ this.fbMode = fbMode;
20
+ this.injectOrdenation = injectOrdenation;
21
+ this.injectPagination = injectPagination;
22
+ }
23
+ }
24
+ exports.DynamicMethodMetadata = DynamicMethodMetadata;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VSRepoRuntimeError = exports.VSRepoExtendError = exports.VSRepoBuildError = exports.VSRepoConfigError = exports.VSRepoError = void 0;
3
+ exports.VSRepoRuntimeError = exports.VSRepoDecoratorError = exports.VSRepoExtendError = exports.VSRepoBuildError = exports.VSRepoConfigError = exports.VSRepoError = void 0;
4
4
  class VSRepoError extends Error {
5
5
  }
6
6
  exports.VSRepoError = VSRepoError;
@@ -16,6 +16,10 @@ class VSRepoExtendError extends VSRepoError {
16
16
  type = "VSREPO_EXTEND";
17
17
  }
18
18
  exports.VSRepoExtendError = VSRepoExtendError;
19
+ class VSRepoDecoratorError extends VSRepoError {
20
+ type = "VSREPO_DECORATOR";
21
+ }
22
+ exports.VSRepoDecoratorError = VSRepoDecoratorError;
19
23
  class VSRepoRuntimeError extends VSRepoError {
20
24
  type = "VSREPO_RUNTIME";
21
25
  code;
@@ -5,7 +5,7 @@ const method_options_validate_1 = require("../validation/method-options.validate
5
5
  const merge_wheres_resolve_1 = require("./merge-wheres.resolve");
6
6
  const select_resolve_1 = require("./select.resolve");
7
7
  function resolveDbAndPrismaArgs(data) {
8
- const { baseConfig, instance, options, wherePkValue, withoutSelect, withoutWhere, specificSelect, dataPayload, createPayload, updatePayload, alreadyValidatedOptions, specificWhere, pushWhere, ordenation, pagination, skipDuplicates, forceSeeMode, withOrdenationAndPagination, } = data;
8
+ const { baseConfig, instance, options, wherePkValue, withoutSelect, withoutWhere, specificSelect, dataPayload, createPayload, updatePayload, alreadyValidatedOptions, specificWhere, pushWhere, ordenation, pagination, skipDuplicates, forceSeeMode, withOrdenationAndPagination, distinctKeys, } = data;
9
9
  const validatedOptions = alreadyValidatedOptions && options
10
10
  ? options
11
11
  : (0, method_options_validate_1.validateMethodOptions)(options, instance);
@@ -24,6 +24,9 @@ function resolveDbAndPrismaArgs(data) {
24
24
  else if (validatedOptions.includeModel) {
25
25
  prismaArgs.include = instance.includeModels?.[validatedOptions.includeModel];
26
26
  }
27
+ else if (validatedOptions.include) {
28
+ prismaArgs.include = validatedOptions.include;
29
+ }
27
30
  else {
28
31
  prismaArgs.select = (0, select_resolve_1.resolveSelect)(instance, validatedOptions.selectModel, baseConfig.defaultSelect);
29
32
  }
@@ -50,5 +53,8 @@ function resolveDbAndPrismaArgs(data) {
50
53
  if (skipDuplicates !== undefined) {
51
54
  prismaArgs.skipDuplicates = skipDuplicates;
52
55
  }
56
+ if (distinctKeys !== undefined) {
57
+ prismaArgs.distinct = distinctKeys;
58
+ }
53
59
  return { db, prismaArgs };
54
60
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveDinamicMethodCustomization = resolveDinamicMethodCustomization;
4
+ const uncapitalize_util_1 = require("../utils/uncapitalize.util");
4
5
  function resolveDinamicMethodCustomization(instance, dinamicMethodInfo, originalKey) {
5
6
  const dinamicMethodCustomization = {};
6
7
  if (!dinamicMethodInfo.ignoreSkipDuplicates) {
@@ -10,8 +11,10 @@ function resolveDinamicMethodCustomization(instance, dinamicMethodInfo, original
10
11
  }
11
12
  }
12
13
  if (!dinamicMethodInfo.ignoreOrderByAndPagination) {
13
- dinamicMethodCustomization.injectOrdenation = instance.methods?.[originalKey]?.injectOrdenation;
14
- dinamicMethodCustomization.injectPagination = instance.methods?.[originalKey]?.injectPagination;
14
+ dinamicMethodCustomization.injectOrdenation =
15
+ instance.methods?.[originalKey]?.injectOrdenation;
16
+ dinamicMethodCustomization.injectPagination =
17
+ instance.methods?.[originalKey]?.injectPagination;
15
18
  if (dinamicMethodInfo.keyToMapReplaced.endsWith("PaginatedAndOrdered")) {
16
19
  dinamicMethodCustomization.orderPosition = -2;
17
20
  dinamicMethodCustomization.paginationPosition = -3;
@@ -41,5 +44,14 @@ function resolveDinamicMethodCustomization(instance, dinamicMethodInfo, original
41
44
  dinamicMethodInfo.argsCount++;
42
45
  }
43
46
  }
47
+ if (!dinamicMethodInfo.ignoreDistinct) {
48
+ const keySplitedDistinct = dinamicMethodInfo.keyToMapReplaced.split("Distinct");
49
+ if (keySplitedDistinct[1]) {
50
+ dinamicMethodCustomization.distinctKeys = keySplitedDistinct[1]
51
+ .split("And")
52
+ .map(uncapitalize_util_1.uncapitalize);
53
+ }
54
+ dinamicMethodInfo.keyToMapReplaced = keySplitedDistinct[0];
55
+ }
44
56
  return dinamicMethodCustomization;
45
57
  }
@@ -15,6 +15,7 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
15
15
  ignoreSkipDuplicates: true,
16
16
  whereParams: [],
17
17
  otherParams: [],
18
+ ignoreDistinct: true,
18
19
  };
19
20
  if (dinamicMethod === "aggregate") {
20
21
  dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("aggregate", "");
@@ -45,6 +46,7 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
45
46
  else if (dinamicMethod.startsWith("findFirstOrThrowBy")) {
46
47
  dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findFirstOrThrowBy", "");
47
48
  dinamicMethodInfo.ignoreOrderByAndPagination = false;
49
+ dinamicMethodInfo.ignoreDistinct = false;
48
50
  dinamicMethodInfo.method = "findFirstOrThrow";
49
51
  }
50
52
  else if (dinamicMethod.startsWith("findFirstOrThrow")) {
@@ -52,11 +54,13 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
52
54
  dinamicMethodInfo.ignoreOrderByAndPagination = false;
53
55
  dinamicMethodInfo.ignoreWhere = true;
54
56
  dinamicMethodInfo.onlyBaseWheres = true;
57
+ dinamicMethodInfo.ignoreDistinct = false;
55
58
  dinamicMethodInfo.method = "findFirstOrThrow";
56
59
  }
57
60
  else if (dinamicMethod.startsWith("findFirstBy")) {
58
61
  dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findFirstBy", "");
59
62
  dinamicMethodInfo.ignoreOrderByAndPagination = false;
63
+ dinamicMethodInfo.ignoreDistinct = false;
60
64
  dinamicMethodInfo.method = "findFirst";
61
65
  }
62
66
  else if (dinamicMethod.startsWith("findFirst")) {
@@ -64,6 +68,7 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
64
68
  dinamicMethodInfo.ignoreOrderByAndPagination = false;
65
69
  dinamicMethodInfo.ignoreWhere = true;
66
70
  dinamicMethodInfo.onlyBaseWheres = true;
71
+ dinamicMethodInfo.ignoreDistinct = false;
67
72
  dinamicMethodInfo.method = "findFirst";
68
73
  }
69
74
  else if (dinamicMethod.startsWith("countBy")) {
@@ -95,6 +100,7 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
95
100
  dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("existsBy", "");
96
101
  dinamicMethodInfo.ignoreSelect = true;
97
102
  dinamicMethodInfo.existsMode = true;
103
+ dinamicMethodInfo.ignoreDistinct = false;
98
104
  dinamicMethodInfo.method = "findFirst";
99
105
  }
100
106
  else if (dinamicMethod.startsWith("existsWhere")) {
@@ -103,6 +109,7 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
103
109
  dinamicMethodInfo.existsMode = true;
104
110
  dinamicMethodInfo.ignoreWhere = true;
105
111
  dinamicMethodInfo.onlyBaseWheres = true;
112
+ dinamicMethodInfo.ignoreDistinct = false;
106
113
  dinamicMethodInfo.method = "findFirst";
107
114
  dinamicMethodInfo.whereIndex = 0;
108
115
  dinamicMethodInfo.otherParams.push("where");
@@ -111,6 +118,7 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
111
118
  else if (dinamicMethod.startsWith("findManyBy")) {
112
119
  dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findManyBy", "");
113
120
  dinamicMethodInfo.ignoreOrderByAndPagination = false;
121
+ dinamicMethodInfo.ignoreDistinct = false;
114
122
  dinamicMethodInfo.method = "findMany";
115
123
  }
116
124
  else if (dinamicMethod.startsWith("findMany")) {
@@ -118,6 +126,7 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
118
126
  dinamicMethodInfo.ignoreOrderByAndPagination = false;
119
127
  dinamicMethodInfo.ignoreWhere = true;
120
128
  dinamicMethodInfo.onlyBaseWheres = true;
129
+ dinamicMethodInfo.ignoreDistinct = false;
121
130
  dinamicMethodInfo.method = "findMany";
122
131
  }
123
132
  else if (dinamicMethod.startsWith("createManyAndReturn")) {
@@ -223,6 +232,7 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
223
232
  dinamicMethodInfo.ignoreOrderByAndPagination = false;
224
233
  dinamicMethodInfo.ignoreWhere = true;
225
234
  dinamicMethodInfo.onlyBaseWheres = true;
235
+ dinamicMethodInfo.ignoreDistinct = false;
226
236
  dinamicMethodInfo.method = "findFirst";
227
237
  dinamicMethodInfo.whereIndex = 0;
228
238
  dinamicMethodInfo.otherParams.push("where");
@@ -233,6 +243,7 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
233
243
  dinamicMethodInfo.ignoreOrderByAndPagination = false;
234
244
  dinamicMethodInfo.ignoreWhere = true;
235
245
  dinamicMethodInfo.onlyBaseWheres = true;
246
+ dinamicMethodInfo.ignoreDistinct = false;
236
247
  dinamicMethodInfo.method = "findFirst";
237
248
  dinamicMethodInfo.whereIndex = 0;
238
249
  dinamicMethodInfo.otherParams.push("where");
@@ -243,6 +254,7 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
243
254
  dinamicMethodInfo.ignoreOrderByAndPagination = false;
244
255
  dinamicMethodInfo.ignoreWhere = true;
245
256
  dinamicMethodInfo.onlyBaseWheres = true;
257
+ dinamicMethodInfo.ignoreDistinct = false;
246
258
  dinamicMethodInfo.method = "findMany";
247
259
  dinamicMethodInfo.whereIndex = 0;
248
260
  dinamicMethodInfo.otherParams.push("where");
@@ -251,11 +263,13 @@ function resolveDinamicMethodInfo(instance, dinamicMethod, originalKey) {
251
263
  else if (dinamicMethod.startsWith("findOneBy")) {
252
264
  dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findOneBy", "");
253
265
  dinamicMethodInfo.ignoreOrderByAndPagination = false;
266
+ dinamicMethodInfo.ignoreDistinct = false;
254
267
  dinamicMethodInfo.method = "findFirst";
255
268
  }
256
269
  else if (dinamicMethod.startsWith("findBy")) {
257
270
  dinamicMethodInfo.keyToMapReplaced = dinamicMethod.replace("findBy", "");
258
271
  dinamicMethodInfo.ignoreOrderByAndPagination = false;
272
+ dinamicMethodInfo.ignoreDistinct = false;
259
273
  dinamicMethodInfo.method = instance.methods?.[originalKey]?.fbMode === "one" ? "findFirst" : "findMany";
260
274
  }
261
275
  else {
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveDynamicMethodsMetadata = resolveDynamicMethodsMetadata;
4
+ const dinamic_methods_key_constant_1 = require("../constants/dinamic-methods-key.constant");
5
+ function resolveDynamicMethodsMetadata(prototype) {
6
+ const methods = Reflect.getMetadata(dinamic_methods_key_constant_1.DINAMIC_METHODS_KEY, prototype);
7
+ const methodsRecord = {};
8
+ if (!methods)
9
+ return methodsRecord;
10
+ for (const method of methods) {
11
+ const { propertyKey, ...rest } = method;
12
+ methodsRecord[propertyKey] = rest;
13
+ }
14
+ return methodsRecord;
15
+ }
@@ -4,7 +4,7 @@ exports.logger = logger;
4
4
  exports.performanceLoggerStart = performanceLoggerStart;
5
5
  exports.performanceLoggerEnd = performanceLoggerEnd;
6
6
  function logger(message, moment, tableName, obj) {
7
- console.log(`[VSRepository] (${tableName ?? "unknown"}: ${moment}) ${message}`);
7
+ console.log(`\n[VSRepository] (${tableName ?? "unknown"}: ${moment}) ${message}`);
8
8
  if (obj)
9
9
  console.log(JSON.stringify(obj, null, 2));
10
10
  }
@@ -3,8 +3,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.booleanSchema = exports.objectSchema = exports.stringSchema = void 0;
6
+ exports.methodSchema = exports.booleanSchema = exports.objectSchema = exports.stringSchema = void 0;
7
7
  const zod_1 = __importDefault(require("zod"));
8
8
  exports.stringSchema = zod_1.default.string().trim().nonempty();
9
9
  exports.objectSchema = zod_1.default.looseObject({});
10
10
  exports.booleanSchema = zod_1.default.boolean();
11
+ exports.methodSchema = zod_1.default.strictObject({
12
+ map: exports.booleanSchema,
13
+ selectModel: exports.stringSchema.or(zod_1.default.literal(false)).optional(),
14
+ whereType: zod_1.default.enum(["overwrite", "extending"]).optional(),
15
+ proxyTo: exports.stringSchema.optional(),
16
+ pushWhere: exports.objectSchema.optional(),
17
+ fbMode: zod_1.default.enum(["one", "list"]).optional(),
18
+ injectOrdenation: exports.objectSchema.or(zod_1.default.array(exports.objectSchema)).optional(),
19
+ injectPagination: exports.objectSchema.optional(),
20
+ });
@@ -27,16 +27,7 @@ function validateConstructorConfig(config) {
27
27
  }))
28
28
  .optional(),
29
29
  methods: zod_1.default
30
- .record(schemas_util_1.stringSchema, zod_1.default.strictObject({
31
- map: schemas_util_1.booleanSchema,
32
- selectModel: schemas_util_1.stringSchema.or(zod_1.default.literal(false)).optional(),
33
- whereType: zod_1.default.enum(["overwrite", "extending"]).optional(),
34
- proxyTo: schemas_util_1.stringSchema.optional(),
35
- pushWhere: schemas_util_1.objectSchema.optional(),
36
- fbMode: zod_1.default.enum(["one", "list"]).optional(),
37
- injectOrdenation: schemas_util_1.objectSchema.or(zod_1.default.array(schemas_util_1.objectSchema)).optional(),
38
- injectPagination: schemas_util_1.objectSchema.optional(),
39
- }))
30
+ .record(schemas_util_1.stringSchema, schemas_util_1.methodSchema)
40
31
  .optional(),
41
32
  defaultOrdenation: schemas_util_1.objectSchema.or(zod_1.default.array(schemas_util_1.objectSchema)).optional(),
42
33
  })
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateDynamicMethodConfig = validateDynamicMethodConfig;
4
+ const vs_repo_error_1 = require("../errors/vs-repo.error");
5
+ const schemas_util_1 = require("../utils/schemas.util");
6
+ const is_object_validate_1 = require("./is-object.validate");
7
+ function validateDynamicMethodConfig(config) {
8
+ if (!(0, is_object_validate_1.isObject)(config)) {
9
+ throw new vs_repo_error_1.VSRepoDecoratorError(`[VSRepository] (unknown: decorator) 'config' must be a valid object`);
10
+ }
11
+ config["map"] = true;
12
+ const configParsed = schemas_util_1.methodSchema.safeParse(config);
13
+ if (!configParsed.success) {
14
+ const firstIssue = configParsed.error.issues[0];
15
+ const path = firstIssue?.path.length ? firstIssue.path.join(".") : "config";
16
+ throw new vs_repo_error_1.VSRepoDecoratorError(`[VSRepository] (unknown: decorator) ${path}: ${firstIssue?.message}`);
17
+ }
18
+ return configParsed.data;
19
+ }
@@ -17,6 +17,7 @@ function validateMethodOptions(options, instance) {
17
17
  .optional(),
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
+ include: schemas_util_1.objectSchema.optional(),
20
21
  })
21
22
  .refine(data => {
22
23
  return !(data.selectModel !== undefined && data.includeModel !== undefined);
package/package.json CHANGED
@@ -1,72 +1,78 @@
1
- {
2
- "name": "vsrepo",
3
- "version": "1.3.1",
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
- }
1
+ {
2
+ "name": "vsrepo",
3
+ "version": "1.3.3",
4
+ "description": "A repository pattern library for 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
+ "./DynamicRepository": {
24
+ "types": "./dist/DynamicRepository.d.ts",
25
+ "import": "./dist/DynamicRepository.js",
26
+ "require": "./dist/DynamicRepository.js"
27
+ },
28
+ "./VSRepoError": {
29
+ "types": "./dist/VSRepoError.d.ts",
30
+ "import": "./dist/VSRepoError.js",
31
+ "require": "./dist/VSRepoError.js"
32
+ }
33
+ },
34
+ "type": "commonjs",
35
+ "files": [
36
+ "dist",
37
+ "scripts"
38
+ ],
39
+ "bin": {
40
+ "vsrepo": "scripts/configure-prisma-import.mjs"
41
+ },
42
+ "engines": {
43
+ "node": ">=18"
44
+ },
45
+ "scripts": {
46
+ "vsrepo": "node ./scripts/configure-prisma-import.mjs",
47
+ "build": "tsc -p tsconfig.build.json && node ./scripts/copy-types.mjs",
48
+ "prepack": "pnpm build"
49
+ },
50
+ "keywords": [
51
+ "prisma",
52
+ "repository",
53
+ "orm",
54
+ "typescript",
55
+ "vsrepo",
56
+ "vsrepository",
57
+ "jparepository"
58
+ ],
59
+ "author": "João Pedro Azevedo Freire Mecenas",
60
+ "license": "MIT",
61
+ "peerDependencies": {
62
+ "@prisma/client": "^7.8.0"
63
+ },
64
+ "devDependencies": {
65
+ "@prisma/adapter-pg": "^7.8.0",
66
+ "@prisma/client": "^7.8.0",
67
+ "@types/node": "^25.6.0",
68
+ "dotenv": "^17.4.2",
69
+ "prisma": "^7.8.0",
70
+ "tsx": "^4.22.3",
71
+ "typescript": "^6.0.3"
72
+ },
73
+ "dependencies": {
74
+ "deepmerge": "^4.3.1",
75
+ "reflect-metadata": "^0.2.2",
76
+ "zod": "^4.4.3"
77
+ }
78
+ }
@@ -81,8 +81,25 @@ fs.mkdirSync(outputDir, { recursive: true });
81
81
  const typeFiles = [
82
82
  'VSRepoError.d.ts',
83
83
  'VSRepository.d.ts',
84
+ 'DynamicRepository.d.ts'
84
85
  ];
85
86
 
87
+ // Mapa de basename original (com e sem extensao) -> basename final `.types`,
88
+ // usado para corrigir os imports relativos entre os proprios arquivos gerados
89
+ // (ex: DynamicRepository.d.ts importando de "./VSRepository.d" ou
90
+ // VSRepository.d.ts importando de "./VSRepoError").
91
+ const crossFileReplacements = typeFiles.flatMap((fileName) => {
92
+ const originalBase = fileName.replace(/\.d\.ts$/, '');
93
+ const finalBase = `${originalBase}.types`;
94
+
95
+ return [
96
+ // from "./VSRepository.d" -> from "./VSRepository.types"
97
+ { pattern: new RegExp(`from(\\s+)(['"])\\./${originalBase}\\.d\\2`, 'g'), replacement: `from$1$2./${finalBase}$2` },
98
+ // from "./VSRepoError" -> from "./VSRepoError.types"
99
+ { pattern: new RegExp(`from(\\s+)(['"])\\./${originalBase}\\2`, 'g'), replacement: `from$1$2./${finalBase}$2` },
100
+ ];
101
+ });
102
+
86
103
  for (const fileName of typeFiles) {
87
104
  const sourceFile = path.join(sourceDir, fileName);
88
105
 
@@ -103,6 +120,10 @@ for (const fileName of typeFiles) {
103
120
  `from '${prismaTargetPath === CLASSIC_PRISMA_GENERATED_PATH ? prismaTargetPath : relativeImportPath(path.dirname(targetFile), prismaTargetPath)}'`
104
121
  );
105
122
 
123
+ for (const { pattern, replacement } of crossFileReplacements) {
124
+ contents = contents.replace(pattern, replacement);
125
+ }
126
+
106
127
  fs.writeFileSync(targetFile, GENERATED_HEADER + contents, 'utf8');
107
128
 
108
129
  console.log(`Gerado: ${path.relative(workspaceRoot, targetFile)}`);
@@ -152,6 +173,24 @@ export const VSRepository = VSRepositoryRuntime as typeof VSRepositoryType;
152
173
  export const setupVSRepo = setupVSRepoRuntime as typeof setupVSRepoType;
153
174
 
154
175
  export type * from './VSRepository.types';
176
+ `,
177
+ },
178
+ {
179
+ fileName: 'DynamicRepository.ts',
180
+ content: `import {
181
+ DynamicRepository as DynamicRepositoryRuntime,
182
+ DynamicMethod as DynamicMethodRuntime
183
+ } from 'vsrepo/DynamicRepository';
184
+
185
+ import type {
186
+ DynamicRepository as DynamicRepositoryType,
187
+ DynamicMethod as DynamicMethodType
188
+ } from './DynamicRepository.types';
189
+
190
+ export const DynamicRepository = DynamicRepositoryRuntime as typeof DynamicRepositoryType;
191
+ export const DynamicMethod = DynamicMethodRuntime as typeof DynamicMethodType;
192
+
193
+ export type * from './DynamicRepository.types';
155
194
  `,
156
195
  },
157
196
  {
@@ -169,8 +208,14 @@ export {
169
208
  setupVSRepo
170
209
  } from './VSRepository.js';
171
210
 
211
+ export {
212
+ DynamicRepository,
213
+ DynamicMethod
214
+ } from './DynamicRepository.js';
215
+
172
216
  export type * from './VSRepoError.types';
173
217
  export type * from './VSRepository.types';
218
+ export type * from './DynamicRepository.types';
174
219
  `,
175
220
  },
176
221
  ];