-
-
Notifications
You must be signed in to change notification settings - Fork 53
fix: treaty infer status code (#201) #203
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?
Conversation
WalkthroughThe changes introduce new TypeScript utility types for numeric range handling and update the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Treaty
participant ElysiaApp
Client->>Treaty: Send GET request
Treaty->>ElysiaApp: Forward request
ElysiaApp-->>Treaty: Respond with status code (e.g., 199, 200, 201, 299, 300)
Treaty-->>Client: Return response
Note right of Treaty: Type mapping:<br>status 200-299 → data<br>otherwise → error
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15 minutes Poem
Note 🔌 MCP (Model Context Protocol) integration is now available in Early Access!Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context. ✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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
🧹 Nitpick comments (1)
src/treaty2/types.ts (1)
41-42
: Consider TypeScript recursion depth limitsThe
Enumerate
type uses recursive type instantiation which has a default depth limit of 1000 in TypeScript. While generating 100 values (200-299) is well within limits, this implementation could fail for larger ranges.For future extensibility, consider documenting this limitation or implementing a more efficient approach for larger ranges if needed.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/treaty2/types.ts
(3 hunks)test/types/treaty2.ts
(2 hunks)
🔇 Additional comments (3)
src/treaty2/types.ts (2)
44-47
: Well-implemented HTTP success status range typesThe
IntegerRange
andSuccessCodeRange
types correctly model the HTTP 2xx success status range (200-299). TheIsSuccessCode
helper provides a clean way to check membership in this range.
168-200
: Correct generalization of HTTP success status handlingThe
TreatyResponse
type now properly handles all 2xx status codes as success responses, which aligns with HTTP specification standards. The use ofExtract
andExclude
withSuccessCodeRange
cleanly separates success and error cases.test/types/treaty2.ts (1)
1068-1131
: Comprehensive test coverage for HTTP status code rangesThe new test cases thoroughly verify the type inference behavior across the boundary conditions:
- Below 2xx range (199)
- Start of 2xx range (200)
- Middle of 2xx range (201)
- End of 2xx range (299)
- Above 2xx range (300)
The assertions correctly validate that 2xx codes result in typed data and unknown errors, while non-2xx codes result in unknown data and typed errors.
Looks like two PRs are open solving the same #204 |
Closes #201
Summary by CodeRabbit
New Features
Tests