From 478f8019331e7b6256d6e783f90cba19217a7bb6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 1 Apr 2026 01:32:29 +0200 Subject: [PATCH] refactor(ocpp): consolidate Ajv type alias in OCPPServiceUtils Export the Ajv type alias from OCPPServiceUtils and import it in OCPPIncomingRequestService, OCPPRequestService, and OCPPResponseService instead of each file duplicating the _Ajv.default type extraction. --- .../ocpp/OCPPIncomingRequestService.ts | 6 ++---- src/charging-station/ocpp/OCPPRequestService.ts | 11 +++++++---- src/charging-station/ocpp/OCPPResponseService.ts | 6 ++---- src/charging-station/ocpp/OCPPServiceUtils.ts | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/charging-station/ocpp/OCPPIncomingRequestService.ts b/src/charging-station/ocpp/OCPPIncomingRequestService.ts index 45c8f6b7..57d1f5a3 100644 --- a/src/charging-station/ocpp/OCPPIncomingRequestService.ts +++ b/src/charging-station/ocpp/OCPPIncomingRequestService.ts @@ -1,4 +1,4 @@ -import type { default as _Ajv, ValidateFunction } from 'ajv' +import type { ValidateFunction } from 'ajv' import { EventEmitter } from 'node:events' @@ -12,9 +12,7 @@ import { type OCPPVersion, } from '../../types/index.js' import { isAsyncFunction, logger } from '../../utils/index.js' -import { ajvErrorsToErrorType, createAjv } from './OCPPServiceUtils.js' - -type Ajv = _Ajv.default +import { type Ajv, ajvErrorsToErrorType, createAjv } from './OCPPServiceUtils.js' const moduleName = 'OCPPIncomingRequestService' diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 8ddf85e5..5385a9a1 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -1,4 +1,4 @@ -import type { default as _Ajv, ValidateFunction } from 'ajv' +import type { ValidateFunction } from 'ajv' import type { ChargingStation } from '../../charging-station/index.js' import type { OCPPResponseService } from './OCPPResponseService.js' @@ -31,9 +31,12 @@ import { logger, } from '../../utils/index.js' import { OCPPConstants } from './OCPPConstants.js' -import { ajvErrorsToErrorType, convertDateToISOString, createAjv } from './OCPPServiceUtils.js' - -type Ajv = _Ajv.default +import { + type Ajv, + ajvErrorsToErrorType, + convertDateToISOString, + createAjv, +} from './OCPPServiceUtils.js' const moduleName = 'OCPPRequestService' diff --git a/src/charging-station/ocpp/OCPPResponseService.ts b/src/charging-station/ocpp/OCPPResponseService.ts index 44f15090..2975025a 100644 --- a/src/charging-station/ocpp/OCPPResponseService.ts +++ b/src/charging-station/ocpp/OCPPResponseService.ts @@ -1,4 +1,4 @@ -import type { default as _Ajv, ValidateFunction } from 'ajv' +import type { ValidateFunction } from 'ajv' import type { ChargingStation } from '../../charging-station/index.js' @@ -12,9 +12,7 @@ import { type ResponseHandler, } from '../../types/index.js' import { Constants, isAsyncFunction, logger } from '../../utils/index.js' -import { ajvErrorsToErrorType, createAjv } from './OCPPServiceUtils.js' - -type Ajv = _Ajv.default +import { type Ajv, ajvErrorsToErrorType, createAjv } from './OCPPServiceUtils.js' const moduleName = 'OCPPResponseService' diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts index 8995aaae..b9996f4a 100644 --- a/src/charging-station/ocpp/OCPPServiceUtils.ts +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -67,7 +67,7 @@ import { OCPPConstants } from './OCPPConstants.js' const moduleName = 'OCPPServiceUtils' -type Ajv = _Ajv.default +export type Ajv = _Ajv.default // eslint-disable-next-line @typescript-eslint/no-redeclare const Ajv = _Ajv.default const ajvFormats = _ajvFormats.default -- 2.53.0