@vinejs/vine - v4.2.0
    Preparing search index...

    Class VineRecord<Schema>

    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.

    const schema = vine.record(vine.number())

    const result = await vine.validate({
    schema,
    data: { a: 1, b: 2, c: 3 }
    })
    // Record with complex value types
    const schema = vine.record(
    vine.object({
    name: vine.string(),
    age: vine.number()
    })
    )

    Type Parameters

    • Schema extends SchemaTypes

      The schema type for validating all record values

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    "[ITYPE]": { [K: string]: Schema[typeof ITYPE] }

    Define the input type of the schema for TypeScript inference

    "[OTYPE]": { [K: string]: Schema[typeof OTYPE] }

    The output value type of the field after validation. The property points to a type only and not the real value.

    "[COTYPE]": { [K: string]: Schema[typeof COTYPE] }

    Type marker for camelCase output type inference

    rules: {
        maxLength: (
            ...options: [options: { max: number }],
        ) => Validation<{ max: number }>;
        minLength: (
            ...options: [options: { min: number }],
        ) => Validation<{ min: number }>;
        fixedLength: (
            ...options: [options: { size: number }],
        ) => Validation<{ size: number }>;
        validateKeys: (
            ...options: [options: (keys: string[], field: FieldContext) => void],
        ) => Validation<(keys: string[], field: FieldContext) => void>;
    } = ...

    Static collection of all available validation rules for records

    "[UNIQUE_NAME]": string = 'vine.object'

    Unique name identifier for union type resolution

    Methods

    • 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.

      Parameters

      • callback: ParseFn

        Parser function to transform the input value

      Returns this

      This schema instance for method chaining

      vine.string().parse((value) => {
      return typeof value === 'string' ? value.trim() : value
      })
    • Type checker function to determine if a value is an object. Required for "unionOfTypes" functionality.

      Parameters

      • value: unknown

        The value to check

      Returns boolean

      True if the value is a non-null object and not an array

    • Register a custom callback to validate the record's keys. Useful for enforcing key naming patterns or checking key existence.

      Parameters

      • ...args: [options: (keys: string[], field: FieldContext) => void]

        Arguments to pass to the validateKeys rule

      Returns VineRecord<Schema>

      This record schema instance for method chaining

      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)
      }
      })
    • Clones the VineRecord schema including the value schema, options, and validations.

      Returns this

      A cloned instance of this VineRecord schema

    • Compiles the record schema to a compiler node for validation.

      Parameters

      • propertyName: string

        Name of the property being compiled

      • refs: RefsStore

        Reference store for the compiler

      • options: ParserOptions

        Parser options

      Returns RecordNode

      Compiled record node for validation