# `Spectre.Definition.Store`
[🔗](https://github.com/elchemista/spectre/blob/0.4.0/lib/spectre/definition/store.ex#L1)

Immutable persistence boundary for canonical Definitions and Manifest V2.

Adapters store one opaque canonical artifact per `Definition.Ref`. Core owns
artifact encoding, publication receipts, integrity verification, parent
checks, and idempotency read-back. An adapter must never replace different
bytes under an existing key.

A configured `Spectre.Instance.CheckpointStore` is a durable boundary. Such a
runtime may use only a Definition Store whose `durability/1` returns
`:durable`; the bundled in-memory store is intentionally `:volatile`.

# `artifact`

```elixir
@type artifact() :: %{
  definition: Spectre.Definition.Canonical.t(),
  manifest: Spectre.Definition.Manifest.t(),
  receipt: receipt()
}
```

# `config`

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

# `durability`

```elixir
@type durability() :: :volatile | :durable
```

# `receipt`

```elixir
@type receipt() :: %{
  schema_version: pos_integer(),
  publication_id: String.t(),
  definition_ref: String.t(),
  manifest_digest: String.t(),
  store_id: term(),
  durability: durability()
}
```

# `durability`

```elixir
@callback durability(keyword()) :: durability()
```

# `get`

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

# `identity`

```elixir
@callback identity(keyword()) :: term()
```

# `put`

```elixir
@callback put(String.t(), binary(), keyword()) ::
  :ok | {:ok, :created | :existing} | {:error, term()}
```

# `artifact_schema_version`

```elixir
@spec artifact_schema_version() :: pos_integer()
```

Returns the publication artifact schema version.

# `candidate_artifact_schema_version`

```elixir
@spec candidate_artifact_schema_version() :: pos_integer()
```

Returns the immutable Candidate artifact schema version.

# `durability`

```elixir
@spec durability(config()) :: {:ok, durability()} | {:error, term()}
```

Returns the adapter's declared durability after validating its callbacks.

# `fetch`

```elixir
@spec fetch(config(), Spectre.Definition.Ref.t() | String.t(), keyword()) ::
  :not_found | {:ok, artifact()} | {:error, term()}
```

Fetches and fully verifies one published artifact.

Verification covers the lookup key, canonical Definition Ref, Manifest
digest/binding, publication receipt, and current component registry.

# `fetch_candidate`

```elixir
@spec fetch_candidate(
  config(),
  Spectre.Definition.Candidate.Ref.t() | String.t(),
  keyword()
) ::
  :not_found | {:ok, Spectre.Definition.Candidate.t()} | {:error, term()}
```

Re-reads and verifies a Candidate, its bound Definition, and governance receipts.

Supplying an in-memory Candidate struct is never an activation authority;
callers must pass the returned Ref to this function or to
`Spectre.Instance.activate/3`.

# `fetch_gate_receipt`

```elixir
@spec fetch_gate_receipt(
  config(),
  Spectre.Gate.Receipt.Ref.t() | String.t(),
  keyword()
) ::
  :not_found | {:ok, Spectre.Gate.Receipt.t()} | {:error, term()}
```

Re-reads and verifies a governance gate receipt by content Ref.

# `gate_receipt_artifact_schema_version`

```elixir
@spec gate_receipt_artifact_schema_version() :: pos_integer()
```

Returns the immutable gate-receipt artifact schema version.

# `identity`

```elixir
@spec identity(config()) :: {:ok, term()} | {:error, term()}
```

Returns the portable logical identity of the configured Store.

# `normalize`

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

Normalizes a Store module or `{module, opts}` configuration.

# `publish`

```elixir
@spec publish(
  config(),
  Spectre.Definition.Canonical.t(),
  Spectre.Definition.Manifest.t(),
  keyword()
) ::
  {:ok, receipt()} | {:error, term()}
```

Atomically publishes Definition bytes, Manifest bytes, and a core receipt.

Parent Definitions must already resolve. A successful adapter write is read
back and compared byte-for-byte before the publication receipt is returned.
Publishing the same artifact twice is idempotent; different bytes under the
same Ref are an immutable conflict.

# `publish_candidate`

```elixir
@spec publish_candidate(config(), Spectre.Definition.Candidate.t(), keyword()) ::
  {:ok, Spectre.Definition.Candidate.Ref.t()} | {:error, term()}
```

Publishes one immutable bootstrap or governed Candidate after re-reading its Definition.

The Candidate is stored under its content-addressed `Candidate.Ref`. Its
Manifest digest and publication id must match the verified Definition
artifact already present in the same trusted Store.

# `publish_gate_receipt`

```elixir
@spec publish_gate_receipt(config(), Spectre.Gate.Receipt.t(), keyword()) ::
  {:ok, Spectre.Gate.Receipt.Ref.t()} | {:error, term()}
```

Publishes one immutable governance gate receipt.

# `receipt_schema_version`

```elixir
@spec receipt_schema_version() :: pos_integer()
```

Returns the publication receipt schema version.

# `validate_durability_pair`

```elixir
@spec validate_durability_pair(Spectre.Instance.CheckpointStore.config(), config()) ::
  :ok | {:error, term()}
```

Rejects a durable Checkpoint Store paired with a volatile Definition Store.

---

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