-
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).
|
@ksinghal I have big overhaul to fix some issues I found in type-safety and that were addressed by @Nicolapps. It also introduces some further fixes provided by @panzacoder's Zodvex. Would you mind if I made some edits to this PR or should I create a fresh one since its a fairly sizable edit? I am ok either way, I just need to get v4 support shipped finally. 😅 |
|
please go ahead and make the edits here if you like! |
I'm also happy to contribute here. Don't mind that my code is being borrowed (obv it's OSS) but I probably would have opened a PR here already if I thought that was what the convex team wanted. @natedunn if you've already put some work into it I'll wait for your edits, otherwise I can make some contributions later today / this week. |
|
@panzacoder Honestly my approach was just to edit this PR fairly minimally, but I ran into a few type issues that your approach seemed to solve already. Both of you guys had solid, sizable contributions. I'm just bringing them together and patching up a few things. 🙏 Was going to push changes up today but noticed that this PR isn't set up to accept edits. Mind checking that @ksinghal? Appreciate it |
|
Unbelievable - it seems I am unable to access the "allow maintainers to edit" box based on this discussion: https://github.com/orgs/community/discussions/5634. Can't believe that's the case so let me know if im just not looking in the right place. |


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/zod4subpath (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
zodpeer 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