X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FConfiguration.ts;h=25a1475bc2a5f6ec9a6ea40df049048db9538ad8;hb=452a4864d4a8d0286ddd351958d8cc02574b4ba9;hp=30ae873e672a595e362b3c9f68d8818c5b291ee7;hpb=b4c82e730be585cb7d7005d66b781d4a02c18a85;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 30ae873e..25a1475b 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -4,20 +4,11 @@ import { env } from 'node:process' import { fileURLToPath } from 'node:url' import chalk from 'chalk' -import { mergeDeepRight } from 'rambda' +import { mergeDeepRight, once } from 'rambda' -import { - buildPerformanceUriFilePath, - checkWorkerElementsPerWorker, - checkWorkerProcessType, - getDefaultPerformanceStorageUri, - handleFileException, - logPrefix -} from './ConfigurationUtils.js' -import { Constants } from './Constants.js' -import { hasOwnProp, isCFEnvironment, once } from './Utils.js' import { ApplicationProtocol, + ApplicationProtocolVersion, type ConfigurationData, ConfigurationSection, FileType, @@ -30,12 +21,22 @@ import { type WorkerConfiguration } from '../types/index.js' import { - DEFAULT_ELEMENT_START_DELAY, + DEFAULT_ELEMENT_ADD_DELAY, DEFAULT_POOL_MAX_SIZE, DEFAULT_POOL_MIN_SIZE, DEFAULT_WORKER_START_DELAY, WorkerProcessType } from '../worker/index.js' +import { + buildPerformanceUriFilePath, + checkWorkerElementsPerWorker, + checkWorkerProcessType, + getDefaultPerformanceStorageUri, + handleFileException, + logPrefix +} from './ConfigurationUtils.js' +import { Constants } from './Constants.js' +import { hasOwnProp, isCFEnvironment } from './Utils.js' type ConfigurationSectionType = | LogConfiguration @@ -81,8 +82,7 @@ export class Configuration { public static getStationTemplateUrls (): StationTemplateUrl[] | undefined { const checkDeprecatedConfigurationKeysOnce = once( - Configuration.checkDeprecatedConfigurationKeys.bind(Configuration), - Configuration + Configuration.checkDeprecatedConfigurationKeys.bind(Configuration) ) checkDeprecatedConfigurationKeysOnce() return Configuration.getConfigurationData()?.stationTemplateUrls @@ -155,6 +155,7 @@ export class Configuration { let uiServerConfiguration: UIServerConfiguration = { enabled: false, type: ApplicationProtocol.WS, + version: ApplicationProtocolVersion.VERSION_11, options: { host: Constants.DEFAULT_UI_SERVER_HOST, port: Constants.DEFAULT_UI_SERVER_PORT @@ -274,10 +275,11 @@ export class Configuration { processType: WorkerProcessType.workerSet, startDelay: DEFAULT_WORKER_START_DELAY, elementsPerWorker: 'auto', - elementStartDelay: DEFAULT_ELEMENT_START_DELAY, + elementAddDelay: DEFAULT_ELEMENT_ADD_DELAY, poolMinSize: DEFAULT_POOL_MIN_SIZE, poolMaxSize: DEFAULT_POOL_MAX_SIZE } + const deprecatedWorkerConfiguration: WorkerConfiguration = { ...(hasOwnProp(Configuration.getConfigurationData(), 'workerProcess') && { processType: Configuration.getConfigurationData()?.workerProcess @@ -288,8 +290,11 @@ export class Configuration { ...(hasOwnProp(Configuration.getConfigurationData(), 'chargingStationsPerWorker') && { elementsPerWorker: Configuration.getConfigurationData()?.chargingStationsPerWorker }), - ...(hasOwnProp(Configuration.getConfigurationData(), 'elementStartDelay') && { - elementStartDelay: Configuration.getConfigurationData()?.elementStartDelay + ...(hasOwnProp(Configuration.getConfigurationData(), 'elementAddDelay') && { + elementAddDelay: Configuration.getConfigurationData()?.elementAddDelay + }), + ...(hasOwnProp(Configuration.getConfigurationData()?.worker, 'elementStartDelay') && { + elementAddDelay: Configuration.getConfigurationData()?.worker?.elementStartDelay }), ...(hasOwnProp(Configuration.getConfigurationData(), 'workerPoolMinSize') && { poolMinSize: Configuration.getConfigurationData()?.workerPoolMinSize @@ -395,9 +400,9 @@ export class Configuration { `Use '${ConfigurationSection.worker}' section to define the number of element(s) per worker instead` ) Configuration.warnDeprecatedConfigurationKey( - 'elementStartDelay', + 'elementAddDelay', undefined, - `Use '${ConfigurationSection.worker}' section to define the worker's element start delay instead` + `Use '${ConfigurationSection.worker}' section to define the worker's element add delay instead` ) Configuration.warnDeprecatedConfigurationKey( 'workerPoolMinSize', @@ -424,6 +429,11 @@ export class Configuration { ConfigurationSection.worker, 'Not publicly exposed to end users' ) + Configuration.warnDeprecatedConfigurationKey( + 'elementStartDelay', + ConfigurationSection.worker, + "Use 'elementAddDelay' instead" + ) if ( Configuration.getConfigurationData()?.worker?.processType === ('staticPool' as WorkerProcessType) @@ -503,22 +513,22 @@ export class Configuration { private static warnDeprecatedConfigurationKey ( key: string, - sectionName?: string, + configurationSection?: ConfigurationSection, logMsgToAppend = '' ): void { if ( - sectionName != null && - Configuration.getConfigurationData()?.[sectionName as keyof ConfigurationData] != null && + configurationSection != null && + Configuration.getConfigurationData()?.[configurationSection as keyof ConfigurationData] != + null && ( - Configuration.getConfigurationData()?.[sectionName as keyof ConfigurationData] as Record< - string, - unknown - > + Configuration.getConfigurationData()?.[ + configurationSection as keyof ConfigurationData + ] as Record )[key] != null ) { console.error( `${chalk.green(logPrefix())} ${chalk.red( - `Deprecated configuration key '${key}' usage in section '${sectionName}'${ + `Deprecated configuration key '${key}' usage in section '${configurationSection}'${ logMsgToAppend.trim().length > 0 ? `. ${logMsgToAppend}` : '' }` )}` @@ -534,7 +544,7 @@ export class Configuration { } } - private static getConfigurationData (): ConfigurationData | undefined { + public static getConfigurationData (): ConfigurationData | undefined { if (Configuration.configurationData == null) { try { Configuration.configurationData = JSON.parse( @@ -565,7 +575,7 @@ export class Configuration { event === 'change' ) { Configuration.configurationFileReloading = true - const consoleWarnOnce = once(console.warn, this) + const consoleWarnOnce = once(console.warn) consoleWarnOnce( `${chalk.green(logPrefix())} ${chalk.yellow( `${FileType.Configuration} ${this.configurationFile} file have changed, reload` @@ -575,7 +585,7 @@ export class Configuration { Configuration.configurationSectionCache.clear() if (Configuration.configurationChangeCallback != null) { Configuration.configurationChangeCallback() - .catch(error => { + .catch((error: unknown) => { throw typeof error === 'string' ? new Error(error) : error }) .finally(() => {