UNPKG

datapilot-cli

Version:

Enterprise-grade streaming multi-format data analysis with comprehensive statistical insights and intelligent relationship detection - supports CSV, JSON, Excel, TSV, Parquet - memory-efficient, cross-platform

278 lines 8.73 kB
/** * Ultra-Advanced Dependency Graph System for CLI Analyzers * Handles complex dependency resolution, circular detection, memory optimization, and conditional execution */ import type { SectionResultMap, DependencyResolver, CLIOptions } from './types'; import type { LogContext } from '../utils/logger'; /** * Execution plan for dependency resolution */ export interface ExecutionPlan { order: string[]; memoryOptimized: boolean; conditionalSkips: string[]; parallelGroups: string[][]; estimatedMemoryPeak: number; } /** * Advanced dependency graph with topological sorting, cycle detection, and memory optimization */ export declare class DependencyGraph { private nodes; private resolved; private resolving; private executionHistory; private memoryThreshold; constructor(memoryThreshold?: number); /** * Initialize the default section dependency graph */ private initializeDefaultNodes; /** * Add a node to the dependency graph */ addNode(id: string, dependencies?: string[], optional?: boolean, weight?: number, condition?: (options: CLIOptions) => boolean): void; /** * Detect circular dependencies using DFS */ detectCircularDependencies(): { hasCircles: boolean; cycles: string[][]; }; /** * Generate optimal execution plan using modified Kahn's algorithm with memory optimization */ generateExecutionPlan(requestedSections: string[], options: CLIOptions): ExecutionPlan; /** * Expand requested sections to include all required dependencies */ private expandDependencies; /** * Topological sort using Kahn's algorithm with memory-aware ordering */ private topologicalSort; /** * Select next node for execution based on memory optimization */ private selectNextNode; /** * Calculate optimization score for node selection */ private calculateNodeScore; /** * Insert node into queue maintaining sorted order by weight */ private insertSorted; /** * Identify sections that can execute in parallel */ private identifyParallelGroups; /** * Check if execution order is memory optimized */ private isMemoryOptimized; /** * Estimate peak memory usage for execution plan */ private estimateMemoryPeak; /** * Record execution time for future optimization */ recordExecutionTime(sectionId: string, timeMs: number): void; /** * Get dependency graph visualization for debugging */ getGraphVisualization(): string; /** * Validate specific dependency requirements */ validateDependencies(requestedSections: string[]): { isValid: boolean; errors: string[]; warnings: string[]; }; } /** * Concrete implementation of dependency resolver with caching and validation */ export declare class AnalyzerDependencyResolver implements DependencyResolver { private dependencies; private resolverFunctions; private context; private dependencyGraph; private currentExecutionPlan?; private options; constructor(context?: LogContext, options?: CLIOptions); /** * Generate optimal execution plan for requested sections */ planExecution(requestedSections: string[]): ExecutionPlan; /** * Get current execution plan */ getExecutionPlan(): ExecutionPlan | undefined; /** * Check if parallel execution is possible for given sections */ canExecuteInParallel(sectionA: string, sectionB: string): boolean; /** * Register resolver function for a section */ registerResolver<K extends keyof SectionResultMap>(sectionName: K, resolver: () => Promise<SectionResultMap[K]>): void; /** * Resolve a specific section dependency with error handling and performance tracking */ resolve<K extends keyof SectionResultMap>(sectionName: K): Promise<SectionResultMap[K]>; /** * Calculate adaptive timeout based on historical execution data */ private calculateTimeoutForSection; /** * Execute resolver with timeout protection */ private executeWithTimeout; /** * Validate that a section result has the expected structure */ private validateSectionResult; /** * Get validation rules for a specific section */ private getSectionValidationRules; /** * Check if object has a property using safe property access */ private hasProperty; /** * Cache a section result with metadata */ cache<K extends keyof SectionResultMap>(sectionName: K, result: SectionResultMap[K]): void; /** * Clear all cached dependencies */ clear(): void; /** * Check if a section is already cached */ has(sectionName: string): boolean; /** * Get all cached section names */ getCachedSections(): string[]; /** * Get dependency resolution statistics */ getStats(): { totalCached: number; cachedSections: string[]; oldestCache?: Date; newestCache?: Date; }; /** * Resolve multiple dependencies using optimal execution plan */ resolveMultiple<K extends keyof SectionResultMap>(sectionNames: K[]): Promise<Record<K, SectionResultMap[K]>>; /** * Execute sections in parallel groups for optimal performance */ private executeParallelPlan; /** * Execute sections sequentially using optimal order */ private executeSequentialPlan; /** * Perform just-in-time memory cleanup of cached results */ private performJustInTimeCleanup; /** * Get the recommended resolution order for given sections using dependency graph */ getResolutionOrder(sectionNames: string[]): string[]; /** * Check if all dependencies for a section are available */ canResolve(sectionName: string): { canResolve: boolean; missingDependencies: string[]; }; /** * Get detailed dependency information with graph insights */ getDependencyInsights(): { graphVisualization: string; executionStats: any; memoryOptimization: boolean; recommendations: string[]; }; /** * Validate execution readiness for given sections */ validateExecutionReadiness(sectionNames: string[]): { ready: boolean; issues: string[]; warnings: string[]; executionPlan?: ExecutionPlan; }; /** * Access dependency graph for advanced operations */ getDependencyGraph(): DependencyGraph; } /** * Factory function to create a configured dependency resolver with enhanced features */ export declare function createDependencyResolver(filePath: string, options: CLIOptions, context?: LogContext): AnalyzerDependencyResolver; /** * Enhanced dependency chain validator that leverages the new dependency graph system * @deprecated Use DependencyGraph directly for more advanced features */ export declare class DependencyChainValidator { private dependencyGraph; constructor(options?: CLIOptions); /** * Validate that all dependencies can be resolved for the given sections */ validateChain(requestedSections: string[]): { isValid: boolean; errors: string[]; warnings: string[]; }; /** * Get the optimal execution order for the given sections */ getExecutionOrder(requestedSections: string[], options?: CLIOptions): string[]; /** * Get advanced execution plan with memory optimization and parallel groups */ getAdvancedExecutionPlan(requestedSections: string[], options?: CLIOptions): ExecutionPlan; /** * Check for circular dependencies */ checkCircularDependencies(): { hasCircles: boolean; cycles: string[][]; }; /** * Get dependency graph visualization */ getGraphVisualization(): string; } /** * Create a dependency resolver with pre-configured analyzers for common use cases */ export declare function createConfiguredDependencyResolver(filePath: string, options: CLIOptions, context?: LogContext): { resolver: AnalyzerDependencyResolver; executionPlan: ExecutionPlan | null; insights: any; }; /** * Utility function to validate section dependencies without creating a resolver */ export declare function validateSectionDependencies(requestedSections: string[], options?: CLIOptions): { isValid: boolean; errors: string[]; warnings: string[]; recommendedOrder: string[]; memoryEstimate: number; }; //# sourceMappingURL=dependency-resolver.d.ts.map