Generator system
The generator system will be used to create types for various things. It includes
- Scanning Inertia pages and creating a types file for them. This action should run anytime a file is changed inside the
inertia/pagesdirectory. - Creating types for registered routes. This action should run every time the HTTP server is restarted (so we can use the
startmethod from the providers) - Creating the frontend routes client for creating URLs. This action should run every time the HTTP server is restarted.
- Creating an index file with lazy imported controllers. It will cleanup the imports inside the routes file. This action should run anytime files are changed inside the controllers directory with the ability to specify a custom source for controllers.
- Creating types for HTTP transformers. This action should run anytime a file is changed inside the
app/transformersdirectory.
Updates
- Added RoutesScanner
- Added IndexGenerator and integrate it with the DevServer and the TestRunner
Related commits and PRs
- https://github.com/adonisjs/assembler/commit/194861c6dce0c09dd25bb2ddf5ba97c77ff55563
- https://github.com/adonisjs/assembler/releases/tag/v8.0.0-next.6
Just a quick question with all this ongoing codegen work/E2E type safety/delightful grep-ast magic going on recently... will scanning directory patterns always be configurable?
For my larger apps I find using a domain module approach (e.g. app/publications/controllers, app/publications/transformers) helps a lot for reasoning around large codebases. I know in modern day Laravel land this approach is becoming increasingly popular.
Yes, it will be configurable. This is how you can tell the scanners to look for controllers in a DDD setup.
hooks: {
init: [
indexEntities({
controllers: {
enabled: true,
source: './app',
glob: '**/controllers/**/*.ts',
}
})
]
}
This issue has been marked as stale because it has been inactive for more than 21 days. Please reopen if you still need help on this issue
Hello,
I just had the chance to try out the latest v7-alpha release, and I wanted to say thank you, I can already feel the DX improvements, especially around end-to-end type safety.
I did, however, notice a few issues I’d like to highlight.
From what I’ve read, inertia.render should be type-safe, but it doesn’t seem to be working for me.
A clean install of the Inertia/React starter kit shows the following error:
That makes sense since there are no props defined on the page, but if you remove the object, you get another error; render now requires more parameters than just the page.
I also tried adding props to the page, but they don’t seem to reflect in the render method.
Here’s the generated type definition from .adonisjs/server/pages.d.ts:
Weird. Can you please share this project as a repo with me?
Yes, it’s just the default starter kit generated with the following command:
npm init adonisjs@next --kit=adonisjs:react-starter-kit
Here’s the repo:
[email protected]:muco-rolle/adonisjs_v7.git
Another issue I found is in the transformer. When the toObject method’s return type is set to JSONDataTypes, the resource types are missing from the generated types in .adonisjs/client/data.d.ts. However, they appear correctly when that type is removed.
The screenshots below show the difference between when JSONDataTypes is not added to the toObject method and when it is.
When JSONDataTypes is added:
When JSONDataTypes is removed:
I can provide more details if this happens to be an edge case.
Which is expected, because in that case you are explicitly setting the return type of a function to JSONDataTypes. You should let TypeScript infer the return type.
@muco-rolle I found the issues after using your repo. Fixing them 🙏
Okay, thank you!
Hey @thetutlage I’m starting a new project and would love to use v7 for its transformer support and Inertia’s end-to-end type safety, since my current v6 setup is pretty messy in those areas. I’d be happy to help fix this if you can point me to the issue. I think the only problem now is with the render method in inertia.render. The node ace make:transformer command no longer adds JSONDataTypes to the toObject method.
@muco-rolle Onto it!
Awesome, thanks!
@muco-rolle Fixed. You can try creating a new app and lemme know how it goes. Also, feel free to report any issues you face as you use v7.
This commit should explain the changes. https://github.com/adonisjs/react-starter-kit/commit/218eb381530b716d73317b1f239a55936a90ce5a
@thetutlage, it works perfectly fine now. Thanks! I definitely will.
@thetutlage
There's still an issue: if the page doesn't define any props, the render method makes the pageProps argument required. Ideally, the pageProps argument should be optional when no props are defined on the page, just like in v6.
When the second argument is not provided:
When the second argument is provided:
Yeah, that's a known issue right now. I will fix it in the next release 👍🏽
This issue has been marked as stale because it has been inactive for more than 21 days. Please reopen if you still need help on this issue
This issue has been marked as stale because it has been inactive for more than 21 days. Please reopen if you still need help on this issue
Closing, since we have it stable for a while, except the Inertia intellisense for which we will create a separate issue