"cacheable",
"commitlint",
"CSMS",
+ "emobility",
"evse",
"evses",
"iccid",
-FROM node:lts-alpine as builder
+FROM node:lts-alpine AS builder
# Build simulator
WORKDIR /usr/builder
#!/usr/bin/env sh
-node -r source-map-support/register dist/start.mjs &
+node -r source-map-support/register dist/start.js &
node webui/start.js
routes:
- route: e-mobility-charging-stations-simulator.cfapps.sap.hana.ondemand.com
health-check-type: process
- command: node -r source-map-support/register dist/start.mjs
+ command: node -r source-map-support/register dist/start.js
env:
# OPTIMIZE_MEMORY: true
NODE_OPTIONS: --stack-trace-limit=1024 --max-old-space-size=768
import path from 'node:path';
+import { fileURLToPath } from 'node:url';
import { TsMorphMetadataProvider } from '@mikro-orm/reflection';
entities: [PerformanceRecord, PerformanceData],
type: 'sqlite',
clientUrl: `file://${path.join(
- path.resolve(__dirname),
+ path.dirname(fileURLToPath(import.meta.url)),
`${Constants.DEFAULT_PERFORMANCE_RECORDS_DB_NAME}.db`
)}`,
};
],
"type": "module",
"exports": [
- "./dist/start.mjs"
+ "./dist/start.js"
],
"auto-changelog": {
"commitUrl": "https://github.com/sap/e-mobility-charging-stations-simulator/commit/{id}",
"preinstall": "node skip-preinstall.cjs || npx --yes only-allow pnpm",
"prepare": "node prepare.cjs",
"build-requirements": "node --no-warnings build-requirements.mjs",
- "start": "pnpm build && cross-env NODE_ENV=production node -r source-map-support/register dist/start.mjs",
- "start:dev": "pnpm build:dev && cross-env NODE_ENV=development node -r source-map-support/register dist/start.mjs",
- "start:dev:debug": "pnpm build:dev && cross-env NODE_ENV=development node -r source-map-support/register --inspect dist/start.mjs",
- "start:prof": "cross-env NODE_ENV=production node -r source-map-support/register --prof dist/start.mjs",
- "start:doctorprof": "cross-env NODE_ENV=production clinic doctor -- node -r source-map-support/register dist/start.mjs",
- "start:flameprof": "cross-env NODE_ENV=production clinic flame -- node -r source-map-support/register dist/start.mjs",
- "start:bubbleprof": "cross-env NODE_ENV=production clinic bubbleprof -- node -r source-map-support/register dist/start.mjs",
- "start:heapprofiler": "cross-env NODE_ENV=production clinic heapprofiler -- node -r source-map-support/register dist/start.mjs",
+ "start": "pnpm build && cross-env NODE_ENV=production node -r source-map-support/register dist/start.js",
+ "start:dev": "pnpm build:dev && cross-env NODE_ENV=development node -r source-map-support/register dist/start.js",
+ "start:dev:debug": "pnpm build:dev && cross-env NODE_ENV=development node -r source-map-support/register --inspect dist/start.js",
+ "start:prof": "cross-env NODE_ENV=production node -r source-map-support/register --prof dist/start.js",
+ "start:doctorprof": "cross-env NODE_ENV=production clinic doctor -- node -r source-map-support/register dist/start.js",
+ "start:flameprof": "cross-env NODE_ENV=production clinic flame -- node -r source-map-support/register dist/start.js",
+ "start:bubbleprof": "cross-env NODE_ENV=production clinic bubbleprof -- node -r source-map-support/register dist/start.js",
+ "start:heapprofiler": "cross-env NODE_ENV=production clinic heapprofiler -- node -r source-map-support/register dist/start.js",
"rollup": "pnpm build-requirements && rollup --config",
"build": "pnpm rollup",
"build:cf": "pnpm clean:node_modules && npx cross-env SKIP_PREINSTALL=1 npm install && pnpm rollup",
- "build:dev": "pnpm rollup -- --environment BUILD:development",
- "build:dev:watch": "pnpm rollup -- --environment BUILD:development --watch",
+ "build:dev": "pnpm rollup --environment BUILD:development",
+ "build:dev:analyze": "pnpm rollup --environment ANALYZE,BUILD:development",
+ "build:dev:watch": "pnpm rollup --environment BUILD:development --watch",
"clean:dist": "npx rimraf dist",
"clean:node_modules": "npx rimraf node_modules",
"lint": "cross-env TIMING=1 eslint --cache --ext .js,.cjs,.mjs,.ts src",
import del from 'rollup-plugin-delete';
const isDevelopmentBuild = process.env.BUILD === 'development';
+const isAnalyzeBuild = process.env.ANALYZE;
export default {
input: ['src/start.ts', 'src/charging-station/ChargingStationWorker.ts'],
dir: 'dist',
format: 'esm',
exports: 'auto',
- sourcemap: true,
- preserveModules: true,
- preserveModulesRoot: 'src',
- entryFileNames: '[name].mjs',
+ ...(isDevelopmentBuild && { sourcemap: true }),
...(!isDevelopmentBuild && { plugins: [terser({ maxWorkers: 2 })] }),
},
],
copy({
targets: [{ src: 'src/assets', dest: 'dist/' }],
}),
- isDevelopmentBuild && analyze(),
+ isAnalyzeBuild && analyze(),
],
};
this.initializeCounters();
this.workerImplementation = null;
this.workerScript = path.join(
- path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'),
- 'charging-station',
+ path.dirname(fileURLToPath(import.meta.url)),
`ChargingStationWorker${path.extname(fileURLToPath(import.meta.url))}`
);
Configuration.getUIServer().enabled === true &&
await this.workerImplementation?.addElement({
index,
templateFile: path.join(
- path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'),
+ path.dirname(fileURLToPath(import.meta.url)),
'assets',
'station-templates',
stationTemplateUrl.file
Configuration,
Constants,
DCElectricUtils,
+ ErrorUtils,
FileUtils,
Utils,
logger,
this.templateFileHash = template.templateHash;
}
} catch (error) {
- FileUtils.handleFileException(
+ ErrorUtils.handleFileException(
this.templateFile,
FileType.ChargingStationTemplate,
error as NodeJS.ErrnoException,
this.configurationFileHash = configuration.configurationHash;
}
} catch (error) {
- FileUtils.handleFileException(
+ ErrorUtils.handleFileException(
this.configurationFile,
FileType.ChargingStationConfiguration,
error as NodeJS.ErrnoException,
this.configurationFileHash = configurationHash;
})
.catch((error) => {
- FileUtils.handleFileException(
+ ErrorUtils.handleFileException(
this.configurationFile,
FileType.ChargingStationConfiguration,
error as NodeJS.ErrnoException,
);
}
} catch (error) {
- FileUtils.handleFileException(
+ ErrorUtils.handleFileException(
this.configurationFile,
FileType.ChargingStationConfiguration,
error as NodeJS.ErrnoException,
return (
stationInfo.idTagsFile &&
path.join(
- path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'),
+ path.dirname(fileURLToPath(import.meta.url)),
'assets',
path.basename(stationInfo.idTagsFile)
)
import type { ChargingStation } from './ChargingStation';
import { ChargingStationUtils } from './ChargingStationUtils';
import { FileType, IdTagDistribution } from '../types';
-import { FileUtils, Utils, logger } from '../utils';
+import { ErrorUtils, FileUtils, Utils, logger } from '../utils';
type IdTagsCacheValueType = {
idTags: string[];
this.deleteIdTagsCache(file);
this.deleteIdTagsCacheIndexes(file);
} catch (error) {
- FileUtils.handleFileException(
+ ErrorUtils.handleFileException(
file,
FileType.Authorization,
error as NodeJS.ErrnoException,
// Load id tags file
idTags = JSON.parse(fs.readFileSync(file, 'utf8')) as string[];
} catch (error) {
- FileUtils.handleFileException(
+ ErrorUtils.handleFileException(
file,
FileType.Authorization,
error as NodeJS.ErrnoException,
[
OCPP16IncomingRequestCommand.RESET,
OCPP16ServiceUtils.parseJsonSchemaFile<ResetRequest>(
- '../../../assets/json-schemas/ocpp/1.6/Reset.json',
+ 'assets/json-schemas/ocpp/1.6/Reset.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.CLEAR_CACHE,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16ClearCacheRequest>(
- '../../../assets/json-schemas/ocpp/1.6/ClearCache.json',
+ 'assets/json-schemas/ocpp/1.6/ClearCache.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.UNLOCK_CONNECTOR,
OCPP16ServiceUtils.parseJsonSchemaFile<UnlockConnectorRequest>(
- '../../../assets/json-schemas/ocpp/1.6/UnlockConnector.json',
+ 'assets/json-schemas/ocpp/1.6/UnlockConnector.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.GET_CONFIGURATION,
OCPP16ServiceUtils.parseJsonSchemaFile<GetConfigurationRequest>(
- '../../../assets/json-schemas/ocpp/1.6/GetConfiguration.json',
+ 'assets/json-schemas/ocpp/1.6/GetConfiguration.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.CHANGE_CONFIGURATION,
OCPP16ServiceUtils.parseJsonSchemaFile<ChangeConfigurationRequest>(
- '../../../assets/json-schemas/ocpp/1.6/ChangeConfiguration.json',
+ 'assets/json-schemas/ocpp/1.6/ChangeConfiguration.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.GET_DIAGNOSTICS,
OCPP16ServiceUtils.parseJsonSchemaFile<GetDiagnosticsRequest>(
- '../../../assets/json-schemas/ocpp/1.6/GetDiagnostics.json',
+ 'assets/json-schemas/ocpp/1.6/GetDiagnostics.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.GET_COMPOSITE_SCHEDULE,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16GetCompositeScheduleRequest>(
- '../../../assets/json-schemas/ocpp/1.6/GetCompositeSchedule.json',
+ 'assets/json-schemas/ocpp/1.6/GetCompositeSchedule.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.SET_CHARGING_PROFILE,
OCPP16ServiceUtils.parseJsonSchemaFile<SetChargingProfileRequest>(
- '../../../assets/json-schemas/ocpp/1.6/SetChargingProfile.json',
+ 'assets/json-schemas/ocpp/1.6/SetChargingProfile.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.CLEAR_CHARGING_PROFILE,
OCPP16ServiceUtils.parseJsonSchemaFile<ClearChargingProfileRequest>(
- '../../../assets/json-schemas/ocpp/1.6/ClearChargingProfile.json',
+ 'assets/json-schemas/ocpp/1.6/ClearChargingProfile.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.CHANGE_AVAILABILITY,
OCPP16ServiceUtils.parseJsonSchemaFile<ChangeAvailabilityRequest>(
- '../../../assets/json-schemas/ocpp/1.6/ChangeAvailability.json',
+ 'assets/json-schemas/ocpp/1.6/ChangeAvailability.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.REMOTE_START_TRANSACTION,
OCPP16ServiceUtils.parseJsonSchemaFile<RemoteStartTransactionRequest>(
- '../../../assets/json-schemas/ocpp/1.6/RemoteStartTransaction.json',
+ 'assets/json-schemas/ocpp/1.6/RemoteStartTransaction.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.REMOTE_STOP_TRANSACTION,
OCPP16ServiceUtils.parseJsonSchemaFile<RemoteStopTransactionRequest>(
- '../../../assets/json-schemas/ocpp/1.6/RemoteStopTransaction.json',
+ 'assets/json-schemas/ocpp/1.6/RemoteStopTransaction.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.TRIGGER_MESSAGE,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16TriggerMessageRequest>(
- '../../../assets/json-schemas/ocpp/1.6/TriggerMessage.json',
+ 'assets/json-schemas/ocpp/1.6/TriggerMessage.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.DATA_TRANSFER,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DataTransferRequest>(
- '../../../assets/json-schemas/ocpp/1.6/DataTransfer.json',
+ 'assets/json-schemas/ocpp/1.6/DataTransfer.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.UPDATE_FIRMWARE,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16UpdateFirmwareRequest>(
- '../../../assets/json-schemas/ocpp/1.6/UpdateFirmware.json',
+ 'assets/json-schemas/ocpp/1.6/UpdateFirmware.json',
moduleName,
'constructor'
),
let ftpClient: Client;
try {
const logFiles = fs
- .readdirSync(path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../../'))
+ .readdirSync(path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'))
.filter((file) => file.endsWith('.log'))
.map((file) => path.join('./', file));
const diagnosticsArchive = `${chargingStation.stationInfo.chargingStationId}_logs.tar.gz`;
});
uploadResponse = await ftpClient.uploadFrom(
path.join(
- path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../../'),
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'),
diagnosticsArchive
),
`${uri.pathname}${diagnosticsArchive}`
[
OCPP16RequestCommand.AUTHORIZE,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16AuthorizeRequest>(
- '../../../assets/json-schemas/ocpp/1.6/Authorize.json',
+ 'assets/json-schemas/ocpp/1.6/Authorize.json',
moduleName,
'constructor'
),
[
OCPP16RequestCommand.BOOT_NOTIFICATION,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16BootNotificationRequest>(
- '../../../assets/json-schemas/ocpp/1.6/BootNotification.json',
+ 'assets/json-schemas/ocpp/1.6/BootNotification.json',
moduleName,
'constructor'
),
[
OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DiagnosticsStatusNotificationRequest>(
- '../../../assets/json-schemas/ocpp/1.6/DiagnosticsStatusNotification.json',
+ 'assets/json-schemas/ocpp/1.6/DiagnosticsStatusNotification.json',
moduleName,
'constructor'
),
[
OCPP16RequestCommand.HEARTBEAT,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16HeartbeatRequest>(
- '../../../assets/json-schemas/ocpp/1.6/Heartbeat.json',
+ 'assets/json-schemas/ocpp/1.6/Heartbeat.json',
moduleName,
'constructor'
),
[
OCPP16RequestCommand.METER_VALUES,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16MeterValuesRequest>(
- '../../../assets/json-schemas/ocpp/1.6/MeterValues.json',
+ 'assets/json-schemas/ocpp/1.6/MeterValues.json',
moduleName,
'constructor'
),
[
OCPP16RequestCommand.STATUS_NOTIFICATION,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StatusNotificationRequest>(
- '../../../assets/json-schemas/ocpp/1.6/StatusNotification.json',
+ 'assets/json-schemas/ocpp/1.6/StatusNotification.json',
moduleName,
'constructor'
),
[
OCPP16RequestCommand.START_TRANSACTION,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StartTransactionRequest>(
- '../../../assets/json-schemas/ocpp/1.6/StartTransaction.json',
+ 'assets/json-schemas/ocpp/1.6/StartTransaction.json',
moduleName,
'constructor'
),
[
OCPP16RequestCommand.STOP_TRANSACTION,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StopTransactionRequest>(
- '../../../assets/json-schemas/ocpp/1.6/StopTransaction.json',
+ 'assets/json-schemas/ocpp/1.6/StopTransaction.json',
moduleName,
'constructor'
),
[
OCPP16RequestCommand.DATA_TRANSFER,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DataTransferRequest>(
- '../../../assets/json-schemas/ocpp/1.6/DataTransfer.json',
+ 'assets/json-schemas/ocpp/1.6/DataTransfer.json',
moduleName,
'constructor'
),
[
OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16FirmwareStatusNotificationRequest>(
- '../../../assets/json-schemas/ocpp/1.6/FirmwareStatusNotification.json',
+ 'assets/json-schemas/ocpp/1.6/FirmwareStatusNotification.json',
moduleName,
'constructor'
),
[
OCPP16RequestCommand.BOOT_NOTIFICATION,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16BootNotificationResponse>(
- '../../../assets/json-schemas/ocpp/1.6/BootNotificationResponse.json',
+ 'assets/json-schemas/ocpp/1.6/BootNotificationResponse.json',
moduleName,
'constructor'
),
[
OCPP16RequestCommand.HEARTBEAT,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16HeartbeatResponse>(
- '../../../assets/json-schemas/ocpp/1.6/HeartbeatResponse.json',
+ 'assets/json-schemas/ocpp/1.6/HeartbeatResponse.json',
moduleName,
'constructor'
),
[
OCPP16RequestCommand.AUTHORIZE,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16AuthorizeResponse>(
- '../../../assets/json-schemas/ocpp/1.6/AuthorizeResponse.json',
+ 'assets/json-schemas/ocpp/1.6/AuthorizeResponse.json',
moduleName,
'constructor'
),
[
OCPP16RequestCommand.START_TRANSACTION,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StartTransactionResponse>(
- '../../../assets/json-schemas/ocpp/1.6/StartTransactionResponse.json',
+ 'assets/json-schemas/ocpp/1.6/StartTransactionResponse.json',
moduleName,
'constructor'
),
[
OCPP16RequestCommand.STOP_TRANSACTION,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StopTransactionResponse>(
- '../../../assets/json-schemas/ocpp/1.6/StopTransactionResponse.json',
+ 'assets/json-schemas/ocpp/1.6/StopTransactionResponse.json',
moduleName,
'constructor'
),
[
OCPP16RequestCommand.STATUS_NOTIFICATION,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StatusNotificationResponse>(
- '../../../assets/json-schemas/ocpp/1.6/StatusNotificationResponse.json',
+ 'assets/json-schemas/ocpp/1.6/StatusNotificationResponse.json',
moduleName,
'constructor'
),
[
OCPP16RequestCommand.METER_VALUES,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16MeterValuesResponse>(
- '../../../assets/json-schemas/ocpp/1.6/MeterValuesResponse.json',
+ 'assets/json-schemas/ocpp/1.6/MeterValuesResponse.json',
moduleName,
'constructor'
),
[
OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DiagnosticsStatusNotificationResponse>(
- '../../../assets/json-schemas/ocpp/1.6/DiagnosticsStatusNotificationResponse.json',
+ 'assets/json-schemas/ocpp/1.6/DiagnosticsStatusNotificationResponse.json',
moduleName,
'constructor'
),
[
OCPP16RequestCommand.DATA_TRANSFER,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DataTransferResponse>(
- '../../../assets/json-schemas/ocpp/1.6/DataTransferResponse.json',
+ 'assets/json-schemas/ocpp/1.6/DataTransferResponse.json',
moduleName,
'constructor'
),
[
OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16FirmwareStatusNotificationResponse>(
- '../../../assets/json-schemas/ocpp/1.6/FirmwareStatusNotificationResponse.json',
+ 'assets/json-schemas/ocpp/1.6/FirmwareStatusNotificationResponse.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.RESET,
OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
- '../../../assets/json-schemas/ocpp/1.6/ResetResponse.json',
+ 'assets/json-schemas/ocpp/1.6/ResetResponse.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.CLEAR_CACHE,
OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
- '../../../assets/json-schemas/ocpp/1.6/ClearCacheResponse.json',
+ 'assets/json-schemas/ocpp/1.6/ClearCacheResponse.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.CHANGE_AVAILABILITY,
OCPP16ServiceUtils.parseJsonSchemaFile<ChangeAvailabilityResponse>(
- '../../../assets/json-schemas/ocpp/1.6/ChangeAvailabilityResponse.json',
+ 'assets/json-schemas/ocpp/1.6/ChangeAvailabilityResponse.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.UNLOCK_CONNECTOR,
OCPP16ServiceUtils.parseJsonSchemaFile<UnlockConnectorResponse>(
- '../../../assets/json-schemas/ocpp/1.6/UnlockConnectorResponse.json',
+ 'assets/json-schemas/ocpp/1.6/UnlockConnectorResponse.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.GET_CONFIGURATION,
OCPP16ServiceUtils.parseJsonSchemaFile<GetConfigurationResponse>(
- '../../../assets/json-schemas/ocpp/1.6/GetConfigurationResponse.json',
+ 'assets/json-schemas/ocpp/1.6/GetConfigurationResponse.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.CHANGE_CONFIGURATION,
OCPP16ServiceUtils.parseJsonSchemaFile<ChangeConfigurationResponse>(
- '../../../assets/json-schemas/ocpp/1.6/ChangeConfigurationResponse.json',
+ 'assets/json-schemas/ocpp/1.6/ChangeConfigurationResponse.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.GET_COMPOSITE_SCHEDULE,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16GetCompositeScheduleResponse>(
- '../../../assets/json-schemas/ocpp/1.6/GetCompositeScheduleResponse.json',
+ 'assets/json-schemas/ocpp/1.6/GetCompositeScheduleResponse.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.SET_CHARGING_PROFILE,
OCPP16ServiceUtils.parseJsonSchemaFile<SetChargingProfileResponse>(
- '../../../assets/json-schemas/ocpp/1.6/SetChargingProfileResponse.json',
+ 'assets/json-schemas/ocpp/1.6/SetChargingProfileResponse.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.CLEAR_CHARGING_PROFILE,
OCPP16ServiceUtils.parseJsonSchemaFile<ClearChargingProfileResponse>(
- '../../../assets/json-schemas/ocpp/1.6/ClearChargingProfileResponse.json',
+ 'assets/json-schemas/ocpp/1.6/ClearChargingProfileResponse.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.REMOTE_START_TRANSACTION,
OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
- '../../../assets/json-schemas/ocpp/1.6/RemoteStartTransactionResponse.json',
+ 'assets/json-schemas/ocpp/1.6/RemoteStartTransactionResponse.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.REMOTE_STOP_TRANSACTION,
OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
- '../../../assets/json-schemas/ocpp/1.6/RemoteStopTransactionResponse.json',
+ 'assets/json-schemas/ocpp/1.6/RemoteStopTransactionResponse.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.GET_DIAGNOSTICS,
OCPP16ServiceUtils.parseJsonSchemaFile<GetDiagnosticsResponse>(
- '../../../assets/json-schemas/ocpp/1.6/GetDiagnosticsResponse.json',
+ 'assets/json-schemas/ocpp/1.6/GetDiagnosticsResponse.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.TRIGGER_MESSAGE,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16TriggerMessageResponse>(
- '../../../assets/json-schemas/ocpp/1.6/TriggerMessageResponse.json',
+ 'assets/json-schemas/ocpp/1.6/TriggerMessageResponse.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.DATA_TRANSFER,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DataTransferResponse>(
- '../../../assets/json-schemas/ocpp/1.6/DataTransferResponse.json',
+ 'assets/json-schemas/ocpp/1.6/DataTransferResponse.json',
moduleName,
'constructor'
),
[
OCPP16IncomingRequestCommand.UPDATE_FIRMWARE,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16UpdateFirmwareResponse>(
- '../../../assets/json-schemas/ocpp/1.6/UpdateFirmwareResponse.json',
+ 'assets/json-schemas/ocpp/1.6/UpdateFirmwareResponse.json',
moduleName,
'constructor'
),
// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
-import path from 'node:path';
-import { fileURLToPath } from 'node:url';
-
import type { JSONSchemaType } from 'ajv';
import type { ChargingStation } from '../../../charging-station';
methodName?: string
): JSONSchemaType<T> {
return super.parseJsonSchemaFile<T>(
- path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath),
+ relativePath,
OCPPVersion.VERSION_16,
moduleName,
methodName
[
OCPP20IncomingRequestCommand.CLEAR_CACHE,
OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20ClearCacheRequest>(
- '../../../assets/json-schemas/ocpp/2.0/ClearCacheRequest.json',
+ 'assets/json-schemas/ocpp/2.0/ClearCacheRequest.json',
moduleName,
'constructor'
),
[
OCPP20RequestCommand.BOOT_NOTIFICATION,
OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20BootNotificationRequest>(
- '../../../assets/json-schemas/ocpp/2.0/BootNotificationRequest.json',
+ 'assets/json-schemas/ocpp/2.0/BootNotificationRequest.json',
moduleName,
'constructor'
),
[
OCPP20RequestCommand.HEARTBEAT,
OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20HeartbeatRequest>(
- '../../../assets/json-schemas/ocpp/2.0/HeartbeatRequest.json',
+ 'assets/json-schemas/ocpp/2.0/HeartbeatRequest.json',
moduleName,
'constructor'
),
[
OCPP20RequestCommand.STATUS_NOTIFICATION,
OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20StatusNotificationRequest>(
- '../../../assets/json-schemas/ocpp/2.0/StatusNotificationRequest.json',
+ 'assets/json-schemas/ocpp/2.0/StatusNotificationRequest.json',
moduleName,
'constructor'
),
[
OCPP20RequestCommand.BOOT_NOTIFICATION,
OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20BootNotificationResponse>(
- '../../../assets/json-schemas/ocpp/2.0/BootNotificationResponse.json',
+ 'assets/json-schemas/ocpp/2.0/BootNotificationResponse.json',
moduleName,
'constructor'
),
[
OCPP20RequestCommand.HEARTBEAT,
OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20HeartbeatResponse>(
- '../../../assets/json-schemas/ocpp/2.0/HeartbeatResponse.json',
+ 'assets/json-schemas/ocpp/2.0/HeartbeatResponse.json',
moduleName,
'constructor'
),
[
OCPP20RequestCommand.STATUS_NOTIFICATION,
OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20StatusNotificationResponse>(
- '../../../assets/json-schemas/ocpp/2.0/StatusNotificationResponse.json',
+ 'assets/json-schemas/ocpp/2.0/StatusNotificationResponse.json',
moduleName,
'constructor'
),
[
OCPP20IncomingRequestCommand.CLEAR_CACHE,
OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20ClearCacheResponse>(
- '../../../assets/json-schemas/ocpp/2.0/ClearCacheResponse.json',
+ 'assets/json-schemas/ocpp/2.0/ClearCacheResponse.json',
moduleName,
'constructor'
),
// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
-import path from 'node:path';
-import { fileURLToPath } from 'node:url';
-
import type { JSONSchemaType } from 'ajv';
import { type JsonType, OCPPVersion } from '../../../types';
methodName?: string
): JSONSchemaType<T> {
return super.parseJsonSchemaFile<T>(
- path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath),
+ relativePath,
OCPPVersion.VERSION_20,
moduleName,
methodName
import fs from 'node:fs';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
import type { DefinedError, ErrorObject, JSONSchemaType } from 'ajv';
type StatusNotificationRequest,
type StatusNotificationResponse,
} from '../../types';
-import { Constants, FileUtils, Utils, logger } from '../../utils';
+import { Constants, ErrorUtils, Utils, logger } from '../../utils';
export class OCPPServiceUtils {
protected constructor() {
}
protected static parseJsonSchemaFile<T extends JsonType>(
- filePath: string,
+ relativePath: string,
ocppVersion: OCPPVersion,
moduleName?: string,
methodName?: string
): JSONSchemaType<T> {
+ const filePath = path.join(path.dirname(fileURLToPath(import.meta.url)), relativePath);
try {
return JSON.parse(fs.readFileSync(filePath, 'utf8')) as JSONSchemaType<T>;
} catch (error) {
- FileUtils.handleFileException(
+ ErrorUtils.handleFileException(
filePath,
FileType.JsonSchema,
error as NodeJS.ErrnoException,
import { Storage } from './Storage';
import { FileType, type Statistics } from '../../types';
-import { AsyncLock, AsyncLockType, Constants, FileUtils, Utils } from '../../utils';
+import { AsyncLock, AsyncLockType, Constants, ErrorUtils, Utils } from '../../utils';
export class JsonFileStorage extends Storage {
private fd: number | null = null;
);
})
.catch((error) => {
- FileUtils.handleFileException(
+ ErrorUtils.handleFileException(
this.dbName,
FileType.PerformanceRecords,
error as NodeJS.ErrnoException,
this.fd = fs.openSync(this.dbName, 'a+');
}
} catch (error) {
- FileUtils.handleFileException(
+ ErrorUtils.handleFileException(
this.dbName,
FileType.PerformanceRecords,
error as NodeJS.ErrnoException,
this.fd = null;
}
} catch (error) {
- FileUtils.handleFileException(
+ ErrorUtils.handleFileException(
this.dbName,
FileType.PerformanceRecords,
error as NodeJS.ErrnoException,
export class Configuration {
private static configurationFile = path.join(
- path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'),
+ path.dirname(fileURLToPath(import.meta.url)),
'assets',
'config.json'
);
private static buildPerformanceUriFilePath(file: string) {
return `file://${path.join(
- path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../'),
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'),
file
)}`;
}
--- /dev/null
+import chalk from 'chalk';
+
+import { logger } from './Logger';
+import { Utils } from './Utils';
+import type { EmptyObject, FileType, HandleErrorParams } from '../types';
+
+export class ErrorUtils {
+ private constructor() {
+ // This is intentional
+ }
+
+ public static handleFileException(
+ file: string,
+ fileType: FileType,
+ error: NodeJS.ErrnoException,
+ logPrefix: string,
+ params: HandleErrorParams<EmptyObject> = { throwError: true, consoleOut: false }
+ ): void {
+ const prefix = Utils.isNotEmptyString(logPrefix) ? `${logPrefix} ` : '';
+ let logMsg: string;
+ switch (error.code) {
+ case 'ENOENT':
+ logMsg = `${fileType} file ${file} not found:`;
+ break;
+ case 'EEXIST':
+ logMsg = `${fileType} file ${file} already exists:`;
+ break;
+ case 'EACCES':
+ logMsg = `${fileType} file ${file} access denied:`;
+ break;
+ default:
+ logMsg = `${fileType} file ${file} error:`;
+ }
+ if (params?.consoleOut) {
+ console.warn(`${chalk.green(prefix)}${chalk.yellow(`${logMsg} `)}`, error);
+ } else {
+ logger.warn(`${prefix}${logMsg}`, error);
+ }
+ if (params?.throwError) {
+ throw error;
+ }
+ }
+}
import fs from 'node:fs';
-import chalk from 'chalk';
-
+import { ErrorUtils } from './ErrorUtils';
import { logger } from './Logger';
import { Utils } from './Utils';
-import type { EmptyObject, FileType, HandleErrorParams, JsonType } from '../types';
+import type { FileType, JsonType } from '../types';
export class FileUtils {
private constructor() {
logger.debug(`${logPrefix} ${fileType} file ${file} have changed, reload`);
refreshedVariable && (refreshedVariable = JSON.parse(fs.readFileSync(file, 'utf8')) as T);
} catch (error) {
- FileUtils.handleFileException(file, fileType, error as NodeJS.ErrnoException, logPrefix, {
- throwError: false,
- });
+ ErrorUtils.handleFileException(
+ file,
+ fileType,
+ error as NodeJS.ErrnoException,
+ logPrefix,
+ {
+ throwError: false,
+ }
+ );
}
}
}
try {
return fs.watch(file, listener);
} catch (error) {
- FileUtils.handleFileException(file, fileType, error as NodeJS.ErrnoException, logPrefix, {
+ ErrorUtils.handleFileException(file, fileType, error as NodeJS.ErrnoException, logPrefix, {
throwError: false,
});
}
logger.info(`${logPrefix} No ${fileType} file to watch given. Not monitoring its changes`);
}
}
-
- public static handleFileException(
- file: string,
- fileType: FileType,
- error: NodeJS.ErrnoException,
- logPrefix: string,
- params: HandleErrorParams<EmptyObject> = { throwError: true, consoleOut: false }
- ): void {
- const prefix = Utils.isNotEmptyString(logPrefix) ? `${logPrefix} ` : '';
- let logMsg: string;
- switch (error.code) {
- case 'ENOENT':
- logMsg = `${fileType} file ${file} not found:`;
- break;
- case 'EEXIST':
- logMsg = `${fileType} file ${file} already exists:`;
- break;
- case 'EACCES':
- logMsg = `${fileType} file ${file} access denied:`;
- break;
- default:
- logMsg = `${fileType} file ${file} error:`;
- }
- if (params?.consoleOut) {
- console.warn(`${chalk.green(prefix)}${chalk.yellow(`${logMsg} `)}`, error);
- } else {
- logger.warn(`${prefix}${logMsg}`, error);
- }
- if (params?.throwError) {
- throw error;
- }
- }
}
export { CircularArray } from './CircularArray';
export { Configuration } from './Configuration';
export { Constants } from './Constants';
+export { ErrorUtils } from './ErrorUtils';
export { FileUtils } from './FileUtils';
export { Utils } from './Utils';
export { logger } from './Logger';