-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Description
Describe the feature you'd like to request
Basically I automated the client to parse every object with a File into FormData and did the splitLink, but sadly there's no way to automate this on the server, so I always need to verify and parse on the input (something that I can end up forgeting, specially in larger projects).
Example of client code:
export const client = createTRPCClient<AppRouter>({
links: [
function formDataLink() {
return ({ op, next }) => {
return observable((observer) => {
if (!containsFile(op.input as Record<string, unknown>)) {
op.input = objectToFormData(op.input);
}
return next(op).subscribe({
next(value) {
observer.next(value);
},
error(err) {
observer.error(err);
},
complete() {
observer.complete();
},
});
});
};
},
loggerLink(),
splitLink({
condition: (op) => isNonJsonSerializable(op.input),
true: httpLink({
transformer: transformer,
url: `${getBaseUrl()}/api/trpc`,
}),
false: httpBatchLink({
transformer: transformer,
url: `${getBaseUrl()}/api/trpc`,
}),
}),
],
});Describe the solution you'd like to see
Currently, transformer is not called when you pass a FormData and goes directly into the input validation. I would suggest a way to handle non string/json in the server. Maybe transformFormData?
Describe alternate solutions
- Always remember to wrap input into
zfd.formData - Hack a way to pass the correct body to trpc in the server before it reaches it.
Additional information
No response
π¨βπ§βπ¦ Contributing
- πββοΈ Yes, I'd be down to file a PR implementing this feature!
coderabbitai
Metadata
Metadata
Assignees
Labels
No labels