Skip to content

Add anyOf action for alternative pipeline constraints - #1466

Open
yslpn wants to merge 16 commits into
open-circle:mainfrom
yslpn:feat-any-of-action
Open

Add anyOf action for alternative pipeline constraints#1466
yslpn wants to merge 16 commits into
open-circle:mainfrom
yslpn:feat-any-of-action

Conversation

@yslpn

@yslpn yslpn commented May 18, 2026

Copy link
Copy Markdown
Member

Summary

Add the anyOf action for alternative sync validation constraints on an already typed pipeline value, including runtime/type tests, JSON Schema conversion support, and API documentation.

Examples

const WebsiteSchema = v.pipe(v.string(), v.anyOf([v.domain(), v.url()]));
const isPixelString = (input: string): input is `${number}px` =>
  /^\d+px$/u.test(input);

const isRemString = (input: string): input is `${number}rem` =>
  /^\d+rem$/u.test(input);

const CssSizeSchema = v.pipe(
  v.string(),
  v.anyOf([v.guard(isPixelString), v.guard(isRemString)])
);

Closes open-circle/valibot#1446.


Summary by cubic

Adds a new anyOf validation action for alternative pipeline constraints, with full runtime/type safety, JSON Schema conversion, and docs. This helps validate inputs that can satisfy one of several sync rules without changing the value.

  • New Features

    • New v.anyOf([...]) for alternative constraints in pipe; supports sync validations and guard; aggregates sub-issues on failure.
    • Strong TS inference; preserves input type, narrows outputs with guard; rejects async/transform/metadata options at type level and runtime.
    • to-json-schema: converts to JSON Schema anyOf, composes with existing anyOf via allOf, respects ignoreActions, warns on unsupported nested guard.
  • Bug Fixes

    • Tightened runtime checks and clearer errors: only sync validations or guard are allowed as options.
    • Correct issue typing and dataset typed flag when only guard options fail; preserves existing issues and propagates config; sorted exports and action lists in docs; updated examples with named guard functions for clarity.
    • Refactor: centralized _subIssues in utils and reused it in anyOf/union (updated imports and tests).

Written for commit 11cd4ff. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features

    • Added anyOf validation for trying multiple synchronous validation or transformation options in order.
    • Supports first-match results, fallback transformations, custom messages, and detailed combined failure issues.
    • Added JSON Schema generation support for anyOf.
  • Documentation

    • Added API reference and guide documentation for anyOf and its related types.
    • Updated navigation and pipeline documentation.
  • Tests

    • Added comprehensive runtime, type inference, and JSON Schema coverage for anyOf.

Copilot AI review requested due to automatic review settings May 18, 2026 09:52
@vercel

vercel Bot commented May 18, 2026

Copy link
Copy Markdown

@yslpn is attempting to deploy a commit to the Open Circle Team on Vercel.

A member of the Team first needs to authorize it.

@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. enhancement New feature or request labels May 18, 2026
@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

This PR adds a synchronous anyOf validation action with composite type inference, ordered option execution, transformation support, and aggregated failure issues. It includes runtime and compile-time tests, JSON Schema conversion, public exports, API and type documentation, navigation updates, and pipeline guide integration. It also consolidates _subIssues imports through the shared utilities barrel and updates related import paths.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the new anyOf action for pipeline alternatives.
Linked Issues check ✅ Passed The PR implements the requested OR-style pipe action with anyOf, including runtime, typing, JSON Schema, and docs support.
Out of Scope Changes check ✅ Passed The changes are centered on anyOf and its supporting tests, docs, and exports, with no clearly unrelated additions.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a new anyOf validation action that combines multiple sync validation (and guard) options into an OR constraint on an already-typed pipeline value, with full typing, runtime checks, JSON Schema converter support, and API/site documentation.

Changes:

  • New anyOf action with strict typing of options (AnyOfOptions, AnyOfAction, AnyOfIssue), runtime guards, and runtime+type tests.
  • JSON Schema converter case for any_of, including support for an existing anyOf via allOf fall-back.
  • API reference, guide and menu updates documenting the new action and related types.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
