core icon indicating copy to clipboard operation
core copied to clipboard

Generator system

Open thetutlage opened this issue 5 months ago • 19 comments

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/pages directory.
  • Creating types for registered routes. This action should run every time the HTTP server is restarted (so we can use the start method 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/transformers directory.

Updates

Related commits and PRs

  • https://github.com/adonisjs/assembler/commit/194861c6dce0c09dd25bb2ddf5ba97c77ff55563
  • https://github.com/adonisjs/assembler/releases/tag/v8.0.0-next.6

thetutlage avatar Sep 05 '25 05:09 thetutlage

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.

iamtommcc avatar Sep 09 '25 06:09 iamtommcc

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',
      }
    })
  ]
}

thetutlage avatar Sep 10 '25 04:09 thetutlage

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

github-actions[bot] avatar Oct 02 '25 00:10 github-actions[bot]

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:

Image

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.

Image

I also tried adding props to the page, but they don’t seem to reflect in the render method.

Image Image

Here’s the generated type definition from .adonisjs/server/pages.d.ts:

Image

muco-rolle avatar Oct 04 '25 07:10 muco-rolle

Weird. Can you please share this project as a repo with me?

thetutlage avatar Oct 04 '25 08:10 thetutlage

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

muco-rolle avatar Oct 04 '25 09:10 muco-rolle

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:

Image

When JSONDataTypes is removed:

Image

I can provide more details if this happens to be an edge case.

muco-rolle avatar Oct 05 '25 09:10 muco-rolle

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.

thetutlage avatar Oct 05 '25 09:10 thetutlage

@muco-rolle I found the issues after using your repo. Fixing them 🙏

thetutlage avatar Oct 05 '25 10:10 thetutlage

Okay, thank you!

muco-rolle avatar Oct 05 '25 13:10 muco-rolle

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 avatar Oct 18 '25 10:10 muco-rolle

@muco-rolle Onto it!

thetutlage avatar Oct 19 '25 06:10 thetutlage

Awesome, thanks!

muco-rolle avatar Oct 19 '25 07:10 muco-rolle

@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 avatar Oct 19 '25 15:10 thetutlage

@thetutlage, it works perfectly fine now. Thanks! I definitely will.

muco-rolle avatar Oct 20 '25 20:10 muco-rolle

@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:

Image

When the second argument is provided:

Image

muco-rolle avatar Oct 21 '25 09:10 muco-rolle

Yeah, that's a known issue right now. I will fix it in the next release 👍🏽

thetutlage avatar Oct 22 '25 05:10 thetutlage

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

github-actions[bot] avatar Nov 13 '25 00:11 github-actions[bot]

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

github-actions[bot] avatar Dec 05 '25 00:12 github-actions[bot]

Closing, since we have it stable for a while, except the Inertia intellisense for which we will create a separate issue

thetutlage avatar Dec 15 '25 12:12 thetutlage