Skip to content
Strata is pre-1.0. APIs, protocol, and storage format may change.

strata_protocol/client

Client → server frames.

Wire shape:

{"v": 0, "kind": "join", "doc": "..."} {"v": 0, "kind": "leave", "doc": "..."} {"v": 0, "kind": "create", "doc": "...", "child": "...", "child_state": <opaque>, "state": <opaque>} {"v": 0, "kind": "delete", "doc": "...", "child": "...", "state": <opaque>} {"v": 0, "kind": "delta", "doc": "...", "state": <opaque CRDT JSON>} {"v": 0, "kind": "presence_set", "doc": "...", "payload": <opaque>} {"v": 0, "kind": "ping"}

Authentication is performed at WebSocket upgrade time via a ?token= query parameter — there is no in-band auth frame.

A frame sent by a client to the server.

CRDT payloads (ops, ctx, presence payload) are decoded as Dynamic so callers can hand them directly to lattice's typed JSON decoders without this package needing to depend on lattice.

pub type ClientFrame {
Join(document_id: String)
Leave(document_id: String)
Create(document_id: String, child: String, child_state: dynamic.Dynamic, state: dynamic.Dynamic)
Delete(document_id: String, child: String, state: dynamic.Dynamic)
Delta(document_id: String, state: dynamic.Dynamic)
PresenceSet(document_id: String, payload: dynamic.Dynamic)
Ping
}

Encode a Create frame.

pub fn create(
String,
String,
json.Json,
json.Json
) -> json.Json

Parse a JSON string into a ClientFrame.

pub fn decode(String) -> Result(ClientFrame, error.DecodeError)

Encode a Delete frame.

pub fn delete(
String,
String,
json.Json
) -> json.Json

Encode a Delta frame. state is the opaque CRDT JSON state produced by the client's CRDT layer (typically or_map.to_json).

pub fn delta(
String,
json.Json
) -> json.Json

Encode a typed ClientFrame back to JSON. Useful for proxying or re-broadcasting decoded frames; round-trips with decode.

pub fn encode(ClientFrame) -> json.Json

Decoder that yields a Result(ClientFrame, DecodeError). The outer Result represents JSON shape errors; the inner one represents protocol-level errors (unknown kind, version mismatch).

pub fn frame_decoder() -> decode.Decoder(Result(ClientFrame, error.DecodeError))

Encode a Join frame.

pub fn join(String) -> json.Json

Encode a Leave frame.

pub fn leave(String) -> json.Json

Encode a Ping frame.

pub fn ping() -> json.Json

Encode a PresenceSet frame.

pub fn presence_set(
String,
json.Json
) -> json.Json