Suite of AT Protocol TypeScript libraries built on web standards
21
fork

Configure Feed

Select the types of activity you want to include in your feed.

sync documentation

+97 -1
+53
sync/events.ts
··· 4 4 import type { BlockMap } from "@atp/repo"; 5 5 import type { AtUri } from "@atp/syntax"; 6 6 7 + /** Broad sync event type for all sync events */ 7 8 export type Event = CommitEvt | SyncEvt | IdentityEvt | AccountEvt; 8 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 + */ 9 24 export type CommitMeta = { 10 25 seq: number; 11 26 time: string; ··· 18 33 rkey: string; 19 34 }; 20 35 36 + /** {@link Event} for all commit events */ 21 37 export type CommitEvt = Create | Update | Delete; 22 38 39 + /** {@link CommitEvt} for record creation */ 23 40 export type Create = CommitMeta & { 24 41 event: "create"; 25 42 record: RepoRecord; 26 43 cid: CID; 27 44 }; 28 45 46 + /** {@link CommitEvt} for record updates/edits */ 29 47 export type Update = CommitMeta & { 30 48 event: "update"; 31 49 record: RepoRecord; 32 50 cid: CID; 33 51 }; 34 52 53 + /** {@link CommitEvt} for record deletions */ 35 54 export type Delete = CommitMeta & { 36 55 event: "delete"; 37 56 }; 38 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 + */ 39 70 export type SyncEvt = { 40 71 seq: number; 41 72 time: string; ··· 46 77 blocks: BlockMap; 47 78 }; 48 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 + */ 49 91 export type IdentityEvt = { 50 92 seq: number; 51 93 time: string; ··· 55 97 didDocument?: DidDocument; 56 98 }; 57 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 + */ 58 110 export type AccountEvt = { 59 111 seq: number; 60 112 time: string; ··· 64 116 status?: AccountStatus; 65 117 }; 66 118 119 + /** Upstream status of an account */ 67 120 export type AccountStatus = 68 121 | "takendown" 69 122 | "suspended"
+28
sync/firehose/index.ts
··· 327 327 } 328 328 } 329 329 330 + /** 331 + * Parse a {@link Commit} object while authenticating the commit 332 + * @param idResolver Identity resolver for DIDs and handles 333 + * @param evt Commit event object to parse 334 + * @param matchCollection Lexicon collection to match record to 335 + * @param forceKeyRefresh Whether to force a refresh when resolving AT Protocol Key 336 + * @returns A parsed authenticated commit 337 + */ 330 338 export const parseCommitAuthenticated = async ( 331 339 idResolver: IdResolver, 332 340 evt: Commit, ··· 372 380 }); 373 381 }; 374 382 383 + /** 384 + * Parse a {@link Commit} object without authenticating the commit 385 + * @param evt Commit event object to parse 386 + * @param matchCollection Lexicon collection to match record to 387 + * @returns A parsed commit 388 + */ 375 389 export const parseCommitUnauthenticated = ( 376 390 evt: Commit, 377 391 matchCollection?: ((col: string) => boolean) | null, ··· 439 453 return evts; 440 454 }; 441 455 456 + /** 457 + * Parse {@link Sync} object to a sync event 458 + * @param evt Sync event to parse 459 + */ 442 460 export const parseSync = async (evt: Sync): Promise<SyncEvt | null> => { 443 461 const car = await readCarWithRoot(evt.blocks); 444 462 ··· 453 471 }; 454 472 }; 455 473 474 + /** 475 + * Parse and authenticate an identity event 476 + * @param idResolver DID and handle resolver for authentication 477 + * @param evt Identity event to parse 478 + * @param unauthenticated If true authentication is skipped 479 + */ 456 480 export const parseIdentity = async ( 457 481 idResolver: IdResolver, 458 482 evt: Identity, ··· 486 510 return res === did ? handle : undefined; 487 511 }; 488 512 513 + /** 514 + * Parse an account event 515 + * @param evt Account event to parse 516 + */ 489 517 export const parseAccount = (evt: Account): AccountEvt | undefined => { 490 518 if (evt.status && !isValidStatus(evt.status)) return; 491 519 return {
+5 -1
sync/runner/consecutive-list.ts
··· 1 1 /** 2 2 * Add items to a list, and mark those items as 3 3 * completed. Upon item completion, get list of consecutive 4 - * items completed at the head of the list. Example: 4 + * items completed at the head of the list. 5 5 * 6 + * @example Get consecultive item list 7 + * ```typescript 6 8 * const consecutive = new ConsecutiveList<number>() 7 9 * const item1 = consecutive.push(1) 8 10 * const item2 = consecutive.push(2) ··· 10 12 * item2.complete() // [] 11 13 * item1.complete() // [1, 2] 12 14 * item3.complete() // [3] 15 + * ``` 13 16 */ 14 17 export class ConsecutiveList<T> { 15 18 list: ConsecutiveItem<T>[] = []; ··· 29 32 } 30 33 } 31 34 35 + /** Process being run consecutively in a {@link ConsecutiveList} */ 32 36 export class ConsecutiveItem<T> { 33 37 isComplete = false; 34 38 constructor(
+7
sync/runner/memory-runner.ts
··· 2 2 import { ConsecutiveList } from "./consecutive-list.ts"; 3 3 import type { EventRunner } from "./types.ts"; 4 4 5 + /** 6 + * Options for {@link MemoryRunner} 7 + * @param setCursor Method to save the current cursor 8 + * @param concurrency Maximum amount of concurrent events being processed 9 + * @param startCursor Starting Cursor for filling in downtime 10 + * @param setCursorInterval Interval on which to run setCursor 11 + */ 5 12 export type MemoryRunnerOptions = { 6 13 setCursor?: (cursor: number) => Promise<void>; 7 14 concurrency?: number;
+4
sync/runner/types.ts
··· 1 + /** 2 + * Generic event runner interface 3 + * for event tracking and processing 4 + */ 1 5 export interface EventRunner { 2 6 getCursor(): Awaited<number | undefined>; 3 7 trackEvent(