refactor(simulator): switch to internal modules export/import design
[e-mobility-charging-stations-simulator.git] / src / utils / Configuration.ts
index 8490be4eb79a0bde8358c50849c7e8b5a5fa4ace..16de0f899ab9aaed2145356fc0712d828faef5bb 100644 (file)
@@ -6,24 +6,23 @@ import chalk from 'chalk';
 import merge from 'just-merge';
 import { WorkerChoiceStrategies } from 'poolifier';
 
-import Constants from './Constants';
+import { Constants } from './Constants';
 import {
+  ApplicationProtocol,
   type ConfigurationData,
+  type EmptyObject,
+  FileType,
+  type HandleErrorParams,
   type StationTemplateUrl,
   type StorageConfiguration,
+  StorageType,
   SupervisionUrlDistribution,
   type UIServerConfiguration,
   type WorkerConfiguration,
-} from '../types/ConfigurationData';
-import type { EmptyObject } from '../types/EmptyObject';
-import type { HandleErrorParams } from '../types/Error';
-import { FileType } from '../types/FileType';
-import { StorageType } from '../types/Storage';
-import { ApplicationProtocol } from '../types/UIProtocol';
-import { WorkerProcessType } from '../types/Worker';
-import WorkerConstants from '../worker/WorkerConstants';
+} from '../types';
+import { WorkerConstants, WorkerProcessType } from '../worker';
 
-export default class Configuration {
+export class Configuration {
   private static configurationFile = path.join(
     path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'),
     'assets',
@@ -69,7 +68,10 @@ export default class Configuration {
       },
     };
     if (Configuration.objectHasOwnProperty(Configuration.getConfig(), 'uiServer')) {
-      uiServerConfiguration = merge(uiServerConfiguration, Configuration.getConfig()?.uiServer);
+      uiServerConfiguration = merge<UIServerConfiguration>(
+        uiServerConfiguration,
+        Configuration.getConfig()?.uiServer
+      );
     }
     if (Configuration.isCFEnvironment() === true) {
       delete uiServerConfiguration.options?.host;
@@ -318,9 +320,9 @@ export default class Configuration {
       : SupervisionUrlDistribution.ROUND_ROBIN;
   }
 
-  private static logPrefix(): string {
+  private static logPrefix = (): string => {
     return `${new Date().toLocaleString()} Simulator configuration |`;
-  }
+  };
 
   private static warnDeprecatedConfigurationKey(
     key: string,
@@ -336,13 +338,13 @@ export default class Configuration {
     ) {
       console.error(
         chalk`{green ${Configuration.logPrefix()}} {red Deprecated configuration key '${key}' usage in section '${sectionName}'${
-          logMsgToAppend.trim().length !== 0 && `. ${logMsgToAppend}`
+          logMsgToAppend.trim().length > 0 && `. ${logMsgToAppend}`
         }}`
       );
     } else if (!Configuration.isUndefined(Configuration.getConfig()[key])) {
       console.error(
         chalk`{green ${Configuration.logPrefix()}} {red Deprecated configuration key '${key}' usage${
-          logMsgToAppend.trim().length !== 0 && `. ${logMsgToAppend}`
+          logMsgToAppend.trim().length > 0 && `. ${logMsgToAppend}`
         }}`
       );
     }
@@ -373,7 +375,7 @@ export default class Configuration {
   private static getConfigurationFileWatcher(): fs.FSWatcher | undefined {
     try {
       return fs.watch(Configuration.configurationFile, (event, filename): void => {
-        if (filename.trim().length !== 0 && event === 'change') {
+        if (filename?.trim().length > 0 && event === 'change') {
           // Nullify to force configuration file reading
           Configuration.configuration = null;
           if (!Configuration.isUndefined(Configuration.configurationChangeCallback)) {
@@ -429,7 +431,7 @@ export default class Configuration {
     logPrefix: string,
     params: HandleErrorParams<EmptyObject> = { throwError: true }
   ): void {
-    const prefix = logPrefix.trim().length !== 0 ? `${logPrefix} ` : '';
+    const prefix = logPrefix?.trim().length > 0 ? `${logPrefix} ` : '';
     let logMsg: string;
     switch (error.code) {
       case 'ENOENT':