Spectre.Payload.Store behaviour (Spectre v0.4.0)

Copy Markdown View Source

Application-owned storage for content kept outside durable Spectre records.

Configure {MyApp.Payloads, options} at the consuming runtime boundary. put/3 returns an opaque, portable reference; fetch/3 resolves it. Spectre does not prescribe a database, object store, encryption scheme, digest or reference format. The adapter owns those choices and the guarantees offered by its references, including retention and any integrity checks.

Callbacks run in the caller's worker. This facade does not start detached tasks, retain payloads, retry writes or fall back to inline persistence. Runtime integrations must invoke it outside their ordering process and own the worker's timeout, cancellation and result handling.

The small context map describes why content is being stored or fetched. Adapters can use its operation identity for idempotency and access control; it is application context, never an authorization capability.

A successful put/3 must mean the reference can be resolved according to the adapter's contract. If an external write succeeds but the subsequent Spectre commit fails, cleanup of unused content belongs to the application.

Summary

Functions

Resolves content through the configured adapter without imposing a payload schema.

Validates adapter wiring; nil leaves external payload storage unconfigured.

Stores content and validates only that its opaque reference is portable.

Types

config()

@type config() :: {module(), keyword()}

context()

@type context() :: map()

payload_ref()

@type payload_ref() :: term()

Callbacks

fetch(payload_ref, context, keyword)

@callback fetch(payload_ref(), context(), keyword()) :: {:ok, term()} | {:error, term()}

put(term, context, keyword)

@callback put(term(), context(), keyword()) :: {:ok, payload_ref()} | {:error, term()}

Functions

fetch(config, reference, context)

@spec fetch(config(), payload_ref(), context()) :: {:ok, term()} | {:error, term()}

Resolves content through the configured adapter without imposing a payload schema.

normalize(config)

@spec normalize(term()) :: {:ok, config() | nil} | {:error, :invalid_payload_store}

Validates adapter wiring; nil leaves external payload storage unconfigured.

put(config, payload, context)

@spec put(config(), term(), context()) :: {:ok, payload_ref()} | {:error, term()}

Stores content and validates only that its opaque reference is portable.