import { type FSWatcher, readFileSync } from 'node:fs'
-import type { ChargingStation } from './ChargingStation.js'
-import { getIdTagsFile } from './Helpers.js'
import { FileType, IdTagDistribution } from '../types/index.js'
import {
handleFileException,
isNotEmptyString,
- logPrefix,
logger,
+ logPrefix,
secureRandom,
watchJsonFile
} from '../utils/index.js'
+import type { ChargingStation } from './ChargingStation.js'
+import { getIdTagsFile } from './Helpers.js'
interface IdTagsCacheValueType {
idTags: string[]
chargingStation: ChargingStation,
connectorId: number
): string {
- const hashId = chargingStation.stationInfo.hashId
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const idTagsFile = getIdTagsFile(chargingStation.stationInfo)!
+ const hashId = chargingStation.stationInfo!.hashId
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ const idTagsFile = getIdTagsFile(chargingStation.stationInfo!)!
switch (distribution) {
case IdTagDistribution.RANDOM:
return this.getRandomIdTag(hashId, idTagsFile)
private getConnectorAffinityIdTag (chargingStation: ChargingStation, connectorId: number): string {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
- const file = getIdTagsFile(chargingStation.stationInfo)!
+ const file = getIdTagsFile(chargingStation.stationInfo!)!
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const idTags = this.getIdTags(file)!
const addressableKey = this.getIdTagsCacheIndexesAddressableKey(
file,
- chargingStation.stationInfo.hashId
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ chargingStation.stationInfo!.hashId
)
this.idTagsCachesAddressableIndexes.set(
addressableKey,
logger.debug(
`${this.logPrefix(file)} ${FileType.Authorization} file have changed, reload`
)
- this.deleteIdTagsCache(file)
- this.deleteIdTagsCacheIndexes(file)
+ this.deleteIdTags(file)
} catch (error) {
handleFileException(
file,
deleted.push(this.idTagsCachesAddressableIndexes.delete(key))
}
}
- return !deleted.some((value) => !value)
+ return !deleted.some(value => !value)
}
private getIdTagsCacheIndexesAddressableKey (prefix: string, uid: string): string {