feng
feng3w ago

How to use output validation for dates? (Zod, SuperJSON)

I am trying to add output validation with zod, and my defined zod schema. I have currently set up superJson to transform my objects to and from, so that it can also do date transformation. If I add .output(ZodSchemaObject) it throws Expected date, received string This is becuse the ZodSchemaObject has a date in it. However I'm not sure how to make it so that it does the validation BEFORE the SuperJSON has had a chance to transform to string (is this correct?) to send to the client. Has anyone else had any success with this? Only solution now is to remove output validation and risk returning too much data
2 Replies
Nick
Nick3w ago
Validators DO run before your transformer runs Your data is legitimately wrong
feng
feng3w ago
Haha thanks, i thought I was going crazy. You were right, the culprit was a json_agg query that wasnt parsing a date data properly into string. Knowing that the validator ran before the transformer helped a lot thanks
More Posts
Can someone explain to me how `deserialize` works in `input` of `transformer`?```TypeScript export interface DataTransformer { serialize(object: any): any; deserialize(objectWebSocket Subscriptions in Next.js 14 Using `fetchRequestHandler` and `createTRPCReact`Hello everyone, Does anyone have a working example of using WebSockets/subscriptions with `fetchReqHow do I pass FormData from client to the public procedure ?Whilst being able to pass objects when calling mutate() from react-query's, FormData seems to not woTRPCClientError: Cannot use 'in' operator to search for 'error' in nullI am getting weird errors only in production. Everything works and builds perfectly fine locally, buAll backend imports becoming accessible on frontend?**Node Environment Version**: v20.10.0 **Package Manager**: PNPM Workspaces **Repo Setup**: MonorepoComponent suspends/rerenders on cached querykeyI've been trying to fix this issue for ours but dont get ahead I have a query which takes in a striNew versions doesn't fit the docs?I just updated versions of my packages and now I get typescript errors that the my query doesn't fitFind Usages of a procedure do not show client calls.If I define a procedure: ``` const appRouter = router({ list: publicProcedure.query(...) }) ``` tRPC + GCP headers issueHey everyone, I'm currently working on a tRPC-based app and I'm facing an issue with retrieving heaData Race in a useEffectHi, I have been using tRPC for a while, and it has been amazing. I am currently running into a smal