Using Zod Codec instead of transform. #1075
Replies: 3 comments 4 replies
-
|
yeah sure, that'd be a better way of doing it. Happy to merge a PR with the examples change! |
Beta Was this translation helpful? Give feedback.
-
|
Also Also, Fantastic job on the library! |
Beta Was this translation helpful? Give feedback.
-
|
I highly support this. I'm currently using PowerSync + Kysely + Zod + my custom de-normalization and it works well-ish, but looking at TanStack DB as a client-side ORM replacing Kysely and custom stuff. However, there are many missing spots in DB which my previous setup nails, including IMO quite non-ergonomical schemas support. @KyleAMathews please take a look at Zod's codecs feature, especially the
|
Beta Was this translation helpful? Give feedback.


Uh oh!
There was an error while loading. Please reload this page.
-
So question,
I we are using Zod Schemas, and doing mapping based on input / output shape ( hence the transform in the documentation ), Wouldn't it make more sense to use codecs, since that is inherently a bi-directional spec ?
for example, date fields the official docs currently recommend,
z.union([z.string(), z.date()]).transform(val => typeof val === 'string' ? new Date(val) : val)But Zod supports Implicitly specifying both types while maintaining JSON Schema compatibility.
This makes the types more easily re-used and, removes in my opinion some of the ambiguity from the first example
Zod Codecs
Beta Was this translation helpful? Give feedback.
All reactions