UNPKG

histoire

Version:

A fast story book powered by Vite

29 lines (28 loc) • 1.21 kB
/** The index of a selector that has not analyzed anything yet. */ export const EMPTY_INDEX = { known: false, stories: new Map(), owners: new Map(), storyFiles: new Map(), unresolved: new Set() }; /** * Builds a detached index from a finished analysis. * @param storyFiles Collected story files the analysis covered. * @param evidence Per-story evidence of that analysis; absent stories become unresolved. */ export function buildEvidenceIndex(storyFiles, evidence) { const stories = new Map(); const owners = new Map(); for (const [storyId, proof] of evidence) { stories.set(storyId, { files: new Set(proof.files), leaves: new Map(proof.leaves) }); for (const file of proof.files) { let set = owners.get(file); if (!set) owners.set(file, set = new Set()); set.add(storyId); } } const byFile = new Map(); const unresolved = new Set(); for (const { path, storyId } of storyFiles) { byFile.set(path, [...byFile.get(path) ?? [], storyId]); if (!stories.has(storyId)) unresolved.add(storyId); } return { known: true, stories, owners, storyFiles: byFile, unresolved }; }