Policies & Rules
A policy names a coherent validation concern. Rules inside the policy describe valid model state; execution remains separate.
Policy composition
Prefer several focused policies over one application-wide policy. A checkout flow may have PersonalInfo, ShippingAddress, and BillingAddress policies that can run independently or as one policy group.
Built-in rules
The fluent validator supports common checks such as required values, email shape, numeric values, ranges, dates, regular expressions, and checked states. Rules return the success sentinel or a structured validation failure.
v.validateFor('seatCount')
.isRequired('Seat count is required')
.isNumber('Seat count must be numeric')
.range('Choose between 1 and 500 seats', 1, 500, 'number');
Conditional rules
Pass a dependency when a field should be validated only for a particular model state. Keep the dependency deterministic: it may run more than once during required-state and validation evaluation.
Rule execution
- Resolve the registered policy by name.
- Evaluate active validators for the model or requested property.
- Wait for synchronous and asynchronous results.
- Replace failures for the evaluated paths.
- Update required and group state when requested.
- Notify refresh subscribers.
Result shape
{
propertyName: 'email',
error: { message: 'Enter a valid email address' }
}
Applications remain responsible for deciding when to display, persist, or clear these results.