vsrepo 1.3.2 → 1.3.4

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.
Files changed (26) hide show
  1. package/README.md +116 -2
  2. package/README.pt-BR.md +1556 -0
  3. package/dist/DynamicRepository.d.ts +476 -0
  4. package/dist/DynamicRepository.js +26 -0
  5. package/dist/VSRepoError.d.ts +63 -54
  6. package/dist/VSRepository.d.ts +1162 -1056
  7. package/dist/VSRepository.js +51 -16
  8. package/dist/internal/constants/dinamic-methods-key.constant.js +4 -0
  9. package/dist/internal/decorators/dynamic-method.decorator.js +14 -0
  10. package/dist/internal/decorators/query-method.decorator.js +16 -0
  11. package/dist/internal/decorators/types/dynamic-method-config.type.js +2 -0
  12. package/dist/internal/entities/dynamic-method-metadata.entity.js +26 -0
  13. package/dist/internal/errors/vs-repo.error.js +5 -1
  14. package/dist/internal/resolvers/dbAndPrismaArgs.resolve.js +3 -0
  15. package/dist/internal/resolvers/dynamic-methods-metadata.resolve.js +15 -0
  16. package/dist/internal/utils/logger.util.js +1 -1
  17. package/dist/internal/utils/schemas.util.js +16 -1
  18. package/dist/internal/validation/constructor-config.validate.js +1 -10
  19. package/dist/internal/validation/dynamic-method-config.validate.js +19 -0
  20. package/dist/internal/validation/method-options.validate.js +1 -0
  21. package/dist/internal/validation/query-method-arg.validate.js +22 -0
  22. package/dist/internal/validation/query-method-options.validate.js +24 -0
  23. package/dist/internal/validation/types/query-method-arg.type.js +2 -0
  24. package/dist/internal/validation/types/query-method-options.type.js +2 -0
  25. package/package.json +78 -72
  26. package/scripts/configure-prisma-import.mjs +58 -9
