@zwave-js/config 14.0.0-beta.1 → 14.0.0-beta.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/{ConfigManager.d.ts → cjs/ConfigManager.d.ts} +2 -2
- package/build/cjs/ConfigManager.js +208 -0
- package/build/cjs/ConfigManager.js.map +7 -0
- package/build/cjs/JsonTemplate.js +198 -0
- package/build/cjs/JsonTemplate.js.map +7 -0
- package/build/{Logger.d.ts → cjs/Logger.d.ts} +1 -1
- package/build/cjs/Logger.js +50 -0
- package/build/cjs/Logger.js.map +7 -0
- package/build/cjs/Logger_safe.js +32 -0
- package/build/cjs/Logger_safe.js.map +7 -0
- package/build/cjs/Logic.js +71 -0
- package/build/cjs/Logic.js.map +7 -0
- package/build/cjs/LogicParser.js +1343 -0
- package/build/cjs/LogicParser.js.map +7 -0
- package/build/cjs/Manufacturers.js +88 -0
- package/build/cjs/Manufacturers.js.map +7 -0
- package/build/cjs/_version.d.ts +2 -0
- package/build/cjs/_version.js +29 -0
- package/build/cjs/_version.js.map +7 -0
- package/build/{devices → cjs/devices}/AssociationConfig.d.ts +2 -2
- package/build/cjs/devices/AssociationConfig.js +93 -0
- package/build/cjs/devices/AssociationConfig.js.map +7 -0
- package/build/{devices → cjs/devices}/CompatConfig.d.ts +2 -2
- package/build/cjs/devices/CompatConfig.js +584 -0
- package/build/cjs/devices/CompatConfig.js.map +7 -0
- package/build/{devices → cjs/devices}/ConditionalItem.d.ts +1 -1
- package/build/cjs/devices/ConditionalItem.js +107 -0
- package/build/cjs/devices/ConditionalItem.js.map +7 -0
- package/build/{devices → cjs/devices}/ConditionalPrimitive.d.ts +2 -2
- package/build/cjs/devices/ConditionalPrimitive.js +59 -0
- package/build/cjs/devices/ConditionalPrimitive.js.map +7 -0
- package/build/{devices → cjs/devices}/DeviceConfig.d.ts +7 -7
- package/build/cjs/devices/DeviceConfig.js +502 -0
- package/build/cjs/devices/DeviceConfig.js.map +7 -0
- package/build/cjs/devices/DeviceConfig.unit._test.js +17 -0
- package/build/cjs/devices/DeviceConfig.unit._test.js.map +7 -0
- package/build/{devices → cjs/devices}/DeviceMetadata.d.ts +3 -3
- package/build/cjs/devices/DeviceMetadata.js +112 -0
- package/build/cjs/devices/DeviceMetadata.js.map +7 -0
- package/build/{devices → cjs/devices}/EndpointConfig.d.ts +5 -5
- package/build/cjs/devices/EndpointConfig.js +87 -0
- package/build/cjs/devices/EndpointConfig.js.map +7 -0
- package/build/{devices → cjs/devices}/ParamInformation.d.ts +3 -3
- package/build/cjs/devices/ParamInformation.js +209 -0
- package/build/cjs/devices/ParamInformation.js.map +7 -0
- package/build/cjs/devices/shared.js +17 -0
- package/build/cjs/devices/shared.js.map +7 -0
- package/build/cjs/index.d.ts +13 -0
- package/build/cjs/index.js +53 -0
- package/build/cjs/index.js.map +7 -0
- package/build/cjs/index_safe.d.ts +3 -0
- package/build/cjs/index_safe.js +32 -0
- package/build/cjs/index_safe.js.map +7 -0
- package/build/cjs/package.json +3 -0
- package/build/{utils.d.ts → cjs/utils.d.ts} +2 -2
- package/build/cjs/utils.js +117 -0
- package/build/cjs/utils.js.map +7 -0
- package/build/cjs/utils_safe.js +57 -0
- package/build/cjs/utils_safe.js.map +7 -0
- package/build/esm/ConfigManager.d.ts +57 -0
- package/build/esm/ConfigManager.d.ts.map +1 -0
- package/build/{ConfigManager.js → esm/ConfigManager.js} +36 -43
- package/build/esm/ConfigManager.js.map +1 -0
- package/build/esm/JsonTemplate.d.ts +4 -0
- package/build/esm/JsonTemplate.d.ts.map +1 -0
- package/build/{JsonTemplate.js → esm/JsonTemplate.js} +30 -60
- package/build/esm/JsonTemplate.js.map +1 -0
- package/build/esm/Logger.d.ts +11 -0
- package/build/esm/Logger.d.ts.map +1 -0
- package/build/esm/Logger.js +23 -0
- package/build/esm/Logger.js.map +1 -0
- package/build/esm/Logger_safe.d.ts +5 -0
- package/build/esm/Logger_safe.d.ts.map +1 -0
- package/build/esm/Logger_safe.js +3 -0
- package/build/esm/Logger_safe.js.map +1 -0
- package/build/esm/Logic.d.ts +4 -0
- package/build/esm/Logic.d.ts.map +1 -0
- package/build/esm/Logic.js +35 -0
- package/build/esm/Logic.js.map +1 -0
- package/build/esm/LogicParser.d.ts +93 -0
- package/build/esm/LogicParser.d.ts.map +1 -0
- package/build/{LogicParser.js → esm/LogicParser.js} +2 -5
- package/build/{LogicParser.js.map → esm/LogicParser.js.map} +1 -1
- package/build/esm/Manufacturers.d.ts +6 -0
- package/build/esm/Manufacturers.d.ts.map +1 -0
- package/build/esm/Manufacturers.js +55 -0
- package/build/esm/Manufacturers.js.map +1 -0
- package/build/esm/_version.d.ts +2 -0
- package/build/esm/_version.d.ts.map +1 -0
- package/build/esm/_version.js +3 -0
- package/build/esm/_version.js.map +1 -0
- package/build/esm/devices/AssociationConfig.d.ts +27 -0
- package/build/esm/devices/AssociationConfig.d.ts.map +1 -0
- package/build/{devices → esm/devices}/AssociationConfig.js +12 -16
- package/build/esm/devices/AssociationConfig.js.map +1 -0
- package/build/esm/devices/CompatConfig.d.ts +112 -0
- package/build/esm/devices/CompatConfig.d.ts.map +1 -0
- package/build/{devices → esm/devices}/CompatConfig.js +112 -119
- package/build/esm/devices/CompatConfig.js.map +1 -0
- package/build/esm/devices/ConditionalItem.d.ts +14 -0
- package/build/esm/devices/ConditionalItem.d.ts.map +1 -0
- package/build/{devices → esm/devices}/ConditionalItem.js +15 -21
- package/build/esm/devices/ConditionalItem.js.map +1 -0
- package/build/esm/devices/ConditionalPrimitive.d.ts +13 -0
- package/build/esm/devices/ConditionalPrimitive.d.ts.map +1 -0
- package/build/esm/devices/ConditionalPrimitive.js +35 -0
- package/build/esm/devices/ConditionalPrimitive.js.map +1 -0
- package/build/esm/devices/DeviceConfig.d.ts +117 -0
- package/build/esm/devices/DeviceConfig.d.ts.map +1 -0
- package/build/{devices → esm/devices}/DeviceConfig.js +96 -108
- package/build/esm/devices/DeviceConfig.js.map +1 -0
- package/build/esm/devices/DeviceConfig.unit._test.d.ts +2 -0
- package/build/esm/devices/DeviceConfig.unit._test.d.ts.map +1 -0
- package/build/{devices → esm/devices}/DeviceConfig.unit._test.js +1 -2
- package/build/esm/devices/DeviceConfig.unit._test.js.map +1 -0
- package/build/esm/devices/DeviceMetadata.d.ts +41 -0
- package/build/esm/devices/DeviceMetadata.d.ts.map +1 -0
- package/build/{devices → esm/devices}/DeviceMetadata.js +16 -21
- package/build/esm/devices/DeviceMetadata.js.map +1 -0
- package/build/esm/devices/EndpointConfig.d.ts +20 -0
- package/build/esm/devices/EndpointConfig.d.ts.map +1 -0
- package/build/esm/devices/EndpointConfig.js +60 -0
- package/build/esm/devices/EndpointConfig.js.map +1 -0
- package/build/esm/devices/ParamInformation.d.ts +50 -0
- package/build/esm/devices/ParamInformation.d.ts.map +1 -0
- package/build/{devices → esm/devices}/ParamInformation.js +38 -44
- package/build/esm/devices/ParamInformation.js.map +1 -0
- package/build/esm/devices/shared.d.ts +11 -0
- package/build/esm/devices/shared.d.ts.map +1 -0
- package/build/esm/devices/shared.js +2 -0
- package/build/{devices → esm/devices}/shared.js.map +1 -1
- package/build/esm/index.d.ts +13 -0
- package/build/esm/index.d.ts.map +1 -0
- package/build/esm/index.js +14 -0
- package/build/esm/index.js.map +1 -0
- package/build/esm/index_safe.d.ts +3 -0
- package/build/esm/index_safe.d.ts.map +1 -0
- package/build/esm/index_safe.js +4 -0
- package/build/esm/index_safe.js.map +1 -0
- package/build/esm/package.json +3 -0
- package/build/esm/utils.d.ts +19 -0
- package/build/esm/utils.d.ts.map +1 -0
- package/build/esm/utils.js +93 -0
- package/build/esm/utils.js.map +1 -0
- package/build/esm/utils_safe.d.ts +7 -0
- package/build/esm/utils_safe.d.ts.map +1 -0
- package/build/esm/utils_safe.js +28 -0
- package/build/esm/utils_safe.js.map +1 -0
- package/package.json +22 -19
- package/build/ConfigManager.d.ts.map +0 -1
- package/build/ConfigManager.js.map +0 -1
- package/build/JsonTemplate.d.ts.map +0 -1
- package/build/JsonTemplate.js.map +0 -1
- package/build/Logger.d.ts.map +0 -1
- package/build/Logger.js +0 -27
- package/build/Logger.js.map +0 -1
- package/build/Logger_safe.d.ts.map +0 -1
- package/build/Logger_safe.js +0 -6
- package/build/Logger_safe.js.map +0 -1
- package/build/Logic.d.ts.map +0 -1
- package/build/Logic.js +0 -60
- package/build/Logic.js.map +0 -1
- package/build/LogicParser.d.ts.map +0 -1
- package/build/Manufacturers.d.ts.map +0 -1
- package/build/Manufacturers.js +0 -62
- package/build/Manufacturers.js.map +0 -1
- package/build/_version.d.ts +0 -2
- package/build/_version.d.ts.map +0 -1
- package/build/_version.js +0 -6
- package/build/_version.js.map +0 -1
- package/build/devices/AssociationConfig.d.ts.map +0 -1
- package/build/devices/AssociationConfig.js.map +0 -1
- package/build/devices/CompatConfig.d.ts.map +0 -1
- package/build/devices/CompatConfig.js.map +0 -1
- package/build/devices/ConditionalItem.d.ts.map +0 -1
- package/build/devices/ConditionalItem.js.map +0 -1
- package/build/devices/ConditionalPrimitive.d.ts.map +0 -1
- package/build/devices/ConditionalPrimitive.js +0 -40
- package/build/devices/ConditionalPrimitive.js.map +0 -1
- package/build/devices/DeviceConfig.d.ts.map +0 -1
- package/build/devices/DeviceConfig.js.map +0 -1
- package/build/devices/DeviceConfig.unit._test.d.ts.map +0 -1
- package/build/devices/DeviceConfig.unit._test.js.map +0 -1
- package/build/devices/DeviceMetadata.d.ts.map +0 -1
- package/build/devices/DeviceMetadata.js.map +0 -1
- package/build/devices/EndpointConfig.d.ts.map +0 -1
- package/build/devices/EndpointConfig.js +0 -64
- package/build/devices/EndpointConfig.js.map +0 -1
- package/build/devices/ParamInformation.d.ts.map +0 -1
- package/build/devices/ParamInformation.js.map +0 -1
- package/build/devices/shared.d.ts.map +0 -1
- package/build/devices/shared.js +0 -3
- package/build/index.d.ts +0 -13
- package/build/index.d.ts.map +0 -1
- package/build/index.js +0 -33
- package/build/index.js.map +0 -1
- package/build/index_safe.d.ts +0 -3
- package/build/index_safe.d.ts.map +0 -1
- package/build/index_safe.js +0 -22
- package/build/index_safe.js.map +0 -1
- package/build/utils.d.ts.map +0 -1
- package/build/utils.js +0 -124
- package/build/utils.js.map +0 -1
- package/build/utils_safe.d.ts.map +0 -1
- package/build/utils_safe.js +0 -33
- package/build/utils_safe.js.map +0 -1
- /package/build/{JsonTemplate.d.ts → cjs/JsonTemplate.d.ts} +0 -0
- /package/build/{Logger_safe.d.ts → cjs/Logger_safe.d.ts} +0 -0
- /package/build/{Logic.d.ts → cjs/Logic.d.ts} +0 -0
- /package/build/{LogicParser.d.ts → cjs/LogicParser.d.ts} +0 -0
- /package/build/{Manufacturers.d.ts → cjs/Manufacturers.d.ts} +0 -0
- /package/build/{devices → cjs/devices}/DeviceConfig.unit._test.d.ts +0 -0
- /package/build/{devices → cjs/devices}/shared.d.ts +0 -0
- /package/build/{utils_safe.d.ts → cjs/utils_safe.d.ts} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ZWaveLogContainer } from "@zwave-js/core";
|
|
2
|
-
import { type ManufacturersMap } from "./Manufacturers";
|
|
3
|
-
import { ConditionalDeviceConfig, type DeviceConfig, type DeviceConfigIndex, type FulltextDeviceConfigIndex } from "./devices/DeviceConfig";
|
|
2
|
+
import { type ManufacturersMap } from "./Manufacturers.js";
|
|
3
|
+
import { ConditionalDeviceConfig, type DeviceConfig, type DeviceConfigIndex, type FulltextDeviceConfigIndex } from "./devices/DeviceConfig.js";
|
|
4
4
|
export interface ConfigManagerOptions {
|
|
5
5
|
logContainer?: ZWaveLogContainer;
|
|
6
6
|
deviceConfigPriorityDir?: string;
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var ConfigManager_exports = {};
|
|
30
|
+
__export(ConfigManager_exports, {
|
|
31
|
+
ConfigManager: () => ConfigManager
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(ConfigManager_exports);
|
|
34
|
+
var import_core = require("@zwave-js/core");
|
|
35
|
+
var import_shared = require("@zwave-js/shared");
|
|
36
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
37
|
+
var import_Logger = require("./Logger.js");
|
|
38
|
+
var import_Manufacturers = require("./Manufacturers.js");
|
|
39
|
+
var import_version = require("./_version.js");
|
|
40
|
+
var import_DeviceConfig = require("./devices/DeviceConfig.js");
|
|
41
|
+
var import_utils = require("./utils.js");
|
|
42
|
+
class ConfigManager {
|
|
43
|
+
constructor(options = {}) {
|
|
44
|
+
this.logger = new import_Logger.ConfigLogger(options.logContainer ?? new import_core.ZWaveLogContainer({ enabled: false }));
|
|
45
|
+
this.deviceConfigPriorityDir = options.deviceConfigPriorityDir;
|
|
46
|
+
this._configVersion = import_version.PACKAGE_VERSION;
|
|
47
|
+
}
|
|
48
|
+
_configVersion;
|
|
49
|
+
get configVersion() {
|
|
50
|
+
return this._configVersion;
|
|
51
|
+
}
|
|
52
|
+
logger;
|
|
53
|
+
_manufacturers;
|
|
54
|
+
get manufacturers() {
|
|
55
|
+
if (!this._manufacturers) {
|
|
56
|
+
throw new import_core.ZWaveError("The config has not been loaded yet!", import_core.ZWaveErrorCodes.Driver_NotReady);
|
|
57
|
+
}
|
|
58
|
+
return this._manufacturers;
|
|
59
|
+
}
|
|
60
|
+
deviceConfigPriorityDir;
|
|
61
|
+
index;
|
|
62
|
+
fulltextIndex;
|
|
63
|
+
_useExternalConfig = false;
|
|
64
|
+
get useExternalConfig() {
|
|
65
|
+
return this._useExternalConfig;
|
|
66
|
+
}
|
|
67
|
+
async loadAll() {
|
|
68
|
+
const syncResult = await (0, import_utils.syncExternalConfigDir)(this.logger);
|
|
69
|
+
if (syncResult.success) {
|
|
70
|
+
this._useExternalConfig = true;
|
|
71
|
+
this.logger.print(`Using external configuration dir ${(0, import_utils.externalConfigDir)()}`);
|
|
72
|
+
this._configVersion = syncResult.version;
|
|
73
|
+
} else {
|
|
74
|
+
this._useExternalConfig = false;
|
|
75
|
+
this._configVersion = import_version.PACKAGE_VERSION;
|
|
76
|
+
}
|
|
77
|
+
this.logger.print(`version ${this._configVersion}`, "info");
|
|
78
|
+
await this.loadManufacturers();
|
|
79
|
+
await this.loadDeviceIndex();
|
|
80
|
+
}
|
|
81
|
+
async loadManufacturers() {
|
|
82
|
+
try {
|
|
83
|
+
this._manufacturers = await (0, import_Manufacturers.loadManufacturersInternal)(this._useExternalConfig);
|
|
84
|
+
} catch (e) {
|
|
85
|
+
if ((0, import_core.isZWaveError)(e) && e.code === import_core.ZWaveErrorCodes.Config_Invalid) {
|
|
86
|
+
if (process.env.NODE_ENV !== "test") {
|
|
87
|
+
this.logger.print(`Could not load manufacturers config: ${e.message}`, "error");
|
|
88
|
+
}
|
|
89
|
+
if (!this._manufacturers)
|
|
90
|
+
this._manufacturers = /* @__PURE__ */ new Map();
|
|
91
|
+
} else {
|
|
92
|
+
throw e;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async saveManufacturers() {
|
|
97
|
+
if (!this._manufacturers) {
|
|
98
|
+
throw new import_core.ZWaveError("The config has not been loaded yet!", import_core.ZWaveErrorCodes.Driver_NotReady);
|
|
99
|
+
}
|
|
100
|
+
await (0, import_Manufacturers.saveManufacturersInternal)(this._manufacturers);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Looks up the name of the manufacturer with the given ID in the configuration DB
|
|
104
|
+
* @param manufacturerId The manufacturer id to look up
|
|
105
|
+
*/
|
|
106
|
+
lookupManufacturer(manufacturerId) {
|
|
107
|
+
if (!this._manufacturers) {
|
|
108
|
+
throw new import_core.ZWaveError("The config has not been loaded yet!", import_core.ZWaveErrorCodes.Driver_NotReady);
|
|
109
|
+
}
|
|
110
|
+
return this._manufacturers.get(manufacturerId);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Add new manufacturers to configuration DB
|
|
114
|
+
* @param manufacturerId The manufacturer id to look up
|
|
115
|
+
* @param manufacturerName The manufacturer name
|
|
116
|
+
*/
|
|
117
|
+
setManufacturer(manufacturerId, manufacturerName) {
|
|
118
|
+
if (!this._manufacturers) {
|
|
119
|
+
throw new import_core.ZWaveError("The config has not been loaded yet!", import_core.ZWaveErrorCodes.Driver_NotReady);
|
|
120
|
+
}
|
|
121
|
+
this._manufacturers.set(manufacturerId, manufacturerName);
|
|
122
|
+
}
|
|
123
|
+
async loadDeviceIndex() {
|
|
124
|
+
try {
|
|
125
|
+
const embeddedIndex = await (0, import_DeviceConfig.loadDeviceIndexInternal)(this.logger, this._useExternalConfig);
|
|
126
|
+
const priorityIndex = [];
|
|
127
|
+
if (this.deviceConfigPriorityDir) {
|
|
128
|
+
if (await (0, import_shared.pathExists)(this.deviceConfigPriorityDir)) {
|
|
129
|
+
priorityIndex.push(...await (0, import_DeviceConfig.generatePriorityDeviceIndex)(this.deviceConfigPriorityDir, this.logger));
|
|
130
|
+
} else {
|
|
131
|
+
this.logger.print(`Priority device configuration directory ${this.deviceConfigPriorityDir} not found`, "warn");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
this.index = [...priorityIndex, ...embeddedIndex];
|
|
135
|
+
} catch (e) {
|
|
136
|
+
if (!(0, import_core.isZWaveError)(e) && e instanceof Error || (0, import_core.isZWaveError)(e) && e.code === import_core.ZWaveErrorCodes.Config_Invalid) {
|
|
137
|
+
if (!this.index)
|
|
138
|
+
this.index = [];
|
|
139
|
+
if (process.env.NODE_ENV !== "test") {
|
|
140
|
+
this.logger.print(`Could not load or regenerate device config index: ${e.message}`, "error");
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
throw e;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
getIndex() {
|
|
148
|
+
return this.index;
|
|
149
|
+
}
|
|
150
|
+
async loadFulltextDeviceIndex() {
|
|
151
|
+
this.fulltextIndex = await (0, import_DeviceConfig.loadFulltextDeviceIndexInternal)(this.logger);
|
|
152
|
+
}
|
|
153
|
+
getFulltextIndex() {
|
|
154
|
+
return this.fulltextIndex;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Looks up the definition of a given device in the configuration DB, but does not evaluate conditional settings.
|
|
158
|
+
* @param manufacturerId The manufacturer id of the device
|
|
159
|
+
* @param productType The product type of the device
|
|
160
|
+
* @param productId The product id of the device
|
|
161
|
+
* @param firmwareVersion If known, configuration for a specific firmware version can be loaded.
|
|
162
|
+
* If this is `undefined` or not given, the first matching file with a defined firmware range will be returned.
|
|
163
|
+
*/
|
|
164
|
+
async lookupDevicePreserveConditions(manufacturerId, productType, productId, firmwareVersion) {
|
|
165
|
+
if (!this.index)
|
|
166
|
+
await this.loadDeviceIndex();
|
|
167
|
+
const indexEntries = this.index.filter((0, import_utils.getDeviceEntryPredicate)(manufacturerId, productType, productId, firmwareVersion));
|
|
168
|
+
const indexEntry = indexEntries.find((e) => !!e.preferred) ?? indexEntries[0];
|
|
169
|
+
if (indexEntry) {
|
|
170
|
+
const devicesDir = (0, import_DeviceConfig.getDevicesPaths)(this._useExternalConfig ? (0, import_utils.externalConfigDir)() : import_utils.configDir).devicesDir;
|
|
171
|
+
const filePath = import_node_path.default.isAbsolute(indexEntry.filename) ? indexEntry.filename : import_node_path.default.join(devicesDir, indexEntry.filename);
|
|
172
|
+
if (!await (0, import_shared.pathExists)(filePath))
|
|
173
|
+
return;
|
|
174
|
+
const isEmbedded = !import_node_path.default.relative(devicesDir, filePath).startsWith("..");
|
|
175
|
+
const rootDir = indexEntry.rootDir ?? devicesDir;
|
|
176
|
+
const fallbackDirs = rootDir === devicesDir ? void 0 : [devicesDir];
|
|
177
|
+
try {
|
|
178
|
+
return await import_DeviceConfig.ConditionalDeviceConfig.from(filePath, isEmbedded, { rootDir, fallbackDirs });
|
|
179
|
+
} catch (e) {
|
|
180
|
+
if (process.env.NODE_ENV !== "test") {
|
|
181
|
+
this.logger.print(`Error loading device config ${filePath}: ${(0, import_shared.getErrorMessage)(e, true)}`, "error");
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Looks up the definition of a given device in the configuration DB
|
|
188
|
+
* @param manufacturerId The manufacturer id of the device
|
|
189
|
+
* @param productType The product type of the device
|
|
190
|
+
* @param productId The product id of the device
|
|
191
|
+
* @param firmwareVersion If known, configuration for a specific firmware version can be loaded.
|
|
192
|
+
* If this is `undefined` or not given, the first matching file with a defined firmware range will be returned.
|
|
193
|
+
*/
|
|
194
|
+
async lookupDevice(manufacturerId, productType, productId, firmwareVersion) {
|
|
195
|
+
const ret = await this.lookupDevicePreserveConditions(manufacturerId, productType, productId, firmwareVersion);
|
|
196
|
+
return ret?.evaluate({
|
|
197
|
+
manufacturerId,
|
|
198
|
+
productType,
|
|
199
|
+
productId,
|
|
200
|
+
firmwareVersion
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
205
|
+
0 && (module.exports = {
|
|
206
|
+
ConfigManager
|
|
207
|
+
});
|
|
208
|
+
//# sourceMappingURL=ConfigManager.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/ConfigManager.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n\tZWaveError,\n\tZWaveErrorCodes,\n\tZWaveLogContainer,\n\tisZWaveError,\n} from \"@zwave-js/core\";\nimport { getErrorMessage, pathExists } from \"@zwave-js/shared\";\nimport path from \"node:path\";\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\tconfigDir,\n\texternalConfigDir,\n\tgetDeviceEntryPredicate,\n\tsyncExternalConfigDir,\n} from \"./utils.js\";\n\nexport interface ConfigManagerOptions {\n\tlogContainer?: ZWaveLogContainer;\n\tdeviceConfigPriorityDir?: string;\n}\n\nexport class ConfigManager {\n\tpublic constructor(options: ConfigManagerOptions = {}) {\n\t\tthis.logger = new ConfigLogger(\n\t\t\toptions.logContainer ?? new ZWaveLogContainer({ enabled: false }),\n\t\t);\n\t\tthis.deviceConfigPriorityDir = options.deviceConfigPriorityDir;\n\t\tthis._configVersion = PACKAGE_VERSION;\n\t}\n\n\tprivate _configVersion: string;\n\tpublic get configVersion(): string {\n\t\treturn this._configVersion;\n\t}\n\n\tprivate logger: ConfigLogger;\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 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\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\tconst syncResult = await syncExternalConfigDir(this.logger);\n\t\tif (syncResult.success) {\n\t\t\tthis._useExternalConfig = true;\n\t\t\tthis.logger.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\tthis.logger.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\tthis._useExternalConfig,\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\tthis.logger.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(this._manufacturers);\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\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\tthis.logger,\n\t\t\t\tthis._useExternalConfig,\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(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\tthis.deviceConfigPriorityDir,\n\t\t\t\t\t\t\tthis.logger,\n\t\t\t\t\t\t)),\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tthis.logger.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\tthis.logger.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(this.logger);\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\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 ? 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(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\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\tthis.logger.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
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,kBAKO;AACP,oBAA4C;AAC5C,uBAAiB;AACjB,oBAA6B;AAC7B,2BAIO;AAC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E;EAEO,mBAAgB;AACtB,WAAO,KAAK;EACb;;;;;;;;;EAUO,MAAM,+BACZ,gBACA,aACA,WACA,iBAAwB;AAGxB,QAAI,CAAC,KAAK;AAAO,YAAM,KAAK,gBAAe;AAG3C,UAAM,eAAe,KAAK,MAAO,WAChC,sCACC,gBACA,aACA,WACA,eAAe,CACf;AAGF,UAAM,aAAa,aAAa,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,KACrD,aAAa,CAAC;AAElB,QAAI,YAAY;AACf,YAAM,iBAAa,qCAClB,KAAK,yBAAqB,gCAAiB,IAAM,sBAAS,EACzD;AACF,YAAM,WAAW,iBAAAA,QAAK,WAAW,WAAW,QAAQ,IACjD,WAAW,WACX,iBAAAA,QAAK,KAAK,YAAY,WAAW,QAAQ;AAC5C,UAAI,CAAE,UAAM,0BAAW,QAAQ;AAAI;AAInC,YAAM,aAAa,CAAC,iBAAAA,QAClB,SAAS,YAAY,QAAQ,EAC7B,WAAW,IAAI;AAIjB,YAAM,UAAU,WAAW,WAAW;AACtC,YAAM,eAAe,YAAY,aAC9B,SACA,CAAC,UAAU;AAEd,UAAI;AACH,eAAO,MAAM,4CAAwB,KACpC,UACA,YACA,EAAE,SAAS,aAAY,CAAE;MAE3B,SAAS,GAAG;AACX,YAAI,QAAQ,IAAI,aAAa,QAAQ;AACpC,eAAK,OAAO,MACX,+BAA+B,QAAQ,SACtC,+BACC,GACA,IAAI,CAEN,IACA,OAAO;QAET;MACD;IACD;EACD;;;;;;;;;EAUO,MAAM,aACZ,gBACA,aACA,WACA,iBAAwB;AAExB,UAAM,MAAM,MAAM,KAAK,+BACtB,gBACA,aACA,WACA,eAAe;AAEhB,WAAO,KAAK,SAAS;MACpB;MACA;MACA;MACA;KACA;EACF;;",
|
|
6
|
+
"names": ["path"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var JsonTemplate_exports = {};
|
|
30
|
+
__export(JsonTemplate_exports, {
|
|
31
|
+
clearTemplateCache: () => clearTemplateCache,
|
|
32
|
+
readJsonWithTemplate: () => readJsonWithTemplate
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(JsonTemplate_exports);
|
|
35
|
+
var import_safe = require("@zwave-js/core/safe");
|
|
36
|
+
var import_shared = require("@zwave-js/shared");
|
|
37
|
+
var import_safe2 = require("@zwave-js/shared/safe");
|
|
38
|
+
var import_typeguards = require("alcalzone-shared/typeguards/index.js");
|
|
39
|
+
var import_json5 = __toESM(require("json5"), 1);
|
|
40
|
+
var import_promises = __toESM(require("node:fs/promises"), 1);
|
|
41
|
+
var path = __toESM(require("node:path"), 1);
|
|
42
|
+
const IMPORT_KEY = "$import";
|
|
43
|
+
const importSpecifierRegex = /^(?<filename>(?:~\/)?[\w\d\/\\\._-]+\.json)?(?:#(?<selector>[\w\d\/\._-]+(?:\[0x[0-9a-fA-F]+\])?))?$/i;
|
|
44
|
+
const templateCache = /* @__PURE__ */ new Map();
|
|
45
|
+
function clearTemplateCache() {
|
|
46
|
+
templateCache.clear();
|
|
47
|
+
}
|
|
48
|
+
async function readJsonWithTemplate(filename, rootDirs) {
|
|
49
|
+
if (!await (0, import_shared.pathExists)(filename)) {
|
|
50
|
+
throw new import_safe.ZWaveError(`Could not open config file ${filename}: not found!`, import_safe.ZWaveErrorCodes.Config_NotFound);
|
|
51
|
+
}
|
|
52
|
+
if (typeof rootDirs === "string")
|
|
53
|
+
rootDirs = [rootDirs];
|
|
54
|
+
const fileCache = new Map(templateCache);
|
|
55
|
+
const ret = await readJsonWithTemplateInternal(filename, void 0, [], fileCache, rootDirs);
|
|
56
|
+
for (const [filename2, cached] of fileCache) {
|
|
57
|
+
if (/[\\/]templates[\\/]/.test(filename2)) {
|
|
58
|
+
templateCache.set(filename2, cached);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return ret;
|
|
62
|
+
}
|
|
63
|
+
function assertImportSpecifier(val, source) {
|
|
64
|
+
if (typeof val !== "string") {
|
|
65
|
+
throw new import_safe.ZWaveError(`Invalid import specifier ${String(val)}!${source != void 0 ? ` Source: ${source}` : ""}`, import_safe.ZWaveErrorCodes.Config_Invalid);
|
|
66
|
+
}
|
|
67
|
+
if (!importSpecifierRegex.test(val)) {
|
|
68
|
+
throw new import_safe.ZWaveError(`Import specifier "${val}" is invalid!${source != void 0 ? ` Source: ${source}` : ""}`, import_safe.ZWaveErrorCodes.Config_Invalid);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function getImportSpecifier(filename, selector) {
|
|
72
|
+
let ret = filename;
|
|
73
|
+
if (selector)
|
|
74
|
+
ret += `#${selector}`;
|
|
75
|
+
return ret;
|
|
76
|
+
}
|
|
77
|
+
function select(obj, selector) {
|
|
78
|
+
let ret = obj;
|
|
79
|
+
const selectorParts = selector.split("/").filter((s) => !!s);
|
|
80
|
+
for (const part of selectorParts) {
|
|
81
|
+
if ((0, import_typeguards.isArray)(ret)) {
|
|
82
|
+
const item = ret.find((r) => (0, import_typeguards.isObject)(r) && "#" in r && r["#"] === part);
|
|
83
|
+
if (item != void 0) {
|
|
84
|
+
const { ["#"]: _, ...rest } = item;
|
|
85
|
+
ret = rest;
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
ret = ret[part];
|
|
90
|
+
}
|
|
91
|
+
if (!(0, import_typeguards.isObject)(ret)) {
|
|
92
|
+
throw new import_safe.ZWaveError(`The import target "${selector}" is not an object!`, import_safe.ZWaveErrorCodes.Config_Invalid);
|
|
93
|
+
}
|
|
94
|
+
return ret;
|
|
95
|
+
}
|
|
96
|
+
function getImportStack(visited, selector) {
|
|
97
|
+
const source = [...visited, selector ? `#${selector}` : void 0].reverse().filter((s) => !!s);
|
|
98
|
+
if (source.length > 0) {
|
|
99
|
+
return `
|
|
100
|
+
Import stack: ${source.map((s) => `
|
|
101
|
+
in ${s}`).join("")}`;
|
|
102
|
+
}
|
|
103
|
+
return "";
|
|
104
|
+
}
|
|
105
|
+
async function readJsonWithTemplateInternal(filename, selector, visited, fileCache, rootDirs) {
|
|
106
|
+
filename = path.normalize(filename);
|
|
107
|
+
if (rootDirs) {
|
|
108
|
+
const outsideAllRootDirs = rootDirs.every((rootDir) => {
|
|
109
|
+
const relativeToRoot = path.relative(rootDir, filename);
|
|
110
|
+
return relativeToRoot.startsWith("..");
|
|
111
|
+
});
|
|
112
|
+
if (outsideAllRootDirs) {
|
|
113
|
+
throw new import_safe.ZWaveError(`Tried to import config file "${filename}" from outside all root directories: ${rootDirs.map((d) => `
|
|
114
|
+
\xB7 ${d}`).join("")}
|
|
115
|
+
${getImportStack(visited, selector)}`, import_safe.ZWaveErrorCodes.Config_Invalid);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const specifier = getImportSpecifier(filename, selector);
|
|
119
|
+
if (visited.includes(specifier)) {
|
|
120
|
+
const msg = `Circular $import in config files: ${[
|
|
121
|
+
...visited,
|
|
122
|
+
specifier
|
|
123
|
+
].join(" -> ")}
|
|
124
|
+
`;
|
|
125
|
+
throw new import_safe.ZWaveError(msg, import_safe.ZWaveErrorCodes.Config_CircularImport);
|
|
126
|
+
}
|
|
127
|
+
let json;
|
|
128
|
+
if (fileCache.has(filename)) {
|
|
129
|
+
json = fileCache.get(filename);
|
|
130
|
+
} else {
|
|
131
|
+
try {
|
|
132
|
+
const fileContent = await import_promises.default.readFile(filename, "utf8");
|
|
133
|
+
json = import_json5.default.parse(fileContent);
|
|
134
|
+
fileCache.set(filename, json);
|
|
135
|
+
} catch (e) {
|
|
136
|
+
throw new import_safe.ZWaveError(`Could not parse config file ${filename}: ${(0, import_safe2.getErrorMessage)(e)}${getImportStack(visited, selector)}`, import_safe.ZWaveErrorCodes.Config_Invalid);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return resolveJsonImports(selector ? select(json, selector) : json, filename, [...visited, specifier], fileCache, rootDirs);
|
|
140
|
+
}
|
|
141
|
+
async function resolveJsonImports(json, filename, visited, fileCache, rootDirs) {
|
|
142
|
+
const ret = {};
|
|
143
|
+
for (const [prop, val] of Object.entries(json)) {
|
|
144
|
+
if (prop === IMPORT_KEY) {
|
|
145
|
+
assertImportSpecifier(val, visited.join(" -> "));
|
|
146
|
+
const { filename: importFilename, selector } = importSpecifierRegex.exec(val).groups;
|
|
147
|
+
let newFilename;
|
|
148
|
+
if (importFilename) {
|
|
149
|
+
if (importFilename.startsWith("~/")) {
|
|
150
|
+
if (rootDirs) {
|
|
151
|
+
for (const rootDir of rootDirs) {
|
|
152
|
+
newFilename = path.join(rootDir, importFilename.slice(2));
|
|
153
|
+
if (await (0, import_shared.pathExists)(newFilename)) {
|
|
154
|
+
break;
|
|
155
|
+
} else {
|
|
156
|
+
newFilename = void 0;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (!newFilename) {
|
|
160
|
+
throw new import_safe.ZWaveError(`Could not find the referenced file ${importFilename.slice(2)} in any of the root directories: ${rootDirs.map((d) => `
|
|
161
|
+
\xB7 ${d}`).join("")}
|
|
162
|
+
${getImportStack(visited, selector)}`, import_safe.ZWaveErrorCodes.Config_Invalid);
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
throw new import_safe.ZWaveError(`An $import specifier cannot start with ~/ when no root directory is defined!${getImportStack(visited, selector)}`, import_safe.ZWaveErrorCodes.Config_Invalid);
|
|
166
|
+
}
|
|
167
|
+
} else {
|
|
168
|
+
newFilename = path.join(path.dirname(filename), importFilename);
|
|
169
|
+
}
|
|
170
|
+
} else {
|
|
171
|
+
newFilename = filename;
|
|
172
|
+
}
|
|
173
|
+
const imported = await readJsonWithTemplateInternal(newFilename, selector, visited, fileCache, rootDirs);
|
|
174
|
+
Object.assign(ret, imported);
|
|
175
|
+
} else if ((0, import_typeguards.isObject)(val)) {
|
|
176
|
+
ret[prop] = await resolveJsonImports(val, filename, visited, fileCache, rootDirs);
|
|
177
|
+
} else if ((0, import_typeguards.isArray)(val)) {
|
|
178
|
+
const vals = [];
|
|
179
|
+
for (const v of val) {
|
|
180
|
+
if ((0, import_typeguards.isObject)(v)) {
|
|
181
|
+
vals.push(await resolveJsonImports(v, filename, visited, fileCache, rootDirs));
|
|
182
|
+
} else {
|
|
183
|
+
vals.push(v);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
ret[prop] = vals;
|
|
187
|
+
} else {
|
|
188
|
+
ret[prop] = val;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return ret;
|
|
192
|
+
}
|
|
193
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
194
|
+
0 && (module.exports = {
|
|
195
|
+
clearTemplateCache,
|
|
196
|
+
readJsonWithTemplate
|
|
197
|
+
});
|
|
198
|
+
//# sourceMappingURL=JsonTemplate.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/JsonTemplate.ts"],
|
|
4
|
+
"sourcesContent": ["import { ZWaveError, ZWaveErrorCodes } from \"@zwave-js/core/safe\";\nimport { pathExists } from \"@zwave-js/shared\";\nimport { getErrorMessage } from \"@zwave-js/shared/safe\";\nimport { isArray, isObject } from \"alcalzone-shared/typeguards/index.js\";\nimport JSON5 from \"json5\";\nimport fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\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\tfilename: string,\n\trootDirs?: string | string[],\n): Promise<Record<string, unknown>> {\n\tif (!(await pathExists(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\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.find(\n\t\t\t\t(r) => 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 as any;\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\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 fs.readFile(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\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\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(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\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\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\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,oBAA2B;AAC3B,IAAAA,eAAgC;AAChC,wBAAkC;AAClC,mBAAkB;AAClB,sBAAe;AACf,WAAsB;AAEtB,MAAM,aAAa;AACnB,MAAM,uBACL;AAOD,MAAM,gBAA2B,oBAAI,IAAG;AAClC,SAAU,qBAAkB;AACjC,gBAAc,MAAK;AACpB;AAGA,eAAsB,qBACrB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AEhB;MACD,OAAO;AACN,sBAAc;MACf;AAGA,YAAM,WAAW,MAAM,6BACtB,aACA,UACA,SACA,WACA,QAAQ;AAET,aAAO,OAAO,KAAK,QAAQ;IAC5B,eAAW,4BAAS,GAAG,GAAG;AAEzB,UAAI,IAAI,IAAI,MAAM,mBACjB,KACA,UACA,SACA,WACA,QAAQ;IAEV,eAAW,2BAAQ,GAAG,GAAG;AAExB,YAAM,OAAkB,CAAA;AACxB,iBAAW,KAAK,KAAK;AACpB,gBAAI,4BAAS,CAAC,GAAG;AAChB,eAAK,KACJ,MAAM,mBACL,GACA,UACA,SACA,WACA,QAAQ,CACR;QAEH,OAAO;AACN,eAAK,KAAK,CAAC;QACZ;MACD;AACA,UAAI,IAAI,IAAI;IACb,OAAO;AACN,UAAI,IAAI,IAAI;IACb;EACD;AACA,SAAO;AACR;",
|
|
6
|
+
"names": ["import_safe", "filename", "fs", "JSON5"]
|
|
7
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ZWaveLogContainer, ZWaveLoggerBase } from "@zwave-js/core";
|
|
2
|
-
import { type ConfigLogContext } from "./Logger_safe";
|
|
2
|
+
import { type ConfigLogContext } from "./Logger_safe.js";
|
|
3
3
|
export declare class ConfigLogger extends ZWaveLoggerBase<ConfigLogContext> {
|
|
4
4
|
constructor(loggers: ZWaveLogContainer);
|
|
5
5
|
/**
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var Logger_exports = {};
|
|
20
|
+
__export(Logger_exports, {
|
|
21
|
+
ConfigLogger: () => ConfigLogger
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(Logger_exports);
|
|
24
|
+
var import_core = require("@zwave-js/core");
|
|
25
|
+
var import_Logger_safe = require("./Logger_safe.js");
|
|
26
|
+
class ConfigLogger extends import_core.ZWaveLoggerBase {
|
|
27
|
+
constructor(loggers) {
|
|
28
|
+
super(loggers, import_Logger_safe.CONFIG_LABEL);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Logs a message
|
|
32
|
+
* @param msg The message to output
|
|
33
|
+
*/
|
|
34
|
+
print(message, level) {
|
|
35
|
+
const actualLevel = level || import_Logger_safe.CONFIG_LOGLEVEL;
|
|
36
|
+
if (!this.container.isLoglevelVisible(actualLevel))
|
|
37
|
+
return;
|
|
38
|
+
this.logger.log({
|
|
39
|
+
level: actualLevel,
|
|
40
|
+
message,
|
|
41
|
+
direction: (0, import_core.getDirectionPrefix)("none"),
|
|
42
|
+
context: { source: "config" }
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
ConfigLogger
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=Logger.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Logger.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n\ttype ZWaveLogContainer,\n\tZWaveLoggerBase,\n\tgetDirectionPrefix,\n} from \"@zwave-js/core\";\nimport {\n\tCONFIG_LABEL,\n\tCONFIG_LOGLEVEL,\n\ttype ConfigLogContext,\n} from \"./Logger_safe.js\";\n\nexport class ConfigLogger extends ZWaveLoggerBase<ConfigLogContext> {\n\tconstructor(loggers: ZWaveLogContainer) {\n\t\tsuper(loggers, CONFIG_LABEL);\n\t}\n\n\t/**\n\t * Logs a message\n\t * @param msg The message to output\n\t */\n\tpublic print(\n\t\tmessage: string,\n\t\tlevel?: \"debug\" | \"verbose\" | \"warn\" | \"error\" | \"info\",\n\t): void {\n\t\tconst actualLevel = level || CONFIG_LOGLEVEL;\n\t\tif (!this.container.isLoglevelVisible(actualLevel)) return;\n\n\t\tthis.logger.log({\n\t\t\tlevel: actualLevel,\n\t\t\tmessage,\n\t\t\tdirection: getDirectionPrefix(\"none\"),\n\t\t\tcontext: { source: \"config\" },\n\t\t});\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,kBAIO;AACP,yBAIO;AAED,MAAO,qBAAqB,4BAAiC;EAClE,YAAY,SAA0B;AACrC,UAAM,SAAS,+BAAY;EAC5B;;;;;EAMO,MACN,SACA,OAAuD;AAEvD,UAAM,cAAc,SAAS;AAC7B,QAAI,CAAC,KAAK,UAAU,kBAAkB,WAAW;AAAG;AAEpD,SAAK,OAAO,IAAI;MACf,OAAO;MACP;MACA,eAAW,gCAAmB,MAAM;MACpC,SAAS,EAAE,QAAQ,SAAQ;KAC3B;EACF;;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var Logger_safe_exports = {};
|
|
20
|
+
__export(Logger_safe_exports, {
|
|
21
|
+
CONFIG_LABEL: () => CONFIG_LABEL,
|
|
22
|
+
CONFIG_LOGLEVEL: () => CONFIG_LOGLEVEL
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(Logger_safe_exports);
|
|
25
|
+
const CONFIG_LABEL = "CONFIG";
|
|
26
|
+
const CONFIG_LOGLEVEL = "debug";
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
CONFIG_LABEL,
|
|
30
|
+
CONFIG_LOGLEVEL
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=Logger_safe.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Logger_safe.ts"],
|
|
4
|
+
"sourcesContent": ["import type { LogContext } from \"@zwave-js/core/safe\";\n\nexport const CONFIG_LABEL = \"CONFIG\";\nexport const CONFIG_LOGLEVEL = \"debug\";\n\nexport type ConfigLogContext = LogContext<\"config\">;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAEA;;;;;;AAAO,MAAM,eAAe;AACrB,MAAM,kBAAkB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|