Add anyOf action for alternative pipeline constraints - #1466
Conversation
|
@yslpn is attempting to deploy a commit to the Open Circle Team on Vercel. A member of the Team first needs to authorize it. |
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughThis PR adds a synchronous 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
There was a problem hiding this comment.
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
anyOfaction 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 existinganyOfviaallOffall-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.
commit: |
There was a problem hiding this comment.
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
📒 Files selected for processing (5)
library/src/actions/anyOf/anyOf.test-d.tslibrary/src/actions/anyOf/anyOf.test.tslibrary/src/actions/anyOf/anyOf.tswebsite/src/routes/api/(actions)/anyOf/index.mdxwebsite/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
There was a problem hiding this comment.
All reported issues were addressed
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 26 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Summary
Add the
anyOfaction for alternative sync validation constraints on an already typed pipeline value, including runtime/type tests, JSON Schema conversion support, and API documentation.Examples
Closes open-circle/valibot#1446.
Summary by cubic
Adds a new
anyOfvalidation 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
v.anyOf([...])for alternative constraints inpipe; supports sync validations andguard; aggregates sub-issues on failure.guard; rejects async/transform/metadata options at type level and runtime.to-json-schema: converts to JSON SchemaanyOf, composes with existinganyOfviaallOf, respectsignoreActions, warns on unsupported nestedguard.Bug Fixes
guardare allowed as options.typedflag when onlyguardoptions fail; preserves existing issues and propagates config; sorted exports and action lists in docs; updated examples with named guard functions for clarity._subIssuesinutilsand reused it inanyOf/union(updated imports and tests).Written for commit 11cd4ff. Summary will update on new commits.
Summary by CodeRabbit
New Features
anyOfvalidation for trying multiple synchronous validation or transformation options in order.anyOf.Documentation
anyOfand its related types.Tests
anyOf.