Skip to content

Conversation

@Mnigos
Copy link

@Mnigos Mnigos commented Dec 14, 2025

Summary

Adds support for the Hono HTTP adapter in the @orpc/nest package, enabling oRPC contracts to work with NestJS applications using @kiyasov/platform-hono.

Changes

  • Added @orpc/standard-server-fetch dependency for fetch-based request/response handling
  • Detect Hono adapter by checking for finalized property and newResponse method on response context
  • Convert Hono requests using toStandardLazyRequest from standard-server-fetch
  • Set response on Hono context using toFetchResponse

Usage

Works automatically when using @kiyasov/platform-hono. No configuration needed.

Related

This PR works in conjunction with a fix in @kiyasov/platform-hono that returns the pre-built response when ctx.res is set by interceptors. kiyasov/platform-hono#10

Summary by CodeRabbit

  • New Features
    • Added runtime support for Hono and Fastify servers so the package can run on those platforms in addition to existing environments.
    • Improved cross-framework request/response handling to ensure interceptors and responses work consistently across supported server types.

✏️ Tip: You can customize this high-level summary in your review settings.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Dec 14, 2025
@coderabbitai
Copy link

coderabbitai bot commented Dec 14, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Added a workspace dependency and extended Nest implement.ts to detect Hono/Fastify/Node at runtime, converting incoming requests and sending responses via the corresponding standard-server adapter branches.

Changes

Cohort / File(s) Summary
Dependency Management
packages/nest/package.json
Added workspace dependency @orpc/standard-server-fetch: "workspace:*"
Multi‑Framework Request/Response Handling
packages/nest/src/implement.ts
Imported StandardServerFetch; added HonoContext type; extended request/response unions to include Hono and Fastify; added runtime checks (isHono, isFastify) and branching to use the appropriate adapter: StandardServerFetch (Hono), StandardServerFastify (Fastify), or StandardServerNode (Node/Express) for toStandardLazyRequest and sending responses.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ImplementTS as implement.ts
    participant Adapters as Standard Adapters
    participant HTTP as HTTP Response

    Client->>ImplementTS: Incoming request
    ImplementTS->>ImplementTS: runtime check: isHono? / isFastify? / else Node
    alt Hono
        ImplementTS->>Adapters: StandardServerFetch.toStandardLazyRequest(req.raw)
        Adapters->>ImplementTS: standardRequest
        ImplementTS->>Adapters: StandardServerFetch.toFetchResponse(...)
        Adapters->>HTTP: deliver fetch response to Hono
    else Fastify
        ImplementTS->>Adapters: StandardServerFastify.toStandardLazyRequest(req,res)
        Adapters->>ImplementTS: standardRequest
        ImplementTS->>Adapters: StandardServerFastify.sendStandardResponse(...)
        Adapters->>HTTP: deliver Fastify response
    else Node/Express
        ImplementTS->>Adapters: StandardServerNode.toStandardLazyRequest(req,res)
        Adapters->>ImplementTS: standardRequest
        ImplementTS->>Adapters: StandardServerNode.sendStandardResponse(...)
        Adapters->>HTTP: deliver Node/Express response
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Pay attention to: isHono / isFastify detection correctness and edge cases.
  • Verify adapter import/exports and method signatures (toStandardLazyRequest, toFetchResponse, sendStandardResponse).
  • Ensure Hono path uses req.raw safely and response assignment integrates with Hono lifecycle.

Possibly related issues

  • unnoq/orpc#1291: Matches Hono-specific handling and dependency addition for @orpc/standard-server-fetch; likely addressed by these changes.

Possibly related PRs

  • unnoq/orpc#290: Alters standard-server-fetch/adapter APIs used by the new Hono branch — directly relevant.
  • unnoq/orpc#1256: Modifies packages/nest/src/implement.ts request/response flow; intersects with these branching changes.
  • unnoq/orpc#1001: Changes how standardRequest.body is derived in implement.ts; related to adapter conversion logic.

Poem

🐇 I twitched my nose and hopped between threads,
Hono, Fastify, Node — I carried your meds.
Adapters in pockets, branching delight,
One rabbit, three paths, routing just right. ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(nest): add Hono framework support' accurately and specifically summarizes the main change—adding Hono framework support to the @orpc/nest package.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Mnigos, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the @orpc/nest package by introducing support for the Hono HTTP adapter. The primary goal is to allow oRPC contracts to function correctly within NestJS applications that leverage the Hono framework, particularly through @kiyasov/platform-hono. The changes involve adapting the core request and response handling mechanisms to align with Hono's fetch-based API, ensuring that applications can utilize Hono's performance benefits without requiring manual configuration for oRPC integration.

