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

Generate types for Eden #9

Open
framp opened this issue Sep 26, 2023 · 1 comment
Open

Generate types for Eden #9

framp opened this issue Sep 26, 2023 · 1 comment

Comments

@framp
Copy link
Contributor

framp commented Sep 26, 2023

Thanks for the work on this module!

I have a suggestion on how to get types for Eden.

We're loading files async at runtime, which makes it impossible to have end to end type safety during development.

I think Prisma has a similar issue (just with database schemas, instead of async file fetching) and the only solution is to generate types manually from a state X of the filesystem

In order to have this working we need to configure something project wise, so that if you have multiple instances to elysia-autoroutes you could generate the type for all of those directories.

Ideally I'd like to have:

  • an autoroutes command which can:
    • generate: if a file autoroutes.json is present, parse it and assume it's an array of strings of routesDir. If it's not available, scan the AST of all the ts/js/tsx/jsx files in the project, looking for calls to autoroutes, collect routesDir. For each routesDir, generate a file in node_modules/.autoroutes/router-${myRoutesDir}.ts which requires all the files and generate the correct types for the routers
    • preload-paths: run the logic in generate and save the paths to autoroutes.json
    • generate --watch: run generate and watches for file changes in the routes directories (not in all the projects, scanning for AST, that'd be a perf nightmare)
  • When the user is using the autoroutes plugin, get the type from node_modules/.autoroutes/router-${myRoutesDir}.ts the and cast the router to that type (but still load it dynamically at runtime)

Runtime behaviour will be unchanged, we should just get better types instead of unknown

What do you think? I might try to sketch something

@kravetsone
Copy link

I released elysia-autoload with this feature)

NPM
GitHub

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

No branches or pull requests

2 participants