repositories
/
e-mobility-charging-stations-simulator.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix(ci): silence linter
[e-mobility-charging-stations-simulator.git]
/
src
/
charging-station
/
ocpp
/
OCPPIncomingRequestService.ts
diff --git
a/src/charging-station/ocpp/OCPPIncomingRequestService.ts
b/src/charging-station/ocpp/OCPPIncomingRequestService.ts
index d0ff0229350ea4b03c20ea4d5dabd6becaa6f533..06165c2f0514ec79399fa1483b39458bb8ade616 100644
(file)
--- a/
src/charging-station/ocpp/OCPPIncomingRequestService.ts
+++ b/
src/charging-station/ocpp/OCPPIncomingRequestService.ts
@@
-1,8
+1,8
@@
+import { EventEmitter } from 'node:events'
+
import _Ajv, { type ValidateFunction } from 'ajv'
import _ajvFormats from 'ajv-formats'
import _Ajv, { type ValidateFunction } from 'ajv'
import _ajvFormats from 'ajv-formats'
-import { OCPPConstants } from './OCPPConstants.js'
-import { OCPPServiceUtils } from './OCPPServiceUtils.js'
import { type ChargingStation, getIdTagsFile } from '../../charging-station/index.js'
import { OCPPError } from '../../exception/index.js'
import type {
import { type ChargingStation, getIdTagsFile } from '../../charging-station/index.js'
import { OCPPError } from '../../exception/index.js'
import type {
@@
-13,6
+13,8
@@
import type {
OCPPVersion
} from '../../types/index.js'
import { logger, setDefaultErrorParams } from '../../utils/index.js'
OCPPVersion
} from '../../types/index.js'
import { logger, setDefaultErrorParams } from '../../utils/index.js'
+import { OCPPConstants } from './OCPPConstants.js'
+import { ajvErrorsToErrorType } from './OCPPServiceUtils.js'
type Ajv = _Ajv.default
// eslint-disable-next-line @typescript-eslint/no-redeclare
const Ajv = _Ajv.default
type Ajv = _Ajv.default
// eslint-disable-next-line @typescript-eslint/no-redeclare
const Ajv = _Ajv.default
@@
-20,16
+22,17
@@
const ajvFormats = _ajvFormats.default
const moduleName = 'OCPPIncomingRequestService'
const moduleName = 'OCPPIncomingRequestService'
-export abstract class OCPPIncomingRequestService {
+export abstract class OCPPIncomingRequestService
extends EventEmitter
{
private static instance: OCPPIncomingRequestService | null = null
private readonly version: OCPPVersion
protected readonly ajv: Ajv
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>
>
protected constructor (version: OCPPVersion) {
IncomingRequestCommand,
ValidateFunction<JsonType>
>
protected constructor (version: OCPPVersion) {
+ super()
this.version = version
this.ajv = new Ajv({
keywords: ['javaType'],
this.version = version
this.ajv = new Ajv({
keywords: ['javaType'],
@@
-53,7
+56,7
@@
export abstract class OCPPIncomingRequestService {
error: Error,
params: HandleErrorParams<T> = { throwError: true, consoleOut: false }
): T | undefined {
error: Error,
params: HandleErrorParams<T> = { throwError: true, consoleOut: false }
): T | undefined {
- setDefaultErrorParams(params)
+
params =
setDefaultErrorParams(params)
logger.error(
`${chargingStation.logPrefix()} ${moduleName}.handleIncomingRequestError: Incoming request command '${commandName}' error:`,
error
logger.error(
`${chargingStation.logPrefix()} ${moduleName}.handleIncomingRequestError: Incoming request command '${commandName}' error:`,
error
@@
-77,7
+80,7
@@
export abstract class OCPPIncomingRequestService {
if (chargingStation.stationInfo?.ocppStrictCompliance === false) {
return true
}
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
}
if (validate?.(payload) === true) {
return true
}
@@
-86,7
+89,7
@@
export abstract class OCPPIncomingRequestService {
validate?.errors
)
throw new OCPPError(
validate?.errors
)
throw new OCPPError(
-
OCPPServiceUtils.
ajvErrorsToErrorType(validate?.errors),
+ ajvErrorsToErrorType(validate?.errors),
'Incoming request PDU is invalid',
commandName,
JSON.stringify(validate?.errors, undefined, 2)
'Incoming request PDU is invalid',
commandName,
JSON.stringify(validate?.errors, undefined, 2)