Replies: 1 comment 5 replies
|
Hello @nebbles Yes, I explored codecs. The state is that they are generally supported since they extend Codecs could take place somewhere in the generated Client. For instance, to establish the Perhaps the Codec's transforming functions could be placed in the generated client using Within the API itself Codecs don't bring much value. The requirement to invert them are not more convenient that using a dedicated transforming schema (in my opinion). If you have any ideas on what/how could/should be done, please let know! |
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hello! I was wondering about the stance of this project on Zod Codecs1. I did a search but could not find them referenced in documentation/issues/discussions.
Codecs would provide a more standardised way for us HTTP API maintainers to define our schemas, in ways that are more portable outside of the express-zod-api framework (such as taking the schemas to the client).
Perfect basic use case for this is dates (but i reckon useful for more complex schemas). Rather than using
ez.datewe could define our codec for input/output. Here's the example of "Dealing with dates" from the documentation adapted to using zod codecs:Existing documentation example
The change required, as I understand it, is that EZA would need to use the
encode/decodeof Zod instead of just parse. (Fortunately this is backwards compatible2)Less fortunately, we can't use the
z.invertCodec(schema)as this doesn't walk the object - soz.invertCodec(UserSchema)wouldn't have the desired outcome of inverting the full schema for compatability with EZA.I currently don't have any good workarounds, as fundamentally codec are the only way of 'deduplicating schemas' to avoid maintaining separate input from output. We've had uncomfortable bad compromises such as trying to use date coercion etc
Footnotes
https://zod.dev/codecs ↩
https://zod.dev/codecs?id=composability#composability ↩
All reactions