Chronicle.EventSequences.EventSequence (cratis_chronicle v2.2.0)

Copy Markdown View Source

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.

Summary

Functions

Appends a single event to the event sequence.

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

Appends multiple events to the event sequence.

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

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

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

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

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

Gets the tail sequence number for the event sequence.

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

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

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

Redacts a single event at a specific sequence number.

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

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

Types

t()

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

Functions

append(event_sequence, event_source_id, event, opts \\ [])

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

Appends a single event to the event sequence.

append_and_wait_for_completion(event_sequence, event_source_id, event, opts \\ [])

@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(event_sequence, event_source_id, events, opts \\ [])

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

Appends multiple events to the event sequence.

append_many_for_event_sources(event_sequence, events, opts \\ [])

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

complete_stream(event_sequence, event_stream_type, event_stream_id, opts \\ [])

@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(event_sequence, event_source_id, opts \\ [])

@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(event_sequence, sequence_number, opts \\ [])

@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_next_sequence_number(event_sequence, event_source_id \\ nil, opts \\ [])

@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(event_sequence, event_source_id \\ nil, opts \\ [])

@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(event_sequence, observer_module, opts \\ [])

@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?(event_sequence, event_source_id, opts \\ [])

@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(id, opts \\ [])

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

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

redact(event_sequence, sequence_number, reason, opts \\ [])

@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(event_sequence, event_source_id, reason, event_types \\ [], opts \\ [])

@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(event_sequence)

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