ChargingStationData,
ChargingStationWorkerData,
ChargingStationWorkerMessage,
+ ChargingStationWorkerMessageData,
ChargingStationWorkerMessageEvents,
} from '../types/ChargingStationWorker';
import { StationTemplateUrl } from '../types/ConfigurationData';
workerChoiceStrategy: Configuration.getWorker().poolStrategy,
},
messageHandler: this.messageHandler.bind(this) as (
- msg: ChargingStationWorkerMessage<ChargingStationData | Statistics>
+ msg: ChargingStationWorkerMessage<ChargingStationWorkerMessageData>
) => void,
}
));
}
private messageHandler(
- msg: ChargingStationWorkerMessage<ChargingStationData | Statistics>
+ msg: ChargingStationWorkerMessage<ChargingStationWorkerMessageData>
): void {
// logger.debug(
// `${this.logPrefix()} ${moduleName}.messageHandler: Worker channel message received: ${JSON.stringify(
);
this.getConnectorStatus(connectorId).chargingProfiles = [];
}
- if (!Array.isArray(this.getConnectorStatus(connectorId).chargingProfiles)) {
+ if (Array.isArray(this.getConnectorStatus(connectorId).chargingProfiles) === false) {
logger.error(
`${this.logPrefix()} Trying to set a charging profile on connectorId ${connectorId} with an improper attribute type for the charging profiles array, applying proper type initialization`
);
let errMsg: string;
try {
const request = JSON.parse(data.toString()) as IncomingRequest | Response | ErrorResponse;
- if (Utils.isIterable(request)) {
+ if (Array.isArray(request) === true) {
[messageType, messageId] = request;
// Check the type of message
switch (messageType) {
}
// Respond
cachedRequest = this.requests.get(messageId);
- if (Utils.isIterable(cachedRequest)) {
+ if (Array.isArray(cachedRequest) === true) {
[responseCallback, , requestCommandName, requestPayload] = cachedRequest;
} else {
throw new OCPPError(
ErrorType.PROTOCOL_ERROR,
- `Cached request for message id ${messageId} response is not iterable`,
+ `Cached request for message id ${messageId} response is not an array`,
null,
cachedRequest as unknown as JsonType
);
);
}
cachedRequest = this.requests.get(messageId);
- if (Utils.isIterable(cachedRequest)) {
+ if (Array.isArray(cachedRequest) === true) {
[, errorCallback, requestCommandName] = cachedRequest;
} else {
throw new OCPPError(
ErrorType.PROTOCOL_ERROR,
- `Cached request for message id ${messageId} error response is not iterable`,
+ `Cached request for message id ${messageId} error response is not an array`,
null,
cachedRequest as unknown as JsonType
);
}
parentPort.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
} else {
- throw new OCPPError(ErrorType.PROTOCOL_ERROR, 'Incoming message is not iterable', null, {
+ throw new OCPPError(ErrorType.PROTOCOL_ERROR, 'Incoming message is not an array', null, {
payload: request,
});
}
if (this.isResponse(messageEvent.data)) {
return;
}
+ if (Array.isArray(messageEvent.data) === false) {
+ throw new BaseError('Worker broadcast channel protocol request is not an array');
+ }
const [uuid, command, requestPayload] = messageEvent.data as BroadcastChannelRequest;
+import BaseError from '../exception/BaseError';
import { BroadcastChannelResponse, MessageEvent } from '../types/WorkerBroadcastChannel';
import logger from '../utils/Logger';
import type AbstractUIService from './ui-server/ui-services/AbstractUIService';
if (this.isRequest(messageEvent.data)) {
return;
}
+ if (Array.isArray(messageEvent.data) === false) {
+ throw new BaseError('Worker broadcast channel protocol response is not an array');
+ }
const [uuid, responsePayload] = messageEvent.data as BroadcastChannelResponse;
this.uiService.sendResponse(uuid, responsePayload);
ResponseStatus,
} from '../../../types/UIProtocol';
import logger from '../../../utils/Logger';
-import Utils from '../../../utils/Utils';
import Bootstrap from '../../Bootstrap';
import UIServiceWorkerBroadcastChannel from '../../UIServiceWorkerBroadcastChannel';
import type { AbstractUIServer } from '../AbstractUIServer';
const data = JSON.parse(rawData.toString()) as JsonType[];
- if (Utils.isIterable(data) === false) {
- throw new BaseError('UI protocol request is not iterable');
+ if (Array.isArray(data) === false) {
+ throw new BaseError('UI protocol request is not an array');
}
if (data.length !== 3) {
import ChargingStationInfo from './ChargingStationInfo';
import { ConnectorStatus } from './ConnectorStatus';
import { JsonObject } from './JsonType';
+import Statistics from './Statistics';
import { WorkerData, WorkerMessage, WorkerMessageEvents } from './Worker';
export interface ChargingStationWorkerOptions extends JsonObject {
...ChargingStationMessageEvents,
};
+export type ChargingStationWorkerMessageData = ChargingStationData | Statistics;
+
export interface ChargingStationWorkerMessage<T extends WorkerData>
extends Omit<WorkerMessage<T>, 'id'> {
id: ChargingStationWorkerMessageEvents;
private responseHandler(messageEvent: MessageEvent<string>): void {
const data = JSON.parse(messageEvent.data) as ProtocolResponse;
- if (Utils.isIterable(data) === false) {
- throw new Error('Response not iterable: ' + JSON.stringify(data, null, 2));
+ if (Array.isArray(data) === false) {
+ throw new Error('Response not an array: ' + JSON.stringify(data, null, 2));
}
const [uuid, response] = data;
}
private static isObject(item): boolean {
- return item && typeof item === 'object' && !Array.isArray(item);
+ return item && typeof item === 'object' && Array.isArray(item) === false;
}
private static deepMerge(target: object, ...sources: object[]): object {