| … | … | @@ -330,13 +330,28 @@ export class DidPeer { |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | // com.atproto.repo.listRecords |
| 333 | | async listRecords (collection) { |
| 334 | | if (this.repo) return rvListRecords(this.repo, collection, { did: this.did }) |
| 335 | | if (this._noRepo) return [] |
| 333 | // Returns { records, cursor } per the lexicon. `limit`/`reverse`/`cursor` were dropped on the floor |
| 334 | // here as well as in read-view, so a caller's paging parameters never reached anything that honoured |
| 335 | // them. Both derived and repo-backed paths now page identically — a client must not get different |
| 336 | // semantics depending on which internal path answered. |
| 337 | async listRecords (collection, { limit = 50, reverse = false, cursor = null } = {}) { |
| 338 | if (this.repo) return rvListRecords(this.repo, collection, { did: this.did, limit, reverse, cursor }) |
| 339 | if (this._noRepo) return { records: [], cursor: undefined } |
| 340 | const n = Math.min(100, Math.max(1, Number(limit) || 50)) |
| 336 | 341 | const prefix = collection + '/' |
| 337 | | return (await this._derivedRecords()) |
| 342 | const all = (await this._derivedRecords()) |
| 338 | 343 | .filter((r) => r.key.startsWith(prefix)) |
| 339 | | .map((r) => ({ uri: `at://${this.did}/${r.key}`, cid: r.cid, value: r.value })) |
| 344 | .map((r) => ({ rkey: r.key.slice(prefix.length), uri: `at://${this.did}/${r.key}`, cid: r.cid, value: r.value })) |
| 345 | if (reverse) all.reverse() |
| 346 | let start = 0 |
| 347 | if (cursor) { |
| 348 | const i = all.findIndex((r) => r.rkey === cursor) |
| 349 | start = i >= 0 ? i + 1 : all.length |
| 350 | } |
| 351 | const page = all.slice(start, start + n) |
| 352 | const more = start + page.length < all.length |
| 353 | const last = page.length ? page[page.length - 1].rkey : null |
| 354 | return { records: page.map(({ uri, cid, value }) => ({ uri, cid, value })), cursor: more && last ? last : undefined } |
| 340 | 355 | } |
| 341 | 356 | |
| 342 | 357 | // com.atproto.sync.getLatestCommit -> { cid, rev } from the verified head (keyless). |