build(simulator): switch to strict type checking
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 18 Jul 2023 17:52:10 +0000 (19:52 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 18 Jul 2023 17:52:10 +0000 (19:52 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
20 files changed:
src/charging-station/ChargingStation.ts
src/charging-station/ChargingStationUtils.ts
src/charging-station/ChargingStationWorker.ts
src/charging-station/broadcast-channel/ChargingStationWorkerBroadcastChannel.ts
src/charging-station/broadcast-channel/UIServiceWorkerBroadcastChannel.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.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/charging-station/ocpp/OCPPServiceUtils.ts
src/charging-station/ui-server/UIHttpServer.ts
src/charging-station/ui-server/UIWebSocketServer.ts
src/charging-station/ui-server/ui-services/AbstractUIService.ts
src/charging-station/ui-server/ui-services/UIService001.ts
src/utils/Configuration.ts
src/utils/Logger.ts
src/utils/Utils.ts
src/worker/WorkerAbstract.ts
src/worker/WorkerSet.ts
tsconfig-base.json

index d0c7b0780119e528ab5c6a019563f7177dc4c7ff..bca03a793980ba72304075d3882f7d63e8af4fda 100644 (file)
@@ -363,7 +363,10 @@ export class ChargingStation {
   public getMaximumPower(stationInfo?: ChargingStationInfo): number {
     const localStationInfo = stationInfo ?? this.stationInfo;
     // eslint-disable-next-line @typescript-eslint/dot-notation
-    return (localStationInfo['maxPower'] as number) ?? localStationInfo.maximumPower;
+    return (
+      (localStationInfo['maxPower' as keyof ChargingStationInfo] as number) ??
+      localStationInfo.maximumPower
+    );
   }
 
   public getConnectorMaximumAvailablePower(connectorId: number): number {
@@ -1006,14 +1009,14 @@ export class ChargingStation {
     if (this.hasEvses) {
       for (const evseStatus of this.evses.values()) {
         for (const connectorStatus of evseStatus.connectors.values()) {
-          if (connectorStatus?.reservation?.[filterKey] === value) {
+          if (connectorStatus?.reservation?.[filterKey as keyof Reservation] === value) {
             return connectorStatus.reservation;
           }
         }
       }
     } else {
       for (const connectorStatus of this.connectors.values()) {
-        if (connectorStatus?.reservation?.[filterKey] === value) {
+        if (connectorStatus?.reservation?.[filterKey as keyof Reservation] === value) {
           return connectorStatus.reservation;
         }
       }
index 0fae41f7ddd259b209d7d1a8132e3a00a8f9dbb7..383db84780f53aa22bb415ba7b3603e6b32bea2f 100644 (file)
@@ -623,7 +623,7 @@ const warnDeprecatedTemplateKey = (
   templateFile: string,
   logMsgToAppend = '',
 ): void => {
-  if (!isUndefined(template[key])) {
+  if (!isUndefined(template[key as keyof ChargingStationTemplate])) {
     const logMsg = `Deprecated template key '${key}' usage in file '${templateFile}'${
       isNotEmptyString(logMsgToAppend) ? `. ${logMsgToAppend}` : ''
     }`;
@@ -637,11 +637,12 @@ const convertDeprecatedTemplateKey = (
   deprecatedKey: string,
   key?: string,
 ): void => {
-  if (!isUndefined(template[deprecatedKey])) {
+  if (!isUndefined(template[deprecatedKey as keyof ChargingStationTemplate])) {
     if (!isUndefined(key)) {
-      template[key!] = template[deprecatedKey] as unknown;
+      (template as unknown as Record<string, unknown>)[key!] =
+        template[deprecatedKey as keyof ChargingStationTemplate];
     }
-    delete template[deprecatedKey];
+    delete template[deprecatedKey as keyof ChargingStationTemplate];
   }
 };
 
index 70d960119901d4a63c037c1032c6310d6c2d1b5c..d506637dcccfda43ec2d1989484ae58633a0ae7c 100644 (file)
@@ -17,8 +17,8 @@ const moduleName = 'ChargingStationWorker';
  *
  * @param data - workerData
  */
-const startChargingStation = (data: ChargingStationWorkerData): void => {
-  new ChargingStation(data.index, data.templateFile).start();
+const startChargingStation = (data?: ChargingStationWorkerData): void => {
+  new ChargingStation(data!.index, data!.templateFile).start();
 };
 
 class ChargingStationWorker extends AsyncResource {
@@ -28,7 +28,7 @@ class ChargingStationWorker extends AsyncResource {
     parentPort?.on('message', (message: WorkerMessage<ChargingStationWorkerData>) => {
       if (message.id === WorkerMessageEvents.startWorkerElement) {
         this.runInAsyncScope(
-          startChargingStation.bind(this) as (data: ChargingStationWorkerData) => void,
+          startChargingStation.bind(this) as (data?: ChargingStationWorkerData) => void,
           this,
           message.data,
         );
index c9c2d84a512bfefacc2d944d1c086851ed83c3f7..84d6961e56cbde3acc4b1e5302e9d0dbed647c6b 100644 (file)
@@ -239,8 +239,8 @@ export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChanne
       ],
     ]);
     this.chargingStation = chargingStation;
-    this.onmessage = this.requestHandler.bind(this) as (message: MessageEvent) => void;
-    this.onmessageerror = this.messageErrorHandler.bind(this) as (message: MessageEvent) => void;
+    this.onmessage = this.requestHandler.bind(this) as (message: unknown) => void;
+    this.onmessageerror = this.messageErrorHandler.bind(this) as (message: unknown) => void;
   }
 
   private async requestHandler(messageEvent: MessageEvent): Promise<void> {
index d94dfe24be6ffaf34d0b9fad0396f37e4195dc6b..b385be7fc47aae52e67eaac792dc4f59256c81a1 100644 (file)
@@ -24,8 +24,8 @@ export class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChannel {
   constructor(uiService: AbstractUIService) {
     super();
     this.uiService = uiService;
-    this.onmessage = this.responseHandler.bind(this) as (message: MessageEvent) => void;
-    this.onmessageerror = this.messageErrorHandler.bind(this) as (message: MessageEvent) => void;
+    this.onmessage = this.responseHandler.bind(this) as (message: unknown) => void;
+    this.onmessageerror = this.messageErrorHandler.bind(this) as (message: unknown) => void;
     this.responses = new Map<string, Responses>();
   }
 
index eaa84704f77621c92050e5c0f23b3d2fe13672a3..5fa160c3fa453ace012e645d4039f5efda0d1b25 100644 (file)
@@ -115,49 +115,73 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
     // }
     super(OCPPVersion.VERSION_16);
     this.incomingRequestHandlers = new Map<OCPP16IncomingRequestCommand, IncomingRequestHandler>([
-      [OCPP16IncomingRequestCommand.RESET, this.handleRequestReset.bind(this)],
-      [OCPP16IncomingRequestCommand.CLEAR_CACHE, this.handleRequestClearCache.bind(this)],
-      [OCPP16IncomingRequestCommand.UNLOCK_CONNECTOR, this.handleRequestUnlockConnector.bind(this)],
+      [
+        OCPP16IncomingRequestCommand.RESET,
+        this.handleRequestReset.bind(this) as unknown as IncomingRequestHandler,
+      ],
+      [
+        OCPP16IncomingRequestCommand.CLEAR_CACHE,
+        this.handleRequestClearCache.bind(this) as IncomingRequestHandler,
+      ],
+      [
+        OCPP16IncomingRequestCommand.UNLOCK_CONNECTOR,
+        this.handleRequestUnlockConnector.bind(this) as unknown as IncomingRequestHandler,
+      ],
       [
         OCPP16IncomingRequestCommand.GET_CONFIGURATION,
-        this.handleRequestGetConfiguration.bind(this),
+        this.handleRequestGetConfiguration.bind(this) as IncomingRequestHandler,
       ],
       [
         OCPP16IncomingRequestCommand.CHANGE_CONFIGURATION,
-        this.handleRequestChangeConfiguration.bind(this),
+        this.handleRequestChangeConfiguration.bind(this) as unknown as IncomingRequestHandler,
       ],
       [
         OCPP16IncomingRequestCommand.GET_COMPOSITE_SCHEDULE,
-        this.handleRequestGetCompositeSchedule.bind(this),
+        this.handleRequestGetCompositeSchedule.bind(this) as unknown as IncomingRequestHandler,
       ],
       [
         OCPP16IncomingRequestCommand.SET_CHARGING_PROFILE,
-        this.handleRequestSetChargingProfile.bind(this),
+        this.handleRequestSetChargingProfile.bind(this) as unknown as IncomingRequestHandler,
       ],
       [
         OCPP16IncomingRequestCommand.CLEAR_CHARGING_PROFILE,
-        this.handleRequestClearChargingProfile.bind(this),
+        this.handleRequestClearChargingProfile.bind(this) as IncomingRequestHandler,
       ],
       [
         OCPP16IncomingRequestCommand.CHANGE_AVAILABILITY,
-        this.handleRequestChangeAvailability.bind(this),
+        this.handleRequestChangeAvailability.bind(this) as unknown as IncomingRequestHandler,
       ],
       [
         OCPP16IncomingRequestCommand.REMOTE_START_TRANSACTION,
-        this.handleRequestRemoteStartTransaction.bind(this),
+        this.handleRequestRemoteStartTransaction.bind(this) as unknown as IncomingRequestHandler,
       ],
       [
         OCPP16IncomingRequestCommand.REMOTE_STOP_TRANSACTION,
-        this.handleRequestRemoteStopTransaction.bind(this),
+        this.handleRequestRemoteStopTransaction.bind(this) as unknown as IncomingRequestHandler,
+      ],
+      [
+        OCPP16IncomingRequestCommand.GET_DIAGNOSTICS,
+        this.handleRequestGetDiagnostics.bind(this) as IncomingRequestHandler,
+      ],
+      [
+        OCPP16IncomingRequestCommand.TRIGGER_MESSAGE,
+        this.handleRequestTriggerMessage.bind(this) as unknown as IncomingRequestHandler,
+      ],
+      [
+        OCPP16IncomingRequestCommand.DATA_TRANSFER,
+        this.handleRequestDataTransfer.bind(this) as unknown as IncomingRequestHandler,
+      ],
+      [
+        OCPP16IncomingRequestCommand.UPDATE_FIRMWARE,
+        this.handleRequestUpdateFirmware.bind(this) as unknown as IncomingRequestHandler,
+      ],
+      [
+        OCPP16IncomingRequestCommand.RESERVE_NOW,
+        this.handleRequestReserveNow.bind(this) as unknown as IncomingRequestHandler,
       ],
-      [OCPP16IncomingRequestCommand.GET_DIAGNOSTICS, this.handleRequestGetDiagnostics.bind(this)],
-      [OCPP16IncomingRequestCommand.TRIGGER_MESSAGE, this.handleRequestTriggerMessage.bind(this)],
-      [OCPP16IncomingRequestCommand.DATA_TRANSFER, this.handleRequestDataTransfer.bind(this)],
-      [OCPP16IncomingRequestCommand.UPDATE_FIRMWARE, this.handleRequestUpdateFirmware.bind(this)],
-      [OCPP16IncomingRequestCommand.RESERVE_NOW, this.handleRequestReserveNow.bind(this)],
       [
         OCPP16IncomingRequestCommand.CANCEL_RESERVATION,
-        this.handleRequestCancelReservation.bind(this),
+        this.handleRequestCancelReservation.bind(this) as unknown as IncomingRequestHandler,
       ],
     ]);
     this.jsonSchemas = new Map<OCPP16IncomingRequestCommand, JSONSchemaType<JsonObject>>([
index 66f1f6b9fc4756dac7c90455f34fc11769ecdc5e..02c03140e341654ddb8a2c4949cebb1d6d59fa39 100644 (file)
@@ -76,16 +76,34 @@ export class OCPP16ResponseService extends OCPPResponseService {
     // }
     super(OCPPVersion.VERSION_16);
     this.responseHandlers = new Map<OCPP16RequestCommand, ResponseHandler>([
-      [OCPP16RequestCommand.BOOT_NOTIFICATION, this.handleResponseBootNotification.bind(this)],
-      [OCPP16RequestCommand.HEARTBEAT, this.emptyResponseHandler.bind(this)],
-      [OCPP16RequestCommand.AUTHORIZE, this.handleResponseAuthorize.bind(this)],
-      [OCPP16RequestCommand.START_TRANSACTION, this.handleResponseStartTransaction.bind(this)],
-      [OCPP16RequestCommand.STOP_TRANSACTION, this.handleResponseStopTransaction.bind(this)],
-      [OCPP16RequestCommand.STATUS_NOTIFICATION, this.emptyResponseHandler.bind(this)],
-      [OCPP16RequestCommand.METER_VALUES, this.emptyResponseHandler.bind(this)],
-      [OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, this.emptyResponseHandler.bind(this)],
-      [OCPP16RequestCommand.DATA_TRANSFER, this.emptyResponseHandler.bind(this)],
-      [OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION, this.emptyResponseHandler.bind(this)],
+      [
+        OCPP16RequestCommand.BOOT_NOTIFICATION,
+        this.handleResponseBootNotification.bind(this) as ResponseHandler,
+      ],
+      [OCPP16RequestCommand.HEARTBEAT, this.emptyResponseHandler.bind(this) as ResponseHandler],
+      [OCPP16RequestCommand.AUTHORIZE, this.handleResponseAuthorize.bind(this) as ResponseHandler],
+      [
+        OCPP16RequestCommand.START_TRANSACTION,
+        this.handleResponseStartTransaction.bind(this) as ResponseHandler,
+      ],
+      [
+        OCPP16RequestCommand.STOP_TRANSACTION,
+        this.handleResponseStopTransaction.bind(this) as ResponseHandler,
+      ],
+      [
+        OCPP16RequestCommand.STATUS_NOTIFICATION,
+        this.emptyResponseHandler.bind(this) as ResponseHandler,
+      ],
+      [OCPP16RequestCommand.METER_VALUES, this.emptyResponseHandler.bind(this) as ResponseHandler],
+      [
+        OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
+        this.emptyResponseHandler.bind(this) as ResponseHandler,
+      ],
+      [OCPP16RequestCommand.DATA_TRANSFER, this.emptyResponseHandler.bind(this) as ResponseHandler],
+      [
+        OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION,
+        this.emptyResponseHandler.bind(this) as ResponseHandler,
+      ],
     ]);
     this.jsonSchemas = new Map<OCPP16RequestCommand, JSONSchemaType<JsonObject>>([
       [
index f65e0c6efca4feecff0cef091dcb40a443b4597e..c3e708df176d8c08a8c7f8a85c1bd99e0927dbcd 100644 (file)
@@ -411,9 +411,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
         const phaseValue = `L${phase}-N`;
         meterValue.sampledValue.push(
           OCPP16ServiceUtils.buildSampledValue(
-            (powerPerPhaseSampledValueTemplates[`L${phase}`] as SampledValueTemplate) ??
-              powerSampledValueTemplate,
-            powerMeasurandValues[`L${phase}`] as number,
+            powerPerPhaseSampledValueTemplates[
+              `L${phase}` as keyof MeasurandPerPhaseSampledValueTemplates
+            ]! ?? powerSampledValueTemplate,
+            powerMeasurandValues[`L${phase}` as keyof MeasurandPerPhaseSampledValueTemplates],
             undefined,
             phaseValue as OCPP16MeterValuePhase,
           ),
@@ -632,9 +633,10 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils {
         const phaseValue = `L${phase}`;
         meterValue.sampledValue.push(
           OCPP16ServiceUtils.buildSampledValue(
-            (currentPerPhaseSampledValueTemplates[phaseValue] as SampledValueTemplate) ??
-              currentSampledValueTemplate,
-            currentMeasurandValues[phaseValue] as number,
+            currentPerPhaseSampledValueTemplates[
+              phaseValue as keyof MeasurandPerPhaseSampledValueTemplates
+            ]! ?? currentSampledValueTemplate,
+            currentMeasurandValues[phaseValue as keyof MeasurandPerPhaseSampledValueTemplates],
             undefined,
             phaseValue as OCPP16MeterValuePhase,
           ),
index 4984b115e48a03d0315a83eeee28ae2c74e488cf..4727194659aaad501a1f06e127eae9530f0278ee 100644 (file)
@@ -40,9 +40,15 @@ export class OCPP20ResponseService extends OCPPResponseService {
     // }
     super(OCPPVersion.VERSION_20);
     this.responseHandlers = new Map<OCPP20RequestCommand, ResponseHandler>([
-      [OCPP20RequestCommand.BOOT_NOTIFICATION, this.handleResponseBootNotification.bind(this)],
-      [OCPP20RequestCommand.HEARTBEAT, this.emptyResponseHandler.bind(this)],
-      [OCPP20RequestCommand.STATUS_NOTIFICATION, this.emptyResponseHandler.bind(this)],
+      [
+        OCPP20RequestCommand.BOOT_NOTIFICATION,
+        this.handleResponseBootNotification.bind(this) as ResponseHandler,
+      ],
+      [OCPP20RequestCommand.HEARTBEAT, this.emptyResponseHandler.bind(this) as ResponseHandler],
+      [
+        OCPP20RequestCommand.STATUS_NOTIFICATION,
+        this.emptyResponseHandler.bind(this) as ResponseHandler,
+      ],
     ]);
     this.jsonSchemas = new Map<OCPP20RequestCommand, JSONSchemaType<JsonObject>>([
       [
index dcd7447272a4dccb74c1dc21844141f2353385b2..16d83ee99c6be12b4bc56cadc6e65d83830cbd03 100644 (file)
@@ -15,7 +15,6 @@ import {
   ErrorType,
   FileType,
   IncomingRequestCommand,
-  type JsonObject,
   type JsonType,
   MessageTrigger,
   MessageType,
@@ -144,10 +143,14 @@ export class OCPPServiceUtils {
   }
 
   public static convertDateToISOString<T extends JsonType>(obj: T): void {
-    for (const key in obj as JsonObject) {
+    for (const key in obj) {
+      // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
       if (obj![key] instanceof Date) {
-        obj![key] = (obj![key] as Date).toISOString();
+        // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
+        (obj![key] as string) = (obj![key] as Date).toISOString();
+        // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
       } else if (obj![key] !== null && typeof obj![key] === 'object') {
+        // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
         OCPPServiceUtils.convertDateToISOString<T>(obj![key] as T);
       }
     }
index cb02d4a54101fd75b8962cee4586bc7b4622eb0d..103a27aed75c163ef7481035ae2eef681ac6b81a 100644 (file)
@@ -132,9 +132,9 @@ export class UIHttpServer extends AbstractUIServer {
                   body ?? Constants.EMPTY_FREEZED_OBJECT,
                 ),
               )
-              .then((protocolResponse: ProtocolResponse) => {
+              .then((protocolResponse: ProtocolResponse | undefined) => {
                 if (!isNullOrUndefined(protocolResponse)) {
-                  this.sendResponse(protocolResponse);
+                  this.sendResponse(protocolResponse!);
                 }
               })
               .catch(Constants.EMPTY_FUNCTION);
index b28b6df76f4d33e85ab2cf82178a86addfc6e94c..befb9854fa8a1a0d91e9daeff2a935eaa5634a0d 100644 (file)
@@ -60,9 +60,9 @@ export class UIWebSocketServer extends AbstractUIServer {
         this.uiServices
           .get(version)
           ?.requestHandler(request)
-          .then((protocolResponse: ProtocolResponse) => {
+          .then((protocolResponse: ProtocolResponse | undefined) => {
             if (!isNullOrUndefined(protocolResponse)) {
-              this.sendResponse(protocolResponse);
+              this.sendResponse(protocolResponse!);
             }
           })
           .catch(Constants.EMPTY_FUNCTION);
index 0caf003e17039b0ad11f5e6f059e2d95d34cc3e6..8e359b4d0ce21c93574fdb11e7d0a102a9d28a3c 100644 (file)
@@ -19,34 +19,40 @@ import type { AbstractUIServer } from '../AbstractUIServer';
 const moduleName = 'AbstractUIService';
 
 export abstract class AbstractUIService {
-  protected static readonly ProcedureNameToBroadCastChannelProcedureNameMapping: Omit<
-    Record<ProcedureName, BroadcastChannelProcedureName>,
-    | ProcedureName.START_SIMULATOR
-    | ProcedureName.STOP_SIMULATOR
-    | ProcedureName.LIST_CHARGING_STATIONS
-  > = {
-    [ProcedureName.START_CHARGING_STATION]: BroadcastChannelProcedureName.START_CHARGING_STATION,
-    [ProcedureName.STOP_CHARGING_STATION]: BroadcastChannelProcedureName.STOP_CHARGING_STATION,
-    [ProcedureName.CLOSE_CONNECTION]: BroadcastChannelProcedureName.CLOSE_CONNECTION,
-    [ProcedureName.OPEN_CONNECTION]: BroadcastChannelProcedureName.OPEN_CONNECTION,
-    [ProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR]:
+  protected static readonly ProcedureNameToBroadCastChannelProcedureNameMapping = new Map<
+    ProcedureName,
+    BroadcastChannelProcedureName
+  >([
+    [ProcedureName.START_CHARGING_STATION, BroadcastChannelProcedureName.START_CHARGING_STATION],
+    [ProcedureName.STOP_CHARGING_STATION, BroadcastChannelProcedureName.STOP_CHARGING_STATION],
+    [ProcedureName.CLOSE_CONNECTION, BroadcastChannelProcedureName.CLOSE_CONNECTION],
+    [ProcedureName.OPEN_CONNECTION, BroadcastChannelProcedureName.OPEN_CONNECTION],
+    [
+      ProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
       BroadcastChannelProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
-    [ProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR]:
+    ],
+    [
+      ProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
       BroadcastChannelProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
-    [ProcedureName.SET_SUPERVISION_URL]: BroadcastChannelProcedureName.SET_SUPERVISION_URL,
-    [ProcedureName.START_TRANSACTION]: BroadcastChannelProcedureName.START_TRANSACTION,
-    [ProcedureName.STOP_TRANSACTION]: BroadcastChannelProcedureName.STOP_TRANSACTION,
-    [ProcedureName.AUTHORIZE]: BroadcastChannelProcedureName.AUTHORIZE,
-    [ProcedureName.BOOT_NOTIFICATION]: BroadcastChannelProcedureName.BOOT_NOTIFICATION,
-    [ProcedureName.STATUS_NOTIFICATION]: BroadcastChannelProcedureName.STATUS_NOTIFICATION,
-    [ProcedureName.HEARTBEAT]: BroadcastChannelProcedureName.HEARTBEAT,
-    [ProcedureName.METER_VALUES]: BroadcastChannelProcedureName.METER_VALUES,
-    [ProcedureName.DATA_TRANSFER]: BroadcastChannelProcedureName.DATA_TRANSFER,
-    [ProcedureName.DIAGNOSTICS_STATUS_NOTIFICATION]:
+    ],
+    [ProcedureName.SET_SUPERVISION_URL, BroadcastChannelProcedureName.SET_SUPERVISION_URL],
+    [ProcedureName.START_TRANSACTION, BroadcastChannelProcedureName.START_TRANSACTION],
+    [ProcedureName.STOP_TRANSACTION, BroadcastChannelProcedureName.STOP_TRANSACTION],
+    [ProcedureName.AUTHORIZE, BroadcastChannelProcedureName.AUTHORIZE],
+    [ProcedureName.BOOT_NOTIFICATION, BroadcastChannelProcedureName.BOOT_NOTIFICATION],
+    [ProcedureName.STATUS_NOTIFICATION, BroadcastChannelProcedureName.STATUS_NOTIFICATION],
+    [ProcedureName.HEARTBEAT, BroadcastChannelProcedureName.HEARTBEAT],
+    [ProcedureName.METER_VALUES, BroadcastChannelProcedureName.METER_VALUES],
+    [ProcedureName.DATA_TRANSFER, BroadcastChannelProcedureName.DATA_TRANSFER],
+    [
+      ProcedureName.DIAGNOSTICS_STATUS_NOTIFICATION,
       BroadcastChannelProcedureName.DIAGNOSTICS_STATUS_NOTIFICATION,
-    [ProcedureName.FIRMWARE_STATUS_NOTIFICATION]:
+    ],
+    [
+      ProcedureName.FIRMWARE_STATUS_NOTIFICATION,
       BroadcastChannelProcedureName.FIRMWARE_STATUS_NOTIFICATION,
-  };
+    ],
+  ]);
 
   protected readonly requestHandlers: Map<ProcedureName, ProtocolRequestHandler>;
   private readonly version: ProtocolVersion;
@@ -144,9 +150,7 @@ export abstract class AbstractUIService {
   ): void {
     this.sendBroadcastChannelRequest(
       uuid,
-      AbstractUIService.ProcedureNameToBroadCastChannelProcedureNameMapping[
-        procedureName
-      ] as BroadcastChannelProcedureName,
+      AbstractUIService.ProcedureNameToBroadCastChannelProcedureNameMapping.get(procedureName)!,
       payload,
     );
   }
index b8ac1c9181069c13cd8d44d075eff95953e223e6..e7570c1a24f1b03f4b2e48a9e3a3f58fae25bbdb 100644 (file)
@@ -1,13 +1,13 @@
 import { AbstractUIService } from './AbstractUIService';
-import { type ProcedureName, type ProtocolRequestHandler, ProtocolVersion } from '../../../types';
+import { type ProtocolRequestHandler, ProtocolVersion } from '../../../types';
 import type { AbstractUIServer } from '../AbstractUIServer';
 
 export class UIService001 extends AbstractUIService {
   constructor(uiServer: AbstractUIServer) {
     super(uiServer, ProtocolVersion['0.0.1']);
-    for (const procedureName in AbstractUIService.ProcedureNameToBroadCastChannelProcedureNameMapping) {
+    for (const procedureName of AbstractUIService.ProcedureNameToBroadCastChannelProcedureNameMapping.keys()) {
       this.requestHandlers.set(
-        procedureName as ProcedureName,
+        procedureName,
         this.handleProtocolRequest.bind(this) as ProtocolRequestHandler,
       );
     }
index 4aaa2250dc77169cf0113b0958ce23738680da26..cbc9f20d4125a6a562444dddd22860e68cded900 100644 (file)
@@ -119,16 +119,18 @@ export class Configuration {
       "Use 'stationTemplateUrls' instead",
     );
     // eslint-disable-next-line @typescript-eslint/dot-notation
-    !isUndefined(Configuration.getConfigurationData()!['stationTemplateURLs']) &&
+    !isUndefined(
+      Configuration.getConfigurationData()!['stationTemplateURLs' as keyof ConfigurationData],
+    ) &&
       (Configuration.getConfigurationData()!.stationTemplateUrls =
         Configuration.getConfigurationData()![
           // eslint-disable-next-line @typescript-eslint/dot-notation
-          'stationTemplateURLs'
+          'stationTemplateURLs' as keyof ConfigurationData
         ] as StationTemplateUrl[]);
     Configuration.getConfigurationData()!.stationTemplateUrls.forEach(
       (stationTemplateUrl: StationTemplateUrl) => {
         // eslint-disable-next-line @typescript-eslint/dot-notation
-        if (!isUndefined(stationTemplateUrl['numberOfStation'])) {
+        if (!isUndefined(stationTemplateUrl['numberOfStation' as keyof StationTemplateUrl])) {
           console.error(
             `${chalk.green(Configuration.logPrefix())} ${chalk.red(
               `Deprecated configuration key 'numberOfStation' usage for template file '${stationTemplateUrl.file}' in 'stationTemplateUrls'. Use 'numberOfStations' instead`,
@@ -147,10 +149,14 @@ export class Configuration {
       "Use 'supervisionUrls' instead",
     );
     // eslint-disable-next-line @typescript-eslint/dot-notation
-    if (!isUndefined(Configuration.getConfigurationData()!['supervisionURLs'])) {
+    if (
+      !isUndefined(
+        Configuration.getConfigurationData()!['supervisionURLs' as keyof ConfigurationData],
+      )
+    ) {
       Configuration.getConfigurationData()!.supervisionUrls = Configuration.getConfigurationData()![
         // eslint-disable-next-line @typescript-eslint/dot-notation
-        'supervisionURLs'
+        'supervisionURLs' as keyof ConfigurationData
       ] as string | string[];
     }
     return Configuration.getConfigurationData()?.supervisionUrls;
@@ -445,9 +451,14 @@ export class Configuration {
   ) {
     if (
       sectionName &&
-      !isUndefined(Configuration.getConfigurationData()![sectionName]) &&
+      !isUndefined(Configuration.getConfigurationData()![sectionName as keyof ConfigurationData]) &&
       !isUndefined(
-        (Configuration.getConfigurationData()![sectionName] as Record<string, unknown>)[key],
+        (
+          Configuration.getConfigurationData()![sectionName as keyof ConfigurationData] as Record<
+            string,
+            unknown
+          >
+        )[key],
       )
     ) {
       console.error(
@@ -457,7 +468,9 @@ export class Configuration {
           }`,
         )}`,
       );
-    } else if (!isUndefined(Configuration.getConfigurationData()![key])) {
+    } else if (
+      !isUndefined(Configuration.getConfigurationData()![key as keyof ConfigurationData])
+    ) {
       console.error(
         `${chalk.green(Configuration.logPrefix())} ${chalk.red(
           `Deprecated configuration key '${key}' usage${
index 6ea286b2b23d0b0a5cab66e10f24e7012d24f249..239ec9186310c2de9d2a6f94d78f8d75d99597f3 100644 (file)
@@ -46,7 +46,10 @@ if (logConfiguration.rotate === true) {
 export const logger = createLogger({
   silent: !logConfiguration.enabled,
   level: logConfiguration.level,
-  format: format.combine(format.splat(), (format[logConfiguration.format!] as FormatWrap)()),
+  format: format.combine(
+    format.splat(),
+    (format[logConfiguration.format! as keyof FormatWrap] as FormatWrap)(),
+  ),
   transports,
 });
 
@@ -57,7 +60,10 @@ export const logger = createLogger({
 if (logConfiguration.console) {
   logger.add(
     new TransportType.Console({
-      format: format.combine(format.splat(), (format[logConfiguration.format!] as FormatWrap)()),
+      format: format.combine(
+        format.splat(),
+        (format[logConfiguration.format! as keyof FormatWrap] as FormatWrap)(),
+      ),
     }),
   );
 }
index 49a5fdf954c4a54e9eb807ab434880ec79027480..8d51349a2357fbb9ea0b450dd3367f00f8c7406e 100644 (file)
@@ -198,7 +198,7 @@ export const isCFEnvironment = (): boolean => {
 };
 
 export const isIterable = <T>(obj: T): boolean => {
-  return !isNullOrUndefined(obj) ? typeof obj[Symbol.iterator] === 'function' : false;
+  return !isNullOrUndefined(obj) ? typeof obj[Symbol.iterator as keyof T] === 'function' : false;
 };
 
 const isString = (value: unknown): boolean => {
@@ -332,8 +332,12 @@ export const getWebSocketCloseEventStatusString = (code: number): string => {
       return '(For applications)';
     }
   }
-  if (!isUndefined(WebSocketCloseEventStatusString[code])) {
-    return WebSocketCloseEventStatusString[code] as string;
+  if (
+    !isUndefined(
+      WebSocketCloseEventStatusString[code as keyof typeof WebSocketCloseEventStatusString],
+    )
+  ) {
+    return WebSocketCloseEventStatusString[code as keyof typeof WebSocketCloseEventStatusString];
   }
   return '(Unknown)';
 };
index 75fc2f6bed5baaf47a9e2aae9f52d1992253eec3..41145f803ed448ce60b9a03fa584af5403ae4a92 100644 (file)
@@ -1,8 +1,7 @@
 import type { EventEmitter } from 'node:events';
 import { existsSync } from 'node:fs';
-import type { Worker } from 'node:worker_threads';
 
-import type { ErrorHandler, ExitHandler, PoolEmitter, PoolInfo } from 'poolifier';
+import type { PoolEmitter, PoolInfo } from 'poolifier';
 
 import { WorkerConstants } from './WorkerConstants';
 import type { SetInfo, WorkerData, WorkerOptions } from './WorkerTypes';
@@ -44,14 +43,10 @@ export abstract class WorkerAbstract<T extends WorkerData> {
     }
     this.workerScript = workerScript;
     this.workerOptions = workerOptions;
-    this.workerOptions.poolOptions?.messageHandler?.bind(this);
-    this.workerOptions.poolOptions!.errorHandler = (
-      this.workerOptions?.poolOptions?.errorHandler ?? defaultErrorHandler
-    ).bind(this) as ErrorHandler<Worker>;
-    this.workerOptions.poolOptions?.onlineHandler?.bind(this);
-    this.workerOptions.poolOptions!.exitHandler = (
-      this.workerOptions?.poolOptions?.exitHandler ?? defaultExitHandler
-    ).bind(this) as ExitHandler<Worker>;
+    this.workerOptions.poolOptions!.errorHandler =
+      this.workerOptions.poolOptions?.errorHandler ?? defaultErrorHandler;
+    this.workerOptions.poolOptions!.exitHandler =
+      this.workerOptions.poolOptions?.exitHandler ?? defaultExitHandler;
   }
 
   /**
index 03d52625e8ec5cd0150bca7f34f33ed368beb1bf..61118a0d0a274d17871a71ec8e2ebec3efa2c2a9 100644 (file)
@@ -16,7 +16,7 @@ import {
 import { sleep } from './WorkerUtils';
 
 export class WorkerSet extends WorkerAbstract<WorkerData> {
-  public readonly emitter: EventEmitter;
+  public readonly emitter!: EventEmitter;
   private readonly workerSet: Set<WorkerSetElement>;
 
   /**
@@ -35,7 +35,7 @@ export class WorkerSet extends WorkerAbstract<WorkerData> {
       ...this.workerOptions.poolOptions,
     };
     this.workerSet = new Set<WorkerSetElement>();
-    if (this.workerOptions?.poolOptions?.enableEvents) {
+    if (this.workerOptions.poolOptions?.enableEvents) {
       this.emitter = new EventEmitter();
     }
   }
@@ -110,25 +110,25 @@ export class WorkerSet extends WorkerAbstract<WorkerData> {
     });
     worker.on(
       'message',
-      this.workerOptions?.poolOptions?.messageHandler ?? WorkerConstants.EMPTY_FUNCTION,
+      this.workerOptions.poolOptions?.messageHandler ?? WorkerConstants.EMPTY_FUNCTION,
     );
     worker.on(
       'error',
-      this.workerOptions?.poolOptions?.errorHandler ?? WorkerConstants.EMPTY_FUNCTION,
+      this.workerOptions.poolOptions?.errorHandler ?? WorkerConstants.EMPTY_FUNCTION,
     );
     worker.on('error', (error) => {
       this.emitter?.emit(WorkerSetEvents.error, error);
-      if (this.workerOptions?.poolOptions?.restartWorkerOnError) {
+      if (this.workerOptions.poolOptions?.restartWorkerOnError) {
         this.addWorkerSetElement();
       }
     });
     worker.on(
       'online',
-      this.workerOptions?.poolOptions?.onlineHandler ?? WorkerConstants.EMPTY_FUNCTION,
+      this.workerOptions.poolOptions?.onlineHandler ?? WorkerConstants.EMPTY_FUNCTION,
     );
     worker.on(
       'exit',
-      this.workerOptions?.poolOptions?.exitHandler ?? WorkerConstants.EMPTY_FUNCTION,
+      this.workerOptions.poolOptions?.exitHandler ?? WorkerConstants.EMPTY_FUNCTION,
     );
     worker.once('exit', () =>
       this.removeWorkerSetElement(this.getWorkerSetElementByWorker(worker)!),
index e48109329a644408d0895a4cf16a8168fc22a4fa..5e8e5f443d8de50db17faeb5f4b852e6d7ff9479 100644 (file)
@@ -28,9 +28,9 @@
     // "isolatedModules": true,               /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
 
     /* Strict Type-Checking Options */
-    // "strict": true,                        /* Enable all strict type-checking options. */
+    "strict": true,                           /* Enable all strict type-checking options. */
     // "noImplicitAny": true,                 /* Raise error on expressions and declarations with an implied 'any' type. */
-    "strictNullChecks": true,                 /* Enable strict null checks. */
+    // "strictNullChecks": true,              /* Enable strict null checks. */
     // "strictFunctionTypes": true,           /* Enable strict checking of function types. */
     // "strictBindCallApply": true,           /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
     // "strictPropertyInitialization": true,  /* Enable strict checking of property initialization in classes. */