-
-
Notifications
You must be signed in to change notification settings - Fork 262
feat: add or
migration
#1261
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: add or
migration
#1261
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
Pull Request Overview
This PR adds support for migrating Zod's .or()
method to Valibot's equivalent union()
function. Previously, the codemod would produce invalid code when encountering .or()
calls, resulting in runtime errors.
- Added transformation logic to convert Zod's
.or()
method calls to Valibot'sunion()
function - Integrated the new transformation into the existing codemod infrastructure
- Added test coverage for the new functionality
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
schemas-and-links.ts |
Added import and case handling for the new transformOr function |
or/or.ts |
Implemented the core transformation logic to convert .or() to union() |
or/index.ts |
Added export for the new or module |
methods/index.ts |
Added export to include the or transformation in the main methods export |
constants.ts |
Added 'or' to the list of supported Zod methods |
test-setup.test.ts |
Added 'or' to the test suite |
__testfixtures__/or/input.ts |
Test input file showing Zod .or() usage |
__testfixtures__/or/output.ts |
Expected output showing Valibot union() conversion |
@@ -0,0 +1,3 @@ | |||
import * as v from "valibot"; | |||
|
|||
const Schema1 = v.union(v.string(), v.number()); |
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.
The array is missing: v.union([v.string(), v.number()])
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.
Dang...should've actually tested the code and not just rely on me remembering 😄
commit: |
@@ -0,0 +1,3 @@ | |||
import { z } from "zod"; | |||
|
|||
const Schema1 = z.string().or(z.number()); |
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.
Does it work with multiple .or
in the same chain? We should probably add a test cases for it as well.
Currently migrating
or
produces a runtime errorproudces
this fixes it migrating or to an union.