Merge pull request #1016 from SAP/dependabot/npm_and_yarn/types/node-20.11.30
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 20 Mar 2024 08:53:39 +0000 (08:53 +0000)
committerGitHub <noreply@github.com>
Wed, 20 Mar 2024 08:53:39 +0000 (08:53 +0000)
build(deps-dev): bump @types/node from 20.11.29 to 20.11.30

12 files changed:
bundle.js
src/charging-station/Bootstrap.ts
src/charging-station/ChargingStation.ts
src/charging-station/Helpers.ts
src/utils/Configuration.ts
src/utils/Constants.ts
src/worker/WorkerAbstract.ts
src/worker/WorkerConstants.ts
src/worker/WorkerDynamicPool.ts
src/worker/WorkerFactory.ts
src/worker/WorkerFixedPool.ts
src/worker/WorkerSet.ts

index 2d4bc8631952220d84f8a99141c794795d095606..4443f985160205ae4e0356f8d133f221712a3e6f 100644 (file)
--- a/bundle.js
+++ b/bundle.js
@@ -22,6 +22,7 @@ await build({
     'basic-ftp',
     'chalk',
     'date-fns',
+    'date-fns/*',
     'http-status-codes',
     'logform',
     'mnemonist',
index 545e88899da9a91629e3736d5025670f8b26c263..34ac90f3f3e4ba2e211d47ef3639907e5ccff066 100644 (file)
@@ -64,7 +64,6 @@ export class Bootstrap extends EventEmitter {
   private storage?: Storage
   private readonly templateStatistics: Map<string, TemplateStatistics>
   private readonly version: string = version
-  private initializedCounters: boolean
   private started: boolean
   private starting: boolean
   private stopping: boolean
@@ -82,12 +81,14 @@ export class Bootstrap extends EventEmitter {
     this.starting = false
     this.stopping = false
     this.uiServerStarted = false
+    this.templateStatistics = new Map<string, TemplateStatistics>()
     this.uiServer = UIServerFactory.getUIServerImplementation(
       Configuration.getConfigurationSection<UIServerConfiguration>(ConfigurationSection.uiServer)
     )
-    this.templateStatistics = new Map<string, TemplateStatistics>()
-    this.initializedCounters = false
     this.initializeCounters()
+    this.initializeWorkerImplementation(
+      Configuration.getConfigurationSection<WorkerConfiguration>(ConfigurationSection.worker)
+    )
     Configuration.configurationChangeCallback = async () => {
       if (isMainThread) {
         await Bootstrap.getInstance().restart()
@@ -174,12 +175,12 @@ export class Bootstrap extends EventEmitter {
             )
           }
         )
-        this.initializeCounters()
-        const workerConfiguration = Configuration.getConfigurationSection<WorkerConfiguration>(
-          ConfigurationSection.worker
-        )
-        this.initializeWorkerImplementation(workerConfiguration)
-        await this.workerImplementation?.start()
+        // eslint-disable-next-line @typescript-eslint/unbound-method
+        if (isAsyncFunction(this.workerImplementation?.start)) {
+          await this.workerImplementation.start()
+        } else {
+          (this.workerImplementation?.start as () => void)()
+        }
         const performanceStorageConfiguration =
           Configuration.getConfigurationSection<StorageConfiguration>(
             ConfigurationSection.performanceStorage
@@ -220,6 +221,9 @@ export class Bootstrap extends EventEmitter {
             )
           }
         }
+        const workerConfiguration = Configuration.getConfigurationSection<WorkerConfiguration>(
+          ConfigurationSection.worker
+        )
         console.info(
           chalk.green(
             `Charging stations simulator ${
@@ -269,10 +273,8 @@ export class Bootstrap extends EventEmitter {
           console.error(chalk.red('Error while waiting for charging stations to stop: '), error)
         }
         await this.workerImplementation?.stop()
-        delete this.workerImplementation
         this.removeAllListeners()
         this.uiServer.clearCaches()
-        this.initializedCounters = false
         await this.storage?.close()
         delete this.storage
         this.started = false
@@ -295,6 +297,11 @@ export class Bootstrap extends EventEmitter {
       this.uiServer.stop()
       this.uiServerStarted = false
     }
+    this.initializeCounters()
+    // FIXME: initialize worker implementation only if the worker section has changed
+    this.initializeWorkerImplementation(
+      Configuration.getConfigurationSection<WorkerConfiguration>(ConfigurationSection.worker)
+    )
     await this.start()
   }
 
@@ -356,7 +363,9 @@ export class Bootstrap extends EventEmitter {
         elementsPerWorker,
         poolOptions: {
           messageHandler: this.messageHandler.bind(this) as MessageHandler<Worker>,
-          workerOptions: { resourceLimits: workerConfiguration.resourceLimits }
+          ...(workerConfiguration.resourceLimits != null && {
+            workerOptions: { resourceLimits: workerConfiguration.resourceLimits }
+          })
         }
       }
     )
@@ -487,47 +496,44 @@ export class Bootstrap extends EventEmitter {
   }
 
   private initializeCounters (): void {
-    if (!this.initializedCounters) {
-      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
-      const stationTemplateUrls = Configuration.getStationTemplateUrls()!
-      if (isNotEmptyArray(stationTemplateUrls)) {
-        for (const stationTemplateUrl of stationTemplateUrls) {
-          const templateName = buildTemplateName(stationTemplateUrl.file)
-          this.templateStatistics.set(templateName, {
-            configured: stationTemplateUrl.numberOfStations,
-            added: 0,
-            started: 0,
-            indexes: new Set<number>()
-          })
-          this.uiServer.chargingStationTemplates.add(templateName)
-        }
-        if (this.templateStatistics.size !== stationTemplateUrls.length) {
-          console.error(
-            chalk.red(
-              "'stationTemplateUrls' contains duplicate entries, please check your configuration"
-            )
-          )
-          exit(exitCodes.duplicateChargingStationTemplateUrls)
-        }
-      } else {
-        console.error(
-          chalk.red("'stationTemplateUrls' not defined or empty, please check your configuration")
-        )
-        exit(exitCodes.missingChargingStationsConfiguration)
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    const stationTemplateUrls = Configuration.getStationTemplateUrls()!
+    if (isNotEmptyArray(stationTemplateUrls)) {
+      for (const stationTemplateUrl of stationTemplateUrls) {
+        const templateName = buildTemplateName(stationTemplateUrl.file)
+        this.templateStatistics.set(templateName, {
+          configured: stationTemplateUrl.numberOfStations,
+          added: 0,
+          started: 0,
+          indexes: new Set<number>()
+        })
+        this.uiServer.chargingStationTemplates.add(templateName)
       }
-      if (
-        this.numberOfConfiguredChargingStations === 0 &&
-        Configuration.getConfigurationSection<UIServerConfiguration>(ConfigurationSection.uiServer)
-          .enabled !== true
-      ) {
+      if (this.templateStatistics.size !== stationTemplateUrls.length) {
         console.error(
           chalk.red(
-            "'stationTemplateUrls' has no charging station enabled and UI server is disabled, please check your configuration"
+            "'stationTemplateUrls' contains duplicate entries, please check your configuration"
           )
         )
-        exit(exitCodes.noChargingStationTemplates)
+        exit(exitCodes.duplicateChargingStationTemplateUrls)
       }
-      this.initializedCounters = true
+    } else {
+      console.error(
+        chalk.red("'stationTemplateUrls' not defined or empty, please check your configuration")
+      )
+      exit(exitCodes.missingChargingStationsConfiguration)
+    }
+    if (
+      this.numberOfConfiguredChargingStations === 0 &&
+      Configuration.getConfigurationSection<UIServerConfiguration>(ConfigurationSection.uiServer)
+        .enabled !== true
+    ) {
+      console.error(
+        chalk.red(
+          "'stationTemplateUrls' has no charging station enabled and UI server is disabled, please check your configuration"
+        )
+      )
+      exit(exitCodes.noChargingStationTemplates)
     }
   }
 
index 29aedcbae2bbb1ee7ee66b23432c27359483cf66..e41ea5ec79980db46558684cca08f2ff9cab6d38 100644 (file)
@@ -1191,15 +1191,6 @@ export class ChargingStation extends EventEmitter {
         } does not match firmware version pattern '${stationInfo.firmwareVersionPattern}'`
       )
     }
-    stationInfo.firmwareUpgrade = mergeDeepRight(
-      {
-        versionUpgrade: {
-          step: 1
-        },
-        reset: true
-      },
-      stationTemplate.firmwareUpgrade ?? {}
-    )
     if (stationTemplate.resetTime != null) {
       stationInfo.resetTime = secondsToMilliseconds(stationTemplate.resetTime)
     }
@@ -1244,7 +1235,7 @@ export class ChargingStation extends EventEmitter {
       stationInfoFromFile.templateHash === stationInfoFromTemplate.templateHash
     ) {
       return setChargingStationOptions(
-        { ...Constants.DEFAULT_STATION_INFO, ...stationInfoFromFile },
+        mergeDeepRight(Constants.DEFAULT_STATION_INFO, stationInfoFromFile),
         options
       )
     }
@@ -1255,7 +1246,7 @@ export class ChargingStation extends EventEmitter {
         stationInfoFromTemplate
       )
     return setChargingStationOptions(
-      { ...Constants.DEFAULT_STATION_INFO, ...stationInfoFromTemplate },
+      mergeDeepRight(Constants.DEFAULT_STATION_INFO, stationInfoFromTemplate),
       options
     )
   }
index 916cf499ecedaadfe821719658a1608aefbdf880..735a0b39c9bcf967f69297aa1a66618d2b4f9752 100644 (file)
@@ -974,7 +974,7 @@ export const prepareChargingProfileKind = (
       if (connectorStatus?.transactionStarted === true) {
         chargingProfile.chargingSchedule.startSchedule = connectorStatus.transactionStart
       }
-      // FIXME: Handle relative charging profile duration
+      // FIXME: handle relative charging profile duration
       break
   }
   return true
index e1fd11c731af1024ebfd08dfba373eb82680abc2..9356785deaf2af7dfba30ff313d9bfbf82f8ee34 100644 (file)
@@ -513,22 +513,22 @@ export class Configuration {
 
   private static warnDeprecatedConfigurationKey (
     key: string,
-    sectionName?: string,
+    configurationSection?: ConfigurationSection,
     logMsgToAppend = ''
   ): void {
     if (
-      sectionName != null &&
-      Configuration.getConfigurationData()?.[sectionName as keyof ConfigurationData] != null &&
+      configurationSection != null &&
+      Configuration.getConfigurationData()?.[configurationSection as keyof ConfigurationData] !=
+        null &&
       (
-        Configuration.getConfigurationData()?.[sectionName as keyof ConfigurationData] as Record<
-        string,
-        unknown
-        >
+        Configuration.getConfigurationData()?.[
+          configurationSection as keyof ConfigurationData
+        ] as Record<string, unknown>
       )[key] != null
     ) {
       console.error(
         `${chalk.green(logPrefix())} ${chalk.red(
-          `Deprecated configuration key '${key}' usage in section '${sectionName}'${
+          `Deprecated configuration key '${key}' usage in section '${configurationSection}'${
             logMsgToAppend.trim().length > 0 ? `. ${logMsgToAppend}` : ''
           }`
         )}`
index a5e46f60673e3078afd9386c4b3995c0800477b5..3746c4fdd91e8277ebc5167c563cbd3cf88fb673 100644 (file)
@@ -34,6 +34,12 @@ export class Constants {
     useConnectorId0: true,
     ocppVersion: OCPPVersion.VERSION_16,
     firmwareVersionPattern: Constants.SEMVER_PATTERN,
+    firmwareUpgrade: {
+      versionUpgrade: {
+        step: 1
+      },
+      reset: true
+    },
     ocppPersistentConfiguration: true,
     stationInfoPersistentConfiguration: true,
     automaticTransactionGeneratorPersistentConfiguration: true,
index 9a10e6f2afa1de4c463dd8a2803917b61f5b76b5..907d0bd0e580273bbba8f54c60cfd0b73d4a6c7c 100644 (file)
@@ -39,7 +39,7 @@ export abstract class WorkerAbstract<T extends WorkerData> {
   /**
    * Starts the worker pool/set.
    */
-  public abstract start (): Promise<void>
+  public abstract start (): void | Promise<void>
   /**
    * Stops the worker pool/set.
    */
index 28e9927dd42790bfb43ae74d19141129abdfa162..ded5c89142f8e2aa9f485ed9df6ea476a7832100 100644 (file)
@@ -22,6 +22,7 @@ export const DEFAULT_WORKER_OPTIONS: WorkerOptions = Object.freeze({
   poolMaxSize: DEFAULT_POOL_MAX_SIZE,
   elementsPerWorker: DEFAULT_ELEMENTS_PER_WORKER,
   poolOptions: {
+    startWorkers: false,
     enableEvents: true,
     restartWorkerOnError: true,
     errorHandler: defaultErrorHandler,
index 0bdb26194465384f060cf6c01ef858799b3dafe9..2043297318c38e8d298a76c9d660b4d215bc8d71 100644 (file)
@@ -42,8 +42,8 @@ export class WorkerDynamicPool extends WorkerAbstract<WorkerData> {
   }
 
   /** @inheritDoc */
-  public async start (): Promise<void> {
-    // This is intentional
+  public start (): void {
+    this.pool.start()
   }
 
   /** @inheritDoc */
index 833c939f1767e832b021f152a5d2725caf221f72..67da00d88a5b2d32572fa2f8a5f422fe3b73a843 100644 (file)
@@ -1,5 +1,7 @@
 import { isMainThread } from 'node:worker_threads'
 
+import { mergeDeepRight } from 'rambda'
+
 import type { WorkerAbstract } from './WorkerAbstract.js'
 import { DEFAULT_WORKER_OPTIONS } from './WorkerConstants.js'
 import { WorkerDynamicPool } from './WorkerDynamicPool.js'
@@ -21,7 +23,7 @@ export class WorkerFactory {
     if (!isMainThread) {
       throw new Error('Cannot get a worker implementation outside the main thread')
     }
-    workerOptions = { ...DEFAULT_WORKER_OPTIONS, ...workerOptions }
+    workerOptions = mergeDeepRight<WorkerOptions>(DEFAULT_WORKER_OPTIONS, workerOptions ?? {})
     let workerImplementation: WorkerAbstract<T>
     switch (workerProcessType) {
       case WorkerProcessType.workerSet:
index 4eafa1d59933395ee0fb5f2c2dddc9f5404aeb00..22290666c17546e1f3c0f461a0cbca39e0841de2 100644 (file)
@@ -41,8 +41,8 @@ export class WorkerFixedPool extends WorkerAbstract<WorkerData> {
   }
 
   /** @inheritDoc */
-  public async start (): Promise<void> {
-    // This is intentional
+  public start (): void {
+    this.pool.start()
   }
 
   /** @inheritDoc */
index 1ad551efb0553e47458e2766734fdfd1cbc0ef12..d0f80b6ed59a54342430991ff4d318d86e0a5402 100644 (file)
@@ -99,7 +99,6 @@ export class WorkerSet extends WorkerAbstract<WorkerData> {
     this.emitter?.emit(WorkerSetEvents.stopped, this.info)
     this.started = false
     this.emitter?.emitDestroy()
-    this.emitter?.removeAllListeners()
   }
 
   /** @inheritDoc */