fetchAnnounced

tcmts.cli.libraries.fetchAnnounced · #ovszqziy · term · runs anywhere

Fetch a release who announced (what: geo@1.2.0, or geo for its highest version): found among their codes.tcm.release records, its namespace fetched by hash from the record's sources (first ahead of them, also after), and checked by re-hashing as it arrives.

import { resolveAnnounced } from "#codebase/tcmts/cli/announce";
import type { Codebase } from "#codebase/tcmts/cli/codebase";
import { fetchFromSources } from "#codebase/tcmts/cli/libraries";

export async function fetchAnnounced(
  cb: Codebase,
  who: string,
  what: string,
  o: { first?: string | undefined; also?: string[] } = {},
): Promise<{
  found: { namespace: string; release: string };
  from: string;
  received: number;
  sources: string[];
  did: string;
  handle?: string;
}> {
  const { id, record } = await resolveAnnounced(who, what);
  const sources = [
    ...new Set([...(o.first ? [o.first] : []), ...record.sources, ...(o.also ?? [])]),
  ];
  const { found, from, received } = await fetchFromSources(cb, sources, `#${record.namespace}`);
  return {
    found: { namespace: found.namespace, release: `${record.package}@${record.version}` },
    from,
    received,
    sources,
    did: id.did,
    ...(id.handle ? { handle: id.handle } : {}),
  };
}

uses

used by