wobsoriano / elysia-autoroutes

File system routes for Elysia.js.
MIT License
112 stars 8 forks source link

Generate TypeSafe Signatures from Hooks and ElysiaApp #3

Closed framp closed 1 year ago

framp commented 1 year ago

Thanks a lot for the awesome library!

I created some basic utilities to extend the signature for Params & Body: https://github.com/framp/elysia-demo/blob/f66ed0e/src/utils.ts

they can be used like this: https://github.com/framp/elysia-demo/blob/f66ed0e/src/http/api/books/%5Bid%5D.ts but they're not very user friendly

I'm pretty sure we can autogenerate all of this by getting the app as an input and knowing which params have been defined through the filepath and what's the type of the handler.

Another completely different option could be to define a route using an Elysia instance; we should be able to set the type to the parent instance (Elysia App in your example) for type safety and then access the methods from the child instance from autoroutes.

I'll try to come up with a PR to address some of this

wobsoriano commented 1 year ago

I'm going to review this PR today. Thank you!

wobsoriano commented 1 year ago

https://github.com/wobsoriano/elysia-autoroutes/pull/4