# `Commanded.EventStore.Adapter`
[🔗](https://github.com/commanded/commanded/blob/v1.4.12/lib/commanded/event_store/adapter.ex#L1)

Defines the behaviour to be implemented by an event store adapter to be used by Commanded.

# `adapter_meta`

```elixir
@type adapter_meta() :: map()
```

# `application`

```elixir
@type application() :: Commanded.Application.t()
```

# `config`

```elixir
@type config() :: Keyword.t()
```

# `error`

```elixir
@type error() :: term()
```

# `expected_version`

```elixir
@type expected_version() ::
  :any_version | :no_stream | :stream_exists | non_neg_integer()
```

# `source_uuid`

```elixir
@type source_uuid() :: String.t()
```

# `start_from`

```elixir
@type start_from() :: :origin | :current | integer()
```

# `stream_uuid`

```elixir
@type stream_uuid() :: String.t()
```

# `subscriber`

```elixir
@type subscriber() :: pid()
```

# `subscription`

```elixir
@type subscription() :: any()
```

# `subscription_name`

```elixir
@type subscription_name() :: String.t()
```

# `ack_event`

```elixir
@callback ack_event(adapter_meta(), pid(), Commanded.EventStore.RecordedEvent.t()) :: :ok
```

Acknowledge receipt and successful processing of the given event received from
a subscription to an event stream. Note that if the event is part of a batch,
all events that precede this event in the batch are considered to be acknowledged
as well.

# `append_to_stream`

```elixir
@callback append_to_stream(
  adapter_meta(),
  stream_uuid(),
  expected_version(),
  events :: [Commanded.EventStore.EventData.t()],
  opts :: Keyword.t()
) :: :ok | {:error, :wrong_expected_version} | {:error, error()}
```

Append one or more events to a stream atomically.

# `child_spec`

```elixir
@callback child_spec(application(), config()) ::
  {:ok, [:supervisor.child_spec() | {module(), term()} | module()],
   adapter_meta()}
```

Return a child spec defining all processes required by the event store.

# `delete_snapshot`

```elixir
@callback delete_snapshot(adapter_meta(), source_uuid()) :: :ok | {:error, error()}
```

Delete a previously recorded snapshot for a given source

# `delete_subscription`

```elixir
@callback delete_subscription(adapter_meta(), stream_uuid() | :all, subscription_name()) ::
  :ok | {:error, :subscription_not_found} | {:error, error()}
```

Delete an existing subscription.

# `read_snapshot`

```elixir
@callback read_snapshot(adapter_meta(), source_uuid()) ::
  {:ok, Commanded.EventStore.SnapshotData.t()} | {:error, :snapshot_not_found}
```

Read a snapshot, if available, for a given source.

# `record_snapshot`

```elixir
@callback record_snapshot(adapter_meta(), Commanded.EventStore.SnapshotData.t()) ::
  :ok | {:error, error()}
```

Record a snapshot of the data and metadata for a given source

# `stream_forward`

```elixir
@callback stream_forward(
  adapter_meta(),
  stream_uuid(),
  start_version :: non_neg_integer(),
  read_batch_size :: non_neg_integer()
) :: Enumerable.t() | {:error, :stream_not_found} | {:error, error()}
```

Streams events from the given stream, in the order in which they were
originally written.

# `subscribe`

```elixir
@callback subscribe(adapter_meta(), stream_uuid() | :all) :: :ok | {:error, error()}
```

Create a transient subscription to a single event stream.

The event store will publish any events appended to the given stream to the
`subscriber` process as an `{:events, events}` message.

The subscriber does not need to acknowledge receipt of the events.

# `subscribe_to`

```elixir
@callback subscribe_to(
  adapter_meta(),
  stream_uuid() | :all,
  subscription_name(),
  subscriber(),
  start_from(),
  opts :: Keyword.t()
) ::
  {:ok, subscription()}
  | {:error, :subscription_already_exists}
  | {:error, error()}
```

Create a persistent subscription to an event stream.

# `unsubscribe`

```elixir
@callback unsubscribe(adapter_meta(), subscription()) :: :ok
```

Unsubscribe an existing subscriber from event notifications.

This should not delete the subscription.

---

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