/** * @angular-modernizer/plugin-angular - Facade Pattern Orchestrator * * The central "brain" of the facade pattern plugin. * Orchestrates the extraction of complex component logic into facade services. * * Philosophy: "API-Driven Orchestration" * - Receives all capabilities via TransformContext * - Uses PublicApi for all AST operations * - Stateless - no constructor dependencies * - Pure business logic, no low-level manipulation */ import type { TransformContext } from '@angular-modernizer/plugin-system'; import type { PublicApi } from '@angular-modernizer/api'; /** * Configuration options for facade pattern extraction. */ export interface FacadePatternConfig { /** * Minimum number of methods to trigger facade extraction. * Default: 8 */ minMethodsForFacade?: number; /** * Minimum complexity score to trigger facade extraction. * Default: 50 */ minComplexityForFacade?: number; /** * Whether to create facade services. * Default: true */ createFacadeServices?: boolean; /** * Whether to update component to use facade services. * Default: true */ updateComponentUsage?: boolean; /** * Whether to add Injectable decorator to facade services. * Default: true */ addInjectableDecorator?: boolean; } /** * Facade Pattern Orchestrator * * @remarks * The central orchestrator for extracting complex component logic into facade services. * This class analyzes Angular components and extracts business logic into dedicated * facade services for better separation of concerns and maintainability. * * ## Architecture Pattern * * This orchestrator follows three core principles: * 1. **Stateless Design** - No constructor dependencies * 2. **Context-Driven** - All capabilities injected via {@link TransformContext} * 3. **API-First** - Uses {@link PublicApi} for all AST operations * * ## Facade Extraction Workflow * * The orchestrator performs the following transformations: * 1. Analyze components for complexity (method count, complexity score) * 2. Identify business logic methods to extract * 3. Create facade service with extracted methods * 4. Update component to inject and use facade service * 5. Update imports and dependencies * * ## Example Usage * * ```typescript * const orchestrator = new FacadePatternOrchestrator(); * const context = ContextFactory.createTransformContext({ * sourceFile, * project, * api, * config: { minMethodsForFacade: 10 } * }); * orchestrator.run(context); * ``` * * @see {@link TransformContext} for context structure * @see {@link PublicApi} for available API tools * @see {@link FacadePatternConfig} for configuration options * * @public */ export declare class FacadePatternOrchestrator { /** * Creates a new FacadePatternOrchestrator instance. * * @remarks * The constructor is intentionally stateless. All dependencies are provided * through the {@link TransformContext} passed to the {@link run} method. * This enables testing, composition, and prevents tight coupling. * * @public */ constructor(); /** * Executes the facade pattern extraction on a single source file. * * @remarks * This method is the main entry point for the orchestrator. It receives all * necessary dependencies (project, API, config) through the context parameter, * analyzes components for complexity, and extracts facade services as needed. * * The method operates on one source file at a time and is safe to call * multiple times. It will: * - Analyze component complexity * - Extract business logic into facade services * - Update component dependencies and usage * * ## Facade Extraction Behavior * * **Complexity Analysis**: * - Counts methods in component * - Calculates complexity score based on method bodies * - Identifies business logic vs. lifecycle methods * * **Facade Service Creation**: * - Creates new service file with extracted methods * - Adds @Injectable decorator * - Moves complex business logic from component * * **Component Updates**: * - Injects facade service in constructor * - Updates method calls to use facade service * - Removes extracted methods from component * * @param context - The transformation context containing: * - `sourceFile`: The TypeScript source file to analyze * - `project`: The ts-morph Project for cross-file operations * - `api`: The PublicApi with analysis and transformation tools * - `config`: User-provided configuration options * * @example * ```typescript * // Basic usage * orchestrator.run(context); * * // With custom configuration * const context = ContextFactory.createTransformContext({ * sourceFile, * project, * api, * config: { * minMethodsForFacade: 5, // Lower threshold * createFacadeServices: true, * } * }); * orchestrator.run(context); * ``` * * @see {@link TransformContext} for context structure * @see {@link FacadePatternConfig} for configuration options * * @public */ run(context: TransformContext): void; /** * Check if a component needs facade extraction. */ private needsFacadeExtraction; /** * Extract facade service for a complex component. */ private extractFacadeForComponent; /** * Analyze service dependencies used by extracted methods. */ private analyzeServiceDependencies; /** * Check if a class is an Angular component. */ private isAngularComponent; /** * Get business logic methods (excluding lifecycle hooks). */ private getBusinessMethods; /** * Calculate complexity score for methods. */ private calculateComplexityScore; /** * Create a facade service with extracted methods. */ private createFacadeService; /** * Generate facade service content. */ private generateFacadeServiceContent; /** * Add facade service to the source file. */ private addFacadeServiceToFile; /** * Update component to use facade service. */ private updateComponentToUseFacade; /** * Remove migrated services from component constructor. */ private removeMigratedServicesFromComponent; /** * Add facade service injection to constructor. */ private addFacadeInjection; /** * Replace method calls to use facade service. */ private replaceMethodCalls; /** * Convert PascalCase to camelCase. */ private toCamelCase; /** * Get facade configuration with defaults. */ private getFacadeConfig; } //# sourceMappingURL=facade-pattern-orchestrator.d.ts.map