import { IServiceConfig } from "../../../../interfaces/core/IServiceRegistry"; import { ServiceConfigManager } from "../../../../config/ServiceConfig"; import { Allocator } from "./Allocator"; import { PayloadDtoValidator } from "./PayloadDtoValidator"; import { Service } from "./index"; import { AggregationCounterAPI } from "../../../core/AggregationCounterAPI"; import { IWorkerRegistry } from "../../../../interfaces/core/IWorkerRegistry"; import { MESSAGE_TYPE } from "./env"; export class ServiceFactory { static createServiceConfig(dependencies: { aggregationCounterAPI: AggregationCounterAPI, workerRegistry: IWorkerRegistry }): IServiceConfig { const typeConfig = ServiceConfigManager.getServiceConfig(MESSAGE_TYPE); if (!typeConfig) { throw new Error(`${MESSAGE_TYPE} service config not found (check worker profile or ServiceConfig.ts)`); } const allocator = new Allocator(); const payloadDtoValidator = new PayloadDtoValidator(); const service = new Service({ payloadDtoValidator }); const config: IServiceConfig = { messageType: MESSAGE_TYPE, service, allocator, payloadDtoValidator, typeConfig }; return config; } }