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