From: Jérôme Benoit Date: Sun, 17 Jul 2022 22:58:04 +0000 (+0200) Subject: Use eslint extension for import sorting instead of unmaintained external ones X-Git-Tag: v1.1.64~12 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=8114d10e3893e96bb725ce2fca9744429ee4b75b;p=e-mobility-charging-stations-simulator.git Use eslint extension for import sorting instead of unmaintained external ones Signed-off-by: Jérôme Benoit --- diff --git a/.eslintrc b/.eslintrc index 9a860ac8..adb3c787 100644 --- a/.eslintrc +++ b/.eslintrc @@ -19,6 +19,11 @@ "settings": { "jsdoc": { "mode": "typescript" + }, + "import/resolver": { + "typescript": { + "project": "./tsconfig.json" + } } }, "rules": { @@ -95,9 +100,31 @@ "warn", { "ignoreCase": false, - "ignoreDeclarationSort": false, + "ignoreDeclarationSort": true, "ignoreMemberSort": false, - "memberSyntaxSortOrder": ["none", "all", "multiple", "single"] + "memberSyntaxSortOrder": ["none", "all", "multiple", "single"], + "allowSeparatedGroups": true + } + ], + "import/no-unresolved": "error", + "import/order": [ + "error", + { + "groups": [ + "builtin", // Built-in imports (come from NodeJS native) go first + "external", // <- External imports + "internal", // <- Absolute imports + ["sibling", "parent"], // <- Relative imports, the sibling and parent types they can be mingled together + "index", // <- Index imports + "unknown" // <- Unknown + ], + "newlines-between": "always", + "alphabetize": { + /* Sort in ascending order. Options: ["ignore", "asc", "desc"] */ + "order": "asc", + /* Ignore case. Options: [true, false] */ + "caseInsensitive": true + } } ], "object-curly-spacing": ["error", "always"], diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 5366569b..bed2ea6e 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -2,7 +2,6 @@ // See https://go.microsoft.com/fwlink/?LinkId=827846 // for the documentation about the extensions.json format "recommendations": [ - "amatiasq.sort-imports", "codezombiech.gitignore", "dbaeumer.vscode-eslint", "eamodio.gitlens", diff --git a/.vscode/settings.json b/.vscode/settings.json index 246e9c6e..b40f1546 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { + "editor.formatOnSave": false, "editor.codeActionsOnSave": { - "source.fixAll.eslint": true + "source.fixAll": true } } diff --git a/package-lock.json b/package-lock.json index bd5251f3..922566dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48,7 +48,7 @@ "cross-env": "^7.0.3", "eslint": "^8.19.0", "eslint-config-prettier": "^8.5.0", - "eslint-import-resolver-typescript": "^3.2.6", + "eslint-import-resolver-typescript": "^3.2.7", "eslint-plugin-import": "^2.26.0", "eslint-plugin-jsdoc": "^39.3.3", "eslint-plugin-node": "^11.1.0", @@ -2020,9 +2020,9 @@ } }, "node_modules/@types/node": { - "version": "18.0.4", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.0.4.tgz", - "integrity": "sha512-M0+G6V0Y4YV8cqzHssZpaNCqvYwlCiulmm0PwpNLF55r/+cT8Ol42CHRU1SEaYFH2rTwiiE1aYg/2g2rrtGdPA==" + "version": "18.0.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.0.6.tgz", + "integrity": "sha512-/xUq6H2aQm261exT6iZTMifUySEt4GR5KX8eYyY+C4MSNPqSh9oNIP7tz2GLKTlFaiBbgZNxffoR3CVRG+cljw==" }, "node_modules/@types/object-path": { "version": "0.11.1", @@ -5920,9 +5920,9 @@ } }, "node_modules/eslint-import-resolver-typescript": { - "version": "3.2.6", - "resolved": "https://registry.npmjs.org/eslint-import-resolver-typescript/-/eslint-import-resolver-typescript-3.2.6.tgz", - "integrity": "sha512-Gk7+viMP9Ho5Q36gmXw3UJrnSCbMTStLS+TuF49SdsOUQGNvhg7ZVsnaieuN0FNNWPB+Xf5tBwADgEuoRPeDDw==", + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/eslint-import-resolver-typescript/-/eslint-import-resolver-typescript-3.2.7.tgz", + "integrity": "sha512-WvcsRy3aPmwVsuS/XVliAJWpIdTlaFXXZPZk3TCbvvF8RtaAkjAhcLL5bl5VEoTmE+XnTHjIbWMzNZcOQpK/DA==", "dev": true, "dependencies": { "debug": "^4.3.4", @@ -5931,7 +5931,7 @@ "globby": "^13.1.2", "is-core-module": "^2.9.0", "is-glob": "^4.0.3", - "synckit": "^0.7.2" + "synckit": "^0.8.1" }, "engines": { "node": "^12.20.0 || ^14.18.0 || >=16.0.0" @@ -16130,16 +16130,16 @@ } }, "node_modules/synckit": { - "version": "0.7.2", - "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.7.2.tgz", - "integrity": "sha512-CSZRtSRZ8RhJGMtWyLRqlarmWPPlsgZJHtV6cz0VTHNOg+R7UBoE2eNPQmB5Qrhtk3RX2AAcJmVwMXFULVQSwg==", + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.8.1.tgz", + "integrity": "sha512-rJEeygO5PNmcZICmrgnbOd2usi5zWE1ESc0Gn5tTmJlongoU8zCTwMFQtar2UgMSiR68vK9afPQ+uVs2lURSIA==", "dev": true, "dependencies": { - "@pkgr/utils": "^2.2.0", + "@pkgr/utils": "^2.3.0", "tslib": "^2.4.0" }, "engines": { - "node": "^12.20.0 || ^14.18.0 || >=16.0.0" + "node": "^14.18.0 || >=16.0.0" }, "funding": { "url": "https://opencollective.com/unts" @@ -19372,9 +19372,9 @@ } }, "@types/node": { - "version": "18.0.4", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.0.4.tgz", - "integrity": "sha512-M0+G6V0Y4YV8cqzHssZpaNCqvYwlCiulmm0PwpNLF55r/+cT8Ol42CHRU1SEaYFH2rTwiiE1aYg/2g2rrtGdPA==" + "version": "18.0.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.0.6.tgz", + "integrity": "sha512-/xUq6H2aQm261exT6iZTMifUySEt4GR5KX8eYyY+C4MSNPqSh9oNIP7tz2GLKTlFaiBbgZNxffoR3CVRG+cljw==" }, "@types/object-path": { "version": "0.11.1", @@ -22585,9 +22585,9 @@ } }, "eslint-import-resolver-typescript": { - "version": "3.2.6", - "resolved": "https://registry.npmjs.org/eslint-import-resolver-typescript/-/eslint-import-resolver-typescript-3.2.6.tgz", - "integrity": "sha512-Gk7+viMP9Ho5Q36gmXw3UJrnSCbMTStLS+TuF49SdsOUQGNvhg7ZVsnaieuN0FNNWPB+Xf5tBwADgEuoRPeDDw==", + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/eslint-import-resolver-typescript/-/eslint-import-resolver-typescript-3.2.7.tgz", + "integrity": "sha512-WvcsRy3aPmwVsuS/XVliAJWpIdTlaFXXZPZk3TCbvvF8RtaAkjAhcLL5bl5VEoTmE+XnTHjIbWMzNZcOQpK/DA==", "dev": true, "requires": { "debug": "^4.3.4", @@ -22596,7 +22596,7 @@ "globby": "^13.1.2", "is-core-module": "^2.9.0", "is-glob": "^4.0.3", - "synckit": "^0.7.2" + "synckit": "^0.8.1" }, "dependencies": { "globby": { @@ -30406,12 +30406,12 @@ "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==" }, "synckit": { - "version": "0.7.2", - "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.7.2.tgz", - "integrity": "sha512-CSZRtSRZ8RhJGMtWyLRqlarmWPPlsgZJHtV6cz0VTHNOg+R7UBoE2eNPQmB5Qrhtk3RX2AAcJmVwMXFULVQSwg==", + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.8.1.tgz", + "integrity": "sha512-rJEeygO5PNmcZICmrgnbOd2usi5zWE1ESc0Gn5tTmJlongoU8zCTwMFQtar2UgMSiR68vK9afPQ+uVs2lURSIA==", "dev": true, "requires": { - "@pkgr/utils": "^2.2.0", + "@pkgr/utils": "^2.3.0", "tslib": "^2.4.0" } }, diff --git a/package.json b/package.json index 2da02475..840f8d31 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,6 @@ "lint": "cross-env TIMING=1 eslint --cache --ext .js,.ts src", "lint:fix": "cross-env TIMING=1 eslint --cache --fix --ext .js,.ts src", "format": "prettier --write .", - "import-sort": "npx import-sort-cli --write 'src/**/*.ts{,x}'", "test": "cross-env TS_NODE_COMPILER_OPTIONS={\\\"module\\\":\\\"commonjs\\\"} nyc mocha test/**/*Test.ts", "coverage": "nyc report --reporter=lcov", "coverage:html": "nyc report --reporter=html", @@ -124,7 +123,7 @@ "cross-env": "^7.0.3", "eslint": "^8.19.0", "eslint-config-prettier": "^8.5.0", - "eslint-import-resolver-typescript": "^3.2.6", + "eslint-import-resolver-typescript": "^3.2.7", "eslint-plugin-import": "^2.26.0", "eslint-plugin-jsdoc": "^39.3.3", "eslint-plugin-node": "^11.1.0", diff --git a/src/charging-station/AuthorizedTagsCache.ts b/src/charging-station/AuthorizedTagsCache.ts index 4a9da4ce..4142ee25 100644 --- a/src/charging-station/AuthorizedTagsCache.ts +++ b/src/charging-station/AuthorizedTagsCache.ts @@ -1,8 +1,9 @@ +import fs from 'fs'; + import { FileType } from '../types/FileType'; import FileUtils from '../utils/FileUtils'; -import Utils from '../utils/Utils'; -import fs from 'fs'; import logger from '../utils/Logger'; +import Utils from '../utils/Utils'; export default class AuthorizedTagsCache { private static instance: AuthorizedTagsCache | null = null; diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index 31f07168..d3517fa0 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -1,5 +1,12 @@ // Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +import PerformanceStatistics from '../performance/PerformanceStatistics'; +import { + AutomaticTransactionGeneratorConfiguration, + Status, +} from '../types/AutomaticTransactionGenerator'; +import { MeterValuesRequest, RequestCommand } from '../types/ocpp/Requests'; +import { MeterValuesResponse } from '../types/ocpp/Responses'; import { AuthorizationStatus, AuthorizeRequest, @@ -10,19 +17,11 @@ import { StopTransactionRequest, StopTransactionResponse, } from '../types/ocpp/Transaction'; -import { - AutomaticTransactionGeneratorConfiguration, - Status, -} from '../types/AutomaticTransactionGenerator'; -import { MeterValuesRequest, RequestCommand } from '../types/ocpp/Requests'; - -import type ChargingStation from './ChargingStation'; import Constants from '../utils/Constants'; -import { MeterValuesResponse } from '../types/ocpp/Responses'; -import { OCPP16ServiceUtils } from './ocpp/1.6/OCPP16ServiceUtils'; -import PerformanceStatistics from '../performance/PerformanceStatistics'; -import Utils from '../utils/Utils'; import logger from '../utils/Logger'; +import Utils from '../utils/Utils'; +import type ChargingStation from './ChargingStation'; +import { OCPP16ServiceUtils } from './ocpp/1.6/OCPP16ServiceUtils'; export default class AutomaticTransactionGenerator { private static readonly instances: Map = new Map< diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index ed9f1bef..b5e90bd8 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -1,29 +1,30 @@ // Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +import path from 'path'; +import { fileURLToPath } from 'url'; +import { isMainThread } from 'worker_threads'; + +import chalk from 'chalk'; + +import { version } from '../../package.json'; +import { Storage } from '../performance/storage/Storage'; +import { StorageFactory } from '../performance/storage/StorageFactory'; import { ChargingStationWorkerData, ChargingStationWorkerMessage, ChargingStationWorkerMessageEvents, } from '../types/ChargingStationWorker'; - -import { AbstractUIServer } from './ui-server/AbstractUIServer'; -import { ApplicationProtocol } from '../types/UIProtocol'; -import { ChargingStationUtils } from './ChargingStationUtils'; -import Configuration from '../utils/Configuration'; import { StationTemplateUrl } from '../types/ConfigurationData'; import Statistics from '../types/Statistics'; -import { Storage } from '../performance/storage/Storage'; -import { StorageFactory } from '../performance/storage/StorageFactory'; -import UIServerFactory from './ui-server/UIServerFactory'; -import { UIServiceUtils } from './ui-server/ui-services/UIServiceUtils'; +import { ApplicationProtocol } from '../types/UIProtocol'; +import Configuration from '../utils/Configuration'; import Utils from '../utils/Utils'; import WorkerAbstract from '../worker/WorkerAbstract'; import WorkerFactory from '../worker/WorkerFactory'; -import chalk from 'chalk'; -import { fileURLToPath } from 'url'; -import { isMainThread } from 'worker_threads'; -import path from 'path'; -import { version } from '../../package.json'; +import { ChargingStationUtils } from './ChargingStationUtils'; +import { AbstractUIServer } from './ui-server/AbstractUIServer'; +import { UIServiceUtils } from './ui-server/ui-services/UIServiceUtils'; +import UIServerFactory from './ui-server/UIServerFactory'; export default class Bootstrap { private static instance: Bootstrap | null = null; diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 23ac2bdc..98cd5e83 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1,6 +1,43 @@ // Partial Copyright Jerome Benoit. 2021. All Rights Reserved. -import { ACElectricUtils, DCElectricUtils } from '../utils/ElectricUtils'; +import crypto from 'crypto'; +import fs from 'fs'; +import path from 'path'; +import { URL, fileURLToPath } from 'url'; +import { parentPort } from 'worker_threads'; + +import WebSocket, { Data, RawData } from 'ws'; + +import BaseError from '../exception/BaseError'; +import OCPPError from '../exception/OCPPError'; +import PerformanceStatistics from '../performance/PerformanceStatistics'; +import { AutomaticTransactionGeneratorConfiguration } from '../types/AutomaticTransactionGenerator'; +import ChargingStationConfiguration from '../types/ChargingStationConfiguration'; +import ChargingStationInfo from '../types/ChargingStationInfo'; +import ChargingStationOcppConfiguration from '../types/ChargingStationOcppConfiguration'; +import ChargingStationTemplate, { + CurrentType, + PowerUnits, + WsOptions, +} from '../types/ChargingStationTemplate'; +import { ChargingStationWorkerMessageEvents } from '../types/ChargingStationWorker'; +import { SupervisionUrlDistribution } from '../types/ConfigurationData'; +import { ConnectorStatus } from '../types/ConnectorStatus'; +import { FileType } from '../types/FileType'; +import { JsonType } from '../types/JsonType'; +import { ChargePointErrorCode } from '../types/ocpp/ChargePointErrorCode'; +import { ChargePointStatus } from '../types/ocpp/ChargePointStatus'; +import { ChargingProfile, ChargingRateUnitType } from '../types/ocpp/ChargingProfile'; +import { + ConnectorPhaseRotation, + StandardParametersKey, + SupportedFeatureProfiles, + VendorDefaultParametersKey, +} from '../types/ocpp/Configuration'; +import { ErrorType } from '../types/ocpp/ErrorType'; +import { MessageType } from '../types/ocpp/MessageType'; +import { MeterValue, MeterValueMeasurand } from '../types/ocpp/MeterValues'; +import { OCPPVersion } from '../types/ocpp/OCPPVersion'; import { AvailabilityType, BootNotificationRequest, @@ -21,65 +58,29 @@ import { Response, StatusNotificationResponse, } from '../types/ocpp/Responses'; -import { ChargingProfile, ChargingRateUnitType } from '../types/ocpp/ChargingProfile'; -import ChargingStationTemplate, { - CurrentType, - PowerUnits, - WsOptions, -} from '../types/ChargingStationTemplate'; -import { - ConnectorPhaseRotation, - StandardParametersKey, - SupportedFeatureProfiles, - VendorDefaultParametersKey, -} from '../types/ocpp/Configuration'; -import { MeterValue, MeterValueMeasurand } from '../types/ocpp/MeterValues'; import { StopTransactionReason, StopTransactionRequest, StopTransactionResponse, } from '../types/ocpp/Transaction'; -import { URL, fileURLToPath } from 'url'; import { WSError, WebSocketCloseEventStatusCode } from '../types/WebSocket'; -import WebSocket, { Data, RawData } from 'ws'; - +import Configuration from '../utils/Configuration'; +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 AuthorizedTagsCache from './AuthorizedTagsCache'; import AutomaticTransactionGenerator from './AutomaticTransactionGenerator'; -import { AutomaticTransactionGeneratorConfiguration } from '../types/AutomaticTransactionGenerator'; -import BaseError from '../exception/BaseError'; -import { ChargePointErrorCode } from '../types/ocpp/ChargePointErrorCode'; -import { ChargePointStatus } from '../types/ocpp/ChargePointStatus'; -import ChargingStationConfiguration from '../types/ChargingStationConfiguration'; import { ChargingStationConfigurationUtils } from './ChargingStationConfigurationUtils'; -import ChargingStationInfo from '../types/ChargingStationInfo'; -import ChargingStationOcppConfiguration from '../types/ChargingStationOcppConfiguration'; import { ChargingStationUtils } from './ChargingStationUtils'; -import { ChargingStationWorkerMessageEvents } from '../types/ChargingStationWorker'; -import Configuration from '../utils/Configuration'; -import { ConnectorStatus } from '../types/ConnectorStatus'; -import Constants from '../utils/Constants'; -import { ErrorType } from '../types/ocpp/ErrorType'; -import { FileType } from '../types/FileType'; -import FileUtils from '../utils/FileUtils'; -import { JsonType } from '../types/JsonType'; -import { MessageType } from '../types/ocpp/MessageType'; import OCPP16IncomingRequestService from './ocpp/1.6/OCPP16IncomingRequestService'; import OCPP16RequestService from './ocpp/1.6/OCPP16RequestService'; import OCPP16ResponseService from './ocpp/1.6/OCPP16ResponseService'; import { OCPP16ServiceUtils } from './ocpp/1.6/OCPP16ServiceUtils'; -import OCPPError from '../exception/OCPPError'; import OCPPIncomingRequestService from './ocpp/OCPPIncomingRequestService'; import OCPPRequestService from './ocpp/OCPPRequestService'; -import { OCPPVersion } from '../types/ocpp/OCPPVersion'; -import PerformanceStatistics from '../performance/PerformanceStatistics'; import SharedLRUCache from './SharedLRUCache'; -import { SupervisionUrlDistribution } from '../types/ConfigurationData'; -import Utils from '../utils/Utils'; -import crypto from 'crypto'; -import fs from 'fs'; -import logger from '../utils/Logger'; -import { parentPort } from 'worker_threads'; -import path from 'path'; export default class ChargingStation { public hashId!: string; diff --git a/src/charging-station/ChargingStationConfigurationUtils.ts b/src/charging-station/ChargingStationConfigurationUtils.ts index 7f1ff980..8a046715 100644 --- a/src/charging-station/ChargingStationConfigurationUtils.ts +++ b/src/charging-station/ChargingStationConfigurationUtils.ts @@ -1,7 +1,7 @@ -import ChargingStation from './ChargingStation'; import { ConfigurationKey } from '../types/ChargingStationOcppConfiguration'; import { StandardParametersKey } from '../types/ocpp/Configuration'; import logger from '../utils/Logger'; +import ChargingStation from './ChargingStation'; export class ChargingStationConfigurationUtils { private constructor() { diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index 2ac8a81b..51887b1b 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -1,29 +1,30 @@ -import { ChargingProfile, ChargingSchedulePeriod } from '../types/ocpp/ChargingProfile'; -import { ChargingProfileKindType, RecurrencyKindType } from '../types/ocpp/1.6/ChargingProfile'; +import crypto from 'crypto'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +import moment from 'moment'; + +import BaseError from '../exception/BaseError'; +import ChargingStationInfo from '../types/ChargingStationInfo'; import ChargingStationTemplate, { AmpereUnits, CurrentType, Voltage, } from '../types/ChargingStationTemplate'; -import { MeterValueMeasurand, MeterValuePhase } from '../types/ocpp/MeterValues'; - -import BaseError from '../exception/BaseError'; -import { BootNotificationRequest } from '../types/ocpp/Requests'; -import ChargingStation from './ChargingStation'; -import { ChargingStationConfigurationUtils } from './ChargingStationConfigurationUtils'; -import ChargingStationInfo from '../types/ChargingStationInfo'; -import Configuration from '../utils/Configuration'; -import Constants from '../utils/Constants'; import { SampledValueTemplate } from '../types/MeasurandPerPhaseSampledValueTemplates'; +import { ChargingProfileKindType, RecurrencyKindType } from '../types/ocpp/1.6/ChargingProfile'; +import { ChargingProfile, ChargingSchedulePeriod } from '../types/ocpp/ChargingProfile'; import { StandardParametersKey } from '../types/ocpp/Configuration'; -import Utils from '../utils/Utils'; +import { MeterValueMeasurand, MeterValuePhase } from '../types/ocpp/MeterValues'; +import { BootNotificationRequest } from '../types/ocpp/Requests'; import { WebSocketCloseEventStatusString } from '../types/WebSocket'; import { WorkerProcessType } from '../types/Worker'; -import crypto from 'crypto'; -import { fileURLToPath } from 'url'; +import Configuration from '../utils/Configuration'; +import Constants from '../utils/Constants'; import logger from '../utils/Logger'; -import moment from 'moment'; -import path from 'path'; +import Utils from '../utils/Utils'; +import ChargingStation from './ChargingStation'; +import { ChargingStationConfigurationUtils } from './ChargingStationConfigurationUtils'; export class ChargingStationUtils { private constructor() { diff --git a/src/charging-station/ChargingStationWorker.ts b/src/charging-station/ChargingStationWorker.ts index 85ea77fb..2fd83728 100644 --- a/src/charging-station/ChargingStationWorker.ts +++ b/src/charging-station/ChargingStationWorker.ts @@ -1,17 +1,18 @@ // Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +import { parentPort, workerData } from 'worker_threads'; + +import { ThreadWorker } from 'poolifier'; + import { ChargingStationWorkerData, ChargingStationWorkerMessage, ChargingStationWorkerMessageEvents, } from '../types/ChargingStationWorker'; -import { parentPort, workerData } from 'worker_threads'; - -import ChargingStation from './ChargingStation'; -import { ChargingStationUtils } from './ChargingStationUtils'; -import { ThreadWorker } from 'poolifier'; import Utils from '../utils/Utils'; import WorkerConstants from '../worker/WorkerConstants'; +import ChargingStation from './ChargingStation'; +import { ChargingStationUtils } from './ChargingStationUtils'; // Conditionally export ThreadWorker instance for pool usage export let threadWorker: ThreadWorker; diff --git a/src/charging-station/SharedLRUCache.ts b/src/charging-station/SharedLRUCache.ts index cda04196..697cf943 100644 --- a/src/charging-station/SharedLRUCache.ts +++ b/src/charging-station/SharedLRUCache.ts @@ -1,6 +1,7 @@ +import LRUCache from 'mnemonist/lru-map-with-delete'; + import ChargingStationConfiguration from '../types/ChargingStationConfiguration'; import ChargingStationTemplate from '../types/ChargingStationTemplate'; -import LRUCache from 'mnemonist/lru-map-with-delete'; import Utils from '../utils/Utils'; enum CacheType { diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 7aad17a1..e579395e 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -1,5 +1,29 @@ // Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +import fs from 'fs'; +import path from 'path'; +import { URL, fileURLToPath } from 'url'; + +import { Client, FTPResponse } from 'basic-ftp'; +import tar from 'tar'; + +import OCPPError from '../../../exception/OCPPError'; +import { JsonType } from '../../../types/JsonType'; +import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode'; +import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus'; +import { + ChargingProfilePurposeType, + OCPP16ChargingProfile, +} from '../../../types/ocpp/1.6/ChargingProfile'; +import { + OCPP16StandardParametersKey, + OCPP16SupportedFeatureProfiles, +} from '../../../types/ocpp/1.6/Configuration'; +import { OCPP16DiagnosticsStatus } from '../../../types/ocpp/1.6/DiagnosticsStatus'; +import { + OCPP16MeterValuesRequest, + OCPP16MeterValuesResponse, +} from '../../../types/ocpp/1.6/MeterValues'; import { ChangeAvailabilityRequest, ChangeConfigurationRequest, @@ -35,11 +59,6 @@ import { SetChargingProfileResponse, UnlockConnectorResponse, } from '../../../types/ocpp/1.6/Responses'; -import { - ChargingProfilePurposeType, - OCPP16ChargingProfile, -} from '../../../types/ocpp/1.6/ChargingProfile'; -import { Client, FTPResponse } from 'basic-ftp'; import { OCPP16AuthorizationStatus, OCPP16AuthorizeRequest, @@ -50,36 +69,18 @@ import { OCPP16StopTransactionRequest, OCPP16StopTransactionResponse, } from '../../../types/ocpp/1.6/Transaction'; -import { - OCPP16MeterValuesRequest, - OCPP16MeterValuesResponse, -} from '../../../types/ocpp/1.6/MeterValues'; -import { - OCPP16StandardParametersKey, - OCPP16SupportedFeatureProfiles, -} from '../../../types/ocpp/1.6/Configuration'; -import { URL, fileURLToPath } from 'url'; - +import { OCPPConfigurationKey } from '../../../types/ocpp/Configuration'; +import { ErrorType } from '../../../types/ocpp/ErrorType'; +import { IncomingRequestHandler } from '../../../types/ocpp/Requests'; +import { DefaultResponse } from '../../../types/ocpp/Responses'; +import Constants from '../../../utils/Constants'; +import logger from '../../../utils/Logger'; +import Utils from '../../../utils/Utils'; import type ChargingStation from '../../ChargingStation'; import { ChargingStationConfigurationUtils } from '../../ChargingStationConfigurationUtils'; import { ChargingStationUtils } from '../../ChargingStationUtils'; -import Constants from '../../../utils/Constants'; -import { DefaultResponse } from '../../../types/ocpp/Responses'; -import { ErrorType } from '../../../types/ocpp/ErrorType'; -import { IncomingRequestHandler } from '../../../types/ocpp/Requests'; -import { JsonType } from '../../../types/JsonType'; -import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode'; -import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus'; -import { OCPP16DiagnosticsStatus } from '../../../types/ocpp/1.6/DiagnosticsStatus'; -import { OCPP16ServiceUtils } from './OCPP16ServiceUtils'; -import { OCPPConfigurationKey } from '../../../types/ocpp/Configuration'; -import OCPPError from '../../../exception/OCPPError'; import OCPPIncomingRequestService from '../OCPPIncomingRequestService'; -import Utils from '../../../utils/Utils'; -import fs from 'fs'; -import logger from '../../../utils/Logger'; -import path from 'path'; -import tar from 'tar'; +import { OCPP16ServiceUtils } from './OCPP16ServiceUtils'; const moduleName = 'OCPP16IncomingRequestService'; diff --git a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts index 3296dc94..2a2d4dfc 100644 --- a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts @@ -1,17 +1,16 @@ // Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +import OCPPError from '../../../exception/OCPPError'; import { JsonObject, JsonType } from '../../../types/JsonType'; - -import type ChargingStation from '../../ChargingStation'; -import Constants from '../../../utils/Constants'; -import { ErrorType } from '../../../types/ocpp/ErrorType'; import { OCPP16RequestCommand } from '../../../types/ocpp/1.6/Requests'; -import { OCPP16ServiceUtils } from './OCPP16ServiceUtils'; -import OCPPError from '../../../exception/OCPPError'; -import OCPPRequestService from '../OCPPRequestService'; -import type OCPPResponseService from '../OCPPResponseService'; +import { ErrorType } from '../../../types/ocpp/ErrorType'; import { RequestParams } from '../../../types/ocpp/Requests'; +import Constants from '../../../utils/Constants'; import Utils from '../../../utils/Utils'; +import type ChargingStation from '../../ChargingStation'; +import OCPPRequestService from '../OCPPRequestService'; +import type OCPPResponseService from '../OCPPResponseService'; +import { OCPP16ServiceUtils } from './OCPP16ServiceUtils'; const moduleName = 'OCPP16RequestService'; diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index 90c04035..fd972b26 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -1,14 +1,14 @@ // Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +import OCPPError from '../../../exception/OCPPError'; +import { JsonType } from '../../../types/JsonType'; +import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode'; +import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus'; +import { OCPP16StandardParametersKey } from '../../../types/ocpp/1.6/Configuration'; import { - OCPP16AuthorizationStatus, - OCPP16AuthorizeRequest, - OCPP16AuthorizeResponse, - OCPP16StartTransactionRequest, - OCPP16StartTransactionResponse, - OCPP16StopTransactionRequest, - OCPP16StopTransactionResponse, -} from '../../../types/ocpp/1.6/Transaction'; + OCPP16MeterValuesRequest, + OCPP16MeterValuesResponse, +} from '../../../types/ocpp/1.6/MeterValues'; import { OCPP16BootNotificationRequest, OCPP16RequestCommand, @@ -20,23 +20,22 @@ import { OCPP16StatusNotificationResponse, } from '../../../types/ocpp/1.6/Responses'; import { - OCPP16MeterValuesRequest, - OCPP16MeterValuesResponse, -} from '../../../types/ocpp/1.6/MeterValues'; - -import type ChargingStation from '../../ChargingStation'; -import { ChargingStationConfigurationUtils } from '../../ChargingStationConfigurationUtils'; + OCPP16AuthorizationStatus, + OCPP16AuthorizeRequest, + OCPP16AuthorizeResponse, + OCPP16StartTransactionRequest, + OCPP16StartTransactionResponse, + OCPP16StopTransactionRequest, + OCPP16StopTransactionResponse, +} from '../../../types/ocpp/1.6/Transaction'; import { ErrorType } from '../../../types/ocpp/ErrorType'; -import { JsonType } from '../../../types/JsonType'; -import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode'; -import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus'; -import { OCPP16ServiceUtils } from './OCPP16ServiceUtils'; -import { OCPP16StandardParametersKey } from '../../../types/ocpp/1.6/Configuration'; -import OCPPError from '../../../exception/OCPPError'; -import OCPPResponseService from '../OCPPResponseService'; import { ResponseHandler } from '../../../types/ocpp/Responses'; -import Utils from '../../../utils/Utils'; import logger from '../../../utils/Logger'; +import Utils from '../../../utils/Utils'; +import type ChargingStation from '../../ChargingStation'; +import { ChargingStationConfigurationUtils } from '../../ChargingStationConfigurationUtils'; +import OCPPResponseService from '../OCPPResponseService'; +import { OCPP16ServiceUtils } from './OCPP16ServiceUtils'; const moduleName = 'OCPP16ResponseService'; diff --git a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts index 0599cfa0..2a154e7b 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -1,10 +1,15 @@ // Partial Copyright Jerome Benoit. 2021. All Rights Reserved. -import { ACElectricUtils, DCElectricUtils } from '../../../utils/ElectricUtils'; +import OCPPError from '../../../exception/OCPPError'; import { CurrentType, Voltage } from '../../../types/ChargingStationTemplate'; import MeasurandPerPhaseSampledValueTemplates, { SampledValueTemplate, } from '../../../types/MeasurandPerPhaseSampledValueTemplates'; +import MeasurandValues from '../../../types/MeasurandValues'; +import { + OCPP16StandardParametersKey, + OCPP16SupportedFeatureProfiles, +} from '../../../types/ocpp/1.6/Configuration'; import { MeterValueContext, MeterValueLocation, @@ -18,20 +23,14 @@ import { OCPP16IncomingRequestCommand, OCPP16RequestCommand, } from '../../../types/ocpp/1.6/Requests'; -import { - OCPP16StandardParametersKey, - OCPP16SupportedFeatureProfiles, -} from '../../../types/ocpp/1.6/Configuration'; - +import { ErrorType } from '../../../types/ocpp/ErrorType'; +import Constants from '../../../utils/Constants'; +import { ACElectricUtils, DCElectricUtils } from '../../../utils/ElectricUtils'; +import logger from '../../../utils/Logger'; +import Utils from '../../../utils/Utils'; import type ChargingStation from '../../ChargingStation'; import { ChargingStationUtils } from '../../ChargingStationUtils'; -import Constants from '../../../utils/Constants'; -import { ErrorType } from '../../../types/ocpp/ErrorType'; -import MeasurandValues from '../../../types/MeasurandValues'; -import OCPPError from '../../../exception/OCPPError'; import { OCPPServiceUtils } from '../OCPPServiceUtils'; -import Utils from '../../../utils/Utils'; -import logger from '../../../utils/Logger'; export class OCPP16ServiceUtils extends OCPPServiceUtils { public static checkFeatureProfile( diff --git a/src/charging-station/ocpp/OCPPIncomingRequestService.ts b/src/charging-station/ocpp/OCPPIncomingRequestService.ts index bf517095..5955b6c9 100644 --- a/src/charging-station/ocpp/OCPPIncomingRequestService.ts +++ b/src/charging-station/ocpp/OCPPIncomingRequestService.ts @@ -1,8 +1,8 @@ -import type ChargingStation from '../ChargingStation'; import { HandleErrorParams } from '../../types/Error'; -import { IncomingRequestCommand } from '../../types/ocpp/Requests'; import { JsonType } from '../../types/JsonType'; +import { IncomingRequestCommand } from '../../types/ocpp/Requests'; import logger from '../../utils/Logger'; +import type ChargingStation from '../ChargingStation'; export default abstract class OCPPIncomingRequestService { private static instance: OCPPIncomingRequestService | null = null; diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index d03e64ec..6695fcbc 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -1,4 +1,10 @@ -import { ErrorResponse, Response } from '../../types/ocpp/Responses'; +import OCPPError from '../../exception/OCPPError'; +import PerformanceStatistics from '../../performance/PerformanceStatistics'; +import { EmptyObject } from '../../types/EmptyObject'; +import { HandleErrorParams } from '../../types/Error'; +import { JsonObject, JsonType } from '../../types/JsonType'; +import { ErrorType } from '../../types/ocpp/ErrorType'; +import { MessageType } from '../../types/ocpp/MessageType'; import { IncomingRequestCommand, OutgoingRequest, @@ -6,19 +12,12 @@ import { RequestParams, ResponseType, } from '../../types/ocpp/Requests'; -import { JsonObject, JsonType } from '../../types/JsonType'; - -import type ChargingStation from '../ChargingStation'; +import { ErrorResponse, Response } from '../../types/ocpp/Responses'; import Constants from '../../utils/Constants'; -import { EmptyObject } from '../../types/EmptyObject'; -import { ErrorType } from '../../types/ocpp/ErrorType'; -import { HandleErrorParams } from '../../types/Error'; -import { MessageType } from '../../types/ocpp/MessageType'; -import OCPPError from '../../exception/OCPPError'; -import type OCPPResponseService from './OCPPResponseService'; -import PerformanceStatistics from '../../performance/PerformanceStatistics'; -import Utils from '../../utils/Utils'; import logger from '../../utils/Logger'; +import Utils from '../../utils/Utils'; +import type ChargingStation from '../ChargingStation'; +import type OCPPResponseService from './OCPPResponseService'; export default abstract class OCPPRequestService { private static instance: OCPPRequestService | null = null; diff --git a/src/charging-station/ocpp/OCPPResponseService.ts b/src/charging-station/ocpp/OCPPResponseService.ts index 19088aab..ffcb888f 100644 --- a/src/charging-station/ocpp/OCPPResponseService.ts +++ b/src/charging-station/ocpp/OCPPResponseService.ts @@ -1,6 +1,6 @@ -import type ChargingStation from '../ChargingStation'; import { JsonType } from '../../types/JsonType'; import { RequestCommand } from '../../types/ocpp/Requests'; +import type ChargingStation from '../ChargingStation'; export default abstract class OCPPResponseService { private static instance: OCPPResponseService | null = null; diff --git a/src/charging-station/ui-server/AbstractUIServer.ts b/src/charging-station/ui-server/AbstractUIServer.ts index 1c8ed1b5..432c91e7 100644 --- a/src/charging-station/ui-server/AbstractUIServer.ts +++ b/src/charging-station/ui-server/AbstractUIServer.ts @@ -1,8 +1,10 @@ -import AbstractUIService from './ui-services/AbstractUIService'; import { Server as HttpServer } from 'http'; -import { ProtocolVersion } from '../../types/UIProtocol'; + import WebSocket from 'ws'; +import { ProtocolVersion } from '../../types/UIProtocol'; +import AbstractUIService from './ui-services/AbstractUIService'; + export abstract class AbstractUIServer { public readonly chargingStations: Set; protected readonly uiServices: Map; diff --git a/src/charging-station/ui-server/UIServerFactory.ts b/src/charging-station/ui-server/UIServerFactory.ts index 26bbe6dd..b0020b2e 100644 --- a/src/charging-station/ui-server/UIServerFactory.ts +++ b/src/charging-station/ui-server/UIServerFactory.ts @@ -1,10 +1,11 @@ -import { AbstractUIServer } from './AbstractUIServer'; +import chalk from 'chalk'; + +import { ServerOptions } from '../../types/ConfigurationData'; import { ApplicationProtocol } from '../../types/UIProtocol'; import Configuration from '../../utils/Configuration'; -import { ServerOptions } from '../../types/ConfigurationData'; +import { AbstractUIServer } from './AbstractUIServer'; import { UIServiceUtils } from './ui-services/UIServiceUtils'; import UIWebSocketServer from './UIWebSocketServer'; -import chalk from 'chalk'; export default class UIServerFactory { private constructor() { diff --git a/src/charging-station/ui-server/UIWebSocketServer.ts b/src/charging-station/ui-server/UIWebSocketServer.ts index c67da00e..ad384779 100644 --- a/src/charging-station/ui-server/UIWebSocketServer.ts +++ b/src/charging-station/ui-server/UIWebSocketServer.ts @@ -1,13 +1,14 @@ -import { Protocol, ProtocolVersion } from '../../types/UIProtocol'; - -import { AbstractUIServer } from './AbstractUIServer'; -import Configuration from '../../utils/Configuration'; import { IncomingMessage } from 'http'; -import { ServerOptions } from '../../types/ConfigurationData'; -import UIServiceFactory from './ui-services/UIServiceFactory'; -import Utils from '../../utils/Utils'; + import WebSocket from 'ws'; + +import { ServerOptions } from '../../types/ConfigurationData'; +import { Protocol, ProtocolVersion } from '../../types/UIProtocol'; +import Configuration from '../../utils/Configuration'; import logger from '../../utils/Logger'; +import Utils from '../../utils/Utils'; +import { AbstractUIServer } from './AbstractUIServer'; +import UIServiceFactory from './ui-services/UIServiceFactory'; export default class UIWebSocketServer extends AbstractUIServer { public constructor(options?: ServerOptions) { diff --git a/src/charging-station/ui-server/ui-services/AbstractUIService.ts b/src/charging-station/ui-server/ui-services/AbstractUIService.ts index 151cff33..9b5e0885 100644 --- a/src/charging-station/ui-server/ui-services/AbstractUIService.ts +++ b/src/charging-station/ui-server/ui-services/AbstractUIService.ts @@ -1,15 +1,15 @@ +import { RawData } from 'ws'; + +import BaseError from '../../../exception/BaseError'; +import { JsonType } from '../../../types/JsonType'; import { ProtocolCommand, ProtocolRequest, ProtocolRequestHandler, } from '../../../types/UIProtocol'; - -import { AbstractUIServer } from '../AbstractUIServer'; -import BaseError from '../../../exception/BaseError'; -import { JsonType } from '../../../types/JsonType'; -import { RawData } from 'ws'; -import Utils from '../../../utils/Utils'; import logger from '../../../utils/Logger'; +import Utils from '../../../utils/Utils'; +import { AbstractUIServer } from '../AbstractUIServer'; export default abstract class AbstractUIService { protected readonly uiServer: AbstractUIServer; diff --git a/src/charging-station/ui-server/ui-services/UIService001.ts b/src/charging-station/ui-server/ui-services/UIService001.ts index cbe4c8c3..10f21f06 100644 --- a/src/charging-station/ui-server/ui-services/UIService001.ts +++ b/src/charging-station/ui-server/ui-services/UIService001.ts @@ -1,8 +1,7 @@ +import { JsonType } from '../../../types/JsonType'; import { ProtocolCommand, ProtocolRequestHandler } from '../../../types/UIProtocol'; - import { AbstractUIServer } from '../AbstractUIServer'; import AbstractUIService from './AbstractUIService'; -import { JsonType } from '../../../types/JsonType'; export default class UIService001 extends AbstractUIService { constructor(uiServer: AbstractUIServer) { diff --git a/src/charging-station/ui-server/ui-services/UIServiceFactory.ts b/src/charging-station/ui-server/ui-services/UIServiceFactory.ts index 7136e447..8fb55e04 100644 --- a/src/charging-station/ui-server/ui-services/UIServiceFactory.ts +++ b/src/charging-station/ui-server/ui-services/UIServiceFactory.ts @@ -1,6 +1,6 @@ +import { ProtocolVersion } from '../../../types/UIProtocol'; import { AbstractUIServer } from '../AbstractUIServer'; import AbstractUIService from './AbstractUIService'; -import { ProtocolVersion } from '../../../types/UIProtocol'; import UIService001 from './UIService001'; export default class UIServiceFactory { diff --git a/src/charging-station/ui-server/ui-services/UIServiceUtils.ts b/src/charging-station/ui-server/ui-services/UIServiceUtils.ts index 974d6fc4..573520b9 100644 --- a/src/charging-station/ui-server/ui-services/UIServiceUtils.ts +++ b/src/charging-station/ui-server/ui-services/UIServiceUtils.ts @@ -1,8 +1,8 @@ -import { Protocol, ProtocolVersion } from '../../../types/UIProtocol'; - import { IncomingMessage } from 'http'; -import Utils from '../../../utils/Utils'; + +import { Protocol, ProtocolVersion } from '../../../types/UIProtocol'; import logger from '../../../utils/Logger'; +import Utils from '../../../utils/Utils'; export class UIServiceUtils { private constructor() { diff --git a/src/exception/OCPPError.ts b/src/exception/OCPPError.ts index e67f3c95..563575a3 100644 --- a/src/exception/OCPPError.ts +++ b/src/exception/OCPPError.ts @@ -1,10 +1,9 @@ // Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +import { JsonType } from '../types/JsonType'; +import { ErrorType } from '../types/ocpp/ErrorType'; import { IncomingRequestCommand, RequestCommand } from '../types/ocpp/Requests'; - import BaseError from './BaseError'; -import { ErrorType } from '../types/ocpp/ErrorType'; -import { JsonType } from '../types/JsonType'; export default class OCPPError extends BaseError { code: ErrorType; diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index fdcabb33..8dda0253 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -1,17 +1,17 @@ // Partial Copyright Jerome Benoit. 2021. All Rights Reserved. -import { CircularArray, DEFAULT_CIRCULAR_ARRAY_SIZE } from '../utils/CircularArray'; -import { IncomingRequestCommand, RequestCommand } from '../types/ocpp/Requests'; import { PerformanceEntry, PerformanceObserver, performance } from 'perf_hooks'; -import Statistics, { StatisticsData, TimeSeries } from '../types/Statistics'; +import { URL } from 'url'; +import { parentPort } from 'worker_threads'; import { ChargingStationWorkerMessageEvents } from '../types/ChargingStationWorker'; -import Configuration from '../utils/Configuration'; import { MessageType } from '../types/ocpp/MessageType'; -import { URL } from 'url'; -import Utils from '../utils/Utils'; +import { IncomingRequestCommand, RequestCommand } from '../types/ocpp/Requests'; +import Statistics, { StatisticsData, TimeSeries } from '../types/Statistics'; +import { CircularArray, DEFAULT_CIRCULAR_ARRAY_SIZE } from '../utils/CircularArray'; +import Configuration from '../utils/Configuration'; import logger from '../utils/Logger'; -import { parentPort } from 'worker_threads'; +import Utils from '../utils/Utils'; export default class PerformanceStatistics { private static readonly instances: Map = new Map< diff --git a/src/performance/storage/JsonFileStorage.ts b/src/performance/storage/JsonFileStorage.ts index 17f5ad2f..bc28a6cb 100644 --- a/src/performance/storage/JsonFileStorage.ts +++ b/src/performance/storage/JsonFileStorage.ts @@ -1,11 +1,13 @@ // Copyright Jerome Benoit. 2021. All Rights Reserved. +import fs from 'fs'; + +import lockfile from 'proper-lockfile'; + import { FileType } from '../../types/FileType'; -import FileUtils from '../../utils/FileUtils'; import Statistics from '../../types/Statistics'; +import FileUtils from '../../utils/FileUtils'; import { Storage } from './Storage'; -import fs from 'fs'; -import lockfile from 'proper-lockfile'; export class JsonFileStorage extends Storage { private fd: number | null = null; diff --git a/src/performance/storage/MikroOrmStorage.ts b/src/performance/storage/MikroOrmStorage.ts index 1953491a..df96d6a6 100644 --- a/src/performance/storage/MikroOrmStorage.ts +++ b/src/performance/storage/MikroOrmStorage.ts @@ -1,14 +1,14 @@ // Copyright Jerome Benoit. 2021. All Rights Reserved. import { Configuration, Connection, IDatabaseDriver, MikroORM, Options } from '@mikro-orm/core'; -import { MikroORMDBType, StorageType } from '../../types/Storage'; +import { TsMorphMetadataProvider } from '@mikro-orm/reflection'; -import Constants from '../../utils/Constants'; import { PerformanceData } from '../../types/orm/entities/PerformanceData'; import { PerformanceRecord } from '../../types/orm/entities/PerformanceRecord'; import Statistics from '../../types/Statistics'; +import { MikroORMDBType, StorageType } from '../../types/Storage'; +import Constants from '../../utils/Constants'; import { Storage } from './Storage'; -import { TsMorphMetadataProvider } from '@mikro-orm/reflection'; export class MikroOrmStorage extends Storage { private storageType: StorageType; diff --git a/src/performance/storage/MongoDBStorage.ts b/src/performance/storage/MongoDBStorage.ts index cefab6f3..d941d7c1 100644 --- a/src/performance/storage/MongoDBStorage.ts +++ b/src/performance/storage/MongoDBStorage.ts @@ -1,10 +1,11 @@ // Copyright Jerome Benoit. 2021. All Rights Reserved. -import Constants from '../../utils/Constants'; import { MongoClient } from 'mongodb'; + import Statistics from '../../types/Statistics'; -import { Storage } from './Storage'; import { StorageType } from '../../types/Storage'; +import Constants from '../../utils/Constants'; +import { Storage } from './Storage'; export class MongoDBStorage extends Storage { private readonly client: MongoClient | null; diff --git a/src/performance/storage/Storage.ts b/src/performance/storage/Storage.ts index 4770fb75..565c15df 100644 --- a/src/performance/storage/Storage.ts +++ b/src/performance/storage/Storage.ts @@ -1,13 +1,13 @@ // Copyright Jerome Benoit. 2021. All Rights Reserved. -import { DBName, StorageType } from '../../types/Storage'; +import { URL } from 'url'; import { EmptyObject } from '../../types/EmptyObject'; import { HandleErrorParams } from '../../types/Error'; import Statistics from '../../types/Statistics'; -import { URL } from 'url'; -import Utils from '../../utils/Utils'; +import { DBName, StorageType } from '../../types/Storage'; import logger from '../../utils/Logger'; +import Utils from '../../utils/Utils'; export abstract class Storage { protected readonly storageUri: URL; diff --git a/src/performance/storage/StorageFactory.ts b/src/performance/storage/StorageFactory.ts index 677ae8f2..b4c19d58 100644 --- a/src/performance/storage/StorageFactory.ts +++ b/src/performance/storage/StorageFactory.ts @@ -1,10 +1,10 @@ // Copyright Jerome Benoit. 2021. All Rights Reserved. +import { StorageType } from '../../types/Storage'; import { JsonFileStorage } from './JsonFileStorage'; import { MikroOrmStorage } from './MikroOrmStorage'; import { MongoDBStorage } from './MongoDBStorage'; import { Storage } from './Storage'; -import { StorageType } from '../../types/Storage'; export class StorageFactory { private constructor() { diff --git a/src/scripts/deleteChargingStations.js b/src/scripts/deleteChargingStations.js index e720136b..8d1d601a 100755 --- a/src/scripts/deleteChargingStations.js +++ b/src/scripts/deleteChargingStations.js @@ -1,8 +1,9 @@ #!/usr/bin/env node -const MongoClient = require('mongodb'); const fs = require('fs'); +const MongoClient = require('mongodb'); + // This script deletes charging stations // Filter charging stations by id pattern diff --git a/src/scripts/setCSPublicFlag.js b/src/scripts/setCSPublicFlag.js index 0b334c1a..29b87a7e 100755 --- a/src/scripts/setCSPublicFlag.js +++ b/src/scripts/setCSPublicFlag.js @@ -1,8 +1,9 @@ #!/usr/bin/env node -const MongoClient = require('mongodb'); const fs = require('fs'); +const MongoClient = require('mongodb'); + // This script sets charging stations public or private // Filter charging stations by id pattern diff --git a/src/start.ts b/src/start.ts index ebad51ef..d5c28b0b 100644 --- a/src/start.ts +++ b/src/start.ts @@ -1,8 +1,9 @@ // Partial Copyright Jerome Benoit. 2021. All Rights Reserved. -import Bootstrap from './charging-station/Bootstrap'; import chalk from 'chalk'; +import Bootstrap from './charging-station/Bootstrap'; + Bootstrap.getInstance() .start() .catch((error) => { diff --git a/src/types/ChargingStationTemplate.ts b/src/types/ChargingStationTemplate.ts index 639cf8f7..6a2abe89 100644 --- a/src/types/ChargingStationTemplate.ts +++ b/src/types/ChargingStationTemplate.ts @@ -1,7 +1,9 @@ +import { ClientRequestArgs } from 'http'; + +import { ClientOptions } from 'ws'; + import { AutomaticTransactionGeneratorConfiguration } from './AutomaticTransactionGenerator'; import ChargingStationOcppConfiguration from './ChargingStationOcppConfiguration'; -import { ClientOptions } from 'ws'; -import { ClientRequestArgs } from 'http'; import { ConnectorStatus } from './ConnectorStatus'; import { OCPPProtocol } from './ocpp/OCPPProtocol'; import { OCPPVersion } from './ocpp/OCPPVersion'; diff --git a/src/types/ChargingStationWorker.ts b/src/types/ChargingStationWorker.ts index fe09514f..945d3d20 100644 --- a/src/types/ChargingStationWorker.ts +++ b/src/types/ChargingStationWorker.ts @@ -1,6 +1,5 @@ -import { WorkerData, WorkerMessage, WorkerMessageEvents } from './Worker'; - import { JsonObject } from './JsonType'; +import { WorkerData, WorkerMessage, WorkerMessageEvents } from './Worker'; export interface ChargingStationWorkerOptions extends JsonObject { elementStartDelay?: number; diff --git a/src/types/ConfigurationData.ts b/src/types/ConfigurationData.ts index 708f411c..e5493681 100644 --- a/src/types/ConfigurationData.ts +++ b/src/types/ConfigurationData.ts @@ -1,7 +1,9 @@ import { ListenOptions } from 'net'; -import { StorageType } from './Storage'; -import { ServerOptions as WSServerOptions } from 'ws'; + import type { WorkerChoiceStrategy } from 'poolifier'; +import { ServerOptions as WSServerOptions } from 'ws'; + +import { StorageType } from './Storage'; import { WorkerProcessType } from './Worker'; export type ServerOptions = WSServerOptions & ListenOptions; diff --git a/src/types/ConnectorStatus.ts b/src/types/ConnectorStatus.ts index c63dd3db..6eab4106 100644 --- a/src/types/ConnectorStatus.ts +++ b/src/types/ConnectorStatus.ts @@ -1,8 +1,8 @@ -import { AvailabilityType } from './ocpp/Requests'; +import { SampledValueTemplate } from './MeasurandPerPhaseSampledValueTemplates'; import { ChargePointStatus } from './ocpp/ChargePointStatus'; import { ChargingProfile } from './ocpp/ChargingProfile'; import { MeterValue } from './ocpp/MeterValues'; -import { SampledValueTemplate } from './MeasurandPerPhaseSampledValueTemplates'; +import { AvailabilityType } from './ocpp/Requests'; export interface ConnectorStatus { availability: AvailabilityType; diff --git a/src/types/Worker.ts b/src/types/Worker.ts index 05dc4158..c9882ccd 100644 --- a/src/types/Worker.ts +++ b/src/types/Worker.ts @@ -1,7 +1,9 @@ -import { JsonObject } from './JsonType'; -import { PoolOptions } from 'poolifier'; import { Worker } from 'worker_threads'; +import { PoolOptions } from 'poolifier'; + +import { JsonObject } from './JsonType'; + export enum WorkerProcessType { WORKER_SET = 'workerSet', DYNAMIC_POOL = 'dynamicPool', diff --git a/src/types/ocpp/1.6/Requests.ts b/src/types/ocpp/1.6/Requests.ts index 1499e4ff..8eb0657e 100644 --- a/src/types/ocpp/1.6/Requests.ts +++ b/src/types/ocpp/1.6/Requests.ts @@ -1,11 +1,10 @@ -import { ChargingProfilePurposeType, OCPP16ChargingProfile } from './ChargingProfile'; - import { EmptyObject } from '../../EmptyObject'; import { JsonObject } from '../../JsonType'; import { OCPP16ChargePointErrorCode } from './ChargePointErrorCode'; import { OCPP16ChargePointStatus } from './ChargePointStatus'; -import { OCPP16DiagnosticsStatus } from './DiagnosticsStatus'; +import { ChargingProfilePurposeType, OCPP16ChargingProfile } from './ChargingProfile'; import { OCPP16StandardParametersKey } from './Configuration'; +import { OCPP16DiagnosticsStatus } from './DiagnosticsStatus'; export enum OCPP16RequestCommand { BOOT_NOTIFICATION = 'BootNotification', diff --git a/src/types/ocpp/Configuration.ts b/src/types/ocpp/Configuration.ts index 5aa96818..31d71499 100644 --- a/src/types/ocpp/Configuration.ts +++ b/src/types/ocpp/Configuration.ts @@ -1,11 +1,10 @@ +import { JsonObject } from '../JsonType'; import { OCPP16StandardParametersKey, OCPP16SupportedFeatureProfiles, OCPP16VendorDefaultParametersKey, } from './1.6/Configuration'; -import { JsonObject } from '../JsonType'; - export type StandardParametersKey = OCPP16StandardParametersKey; export const StandardParametersKey = { diff --git a/src/types/ocpp/Requests.ts b/src/types/ocpp/Requests.ts index 485d58a1..e931e83f 100644 --- a/src/types/ocpp/Requests.ts +++ b/src/types/ocpp/Requests.ts @@ -1,3 +1,8 @@ +import type ChargingStation from '../../charging-station/ChargingStation'; +import OCPPError from '../../exception/OCPPError'; +import { JsonType } from '../JsonType'; +import { OCPP16DiagnosticsStatus } from './1.6/DiagnosticsStatus'; +import { OCPP16MeterValuesRequest } from './1.6/MeterValues'; import { OCPP16AvailabilityType, OCPP16BootNotificationRequest, @@ -6,13 +11,7 @@ import { OCPP16RequestCommand, OCPP16StatusNotificationRequest, } from './1.6/Requests'; - -import type ChargingStation from '../../charging-station/ChargingStation'; -import { JsonType } from '../JsonType'; import { MessageType } from './MessageType'; -import { OCPP16DiagnosticsStatus } from './1.6/DiagnosticsStatus'; -import { OCPP16MeterValuesRequest } from './1.6/MeterValues'; -import OCPPError from '../../exception/OCPPError'; export type OutgoingRequest = [MessageType.CALL_MESSAGE, string, RequestCommand, JsonType]; diff --git a/src/types/ocpp/Responses.ts b/src/types/ocpp/Responses.ts index 62df6ccd..d5b4b7c5 100644 --- a/src/types/ocpp/Responses.ts +++ b/src/types/ocpp/Responses.ts @@ -1,3 +1,6 @@ +import type ChargingStation from '../../charging-station/ChargingStation'; +import { JsonType } from '../JsonType'; +import { OCPP16MeterValuesResponse } from './1.6/MeterValues'; import { OCPP16AvailabilityStatus, OCPP16BootNotificationResponse, @@ -10,12 +13,8 @@ import { OCPP16TriggerMessageStatus, OCPP16UnlockStatus, } from './1.6/Responses'; - -import type ChargingStation from '../../charging-station/ChargingStation'; import { ErrorType } from './ErrorType'; -import { JsonType } from '../JsonType'; import { MessageType } from './MessageType'; -import { OCPP16MeterValuesResponse } from './1.6/MeterValues'; export type Response = [MessageType.CALL_RESULT_MESSAGE, string, JsonType]; diff --git a/src/ui/httpd/start.ts b/src/ui/httpd/start.ts index dffb3315..116b9174 100644 --- a/src/ui/httpd/start.ts +++ b/src/ui/httpd/start.ts @@ -1,6 +1,7 @@ -import Bootstrap from '../../charging-station/Bootstrap'; import express from 'express'; +import Bootstrap from '../../charging-station/Bootstrap'; + const pageHeader = ` diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 67cf501b..c185133a 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -1,3 +1,9 @@ +import fs from 'fs'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +import chalk from 'chalk'; + import ConfigurationData, { StationTemplateUrl, StorageConfiguration, @@ -5,18 +11,13 @@ import ConfigurationData, { UIServerConfiguration, WorkerConfiguration, } from '../types/ConfigurationData'; - -import Constants from './Constants'; import { EmptyObject } from '../types/EmptyObject'; -import { FileType } from '../types/FileType'; import { HandleErrorParams } from '../types/Error'; +import { FileType } from '../types/FileType'; import { StorageType } from '../types/Storage'; -import WorkerConstants from '../worker/WorkerConstants'; import { WorkerProcessType } from '../types/Worker'; -import chalk from 'chalk'; -import { fileURLToPath } from 'url'; -import fs from 'fs'; -import path from 'path'; +import WorkerConstants from '../worker/WorkerConstants'; +import Constants from './Constants'; export default class Configuration { private static configurationFile = path.join( diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index 1c420879..ee8bcb41 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -1,3 +1,4 @@ +import { MeterValueMeasurand } from '../types/ocpp/MeterValues'; import { AvailabilityStatus, ChargingProfileStatus, @@ -8,8 +9,6 @@ import { UnlockStatus, } from '../types/ocpp/Responses'; -import { MeterValueMeasurand } from '../types/ocpp/MeterValues'; - export default class Constants { static readonly OCPP_RESPONSE_EMPTY = Object.freeze({}); static readonly OCPP_RESPONSE_ACCEPTED = Object.freeze({ status: DefaultStatus.ACCEPTED }); diff --git a/src/utils/FileUtils.ts b/src/utils/FileUtils.ts index e36e85f7..7d1dbd66 100644 --- a/src/utils/FileUtils.ts +++ b/src/utils/FileUtils.ts @@ -1,11 +1,13 @@ +import fs from 'fs'; + +import chalk from 'chalk'; + import { EmptyObject } from '../types/EmptyObject'; -import { FileType } from '../types/FileType'; import { HandleErrorParams } from '../types/Error'; +import { FileType } from '../types/FileType'; import { JsonType } from '../types/JsonType'; -import Utils from './Utils'; -import chalk from 'chalk'; -import fs from 'fs'; import logger from './Logger'; +import Utils from './Utils'; export default class FileUtils { private constructor() { diff --git a/src/utils/Logger.ts b/src/utils/Logger.ts index aba00c74..60a101d0 100644 --- a/src/utils/Logger.ts +++ b/src/utils/Logger.ts @@ -1,9 +1,9 @@ +import { Format } from 'logform'; import { Logger, createLogger, format, transport } from 'winston'; - -import Configuration from './Configuration'; import DailyRotateFile from 'winston-daily-rotate-file'; -import { Format } from 'logform'; import TransportType from 'winston/lib/winston/transports/index.js'; + +import Configuration from './Configuration'; import Utils from './Utils'; let transports: transport[]; diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 9486ca09..1ad1a792 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -1,4 +1,5 @@ import crypto from 'crypto'; + import { v4 as uuid } from 'uuid'; export default class Utils { diff --git a/src/worker/WorkerAbstract.ts b/src/worker/WorkerAbstract.ts index 1dd064fb..3fbd4a0b 100644 --- a/src/worker/WorkerAbstract.ts +++ b/src/worker/WorkerAbstract.ts @@ -1,7 +1,7 @@ -import { WorkerData, WorkerOptions } from '../types/Worker'; +import fs from 'fs'; +import { WorkerData, WorkerOptions } from '../types/Worker'; import WorkerConstants from './WorkerConstants'; -import fs from 'fs'; export default abstract class WorkerAbstract { protected readonly workerScript: string; diff --git a/src/worker/WorkerDynamicPool.ts b/src/worker/WorkerDynamicPool.ts index dfa34423..68813e20 100644 --- a/src/worker/WorkerDynamicPool.ts +++ b/src/worker/WorkerDynamicPool.ts @@ -1,6 +1,6 @@ -import { WorkerData, WorkerOptions } from '../types/Worker'; - import { DynamicThreadPool } from 'poolifier'; + +import { WorkerData, WorkerOptions } from '../types/Worker'; import Utils from '../utils/Utils'; import WorkerAbstract from './WorkerAbstract'; import { WorkerUtils } from './WorkerUtils'; diff --git a/src/worker/WorkerFactory.ts b/src/worker/WorkerFactory.ts index d95f4d32..01adb96e 100644 --- a/src/worker/WorkerFactory.ts +++ b/src/worker/WorkerFactory.ts @@ -1,7 +1,8 @@ import { Worker, isMainThread } from 'worker_threads'; -import { WorkerData, WorkerOptions, WorkerProcessType } from '../types/Worker'; import { PoolOptions } from 'poolifier'; + +import { WorkerData, WorkerOptions, WorkerProcessType } from '../types/Worker'; import type WorkerAbstract from './WorkerAbstract'; import WorkerConstants from './WorkerConstants'; import WorkerDynamicPool from './WorkerDynamicPool'; diff --git a/src/worker/WorkerSet.ts b/src/worker/WorkerSet.ts index 73014977..956d97de 100644 --- a/src/worker/WorkerSet.ts +++ b/src/worker/WorkerSet.ts @@ -1,9 +1,9 @@ // Partial Copyright Jerome Benoit. 2021. All Rights Reserved. -import { WorkerData, WorkerMessageEvents, WorkerOptions, WorkerSetElement } from '../types/Worker'; +import { Worker } from 'worker_threads'; +import { WorkerData, WorkerMessageEvents, WorkerOptions, WorkerSetElement } from '../types/Worker'; import Utils from '../utils/Utils'; -import { Worker } from 'worker_threads'; import WorkerAbstract from './WorkerAbstract'; import { WorkerUtils } from './WorkerUtils'; diff --git a/src/worker/WorkerStaticPool.ts b/src/worker/WorkerStaticPool.ts index 3eaffff4..99ea301d 100644 --- a/src/worker/WorkerStaticPool.ts +++ b/src/worker/WorkerStaticPool.ts @@ -1,6 +1,6 @@ -import { WorkerData, WorkerOptions } from '../types/Worker'; - import { FixedThreadPool } from 'poolifier'; + +import { WorkerData, WorkerOptions } from '../types/Worker'; import Utils from '../utils/Utils'; import WorkerAbstract from './WorkerAbstract'; import { WorkerUtils } from './WorkerUtils'; diff --git a/test/robohydra/plugins/wsServer/index.js b/test/robohydra/plugins/wsServer/index.js index 485ee19e..95793056 100644 --- a/test/robohydra/plugins/wsServer/index.js +++ b/test/robohydra/plugins/wsServer/index.js @@ -1,7 +1,10 @@ -const RoboHydraHead = require('robohydra').heads.RoboHydraHead; -const RoboHydraWebSocketHead = require('robohydra').heads.RoboHydraWebSocketHead; -const RoboHydraWebSocketHeadProxy = require('robohydra').heads.RoboHydraWebSocketHeadProxy; +// eslint-disable-next-line node/no-unpublished-require +const RoboHydra = require('robohydra'); +const RoboHydraHead = RoboHydra.heads.RoboHydraHead; +const RoboHydraWebSocketHead = RoboHydra.heads.RoboHydraWebSocketHead; +const RoboHydraWebSocketHeadProxy = RoboHydra.heads.RoboHydraWebSocketHeadProxy; +// eslint-disable-next-line no-unused-vars exports.getBodyParts = function (conf) { let wsSocket; return { diff --git a/test/utils/CircularArrayTest.ts b/test/utils/CircularArrayTest.ts index c1c2e67e..c8b38a9a 100644 --- a/test/utils/CircularArrayTest.ts +++ b/test/utils/CircularArrayTest.ts @@ -1,6 +1,7 @@ -import { CircularArray } from '../../src/utils/CircularArray'; import { expect } from 'expect'; +import { CircularArray } from '../../src/utils/CircularArray'; + describe('Circular array test suite', () => { it('Verify that circular array can be instantiated', () => { const circularArray = new CircularArray();