# `Spectre.GAM.Ledger.Store`
[🔗](https://github.com/elchemista/spectre/blob/0.4.0/lib/spectre/gam/ledger/store.ex#L1)

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.

# `batch_id`

```elixir
@type batch_id() :: Spectre.GAM.Ledger.batch_id()
```

# `config`

```elixir
@type config() :: module() | {module(), keyword()}
```

# `domain_ref`

```elixir
@type domain_ref() :: Spectre.GAM.Ledger.domain_ref()
```

# `append`

```elixir
@callback append(domain_ref(), batch_id(), [map()], non_neg_integer(), keyword()) ::
  {:ok, non_neg_integer()}
  | {:error, :conflict}
  | {:error, :ambiguous}
  | {:error, term()}
```

# `export`

```elixir
@callback export(
  domain_ref(),
  keyword()
) :: :not_found | {:ok, map()} | {:error, term()}
```

# `head`
*optional* 

```elixir
@callback head(
  domain_ref(),
  keyword()
) :: :not_found | {:ok, Spectre.GAM.Ledger.cursor()} | {:error, term()}
```

Captures the committed head without loading historical entries.

# `load`

```elixir
@callback load(
  domain_ref(),
  keyword()
) :: :not_found | {:ok, Spectre.GAM.Ledger.snapshot()} | {:error, term()}
```

# `load_from`
*optional* 

```elixir
@callback load_from(domain_ref(), non_neg_integer(), keyword()) ::
  :not_found | {:ok, Spectre.GAM.Ledger.snapshot()} | {:error, term()}
```

# `lookup_batch`

```elixir
@callback lookup_batch(domain_ref(), batch_id(), keyword()) ::
  :not_found | {:ok, Spectre.GAM.Ledger.batch_info()} | {:error, term()}
```

# `read_batch`
*optional* 

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

# `batch_reads?`

```elixir
@spec batch_reads?(config()) :: boolean()
```

Whether an adapter implements native batch paging and a lightweight head read.

# `head`

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

# `load_from`

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

# `normalize`

```elixir
@spec normalize(config()) :: {:ok, {module(), keyword()}} | {:error, term()}
```

Normalizes a Store module or `{module, options}` pair.

# `read_batch`

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

---

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