import type { MiniDoc } from "#lib/api/identity.ts"; import { buildRepoCar } from "#lib/migration/repoCar.ts"; import type { Fetch } from "#lib/fetch.ts"; const STARS = 230; const CREATED_AT = "2026-01-01T00:00:00.000Z"; const starRkey = (index: number) => `3mock${String(index).padStart(8, "0")}`; // more than one applyWrites batch, so progress and batching get exercised const mockRecords = (did: string) => [ { collection: "org.tangled.actor.profile", rkey: "self", value: { $type: "org.tangled.actor.profile", description: "moved from the liar pds" } }, { collection: "org.tangled.graph.follow", rkey: "did:plc:mockfollowee", value: { $type: "org.tangled.graph.follow", createdAt: CREATED_AT } }, { collection: "org.tangled.repo.declaration", rkey: "mockrepo", value: { $type: "org.tangled.repo.declaration", repo: did, createdAt: CREATED_AT } }, ...Array.from({ length: STARS }, (_, index) => ({ collection: "org.tangled.feed.star", rkey: starRkey(index), value: { $type: "org.tangled.feed.star", subject: { $type: "org.tangled.feed.star#repo", identity: `did:plc:mockrepo${index}` }, createdAt: CREATED_AT } })) ]; export const mockLiarFetch: Fetch = async (input) => { const request = new URL(input instanceof Request ? input.url : String(input)); if (request.pathname === "/xrpc/org.tangled.foster.unmarkLiarAccount") { return new Response(null, { status: 200 }); } if (request.pathname === "/xrpc/com.atproto.sync.listBlobs") { return new Response('{"cids":[]}', { status: 200 }); } const did = request.searchParams.get("did"); if (request.pathname !== "/xrpc/com.atproto.sync.getRepo" || !did) { return new Response("{}", { status: 404 }); } return new Response(await buildRepoCar(did, mockRecords(did)), { headers: { "content-type": "application/vnd.ipld.car" } }); }; // the mock records landing on the real pds counts as migrated export const mockHydrantDoc = async ( doc: MiniDoc, liarPdsUrl: string, fetch: Fetch ): Promise => { if (!doc.pds) return doc; const url = new URL("/xrpc/com.atproto.repo.getRecord", doc.pds); url.searchParams.set("repo", doc.did); url.searchParams.set("collection", "org.tangled.feed.star"); url.searchParams.set("rkey", starRkey(STARS - 1)); const imported = await fetch(url).then( (response) => response.ok, () => false ); return imported ? doc : { ...doc, pds: liarPdsUrl as MiniDoc["pds"] }; };