type RequestPayload,
type ResponsePayload,
type UIServerConfiguration,
+ type UUIDv4,
} from '../../types/index.js'
import { isEmpty, logger } from '../../utils/index.js'
import { UIServiceFactory } from './ui-services/UIServiceFactory.js'
export abstract class AbstractUIServer {
protected readonly httpServer: Http2Server | Server
- protected readonly responseHandlers: Map<
- `${string}-${string}-${string}-${string}-${string}`,
- ServerResponse | WebSocket
- >
+ protected readonly responseHandlers: Map<UUIDv4, ServerResponse | WebSocket>
protected readonly uiServices: Map<ProtocolVersion, AbstractUIService>
`Unsupported application protocol version ${this.uiServerConfiguration.version} in '${ConfigurationSection.uiServer}' configuration section`
)
}
- this.responseHandlers = new Map<
- `${string}-${string}-${string}-${string}-${string}`,
- ServerResponse | WebSocket
- >()
+ this.responseHandlers = new Map<UUIDv4, ServerResponse | WebSocket>()
this.uiServices = new Map<ProtocolVersion, AbstractUIService>()
}
public buildProtocolRequest (
- uuid: `${string}-${string}-${string}-${string}-${string}`,
+ uuid: UUIDv4,
procedureName: ProcedureName,
requestPayload: RequestPayload
): ProtocolRequest {
return [uuid, procedureName, requestPayload]
}
- public buildProtocolResponse (
- uuid: `${string}-${string}-${string}-${string}-${string}`,
- responsePayload: ResponsePayload
- ): ProtocolResponse {
+ public buildProtocolResponse (uuid: UUIDv4, responsePayload: ResponsePayload): ProtocolResponse {
return [uuid, responsePayload]
}
return this.chargingStationTemplates.has(template)
}
- public hasResponseHandler (uuid: `${string}-${string}-${string}-${string}-${string}`): boolean {
+ public hasResponseHandler (uuid: UUIDv4): boolean {
return this.responseHandlers.has(uuid)
}
type ResponsePayload,
ResponseStatus,
type StorageConfiguration,
+ type UUIDv4,
} from '../../../types/index.js'
import { Configuration, isAsyncFunction, isNotEmptyArray, logger } from '../../../utils/index.js'
import { Bootstrap } from '../../Bootstrap.js'
])
protected readonly requestHandlers: Map<ProcedureName, ProtocolRequestHandler>
- private readonly broadcastChannelRequests: Map<
- `${string}-${string}-${string}-${string}-${string}`,
- number
- >
+ private readonly broadcastChannelRequests: Map<UUIDv4, number>
private readonly uiServer: AbstractUIServer
private readonly uiServiceWorkerBroadcastChannel: UIServiceWorkerBroadcastChannel
[ProcedureName.STOP_SIMULATOR, this.handleStopSimulator.bind(this)],
])
this.uiServiceWorkerBroadcastChannel = new UIServiceWorkerBroadcastChannel(this)
- this.broadcastChannelRequests = new Map<
- `${string}-${string}-${string}-${string}-${string}`,
- number
- >()
+ this.broadcastChannelRequests = new Map<UUIDv4, number>()
}
- public deleteBroadcastChannelRequest (
- uuid: `${string}-${string}-${string}-${string}-${string}`
- ): void {
+ public deleteBroadcastChannelRequest (uuid: UUIDv4): void {
this.broadcastChannelRequests.delete(uuid)
}
- public getBroadcastChannelExpectedResponses (
- uuid: `${string}-${string}-${string}-${string}-${string}`
- ): number {
+ public getBroadcastChannelExpectedResponses (uuid: UUIDv4): number {
return this.broadcastChannelRequests.get(uuid) ?? 0
}
}
public async requestHandler (request: ProtocolRequest): Promise<ProtocolResponse | undefined> {
- let uuid: `${string}-${string}-${string}-${string}-${string}` | undefined
+ let uuid: undefined | UUIDv4
let command: ProcedureName | undefined
let requestPayload: RequestPayload | undefined
let responsePayload: ResponsePayload | undefined
}
// public sendRequest (
- // uuid: `${string}-${string}-${string}-${string}-${string}`,
+ // uuid: UUIDv4,
// procedureName: ProcedureName,
// requestPayload: RequestPayload
// ): void {
// )
// }
- public sendResponse (
- uuid: `${string}-${string}-${string}-${string}-${string}`,
- responsePayload: ResponsePayload
- ): void {
+ public sendResponse (uuid: UUIDv4, responsePayload: ResponsePayload): void {
if (this.uiServer.hasResponseHandler(uuid)) {
this.uiServer.sendResponse(this.uiServer.buildProtocolResponse(uuid, responsePayload))
} else {
}
protected handleProtocolRequest (
- uuid: `${string}-${string}-${string}-${string}-${string}`,
+ uuid: UUIDv4,
procedureName: ProcedureName,
payload: RequestPayload
): void {
}
private async handleAddChargingStations (
- _uuid?: `${string}-${string}-${string}-${string}-${string}`,
+ _uuid?: UUIDv4,
_procedureName?: ProcedureName,
requestPayload?: RequestPayload
): Promise<ResponsePayload> {
}
private sendBroadcastChannelRequest (
- uuid: `${string}-${string}-${string}-${string}-${string}`,
+ uuid: UUIDv4,
procedureName: BroadcastChannelProcedureName,
payload: BroadcastChannelRequestPayload
): void {
import type { JsonObject } from './JsonType.js'
import type { BootNotificationResponse } from './ocpp/Responses.js'
import type { Statistics } from './Statistics.js'
+import type { UUIDv4 } from './UUID.js'
import { ChargingStationEvents } from './ChargingStationEvents.js'
export interface ChargingStationWorkerMessage<T extends ChargingStationWorkerMessageData> {
data: T
event: ChargingStationWorkerMessageEvents
- uuid?: string
+ uuid?: UUIDv4
}
export type ChargingStationWorkerMessageData = ChargingStationData | Statistics
import type { JsonObject } from './JsonType.js'
+import type { UUIDv4 } from './UUID.js'
import type { BroadcastChannelResponsePayload } from './WorkerBroadcastChannel.js'
export enum ApplicationProtocol {
SUCCESS = 'success',
}
-export type ProtocolRequest = [
- `${string}-${string}-${string}-${string}-${string}`,
- ProcedureName,
- RequestPayload
-]
+export type ProtocolRequest = [UUIDv4, ProcedureName, RequestPayload]
export type ProtocolRequestHandler = (
- uuid?: `${string}-${string}-${string}-${string}-${string}`,
+ uuid?: UUIDv4,
procedureName?: ProcedureName,
payload?: RequestPayload
) => Promise<ResponsePayload> | Promise<undefined> | ResponsePayload | undefined
-export type ProtocolResponse = [
- `${string}-${string}-${string}-${string}-${string}`,
- ResponsePayload
-]
+export type ProtocolResponse = [UUIDv4, ResponsePayload]
export interface RequestPayload extends JsonObject {
connectorIds?: number[]
--- /dev/null
+/**
+ * UUIDv4 type representing a standard UUID format
+ * Pattern: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
+ * where x is any hexadecimal digit and y is one of 8, 9, A, or B
+ */
+export type UUIDv4 = `${string}-${string}-${string}-${string}-${string}`
import type { RequestPayload, ResponsePayload } from './UIProtocol.js'
+import type { UUIDv4 } from './UUID.js'
export enum BroadcastChannelProcedureName {
AUTHORIZE = 'authorize',
}
export type BroadcastChannelRequest = [
- `${string}-${string}-${string}-${string}-${string}`,
+ UUIDv4,
BroadcastChannelProcedureName,
BroadcastChannelRequestPayload
]
transactionId?: number
}
-export type BroadcastChannelResponse = [
- `${string}-${string}-${string}-${string}-${string}`,
- BroadcastChannelResponsePayload
-]
+export type BroadcastChannelResponse = [UUIDv4, BroadcastChannelResponsePayload]
export interface BroadcastChannelResponsePayload
extends Omit<ResponsePayload, 'hashIdsFailed' | 'hashIdsSucceeded' | 'responsesFailed'> {
type ResponsePayload,
ResponseStatus,
} from './UIProtocol.js'
+export type { UUIDv4 } from './UUID.js'
export {
WebSocketCloseEventStatusCode,
WebSocketCloseEventStatusString,
export interface OCPP20RequestStopTransactionRequest extends JsonObject {
customData?: CustomDataType
- transactionId: `${string}-${string}-${string}-${string}-${string}`
+ transactionId: UUIDv4
}
export interface OCPP20ResetRequest extends JsonObject {
customData?: CustomDataType
status: RequestStartStopStatusEnumType
statusInfo?: StatusInfoType
- transactionId?: `${string}-${string}-${string}-${string}-${string}`
+ transactionId?: UUIDv4
}
export interface OCPP20RequestStopTransactionResponse extends JsonObject {
remoteStartId?: number
stoppedReason?: OCPP20ReasonEnumType
timeSpentCharging?: number
- transactionId: `${string}-${string}-${string}-${string}-${string}`
+ transactionId: UUIDv4
}
export interface RelativeTimeIntervalType extends JsonObject {
type JsonType,
MapStringifyFormat,
type TimestampedData,
+ type UUIDv4,
WebSocketCloseEventStatusString,
} from '../types/index.js'
return output as T
}
-export const generateUUID = (): `${string}-${string}-${string}-${string}-${string}` => {
+export const generateUUID = (): UUIDv4 => {
return randomUUID()
}
-export const validateUUID = (
- uuid: unknown
-): uuid is `${string}-${string}-${string}-${string}-${string}` => {
+export const validateUUID = (uuid: unknown): uuid is UUIDv4 => {
if (typeof uuid !== 'string') {
return false
}
import { EMPTY_FUNCTION, workerSetVersion } from './WorkerConstants.js'
import {
type SetInfo,
+ type UUIDv4,
type WorkerData,
type WorkerMessage,
WorkerMessageEvents,
return this.workerSet.size
}
- private readonly promiseResponseMap: Map<
- `${string}-${string}-${string}-${string}-${string}`,
- ResponseWrapper<R>
- >
+ private readonly promiseResponseMap: Map<UUIDv4, ResponseWrapper<R>>
private started: boolean
private readonly workerSet: Set<WorkerSetElement>
throw new RangeError('Elements per worker must be greater than zero')
}
this.workerSet = new Set<WorkerSetElement>()
- this.promiseResponseMap = new Map<
- `${string}-${string}-${string}-${string}-${string}`,
- ResponseWrapper<R>
- >()
+ this.promiseResponseMap = new Map<UUIDv4, ResponseWrapper<R>>()
if (this.workerOptions.poolOptions?.enableEvents === true) {
this.emitter = new EventEmitterAsyncResource({ name: 'workerset' })
}
worker: string
}
+/**
+ * UUIDv4 type representing a standard UUID format
+ * Pattern: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
+ * where x is any hexadecimal digit and y is one of 8, 9, A, or B
+ */
+export type UUIDv4 = `${string}-${string}-${string}-${string}-${string}`
+
export type WorkerData = Record<string, unknown>
export interface WorkerDataError extends WorkerData {
export interface WorkerMessage<T extends WorkerData> {
data: T
event: WorkerMessageEvents
- uuid: `${string}-${string}-${string}-${string}-${string}`
+ uuid: UUIDv4
}
export interface WorkerOptions extends Record<string, unknown> {
OCPP20RequestStartTransactionRequest,
OCPP20RequestStopTransactionRequest,
OCPP20TransactionEventRequest,
+ UUIDv4,
} from '../../../../src/types/index.js'
import { OCPP20IncomingRequestService } from '../../../../src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.js'
// Create stop transaction request
const stopRequest: OCPP20RequestStopTransactionRequest = {
- transactionId: transactionId as `${string}-${string}-${string}-${string}-${string}`,
+ transactionId: transactionId as UUIDv4,
}
// Execute stop transaction
// Stop the second transaction
const stopRequest: OCPP20RequestStopTransactionRequest = {
- transactionId: transactionId2 as `${string}-${string}-${string}-${string}-${string}`,
+ transactionId: transactionId2 as UUIDv4,
}
const response = await (incomingRequestService as any).handleRequestStopTransaction(
const nonExistentTransactionId = 'non-existent-transaction-id'
const stopRequest: OCPP20RequestStopTransactionRequest = {
- transactionId:
- nonExistentTransactionId as `${string}-${string}-${string}-${string}-${string}`,
+ transactionId: nonExistentTransactionId as UUIDv4,
}
const response = await (incomingRequestService as any).handleRequestStopTransaction(
sentTransactionEvents = []
const invalidRequest: OCPP20RequestStopTransactionRequest = {
- transactionId: '' as `${string}-${string}-${string}-${string}-${string}`,
+ transactionId: '' as UUIDv4,
}
const response = await (incomingRequestService as any).handleRequestStopTransaction(
// Create a transaction ID longer than 36 characters
const tooLongTransactionId = 'a'.repeat(37)
const invalidRequest: OCPP20RequestStopTransactionRequest = {
- transactionId: tooLongTransactionId as `${string}-${string}-${string}-${string}-${string}`,
+ transactionId: tooLongTransactionId as UUIDv4,
}
const response = await (incomingRequestService as any).handleRequestStopTransaction(
}
const stopRequest: OCPP20RequestStopTransactionRequest = {
- transactionId: testTransactionId as `${string}-${string}-${string}-${string}-${string}`,
+ transactionId: testTransactionId as UUIDv4,
}
const response = await (incomingRequestService as any).handleRequestStopTransaction(
// Attempt to stop the transaction
const stopRequest: OCPP20RequestStopTransactionRequest = {
- transactionId: transactionId as `${string}-${string}-${string}-${string}-${string}`,
+ transactionId: transactionId as UUIDv4,
}
const response = await (incomingRequestService as any).handleRequestStopTransaction(
const transactionId = await startTransaction(1, 400)
const stopRequest: OCPP20RequestStopTransactionRequest = {
- transactionId: transactionId as `${string}-${string}-${string}-${string}-${string}`,
+ transactionId: transactionId as UUIDv4,
}
const response = await (incomingRequestService as any).handleRequestStopTransaction(
data: 'Custom stop transaction data',
vendorId: 'TestVendor',
},
- transactionId: transactionId as `${string}-${string}-${string}-${string}-${string}`,
+ transactionId: transactionId as UUIDv4,
}
const response = await (incomingRequestService as any).handleRequestStopTransaction(
const transactionId = await startTransaction(2, 600) // Use EVSE 2
const stopRequest: OCPP20RequestStopTransactionRequest = {
- transactionId: transactionId as `${string}-${string}-${string}-${string}-${string}`,
+ transactionId: transactionId as UUIDv4,
}
const response = await (incomingRequestService as any).handleRequestStopTransaction(