index.d.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. declare module 'dependency-graph' {
  2. export interface Options {
  3. circular?: boolean;
  4. }
  5. export class DepGraph<T> {
  6. /**
  7. * Creates an instance of DepGraph with optional Options.
  8. */
  9. constructor(opts?: Options);
  10. /**
  11. * The number of nodes in the graph.
  12. */
  13. size(): number;
  14. /**
  15. * Add a node in the graph with optional data. If data is not given, name will be used as data.
  16. * @param {string} name
  17. * @param data
  18. */
  19. addNode(name: string, data?: T): void;
  20. /**
  21. * Remove a node from the graph.
  22. * @param {string} name
  23. */
  24. removeNode(name: string): void;
  25. /**
  26. * Check if a node exists in the graph.
  27. * @param {string} name
  28. */
  29. hasNode(name: string): boolean;
  30. /**
  31. * Get the data associated with a node (will throw an Error if the node does not exist).
  32. * @param {string} name
  33. */
  34. getNodeData(name: string): T;
  35. /**
  36. * Set the data for an existing node (will throw an Error if the node does not exist).
  37. * @param {string} name
  38. * @param data
  39. */
  40. setNodeData(name: string, data?: T): void;
  41. /**
  42. * Add a dependency between two nodes (will throw an Error if one of the nodes does not exist).
  43. * @param {string} from
  44. * @param {string} to
  45. */
  46. addDependency(from: string, to: string): void;
  47. /**
  48. * Remove a dependency between two nodes.
  49. * @param {string} from
  50. * @param {string} to
  51. */
  52. removeDependency(from: string, to: string): void;
  53. /**
  54. * Return a clone of the dependency graph (If any custom data is attached
  55. * to the nodes, it will only be shallow copied).
  56. */
  57. clone(): DepGraph<T>;
  58. /**
  59. * Get an array containing the nodes that the specified node depends on (transitively). If leavesOnly is true, only nodes that do not depend on any other nodes will be returned in the array.
  60. * @param {string} name
  61. * @param {boolean} leavesOnly
  62. */
  63. dependenciesOf(name: string, leavesOnly?: boolean): string[];
  64. /**
  65. * Get an array containing the nodes that depend on the specified node (transitively). If leavesOnly is true, only nodes that do not have any dependants will be returned in the array.
  66. * @param {string} name
  67. * @param {boolean} leavesOnly
  68. */
  69. dependantsOf(name: string, leavesOnly?: boolean): string[];
  70. /**
  71. * Construct the overall processing order for the dependency graph. If leavesOnly is true, only nodes that do not depend on any other nodes will be returned.
  72. * @param {boolean} leavesOnly
  73. */
  74. overallOrder(leavesOnly?: boolean): string[];
  75. }
  76. }