"ecmaVersion": 2020,
"sourceType": "module"
},
- "extends": [
- "eslint:recommended",
- "plugin:import/recommended",
- "plugin:jsdoc/recommended",
- "plugin:prettier/recommended"
- ],
- "plugins": ["import", "jsdoc"],
+ "plugins": ["import"],
+ "extends": ["eslint:recommended", "plugin:import/recommended", "plugin:prettier/recommended"],
"settings": {
- "jsdoc": {
- "mode": "typescript"
- },
"import/resolver": {
"typescript": {
"project": "./tsconfig.json"
"parserOptions": {
"project": "./tsconfig.json"
},
+ "plugins": ["@typescript-eslint", "eslint-plugin-tsdoc"],
"extends": [
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:import/typescript"
],
- "plugins": ["@typescript-eslint"],
"rules": {
+ "tsdoc/syntax": "warn",
"@typescript-eslint/array-type": "off",
"semi": "off",
"@typescript-eslint/semi": ["error", "always"],
},
{
"files": ["**/*.js"],
- "extends": "plugin:n/recommended",
+ "plugins": ["jsdoc"],
+ "extends": ["plugin:jsdoc/recommended", "plugin:n/recommended"],
"rules": {
"n/shebang": "off"
}
"eslint-plugin-jsdoc": "^39.6.4",
"eslint-plugin-n": "^15.6.0",
"eslint-plugin-prettier": "^4.2.1",
+ "eslint-plugin-tsdoc": "^0.2.17",
"expect": "^29.3.1",
"husky": "^8.0.2",
"lint-staged": "^13.1.0",
"integrity": "sha512-EWUguj2kd7ldmrF9F+vI5hUOralPd+sdsUnYbRy33vZTuZkduC1shE9TtEMEjAQwyfyMb4ole5KtjF8MsnQOlA==",
"dev": true
},
+ "node_modules/@microsoft/tsdoc": {
+ "version": "0.14.2",
+ "resolved": "https://registry.npmjs.org/@microsoft/tsdoc/-/tsdoc-0.14.2.tgz",
+ "integrity": "sha512-9b8mPpKrfeGRuhFH5iO1iwCLeIIsV6+H1sRfxbkoGXIyQE2BTsPd9zqSqQJ+pv5sJ/hT5M1zvOFL02MnEezFug==",
+ "dev": true
+ },
+ "node_modules/@microsoft/tsdoc-config": {
+ "version": "0.16.2",
+ "resolved": "https://registry.npmjs.org/@microsoft/tsdoc-config/-/tsdoc-config-0.16.2.tgz",
+ "integrity": "sha512-OGiIzzoBLgWWR0UdRJX98oYO+XKGf7tiK4Zk6tQ/E4IJqGCe7dvkTvgDZV5cFJUzLGDOjeAXrnZoA6QkVySuxw==",
+ "dev": true,
+ "dependencies": {
+ "@microsoft/tsdoc": "0.14.2",
+ "ajv": "~6.12.6",
+ "jju": "~1.4.0",
+ "resolve": "~1.19.0"
+ }
+ },
+ "node_modules/@microsoft/tsdoc-config/node_modules/ajv": {
+ "version": "6.12.6",
+ "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
+ "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==",
+ "dev": true,
+ "dependencies": {
+ "fast-deep-equal": "^3.1.1",
+ "fast-json-stable-stringify": "^2.0.0",
+ "json-schema-traverse": "^0.4.1",
+ "uri-js": "^4.2.2"
+ },
+ "funding": {
+ "type": "github",
+ "url": "https://github.com/sponsors/epoberezkin"
+ }
+ },
+ "node_modules/@microsoft/tsdoc-config/node_modules/json-schema-traverse": {
+ "version": "0.4.1",
+ "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
+ "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==",
+ "dev": true
+ },
+ "node_modules/@microsoft/tsdoc-config/node_modules/resolve": {
+ "version": "1.19.0",
+ "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.19.0.tgz",
+ "integrity": "sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg==",
+ "dev": true,
+ "dependencies": {
+ "is-core-module": "^2.1.0",
+ "path-parse": "^1.0.6"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
"node_modules/@mikro-orm/cli": {
"version": "5.6.3",
"resolved": "https://registry.npmjs.org/@mikro-orm/cli/-/cli-5.6.3.tgz",
}
}
},
+ "node_modules/eslint-plugin-tsdoc": {
+ "version": "0.2.17",
+ "resolved": "https://registry.npmjs.org/eslint-plugin-tsdoc/-/eslint-plugin-tsdoc-0.2.17.tgz",
+ "integrity": "sha512-xRmVi7Zx44lOBuYqG8vzTXuL6IdGOeF9nHX17bjJ8+VE6fsxpdGem0/SBTmAwgYMKYB1WBkqRJVQ+n8GK041pA==",
+ "dev": true,
+ "dependencies": {
+ "@microsoft/tsdoc": "0.14.2",
+ "@microsoft/tsdoc-config": "0.16.2"
+ }
+ },
"node_modules/eslint-scope": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz",
"node": ">= 10.13.0"
}
},
+ "node_modules/jju": {
+ "version": "1.4.0",
+ "resolved": "https://registry.npmjs.org/jju/-/jju-1.4.0.tgz",
+ "integrity": "sha512-8wb9Yw966OSxApiCt0K3yNJL8pnNeIv+OEq2YMidz4FKP6nonSRoOXc80iXY4JaN2FC11B9qsNmDsm+ZOfMROA==",
+ "dev": true
+ },
"node_modules/js-sdsl": {
"version": "4.1.4",
"resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.1.4.tgz",
"integrity": "sha512-EWUguj2kd7ldmrF9F+vI5hUOralPd+sdsUnYbRy33vZTuZkduC1shE9TtEMEjAQwyfyMb4ole5KtjF8MsnQOlA==",
"dev": true
},
+ "@microsoft/tsdoc": {
+ "version": "0.14.2",
+ "resolved": "https://registry.npmjs.org/@microsoft/tsdoc/-/tsdoc-0.14.2.tgz",
+ "integrity": "sha512-9b8mPpKrfeGRuhFH5iO1iwCLeIIsV6+H1sRfxbkoGXIyQE2BTsPd9zqSqQJ+pv5sJ/hT5M1zvOFL02MnEezFug==",
+ "dev": true
+ },
+ "@microsoft/tsdoc-config": {
+ "version": "0.16.2",
+ "resolved": "https://registry.npmjs.org/@microsoft/tsdoc-config/-/tsdoc-config-0.16.2.tgz",
+ "integrity": "sha512-OGiIzzoBLgWWR0UdRJX98oYO+XKGf7tiK4Zk6tQ/E4IJqGCe7dvkTvgDZV5cFJUzLGDOjeAXrnZoA6QkVySuxw==",
+ "dev": true,
+ "requires": {
+ "@microsoft/tsdoc": "0.14.2",
+ "ajv": "~6.12.6",
+ "jju": "~1.4.0",
+ "resolve": "~1.19.0"
+ },
+ "dependencies": {
+ "ajv": {
+ "version": "6.12.6",
+ "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
+ "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==",
+ "dev": true,
+ "requires": {
+ "fast-deep-equal": "^3.1.1",
+ "fast-json-stable-stringify": "^2.0.0",
+ "json-schema-traverse": "^0.4.1",
+ "uri-js": "^4.2.2"
+ }
+ },
+ "json-schema-traverse": {
+ "version": "0.4.1",
+ "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
+ "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==",
+ "dev": true
+ },
+ "resolve": {
+ "version": "1.19.0",
+ "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.19.0.tgz",
+ "integrity": "sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg==",
+ "dev": true,
+ "requires": {
+ "is-core-module": "^2.1.0",
+ "path-parse": "^1.0.6"
+ }
+ }
+ }
+ },
"@mikro-orm/cli": {
"version": "5.6.3",
"resolved": "https://registry.npmjs.org/@mikro-orm/cli/-/cli-5.6.3.tgz",
"prettier-linter-helpers": "^1.0.0"
}
},
+ "eslint-plugin-tsdoc": {
+ "version": "0.2.17",
+ "resolved": "https://registry.npmjs.org/eslint-plugin-tsdoc/-/eslint-plugin-tsdoc-0.2.17.tgz",
+ "integrity": "sha512-xRmVi7Zx44lOBuYqG8vzTXuL6IdGOeF9nHX17bjJ8+VE6fsxpdGem0/SBTmAwgYMKYB1WBkqRJVQ+n8GK041pA==",
+ "dev": true,
+ "requires": {
+ "@microsoft/tsdoc": "0.14.2",
+ "@microsoft/tsdoc-config": "0.16.2"
+ }
+ },
"eslint-scope": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz",
"supports-color": "^7.0.0"
}
},
+ "jju": {
+ "version": "1.4.0",
+ "resolved": "https://registry.npmjs.org/jju/-/jju-1.4.0.tgz",
+ "integrity": "sha512-8wb9Yw966OSxApiCt0K3yNJL8pnNeIv+OEq2YMidz4FKP6nonSRoOXc80iXY4JaN2FC11B9qsNmDsm+ZOfMROA==",
+ "dev": true
+ },
"js-sdsl": {
"version": "4.1.4",
"resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.1.4.tgz",
"eslint-plugin-jsdoc": "^39.6.4",
"eslint-plugin-n": "^15.6.0",
"eslint-plugin-prettier": "^4.2.1",
+ "eslint-plugin-tsdoc": "^0.2.17",
"expect": "^29.3.1",
"husky": "^8.0.2",
"lint-staged": "^13.1.0",
} from '../types/ChargingStationWorker';
import type { StationTemplateUrl } from '../types/ConfigurationData';
import type { Statistics } from '../types/Statistics';
+import type { MessageHandler } from '../types/Worker';
import Configuration from '../utils/Configuration';
import logger from '../utils/Logger';
import Utils from '../utils/Utils';
poolOptions: {
workerChoiceStrategy: Configuration.getWorker().poolStrategy,
},
- messageHandler: this.messageHandler.bind(this) as (
- this: Worker,
- msg: ChargingStationWorkerMessage<ChargingStationWorkerMessageData>
- ) => void,
+ messageHandler: this.messageHandler.bind(this) as MessageHandler<Worker>,
}
));
}
/**
* Charging profiles should already be sorted by connectorId and stack level (highest stack level has priority)
*
- * @param {ChargingProfile[]} chargingProfiles
- * @param {string} logPrefix
- * @returns {{ limit, matchingChargingProfile }}
+ * @param chargingProfiles -
+ * @param logPrefix -
+ * @returns
*/
public static getLimitFromChargingProfiles(
chargingProfiles: ChargingProfile[],
/**
* Create and start a charging station instance
*
- * @param data workerData
+ * @param data - workerData
*/
function startChargingStation(data: ChargingStationWorkerData): void {
const station = new ChargingStation(data.index, data.templateFile);
/**
* Function that will receive the request's response
*
- * @param payload
- * @param requestPayload
+ * @param payload -
+ * @param requestPayload -
*/
function responseCallback(payload: JsonType, requestPayload: JsonType): void {
if (chargingStation.getEnableStatistics() === true) {
/**
* Function that will receive the request's error response
*
- * @param error
- * @param requestStatistic
+ * @param error -
+ * @param requestStatistic -
*/
function errorCallback(error: OCPPError, requestStatistic = true): void {
if (requestStatistic === true && chargingStation.getEnableStatistics() === true) {
STATIC_POOL = 'staticPool',
}
+export type MessageHandler<T> = (this: T, message: unknown) => void;
+
export type WorkerOptions = {
workerStartDelay?: number;
elementStartDelay?: number;
poolMinSize?: number;
elementsPerWorker?: number;
poolOptions?: PoolOptions<Worker>;
- messageHandler?: (this: Worker, message: unknown) => void;
+ messageHandler?: MessageHandler<Worker>;
};
export type WorkerData = Record<string, unknown>;
`${str.slice(0, pos)}${subStr}${str.slice(pos)}`;
/**
- * @param [retryNumber=0]
+ * @param retryNumber - the number of retries that have already been attempted
* @returns delay in milliseconds
*/
public static exponentialDelay(retryNumber = 0): number {
/**
* Convert websocket error code to human readable string message
*
- * @param code websocket error code
+ * @param code - websocket error code
* @returns human readable string message
*/
public static getWebSocketCloseEventStatusString(code: number): string {
/**
* `WorkerAbstract` constructor.
*
- * @param workerScript
- * @param workerOptions
+ * @param workerScript -
+ * @param workerOptions -
*/
constructor(
workerScript: string,
-import { DynamicThreadPool } from 'poolifier';
+import type { Worker } from 'worker_threads';
+
+import { DynamicThreadPool, type ErrorHandler, type ExitHandler } from 'poolifier';
import type { WorkerData, WorkerOptions } from '../types/Worker';
import Utils from '../utils/Utils';
/**
* Create a new `WorkerDynamicPool`.
*
- * @param workerScript
- * @param workerOptions
+ * @param workerScript -
+ * @param workerOptions -
*/
constructor(workerScript: string, workerOptions?: WorkerOptions) {
super(workerScript, workerOptions);
- this.workerOptions.poolOptions.errorHandler =
- this.workerOptions?.poolOptions?.errorHandler ?? WorkerUtils.defaultErrorHandler;
- this.workerOptions.poolOptions.exitHandler =
- this.workerOptions?.poolOptions?.exitHandler ?? WorkerUtils.defaultExitHandler;
+ this.workerOptions.poolOptions.errorHandler = (
+ this.workerOptions?.poolOptions?.errorHandler ?? WorkerUtils.defaultErrorHandler
+ ).bind(this) as ErrorHandler<Worker>;
+ this.workerOptions.poolOptions.exitHandler = (
+ this.workerOptions?.poolOptions?.exitHandler ?? WorkerUtils.defaultExitHandler
+ ).bind(this) as ExitHandler<Worker>;
+ this.workerOptions.poolOptions.messageHandler.bind(this);
this.pool = new DynamicThreadPool<WorkerData>(
this.workerOptions.poolMinSize,
this.workerOptions.poolMaxSize,
/**
*
- * @param elementData
+ * @param elementData -
* @returns
* @public
*/
import { Worker } from 'worker_threads';
-import { WorkerData, WorkerMessageEvents, WorkerOptions, WorkerSetElement } from '../types/Worker';
+import {
+ type MessageHandler,
+ type WorkerData,
+ WorkerMessageEvents,
+ type WorkerOptions,
+ type WorkerSetElement,
+} from '../types/Worker';
import Utils from '../utils/Utils';
import WorkerAbstract from './WorkerAbstract';
import { WorkerUtils } from './WorkerUtils';
export default class WorkerSet extends WorkerAbstract<WorkerData> {
private readonly workerSet: Set<WorkerSetElement>;
- private readonly messageHandler: (message: unknown) => void;
/**
* Create a new `WorkerSet`.
*
- * @param workerScript
- * @param workerOptions
+ * @param workerScript -
+ * @param workerOptions -
*/
constructor(workerScript: string, workerOptions?: WorkerOptions) {
super(workerScript, workerOptions);
this.workerSet = new Set<WorkerSetElement>();
- this.messageHandler =
- workerOptions?.messageHandler ??
- (() => {
- /* This is intentional */
- });
}
get size(): number {
/**
*
- * @param elementData
+ * @param elementData -
* @returns
* @public
*/
*/
private async startWorker(): Promise<void> {
const worker = new Worker(this.workerScript);
- worker.on('message', this.messageHandler);
- worker.on('error', WorkerUtils.defaultErrorHandler);
+ worker.on(
+ 'message',
+ (
+ this.workerOptions?.messageHandler ??
+ (() => {
+ /* This is intentional */
+ })
+ ).bind(this) as MessageHandler<Worker>
+ );
+ worker.on('error', WorkerUtils.defaultErrorHandler.bind(this) as (err: Error) => void);
worker.on('exit', (code) => {
WorkerUtils.defaultExitHandler(code);
this.workerSet.delete(this.getWorkerSetElementByWorker(worker));
-import { FixedThreadPool } from 'poolifier';
+import type { Worker } from 'worker_threads';
+
+import { type ErrorHandler, type ExitHandler, FixedThreadPool } from 'poolifier';
import type { WorkerData, WorkerOptions } from '../types/Worker';
import Utils from '../utils/Utils';
/**
* Create a new `WorkerStaticPool`.
*
- * @param workerScript
- * @param workerOptions
+ * @param workerScript -
+ * @param workerOptions -
*/
constructor(workerScript: string, workerOptions?: WorkerOptions) {
super(workerScript, workerOptions);
- this.workerOptions.poolOptions.errorHandler =
- this.workerOptions?.poolOptions?.errorHandler ?? WorkerUtils.defaultErrorHandler;
- this.workerOptions.poolOptions.exitHandler =
- this.workerOptions?.poolOptions?.exitHandler ?? WorkerUtils.defaultExitHandler;
+ this.workerOptions.poolOptions.errorHandler = (
+ this.workerOptions?.poolOptions?.errorHandler ?? WorkerUtils.defaultErrorHandler
+ ).bind(this) as ErrorHandler<Worker>;
+ this.workerOptions.poolOptions.exitHandler = (
+ this.workerOptions?.poolOptions?.exitHandler ?? WorkerUtils.defaultExitHandler
+ ).bind(this) as ExitHandler<Worker>;
+ this.workerOptions.poolOptions.messageHandler.bind(this);
this.pool = new FixedThreadPool(
this.workerOptions.poolMaxSize,
this.workerScript,
/**
*
- * @param elementData
+ * @param elementData -
* @returns
* @public
*/