DustEcto.Transport behaviour (DustEcto v0.1.2)

Copy Markdown View Source

Behaviour every dustlayer_ecto transport adapter implements. Two implementations ship: DustEcto.Transport.SDK (recommended, uses Phoenix Channels via :dustlayer) and DustEcto.Transport.HTTP (Req-based, stateless, no realtime).

Repo functions never call adapters directly — they go through DustEcto.Transport.pick/0 which returns the active adapter + config based on dust_facade config and the SyncEngineRegistry.

Summary

Functions

Picks the active transport at call time. Returns a {module, config} tuple where config carries adapter-specific data the Repo passes through (e.g. the SDK facade module name, or the HTTP base_url).

The configured default store name for Repo calls. Required.

Types

entry()

@type entry() :: %{
  path: String.t(),
  value: term(),
  type: String.t(),
  revision: integer()
}

opts()

@type opts() :: keyword()

page()

@type page() :: %{items: [entry() | String.t()], next_cursor: String.t() | nil}

path()

@type path() :: String.t()

pattern()

@type pattern() :: String.t()

store()

@type store() :: String.t()

Callbacks

batch_write(store, ops, opts)

@callback batch_write(store(), ops :: [map()], opts()) ::
  {:ok, %{store_seq: integer(), ops: [map()]}} | {:error, term()}

delete(store, path, opts)

@callback delete(store(), path(), opts()) ::
  {:ok, %{store_seq: integer()}} | {:error, term()}

exists?(store, path)

@callback exists?(store(), path()) :: {:ok, boolean()} | {:error, term()}

get(store, path)

@callback get(store(), path()) :: {:ok, entry()} | {:error, :not_found | term()}

list(store, pattern, opts)

@callback list(store(), pattern(), opts()) :: {:ok, page()} | {:error, term()}

put(store, path, value, opts)

@callback put(store(), path(), value :: term(), opts()) ::
  {:ok, %{store_seq: integer()}} | {:error, term()}

subscribe(store, pattern, callback)

@callback subscribe(store(), pattern(), callback :: (map() -> any())) ::
  {:ok, reference()} | {:error, :not_supported | term()}

unsubscribe(store, ref)

@callback unsubscribe(store(), ref :: reference()) :: :ok

Functions

pick()

@spec pick() :: {module(), map()}

Picks the active transport at call time. Returns a {module, config} tuple where config carries adapter-specific data the Repo passes through (e.g. the SDK facade module name, or the HTTP base_url).

Detection order:

  1. Explicit config :dustlayer_ecto, :dust_facade, MyApp.Dust — SDK mode.
  2. Dust.SyncEngineRegistry has the configured store registered — SDK mode using the global Dust module.
  3. Otherwise — HTTP mode.

This runs on every Repo call (cheap — one or two ETS lookups), so the same Elixir node can attach a Dust.Supervisor later and the transport picks it up without restart.

store!()

@spec store!() :: store()

The configured default store name for Repo calls. Required.