feat(nest): add Hono framework support#1299
Conversation
📝 WalkthroughWalkthroughAdded Hono adapter support to the Nest ImplementInterceptor and workspace/dev dependencies; interceptor now detects runtime adapter (Hono / Fastify / Node) and branches request/response conversion through the corresponding StandardServer adapter. Added a Hono compatibility test and documentation section. ChangesNest Hono + multi-adapter integration
Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant Interceptor as ImplementInterceptor
participant Adapters as Standard Adapters
participant AdapterCtx as Adapter Context / Server
Client->>Interceptor: HTTP request
Interceptor->>Interceptor: detect adapter (isHono / isFastify / else Node)
alt Hono
Interceptor->>AdapterCtx: use req.raw via HonoContext
Interceptor->>Adapters: StandardServerFetch.toStandardLazyRequest(req.raw)
Adapters-->>Interceptor: standardRequest
Interceptor->>Adapters: execute handler -> standardResponse
Interceptor->>Adapters: StandardServerFetch.toFetchResponse(standardResponse)
Adapters-->>AdapterCtx: AdapterCtx.newResponse(fetchResponse)
else Fastify
Interceptor->>AdapterCtx: use Fastify req/res
Interceptor->>Adapters: StandardServerFastify.toStandardLazyRequest(req,res)
Adapters-->>Interceptor: standardRequest
Interceptor->>Adapters: StandardServerFastify.sendStandardResponse(res, standardResponse)
else Node/Express
Interceptor->>AdapterCtx: use Node req/res
Interceptor->>Adapters: StandardServerNode.toStandardLazyRequest(req,res)
Adapters-->>Interceptor: standardRequest
Interceptor->>Adapters: StandardServerNode.sendStandardResponse(res, standardResponse)
end
AdapterCtx-->>Client: HTTP response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
Summary of ChangesHello @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 Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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
a95114e to
975b04c
Compare
There was a problem hiding this comment.
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
resproperty 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
📒 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-fetchpackage 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
toFetchResponsereturns immediately and@kiyasov/platform-honopicks up theresproperty. The Fastify and Node branches appropriatelyawaitthe stream-basedsendStandardResponse.
dinwwwh
left a comment
There was a problem hiding this comment.
Please add tests for this feature, include routing matching and update the docs
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/nest/src/implement.test.ts (1)
700-736: ⚡ Quick winAdd one Hono assertion for dynamic/overridden status propagation.
This test covers happy-path/error-path well, but it doesn’t yet pin the Hono-specific response conversion for custom statuses. A regression in
toFetchResponse/newResponsecould still pass here. Add a request whereping_handlerreturnsstatus: 203(or a sendResponseInterceptor override) and assert the HTTP status.Suggested test addition
try { const pingRes = await supertest(httpServer) .post('/ping?param=value¶m2[]=value2¶m2[]=value3') .set('x-custom', 'value') .send({ hello: 'world' }) expect(pingRes.statusCode).toEqual(200) expect(pingRes.body).toEqual('pong') expect(pingRes.headers).toEqual(expect.objectContaining({ 'x-ping': 'pong' })) + + ping_handler.mockResolvedValueOnce({ body: 'pong', headers: { 'x-ping': 'pong' }, status: 203 } as any) + const ping203Res = await supertest(httpServer) + .post('/ping?param=value') + .send({ hello: 'world' }) + expect(ping203Res.statusCode).toEqual(203)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/nest/src/implement.test.ts` around lines 700 - 736, Add an assertion that verifies Hono-specific status propagation by creating a request where ping_handler returns a non-default status (e.g., status: 203) or by using the sendResponseInterceptor to override the response status, then send that request in the same test block and assert the HTTP status equals 203; locate the existing pingRes/ping_handler usage in the test (references: ping_handler and pong_handler) and add a new supertest call and expect(...statusCode).toEqual(203) to ensure toFetchResponse/newResponse correctly preserves custom statuses.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/nest/src/implement.test.ts`:
- Around line 700-736: Add an assertion that verifies Hono-specific status
propagation by creating a request where ping_handler returns a non-default
status (e.g., status: 203) or by using the sendResponseInterceptor to override
the response status, then send that request in the same test block and assert
the HTTP status equals 203; locate the existing pingRes/ping_handler usage in
the test (references: ping_handler and pong_handler) and add a new supertest
call and expect(...statusCode).toEqual(203) to ensure
toFetchResponse/newResponse correctly preserves custom statuses.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7df67dd5-3632-4482-9728-a5e59f17d089
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (4)
apps/content/docs/openapi/integrations/implement-contract-in-nest.mdpackages/nest/package.jsonpackages/nest/src/implement.test.tspackages/nest/src/implement.ts
✅ Files skipped from review due to trivial changes (1)
- apps/content/docs/openapi/integrations/implement-contract-in-nest.md
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/nest/src/implement.ts
- packages/nest/package.json
More templates
@orpc/ai-sdk
@orpc/arktype
@orpc/client
@orpc/contract
@orpc/experimental-durable-iterator
@orpc/hey-api
@orpc/interop
@orpc/json-schema
@orpc/nest
@orpc/openapi
@orpc/openapi-client
@orpc/otel
@orpc/experimental-pino
@orpc/experimental-publisher
@orpc/experimental-publisher-durable-object
@orpc/experimental-ratelimit
@orpc/react
@orpc/react-query
@orpc/experimental-react-swr
@orpc/server
@orpc/shared
@orpc/solid-query
@orpc/standard-server
@orpc/standard-server-aws-lambda
@orpc/standard-server-fastify
@orpc/standard-server-fetch
@orpc/standard-server-node
@orpc/standard-server-peer
@orpc/svelte-query
@orpc/tanstack-query
@orpc/trpc
@orpc/valibot
@orpc/vue-colada
@orpc/vue-query
@orpc/zod
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Summary
Adds Hono-based HTTP adapter support to
@orpc/nestso@Implementroutes can run in Nest applications backed by a Hono adapter.Changes
@orpc/standard-server-fetch.ResponsewithnewResponse(...).OPTIONSroute decorator support for implemented contract routes.@mnigos/platform-hono@^0.1.3, including request body/query/header parsing, route params, response headers, and error responses.@mnigos/platform-honoas an example.Summary by CodeRabbit
New Features
Documentation
Tests