import { type Prettify } from '@poppinss/types'; import type { ObjectNode, RefsStore } from '@vinejs/compiler/types'; import { type ObjectGroup } from './group.js'; import { BaseType } from '../base/main.js'; import { type GroupConditional } from './conditional.js'; import { type OTYPE, type COTYPE, PARSE, UNIQUE_NAME, IS_OF_TYPE, type ITYPE } from '../../symbols.js'; import type { Validation, SchemaTypes, FieldOptions, ParserOptions, PropertiesToOptional, UndefinedOptional, WithJSONSchema } from '../../types.js'; import { type JSONSchema7 } from 'json-schema'; import type { CamelCase } from '../camelcase_types.ts'; /** * Converts schema properties to camelCase during validation. * This is a wrapper around VineObject that automatically converts * property names from snake_case to camelCase in the output. * * @template Schema - The underlying VineObject schema type * * @example * const schema = vine.object({ * first_name: vine.string(), * last_name: vine.string() * }).camelCase() * * // Output will have: { firstName: string, lastName: string } */ export declare class VineCamelCaseObject> extends BaseType { #private; /** * Unique name identifier for union type resolution */ [UNIQUE_NAME]: string; /** * Type checker function to determine if a value is an object. * Required for "unionOfTypes" functionality. * * @param value - The value to check * @returns True if the value is a non-null object and not an array */ [IS_OF_TYPE]: (value: unknown) => boolean; /** * Creates a new VineCamelCaseObject instance wrapping the given schema. * * @param schema - The VineObject schema to wrap with camelCase conversion */ constructor(schema: Schema); /** * Clone object with camelCase conversion preserved. * * @returns A cloned instance of this VineCamelCaseObject schema */ clone(): this; /** * Converts the object schema to JSON Schema format. * * @returns JSON Schema representation of this object */ toJSONSchema(): JSONSchema7; /** * Compiles the schema type to a compiler node with camelCase enabled. * * @param propertyName - Name of the property being compiled * @param refs - Reference store for the compiler * @param options - Parser options * @returns Compiled object node with camelCase conversion */ [PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): ObjectNode; } /** * VineObject represents an object value in the validation schema. * It validates objects with predefined properties, supports conditional * groups, and provides control over unknown properties. * * @template Properties - Record of property names to their schema types * @template Input - The expected input type for this object * @template Output - The output type after validation and transformation * @template CamelCaseOutput - The output type with camelCase property names * * @example * const schema = vine.object({ * name: vine.string(), * email: vine.string().email(), * age: vine.number().min(0) * }) * * const result = await vine.validate({ * schema, * data: { name: 'John', email: 'john@example.com', age: 30 } * }) */ export declare class VineObject, Input, Output, CamelCaseOutput> extends BaseType implements WithJSONSchema { #private; /** * Unique name identifier for union type resolution */ [UNIQUE_NAME]: string; /** * Type checker function to determine if a value is an object. * Required for "unionOfTypes" functionality. * * @param value - The value to check * @returns True if the value is a non-null object and not an array */ [IS_OF_TYPE]: (value: unknown) => boolean; /** * Creates a new VineObject instance with property schemas and optional configuration. * * @param properties - Record of property names to their validation schemas * @param options - Field options like bail mode and nullability * @param validations - Initial set of validations to apply * @throws Error if properties is not provided */ constructor(properties: Properties, options?: FieldOptions, validations?: Validation[]); /** * Returns a cloned copy of all object properties with their validation schemas. * Note: Object groups are not included to keep implementations simple. * * @returns Cloned properties record * * @example * const properties = schema.getProperties() */ getProperties(): Properties; /** * Returns a cloned subset of object properties containing only the specified keys. * * @param keys - Array of property keys to include * @returns Picked properties record * * @example * const userSchema = vine.object({ * name: vine.string(), * email: vine.string().email(), * password: vine.string() * }) * * const publicFields = userSchema.pick(['name', 'email']) */ pick(keys: Keys[] | readonly Keys[]): Pick; /** * Returns a cloned copy of object properties excluding the specified keys. * * @param keys - Array of property keys to exclude * @returns Omitted properties record * * @example * const userSchema = vine.object({ * name: vine.string(), * email: vine.string().email(), * password: vine.string() * }) * * const withoutPassword = userSchema.omit(['password']) */ omit(keys: Keys[] | readonly Keys[]): Omit; /** * Allows unknown properties to pass through validation and be included in the output. * By default, objects with properties not defined in the schema will fail validation. * * @returns This object schema with unknown properties allowed * * @example * const schema = vine.object({ * name: vine.string() * }).allowUnknownProperties() * * // Now { name: 'John', extra: 'value' } will pass validation */ allowUnknownProperties(): VineObject; /** * Merges conditional property groups into the object schema. Groups allow * adding properties dynamically based on runtime conditions. * * @param group - The conditional group to merge * @returns This object schema with the group merged * * @example * const schema = vine.object({ * type: vine.string() * }).merge( * vine.group([ * vine.group.if('type', 'user', { name: vine.string() }), * vine.group.if('type', 'admin', { permissions: vine.array(vine.string()) }) * ]) * ) */ merge>>(group: Group): VineObject; /** * Clones the VineObject schema including all properties, validations, groups, and options. * * @returns A cloned instance of this VineObject schema */ clone(): this; /** * Converts object property names to camelCase in the validation output. * Useful when accepting snake_case input but wanting camelCase output. * * @returns A VineCamelCaseObject wrapper for this schema * * @example * const schema = vine.object({ * first_name: vine.string(), * last_name: vine.string() * }).toCamelCase() * * // Output: { firstName: string, lastName: string } */ toCamelCase(): VineCamelCaseObject; /** * Converts the object schema to JSON Schema format. * * @returns JSON Schema representation of this object */ toJSONSchema(): JSONSchema7; /** * Creates a new object schema with all properties (or specified properties) marked as optional. * This is useful for update/PATCH operations where not all fields are required. * * @param keys - Optional array of property keys to make optional. If omitted, all properties become optional. * @returns A new VineObject schema with optional properties * * @example * // Make all properties optional * const updateSchema = createSchema.partial() * * @example * // Make only specific properties optional * const userSchema = vine.object({ * name: vine.string(), * email: vine.string().email(), * age: vine.number() * }) * * const updateUserSchema = userSchema.partial(['name', 'age']) * // email remains required, name and age become optional */ partial = Omit & PropertiesToOptional>>(keys?: Keys[] | readonly Keys[]): VineObject, UndefinedOptional<{ [K in keyof T]: T[K][typeof ITYPE]; }>, UndefinedOptional<{ [K in keyof T]: T[K][typeof OTYPE]; }>, UndefinedOptional<{ [K in keyof T as CamelCase]: T[K][typeof COTYPE]; }>>; /** * Compiles the schema type to a compiler node for validation. * * @param propertyName - Name of the property being compiled * @param refs - Reference store for the compiler * @param options - Parser options * @returns Compiled object node for validation */ [PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): ObjectNode; }