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

strata_protocol/server

Server → client frames.

Wire shape:

{"v": 0, "kind": "welcome", "session_id": "...", "server": "..."} {"v": 0, "kind": "snapshot", "doc": "...", "state": <opaque CRDT JSON>} {"v": 0, "kind": "deleted", "doc": "..."} {"v": 0, "kind": "delta", "doc": "...", "state": <opaque CRDT JSON>, "from": "..."} {"v": 0, "kind": "presence_state", "doc": "...", "presences": [Presence...]} {"v": 0, "kind": "presence_diff", "doc": "...", "diff": {"joins": {<session_id>: {"metas": [Presence...]}}, "leaves": {...}}} {"v": 0, "kind": "error", "code": "...", "message": "..."} {"v": 0, "kind": "pong"}

A frame sent by the server to a client.

CRDT payloads (state) are decoded as Dynamic so the client can hand them directly to lattice's typed decoders.

pub type ServerFrame {
Welcome(session_id: String, server: String)
Snapshot(document_id: String, state: dynamic.Dynamic)
Deleted(document_id: String)
Delta(document_id: String, state: dynamic.Dynamic, from: String)
PresenceState(document_id: String, presences: List(presence.Presence))
PresenceDiff(document_id: String, joins: List(presence.Presence), leaves: List(presence.Presence))
ServerError(code: String, message: String)
Pong
}

Parse a JSON string into a ServerFrame.

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

Encode a Deleted frame.

pub fn deleted(String) -> json.Json

Encode a Delta frame.

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

Encode a typed ServerFrame back to JSON. Round-trips with decode.

pub fn encode(ServerFrame) -> json.Json

Encode an Error frame.

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

Decoder that yields a Result(ServerFrame, DecodeError).

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

Encode a Pong frame.

pub fn pong() -> json.Json

Encode a PresenceDiff frame.

The diff payload uses the Phoenix/beryl presence shape: joins and leaves are objects keyed by session id, each holding a metas list of presence records. Presences without a session_id are keyed by the empty string.

pub fn presence_diff(
String,
List(presence.Presence),
List(presence.Presence)
) -> json.Json

Wrap an already-encoded presence diff (as produced by beryl's runtime) in a presence_diff envelope. The diff is forwarded untouched.

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

Encode a PresenceState frame.

pub fn presence_state(
String,
List(presence.Presence)
) -> json.Json

Encode a Snapshot frame. state is the opaque CRDT JSON state produced by or_map.to_json (or equivalent).

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

Encode a Welcome frame.

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