# `Spectre.Instance.Lifecycle`
[🔗](https://github.com/elchemista/spectre/blob/0.4.0/lib/spectre/instance/lifecycle.ex#L1)

Independent admission, authority, retention and activation axes for a Definition.

A saved Run authority epoch is lineage only. Authorization always consults
the current lifecycle record at admission, commit or dispatch time.

# `axis`

```elixir
@type axis() :: :admission | :authority | :retention | :activation
```

# `t`

```elixir
@type t() :: %Spectre.Instance.Lifecycle{
  activation: :active | :inactive,
  admission: :accepting | :draining | :closed,
  authority: :granted | :restricted | :revoked,
  authority_epoch: non_neg_integer(),
  changed_at: non_neg_integer(),
  definition_ref: Spectre.Definition.Ref.t(),
  provenance: map(),
  reason: term(),
  retention: :retained | :gc_eligible | :purged,
  revision: non_neg_integer(),
  schema_version: pos_integer()
}
```

# `activate`

```elixir
@spec activate(
  map(),
  Spectre.Instance.Activation.t() | nil,
  Spectre.Instance.Activation.t(),
  keyword()
) ::
  {:ok, map()} | {:error, term()}
```

Moves the active lifecycle fence atomically for a Definition Activation.

# `authorize`

```elixir
@spec authorize(t(), :new_admission | :continuation | :dispatch | :commit) ::
  :ok | {:error, term()}
```

Checks current-time lifecycle authority for a runtime operation.

# `fetch`

```elixir
@spec fetch(map(), Spectre.Definition.Ref.t(), keyword()) :: t()
```

Fetches a lifecycle or returns a safe default for a known Definition.

# `from_activation`

```elixir
@spec from_activation(Spectre.Instance.Activation.t()) :: t()
```

Builds the initial active lifecycle represented by an Activation.

# `from_data`

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

Restores lifecycle data without creating atoms.

# `key`

```elixir
@spec key(Spectre.Definition.Ref.t() | t()) :: String.t()
```

Returns the stable map key for a Definition lifecycle.

# `new`

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

Builds and validates a Definition lifecycle record.

# `new!`

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

Builds a lifecycle record or raises with its stable reason.

# `schema_version`

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

Returns the lifecycle schema version.

# `to_data`

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

Returns portable lifecycle data.

# `transition`

```elixir
@spec transition(t(), axis(), atom(), keyword()) :: {:ok, t()} | {:error, term()}
```

Transitions one axis through revision CAS and monotonic safety rules.

---

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