Skip to content

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

Merged
merged 2 commits into from
Jul 27, 2025

Conversation

paoloricciuti
Copy link
Contributor

Currently migrating or produces a runtime error

import * as z from 'zod';

const Schema = z.string().or(z.number())

proudces

import * as v from "valibot";

const Schema = v.string()(v.number())

this fixes it migrating or to an union.

@Copilot Copilot AI review requested due to automatic review settings July 27, 2025 18:01
Copy link

vercel bot commented Jul 27, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
valibot ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 27, 2025 7:04pm

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jul 27, 2025
Copy link

@Copilot Copilot AI left a 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's union() 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());
Copy link
Owner

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()])

Copy link
Contributor Author

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 😄

Copy link

pkg-pr-new bot commented Jul 27, 2025

Open in StackBlitz

npm i https://pkg.pr.new/valibot@1261

commit: 17df5ca

@@ -0,0 +1,3 @@
import { z } from "zod";

const Schema1 = z.string().or(z.number());
Copy link
Owner

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.

@fabian-hiller fabian-hiller self-assigned this Jul 27, 2025
@fabian-hiller fabian-hiller merged commit 04bcbae into fabian-hiller:main Jul 27, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants