Skip to content

fix(server)!: remove input type in client interceptors#309

Merged
dinwwwh merged 1 commit into
mainfrom
fix/server/not-type-input-CreateProcedureClientOptions
Mar 30, 2025
Merged

fix(server)!: remove input type in client interceptors#309
dinwwwh merged 1 commit into
mainfrom
fix/server/not-type-input-CreateProcedureClientOptions

Conversation

@dinwwwh
Copy link
Copy Markdown
Member

@dinwwwh dinwwwh commented Mar 30, 2025

Type input in interceptors is not safe since this input is not validated and may diff as expected type in remote call like server action envs

Summary by CodeRabbit

  • Refactor
    • Streamlined procedure action configurations by removing redundant input schema specifications.
    • Enhanced consistency and simplicity across client and server interactions, improving overall developer experience.

Type input in interceptors is not safe since this input is not validated and may diff as expected type in remote call like server action envs
@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 30, 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 30, 2025 2:12am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 30, 2025

Walkthrough

The changes remove the TInputSchema type parameter from various procedure client and router function signatures as well as related interfaces in both React and Server packages. This update affects functions such as createFormAction, createProcedureClient, and methods in ImplementedProcedure, DecoratedProcedure, and others. In addition, the StandardHandlerOptions and test type assertions have been updated to use a broader, less specific input type. Overall, the modifications simplify type definitions and remove redundant schema constraints.

Changes

File(s) Change Summary
packages/react/src/action-form.ts,
packages/server/src/implementer-procedure.ts,
packages/server/src/procedure-decorated.ts,
packages/server/src/procedure-utils.ts,
packages/server/src/router-client.ts
Removed TInputSchema from CreateProcedureClientOptions in function/method signatures to simplify type definitions for procedure and router clients.
packages/server/src/procedure-client.ts Updated ProcedureClientInterceptorOptions and CreateProcedureClientOptions interfaces by removing the TInputSchema parameter and changing the inferred input type to unknown within interceptor options; adjusted createProcedureClient function signature accordingly.
packages/server/src/adapters/standard/handler.ts Modified the clientInterceptors property type by removing the AnySchema type parameter from ProcedureClientInterceptorOptions within the StandardHandlerOptions interface.
packages/server/src/procedure-client.test-d.ts Changed the type assertion for the interceptor's input parameter from an object with a numeric property to unknown.

Possibly related PRs

  • unnoq/orpc#290: Adjustments similar to this PR were made by removing TInputSchema in the StandardHandlerOptions and related interceptor types.
  • unnoq/orpc#223: This PR also modified the callable and actionable methods in the DecoratedProcedure class by removing the TInputSchema parameter.
  • unnoq/orpc#218: Focused on input schema handling improvements, complementing the changes made here by restructuring type definitions in procedure clients.

Poem

In the meadow of type code, I hop along with glee,
Removing extra schema tags so simple and free.
No TInputSchema to slow my pace,
Just clear, clean types in every case.
My carrot-fueled heart sings a simplified tune,
Bounding through code under a happy full moon.
🥕🐰 CodeRabbit cheers the streamlined boon!


📜 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 9486ab5 and 6a9d483.

📒 Files selected for processing (8)
  • packages/react/src/action-form.ts (0 hunks)
  • packages/server/src/adapters/standard/handler.ts (1 hunks)
  • packages/server/src/implementer-procedure.ts (0 hunks)
  • packages/server/src/procedure-client.test-d.ts (1 hunks)
  • packages/server/src/procedure-client.ts (2 hunks)
  • packages/server/src/procedure-decorated.ts (0 hunks)
  • packages/server/src/procedure-utils.ts (0 hunks)
  • packages/server/src/router-client.ts (0 hunks)
💤 Files with no reviewable changes (5)
  • packages/react/src/action-form.ts
  • packages/server/src/router-client.ts
  • packages/server/src/procedure-utils.ts
  • packages/server/src/procedure-decorated.ts
  • packages/server/src/implementer-procedure.ts
🧰 Additional context used
🧬 Code Definitions (1)
packages/server/src/procedure-client.test-d.ts (2)
packages/server/src/builder.ts (1)
  • input (186-194)
packages/contract/src/builder.ts (1)
  • input (90-97)
🔇 Additional comments (5)
packages/server/src/procedure-client.test-d.ts (1)

99-99: Updated type assertion to match new input type.

The assertion now correctly expects the input parameter to be of type unknown instead of a specific schema type, aligning with the changes to the ProcedureClientInterceptorOptions interface.

packages/server/src/adapters/standard/handler.ts (1)

46-46: Removed input schema type parameter from ProcedureClientInterceptorOptions.

The clientInterceptors property type has been updated to remove the AnySchema type parameter from ProcedureClientInterceptorOptions, which aligns with the core changes in the procedure client implementation. This improves safety by not assuming the input is validated against a specific schema.

packages/server/src/procedure-client.ts (3)

32-32: Changed input type from schema-based to unknown.

The input property in ProcedureClientInterceptorOptions is now typed as unknown instead of a schema-derived type. This change addresses the safety issue mentioned in the PR description, as it no longer assumes the input conforms to a specific schema.


57-57: Removed input schema type parameter from interceptors configuration.

Removed the TInputSchema type parameter from the ProcedureClientInterceptorOptions used in the interceptors property. This is consistent with the changes to the interface definition and reinforces the safety improvement by not assuming specific input types.


99-101:

Details

❓ Verification inconclusive

Verify the safety of the type casting.

The code is still casting input to InferSchemaInput<TInputSchema> when passing it to the interceptors, even though the interceptor type now expects unknown.

input: input as InferSchemaInput<TInputSchema>, // input only optional when it undefinable so we can safely cast it

This cast might be unnecessary since the receiving type is now unknown. Consider removing the cast for consistency with the type changes.


🏁 Script executed:

#!/bin/bash
# Check how input is used in interceptors and if the cast is necessary

# Find all usages of interceptors with input
rg --type typescript "interceptors.*input" -A 5 -B 5

Length of output: 89


Attention: Manual Verification Required for Input Casting

The current code in
packages/server/src/procedure-client.ts (lines 99–101)
still applies the cast:

input: input as InferSchemaInput<TInputSchema>, // input only optional when it undefinable so we can safely cast it

Even though interceptors now expect an input of type unknown, which implies that the explicit cast might be unnecessary.

Recommendations:

  • Verify that the interceptor implementations indeed handle the input as unknown. Manual inspection is needed because previous automated searches didn’t return conclusive context.
  • If confirmed safe, remove the cast to maintain consistency with the updated interceptor type signature and avoid redundant type assertions.
  • Double-check downstream usage: Ensure that eliminating the cast does not break any assumptions or type expectations in the subsequent logic.
✨ 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.

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 30, 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 30, 2025

Open in Stackblitz

More templates

@orpc/arktype

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

@orpc/client

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

@orpc/contract

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

@orpc/openapi

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

@orpc/openapi-client

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

@orpc/react-query

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

@orpc/react

npm i https://pkg.pr.new/@orpc/react@309

@orpc/server

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

@orpc/shared

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

@orpc/solid-query

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

@orpc/standard-server

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

@orpc/standard-server-fetch

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

@orpc/standard-server-node

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

@orpc/svelte-query

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

@orpc/valibot

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

@orpc/vue-colada

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

@orpc/vue-query

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

@orpc/zod

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

commit: 6a9d483

@dinwwwh dinwwwh merged commit 783ae4e into main Mar 30, 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