# `Chronicle.EventSequences.EventSequence`
[🔗](https://github.com/Cratis/Chronicle.Elixir/blob/main/lib/chronicle/event_sequences/event_sequence.ex#L4)

Represents a Chronicle event sequence.

Use this module when you want to work with a non-default event sequence and keep
the event sequence identifier close to the append/query operations.

# `t`

```elixir
@type t() :: %Chronicle.EventSequences.EventSequence{id: String.t(), opts: keyword()}
```

# `append`

```elixir
@spec append(t(), String.t(), struct(), keyword()) :: :ok | {:error, term()}
```

Appends a single event to the event sequence.

# `append_and_wait_for_completion`

```elixir
@spec append_and_wait_for_completion(t(), String.t(), struct(), keyword()) ::
  {:ok, %{success: boolean(), failed_partitions: list()}} | {:error, term()}
```

Appends a single event, then waits for every observer affected by the append
to either reach the appended sequence number or fail.

# `append_many`

```elixir
@spec append_many(t(), String.t(), [struct()], keyword()) :: :ok | {:error, term()}
```

Appends multiple events to the event sequence.

# `append_many_for_event_sources`

```elixir
@spec append_many_for_event_sources(
  t(),
  [Chronicle.EventSequences.EventForEventSourceId.t()],
  keyword()
) :: :ok | {:error, term()}
```

Appends a list of `Chronicle.EventSequences.EventForEventSourceId` entries as a
single atomic append-many, each carrying its own target event source id.

# `append_many_with_result`

```elixir
@spec append_many_with_result(t(), String.t(), [struct()], keyword()) ::
  {:ok, Chronicle.EventSequences.AppendResult.t()} | {:error, term()}
```

Appends events atomically and returns the detailed `Chronicle.EventSequences.AppendResult`.

# `append_prepared`

```elixir
@spec append_prepared(
  t(),
  String.t(),
  Chronicle.EventSequences.PreparedEvent.t(),
  keyword()
) ::
  :ok | {:error, term()}
```

Appends a `prepare/3`d event. See `Chronicle.EventSequences.EventLog.append_prepared/3`.

# `append_with_result`

```elixir
@spec append_with_result(t(), String.t(), struct(), keyword()) ::
  {:ok, Chronicle.EventSequences.AppendResult.t()} | {:error, term()}
```

Appends a single event and returns the detailed `Chronicle.EventSequences.AppendResult`.

# `complete_stream`

```elixir
@spec complete_stream(t(), String.t(), String.t(), keyword()) ::
  {:ok, non_neg_integer()}
  | {:error, :default_stream_cannot_be_completed | :already_completed | term()}
```

Completes a named, non-default stream so that no further events can be
appended to it.

# `get_for_event_source`

```elixir
@spec get_for_event_source(t(), String.t(), keyword()) ::
  {:ok, list()} | {:error, term()}
```

Gets events for the given event source from the event sequence.

# `get_from_sequence_number`

```elixir
@spec get_from_sequence_number(t(), non_neg_integer(), keyword()) ::
  {:ok, list()} | {:error, term()}
```

Gets events from (and including) the given sequence number onward.

# `get_metadata`

```elixir
@spec get_metadata(t(), [non_neg_integer()], keyword()) ::
  {:ok, [map()]} | {:error, term()}
```

Reads the metadata of events by sequence number. See `Chronicle.EventSequences.Streams.get_metadata/2`.

# `get_metadata_at`

```elixir
@spec get_metadata_at(t(), non_neg_integer(), keyword()) ::
  {:ok, map()} | {:error, term()}
```

Reads the metadata of a single event by sequence number. See
`Chronicle.EventSequences.Streams.get_metadata_at/2`.

# `get_next_sequence_number`

```elixir
@spec get_next_sequence_number(t(), String.t() | nil, keyword()) ::
  {:ok, non_neg_integer()} | {:error, term()}
```

Gets the sequence number that will be assigned to the next appended event.

# `get_tail_sequence_number`

```elixir
@spec get_tail_sequence_number(t(), String.t() | nil, keyword()) ::
  {:ok, non_neg_integer()} | {:error, term()}
```

Gets the tail sequence number for the event sequence.

# `get_tail_sequence_number_for_observer`

```elixir
@spec get_tail_sequence_number_for_observer(t(), module(), keyword()) ::
  {:ok, non_neg_integer()} | {:error, term()}
```

Gets the tail sequence number scoped to only the event types the given
reactor or reducer module subscribes to.

# `has_events_for?`

```elixir
@spec has_events_for?(t(), String.t(), keyword()) ::
  {:ok, boolean()} | {:error, term()}
```

Checks whether the event sequence has events for the given event source id.

# `new`

```elixir
@spec new(String.t(), keyword()) :: t()
```

Creates an event sequence wrapper for the given event sequence id.

# `prepare`

```elixir
@spec prepare(t(), struct(), keyword()) ::
  {:ok, Chronicle.EventSequences.PreparedEvent.t()} | {:error, term()}
```

Serializes `event` once and returns a `Chronicle.EventSequences.PreparedEvent` bound to this
event sequence. See `Chronicle.EventSequences.EventLog.prepare/2`.

# `redact`

```elixir
@spec redact(t(), non_neg_integer(), String.t(), keyword()) :: :ok | {:error, term()}
```

Redacts a single event at a specific sequence number.

# `redact_for_event_source`

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

Redacts all events for a given event source, optionally filtered to
specific event types.

# `transactional`

```elixir
@spec transactional(t()) :: Chronicle.EventSequences.TransactionalEventSequence.t()
```

Gets a transactional view of the event sequence that buffers appends in the current unit of work.

# `verify_content`

```elixir
@spec verify_content(
  t(),
  non_neg_integer(),
  struct() | Chronicle.EventSequences.PreparedEvent.t(),
  keyword()
) :: {:ok, :equal | :different | :unavailable} | {:error, term()}
```

Verifies that `event` is what was stored at `sequence_number`. See
`Chronicle.EventSequences.Streams.verify_content/3`.

---

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