Spectre.GAM.Domain.Projection.Store behaviour (Spectre v0.4.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

Types

change()

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

config()

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

cursor()

@type cursor() :: Spectre.GAM.Ledger.cursor()

handle()

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

key()

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

Callbacks

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

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

fetch(handle, cursor, list, keyword)

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

head(t, keyword)

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

open(t, keyword)

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

page(handle, cursor, atom, keyword)

@callback page(handle(), cursor(), atom(), keyword()) ::
  {:ok, [{key(), binary()}], term() | nil} | {:error, term()}

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

@callback select(handle(), cursor(), atom(), keyword(), keyword()) ::
  {:ok, [{key(), binary()}], term() | nil} | {:error, term()}

Functions

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

fetch(config, handle, cursor, keys)

head(config, domain)

open(config, domain)

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