UNPKG

sicua

Version:

A tool for analyzing project structure and dependencies

255 lines (254 loc) 7.02 kB
/** * Component Flow Analysis Types * Defines all interfaces and types for component flow analysis */ export interface ComponentFlowNode { componentName: string; filePath: string; isExternal: boolean; conditionalRenders: ConditionalRender[]; children: ComponentFlowNode[]; } export interface ConditionalRender { conditionType: ConditionalType; condition: string; trueBranch: ComponentFlowNode[]; falseBranch?: ComponentFlowNode[]; position: CodePosition; htmlElementsTrue?: HTMLElementReference[]; htmlElementsFalse?: HTMLElementReference[]; } export type ConditionalType = "ternary" | "logical_and" | "if_statement" | "switch_statement" | "early_return"; export interface CodePosition { line: number; column: number; startOffset: number; endOffset: number; } export interface RouteFlowTree { routePath: string; pageComponent: ComponentFlowNode; specialFiles: SpecialFileCoverage; metadata: RouteMetadata; } export interface SpecialFileCoverage { layout: SpecialFileInfo[]; template: SpecialFileInfo | null; error: SpecialFileInfo | null; loading: SpecialFileInfo | null; notFound: SpecialFileInfo | null; } export interface SpecialFileInfo { exists: boolean; filePath?: string; routeSegment: string; } export interface RouteMetadata { isDynamic: boolean; isCatchAll: boolean; routeGroup?: string; depth: number; segments: string[]; } export interface ComponentFlowAnalysisResult { routes: RouteFlowTree[]; summary: FlowAnalysisSummary; externalDependencies: ExternalDependency[]; } export interface FlowAnalysisSummary { totalRoutes: number; totalComponents: number; totalConditionalRenders: number; routesWithMissingSpecialFiles: string[]; mostComplexRoute: string; averageComponentDepth: number; } export interface ExternalDependency { name: string; usedInRoutes: string[]; usageCount: number; } export interface JSXReturnStatement { hasConditional: boolean; conditionalPatterns: ConditionalPattern[]; componentReferences: ComponentReference[]; htmlElementReferences: HTMLElementReference[]; position: CodePosition; } export interface ConditionalPattern { type: ConditionalType; condition: string; trueBranch: ComponentReference[]; falseBranch?: ComponentReference[]; htmlElementsTrue: HTMLElementReference[]; htmlElementsFalse?: HTMLElementReference[]; position: CodePosition; } export interface ComponentReference { name: string; isJSXElement: boolean; props: PropReference[]; position: CodePosition; } export interface HTMLElementReference { tagName: string; props: PropReference[]; hasChildren: boolean; textContent?: string; position: CodePosition; } export interface PropReference { name: string; value: string; isDynamic: boolean; } export interface FileFlowAnalysis { filePath: string; componentName: string; jsxReturns: JSXReturnStatement[]; hasMultipleReturns: boolean; imports: ImportReference[]; } export interface ImportReference { name: string; source: string; isDefault: boolean; isNamespace: boolean; localName: string; } export interface RouteStructure { routePath: string; pageFilePath: string; segments: RouteSegment[]; metadata: RouteMetadata; } export interface RouteSegment { name: string; isDynamic: boolean; isCatchAll: boolean; isRouteGroup: boolean; specialFiles: SpecialFileCoverage; depth: number; } export interface ComponentFlowConfig { maxDepth: number; includeExternalComponents: boolean; excludePatterns: string[]; onlyAnalyzeRoutes: string[]; includeHtmlElements: boolean; htmlElementFilter: HTMLElementFilter; } export interface HTMLElementFilter { includeAll: boolean; includeTags: string[]; excludeTags: string[]; captureTextContent: boolean; maxTextLength: number; } export interface FlowAnalysisError { type: "parsing_error" | "resolution_error" | "file_not_found" | "invalid_jsx"; message: string; filePath: string; position?: CodePosition; } export interface ValidationResult { isValid: boolean; errors: FlowAnalysisError[]; warnings: string[]; } export type ElementReference = ComponentReference | HTMLElementReference; export declare function isComponentReference(ref: ElementReference): ref is ComponentReference; export declare function isHTMLElementReference(ref: ElementReference): ref is HTMLElementReference; export declare const DEFAULT_HTML_ELEMENT_FILTER: HTMLElementFilter; /** * Enhanced flow tree with additional metadata */ export interface EnhancedRouteFlowTree extends RouteFlowTree { coverageAnalysis: RouteCoverageAnalysis; componentStats: ComponentTreeStats; visualizationData: VisualizationMetadata; } /** * Statistics about the component tree */ export interface ComponentTreeStats { totalComponents: number; externalComponents: number; internalComponents: number; maxDepth: number; conditionalRenderCount: number; uniqueComponents: Set<string>; componentsByDepth: Map<number, string[]>; } /** * Metadata for visualization purposes */ export interface VisualizationMetadata { nodeCount: number; edgeCount: number; clusterInfo: ClusterInfo[]; layoutHints: LayoutHints; } /** * Cluster information for grouping related components */ export interface ClusterInfo { clusterId: string; clusterType: "conditional" | "external" | "internal" | "special_file"; componentNames: string[]; depth: number; } /** * Layout hints for visualization */ export interface LayoutHints { suggestedLayout: "hierarchical" | "force" | "circular"; primaryFlow: "vertical" | "horizontal"; groupings: { [key: string]: string[]; }; } /** * Coverage analysis results for a single route */ export interface RouteCoverageAnalysis { routePath: string; routeMetadata: RouteMetadata; specialFilesCoverage: SpecialFileCoverage; coverageMetrics: CoverageMetrics; recommendations: CoverageRecommendation[]; riskAssessment: RiskLevel; } /** * Coverage metrics for a route */ export interface CoverageMetrics { totalRequiredFiles: number; existingFiles: number; missingFiles: string[]; coveragePercentage: number; layoutCoverage: { total: number; existing: number; missing: string[]; }; errorHandlingCoverage: { hasErrorBoundary: boolean; hasNotFound: boolean; hasLoading: boolean; }; } /** * Coverage recommendation */ export interface CoverageRecommendation { type: "missing_file" | "best_practice" | "performance" | "user_experience"; priority: "high" | "medium" | "low"; message: string; filePath?: string; action: string; } /** * Risk assessment levels */ export type RiskLevel = "low" | "medium" | "high" | "critical";