Chain class

Internal accumulator for a builder chain.

This class manages the complex pipeline of validators and transformations in the builder pattern. The chain supports at most one type-changing transformer (coercion) to maintain predictable behavior.

Pipeline Structure:

  1. Prefix transformers (value pivots like pluckValue, pick keys) - applied first
  2. Pre-coercion validators - validate the original type
  3. Coercion transformer - changes the type (optional, at most one)
  4. Post-coercion validators - validate the coerced type

Coercion Rules:

  • Only one coercion is allowed per chain
  • Pre-coercion validators are discarded when coercion is applied (they target the old type)
  • If multiple coercions are attempted, they are composed or the later one replaces the earlier
  • Custom coercions can be composed with built-in ones

Example chain flow:

// Original: {"user": {"name": "Alice", "age": "25"}}
pluckValue("user")           // -> {"name": "Alice", "age": "25"}
.isMap()                     // pre-coercion validation
.toInt("age")                // coercion: String -> int
.gt(0)                       // post-coercion validation

Constructors

Chain()

Properties

coercedToBool → bool
no setter
coercedToDateTime → bool
no setter
coercedToDouble → bool
no setter
coercedToInt → bool
no setter
coercedToJson → bool
no setter
coercedToString → bool
no setter
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

add(IValidator v) → void
Adds a validator to the appropriate position in the chain. Pre-coercion validators go before coercion, post-coercion validators go after.
addPrefix(IValidator prefix(IValidator child)) → void
Adds a prefix value-mapping validator that runs before coercion and post-validators. Used for operations like pluckValue that extract values from containers.
build() → IValidator
Builds the final validator by composing all chain elements in the correct order.
copyWith() → Chain
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setTransform(CoercionKind kind, IValidator transformer(IValidator child), {bool dropPre = true}) → void
Sets a type coercion transformer with optional pre-validator preservation.
toString() → String
A string representation of this object.
inherited
wrap(IValidator fn(IValidator child)) → void
Wraps all validators at the current position with a wrapper function.

Operators

operator ==(Object other) → bool
The equality operator.
inherited