mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	chore: split interfaces for import and export (#5004)
## About the changes This splits the interfaces for import and export, especially because the import functionality has to be replaced in enterprise repo. This is a breaking change because of the service renames, but I'll have the PR for the other repository ready so we reduce the time to fix. I intentionally avoided doing it backward compatible because of time.
This commit is contained in:
		
							parent
							
								
									cfcf9de65a
								
							
						
					
					
						commit
						7343183f2d
					
				| @ -1,7 +1,10 @@ | ||||
| import { Response } from 'express'; | ||||
| import Controller from '../../routes/controller'; | ||||
| import { Logger } from '../../logger'; | ||||
| import ExportImportService from './export-import-service'; | ||||
| import ExportImportService, { | ||||
|     IExportService, | ||||
|     IImportService, | ||||
| } from './export-import-service'; | ||||
| import { OpenApiService } from '../../services'; | ||||
| import { | ||||
|     TransactionCreator, | ||||
| @ -32,32 +35,31 @@ import ApiUser from '../../types/api-user'; | ||||
| class ExportImportController extends Controller { | ||||
|     private logger: Logger; | ||||
| 
 | ||||
|     /** @deprecated gradually rolling out exportImportV2 */ | ||||
|     private exportImportService: ExportImportService; | ||||
|     private exportService: IExportService; | ||||
| 
 | ||||
|     /** @deprecated gradually rolling out exportImportV2 */ | ||||
|     /** @deprecated gradually rolling out importService */ | ||||
|     private transactionalExportImportService: ( | ||||
|         db: UnleashTransaction, | ||||
|     ) => Pick<ExportImportService, 'import' | 'validate'>; | ||||
|     ) => IImportService; | ||||
| 
 | ||||
|     private exportImportServiceV2: WithTransactional<ExportImportService>; | ||||
|     private importService: WithTransactional<IImportService>; | ||||
| 
 | ||||
|     private openApiService: OpenApiService; | ||||
| 
 | ||||
|     /** @deprecated gradually rolling out exportImportV2 */ | ||||
|     /** @deprecated gradually rolling out importService */ | ||||
|     private readonly startTransaction: TransactionCreator<UnleashTransaction>; | ||||
| 
 | ||||
|     constructor( | ||||
|         config: IUnleashConfig, | ||||
|         { | ||||
|             exportImportService, | ||||
|             exportService, | ||||
|             transactionalExportImportService, | ||||
|             exportImportServiceV2, | ||||
|             importService, | ||||
|             openApiService, | ||||
|         }: Pick< | ||||
|             IUnleashServices, | ||||
|             | 'exportImportService' | ||||
|             | 'exportImportServiceV2' | ||||
|             | 'exportService' | ||||
|             | 'importService' | ||||
|             | 'openApiService' | ||||
|             | 'transactionalExportImportService' | ||||
|         >, | ||||
| @ -65,10 +67,10 @@ class ExportImportController extends Controller { | ||||
|     ) { | ||||
|         super(config); | ||||
|         this.logger = config.getLogger('/admin-api/export-import.ts'); | ||||
|         this.exportImportService = exportImportService; | ||||
|         this.exportService = exportService; | ||||
|         this.transactionalExportImportService = | ||||
|             transactionalExportImportService; | ||||
|         this.exportImportServiceV2 = exportImportServiceV2; | ||||
|         this.importService = importService; | ||||
|         this.startTransaction = startTransaction; | ||||
|         this.openApiService = openApiService; | ||||
|         this.route({ | ||||
| @ -141,12 +143,7 @@ class ExportImportController extends Controller { | ||||
|         const query = req.body; | ||||
|         const userName = extractUsername(req); | ||||
| 
 | ||||
|         const useTransactionalDecorator = this.config.flagResolver.isEnabled( | ||||
|             'transactionalDecorator', | ||||
|         ); | ||||
|         const data = useTransactionalDecorator | ||||
|             ? await this.exportImportServiceV2.export(query, userName) | ||||
|             : await this.exportImportService.export(query, userName); | ||||
|         const data = await this.exportService.export(query, userName); | ||||
| 
 | ||||
|         this.openApiService.respondWithValidation( | ||||
|             200, | ||||
| @ -168,7 +165,7 @@ class ExportImportController extends Controller { | ||||
|             'transactionalDecorator', | ||||
|         ); | ||||
|         const validation = useTransactionalDecorator | ||||
|             ? await this.exportImportServiceV2.transactional((service) => | ||||
|             ? await this.importService.transactional((service) => | ||||
|                   service.validate(dto, user), | ||||
|               ) | ||||
|             : await this.startTransaction(async (tx) => | ||||
| @ -203,7 +200,7 @@ class ExportImportController extends Controller { | ||||
|         ); | ||||
| 
 | ||||
|         if (useTransactionalDecorator) { | ||||
|             await this.exportImportServiceV2.transactional((service) => | ||||
|             await this.importService.transactional((service) => | ||||
|                 service.import(dto, user), | ||||
|             ); | ||||
|         } else { | ||||
|  | ||||
| @ -50,7 +50,25 @@ import { ImportValidationMessages } from './import-validation-messages'; | ||||
| import { findDuplicates } from '../../util/findDuplicates'; | ||||
| import { FeatureNameCheckResultWithFeaturePattern } from '../feature-toggle/feature-toggle-service'; | ||||
| 
 | ||||
| export default class ExportImportService { | ||||
| export type IImportService = { | ||||
|     validate( | ||||
|         dto: ImportTogglesSchema, | ||||
|         user: User, | ||||
|     ): Promise<ImportTogglesValidateSchema>; | ||||
| 
 | ||||
|     import(dto: ImportTogglesSchema, user: User): Promise<void>; | ||||
| }; | ||||
| 
 | ||||
| export type IExportService = { | ||||
|     export( | ||||
|         query: ExportQuerySchema, | ||||
|         userName: string, | ||||
|     ): Promise<ExportResultSchema>; | ||||
| }; | ||||
| 
 | ||||
| export default class ExportImportService | ||||
|     implements IExportService, IImportService | ||||
| { | ||||
|     private logger: Logger; | ||||
| 
 | ||||
|     private toggleStore: IFeatureToggleStore; | ||||
|  | ||||
| @ -299,7 +299,7 @@ export const createServices = ( | ||||
|     const exportImportService = db | ||||
|         ? createExportImportTogglesService(db, config) | ||||
|         : createFakeExportImportTogglesService(config); | ||||
|     const exportImportServiceV2 = db | ||||
|     const importService = db | ||||
|         ? withTransactional(deferredExportImportTogglesService(config), db) | ||||
|         : withFakeTransactional(createFakeExportImportTogglesService(config)); | ||||
|     const transactionalExportImportService = (txDb: Knex.Transaction) => | ||||
| @ -403,9 +403,9 @@ export const createServices = ( | ||||
|         instanceStatsService, | ||||
|         favoritesService, | ||||
|         maintenanceService, | ||||
|         exportImportService, | ||||
|         exportService: exportImportService, | ||||
|         transactionalExportImportService, | ||||
|         exportImportServiceV2, | ||||
|         importService, | ||||
|         schedulerService, | ||||
|         configurationRevisionService, | ||||
|         transactionalFeatureToggleService, | ||||
|  | ||||
| @ -39,7 +39,10 @@ import MaintenanceService from '../services/maintenance-service'; | ||||
| import { AccountService } from '../services/account-service'; | ||||
| import { SchedulerService } from '../services/scheduler-service'; | ||||
| import { Knex } from 'knex'; | ||||
| import ExportImportService from '../features/export-import-toggles/export-import-service'; | ||||
| import { | ||||
|     IExportService, | ||||
|     IImportService, | ||||
| } from '../features/export-import-toggles/export-import-service'; | ||||
| import { ISegmentService } from '../segments/segment-service-interface'; | ||||
| import ConfigurationRevisionService from '../features/feature-toggle/configuration-revision-service'; | ||||
| import EventAnnouncerService from 'lib/services/event-announcer-service'; | ||||
| @ -89,16 +92,13 @@ export interface IUnleashServices { | ||||
|     instanceStatsService: InstanceStatsService; | ||||
|     favoritesService: FavoritesService; | ||||
|     maintenanceService: MaintenanceService; | ||||
|     /** @deprecated prefer exportImportServiceV2, we're doing a gradual rollout */ | ||||
|     exportImportService: ExportImportService; | ||||
|     exportImportServiceV2: WithTransactional<ExportImportService>; | ||||
|     exportService: IExportService; | ||||
|     importService: WithTransactional<IImportService>; | ||||
|     configurationRevisionService: ConfigurationRevisionService; | ||||
|     schedulerService: SchedulerService; | ||||
|     eventAnnouncerService: EventAnnouncerService; | ||||
|     /** @deprecated prefer exportImportServiceV2, we're doing a gradual rollout */ | ||||
|     transactionalExportImportService: ( | ||||
|         db: Knex.Transaction, | ||||
|     ) => Pick<ExportImportService, 'import' | 'validate'>; | ||||
|     transactionalExportImportService: (db: Knex.Transaction) => IImportService; | ||||
|     transactionalFeatureToggleService: ( | ||||
|         db: Knex.Transaction, | ||||
|     ) => FeatureToggleService; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user