fix: brown paper bag issue at referencing the same literal object instance
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 18 Mar 2023 16:45:29 +0000 (17:45 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 18 Mar 2023 16:47:20 +0000 (17:47 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
14 files changed:
docker/start.sh
manifest-cf-template.yml
package.json
src/charging-station/ChargingStation.ts
src/charging-station/ChargingStationConfigurationUtils.ts
src/charging-station/ChargingStationUtils.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts
src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts
src/charging-station/ocpp/2.0/OCPP20ResponseService.ts
src/performance/PerformanceStatistics.ts
src/utils/Constants.ts
src/worker/WorkerAbstract.ts
src/worker/WorkerConstants.ts
src/worker/WorkerFactory.ts

index caf30846201ec56f7ac1ccf103b19326f876a063..fa3b0b9530a90f1ddbf015f668f06e599ae15acd 100755 (executable)
@@ -1,4 +1,4 @@
 #!/usr/bin/env sh
 
-node -r source-map-support/register dist/start.cjs &
+node -r source-map-support/register dist/start.mjs &
 node webui/start.js
index e1420eb88b7aafa8c0e4437017cf83b2c0abf0d3..a7d07501739c05d270c36bae35eb62eaef72ecb1 100644 (file)
@@ -9,7 +9,7 @@ applications:
     routes:
       - route: e-mobility-charging-stations-simulator.cfapps.sap.hana.ondemand.com
     health-check-type: process
-    command: node -r source-map-support/register dist/start.cjs
+    command: node -r source-map-support/register dist/start.mjs
     env:
       # OPTIMIZE_MEMORY: true
       NODE_OPTIONS: --stack-trace-limit=1024 --max-old-space-size=768
index 57f12e9d9881ee70e209e69ed5897f962daf0571..6bcc3372f2ca916719cbe021898ef3a64fe6673a 100644 (file)
   "scripts": {
     "prepare": "node prepare.js",
     "build-requirements": "node build-requirements.js",
-    "start": "npm run build && cross-env NODE_ENV=production node -r source-map-support/register dist/start.cjs",
-    "start:esm": "npm run build && cross-env NODE_ENV=production node -r source-map-support/register dist/start.mjs",
-    "start:dev": "npm run build:dev && cross-env NODE_ENV=development node -r source-map-support/register dist/start.cjs",
-    "start:dev:debug": "npm run build:dev && cross-env NODE_ENV=development node -r source-map-support/register --inspect dist/start.cjs",
-    "start:dev:esm": "npm run build:dev && cross-env NODE_ENV=development node -r source-map-support/register dist/start.mjs",
-    "start:dev:esm:debug": "npm run build:dev && cross-env NODE_ENV=development node -r source-map-support/register --inspect dist/start.mjs",
+    "start": "npm run build && cross-env NODE_ENV=production node -r source-map-support/register dist/start.mjs",
+    "start:cjs": "npm run build && cross-env NODE_ENV=production node -r source-map-support/register dist/start.cjs",
+    "start:dev": "npm run build:dev && cross-env NODE_ENV=development node -r source-map-support/register dist/start.mjs",
+    "start:dev:debug": "npm run build:dev && cross-env NODE_ENV=development node -r source-map-support/register --inspect dist/start.mjs",
+    "start:dev:cjs": "npm run build:dev && cross-env NODE_ENV=development node -r source-map-support/register dist/start.cjs",
+    "start:dev:cjs:debug": "npm run build:dev && cross-env NODE_ENV=development node -r source-map-support/register --inspect dist/start.cjs",
     "start:prof": "cross-env NODE_ENV=production node -r source-map-support/register --prof dist/start.cjs",
-    "start:doctorprof": "cross-env NODE_ENV=production clinic doctor -- node -r source-map-support/register dist/start.cjs",
-    "start:flameprof": "cross-env NODE_ENV=production clinic flame -- node -r source-map-support/register dist/start.cjs",
-    "start:bubbleprof": "cross-env NODE_ENV=production clinic bubbleprof -- node -r source-map-support/register dist/start.cjs",
-    "start:heapprofiler": "cross-env NODE_ENV=production clinic heapprofiler -- node -r source-map-support/register dist/start.cjs",
+    "start:doctorprof": "cross-env NODE_ENV=production clinic doctor -- node -r source-map-support/register dist/start.mjs",
+    "start:flameprof": "cross-env NODE_ENV=production clinic flame -- node -r source-map-support/register dist/start.mjs",
+    "start:bubbleprof": "cross-env NODE_ENV=production clinic bubbleprof -- node -r source-map-support/register dist/start.mjs",
+    "start:heapprofiler": "cross-env NODE_ENV=production clinic heapprofiler -- node -r source-map-support/register dist/start.mjs",
     "rollup": "npm run build-requirements && rollup --config",
     "build": "npm run rollup",
     "build:dev": "npm run rollup -- --environment BUILD:development",
index 9125c377c2ae76e5750b66f9cf62b5dcdaabe600..c24383e90c84fe122d8aa2165d17820bd71d4205 100644 (file)
@@ -74,7 +74,6 @@ import {
   RegistrationStatusEnumType,
   RequestCommand,
   type Response,
-  type ResponseCallback,
   StandardParametersKey,
   type StatusNotificationRequest,
   type StatusNotificationResponse,
@@ -638,7 +637,7 @@ export class ChargingStation {
   }
 
   public openWSConnection(
-    options: WsOptions = this.stationInfo?.wsOptions ?? Constants.EMPTY_OBJECT,
+    options: WsOptions = this.stationInfo?.wsOptions ?? {},
     params: { closeOpened?: boolean; terminateOpened?: boolean } = {
       closeOpened: false,
       terminateOpened: false,
@@ -907,7 +906,7 @@ export class ChargingStation {
         },
         reset: true,
       },
-      stationTemplate?.firmwareUpgrade ?? Constants.EMPTY_OBJECT
+      stationTemplate?.firmwareUpgrade ?? {}
     );
     stationInfo.resetTime = !Utils.isNullOrUndefined(stationTemplate?.resetTime)
       ? stationTemplate.resetTime * 1000
@@ -1373,7 +1372,7 @@ export class ChargingStation {
           fs.mkdirSync(path.dirname(this.configurationFile), { recursive: true });
         }
         const configurationData: ChargingStationConfiguration =
-          Utils.cloneObject(this.getConfigurationFromFile()) ?? Constants.EMPTY_OBJECT;
+          Utils.cloneObject(this.getConfigurationFromFile()) ?? {};
         this.ocppConfiguration?.configurationKey &&
           (configurationData.configurationKey = this.ocppConfiguration.configurationKey);
         this.stationInfo && (configurationData.stationInfo = this.stationInfo);
@@ -2052,7 +2051,7 @@ export class ChargingStation {
       );
       this.openWSConnection(
         {
-          ...(this.stationInfo?.wsOptions ?? Constants.EMPTY_OBJECT),
+          ...(this.stationInfo?.wsOptions ?? {}),
           handshakeTimeout: reconnectTimeout,
         },
         { closeOpened: true }
index 5e14e4589cba3e63302833cc760ab710835fbed3..f3f043cfb4a2bf509f0ac11699571d1bbd13e973 100644 (file)
@@ -35,7 +35,7 @@ export class ChargingStationConfigurationUtils {
     },
     params: AddConfigurationKeyParams = { overwrite: false, save: false }
   ): void {
-    options = options ?? (Constants.EMPTY_OBJECT as ConfigurationKeyOptions);
+    options = options ?? ({} as ConfigurationKeyOptions);
     options.readonly = options?.readonly ?? false;
     options.visible = options?.visible ?? true;
     options.reboot = options?.reboot ?? false;
index 957aee902adc42e3809aa9766dd64bcd4ab43712..efa8921c645707a293ecbd7a2b60dcb3de1d84c4 100644 (file)
@@ -263,7 +263,7 @@ export class ChargingStationUtils {
       randomSerialNumber: true,
     }
   ): void {
-    params = params ?? Constants.EMPTY_OBJECT;
+    params = params ?? {};
     params.randomSerialNumberUpperCase = params?.randomSerialNumberUpperCase ?? true;
     params.randomSerialNumber = params?.randomSerialNumber ?? true;
     const serialNumberSuffix = params?.randomSerialNumber
index 76bd56c297d8291cc3e5b983f24c9236bb605e02..18973792a1706472c91d436d4b4516f6bf40fa28 100644 (file)
@@ -353,7 +353,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
         chargingStation,
         OCPP16StandardParametersKey.HeartbeatInterval,
         payload.interval.toString(),
-        Constants.EMPTY_OBJECT,
+        {},
         { overwrite: true, save: true }
       );
       ChargingStationConfigurationUtils.addConfigurationKey(
index 907cee323612146cc01b44675f784dbf15aac435..50f6b92540bf35090ced70340431a5f4f3756000 100644 (file)
@@ -196,8 +196,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
       connectorId,
       OCPP16MeterValueMeasurand.POWER_ACTIVE_IMPORT
     );
-    let powerPerPhaseSampledValueTemplates: MeasurandPerPhaseSampledValueTemplates =
-      Constants.EMPTY_OBJECT;
+    let powerPerPhaseSampledValueTemplates: MeasurandPerPhaseSampledValueTemplates = {};
     if (chargingStation.getNumberOfPhases() === 3) {
       powerPerPhaseSampledValueTemplates = {
         L1: OCPP16ServiceUtils.getSampledValueTemplate(
@@ -234,7 +233,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
         powerSampledValueTemplate.measurand ??
         OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
       } measurand value`;
-      const powerMeasurandValues = Constants.EMPTY_OBJECT as MeasurandValues;
+      const powerMeasurandValues = {} as MeasurandValues;
       const unitDivider = powerSampledValueTemplate?.unit === MeterValueUnit.KILO_WATT ? 1000 : 1;
       const connectorMaximumAvailablePower =
         chargingStation.getConnectorMaximumAvailablePower(connectorId);
@@ -404,8 +403,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
       connectorId,
       OCPP16MeterValueMeasurand.CURRENT_IMPORT
     );
-    let currentPerPhaseSampledValueTemplates: MeasurandPerPhaseSampledValueTemplates =
-      Constants.EMPTY_OBJECT;
+    let currentPerPhaseSampledValueTemplates: MeasurandPerPhaseSampledValueTemplates = {};
     if (chargingStation.getNumberOfPhases() === 3) {
       currentPerPhaseSampledValueTemplates = {
         L1: OCPP16ServiceUtils.getSampledValueTemplate(
@@ -442,7 +440,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
         currentSampledValueTemplate.measurand ??
         OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
       } measurand value`;
-      const currentMeasurandValues: MeasurandValues = Constants.EMPTY_OBJECT as MeasurandValues;
+      const currentMeasurandValues: MeasurandValues = {} as MeasurandValues;
       const connectorMaximumAvailablePower =
         chargingStation.getConnectorMaximumAvailablePower(connectorId);
       let connectorMaximumAmperage: number;
index 129d8e52ddecb00fcefc437abdcedbf2c0eb9650..971d5b8394652b82e70fb4934f348620847c1298 100644 (file)
@@ -161,7 +161,7 @@ export class OCPP20ResponseService extends OCPPResponseService {
         chargingStation,
         OCPP20OptionalVariableName.HeartbeatInterval,
         payload.interval.toString(),
-        Constants.EMPTY_OBJECT,
+        {},
         { overwrite: true, save: true }
       );
       chargingStation.heartbeatSetInterval
index 956b8d3606b31c5554f802061b457149d4051a1c..69829ff186e71fd1aca40e465b1c4b654084c8fc 100644 (file)
@@ -226,7 +226,7 @@ export class PerformanceStatistics {
     const entryName = entry.name;
     // Initialize command statistics
     if (!this.statistics.statisticsData.has(entryName)) {
-      this.statistics.statisticsData.set(entryName, Constants.EMPTY_OBJECT);
+      this.statistics.statisticsData.set(entryName, {});
     }
     // Update current statistics
     this.statistics.updatedAt = new Date();
index 67b40146464c168ded98a8f17e9eb3d1a5b04c31..c42e15be6e3687f84202f125af61ea966e6ea46a 100644 (file)
@@ -47,7 +47,6 @@ export class Constants {
 
   static readonly MAX_RANDOM_INTEGER = 281474976710654;
 
-  static EMPTY_OBJECT = {};
   static readonly EMPTY_FREEZED_OBJECT = Object.freeze({});
   static readonly EMPTY_FUNCTION = Object.freeze(() => {
     /* This is intentional */
index 2803eea464da27115e45e1a6a3546fdee46418a9..3dd9a782a8661507f61fa21787ed9f80c9465852 100644 (file)
@@ -23,7 +23,7 @@ export abstract class WorkerAbstract<T extends WorkerData> {
       poolMinSize: WorkerConstants.DEFAULT_POOL_MIN_SIZE,
       poolMaxSize: WorkerConstants.DEFAULT_POOL_MAX_SIZE,
       elementsPerWorker: WorkerConstants.DEFAULT_ELEMENTS_PER_WORKER,
-      poolOptions: WorkerConstants.EMPTY_OBJECT,
+      poolOptions: {},
       messageHandler: WorkerConstants.EMPTY_FUNCTION,
     }
   ) {
index 12bb70accb53f170137313da6f1abc8d43cd8f68..72d436d439f444416524d4bc5245b26fb19ed01a 100644 (file)
@@ -1,5 +1,4 @@
 export class WorkerConstants {
-  public static EMPTY_OBJECT = {};
   public static readonly EMPTY_FUNCTION = Object.freeze(() => {
     /* This is intentional */
   });
index a5b401a3698417887c77426f843d0cae48bd61f0..0a532681cf9a12d41ffb0c73b13b3fd71c8643e7 100644 (file)
@@ -22,13 +22,12 @@ export class WorkerFactory {
     if (!isMainThread) {
       throw new Error('Cannot get a worker implementation outside the main thread');
     }
-    workerOptions = workerOptions ?? (WorkerConstants.EMPTY_OBJECT as WorkerOptions);
+    workerOptions = workerOptions ?? ({} as WorkerOptions);
     workerOptions.workerStartDelay =
       workerOptions?.workerStartDelay ?? WorkerConstants.DEFAULT_WORKER_START_DELAY;
     workerOptions.elementStartDelay =
       workerOptions?.elementStartDelay ?? WorkerConstants.DEFAULT_ELEMENT_START_DELAY;
-    workerOptions.poolOptions =
-      workerOptions?.poolOptions ?? (WorkerConstants.EMPTY_OBJECT as PoolOptions<Worker>);
+    workerOptions.poolOptions = workerOptions?.poolOptions ?? ({} as PoolOptions<Worker>);
     workerOptions?.messageHandler &&
       (workerOptions.poolOptions.messageHandler = workerOptions.messageHandler);
     let workerImplementation: WorkerAbstract<T> | null = null;