Skip to content
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

RPC supports middleware responses #2719

Open
yusukebe opened this issue May 18, 2024 · 3 comments
Open

RPC supports middleware responses #2719

yusukebe opened this issue May 18, 2024 · 3 comments
Labels
enhancement New feature or request.

Comments

@yusukebe
Copy link
Member

What is the feature you are proposing?

Currently, the RPC mode does not support middleware response. The client can't handle the response from the middleware:

CleanShot 2024-05-19 at 06 46 01@2x

I'm not 100% sure, but perhaps we can implement it by modifying types.ts:

diff --git a/src/types.ts b/src/types.ts
index 3c7a53d..5e93fc1 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -190,13 +190,22 @@ export interface HandlerInterface<
     I3 extends Input = I & I2,
     E2 extends Env = E,
     E3 extends Env = E,
-    E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>
+    E4 extends Env = IntersectNonAnyTypes<[E, E2, E3]>,
+    // Response from Middleware
+    RM1 extends HandlerResponse<any> = any,
+    RM2 extends HandlerResponse<any> = any
   >(
     path: P,
-    ...handlers: [H<E2, MergedPath, I>, H<E3, MergedPath, I2>, H<E4, MergedPath, I3, R>]
+    ...handlers: [H<E2, MergedPath, I, RM1>, H<E3, MergedPath, I2, RM2>, H<E4, MergedPath, I3, R>]
   ): Hono<
     IntersectNonAnyTypes<[E, E2, E3, E4]>,
-    S & ToSchema<M, MergePath<BasePath, P>, I3, MergeTypedResponse<R>>,
+    S &
+      ToSchema<
+        M,
+        MergePath<BasePath, P>,
+        I3,
+        MergeTypedResponse<R> | MergeTypedResponse<RM1> | MergeTypedResponse<RM2>
+      >,
     BasePath
   >

CleanShot 2024-05-19 at 06 48 11@2x

It will be worth implementing, though the code will be very long.

@yusukebe yusukebe added the enhancement New feature or request. label May 18, 2024
@yusukebe
Copy link
Member Author

yusukebe commented May 18, 2024

Hey @kosei28 What do you think about it?

@kosei28
Copy link
Contributor

kosei28 commented May 18, 2024

This is exactly what I wanted!

However, merging this may cause type errors in many projects currently using Hono's RPC, so I think this should be considered carefully.

@yusukebe
Copy link
Member Author

@kosei28 Thanks for the comment!

However, merging this may cause type errors in many projects currently using Hono's RPC, so I think this should be considered carefully.

Exactly. We don't have to hurry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request.
Projects
None yet
Development

No branches or pull requests

2 participants