Skip to content

Value Validation

Syntax

command <Name> {
<fieldName>: <TypeName>
validate <expression>
else "<error message>"
}

Behavior

validate constraints are checked at command construction time. A command cannot be created if any constraint fails. All constraints run to completion — failures are collected, not short-circuited.

command AddItem {
cartId: CartId
quantity: Quantity
validate quantity > 0
else "Quantity must be positive"
validate quantity <= 99
else "Maximum 99 items per product"
}

If both constraints fail, both error messages are returned. This gives callers a complete picture of what is wrong.

Public constructors

A command with no validate clauses has a public constructor. The compiler does not add a Result wrapper in that case.

The code generator produces Smart Constructors from validate constraints: a private constructor paired with a create() factory returning Result<Command, ValidationError[]>. Invalid commands cannot be instantiated directly.

Contrast with require

validaterequire
Checked atCommand constructiondecide invocation
State accessNoYes
Short-circuitNo — all runYes — first failure stops
Failure typeValidationError[]RejectionError

validate is state-independent. It cannot reference the current state of a decider. Use require for state-dependent conditions.

Architecture decisions