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(client, server): throw if plugin context is missing #291

Merged
merged 1 commit into from
Mar 25, 2025

Conversation

unnoq
Copy link
Owner

@unnoq unnoq commented Mar 25, 2025

Summary by CodeRabbit

  • Refactor
    • Client Plugin: Streamlined the retry plugin interface for easier integration.
    • Server Plugins: Simplified and unified configuration options for the CORS and response headers plugins, enhancing consistency for setup and use.

Copy link

vercel bot commented Mar 25, 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 25, 2025 2:50am

Copy link

coderabbitai bot commented Mar 25, 2025

Walkthrough

The pull request simplifies generic type constraints in three plugin files. In the client plugin, the ClientContext type is removed from the ClientRetryPlugin generic parameters and its import is deleted. In the server plugins, the generic type parameters are renamed and simplified—from using TContext to using T—with corresponding updates to constructor and method signatures. These changes affect only the type definitions while keeping the overall functionality unchanged.

Changes

File(s) Change Summary
packages/client/src/plugins/retry.ts Removed ClientContext from ClientRetryPlugin's generic constraints and eliminated its import.
packages/server/src/plugins/cors.ts, packages/server/src/plugins/response-headers.ts Renamed generic type parameters (from TContext to T), simplified type constraints, and updated constructor/method signatures.

Possibly related PRs

Poem

In a field of code so neat,
I hop with glee on tiny feet.
Type constraints trimmed to set things right,
Clean and simple—what a sight!
Hop along and code into the night!
🐇

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 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 plan to trigger planning for file edits and PR creation.
  • @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

codecov bot commented Mar 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

Copy link

pkg-pr-new bot commented Mar 25, 2025

Open in Stackblitz

More templates

@orpc/arktype

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

@orpc/client

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

@orpc/openapi

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

@orpc/openapi-client

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

@orpc/contract

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

@orpc/react-query

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

@orpc/server

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

@orpc/shared

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

@orpc/solid-query

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

@orpc/standard-server

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

@orpc/standard-server-fetch

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

@orpc/standard-server-node

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

@orpc/svelte-query

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

@orpc/valibot

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

@orpc/vue-colada

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

@orpc/vue-query

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

@orpc/zod

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

commit: 8b19de7

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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 73a87c7 and 8b19de7.

📒 Files selected for processing (3)
  • packages/client/src/plugins/retry.ts (2 hunks)
  • packages/server/src/plugins/cors.ts (2 hunks)
  • packages/server/src/plugins/response-headers.ts (1 hunks)
🧰 Additional context used
🧬 Code Definitions (3)
packages/client/src/plugins/retry.ts (1)
packages/client/src/plugins/base.ts (1)
  • ClientPlugin (4-6)
packages/server/src/plugins/response-headers.ts (2)
packages/server/src/plugins/base.ts (1)
  • HandlerPlugin (4-6)
packages/server/src/adapters/standard/handler.ts (1)
  • StandardHandlerOptions (24-46)
packages/server/src/plugins/cors.ts (2)
packages/server/src/adapters/standard/handler.ts (2)
  • StandardHandlerInterceptorOptions (20-22)
  • StandardHandlerOptions (24-46)
packages/server/src/plugins/base.ts (1)
  • HandlerPlugin (4-6)
🔇 Additional comments (2)
packages/client/src/plugins/retry.ts (1)

3-3:

❓ Verification inconclusive

Import removed but potentially needed for ClientPlugin compatibility.

The import for ClientContext has been removed, but this might be problematic since:

  1. The ClientPlugin interface requires type T extends ClientContext
  2. Without explicitly extending ClientContext, the plugin might not be compatible with its base interface

🏁 Script executed:

#!/bin/bash
# Verify if ClientRetryPluginContext extends ClientContext which would validate this change

echo "Checking if ClientRetryPluginContext extends ClientContext..."
rg -A 3 "interface\s+ClientRetryPluginContext\s+extends\s+ClientContext" packages/client/src/

# Also check the ClientPlugin interface definition to confirm the requirement
echo "Checking ClientPlugin interface definition..."
rg -A 3 "interface\s+ClientPlugin" packages/client/src/plugins/base.ts

Length of output: 509


Action Required: Verify Compatibility of Plugin Context

