vsrepo 1.3.5 → 1.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/README.md +147 -137
  2. package/README.pt-BR.md +154 -144
  3. package/dist/DynamicRepository.d.ts +24 -7
  4. package/dist/VSRepoError.d.ts +21 -1
  5. package/dist/VSRepository.d.ts +36 -12
  6. package/dist/VSRepository.js +49 -49
  7. package/dist/internal/constants/dynamic-methods-key.constant.js +4 -0
  8. package/dist/internal/decorators/dynamic-method.decorator.js +4 -4
  9. package/dist/internal/decorators/query-method.decorator.js +3 -3
  10. package/dist/internal/entities/dynamic-method-metadata.entity.js +3 -3
  11. package/dist/internal/resolvers/base-methods.resolve.js +2 -2
  12. package/dist/internal/resolvers/dbAndPrismaArgs.resolve.js +4 -4
  13. package/dist/internal/resolvers/dynamic-method-customization.resolve.js +57 -0
  14. package/dist/internal/resolvers/dynamic-method-info.resolve.js +279 -0
  15. package/dist/internal/resolvers/dynamic-methods-metadata.resolve.js +2 -2
  16. package/dist/internal/resolvers/pretty-wheres.resolve.js +8 -8
  17. package/dist/internal/resolvers/types/dynamic-method-where-ops.type.js +2 -0
  18. package/dist/internal/utils/schemas.util.js +8 -2
  19. package/dist/internal/validation/constructor-config.validate.js +7 -4
  20. package/package.json +1 -1
  21. package/scripts/configure-prisma-import.mjs +23 -10
  22. package/scripts/copy-types.mjs +16 -16
  23. package/dist/internal/constants/dinamic-methods-key.constant.js +0 -4
  24. package/dist/internal/resolvers/dinamic-method-customization.resolve.js +0 -57
  25. package/dist/internal/resolvers/dinamic-method-info.resolve.js +0 -279
  26. /package/dist/internal/{resolvers/types/dinamic-method-customization.type.js → errors/types/vs-repo-runtime-error-code.type.js} +0 -0
  27. /package/dist/internal/resolvers/types/{dinamic-method-info.type.js → dynamic-method-customization.type.js} +0 -0
  28. /package/dist/internal/resolvers/types/{dinamic-method-where-ops.type.js → dynamic-method-info.type.js} +0 -0
@@ -8,6 +8,24 @@ export type VSRepoErrorType =
8
8
  | 'VSREPO_RUNTIME'
9
9
  | 'VSREPO_DECORATOR';
10
10
 
11
+ /**
12
+ * Catalog of the internal codes used by `VSRepoRuntimeError`. Each code identifies
13
+ * a category of runtime failure, so consuming code can discriminate on
14
+ * `error.code` without parsing the (human-readable) message. See the
15
+ * "Error handling" section of the README for the full description of each code.
16
+ */
17
+ export type VSRepoRuntimeErrorCode =
18
+ /** A required argument is missing or has an invalid shape (e.g. missing `pk`, `pks`/`objs`/`tuples` that aren't an array, or `options`/`obj` that isn't a valid object). */
19
+ | '65706'
20
+ /** No record was found for the provided primary key (`getOrThrow` when fetching the base record). */
21
+ | '20727'
22
+ /** Validation (zod) of a method's `options`, or of a `@QueryMethod` argument, failed. */
23
+ | '67542'
24
+ /** A relation passed to `save`/`patch`/`merge` has an invalid shape for the configured `mode`/`restriction`. */
25
+ | '91868'
26
+ /** A dynamic method (`config.methods`) was called with fewer positional arguments than its `where` fields require. */
27
+ | '48670';
28
+
11
29
  /**
12
30
  * Base class for all errors thrown by the VSRepository.
13
31
  */
