Domain.Relation reference
Relation
Section titled “Relation”Source:
packages/domain/src/Relation.ts
A rule that relates instances of different aggregates, or two instances of
one: a claimed name belongs to a registered customer. It goes in a model’s
relations.
Where a model’s invariants are given every instance and can only be
searched, a relation is about a fixed few, so Verify.model can prove it:
every command and every decision that records on one of its aggregates is
shown to keep it, from any states the model’s rules allow.
Relation: Relating two aggregates
Section titled “Relation: Relating two aggregates”export class Bank extends Domain.Model("Bank", { aggregates: [Customer, UsernameClaim], decisions: [Registration], relations: { AClaimedNameHasACustomer: Domain.Relation({ over: { customer: Customer, claim: UsernameClaim }, holds: ({ customer, claim }) => claim.state._tag !== "Claimed" || claim.state.customerId !== customer.id || customer.state._tag !== "Unregistered", }), },}) {}Relation: What can be proved
Section titled “Relation: What can be proved”A proof is about every single command, so a relation is proved where one
step changes both sides: a decision. One a policy keeps in step is broken
between the event and the policy’s command. It is not proved, and is
checked like the model’s invariants, once nothing is left to react.