# `Spectre.Operation.Spec`
[🔗](https://github.com/elchemista/spectre/blob/0.4.0/lib/spectre/operation/spec.ex#L1)

Immutable registry entry for one operation available to an operational loop.

Executors and validators are stable module/function references. They are
resolved from code after restart and are never embedded in checkpoints.

# `executor`

```elixir
@type executor() :: nil | module() | {module(), atom()}
```

# `t`

```elixir
@type t() :: %Spectre.Operation.Spec{
  catalog: [atom() | String.t()],
  description: String.t() | nil,
  domain: [term()] | nil,
  executor: executor() | term(),
  fallback: executor(),
  id: atom() | String.t(),
  input: validator(),
  kind: :function | :action | :effect | :cognitive | :planner,
  metadata: map(),
  output: validator(),
  policy: :registered | executor(),
  reconcile: executor(),
  remember: false | true | map(),
  retry: Spectre.Operation.Retry.t(),
  risk: atom() | nil,
  side_effect: :none | :idempotent | :reconcilable | :non_idempotent,
  timeout: pos_integer()
}
```

# `validator`

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

# `new`

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

Builds a validated spec from a struct, map or keyword list.

Missing fields fall back to defaults (`kind: :function`, `timeout: 30_000`,
a kind-dependent `side_effect`). Raises `ArgumentError` when the resulting
spec is invalid.

# `validate`

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

Checks every invariant of the spec, including that its portable contract
fields survive checkpoint serialization.

Returns `:ok` or `{:error, reason}` with a tagged tuple naming the first
violated invariant.

# `validate!`

```elixir
@spec validate!(t()) :: t()
```

Same as `validate/1` but returns the spec on success and raises
`ArgumentError` on failure.

---

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