@@ -59,5 +77,7 @@ export declare class VSRepoDecoratorError extends VSRepoError {
59
77
  */
60
78
  export declare class VSRepoRuntimeError extends VSRepoError {
61
79
  readonly type: 'VSREPO_RUNTIME';
62
- constructor(message: string, code: string);
80
+ /** Internal code identifying the category of runtime failure. See {@link VSRepoRuntimeErrorCode}. */
81
+ readonly code: VSRepoRuntimeErrorCode;
82
+ constructor(message: string, code: VSRepoRuntimeErrorCode);
63
83
  }
@@ -30,7 +30,7 @@ export type DbTransaction = Prisma.TransactionClient;
30
30
  */
31
31
  export type ClientOrTransaction = DbClient | DbTransaction;
32
32
 
33
- export * from './VSRepoError';
33
+ export type * from './VSRepoError';
34
34
 
35
35
  type OrderPattern = {
36
36
  [key: string]: 'asc' | 'desc' | { _count: 'asc' | 'desc' } | OrderPattern;
@@ -409,7 +409,7 @@ type ExtractIncludeModels<Config> = Config extends { includeModels: infer IM } ?
409
409
  type ExtractDefaultSelect<Config> = Config extends { defaultSelectModel: infer D } ? D : never;
410
410
  type ExtractRelations<Config> = Config extends { relations: infer R } ? (R extends object ? R : {}) : {};
411
411
  type ExtractSoftRemovekName<Config> = Config extends { softRemovekName: infer S } ? S : never;
412
- type ExtractDefaultOrdenation<Config> = Config extends { defaultOrdenation: infer O } ? O : never;
412
+ type ExtractDefaultOrdering<Config> = Config extends { defaultOrdering: infer O } ? O : Config extends { defaultOrdenation: infer O } ? O : never;
413
413
 
414
414
  type AggregateMethod<M extends PrismaModelName> = <A extends Prisma.TypeMap['model'][M]['operations']['aggregate']['args']>(
415
415
  prismaArgs: A,
@@ -529,7 +529,13 @@ export type CursorModel<M extends PrismaModelName> = PrismaModelInputs<M>['curso
529
529
  /**
530
530
  * Type of the `orderBy` object of a Prisma model.
531
531
  */
532
- export type OrdenationModel<M extends PrismaModelName> = PrismaModelInputs<M>['orderByInput'];
532
+ export type OrderingModel<M extends PrismaModelName> = PrismaModelInputs<M>['orderByInput'];
533
+
534
+ /**
535
+ * Type of the `orderBy` object of a Prisma model.
536
+ * @deprecated Use `OrderingModel` instead.
537
+ */
538
+ export type OrdenationModel<M extends PrismaModelName> = OrderingModel<M>;
533
539
 
534
540
  /**
535
541
  * Pagination options with typed cursor for a Prisma model.
@@ -563,7 +569,12 @@ export type MethodConfig<M extends PrismaModelName, SelectModels = any> = {
563
569
  */
564
570
  readonly fbMode?: 'one' | 'list';
565
571
  /** Injects a fixed ordering automatically into the query. */
566
- readonly injectOrdenation?: OrdenationModel<M>;
572
+ readonly injectOrdering?: OrderingModel<M>;
573
+ /**
574
+ * Injects a fixed ordering automatically into the query.
575
+ * @deprecated Use `injectOrdering` instead.
576
+ */
577
+ readonly injectOrdenation?: OrderingModel<M>;
567
578
  /** Injects a fixed pagination automatically into the query. */
568
579
  readonly injectPagination?: PaginationModel<M>;
569
580
  /**
@@ -814,7 +825,7 @@ type _Inc<Config> = ExtractIncludeModels<Config>;
814
825
  type _Def<Config> = ExtractDefaultSelect<Config>;
815
826
  type _Rel<Config> = ExtractRelations<Config>;
816
827
  type _Soft<Config> = ExtractSoftRemovekName<Config>;
817
- type _DOrd<Config> = ExtractDefaultOrdenation<Config>;
828
+ type _DOrd<Config> = ExtractDefaultOrdering<Config>;
818
829
 
819
830
  // ─── refactored mapped type — optimized for the TS compiler ──────────────────
820
831
 
@@ -829,7 +840,7 @@ type AllBaseMethods<
829
840
  TRelations = _Rel<Config>,
830
841
  TSoftKey = _Soft<Config>,
831
842
  I = PrismaModelInputs<M>,
832
- TDefaultOrdenation = _DOrd<Config>,
843
+ TDefaultOrdering = _DOrd<Config>,
833
844
  TIncludes = _Inc<Config>
834
845
  > = {
835
846
  /** Fetches a record by its primary key (PK). */
@@ -886,7 +897,7 @@ type AllBaseMethods<
886
897
  pagination?: PaginationOptions<I extends { cursorInput: infer Curs } ? Curs : unknown>;
887
898
  /**
888
899
  * Ordering to apply to the query.
889
- * When omitted and `defaultOrdenation` is configured on the repository,
900
+ * When omitted and `defaultOrdering` is configured on the repository,
890
901
  * the default ordering is applied automatically.
891
902
  */
892
903
  order?: I extends { orderByInput: infer OB } ? OB : OrderOptions;
@@ -927,10 +938,10 @@ type InjectedBaseMethods<
927
938
  TRelations = _Rel<Config>,
928
939
  TSoftKey = _Soft<Config>,
929
940
  I = PrismaModelInputs<M>,
930
- TDefaultOrdenation = _DOrd<Config>,
941
+ TDefaultOrdering = _DOrd<Config>,
931
942
  TIncludes = _Inc<Config>
932
943
  > = Pick<
933
- AllBaseMethods<T, M, Config, C, TSelects, TDefault, TPk, TRelations, TSoftKey, I, TDefaultOrdenation, TIncludes>,
944
+ AllBaseMethods<T, M, Config, C, TSelects, TDefault, TPk, TRelations, TSoftKey, I, TDefaultOrdering, TIncludes>,
934
945
  | (C extends { baseMethods: { get: { active: false } } } ? never : 'get')
935
946
  | (C extends { baseMethods: { getOrThrow: { active: false } } } ? never : 'getOrThrow')
936
947
  | (C extends { baseMethods: { getList: { active: false } } } ? never : 'getList')
@@ -1034,7 +1045,9 @@ export type RepoConfig<T, M extends PrismaModelName, SM extends Record<string, A
1034
1045
  defaultSelectModel?: Extract<keyof SM, string>;
1035
1046
  includeModels?: IncludeModels<M>;
1036
1047
  requiredWhere?: WhereModel<M>;
1037
- defaultOrdenation?: OrdenationModel<M>;
1048
+ defaultOrdering?: OrderingModel<M>;
1049
+ /** @deprecated Use `defaultOrdering` instead. */
1050
+ defaultOrdenation?: OrderingModel<M>;
1038
1051
  relations?: RepositoryRelations<T>;
1039
1052
  methods?: Record<string, MethodConfig<M, SM>>;
1040
1053
  };
@@ -1132,12 +1145,23 @@ export type ValidateRepoConfig<T extends object, M extends PrismaModelName, Conf
1132
1145
 
1133
1146
  /**
1134
1147
  * Default ordering automatically injected into all queries that accept `orderBy`,
1135
- * unless the method already has `injectOrdenation` configured or uses the `Ordered` suffix.
1148
+ * unless the method already has `injectOrdering` configured or uses the `Ordered` suffix.
1149
+ *
1150
+ * Useful for ensuring a consistent sort order across the repository without repeating
1151
+ * the `order` argument on every call.
1152
+ */
1153
+ defaultOrdering?: OrderingModel<M>;
1154
+
1155
+ /**
1156
+ * Default ordering automatically injected into all queries that accept `orderBy`,
1157
+ * unless the method already has `injectOrdering` configured or uses the `Ordered` suffix.
1136
1158
  *
1137
1159
  * Useful for ensuring a consistent sort order across the repository without repeating
1138
1160
  * the `order` argument on every call.
1161
+ *
1162
+ * @deprecated Use `defaultOrdering` instead.
1139
1163
  */
1140
- defaultOrdenation?: OrdenationModel<M>;
1164
+ defaultOrdenation?: OrderingModel<M>;
1141
1165
 
1142
1166
  /**
1143
1167
  * Configures automatic relation management.
@@ -23,8 +23,8 @@ const prisma_client_validate_1 = require("./internal/validation/prisma-client.va
23
23
  const vs_repo_error_1 = require("./internal/errors/vs-repo.error");
24
24
  const base_methods_resolve_1 = require("./internal/resolvers/base-methods.resolve");
25
25
  const logger_util_1 = require("./internal/utils/logger.util");
26
- const dinamic_method_info_resolve_1 = require("./internal/resolvers/dinamic-method-info.resolve");
27
- const dinamic_method_customization_resolve_1 = require("./internal/resolvers/dinamic-method-customization.resolve");
26
+ const dynamic_method_info_resolve_1 = require("./internal/resolvers/dynamic-method-info.resolve");
27
+ const dynamic_method_customization_resolve_1 = require("./internal/resolvers/dynamic-method-customization.resolve");
28
28
  const pretty_wheres_resolve_1 = require("./internal/resolvers/pretty-wheres.resolve");
29
29
  const specific_where_resolve_1 = require("./internal/resolvers/specific-where.resolve");
30
30
  const dbAndPrismaArgs_resolve_1 = require("./internal/resolvers/dbAndPrismaArgs.resolve");
@@ -41,7 +41,7 @@ class VSRepository {
41
41
  requiredWhere;
42
42
  relations;
43
43
  methods;
44
- defaultOrdenation;
44
+ defaultOrdering;
45
45
  constructor(config) {
46
46
  const validatedConfig = (0, constructor_config_validate_1.validateConstructorConfig)(config);
47
47
  this.vsrepocache = new Map();
@@ -54,7 +54,7 @@ class VSRepository {
54
54
  this.relations = validatedConfig.relations;
55
55
  this.requiredWhere = validatedConfig.requiredWhere;
56
56
  this.methods = validatedConfig.methods;
57
- this.defaultOrdenation = validatedConfig.defaultOrdenation;
57
+ this.defaultOrdering = validatedConfig.defaultOrdering;
58
58
  }
59
59
  extend(extensionFunc) {
60
60
  const extension = (0, extension_validate_1.validateExtension)(extensionFunc, this);
@@ -105,19 +105,19 @@ class VSRepository {
105
105
  continue;
106
106
  }
107
107
  methodToMap = methods[originalKey]?.proxyTo ?? methodToMap;
108
- const dinamicMethodInfo = (0, dinamic_method_info_resolve_1.resolveDinamicMethodInfo)(buildInstance, methodToMap, originalKey);
109
- const dinamicMethodCustomization = (0, dinamic_method_customization_resolve_1.resolveDinamicMethodCustomization)(buildInstance, dinamicMethodInfo, originalKey);
110
- const dinamicMethodWhereOps = {
108
+ const dynamicMethodInfo = (0, dynamic_method_info_resolve_1.resolveDynamicMethodInfo)(buildInstance, methodToMap, originalKey);
109
+ const dynamicMethodCustomization = (0, dynamic_method_customization_resolve_1.resolveDynamicMethodCustomization)(buildInstance, dynamicMethodInfo, originalKey);
110
+ const dynamicMethodWhereOps = {
111
111
  uglyWheres: [],
112
112
  prettyWheres: [],
113
113
  whereType: methods[originalKey]?.whereType ?? "extending",
114
114
  pushWhere: methods[originalKey]?.pushWhere,
115
115
  };
116
- if (!dinamicMethodInfo.ignoreWhere) {
117
- (0, pretty_wheres_resolve_1.resolvePrettyWheres)(dinamicMethodInfo, dinamicMethodWhereOps);
116
+ if (!dynamicMethodInfo.ignoreWhere) {
117
+ (0, pretty_wheres_resolve_1.resolvePrettyWheres)(dynamicMethodInfo, dynamicMethodWhereOps);
118
118
  // if (showWorking) {
119
119
  // const argsSimulation: any[] = [];
120
- // for (let x = 0; x < dinamicMethodInfo.argsCount; x++) {
120
+ // for (let x = 0; x < dynamicMethodInfo.argsCount; x++) {
121
121
  // argsSimulation[x] = "00";
122
122
  // }
123
123
  // logger(
@@ -126,24 +126,24 @@ class VSRepository {
126
126
  // buildInstance.tableName,
127
127
  // resolveSpecificWhere(
128
128
  // argsSimulation,
129
- // dinamicMethodWhereOps.prettyWheres,
129
+ // dynamicMethodWhereOps.prettyWheres,
130
130
  // ),
131
131
  // );
132
132
  // // logger(
133
133
  // // `Where object resolved to ${methodToMap}:`,
134
134
  // // "build",
135
135
  // // buildInstance.tableName,
136
- // // dinamicMethodWhereOps.prettyWheres,
136
+ // // dynamicMethodWhereOps.prettyWheres,
137
137
  // // );
138
138
  // }
139
139
  }
140
140
  let select = undefined;
141
- if (dinamicMethodInfo.existsMode) {
141
+ if (dynamicMethodInfo.existsMode) {
142
142
  select = { [buildInstance.pkName]: true };
143
143
  }
144
144
  buildInstance.vsrepocache.set(originalKey, (args, methodOptions) => {
145
- if (dinamicMethodInfo.prismaArgsIndex !== undefined)
146
- return args.at(dinamicMethodInfo.prismaArgsIndex);
145
+ if (dynamicMethodInfo.prismaArgsIndex !== undefined)
146
+ return args.at(dynamicMethodInfo.prismaArgsIndex);
147
147
  const resolveDbAndPrismaArgsData = {
148
148
  instance: buildInstance,
149
149
  options: methodOptions,
@@ -151,58 +151,58 @@ class VSRepository {
151
151
  baseConfig: {
152
152
  active: true,
153
153
  defaultSelect: methods[originalKey]?.selectModel,
154
- ignoreRequiredWhere: dinamicMethodWhereOps.whereType === "overwrite",
154
+ ignoreRequiredWhere: dynamicMethodWhereOps.whereType === "overwrite",
155
155
  },
156
- withoutWhere: dinamicMethodInfo.ignoreWhere && !dinamicMethodInfo.onlyBaseWheres,
156
+ withoutWhere: dynamicMethodInfo.ignoreWhere && !dynamicMethodInfo.onlyBaseWheres,
157
157
  specificSelect: select,
158
- pushWhere: dinamicMethodWhereOps.pushWhere,
159
- withoutSelect: dinamicMethodInfo.ignoreSelect,
160
- skipDuplicates: dinamicMethodCustomization.skipDuplicates,
161
- ordenation: dinamicMethodCustomization.orderPosition !== undefined
162
- ? args.at(dinamicMethodCustomization.orderPosition)
163
- : dinamicMethodCustomization.injectOrdenation,
164
- pagination: dinamicMethodCustomization.paginationPosition !== undefined
165
- ? args.at(dinamicMethodCustomization.paginationPosition)
166
- : dinamicMethodCustomization.injectPagination,
167
- dataPayload: dinamicMethodInfo.dataIndex !== undefined
168
- ? args.at(dinamicMethodInfo.dataIndex)
158
+ pushWhere: dynamicMethodWhereOps.pushWhere,
159
+ withoutSelect: dynamicMethodInfo.ignoreSelect,
160
+ skipDuplicates: dynamicMethodCustomization.skipDuplicates,
161
+ ordering: dynamicMethodCustomization.orderPosition !== undefined
162
+ ? args.at(dynamicMethodCustomization.orderPosition)
163
+ : dynamicMethodCustomization.injectOrdering,
164
+ pagination: dynamicMethodCustomization.paginationPosition !== undefined
165
+ ? args.at(dynamicMethodCustomization.paginationPosition)
166
+ : dynamicMethodCustomization.injectPagination,
167
+ dataPayload: dynamicMethodInfo.dataIndex !== undefined
168
+ ? args.at(dynamicMethodInfo.dataIndex)
169
169
  : undefined,
170
- createPayload: dinamicMethodInfo.createIndex !== undefined
171
- ? args.at(dinamicMethodInfo.createIndex)
170
+ createPayload: dynamicMethodInfo.createIndex !== undefined
171
+ ? args.at(dynamicMethodInfo.createIndex)
172
172
  : undefined,
173
- updatePayload: dinamicMethodInfo.updateIndex !== undefined
174
- ? args.at(dinamicMethodInfo.updateIndex)
173
+ updatePayload: dynamicMethodInfo.updateIndex !== undefined
174
+ ? args.at(dynamicMethodInfo.updateIndex)
175
175
  : undefined,
176
- withOrdenationAndPagination: !dinamicMethodInfo.ignoreOrderByAndPagination,
177
- distinctKeys: dinamicMethodCustomization.distinctKeys,
176
+ withOrderingAndPagination: !dynamicMethodInfo.ignoreOrderByAndPagination,
177
+ distinctKeys: dynamicMethodCustomization.distinctKeys,
178
178
  };
179
- if (!dinamicMethodInfo.ignoreWhere) {
180
- resolveDbAndPrismaArgsData.specificWhere = (0, specific_where_resolve_1.resolveSpecificWhere)(args, dinamicMethodWhereOps.prettyWheres);
179
+ if (!dynamicMethodInfo.ignoreWhere) {
180
+ resolveDbAndPrismaArgsData.specificWhere = (0, specific_where_resolve_1.resolveSpecificWhere)(args, dynamicMethodWhereOps.prettyWheres);
181
181
  }
182
- else if (dinamicMethodInfo.onlyBaseWheres) {
182
+ else if (dynamicMethodInfo.onlyBaseWheres) {
183
183
  resolveDbAndPrismaArgsData.specificWhere =
184
- dinamicMethodInfo.whereIndex !== undefined
185
- ? args.at(dinamicMethodInfo.whereIndex)
184
+ dynamicMethodInfo.whereIndex !== undefined
185
+ ? args.at(dynamicMethodInfo.whereIndex)
186
186
  : {};
187
187
  }
188
188
  const { prismaArgs } = (0, dbAndPrismaArgs_resolve_1.resolveDbAndPrismaArgs)(resolveDbAndPrismaArgsData);
189
189
  return prismaArgs;
190
190
  });
191
191
  if (showWorking) {
192
- const argsSimulation = new Array(dinamicMethodInfo.argsCount).fill("00");
192
+ const argsSimulation = new Array(dynamicMethodInfo.argsCount).fill("00");
193
193
  const prismaArgs = buildInstance.vsrepocache.get(originalKey)(argsSimulation);
194
194
  (0, logger_util_1.logger)(`PrismaArgs preview for ${methodToMap}:`, "build", buildInstance.tableName, prismaArgs);
195
195
  }
196
196
  buildInstance[originalKey] = async (...args) => {
197
197
  let db = buildInstance.prisma;
198
198
  let methodOptions = undefined;
199
- if (args.length < dinamicMethodInfo.argsCount) {
200
- const missingParams = dinamicMethodInfo.whereParams
201
- .concat(dinamicMethodInfo.otherParams)
199
+ if (args.length < dynamicMethodInfo.argsCount) {
200
+ const missingParams = dynamicMethodInfo.whereParams
201
+ .concat(dynamicMethodInfo.otherParams)
202
202
  .slice(args.length);
203
203
  throw new vs_repo_error_1.VSRepoRuntimeError(`[VSRepository] (${buildInstance.tableName}: runtime) Missing parameters: ${missingParams.join(", ")}`, "48670");
204
204
  }
205
- else if (args.length > dinamicMethodInfo.argsCount) {
205
+ else if (args.length > dynamicMethodInfo.argsCount) {
206
206
  const optionsArg = args[args.length - 1];
207
207
  methodOptions = (0, method_options_validate_1.validateMethodOptions)(optionsArg, buildInstance);
208
208
  db = methodOptions.db ?? db;
@@ -212,20 +212,20 @@ class VSRepository {
212
212
  }
213
213
  const prismaArgs = buildInstance.vsrepocache.get(originalKey)(args, methodOptions);
214
214
  const start = showWorking
215
- ? (0, logger_util_1.performanceLoggerStart)(buildInstance.tableName, dinamicMethodInfo.method, prismaArgs)
215
+ ? (0, logger_util_1.performanceLoggerStart)(buildInstance.tableName, dynamicMethodInfo.method, prismaArgs)
216
216
  : undefined;
217
217
  try {
218
- const result = await db[buildInstance.tableName][dinamicMethodInfo.method](prismaArgs);
218
+ const result = await db[buildInstance.tableName][dynamicMethodInfo.method](prismaArgs);
219
219
  if (showWorking)
220
- (0, logger_util_1.performanceLoggerEnd)(buildInstance.tableName, dinamicMethodInfo.method, start);
221
- if (dinamicMethodInfo.existsMode) {
220
+ (0, logger_util_1.performanceLoggerEnd)(buildInstance.tableName, dynamicMethodInfo.method, start);
221
+ if (dynamicMethodInfo.existsMode) {
222
222
  return !!result;
223
223
  }
224
224
  return result;
225
225
  }
226
226
  catch (err) {
227
227
  // logger(
228
- // `Fatal error when executing ${dinamicMethodInfo.method}:`,
228
+ // `Fatal error when executing ${dynamicMethodInfo.method}:`,
229
229
  // "runtime",
230
230
  // buildInstance.tableName,
231
231
  // { prismaArgs },
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DYNAMIC_METHODS_KEY = void 0;
4
+ exports.DYNAMIC_METHODS_KEY = Symbol("dynamic-methods-key");
@@ -1,14 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DynamicMethod = DynamicMethod;
4
- const dinamic_methods_key_constant_1 = require("../constants/dinamic-methods-key.constant");
4
+ const dynamic_methods_key_constant_1 = require("../constants/dynamic-methods-key.constant");
5
5
  const dynamic_method_metadata_entity_1 = require("../entities/dynamic-method-metadata.entity");
6
6
  const dynamic_method_config_validate_1 = require("../validation/dynamic-method-config.validate");
7
7
  function DynamicMethod(config) {
8
8
  const validatedConfig = config ? (0, dynamic_method_config_validate_1.validateDynamicMethodConfig)(config) : undefined;
9
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);
10
+ const methods = Reflect.getMetadata(dynamic_methods_key_constant_1.DYNAMIC_METHODS_KEY, target) ?? [];
11
+ methods.push(new dynamic_method_metadata_entity_1.DynamicMethodMetadata(propertyKey, true, validatedConfig?.proxyTo, validatedConfig?.whereType, validatedConfig?.pushWhere, validatedConfig?.fbMode, validatedConfig?.injectOrdering, validatedConfig?.injectPagination));
12
+ Reflect.defineMetadata(dynamic_methods_key_constant_1.DYNAMIC_METHODS_KEY, methods, target);
13
13
  };
14
14
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.QueryMethod = QueryMethod;
4
- const dinamic_methods_key_constant_1 = require("../constants/dinamic-methods-key.constant");
4
+ const dynamic_methods_key_constant_1 = require("../constants/dynamic-methods-key.constant");
5
5
  const dynamic_method_metadata_entity_1 = require("../entities/dynamic-method-metadata.entity");
6
6
  const vs_repo_error_1 = require("../errors/vs-repo.error");
7
7
  const query_method_options_validate_1 = require("../validation/query-method-options.validate");
@@ -13,8 +13,8 @@ function QueryMethod(value, options) {
13
13
  ? (0, query_method_options_validate_1.validateQueryMethodOptions)(options)
14
14
  : { modifying: false };
15
15
  return (target, propertyKey) => {
16
- const methods = Reflect.getMetadata(dinamic_methods_key_constant_1.DINAMIC_METHODS_KEY, target) ?? [];
16
+ const methods = Reflect.getMetadata(dynamic_methods_key_constant_1.DYNAMIC_METHODS_KEY, target) ?? [];
17
17
  methods.push(new dynamic_method_metadata_entity_1.DynamicMethodMetadata(propertyKey, true, undefined, undefined, undefined, undefined, undefined, undefined, { value, ...validatedConfig }));
18
- Reflect.defineMetadata(dinamic_methods_key_constant_1.DINAMIC_METHODS_KEY, methods, target);
18
+ Reflect.defineMetadata(dynamic_methods_key_constant_1.DYNAMIC_METHODS_KEY, methods, target);
19
19
  };
20
20
  }
@@ -8,17 +8,17 @@ class DynamicMethodMetadata {
8
8
  whereType;
9
9
  pushWhere;
10
10
  fbMode;
11
- injectOrdenation;
11
+ injectOrdering;
12
12
  injectPagination;
13
13
  query;
14
- constructor(propertyKey, map, proxyTo, whereType, pushWhere, fbMode, injectOrdenation, injectPagination, query) {
14
+ constructor(propertyKey, map, proxyTo, whereType, pushWhere, fbMode, injectOrdering, injectPagination, query) {
15
15
  this.propertyKey = propertyKey;
16
16
  this.map = map;
17
17
  this.proxyTo = proxyTo;
18
18
  this.whereType = whereType;
19
19
  this.pushWhere = pushWhere;
20
20
  this.fbMode = fbMode;
21
- this.injectOrdenation = injectOrdenation;
21
+ this.injectOrdering = injectOrdering;
22
22
  this.injectPagination = injectPagination;
23
23
  this.query = query;
24
24
  }
@@ -91,8 +91,8 @@ function resolveBaseMethods(instance, config) {
91
91
  baseConfig: baseMethods.getAll,
92
92
  options: restOptions,
93
93
  pagination,
94
- ordenation: order,
95
- withOrdenationAndPagination: true,
94
+ ordering: order,
95
+ withOrderingAndPagination: true,
96
96
  });
97
97
  const start = showWorking
98
98
  ? (0, logger_util_1.performanceLoggerStart)(tableName, "getAll", prismaArgs)
@@ -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, distinctKeys, } = data;
8
+ const { baseConfig, instance, options, wherePkValue, withoutSelect, withoutWhere, specificSelect, dataPayload, createPayload, updatePayload, alreadyValidatedOptions, specificWhere, pushWhere, ordering, pagination, skipDuplicates, forceSeeMode, withOrderingAndPagination, distinctKeys, } = data;
9
9
  const validatedOptions = alreadyValidatedOptions && options
10
10
  ? options
11
11
  : (0, method_options_validate_1.validateMethodOptions)(options, instance);
@@ -43,9 +43,9 @@ function resolveDbAndPrismaArgs(data) {
43
43
  if (updatePayload) {
44
44
  prismaArgs.update = updatePayload;
45
45
  }
46
- if (withOrdenationAndPagination) {
47
- if (instance.defaultOrdenation || ordenation) {
48
- prismaArgs.orderBy = ordenation ?? instance.defaultOrdenation;
46
+ if (withOrderingAndPagination) {
47
+ if (instance.defaultOrdering || ordering) {
48
+ prismaArgs.orderBy = ordering ?? instance.defaultOrdering;
49
49
  }
50
50
  if (pagination) {
51
51
  prismaArgs.skip = pagination.skip;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveDynamicMethodCustomization = resolveDynamicMethodCustomization;
4
+ const uncapitalize_util_1 = require("../utils/uncapitalize.util");
5
+ function resolveDynamicMethodCustomization(instance, dynamicMethodInfo, originalKey) {
6
+ const dynamicMethodCustomization = {};
7
+ if (!dynamicMethodInfo.ignoreSkipDuplicates) {
8
+ if (dynamicMethodInfo.keyToMapReplaced.endsWith("SkipDuplicates")) {
9
+ dynamicMethodInfo.keyToMapReplaced = dynamicMethodInfo.keyToMapReplaced.replace("SkipDuplicates", "");
10
+ dynamicMethodCustomization.skipDuplicates = true;
11
+ }
12
+ }
13
+ if (!dynamicMethodInfo.ignoreOrderByAndPagination) {
14
+ dynamicMethodCustomization.injectOrdering =
15
+ instance.methods?.[originalKey]?.injectOrdering;
16
+ dynamicMethodCustomization.injectPagination =
17
+ instance.methods?.[originalKey]?.injectPagination;
18
+ if (dynamicMethodInfo.keyToMapReplaced.endsWith("PaginatedAndOrdered")) {
19
+ dynamicMethodCustomization.orderPosition = -2;
20
+ dynamicMethodCustomization.paginationPosition = -3;
21
+ dynamicMethodInfo.otherParams.push("pagination");
22
+ dynamicMethodInfo.otherParams.push("order");
23
+ dynamicMethodInfo.keyToMapReplaced = dynamicMethodInfo.keyToMapReplaced.replace("PaginatedAndOrdered", "");
24
+ dynamicMethodInfo.argsCount += 2;
25
+ }
26
+ else if (dynamicMethodInfo.keyToMapReplaced.endsWith("OrderedAndPaginated")) {
27
+ dynamicMethodCustomization.orderPosition = -3;
28
+ dynamicMethodCustomization.paginationPosition = -2;
29
+ dynamicMethodInfo.otherParams.push("order");
30
+ dynamicMethodInfo.otherParams.push("pagination");
31
+ dynamicMethodInfo.keyToMapReplaced = dynamicMethodInfo.keyToMapReplaced.replace("OrderedAndPaginated", "");
32
+ dynamicMethodInfo.argsCount += 2;
33
+ }
34
+ else if (dynamicMethodInfo.keyToMapReplaced.endsWith("Paginated")) {
35
+ dynamicMethodCustomization.paginationPosition = -2;
36
+ dynamicMethodInfo.otherParams.push("pagination");
37
+ dynamicMethodInfo.keyToMapReplaced = dynamicMethodInfo.keyToMapReplaced.replace("Paginated", "");
38
+ dynamicMethodInfo.argsCount++;
39
+ }
40
+ else if (dynamicMethodInfo.keyToMapReplaced.endsWith("Ordered")) {
41
+ dynamicMethodCustomization.orderPosition = -2;
42
+ dynamicMethodInfo.otherParams.push("order");
43
+ dynamicMethodInfo.keyToMapReplaced = dynamicMethodInfo.keyToMapReplaced.replace("Ordered", "");
44
+ dynamicMethodInfo.argsCount++;
45
+ }
46
+ }
47
+ if (!dynamicMethodInfo.ignoreDistinct) {
48
+ const keySplitedDistinct = dynamicMethodInfo.keyToMapReplaced.split("Distinct");
49
+ if (keySplitedDistinct[1]) {
50
+ dynamicMethodCustomization.distinctKeys = keySplitedDistinct[1]
51
+ .split("And")
52
+ .map(uncapitalize_util_1.uncapitalize);
53
+ }
54
+ dynamicMethodInfo.keyToMapReplaced = keySplitedDistinct[0];
55
+ }
56
+ return dynamicMethodCustomization;
57
+ }