export function topologicalSortWorkItems(items) {
    const byId = new Map(items.map((item) => [item.id, item]));
    const visited = new Set();
    const visiting = new Set();
    const result = [];
    function visit(item) {
        if (visited.has(item.id))
            return;
        if (visiting.has(item.id))
            return;
        visiting.add(item.id);
        item.dependsOn.forEach((dependencyId) => {
            const dependency = byId.get(dependencyId);
            if (dependency)
                visit(dependency);
        });
        visiting.delete(item.id);
        visited.add(item.id);
        result.push(item);
    }
    items.forEach(visit);
    return result;
}
