905d972a3bc2348eee28bc6d9d347e4e8ec9e6b7
1 import { JSONSchemaType
} from
'ajv';
2 import Ajv from
'ajv-draft-04';
3 import ajvFormats from
'ajv-formats';
5 import OCPPError from
'../../exception/OCPPError';
6 import { JsonType
} from
'../../types/JsonType';
7 import { ErrorType
} from
'../../types/ocpp/ErrorType';
8 import { RequestCommand
} from
'../../types/ocpp/Requests';
9 import logger from
'../../utils/Logger';
10 import type ChargingStation from
'../ChargingStation';
12 const moduleName
= 'OCPPResponseService';
14 export default abstract class OCPPResponseService
{
15 private static instance
: OCPPResponseService
| null = null;
18 protected constructor() {
23 public static getInstance
<T
extends OCPPResponseService
>(this: new () => T
): T
{
24 if (!OCPPResponseService
.instance
) {
25 OCPPResponseService
.instance
= new this();
27 return OCPPResponseService
.instance
as T
;
30 protected validateResponsePayload
<T
extends JsonType
>(
31 chargingStation
: ChargingStation
,
32 commandName
: RequestCommand
,
33 schema
: JSONSchemaType
<T
>,
36 if (!chargingStation
.getPayloadSchemaValidation()) {
39 const validate
= this.ajv
.compile(schema
);
40 if (validate(payload
)) {
44 `${chargingStation.logPrefix()} ${moduleName}.validateResponsePayload: Response PDU is invalid: %j`,
48 ErrorType
.FORMATION_VIOLATION
,
49 'Response PDU is invalid',
51 JSON
.stringify(validate
.errors
, null, 2)
55 public abstract responseHandler(
56 chargingStation
: ChargingStation
,
57 commandName
: RequestCommand
,
59 requestPayload
: JsonType