library/src/actions/anyOf/anyOf.ts Core action implementation, types, runtime validation, ~run logic.
library/src/actions/anyOf/index.ts Re-export of anyOf.
library/src/actions/index.ts Adds anyOf to action barrel exports.
library/src/actions/anyOf/anyOf.test.ts Runtime tests for valid/invalid inputs and option count/kind enforcement.
library/src/actions/anyOf/anyOf.test-d.ts Type-level tests for inference and option compatibility.
packages/to-json-schema/src/converters/convertAction/convertAction.ts JSON Schema converter case for any_of.
packages/to-json-schema/src/converters/convertAction/convertAction.test.ts Converter tests including ignoreActions and nested unsupported actions.
packages/to-json-schema/src/functions/toJsonSchema/toJsonSchema.test.ts End-to-end conversion tests for pipelines using anyOf.
website/src/routes/api/menu.md Adds menu entries for anyOf, AnyOfAction, AnyOfIssue, AnyOfOptions.
website/src/routes/api/(actions)/anyOf/{index.mdx,properties.ts} API reference page and property definitions for anyOf.
website/src/routes/api/(types)/AnyOfAction/{index.mdx,properties.ts} API reference for the AnyOfAction type.
website/src/routes/api/(types)/AnyOfIssue/{index.mdx,properties.ts} API reference for the AnyOfIssue type.
website/src/routes/api/(types)/AnyOfOptions/{index.mdx,properties.ts} API reference for the AnyOfOptions type.
website/src/routes/api/(actions)/guard/index.mdx Adds cross-reference from guard to anyOf.
website/src/routes/guides/(main-concepts)/pipelines/index.mdx Lists anyOf among validation actions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread library/src/actions/index.ts Outdated
Comment thread website/src/routes/api/menu.md Outdated
Comment thread library/src/actions/anyOf/anyOf.ts Outdated
Comment thread library/src/actions/anyOf/anyOf.ts Outdated
Comment thread library/src/actions/anyOf/anyOf.ts
Comment thread library/src/actions/anyOf/anyOf.ts
Comment thread website/src/routes/api/(actions)/anyOf/index.mdx Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 19 files

Re-trigger cubic

@yslpn
yslpn marked this pull request as draft May 18, 2026 10:04
@yslpn
yslpn marked this pull request as ready for review May 18, 2026 10:30
@dosubot dosubot Bot added the documentation Improvements or additions to documentation label May 18, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 19 files

Re-trigger cubic

@fabian-hiller fabian-hiller self-assigned this May 19, 2026
@fabian-hiller fabian-hiller added this to the v1.5 milestone May 19, 2026
@pkg-pr-new

pkg-pr-new Bot commented May 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 89f9d38

@yslpn
yslpn marked this pull request as draft July 10, 2026 21:25
@yslpn
yslpn marked this pull request as ready for review July 17, 2026 10:09

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@library/src/actions/anyOf/anyOf.ts`:
- Around line 266-269: Update the successful branch in anyOf’s option processing
to preserve issues already present on the incoming dataset: copy the transformed
value from optionDataset onto the original dataset and return that original
dataset instead of returning optionDataset directly. Keep the existing
typed/no-issues condition and validation behavior unchanged.
- Around line 70-75: Update InferAnyOfOutput to use the pipe-style contextual
output inference for each AnyOfOption, preserving TInput when inferring
input-dependent transforms such as readonly(), brand(), and flavor() instead of
relying on standalone InferOutput. Add a regression test covering pipe(string(),
anyOf([email(), readonly()])) and verify it retains the schema’s concrete output
type rather than widening to unknown.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 45f58f32-136b-41d8-aea8-2204e7ee6ac4

📥 Commits

Reviewing files that changed from the base of the PR and between 11cd4ff and 0e241c4.

📒 Files selected for processing (5)
  • library/src/actions/anyOf/anyOf.test-d.ts
  • library/src/actions/anyOf/anyOf.test.ts
  • library/src/actions/anyOf/anyOf.ts
  • website/src/routes/api/(actions)/anyOf/index.mdx
  • website/src/routes/api/(types)/AnyOfOptions/properties.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • website/src/routes/api/(actions)/anyOf/index.mdx
  • library/src/actions/anyOf/anyOf.test.ts

Comment thread library/src/actions/anyOf/anyOf.ts Outdated
Comment thread library/src/actions/anyOf/anyOf.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread library/src/actions/anyOf/anyOf.ts Outdated
Comment thread library/src/actions/anyOf/anyOf.ts Outdated
@yslpn
yslpn marked this pull request as draft July 17, 2026 11:19
@yslpn
yslpn marked this pull request as ready for review July 17, 2026 11:31

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 26 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread library/src/actions/anyOf/anyOf.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add or, oneOf or some action/method for OR logic between pipe actions

3 participants