chungweileong94 / server-act

A simple React server action builder
MIT License
20 stars 1 forks source link

Feature Request: Context-Preserving Middleware Chaining #26

Open rvndev opened 3 days ago

rvndev commented 3 days ago

Currently, server-act overwrites previous context when chaining multiple middlewares. It would be very useful if, instead of the current behaviour, all middleware contexts were merged.

I was trying to extend server-act to do this, however, I am not a TypeScript wizard and was running into issues when trying to preserve type safety.

I was wondering if you would like to help me with the type safety feature?

chungweileong94 commented 3 days ago

Thought of that before, but it wasn't too difficult to achieve that in the current state, by chaining multiple middlewares (or functions, which they simply are). Maybe we can have a helper function like chainMiddlewares(midlewareOne, middlewareTwo, ...), so it will look something like

serverAct
  .middleware(chainMiddleware(middlewareOne, middlewareTwo, ...))
  .action(...)

I also thought of chaining middleware like serverAct.middleware(...).middleware(...).action(...), but I worry about if this will create any overhead. I might be overthinking, but feedbacks are welcome🙂

chungweileong94 commented 3 days ago

More on the chaining middleware, it could be challenging to make it type-safe as well.

chungweileong94 commented 2 days ago

Before we have an actual middleware chaining implementation, we will prevent people from chaining multiple duplicate methods at type-level in #27.