+const moduleName = 'OCPPResponseService'
+
+export abstract class OCPPResponseService {
+ private static instance: OCPPResponseService | null = null
+ private readonly version: OCPPVersion
+ protected readonly ajv: Ajv
+ protected readonly ajvIncomingRequest: Ajv
+ protected abstract payloadValidateFunctions: Map<RequestCommand, ValidateFunction<JsonType>>
+ public abstract incomingRequestResponsePayloadValidateFunctions: Map<
+ IncomingRequestCommand,
+ ValidateFunction<JsonType>
+ >
+
+ protected constructor (version: OCPPVersion) {
+ this.version = version
+ this.ajv = new Ajv({
+ keywords: ['javaType'],
+ multipleOfPrecision: 2
+ })
+ ajvFormats(this.ajv)
+ this.ajvIncomingRequest = new Ajv({
+ keywords: ['javaType'],
+ multipleOfPrecision: 2
+ })
+ ajvFormats(this.ajvIncomingRequest)
+ this.responseHandler = this.responseHandler.bind(this)
+ this.validateResponsePayload = this.validateResponsePayload.bind(this)
+ }
+
+ public static getInstance<T extends OCPPResponseService>(this: new () => T): T {
+ if (OCPPResponseService.instance === null) {
+ OCPPResponseService.instance = new this()
+ }
+ return OCPPResponseService.instance as T