From e4d3fd00e638370436ed6cdd31a9e6680acdde99 Mon Sep 17 00:00:00 2001 From: HRS Date: Sun, 2 Aug 2026 23:10:40 +0200 Subject: [PATCH 1/5] Add stricter compiler options --- eslint.config.ts | 2 +- package-lock.json | 168 ++++++++++++++++++++++++++++++++++++++++++++-- package.json | 2 +- tsconfig.json | 9 ++- 4 files changed, 172 insertions(+), 9 deletions(-) diff --git a/eslint.config.ts b/eslint.config.ts index 64d32de..4c4040c 100644 --- a/eslint.config.ts +++ b/eslint.config.ts @@ -19,7 +19,7 @@ export default [ }, eslint.configs.recommended, ...tseslint.configs.recommended, - preferArrowFunctions.configs?.all ?? [], + preferArrowFunctions.configs.all, { languageOptions: { parserOptions: { diff --git a/package-lock.json b/package-lock.json index 7ec8560..f112181 100644 --- a/package-lock.json +++ b/package-lock.json @@ -53,7 +53,7 @@ "eslint": "^10.1.0", "eslint-config-prettier": "^10.1.8", "eslint-plugin-jsdoc": "^62.8.0", - "eslint-plugin-prefer-arrow-functions": "^3.9.1", + "eslint-plugin-prefer-arrow-functions": "^3.10.1", "globals": "^17.0.0", "jiti": "^2.6.1", "nodemon": "^3.0.2", @@ -5127,18 +5127,174 @@ } }, "node_modules/eslint-plugin-prefer-arrow-functions": { - "version": "3.9.1", + "version": "3.10.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-prefer-arrow-functions/-/eslint-plugin-prefer-arrow-functions-3.10.1.tgz", + "integrity": "sha512-wutwnNG0S/wqNhqryS7ee2yX01dkvgFMDvdaXcdEfSGcxz37FRfJUCD0YL2Jur0ANCKocgplF7n6GBPhe+DNNg==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "^8.19.1", - "@typescript-eslint/utils": "^8.19.1" + "@typescript-eslint/types": "^8.62.1", + "@typescript-eslint/utils": "^8.62.1" }, "engines": { - "node": ">=18.0.0" + "node": "^20.19.0 || ^22.13.0 || >=24.0.0" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0" + } + }, + "node_modules/eslint-plugin-prefer-arrow-functions/node_modules/@typescript-eslint/project-service": { + "version": "8.65.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/project-service/-/project-service-8.65.0.tgz", + "integrity": "sha512-SxnPhbTsGahizDgbu7oqFH/xVtzIqMd/s+WtnSxNxJZJpLbdT5IPdzg8EZxO3+PoKahXmwJLeNQOpKJb3/bi7Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/tsconfig-utils": "^8.65.0", + "@typescript-eslint/types": "^8.65.0", + "debug": "^4.4.3" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "typescript": ">=4.8.4 <6.1.0" + } + }, + "node_modules/eslint-plugin-prefer-arrow-functions/node_modules/@typescript-eslint/scope-manager": { + "version": "8.65.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.65.0.tgz", + "integrity": "sha512-Esbl8OSYiVxBokYgWPf7VVWg/BE798wXhimnn9ML9Pt5qoDf8bfQlgjlKXR/k98+AcNzlLKYrpCcrcuZ9DZLgg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/types": "8.65.0", + "@typescript-eslint/visitor-keys": "8.65.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/eslint-plugin-prefer-arrow-functions/node_modules/@typescript-eslint/tsconfig-utils": { + "version": "8.65.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/tsconfig-utils/-/tsconfig-utils-8.65.0.tgz", + "integrity": "sha512-j6GzGqCiRdA7Qhur2VVmKZAkBLfnHFQfx4TaJGL9RMveZqCo48jSHHO0DTgizEnGhtWnqmbtCUSrqSkdiY/0Hg==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "typescript": ">=4.8.4 <6.1.0" + } + }, + "node_modules/eslint-plugin-prefer-arrow-functions/node_modules/@typescript-eslint/types": { + "version": "8.65.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.65.0.tgz", + "integrity": "sha512-JSSwWNy+H0E/01jJEM+hrX6N0OFDzFzeIhHFSAS01tlVaevpG8cFyYRPhS5yjGOvBUx3sqQHVMjCL1CAZZMxBg==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/eslint-plugin-prefer-arrow-functions/node_modules/@typescript-eslint/typescript-estree": { + "version": "8.65.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.65.0.tgz", + "integrity": "sha512-JboAE2swaYt4tb1fHhHTABE2K+OLy09XfcTbhnk4Pw96f9dd2e9iYsJ28gBggHlo5z5x1rkyWvcPoTuNTd4oGg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/project-service": "8.65.0", + "@typescript-eslint/tsconfig-utils": "8.65.0", + "@typescript-eslint/types": "8.65.0", + "@typescript-eslint/visitor-keys": "8.65.0", + "debug": "^4.4.3", + "minimatch": "^10.2.2", + "semver": "^7.7.3", + "tinyglobby": "^0.2.15", + "ts-api-utils": "^2.5.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { - "eslint": ">=9.17.0" + "typescript": ">=4.8.4 <6.1.0" + } + }, + "node_modules/eslint-plugin-prefer-arrow-functions/node_modules/@typescript-eslint/utils": { + "version": "8.65.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.65.0.tgz", + "integrity": "sha512-gXiwIHsYreboxeJucHKPvgwl7dXt50mF8s1/c00cP/WoVTyWKFdtfhRWwZiXYFU5H2O8vVoSLNrexFZjYS/SGA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@eslint-community/eslint-utils": "^4.9.1", + "@typescript-eslint/scope-manager": "8.65.0", + "@typescript-eslint/types": "8.65.0", + "@typescript-eslint/typescript-estree": "8.65.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0", + "typescript": ">=4.8.4 <6.1.0" + } + }, + "node_modules/eslint-plugin-prefer-arrow-functions/node_modules/@typescript-eslint/visitor-keys": { + "version": "8.65.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.65.0.tgz", + "integrity": "sha512-8C71BQkGjiMmXtop7pHVJu1l2NNShFdkCyD6a2ezzs5vU/L3LRtb69EtcteFwz0mYMPzIgOw0n6OV4VBUWZd7A==", + "dev": true, + "license": "MIT", + "dependencies": { + "@typescript-eslint/types": "8.65.0", + "eslint-visitor-keys": "^5.0.0" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/eslint-plugin-prefer-arrow-functions/node_modules/semver": { + "version": "7.8.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.5.tgz", + "integrity": "sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" } }, "node_modules/eslint-scope": { diff --git a/package.json b/package.json index 427441f..c062518 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "eslint": "^10.1.0", "eslint-config-prettier": "^10.1.8", "eslint-plugin-jsdoc": "^62.8.0", - "eslint-plugin-prefer-arrow-functions": "^3.9.1", + "eslint-plugin-prefer-arrow-functions": "^3.10.1", "globals": "^17.0.0", "jiti": "^2.6.1", "nodemon": "^3.0.2", diff --git a/tsconfig.json b/tsconfig.json index 3e6bd4b..72ffcc4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,13 +3,20 @@ "module": "NodeNext", "moduleResolution": "NodeNext", "target": "ES2022", - "noImplicitAny": true, "noImplicitOverride": true, "allowSyntheticDefaultImports": true, "sourceMap": true, "experimentalDecorators": true, "forceConsistentCasingInFileNames": true, "strict": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "strictBindCallApply": true, + "strictPropertyInitialization": true, + "noImplicitAny": true, + "noImplicitThis": true, + "alwaysStrict": true, + "useUnknownInCatchVariables": true, "resolveJsonModule": true, "esModuleInterop": true, "types": [ From 5783d5086b845c70c256e6181e72c02ba5578766 Mon Sep 17 00:00:00 2001 From: HRS Date: Sun, 2 Aug 2026 23:18:43 +0200 Subject: [PATCH 2/5] Stricter linting rules --- eslint.config.ts | 3 ++- src/app.ts | 6 +++++- src/automation/scriptRuntime.ts | 8 ++++---- src/automation/scriptVm.ts | 4 ++-- src/automation/scriptVmFactory.ts | 4 ++-- .../automation/createScriptController.ts | 2 +- .../automation/deleteScriptController.ts | 2 +- src/controller/automation/getScriptController.ts | 5 ++++- src/device/attribute/listDeviceAttribute.ts | 2 +- src/device/bleDevice.ts | 2 +- src/device/detectedDeviceOfferQueue.ts | 2 +- src/device/device.ts | 6 +++--- src/device/deviceManager.ts | 16 ++++++++-------- src/device/genericDeviceUpdater.ts | 2 +- src/device/protocol/airotic/airoticDevice.ts | 8 ++++---- .../buttplugIoWebsocketDeviceProviderFactory.ts | 2 +- src/device/protocol/deviceProtocol.ts | 2 +- src/device/protocol/estim2b/estim2bDevice.ts | 2 +- src/device/protocol/estim2b/estim2bProtocol.ts | 4 ++-- src/device/protocol/messageResponseHandler.ts | 8 ++++---- .../protocol/slvCtrlPlus/slvCtrlProtocol.ts | 16 +++++++--------- .../slvCtrlPlus/slvCtrlProtocolLegacy.ts | 6 +++--- .../virtual/audio/piperVirtualDeviceLogic.ts | 6 +++--- .../virtual/audio/ttsVirtualDeviceLogic.ts | 2 +- .../virtual/display/displayVirtualDeviceLogic.ts | 2 +- .../virtual/genericVirtualDeviceFactory.ts | 6 +++--- .../randomGeneratorVirtualDeviceLogic.ts | 2 +- src/device/protocol/zc95/zc95Device.ts | 12 ++++-------- src/device/protocol/zc95/zc95MessageFactory.ts | 4 ++-- .../protocol/zc95/zc95SerialDeviceProvider.ts | 2 +- src/device/provider/deviceProvider.ts | 4 ++-- src/device/provider/deviceProviderManager.ts | 6 +++--- src/device/serializedTypes.ts | 4 ++-- src/device/transport/bleDeviceTransport.ts | 4 ++-- src/device/transport/serialPortObserver.ts | 6 +++--- src/health/serializedTypes.ts | 4 ++-- src/logging/Logger.ts | 6 +++--- src/serviceMap.ts | 2 +- src/settings/deviceSource.ts | 2 +- src/settings/knownDevice.ts | 2 +- src/settings/serializedTypes.ts | 6 +++--- src/settings/settingsManager.ts | 2 +- src/socket/types.ts | 2 +- src/types.d.ts | 2 +- src/util/async.ts | 4 ++-- src/util/devNullStream.ts | 2 +- 46 files changed, 104 insertions(+), 102 deletions(-) diff --git a/eslint.config.ts b/eslint.config.ts index 4c4040c..5ffdde7 100644 --- a/eslint.config.ts +++ b/eslint.config.ts @@ -18,7 +18,8 @@ export default [ ], }, eslint.configs.recommended, - ...tseslint.configs.recommended, + ...tseslint.configs.strict, + ...tseslint.configs.stylistic, preferArrowFunctions.configs.all, { languageOptions: { diff --git a/src/app.ts b/src/app.ts index 809509a..a1c5944 100644 --- a/src/app.ts +++ b/src/app.ts @@ -34,7 +34,11 @@ import fs from 'fs' import BaseError from 'modern-errors'; import { Server } from 'socket.io'; -export type SslConfig = { port: number, keyFile: string, certFile: string }; +export interface SslConfig { + port: number; + keyFile: string; + certFile: string; +}; export interface AppOptions { allowedOrigins: string[]; diff --git a/src/automation/scriptRuntime.ts b/src/automation/scriptRuntime.ts index 2dc01fc..5293ac9 100644 --- a/src/automation/scriptRuntime.ts +++ b/src/automation/scriptRuntime.ts @@ -12,10 +12,10 @@ export type SupportedDeviceEvent = | { type: DeviceManagerEvent.deviceConnected | DeviceManagerEvent.deviceDisconnected | DeviceManagerEvent.deviceRefreshed; device: AnyDevice; args: [] } | { type: DeviceManagerEvent.deviceNotification; device: AnyDevice; args: [notification: DeviceNotification] }; -type ScriptRuntimeEvents = { - [AutomationEventType.consoleLog]: (data: string) => void, - [AutomationEventType.scriptStarted]: () => void, - [AutomationEventType.scriptStopped]: () => void, +interface ScriptRuntimeEvents { + [AutomationEventType.consoleLog]: (data: string) => void; + [AutomationEventType.scriptStarted]: () => void; + [AutomationEventType.scriptStopped]: () => void; } const AUTOMATION_LOG_FILENAME = 'automation.log'; diff --git a/src/automation/scriptVm.ts b/src/automation/scriptVm.ts index 8f56154..50c8562 100644 --- a/src/automation/scriptVm.ts +++ b/src/automation/scriptVm.ts @@ -1,10 +1,10 @@ import ivm from 'isolated-vm'; import { EventEmitter } from 'events'; -export type ScriptVmSignalEvents = { +export interface ScriptVmSignalEvents { eventDone: [errMsg: string | null]; lifecycleDone: [errMsg: string | null]; -}; +} export const LIFECYCLE_START = 'start'; export const LIFECYCLE_STOP = 'stop'; diff --git a/src/automation/scriptVmFactory.ts b/src/automation/scriptVmFactory.ts index 26d7881..c2b1840 100644 --- a/src/automation/scriptVmFactory.ts +++ b/src/automation/scriptVmFactory.ts @@ -7,10 +7,10 @@ import { AnyDevice } from '../device/device.js'; import Logger from '../logging/Logger.js'; import ScriptVm, { LIFECYCLE_START, ScriptVmSignalEvents } from './scriptVm.js'; -export type BridgeDevice = { +export interface BridgeDevice { id: string; name: string; -}; +} export const toBridgeDevice = (device: AnyDevice): BridgeDevice => { return { id: device.getDeviceId, name: device.getDeviceName }; diff --git a/src/controller/automation/createScriptController.ts b/src/controller/automation/createScriptController.ts index 6bace25..8c9ef26 100644 --- a/src/controller/automation/createScriptController.ts +++ b/src/controller/automation/createScriptController.ts @@ -3,7 +3,7 @@ import ControllerInterface from '../controllerInterface.js'; import AutomationScriptRepositoryInterface from '../../repository/automationScriptRepositoryInterface.js'; import { isValidAutomationScriptFileName } from '../../automation/utils.js'; -type RequestParams = { fileName: string }; +interface RequestParams { fileName: string } type RequestBody = string; type CreateScriptRequest = Request; diff --git a/src/controller/automation/deleteScriptController.ts b/src/controller/automation/deleteScriptController.ts index 1808b59..111a87b 100644 --- a/src/controller/automation/deleteScriptController.ts +++ b/src/controller/automation/deleteScriptController.ts @@ -3,7 +3,7 @@ import ControllerInterface from '../controllerInterface.js'; import AutomationScriptRepositoryInterface from '../../repository/automationScriptRepositoryInterface.js'; import { isValidAutomationScriptFileName } from '../../automation/utils.js'; -type RequestParams = { fileName: string }; +interface RequestParams { fileName: string } type DeleteScriptRequest = Request; export default class DeleteScriptController implements ControllerInterface diff --git a/src/controller/automation/getScriptController.ts b/src/controller/automation/getScriptController.ts index 9d728b6..3fee9ff 100644 --- a/src/controller/automation/getScriptController.ts +++ b/src/controller/automation/getScriptController.ts @@ -3,7 +3,10 @@ import ControllerInterface from '../controllerInterface.js'; import AutomationScriptRepositoryInterface from '../../repository/automationScriptRepositoryInterface.js'; import { isValidAutomationScriptFileName } from '../../automation/utils.js'; -type RequestParams = { fileName: string }; +interface RequestParams { + fileName: string; +} + type GetScriptRequest = Request; export default class GetScriptController implements ControllerInterface diff --git a/src/device/attribute/listDeviceAttribute.ts b/src/device/attribute/listDeviceAttribute.ts index 6374757..2da6fc9 100644 --- a/src/device/attribute/listDeviceAttribute.ts +++ b/src/device/attribute/listDeviceAttribute.ts @@ -8,7 +8,7 @@ export type InitializedListDeviceAttribute< IValue extends ListDeviceAttributeItem > = ListDeviceAttribute; -export type ListDeviceAttributeOption = { key: IKey, value: IValue }; +export interface ListDeviceAttributeOption { key: IKey, value: IValue } export type ListDeviceAttributeOptions = ListDeviceAttributeOption[]; export default class ListDeviceAttribute< diff --git a/src/device/bleDevice.ts b/src/device/bleDevice.ts index 84ebfc1..41e7df8 100644 --- a/src/device/bleDevice.ts +++ b/src/device/bleDevice.ts @@ -21,7 +21,7 @@ export default abstract class BleDevice< private readonly rssiInterval: NodeJS.Timeout; private readonly reconnectHandler: () => void; - private closing: boolean = false; + private closing = false; @Expose() private rssi: number; diff --git a/src/device/detectedDeviceOfferQueue.ts b/src/device/detectedDeviceOfferQueue.ts index 9f73eb3..13677ef 100644 --- a/src/device/detectedDeviceOfferQueue.ts +++ b/src/device/detectedDeviceOfferQueue.ts @@ -14,7 +14,7 @@ type DeviceOffer = (cancellationToken: CancellationToken) = export default class DetectedDeviceOfferQueue { - private readonly queues: Map = new Map(); + private readonly queues = new Map(); private readonly logger: Logger; diff --git a/src/device/device.ts b/src/device/device.ts index 4259df0..9f25b27 100644 --- a/src/device/device.ts +++ b/src/device/device.ts @@ -27,7 +27,7 @@ export type DeviceData = { [K in AttributeKeyOf]: AttributeValueOf; }; -export type DeviceError = { +export interface DeviceError { reason: string; occurredAt: Date; } @@ -41,10 +41,10 @@ export enum DeviceEvent { export type DeviceNotification = { [K in keyof TNotifications & string]: { type: K; data: TNotifications[K] } }[keyof TNotifications & string]; -export type DeviceEventMap< +export interface DeviceEventMap< TDevice extends Device = Device, TNotifications extends DeviceNotifications = AnyDeviceNotifications -> = { +> { [DeviceEvent.deviceRefreshed]: [device: TDevice]; [DeviceEvent.deviceDisconnected]: [device: TDevice]; [DeviceEvent.deviceNotification]: [device: TDevice, notification: DeviceNotification]; diff --git a/src/device/deviceManager.ts b/src/device/deviceManager.ts index ffeab52..361ff8b 100644 --- a/src/device/deviceManager.ts +++ b/src/device/deviceManager.ts @@ -10,10 +10,10 @@ import SettingsManager from '../settings/settingsManager.js'; import DeviceOfferRejectedError from './deviceOfferRejectedError.js'; import DetectedDeviceOfferQueue, { OfferResult } from './detectedDeviceOfferQueue.js'; -export type DeviceDetectionInfo = { +export interface DeviceDetectionInfo { type: string; detectionId: DetectionId; -}; +} export enum DeviceManagerEvent { deviceConnected = 'deviceConnected', @@ -23,13 +23,13 @@ export enum DeviceManagerEvent { deviceNotification = 'deviceNotification', } -type DisabledDetectedDevice = { +interface DisabledDetectedDevice { deviceDetectionInfo: DeviceDetectionInfo; canonicalId: DeviceId; deviceReleased: Promise; -}; +} -type DeviceManagerEventMap = { +interface DeviceManagerEventMap { [DeviceManagerEvent.deviceConnected]: [device: AnyDevice]; [DeviceManagerEvent.deviceDisconnected]: [device: AnyDevice]; [DeviceManagerEvent.deviceRefreshed]: [device: AnyDevice]; @@ -37,7 +37,7 @@ type DeviceManagerEventMap = { [DeviceManagerEvent.deviceNotification]: [device: AnyDevice, notification: DeviceNotification]; } -type ConnectedDevice = { device: AnyDevice, deviceDetectionInfo: DeviceDetectionInfo }; +interface ConnectedDevice { device: AnyDevice, deviceDetectionInfo: DeviceDetectionInfo } export default class DeviceManager { @@ -49,9 +49,9 @@ export default class DeviceManager private readonly settingsManager: SettingsManager; - private readonly detectedDisabledDevices: Map = new Map(); + private readonly detectedDisabledDevices = new Map(); - private readonly connectedDevices: Map = new Map(); + private readonly connectedDevices = new Map(); // Serializes onSettingsChanged() runs so rapid settings changes don't interleave private readonly settingsChangeQueue: SequentialTaskQueue = new SequentialTaskQueue(); diff --git a/src/device/genericDeviceUpdater.ts b/src/device/genericDeviceUpdater.ts index e8acec9..9a11c99 100644 --- a/src/device/genericDeviceUpdater.ts +++ b/src/device/genericDeviceUpdater.ts @@ -9,7 +9,7 @@ export default class GenericDeviceUpdater extends AbstractDeviceUpdater { private logger: Logger; - private readonly failedMessageCountPerDevice: Map = new Map(); + private readonly failedMessageCountPerDevice = new Map(); public constructor(serializer: PlainToClassSerializer, logger: Logger) { super(serializer); diff --git a/src/device/protocol/airotic/airoticDevice.ts b/src/device/protocol/airotic/airoticDevice.ts index 7c18293..7272f1c 100644 --- a/src/device/protocol/airotic/airoticDevice.ts +++ b/src/device/protocol/airotic/airoticDevice.ts @@ -25,20 +25,20 @@ const DEFAULT_BREATH_IN_COLOR = '255,0,128'; export type BpmTrend = 'up' | 'down' | 'stable'; -export type AiroticDeviceAttributes = { +export interface AiroticDeviceAttributes { restColor: StrDeviceAttribute, breathInColor: StrDeviceAttribute, resetColors: BoolDeviceAttribute, reboot: BoolDeviceAttribute, breathsPerMin: FloatDeviceAttribute, bpmTrend: StrDeviceAttribute, -}; +} -export type AiroticDeviceNotifications = { +export interface AiroticDeviceNotifications { colorChange: { colorType: 'breathInColor' | 'restColor'; }; -}; +} @Exclude() export default class AiroticDevice extends BleDevice diff --git a/src/device/protocol/buttplugIo/buttplugIoWebsocketDeviceProviderFactory.ts b/src/device/protocol/buttplugIo/buttplugIoWebsocketDeviceProviderFactory.ts index 0a0b36e..92c3c85 100644 --- a/src/device/protocol/buttplugIo/buttplugIoWebsocketDeviceProviderFactory.ts +++ b/src/device/protocol/buttplugIo/buttplugIoWebsocketDeviceProviderFactory.ts @@ -4,7 +4,7 @@ import ButtplugIoDeviceFactory from './buttplugIoDeviceFactory.js'; import ButtplugIoWebsocketDeviceProvider from './buttplugIoWebsocketDeviceProvider.js'; import DeviceManager from '../../deviceManager.js'; -type ButtplugIoWebsocketDeviceProviderConfig = { +interface ButtplugIoWebsocketDeviceProviderConfig { address: string, autoScan: boolean, useDeviceNameAsId: boolean diff --git a/src/device/protocol/deviceProtocol.ts b/src/device/protocol/deviceProtocol.ts index 2dcad02..51008ed 100644 --- a/src/device/protocol/deviceProtocol.ts +++ b/src/device/protocol/deviceProtocol.ts @@ -7,7 +7,7 @@ export type DecodeResult = | { message: TMessage } | { error: ProtocolError }; -export type Message = { +export interface Message { message: T; } diff --git a/src/device/protocol/estim2b/estim2bDevice.ts b/src/device/protocol/estim2b/estim2bDevice.ts index e089085..417f243 100644 --- a/src/device/protocol/estim2b/estim2bDevice.ts +++ b/src/device/protocol/estim2b/estim2bDevice.ts @@ -14,7 +14,7 @@ import EventEmitter from 'events'; import Logger from '../../../logging/Logger.js'; import { DeviceId } from '../../deviceId.js'; -export type EStim2bDeviceAttributes = { +export interface EStim2bDeviceAttributes { mode: ListDeviceAttribute, channelALevel: IntRangeDeviceAttribute, channelBLevel: IntRangeDeviceAttribute, diff --git a/src/device/protocol/estim2b/estim2bProtocol.ts b/src/device/protocol/estim2b/estim2bProtocol.ts index 58147af..f52d295 100644 --- a/src/device/protocol/estim2b/estim2bProtocol.ts +++ b/src/device/protocol/estim2b/estim2bProtocol.ts @@ -1,6 +1,6 @@ import DeviceProtocol, { DecodeResult, InferMessage, MessageWithResponse } from '../deviceProtocol.js'; -export type EStim2bStatus = { +export interface EStim2bStatus { batteryLevel: number, channelALevel: number, channelBLevel: number, @@ -10,7 +10,7 @@ export type EStim2bStatus = { powerMode: string, channelsJoined: boolean, firmwareVersion: string, -}; +} export type EStim2Channel = 'A' | 'B'; export type EStim2PowerMode = 'H' | 'L'; diff --git a/src/device/protocol/messageResponseHandler.ts b/src/device/protocol/messageResponseHandler.ts index 598acbc..c42e435 100644 --- a/src/device/protocol/messageResponseHandler.ts +++ b/src/device/protocol/messageResponseHandler.ts @@ -4,28 +4,28 @@ import { clearTimeout } from 'node:timers'; import Logger from '../../logging/Logger.js'; import { promiseWithTimeout } from '../../util/async.js'; -type PendingEntry = { +interface PendingEntry { msg: MR; resolve: (response: InferResponse) => void; reject: (error: Error) => void; timeout: ReturnType; timeoutMs: number, pendingSince: number, -}; +} export default class MessageResponseHandler

>> { private readonly protocol: P; private readonly transport: DeviceBidirectionalTransport; private readonly logger: Logger; - private readonly pendingEntries: Set>> = new Set(); + private readonly pendingEntries = new Set>>(); private readonly timeoutMs: number; public static create

>>( protocol: P, transport: DeviceBidirectionalTransport, logger: Logger, - timeoutMs: number = 200, + timeoutMs = 200, ): MessageResponseHandler

{ return new this(protocol, transport, logger, timeoutMs); } diff --git a/src/device/protocol/slvCtrlPlus/slvCtrlProtocol.ts b/src/device/protocol/slvCtrlPlus/slvCtrlProtocol.ts index e6dc35f..3add5da 100644 --- a/src/device/protocol/slvCtrlPlus/slvCtrlProtocol.ts +++ b/src/device/protocol/slvCtrlPlus/slvCtrlProtocol.ts @@ -1,23 +1,21 @@ import { SlvCtrlPlusDeviceAttributes } from './slvCtrlPlusDevice.js'; import DeviceProtocol, { DecodeResult, InferMessage, InferResponse, MessageWithResponse } from '../deviceProtocol.js'; -export type DeviceInfo = { +export interface DeviceInfo { deviceType: string, fwVersion: number, protocolVersion: number, -}; -export type KeyValuePairs = { [key: string]: string }; +} +export type KeyValuePairs = Record; export type Result = { status: 'ok' | 'error' | 'unknown', reason?: string, -} & { - [key: string]: string, -} -export type SlvCtrlProtocolCommand = { +} & Record +export interface SlvCtrlProtocolCommand { command: string; args: (string|number|boolean)[]; -}; -export type SlvCtrlProtocolResponse = { +} +export interface SlvCtrlProtocolResponse { command: string, data: KeyValuePairs, result: Result, diff --git a/src/device/protocol/slvCtrlPlus/slvCtrlProtocolLegacy.ts b/src/device/protocol/slvCtrlPlus/slvCtrlProtocolLegacy.ts index a2c718a..9a39433 100644 --- a/src/device/protocol/slvCtrlPlus/slvCtrlProtocolLegacy.ts +++ b/src/device/protocol/slvCtrlPlus/slvCtrlProtocolLegacy.ts @@ -13,13 +13,13 @@ import SlvCtrlProtocol, { } from './slvCtrlProtocol.js'; import { DecodeResult, InferMessage, InferResponse } from '../deviceProtocol.js'; -type SetAttributeResponse = { +interface SetAttributeResponse { command: string, value: string, status: string, -}; +} -export type StatusResponse = { [key: string]: string }; +export type StatusResponse = Record; export default class SlvCtrlProtocolLegacy extends SlvCtrlProtocol { diff --git a/src/device/protocol/virtual/audio/piperVirtualDeviceLogic.ts b/src/device/protocol/virtual/audio/piperVirtualDeviceLogic.ts index fb74ba8..f12a130 100644 --- a/src/device/protocol/virtual/audio/piperVirtualDeviceLogic.ts +++ b/src/device/protocol/virtual/audio/piperVirtualDeviceLogic.ts @@ -13,13 +13,13 @@ import { PiperVirtualDeviceConfig } from './piperVirtualDeviceConfig.js'; import DevNullStream from '../../../../util/devNullStream.js'; import VirtualDeviceLogic from '../virtualDeviceLogic.js'; -type PiperVirtualDeviceAttributes = { +interface PiperVirtualDeviceAttributes { text: StrDeviceAttribute; queuing: BoolDeviceAttribute; } -type PiperModelMetadata = { +interface PiperModelMetadata { num_speakers?: number, sample_width?: number, audio?: { @@ -40,7 +40,7 @@ export default class PiperVirtualDeviceLogic extends VirtualDeviceLogic< private piperProcess?: ChildProcessByStdio; private speaker?: Speaker; private speakerOptions: Speaker.Options = {}; - private speakerCoolDown: boolean = false; + private speakerCoolDown = false; public constructor(config: PiperVirtualDeviceConfig, logger: Logger) { super(config); diff --git a/src/device/protocol/virtual/audio/ttsVirtualDeviceLogic.ts b/src/device/protocol/virtual/audio/ttsVirtualDeviceLogic.ts index f2a7c17..c61a8f6 100644 --- a/src/device/protocol/virtual/audio/ttsVirtualDeviceLogic.ts +++ b/src/device/protocol/virtual/audio/ttsVirtualDeviceLogic.ts @@ -9,7 +9,7 @@ import { Int } from '../../../../util/numbers.js'; import Logger from '../../../../logging/Logger.js'; import { TtsVirtualDeviceConfig } from './ttsVirtualDeviceConfig.js'; -type TtsVirtualDeviceAttributes = { +interface TtsVirtualDeviceAttributes { text: StrDeviceAttribute; speaking: BoolDeviceAttribute; queuing: BoolDeviceAttribute; diff --git a/src/device/protocol/virtual/display/displayVirtualDeviceLogic.ts b/src/device/protocol/virtual/display/displayVirtualDeviceLogic.ts index 8b5de8b..2cc8839 100644 --- a/src/device/protocol/virtual/display/displayVirtualDeviceLogic.ts +++ b/src/device/protocol/virtual/display/displayVirtualDeviceLogic.ts @@ -3,7 +3,7 @@ import StrDeviceAttribute from '../../../attribute/strDeviceAttribute.js'; import VirtualDeviceLogic from '../virtualDeviceLogic.js'; import { NoDeviceConfig } from '../../../deviceConfig.js'; -type DisplayVirtualDeviceAttributes = { +interface DisplayVirtualDeviceAttributes { content: StrDeviceAttribute; } diff --git a/src/device/protocol/virtual/genericVirtualDeviceFactory.ts b/src/device/protocol/virtual/genericVirtualDeviceFactory.ts index bf95e56..f0add9a 100644 --- a/src/device/protocol/virtual/genericVirtualDeviceFactory.ts +++ b/src/device/protocol/virtual/genericVirtualDeviceFactory.ts @@ -11,7 +11,7 @@ import EventEmitterFactory from '../../../factory/eventEmitterFactory.js'; type ExtractConfig> = T extends VirtualDeviceLogic ? C : never; -type LogicFactoryAndConfigTuple, TConfigSchema extends TObject> = { +interface LogicFactoryAndConfigTuple, TConfigSchema extends TObject> { deviceLogicFactory: VirtualDeviceLogicFactory, deviceConfigSchema: TConfigSchema & ( Static extends ExtractConfig @@ -20,7 +20,7 @@ type LogicFactoryAndConfigTuple, TConfigS : never : never ), -}; +} export default class GenericVirtualDeviceFactory implements VirtualDeviceFactory { private readonly dateFactory: DateFactory; @@ -29,7 +29,7 @@ export default class GenericVirtualDeviceFactory implements VirtualDeviceFactory private readonly jsonSchemaValidatorFactory: JsonSchemaValidatorFactory; - private readonly logicFactories: Map, TObject>> = new Map(); + private readonly logicFactories = new Map, TObject>>(); private readonly logger: Logger; diff --git a/src/device/protocol/virtual/randomGenerator/randomGeneratorVirtualDeviceLogic.ts b/src/device/protocol/virtual/randomGenerator/randomGeneratorVirtualDeviceLogic.ts index 55578cf..cccfb6e 100644 --- a/src/device/protocol/virtual/randomGenerator/randomGeneratorVirtualDeviceLogic.ts +++ b/src/device/protocol/virtual/randomGenerator/randomGeneratorVirtualDeviceLogic.ts @@ -5,7 +5,7 @@ import VirtualDevice from '../virtualDevice.js'; import { Int } from '../../../../util/numbers.js'; import { RandomGeneratorVirtualDeviceConfig } from './randomGeneratorVirtualDeviceConfig.js'; -type RandomGeneratorVirtualDeviceAttributes = { +interface RandomGeneratorVirtualDeviceAttributes { value: IntDeviceAttribute; } diff --git a/src/device/protocol/zc95/zc95Device.ts b/src/device/protocol/zc95/zc95Device.ts index 5124722..89612a7 100644 --- a/src/device/protocol/zc95/zc95Device.ts +++ b/src/device/protocol/zc95/zc95Device.ts @@ -25,24 +25,20 @@ import Logger from '../../../logging/Logger.js'; import EventEmitter from 'events'; import { DeviceId } from '../../deviceId.js'; -type RequiredZc95DeviceAttributes = { +interface RequiredZc95DeviceAttributes { activePattern: InitializedListDeviceAttribute; patternStarted: InitializedBoolDeviceAttribute; -}; +} type Zc95DevicePowerChannelAttributesKeyPrefix = `powerChannel`; type Zc95DevicePowerChannelAttributesKey = `${Zc95DevicePowerChannelAttributesKeyPrefix}${1 | 2 | 3 | 4}`; -type Zc95DevicePowerChannelAttributes = { - [K in Zc95DevicePowerChannelAttributesKey]: IntRangeDeviceAttribute; -} +type Zc95DevicePowerChannelAttributes = Record type Zc95DevicePatternAttributesKeyPrefix = `patternAttribute`; type Zc95DevicePatternAttributesKey = `${Zc95DevicePatternAttributesKeyPrefix}${number}`; -type Zc95DevicePatternAttributes = { - [key in Zc95DevicePatternAttributesKey]: InitializedIntRangeDeviceAttribute | ListDeviceAttribute; -} +type Zc95DevicePatternAttributes = Record> export type Zc95DeviceAttributes = Partial & Zc95DevicePatternAttributes> & Required; diff --git a/src/device/protocol/zc95/zc95MessageFactory.ts b/src/device/protocol/zc95/zc95MessageFactory.ts index fb74047..0d305fa 100644 --- a/src/device/protocol/zc95/zc95MessageFactory.ts +++ b/src/device/protocol/zc95/zc95MessageFactory.ts @@ -155,7 +155,7 @@ export interface PatternDetailsMsgResponse extends MsgResponse MenuItems: (MinMaxMenuItem | MultiChoiceMenuItem)[]; } -type LuaScriptInfo = { +interface LuaScriptInfo { Index: number; Empty: boolean; Valid: boolean; @@ -169,7 +169,7 @@ export interface GetLuaScriptsMsgResponse extends MsgResponse export default class Zc95MessageFactory { - private msgId: number = 0; + private msgId = 0; public createGetPatterns(): MsgAndResponseIdentifier { const msgId = this.getNextMsgIndex(); diff --git a/src/device/protocol/zc95/zc95SerialDeviceProvider.ts b/src/device/protocol/zc95/zc95SerialDeviceProvider.ts index f340a40..e290fea 100644 --- a/src/device/protocol/zc95/zc95SerialDeviceProvider.ts +++ b/src/device/protocol/zc95/zc95SerialDeviceProvider.ts @@ -76,7 +76,7 @@ export default class Zc95SerialDeviceProvider extends SerialDeviceProvider, close: boolean = false): Promise { + private async reset(port: SerialPortStream, close = false): Promise { return new Promise((resolve, reject) => { port.write(Buffer.from([Zc95Protocol.EOT]), (writeErr: Error | null | undefined) => { if (null != writeErr) { diff --git a/src/device/provider/deviceProvider.ts b/src/device/provider/deviceProvider.ts index 94bb51b..dfed7c6 100644 --- a/src/device/provider/deviceProvider.ts +++ b/src/device/provider/deviceProvider.ts @@ -15,11 +15,11 @@ export default abstract class DeviceProvider = new Map(); + private readonly connectedDevices = new Map(); private readonly deviceDetectedListener: (deviceDetectionInfo: DeviceDetectionInfo) => void; - private running: boolean = false; + private running = false; protected constructor(deviceManager: DeviceManager, logger: Logger) { this.deviceManager = deviceManager; diff --git a/src/device/provider/deviceProviderManager.ts b/src/device/provider/deviceProviderManager.ts index 0bd9197..42b92d9 100644 --- a/src/device/provider/deviceProviderManager.ts +++ b/src/device/provider/deviceProviderManager.ts @@ -6,10 +6,10 @@ import Logger from '../../logging/Logger.js'; import { AnyDeviceProvider } from './deviceProvider.js'; import { logError } from '../../util/error.js'; -type RunningProvider = { +interface RunningProvider { provider: AnyDeviceProvider; sourceFingerprint: string; -}; +} export default class DeviceProviderManager { @@ -17,7 +17,7 @@ export default class DeviceProviderManager private readonly logger: Logger; - private readonly providers: Map = new Map(); + private readonly providers = new Map(); // Settings can change in rapid succession, so overlapping loadFromSettings()/stopProviders() // calls are serialized to avoid racing on the shared providers map diff --git a/src/device/serializedTypes.ts b/src/device/serializedTypes.ts index d4eebdc..072db1f 100644 --- a/src/device/serializedTypes.ts +++ b/src/device/serializedTypes.ts @@ -2,7 +2,7 @@ import DeviceState from './deviceState.js'; import { DeviceAttributeModifier } from './attribute/deviceAttribute.js'; import { DeviceId } from './deviceId.js'; -type SerializedDeviceAttributeBase = { +interface SerializedDeviceAttributeBase { name: string; label: string | undefined; modifier: DeviceAttributeModifier; @@ -54,7 +54,7 @@ export type SerializedDeviceAttribute = | SerializedStrDeviceAttribute | SerializedListDeviceAttribute; -type SerializedDeviceBase = { +interface SerializedDeviceBase { connectedSince: Date; deviceId: DeviceId; deviceName: string; diff --git a/src/device/transport/bleDeviceTransport.ts b/src/device/transport/bleDeviceTransport.ts index 042c892..3aee963 100644 --- a/src/device/transport/bleDeviceTransport.ts +++ b/src/device/transport/bleDeviceTransport.ts @@ -11,8 +11,8 @@ export default class BleUartDeviceTransport implements DeviceBidirectionalTransp private readonly uartRxCharacteristicUuid: string; private readonly uartTxCharacteristicUuid: string; - private isConnected: boolean = false; - private isSubscribing: boolean = false; + private isConnected = false; + private isSubscribing = false; private onCloseSubscribers: (() => Promise)[] = []; private onReceiveSubscribers: ((data: Buffer) => void)[] = []; diff --git a/src/device/transport/serialPortObserver.ts b/src/device/transport/serialPortObserver.ts index 61aac3f..4e74d77 100644 --- a/src/device/transport/serialPortObserver.ts +++ b/src/device/transport/serialPortObserver.ts @@ -18,13 +18,13 @@ export default class SerialPortObserver extends SharedObserver { protected readonly deviceManager: DeviceManager; - private managedDevices: Map = new Map(); + private managedDevices = new Map(); private onUsbEventRef?: () => void; private rescanTimer?: NodeJS.Timeout; - private readonly discoveryQueue: LatestOnlyTaskQueue = new LatestOnlyTaskQueue(); + private readonly discoveryQueue = new LatestOnlyTaskQueue(); public constructor( deviceManager: DeviceManager, @@ -78,7 +78,7 @@ export default class SerialPortObserver extends SharedObserver public async discoverSerialDevices(cancellationToken?: CancellationToken): Promise { - const foundDevices: Map = new Map(); + const foundDevices = new Map(); let ports: PortInfo[]; try { diff --git a/src/health/serializedTypes.ts b/src/health/serializedTypes.ts index 45f3ed3..fdfa2cc 100644 --- a/src/health/serializedTypes.ts +++ b/src/health/serializedTypes.ts @@ -1,6 +1,6 @@ import { NetworkStats } from 'node-os-utils'; -export type SerializedHealthMetrics = { +export interface SerializedHealthMetrics { process: { memoryUsage: NodeJS.MemoryUsage, }, @@ -31,4 +31,4 @@ export type SerializedHealthMetrics = { hostname: string | null, uptime: number | null, }, -}; +} diff --git a/src/logging/Logger.ts b/src/logging/Logger.ts index ba529dc..c521f81 100644 --- a/src/logging/Logger.ts +++ b/src/logging/Logger.ts @@ -1,12 +1,12 @@ -export type ChildLoggerBindings = { +export interface ChildLoggerBindings { name?: string, } -export type ChildLoggerOptions = { +export interface ChildLoggerOptions { level?: string, } -export type ErrorContext = Error | ({ error: Error } & { [key: string]: unknown }); +export type ErrorContext = Error | ({ error: Error } & Record); export default interface Logger { diff --git a/src/serviceMap.ts b/src/serviceMap.ts index 993fcdf..cac2fde 100644 --- a/src/serviceMap.ts +++ b/src/serviceMap.ts @@ -54,7 +54,7 @@ import AiroticDeviceFactory from './device/protocol/airotic/airoticDeviceFactory import KnownDeviceRegistry from './device/knownDeviceRegistry.js'; -type ServiceMap = { +interface ServiceMap { /* serializerServiceProvider */ 'serializer.classToPlain': ClassToPlainSerializer, 'serializer.plainToClass': PlainToClassSerializer, diff --git a/src/settings/deviceSource.ts b/src/settings/deviceSource.ts index 3519a25..25b45f3 100644 --- a/src/settings/deviceSource.ts +++ b/src/settings/deviceSource.ts @@ -16,7 +16,7 @@ export default class DeviceSource @Expose({ name: 'enabled' }) private readonly _enabled: boolean; - public constructor(id: string, type: string, config: JsonObject, enabled: boolean = true) { + public constructor(id: string, type: string, config: JsonObject, enabled = true) { this._id = id; this._type = type; this._config = config; diff --git a/src/settings/knownDevice.ts b/src/settings/knownDevice.ts index 76f6582..73454c4 100644 --- a/src/settings/knownDevice.ts +++ b/src/settings/knownDevice.ts @@ -24,7 +24,7 @@ export default class KnownDevice private readonly _enabled: boolean; public constructor( - id: DeviceId, name: string, type: string, source: string, config: JsonObject = {}, enabled: boolean = true + id: DeviceId, name: string, type: string, source: string, config: JsonObject = {}, enabled = true ) { this._id = id; this._name = name; diff --git a/src/settings/serializedTypes.ts b/src/settings/serializedTypes.ts index 03262aa..257aff9 100644 --- a/src/settings/serializedTypes.ts +++ b/src/settings/serializedTypes.ts @@ -1,6 +1,6 @@ import { JsonObject } from '../types.js'; -export type SerializedKnownDevice = { +export interface SerializedKnownDevice { id: string; serialNo: string; name: string; @@ -10,14 +10,14 @@ export type SerializedKnownDevice = { enabled: boolean; } -export type SerializedDeviceSource = { +export interface SerializedDeviceSource { id: string; type: string; config: JsonObject; enabled: boolean; } -export type SerializedSettings = { +export interface SerializedSettings { knownDevices: Record; deviceSources: Record; } diff --git a/src/settings/settingsManager.ts b/src/settings/settingsManager.ts index 02cefc1..45e75eb 100644 --- a/src/settings/settingsManager.ts +++ b/src/settings/settingsManager.ts @@ -13,7 +13,7 @@ import { JsonObject } from '../types.js'; import { logError } from '../util/error.js'; -type SettingsEvents = { +interface SettingsEvents { [SettingsEventType.changed]: (settings: Settings) => void, } diff --git a/src/socket/types.ts b/src/socket/types.ts index 4b81dab..d7a65c8 100644 --- a/src/socket/types.ts +++ b/src/socket/types.ts @@ -8,7 +8,7 @@ import { SerializedDevice } from '../device/serializedTypes.js'; import { SerializedSettings } from '../settings/serializedTypes.js'; import { DeviceId } from '../device/deviceId.js'; -export type DeviceUpdateData = { deviceId: DeviceId, data: DeviceData } +export interface DeviceUpdateData { deviceId: DeviceId, data: DeviceData } export interface ClientToServerEvents { [WebSocketEvent.deviceUpdateReceived]: (data: DeviceUpdateData) => void; diff --git a/src/types.d.ts b/src/types.d.ts index 15fadf3..0f41c0d 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,4 +1,4 @@ -export type JsonObject = { [key: string]: JsonValue }; +export interface JsonObject { [key: string]: JsonValue } export type JsonValue = | null diff --git a/src/util/async.ts b/src/util/async.ts index f9985b7..0335ba8 100644 --- a/src/util/async.ts +++ b/src/util/async.ts @@ -16,7 +16,7 @@ export const setImmediateInterval = ( return setInterval(callback, delay, ...args); }; -export type IntervalAsyncOptions = { +export interface IntervalAsyncOptions { intervalMs: number; runImmediately?: boolean; timeoutMs?: number; @@ -32,7 +32,7 @@ export const asyncHandler = ( }; }; -export type IntervalAsync = { clear: () => void }; +export interface IntervalAsync { clear: () => void } export const setIntervalAsync = ( fn: (...args: TArgs) => Promise, diff --git a/src/util/devNullStream.ts b/src/util/devNullStream.ts index 07ab9d8..be9af42 100644 --- a/src/util/devNullStream.ts +++ b/src/util/devNullStream.ts @@ -4,7 +4,7 @@ export default class DevNullStream extends Writable { private readonly timeoutMs: number; private timer?: NodeJS.Timeout; - public constructor(timeoutMs: number = 500) { + public constructor(timeoutMs = 500) { super(); this.timeoutMs = timeoutMs; this.resetTimer(); From 6a49d70cab5a4e66aa754f28fa7c55e74441e4ef Mon Sep 17 00:00:00 2001 From: HRS Date: Mon, 3 Aug 2026 21:29:11 +0200 Subject: [PATCH 3/5] Enforce type over interface, fix lint/typecheck errors - Fix 10 ESLint errors surfaced by the stricter linting rules (non-null assertion, invalid void type, strict-boolean-expressions, class-literal-property-style, dynamic delete, extraneous static class) - Switch consistent-type-definitions to prefer type over interface, since interfaces don't get an implicit index signature the way type aliases do, which was causing real type errors (and, more importantly, was silently defeating attribute key/value type checking in getAttribute/setAttribute across the whole device hierarchy - K extended plain string instead of AttributeKeyOf) - Remove now-unnecessary explicit index signatures and extends workarounds that were needed while interface was still enforced --- eslint.config.ts | 16 +++ src/app.ts | 10 +- src/automation/scriptRuntime.ts | 9 +- src/automation/scriptVm.ts | 2 +- src/automation/scriptVmFactory.ts | 2 +- .../automation/createScriptController.ts | 5 +- .../automation/deleteScriptController.ts | 3 +- .../automation/getScriptController.ts | 2 +- src/controller/controllerInterface.ts | 4 +- src/device/attribute/listDeviceAttribute.ts | 2 +- src/device/device.ts | 6 +- src/device/deviceManager.ts | 8 +- src/device/protocol/airotic/airoticDevice.ts | 20 +-- ...uttplugIoWebsocketDeviceProviderFactory.ts | 2 +- src/device/protocol/deviceProtocol.ts | 8 +- src/device/protocol/estim2b/estim2bDevice.ts | 3 +- .../protocol/estim2b/estim2bProtocol.ts | 2 +- src/device/protocol/messageResponseHandler.ts | 2 +- .../protocol/slvCtrlPlus/slvCtrlProtocol.ts | 6 +- .../slvCtrlPlus/slvCtrlProtocolLegacy.ts | 2 +- .../virtual/audio/piperVirtualDeviceLogic.ts | 10 +- .../virtual/audio/ttsVirtualDeviceLogic.ts | 7 +- .../display/displayVirtualDeviceLogic.ts | 6 +- .../virtual/genericVirtualDeviceFactory.ts | 2 +- .../randomGeneratorVirtualDeviceLogic.ts | 7 +- .../protocol/virtual/virtualDeviceFactory.ts | 3 +- .../virtual/virtualDeviceLogicFactory.ts | 4 +- src/device/protocol/zc95/zc95Device.ts | 4 +- .../protocol/zc95/zc95MessageFactory.ts | 120 +++++++----------- src/device/protocol/zc95/zc95Protocol.ts | 13 +- src/device/provider/deviceProviderFactory.ts | 4 +- src/device/provider/deviceProviderManager.ts | 2 +- src/device/serializedTypes.ts | 4 +- .../transport/deviceBidirectionalTransport.ts | 6 +- .../transport/deviceReadableTransport.ts | 4 +- .../transport/deviceWritableTransport.ts | 4 +- src/device/updater/deviceUpdaterInterface.ts | 4 +- src/health/serializedTypes.ts | 2 +- src/logging/Logger.ts | 8 +- .../automationScriptRepositoryInterface.ts | 4 +- src/repository/deviceRepositoryInterface.ts | 4 +- src/serial/frameParser.ts | 5 +- src/serviceMap.ts | 2 +- src/settings/serializedTypes.ts | 6 +- src/settings/settingsManager.ts | 2 +- src/socket/types.ts | 6 +- src/types.d.ts | 2 +- src/util/async.ts | 4 +- 48 files changed, 179 insertions(+), 184 deletions(-) diff --git a/eslint.config.ts b/eslint.config.ts index 5ffdde7..044c61e 100644 --- a/eslint.config.ts +++ b/eslint.config.ts @@ -101,6 +101,22 @@ export default [ "@typescript-eslint/no-misused-promises": "error", "@typescript-eslint/no-misused-new": "error", "@typescript-eslint/no-namespace": "error", + "@typescript-eslint/no-extraneous-class": [ + "error", + { + "allowStaticOnly": true + } + ], + "@typescript-eslint/no-invalid-void-type": [ + "error", + { + "allowAsThisParameter": true + } + ], + "@typescript-eslint/consistent-type-definitions": [ + "error", + "type" + ], "@typescript-eslint/no-parameter-properties": "off", "@typescript-eslint/no-shadow": [ "error", diff --git a/src/app.ts b/src/app.ts index a1c5944..204164d 100644 --- a/src/app.ts +++ b/src/app.ts @@ -34,23 +34,23 @@ import fs from 'fs' import BaseError from 'modern-errors'; import { Server } from 'socket.io'; -export interface SslConfig { +export type SslConfig = { port: number; keyFile: string; certFile: string; -}; +} -export interface AppOptions { +export type AppOptions = { allowedOrigins: string[]; dataPath: string; } -export interface ServeResult { +export type ServeResult = { httpServer: http.Server; httpsServer?: https.Server; } -export interface AppInstance { +export type AppInstance = { websocket: WebsocketServer; serve: (httpPort: number, sslConfig?: SslConfig) => ServeResult; shutdown: () => Promise; diff --git a/src/automation/scriptRuntime.ts b/src/automation/scriptRuntime.ts index 5293ac9..4aa5578 100644 --- a/src/automation/scriptRuntime.ts +++ b/src/automation/scriptRuntime.ts @@ -12,7 +12,7 @@ export type SupportedDeviceEvent = | { type: DeviceManagerEvent.deviceConnected | DeviceManagerEvent.deviceDisconnected | DeviceManagerEvent.deviceRefreshed; device: AnyDevice; args: [] } | { type: DeviceManagerEvent.deviceNotification; device: AnyDevice; args: [notification: DeviceNotification] }; -interface ScriptRuntimeEvents { +type ScriptRuntimeEvents = { [AutomationEventType.consoleLog]: (data: string) => void; [AutomationEventType.scriptStarted]: () => void; [AutomationEventType.scriptStopped]: () => void; @@ -156,7 +156,12 @@ export default class ScriptRuntime private async processQueue(): Promise { while (this.eventQueue.length > 0) { - const task = this.eventQueue.shift()!; + const task = this.eventQueue.shift(); + + if (undefined === task) { + continue; + } + try { await task(); } catch (e: unknown) { diff --git a/src/automation/scriptVm.ts b/src/automation/scriptVm.ts index 50c8562..b9c3ca5 100644 --- a/src/automation/scriptVm.ts +++ b/src/automation/scriptVm.ts @@ -1,7 +1,7 @@ import ivm from 'isolated-vm'; import { EventEmitter } from 'events'; -export interface ScriptVmSignalEvents { +export type ScriptVmSignalEvents = { eventDone: [errMsg: string | null]; lifecycleDone: [errMsg: string | null]; } diff --git a/src/automation/scriptVmFactory.ts b/src/automation/scriptVmFactory.ts index c2b1840..ae3709b 100644 --- a/src/automation/scriptVmFactory.ts +++ b/src/automation/scriptVmFactory.ts @@ -7,7 +7,7 @@ import { AnyDevice } from '../device/device.js'; import Logger from '../logging/Logger.js'; import ScriptVm, { LIFECYCLE_START, ScriptVmSignalEvents } from './scriptVm.js'; -export interface BridgeDevice { +export type BridgeDevice = { id: string; name: string; } diff --git a/src/controller/automation/createScriptController.ts b/src/controller/automation/createScriptController.ts index 8c9ef26..6c6fa25 100644 --- a/src/controller/automation/createScriptController.ts +++ b/src/controller/automation/createScriptController.ts @@ -3,7 +3,10 @@ import ControllerInterface from '../controllerInterface.js'; import AutomationScriptRepositoryInterface from '../../repository/automationScriptRepositoryInterface.js'; import { isValidAutomationScriptFileName } from '../../automation/utils.js'; -interface RequestParams { fileName: string } + +type RequestParams = { + fileName: string; +} type RequestBody = string; type CreateScriptRequest = Request; diff --git a/src/controller/automation/deleteScriptController.ts b/src/controller/automation/deleteScriptController.ts index 111a87b..ad7292f 100644 --- a/src/controller/automation/deleteScriptController.ts +++ b/src/controller/automation/deleteScriptController.ts @@ -3,7 +3,8 @@ import ControllerInterface from '../controllerInterface.js'; import AutomationScriptRepositoryInterface from '../../repository/automationScriptRepositoryInterface.js'; import { isValidAutomationScriptFileName } from '../../automation/utils.js'; -interface RequestParams { fileName: string } + +type RequestParams = { fileName: string } type DeleteScriptRequest = Request; export default class DeleteScriptController implements ControllerInterface diff --git a/src/controller/automation/getScriptController.ts b/src/controller/automation/getScriptController.ts index 3fee9ff..dbce19c 100644 --- a/src/controller/automation/getScriptController.ts +++ b/src/controller/automation/getScriptController.ts @@ -3,7 +3,7 @@ import ControllerInterface from '../controllerInterface.js'; import AutomationScriptRepositoryInterface from '../../repository/automationScriptRepositoryInterface.js'; import { isValidAutomationScriptFileName } from '../../automation/utils.js'; -interface RequestParams { +type RequestParams = { fileName: string; } diff --git a/src/controller/controllerInterface.ts b/src/controller/controllerInterface.ts index 316964b..11be4e8 100644 --- a/src/controller/controllerInterface.ts +++ b/src/controller/controllerInterface.ts @@ -1,6 +1,6 @@ import { Request, Response } from 'express'; -export default interface ControllerInterface -{ +type ControllerInterface = { execute(req: Request, res: Response): void | Promise; } +export default ControllerInterface diff --git a/src/device/attribute/listDeviceAttribute.ts b/src/device/attribute/listDeviceAttribute.ts index 2da6fc9..afdd8ed 100644 --- a/src/device/attribute/listDeviceAttribute.ts +++ b/src/device/attribute/listDeviceAttribute.ts @@ -8,7 +8,7 @@ export type InitializedListDeviceAttribute< IValue extends ListDeviceAttributeItem > = ListDeviceAttribute; -export interface ListDeviceAttributeOption { key: IKey, value: IValue } +export type ListDeviceAttributeOption = { key: IKey, value: IValue } export type ListDeviceAttributeOptions = ListDeviceAttributeOption[]; export default class ListDeviceAttribute< diff --git a/src/device/device.ts b/src/device/device.ts index 9f25b27..4259df0 100644 --- a/src/device/device.ts +++ b/src/device/device.ts @@ -27,7 +27,7 @@ export type DeviceData = { [K in AttributeKeyOf]: AttributeValueOf; }; -export interface DeviceError { +export type DeviceError = { reason: string; occurredAt: Date; } @@ -41,10 +41,10 @@ export enum DeviceEvent { export type DeviceNotification = { [K in keyof TNotifications & string]: { type: K; data: TNotifications[K] } }[keyof TNotifications & string]; -export interface DeviceEventMap< +export type DeviceEventMap< TDevice extends Device = Device, TNotifications extends DeviceNotifications = AnyDeviceNotifications -> { +> = { [DeviceEvent.deviceRefreshed]: [device: TDevice]; [DeviceEvent.deviceDisconnected]: [device: TDevice]; [DeviceEvent.deviceNotification]: [device: TDevice, notification: DeviceNotification]; diff --git a/src/device/deviceManager.ts b/src/device/deviceManager.ts index 361ff8b..9c1f4e0 100644 --- a/src/device/deviceManager.ts +++ b/src/device/deviceManager.ts @@ -10,7 +10,7 @@ import SettingsManager from '../settings/settingsManager.js'; import DeviceOfferRejectedError from './deviceOfferRejectedError.js'; import DetectedDeviceOfferQueue, { OfferResult } from './detectedDeviceOfferQueue.js'; -export interface DeviceDetectionInfo { +export type DeviceDetectionInfo = { type: string; detectionId: DetectionId; } @@ -23,13 +23,13 @@ export enum DeviceManagerEvent { deviceNotification = 'deviceNotification', } -interface DisabledDetectedDevice { +type DisabledDetectedDevice = { deviceDetectionInfo: DeviceDetectionInfo; canonicalId: DeviceId; deviceReleased: Promise; } -interface DeviceManagerEventMap { +type DeviceManagerEventMap = { [DeviceManagerEvent.deviceConnected]: [device: AnyDevice]; [DeviceManagerEvent.deviceDisconnected]: [device: AnyDevice]; [DeviceManagerEvent.deviceRefreshed]: [device: AnyDevice]; @@ -37,7 +37,7 @@ interface DeviceManagerEventMap { [DeviceManagerEvent.deviceNotification]: [device: AnyDevice, notification: DeviceNotification]; } -interface ConnectedDevice { device: AnyDevice, deviceDetectionInfo: DeviceDetectionInfo } +type ConnectedDevice = { device: AnyDevice, deviceDetectionInfo: DeviceDetectionInfo } export default class DeviceManager { diff --git a/src/device/protocol/airotic/airoticDevice.ts b/src/device/protocol/airotic/airoticDevice.ts index 7272f1c..23bb445 100644 --- a/src/device/protocol/airotic/airoticDevice.ts +++ b/src/device/protocol/airotic/airoticDevice.ts @@ -25,16 +25,18 @@ const DEFAULT_BREATH_IN_COLOR = '255,0,128'; export type BpmTrend = 'up' | 'down' | 'stable'; -export interface AiroticDeviceAttributes { - restColor: StrDeviceAttribute, - breathInColor: StrDeviceAttribute, - resetColors: BoolDeviceAttribute, - reboot: BoolDeviceAttribute, - breathsPerMin: FloatDeviceAttribute, - bpmTrend: StrDeviceAttribute, -} -export interface AiroticDeviceNotifications { +export type AiroticDeviceAttributes = { + restColor: StrDeviceAttribute; + breathInColor: StrDeviceAttribute; + resetColors: BoolDeviceAttribute; + reboot: BoolDeviceAttribute; + breathsPerMin: FloatDeviceAttribute; + bpmTrend: StrDeviceAttribute; +}; + + +export type AiroticDeviceNotifications = { colorChange: { colorType: 'breathInColor' | 'restColor'; }; diff --git a/src/device/protocol/buttplugIo/buttplugIoWebsocketDeviceProviderFactory.ts b/src/device/protocol/buttplugIo/buttplugIoWebsocketDeviceProviderFactory.ts index 92c3c85..0a0b36e 100644 --- a/src/device/protocol/buttplugIo/buttplugIoWebsocketDeviceProviderFactory.ts +++ b/src/device/protocol/buttplugIo/buttplugIoWebsocketDeviceProviderFactory.ts @@ -4,7 +4,7 @@ import ButtplugIoDeviceFactory from './buttplugIoDeviceFactory.js'; import ButtplugIoWebsocketDeviceProvider from './buttplugIoWebsocketDeviceProvider.js'; import DeviceManager from '../../deviceManager.js'; -interface ButtplugIoWebsocketDeviceProviderConfig { +type ButtplugIoWebsocketDeviceProviderConfig = { address: string, autoScan: boolean, useDeviceNameAsId: boolean diff --git a/src/device/protocol/deviceProtocol.ts b/src/device/protocol/deviceProtocol.ts index 51008ed..bd1daa1 100644 --- a/src/device/protocol/deviceProtocol.ts +++ b/src/device/protocol/deviceProtocol.ts @@ -7,7 +7,7 @@ export type DecodeResult = | { message: TMessage } | { error: ProtocolError }; -export interface Message { +export type Message = { message: T; } @@ -21,14 +21,14 @@ export type InferMR

= P extends DeviceProtocol> export type InferMessage = MR extends MessageWithResponse ? M : MR extends Message ? M : never; export type InferResponse = MR extends MessageWithResponse ? R : - MR extends Message ? void : never; + MR extends Message ? undefined : never; -export default interface DeviceProtocol> -{ +type DeviceProtocol> = { encode(message: InferMessage): Buffer; decode(data: Buffer): DecodeResult>; isResponseMatchingMessage(response: InferResponse, message: MR): boolean; } +export default DeviceProtocol export const getErrorFromDecodeResult = (protocolError: ProtocolError, transportResponse: Buffer): Error => { switch (protocolError.type) { diff --git a/src/device/protocol/estim2b/estim2bDevice.ts b/src/device/protocol/estim2b/estim2bDevice.ts index 417f243..f12af37 100644 --- a/src/device/protocol/estim2b/estim2bDevice.ts +++ b/src/device/protocol/estim2b/estim2bDevice.ts @@ -14,7 +14,8 @@ import EventEmitter from 'events'; import Logger from '../../../logging/Logger.js'; import { DeviceId } from '../../deviceId.js'; -export interface EStim2bDeviceAttributes { + +export type EStim2bDeviceAttributes = { mode: ListDeviceAttribute, channelALevel: IntRangeDeviceAttribute, channelBLevel: IntRangeDeviceAttribute, diff --git a/src/device/protocol/estim2b/estim2bProtocol.ts b/src/device/protocol/estim2b/estim2bProtocol.ts index f52d295..acc2e00 100644 --- a/src/device/protocol/estim2b/estim2bProtocol.ts +++ b/src/device/protocol/estim2b/estim2bProtocol.ts @@ -1,6 +1,6 @@ import DeviceProtocol, { DecodeResult, InferMessage, MessageWithResponse } from '../deviceProtocol.js'; -export interface EStim2bStatus { +export type EStim2bStatus = { batteryLevel: number, channelALevel: number, channelBLevel: number, diff --git a/src/device/protocol/messageResponseHandler.ts b/src/device/protocol/messageResponseHandler.ts index c42e435..e22c9ea 100644 --- a/src/device/protocol/messageResponseHandler.ts +++ b/src/device/protocol/messageResponseHandler.ts @@ -4,7 +4,7 @@ import { clearTimeout } from 'node:timers'; import Logger from '../../logging/Logger.js'; import { promiseWithTimeout } from '../../util/async.js'; -interface PendingEntry { +type PendingEntry = { msg: MR; resolve: (response: InferResponse) => void; reject: (error: Error) => void; diff --git a/src/device/protocol/slvCtrlPlus/slvCtrlProtocol.ts b/src/device/protocol/slvCtrlPlus/slvCtrlProtocol.ts index 3add5da..69b68b2 100644 --- a/src/device/protocol/slvCtrlPlus/slvCtrlProtocol.ts +++ b/src/device/protocol/slvCtrlPlus/slvCtrlProtocol.ts @@ -1,7 +1,7 @@ import { SlvCtrlPlusDeviceAttributes } from './slvCtrlPlusDevice.js'; import DeviceProtocol, { DecodeResult, InferMessage, InferResponse, MessageWithResponse } from '../deviceProtocol.js'; -export interface DeviceInfo { +export type DeviceInfo = { deviceType: string, fwVersion: number, protocolVersion: number, @@ -11,11 +11,11 @@ export type Result = { status: 'ok' | 'error' | 'unknown', reason?: string, } & Record -export interface SlvCtrlProtocolCommand { +export type SlvCtrlProtocolCommand = { command: string; args: (string|number|boolean)[]; } -export interface SlvCtrlProtocolResponse { +export type SlvCtrlProtocolResponse = { command: string, data: KeyValuePairs, result: Result, diff --git a/src/device/protocol/slvCtrlPlus/slvCtrlProtocolLegacy.ts b/src/device/protocol/slvCtrlPlus/slvCtrlProtocolLegacy.ts index 9a39433..734f70a 100644 --- a/src/device/protocol/slvCtrlPlus/slvCtrlProtocolLegacy.ts +++ b/src/device/protocol/slvCtrlPlus/slvCtrlProtocolLegacy.ts @@ -13,7 +13,7 @@ import SlvCtrlProtocol, { } from './slvCtrlProtocol.js'; import { DecodeResult, InferMessage, InferResponse } from '../deviceProtocol.js'; -interface SetAttributeResponse { +type SetAttributeResponse = { command: string, value: string, status: string, diff --git a/src/device/protocol/virtual/audio/piperVirtualDeviceLogic.ts b/src/device/protocol/virtual/audio/piperVirtualDeviceLogic.ts index f12a130..5a4a9ac 100644 --- a/src/device/protocol/virtual/audio/piperVirtualDeviceLogic.ts +++ b/src/device/protocol/virtual/audio/piperVirtualDeviceLogic.ts @@ -13,13 +13,13 @@ import { PiperVirtualDeviceConfig } from './piperVirtualDeviceConfig.js'; import DevNullStream from '../../../../util/devNullStream.js'; import VirtualDeviceLogic from '../virtualDeviceLogic.js'; -interface PiperVirtualDeviceAttributes { +type PiperVirtualDeviceAttributes = { text: StrDeviceAttribute; queuing: BoolDeviceAttribute; } -interface PiperModelMetadata { +type PiperModelMetadata = { num_speakers?: number, sample_width?: number, audio?: { @@ -72,7 +72,7 @@ export default class PiperVirtualDeviceLogic extends VirtualDeviceLogic< // If queuing is disabled, we must destroy speaker to end output // and return because we need to wait until the stdout of piper // process is drained (see stopPlayback() for details) - if (!queuing && this.stopPlayback()) { + if (false === queuing && this.stopPlayback()) { return; } @@ -107,9 +107,7 @@ export default class PiperVirtualDeviceLogic extends VirtualDeviceLogic< }; } - public get refreshInterval(): number { - return 175; - } + public readonly refreshInterval = 175; private async startPiper(): Promise { if (undefined !== this.piperProcess) { diff --git a/src/device/protocol/virtual/audio/ttsVirtualDeviceLogic.ts b/src/device/protocol/virtual/audio/ttsVirtualDeviceLogic.ts index c61a8f6..dd85ae0 100644 --- a/src/device/protocol/virtual/audio/ttsVirtualDeviceLogic.ts +++ b/src/device/protocol/virtual/audio/ttsVirtualDeviceLogic.ts @@ -9,7 +9,8 @@ import { Int } from '../../../../util/numbers.js'; import Logger from '../../../../logging/Logger.js'; import { TtsVirtualDeviceConfig } from './ttsVirtualDeviceConfig.js'; -interface TtsVirtualDeviceAttributes { + +type TtsVirtualDeviceAttributes = { text: StrDeviceAttribute; speaking: BoolDeviceAttribute; queuing: BoolDeviceAttribute; @@ -79,9 +80,7 @@ export default class TtsVirtualDeviceLogic extends VirtualDeviceLogic< await device.setAttribute('queueLength', Int.from(this.ttsEntries.length)); } - public get refreshInterval(): number { - return 175; - } + public readonly refreshInterval = 175; public configureAttributes(): TtsVirtualDeviceAttributes { const textAttr = StrDeviceAttribute.create( diff --git a/src/device/protocol/virtual/display/displayVirtualDeviceLogic.ts b/src/device/protocol/virtual/display/displayVirtualDeviceLogic.ts index 2cc8839..5af8d83 100644 --- a/src/device/protocol/virtual/display/displayVirtualDeviceLogic.ts +++ b/src/device/protocol/virtual/display/displayVirtualDeviceLogic.ts @@ -3,7 +3,7 @@ import StrDeviceAttribute from '../../../attribute/strDeviceAttribute.js'; import VirtualDeviceLogic from '../virtualDeviceLogic.js'; import { NoDeviceConfig } from '../../../deviceConfig.js'; -interface DisplayVirtualDeviceAttributes { +type DisplayVirtualDeviceAttributes = { content: StrDeviceAttribute; } @@ -17,9 +17,7 @@ export default class DisplayVirtualDeviceLogic extends VirtualDeviceLogic> = T extends VirtualDeviceLogic ? C : never; -interface LogicFactoryAndConfigTuple, TConfigSchema extends TObject> { +type LogicFactoryAndConfigTuple, TConfigSchema extends TObject> = { deviceLogicFactory: VirtualDeviceLogicFactory, deviceConfigSchema: TConfigSchema & ( Static extends ExtractConfig diff --git a/src/device/protocol/virtual/randomGenerator/randomGeneratorVirtualDeviceLogic.ts b/src/device/protocol/virtual/randomGenerator/randomGeneratorVirtualDeviceLogic.ts index cccfb6e..a5d0597 100644 --- a/src/device/protocol/virtual/randomGenerator/randomGeneratorVirtualDeviceLogic.ts +++ b/src/device/protocol/virtual/randomGenerator/randomGeneratorVirtualDeviceLogic.ts @@ -5,7 +5,8 @@ import VirtualDevice from '../virtualDevice.js'; import { Int } from '../../../../util/numbers.js'; import { RandomGeneratorVirtualDeviceConfig } from './randomGeneratorVirtualDeviceConfig.js'; -interface RandomGeneratorVirtualDeviceAttributes { + +type RandomGeneratorVirtualDeviceAttributes = { value: IntDeviceAttribute; } @@ -23,9 +24,7 @@ export default class RandomGeneratorVirtualDeviceLogic extends VirtualDeviceLogi } } - public get refreshInterval(): number { - return 100; - } + public readonly refreshInterval = 100; public async refreshData(device: VirtualDevice): Promise { const currentNumber = (await device.getAttribute('value'))?.value; diff --git a/src/device/protocol/virtual/virtualDeviceFactory.ts b/src/device/protocol/virtual/virtualDeviceFactory.ts index fb665eb..ab71af7 100644 --- a/src/device/protocol/virtual/virtualDeviceFactory.ts +++ b/src/device/protocol/virtual/virtualDeviceFactory.ts @@ -1,6 +1,7 @@ import KnownDevice from '../../../settings/knownDevice.js'; import VirtualDevice from './virtualDevice.js'; -export default interface VirtualDeviceFactory { +type VirtualDeviceFactory = { create(knownDevice: KnownDevice, provider: string): Promise>; } +export default VirtualDeviceFactory diff --git a/src/device/protocol/virtual/virtualDeviceLogicFactory.ts b/src/device/protocol/virtual/virtualDeviceLogicFactory.ts index 1b002d3..937728f 100644 --- a/src/device/protocol/virtual/virtualDeviceLogicFactory.ts +++ b/src/device/protocol/virtual/virtualDeviceLogicFactory.ts @@ -2,9 +2,9 @@ import VirtualDeviceLogic from './virtualDeviceLogic.js'; type ExtractConfig> = T extends VirtualDeviceLogic ? C : never; -export default interface VirtualDeviceLogicFactory> -{ +type VirtualDeviceLogicFactory> = { create(config: ExtractConfig): TDeviceLogic; forDeviceType(): string; } +export default VirtualDeviceLogicFactory diff --git a/src/device/protocol/zc95/zc95Device.ts b/src/device/protocol/zc95/zc95Device.ts index 89612a7..6336d9a 100644 --- a/src/device/protocol/zc95/zc95Device.ts +++ b/src/device/protocol/zc95/zc95Device.ts @@ -25,7 +25,7 @@ import Logger from '../../../logging/Logger.js'; import EventEmitter from 'events'; import { DeviceId } from '../../deviceId.js'; -interface RequiredZc95DeviceAttributes { +type RequiredZc95DeviceAttributes = { activePattern: InitializedListDeviceAttribute; patternStarted: InitializedBoolDeviceAttribute; } @@ -254,7 +254,7 @@ export default class Zc95Device extends PeripheralDevice = R extends { Type: infer T } ? T : never; -export interface Msg -{ +export type Msg = { Type: string; MsgId: number; } -export interface MsgResponse -{ +export type MsgResponse = { Type: string; MsgId: number; Result: 'OK' | 'ERROR' Error?: string; } -export interface ResponseIdentifier -{ +export type ResponseIdentifier = { msgId: number, type: ResponseToKey } -export interface MsgAndResponseIdentifier extends MessageWithResponse { +export type MsgAndResponseIdentifier = { responseIdentifier: ResponseIdentifier; -} +} & MessageWithResponse export type Zc95ProtocolMessage = MsgAndResponseIdentifier; diff --git a/src/device/provider/deviceProviderFactory.ts b/src/device/provider/deviceProviderFactory.ts index a6e38cd..27808be 100644 --- a/src/device/provider/deviceProviderFactory.ts +++ b/src/device/provider/deviceProviderFactory.ts @@ -1,7 +1,7 @@ import { AnyDeviceProvider } from './deviceProvider.js'; import { JsonObject } from '../../types.js'; -export default interface DeviceProviderFactory -{ +type DeviceProviderFactory = { create(config: JsonObject): DP; } +export default DeviceProviderFactory diff --git a/src/device/provider/deviceProviderManager.ts b/src/device/provider/deviceProviderManager.ts index 42b92d9..999ee71 100644 --- a/src/device/provider/deviceProviderManager.ts +++ b/src/device/provider/deviceProviderManager.ts @@ -6,7 +6,7 @@ import Logger from '../../logging/Logger.js'; import { AnyDeviceProvider } from './deviceProvider.js'; import { logError } from '../../util/error.js'; -interface RunningProvider { +type RunningProvider = { provider: AnyDeviceProvider; sourceFingerprint: string; } diff --git a/src/device/serializedTypes.ts b/src/device/serializedTypes.ts index 072db1f..d4eebdc 100644 --- a/src/device/serializedTypes.ts +++ b/src/device/serializedTypes.ts @@ -2,7 +2,7 @@ import DeviceState from './deviceState.js'; import { DeviceAttributeModifier } from './attribute/deviceAttribute.js'; import { DeviceId } from './deviceId.js'; -interface SerializedDeviceAttributeBase { +type SerializedDeviceAttributeBase = { name: string; label: string | undefined; modifier: DeviceAttributeModifier; @@ -54,7 +54,7 @@ export type SerializedDeviceAttribute = | SerializedStrDeviceAttribute | SerializedListDeviceAttribute; -interface SerializedDeviceBase { +type SerializedDeviceBase = { connectedSince: Date; deviceId: DeviceId; deviceName: string; diff --git a/src/device/transport/deviceBidirectionalTransport.ts b/src/device/transport/deviceBidirectionalTransport.ts index 585473d..6ae3672 100644 --- a/src/device/transport/deviceBidirectionalTransport.ts +++ b/src/device/transport/deviceBidirectionalTransport.ts @@ -1,12 +1,12 @@ import DeviceReadableTransport from './deviceReadableTransport.js'; import DeviceWritableTransport from './deviceWritableTransport.js'; -export default interface DeviceTransport extends DeviceReadableTransport, DeviceWritableTransport -{ +type DeviceTransport = { /** * Writes data and waits for a response associated to it and returns it as a result * @param data The command/input for the device * @param timeout The timeout the transport should wait for the operation to complete and get a response */ sendAndAwaitReceive(data: Buffer, timeout?: number): Promise; -} +} & DeviceReadableTransport & DeviceWritableTransport +export default DeviceTransport diff --git a/src/device/transport/deviceReadableTransport.ts b/src/device/transport/deviceReadableTransport.ts index 2b8e21f..afe2c0e 100644 --- a/src/device/transport/deviceReadableTransport.ts +++ b/src/device/transport/deviceReadableTransport.ts @@ -1,5 +1,4 @@ -export default interface DeviceReadableTransport -{ +type DeviceReadableTransport = { /** * When data is received * @param dataProcessor @@ -27,3 +26,4 @@ export default interface DeviceReadableTransport */ getDeviceIdentifier(): string; } +export default DeviceReadableTransport diff --git a/src/device/transport/deviceWritableTransport.ts b/src/device/transport/deviceWritableTransport.ts index 55563af..abfc815 100644 --- a/src/device/transport/deviceWritableTransport.ts +++ b/src/device/transport/deviceWritableTransport.ts @@ -1,5 +1,4 @@ -export default interface DeviceWritableTransport -{ +type DeviceWritableTransport = { /** * Writes data * @param data The command/input for the device @@ -27,3 +26,4 @@ export default interface DeviceWritableTransport */ getDeviceIdentifier(): string; } +export default DeviceWritableTransport diff --git a/src/device/updater/deviceUpdaterInterface.ts b/src/device/updater/deviceUpdaterInterface.ts index 60f1459..4719f48 100644 --- a/src/device/updater/deviceUpdaterInterface.ts +++ b/src/device/updater/deviceUpdaterInterface.ts @@ -1,6 +1,6 @@ import { AnyDevice, DeviceData } from '../device.js'; -export default interface DeviceUpdaterInterface -{ +type DeviceUpdaterInterface = { update(device: AnyDevice, rawData: DeviceData): Promise; } +export default DeviceUpdaterInterface diff --git a/src/health/serializedTypes.ts b/src/health/serializedTypes.ts index fdfa2cc..fe8628b 100644 --- a/src/health/serializedTypes.ts +++ b/src/health/serializedTypes.ts @@ -1,6 +1,6 @@ import { NetworkStats } from 'node-os-utils'; -export interface SerializedHealthMetrics { +export type SerializedHealthMetrics = { process: { memoryUsage: NodeJS.MemoryUsage, }, diff --git a/src/logging/Logger.ts b/src/logging/Logger.ts index c521f81..498aa31 100644 --- a/src/logging/Logger.ts +++ b/src/logging/Logger.ts @@ -1,15 +1,14 @@ -export interface ChildLoggerBindings { +export type ChildLoggerBindings = { name?: string, } -export interface ChildLoggerOptions { +export type ChildLoggerOptions = { level?: string, } export type ErrorContext = Error | ({ error: Error } & Record); -export default interface Logger -{ +type Logger = { child(bindings?: ChildLoggerBindings, options?: ChildLoggerOptions): Logger; trace(msg: string, context?: unknown): void; @@ -19,3 +18,4 @@ export default interface Logger error(msg: string, context?: ErrorContext | unknown): void; fatal(msg: string, context?: unknown): void; } +export default Logger diff --git a/src/repository/automationScriptRepositoryInterface.ts b/src/repository/automationScriptRepositoryInterface.ts index 6f5343c..a230525 100644 --- a/src/repository/automationScriptRepositoryInterface.ts +++ b/src/repository/automationScriptRepositoryInterface.ts @@ -1,7 +1,6 @@ import AutomationScript from '../entity/automationScript.js'; -export default interface AutomationScriptRepositoryInterface -{ +type AutomationScriptRepositoryInterface = { getAll(): AutomationScript[]; getByName(name: string): string|null; @@ -10,3 +9,4 @@ export default interface AutomationScriptRepositoryInterface delete(fileName: string): void; } +export default AutomationScriptRepositoryInterface diff --git a/src/repository/deviceRepositoryInterface.ts b/src/repository/deviceRepositoryInterface.ts index d0cc3aa..b30a36d 100644 --- a/src/repository/deviceRepositoryInterface.ts +++ b/src/repository/deviceRepositoryInterface.ts @@ -1,8 +1,8 @@ import { AnyDevice } from '../device/device.js'; -export default interface DeviceRepositoryInterface -{ +type DeviceRepositoryInterface = { getAll(): AnyDevice[]; getById(uuid: string): AnyDevice|null; } +export default DeviceRepositoryInterface diff --git a/src/serial/frameParser.ts b/src/serial/frameParser.ts index f1a73bc..05d168f 100644 --- a/src/serial/frameParser.ts +++ b/src/serial/frameParser.ts @@ -1,11 +1,10 @@ import { Transform, TransformCallback, TransformOptions } from 'stream'; -export interface FrameParserOptions extends TransformOptions -{ +export type FrameParserOptions = { stx: number; etx: number; maxMessageSize?: number; -} +} & TransformOptions type State = 'IDLE' | 'RECV'; diff --git a/src/serviceMap.ts b/src/serviceMap.ts index cac2fde..993fcdf 100644 --- a/src/serviceMap.ts +++ b/src/serviceMap.ts @@ -54,7 +54,7 @@ import AiroticDeviceFactory from './device/protocol/airotic/airoticDeviceFactory import KnownDeviceRegistry from './device/knownDeviceRegistry.js'; -interface ServiceMap { +type ServiceMap = { /* serializerServiceProvider */ 'serializer.classToPlain': ClassToPlainSerializer, 'serializer.plainToClass': PlainToClassSerializer, diff --git a/src/settings/serializedTypes.ts b/src/settings/serializedTypes.ts index 257aff9..03262aa 100644 --- a/src/settings/serializedTypes.ts +++ b/src/settings/serializedTypes.ts @@ -1,6 +1,6 @@ import { JsonObject } from '../types.js'; -export interface SerializedKnownDevice { +export type SerializedKnownDevice = { id: string; serialNo: string; name: string; @@ -10,14 +10,14 @@ export interface SerializedKnownDevice { enabled: boolean; } -export interface SerializedDeviceSource { +export type SerializedDeviceSource = { id: string; type: string; config: JsonObject; enabled: boolean; } -export interface SerializedSettings { +export type SerializedSettings = { knownDevices: Record; deviceSources: Record; } diff --git a/src/settings/settingsManager.ts b/src/settings/settingsManager.ts index 45e75eb..02cefc1 100644 --- a/src/settings/settingsManager.ts +++ b/src/settings/settingsManager.ts @@ -13,7 +13,7 @@ import { JsonObject } from '../types.js'; import { logError } from '../util/error.js'; -interface SettingsEvents { +type SettingsEvents = { [SettingsEventType.changed]: (settings: Settings) => void, } diff --git a/src/socket/types.ts b/src/socket/types.ts index d7a65c8..c70eaa5 100644 --- a/src/socket/types.ts +++ b/src/socket/types.ts @@ -8,13 +8,13 @@ import { SerializedDevice } from '../device/serializedTypes.js'; import { SerializedSettings } from '../settings/serializedTypes.js'; import { DeviceId } from '../device/deviceId.js'; -export interface DeviceUpdateData { deviceId: DeviceId, data: DeviceData } +export type DeviceUpdateData = { deviceId: DeviceId, data: DeviceData } -export interface ClientToServerEvents { +export type ClientToServerEvents = { [WebSocketEvent.deviceUpdateReceived]: (data: DeviceUpdateData) => void; } -export interface ServerToClientEvents { +export type ServerToClientEvents = { [WebSocketEvent.deviceConnected]: (data: SerializedDevice) => void; [WebSocketEvent.deviceDisconnected]: (data: SerializedDevice) => void; [WebSocketEvent.deviceRefreshed]: (data: SerializedDevice) => void; diff --git a/src/types.d.ts b/src/types.d.ts index 0f41c0d..75a8d98 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,4 +1,4 @@ -export interface JsonObject { [key: string]: JsonValue } +export type JsonObject = { [key: string]: JsonValue } export type JsonValue = | null diff --git a/src/util/async.ts b/src/util/async.ts index 0335ba8..50ac1a7 100644 --- a/src/util/async.ts +++ b/src/util/async.ts @@ -16,7 +16,7 @@ export const setImmediateInterval = ( return setInterval(callback, delay, ...args); }; -export interface IntervalAsyncOptions { +export type IntervalAsyncOptions = { intervalMs: number; runImmediately?: boolean; timeoutMs?: number; @@ -32,7 +32,7 @@ export const asyncHandler = ( }; }; -export interface IntervalAsync { clear: () => void } +export type IntervalAsync = { clear: () => void } export const setIntervalAsync = ( fn: (...args: TArgs) => Promise, From 972748c93a419383b056a23b8d60fbbec6b9ac3c Mon Sep 17 00:00:00 2001 From: HRS Date: Mon, 3 Aug 2026 21:43:51 +0200 Subject: [PATCH 4/5] Remove no-extraneous-class/no-invalid-void-type rule overrides - ObjectDiscriminator: convert from a static-only abstract base class (extended by DeviceDiscriminator/GenericDeviceAttributeDiscriminator overriding a static discriminatorMap) to a concrete class taking discriminatorMap via constructor, with the two former subclasses becoming pre-built exported instances instead. Removes the need for no-extraneous-class's allowStaticOnly. - BufferedDeviceUpdater.handleUpdate: no longer needs an explicit `this: void` parameter to satisfy unbound-method. Removes the need for no-invalid-void-type's allowAsThisParameter. --- eslint.config.ts | 14 ++----------- src/controller/getDeviceController.ts | 4 ++-- src/device/updater/bufferedDeviceUpdater.ts | 17 +++++++-------- src/entity/deviceList.ts | 4 ++-- .../discriminator/deviceDiscriminator.ts | 21 +++++++++---------- .../genericDeviceAttributeDiscriminator.ts | 20 +++++++++--------- .../discriminator/objectDiscriminator.ts | 14 ++++++++----- 7 files changed, 43 insertions(+), 51 deletions(-) diff --git a/eslint.config.ts b/eslint.config.ts index 044c61e..384962a 100644 --- a/eslint.config.ts +++ b/eslint.config.ts @@ -101,18 +101,8 @@ export default [ "@typescript-eslint/no-misused-promises": "error", "@typescript-eslint/no-misused-new": "error", "@typescript-eslint/no-namespace": "error", - "@typescript-eslint/no-extraneous-class": [ - "error", - { - "allowStaticOnly": true - } - ], - "@typescript-eslint/no-invalid-void-type": [ - "error", - { - "allowAsThisParameter": true - } - ], + "@typescript-eslint/no-extraneous-class": "error", + "@typescript-eslint/no-invalid-void-type": "error", "@typescript-eslint/consistent-type-definitions": [ "error", "type" diff --git a/src/controller/getDeviceController.ts b/src/controller/getDeviceController.ts index b6b3ecb..e563d57 100644 --- a/src/controller/getDeviceController.ts +++ b/src/controller/getDeviceController.ts @@ -2,7 +2,7 @@ import { Request, Response } from 'express'; import ControllerInterface from './controllerInterface.js'; import ClassToPlainSerializer from '../serialization/classToPlainSerializer.js'; import ConnectedDeviceRepository from '../repository/connectedDeviceRepository.js'; -import DeviceDiscriminator from '../serialization/discriminator/deviceDiscriminator.js'; +import deviceDiscriminator from '../serialization/discriminator/deviceDiscriminator.js'; import { DeviceId } from '../device/deviceId.js'; type GetDeviceRequest = Request<{ deviceId: DeviceId }>; @@ -31,7 +31,7 @@ export default class GetDeviceController implements ControllerInterface res.json(this.serializer.transform( device, - DeviceDiscriminator.createClassTransformerTypeDiscriminator('type') + deviceDiscriminator.createClassTransformerTypeDiscriminator('type') )); } } diff --git a/src/device/updater/bufferedDeviceUpdater.ts b/src/device/updater/bufferedDeviceUpdater.ts index b58b97b..3ce936e 100644 --- a/src/device/updater/bufferedDeviceUpdater.ts +++ b/src/device/updater/bufferedDeviceUpdater.ts @@ -8,6 +8,14 @@ export default class BufferedDeviceUpdater implements DeviceUpdaterInterface private readonly queue: SequentialTaskQueue; + private static readonly handleUpdate = async ( + deviceUpdater: DeviceUpdaterInterface, + device: AnyDevice, + deviceData: DeviceData + ): Promise => { + await deviceUpdater.update(device, deviceData); + }; + public constructor(decoratedDeviceUpdater: DeviceUpdaterInterface) { this.decoratedDeviceUpdater = decoratedDeviceUpdater; this.queue = new SequentialTaskQueue(); @@ -16,13 +24,4 @@ export default class BufferedDeviceUpdater implements DeviceUpdaterInterface public async update(device: AnyDevice, deviceData: DeviceData): Promise { await this.queue.push(BufferedDeviceUpdater.handleUpdate, { args: [this.decoratedDeviceUpdater, device, deviceData] }); } - - private static async handleUpdate( - this: void, - deviceUpdater: DeviceUpdaterInterface, - device: AnyDevice, - deviceData: DeviceData - ): Promise { - await deviceUpdater.update(device, deviceData); - } } diff --git a/src/entity/deviceList.ts b/src/entity/deviceList.ts index 34a345b..3081cb4 100644 --- a/src/entity/deviceList.ts +++ b/src/entity/deviceList.ts @@ -1,11 +1,11 @@ import { Exclude, Type } from 'class-transformer'; import Device, { AnyDevice } from '../device/device.js'; import List from './list.js'; -import DeviceDiscriminator from '../serialization/discriminator/deviceDiscriminator.js'; +import deviceDiscriminator from '../serialization/discriminator/deviceDiscriminator.js'; @Exclude() export default class DeviceList extends List { - @Type(() => Device, DeviceDiscriminator.createClassTransformerTypeDiscriminator('type')) + @Type(() => Device, deviceDiscriminator.createClassTransformerTypeDiscriminator('type')) protected readonly declare items: AnyDevice[]; } diff --git a/src/serialization/discriminator/deviceDiscriminator.ts b/src/serialization/discriminator/deviceDiscriminator.ts index 772ae68..4fd70c8 100644 --- a/src/serialization/discriminator/deviceDiscriminator.ts +++ b/src/serialization/discriminator/deviceDiscriminator.ts @@ -6,14 +6,13 @@ import Zc95Device from '../../device/protocol/zc95/zc95Device.js'; import EStim2bDevice from '../../device/protocol/estim2b/estim2bDevice.js'; import AiroticDevice from '../../device/protocol/airotic/airoticDevice.js'; -export default class DeviceDiscriminator extends ObjectDiscriminator -{ - protected static override discriminatorMap = [ - { value: GenericSlvCtrlPlusDevice, name: 'slvCtrlPlus' }, - { value: ButtplugIoDevice, name: 'buttplugIo' }, - { value: Zc95Device, name: 'zc95' }, - { value: VirtualDevice, name: 'virtual' }, - { value: EStim2bDevice, name: 'estim2b' }, - { value: AiroticDevice, name: 'airotic' }, - ]; -} +const deviceDiscriminator = new ObjectDiscriminator([ + { value: GenericSlvCtrlPlusDevice, name: 'slvCtrlPlus' }, + { value: ButtplugIoDevice, name: 'buttplugIo' }, + { value: Zc95Device, name: 'zc95' }, + { value: VirtualDevice, name: 'virtual' }, + { value: EStim2bDevice, name: 'estim2b' }, + { value: AiroticDevice, name: 'airotic' }, +]); + +export default deviceDiscriminator; diff --git a/src/serialization/discriminator/genericDeviceAttributeDiscriminator.ts b/src/serialization/discriminator/genericDeviceAttributeDiscriminator.ts index b0c42de..1255e41 100644 --- a/src/serialization/discriminator/genericDeviceAttributeDiscriminator.ts +++ b/src/serialization/discriminator/genericDeviceAttributeDiscriminator.ts @@ -6,13 +6,13 @@ import StrDeviceAttribute from '../../device/attribute/strDeviceAttribute.js'; import IntRangeDeviceAttribute from '../../device/attribute/intRangeDeviceAttribute.js'; import ListDeviceAttribute from '../../device/attribute/listDeviceAttribute.js'; -export default class GenericDeviceAttributeDiscriminator extends ObjectDiscriminator { - protected static override discriminatorMap = [ - { value: BoolDeviceAttribute, name: 'bool' }, - { value: IntDeviceAttribute, name: 'int' }, - { value: FloatDeviceAttribute, name: 'float' }, - { value: StrDeviceAttribute, name: 'str' }, - { value: IntRangeDeviceAttribute, name: 'range' }, - { value: ListDeviceAttribute, name: 'list' } - ]; -} +const genericDeviceAttributeDiscriminator = new ObjectDiscriminator([ + { value: BoolDeviceAttribute, name: 'bool' }, + { value: IntDeviceAttribute, name: 'int' }, + { value: FloatDeviceAttribute, name: 'float' }, + { value: StrDeviceAttribute, name: 'str' }, + { value: IntRangeDeviceAttribute, name: 'range' }, + { value: ListDeviceAttribute, name: 'list' } +]); + +export default genericDeviceAttributeDiscriminator; diff --git a/src/serialization/discriminator/objectDiscriminator.ts b/src/serialization/discriminator/objectDiscriminator.ts index f81918a..75b05bc 100644 --- a/src/serialization/discriminator/objectDiscriminator.ts +++ b/src/serialization/discriminator/objectDiscriminator.ts @@ -11,10 +11,14 @@ type DiscriminatorMap = { value: ClassConstructor; }[]; -export default abstract class ObjectDiscriminator { - protected static discriminatorMap: DiscriminatorMap; +export default class ObjectDiscriminator { + private readonly discriminatorMap: DiscriminatorMap; - public static fromName(name: string): ClassConstructor { + public constructor(discriminatorMap: DiscriminatorMap) { + this.discriminatorMap = discriminatorMap; + } + + public fromName(name: string): ClassConstructor { for (const subType of this.discriminatorMap) { if (subType.name === name) { return subType.value; @@ -24,7 +28,7 @@ export default abstract class ObjectDiscriminator { throw new Error(`Could not resolve from name '${name}'`); } - public static fromValue(value: ClassConstructor): string { + public fromValue(value: ClassConstructor): string { for (const subType of this.discriminatorMap) { if (subType.value === value) { return subType.name; @@ -34,7 +38,7 @@ export default abstract class ObjectDiscriminator { throw new Error(`Could not resolve from value '${value.name}'`); } - public static createClassTransformerTypeDiscriminator(typePropertyName: string): TypeOptions { + public createClassTransformerTypeDiscriminator(typePropertyName: string): TypeOptions { return { discriminator: { property: typePropertyName, From 794ab4dfb9a8579bb50a56e7909f8ca69f557c2e Mon Sep 17 00:00:00 2001 From: HRS Date: Wed, 5 Aug 2026 23:43:33 +0200 Subject: [PATCH 5/5] Improve naming --- src/app.ts | 12 ++++++------ .../discriminator/objectDiscriminator.ts | 8 ++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/app.ts b/src/app.ts index 204164d..9f6a0d8 100644 --- a/src/app.ts +++ b/src/app.ts @@ -18,7 +18,7 @@ import { AnyDevice } from './device/device.js'; import WebSocketEvent from './device/webSocketEvent.js'; import AutomationEventType from './automation/automationEventType.js'; import LoggerServiceProvider from './serviceProvider/loggerServiceProvider.js'; -import DeviceDiscriminator from './serialization/discriminator/deviceDiscriminator.js'; +import deviceDiscriminator from './serialization/discriminator/deviceDiscriminator.js'; import ServiceMap from './serviceMap.js'; import SettingsEventType from './settings/settingsEventType.js'; import type Settings from './settings/settings.js'; @@ -87,7 +87,7 @@ const configureWebsocket = (io: WebsocketServer, container: Container { - io.emit(WebSocketEvent.deviceConnected, serializer.transform(device, deviceDiscriminator)); + io.emit(WebSocketEvent.deviceConnected, serializer.transform(device, deviceDiscriminatorInstance)); void scriptRuntime.runForEvent({ type: DeviceManagerEvent.deviceConnected, device, args: [] }); }); deviceManager.on(DeviceManagerEvent.deviceDisconnected, (device: AnyDevice) => { - io.emit(WebSocketEvent.deviceDisconnected, serializer.transform(device, deviceDiscriminator)); + io.emit(WebSocketEvent.deviceDisconnected, serializer.transform(device, deviceDiscriminatorInstance)); void scriptRuntime.runForEvent({ type: DeviceManagerEvent.deviceDisconnected, device, args: [] }); }); deviceManager.on(DeviceManagerEvent.deviceRefreshed, (device: AnyDevice) => { - io.emit(WebSocketEvent.deviceRefreshed, serializer.transform(device, deviceDiscriminator)); + io.emit(WebSocketEvent.deviceRefreshed, serializer.transform(device, deviceDiscriminatorInstance)); void scriptRuntime.runForEvent({ type: DeviceManagerEvent.deviceRefreshed, device, args: [] }); }); deviceManager.on(DeviceManagerEvent.deviceNotification, (device: AnyDevice, notification) => { - io.emit(WebSocketEvent.deviceNotification, serializer.transform(device, deviceDiscriminator), notification); + io.emit(WebSocketEvent.deviceNotification, serializer.transform(device, deviceDiscriminatorInstance), notification); void scriptRuntime.runForEvent({ type: DeviceManagerEvent.deviceNotification, device, args: [notification] }); }); diff --git a/src/serialization/discriminator/objectDiscriminator.ts b/src/serialization/discriminator/objectDiscriminator.ts index 75b05bc..83db43e 100644 --- a/src/serialization/discriminator/objectDiscriminator.ts +++ b/src/serialization/discriminator/objectDiscriminator.ts @@ -1,13 +1,9 @@ import { ClassConstructor, TypeOptions } from 'class-transformer'; type DiscriminatorMap = { - /** - * Name of the type. - */ + // Name of the type. name: string; - /** - * A class constructor which can be used to create the object. - */ + // A class constructor which can be used to create the object. value: ClassConstructor; }[];