recheckRelease

tcmts.registry.recheckRelease · #idhpybxy · term · runs on the server

uses tcmts.registry.releases, which uses tcmts.server.table, which uses tcmts.server.Table, which uses #tcm/host (database)

Check a release again against its author's repository, when Jetstream says its record changed or went (a job): a registry keeps only what the repository signs, so an event alone changes nothing. A record that's gone withdraws a release the registry checked (its code stays) and drops one it never did; one that's changed is taken as it's signed now (another namespace under its version fails it); one not checked yet is mirrored.

import { NoSuchRecord, NotTheirs } from "#codebase/tcmts/atproto";
import { mirror, releaseFields, releases, signedRelease, uses } from "#codebase/tcmts/registry";
import { enqueue } from "#codebase/tcmts/server";

export async function recheckRelease(uri: string): Promise<void> {
  const found = await releases.findOne({ uri });
  if (!found) return;
  const r = found.value;
  try {
    const signed = await signedRelease(r.did, r.rkey);
    if (r.verifiedAt === undefined) {
      if (r.state !== "pending") {
        await releases.update(found.id, (v) => ({
          ...v,
          ...releaseFields(signed.record),
          state: "pending",
        }));
        enqueue(mirror, uri);
      }
      return;
    }
    if (signed.record.namespace !== r.namespace)
      return void (await releases.update(found.id, (v) => ({
        ...v,
        state: "failed",
        reason: `announced again as #${signed.record.namespace}, after #${r.namespace}: a version names one release`,
      })));
    await releases.update(found.id, (v) => {
      const { reason: _, ...kept } = v;
      return { ...kept, ...releaseFields(signed.record), cid: signed.cid, state: "mirrored" };
    });
  } catch (e) {
    if (e instanceof NoSuchRecord) {
      if (r.verifiedAt === undefined) {
        for (const u of await uses.find({ uri })) await uses.delete(u.id);
        await releases.delete(found.id);
      } else
        await releases.update(found.id, (v) => ({
          ...v,
          state: "withdrawn",
          reason: "its author deleted the record",
        }));
      return;
    }
    // (a record there that doesn't check out now: what the registry checked before stands)
    if (!(e instanceof NotTheirs)) throw e;
  }
}

uses

used by