vsrepo 1.2.3 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/VSRepository/VSRepository.d.ts +19 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# VSRepository
|
|
2
2
|
|
|
3
3
|

|
|
4
|
-

|
|
5
5
|

|
|
6
6
|
|
|
7
7
|
Biblioteca de repository pattern para projetos que usam **Prisma**, com suporte completo a **TypeScript** e **type inference** automático.
|
|
@@ -1113,10 +1113,11 @@ type UsuarioRepositoryExtended = RepositoryOf<typeof usuarioVSRepo, undefined, t
|
|
|
1113
1113
|
|
|
1114
1114
|
### Tipos do payload dos métodos `save` e `patch`
|
|
1115
1115
|
|
|
1116
|
-
Use `SaveObject` e `PatchObject` para extrair o tipo do payload esperado pelos métodos `save` e `patch` diretamente a partir de uma instância `VSRepository` configurada. Esses tipos
|
|
1116
|
+
Use `SaveObject` e `PatchObject` para extrair o tipo do payload esperado pelos métodos `save` e `patch` diretamente a partir de uma instância `VSRepository` configurada. Esses tipos combinam o input base do Prisma com as relações configuradas no repository.
|
|
1117
1117
|
|
|
1118
1118
|
```ts
|
|
1119
|
-
import type { SaveObject,
|
|
1119
|
+
import type { SaveObject, PatchObject } from "../../generated/vsrepo";
|
|
1120
|
+
import type { Prisma } from "../../generated/prisma/client";
|
|
1120
1121
|
|
|
1121
1122
|
const usuarioVSRepo = setupVSRepo<Usuario, "usuario">()({
|
|
1122
1123
|
tableName: "usuario",
|
|
@@ -1128,10 +1129,10 @@ const usuarioVSRepo = setupVSRepo<Usuario, "usuario">()({
|
|
|
1128
1129
|
});
|
|
1129
1130
|
|
|
1130
1131
|
// Tipo do objeto aceito pelo .save()
|
|
1131
|
-
type UsuarioSavePayload = SaveObject<typeof usuarioVSRepo>;
|
|
1132
|
+
type UsuarioSavePayload = SaveObject<Prisma.UsuarioCreateInput, typeof usuarioVSRepo>;
|
|
1132
1133
|
|
|
1133
1134
|
// Tipo do objeto aceito pelo .patch()
|
|
1134
|
-
type UsuarioPatchPayload =
|
|
1135
|
+
type UsuarioPatchPayload = PatchObject<Prisma.UsuarioUpdateInput, typeof usuarioVSRepo>;
|
|
1135
1136
|
```
|
|
1136
1137
|
|
|
1137
1138
|
> Útil para tipar DTOs, funções auxiliares ou serviços que chamam `save`/`patch` e precisam do tipo correto do payload sem referenciar diretamente os tipos internos do Prisma.
|
|
@@ -550,15 +550,15 @@ type UpsertWithRelations<T, M extends Prisma.ModelName, TRelations> =
|
|
|
550
550
|
[K in Extract<keyof TRelations, keyof T>]?: RelationPayload<T[K], TRelations[K], M, K>;
|
|
551
551
|
};
|
|
552
552
|
|
|
553
|
+
type CleanNestedInput<T> = T extends any
|
|
554
|
+
? T extends { data: infer D }
|
|
555
|
+
? CleanNestedInput<Exclude<D, any[]>>
|
|
556
|
+
: Omit<T, 'where' | 'data'>
|
|
557
|
+
: never;
|
|
558
|
+
|
|
553
559
|
type ExtractNestedUpdateInput<M extends Prisma.ModelName, K extends PropertyKey> =
|
|
554
560
|
NonNullable<ExtractUnionProp<PrismaModelInputs<M>['updateInput'], K>> extends { update?: infer U }
|
|
555
|
-
?
|
|
556
|
-
Exclude<U, any[]> extends infer Obj
|
|
557
|
-
? Obj extends { where: any, data: infer D }
|
|
558
|
-
? Exclude<D, any[]>
|
|
559
|
-
: Obj
|
|
560
|
-
: never
|
|
561
|
-
)
|
|
561
|
+
? CleanNestedInput<Exclude<U, any[]>>
|
|
562
562
|
: never;
|
|
563
563
|
|
|
564
564
|
type RelationUpdatePayload<TField, TRelationConfig, M extends Prisma.ModelName, K extends PropertyKey> = NonNullable<TField> extends any[]
|
|
@@ -581,17 +581,25 @@ type UpdateWithRelations<T, M extends Prisma.ModelName, TRelations> =
|
|
|
581
581
|
/**
|
|
582
582
|
* Extrai o tipo de payload do método `save` a partir de uma instância de VSRepository configurada.
|
|
583
583
|
*/
|
|
584
|
-
export type SaveObject<TRepo> =
|
|
584
|
+
export type SaveObject<TInput, TRepo> =
|
|
585
585
|
TRepo extends VSRepository<infer T, infer M, infer Config>
|
|
586
|
-
?
|
|
586
|
+
? (Config extends { relations: infer R } ? (R extends object ? R : {}) : {}) extends infer TRelations
|
|
587
|
+
? DistributiveOmit<TInput, keyof TRelations> & {
|
|
588
|
+
[K in Extract<keyof TRelations, keyof T>]?: RelationPayload<T[K], TRelations[K], M, K>;
|
|
589
|
+
}
|
|
590
|
+
: never
|
|
587
591
|
: never;
|
|
588
592
|
|
|
589
593
|
/**
|
|
590
594
|
* Extrai o tipo de payload do método `patch` a partir de uma instância de VSRepository configurada.
|
|
591
595
|
*/
|
|
592
|
-
export type PacthObject<TRepo> =
|
|
596
|
+
export type PacthObject<TInput, TRepo> =
|
|
593
597
|
TRepo extends VSRepository<infer T, infer M, infer Config>
|
|
594
|
-
?
|
|
598
|
+
? (Config extends { relations: infer R } ? (R extends object ? R : {}) : {}) extends infer TRelations
|
|
599
|
+
? DistributiveOmit<TInput, keyof TRelations> & {
|
|
600
|
+
[K in Extract<keyof TRelations, keyof T>]?: RelationUpdatePayload<T[K], TRelations[K], M, K>;
|
|
601
|
+
}
|
|
602
|
+
: never
|
|
595
603
|
: never;
|
|
596
604
|
|
|
597
605
|
type InjectedSave<
|