@zwave-js/nvmedit 14.1.0 → 14.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,10 +39,14 @@ __export(convert_exports, {
39
39
  nvmToJSON: () => nvmToJSON
40
40
  });
41
41
  module.exports = __toCommonJS(convert_exports);
42
+ var import_error = require("@zwave-js/core/error");
42
43
  var import_safe = require("@zwave-js/core/safe");
43
44
  var import_safe2 = require("@zwave-js/shared/safe");
44
45
  var import_typeguards = require("alcalzone-shared/typeguards");
45
- var import_semver = __toESM(require("semver"), 1);
46
+ var import_gte = __toESM(require("semver/functions/gte.js"), 1);
47
+ var import_lt = __toESM(require("semver/functions/lt.js"), 1);
48
+ var import_lte = __toESM(require("semver/functions/lte.js"), 1);
49
+ var import_parse = __toESM(require("semver/functions/parse.js"), 1);
46
50
  var import_consts = require("./consts.js");
47
51
  var import_NVM3 = require("./lib/NVM3.js");
48
52
  var import_NVM500 = require("./lib/NVM500.js");
@@ -125,7 +129,7 @@ function nvmObjectsToJSON(objects) {
125
129
  const ret2 = getObject(id);
126
130
  if (ret2)
127
131
  return ret2;
128
- throw new import_safe.ZWaveError(`Object${typeof id === "number" ? ` ${(0, import_safe2.num2hex)(id)} (${id})` : ""} not found!`, import_safe.ZWaveErrorCodes.NVM_ObjectNotFound);
132
+ throw new import_error.ZWaveError(`Object${typeof id === "number" ? ` ${(0, import_safe2.num2hex)(id)} (${id})` : ""} not found!`, import_error.ZWaveErrorCodes.NVM_ObjectNotFound);
129
133
  };
