Spectre.Definition.ContractRegistry (Spectre v0.3.0)

Copy Markdown View Source

Trusted registry of component contracts understood by this runtime.

Canonical Definitions carry schema Refs, never validator modules. The host constructs this registry from reviewed code and the resolver rejects every unknown :must_understand component. Unknown advisory or descriptive components remain opaque and are preserved in the Manifest snapshot.

Summary

Functions

Returns the registry understood by the current Spectre release.

Fetches a registered contract by its exact schema Ref.

Builds a registry from trusted component contract entries.

Builds a registry or raises with its stable validation reason.

Registers one reviewed component contract.

Returns the exact contract interpretation sealed into a Manifest.

Validates all understood components and fail-closes unknown critical semantics.

Verifies that the current registry interprets a Definition exactly as published.

Types

entry()

@type entry() :: %{
  component_type: atom() | String.t(),
  schema_ref: String.t(),
  criticalities: [Spectre.Definition.Component.criticality()],
  version: pos_integer(),
  validator: validator()
}

t()

@type t() :: %Spectre.Definition.ContractRegistry{
  entries: %{optional(String.t()) => entry()}
}

validator()

@type validator() :: {module(), atom()} | nil

Functions

default()

@spec default() :: t()

Returns the registry understood by the current Spectre release.

fetch(contract_registry, schema_ref)

@spec fetch(t(), String.t()) :: {:ok, entry()} | :error

Fetches a registered contract by its exact schema Ref.

new(entries)

@spec new([map() | keyword()]) :: {:ok, t()} | {:error, term()}

Builds a registry from trusted component contract entries.

new!(entries)

@spec new!([map() | keyword()]) :: t()

Builds a registry or raises with its stable validation reason.

register(registry, attrs)

@spec register(t(), map() | keyword()) :: {:ok, t()} | {:error, term()}

Registers one reviewed component contract.

snapshot(registry, canonical)

@spec snapshot(t(), Spectre.Definition.Canonical.t()) ::
  {:ok, [map()]} | {:error, term()}

Returns the exact contract interpretation sealed into a Manifest.

validate(registry, canonical)

@spec validate(t(), Spectre.Definition.Canonical.t()) :: :ok | {:error, term()}

Validates all understood components and fail-closes unknown critical semantics.

verify_snapshot(registry, canonical, expected)

@spec verify_snapshot(t(), Spectre.Definition.Canonical.t(), [map()]) ::
  :ok | {:error, term()}

Verifies that the current registry interprets a Definition exactly as published.