if (chargingStation.stationInfo?.ocppStrictCompliance === false) {
return true;
}
- if (this.jsonValidateFunctions.has(commandName) === false) {
- this.jsonValidateFunctions.set(commandName, this.ajv.compile<T>(schema).bind(this));
- }
- const validate = this.jsonValidateFunctions.get(commandName)!;
+ const validate = this.getJsonIncomingRequestValidateFunction<T>(commandName, schema);
if (validate(payload)) {
return true;
}
return OCPPConstants.OCPP_RESPONSE_REJECTED;
}
+ private getJsonIncomingRequestValidateFunction<T extends JsonType>(
+ commandName: IncomingRequestCommand,
+ schema: JSONSchemaType<T>,
+ ) {
+ if (this.jsonValidateFunctions.has(commandName) === false) {
+ this.jsonValidateFunctions.set(commandName, this.ajv.compile<T>(schema).bind(this));
+ }
+ return this.jsonValidateFunctions.get(commandName)!;
+ }
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public abstract incomingRequestHandler<ReqType extends JsonType, ResType extends JsonType>(
chargingStation: ChargingStation,
);
return true;
}
- if (this.jsonValidateFunctions.has(commandName as RequestCommand) === false) {
- this.jsonValidateFunctions.set(
- commandName as RequestCommand,
- this.ajv.compile<T>(this.jsonSchemas.get(commandName as RequestCommand)!).bind(this),
- );
- }
- const validate = this.jsonValidateFunctions.get(commandName as RequestCommand)!;
+ const validate = this.getJsonRequestValidateFunction<T>(commandName as RequestCommand);
payload = cloneObject<T>(payload);
OCPPServiceUtils.convertDateToISOString<T>(payload);
if (validate(payload)) {
);
}
+ private getJsonRequestValidateFunction<T extends JsonType>(commandName: RequestCommand) {
+ if (this.jsonValidateFunctions.has(commandName) === false) {
+ this.jsonValidateFunctions.set(
+ commandName,
+ this.ajv.compile<T>(this.jsonSchemas.get(commandName)!).bind(this),
+ );
+ }
+ return this.jsonValidateFunctions.get(commandName)!;
+ }
+
private validateIncomingRequestResponsePayload<T extends JsonType>(
chargingStation: ChargingStation,
commandName: RequestCommand | IncomingRequestCommand,
);
return true;
}
- if (
- this.ocppResponseService.jsonIncomingRequestResponseValidateFunctions.has(
- commandName as IncomingRequestCommand,
- ) === false
- ) {
- this.ocppResponseService.jsonIncomingRequestResponseValidateFunctions.set(
- commandName as IncomingRequestCommand,
- this.ajv
- .compile<T>(
- this.ocppResponseService.jsonIncomingRequestResponseSchemas.get(
- commandName as IncomingRequestCommand,
- )!,
- )
- .bind(this),
- );
- }
- const validate = this.ocppResponseService.jsonIncomingRequestResponseValidateFunctions.get(
+ const validate = this.getJsonRequestResponseValidateFunction<T>(
commandName as IncomingRequestCommand,
- )!;
+ );
payload = cloneObject<T>(payload);
OCPPServiceUtils.convertDateToISOString<T>(payload);
if (validate(payload)) {
);
}
+ private getJsonRequestResponseValidateFunction<T extends JsonType>(
+ commandName: IncomingRequestCommand,
+ ) {
+ if (
+ this.ocppResponseService.jsonIncomingRequestResponseValidateFunctions.has(commandName) ===
+ false
+ ) {
+ this.ocppResponseService.jsonIncomingRequestResponseValidateFunctions.set(
+ commandName,
+ this.ajv
+ .compile<T>(this.ocppResponseService.jsonIncomingRequestResponseSchemas.get(commandName)!)
+ .bind(this),
+ );
+ }
+ return this.ocppResponseService.jsonIncomingRequestResponseValidateFunctions.get(commandName)!;
+ }
+
private async internalSendMessage(
chargingStation: ChargingStation,
messageId: string,
if (chargingStation.stationInfo?.ocppStrictCompliance === false) {
return true;
}
- if (this.jsonRequestValidateFunctions.has(commandName) === false) {
- this.jsonRequestValidateFunctions.set(commandName, this.ajv.compile<T>(schema).bind(this));
- }
- const validate = this.jsonRequestValidateFunctions.get(commandName)!;
+ const validate = this.getJsonRequestValidateFunction<T>(commandName, schema);
if (validate(payload)) {
return true;
}
/* This is intentional */
}
+ private getJsonRequestValidateFunction<T extends JsonType>(
+ commandName: RequestCommand,
+ schema: JSONSchemaType<T>,
+ ) {
+ if (this.jsonRequestValidateFunctions.has(commandName) === false) {
+ this.jsonRequestValidateFunctions.set(commandName, this.ajv.compile<T>(schema).bind(this));
+ }
+ return this.jsonRequestValidateFunctions.get(commandName)!;
+ }
+
public abstract responseHandler<ReqType extends JsonType, ResType extends JsonType>(
chargingStation: ChargingStation,
commandName: RequestCommand,
hasBin: true
dependencies:
caniuse-lite: 1.0.30001562
- electron-to-chromium: 1.4.582
+ electron-to-chromium: 1.4.583
node-releases: 2.0.13
update-browserslist-db: 1.0.13(browserslist@4.22.1)
dev: true
resolution: {integrity: sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==}
dev: false
- /electron-to-chromium@1.4.582:
- resolution: {integrity: sha512-89o0MGoocwYbzqUUjc+VNpeOFSOK9nIdC5wY4N+PVUarUK0MtjyTjks75AZS2bW4Kl8MdewdFsWaH0jLy+JNoA==}
+ /electron-to-chromium@1.4.583:
+ resolution: {integrity: sha512-93y1gcONABZ7uqYe/JWDVQP/Pj/sQSunF0HVAPdlg/pfBnOyBMLlQUxWvkqcljJg1+W6cjvPuYD+r1Th9Tn8mA==}
dev: true
/emoji-regex@8.0.0:
acorn: 8.11.2
pathe: 1.1.1
pkg-types: 1.0.3
- ufo: 1.3.1
+ ufo: 1.3.2
dev: true
/ms@2.0.0:
engines: {node: '>=14.17'}
hasBin: true
- /ufo@1.3.1:
- resolution: {integrity: sha512-uY/99gMLIOlJPwATcMVYfqDSxUR9//AUcgZMzwfSTJPDKzA1S8mX4VLqa+fiAtveraQUBCz4FFcwVZBGbwBXIw==}
+ /ufo@1.3.2:
+ resolution: {integrity: sha512-o+ORpgGwaYQXgqGDwd+hkS4PuZ3QnmqMMxRuajK/a38L6fTpcE5GPIfrf+L/KemFzfUpeUQc1rRS1iDBozvnFA==}
dev: true
/unbox-primitive@1.0.2: