| 
									
										
										
										
											2025-10-19 20:41:09 +00:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Abstract base class for configuration migrations | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Each migration represents an upgrade from one config version to another. | 
					
						
							|  |  |  |  * Migrations run in order based on the `order` field, allowing users to jump | 
					
						
							|  |  |  |  * multiple versions (e.g., v1 → v4 runs migrations 2, 3, and 4). | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2025-10-20 12:03:14 +00:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Abstract base class for configuration migrations | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Each migration represents an upgrade from one config version to another. | 
					
						
							|  |  |  |  * Migrations run in order based on the `toVersion` field, allowing users to jump | 
					
						
							|  |  |  |  * multiple versions (e.g., v1 → v4 runs migrations 2, 3, and 4). | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2025-10-19 20:41:09 +00:00
										 |  |  | export abstract class BaseMigration { | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Source version this migration upgrades from | 
					
						
							|  |  |  |    * e.g., "1.x", "3.x" | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   abstract readonly fromVersion: string; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Target version this migration upgrades to | 
					
						
							| 
									
										
										
										
											2025-10-20 12:03:14 +00:00
										 |  |  |    * e.g., "2.0", "4.0", "4.1" | 
					
						
							| 
									
										
										
										
											2025-10-19 20:41:09 +00:00
										 |  |  |    */ | 
					
						
							|  |  |  |   abstract readonly toVersion: string; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Check if this migration should run on the given config | 
					
						
							|  |  |  |    * | 
					
						
							| 
									
										
										
										
											2025-10-20 12:27:02 +00:00
										 |  |  |    * @param config - Raw configuration object to check (unknown schema for migrations) | 
					
						
							| 
									
										
										
										
											2025-10-19 20:41:09 +00:00
										 |  |  |    * @returns True if migration should run, false otherwise | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2025-10-20 12:27:02 +00:00
										 |  |  |   abstract shouldRun(config: Record<string, unknown>): Promise<boolean>; | 
					
						
							| 
									
										
										
										
											2025-10-19 20:41:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Perform the migration on the given config | 
					
						
							|  |  |  |    * | 
					
						
							| 
									
										
										
										
											2025-10-20 12:27:02 +00:00
										 |  |  |    * @param config - Raw configuration object to migrate (unknown schema for migrations) | 
					
						
							| 
									
										
										
										
											2025-10-19 20:41:09 +00:00
										 |  |  |    * @returns Migrated configuration object | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2025-10-20 12:27:02 +00:00
										 |  |  |   abstract migrate(config: Record<string, unknown>): Promise<Record<string, unknown>>; | 
					
						
							| 
									
										
										
										
											2025-10-19 20:41:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Get human-readable name for this migration | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * @returns Migration name | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   getName(): string { | 
					
						
							|  |  |  |     return `Migration ${this.fromVersion} → ${this.toVersion}`; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-10-20 12:03:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Parse version string into a comparable number | 
					
						
							|  |  |  |    * Supports formats like "2.0", "4.1", etc. | 
					
						
							|  |  |  |    * Returns a number like 2.0, 4.1 for sorting | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * @returns Parsed version number for ordering | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   getVersionOrder(): number { | 
					
						
							|  |  |  |     const parsed = parseFloat(this.toVersion); | 
					
						
							|  |  |  |     if (isNaN(parsed)) { | 
					
						
							|  |  |  |       throw new Error(`Invalid version format: ${this.toVersion}`); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return parsed; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-10-19 20:41:09 +00:00
										 |  |  | } |