import { type RefsStore, type UnionNode } from '@vinejs/compiler/types'; import { UnionConditional } from './conditional.js'; import { ITYPE, OTYPE, COTYPE, PARSE } from '../../symbols.js'; import type { SchemaTypes, ParserOptions, ConstructableSchema, UnionNoMatchCallback, WithJSONSchema } from '../../types.js'; import { VineOptional } from '../optional/main.js'; import { VineNull } from '../null/main.js'; import { type JSONSchema7 } from 'json-schema'; /** * Vine union represents a union data type. A union is a collection * of conditionals and each condition has an associated schema. * * Unions allow you to define validation logic where different schemas * are applied based on runtime conditions. Each conditional is evaluated * in order, and the first matching condition's schema is used for validation. * * @template Conditional - The union conditional type extending UnionConditional * * @example * const schema = vine.object({ * userType: vine.string(), * data: vine.union([ * vine.union.if( * (value) => value.userType === 'admin', * vine.object({ permissions: vine.array(vine.string()) }) * ), * vine.union.else( * vine.object({ role: vine.string() }) * ) * ]) * }) */ export declare class VineUnion> implements ConstructableSchema, WithJSONSchema { #private; /** * The input type of the schema */ [ITYPE]: Conditional[typeof ITYPE]; /** * The output type of the schema */ [OTYPE]: Conditional[typeof OTYPE]; /** * The camelCase output type of the schema */ [COTYPE]: Conditional[typeof COTYPE]; /** * Creates a new VineUnion instance with the specified conditionals. * * @param conditionals - Array of conditional branches to evaluate */ constructor(conditionals: Conditional[]); /** * Mark the field under validation as optional. An optional * field allows both null and undefined values. */ optional(): VineUnion>>; /** * Mark the field under validation to be null. The null value will * be written to the output as well. * * If `optional` and `nullable` are used together, then both undefined * and null values will be allowed. */ nullable(): VineUnion>; /** * Define a fallback method to invoke when all of the union conditions * fail. You may use this method to report an error. */ otherwise(callback: UnionNoMatchCallback>): this; /** * Transforms into JSONSchema. */ toJSONSchema(): JSONSchema7; /** * Clones the VineUnion schema type. */ clone(): this; /** * Compiles the union schema to a compiler node. * * @param propertyName - The name of the property being validated * @param refs - Reference store for tracking validators and conditionals * @param options - Parser options including camelCase transformation */ [PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): UnionNode; }