glutinum-org / Glutinum

MIT License
30 stars 3 forks source link

express middleware binding types #16

Closed joprice closed 1 week ago

joprice commented 1 week ago

I'm curious when combining the bindings for Express in this repo with bindings generated by glutinum-cli, what would the expected types for the use function when being called with middleware be? When generating code for express-basic-auth, the middleware function as express's RequestHandler, which seems to map to the type Glutinum.Express.Express.RequestHandler. However, I can't seem to call use with it to provide the middleware to the application.

I can work around this by typing the middleware as Func<Request, Response, NextFunction, unit>, but not sure if there should be a common type for sharing middleware bindings.

MangelMaxime commented 1 week ago

If I remember correctly it needs to be one of these types:

https://github.com/glutinum-org/Glutinum/blob/52b2f2487aa2195fb04751df72f607aa6980f4b7/glues/ExpressServeStaticCore/src/Glutinum.ExpressServeStaticCore.fs#L1131-L1142

Express binding were created / optimised manually a few fears ago.

I plan to try them with Glutinum in the future, but I already know that in the current state the existing bindings are better because Glutinum is missing some key feature yet like https://github.com/glutinum-org/cli/issues/29 https://github.com/glutinum-org/cli/issues/18 and similar things.

joprice commented 1 week ago

Checking out some other libraries, it seems that they make use of structural typing a lot and so don't share common interfaces, but perhaps there's some union or set of overloads that could be used to wrangle the most popular ones so the generated code can be usable without coercions or extra helpers.