From c14729f47992a1b142d2c20f94777d0747eaf9f2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 24 May 2022 23:06:01 +0200 Subject: [PATCH] Move cache related helper to the right class MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- package-lock.json | 38 ++++++++++---------- package.json | 2 +- src/charging-station/ChargingStationCache.ts | 19 +++++++--- src/charging-station/ChargingStationUtils.ts | 14 -------- 4 files changed, 35 insertions(+), 38 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4e02b7f0..f258bf73 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", @@ -9074,9 +9074,9 @@ } }, "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", @@ -9214,9 +9214,9 @@ "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", @@ -10861,9 +10861,9 @@ } }, "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" @@ -24386,9 +24386,9 @@ } }, "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", @@ -24481,9 +24481,9 @@ "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", @@ -25825,9 +25825,9 @@ }, "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 } } diff --git a/package.json b/package.json index 629854eb..db6cf1b2 100644 --- a/package.json +++ b/package.json @@ -125,7 +125,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", diff --git a/src/charging-station/ChargingStationCache.ts b/src/charging-station/ChargingStationCache.ts index 8aff62a2..682e2d9c 100644 --- a/src/charging-station/ChargingStationCache.ts +++ b/src/charging-station/ChargingStationCache.ts @@ -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) + ); + } } diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 352de110..9eee3466 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -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; -- 2.34.1