Move cache related helper to the right class
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 24 May 2022 21:06:01 +0000 (23:06 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 24 May 2022 21:06:01 +0000 (23:06 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
package-lock.json
package.json
src/charging-station/ChargingStationCache.ts
src/charging-station/ChargingStationUtils.ts

index 4e02b7f0d23053f55e819173455781f5dccc79fb..f258bf738e3cb659d42a29d559312ac2cf5f1a21 100644 (file)
@@ -54,7 +54,7 @@
         "eslint-plugin-prettier": "^4.0.0",
         "expect": "^28.1.0",
         "husky": "^8.0.1",
-        "lint-staged": "^12.4.1",
+        "lint-staged": "^12.4.2",
         "mocha": "^10.0.0",
         "mochawesome": "^7.1.3",
         "nyc": "^15.1.0",
       }
     },
     "node_modules/keyv": {
-      "version": "4.2.9",
-      "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.2.9.tgz",
-      "integrity": "sha512-vqRBrN4xQHud7UMAGzGGFbt96MtGB9pb0OOg8Dhtq5RtiswCb1pCFq878iqC4hdeOP6eDPnCoFxA+2TXx427Ow==",
+      "version": "4.3.0",
+      "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.3.0.tgz",
+      "integrity": "sha512-C30Un9+63J0CsR7Wka5quXKqYZsT6dcRQ2aOwGcSc3RiQ4HGWpTAHlCA+puNfw2jA/s11EsxA1nCXgZRuRKMQQ==",
       "dev": true,
       "dependencies": {
         "compress-brotli": "^1.3.8",
       "dev": true
     },
     "node_modules/lint-staged": {
-      "version": "12.4.1",
-      "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-12.4.1.tgz",
-      "integrity": "sha512-PTXgzpflrQ+pODQTG116QNB+Q6uUTDg5B5HqGvNhoQSGt8Qy+MA/6zSnR8n38+sxP5TapzeQGTvoKni0KRS8Vg==",
+      "version": "12.4.2",
+      "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-12.4.2.tgz",
+      "integrity": "sha512-JAJGIzY/OioIUtrRePr8go6qUxij//mL+RGGoFKU3VWQRtIHgWoHizSqH0QVn2OwrbXS9Q6CICQjfj+E5qvrXg==",
       "dev": true,
       "dependencies": {
         "cli-truncate": "^3.1.0",
       }
     },
     "node_modules/new-github-release-url/node_modules/type-fest": {
-      "version": "2.12.2",
-      "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.12.2.tgz",
-      "integrity": "sha512-qt6ylCGpLjZ7AaODxbpyBZSs9fCI9SkL3Z9q2oxMBQhs/uyY+VD8jHA8ULCGmWQJlBgqvO3EJeAngOHD8zQCrQ==",
+      "version": "2.13.0",
+      "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.13.0.tgz",
+      "integrity": "sha512-lPfAm42MxE4/456+QyIaaVBAwgpJb6xZ8PRu09utnhPdWwcyj9vgy6Sq0Z5yNbJ21EdxB5dRU/Qg8bsyAMtlcw==",
       "dev": true,
       "engines": {
         "node": ">=12.20"
       }
     },
     "keyv": {
-      "version": "4.2.9",
-      "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.2.9.tgz",
-      "integrity": "sha512-vqRBrN4xQHud7UMAGzGGFbt96MtGB9pb0OOg8Dhtq5RtiswCb1pCFq878iqC4hdeOP6eDPnCoFxA+2TXx427Ow==",
+      "version": "4.3.0",
+      "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.3.0.tgz",
+      "integrity": "sha512-C30Un9+63J0CsR7Wka5quXKqYZsT6dcRQ2aOwGcSc3RiQ4HGWpTAHlCA+puNfw2jA/s11EsxA1nCXgZRuRKMQQ==",
       "dev": true,
       "requires": {
         "compress-brotli": "^1.3.8",
       "dev": true
     },
     "lint-staged": {
-      "version": "12.4.1",
-      "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-12.4.1.tgz",
-      "integrity": "sha512-PTXgzpflrQ+pODQTG116QNB+Q6uUTDg5B5HqGvNhoQSGt8Qy+MA/6zSnR8n38+sxP5TapzeQGTvoKni0KRS8Vg==",
+      "version": "12.4.2",
+      "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-12.4.2.tgz",
+      "integrity": "sha512-JAJGIzY/OioIUtrRePr8go6qUxij//mL+RGGoFKU3VWQRtIHgWoHizSqH0QVn2OwrbXS9Q6CICQjfj+E5qvrXg==",
       "dev": true,
       "requires": {
         "cli-truncate": "^3.1.0",
       },
       "dependencies": {
         "type-fest": {
-          "version": "2.12.2",
-          "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.12.2.tgz",
-          "integrity": "sha512-qt6ylCGpLjZ7AaODxbpyBZSs9fCI9SkL3Z9q2oxMBQhs/uyY+VD8jHA8ULCGmWQJlBgqvO3EJeAngOHD8zQCrQ==",
+          "version": "2.13.0",
+          "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.13.0.tgz",
+          "integrity": "sha512-lPfAm42MxE4/456+QyIaaVBAwgpJb6xZ8PRu09utnhPdWwcyj9vgy6Sq0Z5yNbJ21EdxB5dRU/Qg8bsyAMtlcw==",
           "dev": true
         }
       }
index 629854eb78e52e840e585e6ecfe01c184af8eccd..db6cf1b2d2178ba9cae1be770c4e8e393887205e 100644 (file)
     "eslint-plugin-prettier": "^4.0.0",
     "expect": "^28.1.0",
     "husky": "^8.0.1",
-    "lint-staged": "^12.4.1",
+    "lint-staged": "^12.4.2",
     "mocha": "^10.0.0",
     "mochawesome": "^7.1.3",
     "nyc": "^15.1.0",
index 8aff62a2bf6568e3949383e43c6dedb86f35ec69..682e2d9cdf50324be56b3cfdb0eaf22e4bf937ae 100644 (file)
@@ -1,7 +1,7 @@
 import ChargingStationConfiguration from '../types/ChargingStationConfiguration';
 import ChargingStationTemplate from '../types/ChargingStationTemplate';
-import { ChargingStationUtils } from './ChargingStationUtils';
 import LRUCache from 'mnemonist/lru-map-with-delete';
+import Utils from '../utils/Utils';
 
 enum CacheType {
   CHARGING_STATION_TEMPLATE = 'chargingStationTemplate',
@@ -30,9 +30,7 @@ export class ChargingStationCache {
   public setChargingStationConfiguration(
     chargingStationConfiguration: ChargingStationConfiguration
   ): void {
-    if (
-      ChargingStationUtils.isChargingStationConfigurationCacheable(chargingStationConfiguration)
-    ) {
+    if (this.isChargingStationConfigurationCacheable(chargingStationConfiguration)) {
       this.set(
         CacheType.CHARGING_STATION_CONFIGURATION + chargingStationConfiguration.configurationHash,
         chargingStationConfiguration
@@ -92,4 +90,17 @@ export class ChargingStationCache {
   private delete(key: string): void {
     this.lruCache.delete(key);
   }
+
+  private isChargingStationConfigurationCacheable(
+    chargingStationConfiguration: ChargingStationConfiguration
+  ): boolean {
+    return (
+      !Utils.isNullOrUndefined(chargingStationConfiguration?.configurationKey) &&
+      !Utils.isNullOrUndefined(chargingStationConfiguration?.stationInfo) &&
+      !Utils.isNullOrUndefined(chargingStationConfiguration?.configurationHash) &&
+      !Utils.isEmptyArray(chargingStationConfiguration?.configurationKey) &&
+      !Utils.isEmptyObject(chargingStationConfiguration?.stationInfo) &&
+      !Utils.isEmptyString(chargingStationConfiguration?.configurationHash)
+    );
+  }
 }
index 352de1101d56ca9e569c610ef55fe08a5124b948..9eee346630083ee75dc623af9b16c6ff14704d0f 100644 (file)
@@ -10,7 +10,6 @@ import { MeterValueMeasurand, MeterValuePhase } from '../types/ocpp/MeterValues'
 import BaseError from '../exception/BaseError';
 import { BootNotificationRequest } from '../types/ocpp/Requests';
 import ChargingStation from './ChargingStation';
-import ChargingStationConfiguration from '../types/ChargingStationConfiguration';
 import { ChargingStationConfigurationUtils } from './ChargingStationConfigurationUtils';
 import ChargingStationInfo from '../types/ChargingStationInfo';
 import Configuration from '../utils/Configuration';
@@ -553,19 +552,6 @@ export class ChargingStationUtils {
     );
   }
 
-  public static isChargingStationConfigurationCacheable(
-    chargingStationConfiguration: ChargingStationConfiguration
-  ): boolean {
-    return (
-      !Utils.isNullOrUndefined(chargingStationConfiguration?.configurationKey) &&
-      !Utils.isNullOrUndefined(chargingStationConfiguration?.stationInfo) &&
-      !Utils.isNullOrUndefined(chargingStationConfiguration?.configurationHash) &&
-      !Utils.isEmptyArray(chargingStationConfiguration?.configurationKey) &&
-      !Utils.isEmptyObject(chargingStationConfiguration?.stationInfo) &&
-      !Utils.isEmptyString(chargingStationConfiguration?.configurationHash)
-    );
-  }
-
   private static getRandomSerialNumberSuffix(params?: {
     randomBytesLength?: number;
     upperCase?: boolean;