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
@@ -1,1056 +1,1162 @@
1
- import { Prisma, PrismaClient } from '../generated/prisma/client';
2
- import { Decimal, JsonValue } from '@prisma/client/runtime/client';
3
-
4
- /**
5
- * Flattens a type intersection into a single object,
6
- * avoiding the TypeScript "union type too complex to represent" error.
7
- */
8
- type Simplify<T> = { [K in keyof T]: T[K] } & {};
9
-
10
- type WidenField<T> =
11
- T extends bigint ? bigint | number :
12
- T extends Date ? Date | string :
13
- T extends Decimal ? Decimal | string | number :
14
- T extends readonly [infer U, infer V] ? [WidenField<U>, WidenField<V>] :
15
- T extends Array<infer U> ? WidenField<U>[] :
16
- T;
17
-
18
- /**
19
- * Full Prisma Client instance used to build repositories.
20
- */
21
- export type DbClient = PrismaClient;
22
-
23
- /**
24
- * Prisma transactional client returned by `prisma.$transaction`.
25
- */
26
- export type DbTransaction = Prisma.TransactionClient;
27
-
28
- /**
29
- * Accepts either the main Prisma client or a transaction client.
30
- */
31
- export type ClientOrTransaction = DbClient | DbTransaction;
32
-
33
- export * from './VSRepoError';
34
-
35
- type OrderPattern = {
36
- [key: string]: 'asc' | 'desc' | { _count: 'asc' | 'desc' } | OrderPattern;
37
- };
38
-
39
- /**
40
- * Pagination options accepted by methods with the `Paginated` suffix.
41
- *
42
- * @template TCursor Type of the cursor used by the Prisma model.
43
- */
44
- export type PaginationOptions<TCursor = unknown> = {
45
- /** Number of records to skip. */
46
- skip?: number;
47
- /** Maximum number of records to return. */
48
- take?: number;
49
- /** Typed cursor for position-based pagination. */
50
- cursor?: TCursor;
51
- };
52
-
53
- /**
54
- * Ordering accepted by repository methods.
55
- *
56
- * Can be a single ordering or a list of chained orderings.
57
- */
58
- export type OrderOptions = OrderPattern | OrderPattern[];
59
-
60
- /**
61
- * Visibility mode for records with soft-delete.
62
- *
63
- * - `"active"` — returns only non-deleted records (default).
64
- * - `"removed"` — returns only deleted records.
65
- * - `"all"` — returns all records regardless of their status.
66
- */
67
- export type SeeMode = 'active' | 'removed' | 'all';
68
-
69
- type ValidMethodPatterns =
70
- | `existsBy${string}` | `findBy${string}`
71
- | `findUniqueBy${string}` | `findUniqueOrThrowBy${string}`
72
- | `findFirstBy${string}` | `findFirst${string}`
73
- | `findFirstOrThrowBy${string}` | `findFirstOrThrow${string}`
74
- | `findManyBy${string}` | `findMany${string}`
75
- | `createManyAndReturn${string}` | `createMany${string}`
76
- | `create${string}` | `updateManyAndReturnBy${string}` | `updateManyBy${string}`
77
- | `updateBy${string}` | `upsertBy${string}` | `deleteManyBy${string}`
78
- | `deleteBy${string}` | `countBy${string}` | `count${string}` | `countWhere${string}`
79
- | `findWhere${string}` | `findListWhere${string}`
80
- | `existsWhere${string}` | `updateManyWhere${string}` | `deleteManyWhere${string}`
81
- | `findOneWhere${string}` | `findOneBy${string}` | `updateManyAndReturnWhere${string}`
82
- | 'aggregate' | 'groupBy';
83
-
84
- type StripModifier<S extends string> =
85
- S extends `${infer Base}NotStartsWithInsensitive` ? Base :
86
- S extends `${infer Base}StartsWithInsensitive` ? Base :
87
- S extends `${infer Base}NotEndsWithInsensitive` ? Base :
88
- S extends `${infer Base}EndsWithInsensitive` ? Base :
89
- S extends `${infer Base}NotContainsInsensitive` ? Base :
90
- S extends `${infer Base}ContainsInsensitive` ? Base :
91
- S extends `${infer Base}NotInInsensitive` ? Base :
92
- S extends `${infer Base}InInsensitive` ? Base :
93
- S extends `${infer Base}NotInsensitive` ? Base :
94
- S extends `${infer Base}NotStartsWith` ? Base :
95
- S extends `${infer Base}StartsWith` ? Base :
96
- S extends `${infer Base}NotEndsWith` ? Base :
97
- S extends `${infer Base}EndsWith` ? Base :
98
- S extends `${infer Base}NotContains` ? Base :
99
- S extends `${infer Base}Contains` ? Base :
100
- S extends `${infer Base}NotIn` ? Base :
101
- S extends `${infer Base}In` ? Base :
102
- S extends `${infer Base}NotBetween` ? Base :
103
- S extends `${infer Base}Between` ? Base :
104
- S extends `${infer Base}Not` ? Base :
105
- S extends `${infer Base}LessThanEqual` ? Base :
106
- S extends `${infer Base}LessThan` ? Base :
107
- S extends `${infer Base}GreaterThanEqual` ? Base :
108
- S extends `${infer Base}GreaterThan` ? Base :
109
- S extends `${infer Base}Insensitive` ? Base :
110
- S;
111
-
112
- type ExtractFieldName<S extends string> = Uncapitalize<StripModifier<S>>;
113
-
114
- type IsArrayFilter<S extends string> = S extends `${string}${'NotIn' | 'In'}` ? true : false;
115
-
116
- type IsBetweenFilter<S extends string> = S extends `${string}${'NotBetween' | 'Between'}` ? true : false;
117
-
118
- type ParseRelation<S extends string> =
119
- S extends `${infer Rel}Without${infer Rest}` ? [Uncapitalize<Rel>, 'isNot', Rest] :
120
- S extends `${infer Rel}With${infer Rest}` ? [Uncapitalize<Rel>, 'is', Rest] :
121
- S extends `${infer Rel}Some${infer Rest}` ? [Uncapitalize<Rel>, 'some', Rest] :
122
- S extends `${infer Rel}Every${infer Rest}` ? [Uncapitalize<Rel>, 'every', Rest] :
123
- S extends `${infer Rel}None${infer Rest}` ? [Uncapitalize<Rel>, 'none', Rest] : null;
124
-
125
- type GetFieldType<T, S extends string, I> = WidenField<
126
- ExtractFieldName<S> extends infer FieldName
127
- ? FieldName extends keyof T
128
- ? IsArrayFilter<S> extends true
129
- ? T[FieldName][]
130
- : IsBetweenFilter<S> extends true
131
- ? [NonNullable<T[FieldName]>, NonNullable<T[FieldName]>]
132
- : NonNullable<T[FieldName]> extends object | any[]
133
- ? I extends { whereInput: infer W }
134
- ? FieldName extends keyof NonNullable<W> ? Exclude<NonNullable<W>[FieldName], undefined> : T[FieldName]
135
- : T[FieldName]
136
- : T[FieldName]
137
- : ParseRelation<S> extends [infer Rel extends keyof T, any, infer Rest extends string]
138
- ? GetFieldType<NonNullable<T[Rel]> extends any[] ? NonNullable<T[Rel]>[number] : NonNullable<T[Rel]>, Rest, unknown>
139
- : unknown
140
- : unknown
141
- >;
142
-
143
- type NoArgModifiers = 'IsNull' | 'IsNotNull' | 'IsTrue' | 'IsFalse' | 'None' | 'Some' | 'Every' | 'Without';
144
-
145
- type IsNoArgModifier<S extends string> =
146
- S extends `${string}${'StartsWith' | 'EndsWith'}` ? false :
147
- S extends `${string}${NoArgModifiers | 'With'}` ? true :
148
- false;
149
-
150
- type IsOptional<S extends string> = S extends `${string}Optional` ? true : false;
151
- type StripOptional<S extends string> = S extends `${infer Base}Optional` ? Base : S;
152
-
153
- type MapToContractTypes<T, Arr extends string[], I> =
154
- Arr extends [infer First extends string, ...infer Rest extends string[]]
155
- ? First extends ''
156
- ? MapToContractTypes<T, Rest, I>
157
- : StripOptional<First> extends infer CleanFirst extends string
158
- ? IsNoArgModifier<CleanFirst> extends true
159
- ? MapToContractTypes<T, Rest, I>
160
- : IsOptional<First> extends true
161
- ? [GetFieldType<T, CleanFirst, I> | undefined, ...MapToContractTypes<T, Rest, I>]
162
- : [GetFieldType<T, CleanFirst, I>, ...MapToContractTypes<T, Rest, I>]
163
- : never
164
- : [];
165
-
166
- type SplitAllTokens<S extends string> =
167
- S extends `${infer L}AND${infer R}` ? [...SplitAllTokens<L>, ...SplitAllTokens<R>] :
168
- S extends `${infer L}And${infer R}` ? [...SplitAllTokens<L>, ...SplitAllTokens<R>] :
169
- S extends `${infer L}Or${infer R}` ? [...SplitAllTokens<L>, ...SplitAllTokens<R>] :
170
- S extends '' ? [] :
171
- [S];
172
-
173
- type ExtractFields<T, R extends string, I> =
174
- R extends '' ? []
175
- : FilterNonEmpty<MapToContractTypes<T, SplitAllTokens<R>, I>>;
176
-
177
- type FilterNonEmpty<T extends unknown[]> =
178
- T extends [infer First, ...infer Rest]
179
- ? [First] extends ['']
180
- ? FilterNonEmpty<Rest>
181
- : [First, ...FilterNonEmpty<Rest>]
182
- : [];
183
-
184
- type ResolveReturnType<M extends string, TSelected> =
185
- M extends 'existsBy' | 'existsWhere' ? boolean :
186
- M extends 'createMany' | 'updateManyBy' | 'deleteManyBy' | 'updateManyWhere' | 'deleteManyWhere' ? { count: number } :
187
- M extends 'findMany' | 'createManyAndReturn' | 'updateManyAndReturnBy' | 'updateManyAndReturnWhere' | 'findListWhere' | 'findByList' ? TSelected[] :
188
- M extends 'findUnique' | 'findFirst' | 'findWhere' | 'findByOne' | 'findOneBy' | 'findOneWhere' ? TSelected | null :
189
- M extends 'findUniqueOrThrow' | 'findFirstOrThrow' | 'create' | 'updateBy' | 'upsertBy' | 'deleteBy' ? TSelected :
190
- M extends 'count' | 'countWhere' ? number : never;
191
-
192
- type GetUpdateInput<I> = I extends { updateInput: infer U } ? U : unknown;
193
- type GetCreateInput<I> = I extends { createInput: infer C } ? C : unknown;
194
- type GetCreateManyInput<I> = I extends { createManyInput: infer CM } ? CM : unknown;
195
- type GetUpdateManyInput<I> = I extends { updateManyInput: infer UM } ? UM : unknown;
196
- type GetWhereInput<I> = I extends { whereInput: infer W } ? NonNullable<W> : unknown;
197
- type GetCursorInput<I> = I extends { cursorInput: infer C } ? C : unknown;
198
- type GetOrderByInput<I> = I extends { orderByInput: infer OB } ? NonNullable<OB> : OrderOptions;
199
-
200
- type ExtraArgs<M extends string, R extends string, I> = [
201
- ...(M extends 'upsertBy' ? [update: GetUpdateInput<I>, create: GetCreateInput<I>]
202
- : M extends 'create' ? [data: GetCreateInput<I>]
203
- : M extends 'updateBy' ? [data: GetUpdateInput<I>]
204
- : M extends 'createMany' | 'createManyAndReturn' ? [data: GetCreateManyInput<I>]
205
- : M extends 'updateManyBy' | 'updateManyAndReturnBy' ? [data: GetUpdateManyInput<I>]
206
- : M extends 'findWhere' | 'findListWhere' | 'countWhere' | 'existsWhere' | 'deleteManyWhere' | 'findOneWhere' ? [where: GetWhereInput<I>]
207
- : M extends 'updateManyWhere' | 'updateManyAndReturnWhere' ? [where: GetWhereInput<I>, data: GetUpdateManyInput<I>]
208
- : []),
209
- ...(R extends `${string}PaginatedAndOrdered` ? [pagination: PaginationOptions<GetCursorInput<I>>, order: GetOrderByInput<I>]
210
- : R extends `${string}OrderedAndPaginated` ? [order: GetOrderByInput<I>, pagination: PaginationOptions<GetCursorInput<I>>]
211
- : R extends `${string}Paginated` ? [pagination: PaginationOptions<GetCursorInput<I>>]
212
- : R extends `${string}Ordered` ? [order: GetOrderByInput<I>]
213
- : [])
214
- ];
215
-
216
- type PrismaDelegate<M extends Prisma.ModelName> = Uncapitalize<M> extends keyof DbClient ? DbClient[Uncapitalize<M>] : never;
217
-
218
- type FullModelType<M extends Prisma.ModelName> =
219
- Prisma.Result<PrismaDelegate<M>, {}, 'findMany'> extends Array<infer U> ? U : never;
220
-
221
- type PrecomputedSelects<M extends Prisma.ModelName, SelectModels> = {
222
- [S in keyof SelectModels]: Prisma.Result<PrismaDelegate<M>, { select: SelectModels[S] }, 'findMany'> extends Array<infer U> ? U : never
223
- };
224
-
225
- type PrecomputedIncludes<M extends Prisma.ModelName, IncludeModels> = {
226
- [I in keyof IncludeModels]: Prisma.Result<PrismaDelegate<M>, { include: IncludeModels[I] }, 'findMany'> extends Array<infer U> ? U : never
227
- };
228
-
229
- type SelectedModel<M extends Prisma.ModelName, S, SelectModels, IM = never, IncludeModels = {}> =
230
- [IM] extends [never]
231
- ? [S] extends [false]
232
- ? FullModelType<M>
233
- : [S] extends [never]
234
- ? FullModelType<M>
235
- : [S] extends [keyof SelectModels]
236
- ? PrecomputedSelects<M, SelectModels>[S]
237
- : FullModelType<M>
238
- : IM extends keyof IncludeModels
239
- ? PrecomputedIncludes<M, IncludeModels>[IM]
240
- : FullModelType<M>;
241
-
242
- /**
243
- * Strips the `Distinct{Fields}` suffix used by read methods (e.g. `findManyDistinctIdadeAndCargo`).
244
- * The distinct fields are resolved from the method name at build time, so they never
245
- * become part of the runtime `where` fields extracted by `ExtractFields`.
246
- */
247
- type StripDistinctFields<R extends string> =
248
- R extends `${infer F}Distinct${string}` ? F : R;
249
-
250
- type CleanFields<R extends string> =
251
- R extends `${infer F}PaginatedAndOrdered` ? StripDistinctFields<F> :
252
- R extends `${infer F}OrderedAndPaginated` ? StripDistinctFields<F> :
253
- R extends `${infer F}Paginated` ? StripDistinctFields<F> :
254
- R extends `${infer F}Ordered` ? StripDistinctFields<F> :
255
- R extends `${infer F}SkipDuplicates` ? StripDistinctFields<F> :
256
- StripDistinctFields<R>;
257
-
258
- /**
259
- * Additional options accepted by repository methods.
260
- *
261
- * @template S Available keys in `selectModels`.
262
- * @template IM Available keys in `includeModels`.
263
- */
264
- export type MethodOptions<S, IM extends PropertyKey = never> = {
265
- /** Prisma client or transaction to use for the operation. */
266
- db?: ClientOrTransaction;
267
- /**
268
- * Visibility mode for records with soft-delete.
269
- *
270
- * Only takes effect if `softRemovekName` is configured on the repository.
271
- *
272
- * - `"active"` — returns only non-deleted records (default).
273
- * - `"removed"` — returns only deleted records.
274
- * - `"all"` — returns all records, ignoring deletion status.
275
- */
276
- see?: SeeMode;
277
- } & (
278
- [IM] extends [never]
279
- ? {
280
- /** Select model to apply to the operation. Use `false` to return the full payload. */
281
- selectModel?: S | false;
282
- /** Include model to apply to the operation. Cannot be used together with `selectModel`. */
283
- includeModel?: never;
284
- }
285
- : | { selectModel?: S | false; includeModel?: never }
286
- | { selectModel?: never; includeModel: IM }
287
- );
288
-
289
- /**
290
- * Version of `MethodOptions` derived directly from a configured `VSRepository` instance.
291
- *
292
- * @template TRepo Configured `VSRepository` instance (use `typeof myVSRepo`).
293
- *
294
- * @example
295
- * const userVSRepo = setupVSRepo<User, "user">()(config);
296
- * type Opts = MethodOptionsModel<typeof userVSRepo>;
297
- */
298
- export type MethodOptionsModel<TRepo> =
299
- TRepo extends VSRepository<any, any, infer Config>
300
- ? MethodOptions<keyof ExtractSelectModels<Config> | false, keyof ExtractIncludeModels<Config>>
301
- : never;
302
-
303
- type MethodOptionsWithInclude<
304
- S,
305
- IM extends PropertyKey,
306
- TIncludes,
307
- Excluded extends keyof MethodOptions<S, keyof TIncludes> = never
308
- > = Omit<MethodOptions<S, keyof TIncludes>, Excluded>
309
- & ({ includeModel: IM } | { includeModel?: never });
310
-
311
- type MethodFn<MethodName extends string, T, M extends Prisma.ModelName, R extends string, SelectModels, DefaultSelect extends keyof SelectModels | false, I, IncludeModels> =
312
- <S extends keyof SelectModels | false = DefaultSelect, IM extends keyof IncludeModels = never>(
313
- ...args: [...ExtractFields<T, CleanFields<R>, I>, ...ExtraArgs<MethodName, R, I>, options?: MethodOptionsWithInclude<S, IM, IncludeModels>]
314
- ) => Promise<ResolveReturnType<MethodName, SelectedModel<M, S, SelectModels, IM, IncludeModels>>>;
315
-
316
- type GetMappedMethod<K extends string, MethodConf> =
317
- K extends `findBy${string}` ? (MethodConf extends { fbMode: 'one' } ? 'findByOne' : 'findByList') :
318
- K extends `findOneBy${string}` ? 'findOneBy' :
319
- K extends `existsBy${string}` ? 'existsBy' :
320
- K extends `existsWhere${string}` ? 'existsWhere' :
321
- K extends `findUniqueOrThrowBy${string}` ? 'findUniqueOrThrow' :
322
- K extends `findUniqueBy${string}` ? 'findUnique' :
323
- K extends `findFirstOrThrowBy${string}` | `findFirstOrThrow${string}` ? 'findFirstOrThrow' :
324
- K extends `findFirstBy${string}` | `findFirst${string}` ? 'findFirst' :
325
- K extends `findManyBy${string}` | `findMany${string}` ? 'findMany' :
326
- K extends `createManyAndReturn${string}` ? 'createManyAndReturn' :
327
- K extends `createMany${string}` ? 'createMany' :
328
- K extends `create${string}` ? 'create' :
329
- K extends `updateManyAndReturnBy${string}` ? 'updateManyAndReturnBy' :
330
- K extends `updateManyAndReturnWhere${string}` ? 'updateManyAndReturnWhere' :
331
- K extends `updateManyBy${string}` ? 'updateManyBy' :
332
- K extends `updateManyWhere${string}` ? 'updateManyWhere' :
333
- K extends `updateBy${string}` ? 'updateBy' :
334
- K extends `upsertBy${string}` ? 'upsertBy' :
335
- K extends `deleteManyBy${string}` ? 'deleteManyBy' :
336
- K extends `deleteManyWhere${string}` ? 'deleteManyWhere' :
337
- K extends `deleteBy${string}` ? 'deleteBy' :
338
- K extends `countWhere${string}` ? 'countWhere' :
339
- K extends `countBy${string}` | `count${string}` ? 'count' :
340
- K extends `findListWhere${string}` ? 'findListWhere' :
341
- K extends `findOneWhere${string}` ? 'findOneWhere' :
342
- K extends `findWhere${string}` ? 'findWhere' :
343
- K extends 'aggregate' ? 'aggregate' :
344
- K extends 'groupBy' ? 'groupBy' :
345
- never;
346
-
347
- type ExtractPatternBase<K extends string> =
348
- K extends `${string}By${infer R}` ? R :
349
- K extends `findFirstOrThrow${infer R}` ? R :
350
- K extends `findFirst${infer R}` ? R :
351
- K extends `findMany${infer R}` ? R :
352
- K extends `createManyAndReturn${infer R}` ? R :
353
- K extends `createMany${infer R}` ? R :
354
- K extends `create${infer R}` ? R :
355
- K extends `countWhere${infer R}` ? R :
356
- K extends `count${infer R}` ? R :
357
- K extends `findListWhere${infer R}` ? R :
358
- K extends `findOneWhere${infer R}` ? R :
359
- K extends `findWhere${infer R}` ? R :
360
- K extends `existsWhere${infer R}` ? R :
361
- K extends `updateManyWhere${infer R}` ? R :
362
- K extends `updateManyAndReturnWhere${infer R}` ? R :
363
- K extends `deleteManyWhere${infer R}` ? R : '';
364
-
365
- type MethodFactory<T, M extends Prisma.ModelName, K extends string, SelectModels, DefaultSelect extends keyof SelectModels | false, I, MethodConf, IncludeModels> =
366
- K extends `findWhere${string}`
367
- ? {
368
- /** @deprecated Use findOneWhere instead. */
369
- <S extends keyof SelectModels | false = DefaultSelect, IM extends keyof IncludeModels = never>(...args: [...ExtractFields<T, CleanFields<ExtractPatternBase<K>>, I>, ...ExtraArgs<GetMappedMethod<K, MethodConf>, ExtractPatternBase<K>, I>, options?: MethodOptionsWithInclude<S, IM, IncludeModels>]): Promise<ResolveReturnType<GetMappedMethod<K, MethodConf>, SelectedModel<M, S, SelectModels, IM, IncludeModels>>>;
370
- }
371
- : MethodFn<GetMappedMethod<K, MethodConf>, T, M, ExtractPatternBase<K>, SelectModels, DefaultSelect, I, IncludeModels>;
372
-
373
- type ResolveSelectModel<MethodConf, GlobalConf, SelectModels> =
374
- MethodConf extends { selectModel: infer S } ? (S extends false ? false : S extends keyof SelectModels ? S : never) :
375
- GlobalConf extends { defaultSelectModel: infer D } ? (D extends keyof SelectModels ? D : never) : never;
376
-
377
- type ExtractPkName<T, Config> = Config extends { pkName: infer PK } ? (PK extends keyof T ? PK : never) : never;
378
- type ExtractSelectModels<Config> = Config extends { selectModels: infer SM } ? SM : {};
379
- type ExtractIncludeModels<Config> = Config extends { includeModels: infer IM } ? IM : {};
380
- type ExtractDefaultSelect<Config> = Config extends { defaultSelectModel: infer D } ? D : never;
381
- type ExtractRelations<Config> = Config extends { relations: infer R } ? (R extends object ? R : {}) : {};
382
- type ExtractSoftRemovekName<Config> = Config extends { softRemovekName: infer S } ? S : never;
383
- type ExtractDefaultOrdenation<Config> = Config extends { defaultOrdenation: infer O } ? O : never;
384
-
385
- type AggregateMethod<M extends Prisma.ModelName> = <A extends Prisma.TypeMap['model'][M]['operations']['aggregate']['args']>(
386
- prismaArgs: A,
387
- options?: { db?: ClientOrTransaction }
388
- ) => Promise<Prisma.Result<PrismaDelegate<M>, A, 'aggregate'>>;
389
-
390
- type GroupByMethod<M extends Prisma.ModelName> = <A extends Prisma.TypeMap['model'][M]['operations']['groupBy']['args']>(
391
- prismaArgs: A,
392
- options?: { db?: ClientOrTransaction }
393
- ) => Promise<Prisma.Result<PrismaDelegate<M>, A, 'groupBy'>>;
394
-
395
- type DynamicMethods<T, M extends Prisma.ModelName, Config, I> = Config extends { methods: infer Methods }
396
- ? {
397
- [K in keyof Methods as Methods[K] extends { map: true } ? K : never]: K extends string
398
- ? (Methods[K] extends { proxyTo: infer P extends string } ? P : K) extends infer ResolvedKey
399
- ? ResolvedKey extends 'aggregate'
400
- ? AggregateMethod<M>
401
- : ResolvedKey extends 'groupBy'
402
- ? GroupByMethod<M>
403
- : ResolvedKey extends string
404
- ? MethodFactory<T, M, ResolvedKey, ExtractSelectModels<Config>, ResolveSelectModel<Methods[K], Config, ExtractSelectModels<Config>>, I, Methods[K], ExtractIncludeModels<Config>>
405
- : never
406
- : never
407
- : never;
408
- }
409
- : {};
410
-
411
- /**
412
- * Groups the main Prisma input types derived from a model.
413
- *
414
- * @template M Prisma model name.
415
- */
416
- export type PrismaModelInputs<M extends Prisma.ModelName> = {
417
- /** Type of the `select` argument used in model queries. */
418
- select: Prisma.TypeMap['model'][M]['operations']['findMany']['args']['select'];
419
- /** Type of the `include` argument used in model queries. */
420
- include: Prisma.TypeMap['model'][M]['operations']['findMany']['args']['include'];
421
- /** Type of the `data` used in `create`. */
422
- createInput: Prisma.TypeMap['model'][M]['operations']['create']['args']['data'];
423
- /** Type of the `data` used in `createMany`. */
424
- createManyInput: Prisma.TypeMap['model'][M]['operations']['createMany']['args']['data'];
425
- /** Type of the `data` used in `update`. */
426
- updateInput: Prisma.TypeMap['model'][M]['operations']['update']['args']['data'];
427
- /** Type of the `data` used in `updateMany`. */
428
- updateManyInput: Prisma.TypeMap['model'][M]['operations']['updateMany']['args']['data'];
429
- /** Type of the `where` used in model queries. */
430
- whereInput: Prisma.TypeMap['model'][M]['operations']['findMany']['args']['where'];
431
- /** Type of the `orderBy` used in model queries. */
432
- orderByInput: Prisma.TypeMap['model'][M]['operations']['findMany']['args']['orderBy'];
433
- /** Type of the cursor used in model queries. */
434
- cursorInput: Prisma.TypeMap['model'][M]['operations']['findMany']['args']['cursor'];
435
- /** Type of the `create` payload used in `upsert`. */
436
- upsertCreateInput: Prisma.TypeMap['model'][M]['operations']['upsert']['args']['create'];
437
- /** Type of the `update` payload used in `upsert`. */
438
- upsertUpdateInput: Prisma.TypeMap['model'][M]['operations']['upsert']['args']['update'];
439
- };
440
-
441
- /**
442
- * Type of the `select` object of a Prisma model.
443
- */
444
- export type SelectModel<M extends Prisma.ModelName> = PrismaModelInputs<M>['select'];
445
-
446
- /**
447
- * Map of named, reusable selects for a Prisma model.
448
- */
449
- export type SelectModels<M extends Prisma.ModelName> = Record<string, SelectModel<M>>;
450
-
451
- /**
452
- * Type of the `include` object of a Prisma model.
453
- */
454
- export type IncludeModel<M extends Prisma.ModelName> = PrismaModelInputs<M>['include'];
455
-
456
- /**
457
- * Map of named, reusable includes for a Prisma model.
458
- */
459
- export type IncludeModels<M extends Prisma.ModelName> = Record<string, IncludeModel<M>>;
460
-
461
- /**
462
- * Type of the `where` object of a Prisma model.
463
- */
464
- export type WhereModel<M extends Prisma.ModelName> = PrismaModelInputs<M>['whereInput'];
465
-
466
- /**
467
- * Type of the `orderBy` object of a Prisma model.
468
- */
469
- export type OrdenationModel<M extends Prisma.ModelName> = PrismaModelInputs<M>['orderByInput'];
470
-
471
- /**
472
- * Pagination options with typed cursor for a Prisma model.
473
- */
474
- export type PaginationModel<M extends Prisma.ModelName> = PaginationOptions<PrismaModelInputs<M>['cursorInput']>;
475
-
476
- /**
477
- * Base payload used to create a record in the model's `save`/`upsert`.
478
- */
479
- export type ModelUpsertInput<M extends Prisma.ModelName> = PrismaModelInputs<M>['upsertCreateInput'];
480
-
481
- /**
482
- * Configuration for a dynamic method defined in `methods`.
483
- *
484
- * @template M Prisma model name.
485
- * @template SelectModels Map of select models available in the repository.
486
- */
487
- export type MethodConfig<M extends Prisma.ModelName, SelectModels = any> = {
488
- /** Defines whether the method will be exposed on the repository. */
489
- readonly map: boolean;
490
- /** Overrides `defaultSelectModel` for this method only. */
491
- readonly selectModel?: string | false;
492
- /** Controls whether the method combines (`extending`) or overwrites (`overwrite`) the `requiredWhere`. */
493
- readonly whereType?: 'overwrite' | 'extending';
494
- /** Redirects the logic to another valid method pattern. */
495
- readonly proxyTo?: ValidMethodPatterns;
496
- /** Adds an extra `where` on top of `requiredWhere`. */
497
- readonly pushWhere?: WhereModel<M>;
498
- /** * Defines whether `findBy` returns a single item (`one`) or a list (`list`).
499
- * @deprecated Use `findOneBy` if you want to return a single result.
500
- */
501
- readonly fbMode?: 'one' | 'list';
502
- /** Injects a fixed ordering automatically into the query. */
503
- readonly injectOrdenation?: OrdenationModel<M>;
504
- /** Injects a fixed pagination automatically into the query. */
505
- readonly injectPagination?: PaginationModel<M>;
506
- };
507
-
508
- type BaseMethodConfig<TSelectKeys extends PropertyKey = string> = {
509
- /** Enables or disables the base method in the `build`. */
510
- active?: boolean;
511
- /** Default select model used by the base method. */
512
- defaultSelect?: TSelectKeys;
513
- /** Ignores the `requiredWhere`. */
514
- ignoreRequiredWhere?: boolean;
515
- };
516
-
517
- /**
518
- * Configuration applied during `.build(prisma, config?)`.
519
- *
520
- * @template TSelectKeys Valid keys of `selectModels`.
521
- */
522
- export type BuildConfig<TSelectKeys extends PropertyKey = string> = {
523
- /**
524
- * Freezes the final repository object with `Object.freeze`.
525
- * @deprecated No longer has any practical effect in the next version — freeze will be always applied.
526
- */
527
- freeze?: boolean;
528
- /** Prints internal working logs to the console. */
529
- showWorking?: boolean;
530
- /** Customizes the behavior of the automatic base methods. */
531
- baseMethods?: {
532
- /** Configuration for the `get` method. */
533
- get?: BaseMethodConfig<TSelectKeys>;
534
- /** Configuration for the `getOrThrow` method. */
535
- getOrThrow?: BaseMethodConfig<TSelectKeys>;
536
- /** Configuration for the `getList` method (fetch by list of PKs). */
537
- getList?: BaseMethodConfig<TSelectKeys>;
538
- /** Configuration for the `remove` method. */
539
- remove?: BaseMethodConfig<TSelectKeys>;
540
- /** Configuration for the `save` method. */
541
- save?: BaseMethodConfig<TSelectKeys>;
542
- /** Configuration for the `saveList` method (batch save via transaction). */
543
- saveList?: BaseMethodConfig<TSelectKeys>;
544
- /** Configuration for the `patch` method. */
545
- patch?: BaseMethodConfig<TSelectKeys>;
546
- /** Configuration for the `patchList` method (batch update via transaction). */
547
- patchList?: BaseMethodConfig<TSelectKeys>;
548
- /** Configuration for the `merge` method. */
549
- merge?: BaseMethodConfig<TSelectKeys>;
550
- /** Configuration for the `removeList` method (batch deletion). Does not accept select. */
551
- removeList?: Omit<BaseMethodConfig<TSelectKeys>, 'defaultSelect'>;
552
- /** Configuration for the `getAll` method (full listing). */
553
- getAll?: BaseMethodConfig<TSelectKeys>;
554
- /** Configuration for the `total` method (count). Does not accept select. */
555
- total?: Omit<BaseMethodConfig<TSelectKeys>, 'defaultSelect'>;
556
- /** Configuration for the `has` method (existence check). Does not accept select. */
557
- has?: Omit<BaseMethodConfig<TSelectKeys>, 'defaultSelect'>;
558
- /** Configuration for the `softRemove` method. Only available if `softRemovekName` is configured. */
559
- softRemove?: BaseMethodConfig<TSelectKeys>;
560
- /** Configuration for the `softRemoveList` method. Does not accept select. Only available if `softRemovekName` is configured. */
561
- softRemoveList?: Omit<BaseMethodConfig<TSelectKeys>, 'defaultSelect'>;
562
- /** Configuration for the `restore` method. Only available if `softRemovekName` is configured. */
563
- restore?: BaseMethodConfig<TSelectKeys>;
564
- /** Configuration for the `restoreList` method. Does not accept select. Only available if `softRemovekName` is configured. */
565
- restoreList?: Omit<BaseMethodConfig<TSelectKeys>, 'defaultSelect'>;
566
- };
567
- };
568
-
569
- type ResolveMethodDefaultSelect<Config, C, Method extends keyof NonNullable<BuildConfig['baseMethods']>, TSelects = ExtractSelectModels<Config>> =
570
- C extends { baseMethods?: { [_ in Method]?: { defaultSelect?: infer D } } }
571
- ? D extends keyof TSelects
572
- ? D
573
- : ExtractDefaultSelect<Config> extends keyof TSelects
574
- ? ExtractDefaultSelect<Config>
575
- : false
576
- : ExtractDefaultSelect<Config> extends keyof TSelects
577
- ? ExtractDefaultSelect<Config>
578
- : false;
579
-
580
- type ResolveCurrentReturn<M extends Prisma.ModelName, Models, S, D, IM = never, Includes = {}> =
581
- [IM] extends [never]
582
- ? [S] extends [false]
583
- ? FullModelType<M>
584
- : [S] extends [never]
585
- ? ([D] extends [never] ? FullModelType<M> : SelectedModel<M, D, Models>)
586
- : SelectedModel<M, S, Models>
587
- : IM extends keyof Includes
588
- ? PrecomputedIncludes<M, Includes>[IM]
589
- : FullModelType<M>;
590
-
591
- // ─── helpers reused within the mapped type ───────────────────────────────────
592
- // ─── relation payload types ──────────────────────────────────────────────────
593
-
594
- /**
595
- * Distributive version of `Omit`, preserving unions when removing properties.
596
- */
597
- type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
598
- type ExtractUnionProp<T, K extends PropertyKey> = T extends any ? (K extends keyof T ? T[K] : never) : never;
599
-
600
- type ExtractNestedCreateInput<M extends Prisma.ModelName, K extends PropertyKey> =
601
- NonNullable<ExtractUnionProp<PrismaModelInputs<M>['createInput'], K>> extends { create?: infer C }
602
- ? Exclude<C, any[]>
603
- : never;
604
-
605
- type RelationPayload<TField, TRelationConfig, M extends Prisma.ModelName, K extends PropertyKey> = NonNullable<TField> extends any[]
606
- ? ExtractNestedCreateInput<M, K>[]
607
- : NonNullable<TField> extends object
608
- ? ExtractNestedCreateInput<M, K> | (TRelationConfig extends { mode: 'oto'; restriction: 'set' } | { mode: 'mto'; nullable: true } | { mode: 'mto'; nullAble: true } ? null : never)
609
- : never;
610
-
611
- type TransformCreatePayload<U, T, M extends Prisma.ModelName, TRelations> =
612
- Omit<U, keyof TRelations> &
613
- {
614
- // Fields that are REQUIRED in this specific branch of the Prisma union
615
- [K in Extract<keyof TRelations, keyof U> as {} extends Pick<U, K> ? never : K]:
616
- K extends keyof T ? RelationPayload<T[K], TRelations[K], M, K> : never;
617
- } &
618
- {
619
- // Fields that are OPTIONAL in this branch or do not originally belong to it
620
- [K in keyof TRelations as K extends keyof U ? ({} extends Pick<U, K> ? K : never) : K]?:
621
- K extends keyof T ? RelationPayload<T[K], TRelations[K], M, K> : never;
622
- };
623
-
624
- /**
625
- * Payload accepted by `save` when the repository has configured relations.
626
- */
627
- type UpsertWithRelations<T, M extends Prisma.ModelName, TRelations> =
628
- ModelUpsertInput<M> extends infer U
629
- ? U extends any
630
- ? Simplify<TransformCreatePayload<U, T, M, TRelations>>
631
- : never
632
- : never;
633
-
634
- type CleanNestedInput<T> = T extends any
635
- ? T extends { data: infer D }
636
- ? CleanNestedInput<Exclude<D, any[]>>
637
- : Omit<T, 'where' | 'data'>
638
- : never;
639
-
640
- type ExtractNestedUpdateInput<M extends Prisma.ModelName, K extends PropertyKey> =
641
- NonNullable<ExtractUnionProp<PrismaModelInputs<M>['updateInput'], K>> extends { update?: infer U }
642
- ? CleanNestedInput<Exclude<U, any[]>>
643
- : never;
644
-
645
- type RelationUpdatePayload<TField, TRelationConfig, M extends Prisma.ModelName, K extends PropertyKey> = NonNullable<TField> extends any[]
646
- ? ExtractNestedUpdateInput<M, K>[]
647
- : NonNullable<TField> extends object
648
- ? ExtractNestedUpdateInput<M, K> | (TRelationConfig extends { mode: 'oto'; restriction: 'set' } | { mode: 'mto'; nullable: true } | { mode: 'mto'; nullAble: true } ? null : never)
649
- : never;
650
-
651
- /**
652
- * Payload accepted by `merge` when the repository has configured relations (uses update input).
653
- */
654
- type UpdateWithRelations<T, M extends Prisma.ModelName, TRelations> =
655
- DistributiveOmit<PrismaModelInputs<M>['updateInput'], keyof TRelations> & {
656
- [K in Extract<keyof TRelations, keyof T>]?: RelationUpdatePayload<T[K], TRelations[K], M, K>;
657
- };
658
-
659
- /**
660
- * Payload accepted by `patch` and `patchList` when the repository has configured relations (uses create input).
661
- */
662
- type PatchWithRelations<T, M extends Prisma.ModelName, TRelations> =
663
- DistributiveOmit<PrismaModelInputs<M>['updateInput'], keyof TRelations> & {
664
- [K in Extract<keyof TRelations, keyof T>]?: RelationPayload<T[K], TRelations[K], M, K>;
665
- };
666
-
667
- /**
668
- * Extracts the payload type of the `save` method from a configured VSRepository instance.
669
- */
670
- export type SaveObject<TInput, TRepo> =
671
- TRepo extends VSRepository<infer T, infer M, infer Config>
672
- ? (Config extends { relations: infer R } ? (R extends object ? R : {}) : {}) extends infer TRelations
673
- ? TInput extends infer U
674
- ? U extends any
675
- ? Simplify<TransformCreatePayload<U, T, M, TRelations>>
676
- : never
677
- : never
678
- : never
679
- : never;
680
-
681
- /**
682
- * Extracts the payload type of the `patch` method from a configured VSRepository instance.
683
- */
684
- export type PatchObject<TInput, TRepo> =
685
- TRepo extends VSRepository<infer T, infer M, infer Config>
686
- ? (Config extends { relations: infer R } ? (R extends object ? R : {}) : {}) extends infer TRelations
687
- ? DistributiveOmit<TInput, keyof TRelations> & {
688
- [K in Extract<keyof TRelations, keyof T>]?: RelationPayload<T[K], TRelations[K], M, K>;
689
- }
690
- : never
691
- : never;
692
-
693
-
694
- type _Pk<T, Config> = WidenField<T[ExtractPkName<T, Config> extends keyof T ? ExtractPkName<T, Config> : never]>;
695
- type _Ret<M extends Prisma.ModelName, TSelects, S, TDefault, IM = never, TIncludes = {}> = ResolveCurrentReturn<M, TSelects, S, TDefault, IM, TIncludes>;
696
- type _DS<Config, C, Method extends keyof NonNullable<BuildConfig['baseMethods']>, TSelects = ExtractSelectModels<Config>> =
697
- ResolveMethodDefaultSelect<Config, C, Method, TSelects>;
698
- type _Sel<Config> = ExtractSelectModels<Config>;
699
- type _Inc<Config> = ExtractIncludeModels<Config>;
700
- type _Def<Config> = ExtractDefaultSelect<Config>;
701
- type _Rel<Config> = ExtractRelations<Config>;
702
- type _Soft<Config> = ExtractSoftRemovekName<Config>;
703
- type _DOrd<Config> = ExtractDefaultOrdenation<Config>;
704
-
705
- // ─── refactored mapped type — optimized for the TS compiler ──────────────────
706
-
707
- type AllBaseMethods<
708
- T,
709
- M extends Prisma.ModelName,
710
- Config,
711
- C extends BuildConfig<any> | undefined,
712
- TSelects = _Sel<Config>,
713
- TDefault = _Def<Config>,
714
- TPk = ExtractPkName<T, Config>,
715
- TRelations = _Rel<Config>,
716
- TSoftKey = _Soft<Config>,
717
- I = PrismaModelInputs<M>,
718
- TDefaultOrdenation = _DOrd<Config>,
719
- TIncludes = _Inc<Config>
720
- > = {
721
- /** Fetches a record by its primary key (PK). */
722
- get: <S extends keyof TSelects | false = _DS<Config, C, 'get', TSelects>, IM extends keyof TIncludes = never>(
723
- pk: _Pk<T, Config>, options?: MethodOptionsWithInclude<S, IM, TIncludes>
724
- ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes> | null>;
725
-
726
- /** Fetches a record by PK and throws `VSRepoRuntimeError` if not found. */
727
- getOrThrow: <S extends keyof TSelects | false = _DS<Config, C, 'getOrThrow', TSelects>, IM extends keyof TIncludes = never>(
728
- pk: _Pk<T, Config>, options?: MethodOptionsWithInclude<S, IM, TIncludes>
729
- ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes>>;
730
-
731
- /** Fetches multiple records by a list of primary keys (PKs). */
732
- getList: <S extends keyof TSelects | false = _DS<Config, C, 'getList', TSelects>, IM extends keyof TIncludes = never>(
733
- pks: _Pk<T, Config>[], options?: MethodOptionsWithInclude<S, IM, TIncludes>
734
- ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes>[]>;
735
-
736
- /** Deletes a record identified by its primary key (PK). */
737
- remove: <S extends keyof TSelects | false = _DS<Config, C, 'remove', TSelects>, IM extends keyof TIncludes = never>(
738
- pk: _Pk<T, Config>, options?: MethodOptionsWithInclude<S, IM, TIncludes>
739
- ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes>>;
740
-
741
- /** Inserts or updates (upsert) a record. */
742
- save: <S extends keyof TSelects | false = _DS<Config, C, 'save', TSelects>, IM extends keyof TIncludes = never>(
743
- obj: UpsertWithRelations<T, M, TRelations>, options?: MethodOptionsWithInclude<S, IM, TIncludes>
744
- ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes>>;
745
-
746
- /** Saves an array of objects in a single automatic transaction. */
747
- saveList: <S extends keyof TSelects | false = _DS<Config, C, 'saveList', TSelects>, IM extends keyof TIncludes = never>(
748
- objs: UpsertWithRelations<T, M, TRelations>[], options?: MethodOptionsWithInclude<S, IM, TIncludes, 'db'> & { db?: DbTransaction }
749
- ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes>[]>;
750
-
751
- /** Partially updates (patch) an existing record by its primary key (PK). */
752
- patch: <S extends keyof TSelects | false = _DS<Config, C, 'patch', TSelects>, IM extends keyof TIncludes = never>(
753
- pk: _Pk<T, Config>, obj: PatchWithRelations<T, M, TRelations>, options?: MethodOptionsWithInclude<S, IM, TIncludes>
754
- ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes>>;
755
-
756
- /** Partially updates multiple records via `[pk, obj]` tuples in an automatic transaction. */
757
- patchList: <S extends keyof TSelects | false = _DS<Config, C, 'patchList', TSelects>, IM extends keyof TIncludes = never>(
758
- tuples: [pk: _Pk<T, Config>, obj: PatchWithRelations<T, M, TRelations>][], options?: MethodOptionsWithInclude<S, IM, TIncludes, 'db'> & { db?: DbTransaction }
759
- ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes>[]>;
760
-
761
- /** Fetches a record by PK and deep-merges it with the provided object **in memory**. */
762
- merge: <S extends keyof TSelects | false = _DS<Config, C, 'merge', TSelects>, IM extends keyof TIncludes = never>(
763
- pk: _Pk<T, Config>, obj: UpdateWithRelations<T, M, TRelations>, options?: MethodOptionsWithInclude<S, IM, TIncludes>
764
- ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes> | null>;
765
-
766
- /** Deletes multiple records by their primary keys. */
767
- removeList: (pks: _Pk<T, Config>[], options?: { db?: ClientOrTransaction }) => Promise<{ count: number }>;
768
-
769
- /** Fetches all records (respects `requiredWhere` when set). */
770
- getAll: <S extends keyof TSelects | false = _DS<Config, C, 'getAll', TSelects>, IM extends keyof TIncludes = never>(
771
- options?: MethodOptionsWithInclude<S, IM, TIncludes> & {
772
- pagination?: PaginationOptions<I extends { cursorInput: infer Curs } ? Curs : unknown>;
773
- /**
774
- * Ordering to apply to the query.
775
- * When omitted and `defaultOrdenation` is configured on the repository,
776
- * the default ordering is applied automatically.
777
- */
778
- order?: I extends { orderByInput: infer OB } ? OB : OrderOptions;
779
- }
780
- ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes>[]>;
781
-
782
- /** Returns the total number of records. */
783
- total: (options?: { db?: ClientOrTransaction; see?: SeeMode }) => Promise<number>;
784
-
785
- /** Checks whether a record exists by its primary key (PK). */
786
- has: (pk: _Pk<T, Config>, options?: { db?: ClientOrTransaction; see?: SeeMode }) => Promise<boolean>;
787
-
788
- /** Marks a record as deleted (soft-delete). */
789
- softRemove: <S extends keyof TSelects | false = _DS<Config, C, 'softRemove', TSelects>, IM extends keyof TIncludes = never>(
790
- pk: _Pk<T, Config>, options?: MethodOptionsWithInclude<S, IM, TIncludes, 'see'>
791
- ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes>>;
792
-
793
- /** Marks multiple records as deleted (soft-delete) in batch. */
794
- softRemoveList: (pks: _Pk<T, Config>[], options?: { db?: ClientOrTransaction }) => Promise<{ count: number }>;
795
-
796
- /** Restores a record previously marked as deleted (soft-delete). */
797
- restore: <S extends keyof TSelects | false = _DS<Config, C, 'restore', TSelects>, IM extends keyof TIncludes = never>(
798
- pk: _Pk<T, Config>, options?: MethodOptionsWithInclude<S, IM, TIncludes, 'see'>
799
- ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes>>;
800
-
801
- /** Restores multiple records previously marked as deleted (soft-delete) in batch. */
802
- restoreList: (pks: _Pk<T, Config>[], options?: { db?: ClientOrTransaction }) => Promise<{ count: number }>;
803
- };
804
-
805
- type InjectedBaseMethods<
806
- T,
807
- M extends Prisma.ModelName,
808
- Config,
809
- C extends BuildConfig<any> | undefined,
810
- TSelects = _Sel<Config>,
811
- TDefault = _Def<Config>,
812
- TPk = ExtractPkName<T, Config>,
813
- TRelations = _Rel<Config>,
814
- TSoftKey = _Soft<Config>,
815
- I = PrismaModelInputs<M>,
816
- TDefaultOrdenation = _DOrd<Config>,
817
- TIncludes = _Inc<Config>
818
- > = Pick<
819
- AllBaseMethods<T, M, Config, C, TSelects, TDefault, TPk, TRelations, TSoftKey, I, TDefaultOrdenation, TIncludes>,
820
- | (C extends { baseMethods: { get: { active: false } } } ? never : 'get')
821
- | (C extends { baseMethods: { getOrThrow: { active: false } } } ? never : 'getOrThrow')
822
- | (C extends { baseMethods: { getList: { active: false } } } ? never : 'getList')
823
- | (C extends { baseMethods: { remove: { active: false } } } ? never : 'remove')
824
- | (C extends { baseMethods: { save: { active: false } } } ? never : 'save')
825
- | (C extends { baseMethods: { saveList: { active: false } } } ? never : 'saveList')
826
- | (C extends { baseMethods: { patch: { active: false } } } ? never : 'patch')
827
- | (C extends { baseMethods: { patchList: { active: false } } } ? never : 'patchList')
828
- | (C extends { baseMethods: { merge: { active: false } } } ? never : 'merge')
829
- | (C extends { baseMethods: { removeList: { active: false } } } ? never : 'removeList')
830
- | (C extends { baseMethods: { getAll: { active: false } } } ? never : 'getAll')
831
- | (C extends { baseMethods: { total: { active: false } } } ? never : 'total')
832
- | (C extends { baseMethods: { has: { active: false } } } ? never : 'has')
833
- | ([TSoftKey] extends [never] ? never : C extends { baseMethods: { softRemove: { active: false } } } ? never : 'softRemove')
834
- | ([TSoftKey] extends [never] ? never : C extends { baseMethods: { softRemoveList: { active: false } } } ? never : 'softRemoveList')
835
- | ([TSoftKey] extends [never] ? never : C extends { baseMethods: { restore: { active: false } } } ? never : 'restore')
836
- | ([TSoftKey] extends [never] ? never : C extends { baseMethods: { restoreList: { active: false } } } ? never : 'restoreList')
837
- >;
838
-
839
-
840
- /**
841
- * Relation configuration for One-to-Many or Many-to-Many.
842
- *
843
- * @template TItem Type of the related entity.
844
- */
845
- export type ManyRelationConfig<TItem> = {
846
- /** Primary key of the related entity. */
847
- pk: keyof TItem;
848
- /** Relation type: `otm` (One-to-Many) or `mtm` (Many-to-Many). */
849
- mode: 'otm' | 'mtm';
850
- /** Mutation behavior: `set` (replaces all) or `add` (appends to existing). */
851
- restriction: 'set' | 'add';
852
- };
853
-
854
- /**
855
- * One-to-One relation configuration.
856
- *
857
- * @template TItem Type of the related entity.
858
- */
859
- export type OneToOneRelationConfig<TItem> = {
860
- /** Primary key of the related entity. */
861
- pk: keyof TItem;
862
- /** Relation type: `oto` (One-to-One). */
863
- mode: 'oto';
864
- /** Allowed mutation behavior for saving. */
865
- restriction: 'set' | 'add';
866
- };
867
-
868
- /**
869
- * Many-to-One relation configuration.
870
- *
871
- * @template TItem Type of the related entity.
872
- */
873
- export type ManyToOneRelationConfig<TItem> = {
874
- /** Primary key of the related entity. */
875
- pk: keyof TItem;
876
- /** Relation type: `mto` (Many-to-One). */
877
- mode: 'mto';
878
- /** Allowed mutation behavior for saving. */
879
- restriction: 'set' | 'add';
880
- /**
881
- * Enables the ability to unlink the relation, setting the foreign key to null.
882
- * @deprecated Use `nullable` (lowercase) instead of `nullAble`.
883
- */
884
- nullAble?: boolean;
885
- /** Enables the ability to unlink the relation, setting the foreign key to null. */
886
- nullable?: boolean;
887
- };
888
-
889
- /**
890
- * Automatically infers the possible relation configuration from a field.
891
- */
892
- export type ExtractRelationConfig<TField> = NonNullable<TField> extends infer NonNull
893
- ? NonNull extends Date | Buffer | Uint8Array | Decimal | JsonValue ? never
894
- : NonNull extends any[] ? (NonNull[number] extends object ? ManyRelationConfig<NonNull[number]> : never)
895
- : NonNull extends object ? (OneToOneRelationConfig<NonNull> | ManyToOneRelationConfig<NonNull>)
896
- : never
897
- : never;
898
-
899
- /**
900
- * Map of configurable relations for an entity type.
901
- */
902
- export type RepositoryRelations<T> = {
903
- [K in keyof T as ExtractRelationConfig<T[K]> extends never ? never : K]?: ExtractRelationConfig<T[K]>;
904
- };
905
-
906
- type AnySelect<M extends Prisma.ModelName> = Prisma.TypeMap['model'][M]['operations']['findMany']['args']['select'];
907
-
908
- /**
909
- * Main configuration used in `setupVSRepo<T, M>()(config)`.
910
- *
911
- * @template T Type of the entity managed by the repository.
912
- * @template M Prisma model name.
913
- * @template SM Map of named select models.
914
- */
915
- export type RepoConfig<T, M extends Prisma.ModelName, SM extends Record<string, AnySelect<M>> = Record<string, AnySelect<M>>> = {
916
- tableName: Uncapitalize<M>;
917
- pkName: keyof T;
918
- softRemovekName?: keyof T & string;
919
- selectModels?: SM;
920
- defaultSelectModel?: Extract<keyof SM, string>;
921
- includeModels?: IncludeModels<M>;
922
- requiredWhere?: WhereModel<M>;
923
- defaultOrdenation?: OrdenationModel<M>;
924
- relations?: RepositoryRelations<T>;
925
- methods?: Record<string, MethodConfig<M, SM>>;
926
- };
927
-
928
- /**
929
- * Final type returned by `.build(prisma)`.
930
- *
931
- * Combines dynamic methods, base methods, and custom extensions.
932
- */
933
- type BuiltRepository<T extends object, M extends Prisma.ModelName, Config extends RepoConfig<T, M, any>, C extends BuildConfig<any> | undefined> = {
934
- /**
935
- * Extends the repository with custom methods without losing type inference.
936
- */
937
- extend<E>(extensionFunc: (repo: BuiltRepository<T, M, Config, C>) => E): BuiltRepository<T, M, Config, C> & E;
938
-
939
- /**
940
- * The Prisma Client instance passed to `build`.
941
- */
942
- readonly prisma: DbClient;
943
- } & DynamicMethods<T, M, Config, PrismaModelInputs<M>> & InjectedBaseMethods<T, M, Config, C>;
944
-
945
- /**
946
- * Typed repository factory based on the Prisma model configuration.
947
- */
948
- export declare class VSRepository<T extends object, M extends Prisma.ModelName, const Config extends RepoConfig<T, M, any> = RepoConfig<T, M, any>> {
949
- /** Original configuration provided to `setupVSRepo`. */
950
- readonly config: Config;
951
- /**
952
- * Creates a configurable instance of `VSRepository`.
953
- */
954
- constructor(config: Config);
955
- /**
956
- * Builds the final repository with base and dynamic methods.
957
- */
958
- build<C extends BuildConfig<keyof ExtractSelectModels<Config>>>(prisma: DbClient, config?: C): BuiltRepository<T, M, Config, C>;
959
- vsrepocache: never;
960
- }
961
-
962
- /**
963
- * Infers the type of an already-configured repository from a `VSRepository` instance.
964
- *
965
- * Also allows manually providing the `BuildConfig` and extensions type.
966
- */
967
- export type RepositoryOf<TRepo, C extends BuildConfig<any> | undefined = undefined, E = unknown> =
968
- TRepo extends VSRepository<infer T, infer M, infer Config>
969
- ? Simplify<BuiltRepository<T, M, Config, C> & E>
970
- : never;
971
-
972
- /**
973
- * Utility type used to validate a repository configuration at compile time.
974
- */
975
- export type ValidateRepoConfig<T extends object, M extends Prisma.ModelName, Config> = {
976
- /**
977
- * Name of the table mapped by Prisma (usually uncapitalized).
978
- */
979
- tableName: Uncapitalize<M>;
980
-
981
- /**
982
- * Name of the field that represents the entity's primary key (Primary Key).
983
- */
984
- pkName: keyof T;
985
-
986
- /**
987
- * Name of the `DateTime` field used for soft-delete.
988
- *
989
- * When configured, enables the `softRemove`, `softRemoveList`, `restore`, and `restoreList` methods.
990
- * The field **must** be of type `DateTime` in the Prisma schema — VSRepository validates this during `build`.
991
- */
992
- softRemovekName?: keyof T & string;
993
-
994
- /**
995
- * Defines named and reusable data projections (selects).
996
- * Allows creating different views of the same entity (e.g., `public`, `minimal`, `internal`).
997
- */
998
- selectModels?: SelectModels<M>;
999
-
1000
- /**
1001
- * Defines which select (a key from `selectModels`) will be used automatically
1002
- * when none is specified in the method call.
1003
- * It is highly recommended to define it whenever `selectModels` are used.
1004
- */
1005
- defaultSelectModel?: string;
1006
-
1007
- /**
1008
- * Defines named and reusable include projections.
1009
- * Similar to selectModels, but resolves Prisma `include` clauses.
1010
- */
1011
- includeModels?: IncludeModels<M>;
1012
-
1013
- /**
1014
- * Defines global filters that will be automatically applied to all repository queries.
1015
- * Useful for tenant isolation (multi-tenancy) or base restrictions (e.g., `isActive: true`).
1016
- */
1017
- requiredWhere?: WhereModel<M>;
1018
-
1019
- /**
1020
- * Default ordering automatically injected into all queries that accept `orderBy`,
1021
- * unless the method already has `injectOrdenation` configured or uses the `Ordered` suffix.
1022
- *
1023
- * Useful for ensuring a consistent sort order across the repository without repeating
1024
- * the `order` argument on every call.
1025
- */
1026
- defaultOrdenation?: OrdenationModel<M>;
1027
-
1028
- /**
1029
- * Configures automatic relation management.
1030
- * When configured, allows the `save`, `saveList`, `patch`, and `patchList` methods
1031
- * to automatically handle linking, creation, or cascading deletion of related records.
1032
- */
1033
- relations?: RepositoryRelations<T>;
1034
-
1035
- /**
1036
- * Definition of dynamic repository methods.
1037
- * Behaviors and return types are automatically inferred from the method's name
1038
- * (e.g., `findOneByEmail`, `findManyPaginated`) or proxied via the `proxyTo` property.
1039
- */
1040
- methods?: {
1041
- [K in keyof (Config extends { methods: infer Meth } ? Meth : {})]: K extends string
1042
- ? MethodConfig<M, Config extends { selectModels: infer SM } ? SM : any> & (K extends ValidMethodPatterns ? {} : { proxyTo: ValidMethodPatterns })
1043
- : never;
1044
- };
1045
- };
1046
-
1047
- /**
1048
- * Function to initialize and configure the `repository`.
1049
- * The configuration passed here is what will be read when `.build()` is called.
1050
- */
1051
- export declare function setupVSRepo<T extends object, M extends Prisma.ModelName>(): <
1052
- const SM extends Record<string, SelectModel<M>>,
1053
- const Config extends RepoConfig<T, M, SM>
1054
- >(
1055
- config: Config & ValidateRepoConfig<T, M, Config>
1056
- ) => VSRepository<T, M, Config>;
1
+ import { Prisma, PrismaClient } from '../generated/prisma/client';
2
+ import { Decimal, JsonValue } from '@prisma/client/runtime/client';
3
+
4
+ /**
5
+ * Flattens a type intersection into a single object,
6
+ * avoiding the TypeScript "union type too complex to represent" error.
7
+ */
8
+ type Simplify<T> = { [K in keyof T]: T[K] } & {};
9
+
10
+ type WidenField<T> =
11
+ T extends bigint ? bigint | number :
12
+ T extends Date ? Date | string :
13
+ T extends Decimal ? Decimal | string | number :
14
+ T extends readonly [infer U, infer V] ? [WidenField<U>, WidenField<V>] :
15
+ T extends Array<infer U> ? WidenField<U>[] :
16
+ T;
17
+
18
+ /**
19
+ * Full Prisma Client instance used to build repositories.
20
+ */
21
+ export type DbClient = PrismaClient;
22
+
23
+ /**
24
+ * Prisma transactional client returned by `prisma.$transaction`.
25
+ */
26
+ export type DbTransaction = Prisma.TransactionClient;
27
+
28
+ /**
29
+ * Accepts either the main Prisma client or a transaction client.
30
+ */
31
+ export type ClientOrTransaction = DbClient | DbTransaction;
32
+
33
+ export * from './VSRepoError';
34
+
35
+ type OrderPattern = {
36
+ [key: string]: 'asc' | 'desc' | { _count: 'asc' | 'desc' } | OrderPattern;
37
+ };
38
+
39
+ /**
40
+ * Pagination options accepted by methods with the `Paginated` suffix.
41
+ *
42
+ * @template TCursor Type of the cursor used by the Prisma model.
43
+ */
44
+ export type PaginationOptions<TCursor = unknown> = {
45
+ /** Number of records to skip. */
46
+ skip?: number;
47
+ /** Maximum number of records to return. */
48
+ take?: number;
49
+ /** Typed cursor for position-based pagination. */
50
+ cursor?: TCursor;
51
+ };
52
+
53
+ /**
54
+ * Ordering accepted by repository methods.
55
+ *
56
+ * Can be a single ordering or a list of chained orderings.
57
+ */
58
+ export type OrderOptions = OrderPattern | OrderPattern[];
59
+
60
+ /**
61
+ * Visibility mode for records with soft-delete.
62
+ *
63
+ * - `"active"` — returns only non-deleted records (default).
64
+ * - `"removed"` — returns only deleted records.
65
+ * - `"all"` — returns all records regardless of their status.
66
+ */
67
+ export type SeeMode = 'active' | 'removed' | 'all';
68
+
69
+ type ValidMethodPatterns =
70
+ | `existsBy${string}` | `findBy${string}`
71
+ | `findUniqueBy${string}` | `findUniqueOrThrowBy${string}`
72
+ | `findFirstBy${string}` | `findFirst${string}`
73
+ | `findFirstOrThrowBy${string}` | `findFirstOrThrow${string}`
74
+ | `findManyBy${string}` | `findMany${string}`
75
+ | `createManyAndReturn${string}` | `createMany${string}`
76
+ | `create${string}` | `updateManyAndReturnBy${string}` | `updateManyBy${string}`
77
+ | `updateBy${string}` | `upsertBy${string}` | `deleteManyBy${string}`
78
+ | `deleteBy${string}` | `countBy${string}` | `count${string}` | `countWhere${string}`
79
+ | `findWhere${string}` | `findListWhere${string}`
80
+ | `existsWhere${string}` | `updateManyWhere${string}` | `deleteManyWhere${string}`
81
+ | `findOneWhere${string}` | `findOneBy${string}` | `updateManyAndReturnWhere${string}`
82
+ | 'aggregate' | 'groupBy';
83
+
84
+ type StripModifier<S extends string> =
85
+ S extends `${infer Base}NotStartsWithInsensitive` ? Base :
86
+ S extends `${infer Base}StartsWithInsensitive` ? Base :
87
+ S extends `${infer Base}NotEndsWithInsensitive` ? Base :
88
+ S extends `${infer Base}EndsWithInsensitive` ? Base :
89
+ S extends `${infer Base}NotContainsInsensitive` ? Base :
90
+ S extends `${infer Base}ContainsInsensitive` ? Base :
91
+ S extends `${infer Base}NotInInsensitive` ? Base :
92
+ S extends `${infer Base}InInsensitive` ? Base :
93
+ S extends `${infer Base}NotInsensitive` ? Base :
94
+ S extends `${infer Base}NotStartsWith` ? Base :
95
+ S extends `${infer Base}StartsWith` ? Base :
96
+ S extends `${infer Base}NotEndsWith` ? Base :
97
+ S extends `${infer Base}EndsWith` ? Base :
98
+ S extends `${infer Base}NotContains` ? Base :
99
+ S extends `${infer Base}Contains` ? Base :
100
+ S extends `${infer Base}NotIn` ? Base :
101
+ S extends `${infer Base}In` ? Base :
102
+ S extends `${infer Base}NotBetween` ? Base :
103
+ S extends `${infer Base}Between` ? Base :
104
+ S extends `${infer Base}Not` ? Base :
105
+ S extends `${infer Base}LessThanEqual` ? Base :
106
+ S extends `${infer Base}LessThan` ? Base :
107
+ S extends `${infer Base}GreaterThanEqual` ? Base :
108
+ S extends `${infer Base}GreaterThan` ? Base :
109
+ S extends `${infer Base}Insensitive` ? Base :
110
+ S;
111
+
112
+ type ExtractFieldName<S extends string> = Uncapitalize<StripModifier<S>>;
113
+
114
+ type IsArrayFilter<S extends string> = S extends `${string}${'NotIn' | 'In'}` ? true : false;
115
+
116
+ type IsBetweenFilter<S extends string> = S extends `${string}${'NotBetween' | 'Between'}` ? true : false;
117
+
118
+ type ParseRelation<S extends string> =
119
+ S extends `${infer Rel}Without${infer Rest}` ? [Uncapitalize<Rel>, 'isNot', Rest] :
120
+ S extends `${infer Rel}With${infer Rest}` ? [Uncapitalize<Rel>, 'is', Rest] :
121
+ S extends `${infer Rel}Some${infer Rest}` ? [Uncapitalize<Rel>, 'some', Rest] :
122
+ S extends `${infer Rel}Every${infer Rest}` ? [Uncapitalize<Rel>, 'every', Rest] :
123
+ S extends `${infer Rel}None${infer Rest}` ? [Uncapitalize<Rel>, 'none', Rest] : null;
124
+
125
+ type GetFieldType<T, S extends string, I> = WidenField<
126
+ ExtractFieldName<S> extends infer FieldName
127
+ ? FieldName extends keyof T
128
+ ? IsArrayFilter<S> extends true
129
+ ? T[FieldName][]
130
+ : IsBetweenFilter<S> extends true
131
+ ? [NonNullable<T[FieldName]>, NonNullable<T[FieldName]>]
132
+ : NonNullable<T[FieldName]> extends object | any[]
133
+ ? I extends { whereInput: infer W }
134
+ ? FieldName extends keyof NonNullable<W> ? Exclude<NonNullable<W>[FieldName], undefined> : T[FieldName]
135
+ : T[FieldName]
136
+ : T[FieldName]
137
+ : ParseRelation<S> extends [infer Rel extends keyof T, any, infer Rest extends string]
138
+ ? GetFieldType<NonNullable<T[Rel]> extends any[] ? NonNullable<T[Rel]>[number] : NonNullable<T[Rel]>, Rest, unknown>
139
+ : unknown
140
+ : unknown
141
+ >;
142
+
143
+ type NoArgModifiers = 'IsNull' | 'IsNotNull' | 'IsTrue' | 'IsFalse' | 'None' | 'Some' | 'Every' | 'Without';
144
+
145
+ type IsNoArgModifier<S extends string> =
146
+ S extends `${string}${'StartsWith' | 'EndsWith'}` ? false :
147
+ S extends `${string}${NoArgModifiers | 'With'}` ? true :
148
+ false;
149
+
150
+ type IsOptional<S extends string> = S extends `${string}Optional` ? true : false;
151
+ type StripOptional<S extends string> = S extends `${infer Base}Optional` ? Base : S;
152
+
153
+ type MapToContractTypes<T, Arr extends string[], I> =
154
+ Arr extends [infer First extends string, ...infer Rest extends string[]]
155
+ ? First extends ''
156
+ ? MapToContractTypes<T, Rest, I>
157
+ : StripOptional<First> extends infer CleanFirst extends string
158
+ ? IsNoArgModifier<CleanFirst> extends true
159
+ ? MapToContractTypes<T, Rest, I>
160
+ : IsOptional<First> extends true
161
+ ? [GetFieldType<T, CleanFirst, I> | undefined, ...MapToContractTypes<T, Rest, I>]
162
+ : [GetFieldType<T, CleanFirst, I>, ...MapToContractTypes<T, Rest, I>]
163
+ : never
164
+ : [];
165
+
166
+ type SplitAllTokens<S extends string> =
167
+ S extends `${infer L}AND${infer R}` ? [...SplitAllTokens<L>, ...SplitAllTokens<R>] :
168
+ S extends `${infer L}And${infer R}` ? [...SplitAllTokens<L>, ...SplitAllTokens<R>] :
169
+ S extends `${infer L}Or${infer R}` ? [...SplitAllTokens<L>, ...SplitAllTokens<R>] :
170
+ S extends '' ? [] :
171
+ [S];
172
+
173
+ type ExtractFields<T, R extends string, I> =
174
+ R extends '' ? []
175
+ : FilterNonEmpty<MapToContractTypes<T, SplitAllTokens<R>, I>>;
176
+
177
+ type FilterNonEmpty<T extends unknown[]> =
178
+ T extends [infer First, ...infer Rest]
179
+ ? [First] extends ['']
180
+ ? FilterNonEmpty<Rest>
181
+ : [First, ...FilterNonEmpty<Rest>]
182
+ : [];
183
+
184
+ type ResolveReturnType<M extends string, TSelected> =
185
+ M extends 'existsBy' | 'existsWhere' ? boolean :
186
+ M extends 'createMany' | 'updateManyBy' | 'deleteManyBy' | 'updateManyWhere' | 'deleteManyWhere' ? { count: number } :
187
+ M extends 'findMany' | 'createManyAndReturn' | 'updateManyAndReturnBy' | 'updateManyAndReturnWhere' | 'findListWhere' | 'findByList' ? TSelected[] :
188
+ M extends 'findUnique' | 'findFirst' | 'findWhere' | 'findByOne' | 'findOneBy' | 'findOneWhere' ? TSelected | null :
189
+ M extends 'findUniqueOrThrow' | 'findFirstOrThrow' | 'create' | 'updateBy' | 'upsertBy' | 'deleteBy' ? TSelected :
190
+ M extends 'count' | 'countWhere' ? number : never;
191
+
192
+ type GetUpdateInput<I> = I extends { updateInput: infer U } ? U : unknown;
193
+ type GetCreateInput<I> = I extends { createInput: infer C } ? C : unknown;
194
+ type GetCreateManyInput<I> = I extends { createManyInput: infer CM } ? CM : unknown;
195
+ type GetUpdateManyInput<I> = I extends { updateManyInput: infer UM } ? UM : unknown;
196
+ type GetWhereInput<I> = I extends { whereInput: infer W } ? NonNullable<W> : unknown;
197
+ type GetCursorInput<I> = I extends { cursorInput: infer C } ? C : unknown;
198
+ type GetOrderByInput<I> = I extends { orderByInput: infer OB } ? NonNullable<OB> : OrderOptions;
199
+
200
+ type ExtraArgs<M extends string, R extends string, I> = [
201
+ ...(M extends 'upsertBy' ? [update: GetUpdateInput<I>, create: GetCreateInput<I>]
202
+ : M extends 'create' ? [data: GetCreateInput<I>]
203
+ : M extends 'updateBy' ? [data: GetUpdateInput<I>]
204
+ : M extends 'createMany' | 'createManyAndReturn' ? [data: GetCreateManyInput<I>]
205
+ : M extends 'updateManyBy' | 'updateManyAndReturnBy' ? [data: GetUpdateManyInput<I>]
206
+ : M extends 'findWhere' | 'findListWhere' | 'countWhere' | 'existsWhere' | 'deleteManyWhere' | 'findOneWhere' ? [where: GetWhereInput<I>]
207
+ : M extends 'updateManyWhere' | 'updateManyAndReturnWhere' ? [where: GetWhereInput<I>, data: GetUpdateManyInput<I>]
208
+ : []),
209
+ ...(R extends `${string}PaginatedAndOrdered` ? [pagination: PaginationOptions<GetCursorInput<I>>, order: GetOrderByInput<I>]
210
+ : R extends `${string}OrderedAndPaginated` ? [order: GetOrderByInput<I>, pagination: PaginationOptions<GetCursorInput<I>>]
211
+ : R extends `${string}Paginated` ? [pagination: PaginationOptions<GetCursorInput<I>>]
212
+ : R extends `${string}Ordered` ? [order: GetOrderByInput<I>]
213
+ : [])
214
+ ];
215
+
216
+ export type PrismaModelName = Prisma.ModelName;
217
+
218
+ type PrismaDelegate<M extends PrismaModelName> = Uncapitalize<M> extends keyof DbClient ? DbClient[Uncapitalize<M>] : never;
219
+
220
+ type FullModelType<M extends PrismaModelName> =
221
+ Prisma.Result<PrismaDelegate<M>, {}, 'findMany'> extends Array<infer U> ? U : never;
222
+
223
+ type PrecomputedSelects<M extends PrismaModelName, SelectModels> = {
224
+ [S in keyof SelectModels]: Prisma.Result<PrismaDelegate<M>, { select: SelectModels[S] }, 'findMany'> extends Array<infer U> ? U : never
225
+ };
226
+
227
+ type PrecomputedIncludes<M extends PrismaModelName, IncludeModels> = {
228
+ [I in keyof IncludeModels]: Prisma.Result<PrismaDelegate<M>, { include: IncludeModels[I] }, 'findMany'> extends Array<infer U> ? U : never
229
+ };
230
+
231
+ type SelectedModel<M extends PrismaModelName, S, SelectModels, IM = never, IncludeModels = {}, RI = never> =
232
+ [RI] extends [never]
233
+ ? [IM] extends [never]
234
+ ? [S] extends [false]
235
+ ? FullModelType<M>
236
+ : [S] extends [never]
237
+ ? FullModelType<M>
238
+ : [S] extends [keyof SelectModels]
239
+ ? PrecomputedSelects<M, SelectModels>[S]
240
+ : FullModelType<M>
241
+ : IM extends keyof IncludeModels
242
+ ? PrecomputedIncludes<M, IncludeModels>[IM]
243
+ : FullModelType<M>
244
+ : Prisma.Result<PrismaDelegate<M>, { include: RI }, 'findMany'> extends Array<infer U> ? U : never;
245
+
246
+ /**
247
+ * Strips the `Distinct{Fields}` suffix used by read methods (e.g. `findManyDistinctIdadeAndCargo`).
248
+ * The distinct fields are resolved from the method name at build time, so they never
249
+ * become part of the runtime `where` fields extracted by `ExtractFields`.
250
+ */
251
+ type StripDistinctFields<R extends string> =
252
+ R extends `${infer F}Distinct${string}` ? F : R;
253
+
254
+ type CleanFields<R extends string> =
255
+ R extends `${infer F}PaginatedAndOrdered` ? StripDistinctFields<F> :
256
+ R extends `${infer F}OrderedAndPaginated` ? StripDistinctFields<F> :
257
+ R extends `${infer F}Paginated` ? StripDistinctFields<F> :
258
+ R extends `${infer F}Ordered` ? StripDistinctFields<F> :
259
+ R extends `${infer F}SkipDuplicates` ? StripDistinctFields<F> :
260
+ StripDistinctFields<R>;
261
+
262
+ /**
263
+ * Additional options accepted by repository methods.
264
+ *
265
+ * @template S Available keys in `selectModels`.
266
+ * @template IM Available keys in `includeModels`.
267
+ */
268
+ export type MethodOptions<S, IM extends PropertyKey = never, M extends PrismaModelName = never, RI = never> = {
269
+ /** Prisma client or transaction to use for the operation. */
270
+ db?: ClientOrTransaction;
271
+ /**
272
+ * Visibility mode for records with soft-delete.
273
+ *
274
+ * Only takes effect if `softRemovekName` is configured on the repository.
275
+ *
276
+ * - `"active"` — returns only non-deleted records (default).
277
+ * - `"removed"` — returns only deleted records.
278
+ * - `"all"` — returns all records, ignoring deletion status.
279
+ */
280
+ see?: SeeMode;
281
+ } & (
282
+ [IM] extends [never]
283
+ ? | {
284
+ /** Select model to apply to the operation. Use `false` to return the full payload. */
285
+ selectModel?: S | false;
286
+ /** Include model to apply to the operation. Cannot be used together with `selectModel`. */
287
+ includeModel?: never;
288
+ /** Raw Prisma `include`. Cannot be used together with `selectModel` or `includeModel`. */
289
+ include?: never;
290
+ }
291
+ | {
292
+ selectModel?: never;
293
+ includeModel?: never;
294
+ include: RI;
295
+ }
296
+ : | { selectModel?: S | false; includeModel?: never; include?: never }
297
+ | { selectModel?: never; includeModel: IM; include?: never }
298
+ | { selectModel?: never; includeModel?: never; include: RI }
299
+ );
300
+
301
+ /**
302
+ * Version of `MethodOptions` derived directly from a configured `VSRepository` instance.
303
+ *
304
+ * @template TRepo Configured `VSRepository` instance (use `typeof myVSRepo`).
305
+ *
306
+ * @example
307
+ * const userVSRepo = setupVSRepo<User, "user">()(config);
308
+ * type Opts = MethodOptionsModel<typeof userVSRepo>;
309
+ */
310
+ export type MethodOptionsModel<TRepo> =
311
+ TRepo extends VSRepository<any, infer M, infer Config>
312
+ ? MethodOptions<keyof ExtractSelectModels<Config> | false, keyof ExtractIncludeModels<Config>, M>
313
+ : never;
314
+
315
+ type MethodOptionsWithInclude<
316
+ S,
317
+ IM extends PropertyKey,
318
+ TIncludes,
319
+ M extends PrismaModelName,
320
+ RI = never,
321
+ Excluded extends keyof MethodOptions<S, keyof TIncludes, M, RI> = never
322
+ > = DistributiveOmit<MethodOptions<S, keyof TIncludes, M, RI>, Excluded>
323
+ & ({ includeModel: IM } | { includeModel?: never });
324
+
325
+ type MethodFn<MethodName extends string, T, M extends PrismaModelName, R extends string, SelectModels, DefaultSelect extends keyof SelectModels | false, I, IncludeModels> =
326
+ <S extends keyof SelectModels | false = DefaultSelect, IM extends keyof IncludeModels = never, RI extends IncludeModel<M> = never>(
327
+ ...args: [...ExtractFields<T, CleanFields<R>, I>, ...ExtraArgs<MethodName, R, I>, options?: MethodOptionsWithInclude<S, IM, IncludeModels, M, RI>]
328
+ ) => Promise<ResolveReturnType<MethodName, SelectedModel<M, S, SelectModels, IM, IncludeModels, RI>>>;
329
+
330
+ type GetMappedMethod<K extends string, MethodConf> =
331
+ K extends `findBy${string}` ? (MethodConf extends { fbMode: 'one' } ? 'findByOne' : 'findByList') :
332
+ K extends `findOneBy${string}` ? 'findOneBy' :
333
+ K extends `existsBy${string}` ? 'existsBy' :
334
+ K extends `existsWhere${string}` ? 'existsWhere' :
335
+ K extends `findUniqueOrThrowBy${string}` ? 'findUniqueOrThrow' :
336
+ K extends `findUniqueBy${string}` ? 'findUnique' :
337
+ K extends `findFirstOrThrowBy${string}` | `findFirstOrThrow${string}` ? 'findFirstOrThrow' :
338
+ K extends `findFirstBy${string}` | `findFirst${string}` ? 'findFirst' :
339
+ K extends `findManyBy${string}` | `findMany${string}` ? 'findMany' :
340
+ K extends `createManyAndReturn${string}` ? 'createManyAndReturn' :
341
+ K extends `createMany${string}` ? 'createMany' :
342
+ K extends `create${string}` ? 'create' :
343
+ K extends `updateManyAndReturnBy${string}` ? 'updateManyAndReturnBy' :
344
+ K extends `updateManyAndReturnWhere${string}` ? 'updateManyAndReturnWhere' :
345
+ K extends `updateManyBy${string}` ? 'updateManyBy' :
346
+ K extends `updateManyWhere${string}` ? 'updateManyWhere' :
347
+ K extends `updateBy${string}` ? 'updateBy' :
348
+ K extends `upsertBy${string}` ? 'upsertBy' :
349
+ K extends `deleteManyBy${string}` ? 'deleteManyBy' :
350
+ K extends `deleteManyWhere${string}` ? 'deleteManyWhere' :
351
+ K extends `deleteBy${string}` ? 'deleteBy' :
352
+ K extends `countWhere${string}` ? 'countWhere' :
353
+ K extends `countBy${string}` | `count${string}` ? 'count' :
354
+ K extends `findListWhere${string}` ? 'findListWhere' :
355
+ K extends `findOneWhere${string}` ? 'findOneWhere' :
356
+ K extends `findWhere${string}` ? 'findWhere' :
357
+ K extends 'aggregate' ? 'aggregate' :
358
+ K extends 'groupBy' ? 'groupBy' :
359
+ never;
360
+
361
+ type ExtractPatternBase<K extends string> =
362
+ K extends `${string}By${infer R}` ? R :
363
+ K extends `findFirstOrThrow${infer R}` ? R :
364
+ K extends `findFirst${infer R}` ? R :
365
+ K extends `findMany${infer R}` ? R :
366
+ K extends `createManyAndReturn${infer R}` ? R :
367
+ K extends `createMany${infer R}` ? R :
368
+ K extends `create${infer R}` ? R :
369
+ K extends `countWhere${infer R}` ? R :
370
+ K extends `count${infer R}` ? R :
371
+ K extends `findListWhere${infer R}` ? R :
372
+ K extends `findOneWhere${infer R}` ? R :
373
+ K extends `findWhere${infer R}` ? R :
374
+ K extends `existsWhere${infer R}` ? R :
375
+ K extends `updateManyWhere${infer R}` ? R :
376
+ K extends `updateManyAndReturnWhere${infer R}` ? R :
377
+ K extends `deleteManyWhere${infer R}` ? R : '';
378
+
379
+ type MethodFactory<T, M extends PrismaModelName, K extends string, SelectModels, DefaultSelect extends keyof SelectModels | false, I, MethodConf, IncludeModels> =
380
+ K extends `findWhere${string}`
381
+ ? {
382
+ /** @deprecated Use findOneWhere instead. */
383
+ <S extends keyof SelectModels | false = DefaultSelect, IM extends keyof IncludeModels = never, RI extends IncludeModel<M> = never>(
384
+ ...args: [...ExtractFields<T, CleanFields<ExtractPatternBase<K>>, I>, ...ExtraArgs<GetMappedMethod<K, MethodConf>, ExtractPatternBase<K>, I>, options?: MethodOptionsWithInclude<S, IM, IncludeModels, M, RI>]
385
+ ): Promise<ResolveReturnType<GetMappedMethod<K, MethodConf>, SelectedModel<M, S, SelectModels, IM, IncludeModels, RI>>>;
386
+ }
387
+ : MethodFn<GetMappedMethod<K, MethodConf>, T, M, ExtractPatternBase<K>, SelectModels, DefaultSelect, I, IncludeModels>;
388
+
389
+ type ResolveSelectModel<MethodConf, GlobalConf, SelectModels> =
390
+ MethodConf extends { selectModel: infer S } ? (S extends false ? false : S extends keyof SelectModels ? S : never) :
391
+ GlobalConf extends { defaultSelectModel: infer D } ? (D extends keyof SelectModels ? D : never) : never;
392
+
393
+ type ExtractPkName<T, Config> = Config extends { pkName: infer PK } ? (PK extends keyof T ? PK : never) : never;
394
+ type ExtractSelectModels<Config> = Config extends { selectModels: infer SM } ? SM : {};
395
+ type ExtractIncludeModels<Config> = Config extends { includeModels: infer IM } ? IM : {};
396
+ type ExtractDefaultSelect<Config> = Config extends { defaultSelectModel: infer D } ? D : never;
397
+ type ExtractRelations<Config> = Config extends { relations: infer R } ? (R extends object ? R : {}) : {};
398
+ type ExtractSoftRemovekName<Config> = Config extends { softRemovekName: infer S } ? S : never;
399
+ type ExtractDefaultOrdenation<Config> = Config extends { defaultOrdenation: infer O } ? O : never;
400
+
401
+ type AggregateMethod<M extends PrismaModelName> = <A extends Prisma.TypeMap['model'][M]['operations']['aggregate']['args']>(
402
+ prismaArgs: A,
403
+ options?: { db?: ClientOrTransaction }
404
+ ) => Promise<Prisma.Result<PrismaDelegate<M>, A, 'aggregate'>>;
405
+
406
+ type GroupByMethod<M extends PrismaModelName> = <A extends Prisma.TypeMap['model'][M]['operations']['groupBy']['args']>(
407
+ prismaArgs: A,
408
+ options?: { db?: ClientOrTransaction }
409
+ ) => Promise<Prisma.Result<PrismaDelegate<M>, A, 'groupBy'>>;
410
+
411
+ /**
412
+ * Function type generated for a dynamic method configured with `query` (non-modifying).
413
+ *
414
+ * The result of a raw SQL `SELECT` isn't statically known, so the method itself
415
+ * resolves to `any` by default, but exposes a generic parameter so the caller can
416
+ * infer/assert the shape of the result: `repo.myRawQuery<User[]>({ args: [...] })`.
417
+ *
418
+ * @template TReturn Return type asserted at the call site. Defaults to `any`.
419
+ */
420
+ type QueryMethodFn = <TReturn = any>(
421
+ arg: { args: any[]; db?: ClientOrTransaction },
422
+ ) => Promise<TReturn>;
423
+
424
+ /**
425
+ * Function type generated for a dynamic method configured with `query` and
426
+ * `modifying: true`.
427
+ *
428
+ * Modifying raw queries run through `$executeRawUnsafe` and always resolve to the
429
+ * number of affected rows, so — unlike `QueryMethodFn` — no generic return type is
430
+ * exposed here.
431
+ */
432
+ type QueryMethodModifyingFn = (
433
+ arg: { args: any[]; db?: ClientOrTransaction },
434
+ ) => Promise<number>;
435
+
436
+ type DynamicMethods<T, M extends PrismaModelName, Config, I> = Config extends { methods: infer Methods }
437
+ ? {
438
+ [K in keyof Methods as Methods[K] extends { map: true } ? K : never]: K extends string
439
+ ? Methods[K] extends { query: { modifying: true } }
440
+ ? QueryMethodModifyingFn
441
+ : Methods[K] extends { query: infer Q }
442
+ ? QueryMethodFn
443
+ : (Methods[K] extends { proxyTo: infer P extends string } ? P : K) extends infer ResolvedKey
444
+ ? ResolvedKey extends 'aggregate'
445
+ ? AggregateMethod<M>
446
+ : ResolvedKey extends 'groupBy'
447
+ ? GroupByMethod<M>
448
+ : ResolvedKey extends string
449
+ ? MethodFactory<T, M, ResolvedKey, ExtractSelectModels<Config>, ResolveSelectModel<Methods[K], Config, ExtractSelectModels<Config>>, I, Methods[K], ExtractIncludeModels<Config>>
450
+ : never
451
+ : never
452
+ : never;
453
+ }
454
+ : {};
455
+
456
+ /**
457
+ * Groups the main Prisma input types derived from a model.
458
+ *
459
+ * @template M Prisma model name.
460
+ */
461
+ export type PrismaModelInputs<M extends PrismaModelName> = {
462
+ /** Type of the `select` argument used in model queries. */
463
+ select: Prisma.TypeMap['model'][M]['operations']['findMany']['args']['select'];
464
+ /** Type of the `include` argument used in model queries. */
465
+ include: Prisma.TypeMap['model'][M]['operations']['findMany']['args']['include'];
466
+ /** Type of the `data` used in `create`. */
467
+ createInput: Prisma.TypeMap['model'][M]['operations']['create']['args']['data'];
468
+ /** Type of the `data` used in `createMany`. */
469
+ createManyInput: Prisma.TypeMap['model'][M]['operations']['createMany']['args']['data'];
470
+ /** Type of the `data` used in `update`. */
471
+ updateInput: Prisma.TypeMap['model'][M]['operations']['update']['args']['data'];
472
+ /** Type of the `data` used in `updateMany`. */
473
+ updateManyInput: Prisma.TypeMap['model'][M]['operations']['updateMany']['args']['data'];
474
+ /** Type of the `where` used in model queries. */
475
+ whereInput: Prisma.TypeMap['model'][M]['operations']['findMany']['args']['where'];
476
+ /** Type of the `orderBy` used in model queries. */
477
+ orderByInput: Prisma.TypeMap['model'][M]['operations']['findMany']['args']['orderBy'];
478
+ /** Type of the cursor used in model queries. */
479
+ cursorInput: Prisma.TypeMap['model'][M]['operations']['findMany']['args']['cursor'];
480
+ /** Type of the `create` payload used in `upsert`. */
481
+ upsertCreateInput: Prisma.TypeMap['model'][M]['operations']['upsert']['args']['create'];
482
+ /** Type of the `update` payload used in `upsert`. */
483
+ upsertUpdateInput: Prisma.TypeMap['model'][M]['operations']['upsert']['args']['update'];
484
+ };
485
+
486
+ /**
487
+ * Type of the `select` object of a Prisma model.
488
+ */
489
+ export type SelectModel<M extends PrismaModelName> = PrismaModelInputs<M>['select'];
490
+
491
+ /**
492
+ * Map of named, reusable selects for a Prisma model.
493
+ */
494
+ export type SelectModels<M extends PrismaModelName> = Record<string, SelectModel<M>>;
495
+
496
+ /**
497
+ * Type of the `include` object of a Prisma model.
498
+ */
499
+ export type IncludeModel<M extends PrismaModelName> = PrismaModelInputs<M>['include'];
500
+
501
+ /**
502
+ * Map of named, reusable includes for a Prisma model.
503
+ */
504
+ export type IncludeModels<M extends PrismaModelName> = Record<string, IncludeModel<M>>;
505
+
506
+ /**
507
+ * Type of the `where` object of a Prisma model.
508
+ */
509
+ export type WhereModel<M extends PrismaModelName> = PrismaModelInputs<M>['whereInput'];
510
+
511
+ /**
512
+ * Type of the `cursor` object of a Prisma model.
513
+ */
514
+ export type CursorModel<M extends PrismaModelName> = PrismaModelInputs<M>['cursorInput'];
515
+
516
+ /**
517
+ * Type of the `orderBy` object of a Prisma model.
518
+ */
519
+ export type OrdenationModel<M extends PrismaModelName> = PrismaModelInputs<M>['orderByInput'];
520
+
521
+ /**
522
+ * Pagination options with typed cursor for a Prisma model.
523
+ */
524
+ export type PaginationModel<M extends PrismaModelName> = PaginationOptions<PrismaModelInputs<M>['cursorInput']>;
525
+
526
+ /**
527
+ * Base payload used to create a record in the model's `save`/`upsert`.
528
+ */
529
+ export type ModelUpsertInput<M extends PrismaModelName> = PrismaModelInputs<M>['upsertCreateInput'];
530
+
531
+ /**
532
+ * Configuration for a dynamic method defined in `methods`.
533
+ *
534
+ * @template M Prisma model name.
535
+ * @template SelectModels Map of select models available in the repository.
536
+ */
537
+ export type MethodConfig<M extends PrismaModelName, SelectModels = any> = {
538
+ /** Defines whether the method will be exposed on the repository. */
539
+ readonly map: boolean;
540
+ /** Overrides `defaultSelectModel` for this method only. */
541
+ readonly selectModel?: string | false;
542
+ /** Controls whether the method combines (`extending`) or overwrites (`overwrite`) the `requiredWhere`. */
543
+ readonly whereType?: 'overwrite' | 'extending';
544
+ /** Redirects the logic to another valid method pattern. */
545
+ readonly proxyTo?: ValidMethodPatterns;
546
+ /** Adds an extra `where` on top of `requiredWhere`. */
547
+ readonly pushWhere?: WhereModel<M>;
548
+ /** * Defines whether `findBy` returns a single item (`one`) or a list (`list`).
549
+ * @deprecated Use `findOneBy` if you want to return a single result.
550
+ */
551
+ readonly fbMode?: 'one' | 'list';
552
+ /** Injects a fixed ordering automatically into the query. */
553
+ readonly injectOrdenation?: OrdenationModel<M>;
554
+ /** Injects a fixed pagination automatically into the query. */
555
+ readonly injectPagination?: PaginationModel<M>;
556
+ /**
557
+ * Turns this method into a **raw SQL query method**, bypassing name-based parsing
558
+ * entirely. The method executes the given SQL directly through Prisma, with
559
+ * parameters injected positionally via the `args` array passed at the call site
560
+ * (`$1`, `$2`, ... placeholders), so no other option in `MethodConfig` applies
561
+ * (`selectModels`, `requiredWhere`, `pushWhere`, etc. are all ignored).
562
+ *
563
+ * - `modifying: false` (default) runs through `$queryRawUnsafe` and the method
564
+ * resolves to `TReturn` (`any` by default), inferable/assertable via a generic
565
+ * at the call site.
566
+ * - `modifying: true` runs through `$executeRawUnsafe` and the method **always**
567
+ * resolves to `number` (the count of affected rows).
568
+ *
569
+ * @example
570
+ * ```typescript
571
+ * methods: {
572
+ * findActiveUsersRaw: {
573
+ * map: true,
574
+ * query: { value: 'SELECT * FROM "user" WHERE active = $1' },
575
+ * },
576
+ * deactivateUsersOlderThanRaw: {
577
+ * map: true,
578
+ * query: { value: 'UPDATE "user" SET active = false WHERE "createdAt" < $1', modifying: true },
579
+ * },
580
+ * }
581
+ *
582
+ * // Uso:
583
+ * const users = await repo.findActiveUsersRaw<User[]>({ args: [true] });
584
+ * const affected = await repo.deactivateUsersOlderThanRaw({ args: [cutoffDate] });
585
+ * ```
586
+ */
587
+ readonly query?: {
588
+ /**
589
+ * Raw SQL statement to execute. Use positional placeholders (`$1`, `$2`, ...)
590
+ * for the values passed in `args`, never string-interpolate the values
591
+ * directly, or you'll re-introduce the SQL injection risk this API exists to avoid.
592
+ */
593
+ readonly value: string;
594
+ /**
595
+ * When `true`, executes via `$executeRawUnsafe` and the method always resolves
596
+ * to `number` (rows affected). When `false`/omitted, executes via
597
+ * `$queryRawUnsafe` and the method resolves to `TReturn` (`any` by default).
598
+ *
599
+ * @default false
600
+ */
601
+ readonly modifying?: boolean;
602
+ };
603
+ };
604
+
605
+ type BaseMethodConfig<TSelectKeys extends PropertyKey = string> = {
606
+ /** Enables or disables the base method in the `build`. */
607
+ active?: boolean;
608
+ /** Default select model used by the base method. */
609
+ defaultSelect?: TSelectKeys;
610
+ /** Ignores the `requiredWhere`. */
611
+ ignoreRequiredWhere?: boolean;
612
+ };
613
+
614
+ /**
615
+ * Configuration applied during `.build(prisma, config?)`.
616
+ *
617
+ * @template TSelectKeys Valid keys of `selectModels`.
618
+ */
619
+ export type BuildConfig<TSelectKeys extends PropertyKey = string> = {
620
+ /**
621
+ * Freezes the final repository object with `Object.freeze`.
622
+ * @deprecated No longer has any practical effect in the next version — freeze will be always applied.
623
+ */
624
+ freeze?: boolean;
625
+ /** Prints internal working logs to the console. */
626
+ showWorking?: boolean;
627
+ /** Customizes the behavior of the automatic base methods. */
628
+ baseMethods?: {
629
+ /** Configuration for the `get` method. */
630
+ get?: BaseMethodConfig<TSelectKeys>;
631
+ /** Configuration for the `getOrThrow` method. */
632
+ getOrThrow?: BaseMethodConfig<TSelectKeys>;
633
+ /** Configuration for the `getList` method (fetch by list of PKs). */
634
+ getList?: BaseMethodConfig<TSelectKeys>;
635
+ /** Configuration for the `remove` method. */
636
+ remove?: BaseMethodConfig<TSelectKeys>;
637
+ /** Configuration for the `save` method. */
638
+ save?: BaseMethodConfig<TSelectKeys>;
639
+ /** Configuration for the `saveList` method (batch save via transaction). */
640
+ saveList?: BaseMethodConfig<TSelectKeys>;
641
+ /** Configuration for the `patch` method. */
642
+ patch?: BaseMethodConfig<TSelectKeys>;
643
+ /** Configuration for the `patchList` method (batch update via transaction). */
644
+ patchList?: BaseMethodConfig<TSelectKeys>;
645
+ /** Configuration for the `merge` method. */
646
+ merge?: BaseMethodConfig<TSelectKeys>;
647
+ /** Configuration for the `removeList` method (batch deletion). Does not accept select. */
648
+ removeList?: Omit<BaseMethodConfig<TSelectKeys>, 'defaultSelect'>;
649
+ /** Configuration for the `getAll` method (full listing). */
650
+ getAll?: BaseMethodConfig<TSelectKeys>;
651
+ /** Configuration for the `total` method (count). Does not accept select. */
652
+ total?: Omit<BaseMethodConfig<TSelectKeys>, 'defaultSelect'>;
653
+ /** Configuration for the `has` method (existence check). Does not accept select. */
654
+ has?: Omit<BaseMethodConfig<TSelectKeys>, 'defaultSelect'>;
655
+ /** Configuration for the `softRemove` method. Only available if `softRemovekName` is configured. */
656
+ softRemove?: BaseMethodConfig<TSelectKeys>;
657
+ /** Configuration for the `softRemoveList` method. Does not accept select. Only available if `softRemovekName` is configured. */
658
+ softRemoveList?: Omit<BaseMethodConfig<TSelectKeys>, 'defaultSelect'>;
659
+ /** Configuration for the `restore` method. Only available if `softRemovekName` is configured. */
660
+ restore?: BaseMethodConfig<TSelectKeys>;
661
+ /** Configuration for the `restoreList` method. Does not accept select. Only available if `softRemovekName` is configured. */
662
+ restoreList?: Omit<BaseMethodConfig<TSelectKeys>, 'defaultSelect'>;
663
+ };
664
+ };
665
+
666
+ type ResolveMethodDefaultSelect<Config, C, Method extends keyof NonNullable<BuildConfig['baseMethods']>, TSelects = ExtractSelectModels<Config>> =
667
+ C extends { baseMethods?: { [_ in Method]?: { defaultSelect?: infer D } } }
668
+ ? D extends keyof TSelects
669
+ ? D
670
+ : ExtractDefaultSelect<Config> extends keyof TSelects
671
+ ? ExtractDefaultSelect<Config>
672
+ : false
673
+ : ExtractDefaultSelect<Config> extends keyof TSelects
674
+ ? ExtractDefaultSelect<Config>
675
+ : false;
676
+
677
+ type ResolveCurrentReturn<M extends PrismaModelName, Models, S, D, IM = never, Includes = {}, RI = never> =
678
+ [RI] extends [never]
679
+ ? [IM] extends [never]
680
+ ? [S] extends [false]
681
+ ? FullModelType<M>
682
+ : [S] extends [never]
683
+ ? ([D] extends [never] ? FullModelType<M> : SelectedModel<M, D, Models>)
684
+ : SelectedModel<M, S, Models>
685
+ : IM extends keyof Includes
686
+ ? PrecomputedIncludes<M, Includes>[IM]
687
+ : FullModelType<M>
688
+ : Prisma.Result<PrismaDelegate<M>, { include: RI }, 'findMany'> extends Array<infer U> ? U : never;
689
+
690
+ // ─── helpers reused within the mapped type ───────────────────────────────────
691
+ // ─── relation payload types ──────────────────────────────────────────────────
692
+
693
+ /**
694
+ * Distributive version of `Omit`, preserving unions when removing properties.
695
+ */
696
+ export type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
697
+ type ExtractUnionProp<T, K extends PropertyKey> = T extends any ? (K extends keyof T ? T[K] : never) : never;
698
+
699
+ export type ExtractNestedCreateInput<M extends PrismaModelName, K extends PropertyKey> =
700
+ NonNullable<ExtractUnionProp<PrismaModelInputs<M>['createInput'], K>> extends { create?: infer C }
701
+ ? Exclude<C, any[]>
702
+ : never;
703
+
704
+ export type RelationPayload<TField, TRelationConfig, M extends PrismaModelName, K extends PropertyKey> = NonNullable<TField> extends any[]
705
+ ? ExtractNestedCreateInput<M, K>[]
706
+ : NonNullable<TField> extends object
707
+ ? ExtractNestedCreateInput<M, K> | (TRelationConfig extends { mode: 'oto'; restriction: 'set' } | { mode: 'mto'; nullable: true } | { mode: 'mto'; nullAble: true } ? null : never)
708
+ : never;
709
+
710
+ export type TransformCreatePayload<U, T, M extends PrismaModelName, TRelations> =
711
+ Omit<U, keyof TRelations> &
712
+ {
713
+ // Fields that are REQUIRED in this specific branch of the Prisma union
714
+ [K in Extract<keyof TRelations, keyof U> as {} extends Pick<U, K> ? never : K]:
715
+ K extends keyof T ? RelationPayload<T[K], TRelations[K], M, K> : never;
716
+ } &
717
+ {
718
+ // Fields that are OPTIONAL in this branch or do not originally belong to it
719
+ [K in keyof TRelations as K extends keyof U ? ({} extends Pick<U, K> ? K : never) : K]?:
720
+ K extends keyof T ? RelationPayload<T[K], TRelations[K], M, K> : never;
721
+ };
722
+
723
+ /**
724
+ * Payload accepted by `save` when the repository has configured relations.
725
+ */
726
+ export type UpsertWithRelations<T, M extends PrismaModelName, TRelations> =
727
+ ModelUpsertInput<M> extends infer U
728
+ ? U extends any
729
+ ? Simplify<TransformCreatePayload<U, T, M, TRelations>>
730
+ : never
731
+ : never;
732
+
733
+ export type CleanNestedInput<T> = T extends any
734
+ ? T extends { data: infer D }
735
+ ? CleanNestedInput<Exclude<D, any[]>>
736
+ : Omit<T, 'where' | 'data'>
737
+ : never;
738
+
739
+ export type ExtractNestedUpdateInput<M extends PrismaModelName, K extends PropertyKey> =
740
+ NonNullable<ExtractUnionProp<PrismaModelInputs<M>['updateInput'], K>> extends { update?: infer U }
741
+ ? CleanNestedInput<Exclude<U, any[]>>
742
+ : never;
743
+
744
+ export type RelationUpdatePayload<TField, TRelationConfig, M extends PrismaModelName, K extends PropertyKey> = NonNullable<TField> extends any[]
745
+ ? ExtractNestedUpdateInput<M, K>[]
746
+ : NonNullable<TField> extends object
747
+ ? ExtractNestedUpdateInput<M, K> | (TRelationConfig extends { mode: 'oto'; restriction: 'set' } | { mode: 'mto'; nullable: true } | { mode: 'mto'; nullAble: true } ? null : never)
748
+ : never;
749
+
750
+ /**
751
+ * Payload accepted by `merge` when the repository has configured relations (uses update input).
752
+ */
753
+ export type UpdateWithRelations<T, M extends PrismaModelName, TRelations> =
754
+ DistributiveOmit<PrismaModelInputs<M>['updateInput'], keyof TRelations> & {
755
+ [K in Extract<keyof TRelations, keyof T>]?: RelationUpdatePayload<T[K], TRelations[K], M, K>;
756
+ };
757
+
758
+ /**
759
+ * Payload accepted by `patch` and `patchList` when the repository has configured relations (uses create input).
760
+ */
761
+ export type PatchWithRelations<T, M extends PrismaModelName, TRelations> =
762
+ DistributiveOmit<PrismaModelInputs<M>['updateInput'], keyof TRelations> & {
763
+ [K in Extract<keyof TRelations, keyof T>]?: RelationPayload<T[K], TRelations[K], M, K>;
764
+ };
765
+
766
+ /**
767
+ * Extracts the payload type of the `save` method from a configured VSRepository instance.
768
+ */
769
+ export type SaveObject<TInput, TRepo> =
770
+ TRepo extends VSRepository<infer T, infer M, infer Config>
771
+ ? (Config extends { relations: infer R } ? (R extends object ? R : {}) : {}) extends infer TRelations
772
+ ? TInput extends infer U
773
+ ? U extends any
774
+ ? Simplify<TransformCreatePayload<U, T, M, TRelations>>
775
+ : never
776
+ : never
777
+ : never
778
+ : never;
779
+
780
+ /**
781
+ * Extracts the payload type of the `patch` method from a configured VSRepository instance.
782
+ */
783
+ export type PatchObject<TInput, TRepo> =
784
+ TRepo extends VSRepository<infer T, infer M, infer Config>
785
+ ? (Config extends { relations: infer R } ? (R extends object ? R : {}) : {}) extends infer TRelations
786
+ ? DistributiveOmit<TInput, keyof TRelations> & {
787
+ [K in Extract<keyof TRelations, keyof T>]?: RelationPayload<T[K], TRelations[K], M, K>;
788
+ }
789
+ : never
790
+ : never;
791
+
792
+
793
+ type _Pk<T, Config> = WidenField<T[ExtractPkName<T, Config> extends keyof T ? ExtractPkName<T, Config> : never]>;
794
+ type _Ret<M extends PrismaModelName, TSelects, S, TDefault, IM = never, TIncludes = {}, RI = never> = ResolveCurrentReturn<M, TSelects, S, TDefault, IM, TIncludes, RI>;
795
+ type _DS<Config, C, Method extends keyof NonNullable<BuildConfig['baseMethods']>, TSelects = ExtractSelectModels<Config>> =
796
+ ResolveMethodDefaultSelect<Config, C, Method, TSelects>;
797
+ type _Sel<Config> = ExtractSelectModels<Config>;
798
+ type _Inc<Config> = ExtractIncludeModels<Config>;
799
+ type _Def<Config> = ExtractDefaultSelect<Config>;
800
+ type _Rel<Config> = ExtractRelations<Config>;
801
+ type _Soft<Config> = ExtractSoftRemovekName<Config>;
802
+ type _DOrd<Config> = ExtractDefaultOrdenation<Config>;
803
+
804
+ // ─── refactored mapped type — optimized for the TS compiler ──────────────────
805
+
806
+ type AllBaseMethods<
807
+ T,
808
+ M extends PrismaModelName,
809
+ Config,
810
+ C extends BuildConfig<any> | undefined,
811
+ TSelects = _Sel<Config>,
812
+ TDefault = _Def<Config>,
813
+ TPk = ExtractPkName<T, Config>,
814
+ TRelations = _Rel<Config>,
815
+ TSoftKey = _Soft<Config>,
816
+ I = PrismaModelInputs<M>,
817
+ TDefaultOrdenation = _DOrd<Config>,
818
+ TIncludes = _Inc<Config>
819
+ > = {
820
+ /** Fetches a record by its primary key (PK). */
821
+ get: <S extends keyof TSelects | false = _DS<Config, C, 'get', TSelects>, IM extends keyof TIncludes = never, RI extends IncludeModel<M> = never>(
822
+ pk: _Pk<T, Config>, options?: MethodOptionsWithInclude<S, IM, TIncludes, M, RI>
823
+ ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes, RI> | null>;
824
+
825
+ /** Fetches a record by PK and throws `VSRepoRuntimeError` if not found. */
826
+ getOrThrow: <S extends keyof TSelects | false = _DS<Config, C, 'getOrThrow', TSelects>, IM extends keyof TIncludes = never, RI extends IncludeModel<M> = never>(
827
+ pk: _Pk<T, Config>, options?: MethodOptionsWithInclude<S, IM, TIncludes, M, RI>
828
+ ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes, RI>>;
829
+
830
+ /** Fetches multiple records by a list of primary keys (PKs). */
831
+ getList: <S extends keyof TSelects | false = _DS<Config, C, 'getList', TSelects>, IM extends keyof TIncludes = never, RI extends IncludeModel<M> = never>(
832
+ pks: _Pk<T, Config>[], options?: MethodOptionsWithInclude<S, IM, TIncludes, M, RI>
833
+ ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes, RI>[]>;
834
+
835
+ /** Deletes a record identified by its primary key (PK). */
836
+ remove: <S extends keyof TSelects | false = _DS<Config, C, 'remove', TSelects>, IM extends keyof TIncludes = never, RI extends IncludeModel<M> = never>(
837
+ pk: _Pk<T, Config>, options?: MethodOptionsWithInclude<S, IM, TIncludes, M, RI>
838
+ ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes, RI>>;
839
+
840
+ /** Inserts or updates (upsert) a record. */
841
+ save: <S extends keyof TSelects | false = _DS<Config, C, 'save', TSelects>, IM extends keyof TIncludes = never, RI extends IncludeModel<M> = never>(
842
+ obj: UpsertWithRelations<T, M, TRelations>, options?: MethodOptionsWithInclude<S, IM, TIncludes, M, RI>
843
+ ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes, RI>>;
844
+
845
+ /** Saves an array of objects in a single automatic transaction. */
846
+ saveList: <S extends keyof TSelects | false = _DS<Config, C, 'saveList', TSelects>, IM extends keyof TIncludes = never, RI extends IncludeModel<M> = never>(
847
+ objs: UpsertWithRelations<T, M, TRelations>[], options?: MethodOptionsWithInclude<S, IM, TIncludes, M, RI, 'db'> & { db?: DbTransaction }
848
+ ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes, RI>[]>;
849
+
850
+ /** Partially updates (patch) an existing record by its primary key (PK). */
851
+ patch: <S extends keyof TSelects | false = _DS<Config, C, 'patch', TSelects>, IM extends keyof TIncludes = never, RI extends IncludeModel<M> = never>(
852
+ pk: _Pk<T, Config>, obj: PatchWithRelations<T, M, TRelations>, options?: MethodOptionsWithInclude<S, IM, TIncludes, M, RI>
853
+ ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes, RI>>;
854
+
855
+ /** Partially updates multiple records via `[pk, obj]` tuples in an automatic transaction. */
856
+ patchList: <S extends keyof TSelects | false = _DS<Config, C, 'patchList', TSelects>, IM extends keyof TIncludes = never, RI extends IncludeModel<M> = never>(
857
+ tuples: [pk: _Pk<T, Config>, obj: PatchWithRelations<T, M, TRelations>][], options?: MethodOptionsWithInclude<S, IM, TIncludes, M, RI, 'db'> & { db?: DbTransaction }
858
+ ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes, RI>[]>;
859
+
860
+ /** Fetches a record by PK and deep-merges it with the provided object **in memory**. */
861
+ merge: <S extends keyof TSelects | false = _DS<Config, C, 'merge', TSelects>, IM extends keyof TIncludes = never, RI extends IncludeModel<M> = never>(
862
+ pk: _Pk<T, Config>, obj: UpdateWithRelations<T, M, TRelations>, options?: MethodOptionsWithInclude<S, IM, TIncludes, M, RI>
863
+ ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes, RI> | null>;
864
+
865
+ /** Deletes multiple records by their primary keys. */
866
+ removeList: (pks: _Pk<T, Config>[], options?: { db?: ClientOrTransaction }) => Promise<{ count: number }>;
867
+
868
+ /** Fetches all records (respects `requiredWhere` when set). */
869
+ getAll: <S extends keyof TSelects | false = _DS<Config, C, 'getAll', TSelects>, IM extends keyof TIncludes = never, RI extends IncludeModel<M> = never>(
870
+ options?: MethodOptionsWithInclude<S, IM, TIncludes, M, RI> & {
871
+ pagination?: PaginationOptions<I extends { cursorInput: infer Curs } ? Curs : unknown>;
872
+ /**
873
+ * Ordering to apply to the query.
874
+ * When omitted and `defaultOrdenation` is configured on the repository,
875
+ * the default ordering is applied automatically.
876
+ */
877
+ order?: I extends { orderByInput: infer OB } ? OB : OrderOptions;
878
+ }
879
+ ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes, RI>[]>;
880
+
881
+ /** Returns the total number of records. */
882
+ total: (options?: { db?: ClientOrTransaction; see?: SeeMode }) => Promise<number>;
883
+
884
+ /** Checks whether a record exists by its primary key (PK). */
885
+ has: (pk: _Pk<T, Config>, options?: { db?: ClientOrTransaction; see?: SeeMode }) => Promise<boolean>;
886
+
887
+ /** Marks a record as deleted (soft-delete). */
888
+ softRemove: <S extends keyof TSelects | false = _DS<Config, C, 'softRemove', TSelects>, IM extends keyof TIncludes = never, RI extends IncludeModel<M> = never>(
889
+ pk: _Pk<T, Config>, options?: MethodOptionsWithInclude<S, IM, TIncludes, M, RI, 'see'>
890
+ ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes, RI>>;
891
+
892
+ /** Marks multiple records as deleted (soft-delete) in batch. */
893
+ softRemoveList: (pks: _Pk<T, Config>[], options?: { db?: ClientOrTransaction }) => Promise<{ count: number }>;
894
+
895
+ /** Restores a record previously marked as deleted (soft-delete). */
896
+ restore: <S extends keyof TSelects | false = _DS<Config, C, 'restore', TSelects>, IM extends keyof TIncludes = never, RI extends IncludeModel<M> = never>(
897
+ pk: _Pk<T, Config>, options?: MethodOptionsWithInclude<S, IM, TIncludes, M, RI, 'see'>
898
+ ) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes, RI>>;
899
+
900
+ /** Restores multiple records previously marked as deleted (soft-delete) in batch. */
901
+ restoreList: (pks: _Pk<T, Config>[], options?: { db?: ClientOrTransaction }) => Promise<{ count: number }>;
902
+ };
903
+
904
+ type InjectedBaseMethods<
905
+ T,
906
+ M extends PrismaModelName,
907
+ Config,
908
+ C extends BuildConfig<any> | undefined,
909
+ TSelects = _Sel<Config>,
910
+ TDefault = _Def<Config>,
911
+ TPk = ExtractPkName<T, Config>,
912
+ TRelations = _Rel<Config>,
913
+ TSoftKey = _Soft<Config>,
914
+ I = PrismaModelInputs<M>,
915
+ TDefaultOrdenation = _DOrd<Config>,
916
+ TIncludes = _Inc<Config>
917
+ > = Pick<
918
+ AllBaseMethods<T, M, Config, C, TSelects, TDefault, TPk, TRelations, TSoftKey, I, TDefaultOrdenation, TIncludes>,
919
+ | (C extends { baseMethods: { get: { active: false } } } ? never : 'get')
920
+ | (C extends { baseMethods: { getOrThrow: { active: false } } } ? never : 'getOrThrow')
921
+ | (C extends { baseMethods: { getList: { active: false } } } ? never : 'getList')
922
+ | (C extends { baseMethods: { remove: { active: false } } } ? never : 'remove')
923
+ | (C extends { baseMethods: { save: { active: false } } } ? never : 'save')
924
+ | (C extends { baseMethods: { saveList: { active: false } } } ? never : 'saveList')
925
+ | (C extends { baseMethods: { patch: { active: false } } } ? never : 'patch')
926
+ | (C extends { baseMethods: { patchList: { active: false } } } ? never : 'patchList')
927
+ | (C extends { baseMethods: { merge: { active: false } } } ? never : 'merge')
928
+ | (C extends { baseMethods: { removeList: { active: false } } } ? never : 'removeList')
929
+ | (C extends { baseMethods: { getAll: { active: false } } } ? never : 'getAll')
930
+ | (C extends { baseMethods: { total: { active: false } } } ? never : 'total')
931
+ | (C extends { baseMethods: { has: { active: false } } } ? never : 'has')
932
+ | ([TSoftKey] extends [never] ? never : C extends { baseMethods: { softRemove: { active: false } } } ? never : 'softRemove')
933
+ | ([TSoftKey] extends [never] ? never : C extends { baseMethods: { softRemoveList: { active: false } } } ? never : 'softRemoveList')
934
+ | ([TSoftKey] extends [never] ? never : C extends { baseMethods: { restore: { active: false } } } ? never : 'restore')
935
+ | ([TSoftKey] extends [never] ? never : C extends { baseMethods: { restoreList: { active: false } } } ? never : 'restoreList')
936
+ >;
937
+
938
+
939
+ /**
940
+ * Relation configuration for One-to-Many or Many-to-Many.
941
+ *
942
+ * @template TItem Type of the related entity.
943
+ */
944
+ export type ManyRelationConfig<TItem> = {
945
+ /** Primary key of the related entity. */
946
+ pk: keyof TItem;
947
+ /** Relation type: `otm` (One-to-Many) or `mtm` (Many-to-Many). */
948
+ mode: 'otm' | 'mtm';
949
+ /** Mutation behavior: `set` (replaces all) or `add` (appends to existing). */
950
+ restriction: 'set' | 'add';
951
+ };
952
+
953
+ /**
954
+ * One-to-One relation configuration.
955
+ *
956
+ * @template TItem Type of the related entity.
957
+ */
958
+ export type OneToOneRelationConfig<TItem> = {
959
+ /** Primary key of the related entity. */
960
+ pk: keyof TItem;
961
+ /** Relation type: `oto` (One-to-One). */
962
+ mode: 'oto';
963
+ /** Allowed mutation behavior for saving. */
964
+ restriction: 'set' | 'add';
965
+ };
966
+
967
+ /**
968
+ * Many-to-One relation configuration.
969
+ *
970
+ * @template TItem Type of the related entity.
971
+ */
972
+ export type ManyToOneRelationConfig<TItem> = {
973
+ /** Primary key of the related entity. */
974
+ pk: keyof TItem;
975
+ /** Relation type: `mto` (Many-to-One). */
976
+ mode: 'mto';
977
+ /** Allowed mutation behavior for saving. */
978
+ restriction: 'set' | 'add';
979
+ /**
980
+ * Enables the ability to unlink the relation, setting the foreign key to null.
981
+ * @deprecated Use `nullable` (lowercase) instead of `nullAble`.
982
+ */
983
+ nullAble?: boolean;
984
+ /** Enables the ability to unlink the relation, setting the foreign key to null. */
985
+ nullable?: boolean;
986
+ };
987
+
988
+ /**
989
+ * Automatically infers the possible relation configuration from a field.
990
+ */
991
+ export type ExtractRelationConfig<TField> = NonNullable<TField> extends infer NonNull
992
+ ? NonNull extends Date | Buffer | Uint8Array | Decimal | JsonValue ? never
993
+ : NonNull extends any[] ? (NonNull[number] extends object ? ManyRelationConfig<NonNull[number]> : never)
994
+ : NonNull extends object ? (OneToOneRelationConfig<NonNull> | ManyToOneRelationConfig<NonNull>)
995
+ : never
996
+ : never;
997
+
998
+ /**
999
+ * Map of configurable relations for an entity type.
1000
+ */
1001
+ export type RepositoryRelations<T> = {
1002
+ [K in keyof T as ExtractRelationConfig<T[K]> extends never ? never : K]?: ExtractRelationConfig<T[K]>;
1003
+ };
1004
+
1005
+ type AnySelect<M extends PrismaModelName> = Prisma.TypeMap['model'][M]['operations']['findMany']['args']['select'];
1006
+
1007
+ /**
1008
+ * Main configuration used in `setupVSRepo<T, M>()(config)`.
1009
+ *
1010
+ * @template T Type of the entity managed by the repository.
1011
+ * @template M Prisma model name.
1012
+ * @template SM Map of named select models.
1013
+ */
1014
+ export type RepoConfig<T, M extends PrismaModelName, SM extends Record<string, AnySelect<M>> = Record<string, AnySelect<M>>> = {
1015
+ tableName: Uncapitalize<M>;
1016
+ pkName: keyof T;
1017
+ softRemovekName?: keyof T & string;
1018
+ selectModels?: SM;
1019
+ defaultSelectModel?: Extract<keyof SM, string>;
1020
+ includeModels?: IncludeModels<M>;
1021
+ requiredWhere?: WhereModel<M>;
1022
+ defaultOrdenation?: OrdenationModel<M>;
1023
+ relations?: RepositoryRelations<T>;
1024
+ methods?: Record<string, MethodConfig<M, SM>>;
1025
+ };
1026
+
1027
+ /**
1028
+ * Final type returned by `.build(prisma)`.
1029
+ *
1030
+ * Combines dynamic methods, base methods, and custom extensions.
1031
+ */
1032
+ type BuiltRepository<T extends object, M extends PrismaModelName, Config extends RepoConfig<T, M, any>, C extends BuildConfig<any> | undefined> = {
1033
+ /**
1034
+ * Extends the repository with custom methods without losing type inference.
1035
+ */
1036
+ extend<E>(extensionFunc: (repo: BuiltRepository<T, M, Config, C>) => E): BuiltRepository<T, M, Config, C> & E;
1037
+
1038
+ /**
1039
+ * The Prisma Client instance passed to `build`.
1040
+ */
1041
+ readonly prisma: DbClient;
1042
+ } & DynamicMethods<T, M, Config, PrismaModelInputs<M>> & InjectedBaseMethods<T, M, Config, C>;
1043
+
1044
+ /**
1045
+ * Typed repository factory based on the Prisma model configuration.
1046
+ */
1047
+ export declare class VSRepository<T extends object, M extends PrismaModelName, const Config extends RepoConfig<T, M, any> = RepoConfig<T, M, any>> {
1048
+ /** Original configuration provided to `setupVSRepo`. */
1049
+ readonly config: Config;
1050
+ /**
1051
+ * Creates a configurable instance of `VSRepository`.
1052
+ */
1053
+ constructor(config: Config);
1054
+ /**
1055
+ * Builds the final repository with base and dynamic methods.
1056
+ */
1057
+ build<C extends BuildConfig<keyof ExtractSelectModels<Config>>>(prisma: DbClient, config?: C): BuiltRepository<T, M, Config, C>;
1058
+ vsrepocache: never;
1059
+ }
1060
+
1061
+ /**
1062
+ * Infers the type of an already-configured repository from a `VSRepository` instance.
1063
+ *
1064
+ * Also allows manually providing the `BuildConfig` and extensions type.
1065
+ */
1066
+ export type RepositoryOf<TRepo, C extends BuildConfig<any> | undefined = undefined, E = unknown> =
1067
+ TRepo extends VSRepository<infer T, infer M, infer Config>
1068
+ ? Simplify<BuiltRepository<T, M, Config, C> & E>
1069
+ : never;
1070
+
1071
+ /**
1072
+ * Utility type used to validate a repository configuration at compile time.
1073
+ */
1074
+ export type ValidateRepoConfig<T extends object, M extends PrismaModelName, Config> = {
1075
+ /**
1076
+ * Name of the table mapped by Prisma (usually uncapitalized).
1077
+ */
1078
+ tableName: Uncapitalize<M>;
1079
+
1080
+ /**
1081
+ * Name of the field that represents the entity's primary key (Primary Key).
1082
+ */
1083
+ pkName: keyof T;
1084
+
1085
+ /**
1086
+ * Name of the `DateTime` field used for soft-delete.
1087
+ *
1088
+ * When configured, enables the `softRemove`, `softRemoveList`, `restore`, and `restoreList` methods.
1089
+ * The field **must** be of type `DateTime` in the Prisma schema — VSRepository validates this during `build`.
1090
+ */
1091
+ softRemovekName?: keyof T & string;
1092
+
1093
+ /**
1094
+ * Defines named and reusable data projections (selects).
1095
+ * Allows creating different views of the same entity (e.g., `public`, `minimal`, `internal`).
1096
+ */
1097
+ selectModels?: SelectModels<M>;
1098
+
1099
+ /**
1100
+ * Defines which select (a key from `selectModels`) will be used automatically
1101
+ * when none is specified in the method call.
1102
+ * It is highly recommended to define it whenever `selectModels` are used.
1103
+ */
1104
+ defaultSelectModel?: string;
1105
+
1106
+ /**
1107
+ * Defines named and reusable include projections.
1108
+ * Similar to selectModels, but resolves Prisma `include` clauses.
1109
+ */
1110
+ includeModels?: IncludeModels<M>;
1111
+
1112
+ /**
1113
+ * Defines global filters that will be automatically applied to all repository queries.
1114
+ * Useful for tenant isolation (multi-tenancy) or base restrictions (e.g., `isActive: true`).
1115
+ */
1116
+ requiredWhere?: WhereModel<M>;
1117
+
1118
+ /**
1119
+ * Default ordering automatically injected into all queries that accept `orderBy`,
1120
+ * unless the method already has `injectOrdenation` configured or uses the `Ordered` suffix.
1121
+ *
1122
+ * Useful for ensuring a consistent sort order across the repository without repeating
1123
+ * the `order` argument on every call.
1124
+ */
1125
+ defaultOrdenation?: OrdenationModel<M>;
1126
+
1127
+ /**
1128
+ * Configures automatic relation management.
1129
+ * When configured, allows the `save`, `saveList`, `patch`, and `patchList` methods
1130
+ * to automatically handle linking, creation, or cascading deletion of related records.
1131
+ */
1132
+ relations?: RepositoryRelations<T>;
1133
+
1134
+ /**
1135
+ * Definition of dynamic repository methods.
1136
+ * Behaviors and return types are automatically inferred from the method's name
1137
+ * (e.g., `findOneByEmail`, `findManyPaginated`) or proxied via the `proxyTo` property.
1138
+ */
1139
+ methods?: {
1140
+ [K in keyof (Config extends { methods: infer Meth } ? Meth : {})]: K extends string
1141
+ ? MethodConfig<M, Config extends { selectModels: infer SM } ? SM : any> &
1142
+ (K extends ValidMethodPatterns
1143
+ ? {}
1144
+ : (Config extends { methods: infer Meth }
1145
+ ? (K extends keyof Meth ? Meth[K] : never)
1146
+ : never) extends { query: any }
1147
+ ? {}
1148
+ : { proxyTo: ValidMethodPatterns })
1149
+ : never;
1150
+ };
1151
+ };
1152
+
1153
+ /**
1154
+ * Function to initialize and configure the `repository`.
1155
+ * The configuration passed here is what will be read when `.build()` is called.
1156
+ */
1157
+ export declare function setupVSRepo<T extends object, M extends PrismaModelName>(): <
1158
+ const SM extends Record<string, SelectModel<M>>,
1159
+ const Config extends RepoConfig<T, M, SM>
1160
+ >(
1161
+ config: Config & ValidateRepoConfig<T, M, Config>
1162
+ ) => VSRepository<T, M, Config>;