-
-
Notifications
You must be signed in to change notification settings - Fork 126
feat(nest): add Hono framework support #1299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(nest): add Hono framework support #1299
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit 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. WalkthroughAdded 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related issues
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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.
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
a95114e to
975b04c
Compare
There was a problem hiding this 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
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.
unnoq
left a comment
There was a problem hiding this 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) |
There was a problem hiding this comment.
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
Summary
Adds support for the Hono HTTP adapter in the
@orpc/nestpackage, enabling oRPC contracts to work with NestJS applications using@kiyasov/platform-hono.Changes
@orpc/standard-server-fetchdependency for fetch-based request/response handlingfinalizedproperty andnewResponsemethod on response contexttoStandardLazyRequestfrom standard-server-fetchtoFetchResponseUsage
Works automatically when using
@kiyasov/platform-hono. No configuration needed.Related
This PR works in conjunction with a fix in
@kiyasov/platform-honothat returns the pre-built response whenctx.resis set by interceptors. kiyasov/platform-hono#10Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.