import { type RefsStore, type RecordNode } from '@vinejs/compiler/types'; import { BaseType } from '../base/main.js'; import { type ITYPE, type OTYPE, type COTYPE, PARSE, UNIQUE_NAME, IS_OF_TYPE } from '../../symbols.js'; import type { FieldOptions, ParserOptions, SchemaTypes, Validation, WithJSONSchema } from '../../types.js'; import { validateKeysRule } from './rules.js'; /** * VineRecord represents an object with dynamic keys where all values share the same schema. * Unlike VineObject which has predefined properties, records allow any string key * but enforce consistent value types across all keys. * * @template Schema - The schema type for validating all record values * * @example * const schema = vine.record(vine.number()) * * const result = await vine.validate({ * schema, * data: { a: 1, b: 2, c: 3 } * }) * * @example * // Record with complex value types * const schema = vine.record( * vine.object({ * name: vine.string(), * age: vine.number() * }) * ) */ export declare class VineRecord extends BaseType<{ [K: string]: Schema[typeof ITYPE]; }, { [K: string]: Schema[typeof OTYPE]; }, { [K: string]: Schema[typeof COTYPE]; }> implements WithJSONSchema { #private; /** * Static collection of all available validation rules for records */ static rules: { maxLength: (options: { max: number; }) => Validation<{ max: number; }>; minLength: (options: { min: number; }) => Validation<{ min: number; }>; fixedLength: (options: { size: number; }) => Validation<{ size: number; }>; validateKeys: (options: (keys: string[], field: import("@vinejs/compiler/types").FieldContext) => void) => Validation<(keys: string[], field: import("@vinejs/compiler/types").FieldContext) => void>; }; /** * 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 VineRecord instance with value schema and optional configuration. * * @param schema - The schema to validate each record value * @param options - Field options like bail mode and nullability * @param validations - Initial set of validations to apply */ constructor(schema: Schema, options?: FieldOptions, validations?: Validation[]); /** * Enforce a minimum number of properties on the record. * * @param expectedLength - The minimum required number of key-value pairs * @returns This record schema instance for method chaining */ minLength(expectedLength: number): this; /** * Enforce a maximum number of properties on the record. * * @param expectedLength - The maximum allowed number of key-value pairs * @returns This record schema instance for method chaining */ maxLength(expectedLength: number): this; /** * Enforce an exact number of properties on the record. * * @param expectedLength - The exact required number of key-value pairs * @returns This record schema instance for method chaining */ fixedLength(expectedLength: number): this; /** * Register a custom callback to validate the record's keys. * Useful for enforcing key naming patterns or checking key existence. * * @param args - Arguments to pass to the validateKeys rule * @returns This record schema instance for method chaining * * @example * vine.record(vine.string()).validateKeys((keys, field) => { * if (!keys.every(key => /^[a-z_]+$/.test(key))) { * field.report('Keys must be lowercase with underscores', 'invalidKeys', field) * } * }) */ validateKeys(...args: Parameters): this; /** * Clones the VineRecord schema including the value schema, options, and validations. * * @returns A cloned instance of this VineRecord schema */ clone(): this; /** * Converts the record schema to JSON Schema format. * * @returns JSON Schema representation of this record */ toJSONSchema(): { type: "object"; additionalProperties: {}; }; /** * Compiles the record schema 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 record node for validation */ [PARSE](propertyName: string, refs: RefsStore, options: ParserOptions): RecordNode; }