import { resolvePds, xrpcGet } from '../atproto/identity.ts' import type { RepoReader } from './sync.ts' /** Reads records straight from the owner's PDS. Public data, so no session is needed. */ export const pdsReader: RepoReader = { async list(did, collection) { const pds = await resolvePds(did) if (!pds) throw new Error(`couldn’t find the PDS for ${did}`) const out: { rkey: string; cid: string; value: unknown }[] = [] let cursor: string | undefined for (let page = 0; page < 100; page++) { const res = await xrpcGet<{ records: { uri: string; cid: string; value: unknown }[]; cursor?: string }>(pds, 'com.atproto.repo.listRecords', { repo: did, collection, limit: 100, cursor, }) for (const r of res.records) out.push({ rkey: r.uri.split('/').pop()!, cid: r.cid, value: r.value }) if (!res.cursor || res.records.length === 0) return out cursor = res.cursor } // Too many to read fully; a partial list would look like deletions, so give up instead. throw new Error(`${collection} in ${did} has too many records to reconcile`) }, }