Sharing zod schema between api and front-end

Im looking to build an app using nextjs and drizzle orm. I was wondering if I could use the zod schemas generated from drizzle-zod. My main concern was the "pollution" of the front-end bundle with back-end stuff. I wouldn't like people looking at my database schema or something unintended
6 Replies
Dan
Dan3y ago
well, if you have tree shaking, it should only bundle the table definitions and zod schemas that you use on the frontend not sure if there's a way to avoid exposing the table definition, since the zod schema generation happens at runtime using the table
teo.villanueva
teo.villanuevaOP3y ago
Found this discussion
teo.villanueva
teo.villanuevaOP3y ago
GitHub
Zod schema serialize/deserialize · colinhacks zod · Discussion #2030
How can I serialise/deserialize zod schema? So that I can store it in database for example as a string and reuse later when needed.
teo.villanueva
teo.villanuevaOP3y ago
There is maybe a solution to this The schema can be serialized and queried through trpc to then be deserrialzed on the front-end and used to validate a form The main issue with this is that you cant really serialize the refine Do you think that bundling the table definitions is a good idea?
Dan
Dan3y ago
I mean It depends on how do you define sensitive Honestly, I'm not sure
teo.villanueva
teo.villanuevaOP3y ago
Ok thanks!

Did you find this page helpful?