retrace_frontend/client/adapter

Construct existing client adapters from typed Gleam operations. No storage engine, upload policy, scheduler or resource owner is introduced.

Types

pub type Queue {
  Queue(name: String, max_items: Int, max_bytes: Int)
}

Constructors

  • Queue(name: String, max_items: Int, max_bytes: Int)
pub type Row {
  Row(key: String, body: String)
}

Constructors

  • Row(key: String, body: String)

Caller-owned persistence. Put must enforce limits atomically, accept an identical retry, reject conflicting content and reply only after saving. All operations must settle, including failures. The client never closes the store; callers release resources only after pending operations have settled.

pub type Store(error) {
  Store(
    all: fn() -> fn(fn(Result(List(Row), error)) -> Nil) -> fn() -> Nil,
    put: fn(Row) -> fn(fn(Result(Nil, error)) -> Nil) -> fn() -> Nil,
    remove: fn(String) -> fn(fn(Result(Nil, error)) -> Nil) -> fn(
      ,
    ) -> Nil,
  )
}

Constructors

  • Store(
      all: fn() -> fn(fn(Result(List(Row), error)) -> Nil) -> fn() -> Nil,
      put: fn(Row) -> fn(fn(Result(Nil, error)) -> Nil) -> fn() -> Nil,
      remove: fn(String) -> fn(fn(Result(Nil, error)) -> Nil) -> fn() -> Nil,
    )

Cold operation: start work only when invoked, reply with its outcome, and return cancellation for pending work. The bridge observes only the first completion and ignores late replies after cancellation. Cancellation cannot undo a remote commit; upload retries must still be idempotent.

Storage operations must settle. Their cancellation functions are not called: admitted saves and deletions complete even when the client shuts down.

pub type Task(value, error) =
  fn(fn(Result(value, error)) -> Nil) -> fn() -> Nil

Values

pub fn defer(
  work: fn() -> Result(value, error),
) -> fn(fn(Result(value, error)) -> Nil) -> fn() -> Nil

Run synchronous work when the adapter invokes it, not during configuration. For asynchronous IO supply a Task directly; no additional task framework is needed. Side effects and failures belong inside work.

pub fn storage(
  open: fn(Queue) -> fn(fn(Result(Store(error), error)) -> Nil) -> fn(
    ,
  ) -> Nil,
  explain: fn(error) -> String,
) -> client.Storage

Construct a Storage with provider-specific errors and explicit diagnostics. The client passes its validated queue settings to open. The returned store and its underlying handles remain caller-owned.

pub fn transport(
  open open: fn(String) -> fn(fn(Result(String, error)) -> Nil) -> fn(
    ,
  ) -> Nil,
  send send: fn(String) -> fn(fn(Result(String, error)) -> Nil) -> fn(
    ,
  ) -> Nil,
  explain explain: fn(error) -> String,
  rejected rejected: fn(error) -> Bool,
) -> client.Transport

Construct a collector adapter. Open receives encoded session metadata and returns the encoded grant: a session id the collector chose and the write token it issued (wire.encode_grant). Send receives the exact encoded upload and returns the encoded acknowledgement. The client checks the grant and the receipt before using them. Deadline and shutdown invoke pending task cancellation; a late callback cannot turn cancellation into success.

rejected classifies a provider error as a permanent refusal that an identical retry cannot change. A refused upload ends delivery of its session from this client: the client discards that session’s saved batches and goes on with the others. A refused open fails the capture that asked for it. Every other failure is retried with backoff. Return False for failures the host can repair, such as expired credentials.

✨ Search Document