Skip to content

feat(server): unlazyRouter utility#219

Merged
dinwwwh merged 1 commit intomainfrom
feat/testing
Mar 10, 2025
Merged

feat(server): unlazyRouter utility#219
dinwwwh merged 1 commit intomainfrom
feat/testing

Conversation

@dinwwwh
Copy link
Copy Markdown
Member

@dinwwwh dinwwwh commented Mar 10, 2025

Summary by CodeRabbit

  • New Features

    • Introduced an enhanced router processing capability that converts deferred configurations into fully accessible structures for streamlined routing.
  • Tests

    • Expanded test coverage to ensure functional correctness and type consistency of the updated routing mechanism.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 10, 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 10, 2025 1:53pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 10, 2025

Walkthrough

The changes extend the functionality and testing of the router utilities by introducing a new type alias UnlaziedRouter and an asynchronous function unlazyRouter. Both production and test files have been updated. In the tests, new cases verify that the router is correctly unwrapped and the type structure is maintained. Import statements have been refined to explicitly import the necessary types and functions.

Changes

File(s) Summary
packages/.../router-utils.test-d.ts
packages/.../router-utils.test.ts
Added test cases to validate the new UnlaziedRouter type and verify that unlazyRouter returns the correct unwrapped router structure. Import statements were modified for greater clarity.
packages/.../router-utils.ts Introduced the UnlaziedRouter type alias and an async unlazyRouter function that recursively unwraps lazy routers. The implementation includes a check via isProcedure and iterative unwrapping of nested router items.

Sequence Diagram(s)

sequenceDiagram
    participant T as Test
    participant UR as unlazyRouter
    participant IP as isProcedure
    participant UL as unlazy

    T->>UR: call unlazyRouter(router)
    UR->>IP: "Is this a procedure?"
    alt Procedure condition true
        IP-->>UR: true
        UR-->>T: return router directly
    else Not a procedure
        loop For each key in router
            UR->>UL: await unlazy(router[key])
            UR->>UR: recursively call unlazyRouter(router[key])
        end
        UR-->>T: return fully unwrapped router object
    end
Loading

Poem

I'm a rabbit hopping through new code lanes,
Unwrapping lazy routes with joyful gains.
Types and tests aligned in a playful art,
Each function beats like a thumping heart.
CodeRabbit cheers in every line — a joyful start!
🐇💻 Hop, hop, hooray!

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

 ERR_PNPM_OPTIONAL_DEPS_REQUIRE_PROD_DEPS  Optional dependencies cannot be installed without production dependencies


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1d3318c and 7f32043.

📒 Files selected for processing (3)
  • packages/server/src/router-utils.test-d.ts (2 hunks)
  • packages/server/src/router-utils.test.ts (2 hunks)
  • packages/server/src/router-utils.ts (1 hunks)
🔇 Additional comments (6)
packages/server/src/router-utils.ts (2)

227-233: Great type definition for UnlaziedRouter!

The recursive conditional type is well-structured and properly handles both the base case (when the router is a procedure) and the recursive case (for nested routers).


234-250: Well-implemented unlazyRouter function.

The implementation correctly mirrors the type definition, with proper handling of the base case and recursion through nested router properties. The function robustly handles the asynchronous nature of unlazying routers.

packages/server/src/router-utils.test.ts (2)

5-5: Correctly updated import statement.

The import now includes the new unlazyRouter function.


192-203: Good test for unlazyRouter functionality.

The test effectively verifies that unlazyRouter correctly unwraps the lazy router structure, preserving the expected shape with ping, pong, and nested properties.

packages/server/src/router-utils.test-d.ts (2)

3-8: Good organization of imports.

The imports have been properly structured to separate type imports from value imports, making the code more maintainable.


75-86: Well-structured type test for UnlaziedRouter.

The test properly validates that the UnlaziedRouter type correctly transforms the input router type into the expected structure with all nested properties.

✨ 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.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 10, 2025

Open in Stackblitz

More templates

@orpc/client

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

@orpc/contract

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

@orpc/openapi-client

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

@orpc/react-query

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

@orpc/openapi

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

@orpc/server

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

@orpc/shared

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

@orpc/standard-server

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

@orpc/standard-server-fetch

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

@orpc/standard-server-node

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

@orpc/vue-colada

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

@orpc/vue-query

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

@orpc/zod

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

commit: 7f32043

@dinwwwh dinwwwh merged commit 6c5bfe4 into main Mar 10, 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