private readonly version: OCPPVersion;
private readonly ajv: Ajv;
private readonly ocppResponseService: OCPPResponseService;
- private readonly jsonValidateFunctions: Map<RequestCommand, ValidateFunction<JsonObject>>;
- protected abstract jsonSchemas: Map<RequestCommand, JSONSchemaType<JsonObject>>;
+ private readonly jsonValidateFunctions: Map<RequestCommand, ValidateFunction<JsonType>>;
+ protected abstract jsonSchemas: Map<RequestCommand, JSONSchemaType<JsonType>>;
protected constructor(version: OCPPVersion, ocppResponseService: OCPPResponseService) {
this.version = version;
multipleOfPrecision: 2,
});
ajvFormats(this.ajv);
- this.jsonValidateFunctions = new Map<RequestCommand, ValidateFunction<JsonObject>>();
+ this.jsonValidateFunctions = new Map<RequestCommand, ValidateFunction<JsonType>>();
this.ocppResponseService = ocppResponseService;
this.requestHandler = this.requestHandler.bind(this) as <
// eslint-disable-next-line @typescript-eslint/no-unused-vars
responseCallback: ResponseCallback,
errorCallback: ErrorCallback,
) => string;
- this.validateRequestPayload = this.validateRequestPayload.bind(this) as <T extends JsonObject>(
+ this.validateRequestPayload = this.validateRequestPayload.bind(this) as <T extends JsonType>(
chargingStation: ChargingStation,
commandName: RequestCommand | IncomingRequestCommand,
payload: T,
) => boolean;
this.validateIncomingRequestResponsePayload = this.validateIncomingRequestResponsePayload.bind(
this,
- ) as <T extends JsonObject>(
+ ) as <T extends JsonType>(
chargingStation: ChargingStation,
commandName: RequestCommand | IncomingRequestCommand,
payload: T,
}
}
- private validateRequestPayload<T extends JsonObject>(
+ private validateRequestPayload<T extends JsonType>(
chargingStation: ChargingStation,
commandName: RequestCommand | IncomingRequestCommand,
payload: T,
): boolean {
- if (chargingStation.getOcppStrictCompliance() === false) {
+ if (chargingStation.stationInfo?.ocppStrictCompliance === false) {
return true;
}
if (this.jsonSchemas.has(commandName as RequestCommand) === false) {
if (this.jsonValidateFunctions.has(commandName as RequestCommand) === false) {
this.jsonValidateFunctions.set(
commandName as RequestCommand,
- this.ajv.compile(this.jsonSchemas.get(commandName as RequestCommand)!).bind(this),
+ this.ajv.compile<T>(this.jsonSchemas.get(commandName as RequestCommand)!).bind(this),
);
}
const validate = this.jsonValidateFunctions.get(commandName as RequestCommand)!;
);
// OCPPError usage here is debatable: it's an error in the OCPP stack but not targeted to sendError().
throw new OCPPError(
- OCPPServiceUtils.ajvErrorsToErrorType(validate.errors!),
+ OCPPServiceUtils.ajvErrorsToErrorType(validate.errors),
'Request PDU is invalid',
commandName,
JSON.stringify(validate.errors, undefined, 2),
);
}
- private validateIncomingRequestResponsePayload<T extends JsonObject>(
+ private validateIncomingRequestResponsePayload<T extends JsonType>(
chargingStation: ChargingStation,
commandName: RequestCommand | IncomingRequestCommand,
payload: T,
): boolean {
- if (chargingStation.getOcppStrictCompliance() === false) {
+ if (chargingStation.stationInfo?.ocppStrictCompliance === false) {
return true;
}
if (
this.ocppResponseService.jsonIncomingRequestResponseValidateFunctions.set(
commandName as IncomingRequestCommand,
this.ajv
- .compile(
+ .compile<T>(
this.ocppResponseService.jsonIncomingRequestResponseSchemas.get(
commandName as IncomingRequestCommand,
)!,
);
// OCPPError usage here is debatable: it's an error in the OCPP stack but not targeted to sendError().
throw new OCPPError(
- OCPPServiceUtils.ajvErrorsToErrorType(validate.errors!),
+ OCPPServiceUtils.ajvErrorsToErrorType(validate.errors),
'Response PDU is invalid',
commandName,
JSON.stringify(validate.errors, undefined, 2),
if (
(chargingStation.inUnknownState() === true &&
commandName === RequestCommand.BOOT_NOTIFICATION) ||
- (chargingStation.getOcppStrictCompliance() === false &&
+ (chargingStation.stationInfo?.ocppStrictCompliance === false &&
chargingStation.inUnknownState() === true) ||
chargingStation.inAcceptedState() === true ||
(chargingStation.inPendingState() === true &&
* @param requestPayload -
*/
const responseCallback = (payload: JsonType, requestPayload: JsonType): void => {
- if (chargingStation.getEnableStatistics() === true) {
+ if (chargingStation.stationInfo?.enableStatistics === true) {
chargingStation.performanceStatistics?.addRequestStatistic(
commandName,
MessageType.CALL_RESULT_MESSAGE,
* @param requestStatistic -
*/
const errorCallback = (error: OCPPError, requestStatistic = true): void => {
- if (requestStatistic === true && chargingStation.getEnableStatistics() === true) {
+ if (
+ requestStatistic === true &&
+ chargingStation.stationInfo?.enableStatistics === true
+ ) {
chargingStation.performanceStatistics?.addRequestStatistic(
commandName,
MessageType.CALL_ERROR_MESSAGE,
reject(error);
};
- if (chargingStation.getEnableStatistics() === true) {
+ if (chargingStation.stationInfo?.enableStatistics === true) {
chargingStation.performanceStatistics?.addRequestStatistic(commandName, messageType);
}
const messageToSend = this.buildMessageToSend(
// Request
case MessageType.CALL_MESSAGE:
// Build request
- this.validateRequestPayload(chargingStation, commandName, messagePayload as JsonObject);
+ this.validateRequestPayload(chargingStation, commandName, messagePayload as JsonType);
chargingStation.requests.set(messageId, [
responseCallback,
errorCallback,
this.validateIncomingRequestResponsePayload(
chargingStation,
commandName,
- messagePayload as JsonObject,
+ messagePayload as JsonType,
);
messageToSend = JSON.stringify([messageType, messageId, messagePayload] as Response);
break;