validNames
Names from another codebase: paths must be valid (a file's as files are named: docs.getting-started) and every
hash must already be stored here; kinds come from the local store.
import { IDENT_PATH } from "#codebase/tcmts/cli/codebase"; import type { Codebase } from "#codebase/tcmts/cli/codebase"; import { FILE_PATH } from "#codebase/tcmts/cli/files"; import { shortHash } from "#codebase/tcmts/core/hash"; import type { NameRow } from "#codebase/tcmts/store"; export function validNames(cb: Codebase, names: NameRow[]): NameRow[] { return names.map((n) => { const rec = cb.store.getDef(n.hash); if (!rec) throw new Error(`${n.path} refers to ${shortHash(n.hash)}, which was not sent`); if (!(rec.kind === "file" ? FILE_PATH : IDENT_PATH).test(n.path)) throw new Error(`invalid name '${n.path}'`); return { path: n.path, hash: n.hash, kind: rec.kind }; }); }
uses
- tcmts.cli.codebase.Codebase
- tcmts.cli.codebase.IDENT_PATH
- tcmts.cli.files.FILE_PATH
- tcmts.core.hash.shortHash
- tcmts.store.NameRow