vsrepo 1.3.4 → 1.3.6
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 +181 -137
- package/README.pt-BR.md +188 -144
- package/dist/DynamicRepository.d.ts +36 -15
- package/dist/VSRepoError.d.ts +21 -1
- package/dist/VSRepository.d.ts +126 -87
- package/dist/VSRepository.js +49 -49
- package/dist/internal/constants/dynamic-methods-key.constant.js +4 -0
- package/dist/internal/decorators/dynamic-method.decorator.js +4 -4
- package/dist/internal/decorators/query-method.decorator.js +7 -3
- package/dist/internal/entities/dynamic-method-metadata.entity.js +3 -3
- package/dist/internal/resolvers/base-methods.resolve.js +2 -2
- package/dist/internal/resolvers/dbAndPrismaArgs.resolve.js +7 -4
- package/dist/internal/resolvers/dynamic-method-customization.resolve.js +57 -0
- package/dist/internal/resolvers/dynamic-method-info.resolve.js +279 -0
- package/dist/internal/resolvers/dynamic-methods-metadata.resolve.js +2 -2
- package/dist/internal/resolvers/pretty-wheres.resolve.js +8 -8
- package/dist/internal/resolvers/types/dynamic-method-where-ops.type.js +2 -0
- package/dist/internal/utils/schemas.util.js +8 -2
- package/dist/internal/validation/constructor-config.validate.js +7 -4
- package/dist/internal/validation/method-options.validate.js +10 -3
- package/package.json +11 -2
- package/scripts/configure-prisma-import.mjs +12 -8
- package/scripts/copy-types.mjs +16 -16
- package/dist/internal/constants/dinamic-methods-key.constant.js +0 -4
- package/dist/internal/resolvers/dinamic-method-customization.resolve.js +0 -57
- package/dist/internal/resolvers/dinamic-method-info.resolve.js +0 -279
- /package/dist/internal/{resolvers/types/dinamic-method-customization.type.js → errors/types/vs-repo-runtime-error-code.type.js} +0 -0
- /package/dist/internal/resolvers/types/{dinamic-method-info.type.js → dynamic-method-customization.type.js} +0 -0
- /package/dist/internal/resolvers/types/{dinamic-method-where-ops.type.js → dynamic-method-info.type.js} +0 -0
|
@@ -8,13 +8,14 @@ import {
|
|
|
8
8
|
ExtractNestedUpdateInput,
|
|
9
9
|
IncludeModel,
|
|
10
10
|
ModelUpsertInput,
|
|
11
|
-
|
|
11
|
+
OrderingModel,
|
|
12
12
|
PaginationModel,
|
|
13
13
|
PaginationOptions,
|
|
14
14
|
PrismaModelInputs,
|
|
15
15
|
PrismaModelName,
|
|
16
16
|
RepositoryRelations,
|
|
17
17
|
SeeMode,
|
|
18
|
+
SelectModel,
|
|
18
19
|
WhereModel,
|
|
19
20
|
} from "./VSRepository.d";
|
|
20
21
|
|
|
@@ -157,8 +158,11 @@ export type DynamicMethodOptions<TName extends PrismaModelName = PrismaModelName
|
|
|
157
158
|
*/
|
|
158
159
|
see?: SeeMode;
|
|
159
160
|
|
|
160
|
-
/** Raw Prisma `include`. */
|
|
161
|
+
/** Raw Prisma `include`. Cannot be used together with `select`. */
|
|
161
162
|
include?: IncludeModel<TName>;
|
|
163
|
+
|
|
164
|
+
/** Raw Prisma `select`. Cannot be used together with `include`. */
|
|
165
|
+
select?: SelectModel<TName>;
|
|
162
166
|
};
|
|
163
167
|
|
|
164
168
|
/**
|
|
@@ -220,12 +224,23 @@ export interface DynamicRepositoryConstructorConfig<T, U extends PrismaModelName
|
|
|
220
224
|
|
|
221
225
|
/**
|
|
222
226
|
* Default ordering automatically injected into all queries that accept `orderBy`,
|
|
223
|
-
* unless the method already has `
|
|
227
|
+
* unless the method already has `injectOrdering` configured or uses the `Ordered` suffix.
|
|
228
|
+
*
|
|
229
|
+
* Useful for ensuring a consistent sort order across the repository without repeating
|
|
230
|
+
* the `order` argument on every call.
|
|
231
|
+
*/
|
|
232
|
+
defaultOrdering?: OrderingModel<U>;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Default ordering automatically injected into all queries that accept `orderBy`,
|
|
236
|
+
* unless the method already has `injectOrdering` configured or uses the `Ordered` suffix.
|
|
224
237
|
*
|
|
225
238
|
* Useful for ensuring a consistent sort order across the repository without repeating
|
|
226
239
|
* the `order` argument on every call.
|
|
240
|
+
*
|
|
241
|
+
* @deprecated Use `defaultOrdering` instead.
|
|
227
242
|
*/
|
|
228
|
-
defaultOrdenation?:
|
|
243
|
+
defaultOrdenation?: OrderingModel<U>;
|
|
229
244
|
|
|
230
245
|
/**
|
|
231
246
|
* Configures automatic relation management.
|
|
@@ -290,7 +305,7 @@ export declare abstract class DynamicRepository<
|
|
|
290
305
|
/** Saves an array of objects in a single automatic transaction. */
|
|
291
306
|
saveList(
|
|
292
307
|
objs: DynamicSaveInput<TEntity, UName, WRelations>[],
|
|
293
|
-
options?: Omit<DynamicMethodOptions<UName>, "include"> & {
|
|
308
|
+
options?: Omit<DynamicMethodOptions<UName>, "include" | "select"> & {
|
|
294
309
|
/** Transaction client to use for this operation. */
|
|
295
310
|
db?: DbTransaction;
|
|
296
311
|
},
|
|
@@ -306,7 +321,7 @@ export declare abstract class DynamicRepository<
|
|
|
306
321
|
/** Partially updates multiple records via `[pk, obj]` tuples in an automatic transaction. */
|
|
307
322
|
patchList(
|
|
308
323
|
tuples: [pk: VPKType, obj: DynamicPatchInput<TEntity, UName, WRelations>][],
|
|
309
|
-
options?: Omit<DynamicMethodOptions<UName>, "include"> & {
|
|
324
|
+
options?: Omit<DynamicMethodOptions<UName>, "include" | "select"> & {
|
|
310
325
|
/** Transaction client to use for this operation. */
|
|
311
326
|
db?: DbTransaction;
|
|
312
327
|
},
|
|
@@ -322,7 +337,7 @@ export declare abstract class DynamicRepository<
|
|
|
322
337
|
/** Deletes multiple records by their primary keys. */
|
|
323
338
|
removeList(
|
|
324
339
|
pks: VPKType[],
|
|
325
|
-
options?: Omit<DynamicMethodOptions<UName>, "include">,
|
|
340
|
+
options?: Omit<DynamicMethodOptions<UName>, "include" | "select">,
|
|
326
341
|
): Promise<{ count: number }>;
|
|
327
342
|
|
|
328
343
|
/** Fetches all records (respects `requiredWhere` when set). */
|
|
@@ -332,18 +347,18 @@ export declare abstract class DynamicRepository<
|
|
|
332
347
|
pagination?: PaginationOptions;
|
|
333
348
|
/**
|
|
334
349
|
* Ordering to apply to the query.
|
|
335
|
-
* When omitted and `
|
|
350
|
+
* When omitted and `defaultOrdering` is configured on the repository,
|
|
336
351
|
* the default ordering is applied automatically.
|
|
337
352
|
*/
|
|
338
|
-
order?:
|
|
353
|
+
order?: OrderingModel<UName>;
|
|
339
354
|
},
|
|
340
355
|
): Promise<TEntity[]>;
|
|
341
356
|
|
|
342
357
|
/** Returns the total number of records. */
|
|
343
|
-
total(options?: Omit<DynamicMethodOptions<UName>, "include">): Promise<number>;
|
|
358
|
+
total(options?: Omit<DynamicMethodOptions<UName>, "include" | "select">): Promise<number>;
|
|
344
359
|
|
|
345
360
|
/** Checks whether a record exists by its primary key (PK). */
|
|
346
|
-
has(pk: VPKType, options?: Omit<DynamicMethodOptions<UName>, "include">): Promise<boolean>;
|
|
361
|
+
has(pk: VPKType, options?: Omit<DynamicMethodOptions<UName>, "include" | "select">): Promise<boolean>;
|
|
347
362
|
|
|
348
363
|
/** Marks a record as deleted (soft-delete). */
|
|
349
364
|
softRemove(pk: VPKType, options?: Omit<DynamicMethodOptions<UName>, "see">): Promise<TEntity>;
|
|
@@ -351,7 +366,7 @@ export declare abstract class DynamicRepository<
|
|
|
351
366
|
/** Marks multiple records as deleted (soft-delete) in batch. */
|
|
352
367
|
softRemoveList(
|
|
353
368
|
pks: VPKType[],
|
|
354
|
-
options?: Omit<DynamicMethodOptions<UName>, "see" | "include">,
|
|
369
|
+
options?: Omit<DynamicMethodOptions<UName>, "see" | "include" | "select">,
|
|
355
370
|
): Promise<{ count: number }>;
|
|
356
371
|
|
|
357
372
|
/** Restores a record previously marked as deleted (soft-delete). */
|
|
@@ -360,7 +375,7 @@ export declare abstract class DynamicRepository<
|
|
|
360
375
|
/** Restores multiple records previously marked as deleted (soft-delete) in batch. */
|
|
361
376
|
restoreList(
|
|
362
377
|
pks: VPKType[],
|
|
363
|
-
options?: Omit<DynamicMethodOptions<UName>, "see" | "include">,
|
|
378
|
+
options?: Omit<DynamicMethodOptions<UName>, "see" | "include" | "select">,
|
|
364
379
|
): Promise<{ count: number }>;
|
|
365
380
|
}
|
|
366
381
|
|
|
@@ -381,7 +396,13 @@ export type DynamicMethodConfig<M extends PrismaModelName = PrismaModelName> = {
|
|
|
381
396
|
fbMode?: "one" | "list";
|
|
382
397
|
|
|
383
398
|
/** Injects a fixed ordering automatically into the query. */
|
|
384
|
-
|
|
399
|
+
injectOrdering?: OrderingModel<M>;
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Injects a fixed ordering automatically into the query.
|
|
403
|
+
* @deprecated Use `injectOrdering` instead.
|
|
404
|
+
*/
|
|
405
|
+
injectOrdenation?: OrderingModel<M>;
|
|
385
406
|
|
|
386
407
|
/** Injects a fixed pagination automatically into the query. */
|
|
387
408
|
injectPagination?: PaginationModel<M>;
|
|
@@ -402,7 +423,7 @@ export type DynamicMethodConfig<M extends PrismaModelName = PrismaModelName> = {
|
|
|
402
423
|
* `@DynamicMethod()`
|
|
403
424
|
* declare findOneByEmail: (email: string) => Promise<User | null>;
|
|
404
425
|
*
|
|
405
|
-
* @DynamicMethod<"User">({
|
|
426
|
+
* @DynamicMethod<"User">({ injectOrdering: { createdAt: "desc" } })
|
|
406
427
|
* declare findByAge: (email: number) => Promise<User[]>;
|
|
407
428
|
* }
|
|
408
429
|
* ```
|
package/dist/VSRepoError.d.ts
CHANGED
|
@@ -8,6 +8,24 @@ export type VSRepoErrorType =
|
|
|
8
8
|
| 'VSREPO_RUNTIME'
|
|
9
9
|
| 'VSREPO_DECORATOR';
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Catalog of the internal codes used by `VSRepoRuntimeError`. Each code identifies
|
|
13
|
+
* a category of runtime failure, so consuming code can discriminate on
|
|
14
|
+
* `error.code` without parsing the (human-readable) message. See the
|
|
15
|
+
* "Error handling" section of the README for the full description of each code.
|
|
16
|
+
*/
|
|
17
|
+
export type VSRepoRuntimeErrorCode =
|
|
18
|
+
/** A required argument is missing or has an invalid shape (e.g. missing `pk`, `pks`/`objs`/`tuples` that aren't an array, or `options`/`obj` that isn't a valid object). */
|
|
19
|
+
| '65706'
|
|
20
|
+
/** No record was found for the provided primary key (`getOrThrow` when fetching the base record). */
|
|
21
|
+
| '20727'
|
|
22
|
+
/** Validation (zod) of a method's `options`, or of a `@QueryMethod` argument, failed. */
|
|
23
|
+
| '67542'
|
|
24
|
+
/** A relation passed to `save`/`patch`/`merge` has an invalid shape for the configured `mode`/`restriction`. */
|
|
25
|
+
| '91868'
|
|
26
|
+
/** A dynamic method (`config.methods`) was called with fewer positional arguments than its `where` fields require. */
|
|
27
|
+
| '48670';
|
|
28
|
+
|
|
11
29
|
/**
|
|
12
30
|
* Base class for all errors thrown by the VSRepository.
|
|
13
31
|
*/
|
|
@@ -59,5 +77,7 @@ export declare class VSRepoDecoratorError extends VSRepoError {
|
|
|
59
77
|
*/
|
|
60
78
|
export declare class VSRepoRuntimeError extends VSRepoError {
|
|
61
79
|
readonly type: 'VSREPO_RUNTIME';
|
|
62
|
-
|
|
80
|
+
/** Internal code identifying the category of runtime failure. See {@link VSRepoRuntimeErrorCode}. */
|
|
81
|
+
readonly code: VSRepoRuntimeErrorCode;
|
|
82
|
+
constructor(message: string, code: VSRepoRuntimeErrorCode);
|
|
63
83
|
}
|
package/dist/VSRepository.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export type DbTransaction = Prisma.TransactionClient;
|
|
|
30
30
|
*/
|
|
31
31
|
export type ClientOrTransaction = DbClient | DbTransaction;
|
|
32
32
|
|
|
33
|
-
export * from './VSRepoError';
|
|
33
|
+
export type * from './VSRepoError';
|
|
34
34
|
|
|
35
35
|
type OrderPattern = {
|
|
36
36
|
[key: string]: 'asc' | 'desc' | { _count: 'asc' | 'desc' } | OrderPattern;
|
|
@@ -228,20 +228,22 @@ type PrecomputedIncludes<M extends PrismaModelName, IncludeModels> = {
|
|
|
228
228
|
[I in keyof IncludeModels]: Prisma.Result<PrismaDelegate<M>, { include: IncludeModels[I] }, 'findMany'> extends Array<infer U> ? U : never
|
|
229
229
|
};
|
|
230
230
|
|
|
231
|
-
type SelectedModel<M extends PrismaModelName, S, SelectModels, IM = never, IncludeModels = {}, RI = never> =
|
|
232
|
-
[
|
|
233
|
-
? [
|
|
234
|
-
? [
|
|
235
|
-
?
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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;
|
|
245
247
|
|
|
246
248
|
/**
|
|
247
249
|
* Strips the `Distinct{Fields}` suffix used by read methods (e.g. `findManyDistinctIdadeAndCargo`).
|
|
@@ -265,7 +267,7 @@ type CleanFields<R extends string> =
|
|
|
265
267
|
* @template S Available keys in `selectModels`.
|
|
266
268
|
* @template IM Available keys in `includeModels`.
|
|
267
269
|
*/
|
|
268
|
-
export type MethodOptions<S, IM extends PropertyKey = never, M extends PrismaModelName = never, RI = never> = {
|
|
270
|
+
export type MethodOptions<S, IM extends PropertyKey = never, M extends PrismaModelName = never, RI = never, RS = never> = {
|
|
269
271
|
/** Prisma client or transaction to use for the operation. */
|
|
270
272
|
db?: ClientOrTransaction;
|
|
271
273
|
/**
|
|
@@ -287,15 +289,25 @@ export type MethodOptions<S, IM extends PropertyKey = never, M extends PrismaMod
|
|
|
287
289
|
includeModel?: never;
|
|
288
290
|
/** Raw Prisma `include`. Cannot be used together with `selectModel` or `includeModel`. */
|
|
289
291
|
include?: never;
|
|
292
|
+
/** Raw Prisma `select`. Cannot be used together with `selectModel`, `includeModel` or `include`. */
|
|
293
|
+
select?: never;
|
|
290
294
|
}
|
|
291
295
|
| {
|
|
292
296
|
selectModel?: never;
|
|
293
297
|
includeModel?: never;
|
|
294
298
|
include: RI;
|
|
299
|
+
select?: never;
|
|
300
|
+
}
|
|
301
|
+
| {
|
|
302
|
+
selectModel?: never;
|
|
303
|
+
includeModel?: never;
|
|
304
|
+
include?: never;
|
|
305
|
+
select: RS;
|
|
295
306
|
}
|
|
296
|
-
: | { selectModel?: S | false; includeModel?: never; include?: never }
|
|
297
|
-
| { selectModel?: never; includeModel: IM; include?: never }
|
|
298
|
-
| { selectModel?: never; includeModel?: never; include: RI }
|
|
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 }
|
|
299
311
|
);
|
|
300
312
|
|
|
301
313
|
/**
|
|
@@ -318,14 +330,15 @@ type MethodOptionsWithInclude<
|
|
|
318
330
|
TIncludes,
|
|
319
331
|
M extends PrismaModelName,
|
|
320
332
|
RI = never,
|
|
321
|
-
|
|
322
|
-
|
|
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>
|
|
323
336
|
& ({ includeModel: IM } | { includeModel?: never });
|
|
324
337
|
|
|
325
338
|
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>>>;
|
|
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>>>;
|
|
329
342
|
|
|
330
343
|
type GetMappedMethod<K extends string, MethodConf> =
|
|
331
344
|
K extends `findBy${string}` ? (MethodConf extends { fbMode: 'one' } ? 'findByOne' : 'findByList') :
|
|
@@ -380,9 +393,9 @@ type MethodFactory<T, M extends PrismaModelName, K extends string, SelectModels,
|
|
|
380
393
|
K extends `findWhere${string}`
|
|
381
394
|
? {
|
|
382
395
|
/** @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>>>;
|
|
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>>>;
|
|
386
399
|
}
|
|
387
400
|
: MethodFn<GetMappedMethod<K, MethodConf>, T, M, ExtractPatternBase<K>, SelectModels, DefaultSelect, I, IncludeModels>;
|
|
388
401
|
|
|
@@ -396,7 +409,7 @@ type ExtractIncludeModels<Config> = Config extends { includeModels: infer IM } ?
|
|
|
396
409
|
type ExtractDefaultSelect<Config> = Config extends { defaultSelectModel: infer D } ? D : never;
|
|
397
410
|
type ExtractRelations<Config> = Config extends { relations: infer R } ? (R extends object ? R : {}) : {};
|
|
398
411
|
type ExtractSoftRemovekName<Config> = Config extends { softRemovekName: infer S } ? S : never;
|
|
399
|
-
type
|
|
412
|
+
type ExtractDefaultOrdering<Config> = Config extends { defaultOrdering: infer O } ? O : Config extends { defaultOrdenation: infer O } ? O : never;
|
|
400
413
|
|
|
401
414
|
type AggregateMethod<M extends PrismaModelName> = <A extends Prisma.TypeMap['model'][M]['operations']['aggregate']['args']>(
|
|
402
415
|
prismaArgs: A,
|
|
@@ -516,7 +529,13 @@ export type CursorModel<M extends PrismaModelName> = PrismaModelInputs<M>['curso
|
|
|
516
529
|
/**
|
|
517
530
|
* Type of the `orderBy` object of a Prisma model.
|
|
518
531
|
*/
|
|
519
|
-
export type
|
|
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>;
|
|
520
539
|
|
|
521
540
|
/**
|
|
522
541
|
* Pagination options with typed cursor for a Prisma model.
|
|
@@ -550,7 +569,12 @@ export type MethodConfig<M extends PrismaModelName, SelectModels = any> = {
|
|
|
550
569
|
*/
|
|
551
570
|
readonly fbMode?: 'one' | 'list';
|
|
552
571
|
/** Injects a fixed ordering automatically into the query. */
|
|
553
|
-
readonly
|
|
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>;
|
|
554
578
|
/** Injects a fixed pagination automatically into the query. */
|
|
555
579
|
readonly injectPagination?: PaginationModel<M>;
|
|
556
580
|
/**
|
|
@@ -674,18 +698,20 @@ type ResolveMethodDefaultSelect<Config, C, Method extends keyof NonNullable<Buil
|
|
|
674
698
|
? ExtractDefaultSelect<Config>
|
|
675
699
|
: false;
|
|
676
700
|
|
|
677
|
-
type ResolveCurrentReturn<M extends PrismaModelName, Models, S, D, IM = never, Includes = {}, RI = never> =
|
|
678
|
-
[
|
|
679
|
-
? [
|
|
680
|
-
? [
|
|
681
|
-
?
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
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;
|
|
689
715
|
|
|
690
716
|
// ─── helpers reused within the mapped type ───────────────────────────────────
|
|
691
717
|
// ─── relation payload types ──────────────────────────────────────────────────
|
|
@@ -791,7 +817,7 @@ export type PatchObject<TInput, TRepo> =
|
|
|
791
817
|
|
|
792
818
|
|
|
793
819
|
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>;
|
|
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>;
|
|
795
821
|
type _DS<Config, C, Method extends keyof NonNullable<BuildConfig['baseMethods']>, TSelects = ExtractSelectModels<Config>> =
|
|
796
822
|
ResolveMethodDefaultSelect<Config, C, Method, TSelects>;
|
|
797
823
|
type _Sel<Config> = ExtractSelectModels<Config>;
|
|
@@ -799,7 +825,7 @@ type _Inc<Config> = ExtractIncludeModels<Config>;
|
|
|
799
825
|
type _Def<Config> = ExtractDefaultSelect<Config>;
|
|
800
826
|
type _Rel<Config> = ExtractRelations<Config>;
|
|
801
827
|
type _Soft<Config> = ExtractSoftRemovekName<Config>;
|
|
802
|
-
type _DOrd<Config> =
|
|
828
|
+
type _DOrd<Config> = ExtractDefaultOrdering<Config>;
|
|
803
829
|
|
|
804
830
|
// ─── refactored mapped type — optimized for the TS compiler ──────────────────
|
|
805
831
|
|
|
@@ -814,69 +840,69 @@ type AllBaseMethods<
|
|
|
814
840
|
TRelations = _Rel<Config>,
|
|
815
841
|
TSoftKey = _Soft<Config>,
|
|
816
842
|
I = PrismaModelInputs<M>,
|
|
817
|
-
|
|
843
|
+
TDefaultOrdering = _DOrd<Config>,
|
|
818
844
|
TIncludes = _Inc<Config>
|
|
819
845
|
> = {
|
|
820
846
|
/** 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>;
|
|
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>;
|
|
824
850
|
|
|
825
851
|
/** 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>>;
|
|
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>>;
|
|
829
855
|
|
|
830
856
|
/** 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>[]>;
|
|
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>[]>;
|
|
834
860
|
|
|
835
861
|
/** 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>>;
|
|
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>>;
|
|
839
865
|
|
|
840
866
|
/** 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>>;
|
|
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>>;
|
|
844
870
|
|
|
845
871
|
/** 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>[]>;
|
|
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>[]>;
|
|
849
875
|
|
|
850
876
|
/** 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>>;
|
|
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>>;
|
|
854
880
|
|
|
855
881
|
/** 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>[]>;
|
|
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>[]>;
|
|
859
885
|
|
|
860
886
|
/** 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>;
|
|
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>;
|
|
864
890
|
|
|
865
891
|
/** Deletes multiple records by their primary keys. */
|
|
866
892
|
removeList: (pks: _Pk<T, Config>[], options?: { db?: ClientOrTransaction }) => Promise<{ count: number }>;
|
|
867
893
|
|
|
868
894
|
/** 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> & {
|
|
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> & {
|
|
871
897
|
pagination?: PaginationOptions<I extends { cursorInput: infer Curs } ? Curs : unknown>;
|
|
872
898
|
/**
|
|
873
899
|
* Ordering to apply to the query.
|
|
874
|
-
* When omitted and `
|
|
900
|
+
* When omitted and `defaultOrdering` is configured on the repository,
|
|
875
901
|
* the default ordering is applied automatically.
|
|
876
902
|
*/
|
|
877
903
|
order?: I extends { orderByInput: infer OB } ? OB : OrderOptions;
|
|
878
904
|
}
|
|
879
|
-
) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes, RI>[]>;
|
|
905
|
+
) => Promise<_Ret<M, TSelects, S, TDefault, IM, TIncludes, RI, RS>[]>;
|
|
880
906
|
|
|
881
907
|
/** Returns the total number of records. */
|
|
882
908
|
total: (options?: { db?: ClientOrTransaction; see?: SeeMode }) => Promise<number>;
|
|
@@ -885,17 +911,17 @@ type AllBaseMethods<
|
|
|
885
911
|
has: (pk: _Pk<T, Config>, options?: { db?: ClientOrTransaction; see?: SeeMode }) => Promise<boolean>;
|
|
886
912
|
|
|
887
913
|
/** 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>>;
|
|
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>>;
|
|
891
917
|
|
|
892
918
|
/** Marks multiple records as deleted (soft-delete) in batch. */
|
|
893
919
|
softRemoveList: (pks: _Pk<T, Config>[], options?: { db?: ClientOrTransaction }) => Promise<{ count: number }>;
|
|
894
920
|
|
|
895
921
|
/** 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>>;
|
|
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>>;
|
|
899
925
|
|
|
900
926
|
/** Restores multiple records previously marked as deleted (soft-delete) in batch. */
|
|
901
927
|
restoreList: (pks: _Pk<T, Config>[], options?: { db?: ClientOrTransaction }) => Promise<{ count: number }>;
|
|
@@ -912,10 +938,10 @@ type InjectedBaseMethods<
|
|
|
912
938
|
TRelations = _Rel<Config>,
|
|
913
939
|
TSoftKey = _Soft<Config>,
|
|
914
940
|
I = PrismaModelInputs<M>,
|
|
915
|
-
|
|
941
|
+
TDefaultOrdering = _DOrd<Config>,
|
|
916
942
|
TIncludes = _Inc<Config>
|
|
917
943
|
> = Pick<
|
|
918
|
-
AllBaseMethods<T, M, Config, C, TSelects, TDefault, TPk, TRelations, TSoftKey, I,
|
|
944
|
+
AllBaseMethods<T, M, Config, C, TSelects, TDefault, TPk, TRelations, TSoftKey, I, TDefaultOrdering, TIncludes>,
|
|
919
945
|
| (C extends { baseMethods: { get: { active: false } } } ? never : 'get')
|
|
920
946
|
| (C extends { baseMethods: { getOrThrow: { active: false } } } ? never : 'getOrThrow')
|
|
921
947
|
| (C extends { baseMethods: { getList: { active: false } } } ? never : 'getList')
|
|
@@ -1019,7 +1045,9 @@ export type RepoConfig<T, M extends PrismaModelName, SM extends Record<string, A
|
|
|
1019
1045
|
defaultSelectModel?: Extract<keyof SM, string>;
|
|
1020
1046
|
includeModels?: IncludeModels<M>;
|
|
1021
1047
|
requiredWhere?: WhereModel<M>;
|
|
1022
|
-
|
|
1048
|
+
defaultOrdering?: OrderingModel<M>;
|
|
1049
|
+
/** @deprecated Use `defaultOrdering` instead. */
|
|
1050
|
+
defaultOrdenation?: OrderingModel<M>;
|
|
1023
1051
|
relations?: RepositoryRelations<T>;
|
|
1024
1052
|
methods?: Record<string, MethodConfig<M, SM>>;
|
|
1025
1053
|
};
|
|
@@ -1117,12 +1145,23 @@ export type ValidateRepoConfig<T extends object, M extends PrismaModelName, Conf
|
|
|
1117
1145
|
|
|
1118
1146
|
/**
|
|
1119
1147
|
* Default ordering automatically injected into all queries that accept `orderBy`,
|
|
1120
|
-
* unless the method already has `
|
|
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.
|
|
1121
1158
|
*
|
|
1122
1159
|
* Useful for ensuring a consistent sort order across the repository without repeating
|
|
1123
1160
|
* the `order` argument on every call.
|
|
1161
|
+
*
|
|
1162
|
+
* @deprecated Use `defaultOrdering` instead.
|
|
1124
1163
|
*/
|
|
1125
|
-
defaultOrdenation?:
|
|
1164
|
+
defaultOrdenation?: OrderingModel<M>;
|
|
1126
1165
|
|
|
1127
1166
|
/**
|
|
1128
1167
|
* Configures automatic relation management.
|