@iobroker/js-controller-adapter 5.0.19 → 5.0.20-alpha.0-20240131-ea40ee4f
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/lib/adapter/adapter.d.ts +12 -4
- package/build/lib/adapter/adapter.d.ts.map +1 -1
- package/build/lib/adapter/adapter.js +533 -510
- package/build/lib/adapter/adapter.js.map +1 -1
- package/build/lib/adapter/log.js +4 -0
- package/build/lib/adapter/log.js.map +1 -1
- package/build/lib/adapter/userInterfaceMessagingController.js +10 -4
- package/build/lib/adapter/userInterfaceMessagingController.js.map +1 -1
- package/build/lib/adapter/utils.d.ts +1 -1
- package/build/lib/adapter/utils.d.ts.map +1 -1
- package/build/lib/adapter/utils.js.map +1 -1
- package/build/lib/adapter/validator.js +7 -2
- package/build/lib/adapter/validator.js.map +1 -1
- package/package.json +57 -57
|
@@ -1,42 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
26
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
27
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
28
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
29
|
-
};
|
|
30
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
31
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
32
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
33
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
34
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
35
|
-
};
|
|
36
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
4
|
};
|
|
39
|
-
var _AdapterClass_states, _AdapterClass_objects;
|
|
40
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
6
|
exports.Adapter = exports.AdapterClass = void 0;
|
|
42
7
|
const node_net_1 = __importDefault(require("node:net"));
|
|
@@ -59,7 +24,7 @@ const package_json_1 = require("@iobroker/js-controller-adapter/package.json");
|
|
|
59
24
|
const log_1 = require("../../lib/adapter/log");
|
|
60
25
|
const validator_1 = require("./validator");
|
|
61
26
|
const { FORBIDDEN_CHARS } = js_controller_common_1.tools;
|
|
62
|
-
const constants_1 = require("
|
|
27
|
+
const constants_1 = require("../../lib/adapter/constants");
|
|
63
28
|
const userInterfaceMessagingController_1 = require("../../lib/adapter/userInterfaceMessagingController");
|
|
64
29
|
const constants_2 = require("@iobroker/js-controller-common/constants");
|
|
65
30
|
js_controller_common_1.tools.ensureDNSOrder();
|
|
@@ -71,51 +36,134 @@ js_controller_common_1.tools.ensureDNSOrder();
|
|
|
71
36
|
*
|
|
72
37
|
*/
|
|
73
38
|
class AdapterClass extends node_events_1.EventEmitter {
|
|
39
|
+
/** Instance to access states DB */
|
|
40
|
+
#states;
|
|
41
|
+
/** Instance to access objects DB */
|
|
42
|
+
#objects;
|
|
43
|
+
/** States DB constructor */
|
|
44
|
+
States;
|
|
45
|
+
/** Objects DB constructor */
|
|
46
|
+
Objects;
|
|
47
|
+
/** Contents of iobroker.json */
|
|
48
|
+
_config;
|
|
49
|
+
_options;
|
|
50
|
+
startedInCompactMode;
|
|
51
|
+
/** List of instances which want our logs */
|
|
52
|
+
logList = new Set();
|
|
53
|
+
aliases = new Map();
|
|
54
|
+
aliasPatterns = new Set();
|
|
55
|
+
enums = {};
|
|
56
|
+
eventLoopLags = [];
|
|
57
|
+
overwriteLogLevel = false;
|
|
58
|
+
adapterReady = false;
|
|
59
|
+
/** Callbacks from sendTo */
|
|
60
|
+
messageCallbacks = new Map();
|
|
61
|
+
/**
|
|
62
|
+
* Contains a live cache of the adapter's states.
|
|
63
|
+
* NOTE: This is only defined if the adapter was initialized with the option states: true.
|
|
64
|
+
*/
|
|
65
|
+
oStates;
|
|
66
|
+
/**
|
|
67
|
+
* Contains a live cache of the adapter's objects.
|
|
68
|
+
* NOTE: This is only defined if the adapter was initialized with the option objects: true.
|
|
69
|
+
*/
|
|
70
|
+
oObjects;
|
|
71
|
+
_stopInProgress = false;
|
|
72
|
+
_callbackId = 1;
|
|
73
|
+
_firstConnection = true;
|
|
74
|
+
_timers = new Set();
|
|
75
|
+
_intervals = new Set();
|
|
76
|
+
_delays = new Set();
|
|
77
|
+
/** For ease of use the log property is always defined, however it is only available after `ready` has been called. */
|
|
78
|
+
log;
|
|
79
|
+
performStrictObjectChecks;
|
|
80
|
+
_logger;
|
|
81
|
+
_restartScheduleJob;
|
|
82
|
+
_schedule;
|
|
83
|
+
namespaceLog;
|
|
84
|
+
namespace;
|
|
85
|
+
name;
|
|
86
|
+
_systemSecret;
|
|
87
|
+
/** Whether the adapter has already terminated */
|
|
88
|
+
terminated = false;
|
|
89
|
+
/** The cache of usernames */
|
|
90
|
+
usernames = {};
|
|
91
|
+
/** A RegExp to test for forbidden chars in object IDs */
|
|
92
|
+
FORBIDDEN_CHARS = FORBIDDEN_CHARS;
|
|
93
|
+
inputCount = 0;
|
|
94
|
+
outputCount = 0;
|
|
95
|
+
/** The cache of users */
|
|
96
|
+
users = {}; // todo
|
|
97
|
+
/** The cache of user groups */
|
|
98
|
+
groups = {};
|
|
99
|
+
/** An array of instances, that support auto subscribe */
|
|
100
|
+
autoSubscribe = [];
|
|
101
|
+
defaultHistory = null;
|
|
102
|
+
pluginHandler;
|
|
103
|
+
_reportInterval;
|
|
104
|
+
getPortRunning = null;
|
|
105
|
+
_namespaceRegExp;
|
|
106
|
+
instance;
|
|
107
|
+
// @ts-expect-error decide how to handle it
|
|
108
|
+
_utils;
|
|
109
|
+
/** contents of io-package.json */
|
|
110
|
+
adapterConfig;
|
|
111
|
+
connected;
|
|
112
|
+
adapterDir;
|
|
113
|
+
/** contents of package.json */
|
|
114
|
+
pack;
|
|
115
|
+
/** contents of io-package.json */
|
|
116
|
+
ioPack; // contents of io-package.json TODO difference to adapterConfig?
|
|
117
|
+
_initializeTimeout;
|
|
118
|
+
inited;
|
|
119
|
+
/** contents of iobroker.json if required via AdapterOptions */
|
|
120
|
+
systemConfig;
|
|
121
|
+
/** the configured date format of system.config, only available if requested via AdapterOptions `useFormatDate` */
|
|
122
|
+
dateFormat;
|
|
123
|
+
/** if float comma instead of dot is used, only available if requested via AdapterOptions `useFormatDate` */
|
|
124
|
+
isFloatComma;
|
|
125
|
+
/** configured language of system.config, only available if requested via AdapterOptions `useFormatDate` */
|
|
126
|
+
language;
|
|
127
|
+
/** longitude configured in system.config, only available if requested via AdapterOptions `useFormatDate`*/
|
|
128
|
+
longitude;
|
|
129
|
+
/** latitude configured in system.config, only available if requested via AdapterOptions `useFormatDate`*/
|
|
130
|
+
latitude;
|
|
131
|
+
_defaultObjs;
|
|
132
|
+
_aliasObjectsSubscribed;
|
|
133
|
+
config = {};
|
|
134
|
+
host;
|
|
135
|
+
common;
|
|
136
|
+
mboxSubscribed;
|
|
137
|
+
/** Stop the adapter */
|
|
138
|
+
stop;
|
|
139
|
+
version;
|
|
140
|
+
/** Stop the adapter only defined in compact, not for external usage */
|
|
141
|
+
kill;
|
|
142
|
+
processLog;
|
|
143
|
+
/**
|
|
144
|
+
* Start or stop subscribing to log messages
|
|
145
|
+
* The method is only available if logTransporter is active via io-pack or adapter options
|
|
146
|
+
* Note, that stopping will stop after 10 seconds, not immediately
|
|
147
|
+
*
|
|
148
|
+
* @param isActive - if log subscription should be activated or deactivated
|
|
149
|
+
* @param options - options passed to setState e.g. user permissions
|
|
150
|
+
*/
|
|
151
|
+
requireLog;
|
|
152
|
+
logOffTimer;
|
|
153
|
+
logRedirect;
|
|
154
|
+
logRequired;
|
|
155
|
+
patterns;
|
|
156
|
+
statesConnectedTime;
|
|
157
|
+
/** Constants for frequent use in adapters */
|
|
158
|
+
constants = {
|
|
159
|
+
STATE_QUALITY: constants_1.STATE_QUALITY
|
|
160
|
+
};
|
|
161
|
+
/** Features supported by the running instance */
|
|
162
|
+
SUPPORTED_FEATURES = (0, utils_1.getSupportedFeatures)();
|
|
163
|
+
/** Controller for messaging related functionality */
|
|
164
|
+
uiMessagingController;
|
|
74
165
|
constructor(options) {
|
|
75
166
|
super();
|
|
76
|
-
/** Instance to access states DB */
|
|
77
|
-
_AdapterClass_states.set(this, void 0);
|
|
78
|
-
/** Instance to access objects DB */
|
|
79
|
-
_AdapterClass_objects.set(this, void 0);
|
|
80
|
-
/** List of instances which want our logs */
|
|
81
|
-
this.logList = new Set();
|
|
82
|
-
this.aliases = new Map();
|
|
83
|
-
this.aliasPatterns = new Set();
|
|
84
|
-
this.enums = {};
|
|
85
|
-
this.eventLoopLags = [];
|
|
86
|
-
this.overwriteLogLevel = false;
|
|
87
|
-
this.adapterReady = false;
|
|
88
|
-
/** Callbacks from sendTo */
|
|
89
|
-
this.messageCallbacks = new Map();
|
|
90
|
-
this._stopInProgress = false;
|
|
91
|
-
this._callbackId = 1;
|
|
92
|
-
this._firstConnection = true;
|
|
93
|
-
this._timers = new Set();
|
|
94
|
-
this._intervals = new Set();
|
|
95
|
-
this._delays = new Set();
|
|
96
|
-
/** Whether the adapter has already terminated */
|
|
97
|
-
this.terminated = false;
|
|
98
|
-
/** The cache of usernames */
|
|
99
|
-
this.usernames = {};
|
|
100
|
-
/** A RegExp to test for forbidden chars in object IDs */
|
|
101
|
-
this.FORBIDDEN_CHARS = FORBIDDEN_CHARS;
|
|
102
|
-
this.inputCount = 0;
|
|
103
|
-
this.outputCount = 0;
|
|
104
|
-
/** The cache of users */
|
|
105
|
-
this.users = {}; // todo
|
|
106
|
-
/** The cache of user groups */
|
|
107
|
-
this.groups = {};
|
|
108
|
-
/** An array of instances, that support auto subscribe */
|
|
109
|
-
this.autoSubscribe = [];
|
|
110
|
-
this.defaultHistory = null;
|
|
111
|
-
this.getPortRunning = null;
|
|
112
|
-
this.config = {};
|
|
113
|
-
/** Constants for frequent use in adapters */
|
|
114
|
-
this.constants = {
|
|
115
|
-
STATE_QUALITY: constants_1.STATE_QUALITY
|
|
116
|
-
};
|
|
117
|
-
/** Features supported by the running instance */
|
|
118
|
-
this.SUPPORTED_FEATURES = (0, utils_1.getSupportedFeatures)();
|
|
119
167
|
// enable "const adapter = require(__dirname + '/../../lib/adapter.js')('adapterName');" call
|
|
120
168
|
if (typeof options === 'string') {
|
|
121
169
|
this._options = { name: options };
|
|
@@ -583,12 +631,12 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
583
631
|
}
|
|
584
632
|
// actual implementation
|
|
585
633
|
_getSession(options) {
|
|
586
|
-
if (!
|
|
634
|
+
if (!this.#states) {
|
|
587
635
|
// if states is no longer existing, we do not need to unsubscribe
|
|
588
636
|
this._logger.info(`${this.namespaceLog} getSession not processed because States database not connected`);
|
|
589
637
|
return js_controller_common_1.tools.maybeCallbackWithError(options.callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
590
638
|
}
|
|
591
|
-
|
|
639
|
+
this.#states.getSession(options.id, options.callback);
|
|
592
640
|
}
|
|
593
641
|
// unknown implementation guards
|
|
594
642
|
setSession(id, ttl, data, callback) {
|
|
@@ -600,12 +648,12 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
600
648
|
}
|
|
601
649
|
// actual implementation
|
|
602
650
|
_setSession(options) {
|
|
603
|
-
if (!
|
|
651
|
+
if (!this.#states) {
|
|
604
652
|
// if states is no longer existing, we do not need to unsubscribe
|
|
605
653
|
this._logger.info(`${this.namespaceLog} setSession not processed because States database not connected`);
|
|
606
654
|
return js_controller_common_1.tools.maybeCallbackWithError(options.callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
607
655
|
}
|
|
608
|
-
|
|
656
|
+
this.#states.setSession(options.id, options.ttl, options.data, options.callback);
|
|
609
657
|
}
|
|
610
658
|
destroySession(id, callback) {
|
|
611
659
|
validator_1.Validator.assertString(id, 'id');
|
|
@@ -613,16 +661,16 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
613
661
|
return this._destroySession({ id, callback });
|
|
614
662
|
}
|
|
615
663
|
_destroySession(options) {
|
|
616
|
-
if (!
|
|
664
|
+
if (!this.#states) {
|
|
617
665
|
// if states is no longer existing, we do not need to unsubscribe
|
|
618
666
|
this._logger.info(`${this.namespaceLog} destroySession not processed because States database not connected`);
|
|
619
667
|
return js_controller_common_1.tools.maybeCallbackWithError(options.callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
620
668
|
}
|
|
621
|
-
|
|
669
|
+
this.#states.destroySession(options.id, options.callback);
|
|
622
670
|
}
|
|
623
671
|
async _getObjectsByArray(keys, options) {
|
|
624
672
|
try {
|
|
625
|
-
const res = await
|
|
673
|
+
const res = await this.#objects.getObjects(keys, options);
|
|
626
674
|
return res;
|
|
627
675
|
}
|
|
628
676
|
catch (e) {
|
|
@@ -681,17 +729,17 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
681
729
|
}
|
|
682
730
|
setTimeout(async () => {
|
|
683
731
|
// give last states some time to get handled
|
|
684
|
-
if (
|
|
732
|
+
if (this.#states) {
|
|
685
733
|
try {
|
|
686
|
-
await
|
|
734
|
+
await this.#states.destroy();
|
|
687
735
|
}
|
|
688
736
|
catch {
|
|
689
737
|
// ignore
|
|
690
738
|
}
|
|
691
739
|
}
|
|
692
|
-
if (
|
|
740
|
+
if (this.#objects) {
|
|
693
741
|
try {
|
|
694
|
-
await
|
|
742
|
+
await this.#objects.destroy();
|
|
695
743
|
}
|
|
696
744
|
catch {
|
|
697
745
|
//ignore
|
|
@@ -699,8 +747,8 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
699
747
|
}
|
|
700
748
|
if (this.startedInCompactMode) {
|
|
701
749
|
this.emit('exit', _exitCode, reason);
|
|
702
|
-
|
|
703
|
-
|
|
750
|
+
this.#states = null;
|
|
751
|
+
this.#objects = null;
|
|
704
752
|
}
|
|
705
753
|
else {
|
|
706
754
|
process.exit(_exitCode);
|
|
@@ -1223,12 +1271,11 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
1223
1271
|
return js_controller_common_1.tools.maybeCallback(options.callback, acl);
|
|
1224
1272
|
}
|
|
1225
1273
|
this.getForeignObjects('*', 'group', null, options, (err, groups) => {
|
|
1226
|
-
var _a, _b;
|
|
1227
1274
|
acl.groups = [];
|
|
1228
1275
|
// aggregate all groups permissions, where this user is
|
|
1229
1276
|
if (groups) {
|
|
1230
1277
|
for (const g of Object.keys(groups)) {
|
|
1231
|
-
if (
|
|
1278
|
+
if (groups[g]?.common?.members && groups[g].common.members.includes(userId)) {
|
|
1232
1279
|
acl.groups.push(groups[g]._id);
|
|
1233
1280
|
if (groups[g]._id === constants_1.SYSTEM_ADMIN_GROUP) {
|
|
1234
1281
|
acl = {
|
|
@@ -1308,7 +1355,6 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
1308
1355
|
});
|
|
1309
1356
|
}
|
|
1310
1357
|
async _stop(isPause, isScheduled, exitCode, updateAliveState) {
|
|
1311
|
-
var _a;
|
|
1312
1358
|
exitCode = exitCode || (isScheduled ? js_controller_common_1.EXIT_CODES.START_IMMEDIATELY_AFTER_STOP : 0);
|
|
1313
1359
|
if (updateAliveState === undefined) {
|
|
1314
1360
|
updateAliveState = true;
|
|
@@ -1336,9 +1382,9 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
1336
1382
|
this.messageCallbacks.forEach(callbackObj => clearTimeout(callbackObj.timer));
|
|
1337
1383
|
this.messageCallbacks.clear();
|
|
1338
1384
|
}
|
|
1339
|
-
if (
|
|
1385
|
+
if (this.#states && updateAliveState) {
|
|
1340
1386
|
this.outputCount++;
|
|
1341
|
-
|
|
1387
|
+
this.#states.setState(`${id}.alive`, { val: false, ack: true, from: id }, () => {
|
|
1342
1388
|
if (!isPause) {
|
|
1343
1389
|
this._logger.info(`${this.namespaceLog} terminating`);
|
|
1344
1390
|
}
|
|
@@ -1386,7 +1432,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
1386
1432
|
// Even if the developer forgets to call the unload callback, we need to stop the process.
|
|
1387
1433
|
// Therefore, wait a short while and then force the unload procedure
|
|
1388
1434
|
setTimeout(() => {
|
|
1389
|
-
if (
|
|
1435
|
+
if (this.#states) {
|
|
1390
1436
|
finishUnload();
|
|
1391
1437
|
// Give 1 second to write the value
|
|
1392
1438
|
setTimeout(() => {
|
|
@@ -1402,7 +1448,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
1402
1448
|
}
|
|
1403
1449
|
this.terminate(exitCode);
|
|
1404
1450
|
}
|
|
1405
|
-
},
|
|
1451
|
+
}, this.common?.stopTimeout || 500);
|
|
1406
1452
|
}
|
|
1407
1453
|
}
|
|
1408
1454
|
/**
|
|
@@ -1481,13 +1527,13 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
1481
1527
|
async _getCertificates(options) {
|
|
1482
1528
|
const { publicName, chainedName, privateName, callback } = options;
|
|
1483
1529
|
let obj;
|
|
1484
|
-
if (!
|
|
1530
|
+
if (!this.#objects) {
|
|
1485
1531
|
this._logger.info(`${this.namespaceLog} getCertificates not processed because Objects database not connected`);
|
|
1486
1532
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
1487
1533
|
}
|
|
1488
1534
|
try {
|
|
1489
1535
|
// Load certificates
|
|
1490
|
-
obj = await
|
|
1536
|
+
obj = await this.#objects.getObject('system.certificates');
|
|
1491
1537
|
}
|
|
1492
1538
|
catch {
|
|
1493
1539
|
// ignore
|
|
@@ -1636,7 +1682,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
1636
1682
|
}
|
|
1637
1683
|
try {
|
|
1638
1684
|
const data = await this.getForeignObjectAsync('system.config');
|
|
1639
|
-
if (data
|
|
1685
|
+
if (data?.native) {
|
|
1640
1686
|
this._systemSecret = data.native.secret;
|
|
1641
1687
|
}
|
|
1642
1688
|
}
|
|
@@ -1794,7 +1840,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
1794
1840
|
}
|
|
1795
1841
|
async _setObject(options) {
|
|
1796
1842
|
if (!this._defaultObjs) {
|
|
1797
|
-
this._defaultObjs = (await
|
|
1843
|
+
this._defaultObjs = (await import('./defaultObjs.js')).createDefaults();
|
|
1798
1844
|
}
|
|
1799
1845
|
if (!options.obj) {
|
|
1800
1846
|
this._logger.error(`${this.namespaceLog} setObject: try to set null object for ${options.id}`);
|
|
@@ -1877,7 +1923,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
1877
1923
|
* @param [callback]
|
|
1878
1924
|
*/
|
|
1879
1925
|
async _setObjectWithDefaultValue(id, obj, options, callback) {
|
|
1880
|
-
if (!
|
|
1926
|
+
if (!this.#objects) {
|
|
1881
1927
|
this._logger.info(`${this.namespaceLog} setObject not processed because Objects database not connected`);
|
|
1882
1928
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
1883
1929
|
}
|
|
@@ -1896,7 +1942,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
1896
1942
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, err);
|
|
1897
1943
|
}
|
|
1898
1944
|
try {
|
|
1899
|
-
const result = await
|
|
1945
|
+
const result = await this.#objects.setObjectAsync(id, obj, options);
|
|
1900
1946
|
if (obj.type === 'state' && obj.common && obj.common.def !== undefined && obj.common.def !== null) {
|
|
1901
1947
|
const state = await this.getForeignStateAsync(id);
|
|
1902
1948
|
// only set the def state, if state is non-existent
|
|
@@ -1940,7 +1986,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
1940
1986
|
}
|
|
1941
1987
|
}
|
|
1942
1988
|
};
|
|
1943
|
-
if (!
|
|
1989
|
+
if (!this.#objects) {
|
|
1944
1990
|
return js_controller_common_1.tools.maybeCallback(options.callback, ret);
|
|
1945
1991
|
}
|
|
1946
1992
|
const params = {
|
|
@@ -1949,7 +1995,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
1949
1995
|
include_docs: true
|
|
1950
1996
|
};
|
|
1951
1997
|
try {
|
|
1952
|
-
const folders = await
|
|
1998
|
+
const folders = await this.#objects.getObjectViewAsync('system', 'folder', params);
|
|
1953
1999
|
if (folders) {
|
|
1954
2000
|
addRows(folders.rows);
|
|
1955
2001
|
}
|
|
@@ -1958,7 +2004,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
1958
2004
|
/* ignore, we'll return what we get till now */
|
|
1959
2005
|
}
|
|
1960
2006
|
try {
|
|
1961
|
-
const devices = await
|
|
2007
|
+
const devices = await this.#objects.getObjectViewAsync('system', 'device', params);
|
|
1962
2008
|
if (devices) {
|
|
1963
2009
|
addRows(devices.rows);
|
|
1964
2010
|
}
|
|
@@ -1967,7 +2013,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
1967
2013
|
/* ignore, we'll return what we get till now */
|
|
1968
2014
|
}
|
|
1969
2015
|
try {
|
|
1970
|
-
const channels = await
|
|
2016
|
+
const channels = await this.#objects.getObjectViewAsync('system', 'channel', params);
|
|
1971
2017
|
if (channels) {
|
|
1972
2018
|
addRows(channels.rows);
|
|
1973
2019
|
}
|
|
@@ -1976,7 +2022,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
1976
2022
|
/* ignore, we'll return what we get till now */
|
|
1977
2023
|
}
|
|
1978
2024
|
try {
|
|
1979
|
-
const states = await
|
|
2025
|
+
const states = await this.#objects.getObjectViewAsync('system', 'state', params);
|
|
1980
2026
|
if (states) {
|
|
1981
2027
|
addRows(states.rows);
|
|
1982
2028
|
}
|
|
@@ -2066,7 +2112,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2066
2112
|
}
|
|
2067
2113
|
// TODO: the public return type needs to be defined correctly, probably needs to be discussed
|
|
2068
2114
|
async _extendObject(options) {
|
|
2069
|
-
if (!
|
|
2115
|
+
if (!this.#objects) {
|
|
2070
2116
|
this._logger.info(`${this.namespaceLog} extendObject not processed because Objects database not connected`);
|
|
2071
2117
|
return js_controller_common_1.tools.maybeCallbackWithError(options.callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
2072
2118
|
}
|
|
@@ -2092,12 +2138,12 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2092
2138
|
// Read whole object
|
|
2093
2139
|
let oldObj;
|
|
2094
2140
|
try {
|
|
2095
|
-
oldObj = await
|
|
2141
|
+
oldObj = await this.#objects.getObjectAsync(options.id, options.options);
|
|
2096
2142
|
}
|
|
2097
2143
|
catch (e) {
|
|
2098
2144
|
return js_controller_common_1.tools.maybeCallbackWithError(options.callback, e);
|
|
2099
2145
|
}
|
|
2100
|
-
if (!
|
|
2146
|
+
if (!this.#objects) {
|
|
2101
2147
|
this._logger.info(`${this.namespaceLog} extendObject not processed because Objects database not connected`);
|
|
2102
2148
|
return js_controller_common_1.tools.maybeCallbackWithError(options.callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
2103
2149
|
}
|
|
@@ -2138,7 +2184,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2138
2184
|
options.obj.ts = options.obj.ts || Date.now();
|
|
2139
2185
|
options.obj = extend(true, oldObj, options.obj);
|
|
2140
2186
|
// @ts-expect-error TODO we are returning type Object for ease of use to devs, but formally these are AnyObjects, e.g. not guaranteed to have common
|
|
2141
|
-
return
|
|
2187
|
+
return this.#objects.setObject(options.id, options.obj, options.options, options.callback);
|
|
2142
2188
|
}
|
|
2143
2189
|
else {
|
|
2144
2190
|
options.obj.from = options.obj.from || `system.adapter.${this.namespace}`;
|
|
@@ -2165,7 +2211,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2165
2211
|
return this.setForeignObject(options.id, options.obj, options.options, options.callback);
|
|
2166
2212
|
}
|
|
2167
2213
|
try {
|
|
2168
|
-
const cbObj = await
|
|
2214
|
+
const cbObj = await this.#objects.extendObjectAsync(options.id, options.obj, options.options || {});
|
|
2169
2215
|
let defState;
|
|
2170
2216
|
if (options.obj.type === 'state' || oldObj.type === 'state') {
|
|
2171
2217
|
if (options.obj.common && 'def' in options.obj.common && options.obj.common.def !== undefined) {
|
|
@@ -2243,7 +2289,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2243
2289
|
const { options, callback, obj } = _options;
|
|
2244
2290
|
let { id } = _options;
|
|
2245
2291
|
obj.from = obj.from || `system.adapter.${this.namespace}`;
|
|
2246
|
-
obj.user = obj.user ||
|
|
2292
|
+
obj.user = obj.user || options?.user || constants_1.SYSTEM_ADMIN_USER;
|
|
2247
2293
|
obj.ts = obj.ts || Date.now();
|
|
2248
2294
|
id = this.fixForbiddenCharsInId(id);
|
|
2249
2295
|
// check that alias is valid if given
|
|
@@ -2324,14 +2370,14 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2324
2370
|
async _extendForeignObjectAsync(_options) {
|
|
2325
2371
|
const { id, callback, options } = _options;
|
|
2326
2372
|
let { obj } = _options;
|
|
2327
|
-
if (!
|
|
2373
|
+
if (!this.#objects) {
|
|
2328
2374
|
this._logger.info(`${this.namespaceLog} extendForeignObject not processed because Objects database not connected`);
|
|
2329
2375
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
2330
2376
|
}
|
|
2331
2377
|
// Read whole object
|
|
2332
2378
|
let oldObj;
|
|
2333
2379
|
try {
|
|
2334
|
-
oldObj = await
|
|
2380
|
+
oldObj = await this.#objects.getObjectAsync(id, options);
|
|
2335
2381
|
}
|
|
2336
2382
|
catch (e) {
|
|
2337
2383
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, e);
|
|
@@ -2363,15 +2409,15 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2363
2409
|
oldObj.native.devices = [];
|
|
2364
2410
|
}
|
|
2365
2411
|
obj.from = obj.from || `system.adapter.${this.namespace}`;
|
|
2366
|
-
obj.user = obj.user ||
|
|
2412
|
+
obj.user = obj.user || options?.user || constants_1.SYSTEM_ADMIN_USER;
|
|
2367
2413
|
obj.ts = obj.ts || Date.now();
|
|
2368
2414
|
obj = extend(true, oldObj, obj);
|
|
2369
2415
|
// @ts-expect-error TODO we are returning type Object for ease of use to devs, but formally these are AnyObjects, e.g. not guaranteed to have common
|
|
2370
|
-
return
|
|
2416
|
+
return this.#objects.setObject(id, obj, options, callback);
|
|
2371
2417
|
}
|
|
2372
2418
|
else {
|
|
2373
2419
|
obj.from = obj.from || `system.adapter.${this.namespace}`;
|
|
2374
|
-
obj.user = obj.user ||
|
|
2420
|
+
obj.user = obj.user || options?.user || constants_1.SYSTEM_ADMIN_USER;
|
|
2375
2421
|
obj.ts = obj.ts || Date.now();
|
|
2376
2422
|
if ((obj.type && obj.type === 'state') || (!obj.type && oldObj && oldObj.type === 'state')) {
|
|
2377
2423
|
if (obj.common &&
|
|
@@ -2393,8 +2439,8 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2393
2439
|
return this.setForeignObject(id, obj, options, callback);
|
|
2394
2440
|
}
|
|
2395
2441
|
try {
|
|
2396
|
-
const cbObj = await
|
|
2397
|
-
if (
|
|
2442
|
+
const cbObj = await this.#objects.extendObjectAsync(id, obj, options || {});
|
|
2443
|
+
if (cbObj?.value.type === 'state') {
|
|
2398
2444
|
let defState;
|
|
2399
2445
|
if (obj.common && 'def' in obj.common && obj.common.def !== undefined) {
|
|
2400
2446
|
defState = obj.common.def;
|
|
@@ -2438,7 +2484,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2438
2484
|
* @param options optional user context
|
|
2439
2485
|
*/
|
|
2440
2486
|
objectExists(id, options) {
|
|
2441
|
-
if (!
|
|
2487
|
+
if (!this.#objects) {
|
|
2442
2488
|
this._logger.info(`${this.namespaceLog} objectExists not processed because Objects database not connected`);
|
|
2443
2489
|
return Promise.resolve();
|
|
2444
2490
|
}
|
|
@@ -2448,7 +2494,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2448
2494
|
}
|
|
2449
2495
|
id = this._utils.fixId(id);
|
|
2450
2496
|
this._utils.validateId(id, false, null);
|
|
2451
|
-
return
|
|
2497
|
+
return this.#objects.objectExists(id, options);
|
|
2452
2498
|
}
|
|
2453
2499
|
/**
|
|
2454
2500
|
* Checks if an object exists to the given id
|
|
@@ -2457,7 +2503,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2457
2503
|
* @param options optional user context
|
|
2458
2504
|
*/
|
|
2459
2505
|
foreignObjectExists(id, options) {
|
|
2460
|
-
if (!
|
|
2506
|
+
if (!this.#objects) {
|
|
2461
2507
|
this._logger.info(`${this.namespaceLog} foreignObjectExists not processed because Objects database not connected`);
|
|
2462
2508
|
return Promise.resolve();
|
|
2463
2509
|
}
|
|
@@ -2466,7 +2512,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2466
2512
|
validator_1.Validator.assertObject(options, 'options');
|
|
2467
2513
|
}
|
|
2468
2514
|
this._utils.validateId(id, true, null);
|
|
2469
|
-
return
|
|
2515
|
+
return this.#objects.objectExists(id, options);
|
|
2470
2516
|
}
|
|
2471
2517
|
/**
|
|
2472
2518
|
* Get object of this instance.
|
|
@@ -2492,7 +2538,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2492
2538
|
if (options !== null && options !== undefined) {
|
|
2493
2539
|
validator_1.Validator.assertObject(options, 'options');
|
|
2494
2540
|
}
|
|
2495
|
-
if (!
|
|
2541
|
+
if (!this.#objects) {
|
|
2496
2542
|
this._logger.info(`${this.namespaceLog} getObject not processed because Objects database not connected`);
|
|
2497
2543
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
2498
2544
|
}
|
|
@@ -2502,7 +2548,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2502
2548
|
catch (err) {
|
|
2503
2549
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, err);
|
|
2504
2550
|
}
|
|
2505
|
-
|
|
2551
|
+
this.#objects.getObject(this._utils.fixId(id), options, callback);
|
|
2506
2552
|
}
|
|
2507
2553
|
/**
|
|
2508
2554
|
* Read object view from DB.
|
|
@@ -2547,7 +2593,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2547
2593
|
}
|
|
2548
2594
|
_getObjectView(_options) {
|
|
2549
2595
|
const { design, search, params, options, callback } = _options;
|
|
2550
|
-
if (!
|
|
2596
|
+
if (!this.#objects) {
|
|
2551
2597
|
this._logger.info(`${this.namespaceLog} getObjectView not processed because Objects database not connected`);
|
|
2552
2598
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
2553
2599
|
}
|
|
@@ -2588,7 +2634,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2588
2634
|
}
|
|
2589
2635
|
}
|
|
2590
2636
|
// @ts-expect-error fix it
|
|
2591
|
-
return
|
|
2637
|
+
return this.#objects.getObjectView(design, search, params, options, callback);
|
|
2592
2638
|
}
|
|
2593
2639
|
/**
|
|
2594
2640
|
* Read object list from DB.
|
|
@@ -2625,11 +2671,11 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2625
2671
|
}
|
|
2626
2672
|
validator_1.Validator.assertObject(params, 'params');
|
|
2627
2673
|
validator_1.Validator.assertOptionalCallback(callback, 'callback');
|
|
2628
|
-
if (!
|
|
2674
|
+
if (!this.#objects) {
|
|
2629
2675
|
this._logger.info(`${this.namespaceLog} getObjectList not processed because Objects database not connected`);
|
|
2630
2676
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
2631
2677
|
}
|
|
2632
|
-
|
|
2678
|
+
this.#objects.getObjectList(params, options, callback);
|
|
2633
2679
|
}
|
|
2634
2680
|
/**
|
|
2635
2681
|
* Get the enum tree.
|
|
@@ -2679,7 +2725,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2679
2725
|
_getEnum(_options) {
|
|
2680
2726
|
const { options, callback } = _options;
|
|
2681
2727
|
let { _enum } = _options;
|
|
2682
|
-
if (!
|
|
2728
|
+
if (!this.#objects) {
|
|
2683
2729
|
this._logger.info(`${this.namespaceLog} getEnum not processed because Objects database not connected`);
|
|
2684
2730
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
2685
2731
|
}
|
|
@@ -2687,14 +2733,14 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2687
2733
|
_enum = `enum.${_enum}`;
|
|
2688
2734
|
}
|
|
2689
2735
|
const result = {};
|
|
2690
|
-
|
|
2736
|
+
this.#objects.getObjectView('system', 'enum', {
|
|
2691
2737
|
startkey: `${_enum}.`,
|
|
2692
2738
|
endkey: `${_enum}.\u9999`
|
|
2693
2739
|
}, options, (err, res) => {
|
|
2694
2740
|
if (err) {
|
|
2695
2741
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, err);
|
|
2696
2742
|
}
|
|
2697
|
-
if (res
|
|
2743
|
+
if (res?.rows) {
|
|
2698
2744
|
for (const row of res.rows) {
|
|
2699
2745
|
result[row.id] = row.value;
|
|
2700
2746
|
}
|
|
@@ -2762,7 +2808,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2762
2808
|
async _getEnums(_options) {
|
|
2763
2809
|
const { options, callback } = _options;
|
|
2764
2810
|
let { _enumList } = _options;
|
|
2765
|
-
if (!
|
|
2811
|
+
if (!this.#objects) {
|
|
2766
2812
|
this._logger.info(`${this.namespaceLog} getEnums not processed because Objects database not connected`);
|
|
2767
2813
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
2768
2814
|
}
|
|
@@ -2793,7 +2839,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2793
2839
|
}
|
|
2794
2840
|
else {
|
|
2795
2841
|
// Read all enums
|
|
2796
|
-
|
|
2842
|
+
this.#objects.getObjectView('system', 'enum', {
|
|
2797
2843
|
startkey: 'enum.',
|
|
2798
2844
|
endkey: 'enum.\u9999'
|
|
2799
2845
|
}, options, (err, res) => {
|
|
@@ -2802,7 +2848,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2802
2848
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, err);
|
|
2803
2849
|
}
|
|
2804
2850
|
const result = {};
|
|
2805
|
-
if (res
|
|
2851
|
+
if (res?.rows) {
|
|
2806
2852
|
for (const row of res.rows) {
|
|
2807
2853
|
const parts = row.id.split('.', 3);
|
|
2808
2854
|
if (!parts[2]) {
|
|
@@ -2899,16 +2945,15 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2899
2945
|
});
|
|
2900
2946
|
}
|
|
2901
2947
|
async _getForeignObjects(_options) {
|
|
2902
|
-
var _a;
|
|
2903
2948
|
const { options, callback, type, pattern, enums } = _options;
|
|
2904
|
-
if (!
|
|
2949
|
+
if (!this.#objects) {
|
|
2905
2950
|
this._logger.info(`${this.namespaceLog} getForeignObjects not processed because Objects database not connected`);
|
|
2906
2951
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
2907
2952
|
}
|
|
2908
2953
|
let objs;
|
|
2909
2954
|
if (Array.isArray(pattern)) {
|
|
2910
2955
|
try {
|
|
2911
|
-
objs = await
|
|
2956
|
+
objs = await this.#objects.getObjects(pattern, options);
|
|
2912
2957
|
}
|
|
2913
2958
|
catch (e) {
|
|
2914
2959
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, e);
|
|
@@ -2923,7 +2968,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2923
2968
|
};
|
|
2924
2969
|
}
|
|
2925
2970
|
try {
|
|
2926
|
-
const res = await
|
|
2971
|
+
const res = await this.#objects.getObjectView('system', type || 'state', params, options);
|
|
2927
2972
|
objs = res.rows.map(row => row.value);
|
|
2928
2973
|
}
|
|
2929
2974
|
catch (e) {
|
|
@@ -2958,7 +3003,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
2958
3003
|
list[id].enums = {};
|
|
2959
3004
|
for (const _enum of Object.values(_enums)) {
|
|
2960
3005
|
for (const [enumID, enumObj] of Object.entries(_enum)) {
|
|
2961
|
-
if (!
|
|
3006
|
+
if (!enumObj?.common?.members) {
|
|
2962
3007
|
continue;
|
|
2963
3008
|
}
|
|
2964
3009
|
if (enumObj.common.members.includes(id) ||
|
|
@@ -3017,7 +3062,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3017
3062
|
if (options !== null && options !== undefined) {
|
|
3018
3063
|
validator_1.Validator.assertObject(options, 'options');
|
|
3019
3064
|
}
|
|
3020
|
-
if (!
|
|
3065
|
+
if (!this.#objects) {
|
|
3021
3066
|
this._logger.info(`${this.namespaceLog} findForeignObject not processed because Objects database not connected`);
|
|
3022
3067
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
3023
3068
|
}
|
|
@@ -3027,7 +3072,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3027
3072
|
catch (err) {
|
|
3028
3073
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, err);
|
|
3029
3074
|
}
|
|
3030
|
-
|
|
3075
|
+
this.#objects.findObject(id, type, options || {}, callback);
|
|
3031
3076
|
}
|
|
3032
3077
|
/**
|
|
3033
3078
|
* Get any object.
|
|
@@ -3061,12 +3106,12 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3061
3106
|
return this._getForeignObject({ id, options, callback });
|
|
3062
3107
|
}
|
|
3063
3108
|
async _getForeignObject(options) {
|
|
3064
|
-
if (!
|
|
3109
|
+
if (!this.#objects) {
|
|
3065
3110
|
this._logger.info(`${this.namespaceLog} getForeignObject not processed because Objects database not connected`);
|
|
3066
3111
|
return js_controller_common_1.tools.maybeCallbackWithError(options.callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
3067
3112
|
}
|
|
3068
3113
|
try {
|
|
3069
|
-
const obj = await
|
|
3114
|
+
const obj = await this.#objects.getObjectAsync(options.id, options);
|
|
3070
3115
|
// remove protectedNative if not admin, not cloud or not own adapter
|
|
3071
3116
|
if (obj &&
|
|
3072
3117
|
'protectedNative' in obj &&
|
|
@@ -3116,7 +3161,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3116
3161
|
}
|
|
3117
3162
|
else {
|
|
3118
3163
|
const task = tasks.shift();
|
|
3119
|
-
|
|
3164
|
+
this.#objects.delObject(task.id, options, async (err) => {
|
|
3120
3165
|
if (err) {
|
|
3121
3166
|
return js_controller_common_1.tools.maybeCallbackWithError(cb, err);
|
|
3122
3167
|
}
|
|
@@ -3129,7 +3174,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3129
3174
|
}
|
|
3130
3175
|
}
|
|
3131
3176
|
try {
|
|
3132
|
-
await js_controller_common_1.tools.removeIdFromAllEnums(
|
|
3177
|
+
await js_controller_common_1.tools.removeIdFromAllEnums(this.#objects, task.id, this.enums);
|
|
3133
3178
|
}
|
|
3134
3179
|
catch (e) {
|
|
3135
3180
|
this._logger.warn(`${this.namespaceLog} Could not remove ${task.id} from enums: ${e.message}`);
|
|
@@ -3162,7 +3207,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3162
3207
|
if (options !== undefined && options !== null) {
|
|
3163
3208
|
validator_1.Validator.assertObject(options, 'options');
|
|
3164
3209
|
}
|
|
3165
|
-
if (!
|
|
3210
|
+
if (!this.#objects) {
|
|
3166
3211
|
this._logger.info(`${this.namespaceLog} delForeignObject not processed because Objects database not connected`);
|
|
3167
3212
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
3168
3213
|
}
|
|
@@ -3181,13 +3226,13 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3181
3226
|
_delForeignObject(_options) {
|
|
3182
3227
|
const { id, options, callback } = _options;
|
|
3183
3228
|
// If recursive deletion of all underlying objects, including id
|
|
3184
|
-
if (options
|
|
3229
|
+
if (options?.recursive) {
|
|
3185
3230
|
// read object itself
|
|
3186
|
-
|
|
3231
|
+
this.#objects.getObject(id, options, (err, obj) => {
|
|
3187
3232
|
const tasks = obj && (!obj.common || !obj.common.dontDelete) ? [{ id, state: obj.type === 'state' }] : [];
|
|
3188
3233
|
const selector = { startkey: `${id}.`, endkey: `${id}.\u9999` };
|
|
3189
3234
|
// read all underlying states
|
|
3190
|
-
|
|
3235
|
+
this.#objects.getObjectList(selector, options, (err, res) => {
|
|
3191
3236
|
res &&
|
|
3192
3237
|
res.rows.forEach((item) => !tasks.find(task => task.id === item.id) &&
|
|
3193
3238
|
(!item.value || !item.value.common || !item.value.common.dontDelete) && // exclude objects with dontDelete flag
|
|
@@ -3197,18 +3242,17 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3197
3242
|
});
|
|
3198
3243
|
}
|
|
3199
3244
|
else {
|
|
3200
|
-
|
|
3201
|
-
var _a;
|
|
3245
|
+
this.#objects.getObject(id, options, async (err, obj) => {
|
|
3202
3246
|
if (err) {
|
|
3203
3247
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, err);
|
|
3204
3248
|
}
|
|
3205
3249
|
else if (obj) {
|
|
3206
3250
|
// do not allow deletion of objects with dontDelete flag
|
|
3207
|
-
if (
|
|
3251
|
+
if (obj.common?.dontDelete) {
|
|
3208
3252
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, new Error('not deletable'));
|
|
3209
3253
|
}
|
|
3210
3254
|
try {
|
|
3211
|
-
await
|
|
3255
|
+
await this.#objects.delObject(obj._id, options);
|
|
3212
3256
|
}
|
|
3213
3257
|
catch (err) {
|
|
3214
3258
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, err);
|
|
@@ -3227,7 +3271,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3227
3271
|
}
|
|
3228
3272
|
}
|
|
3229
3273
|
try {
|
|
3230
|
-
await js_controller_common_1.tools.removeIdFromAllEnums(
|
|
3274
|
+
await js_controller_common_1.tools.removeIdFromAllEnums(this.#objects, id, this.enums);
|
|
3231
3275
|
}
|
|
3232
3276
|
catch (e) {
|
|
3233
3277
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, e);
|
|
@@ -3259,16 +3303,16 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3259
3303
|
if (options !== null && options !== undefined) {
|
|
3260
3304
|
validator_1.Validator.assertObject(options, 'options');
|
|
3261
3305
|
}
|
|
3262
|
-
if (!
|
|
3306
|
+
if (!this.#objects) {
|
|
3263
3307
|
this._logger.info(`${this.namespaceLog} subscribeObjects not processed because Objects database not connected`);
|
|
3264
3308
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
3265
3309
|
}
|
|
3266
3310
|
if (pattern === '*') {
|
|
3267
|
-
|
|
3311
|
+
this.#objects.subscribeUser(`${this.namespace}.*`, options, callback);
|
|
3268
3312
|
}
|
|
3269
3313
|
else {
|
|
3270
3314
|
const fixedPattern = Array.isArray(pattern) ? pattern : this._utils.fixId(pattern, true);
|
|
3271
|
-
|
|
3315
|
+
this.#objects.subscribeUser(fixedPattern, options, callback);
|
|
3272
3316
|
}
|
|
3273
3317
|
}
|
|
3274
3318
|
/**
|
|
@@ -3293,16 +3337,16 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3293
3337
|
if (options !== null && options !== undefined) {
|
|
3294
3338
|
validator_1.Validator.assertObject(options, 'options');
|
|
3295
3339
|
}
|
|
3296
|
-
if (!
|
|
3340
|
+
if (!this.#objects) {
|
|
3297
3341
|
this._logger.info(`${this.namespaceLog} unsubscribeObjects not processed because Objects database not connected`);
|
|
3298
3342
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
3299
3343
|
}
|
|
3300
3344
|
if (pattern === '*') {
|
|
3301
|
-
|
|
3345
|
+
this.#objects.unsubscribeUser(`${this.namespace}.*`, options, callback);
|
|
3302
3346
|
}
|
|
3303
3347
|
else {
|
|
3304
3348
|
const fixedPattern = Array.isArray(pattern) ? pattern : this._utils.fixId(pattern, true);
|
|
3305
|
-
|
|
3349
|
+
this.#objects.unsubscribeUser(fixedPattern, options, callback);
|
|
3306
3350
|
}
|
|
3307
3351
|
}
|
|
3308
3352
|
/**
|
|
@@ -3327,11 +3371,11 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3327
3371
|
if (options !== null && options !== undefined) {
|
|
3328
3372
|
validator_1.Validator.assertObject(options, 'options');
|
|
3329
3373
|
}
|
|
3330
|
-
if (!
|
|
3374
|
+
if (!this.#objects) {
|
|
3331
3375
|
this._logger.info(`${this.namespaceLog} subscribeForeignObjects not processed because Objects database not connected`);
|
|
3332
3376
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
3333
3377
|
}
|
|
3334
|
-
|
|
3378
|
+
this.#objects.subscribeUser(pattern, options, callback);
|
|
3335
3379
|
}
|
|
3336
3380
|
/**
|
|
3337
3381
|
* Unsubscribe for the patterns on all objects.
|
|
@@ -3358,11 +3402,11 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3358
3402
|
if (options !== null && options !== undefined) {
|
|
3359
3403
|
validator_1.Validator.assertObject(options, 'options');
|
|
3360
3404
|
}
|
|
3361
|
-
if (!
|
|
3405
|
+
if (!this.#objects) {
|
|
3362
3406
|
this._logger.info(`${this.namespaceLog} unsubscribeForeignObjects not processed because Objects database not connected`);
|
|
3363
3407
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
3364
3408
|
}
|
|
3365
|
-
|
|
3409
|
+
this.#objects.unsubscribeUser(pattern, options, callback);
|
|
3366
3410
|
}
|
|
3367
3411
|
/**
|
|
3368
3412
|
* Subscribe for the changes of files in specific instance.
|
|
@@ -3372,7 +3416,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3372
3416
|
* @param options optional user context
|
|
3373
3417
|
*/
|
|
3374
3418
|
subscribeForeignFiles(id, pattern, options) {
|
|
3375
|
-
if (!
|
|
3419
|
+
if (!this.#objects) {
|
|
3376
3420
|
this._logger.info(`${this.namespaceLog} subscribeForeignFiles not processed because Objects database not connected`);
|
|
3377
3421
|
return Promise.reject(js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
3378
3422
|
}
|
|
@@ -3381,7 +3425,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3381
3425
|
if (options !== null && options !== undefined) {
|
|
3382
3426
|
validator_1.Validator.assertObject(options, 'options');
|
|
3383
3427
|
}
|
|
3384
|
-
return
|
|
3428
|
+
return this.#objects.subscribeUserFile(id, pattern, options);
|
|
3385
3429
|
}
|
|
3386
3430
|
/**
|
|
3387
3431
|
* Unsubscribe for the changes of files on specific instance.
|
|
@@ -3394,7 +3438,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3394
3438
|
if (!pattern) {
|
|
3395
3439
|
pattern = '*';
|
|
3396
3440
|
}
|
|
3397
|
-
if (!
|
|
3441
|
+
if (!this.#objects) {
|
|
3398
3442
|
this._logger.info(`${this.namespaceLog} unsubscribeForeignFiles not processed because Objects database not connected`);
|
|
3399
3443
|
return Promise.reject(js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
3400
3444
|
}
|
|
@@ -3403,7 +3447,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3403
3447
|
if (options !== null && options !== undefined) {
|
|
3404
3448
|
validator_1.Validator.assertObject(options, 'options');
|
|
3405
3449
|
}
|
|
3406
|
-
return
|
|
3450
|
+
return this.#objects.unsubscribeUserFile(id, pattern, options);
|
|
3407
3451
|
}
|
|
3408
3452
|
/**
|
|
3409
3453
|
* Same as {@link AdapterClass.setObject}, but with check if the object exists.
|
|
@@ -3446,7 +3490,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3446
3490
|
});
|
|
3447
3491
|
}
|
|
3448
3492
|
async _setObjectNotExists(options) {
|
|
3449
|
-
if (!
|
|
3493
|
+
if (!this.#objects) {
|
|
3450
3494
|
this._logger.info(`${this.namespaceLog} setObjectNotExists not processed because Objects database not connected`);
|
|
3451
3495
|
return js_controller_common_1.tools.maybeCallbackWithError(options.callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
3452
3496
|
}
|
|
@@ -3456,7 +3500,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3456
3500
|
// check if object already exists
|
|
3457
3501
|
let objExists;
|
|
3458
3502
|
try {
|
|
3459
|
-
objExists = await
|
|
3503
|
+
objExists = await this.#objects.objectExists(options.id, options.options);
|
|
3460
3504
|
}
|
|
3461
3505
|
catch (e) {
|
|
3462
3506
|
return js_controller_common_1.tools.maybeCallbackWithError(options.callback, `Could not check object existence of ${options.id}: ${e.message}`);
|
|
@@ -3509,7 +3553,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3509
3553
|
}
|
|
3510
3554
|
async _setForeignObjectNotExists(_options) {
|
|
3511
3555
|
const { id, obj, options, callback } = _options;
|
|
3512
|
-
if (!
|
|
3556
|
+
if (!this.#objects) {
|
|
3513
3557
|
this._logger.info(`${this.namespaceLog} setForeignObjectNotExists not processed because Objects database not connected`);
|
|
3514
3558
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
3515
3559
|
}
|
|
@@ -3522,7 +3566,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3522
3566
|
// check if object exists
|
|
3523
3567
|
let objExists;
|
|
3524
3568
|
try {
|
|
3525
|
-
objExists = await
|
|
3569
|
+
objExists = await this.#objects.objectExists(id, options || {});
|
|
3526
3570
|
}
|
|
3527
3571
|
catch (e) {
|
|
3528
3572
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, `Could not check object existence of ${id}: ${e.message}`);
|
|
@@ -3532,7 +3576,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3532
3576
|
obj.from = `system.adapter.${this.namespace}`;
|
|
3533
3577
|
}
|
|
3534
3578
|
if (!obj.user) {
|
|
3535
|
-
obj.user =
|
|
3579
|
+
obj.user = options?.user || constants_1.SYSTEM_ADMIN_USER;
|
|
3536
3580
|
}
|
|
3537
3581
|
if (!obj.ts) {
|
|
3538
3582
|
obj.ts = Date.now();
|
|
@@ -3830,7 +3874,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3830
3874
|
async _deleteDevice(_options) {
|
|
3831
3875
|
const { callback } = _options;
|
|
3832
3876
|
let { deviceName } = _options;
|
|
3833
|
-
if (!
|
|
3877
|
+
if (!this.#objects) {
|
|
3834
3878
|
this._logger.info(`${this.namespaceLog} deleteDevice not processed because Objects database not connected`);
|
|
3835
3879
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
3836
3880
|
}
|
|
@@ -3878,7 +3922,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3878
3922
|
_addChannelToEnum(_options) {
|
|
3879
3923
|
const { addTo, options, callback } = _options;
|
|
3880
3924
|
let { enumName, parentDevice, channelName } = _options;
|
|
3881
|
-
if (!
|
|
3925
|
+
if (!this.#objects) {
|
|
3882
3926
|
this._logger.info(`${this.namespaceLog} addChannelToEnum not processed because Objects database not connected`);
|
|
3883
3927
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
3884
3928
|
}
|
|
@@ -3897,7 +3941,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3897
3941
|
channelName = channelName.replace(FORBIDDEN_CHARS, '_').replace(/\./g, '_');
|
|
3898
3942
|
const objId = `${this.namespace}.${this._DCS2ID(parentDevice, channelName)}`;
|
|
3899
3943
|
if (addTo.startsWith('enum.')) {
|
|
3900
|
-
|
|
3944
|
+
this.#objects.getObject(addTo, options, (err, obj) => {
|
|
3901
3945
|
if (err) {
|
|
3902
3946
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, err);
|
|
3903
3947
|
}
|
|
@@ -3905,9 +3949,9 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3905
3949
|
if (!obj.common.members.includes(objId)) {
|
|
3906
3950
|
obj.common.members.push(objId);
|
|
3907
3951
|
obj.from = `system.adapter.${this.namespace}`;
|
|
3908
|
-
obj.user =
|
|
3952
|
+
obj.user = options?.user || constants_1.SYSTEM_ADMIN_USER;
|
|
3909
3953
|
obj.ts = Date.now();
|
|
3910
|
-
|
|
3954
|
+
this.#objects.setObject(obj._id, obj, options, callback);
|
|
3911
3955
|
}
|
|
3912
3956
|
else {
|
|
3913
3957
|
return js_controller_common_1.tools.maybeCallback(callback);
|
|
@@ -3919,7 +3963,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3919
3963
|
if (enumName.startsWith('enum.')) {
|
|
3920
3964
|
enumName = enumName.substring(5);
|
|
3921
3965
|
}
|
|
3922
|
-
|
|
3966
|
+
this.#objects.getObject(`enum.${enumName}.${addTo}`, options, (err, obj) => {
|
|
3923
3967
|
if (err) {
|
|
3924
3968
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, err);
|
|
3925
3969
|
}
|
|
@@ -3929,9 +3973,9 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3929
3973
|
// @ts-expect-error
|
|
3930
3974
|
obj.common.members.push(objId);
|
|
3931
3975
|
obj.from = `system.adapter.${this.namespace}`;
|
|
3932
|
-
obj.user =
|
|
3976
|
+
obj.user = options?.user || constants_1.SYSTEM_ADMIN_USER;
|
|
3933
3977
|
obj.ts = Date.now();
|
|
3934
|
-
|
|
3978
|
+
this.#objects.setObject(obj._id, obj, options, callback);
|
|
3935
3979
|
}
|
|
3936
3980
|
else {
|
|
3937
3981
|
return js_controller_common_1.tools.maybeCallback(callback);
|
|
@@ -3939,7 +3983,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3939
3983
|
}
|
|
3940
3984
|
else {
|
|
3941
3985
|
// Create enum
|
|
3942
|
-
|
|
3986
|
+
this.#objects.setObject(`enum.${enumName}.${addTo}`, {
|
|
3943
3987
|
common: {
|
|
3944
3988
|
name: addTo,
|
|
3945
3989
|
members: [objId]
|
|
@@ -3970,7 +4014,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3970
4014
|
_deleteChannelFromEnum(_options) {
|
|
3971
4015
|
const { options, callback } = _options;
|
|
3972
4016
|
let { enumName, channelName, parentDevice } = _options;
|
|
3973
|
-
if (!
|
|
4017
|
+
if (!this.#objects) {
|
|
3974
4018
|
this._logger.info(`${this.namespaceLog} deleteChannelFromEnum not processed because Objects database not connected`);
|
|
3975
4019
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
3976
4020
|
}
|
|
@@ -3995,26 +4039,25 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
3995
4039
|
else {
|
|
3996
4040
|
enumName = 'enum.';
|
|
3997
4041
|
}
|
|
3998
|
-
|
|
4042
|
+
this.#objects.getObjectView('system', 'enum', {
|
|
3999
4043
|
startkey: enumName,
|
|
4000
4044
|
endkey: `${enumName}\u9999`
|
|
4001
4045
|
}, options, async (err, res) => {
|
|
4002
|
-
var _a;
|
|
4003
4046
|
if (err) {
|
|
4004
4047
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, err);
|
|
4005
4048
|
}
|
|
4006
4049
|
if (res) {
|
|
4007
4050
|
for (const row of res.rows) {
|
|
4008
4051
|
try {
|
|
4009
|
-
const obj = (await
|
|
4010
|
-
if (
|
|
4052
|
+
const obj = (await this.#objects.getObject(row.id, options));
|
|
4053
|
+
if (obj?.common?.members) {
|
|
4011
4054
|
const pos = obj.common.members.indexOf(objId);
|
|
4012
4055
|
if (pos !== -1) {
|
|
4013
4056
|
obj.common.members.splice(pos, 1);
|
|
4014
4057
|
obj.from = `system.adapter.${this.namespace}`;
|
|
4015
|
-
obj.user =
|
|
4058
|
+
obj.user = options?.user || constants_1.SYSTEM_ADMIN_USER;
|
|
4016
4059
|
obj.ts = Date.now();
|
|
4017
|
-
await
|
|
4060
|
+
await this.#objects.setObjectAsync(obj._id, obj, options);
|
|
4018
4061
|
}
|
|
4019
4062
|
}
|
|
4020
4063
|
}
|
|
@@ -4067,7 +4110,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4067
4110
|
async _deleteChannel(_options) {
|
|
4068
4111
|
const { callback } = _options;
|
|
4069
4112
|
let { channelName, parentDevice } = _options;
|
|
4070
|
-
if (!
|
|
4113
|
+
if (!this.#objects) {
|
|
4071
4114
|
this._logger.info(`${this.namespaceLog} deleteChannel not processed because Objects database not connected`);
|
|
4072
4115
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
4073
4116
|
}
|
|
@@ -4147,9 +4190,9 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4147
4190
|
parentDevice = '';
|
|
4148
4191
|
}
|
|
4149
4192
|
}
|
|
4150
|
-
parentDevice = parentDevice
|
|
4151
|
-
parentChannel = parentChannel
|
|
4152
|
-
stateName = stateName
|
|
4193
|
+
parentDevice = parentDevice ?? '';
|
|
4194
|
+
parentChannel = parentChannel ?? '';
|
|
4195
|
+
stateName = stateName ?? '';
|
|
4153
4196
|
validator_1.Validator.assertString(parentDevice, 'parentDevice');
|
|
4154
4197
|
validator_1.Validator.assertString(parentChannel, 'parentChannel');
|
|
4155
4198
|
validator_1.Validator.assertString(stateName, 'stateName');
|
|
@@ -4209,11 +4252,11 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4209
4252
|
}
|
|
4210
4253
|
_getDevices(_options) {
|
|
4211
4254
|
const { options, callback } = _options;
|
|
4212
|
-
if (!
|
|
4255
|
+
if (!this.#objects) {
|
|
4213
4256
|
this._logger.info(`${this.namespaceLog} getDevices not processed because Objects database not connected`);
|
|
4214
4257
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
4215
4258
|
}
|
|
4216
|
-
|
|
4259
|
+
this.#objects.getObjectView('system', 'device', {
|
|
4217
4260
|
startkey: `${this.namespace}.`,
|
|
4218
4261
|
endkey: `${this.namespace}.\u9999`
|
|
4219
4262
|
}, options, (err, obj) => {
|
|
@@ -4248,7 +4291,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4248
4291
|
return this._getChannelsOf({ parentDevice, options, callback });
|
|
4249
4292
|
}
|
|
4250
4293
|
_getChannelsOf(options) {
|
|
4251
|
-
if (!
|
|
4294
|
+
if (!this.#objects) {
|
|
4252
4295
|
this._logger.info(`${this.namespaceLog} getChannelsOf not processed because Objects database not connected`);
|
|
4253
4296
|
return js_controller_common_1.tools.maybeCallbackWithError(options.callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
4254
4297
|
}
|
|
@@ -4260,7 +4303,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4260
4303
|
}
|
|
4261
4304
|
options.parentDevice = options.parentDevice.replace(FORBIDDEN_CHARS, '_').replace(/\./g, '_');
|
|
4262
4305
|
options.parentDevice = this.namespace + (options.parentDevice ? `.${options.parentDevice}` : '');
|
|
4263
|
-
|
|
4306
|
+
this.#objects.getObjectView('system', 'channel', {
|
|
4264
4307
|
startkey: `${options.parentDevice}.`,
|
|
4265
4308
|
endkey: `${options.parentDevice}.\u9999`
|
|
4266
4309
|
}, options.options || {}, (err, obj) => {
|
|
@@ -4308,7 +4351,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4308
4351
|
_getStatesOf(_options) {
|
|
4309
4352
|
const { options, callback } = _options;
|
|
4310
4353
|
let { parentDevice, parentChannel } = _options;
|
|
4311
|
-
if (!
|
|
4354
|
+
if (!this.#objects) {
|
|
4312
4355
|
this._logger.info(`${this.namespaceLog} getStatesOf not processed because Objects database not connected`);
|
|
4313
4356
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
4314
4357
|
}
|
|
@@ -4332,7 +4375,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4332
4375
|
}
|
|
4333
4376
|
parentChannel = parentChannel.replace(FORBIDDEN_CHARS, '_').replace(/\./g, '_');
|
|
4334
4377
|
const id = `${this.namespace}.${this._DCS2ID(parentDevice, parentChannel, true)}`;
|
|
4335
|
-
|
|
4378
|
+
this.#objects.getObjectView('system', 'state', {
|
|
4336
4379
|
startkey: id,
|
|
4337
4380
|
endkey: `${id}\u9999`
|
|
4338
4381
|
}, options, (err, obj) => {
|
|
@@ -4343,7 +4386,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4343
4386
|
let read = 0;
|
|
4344
4387
|
for (const row of obj.rows) {
|
|
4345
4388
|
read++;
|
|
4346
|
-
|
|
4389
|
+
this.#objects.getObject(row.id, (err, subObj) => {
|
|
4347
4390
|
if (subObj) {
|
|
4348
4391
|
res.push(subObj);
|
|
4349
4392
|
}
|
|
@@ -4373,7 +4416,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4373
4416
|
_addStateToEnum(_options) {
|
|
4374
4417
|
const { addTo, options, callback } = _options;
|
|
4375
4418
|
let { enumName, parentDevice, parentChannel, stateName } = _options;
|
|
4376
|
-
if (!
|
|
4419
|
+
if (!this.#objects) {
|
|
4377
4420
|
this._logger.info(`${this.namespaceLog} addStateToEnum not processed because Objects database not connected`);
|
|
4378
4421
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
4379
4422
|
}
|
|
@@ -4404,16 +4447,16 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4404
4447
|
stateName = stateName.replace(FORBIDDEN_CHARS, '_').replace(/\./g, '_');
|
|
4405
4448
|
const objId = this._utils.fixId({ device: parentDevice, channel: parentChannel, state: stateName });
|
|
4406
4449
|
if (addTo.startsWith('enum.')) {
|
|
4407
|
-
|
|
4450
|
+
this.#objects.getObject(addTo, options, (err, obj) => {
|
|
4408
4451
|
if (err || !obj) {
|
|
4409
4452
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, err || js_controller_common_1.tools.ERRORS.ERROR_NOT_FOUND);
|
|
4410
4453
|
}
|
|
4411
4454
|
if (!obj.common.members.includes(objId)) {
|
|
4412
4455
|
obj.common.members.push(objId);
|
|
4413
4456
|
obj.from = `system.adapter.${this.namespace}`;
|
|
4414
|
-
obj.user =
|
|
4457
|
+
obj.user = options?.user || constants_1.SYSTEM_ADMIN_USER;
|
|
4415
4458
|
obj.ts = Date.now();
|
|
4416
|
-
|
|
4459
|
+
this.#objects.setObject(obj._id, obj, options, callback);
|
|
4417
4460
|
}
|
|
4418
4461
|
else {
|
|
4419
4462
|
return js_controller_common_1.tools.maybeCallback(callback);
|
|
@@ -4424,15 +4467,15 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4424
4467
|
if (enumName.startsWith('enum.')) {
|
|
4425
4468
|
enumName = enumName.substring(5);
|
|
4426
4469
|
}
|
|
4427
|
-
|
|
4470
|
+
this.#objects.getObject(`enum.${enumName}.${addTo}`, options, (err, obj) => {
|
|
4428
4471
|
if (!err && obj) {
|
|
4429
4472
|
// @ts-expect-error cast to enum object
|
|
4430
4473
|
if (!obj.common.members.includes(objId)) {
|
|
4431
4474
|
obj.common.members.push(objId);
|
|
4432
4475
|
obj.from = `system.adapter.${this.namespace}`;
|
|
4433
|
-
obj.user =
|
|
4476
|
+
obj.user = options?.user || constants_1.SYSTEM_ADMIN_USER;
|
|
4434
4477
|
obj.ts = Date.now();
|
|
4435
|
-
|
|
4478
|
+
this.#objects.setObject(obj._id, obj, callback);
|
|
4436
4479
|
}
|
|
4437
4480
|
else {
|
|
4438
4481
|
return js_controller_common_1.tools.maybeCallback(callback);
|
|
@@ -4443,7 +4486,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4443
4486
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, err);
|
|
4444
4487
|
}
|
|
4445
4488
|
// Create enum
|
|
4446
|
-
|
|
4489
|
+
this.#objects.setObject(`enum.${enumName}.${addTo}`, {
|
|
4447
4490
|
common: {
|
|
4448
4491
|
name: addTo,
|
|
4449
4492
|
members: [objId]
|
|
@@ -4475,7 +4518,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4475
4518
|
_deleteStateFromEnum(_options) {
|
|
4476
4519
|
const { options, callback } = _options;
|
|
4477
4520
|
let { enumName, parentDevice, parentChannel, stateName } = _options;
|
|
4478
|
-
if (!
|
|
4521
|
+
if (!this.#objects) {
|
|
4479
4522
|
this._logger.info(`${this.namespaceLog} deleteStateFromEnum not processed because Objects database not connected`);
|
|
4480
4523
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
4481
4524
|
}
|
|
@@ -4515,7 +4558,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4515
4558
|
else {
|
|
4516
4559
|
enumName = 'enum.';
|
|
4517
4560
|
}
|
|
4518
|
-
|
|
4561
|
+
this.#objects.getObjectView('system', 'enum', {
|
|
4519
4562
|
startkey: enumName,
|
|
4520
4563
|
endkey: `${enumName}\u9999`
|
|
4521
4564
|
}, options, async (err, res) => {
|
|
@@ -4524,15 +4567,15 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4524
4567
|
}
|
|
4525
4568
|
for (const row of res.rows) {
|
|
4526
4569
|
try {
|
|
4527
|
-
const obj = await
|
|
4570
|
+
const obj = await this.#objects.getObjectAsync(row.id);
|
|
4528
4571
|
if (obj && obj.common && obj.common.members) {
|
|
4529
4572
|
const pos = obj.common.members.indexOf(objId);
|
|
4530
4573
|
if (pos !== -1) {
|
|
4531
4574
|
obj.common.members.splice(pos, 1);
|
|
4532
4575
|
obj.from = `system.adapter.${this.namespace}`;
|
|
4533
|
-
obj.user =
|
|
4576
|
+
obj.user = options?.user || constants_1.SYSTEM_ADMIN_USER;
|
|
4534
4577
|
obj.ts = Date.now();
|
|
4535
|
-
await
|
|
4578
|
+
await this.#objects.setObjectAsync(obj._id, obj);
|
|
4536
4579
|
}
|
|
4537
4580
|
}
|
|
4538
4581
|
}
|
|
@@ -4572,11 +4615,11 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4572
4615
|
callback = options;
|
|
4573
4616
|
options = null;
|
|
4574
4617
|
}
|
|
4575
|
-
if (!
|
|
4618
|
+
if (!this.#objects) {
|
|
4576
4619
|
this._logger.info(`${this.namespaceLog} chmodFile not processed because Objects database not connected`);
|
|
4577
4620
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
4578
4621
|
}
|
|
4579
|
-
|
|
4622
|
+
this.#objects.chmodFile(_adapter, path, options, callback);
|
|
4580
4623
|
}
|
|
4581
4624
|
/**
|
|
4582
4625
|
* Change a file owner
|
|
@@ -4607,11 +4650,11 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4607
4650
|
callback = options;
|
|
4608
4651
|
options = null;
|
|
4609
4652
|
}
|
|
4610
|
-
if (!
|
|
4653
|
+
if (!this.#objects) {
|
|
4611
4654
|
this._logger.info(`${this.namespaceLog} chownFile not processed because Objects database not connected`);
|
|
4612
4655
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
4613
4656
|
}
|
|
4614
|
-
|
|
4657
|
+
this.#objects.chownFile(_adapter, path, options, callback);
|
|
4615
4658
|
}
|
|
4616
4659
|
/**
|
|
4617
4660
|
* Read directory from DB.
|
|
@@ -4662,11 +4705,11 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4662
4705
|
if (options !== null && options !== undefined) {
|
|
4663
4706
|
validator_1.Validator.assertObject(options, 'options');
|
|
4664
4707
|
}
|
|
4665
|
-
if (!
|
|
4708
|
+
if (!this.#objects) {
|
|
4666
4709
|
this._logger.info(`${this.namespaceLog} readDir not processed because Objects database not connected`);
|
|
4667
4710
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
4668
4711
|
}
|
|
4669
|
-
|
|
4712
|
+
this.#objects.readDir(_adapter, path, options, callback);
|
|
4670
4713
|
}
|
|
4671
4714
|
unlink(_adapter, name, options, callback) {
|
|
4672
4715
|
if (_adapter === null) {
|
|
@@ -4682,11 +4725,11 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4682
4725
|
if (options !== undefined && options !== null) {
|
|
4683
4726
|
validator_1.Validator.assertObject(options, 'options');
|
|
4684
4727
|
}
|
|
4685
|
-
if (!
|
|
4728
|
+
if (!this.#objects) {
|
|
4686
4729
|
this._logger.info(`${this.namespaceLog} unlink not processed because Objects database not connected`);
|
|
4687
4730
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
4688
4731
|
}
|
|
4689
|
-
|
|
4732
|
+
this.#objects.unlink(_adapter, name, options, callback);
|
|
4690
4733
|
}
|
|
4691
4734
|
rename(_adapter, oldName, newName, options, callback) {
|
|
4692
4735
|
if (_adapter === null) {
|
|
@@ -4703,11 +4746,11 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4703
4746
|
if (options !== null && options !== undefined) {
|
|
4704
4747
|
validator_1.Validator.assertObject(options, 'options');
|
|
4705
4748
|
}
|
|
4706
|
-
if (!
|
|
4749
|
+
if (!this.#objects) {
|
|
4707
4750
|
this._logger.info(`${this.namespaceLog} rename not processed because Objects database not connected`);
|
|
4708
4751
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
4709
4752
|
}
|
|
4710
|
-
|
|
4753
|
+
this.#objects.rename(_adapter, oldName, newName, options, callback);
|
|
4711
4754
|
}
|
|
4712
4755
|
mkdir(_adapter, dirname, options, callback) {
|
|
4713
4756
|
if (_adapter === null) {
|
|
@@ -4723,11 +4766,11 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4723
4766
|
if (options !== undefined && options !== null) {
|
|
4724
4767
|
validator_1.Validator.assertObject(options, 'options');
|
|
4725
4768
|
}
|
|
4726
|
-
if (!
|
|
4769
|
+
if (!this.#objects) {
|
|
4727
4770
|
this._logger.info(`${this.namespaceLog} mkdir not processed because Objects database not connected`);
|
|
4728
4771
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
4729
4772
|
}
|
|
4730
|
-
|
|
4773
|
+
this.#objects.mkdir(_adapter, dirname, options, callback);
|
|
4731
4774
|
}
|
|
4732
4775
|
/**
|
|
4733
4776
|
* Read file from DB.
|
|
@@ -4765,11 +4808,11 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4765
4808
|
validator_1.Validator.assertObject(options, 'options');
|
|
4766
4809
|
}
|
|
4767
4810
|
validator_1.Validator.assertCallback(callback, 'callback');
|
|
4768
|
-
if (!
|
|
4811
|
+
if (!this.#objects) {
|
|
4769
4812
|
this._logger.info(`${this.namespaceLog} readFile not processed because Objects database not connected`);
|
|
4770
4813
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
4771
4814
|
}
|
|
4772
|
-
|
|
4815
|
+
this.#objects.readFile(_adapter, filename, options, callback);
|
|
4773
4816
|
}
|
|
4774
4817
|
/**
|
|
4775
4818
|
* Write file to DB.
|
|
@@ -4809,11 +4852,11 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4809
4852
|
if (typeof data !== 'string') {
|
|
4810
4853
|
validator_1.Validator.assertBuffer(data, 'data');
|
|
4811
4854
|
}
|
|
4812
|
-
if (!
|
|
4855
|
+
if (!this.#objects) {
|
|
4813
4856
|
this._logger.info(`${this.namespaceLog} writeFile not processed because Objects database not connected`);
|
|
4814
4857
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
4815
4858
|
}
|
|
4816
|
-
return
|
|
4859
|
+
return this.#objects.writeFile(_adapter, filename, data, options, callback);
|
|
4817
4860
|
}
|
|
4818
4861
|
/**
|
|
4819
4862
|
* Checks if file exists in DB.
|
|
@@ -4834,12 +4877,12 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
4834
4877
|
if (options !== null && options !== undefined) {
|
|
4835
4878
|
validator_1.Validator.assertObject(options, 'options');
|
|
4836
4879
|
}
|
|
4837
|
-
if (!
|
|
4880
|
+
if (!this.#objects) {
|
|
4838
4881
|
this._logger.info(`${this.namespaceLog} fileExists not processed because Objects database not connected`);
|
|
4839
4882
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
4840
4883
|
}
|
|
4841
4884
|
try {
|
|
4842
|
-
const exists = await
|
|
4885
|
+
const exists = await this.#objects.fileExists(_adapter, filename, options);
|
|
4843
4886
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, null, exists);
|
|
4844
4887
|
}
|
|
4845
4888
|
catch (e) {
|
|
@@ -5093,7 +5136,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5093
5136
|
if (!instanceName.startsWith('system.adapter.')) {
|
|
5094
5137
|
instanceName = `system.adapter.${instanceName}`;
|
|
5095
5138
|
}
|
|
5096
|
-
if (!
|
|
5139
|
+
if (!this.#states) {
|
|
5097
5140
|
// if states is no longer existing, we do not need to unsubscribe
|
|
5098
5141
|
this._logger.info(`${this.namespaceLog} sendTo not processed because States database not connected`);
|
|
5099
5142
|
// @ts-expect-error TODO it could also be the cb object
|
|
@@ -5107,21 +5150,21 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5107
5150
|
}
|
|
5108
5151
|
// If not specific instance
|
|
5109
5152
|
if (!instanceName.match(/\.[0-9]+$/)) {
|
|
5110
|
-
if (!
|
|
5153
|
+
if (!this.#objects) {
|
|
5111
5154
|
this._logger.info(`${this.namespaceLog} sendTo not processed because Objects database not connected`);
|
|
5112
5155
|
// @ts-expect-error TODO it could also be the cb object
|
|
5113
5156
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
5114
5157
|
}
|
|
5115
5158
|
try {
|
|
5116
5159
|
// Send to all instances of adapter
|
|
5117
|
-
const res = await
|
|
5160
|
+
const res = await this.#objects.getObjectView('system', 'instance', {
|
|
5118
5161
|
startkey: `${instanceName}.`,
|
|
5119
5162
|
endkey: `${instanceName}.\u9999`
|
|
5120
5163
|
});
|
|
5121
5164
|
if (res) {
|
|
5122
5165
|
for (const row of res.rows) {
|
|
5123
5166
|
try {
|
|
5124
|
-
await
|
|
5167
|
+
await this.#states.pushMessage(row.id, obj);
|
|
5125
5168
|
}
|
|
5126
5169
|
catch (e) {
|
|
5127
5170
|
// @ts-expect-error TODO it could also be the cb object
|
|
@@ -5140,7 +5183,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5140
5183
|
// force subscribe even no messagebox enabled
|
|
5141
5184
|
if (!(0, utils_1.isMessageboxSupported)(this.common) && !this.mboxSubscribed) {
|
|
5142
5185
|
this.mboxSubscribed = true;
|
|
5143
|
-
|
|
5186
|
+
this.#states.subscribeMessage(`system.adapter.${this.namespace}`);
|
|
5144
5187
|
}
|
|
5145
5188
|
obj.callback = {
|
|
5146
5189
|
message: message,
|
|
@@ -5153,7 +5196,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5153
5196
|
}
|
|
5154
5197
|
const callbackId = obj.callback.id;
|
|
5155
5198
|
let timer;
|
|
5156
|
-
if (options
|
|
5199
|
+
if (options?.timeout) {
|
|
5157
5200
|
timer = setTimeout(() => {
|
|
5158
5201
|
const callbackObj = this.messageCallbacks.get(callbackId);
|
|
5159
5202
|
if (callbackObj) {
|
|
@@ -5177,7 +5220,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5177
5220
|
}
|
|
5178
5221
|
}
|
|
5179
5222
|
try {
|
|
5180
|
-
await
|
|
5223
|
+
await this.#states.pushMessage(instanceName, obj);
|
|
5181
5224
|
}
|
|
5182
5225
|
catch (e) {
|
|
5183
5226
|
// @ts-expect-error TODO it could also be the cb object
|
|
@@ -5225,7 +5268,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5225
5268
|
const { command, message, callback } = _options;
|
|
5226
5269
|
let { hostName } = _options;
|
|
5227
5270
|
const obj = { command, message, from: `system.adapter.${this.namespace}` };
|
|
5228
|
-
if (!
|
|
5271
|
+
if (!this.#states) {
|
|
5229
5272
|
// if states is no longer existing, we do not need to unsubscribe
|
|
5230
5273
|
this._logger.info(`${this.namespaceLog} sendToHost not processed because States database not connected`);
|
|
5231
5274
|
// @ts-expect-error TODO it could also be the cb object
|
|
@@ -5235,27 +5278,27 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5235
5278
|
hostName = `system.host.${hostName}`;
|
|
5236
5279
|
}
|
|
5237
5280
|
if (!hostName) {
|
|
5238
|
-
if (!
|
|
5281
|
+
if (!this.#objects) {
|
|
5239
5282
|
this._logger.info(`${this.namespaceLog} sendToHost not processed because Objects database not connected`);
|
|
5240
5283
|
// @ts-expect-error TODO it could also be the cb object
|
|
5241
5284
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
5242
5285
|
}
|
|
5243
5286
|
// Send to all hosts
|
|
5244
|
-
|
|
5287
|
+
this.#objects.getObjectList({
|
|
5245
5288
|
startkey: 'system.host.',
|
|
5246
5289
|
endkey: `system.host.\u9999`
|
|
5247
5290
|
}, null, async (err, res) => {
|
|
5248
|
-
if (!
|
|
5291
|
+
if (!this.#states) {
|
|
5249
5292
|
// if states is no longer existing, we do not need to unsubscribe
|
|
5250
5293
|
return;
|
|
5251
5294
|
}
|
|
5252
|
-
if (!err &&
|
|
5295
|
+
if (!err && res?.rows.length) {
|
|
5253
5296
|
for (const row of res.rows) {
|
|
5254
5297
|
const parts = row.id.split('.');
|
|
5255
5298
|
// ignore system.host.name.alive and so on
|
|
5256
5299
|
if (parts.length === 3) {
|
|
5257
5300
|
try {
|
|
5258
|
-
await
|
|
5301
|
+
await this.#states.pushMessage(row.id, obj);
|
|
5259
5302
|
}
|
|
5260
5303
|
catch (e) {
|
|
5261
5304
|
// @ts-expect-error TODO it could also be the cb object
|
|
@@ -5272,7 +5315,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5272
5315
|
// force subscribe even no messagebox enabled
|
|
5273
5316
|
if (!(0, utils_1.isMessageboxSupported)(this.common) && !this.mboxSubscribed) {
|
|
5274
5317
|
this.mboxSubscribed = true;
|
|
5275
|
-
|
|
5318
|
+
this.#states.subscribeMessage(`system.adapter.${this.namespace}`);
|
|
5276
5319
|
}
|
|
5277
5320
|
obj.callback = {
|
|
5278
5321
|
message,
|
|
@@ -5291,7 +5334,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5291
5334
|
}
|
|
5292
5335
|
}
|
|
5293
5336
|
try {
|
|
5294
|
-
await
|
|
5337
|
+
await this.#states.pushMessage(hostName, obj);
|
|
5295
5338
|
}
|
|
5296
5339
|
catch (e) {
|
|
5297
5340
|
// @ts-expect-error TODO it could also be the cb object
|
|
@@ -5305,21 +5348,21 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5305
5348
|
* @param options clientId and data options
|
|
5306
5349
|
*/
|
|
5307
5350
|
sendToUI(options) {
|
|
5308
|
-
if (!
|
|
5351
|
+
if (!this.#states) {
|
|
5309
5352
|
throw new Error(js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
5310
5353
|
}
|
|
5311
5354
|
const { clientId, data } = options;
|
|
5312
5355
|
if (clientId === undefined) {
|
|
5313
5356
|
return this.uiMessagingController.sendToAllClients({
|
|
5314
5357
|
data,
|
|
5315
|
-
states:
|
|
5358
|
+
states: this.#states
|
|
5316
5359
|
});
|
|
5317
5360
|
}
|
|
5318
5361
|
validator_1.Validator.assertString(clientId, 'clientId');
|
|
5319
5362
|
return this.uiMessagingController.sendToClient({
|
|
5320
5363
|
clientId,
|
|
5321
5364
|
data,
|
|
5322
|
-
states:
|
|
5365
|
+
states: this.#states
|
|
5323
5366
|
});
|
|
5324
5367
|
}
|
|
5325
5368
|
/**
|
|
@@ -5330,7 +5373,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5330
5373
|
* @param message - message to be stored/checked
|
|
5331
5374
|
*/
|
|
5332
5375
|
async registerNotification(scope, category, message) {
|
|
5333
|
-
if (!
|
|
5376
|
+
if (!this.#states) {
|
|
5334
5377
|
// if states is no longer existing, we do not need to set
|
|
5335
5378
|
this._logger.info(`${this.namespaceLog} registerNotification not processed because States database not connected`);
|
|
5336
5379
|
throw new Error(js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
@@ -5345,7 +5388,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5345
5388
|
message: { scope, category, message, instance: this.namespace },
|
|
5346
5389
|
from: `system.adapter.${this.namespace}`
|
|
5347
5390
|
};
|
|
5348
|
-
await
|
|
5391
|
+
await this.#states.pushMessage(`system.host.${this.host}`, obj);
|
|
5349
5392
|
}
|
|
5350
5393
|
/**
|
|
5351
5394
|
* Writes value into states DB.
|
|
@@ -5406,15 +5449,14 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5406
5449
|
return this._setState({ id, state: state, ack, options, callback });
|
|
5407
5450
|
}
|
|
5408
5451
|
async _setState(_options) {
|
|
5409
|
-
var _a, _b;
|
|
5410
5452
|
const { state, ack, options, callback } = _options;
|
|
5411
5453
|
const { id } = _options;
|
|
5412
|
-
if (!
|
|
5454
|
+
if (!this.#states) {
|
|
5413
5455
|
// if states is no longer existing, we do not need to set
|
|
5414
5456
|
this._logger.info(`${this.namespaceLog} setState not processed because States database not connected`);
|
|
5415
5457
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
5416
5458
|
}
|
|
5417
|
-
if (!
|
|
5459
|
+
if (!this.#objects) {
|
|
5418
5460
|
this._logger.info(`${this.namespaceLog} setState not processed because Objects database not connected`);
|
|
5419
5461
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
5420
5462
|
}
|
|
@@ -5453,9 +5495,9 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5453
5495
|
typeof stateObj.from === 'string' && stateObj.from !== ''
|
|
5454
5496
|
? stateObj.from
|
|
5455
5497
|
: `system.adapter.${this.namespace}`;
|
|
5456
|
-
stateObj.user =
|
|
5498
|
+
stateObj.user = options?.user || constants_1.SYSTEM_ADMIN_USER;
|
|
5457
5499
|
let permCheckRequired = false;
|
|
5458
|
-
if (
|
|
5500
|
+
if (options?.user && options.user !== constants_1.SYSTEM_ADMIN_USER) {
|
|
5459
5501
|
permCheckRequired = true;
|
|
5460
5502
|
}
|
|
5461
5503
|
let obj;
|
|
@@ -5464,13 +5506,13 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5464
5506
|
obj = (await this._checkStates(fixedId, options || {}, 'setState')).objs[0];
|
|
5465
5507
|
}
|
|
5466
5508
|
else {
|
|
5467
|
-
obj = (await
|
|
5509
|
+
obj = (await this.#objects.getObject(fixedId, options));
|
|
5468
5510
|
}
|
|
5469
5511
|
}
|
|
5470
5512
|
catch (e) {
|
|
5471
5513
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, e);
|
|
5472
5514
|
}
|
|
5473
|
-
if (!
|
|
5515
|
+
if (!this.#objects) {
|
|
5474
5516
|
// if objects is no longer existing, we do not need to unsubscribe
|
|
5475
5517
|
this._logger.info(`${this.namespaceLog} setForeignState not processed because Objects database not connected`);
|
|
5476
5518
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
@@ -5481,7 +5523,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5481
5523
|
}
|
|
5482
5524
|
if (fixedId.startsWith(constants_1.ALIAS_STARTS_WITH)) {
|
|
5483
5525
|
// write alias
|
|
5484
|
-
if (
|
|
5526
|
+
if (obj?.common?.alias?.id) {
|
|
5485
5527
|
// id can be string or can have attribute write
|
|
5486
5528
|
const aliasId = js_controller_common_1.tools.isObject(obj.common.alias.id) ? obj.common.alias.id.write : obj.common.alias.id;
|
|
5487
5529
|
// validate here because we use objects/states db directly
|
|
@@ -5499,27 +5541,27 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5499
5541
|
targetObj = (await this._checkStates(aliasId, options || {}, 'setState')).objs[0];
|
|
5500
5542
|
}
|
|
5501
5543
|
else {
|
|
5502
|
-
targetObj = (await
|
|
5544
|
+
targetObj = (await this.#objects.getObject(aliasId, options));
|
|
5503
5545
|
}
|
|
5504
5546
|
}
|
|
5505
5547
|
catch (e) {
|
|
5506
5548
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, e);
|
|
5507
5549
|
}
|
|
5508
|
-
if (!
|
|
5550
|
+
if (!this.#states) {
|
|
5509
5551
|
// if states is no longer existing, we do not need to unsubscribe
|
|
5510
5552
|
this._logger.info(`${this.namespaceLog} setForeignState not processed because States database not connected`);
|
|
5511
5553
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
5512
5554
|
}
|
|
5513
5555
|
// write target state
|
|
5514
5556
|
this.outputCount++;
|
|
5515
|
-
return
|
|
5516
|
-
sourceCommon: obj
|
|
5517
|
-
targetCommon: targetObj
|
|
5557
|
+
return this.#states.setState(aliasId, js_controller_common_1.tools.formatAliasValue({
|
|
5558
|
+
sourceCommon: obj?.common,
|
|
5559
|
+
targetCommon: targetObj?.common,
|
|
5518
5560
|
state: stateObj,
|
|
5519
5561
|
logger: this._logger,
|
|
5520
5562
|
logNamespace: this.namespaceLog,
|
|
5521
|
-
sourceId: obj
|
|
5522
|
-
targetId: targetObj
|
|
5563
|
+
sourceId: obj?._id,
|
|
5564
|
+
targetId: targetObj?._id
|
|
5523
5565
|
}), callback);
|
|
5524
5566
|
}
|
|
5525
5567
|
else {
|
|
@@ -5528,18 +5570,17 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5528
5570
|
}
|
|
5529
5571
|
}
|
|
5530
5572
|
else {
|
|
5531
|
-
if (!
|
|
5573
|
+
if (!this.#states) {
|
|
5532
5574
|
// if states is no longer existing, we do not need to unsubscribe
|
|
5533
5575
|
this._logger.info(`${this.namespaceLog} setForeignState not processed because States database not connected`);
|
|
5534
5576
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
5535
5577
|
}
|
|
5536
5578
|
this.outputCount++;
|
|
5537
|
-
return
|
|
5579
|
+
return this.#states.setState(fixedId, stateObj, callback);
|
|
5538
5580
|
}
|
|
5539
5581
|
}
|
|
5540
5582
|
// Cache will be cleared if user or group changes. Important! only if subscribed.
|
|
5541
5583
|
async _getUserGroups(options) {
|
|
5542
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
5543
5584
|
if (this.users[options.user]) {
|
|
5544
5585
|
options.groups = this.users[options.user].groups;
|
|
5545
5586
|
options.acl = this.users[options.user].acl;
|
|
@@ -5578,17 +5619,17 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5578
5619
|
this.users[options.user] = {
|
|
5579
5620
|
groups: options.groups,
|
|
5580
5621
|
// @ts-expect-error TODO: UserCommon has no acl
|
|
5581
|
-
acl:
|
|
5622
|
+
acl: userAcl.common?.acl || {}
|
|
5582
5623
|
};
|
|
5583
5624
|
await this._getGroups(options.groups);
|
|
5584
5625
|
// combine all rights
|
|
5585
5626
|
const user = this.users[options.user];
|
|
5586
5627
|
for (const gName of options.groups) {
|
|
5587
|
-
if (!
|
|
5628
|
+
if (!this.groups[gName].common?.acl) {
|
|
5588
5629
|
continue;
|
|
5589
5630
|
}
|
|
5590
5631
|
const group = this.groups[gName];
|
|
5591
|
-
if (
|
|
5632
|
+
if (group.common?.acl?.file) {
|
|
5592
5633
|
if (!user.acl || !user.acl.file) {
|
|
5593
5634
|
user.acl = user.acl || {};
|
|
5594
5635
|
user.acl.file = user.acl.file || {};
|
|
@@ -5606,7 +5647,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5606
5647
|
user.acl.file.list = user.acl.file.list || group.common.acl.file.list;
|
|
5607
5648
|
}
|
|
5608
5649
|
}
|
|
5609
|
-
if (
|
|
5650
|
+
if (group.common?.acl?.object) {
|
|
5610
5651
|
if (!user.acl || !user.acl.object) {
|
|
5611
5652
|
user.acl = user.acl || {};
|
|
5612
5653
|
user.acl.object = user.acl.object || {};
|
|
@@ -5624,7 +5665,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5624
5665
|
user.acl.object.list = user.acl.object.list || group.common.acl.object.list;
|
|
5625
5666
|
}
|
|
5626
5667
|
}
|
|
5627
|
-
if (
|
|
5668
|
+
if (group.common?.acl?.users) {
|
|
5628
5669
|
if (!user.acl || !user.acl.users) {
|
|
5629
5670
|
user.acl = user.acl || {};
|
|
5630
5671
|
user.acl.users = user.acl.users || {};
|
|
@@ -5642,7 +5683,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5642
5683
|
user.acl.users.list = user.acl.users.list || group.common.acl.users.list;
|
|
5643
5684
|
}
|
|
5644
5685
|
}
|
|
5645
|
-
if (
|
|
5686
|
+
if (group.common?.acl?.state) {
|
|
5646
5687
|
if (!user.acl || !user.acl.state) {
|
|
5647
5688
|
user.acl = user.acl || {};
|
|
5648
5689
|
user.acl.state = user.acl.state || {};
|
|
@@ -5667,7 +5708,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5667
5708
|
}
|
|
5668
5709
|
_checkState(obj, options, command) {
|
|
5669
5710
|
const limitToOwnerRights = options.limitToOwnerRights === true;
|
|
5670
|
-
if (obj
|
|
5711
|
+
if (obj?.acl) {
|
|
5671
5712
|
obj.acl.state = obj.acl.state || obj.acl.object;
|
|
5672
5713
|
if (obj.acl.state) {
|
|
5673
5714
|
// If user is owner
|
|
@@ -5790,11 +5831,11 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5790
5831
|
originalChecked = options.checked;
|
|
5791
5832
|
}
|
|
5792
5833
|
options.checked = true;
|
|
5793
|
-
if (!
|
|
5834
|
+
if (!this.#objects) {
|
|
5794
5835
|
this._logger.info(`${this.namespaceLog} checkStates not processed because Objects database not connected`);
|
|
5795
5836
|
throw new Error(js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
5796
5837
|
}
|
|
5797
|
-
const obj = (await
|
|
5838
|
+
const obj = (await this.#objects.getObject(id, options));
|
|
5798
5839
|
objs.push(obj);
|
|
5799
5840
|
if (originalChecked !== undefined) {
|
|
5800
5841
|
options.checked = originalChecked;
|
|
@@ -5824,8 +5865,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5824
5865
|
}
|
|
5825
5866
|
}
|
|
5826
5867
|
async _setStateChangedHelper(id, state) {
|
|
5827
|
-
|
|
5828
|
-
if (!__classPrivateFieldGet(this, _AdapterClass_objects, "f")) {
|
|
5868
|
+
if (!this.#objects) {
|
|
5829
5869
|
this._logger.info(`${this.namespaceLog} setStateChanged not processed because Objects database not connected`);
|
|
5830
5870
|
throw new Error(js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
5831
5871
|
}
|
|
@@ -5833,12 +5873,12 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5833
5873
|
let obj;
|
|
5834
5874
|
let err;
|
|
5835
5875
|
try {
|
|
5836
|
-
obj = await
|
|
5876
|
+
obj = await this.#objects.getObject(id);
|
|
5837
5877
|
}
|
|
5838
5878
|
catch (e) {
|
|
5839
5879
|
err = e;
|
|
5840
5880
|
}
|
|
5841
|
-
if (
|
|
5881
|
+
if (obj?.common?.alias?.id) {
|
|
5842
5882
|
// id can be string or can have attribute write
|
|
5843
5883
|
const aliasId = js_controller_common_1.tools.isObject(obj.common.alias.id) ? obj.common.alias.id.write : obj.common.alias.id;
|
|
5844
5884
|
return this._setStateChangedHelper(aliasId, state);
|
|
@@ -5885,7 +5925,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5885
5925
|
await this._utils.performStrictObjectCheck(id, state);
|
|
5886
5926
|
}
|
|
5887
5927
|
this.outputCount++;
|
|
5888
|
-
await
|
|
5928
|
+
await this.#states.setState(id, state);
|
|
5889
5929
|
return { id, notChanged: false };
|
|
5890
5930
|
}
|
|
5891
5931
|
else {
|
|
@@ -5941,7 +5981,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5941
5981
|
}
|
|
5942
5982
|
async _setStateChanged(_options) {
|
|
5943
5983
|
const { id, ack, options, callback, state } = _options;
|
|
5944
|
-
if (!
|
|
5984
|
+
if (!this.#states) {
|
|
5945
5985
|
// if states is no longer existing, we do not need to unsubscribe
|
|
5946
5986
|
this._logger.info(`${this.namespaceLog} setStateChanged not processed because States database not connected`);
|
|
5947
5987
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
@@ -5981,7 +6021,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
5981
6021
|
typeof stateObj.from === 'string' && stateObj.from !== ''
|
|
5982
6022
|
? stateObj.from
|
|
5983
6023
|
: `system.adapter.${this.namespace}`;
|
|
5984
|
-
if (
|
|
6024
|
+
if (options?.user && options.user !== constants_1.SYSTEM_ADMIN_USER) {
|
|
5985
6025
|
try {
|
|
5986
6026
|
await this._checkStates(fixedId, options, 'setState');
|
|
5987
6027
|
}
|
|
@@ -6029,7 +6069,6 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6029
6069
|
* ```
|
|
6030
6070
|
*/
|
|
6031
6071
|
async setForeignState(id, state, ack, options, callback) {
|
|
6032
|
-
var _a, _b, _c, _d;
|
|
6033
6072
|
if (typeof state === 'object' && typeof ack !== 'boolean') {
|
|
6034
6073
|
callback = options;
|
|
6035
6074
|
options = ack;
|
|
@@ -6043,7 +6082,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6043
6082
|
callback = ack;
|
|
6044
6083
|
ack = undefined;
|
|
6045
6084
|
}
|
|
6046
|
-
if (!
|
|
6085
|
+
if (!this.#states) {
|
|
6047
6086
|
// if states is no longer existing, we do not need to unsubscribe
|
|
6048
6087
|
this._logger.info(`${this.namespaceLog} setForeignState not processed because States database not connected`);
|
|
6049
6088
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
@@ -6079,14 +6118,14 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6079
6118
|
// if state.from provided, we use it else, we set default property
|
|
6080
6119
|
state.from =
|
|
6081
6120
|
typeof state.from === 'string' && state.from !== '' ? state.from : `system.adapter.${this.namespace}`;
|
|
6082
|
-
state.user =
|
|
6121
|
+
state.user = options?.user || constants_1.SYSTEM_ADMIN_USER;
|
|
6083
6122
|
if (!id || typeof id !== 'string') {
|
|
6084
6123
|
const warn = id ? `ID can be only string and not "${typeof id}"` : `Empty ID: ${JSON.stringify(state)}`;
|
|
6085
6124
|
this._logger.warn(`${this.namespaceLog} ${warn}`);
|
|
6086
6125
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, warn);
|
|
6087
6126
|
}
|
|
6088
6127
|
id = this.fixForbiddenCharsInId(id);
|
|
6089
|
-
if (
|
|
6128
|
+
if (options?.user && options.user !== constants_1.SYSTEM_ADMIN_USER) {
|
|
6090
6129
|
let obj;
|
|
6091
6130
|
try {
|
|
6092
6131
|
obj = (await this._checkStates(id, options, 'setState')).objs[0];
|
|
@@ -6094,7 +6133,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6094
6133
|
catch (e) {
|
|
6095
6134
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, e);
|
|
6096
6135
|
}
|
|
6097
|
-
if (!
|
|
6136
|
+
if (!this.#states) {
|
|
6098
6137
|
// if states is no longer existing, we do not need to unsubscribe
|
|
6099
6138
|
this._logger.info(`${this.namespaceLog} setForeignState not processed because States database not connected`);
|
|
6100
6139
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
@@ -6105,7 +6144,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6105
6144
|
}
|
|
6106
6145
|
if (id.startsWith(constants_1.ALIAS_STARTS_WITH)) {
|
|
6107
6146
|
// write alias
|
|
6108
|
-
if (
|
|
6147
|
+
if (obj?.common?.alias?.id) {
|
|
6109
6148
|
// id can be string or can have attribute write
|
|
6110
6149
|
const aliasId = js_controller_common_1.tools.isObject(obj.common.alias.id)
|
|
6111
6150
|
? obj.common.alias.id.write
|
|
@@ -6126,20 +6165,20 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6126
6165
|
catch (e) {
|
|
6127
6166
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, e);
|
|
6128
6167
|
}
|
|
6129
|
-
if (!
|
|
6168
|
+
if (!this.#states) {
|
|
6130
6169
|
// if states is no longer existing, we do not need to unsubscribe
|
|
6131
6170
|
this._logger.info(`${this.namespaceLog} setForeignState not processed because States database not connected`);
|
|
6132
6171
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
6133
6172
|
}
|
|
6134
6173
|
this.outputCount++;
|
|
6135
|
-
|
|
6136
|
-
sourceCommon: obj
|
|
6174
|
+
this.#states.setState(aliasId, js_controller_common_1.tools.formatAliasValue({
|
|
6175
|
+
sourceCommon: obj?.common,
|
|
6137
6176
|
targetCommon: targetObj && targetObj.common,
|
|
6138
6177
|
state,
|
|
6139
6178
|
logger: this._logger,
|
|
6140
6179
|
logNamespace: this.namespaceLog,
|
|
6141
|
-
sourceId: obj
|
|
6142
|
-
targetId: targetObj
|
|
6180
|
+
sourceId: obj?._id,
|
|
6181
|
+
targetId: targetObj?._id
|
|
6143
6182
|
}), callback);
|
|
6144
6183
|
}
|
|
6145
6184
|
else {
|
|
@@ -6148,25 +6187,25 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6148
6187
|
}
|
|
6149
6188
|
}
|
|
6150
6189
|
else {
|
|
6151
|
-
if (!
|
|
6190
|
+
if (!this.#states) {
|
|
6152
6191
|
// if states is no longer existing, we do not need to unsubscribe
|
|
6153
6192
|
this._logger.info(`${this.namespaceLog} setForeignState not processed because States database not connected`);
|
|
6154
6193
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
6155
6194
|
}
|
|
6156
6195
|
this.outputCount++;
|
|
6157
|
-
|
|
6196
|
+
this.#states.setState(id, state, callback);
|
|
6158
6197
|
}
|
|
6159
6198
|
}
|
|
6160
6199
|
else {
|
|
6161
6200
|
// write alias
|
|
6162
6201
|
if (id.startsWith(constants_1.ALIAS_STARTS_WITH)) {
|
|
6163
|
-
if (!
|
|
6202
|
+
if (!this.#objects) {
|
|
6164
6203
|
this._logger.info(`${this.namespaceLog} setForeignState not processed because Objects database not connected`);
|
|
6165
6204
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
6166
6205
|
}
|
|
6167
6206
|
// read alias id
|
|
6168
|
-
const obj = (await
|
|
6169
|
-
if (
|
|
6207
|
+
const obj = (await this.#objects.getObjectAsync(id, options));
|
|
6208
|
+
if (obj?.common?.alias?.id) {
|
|
6170
6209
|
// alias id can be a string or can have id.write
|
|
6171
6210
|
const aliasId = js_controller_common_1.tools.isObject(obj.common.alias.id)
|
|
6172
6211
|
? obj.common.alias.id.write
|
|
@@ -6179,27 +6218,27 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6179
6218
|
this._logger.warn(`${this.namespaceLog} Error validating alias id of ${id}: ${e.message}`);
|
|
6180
6219
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, `Error validating alias id of ${id}: ${e.message}`);
|
|
6181
6220
|
}
|
|
6182
|
-
if (!
|
|
6221
|
+
if (!this.#objects) {
|
|
6183
6222
|
// if objects is no longer existing, we do not need to unsubscribe
|
|
6184
6223
|
this._logger.info(`${this.namespaceLog} setForeignState not processed because Objects database not connected`);
|
|
6185
6224
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
6186
6225
|
}
|
|
6187
6226
|
// read object for formatting
|
|
6188
|
-
|
|
6189
|
-
if (!
|
|
6227
|
+
this.#objects.getObject(aliasId, options, (err, targetObj) => {
|
|
6228
|
+
if (!this.#states) {
|
|
6190
6229
|
// if states is no longer existing, we do not need to unsubscribe
|
|
6191
6230
|
this._logger.info(`${this.namespaceLog} setForeignState not processed because States database not connected`);
|
|
6192
6231
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
6193
6232
|
}
|
|
6194
6233
|
this.outputCount++;
|
|
6195
|
-
|
|
6234
|
+
this.#states.setState(aliasId, js_controller_common_1.tools.formatAliasValue({
|
|
6196
6235
|
sourceCommon: obj.common,
|
|
6197
|
-
targetCommon: targetObj
|
|
6236
|
+
targetCommon: targetObj?.common,
|
|
6198
6237
|
state,
|
|
6199
6238
|
logger: this._logger,
|
|
6200
6239
|
logNamespace: this.namespaceLog,
|
|
6201
6240
|
sourceId: obj._id,
|
|
6202
|
-
targetId: targetObj
|
|
6241
|
+
targetId: targetObj?._id
|
|
6203
6242
|
}), callback);
|
|
6204
6243
|
});
|
|
6205
6244
|
}
|
|
@@ -6210,7 +6249,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6210
6249
|
}
|
|
6211
6250
|
else {
|
|
6212
6251
|
if (this.performStrictObjectChecks) {
|
|
6213
|
-
if (!
|
|
6252
|
+
if (!this.#objects) {
|
|
6214
6253
|
// if objects is no longer existing, we do not need to unsubscribe
|
|
6215
6254
|
this._logger.info(`${this.namespaceLog} setForeignState not processed because Objects database not connected`);
|
|
6216
6255
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
@@ -6218,13 +6257,13 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6218
6257
|
// validate that object exists, read-only logic ok, type ok, etc. won't throw now
|
|
6219
6258
|
await this._utils.performStrictObjectCheck(id, state);
|
|
6220
6259
|
}
|
|
6221
|
-
if (!
|
|
6260
|
+
if (!this.#states) {
|
|
6222
6261
|
// if states is no longer existing, we do not need to unsubscribe
|
|
6223
6262
|
this._logger.info(`${this.namespaceLog} setForeignState not processed because States database not connected`);
|
|
6224
6263
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
6225
6264
|
}
|
|
6226
6265
|
this.outputCount++;
|
|
6227
|
-
|
|
6266
|
+
this.#states.setState(id, state, callback);
|
|
6228
6267
|
}
|
|
6229
6268
|
}
|
|
6230
6269
|
}
|
|
@@ -6272,7 +6311,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6272
6311
|
callback = ack;
|
|
6273
6312
|
ack = undefined;
|
|
6274
6313
|
}
|
|
6275
|
-
if (!
|
|
6314
|
+
if (!this.#states) {
|
|
6276
6315
|
// if states is no longer existing, we do not need to unsubscribe
|
|
6277
6316
|
this._logger.info(`${this.namespaceLog} setForeignStateChanged not processed because States database not connected`);
|
|
6278
6317
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
@@ -6308,9 +6347,9 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6308
6347
|
// if state.from provided, we use it else, we set default property
|
|
6309
6348
|
state.from =
|
|
6310
6349
|
typeof state.from === 'string' && state.from !== '' ? state.from : `system.adapter.${this.namespace}`;
|
|
6311
|
-
state.user =
|
|
6350
|
+
state.user = options?.user || constants_1.SYSTEM_ADMIN_USER;
|
|
6312
6351
|
id = this.fixForbiddenCharsInId(id);
|
|
6313
|
-
if (
|
|
6352
|
+
if (options?.user && options.user !== constants_1.SYSTEM_ADMIN_USER) {
|
|
6314
6353
|
try {
|
|
6315
6354
|
await this._checkStates(id, options, 'setState');
|
|
6316
6355
|
}
|
|
@@ -6380,14 +6419,13 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6380
6419
|
return this._getForeignState({ id, options, callback });
|
|
6381
6420
|
}
|
|
6382
6421
|
async _getForeignState(_options) {
|
|
6383
|
-
var _a, _b;
|
|
6384
6422
|
const { id, options, callback } = _options;
|
|
6385
|
-
if (!
|
|
6423
|
+
if (!this.#states) {
|
|
6386
6424
|
// if states is no longer existing, we do not need to unsubscribe
|
|
6387
6425
|
this._logger.info(`${this.namespaceLog} getForeignState not processed because States database not connected`);
|
|
6388
6426
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
6389
6427
|
}
|
|
6390
|
-
if (!
|
|
6428
|
+
if (!this.#objects) {
|
|
6391
6429
|
this._logger.info(`${this.namespaceLog} getForeignState not processed because Objects database not connected`);
|
|
6392
6430
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
6393
6431
|
}
|
|
@@ -6398,7 +6436,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6398
6436
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, err);
|
|
6399
6437
|
}
|
|
6400
6438
|
let permCheckRequired = false;
|
|
6401
|
-
if (
|
|
6439
|
+
if (options?.user && options.user !== constants_1.SYSTEM_ADMIN_USER) {
|
|
6402
6440
|
permCheckRequired = true;
|
|
6403
6441
|
}
|
|
6404
6442
|
let obj;
|
|
@@ -6407,7 +6445,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6407
6445
|
obj = (await this._checkStates(id, options || {}, 'getState')).objs[0];
|
|
6408
6446
|
}
|
|
6409
6447
|
else {
|
|
6410
|
-
obj = (await
|
|
6448
|
+
obj = (await this.#objects.getObject(id, options));
|
|
6411
6449
|
}
|
|
6412
6450
|
}
|
|
6413
6451
|
catch (e) {
|
|
@@ -6415,7 +6453,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6415
6453
|
}
|
|
6416
6454
|
if (id.startsWith(constants_1.ALIAS_STARTS_WITH)) {
|
|
6417
6455
|
// TODO: optimize alias GET performance
|
|
6418
|
-
if (
|
|
6456
|
+
if (obj?.common?.alias?.id) {
|
|
6419
6457
|
// id can be string or can have attribute id.read
|
|
6420
6458
|
const aliasId = js_controller_common_1.tools.isObject(obj.common.alias.id) ? obj.common.alias.id.read : obj.common.alias.id;
|
|
6421
6459
|
// validate here because we use objects/states db directly
|
|
@@ -6433,7 +6471,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6433
6471
|
sourceObj = (await this._checkStates(aliasId, options || {}, 'getState')).objs[0];
|
|
6434
6472
|
}
|
|
6435
6473
|
else {
|
|
6436
|
-
sourceObj = (await
|
|
6474
|
+
sourceObj = (await this.#objects.getObject(aliasId, options));
|
|
6437
6475
|
}
|
|
6438
6476
|
}
|
|
6439
6477
|
catch (e) {
|
|
@@ -6447,19 +6485,19 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6447
6485
|
this.inputCount++;
|
|
6448
6486
|
try {
|
|
6449
6487
|
// @ts-expect-error void return possible fix it
|
|
6450
|
-
state = await
|
|
6488
|
+
state = await this.#states.getState(aliasId);
|
|
6451
6489
|
}
|
|
6452
6490
|
catch (e) {
|
|
6453
6491
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, e);
|
|
6454
6492
|
}
|
|
6455
6493
|
}
|
|
6456
6494
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, null, js_controller_common_1.tools.formatAliasValue({
|
|
6457
|
-
sourceCommon: sourceObj
|
|
6495
|
+
sourceCommon: sourceObj?.common,
|
|
6458
6496
|
targetCommon: obj.common,
|
|
6459
6497
|
state,
|
|
6460
6498
|
logger: this._logger,
|
|
6461
6499
|
logNamespace: this.namespaceLog,
|
|
6462
|
-
sourceId: sourceObj
|
|
6500
|
+
sourceId: sourceObj?._id,
|
|
6463
6501
|
targetId: obj._id
|
|
6464
6502
|
}));
|
|
6465
6503
|
}
|
|
@@ -6474,13 +6512,12 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6474
6512
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, null, this.oStates[id]);
|
|
6475
6513
|
}
|
|
6476
6514
|
else {
|
|
6477
|
-
return
|
|
6515
|
+
return this.#states.getState(id, callback);
|
|
6478
6516
|
}
|
|
6479
6517
|
}
|
|
6480
6518
|
}
|
|
6481
6519
|
// find out default history instance
|
|
6482
6520
|
async _getDefaultHistory() {
|
|
6483
|
-
var _a;
|
|
6484
6521
|
if (!this.defaultHistory) {
|
|
6485
6522
|
// read default history instance from system.config
|
|
6486
6523
|
let data;
|
|
@@ -6490,10 +6527,10 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6490
6527
|
catch {
|
|
6491
6528
|
// ignore
|
|
6492
6529
|
}
|
|
6493
|
-
if (data
|
|
6530
|
+
if (data?.common) {
|
|
6494
6531
|
this.defaultHistory = data.common.defaultHistory;
|
|
6495
6532
|
}
|
|
6496
|
-
if (data
|
|
6533
|
+
if (data?.native) {
|
|
6497
6534
|
this._systemSecret = data.native.secret;
|
|
6498
6535
|
}
|
|
6499
6536
|
// if no default history set
|
|
@@ -6501,7 +6538,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6501
6538
|
let _obj;
|
|
6502
6539
|
// read all adapters
|
|
6503
6540
|
try {
|
|
6504
|
-
_obj = await
|
|
6541
|
+
_obj = await this.#objects.getObjectViewAsync('system', 'instance', {
|
|
6505
6542
|
startkey: 'system.adapter.',
|
|
6506
6543
|
endkey: 'system.adapter.\u9999'
|
|
6507
6544
|
});
|
|
@@ -6509,9 +6546,9 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6509
6546
|
catch {
|
|
6510
6547
|
// ignore
|
|
6511
6548
|
}
|
|
6512
|
-
if (_obj
|
|
6549
|
+
if (_obj?.rows) {
|
|
6513
6550
|
for (const row of _obj.rows) {
|
|
6514
|
-
if (
|
|
6551
|
+
if (row.value?.common && row.value.common.type === 'storage') {
|
|
6515
6552
|
this.defaultHistory = row.id.substring('system.adapter.'.length);
|
|
6516
6553
|
break;
|
|
6517
6554
|
}
|
|
@@ -6697,7 +6734,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6697
6734
|
}
|
|
6698
6735
|
async _delForeignState(_options) {
|
|
6699
6736
|
const { id, options, callback } = _options;
|
|
6700
|
-
if (!
|
|
6737
|
+
if (!this.#states) {
|
|
6701
6738
|
// if states is no longer existing, we do not need to unsubscribe
|
|
6702
6739
|
this._logger.info(`${this.namespaceLog} delForeignState not processed because States database not connected`);
|
|
6703
6740
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
@@ -6708,7 +6745,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6708
6745
|
catch (err) {
|
|
6709
6746
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, err);
|
|
6710
6747
|
}
|
|
6711
|
-
if (
|
|
6748
|
+
if (options?.user && options.user !== constants_1.SYSTEM_ADMIN_USER) {
|
|
6712
6749
|
try {
|
|
6713
6750
|
await this._checkStates(id, options, 'delState');
|
|
6714
6751
|
}
|
|
@@ -6716,7 +6753,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6716
6753
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, e);
|
|
6717
6754
|
}
|
|
6718
6755
|
}
|
|
6719
|
-
|
|
6756
|
+
this.#states.delState(id, callback);
|
|
6720
6757
|
}
|
|
6721
6758
|
/**
|
|
6722
6759
|
* Read all states of this adapter, that pass the pattern
|
|
@@ -6748,12 +6785,11 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6748
6785
|
this.getForeignStates(fixedPattern, options, callback);
|
|
6749
6786
|
}
|
|
6750
6787
|
async _processStatesSecondary(keys, targetObjs, srcObjs) {
|
|
6751
|
-
|
|
6752
|
-
const arr = await __classPrivateFieldGet(this, _AdapterClass_states, "f").getStates(keys);
|
|
6788
|
+
const arr = await this.#states.getStates(keys);
|
|
6753
6789
|
const result = {};
|
|
6754
6790
|
for (let i = 0; i < keys.length; i++) {
|
|
6755
6791
|
const obj = targetObjs && targetObjs[i];
|
|
6756
|
-
if (
|
|
6792
|
+
if (obj?.common?.alias && srcObjs) {
|
|
6757
6793
|
const srcObj = srcObjs[i];
|
|
6758
6794
|
if (srcObj) {
|
|
6759
6795
|
result[obj._id] =
|
|
@@ -6772,7 +6808,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6772
6808
|
}
|
|
6773
6809
|
}
|
|
6774
6810
|
else {
|
|
6775
|
-
result[
|
|
6811
|
+
result[obj?._id || keys[i]] = arr[i] || null;
|
|
6776
6812
|
}
|
|
6777
6813
|
}
|
|
6778
6814
|
// @ts-expect-error adapt the return type?
|
|
@@ -6786,7 +6822,6 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6786
6822
|
* @param targetObjs the target objects (e.g. alias objects or the actual objects)
|
|
6787
6823
|
*/
|
|
6788
6824
|
async _processStates(keys, targetObjs) {
|
|
6789
|
-
var _a;
|
|
6790
6825
|
const aliasIndexes = [];
|
|
6791
6826
|
const aliasIds = [];
|
|
6792
6827
|
/** Target objects with null placeholders for non-alias keys */
|
|
@@ -6814,7 +6849,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6814
6849
|
const obj = targetObjs[i];
|
|
6815
6850
|
const aliasIdx = aliasIndexes[i];
|
|
6816
6851
|
fullTargetObjs[aliasIdx] = obj;
|
|
6817
|
-
if (
|
|
6852
|
+
if (obj?.common?.alias) {
|
|
6818
6853
|
// alias id can be string or can have attribute read (this is used by getStates -> so read is important)
|
|
6819
6854
|
keys[aliasIdx] =
|
|
6820
6855
|
js_controller_common_1.tools.isObject(obj.common.alias.id) && 'read' in obj.common.alias.id
|
|
@@ -6867,12 +6902,12 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6867
6902
|
}
|
|
6868
6903
|
async _getForeignStates(_options) {
|
|
6869
6904
|
const { options, pattern, callback } = _options;
|
|
6870
|
-
if (!
|
|
6905
|
+
if (!this.#states) {
|
|
6871
6906
|
// if states is no longer existing, we do not need to unsubscribe
|
|
6872
6907
|
this._logger.info(`${this.namespaceLog} getForeignStates not processed because States database not connected`);
|
|
6873
6908
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
6874
6909
|
}
|
|
6875
|
-
if (!
|
|
6910
|
+
if (!this.#objects) {
|
|
6876
6911
|
// if states is no longer existing, we do not need to unsubscribe
|
|
6877
6912
|
this._logger.info(`${this.namespaceLog} getForeignStates not processed because Objects database not connected`);
|
|
6878
6913
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
@@ -6890,7 +6925,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6890
6925
|
}
|
|
6891
6926
|
}
|
|
6892
6927
|
else {
|
|
6893
|
-
const res = await this._processStates(pattern, options
|
|
6928
|
+
const res = await this._processStates(pattern, options?._objects);
|
|
6894
6929
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, null, res);
|
|
6895
6930
|
}
|
|
6896
6931
|
}
|
|
@@ -6911,7 +6946,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6911
6946
|
// in special maintenance mode, just returns all states. Aliases are not supported in this mode
|
|
6912
6947
|
if (options.user === constants_1.SYSTEM_ADMIN_USER && options.maintenance) {
|
|
6913
6948
|
try {
|
|
6914
|
-
const keys = await
|
|
6949
|
+
const keys = await this.#states.getKeys(pattern);
|
|
6915
6950
|
const res = await this._processStatesSecondary(keys || [], null, null);
|
|
6916
6951
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, null, res);
|
|
6917
6952
|
}
|
|
@@ -6920,7 +6955,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
6920
6955
|
}
|
|
6921
6956
|
}
|
|
6922
6957
|
try {
|
|
6923
|
-
const res = await
|
|
6958
|
+
const res = await this.#objects.getObjectView('system', 'state', params, options);
|
|
6924
6959
|
if (originalChecked !== undefined) {
|
|
6925
6960
|
options.checked = originalChecked;
|
|
6926
6961
|
}
|
|
@@ -7001,13 +7036,13 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7001
7036
|
if (!aliasDetails.source) {
|
|
7002
7037
|
let sourceObj;
|
|
7003
7038
|
try {
|
|
7004
|
-
await
|
|
7005
|
-
sourceObj = await
|
|
7039
|
+
await this.#states.subscribe(sourceId);
|
|
7040
|
+
sourceObj = await this.#objects.getObject(sourceId, this._options);
|
|
7006
7041
|
}
|
|
7007
7042
|
catch (e) {
|
|
7008
7043
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, e);
|
|
7009
7044
|
}
|
|
7010
|
-
if (sourceObj
|
|
7045
|
+
if (sourceObj?.common) {
|
|
7011
7046
|
if (!this.aliases.has(sourceObj._id)) {
|
|
7012
7047
|
// TODO what means this, we ensured alias existed, did some async stuff now it's gone -> alias has been deleted?
|
|
7013
7048
|
this._logger.error(`${this.namespaceLog} Alias subscription error. Please check your alias definitions: sourceId=${sourceId}, sourceObj=${JSON.stringify(sourceObj)}`);
|
|
@@ -7047,7 +7082,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7047
7082
|
// unsubscribe if no more aliases exists
|
|
7048
7083
|
if (!this.aliases.get(sourceId).targets.length) {
|
|
7049
7084
|
this.aliases.delete(sourceId);
|
|
7050
|
-
await
|
|
7085
|
+
await this.#states.unsubscribe(sourceId);
|
|
7051
7086
|
}
|
|
7052
7087
|
}
|
|
7053
7088
|
return js_controller_common_1.tools.maybeCallback(callback);
|
|
@@ -7084,12 +7119,12 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7084
7119
|
const { pattern, options, callback } = _options;
|
|
7085
7120
|
// Todo check rights for options
|
|
7086
7121
|
await this._autoSubscribeOn();
|
|
7087
|
-
if (!
|
|
7122
|
+
if (!this.#states) {
|
|
7088
7123
|
// if states is no longer existing, we do not need to unsubscribe
|
|
7089
7124
|
this._logger.info(`${this.namespaceLog} subscribeForeignStates not processed because States database not connected`);
|
|
7090
7125
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
7091
7126
|
}
|
|
7092
|
-
if (!
|
|
7127
|
+
if (!this.#objects) {
|
|
7093
7128
|
this._logger.info(`${this.namespaceLog} subscribeForeignStates not processed because Objects database not connected`);
|
|
7094
7129
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
7095
7130
|
}
|
|
@@ -7099,7 +7134,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7099
7134
|
// put this pattern into adapter list
|
|
7100
7135
|
let state;
|
|
7101
7136
|
try {
|
|
7102
|
-
state = await
|
|
7137
|
+
state = await this.#states.getState(`system.adapter.${autoSubEntry}.subscribes`);
|
|
7103
7138
|
}
|
|
7104
7139
|
catch {
|
|
7105
7140
|
// ignore
|
|
@@ -7125,7 +7160,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7125
7160
|
}
|
|
7126
7161
|
subs[pattern][this.namespace]++;
|
|
7127
7162
|
this.outputCount++;
|
|
7128
|
-
|
|
7163
|
+
this.#states.setState(`system.adapter.${autoSubEntry}.subscribes`, JSON.stringify(subs));
|
|
7129
7164
|
}
|
|
7130
7165
|
}
|
|
7131
7166
|
if (Array.isArray(pattern)) {
|
|
@@ -7148,7 +7183,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7148
7183
|
if (aliasesIds.length) {
|
|
7149
7184
|
if (!this._aliasObjectsSubscribed) {
|
|
7150
7185
|
this._aliasObjectsSubscribed = true;
|
|
7151
|
-
|
|
7186
|
+
this.#objects.subscribe(`${constants_1.ALIAS_STARTS_WITH}*`);
|
|
7152
7187
|
}
|
|
7153
7188
|
const aliasObjs = await this._getObjectsByArray(aliasesIds, options);
|
|
7154
7189
|
for (const aliasObj of aliasObjs) {
|
|
@@ -7160,7 +7195,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7160
7195
|
}
|
|
7161
7196
|
if (nonAliasesIds.length) {
|
|
7162
7197
|
for (const id of nonAliasesIds) {
|
|
7163
|
-
promises.push(new Promise(resolve =>
|
|
7198
|
+
promises.push(new Promise(resolve => this.#states.subscribeUser(id, resolve)));
|
|
7164
7199
|
}
|
|
7165
7200
|
}
|
|
7166
7201
|
try {
|
|
@@ -7175,7 +7210,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7175
7210
|
if (pattern === '*' || pattern.startsWith(constants_1.ALIAS_STARTS_WITH)) {
|
|
7176
7211
|
if (!this._aliasObjectsSubscribed) {
|
|
7177
7212
|
this._aliasObjectsSubscribed = true;
|
|
7178
|
-
|
|
7213
|
+
this.#objects.subscribe(`${constants_1.ALIAS_STARTS_WITH}*`);
|
|
7179
7214
|
}
|
|
7180
7215
|
// read all aliases
|
|
7181
7216
|
try {
|
|
@@ -7200,7 +7235,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7200
7235
|
catch (e) {
|
|
7201
7236
|
this._logger.error(`${this.namespaceLog} Error on "subscribeForeignStates": ${e.message}`);
|
|
7202
7237
|
}
|
|
7203
|
-
if (!
|
|
7238
|
+
if (!this.#states) {
|
|
7204
7239
|
// if states is no longer existing, we do not need to unsubscribe
|
|
7205
7240
|
this._logger.info(`${this.namespaceLog} subscribeForeignStates not processed because States database not connected`);
|
|
7206
7241
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
@@ -7210,7 +7245,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7210
7245
|
}
|
|
7211
7246
|
else {
|
|
7212
7247
|
// no alias objects found or pattern *
|
|
7213
|
-
|
|
7248
|
+
this.#states.subscribeUser(pattern, callback);
|
|
7214
7249
|
}
|
|
7215
7250
|
}
|
|
7216
7251
|
catch (e) {
|
|
@@ -7219,13 +7254,13 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7219
7254
|
}
|
|
7220
7255
|
}
|
|
7221
7256
|
else {
|
|
7222
|
-
|
|
7257
|
+
this.#states.subscribeUser(pattern, callback);
|
|
7223
7258
|
}
|
|
7224
7259
|
}
|
|
7225
7260
|
else if (pattern.startsWith(constants_1.ALIAS_STARTS_WITH)) {
|
|
7226
7261
|
if (!this._aliasObjectsSubscribed) {
|
|
7227
7262
|
this._aliasObjectsSubscribed = true;
|
|
7228
|
-
|
|
7263
|
+
this.#objects.subscribe(`${constants_1.ALIAS_STARTS_WITH}*`);
|
|
7229
7264
|
}
|
|
7230
7265
|
// aliases['sourceId'] = {
|
|
7231
7266
|
// source: {common attributes},
|
|
@@ -7242,7 +7277,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7242
7277
|
// };
|
|
7243
7278
|
// just read one alias Object
|
|
7244
7279
|
try {
|
|
7245
|
-
const aliasObj = await
|
|
7280
|
+
const aliasObj = await this.#objects.getObjectAsync(pattern, options);
|
|
7246
7281
|
if (aliasObj) {
|
|
7247
7282
|
// cb will be called, but await for catching promisified part
|
|
7248
7283
|
await this._addAliasSubscribe(aliasObj, pattern, callback);
|
|
@@ -7256,7 +7291,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7256
7291
|
}
|
|
7257
7292
|
}
|
|
7258
7293
|
else {
|
|
7259
|
-
|
|
7294
|
+
this.#states.subscribeUser(pattern, callback);
|
|
7260
7295
|
}
|
|
7261
7296
|
}
|
|
7262
7297
|
/**
|
|
@@ -7295,7 +7330,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7295
7330
|
}
|
|
7296
7331
|
async _unsubscribeForeignStates(_options) {
|
|
7297
7332
|
const { pattern, callback } = _options;
|
|
7298
|
-
if (!
|
|
7333
|
+
if (!this.#states) {
|
|
7299
7334
|
// if states is no longer existing, we do not need to unsubscribe
|
|
7300
7335
|
this._logger.info(`${this.namespaceLog} unsubscrubeForeignStates not processed because States database not connected`);
|
|
7301
7336
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
@@ -7306,7 +7341,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7306
7341
|
// remove this pattern from adapter list
|
|
7307
7342
|
let state;
|
|
7308
7343
|
try {
|
|
7309
|
-
state = await
|
|
7344
|
+
state = await this.#states.getState(`system.adapter.${autoSub}.subscribes`);
|
|
7310
7345
|
}
|
|
7311
7346
|
catch {
|
|
7312
7347
|
// ignore
|
|
@@ -7343,7 +7378,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7343
7378
|
delete subs[pattern];
|
|
7344
7379
|
}
|
|
7345
7380
|
this.outputCount++;
|
|
7346
|
-
|
|
7381
|
+
this.#states.setState(`system.adapter.${autoSub}.subscribes`, JSON.stringify(subs));
|
|
7347
7382
|
}
|
|
7348
7383
|
}
|
|
7349
7384
|
}
|
|
@@ -7359,15 +7394,15 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7359
7394
|
if (pattern === '*' || pattern.startsWith(constants_1.ALIAS_STARTS_WITH)) {
|
|
7360
7395
|
aliasPattern = pattern; // check all aliases
|
|
7361
7396
|
if (pattern === '*') {
|
|
7362
|
-
promises.push(
|
|
7397
|
+
promises.push(this.#states.unsubscribeUser(pattern));
|
|
7363
7398
|
}
|
|
7364
7399
|
}
|
|
7365
7400
|
else {
|
|
7366
|
-
promises.push(
|
|
7401
|
+
promises.push(this.#states.unsubscribeUser(pattern));
|
|
7367
7402
|
}
|
|
7368
7403
|
}
|
|
7369
7404
|
else {
|
|
7370
|
-
promises.push(
|
|
7405
|
+
promises.push(this.#states.unsubscribeUser(pattern));
|
|
7371
7406
|
}
|
|
7372
7407
|
if (aliasPattern) {
|
|
7373
7408
|
// if pattern known, remove it from alias patterns to not subscribe to further matching aliases
|
|
@@ -7384,7 +7419,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7384
7419
|
// if no alias subscribed any longer, remove subscription
|
|
7385
7420
|
if (!this.aliases.size && this._aliasObjectsSubscribed) {
|
|
7386
7421
|
this._aliasObjectsSubscribed = false;
|
|
7387
|
-
|
|
7422
|
+
this.#objects.unsubscribe(`${constants_1.ALIAS_STARTS_WITH}*`);
|
|
7388
7423
|
}
|
|
7389
7424
|
return js_controller_common_1.tools.maybeCallback(callback);
|
|
7390
7425
|
}
|
|
@@ -7483,11 +7518,11 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7483
7518
|
if (this.performStrictObjectChecks) {
|
|
7484
7519
|
// obj needs to exist and has to be of type "file" - custom check for binary state
|
|
7485
7520
|
try {
|
|
7486
|
-
if (!
|
|
7521
|
+
if (!this.#objects) {
|
|
7487
7522
|
this._logger.info(`${this.namespaceLog} setBinaryState not processed because Objects database not connected`);
|
|
7488
7523
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
7489
7524
|
}
|
|
7490
|
-
const obj = await
|
|
7525
|
+
const obj = await this.#objects.getObjectAsync(id);
|
|
7491
7526
|
// at first check object existence
|
|
7492
7527
|
if (!obj) {
|
|
7493
7528
|
this._logger.warn(`${this.namespaceLog} Binary state "${id}" has no existing object, this might lead to an error in future versions`);
|
|
@@ -7504,7 +7539,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7504
7539
|
this._logger.warn(`${this.namespaceLog} Could not perform strict object check of binary state ${id}: ${e.message}`);
|
|
7505
7540
|
}
|
|
7506
7541
|
}
|
|
7507
|
-
if (!
|
|
7542
|
+
if (!this.#states) {
|
|
7508
7543
|
// if states is no longer existing, we do not need to unsubscribe
|
|
7509
7544
|
this._logger.info(`${this.namespaceLog} setBinaryState not processed because States database not connected`);
|
|
7510
7545
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
@@ -7526,38 +7561,38 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7526
7561
|
if (obj && !('binary' in obj)) {
|
|
7527
7562
|
// @ts-expect-error probably need to adjust types
|
|
7528
7563
|
obj.binary = true;
|
|
7529
|
-
if (!
|
|
7564
|
+
if (!this.#objects) {
|
|
7530
7565
|
this._logger.info(`${this.namespaceLog} setBinaryState not processed because Objects database not connected`);
|
|
7531
7566
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
7532
7567
|
}
|
|
7533
|
-
|
|
7568
|
+
this.#objects.setObject(id, obj, err => {
|
|
7534
7569
|
if (err) {
|
|
7535
7570
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, err);
|
|
7536
7571
|
}
|
|
7537
7572
|
else {
|
|
7538
|
-
if (!
|
|
7573
|
+
if (!this.#states) {
|
|
7539
7574
|
// if states is no longer existing, we do not need to unsubscribe
|
|
7540
7575
|
this._logger.info(`${this.namespaceLog} setBinaryState not processed because States database not connected`);
|
|
7541
7576
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
7542
7577
|
}
|
|
7543
7578
|
this.outputCount++;
|
|
7544
|
-
|
|
7579
|
+
this.#states.setBinaryState(id, binary, callback);
|
|
7545
7580
|
}
|
|
7546
7581
|
});
|
|
7547
7582
|
}
|
|
7548
7583
|
else {
|
|
7549
|
-
if (!
|
|
7584
|
+
if (!this.#states) {
|
|
7550
7585
|
// if states is no longer existing, we do not need to unsubscribe
|
|
7551
7586
|
this._logger.info(`${this.namespaceLog} setBinaryState not processed because States database not connected`);
|
|
7552
7587
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
7553
7588
|
}
|
|
7554
7589
|
this.outputCount++;
|
|
7555
|
-
|
|
7590
|
+
this.#states.setBinaryState(id, binary, callback);
|
|
7556
7591
|
}
|
|
7557
7592
|
}
|
|
7558
7593
|
else {
|
|
7559
7594
|
this.outputCount++;
|
|
7560
|
-
|
|
7595
|
+
this.#states.setBinaryState(id, binary, callback);
|
|
7561
7596
|
}
|
|
7562
7597
|
}
|
|
7563
7598
|
/**
|
|
@@ -7600,7 +7635,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7600
7635
|
}
|
|
7601
7636
|
async _getForeignBinaryState(_options) {
|
|
7602
7637
|
const { id, options, callback } = _options;
|
|
7603
|
-
if (!
|
|
7638
|
+
if (!this.#states) {
|
|
7604
7639
|
// if states is no longer existing, we do not need to unsubscribe
|
|
7605
7640
|
this._logger.info(`${this.namespaceLog} getBinaryState not processed because States database not connected`);
|
|
7606
7641
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
@@ -7623,11 +7658,11 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7623
7658
|
catch (e) {
|
|
7624
7659
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, e);
|
|
7625
7660
|
}
|
|
7626
|
-
|
|
7661
|
+
this.#states.getBinaryState(id, (err, data) => {
|
|
7627
7662
|
if (!err && data && obj && !('binary' in obj)) {
|
|
7628
7663
|
// @ts-expect-error type adjustment needed?
|
|
7629
7664
|
obj.binary = true;
|
|
7630
|
-
|
|
7665
|
+
this.#objects.setObject(id, obj, err => {
|
|
7631
7666
|
if (err) {
|
|
7632
7667
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, err);
|
|
7633
7668
|
}
|
|
@@ -7686,7 +7721,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7686
7721
|
}
|
|
7687
7722
|
async _delForeignBinaryState(_options) {
|
|
7688
7723
|
const { id, options, callback } = _options;
|
|
7689
|
-
if (!
|
|
7724
|
+
if (!this.#states) {
|
|
7690
7725
|
// if states is no longer existing, we do not need to unsubscribe
|
|
7691
7726
|
this._logger.info(`${this.namespaceLog} delBinaryState not processed because States database not connected`);
|
|
7692
7727
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
@@ -7704,10 +7739,10 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7704
7739
|
catch (e) {
|
|
7705
7740
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, e);
|
|
7706
7741
|
}
|
|
7707
|
-
|
|
7742
|
+
this.#states.delBinaryState(id, callback);
|
|
7708
7743
|
}
|
|
7709
7744
|
else {
|
|
7710
|
-
|
|
7745
|
+
this.#states.delBinaryState(id, callback);
|
|
7711
7746
|
}
|
|
7712
7747
|
}
|
|
7713
7748
|
/**
|
|
@@ -7752,17 +7787,16 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7752
7787
|
return this.pluginHandler.getPluginConfig(name);
|
|
7753
7788
|
}
|
|
7754
7789
|
async _autoSubscribeOn() {
|
|
7755
|
-
|
|
7756
|
-
if (!this.autoSubscribe && __classPrivateFieldGet(this, _AdapterClass_objects, "f")) {
|
|
7790
|
+
if (!this.autoSubscribe && this.#objects) {
|
|
7757
7791
|
try {
|
|
7758
7792
|
// collect all
|
|
7759
|
-
const res = await
|
|
7793
|
+
const res = await this.#objects.getObjectViewAsync('system', 'instance', {
|
|
7760
7794
|
startkey: 'system.adapter.',
|
|
7761
7795
|
endkey: 'system.adapter.\u9999'
|
|
7762
7796
|
});
|
|
7763
7797
|
this.autoSubscribe = [];
|
|
7764
7798
|
for (const row of res.rows) {
|
|
7765
|
-
if (
|
|
7799
|
+
if (row.value?.common.subscribable) {
|
|
7766
7800
|
const _id = row.id.substring(15); // cut system.adapter.
|
|
7767
7801
|
if (!this.autoSubscribe.includes(_id)) {
|
|
7768
7802
|
this.autoSubscribe.push(_id);
|
|
@@ -7770,7 +7804,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7770
7804
|
}
|
|
7771
7805
|
}
|
|
7772
7806
|
// because of autoSubscribe
|
|
7773
|
-
await
|
|
7807
|
+
await this.#objects.subscribeAsync('system.adapter.*');
|
|
7774
7808
|
}
|
|
7775
7809
|
catch {
|
|
7776
7810
|
// ignore
|
|
@@ -7784,20 +7818,19 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7784
7818
|
* @returns list of suitable licenses
|
|
7785
7819
|
*/
|
|
7786
7820
|
async getSuitableLicenses(all, adapterName) {
|
|
7787
|
-
var _a, _b, _c, _d;
|
|
7788
7821
|
const licenses = [];
|
|
7789
7822
|
try {
|
|
7790
7823
|
const obj = await this.getForeignObjectAsync('system.licenses');
|
|
7791
7824
|
const uuidObj = await this.getForeignObjectAsync('system.meta.uuid');
|
|
7792
7825
|
let uuid;
|
|
7793
|
-
if (!
|
|
7826
|
+
if (!uuidObj?.native?.uuid) {
|
|
7794
7827
|
this._logger.warn(`${this.namespaceLog} No UUID found!`);
|
|
7795
7828
|
return licenses;
|
|
7796
7829
|
}
|
|
7797
7830
|
else {
|
|
7798
7831
|
uuid = uuidObj.native.uuid;
|
|
7799
7832
|
}
|
|
7800
|
-
if (
|
|
7833
|
+
if (obj?.native?.licenses?.length) {
|
|
7801
7834
|
const now = Date.now();
|
|
7802
7835
|
const cert = fs_extra_1.default.readFileSync(node_path_1.default.join(__dirname, '..', '..', 'cert', 'cloudCert.crt'));
|
|
7803
7836
|
let adapterObj;
|
|
@@ -7809,7 +7842,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7809
7842
|
// ignore
|
|
7810
7843
|
}
|
|
7811
7844
|
}
|
|
7812
|
-
const version = semver_1.default.major(
|
|
7845
|
+
const version = semver_1.default.major(adapterObj?.common?.version || this.pack.version);
|
|
7813
7846
|
obj.native.licenses.forEach((license) => {
|
|
7814
7847
|
try {
|
|
7815
7848
|
const decoded = jsonwebtoken_1.default.verify(license.json, cert);
|
|
@@ -7880,13 +7913,13 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7880
7913
|
return licenses;
|
|
7881
7914
|
}
|
|
7882
7915
|
_reportStatus() {
|
|
7883
|
-
if (!
|
|
7916
|
+
if (!this.#states) {
|
|
7884
7917
|
return;
|
|
7885
7918
|
}
|
|
7886
7919
|
/** Time after which states regularly set by the status report expire in seconds */
|
|
7887
7920
|
const reportStatusExpirySec = Math.floor(this._config.system.statisticsInterval / 1000) + 10;
|
|
7888
7921
|
const id = `system.adapter.${this.namespace}`;
|
|
7889
|
-
|
|
7922
|
+
this.#states.setState(`${id}.alive`, {
|
|
7890
7923
|
val: true,
|
|
7891
7924
|
ack: true,
|
|
7892
7925
|
expire: reportStatusExpirySec,
|
|
@@ -7894,7 +7927,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7894
7927
|
});
|
|
7895
7928
|
this.outputCount++;
|
|
7896
7929
|
if (this.connected) {
|
|
7897
|
-
|
|
7930
|
+
this.#states.setState(`${id}.connected`, {
|
|
7898
7931
|
val: true,
|
|
7899
7932
|
ack: true,
|
|
7900
7933
|
expire: reportStatusExpirySec,
|
|
@@ -7915,14 +7948,14 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7915
7948
|
// }
|
|
7916
7949
|
(0, pidusage_1.default)(process.pid, (err, stats) => {
|
|
7917
7950
|
// sometimes adapter is stopped, but this is still running
|
|
7918
|
-
if (!err && this &&
|
|
7919
|
-
|
|
7951
|
+
if (!err && this && this.#states && this.#states.setState && stats) {
|
|
7952
|
+
this.#states.setState(`${id}.cpu`, {
|
|
7920
7953
|
ack: true,
|
|
7921
7954
|
from: id,
|
|
7922
7955
|
val: Math.round(100 * stats.cpu) / 100,
|
|
7923
7956
|
expire: reportStatusExpirySec
|
|
7924
7957
|
});
|
|
7925
|
-
|
|
7958
|
+
this.#states.setState(`${id}.cputime`, {
|
|
7926
7959
|
ack: true,
|
|
7927
7960
|
from: id,
|
|
7928
7961
|
val: stats.ctime / 1000,
|
|
@@ -7934,21 +7967,21 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7934
7967
|
try {
|
|
7935
7968
|
//RSS is the resident set size, the portion of the process's memory held in RAM (as opposed to the swap space or the part held in the filesystem).
|
|
7936
7969
|
const mem = process.memoryUsage();
|
|
7937
|
-
|
|
7970
|
+
this.#states.setState(`${id}.memRss`, {
|
|
7938
7971
|
val: parseFloat((mem.rss / 1048576) /* 1MB */
|
|
7939
7972
|
.toFixed(2)),
|
|
7940
7973
|
ack: true,
|
|
7941
7974
|
from: id,
|
|
7942
7975
|
expire: reportStatusExpirySec
|
|
7943
7976
|
});
|
|
7944
|
-
|
|
7977
|
+
this.#states.setState(`${id}.memHeapTotal`, {
|
|
7945
7978
|
val: parseFloat((mem.heapTotal / 1048576) /* 1MB */
|
|
7946
7979
|
.toFixed(2)),
|
|
7947
7980
|
ack: true,
|
|
7948
7981
|
from: id,
|
|
7949
7982
|
expire: reportStatusExpirySec
|
|
7950
7983
|
});
|
|
7951
|
-
|
|
7984
|
+
this.#states.setState(`${id}.memHeapUsed`, {
|
|
7952
7985
|
val: parseFloat((mem.heapUsed / 1048576) /* 1MB */
|
|
7953
7986
|
.toFixed(2)),
|
|
7954
7987
|
ack: true,
|
|
@@ -7962,7 +7995,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7962
7995
|
this.outputCount += 3;
|
|
7963
7996
|
if (this.eventLoopLags.length) {
|
|
7964
7997
|
const eventLoopLag = Math.ceil(this.eventLoopLags.reduce((a, b) => a + b) / this.eventLoopLags.length);
|
|
7965
|
-
|
|
7998
|
+
this.#states.setState(`${id}.eventLoopLag`, {
|
|
7966
7999
|
val: eventLoopLag,
|
|
7967
8000
|
ack: true,
|
|
7968
8001
|
from: id,
|
|
@@ -7973,19 +8006,19 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7973
8006
|
}
|
|
7974
8007
|
}
|
|
7975
8008
|
this.outputCount += 3;
|
|
7976
|
-
|
|
8009
|
+
this.#states.setState(`${id}.uptime`, {
|
|
7977
8010
|
val: parseInt(process.uptime().toFixed(), 10),
|
|
7978
8011
|
ack: true,
|
|
7979
8012
|
from: id,
|
|
7980
8013
|
expire: reportStatusExpirySec
|
|
7981
8014
|
});
|
|
7982
|
-
|
|
8015
|
+
this.#states.setState(`${id}.inputCount`, {
|
|
7983
8016
|
val: this.inputCount,
|
|
7984
8017
|
ack: true,
|
|
7985
8018
|
from: id,
|
|
7986
8019
|
expire: reportStatusExpirySec
|
|
7987
8020
|
});
|
|
7988
|
-
|
|
8021
|
+
this.#states.setState(`${id}.outputCount`, {
|
|
7989
8022
|
val: this.outputCount,
|
|
7990
8023
|
ack: true,
|
|
7991
8024
|
from: id,
|
|
@@ -7999,18 +8032,18 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
7999
8032
|
let logs = [];
|
|
8000
8033
|
// LogList
|
|
8001
8034
|
logs.push(`Actual Loglist - ${JSON.stringify(Array.from(this.logList))}`);
|
|
8002
|
-
if (!
|
|
8035
|
+
if (!this.#states) {
|
|
8003
8036
|
// if adapterState was destroyed, we can not continue
|
|
8004
8037
|
return;
|
|
8005
8038
|
}
|
|
8006
8039
|
// Read current state of all log subscribers
|
|
8007
|
-
|
|
8008
|
-
if (keys
|
|
8009
|
-
if (!
|
|
8040
|
+
this.#states.getKeys(`${constants_2.SYSTEM_ADAPTER_PREFIX}*.logging`, (err, keys) => {
|
|
8041
|
+
if (keys?.length) {
|
|
8042
|
+
if (!this.#states) {
|
|
8010
8043
|
// if adapterState was destroyed, we can not continue
|
|
8011
8044
|
return;
|
|
8012
8045
|
}
|
|
8013
|
-
|
|
8046
|
+
this.#states.getStates(keys, (err, obj) => {
|
|
8014
8047
|
if (obj) {
|
|
8015
8048
|
for (let i = 0; i < keys.length; i++) {
|
|
8016
8049
|
const objPart = obj[i];
|
|
@@ -8048,17 +8081,17 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8048
8081
|
// temporary log buffer
|
|
8049
8082
|
let messages = [];
|
|
8050
8083
|
// Read current state of all log subscriber
|
|
8051
|
-
if (!
|
|
8084
|
+
if (!this.#states) {
|
|
8052
8085
|
// if adapterState was destroyed, we can not continue
|
|
8053
8086
|
return;
|
|
8054
8087
|
}
|
|
8055
|
-
|
|
8056
|
-
if (keys
|
|
8057
|
-
if (!
|
|
8088
|
+
this.#states.getKeys(`${constants_2.SYSTEM_ADAPTER_PREFIX}*.logging`, (err, keys) => {
|
|
8089
|
+
if (keys?.length) {
|
|
8090
|
+
if (!this.#states) {
|
|
8058
8091
|
// if adapterState was destroyed, we can not continue
|
|
8059
8092
|
return;
|
|
8060
8093
|
}
|
|
8061
|
-
|
|
8094
|
+
this.#states.getStates(keys, (err, obj) => {
|
|
8062
8095
|
if (obj) {
|
|
8063
8096
|
for (let i = 0; i < keys.length; i++) {
|
|
8064
8097
|
const objPart = obj[i];
|
|
@@ -8077,10 +8110,10 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8077
8110
|
this.logRedirect(true, id);
|
|
8078
8111
|
}
|
|
8079
8112
|
}
|
|
8080
|
-
if (this.logList.size &&
|
|
8113
|
+
if (this.logList.size && messages?.length && this.#states) {
|
|
8081
8114
|
for (const message of messages) {
|
|
8082
8115
|
for (const instanceId of this.logList) {
|
|
8083
|
-
|
|
8116
|
+
this.#states.pushLog(instanceId, message);
|
|
8084
8117
|
}
|
|
8085
8118
|
}
|
|
8086
8119
|
}
|
|
@@ -8115,7 +8148,6 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8115
8148
|
const ts = this._logger.transports.find(t => t.name === 'NT');
|
|
8116
8149
|
// @ts-expect-error
|
|
8117
8150
|
ts.on('logged', info => {
|
|
8118
|
-
var _a;
|
|
8119
8151
|
info.from = this.namespace;
|
|
8120
8152
|
// emit to itself
|
|
8121
8153
|
if (this._options.logTransporter && this.logRequired && !this._stopInProgress) {
|
|
@@ -8131,17 +8163,17 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8131
8163
|
}
|
|
8132
8164
|
}
|
|
8133
8165
|
}
|
|
8134
|
-
else if (
|
|
8166
|
+
else if (this.#states?.pushLog) {
|
|
8135
8167
|
// Send to all adapter, that required logs
|
|
8136
8168
|
for (const instanceId of this.logList) {
|
|
8137
|
-
|
|
8169
|
+
this.#states.pushLog(instanceId, info);
|
|
8138
8170
|
}
|
|
8139
8171
|
}
|
|
8140
8172
|
});
|
|
8141
8173
|
this._options.logTransporter = this._options.logTransporter || this.ioPack.common.logTransporter;
|
|
8142
8174
|
if (this._options.logTransporter) {
|
|
8143
8175
|
this.requireLog = async (isActive, options) => {
|
|
8144
|
-
if (!
|
|
8176
|
+
if (!this.#states) {
|
|
8145
8177
|
return;
|
|
8146
8178
|
}
|
|
8147
8179
|
if (this.logRequired !== isActive) {
|
|
@@ -8155,7 +8187,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8155
8187
|
this.logOffTimer = null;
|
|
8156
8188
|
this._logger.silly(`${this.namespaceLog} Change log subscriber state: FALSE`);
|
|
8157
8189
|
this.outputCount++;
|
|
8158
|
-
if (
|
|
8190
|
+
if (this.#states) {
|
|
8159
8191
|
try {
|
|
8160
8192
|
await this.setForeignStateAsync(`system.adapter.${this.namespace}.logging`, {
|
|
8161
8193
|
val: false,
|
|
@@ -8196,7 +8228,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8196
8228
|
this.emit('log', msg);
|
|
8197
8229
|
}
|
|
8198
8230
|
};
|
|
8199
|
-
|
|
8231
|
+
this.#states.subscribeLog(`system.adapter.${this.namespace}`);
|
|
8200
8232
|
}
|
|
8201
8233
|
else {
|
|
8202
8234
|
this.requireLog = isActive => {
|
|
@@ -8225,11 +8257,11 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8225
8257
|
this.terminate(js_controller_common_1.EXIT_CODES.NO_ERROR);
|
|
8226
8258
|
}
|
|
8227
8259
|
// Internal object, but some special adapters want to access it anyway.
|
|
8228
|
-
|
|
8260
|
+
this.#states = new this.States({
|
|
8229
8261
|
namespace: this.namespaceLog,
|
|
8230
8262
|
connection: this._config.states,
|
|
8231
8263
|
connected: async () => {
|
|
8232
|
-
if (!
|
|
8264
|
+
if (!this.#states) {
|
|
8233
8265
|
return;
|
|
8234
8266
|
}
|
|
8235
8267
|
this._logger.silly(`${this.namespaceLog} statesDB connected`);
|
|
@@ -8240,22 +8272,22 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8240
8272
|
}
|
|
8241
8273
|
if (!this._config.isInstall) {
|
|
8242
8274
|
// Subscribe for process exit signal
|
|
8243
|
-
|
|
8275
|
+
this.#states.subscribe(`system.adapter.${this.namespace}.sigKill`);
|
|
8244
8276
|
// Subscribe for loglevel
|
|
8245
|
-
|
|
8277
|
+
this.#states.subscribe(`system.adapter.${this.namespace}.logLevel`);
|
|
8246
8278
|
}
|
|
8247
8279
|
if (this._options.subscribable) {
|
|
8248
8280
|
// subscribe on if other instance wants to have states of this adapter
|
|
8249
|
-
|
|
8281
|
+
this.#states.subscribe(`system.adapter.${this.namespace}.subscribes`);
|
|
8250
8282
|
// read actual autosubscribe requests
|
|
8251
8283
|
let state;
|
|
8252
8284
|
try {
|
|
8253
|
-
state = await
|
|
8285
|
+
state = await this.#states.getStateAsync(`system.adapter.${this.namespace}.subscribes`);
|
|
8254
8286
|
}
|
|
8255
8287
|
catch {
|
|
8256
8288
|
// ignore
|
|
8257
8289
|
}
|
|
8258
|
-
if (!
|
|
8290
|
+
if (!state?.val) {
|
|
8259
8291
|
this.patterns = {};
|
|
8260
8292
|
}
|
|
8261
8293
|
else {
|
|
@@ -8275,7 +8307,6 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8275
8307
|
},
|
|
8276
8308
|
logger: this._logger,
|
|
8277
8309
|
change: async (id, stateOrMessage) => {
|
|
8278
|
-
var _a, _b;
|
|
8279
8310
|
this.inputCount++;
|
|
8280
8311
|
// for simplicity reasons we exclude Message for now TODO
|
|
8281
8312
|
const state = stateOrMessage;
|
|
@@ -8328,8 +8359,8 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8328
8359
|
this._logger.info(`${this.namespaceLog} Got invalid loglevel "${state.val}", ignoring`);
|
|
8329
8360
|
}
|
|
8330
8361
|
this.outputCount++;
|
|
8331
|
-
|
|
8332
|
-
|
|
8362
|
+
this.#states &&
|
|
8363
|
+
this.#states.setState(`system.adapter.${this.namespace}.logLevel`, {
|
|
8333
8364
|
val: currentLevel,
|
|
8334
8365
|
ack: true,
|
|
8335
8366
|
from: `system.adapter.${this.namespace}`
|
|
@@ -8374,7 +8405,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8374
8405
|
const obj = state;
|
|
8375
8406
|
if (obj) {
|
|
8376
8407
|
let callbackObj;
|
|
8377
|
-
if (
|
|
8408
|
+
if (obj.callback?.id) {
|
|
8378
8409
|
callbackObj = this.messageCallbacks.get(obj.callback.id);
|
|
8379
8410
|
}
|
|
8380
8411
|
// If callback stored for this request
|
|
@@ -8422,14 +8453,14 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8422
8453
|
nameEndIndex = undefined;
|
|
8423
8454
|
}
|
|
8424
8455
|
const pluginName = id.substring(pluginStatesIndex, nameEndIndex);
|
|
8425
|
-
if (!
|
|
8456
|
+
if (!this.pluginHandler?.pluginExists(pluginName)) {
|
|
8426
8457
|
return;
|
|
8427
8458
|
}
|
|
8428
8459
|
if (this.pluginHandler.isPluginActive(pluginName) !== state.val) {
|
|
8429
8460
|
if (state.val) {
|
|
8430
8461
|
if (!this.pluginHandler.isPluginInstanciated(pluginName)) {
|
|
8431
8462
|
this.pluginHandler.instanciatePlugin(pluginName, this.pluginHandler.getPluginConfig(pluginName) || {}, __dirname);
|
|
8432
|
-
this.pluginHandler.setDatabaseForPlugin(pluginName,
|
|
8463
|
+
this.pluginHandler.setDatabaseForPlugin(pluginName, this.#objects, this.#states);
|
|
8433
8464
|
this.pluginHandler.initPlugin(pluginName, this.adapterConfig || {});
|
|
8434
8465
|
}
|
|
8435
8466
|
}
|
|
@@ -8506,7 +8537,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8506
8537
|
this.terminate(js_controller_common_1.EXIT_CODES.NO_ERROR);
|
|
8507
8538
|
}, 5000);
|
|
8508
8539
|
}
|
|
8509
|
-
})
|
|
8540
|
+
});
|
|
8510
8541
|
}
|
|
8511
8542
|
_initObjects(cb) {
|
|
8512
8543
|
this._initializeTimeout = setTimeout(() => {
|
|
@@ -8523,7 +8554,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8523
8554
|
this._logger.warn(`${this.namespaceLog} Objects DB constructor has not been initialized`);
|
|
8524
8555
|
this.terminate(js_controller_common_1.EXIT_CODES.NO_ERROR);
|
|
8525
8556
|
}
|
|
8526
|
-
|
|
8557
|
+
this.#objects = new this.Objects({
|
|
8527
8558
|
namespace: this.namespaceLog,
|
|
8528
8559
|
connection: this._config.objects,
|
|
8529
8560
|
logger: this._logger,
|
|
@@ -8533,18 +8564,18 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8533
8564
|
clearTimeout(this._initializeTimeout);
|
|
8534
8565
|
this._initializeTimeout = null;
|
|
8535
8566
|
}
|
|
8536
|
-
if (!
|
|
8567
|
+
if (!this.#objects) {
|
|
8537
8568
|
return;
|
|
8538
8569
|
}
|
|
8539
8570
|
// subscribe to user changes
|
|
8540
|
-
|
|
8571
|
+
this.#objects.subscribe('system.user.*');
|
|
8541
8572
|
// get all enums and register for enum changes
|
|
8542
|
-
this.enums = await js_controller_common_1.tools.getAllEnums(
|
|
8543
|
-
|
|
8573
|
+
this.enums = await js_controller_common_1.tools.getAllEnums(this.#objects);
|
|
8574
|
+
this.#objects.subscribe('enum.*');
|
|
8544
8575
|
// Read dateformat if using of formatDate is announced
|
|
8545
8576
|
if (this._options.useFormatDate) {
|
|
8546
|
-
|
|
8547
|
-
if (data
|
|
8577
|
+
this.#objects.getObject('system.config', (err, data) => {
|
|
8578
|
+
if (data?.common) {
|
|
8548
8579
|
this.dateFormat = data.common.dateFormat;
|
|
8549
8580
|
this.isFloatComma = data.common.isFloatComma;
|
|
8550
8581
|
this.language = data.common.language;
|
|
@@ -8552,7 +8583,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8552
8583
|
this.latitude = data.common.latitude;
|
|
8553
8584
|
this.defaultHistory = data.common.defaultHistory;
|
|
8554
8585
|
}
|
|
8555
|
-
if (data
|
|
8586
|
+
if (data?.native) {
|
|
8556
8587
|
this._systemSecret = data.native.secret;
|
|
8557
8588
|
}
|
|
8558
8589
|
return js_controller_common_1.tools.maybeCallback(cb);
|
|
@@ -8574,7 +8605,6 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8574
8605
|
}, 4000);
|
|
8575
8606
|
},
|
|
8576
8607
|
change: async (id, obj) => {
|
|
8577
|
-
var _a, _b, _c;
|
|
8578
8608
|
// System level object changes (and alias objects)
|
|
8579
8609
|
if (!id) {
|
|
8580
8610
|
this._logger.error(`${this.namespaceLog} change ID is empty: ${JSON.stringify(obj)}`);
|
|
@@ -8589,8 +8619,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8589
8619
|
}
|
|
8590
8620
|
// update language, dateFormat and comma
|
|
8591
8621
|
if (id === 'system.config' &&
|
|
8592
|
-
obj &&
|
|
8593
|
-
obj.common &&
|
|
8622
|
+
obj?.common &&
|
|
8594
8623
|
(this._options.useFormatDate || this.defaultHistory !== undefined)) {
|
|
8595
8624
|
this.dateFormat = obj.common.dateFormat;
|
|
8596
8625
|
this.isFloatComma = obj.common.isFloatComma;
|
|
@@ -8609,7 +8638,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8609
8638
|
if (targetAlias) {
|
|
8610
8639
|
isNewAlias = false;
|
|
8611
8640
|
// new sourceId or same
|
|
8612
|
-
if (
|
|
8641
|
+
if (obj?.common?.alias?.id) {
|
|
8613
8642
|
// check if id.read or id
|
|
8614
8643
|
const newSourceId = typeof obj.common.alias.id.read === 'string'
|
|
8615
8644
|
? obj.common.alias.id.read
|
|
@@ -8662,7 +8691,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8662
8691
|
}
|
|
8663
8692
|
// process auto-subscribe adapters
|
|
8664
8693
|
if (id.startsWith('system.adapter.')) {
|
|
8665
|
-
if (
|
|
8694
|
+
if (obj?.common?.subscribable) {
|
|
8666
8695
|
const _id = id.substring(15); // 'system.adapter.'.length
|
|
8667
8696
|
if (obj.common.enabled) {
|
|
8668
8697
|
if (!this.autoSubscribe.includes(_id)) {
|
|
@@ -8742,22 +8771,22 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8742
8771
|
setImmediate(() => this.emit('fileChange', id, fileName, size));
|
|
8743
8772
|
}
|
|
8744
8773
|
}
|
|
8745
|
-
})
|
|
8774
|
+
});
|
|
8746
8775
|
}
|
|
8747
8776
|
/**
|
|
8748
8777
|
* Called if states and objects successfully initialized
|
|
8749
8778
|
*/
|
|
8750
8779
|
_prepareInitAdapter() {
|
|
8751
|
-
if (this.terminated || !
|
|
8780
|
+
if (this.terminated || !this.#objects || !this.#states) {
|
|
8752
8781
|
return;
|
|
8753
8782
|
}
|
|
8754
8783
|
if (this._options.instance !== undefined) {
|
|
8755
8784
|
this._initAdapter(this._options);
|
|
8756
8785
|
}
|
|
8757
8786
|
else {
|
|
8758
|
-
|
|
8759
|
-
|
|
8760
|
-
if (
|
|
8787
|
+
this.#states.getState(`system.adapter.${this.namespace}.alive`, (err, resAlive) => {
|
|
8788
|
+
this.#states.getState(`system.adapter.${this.namespace}.sigKill`, (err, killRes) => {
|
|
8789
|
+
if (killRes?.val !== undefined) {
|
|
8761
8790
|
killRes.val = parseInt(killRes.val, 10);
|
|
8762
8791
|
}
|
|
8763
8792
|
if (!this._config.isInstall &&
|
|
@@ -8789,7 +8818,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8789
8818
|
this.terminate(js_controller_common_1.EXIT_CODES.ADAPTER_ALREADY_RUNNING);
|
|
8790
8819
|
}
|
|
8791
8820
|
else {
|
|
8792
|
-
|
|
8821
|
+
this.#objects.getObject(`system.adapter.${this.namespace}`, (err, res) => {
|
|
8793
8822
|
// TODO: ts infers AdapterObject instead of InstanceObject
|
|
8794
8823
|
if ((err || !res) && !this._config.isInstall) {
|
|
8795
8824
|
this._logger.error(`${this.namespaceLog} ${this.namespace} invalid config`);
|
|
@@ -8809,14 +8838,13 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8809
8838
|
if (!this.pluginHandler) {
|
|
8810
8839
|
return;
|
|
8811
8840
|
}
|
|
8812
|
-
this.pluginHandler.setDatabaseForPlugins(
|
|
8841
|
+
this.pluginHandler.setDatabaseForPlugins(this.#objects, this.#states);
|
|
8813
8842
|
this.pluginHandler.initPlugins(adapterConfig || {}, async () => {
|
|
8814
|
-
|
|
8815
|
-
if (!__classPrivateFieldGet(this, _AdapterClass_states, "f") || !__classPrivateFieldGet(this, _AdapterClass_objects, "f") || this.terminated) {
|
|
8843
|
+
if (!this.#states || !this.#objects || this.terminated) {
|
|
8816
8844
|
// if adapterState was destroyed,we should not continue
|
|
8817
8845
|
return;
|
|
8818
8846
|
}
|
|
8819
|
-
|
|
8847
|
+
this.#states.subscribe(`system.adapter.${this.namespace}.plugins.*`);
|
|
8820
8848
|
if (this._options.instance === undefined) {
|
|
8821
8849
|
if (!adapterConfig || !('common' in adapterConfig) || !adapterConfig.common.enabled) {
|
|
8822
8850
|
if (adapterConfig && 'common' in adapterConfig && adapterConfig.common.enabled !== undefined) {
|
|
@@ -8829,9 +8857,9 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8829
8857
|
if (!this._config.isInstall && (!process.argv || !this._config.forceIfDisabled)) {
|
|
8830
8858
|
const id = `system.adapter.${this.namespace}`;
|
|
8831
8859
|
this.outputCount += 2;
|
|
8832
|
-
|
|
8860
|
+
this.#states.setState(`${id}.alive`, { val: true, ack: true, expire: 30, from: id });
|
|
8833
8861
|
let done = false;
|
|
8834
|
-
|
|
8862
|
+
this.#states.setState(`${id}.connected`, {
|
|
8835
8863
|
val: true,
|
|
8836
8864
|
ack: true,
|
|
8837
8865
|
expire: 30,
|
|
@@ -8924,7 +8952,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8924
8952
|
this.stop = () => this._stop(false);
|
|
8925
8953
|
}
|
|
8926
8954
|
// Monitor logging state
|
|
8927
|
-
|
|
8955
|
+
this.#states.subscribe(`${constants_2.SYSTEM_ADAPTER_PREFIX}*.logging`);
|
|
8928
8956
|
if (typeof this._options.message === 'function' &&
|
|
8929
8957
|
// @ts-expect-error, we should infer correctly that this is an InstanceObject in this case
|
|
8930
8958
|
!(0, utils_1.isMessageboxSupported)(adapterConfig.common)) {
|
|
@@ -8933,7 +8961,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8933
8961
|
}
|
|
8934
8962
|
else if ((0, utils_1.isMessageboxSupported)(adapterConfig.common)) {
|
|
8935
8963
|
this.mboxSubscribed = true;
|
|
8936
|
-
|
|
8964
|
+
this.#states.subscribeMessage(`system.adapter.${this.namespace}`);
|
|
8937
8965
|
}
|
|
8938
8966
|
}
|
|
8939
8967
|
else {
|
|
@@ -8948,10 +8976,10 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8948
8976
|
this.config = adapterConfig.native || {};
|
|
8949
8977
|
// @ts-expect-error
|
|
8950
8978
|
this.common = adapterConfig.common || {};
|
|
8951
|
-
this.host =
|
|
8979
|
+
this.host = this.common?.host || js_controller_common_1.tools.getHostName() || node_os_1.default.hostname();
|
|
8952
8980
|
}
|
|
8953
8981
|
this.adapterConfig = adapterConfig;
|
|
8954
|
-
this._utils = new validator_1.Validator(
|
|
8982
|
+
this._utils = new validator_1.Validator(this.#objects, this.#states, this.namespaceLog, this._logger, this.namespace, this._namespaceRegExp);
|
|
8955
8983
|
this.log = new log_1.Log(this.namespaceLog, this._config.log.level, this._logger);
|
|
8956
8984
|
await this._createInstancesObjects(adapterConfig);
|
|
8957
8985
|
// auto oObjects
|
|
@@ -8986,21 +9014,21 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
8986
9014
|
}
|
|
8987
9015
|
// Wait till all attributes decrypted
|
|
8988
9016
|
await Promise.all(promises);
|
|
8989
|
-
if (!
|
|
9017
|
+
if (!this.#states) {
|
|
8990
9018
|
// if this.adapterStates was destroyed, we should not continue
|
|
8991
9019
|
return;
|
|
8992
9020
|
}
|
|
8993
9021
|
this.outputCount++;
|
|
8994
9022
|
// set current loglevel
|
|
8995
|
-
|
|
9023
|
+
this.#states.setState(`system.adapter.${this.namespace}.logLevel`, {
|
|
8996
9024
|
val: this._config.log.level,
|
|
8997
9025
|
ack: true,
|
|
8998
9026
|
from: `system.adapter.${this.namespace}`
|
|
8999
9027
|
});
|
|
9000
9028
|
if (this._options.instance === undefined) {
|
|
9001
|
-
this.version =
|
|
9029
|
+
this.version = this.pack?.version
|
|
9002
9030
|
? this.pack.version
|
|
9003
|
-
:
|
|
9031
|
+
: this.ioPack?.common
|
|
9004
9032
|
? this.ioPack.common.version
|
|
9005
9033
|
: 'unknown';
|
|
9006
9034
|
// display if it's a non-official version - only if installedFrom is explicitly given and differs it's not npm
|
|
@@ -9016,19 +9044,19 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
9016
9044
|
this._reportInterval = setInterval(() => this._reportStatus(), this._config.system.statisticsInterval);
|
|
9017
9045
|
this._reportStatus();
|
|
9018
9046
|
const id = `system.adapter.${this.namespace}`;
|
|
9019
|
-
|
|
9047
|
+
this.#states.setState(`${id}.compactMode`, {
|
|
9020
9048
|
ack: true,
|
|
9021
9049
|
from: id,
|
|
9022
9050
|
val: !!this.startedInCompactMode
|
|
9023
9051
|
});
|
|
9024
9052
|
this.outputCount++;
|
|
9025
9053
|
if (this.startedInCompactMode) {
|
|
9026
|
-
|
|
9027
|
-
|
|
9028
|
-
|
|
9029
|
-
|
|
9030
|
-
|
|
9031
|
-
|
|
9054
|
+
this.#states.setState(`${id}.cpu`, { ack: true, from: id, val: 0 });
|
|
9055
|
+
this.#states.setState(`${id}.cputime`, { ack: true, from: id, val: 0 });
|
|
9056
|
+
this.#states.setState(`${id}.memRss`, { val: 0, ack: true, from: id });
|
|
9057
|
+
this.#states.setState(`${id}.memHeapTotal`, { val: 0, ack: true, from: id });
|
|
9058
|
+
this.#states.setState(`${id}.memHeapUsed`, { val: 0, ack: true, from: id });
|
|
9059
|
+
this.#states.setState(`${id}.eventLoopLag`, { val: 0, ack: true, from: id });
|
|
9032
9060
|
this.outputCount += 6;
|
|
9033
9061
|
}
|
|
9034
9062
|
else {
|
|
@@ -9042,7 +9070,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
9042
9070
|
}
|
|
9043
9071
|
if (adapterConfig && 'common' in adapterConfig && adapterConfig.common.restartSchedule) {
|
|
9044
9072
|
try {
|
|
9045
|
-
this._schedule = await
|
|
9073
|
+
this._schedule = await import('node-schedule');
|
|
9046
9074
|
}
|
|
9047
9075
|
catch {
|
|
9048
9076
|
this._logger.error(`${this.namespaceLog} Cannot load node-schedule. Scheduled restart is disabled`);
|
|
@@ -9112,7 +9140,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
9112
9140
|
}
|
|
9113
9141
|
}
|
|
9114
9142
|
// catch it on Windows
|
|
9115
|
-
if (this.getPortRunning &&
|
|
9143
|
+
if (this.getPortRunning && err?.message === 'listen EADDRINUSE') {
|
|
9116
9144
|
const { host, port, callback } = this.getPortRunning;
|
|
9117
9145
|
this._logger.warn(`${this.namespaceLog} Port ${port}${host ? ` for host ${host}` : ''} is in use. Get next`);
|
|
9118
9146
|
setImmediate(() => this.getPort(port + 1, host, callback));
|
|
@@ -9144,9 +9172,8 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
9144
9172
|
}
|
|
9145
9173
|
}
|
|
9146
9174
|
async _createInstancesObjects(instanceObj) {
|
|
9147
|
-
var _a;
|
|
9148
9175
|
let objs;
|
|
9149
|
-
if (
|
|
9176
|
+
if (instanceObj?.common && !('onlyWWW' in instanceObj.common) && instanceObj.common.mode !== 'once') {
|
|
9150
9177
|
// @ts-expect-error
|
|
9151
9178
|
objs = js_controller_common_1.tools.getInstanceIndicatorObjects(this.namespace, instanceObj.common.wakeup);
|
|
9152
9179
|
}
|
|
@@ -9161,35 +9188,33 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
9161
9188
|
obj._id = obj._id === '' ? this.namespace : `${this.namespace}.${obj._id}`;
|
|
9162
9189
|
}
|
|
9163
9190
|
if (obj && (obj._id || obj.type === 'meta')) {
|
|
9164
|
-
if (obj.common) {
|
|
9165
|
-
|
|
9166
|
-
|
|
9167
|
-
|
|
9168
|
-
|
|
9169
|
-
|
|
9170
|
-
commonName[lang] = value.replace('%INSTANCE%', this.instance.toString());
|
|
9171
|
-
}
|
|
9172
|
-
}
|
|
9173
|
-
else {
|
|
9174
|
-
obj.common.name = commonName.replace('%INSTANCE%', this.instance.toString());
|
|
9191
|
+
if (obj.common?.name) {
|
|
9192
|
+
const commonName = obj.common.name;
|
|
9193
|
+
// if name has many languages
|
|
9194
|
+
if (js_controller_common_1.tools.isObject(commonName)) {
|
|
9195
|
+
for (const [lang, value] of Object.entries(commonName)) {
|
|
9196
|
+
commonName[lang] = value.replace('%INSTANCE%', this.instance.toString());
|
|
9175
9197
|
}
|
|
9176
9198
|
}
|
|
9199
|
+
else {
|
|
9200
|
+
obj.common.name = commonName.replace('%INSTANCE%', this.instance.toString());
|
|
9201
|
+
}
|
|
9177
9202
|
if ('desc' in obj.common) {
|
|
9178
9203
|
const commonDesc = obj.common.desc;
|
|
9179
9204
|
// if description has many languages
|
|
9180
9205
|
if (js_controller_common_1.tools.isObject(commonDesc)) {
|
|
9181
9206
|
for (const [lang, value] of Object.entries(commonDesc)) {
|
|
9182
|
-
commonDesc[lang] = value.replace('%INSTANCE%', this.instance);
|
|
9207
|
+
commonDesc[lang] = value.replace('%INSTANCE%', this.instance.toString());
|
|
9183
9208
|
}
|
|
9184
9209
|
}
|
|
9185
|
-
else {
|
|
9186
|
-
obj.common.desc = commonDesc.replace('%INSTANCE%', this.instance);
|
|
9210
|
+
else if (commonDesc) {
|
|
9211
|
+
obj.common.desc = commonDesc.replace('%INSTANCE%', this.instance.toString());
|
|
9187
9212
|
}
|
|
9188
9213
|
}
|
|
9189
9214
|
if (obj.type === 'state' && obj.common.def !== undefined) {
|
|
9190
9215
|
// default value given - if obj non-existing we have to set it
|
|
9191
9216
|
try {
|
|
9192
|
-
const checkObj = await
|
|
9217
|
+
const checkObj = await this.#objects.objectExists(obj._id);
|
|
9193
9218
|
if (!checkObj) {
|
|
9194
9219
|
obj.state = obj.common.def;
|
|
9195
9220
|
}
|
|
@@ -9207,7 +9232,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
9207
9232
|
}
|
|
9208
9233
|
}
|
|
9209
9234
|
// create logging object for log-transporter instances
|
|
9210
|
-
if (
|
|
9235
|
+
if (instanceObj?.common?.logTransporter) {
|
|
9211
9236
|
// create system.adapter.ADAPTERNAME.instance.logger
|
|
9212
9237
|
objs.push({
|
|
9213
9238
|
_id: `system.adapter.${this.namespace}.logging`,
|
|
@@ -9244,7 +9269,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
9244
9269
|
this._logger.warn(`${this.namespaceLog} Object ${task._id} is invalid: ${e.message}`);
|
|
9245
9270
|
this._logger.warn(`${this.namespaceLog} This object will not be created in future versions. Please report this to the developer.`);
|
|
9246
9271
|
}
|
|
9247
|
-
if (!
|
|
9272
|
+
if (!this.#objects) {
|
|
9248
9273
|
this._logger.info(`${this.namespaceLog} extendObjects not processed because Objects database not connected.`);
|
|
9249
9274
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
9250
9275
|
}
|
|
@@ -9257,12 +9282,12 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
9257
9282
|
// ignore
|
|
9258
9283
|
}
|
|
9259
9284
|
if (state !== undefined) {
|
|
9260
|
-
if (!
|
|
9285
|
+
if (!this.#states) {
|
|
9261
9286
|
this._logger.info(`${this.namespaceLog} extendObjects not processed because States database not connected.`);
|
|
9262
9287
|
return js_controller_common_1.tools.maybeCallbackWithError(callback, js_controller_common_1.tools.ERRORS.ERROR_DB_CLOSED);
|
|
9263
9288
|
}
|
|
9264
9289
|
this.outputCount++;
|
|
9265
|
-
|
|
9290
|
+
this.#states.setState(task._id, {
|
|
9266
9291
|
val: state,
|
|
9267
9292
|
from: `system.adapter.${this.namespace}`,
|
|
9268
9293
|
ack: true
|
|
@@ -9286,7 +9311,6 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
9286
9311
|
return mId;
|
|
9287
9312
|
}
|
|
9288
9313
|
async _init() {
|
|
9289
|
-
var _a, _b;
|
|
9290
9314
|
/**
|
|
9291
9315
|
* Initiates the databases
|
|
9292
9316
|
*/
|
|
@@ -9317,7 +9341,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
9317
9341
|
}
|
|
9318
9342
|
if (this._config.states && this._config.states.type) {
|
|
9319
9343
|
try {
|
|
9320
|
-
this.States = (await (
|
|
9344
|
+
this.States = (await import(`@iobroker/db-states-${this._config.states.type}`)).Client;
|
|
9321
9345
|
}
|
|
9322
9346
|
catch (err) {
|
|
9323
9347
|
throw new Error(`Unknown states type: ${this._config.states.type}: ${err.message}`);
|
|
@@ -9328,7 +9352,7 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
9328
9352
|
}
|
|
9329
9353
|
if (this._config.objects && this._config.objects.type) {
|
|
9330
9354
|
try {
|
|
9331
|
-
this.Objects = (await (
|
|
9355
|
+
this.Objects = (await import(`@iobroker/db-objects-${this._config.objects.type}`)).Client;
|
|
9332
9356
|
}
|
|
9333
9357
|
catch (err) {
|
|
9334
9358
|
throw new Error(`Unknown objects type: ${this._config.objects.type}: ${err.message}`);
|
|
@@ -9376,7 +9400,6 @@ class AdapterClass extends node_events_1.EventEmitter {
|
|
|
9376
9400
|
}
|
|
9377
9401
|
}
|
|
9378
9402
|
exports.AdapterClass = AdapterClass;
|
|
9379
|
-
_AdapterClass_states = new WeakMap(), _AdapterClass_objects = new WeakMap();
|
|
9380
9403
|
/**
|
|
9381
9404
|
* Polyfill to allow calling without `new`
|
|
9382
9405
|
* @type {AdapterClass}
|