// manifest-sources.mjs — the (channel, video) sources a manifest cites, as the // availability preflight counts them. A LEAF (no imports), so the preflight, // the driver that budgets its timeout, and the routes that build its step all // count the same thing without pulling the build into a request handler. /** * Every clip without its own `src` (a `src` clip is a file beside the * manifest, on no platform: the build checks it is there), and every ledger * claim with a video. A clip may name its own channel: the same id under a * different slug is a different file, so the unit is (channel, video). * * LEDGER SOURCES TOO, not just the clipped ones. A cut that stacks its * unclipped claims onto cards has to say WHY each one is a line of text rather * than footage, and "the upload is gone" and "we did not cut it" are different * sentences. Guessing which is which is how a live source ends up labelled * deleted on screen. * * @param {any} manifest * @returns {{ key: string, channel: string, video: string, clips: string[], claims: string[], entries: any[] }[]} */ export function manifestSources(manifest) { const slug = manifest?.provenance?.channelSlug; const wanted = new Map(); const want = (channel, video) => { const key = `${channel}/${video}`; if (!wanted.has(key)) wanted.set(key, { key, channel, video, clips: [], claims: [], entries: [] }); return wanted.get(key); }; for (const e of manifest?.timeline ?? []) { if (e?.type !== "clip" || e.src != null) continue; const w = want(e.channel ?? slug, e.video); w.clips.push(e.id); w.entries.push(e); } for (const c of manifest?.ledger ?? []) { if (!c?.video) continue; want(c.channel ?? slug, c.video).claims.push(c.id); } return [...wanted.values()]; } /** How many sources the preflight may have to probe. */ export const sourceCountOf = (manifest) => manifestSources(manifest).length;