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)
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
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(
send: fn(String) -> fn(fn(Result(String, error)) -> Nil) -> fn() -> Nil,
explain: fn(error) -> String,
) -> client.Transport
Construct an upload adapter. Send receives the exact encoded batch and returns the encoded acknowledgement. The client checks the receipt before removing anything from storage. Deadline and shutdown invoke pending task cancellation; a late callback cannot turn cancellation into success.