Sortable import type {Sortable} from '@fuzdev/fuz_util/sort.js'; Minimum shape required for topological sorting.
id
type string
depends_on?
type Array<string>
Generic topological sort using Kahn's algorithm.
Orders items so that dependencies come before dependents.
Works with any item type that has id and optional depends_on.
3 declarations
Sortable import type {Sortable} from '@fuzdev/fuz_util/sort.js'; Minimum shape required for topological sorting.
idtype string
depends_on?type Array<string>
<T extends Sortable>(items: T[], label?: string): TopologicalSortResult<T> import {topological_sort} from '@fuzdev/fuz_util/sort.js'; Sort items by their dependencies using Kahn's algorithm.
Returns items ordered so that dependencies come before dependents. If a cycle is detected, returns an error with the cycle path.
itemsarray of items to sort
T[]labellabel for error messages (e.g. "resource", "step")
string'item'TopologicalSortResult<T> sorted items or error if cycle detected
topological_sort<T extends Sortable>TTopologicalSortResult<T> import type {TopologicalSortResult} from '@fuzdev/fuz_util/sort.js'; Result of topological sort.
TopologicalSortResult<T extends Sortable>T