vsrepo 1.1.8 → 1.1.9

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.
@@ -488,6 +488,34 @@ export type UpsertWithRelations<T, M extends Prisma.ModelName, TRelations> =
488
488
  [K in Extract<keyof TRelations, keyof T>]?: RelationPayload<T[K], TRelations[K], M, K>;
489
489
  };
490
490
 
491
+ type ExtractNestedUpdateInput<M extends Prisma.ModelName, K extends PropertyKey> =
492
+ NonNullable<ExtractUnionProp<PrismaModelInputs<M>['updateInput'], K>> extends { update?: infer U }
493
+ ? (
494
+ Exclude<U, any[]> extends infer Obj
495
+ ? Obj extends { where: any, data: infer D }
496
+ ? Exclude<D, any[]>
497
+ : Obj
498
+ : never
499
+ )
500
+ : never;
501
+
502
+ type RelationUpdatePayload<TField, TRelationConfig, M extends Prisma.ModelName, K extends PropertyKey> = NonNullable<TField> extends any[]
503
+ ? (ExtractNestedUpdateInput<M, K>)[]
504
+ : NonNullable<TField> extends object
505
+ ? ExtractNestedUpdateInput<M, K> | (TRelationConfig extends { mode: 'oto'; restriction: 'set' } | { mode: 'mto'; nullAble: true } ? null : never)
506
+ : never;
507
+
508
+ /**
509
+ * Payload aceito pelo `patch` quando o repository possui relações configuradas.
510
+ *
511
+ * Substitui os campos relacionais pelo formato compatível com os modos
512
+ * configurados em `relations` para fluxos de Update.
513
+ */
514
+ export type UpdateWithRelations<T, M extends Prisma.ModelName, TRelations> =
515
+ DistributiveOmit<PrismaModelInputs<M>['updateInput'], keyof TRelations> & {
516
+ [K in Extract<keyof TRelations, keyof T>]?: RelationUpdatePayload<T[K], TRelations[K], M, K>;
517
+ };
518
+
491
519
  type InjectedSave<
492
520
  T, M extends Prisma.ModelName, Config, C extends BuildConfig<any> | undefined,
493
521
  TSelects = ExtractSelectModels<Config>,
@@ -514,7 +542,7 @@ type InjectedPatch<
514
542
  TSelects = ExtractSelectModels<Config>,
515
543
  TDefault = ExtractDefaultSelect<Config>,
516
544
  TPk = ExtractPkName<T, Config>,
517
- I = PrismaModelInputs<M>
545
+ TRelations = ExtractRelations<Config>
518
546
  > = C extends { baseMethods: { patch: { active: false } } } ? {} : {
519
547
  /**
520
548
  * Atualiza parcialmente (patch) um registro existente pela chave primária (PK), aceita os campos de relações definidas nas `relations`.
@@ -524,11 +552,11 @@ type InjectedPatch<
524
552
  * @returns O registro atualizado refinado conforme a entrada.
525
553
  */
526
554
  patch<
527
- O extends (I extends { updateInput: infer U } ? U : Record<string, any>),
555
+ O extends UpdateWithRelations<T, M, TRelations>,
528
556
  S extends keyof TSelects | false = ResolveMethodDefaultSelect<Config, C, 'patch', TSelects>
529
557
  >(
530
558
  pk: T[TPk extends keyof T ? TPk : never],
531
- obj: O & (I extends { updateInput: infer U } ? U : Record<string, any>),
559
+ obj: O & UpdateWithRelations<T, M, TRelations>,
532
560
  options?: MethodOptions<S>
533
561
  ): Promise<RefineSaveResult<ResolveCurrentReturn<M, TSelects, S, TDefault>, O>>;
534
562
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vsrepo",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "Uma biblioteca de repository pattern para Prisma",
5
5
  "homepage": "https://github.com/jaobrabo123/VSRepository#readme",
6
6
  "repository": {