@atproto/sync
Version:
atproto sync library
105 lines • 5.4 kB
TypeScript
import type { IncomingMessage } from 'node:http';
import type { CID } from 'multiformats/cid';
import { type LexiconDoc } from '@atproto/lexicon';
import type { ErrorFrame, HandlerAuth } from '@atproto/xrpc-server';
export declare function isObj(v: unknown): v is Record<string, unknown>;
export declare function hasProp<K extends PropertyKey>(data: object, prop: K): data is Record<K, unknown>;
export interface QueryParams {
/** The last known event seq number to backfill from. */
cursor?: number;
}
export type RepoEvent = Commit | Identity | Account | Sync | Info | {
$type: string;
[k: string]: unknown;
};
export type HandlerError = ErrorFrame<'FutureCursor' | 'ConsumerTooSlow'>;
export type HandlerOutput = HandlerError | RepoEvent;
export type HandlerReqCtx<HA extends HandlerAuth = never> = {
auth: HA;
params: QueryParams;
req: IncomingMessage;
signal: AbortSignal;
};
export type Handler<HA extends HandlerAuth = never> = (ctx: HandlerReqCtx<HA>) => AsyncIterable<HandlerOutput>;
/** Represents an update of repository state. Note that empty commits are allowed, which include no repo data changes, but an update to rev and signature. */
export interface Commit {
/** The stream sequence number of this message. */
seq: number;
/** DEPRECATED -- unused */
rebase: boolean;
/** Indicates that this commit contained too many ops, or data size was too large. Consumers will need to make a separate request to get missing data. */
tooBig: boolean;
/** The repo this event comes from. */
repo: string;
/** Repo commit object CID. */
commit: CID;
/** DEPRECATED -- unused. WARNING -- nullable and optional; stick with optional to ensure golang interoperability. */
prev?: CID | null;
/** The rev of the emitted commit. Note that this information is also in the commit object included in blocks, unless this is a tooBig event. */
rev: string;
/** The rev of the last emitted commit from this repo (if any). */
since: string | null;
/** CAR file containing relevant blocks, as a diff since the previous repo state. */
blocks: Uint8Array;
ops: RepoOp[];
blobs: CID[];
/** Timestamp of when this message was originally broadcast. */
time: string;
[k: string]: unknown;
}
export declare function isCommit(v: unknown): v is Commit;
/** Updates the repo to a new state, without necessarily including that state on the firehose. Used to recover from broken commit streams, data loss incidents, or in situations where upstream host does not know recent state of the repository. */
export interface Sync {
$type?: 'com.atproto.sync.subscribeRepos#sync';
/** The stream sequence number of this message. */
seq: number;
/** The account this repo event corresponds to. Must match that in the commit object. */
did: string;
/** CAR file containing the commit, as a block. The CAR header must include the commit block CID as the first 'root'. */
blocks: Uint8Array;
/** The rev of the commit. This value must match that in the commit object. */
rev: string;
/** Timestamp of when this message was originally broadcast. */
time: string;
}
export declare function isSync(v: unknown): v is Sync;
/** Represents a change to an account's identity. Could be an updated handle, signing key, or pds hosting endpoint. Serves as a prod to all downstream services to refresh their identity cache. */
export interface Identity {
seq: number;
did: string;
time: string;
/** The current handle for the account, or 'handle.invalid' if validation fails. This field is optional, might have been validated or passed-through from an upstream source. Semantics and behaviors for PDS vs Relay may evolve in the future; see atproto specs for more details. */
handle?: string;
[k: string]: unknown;
}
export declare function isIdentity(v: unknown): v is Identity;
/** Represents a change to an account's status on a host (eg, PDS or Relay). The semantics of this event are that the status is at the host which emitted the event, not necessarily that at the currently active PDS. Eg, a Relay takedown would emit a takedown with active=false, even if the PDS is still active. */
export interface Account {
seq: number;
did: string;
time: string;
/** Indicates that the account has a repository which can be fetched from the host that emitted this event. */
active: boolean;
/** If active=false, this optional field indicates a reason for why the account is not active. */
status?: 'takendown' | 'suspended' | 'deleted' | 'deactivated' | string;
[k: string]: unknown;
}
export declare function isAccount(v: unknown): v is Account;
export interface Info {
name: 'OutdatedCursor' | string;
message?: string;
[k: string]: unknown;
}
export declare function isInfo(v: unknown): v is Info;
/** A repo operation, ie a mutation of a single record. */
export interface RepoOp {
action: 'create' | 'update' | 'delete' | string;
path: string;
/** For creates and updates, the new record CID. For deletions, null. */
cid: CID | null;
[k: string]: unknown;
}
export declare function isRepoOp(v: unknown): v is RepoOp;
export declare const ComAtprotoSyncSubscribeRepos: LexiconDoc;
export declare const isValidRepoEvent: (evt: unknown) => RepoEvent;
//# sourceMappingURL=lexicons.d.ts.map