Constraints
Constraints are shared Chronicle behavior. The shared docs cover constraint concepts, model-bound constraints, declarative constraints, and client-tabbed examples.
Kotlin client: constraint scoping
Section titled “Kotlin client: constraint scoping”IConstraintBuilder (passed into IConstraint.define) can scope every
constraint added through it to a narrower uniqueness dimension than the
whole event store:
| Member | Scopes uniqueness checking per… |
|---|---|
perEventSourceType | Event source type |
perEventStreamType | Event stream type |
perEventStreamId | Event stream id |
Combine any of the three; by default (none called) a constraint is checked globally across the whole event store:
import io.cratis.chronicle.constraints.Constraintimport io.cratis.chronicle.constraints.IConstraintimport io.cratis.chronicle.constraints.IConstraintBuilderimport io.cratis.chronicle.events.EventType
@EventTypedata class ConstraintsBridgeUserRegistered( val userId: String = "", val email: String = "")
@Constraintclass ConstraintsBridgeUniqueEmail : IConstraint { override fun define(builder: IConstraintBuilder) { builder .perEventSourceType() .unique { unique -> unique .on( ConstraintsBridgeUserRegistered::class, ConstraintsBridgeUserRegistered::email ) .withMessage("Email must be unique per event source type.") } }}