libraryRows
uses tcmts.cli.libraries.libraryEffects, which uses tcmts.loader.packages.ensureExternals, which uses node:fs
The libraries the branch cb holds, as tcm lib lists them: what each is, who announced it, where it's fetched
from, what it reaches, what uses it, and what its author and the people the codebase trusts say of it.
import { attestationsFor, attesterNames } from "#codebase/tcmts/cli/attest"; import type { Codebase } from "#codebase/tcmts/cli/codebase"; import { announcer, EFFECT_WORDS, librariesIn, libraryEffects, libraryLabel, mountedAsAdded, mountedRows, usersOf, } from "#codebase/tcmts/cli/libraries"; import type { Effect } from "#codebase/tcmts/core/effects"; import { librarySayings } from "#codebase/tcmts/studio"; import type { LibraryRow } from "#codebase/tcmts/studio"; export async function libraryRows(cb: Codebase): Promise<LibraryRow[]> { const order = { yank: 0, advisory: 1, review: 2 } as const; const out: LibraryRow[] = []; for (const l of librariesIn(cb.store)) { const { reaches, unknown } = libraryEffects(cb, mountedRows(cb.store, l)); const key = `${l.namespace} ${l.did ?? ""}`; let known = librarySayings.get(key); if (!known || Date.now() - known.at > 600_000) { const who = attesterNames(cb, l); // (what someone else wrote, as text: no control characters) // eslint-disable-next-line no-control-regex const plain = (s: string) => s.replace(/[\u0000-\u0009\u000b-\u001f\u007f-\u009f]/g, ""); const found = await attestationsFor(cb, [l.namespace], l.did).catch(() => []); known = { at: Date.now(), said: [...found] .sort((x, y) => order[x.kind] - order[y.kind] || y.createdAt.localeCompare(x.createdAt)) .map((a) => ({ kind: a.kind, who: who(a.did), text: plain(a.body), ...(a.severity ? { severity: plain(a.severity) } : {}), ...(a.fixedIn ? { fixedIn: plain(a.fixedIn) } : {}), })), }; librarySayings.set(key, known); } out.push({ path: l.path, label: libraryLabel(l), ...(l.did ? { by: announcer(l) } : {}), sources: l.sources, reaches: (Object.keys(EFFECT_WORDS) as Effect[]) .filter((e) => reaches.has(e)) .map((e) => EFFECT_WORDS[e]), unknown, changed: !mountedAsAdded(cb.store, l), users: usersOf(cb.store, l), said: known.said, }); } return out; }
uses
- tcmts.cli.attest.attestationsFor
- tcmts.cli.attest.attesterNames
- tcmts.cli.codebase.Codebase
- tcmts.cli.libraries.EFFECT_WORDS
- tcmts.cli.libraries.announcer
- tcmts.cli.libraries.librariesIn
- tcmts.cli.libraries.libraryEffects
- tcmts.cli.libraries.libraryLabel
- tcmts.cli.libraries.mountedAsAdded
- tcmts.cli.libraries.mountedRows
- tcmts.cli.libraries.usersOf
- tcmts.core.effects.Effect
- tcmts.studio.LibraryRow
- tcmts.studio.librarySayings