UNPKG

@kamilkisiela/dependency-graph

Version:
94 lines 3.25 kB
export interface Options { circular?: boolean; } export declare class DepGraph<T> { private nodes; private outgoingEdges; private incomingEdges; private circular; constructor(opts?: Options); /** * The number of nodes in the graph. */ size(): number; /** * Add a node to the dependency graph. If a node already exists, this method will do nothing. */ addNode(name: string, data?: T): void; /** * Remove a node from the dependency graph. If a node does not exist, this method will do nothing. */ removeNode(name: string): void; /** * Check if a node exists in the graph */ hasNode(name: string): boolean; /** * Get the data associated with a node name */ getNodeData(name: string): string | T; /** * Set the associated data for a given node name. If the node does not exist, this method will throw an error */ setNodeData(name: string, data?: T): void; /** * Add a dependency between two nodes. If either of the nodes does not exist, * an Error will be thrown. */ addDependency(from: string, to: string): boolean; /** * Remove a dependency between two nodes. */ removeDependency(from: string, to: string): void; /** * Get an array containing the direct dependencies of the specified node. * * Throws an Error if the specified node does not exist. */ directDependenciesOf(name: string): string[]; /** * Get an array containing the nodes that directly depend on the specified node. * * Throws an Error if the specified node does not exist. */ directDependantsOf(name: string): string[]; /** * Get an array containing the nodes that the specified node depends on (transitively). * * Throws an Error if the graph has a cycle, or the specified node does not exist. * * If `leavesOnly` is true, only nodes that do not depend on any other nodes will be returned * in the array. */ dependenciesOf(name: string, leavesOnly?: boolean): string[]; /** * get an array containing the nodes that depend on the specified node (transitively). * * Throws an Error if the graph has a cycle, or the specified node does not exist. * * If `leavesOnly` is true, only nodes that do not have any dependants will be returned in the array. */ dependantsOf(name: string, leavesOnly?: boolean): string[]; /** * Construct the overall processing order for the dependency graph. * * Throws an Error if the graph has a cycle. * * If `leavesOnly` is true, only nodes that do not depend on any other nodes will be returned. */ overallOrder(leavesOnly?: boolean): string[]; /** * Get an array of nodes that have no dependants (i.e. nothing depends on them). */ entryNodes(): string[]; directDependentsOf: (name: string) => string[]; dependentsOf: (name: string, leavesOnly?: boolean) => string[]; } /** * Cycle error, including the path of the cycle. */ export declare class DepGraphCycleError extends Error { cyclePath: string[]; constructor(cyclePath: string[]); } //# sourceMappingURL=index.d.ts.map