Skip to content

feat(client, server)!: improve RPC JSON Serializer Meta#242

Merged
dinwwwh merged 3 commits intomainfrom
feat/client-server/improve-rpc-json-serializer-structure
Mar 14, 2025
Merged

feat(client, server)!: improve RPC JSON Serializer Meta#242
dinwwwh merged 3 commits intomainfrom
feat/client-server/improve-rpc-json-serializer-structure

Conversation

@dinwwwh
Copy link
Copy Markdown
Member

@dinwwwh dinwwwh commented Mar 14, 2025

From [type: number, path: (string | number)[]] to [type: number, ...path: (string | number)[]] it can reduce size a bit

Summary by CodeRabbit

  • Documentation

    • Updated advanced RPC protocol documentation to clarify metadata examples.
  • Refactor

    • Improved metadata handling in the RPC serialization and deserialization processes for greater consistency and flexibility.
  • Tests

    • Revised validations for error responses and key generation to align with the updated metadata structure.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 14, 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 14, 2025 2:15pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 14, 2025

Walkthrough

The changes update the representation of the meta field in both documentation and code. The document now shows a simplified, string-based format and clarifies the accepted structure using spread operators. In the serializer, type definitions and method signatures are revised to use a new tuple format for metadata while the serialization and deserialization logic is adjusted accordingly. Test cases have been updated to verify the new expected structures. No new public entities or functionality are introduced.

Changes

File(s) Change Summary
apps/content/docs/.../rpc-protocol.md Updated documentation to simplify the meta field format from a nested array to a string representation and clarified its structure using a spread operator.
packages/client/src/adapters/standard/rpc-json-serializer.ts Introduced a new readonly tuple type (StandardRPCJsonSerializedMetaItem) replacing the old array type; updated type aliases and method signatures for serialization and deserialization to correctly handle spread segments.
packages/client/src/adapters/standard/rpc-link-codec.test.ts, packages/vue-colada/src/key.test.ts Modified test cases to adjust the expected meta values; changed error response structure in one test and adjusted the expected output format of the buildKey function in another.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant S as RPC Serializer
    C->>S: serialize(data, meta)
    S->>S: Build meta as tuple [type, ...segments]
    S->>C: Return serialized payload
    C->>S: deserialize(payload)
    S->>S: Process meta with updated tuple structure
    S->>C: Return reconstructed data
Loading

Possibly related PRs

  • unnoq/orpc#186: Addresses similar changes to the rpc-json-serializer.ts file by modifying the meta structure in the serialization process.
  • unnoq/orpc#241: Focuses on enhancing the serialization/deserialization mechanisms for the meta field, aligning with the updates made in this PR.

Poem

I hopped through lines of code so bright,
Tweaking meta fields with all my might.
From nested arrays to clean tuple arrays,
My bunny paws left joyous traces.
With every change, the code leaps free—
A rabbit’s delight in clarity! 🐇💻

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 32f3296 and fcbdde8.

📒 Files selected for processing (4)
  • apps/content/docs/advanced/rpc-protocol.md (5 hunks)
  • packages/client/src/adapters/standard/rpc-json-serializer.ts (6 hunks)
  • packages/client/src/adapters/standard/rpc-link-codec.test.ts (1 hunks)
  • packages/vue-colada/src/key.test.ts (1 hunks)
🔇 Additional comments (12)
packages/vue-colada/src/key.test.ts (1)

13-13: LGTM - Meta field structure update is correct

The test's expected output now correctly uses the new meta field format: meta:[[1,"a"]] instead of a nested array structure, which aligns with the PR objective of simplifying the RPC JSON Serializer Meta representation.

apps/content/docs/advanced/rpc-protocol.md (5)

42-43: LGTM - Documentation updated to reflect new meta format

The example now correctly shows the simplified meta field structure with direct values rather than nested arrays.


62-63: LGTM - Documentation updated consistently

The request body example now correctly uses the new meta format.


81-82: LGTM - FormData example updated

The FormData example has been updated to use the new meta format consistently.


110-111: LGTM - Success response example updated

The success response example now correctly uses the new meta format.


142-142: LGTM - Clear documentation of new format

The meta field description accurately explains the new format using spread syntax: [type: number, ...path: (string | number)[]].

packages/client/src/adapters/standard/rpc-link-codec.test.ts (1)

167-168: LGTM - Test case for invalid format updated

The test for invalid RPC response format now correctly uses a numeric value (123) for the meta field to test validation, which is appropriate for the new meta field structure expectations.

Also applies to: 171-171

packages/client/src/adapters/standard/rpc-json-serializer.ts (5)

14-15: LGTM - New type definitions are well structured

The new type definitions effectively implement the PR's goal:

  1. StandardRPCJsonSerializedMetaItem now uses a rest parameter for path segments
  2. This flattens the structure and reduces serialized data size
  3. Using readonly enhances type safety

The type changes align perfectly with the PR objective to optimize the meta representation.


39-40: LGTM - Serialize method signature and implementation updated

The serialize method correctly uses the new type definition and updates how custom serializer metadata is added to match the flattened structure.

Also applies to: 44-46


57-59: LGTM - All type serializations updated consistently

All data type serializations (bigint, Date, NaN, URL, RegExp, Set, Map, and undefined array elements) have been consistently updated to use the spread syntax for segments, ensuring a uniform implementation across the entire codebase.

Also applies to: 62-69, 72-74, 77-79, 82-84, 88-90, 94-96, 101-103


124-127: LGTM - Method overload signatures updated

The deserialize method's overload signatures properly reflect the new type structure, including the addition of readonly modifiers for improved type safety.


144-154: LGTM - Deserialization logic updated correctly

The deserialization logic has been effectively updated to:

  1. Extract the type from the first element of each meta item
  2. Loop through the remaining elements (starting from index 1) to traverse the path
  3. Properly update the reference and segment variables

This implementation correctly handles the flattened meta structure.

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

@dinwwwh dinwwwh changed the title feat(client, server): improve RPC JSON Serializer Meta feat(client, server)!: improve RPC JSON Serializer Meta Mar 14, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 14, 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 14, 2025

Open in Stackblitz

More templates

@orpc/client

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

@orpc/contract

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

@orpc/openapi

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

@orpc/openapi-client

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

@orpc/react-query

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

@orpc/server

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

@orpc/shared

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

@orpc/solid-query

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

@orpc/standard-server-fetch

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

@orpc/standard-server

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

@orpc/standard-server-node

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

@orpc/svelte-query

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

@orpc/vue-colada

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

@orpc/vue-query

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

@orpc/zod

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

commit: fcbdde8

@dinwwwh dinwwwh merged commit 924a598 into main Mar 14, 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