/** * @angular-modernizer/plugin-angular - Form Modernization Orchestrator * * The central "brain" of the form modernization plugin. * Orchestrates the modernization of Angular reactive forms to current best practices. * * 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 form modernization. */ export interface FormModernizationConfig { /** * Whether to convert FormBuilder usage to direct FormGroup/FormControl instantiation. * Default: true */ convertFormBuilder?: boolean; /** * Whether to modernize FormControl initialization (e.g., null to empty string). * Default: true */ modernizeFormControlInit?: boolean; /** * Whether to update validation patterns to current best practices. * Default: true */ updateValidationPatterns?: boolean; /** * Whether to convert ngOnInit form initialization to property initialization. * Default: true */ convertNgOnInitForms?: boolean; } /** * Form Modernization Orchestrator * * @remarks * The central orchestrator for modernizing Angular reactive forms. This class * transforms legacy reactive forms patterns to current Angular best practices. * * ## 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 * * ## Modernization Workflow * * The orchestrator performs the following transformations: * 1. Detect FormBuilder usage in constructors and ngOnInit * 2. Convert FormBuilder.group() calls to new FormGroup() instantiation * 3. Convert FormBuilder.control() calls to new FormControl() instantiation * 4. Modernize FormControl initialization values * 5. Update validation patterns * 6. Convert ngOnInit form initialization to property initialization * 7. Update imports as needed * * ## Example Usage * * ```typescript * const orchestrator = new FormModernizationOrchestrator(); * const context = ContextFactory.createTransformContext({ * sourceFile, * project, * api, * config: { convertFormBuilder: true } * }); * orchestrator.run(context); * ``` * * @see {@link TransformContext} for context structure * @see {@link PublicApi} for available API tools * @see {@link FormModernizationConfig} for configuration options * * @public */ export declare class FormModernizationOrchestrator { /** * Creates a new FormModernizationOrchestrator 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 form modernization 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, * scans the file for reactive forms patterns, and modernizes them. * * The method operates on one source file at a time and is safe to call * multiple times. It will: * - Detect FormBuilder usage and convert to direct instantiation * - Modernize FormControl initialization * - Update validation patterns * - Convert ngOnInit form setup to property initialization * * ## Modernization Behavior * * **FormBuilder Conversion**: * - `this.fb.group({...})` → `new FormGroup({...})` * - `this.fb.control(...)` → `new FormControl(...)` * - `this.fb.array(...)` → `new FormArray(...)` * * **FormControl Initialization**: * - `new FormControl(null)` → `new FormControl('')` * - `new FormControl(undefined)` → `new FormControl('')` * * **Validation Patterns**: * - Updates deprecated validation syntax * - Ensures proper validator composition * * @param context - The transformation context containing: * - `sourceFile`: The TypeScript source file to modernize * - `project`: The ts-morph Project for cross-file analysis * - `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: { * convertFormBuilder: false, // Skip FormBuilder conversion * modernizeFormControlInit: true, * } * }); * orchestrator.run(context); * ``` * * @see {@link TransformContext} for context structure * @see {@link FormModernizationConfig} for configuration options * * @public */ run(context: TransformContext): void; /** * Modernize forms in a single class. */ private modernizeClassForms; /** * Check if a class uses reactive forms. */ private usesReactiveForms; /** * Convert FormBuilder usage to direct instantiation. */ private convertFormBuilderUsage; /** * Convert FormBuilder.group() to new FormGroup(). */ private convertFormBuilderGroup; /** * Convert FormBuilder.control() to new FormControl(). */ private convertFormBuilderControl; /** * Convert FormBuilder.array() to new FormArray(). */ private convertFormBuilderArray; /** * Remove unused FormBuilder from constructor. */ private removeUnusedFormBuilder; /** * Modernize FormControl initialization values. */ private modernizeFormControlInitialization; /** * Update validation patterns to current best practices. */ private updateValidationPatterns; /** * Convert ngOnInit form initialization to property initialization. */ private convertNgOnInitFormInitialization; /** * Update imports based on modernization changes. */ private updateImports; /** * Get modernization configuration with defaults. */ private getModernizationConfig; } //# sourceMappingURL=form-modernization-orchestrator.d.ts.map