Amarula.Conn (amarula v0.1.0)

View Source

A connection handle: everything Amarula knows about one connection, built once from its config at connect time and threaded through the protocol layer.

Fields:

  • :profile — the connection's identity, e.g. :primary. Required; it scopes storage and distinguishes connections.
  • :storage — the resolved Amarula.Storage.Scope (adapter + state). Passed, with :profile, to every storage operation.
  • :retry_cache — the resolved Amarula.RetryCache.Scope.
  • :send_steps / :recv_steps — the plugin pipelines (lists of step funs). A step is fn ctx -> {:cont, ctx} | {:halt, reason}; attach/2 on a plugin appends to these (Req-style). The send pipeline runs before encrypt; the receive pipeline after decrypt, before the consumer sees the message.
  • :config — the original config map (protocol settings: version, browser, websocket url, …).

Storage plugins receive only profile + the scope's adapter state — never this struct — so a backend can't reach the socket pid or creds.

Summary

Types

A pipeline step: transforms the ctx or halts the pipeline.

t()

Functions

Append a step to the receive pipeline (runs after decrypt).

Append a step to the send pipeline (runs before encrypt).

Build a Conn from a connection config map.

Types

step()

@type step() :: (map() -> {:cont, map()} | {:halt, term()})

A pipeline step: transforms the ctx or halts the pipeline.

t()

@type t() :: %Amarula.Conn{
  config: map(),
  profile: Amarula.Storage.profile(),
  recv_steps: [step()],
  retry_cache: Amarula.RetryCache.Scope.t() | nil,
  send_steps: [step()],
  storage: Amarula.Storage.Scope.t()
}

Functions

append_recv_step(conn, step)

@spec append_recv_step(t(), step()) :: t()

Append a step to the receive pipeline (runs after decrypt).

append_send_step(conn, step)

@spec append_send_step(t(), step()) :: t()

Append a step to the send pipeline (runs before encrypt).

new(config)

@spec new(map()) :: t()

Build a Conn from a connection config map.

Requires :profile (the connection name). Storage comes from :storage (a {adapter, opts} spec or a prebuilt Scope); if omitted it defaults to Amarula.Storage.default_adapter/0 (the File adapter unless configured otherwise) rooted at AMARULA_DATA_DIR (or ./amarula_data). The adapter scopes by :profile.

The returned Conn carries the default plugin pipelines (e.g. the retry-cache send step). Attach more with a plugin's attach/2, Req-style:

Amarula.new(config) |> MyPlugin.attach() |> Amarula.connect()