} from '../types/index.js'
import {
Constants,
- cloneObject,
+ clone,
convertToDate,
formatDurationMilliSeconds,
getRandomInteger,
private getConnectorStatus (connectorId: number): Status {
const connectorStatus =
this.chargingStation.getAutomaticTransactionGeneratorStatuses()?.[connectorId - 1] != null
- ? cloneObject<Status>(
+ ? clone<Status>(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.chargingStation.getAutomaticTransactionGeneratorStatuses()![connectorId - 1]
)
buildStartedMessage,
buildStoppedMessage,
buildUpdatedMessage,
- cloneObject,
+ clone,
convertToBoolean,
convertToDate,
convertToInt,
private initializeConnectorsOrEvsesFromFile (configuration: ChargingStationConfiguration): void {
if (configuration.connectorsStatus != null && configuration.evsesStatus == null) {
for (const [connectorId, connectorStatus] of configuration.connectorsStatus.entries()) {
- this.connectors.set(connectorId, cloneObject<ConnectorStatus>(connectorStatus))
+ this.connectors.set(connectorId, clone<ConnectorStatus>(connectorStatus))
}
} else if (configuration.evsesStatus != null && configuration.connectorsStatus == null) {
for (const [evseId, evseStatusConfiguration] of configuration.evsesStatus.entries()) {
- const evseStatus = cloneObject<EvseStatusConfiguration>(evseStatusConfiguration)
+ const evseStatus = clone<EvseStatusConfiguration>(evseStatusConfiguration)
delete evseStatus.connectorsStatus
this.evses.set(evseId, {
...(evseStatus as EvseStatus),
this.logPrefix(),
this.templateFile
)
- this.connectors.set(connectorId, cloneObject<ConnectorStatus>(connectorStatus))
+ this.connectors.set(connectorId, clone<ConnectorStatus>(connectorStatus))
}
initializeConnectorsMapStatus(this.connectors, this.logPrefix())
this.saveConnectorsStatus()
const configurationFromFile = this.getConfigurationFromFile()
let configurationData: ChargingStationConfiguration =
configurationFromFile != null
- ? cloneObject<ChargingStationConfiguration>(configurationFromFile)
+ ? clone<ChargingStationConfiguration>(configurationFromFile)
: {}
if (this.stationInfo?.stationInfoPersistentConfiguration === true) {
configurationData.stationInfo = this.stationInfo
ACElectricUtils,
Constants,
DCElectricUtils,
- cloneObject,
+ clone,
convertToDate,
convertToInt,
isArraySorted,
const connectorStatus = connectors[connector]
const connectorId = convertToInt(connector)
checkStationInfoConnectorStatus(connectorId, connectorStatus, logPrefix, templateFile)
- connectorsMap.set(connectorId, cloneObject<ConnectorStatus>(connectorStatus))
+ connectorsMap.set(connectorId, clone<ConnectorStatus>(connectorStatus))
}
} else {
logger.warn(
export const stationTemplateToStationInfo = (
stationTemplate: ChargingStationTemplate
): ChargingStationInfo => {
- stationTemplate = cloneObject<ChargingStationTemplate>(stationTemplate)
+ stationTemplate = clone<ChargingStationTemplate>(stationTemplate)
delete stationTemplate.power
delete stationTemplate.powerUnit
delete stationTemplate.Connectors
chargingStation: ChargingStation,
connectorId: number
): ChargingProfile[] => {
- return cloneObject<ChargingProfile[]>(
+ return clone<ChargingProfile[]>(
(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles ?? [])
.sort((a, b) => b.stackLevel - a.stackLevel)
.concat(
type ResponseType
} from '../../types/index.js'
import {
- cloneObject,
+ clone,
formatDurationMilliSeconds,
handleSendMessageError,
logger
return true
}
const validate = this.getJsonRequestValidateFunction<T>(commandName as RequestCommand)
- payload = cloneObject<T>(payload)
+ payload = clone<T>(payload)
OCPPServiceUtils.convertDateToISOString<T>(payload)
if (validate(payload)) {
return true
const validate = this.getJsonRequestResponseValidateFunction<T>(
commandName as IncomingRequestCommand
)
- payload = cloneObject<T>(payload)
+ payload = clone<T>(payload)
OCPPServiceUtils.convertDateToISOString<T>(payload)
if (validate(payload)) {
return true
return clone as O
}
-export const cloneObject = <T>(object: T): T => {
+export const clone = <T>(object: T): T => {
return deepClone(object as CloneableData) as T
}
} from './MessageChannelUtils.js'
export {
JSONStringifyWithMapSupport,
- cloneObject,
+ clone,
convertToBoolean,
convertToDate,
convertToFloat,
import { Constants } from '../../src/utils/Constants.js'
import {
- cloneObject,
+ clone,
convertToBoolean,
convertToDate,
convertToFloat,
expect(formatDurationSeconds(hoursToSeconds(4380))).toBe('182 days 12 hours')
})
- await it('Verify isValidTime()', () => {
+ await it('Verify isValidDate()', () => {
expect(isValidDate(undefined)).toBe(false)
expect(isValidDate(-1)).toBe(true)
expect(isValidDate(0)).toBe(true)
expect(isObject(new WeakSet())).toBe(true)
})
- await it('Verify cloneObject()', () => {
+ await it('Verify clone()', () => {
const obj = { 1: 1 }
- expect(cloneObject(obj)).toStrictEqual(obj)
- expect(cloneObject(obj) === obj).toBe(false)
+ expect(clone(obj)).toStrictEqual(obj)
+ expect(clone(obj) === obj).toBe(false)
const nestedObj = { 1: obj, 2: obj }
- expect(cloneObject(nestedObj)).toStrictEqual(nestedObj)
- expect(cloneObject(nestedObj) === nestedObj).toBe(false)
+ expect(clone(nestedObj)).toStrictEqual(nestedObj)
+ expect(clone(nestedObj) === nestedObj).toBe(false)
const array = [1, 2]
- expect(cloneObject(array)).toStrictEqual(array)
- expect(cloneObject(array) === array).toBe(false)
+ expect(clone(array)).toStrictEqual(array)
+ expect(clone(array) === array).toBe(false)
const objArray = [obj, obj]
- expect(cloneObject(objArray)).toStrictEqual(objArray)
- expect(cloneObject(objArray) === objArray).toBe(false)
+ expect(clone(objArray)).toStrictEqual(objArray)
+ expect(clone(objArray) === objArray).toBe(false)
const date = new Date()
- expect(cloneObject(date)).toStrictEqual(date)
- expect(cloneObject(date) === date).toBe(false)
+ expect(clone(date)).toStrictEqual(date)
+ expect(clone(date) === date).toBe(false)
const map = new Map([['1', '2']])
- expect(cloneObject(map)).toStrictEqual({})
+ expect(clone(map)).toStrictEqual({})
const set = new Set(['1'])
- expect(cloneObject(set)).toStrictEqual({})
+ expect(clone(set)).toStrictEqual({})
// The URL object seems to have not enumerable properties
const url = new URL('https://domain.tld')
- expect(cloneObject(url)).toStrictEqual({})
+ expect(clone(url)).toStrictEqual({})
const weakMap = new WeakMap([[{ 1: 1 }, { 2: 2 }]])
- expect(cloneObject(weakMap)).toStrictEqual({})
+ expect(clone(weakMap)).toStrictEqual({})
const weakSet = new WeakSet([{ 1: 1 }, { 2: 2 }])
- expect(cloneObject(weakSet)).toStrictEqual({})
+ expect(clone(weakSet)).toStrictEqual({})
})
await it('Verify hasOwnProp()', () => {