Skip to content

feat(server): support chaining after .callable and .actionable#223

Merged
dinwwwh merged 2 commits into
mainfrom
feat/server/allow-chains-after-callable
Mar 11, 2025
Merged

feat(server): support chaining after .callable and .actionable#223
dinwwwh merged 2 commits into
mainfrom
feat/server/allow-chains-after-callable

Conversation

@dinwwwh
Copy link
Copy Markdown
Member

@dinwwwh dinwwwh commented Mar 11, 2025

Summary by CodeRabbit

  • Refactor

    • Enhanced procedure operations to return enriched objects with consistent properties and improved dynamic behavior.
    • Updated return types for callable and actionable methods to ensure they return specific procedure types.
  • Tests

    • Updated test validations to ensure that the procedure operations reliably expose all expected attributes.
    • Added assertions to confirm the presence of properties on the applied object in test cases.

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 11, 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 11, 2025 7:27am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 11, 2025

Walkthrough

The changes update the type expectations in tests and the implementation of the DecoratedProcedure and ImplementedProcedure classes. Tests now assert against DecoratedProcedure and ImplementedProcedure instead of the base Procedure, adding checks for properties such as name, length, use, route, and meta. Additionally, the callable and actionable methods of both classes have been modified to return their respective types, with the callable method in DecoratedProcedure now using a Proxy for dynamic property access.

Changes

File(s) Change Summary
packages/.../procedure-decorated.test-d.ts
packages/.../implementer-procedure.test-d.ts
Updated test cases to use DecoratedProcedure and ImplementedProcedure instead of Procedure. Adjusted type assertions for the applied variable in tests for .callable and .actionable methods.
packages/.../procedure-decorated.test.ts Added assertions to verify that applied objects have properties such as name, length, use, route, and meta, and confirmed that method calls return DecoratedProcedure instances.
packages/.../procedure-decorated.ts Updated callable and actionable methods to return DecoratedProcedure types. Replaced the use of Object.assign with a Proxy implementation that intercepts property access (via get and has traps) to enhance dynamic behavior.
packages/.../implementer-procedure.ts Updated callable and actionable methods to return ImplementedProcedure types, ensuring more precise type definitions.

Sequence Diagram(s)

sequenceDiagram
    participant Client as User/Caller
    participant DP as DecoratedProcedure
    participant Proxy as Dynamic Proxy

    Client->>DP: Invoke callable()
    DP->>Proxy: Return Proxy with get & has traps
    Client->>Proxy: Access property (e.g., route)
    Proxy->>DP: Check if property exists on instance (this)
    alt Property exists
        DP-->>Proxy: Return property value
    else
        Proxy-->>Client: Fallback to target property value
    end
Loading

Poem

I’m a bunny coding with delight,
Hopping through changes in the moonlight.
My tests now dance with types so true,
Proxy magic makes my dreams come through.
Carrots, code, and cheers—hip-hip-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 c76543d and 93d87aa.

📒 Files selected for processing (2)
  • packages/server/src/implementer-procedure.test-d.ts (2 hunks)
  • packages/server/src/implementer-procedure.ts (2 hunks)
🔇 Additional comments (4)
packages/server/src/implementer-procedure.test-d.ts (2)

148-158: Proper type preservation for method chaining with .callable()

The change from Procedure to ImplementedProcedure improves type safety by ensuring the returned type maintains all the methods and properties specific to ImplementedProcedure, not just the generic Procedure. This allows for proper method chaining after calling .callable().


166-176: Proper type preservation for method chaining with .actionable()

Similar to the .callable() change, updating the return type from Procedure to ImplementedProcedure ensures type preservation when chaining methods after calling .actionable(). This is a good improvement for type safety and developer experience.

packages/server/src/implementer-procedure.ts (2)

65-77: Return type enhancement enables method chaining with .callable()

Changing the return type from Procedure to ImplementedProcedure ensures that when chaining methods after calling .callable(), the returned object correctly preserves all the methods and properties of the more specific ImplementedProcedure interface. This change aligns with the PR objectives of supporting chaining after .callable.


82-94: Return type enhancement enables method chaining with .actionable()

Similar to the .callable() method, changing the return type to ImplementedProcedure for .actionable() enables proper method chaining while maintaining type safety. This change aligns with the PR objectives of supporting chaining after .actionable.

✨ 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 11, 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 11, 2025

Open in Stackblitz

More templates

@orpc/client

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

@orpc/contract

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

@orpc/openapi-client

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

@orpc/openapi

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

@orpc/react-query

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

@orpc/shared

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

@orpc/standard-server

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

@orpc/server

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

@orpc/standard-server-fetch

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

@orpc/standard-server-node

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

@orpc/vue-colada

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

@orpc/vue-query

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

@orpc/zod

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

commit: 93d87aa

Copy link
Copy Markdown

@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 (2)
packages/server/src/procedure-decorated.test.ts (2)

110-122: Good test coverage over function property interception
These assertions confirm that the returned function (.callable) properly intercepts property existence and retrieval through the Proxy, verifying that route, meta, etc. are accessible. You might also add a test scenario for potential naming collisions, so future property expansions in the procedure or the client do not inadvertently overshadow each other.


134-146: Test duplication for .actionable
The checks for .actionable mirror those for .callable. If these blocks become more intricate, consider extracting a shared test helper to keep your tests DRY and more maintainable.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 352022d and c76543d.

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

177-177: Align type expectations with updated DecoratedProcedure
Switching from Procedure to the more specific DecoratedProcedure type aligns the tests with the new return types and ensures correctness of chained method calls.

Also applies to: 195-195

packages/server/src/procedure-decorated.ts (2)

120-120: Proxy usage ensures dynamic property interception
Returning a Proxy object allows unified access to both the original DecoratedProcedure properties and the client’s function behavior, which is a flexible design. Keep an eye on potential naming collisions between the procedure instance and the procedure client in future expansions.

Also applies to: 122-129


147-147: Improved return type for .actionable
Including DecoratedProcedure<...> in the return type properly enables further chaining after invoking .actionable, matching the updated chaining logic.

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