librariesOfRemote

tcmts.hub.librariesOfRemote · #uo5hovqx · term · runs on the server

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

The libraries a codebase's main branch holds, by libraryKey, from its library records (outermost only, as tcm lib lists them): each by its author's DID and package where it was added as an announced release, else by its namespace, if the hub has a release of it.

import { librariesOf, RECORD } from "#codebase/tcmts/cli/libraries";
import type { Remote } from "#codebase/tcmts/cli/sync";
import { libraryKey, releases } from "#codebase/tcmts/hub";

export async function librariesOfRemote(
  remote: Pick<Remote, "branch" | "get">,
): Promise<Set<string>> {
  const out = new Set<string>();
  const rows = (await remote.branch("main"))?.names ?? [];
  const records = rows.filter(
    (n) => n.kind === "file" && n.path.slice(n.path.lastIndexOf(".") + 1) === RECORD,
  );
  const texts = new Map(
    (records.length ? await remote.get(records.map((r) => r.hash)) : []).map((d) => [
      d.hash,
      d.sourceText,
    ]),
  );
  for (const l of librariesOf(rows, (h) => texts.get(h) ?? "")) {
    const pkg = l.release?.slice(0, l.release.lastIndexOf("@"));
    if (l.did && pkg) out.add(libraryKey({ did: l.did, package: pkg }));
    else {
      const r = (await releases.find({ namespace: l.namespace })).map((x) => x.value)[0];
      if (r) out.add(libraryKey(r));
    }
  }
  return out;
}

uses

used by