@iobroker/js-controller-cli 7.2.3-alpha.9-20260711-3ea5f3c89 → 7.2.4
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/index.js +3 -3
- package/build/cjs/lib/_Types.d.ts +1 -8
- package/build/cjs/lib/cli/cliCert.d.ts +4 -7
- package/build/cjs/lib/cli/cliCert.js +6 -10
- package/build/cjs/lib/cli/cliCert.js.map +2 -2
- package/build/cjs/lib/cli/cliCommand.d.ts +14 -45
- package/build/cjs/lib/cli/cliCommand.js +1 -8
- package/build/cjs/lib/cli/cliCommand.js.map +2 -2
- package/build/cjs/lib/cli/cliCompact.d.ts +2 -5
- package/build/cjs/lib/cli/cliCompact.js +2 -9
- package/build/cjs/lib/cli/cliCompact.js.map +2 -2
- package/build/cjs/lib/cli/cliDebug.d.ts +2 -5
- package/build/cjs/lib/cli/cliDebug.js +1 -8
- package/build/cjs/lib/cli/cliDebug.js.map +2 -2
- package/build/cjs/lib/cli/cliHost.d.ts +10 -13
- package/build/cjs/lib/cli/cliHost.js +5 -13
- package/build/cjs/lib/cli/cliHost.js.map +2 -2
- package/build/cjs/lib/cli/cliLogs.d.ts +3 -9
- package/build/cjs/lib/cli/cliLogs.js +1 -12
- package/build/cjs/lib/cli/cliLogs.js.map +2 -2
- package/build/cjs/lib/cli/cliMessage.d.ts +1 -2
- package/build/cjs/lib/cli/cliMessage.js +0 -5
- package/build/cjs/lib/cli/cliMessage.js.map +2 -2
- package/build/cjs/lib/cli/cliObjects.d.ts +18 -21
- package/build/cjs/lib/cli/cliObjects.js +33 -51
- package/build/cjs/lib/cli/cliObjects.js.map +2 -2
- package/build/cjs/lib/cli/cliPlugin.d.ts +3 -3
- package/build/cjs/lib/cli/cliPlugin.js +0 -6
- package/build/cjs/lib/cli/cliPlugin.js.map +2 -2
- package/build/cjs/lib/cli/cliProcess.d.ts +4 -8
- package/build/cjs/lib/cli/cliProcess.js +16 -27
- package/build/cjs/lib/cli/cliProcess.js.map +3 -3
- package/build/cjs/lib/cli/cliStates.d.ts +4 -7
- package/build/cjs/lib/cli/cliStates.js +6 -14
- package/build/cjs/lib/cli/cliStates.js.map +2 -2
- package/build/cjs/lib/cli/cliTools.js +0 -11
- package/build/cjs/lib/cli/cliTools.js.map +1 -1
- package/build/cjs/lib/cli/messages.js +46 -47
- package/build/cjs/lib/cli/messages.js.map +1 -1
- package/build/cjs/lib/setup/customError.d.ts +0 -4
- package/build/cjs/lib/setup/customError.js +0 -7
- package/build/cjs/lib/setup/customError.js.map +2 -2
- package/build/cjs/lib/setup/dbConnection.js +64 -69
- package/build/cjs/lib/setup/dbConnection.js.map +3 -3
- package/build/cjs/lib/setup/formatters.d.ts +4 -4
- package/build/cjs/lib/setup/formatters.js +0 -5
- package/build/cjs/lib/setup/formatters.js.map +2 -2
- package/build/cjs/lib/setup/multihostClient.js +2 -6
- package/build/cjs/lib/setup/multihostClient.js.map +1 -1
- package/build/cjs/lib/setup/pluginInfos.d.ts +0 -5
- package/build/cjs/lib/setup/pluginInfos.js +0 -2
- package/build/cjs/lib/setup/pluginInfos.js.map +2 -2
- package/build/cjs/lib/setup/setupBackup.d.ts +0 -34
- package/build/cjs/lib/setup/setupBackup.js +12 -46
- package/build/cjs/lib/setup/setupBackup.js.map +3 -3
- package/build/cjs/lib/setup/setupInstall.d.ts +15 -38
- package/build/cjs/lib/setup/setupInstall.js +26 -44
- package/build/cjs/lib/setup/setupInstall.js.map +2 -2
- package/build/cjs/lib/setup/setupLicense.d.ts +0 -8
- package/build/cjs/lib/setup/setupLicense.js +0 -7
- package/build/cjs/lib/setup/setupLicense.js.map +2 -2
- package/build/cjs/lib/setup/setupList.d.ts +1 -55
- package/build/cjs/lib/setup/setupList.js +24 -78
- package/build/cjs/lib/setup/setupList.js.map +3 -3
- package/build/cjs/lib/setup/setupMultihost.js +9 -12
- package/build/cjs/lib/setup/setupMultihost.js.map +3 -3
- package/build/cjs/lib/setup/setupPacketManager.d.ts +0 -10
- package/build/cjs/lib/setup/setupPacketManager.js +6 -16
- package/build/cjs/lib/setup/setupPacketManager.js.map +2 -2
- package/build/cjs/lib/setup/setupRepo.d.ts +0 -6
- package/build/cjs/lib/setup/setupRepo.js +11 -28
- package/build/cjs/lib/setup/setupRepo.js.map +2 -2
- package/build/cjs/lib/setup/setupSetup.d.ts +0 -27
- package/build/cjs/lib/setup/setupSetup.js +33 -52
- package/build/cjs/lib/setup/setupSetup.js.map +3 -3
- package/build/cjs/lib/setup/setupUpgrade.d.ts +2 -8
- package/build/cjs/lib/setup/setupUpgrade.js +10 -19
- package/build/cjs/lib/setup/setupUpgrade.js.map +2 -2
- package/build/cjs/lib/setup/setupUpload.d.ts +1 -72
- package/build/cjs/lib/setup/setupUpload.js +6 -74
- package/build/cjs/lib/setup/setupUpload.js.map +2 -2
- package/build/cjs/lib/setup/setupUsers.d.ts +14 -23
- package/build/cjs/lib/setup/setupUsers.js +15 -58
- package/build/cjs/lib/setup/setupUsers.js.map +2 -2
- package/build/cjs/lib/setup/setupVendor.d.ts +1 -9
- package/build/cjs/lib/setup/setupVendor.js +6 -13
- package/build/cjs/lib/setup/setupVendor.js.map +2 -2
- package/build/cjs/lib/setup/setupVisDebug.d.ts +2 -11
- package/build/cjs/lib/setup/setupVisDebug.js +15 -21
- package/build/cjs/lib/setup/setupVisDebug.js.map +3 -3
- package/build/cjs/lib/setup/utils.d.ts +1 -1
- package/build/cjs/lib/setup/utils.js +9 -13
- package/build/cjs/lib/setup/utils.js.map +3 -3
- package/build/cjs/lib/setup.js +330 -269
- package/build/cjs/lib/setup.js.map +3 -3
- package/build/esm/lib/_Types.d.ts +1 -8
- package/build/esm/lib/_Types.d.ts.map +1 -1
- package/build/esm/lib/cli/cliCert.d.ts +4 -7
- package/build/esm/lib/cli/cliCert.d.ts.map +1 -1
- package/build/esm/lib/cli/cliCert.js +6 -6
- package/build/esm/lib/cli/cliCert.js.map +1 -1
- package/build/esm/lib/cli/cliCommand.d.ts +14 -45
- package/build/esm/lib/cli/cliCommand.d.ts.map +1 -1
- package/build/esm/lib/cli/cliCommand.js +1 -4
- package/build/esm/lib/cli/cliCommand.js.map +1 -1
- package/build/esm/lib/cli/cliCompact.d.ts +2 -5
- package/build/esm/lib/cli/cliCompact.d.ts.map +1 -1
- package/build/esm/lib/cli/cliCompact.js +2 -5
- package/build/esm/lib/cli/cliCompact.js.map +1 -1
- package/build/esm/lib/cli/cliDebug.d.ts +2 -5
- package/build/esm/lib/cli/cliDebug.d.ts.map +1 -1
- package/build/esm/lib/cli/cliDebug.js +1 -4
- package/build/esm/lib/cli/cliDebug.js.map +1 -1
- package/build/esm/lib/cli/cliHost.d.ts +10 -13
- package/build/esm/lib/cli/cliHost.d.ts.map +1 -1
- package/build/esm/lib/cli/cliHost.js +5 -8
- package/build/esm/lib/cli/cliHost.js.map +1 -1
- package/build/esm/lib/cli/cliLogs.d.ts +3 -9
- package/build/esm/lib/cli/cliLogs.d.ts.map +1 -1
- package/build/esm/lib/cli/cliLogs.js +1 -8
- package/build/esm/lib/cli/cliLogs.js.map +1 -1
- package/build/esm/lib/cli/cliMessage.d.ts +1 -2
- package/build/esm/lib/cli/cliMessage.d.ts.map +1 -1
- package/build/esm/lib/cli/cliMessage.js +0 -1
- package/build/esm/lib/cli/cliMessage.js.map +1 -1
- package/build/esm/lib/cli/cliObjects.d.ts +18 -21
- package/build/esm/lib/cli/cliObjects.d.ts.map +1 -1
- package/build/esm/lib/cli/cliObjects.js +38 -44
- package/build/esm/lib/cli/cliObjects.js.map +1 -1
- package/build/esm/lib/cli/cliPlugin.d.ts +3 -3
- package/build/esm/lib/cli/cliPlugin.d.ts.map +1 -1
- package/build/esm/lib/cli/cliPlugin.js +1 -1
- package/build/esm/lib/cli/cliPlugin.js.map +1 -1
- package/build/esm/lib/cli/cliProcess.d.ts +4 -8
- package/build/esm/lib/cli/cliProcess.d.ts.map +1 -1
- package/build/esm/lib/cli/cliProcess.js +4 -7
- package/build/esm/lib/cli/cliProcess.js.map +1 -1
- package/build/esm/lib/cli/cliStates.d.ts +4 -7
- package/build/esm/lib/cli/cliStates.d.ts.map +1 -1
- package/build/esm/lib/cli/cliStates.js +2 -6
- package/build/esm/lib/cli/cliStates.js.map +1 -1
- package/build/esm/lib/setup/customError.d.ts +0 -4
- package/build/esm/lib/setup/customError.d.ts.map +1 -1
- package/build/esm/lib/setup/customError.js +0 -3
- package/build/esm/lib/setup/customError.js.map +1 -1
- package/build/esm/lib/setup/dbConnection.d.ts.map +1 -1
- package/build/esm/lib/setup/dbConnection.js +13 -10
- package/build/esm/lib/setup/dbConnection.js.map +1 -1
- package/build/esm/lib/setup/formatters.d.ts +4 -4
- package/build/esm/lib/setup/formatters.js +4 -4
- package/build/esm/lib/setup/pluginInfos.d.ts +0 -5
- package/build/esm/lib/setup/pluginInfos.d.ts.map +1 -1
- package/build/esm/lib/setup/pluginInfos.js +0 -5
- package/build/esm/lib/setup/pluginInfos.js.map +1 -1
- package/build/esm/lib/setup/setupBackup.d.ts +0 -34
- package/build/esm/lib/setup/setupBackup.d.ts.map +1 -1
- package/build/esm/lib/setup/setupBackup.js +12 -46
- package/build/esm/lib/setup/setupBackup.js.map +1 -1
- package/build/esm/lib/setup/setupInstall.d.ts +15 -38
- package/build/esm/lib/setup/setupInstall.d.ts.map +1 -1
- package/build/esm/lib/setup/setupInstall.js +24 -40
- package/build/esm/lib/setup/setupInstall.js.map +1 -1
- package/build/esm/lib/setup/setupLicense.d.ts +0 -8
- package/build/esm/lib/setup/setupLicense.d.ts.map +1 -1
- package/build/esm/lib/setup/setupLicense.js +0 -6
- package/build/esm/lib/setup/setupLicense.js.map +1 -1
- package/build/esm/lib/setup/setupList.d.ts +1 -55
- package/build/esm/lib/setup/setupList.d.ts.map +1 -1
- package/build/esm/lib/setup/setupList.js +8 -61
- package/build/esm/lib/setup/setupList.js.map +1 -1
- package/build/esm/lib/setup/setupMultihost.d.ts.map +1 -1
- package/build/esm/lib/setup/setupMultihost.js +6 -5
- package/build/esm/lib/setup/setupMultihost.js.map +1 -1
- package/build/esm/lib/setup/setupPacketManager.d.ts +0 -10
- package/build/esm/lib/setup/setupPacketManager.d.ts.map +1 -1
- package/build/esm/lib/setup/setupPacketManager.js +0 -9
- package/build/esm/lib/setup/setupPacketManager.js.map +1 -1
- package/build/esm/lib/setup/setupRepo.d.ts +0 -6
- package/build/esm/lib/setup/setupRepo.d.ts.map +1 -1
- package/build/esm/lib/setup/setupRepo.js +14 -30
- package/build/esm/lib/setup/setupRepo.js.map +1 -1
- package/build/esm/lib/setup/setupSetup.d.ts +0 -27
- package/build/esm/lib/setup/setupSetup.d.ts.map +1 -1
- package/build/esm/lib/setup/setupSetup.js +21 -36
- package/build/esm/lib/setup/setupSetup.js.map +1 -1
- package/build/esm/lib/setup/setupUpgrade.d.ts +2 -8
- package/build/esm/lib/setup/setupUpgrade.d.ts.map +1 -1
- package/build/esm/lib/setup/setupUpgrade.js +6 -14
- package/build/esm/lib/setup/setupUpgrade.js.map +1 -1
- package/build/esm/lib/setup/setupUpload.d.ts +1 -72
- package/build/esm/lib/setup/setupUpload.d.ts.map +1 -1
- package/build/esm/lib/setup/setupUpload.js +5 -72
- package/build/esm/lib/setup/setupUpload.js.map +1 -1
- package/build/esm/lib/setup/setupUsers.d.ts +14 -23
- package/build/esm/lib/setup/setupUsers.d.ts.map +1 -1
- package/build/esm/lib/setup/setupUsers.js +14 -56
- package/build/esm/lib/setup/setupUsers.js.map +1 -1
- package/build/esm/lib/setup/setupVendor.d.ts +1 -9
- package/build/esm/lib/setup/setupVendor.d.ts.map +1 -1
- package/build/esm/lib/setup/setupVendor.js +1 -7
- package/build/esm/lib/setup/setupVendor.js.map +1 -1
- package/build/esm/lib/setup/setupVisDebug.d.ts +2 -11
- package/build/esm/lib/setup/setupVisDebug.d.ts.map +1 -1
- package/build/esm/lib/setup/setupVisDebug.js +14 -21
- package/build/esm/lib/setup/setupVisDebug.js.map +1 -1
- package/build/esm/lib/setup/utils.d.ts +1 -1
- package/build/esm/lib/setup/utils.d.ts.map +1 -1
- package/build/esm/lib/setup/utils.js +4 -2
- package/build/esm/lib/setup/utils.js.map +1 -1
- package/build/esm/lib/setup.d.ts.map +1 -1
- package/build/esm/lib/setup.js +211 -162
- package/build/esm/lib/setup.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +14 -14
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/cli/cliHost.ts"],
|
|
4
|
-
"sourcesContent": ["import * as CLI from './messages.js';\nimport { CLICommand, type CLICommandOptions } from './cliCommand.js';\nimport { enumHosts, enumObjects, getObjectFrom, enumInstances } from './cliTools.js';\nimport { tools, EXIT_CODES } from '@iobroker/js-controller-common';\nimport type { Client as ObjectsClient } from '@iobroker/db-objects-redis';\nimport os from 'node:os';\nimport fs from 'fs-extra';\n\n/** Command iobroker host ... */\nexport class CLIHost extends CLICommand {\n /**\n * @param options The command options including context and parameters\n */\n constructor(options: CLICommandOptions) {\n super(options);\n }\n\n /**\n * Executes a command\n *\n * @param args The command arguments (the first is the sub-command)\n */\n execute(args: string[]): void {\n const command = args[0];\n\n switch (command) {\n case 'this':\n case 'self':\n return this.self(args);\n case 'set':\n return this.set(args);\n case 'remove':\n return this.remove(args);\n default:\n return this.rename(args);\n }\n }\n\n /**\n * When in single-host mode, changes the hostname of the host and all instances to the current one\n *\n * @param _args The command arguments (unused)\n */\n self(_args: string[]): void {\n this.renameHost(undefined, os.hostname());\n }\n\n /**\n * Changes the current host's hostname to the given one\n *\n * @param args The command arguments (the second is the new hostname)\n */\n set(args: string[]): void {\n const { callback } = this.options;\n\n const newHostname: string = args[1];\n if (!newHostname) {\n CLI.error.requiredArgumentMissing('newHostname', 'host set newHostname');\n return void callback(34);\n }\n\n this.renameHost(tools.getHostName(), newHostname);\n }\n\n /**\n * Removes the host with the given name\n *\n * @param args The command arguments (the second is the hostname to remove)\n */\n remove(args: string[]): void {\n const { callback, dbConnect } = this.options;\n\n const hostname: string = args[1];\n if (!hostname) {\n CLI.error.requiredArgumentMissing('hostname', 'host remove hostname');\n return void callback(34);\n }\n\n const newHostname = tools.getHostName();\n\n if (hostname === newHostname) {\n // avoid object deletion when target host is same host\n CLI.error.dontRemoveCurrentHost(hostname);\n return void callback(35);\n }\n\n dbConnect(async params => {\n const { objects, isOffline } = params;\n\n try {\n if (!isOffline) {\n CLI.error.cannotChangeRunningSystem();\n return void callback(EXIT_CODES.CONTROLLER_RUNNING);\n }\n\n // Find the requested host object\n const hosts = await enumHosts(objects);\n const hostToDelete = hosts.find(host => host?.common.hostname === hostname);\n if (!hostToDelete) {\n CLI.error.hostDoesNotExist(hostname);\n return void callback(30);\n }\n\n // Delete it\n try {\n await objects.delObjectAsync(hostToDelete._id);\n } catch (err) {\n CLI.error.cannotDeleteObject(hostToDelete._id, err.message);\n return void callback(30);\n }\n\n // Also delete its states\n const hostStates = await enumObjects(objects, 'state', `system.host.${hostname}.`);\n for (const state of hostStates) {\n // Therefore delete the old one because we will recreate it under a new name\n try {\n await objects.delObjectAsync(state._id);\n CLI.success.stateDeleted(state._id);\n } catch (err) {\n CLI.error.cannotDeleteObject(state._id, err.message);\n }\n }\n\n // Move all instances from the deleted host to the current one\n const instances = await enumInstances(objects);\n const instancesToRename = instances.filter(i => i?.common.host === hostname);\n for (const instance of instancesToRename) {\n await changeInstanceHost(objects, instance, newHostname);\n }\n\n // Notify the user that we are done\n CLI.success.hostDeleted(hostname);\n return void callback(EXIT_CODES.NO_ERROR);\n } catch (err) {\n CLI.error.unknown(err.message);\n return void callback(1);\n }\n });\n }\n\n /**\n * Renames the host with the given name to the current one (opposite of `set()`)\n *\n * @param args The command arguments (the second is the old hostname)\n */\n rename(args: string[]): void {\n const { callback } = this.options;\n\n const oldHostname: string = args[0];\n\n if (!oldHostname) {\n CLI.error.requiredArgumentMissing('oldHostname', 'host oldHostname');\n return void callback(34);\n }\n\n this.renameHost(oldHostname, os.hostname());\n }\n\n /**\n * Renames the host with the hostname `oldHostname` to the hostname `newHostname`\n *\n * @param oldHostname The hostname to rename from or `undefined` to rename all hosts (single-host mode only!)\n * @param newHostname The hostname to rename to\n */\n renameHost(oldHostname: string | undefined, newHostname: string): void {\n const { callback, dbConnect, showHelp } = this.options;\n dbConnect(async params => {\n const { isOffline, objects } = params;\n\n try {\n if (!isOffline) {\n CLI.error.cannotChangeRunningSystem();\n return void callback(EXIT_CODES.CONTROLLER_RUNNING);\n }\n\n const hosts = await enumHosts(objects);\n if (hosts.length > 1 && oldHostname === undefined) {\n // iobroker host this/self in multihost is not allowed\n CLI.error.noHostThisInMultihost();\n showHelp();\n return void callback(30);\n }\n\n // Does another host with the target name exist?\n const hostExists = !!hosts.find(obj => obj?.common.hostname === newHostname);\n if (hostExists) {\n // This prevents migration of instances if host already exists, but we need it to prevent\n // multiple hosts with same name. Thus we only allow if no instances are on the host\n // Note: this is only a heuristic, if problems occur we need a `force` flag\n const instances = await enumInstances(objects);\n const hasExistingInstances = !!instances.find(instance => instance?.common.host === newHostname);\n\n if (hasExistingInstances) {\n CLI.error.hostAlreadyExists(newHostname);\n return void callback(EXIT_CODES.INSTANCE_ALREADY_EXISTS);\n }\n }\n\n // Remember the new hostname in the system settings\n const configFileName = tools.getConfigFileName();\n const configData = fs.readJSONSync(configFileName);\n if (configData.system && configData.system.hostname !== newHostname) {\n configData.system.hostname = newHostname;\n fs.writeFileSync(configFileName, JSON.stringify(configData, null, 2), 'utf8');\n }\n\n // Rename the host(s)\n for (const host of hosts) {\n // Remember the current hostname of this object because we need it later\n const prevHostname = host.common.hostname;\n\n // Rename only the hostname we're supposed to rename!\n if (oldHostname && prevHostname !== oldHostname) {\n continue;\n }\n\n // Rename the host object\n // Therefore delete the old one because we will recreate it under a new name\n try {\n await objects.delObjectAsync(host._id);\n } catch (err) {\n CLI.error.cannotDeleteObject(host._id, err.message);\n continue;\n }\n\n // Now update the object\n Object.assign(host, {\n _id: `system.host.${newHostname}`,\n from: getObjectFrom(),\n ts: Date.now(),\n });\n Object.assign(host.common, {\n name: host._id,\n hostname: newHostname,\n address: [],\n cmd: '',\n native: { process: {}, os: {}, hardware: {} },\n });\n // And save it\n try {\n await objects.setObjectAsync(host._id, host);\n } catch (err) {\n CLI.error.cannotChangeObject(host._id, err.message);\n continue;\n }\n\n // Rename its states\n const hostStateObjects = await enumObjects(objects, 'state', `system.host.${prevHostname}.`);\n const hostFolders = await enumObjects(objects, 'folder', `system.host.${prevHostname}.`);\n for (const object of [...hostStateObjects, ...hostFolders]) {\n // Therefore delete the old one because we will recreate it under a new name\n try {\n await objects.delObjectAsync(object._id);\n } catch (err) {\n CLI.error.cannotDeleteObject(object._id, err.message);\n continue;\n }\n\n // Now update the object\n Object.assign(object, {\n _id: object._id.replace(`system.host.${prevHostname}`, `system.host.${newHostname}`),\n from: getObjectFrom(),\n ts: Date.now(),\n });\n\n // And save it\n try {\n await objects.setObjectAsync(object._id, object);\n } catch (err) {\n CLI.error.cannotChangeObject(object._id, err.message);\n }\n }\n\n CLI.success.hostRenamed(prevHostname, newHostname);\n }\n\n // Also rename all instances\n const instances = await enumInstances(objects);\n const instancesToRename =\n oldHostname === undefined ? instances : instances.filter(i => i.common.host === oldHostname);\n if (instancesToRename.length > 0) {\n for (const instance of instancesToRename) {\n // Update each instance object\n await changeInstanceHost(objects, instance, newHostname);\n }\n } else {\n CLI.warn.noInstancesFoundOnHost(oldHostname);\n }\n return void callback(EXIT_CODES.NO_ERROR);\n } catch (err) {\n CLI.error.unknown(err.message);\n return void callback(1);\n }\n });\n }\n}\n\n/**\n * Changes the host an instance is running on\n *\n * @param objects The objects DB to use\n * @param instance The instance object\n * @param newHostname The new hostname the instance should be running on\n */\nasync function changeInstanceHost(\n objects: ObjectsClient,\n instance: ioBroker.InstanceObject,\n newHostname: string,\n): Promise<void> {\n const oldInstanceHost = instance.common.host;\n instance.from = getObjectFrom();\n instance.ts = Date.now();\n instance.common.host = newHostname;\n // and save it\n try {\n await objects.setObjectAsync(instance._id, instance);\n CLI.success.instanceHostChanged(instance._id, oldInstanceHost, newHostname);\n } catch (e) {\n CLI.error.cannotChangeObject(instance._id, e.message);\n // resolve anyways, we don't want to cause errors\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import * as CLI from './messages.js';\nimport { CLICommand, type CLICommandOptions } from './cliCommand.js';\nimport { enumHosts, enumObjects, getObjectFrom, enumInstances } from './cliTools.js';\nimport { tools, EXIT_CODES } from '@iobroker/js-controller-common';\nimport type { Client as ObjectsClient } from '@iobroker/db-objects-redis';\nimport os from 'node:os';\nimport fs from 'fs-extra';\n\n/** Command iobroker host ... */\nexport class CLIHost extends CLICommand {\n constructor(options: CLICommandOptions) {\n super(options);\n }\n\n /**\n * Executes a command\n *\n * @param args\n */\n execute(args: any[]): void {\n const command = args[0];\n\n switch (command) {\n case 'this':\n case 'self':\n return this.self(args);\n case 'set':\n return this.set(args);\n case 'remove':\n return this.remove(args);\n default:\n return this.rename(args);\n }\n }\n\n /**\n * When in single-host mode, changes the hostname of the host and all instances to the current one\n *\n * @param _args\n */\n self(_args: any[]): void {\n this.renameHost(undefined, os.hostname());\n }\n\n /**\n * Changes the current host's hostname to the given one\n *\n * @param args\n */\n set(args: any[]): void {\n const { callback } = this.options;\n\n const newHostname: string = args[1];\n if (!newHostname) {\n CLI.error.requiredArgumentMissing('newHostname', 'host set newHostname');\n return void callback(34);\n }\n\n this.renameHost(tools.getHostName(), newHostname);\n }\n\n /**\n * Removes the host with the given name\n *\n * @param args\n */\n remove(args: any[]): void {\n const { callback, dbConnect } = this.options;\n\n const hostname: string = args[1];\n if (!hostname) {\n CLI.error.requiredArgumentMissing('hostname', 'host remove hostname');\n return void callback(34);\n }\n\n const newHostname = tools.getHostName();\n\n if (hostname === newHostname) {\n // avoid object deletion when target host is same host\n CLI.error.dontRemoveCurrentHost(hostname);\n return void callback(35);\n }\n\n dbConnect(async params => {\n const { objects, isOffline } = params;\n\n try {\n if (!isOffline) {\n CLI.error.cannotChangeRunningSystem();\n return void callback(EXIT_CODES.CONTROLLER_RUNNING);\n }\n\n // Find the requested host object\n const hosts = await enumHosts(objects);\n const hostToDelete = hosts.find(host => host?.common.hostname === hostname);\n if (!hostToDelete) {\n CLI.error.hostDoesNotExist(hostname);\n return void callback(30);\n }\n\n // Delete it\n try {\n await objects.delObjectAsync(hostToDelete._id);\n } catch (err) {\n CLI.error.cannotDeleteObject(hostToDelete._id, err.message);\n return void callback(30);\n }\n\n // Also delete its states\n const hostStates = await enumObjects(objects, 'state', `system.host.${hostname}.`);\n for (const state of hostStates) {\n // Therefore delete the old one because we will recreate it under a new name\n try {\n await objects.delObjectAsync(state._id);\n CLI.success.stateDeleted(state._id);\n } catch (err) {\n CLI.error.cannotDeleteObject(state._id, err.message);\n }\n }\n\n // Move all instances from the deleted host to the current one\n const instances = await enumInstances(objects);\n const instancesToRename = instances.filter(i => i?.common.host === hostname);\n for (const instance of instancesToRename) {\n await changeInstanceHost(objects, instance, newHostname);\n }\n\n // Notify the user that we are done\n CLI.success.hostDeleted(hostname);\n return void callback(EXIT_CODES.NO_ERROR);\n } catch (err) {\n CLI.error.unknown(err.message);\n return void callback(1);\n }\n });\n }\n\n /**\n * Renames the host with the given name to the current one (opposite of `set()`)\n *\n * @param args\n */\n rename(args: any[]): void {\n const { callback } = this.options;\n\n const oldHostname: string = args[0];\n\n if (!oldHostname) {\n CLI.error.requiredArgumentMissing('oldHostname', 'host oldHostname');\n return void callback(34);\n }\n\n this.renameHost(oldHostname, os.hostname());\n }\n\n /**\n * Renames the host with the hostname `oldHostname` to the hostname `newHostname`\n *\n * @param oldHostname The hostname to rename from or `undefined` to rename all hosts (single-host mode only!)\n * @param newHostname The hostname to rename to\n */\n renameHost(oldHostname: string | undefined, newHostname: string): void {\n const { callback, dbConnect, showHelp } = this.options;\n dbConnect(async params => {\n const { isOffline, objects } = params;\n\n try {\n if (!isOffline) {\n CLI.error.cannotChangeRunningSystem();\n return void callback(EXIT_CODES.CONTROLLER_RUNNING);\n }\n\n const hosts = await enumHosts(objects);\n if (hosts.length > 1 && oldHostname === undefined) {\n // iobroker host this/self in multihost is not allowed\n CLI.error.noHostThisInMultihost();\n showHelp();\n return void callback(30);\n }\n\n // Does another host with the target name exist?\n const hostExists = !!hosts.find(obj => obj?.common.hostname === newHostname);\n if (hostExists) {\n // This prevents migration of instances if host already exists, but we need it to prevent\n // multiple hosts with same name. Thus we only allow if no instances are on the host\n // Note: this is only a heuristic, if problems occur we need a `force` flag\n const instances = await enumInstances(objects);\n const hasExistingInstances = !!instances.find(instance => instance?.common.host === newHostname);\n\n if (hasExistingInstances) {\n CLI.error.hostAlreadyExists(newHostname);\n return void callback(EXIT_CODES.INSTANCE_ALREADY_EXISTS);\n }\n }\n\n // Remember the new hostname in the system settings\n const configFileName = tools.getConfigFileName();\n const configData = fs.readJSONSync(configFileName);\n if (configData.system && configData.system.hostname !== newHostname) {\n configData.system.hostname = newHostname;\n fs.writeFileSync(configFileName, JSON.stringify(configData, null, 2), 'utf8');\n }\n\n // Rename the host(s)\n for (const host of hosts) {\n // Remember the current hostname of this object because we need it later\n const prevHostname = host.common.hostname;\n\n // Rename only the hostname we're supposed to rename!\n if (oldHostname && prevHostname !== oldHostname) {\n continue;\n }\n\n // Rename the host object\n // Therefore delete the old one because we will recreate it under a new name\n try {\n await objects.delObjectAsync(host._id);\n } catch (err) {\n CLI.error.cannotDeleteObject(host._id, err.message);\n continue;\n }\n\n // Now update the object\n Object.assign(host, {\n _id: `system.host.${newHostname}`,\n from: getObjectFrom(),\n ts: Date.now(),\n });\n Object.assign(host.common, {\n name: host._id,\n hostname: newHostname,\n address: [],\n cmd: '',\n native: { process: {}, os: {}, hardware: {} },\n });\n // And save it\n try {\n await objects.setObjectAsync(host._id, host);\n } catch (err) {\n CLI.error.cannotChangeObject(host._id, err.message);\n continue;\n }\n\n // Rename its states\n const hostStateObjects = await enumObjects(objects, 'state', `system.host.${prevHostname}.`);\n const hostFolders = await enumObjects(objects, 'folder', `system.host.${prevHostname}.`);\n for (const object of [...hostStateObjects, ...hostFolders]) {\n // Therefore delete the old one because we will recreate it under a new name\n try {\n await objects.delObjectAsync(object._id);\n } catch (err) {\n CLI.error.cannotDeleteObject(object._id, err.message);\n continue;\n }\n\n // Now update the object\n Object.assign(object, {\n _id: object._id.replace(`system.host.${prevHostname}`, `system.host.${newHostname}`),\n from: getObjectFrom(),\n ts: Date.now(),\n });\n\n // And save it\n try {\n await objects.setObjectAsync(object._id, object);\n } catch (err) {\n CLI.error.cannotChangeObject(object._id, err.message);\n }\n }\n\n CLI.success.hostRenamed(prevHostname, newHostname);\n }\n\n // Also rename all instances\n const instances = await enumInstances(objects);\n const instancesToRename =\n oldHostname === undefined ? instances : instances.filter(i => i.common.host === oldHostname);\n if (instancesToRename.length > 0) {\n for (const instance of instancesToRename) {\n // Update each instance object\n await changeInstanceHost(objects, instance, newHostname);\n }\n } else {\n CLI.warn.noInstancesFoundOnHost(oldHostname);\n }\n return void callback(EXIT_CODES.NO_ERROR);\n } catch (err) {\n CLI.error.unknown(err.message);\n return void callback(1);\n }\n });\n }\n}\n\n/**\n * Changes the host an instance is running on\n *\n * @param objects The objects DB to use\n * @param instance The instance object\n * @param newHostname The new hostname the instance should be running on\n */\nasync function changeInstanceHost(\n objects: ObjectsClient,\n instance: ioBroker.InstanceObject,\n newHostname: string,\n): Promise<void> {\n const oldInstanceHost = instance.common.host;\n instance.from = getObjectFrom();\n instance.ts = Date.now();\n instance.common.host = newHostname;\n // and save it\n try {\n await objects.setObjectAsync(instance._id, instance);\n CLI.success.instanceHostChanged(instance._id, oldInstanceHost, newHostname);\n } catch (e) {\n CLI.error.cannotChangeObject(instance._id, e.message);\n // resolve anyways, we don't want to cause errors\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,UAAqB;AACrB,wBAAmD;AACnD,sBAAqE;AACrE,kCAAkC;AAElC,qBAAe;AACf,s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SAAS,uCAAW,QAAQ;MAC5C,SAAS,KAAK;AACV,YAAI,MAAM,QAAQ,IAAI,OAAO;AAC7B,eAAO,KAAK,SAAS,CAAC;MAC1B;IACJ,CAAC;EACL;;AAUJ,eAAe,mBACX,SACA,UACA,aAAmB;AAEnB,QAAM,kBAAkB,SAAS,OAAO;AACxC,WAAS,WAAO,+BAAa;AAC7B,WAAS,KAAK,KAAK,IAAG;AACtB,WAAS,OAAO,OAAO;AAEvB,MAAI;AACA,UAAM,QAAQ,eAAe,SAAS,KAAK,QAAQ;AACnD,QAAI,QAAQ,oBAAoB,SAAS,KAAK,iBAAiB,WAAW;EAC9E,SAAS,GAAG;AACR,QAAI,MAAM,mBAAmB,SAAS,KAAK,EAAE,OAAO;EAExD;AACJ;",
|
|
6
6
|
"names": ["os", "instances", "fs"]
|
|
7
7
|
}
|
|
@@ -9,17 +9,14 @@ interface CLILogsOptions {
|
|
|
9
9
|
export declare class CLILogs extends CLICommand {
|
|
10
10
|
private readonly fileSizes;
|
|
11
11
|
private isReady;
|
|
12
|
-
/**
|
|
13
|
-
* @param options The command options including context and parameters
|
|
14
|
-
*/
|
|
15
12
|
constructor(options: CLICommandOptions);
|
|
16
13
|
/**
|
|
17
14
|
* Executes a command
|
|
18
15
|
*
|
|
19
|
-
* @param args
|
|
16
|
+
* @param args
|
|
20
17
|
* @param params additional parsed CLI parameters
|
|
21
18
|
*/
|
|
22
|
-
execute(args:
|
|
19
|
+
execute(args: any[], params: Record<string, any>): void;
|
|
23
20
|
/**
|
|
24
21
|
* Called by chokidar when watched files change
|
|
25
22
|
*
|
|
@@ -27,11 +24,8 @@ export declare class CLILogs extends CLICommand {
|
|
|
27
24
|
* @param event The type of change
|
|
28
25
|
* @param path Which path has changed
|
|
29
26
|
* @param stats Information about the file
|
|
30
|
-
* @param stats.size The current size of the file in bytes
|
|
31
27
|
*/
|
|
32
|
-
watchHandler(options: CLILogsOptions, event: string, path: string, stats
|
|
33
|
-
size: number;
|
|
34
|
-
}): void;
|
|
28
|
+
watchHandler(options: CLILogsOptions, event: string, path: string, stats: Record<string, any>): void;
|
|
35
29
|
/**
|
|
36
30
|
* If the log file belongs to today
|
|
37
31
|
*
|
|
@@ -5,7 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
8
|
var __export = (target, all) => {
|
|
10
9
|
for (var name in all)
|
|
11
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -43,21 +42,15 @@ var import_node_module = require("node:module");
|
|
|
43
42
|
const require2 = (0, import_node_module.createRequire)(__import_meta_url || `file://${__filename}`);
|
|
44
43
|
const { getConfigFileName } = import_js_controller_common.tools;
|
|
45
44
|
class CLILogs extends import_cliCommand.CLICommand {
|
|
46
|
-
static {
|
|
47
|
-
__name(this, "CLILogs");
|
|
48
|
-
}
|
|
49
45
|
fileSizes = /* @__PURE__ */ new Map();
|
|
50
46
|
isReady = false;
|
|
51
|
-
/**
|
|
52
|
-
* @param options The command options including context and parameters
|
|
53
|
-
*/
|
|
54
47
|
constructor(options) {
|
|
55
48
|
super(options);
|
|
56
49
|
}
|
|
57
50
|
/**
|
|
58
51
|
* Executes a command
|
|
59
52
|
*
|
|
60
|
-
* @param args
|
|
53
|
+
* @param args
|
|
61
54
|
* @param params additional parsed CLI parameters
|
|
62
55
|
*/
|
|
63
56
|
execute(args, params) {
|
|
@@ -107,12 +100,8 @@ class CLILogs extends import_cliCommand.CLICommand {
|
|
|
107
100
|
* @param event The type of change
|
|
108
101
|
* @param path Which path has changed
|
|
109
102
|
* @param stats Information about the file
|
|
110
|
-
* @param stats.size The current size of the file in bytes
|
|
111
103
|
*/
|
|
112
104
|
watchHandler(options, event, path, stats) {
|
|
113
|
-
if (!stats) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
105
|
if (event === "add" || !this.fileSizes.has(path)) {
|
|
117
106
|
this.fileSizes.set(path, stats.size);
|
|
118
107
|
if (stats.size > 0 && (this.isReady || options.complete && this.isTodaysLogfile(path))) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/cli/cliLogs.ts", "../../../../../../node_modules/@alcalzone/esm2cjs/shims/import.meta.url/shim.js"],
|
|
4
|
-
"sourcesContent": ["import { CLICommand, type CLICommandOptions } from './cliCommand.js';\nimport { tools, logger as toolsLogger } from '@iobroker/js-controller-common';\nimport chokidar from 'chokidar';\nimport fs from 'fs-extra';\nimport os from 'node:os';\nimport es from 'event-stream';\nimport { createRequire } from 'node:module';\n// eslint-disable-next-line unicorn/prefer-module\nconst require = createRequire(import.meta.url || `file://${__filename}`);\n\nconst { getConfigFileName } = tools;\n\ninterface CLILogsOptions {\n /** Whether to show today's full log */\n complete?: boolean;\n /** An optional RegExp to filter by */\n regex?: RegExp;\n}\n\n/** Command ioBroker state ... */\nexport class CLILogs extends CLICommand {\n private readonly fileSizes = new Map<string, number>();\n private isReady = false;\n\n
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { CLICommand, type CLICommandOptions } from './cliCommand.js';\nimport { tools, logger as toolsLogger } from '@iobroker/js-controller-common';\nimport chokidar from 'chokidar';\nimport fs from 'fs-extra';\nimport os from 'node:os';\nimport es from 'event-stream';\nimport { createRequire } from 'node:module';\n// eslint-disable-next-line unicorn/prefer-module\nconst require = createRequire(import.meta.url || `file://${__filename}`);\n\nconst { getConfigFileName } = tools;\n\ninterface CLILogsOptions {\n /** Whether to show today's full log */\n complete?: boolean;\n /** An optional RegExp to filter by */\n regex?: RegExp;\n}\n\n/** Command ioBroker state ... */\nexport class CLILogs extends CLICommand {\n private readonly fileSizes = new Map<string, number>();\n private isReady = false;\n\n constructor(options: CLICommandOptions) {\n super(options);\n }\n\n /**\n * Executes a command\n *\n * @param args\n * @param params additional parsed CLI parameters\n */\n execute(args: any[], params: Record<string, any>): void {\n const adapterName = args[0];\n const watch = params.watch || params.w;\n const count = params.lines || 1_000;\n\n const options: CLILogsOptions = {\n complete: this.options.all,\n };\n\n const config = fs.readJSONSync(require.resolve(getConfigFileName()));\n const logger = toolsLogger(config.log);\n // @ts-expect-error todo adjust logger type\n let fileName = logger.getFileName();\n if (fileName) {\n let lines = fs.readFileSync(fileName).toString('utf-8').split('\\n');\n lines = lines.filter(line => line);\n if (lines.length > count) {\n lines.splice(0, lines.length - count);\n }\n let regex: RegExp;\n if (adapterName) {\n //2019-03-02 13:26:54.698 - debug: iot.0 [ALEXA] Created ALEXA device: Bad.Hauptlicht.Aktor.STATE [\"turnOn\",\"turnOff\"]\n regex = new RegExp(`: ${adapterName}\\\\.`);\n options.regex = regex;\n }\n lines.forEach(line => {\n if (regex && !regex.test(line)) {\n return;\n }\n console.log(line);\n });\n\n if (watch) {\n fileName = fileName.replace(/\\\\/g, '/');\n const parts = fileName.split('/');\n parts.pop();\n chokidar\n .watch(`${parts.join('/')}/iobroker*`, {\n awaitWriteFinish: { stabilityThreshold: 500 },\n followSymlinks: false,\n })\n .on('all', this.watchHandler.bind(this, options))\n .on('ready', () => (this.isReady = true));\n }\n } else {\n console.log('No log file found');\n }\n }\n\n /**\n * Called by chokidar when watched files change\n *\n * @param options some options\n * @param event The type of change\n * @param path Which path has changed\n * @param stats Information about the file\n */\n watchHandler(options: CLILogsOptions, event: string, path: string, stats: Record<string, any>): void {\n if (event === 'add' || !this.fileSizes.has(path)) {\n this.fileSizes.set(path, stats.size);\n if (stats.size > 0 && (this.isReady || (options.complete && this.isTodaysLogfile(path)))) {\n this.streamChange(path, 0, options);\n }\n } else if (event === 'change') {\n const oldFileSize = this.fileSizes.get(path)!;\n this.fileSizes.set(path, stats.size);\n if (this.isReady && stats.size > oldFileSize) {\n this.streamChange(path, oldFileSize, options);\n }\n } else if (event === 'unlink') {\n this.fileSizes.delete(path);\n }\n }\n\n /**\n * If the log file belongs to today\n *\n * @param path The log file path\n */\n isTodaysLogfile(path: string): boolean {\n const YYYYMMDDDate = new Date().toJSON().slice(0, 10);\n return path.includes(YYYYMMDDDate);\n }\n\n /**\n * Streams a portion of a file to the console\n *\n * @param path The file to stream\n * @param start The offset in bytes where to start\n * @param options some options\n */\n streamChange(path: string, start: number, options: CLILogsOptions): void {\n const input = fs.createReadStream(path, {\n encoding: 'utf8',\n start,\n autoClose: true,\n });\n if (options.regex) {\n // Read the input line by line and only include the lines matching the filter\n input\n .pipe(es.split())\n .pipe(es.filterSync(line => options.regex!.test(line)))\n .pipe(es.mapSync((line: string) => line + os.EOL))\n .pipe(process.stdout);\n } else {\n // just pipe the input through\n tools.pipeLinewise(input, process.stdout);\n }\n }\n}\n", "export const __import_meta_url =\n typeof document === 'undefined' ? new (require('url'.replace('', '')).URL)('file:' + __filename).href :\n (document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href)\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;ACAO,IAAM,oBACX,OAAO,aAAa,cAAc,KAAK,QAAQ,MAAM,QAAQ,IAAI,EAAE,CAAC,GAAE,IAAK,UAAU,UAAU,EAAE,OAC9F,SAAS,iBAAiB,SAAS,cAAc,OAAO,IAAI,IAAI,WAAW,SAAS,OAAO,EAAE;ADFlG,wBAAmD;AACnD,kCAA6C;AAC7C,sBAAqB;AACrB,sBAAe;AACf,qBAAe;AACf,0BAAe;AACf,yBAA8B;AAE9B,MAAMA,eAAU,kCAAc,qBAAmB,UAAU,UAAU,EAAE;AAEvE,MAAM,EAAE,kBAAiB,IAAK;AAUxB,MAAO,gBAAgB,6BAAU;EAClB,YAAY,oBAAI,IAAG;EAC5B,UAAU;EAElB,YAAY,SAA0B;AAClC,UAAM,OAAO;EACjB;;;;;;;EAQA,QAAQ,MAAa,QAA2B;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C,WAAK,UAAU,IAAI,MAAM,MAAM,IAAI;AACnC,UAAI,MAAM,OAAO,MAAM,KAAK,WAAY,QAAQ,YAAY,KAAK,gBAAgB,IAAI,IAAK;AACtF,aAAK,aAAa,MAAM,GAAG,OAAO;MACtC;IACJ,WAAW,UAAU,UAAU;AAC3B,YAAM,cAAc,KAAK,UAAU,IAAI,IAAI;AAC3C,WAAK,UAAU,IAAI,MAAM,MAAM,IAAI;AACnC,UAAI,KAAK,WAAW,MAAM,OAAO,aAAa;AAC1C,aAAK,aAAa,MAAM,aAAa,OAAO;MAChD;IACJ,WAAW,UAAU,UAAU;AAC3B,WAAK,UAAU,OAAO,IAAI;IAC9B;EACJ;;;;;;EAOA,gBAAgB,MAAY;AACxB,UAAM,gBAAe,oBAAI,KAAI,GAAG,OAAM,EAAG,MAAM,GAAG,EAAE;AACpD,WAAO,KAAK,SAAS,YAAY;EACrC;;;;;;;;EASA,aAAa,MAAc,OAAe,SAAuB;AAC7D,UAAM,QAAQ,gBAAAF,QAAG,iBAAiB,MAAM;MACpC,UAAU;MACV;MACA,WAAW;KACd;AACD,QAAI,QAAQ,OAAO;AAEf,YACK,KAAK,oBAAAG,QAAG,MAAK,CAAE,EACf,KAAK,oBAAAA,QAAG,WAAW,UAAQ,QAAQ,MAAO,KAAK,IAAI,CAAC,CAAC,EACrD,KAAK,oBAAAA,QAAG,QAAQ,CAAC,SAAiB,OAAO,eAAAC,QAAG,GAAG,CAAC,EAChD,KAAK,QAAQ,MAAM;IAC5B,OAAO;AAEH,wCAAM,aAAa,OAAO,QAAQ,MAAM;IAC5C;EACJ;;",
|
|
6
6
|
"names": ["require", "fs", "toolsLogger", "chokidar", "es", "os"]
|
|
7
7
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CLICommand, type CLICommandOptions } from './cliCommand.js';
|
|
2
|
-
/** Command iobroker message ... */
|
|
3
2
|
export declare class CLIMessage extends CLICommand {
|
|
4
3
|
/** @param options The CLI Message options */
|
|
5
4
|
constructor(options: CLICommandOptions);
|
|
@@ -8,6 +7,6 @@ export declare class CLIMessage extends CLICommand {
|
|
|
8
7
|
*
|
|
9
8
|
* @param args parsed arguments
|
|
10
9
|
*/
|
|
11
|
-
execute(args:
|
|
10
|
+
execute(args: any[]): void;
|
|
12
11
|
}
|
|
13
12
|
//# sourceMappingURL=cliMessage.d.ts.map
|
|
@@ -5,7 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
8
|
var __export = (target, all) => {
|
|
10
9
|
for (var name in all)
|
|
11
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -36,9 +35,6 @@ var CLI = __toESM(require("./messages.js"), 1);
|
|
|
36
35
|
var import_cliCommand = require("./cliCommand.js");
|
|
37
36
|
var import_cliTools = require("./cliTools.js");
|
|
38
37
|
class CLIMessage extends import_cliCommand.CLICommand {
|
|
39
|
-
static {
|
|
40
|
-
__name(this, "CLIMessage");
|
|
41
|
-
}
|
|
42
38
|
/** @param options The CLI Message options */
|
|
43
39
|
constructor(options) {
|
|
44
40
|
super(options);
|
|
@@ -102,7 +98,6 @@ async function sendMessage(states, targetId, command, message) {
|
|
|
102
98
|
await states.pushMessage(targetId, { command, message, from: "cli" });
|
|
103
99
|
CLI.success.messageSent(targetId, command, message);
|
|
104
100
|
}
|
|
105
|
-
__name(sendMessage, "sendMessage");
|
|
106
101
|
// Annotate the CommonJS export names for ESM import in node:
|
|
107
102
|
0 && (module.exports = {
|
|
108
103
|
CLIMessage
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/cli/cliMessage.ts"],
|
|
4
|
-
"sourcesContent": ["import * as CLI from './messages.js';\nimport { CLICommand, type CLICommandOptions } from './cliCommand.js';\nimport { enumInstances } from './cliTools.js';\nimport type { Client as StatesClient } from '@iobroker/db-states-redis';\n\
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import * as CLI from './messages.js';\nimport { CLICommand, type CLICommandOptions } from './cliCommand.js';\nimport { enumInstances } from './cliTools.js';\nimport type { Client as StatesClient } from '@iobroker/db-states-redis';\n\nexport class CLIMessage extends CLICommand {\n /** @param options The CLI Message options */\n constructor(options: CLICommandOptions) {\n super(options);\n }\n\n /**\n * Executes a command\n *\n * @param args parsed arguments\n */\n execute(args: any[]): void {\n const { callback, dbConnect, showHelp } = this.options;\n let [adapter, command, message] = args;\n if (adapter === null || adapter === undefined) {\n CLI.error.requiredArgumentMissing('adapter');\n showHelp();\n return void callback(1);\n }\n if (message === null || message === undefined) {\n if (command === null || command === undefined) {\n CLI.error.requiredArgumentMissing('message');\n showHelp();\n return void callback(1);\n }\n message = command;\n command = 'send';\n }\n // Try to parse JSON\n // TODO: can we use the methods from cliObjects?\n if (typeof message === 'string' && message.startsWith('{') && message.endsWith('}')) {\n message = JSON.parse(message);\n }\n\n dbConnect(async params => {\n const { states, objects } = params;\n\n try {\n const pos = adapter.indexOf('.');\n let instance = null;\n if (pos !== -1) {\n instance = adapter.substring(pos + 1);\n adapter = adapter.substring(0, pos);\n }\n let messageTargets = [];\n if (instance === null) {\n // This message wasn't meant for a specific instance,\n const adapterInstances = await enumInstances(objects, adapter);\n if (adapterInstances.length === 0) {\n CLI.error.noInstancesFound(adapter);\n return void callback(1);\n }\n messageTargets = adapterInstances.map(row => row._id);\n } else {\n messageTargets.unshift(`system.adapter.${adapter}.${instance}`);\n }\n\n // Send the message to all targets\n const messagePromises = messageTargets.map(t => sendMessage(states, t, command, message));\n await Promise.all(messagePromises);\n return void callback();\n } catch (err) {\n CLI.error.unknown(err.message);\n return void callback(1);\n }\n });\n }\n}\n\n/**\n * @param states The States DB\n * @param targetId The instance or adapter to send the message to\n * @param command The command to send\n * @param message The message to send\n */\nasync function sendMessage(states: StatesClient, targetId: string, command: string, message: string): Promise<void> {\n await states.pushMessage(targetId, { command, message, from: 'cli' });\n CLI.success.messageSent(targetId, command, message);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,UAAqB;AACrB,wBAAmD;AACnD,sBAA8B;AAGxB,MAAO,mBAAmB,6BAAU;;EAEtC,YAAY,SAA0B;AAClC,UAAM,OAAO;EACjB;;;;;;EAOA,QAAQ,MAAW;AACf,UAAM,EAAE,UAAU,WAAW,SAAQ,IAAK,KAAK;AAC/C,QAAI,CAAC,SAAS,SAAS,OAAO,IAAI;AAClC,QAAI,YAAY,QAAQ,YAAY,QAAW;AAC3C,UAAI,MAAM,wBAAwB,SAAS;AAC3C,eAAQ;AACR,aAAO,KAAK,SAAS,CAAC;IAC1B;AACA,QAAI,YAAY,QAAQ,YAAY,QAAW;AAC3C,UAAI,YAAY,QAAQ,YAAY,QAAW;AAC3C,YAAI,MAAM,wBAAwB,SAAS;AAC3C,iBAAQ;AACR,eAAO,KAAK,SAAS,CAAC;MAC1B;AACA,gBAAU;AACV,gBAAU;IACd;AAGA,QAAI,OAAO,YAAY,YAAY,QAAQ,WAAW,GAAG,KAAK,QAAQ,SAAS,GAAG,GAAG;AACjF,gBAAU,KAAK,MAAM,OAAO;IAChC;AAEA,cAAU,OAAM,WAAS;AACrB,YAAM,EAAE,QAAQ,QAAO,IAAK;AAE5B,UAAI;AACA,cAAM,MAAM,QAAQ,QAAQ,GAAG;AAC/B,YAAI,WAAW;AACf,YAAI,QAAQ,IAAI;AACZ,qBAAW,QAAQ,UAAU,MAAM,CAAC;AACpC,oBAAU,QAAQ,UAAU,GAAG,GAAG;QACtC;AACA,YAAI,iBAAiB,CAAA;AACrB,YAAI,aAAa,MAAM;AAEnB,gBAAM,mBAAmB,UAAM,+BAAc,SAAS,OAAO;AAC7D,cAAI,iBAAiB,WAAW,GAAG;AAC/B,gBAAI,MAAM,iBAAiB,OAAO;AAClC,mBAAO,KAAK,SAAS,CAAC;UAC1B;AACA,2BAAiB,iBAAiB,IAAI,SAAO,IAAI,GAAG;QACxD,OAAO;AACH,yBAAe,QAAQ,kBAAkB,OAAO,IAAI,QAAQ,EAAE;QAClE;AAGA,cAAM,kBAAkB,eAAe,IAAI,OAAK,YAAY,QAAQ,GAAG,SAAS,OAAO,CAAC;AACxF,cAAM,QAAQ,IAAI,eAAe;AACjC,eAAO,KAAK,SAAQ;MACxB,SAAS,KAAK;AACV,YAAI,MAAM,QAAQ,IAAI,OAAO;AAC7B,eAAO,KAAK,SAAS,CAAC;MAC1B;IACJ,CAAC;EACL;;AASJ,eAAe,YAAY,QAAsB,UAAkB,SAAiB,SAAe;AAC/F,QAAM,OAAO,YAAY,UAAU,EAAE,SAAS,SAAS,MAAM,MAAK,CAAE;AACpE,MAAI,QAAQ,YAAY,UAAU,SAAS,OAAO;AACtD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,16 +3,13 @@ import type { Client as ObjectsClient } from '@iobroker/db-objects-redis';
|
|
|
3
3
|
import type { Client as StatesClient } from '@iobroker/db-states-redis';
|
|
4
4
|
/** Command iobroker object ... */
|
|
5
5
|
export declare class CLIObjects extends CLICommand {
|
|
6
|
-
/**
|
|
7
|
-
* @param options The command options including context and parameters
|
|
8
|
-
*/
|
|
9
6
|
constructor(options: CLICommandOptions);
|
|
10
7
|
/**
|
|
11
8
|
* Executes a command
|
|
12
9
|
*
|
|
13
|
-
* @param args
|
|
10
|
+
* @param args
|
|
14
11
|
*/
|
|
15
|
-
execute(args:
|
|
12
|
+
execute(args: any[]): void;
|
|
16
13
|
/**
|
|
17
14
|
* Activates the usage of Redis Sets
|
|
18
15
|
*/
|
|
@@ -32,33 +29,33 @@ export declare class CLIObjects extends CLICommand {
|
|
|
32
29
|
/**
|
|
33
30
|
* Changes access rights for all objects matching the pattern
|
|
34
31
|
*
|
|
35
|
-
* @param args
|
|
32
|
+
* @param args
|
|
36
33
|
*/
|
|
37
|
-
chmod(args:
|
|
34
|
+
chmod(args: any[]): void;
|
|
38
35
|
/**
|
|
39
36
|
* Changes owner for all objects matching the pattern
|
|
40
37
|
*
|
|
41
|
-
* @param args
|
|
38
|
+
* @param args
|
|
42
39
|
*/
|
|
43
|
-
chown(args:
|
|
40
|
+
chown(args: any[]): void;
|
|
44
41
|
/**
|
|
45
42
|
* Lists all objects matching a pattern and their access rights
|
|
46
43
|
*
|
|
47
|
-
* @param args
|
|
44
|
+
* @param args
|
|
48
45
|
*/
|
|
49
|
-
list(args:
|
|
46
|
+
list(args: any[]): void;
|
|
50
47
|
/**
|
|
51
48
|
* Retrieves an object or its property from the DB and prints it
|
|
52
49
|
*
|
|
53
|
-
* @param args
|
|
50
|
+
* @param args
|
|
54
51
|
*/
|
|
55
|
-
get(args:
|
|
52
|
+
get(args: any[]): void;
|
|
56
53
|
/**
|
|
57
54
|
* Updates an object or its property with the given value
|
|
58
55
|
*
|
|
59
|
-
* @param args
|
|
56
|
+
* @param args
|
|
60
57
|
*/
|
|
61
|
-
set(args:
|
|
58
|
+
set(args: any[]): void;
|
|
62
59
|
/**
|
|
63
60
|
* Encrypts all newly set properties of encryptedNative - currently customized for propPath
|
|
64
61
|
*
|
|
@@ -71,11 +68,11 @@ export declare class CLIObjects extends CLICommand {
|
|
|
71
68
|
/**
|
|
72
69
|
* Extends an object with the given value
|
|
73
70
|
*
|
|
74
|
-
* @param args
|
|
71
|
+
* @param args
|
|
75
72
|
*/
|
|
76
|
-
extend(args:
|
|
73
|
+
extend(args: any[]): void;
|
|
77
74
|
/**
|
|
78
|
-
* Collects all
|
|
75
|
+
* Collects all object for specific path
|
|
79
76
|
*
|
|
80
77
|
* @param objects class
|
|
81
78
|
* @param params parameters for getObjectView
|
|
@@ -86,15 +83,15 @@ export declare class CLIObjects extends CLICommand {
|
|
|
86
83
|
*
|
|
87
84
|
* @param objects class
|
|
88
85
|
* @param ids IDs
|
|
89
|
-
* @param callback
|
|
86
|
+
* @param callback
|
|
90
87
|
*/
|
|
91
88
|
_deleteObjects(objects: ObjectsClient, ids: string[], callback: (exitCode: number) => void): Promise<void>;
|
|
92
89
|
/**
|
|
93
90
|
* Deletes an object
|
|
94
91
|
*
|
|
95
|
-
* @param args
|
|
92
|
+
* @param args
|
|
96
93
|
*/
|
|
97
|
-
delete(args:
|
|
94
|
+
delete(args: any[]): void;
|
|
98
95
|
/**
|
|
99
96
|
* Prints a list of objects and its access properties
|
|
100
97
|
*
|
|
@@ -5,7 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
8
|
var __export = (target, all) => {
|
|
10
9
|
for (var name in all)
|
|
11
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -37,19 +36,13 @@ var CLI = __toESM(require("./messages.js"), 1);
|
|
|
37
36
|
var import_cliTools = require("./cliTools.js");
|
|
38
37
|
var import_js_controller_common = require("@iobroker/js-controller-common");
|
|
39
38
|
class CLIObjects extends import_cliCommand.CLICommand {
|
|
40
|
-
static {
|
|
41
|
-
__name(this, "CLIObjects");
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* @param options The command options including context and parameters
|
|
45
|
-
*/
|
|
46
39
|
constructor(options) {
|
|
47
40
|
super(options);
|
|
48
41
|
}
|
|
49
42
|
/**
|
|
50
43
|
* Executes a command
|
|
51
44
|
*
|
|
52
|
-
* @param args
|
|
45
|
+
* @param args
|
|
53
46
|
*/
|
|
54
47
|
execute(args) {
|
|
55
48
|
const { callback, showHelp } = this.options;
|
|
@@ -169,7 +162,7 @@ class CLIObjects extends import_cliCommand.CLICommand {
|
|
|
169
162
|
/**
|
|
170
163
|
* Changes access rights for all objects matching the pattern
|
|
171
164
|
*
|
|
172
|
-
* @param args
|
|
165
|
+
* @param args
|
|
173
166
|
*/
|
|
174
167
|
chmod(args) {
|
|
175
168
|
const { callback, dbConnect } = this.options;
|
|
@@ -191,15 +184,15 @@ class CLIObjects extends import_cliCommand.CLICommand {
|
|
|
191
184
|
}
|
|
192
185
|
dbConnect((params) => {
|
|
193
186
|
const { objects, states } = params;
|
|
194
|
-
|
|
195
|
-
|
|
187
|
+
objects.chmodObject(pattern, { user: "system.user.admin", object: modeObject, state: modeState }, (err, processed) => {
|
|
188
|
+
this.printObjectList(objects, states, err?.message, processed);
|
|
196
189
|
});
|
|
197
190
|
});
|
|
198
191
|
}
|
|
199
192
|
/**
|
|
200
193
|
* Changes owner for all objects matching the pattern
|
|
201
194
|
*
|
|
202
|
-
* @param args
|
|
195
|
+
* @param args
|
|
203
196
|
*/
|
|
204
197
|
chown(args) {
|
|
205
198
|
const { callback, dbConnect } = this.options;
|
|
@@ -223,30 +216,26 @@ class CLIObjects extends import_cliCommand.CLICommand {
|
|
|
223
216
|
}
|
|
224
217
|
dbConnect((params) => {
|
|
225
218
|
const { objects, states } = params;
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
owner: user,
|
|
229
|
-
ownerGroup: group
|
|
230
|
-
}, (err, processed) => {
|
|
231
|
-
return this.printObjectList(objects, states, err?.message, processed);
|
|
219
|
+
objects.chownObject(pattern, { user: "system.user.admin", owner: user, ownerGroup: group }, (err, processed) => {
|
|
220
|
+
this.printObjectList(objects, states, err?.message, processed);
|
|
232
221
|
});
|
|
233
222
|
});
|
|
234
223
|
}
|
|
235
224
|
/**
|
|
236
225
|
* Lists all objects matching a pattern and their access rights
|
|
237
226
|
*
|
|
238
|
-
* @param args
|
|
227
|
+
* @param args
|
|
239
228
|
*/
|
|
240
229
|
list(args) {
|
|
241
230
|
const { callback, dbConnect } = this.options;
|
|
242
|
-
let pattern;
|
|
243
|
-
if (typeof
|
|
244
|
-
pattern = { startkey:
|
|
231
|
+
let pattern = args[1];
|
|
232
|
+
if (typeof pattern === "string") {
|
|
233
|
+
pattern = { startkey: pattern.replace("*", ""), endkey: pattern.replace("*", "\u9999") };
|
|
245
234
|
}
|
|
246
235
|
dbConnect((params) => {
|
|
247
236
|
const { objects, states } = params;
|
|
248
237
|
objects.getObjectList(pattern, { user: "system.user.admin", sorted: true }, (err, processed) => {
|
|
249
|
-
this.printObjectList(objects, states, err?.message, processed && processed.rows && processed.rows.map((r) => r.value))
|
|
238
|
+
this.printObjectList(objects, states, err?.message, processed && processed.rows && processed.rows.map((r) => r.value));
|
|
250
239
|
return void callback(import_js_controller_common.EXIT_CODES.NO_ERROR);
|
|
251
240
|
});
|
|
252
241
|
});
|
|
@@ -254,7 +243,7 @@ class CLIObjects extends import_cliCommand.CLICommand {
|
|
|
254
243
|
/**
|
|
255
244
|
* Retrieves an object or its property from the DB and prints it
|
|
256
245
|
*
|
|
257
|
-
* @param args
|
|
246
|
+
* @param args
|
|
258
247
|
*/
|
|
259
248
|
get(args) {
|
|
260
249
|
const { callback, pretty, dbConnect } = this.options;
|
|
@@ -286,7 +275,7 @@ class CLIObjects extends import_cliCommand.CLICommand {
|
|
|
286
275
|
/**
|
|
287
276
|
* Updates an object or its property with the given value
|
|
288
277
|
*
|
|
289
|
-
* @param args
|
|
278
|
+
* @param args
|
|
290
279
|
*/
|
|
291
280
|
set(args) {
|
|
292
281
|
const { callback, dbConnect } = this.options;
|
|
@@ -304,7 +293,7 @@ class CLIObjects extends import_cliCommand.CLICommand {
|
|
|
304
293
|
const { propPath, value } = parsedArg;
|
|
305
294
|
dbConnect((params) => {
|
|
306
295
|
const { objects } = params;
|
|
307
|
-
const doSetObject =
|
|
296
|
+
const doSetObject = (obj) => {
|
|
308
297
|
objects.setObject(id, obj, (err) => {
|
|
309
298
|
if (err) {
|
|
310
299
|
CLI.error.cannotUpdateObject(id, err.message);
|
|
@@ -313,7 +302,7 @@ class CLIObjects extends import_cliCommand.CLICommand {
|
|
|
313
302
|
CLI.success.objectUpdated(id);
|
|
314
303
|
return void callback(import_js_controller_common.EXIT_CODES.NO_ERROR);
|
|
315
304
|
});
|
|
316
|
-
}
|
|
305
|
+
};
|
|
317
306
|
if (!propPath) {
|
|
318
307
|
doSetObject(value);
|
|
319
308
|
} else {
|
|
@@ -357,7 +346,7 @@ class CLIObjects extends import_cliCommand.CLICommand {
|
|
|
357
346
|
}
|
|
358
347
|
} else if (propPath === "native" && import_js_controller_common.tools.isObject(value)) {
|
|
359
348
|
let config;
|
|
360
|
-
for (const prop
|
|
349
|
+
for (const prop in value) {
|
|
361
350
|
if (typeof res.native[prop] === "string" && "encryptedNative" in res && res.encryptedNative?.includes(prop)) {
|
|
362
351
|
try {
|
|
363
352
|
config = config || await objects.getObjectAsync("system.config");
|
|
@@ -372,7 +361,7 @@ class CLIObjects extends import_cliCommand.CLICommand {
|
|
|
372
361
|
/**
|
|
373
362
|
* Extends an object with the given value
|
|
374
363
|
*
|
|
375
|
-
* @param args
|
|
364
|
+
* @param args
|
|
376
365
|
*/
|
|
377
366
|
extend(args) {
|
|
378
367
|
const { callback, dbConnect } = this.options;
|
|
@@ -388,20 +377,20 @@ class CLIObjects extends import_cliCommand.CLICommand {
|
|
|
388
377
|
return void callback(3);
|
|
389
378
|
}
|
|
390
379
|
const { value } = parsedArg;
|
|
391
|
-
dbConnect(
|
|
380
|
+
dbConnect((params) => {
|
|
392
381
|
const { objects } = params;
|
|
393
|
-
|
|
394
|
-
|
|
382
|
+
objects.extendObject(id, value, null, (err) => {
|
|
383
|
+
if (err) {
|
|
384
|
+
CLI.error.cannotUpdateObject(id, err.message);
|
|
385
|
+
return void callback(1);
|
|
386
|
+
}
|
|
395
387
|
CLI.success.objectUpdated(id);
|
|
396
388
|
return void callback(import_js_controller_common.EXIT_CODES.NO_ERROR);
|
|
397
|
-
}
|
|
398
|
-
CLI.error.cannotUpdateObject(id, err.message);
|
|
399
|
-
return void callback(1);
|
|
400
|
-
}
|
|
389
|
+
});
|
|
401
390
|
});
|
|
402
391
|
}
|
|
403
392
|
/**
|
|
404
|
-
* Collects all
|
|
393
|
+
* Collects all object for specific path
|
|
405
394
|
*
|
|
406
395
|
* @param objects class
|
|
407
396
|
* @param params parameters for getObjectView
|
|
@@ -440,7 +429,7 @@ class CLIObjects extends import_cliCommand.CLICommand {
|
|
|
440
429
|
*
|
|
441
430
|
* @param objects class
|
|
442
431
|
* @param ids IDs
|
|
443
|
-
* @param callback
|
|
432
|
+
* @param callback
|
|
444
433
|
*/
|
|
445
434
|
async _deleteObjects(objects, ids, callback) {
|
|
446
435
|
if (!ids || !ids.length) {
|
|
@@ -465,7 +454,7 @@ class CLIObjects extends import_cliCommand.CLICommand {
|
|
|
465
454
|
/**
|
|
466
455
|
* Deletes an object
|
|
467
456
|
*
|
|
468
|
-
* @param args
|
|
457
|
+
* @param args
|
|
469
458
|
*/
|
|
470
459
|
delete(args) {
|
|
471
460
|
const { callback, dbConnect } = this.options;
|
|
@@ -495,13 +484,14 @@ class CLIObjects extends import_cliCommand.CLICommand {
|
|
|
495
484
|
rl.question(`${result.length} object(s) will be deleted. Are you sure? [y/N]: `, (answer) => {
|
|
496
485
|
rl.close();
|
|
497
486
|
if (answer === "y" || answer === "yes" || answer === "j" || answer === "ja" || answer === "\u0434\u0430" || answer === "\u0434") {
|
|
498
|
-
|
|
487
|
+
this._deleteObjects(objects, ids, callback);
|
|
488
|
+
} else {
|
|
489
|
+
console.log("Aborted.");
|
|
490
|
+
return void callback(3);
|
|
499
491
|
}
|
|
500
|
-
console.log("Aborted.");
|
|
501
|
-
return void callback(3);
|
|
502
492
|
});
|
|
503
493
|
} else {
|
|
504
|
-
|
|
494
|
+
this._deleteObjects(objects, ids, callback);
|
|
505
495
|
}
|
|
506
496
|
} else {
|
|
507
497
|
objects.delObject(id, async (err) => {
|
|
@@ -552,14 +542,12 @@ class CLIObjects extends import_cliCommand.CLICommand {
|
|
|
552
542
|
function reverseString(str) {
|
|
553
543
|
return Array.from(str).reverse().join("");
|
|
554
544
|
}
|
|
555
|
-
__name(reverseString, "reverseString");
|
|
556
545
|
function normalizePropertyPath(path) {
|
|
557
546
|
const arrayIndexRegex = /(]\d+\[)(?!\.)/g;
|
|
558
547
|
let ret = reverseString(path);
|
|
559
548
|
ret = ret.replace(arrayIndexRegex, "$1.");
|
|
560
549
|
return reverseString(ret);
|
|
561
550
|
}
|
|
562
|
-
__name(normalizePropertyPath, "normalizePropertyPath");
|
|
563
551
|
function deepSelectProperty(object, path) {
|
|
564
552
|
function _deepSelectProperty(obj, pathArr) {
|
|
565
553
|
if (!pathArr.length) {
|
|
@@ -571,11 +559,9 @@ function deepSelectProperty(object, path) {
|
|
|
571
559
|
}
|
|
572
560
|
return _deepSelectProperty(obj[propName], pathArr);
|
|
573
561
|
}
|
|
574
|
-
__name(_deepSelectProperty, "_deepSelectProperty");
|
|
575
562
|
path = normalizePropertyPath(path);
|
|
576
563
|
return _deepSelectProperty(object, path.split("."));
|
|
577
564
|
}
|
|
578
|
-
__name(deepSelectProperty, "deepSelectProperty");
|
|
579
565
|
function deepSetProperty(object, path, value) {
|
|
580
566
|
function _deepSetProperty(obj, pathArr) {
|
|
581
567
|
if (pathArr.length === 1) {
|
|
@@ -588,11 +574,9 @@ function deepSetProperty(object, path, value) {
|
|
|
588
574
|
}
|
|
589
575
|
_deepSetProperty(obj[propName], pathArr);
|
|
590
576
|
}
|
|
591
|
-
__name(_deepSetProperty, "_deepSetProperty");
|
|
592
577
|
path = normalizePropertyPath(path);
|
|
593
578
|
_deepSetProperty(object, path.split("."));
|
|
594
579
|
}
|
|
595
|
-
__name(deepSetProperty, "deepSetProperty");
|
|
596
580
|
function parseCLIValue(arg) {
|
|
597
581
|
try {
|
|
598
582
|
return JSON.parse(arg);
|
|
@@ -600,7 +584,6 @@ function parseCLIValue(arg) {
|
|
|
600
584
|
return arg;
|
|
601
585
|
}
|
|
602
586
|
}
|
|
603
|
-
__name(parseCLIValue, "parseCLIValue");
|
|
604
587
|
function parsePropPathAndAssignment(arg) {
|
|
605
588
|
const equalsIndex = arg.indexOf("=");
|
|
606
589
|
if (equalsIndex > -1) {
|
|
@@ -619,7 +602,6 @@ function parsePropPathAndAssignment(arg) {
|
|
|
619
602
|
return void 0;
|
|
620
603
|
}
|
|
621
604
|
}
|
|
622
|
-
__name(parsePropPathAndAssignment, "parsePropPathAndAssignment");
|
|
623
605
|
// Annotate the CommonJS export names for ESM import in node:
|
|
624
606
|
0 && (module.exports = {
|
|
625
607
|
CLIObjects
|