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