Open ericdew opened 4 months ago
Related to #69 the zodToConvexFields
is intended to turn user input into values. It doesn't yet support generating validators for the output type, as you may want for your table.
I have a branch (zod
) where I offer a second parameter to zodToConvexFields
as "output" or "input" but I haven't figured out how to keep TypeScript from giving up on the recursive types.
I believe this may be the issue with (2) as well - running into the TypeScript inference capability, though I haven't debugged it.
I would suggest duplicating the table definition from the zod input validators. Until there's a zod library to wrap database reads & writes to transform values, it's a bit unclear what the guarantees are when using zod validators in this way, since zodToConvexFields
just reduces to bare v.string()
etc and doesn't run the zod code at all at runtime for db read/write.
See here for more details.
If you really want to share configs for frontend validation and db types, I would suggest manually overriding that types that have transforms / defaults:
const messageTableFields = {
...zodToConvexFields(message),
sentTimestamp: v.number()
};
When creating table fields using zod, using a transform on a zod schema results in:
getEntDefinitions
helperExample implementation/use case: