const serviceImpl = service as unknown as TestableOCPP20IncomingRequestService
return {
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
- buildReportData: (serviceImpl as any).buildReportData.bind(service),
+ buildReportData: serviceImpl.buildReportData.bind(service),
handleRequestCertificateSigned: serviceImpl.handleRequestCertificateSigned.bind(service),
handleRequestChangeAvailability: serviceImpl.handleRequestChangeAvailability.bind(service),
handleRequestClearCache: serviceImpl.handleRequestClearCache.bind(service),
import {
type ChargingStationData,
type ChargingStationInfo,
- type ChargingStationOcppConfiguration,
type ChargingStationWorkerMessage,
ChargingStationWorkerMessageEvents,
type Statistics,
bootNotificationResponse: chargingStation.bootNotificationResponse,
connectors: buildConnectorEntries(chargingStation),
evses: buildEvseEntries(chargingStation),
- ocppConfiguration:
- chargingStation.ocppConfiguration ?? ({} as ChargingStationOcppConfiguration),
+ ocppConfiguration: chargingStation.ocppConfiguration ?? {},
started: chargingStation.started,
stationInfo: chargingStation.stationInfo ?? ({} as ChargingStationInfo),
supervisionUrl: chargingStation.wsConnectionUrl.href,
return Object.prototype.toString.call(value).slice(8, -1)
}
+const isObject = (value: unknown): value is object => {
+ return type(value) === 'Object'
+}
+
export const isEmpty = (value: unknown): boolean => {
- const valueType = type(value)
- if (['BigInt', 'Boolean', 'NaN', 'Null', 'Number', 'Undefined'].includes(valueType)) {
+ if (
+ value == null ||
+ typeof value === 'bigint' ||
+ typeof value === 'boolean' ||
+ typeof value === 'number'
+ ) {
return false
}
- if (!value) return true
-
- if (valueType === 'String') {
- return (value as string).trim().length === 0
- }
-
- if (valueType === 'Object') {
- return Object.keys(value as Record<string, unknown>).length === 0
- }
-
- if (valueType === 'Array') {
- return (value as unknown[]).length === 0
- }
-
- if (valueType === 'Map') {
- return (value as Map<unknown, unknown>).size === 0
- }
-
- if (valueType === 'Set') {
- return (value as Set<unknown>).size === 0
- }
+ if (typeof value === 'string') return value.trim().length === 0
+ if (Array.isArray(value)) return value.length === 0
+ if (value instanceof Map) return value.size === 0
+ if (value instanceof Set) return value.size === 0
+ if (isObject(value)) return Object.keys(value).length === 0
return false
}
-const isObject = (value: unknown): value is object => {
- return type(value) === 'Object'
-}
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
export const mergeDeepRight = <T extends object, S extends object>(target: T, source: S): T => {
const output: Record<string, unknown> = { ...(target as Record<string, unknown>) }
if (!isMainThread) {
throw new Error('Cannot get a worker implementation outside the main thread')
}
- workerOptions = mergeDeepRight(DEFAULT_WORKER_OPTIONS, (workerOptions ?? {}) as WorkerOptions)
+ const resolvedOptions = mergeDeepRight(DEFAULT_WORKER_OPTIONS, workerOptions ?? {})
switch (workerProcessType) {
case WorkerProcessType.dynamicPool:
- return new WorkerDynamicPool<D, R>(workerScript, workerOptions)
+ return new WorkerDynamicPool<D, R>(workerScript, resolvedOptions)
case WorkerProcessType.fixedPool:
- return new WorkerFixedPool<D, R>(workerScript, workerOptions)
+ return new WorkerFixedPool<D, R>(workerScript, resolvedOptions)
case WorkerProcessType.workerSet:
- return new WorkerSet<D, R>(workerScript, workerOptions)
+ return new WorkerSet<D, R>(workerScript, resolvedOptions)
default:
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
throw new Error(`Worker implementation type '${workerProcessType}' not found`)