Drizzle-zod schemas included in bundle
Hey all, I am working on a package that exports a ts-rest contract. The contract uses zod schemas to validate inputs. The schemas are created with
createSelectSchema from drizzle-zod in my schema.ts file:
These schemas are then refined into the contract schemas with ClientSchema.pick({ ... }), which are used in the contracts. The contracts are then bundled with tsdown.
The issue I am facing is that when I run the bundler, full dirzzle schemas are generated in the index.mjs file instead of just zod schemas. Is there a way to prevent the bundler from including the entire schemas?Intro
A seriously tiny type-safe wrapper around existing, battle-tested, established tech.
1 Reply
The solution I have come up with is to just define zod schemas instead of using the drizzle-zod schemas. Because of drizzle's native type safety and ts-rest providing request types, I still know that my request and response is typesafe to my db schemas. As a bonus, if my db schema is a bit loose (accepts empty strings, string instead of enum, etc) I can add validation in the new zod schemas without a DB migration.
Let me know if there is a better way though!