-
-
Notifications
You must be signed in to change notification settings - Fork 77
feat(zod): promoteToSingletonArray #829
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(zod): promoteToSingletonArray #829
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Note Other AI code review bot(s) detectedCodeRabbit 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. WalkthroughA new option, Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15 minutes Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 theZodSmartCoercionPlugin
(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¶m=b
). - Improved Zod Integration: The internal
zodCoerceInternal
function (andthis.#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
-
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. ↩
There was a problem hiding this 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.
4a4ca4b
to
0bae0ab
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
More templates
@orpc/arktype
@orpc/client
@orpc/contract
@orpc/experimental-durable-event-iterator
@orpc/hey-api
@orpc/json-schema
@orpc/nest
@orpc/openapi
@orpc/openapi-client
@orpc/react
@orpc/react-query
@orpc/server
@orpc/shared
@orpc/solid-query
@orpc/standard-server
@orpc/standard-server-aws-lambda
@orpc/standard-server-fetch
@orpc/standard-server-node
@orpc/standard-server-peer
@orpc/svelte-query
@orpc/tanstack-query
@orpc/trpc
@orpc/valibot
@orpc/vue-colada
@orpc/vue-query
@orpc/zod
commit: |
Closing this PR due to inactivity |
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