import { Plugin } from './types'; // A utils function that toplogical sort plugins export function topologicalSort(pluginInstancesMap: Map, pluginDepEdgeList: [string, string][]): string[] { const res: string[] = []; const indegree: Map = new Map(); pluginDepEdgeList.forEach(([to]) => { indegree.set(to, (indegree.get(to) ?? 0) + 1); }); const queue: string[] = []; for (const [name] of pluginInstancesMap) { if (!indegree.has(name)) { queue.push(name); } } while(queue.length) { const cur = queue.shift()!; res.push(cur); for (const [to, from] of pluginDepEdgeList) { if (from === cur) { indegree.set(to, (indegree.get(to) ?? 0) - 1); if (indegree.get(to) === 0) { queue.push(to); } } } } return res; }