Skip to content

feat(zod): adapt zod 4 update#506

Merged
dinwwwh merged 8 commits intomainfrom
feat/zod/update-zod4-support
May 16, 2025
Merged

feat(zod): adapt zod 4 update#506
dinwwwh merged 8 commits intomainfrom
feat/zod/update-zod4-support

Conversation

@dinwwwh
Copy link
Copy Markdown
Member

@dinwwwh dinwwwh commented May 16, 2025

Adapt current change from zod4, and improve a bit

Summary by CodeRabbit

  • Chores
    • Updated multiple dependencies across packages and playgrounds, including zod, @tanstack/react-query, @types/node, and typescript, to newer or beta versions.
    • Improved compatibility and ensured up-to-date development environments by aligning dependency versions.
  • Tests
    • Added and expanded test cases for enhanced coverage of schema coercion and conversion behaviors, particularly for default and prefault handling in boolean and string schemas.
  • Refactor
    • Updated import paths for Zod-related modules to use new package paths.
    • Refined internal logic for handling schema defaults and prefaults during conversion and coercion.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 16, 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 May 16, 2025 8:05am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 16, 2025

Walkthrough

This update primarily upgrades the zod package across multiple workspaces and playgrounds to a specific beta version. Several related dependencies, including various @nestjs, @tanstack/react-query, typescript, and @types/node packages, are also updated to newer versions in relevant projects. Additionally, minor dependency management adjustments and test import path updates are made, with some test cases added or modified to reflect new schema features.

Changes

