import { ErrorType } from '../types/ocpp/ErrorType';
import { FileType } from '../types/FileType';
import FileUtils from '../utils/FileUtils';
-import { JsonObject } from '../types/JsonType';
+import { JsonType } from '../types/JsonType';
import { MessageType } from '../types/ocpp/MessageType';
import OCPP16IncomingRequestService from './ocpp/1.6/OCPP16IncomingRequestService';
import OCPP16RequestService from './ocpp/1.6/OCPP16RequestService';
let messageType: number;
let messageId: string;
let commandName: IncomingRequestCommand;
- let commandPayload: JsonObject;
+ let commandPayload: JsonType;
let errorType: ErrorType;
let errorMessage: string;
- let errorDetails: JsonObject;
- let responseCallback: (payload: JsonObject, requestPayload: JsonObject) => void;
+ let errorDetails: JsonType;
+ let responseCallback: (payload: JsonType, requestPayload: JsonType) => void;
let errorCallback: (error: OCPPError, requestStatistic?: boolean) => void;
let requestCommandName: RequestCommand | IncomingRequestCommand;
- let requestPayload: JsonObject;
+ let requestPayload: JsonType;
let cachedRequest: CachedRequest;
let errMsg: string;
try {
ErrorType.PROTOCOL_ERROR,
`Cached request for message id ${messageId} response is not iterable`,
null,
- cachedRequest as unknown as JsonObject
+ cachedRequest as unknown as JsonType
);
}
logger.debug(
ErrorType.PROTOCOL_ERROR,
`Cached request for message id ${messageId} error response is not iterable`,
null,
- cachedRequest as unknown as JsonObject
+ cachedRequest as unknown as JsonType
);
}
logger.debug(
import { DefaultResponse } from '../../../types/ocpp/Responses';
import { ErrorType } from '../../../types/ocpp/ErrorType';
import { IncomingRequestHandler } from '../../../types/ocpp/Requests';
-import { JsonObject } from '../../../types/JsonType';
+import { JsonType } from '../../../types/JsonType';
import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode';
import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus';
import { OCPP16DiagnosticsStatus } from '../../../types/ocpp/1.6/DiagnosticsStatus';
public async incomingRequestHandler(
messageId: string,
commandName: OCPP16IncomingRequestCommand,
- commandPayload: JsonObject
+ commandPayload: JsonType
): Promise<void> {
- let response: JsonObject;
+ let response: JsonType;
if (
this.chargingStation.getOcppStrictCompliance() &&
this.chargingStation.isInPendingState() &&
// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
+import { JsonObject, JsonType } from '../../../types/JsonType';
+
import type ChargingStation from '../../ChargingStation';
import Constants from '../../../utils/Constants';
import { ErrorType } from '../../../types/ocpp/ErrorType';
-import { JsonObject } from '../../../types/JsonType';
import { OCPP16RequestCommand } from '../../../types/ocpp/1.6/Requests';
import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
import OCPPError from '../../../exception/OCPPError';
super(chargingStation, ocppResponseService);
}
- public async requestHandler<Request extends JsonObject, Response extends JsonObject>(
+ public async requestHandler<Request extends JsonType, Response extends JsonType>(
commandName: OCPP16RequestCommand,
- commandParams?: JsonObject,
+ commandParams?: JsonType,
params?: RequestParams
): Promise<Response> {
if (Object.values(OCPP16RequestCommand).includes(commandName)) {
);
}
- private buildRequestPayload<Request extends JsonObject>(
+ private buildRequestPayload<Request extends JsonType>(
commandName: OCPP16RequestCommand,
- commandParams?: JsonObject
+ commandParams?: JsonType
): Request {
let connectorId: number;
+ commandParams = commandParams as JsonObject;
switch (commandName) {
case OCPP16RequestCommand.AUTHORIZE:
return {
import type ChargingStation from '../../ChargingStation';
import { ErrorType } from '../../../types/ocpp/ErrorType';
-import { JsonObject } from '../../../types/JsonType';
+import { JsonType } from '../../../types/JsonType';
import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode';
import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus';
import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
public async responseHandler(
commandName: OCPP16RequestCommand,
- payload: JsonObject,
- requestPayload: JsonObject
+ payload: JsonType,
+ requestPayload: JsonType
): Promise<void> {
if (
this.chargingStation.isRegistered() ||
import type ChargingStation from '../ChargingStation';
import { HandleErrorParams } from '../../types/Error';
import { IncomingRequestCommand } from '../../types/ocpp/Requests';
-import { JsonObject } from '../../types/JsonType';
+import { JsonType } from '../../types/JsonType';
import logger from '../../utils/Logger';
export default abstract class OCPPIncomingRequestService {
public abstract incomingRequestHandler(
messageId: string,
commandName: IncomingRequestCommand,
- commandPayload: JsonObject
+ commandPayload: JsonType
): Promise<void>;
}
RequestParams,
ResponseType,
} from '../../types/ocpp/Requests';
+import { JsonObject, JsonType } from '../../types/JsonType';
import type ChargingStation from '../ChargingStation';
import Constants from '../../utils/Constants';
import { EmptyObject } from '../../types/EmptyObject';
import { ErrorType } from '../../types/ocpp/ErrorType';
import { HandleErrorParams } from '../../types/Error';
-import { JsonObject } from '../../types/JsonType';
import { MessageType } from '../../types/ocpp/MessageType';
import OCPPError from '../../exception/OCPPError';
import type OCPPResponseService from './OCPPResponseService';
public async sendResponse(
messageId: string,
- messagePayload: JsonObject,
+ messagePayload: JsonType,
commandName: IncomingRequestCommand
): Promise<ResponseType> {
try {
protected async sendMessage(
messageId: string,
- messagePayload: JsonObject,
+ messagePayload: JsonType,
commandName: RequestCommand,
params: RequestParams = {
skipBufferingOnError: false,
private async internalSendMessage(
messageId: string,
- messagePayload: JsonObject | OCPPError,
+ messagePayload: JsonType | OCPPError,
messageType: MessageType,
commandName?: RequestCommand | IncomingRequestCommand,
params: RequestParams = {
ErrorType.GENERIC_ERROR,
`WebSocket closed for buffered message id '${messageId}' with content '${messageToSend}'`,
commandName,
- (messagePayload?.details as JsonObject) ?? {}
+ (messagePayload as JsonObject)?.details ?? {}
);
if (messageType === MessageType.CALL_MESSAGE) {
// Reject it but keep the request in the cache
ErrorType.GENERIC_ERROR,
`WebSocket closed for non buffered message id '${messageId}' with content '${messageToSend}'`,
commandName,
- (messagePayload?.details as JsonObject) ?? {}
+ (messagePayload as JsonObject)?.details ?? {}
),
false
);
* @param requestPayload
*/
async function responseCallback(
- payload: JsonObject,
- requestPayload: JsonObject
+ payload: JsonType,
+ requestPayload: JsonType
): Promise<void> {
if (self.chargingStation.getEnableStatistics()) {
self.chargingStation.performanceStatistics.addRequestStatistic(
ErrorType.GENERIC_ERROR,
`Timeout for message id '${messageId}'`,
commandName,
- (messagePayload?.details as JsonObject) ?? {}
+ (messagePayload as JsonObject)?.details ?? {}
),
() => {
messageType === MessageType.CALL_MESSAGE &&
private buildMessageToSend(
messageId: string,
- messagePayload: JsonObject | OCPPError,
+ messagePayload: JsonType | OCPPError,
messageType: MessageType,
commandName?: RequestCommand | IncomingRequestCommand,
- responseCallback?: (payload: JsonObject, requestPayload: JsonObject) => Promise<void>,
+ responseCallback?: (payload: JsonType, requestPayload: JsonType) => Promise<void>,
errorCallback?: (error: OCPPError, requestStatistic?: boolean) => void
): string {
let messageToSend: string;
responseCallback,
errorCallback,
commandName,
- messagePayload as JsonObject,
+ messagePayload as JsonType,
]);
messageToSend = JSON.stringify([
messageType,
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
- public abstract requestHandler<Request extends JsonObject, Response extends JsonObject>(
+ public abstract requestHandler<Request extends JsonType, Response extends JsonType>(
commandName: RequestCommand,
- commandParams?: JsonObject,
+ commandParams?: JsonType,
params?: RequestParams
): Promise<Response>;
}
import type ChargingStation from '../ChargingStation';
-import { JsonObject } from '../../types/JsonType';
+import { JsonType } from '../../types/JsonType';
import { RequestCommand } from '../../types/ocpp/Requests';
export default abstract class OCPPResponseService {
public abstract responseHandler(
commandName: RequestCommand,
- payload: JsonObject,
- requestPayload: JsonObject
+ payload: JsonType,
+ requestPayload: JsonType
): Promise<void>;
}
import { ProtocolCommand, ProtocolRequestHandler } from '../../types/UIProtocol';
import BaseError from '../../exception/BaseError';
-import { JsonObject } from '../../types/JsonType';
+import { JsonType } from '../../types/JsonType';
import UIWebSocketServer from '../UIWebSocketServer';
import logger from '../../utils/Logger';
]);
}
- public async messageHandler(command: ProtocolCommand, payload: JsonObject): Promise<void> {
- let messageResponse: JsonObject;
+ public async messageHandler(command: ProtocolCommand, payload: JsonType): Promise<void> {
+ let messageResponse: JsonType;
if (this.messageHandlers.has(command)) {
try {
// Call the method to build the message response
- messageResponse = (await this.messageHandlers.get(command)(payload)) as JsonObject;
+ messageResponse = (await this.messageHandlers.get(command)(payload)) as JsonType;
} catch (error) {
// Log
logger.error(this.uiWebSocketServer.logPrefix() + ' Handle message error: %j', error);
this.uiWebSocketServer.broadcastToClients(this.buildProtocolMessage(command, messageResponse));
}
- protected buildProtocolMessage(command: ProtocolCommand, payload: JsonObject): string {
+ protected buildProtocolMessage(command: ProtocolCommand, payload: JsonType): string {
return JSON.stringify([command, payload]);
}
import { ProtocolCommand, ProtocolRequestHandler } from '../../types/UIProtocol';
import AbstractUIService from './AbstractUIService';
-import { JsonObject } from '../../types/JsonType';
+import { JsonType } from '../../types/JsonType';
import UIWebSocketServer from '../UIWebSocketServer';
export default class UIService001 extends AbstractUIService {
);
}
- private handleStartTransaction(payload: JsonObject): void {}
- private handleStopTransaction(payload: JsonObject): void {}
+ private handleStartTransaction(payload: JsonType): void {}
+ private handleStopTransaction(payload: JsonType): void {}
}
import BaseError from './BaseError';
import { ErrorType } from '../types/ocpp/ErrorType';
-import { JsonObject } from '../types/JsonType';
+import { JsonType } from '../types/JsonType';
export default class OCPPError extends BaseError {
code: ErrorType;
command?: RequestCommand | IncomingRequestCommand;
- details?: JsonObject;
+ details?: JsonType;
constructor(
code: ErrorType,
message: string,
command?: RequestCommand | IncomingRequestCommand,
- details?: JsonObject
+ details?: JsonType
) {
super(message);
-import { JsonObject } from './JsonType';
+import { JsonType } from './JsonType';
export enum Protocol {
UI = 'ui',
UNKNOWN = 'unknown',
}
-export type ProtocolRequest = [ProtocolCommand, JsonObject];
+export type ProtocolRequest = [ProtocolCommand, JsonType];
export type ProtocolRequestHandler = (
- payload: JsonObject
-) => void | Promise<void> | JsonObject | Promise<JsonObject>;
+ payload: JsonType
+) => void | Promise<void> | JsonType | Promise<JsonType>;
OCPP16StatusNotificationRequest,
} from './1.6/Requests';
-import { JsonObject } from '../JsonType';
+import { JsonType } from '../JsonType';
import { MessageType } from './MessageType';
import { OCPP16DiagnosticsStatus } from './1.6/DiagnosticsStatus';
import { OCPP16MeterValuesRequest } from './1.6/MeterValues';
import OCPPError from '../../exception/OCPPError';
-export type OutgoingRequest = [MessageType.CALL_MESSAGE, string, RequestCommand, JsonObject];
+export type OutgoingRequest = [MessageType.CALL_MESSAGE, string, RequestCommand, JsonType];
-export type IncomingRequest = [
- MessageType.CALL_MESSAGE,
- string,
- IncomingRequestCommand,
- JsonObject
-];
+export type IncomingRequest = [MessageType.CALL_MESSAGE, string, IncomingRequestCommand, JsonType];
export type CachedRequest = [
- (payload: JsonObject, requestPayload: JsonObject) => void,
+ (payload: JsonType, requestPayload: JsonType) => void,
(error: OCPPError, requestStatistic?: boolean) => void,
RequestCommand | IncomingRequestCommand,
- JsonObject
+ JsonType
];
-export type IncomingRequestHandler = (
- commandPayload: JsonObject
-) => JsonObject | Promise<JsonObject>;
+export type IncomingRequestHandler = (commandPayload: JsonType) => JsonType | Promise<JsonType>;
-export type ResponseType = JsonObject | OCPPError;
+export type ResponseType = JsonType | OCPPError;
export interface RequestParams {
skipBufferingOnError?: boolean;
} from './1.6/Responses';
import { ErrorType } from './ErrorType';
-import { JsonObject } from '../JsonType';
+import { JsonType } from '../JsonType';
import { MessageType } from './MessageType';
import { OCPP16MeterValuesResponse } from './1.6/MeterValues';
-export type Response = [MessageType.CALL_RESULT_MESSAGE, string, JsonObject];
+export type Response = [MessageType.CALL_RESULT_MESSAGE, string, JsonType];
-export type ErrorResponse = [MessageType.CALL_ERROR_MESSAGE, string, ErrorType, string, JsonObject];
+export type ErrorResponse = [MessageType.CALL_ERROR_MESSAGE, string, ErrorType, string, JsonType];
export type ResponseHandler = (
- payload: JsonObject,
- requestPayload?: JsonObject
+ payload: JsonType,
+ requestPayload?: JsonType
) => void | Promise<void>;
export type BootNotificationResponse = OCPP16BootNotificationResponse;