From: Jérôme Benoit Date: Fri, 27 Mar 2026 15:28:26 +0000 (+0100) Subject: refactor: type deprecated config key maps with `keyof` to eliminate 4 casts X-Git-Tag: ocpp-server@v4.0.0~37 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=29a04ab52dbd381ca34fa2e09235a13a5817d8ad;p=e-mobility-charging-stations-simulator.git refactor: type deprecated config key maps with `keyof` to eliminate 4 casts --- diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 1b1adf92..fbe02787 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -205,7 +205,7 @@ export class Configuration { private static buildLogSection (): LogConfiguration { const configData = Configuration.getConfigurationData() - const deprecatedLogKeyMap: [string, string][] = [ + const deprecatedLogKeyMap: [keyof ConfigurationData, keyof LogConfiguration][] = [ ['logEnabled', 'enabled'], ['logFile', 'file'], ['logErrorFile', 'errorFile'], @@ -220,9 +220,7 @@ export class Configuration { const deprecatedLogConfiguration: Record = {} for (const [deprecatedKey, newKey] of deprecatedLogKeyMap) { if (has(deprecatedKey, configData)) { - deprecatedLogConfiguration[newKey] = (configData as unknown as Record)[ - deprecatedKey - ] + deprecatedLogConfiguration[newKey] = configData?.[deprecatedKey] } } const logConfiguration: LogConfiguration = { @@ -291,7 +289,7 @@ export class Configuration { private static buildWorkerSection (): WorkerConfiguration { const configData = Configuration.getConfigurationData() - const deprecatedWorkerKeyMap: [string, string][] = [ + const deprecatedWorkerKeyMap: [keyof ConfigurationData, keyof WorkerConfiguration][] = [ ['workerProcess', 'processType'], ['workerStartDelay', 'startDelay'], ['chargingStationsPerWorker', 'elementsPerWorker'], @@ -302,18 +300,17 @@ export class Configuration { const deprecatedWorkerConfiguration: Record = {} for (const [deprecatedKey, newKey] of deprecatedWorkerKeyMap) { if (has(deprecatedKey, configData)) { - deprecatedWorkerConfiguration[newKey] = (configData as unknown as Record)[ - deprecatedKey - ] + deprecatedWorkerConfiguration[newKey] = configData?.[deprecatedKey] } } if (has('elementStartDelay', configData?.worker)) { - deprecatedWorkerConfiguration.elementAddDelay = ( - configData?.worker as unknown as Record - ).elementStartDelay + // eslint-disable-next-line @typescript-eslint/no-deprecated -- intentional deprecated key migration + deprecatedWorkerConfiguration.elementAddDelay = configData?.worker?.elementStartDelay + } + if (configData != null) { + // eslint-disable-next-line @typescript-eslint/no-deprecated -- intentional deprecated key removal + delete configData.workerPoolStrategy } - has('workerPoolStrategy', configData) && - delete (configData as unknown as Record).workerPoolStrategy const workerConfiguration: WorkerConfiguration = { ...defaultWorkerConfiguration, ...(deprecatedWorkerConfiguration as Partial),