File(s) / Path(s) Change Summary
packages/client/package.json, packages/contract/package.json, packages/openapi/package.json, packages/react-query/package.json, packages/react/package.json, packages/solid-query/package.json, packages/svelte-query/package.json, playgrounds/nuxt/package.json, playgrounds/solid-start/package.json Updated zod devDependency from stable ^3.24.2 to beta 3.25.0-beta.20250516T005923.
packages/nest/package.json Upgraded @nestjs/core to ^11.0.1, rxjs to ^7.8.1, and zod to beta version.
playgrounds/astro/package.json Upgraded @tanstack/react-query and zod to newer versions.
playgrounds/contract-first/package.json, playgrounds/next/package.json, playgrounds/svelte-kit/package.json Updated @tanstack/react-query, @types/node, typescript, and zod to newer versions.
playgrounds/nest/package.json Upgraded several NestJS, React Query, Types, TypeScript, and zod dependencies.
playgrounds/tanstack-start/package.json Upgraded @types/react, @types/react-dom, vinxi, and zod dependencies.
apps/content/package.json Upgraded @pinia/colada, @tanstack/react-query, @types/node, pinia, and vue.
packages/vue-colada/package.json Added @pinia/colada, vue as devDependencies; bumped pinia version.
packages/vue-query/package.json Updated @tanstack/vue-query dependency version.
packages/standard-server-node/package.json, package.json Updated @types/node version. Changed typescript version to caret range in root.
packages/zod/package.json Removed peer dependencies on @zod/core, @zod/mini, zod4; updated zod to beta.
packages/zod/src/zod4/*.test.ts, packages/zod/src/zod4/converter.test.ts, packages/zod/src/zod4/converter.structure.test.ts Changed test imports from zod4/@zod/mini to zod/v4/zod/v4-mini; added/modified test cases for new schema features.
packages/zod/src/zod4/coercer.ts, packages/zod/src/zod4/converter.ts Updated imports to zod/v4/core; added support for $ZodPrefault and handled new schema types (prefault); adjusted logic for default/catch/prefault cases.
packages/zod/src/zod4/registries.ts Changed imports from @zod/core to zod/v4/core.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ZodSchema
    participant Coercer
    participant Converter

    User->>ZodSchema: Define schema with .default(), .prefault(), or .catch()
    User->>Coercer: Pass input for coercion
    Coercer->>ZodSchema: Inspect schema type
    alt default or prefault
        Coercer->>ZodSchema: Check input for undefined
        Coercer->>ZodSchema: Return default/prefault value if needed
    else catch
        Coercer->>ZodSchema: Coerce input without undefined check
    end
    Coercer-->>User: Return coerced value

    User->>Converter: Convert schema to JSON Schema
    Converter->>ZodSchema: Inspect schema type
    alt default or prefault
        Converter->>ZodSchema: Extract defaultValue property
        Converter-->>User: JSON Schema with default
    else catch
        Converter->>ZodSchema: Convert inner type
        Converter-->>User: JSON Schema for inner type
    end
Loading

Poem

🐇
A hop, a skip, a beta leap,
Zod’s new form is ours to keep!
Imports changed, dependencies rise,
Prefaults and defaults harmonize.
From playground fields to testy ground,
This update’s carrots all around!
— 🥕


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.
    • @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 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 16, 2025

More templates

@orpc/arktype

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

@orpc/client

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

@orpc/nest

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

@orpc/contract

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

@orpc/openapi

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

@orpc/openapi-client

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

@orpc/react

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

@orpc/react-query

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

@orpc/server

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

@orpc/shared

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

@orpc/solid-query

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

@orpc/standard-server

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

@orpc/standard-server-fetch

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

@orpc/standard-server-node

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

@orpc/standard-server-peer

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

@orpc/svelte-query

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

@orpc/valibot

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

@orpc/vue-colada

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

@orpc/vue-query

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

@orpc/zod

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

commit: afff240

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between fcb9d5a and 2d306cb.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (35)
  • packages/client/package.json (1 hunks)
  • packages/contract/package.json (1 hunks)
  • packages/nest/package.json (1 hunks)
  • packages/openapi/package.json (1 hunks)
  • packages/react-query/package.json (1 hunks)
  • packages/react/package.json (1 hunks)
  • packages/solid-query/package.json (1 hunks)
  • packages/svelte-query/package.json (1 hunks)
  • packages/vue-colada/package.json (1 hunks)
  • packages/zod/package.json (1 hunks)
  • packages/zod/src/zod4/coercer.combination.test.ts (2 hunks)
  • packages/zod/src/zod4/coercer.native.test.ts (1 hunks)
  • packages/zod/src/zod4/coercer.rest.test.ts (1 hunks)
  • packages/zod/src/zod4/coercer.structure.test.ts (1 hunks)
  • packages/zod/src/zod4/coercer.test.ts (1 hunks)
  • packages/zod/src/zod4/coercer.ts (2 hunks)
  • packages/zod/src/zod4/converter.combination.test.ts (1 hunks)
  • packages/zod/src/zod4/converter.meta.test.ts (2 hunks)
  • packages/zod/src/zod4/converter.native.test.ts (1 hunks)
  • packages/zod/src/zod4/converter.number.test.ts (1 hunks)
  • packages/zod/src/zod4/converter.processed.test.ts (1 hunks)
  • packages/zod/src/zod4/converter.rest.test.ts (1 hunks)
  • packages/zod/src/zod4/converter.string.test.ts (1 hunks)
  • packages/zod/src/zod4/converter.structure.test.ts (2 hunks)
  • packages/zod/src/zod4/converter.test.ts (2 hunks)
  • packages/zod/src/zod4/converter.ts (4 hunks)
  • packages/zod/src/zod4/registries.ts (1 hunks)
  • playgrounds/astro/package.json (1 hunks)
  • playgrounds/contract-first/package.json (1 hunks)
  • playgrounds/nest/package.json (1 hunks)
  • playgrounds/next/package.json (1 hunks)
  • playgrounds/nuxt/package.json (1 hunks)
  • playgrounds/solid-start/package.json (1 hunks)
  • playgrounds/svelte-kit/package.json (1 hunks)
  • playgrounds/tanstack-start/package.json (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/zod/src/zod4/converter.ts (1)
packages/zod/src/zod4/coercer.ts (1)
  • schema (45-346)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: publish-commit
  • GitHub Check: lint
🔇 Additional comments (41)
playgrounds/next/package.json (1)

27-27:

Details

✅ Verification successful

Confirm the Zod pre-release version
This change pins zod to 3.25.0-beta.20250516T005923, aligning with the repository-wide upgrade. Ensure this beta release is published on npm to avoid installation failures.

Run the following to verify availability:


🏁 Script executed:

npm view zod@3.25.0-beta.20250516T005923 version

Length of output: 78


Zod pre-release version confirmed
npm view zod@3.25.0-beta.20250516T005923 version returns 3.25.0-beta.20250516T005923, confirming it’s published on npm and safe to install.

playgrounds/tanstack-start/package.json (1)

31-31:

Details

✅ Verification successful

Confirm availability of the Zod beta version

The zod devDependency has been bumped to 3.25.0-beta.20250516T005923 to align with the Zod v4 migration across the repo. Please verify that this pre-release exists on npm and can be resolved correctly.


🏁 Script executed:

#!/bin/bash
# Verify that the Zod beta version is available on npm
npm view zod@3.25.0-beta.20250516T005923 version

Length of output: 78


Zod beta version available on npm

Verified that zod@3.25.0-beta.20250516T005923 is published and resolvable on npm. No further action required.

playgrounds/astro/package.json (1)

28-28:

Details

✅ Verification successful

Confirm zod beta version consistency and availability
Please ensure that this exact zod version (3.25.0-beta.20250516T005923) is intentionally pinned across all related package.json files and verify it’s published and installable from npm.


🏁 Script executed:

#!/bin/bash
# List all 'zod' entries in the repo to check for consistent versioning
rg -n '"zod":' .

# Verify that the specified beta version exists on npm
npm view zod versions --json | jq '.[] | select(.=="3.25.0-beta.20250516T005923")'

Length of output: 1517


zod beta version pinning and npm availability confirmed

  • All package.json entries across playgrounds and packages reference "zod": "3.25.0-beta.20250516T005923".
  • The beta version 3.25.0-beta.20250516T005923 is published and installable from npm.

No further action required.

playgrounds/solid-start/package.json (1)

20-20:

Details

✅ Verification successful

Verify pre-release Zod version availability and compatibility.

The change pins zod to the exact beta version 3.25.0-beta.20250516T005923. Please confirm this pre-release is published and installable, and that it works correctly in your build and tooling. Also ensure consistency with other package.json files that were updated in this PR.

Run the following script to validate the version on npm:


🏁 Script executed:

#!/usr/bin/env bash
# Confirm that the beta version of zod is available on npm
npm view zod@3.25.0-beta.20250516T005923 version

Length of output: 78


🏁 Script executed:

#!/usr/bin/env bash
# Search for all zod dependency versions in package.json files to verify consistency
rg -g '*.json' '"zod": ' -n

Length of output: 1377


🏁 Script executed:

#!/usr/bin/env bash
# Show context for zod entries in the root package.json of the zod package
rg -n '"zod":' -C 3 packages/zod/package.json

Length of output: 414


Confirmed Zod@3.25.0-beta.20250516T005923 availability and alignment
npm view confirms this beta is published and installable. All playgrounds and packages that depend on Zod now pin exactly 3.25.0-beta.20250516T005923, and the core packages/zod/package.json retains a peerDependency of >=3.24.2 by design. No further action needed.

playgrounds/contract-first/package.json (1)

22-22:

Details

✅ Verification successful

Validate the beta version bump for Zod
Please confirm that switching to this exact pre-release (3.25.0-beta.20250516T005923) is intentional and that it doesn’t introduce breaking changes. Also ensure that every package.json in the repo is updated to the same Zod version to avoid mismatches.

Run this script from the repo root to verify consistency:


🏁 Script executed:

#!/usr/bin/env bash
set -e

TARGET='\"zod\": \"3.25.0-beta.20250516T005923\"'
echo "Checking Zod version across all package.json files..."

mismatches=0
while IFS= read -r file; do
  if grep -q '"zod":' "$file" && ! grep -q "$TARGET" "$file"; then
    echo "Mismatch in $file: $(grep '"zod":' "$file")"
    mismatches=$((mismatches+1))
  fi
done < <(find . -type f -name 'package.json')

if [ "$mismatches" -gt 0 ]; then
  echo "❌ Found $mismatches package.json with an incorrect Zod version."
  exit 1
else
  echo "✅ All Zod versions are consistent."
fi

Length of output: 339


I’ll re-run the consistency check using a simpler loop to avoid the /dev/fd error:


🏁 Script executed:

#!/usr/bin/env bash
set -e

TARGET='"zod": "3.25.0-beta.20250516T005923"'
echo "Checking Zod version across all package.json files..."

mismatches=0
for file in $(find . -type f -name 'package.json'); do
  if grep -q '"zod":' "$file" && ! grep -q "$TARGET" "$file"; then
    echo "Mismatch in $file: $(grep '"zod":' "$file")"
    mismatches=$((mismatches+1))
  fi
done

if [ "$mismatches" -gt 0 ]; then
  echo "❌ Found $mismatches package.json with an incorrect Zod version."
  exit 1
else
  echo "✅ All Zod versions are consistent."
fi

Length of output: 65866


Zod pre-release bump confirmed across local packages
All workspace package.json files under /, /packages, and /playgrounds reference "zod": "3.25.0-beta.20250516T005923". Only dependency manifests in node_modules still show older versions, which is expected. No further action required.

playgrounds/nuxt/package.json (1)

22-22: Bump zod to beta pre-release
Updated the zod version from ^3.24.2 to 3.25.0-beta.20250516T005923 to align with Zod 4 support. Please ensure the lockfile (package-lock.json or yarn.lock) is regenerated and confirm that this specific pre-release is published and resolvable on npm.

packages/zod/src/zod4/converter.rest.test.ts (1)

1-1: Use new zod/v4 import path
The test now imports from zod/v4 instead of the old zod4 entrypoint, matching the updated Zod 4 module structure.

packages/zod/src/zod4/coercer.rest.test.ts (1)

1-1: Switch import to zod/v4
Aligns the coercion tests with the new Zod 4 module path by importing z from zod/v4.

packages/zod/src/zod4/converter.combination.test.ts (1)

1-1: Upgrade test import to zod/v4
Updated the import for Zod to zod/v4 to support Zod 4, consistent with other converter tests.

packages/zod/src/zod4/converter.number.test.ts (1)

1-1: Import Zod from zod/v4
Changed the import to zod/v4 to match the new Zod 4 structure; numeric schema tests now reference the correct module.

packages/zod/src/zod4/converter.processed.test.ts (1)

1-1: Consistent import update to zod v4
The default import path has been correctly changed from 'zod4' to 'zod/v4' to align with the new package structure.

packages/zod/src/zod4/coercer.native.test.ts (1)

1-1: Align import with zod v4
Updated the default import to 'zod/v4', matching the migration across all native coercion tests.

packages/zod/src/zod4/coercer.structure.test.ts (1)

1-1: Import path updated for structure coercion tests
Changed import from 'zod4' to 'zod/v4' for consistency with the zod v4 submodule.

packages/zod/src/zod4/converter.string.test.ts (1)

1-1: Update converter tests to use zod/v4
The import path correctly reflects the new zod v4 entry point.

packages/zod/src/zod4/coercer.test.ts (1)

1-1: Switch to zod/v4 for coercer plugin tests
The module import is now aligned with the updated zod v4 structure (import * as z from 'zod/v4').

packages/zod/src/zod4/converter.native.test.ts (1)

1-1: Align import path for Zod v4
Updated the import from the legacy 'zod4' path to 'zod/v4' to reflect the new package structure.

packages/nest/package.json (1)

74-74: Update devDependency Zod to beta v4
Bumped "zod" to "3.25.0-beta.20250516T005923" in devDependencies to maintain consistency with the migration.

packages/react/package.json (1)

56-56: Bump Zod to v4 beta in devDependencies
Updated "zod" to "3.25.0-beta.20250516T005923", aligning with the overall version strategy.

packages/openapi/package.json (1)

72-72: Synchronize Zod beta version
Changed "zod" to "3.25.0-beta.20250516T005923" under devDependencies to match the unified beta release.

packages/contract/package.json (1)

44-44: Sync devDependency Zod version
Updated "zod" to "3.25.0-beta.20250516T005923" in devDependencies to complete the Zod v4 upgrade.

packages/solid-query/package.json (1)

49-49: Consistent Zod beta version bump
The zod devDependency was updated to 3.25.0-beta.20250516T005923, aligning with the PR objective of uniform Zod v4 support across packages.

packages/react-query/package.json (1)

50-50: Consistent Zod beta version bump
The zod devDependency was updated to 3.25.0-beta.20250516T005923, consistent with the coordinated upgrade across your other packages.

packages/svelte-query/package.json (1)

49-49: Consistent Zod beta version bump
The zod devDependency was updated to 3.25.0-beta.20250516T005923, matching the version used in the rest of the monorepo.

packages/client/package.json (1)

67-67: Consistent Zod beta version bump
The zod devDependency was updated to 3.25.0-beta.20250516T005923, ensuring uniform Zod v4 beta usage across all client and plugin packages.

packages/zod/src/zod4/converter.test.ts (2)

1-2: Verify new Zod import paths
The imports were updated to:

import * as z from 'zod/v4'
import * as zm from 'zod/v4-mini'

Please confirm that these paths are valid exports in the 3.25.0-beta.20250516T005923 release and resolve correctly in your build.


19-19: Approve test metadata update
The test name was changed to 'zod mini', which correctly reflects the mini-variant import. No logic or assertion changes introduced.

packages/vue-colada/package.json (1)

49-51: Dependency updates are in line with zod 4 compatibility work

These dependency updates align with the broader work to update dependencies across the monorepo. The additions of @pinia/colada and the specific versions of Vue and Pinia are appropriate for compatibility with the updated zod ecosystem.

packages/zod/src/zod4/registries.ts (1)

2-3: Import path updates for Zod 4 compatibility

The import paths have been correctly updated from '@zod/core' to 'zod/v4/core' to align with Zod 4's module structure. This change is consistent with the broader migration effort across the codebase.

packages/zod/src/zod4/converter.meta.test.ts (3)

1-1: Import path updated for Zod 4 compatibility

The import path has been correctly updated from 'zod4' to 'zod/v4' to align with Zod 4's module structure.


67-71: Added test case for prefault schema

Good addition of a test case for the new prefault schema method introduced in Zod 4. This ensures the converter correctly handles this schema type.


75-75:

Details

✅ Verification successful

Updated expected behavior for catch schema

The expected input validity flag for string.catch("a") has been changed from false to true. This appears to reflect a behavioral change in Zod 4.


🌐 Web query:

What is the behavior difference between catch() and default() methods in Zod 4?

💡 Result:

Behavior Difference Between .catch() and .default() in Zod 4

.default(): Default Value for Undefined Input

  • The .default() method in Zod allows you to specify a default value that is used only when the input provided is undefined.
  • If the input is present and matches the base schema, it is parsed as usual.
  • If the input is present but does not match the schema (i.e., it's invalid), Zod throws a validation error—it does not use the default value in this case.
  • Use .default() when you want to supply a value only for missing (undefined) fields, but still want invalid inputs to trigger an error[1].

.catch(): Default Value for Any Parsing Error

  • The .catch() method also lets you specify a fallback value, but its behavior is broader.
  • If the input is undefined or if any validation error occurs (e.g., input with the wrong type or invalid value), Zod will not throw an error. Instead, it will return the specified catch value.
  • Use .catch() when you want to avoid validation errors entirely and always receive some value, even if the input is present but doesn't match the schema[1][4][10].

Comparison Table

Method Returns Default When Input is Undefined Returns Default When Input is Invalid Throws Error on Invalid Input
.default() Yes No Yes
.catch() Yes Yes No

Example

Suppose you define a schema for user roles:

const roleSchema = z.enum(['Admin', 'User', 'Guest']);
  • roleSchema.default('User') will:
    • Return "User" if the input is undefined.
    • Throw an error if the input is anything other than "Admin", "User", or "Guest".
  • roleSchema.catch('User') will:
    • Return "User" both if the input is undefined or if the input is invalid (e.g., "SuperAdmin", 42, etc.)[1].

Summary

  • Use .default() for optional fields with a fallback value, but strict validation for any provided input.
  • Use .catch() for a forgiving schema that never throws and always returns a value, defaulting on any error (missing or invalid input)[1][4][10].

Citations:


Approve updated .catch() expected behavior

The input validity flag for string.catch("a") should be true in Zod 4, since .catch() returns the fallback value on any parsing error (including invalid input) rather than throwing.

• packages/zod/src/zod4/converter.meta.test.ts:75 – updated input: [true, { type: 'string' }] now correctly reflects Zod 4’s documented behavior.

packages/zod/src/zod4/coercer.combination.test.ts (1)

1-1: Import path updated for Zod 4 compatibility

The import path has been correctly updated from 'zod4' to 'zod/v4' to align with Zod 4's module structure.

packages/zod/src/zod4/converter.structure.test.ts (2)

1-2: Import paths updated to match Zod v4 structure.

The import paths have been updated from 'zod4' and '@zod/mini' to 'zod/v4' and 'zod/v4-mini' respectively, adapting to the new module structure in Zod v4.


32-36: New test case looks good.

This test case verifies the conversion of a schema with both optional and default modifiers. The test ensures that array items of type string with a default value of 'a' are properly converted to the expected JSON schema.

packages/zod/package.json (1)

54-55:

Details

❓ Verification inconclusive

Consider implications of using a beta version in production.

The update to a beta version of Zod (3.25.0-beta.20250516T005923) is appropriate for implementing Zod v4 features, but be cautious about using beta releases in production environments as they may contain breaking changes or bugs.


🌐 Web query:

Are there any known issues with zod version 3.25.0-beta.20250516T005923?

💡 Result:

I don't have specific information about Zod version "3.25.0-beta.20250516T005923" as it appears to be a very recent beta version released today (May 16, 2025) based on the version number format.

Since this appears to be a brand new beta release:

  1. There may not be widespread documentation of issues yet
  2. Being a beta version, it's expected to potentially have some bugs or unfinished features
  3. The official Zod GitHub repository would be the best place to check for known issues

To get accurate information about any known issues with this specific beta version, I recommend:

  1. Checking the Zod GitHub repository issues page
  2. Reading the release notes for this specific version
  3. Joining the Zod community Discord if one exists
  4. Posting a question on Stack Overflow if you're experiencing a specific problem

If you're using this in a production environment, be aware that beta versions are generally not recommended for critical applications.


Review updated: Confirm beta stability before production usage

This Zod version is a fresh beta release with no reported issues so far, but beta releases can include breaking changes or bugs. Before rolling this into production, please:

  • Verify there are no open issues specific to 3.25.0-beta.20250516T005923 on the Zod GitHub issues page
  • Review the release notes for this beta to understand any unfinished or experimental features
  • Consider testing critical flows thoroughly against this beta in a staging environment
  • Stay connected with the Zod community (Discord, GitHub discussions) for early bug reports
packages/zod/src/zod4/coercer.ts (2)

3-25: Updated imports for Zod v4 compatibility.

The imports have been updated from '@zod/core' to 'zod/v4/core' and $ZodPrefault has been added to the import list, aligning with the Zod v4 module structure.


297-311: Improved handling of default, prefault, and catch schemas.

The code now separates the handling of 'default'/'prefault' from 'catch' schemas, improving code clarity and maintainability:

  1. 'default' and 'prefault' types now return the value unchanged when undefined before coercing inner types
  2. 'catch' has been moved to its own case block, focusing only on coercing the inner type

This change correctly adapts to the Zod v4 schema behavior where prefault is a distinct schema type.

packages/zod/src/zod4/converter.ts (4)

21-21: Updated imports for Zod v4 compatibility.

The imports have been updated to use the new 'zod/v4/core' path and added the $ZodPrefault type to the imports list, aligning with the Zod v4 module structure.

Also applies to: 31-31, 36-36


477-486: Enhanced schema handling for default and prefault types.

The code now handles both 'default' and 'prefault' schema types, and accesses the default value through a property (defaultValue) instead of a function call (defaultValue()), adapting to the Zod v4 API changes.


488-491: Simplified catch schema handling.

The code for handling 'catch' schemas has been simplified by directly returning the result of the #convert method call, making the code more concise and readable.


566-566: Improved array item schema handling for default values.

Added a check for schema.default !== undefined in the condition, ensuring that schemas with default values are properly handled even when they're not required. This fixes a potential edge case where default values might be ignored in array items.

Comment thread playgrounds/svelte-kit/package.json
Comment thread playgrounds/nest/package.json
Comment thread packages/zod/src/zod4/coercer.combination.test.ts
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/vue-colada/tests/shared.tsx (1)

13-13: Consider using a more precise type assertion instead of any

The as any type assertion was added to bypass TypeScript's type checking between the result of createPinia() and what's expected by Vue's plugin system. While this works as a quick fix, using any loses type safety.

Consider using a more specific type if available:

- createPinia() as any,
+ createPinia() as Pinia, // or the appropriate plugin type

Alternatively, you could check if updating the @types/pinia package or Vue's type definitions might resolve the type incompatibility without requiring the assertion.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 2d306cb and a344f1c.

📒 Files selected for processing (2)
  • packages/vue-colada/tests/shared.tsx (1 hunks)
  • packages/zod/src/zod4/coercer.combination.test.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/zod/src/zod4/coercer.combination.test.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: publish-commit
  • GitHub Check: lint

@codecov
Copy link
Copy Markdown

codecov Bot commented May 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
package.json (1)

46-46: Review TypeScript version range
Switching from a fixed "5.8.3" to a caret range "^5.8.3" permits minor and patch upgrades, which can sometimes introduce unexpected issues. Ensure your CI enforces pnpm install --frozen-lockfile and runs tsc --noEmit across all workspaces to catch any regressions. If tighter control is needed, consider pinning to an exact version or adding an engines field to enforce the supported range.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between a344f1c and afff240.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (11)
  • apps/content/package.json (1 hunks)
  • package.json (2 hunks)
  • packages/nest/package.json (1 hunks)
  • packages/standard-server-node/package.json (1 hunks)
  • packages/vue-query/package.json (1 hunks)
  • playgrounds/astro/package.json (1 hunks)
  • playgrounds/contract-first/package.json (1 hunks)
  • playgrounds/nest/package.json (3 hunks)
  • playgrounds/next/package.json (1 hunks)
  • playgrounds/svelte-kit/package.json (1 hunks)
  • playgrounds/tanstack-start/package.json (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • packages/standard-server-node/package.json
  • apps/content/package.json
  • packages/vue-query/package.json
  • playgrounds/next/package.json
🚧 Files skipped from review as they are similar to previous changes (6)
  • playgrounds/astro/package.json
  • playgrounds/contract-first/package.json
  • packages/nest/package.json
  • playgrounds/svelte-kit/package.json
  • playgrounds/tanstack-start/package.json
  • playgrounds/nest/package.json
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: publish-commit
  • GitHub Check: lint
🔇 Additional comments (1)
package.json (1)

36-36: Approve bump of @types/node to ^22.15.17
Updating to the latest Node.js type definitions helps ensure compatibility with new Node APIs.

@dinwwwh dinwwwh changed the title feat(zod): update zod 4 support feat(zod): adapt zod 4 update May 16, 2025
@dinwwwh dinwwwh merged commit fa8d145 into main May 16, 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