Adapter contract and guarded invocation facade for Domain ledgers.
Store adapters must make each batch atomically visible, enforce
expected_revision, and treat an uncertain append acknowledgement as
{:error, :ambiguous}. A successful append may only be returned after the
adapter's advertised durability boundary has acknowledged the batch.
Spectre.GAM.Ledger.Store.Support contains portable shape and option helpers for
adapter authors. It deliberately does not abstract transactions, locks,
encoding, recovery or durability: those guarantees stay visible in each
concrete store.
Summary
Callbacks
Captures the committed head without loading historical entries.
Reads exactly one complete batch beginning at first_revision.
Functions
Whether an adapter implements native batch paging and a lightweight head read.
Reads the advertised head; it does not authenticate a projection checkpoint.
Reads a coherent suffix after a revision, with the captured ledger head.
Normalizes a Store module or {module, options} pair.
Reads one indexed batch; unsupported adapters return an explicit error.
Types
@type batch_id() :: Spectre.GAM.Ledger.batch_id()
@type domain_ref() :: Spectre.GAM.Ledger.domain_ref()
Callbacks
@callback append(domain_ref(), batch_id(), [map()], non_neg_integer(), keyword()) :: {:ok, non_neg_integer()} | {:error, :conflict} | {:error, :ambiguous} | {:error, term()}
@callback export( domain_ref(), keyword() ) :: :not_found | {:ok, map()} | {:error, term()}
@callback head( domain_ref(), keyword() ) :: :not_found | {:ok, Spectre.GAM.Ledger.cursor()} | {:error, term()}
Captures the committed head without loading historical entries.
@callback load( domain_ref(), keyword() ) :: :not_found | {:ok, Spectre.GAM.Ledger.snapshot()} | {:error, term()}
@callback load_from(domain_ref(), non_neg_integer(), keyword()) :: :not_found | {:ok, Spectre.GAM.Ledger.snapshot()} | {:error, term()}
@callback lookup_batch(domain_ref(), batch_id(), keyword()) :: :not_found | {:ok, Spectre.GAM.Ledger.batch_info()} | {:error, term()}
@callback read_batch(domain_ref(), pos_integer(), keyword()) :: :not_found | {:ok, Spectre.GAM.Ledger.snapshot()} | {:error, term()}
Reads exactly one complete batch beginning at first_revision.
This is the paging unit: a batch is already bounded by Entry's admission limits and must never be split across semantic folds. Implementations must use indexed reads, not load the entire ledger and slice it. The returned snapshot describes the batch end, not the current Domain head. Its chain must still be verified against the caller's trusted predecessor.
Functions
Whether an adapter implements native batch paging and a lightweight head read.
@spec head(config(), domain_ref(), keyword()) :: :not_found | {:ok, Spectre.GAM.Ledger.cursor()} | {:error, term()}
Reads the advertised head; it does not authenticate a projection checkpoint.
@spec load_from(config(), domain_ref(), non_neg_integer(), keyword()) :: :not_found | {:ok, Spectre.GAM.Ledger.snapshot()} | {:error, term()}
Reads a coherent suffix after a revision, with the captured ledger head.
Native adapters can use their revision index. Adapters without this optional
callback fall back to a verified full read. The caller must verify the suffix
against its trusted predecessor; use Spectre.GAM.Ledger.load_from/4 for that.
Normalizes a Store module or {module, options} pair.
@spec read_batch(config(), domain_ref(), pos_integer(), keyword()) :: :not_found | {:ok, Spectre.GAM.Ledger.snapshot()} | {:error, term()}
Reads one indexed batch; unsupported adapters return an explicit error.