this.jsonSchemas = new Map<OCPP16IncomingRequestCommand, JSONSchemaType<JsonObject>>([
[
OCPP16IncomingRequestCommand.RESET,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/Reset.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<ResetRequest>,
+ this.parseJsonSchemaFile<ResetRequest>('../../../assets/json-schemas/ocpp/1.6/Reset.json'),
],
[
OCPP16IncomingRequestCommand.CLEAR_CACHE,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/ClearCache.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16ClearCacheRequest>,
+ this.parseJsonSchemaFile<OCPP16ClearCacheRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/ClearCache.json'
+ ),
],
[
OCPP16IncomingRequestCommand.UNLOCK_CONNECTOR,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/UnlockConnector.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<UnlockConnectorRequest>,
+ this.parseJsonSchemaFile<UnlockConnectorRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/UnlockConnector.json'
+ ),
],
[
OCPP16IncomingRequestCommand.GET_CONFIGURATION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/GetConfiguration.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<GetConfigurationRequest>,
+ this.parseJsonSchemaFile<GetConfigurationRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/GetConfiguration.json'
+ ),
],
[
OCPP16IncomingRequestCommand.CHANGE_CONFIGURATION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/ChangeConfiguration.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<ChangeConfigurationRequest>,
+ this.parseJsonSchemaFile<ChangeConfigurationRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/ChangeConfiguration.json'
+ ),
],
[
OCPP16IncomingRequestCommand.GET_DIAGNOSTICS,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/GetDiagnostics.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<GetDiagnosticsRequest>,
+ this.parseJsonSchemaFile<GetDiagnosticsRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/GetDiagnostics.json'
+ ),
],
[
OCPP16IncomingRequestCommand.SET_CHARGING_PROFILE,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/SetChargingProfile.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<SetChargingProfileRequest>,
+ this.parseJsonSchemaFile<SetChargingProfileRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/SetChargingProfile.json'
+ ),
],
[
OCPP16IncomingRequestCommand.CLEAR_CHARGING_PROFILE,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/ClearChargingProfile.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<ClearChargingProfileRequest>,
+ this.parseJsonSchemaFile<ClearChargingProfileRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/ClearChargingProfile.json'
+ ),
],
[
OCPP16IncomingRequestCommand.CHANGE_AVAILABILITY,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/ChangeAvailability.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<ChangeAvailabilityRequest>,
+ this.parseJsonSchemaFile<ChangeAvailabilityRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/ChangeAvailability.json'
+ ),
],
[
OCPP16IncomingRequestCommand.REMOTE_START_TRANSACTION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/RemoteStartTransaction.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<RemoteStartTransactionRequest>,
+ this.parseJsonSchemaFile<RemoteStartTransactionRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/RemoteStartTransaction.json'
+ ),
],
[
OCPP16IncomingRequestCommand.REMOTE_STOP_TRANSACTION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/RemoteStopTransaction.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<RemoteStopTransactionRequest>,
+ this.parseJsonSchemaFile<RemoteStopTransactionRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/RemoteStopTransaction.json'
+ ),
],
[
OCPP16IncomingRequestCommand.TRIGGER_MESSAGE,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/TriggerMessage.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16TriggerMessageRequest>,
+ this.parseJsonSchemaFile<OCPP16TriggerMessageRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/TriggerMessage.json'
+ ),
],
[
OCPP16IncomingRequestCommand.DATA_TRANSFER,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/DataTransfer.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16DataTransferRequest>,
+ this.parseJsonSchemaFile<OCPP16DataTransferRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/DataTransfer.json'
+ ),
],
[
OCPP16IncomingRequestCommand.UPDATE_FIRMWARE,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/UpdateFirmware.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16UpdateFirmwareRequest>,
+ this.parseJsonSchemaFile<OCPP16UpdateFirmwareRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/UpdateFirmware.json'
+ ),
],
]);
this.validatePayload.bind(this);
);
}
}
+
+ private parseJsonSchemaFile<T extends JsonType>(relativePath: string): JSONSchemaType<T> {
+ return JSON.parse(
+ fs.readFileSync(
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath),
+ 'utf8'
+ )
+ ) as JSONSchemaType<T>;
+ }
}
type OCPP16BootNotificationRequest,
type OCPP16DataTransferRequest,
type OCPP16DiagnosticsStatusNotificationRequest,
+ type OCPP16FirmwareStatusNotificationRequest,
type OCPP16HeartbeatRequest,
OCPP16RequestCommand,
type OCPP16StatusNotificationRequest,
- type OCPP16UpdateFirmwareRequest,
} from '../../../types/ocpp/1.6/Requests';
import type {
OCPP16AuthorizeRequest,
this.jsonSchemas = new Map<OCPP16RequestCommand, JSONSchemaType<JsonObject>>([
[
OCPP16RequestCommand.AUTHORIZE,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/Authorize.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16AuthorizeRequest>,
+ this.parseJsonSchemaFile<OCPP16AuthorizeRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/Authorize.json'
+ ),
],
[
OCPP16RequestCommand.BOOT_NOTIFICATION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/BootNotification.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16BootNotificationRequest>,
+ this.parseJsonSchemaFile<OCPP16BootNotificationRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/BootNotification.json'
+ ),
],
[
OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/DiagnosticsStatusNotification.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16DiagnosticsStatusNotificationRequest>,
+ this.parseJsonSchemaFile<OCPP16DiagnosticsStatusNotificationRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/DiagnosticsStatusNotification.json'
+ ),
],
[
OCPP16RequestCommand.HEARTBEAT,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/Heartbeat.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16HeartbeatRequest>,
+ this.parseJsonSchemaFile<OCPP16HeartbeatRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/Heartbeat.json'
+ ),
],
[
OCPP16RequestCommand.METER_VALUES,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/MeterValues.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16MeterValuesRequest>,
+ this.parseJsonSchemaFile<OCPP16MeterValuesRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/MeterValues.json'
+ ),
],
[
OCPP16RequestCommand.STATUS_NOTIFICATION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/StatusNotification.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16StatusNotificationRequest>,
+ this.parseJsonSchemaFile<OCPP16StatusNotificationRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/StatusNotification.json'
+ ),
],
[
OCPP16RequestCommand.START_TRANSACTION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/StartTransaction.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16StartTransactionRequest>,
+ this.parseJsonSchemaFile<OCPP16StartTransactionRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/StartTransaction.json'
+ ),
],
[
OCPP16RequestCommand.STOP_TRANSACTION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/StopTransaction.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16StopTransactionRequest>,
+ this.parseJsonSchemaFile<OCPP16StopTransactionRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/StopTransaction.json'
+ ),
],
[
OCPP16RequestCommand.DATA_TRANSFER,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/DataTransfer.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16DataTransferRequest>,
+ this.parseJsonSchemaFile<OCPP16DataTransferRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/DataTransfer.json'
+ ),
],
[
OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/FirmwareStatusNotification.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16UpdateFirmwareRequest>,
+ this.parseJsonSchemaFile<OCPP16FirmwareStatusNotificationRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/FirmwareStatusNotification.json'
+ ),
],
]);
this.buildRequestPayload.bind(this);
);
}
}
+
+ private parseJsonSchemaFile<T extends JsonType>(relativePath: string): JSONSchemaType<T> {
+ return JSON.parse(
+ fs.readFileSync(
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath),
+ 'utf8'
+ )
+ ) as JSONSchemaType<T>;
+ }
}
this.jsonSchemas = new Map<OCPP16RequestCommand, JSONSchemaType<JsonObject>>([
[
OCPP16RequestCommand.BOOT_NOTIFICATION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/BootNotificationResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16BootNotificationResponse>,
+ this.parseJsonSchemaFile<OCPP16BootNotificationResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/BootNotificationResponse.json'
+ ),
],
[
OCPP16RequestCommand.HEARTBEAT,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/HeartbeatResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16HeartbeatResponse>,
+ this.parseJsonSchemaFile<OCPP16HeartbeatResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/HeartbeatResponse.json'
+ ),
],
[
OCPP16RequestCommand.AUTHORIZE,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/AuthorizeResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16AuthorizeResponse>,
+ this.parseJsonSchemaFile<OCPP16AuthorizeResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/AuthorizeResponse.json'
+ ),
],
[
OCPP16RequestCommand.START_TRANSACTION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/StartTransactionResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16StartTransactionResponse>,
+ this.parseJsonSchemaFile<OCPP16StartTransactionResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/StartTransactionResponse.json'
+ ),
],
[
OCPP16RequestCommand.STOP_TRANSACTION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/StopTransactionResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16StopTransactionResponse>,
+ this.parseJsonSchemaFile<OCPP16StopTransactionResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/StopTransactionResponse.json'
+ ),
],
[
OCPP16RequestCommand.STATUS_NOTIFICATION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/StatusNotificationResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16StatusNotificationResponse>,
+ this.parseJsonSchemaFile<OCPP16StatusNotificationResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/StatusNotificationResponse.json'
+ ),
],
[
OCPP16RequestCommand.METER_VALUES,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/MeterValuesResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16MeterValuesResponse>,
+ this.parseJsonSchemaFile<OCPP16MeterValuesResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/MeterValuesResponse.json'
+ ),
],
[
OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/DiagnosticsStatusNotificationResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16DiagnosticsStatusNotificationResponse>,
+ this.parseJsonSchemaFile<OCPP16DiagnosticsStatusNotificationResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/DiagnosticsStatusNotificationResponse.json'
+ ),
],
[
OCPP16RequestCommand.DATA_TRANSFER,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/DataTransferResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16DataTransferResponse>,
+ this.parseJsonSchemaFile<OCPP16DataTransferResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/DataTransferResponse.json'
+ ),
],
[
OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/FirmwareStatusNotificationResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16FirmwareStatusNotificationResponse>,
+ this.parseJsonSchemaFile<OCPP16FirmwareStatusNotificationResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/FirmwareStatusNotificationResponse.json'
+ ),
],
]);
this.jsonIncomingRequestResponseSchemas = new Map([
[
OCPP16IncomingRequestCommand.RESET,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/ResetResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<DefaultResponse>,
+ this.parseJsonSchemaFile<DefaultResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/ResetResponse.json'
+ ),
],
[
OCPP16IncomingRequestCommand.CLEAR_CACHE,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/ClearCacheResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<DefaultResponse>,
+ this.parseJsonSchemaFile<DefaultResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/ClearCacheResponse.json'
+ ),
],
[
OCPP16IncomingRequestCommand.CHANGE_AVAILABILITY,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/ChangeAvailabilityResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<ChangeAvailabilityResponse>,
+ this.parseJsonSchemaFile<ChangeAvailabilityResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/ChangeAvailabilityResponse.json'
+ ),
],
[
OCPP16IncomingRequestCommand.UNLOCK_CONNECTOR,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/UnlockConnectorResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<UnlockConnectorResponse>,
+ this.parseJsonSchemaFile<UnlockConnectorResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/UnlockConnectorResponse.json'
+ ),
],
[
OCPP16IncomingRequestCommand.GET_CONFIGURATION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/GetConfigurationResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<GetConfigurationResponse>,
+ this.parseJsonSchemaFile<GetConfigurationResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/GetConfigurationResponse.json'
+ ),
],
[
OCPP16IncomingRequestCommand.CHANGE_CONFIGURATION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/ChangeConfigurationResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<ChangeConfigurationResponse>,
+ this.parseJsonSchemaFile<ChangeConfigurationResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/ChangeConfigurationResponse.json'
+ ),
],
[
OCPP16IncomingRequestCommand.SET_CHARGING_PROFILE,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/SetChargingProfileResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<SetChargingProfileResponse>,
+ this.parseJsonSchemaFile<SetChargingProfileResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/SetChargingProfileResponse.json'
+ ),
],
[
OCPP16IncomingRequestCommand.CLEAR_CHARGING_PROFILE,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/ClearChargingProfileResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<ClearChargingProfileResponse>,
+ this.parseJsonSchemaFile<ClearChargingProfileResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/ClearChargingProfileResponse.json'
+ ),
],
[
OCPP16IncomingRequestCommand.REMOTE_START_TRANSACTION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/RemoteStartTransactionResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<DefaultResponse>,
+ this.parseJsonSchemaFile<DefaultResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/RemoteStartTransactionResponse.json'
+ ),
],
[
OCPP16IncomingRequestCommand.REMOTE_STOP_TRANSACTION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/RemoteStopTransactionResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<DefaultResponse>,
+ this.parseJsonSchemaFile<DefaultResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/RemoteStopTransactionResponse.json'
+ ),
],
[
OCPP16IncomingRequestCommand.GET_DIAGNOSTICS,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/GetDiagnosticsResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<GetDiagnosticsResponse>,
+ this.parseJsonSchemaFile<GetDiagnosticsResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/GetDiagnosticsResponse.json'
+ ),
],
[
OCPP16IncomingRequestCommand.TRIGGER_MESSAGE,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/TriggerMessageResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16TriggerMessageResponse>,
+ this.parseJsonSchemaFile<OCPP16TriggerMessageResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/TriggerMessageResponse.json'
+ ),
],
[
OCPP16IncomingRequestCommand.DATA_TRANSFER,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/DataTransferResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16DataTransferResponse>,
+ this.parseJsonSchemaFile<OCPP16DataTransferResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/DataTransferResponse.json'
+ ),
],
[
OCPP16IncomingRequestCommand.UPDATE_FIRMWARE,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/1.6/UpdateFirmwareResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP16UpdateFirmwareResponse>,
+ this.parseJsonSchemaFile<OCPP16UpdateFirmwareResponse>(
+ '../../../assets/json-schemas/ocpp/1.6/UpdateFirmwareResponse.json'
+ ),
],
]);
this.validatePayload.bind(this);
);
}
}
+
+ private parseJsonSchemaFile<T extends JsonType>(relativePath: string): JSONSchemaType<T> {
+ return JSON.parse(
+ fs.readFileSync(
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath),
+ 'utf8'
+ )
+ ) as JSONSchemaType<T>;
+ }
}
this.jsonSchemas = new Map<OCPP20IncomingRequestCommand, JSONSchemaType<JsonObject>>([
[
OCPP20IncomingRequestCommand.CLEAR_CACHE,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/2.0/ClearCacheRequest.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP20ClearCacheRequest>,
+ this.parseJsonSchemaFile<OCPP20ClearCacheRequest>(
+ '../../../assets/json-schemas/ocpp/2.0/ClearCacheRequest.json'
+ ),
],
]);
this.validatePayload.bind(this);
);
return false;
}
+
+ private parseJsonSchemaFile<T extends JsonType>(relativePath: string): JSONSchemaType<T> {
+ return JSON.parse(
+ fs.readFileSync(
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath),
+ 'utf8'
+ )
+ ) as JSONSchemaType<T>;
+ }
}
this.jsonSchemas = new Map<OCPP20RequestCommand, JSONSchemaType<JsonObject>>([
[
OCPP20RequestCommand.BOOT_NOTIFICATION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/2.0/BootNotificationRequest.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP20BootNotificationRequest>,
+ this.parseJsonSchemaFile<OCPP20BootNotificationRequest>(
+ '../../../assets/json-schemas/ocpp/2.0/BootNotificationRequest.json'
+ ),
],
[
OCPP20RequestCommand.HEARTBEAT,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/2.0/HeartbeatRequest.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP20HeartbeatRequest>,
+ this.parseJsonSchemaFile<OCPP20HeartbeatRequest>(
+ '../../../assets/json-schemas/ocpp/2.0/HeartbeatRequest.json'
+ ),
],
[
OCPP20RequestCommand.STATUS_NOTIFICATION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/2.0/StatusNotificationRequest.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP20StatusNotificationRequest>,
+ this.parseJsonSchemaFile<OCPP20StatusNotificationRequest>(
+ '../../../assets/json-schemas/ocpp/2.0/StatusNotificationRequest.json'
+ ),
],
]);
this.buildRequestPayload.bind(this);
);
}
}
+
+ private parseJsonSchemaFile<T extends JsonType>(relativePath: string): JSONSchemaType<T> {
+ return JSON.parse(
+ fs.readFileSync(
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath),
+ 'utf8'
+ )
+ ) as JSONSchemaType<T>;
+ }
}
this.jsonSchemas = new Map<OCPP20RequestCommand, JSONSchemaType<JsonObject>>([
[
OCPP20RequestCommand.BOOT_NOTIFICATION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/2.0/BootNotificationResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP20BootNotificationResponse>,
+ this.parseJsonSchemaFile<OCPP20BootNotificationResponse>(
+ '../../../assets/json-schemas/ocpp/2.0/BootNotificationResponse.json'
+ ),
],
[
OCPP20RequestCommand.HEARTBEAT,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/2.0/HeartbeatResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP20HeartbeatResponse>,
+ this.parseJsonSchemaFile<OCPP20HeartbeatResponse>(
+ '../../../assets/json-schemas/ocpp/2.0/HeartbeatResponse.json'
+ ),
],
[
OCPP20RequestCommand.STATUS_NOTIFICATION,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/2.0/StatusNotificationResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP20StatusNotificationResponse>,
+ this.parseJsonSchemaFile<OCPP20StatusNotificationResponse>(
+ '../../../assets/json-schemas/ocpp/2.0/StatusNotificationResponse.json'
+ ),
],
]);
this.jsonIncomingRequestResponseSchemas = new Map([
[
OCPP20IncomingRequestCommand.CLEAR_CACHE,
- JSON.parse(
- fs.readFileSync(
- path.resolve(
- path.dirname(fileURLToPath(import.meta.url)),
- '../../../assets/json-schemas/ocpp/2.0/ClearCacheResponse.json'
- ),
- 'utf8'
- )
- ) as JSONSchemaType<OCPP20ClearCacheResponse>,
+ this.parseJsonSchemaFile<OCPP20ClearCacheResponse>(
+ '../../../assets/json-schemas/ocpp/2.0/ClearCacheResponse.json'
+ ),
],
]);
this.validatePayload.bind(this);
);
}
}
+
+ private parseJsonSchemaFile<T extends JsonType>(relativePath: string): JSONSchemaType<T> {
+ return JSON.parse(
+ fs.readFileSync(
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath),
+ 'utf8'
+ )
+ ) as JSONSchemaType<T>;
+ }
}