diff --git a/packages/runtime/src/client/crud-types.ts b/packages/runtime/src/client/crud-types.ts index 73e5ed31..12c2a64e 100644 --- a/packages/runtime/src/client/crud-types.ts +++ b/packages/runtime/src/client/crud-types.ts @@ -221,7 +221,12 @@ export type WhereInput< ? ArrayFilter> : // enum GetModelFieldType extends GetEnums - ? EnumFilter, ModelFieldIsOptional> + ? EnumFilter< + Schema, + GetModelFieldType, + ModelFieldIsOptional, + WithAggregations + > : // primitive PrimitiveFilter< Schema, @@ -237,14 +242,25 @@ export type WhereInput< NOT?: OrArray>; }; -type EnumFilter, Nullable extends boolean> = +type EnumFilter< + Schema extends SchemaDef, + T extends GetEnums, + Nullable extends boolean, + WithAggregations extends boolean, +> = | NullableIf, Nullable> - | { + | ({ equals?: NullableIf, Nullable>; in?: (keyof GetEnum)[]; notIn?: (keyof GetEnum)[]; - not?: EnumFilter; - }; + not?: EnumFilter; + } & (WithAggregations extends true + ? { + _count?: NumberFilter; + _min?: EnumFilter; + _max?: EnumFilter; + } + : {})); type ArrayFilter = { equals?: MapScalarType[] | null; diff --git a/packages/runtime/src/client/crud/validator.ts b/packages/runtime/src/client/crud/validator.ts index 6d5f7ebf..f2eb732a 100644 --- a/packages/runtime/src/client/crud/validator.ts +++ b/packages/runtime/src/client/crud/validator.ts @@ -1256,11 +1256,15 @@ export class InputValidator { private makeGroupBySchema(model: GetModels) { const modelDef = requireModel(this.schema, model); const nonRelationFields = Object.keys(modelDef.fields).filter((field) => !modelDef.fields[field]?.relation); + const bySchema = + nonRelationFields.length > 0 + ? this.orArray(z.enum(nonRelationFields as [string, ...string[]]), true) + : z.never(); let schema: z.ZodSchema = z.strictObject({ where: this.makeWhereSchema(model, false).optional(), orderBy: this.orArray(this.makeOrderBySchema(model, false, true), true).optional(), - by: this.orArray(z.enum(nonRelationFields as [string, ...string[]]), true), + by: bySchema, having: this.makeHavingSchema(model).optional(), skip: this.makeSkipSchema().optional(), take: this.makeTakeSchema().optional(),