Skip to content
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

feat(server): improve standard apis #290

Merged
merged 2 commits into from
Mar 25, 2025
Merged

Conversation

unnoq
Copy link
Owner

@unnoq unnoq commented Mar 24, 2025

Summary by CodeRabbit

  • Refactor

    • Streamlined the processing of requests and responses to ensure a more uniform behavior across different adapters.
    • Refined error handling to trigger accurate responses under specific conditions.
    • Updated the structure of the raw property in request and response objects to include adapter information.
  • Tests

    • Expanded test coverage to validate the consistent structure and improved handling of requests and responses.
    • Enhanced tests to check the presence of adapter information in request and response objects.

Copy link

vercel bot commented Mar 24, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
orpc ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 24, 2025 2:52pm

@unnoq unnoq changed the title chore(server): improve standard apis feat(server): improve standard apis Mar 24, 2025
Copy link

coderabbitai bot commented Mar 24, 2025

Walkthrough

The changes refactor several modules by simplifying parameter handling and centralizing request/response details into a new raw variable that includes an adapter property. In the StandardHandler, the intercept method now destructures parameters directly and refines error handling. Both the fetch and node implementations of lazy request/response functions have been updated to use the new raw object, and corresponding tests have been modified to verify the new structure. Additionally, interface definitions were updated to reflect these changes.

Changes

File(s) Change Summary
packages/server/.../handler.ts Refactored parameter destructuring in the intercept method; updated context passing to createProcedureClient and refined error handling logic.
packages/standard-server-fetch/.../request.ts
packages/standard-server-fetch/.../request.test.ts
Introduced a new variable raw with an adapter: 'fetch' property to encapsulate the request; updated body and headers references, and modified tests to expect the new structure.
packages/standard-server-fetch/.../response.ts
packages/standard-server-fetch/.../response.test.ts
Created a new variable raw containing { adapter: 'fetch', response } for response handling; updated body and headers accessors, with tests adjusted accordingly.
packages/standard-server-node/.../request.ts
packages/standard-server-node/.../request.test.ts
Introduced a new raw variable with an adapter: 'node' property in the lazy request function; updated the body property and test expectations to reflect the new structure.
packages/server/src/types.ts Updated StandardLazyRequest and StandardLazyResponse interfaces to specify that the raw property now includes an adapter field and revised comments for clarity.
packages/client/.../rpc-link-codec.test.ts
packages/openapi/.../openapi-handler.test.ts
packages/openapi/.../openapi-codec.test.ts
packages/server/.../rpc-handler.test.ts
packages/server/.../handler.test.ts
packages/server/.../rpc-codec.test.ts
Updated tests to expect raw property containing an adapter key with appropriate values, affecting various decoding scenarios.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Handler as StandardHandler
    participant Proc as ProcedureClient

    Client->>Handler: Call intercept(request, context, prefix)
    Handler->>Handler: Destructure parameters directly
    Handler->>Proc: Call createProcedureClient(context)
    alt Error Occurs
        Handler->>Handler: Check if isDecoding and error not ORPCError
        Handler-->>Client: Return error response
    else Success
        Handler-->>Client: Return normal response
    end
Loading
sequenceDiagram
    participant Adapter
    participant RequestFn as toStandardLazyRequest
    participant RawObj

    Adapter->>RequestFn: Pass request (from fetch/node)
    RequestFn->>RawObj: Create raw object { adapter: 'fetch'/'node', request, [response] }
    RequestFn->>RequestFn: Update body & headers from raw.request/response
    RequestFn-->>Adapter: Return StandardLazyRequest object with new structure
Loading

Possibly related PRs

Poem

I’m a rabbit hopped through change,
With code that’s neat and rearranged.
Raw objects now hold the key,
Fetch and node in harmony.
My floppy ears sway with glee—hop on, code, hop free! 🥕🐇

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

pkg-pr-new bot commented Mar 24, 2025

Open in Stackblitz

More templates

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@290

@orpc/client

npm i https://pkg.pr.new/@orpc/client@290

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@290

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@290

@orpc/openapi-client

npm i https://pkg.pr.new/@orpc/openapi-client@290

@orpc/server

npm i https://pkg.pr.new/@orpc/server@290

@orpc/react-query

npm i https://pkg.pr.new/@orpc/react-query@290

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@290

@orpc/solid-query

npm i https://pkg.pr.new/@orpc/solid-query@290

