A2UICore.Message.Adapter behaviour (A2UICore v0.1.1)

Copy Markdown View Source

Version adapter behaviour and the shared envelope-extraction pipeline.

Each protocol version implements the c:Adapter behaviour; the shared extract/3 pipeline (a faithful port of the reference BaseVersionAdapter.extract_operations) drives them:

  1. recursion/pointer preflight (A2UICore.Validation.Integrity),
  2. payload unwrapping — nil/[] are no-ops, lists recurse per item (pre-checking the single-action rule for every item first), and {"messages": [...]} wrappers recurse into the list,
  3. per-message checks, in this order: exactly one action key (with the reference's two distinct error messages), action payload must be an object, surfaceId must be a string when present, version presence and compatibility,
  4. schema validation against the version's vendored envelope document — the message-type $defs entry selected by the action key (mirroring the reference's discriminated dispatch) with the active catalog bound to the catalog.json placeholder,
  5. operation construction via extract_operations/2.

Summary

Types

Adapter options: :catalog binds the catalog schema the envelope's catalog.json references resolve against — a catalog schema map, or :permissive for a stand-in that accepts any component object, theme and well-formed function call (the processor checks components against the catalog each surface actually uses).

Functions

The version adapter behaviour. All callbacks are pure.

Extracts canonical operations from a raw payload using adapter.

Types

opts()

(since 0.1.0)
@type opts() :: keyword()

Adapter options: :catalog binds the catalog schema the envelope's catalog.json references resolve against — a catalog schema map, or :permissive for a stand-in that accepts any component object, theme and well-formed function call (the processor checks components against the catalog each surface actually uses).

Callbacks

compatible_catalog_versions()

(since 0.1.0)
@callback compatible_catalog_versions() :: MapSet.t(String.t())

document_version()

(since 0.1.0)
@callback document_version() :: String.t()

extract_operations(action, message)

(since 0.1.0)
@callback extract_operations(action :: String.t(), message :: map()) :: [
  A2UICore.Message.Operation.t()
]

prepare_message(map)

(since 0.1.0)
@callback prepare_message(map()) :: map()

valid_actions()

(since 0.1.0)
@callback valid_actions() :: [String.t()]

version()

(since 0.1.0)
@callback version() :: String.t()

Functions

__using__(opts)

(since 0.1.0) (macro)

The version adapter behaviour. All callbacks are pure.

extract(adapter, payload, opts \\ [])

(since 0.1.0)
@spec extract(module(), term(), opts()) ::
  {:ok, [A2UICore.Message.Operation.t()]} | {:error, A2UICore.Error.t()}

Extracts canonical operations from a raw payload using adapter.

Returns {:ok, operations} or {:error, error}.