repositories
/
e-mobility-charging-stations-simulator.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
build(simulator): silence linter
[e-mobility-charging-stations-simulator.git]
/
src
/
charging-station
/
IdTagsCache.ts
diff --git
a/src/charging-station/IdTagsCache.ts
b/src/charging-station/IdTagsCache.ts
index 6e8592cb71aecfeb7f3160212761905adde2b9c8..26ef71318af3bf9cb4834c9b4e07e29faa70e1ba 100644
(file)
--- a/
src/charging-station/IdTagsCache.ts
+++ b/
src/charging-station/IdTagsCache.ts
@@
-1,13
+1,20
@@
-import
fs
from 'node:fs';
+import
{ type FSWatcher, readFileSync }
from 'node:fs';
import type { ChargingStation } from './ChargingStation';
import type { ChargingStation } from './ChargingStation';
-import {
ChargingStationUtils
} from './ChargingStationUtils';
+import {
getIdTagsFile
} from './ChargingStationUtils';
import { FileType, IdTagDistribution } from '../types';
import { FileType, IdTagDistribution } from '../types';
-import { Utils, handleFileException, logger, watchJsonFile } from '../utils';
+import {
+ handleFileException,
+ isNotEmptyString,
+ logPrefix,
+ logger,
+ secureRandom,
+ watchJsonFile,
+} from '../utils';
type IdTagsCacheValueType = {
idTags: string[];
type IdTagsCacheValueType = {
idTags: string[];
- idTagsFileWatcher:
fs.
FSWatcher | undefined;
+ idTagsFileWatcher: FSWatcher | undefined;
};
export class IdTagsCache {
};
export class IdTagsCache {
@@
-28,7
+35,7
@@
export class IdTagsCache {
}
/**
}
/**
- * Get one idtag from the cache given the distribution
+ * Get
s
one idtag from the cache given the distribution
* Must be called after checking the cache is not an empty array
*
* @param distribution -
* Must be called after checking the cache is not an empty array
*
* @param distribution -
@@
-39,10
+46,10
@@
export class IdTagsCache {
public getIdTag(
distribution: IdTagDistribution,
chargingStation: ChargingStation,
public getIdTag(
distribution: IdTagDistribution,
chargingStation: ChargingStation,
- connectorId: number
+ connectorId: number
,
): string {
const hashId = chargingStation.stationInfo.hashId;
): string {
const hashId = chargingStation.stationInfo.hashId;
- const idTagsFile =
ChargingStationUtils.
getIdTagsFile(chargingStation.stationInfo);
+ const idTagsFile = getIdTagsFile(chargingStation.stationInfo);
switch (distribution) {
case IdTagDistribution.RANDOM:
return this.getRandomIdTag(hashId, idTagsFile);
switch (distribution) {
case IdTagDistribution.RANDOM:
return this.getRandomIdTag(hashId, idTagsFile);
@@
-56,7
+63,7
@@
export class IdTagsCache {
}
/**
}
/**
- * Get all idtags from the cache
+ * Get
s
all idtags from the cache
* Must be called after checking the cache is not an empty array
*
* @param file -
* Must be called after checking the cache is not an empty array
*
* @param file -
@@
-78,7
+85,7
@@
export class IdTagsCache {
const addressableKey = this.getIdTagsCacheIndexesAddressableKey(file, hashId);
this.idTagsCachesAddressableIndexes.set(
addressableKey,
const addressableKey = this.getIdTagsCacheIndexesAddressableKey(file, hashId);
this.idTagsCachesAddressableIndexes.set(
addressableKey,
- Math.floor(
Utils.secureRandom() * idTags.length)
+ Math.floor(
secureRandom() * idTags.length),
);
return idTags[this.idTagsCachesAddressableIndexes.get(addressableKey)];
}
);
return idTags[this.idTagsCachesAddressableIndexes.get(addressableKey)];
}
@@
-90,21
+97,21
@@
export class IdTagsCache {
const idTag = idTags[idTagIndex];
this.idTagsCachesAddressableIndexes.set(
addressableKey,
const idTag = idTags[idTagIndex];
this.idTagsCachesAddressableIndexes.set(
addressableKey,
- idTagIndex === idTags.length - 1 ? 0 : idTagIndex + 1
+ idTagIndex === idTags.length - 1 ? 0 : idTagIndex + 1
,
);
return idTag;
}
private getConnectorAffinityIdTag(chargingStation: ChargingStation, connectorId: number): string {
);
return idTag;
}
private getConnectorAffinityIdTag(chargingStation: ChargingStation, connectorId: number): string {
- const file =
ChargingStationUtils.
getIdTagsFile(chargingStation.stationInfo);
+ const file = getIdTagsFile(chargingStation.stationInfo);
const idTags = this.getIdTags(file);
const addressableKey = this.getIdTagsCacheIndexesAddressableKey(
file,
const idTags = this.getIdTags(file);
const addressableKey = this.getIdTagsCacheIndexesAddressableKey(
file,
- chargingStation.stationInfo.hashId
+ chargingStation.stationInfo.hashId
,
);
this.idTagsCachesAddressableIndexes.set(
addressableKey,
);
this.idTagsCachesAddressableIndexes.set(
addressableKey,
- (chargingStation.index - 1 + (connectorId - 1)) % idTags.length
+ (chargingStation.index - 1 + (connectorId - 1)) % idTags.length
,
);
return idTags[this.idTagsCachesAddressableIndexes.get(addressableKey)];
}
);
return idTags[this.idTagsCachesAddressableIndexes.get(addressableKey)];
}
@@
-122,10
+129,10
@@
export class IdTagsCache {
this.logPrefix(file),
undefined,
(event, filename) => {
this.logPrefix(file),
undefined,
(event, filename) => {
- if (
Utils.
isNotEmptyString(filename) && event === 'change') {
+ if (isNotEmptyString(filename) && event === 'change') {
try {
logger.debug(
try {
logger.debug(
- `${this.logPrefix(file)} ${FileType.Authorization} file have changed, reload`
+ `${this.logPrefix(file)} ${FileType.Authorization} file have changed, reload`
,
);
this.deleteIdTagsCache(file);
this.deleteIdTagsCacheIndexes(file);
);
this.deleteIdTagsCache(file);
this.deleteIdTagsCacheIndexes(file);
@@
-137,11
+144,11
@@
export class IdTagsCache {
this.logPrefix(file),
{
throwError: false,
this.logPrefix(file),
{
throwError: false,
- }
+ }
,
);
}
}
);
}
}
- }
+ }
,
),
});
}
),
});
}
@@
-170,15
+177,15
@@
export class IdTagsCache {
}
private getIdTagsFromFile(file: string): string[] {
}
private getIdTagsFromFile(file: string): string[] {
- if (
Utils.
isNotEmptyString(file)) {
+ if (isNotEmptyString(file)) {
try {
try {
- return JSON.parse(
fs.
readFileSync(file, 'utf8')) as string[];
+ return JSON.parse(readFileSync(file, 'utf8')) as string[];
} catch (error) {
handleFileException(
file,
FileType.Authorization,
error as NodeJS.ErrnoException,
} catch (error) {
handleFileException(
file,
FileType.Authorization,
error as NodeJS.ErrnoException,
- this.logPrefix(file)
+ this.logPrefix(file)
,
);
}
}
);
}
}
@@
-186,6
+193,6
@@
export class IdTagsCache {
}
private logPrefix = (file: string): string => {
}
private logPrefix = (file: string): string => {
- return
Utils.
logPrefix(` Id tags cache for id tags file '${file}' |`);
+ return logPrefix(` Id tags cache for id tags file '${file}' |`);
};
}
};
}