···44import type { BlockMap } from "@atp/repo";
55import type { AtUri } from "@atp/syntax";
6677+/** Broad sync event type for all sync events */
78export type Event = CommitEvt | SyncEvt | IdentityEvt | AccountEvt;
891010+/**
1111+ * Metadata for a {@link CommitEvt}
1212+ * @prop seq
1313+ * Event Sequence Number
1414+ * @see {@link https://atproto.com/specs/event-stream#sequence-numbers}
1515+ * @prop time Time of the Commit Event
1616+ * @prop commit CID of the Commit
1717+ * @prop blocks CAR "slice" for the corresponding repo diff
1818+ * @prop rev Repo revision identifier as a TID
1919+ * @prop uri AT URI of the record committed
2020+ * @prop did DID of the repository
2121+ * @prop collection Collection (lexicon) of the record
2222+ * @prop rkey Record Key of the record
2323+ */
924export type CommitMeta = {
1025 seq: number;
1126 time: string;
···1833 rkey: string;
1934};
20353636+/** {@link Event} for all commit events */
2137export type CommitEvt = Create | Update | Delete;
22383939+/** {@link CommitEvt} for record creation */
2340export type Create = CommitMeta & {
2441 event: "create";
2542 record: RepoRecord;
2643 cid: CID;
2744};
28454646+/** {@link CommitEvt} for record updates/edits */
2947export type Update = CommitMeta & {
3048 event: "update";
3149 record: RepoRecord;
3250 cid: CID;
3351};
34525353+/** {@link CommitEvt} for record deletions */
3554export type Delete = CommitMeta & {
3655 event: "delete";
3756};
38575858+/**
5959+ * {@link Event} for repository sync events
6060+ * @prop seq
6161+ * Event Sequence Number
6262+ * @see {@link https://atproto.com/specs/event-stream#sequence-numbers}
6363+ * @prop time Time of sync event
6464+ * @prop event Type of event
6565+ * @prop did Repository of event
6666+ * @prop cid CID of event
6767+ * @prop rev Repository revision identifier as a TID
6868+ * @prop blocks CAR "slice" for the corresponding repo diff
6969+ */
3970export type SyncEvt = {
4071 seq: number;
4172 time: string;
···4677 blocks: BlockMap;
4778};
48798080+/**
8181+ * {@link Event} for identity change events
8282+ * @prop seq
8383+ * Event Sequence Number
8484+ * @see {@link https://atproto.com/specs/event-stream#sequence-numbers}
8585+ * @prop time Time of sync event
8686+ * @prop event Type of event
8787+ * @prop did Repository of event
8888+ * @prop handle Handle corresponding to DID
8989+ * @prop didDocument DID Document corresponding to DID
9090+ */
4991export type IdentityEvt = {
5092 seq: number;
5193 time: string;
···5597 didDocument?: DidDocument;
5698};
5799100100+/**
101101+ * @prop seq
102102+ * Event Sequence Number
103103+ * @see {@link https://atproto.com/specs/event-stream#sequence-numbers}
104104+ * @prop time Time of sync event
105105+ * @prop event Type of event
106106+ * @prop did Repository of event
107107+ * @prop active Whether account has been activated or is deactivated
108108+ * @prop status Current Account Status of the repository
109109+ */
58110export type AccountEvt = {
59111 seq: number;
60112 time: string;
···64116 status?: AccountStatus;
65117};
66118119119+/** Upstream status of an account */
67120export type AccountStatus =
68121 | "takendown"
69122 | "suspended"
+28
sync/firehose/index.ts
···327327 }
328328}
329329330330+/**
331331+ * Parse a {@link Commit} object while authenticating the commit
332332+ * @param idResolver Identity resolver for DIDs and handles
333333+ * @param evt Commit event object to parse
334334+ * @param matchCollection Lexicon collection to match record to
335335+ * @param forceKeyRefresh Whether to force a refresh when resolving AT Protocol Key
336336+ * @returns A parsed authenticated commit
337337+ */
330338export const parseCommitAuthenticated = async (
331339 idResolver: IdResolver,
332340 evt: Commit,
···372380 });
373381};
374382383383+/**
384384+ * Parse a {@link Commit} object without authenticating the commit
385385+ * @param evt Commit event object to parse
386386+ * @param matchCollection Lexicon collection to match record to
387387+ * @returns A parsed commit
388388+ */
375389export const parseCommitUnauthenticated = (
376390 evt: Commit,
377391 matchCollection?: ((col: string) => boolean) | null,
···439453 return evts;
440454};
441455456456+/**
457457+ * Parse {@link Sync} object to a sync event
458458+ * @param evt Sync event to parse
459459+ */
442460export const parseSync = async (evt: Sync): Promise<SyncEvt | null> => {
443461 const car = await readCarWithRoot(evt.blocks);
444462···453471 };
454472};
455473474474+/**
475475+ * Parse and authenticate an identity event
476476+ * @param idResolver DID and handle resolver for authentication
477477+ * @param evt Identity event to parse
478478+ * @param unauthenticated If true authentication is skipped
479479+ */
456480export const parseIdentity = async (
457481 idResolver: IdResolver,
458482 evt: Identity,
···486510 return res === did ? handle : undefined;
487511};
488512513513+/**
514514+ * Parse an account event
515515+ * @param evt Account event to parse
516516+ */
489517export const parseAccount = (evt: Account): AccountEvt | undefined => {
490518 if (evt.status && !isValidStatus(evt.status)) return;
491519 return {
+5-1
sync/runner/consecutive-list.ts
···11/**
22 * Add items to a list, and mark those items as
33 * completed. Upon item completion, get list of consecutive
44- * items completed at the head of the list. Example:
44+ * items completed at the head of the list.
55 *
66+ * @example Get consecultive item list
77+ * ```typescript
68 * const consecutive = new ConsecutiveList<number>()
79 * const item1 = consecutive.push(1)
810 * const item2 = consecutive.push(2)
···1012 * item2.complete() // []
1113 * item1.complete() // [1, 2]
1214 * item3.complete() // [3]
1515+ * ```
1316 */
1417export class ConsecutiveList<T> {
1518 list: ConsecutiveItem<T>[] = [];
···2932 }
3033}
31343535+/** Process being run consecutively in a {@link ConsecutiveList} */
3236export class ConsecutiveItem<T> {
3337 isComplete = false;
3438 constructor(
+7
sync/runner/memory-runner.ts
···22import { ConsecutiveList } from "./consecutive-list.ts";
33import type { EventRunner } from "./types.ts";
4455+/**
66+ * Options for {@link MemoryRunner}
77+ * @param setCursor Method to save the current cursor
88+ * @param concurrency Maximum amount of concurrent events being processed
99+ * @param startCursor Starting Cursor for filling in downtime
1010+ * @param setCursorInterval Interval on which to run setCursor
1111+ */
512export type MemoryRunnerOptions = {
613 setCursor?: (cursor: number) => Promise<void>;
714 concurrency?: number;