# `Chronicle.Events.EventTypes`
[🔗](https://github.com/Cratis/Chronicle.Elixir/blob/main/lib/chronicle/events/event_types.ex#L4)

Registers event types with a Chronicle event store.

Called automatically by `Chronicle.Registration.Coordinator` during startup.
You can also call it directly to register event types at runtime.

## Example

    {:ok, channel} = Chronicle.Connections.Connection.channel(:my_conn)

    :ok =
      Chronicle.Events.EventTypes.register(
        channel,
        "my-store",
        [MyApp.Events.AccountOpened],
        [MyApp.Migrations.AccountOpenedV2Migration]
      )

# `register`

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

Registers event type modules and their migrations with Chronicle.

Each event type module must `use Chronicle.Events.EventType`. Chronicle groups all
known generations of the same event type into a single registration, includes
schemas for each known generation, and attaches any registered migrations.

Returns `:ok` on success or `{:error, reason}` on failure.

# `validate`

```elixir
@spec validate([module()], [module()]) :: :ok | {:error, Exception.t()}
```

Validates a set of event type and migration modules without raising.

Returns `{:error, exception}` with a `Chronicle.Events.MultipleEventTypesWithSameIdFound`
struct when several modules represent the same generation of the same event type id, or a
`Chronicle.Events.MultipleMigratorsForSameEventTypeGeneration` struct when more than one
migrator bridges the same pair of generations. Returns `:ok` otherwise.

The client calls this once at startup, before the first connection attempt: a failure is
logged and startup continues, unless the `strict_validation: true` client option is set, in
which case `validate!/2` raises it.

# `validate!`

```elixir
@spec validate!([module()], [module()]) :: :ok
```

Like `validate/2`, but raises the exception instead of returning it.

---

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