Skip to content

Commit 8a1b8a4

Browse files
committed
fix makeExistsSchema typing
1 parent 9b60299 commit 8a1b8a4

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

packages/orm/src/client/zod/factory.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import type {
2222
CreateManyArgs,
2323
DeleteArgs,
2424
DeleteManyArgs,
25+
ExistsArgs,
2526
FindFirstArgs,
2627
FindManyArgs,
2728
FindUniqueArgs,
@@ -209,11 +210,15 @@ export class ZodSchemaFactory<
209210
}
210211

211212
@cache()
212-
makeExistsSchema(model: string) {
213+
makeExistsSchema<Model extends GetModels<Schema>>(
214+
model: Model,
215+
): ZodType<ExistsArgs<Schema, Model, Options, ExtQueryArgs> | undefined> {
213216
const baseSchema = z.strictObject({
214217
where: this.makeWhereSchema(model, false).optional(),
215218
});
216-
return this.mergePluginArgsSchema(baseSchema, 'exists').optional();
219+
return this.mergePluginArgsSchema(baseSchema, 'exists').optional() as ZodType<
220+
ExistsArgs<Schema, Model, Options, ExtQueryArgs> | undefined
221+
>;
217222
}
218223

219224
private makeScalarSchema(type: string, attributes?: readonly AttributeApplication[]) {

tests/e2e/orm/client-api/zod.test-d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ describe('Zod schema typing tests', () => {
3838
expectTypeOf<NonNullable<Args>>().toHaveProperty('take');
3939
});
4040

41+
it('makeExistsSchema returns a typed schema', () => {
42+
const s = client.$zod.makeExistsSchema('User');
43+
type Args = NonNullable<z.infer<typeof s>>;
44+
expectTypeOf<Args>().toHaveProperty('where');
45+
expectTypeOf<Args>().not.toHaveProperty('select');
46+
expectTypeOf<Args>().not.toHaveProperty('include');
47+
});
48+
4149
it('makeCreateSchema returns a typed schema', () => {
4250
const s = client.$zod.makeCreateSchema('User');
4351
type Args = z.infer<typeof s>;

0 commit comments

Comments
 (0)