- public constructor() {
- if (new.target?.name === moduleName) {
- throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
- }
- super();
- this.responseHandlers = new Map<OCPP20RequestCommand, ResponseHandler>();
- this.jsonSchemas = new Map<OCPP20RequestCommand, JSONSchemaType<JsonObject>>();
- this.validatePayload.bind(this);
+ protected payloadValidateFunctions: Map<OCPP20RequestCommand, ValidateFunction<JsonType>>
+ private readonly responseHandlers: Map<OCPP20RequestCommand, ResponseHandler>
+
+ public constructor () {
+ // if (new.target.name === moduleName) {
+ // throw new TypeError(`Cannot construct ${new.target.name} instances directly`)
+ // }
+ super(OCPPVersion.VERSION_20)
+ this.responseHandlers = new Map<OCPP20RequestCommand, ResponseHandler>([
+ [
+ OCPP20RequestCommand.BOOT_NOTIFICATION,
+ this.handleResponseBootNotification.bind(this) as ResponseHandler
+ ],
+ [OCPP20RequestCommand.HEARTBEAT, this.emptyResponseHandler],
+ [OCPP20RequestCommand.STATUS_NOTIFICATION, this.emptyResponseHandler]
+ ])
+ this.payloadValidateFunctions = new Map<OCPP20RequestCommand, ValidateFunction<JsonType>>([
+ [
+ OCPP20RequestCommand.BOOT_NOTIFICATION,
+ this.ajv
+ .compile(
+ OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20BootNotificationResponse>(
+ 'assets/json-schemas/ocpp/2.0/BootNotificationResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
+ ],
+ [
+ OCPP20RequestCommand.HEARTBEAT,
+ this.ajv
+ .compile(
+ OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20HeartbeatResponse>(
+ 'assets/json-schemas/ocpp/2.0/HeartbeatResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
+ ],
+ [
+ OCPP20RequestCommand.STATUS_NOTIFICATION,
+ this.ajv
+ .compile(
+ OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20StatusNotificationResponse>(
+ 'assets/json-schemas/ocpp/2.0/StatusNotificationResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
+ ]
+ ])
+ this.incomingRequestResponsePayloadValidateFunctions = new Map<
+ OCPP20IncomingRequestCommand,
+ ValidateFunction<JsonType>
+ >([
+ [
+ OCPP20IncomingRequestCommand.CLEAR_CACHE,
+ this.ajvIncomingRequest
+ .compile(
+ OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20ClearCacheResponse>(
+ 'assets/json-schemas/ocpp/2.0/ClearCacheResponse.json',
+ moduleName,
+ 'constructor'
+ )
+ )
+ .bind(this)
+ ]
+ ])
+ this.validatePayload = this.validatePayload.bind(this)