-
Notifications
You must be signed in to change notification settings - Fork 57
Zod 4 Support #818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Zod 4 Support #818
Conversation
Huge credit to @panzacoder for his implementation in Zodvex, which this is heavily inspired by!! |
commit: |
ExtraArgs | ||
>, | ||
) { | ||
return customFnBuilder(query, customization) as any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very quick update before bed: re-adding CustomBuilder
as seen in the v3 version, instead of any
does seem to fix the issue related to the custom functions. We might need to generally review the any
usage in order to preserve type-safety. I might have some time tomorrow to take a full pass on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't have enough time to complete a full pass yet. But making some progress though my own adjustments and using a bit from @panzacoder's wonderful zodvex project, mostly helping me with the zodToConvex()
feature. Hopefully that is ok, let me know if you have any objection.
@@ -0,0 +1,642 @@ | |||
import { z } from "zod"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { z } from "zod"; | |
import { z } from "zod/v4/core"; |
I think that this is change is necessary. With the current import, users of convex-helpers that use Zod 3 would get the /zod4
types incorrectly defined based on Zod 3 (see https://zod.dev/library-authors?id=how-to-support-zod-4). According to the same page, we need to import from zod/v4/core
, unless we do something that can’t work with Zod Mini (but they strongly recommend against doing so).
Summary
packages/convex-helpers/server/zod4.ts
.Key Changes
server/zod4.ts
:zid
,zBrand
,zCustomQuery/Mutation/Action
,withSystemFields
,zodToConvex
,zodToConvexFields
,zodOutputToConvex
,convexToZod
,toConvexJS
,fromConvexJS
,convexCodec
../server/zod4
subpath (types + default) inpackages/convex-helpers/package.json
.Documentation
packages/convex-helpers/README.md
(see README for usage and examples).Tests
packages/convex-helpers/server/zod4.test.ts
(parity suite to follow).Peer Dependency
zod
peer range to^3.22.4 || ^4.1.12
(v4.1+ required).Compatibility
server/zod
) remains unchanged; new v4 functionality is opt-in via./server/zod4
.Follow-ups
zod4.test.ts
.server/zod4
.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Fixes #558
Fixes #793