refactor: cleanup payload validation properties namespace
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 25 Jan 2024 23:37:53 +0000 (00:37 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 25 Jan 2024 23:37:53 +0000 (00:37 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/1.6/OCPP16RequestService.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts
src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts
src/charging-station/ocpp/2.0/OCPP20RequestService.ts
src/charging-station/ocpp/2.0/OCPP20ResponseService.ts
src/charging-station/ocpp/OCPPIncomingRequestService.ts
src/charging-station/ocpp/OCPPRequestService.ts
src/charging-station/ocpp/OCPPResponseService.ts

index 5d6172c4f6e273973b083d6f187703fdc1c8aab4..289f03be33c430aee9adf510db8744bee10237cc 100644 (file)
@@ -113,10 +113,7 @@ import { OCPPIncomingRequestService } from '../OCPPIncomingRequestService.js'
 const moduleName = 'OCPP16IncomingRequestService'
 
 export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
-  protected jsonSchemasValidateFunction: Map<
-  OCPP16IncomingRequestCommand,
-  ValidateFunction<JsonType>
-  >
+  protected payloadValidateFunctions: Map<OCPP16IncomingRequestCommand, ValidateFunction<JsonType>>
 
   private readonly incomingRequestHandlers: Map<
   OCPP16IncomingRequestCommand,
@@ -198,7 +195,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
         this.handleRequestCancelReservation.bind(this) as unknown as IncomingRequestHandler
       ]
     ])
