checkStar
uses tcmts.registry.stars, which uses tcmts.server.table, which uses tcmts.server.Table, which uses #tcm/host (database)
Check a star against its writer's signed repository (a job, or when they've just starred): verified, or gone if
their repository doesn't hold it (they took it back). Returns whether it's theirs now. Only a star at its own place
counts: at://<DID>/codes.tcm.star/<its library's key>, so one person's star of a library is one row.
import { isDid, NotTheirs, signedRecord } from "#codebase/tcmts/atproto"; import { STAR_COLLECTION, starOf } from "#codebase/tcmts/records"; import { keepStar, stars } from "#codebase/tcmts/registry"; import type { RegistryStar } from "#codebase/tcmts/registry"; export async function checkStar(uri: string): Promise<boolean> { const m = /^at:\/\/([^/]+)\/codes\.tcm\.star\/([^/]+)$/.exec(uri); if (!m || !isDid(m[1]!)) return false; const [, did, rkey] = m as unknown as [string, string, string]; const had = await stars.findOne({ uri }); try { const got = await signedRecord(did, STAR_COLLECTION, rkey); const s = starOf(rkey, got.record); if (!s) { if (had) await stars.delete(had.id); return false; } const row: RegistryStar = { uri, did, ...s, state: "verified" }; await keepStar(row); return true; } catch (e) { if (!(e instanceof NotTheirs)) throw e; if (had) await stars.delete(had.id); return false; } }
uses
- tcmts.atproto.NotTheirs
- tcmts.atproto.isDid
- tcmts.atproto.signedRecord
- tcmts.records.STAR_COLLECTION
- tcmts.records.starOf
- tcmts.registry.RegistryStar
- tcmts.registry.keepStar
- tcmts.registry.stars