markmv
Version:
TypeScript CLI for markdown file operations with intelligent link refactoring
83 lines • 2.81 kB
TypeScript
import type { ParsedMarkdownFile } from '../types/links.js';
/**
* Represents a node in the markdown file dependency graph.
*
* Each node contains metadata about a markdown file and its relationships to other files through
* links and references. Used for dependency analysis, topological sorting, and impact assessment
* during file operations.
*
* @category Core
*/
export interface FileNode {
/** Absolute file path */
path: string;
/** Parsed markdown data */
data: ParsedMarkdownFile;
/** Files this file directly depends on */
dependencies: Set<string>;
/** Files that directly depend on this file */
dependents: Set<string>;
}
/**
* Builds and analyzes dependency relationships between markdown files.
*
* The DependencyGraph tracks file relationships through links, references, and imports to enable
* intelligent file operations. It supports cycle detection, topological sorting, impact analysis,
* and dependency-aware ordering for operations like joining and splitting.
*
* @category Core
*
* @example
* Building a dependency graph
* ```typescript
* const graph = new DependencyGraph();
*
* // Add files to the graph
* await graph.addFile('intro.md');
* await graph.addFile('setup.md');
* await graph.addFile('usage.md');
*
* // Analyze dependencies
* const order = graph.getTopologicalOrder();
* console.log('Processing order:', order);
*
* // Check for circular dependencies
* const cycles = graph.detectCycles();
* if (cycles.length > 0) {
* console.warn('Circular dependencies detected');
* }
* ```
*
* @example
* Impact analysis
* ```typescript
* const graph = new DependencyGraph(parsedFiles);
*
* // Find all files affected by changing api.md
* const impacted = graph.getImpactedFiles('api.md');
* console.log(`${impacted.length} files will be affected`);
* ```
*/
export declare class DependencyGraph {
private nodes;
private edges;
constructor(files?: ParsedMarkdownFile[]);
build(files: ParsedMarkdownFile[]): void;
addNode(file: ParsedMarkdownFile): void;
addDependencies(file: ParsedMarkdownFile): void;
private updateDependents;
getNode(filePath: string): FileNode | undefined;
getDependencies(filePath: string): string[];
getDependents(filePath: string): string[];
getTransitiveDependencies(filePath: string): string[];
getTransitiveDependents(filePath: string): string[];
detectCircularDependencies(): string[][];
topologicalSort(): string[];
updateFilePath(oldPath: string, newPath: string): void;
removeNode(filePath: string): void;
clear(): void;
getAllFiles(): string[];
size(): number;
toJSON(): Record<string, string[]>;
}
//# sourceMappingURL=dependency-graph.d.ts.map