Spectre.Stack.Installable behaviour (Spectre v0.4.0)

Copy Markdown View Source

Versioned contract implemented by packages that can be installed in a Stack.

manifest/0, compile/3 and optional tools/1 / effects/1 run while the Stack definition is compiled and must return immutable data. tools/1 receives compiled configuration and returns Spectre.Stack.Tools descriptors. use Spectre.Server, tools: MyApp.Stack generates helpers from their names; a package does not export a helper function simply by implementing this callback.

Descriptors declare operation validation, adapters and replay contracts. Cognitive operations return projected portable data; governed operations normalize to host-bound proposals before persistence and enter GAM. A tool registration is not authority to execute its consequences.

Optional effects/1 returns Spectre.Stack.Effects registrations for the managed GAM executor. It is an additive version-1 effect catalog, distinct from helper descriptors and Spectre.Stack.Contract.V2. Packages without it remain compatible with manual GAM bindings. Installing an execution adapter still requires the application to enable the operation under its declared authority.

child_specs/2, when implemented, runs only when a caller explicitly starts Spectre.Stack.Runtime. The optional callback extends the existing version-1 installable contract; packages without tools still install but provide no generated Server helpers. See the Stack Tools guide for a complete descriptor example and the adapter contract.

Summary

Functions

Defines a static manifest and default data-only compiler.

Returns the supported installable contract version.

Compiles optional, data-only execution registrations without granting authority.

Verifies and returns an installable package manifest.

Verifies an installable or raises with a stable contract error.

Callbacks

child_specs(t, keyword)

(optional)
@callback child_specs(
  Spectre.Stack.Installation.t(),
  keyword()
) ::
  [{term(), Supervisor.child_spec()}]
  | {:ok, [{term(), Supervisor.child_spec()}]}
  | {:error, term()}

compile(keyword, arg2, t)

(optional)
@callback compile(keyword(), Macro.t() | nil, Macro.Env.t()) ::
  {:ok, map() | keyword()} | {:error, term()}

effects(arg1)

(optional)
@callback effects(map() | keyword()) :: Spectre.Stack.Effects.t()

manifest()

@callback manifest() :: Spectre.Stack.Package.t() | map() | keyword()

tools(arg1)

(optional)
@callback tools(map() | keyword()) :: Spectre.Stack.Tools.t()

Functions

__using__(manifest_opts)

(macro)

Defines a static manifest and default data-only compiler.

contract_version()

@spec contract_version() :: pos_integer()

Returns the supported installable contract version.

effects!(module, config)

@spec effects!(module(), map() | keyword()) :: Spectre.Stack.Effects.t()

Compiles optional, data-only execution registrations without granting authority.

verify(module, contract \\ 1)

@spec verify(module(), pos_integer()) ::
  {:ok, Spectre.Stack.Package.t()} | {:error, term()}

Verifies and returns an installable package manifest.

verify!(module, contract \\ 1)

@spec verify!(module(), pos_integer()) :: Spectre.Stack.Package.t()

Verifies an installable or raises with a stable contract error.