import type { LiteralNode, RefsStore } from '@vinejs/compiler/types'; import { OTYPE, COTYPE, PARSE, ITYPE, SUBTYPE, UNIQUE_NAME, IS_OF_TYPE } from '../../symbols.js'; import type { Parser, Validation, RuleBuilder, FieldOptions, ParserOptions, ConstructableSchema } from '../../types.js'; import { ConditionalValidations } from '../base/conditional_rules.js'; import { type JSONSchema7 } from 'json-schema'; /** * VineOptional represents an optional value inside a union or schema. * It allows both null and undefined values to pass validation. * * This type is typically used with unions to make certain branches * optional, or to explicitly mark a field as allowing undefined/null values. * * @template Output - The output type when the value is defined * * @example * const schema = vine.object({ * name: vine.string().optional() * }) * * @example * const schema = vine.unionOfTypes([ * vine.string(), * vine.optional() * ]) */ export declare class VineOptional extends ConditionalValidations implements ConstructableSchema { /** * The input type of the schema (null or undefined) */ [ITYPE]: null | undefined; /** * The output type of the schema when value is defined */ [OTYPE]: Output; /** * The camelCase output type of the schema */ [COTYPE]: Output; /** * The subtype identifier for the literal schema field */ [SUBTYPE]: string; /** * Unique name identifier for union type resolution */ [UNIQUE_NAME]: string; /** * Type checker function to determine if a value is optional (null or undefined). * Required for "unionOfTypes" functionality. * * @param value - The value to check */ [IS_OF_TYPE]: (value: unknown) => value is null | undefined; /** * Field options controlling validation behavior */ protected options: FieldOptions; /** * Set of validations to run on the field */ protected validations: Validation[]; /** * Creates a new VineOptional instance. * * @param options - Field options like bail mode and nullability * @param validations - Initial set of validations to apply */ constructor(options?: Partial, validations?: Validation[]); /** * Shallow clones the validations. Since there are no APIs to mutate * the validation options, we can safely copy them by reference. * * @returns Array of cloned validation objects */ protected cloneValidations(): Validation[]; /** * Shallow clones the field options. * * @returns Cloned field options object */ protected cloneOptions(): FieldOptions; /** * Compiles validations into a format suitable for the compiler. * * @param refs - Reference store for tracking validators */ protected compileValidations(refs: RefsStore): { ruleFnId: `ref://${number}`; implicit: boolean; isAsync: boolean; }[]; /** * Define a method to parse the input value. The method * is invoked before any validation and hence you must * perform type-checking to know the value you are working with. * * @param callback - Parser function to transform the input value */ parse(callback: Parser): this; /** * Push a validation to the validations chain. * * @param validation - Validation rule or rule builder to add */ use(validation: Validation | RuleBuilder): this; /** * Enable/disable the bail mode. In bail mode, the field validations * are stopped after the first error. * * @param state - True to enable bail mode, false to disable */ bail(state: boolean): this; /** * Clones the VineOptional schema type. The applied options * and validations are copied to the new instance. * * @returns A cloned instance of this VineOptional schema */ clone(): this; /** * Mark the field under validation to be nullable. The null value will * be written to the output as well. When combined with optional, * both null and undefined values are allowed. */ nullable(): VineOptional; /** * Transforms into JSON Schema format. */ toJSONSchema(): JSONSchema7; /** * Compiles the schema type to a compiler node. * * @param propertyName - The name of the property being validated * @param refs - Reference store for tracking validators and parsers * @param options - Parser options including camelCase transformation */ [PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): LiteralNode & { subtype: string; }; }