listRecords

tcmts.atproto.listRecords · #535um55n · function · runs on the server

uses tcmts.atproto.pdsOf, which uses tcmts.atproto.localNetwork, which uses process

An account's records of collection, as its PDS lists them, without signing in: a page (limit, at most 100), and the cursor for the next, if there's more.

import { didDocument, guardedFetch, okJson, pdsOf } from "#codebase/tcmts/atproto";

export async function listRecords<T = Record<string, unknown>>(
  did: string,
  collection: string,
  o: { limit?: number; cursor?: string } = {},
): Promise<{ records: { uri: string; cid: string; value: T }[]; cursor?: string }> {
  const pds = pdsOf(await didDocument(did), did);
  const q = new URLSearchParams({
    repo: did,
    collection,
    limit: String(Math.min(100, o.limit ?? 50)),
    ...(o.cursor ? { cursor: o.cursor } : {}),
  });
  return okJson(
    await guardedFetch(`${pds}/xrpc/com.atproto.repo.listRecords?${q}`, `${did}'s PDS`, {
      headers: { accept: "application/json" },
    }),
    `${did}'s ${collection} records`,
  );
}

uses

used by