ProtoRune.Jetstream.Event (proto_rune v0.5.1)

Copy Markdown

A single event decoded from a Jetstream JSON message.

Jetstream is a JSON re-encode of the repo firehose with server-side filtering, so events arrive already decoded: no CAR slicing and no CBOR. The record of a commit operation comes inline in the message.

Fields

  • :type - the event type: :commit, :identity, :account or :unknown.
  • :did - the DID of the repository the event belongs to.
  • :time_us - the event timestamp in microseconds since the Unix epoch. Feed it back as the :cursor option of ProtoRune.Jetstream.start_link/1 to resume the stream.
  • :collection - the record collection (:commit events only).
  • :rkey - the record key (:commit events only).
  • :operation - :create, :update or :delete (:commit events only).
  • :cid - the record CID as a string (:commit events only, nil for deletions).
  • :rev - the repository revision (:commit events only).
  • :record - the decoded record for :create and :update operations, nil for deletions.
  • :payload - the raw decoded message, for fields this module does not know about.

Summary

Functions

Builds an event from a JSON-decoded Jetstream message.

Types

operation()

@type operation() :: :create | :update | :delete

t()

@type t() :: %ProtoRune.Jetstream.Event{
  cid: String.t() | nil,
  collection: String.t() | nil,
  did: String.t() | nil,
  operation: operation() | nil,
  payload: map(),
  record: map() | nil,
  rev: String.t() | nil,
  rkey: String.t() | nil,
  time_us: non_neg_integer() | nil,
  type: :commit | :identity | :account | :unknown
}

Functions

from_message(message)

@spec from_message(map()) :: {:ok, t()} | {:error, atom()}

Builds an event from a JSON-decoded Jetstream message.