-    this.jsonSchemasValidateFunction = new Map<
+    this.payloadValidateFunctions = new Map<
     OCPP16IncomingRequestCommand,
     ValidateFunction<JsonType>
     >([
@@ -498,7 +495,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
     commandName: OCPP16IncomingRequestCommand,
     commandPayload: JsonType
   ): boolean {
-    if (this.jsonSchemasValidateFunction.has(commandName)) {
+    if (this.payloadValidateFunctions.has(commandName)) {
       return this.validateIncomingRequestPayload(chargingStation, commandName, commandPayload)
     }
     logger.warn(
index a7bacae9b2814fd5cc813fcb77d43db2964125b8..74c00daa8f42335383b7d5d7f603cdd40fd90303 100644 (file)
@@ -32,14 +32,14 @@ import type { OCPPResponseService } from '../OCPPResponseService.js'
 const moduleName = 'OCPP16RequestService'
 
 export class OCPP16RequestService extends OCPPRequestService {
-  protected jsonSchemasValidateFunction: Map<OCPP16RequestCommand, ValidateFunction<JsonType>>
+  protected payloadValidateFunctions: Map<OCPP16RequestCommand, ValidateFunction<JsonType>>
 
   public constructor (ocppResponseService: OCPPResponseService) {
     // if (new.target.name === moduleName) {
     //   throw new TypeError(`Cannot construct ${new.target.name} instances directly`)
     // }
     super(OCPPVersion.VERSION_16, ocppResponseService)
-    this.jsonSchemasValidateFunction = new Map<OCPP16RequestCommand, ValidateFunction<JsonType>>([
+    this.payloadValidateFunctions = new Map<OCPP16RequestCommand, ValidateFunction<JsonType>>([
       [
         OCPP16RequestCommand.AUTHORIZE,
         this.ajv
index 3b91fba1f028f2a16b38f6abc99f77f55e37938b..11be84936caf98fd77ab3306910a2108dc3d55cf 100644 (file)
@@ -57,12 +57,12 @@ import { OCPPResponseService } from '../OCPPResponseService.js'
 const moduleName = 'OCPP16ResponseService'
 
 export class OCPP16ResponseService extends OCPPResponseService {
-  public jsonSchemasIncomingRequestResponseValidateFunction: Map<
+  public incomingRequestResponsePayloadValidateFunctions: Map<
   OCPP16IncomingRequestCommand,
   ValidateFunction<JsonType>
   >
 
-  protected jsonSchemasValidateFunction: Map<OCPP16RequestCommand, ValidateFunction<JsonType>>
+  protected payloadValidateFunctions: Map<OCPP16RequestCommand, ValidateFunction<JsonType>>
   private readonly responseHandlers: Map<OCPP16RequestCommand, ResponseHandler>
 
   public constructor () {
@@ -97,7 +97,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [OCPP16RequestCommand.DATA_TRANSFER, this.emptyResponseHandler],
       [OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION, this.emptyResponseHandler]
     ])
-    this.jsonSchemasValidateFunction = new Map<OCPP16RequestCommand, ValidateFunction<JsonType>>([
+    this.payloadValidateFunctions = new Map<OCPP16RequestCommand, ValidateFunction<JsonType>>([
       [
         OCPP16RequestCommand.BOOT_NOTIFICATION,
         this.ajv
@@ -219,7 +219,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
           .bind(this)
       ]
     ])
-    this.jsonSchemasIncomingRequestResponseValidateFunction = new Map<
+    this.incomingRequestResponsePayloadValidateFunctions = new Map<
     OCPP16IncomingRequestCommand,
     ValidateFunction<JsonType>
     >([
@@ -485,7 +485,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
     commandName: OCPP16RequestCommand,
     payload: JsonType
   ): boolean {
-    if (this.jsonSchemasValidateFunction.has(commandName)) {
+    if (this.payloadValidateFunctions.has(commandName)) {
       return this.validateResponsePayload(chargingStation, commandName, payload)
     }
     logger.warn(
index cfc58323ed8ad4cf597c1a2b3b9227b86f8ba2cd..94401593b6d0f5ae772bdb9098d60162914e377d 100644 (file)
@@ -19,10 +19,7 @@ import { OCPPIncomingRequestService } from '../OCPPIncomingRequestService.js'
 const moduleName = 'OCPP20IncomingRequestService'
 
 export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
-  protected jsonSchemasValidateFunction: Map<
-  OCPP20IncomingRequestCommand,
-  ValidateFunction<JsonType>
-  >
+  protected payloadValidateFunctions: Map<OCPP20IncomingRequestCommand, ValidateFunction<JsonType>>
 
   private readonly incomingRequestHandlers: Map<
   OCPP20IncomingRequestCommand,
@@ -37,7 +34,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
     this.incomingRequestHandlers = new Map<OCPP20IncomingRequestCommand, IncomingRequestHandler>([
       [OCPP20IncomingRequestCommand.CLEAR_CACHE, this.handleRequestClearCache.bind(this)]
     ])
-    this.jsonSchemasValidateFunction = new Map<
+    this.payloadValidateFunctions = new Map<
     OCPP20IncomingRequestCommand,
     ValidateFunction<JsonType>
     >([
@@ -145,7 +142,7 @@ export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
     commandName: OCPP20IncomingRequestCommand,
     commandPayload: JsonType
   ): boolean {
-    if (this.jsonSchemasValidateFunction.has(commandName)) {
+    if (this.payloadValidateFunctions.has(commandName)) {
       return this.validateIncomingRequestPayload(chargingStation, commandName, commandPayload)
     }
     logger.warn(
index 20bd333f69f466959c4c62f78b09ee4fc44dad69..a61fc2aee090d4d7dfa836e3a7c5d90a1f96aeee 100644 (file)
@@ -24,14 +24,14 @@ import type { OCPPResponseService } from '../OCPPResponseService.js'
 const moduleName = 'OCPP20RequestService'
 
 export class OCPP20RequestService extends OCPPRequestService {
-  protected jsonSchemasValidateFunction: Map<OCPP20RequestCommand, ValidateFunction<JsonType>>
+  protected payloadValidateFunctions: Map<OCPP20RequestCommand, ValidateFunction<JsonType>>
 
   public constructor (ocppResponseService: OCPPResponseService) {
     // if (new.target.name === moduleName) {
     //   throw new TypeError(`Cannot construct ${new.target.name} instances directly`)
     // }
     super(OCPPVersion.VERSION_20, ocppResponseService)
-    this.jsonSchemasValidateFunction = new Map<OCPP20RequestCommand, ValidateFunction<JsonType>>([
+    this.payloadValidateFunctions = new Map<OCPP20RequestCommand, ValidateFunction<JsonType>>([
       [
         OCPP20RequestCommand.BOOT_NOTIFICATION,
         this.ajv
index d5b3e7d1f6a49a3d74cd1b0a5d86b55499c164e5..bb12b0069c7fedbab970755c629b984de486cab8 100644 (file)
@@ -25,12 +25,12 @@ import { OCPPResponseService } from '../OCPPResponseService.js'
 const moduleName = 'OCPP20ResponseService'
 
 export class OCPP20ResponseService extends OCPPResponseService {
-  public jsonSchemasIncomingRequestResponseValidateFunction: Map<
+  public incomingRequestResponsePayloadValidateFunctions: Map<
   OCPP20IncomingRequestCommand,
   ValidateFunction<JsonType>
   >
 
-  protected jsonSchemasValidateFunction: Map<OCPP20RequestCommand, ValidateFunction<JsonType>>
+  protected payloadValidateFunctions: Map<OCPP20RequestCommand, ValidateFunction<JsonType>>
   private readonly responseHandlers: Map<OCPP20RequestCommand, ResponseHandler>
 
   public constructor () {
@@ -46,7 +46,7 @@ export class OCPP20ResponseService extends OCPPResponseService {
       [OCPP20RequestCommand.HEARTBEAT, this.emptyResponseHandler],
       [OCPP20RequestCommand.STATUS_NOTIFICATION, this.emptyResponseHandler]
     ])
-    this.jsonSchemasValidateFunction = new Map<OCPP20RequestCommand, ValidateFunction<JsonType>>([
+    this.payloadValidateFunctions = new Map<OCPP20RequestCommand, ValidateFunction<JsonType>>([
       [
         OCPP20RequestCommand.BOOT_NOTIFICATION,
         this.ajv
@@ -84,7 +84,7 @@ export class OCPP20ResponseService extends OCPPResponseService {
           .bind(this)
       ]
     ])
-    this.jsonSchemasIncomingRequestResponseValidateFunction = new Map<
+    this.incomingRequestResponsePayloadValidateFunctions = new Map<
     OCPP20IncomingRequestCommand,
     ValidateFunction<JsonType>
     >([
@@ -158,7 +158,7 @@ export class OCPP20ResponseService extends OCPPResponseService {
     commandName: OCPP20RequestCommand,
     payload: JsonType
   ): boolean {
-    if (this.jsonSchemasValidateFunction.has(commandName)) {
+    if (this.payloadValidateFunctions.has(commandName)) {
       return this.validateResponsePayload(chargingStation, commandName, payload)
     }
     logger.warn(
index d0ff0229350ea4b03c20ea4d5dabd6becaa6f533..7203569749e04d8ee88a238e4ac2f0ea754382da 100644 (file)
@@ -24,7 +24,7 @@ export abstract class OCPPIncomingRequestService {
   private static instance: OCPPIncomingRequestService | null = null
   private readonly version: OCPPVersion
   protected readonly ajv: Ajv
-  protected abstract jsonSchemasValidateFunction: Map<
+  protected abstract payloadValidateFunctions: Map<
   IncomingRequestCommand,
   ValidateFunction<JsonType>
   >
@@ -77,7 +77,7 @@ export abstract class OCPPIncomingRequestService {
     if (chargingStation.stationInfo?.ocppStrictCompliance === false) {
       return true
     }
-    const validate = this.jsonSchemasValidateFunction.get(commandName)
+    const validate = this.payloadValidateFunctions.get(commandName)
     if (validate?.(payload) === true) {
       return true
     }
index f956d381b30109d14c708b06fae9c7637830d7f5..17fc548438ac612c6fe6274d12a9d88c338a70fb 100644 (file)
@@ -47,7 +47,7 @@ export abstract class OCPPRequestService {
   private readonly version: OCPPVersion
   private readonly ocppResponseService: OCPPResponseService
   protected readonly ajv: Ajv
-  protected abstract jsonSchemasValidateFunction: Map<RequestCommand, ValidateFunction<JsonType>>
+  protected abstract payloadValidateFunctions: Map<RequestCommand, ValidateFunction<JsonType>>
 
   protected constructor (version: OCPPVersion, ocppResponseService: OCPPResponseService) {
     this.version = version
@@ -158,13 +158,13 @@ export abstract class OCPPRequestService {
     if (chargingStation.stationInfo?.ocppStrictCompliance === false) {
       return true
     }
-    if (!this.jsonSchemasValidateFunction.has(commandName as RequestCommand)) {
+    if (!this.payloadValidateFunctions.has(commandName as RequestCommand)) {
       logger.warn(
         `${chargingStation.logPrefix()} ${moduleName}.validateRequestPayload: No JSON schema found for command '${commandName}' PDU validation`
       )
       return true
     }
-    const validate = this.jsonSchemasValidateFunction.get(commandName as RequestCommand)
+    const validate = this.payloadValidateFunctions.get(commandName as RequestCommand)
     payload = clone<T>(payload)
     OCPPServiceUtils.convertDateToISOString<T>(payload)
     if (validate?.(payload) === true) {
@@ -192,7 +192,7 @@ export abstract class OCPPRequestService {
       return true
     }
     if (
-      !this.ocppResponseService.jsonSchemasIncomingRequestResponseValidateFunction.has(
+      !this.ocppResponseService.incomingRequestResponsePayloadValidateFunctions.has(
         commandName as IncomingRequestCommand
       )
     ) {
@@ -201,10 +201,9 @@ export abstract class OCPPRequestService {
       )
       return true
     }
-    const validate =
-      this.ocppResponseService.jsonSchemasIncomingRequestResponseValidateFunction.get(
-        commandName as IncomingRequestCommand
-      )
+    const validate = this.ocppResponseService.incomingRequestResponsePayloadValidateFunctions.get(
+      commandName as IncomingRequestCommand
+    )
     payload = clone<T>(payload)
     OCPPServiceUtils.convertDateToISOString<T>(payload)
     if (validate?.(payload) === true) {
index 45a3e1f2d5822f5236e0266492935effd38f165d..a526c28c6812fea7b27108d1b46daa9c3fe731ec 100644 (file)
@@ -23,8 +23,8 @@ export abstract class OCPPResponseService {
   private readonly version: OCPPVersion
   protected readonly ajv: Ajv
   protected readonly ajvIncomingRequest: Ajv
-  protected abstract jsonSchemasValidateFunction: Map<RequestCommand, ValidateFunction<JsonType>>
-  public abstract jsonSchemasIncomingRequestResponseValidateFunction: Map<
+  protected abstract payloadValidateFunctions: Map<RequestCommand, ValidateFunction<JsonType>>
+  public abstract incomingRequestResponsePayloadValidateFunctions: Map<
   IncomingRequestCommand,
   ValidateFunction<JsonType>
   >
@@ -60,7 +60,7 @@ export abstract class OCPPResponseService {
     if (chargingStation.stationInfo?.ocppStrictCompliance === false) {
       return true
     }
-    const validate = this.jsonSchemasValidateFunction.get(commandName)
+    const validate = this.payloadValidateFunctions.get(commandName)
     if (validate?.(payload) === true) {
       return true
     }