@@ -29,6 +29,7 @@ const pretty_wheres_resolve_1 = require("./internal/resolvers/pretty-wheres.reso
29
29
  const specific_where_resolve_1 = require("./internal/resolvers/specific-where.resolve");
30
30
  const dbAndPrismaArgs_resolve_1 = require("./internal/resolvers/dbAndPrismaArgs.resolve");
31
31
  const method_options_validate_1 = require("./internal/validation/method-options.validate");
32
+ const query_method_arg_validate_1 = require("./internal/validation/query-method-arg.validate");
32
33
  class VSRepository {
33
34
  vsrepocache;
34
35
  tableName;
@@ -63,9 +64,9 @@ class VSRepository {
63
64
  }
64
65
  return extended;
65
66
  }
66
- build(prisma, config) {
67
+ build(prisma, config, useInstance) {
67
68
  (0, prisma_client_validate_1.validatePrismaClient)(prisma, this);
68
- const buildInstance = Object.create(this);
69
+ const buildInstance = useInstance ?? Object.create(this);
69
70
  buildInstance.prisma = prisma;
70
71
  if (buildInstance.softRemovekName &&
71
72
  prisma[buildInstance.tableName]["fields"][buildInstance.softRemovekName]["typeName"] !==
@@ -82,6 +83,27 @@ class VSRepository {
82
83
  (0, logger_util_1.logger)("Keys to map:", "build", buildInstance.tableName, methodsToMap);
83
84
  for (let methodToMap of methodsToMap) {
84
85
  const originalKey = methodToMap;
86
+ if (methods[originalKey]?.query) {
87
+ const modifyingQueryMethod = methods[originalKey].query.modifying;
88
+ const valueQueryMethod = methods[originalKey].query.value;
89
+ buildInstance[originalKey] = async (arg) => {
90
+ const queryArgValidated = (0, query_method_arg_validate_1.validateQueryMethodArg)(arg, buildInstance);
91
+ const db = queryArgValidated.db ?? buildInstance.prisma;
92
+ const start = showWorking
93
+ ? (0, logger_util_1.performanceLoggerStart)(buildInstance.tableName, `Query method: ${originalKey} (Modifying: ${modifyingQueryMethod})`, queryArgValidated.args)
94
+ : undefined;
95
+ try {
96
+ const result = await db[modifyingQueryMethod ? "$executeRawUnsafe" : "$queryRawUnsafe"](valueQueryMethod, ...queryArgValidated.args);
97
+ if (showWorking)
98
+ (0, logger_util_1.performanceLoggerEnd)(buildInstance.tableName, `Query method: ${originalKey} (Modifying: ${modifyingQueryMethod})`, start);
99
+ return result;
100
+ }
101
+ catch (err) {
102
+ throw err;
103
+ }
104
+ };
105
+ continue;
106
+ }
85
107
  methodToMap = methods[originalKey]?.proxyTo ?? methodToMap;
86
108
  const dinamicMethodInfo = (0, dinamic_method_info_resolve_1.resolveDinamicMethodInfo)(buildInstance, methodToMap, originalKey);
87
109
  const dinamicMethodCustomization = (0, dinamic_method_customization_resolve_1.resolveDinamicMethodCustomization)(buildInstance, dinamicMethodInfo, originalKey);
@@ -93,19 +115,27 @@ class VSRepository {
93
115
  };
94
116
  if (!dinamicMethodInfo.ignoreWhere) {
95
117
  (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
- }
118
+ // if (showWorking) {
119
+ // const argsSimulation: any[] = [];
120
+ // for (let x = 0; x < dinamicMethodInfo.argsCount; x++) {
121
+ // argsSimulation[x] = "00";
122
+ // }
123
+ // logger(
124
+ // `Where object resolved to ${methodToMap}:`,
125
+ // "build",
126
+ // buildInstance.tableName,
127
+ // resolveSpecificWhere(
128
+ // argsSimulation,
129
+ // dinamicMethodWhereOps.prettyWheres,
130
+ // ),
131
+ // );
132
+ // // logger(
133
+ // // `Where object resolved to ${methodToMap}:`,
134
+ // // "build",
135
+ // // buildInstance.tableName,
136
+ // // dinamicMethodWhereOps.prettyWheres,
137
+ // // );
138
+ // }
109
139
  }
110
140
  let select = undefined;
111
141
  if (dinamicMethodInfo.existsMode) {
@@ -123,7 +153,7 @@ class VSRepository {
123
153
  defaultSelect: methods[originalKey]?.selectModel,
124
154
  ignoreRequiredWhere: dinamicMethodWhereOps.whereType === "overwrite",
125
155
  },
126
- withoutWhere: dinamicMethodInfo.ignoreWhere,
156
+ withoutWhere: dinamicMethodInfo.ignoreWhere && !dinamicMethodInfo.onlyBaseWheres,
127
157
  specificSelect: select,
128
158
  pushWhere: dinamicMethodWhereOps.pushWhere,
129
159
  withoutSelect: dinamicMethodInfo.ignoreSelect,
@@ -158,6 +188,11 @@ class VSRepository {
158
188
  const { prismaArgs } = (0, dbAndPrismaArgs_resolve_1.resolveDbAndPrismaArgs)(resolveDbAndPrismaArgsData);
159
189
  return prismaArgs;
160
190
  });
191
+ if (showWorking) {
192
+ const argsSimulation = new Array(dinamicMethodInfo.argsCount).fill("00");
193
+ const prismaArgs = buildInstance.vsrepocache.get(originalKey)(argsSimulation);
194
+ (0, logger_util_1.logger)(`PrismaArgs preview for ${methodToMap}:`, "build", buildInstance.tableName, prismaArgs);
195
+ }
161
196
  buildInstance[originalKey] = async (...args) => {
162
197
  let db = buildInstance.prisma;
163
198
  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, 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,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.QueryMethod = QueryMethod;
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 query_method_options_validate_1 = require("../validation/query-method-options.validate");
7
+ function QueryMethod(value, options) {
8
+ const validatedConfig = options
9
+ ? (0, query_method_options_validate_1.validateQueryMethodOptions)(options)
10
+ : { modifying: false };
11
+ return (target, propertyKey) => {
12
+ const methods = Reflect.getMetadata(dinamic_methods_key_constant_1.DINAMIC_METHODS_KEY, target) ?? [];
13
+ methods.push(new dynamic_method_metadata_entity_1.DynamicMethodMetadata(propertyKey, true, undefined, undefined, undefined, undefined, undefined, undefined, { value, ...validatedConfig }));
14
+ Reflect.defineMetadata(dinamic_methods_key_constant_1.DINAMIC_METHODS_KEY, methods, target);
15
+ };
16
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,26 @@
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
+ query;
14
+ constructor(propertyKey, map, proxyTo, whereType, pushWhere, fbMode, injectOrdenation, injectPagination, query) {
15
+ this.propertyKey = propertyKey;
16
+ this.map = map;
17
+ this.proxyTo = proxyTo;
18
+ this.whereType = whereType;
19
+ this.pushWhere = pushWhere;
20
+ this.fbMode = fbMode;
21
+ this.injectOrdenation = injectOrdenation;
22
+ this.injectPagination = injectPagination;
23
+ this.query = query;
24
+ }
25
+ }
26
+ 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;
@@ -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
  }
@@ -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,23 @@ 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.queryOptionsSchema = 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.queryOptionsSchema = zod_1.default.strictObject({
12
+ value: exports.stringSchema,
13
+ modifying: exports.booleanSchema.default(false),
14
+ });
15
+ exports.methodSchema = zod_1.default.strictObject({
16
+ map: exports.booleanSchema,
17
+ selectModel: exports.stringSchema.or(zod_1.default.literal(false)).optional(),
18
+ whereType: zod_1.default.enum(["overwrite", "extending"]).optional(),
19
+ proxyTo: exports.stringSchema.optional(),
20
+ pushWhere: exports.objectSchema.optional(),
21
+ fbMode: zod_1.default.enum(["one", "list"]).optional(),
22
+ injectOrdenation: exports.objectSchema.or(zod_1.default.array(exports.objectSchema)).optional(),
23
+ injectPagination: exports.objectSchema.optional(),
24
+ query: exports.queryOptionsSchema.optional(),
25
+ });
@@ -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);
@@ -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.validateQueryMethodArg = validateQueryMethodArg;
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 validateQueryMethodArg(arg, instance) {
11
+ const queryArgSchema = zod_1.default.strictObject({
12
+ args: zod_1.default.array(zod_1.default.any()),
13
+ db: schemas_util_1.objectSchema.optional(),
14
+ });
15
+ const argParsed = queryArgSchema.safeParse(arg);
16
+ if (!argParsed.success) {
17
+ const firstIssue = argParsed.error.issues[0];
18
+ const path = firstIssue?.path.length ? firstIssue.path.join(".") : "options";
19
+ throw new vs_repo_error_1.VSRepoRuntimeError(`[VSRepository] (${instance.tableName}: runtime) ${path}: ${firstIssue?.message}`, "67542");
20
+ }
21
+ return argParsed.data;
22
+ }
@@ -0,0 +1,24 @@
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.validateQueryMethodOptions = validateQueryMethodOptions;
7
+ const zod_1 = __importDefault(require("zod"));
8
+ const vs_repo_error_1 = require("../errors/vs-repo.error");
9
+ const is_object_validate_1 = require("./is-object.validate");
10
+ const schemas_util_1 = require("../utils/schemas.util");
11
+ function validateQueryMethodOptions(options) {
12
+ if (!(0, is_object_validate_1.isObject)(options)) {
13
+ throw new vs_repo_error_1.VSRepoDecoratorError(`[VSRepository] (unknown: decorator) 'options' must be a valid object`);
14
+ }
15
+ const optionsParsed = zod_1.default
16
+ .strictObject({ modifying: schemas_util_1.booleanSchema.default(false) })
17
+ .safeParse(options);
18
+ if (!optionsParsed.success) {
19
+ const firstIssue = optionsParsed.error.issues[0];
20
+ const path = firstIssue?.path.length ? firstIssue.path.join(".") : "options";
21
+ throw new vs_repo_error_1.VSRepoDecoratorError(`[VSRepository] (unknown: decorator) ${path}: ${firstIssue?.message}`);
22
+ }
23
+ return optionsParsed.data;
24
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,72 +1,78 @@
1
- {
2
- "name": "vsrepo",
3
- "version": "1.3.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": "./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.4",
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,27 @@ 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
+ QueryMethod as QueryMethodRuntime,
184
+ } from 'vsrepo/DynamicRepository';
185
+
186
+ import type {
187
+ DynamicRepository as DynamicRepositoryType,
188
+ DynamicMethod as DynamicMethodType,
189
+ QueryMethod as QueryMethodType,
190
+ } from './DynamicRepository.types';
191
+
192
+ export const DynamicRepository = DynamicRepositoryRuntime as typeof DynamicRepositoryType;
193
+ export const DynamicMethod = DynamicMethodRuntime as typeof DynamicMethodType;
194
+ export const QueryMethod = QueryMethodRuntime as typeof QueryMethodType;
195
+
196
+ export type * from './DynamicRepository.types';
155
197
  `,
156
198
  },
157
199
  {
@@ -169,8 +211,15 @@ export {
169
211
  setupVSRepo
170
212
  } from './VSRepository.js';
171
213
 
214
+ export {
215
+ DynamicRepository,
216
+ DynamicMethod,
217
+ QueryMethod,
218
+ } from './DynamicRepository.js';
219
+
172
220
  export type * from './VSRepoError.types';
173
221
  export type * from './VSRepository.types';
222
+ export type * from './DynamicRepository.types';
174
223
  `,
175
224
  },
176
225
  ];
@@ -184,15 +233,15 @@ for (const file of tsFiles) {
184
233
  }
185
234
 
186
235
  // Copia o README.md do pacote VSRepository para o diretório de output, se existir
187
- const readmeSource = path.join(packageRoot, 'README.md');
188
- const readmeTarget = path.join(outputDir, 'README.md');
189
-
190
- if (fs.existsSync(readmeSource)) {
191
- fs.copyFileSync(readmeSource, readmeTarget);
192
- console.log(`Gerado: ${path.relative(workspaceRoot, readmeTarget)}`);
193
- } else {
194
- console.warn(`README.md do VSRepository nao encontrado em: ${path.relative(workspaceRoot, readmeSource)}. Ignorando a copia.`);
195
- }
236
+ // const readmeSource = path.join(packageRoot, 'README.md');
237
+ // const readmeTarget = path.join(outputDir, 'README.md');
238
+
239
+ // if (fs.existsSync(readmeSource)) {
240
+ // fs.copyFileSync(readmeSource, readmeTarget);
241
+ // console.log(`Gerado: ${path.relative(workspaceRoot, readmeTarget)}`);
242
+ // } else {
243
+ // console.warn(`README.md do VSRepository nao encontrado em: ${path.relative(workspaceRoot, readmeSource)}. Ignorando a copia.`);
244
+ // }
196
245
 
197
246
  console.log('\nVSRepository gerado com tipagem do Prisma.');
198
247
  console.log(`Output: ${path.relative(workspaceRoot, outputDir)}`);