ExGAM.Domain.Projection.Store behaviour (ExGAM v0.1.0)

Copy Markdown View Source

Durable, disposable Domain read model beside the canonical ledger.

A generation is rebuilt by a trusted Domain from verified ledger batches. commit/5 atomically applies row changes and advances its exact predecessor cursor. Readers specify that cursor: stale pages are errors, never mixed revisions. A persisted projection is not authenticated by its head digest; cold recovery must rebuild it from the ledger before using it for authority.

Keys are {collection, identity}. Writes receive typed values; adapters encode them through Rows. Reads return canonical bytes, not a serialized process or a full-state snapshot. No PID, timer, capability, execution secret or callback belongs here. Implementations must distinguish absence from storage failure and support indexed bounded reads.

Summary

Callbacks

Applies all changes atomically at the expected generation and cursor, then advances the cursor.

Reads the canonical bytes of existing keys at one exact generation and cursor.

Reads the active generation and its committed cursor, or returns :not_found.

Opens a fresh projection generation for a Domain and fences its earlier generation.

Reads a count- and byte-bounded page of one collection at an exact cursor.

Reads an indexed selection using query options followed by the original adapter options.

Functions

Commits row changes from the supplied predecessor cursor to the new cursor.

Fetches selected rows as canonical bytes at the requested projection cursor.

Reads the projection head for a Domain through its configured adapter.

Creates a fresh generation through the configured projection adapter.

Pages over a collection using :limit, :max_bytes and an opaque :after cursor.

Types

change()

@type change() :: {:put, key(), term()} | {:delete, key()}

config()

@type config() :: {module(), keyword()}

cursor()

@type cursor() :: ExGAM.Ledger.cursor()

handle()

@type handle() :: %{domain: String.t(), generation: String.t()}

head()

@type head() :: %{handle: handle(), cursor: cursor()}

key()

@type key() :: {atom(), term()}

page()

@type page() :: {:ok, [{key(), binary()}], term() | nil} | {:error, term()}

Callbacks

commit(handle, cursor, cursor, t, keyword)

@callback commit(handle(), cursor(), cursor(), Enumerable.t(), keyword()) ::
  :ok | {:error, term()}

Applies all changes atomically at the expected generation and cursor, then advances the cursor.

fetch(handle, cursor, list, keyword)

@callback fetch(handle(), cursor(), [key()], keyword()) ::
  {:ok, %{optional(key()) => binary()}} | {:error, term()}

Reads the canonical bytes of existing keys at one exact generation and cursor.

head(t, keyword)

@callback head(String.t(), keyword()) :: {:ok, head()} | :not_found | {:error, term()}

Reads the active generation and its committed cursor, or returns :not_found.

open(t, keyword)

@callback open(String.t(), keyword()) :: {:ok, handle()} | {:error, term()}

Opens a fresh projection generation for a Domain and fences its earlier generation.

page(handle, cursor, atom, keyword)

@callback page(handle(), cursor(), atom(), keyword()) :: page()

Reads a count- and byte-bounded page of one collection at an exact cursor.

select(handle, cursor, atom, keyword, keyword)

@callback select(handle(), cursor(), atom(), keyword(), keyword()) :: page()

Reads an indexed selection using query options followed by the original adapter options.

Functions

commit(config, handle, before, after_cursor, changes)

@spec commit(config(), handle(), cursor(), cursor(), Enumerable.t()) ::
  :ok | {:error, term()}

Commits row changes from the supplied predecessor cursor to the new cursor.

fetch(config, handle, cursor, keys)

@spec fetch(config(), handle(), cursor(), [key()]) ::
  {:ok, %{optional(key()) => binary()}} | {:error, term()}

Fetches selected rows as canonical bytes at the requested projection cursor.

head(config, domain)

@spec head(config(), String.t()) :: {:ok, head()} | :not_found | {:error, term()}

Reads the projection head for a Domain through its configured adapter.

open(config, domain)

@spec open(config(), String.t()) :: {:ok, handle()} | {:error, term()}

Creates a fresh generation through the configured projection adapter.

page(config, handle, cursor, collection, page_opts \\ [])

@spec page(config(), handle(), cursor(), atom(), keyword()) :: page()

Pages over a collection using :limit, :max_bytes and an opaque :after cursor.

:group, :from, :through and :nearest select indexed queries via the adapter's select/5 callback. A nil cursor in the reply marks the last page.