/** * @angular-modernizer/plugin-angular - Data Handling Strategy Rule * * Detects inefficient client-side data processing and recommends server-side alternatives. * * Detection Patterns: * - Large table datasets processed client-side (pagination, filtering, sorting) * - Complex chained data transformations in components * - Components not connected to server-side pagination * * Rule ID: plugin-angular:data-handling-strategy * Severity: warning | Category: runtime-architecture */ import type { AnalysisRule, AnalysisContext, AnalysisResult } from '@angular-modernizer/plugin-system'; /** * Configuration for data handling strategy thresholds. * These thresholds determine when client-side processing should be flagged * as inefficient and moved to server-side processing. */ export interface DataHandlingStrategyConfig { /** Threshold for client-side table processing (default: 1000 records) */ clientSideTableThreshold: number; /** Threshold for client-side filtering (default: 500 records) */ clientSideFilterThreshold: number; /** Threshold for client-side sorting (default: 500 records) */ clientSideSortThreshold: number; /** Threshold for complex transformation chains (default: 2 operations) */ complexTransformationThreshold: number; } /** * Rule that detects inefficient data handling strategies in Angular components. * * This rule identifies common performance anti-patterns where large datasets * are processed client-side instead of server-side, which can cause: * - Slow initial page loads * - High memory usage * - Poor user experience on low-end devices * - Excessive network traffic * * The rule suggests moving operations like filtering, sorting, and pagination * to the server when dealing with datasets above configurable thresholds. * * Implementation uses functional programming patterns throughout: * - Method chaining for data transformation pipelines * - Optional chaining (?.) for safe AST navigation * - Array of pure functions for complex logic (e.g., offline detection) * - Strategy pattern for array size estimation * - Pure helper functions for better testability */ export declare class DataHandlingStrategyRule implements AnalysisRule { readonly id = "plugin-angular:data-handling-strategy"; readonly name = "Data Handling Strategy"; readonly description = "Detects inefficient data processing strategies and suggests server-side alternatives"; readonly severity = "warning"; readonly category = "runtime-architecture"; readonly tags: string[]; /** * Default configuration thresholds for data processing detection. * These can be overridden via the configure() method. */ private config; /** * Configures the rule with custom thresholds. * @param config - Partial configuration object to override defaults */ configure(config: Partial): void; /** * Main analysis entry point that runs all data handling strategy checks. * * This method orchestrates multiple detection strategies: * 1. Client-side table processing (large datasets in tables) * 2. Client-side filtering (array.filter() on large arrays) * 3. Client-side sorting (array.sort() on large arrays) * 4. Complex transformations (chained array operations) * 5. Missing server pagination (paginators without server-side logic) * * Each detection method uses functional programming patterns for better * testability and maintainability. * * @param context - Analysis context containing the source file to analyze * @returns Array of violations found in the source file */ analyze(context: AnalysisContext): Promise; /** * Detects client-side table processing that should be moved to server-side. * * This method uses a functional pipeline approach to: * 1. Find all class declarations in the source file * 2. Filter to only Angular components (classes with `` decorator) * 3. Filter to components that have table-like data structures * 4. Analyze HTTP calls to estimate data size * 5. Check offline capability context * 6. Filter to violations above threshold * 7. Create violation objects * * The functional approach makes the data flow clear and each step testable. * * @param context - The analysis context containing the source file to analyze. * @returns An array of analysis results for client-side table processing violations. */ private detectClientSideTableProcessing; /** * Determines if a class declaration is an Angular component. * Checks for the presence of a `` decorator. * * @param classDecl - The class declaration to check * @returns true if the class has a `` decorator */ private isComponentClass; /** * Checks if a component uses Angular Material's MatTableDataSource. * This indicates the component is working with tabular data that might be large. * Uses functional array methods (some) for concise checking. * @param classDecl - The component class to analyze * @returns true if the component has MatTableDataSource properties */ private hasTableDataSource; /** * Checks if a component has custom table-like structures. * Looks for array properties that are used in templates with *ngFor or elements. * * @param classDecl - The component class to analyze * @returns true if the component has custom table patterns */ private hasCustomTable; /** * Analyzes HTTP calls in a component to determine data size and presence. * Scans constructor and methods for HTTP calls and estimates data size from context. * Uses functional reduce pattern to accumulate results across all members. * @param classDecl - The component class to analyze * @returns Object with HTTP call presence and estimated data size */ private analyzeHttpCalls; /** * Creates a violation object for client-side table processing issues. * * @param classDecl - The component class declaration * @param className - The name of the component class * @param estimatedDataSize - The estimated size of the dataset * @param offlineContext - Context about offline capabilities * @param sourceFile - The source file being analyzed * @returns A structured violation object */ private createTableProcessingViolation; /** * Detects client-side filtering that should be moved to server-side. * * This method finds array.filter() calls on large datasets and suggests * moving the filtering logic to the server for better performance. * * @param context - The analysis context containing the source file to analyze. * @returns An array of analysis results for client-side filtering violations. */ private detectClientSideFiltering; /** * Finds all array.filter() call expressions in a class. * Used to identify client-side filtering operations. * * @param classDecl - The class declaration to search * @returns Array of filter call expressions found */ private findFilterCalls; /** * Estimates the size of an array being filtered. * Analyzes the property access expression to determine array size. * * @param filterCall - The filter call expression * @param classDecl - The class containing the filter call * @returns Estimated number of elements in the array */ private estimateFilterArraySize; /** * Creates a violation object for client-side filtering issues. * * @param classDecl - The component class declaration * @param className - The name of the component class * @param filterCall - The filter call expression * @param estimatedSize - The estimated size of the filtered array * @param offlineContext - Context about offline capabilities * @param sourceFile - The source file being analyzed * @returns A structured violation object */ private createFilteringViolation; /** * Detects client-side sorting that should be moved to server-side. * * This method finds array.sort() calls on large datasets and suggests * moving the sorting logic to the server for better performance. * * @param context - The analysis context containing the source file to analyze. * @returns An array of analysis results for client-side sorting violations. */ private detectClientSideSorting; /** * Finds all array.sort() call expressions in a class. * Used to identify client-side sorting operations. * * @param classDecl - The class declaration to search * @returns Array of sort call expressions found */ private findSortCalls; /** * Estimates the size of an array being sorted. * Analyzes the property access expression to determine array size. * * @param sortCall - The sort call expression * @param classDecl - The class containing the sort call * @returns Estimated number of elements in the array */ private estimateSortArraySize; /** * Creates a violation object for client-side sorting issues. * * @param classDecl - The component class declaration * @param className - The name of the component class * @param sortCall - The sort call expression * @param estimatedSize - The estimated size of the sorted array * @param offlineContext - Context about offline capabilities * @param sourceFile - The source file being analyzed * @returns A structured violation object */ private createSortingViolation; /** * Detects complex client-side data transformations that should be moved to server-side. * * This method finds chained array operations (map, filter, reduce, etc.) that * exceed complexity thresholds and suggests moving them to the server. * * @param context - The analysis context containing the source file to analyze. * @returns An array of analysis results for complex transformation violations. */ private detectComplexClientTransformations; /** * Finds complex array operations in a class. * Looks for map, reduce, flatMap, and groupBy operations that might be chained. * * @param classDecl - The class declaration to search * @returns Array of complex operation call expressions */ private findComplexOperations; private calculateOperationComplexity; private createTransformationViolation; private detectMissingServerPagination; private hasPaginatorOrCustomPagination; private hasServerPagination; private checkCallForPagination; private getComponentType; private createPaginationViolation; /** * Extracts the template from a component decorator using functional chaining. * Uses optional chaining to safely navigate the AST structure. * @param classDecl - The class declaration to extract the template from. * @returns The template string or null if not found. */ private getComponentTemplate; /** * Type guard to check if a decorator is a Component decorator. * @param decorator - The decorator to check * @returns True if the decorator is a Component decorator */ private isComponentDecorator; /** * Estimates the size of an array based on variable declarations and assignments. * Uses a functional pipeline approach with an array of strategy objects. * Each strategy has a predicate function to match AST patterns and an estimation function. * The first matching strategy is applied to estimate the array size. * @param node - The AST node to analyze for array size estimation * @param classDecl - The class declaration containing the node * @returns Estimated array size or 0 if cannot determine */ private estimateArraySize; /** * Estimates array size from property access expressions. * @param propAccess - The property access expression * @param classDecl - The class declaration to search for the property * @returns Estimated array size */ private estimateFromPropertyAccess; /** * Estimates array size from variable declarations. * @param identifier - The identifier to analyze * @returns Maximum estimated size from all matching declarations */ private estimateFromVariableDeclarations; /** * Checks if a type represents an array type. * @param type - The type or type node to check * @returns True if the type is an array type */ private isArrayType; /** * Estimates array size from a type annotation. * @param type - The type or type node to analyze * @returns Estimated size or 0 if not an array type */ private estimateFromTypeAnnotation; /** * Estimates array size from an initializer expression. * @param initializer - The initializer expression to analyze * @returns Estimated size or 0 if not an array literal */ private estimateFromInitializer; /** * Detects if a component is offline-capable based on various indicators. * Uses a functional approach with an array of check functions for better testability and maintainability. * Each check returns an OfflineContext if the component is offline-capable, or null otherwise. * The first positive result determines the offline capability. * @param component - The class declaration of the component. * @param className - The name of the component class. * @param filePath - The file path of the component. * @returns An OfflineContext object indicating offline capability. */ private detectOfflineContext; /** * Checks if the source file imports Angular Service Worker. * @param sourceFile - The source file to check for service worker imports * @returns True if service worker is imported */ private hasServiceWorkerImport; /** * Checks if the source file uses IndexedDB for offline storage. * @param sourceFile - The source file to check for IndexedDB usage * @returns True if IndexedDB is used */ private hasIndexedDBUsage; /** * Checks if the source file uses localStorage or sessionStorage. * @param sourceFile - The source file to check for storage usage * @returns True if local/session storage is used */ private hasLocalStorageUsage; /** * Checks if the source file contains offline synchronization patterns. * @param sourceFile - The source file to check for offline sync patterns * @returns True if offline sync patterns are detected */ private hasOfflineSyncPatterns; } //# sourceMappingURL=data-handling-strategy.rule.d.ts.map