Suite of AT Protocol TypeScript libraries built on web standards
1import type { CID } from "multiformats/cid";
2import type { DidDocument } from "@atp/identity";
3import type { RepoRecord } from "@atp/lexicon";
4import type { BlockMap } from "@atp/repo";
5import type { AtUri } from "@atp/syntax";
6
7/** Broad sync event type for all sync events */
8export type Event = CommitEvt | SyncEvt | IdentityEvt | AccountEvt;
9
10/**
11 * Metadata for a {@link CommitEvt}
12 * @prop seq
13 * Event Sequence Number
14 * @see {@link https://atproto.com/specs/event-stream#sequence-numbers}
15 * @prop time Time of the Commit Event
16 * @prop commit CID of the Commit
17 * @prop blocks CAR "slice" for the corresponding repo diff
18 * @prop rev Repo revision identifier as a TID
19 * @prop uri AT URI of the record committed
20 * @prop did DID of the repository
21 * @prop collection Collection (lexicon) of the record
22 * @prop rkey Record Key of the record
23 */
24export type CommitMeta = {
25 seq: number;
26 time: string;
27 commit: CID;
28 blocks: BlockMap;
29 rev: string;
30 uri: AtUri;
31 did: string;
32 collection: string;
33 rkey: string;
34};
35
36/** {@link Event} for all commit events */
37export type CommitEvt = Create | Update | Delete;
38
39/** {@link CommitEvt} for record creation */
40export type Create = CommitMeta & {
41 event: "create";
42 record: RepoRecord;
43 cid: CID;
44};
45
46/** {@link CommitEvt} for record updates/edits */
47export type Update = CommitMeta & {
48 event: "update";
49 record: RepoRecord;
50 cid: CID;
51};
52
53/** {@link CommitEvt} for record deletions */
54export type Delete = CommitMeta & {
55 event: "delete";
56};
57
58/**
59 * {@link Event} for repository sync events
60 * @prop seq
61 * Event Sequence Number
62 * @see {@link https://atproto.com/specs/event-stream#sequence-numbers}
63 * @prop time Time of sync event
64 * @prop event Type of event
65 * @prop did Repository of event
66 * @prop cid CID of event
67 * @prop rev Repository revision identifier as a TID
68 * @prop blocks CAR "slice" for the corresponding repo diff
69 */
70export type SyncEvt = {
71 seq: number;
72 time: string;
73 event: "sync";
74 did: string;
75 cid: CID;
76 rev: string;
77 blocks: BlockMap;
78};
79
80/**
81 * {@link Event} for identity change events
82 * @prop seq
83 * Event Sequence Number
84 * @see {@link https://atproto.com/specs/event-stream#sequence-numbers}
85 * @prop time Time of sync event
86 * @prop event Type of event
87 * @prop did Repository of event
88 * @prop handle Handle corresponding to DID
89 * @prop didDocument DID Document corresponding to DID
90 */
91export type IdentityEvt = {
92 seq: number;
93 time: string;
94 event: "identity";
95 did: string;
96 handle?: string;
97 didDocument?: DidDocument;
98};
99
100/**
101 * @prop seq
102 * Event Sequence Number
103 * @see {@link https://atproto.com/specs/event-stream#sequence-numbers}
104 * @prop time Time of sync event
105 * @prop event Type of event
106 * @prop did Repository of event
107 * @prop active Whether account has been activated or is deactivated
108 * @prop status Current Account Status of the repository
109 */
110export type AccountEvt = {
111 seq: number;
112 time: string;
113 event: "account";
114 did: string;
115 active: boolean;
116 status?: AccountStatus;
117};
118
119/** Upstream status of an account */
120export type AccountStatus =
121 | "takendown"
122 | "suspended"
123 | "deleted"
124 | "deactivated";