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
@@ -0,0 +1,476 @@
1
+ import {
2
+ BuildConfig,
3
+ ClientOrTransaction,
4
+ DbClient,
5
+ DbTransaction,
6
+ DistributiveOmit,
7
+ ExtractNestedCreateInput,
8
+ ExtractNestedUpdateInput,
9
+ IncludeModel,
10
+ ModelUpsertInput,
11
+ OrdenationModel,
12
+ PaginationModel,
13
+ PaginationOptions,
14
+ PrismaModelInputs,
15
+ PrismaModelName,
16
+ RepositoryRelations,
17
+ SeeMode,
18
+ WhereModel,
19
+ } from "./VSRepository.d";
20
+
21
+ /**
22
+ * Flattens a type intersection into a single object,
23
+ * avoiding the TypeScript "union type too complex to represent" error.
24
+ */
25
+ type Simplify<T> = { [K in keyof T]: T[K] } & {};
26
+
27
+ /**
28
+ * Resolves `WRelations` to a concrete relation map, falling back to `{}` when no
29
+ * relations were flagged (mirrors `VSRepository`'s own internal fallback).
30
+ */
31
+ type ResolveRelations<WRelations> = WRelations extends object ? WRelations : {};
32
+
33
+ /**
34
+ * Payload accepted for a relation field mapped as `true` in `WRelations`, used to build
35
+ * the `create`-shaped payload for `save`/`saveList`/`patch`/`patchList`.
36
+ *
37
+ * To-many relations (array fields) resolve to a list of Prisma's own nested `create`
38
+ * payload. To-one relations (object fields) resolve to that same nested `create` payload,
39
+ * but **always also accept `null`** by default — since `WRelations` only flags *which*
40
+ * fields are relations (not their `mode`/`restriction`/`nullable` config), every to-one
41
+ * relation here is treated as unlinkable.
42
+ */
43
+ type DynamicRelationCreatePayload<TField, M extends PrismaModelName, K extends PropertyKey> =
44
+ NonNullable<TField> extends any[]
45
+ ? ExtractNestedCreateInput<M, K>[]
46
+ : NonNullable<TField> extends object
47
+ ? ExtractNestedCreateInput<M, K> | null
48
+ : never;
49
+
50
+ /**
51
+ * Same as `DynamicRelationCreatePayload`, but built from Prisma's nested `update` payload
52
+ * instead of `create` — used by `merge`. To-one relations still accept `null` by default.
53
+ */
54
+ type DynamicRelationUpdatePayload<TField, M extends PrismaModelName, K extends PropertyKey> =
55
+ NonNullable<TField> extends any[]
56
+ ? ExtractNestedUpdateInput<M, K>[]
57
+ : NonNullable<TField> extends object
58
+ ? ExtractNestedUpdateInput<M, K> | null
59
+ : never;
60
+
61
+ /**
62
+ * Distributes over the branches of Prisma's own upsert/create union for `UName`, replacing
63
+ * every field flagged in `TRelations` with `DynamicRelationCreatePayload`.
64
+ */
65
+ type DynamicTransformCreatePayload<U, T, M extends PrismaModelName, TRelations> = Omit<
66
+ U,
67
+ keyof TRelations
68
+ > & {
69
+ // Fields that are REQUIRED in this specific branch of the Prisma union
70
+ [K in Extract<keyof TRelations, keyof U> as {} extends Pick<U, K>
71
+ ? never
72
+ : K]: K extends keyof T ? DynamicRelationCreatePayload<T[K], M, K> : never;
73
+ } & {
74
+ // Fields that are OPTIONAL in this branch or do not originally belong to it
75
+ [K in keyof TRelations as K extends keyof U
76
+ ? {} extends Pick<U, K>
77
+ ? K
78
+ : never
79
+ : K]?: K extends keyof T ? DynamicRelationCreatePayload<T[K], M, K> : never;
80
+ };
81
+
82
+ /**
83
+ * Payload accepted by the `save`/`saveList` methods.
84
+ *
85
+ * Built directly from Prisma's own upsert/create input for `UName`, exactly like
86
+ * `VSRepository`'s `save`: fields flagged as relations via `WRelations` are resolved
87
+ * into their nested `create` payload shape instead of `TEntity`'s own shape (to-one
88
+ * relations also accept `null` by default); every other field keeps Prisma's own
89
+ * validated create input shape.
90
+ */
91
+ export type DynamicSaveInput<TEntity, UName extends PrismaModelName, WRelations = undefined> =
92
+ ModelUpsertInput<UName> extends infer U
93
+ ? U extends any
94
+ ? Simplify<
95
+ DynamicTransformCreatePayload<U, TEntity, UName, ResolveRelations<WRelations>>
96
+ >
97
+ : never
98
+ : never;
99
+
100
+ /**
101
+ * Payload accepted by the `patch`/`patchList` methods.
102
+ *
103
+ * Built from Prisma's own `update` input for `UName` (so every field is already
104
+ * optional); fields flagged as relations via `WRelations` are resolved into their
105
+ * nested `create` payload shape, the same way as in `DynamicSaveInput` (to-one
106
+ * relations also accept `null` by default).
107
+ */
108
+ export type DynamicPatchInput<
109
+ TEntity,
110
+ UName extends PrismaModelName,
111
+ WRelations = undefined,
112
+ > = Simplify<
113
+ DistributiveOmit<
114
+ PrismaModelInputs<UName>["updateInput"],
115
+ keyof ResolveRelations<WRelations>
116
+ > & {
117
+ [K in Extract<
118
+ keyof ResolveRelations<WRelations>,
119
+ keyof TEntity
120
+ >]?: DynamicRelationCreatePayload<TEntity[K], UName, K>;
121
+ }
122
+ >;
123
+
124
+ /**
125
+ * Payload accepted by the `merge` method.
126
+ *
127
+ * Built from Prisma's own `update` input for `UName` (so every field is already
128
+ * optional); fields flagged as relations via `WRelations` are resolved into their
129
+ * nested `update` payload shape (to-one relations also accept `null` by default).
130
+ */
131
+ export type DynamicMergeInput<
132
+ TEntity,
133
+ UName extends PrismaModelName,
134
+ WRelations = undefined,
135
+ > = Simplify<
136
+ DistributiveOmit<
137
+ PrismaModelInputs<UName>["updateInput"],
138
+ keyof ResolveRelations<WRelations>
139
+ > & {
140
+ [K in Extract<
141
+ keyof ResolveRelations<WRelations>,
142
+ keyof TEntity
143
+ >]?: DynamicRelationUpdatePayload<TEntity[K], UName, K>;
144
+ }
145
+ >;
146
+
147
+ /**
148
+ * Base options accepted by most `DynamicRepository` methods.
149
+ */
150
+ export type DynamicMethodOptions<TName extends PrismaModelName = PrismaModelName> = {
151
+ /** Database client or transaction to use for this operation. */
152
+ db?: ClientOrTransaction;
153
+
154
+ /**
155
+ * Controls visibility of soft-deleted records.
156
+ * Only takes effect if `softRemovekName` is configured.
157
+ */
158
+ see?: SeeMode;
159
+
160
+ /** Raw Prisma `include`. */
161
+ include?: IncludeModel<TName>;
162
+ };
163
+
164
+ /**
165
+ * Configuration for an individual base method exposed by `DynamicRepository`.
166
+ *
167
+ * Unlike `VSRepository`'s `BuildConfig`, this configuration does not accept
168
+ * `active` (base methods are always available) nor `defaultSelect`
169
+ * (`DynamicRepository` has no select models).
170
+ */
171
+ type StrippedBaseMethods<TSelectKeys extends PropertyKey = string> = {
172
+ [K in keyof NonNullable<BuildConfig<TSelectKeys>["baseMethods"]>]: Omit<
173
+ NonNullable<NonNullable<BuildConfig<TSelectKeys>["baseMethods"]>[K]>,
174
+ "active" | "defaultSelect"
175
+ >;
176
+ };
177
+
178
+ /**
179
+ * Configuration applied during the construction of a `DynamicRepository`.
180
+ *
181
+ * Equivalent to `VSRepository`'s `BuildConfig`, but without `freeze`
182
+ * (no longer configurable) and without `active`/`defaultSelect` on each
183
+ * base method (base methods are always active and there are no select models).
184
+ */
185
+ export type DynamicRepositoryBuildConfig = Omit<BuildConfig, "freeze" | "baseMethods"> & {
186
+ /** Customizes the behavior of the automatic base methods. */
187
+ baseMethods?: StrippedBaseMethods;
188
+ };
189
+
190
+ /**
191
+ * Configuration used to construct a `DynamicRepository`.
192
+ *
193
+ * @template T Type of the entity managed by the repository.
194
+ * @template U Prisma model name.
195
+ */
196
+ export interface DynamicRepositoryConstructorConfig<T, U extends PrismaModelName> {
197
+ /**
198
+ * Name of the table mapped by Prisma (usually uncapitalized).
199
+ */
200
+ tableName: Uncapitalize<U>;
201
+
202
+ /**
203
+ * Name of the field that represents the entity's primary key (Primary Key).
204
+ */
205
+ pkName: keyof T;
206
+
207
+ /**
208
+ * Name of the `DateTime` field used for soft-delete.
209
+ *
210
+ * When configured, enables the `softRemove`, `softRemoveList`, `restore`, and `restoreList` methods.
211
+ * The field **must** be of type `DateTime` in the Prisma schema — VSRepository validates this during `build`.
212
+ */
213
+ softRemovekName?: keyof T;
214
+
215
+ /**
216
+ * Defines global filters that will be automatically applied to all repository queries.
217
+ * Useful for tenant isolation (multi-tenancy) or base restrictions (e.g., `isActive: true`).
218
+ */
219
+ requiredWhere?: WhereModel<U>;
220
+
221
+ /**
222
+ * Default ordering automatically injected into all queries that accept `orderBy`,
223
+ * unless the method already has `injectOrdenation` configured or uses the `Ordered` suffix.
224
+ *
225
+ * Useful for ensuring a consistent sort order across the repository without repeating
226
+ * the `order` argument on every call.
227
+ */
228
+ defaultOrdenation?: OrdenationModel<U>;
229
+
230
+ /**
231
+ * Configures automatic relation management.
232
+ * When configured, allows the `save`, `saveList`, `patch`, and `patchList` methods
233
+ * to automatically handle linking, creation, or cascading deletion of related records.
234
+ */
235
+ relations?: RepositoryRelations<T>;
236
+
237
+ /**
238
+ * Customizes the behavior of the automatic base methods when the repository is built.
239
+ */
240
+ build?: DynamicRepositoryBuildConfig;
241
+ }
242
+
243
+ /**
244
+ * Base repository built from a fixed configuration, exposing a complete set of
245
+ * ready-to-use CRUD and soft-delete methods around a Prisma model.
246
+ *
247
+ * @template TEntity Type of the entity managed by the repository.
248
+ * @template UName Prisma model name.
249
+ * @template VPKType Type of the entity's primary key value.
250
+ * @template WRelations Keys of `TEntity` configured as relations (flags only, `true`
251
+ * per relation field). The actual relation behavior (`mode`, `restriction`, `nullable`)
252
+ * still comes from `relations` in the constructor config; `WRelations` here only tells
253
+ * `DynamicSaveInput`/`DynamicPatchInput`/`DynamicMergeInput` which fields to resolve
254
+ * into their nested Prisma create/update payload shape instead of `TEntity`'s own shape.
255
+ */
256
+ export declare abstract class DynamicRepository<
257
+ TEntity extends object,
258
+ UName extends PrismaModelName,
259
+ VPKType,
260
+ WRelations extends Partial<Record<keyof TEntity, true>> | undefined = undefined,
261
+ > {
262
+ /**
263
+ * Creates a configured instance of `DynamicRepository`.
264
+ */
265
+ constructor(prisma: DbClient, config: DynamicRepositoryConstructorConfig<TEntity, UName>);
266
+
267
+ /**
268
+ * The Prisma Client instance passed to constructor.
269
+ */
270
+ readonly prisma: DbClient;
271
+
272
+ /** Fetches a record by its primary key (PK). */
273
+ get(pk: VPKType, options?: DynamicMethodOptions<UName>): Promise<TEntity | null>;
274
+
275
+ /** Fetches a record by PK and throws `VSRepoRuntimeError` if not found. */
276
+ getOrThrow(pk: VPKType, options?: DynamicMethodOptions<UName>): Promise<TEntity>;
277
+
278
+ /** Fetches multiple records by a list of primary keys (PKs). */
279
+ getList(pks: VPKType[], options?: DynamicMethodOptions<UName>): Promise<TEntity[]>;
280
+
281
+ /** Deletes a record identified by its primary key (PK). */
282
+ remove(pk: VPKType, options?: DynamicMethodOptions<UName>): Promise<TEntity>;
283
+
284
+ /** Inserts or updates (upsert) a record. */
285
+ save(
286
+ obj: DynamicSaveInput<TEntity, UName, WRelations>,
287
+ options?: DynamicMethodOptions<UName>,
288
+ ): Promise<TEntity>;
289
+
290
+ /** Saves an array of objects in a single automatic transaction. */
291
+ saveList(
292
+ objs: DynamicSaveInput<TEntity, UName, WRelations>[],
293
+ options?: Omit<DynamicMethodOptions<UName>, "include"> & {
294
+ /** Transaction client to use for this operation. */
295
+ db?: DbTransaction;
296
+ },
297
+ ): Promise<TEntity[]>;
298
+
299
+ /** Partially updates (patch) an existing record by its primary key (PK). */
300
+ patch(
301
+ pk: VPKType,
302
+ obj: DynamicPatchInput<TEntity, UName, WRelations>,
303
+ options?: DynamicMethodOptions<UName>,
304
+ ): Promise<TEntity>;
305
+
306
+ /** Partially updates multiple records via `[pk, obj]` tuples in an automatic transaction. */
307
+ patchList(
308
+ tuples: [pk: VPKType, obj: DynamicPatchInput<TEntity, UName, WRelations>][],
309
+ options?: Omit<DynamicMethodOptions<UName>, "include"> & {
310
+ /** Transaction client to use for this operation. */
311
+ db?: DbTransaction;
312
+ },
313
+ ): Promise<TEntity[]>;
314
+
315
+ /** Fetches a record by PK and deep-merges it with the provided object **in memory**. */
316
+ merge(
317
+ pk: VPKType,
318
+ obj: DynamicMergeInput<TEntity, UName, WRelations>,
319
+ options?: DynamicMethodOptions<UName>,
320
+ ): Promise<TEntity | null>;
321
+
322
+ /** Deletes multiple records by their primary keys. */
323
+ removeList(
324
+ pks: VPKType[],
325
+ options?: Omit<DynamicMethodOptions<UName>, "include">,
326
+ ): Promise<{ count: number }>;
327
+
328
+ /** Fetches all records (respects `requiredWhere` when set). */
329
+ getAll(
330
+ options?: DynamicMethodOptions<UName> & {
331
+ /** Pagination options for the query. */
332
+ pagination?: PaginationOptions;
333
+ /**
334
+ * Ordering to apply to the query.
335
+ * When omitted and `defaultOrdenation` is configured on the repository,
336
+ * the default ordering is applied automatically.
337
+ */
338
+ order?: OrdenationModel<UName>;
339
+ },
340
+ ): Promise<TEntity[]>;
341
+
342
+ /** Returns the total number of records. */
343
+ total(options?: Omit<DynamicMethodOptions<UName>, "include">): Promise<number>;
344
+
345
+ /** Checks whether a record exists by its primary key (PK). */
346
+ has(pk: VPKType, options?: Omit<DynamicMethodOptions<UName>, "include">): Promise<boolean>;
347
+
348
+ /** Marks a record as deleted (soft-delete). */
349
+ softRemove(pk: VPKType, options?: Omit<DynamicMethodOptions<UName>, "see">): Promise<TEntity>;
350
+
351
+ /** Marks multiple records as deleted (soft-delete) in batch. */
352
+ softRemoveList(
353
+ pks: VPKType[],
354
+ options?: Omit<DynamicMethodOptions<UName>, "see" | "include">,
355
+ ): Promise<{ count: number }>;
356
+
357
+ /** Restores a record previously marked as deleted (soft-delete). */
358
+ restore(pk: VPKType, options?: Omit<DynamicMethodOptions<UName>, "see">): Promise<TEntity>;
359
+
360
+ /** Restores multiple records previously marked as deleted (soft-delete) in batch. */
361
+ restoreList(
362
+ pks: VPKType[],
363
+ options?: Omit<DynamicMethodOptions<UName>, "see" | "include">,
364
+ ): Promise<{ count: number }>;
365
+ }
366
+
367
+ export type DynamicMethodConfig<M extends PrismaModelName = PrismaModelName> = {
368
+ /** Redirects the logic to another valid method pattern. */
369
+ proxyTo?: string;
370
+
371
+ /** Controls whether the method combines (`extending`) or overwrites (`overwrite`) the `requiredWhere`. */
372
+ whereType?: "overwrite" | "extending";
373
+
374
+ /** Adds an extra `where` on top of `requiredWhere`. */
375
+ pushWhere?: WhereModel<M>;
376
+
377
+ /**
378
+ * Defines whether the method returns a single item (`one`) or a list (`list`).
379
+ * @deprecated Use `findOneBy` if you want to return a single result.
380
+ */
381
+ fbMode?: "one" | "list";
382
+
383
+ /** Injects a fixed ordering automatically into the query. */
384
+ injectOrdenation?: OrdenationModel<M>;
385
+
386
+ /** Injects a fixed pagination automatically into the query. */
387
+ injectPagination?: PaginationModel<M>;
388
+ };
389
+
390
+ /**
391
+ * Property decorator used to declare a dynamic method on a `DynamicRepository` subclass.
392
+ *
393
+ * Applied to a `declare` class field whose name follows one of the supported method
394
+ * patterns (e.g. `findByEmail`, `findManyByStatusPaginated`); the method's behavior and
395
+ * return type are inferred from the field name, optionally adjusted via `config`.
396
+ *
397
+ * @template M Prisma model name the decorated method operates on.
398
+ *
399
+ * @example
400
+ * ```typescript
401
+ * class UserRepository extends DynamicRepository<User, "User", string> {
402
+ * `@DynamicMethod()`
403
+ * declare findOneByEmail: (email: string) => Promise<User | null>;
404
+ *
405
+ * @DynamicMethod<"User">({ injectOrdenation: { createdAt: "desc" } })
406
+ * declare findByAge: (email: number) => Promise<User[]>;
407
+ * }
408
+ * ```
409
+ */
410
+ export declare function DynamicMethod<M extends PrismaModelName = PrismaModelName>(
411
+ config?: DynamicMethodConfig<M>,
412
+ ): PropertyDecorator;
413
+
414
+ /**
415
+ * Single argument accepted by a method declared with `@QueryMethod`.
416
+ *
417
+ * `args` are injected positionally into the raw SQL statement (`$1`, `$2`, ...),
418
+ * exactly like Prisma's `$queryRawUnsafe`/`$executeRawUnsafe` parameters — this is
419
+ * what allows safe parameter injection instead of string-concatenating values into
420
+ * the SQL text.
421
+ *
422
+ * @template T Tuple type of the positional SQL parameters, e.g. `[email: string]`.
423
+ *
424
+ * @example
425
+ * ```typescript
426
+ * declare findByEmail: (arg: QueryMethodArg<[email: string]>) => Promise<User[]>;
427
+ * ```
428
+ */
429
+ export type QueryMethodArg<T extends Array<any>> = {
430
+ /** Positional parameters injected into the SQL placeholders (`$1`, `$2`, ...). */
431
+ args: T;
432
+ /** Transaction client to run this query in, instead of the repository's default client. */
433
+ db?: ClientOrTransaction;
434
+ };
435
+
436
+ /**
437
+ * Options accepted by the `@QueryMethod` decorator.
438
+ */
439
+ export type QueryMethodOptions = {
440
+ /**
441
+ * When `true`, the SQL is executed with `$executeRawUnsafe` (INSERT/UPDATE/DELETE)
442
+ * and the decorated method must resolve to `number` (the count of affected rows).
443
+ * When `false`/omitted, the SQL is executed with `$queryRawUnsafe` and the method
444
+ * resolves to whatever return type you declare on the field.
445
+ *
446
+ * @default false
447
+ */
448
+ modifying?: boolean;
449
+ };
450
+
451
+ /**
452
+ * Property decorator used to declare a **raw SQL query method** on a `DynamicRepository`
453
+ * subclass, bypassing name-based method parsing entirely.
454
+ *
455
+ * Applied to a `declare` class field, it executes `value` directly through Prisma
456
+ * (`$queryRawUnsafe` or `$executeRawUnsafe`, depending on `options.modifying`), with
457
+ * parameters injected positionally via `QueryMethodArg["args"]`. Since the SQL result
458
+ * isn't statically known, the field's own declared function type is what determines
459
+ * the method's return type — for `modifying: true` it must always resolve to `number`.
460
+ *
461
+ * @param value Raw SQL statement to execute. Use `$1`, `$2`, ... placeholders for the
462
+ * values that will be passed via `args` — never interpolate values directly into `value`.
463
+ * @param options Optional configuration; set `modifying: true` for `INSERT`/`UPDATE`/`DELETE` statements.
464
+ *
465
+ * @example
466
+ * ```typescript
467
+ * class UserRepository extends DynamicRepository<User, "User", string> {
468
+ * @QueryMethod('SELECT * FROM "user" WHERE email = $1')
469
+ * declare findByEmailRaw: (arg: QueryMethodArg<[email: string]>) => Promise<User[]>;
470
+ *
471
+ * @QueryMethod('UPDATE "user" SET active = true WHERE id = $1', { modifying: true })
472
+ * declare activateUser: (arg: QueryMethodArg<[id: string]>) => Promise<number>;
473
+ * }
474
+ * ```
475
+ */
476
+ export declare function QueryMethod(value: string, options?: QueryMethodOptions): PropertyDecorator;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DynamicRepository = exports.QueryMethod = exports.DynamicMethod = void 0;
4
+ const dynamic_methods_metadata_resolve_1 = require("./internal/resolvers/dynamic-methods-metadata.resolve");
5
+ const build_config_validate_1 = require("./internal/validation/build-config.validate");
6
+ const is_object_validate_1 = require("./internal/validation/is-object.validate");
7
+ const VSRepository_1 = require("./VSRepository");
8
+ require("reflect-metadata");
9
+ var dynamic_method_decorator_1 = require("./internal/decorators/dynamic-method.decorator");
10
+ Object.defineProperty(exports, "DynamicMethod", { enumerable: true, get: function () { return dynamic_method_decorator_1.DynamicMethod; } });
11
+ var query_method_decorator_1 = require("./internal/decorators/query-method.decorator");
12
+ Object.defineProperty(exports, "QueryMethod", { enumerable: true, get: function () { return query_method_decorator_1.QueryMethod; } });
13
+ class DynamicRepository extends VSRepository_1.VSRepository {
14
+ constructor(prisma, config) {
15
+ if (!(0, is_object_validate_1.isObject)(config)) {
16
+ throw new VSRepository_1.VSRepoConfigError(`[VSRepository] (unknown: config) 'config' must be a valid object`);
17
+ }
18
+ const { build: buildConfig = {}, ...constructorConfig } = config;
19
+ super(constructorConfig);
20
+ const dynamicMethodsMetadata = (0, dynamic_methods_metadata_resolve_1.resolveDynamicMethodsMetadata)(this.constructor.prototype);
21
+ this.methods = dynamicMethodsMetadata;
22
+ const buildConfigValidated = (0, build_config_validate_1.validateBuildConfig)(buildConfig, this);
23
+ this.build(prisma, { ...buildConfigValidated, freeze: false }, this);
24
+ }
25
+ }
26
+ exports.DynamicRepository = DynamicRepository;
@@ -1,54 +1,63 @@
1
- /**
2
- * Literal types representing the internal error codes of the library.
3
- */
4
- export type VSRepoErrorType =
5
- | 'VSREPO_CONFIG'
6
- | 'VSREPO_BUILD'
7
- | 'VSREPO_EXTEND'
8
- | 'VSREPO_RUNTIME';
9
-
10
- /**
11
- * Base class for all errors thrown by the VSRepository.
12
- */
13
- export declare abstract class VSRepoError extends Error {
14
- /** Internal code used to identify the error category. */
15
- abstract readonly type: VSRepoErrorType;
16
-
17
- constructor(message: string, type: VSRepoErrorType);
18
- }
19
-
20
- /**
21
- * Thrown when an invalid configuration or a configuration inconsistency
22
- * is detected before or during repository initialization.
23
- */
24
- export declare class VSRepoConfigError extends VSRepoError {
25
- readonly type: 'VSREPO_CONFIG';
26
- constructor(message: string);
27
- }
28
-
29
- /**
30
- * Thrown when the Prisma instance injection fails or when the
31
- * build configuration is incorrect in the `.build()`.
32
- */
33
- export declare class VSRepoBuildError extends VSRepoError {
34
- readonly type: 'VSREPO_BUILD';
35
- constructor(message: string);
36
- }
37
-
38
- /**
39
- * Thrown when an error occurs while injecting new methods into the repository
40
- * via `.extend()`.
41
- */
42
- export declare class VSRepoExtendError extends VSRepoError {
43
- readonly type: 'VSREPO_EXTEND';
44
- constructor(message: string);
45
- }
46
-
47
- /**
48
- * Thrown when dynamic operations fail at runtime, such as
49
- * when invalid arguments are passed to methods.
50
- */
51
- export declare class VSRepoRuntimeError extends VSRepoError {
52
- readonly type: 'VSREPO_RUNTIME';
53
- constructor(message: string, code: string);
54
- }
1
+ /**
2
+ * Literal types representing the internal error codes of the library.
3
+ */
4
+ export type VSRepoErrorType =
5
+ | 'VSREPO_CONFIG'
6
+ | 'VSREPO_BUILD'
7
+ | 'VSREPO_EXTEND'
8
+ | 'VSREPO_RUNTIME'
9
+ | 'VSREPO_DECORATOR';
10
+
11
+ /**
12
+ * Base class for all errors thrown by the VSRepository.
13
+ */
14
+ export declare abstract class VSRepoError extends Error {
15
+ /** Internal code used to identify the error category. */
16
+ abstract readonly type: VSRepoErrorType;
17
+
18
+ constructor(message: string, type: VSRepoErrorType);
19
+ }
20
+
21
+ /**
22
+ * Thrown when an invalid configuration or a configuration inconsistency
23
+ * is detected before or during repository initialization.
24
+ */
25
+ export declare class VSRepoConfigError extends VSRepoError {
26
+ readonly type: 'VSREPO_CONFIG';
27
+ constructor(message: string);
28
+ }
29
+
30
+ /**
31
+ * Thrown when the Prisma instance injection fails or when the
32
+ * build configuration is incorrect in the `.build()`.
33
+ */
34
+ export declare class VSRepoBuildError extends VSRepoError {
35
+ readonly type: 'VSREPO_BUILD';
36
+ constructor(message: string);
37
+ }
38
+
39
+ /**
40
+ * Thrown when an error occurs while injecting new methods into the repository
41
+ * via `.extend()`.
42
+ */
43
+ export declare class VSRepoExtendError extends VSRepoError {
44
+ readonly type: 'VSREPO_EXTEND';
45
+ constructor(message: string);
46
+ }
47
+
48
+ /**
49
+ * Thrown when invalid arguments are passed to a decorator.
50
+ */
51
+ export declare class VSRepoDecoratorError extends VSRepoError {
52
+ readonly type: 'VSREPO_DECORATOR';
53
+ constructor(message: string);
54
+ }
55
+
56
+ /**
57
+ * Thrown when dynamic operations fail at runtime, such as
58
+ * when invalid arguments are passed to methods.
59
+ */
60
+ export declare class VSRepoRuntimeError extends VSRepoError {
61
+ readonly type: 'VSREPO_RUNTIME';
62
+ constructor(message: string, code: string);
63
+ }