public getMaximumPower(stationInfo?: ChargingStationInfo): number {
const localStationInfo = stationInfo ?? this.stationInfo;
// eslint-disable-next-line @typescript-eslint/dot-notation
- return (localStationInfo['maxPower'] as number) ?? localStationInfo.maximumPower;
+ return (
+ (localStationInfo['maxPower' as keyof ChargingStationInfo] as number) ??
+ localStationInfo.maximumPower
+ );
}
public getConnectorMaximumAvailablePower(connectorId: number): number {
if (this.hasEvses) {
for (const evseStatus of this.evses.values()) {
for (const connectorStatus of evseStatus.connectors.values()) {
- if (connectorStatus?.reservation?.[filterKey] === value) {
+ if (connectorStatus?.reservation?.[filterKey as keyof Reservation] === value) {
return connectorStatus.reservation;
}
}
}
} else {
for (const connectorStatus of this.connectors.values()) {
- if (connectorStatus?.reservation?.[filterKey] === value) {
+ if (connectorStatus?.reservation?.[filterKey as keyof Reservation] === value) {
return connectorStatus.reservation;
}
}
templateFile: string,
logMsgToAppend = '',
): void => {
- if (!isUndefined(template[key])) {
+ if (!isUndefined(template[key as keyof ChargingStationTemplate])) {
const logMsg = `Deprecated template key '${key}' usage in file '${templateFile}'${
isNotEmptyString(logMsgToAppend) ? `. ${logMsgToAppend}` : ''
}`;
deprecatedKey: string,
key?: string,
): void => {
- if (!isUndefined(template[deprecatedKey])) {
+ if (!isUndefined(template[deprecatedKey as keyof ChargingStationTemplate])) {
if (!isUndefined(key)) {
- template[key!] = template[deprecatedKey] as unknown;
+ (template as unknown as Record<string, unknown>)[key!] =
+ template[deprecatedKey as keyof ChargingStationTemplate];
}
- delete template[deprecatedKey];
+ delete template[deprecatedKey as keyof ChargingStationTemplate];
}
};
*
* @param data - workerData
*/
-const startChargingStation = (data: ChargingStationWorkerData): void => {
- new ChargingStation(data.index, data.templateFile).start();
+const startChargingStation = (data?: ChargingStationWorkerData): void => {
+ new ChargingStation(data!.index, data!.templateFile).start();
};
class ChargingStationWorker extends AsyncResource {
parentPort?.on('message', (message: WorkerMessage<ChargingStationWorkerData>) => {
if (message.id === WorkerMessageEvents.startWorkerElement) {
this.runInAsyncScope(
- startChargingStation.bind(this) as (data: ChargingStationWorkerData) => void,
+ startChargingStation.bind(this) as (data?: ChargingStationWorkerData) => void,
this,
message.data,
);
],
]);
this.chargingStation = chargingStation;
- this.onmessage = this.requestHandler.bind(this) as (message: MessageEvent) => void;
- this.onmessageerror = this.messageErrorHandler.bind(this) as (message: MessageEvent) => void;
+ this.onmessage = this.requestHandler.bind(this) as (message: unknown) => void;
+ this.onmessageerror = this.messageErrorHandler.bind(this) as (message: unknown) => void;
}
private async requestHandler(messageEvent: MessageEvent): Promise<void> {
constructor(uiService: AbstractUIService) {
super();
this.uiService = uiService;
- this.onmessage = this.responseHandler.bind(this) as (message: MessageEvent) => void;
- this.onmessageerror = this.messageErrorHandler.bind(this) as (message: MessageEvent) => void;
+ this.onmessage = this.responseHandler.bind(this) as (message: unknown) => void;
+ this.onmessageerror = this.messageErrorHandler.bind(this) as (message: unknown) => void;
this.responses = new Map<string, Responses>();
}
// }
super(OCPPVersion.VERSION_16);
this.incomingRequestHandlers = new Map<OCPP16IncomingRequestCommand, IncomingRequestHandler>([
- [OCPP16IncomingRequestCommand.RESET, this.handleRequestReset.bind(this)],
- [OCPP16IncomingRequestCommand.CLEAR_CACHE, this.handleRequestClearCache.bind(this)],
- [OCPP16IncomingRequestCommand.UNLOCK_CONNECTOR, this.handleRequestUnlockConnector.bind(this)],
+ [
+ OCPP16IncomingRequestCommand.RESET,
+ this.handleRequestReset.bind(this) as unknown as IncomingRequestHandler,
+ ],
+ [
+ OCPP16IncomingRequestCommand.CLEAR_CACHE,
+ this.handleRequestClearCache.bind(this) as IncomingRequestHandler,
+ ],
+ [
+ OCPP16IncomingRequestCommand.UNLOCK_CONNECTOR,
+ this.handleRequestUnlockConnector.bind(this) as unknown as IncomingRequestHandler,
+ ],
[
OCPP16IncomingRequestCommand.GET_CONFIGURATION,
- this.handleRequestGetConfiguration.bind(this),
+ this.handleRequestGetConfiguration.bind(this) as IncomingRequestHandler,
],
[
OCPP16IncomingRequestCommand.CHANGE_CONFIGURATION,
- this.handleRequestChangeConfiguration.bind(this),
+ this.handleRequestChangeConfiguration.bind(this) as unknown as IncomingRequestHandler,
],
[
OCPP16IncomingRequestCommand.GET_COMPOSITE_SCHEDULE,
- this.handleRequestGetCompositeSchedule.bind(this),
+ this.handleRequestGetCompositeSchedule.bind(this) as unknown as IncomingRequestHandler,
],
[
OCPP16IncomingRequestCommand.SET_CHARGING_PROFILE,
- this.handleRequestSetChargingProfile.bind(this),
+ this.handleRequestSetChargingProfile.bind(this) as unknown as IncomingRequestHandler,
],
[
OCPP16IncomingRequestCommand.CLEAR_CHARGING_PROFILE,
- this.handleRequestClearChargingProfile.bind(this),
+ this.handleRequestClearChargingProfile.bind(this) as IncomingRequestHandler,
],
[
OCPP16IncomingRequestCommand.CHANGE_AVAILABILITY,
- this.handleRequestChangeAvailability.bind(this),
+ this.handleRequestChangeAvailability.bind(this) as unknown as IncomingRequestHandler,
],
[
OCPP16IncomingRequestCommand.REMOTE_START_TRANSACTION,
- this.handleRequestRemoteStartTransaction.bind(this),
+ this.handleRequestRemoteStartTransaction.bind(this) as unknown as IncomingRequestHandler,
],
[
OCPP16IncomingRequestCommand.REMOTE_STOP_TRANSACTION,
- this.handleRequestRemoteStopTransaction.bind(this),
+ this.handleRequestRemoteStopTransaction.bind(this) as unknown as IncomingRequestHandler,
+ ],
+ [
+ OCPP16IncomingRequestCommand.GET_DIAGNOSTICS,
+ this.handleRequestGetDiagnostics.bind(this) as IncomingRequestHandler,
+ ],
+ [
+ OCPP16IncomingRequestCommand.TRIGGER_MESSAGE,
+ this.handleRequestTriggerMessage.bind(this) as unknown as IncomingRequestHandler,
+ ],
+ [
+ OCPP16IncomingRequestCommand.DATA_TRANSFER,
+ this.handleRequestDataTransfer.bind(this) as unknown as IncomingRequestHandler,
+ ],
+ [
+ OCPP16IncomingRequestCommand.UPDATE_FIRMWARE,
+ this.handleRequestUpdateFirmware.bind(this) as unknown as IncomingRequestHandler,
+ ],
+ [
+ OCPP16IncomingRequestCommand.RESERVE_NOW,
+ this.handleRequestReserveNow.bind(this) as unknown as IncomingRequestHandler,
],
- [OCPP16IncomingRequestCommand.GET_DIAGNOSTICS, this.handleRequestGetDiagnostics.bind(this)],
- [OCPP16IncomingRequestCommand.TRIGGER_MESSAGE, this.handleRequestTriggerMessage.bind(this)],
- [OCPP16IncomingRequestCommand.DATA_TRANSFER, this.handleRequestDataTransfer.bind(this)],
- [OCPP16IncomingRequestCommand.UPDATE_FIRMWARE, this.handleRequestUpdateFirmware.bind(this)],
- [OCPP16IncomingRequestCommand.RESERVE_NOW, this.handleRequestReserveNow.bind(this)],
[
OCPP16IncomingRequestCommand.CANCEL_RESERVATION,
- this.handleRequestCancelReservation.bind(this),
+ this.handleRequestCancelReservation.bind(this) as unknown as IncomingRequestHandler,
],
]);
this.jsonSchemas = new Map<OCPP16IncomingRequestCommand, JSONSchemaType<JsonObject>>([
// }
super(OCPPVersion.VERSION_16);
this.responseHandlers = new Map<OCPP16RequestCommand, ResponseHandler>([
- [OCPP16RequestCommand.BOOT_NOTIFICATION, this.handleResponseBootNotification.bind(this)],
- [OCPP16RequestCommand.HEARTBEAT, this.emptyResponseHandler.bind(this)],
- [OCPP16RequestCommand.AUTHORIZE, this.handleResponseAuthorize.bind(this)],
- [OCPP16RequestCommand.START_TRANSACTION, this.handleResponseStartTransaction.bind(this)],
- [OCPP16RequestCommand.STOP_TRANSACTION, this.handleResponseStopTransaction.bind(this)],
- [OCPP16RequestCommand.STATUS_NOTIFICATION, this.emptyResponseHandler.bind(this)],
- [OCPP16RequestCommand.METER_VALUES, this.emptyResponseHandler.bind(this)],
- [OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, this.emptyResponseHandler.bind(this)],
- [OCPP16RequestCommand.DATA_TRANSFER, this.emptyResponseHandler.bind(this)],
- [OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION, this.emptyResponseHandler.bind(this)],
+ [
+ OCPP16RequestCommand.BOOT_NOTIFICATION,
+ this.handleResponseBootNotification.bind(this) as ResponseHandler,
+ ],
+ [OCPP16RequestCommand.HEARTBEAT, this.emptyResponseHandler.bind(this) as ResponseHandler],
+ [OCPP16RequestCommand.AUTHORIZE, this.handleResponseAuthorize.bind(this) as ResponseHandler],
+ [
+ OCPP16RequestCommand.START_TRANSACTION,
+ this.handleResponseStartTransaction.bind(this) as ResponseHandler,
+ ],
+ [
+ OCPP16RequestCommand.STOP_TRANSACTION,
+ this.handleResponseStopTransaction.bind(this) as ResponseHandler,
+ ],
+ [
+ OCPP16RequestCommand.STATUS_NOTIFICATION,
+ this.emptyResponseHandler.bind(this) as ResponseHandler,
+ ],
+ [OCPP16RequestCommand.METER_VALUES, this.emptyResponseHandler.bind(this) as ResponseHandler],
+ [
+ OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
+ this.emptyResponseHandler.bind(this) as ResponseHandler,
+ ],
+ [OCPP16RequestCommand.DATA_TRANSFER, this.emptyResponseHandler.bind(this) as ResponseHandler],
+ [
+ OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION,
+ this.emptyResponseHandler.bind(this) as ResponseHandler,
+ ],
]);
this.jsonSchemas = new Map<OCPP16RequestCommand, JSONSchemaType<JsonObject>>([
[
const phaseValue = `L${phase}-N`;
meterValue.sampledValue.push(
OCPP16ServiceUtils.buildSampledValue(
- (powerPerPhaseSampledValueTemplates[`L${phase}`] as SampledValueTemplate) ??
- powerSampledValueTemplate,
- powerMeasurandValues[`L${phase}`] as number,
+ powerPerPhaseSampledValueTemplates[
+ `L${phase}` as keyof MeasurandPerPhaseSampledValueTemplates
+ ]! ?? powerSampledValueTemplate,
+ powerMeasurandValues[`L${phase}` as keyof MeasurandPerPhaseSampledValueTemplates],
undefined,
phaseValue as OCPP16MeterValuePhase,
),
const phaseValue = `L${phase}`;
meterValue.sampledValue.push(
OCPP16ServiceUtils.buildSampledValue(
- (currentPerPhaseSampledValueTemplates[phaseValue] as SampledValueTemplate) ??
- currentSampledValueTemplate,
- currentMeasurandValues[phaseValue] as number,
+ currentPerPhaseSampledValueTemplates[
+ phaseValue as keyof MeasurandPerPhaseSampledValueTemplates
+ ]! ?? currentSampledValueTemplate,
+ currentMeasurandValues[phaseValue as keyof MeasurandPerPhaseSampledValueTemplates],
undefined,
phaseValue as OCPP16MeterValuePhase,
),
// }
super(OCPPVersion.VERSION_20);
this.responseHandlers = new Map<OCPP20RequestCommand, ResponseHandler>([
- [OCPP20RequestCommand.BOOT_NOTIFICATION, this.handleResponseBootNotification.bind(this)],
- [OCPP20RequestCommand.HEARTBEAT, this.emptyResponseHandler.bind(this)],
- [OCPP20RequestCommand.STATUS_NOTIFICATION, this.emptyResponseHandler.bind(this)],
+ [
+ OCPP20RequestCommand.BOOT_NOTIFICATION,
+ this.handleResponseBootNotification.bind(this) as ResponseHandler,
+ ],
+ [OCPP20RequestCommand.HEARTBEAT, this.emptyResponseHandler.bind(this) as ResponseHandler],
+ [
+ OCPP20RequestCommand.STATUS_NOTIFICATION,
+ this.emptyResponseHandler.bind(this) as ResponseHandler,
+ ],
]);
this.jsonSchemas = new Map<OCPP20RequestCommand, JSONSchemaType<JsonObject>>([
[
ErrorType,
FileType,
IncomingRequestCommand,
- type JsonObject,
type JsonType,
MessageTrigger,
MessageType,
}
public static convertDateToISOString<T extends JsonType>(obj: T): void {
- for (const key in obj as JsonObject) {
+ for (const key in obj) {
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
if (obj![key] instanceof Date) {
- obj![key] = (obj![key] as Date).toISOString();
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
+ (obj![key] as string) = (obj![key] as Date).toISOString();
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
} else if (obj![key] !== null && typeof obj![key] === 'object') {
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
OCPPServiceUtils.convertDateToISOString<T>(obj![key] as T);
}
}
body ?? Constants.EMPTY_FREEZED_OBJECT,
),
)
- .then((protocolResponse: ProtocolResponse) => {
+ .then((protocolResponse: ProtocolResponse | undefined) => {
if (!isNullOrUndefined(protocolResponse)) {
- this.sendResponse(protocolResponse);
+ this.sendResponse(protocolResponse!);
}
})
.catch(Constants.EMPTY_FUNCTION);
this.uiServices
.get(version)
?.requestHandler(request)
- .then((protocolResponse: ProtocolResponse) => {
+ .then((protocolResponse: ProtocolResponse | undefined) => {
if (!isNullOrUndefined(protocolResponse)) {
- this.sendResponse(protocolResponse);
+ this.sendResponse(protocolResponse!);
}
})
.catch(Constants.EMPTY_FUNCTION);
const moduleName = 'AbstractUIService';
export abstract class AbstractUIService {
- protected static readonly ProcedureNameToBroadCastChannelProcedureNameMapping: Omit<
- Record<ProcedureName, BroadcastChannelProcedureName>,
- | ProcedureName.START_SIMULATOR
- | ProcedureName.STOP_SIMULATOR
- | ProcedureName.LIST_CHARGING_STATIONS
- > = {
- [ProcedureName.START_CHARGING_STATION]: BroadcastChannelProcedureName.START_CHARGING_STATION,
- [ProcedureName.STOP_CHARGING_STATION]: BroadcastChannelProcedureName.STOP_CHARGING_STATION,
- [ProcedureName.CLOSE_CONNECTION]: BroadcastChannelProcedureName.CLOSE_CONNECTION,
- [ProcedureName.OPEN_CONNECTION]: BroadcastChannelProcedureName.OPEN_CONNECTION,
- [ProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR]:
+ protected static readonly ProcedureNameToBroadCastChannelProcedureNameMapping = new Map<
+ ProcedureName,
+ BroadcastChannelProcedureName
+ >([
+ [ProcedureName.START_CHARGING_STATION, BroadcastChannelProcedureName.START_CHARGING_STATION],
+ [ProcedureName.STOP_CHARGING_STATION, BroadcastChannelProcedureName.STOP_CHARGING_STATION],
+ [ProcedureName.CLOSE_CONNECTION, BroadcastChannelProcedureName.CLOSE_CONNECTION],
+ [ProcedureName.OPEN_CONNECTION, BroadcastChannelProcedureName.OPEN_CONNECTION],
+ [
+ ProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
BroadcastChannelProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
- [ProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR]:
+ ],
+ [
+ ProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
BroadcastChannelProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
- [ProcedureName.SET_SUPERVISION_URL]: BroadcastChannelProcedureName.SET_SUPERVISION_URL,
- [ProcedureName.START_TRANSACTION]: BroadcastChannelProcedureName.START_TRANSACTION,
- [ProcedureName.STOP_TRANSACTION]: BroadcastChannelProcedureName.STOP_TRANSACTION,
- [ProcedureName.AUTHORIZE]: BroadcastChannelProcedureName.AUTHORIZE,
- [ProcedureName.BOOT_NOTIFICATION]: BroadcastChannelProcedureName.BOOT_NOTIFICATION,
- [ProcedureName.STATUS_NOTIFICATION]: BroadcastChannelProcedureName.STATUS_NOTIFICATION,
- [ProcedureName.HEARTBEAT]: BroadcastChannelProcedureName.HEARTBEAT,
- [ProcedureName.METER_VALUES]: BroadcastChannelProcedureName.METER_VALUES,
- [ProcedureName.DATA_TRANSFER]: BroadcastChannelProcedureName.DATA_TRANSFER,
- [ProcedureName.DIAGNOSTICS_STATUS_NOTIFICATION]:
+ ],
+ [ProcedureName.SET_SUPERVISION_URL, BroadcastChannelProcedureName.SET_SUPERVISION_URL],
+ [ProcedureName.START_TRANSACTION, BroadcastChannelProcedureName.START_TRANSACTION],
+ [ProcedureName.STOP_TRANSACTION, BroadcastChannelProcedureName.STOP_TRANSACTION],
+ [ProcedureName.AUTHORIZE, BroadcastChannelProcedureName.AUTHORIZE],
+ [ProcedureName.BOOT_NOTIFICATION, BroadcastChannelProcedureName.BOOT_NOTIFICATION],
+ [ProcedureName.STATUS_NOTIFICATION, BroadcastChannelProcedureName.STATUS_NOTIFICATION],
+ [ProcedureName.HEARTBEAT, BroadcastChannelProcedureName.HEARTBEAT],
+ [ProcedureName.METER_VALUES, BroadcastChannelProcedureName.METER_VALUES],
+ [ProcedureName.DATA_TRANSFER, BroadcastChannelProcedureName.DATA_TRANSFER],
+ [
+ ProcedureName.DIAGNOSTICS_STATUS_NOTIFICATION,
BroadcastChannelProcedureName.DIAGNOSTICS_STATUS_NOTIFICATION,
- [ProcedureName.FIRMWARE_STATUS_NOTIFICATION]:
+ ],
+ [
+ ProcedureName.FIRMWARE_STATUS_NOTIFICATION,
BroadcastChannelProcedureName.FIRMWARE_STATUS_NOTIFICATION,
- };
+ ],
+ ]);
protected readonly requestHandlers: Map<ProcedureName, ProtocolRequestHandler>;
private readonly version: ProtocolVersion;
): void {
this.sendBroadcastChannelRequest(
uuid,
- AbstractUIService.ProcedureNameToBroadCastChannelProcedureNameMapping[
- procedureName
- ] as BroadcastChannelProcedureName,
+ AbstractUIService.ProcedureNameToBroadCastChannelProcedureNameMapping.get(procedureName)!,
payload,
);
}
import { AbstractUIService } from './AbstractUIService';
-import { type ProcedureName, type ProtocolRequestHandler, ProtocolVersion } from '../../../types';
+import { type ProtocolRequestHandler, ProtocolVersion } from '../../../types';
import type { AbstractUIServer } from '../AbstractUIServer';
export class UIService001 extends AbstractUIService {
constructor(uiServer: AbstractUIServer) {
super(uiServer, ProtocolVersion['0.0.1']);
- for (const procedureName in AbstractUIService.ProcedureNameToBroadCastChannelProcedureNameMapping) {
+ for (const procedureName of AbstractUIService.ProcedureNameToBroadCastChannelProcedureNameMapping.keys()) {
this.requestHandlers.set(
- procedureName as ProcedureName,
+ procedureName,
this.handleProtocolRequest.bind(this) as ProtocolRequestHandler,
);
}
"Use 'stationTemplateUrls' instead",
);
// eslint-disable-next-line @typescript-eslint/dot-notation
- !isUndefined(Configuration.getConfigurationData()!['stationTemplateURLs']) &&
+ !isUndefined(
+ Configuration.getConfigurationData()!['stationTemplateURLs' as keyof ConfigurationData],
+ ) &&
(Configuration.getConfigurationData()!.stationTemplateUrls =
Configuration.getConfigurationData()![
// eslint-disable-next-line @typescript-eslint/dot-notation
- 'stationTemplateURLs'
+ 'stationTemplateURLs' as keyof ConfigurationData
] as StationTemplateUrl[]);
Configuration.getConfigurationData()!.stationTemplateUrls.forEach(
(stationTemplateUrl: StationTemplateUrl) => {
// eslint-disable-next-line @typescript-eslint/dot-notation
- if (!isUndefined(stationTemplateUrl['numberOfStation'])) {
+ if (!isUndefined(stationTemplateUrl['numberOfStation' as keyof StationTemplateUrl])) {
console.error(
`${chalk.green(Configuration.logPrefix())} ${chalk.red(
`Deprecated configuration key 'numberOfStation' usage for template file '${stationTemplateUrl.file}' in 'stationTemplateUrls'. Use 'numberOfStations' instead`,
"Use 'supervisionUrls' instead",
);
// eslint-disable-next-line @typescript-eslint/dot-notation
- if (!isUndefined(Configuration.getConfigurationData()!['supervisionURLs'])) {
+ if (
+ !isUndefined(
+ Configuration.getConfigurationData()!['supervisionURLs' as keyof ConfigurationData],
+ )
+ ) {
Configuration.getConfigurationData()!.supervisionUrls = Configuration.getConfigurationData()![
// eslint-disable-next-line @typescript-eslint/dot-notation
- 'supervisionURLs'
+ 'supervisionURLs' as keyof ConfigurationData
] as string | string[];
}
return Configuration.getConfigurationData()?.supervisionUrls;
) {
if (
sectionName &&
- !isUndefined(Configuration.getConfigurationData()![sectionName]) &&
+ !isUndefined(Configuration.getConfigurationData()![sectionName as keyof ConfigurationData]) &&
!isUndefined(
- (Configuration.getConfigurationData()![sectionName] as Record<string, unknown>)[key],
+ (
+ Configuration.getConfigurationData()![sectionName as keyof ConfigurationData] as Record<
+ string,
+ unknown
+ >
+ )[key],
)
) {
console.error(
}`,
)}`,
);
- } else if (!isUndefined(Configuration.getConfigurationData()![key])) {
+ } else if (
+ !isUndefined(Configuration.getConfigurationData()![key as keyof ConfigurationData])
+ ) {
console.error(
`${chalk.green(Configuration.logPrefix())} ${chalk.red(
`Deprecated configuration key '${key}' usage${
export const logger = createLogger({
silent: !logConfiguration.enabled,
level: logConfiguration.level,
- format: format.combine(format.splat(), (format[logConfiguration.format!] as FormatWrap)()),
+ format: format.combine(
+ format.splat(),
+ (format[logConfiguration.format! as keyof FormatWrap] as FormatWrap)(),
+ ),
transports,
});
if (logConfiguration.console) {
logger.add(
new TransportType.Console({
- format: format.combine(format.splat(), (format[logConfiguration.format!] as FormatWrap)()),
+ format: format.combine(
+ format.splat(),
+ (format[logConfiguration.format! as keyof FormatWrap] as FormatWrap)(),
+ ),
}),
);
}
};
export const isIterable = <T>(obj: T): boolean => {
- return !isNullOrUndefined(obj) ? typeof obj[Symbol.iterator] === 'function' : false;
+ return !isNullOrUndefined(obj) ? typeof obj[Symbol.iterator as keyof T] === 'function' : false;
};
const isString = (value: unknown): boolean => {
return '(For applications)';
}
}
- if (!isUndefined(WebSocketCloseEventStatusString[code])) {
- return WebSocketCloseEventStatusString[code] as string;
+ if (
+ !isUndefined(
+ WebSocketCloseEventStatusString[code as keyof typeof WebSocketCloseEventStatusString],
+ )
+ ) {
+ return WebSocketCloseEventStatusString[code as keyof typeof WebSocketCloseEventStatusString];
}
return '(Unknown)';
};
import type { EventEmitter } from 'node:events';
import { existsSync } from 'node:fs';
-import type { Worker } from 'node:worker_threads';
-import type { ErrorHandler, ExitHandler, PoolEmitter, PoolInfo } from 'poolifier';
+import type { PoolEmitter, PoolInfo } from 'poolifier';
import { WorkerConstants } from './WorkerConstants';
import type { SetInfo, WorkerData, WorkerOptions } from './WorkerTypes';
}
this.workerScript = workerScript;
this.workerOptions = workerOptions;
- this.workerOptions.poolOptions?.messageHandler?.bind(this);
- this.workerOptions.poolOptions!.errorHandler = (
- this.workerOptions?.poolOptions?.errorHandler ?? defaultErrorHandler
- ).bind(this) as ErrorHandler<Worker>;
- this.workerOptions.poolOptions?.onlineHandler?.bind(this);
- this.workerOptions.poolOptions!.exitHandler = (
- this.workerOptions?.poolOptions?.exitHandler ?? defaultExitHandler
- ).bind(this) as ExitHandler<Worker>;
+ this.workerOptions.poolOptions!.errorHandler =
+ this.workerOptions.poolOptions?.errorHandler ?? defaultErrorHandler;
+ this.workerOptions.poolOptions!.exitHandler =
+ this.workerOptions.poolOptions?.exitHandler ?? defaultExitHandler;
}
/**
import { sleep } from './WorkerUtils';
export class WorkerSet extends WorkerAbstract<WorkerData> {
- public readonly emitter: EventEmitter;
+ public readonly emitter!: EventEmitter;
private readonly workerSet: Set<WorkerSetElement>;
/**
...this.workerOptions.poolOptions,
};
this.workerSet = new Set<WorkerSetElement>();
- if (this.workerOptions?.poolOptions?.enableEvents) {
+ if (this.workerOptions.poolOptions?.enableEvents) {
this.emitter = new EventEmitter();
}
}
});
worker.on(
'message',
- this.workerOptions?.poolOptions?.messageHandler ?? WorkerConstants.EMPTY_FUNCTION,
+ this.workerOptions.poolOptions?.messageHandler ?? WorkerConstants.EMPTY_FUNCTION,
);
worker.on(
'error',
- this.workerOptions?.poolOptions?.errorHandler ?? WorkerConstants.EMPTY_FUNCTION,
+ this.workerOptions.poolOptions?.errorHandler ?? WorkerConstants.EMPTY_FUNCTION,
);
worker.on('error', (error) => {
this.emitter?.emit(WorkerSetEvents.error, error);
- if (this.workerOptions?.poolOptions?.restartWorkerOnError) {
+ if (this.workerOptions.poolOptions?.restartWorkerOnError) {
this.addWorkerSetElement();
}
});
worker.on(
'online',
- this.workerOptions?.poolOptions?.onlineHandler ?? WorkerConstants.EMPTY_FUNCTION,
+ this.workerOptions.poolOptions?.onlineHandler ?? WorkerConstants.EMPTY_FUNCTION,
);
worker.on(
'exit',
- this.workerOptions?.poolOptions?.exitHandler ?? WorkerConstants.EMPTY_FUNCTION,
+ this.workerOptions.poolOptions?.exitHandler ?? WorkerConstants.EMPTY_FUNCTION,
);
worker.once('exit', () =>
this.removeWorkerSetElement(this.getWorkerSetElementByWorker(worker)!),
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
- // "strict": true, /* Enable all strict type-checking options. */
+ "strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
- "strictNullChecks": true, /* Enable strict null checks. */
+ // "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */