From 17bc43d765c22c8d8c132484f8dc9c3edd370d91 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 12 Feb 2023 17:32:28 +0100 Subject: [PATCH] fix(simulator): make the modules export/import a bit less sensitive to nasty circular dependencies issue MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../AutomaticTransactionGenerator.ts | 2 +- src/charging-station/Bootstrap.ts | 6 ++---- src/charging-station/ChargingStation.ts | 2 +- src/charging-station/SharedLRUCache.ts | 2 +- .../UIServiceWorkerBroadcastChannel.ts | 2 +- src/charging-station/index.ts | 1 + src/charging-station/internal.ts | 8 ++++++++ .../ocpp/OCPPRequestService.ts | 2 +- src/charging-station/ocpp/index.ts | 20 +++++++++---------- .../ui-server/AbstractUIServer.ts | 3 +-- .../ui-server/UIHttpServer.ts | 2 +- .../ui-server/UIServerFactory.ts | 4 +--- .../ui-server/UIWebSocketServer.ts | 2 +- .../ui-services/AbstractUIService.ts | 3 +-- .../ui-server/ui-services/UIService001.ts | 3 +-- .../ui-server/ui-services/UIServiceFactory.ts | 4 +--- src/exception/index.ts | 4 ++-- src/internal.ts | 1 - src/performance/index.ts | 3 +++ src/start.ts | 2 +- src/worker/index.ts | 6 +++--- 21 files changed, 42 insertions(+), 40 deletions(-) create mode 100644 src/charging-station/index.ts create mode 100644 src/charging-station/internal.ts delete mode 100644 src/internal.ts create mode 100644 src/performance/index.ts diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index 3c365932..e6b3dbf4 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -5,7 +5,7 @@ import { AsyncResource } from 'async_hooks'; import type { ChargingStation } from './ChargingStation'; import { ChargingStationUtils } from './ChargingStationUtils'; import { BaseError } from '../exception'; -import { PerformanceStatistics } from '../performance/PerformanceStatistics'; +import { PerformanceStatistics } from '../performance'; import { AuthorizationStatus, type AuthorizeRequest, diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 1acd5bcb..c35464d1 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -7,12 +7,10 @@ import { type Worker, isMainThread } from 'worker_threads'; import chalk from 'chalk'; import { ChargingStationUtils } from './ChargingStationUtils'; -import type { AbstractUIServer } from './ui-server/AbstractUIServer'; -import { UIServerFactory } from './ui-server/UIServerFactory'; +import { type AbstractUIServer, UIServerFactory } from './internal'; import { version } from '../../package.json'; import { BaseError } from '../exception'; -import type { Storage } from '../performance/storage/Storage'; -import { StorageFactory } from '../performance/storage/StorageFactory'; +import { type Storage, StorageFactory } from '../performance'; import { type ChargingStationData, type ChargingStationWorkerData, diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index c74daceb..29119f92 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -29,7 +29,7 @@ import { } from './ocpp'; import { SharedLRUCache } from './SharedLRUCache'; import { BaseError, OCPPError } from '../exception'; -import { PerformanceStatistics } from '../performance/PerformanceStatistics'; +import { PerformanceStatistics } from '../performance'; import { type AutomaticTransactionGeneratorConfiguration, AvailabilityType, diff --git a/src/charging-station/SharedLRUCache.ts b/src/charging-station/SharedLRUCache.ts index 64ee0146..d2d63869 100644 --- a/src/charging-station/SharedLRUCache.ts +++ b/src/charging-station/SharedLRUCache.ts @@ -1,6 +1,6 @@ import LRUCache from 'mnemonist/lru-map-with-delete'; -import { Bootstrap } from '../internal'; +import { Bootstrap } from './internal'; import type { ChargingStationConfiguration, ChargingStationTemplate } from '../types'; import { Utils } from '../utils/Utils'; diff --git a/src/charging-station/UIServiceWorkerBroadcastChannel.ts b/src/charging-station/UIServiceWorkerBroadcastChannel.ts index 77ae46f2..8528c0e2 100644 --- a/src/charging-station/UIServiceWorkerBroadcastChannel.ts +++ b/src/charging-station/UIServiceWorkerBroadcastChannel.ts @@ -1,4 +1,4 @@ -import type { AbstractUIService } from './ui-server/ui-services/AbstractUIService'; +import type { AbstractUIService } from './internal'; import { WorkerBroadcastChannel } from './WorkerBroadcastChannel'; import { type BroadcastChannelResponse, diff --git a/src/charging-station/index.ts b/src/charging-station/index.ts new file mode 100644 index 00000000..c365e0b9 --- /dev/null +++ b/src/charging-station/index.ts @@ -0,0 +1 @@ +export { Bootstrap } from './internal'; diff --git a/src/charging-station/internal.ts b/src/charging-station/internal.ts new file mode 100644 index 00000000..314c9685 --- /dev/null +++ b/src/charging-station/internal.ts @@ -0,0 +1,8 @@ +export * from './Bootstrap'; +export * from './ui-server/AbstractUIServer'; +export * from './ui-server/UIHttpServer'; +export * from './ui-server/UIWebSocketServer'; +export * from './ui-server/UIServerFactory'; +export * from './ui-server/ui-services/AbstractUIService'; +export * from './ui-server/ui-services/UIService001'; +export * from './ui-server/ui-services/UIServiceFactory'; diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index fc729113..4ef39b52 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -4,7 +4,7 @@ import ajvFormats from 'ajv-formats'; import type { OCPPResponseService } from './OCPPResponseService'; import { OCPPServiceUtils } from './OCPPServiceUtils'; import { OCPPError } from '../../exception'; -import { PerformanceStatistics } from '../../performance/PerformanceStatistics'; +import { PerformanceStatistics } from '../../performance'; import { type EmptyObject, type ErrorCallback, diff --git a/src/charging-station/ocpp/index.ts b/src/charging-station/ocpp/index.ts index a0634d19..bf43676f 100644 --- a/src/charging-station/ocpp/index.ts +++ b/src/charging-station/ocpp/index.ts @@ -1,11 +1,11 @@ -export * from './OCPPIncomingRequestService'; -export * from './OCPPRequestService'; -export * from './OCPPServiceUtils'; -export * from './1.6/OCPP16IncomingRequestService'; -export * from './1.6/OCPP16RequestService'; -export * from './1.6/OCPP16ResponseService'; +export { OCPPIncomingRequestService } from './OCPPIncomingRequestService'; +export { OCPPRequestService } from './OCPPRequestService'; +export { OCPPServiceUtils } from './OCPPServiceUtils'; +export { OCPP16IncomingRequestService } from './1.6/OCPP16IncomingRequestService'; +export { OCPP16RequestService } from './1.6/OCPP16RequestService'; +export { OCPP16ResponseService } from './1.6/OCPP16ResponseService'; // FIXME: shall not be exported -export * from './1.6/OCPP16ServiceUtils'; -export * from './2.0/OCPP20IncomingRequestService'; -export * from './2.0/OCPP20RequestService'; -export * from './2.0/OCPP20ResponseService'; +export { OCPP16ServiceUtils } from './1.6/OCPP16ServiceUtils'; +export { OCPP20IncomingRequestService } from './2.0/OCPP20IncomingRequestService'; +export { OCPP20RequestService } from './2.0/OCPP20RequestService'; +export { OCPP20ResponseService } from './2.0/OCPP20ResponseService'; diff --git a/src/charging-station/ui-server/AbstractUIServer.ts b/src/charging-station/ui-server/AbstractUIServer.ts index 053b1bae..840d558c 100644 --- a/src/charging-station/ui-server/AbstractUIServer.ts +++ b/src/charging-station/ui-server/AbstractUIServer.ts @@ -2,8 +2,6 @@ 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 { AuthenticationType, type ChargingStationData, @@ -15,6 +13,7 @@ import { type ResponsePayload, type UIServerConfiguration, } from '../../types'; +import { type AbstractUIService, UIServiceFactory } from '../internal'; 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 23527347..08ea7ff0 100644 --- a/src/charging-station/ui-server/UIHttpServer.ts +++ b/src/charging-station/ui-server/UIHttpServer.ts @@ -2,7 +2,6 @@ import type { IncomingMessage, RequestListener, ServerResponse } from 'http'; import { StatusCodes } from 'http-status-codes'; -import { AbstractUIServer } from './AbstractUIServer'; import { UIServerUtils } from './UIServerUtils'; import { BaseError } from '../../exception'; import { @@ -17,6 +16,7 @@ import { } from '../../types'; import { logger } from '../../utils/Logger'; import { Utils } from '../../utils/Utils'; +import { AbstractUIServer } from '../internal'; const moduleName = 'UIHttpServer'; diff --git a/src/charging-station/ui-server/UIServerFactory.ts b/src/charging-station/ui-server/UIServerFactory.ts index 64d143d4..612054f6 100644 --- a/src/charging-station/ui-server/UIServerFactory.ts +++ b/src/charging-station/ui-server/UIServerFactory.ts @@ -1,11 +1,9 @@ import chalk from 'chalk'; -import type { AbstractUIServer } from './AbstractUIServer'; -import { UIHttpServer } from './UIHttpServer'; import { UIServerUtils } from './UIServerUtils'; -import { UIWebSocketServer } from './UIWebSocketServer'; import { ApplicationProtocol, type UIServerConfiguration } from '../../types'; import { Configuration } from '../../utils/Configuration'; +import { type AbstractUIServer, UIHttpServer, UIWebSocketServer } from '../internal'; export class UIServerFactory { private constructor() { diff --git a/src/charging-station/ui-server/UIWebSocketServer.ts b/src/charging-station/ui-server/UIWebSocketServer.ts index 3e2dd813..d5e6ff80 100644 --- a/src/charging-station/ui-server/UIWebSocketServer.ts +++ b/src/charging-station/ui-server/UIWebSocketServer.ts @@ -4,7 +4,6 @@ import type internal from 'stream'; import { StatusCodes } from 'http-status-codes'; import WebSocket, { type RawData, WebSocketServer } from 'ws'; -import { AbstractUIServer } from './AbstractUIServer'; import { UIServerUtils } from './UIServerUtils'; import { type ProtocolRequest, @@ -14,6 +13,7 @@ import { } from '../../types'; import { logger } from '../../utils/Logger'; import { Utils } from '../../utils/Utils'; +import { AbstractUIServer } from '../internal'; const moduleName = 'UIWebSocketServer'; diff --git a/src/charging-station/ui-server/ui-services/AbstractUIService.ts b/src/charging-station/ui-server/ui-services/AbstractUIService.ts index 49d10abf..9662d635 100644 --- a/src/charging-station/ui-server/ui-services/AbstractUIService.ts +++ b/src/charging-station/ui-server/ui-services/AbstractUIService.ts @@ -1,5 +1,4 @@ import { BaseError, type OCPPError } from '../../../exception'; -import { Bootstrap } from '../../../internal'; import { BroadcastChannelProcedureName, type BroadcastChannelRequestPayload, @@ -13,8 +12,8 @@ import { } from '../../../types'; import { logger } from '../../../utils/Logger'; import { Utils } from '../../../utils/Utils'; +import { type AbstractUIServer, Bootstrap } from '../../internal'; import { UIServiceWorkerBroadcastChannel } from '../../UIServiceWorkerBroadcastChannel'; -import type { AbstractUIServer } from '../AbstractUIServer'; const moduleName = 'AbstractUIService'; diff --git a/src/charging-station/ui-server/ui-services/UIService001.ts b/src/charging-station/ui-server/ui-services/UIService001.ts index 598ebb26..4a1d1e9a 100644 --- a/src/charging-station/ui-server/ui-services/UIService001.ts +++ b/src/charging-station/ui-server/ui-services/UIService001.ts @@ -1,6 +1,5 @@ -import { AbstractUIService } from './AbstractUIService'; import { type ProcedureName, type ProtocolRequestHandler, ProtocolVersion } from '../../../types'; -import type { AbstractUIServer } from '../AbstractUIServer'; +import { type AbstractUIServer, AbstractUIService } from '../../internal'; export class UIService001 extends AbstractUIService { constructor(uiServer: AbstractUIServer) { diff --git a/src/charging-station/ui-server/ui-services/UIServiceFactory.ts b/src/charging-station/ui-server/ui-services/UIServiceFactory.ts index 47a1893d..2d2fa6c8 100644 --- a/src/charging-station/ui-server/ui-services/UIServiceFactory.ts +++ b/src/charging-station/ui-server/ui-services/UIServiceFactory.ts @@ -1,7 +1,5 @@ -import type { AbstractUIService } from './AbstractUIService'; -import { UIService001 } from './UIService001'; import { ProtocolVersion } from '../../../types'; -import type { AbstractUIServer } from '../AbstractUIServer'; +import { type AbstractUIServer, type AbstractUIService, UIService001 } from '../../internal'; export class UIServiceFactory { private constructor() { diff --git a/src/exception/index.ts b/src/exception/index.ts index 49abdfcb..5e5b60ca 100644 --- a/src/exception/index.ts +++ b/src/exception/index.ts @@ -1,2 +1,2 @@ -export * from './BaseError'; -export * from './OCPPError'; +export { BaseError } from './BaseError'; +export { OCPPError } from './OCPPError'; diff --git a/src/internal.ts b/src/internal.ts deleted file mode 100644 index 7cf06b9e..00000000 --- a/src/internal.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './charging-station/Bootstrap'; diff --git a/src/performance/index.ts b/src/performance/index.ts new file mode 100644 index 00000000..1b61c465 --- /dev/null +++ b/src/performance/index.ts @@ -0,0 +1,3 @@ +export { PerformanceStatistics } from './PerformanceStatistics'; +export { Storage } from './storage/Storage'; +export { StorageFactory } from './storage/StorageFactory'; diff --git a/src/start.ts b/src/start.ts index 0185903d..12acc3eb 100644 --- a/src/start.ts +++ b/src/start.ts @@ -2,7 +2,7 @@ import chalk from 'chalk'; -import { Bootstrap } from './internal'; +import { Bootstrap } from './charging-station'; Bootstrap.getInstance() .start() diff --git a/src/worker/index.ts b/src/worker/index.ts index fdc278d5..9fa37055 100644 --- a/src/worker/index.ts +++ b/src/worker/index.ts @@ -1,6 +1,6 @@ -export * from './WorkerAbstract'; -export * from './WorkerConstants'; -export * from './WorkerFactory'; +export { WorkerAbstract } from './WorkerAbstract'; +export { WorkerConstants } from './WorkerConstants'; +export { WorkerFactory } from './WorkerFactory'; export { WorkerProcessType, WorkerData, -- 2.34.1