Highlights

  • Hono Framework Support: Added comprehensive support for the Hono HTTP adapter within the @orpc/nest package, enabling oRPC contracts to seamlessly integrate with NestJS applications utilizing @kiyasov/platform-hono.
  • Dependency Addition: Introduced the @orpc/standard-server-fetch dependency to handle fetch-based request and response processing, which is crucial for Hono's architecture.
  • Dynamic Adapter Detection: Implemented logic to automatically detect the Hono adapter by checking for specific properties (finalized and newResponse method) on the response context, allowing for adaptive request and response handling.
  • Request and Response Conversion: Integrated toStandardLazyRequest from standard-server-fetch for converting Hono requests into a standard format and toFetchResponse for setting the response on the Hono context.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for the Hono framework to @orpc/nest. The changes correctly detect the Hono environment through duck-typing and use @orpc/standard-server-fetch to handle requests and responses. The implementation looks solid. I've provided a few suggestions to improve type correctness and code readability.

- Add @orpc/standard-server-fetch dependency
- Add HonoContext interface for Hono framework detection
- Extend ImplementInterceptor to handle Hono requests and responses
- Support Hono adapter in interceptor response handling
@Mnigos Mnigos force-pushed the fix/hono-adapter-interceptor-response branch from a95114e to 975b04c Compare December 14, 2025 18:48
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
packages/nest/src/implement.ts (1)

136-137: Add explanatory comment for the duck-typing detection logic.

The detection logic is correct, but relies on duck-typing which is fragile if underlying frameworks change. As noted in a previous review, add a comment explaining this coupling:

+        // Detect Hono adapter by checking for properties on the response context.
+        // This is coupled with `@kiyasov/platform-hono`.
+        // See: https://github.com/kiyasov/platform-hono/pull/10
         const isHono = 'finalized' in res && typeof (res as HonoContext).newResponse === 'function'
+        // Fastify also has `raw` on request, so exclude Hono first
         const isFastify = 'raw' in req && !isHono
🧹 Nitpick comments (1)
packages/nest/src/implement.ts (1)

24-29: Well-defined minimal interface.

The interface correctly models only the relevant Hono context surface area. The optional res property accurately reflects that it's assigned by the interceptor rather than being initially present.

Consider adding a brief JSDoc comment explaining this interface's purpose and its coupling to @kiyasov/platform-hono:

+/**
+ * Minimal interface for Hono-like request/response context.
+ * Coupled with @kiyasov/platform-hono behavior.
+ * @see https://github.com/kiyasov/platform-hono/pull/10
+ */
 interface HonoContext {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a95114e and 975b04c.

📒 Files selected for processing (2)
  • packages/nest/package.json (1 hunks)
  • packages/nest/src/implement.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/nest/package.json
🧰 Additional context used
🧬 Code graph analysis (1)
packages/nest/src/implement.ts (1)
packages/standard-server-fastify/src/index.ts (1)
  • FastifyRequest (4-4)
🔇 Additional comments (3)
packages/nest/src/implement.ts (3)

18-18: LGTM!

Import correctly added alongside other standard server adapters. The @orpc/standard-server-fetch package is appropriate for Hono's web-standard Request/Response handling.


139-147: LGTM!

The IIFE pattern cleanly implements the multi-platform request handling. The branch order correctly mirrors the detection logic, and type assertions are safe given the preceding runtime checks.


168-176: Response handling correctly adapts to each platform.

The Hono branch correctly uses synchronous assignment since toFetchResponse returns immediately and @kiyasov/platform-hono picks up the res property. The Fastify and Node branches appropriately await the stream-based sendStandardResponse.

Copy link
Member

@unnoq unnoq left a comment

Choose a reason for hiding this comment

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

Please add tests for this feature, include routing matching and update the docs

if ('raw' in response) {
await StandardServerFastify.sendStandardResponse(response, standardResponse, this.config)
if (isHono) {
(response as HonoContext).res = StandardServerFetch.toFetchResponse(standardResponse, this.config)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should set res directly, we should use built-in method to well integrate with hono apis: https://orpc.dev/docs/adapters/hono

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants