From 73ed6e010e5e8b671bb6fc3dd9d0273d6f67f2cc Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 29 Jul 2023 01:14:53 +0200 Subject: [PATCH] fix: fix circular dependencies in types MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/types/index.ts | 4 +--- src/types/ocpp/1.6/Responses.ts | 2 +- src/types/ocpp/2.0/Common.ts | 2 +- src/types/ocpp/2.0/Responses.ts | 2 +- src/types/ocpp/Common.ts | 16 ++++++++++++++++ src/types/ocpp/Requests.ts | 10 +++++----- src/types/ocpp/Responses.ts | 22 ++++------------------ 7 files changed, 29 insertions(+), 29 deletions(-) create mode 100644 src/types/ocpp/Common.ts diff --git a/src/types/index.ts b/src/types/index.ts index a5ab58ca..f65e4cae 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -17,6 +17,7 @@ export { IdTagDistribution, type Status, } from './AutomaticTransactionGenerator'; +export { type GenericResponse, GenericStatus, RegistrationStatusEnumType } from './ocpp/Common'; export { AvailabilityType, type BootNotificationRequest, @@ -51,11 +52,8 @@ export { type DiagnosticsStatusNotificationResponse, type ErrorResponse, type FirmwareStatusNotificationResponse, - GenericStatus, - type GenericResponse, type HeartbeatResponse, type MeterValuesResponse, - RegistrationStatusEnumType, type Response, type ResponseHandler, type StatusNotificationResponse, diff --git a/src/types/ocpp/1.6/Responses.ts b/src/types/ocpp/1.6/Responses.ts index 9cd96b24..2e5e285b 100644 --- a/src/types/ocpp/1.6/Responses.ts +++ b/src/types/ocpp/1.6/Responses.ts @@ -1,8 +1,8 @@ import type { OCPP16ChargingSchedule } from './ChargingProfile'; import type { EmptyObject } from '../../EmptyObject'; import type { JsonObject } from '../../JsonType'; +import type { GenericStatus, RegistrationStatusEnumType } from '../Common'; import type { OCPPConfigurationKey } from '../Configuration'; -import { GenericStatus, type RegistrationStatusEnumType } from '../Responses'; export interface OCPP16HeartbeatResponse extends JsonObject { currentTime: Date; diff --git a/src/types/ocpp/2.0/Common.ts b/src/types/ocpp/2.0/Common.ts index 511cce00..e9226961 100644 --- a/src/types/ocpp/2.0/Common.ts +++ b/src/types/ocpp/2.0/Common.ts @@ -1,5 +1,5 @@ import type { JsonObject } from '../../JsonType'; -import type { GenericStatus } from '../Responses'; +import type { GenericStatus } from '../Common'; export enum DataEnumType { // eslint-disable-next-line id-blacklist diff --git a/src/types/ocpp/2.0/Responses.ts b/src/types/ocpp/2.0/Responses.ts index ab6357a9..a4ecdadd 100644 --- a/src/types/ocpp/2.0/Responses.ts +++ b/src/types/ocpp/2.0/Responses.ts @@ -6,7 +6,7 @@ import type { import type { OCPP20SetVariableResultType } from './Variables'; import type { EmptyObject } from '../../EmptyObject'; import type { JsonObject } from '../../JsonType'; -import type { RegistrationStatusEnumType } from '../Responses'; +import type { RegistrationStatusEnumType } from '../Common'; export type OCPP20BootNotificationResponse = { currentTime: Date; diff --git a/src/types/ocpp/Common.ts b/src/types/ocpp/Common.ts new file mode 100644 index 00000000..a4422b18 --- /dev/null +++ b/src/types/ocpp/Common.ts @@ -0,0 +1,16 @@ +import type { JsonObject } from '../JsonType'; + +export enum GenericStatus { + Accepted = 'Accepted', + Rejected = 'Rejected', +} + +export interface GenericResponse extends JsonObject { + status: GenericStatus; +} + +export enum RegistrationStatusEnumType { + ACCEPTED = 'Accepted', + PENDING = 'Pending', + REJECTED = 'Rejected', +} diff --git a/src/types/ocpp/Requests.ts b/src/types/ocpp/Requests.ts index a2407476..4cb32e27 100644 --- a/src/types/ocpp/Requests.ts +++ b/src/types/ocpp/Requests.ts @@ -49,6 +49,11 @@ export type IncomingRequestCommand = OCPP16IncomingRequestCommand | OCPP20Incomi export type IncomingRequest = [MessageType.CALL_MESSAGE, string, IncomingRequestCommand, JsonType]; +export type IncomingRequestHandler = ( + chargingStation: ChargingStation, + commandPayload: JsonType, +) => JsonType | Promise; + export type ResponseCallback = (payload: JsonType, requestPayload: JsonType) => void; export type ErrorCallback = (error: OCPPError, requestStatistic?: boolean) => void; @@ -81,11 +86,6 @@ export type DiagnosticsStatusNotificationRequest = OCPP16DiagnosticsStatusNotifi export type FirmwareStatusNotificationRequest = OCPP16FirmwareStatusNotificationRequest; -export type IncomingRequestHandler = ( - chargingStation: ChargingStation, - commandPayload: JsonType, -) => JsonType | Promise; - export const AvailabilityType = { ...OCPP16AvailabilityType, ...OperationalStatusEnumType, diff --git a/src/types/ocpp/Responses.ts b/src/types/ocpp/Responses.ts index 2cd2f369..8107e274 100644 --- a/src/types/ocpp/Responses.ts +++ b/src/types/ocpp/Responses.ts @@ -16,10 +16,11 @@ import { OCPP16UnlockStatus, } from './1.6/Responses'; import type { OCPP20BootNotificationResponse, OCPP20ClearCacheResponse } from './2.0/Responses'; +import { type GenericResponse, GenericStatus } from './Common'; import type { ErrorType } from './ErrorType'; import type { MessageType } from './MessageType'; import type { ChargingStation } from '../../charging-station'; -import type { JsonObject, JsonType } from '../JsonType'; +import type { JsonType } from '../JsonType'; export type Response = [MessageType.CALL_RESULT_MESSAGE, string, JsonType]; @@ -49,21 +50,6 @@ export type DiagnosticsStatusNotificationResponse = OCPP16DiagnosticsStatusNotif export type FirmwareStatusNotificationResponse = OCPP16FirmwareStatusNotificationResponse; -export enum GenericStatus { - Accepted = 'Accepted', - Rejected = 'Rejected', -} - -export interface GenericResponse extends JsonObject { - status: GenericStatus; -} - -export enum RegistrationStatusEnumType { - ACCEPTED = 'Accepted', - PENDING = 'Pending', - REJECTED = 'Rejected', -} - export const AvailabilityStatus = { ...OCPP16AvailabilityStatus, } as const; @@ -102,11 +88,11 @@ export type DataTransferStatus = OCPP16DataTransferStatus; export type ReservationStatus = OCPP16ReservationStatus; export const ReservationStatus = { ...OCPP16ReservationStatus, -}; +} as const; export type CancelReservationStatus = GenericStatus; export const CancelReservationStatus = { ...GenericStatus, -}; +} as const; export type CancelReservationResponse = GenericResponse; -- 2.34.1