From b7b34e1b95e72182aa99d90a3cbb2e8c5707dc52 Mon Sep 17 00:00:00 2001 From: AlCalzone Date: Wed, 6 Nov 2024 14:33:22 +0100 Subject: [PATCH] feat: add "browser" condition to main entrypoint for bundlers (#7374) --- maintenance/parse-zwxml-manufacturers.ts | 2 +- package.json | 4 +- packages/cc/package.json | 5 +- packages/cc/src/cc/AssociationCC.ts | 2 +- packages/cc/src/cc/CentralSceneCC.ts | 5 +- .../cc/src/cc/ClimateControlScheduleCC.ts | 11 +- packages/cc/src/cc/ClockCC.ts | 11 +- packages/cc/src/cc/ColorSwitchCC.ts | 4 +- packages/cc/src/cc/ConfigurationCC.ts | 10 +- packages/cc/src/cc/DoorLockCC.ts | 2 +- packages/cc/src/cc/IndicatorCC.ts | 4 +- packages/cc/src/cc/IrrigationCC.ts | 17 +- packages/cc/src/cc/MultiChannelCC.ts | 2 +- packages/cc/src/cc/NotificationCC.ts | 2 +- packages/cc/src/cc/ProtectionCC.ts | 3 +- packages/cc/src/cc/Security2CC.ts | 4 +- packages/cc/src/cc/SecurityCC.ts | 2 +- packages/cc/src/cc/SoundSwitchCC.ts | 2 +- packages/cc/src/cc/TimeCC.ts | 21 +- packages/cc/src/cc/WakeUpCC.ts | 2 +- .../cc/manufacturerProprietary/FibaroCC.ts | 2 +- packages/cc/src/index_browser.ts | 13 + packages/cc/src/lib/API.ts | 2 +- packages/cc/src/lib/CommandClass.ts | 2 +- .../cc/src/lib/EncapsulatingCommandClass.ts | 2 +- packages/cc/src/lib/Values.ts | 4 +- packages/cc/src/lib/serializers.ts | 2 +- packages/cc/src/lib/utils.ts | 2 +- packages/config/maintenance/importConfig.ts | 12 +- .../config/maintenance/lintConfigFiles.ts | 6 +- packages/config/package.json | 4 +- packages/config/src/JsonTemplate.ts | 8 +- packages/config/src/Manufacturers.ts | 2 +- packages/config/src/devices/CompatConfig.ts | 2 +- .../devices/ConditionalDeviceConfig.test.ts | 2 +- .../config/src/devices/ConditionalItem.ts | 2 +- .../src/devices/ConditionalPrimitive.ts | 2 +- packages/config/src/devices/DeviceConfig.ts | 2 +- packages/config/src/devices/DeviceMetadata.ts | 2 +- packages/config/src/devices/EndpointConfig.ts | 2 +- .../config/src/devices/ParamInformation.ts | 2 +- packages/core/package.json | 34 +- packages/core/src/consts/Transmission.ts | 6 +- .../CommandClasses.ts | 0 .../ControllerCapabilities.ts | 0 packages/core/src/definitions/Frame.ts | 14 + .../LibraryTypes.ts | 0 .../NodeInfo.test.ts | 0 .../{capabilities => definitions}/NodeInfo.ts | 12 +- .../Protocols.ts => definitions/Protocol.ts} | 45 +-- .../{capabilities => definitions}/RFRegion.ts | 0 packages/core/src/definitions/Route.ts | 28 ++ .../SecurityClass.ts | 19 -- .../ZWaveApiVersion.ts | 0 .../ZWaveChipTypes.ts | 0 packages/core/src/definitions/index.ts | 11 + .../src/{security/DSK.ts => dsk/index.ts} | 28 +- packages/core/src/error/ZWaveError.ts | 4 +- packages/core/src/index.ts | 23 +- packages/core/src/index_browser.ts | 32 ++ packages/core/src/index_safe.ts | 16 +- packages/core/src/log/Controller.test.ts | 2 +- packages/core/src/log/Controller.ts | 4 +- packages/core/src/log/shared_safe.ts | 3 +- packages/core/src/qr/definitions.ts | 70 +++++ packages/core/src/qr/index.browser.ts | 13 + packages/core/src/qr/index.ts | 13 + packages/core/src/qr/parse.browser.ts | 89 ++++++ packages/core/src/qr/parse.node.ts | 167 ++++++++++ .../{security/QR.test.ts => qr/parse.test.ts} | 5 +- packages/core/src/qr/utils.ts | 159 ++++++++++ packages/core/src/registries/index.ts | 75 +++++ packages/core/src/security/Manager2.test.ts | 2 +- packages/core/src/security/Manager2.ts | 5 +- packages/core/src/security/QR.ts | 291 ------------------ packages/core/src/security/shared_safe.ts | 24 -- packages/core/src/traits/CommandClasses.ts | 8 +- packages/core/src/traits/Nodes.ts | 2 +- packages/core/src/traits/SecurityClasses.ts | 20 ++ packages/core/src/values/Cache.ts | 5 +- packages/core/src/values/Duration.ts | 2 +- packages/core/src/values/Timeout.ts | 2 +- packages/core/src/values/ValueDB.test.ts | 2 +- packages/core/src/values/ValueDB.ts | 2 +- packages/core/src/values/_Types.ts | 2 +- packages/eslint-plugin/package.json | 2 +- .../src/rules/no-forbidden-imports.ts | 17 +- packages/flash/src/cli.ts | 2 +- packages/host/package.json | 4 +- packages/maintenance/package.json | 2 +- packages/nvmedit/package.json | 5 +- packages/nvmedit/src/cli.ts | 2 +- packages/nvmedit/src/convert.ts | 2 +- packages/nvmedit/src/index.ts | 6 +- packages/nvmedit/src/index_browser.ts | 46 +++ packages/nvmedit/src/index_safe.ts | 1 + packages/nvmedit/src/lib/NVM3.ts | 4 +- packages/nvmedit/src/lib/nvm3/adapter.ts | 6 +- .../nvmedit/src/lib/nvm500/EntryParsers.ts | 4 +- packages/nvmedit/src/lib/nvm500/adapter.ts | 2 +- packages/serial/package.json | 4 +- .../GetNodeProtocolInfoMessages.ts | 2 +- .../transport/SendDataBridgeMessages.ts | 2 +- .../serialapi/transport/SendDataMessages.ts | 2 +- .../src/serialport/ZWaveSerialPort.test.ts | 2 +- .../ZWaveSerialPortImplementation.ts | 2 +- packages/shared/package.json | 6 +- packages/shared/src/AsyncQueue.test.ts | 2 +- packages/shared/src/AsyncQueue.ts | 2 +- packages/shared/src/ObjectKeyMap.ts | 6 +- packages/shared/src/TimedExpectation.ts | 2 +- packages/shared/src/index_browser.ts | 20 ++ packages/shared/src/index_safe.ts | 1 + packages/shared/src/strings.ts | 21 +- packages/shared/src/utils.ts | 2 +- packages/testing/package.json | 4 +- packages/testing/src/MockController.ts | 2 +- packages/zwave-js/package.json | 4 +- .../zwave-js/src/lib/controller/Controller.ts | 10 +- .../src/lib/controller/ZWaveSDKVersions.ts | 4 +- packages/zwave-js/src/lib/controller/utils.ts | 2 +- packages/zwave-js/src/lib/driver/Driver.ts | 8 +- .../zwave-js/src/lib/driver/DriverMock.ts | 2 +- .../src/lib/driver/MessageGenerators.ts | 4 +- .../zwave-js/src/lib/driver/NetworkCache.ts | 2 +- packages/zwave-js/src/lib/driver/Queue.ts | 4 +- .../driver/SerialAPICommandMachine.test.ts | 2 +- packages/zwave-js/src/lib/driver/Task.test.ts | 4 +- packages/zwave-js/src/lib/driver/Task.ts | 6 +- .../zwave-js/src/lib/driver/Transaction.ts | 4 +- .../zwave-js/src/lib/driver/UpdateConfig.ts | 2 +- .../zwave-js/src/lib/driver/mDNSDiscovery.ts | 2 +- packages/zwave-js/src/lib/log/Driver.test.ts | 2 +- packages/zwave-js/src/lib/log/Zniffer.ts | 3 +- packages/zwave-js/src/lib/node/HealthCheck.ts | 7 +- packages/zwave-js/src/lib/node/Node.ts | 15 +- .../src/lib/node/VirtualEndpoint.test.ts | 2 +- .../zwave-js/src/lib/node/VirtualEndpoint.ts | 2 +- packages/zwave-js/src/lib/node/VirtualNode.ts | 2 +- .../src/lib/node/mixins/50_Endpoints.ts | 2 +- .../src/lib/node/mixins/70_FirmwareUpdate.ts | 8 +- .../src/lib/telemetry/deviceConfig.ts | 2 +- .../zwave-js/src/lib/telemetry/statistics.ts | 2 +- .../discardUnsupportedReports.test.ts | 2 +- .../mapNotificationDoorLock.test.ts | 2 +- .../cc-specific/notificationEnums.test.ts | 2 +- .../notificationIdleManually.test.ts | 2 +- .../notificationIdleRelated.test.ts | 2 +- .../cc-specific/undefinedTargetValue.test.ts | 2 +- .../cc-specific/unknownNotifications.test.ts | 2 +- .../compat/notificationAlarmMapping.test.ts | 2 +- .../test/compat/reInterviewWakeUpNIF.test.ts | 2 +- .../test/compliance/decodeLowerS2Keys.test.ts | 2 +- .../discardInsecureCommands.test.ts | 2 +- .../test/driver/bootloaderDetection.test.ts | 2 +- .../lib/test/driver/controllerJammed.test.ts | 2 +- .../createCCValuesUsingKnownVersion.test.ts | 2 +- .../lib/test/driver/handleUnsolicited.test.ts | 2 +- ...noreCCVersion0ForKnownSupportedCCs.test.ts | 2 +- .../lib/test/driver/invalidPayloadLog.test.ts | 2 +- .../multiStageResponseNoTimeout.test.ts | 2 +- .../multicastOptimisticValueUpdate.test.ts | 2 +- .../driver/nodeAsleepBlockNonceReport.test.ts | 2 +- .../driver/nodeAsleepMessageOrder.test.ts | 2 +- .../test/driver/nodeAsleepNoReject.test.ts | 2 +- .../driver/nodeAsleepPingResolves.test.ts | 2 +- .../lib/test/driver/nodeDeadReject.test.ts | 2 +- .../driver/nodeUpdateBeforeCallback.test.ts | 2 +- .../driver/reInterviewAssumeAwake.test.ts | 2 +- .../test/driver/s0AndS2Encapsulation.test.ts | 2 +- .../driver/s0EncapsulationTwoNodes.test.ts | 2 +- .../src/lib/test/driver/s2Collisions.test.ts | 2 +- .../test/driver/sendCommandProgress.test.ts | 2 +- .../sendDataMissingCallbackAbort.test.ts | 2 +- .../driver/sendDataMissingResponse.test.ts | 2 +- .../setValueFailedSupervisionGet.test.ts | 2 +- .../test/driver/setValueNoSupervision.test.ts | 2 +- .../setValueSucceedAfterFailure.test.ts | 2 +- ...setValueSuccessfulSupervisionNoGet.test.ts | 2 +- .../driver/setValueSupervision255Get.test.ts | 2 +- ...ValueSupervisionSuccessMoreUpdates.test.ts | 2 +- .../driver/setValueSupervisionWorking.test.ts | 2 +- .../src/lib/test/driver/unknownValues.test.ts | 2 +- .../lib/test/driver/unresponsiveStick.test.ts | 2 +- .../src/lib/test/integrationTestSuite.ts | 2 +- .../src/lib/test/integrationTestSuiteMulti.ts | 2 +- .../lib/test/node/Node.waitForWakeup.test.ts | 2 +- .../legacyRefreshActuatorSensorCCs.test.ts | 2 +- packages/zwave-js/src/lib/zniffer/MPDU.ts | 6 +- packages/zwave-js/src/lib/zniffer/Zniffer.ts | 2 +- packages/zwave-js/src/mockServer.ts | 2 +- packages/zwave-js/zwave-js.api.md | 6 +- server_config.js | 2 +- test/run.ts | 2 +- test/run_duplex.ts | 2 +- test/run_zniffer.ts | 2 +- yarn.lock | 59 ++-- 197 files changed, 1144 insertions(+), 754 deletions(-) create mode 100644 packages/cc/src/index_browser.ts rename packages/core/src/{capabilities => definitions}/CommandClasses.ts (100%) rename packages/core/src/{capabilities => definitions}/ControllerCapabilities.ts (100%) create mode 100644 packages/core/src/definitions/Frame.ts rename packages/core/src/{capabilities => definitions}/LibraryTypes.ts (100%) rename packages/core/src/{capabilities => definitions}/NodeInfo.test.ts (100%) rename packages/core/src/{capabilities => definitions}/NodeInfo.ts (98%) rename packages/core/src/{capabilities/Protocols.ts => definitions/Protocol.ts} (79%) rename packages/core/src/{capabilities => definitions}/RFRegion.ts (100%) create mode 100644 packages/core/src/definitions/Route.ts rename packages/core/src/{security => definitions}/SecurityClass.ts (67%) rename packages/core/src/{capabilities => definitions}/ZWaveApiVersion.ts (100%) rename packages/core/src/{capabilities => definitions}/ZWaveChipTypes.ts (100%) create mode 100644 packages/core/src/definitions/index.ts rename packages/core/src/{security/DSK.ts => dsk/index.ts} (68%) create mode 100644 packages/core/src/index_browser.ts create mode 100644 packages/core/src/qr/definitions.ts create mode 100644 packages/core/src/qr/index.browser.ts create mode 100644 packages/core/src/qr/index.ts create mode 100644 packages/core/src/qr/parse.browser.ts create mode 100644 packages/core/src/qr/parse.node.ts rename packages/core/src/{security/QR.test.ts => qr/parse.test.ts} (95%) create mode 100644 packages/core/src/qr/utils.ts create mode 100644 packages/core/src/registries/index.ts delete mode 100644 packages/core/src/security/QR.ts delete mode 100644 packages/core/src/security/shared_safe.ts create mode 100644 packages/core/src/traits/SecurityClasses.ts create mode 100644 packages/nvmedit/src/index_browser.ts create mode 100644 packages/shared/src/index_browser.ts diff --git a/maintenance/parse-zwxml-manufacturers.ts b/maintenance/parse-zwxml-manufacturers.ts index 8550dbe18bd2..2b73ec51692e 100644 --- a/maintenance/parse-zwxml-manufacturers.ts +++ b/maintenance/parse-zwxml-manufacturers.ts @@ -1,5 +1,5 @@ import { formatId } from "@zwave-js/shared"; -import { isArray } from "alcalzone-shared/typeguards/index.js"; +import { isArray } from "alcalzone-shared/typeguards"; import fs from "node:fs/promises"; import xml2js from "xml2js"; diff --git a/package.json b/package.json index 2f4d45ab3359..80d36b0a76ba 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "@actions/core": "^1.11.1", "@actions/exec": "^1.1.1", "@actions/github": "^6.0.0", - "@alcalzone/esm2cjs": "^1.2.3", + "@alcalzone/esm2cjs": "^1.3.0", "@alcalzone/jsonl-db": "^3.1.1", "@alcalzone/monopack": "^1.3.0", "@alcalzone/release-script": "~3.8.0", @@ -61,7 +61,7 @@ "@zwave-js/serial": "workspace:*", "@zwave-js/shared": "workspace:*", "@zwave-js/testing": "workspace:*", - "alcalzone-shared": "^4.0.8", + "alcalzone-shared": "^5.0.0", "ansi-colors": "^4.1.3", "chokidar": "^4.0.1", "comment-json": "^4.2.5", diff --git a/packages/cc/package.json b/packages/cc/package.json index 0d22fe9873c1..7b2aca8f7baa 100644 --- a/packages/cc/package.json +++ b/packages/cc/package.json @@ -10,6 +10,7 @@ "exports": { ".": { "@@dev": "./src/index.ts", + "browser": "./build/esm/index_browser.js", "import": "./build/esm/index.js", "require": "./build/cjs/index.js" }, @@ -70,12 +71,12 @@ "@zwave-js/core": "workspace:*", "@zwave-js/host": "workspace:*", "@zwave-js/shared": "workspace:*", - "alcalzone-shared": "^4.0.8", + "alcalzone-shared": "^5.0.0", "ansi-colors": "^4.1.3", "reflect-metadata": "^0.2.2" }, "devDependencies": { - "@alcalzone/esm2cjs": "^1.2.3", + "@alcalzone/esm2cjs": "^1.3.0", "@microsoft/api-extractor": "^7.47.9", "@types/node": "^18.19.63", "@zwave-js/maintenance": "workspace:*", diff --git a/packages/cc/src/cc/AssociationCC.ts b/packages/cc/src/cc/AssociationCC.ts index 57c74eac9e06..7ffbad9f0991 100644 --- a/packages/cc/src/cc/AssociationCC.ts +++ b/packages/cc/src/cc/AssociationCC.ts @@ -22,7 +22,7 @@ import type { } from "@zwave-js/host/safe"; import { Bytes } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; -import { distinct } from "alcalzone-shared/arrays/index.js"; +import { distinct } from "alcalzone-shared/arrays"; import { CCAPI, PhysicalCCAPI } from "../lib/API.js"; import { type CCRaw, diff --git a/packages/cc/src/cc/CentralSceneCC.ts b/packages/cc/src/cc/CentralSceneCC.ts index 24acc89d992f..9e3369d0b2bb 100644 --- a/packages/cc/src/cc/CentralSceneCC.ts +++ b/packages/cc/src/cc/CentralSceneCC.ts @@ -23,7 +23,6 @@ import type { import { Bytes } from "@zwave-js/shared/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; -import { padStart } from "alcalzone-shared/strings/index.js"; import { CCAPI, POLL_VALUE, @@ -80,14 +79,14 @@ export const CentralSceneCCValues = Object.freeze({ ...V.dynamicPropertyAndKeyWithName( "scene", "scene", - (sceneNumber: number) => padStart(sceneNumber.toString(), 3, "0"), + (sceneNumber: number) => sceneNumber.toString().padStart(3, "0"), ({ property, propertyKey }) => property === "scene" && typeof propertyKey === "string" && /^\d{3}$/.test(propertyKey), (sceneNumber: number) => ({ ...ValueMetadata.ReadOnlyUInt8, - label: `Scene ${padStart(sceneNumber.toString(), 3, "0")}`, + label: `Scene ${sceneNumber.toString().padStart(3, "0")}`, } as const), { stateful: false } as const, ), diff --git a/packages/cc/src/cc/ClimateControlScheduleCC.ts b/packages/cc/src/cc/ClimateControlScheduleCC.ts index a7468d110cf3..67a415b513a2 100644 --- a/packages/cc/src/cc/ClimateControlScheduleCC.ts +++ b/packages/cc/src/cc/ClimateControlScheduleCC.ts @@ -18,7 +18,6 @@ import type { import { Bytes } from "@zwave-js/shared/safe"; import { getEnumMemberName } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; -import { padStart } from "alcalzone-shared/strings/index.js"; import { CCAPI } from "../lib/API.js"; import { type CCRaw, CommandClass } from "../lib/CommandClass.js"; import { @@ -274,9 +273,8 @@ export class ClimateControlScheduleCCSet extends ClimateControlScheduleCC { this.switchPoints .map( (sp) => ` -· ${padStart(sp.hour.toString(), 2, "0")}:${ - padStart( - sp.minute.toString(), +· ${sp.hour.toString().padStart(2, "0")}:${ + sp.minute.toString().padStart( 2, "0", ) @@ -349,9 +347,8 @@ export class ClimateControlScheduleCCReport extends ClimateControlScheduleCC { this.schedule .map( (sp) => ` -· ${padStart(sp.hour.toString(), 2, "0")}:${ - padStart( - sp.minute.toString(), +· ${sp.hour.toString().padStart(2, "0")}:${ + sp.minute.toString().padStart( 2, "0", ) diff --git a/packages/cc/src/cc/ClockCC.ts b/packages/cc/src/cc/ClockCC.ts index 0e548737d2b9..d97406917e31 100644 --- a/packages/cc/src/cc/ClockCC.ts +++ b/packages/cc/src/cc/ClockCC.ts @@ -19,7 +19,6 @@ import type { import { Bytes } from "@zwave-js/shared/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; -import { padStart } from "alcalzone-shared/strings/index.js"; import { CCAPI } from "../lib/API.js"; import { type CCRaw, @@ -195,9 +194,8 @@ export class ClockCCSet extends ClockCC { Weekday, this.weekday, ) - }, ${padStart(this.hour.toString(), 2, "0")}:${ - padStart( - this.minute.toString(), + }, ${this.hour.toString().padStart(2, "0")}:${ + this.minute.toString().padStart( 2, "0", ) @@ -259,9 +257,8 @@ export class ClockCCReport extends ClockCC { Weekday, this.weekday, ) - }, ${padStart(this.hour.toString(), 2, "0")}:${ - padStart( - this.minute.toString(), + }, ${this.hour.toString().padStart(2, "0")}:${ + this.minute.toString().padStart( 2, "0", ) diff --git a/packages/cc/src/cc/ColorSwitchCC.ts b/packages/cc/src/cc/ColorSwitchCC.ts index d3e8678ea4c5..c49618d12c73 100644 --- a/packages/cc/src/cc/ColorSwitchCC.ts +++ b/packages/cc/src/cc/ColorSwitchCC.ts @@ -30,8 +30,8 @@ import { pick, } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; -import { clamp } from "alcalzone-shared/math/index.js"; -import { isObject } from "alcalzone-shared/typeguards/index.js"; +import { clamp } from "alcalzone-shared/math"; +import { isObject } from "alcalzone-shared/typeguards"; import { CCAPI, POLL_VALUE, diff --git a/packages/cc/src/cc/ConfigurationCC.ts b/packages/cc/src/cc/ConfigurationCC.ts index b8856e87691f..4b2105e44839 100644 --- a/packages/cc/src/cc/ConfigurationCC.ts +++ b/packages/cc/src/cc/ConfigurationCC.ts @@ -41,9 +41,7 @@ import type { import { Bytes } from "@zwave-js/shared/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; -import { distinct } from "alcalzone-shared/arrays/index.js"; -import { composeObject } from "alcalzone-shared/objects/index.js"; -import { padStart } from "alcalzone-shared/strings/index.js"; +import { distinct } from "alcalzone-shared/arrays"; import { CCAPI, type CCAPIEndpoint, @@ -1409,7 +1407,7 @@ alters capabilities: ${!!properties.altersCapabilities}`; .map((v) => v.property) .filter((p) => typeof p === "number"), ); - return composeObject( + return Object.fromEntries( parameters.map((p) => [ p as any, this.getParamInformation(ctx, p), @@ -1532,7 +1530,7 @@ alters capabilities: ${!!properties.altersCapabilities}`; writeable: !info.readOnly, allowManualEntry: info.allowManualEntry, states: info.options.length > 0 - ? composeObject( + ? Object.fromEntries( info.options.map(({ label, value }) => [ value.toString(), label, @@ -1592,7 +1590,7 @@ alters capabilities: ${!!properties.altersCapabilities}`; ); if (paramInfo.label) return paramInfo.label; // fall back to paramXYZ[_key] if none is defined - let ret = `param${padStart(property.toString(), 3, "0")}`; + let ret = `param${property.toString().padStart(3, "0")}`; if (propertyKey != undefined) { ret += "_" + propertyKey.toString(); } diff --git a/packages/cc/src/cc/DoorLockCC.ts b/packages/cc/src/cc/DoorLockCC.ts index f72b52fb0c18..eba0aa3fab1f 100644 --- a/packages/cc/src/cc/DoorLockCC.ts +++ b/packages/cc/src/cc/DoorLockCC.ts @@ -24,7 +24,7 @@ import type { import { Bytes } from "@zwave-js/shared/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; -import { isArray } from "alcalzone-shared/typeguards/index.js"; +import { isArray } from "alcalzone-shared/typeguards"; import { CCAPI, POLL_VALUE, diff --git a/packages/cc/src/cc/IndicatorCC.ts b/packages/cc/src/cc/IndicatorCC.ts index e2faf6420aab..96f26eeced1f 100644 --- a/packages/cc/src/cc/IndicatorCC.ts +++ b/packages/cc/src/cc/IndicatorCC.ts @@ -24,8 +24,8 @@ import type { import { Bytes } from "@zwave-js/shared/safe"; import { num2hex } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; -import { clamp, roundTo } from "alcalzone-shared/math/index.js"; -import { isArray } from "alcalzone-shared/typeguards/index.js"; +import { clamp, roundTo } from "alcalzone-shared/math"; +import { isArray } from "alcalzone-shared/typeguards"; import { CCAPI, POLL_VALUE, diff --git a/packages/cc/src/cc/IrrigationCC.ts b/packages/cc/src/cc/IrrigationCC.ts index 4ff559ef9aca..eae76cca39d4 100644 --- a/packages/cc/src/cc/IrrigationCC.ts +++ b/packages/cc/src/cc/IrrigationCC.ts @@ -24,7 +24,6 @@ import type { import { Bytes } from "@zwave-js/shared/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; -import { padStart } from "alcalzone-shared/strings/index.js"; import { CCAPI, POLL_VALUE, @@ -555,7 +554,7 @@ export const IrrigationCCValues = Object.freeze({ function valveIdToMetadataPrefix(valveId: ValveId): string { if (valveId === "master") return "Master valve"; - return `Valve ${padStart(valveId.toString(), 3, "0")}`; + return `Valve ${valveId.toString().padStart(3, "0")}`; } const systemConfigProperties = [ @@ -1309,8 +1308,7 @@ moisture sensor polarity: ${ ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Querying configuration for valve ${ - padStart( - i.toString(), + i.toString().padStart( 3, "0", ) @@ -1322,8 +1320,7 @@ moisture sensor polarity: ${ ctx.logNode(node.id, { endpoint: this.endpointIndex, message: `Querying status for valve ${ - padStart( - i.toString(), + i.toString().padStart( 3, "0", ) @@ -1342,7 +1339,7 @@ moisture sensor polarity: ${ if (property === "master") { return "Master valve"; } else if (typeof property === "number") { - return `Valve ${padStart(property.toString(), 3, "0")}`; + return `Valve ${property.toString().padStart(3, "0")}`; } return super.translateProperty(ctx, property, propertyKey); } @@ -2522,7 +2519,7 @@ export class IrrigationCCValveTableSet extends IrrigationCC { }; for (let i = 0; i < this.entries.length; i++) { const entry = this.entries[i]; - const valveLabel = padStart(entry.valveId.toString(), 3, "0"); + const valveLabel = entry.valveId.toString().padStart(3, "0"); if (entry.duration) { message[`valve ${valveLabel} duration`] = `${entry.duration} s`; } else { @@ -2584,7 +2581,7 @@ export class IrrigationCCValveTableReport extends IrrigationCC { }; for (let i = 0; i < this.entries.length; i++) { const entry = this.entries[i]; - const valveLabel = padStart(entry.valveId.toString(), 3, "0"); + const valveLabel = entry.valveId.toString().padStart(3, "0"); if (entry.duration) { message[`valve ${valveLabel} duration`] = `${entry.duration} s`; } else { @@ -2703,7 +2700,7 @@ export class IrrigationCCValveTableRun extends IrrigationCC { ...super.toLogEntry(ctx), message: { "table IDs": this.tableIDs - .map((id) => padStart(id.toString(), 3, "0")) + .map((id) => id.toString().padStart(3, "0")) .join(", "), }, }; diff --git a/packages/cc/src/cc/MultiChannelCC.ts b/packages/cc/src/cc/MultiChannelCC.ts index 3bbedd773fd0..8636eb0cfc92 100644 --- a/packages/cc/src/cc/MultiChannelCC.ts +++ b/packages/cc/src/cc/MultiChannelCC.ts @@ -26,7 +26,7 @@ import type { } from "@zwave-js/host/safe"; import { Bytes } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; -import { distinct } from "alcalzone-shared/arrays/index.js"; +import { distinct } from "alcalzone-shared/arrays"; import { CCAPI } from "../lib/API.js"; import { type CCRaw, diff --git a/packages/cc/src/cc/NotificationCC.ts b/packages/cc/src/cc/NotificationCC.ts index c419b9aeab6b..319bca43fbc3 100644 --- a/packages/cc/src/cc/NotificationCC.ts +++ b/packages/cc/src/cc/NotificationCC.ts @@ -48,7 +48,7 @@ import type { import { Bytes, isUint8Array } from "@zwave-js/shared/safe"; import { buffer2hex, num2hex, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; -import { isArray } from "alcalzone-shared/typeguards/index.js"; +import { isArray } from "alcalzone-shared/typeguards"; import { CCAPI, POLL_VALUE, diff --git a/packages/cc/src/cc/ProtectionCC.ts b/packages/cc/src/cc/ProtectionCC.ts index bb60816d483a..761266dc1e0e 100644 --- a/packages/cc/src/cc/ProtectionCC.ts +++ b/packages/cc/src/cc/ProtectionCC.ts @@ -23,7 +23,6 @@ import type { import { Bytes } from "@zwave-js/shared/safe"; import { getEnumMemberName, pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; -import { padStart } from "alcalzone-shared/strings/index.js"; import { CCAPI, POLL_VALUE, @@ -490,7 +489,7 @@ rf ${getEnumMemberName(RFProtectionState, protectionResp.rf)}`; if (nodeId != undefined) { ctx.logNode(node.id, { message: (nodeId !== 0 - ? `Node ${padStart(nodeId.toString(), 3, "0")}` + ? `Node ${nodeId.toString().padStart(3, "0")}` : `no node`) + ` has exclusive control`, direction: "inbound", }); diff --git a/packages/cc/src/cc/Security2CC.ts b/packages/cc/src/cc/Security2CC.ts index 43b5445c5dae..7f59f745cb18 100644 --- a/packages/cc/src/cc/Security2CC.ts +++ b/packages/cc/src/cc/Security2CC.ts @@ -44,8 +44,8 @@ import type { } from "@zwave-js/host/safe"; import { Bytes } from "@zwave-js/shared/safe"; import { buffer2hex, getEnumMemberName, pick } from "@zwave-js/shared/safe"; -import { wait } from "alcalzone-shared/async/index.js"; -import { isArray } from "alcalzone-shared/typeguards/index.js"; +import { wait } from "alcalzone-shared/async"; +import { isArray } from "alcalzone-shared/typeguards"; import { CCAPI } from "../lib/API.js"; import { type CCRaw, diff --git a/packages/cc/src/cc/SecurityCC.ts b/packages/cc/src/cc/SecurityCC.ts index d1222cb5f707..f934a71abdcf 100644 --- a/packages/cc/src/cc/SecurityCC.ts +++ b/packages/cc/src/cc/SecurityCC.ts @@ -29,7 +29,7 @@ import type { } from "@zwave-js/host/safe"; import { Bytes } from "@zwave-js/shared/safe"; import { buffer2hex, num2hex, pick } from "@zwave-js/shared/safe"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { randomBytes } from "node:crypto"; import { CCAPI, PhysicalCCAPI } from "../lib/API.js"; import { diff --git a/packages/cc/src/cc/SoundSwitchCC.ts b/packages/cc/src/cc/SoundSwitchCC.ts index e1249810941c..b2b9cc817122 100644 --- a/packages/cc/src/cc/SoundSwitchCC.ts +++ b/packages/cc/src/cc/SoundSwitchCC.ts @@ -20,7 +20,7 @@ import type { import { Bytes } from "@zwave-js/shared/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; -import { clamp } from "alcalzone-shared/math/index.js"; +import { clamp } from "alcalzone-shared/math"; import { CCAPI, POLL_VALUE, diff --git a/packages/cc/src/cc/TimeCC.ts b/packages/cc/src/cc/TimeCC.ts index e457f651bf44..7df07a2ca082 100644 --- a/packages/cc/src/cc/TimeCC.ts +++ b/packages/cc/src/cc/TimeCC.ts @@ -20,7 +20,6 @@ import type { import { Bytes } from "@zwave-js/shared/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; -import { padStart } from "alcalzone-shared/strings/index.js"; import { CCAPI } from "../lib/API.js"; import { type CCRaw, @@ -286,13 +285,9 @@ export class TimeCCTimeReport extends TimeCC { return { ...super.toLogEntry(ctx), message: { - time: `${padStart(this.hour.toString(), 2, "0")}:${ - padStart( - this.minute.toString(), - 2, - "0", - ) - }:${padStart(this.second.toString(), 2, "0")}`, + time: `${this.hour.toString().padStart(2, "0")}:${ + this.minute.toString().padStart(2, "0") + }:${this.second.toString().padStart(2, "0")}`, }, }; } @@ -354,13 +349,9 @@ export class TimeCCDateReport extends TimeCC { return { ...super.toLogEntry(ctx), message: { - date: `${padStart(this.year.toString(), 4, "0")}-${ - padStart( - this.month.toString(), - 2, - "0", - ) - }-${padStart(this.day.toString(), 2, "0")}`, + date: `${this.year.toString().padStart(4, "0")}-${ + this.month.toString().padStart(2, "0") + }-${this.day.toString().padStart(2, "0")}`, }, }; } diff --git a/packages/cc/src/cc/WakeUpCC.ts b/packages/cc/src/cc/WakeUpCC.ts index 60c395bd7238..5ba9f26874fa 100644 --- a/packages/cc/src/cc/WakeUpCC.ts +++ b/packages/cc/src/cc/WakeUpCC.ts @@ -18,7 +18,7 @@ import type { import { Bytes } from "@zwave-js/shared/safe"; import { pick } from "@zwave-js/shared/safe"; import { validateArgs } from "@zwave-js/transformers"; -import { clamp } from "alcalzone-shared/math/index.js"; +import { clamp } from "alcalzone-shared/math"; import { CCAPI, POLL_VALUE, diff --git a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts index ba71c278415b..b39fec59fbf8 100644 --- a/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts +++ b/packages/cc/src/cc/manufacturerProprietary/FibaroCC.ts @@ -19,7 +19,7 @@ import type { } from "@zwave-js/host/safe"; import { Bytes, pick } from "@zwave-js/shared"; import { validateArgs } from "@zwave-js/transformers"; -import { isArray } from "alcalzone-shared/typeguards/index.js"; +import { isArray } from "alcalzone-shared/typeguards"; import { POLL_VALUE, type PollValueImplementation, diff --git a/packages/cc/src/index_browser.ts b/packages/cc/src/index_browser.ts new file mode 100644 index 000000000000..398670eef329 --- /dev/null +++ b/packages/cc/src/index_browser.ts @@ -0,0 +1,13 @@ +/* @forbiddenImports external */ + +export * from "./lib/Security2/shared.js"; +export * from "./lib/SetValueResult.js"; +export * from "./lib/SetValueResult.js"; +export { defaultCCValueOptions } from "./lib/Values.js"; +export type { + CCValueOptions, + CCValuePredicate, + PartialCCValuePredicate, +} from "./lib/Values.js"; +export * from "./lib/_Types.js"; +export * from "./lib/_Types.js"; diff --git a/packages/cc/src/lib/API.ts b/packages/cc/src/lib/API.ts index e746573dc605..6debd7c0b307 100644 --- a/packages/cc/src/lib/API.ts +++ b/packages/cc/src/lib/API.ts @@ -47,7 +47,7 @@ import { getErrorMessage, num2hex, } from "@zwave-js/shared"; -import { isArray } from "alcalzone-shared/typeguards/index.js"; +import { isArray } from "alcalzone-shared/typeguards"; import { getAPI, getCCValues, diff --git a/packages/cc/src/lib/CommandClass.ts b/packages/cc/src/lib/CommandClass.ts index 561e6af5c441..f17a803c32ee 100644 --- a/packages/cc/src/lib/CommandClass.ts +++ b/packages/cc/src/lib/CommandClass.ts @@ -54,7 +54,7 @@ import { num2hex, staticExtends, } from "@zwave-js/shared"; -import { isArray } from "alcalzone-shared/typeguards/index.js"; +import { isArray } from "alcalzone-shared/typeguards"; import type { CCAPIHost, CCAPINode, ValueIDProperties } from "./API.js"; import { getCCCommand, diff --git a/packages/cc/src/lib/EncapsulatingCommandClass.ts b/packages/cc/src/lib/EncapsulatingCommandClass.ts index 605ad22bbb82..b15963e6c38d 100644 --- a/packages/cc/src/lib/EncapsulatingCommandClass.ts +++ b/packages/cc/src/lib/EncapsulatingCommandClass.ts @@ -1,4 +1,4 @@ -import { isArray } from "alcalzone-shared/typeguards/index.js"; +import { isArray } from "alcalzone-shared/typeguards"; import { CommandClass } from "./CommandClass.js"; export type EncapsulatedCommandClass = CommandClass & { diff --git a/packages/cc/src/lib/Values.ts b/packages/cc/src/lib/Values.ts index af6da87eeb60..cd1f491e8b0f 100644 --- a/packages/cc/src/lib/Values.ts +++ b/packages/cc/src/lib/Values.ts @@ -3,14 +3,14 @@ import { type EndpointId, type ValueID, ValueMetadata, -} from "@zwave-js/core"; +} from "@zwave-js/core/safe"; import type { GetDeviceConfig, GetValueDB } from "@zwave-js/host"; import { type FnOrStatic, type ReturnTypeOrStatic, evalOrStatic, } from "@zwave-js/shared/safe"; -import type { Overwrite } from "alcalzone-shared/types/index.js"; +import type { Overwrite } from "alcalzone-shared/types"; import type { ValueIDProperties } from "./API.js"; // HINT: To fully view types for definitions created by this, open diff --git a/packages/cc/src/lib/serializers.ts b/packages/cc/src/lib/serializers.ts index b94ce9e42233..17d5296887da 100644 --- a/packages/cc/src/lib/serializers.ts +++ b/packages/cc/src/lib/serializers.ts @@ -1,6 +1,6 @@ import { ZWaveError, ZWaveErrorCodes } from "@zwave-js/core"; import { Bytes } from "@zwave-js/shared/safe"; -import { clamp } from "alcalzone-shared/math/index.js"; +import { clamp } from "alcalzone-shared/math"; import type { SetbackSpecialState, SetbackState, diff --git a/packages/cc/src/lib/utils.ts b/packages/cc/src/lib/utils.ts index 593529b68b0a..55ac2b450a7f 100644 --- a/packages/cc/src/lib/utils.ts +++ b/packages/cc/src/lib/utils.ts @@ -30,7 +30,7 @@ import { type ReadonlyObjectKeyMap, getEnumMemberName, } from "@zwave-js/shared/safe"; -import { distinct } from "alcalzone-shared/arrays/index.js"; +import { distinct } from "alcalzone-shared/arrays"; import { AssociationCC, AssociationCCValues } from "../cc/AssociationCC.js"; import { AssociationGroupInfoCC } from "../cc/AssociationGroupInfoCC.js"; import { MultiChannelAssociationCC } from "../cc/MultiChannelAssociationCC.js"; diff --git a/packages/config/maintenance/importConfig.ts b/packages/config/maintenance/importConfig.ts index e187f105ad30..c6a8be9eb010 100644 --- a/packages/config/maintenance/importConfig.ts +++ b/packages/config/maintenance/importConfig.ts @@ -18,8 +18,7 @@ import { readJSON, stringify, } from "@zwave-js/shared"; -import { composeObject } from "alcalzone-shared/objects/index.js"; -import { isArray, isObject } from "alcalzone-shared/typeguards/index.js"; +import { isArray, isObject } from "alcalzone-shared/typeguards"; import * as JSONC from "comment-json"; import * as JSON5 from "json5"; import { AssertionError, ok } from "node:assert"; @@ -31,11 +30,14 @@ import { compare } from "semver"; import xml2js from "xml2js"; import xml2js_parsers from "xml2js/lib/processors.js"; import yargs from "yargs"; -import { ConfigManager, type DeviceConfigIndexEntry } from "../src"; +import { hideBin } from "yargs/helpers"; +import { ConfigManager } from "../src/ConfigManager.js"; +import { DeviceConfigIndexEntry } from "../src/devices/DeviceConfig.js"; const execPromise = promisify(child.exec); +const yargsInstance = yargs(hideBin(process.argv)); -const program = yargs +const program = yargsInstance .option("source", { description: "source of the import", alias: "s", @@ -1815,7 +1817,7 @@ async function downloadManufacturersOH(): Promise { // Delete the last line process.stdout.write("\r\x1b[K"); - const manufacturers = composeObject( + const manufacturers = Object.fromEntries( // @ts-expect-error data.manufacturers.data.map(({ id, label }) => [ label diff --git a/packages/config/maintenance/lintConfigFiles.ts b/packages/config/maintenance/lintConfigFiles.ts index 9cbc5f644575..ff4090e43851 100644 --- a/packages/config/maintenance/lintConfigFiles.ts +++ b/packages/config/maintenance/lintConfigFiles.ts @@ -11,9 +11,9 @@ import { getErrorMessage, num2hex, } from "@zwave-js/shared"; -import { distinct } from "alcalzone-shared/arrays/index.js"; -import { wait } from "alcalzone-shared/async/index.js"; -import { isArray, isObject } from "alcalzone-shared/typeguards/index.js"; +import { distinct } from "alcalzone-shared/arrays"; +import { wait } from "alcalzone-shared/async"; +import { isArray, isObject } from "alcalzone-shared/typeguards"; import c from "ansi-colors"; import esMain from "es-main"; import levenshtein from "js-levenshtein"; diff --git a/packages/config/package.json b/packages/config/package.json index 4e6e263ad112..236d881f454c 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -60,7 +60,7 @@ "dependencies": { "@zwave-js/core": "workspace:*", "@zwave-js/shared": "workspace:*", - "alcalzone-shared": "^4.0.8", + "alcalzone-shared": "^5.0.0", "ansi-colors": "^4.1.3", "json-logic-js": "^2.0.5", "json5": "^2.2.3", @@ -68,7 +68,7 @@ "winston": "^3.15.0" }, "devDependencies": { - "@alcalzone/esm2cjs": "^1.2.3", + "@alcalzone/esm2cjs": "^1.3.0", "@microsoft/api-extractor": "^7.47.9", "@types/js-levenshtein": "^1.1.3", "@types/json-logic-js": "^2.0.7", diff --git a/packages/config/src/JsonTemplate.ts b/packages/config/src/JsonTemplate.ts index 2768a499936b..1e42244415d5 100644 --- a/packages/config/src/JsonTemplate.ts +++ b/packages/config/src/JsonTemplate.ts @@ -1,7 +1,7 @@ import { ZWaveError, ZWaveErrorCodes } from "@zwave-js/core/safe"; import { pathExists } from "@zwave-js/shared"; import { getErrorMessage } from "@zwave-js/shared/safe"; -import { isArray, isObject } from "alcalzone-shared/typeguards/index.js"; +import { isArray, isObject } from "alcalzone-shared/typeguards"; import JSON5 from "json5"; import fs from "node:fs/promises"; import * as path from "node:path"; @@ -91,12 +91,12 @@ function select( for (const part of selectorParts) { // Special case for paramInformation selectors to select params by # if (isArray(ret)) { - const item = ret.find( - (r) => isObject(r) && "#" in r && r["#"] === part, + const item = (ret as any).find( + (r: any) => isObject(r) && "#" in r && r["#"] === part, ); if (item != undefined) { // Don't copy the param number - const { ["#"]: _, ...rest } = item as any; + const { ["#"]: _, ...rest } = item; ret = rest; continue; } diff --git a/packages/config/src/Manufacturers.ts b/packages/config/src/Manufacturers.ts index f340ec7ab1dd..de7a516fb0da 100644 --- a/packages/config/src/Manufacturers.ts +++ b/packages/config/src/Manufacturers.ts @@ -1,6 +1,6 @@ import { ZWaveError, ZWaveErrorCodes, isZWaveError } from "@zwave-js/core"; import { formatId, pathExists, stringify } from "@zwave-js/shared"; -import { isObject } from "alcalzone-shared/typeguards/index.js"; +import { isObject } from "alcalzone-shared/typeguards"; import JSON5 from "json5"; import fs from "node:fs/promises"; import path from "node:path"; diff --git a/packages/config/src/devices/CompatConfig.ts b/packages/config/src/devices/CompatConfig.ts index c2b3dae88a80..936e160ccda0 100644 --- a/packages/config/src/devices/CompatConfig.ts +++ b/packages/config/src/devices/CompatConfig.ts @@ -6,7 +6,7 @@ import { stripUndefined, } from "@zwave-js/core/safe"; import { type JSONObject, pick } from "@zwave-js/shared/safe"; -import { isArray, isObject } from "alcalzone-shared/typeguards/index.js"; +import { isArray, isObject } from "alcalzone-shared/typeguards"; import { throwInvalidConfig, tryParseCCId } from "../utils_safe.js"; import { type ConditionalItem, conditionApplies } from "./ConditionalItem.js"; import type { DeviceID } from "./shared.js"; diff --git a/packages/config/src/devices/ConditionalDeviceConfig.test.ts b/packages/config/src/devices/ConditionalDeviceConfig.test.ts index dc5828c02b97..1ec1ef24b267 100644 --- a/packages/config/src/devices/ConditionalDeviceConfig.test.ts +++ b/packages/config/src/devices/ConditionalDeviceConfig.test.ts @@ -1,4 +1,4 @@ -import { isArray } from "alcalzone-shared/typeguards/index.js"; +import { isArray } from "alcalzone-shared/typeguards"; import { test } from "vitest"; import { ConditionalDeviceConfig } from "./DeviceConfig.js"; diff --git a/packages/config/src/devices/ConditionalItem.ts b/packages/config/src/devices/ConditionalItem.ts index 873bfe884afb..b17b9beeec5e 100644 --- a/packages/config/src/devices/ConditionalItem.ts +++ b/packages/config/src/devices/ConditionalItem.ts @@ -1,6 +1,6 @@ import { ZWaveError, ZWaveErrorCodes } from "@zwave-js/core/safe"; import { ObjectKeyMap } from "@zwave-js/shared/safe"; -import { isArray } from "alcalzone-shared/typeguards/index.js"; +import { isArray } from "alcalzone-shared/typeguards"; import { evaluate } from "../Logic.js"; import { throwInvalidConfig } from "../utils_safe.js"; import type { DeviceID } from "./shared.js"; diff --git a/packages/config/src/devices/ConditionalPrimitive.ts b/packages/config/src/devices/ConditionalPrimitive.ts index 3e573bec92a5..8e27c192268b 100644 --- a/packages/config/src/devices/ConditionalPrimitive.ts +++ b/packages/config/src/devices/ConditionalPrimitive.ts @@ -1,4 +1,4 @@ -import { isArray, isObject } from "alcalzone-shared/typeguards/index.js"; +import { isArray, isObject } from "alcalzone-shared/typeguards"; import { throwInvalidConfig } from "../utils_safe.js"; import { type ConditionalItem, conditionApplies } from "./ConditionalItem.js"; import type { DeviceID } from "./shared.js"; diff --git a/packages/config/src/devices/DeviceConfig.ts b/packages/config/src/devices/DeviceConfig.ts index 297dc771021d..0778eb72b75e 100644 --- a/packages/config/src/devices/DeviceConfig.ts +++ b/packages/config/src/devices/DeviceConfig.ts @@ -10,7 +10,7 @@ import { pick, stringify, } from "@zwave-js/shared"; -import { isArray, isObject } from "alcalzone-shared/typeguards/index.js"; +import { isArray, isObject } from "alcalzone-shared/typeguards"; import JSON5 from "json5"; import { createHash } from "node:crypto"; import fs from "node:fs/promises"; diff --git a/packages/config/src/devices/DeviceMetadata.ts b/packages/config/src/devices/DeviceMetadata.ts index b70fdf9f6a1b..aead20da3673 100644 --- a/packages/config/src/devices/DeviceMetadata.ts +++ b/packages/config/src/devices/DeviceMetadata.ts @@ -1,5 +1,5 @@ import { type JSONObject, pick } from "@zwave-js/shared/safe"; -import { isArray, isObject } from "alcalzone-shared/typeguards/index.js"; +import { isArray, isObject } from "alcalzone-shared/typeguards"; import { throwInvalidConfig } from "../utils_safe.js"; import { type ConditionalItem, diff --git a/packages/config/src/devices/EndpointConfig.ts b/packages/config/src/devices/EndpointConfig.ts index 3796c955d315..70a2885dfe75 100644 --- a/packages/config/src/devices/EndpointConfig.ts +++ b/packages/config/src/devices/EndpointConfig.ts @@ -1,5 +1,5 @@ import type { JSONObject } from "@zwave-js/shared/safe"; -import { isObject } from "alcalzone-shared/typeguards/index.js"; +import { isObject } from "alcalzone-shared/typeguards"; import { throwInvalidConfig } from "../utils_safe.js"; import { type AssociationConfig, diff --git a/packages/config/src/devices/ParamInformation.ts b/packages/config/src/devices/ParamInformation.ts index 57f5c9aa5d8b..986cbb71eb30 100644 --- a/packages/config/src/devices/ParamInformation.ts +++ b/packages/config/src/devices/ParamInformation.ts @@ -5,7 +5,7 @@ import { type ReadonlyObjectKeyMap, pick, } from "@zwave-js/shared/safe"; -import { isArray, isObject } from "alcalzone-shared/typeguards/index.js"; +import { isArray, isObject } from "alcalzone-shared/typeguards"; import { throwInvalidConfig } from "../utils_safe.js"; import { type ConditionalItem, diff --git a/packages/core/package.json b/packages/core/package.json index 7146cbc371a5..4ea5afef47a6 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -10,6 +10,7 @@ "exports": { ".": { "@@dev": "./src/index.ts", + "browser": "./build/esm/index_browser.js", "import": "./build/esm/index.js", "require": "./build/cjs/index.js" }, @@ -23,8 +24,37 @@ "import": "./build/esm/index_test.js", "require": "./build/cjs/index_test.js" }, + "./definitions": { + "@@dev": "./src/definitions/index.ts", + "import": "./build/esm/definitions/index.js", + "require": "./build/cjs/definitions/index.js" + }, + "./dsk": { + "@@dev": "./src/dsk/index.ts", + "import": "./build/esm/dsk/index.js", + "require": "./build/cjs/dsk/index.js" + }, + "./error": { + "@@dev": "./src/error/ZWaveError.ts", + "import": "./build/esm/error/ZWaveError.js", + "require": "./build/cjs/error/ZWaveError.js" + }, + "./registries": { + "@@dev": "./src/registries/index.ts", + "import": "./build/esm/registries/index.js", + "require": "./build/cjs/registries/index.js" + }, + "./qr": { + "@@dev": "./src/qr/index.ts", + "browser": "./build/esm/qr/index.browser.js", + "import": "./build/esm/qr/index.js", + "require": "./build/cjs/qr/index.js" + }, "./package.json": "./package.json" }, + "sideEffects": [ + "./util/decorators.js" + ], "files": [ "build/**/*.{js,cjs,mjs,d.ts,d.cts,d.mts,map}", "build/**/package.json" @@ -61,7 +91,7 @@ "dependencies": { "@alcalzone/jsonl-db": "^3.1.1", "@zwave-js/shared": "workspace:*", - "alcalzone-shared": "^4.0.8", + "alcalzone-shared": "^5.0.0", "ansi-colors": "^4.1.3", "dayjs": "^1.11.13", "logform": "^2.6.1", @@ -74,7 +104,7 @@ "winston-transport": "^4.8.0" }, "devDependencies": { - "@alcalzone/esm2cjs": "^1.2.3", + "@alcalzone/esm2cjs": "^1.3.0", "@microsoft/api-extractor": "^7.47.9", "@types/node": "^18.19.63", "@types/semver": "^7.5.8", diff --git a/packages/core/src/consts/Transmission.ts b/packages/core/src/consts/Transmission.ts index d7a50f43db36..821cd96163b1 100644 --- a/packages/core/src/consts/Transmission.ts +++ b/packages/core/src/consts/Transmission.ts @@ -1,7 +1,7 @@ import { num2hex } from "@zwave-js/shared/safe"; -import { isObject } from "alcalzone-shared/typeguards/index.js"; -import type { ProtocolDataRate } from "../capabilities/Protocols.js"; -import { type SecurityClass } from "../security/SecurityClass.js"; +import { isObject } from "alcalzone-shared/typeguards"; +import type { ProtocolDataRate } from "../definitions/Protocol.js"; +import { type SecurityClass } from "../definitions/SecurityClass.js"; import type { CCId } from "../traits/CommandClasses.js"; import { Duration } from "../values/Duration.js"; diff --git a/packages/core/src/capabilities/CommandClasses.ts b/packages/core/src/definitions/CommandClasses.ts similarity index 100% rename from packages/core/src/capabilities/CommandClasses.ts rename to packages/core/src/definitions/CommandClasses.ts diff --git a/packages/core/src/capabilities/ControllerCapabilities.ts b/packages/core/src/definitions/ControllerCapabilities.ts similarity index 100% rename from packages/core/src/capabilities/ControllerCapabilities.ts rename to packages/core/src/definitions/ControllerCapabilities.ts diff --git a/packages/core/src/definitions/Frame.ts b/packages/core/src/definitions/Frame.ts new file mode 100644 index 000000000000..8d4dc1750540 --- /dev/null +++ b/packages/core/src/definitions/Frame.ts @@ -0,0 +1,14 @@ +export enum MPDUHeaderType { + Singlecast = 0x1, + Multicast = 0x2, + Acknowledgement = 0x3, + Explorer = 0x5, + Routed = 0x8, +} + +export enum BeamingInfo { + None = 0b00, + ShortContinuous = 0b01, + LongContinuous = 0b10, + Fragmented = 0b100, +} diff --git a/packages/core/src/capabilities/LibraryTypes.ts b/packages/core/src/definitions/LibraryTypes.ts similarity index 100% rename from packages/core/src/capabilities/LibraryTypes.ts rename to packages/core/src/definitions/LibraryTypes.ts diff --git a/packages/core/src/capabilities/NodeInfo.test.ts b/packages/core/src/definitions/NodeInfo.test.ts similarity index 100% rename from packages/core/src/capabilities/NodeInfo.test.ts rename to packages/core/src/definitions/NodeInfo.test.ts diff --git a/packages/core/src/capabilities/NodeInfo.ts b/packages/core/src/definitions/NodeInfo.ts similarity index 98% rename from packages/core/src/capabilities/NodeInfo.ts rename to packages/core/src/definitions/NodeInfo.ts index 82ab7d8f3c13..81eb6d454eda 100644 --- a/packages/core/src/capabilities/NodeInfo.ts +++ b/packages/core/src/definitions/NodeInfo.ts @@ -1,9 +1,10 @@ import { Bytes } from "@zwave-js/shared/safe"; import { sum } from "@zwave-js/shared/safe"; import { NodeIDType } from "../consts/index.js"; -import { type BasicDeviceClass } from "../index_safe.js"; +import { type BasicDeviceClass } from "../registries/DeviceClasses.js"; import { validatePayload } from "../util/misc.js"; import { CommandClasses } from "./CommandClasses.js"; +import { type ProtocolVersion } from "./Protocol.js"; export interface ApplicationNodeInformation { genericDeviceClass: number; @@ -77,7 +78,7 @@ export function encodeNodeUpdatePayload( ]); } -export function isExtendedCCId(ccId: CommandClasses): boolean { +function isExtendedCCId(ccId: CommandClasses): boolean { return ccId >= 0xf1; } @@ -166,13 +167,6 @@ export function encodeCCList( return ret; } -export enum ProtocolVersion { - "unknown" = 0, - "2.0" = 1, - "4.2x / 5.0x" = 2, - "4.5x / 6.0x" = 3, -} - export type FLiRS = false | "250ms" | "1000ms"; export type DataRate = 9600 | 40000 | 100000; diff --git a/packages/core/src/capabilities/Protocols.ts b/packages/core/src/definitions/Protocol.ts similarity index 79% rename from packages/core/src/capabilities/Protocols.ts rename to packages/core/src/definitions/Protocol.ts index 5b49c958727e..636de1f59f77 100644 --- a/packages/core/src/capabilities/Protocols.ts +++ b/packages/core/src/definitions/Protocol.ts @@ -103,33 +103,6 @@ export enum ProtocolType { "Z-Wave for IP" = 2, } -export enum RouteKind { - None = 0x00, - /** Last Working Route */ - LWR = 0x01, - /** Next to Last Working Route */ - NLWR = 0x02, - /** Application-defined priority route */ - Application = 0x10, -} - -export interface Route { - repeaters: number[]; - routeSpeed: ZWaveDataRate; -} - -export const EMPTY_ROUTE: Route = { - repeaters: [], - routeSpeed: ZWaveDataRate["9k6"], -}; - -export function isEmptyRoute(route: Route): boolean { - return ( - route.repeaters.length === 0 - && route.routeSpeed === ZWaveDataRate["9k6"] - ); -} - export enum LongRangeChannel { /** Indicates that Long Range is not supported by the currently set RF region */ Unsupported = 0x00, @@ -144,17 +117,9 @@ export function isLongRangeNodeId(nodeId: number): boolean { return nodeId > 255; } -export enum MPDUHeaderType { - Singlecast = 0x1, - Multicast = 0x2, - Acknowledgement = 0x3, - Explorer = 0x5, - Routed = 0x8, -} - -export enum BeamingInfo { - None = 0b00, - ShortContinuous = 0b01, - LongContinuous = 0b10, - Fragmented = 0b100, +export enum ProtocolVersion { + "unknown" = 0, + "2.0" = 1, + "4.2x / 5.0x" = 2, + "4.5x / 6.0x" = 3, } diff --git a/packages/core/src/capabilities/RFRegion.ts b/packages/core/src/definitions/RFRegion.ts similarity index 100% rename from packages/core/src/capabilities/RFRegion.ts rename to packages/core/src/definitions/RFRegion.ts diff --git a/packages/core/src/definitions/Route.ts b/packages/core/src/definitions/Route.ts new file mode 100644 index 000000000000..178ac486b5b6 --- /dev/null +++ b/packages/core/src/definitions/Route.ts @@ -0,0 +1,28 @@ +import { ZWaveDataRate } from "./Protocol.js"; + +export enum RouteKind { + None = 0x00, + /** Last Working Route */ + LWR = 0x01, + /** Next to Last Working Route */ + NLWR = 0x02, + /** Application-defined priority route */ + Application = 0x10, +} + +export interface Route { + repeaters: number[]; + routeSpeed: ZWaveDataRate; +} + +export const EMPTY_ROUTE: Route = { + repeaters: [], + routeSpeed: ZWaveDataRate["9k6"], +}; + +export function isEmptyRoute(route: Route): boolean { + return ( + route.repeaters.length === 0 + && route.routeSpeed === ZWaveDataRate["9k6"] + ); +} diff --git a/packages/core/src/security/SecurityClass.ts b/packages/core/src/definitions/SecurityClass.ts similarity index 67% rename from packages/core/src/security/SecurityClass.ts rename to packages/core/src/definitions/SecurityClass.ts index 2f441c295782..ace99d8ae671 100644 --- a/packages/core/src/security/SecurityClass.ts +++ b/packages/core/src/definitions/SecurityClass.ts @@ -1,5 +1,3 @@ -import type { MaybeNotKnown } from "../values/Primitive.js"; - export enum SecurityClass { /** * Used internally during inclusion of a node. Don't use this! @@ -50,23 +48,6 @@ export const securityClassOrder = [ SecurityClass.S0_Legacy, ] as const; -/** Allows querying the security classes of a node */ -export interface QuerySecurityClasses { - /** Whether the node was granted at least one security class */ - readonly isSecure: MaybeNotKnown; - - /** Returns whether a node was granted the given security class */ - hasSecurityClass(securityClass: SecurityClass): MaybeNotKnown; - - /** Returns the highest security class this node was granted or `undefined` if that information isn't known yet */ - getHighestSecurityClass(): MaybeNotKnown; -} - -/** Allows modifying the security classes of a node */ -export interface SetSecurityClass { - setSecurityClass(securityClass: SecurityClass, granted: boolean): void; -} - export function getHighestSecurityClass( securityClasses: SecurityClass[], ): SecurityClass { diff --git a/packages/core/src/capabilities/ZWaveApiVersion.ts b/packages/core/src/definitions/ZWaveApiVersion.ts similarity index 100% rename from packages/core/src/capabilities/ZWaveApiVersion.ts rename to packages/core/src/definitions/ZWaveApiVersion.ts diff --git a/packages/core/src/capabilities/ZWaveChipTypes.ts b/packages/core/src/definitions/ZWaveChipTypes.ts similarity index 100% rename from packages/core/src/capabilities/ZWaveChipTypes.ts rename to packages/core/src/definitions/ZWaveChipTypes.ts diff --git a/packages/core/src/definitions/index.ts b/packages/core/src/definitions/index.ts new file mode 100644 index 000000000000..247534b7a9f1 --- /dev/null +++ b/packages/core/src/definitions/index.ts @@ -0,0 +1,11 @@ +export * from "./CommandClasses.js"; +export * from "./ControllerCapabilities.js"; +export * from "./Frame.js"; +export * from "./LibraryTypes.js"; +export * from "./NodeInfo.js"; +export * from "./Protocol.js"; +export * from "./RFRegion.js"; +export * from "./Route.js"; +export * from "./SecurityClass.js"; +export type * from "./ZWaveApiVersion.js"; +export * from "./ZWaveChipTypes.js"; diff --git a/packages/core/src/security/DSK.ts b/packages/core/src/dsk/index.ts similarity index 68% rename from packages/core/src/security/DSK.ts rename to packages/core/src/dsk/index.ts index 3aa4ff5c70ac..c6260b284850 100644 --- a/packages/core/src/security/DSK.ts +++ b/packages/core/src/dsk/index.ts @@ -1,7 +1,5 @@ import { Bytes } from "@zwave-js/shared/safe"; -import { padStart } from "alcalzone-shared/strings/index.js"; import { ZWaveError, ZWaveErrorCodes } from "../error/ZWaveError.js"; -import { isValidDSK } from "./shared_safe.js"; export function dskToString(dsk: Uint8Array): string { if (dsk.length !== 16) { @@ -13,7 +11,7 @@ export function dskToString(dsk: Uint8Array): string { let ret = ""; for (let i = 0; i < 16; i += 2) { if (i > 0) ret += "-"; - ret += padStart(Bytes.view(dsk).readUInt16BE(i).toString(10), 5, "0"); + ret += Bytes.view(dsk).readUInt16BE(i).toString(10).padStart(5, "0"); } return ret; } @@ -57,4 +55,28 @@ export function authHomeIdFromDSK(dsk: Uint8Array): Uint8Array { ret[0] &= 0b00111111; ret[3] |= 0b00000001; return ret; +} /** + * Tries to extract a DSK from a scanned QR code. If the string is a valid DSK (prefixed with "zws2dsk:" or unprefixed), the DSK will be returned. + * This can then be used to initiate an S2 inclusion with pre-filled DSK. + */ + +export function tryParseDSKFromQRCodeString(qr: string): string | undefined { + // Trim off whitespace that might have been copied by accident + qr = qr.trim(); + if (qr.startsWith("zws2dsk:")) { + qr = qr.slice("zws2dsk:".length); + } + if (isValidDSK(qr)) { + return qr; + } +} + +export function isValidDSK(dsk: string): boolean { + const patternMatches = /^(\d{5}-){7}\d{5}$/.test(dsk); + if (!patternMatches) return false; + + return dsk + .split("-") + .map((p) => parseInt(p, 10)) + .every((p) => p <= 0xffff); } diff --git a/packages/core/src/error/ZWaveError.ts b/packages/core/src/error/ZWaveError.ts index 05bfbf7d7c28..fff3a39958a6 100644 --- a/packages/core/src/error/ZWaveError.ts +++ b/packages/core/src/error/ZWaveError.ts @@ -1,5 +1,3 @@ -import { padStart } from "alcalzone-shared/strings/index.js"; - /** * Used to identify errors from this library without relying on the specific wording of the error message */ @@ -215,7 +213,7 @@ export enum ZWaveErrorCodes { } export function getErrorSuffix(code: ZWaveErrorCodes): string { - return `ZW${padStart(code.toString(), 4, "0")}`; + return `ZW${code.toString().padStart(4, "0")}`; } function appendErrorSuffix(message: string, code: ZWaveErrorCodes): string { diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 5b756bbee481..44163bf64678 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,35 +1,22 @@ /* eslint-disable @typescript-eslint/consistent-type-exports */ -export * from "./capabilities/CommandClasses.js"; -export * from "./capabilities/ControllerCapabilities.js"; -export * from "./capabilities/LibraryTypes.js"; -export * from "./capabilities/NodeInfo.js"; -export * from "./capabilities/Protocols.js"; -export * from "./capabilities/RFRegion.js"; -export * from "./capabilities/ZWaveApiVersion.js"; -export * from "./capabilities/ZWaveChipTypes.js"; export * from "./consts/index.js"; +export * from "./definitions/index.js"; +export * from "./dsk/index.js"; export * from "./error/ZWaveError.js"; export * from "./log/Controller.js"; export * from "./log/shared.js"; export * from "./log/shared_safe.js"; -export * from "./registries/DeviceClasses.js"; -export * from "./registries/Indicators.js"; -export * from "./registries/Meters.js"; -export * from "./registries/Notifications.js"; -export * from "./registries/Scales.js"; -export * from "./registries/Sensors.js"; -export * from "./security/DSK.js"; +export * from "./qr/index.js"; +export * from "./registries/index.js"; export * from "./security/Manager.js"; export * from "./security/Manager2.js"; -export * from "./security/QR.js"; -export * from "./security/SecurityClass.js"; export * from "./security/crypto.js"; export * from "./security/ctr_drbg.js"; -export * from "./security/shared_safe.js"; export * from "./test/assertZWaveError.js"; export * from "./traits/CommandClasses.js"; export * from "./traits/Endpoints.js"; export * from "./traits/Nodes.js"; +export * from "./traits/SecurityClasses.js"; export * from "./traits/SecurityManagers.js"; export * from "./util/_Types.js"; export * from "./util/compareVersions.js"; diff --git a/packages/core/src/index_browser.ts b/packages/core/src/index_browser.ts new file mode 100644 index 000000000000..8131aab703e8 --- /dev/null +++ b/packages/core/src/index_browser.ts @@ -0,0 +1,32 @@ +/* @forbiddenImports external */ +// FIXME: Find a way to make sure that the forbiddenImports lint uses the "browser" condition + +export * from "./consts/index.js"; +export * from "./definitions/index.js"; +export * from "./dsk/index.js"; +export * from "./error/ZWaveError.js"; +export * from "./log/shared_safe.js"; +export * from "./qr/index.browser.js"; +export * from "./registries/DeviceClasses.js"; +export * from "./registries/Indicators.js"; +export * from "./registries/Meters.js"; +export * from "./registries/Notifications.js"; +export * from "./registries/Scales.js"; +export * from "./registries/Sensors.js"; +export type * from "./traits/CommandClasses.js"; +export type * from "./traits/Endpoints.js"; +export type * from "./traits/Nodes.js"; +export type * from "./traits/SecurityClasses.js"; +export type * from "./traits/SecurityManagers.js"; +export type * from "./util/_Types.js"; +export * from "./util/config.js"; +export * from "./util/crc.js"; +export * from "./util/graph.js"; +export * from "./util/misc.js"; +export * from "./values/Cache.js"; +export * from "./values/CacheBackedMap.js"; +export * from "./values/Duration.js"; +export * from "./values/Metadata.js"; +export * from "./values/Primitive.js"; +export * from "./values/Timeout.js"; +export type * from "./values/_Types.js"; diff --git a/packages/core/src/index_safe.ts b/packages/core/src/index_safe.ts index d4b7ff55c8da..705a24c6acb7 100644 --- a/packages/core/src/index_safe.ts +++ b/packages/core/src/index_safe.ts @@ -1,30 +1,22 @@ /* eslint-disable @typescript-eslint/consistent-type-exports */ /* @forbiddenImports external */ -export * from "./capabilities/CommandClasses.js"; -export * from "./capabilities/ControllerCapabilities.js"; -export * from "./capabilities/LibraryTypes.js"; -export * from "./capabilities/NodeInfo.js"; -export * from "./capabilities/Protocols.js"; -export * from "./capabilities/RFRegion.js"; -export * from "./capabilities/ZWaveApiVersion.js"; -export * from "./capabilities/ZWaveChipTypes.js"; export * from "./consts/index.js"; +export * from "./definitions/index.js"; +export * from "./dsk/index.js"; export * from "./error/ZWaveError.js"; export * from "./log/shared_safe.js"; +export * from "./qr/index.browser.js"; export * from "./registries/DeviceClasses.js"; export * from "./registries/Indicators.js"; export * from "./registries/Meters.js"; export * from "./registries/Notifications.js"; export * from "./registries/Scales.js"; export * from "./registries/Sensors.js"; -export * from "./security/DSK.js"; -export * from "./security/SecurityClass.js"; -export * from "./security/shared_safe.js"; export * from "./traits/CommandClasses.js"; export * from "./traits/Endpoints.js"; -export * from "./traits/Endpoints.js"; export * from "./traits/Nodes.js"; +export * from "./traits/SecurityClasses.js"; export * from "./traits/SecurityManagers.js"; export * from "./util/_Types.js"; export * from "./util/config.js"; diff --git a/packages/core/src/log/Controller.test.ts b/packages/core/src/log/Controller.test.ts index fc408baa75e0..438ade627596 100644 --- a/packages/core/src/log/Controller.test.ts +++ b/packages/core/src/log/Controller.test.ts @@ -1,6 +1,6 @@ import { beforeEach, test as baseTest } from "vitest"; -import { CommandClasses } from "../capabilities/CommandClasses.js"; import { InterviewStage } from "../consts/InterviewStage.js"; +import { CommandClasses } from "../definitions/CommandClasses.js"; import { SpyTransport, assertLogInfo, diff --git a/packages/core/src/log/Controller.ts b/packages/core/src/log/Controller.ts index b8d404b6479c..7329bc11c172 100644 --- a/packages/core/src/log/Controller.ts +++ b/packages/core/src/log/Controller.ts @@ -1,6 +1,6 @@ -import { isObject } from "alcalzone-shared/typeguards/index.js"; -import { CommandClasses } from "../capabilities/CommandClasses.js"; +import { isObject } from "alcalzone-shared/typeguards"; import { InterviewStage } from "../consts/InterviewStage.js"; +import { CommandClasses } from "../definitions/CommandClasses.js"; import type { ValueAddedArgs, ValueID, diff --git a/packages/core/src/log/shared_safe.ts b/packages/core/src/log/shared_safe.ts index f46b8cc6e63c..d1a77c98bc77 100644 --- a/packages/core/src/log/shared_safe.ts +++ b/packages/core/src/log/shared_safe.ts @@ -1,4 +1,3 @@ -import { padStart } from "alcalzone-shared/strings/index.js"; import type { TransformableInfo } from "logform"; import type { Logger } from "winston"; import type Transport from "winston-transport"; @@ -73,7 +72,7 @@ export interface MessageOrCCLogEntry { /** Returns the tag used to log node related messages */ export function getNodeTag(nodeId: number): string { - return "Node " + padStart(nodeId.toString(), 3, "0"); + return "Node " + nodeId.toString().padStart(3, "0"); } export type ZWaveLogger = diff --git a/packages/core/src/qr/definitions.ts b/packages/core/src/qr/definitions.ts new file mode 100644 index 000000000000..96ad462145f9 --- /dev/null +++ b/packages/core/src/qr/definitions.ts @@ -0,0 +1,70 @@ +import { type Protocols } from "../definitions/Protocol.js"; +import { type SecurityClass } from "../definitions/SecurityClass.js"; + +export const onlyDigitsRegex = /^\d+$/; +export const minQRCodeLength = 52; // 2 digits Z, 2 digits version, 5 digits checksum, 3 digits keys, 40 digits DSK + +export enum QRCodeVersion { + S2 = 0, + SmartStart = 1, +} + +export enum ProvisioningInformationType { + ProductType = 0x00, + ProductId = 0x01, + MaxInclusionRequestInterval = 0x02, + UUID16 = 0x03, + SupportedProtocols = 0x04, + // The ones below are NOT QR code compatible and therefore not implemented here + Name = 0x32, + Location = 0x33, + SmartStartInclusionSetting = 0x34, + AdvancedJoining = 0x35, + BootstrappingMode = 0x36, + NetworkStatus = 0x37, +} + +export interface ProvisioningInformation_ProductType { + genericDeviceClass: number; + specificDeviceClass: number; + installerIconType: number; +} + +export interface ProvisioningInformation_ProductId { + manufacturerId: number; + productType: number; + productId: number; + applicationVersion: string; +} + +export interface ProvisioningInformation_MaxInclusionRequestInterval { + maxInclusionRequestInterval: number; +} + +export interface ProvisioningInformation_UUID16 { + uuid: string; +} + +export interface ProvisioningInformation_SupportedProtocols { + supportedProtocols: Protocols[]; +} + +export type QRProvisioningInformation = + & { + version: QRCodeVersion; + /** + * The security classes that were **requested** by the device. + */ + readonly requestedSecurityClasses: SecurityClass[]; + /** + * The security classes that will be **granted** to this device. + * Until this has been changed by a user, this will be identical to {@link requestedSecurityClasses}. + */ + securityClasses: SecurityClass[]; + dsk: string; + } + & ProvisioningInformation_ProductType + & ProvisioningInformation_ProductId + & Partial + & Partial + & Partial; diff --git a/packages/core/src/qr/index.browser.ts b/packages/core/src/qr/index.browser.ts new file mode 100644 index 000000000000..dc96c270db43 --- /dev/null +++ b/packages/core/src/qr/index.browser.ts @@ -0,0 +1,13 @@ +export { + ProvisioningInformationType, + type ProvisioningInformation_MaxInclusionRequestInterval, + type ProvisioningInformation_ProductId, + type ProvisioningInformation_ProductType, + type ProvisioningInformation_SupportedProtocols, + type ProvisioningInformation_UUID16, + QRCodeVersion, + type QRProvisioningInformation, + minQRCodeLength, +} from "./definitions.js"; +export { parseQRCodeStringAsync } from "./parse.browser.js"; +export * from "./utils.js"; diff --git a/packages/core/src/qr/index.ts b/packages/core/src/qr/index.ts new file mode 100644 index 000000000000..3489ba9c348a --- /dev/null +++ b/packages/core/src/qr/index.ts @@ -0,0 +1,13 @@ +export { + ProvisioningInformationType, + type ProvisioningInformation_MaxInclusionRequestInterval, + type ProvisioningInformation_ProductId, + type ProvisioningInformation_ProductType, + type ProvisioningInformation_SupportedProtocols, + type ProvisioningInformation_UUID16, + QRCodeVersion, + type QRProvisioningInformation, + minQRCodeLength, +} from "./definitions.js"; +export { parseQRCodeString } from "./parse.node.js"; +export * from "./utils.js"; diff --git a/packages/core/src/qr/parse.browser.ts b/packages/core/src/qr/parse.browser.ts new file mode 100644 index 000000000000..39e1fc408cb2 --- /dev/null +++ b/packages/core/src/qr/parse.browser.ts @@ -0,0 +1,89 @@ +import { Bytes } from "@zwave-js/shared/safe"; +import { SecurityClass } from "../definitions/SecurityClass.js"; +import { dskToString } from "../dsk/index.js"; +import { parseBitMask } from "../values/Primitive.js"; +import { + ProvisioningInformationType, + QRCodeVersion, + type QRProvisioningInformation, + minQRCodeLength, + onlyDigitsRegex, +} from "./definitions.js"; +import { fail, parseTLV, readLevel, readUInt16, readUInt8 } from "./utils.js"; + +/** Parses a string that has been decoded from a Z-Wave (S2 or SmartStart) QR code */ +export async function parseQRCodeStringAsync( + qr: string, +): Promise { + // Trim off whitespace that might have been copied by accident + qr = qr.trim(); + // Validate the QR code + if (!qr.startsWith("90")) fail("must start with 90"); + if (qr.length < minQRCodeLength) fail("too short"); + if (!onlyDigitsRegex.test(qr)) fail("contains invalid characters"); + + const version = readLevel(qr, 2); + if (version > QRCodeVersion.SmartStart) fail("invalid version"); + + const checksum = readUInt16(qr, 4); + // The checksum covers the remaining data + const checksumInput = new TextEncoder().encode(qr.slice(9)); + + const subtleCrypto: typeof import("node:crypto").subtle = + // @ts-expect-error Node.js 18 does not support this yet + globalThis.crypto.subtle; + + const hashResult = await subtleCrypto.digest("SHA-1", checksumInput); + const expectedChecksum = Bytes.view(hashResult).readUInt16BE(0); + if (checksum !== expectedChecksum) fail("invalid checksum"); + + const requestedKeysBitmask = readUInt8(qr, 9); + const requestedSecurityClasses = parseBitMask( + [requestedKeysBitmask], + SecurityClass.S2_Unauthenticated, + ); + if (!requestedSecurityClasses.every((k) => k in SecurityClass)) { + fail("invalid security class requested"); + } + + let offset = 12; + const dsk = new Bytes(16); + for (let dskBlock = 0; dskBlock < 8; dskBlock++) { + const block = readUInt16(qr, offset); + dsk.writeUInt16BE(block, dskBlock * 2); + offset += 5; + } + + const ret = { + version, + // This seems like a duplication, but it's more convenient for applications to not have to copy this field over + requestedSecurityClasses, + securityClasses: [...requestedSecurityClasses], + dsk: dskToString(dsk), + } as QRProvisioningInformation; + + let hasProductID = false; + let hasProductType = false; + + while (offset < qr.length) { + const { + entry: { type, ...data }, + charsRead, + } = parseTLV(qr.slice(offset)); + offset += charsRead; + + if (type === ProvisioningInformationType.ProductId) { + hasProductID = true; + } else if (type === ProvisioningInformationType.ProductType) { + hasProductType = true; + } + Object.assign(ret, data); + } + + // Ensure the required fields are present + if (!hasProductID || !hasProductType) { + fail("missing required fields"); + } + + return ret; +} diff --git a/packages/core/src/qr/parse.node.ts b/packages/core/src/qr/parse.node.ts new file mode 100644 index 000000000000..f285906a5137 --- /dev/null +++ b/packages/core/src/qr/parse.node.ts @@ -0,0 +1,167 @@ +import { Bytes } from "@zwave-js/shared/safe"; +import { createHash } from "node:crypto"; +import { SecurityClass } from "../definitions/SecurityClass.js"; +import { dskToString } from "../dsk/index.js"; +import { parseBitMask } from "../values/Primitive.js"; +import { + ProvisioningInformationType, + QRCodeVersion, + type QRProvisioningInformation, + minQRCodeLength, + onlyDigitsRegex, +} from "./definitions.js"; +import { fail, parseTLV, readLevel, readUInt16, readUInt8 } from "./utils.js"; + +/** + * Parses a string that has been decoded from a Z-Wave (S2 or SmartStart) QR code + * @deprecated Use {@link parseQRCodeStringAsync} instead. + */ +export function parseQRCodeString(qr: string): QRProvisioningInformation { + // Trim off whitespace that might have been copied by accident + qr = qr.trim(); + // Validate the QR code + if (!qr.startsWith("90")) fail("must start with 90"); + if (qr.length < minQRCodeLength) fail("too short"); + if (!onlyDigitsRegex.test(qr)) fail("contains invalid characters"); + + const version = readLevel(qr, 2); + if (version > QRCodeVersion.SmartStart) fail("invalid version"); + + const checksum = readUInt16(qr, 4); + // The checksum covers the remaining data + const hash = createHash("sha1"); + hash.update(Bytes.from(qr.slice(9), "ascii")); + const expectedChecksum = hash.digest().readUInt16BE(0); + if (checksum !== expectedChecksum) fail("invalid checksum"); + + const requestedKeysBitmask = readUInt8(qr, 9); + const requestedSecurityClasses = parseBitMask( + [requestedKeysBitmask], + SecurityClass.S2_Unauthenticated, + ); + if (!requestedSecurityClasses.every((k) => k in SecurityClass)) { + fail("invalid security class requested"); + } + + let offset = 12; + const dsk = new Bytes(16); + for (let dskBlock = 0; dskBlock < 8; dskBlock++) { + const block = readUInt16(qr, offset); + dsk.writeUInt16BE(block, dskBlock * 2); + offset += 5; + } + + const ret = { + version, + // This seems like a duplication, but it's more convenient for applications to not have to copy this field over + requestedSecurityClasses, + securityClasses: [...requestedSecurityClasses], + dsk: dskToString(dsk), + } as QRProvisioningInformation; + + let hasProductID = false; + let hasProductType = false; + + while (offset < qr.length) { + const { + entry: { type, ...data }, + charsRead, + } = parseTLV(qr.slice(offset)); + offset += charsRead; + + if (type === ProvisioningInformationType.ProductId) { + hasProductID = true; + } else if (type === ProvisioningInformationType.ProductType) { + hasProductType = true; + } + Object.assign(ret, data); + } + + // Ensure the required fields are present + if (!hasProductID || !hasProductType) { + fail("missing required fields"); + } + + return ret; +} + +/** Parses a string that has been decoded from a Z-Wave (S2 or SmartStart) QR code */ +export async function parseQRCodeStringAsync( + qr: string, +): Promise { + // Trim off whitespace that might have been copied by accident + qr = qr.trim(); + // Validate the QR code + if (!qr.startsWith("90")) fail("must start with 90"); + if (qr.length < minQRCodeLength) fail("too short"); + if (!onlyDigitsRegex.test(qr)) fail("contains invalid characters"); + + const version = readLevel(qr, 2); + if (version > QRCodeVersion.SmartStart) fail("invalid version"); + + const checksum = readUInt16(qr, 4); + // The checksum covers the remaining data + const checksumInput = new TextEncoder().encode(qr.slice(9)); + + const subtleCrypto: typeof import("node:crypto").subtle = + // FIXME: This method is a copy of the one in parse.browser.ts, except for the node:crypto import + // Once the following @ts-expect-error is no longer needed, this method should be removed in favor of the one from parse.browser.ts + // and the exports in index.ts can be updated to be based on index.browser.ts + // + // @ts-expect-error Node.js 18 does not support globalThis.crypto yet + (globalThis.crypto ?? ((await import("node:crypto")).webcrypto)).subtle; + + const hashResult = await subtleCrypto.digest("SHA-1", checksumInput); + const expectedChecksum = Bytes.view(hashResult).readUInt16BE(0); + if (checksum !== expectedChecksum) fail("invalid checksum"); + + const requestedKeysBitmask = readUInt8(qr, 9); + const requestedSecurityClasses = parseBitMask( + [requestedKeysBitmask], + SecurityClass.S2_Unauthenticated, + ); + if (!requestedSecurityClasses.every((k) => k in SecurityClass)) { + fail("invalid security class requested"); + } + + let offset = 12; + const dsk = new Bytes(16); + for (let dskBlock = 0; dskBlock < 8; dskBlock++) { + const block = readUInt16(qr, offset); + dsk.writeUInt16BE(block, dskBlock * 2); + offset += 5; + } + + const ret = { + version, + // This seems like a duplication, but it's more convenient for applications to not have to copy this field over + requestedSecurityClasses, + securityClasses: [...requestedSecurityClasses], + dsk: dskToString(dsk), + } as QRProvisioningInformation; + + let hasProductID = false; + let hasProductType = false; + + while (offset < qr.length) { + const { + entry: { type, ...data }, + charsRead, + } = parseTLV(qr.slice(offset)); + offset += charsRead; + + if (type === ProvisioningInformationType.ProductId) { + hasProductID = true; + } else if (type === ProvisioningInformationType.ProductType) { + hasProductType = true; + } + Object.assign(ret, data); + } + + // Ensure the required fields are present + if (!hasProductID || !hasProductType) { + fail("missing required fields"); + } + + return ret; +} diff --git a/packages/core/src/security/QR.test.ts b/packages/core/src/qr/parse.test.ts similarity index 95% rename from packages/core/src/security/QR.test.ts rename to packages/core/src/qr/parse.test.ts index fe134be72b64..3fe0614aad88 100644 --- a/packages/core/src/security/QR.test.ts +++ b/packages/core/src/qr/parse.test.ts @@ -1,8 +1,9 @@ +/* eslint-disable @typescript-eslint/no-deprecated */ import { test } from "vitest"; +import { SecurityClass } from "../definitions/SecurityClass.js"; import { ZWaveErrorCodes } from "../error/ZWaveError.js"; import { assertZWaveError } from "../test/assertZWaveError.js"; -import { QRCodeVersion, parseQRCodeString } from "./QR.js"; -import { SecurityClass } from "./SecurityClass.js"; +import { QRCodeVersion, parseQRCodeString } from "./index.js"; function createDummyQR(firstDigits: string): string { return firstDigits + "0".repeat(52 - firstDigits.length); diff --git a/packages/core/src/qr/utils.ts b/packages/core/src/qr/utils.ts new file mode 100644 index 000000000000..3c57e6e66574 --- /dev/null +++ b/packages/core/src/qr/utils.ts @@ -0,0 +1,159 @@ +import { Bytes } from "@zwave-js/shared/safe"; +import { Protocols } from "../definitions/Protocol.js"; +import { ZWaveError, ZWaveErrorCodes } from "../error/ZWaveError.js"; +import { parseBitMask } from "../values/Primitive.js"; +import { + ProvisioningInformationType, + type ProvisioningInformation_MaxInclusionRequestInterval, + type ProvisioningInformation_ProductId, + type ProvisioningInformation_ProductType, + type ProvisioningInformation_SupportedProtocols, + type ProvisioningInformation_UUID16, +} from "./definitions.js"; + +function readNumber(qr: string, offset: number, length: number): number { + return parseInt(qr.slice(offset, offset + length), 10); +} + +export function fail(reason: string): never { + throw new ZWaveError( + `Invalid QR code: ${reason}`, + ZWaveErrorCodes.Security2CC_InvalidQRCode, + ); +} + +/** Reads a number between 0 and 99 (2 decimal digits) */ +export function readLevel(qr: string, offset: number): number { + const ret = readNumber(qr, offset, 2); + if (ret > 99) fail("invalid data"); + return ret; +} + +/** Reads a byte (3 decimal digits) */ +export function readUInt8(qr: string, offset: number): number { + const ret = readNumber(qr, offset, 3); + if (ret > 0xff) fail("invalid data"); + return ret; +} + +/** Reads a 2-byte value (5 decimal digits) */ +export function readUInt16(qr: string, offset: number): number { + const ret = readNumber(qr, offset, 5); + if (ret > 0xffff) fail("invalid data"); + return ret; +} + +// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types +export function parseTLVData(type: ProvisioningInformationType, data: string) { + switch (type) { + case ProvisioningInformationType.ProductType: { + const deviceClasses = readUInt16(data, 0); + const installerIconType = readUInt16(data, 5); + const ret: ProvisioningInformation_ProductType = { + genericDeviceClass: deviceClasses >>> 8, + specificDeviceClass: deviceClasses & 0xff, + installerIconType, + }; + return ret; + } + + case ProvisioningInformationType.ProductId: { + const manufacturerId = readUInt16(data, 0); + const productType = readUInt16(data, 5); + const productId = readUInt16(data, 10); + const applicationVersionNumeric = readUInt16(data, 15); + const applicationVersion = `${applicationVersionNumeric >>> 8}.${ + applicationVersionNumeric & 0xff + }`; + const ret: ProvisioningInformation_ProductId = { + manufacturerId, + productType, + productId, + applicationVersion, + }; + return ret; + } + + case ProvisioningInformationType.MaxInclusionRequestInterval: { + const maxInclusionRequestInterval = 128 * readLevel(data, 0); + const ret: ProvisioningInformation_MaxInclusionRequestInterval = { + maxInclusionRequestInterval, + }; + return ret; + } + + case ProvisioningInformationType.UUID16: { + const buffer = new Bytes(16); + // Only format 0 is supported here + const presentationFormat = readLevel(data, 0); + if (presentationFormat !== 0) return; + + for (let chunk = 0; chunk < 8; chunk++) { + const value = readUInt16(data, 2 + chunk * 5); + buffer.writeUInt16BE(value, chunk * 2); + } + const ret: ProvisioningInformation_UUID16 = { + uuid: buffer.toString("hex"), + }; + return ret; + } + + case ProvisioningInformationType.SupportedProtocols: { + const bitMask = Uint8Array.from([ + data.length === 2 + ? readLevel(data, 0) + : data.length === 3 + ? readUInt8(data, 0) + : data.length === 5 + ? readUInt16(data, 0) + : 0, + ]); + const supportedProtocols = parseBitMask(bitMask, Protocols.ZWave); + const ret: ProvisioningInformation_SupportedProtocols = { + supportedProtocols, + }; + return ret; + } + } +} + +export function parseTLV(qr: string): { + entry: { + type: ProvisioningInformationType; + } & Record; + charsRead: number; +} { + let offset = 0; + if (qr.length - offset < 4) fail("incomplete TLV block"); + const typeCritical = readLevel(qr, offset); + const type = typeCritical >>> 1; + const critical = !!(typeCritical & 0b1); + const length = readLevel(qr, offset + 2); + offset += 4; + if (qr.length - offset < length) fail("incomplete TLV block"); + + const data = qr.slice(offset, offset + length); + offset += length; + + // Try to parse the raw data and fail if a critical block is not understood + const parsed = parseTLVData(type, data); + if (!parsed && critical) fail("Unsupported critical TLV block"); + + let entry: any; + if (parsed) { + entry = { + type, + ...parsed, + }; + } else { + entry = { + type, + [ProvisioningInformationType[type]]: data, + }; + } + + return { + entry, + charsRead: offset, + }; +} diff --git a/packages/core/src/registries/index.ts b/packages/core/src/registries/index.ts new file mode 100644 index 000000000000..a90e1f7e85ab --- /dev/null +++ b/packages/core/src/registries/index.ts @@ -0,0 +1,75 @@ +export type { + GenericDeviceClass, + GenericDeviceClassWithSpecific, + SpecificDeviceClass, +} from "./DeviceClasses.js"; +export { + BasicDeviceClass, + getAllDeviceClasses, + getGenericDeviceClass, + getSpecificDeviceClass, +} from "./DeviceClasses.js"; +export type { IndicatorProperties, IndicatorProperty } from "./Indicators.js"; +export { + Indicator, + getAllIndicatorProperties, + getIndicatorProperty, +} from "./Indicators.js"; +export type { + Meter, + MeterDefinition, + MeterScale, + MeterScaleDefinition, + MeterScaleGroup, + Meters, +} from "./Meters.js"; +export { + getAllMeterScales, + getAllMeters, + getMeter, + getMeterName, + getMeterScale, + getUnknownMeterScale, +} from "./Meters.js"; +export type { + Notification, + NotificationEvent, + NotificationParameter, + NotificationParameterWithCommandClass, + NotificationParameterWithDuration, + NotificationParameterWithEnum, + NotificationParameterWithValue, + NotificationState, + NotificationValue, + NotificationValueBase, + NotificationVariable, +} from "./Notifications.js"; +export { + getAllNotifications, + getNotification, + getNotificationEventName, + getNotificationName, + getNotificationValue, + getNotificationValueName, +} from "./Notifications.js"; +export type { + NamedScaleGroup, + NamedScales, + Scale, + ScaleDefinition, + ScaleGroup, +} from "./Scales.js"; +export { + getAllNamedScaleGroups, + getNamedScale, + getNamedScaleGroup, + getUnknownScale, +} from "./Scales.js"; +export type { Sensor, SensorDefinition, Sensors } from "./Sensors.js"; +export { + getAllSensorScales, + getAllSensors, + getSensor, + getSensorName, + getSensorScale, +} from "./Sensors.js"; diff --git a/packages/core/src/security/Manager2.test.ts b/packages/core/src/security/Manager2.test.ts index 25f2a810adf4..4257ad7a17a7 100644 --- a/packages/core/src/security/Manager2.test.ts +++ b/packages/core/src/security/Manager2.test.ts @@ -1,10 +1,10 @@ import { isUint8Array } from "@zwave-js/shared"; import * as crypto from "node:crypto"; import { test } from "vitest"; +import { SecurityClass } from "../definitions/SecurityClass.js"; import { ZWaveErrorCodes } from "../error/ZWaveError.js"; import { assertZWaveError } from "../test/assertZWaveError.js"; import { SecurityManager2 } from "./Manager2.js"; -import { SecurityClass } from "./SecurityClass.js"; function dummyInit( man: SecurityManager2, diff --git a/packages/core/src/security/Manager2.ts b/packages/core/src/security/Manager2.ts index 0b0c06541875..ccf954bbc44c 100644 --- a/packages/core/src/security/Manager2.ts +++ b/packages/core/src/security/Manager2.ts @@ -4,10 +4,13 @@ import { createWrappingCounter, getEnumMemberName } from "@zwave-js/shared"; import * as crypto from "node:crypto"; import { deflateSync } from "node:zlib"; import { MAX_NODES_LR } from "../consts/index.js"; +import { + type S2SecurityClass, + SecurityClass, +} from "../definitions/SecurityClass.js"; import { ZWaveError, ZWaveErrorCodes } from "../error/ZWaveError.js"; import { highResTimestamp } from "../util/date.js"; import { encodeBitMask } from "../values/Primitive.js"; -import { type S2SecurityClass, SecurityClass } from "./SecurityClass.js"; import { increment } from "./bufferUtils.js"; import { computeNoncePRK, diff --git a/packages/core/src/security/QR.ts b/packages/core/src/security/QR.ts deleted file mode 100644 index 936c3f286dff..000000000000 --- a/packages/core/src/security/QR.ts +++ /dev/null @@ -1,291 +0,0 @@ -import { Bytes } from "@zwave-js/shared/safe"; -import { createHash } from "node:crypto"; -import { Protocols } from "../capabilities/Protocols.js"; -import { ZWaveError, ZWaveErrorCodes } from "../error/ZWaveError.js"; -import { parseBitMask } from "../values/Primitive.js"; -import { dskToString } from "./DSK.js"; -import { SecurityClass } from "./SecurityClass.js"; - -function readNumber(qr: string, offset: number, length: number): number { - return parseInt(qr.slice(offset, offset + length), 10); -} - -function fail(reason: string): never { - throw new ZWaveError( - `Invalid QR code: ${reason}`, - ZWaveErrorCodes.Security2CC_InvalidQRCode, - ); -} - -/** Reads a number between 0 and 99 (2 decimal digits) */ -function readLevel(qr: string, offset: number): number { - const ret = readNumber(qr, offset, 2); - if (ret > 99) fail("invalid data"); - return ret; -} - -/** Reads a byte (3 decimal digits) */ -function readUInt8(qr: string, offset: number): number { - const ret = readNumber(qr, offset, 3); - if (ret > 0xff) fail("invalid data"); - return ret; -} - -/** Reads a 2-byte value (5 decimal digits) */ -function readUInt16(qr: string, offset: number): number { - const ret = readNumber(qr, offset, 5); - if (ret > 0xffff) fail("invalid data"); - return ret; -} - -const onlyDigitsRegex = /^\d+$/; -const minQRCodeLength = 52; // 2 digits Z, 2 digits version, 5 digits checksum, 3 digits keys, 40 digits DSK - -export enum QRCodeVersion { - S2 = 0, - SmartStart = 1, -} - -export enum ProvisioningInformationType { - ProductType = 0x00, - ProductId = 0x01, - MaxInclusionRequestInterval = 0x02, - UUID16 = 0x03, - SupportedProtocols = 0x04, - // The ones below are NOT QR code compatible and therefore not implemented here - Name = 0x32, - Location = 0x33, - SmartStartInclusionSetting = 0x34, - AdvancedJoining = 0x35, - BootstrappingMode = 0x36, - NetworkStatus = 0x37, -} - -export interface ProvisioningInformation_ProductType { - genericDeviceClass: number; - specificDeviceClass: number; - installerIconType: number; -} - -export interface ProvisioningInformation_ProductId { - manufacturerId: number; - productType: number; - productId: number; - applicationVersion: string; -} - -export interface ProvisioningInformation_MaxInclusionRequestInterval { - maxInclusionRequestInterval: number; -} - -export interface ProvisioningInformation_UUID16 { - uuid: string; -} - -export interface ProvisioningInformation_SupportedProtocols { - supportedProtocols: Protocols[]; -} - -export type QRProvisioningInformation = - & { - version: QRCodeVersion; - /** - * The security classes that were **requested** by the device. - */ - readonly requestedSecurityClasses: SecurityClass[]; - /** - * The security classes that will be **granted** to this device. - * Until this has been changed by a user, this will be identical to {@link requestedSecurityClasses}. - */ - securityClasses: SecurityClass[]; - dsk: string; - } - & ProvisioningInformation_ProductType - & ProvisioningInformation_ProductId - & Partial - & Partial - & Partial; - -function parseTLVData(type: ProvisioningInformationType, data: string) { - switch (type) { - case ProvisioningInformationType.ProductType: { - const deviceClasses = readUInt16(data, 0); - const installerIconType = readUInt16(data, 5); - const ret: ProvisioningInformation_ProductType = { - genericDeviceClass: deviceClasses >>> 8, - specificDeviceClass: deviceClasses & 0xff, - installerIconType, - }; - return ret; - } - - case ProvisioningInformationType.ProductId: { - const manufacturerId = readUInt16(data, 0); - const productType = readUInt16(data, 5); - const productId = readUInt16(data, 10); - const applicationVersionNumeric = readUInt16(data, 15); - const applicationVersion = `${applicationVersionNumeric >>> 8}.${ - applicationVersionNumeric & 0xff - }`; - const ret: ProvisioningInformation_ProductId = { - manufacturerId, - productType, - productId, - applicationVersion, - }; - return ret; - } - - case ProvisioningInformationType.MaxInclusionRequestInterval: { - const maxInclusionRequestInterval = 128 * readLevel(data, 0); - const ret: ProvisioningInformation_MaxInclusionRequestInterval = { - maxInclusionRequestInterval, - }; - return ret; - } - - case ProvisioningInformationType.UUID16: { - const buffer = new Bytes(16); - // Only format 0 is supported here - const presentationFormat = readLevel(data, 0); - if (presentationFormat !== 0) return; - - for (let chunk = 0; chunk < 8; chunk++) { - const value = readUInt16(data, 2 + chunk * 5); - buffer.writeUInt16BE(value, chunk * 2); - } - const ret: ProvisioningInformation_UUID16 = { - uuid: buffer.toString("hex"), - }; - return ret; - } - - case ProvisioningInformationType.SupportedProtocols: { - const bitMask = Uint8Array.from([ - data.length === 2 - ? readLevel(data, 0) - : data.length === 3 - ? readUInt8(data, 0) - : data.length === 5 - ? readUInt16(data, 0) - : 0, - ]); - const supportedProtocols = parseBitMask(bitMask, Protocols.ZWave); - const ret: ProvisioningInformation_SupportedProtocols = { - supportedProtocols, - }; - return ret; - } - } -} - -function parseTLV(qr: string): { - entry: { - type: ProvisioningInformationType; - } & Record; - charsRead: number; -} { - let offset = 0; - if (qr.length - offset < 4) fail("incomplete TLV block"); - const typeCritical = readLevel(qr, offset); - const type = typeCritical >>> 1; - const critical = !!(typeCritical & 0b1); - const length = readLevel(qr, offset + 2); - offset += 4; - if (qr.length - offset < length) fail("incomplete TLV block"); - - const data = qr.slice(offset, offset + length); - offset += length; - - // Try to parse the raw data and fail if a critical block is not understood - const parsed = parseTLVData(type, data); - if (!parsed && critical) fail("Unsupported critical TLV block"); - - let entry: any; - if (parsed) { - entry = { - type, - ...parsed, - }; - } else { - entry = { - type, - [ProvisioningInformationType[type]]: data, - }; - } - - return { - entry, - charsRead: offset, - }; -} - -/** Parses a string that has been decoded from a Z-Wave (S2 or SmartStart) QR code */ -export function parseQRCodeString(qr: string): QRProvisioningInformation { - // Trim off whitespace that might have been copied by accident - qr = qr.trim(); - // Validate the QR code - if (!qr.startsWith("90")) fail("must start with 90"); - if (qr.length < minQRCodeLength) fail("too short"); - if (!onlyDigitsRegex.test(qr)) fail("contains invalid characters"); - - const version = readLevel(qr, 2); - if (version > QRCodeVersion.SmartStart) fail("invalid version"); - - const checksum = readUInt16(qr, 4); - // The checksum covers the remaining data - const hash = createHash("sha1"); - hash.update(Bytes.from(qr.slice(9), "ascii")); - const expectedChecksum = hash.digest().readUInt16BE(0); - if (checksum !== expectedChecksum) fail("invalid checksum"); - - const requestedKeysBitmask = readUInt8(qr, 9); - const requestedSecurityClasses = parseBitMask( - [requestedKeysBitmask], - SecurityClass.S2_Unauthenticated, - ); - if (!requestedSecurityClasses.every((k) => k in SecurityClass)) { - fail("invalid security class requested"); - } - - let offset = 12; - const dsk = new Bytes(16); - for (let dskBlock = 0; dskBlock < 8; dskBlock++) { - const block = readUInt16(qr, offset); - dsk.writeUInt16BE(block, dskBlock * 2); - offset += 5; - } - - const ret = { - version, - // This seems like a duplication, but it's more convenient for applications to not have to copy this field over - requestedSecurityClasses, - securityClasses: [...requestedSecurityClasses], - dsk: dskToString(dsk), - } as QRProvisioningInformation; - - let hasProductID = false; - let hasProductType = false; - - while (offset < qr.length) { - const { - entry: { type, ...data }, - charsRead, - } = parseTLV(qr.slice(offset)); - offset += charsRead; - - if (type === ProvisioningInformationType.ProductId) { - hasProductID = true; - } else if (type === ProvisioningInformationType.ProductType) { - hasProductType = true; - } - Object.assign(ret, data); - } - - // Ensure the required fields are present - if (!hasProductID || !hasProductType) { - fail("missing required fields"); - } - - return ret; -} diff --git a/packages/core/src/security/shared_safe.ts b/packages/core/src/security/shared_safe.ts deleted file mode 100644 index c3e88c2003d9..000000000000 --- a/packages/core/src/security/shared_safe.ts +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Tries to extract a DSK from a scanned QR code. If the string is a valid DSK (prefixed with "zws2dsk:" or unprefixed), the DSK will be returned. - * This can then be used to initiate an S2 inclusion with pre-filled DSK. - */ -export function tryParseDSKFromQRCodeString(qr: string): string | undefined { - // Trim off whitespace that might have been copied by accident - qr = qr.trim(); - if (qr.startsWith("zws2dsk:")) { - qr = qr.slice("zws2dsk:".length); - } - if (isValidDSK(qr)) { - return qr; - } -} - -export function isValidDSK(dsk: string): boolean { - const patternMatches = /^(\d{5}-){7}\d{5}$/.test(dsk); - if (!patternMatches) return false; - - return dsk - .split("-") - .map((p) => parseInt(p, 10)) - .every((p) => p <= 0xffff); -} diff --git a/packages/core/src/traits/CommandClasses.ts b/packages/core/src/traits/CommandClasses.ts index 34dbd3dcb6dc..9e8d9593900c 100644 --- a/packages/core/src/traits/CommandClasses.ts +++ b/packages/core/src/traits/CommandClasses.ts @@ -1,12 +1,12 @@ -import type { - CommandClassInfo, - CommandClasses, -} from "../capabilities/CommandClasses.js"; import type { MulticastDestination, NODE_ID_BROADCAST, NODE_ID_BROADCAST_LR, } from "../consts/index.js"; +import type { + CommandClassInfo, + CommandClasses, +} from "../definitions/CommandClasses.js"; /** Identifies which node and/or endpoint a CC is addressed to */ export interface CCAddress { diff --git a/packages/core/src/traits/Nodes.ts b/packages/core/src/traits/Nodes.ts index 31fe43dd98f7..9b3cf0bc009c 100644 --- a/packages/core/src/traits/Nodes.ts +++ b/packages/core/src/traits/Nodes.ts @@ -1,5 +1,5 @@ -import { type FLiRS } from "../capabilities/NodeInfo.js"; import { type NodeStatus } from "../consts/NodeStatus.js"; +import { type FLiRS } from "../definitions/NodeInfo.js"; import { type MaybeNotKnown } from "../values/Primitive.js"; import { type EndpointId, type VirtualEndpointId } from "./Endpoints.js"; diff --git a/packages/core/src/traits/SecurityClasses.ts b/packages/core/src/traits/SecurityClasses.ts new file mode 100644 index 000000000000..6d63a0d4c021 --- /dev/null +++ b/packages/core/src/traits/SecurityClasses.ts @@ -0,0 +1,20 @@ +import { type SecurityClass } from "../definitions/SecurityClass.js"; +import { type MaybeNotKnown } from "../values/Primitive.js"; + +/** Allows querying the security classes of a node */ + +export interface QuerySecurityClasses { + /** Whether the node was granted at least one security class */ + readonly isSecure: MaybeNotKnown; + + /** Returns whether a node was granted the given security class */ + hasSecurityClass(securityClass: SecurityClass): MaybeNotKnown; + + /** Returns the highest security class this node was granted or `undefined` if that information isn't known yet */ + getHighestSecurityClass(): MaybeNotKnown; +} +/** Allows modifying the security classes of a node */ + +export interface SetSecurityClass { + setSecurityClass(securityClass: SecurityClass, granted: boolean): void; +} diff --git a/packages/core/src/values/Cache.ts b/packages/core/src/values/Cache.ts index 0f53e603be24..99b61914d2c5 100644 --- a/packages/core/src/values/Cache.ts +++ b/packages/core/src/values/Cache.ts @@ -4,8 +4,7 @@ import { isUint8Array, uint8ArrayToHex, } from "@zwave-js/shared/safe"; -import { composeObject } from "alcalzone-shared/objects/index.js"; -import { isArray, isObject } from "alcalzone-shared/typeguards/index.js"; +import { isArray, isObject } from "alcalzone-shared/typeguards"; import { Duration } from "./Duration.js"; import type { ValueMetadata } from "./Metadata.js"; import type { ValueID } from "./_Types.js"; @@ -37,7 +36,7 @@ export function serializeCacheValue(value: unknown): SerializedValue { if (value instanceof Map) { // We mark maps with a special key, so they can be detected by the deserialization routine return { - ...composeObject( + ...Object.fromEntries( [...value.entries()].map(([k, v]) => [ k, serializeCacheValue(v), diff --git a/packages/core/src/values/Duration.ts b/packages/core/src/values/Duration.ts index c556064f99f4..0e3e228dfdd5 100644 --- a/packages/core/src/values/Duration.ts +++ b/packages/core/src/values/Duration.ts @@ -1,5 +1,5 @@ import type { JSONObject } from "@zwave-js/shared"; -import { clamp } from "alcalzone-shared/math/index.js"; +import { clamp } from "alcalzone-shared/math"; import { ZWaveError, ZWaveErrorCodes } from "../error/ZWaveError.js"; export type DurationUnit = "seconds" | "minutes" | "unknown" | "default"; diff --git a/packages/core/src/values/Timeout.ts b/packages/core/src/values/Timeout.ts index 1d6c6333aa0c..e1180e27ddb6 100644 --- a/packages/core/src/values/Timeout.ts +++ b/packages/core/src/values/Timeout.ts @@ -1,5 +1,5 @@ import type { JSONObject } from "@zwave-js/shared"; -import { clamp } from "alcalzone-shared/math/index.js"; +import { clamp } from "alcalzone-shared/math"; export type TimeoutUnit = "seconds" | "minutes" | "none" | "infinite"; diff --git a/packages/core/src/values/ValueDB.test.ts b/packages/core/src/values/ValueDB.test.ts index b036509da526..c317c1ed8002 100644 --- a/packages/core/src/values/ValueDB.test.ts +++ b/packages/core/src/values/ValueDB.test.ts @@ -1,7 +1,7 @@ import { pick } from "@zwave-js/shared/safe"; import sinon from "sinon"; import { test } from "vitest"; -import { CommandClasses } from "../capabilities/CommandClasses.js"; +import { CommandClasses } from "../definitions/CommandClasses.js"; import { ZWaveErrorCodes } from "../error/ZWaveError.js"; import { assertZWaveError } from "../test/assertZWaveError.js"; import { ValueMetadata } from "./Metadata.js"; diff --git a/packages/core/src/values/ValueDB.ts b/packages/core/src/values/ValueDB.ts index 009a5fe9e3f4..8673b033f4d8 100644 --- a/packages/core/src/values/ValueDB.ts +++ b/packages/core/src/values/ValueDB.ts @@ -1,6 +1,6 @@ import type { JsonlDB } from "@alcalzone/jsonl-db"; import { TypedEventEmitter } from "@zwave-js/shared"; -import type { CommandClasses } from "../capabilities/CommandClasses.js"; +import type { CommandClasses } from "../definitions/CommandClasses.js"; import { ZWaveError, ZWaveErrorCodes, diff --git a/packages/core/src/values/_Types.ts b/packages/core/src/values/_Types.ts index 797541f4d09f..bf8ba63179c0 100644 --- a/packages/core/src/values/_Types.ts +++ b/packages/core/src/values/_Types.ts @@ -1,4 +1,4 @@ -import type { CommandClasses } from "../capabilities/CommandClasses.js"; +import type { CommandClasses } from "../definitions/CommandClasses.js"; import type { ValueMetadata } from "./Metadata.js"; /** Uniquely identifies to which CC, endpoint and property a value belongs to */ diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 2aa0727adab0..bb9cc2ba0519 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -38,7 +38,7 @@ "lint:ts:fix": "yarn run lint:ts --fix" }, "devDependencies": { - "@alcalzone/esm2cjs": "^1.2.3", + "@alcalzone/esm2cjs": "^1.3.0", "@types/eslint": "^9.6.1", "@typescript-eslint/utils": "^8.8.1", "@zwave-js/core": "workspace:*", diff --git a/packages/eslint-plugin/src/rules/no-forbidden-imports.ts b/packages/eslint-plugin/src/rules/no-forbidden-imports.ts index ea7b5d133a57..f5360129fad7 100644 --- a/packages/eslint-plugin/src/rules/no-forbidden-imports.ts +++ b/packages/eslint-plugin/src/rules/no-forbidden-imports.ts @@ -6,15 +6,14 @@ import ts from "typescript"; // Whitelist some imports that are known not to import forbidden modules const whitelistedImports = [ "reflect-metadata", - "alcalzone-shared/arrays/index.js", - "alcalzone-shared/async/index.js", - "alcalzone-shared/comparable/index.js", - "alcalzone-shared/deferred-promise/index.js", - "alcalzone-shared/math/index.js", - "alcalzone-shared/objects/index.js", - "alcalzone-shared/sorted-list/index.js", - "alcalzone-shared/strings/index.js", - "alcalzone-shared/typeguards/index.js", + "alcalzone-shared/arrays", + "alcalzone-shared/async", + "alcalzone-shared/comparable", + "alcalzone-shared/deferred-promise", + "alcalzone-shared/helpers", + "alcalzone-shared/math", + "alcalzone-shared/sorted-list", + "alcalzone-shared/typeguards", ]; // Whitelist some more imports that should be ignored in the checking diff --git a/packages/flash/src/cli.ts b/packages/flash/src/cli.ts index 793fe3d59729..63c094a7748c 100644 --- a/packages/flash/src/cli.ts +++ b/packages/flash/src/cli.ts @@ -1,5 +1,5 @@ import { ZWaveErrorCodes, isZWaveError } from "@zwave-js/core/safe"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import fs from "node:fs/promises"; import path from "node:path"; import yargs from "yargs"; diff --git a/packages/host/package.json b/packages/host/package.json index 880ed007ee8c..3f43adc6e8d0 100644 --- a/packages/host/package.json +++ b/packages/host/package.json @@ -55,10 +55,10 @@ "@zwave-js/config": "workspace:*", "@zwave-js/core": "workspace:*", "@zwave-js/shared": "workspace:*", - "alcalzone-shared": "^4.0.8" + "alcalzone-shared": "^5.0.0" }, "devDependencies": { - "@alcalzone/esm2cjs": "^1.2.3", + "@alcalzone/esm2cjs": "^1.3.0", "@microsoft/api-extractor": "^7.47.9", "@types/node": "^18.19.63", "del-cli": "^6.0.0", diff --git a/packages/maintenance/package.json b/packages/maintenance/package.json index 37e59b2ee501..f18ffefe4abe 100644 --- a/packages/maintenance/package.json +++ b/packages/maintenance/package.json @@ -38,7 +38,7 @@ "lint:ts:fix": "yarn run lint:ts --fix" }, "devDependencies": { - "@alcalzone/esm2cjs": "^1.2.3", + "@alcalzone/esm2cjs": "^1.3.0", "@dprint/formatter": "^0.4.1", "@dprint/json": "^0.19.4", "@dprint/markdown": "^0.17.8", diff --git a/packages/nvmedit/package.json b/packages/nvmedit/package.json index 50f19f679c14..5f49ab324a6f 100644 --- a/packages/nvmedit/package.json +++ b/packages/nvmedit/package.json @@ -10,6 +10,7 @@ "exports": { ".": { "@@dev": "./src/index.ts", + "browser": "./build/esm/index_browser.js", "import": "./build/esm/index.js", "require": "./build/cjs/index.js" }, @@ -48,7 +49,7 @@ "dependencies": { "@zwave-js/core": "workspace:*", "@zwave-js/shared": "workspace:*", - "alcalzone-shared": "^4.0.8", + "alcalzone-shared": "^5.0.0", "reflect-metadata": "^0.2.2", "semver": "^7.6.3", "yargs": "^17.7.2" @@ -64,7 +65,7 @@ "test:dirty": "tsx ../maintenance/src/resolveDirtyTests.ts --run" }, "devDependencies": { - "@alcalzone/esm2cjs": "^1.2.3", + "@alcalzone/esm2cjs": "^1.3.0", "@microsoft/api-extractor": "^7.47.9", "@types/node": "^18.19.63", "@types/semver": "^7.5.8", diff --git a/packages/nvmedit/src/cli.ts b/packages/nvmedit/src/cli.ts index 724be36b920a..1d14aead6dc6 100644 --- a/packages/nvmedit/src/cli.ts +++ b/packages/nvmedit/src/cli.ts @@ -1,5 +1,5 @@ import { readJSON } from "@zwave-js/shared"; -import { isObject } from "alcalzone-shared/typeguards/index.js"; +import { isObject } from "alcalzone-shared/typeguards"; import fs from "node:fs/promises"; import "reflect-metadata"; import yargs from "yargs"; diff --git a/packages/nvmedit/src/convert.ts b/packages/nvmedit/src/convert.ts index acb6fdb3a63b..04d5a6698ef1 100644 --- a/packages/nvmedit/src/convert.ts +++ b/packages/nvmedit/src/convert.ts @@ -18,7 +18,7 @@ import { num2hex, pick, } from "@zwave-js/shared/safe"; -import { isObject } from "alcalzone-shared/typeguards/index.js"; +import { isObject } from "alcalzone-shared/typeguards"; import semver from "semver"; import { MAX_PROTOCOL_FILE_FORMAT, SUC_MAX_UPDATES } from "./consts.js"; import { NVM3, type NVM3Meta } from "./lib/NVM3.js"; diff --git a/packages/nvmedit/src/index.ts b/packages/nvmedit/src/index.ts index b3d8d5e40553..39bfcfc277b0 100644 --- a/packages/nvmedit/src/index.ts +++ b/packages/nvmedit/src/index.ts @@ -46,11 +46,7 @@ export { PageStatus, PageWriteSize, } from "./lib/nvm3/consts.js"; -export { - ControllerInfoFile, - ControllerInfoFileID, - NVMFile, -} from "./lib/nvm3/files/index.js"; +export * from "./lib/nvm3/files/index.js"; export type { NVM3Object } from "./lib/nvm3/object.js"; export type { NVM3Page, NVM3PageHeader } from "./lib/nvm3/page.js"; export { NVM500Adapter } from "./lib/nvm500/adapter.js"; diff --git a/packages/nvmedit/src/index_browser.ts b/packages/nvmedit/src/index_browser.ts new file mode 100644 index 000000000000..282f5013ee6c --- /dev/null +++ b/packages/nvmedit/src/index_browser.ts @@ -0,0 +1,46 @@ +/* @forbiddenImports external */ + +import "reflect-metadata"; + +export type { + NVMJSON, + NVMJSONController, + NVMJSONControllerRFConfig, + NVMJSONNode, + NVMJSONNodeWithInfo, + NVMJSONVirtualNode, +} from "./convert.js"; +export type { NVM3EraseOptions, NVM3Meta } from "./lib/NVM3.js"; +export type { NVM500EraseOptions, NVM500Info } from "./lib/NVM500.js"; +export { NVMAccess } from "./lib/common/definitions.js"; +export type { + ControllerNVMProperty, + ControllerNVMPropertyToDataType, + LRNodeNVMProperty, + LRNodeNVMPropertyToDataType, + NVM, + NVMAdapter, + NVMIO, + NVMProperty, + NVMPropertyToDataType, + NodeNVMProperty, + NodeNVMPropertyToDataType, +} from "./lib/common/definitions.js"; +export { BufferedNVMReader } from "./lib/io/BufferedNVMReader.js"; +export { + FragmentType, + ObjectType, + PageStatus, + PageWriteSize, +} from "./lib/nvm3/consts.js"; +export type { NVM3Object } from "./lib/nvm3/object.js"; +export type { NVM3Page, NVM3PageHeader } from "./lib/nvm3/page.js"; +export type { + NVM500JSON, + NVM500JSONController, + NVM500JSONControllerRFConfig, + NVM500JSONNode, + NVM500JSONNodeWithInfo, + NVM500JSONVirtualNode, + NVM500Meta, +} from "./nvm500/NVMParser.js"; diff --git a/packages/nvmedit/src/index_safe.ts b/packages/nvmedit/src/index_safe.ts index 2da1a76f1223..282f5013ee6c 100644 --- a/packages/nvmedit/src/index_safe.ts +++ b/packages/nvmedit/src/index_safe.ts @@ -26,6 +26,7 @@ export type { NodeNVMProperty, NodeNVMPropertyToDataType, } from "./lib/common/definitions.js"; +export { BufferedNVMReader } from "./lib/io/BufferedNVMReader.js"; export { FragmentType, ObjectType, diff --git a/packages/nvmedit/src/lib/NVM3.ts b/packages/nvmedit/src/lib/NVM3.ts index 69e440340f9f..590ee133a577 100644 --- a/packages/nvmedit/src/lib/NVM3.ts +++ b/packages/nvmedit/src/lib/NVM3.ts @@ -1,5 +1,5 @@ -import { ZWaveError, ZWaveErrorCodes } from "@zwave-js/core"; -import { Bytes, getEnumMemberName, num2hex } from "@zwave-js/shared"; +import { ZWaveError, ZWaveErrorCodes } from "@zwave-js/core/safe"; +import { Bytes, getEnumMemberName, num2hex } from "@zwave-js/shared/safe"; import { type NVM, NVMAccess, type NVMIO } from "./common/definitions.js"; import { nvmReadBuffer, diff --git a/packages/nvmedit/src/lib/nvm3/adapter.ts b/packages/nvmedit/src/lib/nvm3/adapter.ts index faa60d5080b3..d6ad0b744bb4 100644 --- a/packages/nvmedit/src/lib/nvm3/adapter.ts +++ b/packages/nvmedit/src/lib/nvm3/adapter.ts @@ -1,6 +1,6 @@ -import { ZWaveError, ZWaveErrorCodes } from "@zwave-js/core"; -import { num2hex } from "@zwave-js/shared"; -import { assertNever } from "alcalzone-shared/helpers/index.js"; +import { ZWaveError, ZWaveErrorCodes } from "@zwave-js/core/safe"; +import { num2hex } from "@zwave-js/shared/safe"; +import { assertNever } from "alcalzone-shared/helpers"; import { SUC_MAX_UPDATES } from "../../consts.js"; import { type NVM3 } from "../NVM3.js"; import { diff --git a/packages/nvmedit/src/lib/nvm500/EntryParsers.ts b/packages/nvmedit/src/lib/nvm500/EntryParsers.ts index a0d3051a8746..aa01e5492c7e 100644 --- a/packages/nvmedit/src/lib/nvm500/EntryParsers.ts +++ b/packages/nvmedit/src/lib/nvm500/EntryParsers.ts @@ -4,7 +4,6 @@ import { parseNodeProtocolInfo, } from "@zwave-js/core/safe"; import { Bytes } from "@zwave-js/shared/safe"; -import { padStart } from "alcalzone-shared/strings/index.js"; import type { NVMModuleType } from "./shared.js"; export interface NVMDescriptor { @@ -29,8 +28,7 @@ export function parseNVMDescriptor( firmwareVersion: `${buffer[offset + 8]}.${buffer[offset + 9]}`, // Z-Wave protocol versions are formatted as "6.07" and similar protocolVersion: `${buffer[offset + 10]}.${ - padStart( - buffer[offset + 11].toString(), + buffer[offset + 11].toString().padStart( 2, "0", ) diff --git a/packages/nvmedit/src/lib/nvm500/adapter.ts b/packages/nvmedit/src/lib/nvm500/adapter.ts index 6bda4f4324e0..83afaa794774 100644 --- a/packages/nvmedit/src/lib/nvm500/adapter.ts +++ b/packages/nvmedit/src/lib/nvm500/adapter.ts @@ -4,7 +4,7 @@ import { ZWaveErrorCodes, } from "@zwave-js/core"; import { Bytes } from "@zwave-js/shared"; -import { assertNever } from "alcalzone-shared/helpers/index.js"; +import { assertNever } from "alcalzone-shared/helpers"; import { SUC_MAX_UPDATES } from "../../consts.js"; import { type NVM500, type NVM500Info } from "../NVM500.js"; import { diff --git a/packages/serial/package.json b/packages/serial/package.json index 707a2be0f5ec..aa669e1a4c79 100644 --- a/packages/serial/package.json +++ b/packages/serial/package.json @@ -69,12 +69,12 @@ "@zwave-js/core": "workspace:*", "@zwave-js/host": "workspace:*", "@zwave-js/shared": "workspace:*", - "alcalzone-shared": "^4.0.8", + "alcalzone-shared": "^5.0.0", "serialport": "^12.0.0", "winston": "^3.15.0" }, "devDependencies": { - "@alcalzone/esm2cjs": "^1.2.3", + "@alcalzone/esm2cjs": "^1.3.0", "@microsoft/api-extractor": "^7.47.9", "@serialport/binding-mock": "^10.2.2", "@serialport/bindings-interface": "patch:@serialport/bindings-interface@npm%3A1.2.2#~/.yarn/patches/@serialport-bindings-interface-npm-1.2.2-e597dbc676.patch", diff --git a/packages/serial/src/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts b/packages/serial/src/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts index 434692725659..f65e023edb95 100644 --- a/packages/serial/src/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts +++ b/packages/serial/src/serialapi/network-mgmt/GetNodeProtocolInfoMessages.ts @@ -25,7 +25,7 @@ import { priority, } from "@zwave-js/serial"; import { Bytes } from "@zwave-js/shared"; -import { isObject } from "alcalzone-shared/typeguards/index.js"; +import { isObject } from "alcalzone-shared/typeguards"; export interface GetNodeProtocolInfoRequestOptions { requestedNodeId: number; diff --git a/packages/serial/src/serialapi/transport/SendDataBridgeMessages.ts b/packages/serial/src/serialapi/transport/SendDataBridgeMessages.ts index 65c68ba0f9d8..8a573a177385 100644 --- a/packages/serial/src/serialapi/transport/SendDataBridgeMessages.ts +++ b/packages/serial/src/serialapi/transport/SendDataBridgeMessages.ts @@ -33,7 +33,7 @@ import { priority, } from "@zwave-js/serial"; import { Bytes, getEnumMemberName, num2hex } from "@zwave-js/shared"; -import { clamp } from "alcalzone-shared/math/index.js"; +import { clamp } from "alcalzone-shared/math"; import { ApplicationCommandRequest } from "../application/ApplicationCommandRequest.js"; import { BridgeApplicationCommandRequest } from "../application/BridgeApplicationCommandRequest.js"; import { type MessageWithCC, containsCC } from "../utils.js"; diff --git a/packages/serial/src/serialapi/transport/SendDataMessages.ts b/packages/serial/src/serialapi/transport/SendDataMessages.ts index 23c423182419..6d620813d6ae 100644 --- a/packages/serial/src/serialapi/transport/SendDataMessages.ts +++ b/packages/serial/src/serialapi/transport/SendDataMessages.ts @@ -32,7 +32,7 @@ import { priority, } from "@zwave-js/serial"; import { Bytes, getEnumMemberName, num2hex } from "@zwave-js/shared"; -import { clamp } from "alcalzone-shared/math/index.js"; +import { clamp } from "alcalzone-shared/math"; import { ApplicationCommandRequest } from "../application/ApplicationCommandRequest.js"; import { BridgeApplicationCommandRequest } from "../application/BridgeApplicationCommandRequest.js"; import { type MessageWithCC, containsCC } from "../utils.js"; diff --git a/packages/serial/src/serialport/ZWaveSerialPort.test.ts b/packages/serial/src/serialport/ZWaveSerialPort.test.ts index 1e7a1a0af814..b801d8cec252 100644 --- a/packages/serial/src/serialport/ZWaveSerialPort.test.ts +++ b/packages/serial/src/serialport/ZWaveSerialPort.test.ts @@ -1,5 +1,5 @@ import { Bytes } from "@zwave-js/shared/safe"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { PassThrough } from "node:stream"; import sinon from "sinon"; import { afterEach, beforeEach, test } from "vitest"; diff --git a/packages/serial/src/serialport/ZWaveSerialPortImplementation.ts b/packages/serial/src/serialport/ZWaveSerialPortImplementation.ts index 82a8267b598d..4e185210f2ff 100644 --- a/packages/serial/src/serialport/ZWaveSerialPortImplementation.ts +++ b/packages/serial/src/serialport/ZWaveSerialPortImplementation.ts @@ -1,4 +1,4 @@ -import { isObject } from "alcalzone-shared/typeguards/index.js"; +import { isObject } from "alcalzone-shared/typeguards"; import { type EventEmitter } from "node:events"; import { type Duplex } from "node:stream"; diff --git a/packages/shared/package.json b/packages/shared/package.json index 26347a8ce090..75031aba36e8 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -10,6 +10,7 @@ "exports": { ".": { "@@dev": "./src/index.ts", + "browser": "./build/esm/index_browser.js", "import": "./build/esm/index.js", "require": "./build/cjs/index.js" }, @@ -20,6 +21,7 @@ }, "./package.json": "./package.json" }, + "sideEffects": false, "files": [ "build/**/*.{js,cjs,mjs,d.ts,d.cts,d.mts,map}", "build/**/package.json" @@ -44,7 +46,7 @@ "node": ">= 18" }, "dependencies": { - "alcalzone-shared": "^4.0.8" + "alcalzone-shared": "^5.0.0" }, "scripts": { "build": "tsc -b tsconfig.build.json --pretty && yarn postbuild", @@ -57,7 +59,7 @@ "test:dirty": "tsx ../maintenance/src/resolveDirtyTests.ts --run" }, "devDependencies": { - "@alcalzone/esm2cjs": "^1.2.3", + "@alcalzone/esm2cjs": "^1.3.0", "@microsoft/api-extractor": "^7.47.9", "@types/node": "^18.19.63", "@types/sinon": "^17.0.3", diff --git a/packages/shared/src/AsyncQueue.test.ts b/packages/shared/src/AsyncQueue.test.ts index f1ce517151fd..a372398e1323 100644 --- a/packages/shared/src/AsyncQueue.test.ts +++ b/packages/shared/src/AsyncQueue.test.ts @@ -1,4 +1,4 @@ -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { test } from "vitest"; import { AsyncQueue } from "./AsyncQueue.js"; diff --git a/packages/shared/src/AsyncQueue.ts b/packages/shared/src/AsyncQueue.ts index e9ddcc3f7bf6..1b612db3a0a2 100644 --- a/packages/shared/src/AsyncQueue.ts +++ b/packages/shared/src/AsyncQueue.ts @@ -1,7 +1,7 @@ import { type DeferredPromise, createDeferredPromise, -} from "alcalzone-shared/deferred-promise/index.js"; +} from "alcalzone-shared/deferred-promise"; export class AsyncQueue implements AsyncIterable { /** Adds one or more items onto the queue */ diff --git a/packages/shared/src/ObjectKeyMap.ts b/packages/shared/src/ObjectKeyMap.ts index de787b17b01a..995ab8d2ba17 100644 --- a/packages/shared/src/ObjectKeyMap.ts +++ b/packages/shared/src/ObjectKeyMap.ts @@ -1,5 +1,3 @@ -import { composeObject, entries } from "alcalzone-shared/objects/index.js"; - export class ObjectKeyMap, TValue> { public constructor( entries?: [TKey, TValue][], @@ -93,8 +91,8 @@ export class ObjectKeyMap, TValue> { if (!(required in filledKey)) filledKey[required as any] = def; } } - const _key = composeObject( - entries(filledKey) + const _key = Object.fromEntries( + Object.entries(filledKey) .filter(([, value]) => value != undefined) .sort(([keyA], [keyB]) => keyA > keyB ? 1 : keyA < keyB ? -1 : 0 diff --git a/packages/shared/src/TimedExpectation.ts b/packages/shared/src/TimedExpectation.ts index 560fecb471ec..e9c57e1cbfef 100644 --- a/packages/shared/src/TimedExpectation.ts +++ b/packages/shared/src/TimedExpectation.ts @@ -1,7 +1,7 @@ import { type DeferredPromise, createDeferredPromise, -} from "alcalzone-shared/deferred-promise/index.js"; +} from "alcalzone-shared/deferred-promise"; /** Allows waiting for something for a given amount of time, after which the expectation will automatically be rejected. */ export class TimedExpectation diff --git a/packages/shared/src/index_browser.ts b/packages/shared/src/index_browser.ts new file mode 100644 index 000000000000..2ca7b4401be9 --- /dev/null +++ b/packages/shared/src/index_browser.ts @@ -0,0 +1,20 @@ +/* @forbiddenImports external */ + +export * from "./AsyncQueue.js"; +export { Bytes } from "./Bytes.js"; +export { ObjectKeyMap } from "./ObjectKeyMap.js"; +export type { ReadonlyObjectKeyMap } from "./ObjectKeyMap.js"; +export * from "./ThrowingMap.js"; +export * from "./TimedExpectation.js"; +export * from "./strings.js"; +export type * from "./types.js"; +export { + areUint8ArraysEqual, + assertUint8Array, + hexToUint8Array, + isUint8Array, + uint8ArrayToHex, + uint8ArrayToString, +} from "./uint8array-extras.js"; +export * from "./utils.js"; +export * from "./wrappingCounter.js"; diff --git a/packages/shared/src/index_safe.ts b/packages/shared/src/index_safe.ts index b2a2adf00ae7..8f28aebdfb29 100644 --- a/packages/shared/src/index_safe.ts +++ b/packages/shared/src/index_safe.ts @@ -1,6 +1,7 @@ /* eslint-disable @typescript-eslint/consistent-type-exports */ /* @forbiddenImports external */ +export * from "./AsyncQueue.js"; export { Bytes } from "./Bytes.js"; export { ObjectKeyMap } from "./ObjectKeyMap.js"; export type { ReadonlyObjectKeyMap } from "./ObjectKeyMap.js"; diff --git a/packages/shared/src/strings.ts b/packages/shared/src/strings.ts index 2e81b40e38e3..a32bc79c575c 100644 --- a/packages/shared/src/strings.ts +++ b/packages/shared/src/strings.ts @@ -1,4 +1,3 @@ -import { padStart } from "alcalzone-shared/strings/index.js"; import { Bytes } from "./Bytes.js"; import { uint8ArrayToHex } from "./uint8array-extras.js"; @@ -33,7 +32,7 @@ export function num2hex( */ export function formatId(id: number | string): string { id = typeof id === "number" ? id.toString(16) : id; - return "0x" + padStart(id, 4, "0").toLowerCase(); + return "0x" + id.padStart(4, "0").toLowerCase(); } export function stringify(arg: unknown, space: 4 | "\t" = 4): string { @@ -72,23 +71,15 @@ export function compareStrings(a: string, b: string): number { } export function formatTime(hour: number, minute: number): string { - return `${padStart(hour.toString(), 2, "0")}:${ - padStart( - minute.toString(), - 2, - "0", - ) + return `${hour.toString().padStart(2, "0")}:${ + minute.toString().padStart(2, "0") }`; } export function formatDate(year: number, month: number, day: number): string { - return `${padStart(year.toString(), 4, "0")}-${ - padStart( - month.toString(), - 2, - "0", - ) - }-${padStart(day.toString(), 2, "0")}`; + return `${year.toString().padStart(4, "0")}-${ + month.toString().padStart(2, "0") + }-${day.toString().padStart(2, "0")}`; } export function stringToUint8ArrayUTF16BE(str: string): Uint8Array { diff --git a/packages/shared/src/utils.ts b/packages/shared/src/utils.ts index c4f44ac7d1dc..fc9272e5ebf4 100644 --- a/packages/shared/src/utils.ts +++ b/packages/shared/src/utils.ts @@ -1,4 +1,4 @@ -import { isArray, isObject } from "alcalzone-shared/typeguards/index.js"; +import { isArray, isObject } from "alcalzone-shared/typeguards"; import { num2hex } from "./strings.js"; /** Object.keys, but with `(keyof T)[]` as the return type */ diff --git a/packages/testing/package.json b/packages/testing/package.json index b82d39a401f5..40e7f30d62bb 100644 --- a/packages/testing/package.json +++ b/packages/testing/package.json @@ -51,11 +51,11 @@ "@zwave-js/host": "workspace:*", "@zwave-js/serial": "workspace:*", "@zwave-js/shared": "workspace:*", - "alcalzone-shared": "^4.0.8", + "alcalzone-shared": "^5.0.0", "ansi-colors": "^4.1.3" }, "devDependencies": { - "@alcalzone/esm2cjs": "^1.2.3", + "@alcalzone/esm2cjs": "^1.3.0", "@microsoft/api-extractor": "^7.47.9", "@types/node": "^18.19.63", "@types/triple-beam": "^1.3.5", diff --git a/packages/testing/src/MockController.ts b/packages/testing/src/MockController.ts index abb3ce700833..a4179eb99180 100644 --- a/packages/testing/src/MockController.ts +++ b/packages/testing/src/MockController.ts @@ -19,7 +19,7 @@ import { import type { MockPortBinding } from "@zwave-js/serial/mock"; import { AsyncQueue } from "@zwave-js/shared"; import { TimedExpectation } from "@zwave-js/shared/safe"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { randomInt } from "node:crypto"; import { type MockControllerCapabilities, diff --git a/packages/zwave-js/package.json b/packages/zwave-js/package.json index 8bf1de1832a9..9651e0b39d77 100644 --- a/packages/zwave-js/package.json +++ b/packages/zwave-js/package.json @@ -107,7 +107,7 @@ "@zwave-js/serial": "workspace:*", "@zwave-js/shared": "workspace:*", "@zwave-js/testing": "workspace:*", - "alcalzone-shared": "^4.0.8", + "alcalzone-shared": "^5.0.0", "ansi-colors": "^4.1.3", "execa": "^5.1.1", "got": "^13.0.0", @@ -122,7 +122,7 @@ "xstate": "4.38.3" }, "devDependencies": { - "@alcalzone/esm2cjs": "^1.2.3", + "@alcalzone/esm2cjs": "^1.3.0", "@microsoft/api-extractor": "^7.47.9", "@types/node": "^18.19.63", "@types/proper-lockfile": "^4.1.4", diff --git a/packages/zwave-js/src/lib/controller/Controller.ts b/packages/zwave-js/src/lib/controller/Controller.ts index dea03ea19a1c..8864da102129 100644 --- a/packages/zwave-js/src/lib/controller/Controller.ts +++ b/packages/zwave-js/src/lib/controller/Controller.ts @@ -371,14 +371,14 @@ import { num2hex, pick, } from "@zwave-js/shared"; -import { distinct } from "alcalzone-shared/arrays/index.js"; -import { wait } from "alcalzone-shared/async/index.js"; +import { distinct } from "alcalzone-shared/arrays"; +import { wait } from "alcalzone-shared/async"; import { type DeferredPromise, createDeferredPromise, -} from "alcalzone-shared/deferred-promise/index.js"; -import { roundTo } from "alcalzone-shared/math/index.js"; -import { isObject } from "alcalzone-shared/typeguards/index.js"; +} from "alcalzone-shared/deferred-promise"; +import { roundTo } from "alcalzone-shared/math"; +import { isObject } from "alcalzone-shared/typeguards"; import crypto from "node:crypto"; import type { Driver } from "../driver/Driver.js"; import { cacheKeyUtils, cacheKeys } from "../driver/NetworkCache.js"; diff --git a/packages/zwave-js/src/lib/controller/ZWaveSDKVersions.ts b/packages/zwave-js/src/lib/controller/ZWaveSDKVersions.ts index f9a0fc8962fd..b4511f13f55a 100644 --- a/packages/zwave-js/src/lib/controller/ZWaveSDKVersions.ts +++ b/packages/zwave-js/src/lib/controller/ZWaveSDKVersions.ts @@ -1,5 +1,3 @@ -import { padStart } from "alcalzone-shared/strings/index.js"; - // Based on INS13954-13, chapter 7 const versions = Object.freeze([ // Z-Wave 700 uses 7.x SDK versions but also a different NVM format, @@ -338,7 +336,7 @@ const versions = Object.freeze([ function semverToLegacy(version: string): string { // eslint-disable-next-line @typescript-eslint/no-unused-vars const [major, minor, _patch] = version.split(".", 3); - return `${major}.${padStart(minor, 2, "0")}`; + return `${major}.${minor.toString().padStart(2, "0")}`; } /** diff --git a/packages/zwave-js/src/lib/controller/utils.ts b/packages/zwave-js/src/lib/controller/utils.ts index e67009b8c326..616db24021ea 100644 --- a/packages/zwave-js/src/lib/controller/utils.ts +++ b/packages/zwave-js/src/lib/controller/utils.ts @@ -5,7 +5,7 @@ import { ZWaveErrorCodes, isValidDSK, } from "@zwave-js/core/safe"; -import { isArray, isObject } from "alcalzone-shared/typeguards/index.js"; +import { isArray, isObject } from "alcalzone-shared/typeguards"; import { type Task } from "../driver/Task.js"; import { type PlannedProvisioningEntry, diff --git a/packages/zwave-js/src/lib/driver/Driver.ts b/packages/zwave-js/src/lib/driver/Driver.ts index 0cf8f4d3281f..bef9df66d1b3 100644 --- a/packages/zwave-js/src/lib/driver/Driver.ts +++ b/packages/zwave-js/src/lib/driver/Driver.ts @@ -177,13 +177,13 @@ import { pathExists, pick, } from "@zwave-js/shared"; -import { distinct } from "alcalzone-shared/arrays/index.js"; -import { wait } from "alcalzone-shared/async/index.js"; +import { distinct } from "alcalzone-shared/arrays"; +import { wait } from "alcalzone-shared/async"; import { type DeferredPromise, createDeferredPromise, -} from "alcalzone-shared/deferred-promise/index.js"; -import { isArray, isObject } from "alcalzone-shared/typeguards/index.js"; +} from "alcalzone-shared/deferred-promise"; +import { isArray, isObject } from "alcalzone-shared/typeguards"; import { randomBytes } from "node:crypto"; import type { EventEmitter } from "node:events"; import fs from "node:fs/promises"; diff --git a/packages/zwave-js/src/lib/driver/DriverMock.ts b/packages/zwave-js/src/lib/driver/DriverMock.ts index a83d8e465185..d2e48facd9ac 100644 --- a/packages/zwave-js/src/lib/driver/DriverMock.ts +++ b/packages/zwave-js/src/lib/driver/DriverMock.ts @@ -4,7 +4,7 @@ import { type MockPortBinding, SerialPortMock, } from "@zwave-js/serial/mock"; -import { createDeferredPromise } from "alcalzone-shared/deferred-promise/index.js"; +import { createDeferredPromise } from "alcalzone-shared/deferred-promise"; import fs from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; diff --git a/packages/zwave-js/src/lib/driver/MessageGenerators.ts b/packages/zwave-js/src/lib/driver/MessageGenerators.ts index 109c1cf88715..b378a6542db4 100644 --- a/packages/zwave-js/src/lib/driver/MessageGenerators.ts +++ b/packages/zwave-js/src/lib/driver/MessageGenerators.ts @@ -50,11 +50,11 @@ import { } from "@zwave-js/serial/serialapi"; import { type ContainsCC, containsCC } from "@zwave-js/serial/serialapi"; import { getErrorMessage } from "@zwave-js/shared"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { type DeferredPromise, createDeferredPromise, -} from "alcalzone-shared/deferred-promise/index.js"; +} from "alcalzone-shared/deferred-promise"; import type { Driver } from "./Driver.js"; import type { MessageGenerator } from "./Transaction.js"; diff --git a/packages/zwave-js/src/lib/driver/NetworkCache.ts b/packages/zwave-js/src/lib/driver/NetworkCache.ts index baa4fbc1053c..0a6914c16519 100644 --- a/packages/zwave-js/src/lib/driver/NetworkCache.ts +++ b/packages/zwave-js/src/lib/driver/NetworkCache.ts @@ -13,7 +13,7 @@ import { } from "@zwave-js/core"; import type { FileSystem } from "@zwave-js/host"; import { Bytes, getEnumMemberName, num2hex, pickDeep } from "@zwave-js/shared"; -import { isArray, isObject } from "alcalzone-shared/typeguards/index.js"; +import { isArray, isObject } from "alcalzone-shared/typeguards"; import path from "node:path"; import { ProvisioningEntryStatus, diff --git a/packages/zwave-js/src/lib/driver/Queue.ts b/packages/zwave-js/src/lib/driver/Queue.ts index 77d7d9e98237..b1d638022702 100644 --- a/packages/zwave-js/src/lib/driver/Queue.ts +++ b/packages/zwave-js/src/lib/driver/Queue.ts @@ -2,8 +2,8 @@ import { type Message } from "@zwave-js/serial"; import { type DeferredPromise, createDeferredPromise, -} from "alcalzone-shared/deferred-promise/index.js"; -import { SortedList } from "alcalzone-shared/sorted-list/index.js"; +} from "alcalzone-shared/deferred-promise"; +import { SortedList } from "alcalzone-shared/sorted-list"; import { type Transaction } from "./Transaction.js"; export interface TransactionQueueOptions { diff --git a/packages/zwave-js/src/lib/driver/SerialAPICommandMachine.test.ts b/packages/zwave-js/src/lib/driver/SerialAPICommandMachine.test.ts index ac65f84309e9..bf2bc6f388b7 100644 --- a/packages/zwave-js/src/lib/driver/SerialAPICommandMachine.test.ts +++ b/packages/zwave-js/src/lib/driver/SerialAPICommandMachine.test.ts @@ -3,7 +3,7 @@ import type { Message } from "@zwave-js/serial"; import { type DeferredPromise, createDeferredPromise, -} from "alcalzone-shared/deferred-promise/index.js"; +} from "alcalzone-shared/deferred-promise"; import sinon from "sinon"; import { type ExpectStatic, afterAll, beforeAll, test, vi } from "vitest"; import { Machine, type State, assign, interpret } from "xstate"; diff --git a/packages/zwave-js/src/lib/driver/Task.test.ts b/packages/zwave-js/src/lib/driver/Task.test.ts index 20fb2b5cef28..c88d777c0bbd 100644 --- a/packages/zwave-js/src/lib/driver/Task.test.ts +++ b/packages/zwave-js/src/lib/driver/Task.test.ts @@ -1,7 +1,7 @@ import { ZWaveError, ZWaveErrorCodes, assertZWaveError } from "@zwave-js/core"; import { noop } from "@zwave-js/shared"; -import { wait } from "alcalzone-shared/async/index.js"; -import { createDeferredPromise } from "alcalzone-shared/deferred-promise/index.js"; +import { wait } from "alcalzone-shared/async"; +import { createDeferredPromise } from "alcalzone-shared/deferred-promise"; import { test } from "vitest"; import { type TaskBuilder, diff --git a/packages/zwave-js/src/lib/driver/Task.ts b/packages/zwave-js/src/lib/driver/Task.ts index bc838d1a9e5b..229e7319401f 100644 --- a/packages/zwave-js/src/lib/driver/Task.ts +++ b/packages/zwave-js/src/lib/driver/Task.ts @@ -1,11 +1,11 @@ import { ZWaveError, ZWaveErrorCodes, highResTimestamp } from "@zwave-js/core"; import { createWrappingCounter, evalOrStatic, noop } from "@zwave-js/shared"; -import { type CompareResult } from "alcalzone-shared/comparable/index.js"; +import { type CompareResult } from "alcalzone-shared/comparable"; import { type DeferredPromise, createDeferredPromise, -} from "alcalzone-shared/deferred-promise/index.js"; -import { SortedList } from "alcalzone-shared/sorted-list/index.js"; +} from "alcalzone-shared/deferred-promise"; +import { SortedList } from "alcalzone-shared/sorted-list"; /** A high-level task that can be started and stepped through */ export interface Task { diff --git a/packages/zwave-js/src/lib/driver/Transaction.ts b/packages/zwave-js/src/lib/driver/Transaction.ts index 83690e6bf358..de1680e036f7 100644 --- a/packages/zwave-js/src/lib/driver/Transaction.ts +++ b/packages/zwave-js/src/lib/driver/Transaction.ts @@ -12,8 +12,8 @@ import { type Comparable, type CompareResult, compareNumberOrString, -} from "alcalzone-shared/comparable/index.js"; -import type { DeferredPromise } from "alcalzone-shared/deferred-promise/index.js"; +} from "alcalzone-shared/comparable"; +import type { DeferredPromise } from "alcalzone-shared/deferred-promise"; import { NodeStatus } from "../node/_Types.js"; import type { Driver } from "./Driver.js"; diff --git a/packages/zwave-js/src/lib/driver/UpdateConfig.ts b/packages/zwave-js/src/lib/driver/UpdateConfig.ts index dca2ac12b0fd..10e7faafdeec 100644 --- a/packages/zwave-js/src/lib/driver/UpdateConfig.ts +++ b/packages/zwave-js/src/lib/driver/UpdateConfig.ts @@ -1,6 +1,6 @@ import { ZWaveError, ZWaveErrorCodes } from "@zwave-js/core"; import { copyFilesRecursive, getErrorMessage } from "@zwave-js/shared"; -import { isObject } from "alcalzone-shared/typeguards/index.js"; +import { isObject } from "alcalzone-shared/typeguards"; import execa from "execa"; import fs from "node:fs/promises"; import os from "node:os"; diff --git a/packages/zwave-js/src/lib/driver/mDNSDiscovery.ts b/packages/zwave-js/src/lib/driver/mDNSDiscovery.ts index 7ce761c7262f..bd72bad2bebc 100644 --- a/packages/zwave-js/src/lib/driver/mDNSDiscovery.ts +++ b/packages/zwave-js/src/lib/driver/mDNSDiscovery.ts @@ -1,5 +1,5 @@ import { Bytes, isUint8Array } from "@zwave-js/shared"; -import { isArray, isObject } from "alcalzone-shared/typeguards/index.js"; +import { isArray, isObject } from "alcalzone-shared/typeguards"; import createMDNSServer from "mdns-server"; export interface RemoteSerialPort { diff --git a/packages/zwave-js/src/lib/log/Driver.test.ts b/packages/zwave-js/src/lib/log/Driver.test.ts index 270d1fd821f2..b77d12fe98e6 100644 --- a/packages/zwave-js/src/lib/log/Driver.test.ts +++ b/packages/zwave-js/src/lib/log/Driver.test.ts @@ -10,7 +10,7 @@ import { assertMessage, } from "@zwave-js/core/test"; import { FunctionType, Message, MessageType } from "@zwave-js/serial"; -import { createDeferredPromise } from "alcalzone-shared/deferred-promise/index.js"; +import { createDeferredPromise } from "alcalzone-shared/deferred-promise"; import colors from "ansi-colors"; import MockDate from "mockdate"; import { beforeEach, test as baseTest } from "vitest"; diff --git a/packages/zwave-js/src/lib/log/Zniffer.ts b/packages/zwave-js/src/lib/log/Zniffer.ts index 4d42ed5796ec..c018e91571a1 100644 --- a/packages/zwave-js/src/lib/log/Zniffer.ts +++ b/packages/zwave-js/src/lib/log/Zniffer.ts @@ -18,7 +18,6 @@ import { } from "@zwave-js/core"; import { type ZnifferDataMessage } from "@zwave-js/serial"; import { buffer2hex, num2hex } from "@zwave-js/shared"; -import { padStart } from "alcalzone-shared/strings/index.js"; import { type BeamStop, type LongRangeBeamStart, @@ -157,7 +156,7 @@ export class ZnifferLogger extends ZWaveLoggerBase { logCC(payloadCC); } - const homeId = padStart(mpdu.homeId.toString(16), 8, "0") + const homeId = mpdu.homeId.toString(16).padStart(8, "0") .toLowerCase(); this.logger.log({ diff --git a/packages/zwave-js/src/lib/node/HealthCheck.ts b/packages/zwave-js/src/lib/node/HealthCheck.ts index 41c72bbf3d9e..f1cdf85c7326 100644 --- a/packages/zwave-js/src/lib/node/HealthCheck.ts +++ b/packages/zwave-js/src/lib/node/HealthCheck.ts @@ -1,6 +1,5 @@ import { Powerlevel } from "@zwave-js/cc/safe"; import { getEnumMemberName } from "@zwave-js/shared/safe"; -import { padStart } from "alcalzone-shared/strings/index.js"; import type { LifelineHealthCheckResult, LifelineHealthCheckSummary, @@ -29,8 +28,7 @@ export function formatLifelineHealthCheckRound( ): string { const ret = [ `· round ${ - padStart( - round.toString(), + round.toString().padStart( Math.floor(Math.log10(numRounds) + 1), " ", ) @@ -101,8 +99,7 @@ export function formatRouteHealthCheckRound( ): string { const ret = [ `· round ${ - padStart( - round.toString(), + round.toString().padStart( Math.floor(Math.log10(numRounds) + 1), " ", ) diff --git a/packages/zwave-js/src/lib/node/Node.ts b/packages/zwave-js/src/lib/node/Node.ts index 7cc53b83f811..0bb19a1caa3d 100644 --- a/packages/zwave-js/src/lib/node/Node.ts +++ b/packages/zwave-js/src/lib/node/Node.ts @@ -226,14 +226,13 @@ import { pick, stringify, } from "@zwave-js/shared"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { type DeferredPromise, createDeferredPromise, -} from "alcalzone-shared/deferred-promise/index.js"; -import { roundTo } from "alcalzone-shared/math/index.js"; -import { padStart } from "alcalzone-shared/strings/index.js"; -import { isArray, isObject } from "alcalzone-shared/typeguards/index.js"; +} from "alcalzone-shared/deferred-promise"; +import { roundTo } from "alcalzone-shared/math"; +import { isArray, isObject } from "alcalzone-shared/typeguards"; import { EventEmitter } from "node:events"; import path from "node:path"; import semver from "semver"; @@ -1476,8 +1475,7 @@ protocol version: ${this.protocolVersion}`; "error", new ZWaveError( `Node ${ - padStart( - this.id.toString(), + this.id.toString().padStart( 3, "0", ) @@ -1537,8 +1535,7 @@ protocol version: ${this.protocolVersion}`; "error", new ZWaveError( `Node ${ - padStart( - this.id.toString(), + this.id.toString().padStart( 3, "0", ) diff --git a/packages/zwave-js/src/lib/node/VirtualEndpoint.test.ts b/packages/zwave-js/src/lib/node/VirtualEndpoint.test.ts index f68b4c422b7a..a5c45171ffe6 100644 --- a/packages/zwave-js/src/lib/node/VirtualEndpoint.test.ts +++ b/packages/zwave-js/src/lib/node/VirtualEndpoint.test.ts @@ -19,7 +19,7 @@ import { MockNode, getDefaultSupportedFunctionTypes, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { test as baseTest } from "vitest"; import { createDefaultMockControllerBehaviors, diff --git a/packages/zwave-js/src/lib/node/VirtualEndpoint.ts b/packages/zwave-js/src/lib/node/VirtualEndpoint.ts index 89f27b4d25b2..7e109deff35f 100644 --- a/packages/zwave-js/src/lib/node/VirtualEndpoint.ts +++ b/packages/zwave-js/src/lib/node/VirtualEndpoint.ts @@ -20,7 +20,7 @@ import { securityClassIsS2, } from "@zwave-js/core/safe"; import { staticExtends } from "@zwave-js/shared/safe"; -import { distinct } from "alcalzone-shared/arrays/index.js"; +import { distinct } from "alcalzone-shared/arrays"; import type { Driver } from "../driver/Driver.js"; import { createMultiCCAPIWrapper } from "./MultiCCAPIWrapper.js"; import { VirtualNode } from "./VirtualNode.js"; diff --git a/packages/zwave-js/src/lib/node/VirtualNode.ts b/packages/zwave-js/src/lib/node/VirtualNode.ts index 61a53b8baeb6..fc08f5f0d196 100644 --- a/packages/zwave-js/src/lib/node/VirtualNode.ts +++ b/packages/zwave-js/src/lib/node/VirtualNode.ts @@ -26,7 +26,7 @@ import { supervisedCommandSucceeded, valueIdToString, } from "@zwave-js/core"; -import { distinct } from "alcalzone-shared/arrays/index.js"; +import { distinct } from "alcalzone-shared/arrays"; import type { Driver } from "../driver/Driver.js"; import type { ZWaveNode } from "./Node.js"; import { VirtualEndpoint } from "./VirtualEndpoint.js"; diff --git a/packages/zwave-js/src/lib/node/mixins/50_Endpoints.ts b/packages/zwave-js/src/lib/node/mixins/50_Endpoints.ts index 21c93d25da53..771aa6fb1694 100644 --- a/packages/zwave-js/src/lib/node/mixins/50_Endpoints.ts +++ b/packages/zwave-js/src/lib/node/mixins/50_Endpoints.ts @@ -7,7 +7,7 @@ import { ZWaveError, ZWaveErrorCodes, } from "@zwave-js/core"; -import { isArray, isObject } from "alcalzone-shared/typeguards/index.js"; +import { isArray, isObject } from "alcalzone-shared/typeguards"; import { DeviceClass } from "../DeviceClass.js"; import { Endpoint } from "../Endpoint.js"; import * as nodeUtils from "../utils.js"; diff --git a/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts b/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts index 345b4b80f813..7be3e0074731 100644 --- a/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts +++ b/packages/zwave-js/src/lib/node/mixins/70_FirmwareUpdate.ts @@ -26,13 +26,13 @@ import { } from "@zwave-js/core"; import { containsCC } from "@zwave-js/serial/serialapi"; import { getEnumMemberName, throttle } from "@zwave-js/shared"; -import { distinct } from "alcalzone-shared/arrays/index.js"; -import { wait } from "alcalzone-shared/async/index.js"; +import { distinct } from "alcalzone-shared/arrays"; +import { wait } from "alcalzone-shared/async"; import { type DeferredPromise, createDeferredPromise, -} from "alcalzone-shared/deferred-promise/index.js"; -import { roundTo } from "alcalzone-shared/math/index.js"; +} from "alcalzone-shared/deferred-promise"; +import { roundTo } from "alcalzone-shared/math"; import { randomBytes } from "node:crypto"; import { type Task, diff --git a/packages/zwave-js/src/lib/telemetry/deviceConfig.ts b/packages/zwave-js/src/lib/telemetry/deviceConfig.ts index a25740c91c08..7db979b9ee45 100644 --- a/packages/zwave-js/src/lib/telemetry/deviceConfig.ts +++ b/packages/zwave-js/src/lib/telemetry/deviceConfig.ts @@ -2,7 +2,7 @@ // import { AssociationGroupInfoCC, ConfigurationCC } from "@zwave-js/cc"; // import { CommandClasses } from "@zwave-js/core"; // import { formatId } from "@zwave-js/shared"; -// import { isObject } from "alcalzone-shared/typeguards/index.js"; +// import { isObject } from "alcalzone-shared/typeguards"; import type { ZWaveNode } from "../node/Node.js"; // const missingDeviceConfigCache = new Set(); diff --git a/packages/zwave-js/src/lib/telemetry/statistics.ts b/packages/zwave-js/src/lib/telemetry/statistics.ts index 0034e63fa634..fd14593501ba 100644 --- a/packages/zwave-js/src/lib/telemetry/statistics.ts +++ b/packages/zwave-js/src/lib/telemetry/statistics.ts @@ -1,5 +1,5 @@ import { formatId } from "@zwave-js/shared"; -import { isObject } from "alcalzone-shared/typeguards/index.js"; +import { isObject } from "alcalzone-shared/typeguards"; import * as crypto from "node:crypto"; import type { Driver } from "../driver/Driver.js"; diff --git a/packages/zwave-js/src/lib/test/cc-specific/discardUnsupportedReports.test.ts b/packages/zwave-js/src/lib/test/cc-specific/discardUnsupportedReports.test.ts index 8274c560fccd..ae7c89154325 100644 --- a/packages/zwave-js/src/lib/test/cc-specific/discardUnsupportedReports.test.ts +++ b/packages/zwave-js/src/lib/test/cc-specific/discardUnsupportedReports.test.ts @@ -8,7 +8,7 @@ import { RateType, } from "@zwave-js/cc"; import { createMockZWaveRequestFrame } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import path from "node:path"; import { integrationTest } from "../integrationTestSuite.js"; diff --git a/packages/zwave-js/src/lib/test/cc-specific/mapNotificationDoorLock.test.ts b/packages/zwave-js/src/lib/test/cc-specific/mapNotificationDoorLock.test.ts index 77a64a30a320..d5b1bb8dfa89 100644 --- a/packages/zwave-js/src/lib/test/cc-specific/mapNotificationDoorLock.test.ts +++ b/packages/zwave-js/src/lib/test/cc-specific/mapNotificationDoorLock.test.ts @@ -2,7 +2,7 @@ import { DoorLockMode } from "@zwave-js/cc"; import { DoorLockCCValues } from "@zwave-js/cc/DoorLockCC"; import { NotificationCCReport } from "@zwave-js/cc/NotificationCC"; import { createMockZWaveRequestFrame } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import path from "node:path"; import { integrationTest } from "../integrationTestSuite.js"; diff --git a/packages/zwave-js/src/lib/test/cc-specific/notificationEnums.test.ts b/packages/zwave-js/src/lib/test/cc-specific/notificationEnums.test.ts index 1de85ecbd712..f2db42338e27 100644 --- a/packages/zwave-js/src/lib/test/cc-specific/notificationEnums.test.ts +++ b/packages/zwave-js/src/lib/test/cc-specific/notificationEnums.test.ts @@ -4,7 +4,7 @@ import { } from "@zwave-js/cc/NotificationCC"; import { CommandClasses, type ValueMetadataNumeric } from "@zwave-js/core"; import { createMockZWaveRequestFrame } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { integrationTest } from "../integrationTestSuite.js"; integrationTest( diff --git a/packages/zwave-js/src/lib/test/cc-specific/notificationIdleManually.test.ts b/packages/zwave-js/src/lib/test/cc-specific/notificationIdleManually.test.ts index cb7799de692d..4c2f04d532ea 100644 --- a/packages/zwave-js/src/lib/test/cc-specific/notificationIdleManually.test.ts +++ b/packages/zwave-js/src/lib/test/cc-specific/notificationIdleManually.test.ts @@ -3,7 +3,7 @@ import { NotificationCCValues, } from "@zwave-js/cc/NotificationCC"; import { createMockZWaveRequestFrame } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import path from "node:path"; import { integrationTest } from "../integrationTestSuite.js"; diff --git a/packages/zwave-js/src/lib/test/cc-specific/notificationIdleRelated.test.ts b/packages/zwave-js/src/lib/test/cc-specific/notificationIdleRelated.test.ts index 65fec1299389..4c7de630e764 100644 --- a/packages/zwave-js/src/lib/test/cc-specific/notificationIdleRelated.test.ts +++ b/packages/zwave-js/src/lib/test/cc-specific/notificationIdleRelated.test.ts @@ -3,7 +3,7 @@ import { NotificationCCValues, } from "@zwave-js/cc/NotificationCC"; import { createMockZWaveRequestFrame } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import path from "node:path"; import { integrationTest } from "../integrationTestSuite.js"; diff --git a/packages/zwave-js/src/lib/test/cc-specific/undefinedTargetValue.test.ts b/packages/zwave-js/src/lib/test/cc-specific/undefinedTargetValue.test.ts index f6ced6193485..4cc9dd942c3a 100644 --- a/packages/zwave-js/src/lib/test/cc-specific/undefinedTargetValue.test.ts +++ b/packages/zwave-js/src/lib/test/cc-specific/undefinedTargetValue.test.ts @@ -4,7 +4,7 @@ import { } from "@zwave-js/cc/BinarySwitchCC"; import { createMockZWaveRequestFrame } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import path from "node:path"; import { integrationTest } from "../integrationTestSuite.js"; diff --git a/packages/zwave-js/src/lib/test/cc-specific/unknownNotifications.test.ts b/packages/zwave-js/src/lib/test/cc-specific/unknownNotifications.test.ts index 9f6db9d652c3..f20290bf4a09 100644 --- a/packages/zwave-js/src/lib/test/cc-specific/unknownNotifications.test.ts +++ b/packages/zwave-js/src/lib/test/cc-specific/unknownNotifications.test.ts @@ -4,7 +4,7 @@ import { } from "@zwave-js/cc/NotificationCC"; import { ValueMetadata } from "@zwave-js/core"; import { createMockZWaveRequestFrame } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import path from "node:path"; import { integrationTest } from "../integrationTestSuite.js"; diff --git a/packages/zwave-js/src/lib/test/compat/notificationAlarmMapping.test.ts b/packages/zwave-js/src/lib/test/compat/notificationAlarmMapping.test.ts index a8c4c52a7168..6b95d2d1fd44 100644 --- a/packages/zwave-js/src/lib/test/compat/notificationAlarmMapping.test.ts +++ b/packages/zwave-js/src/lib/test/compat/notificationAlarmMapping.test.ts @@ -4,7 +4,7 @@ import { } from "@zwave-js/cc/NotificationCC"; import { CommandClasses } from "@zwave-js/core"; import { createMockZWaveRequestFrame } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import sinon from "sinon"; import { integrationTest } from "../integrationTestSuite.js"; diff --git a/packages/zwave-js/src/lib/test/compat/reInterviewWakeUpNIF.test.ts b/packages/zwave-js/src/lib/test/compat/reInterviewWakeUpNIF.test.ts index a7030e7dbf1d..4b487045d883 100644 --- a/packages/zwave-js/src/lib/test/compat/reInterviewWakeUpNIF.test.ts +++ b/packages/zwave-js/src/lib/test/compat/reInterviewWakeUpNIF.test.ts @@ -1,7 +1,7 @@ import { ZWaveProtocolCCNodeInformationFrame } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; import { createMockZWaveRequestFrame } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import path from "node:path"; import { integrationTest } from "../integrationTestSuite.js"; diff --git a/packages/zwave-js/src/lib/test/compliance/decodeLowerS2Keys.test.ts b/packages/zwave-js/src/lib/test/compliance/decodeLowerS2Keys.test.ts index 01bef4325d68..4f6979d3aa47 100644 --- a/packages/zwave-js/src/lib/test/compliance/decodeLowerS2Keys.test.ts +++ b/packages/zwave-js/src/lib/test/compliance/decodeLowerS2Keys.test.ts @@ -15,7 +15,7 @@ import { MockZWaveFrameType, createMockZWaveRequestFrame, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { randomBytes } from "node:crypto"; import path from "node:path"; import { integrationTest } from "../integrationTestSuite.js"; diff --git a/packages/zwave-js/src/lib/test/compliance/discardInsecureCommands.test.ts b/packages/zwave-js/src/lib/test/compliance/discardInsecureCommands.test.ts index b52ba658dd4b..5937dbb3ed06 100644 --- a/packages/zwave-js/src/lib/test/compliance/discardInsecureCommands.test.ts +++ b/packages/zwave-js/src/lib/test/compliance/discardInsecureCommands.test.ts @@ -16,7 +16,7 @@ import { type MockNodeBehavior, createMockZWaveRequestFrame, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import path from "node:path"; import { integrationTest } from "../integrationTestSuite.js"; diff --git a/packages/zwave-js/src/lib/test/driver/bootloaderDetection.test.ts b/packages/zwave-js/src/lib/test/driver/bootloaderDetection.test.ts index 95333ee16136..9fedce7b3239 100644 --- a/packages/zwave-js/src/lib/test/driver/bootloaderDetection.test.ts +++ b/packages/zwave-js/src/lib/test/driver/bootloaderDetection.test.ts @@ -1,6 +1,6 @@ import { Bytes } from "@zwave-js/shared"; import { type MockControllerBehavior } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { integrationTest } from "../integrationTestSuite.js"; integrationTest( diff --git a/packages/zwave-js/src/lib/test/driver/controllerJammed.test.ts b/packages/zwave-js/src/lib/test/driver/controllerJammed.test.ts index 61fd0610d368..01b882a58af4 100644 --- a/packages/zwave-js/src/lib/test/driver/controllerJammed.test.ts +++ b/packages/zwave-js/src/lib/test/driver/controllerJammed.test.ts @@ -20,7 +20,7 @@ import { getDefaultMockControllerCapabilities, getDefaultSupportedFunctionTypes, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import sinon from "sinon"; import { MockControllerCommunicationState, diff --git a/packages/zwave-js/src/lib/test/driver/createCCValuesUsingKnownVersion.test.ts b/packages/zwave-js/src/lib/test/driver/createCCValuesUsingKnownVersion.test.ts index 8f5b781afb9f..677ba339f6ea 100644 --- a/packages/zwave-js/src/lib/test/driver/createCCValuesUsingKnownVersion.test.ts +++ b/packages/zwave-js/src/lib/test/driver/createCCValuesUsingKnownVersion.test.ts @@ -1,7 +1,7 @@ import { BatteryCCReport, BatteryCCValues } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; import { createMockZWaveRequestFrame } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import path from "node:path"; import { integrationTest } from "../integrationTestSuite.js"; diff --git a/packages/zwave-js/src/lib/test/driver/handleUnsolicited.test.ts b/packages/zwave-js/src/lib/test/driver/handleUnsolicited.test.ts index 80d5f6aa5feb..d77fe33e5459 100644 --- a/packages/zwave-js/src/lib/test/driver/handleUnsolicited.test.ts +++ b/packages/zwave-js/src/lib/test/driver/handleUnsolicited.test.ts @@ -4,7 +4,7 @@ import { type MockControllerBehavior, createMockZWaveRequestFrame, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { integrationTest } from "../integrationTestSuite.js"; integrationTest( diff --git a/packages/zwave-js/src/lib/test/driver/ignoreCCVersion0ForKnownSupportedCCs.test.ts b/packages/zwave-js/src/lib/test/driver/ignoreCCVersion0ForKnownSupportedCCs.test.ts index af0c491a3ac8..deae09103d3b 100644 --- a/packages/zwave-js/src/lib/test/driver/ignoreCCVersion0ForKnownSupportedCCs.test.ts +++ b/packages/zwave-js/src/lib/test/driver/ignoreCCVersion0ForKnownSupportedCCs.test.ts @@ -29,7 +29,7 @@ import { MockZWaveFrameType, createMockZWaveRequestFrame, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { integrationTest } from "../integrationTestSuite.js"; // Repro for https://github.com/zwave-js/node-zwave-js/issues/6305 diff --git a/packages/zwave-js/src/lib/test/driver/invalidPayloadLog.test.ts b/packages/zwave-js/src/lib/test/driver/invalidPayloadLog.test.ts index e4b3831cd556..ee0ba9f6d33c 100644 --- a/packages/zwave-js/src/lib/test/driver/invalidPayloadLog.test.ts +++ b/packages/zwave-js/src/lib/test/driver/invalidPayloadLog.test.ts @@ -6,7 +6,7 @@ import { getDefaultMockControllerCapabilities, getDefaultSupportedFunctionTypes, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { integrationTest } from "../integrationTestSuite.js"; const spyTransport = new SpyTransport(); diff --git a/packages/zwave-js/src/lib/test/driver/multiStageResponseNoTimeout.test.ts b/packages/zwave-js/src/lib/test/driver/multiStageResponseNoTimeout.test.ts index f3577fc9ad4f..e23fd55d078e 100644 --- a/packages/zwave-js/src/lib/test/driver/multiStageResponseNoTimeout.test.ts +++ b/packages/zwave-js/src/lib/test/driver/multiStageResponseNoTimeout.test.ts @@ -13,7 +13,7 @@ import { type MockNodeBehavior, createMockZWaveRequestFrame, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { integrationTest } from "../integrationTestSuite.js"; integrationTest( diff --git a/packages/zwave-js/src/lib/test/driver/multicastOptimisticValueUpdate.test.ts b/packages/zwave-js/src/lib/test/driver/multicastOptimisticValueUpdate.test.ts index 0f9628c95677..ca8e90c87d9b 100644 --- a/packages/zwave-js/src/lib/test/driver/multicastOptimisticValueUpdate.test.ts +++ b/packages/zwave-js/src/lib/test/driver/multicastOptimisticValueUpdate.test.ts @@ -8,7 +8,7 @@ import { getDefaultMockControllerCapabilities, getDefaultSupportedFunctionTypes, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { integrationTest } from "../integrationTestSuiteMulti.js"; // Regression test for #5844 diff --git a/packages/zwave-js/src/lib/test/driver/nodeAsleepBlockNonceReport.test.ts b/packages/zwave-js/src/lib/test/driver/nodeAsleepBlockNonceReport.test.ts index a63936f3361c..a86f9fb5bf69 100644 --- a/packages/zwave-js/src/lib/test/driver/nodeAsleepBlockNonceReport.test.ts +++ b/packages/zwave-js/src/lib/test/driver/nodeAsleepBlockNonceReport.test.ts @@ -10,7 +10,7 @@ import { MockZWaveFrameType, createMockZWaveRequestFrame, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import path from "node:path"; import { integrationTest } from "../integrationTestSuite.js"; diff --git a/packages/zwave-js/src/lib/test/driver/nodeAsleepMessageOrder.test.ts b/packages/zwave-js/src/lib/test/driver/nodeAsleepMessageOrder.test.ts index 9e8a93067d5d..f195f219167c 100644 --- a/packages/zwave-js/src/lib/test/driver/nodeAsleepMessageOrder.test.ts +++ b/packages/zwave-js/src/lib/test/driver/nodeAsleepMessageOrder.test.ts @@ -11,7 +11,7 @@ import { MockZWaveFrameType, createMockZWaveRequestFrame, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import path from "node:path"; import { integrationTest } from "../integrationTestSuiteMulti.js"; diff --git a/packages/zwave-js/src/lib/test/driver/nodeAsleepNoReject.test.ts b/packages/zwave-js/src/lib/test/driver/nodeAsleepNoReject.test.ts index 84d4413eb56e..ec6dd5ddaec2 100644 --- a/packages/zwave-js/src/lib/test/driver/nodeAsleepNoReject.test.ts +++ b/packages/zwave-js/src/lib/test/driver/nodeAsleepNoReject.test.ts @@ -2,7 +2,7 @@ import { BasicCCGet, BasicCCSet } from "@zwave-js/cc"; import { MessagePriority, NodeStatus } from "@zwave-js/core"; import { type SendDataRequest } from "@zwave-js/serial/serialapi"; import { MOCK_FRAME_ACK_TIMEOUT, MockZWaveFrameType } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import path from "node:path"; import { integrationTest } from "../integrationTestSuite.js"; diff --git a/packages/zwave-js/src/lib/test/driver/nodeAsleepPingResolves.test.ts b/packages/zwave-js/src/lib/test/driver/nodeAsleepPingResolves.test.ts index 0b2f77a731ca..b69e61116175 100644 --- a/packages/zwave-js/src/lib/test/driver/nodeAsleepPingResolves.test.ts +++ b/packages/zwave-js/src/lib/test/driver/nodeAsleepPingResolves.test.ts @@ -1,5 +1,5 @@ import { NodeStatus } from "@zwave-js/core"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import path from "node:path"; import { integrationTest } from "../integrationTestSuite.js"; diff --git a/packages/zwave-js/src/lib/test/driver/nodeDeadReject.test.ts b/packages/zwave-js/src/lib/test/driver/nodeDeadReject.test.ts index bdfe70005c52..061ce6e75c01 100644 --- a/packages/zwave-js/src/lib/test/driver/nodeDeadReject.test.ts +++ b/packages/zwave-js/src/lib/test/driver/nodeDeadReject.test.ts @@ -1,7 +1,7 @@ import { BasicCCGet, BasicCCSet } from "@zwave-js/cc"; import { NodeStatus, ZWaveErrorCodes, assertZWaveError } from "@zwave-js/core"; import { MockZWaveFrameType } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import path from "node:path"; import { integrationTest } from "../integrationTestSuite.js"; diff --git a/packages/zwave-js/src/lib/test/driver/nodeUpdateBeforeCallback.test.ts b/packages/zwave-js/src/lib/test/driver/nodeUpdateBeforeCallback.test.ts index 72f615d32cc4..78021df4bc93 100644 --- a/packages/zwave-js/src/lib/test/driver/nodeUpdateBeforeCallback.test.ts +++ b/packages/zwave-js/src/lib/test/driver/nodeUpdateBeforeCallback.test.ts @@ -3,7 +3,7 @@ import { type MockNodeBehavior, createMockZWaveRequestFrame, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import path from "node:path"; import { integrationTest } from "../integrationTestSuite.js"; diff --git a/packages/zwave-js/src/lib/test/driver/reInterviewAssumeAwake.test.ts b/packages/zwave-js/src/lib/test/driver/reInterviewAssumeAwake.test.ts index 084bc638eca3..7949a3fe9a9f 100644 --- a/packages/zwave-js/src/lib/test/driver/reInterviewAssumeAwake.test.ts +++ b/packages/zwave-js/src/lib/test/driver/reInterviewAssumeAwake.test.ts @@ -1,7 +1,7 @@ import { WakeUpCCWakeUpNotification } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; import { createMockZWaveRequestFrame } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { integrationTest } from "../integrationTestSuite.js"; integrationTest("Assume a node to be awake at the start of a re-interview", { diff --git a/packages/zwave-js/src/lib/test/driver/s0AndS2Encapsulation.test.ts b/packages/zwave-js/src/lib/test/driver/s0AndS2Encapsulation.test.ts index a81db906a041..0c8b5d70e73a 100644 --- a/packages/zwave-js/src/lib/test/driver/s0AndS2Encapsulation.test.ts +++ b/packages/zwave-js/src/lib/test/driver/s0AndS2Encapsulation.test.ts @@ -20,7 +20,7 @@ import { ZWaveErrorCodes, } from "@zwave-js/core"; import { type MockNodeBehavior, MockZWaveFrameType } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import path from "node:path"; import { integrationTest } from "../integrationTestSuite.js"; diff --git a/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts b/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts index 97512298c530..b0d531459bcc 100644 --- a/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts +++ b/packages/zwave-js/src/lib/test/driver/s0EncapsulationTwoNodes.test.ts @@ -15,7 +15,7 @@ import { MockZWaveFrameType, createMockZWaveRequestFrame, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { integrationTest } from "../integrationTestSuiteMulti.js"; integrationTest( diff --git a/packages/zwave-js/src/lib/test/driver/s2Collisions.test.ts b/packages/zwave-js/src/lib/test/driver/s2Collisions.test.ts index 2268e862bed6..02bb4eb2e69a 100644 --- a/packages/zwave-js/src/lib/test/driver/s2Collisions.test.ts +++ b/packages/zwave-js/src/lib/test/driver/s2Collisions.test.ts @@ -25,7 +25,7 @@ import { type MockZWaveRequestFrame, createMockZWaveRequestFrame, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import path from "node:path"; import { integrationTest } from "../integrationTestSuite.js"; diff --git a/packages/zwave-js/src/lib/test/driver/sendCommandProgress.test.ts b/packages/zwave-js/src/lib/test/driver/sendCommandProgress.test.ts index 4db35ec97776..26638385099b 100644 --- a/packages/zwave-js/src/lib/test/driver/sendCommandProgress.test.ts +++ b/packages/zwave-js/src/lib/test/driver/sendCommandProgress.test.ts @@ -3,7 +3,7 @@ import { CommandClasses, TransactionState } from "@zwave-js/core"; import sinon from "sinon"; import { getEnumMemberName } from "@zwave-js/shared"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import path from "node:path"; import { integrationTest } from "../integrationTestSuite.js"; diff --git a/packages/zwave-js/src/lib/test/driver/sendDataMissingCallbackAbort.test.ts b/packages/zwave-js/src/lib/test/driver/sendDataMissingCallbackAbort.test.ts index 52df3a813cba..60d03c5abd2e 100644 --- a/packages/zwave-js/src/lib/test/driver/sendDataMissingCallbackAbort.test.ts +++ b/packages/zwave-js/src/lib/test/driver/sendDataMissingCallbackAbort.test.ts @@ -5,7 +5,7 @@ import { getDefaultMockControllerCapabilities, getDefaultSupportedFunctionTypes, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { MockControllerCommunicationState, MockControllerStateKeys, diff --git a/packages/zwave-js/src/lib/test/driver/sendDataMissingResponse.test.ts b/packages/zwave-js/src/lib/test/driver/sendDataMissingResponse.test.ts index d74976f3dd27..5ce5954c81e4 100644 --- a/packages/zwave-js/src/lib/test/driver/sendDataMissingResponse.test.ts +++ b/packages/zwave-js/src/lib/test/driver/sendDataMissingResponse.test.ts @@ -5,7 +5,7 @@ import { getDefaultMockControllerCapabilities, getDefaultSupportedFunctionTypes, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { MockControllerCommunicationState, MockControllerStateKeys, diff --git a/packages/zwave-js/src/lib/test/driver/setValueFailedSupervisionGet.test.ts b/packages/zwave-js/src/lib/test/driver/setValueFailedSupervisionGet.test.ts index 0553247c7805..0f7260cb54ca 100644 --- a/packages/zwave-js/src/lib/test/driver/setValueFailedSupervisionGet.test.ts +++ b/packages/zwave-js/src/lib/test/driver/setValueFailedSupervisionGet.test.ts @@ -8,7 +8,7 @@ import { } from "@zwave-js/cc"; import { CommandClasses, SupervisionStatus } from "@zwave-js/core"; import { type MockNodeBehavior, MockZWaveFrameType } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { integrationTest } from "../integrationTestSuite.js"; integrationTest( diff --git a/packages/zwave-js/src/lib/test/driver/setValueNoSupervision.test.ts b/packages/zwave-js/src/lib/test/driver/setValueNoSupervision.test.ts index 56c5325ad77a..19fe4f75d778 100644 --- a/packages/zwave-js/src/lib/test/driver/setValueNoSupervision.test.ts +++ b/packages/zwave-js/src/lib/test/driver/setValueNoSupervision.test.ts @@ -6,7 +6,7 @@ import { } from "@zwave-js/cc"; import { CommandClasses } from "@zwave-js/core"; import { type MockNodeBehavior, MockZWaveFrameType } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { integrationTest } from "../integrationTestSuite.js"; integrationTest("setValue without supervision: expect validation GET", { diff --git a/packages/zwave-js/src/lib/test/driver/setValueSucceedAfterFailure.test.ts b/packages/zwave-js/src/lib/test/driver/setValueSucceedAfterFailure.test.ts index 57855a9356c1..25589ef6e172 100644 --- a/packages/zwave-js/src/lib/test/driver/setValueSucceedAfterFailure.test.ts +++ b/packages/zwave-js/src/lib/test/driver/setValueSucceedAfterFailure.test.ts @@ -6,7 +6,7 @@ import { MOCK_FRAME_ACK_TIMEOUT, type MockNodeBehavior, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { integrationTest } from "../integrationTestSuite.js"; // Repro for https://github.com/home-assistant/core/issues/98491 diff --git a/packages/zwave-js/src/lib/test/driver/setValueSuccessfulSupervisionNoGet.test.ts b/packages/zwave-js/src/lib/test/driver/setValueSuccessfulSupervisionNoGet.test.ts index 5b39df891f0b..fa777bbd06bd 100644 --- a/packages/zwave-js/src/lib/test/driver/setValueSuccessfulSupervisionNoGet.test.ts +++ b/packages/zwave-js/src/lib/test/driver/setValueSuccessfulSupervisionNoGet.test.ts @@ -7,7 +7,7 @@ import { } from "@zwave-js/cc"; import { CommandClasses, SupervisionStatus } from "@zwave-js/core"; import { type MockNodeBehavior, MockZWaveFrameType } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import sinon from "sinon"; import { integrationTest } from "../integrationTestSuite.js"; diff --git a/packages/zwave-js/src/lib/test/driver/setValueSupervision255Get.test.ts b/packages/zwave-js/src/lib/test/driver/setValueSupervision255Get.test.ts index 36d71368453f..72002c92c866 100644 --- a/packages/zwave-js/src/lib/test/driver/setValueSupervision255Get.test.ts +++ b/packages/zwave-js/src/lib/test/driver/setValueSupervision255Get.test.ts @@ -12,7 +12,7 @@ import { MockZWaveFrameType, createMockZWaveRequestFrame, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { integrationTest } from "../integrationTestSuite.js"; integrationTest( diff --git a/packages/zwave-js/src/lib/test/driver/setValueSupervisionSuccessMoreUpdates.test.ts b/packages/zwave-js/src/lib/test/driver/setValueSupervisionSuccessMoreUpdates.test.ts index 4ac31c6bc8bc..c68a8c29df4d 100644 --- a/packages/zwave-js/src/lib/test/driver/setValueSupervisionSuccessMoreUpdates.test.ts +++ b/packages/zwave-js/src/lib/test/driver/setValueSupervisionSuccessMoreUpdates.test.ts @@ -6,7 +6,7 @@ import { } from "@zwave-js/cc"; import { CommandClasses, SupervisionStatus } from "@zwave-js/core"; import { type MockNodeBehavior } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import sinon from "sinon"; import { integrationTest } from "../integrationTestSuite.js"; diff --git a/packages/zwave-js/src/lib/test/driver/setValueSupervisionWorking.test.ts b/packages/zwave-js/src/lib/test/driver/setValueSupervisionWorking.test.ts index 721b74de6f0e..50fedde31412 100644 --- a/packages/zwave-js/src/lib/test/driver/setValueSupervisionWorking.test.ts +++ b/packages/zwave-js/src/lib/test/driver/setValueSupervisionWorking.test.ts @@ -14,7 +14,7 @@ import { ccCaps, createMockZWaveRequestFrame, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { integrationTest } from "../integrationTestSuite.js"; integrationTest( diff --git a/packages/zwave-js/src/lib/test/driver/unknownValues.test.ts b/packages/zwave-js/src/lib/test/driver/unknownValues.test.ts index 1399e1d679e0..d269a52e0ce3 100644 --- a/packages/zwave-js/src/lib/test/driver/unknownValues.test.ts +++ b/packages/zwave-js/src/lib/test/driver/unknownValues.test.ts @@ -18,7 +18,7 @@ import { ccCaps, createMockZWaveRequestFrame, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { integrationTest } from "../integrationTestSuite.js"; integrationTest(`Basic Reports with the UNKNOWN state are correctly handled`, { diff --git a/packages/zwave-js/src/lib/test/driver/unresponsiveStick.test.ts b/packages/zwave-js/src/lib/test/driver/unresponsiveStick.test.ts index 0ef4dcf403c9..36caa4ca8da0 100644 --- a/packages/zwave-js/src/lib/test/driver/unresponsiveStick.test.ts +++ b/packages/zwave-js/src/lib/test/driver/unresponsiveStick.test.ts @@ -6,7 +6,7 @@ import { } from "@zwave-js/serial/serialapi"; import { SoftResetRequest } from "@zwave-js/serial/serialapi"; import { type MockControllerBehavior } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import Sinon from "sinon"; import { integrationTest } from "../integrationTestSuite.js"; diff --git a/packages/zwave-js/src/lib/test/integrationTestSuite.ts b/packages/zwave-js/src/lib/test/integrationTestSuite.ts index 29734c12a9d7..e7ceebb0a65a 100644 --- a/packages/zwave-js/src/lib/test/integrationTestSuite.ts +++ b/packages/zwave-js/src/lib/test/integrationTestSuite.ts @@ -6,7 +6,7 @@ import { type MockNode, type MockNodeOptions, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import crypto from "node:crypto"; import fs from "node:fs/promises"; import os from "node:os"; diff --git a/packages/zwave-js/src/lib/test/integrationTestSuiteMulti.ts b/packages/zwave-js/src/lib/test/integrationTestSuiteMulti.ts index 9ec7096430a1..9aaaa2e51895 100644 --- a/packages/zwave-js/src/lib/test/integrationTestSuiteMulti.ts +++ b/packages/zwave-js/src/lib/test/integrationTestSuiteMulti.ts @@ -6,7 +6,7 @@ import { type MockNode, type MockNodeOptions, } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import crypto from "node:crypto"; import fs from "node:fs/promises"; import os from "node:os"; diff --git a/packages/zwave-js/src/lib/test/node/Node.waitForWakeup.test.ts b/packages/zwave-js/src/lib/test/node/Node.waitForWakeup.test.ts index 99068ef0e1d7..de9f9645a162 100644 --- a/packages/zwave-js/src/lib/test/node/Node.waitForWakeup.test.ts +++ b/packages/zwave-js/src/lib/test/node/Node.waitForWakeup.test.ts @@ -5,7 +5,7 @@ import { } from "@zwave-js/core"; import type { ThrowingMap } from "@zwave-js/shared"; import { MockController } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { test as baseTest } from "vitest"; import { createDefaultMockControllerBehaviors } from "../../../Utils.js"; import type { Driver } from "../../driver/Driver.js"; diff --git a/packages/zwave-js/src/lib/test/node/legacyRefreshActuatorSensorCCs.test.ts b/packages/zwave-js/src/lib/test/node/legacyRefreshActuatorSensorCCs.test.ts index 40d0d6cba976..40833c5abd93 100644 --- a/packages/zwave-js/src/lib/test/node/legacyRefreshActuatorSensorCCs.test.ts +++ b/packages/zwave-js/src/lib/test/node/legacyRefreshActuatorSensorCCs.test.ts @@ -6,7 +6,7 @@ import { import { CommandClasses } from "@zwave-js/core"; import { ApplicationUpdateRequestNodeInfoReceived } from "@zwave-js/serial/serialapi"; import { type MockNodeBehavior, MockZWaveFrameType } from "@zwave-js/testing"; -import { wait } from "alcalzone-shared/async/index.js"; +import { wait } from "alcalzone-shared/async"; import { integrationTest } from "../integrationTestSuite.js"; integrationTest( diff --git a/packages/zwave-js/src/lib/zniffer/MPDU.ts b/packages/zwave-js/src/lib/zniffer/MPDU.ts index fdd1ee174e65..5d9a32e997ae 100644 --- a/packages/zwave-js/src/lib/zniffer/MPDU.ts +++ b/packages/zwave-js/src/lib/zniffer/MPDU.ts @@ -30,7 +30,6 @@ import { pick, staticExtends, } from "@zwave-js/shared"; -import { padStart } from "alcalzone-shared/strings/index.js"; import { ExplorerFrameCommand, LongRangeFrameType, @@ -73,7 +72,7 @@ function longRangeBeamPowerToDBm(power: number): number { } function formatNodeId(nodeId: number): string { - return padStart(nodeId.toString(), 3, "0"); + return nodeId.toString().padStart(3, "0"); } function formatRoute( @@ -726,8 +725,7 @@ export class InclusionRequestExplorerZWaveMPDU extends ExplorerZWaveMPDU { const message: MessageRecord = { ...original, - "network home ID": padStart( - this.networkHomeId.toString(16), + "network home ID": this.networkHomeId.toString(16).padStart( 8, "0", ), diff --git a/packages/zwave-js/src/lib/zniffer/Zniffer.ts b/packages/zwave-js/src/lib/zniffer/Zniffer.ts index 350909071c04..5b6cbb6ba022 100644 --- a/packages/zwave-js/src/lib/zniffer/Zniffer.ts +++ b/packages/zwave-js/src/lib/zniffer/Zniffer.ts @@ -69,7 +69,7 @@ import { import { type DeferredPromise, createDeferredPromise, -} from "alcalzone-shared/deferred-promise/index.js"; +} from "alcalzone-shared/deferred-promise"; import fs from "node:fs/promises"; import { type ZWaveOptions } from "../driver/ZWaveOptions.js"; import { ZnifferLogger } from "../log/Zniffer.js"; diff --git a/packages/zwave-js/src/mockServer.ts b/packages/zwave-js/src/mockServer.ts index 7cbfb2f1842c..a1ed1eb925c0 100644 --- a/packages/zwave-js/src/mockServer.ts +++ b/packages/zwave-js/src/mockServer.ts @@ -40,7 +40,7 @@ import { getDefaultMockEndpointCapabilities, getDefaultMockNodeCapabilities, } from "@zwave-js/testing"; -import { createDeferredPromise } from "alcalzone-shared/deferred-promise/index.js"; +import { createDeferredPromise } from "alcalzone-shared/deferred-promise"; import { type AddressInfo, type Server, createServer } from "node:net"; import { ProtocolVersion, diff --git a/packages/zwave-js/zwave-js.api.md b/packages/zwave-js/zwave-js.api.md index 692c6d83232a..9e6145f61bf6 100644 --- a/packages/zwave-js/zwave-js.api.md +++ b/packages/zwave-js/zwave-js.api.md @@ -26,8 +26,8 @@ import { CommandClasses as CommandClasses_2 } from '@zwave-js/core'; import { CommandClassInfo } from '@zwave-js/core'; import type { CommandClassInfo as CommandClassInfo_2 } from '@zwave-js/core/safe'; import { CommandRequest } from '@zwave-js/serial/serialapi'; -import { Comparable } from 'alcalzone-shared/comparable/index.js'; -import { CompareResult } from 'alcalzone-shared/comparable/index.js'; +import { Comparable } from 'alcalzone-shared/comparable'; +import { CompareResult } from 'alcalzone-shared/comparable'; import { ConfigManager } from '@zwave-js/config'; import { ContainsCC } from '@zwave-js/serial/serialapi'; import { containsCC } from '@zwave-js/serial/serialapi'; @@ -46,7 +46,7 @@ import { DataDirection } from '@zwave-js/core'; import { DataRate } from '@zwave-js/core/safe'; import { DataRate as DataRate_2 } from '@zwave-js/core'; import { DeepPartial } from '@zwave-js/shared'; -import type { DeferredPromise } from 'alcalzone-shared/deferred-promise/index.js'; +import type { DeferredPromise } from 'alcalzone-shared/deferred-promise'; import { DeviceConfig } from '@zwave-js/config'; import { DeviceID } from '@zwave-js/config'; import { Duration } from '@zwave-js/core/safe'; diff --git a/server_config.js b/server_config.js index 10fc913f0cd8..eabf48f1cd14 100644 --- a/server_config.js +++ b/server_config.js @@ -5,7 +5,7 @@ const { CommandClasses, ConfigValueFormat, SupervisionStatus } = require( const { ccCaps, MockZWaveFrameType, createMockZWaveRequestFrame } = require( "@zwave-js/testing", ); -const { wait } = require("alcalzone-shared/async/index.js"); +const { wait } = require("alcalzone-shared/async"); const { SupervisionCCGet, SupervisionCCReport, ConfigurationCCSet } = require( "zwave-js", ); diff --git a/test/run.ts b/test/run.ts index 66200b968cdb..98362510be27 100644 --- a/test/run.ts +++ b/test/run.ts @@ -1,4 +1,4 @@ -import { wait as _wait } from "alcalzone-shared/async/index.js"; +import { wait as _wait } from "alcalzone-shared/async"; import path from "node:path"; import "reflect-metadata"; import { Bytes } from "@zwave-js/shared/safe"; diff --git a/test/run_duplex.ts b/test/run_duplex.ts index 88fcf90553d4..30a9854f2c73 100644 --- a/test/run_duplex.ts +++ b/test/run_duplex.ts @@ -1,4 +1,4 @@ -import { wait as _wait } from "alcalzone-shared/async/index.js"; +import { wait as _wait } from "alcalzone-shared/async"; import path from "node:path"; import "reflect-metadata"; import { Bytes } from "@zwave-js/shared/safe"; diff --git a/test/run_zniffer.ts b/test/run_zniffer.ts index 911b922bdb83..df0ad4a5aba6 100644 --- a/test/run_zniffer.ts +++ b/test/run_zniffer.ts @@ -1,4 +1,4 @@ -import { wait as _wait } from "alcalzone-shared/async/index.js"; +import { wait as _wait } from "alcalzone-shared/async"; import "reflect-metadata"; import { Zniffer } from "zwave-js"; diff --git a/yarn.lock b/yarn.lock index bd054531817b..a1439ddb29f0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -69,9 +69,9 @@ __metadata: languageName: node linkType: hard -"@alcalzone/esm2cjs@npm:^1.2.3": - version: 1.2.3 - resolution: "@alcalzone/esm2cjs@npm:1.2.3" +"@alcalzone/esm2cjs@npm:^1.3.0": + version: 1.3.0 + resolution: "@alcalzone/esm2cjs@npm:1.3.0" dependencies: esbuild: "npm:^0.24.0" fs-extra: "npm:^10.1.0" @@ -79,7 +79,7 @@ __metadata: yargs: "npm:^17.5.1" bin: esm2cjs: bin/esm2cjs.cjs - checksum: 10/fc472f63d091db4f3888e2f4be61992ba349a9e98036371713f08fa9a02a38ac611db0dcb1e7967f251f0cdd8a246406fa1557cd9a106718eaca32bacd17573f + checksum: 10/71d83742d6ce4c32ce15ed0f11a64118ffd88a07fbb54849208de834ed32b79bd05adec46db773938cbca665863064eadde160dff99dd13c58c865a5333bfb4b languageName: node linkType: hard @@ -2558,7 +2558,7 @@ __metadata: version: 0.0.0-use.local resolution: "@zwave-js/cc@workspace:packages/cc" dependencies: - "@alcalzone/esm2cjs": "npm:^1.2.3" + "@alcalzone/esm2cjs": "npm:^1.3.0" "@microsoft/api-extractor": "npm:^7.47.9" "@types/node": "npm:^18.19.63" "@zwave-js/core": "workspace:*" @@ -2566,7 +2566,7 @@ __metadata: "@zwave-js/maintenance": "workspace:*" "@zwave-js/shared": "workspace:*" "@zwave-js/transformers": "workspace:*" - alcalzone-shared: "npm:^4.0.8" + alcalzone-shared: "npm:^5.0.0" ansi-colors: "npm:^4.1.3" del-cli: "npm:^6.0.0" es-main: "npm:^1.3.0" @@ -2581,7 +2581,7 @@ __metadata: version: 0.0.0-use.local resolution: "@zwave-js/config@workspace:packages/config" dependencies: - "@alcalzone/esm2cjs": "npm:^1.2.3" + "@alcalzone/esm2cjs": "npm:^1.3.0" "@microsoft/api-extractor": "npm:^7.47.9" "@types/js-levenshtein": "npm:^1.1.3" "@types/json-logic-js": "npm:^2.0.7" @@ -2594,7 +2594,7 @@ __metadata: "@zwave-js/core": "workspace:*" "@zwave-js/maintenance": "workspace:*" "@zwave-js/shared": "workspace:*" - alcalzone-shared: "npm:^4.0.8" + alcalzone-shared: "npm:^5.0.0" ansi-colors: "npm:^4.1.3" comment-json: "npm:^4.2.5" del-cli: "npm:^6.0.0" @@ -2621,7 +2621,7 @@ __metadata: version: 0.0.0-use.local resolution: "@zwave-js/core@workspace:packages/core" dependencies: - "@alcalzone/esm2cjs": "npm:^1.2.3" + "@alcalzone/esm2cjs": "npm:^1.3.0" "@alcalzone/jsonl-db": "npm:^3.1.1" "@microsoft/api-extractor": "npm:^7.47.9" "@types/node": "npm:^18.19.63" @@ -2629,7 +2629,7 @@ __metadata: "@types/sinon": "npm:^17.0.3" "@types/triple-beam": "npm:^1.3.5" "@zwave-js/shared": "workspace:*" - alcalzone-shared: "npm:^4.0.8" + alcalzone-shared: "npm:^5.0.0" ansi-colors: "npm:^4.1.3" dayjs: "npm:^1.11.13" del-cli: "npm:^6.0.0" @@ -2652,7 +2652,7 @@ __metadata: version: 0.0.0-use.local resolution: "@zwave-js/eslint-plugin@workspace:packages/eslint-plugin" dependencies: - "@alcalzone/esm2cjs": "npm:^1.2.3" + "@alcalzone/esm2cjs": "npm:^1.3.0" "@types/eslint": "npm:^9.6.1" "@typescript-eslint/utils": "npm:^8.8.1" "@zwave-js/core": "workspace:*" @@ -2697,13 +2697,13 @@ __metadata: version: 0.0.0-use.local resolution: "@zwave-js/host@workspace:packages/host" dependencies: - "@alcalzone/esm2cjs": "npm:^1.2.3" + "@alcalzone/esm2cjs": "npm:^1.3.0" "@microsoft/api-extractor": "npm:^7.47.9" "@types/node": "npm:^18.19.63" "@zwave-js/config": "workspace:*" "@zwave-js/core": "workspace:*" "@zwave-js/shared": "workspace:*" - alcalzone-shared: "npm:^4.0.8" + alcalzone-shared: "npm:^5.0.0" del-cli: "npm:^6.0.0" typescript: "npm:5.6.2" languageName: unknown @@ -2713,7 +2713,7 @@ __metadata: version: 0.0.0-use.local resolution: "@zwave-js/maintenance@workspace:packages/maintenance" dependencies: - "@alcalzone/esm2cjs": "npm:^1.2.3" + "@alcalzone/esm2cjs": "npm:^1.3.0" "@dprint/formatter": "npm:^0.4.1" "@dprint/json": "npm:^0.19.4" "@dprint/markdown": "npm:^0.17.8" @@ -2745,14 +2745,14 @@ __metadata: version: 0.0.0-use.local resolution: "@zwave-js/nvmedit@workspace:packages/nvmedit" dependencies: - "@alcalzone/esm2cjs": "npm:^1.2.3" + "@alcalzone/esm2cjs": "npm:^1.3.0" "@microsoft/api-extractor": "npm:^7.47.9" "@types/node": "npm:^18.19.63" "@types/semver": "npm:^7.5.8" "@types/yargs": "npm:^17.0.33" "@zwave-js/core": "workspace:*" "@zwave-js/shared": "workspace:*" - alcalzone-shared: "npm:^4.0.8" + alcalzone-shared: "npm:^5.0.0" del-cli: "npm:^6.0.0" reflect-metadata: "npm:^0.2.2" semver: "npm:^7.6.3" @@ -2772,7 +2772,7 @@ __metadata: "@actions/core": "npm:^1.11.1" "@actions/exec": "npm:^1.1.1" "@actions/github": "npm:^6.0.0" - "@alcalzone/esm2cjs": "npm:^1.2.3" + "@alcalzone/esm2cjs": "npm:^1.3.0" "@alcalzone/jsonl-db": "npm:^3.1.1" "@alcalzone/monopack": "npm:^1.3.0" "@alcalzone/release-script": "npm:~3.8.0" @@ -2801,7 +2801,7 @@ __metadata: "@zwave-js/serial": "workspace:*" "@zwave-js/shared": "workspace:*" "@zwave-js/testing": "workspace:*" - alcalzone-shared: "npm:^4.0.8" + alcalzone-shared: "npm:^5.0.0" ansi-colors: "npm:^4.1.3" chokidar: "npm:^4.0.1" comment-json: "npm:^4.2.5" @@ -2836,7 +2836,7 @@ __metadata: version: 0.0.0-use.local resolution: "@zwave-js/serial@workspace:packages/serial" dependencies: - "@alcalzone/esm2cjs": "npm:^1.2.3" + "@alcalzone/esm2cjs": "npm:^1.3.0" "@microsoft/api-extractor": "npm:^7.47.9" "@serialport/binding-mock": "npm:^10.2.2" "@serialport/bindings-interface": "patch:@serialport/bindings-interface@npm%3A1.2.2#~/.yarn/patches/@serialport-bindings-interface-npm-1.2.2-e597dbc676.patch" @@ -2847,7 +2847,7 @@ __metadata: "@zwave-js/core": "workspace:*" "@zwave-js/host": "workspace:*" "@zwave-js/shared": "workspace:*" - alcalzone-shared: "npm:^4.0.8" + alcalzone-shared: "npm:^5.0.0" ansi-colors: "npm:^4.1.3" del-cli: "npm:^6.0.0" serialport: "npm:^12.0.0" @@ -2863,11 +2863,11 @@ __metadata: version: 0.0.0-use.local resolution: "@zwave-js/shared@workspace:packages/shared" dependencies: - "@alcalzone/esm2cjs": "npm:^1.2.3" + "@alcalzone/esm2cjs": "npm:^1.3.0" "@microsoft/api-extractor": "npm:^7.47.9" "@types/node": "npm:^18.19.63" "@types/sinon": "npm:^17.0.3" - alcalzone-shared: "npm:^4.0.8" + alcalzone-shared: "npm:^5.0.0" del-cli: "npm:^6.0.0" sinon: "npm:^19.0.2" tsx: "npm:^4.19.2" @@ -2880,7 +2880,7 @@ __metadata: version: 0.0.0-use.local resolution: "@zwave-js/testing@workspace:packages/testing" dependencies: - "@alcalzone/esm2cjs": "npm:^1.2.3" + "@alcalzone/esm2cjs": "npm:^1.3.0" "@microsoft/api-extractor": "npm:^7.47.9" "@types/node": "npm:^18.19.63" "@types/triple-beam": "npm:^1.3.5" @@ -2889,7 +2889,7 @@ __metadata: "@zwave-js/host": "workspace:*" "@zwave-js/serial": "workspace:*" "@zwave-js/shared": "workspace:*" - alcalzone-shared: "npm:^4.0.8" + alcalzone-shared: "npm:^5.0.0" ansi-colors: "npm:^4.1.3" del-cli: "npm:^6.0.0" triple-beam: "npm:*" @@ -3111,6 +3111,13 @@ __metadata: languageName: node linkType: hard +"alcalzone-shared@npm:^5.0.0": + version: 5.0.0 + resolution: "alcalzone-shared@npm:5.0.0" + checksum: 10/79f69256314796b319184b60d013d9b5be65298ad321b55a7eb477e50b5cdb09e9d75d8042efcb747cc41a48677f621c8b9fe163c19c8b0f0fda572e2942a66f + languageName: node + linkType: hard + "ansi-colors@npm:^4.1.1": version: 4.1.1 resolution: "ansi-colors@npm:4.1.1" @@ -10052,7 +10059,7 @@ __metadata: version: 0.0.0-use.local resolution: "zwave-js@workspace:packages/zwave-js" dependencies: - "@alcalzone/esm2cjs": "npm:^1.2.3" + "@alcalzone/esm2cjs": "npm:^1.3.0" "@alcalzone/jsonl-db": "npm:^3.1.1" "@homebridge/ciao": "npm:^1.3.1" "@microsoft/api-extractor": "npm:^7.47.9" @@ -10073,7 +10080,7 @@ __metadata: "@zwave-js/shared": "workspace:*" "@zwave-js/testing": "workspace:*" "@zwave-js/transformers": "workspace:*" - alcalzone-shared: "npm:^4.0.8" + alcalzone-shared: "npm:^5.0.0" ansi-colors: "npm:^4.1.3" del-cli: "npm:^6.0.0" execa: "npm:^5.1.1"