The ClientPlugin interface (see packages/client/src/plugins/base.ts) requires its generic type to extend ClientContext. In packages/client/src/plugins/retry.ts, the only imported type is ClientOptionsOut, and the explicit import for ClientContext has been removed. However, our verification did not find any declaration showing that the retry plugin’s context (e.g. a potential ClientRetryPluginContext or ClientOptionsOut) explicitly extends ClientContext.

Please verify that:

  • The type passed to ClientPlugin (likely ClientOptionsOut) either directly extends or is compatible with ClientContext.
  • If it does not, the ClientContext import should be reintroduced and the context type adjusted accordingly to ensure compatibility with the base ClientPlugin interface.
packages/server/src/plugins/cors.ts (1)

7-9: Generic type parameter renamed for consistency.

The generic type parameter has been renamed from TContext to T throughout the file while maintaining the same type constraint extends Context. This change improves naming consistency across plugins while preserving type safety.

Also applies to: 17-21, 32-32

Comment on lines +8 to +9
export class ResponseHeadersPlugin<T extends ResponseHeadersPluginContext> implements HandlerPlugin<T> {
init(options: StandardHandlerOptions<T>): void {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Type constraint is simplified but may have compatibility concerns.

The generic type parameter has been renamed from TContext to T and the type constraint has been simplified to only extend ResponseHeadersPluginContext instead of both ResponseHeadersPluginContext & Context. This change might cause type incompatibility since:

  1. HandlerPlugin<T> (which this class implements) requires T extends Context according to the base interface in plugins/base.ts
  2. StandardHandlerOptions<T> in the init method requires T extends Context

🏁 Script executed:

#!/bin/bash
# Check if ResponseHeadersPluginContext extends Context to verify if the simplified type constraint is sufficient

# First, search if ResponseHeadersPluginContext extends Context directly
echo "Checking if ResponseHeadersPluginContext extends Context directly..."
rg -A 3 "interface\s+ResponseHeadersPluginContext\s+extends\s+Context" packages/server/src/

# Check if ResponseHeadersPluginContext is potentially part of a type hierarchy that extends Context
echo "Checking type hierarchy..."
rg -A 5 "ResponseHeadersPluginContext" packages/server/src/

Length of output: 2428


Let's further verify whether the base interface imposes a T extends Context constraint. We'll search for "interface HandlerPlugin" in the repository to see the actual declaration.

Once we confirm that, we can finalize our response.


🏁 Script executed:

#!/bin/bash
rg -A 3 "interface\s+HandlerPlugin<" -n .

Length of output: 322


Action Required: Resolve Generic Type Compatibility Issue

The current change restricts T to extend ResponseHeadersPluginContext, but the base interface (HandlerPlugin<TContext extends Context>) and StandardHandlerOptions<T> require T to extend Context. Since ResponseHeadersPluginContext does not extend Context, this simplified constraint may lead to type incompatibility. Consider one of the following fixes:

  • Update ResponseHeadersPluginContext to extend Context (e.g., export interface ResponseHeadersPluginContext extends Context { ... }), or
  • Revise the generic constraint in ResponseHeadersPlugin to enforce both requirements (e.g., change the declaration to T extends ResponseHeadersPluginContext & Context).

Addressing this will ensure that implementations correctly satisfy all expected type constraints across the codebase.

@@ -62,7 +62,7 @@ export interface ClientRetryPluginOptions {
default?: ClientRetryPluginContext
}

export class ClientRetryPlugin<T extends ClientContext & ClientRetryPluginContext> implements ClientPlugin<T> {
export class ClientRetryPlugin<T extends ClientRetryPluginContext> implements ClientPlugin<T> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Type constraint is simplified but may break interface compatibility.

The type constraint has been simplified from T extends ClientContext & ClientRetryPluginContext to just T extends ClientRetryPluginContext. This could cause compatibility issues because:

  1. ClientPlugin<T> (which this class implements) requires T extends ClientContext
  2. Without the ClientContext constraint, the type system might not enforce required properties expected by the core client code

Consider maintaining the ClientContext constraint or ensure that ClientRetryPluginContext extends ClientContext:

-export class ClientRetryPlugin<T extends ClientRetryPluginContext> implements ClientPlugin<T> {
+export class ClientRetryPlugin<T extends ClientContext & ClientRetryPluginContext> implements ClientPlugin<T> {

Alternative solution if ClientRetryPluginContext should extend ClientContext:

export interface ClientRetryPluginContext extends ClientContext {
  // existing properties...
}

@unnoq unnoq merged commit 62795ca 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