-import path from 'path';
+import path from 'node:path';
import { TsMorphMetadataProvider } from '@mikro-orm/reflection';
'async_hooks',
'basic-ftp',
'chalk',
- 'fs',
'http',
'http-status-codes',
'just-clone',
'moment',
'mongodb',
'node:crypto',
+ 'node:fs',
+ 'node:path',
+ 'node:url',
'node:util',
- 'path',
'perf_hooks',
'poolifier',
'proper-lockfile',
'tar',
- 'url',
'winston',
'winston-daily-rotate-file',
'winston/lib/winston/transports',
-import fs from 'fs';
+import fs from 'node:fs';
import { FileType } from '../types/FileType';
import FileUtils from '../utils/FileUtils';
// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
-import path from 'path';
-import { fileURLToPath } from 'url';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
import { type Worker, isMainThread } from 'worker_threads';
import chalk from 'chalk';
// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
-import fs from 'fs';
import crypto from 'node:crypto';
-import path from 'path';
-import { URL } from 'url';
+import fs from 'node:fs';
+import path from 'node:path';
+import { URL } from 'node:url';
import { parentPort } from 'worker_threads';
import merge from 'just-merge';
import crypto from 'node:crypto';
-import path from 'path';
-import { fileURLToPath } from 'url';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
import moment from 'moment';
// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
-import fs from 'fs';
-import path from 'path';
-import { URL, fileURLToPath } from 'url';
+import fs from 'node:fs';
+import path from 'node:path';
+import { URL, fileURLToPath } from 'node:url';
import type { JSONSchemaType } from 'ajv';
import { Client, type FTPResponse } from 'basic-ftp';
this.jsonSchemas = new Map<OCPP16IncomingRequestCommand, JSONSchemaType<JsonObject>>([
[
OCPP16IncomingRequestCommand.RESET,
- this.parseJsonSchemaFile<ResetRequest>('../../../assets/json-schemas/ocpp/1.6/Reset.json'),
+ OCPP16ServiceUtils.parseJsonSchemaFile<ResetRequest>(
+ '../../../assets/json-schemas/ocpp/1.6/Reset.json'
+ ),
],
[
OCPP16IncomingRequestCommand.CLEAR_CACHE,
- this.parseJsonSchemaFile<OCPP16ClearCacheRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16ClearCacheRequest>(
'../../../assets/json-schemas/ocpp/1.6/ClearCache.json'
),
],
[
OCPP16IncomingRequestCommand.UNLOCK_CONNECTOR,
- this.parseJsonSchemaFile<UnlockConnectorRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<UnlockConnectorRequest>(
'../../../assets/json-schemas/ocpp/1.6/UnlockConnector.json'
),
],
[
OCPP16IncomingRequestCommand.GET_CONFIGURATION,
- this.parseJsonSchemaFile<GetConfigurationRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<GetConfigurationRequest>(
'../../../assets/json-schemas/ocpp/1.6/GetConfiguration.json'
),
],
[
OCPP16IncomingRequestCommand.CHANGE_CONFIGURATION,
- this.parseJsonSchemaFile<ChangeConfigurationRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<ChangeConfigurationRequest>(
'../../../assets/json-schemas/ocpp/1.6/ChangeConfiguration.json'
),
],
[
OCPP16IncomingRequestCommand.GET_DIAGNOSTICS,
- this.parseJsonSchemaFile<GetDiagnosticsRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<GetDiagnosticsRequest>(
'../../../assets/json-schemas/ocpp/1.6/GetDiagnostics.json'
),
],
[
OCPP16IncomingRequestCommand.SET_CHARGING_PROFILE,
- this.parseJsonSchemaFile<SetChargingProfileRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<SetChargingProfileRequest>(
'../../../assets/json-schemas/ocpp/1.6/SetChargingProfile.json'
),
],
[
OCPP16IncomingRequestCommand.CLEAR_CHARGING_PROFILE,
- this.parseJsonSchemaFile<ClearChargingProfileRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<ClearChargingProfileRequest>(
'../../../assets/json-schemas/ocpp/1.6/ClearChargingProfile.json'
),
],
[
OCPP16IncomingRequestCommand.CHANGE_AVAILABILITY,
- this.parseJsonSchemaFile<ChangeAvailabilityRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<ChangeAvailabilityRequest>(
'../../../assets/json-schemas/ocpp/1.6/ChangeAvailability.json'
),
],
[
OCPP16IncomingRequestCommand.REMOTE_START_TRANSACTION,
- this.parseJsonSchemaFile<RemoteStartTransactionRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<RemoteStartTransactionRequest>(
'../../../assets/json-schemas/ocpp/1.6/RemoteStartTransaction.json'
),
],
[
OCPP16IncomingRequestCommand.REMOTE_STOP_TRANSACTION,
- this.parseJsonSchemaFile<RemoteStopTransactionRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<RemoteStopTransactionRequest>(
'../../../assets/json-schemas/ocpp/1.6/RemoteStopTransaction.json'
),
],
[
OCPP16IncomingRequestCommand.TRIGGER_MESSAGE,
- this.parseJsonSchemaFile<OCPP16TriggerMessageRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16TriggerMessageRequest>(
'../../../assets/json-schemas/ocpp/1.6/TriggerMessage.json'
),
],
[
OCPP16IncomingRequestCommand.DATA_TRANSFER,
- this.parseJsonSchemaFile<OCPP16DataTransferRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DataTransferRequest>(
'../../../assets/json-schemas/ocpp/1.6/DataTransfer.json'
),
],
[
OCPP16IncomingRequestCommand.UPDATE_FIRMWARE,
- this.parseJsonSchemaFile<OCPP16UpdateFirmwareRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16UpdateFirmwareRequest>(
'../../../assets/json-schemas/ocpp/1.6/UpdateFirmware.json'
),
],
);
}
}
-
- private parseJsonSchemaFile<T extends JsonType>(relativePath: string): JSONSchemaType<T> {
- return JSON.parse(
- fs.readFileSync(
- path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath),
- 'utf8'
- )
- ) as JSONSchemaType<T>;
- }
}
// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
-import fs from 'fs';
-import path from 'path';
-import { fileURLToPath } from 'url';
-
import type { JSONSchemaType } from 'ajv';
import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
this.jsonSchemas = new Map<OCPP16RequestCommand, JSONSchemaType<JsonObject>>([
[
OCPP16RequestCommand.AUTHORIZE,
- this.parseJsonSchemaFile<OCPP16AuthorizeRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16AuthorizeRequest>(
'../../../assets/json-schemas/ocpp/1.6/Authorize.json'
),
],
[
OCPP16RequestCommand.BOOT_NOTIFICATION,
- this.parseJsonSchemaFile<OCPP16BootNotificationRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16BootNotificationRequest>(
'../../../assets/json-schemas/ocpp/1.6/BootNotification.json'
),
],
[
OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
- this.parseJsonSchemaFile<OCPP16DiagnosticsStatusNotificationRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DiagnosticsStatusNotificationRequest>(
'../../../assets/json-schemas/ocpp/1.6/DiagnosticsStatusNotification.json'
),
],
[
OCPP16RequestCommand.HEARTBEAT,
- this.parseJsonSchemaFile<OCPP16HeartbeatRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16HeartbeatRequest>(
'../../../assets/json-schemas/ocpp/1.6/Heartbeat.json'
),
],
[
OCPP16RequestCommand.METER_VALUES,
- this.parseJsonSchemaFile<OCPP16MeterValuesRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16MeterValuesRequest>(
'../../../assets/json-schemas/ocpp/1.6/MeterValues.json'
),
],
[
OCPP16RequestCommand.STATUS_NOTIFICATION,
- this.parseJsonSchemaFile<OCPP16StatusNotificationRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StatusNotificationRequest>(
'../../../assets/json-schemas/ocpp/1.6/StatusNotification.json'
),
],
[
OCPP16RequestCommand.START_TRANSACTION,
- this.parseJsonSchemaFile<OCPP16StartTransactionRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StartTransactionRequest>(
'../../../assets/json-schemas/ocpp/1.6/StartTransaction.json'
),
],
[
OCPP16RequestCommand.STOP_TRANSACTION,
- this.parseJsonSchemaFile<OCPP16StopTransactionRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StopTransactionRequest>(
'../../../assets/json-schemas/ocpp/1.6/StopTransaction.json'
),
],
[
OCPP16RequestCommand.DATA_TRANSFER,
- this.parseJsonSchemaFile<OCPP16DataTransferRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DataTransferRequest>(
'../../../assets/json-schemas/ocpp/1.6/DataTransfer.json'
),
],
[
OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION,
- this.parseJsonSchemaFile<OCPP16FirmwareStatusNotificationRequest>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16FirmwareStatusNotificationRequest>(
'../../../assets/json-schemas/ocpp/1.6/FirmwareStatusNotification.json'
),
],
);
}
}
-
- private parseJsonSchemaFile<T extends JsonType>(relativePath: string): JSONSchemaType<T> {
- return JSON.parse(
- fs.readFileSync(
- path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath),
- 'utf8'
- )
- ) as JSONSchemaType<T>;
- }
}
// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
-import fs from 'fs';
-import path from 'path';
-import { fileURLToPath } from 'url';
-
import type { JSONSchemaType } from 'ajv';
import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
this.jsonSchemas = new Map<OCPP16RequestCommand, JSONSchemaType<JsonObject>>([
[
OCPP16RequestCommand.BOOT_NOTIFICATION,
- this.parseJsonSchemaFile<OCPP16BootNotificationResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16BootNotificationResponse>(
'../../../assets/json-schemas/ocpp/1.6/BootNotificationResponse.json'
),
],
[
OCPP16RequestCommand.HEARTBEAT,
- this.parseJsonSchemaFile<OCPP16HeartbeatResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16HeartbeatResponse>(
'../../../assets/json-schemas/ocpp/1.6/HeartbeatResponse.json'
),
],
[
OCPP16RequestCommand.AUTHORIZE,
- this.parseJsonSchemaFile<OCPP16AuthorizeResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16AuthorizeResponse>(
'../../../assets/json-schemas/ocpp/1.6/AuthorizeResponse.json'
),
],
[
OCPP16RequestCommand.START_TRANSACTION,
- this.parseJsonSchemaFile<OCPP16StartTransactionResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StartTransactionResponse>(
'../../../assets/json-schemas/ocpp/1.6/StartTransactionResponse.json'
),
],
[
OCPP16RequestCommand.STOP_TRANSACTION,
- this.parseJsonSchemaFile<OCPP16StopTransactionResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StopTransactionResponse>(
'../../../assets/json-schemas/ocpp/1.6/StopTransactionResponse.json'
),
],
[
OCPP16RequestCommand.STATUS_NOTIFICATION,
- this.parseJsonSchemaFile<OCPP16StatusNotificationResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StatusNotificationResponse>(
'../../../assets/json-schemas/ocpp/1.6/StatusNotificationResponse.json'
),
],
[
OCPP16RequestCommand.METER_VALUES,
- this.parseJsonSchemaFile<OCPP16MeterValuesResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16MeterValuesResponse>(
'../../../assets/json-schemas/ocpp/1.6/MeterValuesResponse.json'
),
],
[
OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
- this.parseJsonSchemaFile<OCPP16DiagnosticsStatusNotificationResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DiagnosticsStatusNotificationResponse>(
'../../../assets/json-schemas/ocpp/1.6/DiagnosticsStatusNotificationResponse.json'
),
],
[
OCPP16RequestCommand.DATA_TRANSFER,
- this.parseJsonSchemaFile<OCPP16DataTransferResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DataTransferResponse>(
'../../../assets/json-schemas/ocpp/1.6/DataTransferResponse.json'
),
],
[
OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION,
- this.parseJsonSchemaFile<OCPP16FirmwareStatusNotificationResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16FirmwareStatusNotificationResponse>(
'../../../assets/json-schemas/ocpp/1.6/FirmwareStatusNotificationResponse.json'
),
],
this.jsonIncomingRequestResponseSchemas = new Map([
[
OCPP16IncomingRequestCommand.RESET,
- this.parseJsonSchemaFile<GenericResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
'../../../assets/json-schemas/ocpp/1.6/ResetResponse.json'
),
],
[
OCPP16IncomingRequestCommand.CLEAR_CACHE,
- this.parseJsonSchemaFile<GenericResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
'../../../assets/json-schemas/ocpp/1.6/ClearCacheResponse.json'
),
],
[
OCPP16IncomingRequestCommand.CHANGE_AVAILABILITY,
- this.parseJsonSchemaFile<ChangeAvailabilityResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<ChangeAvailabilityResponse>(
'../../../assets/json-schemas/ocpp/1.6/ChangeAvailabilityResponse.json'
),
],
[
OCPP16IncomingRequestCommand.UNLOCK_CONNECTOR,
- this.parseJsonSchemaFile<UnlockConnectorResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<UnlockConnectorResponse>(
'../../../assets/json-schemas/ocpp/1.6/UnlockConnectorResponse.json'
),
],
[
OCPP16IncomingRequestCommand.GET_CONFIGURATION,
- this.parseJsonSchemaFile<GetConfigurationResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<GetConfigurationResponse>(
'../../../assets/json-schemas/ocpp/1.6/GetConfigurationResponse.json'
),
],
[
OCPP16IncomingRequestCommand.CHANGE_CONFIGURATION,
- this.parseJsonSchemaFile<ChangeConfigurationResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<ChangeConfigurationResponse>(
'../../../assets/json-schemas/ocpp/1.6/ChangeConfigurationResponse.json'
),
],
[
OCPP16IncomingRequestCommand.SET_CHARGING_PROFILE,
- this.parseJsonSchemaFile<SetChargingProfileResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<SetChargingProfileResponse>(
'../../../assets/json-schemas/ocpp/1.6/SetChargingProfileResponse.json'
),
],
[
OCPP16IncomingRequestCommand.CLEAR_CHARGING_PROFILE,
- this.parseJsonSchemaFile<ClearChargingProfileResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<ClearChargingProfileResponse>(
'../../../assets/json-schemas/ocpp/1.6/ClearChargingProfileResponse.json'
),
],
[
OCPP16IncomingRequestCommand.REMOTE_START_TRANSACTION,
- this.parseJsonSchemaFile<GenericResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
'../../../assets/json-schemas/ocpp/1.6/RemoteStartTransactionResponse.json'
),
],
[
OCPP16IncomingRequestCommand.REMOTE_STOP_TRANSACTION,
- this.parseJsonSchemaFile<GenericResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
'../../../assets/json-schemas/ocpp/1.6/RemoteStopTransactionResponse.json'
),
],
[
OCPP16IncomingRequestCommand.GET_DIAGNOSTICS,
- this.parseJsonSchemaFile<GetDiagnosticsResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<GetDiagnosticsResponse>(
'../../../assets/json-schemas/ocpp/1.6/GetDiagnosticsResponse.json'
),
],
[
OCPP16IncomingRequestCommand.TRIGGER_MESSAGE,
- this.parseJsonSchemaFile<OCPP16TriggerMessageResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16TriggerMessageResponse>(
'../../../assets/json-schemas/ocpp/1.6/TriggerMessageResponse.json'
),
],
[
OCPP16IncomingRequestCommand.DATA_TRANSFER,
- this.parseJsonSchemaFile<OCPP16DataTransferResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DataTransferResponse>(
'../../../assets/json-schemas/ocpp/1.6/DataTransferResponse.json'
),
],
[
OCPP16IncomingRequestCommand.UPDATE_FIRMWARE,
- this.parseJsonSchemaFile<OCPP16UpdateFirmwareResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16UpdateFirmwareResponse>(
'../../../assets/json-schemas/ocpp/1.6/UpdateFirmwareResponse.json'
),
],
logger.warn(logMsg);
}
}
-
- private parseJsonSchemaFile<T extends JsonType>(relativePath: string): JSONSchemaType<T> {
- return JSON.parse(
- fs.readFileSync(
- path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath),
- 'utf8'
- )
- ) as JSONSchemaType<T>;
- }
}
// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
+import fs from 'node:fs';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+import type { JSONSchemaType } from 'ajv';
+
import OCPPError from '../../../exception/OCPPError';
import { CurrentType, Voltage } from '../../../types/ChargingStationTemplate';
+import { FileType } from '../../../types/FileType';
+import type { JsonType } from '../../../types/JsonType';
import type {
MeasurandPerPhaseSampledValueTemplates,
SampledValueTemplate,
OCPP16RequestCommand,
} from '../../../types/ocpp/1.6/Requests';
import { ErrorType } from '../../../types/ocpp/ErrorType';
+import { OCPPVersion } from '../../../types/ocpp/OCPPVersion';
import Constants from '../../../utils/Constants';
import { ACElectricUtils, DCElectricUtils } from '../../../utils/ElectricUtils';
+import FileUtils from '../../../utils/FileUtils';
import logger from '../../../utils/Logger';
import Utils from '../../../utils/Utils';
import type ChargingStation from '../../ChargingStation';
!cpReplaced && chargingStation.getConnectorStatus(connectorId)?.chargingProfiles?.push(cp);
}
+ public static parseJsonSchemaFile<T extends JsonType>(relativePath: string): JSONSchemaType<T> {
+ const filePath = path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath);
+ try {
+ return JSON.parse(fs.readFileSync(filePath, 'utf8')) as JSONSchemaType<T>;
+ } catch (error) {
+ FileUtils.handleFileException(
+ OCPPServiceUtils.logPrefix(OCPPVersion.VERSION_16),
+ FileType.JsonSchema,
+ filePath,
+ error as NodeJS.ErrnoException,
+ { throwError: false }
+ );
+ }
+ }
+
private static buildSampledValue(
sampledValueTemplate: SampledValueTemplate,
value: number,
// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
-import fs from 'fs';
-import path from 'path';
-import { fileURLToPath } from 'url';
-
import type { JSONSchemaType } from 'ajv';
import { OCPP20ServiceUtils } from './OCPP20ServiceUtils';
this.jsonSchemas = new Map<OCPP20IncomingRequestCommand, JSONSchemaType<JsonObject>>([
[
OCPP20IncomingRequestCommand.CLEAR_CACHE,
- this.parseJsonSchemaFile<OCPP20ClearCacheRequest>(
+ OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20ClearCacheRequest>(
'../../../assets/json-schemas/ocpp/2.0/ClearCacheRequest.json'
),
],
);
return false;
}
-
- private parseJsonSchemaFile<T extends JsonType>(relativePath: string): JSONSchemaType<T> {
- return JSON.parse(
- fs.readFileSync(
- path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath),
- 'utf8'
- )
- ) as JSONSchemaType<T>;
- }
}
// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
-import fs from 'fs';
-import path from 'path';
-import { fileURLToPath } from 'url';
-
import type { JSONSchemaType } from 'ajv';
import { OCPP20ServiceUtils } from './OCPP20ServiceUtils';
this.jsonSchemas = new Map<OCPP20RequestCommand, JSONSchemaType<JsonObject>>([
[
OCPP20RequestCommand.BOOT_NOTIFICATION,
- this.parseJsonSchemaFile<OCPP20BootNotificationRequest>(
+ OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20BootNotificationRequest>(
'../../../assets/json-schemas/ocpp/2.0/BootNotificationRequest.json'
),
],
[
OCPP20RequestCommand.HEARTBEAT,
- this.parseJsonSchemaFile<OCPP20HeartbeatRequest>(
+ OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20HeartbeatRequest>(
'../../../assets/json-schemas/ocpp/2.0/HeartbeatRequest.json'
),
],
[
OCPP20RequestCommand.STATUS_NOTIFICATION,
- this.parseJsonSchemaFile<OCPP20StatusNotificationRequest>(
+ OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20StatusNotificationRequest>(
'../../../assets/json-schemas/ocpp/2.0/StatusNotificationRequest.json'
),
],
);
}
}
-
- private parseJsonSchemaFile<T extends JsonType>(relativePath: string): JSONSchemaType<T> {
- return JSON.parse(
- fs.readFileSync(
- path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath),
- 'utf8'
- )
- ) as JSONSchemaType<T>;
- }
}
// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
-import fs from 'fs';
-import path from 'path';
-import { fileURLToPath } from 'url';
-
import type { JSONSchemaType } from 'ajv';
import { OCPP20ServiceUtils } from './OCPP20ServiceUtils';
this.jsonSchemas = new Map<OCPP20RequestCommand, JSONSchemaType<JsonObject>>([
[
OCPP20RequestCommand.BOOT_NOTIFICATION,
- this.parseJsonSchemaFile<OCPP20BootNotificationResponse>(
+ OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20BootNotificationResponse>(
'../../../assets/json-schemas/ocpp/2.0/BootNotificationResponse.json'
),
],
[
OCPP20RequestCommand.HEARTBEAT,
- this.parseJsonSchemaFile<OCPP20HeartbeatResponse>(
+ OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20HeartbeatResponse>(
'../../../assets/json-schemas/ocpp/2.0/HeartbeatResponse.json'
),
],
[
OCPP20RequestCommand.STATUS_NOTIFICATION,
- this.parseJsonSchemaFile<OCPP20StatusNotificationResponse>(
+ OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20StatusNotificationResponse>(
'../../../assets/json-schemas/ocpp/2.0/StatusNotificationResponse.json'
),
],
this.jsonIncomingRequestResponseSchemas = new Map([
[
OCPP20IncomingRequestCommand.CLEAR_CACHE,
- this.parseJsonSchemaFile<OCPP20ClearCacheResponse>(
+ OCPP20ServiceUtils.parseJsonSchemaFile<OCPP20ClearCacheResponse>(
'../../../assets/json-schemas/ocpp/2.0/ClearCacheResponse.json'
),
],
);
}
}
-
- private parseJsonSchemaFile<T extends JsonType>(relativePath: string): JSONSchemaType<T> {
- return JSON.parse(
- fs.readFileSync(
- path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath),
- 'utf8'
- )
- ) as JSONSchemaType<T>;
- }
}
// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
+import fs from 'node:fs';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+import type { JSONSchemaType } from 'ajv';
+
+import { FileType } from '../../../types/FileType';
+import type { JsonType } from '../../../types/JsonType';
+import { OCPPVersion } from '../../../types/ocpp/OCPPVersion';
+import FileUtils from '../../../utils/FileUtils';
import { OCPPServiceUtils } from '../OCPPServiceUtils';
-export class OCPP20ServiceUtils extends OCPPServiceUtils {}
+export class OCPP20ServiceUtils extends OCPPServiceUtils {
+ public static parseJsonSchemaFile<T extends JsonType>(relativePath: string): JSONSchemaType<T> {
+ const filePath = path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath);
+ try {
+ return JSON.parse(fs.readFileSync(filePath, 'utf8')) as JSONSchemaType<T>;
+ } catch (error) {
+ FileUtils.handleFileException(
+ OCPPServiceUtils.logPrefix(OCPPVersion.VERSION_20),
+ FileType.JsonSchema,
+ filePath,
+ error as NodeJS.ErrnoException,
+ { throwError: false }
+ );
+ }
+ }
+}
}
}
+ protected static logPrefix(ocppVersion: OCPPVersion): string {
+ return Utils.logPrefix(` OCPP ${ocppVersion} |`);
+ }
+
protected static getSampledValueTemplate(
chargingStation: ChargingStation,
connectorId: number,
// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
+import type { URL } from 'node:url';
import { PerformanceEntry, PerformanceObserver, performance } from 'perf_hooks';
-import type { URL } from 'url';
import { parentPort } from 'worker_threads';
import { MessageChannelUtils } from '../charging-station/MessageChannelUtils';
// Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
-import fs from 'fs';
+import fs from 'node:fs';
import lockfile from 'proper-lockfile';
// Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
-import { URL } from 'url';
+import { URL } from 'node:url';
import type { EmptyObject } from '../../types/EmptyObject';
import type { HandleErrorParams } from '../../types/Error';
-import fs from 'fs';
-import path from 'path';
-import { fileURLToPath } from 'url';
+import fs from 'node:fs';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
import chalk from 'chalk';
import merge from 'just-merge';
-import fs from 'fs';
+import fs from 'node:fs';
import chalk from 'chalk';
-import fs from 'fs';
+import fs from 'node:fs';
import WorkerConstants from './WorkerConstants';
import type { WorkerData, WorkerOptions } from '../types/Worker';