# `Chronicle.Constraints`
[🔗](https://github.com/Cratis/Chronicle.Elixir/blob/main/lib/chronicle/constraints.ex#L4)

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`.

# `register`

```elixir
@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}`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
