Chronicle.Constraints (chronicle v0.0.1)

Copy Markdown View Source

Registers event constraints with a Chronicle event store.

Constraints enforce invariants on the event log. The most common constraint is a unique constraint — ensuring that no two events of the same type share the same property value within the same event store.

Registering a unique constraint

alias Chronicle.Constraints

{:ok, channel} = Chronicle.Connections.Connection.channel(:my_conn)
Constraints.register(channel, "my-store", [
  %{
    name: "unique-email",
    type: :unique,
    event_type_id: "user-registered-v1",
    on: ["Email"]
  }
])

Constraints are typically registered as part of event type registration during client startup via Chronicle.Client.

Summary

Functions

Registers a list of constraint definitions with Chronicle.

Functions

register(channel, event_store, constraints)

@spec register(term(), String.t(), [map()]) :: :ok | {:error, term()}

Registers a list of constraint definitions with Chronicle.

Each constraint map supports:

  • :name(required) a unique constraint name
  • :type(required) :unique or :unique_event_type
  • :event_type_id — the event type ID string this constraint applies to
  • :on — list of property path strings to check for uniqueness

Returns :ok or {:error, reason}.