sendClosure
uses tcmts.cli.sync.componentBatches, which uses Buffer
Send whatever the remote lacks of the components needed for hashes: what each uses before it (the receiver
checks every reference resolves), in requests of a bounded size, however much there is.
import type { Codebase } from "#codebase/tcmts/cli/codebase"; import { chunks, componentBatches } from "#codebase/tcmts/cli/sync"; import type { Remote } from "#codebase/tcmts/cli/sync"; export async function sendClosure(cb: Codebase, remote: Remote, hashes: string[]): Promise<number> { const comps = [...cb.closureComponents(hashes)]; const missing: string[] = []; for (const c of chunks(comps)) missing.push(...(await remote.missing(c))); // what a component uses, before it (components hold any cycle, so the graph they make has none) // (each as first stored: the texts names show go with the history naming them) const records = missing.flatMap((c) => cb.store.componentMembers(c).map((m) => cb.store.defWithText(m.hash, undefined)!), ); if (!records.length) return 0; // the versions the code runs on go first: the other side verifies it on them await remote.putPackages(cb.packagesUsedBy(records)); for (const batch of componentBatches(records)) await remote.put(batch); return records.length; }
uses
- tcmts.cli.codebase.Codebase
- tcmts.cli.sync.Remote
- tcmts.cli.sync.chunks
- tcmts.cli.sync.componentBatches