Switch log messages to string literal
[e-mobility-charging-stations-simulator.git] / src / utils / Configuration.ts
index f18935313ee37e76b6f4869939d8f8e5fcc4be91..f1f43bcfff188f353c10534199895533a34b25fe 100644 (file)
@@ -3,8 +3,10 @@ import path from 'path';
 import { fileURLToPath } from 'url';
 
 import chalk from 'chalk';
+import merge from 'just-merge';
 import { WorkerChoiceStrategies } from 'poolifier';
 
+import Constants from './Constants';
 import {
   type ConfigurationData,
   type StationTemplateUrl,
@@ -20,7 +22,6 @@ import { StorageType } from '../types/Storage';
 import { ApplicationProtocol } from '../types/UIProtocol';
 import { WorkerProcessType } from '../types/Worker';
 import WorkerConstants from '../worker/WorkerConstants';
-import Constants from './Constants';
 
 export default class Configuration {
   private static configurationFile = path.join(
@@ -68,10 +69,7 @@ export default class Configuration {
       },
     };
     if (Configuration.objectHasOwnProperty(Configuration.getConfig(), 'uiServer')) {
-      uiServerConfiguration = Configuration.deepMerge(
-        uiServerConfiguration,
-        Configuration.getConfig().uiServer
-      );
+      uiServerConfiguration = merge(uiServerConfiguration, Configuration.getConfig().uiServer);
     }
     if (Configuration.isCFEnvironment() === true) {
       delete uiServerConfiguration.options.host;
@@ -246,10 +244,18 @@ export default class Configuration {
       : true;
   }
 
-  static getLogMaxFiles(): number {
-    return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'logMaxFiles')
-      ? Configuration.getConfig().logMaxFiles
-      : 7;
+  static getLogMaxFiles(): number | string | undefined {
+    return (
+      Configuration.objectHasOwnProperty(Configuration.getConfig(), 'logMaxFiles') &&
+      Configuration.getConfig().logMaxFiles
+    );
+  }
+
+  static getLogMaxSize(): number | string | undefined {
+    return (
+      Configuration.objectHasOwnProperty(Configuration.getConfig(), 'logMaxFiles') &&
+      Configuration.getConfig().logMaxSize
+    );
   }
 
   static getLogLevel(): string {
@@ -322,13 +328,13 @@ export default class Configuration {
     ) {
       console.error(
         chalk`{green ${Configuration.logPrefix()}} {red Deprecated configuration key '${key}' usage in section '${sectionName}'${
-          logMsgToAppend && '. ' + logMsgToAppend
+          logMsgToAppend && `. ${logMsgToAppend}`
         }}`
       );
     } else if (!Configuration.isUndefined(Configuration.getConfig()[key])) {
       console.error(
         chalk`{green ${Configuration.logPrefix()}} {red Deprecated configuration key '${key}' usage${
-          logMsgToAppend && '. ' + logMsgToAppend
+          logMsgToAppend && `. ${logMsgToAppend}`
         }}`
       );
     }
@@ -384,7 +390,6 @@ export default class Configuration {
   }
 
   private static getDefaultPerformanceStorageUri(storageType: StorageType) {
-    const SQLiteFileName = `${Constants.DEFAULT_PERFORMANCE_RECORDS_DB_NAME}.db`;
     switch (storageType) {
       case StorageType.JSON_FILE:
         return `file://${path.join(
@@ -394,17 +399,13 @@ export default class Configuration {
       case StorageType.SQLITE:
         return `file://${path.join(
           path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../'),
-          SQLiteFileName
+          `${Constants.DEFAULT_PERFORMANCE_RECORDS_DB_NAME}.db`
         )}`;
       default:
         throw new Error(`Performance storage URI is mandatory with storage type '${storageType}'`);
     }
   }
 
-  private static isObject(item: unknown): boolean {
-    return item && typeof item === 'object' && Array.isArray(item) === false;
-  }
-
   private static objectHasOwnProperty(object: unknown, property: string): boolean {
     return Object.prototype.hasOwnProperty.call(object, property) as boolean;
   }
@@ -413,29 +414,6 @@ export default class Configuration {
     return typeof obj === 'undefined';
   }
 
-  private static deepMerge(target: object, ...sources: object[]): object {
-    if (!sources.length) {
-      return target;
-    }
-    const source = sources.shift();
-
-    if (Configuration.isObject(target) && Configuration.isObject(source)) {
-      for (const key in source) {
-        if (Configuration.isObject(source[key])) {
-          if (!target[key]) {
-            Object.assign(target, { [key]: {} });
-          }
-          // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
-          Configuration.deepMerge(target[key], source[key]);
-        } else {
-          // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
-          Object.assign(target, { [key]: source[key] });
-        }
-      }
-    }
-    return Configuration.deepMerge(target, ...sources);
-  }
-
   private static handleFileException(
     logPrefix: string,
     fileType: FileType,