Skip to content

Conversation

timvandam
Copy link

@timvandam timvandam commented Aug 4, 2025

https://discord.com/channels/1308966753044398161/1401992321737949224/1401992321737949224

An option that will make it easy to convert ?fields=1 into { fields: [1] } rather than { fields: 1 }

Summary by CodeRabbit

  • New Features
    • Added an option to automatically convert single values into singleton arrays when an array is expected, enhancing flexibility for array coercion.
    • Introduced new configuration options to control this behavior in relevant plugins.

Copy link

vercel bot commented Aug 4, 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 Aug 4, 2025 8:48pm

Copy link

coderabbitai bot commented Aug 4, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

A new option, promoteToSingletonArray, was introduced to the smart coercion plugins in both the main and experimental Zod coercer modules. This allows scalar values to be coerced into singleton arrays when the schema expects an array. Constructors and internal logic were updated to support and propagate this option.

Changes

Cohort / File(s) Change Summary
Main Zod Coercer Plugin Enhancements
packages/zod/src/coercer.ts
Added ZodSmartCoercionPluginOptions interface with promoteToSingletonArray. Updated plugin and internal coercion logic to optionally wrap scalars as singleton arrays for array schemas.
Experimental Zod4 Coercer Plugin Enhancements
packages/zod/src/zod4/coercer.ts
Added experimental_ZodSmartCoercionPluginOptions interface with promoteToSingletonArray. Updated plugin constructor and coercion logic to support singleton array promotion for array schemas.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ZodSmartCoercionPlugin
    participant zodCoerceInternal
    participant Schema

    User->>ZodSmartCoercionPlugin: new ZodSmartCoercionPlugin({ promoteToSingletonArray: true })
    User->>ZodSmartCoercionPlugin: coerce(schema, value)
    ZodSmartCoercionPlugin->>zodCoerceInternal: coerce(schema, value, options)
    zodCoerceInternal->>Schema: check if schema is array
    alt promoteToSingletonArray enabled & value not array
        zodCoerceInternal->>zodCoerceInternal: wrap value in [value]
    else value is array or promotion disabled
        zodCoerceInternal->>zodCoerceInternal: proceed as usual
    end
    zodCoerceInternal-->>ZodSmartCoercionPlugin: coerced value
    ZodSmartCoercionPlugin-->>User: result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Poem

🐇
With a hop and a twist, arrays now bloom,
Singletons promoted, no more gloom!
Coercion’s smarter, options in tow,
Scalars to arrays, just say so.
Zod plugins enhanced, the code’s in array—
Reviewers, rejoice, for clarity’s in play!
🌱✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 aad4149 and 0bae0ab.

📒 Files selected for processing (2)
  • packages/zod/src/coercer.ts (4 hunks)
  • packages/zod/src/zod4/coercer.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/zod/src/zod4/coercer.ts
  • packages/zod/src/coercer.ts
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • Explain this complex logic.
    • 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 explain this code block.
  • 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 explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests 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.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 4, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @timvandam, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the Zod Smart Coercion Plugin by adding a new configuration option. This option enables the plugin to automatically convert single input values into singleton arrays when the corresponding Zod schema expects an array, thereby streamlining data parsing for common scenarios like query parameters.

Highlights

  • New Feature: Singleton Array Promotion: Introduced a promoteToSingletonArray option to the ZodSmartCoercionPlugin (and its experimental Zod v4 counterpart). This option allows the plugin to automatically wrap a single input value into a singleton array if the target Zod schema expects an array.
  • Configurable Coercion Behavior: The new option provides more flexible data parsing, particularly useful for handling query string parameters where a single value might be provided for a field that expects an array (e.g., ?param=a instead of ?param=a&param=b).
  • Improved Zod Integration: The internal zodCoerceInternal function (and this.#coerce in the experimental v4 plugin) now accepts and utilizes these new options to modify coercion behavior specifically for array types.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the promoteToSingletonArray option to ZodSmartCoercionPlugin, enabling automatic wrapping of single values into arrays, useful for query parameters. The implementation covers both Zod v3 and v4.

I've identified potential breaking changes in the constructors and a bug in the promoteToSingletonArray logic where the element itself is not coerced. I've provided suggestions to address these issues.

Copy link

codecov bot commented Aug 5, 2025

Codecov Report

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/zod/src/coercer.ts 85.71% 1 Missing ⚠️
packages/zod/src/zod4/coercer.ts 80.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link

pkg-pr-new bot commented Aug 5, 2025

More templates

@orpc/arktype

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

@orpc/client

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

@orpc/contract

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

@orpc/experimental-durable-event-iterator

npm i https://pkg.pr.new/@orpc/experimental-durable-event-iterator@829

@orpc/hey-api

npm i https://pkg.pr.new/@orpc/hey-api@829

@orpc/json-schema

npm i https://pkg.pr.new/@orpc/json-schema@829

@orpc/nest

npm i https://pkg.pr.new/@orpc/nest@829

@orpc/openapi

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

@orpc/openapi-client

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

@orpc/react

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

@orpc/react-query

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

@orpc/server

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

@orpc/shared

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

@orpc/solid-query

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

@orpc/standard-server

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

@orpc/standard-server-aws-lambda

npm i https://pkg.pr.new/@orpc/standard-server-aws-lambda@829

@orpc/standard-server-fetch

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

@orpc/standard-server-node

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

@orpc/standard-server-peer

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

@orpc/svelte-query

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

@orpc/tanstack-query

npm i https://pkg.pr.new/@orpc/tanstack-query@829

@orpc/trpc

npm i https://pkg.pr.new/@orpc/trpc@829

@orpc/valibot

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

@orpc/vue-colada

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

@orpc/vue-query

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

@orpc/zod

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

commit: 0bae0ab

@unnoq
Copy link
Owner

unnoq commented Sep 14, 2025

Closing this PR due to inactivity

@unnoq unnoq closed this Sep 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants