ProtoRune.Firehose.Event (proto_rune v0.5.2)

Copy Markdown

A single event decoded from the ATProto firehose.

Fields

  • :type - the event type: :commit, :identity, :account, :handle, :migrate, :tombstone, :info, :error or :unknown.
  • :seq - the sequence number of the event. Feed it back as the :cursor option of ProtoRune.Firehose to resume the stream from this point.
  • :repo - the DID of the repository the event belongs to.
  • :time - the event timestamp as an ISO 8601 string.
  • :rev - the repository revision (:commit events only).
  • :ops - the repository operations of a :commit event.
  • :blocks - the repository blocks of a :commit event, CBOR-decoded and keyed by CID string. The record for an operation can be found at event.blocks[to_string(op.cid)].
  • :payload - the raw decoded frame payload, for event types without dedicated fields and for fields this module does not know about.

Summary

Types

A repository operation within a :commit event.

t()

Functions

Returns true when any operation of a :commit event belongs to the given collection or a collection under it.

Types

op()

@type op() :: %{
  action: :create | :update | :delete,
  path: String.t(),
  cid: ProtoRune.CID.t() | nil
}

A repository operation within a :commit event.

  • :action - :create, :update or :delete.
  • :path - the record path, e.g. "app.bsky.feed.post/3jxfb3nkkf22v".
  • :cid - the record CID (nil for deletions).

t()

@type t() :: %ProtoRune.Firehose.Event{
  blocks: %{optional(String.t()) => term()},
  ops: [op()],
  payload: map(),
  repo: String.t() | nil,
  rev: String.t() | nil,
  seq: non_neg_integer() | nil,
  time: String.t() | nil,
  type:
    :commit
    | :identity
    | :account
    | :handle
    | :migrate
    | :tombstone
    | :info
    | :error
    | :unknown
}

Functions

collection?(event, prefix)

@spec collection?(t(), String.t()) :: boolean()

Returns true when any operation of a :commit event belongs to the given collection or a collection under it.

The match is segment-aware: "app.bsky.feed" matches "app.bsky.feed.post" but not "app.bsky.feedback.x". Non-commit events carry no operations and always return false.

Examples

iex> Event.collection?(%Event{type: :commit, ops: [%{action: :create, path: "app.bsky.feed.post/abc", cid: nil}]}, "app.bsky.feed")
true

iex> Event.collection?(%Event{type: :commit, ops: [%{action: :create, path: "app.bsky.feedback.x/abc", cid: nil}]}, "app.bsky.feed")
false

iex> Event.collection?(%Event{type: :identity}, "app.bsky.feed")
false