# `ExGAM.Domain.Projection.Store`
[🔗](https://github.com/elchemista/ex_gam/blob/0.1.0/lib/ex_gam/domain/projection/store.ex#L1)

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.

# `change`

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

# `config`

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

# `cursor`

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

# `handle`

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

# `head`

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

# `key`

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

# `page`

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

# `commit`

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

```elixir
@callback fetch(handle(), cursor(), [key()], keyword()) ::
  {:ok, %{optional(key()) =&gt; binary()}} | {:error, term()}
```

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

# `head`

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

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

# `open`

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

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

# `page`

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

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

# `select`

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

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

# `commit`

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

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

# `fetch`

```elixir
@spec fetch(config(), handle(), cursor(), [key()]) ::
  {:ok, %{optional(key()) =&gt; binary()}} | {:error, term()}
```

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

# `head`

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

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

# `open`

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

Creates a fresh generation through the configured projection adapter.

# `page`

```elixir
@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 `c:select/5` callback. A `nil` cursor in the reply marks the last page.

---

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