Replies: 1 comment 1 reply
-
Assuming you're using Zod as your validation library, you already could pass |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm loving this library. Thanks for the hard work!
There's one thing that I'd love to see added so that I can use it in big projects.
What follows is the reason I want this change. You can skip this and head to the last section to get to the actual feature request.
Morale
Let me share what I want in a library like this first:
This library fits these needs quite well. However, the moment I'd want to add Native apps (or other types of clients) to the mix, I wouldn't be able to use the Server Action setup anymore (you're not supposed to use Server Actions endpoints outside your React app).
This is why I’d like to use tRPC to build my routes. It provides all points listed above as well, with the ability to expose endpoints to non-Web/React clients. There exists tooling to convert the schemas to OpenAPI docs as well.
But there’s one issue with using just tRPC: You can’t use
revalidatePath(..)
orrevalidateTag(..)
. In order to fetch the latest data you’d have to resort to arouter.refresh()
call after the fetch is completed, resulting in a waterfall.This is why I want to use Server Actions instead of pure tRPC.
So ideally, I’d use a combination of next-safe-action and tRPC. But this brings some redundancy with it. Namely the first 2 points listed above.
Point 1 is easily solved: Just don’t use middleware in next-safe-action, and only use it in tRPC. This means you must always use tRPC to do things that require authentication, though.
Point 2 is currently unable to be solved. It’s not possible to omit a schema in next-safe-action. This means I’d need to provide next-safe-action with a schema, and tRPC with the same schema. This is undesirable for 2 reasons:
Then there’s the issue of not being able to use next-safe-action for fetches that truly don’t need an input, like a GET equivalent, due to point 2. Let’s say I wasn’t going to use tRPC. I would then love to be able to use next-safe-action for its middleware with which I can setup auth. I could then use it in a Server Component to fetch data with the auth baked in. If I was able to do this, it would make my initial point 3 (A central data layer) easier to achieve.
So in actuality, this issue and issue 2 above share the same underlying obstacle: not being able to omit a schema.
Now, granted, the purpose of this library is to facilitate Server Actions, and fetching data in a Server Component is not that. That’s why I mention this last. It would be very nice to have, though.
The feature request
So that brings me to my request:
I’d love to see a change in the implementation to allow the input schema to be optional, instead of required. This should be possible with an overload where the first accepts just a function that takes a generic input (the handler), and the second overload would have the signature of the current implementation. Then only run the validation if a schema was passed.
Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions