Skip to content

Expose handler type with preload on - #697

Merged
DZakh merged 2 commits into
mainfrom
dz/expose-handler-type-with-preload
Aug 20, 2025
Merged

DZakh merged 2 commits into
mainfrom
dz/expose-handler-type-with-preload

Conversation

@DZakh

@DZakh DZakh commented Aug 20, 2025 •

Copy link
Copy Markdown
Member

Fixes #540

Summary by CodeRabbit

  • New Features

    • When preload_handlers is enabled, generated code now includes typed aliases for handler arguments, handlers, and contract registration. This improves type clarity, autocompletion, and integration in consumer projects. Behavior is unchanged when preload_handlers is disabled.
  • Chores

    • Internal template output updated to emit explicit handler-related types only for preload_handlers-enabled generation, with no impact on public APIs.

@DZakh
DZakh requested a review from JonoPrest August 20, 2025 12:13
@coderabbitai

coderabbitai Bot commented Aug 20, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The template for generated code now emits three type aliases in the preload_handlers branch: handlerArgs, handler, and contractRegister, replacing a previously empty output. The non-preload branch remains unchanged. No Rust public API signatures were modified; only generated string content was updated.

Changes

Cohort / File(s) Summary
Codegen templates
codegenerator/cli/src/hbs_templating/codegen_templates.rs
In the preload_handlers path, generated code now includes type aliases: handlerArgs = Internal.genericHandlerArgs<event, handlerContext, unit>, handler = Internal.genericHandler, and contractRegister = Internal.genericContractRegister<Internal.genericContractRegisterArgs<event, contractRegistrations>>. Non-preload path unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Generate type for handlerArgs per event (#540) ❓ handlerArgs alias added, but per-event specificity is unclear from the template and only applied under preload_handlers.
Generate type for loaderArgs per event (#540) ❌ No loaderArgs type introduced.

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Add contractRegister type alias in generated code (codegenerator/cli/src/hbs_templating/codegen_templates.rs) Not requested by #540, which targets loaderArgs and handlerArgs only.
Add handler type alias in generated code (codegenerator/cli/src/hbs_templating/codegen_templates.rs) #540 does not mention introducing a handler alias; scope is limited to args types.

Possibly related PRs

Poem

A nibble of types in fields of code,
I twitch my ears at the preload mode.
HandlerArgs hop in, a tidy trio appears,
But where’s loaderArgs? I thump my fears.
Still, springy steps on the template track—
One hop forward, one to circle back. 🐇

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dz/expose-handler-type-with-preload

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
codegenerator/cli/src/hbs_templating/codegen_templates.rs (1)

462-469: Preload branch types look correct; consider also exposing loaderArgs and confirm 'unit is the intended loader return.

  • Emitting handlerArgs, handler, and contractRegister under preload_handlers is aligned with the PR goal and seems correct.
  • Given Issue #540’s objective to generate types for both loaderArgs and handlerArgs per event, it may be beneficial to also expose loaderArgs in the preload branch for ergonomics (typing loaders created outside registration), even if loaders are preloaded at runtime.
  • Please confirm that hard-coding the loader return to unit in handlerArgs is the intended semantics when preloading is enabled. If handler code is expected to access loader results even in preload mode, unit may be too restrictive.

Proposed addition of loaderArgs in the preload branch:

             format!(
                 r#"@genType
+type loaderArgs = Internal.genericLoaderArgs<event, loaderContext>
+@genType
 type handlerArgs = Internal.genericHandlerArgs<event, handlerContext, unit>
 @genType
 type handler = Internal.genericHandler<handlerArgs>
 @genType
 type contractRegister = Internal.genericContractRegister<Internal.genericContractRegisterArgs<event, contractRegistrations>>"#
             )

Follow-ups:

  • If you want, I can add a minimal test asserting that module_code contains the new preload-specific types when preload_handlers = true (e.g., check for type handlerArgs = Internal.genericHandlerArgs<event, handlerContext, unit> and type loaderArgs = Internal.genericLoaderArgs<event, loaderContext>). Do you want me to draft that test?
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a021fd1 and bd82cd3.

📒 Files selected for processing (1)
  • codegenerator/cli/src/hbs_templating/codegen_templates.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build_and_test

@DZakh
DZakh enabled auto-merge (squash) August 20, 2025 13:52
@DZakh
DZakh merged commit f5d55e5 into main Aug 20, 2025
2 checks passed
@DZakh
DZakh deleted the dz/expose-handler-type-with-preload branch August 20, 2025 13:59
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

Successfully merging this pull request may close these issues.

2 participants