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
validate | require | |
|---|---|---|
| Checked at | Command construction | decide invocation |
| State access | No | Yes |
| Short-circuit | No — all run | Yes — first failure stops |
| Failure type | ValidationError[] | RejectionError |
validate is state-independent. It cannot reference the current state of a decider. Use require for state-dependent conditions.