Skip to content

Constraints

Constraints are shared Chronicle behavior. The shared docs cover constraint concepts, model-bound constraints, declarative constraints, and client-tabbed examples.

IConstraintBuilder (passed into IConstraint.define) can scope every constraint added through it to a narrower uniqueness dimension than the whole event store:

MemberScopes uniqueness checking per…
perEventSourceTypeEvent source type
perEventStreamTypeEvent stream type
perEventStreamIdEvent 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.Constraint
import io.cratis.chronicle.constraints.IConstraint
import io.cratis.chronicle.constraints.IConstraintBuilder
import io.cratis.chronicle.events.EventType
@EventType
data class ConstraintsBridgeUserRegistered(
val userId: String = "",
val email: String = ""
)
@Constraint
class 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.")
}
}
}