@zwave-js/config 15.1.1 → 15.1.2
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/ConfigManager.d.ts +1 -1
- package/build/cjs/ConfigManager.js.map +1 -1
- package/build/cjs/JsonTemplate.d.ts +1 -1
- package/build/cjs/JsonTemplate.js +12 -13
- package/build/cjs/JsonTemplate.js.map +3 -3
- package/build/cjs/Logger_safe.d.ts +1 -1
- package/build/cjs/Logger_safe.js.map +1 -1
- package/build/cjs/Manufacturers.d.ts +1 -1
- package/build/cjs/Manufacturers.js.map +1 -1
- package/build/cjs/_version.d.ts +1 -1
- package/build/cjs/_version.js +1 -1
- package/build/cjs/_version.js.map +1 -1
- package/build/cjs/devices/AssociationConfig.d.ts +1 -1
- package/build/cjs/devices/AssociationConfig.js +2 -2
- package/build/cjs/devices/AssociationConfig.js.map +2 -2
- package/build/cjs/devices/CompatConfig.d.ts +2 -2
- package/build/cjs/devices/CompatConfig.js +13 -13
- package/build/cjs/devices/CompatConfig.js.map +3 -3
- package/build/cjs/devices/ConditionalItem.d.ts +1 -1
- package/build/cjs/devices/ConditionalItem.js +5 -5
- package/build/cjs/devices/ConditionalItem.js.map +3 -3
- package/build/cjs/devices/DeviceConfig.d.ts +1 -1
- package/build/cjs/devices/DeviceConfig.js +1 -2
- package/build/cjs/devices/DeviceConfig.js.map +3 -3
- package/build/cjs/devices/DeviceMetadata.d.ts +1 -1
- package/build/cjs/devices/DeviceMetadata.js +2 -2
- package/build/cjs/devices/DeviceMetadata.js.map +2 -2
- package/build/cjs/devices/EndpointConfig.d.ts +1 -1
- package/build/cjs/devices/EndpointConfig.js.map +1 -1
- package/build/cjs/devices/ParamInformation.d.ts +1 -1
- package/build/cjs/devices/ParamInformation.js +4 -4
- package/build/cjs/devices/ParamInformation.js.map +2 -2
- package/build/cjs/traits.d.ts +1 -1
- package/build/cjs/utils.d.ts +1 -1
- package/build/cjs/utils.js.map +1 -1
- package/build/cjs/utils_safe.d.ts +1 -1
- package/build/cjs/utils_safe.js +6 -6
- package/build/cjs/utils_safe.js.map +2 -2
- package/build/esm/ConfigManager.d.ts +1 -1
- package/build/esm/ConfigManager.d.ts.map +1 -1
- package/build/esm/JsonTemplate.d.ts +1 -1
- package/build/esm/JsonTemplate.d.ts.map +1 -1
- package/build/esm/JsonTemplate.js +2 -3
- package/build/esm/JsonTemplate.js.map +1 -1
- package/build/esm/Logger_safe.d.ts +1 -1
- package/build/esm/Logger_safe.d.ts.map +1 -1
- package/build/esm/Manufacturers.d.ts +1 -1
- package/build/esm/Manufacturers.d.ts.map +1 -1
- package/build/esm/_version.d.ts +1 -1
- package/build/esm/_version.js +1 -1
- package/build/esm/devices/AssociationConfig.d.ts +1 -1
- package/build/esm/devices/AssociationConfig.d.ts.map +1 -1
- package/build/esm/devices/AssociationConfig.js +1 -1
- package/build/esm/devices/AssociationConfig.js.map +1 -1
- package/build/esm/devices/CompatConfig.d.ts +2 -2
- package/build/esm/devices/CompatConfig.d.ts.map +1 -1
- package/build/esm/devices/CompatConfig.js +2 -2
- package/build/esm/devices/CompatConfig.js.map +1 -1
- package/build/esm/devices/ConditionalItem.d.ts +1 -1
- package/build/esm/devices/ConditionalItem.d.ts.map +1 -1
- package/build/esm/devices/ConditionalItem.js +2 -2
- package/build/esm/devices/ConditionalItem.js.map +1 -1
- package/build/esm/devices/DeviceConfig.d.ts +1 -1
- package/build/esm/devices/DeviceConfig.d.ts.map +1 -1
- package/build/esm/devices/DeviceConfig.js +1 -2
- package/build/esm/devices/DeviceConfig.js.map +1 -1
- package/build/esm/devices/DeviceMetadata.d.ts +1 -1
- package/build/esm/devices/DeviceMetadata.d.ts.map +1 -1
- package/build/esm/devices/DeviceMetadata.js +1 -1
- package/build/esm/devices/DeviceMetadata.js.map +1 -1
- package/build/esm/devices/EndpointConfig.d.ts +1 -1
- package/build/esm/devices/EndpointConfig.d.ts.map +1 -1
- package/build/esm/devices/ParamInformation.d.ts +1 -1
- package/build/esm/devices/ParamInformation.d.ts.map +1 -1
- package/build/esm/devices/ParamInformation.js +1 -1
- package/build/esm/devices/ParamInformation.js.map +1 -1
- package/build/esm/traits.d.ts +1 -1
- package/build/esm/traits.d.ts.map +1 -1
- package/build/esm/utils.d.ts +1 -1
- package/build/esm/utils.d.ts.map +1 -1
- package/build/esm/utils_safe.d.ts +1 -1
- package/build/esm/utils_safe.d.ts.map +1 -1
- package/build/esm/utils_safe.js +1 -1
- package/build/esm/utils_safe.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type LogContainer } from "@zwave-js/core";
|
|
2
|
-
import {
|
|
2
|
+
import type { FileSystem } from "@zwave-js/shared/bindings";
|
|
3
3
|
import { type ManufacturersMap } from "./Manufacturers.js";
|
|
4
4
|
import { ConditionalDeviceConfig, type DeviceConfig, type DeviceConfigIndex, type FulltextDeviceConfigIndex } from "./devices/DeviceConfig.js";
|
|
5
5
|
export interface ConfigManagerOptions {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/ConfigManager.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n\ttype LogContainer,\n\tZWaveError,\n\tZWaveErrorCodes,\n\tisZWaveError,\n} from \"@zwave-js/core\";\nimport { getErrorMessage, pathExists } from \"@zwave-js/shared\";\nimport { type FileSystem } from \"@zwave-js/shared/bindings\";\nimport path from \"pathe\";\nimport { ConfigLogger } from \"./Logger.js\";\nimport {\n\ttype ManufacturersMap,\n\tloadManufacturersInternal,\n\tsaveManufacturersInternal,\n} from \"./Manufacturers.js\";\nimport { PACKAGE_VERSION } from \"./_version.js\";\nimport {\n\tConditionalDeviceConfig,\n\ttype DeviceConfig,\n\ttype DeviceConfigIndex,\n\ttype FulltextDeviceConfigIndex,\n\tgeneratePriorityDeviceIndex,\n\tgetDevicesPaths,\n\tloadDeviceIndexInternal,\n\tloadFulltextDeviceIndexInternal,\n} from \"./devices/DeviceConfig.js\";\nimport {\n\ttype SyncExternalConfigDirResult,\n\tconfigDir,\n\tgetDeviceEntryPredicate,\n\tgetExternalConfigDirEnvVariable,\n\tsyncExternalConfigDir,\n} from \"./utils.js\";\n\nexport interface ConfigManagerOptions {\n\tbindings?: FileSystem;\n\tlogContainer?: LogContainer;\n\tdeviceConfigPriorityDir?: string;\n\tdeviceConfigExternalDir?: string;\n}\n\nexport class ConfigManager {\n\tpublic constructor(options: ConfigManagerOptions = {}) {\n\t\tthis._fs = options.bindings;\n\t\tthis._logContainer = options.logContainer;\n\n\t\tthis.deviceConfigPriorityDir = options.deviceConfigPriorityDir;\n\t\tthis.deviceConfigExternalDir = options.deviceConfigExternalDir;\n\n\t\tthis._configVersion = PACKAGE_VERSION;\n\t}\n\n\tprivate _fs: FileSystem | undefined;\n\tprivate async getFS(): Promise<FileSystem> {\n\t\tthis._fs ??= (await import(\"@zwave-js/core/bindings/fs/node\")).fs;\n\t\treturn this._fs;\n\t}\n\n\tprivate _configVersion: string;\n\tpublic get configVersion(): string {\n\t\treturn this._configVersion;\n\t}\n\n\tprivate _logContainer: LogContainer | undefined;\n\tprivate _logger: ConfigLogger | undefined;\n\tprivate async getLogger(): Promise<ConfigLogger> {\n\t\tif (!this._logContainer) {\n\t\t\tthis._logContainer =\n\t\t\t\t(await import(\"@zwave-js/core/bindings/log/node\")).log({\n\t\t\t\t\tenabled: false,\n\t\t\t\t});\n\t\t}\n\t\tif (!this._logger) {\n\t\t\tthis._logger = new ConfigLogger(this._logContainer);\n\t\t}\n\t\treturn this._logger;\n\t}\n\n\tprivate _manufacturers: ManufacturersMap | undefined;\n\tpublic get manufacturers(): ManufacturersMap {\n\t\tif (!this._manufacturers) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t\"The config has not been loaded yet!\",\n\t\t\t\tZWaveErrorCodes.Driver_NotReady,\n\t\t\t);\n\t\t}\n\t\treturn this._manufacturers;\n\t}\n\n\tprivate deviceConfigPriorityDir: string | undefined;\n\tprivate deviceConfigExternalDir: string | undefined;\n\tpublic get externalConfigDir(): string | undefined {\n\t\treturn this.deviceConfigExternalDir\n\t\t\t?? getExternalConfigDirEnvVariable();\n\t}\n\n\tprivate index: DeviceConfigIndex | undefined;\n\tprivate fulltextIndex: FulltextDeviceConfigIndex | undefined;\n\n\tprivate _useExternalConfig: boolean = false;\n\tpublic get useExternalConfig(): boolean {\n\t\treturn this._useExternalConfig;\n\t}\n\n\tpublic async loadAll(): Promise<void> {\n\t\tconst logger = await this.getLogger();\n\t\t// If the environment option for an external config dir is set\n\t\t// try to sync it and then use it\n\t\tlet syncResult: SyncExternalConfigDirResult | undefined;\n\t\tconst externalConfigDir = this.externalConfigDir;\n\t\tif (externalConfigDir) {\n\t\t\tsyncResult = await syncExternalConfigDir(\n\t\t\t\tawait this.getFS(),\n\t\t\t\texternalConfigDir,\n\t\t\t\tlogger,\n\t\t\t);\n\t\t}\n\n\t\tif (syncResult?.success) {\n\t\t\tthis._useExternalConfig = true;\n\t\t\tlogger.print(\n\t\t\t\t`Using external configuration dir ${externalConfigDir}`,\n\t\t\t);\n\t\t\tthis._configVersion = syncResult.version;\n\t\t} else {\n\t\t\tthis._useExternalConfig = false;\n\t\t\tthis._configVersion = PACKAGE_VERSION;\n\t\t}\n\t\tlogger.print(`version ${this._configVersion}`, \"info\");\n\n\t\tawait this.loadManufacturers();\n\t\tawait this.loadDeviceIndex();\n\t}\n\n\tpublic async loadManufacturers(): Promise<void> {\n\t\ttry {\n\t\t\tthis._manufacturers = await loadManufacturersInternal(\n\t\t\t\tawait this.getFS(),\n\t\t\t\tthis._useExternalConfig && this.externalConfigDir || undefined,\n\t\t\t);\n\t\t} catch (e) {\n\t\t\t// If the config file is missing or invalid, don't try to find it again\n\t\t\tif (isZWaveError(e) && e.code === ZWaveErrorCodes.Config_Invalid) {\n\t\t\t\tif (process.env.NODE_ENV !== \"test\") {\n\t\t\t\t\t(await this.getLogger()).print(\n\t\t\t\t\t\t`Could not load manufacturers config: ${e.message}`,\n\t\t\t\t\t\t\"error\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (!this._manufacturers) this._manufacturers = new Map();\n\t\t\t} else {\n\t\t\t\t// This is an unexpected error\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async saveManufacturers(): Promise<void> {\n\t\tif (!this._manufacturers) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t\"The config has not been loaded yet!\",\n\t\t\t\tZWaveErrorCodes.Driver_NotReady,\n\t\t\t);\n\t\t}\n\n\t\tawait saveManufacturersInternal(\n\t\t\tawait this.getFS(),\n\t\t\tthis._manufacturers,\n\t\t);\n\t}\n\n\t/**\n\t * Looks up the name of the manufacturer with the given ID in the configuration DB\n\t * @param manufacturerId The manufacturer id to look up\n\t */\n\tpublic lookupManufacturer(manufacturerId: number): string | undefined {\n\t\tif (!this._manufacturers) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t\"The config has not been loaded yet!\",\n\t\t\t\tZWaveErrorCodes.Driver_NotReady,\n\t\t\t);\n\t\t}\n\n\t\treturn this._manufacturers.get(manufacturerId);\n\t}\n\n\t/**\n\t * Add new manufacturers to configuration DB\n\t * @param manufacturerId The manufacturer id to look up\n\t * @param manufacturerName The manufacturer name\n\t */\n\tpublic setManufacturer(\n\t\tmanufacturerId: number,\n\t\tmanufacturerName: string,\n\t): void {\n\t\tif (!this._manufacturers) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t\"The config has not been loaded yet!\",\n\t\t\t\tZWaveErrorCodes.Driver_NotReady,\n\t\t\t);\n\t\t}\n\n\t\tthis._manufacturers.set(manufacturerId, manufacturerName);\n\t}\n\n\tpublic async loadDeviceIndex(): Promise<void> {\n\t\tconst fs = await this.getFS();\n\t\tconst logger = await this.getLogger();\n\t\ttry {\n\t\t\t// The index of config files included in this package\n\t\t\tconst embeddedIndex = await loadDeviceIndexInternal(\n\t\t\t\tfs,\n\t\t\t\tlogger,\n\t\t\t\tthis._useExternalConfig && this.externalConfigDir || undefined,\n\t\t\t);\n\t\t\t// A dynamic index of the user-defined priority device config files\n\t\t\tconst priorityIndex: DeviceConfigIndex = [];\n\t\t\tif (this.deviceConfigPriorityDir) {\n\t\t\t\tif (await pathExists(fs, this.deviceConfigPriorityDir)) {\n\t\t\t\t\tpriorityIndex.push(\n\t\t\t\t\t\t...(await generatePriorityDeviceIndex(\n\t\t\t\t\t\t\tfs,\n\t\t\t\t\t\t\tthis.deviceConfigPriorityDir,\n\t\t\t\t\t\t\tlogger,\n\t\t\t\t\t\t)),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tlogger.print(\n\t\t\t\t\t\t`Priority device configuration directory ${this.deviceConfigPriorityDir} not found`,\n\t\t\t\t\t\t\"warn\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Put the priority index in front, so the files get resolved first\n\t\t\tthis.index = [...priorityIndex, ...embeddedIndex];\n\t\t} catch (e) {\n\t\t\t// If the index file is missing or invalid, don't try to find it again\n\t\t\tif (\n\t\t\t\t(!isZWaveError(e) && e instanceof Error)\n\t\t\t\t|| (isZWaveError(e)\n\t\t\t\t\t&& e.code === ZWaveErrorCodes.Config_Invalid)\n\t\t\t) {\n\t\t\t\t// Fall back to no index on production systems\n\t\t\t\tif (!this.index) this.index = [];\n\t\t\t\tif (process.env.NODE_ENV !== \"test\") {\n\t\t\t\t\tlogger.print(\n\t\t\t\t\t\t`Could not load or regenerate device config index: ${e.message}`,\n\t\t\t\t\t\t\"error\",\n\t\t\t\t\t);\n\t\t\t\t\t// and don't throw\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// But fail hard in tests\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic getIndex(): DeviceConfigIndex | undefined {\n\t\treturn this.index;\n\t}\n\n\tpublic async loadFulltextDeviceIndex(): Promise<void> {\n\t\tthis.fulltextIndex = await loadFulltextDeviceIndexInternal(\n\t\t\tawait this.getFS(),\n\t\t\tawait this.getLogger(),\n\t\t);\n\t}\n\n\tpublic getFulltextIndex(): FulltextDeviceConfigIndex | undefined {\n\t\treturn this.fulltextIndex;\n\t}\n\n\t/**\n\t * Looks up the definition of a given device in the configuration DB, but does not evaluate conditional settings.\n\t * @param manufacturerId The manufacturer id of the device\n\t * @param productType The product type of the device\n\t * @param productId The product id of the device\n\t * @param firmwareVersion If known, configuration for a specific firmware version can be loaded.\n\t * If this is `undefined` or not given, the first matching file with a defined firmware range will be returned.\n\t */\n\tpublic async lookupDevicePreserveConditions(\n\t\tmanufacturerId: number,\n\t\tproductType: number,\n\t\tproductId: number,\n\t\tfirmwareVersion?: string,\n\t): Promise<ConditionalDeviceConfig | undefined> {\n\t\t// Load/regenerate the index if necessary\n\t\tif (!this.index) await this.loadDeviceIndex();\n\n\t\tconst fs = await this.getFS();\n\n\t\t// Look up the device in the index\n\t\tconst indexEntries = this.index!.filter(\n\t\t\tgetDeviceEntryPredicate(\n\t\t\t\tmanufacturerId,\n\t\t\t\tproductType,\n\t\t\t\tproductId,\n\t\t\t\tfirmwareVersion,\n\t\t\t),\n\t\t);\n\t\t// If there are multiple with overlapping firmware ranges, return the preferred one first\n\t\tconst indexEntry = indexEntries.find((e) => !!e.preferred)\n\t\t\t?? indexEntries[0];\n\n\t\tif (indexEntry) {\n\t\t\tconst devicesDir = getDevicesPaths(\n\t\t\t\tthis._useExternalConfig && this.externalConfigDir || configDir,\n\t\t\t).devicesDir;\n\t\t\tconst filePath = path.isAbsolute(indexEntry.filename)\n\t\t\t\t? indexEntry.filename\n\t\t\t\t: path.join(devicesDir, indexEntry.filename);\n\t\t\tif (!(await pathExists(fs, filePath))) return;\n\n\t\t\t// A config file is treated as am embedded one when it is located under the devices root dir\n\t\t\t// or the external config dir\n\t\t\tconst isEmbedded = !path\n\t\t\t\t.relative(devicesDir, filePath)\n\t\t\t\t.startsWith(\"..\");\n\n\t\t\t// When a device file is located in a different root directory than the embedded config files,\n\t\t\t// we use the embedded dir a fallback\n\t\t\tconst rootDir = indexEntry.rootDir ?? devicesDir;\n\t\t\tconst fallbackDirs = rootDir === devicesDir\n\t\t\t\t? undefined\n\t\t\t\t: [devicesDir];\n\n\t\t\ttry {\n\t\t\t\treturn await ConditionalDeviceConfig.from(\n\t\t\t\t\tfs,\n\t\t\t\t\tfilePath,\n\t\t\t\t\tisEmbedded,\n\t\t\t\t\t{ rootDir, fallbackDirs },\n\t\t\t\t);\n\t\t\t} catch (e) {\n\t\t\t\tif (process.env.NODE_ENV !== \"test\") {\n\t\t\t\t\t(await this.getLogger()).print(\n\t\t\t\t\t\t`Error loading device config ${filePath}: ${\n\t\t\t\t\t\t\tgetErrorMessage(\n\t\t\t\t\t\t\t\te,\n\t\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}`,\n\t\t\t\t\t\t\"error\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Looks up the definition of a given device in the configuration DB\n\t * @param manufacturerId The manufacturer id of the device\n\t * @param productType The product type of the device\n\t * @param productId The product id of the device\n\t * @param firmwareVersion If known, configuration for a specific firmware version can be loaded.\n\t * If this is `undefined` or not given, the first matching file with a defined firmware range will be returned.\n\t */\n\tpublic async lookupDevice(\n\t\tmanufacturerId: number,\n\t\tproductType: number,\n\t\tproductId: number,\n\t\tfirmwareVersion?: string,\n\t): Promise<DeviceConfig | undefined> {\n\t\tconst ret = await this.lookupDevicePreserveConditions(\n\t\t\tmanufacturerId,\n\t\t\tproductType,\n\t\t\tproductId,\n\t\t\tfirmwareVersion,\n\t\t);\n\t\treturn ret?.evaluate({\n\t\t\tmanufacturerId,\n\t\t\tproductType,\n\t\t\tproductId,\n\t\t\tfirmwareVersion,\n\t\t});\n\t}\n}\n"],
|
|
4
|
+
"sourcesContent": ["import {\n\ttype LogContainer,\n\tZWaveError,\n\tZWaveErrorCodes,\n\tisZWaveError,\n} from \"@zwave-js/core\";\nimport { getErrorMessage, pathExists } from \"@zwave-js/shared\";\nimport type { FileSystem } from \"@zwave-js/shared/bindings\";\nimport path from \"pathe\";\nimport { ConfigLogger } from \"./Logger.js\";\nimport {\n\ttype ManufacturersMap,\n\tloadManufacturersInternal,\n\tsaveManufacturersInternal,\n} from \"./Manufacturers.js\";\nimport { PACKAGE_VERSION } from \"./_version.js\";\nimport {\n\tConditionalDeviceConfig,\n\ttype DeviceConfig,\n\ttype DeviceConfigIndex,\n\ttype FulltextDeviceConfigIndex,\n\tgeneratePriorityDeviceIndex,\n\tgetDevicesPaths,\n\tloadDeviceIndexInternal,\n\tloadFulltextDeviceIndexInternal,\n} from \"./devices/DeviceConfig.js\";\nimport {\n\ttype SyncExternalConfigDirResult,\n\tconfigDir,\n\tgetDeviceEntryPredicate,\n\tgetExternalConfigDirEnvVariable,\n\tsyncExternalConfigDir,\n} from \"./utils.js\";\n\nexport interface ConfigManagerOptions {\n\tbindings?: FileSystem;\n\tlogContainer?: LogContainer;\n\tdeviceConfigPriorityDir?: string;\n\tdeviceConfigExternalDir?: string;\n}\n\nexport class ConfigManager {\n\tpublic constructor(options: ConfigManagerOptions = {}) {\n\t\tthis._fs = options.bindings;\n\t\tthis._logContainer = options.logContainer;\n\n\t\tthis.deviceConfigPriorityDir = options.deviceConfigPriorityDir;\n\t\tthis.deviceConfigExternalDir = options.deviceConfigExternalDir;\n\n\t\tthis._configVersion = PACKAGE_VERSION;\n\t}\n\n\tprivate _fs: FileSystem | undefined;\n\tprivate async getFS(): Promise<FileSystem> {\n\t\tthis._fs ??= (await import(\"@zwave-js/core/bindings/fs/node\")).fs;\n\t\treturn this._fs;\n\t}\n\n\tprivate _configVersion: string;\n\tpublic get configVersion(): string {\n\t\treturn this._configVersion;\n\t}\n\n\tprivate _logContainer: LogContainer | undefined;\n\tprivate _logger: ConfigLogger | undefined;\n\tprivate async getLogger(): Promise<ConfigLogger> {\n\t\tif (!this._logContainer) {\n\t\t\tthis._logContainer =\n\t\t\t\t(await import(\"@zwave-js/core/bindings/log/node\")).log({\n\t\t\t\t\tenabled: false,\n\t\t\t\t});\n\t\t}\n\t\tif (!this._logger) {\n\t\t\tthis._logger = new ConfigLogger(this._logContainer);\n\t\t}\n\t\treturn this._logger;\n\t}\n\n\tprivate _manufacturers: ManufacturersMap | undefined;\n\tpublic get manufacturers(): ManufacturersMap {\n\t\tif (!this._manufacturers) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t\"The config has not been loaded yet!\",\n\t\t\t\tZWaveErrorCodes.Driver_NotReady,\n\t\t\t);\n\t\t}\n\t\treturn this._manufacturers;\n\t}\n\n\tprivate deviceConfigPriorityDir: string | undefined;\n\tprivate deviceConfigExternalDir: string | undefined;\n\tpublic get externalConfigDir(): string | undefined {\n\t\treturn this.deviceConfigExternalDir\n\t\t\t?? getExternalConfigDirEnvVariable();\n\t}\n\n\tprivate index: DeviceConfigIndex | undefined;\n\tprivate fulltextIndex: FulltextDeviceConfigIndex | undefined;\n\n\tprivate _useExternalConfig: boolean = false;\n\tpublic get useExternalConfig(): boolean {\n\t\treturn this._useExternalConfig;\n\t}\n\n\tpublic async loadAll(): Promise<void> {\n\t\tconst logger = await this.getLogger();\n\t\t// If the environment option for an external config dir is set\n\t\t// try to sync it and then use it\n\t\tlet syncResult: SyncExternalConfigDirResult | undefined;\n\t\tconst externalConfigDir = this.externalConfigDir;\n\t\tif (externalConfigDir) {\n\t\t\tsyncResult = await syncExternalConfigDir(\n\t\t\t\tawait this.getFS(),\n\t\t\t\texternalConfigDir,\n\t\t\t\tlogger,\n\t\t\t);\n\t\t}\n\n\t\tif (syncResult?.success) {\n\t\t\tthis._useExternalConfig = true;\n\t\t\tlogger.print(\n\t\t\t\t`Using external configuration dir ${externalConfigDir}`,\n\t\t\t);\n\t\t\tthis._configVersion = syncResult.version;\n\t\t} else {\n\t\t\tthis._useExternalConfig = false;\n\t\t\tthis._configVersion = PACKAGE_VERSION;\n\t\t}\n\t\tlogger.print(`version ${this._configVersion}`, \"info\");\n\n\t\tawait this.loadManufacturers();\n\t\tawait this.loadDeviceIndex();\n\t}\n\n\tpublic async loadManufacturers(): Promise<void> {\n\t\ttry {\n\t\t\tthis._manufacturers = await loadManufacturersInternal(\n\t\t\t\tawait this.getFS(),\n\t\t\t\tthis._useExternalConfig && this.externalConfigDir || undefined,\n\t\t\t);\n\t\t} catch (e) {\n\t\t\t// If the config file is missing or invalid, don't try to find it again\n\t\t\tif (isZWaveError(e) && e.code === ZWaveErrorCodes.Config_Invalid) {\n\t\t\t\tif (process.env.NODE_ENV !== \"test\") {\n\t\t\t\t\t(await this.getLogger()).print(\n\t\t\t\t\t\t`Could not load manufacturers config: ${e.message}`,\n\t\t\t\t\t\t\"error\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (!this._manufacturers) this._manufacturers = new Map();\n\t\t\t} else {\n\t\t\t\t// This is an unexpected error\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async saveManufacturers(): Promise<void> {\n\t\tif (!this._manufacturers) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t\"The config has not been loaded yet!\",\n\t\t\t\tZWaveErrorCodes.Driver_NotReady,\n\t\t\t);\n\t\t}\n\n\t\tawait saveManufacturersInternal(\n\t\t\tawait this.getFS(),\n\t\t\tthis._manufacturers,\n\t\t);\n\t}\n\n\t/**\n\t * Looks up the name of the manufacturer with the given ID in the configuration DB\n\t * @param manufacturerId The manufacturer id to look up\n\t */\n\tpublic lookupManufacturer(manufacturerId: number): string | undefined {\n\t\tif (!this._manufacturers) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t\"The config has not been loaded yet!\",\n\t\t\t\tZWaveErrorCodes.Driver_NotReady,\n\t\t\t);\n\t\t}\n\n\t\treturn this._manufacturers.get(manufacturerId);\n\t}\n\n\t/**\n\t * Add new manufacturers to configuration DB\n\t * @param manufacturerId The manufacturer id to look up\n\t * @param manufacturerName The manufacturer name\n\t */\n\tpublic setManufacturer(\n\t\tmanufacturerId: number,\n\t\tmanufacturerName: string,\n\t): void {\n\t\tif (!this._manufacturers) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t\"The config has not been loaded yet!\",\n\t\t\t\tZWaveErrorCodes.Driver_NotReady,\n\t\t\t);\n\t\t}\n\n\t\tthis._manufacturers.set(manufacturerId, manufacturerName);\n\t}\n\n\tpublic async loadDeviceIndex(): Promise<void> {\n\t\tconst fs = await this.getFS();\n\t\tconst logger = await this.getLogger();\n\t\ttry {\n\t\t\t// The index of config files included in this package\n\t\t\tconst embeddedIndex = await loadDeviceIndexInternal(\n\t\t\t\tfs,\n\t\t\t\tlogger,\n\t\t\t\tthis._useExternalConfig && this.externalConfigDir || undefined,\n\t\t\t);\n\t\t\t// A dynamic index of the user-defined priority device config files\n\t\t\tconst priorityIndex: DeviceConfigIndex = [];\n\t\t\tif (this.deviceConfigPriorityDir) {\n\t\t\t\tif (await pathExists(fs, this.deviceConfigPriorityDir)) {\n\t\t\t\t\tpriorityIndex.push(\n\t\t\t\t\t\t...(await generatePriorityDeviceIndex(\n\t\t\t\t\t\t\tfs,\n\t\t\t\t\t\t\tthis.deviceConfigPriorityDir,\n\t\t\t\t\t\t\tlogger,\n\t\t\t\t\t\t)),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tlogger.print(\n\t\t\t\t\t\t`Priority device configuration directory ${this.deviceConfigPriorityDir} not found`,\n\t\t\t\t\t\t\"warn\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Put the priority index in front, so the files get resolved first\n\t\t\tthis.index = [...priorityIndex, ...embeddedIndex];\n\t\t} catch (e) {\n\t\t\t// If the index file is missing or invalid, don't try to find it again\n\t\t\tif (\n\t\t\t\t(!isZWaveError(e) && e instanceof Error)\n\t\t\t\t|| (isZWaveError(e)\n\t\t\t\t\t&& e.code === ZWaveErrorCodes.Config_Invalid)\n\t\t\t) {\n\t\t\t\t// Fall back to no index on production systems\n\t\t\t\tif (!this.index) this.index = [];\n\t\t\t\tif (process.env.NODE_ENV !== \"test\") {\n\t\t\t\t\tlogger.print(\n\t\t\t\t\t\t`Could not load or regenerate device config index: ${e.message}`,\n\t\t\t\t\t\t\"error\",\n\t\t\t\t\t);\n\t\t\t\t\t// and don't throw\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// But fail hard in tests\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic getIndex(): DeviceConfigIndex | undefined {\n\t\treturn this.index;\n\t}\n\n\tpublic async loadFulltextDeviceIndex(): Promise<void> {\n\t\tthis.fulltextIndex = await loadFulltextDeviceIndexInternal(\n\t\t\tawait this.getFS(),\n\t\t\tawait this.getLogger(),\n\t\t);\n\t}\n\n\tpublic getFulltextIndex(): FulltextDeviceConfigIndex | undefined {\n\t\treturn this.fulltextIndex;\n\t}\n\n\t/**\n\t * Looks up the definition of a given device in the configuration DB, but does not evaluate conditional settings.\n\t * @param manufacturerId The manufacturer id of the device\n\t * @param productType The product type of the device\n\t * @param productId The product id of the device\n\t * @param firmwareVersion If known, configuration for a specific firmware version can be loaded.\n\t * If this is `undefined` or not given, the first matching file with a defined firmware range will be returned.\n\t */\n\tpublic async lookupDevicePreserveConditions(\n\t\tmanufacturerId: number,\n\t\tproductType: number,\n\t\tproductId: number,\n\t\tfirmwareVersion?: string,\n\t): Promise<ConditionalDeviceConfig | undefined> {\n\t\t// Load/regenerate the index if necessary\n\t\tif (!this.index) await this.loadDeviceIndex();\n\n\t\tconst fs = await this.getFS();\n\n\t\t// Look up the device in the index\n\t\tconst indexEntries = this.index!.filter(\n\t\t\tgetDeviceEntryPredicate(\n\t\t\t\tmanufacturerId,\n\t\t\t\tproductType,\n\t\t\t\tproductId,\n\t\t\t\tfirmwareVersion,\n\t\t\t),\n\t\t);\n\t\t// If there are multiple with overlapping firmware ranges, return the preferred one first\n\t\tconst indexEntry = indexEntries.find((e) => !!e.preferred)\n\t\t\t?? indexEntries[0];\n\n\t\tif (indexEntry) {\n\t\t\tconst devicesDir = getDevicesPaths(\n\t\t\t\tthis._useExternalConfig && this.externalConfigDir || configDir,\n\t\t\t).devicesDir;\n\t\t\tconst filePath = path.isAbsolute(indexEntry.filename)\n\t\t\t\t? indexEntry.filename\n\t\t\t\t: path.join(devicesDir, indexEntry.filename);\n\t\t\tif (!(await pathExists(fs, filePath))) return;\n\n\t\t\t// A config file is treated as am embedded one when it is located under the devices root dir\n\t\t\t// or the external config dir\n\t\t\tconst isEmbedded = !path\n\t\t\t\t.relative(devicesDir, filePath)\n\t\t\t\t.startsWith(\"..\");\n\n\t\t\t// When a device file is located in a different root directory than the embedded config files,\n\t\t\t// we use the embedded dir a fallback\n\t\t\tconst rootDir = indexEntry.rootDir ?? devicesDir;\n\t\t\tconst fallbackDirs = rootDir === devicesDir\n\t\t\t\t? undefined\n\t\t\t\t: [devicesDir];\n\n\t\t\ttry {\n\t\t\t\treturn await ConditionalDeviceConfig.from(\n\t\t\t\t\tfs,\n\t\t\t\t\tfilePath,\n\t\t\t\t\tisEmbedded,\n\t\t\t\t\t{ rootDir, fallbackDirs },\n\t\t\t\t);\n\t\t\t} catch (e) {\n\t\t\t\tif (process.env.NODE_ENV !== \"test\") {\n\t\t\t\t\t(await this.getLogger()).print(\n\t\t\t\t\t\t`Error loading device config ${filePath}: ${\n\t\t\t\t\t\t\tgetErrorMessage(\n\t\t\t\t\t\t\t\te,\n\t\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}`,\n\t\t\t\t\t\t\"error\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Looks up the definition of a given device in the configuration DB\n\t * @param manufacturerId The manufacturer id of the device\n\t * @param productType The product type of the device\n\t * @param productId The product id of the device\n\t * @param firmwareVersion If known, configuration for a specific firmware version can be loaded.\n\t * If this is `undefined` or not given, the first matching file with a defined firmware range will be returned.\n\t */\n\tpublic async lookupDevice(\n\t\tmanufacturerId: number,\n\t\tproductType: number,\n\t\tproductId: number,\n\t\tfirmwareVersion?: string,\n\t): Promise<DeviceConfig | undefined> {\n\t\tconst ret = await this.lookupDevicePreserveConditions(\n\t\t\tmanufacturerId,\n\t\t\tproductType,\n\t\t\tproductId,\n\t\t\tfirmwareVersion,\n\t\t);\n\t\treturn ret?.evaluate({\n\t\t\tmanufacturerId,\n\t\t\tproductType,\n\t\t\tproductId,\n\t\t\tfirmwareVersion,\n\t\t});\n\t}\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,kBAKO;AACP,oBAA4C;AAE5C,mBAAiB;AACjB,oBAA6B;AAC7B,2BAIO;AACP,qBAAgC;AAChC,0BASO;AACP,mBAMO;AASD,MAAO,cAAa;EAzC1B,OAyC0B;;;EACzB,YAAmB,UAAgC,CAAA,GAAE;AACpD,SAAK,MAAM,QAAQ;AACnB,SAAK,gBAAgB,QAAQ;AAE7B,SAAK,0BAA0B,QAAQ;AACvC,SAAK,0BAA0B,QAAQ;AAEvC,SAAK,iBAAiB;EACvB;EAEQ;EACA,MAAM,QAAK;AAClB,SAAK,SAAS,MAAM,OAAO,iCAAiC,GAAG;AAC/D,WAAO,KAAK;EACb;EAEQ;EACR,IAAW,gBAAa;AACvB,WAAO,KAAK;EACb;EAEQ;EACA;EACA,MAAM,YAAS;AACtB,QAAI,CAAC,KAAK,eAAe;AACxB,WAAK,iBACH,MAAM,OAAO,kCAAkC,GAAG,IAAI;QACtD,SAAS;OACT;IACH;AACA,QAAI,CAAC,KAAK,SAAS;AAClB,WAAK,UAAU,IAAI,2BAAa,KAAK,aAAa;IACnD;AACA,WAAO,KAAK;EACb;EAEQ;EACR,IAAW,gBAAa;AACvB,QAAI,CAAC,KAAK,gBAAgB;AACzB,YAAM,IAAI,uBACT,uCACA,4BAAgB,eAAe;IAEjC;AACA,WAAO,KAAK;EACb;EAEQ;EACA;EACR,IAAW,oBA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
2
|
export declare function clearTemplateCache(): void;
|
|
3
3
|
/** Parses a JSON file with $import keys and replaces them with the selected objects */
|
|
4
4
|
export declare function readJsonWithTemplate(fs: ReadFileSystemInfo & ReadFile, filename: string, rootDirs?: string | string[]): Promise<Record<string, unknown>>;
|
|
@@ -33,9 +33,8 @@ __export(JsonTemplate_exports, {
|
|
|
33
33
|
readJsonWithTemplate: () => readJsonWithTemplate
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(JsonTemplate_exports);
|
|
36
|
-
var
|
|
36
|
+
var import_core = require("@zwave-js/core");
|
|
37
37
|
var import_shared = require("@zwave-js/shared");
|
|
38
|
-
var import_safe2 = require("@zwave-js/shared/safe");
|
|
39
38
|
var import_typeguards = require("alcalzone-shared/typeguards");
|
|
40
39
|
var import_json5 = __toESM(require("json5"), 1);
|
|
41
40
|
var import_pathe = __toESM(require("pathe"), 1);
|
|
@@ -48,7 +47,7 @@ function clearTemplateCache() {
|
|
|
48
47
|
__name(clearTemplateCache, "clearTemplateCache");
|
|
49
48
|
async function readJsonWithTemplate(fs, filename, rootDirs) {
|
|
50
49
|
if (!await (0, import_shared.pathExists)(fs, filename)) {
|
|
51
|
-
throw new
|
|
50
|
+
throw new import_core.ZWaveError(`Could not open config file ${filename}: not found!`, import_core.ZWaveErrorCodes.Config_NotFound);
|
|
52
51
|
}
|
|
53
52
|
if (typeof rootDirs === "string")
|
|
54
53
|
rootDirs = [rootDirs];
|
|
@@ -64,10 +63,10 @@ async function readJsonWithTemplate(fs, filename, rootDirs) {
|
|
|
64
63
|
__name(readJsonWithTemplate, "readJsonWithTemplate");
|
|
65
64
|
function assertImportSpecifier(val, source) {
|
|
66
65
|
if (typeof val !== "string") {
|
|
67
|
-
throw new
|
|
66
|
+
throw new import_core.ZWaveError(`Invalid import specifier ${String(val)}!${source != void 0 ? ` Source: ${source}` : ""}`, import_core.ZWaveErrorCodes.Config_Invalid);
|
|
68
67
|
}
|
|
69
68
|
if (!importSpecifierRegex.test(val)) {
|
|
70
|
-
throw new
|
|
69
|
+
throw new import_core.ZWaveError(`Import specifier "${val}" is invalid!${source != void 0 ? ` Source: ${source}` : ""}`, import_core.ZWaveErrorCodes.Config_Invalid);
|
|
71
70
|
}
|
|
72
71
|
}
|
|
73
72
|
__name(assertImportSpecifier, "assertImportSpecifier");
|
|
@@ -93,7 +92,7 @@ function select(obj, selector) {
|
|
|
93
92
|
ret = ret[part];
|
|
94
93
|
}
|
|
95
94
|
if (!(0, import_typeguards.isObject)(ret)) {
|
|
96
|
-
throw new
|
|
95
|
+
throw new import_core.ZWaveError(`The import target "${selector}" is not an object!`, import_core.ZWaveErrorCodes.Config_Invalid);
|
|
97
96
|
}
|
|
98
97
|
return ret;
|
|
99
98
|
}
|
|
@@ -116,9 +115,9 @@ async function readJsonWithTemplateInternal(fs, filename, selector, visited, fil
|
|
|
116
115
|
return relativeToRoot.startsWith("..");
|
|
117
116
|
});
|
|
118
117
|
if (outsideAllRootDirs) {
|
|
119
|
-
throw new
|
|
118
|
+
throw new import_core.ZWaveError(`Tried to import config file "${filename}" from outside all root directories: ${rootDirs.map((d) => `
|
|
120
119
|
\xB7 ${d}`).join("")}
|
|
121
|
-
${getImportStack(visited, selector)}`,
|
|
120
|
+
${getImportStack(visited, selector)}`, import_core.ZWaveErrorCodes.Config_Invalid);
|
|
122
121
|
}
|
|
123
122
|
}
|
|
124
123
|
const specifier = getImportSpecifier(filename, selector);
|
|
@@ -128,7 +127,7 @@ ${getImportStack(visited, selector)}`, import_safe.ZWaveErrorCodes.Config_Invali
|
|
|
128
127
|
specifier
|
|
129
128
|
].join(" -> ")}
|
|
130
129
|
`;
|
|
131
|
-
throw new
|
|
130
|
+
throw new import_core.ZWaveError(msg, import_core.ZWaveErrorCodes.Config_CircularImport);
|
|
132
131
|
}
|
|
133
132
|
let json;
|
|
134
133
|
if (fileCache.has(filename)) {
|
|
@@ -139,7 +138,7 @@ ${getImportStack(visited, selector)}`, import_safe.ZWaveErrorCodes.Config_Invali
|
|
|
139
138
|
json = import_json5.default.parse(fileContent);
|
|
140
139
|
fileCache.set(filename, json);
|
|
141
140
|
} catch (e) {
|
|
142
|
-
throw new
|
|
141
|
+
throw new import_core.ZWaveError(`Could not parse config file ${filename}: ${(0, import_shared.getErrorMessage)(e)}${getImportStack(visited, selector)}`, import_core.ZWaveErrorCodes.Config_Invalid);
|
|
143
142
|
}
|
|
144
143
|
}
|
|
145
144
|
return resolveJsonImports(fs, selector ? select(json, selector) : json, filename, [...visited, specifier], fileCache, rootDirs);
|
|
@@ -164,12 +163,12 @@ async function resolveJsonImports(fs, json, filename, visited, fileCache, rootDi
|
|
|
164
163
|
}
|
|
165
164
|
}
|
|
166
165
|
if (!newFilename) {
|
|
167
|
-
throw new
|
|
166
|
+
throw new import_core.ZWaveError(`Could not find the referenced file ${importFilename.slice(2)} in any of the root directories: ${rootDirs.map((d) => `
|
|
168
167
|
\xB7 ${d}`).join("")}
|
|
169
|
-
${getImportStack(visited, selector)}`,
|
|
168
|
+
${getImportStack(visited, selector)}`, import_core.ZWaveErrorCodes.Config_Invalid);
|
|
170
169
|
}
|
|
171
170
|
} else {
|
|
172
|
-
throw new
|
|
171
|
+
throw new import_core.ZWaveError(`An $import specifier cannot start with ~/ when no root directory is defined!${getImportStack(visited, selector)}`, import_core.ZWaveErrorCodes.Config_Invalid);
|
|
173
172
|
}
|
|
174
173
|
} else {
|
|
175
174
|
newFilename = import_pathe.default.join(import_pathe.default.dirname(filename), importFilename);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/JsonTemplate.ts"],
|
|
4
|
-
"sourcesContent": ["import { ZWaveError, ZWaveErrorCodes } from \"@zwave-js/core/safe\";\nimport { pathExists, readTextFile } from \"@zwave-js/shared\";\nimport {\n\ttype ReadFile,\n\ttype ReadFileSystemInfo,\n} from \"@zwave-js/shared/bindings\";\nimport { getErrorMessage } from \"@zwave-js/shared/safe\";\nimport { isArray, isObject } from \"alcalzone-shared/typeguards\";\nimport JSON5 from \"json5\";\nimport path from \"pathe\";\n\nconst IMPORT_KEY = \"$import\";\nconst importSpecifierRegex =\n\t/^(?<filename>(?:~\\/)?[\\w\\d\\/\\\\\\._-]+\\.json)?(?:#(?<selector>[\\w\\d\\/\\._-]+(?:\\[0x[0-9a-fA-F]+\\])?))?$/i;\n\ntype FileCache = Map<string, Record<string, unknown>>;\n\n// The template cache is used to speed up cases where the same files get parsed multiple times,\n// e.g. during config file linting. It should be cleared whenever the files need to be loaded fresh\n// from disk, like when creating an index\nconst templateCache: FileCache = new Map();\nexport function clearTemplateCache(): void {\n\ttemplateCache.clear();\n}\n\n/** Parses a JSON file with $import keys and replaces them with the selected objects */\nexport async function readJsonWithTemplate(\n\tfs: ReadFileSystemInfo & ReadFile,\n\tfilename: string,\n\trootDirs?: string | string[],\n): Promise<Record<string, unknown>> {\n\tif (!(await pathExists(fs, filename))) {\n\t\tthrow new ZWaveError(\n\t\t\t`Could not open config file ${filename}: not found!`,\n\t\t\tZWaveErrorCodes.Config_NotFound,\n\t\t);\n\t}\n\n\tif (typeof rootDirs === \"string\") rootDirs = [rootDirs];\n\n\t// Try to use the cached versions of the template files to speed up the loading\n\tconst fileCache = new Map(templateCache);\n\tconst ret = await readJsonWithTemplateInternal(\n\t\tfs,\n\t\tfilename,\n\t\tundefined,\n\t\t[],\n\t\tfileCache,\n\t\trootDirs,\n\t);\n\n\t// Only remember the cached templates, not the individual files to save RAM\n\tfor (const [filename, cached] of fileCache) {\n\t\tif (/[\\\\/]templates[\\\\/]/.test(filename)) {\n\t\t\ttemplateCache.set(filename, cached);\n\t\t}\n\t}\n\n\treturn ret;\n}\n\nfunction assertImportSpecifier(\n\tval: unknown,\n\tsource?: string,\n): asserts val is string {\n\tif (typeof val !== \"string\") {\n\t\tthrow new ZWaveError(\n\t\t\t`Invalid import specifier ${String(val)}!${\n\t\t\t\tsource != undefined ? ` Source: ${source}` : \"\"\n\t\t\t}`,\n\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t);\n\t}\n\tif (!importSpecifierRegex.test(val)) {\n\t\tthrow new ZWaveError(\n\t\t\t`Import specifier \"${val}\" is invalid!${\n\t\t\t\tsource != undefined ? ` Source: ${source}` : \"\"\n\t\t\t}`,\n\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t);\n\t}\n}\n\nfunction getImportSpecifier(filename: string, selector?: string): string {\n\tlet ret = filename;\n\tif (selector) ret += `#${selector}`;\n\treturn ret;\n}\n\nfunction select(\n\tobj: Record<string, unknown>,\n\tselector: string,\n): Record<string, unknown> {\n\tlet ret: Record<string, unknown> = obj;\n\tconst selectorParts = selector.split(\"/\").filter((s) => !!s);\n\tfor (const part of selectorParts) {\n\t\t// Special case for paramInformation selectors to select params by #\n\t\tif (isArray(ret)) {\n\t\t\tconst item = (ret as any).find(\n\t\t\t\t(r: any) => isObject(r) && \"#\" in r && r[\"#\"] === part,\n\t\t\t);\n\t\t\tif (item != undefined) {\n\t\t\t\t// Don't copy the param number\n\t\t\t\tconst { [\"#\"]: _, ...rest } = item;\n\t\t\t\tret = rest;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\t// By default select the object property\n\t\tret = (ret as any)[part];\n\t}\n\tif (!isObject(ret)) {\n\t\tthrow new ZWaveError(\n\t\t\t`The import target \"${selector}\" is not an object!`,\n\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t);\n\t}\n\treturn ret;\n}\n\nfunction getImportStack(\n\tvisited: string[],\n\tselector: string | undefined,\n): string {\n\tconst source = [...visited, selector ? `#${selector}` : undefined]\n\t\t.reverse()\n\t\t.filter((s) => !!s) as string[];\n\tif (source.length > 0) {\n\t\treturn `\\nImport stack: ${source.map((s) => `\\n in ${s}`).join(\"\")}`;\n\t}\n\treturn \"\";\n}\n\nasync function readJsonWithTemplateInternal(\n\tfs: ReadFileSystemInfo & ReadFile,\n\tfilename: string,\n\tselector: string | undefined,\n\tvisited: string[],\n\tfileCache: FileCache,\n\trootDirs?: string[],\n): Promise<Record<string, unknown>> {\n\tfilename = path.normalize(filename);\n\n\t// If we're limited by one or more root directories, make sure the file is inside one of those\n\tif (rootDirs) {\n\t\tconst outsideAllRootDirs = rootDirs.every((rootDir) => {\n\t\t\tconst relativeToRoot = path.relative(rootDir, filename);\n\t\t\treturn relativeToRoot.startsWith(\"..\");\n\t\t});\n\n\t\tif (outsideAllRootDirs) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t`Tried to import config file \"${filename}\" from outside all root directories: ${\n\t\t\t\t\trootDirs\n\t\t\t\t\t\t.map((d) => `\\n\u00B7 ${d}`)\n\t\t\t\t\t\t.join(\"\")\n\t\t\t\t}\n${getImportStack(visited, selector)}`,\n\t\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst specifier = getImportSpecifier(filename, selector);\n\tif (visited.includes(specifier)) {\n\t\tconst msg = `Circular $import in config files: ${\n\t\t\t[\n\t\t\t\t...visited,\n\t\t\t\tspecifier,\n\t\t\t].join(\" -> \")\n\t\t}\\n`;\n\t\t// process.stderr.write(msg + \"\\n\");\n\t\tthrow new ZWaveError(msg, ZWaveErrorCodes.Config_CircularImport);\n\t}\n\n\tlet json: Record<string, unknown>;\n\tif (fileCache.has(filename)) {\n\t\tjson = fileCache.get(filename)!;\n\t} else {\n\t\ttry {\n\t\t\tconst fileContent = await readTextFile(fs, filename, \"utf8\");\n\t\t\tjson = JSON5.parse(fileContent);\n\t\t\tfileCache.set(filename, json);\n\t\t} catch (e) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t`Could not parse config file ${filename}: ${\n\t\t\t\t\tgetErrorMessage(\n\t\t\t\t\t\te,\n\t\t\t\t\t)\n\t\t\t\t}${getImportStack(visited, selector)}`,\n\t\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t\t);\n\t\t}\n\t}\n\t// Resolve the JSON imports for (a subset) of the file and return the compound file\n\treturn resolveJsonImports(\n\t\tfs,\n\t\tselector ? select(json, selector) : json,\n\t\tfilename,\n\t\t[...visited, specifier],\n\t\tfileCache,\n\t\trootDirs,\n\t);\n}\n\n/** Replaces all `$import` properties in a JSON object with object spreads of the referenced file/property */\nasync function resolveJsonImports(\n\tfs: ReadFileSystemInfo & ReadFile,\n\tjson: Record<string, unknown>,\n\tfilename: string,\n\tvisited: string[],\n\tfileCache: FileCache,\n\trootDirs?: string[],\n): Promise<Record<string, unknown>> {\n\tconst ret: Record<string, unknown> = {};\n\t// Loop through all properties and copy them to the resulting object\n\tfor (const [prop, val] of Object.entries(json)) {\n\t\tif (prop === IMPORT_KEY) {\n\t\t\t// This is an import statement. Make sure we're working with a string\n\t\t\tassertImportSpecifier(val, visited.join(\" -> \"));\n\t\t\tconst { filename: importFilename, selector } = importSpecifierRegex\n\t\t\t\t.exec(val)!.groups!;\n\n\t\t\t// Resolve the correct import path\n\t\t\tlet newFilename: string | undefined;\n\t\t\tif (importFilename) {\n\t\t\t\tif (importFilename.startsWith(\"~/\")) {\n\t\t\t\t\t// This is a special import specifier that is relative to the root directory\n\t\t\t\t\t// Try to find at least one root directory that contains the referenced file\n\t\t\t\t\tif (rootDirs) {\n\t\t\t\t\t\tfor (const rootDir of rootDirs) {\n\t\t\t\t\t\t\tnewFilename = path.join(\n\t\t\t\t\t\t\t\trootDir,\n\t\t\t\t\t\t\t\timportFilename.slice(2),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif (await pathExists(fs, newFilename)) {\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// Try the next\n\t\t\t\t\t\t\t\tnewFilename = undefined!;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!newFilename) {\n\t\t\t\t\t\t\tthrow new ZWaveError(\n\t\t\t\t\t\t\t\t`Could not find the referenced file ${\n\t\t\t\t\t\t\t\t\timportFilename.slice(\n\t\t\t\t\t\t\t\t\t\t2,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t} in any of the root directories: ${\n\t\t\t\t\t\t\t\t\trootDirs\n\t\t\t\t\t\t\t\t\t\t.map((d) => `\\n\u00B7 ${d}`)\n\t\t\t\t\t\t\t\t\t\t.join(\"\")\n\t\t\t\t\t\t\t\t}\\n${\n\t\t\t\t\t\t\t\t\tgetImportStack(\n\t\t\t\t\t\t\t\t\t\tvisited,\n\t\t\t\t\t\t\t\t\t\tselector,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}`,\n\t\t\t\t\t\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new ZWaveError(\n\t\t\t\t\t\t\t`An $import specifier cannot start with ~/ when no root directory is defined!${\n\t\t\t\t\t\t\t\tgetImportStack(\n\t\t\t\t\t\t\t\t\tvisited,\n\t\t\t\t\t\t\t\t\tselector,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}`,\n\t\t\t\t\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tnewFilename = path.join(\n\t\t\t\t\t\tpath.dirname(filename),\n\t\t\t\t\t\timportFilename,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tnewFilename = filename;\n\t\t\t}\n\n\t\t\t// const importFilename = path.join(path.dirname(filename), val);\n\t\t\tconst imported = await readJsonWithTemplateInternal(\n\t\t\t\tfs,\n\t\t\t\tnewFilename,\n\t\t\t\tselector,\n\t\t\t\tvisited,\n\t\t\t\tfileCache,\n\t\t\t\trootDirs,\n\t\t\t);\n\t\t\tObject.assign(ret, imported);\n\t\t} else if (isObject(val)) {\n\t\t\t// We're looking at an object, recurse into it\n\t\t\tret[prop] = await resolveJsonImports(\n\t\t\t\tfs,\n\t\t\t\tval,\n\t\t\t\tfilename,\n\t\t\t\tvisited,\n\t\t\t\tfileCache,\n\t\t\t\trootDirs,\n\t\t\t);\n\t\t} else if (isArray(val)) {\n\t\t\t// We're looking at an array, check if there are objects we need to recurse into\n\t\t\tconst vals: unknown[] = [];\n\t\t\tfor (const v of val) {\n\t\t\t\tif (isObject(v)) {\n\t\t\t\t\tvals.push(\n\t\t\t\t\t\tawait resolveJsonImports(\n\t\t\t\t\t\t\tfs,\n\t\t\t\t\t\t\tv,\n\t\t\t\t\t\t\tfilename,\n\t\t\t\t\t\t\tvisited,\n\t\t\t\t\t\t\tfileCache,\n\t\t\t\t\t\t\trootDirs,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tvals.push(v);\n\t\t\t\t}\n\t\t\t}\n\t\t\tret[prop] = vals;\n\t\t} else {\n\t\t\tret[prop] = val;\n\t\t}\n\t}\n\treturn ret;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;AAAA,kBAA4C;AAC5C,
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["import { ZWaveError, ZWaveErrorCodes } from \"@zwave-js/core\";\nimport { getErrorMessage, pathExists, readTextFile } from \"@zwave-js/shared\";\nimport type { ReadFile, ReadFileSystemInfo } from \"@zwave-js/shared/bindings\";\nimport { isArray, isObject } from \"alcalzone-shared/typeguards\";\nimport JSON5 from \"json5\";\nimport path from \"pathe\";\n\nconst IMPORT_KEY = \"$import\";\nconst importSpecifierRegex =\n\t/^(?<filename>(?:~\\/)?[\\w\\d\\/\\\\\\._-]+\\.json)?(?:#(?<selector>[\\w\\d\\/\\._-]+(?:\\[0x[0-9a-fA-F]+\\])?))?$/i;\n\ntype FileCache = Map<string, Record<string, unknown>>;\n\n// The template cache is used to speed up cases where the same files get parsed multiple times,\n// e.g. during config file linting. It should be cleared whenever the files need to be loaded fresh\n// from disk, like when creating an index\nconst templateCache: FileCache = new Map();\nexport function clearTemplateCache(): void {\n\ttemplateCache.clear();\n}\n\n/** Parses a JSON file with $import keys and replaces them with the selected objects */\nexport async function readJsonWithTemplate(\n\tfs: ReadFileSystemInfo & ReadFile,\n\tfilename: string,\n\trootDirs?: string | string[],\n): Promise<Record<string, unknown>> {\n\tif (!(await pathExists(fs, filename))) {\n\t\tthrow new ZWaveError(\n\t\t\t`Could not open config file ${filename}: not found!`,\n\t\t\tZWaveErrorCodes.Config_NotFound,\n\t\t);\n\t}\n\n\tif (typeof rootDirs === \"string\") rootDirs = [rootDirs];\n\n\t// Try to use the cached versions of the template files to speed up the loading\n\tconst fileCache = new Map(templateCache);\n\tconst ret = await readJsonWithTemplateInternal(\n\t\tfs,\n\t\tfilename,\n\t\tundefined,\n\t\t[],\n\t\tfileCache,\n\t\trootDirs,\n\t);\n\n\t// Only remember the cached templates, not the individual files to save RAM\n\tfor (const [filename, cached] of fileCache) {\n\t\tif (/[\\\\/]templates[\\\\/]/.test(filename)) {\n\t\t\ttemplateCache.set(filename, cached);\n\t\t}\n\t}\n\n\treturn ret;\n}\n\nfunction assertImportSpecifier(\n\tval: unknown,\n\tsource?: string,\n): asserts val is string {\n\tif (typeof val !== \"string\") {\n\t\tthrow new ZWaveError(\n\t\t\t`Invalid import specifier ${String(val)}!${\n\t\t\t\tsource != undefined ? ` Source: ${source}` : \"\"\n\t\t\t}`,\n\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t);\n\t}\n\tif (!importSpecifierRegex.test(val)) {\n\t\tthrow new ZWaveError(\n\t\t\t`Import specifier \"${val}\" is invalid!${\n\t\t\t\tsource != undefined ? ` Source: ${source}` : \"\"\n\t\t\t}`,\n\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t);\n\t}\n}\n\nfunction getImportSpecifier(filename: string, selector?: string): string {\n\tlet ret = filename;\n\tif (selector) ret += `#${selector}`;\n\treturn ret;\n}\n\nfunction select(\n\tobj: Record<string, unknown>,\n\tselector: string,\n): Record<string, unknown> {\n\tlet ret: Record<string, unknown> = obj;\n\tconst selectorParts = selector.split(\"/\").filter((s) => !!s);\n\tfor (const part of selectorParts) {\n\t\t// Special case for paramInformation selectors to select params by #\n\t\tif (isArray(ret)) {\n\t\t\tconst item = (ret as any).find(\n\t\t\t\t(r: any) => isObject(r) && \"#\" in r && r[\"#\"] === part,\n\t\t\t);\n\t\t\tif (item != undefined) {\n\t\t\t\t// Don't copy the param number\n\t\t\t\tconst { [\"#\"]: _, ...rest } = item;\n\t\t\t\tret = rest;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\t// By default select the object property\n\t\tret = (ret as any)[part];\n\t}\n\tif (!isObject(ret)) {\n\t\tthrow new ZWaveError(\n\t\t\t`The import target \"${selector}\" is not an object!`,\n\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t);\n\t}\n\treturn ret;\n}\n\nfunction getImportStack(\n\tvisited: string[],\n\tselector: string | undefined,\n): string {\n\tconst source = [...visited, selector ? `#${selector}` : undefined]\n\t\t.reverse()\n\t\t.filter((s) => !!s) as string[];\n\tif (source.length > 0) {\n\t\treturn `\\nImport stack: ${source.map((s) => `\\n in ${s}`).join(\"\")}`;\n\t}\n\treturn \"\";\n}\n\nasync function readJsonWithTemplateInternal(\n\tfs: ReadFileSystemInfo & ReadFile,\n\tfilename: string,\n\tselector: string | undefined,\n\tvisited: string[],\n\tfileCache: FileCache,\n\trootDirs?: string[],\n): Promise<Record<string, unknown>> {\n\tfilename = path.normalize(filename);\n\n\t// If we're limited by one or more root directories, make sure the file is inside one of those\n\tif (rootDirs) {\n\t\tconst outsideAllRootDirs = rootDirs.every((rootDir) => {\n\t\t\tconst relativeToRoot = path.relative(rootDir, filename);\n\t\t\treturn relativeToRoot.startsWith(\"..\");\n\t\t});\n\n\t\tif (outsideAllRootDirs) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t`Tried to import config file \"${filename}\" from outside all root directories: ${\n\t\t\t\t\trootDirs\n\t\t\t\t\t\t.map((d) => `\\n\u00B7 ${d}`)\n\t\t\t\t\t\t.join(\"\")\n\t\t\t\t}\n${getImportStack(visited, selector)}`,\n\t\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst specifier = getImportSpecifier(filename, selector);\n\tif (visited.includes(specifier)) {\n\t\tconst msg = `Circular $import in config files: ${\n\t\t\t[\n\t\t\t\t...visited,\n\t\t\t\tspecifier,\n\t\t\t].join(\" -> \")\n\t\t}\\n`;\n\t\t// process.stderr.write(msg + \"\\n\");\n\t\tthrow new ZWaveError(msg, ZWaveErrorCodes.Config_CircularImport);\n\t}\n\n\tlet json: Record<string, unknown>;\n\tif (fileCache.has(filename)) {\n\t\tjson = fileCache.get(filename)!;\n\t} else {\n\t\ttry {\n\t\t\tconst fileContent = await readTextFile(fs, filename, \"utf8\");\n\t\t\tjson = JSON5.parse(fileContent);\n\t\t\tfileCache.set(filename, json);\n\t\t} catch (e) {\n\t\t\tthrow new ZWaveError(\n\t\t\t\t`Could not parse config file ${filename}: ${\n\t\t\t\t\tgetErrorMessage(\n\t\t\t\t\t\te,\n\t\t\t\t\t)\n\t\t\t\t}${getImportStack(visited, selector)}`,\n\t\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t\t);\n\t\t}\n\t}\n\t// Resolve the JSON imports for (a subset) of the file and return the compound file\n\treturn resolveJsonImports(\n\t\tfs,\n\t\tselector ? select(json, selector) : json,\n\t\tfilename,\n\t\t[...visited, specifier],\n\t\tfileCache,\n\t\trootDirs,\n\t);\n}\n\n/** Replaces all `$import` properties in a JSON object with object spreads of the referenced file/property */\nasync function resolveJsonImports(\n\tfs: ReadFileSystemInfo & ReadFile,\n\tjson: Record<string, unknown>,\n\tfilename: string,\n\tvisited: string[],\n\tfileCache: FileCache,\n\trootDirs?: string[],\n): Promise<Record<string, unknown>> {\n\tconst ret: Record<string, unknown> = {};\n\t// Loop through all properties and copy them to the resulting object\n\tfor (const [prop, val] of Object.entries(json)) {\n\t\tif (prop === IMPORT_KEY) {\n\t\t\t// This is an import statement. Make sure we're working with a string\n\t\t\tassertImportSpecifier(val, visited.join(\" -> \"));\n\t\t\tconst { filename: importFilename, selector } = importSpecifierRegex\n\t\t\t\t.exec(val)!.groups!;\n\n\t\t\t// Resolve the correct import path\n\t\t\tlet newFilename: string | undefined;\n\t\t\tif (importFilename) {\n\t\t\t\tif (importFilename.startsWith(\"~/\")) {\n\t\t\t\t\t// This is a special import specifier that is relative to the root directory\n\t\t\t\t\t// Try to find at least one root directory that contains the referenced file\n\t\t\t\t\tif (rootDirs) {\n\t\t\t\t\t\tfor (const rootDir of rootDirs) {\n\t\t\t\t\t\t\tnewFilename = path.join(\n\t\t\t\t\t\t\t\trootDir,\n\t\t\t\t\t\t\t\timportFilename.slice(2),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif (await pathExists(fs, newFilename)) {\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t// Try the next\n\t\t\t\t\t\t\t\tnewFilename = undefined!;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!newFilename) {\n\t\t\t\t\t\t\tthrow new ZWaveError(\n\t\t\t\t\t\t\t\t`Could not find the referenced file ${\n\t\t\t\t\t\t\t\t\timportFilename.slice(\n\t\t\t\t\t\t\t\t\t\t2,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t} in any of the root directories: ${\n\t\t\t\t\t\t\t\t\trootDirs\n\t\t\t\t\t\t\t\t\t\t.map((d) => `\\n\u00B7 ${d}`)\n\t\t\t\t\t\t\t\t\t\t.join(\"\")\n\t\t\t\t\t\t\t\t}\\n${\n\t\t\t\t\t\t\t\t\tgetImportStack(\n\t\t\t\t\t\t\t\t\t\tvisited,\n\t\t\t\t\t\t\t\t\t\tselector,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t}`,\n\t\t\t\t\t\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new ZWaveError(\n\t\t\t\t\t\t\t`An $import specifier cannot start with ~/ when no root directory is defined!${\n\t\t\t\t\t\t\t\tgetImportStack(\n\t\t\t\t\t\t\t\t\tvisited,\n\t\t\t\t\t\t\t\t\tselector,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}`,\n\t\t\t\t\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tnewFilename = path.join(\n\t\t\t\t\t\tpath.dirname(filename),\n\t\t\t\t\t\timportFilename,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tnewFilename = filename;\n\t\t\t}\n\n\t\t\t// const importFilename = path.join(path.dirname(filename), val);\n\t\t\tconst imported = await readJsonWithTemplateInternal(\n\t\t\t\tfs,\n\t\t\t\tnewFilename,\n\t\t\t\tselector,\n\t\t\t\tvisited,\n\t\t\t\tfileCache,\n\t\t\t\trootDirs,\n\t\t\t);\n\t\t\tObject.assign(ret, imported);\n\t\t} else if (isObject(val)) {\n\t\t\t// We're looking at an object, recurse into it\n\t\t\tret[prop] = await resolveJsonImports(\n\t\t\t\tfs,\n\t\t\t\tval,\n\t\t\t\tfilename,\n\t\t\t\tvisited,\n\t\t\t\tfileCache,\n\t\t\t\trootDirs,\n\t\t\t);\n\t\t} else if (isArray(val)) {\n\t\t\t// We're looking at an array, check if there are objects we need to recurse into\n\t\t\tconst vals: unknown[] = [];\n\t\t\tfor (const v of val) {\n\t\t\t\tif (isObject(v)) {\n\t\t\t\t\tvals.push(\n\t\t\t\t\t\tawait resolveJsonImports(\n\t\t\t\t\t\t\tfs,\n\t\t\t\t\t\t\tv,\n\t\t\t\t\t\t\tfilename,\n\t\t\t\t\t\t\tvisited,\n\t\t\t\t\t\t\tfileCache,\n\t\t\t\t\t\t\troot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
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Logger_safe.ts"],
|
|
4
|
-
"sourcesContent": ["import type { LogContext } from \"@zwave-js/core
|
|
4
|
+
"sourcesContent": ["import type { LogContext } from \"@zwave-js/core\";\n\nexport const CONFIG_LABEL = \"CONFIG\";\nexport const CONFIG_LOGLEVEL = \"debug\";\n\nexport type ConfigLogContext = LogContext<\"config\">;\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAEA;;;;;;AAAO,MAAM,eAAe;AACrB,MAAM,kBAAkB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Manufacturers.ts"],
|
|
4
|
-
"sourcesContent": ["import { ZWaveError, ZWaveErrorCodes, isZWaveError } from \"@zwave-js/core\";\nimport {\n\tformatId,\n\tpathExists,\n\treadTextFile,\n\tstringify,\n\twriteTextFile,\n} from \"@zwave-js/shared\";\nimport {\n\
|
|
4
|
+
"sourcesContent": ["import { ZWaveError, ZWaveErrorCodes, isZWaveError } from \"@zwave-js/core\";\nimport {\n\tformatId,\n\tpathExists,\n\treadTextFile,\n\tstringify,\n\twriteTextFile,\n} from \"@zwave-js/shared\";\nimport type {\n\tReadFile,\n\tReadFileSystemInfo,\n\tWriteFile,\n} from \"@zwave-js/shared/bindings\";\nimport { isObject } from \"alcalzone-shared/typeguards\";\nimport JSON5 from \"json5\";\nimport path from \"pathe\";\nimport { configDir } from \"./utils.js\";\nimport { hexKeyRegex4Digits, throwInvalidConfig } from \"./utils_safe.js\";\n\nexport type ManufacturersMap = Map<number, string>;\n\n/** @internal */\nexport async function loadManufacturersInternal(\n\tfs: ReadFileSystemInfo & ReadFile,\n\texternalConfigDir?: string,\n): Promise<ManufacturersMap> {\n\tconst configPath = path.join(\n\t\texternalConfigDir || configDir,\n\t\t\"manufacturers.json\",\n\t);\n\n\tif (!(await pathExists(fs, configPath))) {\n\t\tthrow new ZWaveError(\n\t\t\t\"The manufacturer config file does not exist!\",\n\t\t\tZWaveErrorCodes.Config_Invalid,\n\t\t);\n\t}\n\ttry {\n\t\tconst fileContents = await readTextFile(fs, configPath, \"utf8\");\n\t\tconst definition = JSON5.parse(fileContents);\n\t\tif (!isObject(definition)) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"manufacturers\",\n\t\t\t\t`the database is not an object!`,\n\t\t\t);\n\t\t}\n\n\t\tconst manufacturers = new Map();\n\t\tfor (const [id, name] of Object.entries(definition)) {\n\t\t\tif (!hexKeyRegex4Digits.test(id)) {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\"manufacturers\",\n\t\t\t\t\t`found invalid key ${id} at the root level. Manufacturer IDs must be hexadecimal lowercase.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (typeof name !== \"string\") {\n\t\t\t\tthrowInvalidConfig(\n\t\t\t\t\t\"manufacturers\",\n\t\t\t\t\t`Key ${id} has a non-string manufacturer name`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst idNum = parseInt(id.slice(2), 16);\n\t\t\tmanufacturers.set(idNum, name);\n\t\t}\n\n\t\treturn manufacturers;\n\t} catch (e) {\n\t\tif (isZWaveError(e) || ((e as any).code === \"ENOENT\")) {\n\t\t\tthrow e;\n\t\t} else {\n\t\t\tthrowInvalidConfig(\"manufacturers\");\n\t\t}\n\t}\n}\n\n/**\n * Write current manufacturers map to json\n */\nexport async function saveManufacturersInternal(\n\tfs: WriteFile,\n\tmanufacturers: ManufacturersMap,\n): Promise<void> {\n\tconst data: Record<string, string> = {};\n\n\tconst orderedMap = new Map(\n\t\t[...manufacturers].sort((a, b) => (a[0] > b[0] ? 1 : -1)),\n\t);\n\n\tfor (const [id, name] of orderedMap) {\n\t\tdata[formatId(id)] = name;\n\t}\n\n\tconst configPath = path.join(configDir, \"manufacturers.json\");\n\tawait writeTextFile(fs, configPath, stringify(data, \"\\t\") + \"\\n\");\n}\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AAG,CAAC;AAG1D,aAAW,CAAC,IAAI,IAAI,KAAK,YAAY;AACpC,aAAK,wBAAS,EAAE,CAAC,IAAI;EACtB;AAEA,QAAM,aAAa,aAAAD,QAAK,KAAK,wBAAW,oBAAoB;AAC5D,YAAM,6BAAc,IAAI,gBAAY,yBAAU,MAAM,GAAI,IAAI,IAAI;AACjE;AAhBsB;",
|
|
6
6
|
"names": ["path", "JSON5"]
|
|
7
7
|
}
|
package/build/cjs/_version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "15.1.
|
|
1
|
+
export declare const PACKAGE_VERSION = "15.1.2";
|
|
2
2
|
//# sourceMappingURL=_version.d.ts.map
|
package/build/cjs/_version.js
CHANGED
|
@@ -21,7 +21,7 @@ __export(version_exports, {
|
|
|
21
21
|
PACKAGE_VERSION: () => PACKAGE_VERSION
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(version_exports);
|
|
24
|
-
const PACKAGE_VERSION = "15.1.
|
|
24
|
+
const PACKAGE_VERSION = "15.1.2";
|
|
25
25
|
// Annotate the CommonJS export names for ESM import in node:
|
|
26
26
|
0 && (module.exports = {
|
|
27
27
|
PACKAGE_VERSION
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/_version.ts"],
|
|
4
|
-
"sourcesContent": ["// This file is auto-generated by the codegen maintenance script\nexport const PACKAGE_VERSION = \"15.1.
|
|
4
|
+
"sourcesContent": ["// This file is auto-generated by the codegen maintenance script\nexport const PACKAGE_VERSION = \"15.1.2\";\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;AACO,MAAM,kBAAkB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type JSONObject } from "@zwave-js/shared
|
|
1
|
+
import { type JSONObject } from "@zwave-js/shared";
|
|
2
2
|
import { type ConditionalItem } from "./ConditionalItem.js";
|
|
3
3
|
import type { DeviceID } from "./shared.js";
|
|
4
4
|
export declare class ConditionalAssociationConfig implements ConditionalItem<AssociationConfig> {
|
|
@@ -22,7 +22,7 @@ __export(AssociationConfig_exports, {
|
|
|
22
22
|
ConditionalAssociationConfig: () => ConditionalAssociationConfig
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(AssociationConfig_exports);
|
|
25
|
-
var
|
|
25
|
+
var import_shared = require("@zwave-js/shared");
|
|
26
26
|
var import_utils_safe = require("../utils_safe.js");
|
|
27
27
|
var import_ConditionalItem = require("./ConditionalItem.js");
|
|
28
28
|
class ConditionalAssociationConfig {
|
|
@@ -80,7 +80,7 @@ multiChannel in association ${groupId} must be a boolean`);
|
|
|
80
80
|
evaluateCondition(deviceId) {
|
|
81
81
|
if (!(0, import_ConditionalItem.conditionApplies)(this, deviceId))
|
|
82
82
|
return;
|
|
83
|
-
return (0,
|
|
83
|
+
return (0, import_shared.pick)(this, [
|
|
84
84
|
"groupId",
|
|
85
85
|
"label",
|
|
86
86
|
"description",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/devices/AssociationConfig.ts"],
|
|
4
|
-
"sourcesContent": ["import { type JSONObject, pick } from \"@zwave-js/shared
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,
|
|
4
|
+
"sourcesContent": ["import { type JSONObject, pick } from \"@zwave-js/shared\";\nimport { throwInvalidConfig } from \"../utils_safe.js\";\nimport {\n\ttype ConditionalItem,\n\tconditionApplies,\n\tvalidateCondition,\n} from \"./ConditionalItem.js\";\nimport type { DeviceID } from \"./shared.js\";\n\nexport class ConditionalAssociationConfig\n\timplements ConditionalItem<AssociationConfig>\n{\n\tpublic constructor(\n\t\tfilename: string,\n\t\tgroupId: number,\n\t\tdefinition: JSONObject,\n\t) {\n\t\tthis.groupId = groupId;\n\n\t\tvalidateCondition(\n\t\t\tfilename,\n\t\t\tdefinition,\n\t\t\t`Association ${groupId} contains an`,\n\t\t);\n\t\tthis.condition = definition.$if;\n\n\t\tif (typeof definition.label !== \"string\") {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${filename}:\nAssociation ${groupId} has a non-string label`,\n\t\t\t);\n\t\t}\n\t\tthis.label = definition.label;\n\n\t\tif (\n\t\t\tdefinition.description != undefined\n\t\t\t&& typeof definition.description !== \"string\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${filename}:\nAssociation ${groupId} has a non-string description`,\n\t\t\t);\n\t\t}\n\t\tthis.description = definition.description;\n\n\t\tif (typeof definition.maxNodes !== \"number\") {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${filename}:\nmaxNodes for association ${groupId} is not a number`,\n\t\t\t);\n\t\t}\n\t\tthis.maxNodes = definition.maxNodes;\n\n\t\tif (\n\t\t\tdefinition.isLifeline != undefined\n\t\t\t&& typeof definition.isLifeline !== \"boolean\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${filename}:\nisLifeline in association ${groupId} must be a boolean`,\n\t\t\t);\n\t\t}\n\t\tthis.isLifeline = !!definition.isLifeline;\n\n\t\tif (\n\t\t\tdefinition.multiChannel != undefined\n\t\t\t&& typeof definition.multiChannel !== \"boolean\"\n\t\t) {\n\t\t\tthrowInvalidConfig(\n\t\t\t\t\"devices\",\n\t\t\t\t`packages/config/config/devices/${filename}:\nmultiChannel in association ${groupId} must be a boolean`,\n\t\t\t);\n\t\t}\n\t\t// Default to the \"auto\" strategy\n\t\tthis.multiChannel = definition.multiChannel ?? \"auto\";\n\t}\n\n\tpublic readonly condition?: string;\n\n\tpublic readonly groupId: number;\n\tpublic readonly label: string;\n\tpublic readonly description?: string;\n\tpublic readonly maxNodes: number;\n\t/**\n\t * Whether this association group is used to report updates to the controller.\n\t * While Z-Wave+ defines a single lifeline, older devices may have multiple lifeline associations.\n\t */\n\tpublic readonly isLifeline: boolean;\n\t/**\n\t * Controls the strategy of setting up lifeline associations:\n\t *\n\t * * `true` - Use a multi channel association (if possible)\n\t * * `false` - Use a node association (if possible)\n\t * * `\"auto\"` - Prefer node associations, fall back to multi channel associations\n\t */\n\tpublic readonly multiChannel: boolean | \"auto\";\n\n\tpublic evaluateCondition(\n\t\tdeviceId?: DeviceID,\n\t): AssociationConfig | undefined {\n\t\tif (!conditionApplies(this, deviceId)) return;\n\n\t\treturn pick(this, [\n\t\t\t\"groupId\",\n\t\t\t\"label\",\n\t\t\t\"description\",\n\t\t\t\"maxNodes\",\n\t\t\t\"isLifeline\",\n\t\t\t\"multiChannel\",\n\t\t]);\n\t}\n}\n\nexport type AssociationConfig = Omit<\n\tConditionalAssociationConfig,\n\t\"condition\" | \"evaluateCondition\"\n>;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,oBAAsC;AACtC,wBAAmC;AACnC,6BAIO;AAGD,MAAO,6BAA4B;EATzC,OASyC;;;EAGxC,YACC,UACA,SACA,YAAsB;AAEtB,SAAK,UAAU;AAEf,kDACC,UACA,YACA,eAAe,OAAO,cAAc;AAErC,SAAK,YAAY,WAAW;AAE5B,QAAI,OAAO,WAAW,UAAU,UAAU;AACzC,gDACC,WACA,kCAAkC,QAAQ;cAChC,OAAO,yBAAyB;IAE5C;AACA,SAAK,QAAQ,WAAW;AAExB,QACC,WAAW,eAAe,UACvB,OAAO,WAAW,gBAAgB,UACpC;AACD,gDACC,WACA,kCAAkC,QAAQ;cAChC,OAAO,+BAA+B;IAElD;AACA,SAAK,cAAc,WAAW;AAE9B,QAAI,OAAO,WAAW,aAAa,UAAU;AAC5C,gDACC,WACA,kCAAkC,QAAQ;2BACnB,OAAO,kBAAkB;IAElD;AACA,SAAK,WAAW,WAAW;AAE3B,QACC,WAAW,cAAc,UACtB,OAAO,WAAW,eAAe,WACnC;AACD,gDACC,WACA,kCAAkC,QAAQ;4BAClB,OAAO,oBAAoB;IAErD;AACA,SAAK,aAAa,CAAC,CAAC,WAAW;AAE/B,QACC,WAAW,gBAAgB,UACxB,OAAO,WAAW,iBAAiB,WACrC;AACD,gDACC,WACA,kCAAkC,QAAQ;8BAChB,OAAO,oBAAoB;IAEvD;AAEA,SAAK,eAAe,WAAW,gBAAgB;EAChD;EAEgB;EAEA;EACA;EACA;EACA;;;;;EAKA;;;;;;;;EAQA;EAET,kBACN,UAAmB;AAEnB,QAAI,KAAC,yCAAiB,MAAM,QAAQ;AAAG;AAEvC,eAAO,oBAAK,MAAM;MACjB;MACA;MACA;MACA;MACA;MACA;KACA;EACF;;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type CommandClassInfo, type CommandClasses, type ValueID } from "@zwave-js/core
|
|
2
|
-
import { type JSONObject } from "@zwave-js/shared
|
|
1
|
+
import { type CommandClassInfo, type CommandClasses, type ValueID } from "@zwave-js/core";
|
|
2
|
+
import { type JSONObject } from "@zwave-js/shared";
|
|
3
3
|
import { type ConditionalItem } from "./ConditionalItem.js";
|
|
4
4
|
import type { DeviceID } from "./shared.js";
|
|
5
5
|
export declare class ConditionalCompatConfig implements ConditionalItem<CompatConfig> {
|
|
@@ -25,8 +25,8 @@ __export(CompatConfig_exports, {
|
|
|
25
25
|
ConditionalCompatConfig: () => ConditionalCompatConfig
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(CompatConfig_exports);
|
|
28
|
-
var
|
|
29
|
-
var
|
|
28
|
+
var import_core = require("@zwave-js/core");
|
|
29
|
+
var import_shared = require("@zwave-js/shared");
|
|
30
30
|
var import_typeguards = require("alcalzone-shared/typeguards");
|
|
31
31
|
var import_utils_safe = require("../utils_safe.js");
|
|
32
32
|
var import_ConditionalItem = require("./ConditionalItem.js");
|
|
@@ -346,7 +346,7 @@ compat option overrideQueries must be an object!`);
|
|
|
346
346
|
evaluateCondition(deviceId) {
|
|
347
347
|
if (!(0, import_ConditionalItem.conditionApplies)(this, deviceId))
|
|
348
348
|
return;
|
|
349
|
-
const ret = (0,
|
|
349
|
+
const ret = (0, import_shared.pick)(this, [
|
|
350
350
|
"alarmMapping",
|
|
351
351
|
"addCCs",
|
|
352
352
|
"removeCCs",
|
|
@@ -375,7 +375,7 @@ compat option overrideQueries must be an object!`);
|
|
|
375
375
|
"useUTCInTimeParametersCC",
|
|
376
376
|
"queryOnWakeup"
|
|
377
377
|
]);
|
|
378
|
-
return (0,
|
|
378
|
+
return (0, import_core.stripUndefined)(ret);
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
381
|
class CompatAddCC {
|
|
@@ -481,8 +481,8 @@ error in compat option alarmMapping, mapping #${index}: property "to.eventParame
|
|
|
481
481
|
}
|
|
482
482
|
}
|
|
483
483
|
}
|
|
484
|
-
this.from = (0,
|
|
485
|
-
this.to = (0,
|
|
484
|
+
this.from = (0, import_shared.pick)(definition.from, ["alarmType", "alarmLevel"]);
|
|
485
|
+
this.to = (0, import_shared.pick)(definition.to, [
|
|
486
486
|
"notificationType",
|
|
487
487
|
"notificationEvent",
|
|
488
488
|
"eventParameters"
|
|
@@ -500,22 +500,22 @@ class CompatOverrideQueries {
|
|
|
500
500
|
const parseOverride = /* @__PURE__ */ __name((cc, info) => {
|
|
501
501
|
if (typeof info.method !== "string") {
|
|
502
502
|
(0, import_utils_safe.throwInvalidConfig)("devices", `config/devices/${filename}:
|
|
503
|
-
Property "method" in compat option overrideQueries, CC ${(0,
|
|
503
|
+
Property "method" in compat option overrideQueries, CC ${(0, import_core.getCCName)(cc)} must be a string!`);
|
|
504
504
|
} else if (info.matchArgs != void 0 && !(0, import_typeguards.isArray)(info.matchArgs)) {
|
|
505
505
|
(0, import_utils_safe.throwInvalidConfig)("devices", `config/devices/${filename}:
|
|
506
|
-
Property "matchArgs" in compat option overrideQueries, CC ${(0,
|
|
506
|
+
Property "matchArgs" in compat option overrideQueries, CC ${(0, import_core.getCCName)(cc)} must be an array!`);
|
|
507
507
|
} else if (!("result" in info)) {
|
|
508
508
|
(0, import_utils_safe.throwInvalidConfig)("devices", `config/devices/${filename}:
|
|
509
|
-
Property "result" is missing in in compat option overrideQueries, CC ${(0,
|
|
509
|
+
Property "result" is missing in in compat option overrideQueries, CC ${(0, import_core.getCCName)(cc)}!`);
|
|
510
510
|
} else if (info.endpoint != void 0 && typeof info.endpoint !== "number") {
|
|
511
511
|
(0, import_utils_safe.throwInvalidConfig)("devices", `config/devices/${filename}:
|
|
512
|
-
Property "endpoint" in compat option overrideQueries, CC ${(0,
|
|
512
|
+
Property "endpoint" in compat option overrideQueries, CC ${(0, import_core.getCCName)(cc)} must be a number!`);
|
|
513
513
|
} else if (info.persistValues && !(0, import_typeguards.isObject)(info.persistValues)) {
|
|
514
514
|
(0, import_utils_safe.throwInvalidConfig)("devices", `config/devices/${filename}:
|
|
515
|
-
Property "persistValues" in compat option overrideQueries, CC ${(0,
|
|
515
|
+
Property "persistValues" in compat option overrideQueries, CC ${(0, import_core.getCCName)(cc)} must be an object!`);
|
|
516
516
|
} else if (info.extendMetadata && !(0, import_typeguards.isObject)(info.extendMetadata)) {
|
|
517
517
|
(0, import_utils_safe.throwInvalidConfig)("devices", `config/devices/${filename}:
|
|
518
|
-
Property "extendMetadata" in compat option overrideQueries, CC ${(0,
|
|
518
|
+
Property "extendMetadata" in compat option overrideQueries, CC ${(0, import_core.getCCName)(cc)} must be an object!`);
|
|
519
519
|
}
|
|
520
520
|
return {
|
|
521
521
|
endpoint: info.endpoint,
|
|
@@ -566,7 +566,7 @@ Property "${key}" in compat option overrideQueries must be a single override obj
|
|
|
566
566
|
continue;
|
|
567
567
|
}
|
|
568
568
|
}
|
|
569
|
-
return (0,
|
|
569
|
+
return (0, import_shared.pick)(query, ["result", "persistValues", "extendMetadata"]);
|
|
570
570
|
}
|
|
571
571
|
}
|
|
572
572
|
}
|