@@ -2,7 +2,7 @@ import { invariant } from '@zenstackhq/common-helpers';
22import Decimal from 'decimal.js' ;
33import stableStringify from 'json-stable-stringify' ;
44import { match , P } from 'ts-pattern' ;
5- import { z , ZodType } from 'zod' ;
5+ import { z , ZodSchema , ZodType } from 'zod' ;
66import {
77 type BuiltinType ,
88 type EnumDef ,
@@ -764,13 +764,15 @@ export class InputValidator<Schema extends SchemaDef> {
764764
765765 private makeCreateSchema ( model : string ) {
766766 const dataSchema = this . makeCreateDataSchema ( model , false ) ;
767- const schema = z . strictObject ( {
767+ let schema : ZodSchema = z . strictObject ( {
768768 data : dataSchema ,
769769 select : this . makeSelectSchema ( model ) . optional ( ) ,
770770 include : this . makeIncludeSchema ( model ) . optional ( ) ,
771771 omit : this . makeOmitSchema ( model ) . optional ( ) ,
772772 } ) ;
773- return this . refineForSelectIncludeMutuallyExclusive ( schema ) ;
773+ schema = this . refineForSelectIncludeMutuallyExclusive ( schema ) ;
774+ schema = this . refineForSelectOmitMutuallyExclusive ( schema ) ;
775+ return schema ;
774776 }
775777
776778 private makeCreateManySchema ( model : string ) {
@@ -934,15 +936,15 @@ export class InputValidator<Schema extends SchemaDef> {
934936 fields [ 'update' ] = array
935937 ? this . orArray (
936938 z . strictObject ( {
937- where : this . makeWhereSchema ( fieldType , true ) ,
939+ where : this . makeWhereSchema ( fieldType , true ) . optional ( ) ,
938940 data : this . makeUpdateDataSchema ( fieldType , withoutFields ) ,
939941 } ) ,
940942 true ,
941943 ) . optional ( )
942944 : z
943945 . union ( [
944946 z . strictObject ( {
945- where : this . makeWhereSchema ( fieldType , true ) ,
947+ where : this . makeWhereSchema ( fieldType , true ) . optional ( ) ,
946948 data : this . makeUpdateDataSchema ( fieldType , withoutFields ) ,
947949 } ) ,
948950 this . makeUpdateDataSchema ( fieldType , withoutFields ) ,
@@ -1026,14 +1028,16 @@ export class InputValidator<Schema extends SchemaDef> {
10261028 // #region Update
10271029
10281030 private makeUpdateSchema ( model : string ) {
1029- const schema = z . strictObject ( {
1031+ let schema : ZodSchema = z . strictObject ( {
10301032 where : this . makeWhereSchema ( model , true ) ,
10311033 data : this . makeUpdateDataSchema ( model ) ,
10321034 select : this . makeSelectSchema ( model ) . optional ( ) ,
10331035 include : this . makeIncludeSchema ( model ) . optional ( ) ,
10341036 omit : this . makeOmitSchema ( model ) . optional ( ) ,
10351037 } ) ;
1036- return this . refineForSelectIncludeMutuallyExclusive ( schema ) ;
1038+ schema = this . refineForSelectIncludeMutuallyExclusive ( schema ) ;
1039+ schema = this . refineForSelectOmitMutuallyExclusive ( schema ) ;
1040+ return schema ;
10371041 }
10381042
10391043 private makeUpdateManySchema ( model : string ) {
@@ -1046,23 +1050,26 @@ export class InputValidator<Schema extends SchemaDef> {
10461050
10471051 private makeUpdateManyAndReturnSchema ( model : string ) {
10481052 const base = this . makeUpdateManySchema ( model ) ;
1049- const result = base . extend ( {
1053+ let schema : ZodSchema = base . extend ( {
10501054 select : this . makeSelectSchema ( model ) . optional ( ) ,
10511055 omit : this . makeOmitSchema ( model ) . optional ( ) ,
10521056 } ) ;
1053- return this . refineForSelectOmitMutuallyExclusive ( result ) ;
1057+ schema = this . refineForSelectOmitMutuallyExclusive ( schema ) ;
1058+ return schema ;
10541059 }
10551060
10561061 private makeUpsertSchema ( model : string ) {
1057- const schema = z . strictObject ( {
1062+ let schema : ZodSchema = z . strictObject ( {
10581063 where : this . makeWhereSchema ( model , true ) ,
10591064 create : this . makeCreateDataSchema ( model , false ) ,
10601065 update : this . makeUpdateDataSchema ( model ) ,
10611066 select : this . makeSelectSchema ( model ) . optional ( ) ,
10621067 include : this . makeIncludeSchema ( model ) . optional ( ) ,
10631068 omit : this . makeOmitSchema ( model ) . optional ( ) ,
10641069 } ) ;
1065- return this . refineForSelectIncludeMutuallyExclusive ( schema ) ;
1070+ schema = this . refineForSelectIncludeMutuallyExclusive ( schema ) ;
1071+ schema = this . refineForSelectOmitMutuallyExclusive ( schema ) ;
1072+ return schema ;
10661073 }
10671074
10681075 private makeUpdateDataSchema ( model : string , withoutFields : string [ ] = [ ] , withoutRelationFields = false ) {
@@ -1166,12 +1173,14 @@ export class InputValidator<Schema extends SchemaDef> {
11661173 // #region Delete
11671174
11681175 private makeDeleteSchema ( model : GetModels < Schema > ) {
1169- const schema = z . strictObject ( {
1176+ let schema : ZodSchema = z . strictObject ( {
11701177 where : this . makeWhereSchema ( model , true ) ,
11711178 select : this . makeSelectSchema ( model ) . optional ( ) ,
11721179 include : this . makeIncludeSchema ( model ) . optional ( ) ,
11731180 } ) ;
1174- return this . refineForSelectIncludeMutuallyExclusive ( schema ) ;
1181+ schema = this . refineForSelectIncludeMutuallyExclusive ( schema ) ;
1182+ schema = this . refineForSelectOmitMutuallyExclusive ( schema ) ;
1183+ return schema ;
11751184 }
11761185
11771186 private makeDeleteManySchema ( model : GetModels < Schema > ) {
0 commit comments