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

    Class ObjectGroup<Conditional>

    ObjectGroup represents a collection of conditional property sets that can be merged into an object based on runtime conditions. This enables dynamic schema composition where different properties are validated based on conditional logic.

    const schema = vine.object({
    type: vine.string()
    }).merge(
    vine.group([
    vine.group.if((value) => value.type === 'user', {
    username: vine.string()
    }),
    vine.group.if((value) => value.type === 'admin', {
    permissions: vine.array(vine.string())
    })
    ])
    )

    Type Parameters

    • Conditional extends GroupConditional<any, any, any, any>

      The type of conditional used in this group

    Implements

    Index

    Constructors

    Properties

    "[ITYPE]": Conditional[typeof ITYPE]
    "[OTYPE]": Conditional[typeof OTYPE]
    "[COTYPE]": Conditional[typeof COTYPE]

    Methods

    • Clones the ObjectGroup including all conditionals and the otherwise callback.

      Returns this

      A cloned instance of this ObjectGroup

    • Defines a fallback callback to invoke when none of the group conditions match. By default, this reports a validation error. Use this method to customize the error handling behavior.

      Parameters

      • callback: UnionNoMatchCallback<Record<string, unknown>>

        Callback to invoke when no condition matches

      Returns this

      This group instance for method chaining

      vine.group([
      vine.group.if((value) => value.type === 'user', { username: vine.string() }),
      vine.group.if((value) => value.type === 'admin', { role: vine.string() })
      ]).otherwise((value, field) => {
      field.report('Invalid type specified', 'invalidType', field)
      })
    • Compiles the group to a compiler node for validation.

      Parameters

      • refs: RefsStore

        Reference store for the compiler

      • options: ParserOptions

        Parser options

      Returns ObjectGroupNode

      Compiled object group node