@orpc/standard-server

npm i https://pkg.pr.new/@orpc/standard-server@290

@orpc/standard-server-fetch

npm i https://pkg.pr.new/@orpc/standard-server-fetch@290

@orpc/standard-server-node

npm i https://pkg.pr.new/@orpc/standard-server-node@290

@orpc/svelte-query

npm i https://pkg.pr.new/@orpc/svelte-query@290

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@290

@orpc/vue-colada

npm i https://pkg.pr.new/@orpc/vue-colada@290

@orpc/vue-query

npm i https://pkg.pr.new/@orpc/vue-query@290

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@290

commit: 3743f70

Copy link

codecov bot commented Mar 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

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

🧹 Nitpick comments (1)
packages/server/src/adapters/standard/handler.test.ts (1)

38-38: Consider using 'unknown' for adapter instead of empty string for consistency.

While the change correctly adds the adapter property to the raw object, other similar changes in the codebase use 'unknown' as the value instead of an empty string. Consider standardizing this value for better consistency.

-    raw: { adapter: '' },
+    raw: { adapter: 'unknown' },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b43955 and 3743f70.

📒 Files selected for processing (6)
  • packages/client/src/adapters/standard/rpc-link-codec.test.ts (5 hunks)
  • packages/openapi/src/adapters/node/openapi-handler.test.ts (1 hunks)
  • packages/openapi/src/adapters/standard/openapi-codec.test.ts (4 hunks)
  • packages/server/src/adapters/node/rpc-handler.test.ts (1 hunks)
  • packages/server/src/adapters/standard/handler.test.ts (1 hunks)
  • packages/server/src/adapters/standard/rpc-codec.test.ts (2 hunks)
🔇 Additional comments (13)
packages/server/src/adapters/standard/rpc-codec.test.ts (2)

25-25: Update to request structure for GET method test.

The change adds an adapter property to the raw object in the request, aligning with the refactoring mentioned in the PR that centralizes request/response details into a raw variable with an adapter property.


48-48: Update to request structure for non-GET method test.

Similar to the GET method test, this change adds an adapter property to the raw object, maintaining consistency across different request methods. The change ensures test compatibility with the updated structure of request objects in the codebase.

packages/openapi/src/adapters/node/openapi-handler.test.ts (1)

40-50: Update to standardRequest.raw looks good!

This change aligns the test with the broader PR objectives of centralizing request/response details into a raw variable with an adapter property. Using the value 'unknown' is appropriate for this test context.

packages/server/src/adapters/node/rpc-handler.test.ts (1)

42-42: LGTM! The adapter property has been consistently added to the raw object.

This change aligns with the broader effort to standardize the request/response structure by including adapter information in the raw property. Now the tests accurately reflect that the adapter is identified as 'unknown' for test requests.

packages/openapi/src/adapters/standard/openapi-codec.test.ts (4)

27-27: LGTM! Consistently added adapter information to the raw property.

The change standardizes the test request structure by including the adapter type, which aligns with other similar changes throughout the codebase.


47-47: LGTM! Consistently added adapter information to the raw property.

The update ensures the test properly includes adapter type in the request structure for the non-GET method test case.


77-77: LGTM! Consistently added adapter information to the raw property.

This change continues the pattern of standardizing request structures by adding the adapter property for the detailed structure GET method test.


108-108: LGTM! Consistently added adapter information to the raw property.

The adapter property has been properly added to the raw object for the non-GET method with detailed structure test.

packages/client/src/adapters/standard/rpc-link-codec.test.ts (5)

138-138: LGTM! Consistently added adapter information to the raw property.

The adapter property has been properly added to the output decoding test case, which aligns with the standardization changes across the codebase.


160-160: LGTM! Consistently added adapter information to the raw property.

The adapter property has been properly added to the error decoding test case, following the same pattern as other changes.


176-176: LGTM! Consistently added adapter information to the raw property.

The adapter property has been correctly added to the test for error handling when parsing response body fails.


189-189: LGTM! Consistently added adapter information to the raw property.

The adapter property has been correctly added to the test for invalid RPC response format, maintaining consistency with other changes.


212-212: LGTM! Consistently added adapter information to the raw property.

The adapter property has been properly added to the test for invalid RPC error response format, completing the standardization of the raw property structure.

@unnoq unnoq merged commit 73a87c7 into main Mar 25, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant