import { env } from 'node:process'
import { fileURLToPath } from 'node:url'
import { mergeDeepRight, once } from 'rambda'
+import { has } from 'rambda'
import {
ApplicationProtocol,
logPrefix,
} from './ConfigurationUtils.js'
import { Constants } from './Constants.js'
-import { hasOwnProp, isCFEnvironment } from './Utils.js'
+import { isCFEnvironment } from './Utils.js'
type ConfigurationSectionType =
| LogConfiguration
private static buildLogSection (): LogConfiguration {
const deprecatedLogConfiguration: LogConfiguration = {
- ...(hasOwnProp(Configuration.getConfigurationData(), 'logEnabled') && {
+ ...(has(Configuration.getConfigurationData(), 'logEnabled') && {
// eslint-disable-next-line @typescript-eslint/no-deprecated
enabled: Configuration.getConfigurationData()?.logEnabled,
}),
- ...(hasOwnProp(Configuration.getConfigurationData(), 'logFile') && {
+ ...(has(Configuration.getConfigurationData(), 'logFile') && {
// eslint-disable-next-line @typescript-eslint/no-deprecated
file: Configuration.getConfigurationData()?.logFile,
}),
- ...(hasOwnProp(Configuration.getConfigurationData(), 'logErrorFile') && {
+ ...(has(Configuration.getConfigurationData(), 'logErrorFile') && {
// eslint-disable-next-line @typescript-eslint/no-deprecated
errorFile: Configuration.getConfigurationData()?.logErrorFile,
}),
- ...(hasOwnProp(Configuration.getConfigurationData(), 'logStatisticsInterval') && {
+ ...(has(Configuration.getConfigurationData(), 'logStatisticsInterval') && {
// eslint-disable-next-line @typescript-eslint/no-deprecated
statisticsInterval: Configuration.getConfigurationData()?.logStatisticsInterval,
}),
- ...(hasOwnProp(Configuration.getConfigurationData(), 'logLevel') && {
+ ...(has(Configuration.getConfigurationData(), 'logLevel') && {
// eslint-disable-next-line @typescript-eslint/no-deprecated
level: Configuration.getConfigurationData()?.logLevel,
}),
- ...(hasOwnProp(Configuration.getConfigurationData(), 'logConsole') && {
+ ...(has(Configuration.getConfigurationData(), 'logConsole') && {
// eslint-disable-next-line @typescript-eslint/no-deprecated
console: Configuration.getConfigurationData()?.logConsole,
}),
- ...(hasOwnProp(Configuration.getConfigurationData(), 'logFormat') && {
+ ...(has(Configuration.getConfigurationData(), 'logFormat') && {
// eslint-disable-next-line @typescript-eslint/no-deprecated
format: Configuration.getConfigurationData()?.logFormat,
}),
- ...(hasOwnProp(Configuration.getConfigurationData(), 'logRotate') && {
+ ...(has(Configuration.getConfigurationData(), 'logRotate') && {
// eslint-disable-next-line @typescript-eslint/no-deprecated
rotate: Configuration.getConfigurationData()?.logRotate,
}),
- ...(hasOwnProp(Configuration.getConfigurationData(), 'logMaxFiles') && {
+ ...(has(Configuration.getConfigurationData(), 'logMaxFiles') && {
// eslint-disable-next-line @typescript-eslint/no-deprecated
maxFiles: Configuration.getConfigurationData()?.logMaxFiles,
}),
- ...(hasOwnProp(Configuration.getConfigurationData(), 'logMaxSize') && {
+ ...(has(Configuration.getConfigurationData(), 'logMaxSize') && {
// eslint-disable-next-line @typescript-eslint/no-deprecated
maxSize: Configuration.getConfigurationData()?.logMaxSize,
}),
const logConfiguration: LogConfiguration = {
...defaultLogConfiguration,
...deprecatedLogConfiguration,
- ...(hasOwnProp(Configuration.getConfigurationData(), ConfigurationSection.log) &&
+ ...(has(Configuration.getConfigurationData(), ConfigurationSection.log) &&
Configuration.getConfigurationData()?.log),
}
return logConfiguration
storageConfiguration = defaultStorageConfiguration
break
}
- if (hasOwnProp(Configuration.getConfigurationData(), ConfigurationSection.performanceStorage)) {
+ if (has(Configuration.getConfigurationData(), ConfigurationSection.performanceStorage)) {
storageConfiguration = {
...storageConfiguration,
...Configuration.getConfigurationData()?.performanceStorage,
private static buildUIServerSection (): UIServerConfiguration {
let uiServerConfiguration: UIServerConfiguration = defaultUIServerConfiguration
- if (hasOwnProp(Configuration.getConfigurationData(), ConfigurationSection.uiServer)) {
+ if (has(Configuration.getConfigurationData(), ConfigurationSection.uiServer)) {
uiServerConfiguration = mergeDeepRight(
uiServerConfiguration,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
private static buildWorkerSection (): WorkerConfiguration {
const deprecatedWorkerConfiguration: WorkerConfiguration = {
- ...(hasOwnProp(Configuration.getConfigurationData(), 'workerProcess') && {
+ ...(has(Configuration.getConfigurationData(), 'workerProcess') && {
// eslint-disable-next-line @typescript-eslint/no-deprecated
processType: Configuration.getConfigurationData()?.workerProcess,
}),
- ...(hasOwnProp(Configuration.getConfigurationData(), 'workerStartDelay') && {
+ ...(has(Configuration.getConfigurationData(), 'workerStartDelay') && {
// eslint-disable-next-line @typescript-eslint/no-deprecated
startDelay: Configuration.getConfigurationData()?.workerStartDelay,
}),
- ...(hasOwnProp(Configuration.getConfigurationData(), 'chargingStationsPerWorker') && {
+ ...(has(Configuration.getConfigurationData(), 'chargingStationsPerWorker') && {
// eslint-disable-next-line @typescript-eslint/no-deprecated
elementsPerWorker: Configuration.getConfigurationData()?.chargingStationsPerWorker,
}),
- ...(hasOwnProp(Configuration.getConfigurationData(), 'elementAddDelay') && {
+ ...(has(Configuration.getConfigurationData(), 'elementAddDelay') && {
// eslint-disable-next-line @typescript-eslint/no-deprecated
elementAddDelay: Configuration.getConfigurationData()?.elementAddDelay,
}),
- ...(hasOwnProp(Configuration.getConfigurationData()?.worker, 'elementStartDelay') && {
+ ...(has(Configuration.getConfigurationData()?.worker, 'elementStartDelay') && {
// eslint-disable-next-line @typescript-eslint/no-deprecated
elementAddDelay: Configuration.getConfigurationData()?.worker?.elementStartDelay,
}),
- ...(hasOwnProp(Configuration.getConfigurationData(), 'workerPoolMinSize') && {
+ ...(has(Configuration.getConfigurationData(), 'workerPoolMinSize') && {
// eslint-disable-next-line @typescript-eslint/no-deprecated
poolMinSize: Configuration.getConfigurationData()?.workerPoolMinSize,
}),
- ...(hasOwnProp(Configuration.getConfigurationData(), 'workerPoolMaxSize') && {
+ ...(has(Configuration.getConfigurationData(), 'workerPoolMaxSize') && {
// eslint-disable-next-line @typescript-eslint/no-deprecated
poolMaxSize: Configuration.getConfigurationData()?.workerPoolMaxSize,
}),
}
- hasOwnProp(Configuration.getConfigurationData(), 'workerPoolStrategy') &&
+ has(Configuration.getConfigurationData(), 'workerPoolStrategy') &&
// eslint-disable-next-line @typescript-eslint/no-deprecated
delete Configuration.getConfigurationData()?.workerPoolStrategy
const workerConfiguration: WorkerConfiguration = {
...defaultWorkerConfiguration,
...deprecatedWorkerConfiguration,
- ...(hasOwnProp(Configuration.getConfigurationData(), ConfigurationSection.worker) &&
+ ...(has(Configuration.getConfigurationData(), ConfigurationSection.worker) &&
Configuration.getConfigurationData()?.worker),
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
"Use 'uri' instead"
)
// uiServer section
- if (hasOwnProp(Configuration.getConfigurationData(), 'uiWebSocketServer')) {
+ if (has(Configuration.getConfigurationData(), 'uiWebSocketServer')) {
console.error(
`${chalk.green(logPrefix())} ${chalk.red(
`Deprecated configuration section 'uiWebSocketServer' usage. Use '${ConfigurationSection.uiServer}' instead`
}
public static getSupervisionUrlDistribution (): SupervisionUrlDistribution | undefined {
- return hasOwnProp(Configuration.getConfigurationData(), 'supervisionUrlDistribution')
+ return has(Configuration.getConfigurationData(), 'supervisionUrlDistribution')
? Configuration.getConfigurationData()?.supervisionUrlDistribution
: SupervisionUrlDistribution.ROUND_ROBIN
}
formatDurationSeconds,
generateUUID,
getRandomFloat,
- hasOwnProp,
insertAt,
isArraySorted,
isAsyncFunction,
isNotEmptyArray,
isNotEmptyString,
- isObject,
isValidDate,
roundTo,
secureRandom,
expect(extractTimeSeriesValues(circularBuffer)).toEqual([1.1, 2.2, 3.3])
})
- await it('Verify isObject()', () => {
- expect(isObject('test')).toBe(false)
- expect(isObject(undefined)).toBe(false)
- expect(isObject(null)).toBe(false)
- expect(isObject(0)).toBe(false)
- expect(isObject([])).toBe(false)
- expect(isObject([0, 1])).toBe(false)
- expect(isObject(['0', '1'])).toBe(false)
- expect(isObject({})).toBe(true)
- expect(isObject({ 1: 1 })).toBe(true)
- expect(isObject({ 1: '1' })).toBe(true)
- expect(isObject(new Map())).toBe(true)
- expect(isObject(new Set())).toBe(true)
- expect(isObject(new WeakMap())).toBe(true)
- expect(isObject(new WeakSet())).toBe(true)
- })
-
await it('Verify isAsyncFunction()', () => {
expect(isAsyncFunction(null)).toBe(false)
expect(isAsyncFunction(undefined)).toBe(false)
expect(() => clone(weakSet)).toThrowError(new Error('#<WeakSet> could not be cloned.'))
})
- await it('Verify hasOwnProp()', () => {
- expect(hasOwnProp('test', '')).toBe(false)
- expect(hasOwnProp(undefined, '')).toBe(false)
- expect(hasOwnProp(null, '')).toBe(false)
- expect(hasOwnProp([], '')).toBe(false)
- expect(hasOwnProp({}, '')).toBe(false)
- expect(hasOwnProp({ 1: 1 }, 1)).toBe(true)
- expect(hasOwnProp({ 1: 1 }, '1')).toBe(true)
- expect(hasOwnProp({ 1: 1 }, 2)).toBe(false)
- expect(hasOwnProp({ 1: 1 }, '2')).toBe(false)
- expect(hasOwnProp({ 1: '1' }, '1')).toBe(true)
- expect(hasOwnProp({ 1: '1' }, 1)).toBe(true)
- expect(hasOwnProp({ 1: '1' }, '2')).toBe(false)
- expect(hasOwnProp({ 1: '1' }, 2)).toBe(false)
- })
-
await it('Verify isNotEmptyString()', () => {
expect(isNotEmptyString('')).toBe(false)
expect(isNotEmptyString(' ')).toBe(false)