Spectre.Skill.StateBinding (Spectre v0.3.0)

Copy Markdown View Source

Portable, generation-fenced state owned by one stable Skill and Definition.

A binding identifies one branch. Its schema, generation, parent branch and owning Definition are immutable; state updates use revision CAS. Activation may move a retained branch between :active and :dormant, while retention transitions are monotonic and a purged binding keeps only its tombstone.

Summary

Functions

Returns the immutable pointer stored in an Activation snapshot.

Returns true for an Activation Skill-state pointer.

Decodes and verifies portable binding bytes.

Encodes a binding into portable canonical bytes.

Restores portable binding data without creating atoms.

Builds and verifies one Skill-state branch binding.

Builds a binding or raises with its stable validation reason.

Returns the Skill-state binding schema version.

Returns portable canonical data.

Applies a monotonic retention transition and preserves a purged tombstone.

Moves a retained branch between active and dormant with revision CAS.

Updates the active branch state through generation and revision CAS.

Types

retention()

@type retention() :: :retained | :gc_eligible | :abandoned | :purged

status()

@type status() :: :active | :dormant

t()

@type t() :: %Spectre.Skill.StateBinding{
  binding_receipt: String.t(),
  branch_id: String.t(),
  created_at: non_neg_integer(),
  fencing_token: pos_integer(),
  owning_definition_ref: Spectre.Definition.Ref.t(),
  parent_branch_id: String.t() | nil,
  provenance: map(),
  retention: retention(),
  revision: non_neg_integer(),
  schema_version: pos_integer(),
  skill_id: String.t(),
  state: term(),
  state_generation: pos_integer(),
  state_schema_ref: String.t(),
  status: status(),
  updated_at: non_neg_integer()
}

Functions

activation_pointer(binding)

@spec activation_pointer(t()) :: map()

Returns the immutable pointer stored in an Activation snapshot.

activation_pointer?(arg1)

@spec activation_pointer?(term()) :: boolean()

Returns true for an Activation Skill-state pointer.

decode(encoded)

@spec decode(binary()) :: {:ok, t()} | {:error, term()}

Decodes and verifies portable binding bytes.

encode(binding)

@spec encode(t()) :: {:ok, binary()} | {:error, term()}

Encodes a binding into portable canonical bytes.

from_data(value)

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

Restores portable binding data without creating atoms.

new(binding)

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

Builds and verifies one Skill-state branch binding.

new!(attrs)

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

Builds a binding or raises with its stable validation reason.

schema_version()

@spec schema_version() :: pos_integer()

Returns the Skill-state binding schema version.

to_data(binding)

@spec to_data(t()) :: map()

Returns portable canonical data.

transition_retention(binding, retention, opts)

@spec transition_retention(t(), retention(), keyword()) ::
  {:ok, t()} | {:error, term()}

Applies a monotonic retention transition and preserves a purged tombstone.

transition_status(binding, status, opts)

@spec transition_status(t(), status(), keyword()) :: {:ok, t()} | {:error, term()}

Moves a retained branch between active and dormant with revision CAS.

update(binding, state, opts)

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

Updates the active branch state through generation and revision CAS.