From: Jérôme Benoit Date: Sun, 12 Feb 2023 14:03:13 +0000 (+0100) Subject: refactor(simulator): switch to named exports X-Git-Tag: v1.1.95~72 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=268a74bb051fcbbad532fd833f0d8fd2b33b6c64;p=e-mobility-charging-stations-simulator.git refactor(simulator): switch to named exports Signed-off-by: Jérôme Benoit --- diff --git a/mikro-orm.config-template.ts b/mikro-orm.config-template.ts index eea71b03..7ac022be 100644 --- a/mikro-orm.config-template.ts +++ b/mikro-orm.config-template.ts @@ -4,7 +4,7 @@ import { TsMorphMetadataProvider } from '@mikro-orm/reflection'; import { PerformanceData } from './src/types/orm/entities/PerformanceData'; import { PerformanceRecord } from './src/types/orm/entities/PerformanceRecord'; -import Constants from './src/utils/Constants'; +import { Constants } from './src/utils/Constants'; export default { metadataProvider: TsMorphMetadataProvider, diff --git a/src/charging-station/AuthorizedTagsCache.ts b/src/charging-station/AuthorizedTagsCache.ts index a3c8e5cd..14f6844e 100644 --- a/src/charging-station/AuthorizedTagsCache.ts +++ b/src/charging-station/AuthorizedTagsCache.ts @@ -1,11 +1,11 @@ import fs from 'node:fs'; -import { FileType } from '../types/FileType'; -import FileUtils from '../utils/FileUtils'; -import logger from '../utils/Logger'; -import Utils from '../utils/Utils'; +import { FileType } from '../types'; +import { FileUtils } from '../utils/FileUtils'; +import { logger } from '../utils/Logger'; +import { Utils } from '../utils/Utils'; -export default class AuthorizedTagsCache { +export class AuthorizedTagsCache { private static instance: AuthorizedTagsCache | null = null; private readonly tagsCaches: Map; private readonly FSWatchers: Map; diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index dca2e060..3c365932 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -2,32 +2,30 @@ import { AsyncResource } from 'async_hooks'; -import type ChargingStation from './ChargingStation'; +import type { ChargingStation } from './ChargingStation'; import { ChargingStationUtils } from './ChargingStationUtils'; -import BaseError from '../exception/BaseError'; -import PerformanceStatistics from '../performance/PerformanceStatistics'; -import { - type AutomaticTransactionGeneratorConfiguration, - IdTagDistribution, - type Status, -} from '../types/AutomaticTransactionGenerator'; -import { RequestCommand } from '../types/ocpp/Requests'; +import { BaseError } from '../exception'; +import { PerformanceStatistics } from '../performance/PerformanceStatistics'; import { AuthorizationStatus, type AuthorizeRequest, type AuthorizeResponse, + type AutomaticTransactionGeneratorConfiguration, + IdTagDistribution, + RequestCommand, type StartTransactionRequest, type StartTransactionResponse, + type Status, StopTransactionReason, type StopTransactionResponse, -} from '../types/ocpp/Transaction'; -import Constants from '../utils/Constants'; -import logger from '../utils/Logger'; -import Utils from '../utils/Utils'; +} from '../types'; +import { Constants } from '../utils/Constants'; +import { logger } from '../utils/Logger'; +import { Utils } from '../utils/Utils'; const moduleName = 'AutomaticTransactionGenerator'; -export default class AutomaticTransactionGenerator extends AsyncResource { +export class AutomaticTransactionGenerator extends AsyncResource { private static readonly instances: Map = new Map< string, AutomaticTransactionGenerator diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 62f04891..1acd5bcb 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -8,9 +8,9 @@ import chalk from 'chalk'; import { ChargingStationUtils } from './ChargingStationUtils'; import type { AbstractUIServer } from './ui-server/AbstractUIServer'; -import UIServerFactory from './ui-server/UIServerFactory'; +import { UIServerFactory } from './ui-server/UIServerFactory'; import { version } from '../../package.json'; -import BaseError from '../exception/BaseError'; +import { BaseError } from '../exception'; import type { Storage } from '../performance/storage/Storage'; import { StorageFactory } from '../performance/storage/StorageFactory'; import { @@ -19,15 +19,13 @@ import { type ChargingStationWorkerMessage, type ChargingStationWorkerMessageData, ChargingStationWorkerMessageEvents, -} from '../types/ChargingStationWorker'; -import type { StationTemplateUrl } from '../types/ConfigurationData'; -import type { Statistics } from '../types/Statistics'; -import type { MessageHandler } from '../types/Worker'; -import Configuration from '../utils/Configuration'; -import logger from '../utils/Logger'; -import Utils from '../utils/Utils'; -import type WorkerAbstract from '../worker/WorkerAbstract'; -import WorkerFactory from '../worker/WorkerFactory'; + type StationTemplateUrl, + type Statistics, +} from '../types'; +import { Configuration } from '../utils/Configuration'; +import { logger } from '../utils/Logger'; +import { Utils } from '../utils/Utils'; +import { type MessageHandler, type WorkerAbstract, WorkerFactory } from '../worker'; const moduleName = 'Bootstrap'; diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index a425d865..0118f3d1 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -9,92 +9,85 @@ import { parentPort } from 'worker_threads'; import merge from 'just-merge'; import WebSocket, { type RawData } from 'ws'; -import AuthorizedTagsCache from './AuthorizedTagsCache'; -import AutomaticTransactionGenerator from './AutomaticTransactionGenerator'; +import { AuthorizedTagsCache } from './AuthorizedTagsCache'; +import { AutomaticTransactionGenerator } from './AutomaticTransactionGenerator'; import { ChargingStationConfigurationUtils } from './ChargingStationConfigurationUtils'; import { ChargingStationUtils } from './ChargingStationUtils'; -import ChargingStationWorkerBroadcastChannel from './ChargingStationWorkerBroadcastChannel'; +import { ChargingStationWorkerBroadcastChannel } from './ChargingStationWorkerBroadcastChannel'; import { MessageChannelUtils } from './MessageChannelUtils'; -import OCPP16IncomingRequestService from './ocpp/1.6/OCPP16IncomingRequestService'; -import OCPP16RequestService from './ocpp/1.6/OCPP16RequestService'; -import OCPP16ResponseService from './ocpp/1.6/OCPP16ResponseService'; +import { OCPP16IncomingRequestService } from './ocpp/1.6/OCPP16IncomingRequestService'; +import { OCPP16RequestService } from './ocpp/1.6/OCPP16RequestService'; +import { OCPP16ResponseService } from './ocpp/1.6/OCPP16ResponseService'; import { OCPP16ServiceUtils } from './ocpp/1.6/OCPP16ServiceUtils'; -import OCPP20IncomingRequestService from './ocpp/2.0/OCPP20IncomingRequestService'; -import OCPP20RequestService from './ocpp/2.0/OCPP20RequestService'; -import OCPP20ResponseService from './ocpp/2.0/OCPP20ResponseService'; -import type OCPPIncomingRequestService from './ocpp/OCPPIncomingRequestService'; -import type OCPPRequestService from './ocpp/OCPPRequestService'; +import { OCPP20IncomingRequestService } from './ocpp/2.0/OCPP20IncomingRequestService'; +import { OCPP20RequestService } from './ocpp/2.0/OCPP20RequestService'; +import { OCPP20ResponseService } from './ocpp/2.0/OCPP20ResponseService'; +import type { OCPPIncomingRequestService } from './ocpp/OCPPIncomingRequestService'; +import type { OCPPRequestService } from './ocpp/OCPPRequestService'; import { OCPPServiceUtils } from './ocpp/OCPPServiceUtils'; -import SharedLRUCache from './SharedLRUCache'; -import BaseError from '../exception/BaseError'; -import OCPPError from '../exception/OCPPError'; -import PerformanceStatistics from '../performance/PerformanceStatistics'; -import type { AutomaticTransactionGeneratorConfiguration } from '../types/AutomaticTransactionGenerator'; -import type { ChargingStationConfiguration } from '../types/ChargingStationConfiguration'; -import type { ChargingStationInfo } from '../types/ChargingStationInfo'; -import type { ChargingStationOcppConfiguration } from '../types/ChargingStationOcppConfiguration'; -import { - type ChargingStationTemplate, - CurrentType, - type FirmwareUpgrade, - PowerUnits, - type WsOptions, -} from '../types/ChargingStationTemplate'; -import { SupervisionUrlDistribution } from '../types/ConfigurationData'; -import type { ConnectorStatus } from '../types/ConnectorStatus'; -import { FileType } from '../types/FileType'; -import type { JsonType } from '../types/JsonType'; -import { - ConnectorPhaseRotation, - StandardParametersKey, - SupportedFeatureProfiles, - VendorDefaultParametersKey, -} from '../types/ocpp/Configuration'; -import { ConnectorStatusEnum } from '../types/ocpp/ConnectorStatusEnum'; -import { ErrorType } from '../types/ocpp/ErrorType'; -import { MessageType } from '../types/ocpp/MessageType'; -import { MeterValue, MeterValueMeasurand } from '../types/ocpp/MeterValues'; -import { OCPPVersion } from '../types/ocpp/OCPPVersion'; +import { SharedLRUCache } from './SharedLRUCache'; +import { BaseError, OCPPError } from '../exception'; +import { PerformanceStatistics } from '../performance/PerformanceStatistics'; import { + type AutomaticTransactionGeneratorConfiguration, AvailabilityType, type BootNotificationRequest, + type BootNotificationResponse, type CachedRequest, + type ChargingStationConfiguration, + type ChargingStationInfo, + type ChargingStationOcppConfiguration, + type ChargingStationTemplate, + ConnectorPhaseRotation, + ConnectorStatus, + ConnectorStatusEnum, + CurrentType, type ErrorCallback, + type ErrorResponse, + ErrorType, + FileType, FirmwareStatus, type FirmwareStatusNotificationRequest, + type FirmwareStatusNotificationResponse, + type FirmwareUpgrade, type HeartbeatRequest, + type HeartbeatResponse, type IncomingRequest, - IncomingRequestCommand, + type IncomingRequestCommand, + type JsonType, + MessageType, + type MeterValue, + MeterValueMeasurand, type MeterValuesRequest, + type MeterValuesResponse, + OCPPVersion, type OutgoingRequest, + PowerUnits, + RegistrationStatusEnumType, RequestCommand, + type Response, type ResponseCallback, + StandardParametersKey, type StatusNotificationRequest, -} from '../types/ocpp/Requests'; -import { - type BootNotificationResponse, - type ErrorResponse, - type FirmwareStatusNotificationResponse, - type HeartbeatResponse, - type MeterValuesResponse, - RegistrationStatusEnumType, - type Response, type StatusNotificationResponse, -} from '../types/ocpp/Responses'; -import { StopTransactionReason, type StopTransactionRequest, type StopTransactionResponse, -} from '../types/ocpp/Transaction'; -import { WSError, WebSocketCloseEventStatusCode } from '../types/WebSocket'; -import Configuration from '../utils/Configuration'; -import Constants from '../utils/Constants'; + SupervisionUrlDistribution, + SupportedFeatureProfiles, + VendorDefaultParametersKey, + type WSError, + WebSocketCloseEventStatusCode, + type WsOptions, +} from '../types'; +import { Configuration } from '../utils/Configuration'; +import { Constants } from '../utils/Constants'; import { ACElectricUtils, DCElectricUtils } from '../utils/ElectricUtils'; -import FileUtils from '../utils/FileUtils'; -import logger from '../utils/Logger'; -import Utils from '../utils/Utils'; +import { FileUtils } from '../utils/FileUtils'; +import { logger } from '../utils/Logger'; +import { Utils } from '../utils/Utils'; -export default class ChargingStation { +export class ChargingStation { public readonly index: number; public readonly templateFile: string; public stationInfo!: ChargingStationInfo; diff --git a/src/charging-station/ChargingStationConfigurationUtils.ts b/src/charging-station/ChargingStationConfigurationUtils.ts index e31e6bfb..541fd445 100644 --- a/src/charging-station/ChargingStationConfigurationUtils.ts +++ b/src/charging-station/ChargingStationConfigurationUtils.ts @@ -1,7 +1,6 @@ -import type ChargingStation from './ChargingStation'; -import type { ConfigurationKey } from '../types/ChargingStationOcppConfiguration'; -import type { StandardParametersKey } from '../types/ocpp/Configuration'; -import logger from '../utils/Logger'; +import type { ChargingStation } from './ChargingStation'; +import type { ConfigurationKey, StandardParametersKey } from '../types'; +import { logger } from '../utils/Logger'; type ConfigurationKeyOptions = { readonly?: boolean; visible?: boolean; reboot?: boolean }; type DeleteConfigurationKeyParams = { save?: boolean; caseInsensitive?: boolean }; diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 9d23f1b4..92ed0406 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -4,31 +4,31 @@ import { fileURLToPath } from 'node:url'; import moment from 'moment'; -import type ChargingStation from './ChargingStation'; -import BaseError from '../exception/BaseError'; -import type { ChargingStationInfo } from '../types/ChargingStationInfo'; +import type { ChargingStation } from './ChargingStation'; +import { BaseError } from '../exception'; import { AmpereUnits, - type ChargingStationTemplate, - CurrentType, - Voltage, -} from '../types/ChargingStationTemplate'; -import { ChargingProfileKindType, RecurrencyKindType } from '../types/ocpp/1.6/ChargingProfile'; -import type { OCPP16BootNotificationRequest } from '../types/ocpp/1.6/Requests'; -import { BootReasonEnumType, type OCPP20BootNotificationRequest } from '../types/ocpp/2.0/Requests'; -import { + type BootNotificationRequest, + BootReasonEnumType, type ChargingProfile, + ChargingProfileKindType, ChargingRateUnitType, type ChargingSchedulePeriod, -} from '../types/ocpp/ChargingProfile'; -import { OCPPVersion } from '../types/ocpp/OCPPVersion'; -import type { BootNotificationRequest } from '../types/ocpp/Requests'; -import { WorkerProcessType } from '../types/Worker'; -import Configuration from '../utils/Configuration'; -import Constants from '../utils/Constants'; + type ChargingStationInfo, + type ChargingStationTemplate, + CurrentType, + type OCPP16BootNotificationRequest, + type OCPP20BootNotificationRequest, + OCPPVersion, + RecurrencyKindType, + Voltage, +} from '../types'; +import { Configuration } from '../utils/Configuration'; +import { Constants } from '../utils/Constants'; import { ACElectricUtils, DCElectricUtils } from '../utils/ElectricUtils'; -import logger from '../utils/Logger'; -import Utils from '../utils/Utils'; +import { logger } from '../utils/Logger'; +import { Utils } from '../utils/Utils'; +import { WorkerProcessType } from '../worker'; const moduleName = 'ChargingStationUtils'; diff --git a/src/charging-station/ChargingStationWorker.ts b/src/charging-station/ChargingStationWorker.ts index 2204f308..d28204e3 100644 --- a/src/charging-station/ChargingStationWorker.ts +++ b/src/charging-station/ChargingStationWorker.ts @@ -4,12 +4,11 @@ import { parentPort, workerData } from 'worker_threads'; import { ThreadWorker } from 'poolifier'; -import ChargingStation from './ChargingStation'; +import { ChargingStation } from './ChargingStation'; import { ChargingStationUtils } from './ChargingStationUtils'; -import type { ChargingStationWorkerData } from '../types/ChargingStationWorker'; -import { type WorkerMessage, WorkerMessageEvents } from '../types/Worker'; -import Utils from '../utils/Utils'; -import WorkerConstants from '../worker/WorkerConstants'; +import type { ChargingStationWorkerData } from '../types'; +import { Utils } from '../utils/Utils'; +import { WorkerConstants, type WorkerMessage, WorkerMessageEvents } from '../worker'; // Conditionally export ThreadWorker instance for pool usage export let threadWorker: ThreadWorker; diff --git a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts index ef232641..6ffa0f14 100644 --- a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts @@ -1,52 +1,45 @@ -import type ChargingStation from './ChargingStation'; +import type { ChargingStation } from './ChargingStation'; import { ChargingStationConfigurationUtils } from './ChargingStationConfigurationUtils'; import { OCPP16ServiceUtils } from './ocpp/1.6/OCPP16ServiceUtils'; -import WorkerBroadcastChannel from './WorkerBroadcastChannel'; -import BaseError from '../exception/BaseError'; -import type OCPPError from '../exception/OCPPError'; -import { StandardParametersKey } from '../types/ocpp/Configuration'; +import { WorkerBroadcastChannel } from './WorkerBroadcastChannel'; +import { BaseError, type OCPPError } from '../exception'; import { + AuthorizationStatus, + type AuthorizeRequest, + type AuthorizeResponse, type BootNotificationRequest, - type DataTransferRequest, - type DiagnosticsStatusNotificationRequest, - type FirmwareStatusNotificationRequest, - type HeartbeatRequest, - type MeterValuesRequest, - RequestCommand, - type RequestParams, - type StatusNotificationRequest, -} from '../types/ocpp/Requests'; -import { type BootNotificationResponse, + BroadcastChannelProcedureName, + type BroadcastChannelRequest, + type BroadcastChannelRequestPayload, + type BroadcastChannelResponsePayload, + type DataTransferRequest, type DataTransferResponse, DataTransferStatus, + type DiagnosticsStatusNotificationRequest, type DiagnosticsStatusNotificationResponse, + type FirmwareStatusNotificationRequest, type FirmwareStatusNotificationResponse, + type HeartbeatRequest, type HeartbeatResponse, + type MessageEvent, + type MeterValuesRequest, type MeterValuesResponse, RegistrationStatusEnumType, - type StatusNotificationResponse, -} from '../types/ocpp/Responses'; -import { - AuthorizationStatus, - type AuthorizeRequest, - type AuthorizeResponse, + RequestCommand, + type RequestParams, + ResponseStatus, + StandardParametersKey, type StartTransactionRequest, type StartTransactionResponse, + type StatusNotificationRequest, + type StatusNotificationResponse, type StopTransactionRequest, type StopTransactionResponse, -} from '../types/ocpp/Transaction'; -import { ResponseStatus } from '../types/UIProtocol'; -import { - BroadcastChannelProcedureName, - type BroadcastChannelRequest, - type BroadcastChannelRequestPayload, - type BroadcastChannelResponsePayload, - type MessageEvent, -} from '../types/WorkerBroadcastChannel'; -import Constants from '../utils/Constants'; -import logger from '../utils/Logger'; -import Utils from '../utils/Utils'; +} from '../types'; +import { Constants } from '../utils/Constants'; +import { logger } from '../utils/Logger'; +import { Utils } from '../utils/Utils'; const moduleName = 'ChargingStationWorkerBroadcastChannel'; @@ -66,7 +59,7 @@ type CommandHandler = ( requestPayload?: BroadcastChannelRequestPayload ) => Promise | void; -export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChannel { +export class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChannel { private readonly commandHandlers: Map; private readonly chargingStation: ChargingStation; diff --git a/src/charging-station/MessageChannelUtils.ts b/src/charging-station/MessageChannelUtils.ts index 40496b60..d8f1aa10 100644 --- a/src/charging-station/MessageChannelUtils.ts +++ b/src/charging-station/MessageChannelUtils.ts @@ -1,10 +1,10 @@ -import type ChargingStation from './ChargingStation'; +import type { ChargingStation } from './ChargingStation'; import { type ChargingStationData, type ChargingStationWorkerMessage, ChargingStationWorkerMessageEvents, -} from '../types/ChargingStationWorker'; -import type { Statistics } from '../types/Statistics'; + type Statistics, +} from '../types'; export class MessageChannelUtils { private constructor() { diff --git a/src/charging-station/SharedLRUCache.ts b/src/charging-station/SharedLRUCache.ts index 3e2e0de0..64ee0146 100644 --- a/src/charging-station/SharedLRUCache.ts +++ b/src/charging-station/SharedLRUCache.ts @@ -1,9 +1,8 @@ import LRUCache from 'mnemonist/lru-map-with-delete'; import { Bootstrap } from '../internal'; -import type { ChargingStationConfiguration } from '../types/ChargingStationConfiguration'; -import type { ChargingStationTemplate } from '../types/ChargingStationTemplate'; -import Utils from '../utils/Utils'; +import type { ChargingStationConfiguration, ChargingStationTemplate } from '../types'; +import { Utils } from '../utils/Utils'; enum CacheType { CHARGING_STATION_TEMPLATE = 'chargingStationTemplate', @@ -12,7 +11,7 @@ enum CacheType { type CacheableType = ChargingStationTemplate | ChargingStationConfiguration; -export default class SharedLRUCache { +export class SharedLRUCache { private static instance: SharedLRUCache | null = null; private readonly lruCache: LRUCache; diff --git a/src/charging-station/UIServiceWorkerBroadcastChannel.ts b/src/charging-station/UIServiceWorkerBroadcastChannel.ts index 0e84b3a1..77ae46f2 100644 --- a/src/charging-station/UIServiceWorkerBroadcastChannel.ts +++ b/src/charging-station/UIServiceWorkerBroadcastChannel.ts @@ -1,12 +1,13 @@ -import type AbstractUIService from './ui-server/ui-services/AbstractUIService'; -import WorkerBroadcastChannel from './WorkerBroadcastChannel'; -import { type ResponsePayload, ResponseStatus } from '../types/UIProtocol'; -import type { - BroadcastChannelResponse, - BroadcastChannelResponsePayload, - MessageEvent, -} from '../types/WorkerBroadcastChannel'; -import logger from '../utils/Logger'; +import type { AbstractUIService } from './ui-server/ui-services/AbstractUIService'; +import { WorkerBroadcastChannel } from './WorkerBroadcastChannel'; +import { + type BroadcastChannelResponse, + type BroadcastChannelResponsePayload, + type MessageEvent, + type ResponsePayload, + ResponseStatus, +} from '../types'; +import { logger } from '../utils/Logger'; const moduleName = 'UIServiceWorkerBroadcastChannel'; @@ -16,7 +17,7 @@ type Responses = { responses: BroadcastChannelResponsePayload[]; }; -export default class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChannel { +export class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChannel { private readonly uiService: AbstractUIService; private readonly responses: Map; diff --git a/src/charging-station/WorkerBroadcastChannel.ts b/src/charging-station/WorkerBroadcastChannel.ts index 37987437..dd14d781 100644 --- a/src/charging-station/WorkerBroadcastChannel.ts +++ b/src/charging-station/WorkerBroadcastChannel.ts @@ -1,17 +1,17 @@ import { BroadcastChannel } from 'worker_threads'; -import type { JsonType } from '../types/JsonType'; import type { BroadcastChannelRequest, BroadcastChannelResponse, + JsonType, MessageEvent, -} from '../types/WorkerBroadcastChannel'; -import logger from '../utils/Logger'; -import Utils from '../utils/Utils'; +} from '../types'; +import { logger } from '../utils/Logger'; +import { Utils } from '../utils/Utils'; const moduleName = 'WorkerBroadcastChannel'; -export default abstract class WorkerBroadcastChannel extends BroadcastChannel { +export abstract class WorkerBroadcastChannel extends BroadcastChannel { protected constructor() { super('worker'); } diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index b1df54b7..e6b8cc97 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -9,89 +9,82 @@ import { Client, type FTPResponse } from 'basic-ftp'; import tar from 'tar'; import { OCPP16ServiceUtils } from './OCPP16ServiceUtils'; -import OCPPError from '../../../exception/OCPPError'; -import type { JsonObject, JsonType } from '../../../types/JsonType'; -import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode'; -import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus'; -import { - ChargingProfilePurposeType, - type OCPP16ChargingProfile, -} from '../../../types/ocpp/1.6/ChargingProfile'; -import { - OCPP16StandardParametersKey, - OCPP16SupportedFeatureProfiles, -} from '../../../types/ocpp/1.6/Configuration'; -import { OCPP16DiagnosticsStatus } from '../../../types/ocpp/1.6/DiagnosticsStatus'; +import { OCPPError } from '../../../exception'; import { type ChangeAvailabilityRequest, + type ChangeAvailabilityResponse, type ChangeConfigurationRequest, + type ChangeConfigurationResponse, + ChargingProfilePurposeType, type ClearChargingProfileRequest, + type ClearChargingProfileResponse, + ErrorType, + type GenericResponse, type GetConfigurationRequest, + type GetConfigurationResponse, type GetDiagnosticsRequest, + type GetDiagnosticsResponse, + type IncomingRequestHandler, + type JsonObject, + type JsonType, + OCPP16AuthorizationStatus, + type OCPP16AuthorizeRequest, + type OCPP16AuthorizeResponse, OCPP16AvailabilityType, type OCPP16BootNotificationRequest, + type OCPP16BootNotificationResponse, + OCPP16ChargePointErrorCode, + OCPP16ChargePointStatus, + type OCPP16ChargingProfile, type OCPP16ClearCacheRequest, type OCPP16DataTransferRequest, + type OCPP16DataTransferResponse, + OCPP16DataTransferStatus, OCPP16DataTransferVendorId, + OCPP16DiagnosticsStatus, type OCPP16DiagnosticsStatusNotificationRequest, + type OCPP16DiagnosticsStatusNotificationResponse, OCPP16FirmwareStatus, type OCPP16FirmwareStatusNotificationRequest, + type OCPP16FirmwareStatusNotificationResponse, type OCPP16HeartbeatRequest, + type OCPP16HeartbeatResponse, OCPP16IncomingRequestCommand, OCPP16MessageTrigger, OCPP16RequestCommand, + OCPP16StandardParametersKey, + type OCPP16StartTransactionRequest, + type OCPP16StartTransactionResponse, type OCPP16StatusNotificationRequest, + type OCPP16StatusNotificationResponse, + OCPP16StopTransactionReason, + OCPP16SupportedFeatureProfiles, type OCPP16TriggerMessageRequest, + type OCPP16TriggerMessageResponse, type OCPP16UpdateFirmwareRequest, + type OCPP16UpdateFirmwareResponse, + type OCPPConfigurationKey, + OCPPVersion, type RemoteStartTransactionRequest, type RemoteStopTransactionRequest, type ResetRequest, type SetChargingProfileRequest, - type UnlockConnectorRequest, -} from '../../../types/ocpp/1.6/Requests'; -import { - type ChangeAvailabilityResponse, - type ChangeConfigurationResponse, - type ClearChargingProfileResponse, - type GetConfigurationResponse, - type GetDiagnosticsResponse, - type OCPP16BootNotificationResponse, - type OCPP16DataTransferResponse, - OCPP16DataTransferStatus, - type OCPP16DiagnosticsStatusNotificationResponse, - type OCPP16FirmwareStatusNotificationResponse, - type OCPP16HeartbeatResponse, - type OCPP16StatusNotificationResponse, - type OCPP16TriggerMessageResponse, - type OCPP16UpdateFirmwareResponse, type SetChargingProfileResponse, + type UnlockConnectorRequest, type UnlockConnectorResponse, -} from '../../../types/ocpp/1.6/Responses'; -import { - OCPP16AuthorizationStatus, - type OCPP16AuthorizeRequest, - type OCPP16AuthorizeResponse, - type OCPP16StartTransactionRequest, - type OCPP16StartTransactionResponse, - OCPP16StopTransactionReason, -} from '../../../types/ocpp/1.6/Transaction'; -import type { OCPPConfigurationKey } from '../../../types/ocpp/Configuration'; -import { ErrorType } from '../../../types/ocpp/ErrorType'; -import { OCPPVersion } from '../../../types/ocpp/OCPPVersion'; -import type { IncomingRequestHandler } from '../../../types/ocpp/Requests'; -import type { GenericResponse } from '../../../types/ocpp/Responses'; -import Constants from '../../../utils/Constants'; -import logger from '../../../utils/Logger'; -import Utils from '../../../utils/Utils'; -import type ChargingStation from '../../ChargingStation'; +} from '../../../types'; +import { Constants } from '../../../utils/Constants'; +import { logger } from '../../../utils/Logger'; +import { Utils } from '../../../utils/Utils'; +import type { ChargingStation } from '../../ChargingStation'; import { ChargingStationConfigurationUtils } from '../../ChargingStationConfigurationUtils'; import { ChargingStationUtils } from '../../ChargingStationUtils'; -import OCPPConstants from '../OCPPConstants'; -import OCPPIncomingRequestService from '../OCPPIncomingRequestService'; +import { OCPPConstants } from '../OCPPConstants'; +import { OCPPIncomingRequestService } from '../OCPPIncomingRequestService'; const moduleName = 'OCPP16IncomingRequestService'; -export default class OCPP16IncomingRequestService extends OCPPIncomingRequestService { +export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { protected jsonSchemas: Map>; private incomingRequestHandlers: Map; diff --git a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts index 98cf5317..efbd603c 100644 --- a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts @@ -3,36 +3,35 @@ import type { JSONSchemaType } from 'ajv'; import { OCPP16ServiceUtils } from './OCPP16ServiceUtils'; -import OCPPError from '../../../exception/OCPPError'; -import type { JsonObject, JsonType } from '../../../types/JsonType'; -import type { OCPP16MeterValuesRequest } from '../../../types/ocpp/1.6/MeterValues'; +import { OCPPError } from '../../../exception'; import { + ErrorType, + type JsonObject, + type JsonType, + type OCPP16AuthorizeRequest, type OCPP16BootNotificationRequest, type OCPP16DataTransferRequest, type OCPP16DiagnosticsStatusNotificationRequest, type OCPP16FirmwareStatusNotificationRequest, type OCPP16HeartbeatRequest, + type OCPP16MeterValuesRequest, OCPP16RequestCommand, + type OCPP16StartTransactionRequest, type OCPP16StatusNotificationRequest, -} from '../../../types/ocpp/1.6/Requests'; -import type { - OCPP16AuthorizeRequest, - OCPP16StartTransactionRequest, - OCPP16StopTransactionRequest, -} from '../../../types/ocpp/1.6/Transaction'; -import { ErrorType } from '../../../types/ocpp/ErrorType'; -import { OCPPVersion } from '../../../types/ocpp/OCPPVersion'; -import type { RequestParams } from '../../../types/ocpp/Requests'; -import Constants from '../../../utils/Constants'; -import Utils from '../../../utils/Utils'; -import type ChargingStation from '../../ChargingStation'; -import OCPPConstants from '../OCPPConstants'; -import OCPPRequestService from '../OCPPRequestService'; -import type OCPPResponseService from '../OCPPResponseService'; + type OCPP16StopTransactionRequest, + OCPPVersion, + type RequestParams, +} from '../../../types'; +import { Constants } from '../../../utils/Constants'; +import { Utils } from '../../../utils/Utils'; +import type { ChargingStation } from '../../ChargingStation'; +import { OCPPConstants } from '../OCPPConstants'; +import { OCPPRequestService } from '../OCPPRequestService'; +import type { OCPPResponseService } from '../OCPPResponseService'; const moduleName = 'OCPP16RequestService'; -export default class OCPP16RequestService extends OCPPRequestService { +export class OCPP16RequestService extends OCPPRequestService { protected jsonSchemas: Map>; public constructor(ocppResponseService: OCPPResponseService) { diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index 5433adec..958f1a5d 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -3,64 +3,57 @@ import type { JSONSchemaType } from 'ajv'; import { OCPP16ServiceUtils } from './OCPP16ServiceUtils'; -import OCPPError from '../../../exception/OCPPError'; -import type { JsonObject, JsonType } from '../../../types/JsonType'; -import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode'; -import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus'; -import { OCPP16StandardParametersKey } from '../../../types/ocpp/1.6/Configuration'; -import type { - OCPP16MeterValuesRequest, - OCPP16MeterValuesResponse, -} from '../../../types/ocpp/1.6/MeterValues'; -import { - type OCPP16BootNotificationRequest, - OCPP16IncomingRequestCommand, - OCPP16RequestCommand, - type OCPP16StatusNotificationRequest, -} from '../../../types/ocpp/1.6/Requests'; -import type { - ChangeAvailabilityResponse, - ChangeConfigurationResponse, - ClearChargingProfileResponse, - GetConfigurationResponse, - GetDiagnosticsResponse, - OCPP16BootNotificationResponse, - OCPP16DataTransferResponse, - OCPP16DiagnosticsStatusNotificationResponse, - OCPP16FirmwareStatusNotificationResponse, - OCPP16HeartbeatResponse, - OCPP16StatusNotificationResponse, - OCPP16TriggerMessageResponse, - OCPP16UpdateFirmwareResponse, - SetChargingProfileResponse, - UnlockConnectorResponse, -} from '../../../types/ocpp/1.6/Responses'; +import { OCPPError } from '../../../exception'; import { + type ChangeAvailabilityResponse, + type ChangeConfigurationResponse, + type ClearChargingProfileResponse, + ErrorType, + type GenericResponse, + type GetConfigurationResponse, + type GetDiagnosticsResponse, + type JsonObject, + type JsonType, OCPP16AuthorizationStatus, type OCPP16AuthorizeRequest, type OCPP16AuthorizeResponse, + type OCPP16BootNotificationRequest, + type OCPP16BootNotificationResponse, + OCPP16ChargePointErrorCode, + OCPP16ChargePointStatus, + type OCPP16DataTransferResponse, + type OCPP16DiagnosticsStatusNotificationResponse, + type OCPP16FirmwareStatusNotificationResponse, + type OCPP16HeartbeatResponse, + OCPP16IncomingRequestCommand, + type OCPP16MeterValuesRequest, + type OCPP16MeterValuesResponse, + OCPP16RequestCommand, + OCPP16StandardParametersKey, type OCPP16StartTransactionRequest, type OCPP16StartTransactionResponse, + type OCPP16StatusNotificationRequest, + type OCPP16StatusNotificationResponse, type OCPP16StopTransactionRequest, type OCPP16StopTransactionResponse, -} from '../../../types/ocpp/1.6/Transaction'; -import { ErrorType } from '../../../types/ocpp/ErrorType'; -import { OCPPVersion } from '../../../types/ocpp/OCPPVersion'; -import { - type GenericResponse, + type OCPP16TriggerMessageResponse, + type OCPP16UpdateFirmwareResponse, + OCPPVersion, RegistrationStatusEnumType, type ResponseHandler, -} from '../../../types/ocpp/Responses'; -import Constants from '../../../utils/Constants'; -import logger from '../../../utils/Logger'; -import Utils from '../../../utils/Utils'; -import type ChargingStation from '../../ChargingStation'; + type SetChargingProfileResponse, + type UnlockConnectorResponse, +} from '../../../types'; +import { Constants } from '../../../utils/Constants'; +import { logger } from '../../../utils/Logger'; +import { Utils } from '../../../utils/Utils'; +import type { ChargingStation } from '../../ChargingStation'; import { ChargingStationConfigurationUtils } from '../../ChargingStationConfigurationUtils'; -import OCPPResponseService from '../OCPPResponseService'; +import { OCPPResponseService } from '../OCPPResponseService'; const moduleName = 'OCPP16ResponseService'; -export default class OCPP16ResponseService extends OCPPResponseService { +export class OCPP16ResponseService extends OCPPResponseService { public jsonIncomingRequestResponseSchemas: Map< OCPP16IncomingRequestCommand, JSONSchemaType diff --git a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts index eceb2148..528a8aa7 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -5,39 +5,34 @@ import { fileURLToPath } from 'node:url'; import type { JSONSchemaType } from 'ajv'; -import OCPPError from '../../../exception/OCPPError'; -import { CurrentType, Voltage } from '../../../types/ChargingStationTemplate'; -import type { JsonType } from '../../../types/JsonType'; -import type { - MeasurandPerPhaseSampledValueTemplates, - SampledValueTemplate, -} from '../../../types/MeasurandPerPhaseSampledValueTemplates'; -import type { MeasurandValues } from '../../../types/MeasurandValues'; -import type { OCPP16ChargingProfile } from '../../../types/ocpp/1.6/ChargingProfile'; -import { - OCPP16StandardParametersKey, - OCPP16SupportedFeatureProfiles, -} from '../../../types/ocpp/1.6/Configuration'; +import { OCPPError } from '../../../exception'; import { + CurrentType, + ErrorType, + type JsonType, + type MeasurandPerPhaseSampledValueTemplates, + type MeasurandValues, MeterValueContext, MeterValueLocation, MeterValueUnit, + type OCPP16ChargingProfile, + type OCPP16IncomingRequestCommand, type OCPP16MeterValue, OCPP16MeterValueMeasurand, OCPP16MeterValuePhase, - type OCPP16SampledValue, -} from '../../../types/ocpp/1.6/MeterValues'; -import { - type OCPP16IncomingRequestCommand, OCPP16RequestCommand, -} from '../../../types/ocpp/1.6/Requests'; -import { ErrorType } from '../../../types/ocpp/ErrorType'; -import { OCPPVersion } from '../../../types/ocpp/OCPPVersion'; -import Constants from '../../../utils/Constants'; + type OCPP16SampledValue, + OCPP16StandardParametersKey, + type OCPP16SupportedFeatureProfiles, + OCPPVersion, + type SampledValueTemplate, + Voltage, +} from '../../../types'; +import { Constants } from '../../../utils/Constants'; import { ACElectricUtils, DCElectricUtils } from '../../../utils/ElectricUtils'; -import logger from '../../../utils/Logger'; -import Utils from '../../../utils/Utils'; -import type ChargingStation from '../../ChargingStation'; +import { logger } from '../../../utils/Logger'; +import { Utils } from '../../../utils/Utils'; +import type { ChargingStation } from '../../ChargingStation'; import { OCPPServiceUtils } from '../OCPPServiceUtils'; export class OCPP16ServiceUtils extends OCPPServiceUtils { diff --git a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts index 182f58d7..95169e2b 100644 --- a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts @@ -3,22 +3,23 @@ import type { JSONSchemaType } from 'ajv'; import { OCPP20ServiceUtils } from './OCPP20ServiceUtils'; -import OCPPError from '../../../exception/OCPPError'; -import type { JsonObject, JsonType } from '../../../types/JsonType'; +import { OCPPError } from '../../../exception'; import { + ErrorType, + type IncomingRequestHandler, + type JsonObject, + type JsonType, type OCPP20ClearCacheRequest, OCPP20IncomingRequestCommand, -} from '../../../types/ocpp/2.0/Requests'; -import { ErrorType } from '../../../types/ocpp/ErrorType'; -import { OCPPVersion } from '../../../types/ocpp/OCPPVersion'; -import type { IncomingRequestHandler } from '../../../types/ocpp/Requests'; -import logger from '../../../utils/Logger'; -import type ChargingStation from '../../ChargingStation'; -import OCPPIncomingRequestService from '../OCPPIncomingRequestService'; + OCPPVersion, +} from '../../../types'; +import { logger } from '../../../utils/Logger'; +import type { ChargingStation } from '../../ChargingStation'; +import { OCPPIncomingRequestService } from '../OCPPIncomingRequestService'; const moduleName = 'OCPP20IncomingRequestService'; -export default class OCPP20IncomingRequestService extends OCPPIncomingRequestService { +export class OCPP20IncomingRequestService extends OCPPIncomingRequestService { protected jsonSchemas: Map>; private incomingRequestHandlers: Map; diff --git a/src/charging-station/ocpp/2.0/OCPP20RequestService.ts b/src/charging-station/ocpp/2.0/OCPP20RequestService.ts index b9813d59..bf8119c5 100644 --- a/src/charging-station/ocpp/2.0/OCPP20RequestService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20RequestService.ts @@ -3,26 +3,27 @@ import type { JSONSchemaType } from 'ajv'; import { OCPP20ServiceUtils } from './OCPP20ServiceUtils'; -import OCPPError from '../../../exception/OCPPError'; -import type { JsonObject, JsonType } from '../../../types/JsonType'; +import { OCPPError } from '../../../exception'; import { + ErrorType, + type JsonObject, + type JsonType, type OCPP20BootNotificationRequest, type OCPP20HeartbeatRequest, OCPP20RequestCommand, type OCPP20StatusNotificationRequest, -} from '../../../types/ocpp/2.0/Requests'; -import { ErrorType } from '../../../types/ocpp/ErrorType'; -import { OCPPVersion } from '../../../types/ocpp/OCPPVersion'; -import type { RequestParams } from '../../../types/ocpp/Requests'; -import Utils from '../../../utils/Utils'; -import type ChargingStation from '../../ChargingStation'; -import OCPPConstants from '../OCPPConstants'; -import OCPPRequestService from '../OCPPRequestService'; -import type OCPPResponseService from '../OCPPResponseService'; + OCPPVersion, + type RequestParams, +} from '../../../types'; +import { Utils } from '../../../utils/Utils'; +import type { ChargingStation } from '../../ChargingStation'; +import { OCPPConstants } from '../OCPPConstants'; +import { OCPPRequestService } from '../OCPPRequestService'; +import type { OCPPResponseService } from '../OCPPResponseService'; const moduleName = 'OCPP20RequestService'; -export default class OCPP20RequestService extends OCPPRequestService { +export class OCPP20RequestService extends OCPPRequestService { protected jsonSchemas: Map>; public constructor(ocppResponseService: OCPPResponseService) { diff --git a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts index ee4c1606..5561b82b 100644 --- a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts @@ -3,28 +3,30 @@ import type { JSONSchemaType } from 'ajv'; import { OCPP20ServiceUtils } from './OCPP20ServiceUtils'; -import OCPPError from '../../../exception/OCPPError'; -import type { JsonObject, JsonType } from '../../../types/JsonType'; +import { OCPPError } from '../../../exception'; import { + ErrorType, + type JsonObject, + type JsonType, + OCPP16StandardParametersKey, + type OCPP20BootNotificationResponse, + type OCPP20ClearCacheResponse, + type OCPP20HeartbeatResponse, OCPP20IncomingRequestCommand, OCPP20RequestCommand, -} from '../../../types/ocpp/2.0/Requests'; -import type { - OCPP20BootNotificationResponse, - OCPP20ClearCacheResponse, - OCPP20HeartbeatResponse, - OCPP20StatusNotificationResponse, -} from '../../../types/ocpp/2.0/Responses'; -import { ErrorType } from '../../../types/ocpp/ErrorType'; -import { OCPPVersion } from '../../../types/ocpp/OCPPVersion'; -import { RegistrationStatusEnumType, ResponseHandler } from '../../../types/ocpp/Responses'; -import logger from '../../../utils/Logger'; -import type ChargingStation from '../../ChargingStation'; -import OCPPResponseService from '../OCPPResponseService'; + type OCPP20StatusNotificationResponse, + OCPPVersion, + RegistrationStatusEnumType, + type ResponseHandler, +} from '../../../types'; +import { logger } from '../../../utils/Logger'; +import type { ChargingStation } from '../../ChargingStation'; +import { ChargingStationConfigurationUtils } from '../../ChargingStationConfigurationUtils'; +import { OCPPResponseService } from '../OCPPResponseService'; const moduleName = 'OCPP20ResponseService'; -export default class OCPP20ResponseService extends OCPPResponseService { +export class OCPP20ResponseService extends OCPPResponseService { public jsonIncomingRequestResponseSchemas: Map< OCPP20IncomingRequestCommand, JSONSchemaType @@ -157,20 +159,20 @@ export default class OCPP20ResponseService extends OCPPResponseService { payload: OCPP20BootNotificationResponse ): void { if (payload.status === RegistrationStatusEnumType.ACCEPTED) { - // ChargingStationConfigurationUtils.addConfigurationKey( - // chargingStation, - // OCPP16StandardParametersKey.HeartbeatInterval, - // payload.interval.toString(), - // {}, - // { overwrite: true, save: true } - // ); - // ChargingStationConfigurationUtils.addConfigurationKey( - // chargingStation, - // OCPP16StandardParametersKey.HeartBeatInterval, - // payload.interval.toString(), - // { visible: false }, - // { overwrite: true, save: true } - // ); + ChargingStationConfigurationUtils.addConfigurationKey( + chargingStation, + OCPP16StandardParametersKey.HeartbeatInterval, + payload.interval.toString(), + {}, + { overwrite: true, save: true } + ); + ChargingStationConfigurationUtils.addConfigurationKey( + chargingStation, + OCPP16StandardParametersKey.HeartBeatInterval, + payload.interval.toString(), + { visible: false }, + { overwrite: true, save: true } + ); chargingStation.heartbeatSetInterval ? chargingStation.restartHeartbeat() : chargingStation.startHeartbeat(); diff --git a/src/charging-station/ocpp/2.0/OCPP20ServiceUtils.ts b/src/charging-station/ocpp/2.0/OCPP20ServiceUtils.ts index b155f462..38b80968 100644 --- a/src/charging-station/ocpp/2.0/OCPP20ServiceUtils.ts +++ b/src/charging-station/ocpp/2.0/OCPP20ServiceUtils.ts @@ -5,8 +5,7 @@ import { fileURLToPath } from 'node:url'; import type { JSONSchemaType } from 'ajv'; -import type { JsonType } from '../../../types/JsonType'; -import { OCPPVersion } from '../../../types/ocpp/OCPPVersion'; +import { type JsonType, OCPPVersion } from '../../../types'; import { OCPPServiceUtils } from '../OCPPServiceUtils'; export class OCPP20ServiceUtils extends OCPPServiceUtils { diff --git a/src/charging-station/ocpp/OCPPConstants.ts b/src/charging-station/ocpp/OCPPConstants.ts index a0b0d70a..f6b9af80 100644 --- a/src/charging-station/ocpp/OCPPConstants.ts +++ b/src/charging-station/ocpp/OCPPConstants.ts @@ -7,9 +7,9 @@ import { GenericStatus, TriggerMessageStatus, UnlockStatus, -} from '../../types/ocpp/Responses'; +} from '../../types'; -export default class OCPPConstants { +export class OCPPConstants { static readonly OCPP_REQUEST_EMPTY = Object.freeze({}); static readonly OCPP_RESPONSE_EMPTY = Object.freeze({}); static readonly OCPP_RESPONSE_ACCEPTED = Object.freeze({ status: GenericStatus.ACCEPTED }); diff --git a/src/charging-station/ocpp/OCPPIncomingRequestService.ts b/src/charging-station/ocpp/OCPPIncomingRequestService.ts index 41c0e49b..00059f4b 100644 --- a/src/charging-station/ocpp/OCPPIncomingRequestService.ts +++ b/src/charging-station/ocpp/OCPPIncomingRequestService.ts @@ -3,21 +3,24 @@ import { AsyncResource } from 'async_hooks'; import Ajv, { type JSONSchemaType } from 'ajv'; import ajvFormats from 'ajv-formats'; -import OCPPConstants from './OCPPConstants'; +import { OCPPConstants } from './OCPPConstants'; import { OCPPServiceUtils } from './OCPPServiceUtils'; -import OCPPError from '../../exception/OCPPError'; -import type { HandleErrorParams } from '../../types/Error'; -import type { JsonObject, JsonType } from '../../types/JsonType'; -import type { OCPPVersion } from '../../types/ocpp/OCPPVersion'; -import type { IncomingRequestCommand } from '../../types/ocpp/Requests'; -import type { ClearCacheResponse } from '../../types/ocpp/Responses'; -import logger from '../../utils/Logger'; -import type ChargingStation from '../ChargingStation'; +import { OCPPError } from '../../exception'; +import type { + ClearCacheResponse, + HandleErrorParams, + IncomingRequestCommand, + JsonObject, + JsonType, + OCPPVersion, +} from '../../types'; +import { logger } from '../../utils/Logger'; +import type { ChargingStation } from '../ChargingStation'; import { ChargingStationUtils } from '../ChargingStationUtils'; const moduleName = 'OCPPIncomingRequestService'; -export default abstract class OCPPIncomingRequestService extends AsyncResource { +export abstract class OCPPIncomingRequestService extends AsyncResource { private static instance: OCPPIncomingRequestService | null = null; private readonly version: OCPPVersion; private readonly ajv: Ajv; diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 6a772995..fc729113 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -1,34 +1,36 @@ import Ajv, { type JSONSchemaType } from 'ajv'; import ajvFormats from 'ajv-formats'; -import type OCPPResponseService from './OCPPResponseService'; +import type { OCPPResponseService } from './OCPPResponseService'; import { OCPPServiceUtils } from './OCPPServiceUtils'; -import OCPPError from '../../exception/OCPPError'; -import PerformanceStatistics from '../../performance/PerformanceStatistics'; -import type { EmptyObject } from '../../types/EmptyObject'; -import type { HandleErrorParams } from '../../types/Error'; -import type { JsonObject, JsonType } from '../../types/JsonType'; -import { ErrorType } from '../../types/ocpp/ErrorType'; -import { MessageType } from '../../types/ocpp/MessageType'; -import type { OCPPVersion } from '../../types/ocpp/OCPPVersion'; +import { OCPPError } from '../../exception'; +import { PerformanceStatistics } from '../../performance/PerformanceStatistics'; import { + type EmptyObject, type ErrorCallback, + type ErrorResponse, + ErrorType, + type HandleErrorParams, type IncomingRequestCommand, + type JsonObject, + type JsonType, + MessageType, + type OCPPVersion, type OutgoingRequest, RequestCommand, type RequestParams, + type Response, type ResponseCallback, type ResponseType, -} from '../../types/ocpp/Requests'; -import type { ErrorResponse, Response } from '../../types/ocpp/Responses'; -import Constants from '../../utils/Constants'; -import logger from '../../utils/Logger'; -import Utils from '../../utils/Utils'; -import type ChargingStation from '../ChargingStation'; +} from '../../types'; +import { Constants } from '../../utils/Constants'; +import { logger } from '../../utils/Logger'; +import { Utils } from '../../utils/Utils'; +import type { ChargingStation } from '../ChargingStation'; const moduleName = 'OCPPRequestService'; -export default abstract class OCPPRequestService { +export abstract class OCPPRequestService { private static instance: OCPPRequestService | null = null; private readonly version: OCPPVersion; private readonly ajv: Ajv; diff --git a/src/charging-station/ocpp/OCPPResponseService.ts b/src/charging-station/ocpp/OCPPResponseService.ts index 80d5a686..ab17b05a 100644 --- a/src/charging-station/ocpp/OCPPResponseService.ts +++ b/src/charging-station/ocpp/OCPPResponseService.ts @@ -2,16 +2,20 @@ import Ajv, { type JSONSchemaType } from 'ajv'; import ajvFormats from 'ajv-formats'; import { OCPPServiceUtils } from './OCPPServiceUtils'; -import OCPPError from '../../exception/OCPPError'; -import type { JsonObject, JsonType } from '../../types/JsonType'; -import type { OCPPVersion } from '../../types/ocpp/OCPPVersion'; -import type { IncomingRequestCommand, RequestCommand } from '../../types/ocpp/Requests'; -import logger from '../../utils/Logger'; -import type ChargingStation from '../ChargingStation'; +import { OCPPError } from '../../exception'; +import type { + IncomingRequestCommand, + JsonObject, + JsonType, + OCPPVersion, + RequestCommand, +} from '../../types'; +import { logger } from '../../utils/Logger'; +import type { ChargingStation } from '../ChargingStation'; const moduleName = 'OCPPResponseService'; -export default abstract class OCPPResponseService { +export abstract class OCPPResponseService { private static instance: OCPPResponseService | null = null; private readonly version: OCPPVersion; private readonly ajv: Ajv; diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts index 3fced606..4b232033 100644 --- a/src/charging-station/ocpp/OCPPServiceUtils.ts +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -2,30 +2,32 @@ import fs from 'node:fs'; import type { DefinedError, ErrorObject, JSONSchemaType } from 'ajv'; -import BaseError from '../../exception/BaseError'; -import { FileType } from '../../types/FileType'; -import type { JsonObject, JsonType } from '../../types/JsonType'; -import type { SampledValueTemplate } from '../../types/MeasurandPerPhaseSampledValueTemplates'; -import type { OCPP16StatusNotificationRequest } from '../../types/ocpp/1.6/Requests'; -import type { OCPP20StatusNotificationRequest } from '../../types/ocpp/2.0/Requests'; -import { ChargePointErrorCode } from '../../types/ocpp/ChargePointErrorCode'; -import { StandardParametersKey } from '../../types/ocpp/Configuration'; -import type { ConnectorStatusEnum } from '../../types/ocpp/ConnectorStatusEnum'; -import { ErrorType } from '../../types/ocpp/ErrorType'; -import { MessageType } from '../../types/ocpp/MessageType'; -import { MeterValueMeasurand, type MeterValuePhase } from '../../types/ocpp/MeterValues'; -import { OCPPVersion } from '../../types/ocpp/OCPPVersion'; +import { BaseError } from '../../exception'; import { + ChargePointErrorCode, + type ConnectorStatusEnum, + ErrorType, + FileType, IncomingRequestCommand, + type JsonObject, + type JsonType, MessageTrigger, + MessageType, + MeterValueMeasurand, + type MeterValuePhase, + type OCPP16StatusNotificationRequest, + type OCPP20StatusNotificationRequest, + OCPPVersion, RequestCommand, + type SampledValueTemplate, + StandardParametersKey, type StatusNotificationRequest, -} from '../../types/ocpp/Requests'; -import Constants from '../../utils/Constants'; -import FileUtils from '../../utils/FileUtils'; -import logger from '../../utils/Logger'; -import Utils from '../../utils/Utils'; -import type ChargingStation from '../ChargingStation'; +} from '../../types'; +import { Constants } from '../../utils/Constants'; +import { FileUtils } from '../../utils/FileUtils'; +import { logger } from '../../utils/Logger'; +import { Utils } from '../../utils/Utils'; +import type { ChargingStation } from '../ChargingStation'; import { ChargingStationConfigurationUtils } from '../ChargingStationConfigurationUtils'; export class OCPPServiceUtils { diff --git a/src/charging-station/ui-server/AbstractUIServer.ts b/src/charging-station/ui-server/AbstractUIServer.ts index f69b9b34..053b1bae 100644 --- a/src/charging-station/ui-server/AbstractUIServer.ts +++ b/src/charging-station/ui-server/AbstractUIServer.ts @@ -2,19 +2,19 @@ import { type IncomingMessage, Server, type ServerResponse } from 'http'; import type { WebSocket } from 'ws'; -import type AbstractUIService from './ui-services/AbstractUIService'; -import UIServiceFactory from './ui-services/UIServiceFactory'; -import type { ChargingStationData } from '../../types/ChargingStationWorker'; -import type { UIServerConfiguration } from '../../types/ConfigurationData'; +import type { AbstractUIService } from './ui-services/AbstractUIService'; +import { UIServiceFactory } from './ui-services/UIServiceFactory'; import { AuthenticationType, + type ChargingStationData, type ProcedureName, type ProtocolRequest, type ProtocolResponse, type ProtocolVersion, type RequestPayload, type ResponsePayload, -} from '../../types/UIProtocol'; + type UIServerConfiguration, +} from '../../types'; export abstract class AbstractUIServer { public readonly chargingStations: Map; diff --git a/src/charging-station/ui-server/UIHttpServer.ts b/src/charging-station/ui-server/UIHttpServer.ts index 48dfadbd..23527347 100644 --- a/src/charging-station/ui-server/UIHttpServer.ts +++ b/src/charging-station/ui-server/UIHttpServer.ts @@ -4,8 +4,7 @@ import { StatusCodes } from 'http-status-codes'; import { AbstractUIServer } from './AbstractUIServer'; import { UIServerUtils } from './UIServerUtils'; -import BaseError from '../../exception/BaseError'; -import type { UIServerConfiguration } from '../../types/ConfigurationData'; +import { BaseError } from '../../exception'; import { type ProcedureName, type Protocol, @@ -14,13 +13,14 @@ import { type ProtocolVersion, type RequestPayload, ResponseStatus, -} from '../../types/UIProtocol'; -import logger from '../../utils/Logger'; -import Utils from '../../utils/Utils'; + type UIServerConfiguration, +} from '../../types'; +import { logger } from '../../utils/Logger'; +import { Utils } from '../../utils/Utils'; const moduleName = 'UIHttpServer'; -export default class UIHttpServer extends AbstractUIServer { +export class UIHttpServer extends AbstractUIServer { public constructor(protected readonly uiServerConfiguration: UIServerConfiguration) { super(uiServerConfiguration); } diff --git a/src/charging-station/ui-server/UIServerFactory.ts b/src/charging-station/ui-server/UIServerFactory.ts index 9d2bc574..64d143d4 100644 --- a/src/charging-station/ui-server/UIServerFactory.ts +++ b/src/charging-station/ui-server/UIServerFactory.ts @@ -1,14 +1,13 @@ import chalk from 'chalk'; import type { AbstractUIServer } from './AbstractUIServer'; -import UIHttpServer from './UIHttpServer'; +import { UIHttpServer } from './UIHttpServer'; import { UIServerUtils } from './UIServerUtils'; -import UIWebSocketServer from './UIWebSocketServer'; -import type { UIServerConfiguration } from '../../types/ConfigurationData'; -import { ApplicationProtocol } from '../../types/UIProtocol'; -import Configuration from '../../utils/Configuration'; +import { UIWebSocketServer } from './UIWebSocketServer'; +import { ApplicationProtocol, type UIServerConfiguration } from '../../types'; +import { Configuration } from '../../utils/Configuration'; -export default class UIServerFactory { +export class UIServerFactory { private constructor() { // This is intentional } diff --git a/src/charging-station/ui-server/UIServerUtils.ts b/src/charging-station/ui-server/UIServerUtils.ts index fc37ddc6..78590e09 100644 --- a/src/charging-station/ui-server/UIServerUtils.ts +++ b/src/charging-station/ui-server/UIServerUtils.ts @@ -1,8 +1,8 @@ import type { IncomingMessage } from 'http'; -import { Protocol, ProtocolVersion } from '../../types/UIProtocol'; -import logger from '../../utils/Logger'; -import Utils from '../../utils/Utils'; +import { Protocol, ProtocolVersion } from '../../types'; +import { logger } from '../../utils/Logger'; +import { Utils } from '../../utils/Utils'; export class UIServerUtils { private constructor() { diff --git a/src/charging-station/ui-server/UIWebSocketServer.ts b/src/charging-station/ui-server/UIWebSocketServer.ts index 9e8ad84b..3e2dd813 100644 --- a/src/charging-station/ui-server/UIWebSocketServer.ts +++ b/src/charging-station/ui-server/UIWebSocketServer.ts @@ -6,15 +6,18 @@ import WebSocket, { type RawData, WebSocketServer } from 'ws'; import { AbstractUIServer } from './AbstractUIServer'; import { UIServerUtils } from './UIServerUtils'; -import type { UIServerConfiguration } from '../../types/ConfigurationData'; -import type { ProtocolRequest, ProtocolResponse } from '../../types/UIProtocol'; -import { WebSocketCloseEventStatusCode } from '../../types/WebSocket'; -import logger from '../../utils/Logger'; -import Utils from '../../utils/Utils'; +import { + type ProtocolRequest, + type ProtocolResponse, + type UIServerConfiguration, + WebSocketCloseEventStatusCode, +} from '../../types'; +import { logger } from '../../utils/Logger'; +import { Utils } from '../../utils/Utils'; const moduleName = 'UIWebSocketServer'; -export default class UIWebSocketServer extends AbstractUIServer { +export class UIWebSocketServer extends AbstractUIServer { private readonly webSocketServer: WebSocketServer; public constructor(protected readonly uiServerConfiguration: UIServerConfiguration) { diff --git a/src/charging-station/ui-server/ui-services/AbstractUIService.ts b/src/charging-station/ui-server/ui-services/AbstractUIService.ts index 62249549..49d10abf 100644 --- a/src/charging-station/ui-server/ui-services/AbstractUIService.ts +++ b/src/charging-station/ui-server/ui-services/AbstractUIService.ts @@ -1,7 +1,8 @@ -import BaseError from '../../../exception/BaseError'; -import type OCPPError from '../../../exception/OCPPError'; +import { BaseError, type OCPPError } from '../../../exception'; import { Bootstrap } from '../../../internal'; import { + BroadcastChannelProcedureName, + type BroadcastChannelRequestPayload, ProcedureName, type ProtocolRequest, type ProtocolRequestHandler, @@ -9,19 +10,15 @@ import { type RequestPayload, type ResponsePayload, ResponseStatus, -} from '../../../types/UIProtocol'; -import { - BroadcastChannelProcedureName, - type BroadcastChannelRequestPayload, -} from '../../../types/WorkerBroadcastChannel'; -import logger from '../../../utils/Logger'; -import Utils from '../../../utils/Utils'; -import UIServiceWorkerBroadcastChannel from '../../UIServiceWorkerBroadcastChannel'; +} from '../../../types'; +import { logger } from '../../../utils/Logger'; +import { Utils } from '../../../utils/Utils'; +import { UIServiceWorkerBroadcastChannel } from '../../UIServiceWorkerBroadcastChannel'; import type { AbstractUIServer } from '../AbstractUIServer'; const moduleName = 'AbstractUIService'; -export default abstract class AbstractUIService { +export abstract class AbstractUIService { protected static readonly ProcedureNameToBroadCastChannelProcedureNameMap: Omit< Record, | ProcedureName.START_SIMULATOR diff --git a/src/charging-station/ui-server/ui-services/UIService001.ts b/src/charging-station/ui-server/ui-services/UIService001.ts index 0ac0daa0..598ebb26 100644 --- a/src/charging-station/ui-server/ui-services/UIService001.ts +++ b/src/charging-station/ui-server/ui-services/UIService001.ts @@ -1,12 +1,8 @@ -import AbstractUIService from './AbstractUIService'; -import { - ProcedureName, - type ProtocolRequestHandler, - ProtocolVersion, -} from '../../../types/UIProtocol'; +import { AbstractUIService } from './AbstractUIService'; +import { type ProcedureName, type ProtocolRequestHandler, ProtocolVersion } from '../../../types'; import type { AbstractUIServer } from '../AbstractUIServer'; -export default class UIService001 extends AbstractUIService { +export class UIService001 extends AbstractUIService { constructor(uiServer: AbstractUIServer) { super(uiServer, ProtocolVersion['0.0.1']); for (const procedureName of Object.keys( diff --git a/src/charging-station/ui-server/ui-services/UIServiceFactory.ts b/src/charging-station/ui-server/ui-services/UIServiceFactory.ts index 9f2d448b..47a1893d 100644 --- a/src/charging-station/ui-server/ui-services/UIServiceFactory.ts +++ b/src/charging-station/ui-server/ui-services/UIServiceFactory.ts @@ -1,9 +1,9 @@ -import type AbstractUIService from './AbstractUIService'; -import UIService001 from './UIService001'; -import { ProtocolVersion } from '../../../types/UIProtocol'; +import type { AbstractUIService } from './AbstractUIService'; +import { UIService001 } from './UIService001'; +import { ProtocolVersion } from '../../../types'; import type { AbstractUIServer } from '../AbstractUIServer'; -export default class UIServiceFactory { +export class UIServiceFactory { private constructor() { // This is intentional } diff --git a/src/exception/BaseError.ts b/src/exception/BaseError.ts index 1471844c..84421eac 100644 --- a/src/exception/BaseError.ts +++ b/src/exception/BaseError.ts @@ -1,4 +1,4 @@ -export default class BaseError extends Error { +export class BaseError extends Error { public constructor(message?: string) { super(message); this.name = new.target.name; diff --git a/src/exception/OCPPError.ts b/src/exception/OCPPError.ts index 8e7dcc2f..8ccc4fbf 100644 --- a/src/exception/OCPPError.ts +++ b/src/exception/OCPPError.ts @@ -1,11 +1,14 @@ // Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. -import BaseError from './BaseError'; -import type { JsonType } from '../types/JsonType'; -import { ErrorType } from '../types/ocpp/ErrorType'; -import type { IncomingRequestCommand, RequestCommand } from '../types/ocpp/Requests'; +import { BaseError } from './BaseError'; +import { + ErrorType, + type IncomingRequestCommand, + type JsonType, + type RequestCommand, +} from '../types'; -export default class OCPPError extends BaseError { +export class OCPPError extends BaseError { code: ErrorType; command?: RequestCommand | IncomingRequestCommand; details?: JsonType; diff --git a/src/exception/index.ts b/src/exception/index.ts new file mode 100644 index 00000000..49abdfcb --- /dev/null +++ b/src/exception/index.ts @@ -0,0 +1,2 @@ +export * from './BaseError'; +export * from './OCPPError'; diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index aa0cc723..79650c8f 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -5,16 +5,20 @@ import { PerformanceEntry, PerformanceObserver, performance } from 'perf_hooks'; import { parentPort } from 'worker_threads'; import { MessageChannelUtils } from '../charging-station/MessageChannelUtils'; -import { MessageType } from '../types/ocpp/MessageType'; -import type { IncomingRequestCommand, RequestCommand } from '../types/ocpp/Requests'; -import type { Statistics, TimeSeries } from '../types/Statistics'; +import { + type IncomingRequestCommand, + MessageType, + type RequestCommand, + type Statistics, + type TimeSeries, +} from '../types'; import { CircularArray } from '../utils/CircularArray'; -import Configuration from '../utils/Configuration'; -import Constants from '../utils/Constants'; -import logger from '../utils/Logger'; -import Utils from '../utils/Utils'; +import { Configuration } from '../utils/Configuration'; +import { Constants } from '../utils/Constants'; +import { logger } from '../utils/Logger'; +import { Utils } from '../utils/Utils'; -export default class PerformanceStatistics { +export class PerformanceStatistics { private static readonly instances: Map = new Map< string, PerformanceStatistics diff --git a/src/performance/storage/JsonFileStorage.ts b/src/performance/storage/JsonFileStorage.ts index bacc8d21..3128c862 100644 --- a/src/performance/storage/JsonFileStorage.ts +++ b/src/performance/storage/JsonFileStorage.ts @@ -5,10 +5,9 @@ import fs from 'node:fs'; import lockfile from 'proper-lockfile'; import { Storage } from './Storage'; -import { FileType } from '../../types/FileType'; -import type { Statistics } from '../../types/Statistics'; -import FileUtils from '../../utils/FileUtils'; -import Utils from '../../utils/Utils'; +import { FileType, type Statistics } from '../../types'; +import { FileUtils } from '../../utils/FileUtils'; +import { Utils } from '../../utils/Utils'; export class JsonFileStorage extends Storage { private fd: number | null = null; diff --git a/src/performance/storage/MikroOrmStorage.ts b/src/performance/storage/MikroOrmStorage.ts index 69905d8d..5d236f27 100644 --- a/src/performance/storage/MikroOrmStorage.ts +++ b/src/performance/storage/MikroOrmStorage.ts @@ -4,11 +4,14 @@ import { Configuration, Connection, IDatabaseDriver, MikroORM, Options } from '@ import { TsMorphMetadataProvider } from '@mikro-orm/reflection'; import { Storage } from './Storage'; -import { PerformanceData } from '../../types/orm/entities/PerformanceData'; -import { PerformanceRecord } from '../../types/orm/entities/PerformanceRecord'; -import type { Statistics } from '../../types/Statistics'; -import { MikroORMDBType, StorageType } from '../../types/Storage'; -import Constants from '../../utils/Constants'; +import { + type MikroORMDBType, + PerformanceData, + PerformanceRecord, + type Statistics, + StorageType, +} from '../../types'; +import { Constants } from '../../utils/Constants'; export class MikroOrmStorage extends Storage { private storageType: StorageType; diff --git a/src/performance/storage/MongoDBStorage.ts b/src/performance/storage/MongoDBStorage.ts index 9e5c0662..32532ead 100644 --- a/src/performance/storage/MongoDBStorage.ts +++ b/src/performance/storage/MongoDBStorage.ts @@ -3,9 +3,8 @@ import { MongoClient } from 'mongodb'; import { Storage } from './Storage'; -import type { Statistics } from '../../types/Statistics'; -import { StorageType } from '../../types/Storage'; -import Constants from '../../utils/Constants'; +import { type Statistics, StorageType } from '../../types'; +import { Constants } from '../../utils/Constants'; export class MongoDBStorage extends Storage { private readonly client: MongoClient | null; diff --git a/src/performance/storage/Storage.ts b/src/performance/storage/Storage.ts index 4b8f4c7c..caa5fae2 100644 --- a/src/performance/storage/Storage.ts +++ b/src/performance/storage/Storage.ts @@ -2,12 +2,15 @@ import { URL } from 'node:url'; -import type { EmptyObject } from '../../types/EmptyObject'; -import type { HandleErrorParams } from '../../types/Error'; -import type { Statistics } from '../../types/Statistics'; -import { DBName, StorageType } from '../../types/Storage'; -import logger from '../../utils/Logger'; -import Utils from '../../utils/Utils'; +import { + DBName, + type EmptyObject, + type HandleErrorParams, + type Statistics, + StorageType, +} from '../../types'; +import { logger } from '../../utils/Logger'; +import { Utils } from '../../utils/Utils'; export abstract class Storage { protected readonly storageUri: URL; diff --git a/src/performance/storage/StorageFactory.ts b/src/performance/storage/StorageFactory.ts index 3da99725..09b58a15 100644 --- a/src/performance/storage/StorageFactory.ts +++ b/src/performance/storage/StorageFactory.ts @@ -4,7 +4,7 @@ import { JsonFileStorage } from './JsonFileStorage'; import { MikroOrmStorage } from './MikroOrmStorage'; import { MongoDBStorage } from './MongoDBStorage'; import type { Storage } from './Storage'; -import { StorageType } from '../../types/Storage'; +import { StorageType } from '../../types'; export class StorageFactory { private constructor() { diff --git a/src/types/ChargingStationWorker.ts b/src/types/ChargingStationWorker.ts index f0a58013..9a9d3574 100644 --- a/src/types/ChargingStationWorker.ts +++ b/src/types/ChargingStationWorker.ts @@ -6,7 +6,7 @@ import type { ConnectorStatus } from './ConnectorStatus'; import type { JsonObject } from './JsonType'; import type { BootNotificationResponse } from './ocpp/Responses'; import type { Statistics } from './Statistics'; -import { WorkerData, WorkerMessage, WorkerMessageEvents } from './Worker'; +import { type WorkerData, type WorkerMessage, WorkerMessageEvents } from '../worker'; export interface ChargingStationWorkerOptions extends JsonObject { elementStartDelay?: number; diff --git a/src/types/ConfigurationData.ts b/src/types/ConfigurationData.ts index b629dd3b..9688010a 100644 --- a/src/types/ConfigurationData.ts +++ b/src/types/ConfigurationData.ts @@ -4,7 +4,7 @@ import type { WorkerChoiceStrategy } from 'poolifier'; import type { StorageType } from './Storage'; import type { ApplicationProtocol, AuthenticationType } from './UIProtocol'; -import type { WorkerProcessType } from './Worker'; +import type { WorkerProcessType } from '../worker'; export type ServerOptions = ListenOptions; diff --git a/src/types/Statistics.ts b/src/types/Statistics.ts index 6abc1287..782adae2 100644 --- a/src/types/Statistics.ts +++ b/src/types/Statistics.ts @@ -1,6 +1,6 @@ import type { IncomingRequestCommand, RequestCommand } from './ocpp/Requests'; -import type { WorkerData } from './Worker'; import type { CircularArray } from '../utils/CircularArray'; +import type { WorkerData } from '../worker'; export type TimeSeries = { timestamp: number; diff --git a/src/types/index.ts b/src/types/index.ts new file mode 100644 index 00000000..1ca290d2 --- /dev/null +++ b/src/types/index.ts @@ -0,0 +1,44 @@ +export * from './ocpp/ChargePointErrorCode'; +export * from './ocpp/ChargingProfile'; +export * from './ocpp/Configuration'; +export * from './ocpp/ConnectorStatusEnum'; +export * from './ocpp/ErrorType'; +export * from './ocpp/MessageType'; +export * from './ocpp/MeterValues'; +export * from './ocpp/OCPPProtocol'; +export * from './ocpp/OCPPVersion'; +export * from './ocpp/Requests'; +export * from './ocpp/Responses'; +export * from './ocpp/Transaction'; +export * from './ocpp/1.6/ChargePointErrorCode'; +export * from './ocpp/1.6/ChargePointStatus'; +export * from './ocpp/1.6/ChargingProfile'; +export * from './ocpp/1.6/Configuration'; +export * from './ocpp/1.6/DiagnosticsStatus'; +export * from './ocpp/1.6/MeterValues'; +export * from './ocpp/1.6/Requests'; +export * from './ocpp/1.6/Responses'; +export * from './ocpp/1.6/Transaction'; +export * from './ocpp/2.0/Requests'; +export * from './ocpp/2.0/Responses'; +export * from './orm/entities/PerformanceData'; +export * from './orm/entities/PerformanceRecord'; +export * from './AutomaticTransactionGenerator'; +export * from './ChargingStationConfiguration'; +export * from './ChargingStationInfo'; +export * from './ChargingStationOcppConfiguration'; +export * from './ChargingStationTemplate'; +export * from './ChargingStationWorker'; +export * from './ConfigurationData'; +export * from './ConnectorStatus'; +export * from './EmptyObject'; +export * from './Error'; +export * from './FileType'; +export * from './JsonType'; +export * from './MeasurandPerPhaseSampledValueTemplates'; +export * from './MeasurandValues'; +export * from './Statistics'; +export * from './Storage'; +export * from './UIProtocol'; +export * from './WebSocket'; +export * from './WorkerBroadcastChannel'; diff --git a/src/types/ocpp/Requests.ts b/src/types/ocpp/Requests.ts index 6e61fcc1..8ef05664 100644 --- a/src/types/ocpp/Requests.ts +++ b/src/types/ocpp/Requests.ts @@ -20,8 +20,8 @@ import { type OCPP20StatusNotificationRequest, } from './2.0/Requests'; import type { MessageType } from './MessageType'; -import type ChargingStation from '../../charging-station/ChargingStation'; -import type OCPPError from '../../exception/OCPPError'; +import type { ChargingStation } from '../../charging-station/ChargingStation'; +import type { OCPPError } from '../../exception'; import type { JsonType } from '../JsonType'; export const RequestCommand = { diff --git a/src/types/ocpp/Responses.ts b/src/types/ocpp/Responses.ts index df4bdf90..c61b5463 100644 --- a/src/types/ocpp/Responses.ts +++ b/src/types/ocpp/Responses.ts @@ -21,7 +21,7 @@ import type { } from './2.0/Responses'; import type { ErrorType } from './ErrorType'; import type { MessageType } from './MessageType'; -import type ChargingStation from '../../charging-station/ChargingStation'; +import type { ChargingStation } from '../../charging-station/ChargingStation'; import type { JsonType } from '../JsonType'; export type Response = [MessageType.CALL_RESULT_MESSAGE, string, JsonType]; diff --git a/src/types/orm/entities/PerformanceData.ts b/src/types/orm/entities/PerformanceData.ts index 2622fa72..fc7268aa 100644 --- a/src/types/orm/entities/PerformanceData.ts +++ b/src/types/orm/entities/PerformanceData.ts @@ -1,6 +1,6 @@ import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'; -import { PerformanceRecord } from './PerformanceRecord'; +import type { PerformanceRecord } from './PerformanceRecord'; @Entity() export class PerformanceData { diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index c71b3ee5..16de0f89 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -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', diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index c6c691b0..246aa788 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -1,6 +1,6 @@ -import { MeterValueMeasurand } from '../types/ocpp/MeterValues'; +import { MeterValueMeasurand } from '../types'; -export default class Constants { +export class Constants { static readonly OCPP_DEFAULT_BOOT_NOTIFICATION_INTERVAL = 60000; // Ms static readonly OCPP_WEBSOCKET_TIMEOUT = 60000; // Ms static readonly OCPP_TRIGGER_MESSAGE_DELAY = 500; // Ms diff --git a/src/utils/FileUtils.ts b/src/utils/FileUtils.ts index ee8f053c..9b7f62e0 100644 --- a/src/utils/FileUtils.ts +++ b/src/utils/FileUtils.ts @@ -2,14 +2,11 @@ import fs from 'node:fs'; import chalk from 'chalk'; -import logger from './Logger'; -import Utils from './Utils'; -import type { EmptyObject } from '../types/EmptyObject'; -import type { HandleErrorParams } from '../types/Error'; -import type { FileType } from '../types/FileType'; -import type { JsonType } from '../types/JsonType'; +import { logger } from './Logger'; +import { Utils } from './Utils'; +import type { EmptyObject, FileType, HandleErrorParams, JsonType } from '../types'; -export default class FileUtils { +export class FileUtils { private constructor() { // This is intentional } diff --git a/src/utils/Logger.ts b/src/utils/Logger.ts index 53a4bf5f..96199e4f 100644 --- a/src/utils/Logger.ts +++ b/src/utils/Logger.ts @@ -3,8 +3,8 @@ import { type Logger, createLogger, format, type transport } from 'winston'; import TransportType from 'winston/lib/winston/transports'; import DailyRotateFile from 'winston-daily-rotate-file'; -import Configuration from './Configuration'; -import Utils from './Utils'; +import { Configuration } from './Configuration'; +import { Utils } from './Utils'; let transports: transport[]; if (Configuration.getLogRotate() === true) { @@ -59,4 +59,4 @@ if (Configuration.getLogConsole()) { ); } -export default logger; +export { logger }; diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index fa1c7b6b..0271754f 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -3,10 +3,10 @@ import util from 'node:util'; import clone from 'just-clone'; -import Constants from './Constants'; -import { WebSocketCloseEventStatusString } from '../types/WebSocket'; +import { Constants } from './Constants'; +import { WebSocketCloseEventStatusString } from '../types'; -export default class Utils { +export class Utils { private constructor() { // This is intentional } diff --git a/src/worker/WorkerAbstract.ts b/src/worker/WorkerAbstract.ts index 8588691d..f6777948 100644 --- a/src/worker/WorkerAbstract.ts +++ b/src/worker/WorkerAbstract.ts @@ -1,9 +1,9 @@ import fs from 'node:fs'; -import WorkerConstants from './WorkerConstants'; -import type { WorkerData, WorkerOptions } from '../types/Worker'; +import { WorkerConstants } from './WorkerConstants'; +import type { WorkerData, WorkerOptions } from './WorkerTypes'; -export default abstract class WorkerAbstract { +export abstract class WorkerAbstract { protected readonly workerScript: string; protected readonly workerOptions: WorkerOptions; public abstract readonly size: number; diff --git a/src/worker/WorkerConstants.ts b/src/worker/WorkerConstants.ts index 1e2e8cdc..8e34a165 100644 --- a/src/worker/WorkerConstants.ts +++ b/src/worker/WorkerConstants.ts @@ -1,4 +1,4 @@ -export default class WorkerConstants { +export class WorkerConstants { static readonly DEFAULT_ELEMENT_START_DELAY = 0; static readonly DEFAULT_WORKER_START_DELAY = 500; static readonly POOL_MAX_INACTIVE_TIME = 60000; diff --git a/src/worker/WorkerDynamicPool.ts b/src/worker/WorkerDynamicPool.ts index 9926a09e..889ae457 100644 --- a/src/worker/WorkerDynamicPool.ts +++ b/src/worker/WorkerDynamicPool.ts @@ -2,12 +2,11 @@ import type { Worker } from 'worker_threads'; import { DynamicThreadPool, type ErrorHandler, type ExitHandler } from 'poolifier'; -import WorkerAbstract from './WorkerAbstract'; +import { WorkerAbstract } from './WorkerAbstract'; +import type { WorkerData, WorkerOptions } from './WorkerTypes'; import { WorkerUtils } from './WorkerUtils'; -import type { WorkerData, WorkerOptions } from '../types/Worker'; -import Utils from '../utils/Utils'; -export default class WorkerDynamicPool extends WorkerAbstract { +export class WorkerDynamicPool extends WorkerAbstract { private readonly pool: DynamicThreadPool; /** @@ -69,6 +68,6 @@ export default class WorkerDynamicPool extends WorkerAbstract { await this.pool.execute(elementData); // Start element sequentially to optimize memory at startup this.workerOptions.elementStartDelay > 0 && - (await Utils.sleep(this.workerOptions.elementStartDelay)); + (await WorkerUtils.sleep(this.workerOptions.elementStartDelay)); } } diff --git a/src/worker/WorkerFactory.ts b/src/worker/WorkerFactory.ts index 465a3eff..fb9a26f1 100644 --- a/src/worker/WorkerFactory.ts +++ b/src/worker/WorkerFactory.ts @@ -2,14 +2,14 @@ import { type Worker, isMainThread } from 'worker_threads'; import type { PoolOptions } from 'poolifier'; -import type WorkerAbstract from './WorkerAbstract'; -import WorkerConstants from './WorkerConstants'; -import WorkerDynamicPool from './WorkerDynamicPool'; -import WorkerSet from './WorkerSet'; -import WorkerStaticPool from './WorkerStaticPool'; -import { type WorkerData, type WorkerOptions, WorkerProcessType } from '../types/Worker'; +import type { WorkerAbstract } from './WorkerAbstract'; +import { WorkerConstants } from './WorkerConstants'; +import { WorkerDynamicPool } from './WorkerDynamicPool'; +import { WorkerSet } from './WorkerSet'; +import { WorkerStaticPool } from './WorkerStaticPool'; +import { type WorkerData, type WorkerOptions, WorkerProcessType } from './WorkerTypes'; -export default class WorkerFactory { +export class WorkerFactory { private constructor() { // This is intentional } diff --git a/src/worker/WorkerSet.ts b/src/worker/WorkerSet.ts index c5b2d84a..a79db16e 100644 --- a/src/worker/WorkerSet.ts +++ b/src/worker/WorkerSet.ts @@ -2,18 +2,17 @@ import { Worker } from 'worker_threads'; -import WorkerAbstract from './WorkerAbstract'; -import { WorkerUtils } from './WorkerUtils'; +import { WorkerAbstract } from './WorkerAbstract'; import { type MessageHandler, type WorkerData, WorkerMessageEvents, type WorkerOptions, type WorkerSetElement, -} from '../types/Worker'; -import Utils from '../utils/Utils'; +} from './WorkerTypes'; +import { WorkerUtils } from './WorkerUtils'; -export default class WorkerSet extends WorkerAbstract { +export class WorkerSet extends WorkerAbstract { private readonly workerSet: Set; /** @@ -58,7 +57,7 @@ export default class WorkerSet extends WorkerAbstract { this.getLastWorkerSetElement().numberOfWorkerElements++; // Start element sequentially to optimize memory at startup if (this.workerOptions.elementStartDelay > 0) { - await Utils.sleep(this.workerOptions.elementStartDelay); + await WorkerUtils.sleep(this.workerOptions.elementStartDelay); } } @@ -105,7 +104,7 @@ export default class WorkerSet extends WorkerAbstract { this.workerSet.add({ worker, numberOfWorkerElements: 0 }); // Start worker sequentially to optimize memory at startup this.workerOptions.workerStartDelay > 0 && - (await Utils.sleep(this.workerOptions.workerStartDelay)); + (await WorkerUtils.sleep(this.workerOptions.workerStartDelay)); } private getLastWorkerSetElement(): WorkerSetElement { diff --git a/src/worker/WorkerStaticPool.ts b/src/worker/WorkerStaticPool.ts index 2ec049e1..58e4c65a 100644 --- a/src/worker/WorkerStaticPool.ts +++ b/src/worker/WorkerStaticPool.ts @@ -2,12 +2,11 @@ import type { Worker } from 'worker_threads'; import { type ErrorHandler, type ExitHandler, FixedThreadPool } from 'poolifier'; -import WorkerAbstract from './WorkerAbstract'; +import { WorkerAbstract } from './WorkerAbstract'; +import type { WorkerData, WorkerOptions } from './WorkerTypes'; import { WorkerUtils } from './WorkerUtils'; -import type { WorkerData, WorkerOptions } from '../types/Worker'; -import Utils from '../utils/Utils'; -export default class WorkerStaticPool extends WorkerAbstract { +export class WorkerStaticPool extends WorkerAbstract { private readonly pool: FixedThreadPool; /** @@ -68,6 +67,6 @@ export default class WorkerStaticPool extends WorkerAbstract { await this.pool.execute(elementData); // Start element sequentially to optimize memory at startup this.workerOptions.elementStartDelay > 0 && - (await Utils.sleep(this.workerOptions.elementStartDelay)); + (await WorkerUtils.sleep(this.workerOptions.elementStartDelay)); } } diff --git a/src/types/Worker.ts b/src/worker/WorkerTypes.ts similarity index 100% rename from src/types/Worker.ts rename to src/worker/WorkerTypes.ts diff --git a/src/worker/WorkerUtils.ts b/src/worker/WorkerUtils.ts index 2b612351..7c72ff3e 100644 --- a/src/worker/WorkerUtils.ts +++ b/src/worker/WorkerUtils.ts @@ -5,6 +5,10 @@ export class WorkerUtils { // This is intentional } + public static async sleep(milliSeconds: number): Promise { + return new Promise((resolve) => setTimeout(resolve as () => void, milliSeconds)); + } + public static defaultExitHandler = (code: number): void => { if (code !== 0) { console.error(chalk.red(`Worker exited with error exit code: ${code.toString()}`)); diff --git a/src/worker/index.ts b/src/worker/index.ts new file mode 100644 index 00000000..fdc278d5 --- /dev/null +++ b/src/worker/index.ts @@ -0,0 +1,10 @@ +export * from './WorkerAbstract'; +export * from './WorkerConstants'; +export * from './WorkerFactory'; +export { + WorkerProcessType, + WorkerData, + WorkerMessage, + WorkerMessageEvents, + MessageHandler, +} from './WorkerTypes'; diff --git a/test/utils/UtilsTest.ts b/test/utils/UtilsTest.ts index 836e41b9..b189bfd5 100644 --- a/test/utils/UtilsTest.ts +++ b/test/utils/UtilsTest.ts @@ -1,7 +1,7 @@ import expect from 'expect'; -import Constants from '../../src/utils/Constants'; -import Utils from '../../src/utils/Utils'; +import { Constants } from '../../src/utils/Constants'; +import { Utils } from '../../src/utils/Utils'; describe('Utils test suite', () => { it('Verify generateUUID()/validateUUID()', () => {