@zwave-js/nvmedit 15.0.6 → 15.1.1

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.
package/build/cjs/cli.js CHANGED
@@ -158,11 +158,43 @@ Create a backup of the target stick, use the nvm2json command to convert it to J
158
158
  describe: "The output filename where the convert NVM will be written.",
159
159
  type: "string",
160
160
  required: true
161
+ },
162
+ noAppData: {
163
+ describe: "Whether application data should be stripped during the migration",
164
+ type: "boolean",
165
+ default: false
166
+ },
167
+ noRoutes: {
168
+ describe: "Whether known routes should be stripped during the migration",
169
+ type: "boolean",
170
+ default: false
171
+ },
172
+ noNeighbors: {
173
+ describe: "Whether information about neighbors should be stripped during the migration",
174
+ type: "boolean",
175
+ default: false
176
+ },
177
+ noSUCEntries: {
178
+ describe: "Whether SUC update entries should be stripped during the migration",
179
+ type: "boolean",
180
+ default: false
181
+ },
182
+ noOptional: {
183
+ describe: "Strip all optional information from the NVM. Overrides all other noXYZ flags.",
184
+ type: "boolean",
185
+ default: false
161
186
  }
162
187
  }), async (argv) => {
188
+ const { noAppData, noNeighbors, noRoutes, noSUCEntries, noOptional } = argv;
189
+ const options = {
190
+ preserveApplicationData: !noOptional && !noAppData,
191
+ preserveRoutes: !noOptional && !noRoutes,
192
+ preserveNeighbors: !noOptional && !noNeighbors,
193
+ preserveSUCUpdateEntries: !noOptional && !noSUCEntries
194
+ };
163
195
  const source = await import_node.fs.readFile(argv.source);
164
196
  const target = await import_node.fs.readFile(argv.target);
165
- const output = await (0, import_convert.migrateNVM)(source, target);
197
+ const output = await (0, import_convert.migrateNVM)(source, target, options);
166
198
  await import_node.fs.writeFile(argv.out, output);
167
199
  console.error(`Converted NVM written to ${argv.out}`);
168
200
  process.exit(0);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/cli.ts"],
4
- "sourcesContent": ["import { readJSON, writeTextFile } from \"@zwave-js/shared\";\nimport { isObject } from \"alcalzone-shared/typeguards\";\nimport \"reflect-metadata\";\nimport { fs } from \"@zwave-js/core/bindings/fs/node\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\nimport {\n\tjson500To700,\n\tjson700To500,\n\tjsonToNVM,\n\tjsonToNVM500,\n\tmigrateNVM,\n\tnvm500ToJSON,\n\tnvmToJSON,\n} from \"./convert.js\";\n\nconst yargsInstance = yargs(hideBin(process.argv));\n\nvoid yargsInstance\n\t.env(\"NVMEDIT\")\n\t.strict()\n\t.usage(\"Z-Wave JS NVM converter utility\\n\\nUsage: $0 [options]\")\n\t.alias(\"h\", \"help\")\n\t.alias(\"v\", \"version\")\n\t.wrap(Math.min(100, yargsInstance.terminalWidth()))\n\t.options({\n\t\tverbose: {\n\t\t\talias: \"vv\",\n\t\t\tdescribe: \"Print verbose output\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t})\n\t.command(\n\t\t\"nvm2json\",\n\t\t\"Convert an NVM backup to JSON\",\n\t\t(yargs) =>\n\t\t\tyargs.usage(\"$0 nvm2json --in <input> --out <output>\").options({\n\t\t\t\tin: {\n\t\t\t\t\tdescribe: \"NVM backup filename\",\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t},\n\t\t\t\tout: {\n\t\t\t\t\tdescribe: \"JSON output filename\",\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t},\n\t\t\t}),\n\t\tasync (argv) => {\n\t\t\tconst buffer = await fs.readFile(argv.in);\n\t\t\tlet json: any;\n\t\t\ttry {\n\t\t\t\tjson = await nvmToJSON(buffer, argv.verbose);\n\t\t\t} catch (e) {\n\t\t\t\ttry {\n\t\t\t\t\tjson = await nvm500ToJSON(buffer);\n\t\t\t\t} catch {\n\t\t\t\t\tconsole.error(e);\n\t\t\t\t\tprocess.exit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tawait writeTextFile(fs, argv.out, JSON.stringify(json, null, \"\\t\"));\n\t\t\tconsole.error(`NVM (JSON) written to ${argv.out}`);\n\n\t\t\tprocess.exit(0);\n\t\t},\n\t)\n\t.command(\n\t\t\"json2nvm\",\n\t\t\"Convert the JSON representation of an NVM to binary\",\n\t\t(yargs) =>\n\t\t\tyargs\n\t\t\t\t.usage(\n\t\t\t\t\t\"$0 json2nvm --in <input> --out <output> --protocolVersion <version>\",\n\t\t\t\t)\n\t\t\t\t.options({\n\t\t\t\t\tin: {\n\t\t\t\t\t\tdescribe: \"JSON input filename\",\n\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t},\n\t\t\t\t\tout: {\n\t\t\t\t\t\tdescribe: \"NVM output filename\",\n\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t},\n\t\t\t\t\tprotocolVersion: {\n\t\t\t\t\t\talias: \"V\",\n\t\t\t\t\t\tdescribe:\n\t\t\t\t\t\t\t\"target protocol version, determines the NVM format\",\n\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\tasync (argv) => {\n\t\t\tconst { protocolVersion } = argv;\n\t\t\tconst versionIs500 = /^\\d\\.\\d+$/.test(protocolVersion);\n\n\t\t\tconst json = await readJSON(fs, argv.in);\n\t\t\tconst jsonIs500 = json.format === 500;\n\t\t\tif (versionIs500 && !jsonIs500) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`ERROR: Protocol version ${protocolVersion} looks like a 500-series version, but the JSON file does not belong to a 500-series NVM!\nConvert it first using the 700to500 command.`,\n\t\t\t\t);\n\t\t\t\tprocess.exit(1);\n\t\t\t} else if (jsonIs500 && !versionIs500) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`ERROR: Protocol version ${protocolVersion} looks like a 700-series version, but the JSON file belong to a 500-series NVM!\nConvert it first using the 500to700 command.`,\n\t\t\t\t);\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\tif (!isObject(json.meta)) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`ERROR: The JSON file does not contain the meta section, which is required for the conversion to a binary NVM!\nCreate a backup of the target stick, use the nvm2json command to convert it to JSON and copy the meta section from there.`,\n\t\t\t\t);\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\tconst nvm = versionIs500\n\t\t\t\t? await jsonToNVM500(json, protocolVersion)\n\t\t\t\t: await jsonToNVM(json, protocolVersion);\n\t\t\tawait fs.writeFile(argv.out, nvm);\n\t\t\tconsole.error(`NVM (binary) written to ${argv.out}`);\n\n\t\t\tprocess.exit(0);\n\t\t},\n\t)\n\t.command(\n\t\t\"500to700\",\n\t\t\"Convert a 500-series JSON file into a 700-series JSON file\",\n\t\t(yargs) =>\n\t\t\tyargs\n\t\t\t\t.usage(\"$0 500to700 --in <input> --out <output> [--truncate]\")\n\t\t\t\t.options({\n\t\t\t\t\tin: {\n\t\t\t\t\t\tdescribe: \"500 series JSON input filename\",\n\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t},\n\t\t\t\t\tout: {\n\t\t\t\t\t\tdescribe: \"700 series output filename\",\n\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t},\n\t\t\t\t\ttruncate: {\n\t\t\t\t\t\talias: \"t\",\n\t\t\t\t\t\tdescribe:\n\t\t\t\t\t\t\t\"Truncate application data if it is too large (> 512 bytes)\",\n\t\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\t\trequired: false,\n\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\tasync (argv) => {\n\t\t\tconst json500 = await readJSON(fs, argv.in);\n\t\t\tconst json700 = json500To700(json500, argv.truncate);\n\t\t\tawait writeTextFile(\n\t\t\t\tfs,\n\t\t\t\targv.out,\n\t\t\t\tJSON.stringify(json700, null, \"\\t\"),\n\t\t\t);\n\t\t\tconsole.error(`700-series NVM (JSON) written to ${argv.out}`);\n\n\t\t\tprocess.exit(0);\n\t\t},\n\t)\n\t.command(\n\t\t\"700to500\",\n\t\t\"Convert a 700-series JSON file into a 500-series JSON file\",\n\t\t(yargs) =>\n\t\t\tyargs.usage(\"$0 700to500 --in <input> --out <output>\").options({\n\t\t\t\tin: {\n\t\t\t\t\tdescribe: \"700 series JSON input filename\",\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t},\n\t\t\t\tout: {\n\t\t\t\t\tdescribe: \"500 series output filename\",\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t},\n\t\t\t}),\n\t\tasync (argv) => {\n\t\t\tconst json700 = await readJSON(fs, argv.in);\n\t\t\tconst json500 = json700To500(json700);\n\t\t\tawait writeTextFile(\n\t\t\t\tfs,\n\t\t\t\targv.out,\n\t\t\t\tJSON.stringify(json500, null, \"\\t\"),\n\t\t\t);\n\t\t\tconsole.error(`500-series NVM (JSON) written to ${argv.out}`);\n\n\t\t\tprocess.exit(0);\n\t\t},\n\t)\n\t.command(\n\t\t\"convert\",\n\t\t\"Convert the format of an NVM backup between different Z-Wave modules\",\n\t\t(yargs) =>\n\t\t\tyargs\n\t\t\t\t.usage(\n\t\t\t\t\t\"$0 convert --source <source> --target <target> --out <output>\",\n\t\t\t\t)\n\t\t\t\t.options({\n\t\t\t\t\tsource: {\n\t\t\t\t\t\tdescribe:\n\t\t\t\t\t\t\t\"The source NVM filename. This file will be converted to match the target NVM.\",\n\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t},\n\t\t\t\t\ttarget: {\n\t\t\t\t\t\tdescribe:\n\t\t\t\t\t\t\t\"The target NVM filename. This file will used to determine how to convert the source NVM.\",\n\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t},\n\t\t\t\t\tout: {\n\t\t\t\t\t\tdescribe:\n\t\t\t\t\t\t\t\"The output filename where the convert NVM will be written.\",\n\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\tasync (argv) => {\n\t\t\tconst source = await fs.readFile(argv.source);\n\t\t\tconst target = await fs.readFile(argv.target);\n\t\t\tconst output = await migrateNVM(source, target);\n\t\t\tawait fs.writeFile(argv.out, output);\n\t\t\tconsole.error(`Converted NVM written to ${argv.out}`);\n\n\t\t\tprocess.exit(0);\n\t\t},\n\t)\n\t.demandCommand(1, \"Please specify a command\")\n\t.parseAsync();\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA,oBAAwC;AACxC,wBAAyB;AACzB,8BAAO;AACP,kBAAmB;AACnB,mBAAkB;AAClB,qBAAwB;AACxB,qBAQO;AAEP,MAAM,oBAAgB,aAAAA,aAAM,wBAAQ,QAAQ,IAAI,CAAC;AAEjD,KAAK,cACH,IAAI,SAAS,EACb,OAAM,EACN,MAAM,wDAAwD,EAC9D,MAAM,KAAK,MAAM,EACjB,MAAM,KAAK,SAAS,EACpB,KAAK,KAAK,IAAI,KAAK,cAAc,cAAa,CAAE,CAAC,EACjD,QAAQ;EACR,SAAS;IACR,OAAO;IACP,UAAU;IACV,MAAM;;CAEP,EACA,QACA,YACA,iCACA,CAACA,WACAA,OAAM,MAAM,yCAAyC,EAAE,QAAQ;EAC9D,IAAI;IACH,UAAU;IACV,MAAM;IACN,UAAU;;EAEX,KAAK;IACJ,UAAU;IACV,MAAM;IACN,UAAU;;CAEX,GACF,OAAO,SAAQ;AACd,QAAM,SAAS,MAAM,eAAG,SAAS,KAAK,EAAE;AACxC,MAAI;AACJ,MAAI;AACH,WAAO,UAAM,0BAAU,QAAQ,KAAK,OAAO;EAC5C,SAAS,GAAG;AACX,QAAI;AACH,aAAO,UAAM,6BAAa,MAAM;IACjC,QAAQ;AACP,cAAQ,MAAM,CAAC;AACf,cAAQ,KAAK,CAAC;IACf;EACD;AACA,YAAM,6BAAc,gBAAI,KAAK,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",
4
+ "sourcesContent": ["import { readJSON, writeTextFile } from \"@zwave-js/shared\";\nimport { isObject } from \"alcalzone-shared/typeguards\";\nimport \"reflect-metadata\";\nimport { fs } from \"@zwave-js/core/bindings/fs/node\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\nimport {\n\ttype MigrateNVMOptions,\n\tjson500To700,\n\tjson700To500,\n\tjsonToNVM,\n\tjsonToNVM500,\n\tmigrateNVM,\n\tnvm500ToJSON,\n\tnvmToJSON,\n} from \"./convert.js\";\n\nconst yargsInstance = yargs(hideBin(process.argv));\n\nvoid yargsInstance\n\t.env(\"NVMEDIT\")\n\t.strict()\n\t.usage(\"Z-Wave JS NVM converter utility\\n\\nUsage: $0 [options]\")\n\t.alias(\"h\", \"help\")\n\t.alias(\"v\", \"version\")\n\t.wrap(Math.min(100, yargsInstance.terminalWidth()))\n\t.options({\n\t\tverbose: {\n\t\t\talias: \"vv\",\n\t\t\tdescribe: \"Print verbose output\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t})\n\t.command(\n\t\t\"nvm2json\",\n\t\t\"Convert an NVM backup to JSON\",\n\t\t(yargs) =>\n\t\t\tyargs.usage(\"$0 nvm2json --in <input> --out <output>\").options({\n\t\t\t\tin: {\n\t\t\t\t\tdescribe: \"NVM backup filename\",\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t},\n\t\t\t\tout: {\n\t\t\t\t\tdescribe: \"JSON output filename\",\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t},\n\t\t\t}),\n\t\tasync (argv) => {\n\t\t\tconst buffer = await fs.readFile(argv.in);\n\t\t\tlet json: any;\n\t\t\ttry {\n\t\t\t\tjson = await nvmToJSON(buffer, argv.verbose);\n\t\t\t} catch (e) {\n\t\t\t\ttry {\n\t\t\t\t\tjson = await nvm500ToJSON(buffer);\n\t\t\t\t} catch {\n\t\t\t\t\tconsole.error(e);\n\t\t\t\t\tprocess.exit(1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tawait writeTextFile(fs, argv.out, JSON.stringify(json, null, \"\\t\"));\n\t\t\tconsole.error(`NVM (JSON) written to ${argv.out}`);\n\n\t\t\tprocess.exit(0);\n\t\t},\n\t)\n\t.command(\n\t\t\"json2nvm\",\n\t\t\"Convert the JSON representation of an NVM to binary\",\n\t\t(yargs) =>\n\t\t\tyargs\n\t\t\t\t.usage(\n\t\t\t\t\t\"$0 json2nvm --in <input> --out <output> --protocolVersion <version>\",\n\t\t\t\t)\n\t\t\t\t.options({\n\t\t\t\t\tin: {\n\t\t\t\t\t\tdescribe: \"JSON input filename\",\n\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t},\n\t\t\t\t\tout: {\n\t\t\t\t\t\tdescribe: \"NVM output filename\",\n\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t},\n\t\t\t\t\tprotocolVersion: {\n\t\t\t\t\t\talias: \"V\",\n\t\t\t\t\t\tdescribe:\n\t\t\t\t\t\t\t\"target protocol version, determines the NVM format\",\n\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\tasync (argv) => {\n\t\t\tconst { protocolVersion } = argv;\n\t\t\tconst versionIs500 = /^\\d\\.\\d+$/.test(protocolVersion);\n\n\t\t\tconst json = await readJSON(fs, argv.in);\n\t\t\tconst jsonIs500 = json.format === 500;\n\t\t\tif (versionIs500 && !jsonIs500) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`ERROR: Protocol version ${protocolVersion} looks like a 500-series version, but the JSON file does not belong to a 500-series NVM!\nConvert it first using the 700to500 command.`,\n\t\t\t\t);\n\t\t\t\tprocess.exit(1);\n\t\t\t} else if (jsonIs500 && !versionIs500) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`ERROR: Protocol version ${protocolVersion} looks like a 700-series version, but the JSON file belong to a 500-series NVM!\nConvert it first using the 500to700 command.`,\n\t\t\t\t);\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\tif (!isObject(json.meta)) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`ERROR: The JSON file does not contain the meta section, which is required for the conversion to a binary NVM!\nCreate a backup of the target stick, use the nvm2json command to convert it to JSON and copy the meta section from there.`,\n\t\t\t\t);\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\tconst nvm = versionIs500\n\t\t\t\t? await jsonToNVM500(json, protocolVersion)\n\t\t\t\t: await jsonToNVM(json, protocolVersion);\n\t\t\tawait fs.writeFile(argv.out, nvm);\n\t\t\tconsole.error(`NVM (binary) written to ${argv.out}`);\n\n\t\t\tprocess.exit(0);\n\t\t},\n\t)\n\t.command(\n\t\t\"500to700\",\n\t\t\"Convert a 500-series JSON file into a 700-series JSON file\",\n\t\t(yargs) =>\n\t\t\tyargs\n\t\t\t\t.usage(\"$0 500to700 --in <input> --out <output> [--truncate]\")\n\t\t\t\t.options({\n\t\t\t\t\tin: {\n\t\t\t\t\t\tdescribe: \"500 series JSON input filename\",\n\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t},\n\t\t\t\t\tout: {\n\t\t\t\t\t\tdescribe: \"700 series output filename\",\n\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t},\n\t\t\t\t\ttruncate: {\n\t\t\t\t\t\talias: \"t\",\n\t\t\t\t\t\tdescribe:\n\t\t\t\t\t\t\t\"Truncate application data if it is too large (> 512 bytes)\",\n\t\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\t\trequired: false,\n\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\tasync (argv) => {\n\t\t\tconst json500 = await readJSON(fs, argv.in);\n\t\t\tconst json700 = json500To700(json500, argv.truncate);\n\t\t\tawait writeTextFile(\n\t\t\t\tfs,\n\t\t\t\targv.out,\n\t\t\t\tJSON.stringify(json700, null, \"\\t\"),\n\t\t\t);\n\t\t\tconsole.error(`700-series NVM (JSON) written to ${argv.out}`);\n\n\t\t\tprocess.exit(0);\n\t\t},\n\t)\n\t.command(\n\t\t\"700to500\",\n\t\t\"Convert a 700-series JSON file into a 500-series JSON file\",\n\t\t(yargs) =>\n\t\t\tyargs.usage(\"$0 700to500 --in <input> --out <output>\").options({\n\t\t\t\tin: {\n\t\t\t\t\tdescribe: \"700 series JSON input filename\",\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t},\n\t\t\t\tout: {\n\t\t\t\t\tdescribe: \"500 series output filename\",\n\t\t\t\t\ttype: \"string\",\n\t\t\t\t\trequired: true,\n\t\t\t\t},\n\t\t\t}),\n\t\tasync (argv) => {\n\t\t\tconst json700 = await readJSON(fs, argv.in);\n\t\t\tconst json500 = json700To500(json700);\n\t\t\tawait writeTextFile(\n\t\t\t\tfs,\n\t\t\t\targv.out,\n\t\t\t\tJSON.stringify(json500, null, \"\\t\"),\n\t\t\t);\n\t\t\tconsole.error(`500-series NVM (JSON) written to ${argv.out}`);\n\n\t\t\tprocess.exit(0);\n\t\t},\n\t)\n\t.command(\n\t\t\"convert\",\n\t\t\"Convert the format of an NVM backup between different Z-Wave modules\",\n\t\t(yargs) =>\n\t\t\tyargs\n\t\t\t\t.usage(\n\t\t\t\t\t\"$0 convert --source <source> --target <target> --out <output>\",\n\t\t\t\t)\n\t\t\t\t.options({\n\t\t\t\t\tsource: {\n\t\t\t\t\t\tdescribe:\n\t\t\t\t\t\t\t\"The source NVM filename. This file will be converted to match the target NVM.\",\n\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t},\n\t\t\t\t\ttarget: {\n\t\t\t\t\t\tdescribe:\n\t\t\t\t\t\t\t\"The target NVM filename. This file will used to determine how to convert the source NVM.\",\n\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t},\n\t\t\t\t\tout: {\n\t\t\t\t\t\tdescribe:\n\t\t\t\t\t\t\t\"The output filename where the convert NVM will be written.\",\n\t\t\t\t\t\ttype: \"string\",\n\t\t\t\t\t\trequired: true,\n\t\t\t\t\t},\n\t\t\t\t\tnoAppData: {\n\t\t\t\t\t\tdescribe:\n\t\t\t\t\t\t\t\"Whether application data should be stripped during the migration\",\n\t\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t},\n\t\t\t\t\tnoRoutes: {\n\t\t\t\t\t\tdescribe:\n\t\t\t\t\t\t\t\"Whether known routes should be stripped during the migration\",\n\t\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t},\n\t\t\t\t\tnoNeighbors: {\n\t\t\t\t\t\tdescribe:\n\t\t\t\t\t\t\t\"Whether information about neighbors should be stripped during the migration\",\n\t\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t},\n\t\t\t\t\tnoSUCEntries: {\n\t\t\t\t\t\tdescribe:\n\t\t\t\t\t\t\t\"Whether SUC update entries should be stripped during the migration\",\n\t\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t},\n\t\t\t\t\tnoOptional: {\n\t\t\t\t\t\tdescribe:\n\t\t\t\t\t\t\t\"Strip all optional information from the NVM. Overrides all other noXYZ flags.\",\n\t\t\t\t\t\ttype: \"boolean\",\n\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\tasync (argv) => {\n\t\t\tconst {\n\t\t\t\tnoAppData,\n\t\t\t\tnoNeighbors,\n\t\t\t\tnoRoutes,\n\t\t\t\tnoSUCEntries,\n\t\t\t\tnoOptional,\n\t\t\t} = argv;\n\t\t\tconst options: MigrateNVMOptions = {\n\t\t\t\tpreserveApplicationData: !noOptional && !noAppData,\n\t\t\t\tpreserveRoutes: !noOptional && !noRoutes,\n\t\t\t\tpreserveNeighbors: !noOptional && !noNeighbors,\n\t\t\t\tpreserveSUCUpdateEntries: !noOptional && !noSUCEntries,\n\t\t\t};\n\n\t\t\tconst source = await fs.readFile(argv.source);\n\t\t\tconst target = await fs.readFile(argv.target);\n\n\t\t\tconst output = await migrateNVM(source, target, options);\n\n\t\t\tawait fs.writeFile(argv.out, output);\n\t\t\tconsole.error(`Converted NVM written to ${argv.out}`);\n\n\t\t\tprocess.exit(0);\n\t\t},\n\t)\n\t.demandCommand(1, \"Please specify a command\")\n\t.parseAsync();\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA,oBAAwC;AACxC,wBAAyB;AACzB,8BAAO;AACP,kBAAmB;AACnB,mBAAkB;AAClB,qBAAwB;AACxB,qBASO;AAEP,MAAM,oBAAgB,aAAAA,aAAM,wBAAQ,QAAQ,IAAI,CAAC;AAEjD,KAAK,cACH,IAAI,SAAS,EACb,OAAM,EACN,MAAM,wDAAwD,EAC9D,MAAM,KAAK,MAAM,EACjB,MAAM,KAAK,SAAS,EACpB,KAAK,KAAK,IAAI,KAAK,cAAc,cAAa,CAAE,CAAC,EACjD,QAAQ;EACR,SAAS;IACR,OAAO;IACP,UAAU;IACV,MAAM;;CAEP,EACA,QACA,YACA,iCACA,CAACA,WACAA,OAAM,MAAM,yCAAyC,EAAE,QAAQ;EAC9D,IAAI;IACH,UAAU;IACV,MAAM;IACN,UAAU;;EAEX,KAAK;IACJ,UAAU;IACV,MAAM;IACN,UAAU;;CAEX,GACF,OAAO,SAAQ;AACd,QAAM,SAAS,MAAM,eAAG,SAAS,KAAK,EAAE;AACxC,MAAI;AACJ,MAAI;AACH,WAAO,UAAM,0BAAU,QAAQ,KAAK,OAAO;EAC5C,SAAS,GAAG;AACX,QAAI;AACH,aAAO,UAAM,6BAAa,MAAM;IACjC,QAAQ;AACP,cAAQ,MAAM,CAAC;AACf,cAAQ,KAAK,CAAC;IACf;EACD;AACA,YAA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A6B;IAClC,yBAAyB,CAAC,cAAc,CAAC;IACzC,gBAAgB,CAAC,cAAc,CAAC;IAChC,mBAAmB,CAAC,cAAc,CAAC;IACnC,0BAA0B,CAAC,cAAc,CAAC;;AAG3C,QAAM,SAAS,MAAM,eAAG,SAAS,KAAK,MAAM;AAC5C,QAAM,SAAS,MAAM,eAAG,SAAS,KAAK,MAAM;AAE5C,QAAM,SAAS,UAAM,2BAAW,QAAQ,QAAQ,OAAO;AAEvD,QAAM,eAAG,UAAU,KAAK,KAAK,MAAM;AACnC,UAAQ,MAAM,4BAA4B,KAAK,GAAG,EAAE;AAEpD,UAAQ,KAAK,CAAC;AACf,CAAC,EAED,cAAc,GAAG,0BAA0B,EAC3C,WAAU;",
6
6
  "names": ["yargs"]
7
7
  }
@@ -77,6 +77,20 @@ export interface NVMJSONLRNode extends Omit<NodeProtocolInfo, "hasSpecificDevice
77
77
  specificDeviceClass?: number | null;
78
78
  }
79
79
  export type NVMJSONNode = NVMJSONNodeWithInfo | NVMJSONVirtualNode;
80
+ /**
81
+ * Options influencing how NVM contents should be migrated.
82
+ * By default, all data will be preserved.
83
+ */
84
+ export interface MigrateNVMOptions {
85
+ /** Whether application data will be preserved */
86
+ preserveApplicationData?: boolean;
87
+ /** Whether SUC update entries will be preserved */
88
+ preserveSUCUpdateEntries?: boolean;
89
+ /** Whether LWR, NLWR and the priority route flag will be preserved */
90
+ preserveRoutes?: boolean;
91
+ /** Whether the neighbor table will be preserved */
92
+ preserveNeighbors?: boolean;
93
+ }
80
94
  export declare function nodeHasInfo(node: NVMJSONNode): node is NVMJSONNodeWithInfo;
81
95
  /** Converts a compressed set of NVM objects to a JSON representation */
82
96
  export declare function nvmObjectsToJSON(objects: ReadonlyMap<number, NVM3Object>): NVMJSON;
@@ -90,5 +104,5 @@ export declare function jsonToNVM500(json: Required<NVM500JSON>, protocolVersion
90
104
  export declare function json500To700(json: NVM500JSON, truncateApplicationData?: boolean): NVMJSON;
91
105
  export declare function json700To500(json: NVMJSON): NVM500JSON;
92
106
  /** Converts the given source NVM into a format that is compatible with the given target NVM */
93
- export declare function migrateNVM(sourceNVM: Uint8Array, targetNVM: Uint8Array): Promise<Uint8Array>;
107
+ export declare function migrateNVM(sourceNVM: Uint8Array, targetNVM: Uint8Array, options?: MigrateNVMOptions): Promise<Uint8Array>;
94
108
  //# sourceMappingURL=convert.d.ts.map
@@ -1209,7 +1209,7 @@ function json700To500(json) {
1209
1209
  return ret;
1210
1210
  }
1211
1211
  __name(json700To500, "json700To500");
1212
- async function migrateNVM(sourceNVM, targetNVM) {
1212
+ async function migrateNVM(sourceNVM, targetNVM, options = {}) {
1213
1213
  let source;
1214
1214
  let target;
1215
1215
  let sourceProtocolFileFormat;
@@ -1252,9 +1252,11 @@ async function migrateNVM(sourceNVM, targetNVM) {
1252
1252
  target = { type: "unknown" };
1253
1253
  }
1254
1254
  }
1255
- if (target.type === "unknown" && targetProtocolFileFormat && targetProtocolFileFormat > import_consts.MAX_PROTOCOL_FILE_FORMAT && sourceProtocolFileFormat && sourceProtocolFileFormat <= targetProtocolFileFormat && sourceNVM.length === targetNVM.length) {
1255
+ const { preserveApplicationData = true, preserveNeighbors = true, preserveRoutes = true, preserveSUCUpdateEntries = true } = options;
1256
+ const preserveAll = preserveApplicationData && preserveNeighbors && preserveRoutes && preserveSUCUpdateEntries;
1257
+ if (target.type === "unknown" && targetProtocolFileFormat && targetProtocolFileFormat > import_consts.MAX_PROTOCOL_FILE_FORMAT && sourceProtocolFileFormat && sourceProtocolFileFormat <= targetProtocolFileFormat && sourceNVM.length === targetNVM.length && preserveAll) {
1256
1258
  return sourceNVM;
1257
- } else if (source.type === 700 && target.type === 700 && sourceNVM.length === targetNVM.length && source.json.meta.sharedFileSystem === target.json.meta.sharedFileSystem) {
1259
+ } else if (source.type === 700 && target.type === 700 && sourceNVM.length === targetNVM.length && source.json.meta.sharedFileSystem === target.json.meta.sharedFileSystem && preserveAll) {
1258
1260
  const sourceProtocolVersion = source.json.controller.protocolVersion;
1259
1261
  const targetProtocolVersion = target.json.controller.protocolVersion;
1260
1262
  const sourceApplicationVersion = source.json.controller.applicationVersion;
@@ -1275,6 +1277,35 @@ async function migrateNVM(sourceNVM, targetNVM) {
1275
1277
  target.json.controller.applicationVersion = target.json.controller.protocolVersion;
1276
1278
  }
1277
1279
  source.json.controller.applicationVersion = target.json.controller.applicationVersion;
1280
+ if (!preserveApplicationData) {
1281
+ source.json.controller.applicationData = void 0;
1282
+ }
1283
+ if (!preserveNeighbors) {
1284
+ for (const node of Object.values(source.json.nodes)) {
1285
+ if (!node.isVirtual) {
1286
+ node.neighbors = [];
1287
+ }
1288
+ }
1289
+ }
1290
+ if (!preserveRoutes) {
1291
+ for (const node of Object.values(source.json.nodes)) {
1292
+ if (!node.isVirtual) {
1293
+ node.appRouteLock = false;
1294
+ node.lwr = void 0;
1295
+ node.nlwr = void 0;
1296
+ }
1297
+ }
1298
+ }
1299
+ if (!preserveSUCUpdateEntries) {
1300
+ source.json.controller.sucUpdateEntries = [];
1301
+ source.json.controller.sucLastIndex = 255;
1302
+ for (const node of Object.values(source.json.nodes)) {
1303
+ if (!node.isVirtual) {
1304
+ node.sucUpdateIndex = 254;
1305
+ node.sucPendingUpdate = false;
1306
+ }
1307
+ }
1308
+ }
1278
1309
  if (source.type === 500 && target.type === 500) {
1279
1310
  const json = {
1280
1311
  ...source.json,