130
134
  const getFileOrThrow = (id, fileVersion) => {
131
135
  const obj = getObjectOrThrow(id);
@@ -141,7 +145,7 @@ function nvmObjectsToJSON(objects) {
141
145
  const protocolFileFormat = protocolVersionFile.format;
142
146
  const protocolVersion = `${protocolVersionFile.major}.${protocolVersionFile.minor}.${protocolVersionFile.patch}`;
143
147
  if (protocolFileFormat > import_consts.MAX_PROTOCOL_FILE_FORMAT) {
144
- throw new import_safe.ZWaveError(`Unsupported protocol file format: ${protocolFileFormat}`, import_safe.ZWaveErrorCodes.NVM_NotSupported, { protocolFileFormat });
148
+ throw new import_error.ZWaveError(`Unsupported protocol file format: ${protocolFileFormat}`, import_error.ZWaveErrorCodes.NVM_NotSupported, { protocolFileFormat });
145
149
  }
146
150
  const nodeIds = getFileOrThrow(import_files.ProtocolNodeListFileID, protocolVersion).nodeIds;
147
151
  const appRouteLock = new Set(getFileOrThrow(import_files.ProtocolAppRouteLockNodeMaskFileID, protocolVersion).nodeIds);
@@ -226,7 +230,7 @@ function nvmObjectsToJSON(objects) {
226
230
  const applicationVersionFile800 = getFile(import_files.ApplicationVersionFile800ID, "7.0.0");
227
231
  const applicationVersionFile = applicationVersionFile700 ?? applicationVersionFile800;
228
232
  if (!applicationVersionFile) {
229
- throw new import_safe.ZWaveError("ApplicationVersionFile not found!", import_safe.ZWaveErrorCodes.NVM_ObjectNotFound);
233
+ throw new import_error.ZWaveError("ApplicationVersionFile not found!", import_error.ZWaveErrorCodes.NVM_ObjectNotFound);
230
234
  }
231
235
  const applicationVersion = `${applicationVersionFile.major}.${applicationVersionFile.minor}.${applicationVersionFile.patch}`;
232
236
  const rfConfigFile = getFile(import_files.ApplicationRFConfigFileID, applicationVersion);
@@ -406,7 +410,7 @@ async function nvmToJSON(buffer, debugLogs = false) {
406
410
  type: "protocolFileFormat"
407
411
  }, true);
408
412
  if (protocolFileFormat > import_consts.MAX_PROTOCOL_FILE_FORMAT) {
409
- throw new import_safe.ZWaveError(`Unsupported protocol file format: ${protocolFileFormat}`, import_safe.ZWaveErrorCodes.NVM_NotSupported, { protocolFileFormat });
413
+ throw new import_error.ZWaveError(`Unsupported protocol file format: ${protocolFileFormat}`, import_error.ZWaveErrorCodes.NVM_NotSupported, { protocolFileFormat });
410
414
  }
411
415
  const protocolVersion = await adapter.get({
412
416
  domain: "controller",
@@ -761,9 +765,9 @@ async function nvm500ToJSON(buffer) {
761
765
  };
762
766
  }
763
767
  async function jsonToNVM(json, targetSDKVersion) {
764
- const parsedVersion = import_semver.default.parse(targetSDKVersion);
768
+ const parsedVersion = (0, import_parse.default)(targetSDKVersion);
765
769
  if (!parsedVersion) {
766
- throw new import_safe.ZWaveError(`Invalid SDK version: ${targetSDKVersion}`, import_safe.ZWaveErrorCodes.Argument_Invalid);
770
+ throw new import_error.ZWaveError(`Invalid SDK version: ${targetSDKVersion}`, import_error.ZWaveErrorCodes.Argument_Invalid);
767
771
  }
768
772
  const sharedFileSystem = json.meta?.sharedFileSystem;
769
773
  const nvmSize = sharedFileSystem ? import_consts2.ZWAVE_SHARED_NVM_SIZE : import_consts2.ZWAVE_APPLICATION_NVM_SIZE + import_consts2.ZWAVE_PROTOCOL_NVM_SIZE;
@@ -779,28 +783,28 @@ async function jsonToNVM(json, targetSDKVersion) {
779
783
  let targetProtocolVersion;
780
784
  let targetProtocolFormat;
781
785
  const HIGHEST_SUPPORTED_SDK_VERSION = "7.21.0";
782
- if (import_semver.default.lte(targetSDKVersion, HIGHEST_SUPPORTED_SDK_VERSION)) {
783
- targetApplicationVersion = import_semver.default.parse(targetSDKVersion);
786
+ if ((0, import_lte.default)(targetSDKVersion, HIGHEST_SUPPORTED_SDK_VERSION)) {
787
+ targetApplicationVersion = (0, import_parse.default)(targetSDKVersion);
784
788
  } else {
785
- targetApplicationVersion = import_semver.default.parse(HIGHEST_SUPPORTED_SDK_VERSION);
789
+ targetApplicationVersion = (0, import_parse.default)(HIGHEST_SUPPORTED_SDK_VERSION);
786
790
  }
787
- if (import_semver.default.gte(targetSDKVersion, "7.19.0")) {
788
- targetProtocolVersion = import_semver.default.parse("7.19.0");
791
+ if ((0, import_gte.default)(targetSDKVersion, "7.19.0")) {
792
+ targetProtocolVersion = (0, import_parse.default)("7.19.0");
789
793
  targetProtocolFormat = 5;
790
- } else if (import_semver.default.gte(targetSDKVersion, "7.17.0")) {
791
- targetProtocolVersion = import_semver.default.parse("7.17.0");
794
+ } else if ((0, import_gte.default)(targetSDKVersion, "7.17.0")) {
795
+ targetProtocolVersion = (0, import_parse.default)("7.17.0");
792
796
  targetProtocolFormat = 4;
793
- } else if (import_semver.default.gte(targetSDKVersion, "7.15.3")) {
794
- targetProtocolVersion = import_semver.default.parse("7.15.3");
797
+ } else if ((0, import_gte.default)(targetSDKVersion, "7.15.3")) {
798
+ targetProtocolVersion = (0, import_parse.default)("7.15.3");
795
799
  targetProtocolFormat = 3;
796
- } else if (import_semver.default.gte(targetSDKVersion, "7.12.0")) {
797
- targetProtocolVersion = import_semver.default.parse("7.12.0");
800
+ } else if ((0, import_gte.default)(targetSDKVersion, "7.12.0")) {
801
+ targetProtocolVersion = (0, import_parse.default)("7.12.0");
798
802
  targetProtocolFormat = 2;
799
- } else if (import_semver.default.gte(targetSDKVersion, "7.11.0")) {
800
- targetProtocolVersion = import_semver.default.parse("7.11.0");
803
+ } else if ((0, import_gte.default)(targetSDKVersion, "7.11.0")) {
804
+ targetProtocolVersion = (0, import_parse.default)("7.11.0");
801
805
  targetProtocolFormat = 1;
802
806
  } else {
803
- targetProtocolVersion = import_semver.default.parse("7.0.0");
807
+ targetProtocolVersion = (0, import_parse.default)("7.0.0");
804
808
  targetProtocolFormat = 0;
805
809
  }
806
810
  const target = (0, import_safe2.cloneDeep)(json);
@@ -858,11 +862,11 @@ async function jsonToNVM(json, targetSDKVersion) {
858
862
  maxTXPower: null,
859
863
  nodeIdType: null
860
864
  };
861
- if (import_semver.default.gte(targetSDKVersion, "7.15.3")) {
865
+ if ((0, import_gte.default)(targetSDKVersion, "7.15.3")) {
862
866
  target.controller.rfConfig.enablePTI ??= 0;
863
867
  target.controller.rfConfig.maxTXPower ??= 14;
864
868
  }
865
- if (import_semver.default.gte(targetSDKVersion, "7.21.0")) {
869
+ if ((0, import_gte.default)(targetSDKVersion, "7.21.0")) {
866
870
  target.controller.rfConfig.nodeIdType ??= import_safe.NodeIDType.Short;
867
871
  }
868
872
  const applRFConfigFile = new import_files.ApplicationRFConfigFile({
@@ -953,7 +957,7 @@ async function jsonToNVM(json, targetSDKVersion) {
953
957
  async function jsonToNVM500(json, protocolVersion) {
954
958
  const impl = import_impls.nvm500Impls.find((p) => p.protocolVersions.includes(protocolVersion) && p.name.toLowerCase().startsWith(json.meta.library));
955
959
  if (!impl) {
956
- throw new import_safe.ZWaveError(`Did not find a matching implementation for protocol version ${protocolVersion} and library ${json.meta.library}. To convert 500-series NVMs, both the source and the target controller must be using Z-Wave SDK 6.61 or higher.`, import_safe.ZWaveErrorCodes.NVM_NotSupported);
960
+ throw new import_error.ZWaveError(`Did not find a matching implementation for protocol version ${protocolVersion} and library ${json.meta.library}. To convert 500-series NVMs, both the source and the target controller must be using Z-Wave SDK 6.61 or higher.`, import_error.ZWaveErrorCodes.NVM_NotSupported);
957
961
  }
958
962
  const { layout, nvmSize } = (0, import_shared.resolveLayout)(impl.layout);
959
963
  const ret = new Uint8Array(nvmSize);
@@ -1064,7 +1068,7 @@ function json500To700(json, truncateApplicationData) {
1064
1068
  raw = raw.subarray(start, end + 1);
1065
1069
  if (raw.length > 512) {
1066
1070
  if (!truncateApplicationData) {
1067
- throw new import_safe.ZWaveError("Invalid NVM JSON: Application data would be truncated! Set truncateApplicationData to true to allow this.", import_safe.ZWaveErrorCodes.NVM_InvalidJSON);
1071
+ throw new import_error.ZWaveError("Invalid NVM JSON: Application data would be truncated! Set truncateApplicationData to true to allow this.", import_error.ZWaveErrorCodes.NVM_InvalidJSON);
1068
1072
  }
1069
1073
  raw = raw.subarray(0, 512);
1070
1074
  }
@@ -1191,12 +1195,12 @@ async function migrateNVM(sourceNVM, targetNVM) {
1191
1195
  };
1192
1196
  sourceProtocolFileFormat = source.json.format;
1193
1197
  } catch (e) {
1194
- if ((0, import_safe.isZWaveError)(e) && e.code === import_safe.ZWaveErrorCodes.NVM_InvalidFormat) {
1198
+ if ((0, import_error.isZWaveError)(e) && e.code === import_error.ZWaveErrorCodes.NVM_InvalidFormat) {
1195
1199
  source = {
1196
1200
  type: 500,
1197
1201
  json: await nvm500ToJSON(sourceNVM)
1198
1202
  };
1199
- } else if ((0, import_safe.isZWaveError)(e) && e.code === import_safe.ZWaveErrorCodes.NVM_NotSupported && (0, import_typeguards.isObject)(e.context) && typeof e.context.protocolFileFormat === "number") {
1203
+ } else if ((0, import_error.isZWaveError)(e) && e.code === import_error.ZWaveErrorCodes.NVM_NotSupported && (0, import_typeguards.isObject)(e.context) && typeof e.context.protocolFileFormat === "number") {
1200
1204
  source = { type: "unknown" };
1201
1205
  sourceProtocolFileFormat = e.context.protocolFileFormat;
1202
1206
  } else {
@@ -1210,12 +1214,12 @@ async function migrateNVM(sourceNVM, targetNVM) {
1210
1214
  };
1211
1215
  targetProtocolFileFormat = target.json.format;
1212
1216
  } catch (e) {
1213
- if ((0, import_safe.isZWaveError)(e) && e.code === import_safe.ZWaveErrorCodes.NVM_InvalidFormat) {
1217
+ if ((0, import_error.isZWaveError)(e) && e.code === import_error.ZWaveErrorCodes.NVM_InvalidFormat) {
1214
1218
  target = {
1215
1219
  type: 500,
1216
1220
  json: await nvm500ToJSON(targetNVM)
1217
1221
  };
1218
- } else if ((0, import_safe.isZWaveError)(e) && e.code === import_safe.ZWaveErrorCodes.NVM_NotSupported && source.type === 700 && (0, import_typeguards.isObject)(e.context) && typeof e.context.protocolFileFormat === "number") {
1222
+ } else if ((0, import_error.isZWaveError)(e) && e.code === import_error.ZWaveErrorCodes.NVM_NotSupported && source.type === 700 && (0, import_typeguards.isObject)(e.context) && typeof e.context.protocolFileFormat === "number") {
1219
1223
  target = { type: "unknown" };
1220
1224
  targetProtocolFileFormat = e.context.protocolFileFormat;
1221
1225
  } else {
@@ -1229,19 +1233,19 @@ async function migrateNVM(sourceNVM, targetNVM) {
1229
1233
  const targetProtocolVersion = target.json.controller.protocolVersion;
1230
1234
  const sourceApplicationVersion = source.json.controller.applicationVersion;
1231
1235
  const targetApplicationVersion = target.json.controller.applicationVersion;
1232
- if (import_semver.default.gte(targetProtocolVersion, "7.16.0") && import_semver.default.gte(targetProtocolVersion, sourceProtocolVersion) && import_semver.default.gte(targetApplicationVersion, targetProtocolVersion) && import_semver.default.gte(sourceApplicationVersion, sourceProtocolVersion) && import_semver.default.lt(sourceApplicationVersion, "255.0.0") && import_semver.default.lt(targetApplicationVersion, "255.0.0") && !hasShiftedAppVersion800File(source.json)) {
1236
+ if ((0, import_gte.default)(targetProtocolVersion, "7.16.0") && (0, import_gte.default)(targetProtocolVersion, sourceProtocolVersion) && (0, import_gte.default)(targetApplicationVersion, targetProtocolVersion) && (0, import_gte.default)(sourceApplicationVersion, sourceProtocolVersion) && (0, import_lt.default)(sourceApplicationVersion, "255.0.0") && (0, import_lt.default)(targetApplicationVersion, "255.0.0") && !hasShiftedAppVersion800File(source.json)) {
1233
1237
  return sourceNVM;
1234
1238
  }
1235
1239
  } else if (source.type === "unknown" && target.type !== "unknown") {
1236
- throw new import_safe.ZWaveError(`The source NVM has an unsupported format, which cannot be restored on a ${target.type}-series NVM!`, import_safe.ZWaveErrorCodes.NVM_NotSupported);
1240
+ throw new import_error.ZWaveError(`The source NVM has an unsupported format, which cannot be restored on a ${target.type}-series NVM!`, import_error.ZWaveErrorCodes.NVM_NotSupported);
1237
1241
  } else if (source.type !== "unknown" && target.type === "unknown") {
1238
- throw new import_safe.ZWaveError(`The target NVM has an unsupported format, cannot restore ${source.type}-series NVM onto it!`, import_safe.ZWaveErrorCodes.NVM_NotSupported);
1242
+ throw new import_error.ZWaveError(`The target NVM has an unsupported format, cannot restore ${source.type}-series NVM onto it!`, import_error.ZWaveErrorCodes.NVM_NotSupported);
1239
1243
  } else if (source.type === "unknown" && target.type === "unknown") {
1240
1244
  return sourceNVM;
1241
1245
  }
1242
1246
  source = source;
1243
1247
  target = target;
1244
- if (target.type === 700 && import_semver.default.gte(target.json.controller.applicationVersion, "255.0.0")) {
1248
+ if (target.type === 700 && (0, import_gte.default)(target.json.controller.applicationVersion, "255.0.0")) {
1245
1249
  target.json.controller.applicationVersion = target.json.controller.protocolVersion;
1246
1250
  }
1247
1251
  source.json.controller.applicationVersion = target.json.controller.applicationVersion;
@@ -1278,10 +1282,10 @@ async function migrateNVM(sourceNVM, targetNVM) {
1278
1282
  function hasShiftedAppVersion800File(json) {
1279
1283
  if (!json.meta.sharedFileSystem)
1280
1284
  return false;
1281
- const protocolVersion = import_semver.default.parse(json.controller.protocolVersion);
1285
+ const protocolVersion = (0, import_parse.default)(json.controller.protocolVersion);
1282
1286
  if (!protocolVersion)
1283
1287
  return false;
1284
- const applicationVersion = import_semver.default.parse(json.controller.applicationVersion);
1288
+ const applicationVersion = (0, import_parse.default)(json.controller.applicationVersion);
1285
1289
  if (!applicationVersion)
1286
1290
  return false;
1287
1291
  if (json.applicationFileFormat !== protocolVersion.major)