-
-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE REQUEST] Transform function configuration #16
Comments
Interesting, this should be implemented. If you have more thoughts to share about DX, and what we are missing in general. I'll implement this with Elysia 0.7 |
@SaltyAom was this implemented as part of the 0.7 update? I cannot find anything about it as of yet. Maybe it is too early to ask :) |
aa8176b, published on 0.7.4 |
Do you think there is a way to make it type-safe? @SaltyAom After doing this: export const app = edenTreaty<App>('', {
transform: (response) => {
if (response.error) throw response.error;
return response.data;
},
}); Returning an error should not be possible anymore, because it is always thrown. Calling the treaty still believes like an error can be returned: const res: ({
data: string[];
error: null;
} | {
data: null;
error: EdenFetchError<number, string>;
}) & {
status: number;
response: Response;
headers: Record<string, string>;
} = await app.api.hello.get(); Expected output (ideally, if this is even possible): const res: string[] = await app.api.hello.get(); |
Currently the transform function seems to not run? the requests are not transformed at all. It seems to be buggy both on the type and execution level somehow. |
Upon inspecting the source code it became apparent: it is not transforming the whole response object, only the data property. I guess this was intended by @SaltyAom , but is probably not very intuitive? I expected that it would transform everything returned by Eden Treaty. The current implementation does seem to work, I just do not know if there is any specific reason why we cannot remove or assign to the other fields? |
It would be nice if Eden Treaty allowed for the transformation of the response.
Proposed API:
Current workaround, which needs to be coded manually for each request:
--- Why would this be useful? ---
Lot of current querying libraries like Tanstack query, SWR, depend on errors being thrown, so they can be returned by the hook used for querying. Eden Treaty does not throw, but returns errors and data objects, which is fine, but there should be a way to configure the transformation of the response for these use-cases on the client level. Is this something that would be feasible to implement? @SaltyAom
The text was updated successfully, but these errors were encountered: