You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(node): return NodeHttp1Handler & NodeHttp2Handler from toNodeHandler - #376
toNodeHandler() returns a function typed with (NodeServerRequest, NodeServerResponse) that supports both HTTP/1 and HTTP/2, so its return type should be NodeHttp1Handler & NodeHttp2Handler & AdapterMeta rather than the NodeHttpHandler union.
Changes:
Update toNodeHandler()'s return type (and internal __nodeHandler return assertion) to NodeHttp1Handler & NodeHttp2Handler & AdapterMeta.
Remove the workaround as NodeHttp1Handler casts in test/node-adapters.test.ts, test/node-error-paths.test.ts, and test/node-promises.test.ts.
Add a test verifying toNodeHandler() is directly assignable to both node:http's createServer and node:http2's createServer.
Summary by CodeRabbit
Improvements
Improved TypeScript support for using the Node adapter with both HTTP/1 and HTTP/2 servers, without requiring type casts.
No actionable comments were generated in the recent review.
Walkthrough
toNodeHandler now returns a type that combines the Node HTTP/1 and HTTP/2 handler types. Tests pass the inferred result to both server constructors and remove explicit HTTP/1 handler casts.
Changes: Node handler type compatibility
Layer / File(s)
Summary
Combined return type and server usage src/adapters/_node/adapter.ts, test/node-adapters.test.ts, test/node-error-paths.test.ts, test/node-promises.test.ts
toNodeHandler returns the intersection of NodeHttp1Handler, NodeHttp2Handler, and AdapterMeta. Tests verify acceptance by both server constructors and remove NodeHttp1Handler casts.
h3js/srvx#368: Changes the toNodeHandler() return type and removes casts to address the same linked issue.
Suggested reviewers:pi0x
Merge Risk: Minimal · up to e3b4f
This change lets the Node handler be passed to HTTP and HTTP/2 servers without casts, with no runtime behavior change. The one documented caveat about handlers round-tripped through the fetch adapter is accepted, so the change looks ready to merge.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: toNodeHandler's return type becomes NodeHttp1Handler & NodeHttp2Handler, which matches the adapter.ts type change and the objectives (PR #376, issue #367). The fix(nod…
Linked Issues check
[#367] Issue #367 requires that the return type of toNodeHandler() allow direct passing to node:http, node:https, and node:http2 servers without a cast. At the reviewed head, `src/adapters/_no…
Out of Scope Changes check
All reported changes serve issue #367. The return-type change and the internal __nodeHandler assertion in src/adapters/_node/adapter.ts implement the requested type. Removing the `NodeHttp1Handler…
Full details: Title check
Explanation
The title names the main change: toNodeHandler's return type becomes NodeHttp1Handler & NodeHttp2Handler, which matches the adapter.ts type change and the objectives (PR #376, issue #367). The fix(node) prefix matches the node adapter scope. The test updates and the new createServer assignment test are supporting changes that the title does not need to cover.
Full details: Linked Issues check
Explanation
[#367] Issue #367 requires that the return type of toNodeHandler() allow direct passing to node:http, node:https, and node:http2 servers without a cast. At the reviewed head, src/adapters/_node/adapter.ts declares toNodeHandler(...) as returning NodeHttp1Handler & NodeHttp2Handler & AdapterMeta, which matches the issue's expected return type. The __nodeHandler cached-return path is cast to the same type. The convertedNodeHandler path returns without a cast. The summary reports that the as NodeHttp1Handler workarounds were removed from test/node-adapters.test.ts, test/node-error-paths.test.ts, and test/node-promises.test.ts, and that a new assignability test was added to test/node-adapters.test.ts. I read the source file only. I did not read the test diffs or run the TypeScript compiler, so the test-file changes rest on the PR summary. The issue's round-trip caveat is acknowledged in the PR description; it does not add a coding requirement.
Full details: Out of Scope Changes check
Explanation
All reported changes serve issue #367. The return-type change and the internal __nodeHandler assertion in src/adapters/_node/adapter.ts implement the requested type. Removing the NodeHttp1Handler casts and adding an assignability test in the three test files support the same objective. No runtime behavior change or unrelated edit is reported. The test-file hunks were not read directly, so this verdict relies on the PR summary for those files.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Fix failing CI checks
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
A rabbit checks the handler’s type, For HTTP/1 and HTTP/2 alike. No cast is needed in the test, The inferred type now meets the request. Hop, hop, both servers accept it right!
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 43ab22d4-fd87-40ad-a4a3-7ea6233ba390
Commits
Reviewing files that changed from the base of the PR and between 14641b9 and e3b4f31.
Files selected for processing: 4
src/adapters/_node/adapter.ts
test/node-adapters.test.ts
test/node-error-paths.test.ts
test/node-promises.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #367
toNodeHandler()returns a function typed with(NodeServerRequest, NodeServerResponse)that supports both HTTP/1 and HTTP/2, so its return type should beNodeHttp1Handler & NodeHttp2Handler & AdapterMetarather than theNodeHttpHandlerunion.Changes:
toNodeHandler()'s return type (and internal__nodeHandlerreturn assertion) toNodeHttp1Handler & NodeHttp2Handler & AdapterMeta.as NodeHttp1Handlercasts intest/node-adapters.test.ts,test/node-error-paths.test.ts, andtest/node-promises.test.ts.toNodeHandler()is directly assignable to bothnode:http'screateServerandnode:http2'screateServer.Summary by CodeRabbit