export default class AuthorizedTagsCache {
private static instance: AuthorizedTagsCache | null = null;
private readonly tagsCaches: Map<string, string[]>;
- private readonly FSWatchers: Map<string, fs.FSWatcher>;
+ private readonly FSWatchers: Map<string, fs.FSWatcher | undefined>;
private constructor() {
this.tagsCaches = new Map<string, string[]>();
- this.FSWatchers = new Map<string, fs.FSWatcher>();
+ this.FSWatchers = new Map<string, fs.FSWatcher | undefined>();
}
public static getInstance(): AuthorizedTagsCache {
return AuthorizedTagsCache.instance;
}
- public getAuthorizedTags(file: string): string[] {
+ public getAuthorizedTags(file: string): string[] | undefined {
if (this.hasTags(file) === false) {
this.setTags(file, this.getAuthorizedTagsFromFile(file));
// Monitor authorization file
return this.tagsCaches.set(file, tags);
}
- private getTags(file: string): string[] {
+ private getTags(file: string): string[] | undefined {
return this.tagsCaches.get(file);
}
}
private deleteFSWatcher(file: string): boolean {
- this.FSWatchers.get(file).close();
+ this.FSWatchers.get(file)?.close();
return this.FSWatchers.delete(file);
}
public static getInstance(
automaticTransactionGeneratorConfiguration: AutomaticTransactionGeneratorConfiguration,
chargingStation: ChargingStation
- ): AutomaticTransactionGenerator {
+ ): AutomaticTransactionGenerator | undefined {
if (AutomaticTransactionGenerator.instances.has(chargingStation.stationInfo.hashId) === false) {
AutomaticTransactionGenerator.instances.set(
chargingStation.stationInfo.hashId,
this.connectorsStatus.get(connectorId).startDate.getTime()
)}`
);
- while (this.connectorsStatus.get(connectorId).start === true) {
+ while (this.connectorsStatus.get(connectorId)?.start === true) {
if (new Date() > this.connectorsStatus.get(connectorId).stopDate) {
this.stopConnector(connectorId);
break;
logger.info(
`${this.logPrefix(connectorId)} stop transaction ${this.chargingStation
.getConnectorStatus(connectorId)
- .transactionId.toString()}`
+ ?.transactionId?.toString()}`
);
await this.stopTransaction(connectorId);
}
logger.info(
`${this.logPrefix(connectorId)} skipped consecutively ${this.connectorsStatus
.get(connectorId)
- .skippedConsecutiveTransactions.toString()}/${this.connectorsStatus
+ ?.skippedConsecutiveTransactions?.toString()}/${this.connectorsStatus
.get(connectorId)
- .skippedTransactions.toString()} transaction(s)`
+ ?.skippedTransactions?.toString()} transaction(s)`
);
}
this.connectorsStatus.get(connectorId).lastRunDate = new Date();
this.connectorsStatus.get(connectorId).rejectedStopTransactionRequests++;
}
} else {
- const transactionId = this.chargingStation.getConnectorStatus(connectorId).transactionId;
+ const transactionId = this.chargingStation.getConnectorStatus(connectorId)?.transactionId;
logger.warn(
`${this.logPrefix(connectorId)} stopping a not started transaction${
transactionId ? ` ${transactionId.toString()}` : ''
this.logUncaughtException();
this.initialize();
await this.storage?.open();
- await this.workerImplementation.start();
+ await this.workerImplementation?.start();
this.uiServer?.start();
const stationTemplateUrls = Configuration.getStationTemplateUrls();
this.numberOfChargingStationTemplates = stationTemplateUrls.length;
this.version
} started with ${this.numberOfChargingStations.toString()} charging station(s) from ${this.numberOfChargingStationTemplates.toString()} configured charging station template(s) and ${
ChargingStationUtils.workerDynamicPoolInUse()
- ? `${Configuration.getWorker().poolMinSize.toString()}/`
+ ? `${Configuration.getWorker().poolMinSize?.toString()}/`
: ''
- }${this.workerImplementation.size}${
+ }${this.workerImplementation?.size}${
ChargingStationUtils.workerPoolInUse()
- ? `/${Configuration.getWorker().poolMaxSize.toString()}`
+ ? `/${Configuration.getWorker().poolMaxSize?.toString()}`
: ''
} worker(s) concurrently running in '${Configuration.getWorker().processType}' mode${
- this.workerImplementation.maxElementsPerWorker
- ? ` (${this.workerImplementation.maxElementsPerWorker} charging station(s) per worker)`
+ this.workerImplementation?.maxElementsPerWorker
+ ? ` (${this.workerImplementation?.maxElementsPerWorker} charging station(s) per worker)`
: ''
}`
)
public async stop(): Promise<void> {
if (isMainThread && this.started === true) {
- await this.workerImplementation.stop();
+ await this.workerImplementation?.stop();
this.workerImplementation = null;
this.uiServer?.stop();
await this.storage?.close();
public heartbeatSetInterval!: NodeJS.Timeout;
public ocppRequestService!: OCPPRequestService;
public bootNotificationRequest!: BootNotificationRequest;
- public bootNotificationResponse!: BootNotificationResponse | null;
+ public bootNotificationResponse!: BootNotificationResponse | undefined;
public powerDivider!: number;
private stopping: boolean;
private configurationFile!: string;
return this?.wsConnection?.readyState === WebSocket.OPEN;
}
- public getRegistrationStatus(): RegistrationStatusEnumType {
+ public getRegistrationStatus(): RegistrationStatusEnumType | undefined {
return this?.bootNotificationResponse?.status;
}
}
public isChargingStationAvailable(): boolean {
- return this.getConnectorStatus(0).availability === AvailabilityType.OPERATIVE;
+ return this.getConnectorStatus(0)?.availability === AvailabilityType.OPERATIVE;
}
public isConnectorAvailable(id: number): boolean {
- return id > 0 && this.getConnectorStatus(id).availability === AvailabilityType.OPERATIVE;
+ return id > 0 && this.getConnectorStatus(id)?.availability === AvailabilityType.OPERATIVE;
}
public getNumberOfConnectors(): number {
public getTransactionIdTag(transactionId: number): string | undefined {
for (const connectorId of this.connectors.keys()) {
- if (connectorId > 0 && this.getConnectorStatus(connectorId).transactionId === transactionId) {
+ if (
+ connectorId > 0 &&
+ this.getConnectorStatus(connectorId)?.transactionId === transactionId
+ ) {
return this.getConnectorStatus(connectorId).transactionIdTag;
}
}
}
);
this.started = true;
- parentPort.postMessage(MessageChannelUtils.buildStartedMessage(this));
+ parentPort?.postMessage(MessageChannelUtils.buildStartedMessage(this));
this.starting = false;
} else {
logger.warn(`${this.logPrefix()} Charging station is already starting...`);
this.sharedLRUCache.deleteChargingStationConfiguration(this.configurationFileHash);
this.templateFileWatcher.close();
this.sharedLRUCache.deleteChargingStationTemplate(this.stationInfo?.templateHash);
- this.bootNotificationResponse = null;
+ this.bootNotificationResponse = undefined;
this.started = false;
- parentPort.postMessage(MessageChannelUtils.buildStoppedMessage(this));
+ parentPort?.postMessage(MessageChannelUtils.buildStoppedMessage(this));
this.stopping = false;
} else {
logger.warn(`${this.logPrefix()} Charging station is already stopping...`);
this.getConnectorStatus(connectorId).transactionEnergyActiveImportRegisterValue = 0;
delete this.getConnectorStatus(connectorId).transactionBeginMeterValue;
this.stopMeterValues(connectorId);
- parentPort.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
+ parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
}
public hasFeatureProfile(featureProfile: SupportedFeatureProfiles): boolean {
} else {
this.automaticTransactionGenerator.start();
}
- parentPort.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
+ parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
}
public stopAutomaticTransactionGenerator(connectorIds?: number[]): void {
} else {
this.automaticTransactionGenerator?.stop();
}
- parentPort.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
+ parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
}
public async stopTransactionOnConnector(
if (this.isRegistered() === false) {
this.getRegistrationMaxRetries() !== -1 && registrationRetryCount++;
await Utils.sleep(
- this.bootNotificationResponse?.interval
+ this?.bootNotificationResponse?.interval
? this.bootNotificationResponse.interval * 1000
: Constants.OCPP_DEFAULT_BOOT_NOTIFICATION_INTERVAL
);
}
this.wsConnectionRestarted = false;
this.autoReconnectRetryCount = 0;
- parentPort.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
+ parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
} else {
logger.warn(
`${this.logPrefix()} Connection to OCPP server through ${this.wsConnectionUrl.toString()} failed`
this.started === true && (await this.reconnect());
break;
}
- parentPort.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
+ parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
}
private async onMessage(data: RawData): Promise<void> {
logger.error(`${this.logPrefix()} ${errMsg}`);
throw new OCPPError(ErrorType.PROTOCOL_ERROR, errMsg);
}
- parentPort.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
+ parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
} else {
throw new OCPPError(ErrorType.PROTOCOL_ERROR, 'Incoming message is not an array', null, {
request,
key: string | StandardParametersKey,
caseInsensitive = false
): ConfigurationKey | undefined {
- return chargingStation.ocppConfiguration.configurationKey.find(configElement => {
+ return chargingStation.ocppConfiguration.configurationKey?.find(configElement => {
if (caseInsensitive) {
return configElement.key.toLowerCase() === key.toLowerCase();
}
keyFound = undefined;
}
if (!keyFound) {
- chargingStation.ocppConfiguration.configurationKey.push({
+ chargingStation.ocppConfiguration.configurationKey?.push({
key,
readonly: options.readonly,
value,
chargingStation: ChargingStation,
key: string | StandardParametersKey,
params: DeleteConfigurationKeyParams = { save: true, caseInsensitive: false }
- ): ConfigurationKey[] {
+ ): ConfigurationKey[] | undefined {
const keyFound = ChargingStationConfigurationUtils.getConfigurationKey(
chargingStation,
key,
// Get charging profiles for connector and sort by stack level
chargingProfiles = chargingStation
.getConnectorStatus(connectorId)
- .chargingProfiles.sort((a, b) => b.stackLevel - a.stackLevel);
+ ?.chargingProfiles?.sort((a, b) => b.stackLevel - a.stackLevel);
// Get profiles on connector 0
- if (chargingStation.getConnectorStatus(0).chargingProfiles) {
+ if (chargingStation.getConnectorStatus(0)?.chargingProfiles) {
chargingProfiles.push(
...chargingStation
.getConnectorStatus(0)
chargingStation.logPrefix()
);
if (!Utils.isNullOrUndefined(result)) {
- limit = result.limit;
- matchingChargingProfile = result.matchingChargingProfile;
+ limit = result?.limit;
+ matchingChargingProfile = result?.matchingChargingProfile;
switch (chargingStation.getCurrentOutType()) {
case CurrentType.AC:
limit =
return this.lruCache.has(key);
}
- private get(key: string): CacheableType {
+ private get(key: string): CacheableType | undefined {
return this.lruCache.get(key);
}
private readonly objId: string;
private readonly objName: string;
- private performanceObserver: PerformanceObserver;
+ private performanceObserver!: PerformanceObserver;
private readonly statistics: Statistics;
- private displayInterval: NodeJS.Timeout;
+ private displayInterval!: NodeJS.Timeout;
private constructor(objId: string, objName: string, uri: URL) {
this.objId = objId;
)
);
if (Configuration.getPerformanceStorage().enabled) {
- parentPort.postMessage(
+ parentPort?.postMessage(
MessageChannelUtils.buildPerformanceStatisticsMessage(this.statistics)
);
}
export class MikroOrmStorage extends Storage {
private storageType: StorageType;
- private orm: MikroORM | null;
+ private orm!: MikroORM | null;
constructor(storageUri: string, logPrefix: string, storageType: StorageType) {
super(storageUri, logPrefix);
public async storePerformanceStatistics(performanceStatistics: Statistics): Promise<void> {
try {
const performanceRecord = new PerformanceRecord();
- await this.orm.em.persistAndFlush(performanceRecord);
+ await this.orm?.em.persistAndFlush(performanceRecord);
} catch (error) {
this.handleDBError(this.storageType, error as Error, Constants.PERFORMANCE_RECORDS_TABLE);
}
};
}
- private getClientUrl(): string {
+ private getClientUrl(): string | undefined {
switch (this.storageType) {
case StorageType.SQLITE:
case StorageType.MARIA_DB:
export abstract class Storage {
protected readonly storageUri: URL;
protected readonly logPrefix: string;
- protected dbName: string;
+ protected dbName!: string;
constructor(storageUri: string, logPrefix: string) {
this.storageUri = new URL(storageUri);
}
}
- protected getDBNameFromStorageType(type: StorageType): DBName {
+ protected getDBNameFromStorageType(type: StorageType): DBName | undefined {
switch (type) {
case StorageType.MARIA_DB:
return DBName.MARIA_DB;
}
public static getStorage(type: StorageType, connectionUri: string, logPrefix: string): Storage {
- let storageInstance: Storage = null;
+ let storageInstance: Storage | null = null;
switch (type) {
case StorageType.JSON_FILE:
storageInstance = new JsonFileStorage(connectionUri, logPrefix);
| typeof WebSocket.OPEN
| typeof WebSocket.CLOSING
| typeof WebSocket.CLOSED;
- bootNotificationResponse: BootNotificationResponse;
+ bootNotificationResponse?: BootNotificationResponse;
connectors: ConnectorStatus[];
automaticTransactionGenerator?: ChargingStationAutomaticTransactionGeneratorConfiguration;
}
export type WorkerOptions = {
workerStartDelay?: number;
elementStartDelay?: number;
- poolMaxSize?: number;
- poolMinSize?: number;
+ poolMaxSize: number;
+ poolMinSize: number;
elementsPerWorker?: number;
poolOptions?: PoolOptions<Worker>;
messageHandler?: MessageHandler<Worker>;
'config.json'
);
- private static configurationFileWatcher: fs.FSWatcher;
+ private static configurationFileWatcher: fs.FSWatcher | undefined;
private static configuration: ConfigurationData | null = null;
private static configurationChangeCallback: () => Promise<void>;
Configuration.configurationChangeCallback = cb;
}
- static getLogStatisticsInterval(): number {
+ static getLogStatisticsInterval(): number | undefined {
Configuration.warnDeprecatedConfigurationKey(
'statisticsDisplayInterval',
- null,
+ undefined,
"Use 'logStatisticsInterval' instead"
);
// Read conf
return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'logStatisticsInterval')
- ? Configuration.getConfig().logStatisticsInterval
+ ? Configuration.getConfig()?.logStatisticsInterval
: Constants.DEFAULT_LOG_STATISTICS_INTERVAL;
}
},
};
if (Configuration.objectHasOwnProperty(Configuration.getConfig(), 'uiServer')) {
- uiServerConfiguration = merge(uiServerConfiguration, Configuration.getConfig().uiServer);
+ uiServerConfiguration = merge(uiServerConfiguration, Configuration.getConfig()?.uiServer);
}
if (Configuration.isCFEnvironment() === true) {
delete uiServerConfiguration.options.host;
if (Configuration.objectHasOwnProperty(Configuration.getConfig(), 'performanceStorage')) {
storageConfiguration = {
...storageConfiguration,
- ...Configuration.getConfig().performanceStorage,
+ ...Configuration.getConfig()?.performanceStorage,
};
}
return storageConfiguration;
}
- static getAutoReconnectMaxRetries(): number {
+ static getAutoReconnectMaxRetries(): number | undefined {
Configuration.warnDeprecatedConfigurationKey(
'autoReconnectTimeout',
- null,
+ undefined,
"Use 'ConnectionTimeOut' OCPP parameter in charging station template instead"
);
Configuration.warnDeprecatedConfigurationKey(
'connectionTimeout',
- null,
+ undefined,
"Use 'ConnectionTimeOut' OCPP parameter in charging station template instead"
);
Configuration.warnDeprecatedConfigurationKey(
'autoReconnectMaxRetries',
- null,
+ undefined,
'Use it in charging station template instead'
);
// Read conf
if (Configuration.objectHasOwnProperty(Configuration.getConfig(), 'autoReconnectMaxRetries')) {
- return Configuration.getConfig().autoReconnectMaxRetries;
+ return Configuration.getConfig()?.autoReconnectMaxRetries;
}
}
- static getStationTemplateUrls(): StationTemplateUrl[] {
+ static getStationTemplateUrls(): StationTemplateUrl[] | undefined {
Configuration.warnDeprecatedConfigurationKey(
'stationTemplateURLs',
- null,
+ undefined,
"Use 'stationTemplateUrls' instead"
);
!Configuration.isUndefined(Configuration.getConfig()['stationTemplateURLs']) &&
(Configuration.getConfig().stationTemplateUrls = Configuration.getConfig()[
'stationTemplateURLs'
- ] as StationTemplateUrl[]);
+ ] as unknown as StationTemplateUrl[]);
Configuration.getConfig().stationTemplateUrls.forEach((stationUrl: StationTemplateUrl) => {
if (!Configuration.isUndefined(stationUrl['numberOfStation'])) {
console.error(
}
});
// Read conf
- return Configuration.getConfig().stationTemplateUrls;
+ return Configuration.getConfig()?.stationTemplateUrls;
}
static getWorker(): WorkerConfiguration {
Configuration.warnDeprecatedConfigurationKey(
'useWorkerPool',
- null,
+ undefined,
"Use 'worker' section to define the type of worker process model instead"
);
Configuration.warnDeprecatedConfigurationKey(
'workerProcess',
- null,
+ undefined,
"Use 'worker' section to define the type of worker process model instead"
);
Configuration.warnDeprecatedConfigurationKey(
'workerStartDelay',
- null,
+ undefined,
"Use 'worker' section to define the worker start delay instead"
);
Configuration.warnDeprecatedConfigurationKey(
'chargingStationsPerWorker',
- null,
+ undefined,
"Use 'worker' section to define the number of element(s) per worker instead"
);
Configuration.warnDeprecatedConfigurationKey(
'elementStartDelay',
- null,
+ undefined,
"Use 'worker' section to define the worker's element start delay instead"
);
Configuration.warnDeprecatedConfigurationKey(
'workerPoolMinSize',
- null,
+ undefined,
"Use 'worker' section to define the worker pool minimum size instead"
);
Configuration.warnDeprecatedConfigurationKey(
'workerPoolSize;',
- null,
+ undefined,
"Use 'worker' section to define the worker pool maximum size instead"
);
Configuration.warnDeprecatedConfigurationKey(
'workerPoolMaxSize;',
- null,
+ undefined,
"Use 'worker' section to define the worker pool maximum size instead"
);
Configuration.warnDeprecatedConfigurationKey(
'workerPoolStrategy;',
- null,
+ undefined,
"Use 'worker' section to define the worker pool strategy instead"
);
let workerConfiguration: WorkerConfiguration = {
processType: Configuration.objectHasOwnProperty(Configuration.getConfig(), 'workerProcess')
- ? Configuration.getConfig().workerProcess
+ ? Configuration.getConfig()?.workerProcess
: WorkerProcessType.WORKER_SET,
startDelay: Configuration.objectHasOwnProperty(Configuration.getConfig(), 'workerStartDelay')
- ? Configuration.getConfig().workerStartDelay
+ ? Configuration.getConfig()?.workerStartDelay
: WorkerConstants.DEFAULT_WORKER_START_DELAY,
elementsPerWorker: Configuration.objectHasOwnProperty(
Configuration.getConfig(),
'chargingStationsPerWorker'
)
- ? Configuration.getConfig().chargingStationsPerWorker
+ ? Configuration.getConfig()?.chargingStationsPerWorker
: WorkerConstants.DEFAULT_ELEMENTS_PER_WORKER,
elementStartDelay: Configuration.objectHasOwnProperty(
Configuration.getConfig(),
'elementStartDelay'
)
- ? Configuration.getConfig().elementStartDelay
+ ? Configuration.getConfig()?.elementStartDelay
: WorkerConstants.DEFAULT_ELEMENT_START_DELAY,
poolMinSize: Configuration.objectHasOwnProperty(
Configuration.getConfig(),
'workerPoolMinSize'
)
- ? Configuration.getConfig().workerPoolMinSize
+ ? Configuration.getConfig()?.workerPoolMinSize
: WorkerConstants.DEFAULT_POOL_MIN_SIZE,
poolMaxSize: Configuration.objectHasOwnProperty(
Configuration.getConfig(),
'workerPoolMaxSize'
)
- ? Configuration.getConfig().workerPoolMaxSize
+ ? Configuration.getConfig()?.workerPoolMaxSize
: WorkerConstants.DEFAULT_POOL_MAX_SIZE,
poolStrategy:
- Configuration.getConfig().workerPoolStrategy ?? WorkerChoiceStrategies.ROUND_ROBIN,
+ Configuration.getConfig()?.workerPoolStrategy ?? WorkerChoiceStrategies.ROUND_ROBIN,
};
if (Configuration.objectHasOwnProperty(Configuration.getConfig(), 'worker')) {
- workerConfiguration = { ...workerConfiguration, ...Configuration.getConfig().worker };
+ workerConfiguration = { ...workerConfiguration, ...Configuration.getConfig()?.worker };
}
return workerConfiguration;
}
- static getLogConsole(): boolean {
- Configuration.warnDeprecatedConfigurationKey('consoleLog', null, "Use 'logConsole' instead");
+ static getLogConsole(): boolean | undefined {
+ Configuration.warnDeprecatedConfigurationKey(
+ 'consoleLog',
+ undefined,
+ "Use 'logConsole' instead"
+ );
return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'logConsole')
- ? Configuration.getConfig().logConsole
+ ? Configuration.getConfig()?.logConsole
: false;
}
- static getLogFormat(): string {
+ static getLogFormat(): string | undefined {
return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'logFormat')
- ? Configuration.getConfig().logFormat
+ ? Configuration.getConfig()?.logFormat
: 'simple';
}
- static getLogRotate(): boolean {
+ static getLogRotate(): boolean | undefined {
return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'logRotate')
- ? Configuration.getConfig().logRotate
+ ? Configuration.getConfig()?.logRotate
: true;
}
- static getLogMaxFiles(): number | string | undefined {
+ static getLogMaxFiles(): number | string | false | undefined {
return (
Configuration.objectHasOwnProperty(Configuration.getConfig(), 'logMaxFiles') &&
- Configuration.getConfig().logMaxFiles
+ Configuration.getConfig()?.logMaxFiles
);
}
- static getLogMaxSize(): number | string | undefined {
+ static getLogMaxSize(): number | string | false | undefined {
return (
Configuration.objectHasOwnProperty(Configuration.getConfig(), 'logMaxFiles') &&
- Configuration.getConfig().logMaxSize
+ Configuration.getConfig()?.logMaxSize
);
}
- static getLogLevel(): string {
+ static getLogLevel(): string | undefined {
return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'logLevel')
- ? Configuration.getConfig().logLevel.toLowerCase()
+ ? Configuration.getConfig()?.logLevel?.toLowerCase()
: 'info';
}
- static getLogFile(): string {
+ static getLogFile(): string | undefined {
return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'logFile')
- ? Configuration.getConfig().logFile
+ ? Configuration.getConfig()?.logFile
: 'combined.log';
}
- static getLogErrorFile(): string {
- Configuration.warnDeprecatedConfigurationKey('errorFile', null, "Use 'logErrorFile' instead");
+ static getLogErrorFile(): string | undefined {
+ Configuration.warnDeprecatedConfigurationKey(
+ 'errorFile',
+ undefined,
+ "Use 'logErrorFile' instead"
+ );
return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'logErrorFile')
- ? Configuration.getConfig().logErrorFile
+ ? Configuration.getConfig()?.logErrorFile
: 'error.log';
}
- static getSupervisionUrls(): string | string[] {
+ static getSupervisionUrls(): string | string[] | undefined {
Configuration.warnDeprecatedConfigurationKey(
'supervisionURLs',
- null,
+ undefined,
"Use 'supervisionUrls' instead"
);
!Configuration.isUndefined(Configuration.getConfig()['supervisionURLs']) &&
- (Configuration.getConfig().supervisionUrls = Configuration.getConfig()[
- 'supervisionURLs'
- ] as string[]);
+ (Configuration.getConfig().supervisionUrls = Configuration.getConfig()['supervisionURLs'] as
+ | string
+ | string[]);
// Read conf
- return Configuration.getConfig().supervisionUrls;
+ return Configuration.getConfig()?.supervisionUrls;
}
- static getSupervisionUrlDistribution(): SupervisionUrlDistribution {
+ static getSupervisionUrlDistribution(): SupervisionUrlDistribution | undefined {
Configuration.warnDeprecatedConfigurationKey(
'distributeStationToTenantEqually',
- null,
+ undefined,
"Use 'supervisionUrlDistribution' instead"
);
Configuration.warnDeprecatedConfigurationKey(
'distributeStationsToTenantsEqually',
- null,
+ undefined,
"Use 'supervisionUrlDistribution' instead"
);
return Configuration.objectHasOwnProperty(
Configuration.getConfig(),
'supervisionUrlDistribution'
)
- ? Configuration.getConfig().supervisionUrlDistribution
+ ? Configuration.getConfig()?.supervisionUrlDistribution
: SupervisionUrlDistribution.ROUND_ROBIN;
}
}
// Read the config file
- private static getConfig(): ConfigurationData {
+ private static getConfig(): ConfigurationData | null {
if (!Configuration.configuration) {
try {
Configuration.configuration = JSON.parse(
return Configuration.configuration;
}
- private static getConfigurationFileWatcher(): fs.FSWatcher {
+ private static getConfigurationFileWatcher(): fs.FSWatcher | undefined {
try {
return fs.watch(Configuration.configurationFile, (event, filename): void => {
if (filename && event === 'change') {
}
private static isUndefined(obj: unknown): boolean {
- return typeof obj === 'undefined';
+ return obj === undefined;
}
private static handleFileException(
}
}
}
- ): fs.FSWatcher {
+ ): fs.FSWatcher | undefined {
if (file) {
try {
return fs.watch(file, listener);
filename: Utils.insertAt(
Configuration.getLogErrorFile(),
'-%DATE%',
- Configuration.getLogErrorFile().indexOf('.log')
+ Configuration.getLogErrorFile()?.indexOf('.log')
),
level: 'error',
...(logMaxFiles && { maxFiles: logMaxFiles }),
filename: Utils.insertAt(
Configuration.getLogFile(),
'-%DATE%',
- Configuration.getLogFile().indexOf('.log')
+ Configuration.getLogFile()?.indexOf('.log')
),
...(logMaxFiles && { maxFiles: logMaxFiles }),
...(logMaxSize && { maxSize: logMaxSize }),
return clone<T>(object);
}
- public static isIterable<T>(obj: T): boolean {
- return obj ? typeof obj[Symbol.iterator] === 'function' : false;
+ public static isIterable<T extends Iterable<T>>(obj: T): boolean {
+ return !Utils.isNullOrUndefined(obj) ? typeof obj[Symbol.iterator] === 'function' : false;
}
public static isString(value: unknown): boolean {
workerOptions.poolOptions = workerOptions?.poolOptions ?? ({} as PoolOptions<Worker>);
workerOptions?.messageHandler &&
(workerOptions.poolOptions.messageHandler = workerOptions.messageHandler);
- let workerImplementation: WorkerAbstract<T> = null;
+ let workerImplementation: WorkerAbstract<T> | null = null;
switch (workerProcessType) {
case WorkerProcessType.WORKER_SET:
workerOptions.elementsPerWorker =