@@ -6,10 +6,8 @@ import { AnyNullClass, DbNullClass, JsonNullClass } from '../../../common-types'
66import {
77 type AttributeApplication ,
88 type BuiltinType ,
9- type EnumDef ,
109 type FieldDef ,
1110 type GetModels ,
12- type ModelDef ,
1311 type ProcedureDef ,
1412 type SchemaDef ,
1513} from '../../../schema' ;
@@ -589,7 +587,6 @@ export class InputValidator<Schema extends SchemaDef> {
589587 if ( Object . keys ( enumDef . values ) . length > 0 ) {
590588 fieldSchema = this . makeEnumFilterSchema (
591589 fieldDef . type ,
592- enumDef ,
593590 ! ! fieldDef . optional ,
594591 withAggregations ,
595592 ! ! fieldDef . array ,
@@ -632,7 +629,6 @@ export class InputValidator<Schema extends SchemaDef> {
632629 if ( Object . keys ( enumDef . values ) . length > 0 ) {
633630 fieldSchema = this . makeEnumFilterSchema (
634631 def . type ,
635- enumDef ,
636632 ! ! def . optional ,
637633 false ,
638634 false ,
@@ -724,7 +720,6 @@ export class InputValidator<Schema extends SchemaDef> {
724720 if ( enumDef ) {
725721 fieldSchemas [ fieldName ] = this . makeEnumFilterSchema (
726722 fieldDef . type ,
727- enumDef ,
728723 ! ! fieldDef . optional ,
729724 false ,
730725 ! ! fieldDef . array ,
@@ -781,21 +776,17 @@ export class InputValidator<Schema extends SchemaDef> {
781776 }
782777
783778 @cache ( )
784- private makeEnumFilterSchema (
785- enumName : string ,
786- enumDef : EnumDef ,
787- optional : boolean ,
788- withAggregations : boolean ,
789- array : boolean ,
790- ) {
779+ private makeEnumFilterSchema ( enumName : string , optional : boolean , withAggregations : boolean , array : boolean ) {
780+ const enumDef = getEnum ( this . schema , enumName ) ;
781+ invariant ( enumDef , `Enum "${ enumName } " not found in schema` ) ;
791782 const baseSchema = z . enum ( Object . keys ( enumDef . values ) as [ string , ...string [ ] ] ) ;
792783 if ( array ) {
793784 return this . internalMakeArrayFilterSchema ( baseSchema ) ;
794785 }
795786 const components = this . makeCommonPrimitiveFilterComponents (
796787 baseSchema ,
797788 optional ,
798- ( ) => z . lazy ( ( ) => this . makeEnumFilterSchema ( enumName , enumDef , optional , withAggregations , array ) ) ,
789+ ( ) => z . lazy ( ( ) => this . makeEnumFilterSchema ( enumName , optional , withAggregations , array ) ) ,
799790 [ 'equals' , 'in' , 'notIn' , 'not' ] ,
800791 withAggregations ? [ '_count' , '_min' , '_max' ] : undefined ,
801792 ) ;
@@ -1003,13 +994,13 @@ export class InputValidator<Schema extends SchemaDef> {
1003994 for ( const field of Object . keys ( modelDef . fields ) ) {
1004995 const fieldDef = requireField ( this . schema , model , field ) ;
1005996 if ( fieldDef . relation ) {
1006- fields [ field ] = this . makeRelationSelectIncludeSchema ( fieldDef ) . optional ( ) ;
997+ fields [ field ] = this . makeRelationSelectIncludeSchema ( model , field ) . optional ( ) ;
1007998 } else {
1008999 fields [ field ] = z . boolean ( ) . optional ( ) ;
10091000 }
10101001 }
10111002
1012- const _countSchema = this . makeCountSelectionSchema ( modelDef ) ;
1003+ const _countSchema = this . makeCountSelectionSchema ( model ) ;
10131004 if ( ! ( _countSchema instanceof z . ZodNever ) ) {
10141005 fields [ '_count' ] = _countSchema ;
10151006 }
@@ -1018,7 +1009,8 @@ export class InputValidator<Schema extends SchemaDef> {
10181009 }
10191010
10201011 @cache ( )
1021- private makeCountSelectionSchema ( modelDef : ModelDef ) {
1012+ private makeCountSelectionSchema ( model : string ) {
1013+ const modelDef = requireModel ( this . schema , model ) ;
10221014 const toManyRelations = Object . values ( modelDef . fields ) . filter ( ( def ) => def . relation && def . array ) ;
10231015 if ( toManyRelations . length > 0 ) {
10241016 return z
@@ -1050,7 +1042,8 @@ export class InputValidator<Schema extends SchemaDef> {
10501042 }
10511043
10521044 @cache ( )
1053- private makeRelationSelectIncludeSchema ( fieldDef : FieldDef ) {
1045+ private makeRelationSelectIncludeSchema ( model : string , field : string ) {
1046+ const fieldDef = requireField ( this . schema , model , field ) ;
10541047 let objSchema : z . ZodType = z . strictObject ( {
10551048 ...( fieldDef . array || fieldDef . optional
10561049 ? {
@@ -1116,11 +1109,11 @@ export class InputValidator<Schema extends SchemaDef> {
11161109 for ( const field of Object . keys ( modelDef . fields ) ) {
11171110 const fieldDef = requireField ( this . schema , model , field ) ;
11181111 if ( fieldDef . relation ) {
1119- fields [ field ] = this . makeRelationSelectIncludeSchema ( fieldDef ) . optional ( ) ;
1112+ fields [ field ] = this . makeRelationSelectIncludeSchema ( model , field ) . optional ( ) ;
11201113 }
11211114 }
11221115
1123- const _countSchema = this . makeCountSelectionSchema ( modelDef ) ;
1116+ const _countSchema = this . makeCountSelectionSchema ( model ) ;
11241117 if ( ! ( _countSchema instanceof z . ZodNever ) ) {
11251118 fields [ '_count' ] = _countSchema ;
11261119 }
@@ -1267,7 +1260,7 @@ export class InputValidator<Schema extends SchemaDef> {
12671260 }
12681261
12691262 let fieldSchema : ZodType = z . lazy ( ( ) =>
1270- this . makeRelationManipulationSchema ( fieldDef , excludeFields , 'create' ) ,
1263+ this . makeRelationManipulationSchema ( model , field , excludeFields , 'create' ) ,
12711264 ) ;
12721265
12731266 if ( fieldDef . optional || fieldDef . array ) {
@@ -1361,7 +1354,13 @@ export class InputValidator<Schema extends SchemaDef> {
13611354 }
13621355
13631356 @cache ( )
1364- private makeRelationManipulationSchema ( fieldDef : FieldDef , withoutFields : string [ ] , mode : 'create' | 'update' ) {
1357+ private makeRelationManipulationSchema (
1358+ model : string ,
1359+ field : string ,
1360+ withoutFields : string [ ] ,
1361+ mode : 'create' | 'update' ,
1362+ ) {
1363+ const fieldDef = requireField ( this . schema , model , field ) ;
13651364 const fieldType = fieldDef . type ;
13661365 const array = ! ! fieldDef . array ;
13671366 const fields : Record < string , ZodType > = {
@@ -1573,7 +1572,7 @@ export class InputValidator<Schema extends SchemaDef> {
15731572 }
15741573 }
15751574 let fieldSchema : ZodType = z
1576- . lazy ( ( ) => this . makeRelationManipulationSchema ( fieldDef , excludeFields , 'update' ) )
1575+ . lazy ( ( ) => this . makeRelationManipulationSchema ( model , field , excludeFields , 'update' ) )
15771576 . optional ( ) ;
15781577 // optional to-one relation can be null
15791578 if ( fieldDef . optional && ! fieldDef . array ) {
@@ -1656,7 +1655,7 @@ export class InputValidator<Schema extends SchemaDef> {
16561655 // #region Delete
16571656
16581657 @cache ( )
1659- private makeDeleteSchema ( model : GetModels < Schema > ) {
1658+ private makeDeleteSchema ( model : string ) {
16601659 const baseSchema = z . strictObject ( {
16611660 where : this . makeWhereSchema ( model , true ) ,
16621661 select : this . makeSelectSchema ( model ) . optional ( ) . nullable ( ) ,
@@ -1670,7 +1669,7 @@ export class InputValidator<Schema extends SchemaDef> {
16701669 }
16711670
16721671 @cache ( )
1673- private makeDeleteManySchema ( model : GetModels < Schema > ) {
1672+ private makeDeleteManySchema ( model : string ) {
16741673 return this . mergePluginArgsSchema (
16751674 z . strictObject ( {
16761675 where : this . makeWhereSchema ( model , false ) . optional ( ) ,
@@ -1685,7 +1684,7 @@ export class InputValidator<Schema extends SchemaDef> {
16851684 // #region Count
16861685
16871686 @cache ( )
1688- makeCountSchema ( model : GetModels < Schema > ) {
1687+ makeCountSchema ( model : string ) {
16891688 return this . mergePluginArgsSchema (
16901689 z . strictObject ( {
16911690 where : this . makeWhereSchema ( model , false ) . optional ( ) ,
@@ -1699,7 +1698,7 @@ export class InputValidator<Schema extends SchemaDef> {
16991698 }
17001699
17011700 @cache ( )
1702- private makeCountAggregateInputSchema ( model : GetModels < Schema > ) {
1701+ private makeCountAggregateInputSchema ( model : string ) {
17031702 const modelDef = requireModel ( this . schema , model ) ;
17041703 return z . union ( [
17051704 z . literal ( true ) ,
@@ -1721,7 +1720,7 @@ export class InputValidator<Schema extends SchemaDef> {
17211720 // #region Aggregate
17221721
17231722 @cache ( )
1724- makeAggregateSchema ( model : GetModels < Schema > ) {
1723+ makeAggregateSchema ( model : string ) {
17251724 return this . mergePluginArgsSchema (
17261725 z . strictObject ( {
17271726 where : this . makeWhereSchema ( model , false ) . optional ( ) ,
@@ -1739,7 +1738,7 @@ export class InputValidator<Schema extends SchemaDef> {
17391738 }
17401739
17411740 @cache ( )
1742- makeSumAvgInputSchema ( model : GetModels < Schema > ) {
1741+ makeSumAvgInputSchema ( model : string ) {
17431742 const modelDef = requireModel ( this . schema , model ) ;
17441743 return z . strictObject (
17451744 Object . keys ( modelDef . fields ) . reduce (
@@ -1756,7 +1755,7 @@ export class InputValidator<Schema extends SchemaDef> {
17561755 }
17571756
17581757 @cache ( )
1759- makeMinMaxInputSchema ( model : GetModels < Schema > ) {
1758+ makeMinMaxInputSchema ( model : string ) {
17601759 const modelDef = requireModel ( this . schema , model ) ;
17611760 return z . strictObject (
17621761 Object . keys ( modelDef . fields ) . reduce (
@@ -1773,7 +1772,7 @@ export class InputValidator<Schema extends SchemaDef> {
17731772 }
17741773
17751774 @cache ( )
1776- private makeGroupBySchema ( model : GetModels < Schema > ) {
1775+ private makeGroupBySchema ( model : string ) {
17771776 const modelDef = requireModel ( this . schema , model ) ;
17781777 const nonRelationFields = Object . keys ( modelDef . fields ) . filter ( ( field ) => ! modelDef . fields [ field ] ?. relation ) ;
17791778 const bySchema =
@@ -1859,7 +1858,7 @@ export class InputValidator<Schema extends SchemaDef> {
18591858 return true ;
18601859 }
18611860
1862- private makeHavingSchema ( model : GetModels < Schema > ) {
1861+ private makeHavingSchema ( model : string ) {
18631862 // `makeWhereSchema` is cached
18641863 return this . makeWhereSchema ( model , false , true , true ) ;
18651864 }
0 commit comments