@@ -589,34 +589,7 @@ export class InputValidator<Schema extends SchemaDef> {
589589 for ( const field of Object . keys ( modelDef . fields ) ) {
590590 const fieldDef = requireField ( this . schema , model , field ) ;
591591 if ( fieldDef . relation ) {
592- fields [ field ] = z
593- . union ( [
594- z . literal ( true ) ,
595- z . strictObject ( {
596- ...( fieldDef . array || fieldDef . optional
597- ? {
598- // to-many relations and optional to-one relations are filterable
599- where : z . lazy ( ( ) => this . makeWhereSchema ( fieldDef . type , false ) ) . optional ( ) ,
600- }
601- : { } ) ,
602- select : z . lazy ( ( ) => this . makeSelectSchema ( fieldDef . type ) ) . optional ( ) ,
603- include : z . lazy ( ( ) => this . makeIncludeSchema ( fieldDef . type ) ) . optional ( ) ,
604- omit : z . lazy ( ( ) => this . makeOmitSchema ( fieldDef . type ) ) . optional ( ) ,
605- ...( fieldDef . array
606- ? {
607- // to-many relations can be ordered, skipped, taken, and cursor-located
608- orderBy : z
609- . lazy ( ( ) => this . makeOrderBySchema ( fieldDef . type , true , false ) )
610- . optional ( ) ,
611- skip : this . makeSkipSchema ( ) . optional ( ) ,
612- take : this . makeTakeSchema ( ) . optional ( ) ,
613- cursor : this . makeCursorSchema ( fieldDef . type ) . optional ( ) ,
614- distinct : this . makeDistinctSchema ( fieldDef . type ) . optional ( ) ,
615- }
616- : { } ) ,
617- } ) ,
618- ] )
619- . optional ( ) ;
592+ fields [ field ] = this . makeRelationSelectIncludeSchema ( fieldDef ) . optional ( ) ;
620593 } else {
621594 fields [ field ] = z . boolean ( ) . optional ( ) ;
622595 }
@@ -653,6 +626,33 @@ export class InputValidator<Schema extends SchemaDef> {
653626 return z . strictObject ( fields ) ;
654627 }
655628
629+ private makeRelationSelectIncludeSchema ( fieldDef : FieldDef ) {
630+ return z . union ( [
631+ z . boolean ( ) ,
632+ z . strictObject ( {
633+ ...( fieldDef . array || fieldDef . optional
634+ ? {
635+ // to-many relations and optional to-one relations are filterable
636+ where : z . lazy ( ( ) => this . makeWhereSchema ( fieldDef . type , false ) ) . optional ( ) ,
637+ }
638+ : { } ) ,
639+ select : z . lazy ( ( ) => this . makeSelectSchema ( fieldDef . type ) ) . optional ( ) ,
640+ include : z . lazy ( ( ) => this . makeIncludeSchema ( fieldDef . type ) ) . optional ( ) ,
641+ omit : z . lazy ( ( ) => this . makeOmitSchema ( fieldDef . type ) ) . optional ( ) ,
642+ ...( fieldDef . array
643+ ? {
644+ // to-many relations can be ordered, skipped, taken, and cursor-located
645+ orderBy : z . lazy ( ( ) => this . makeOrderBySchema ( fieldDef . type , true , false ) ) . optional ( ) ,
646+ skip : this . makeSkipSchema ( ) . optional ( ) ,
647+ take : this . makeTakeSchema ( ) . optional ( ) ,
648+ cursor : this . makeCursorSchema ( fieldDef . type ) . optional ( ) ,
649+ distinct : this . makeDistinctSchema ( fieldDef . type ) . optional ( ) ,
650+ }
651+ : { } ) ,
652+ } ) ,
653+ ] ) ;
654+ }
655+
656656 private makeOmitSchema ( model : string ) {
657657 const modelDef = requireModel ( this . schema , model ) ;
658658 const fields : Record < string , ZodType > = { } ;
@@ -671,21 +671,7 @@ export class InputValidator<Schema extends SchemaDef> {
671671 for ( const field of Object . keys ( modelDef . fields ) ) {
672672 const fieldDef = requireField ( this . schema , model , field ) ;
673673 if ( fieldDef . relation ) {
674- fields [ field ] = z
675- . union ( [
676- z . literal ( true ) ,
677- z . strictObject ( {
678- select : z . lazy ( ( ) => this . makeSelectSchema ( fieldDef . type ) ) . optional ( ) ,
679- include : z . lazy ( ( ) => this . makeIncludeSchema ( fieldDef . type ) ) . optional ( ) ,
680- omit : z . lazy ( ( ) => this . makeOmitSchema ( fieldDef . type ) ) . optional ( ) ,
681- where : z . lazy ( ( ) => this . makeWhereSchema ( fieldDef . type , false ) ) . optional ( ) ,
682- orderBy : z . lazy ( ( ) => this . makeOrderBySchema ( fieldDef . type , true , false ) ) . optional ( ) ,
683- skip : this . makeSkipSchema ( ) . optional ( ) ,
684- take : this . makeTakeSchema ( ) . optional ( ) ,
685- distinct : this . makeDistinctSchema ( fieldDef . type ) . optional ( ) ,
686- } ) ,
687- ] )
688- . optional ( ) ;
674+ fields [ field ] = this . makeRelationSelectIncludeSchema ( fieldDef ) . optional ( ) ;
689675 }
690676 }
691677
0 commit comments