import type { ContainerAsset } from './Asset'; import { findAsset, type Project } from './Project'; /** * Whether `wantedId` is that container or sits somewhere in its content. Editing a container's * template can place containers into it, and a cycle would expand forever the moment one of them * is resolved. */ export function containerReaches(project: Project, asset: ContainerAsset, wantedId: string): boolean { if (asset.id === wantedId) return true; const seen = new Set([asset.id]); const queue = [asset]; for (const current of queue) { for (const template of current.objects) { const nested = findAsset(project, template.assetId); if (nested?.type !== 'container' || seen.has(nested.id)) continue; if (nested.id === wantedId) return true; seen.add(nested.id); queue.push(nested); } } return false; }