Skip to content

feat!: update onFinish state#332

Merged
dinwwwh merged 3 commits intomainfrom
feat/upate-onFinish-state
Apr 5, 2025
Merged

feat!: update onFinish state#332
dinwwwh merged 3 commits intomainfrom
feat/upate-onFinish-state

Conversation

@dinwwwh
Copy link
Copy Markdown
Member

@dinwwwh dinwwwh commented Apr 5, 2025

Summary by CodeRabbit

  • Refactor
    • Enhanced clarity in the management of operation outcomes, providing more explicit error and success indications.
  • Tests
    • Modified test cases to align with the updated outcome handling, ensuring accurate validation of results.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 5, 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 Apr 5, 2025 9:40am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 5, 2025

Walkthrough

This pull request refactors the state handling logic in the onFinish function. Both the test file and the implementation are updated to use a destructured array format [error, data, isSuccess] instead of a union tuple. The changes include redefined type definitions and updated validations based on the success state. No alterations were made to exported or public entities.

Changes

File(s) Summary
packages/shared/src/interceptor.test-d.ts Updated test functions to destructure the state into error, data, and isSuccess and apply conditional type assertions.
packages/shared/src/interceptor.ts Modified OnFinishState type and updated the onFinish function to assign state as [null, result, true] for success and [error, undefined, false] for errors.
packages/shared/src/interceptor.test.ts Changed arguments in test cases for onFinishFn to reflect the new state format, modifying the order and values of the parameters.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant onFinish
    Caller->>onFinish: Invoke onFinish(result or error)
    alt Operation Successful
        onFinish-->>Caller: Return [null, result, true]
    else Operation Failed
        onFinish-->>Caller: Return [error, undefined, false]
    end
Loading

Possibly related PRs

  • unnoq/orpc#331: Updates in that PR also modify the onFinish function's state handling and type definitions, directly relating to these changes.

Poem

In my burrow, I hop with glee,
Seeing cleaner code as far as I can see.
State now splits with error and success so clear,
Tests and functions now cheer, oh dear!
With each new change, I dance on my feet—
Coding carrots make this journey sweet! 🐰


📜 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 41d89a0 and 5278711.

📒 Files selected for processing (2)
  • packages/shared/src/interceptor.test-d.ts (2 hunks)
  • packages/shared/src/interceptor.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/shared/src/interceptor.test-d.ts
🔇 Additional comments (4)
packages/shared/src/interceptor.ts (4)

66-68: Improved type definition with better semantics

The updated OnFinishState type definition is now more self-documenting with named tuple elements and uses boolean flags instead of string literals. This makes the API more intuitive and easier to work with when destructuring the returned state.

Note that this is a breaking change that will require updates in any code that consumes this type.


88-88: State assignment updated to match new type structure

The success state assignment now correctly follows the new type definition pattern with error as the first element (null), data as the second element, and a boolean success flag (true) as the third element.


92-92: Error state assignment updated to match new type structure

The error state assignment now correctly follows the new type definition pattern with the error object as the first element, undefined data as the second element, and a boolean success flag (false) as the third element.


83-98:

Details

✅ Verification successful

Verify that all consumers of the onFinish API are updated

This change introduces a breaking change in the structure and meaning of the state tuple. Ensure that all consumers of this API are updated to work with the new structure.


🏁 Script executed:

#!/bin/bash
# Look for code that uses onFinish function or references OnFinishState
echo "Searching for potential consumers of onFinish API..."
rg -g '*.ts' -g '*.tsx' --type-add 'test:*.test.{ts,tsx}' --type-add 'testd:*.test-d.{ts,tsx}' -t ts -t tsx 'onFinish|OnFinishState' --files-with-matches

Length of output: 298


I'll generate a new verification script that explicitly registers the TSX file type to avoid the error. Please run this script to verify if there are any consumers of the onFinish API:


🏁 Script executed:

#!/bin/bash
echo "Searching for potential consumers of onFinish API with corrected TSX file type handling..."
rg --type-add 'tsx:*.tsx' -g '*.ts' -g '*.tsx' 'onFinish|OnFinishState'

Length of output: 2089


Action: Confirm Consistent Usage of Updated onFinish API

The updated implementation now returns a three-element tuple—[error, result, isSuccess]—as shown below:

  let state: any

  return async (options, ...rest) => {
    try {
      const result = await options.next()
      state = [null, result, true]
      return result
    }
    catch (error) {
      state = [error, undefined, false]
      throw error
    }
    finally {
      await callback(state, options, ...rest)
    }
  }

Our recent search confirms that references to the onFinish API include:

  • Re-exports in both packages/server/src/index.ts and packages/client/src/index.ts
  • Type and function definitions within packages/shared/src/interceptor.ts
  • Consumer validations in test suites (packages/shared/src/interceptor.test.ts and packages/shared/src/interceptor.test-d.ts), where the updated tuple is properly destructured.

Please review all downstream consumers (especially any external or non-tested usages) to ensure they correctly handle the new tuple structure.

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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 5, 2025

More templates

@orpc/arktype

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

@orpc/client

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

@orpc/openapi

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

@orpc/openapi-client

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

@orpc/contract

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

@orpc/react

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

@orpc/react-query

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

@orpc/server

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

@orpc/shared

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

@orpc/solid-query

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

@orpc/standard-server

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

@orpc/standard-server-fetch

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

@orpc/standard-server-node

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

@orpc/svelte-query

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

@orpc/valibot

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

@orpc/vue-colada

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

@orpc/vue-query

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

@orpc/zod

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

commit: 5278711

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@dinwwwh dinwwwh merged commit aa59d19 into main Apr 5, 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