How do I exclude properties while returning data?

I basically need to create a dto's that would exclude properties like access keys etc. while returning the data to the client - so basically just striping the object on return. How can that be achieved?
BeBoRE
BeBoRE39d ago
You can use Zod schema’s for that, you can also add them as output schemas to make sure you aren’t returning something that you shouldn’t be
nightspite
nightspite39d ago
how do you actually achieve that? you can technically parse them, so they will automatically strip all unnecessary properties, but if the parse would fail, then you are left with zod validation error and nothing got returned
BeBoRE
BeBoRE39d ago
That’s the point right, you wouldn’t want to send that data if it wasn’t what you’d expect the output to be?
nightspite
nightspite37d ago
Sure in most of the cases, but in the edge case, where for example a value of one property is null I would rather have it returned with the null there than to have a validation error. Or in the case of using the same schema for validating input (for example setting min length of a string) and output, if a record with min length that would not satisfy this validation would also throw the error, even tho it might be unnecessary. Just my way of thinking about this problem. I had this problem with ts-rest, that is also using zod for validating output, that's why it's on my mind and I'm looking for other ways to solve it
More Posts
Does anyone have an example of subscriptions implemented in CloudFlare Workers?I'm trying to use subscriptions via WebSocket in CloudFlare Workers, but it's been a real pain so faTRPCClientError: Unable to transform response from serverI am currently encountering this error occasionally in my apps. I am using a Monorepo, which includeUnexpected tokenWorks fine locally, doesn't work when deployed to AWS via sst.dev. Was working last night. RedeployeContext is not being passed correctlyI will include my setup at the end. My problem is that I am using nextauth with database sessions anHow to get the Request Body data of QStashHello everyone. I'm currently working on a client project that involves using trpc with Next.js. We'Preventing uncaught error propagation from server to clientHello guys, is there any way to create default error handler? I want to avoid leaking internal inforThrowing something other than `Unexpected token '<', "<!DOCTYPE "... is not valid JSON`I'm trying to do custom error handling but whatever I throw just ends up being `Unexpected token '<'Create client that is used in every request, without re-creating clientHi all, Consider the following ``` export const createContextInner = async ({ req, res, }: { Using TRPC Server Caller in client side.What's up TRPCer. so i'm currently working in vanilla react app with seperate backend in .NET, in pAnyone has successfully setup a websockets subscription with an input ?Hi guys, here is my environment: *** node v20.11.1 * yarn@4.1.0 * trpc 11.0.0-next-beta.294 * next 1Middleware context changes aren't applied to `responseMeta(opts)` optionsIn our middleware I extend the ctx like this: ```ts const public = t.middleware(async ({ next, ctx Cookie authentication flowHello can i get a bit of a help and explanation please? Im frontend learning backend on trpc, I have