From 0ac97927984473fcb11a177f013b0e112638e050 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 14 Feb 2023 19:41:06 +0100 Subject: [PATCH] refactor(simulator): explicitly export needed types only MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 10 +- src/types/ConfigurationData.ts | 2 +- src/types/Statistics.ts | 2 +- src/types/index.ts | 208 +++++++++++++++++- src/types/ocpp/1.6/ChargingProfile.ts | 14 +- src/types/ocpp/1.6/MeterValues.ts | 2 +- src/types/ocpp/1.6/Requests.ts | 6 +- src/types/ocpp/1.6/Transaction.ts | 2 +- src/types/ocpp/ChargingProfile.ts | 12 + 9 files changed, 238 insertions(+), 20 deletions(-) diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index b7359677..9424fcf2 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -19,7 +19,6 @@ import { type ChangeAvailabilityResponse, type ChangeConfigurationRequest, type ChangeConfigurationResponse, - ChargingProfilePurposeType, type ClearChargingProfileRequest, type ClearChargingProfileResponse, ErrorType, @@ -40,6 +39,7 @@ import { OCPP16ChargePointErrorCode, OCPP16ChargePointStatus, type OCPP16ChargingProfile, + OCPP16ChargingProfilePurposeType, type OCPP16ClearCacheRequest, type OCPP16DataTransferRequest, type OCPP16DataTransferResponse, @@ -537,14 +537,14 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { } if ( commandPayload.csChargingProfiles.chargingProfilePurpose === - ChargingProfilePurposeType.CHARGE_POINT_MAX_PROFILE && + OCPP16ChargingProfilePurposeType.CHARGE_POINT_MAX_PROFILE && commandPayload.connectorId !== 0 ) { return OCPPConstants.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED; } if ( commandPayload.csChargingProfiles.chargingProfilePurpose === - ChargingProfilePurposeType.TX_PROFILE && + OCPP16ChargingProfilePurposeType.TX_PROFILE && (commandPayload.connectorId === 0 || chargingStation.getConnectorStatus(commandPayload.connectorId)?.transactionStarted === false) @@ -888,14 +888,14 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { connectorId: number, cp: OCPP16ChargingProfile ): boolean { - if (cp && cp.chargingProfilePurpose === ChargingProfilePurposeType.TX_PROFILE) { + if (cp && cp.chargingProfilePurpose === OCPP16ChargingProfilePurposeType.TX_PROFILE) { OCPP16ServiceUtils.setChargingProfile(chargingStation, connectorId, cp); logger.debug( `${chargingStation.logPrefix()} Charging profile(s) set at remote start transaction on connector id ${connectorId}: %j`, cp ); return true; - } else if (cp && cp.chargingProfilePurpose !== ChargingProfilePurposeType.TX_PROFILE) { + } else if (cp && cp.chargingProfilePurpose !== OCPP16ChargingProfilePurposeType.TX_PROFILE) { logger.warn( `${chargingStation.logPrefix()} Not allowed to set ${ cp.chargingProfilePurpose diff --git a/src/types/ConfigurationData.ts b/src/types/ConfigurationData.ts index 246969d9..5a6853d2 100644 --- a/src/types/ConfigurationData.ts +++ b/src/types/ConfigurationData.ts @@ -5,7 +5,7 @@ import type { WorkerChoiceStrategy } from 'poolifier'; import type { ApplicationProtocol, AuthenticationType, StorageType } from './internal'; import type { WorkerProcessType } from '../worker'; -export type ServerOptions = ListenOptions; +type ServerOptions = ListenOptions; export enum SupervisionUrlDistribution { ROUND_ROBIN = 'round-robin', diff --git a/src/types/Statistics.ts b/src/types/Statistics.ts index 93687190..5f22cdaf 100644 --- a/src/types/Statistics.ts +++ b/src/types/Statistics.ts @@ -7,7 +7,7 @@ export type TimeSeries = { value: number; }; -export type StatisticsData = { +type StatisticsData = { countRequest: number; countResponse: number; countError: number; diff --git a/src/types/index.ts b/src/types/index.ts index d4ae9b14..463a7567 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1 +1,207 @@ -export * from './internal'; +export { + AmpereUnits, + ApplicationProtocol, + AuthenticationType, + AuthorizationStatus, + type AuthorizeRequest, + type AuthorizeResponse, + type AutomaticTransactionGeneratorConfiguration, + AvailabilityStatus, + AvailabilityType, + type BootNotificationRequest, + type BootNotificationResponse, + BootReasonEnumType, + BroadcastChannelProcedureName, + type BroadcastChannelRequest, + type BroadcastChannelRequestPayload, + type BroadcastChannelResponse, + type BroadcastChannelResponsePayload, + type CachedRequest, + type ChangeAvailabilityRequest, + type ChangeAvailabilityResponse, + type ChangeConfigurationRequest, + type ChangeConfigurationResponse, + ChargePointErrorCode, + type ChargingProfile, + ChargingProfileKindType, + ChargingProfileStatus, + ChargingRateUnitType, + type ChargingSchedulePeriod, + type ChargingStationConfiguration, + type ChargingStationData, + type ChargingStationInfo, + type ChargingStationOcppConfiguration, + type ChargingStationTemplate, + type ChargingStationWorkerData, + type ChargingStationWorkerMessage, + type ChargingStationWorkerMessageData, + ChargingStationWorkerMessageEvents, + type ClearCacheResponse, + type ClearChargingProfileRequest, + type ClearChargingProfileResponse, + ClearChargingProfileStatus, + type ConfigurationData, + type ConfigurationKey, + ConfigurationStatus, + ConnectorPhaseRotation, + ConnectorStatus, + ConnectorStatusEnum, + CurrentType, + DBName, + type DataTransferRequest, + type DataTransferResponse, + DataTransferStatus, + type DiagnosticsStatusNotificationRequest, + type DiagnosticsStatusNotificationResponse, + type EmptyObject, + type ErrorCallback, + type ErrorResponse, + ErrorType, + FileType, + FirmwareStatus, + type FirmwareStatusNotificationRequest, + type FirmwareStatusNotificationResponse, + type FirmwareUpgrade, + type GenericResponse, + GenericStatus, + type GetConfigurationRequest, + type GetConfigurationResponse, + type GetDiagnosticsRequest, + type GetDiagnosticsResponse, + type HandleErrorParams, + type HeartbeatRequest, + type HeartbeatResponse, + IdTagDistribution, + type IncomingRequest, + IncomingRequestCommand, + type IncomingRequestHandler, + type JsonObject, + type JsonType, + type MeasurandPerPhaseSampledValueTemplates, + type MeasurandValues, + type MessageEvent, + MessageTrigger, + MessageType, + type MeterValue, + MeterValueContext, + MeterValueLocation, + MeterValueMeasurand, + type MeterValuePhase, + MeterValueUnit, + type MeterValuesRequest, + type MeterValuesResponse, + type MikroORMDBType, + OCPP16AuthorizationStatus, + type OCPP16AuthorizeRequest, + type OCPP16AuthorizeResponse, + OCPP16AvailabilityType, + type OCPP16BootNotificationRequest, + type OCPP16BootNotificationResponse, + OCPP16ChargePointErrorCode, + OCPP16ChargePointStatus, + type OCPP16ChargingProfile, + OCPP16ChargingProfilePurposeType, + type OCPP16ClearCacheRequest, + type OCPP16DataTransferRequest, + type OCPP16DataTransferResponse, + OCPP16DataTransferStatus, + OCPP16DataTransferVendorId, + OCPP16DiagnosticsStatus, + type OCPP16DiagnosticsStatusNotificationRequest, + type OCPP16DiagnosticsStatusNotificationResponse, + OCPP16FirmwareStatus, + type OCPP16FirmwareStatusNotificationRequest, + type OCPP16FirmwareStatusNotificationResponse, + type OCPP16HeartbeatRequest, + type OCPP16HeartbeatResponse, + OCPP16IncomingRequestCommand, + OCPP16MessageTrigger, + type OCPP16MeterValue, + OCPP16MeterValueMeasurand, + OCPP16MeterValuePhase, + type OCPP16MeterValuesRequest, + type OCPP16MeterValuesResponse, + OCPP16RequestCommand, + type OCPP16SampledValue, + OCPP16StandardParametersKey, + type OCPP16StartTransactionRequest, + type OCPP16StartTransactionResponse, + type OCPP16StatusNotificationRequest, + type OCPP16StatusNotificationResponse, + OCPP16StopTransactionReason, + type OCPP16StopTransactionRequest, + type OCPP16StopTransactionResponse, + OCPP16SupportedFeatureProfiles, + type OCPP16TriggerMessageRequest, + type OCPP16TriggerMessageResponse, + type OCPP16UpdateFirmwareRequest, + type OCPP16UpdateFirmwareResponse, + type OCPP20BootNotificationRequest, + type OCPP20BootNotificationResponse, + type OCPP20ClearCacheRequest, + type OCPP20ClearCacheResponse, + type OCPP20HeartbeatRequest, + type OCPP20HeartbeatResponse, + OCPP20IncomingRequestCommand, + OCPP20OptionalVariableName, + OCPP20RequestCommand, + type OCPP20StatusNotificationRequest, + type OCPP20StatusNotificationResponse, + type OCPPConfigurationKey, + OCPPVersion, + type OutgoingRequest, + PerformanceData, + PerformanceRecord, + PowerUnits, + ProcedureName, + Protocol, + type ProtocolRequest, + type ProtocolRequestHandler, + type ProtocolResponse, + ProtocolVersion, + RecurrencyKindType, + RegistrationStatusEnumType, + type RemoteStartTransactionRequest, + type RemoteStopTransactionRequest, + RequestCommand, + type RequestParams, + type RequestPayload, + type ResetRequest, + type Response, + type ResponseCallback, + type ResponseHandler, + type ResponsePayload, + ResponseStatus, + type ResponseType, + type SampledValueTemplate, + type SetChargingProfileRequest, + type SetChargingProfileResponse, + StandardParametersKey, + type StartTransactionRequest, + type StartTransactionResponse, + type StationTemplateUrl, + type Statistics, + type Status, + type StatusNotificationRequest, + type StatusNotificationResponse, + StopTransactionReason, + type StopTransactionRequest, + type StopTransactionResponse, + type StorageConfiguration, + StorageType, + SupervisionUrlDistribution, + SupportedFeatureProfiles, + type TimeSeries, + TriggerMessageStatus, + type UIServerConfiguration, + type UnlockConnectorRequest, + type UnlockConnectorResponse, + UnlockStatus, + VendorDefaultParametersKey, + Voltage, + type WSError, + WebSocketCloseEventStatusCode, + WebSocketCloseEventStatusString, + type WorkerConfiguration, + type WsOptions, +} from './internal'; diff --git a/src/types/ocpp/1.6/ChargingProfile.ts b/src/types/ocpp/1.6/ChargingProfile.ts index 1b925bca..0bfdcd2f 100644 --- a/src/types/ocpp/1.6/ChargingProfile.ts +++ b/src/types/ocpp/1.6/ChargingProfile.ts @@ -4,15 +4,15 @@ export interface OCPP16ChargingProfile extends JsonObject { chargingProfileId: number; transactionId?: number; stackLevel: number; - chargingProfilePurpose: ChargingProfilePurposeType; - chargingProfileKind: ChargingProfileKindType; - recurrencyKind?: RecurrencyKindType; + chargingProfilePurpose: OCPP16ChargingProfilePurposeType; + chargingProfileKind: OCPP16ChargingProfileKindType; + recurrencyKind?: OCPP16RecurrencyKindType; validFrom?: Date; validTo?: Date; chargingSchedule: ChargingSchedule; } -export interface ChargingSchedule extends JsonObject { +interface ChargingSchedule extends JsonObject { duration?: number; startSchedule?: Date; chargingRateUnit: OCPP16ChargingRateUnitType; @@ -31,19 +31,19 @@ export enum OCPP16ChargingRateUnitType { AMPERE = 'A', } -export enum ChargingProfileKindType { +export enum OCPP16ChargingProfileKindType { ABSOLUTE = 'Absolute', RECURRING = 'Recurring', RELATIVE = 'Relative', } -export enum ChargingProfilePurposeType { +export enum OCPP16ChargingProfilePurposeType { CHARGE_POINT_MAX_PROFILE = 'ChargePointMaxProfile', TX_DEFAULT_PROFILE = 'TxDefaultProfile', TX_PROFILE = 'TxProfile', } -export enum RecurrencyKindType { +export enum OCPP16RecurrencyKindType { DAILY = 'Daily', WEEKLY = 'Weekly', MONTHLY = 'Monthly', diff --git a/src/types/ocpp/1.6/MeterValues.ts b/src/types/ocpp/1.6/MeterValues.ts index 9fcff5e3..5a59230c 100644 --- a/src/types/ocpp/1.6/MeterValues.ts +++ b/src/types/ocpp/1.6/MeterValues.ts @@ -76,7 +76,7 @@ export enum OCPP16MeterValuePhase { L3_L1 = 'L3-L1', } -export enum MeterValueFormat { +enum MeterValueFormat { RAW = 'Raw', SIGNED_DATA = 'SignedData', } diff --git a/src/types/ocpp/1.6/Requests.ts b/src/types/ocpp/1.6/Requests.ts index 079c1dbb..6b244d04 100644 --- a/src/types/ocpp/1.6/Requests.ts +++ b/src/types/ocpp/1.6/Requests.ts @@ -1,10 +1,10 @@ import type { - ChargingProfilePurposeType, EmptyObject, JsonObject, OCPP16ChargePointErrorCode, OCPP16ChargePointStatus, OCPP16ChargingProfile, + OCPP16ChargingProfilePurposeType, OCPP16DiagnosticsStatus, OCPP16StandardParametersKey, } from '../../internal'; @@ -88,7 +88,7 @@ export interface GetConfigurationRequest extends JsonObject { key?: (string | OCPP16StandardParametersKey)[]; } -export enum ResetType { +enum ResetType { HARD = 'Hard', SOFT = 'Soft', } @@ -115,7 +115,7 @@ export interface ChangeAvailabilityRequest extends JsonObject { export interface ClearChargingProfileRequest extends JsonObject { id?: number; connectorId?: number; - chargingProfilePurpose?: ChargingProfilePurposeType; + chargingProfilePurpose?: OCPP16ChargingProfilePurposeType; stackLevel?: number; } diff --git a/src/types/ocpp/1.6/Transaction.ts b/src/types/ocpp/1.6/Transaction.ts index 8824d1bc..215628f7 100644 --- a/src/types/ocpp/1.6/Transaction.ts +++ b/src/types/ocpp/1.6/Transaction.ts @@ -23,7 +23,7 @@ export enum OCPP16AuthorizationStatus { CONCURRENT_TX = 'ConcurrentTx', } -export interface IdTagInfo extends JsonObject { +interface IdTagInfo extends JsonObject { status: OCPP16AuthorizationStatus; parentIdTag?: string; expiryDate?: Date; diff --git a/src/types/ocpp/ChargingProfile.ts b/src/types/ocpp/ChargingProfile.ts index 643e38db..0b21f109 100644 --- a/src/types/ocpp/ChargingProfile.ts +++ b/src/types/ocpp/ChargingProfile.ts @@ -1,13 +1,25 @@ import { type OCPP16ChargingProfile, + OCPP16ChargingProfileKindType, OCPP16ChargingRateUnitType, type OCPP16ChargingSchedulePeriod, + OCPP16RecurrencyKindType, } from '../internal'; export type ChargingProfile = OCPP16ChargingProfile; export type ChargingSchedulePeriod = OCPP16ChargingSchedulePeriod; +export const ChargingProfileKindType = { + ...OCPP16ChargingProfileKindType, +} as const; +export type ChargingProfileKindType = OCPP16ChargingProfileKindType; + +export const RecurrencyKindType = { + ...OCPP16RecurrencyKindType, +} as const; +export type RecurrencyKindType = OCPP16RecurrencyKindType; + export const ChargingRateUnitType = { ...OCPP16ChargingRateUnitType, } as const; -- 2.34.1