@iobroker/db-objects-redis 5.0.18-alpha.0-20240129-1906f86c → 5.0.18
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.
|
@@ -48,31 +48,6 @@ const semver_1 = __importDefault(require("semver"));
|
|
|
48
48
|
const CONSTS = __importStar(require("./constants"));
|
|
49
49
|
const ERRORS = CONSTS.ERRORS;
|
|
50
50
|
class ObjectsInRedisClient {
|
|
51
|
-
client;
|
|
52
|
-
fileNamespace;
|
|
53
|
-
redisNamespace;
|
|
54
|
-
fileNamespaceL;
|
|
55
|
-
objNamespace;
|
|
56
|
-
setNamespace;
|
|
57
|
-
metaNamespace;
|
|
58
|
-
objNamespaceL;
|
|
59
|
-
supportedProtocolVersions;
|
|
60
|
-
stop;
|
|
61
|
-
sub;
|
|
62
|
-
subSystem;
|
|
63
|
-
settings;
|
|
64
|
-
preserveSettings;
|
|
65
|
-
defaultNewAcl;
|
|
66
|
-
namespace;
|
|
67
|
-
hostname;
|
|
68
|
-
scripts;
|
|
69
|
-
existingMetaObjects;
|
|
70
|
-
log;
|
|
71
|
-
activeProtocolVersion;
|
|
72
|
-
useSets;
|
|
73
|
-
noLegacyMultihost;
|
|
74
|
-
userSubscriptions;
|
|
75
|
-
systemSubscriptions;
|
|
76
51
|
constructor(settings) {
|
|
77
52
|
this.settings = settings || {};
|
|
78
53
|
this.redisNamespace = `${this.settings.redisNamespace ||
|
|
@@ -836,7 +811,7 @@ class ObjectsInRedisClient {
|
|
|
836
811
|
if (typeof options === 'string') {
|
|
837
812
|
options = { mimeType: options };
|
|
838
813
|
}
|
|
839
|
-
if (options
|
|
814
|
+
if (options === null || options === void 0 ? void 0 : options.acl) {
|
|
840
815
|
options.acl = null;
|
|
841
816
|
}
|
|
842
817
|
if (!callback) {
|
|
@@ -2179,6 +2154,7 @@ class ObjectsInRedisClient {
|
|
|
2179
2154
|
return new Promise((resolve, reject) => this.unsubscribeUser(pattern, options, err => (err ? reject(err) : resolve())));
|
|
2180
2155
|
}
|
|
2181
2156
|
async _objectHelper(keys, objs) {
|
|
2157
|
+
var _a;
|
|
2182
2158
|
if (!keys.length) {
|
|
2183
2159
|
return;
|
|
2184
2160
|
}
|
|
@@ -2196,7 +2172,7 @@ class ObjectsInRedisClient {
|
|
|
2196
2172
|
// add the object to the set + set object atomic
|
|
2197
2173
|
commands.push(['sadd', `${this.setNamespace}object.type.${obj.type}`, id]);
|
|
2198
2174
|
}
|
|
2199
|
-
if (obj.common
|
|
2175
|
+
if ((_a = obj.common) === null || _a === void 0 ? void 0 : _a.custom) {
|
|
2200
2176
|
// add to "common" set
|
|
2201
2177
|
commands.push(['sadd', `${this.setNamespace}object.common.custom`, id]);
|
|
2202
2178
|
}
|
|
@@ -2472,7 +2448,7 @@ class ObjectsInRedisClient {
|
|
|
2472
2448
|
return new Promise((resolve, reject) => this.getObject(id, options, (err, obj) => (err ? reject(err) : resolve(obj))));
|
|
2473
2449
|
}
|
|
2474
2450
|
if (typeof callback === 'function') {
|
|
2475
|
-
if (options
|
|
2451
|
+
if (options === null || options === void 0 ? void 0 : options.acl) {
|
|
2476
2452
|
options.acl = null;
|
|
2477
2453
|
}
|
|
2478
2454
|
utils.checkObjectRights(this, null, null, options, CONSTS.ACCESS_READ, (err, options) => {
|
|
@@ -2666,7 +2642,7 @@ class ObjectsInRedisClient {
|
|
|
2666
2642
|
// @ts-expect-error need to clarify, that objs is not undefined if no error is provided
|
|
2667
2643
|
this.getObjects(keys, options, (err, objs) => (err ? reject(err) : resolve(objs)), dontModify));
|
|
2668
2644
|
}
|
|
2669
|
-
if (options
|
|
2645
|
+
if (options === null || options === void 0 ? void 0 : options.acl) {
|
|
2670
2646
|
options.acl = null;
|
|
2671
2647
|
}
|
|
2672
2648
|
if (typeof callback === 'function') {
|
|
@@ -2730,6 +2706,7 @@ class ObjectsInRedisClient {
|
|
|
2730
2706
|
return new Promise((resolve, reject) => this.getObjectsByPattern(pattern, options, (err, objs) => (err ? reject(err) : resolve(objs))));
|
|
2731
2707
|
}
|
|
2732
2708
|
async _setObject(id, obj, options) {
|
|
2709
|
+
var _a, _b, _c, _d, _e;
|
|
2733
2710
|
if (!id || typeof id !== 'string' || utils.REG_CHECK_ID.test(id)) {
|
|
2734
2711
|
throw new Error(`Invalid ID: ${id}`);
|
|
2735
2712
|
}
|
|
@@ -2760,9 +2737,9 @@ class ObjectsInRedisClient {
|
|
|
2760
2737
|
throw new Error('Invalid password for update of vendor information');
|
|
2761
2738
|
}
|
|
2762
2739
|
// we need to know if custom has been added/deleted
|
|
2763
|
-
const oldObjHasCustom = oldObj
|
|
2740
|
+
const oldObjHasCustom = (_a = oldObj === null || oldObj === void 0 ? void 0 : oldObj.common) === null || _a === void 0 ? void 0 : _a.custom;
|
|
2764
2741
|
// do not delete common settings, like "history" or "mobile". It can be erased only with "null"
|
|
2765
|
-
if (oldObj
|
|
2742
|
+
if (oldObj === null || oldObj === void 0 ? void 0 : oldObj.common) {
|
|
2766
2743
|
for (const commonSetting of this.preserveSettings) {
|
|
2767
2744
|
// special case if "custom"
|
|
2768
2745
|
if (commonSetting === 'custom') {
|
|
@@ -2786,7 +2763,7 @@ class ObjectsInRedisClient {
|
|
|
2786
2763
|
obj.common = obj.common || {};
|
|
2787
2764
|
obj.common.custom = oldObj.common.custom;
|
|
2788
2765
|
}
|
|
2789
|
-
else if (obj.common
|
|
2766
|
+
else if (((_b = obj.common) === null || _b === void 0 ? void 0 : _b.custom) && oldObj.common.custom) {
|
|
2790
2767
|
// merge together
|
|
2791
2768
|
for (const attr of Object.keys(oldObj.common.custom)) {
|
|
2792
2769
|
if (obj.common.custom[attr] === null) {
|
|
@@ -2798,7 +2775,7 @@ class ObjectsInRedisClient {
|
|
|
2798
2775
|
}
|
|
2799
2776
|
}
|
|
2800
2777
|
// remove custom if no one attribute inside
|
|
2801
|
-
if (obj.common
|
|
2778
|
+
if ((_c = obj.common) === null || _c === void 0 ? void 0 : _c.custom) {
|
|
2802
2779
|
for (const attr of Object.keys(obj.common.custom)) {
|
|
2803
2780
|
if (obj.common.custom[attr] === null) {
|
|
2804
2781
|
delete obj.common.custom[attr];
|
|
@@ -2846,7 +2823,7 @@ class ObjectsInRedisClient {
|
|
|
2846
2823
|
}
|
|
2847
2824
|
}
|
|
2848
2825
|
}
|
|
2849
|
-
if (oldObj
|
|
2826
|
+
if ((oldObj === null || oldObj === void 0 ? void 0 : oldObj.acl) && !obj.acl) {
|
|
2850
2827
|
obj.acl = oldObj.acl;
|
|
2851
2828
|
}
|
|
2852
2829
|
// add user default rights if no acl provided
|
|
@@ -2873,7 +2850,7 @@ class ObjectsInRedisClient {
|
|
|
2873
2850
|
const message = JSON.stringify(obj);
|
|
2874
2851
|
const commands = [];
|
|
2875
2852
|
if (this.useSets) {
|
|
2876
|
-
if (obj.type && !oldObj
|
|
2853
|
+
if (obj.type && !(oldObj === null || oldObj === void 0 ? void 0 : oldObj.type)) {
|
|
2877
2854
|
// new object or oldObj had no type -> add to set + set object
|
|
2878
2855
|
commands.push(['sadd', `${this.setNamespace}object.type.${obj.type}`, this.objNamespace + id]);
|
|
2879
2856
|
}
|
|
@@ -2881,16 +2858,16 @@ class ObjectsInRedisClient {
|
|
|
2881
2858
|
// the old obj had a type which differs from the new type -> rem old, add new
|
|
2882
2859
|
commands.push(['sadd', `${this.setNamespace}object.type.${obj.type}`, this.objNamespace + id], ['srem', `${this.setNamespace}object.type.${oldObj.type}`, this.objNamespace + id]);
|
|
2883
2860
|
}
|
|
2884
|
-
else if (oldObj
|
|
2861
|
+
else if ((oldObj === null || oldObj === void 0 ? void 0 : oldObj.type) && !obj.type) {
|
|
2885
2862
|
// the oldObj had a type, the new one has no -> rem
|
|
2886
2863
|
// @ts-expect-error TODO remove in v5.1, for now support objs without type for legacy design objects
|
|
2887
2864
|
commands.push(['srem', `${this.setNamespace}object.type.${obj.type}`, this.objNamespace + id]);
|
|
2888
2865
|
}
|
|
2889
|
-
if (obj.common
|
|
2866
|
+
if (((_d = obj.common) === null || _d === void 0 ? void 0 : _d.custom) && !oldObjHasCustom) {
|
|
2890
2867
|
// we now have custom, old object had no custom
|
|
2891
2868
|
commands.push(['sadd', `${this.setNamespace}object.common.custom`, this.objNamespace + id]);
|
|
2892
2869
|
}
|
|
2893
|
-
else if (oldObjHasCustom && !obj.common
|
|
2870
|
+
else if (oldObjHasCustom && !((_e = obj.common) === null || _e === void 0 ? void 0 : _e.custom)) {
|
|
2894
2871
|
// we no longer have custom
|
|
2895
2872
|
commands.push(['srem', `${this.setNamespace}object.common.custom`, this.objNamespace + id]);
|
|
2896
2873
|
}
|
|
@@ -2904,7 +2881,7 @@ class ObjectsInRedisClient {
|
|
|
2904
2881
|
await this.client.multi(commands).exec();
|
|
2905
2882
|
}
|
|
2906
2883
|
// object updated -> if type changed to meta -> cache
|
|
2907
|
-
if (oldObj
|
|
2884
|
+
if ((oldObj === null || oldObj === void 0 ? void 0 : oldObj.type) === 'meta' && this.existingMetaObjects[id] === false) {
|
|
2908
2885
|
this.existingMetaObjects[id] = true;
|
|
2909
2886
|
}
|
|
2910
2887
|
await this.client.publish(this.objNamespace + id, message);
|
|
@@ -2953,6 +2930,7 @@ class ObjectsInRedisClient {
|
|
|
2953
2930
|
this.setObject(id, obj, options, (err, res) => (err ? reject(err) : resolve(res))));
|
|
2954
2931
|
}
|
|
2955
2932
|
async _delObject(id, options) {
|
|
2933
|
+
var _a;
|
|
2956
2934
|
if (!id || typeof id !== 'string' || utils.REG_CHECK_ID.test(id)) {
|
|
2957
2935
|
throw new Error(`Invalid ID: ${id}`);
|
|
2958
2936
|
}
|
|
@@ -2992,7 +2970,7 @@ class ObjectsInRedisClient {
|
|
|
2992
2970
|
// del the object from the set + del object atomic
|
|
2993
2971
|
commands.push(['srem', `${this.setNamespace}object.type.${oldObj.type}`, this.objNamespace + id]);
|
|
2994
2972
|
}
|
|
2995
|
-
if (oldObj.common
|
|
2973
|
+
if ((_a = oldObj.common) === null || _a === void 0 ? void 0 : _a.custom) {
|
|
2996
2974
|
// del the object from "custom" set
|
|
2997
2975
|
commands.push(['srem', `${this.setNamespace}object.common.custom`, this.objNamespace + id]);
|
|
2998
2976
|
}
|
|
@@ -3021,7 +2999,7 @@ class ObjectsInRedisClient {
|
|
|
3021
2999
|
if (!callback) {
|
|
3022
3000
|
return new Promise((resolve, reject) => this.delObject(id, options, err => (err ? reject(err) : resolve())));
|
|
3023
3001
|
}
|
|
3024
|
-
if (options
|
|
3002
|
+
if (options === null || options === void 0 ? void 0 : options.acl) {
|
|
3025
3003
|
options.acl = null;
|
|
3026
3004
|
}
|
|
3027
3005
|
utils.checkObjectRights(this, null, null, options, CONSTS.ACCESS_DELETE, async (err, options) => {
|
|
@@ -3060,6 +3038,7 @@ class ObjectsInRedisClient {
|
|
|
3060
3038
|
}
|
|
3061
3039
|
// this function is very ineffective. Because reads all objects and then process them
|
|
3062
3040
|
async _applyViewFunc(func, params, options = {}) {
|
|
3041
|
+
var _a;
|
|
3063
3042
|
if (!this.client) {
|
|
3064
3043
|
throw new Error(ERRORS.ERROR_DB_CLOSED);
|
|
3065
3044
|
}
|
|
@@ -3106,7 +3085,7 @@ class ObjectsInRedisClient {
|
|
|
3106
3085
|
}
|
|
3107
3086
|
const matches = func.map.match(/if\s\(doc\.type\s?===?\s?'(\w+)'\)\semit\(([^,]+),\s?doc\s?\)/);
|
|
3108
3087
|
// filter by type
|
|
3109
|
-
if (wildCardLastPos && func
|
|
3088
|
+
if (wildCardLastPos && (func === null || func === void 0 ? void 0 : func.map) && this.scripts.filter && matches) {
|
|
3110
3089
|
let cursor = '0';
|
|
3111
3090
|
let filterRequired = true;
|
|
3112
3091
|
do {
|
|
@@ -3200,7 +3179,7 @@ class ObjectsInRedisClient {
|
|
|
3200
3179
|
else if (
|
|
3201
3180
|
// filter by script
|
|
3202
3181
|
wildCardLastPos &&
|
|
3203
|
-
func
|
|
3182
|
+
(func === null || func === void 0 ? void 0 : func.map) &&
|
|
3204
3183
|
this.scripts.script &&
|
|
3205
3184
|
func.map.includes('doc.common.engineType')) {
|
|
3206
3185
|
let cursor = '0';
|
|
@@ -3257,7 +3236,7 @@ class ObjectsInRedisClient {
|
|
|
3257
3236
|
else if (
|
|
3258
3237
|
// filter by hm-rega programs
|
|
3259
3238
|
wildCardLastPos &&
|
|
3260
|
-
func
|
|
3239
|
+
(func === null || func === void 0 ? void 0 : func.map) &&
|
|
3261
3240
|
this.scripts.programs &&
|
|
3262
3241
|
func.map.includes("doc.native.TypeName === 'PROGRAM'")) {
|
|
3263
3242
|
let cursor = '0';
|
|
@@ -3312,7 +3291,7 @@ class ObjectsInRedisClient {
|
|
|
3312
3291
|
else if (
|
|
3313
3292
|
// filter by hm-rega variables
|
|
3314
3293
|
wildCardLastPos &&
|
|
3315
|
-
func
|
|
3294
|
+
(func === null || func === void 0 ? void 0 : func.map) &&
|
|
3316
3295
|
this.scripts.variables &&
|
|
3317
3296
|
func.map.includes("doc.native.TypeName === 'ALARMDP'")) {
|
|
3318
3297
|
let cursor = '0';
|
|
@@ -3367,7 +3346,7 @@ class ObjectsInRedisClient {
|
|
|
3367
3346
|
else if (
|
|
3368
3347
|
// filter by custom, redis also returns if common.custom is not present
|
|
3369
3348
|
wildCardLastPos &&
|
|
3370
|
-
func
|
|
3349
|
+
(func === null || func === void 0 ? void 0 : func.map) &&
|
|
3371
3350
|
this.scripts.custom &&
|
|
3372
3351
|
func.map.includes('doc.common.custom')) {
|
|
3373
3352
|
let cursor = '0';
|
|
@@ -3411,7 +3390,7 @@ class ObjectsInRedisClient {
|
|
|
3411
3390
|
this.log.error(`${this.namespace} Cannot parse JSON: ${_obj}`);
|
|
3412
3391
|
continue;
|
|
3413
3392
|
}
|
|
3414
|
-
if (obj
|
|
3393
|
+
if ((_a = obj === null || obj === void 0 ? void 0 : obj.common) === null || _a === void 0 ? void 0 : _a.custom) {
|
|
3415
3394
|
if (useFullObject) {
|
|
3416
3395
|
result.rows.push({ id: obj._id, value: obj });
|
|
3417
3396
|
}
|
|
@@ -3518,6 +3497,7 @@ class ObjectsInRedisClient {
|
|
|
3518
3497
|
}
|
|
3519
3498
|
}
|
|
3520
3499
|
async _getObjectView(design, search, params, options) {
|
|
3500
|
+
var _a;
|
|
3521
3501
|
if (!this.client) {
|
|
3522
3502
|
throw new Error(ERRORS.ERROR_DB_CLOSED);
|
|
3523
3503
|
}
|
|
@@ -3537,7 +3517,7 @@ class ObjectsInRedisClient {
|
|
|
3537
3517
|
this.log.error(`${this.namespace} Cannot parse JSON: ${obj}`);
|
|
3538
3518
|
throw new Error(`Cannot parse JSON: "_design/${design}" / "${obj}"`);
|
|
3539
3519
|
}
|
|
3540
|
-
if (obj.views
|
|
3520
|
+
if ((_a = obj.views) === null || _a === void 0 ? void 0 : _a[search]) {
|
|
3541
3521
|
return this._applyViewFunc(obj.views[search], params, options);
|
|
3542
3522
|
}
|
|
3543
3523
|
else {
|
|
@@ -3558,7 +3538,7 @@ class ObjectsInRedisClient {
|
|
|
3558
3538
|
if (!callback) {
|
|
3559
3539
|
return new Promise((resolve, reject) => this.getObjectView(design, search, params, options, (err, obj) => (err ? reject(err) : resolve(obj))));
|
|
3560
3540
|
}
|
|
3561
|
-
if (options
|
|
3541
|
+
if (options === null || options === void 0 ? void 0 : options.acl) {
|
|
3562
3542
|
options.acl = null;
|
|
3563
3543
|
}
|
|
3564
3544
|
if (typeof callback === 'function') {
|
|
@@ -3585,6 +3565,7 @@ class ObjectsInRedisClient {
|
|
|
3585
3565
|
if (!this.client) {
|
|
3586
3566
|
throw new Error(ERRORS.ERROR_DB_CLOSED);
|
|
3587
3567
|
}
|
|
3568
|
+
//params = {startkey, endkey, include_docs}
|
|
3588
3569
|
params = params || {};
|
|
3589
3570
|
params.startkey = params.startkey || '';
|
|
3590
3571
|
params.endkey = params.endkey || '\u9999';
|
|
@@ -3653,7 +3634,7 @@ class ObjectsInRedisClient {
|
|
|
3653
3634
|
if (!callback) {
|
|
3654
3635
|
return new Promise((resolve, reject) => this.getObjectList(params, options, (err, obj) => (err ? reject(err) : resolve(obj))));
|
|
3655
3636
|
}
|
|
3656
|
-
if (options
|
|
3637
|
+
if (options === null || options === void 0 ? void 0 : options.acl) {
|
|
3657
3638
|
options.acl = null;
|
|
3658
3639
|
}
|
|
3659
3640
|
if (typeof callback === 'function') {
|
|
@@ -3678,6 +3659,7 @@ class ObjectsInRedisClient {
|
|
|
3678
3659
|
}
|
|
3679
3660
|
// could be optimized, to read object only once. Now it will read 3 times
|
|
3680
3661
|
async _extendObject(id, obj, options, callback) {
|
|
3662
|
+
var _a;
|
|
3681
3663
|
if (!id || typeof id !== 'string' || utils.REG_CHECK_ID.test(id)) {
|
|
3682
3664
|
// @ts-expect-error we fix when removing cb
|
|
3683
3665
|
return db_base_1.tools.maybeCallbackWithError(callback, `Invalid ID: ${id}`);
|
|
@@ -3704,12 +3686,12 @@ class ObjectsInRedisClient {
|
|
|
3704
3686
|
return db_base_1.tools.maybeCallbackWithError(callback, ERRORS.ERROR_PERMISSION);
|
|
3705
3687
|
}
|
|
3706
3688
|
let _oldObj;
|
|
3707
|
-
if (oldObj
|
|
3689
|
+
if (oldObj === null || oldObj === void 0 ? void 0 : oldObj.nonEdit) {
|
|
3708
3690
|
// copy object
|
|
3709
3691
|
_oldObj = (0, deep_clone_1.default)(oldObj);
|
|
3710
3692
|
}
|
|
3711
3693
|
// we need to know if custom has been added/deleted
|
|
3712
|
-
const oldObjHasCustom = !!oldObj
|
|
3694
|
+
const oldObjHasCustom = !!((_a = oldObj === null || oldObj === void 0 ? void 0 : oldObj.common) === null || _a === void 0 ? void 0 : _a.custom);
|
|
3713
3695
|
oldObj = oldObj || {};
|
|
3714
3696
|
obj = (0, deep_clone_1.default)(obj); // copy here to prevent "sandboxed" objects from JavaScript adapter
|
|
3715
3697
|
if (oldObj.common &&
|
|
@@ -3882,7 +3864,7 @@ class ObjectsInRedisClient {
|
|
|
3882
3864
|
this.log.error(`${this.namespace} Cannot parse JSON ${keys[i]}: ${objs[i]}`);
|
|
3883
3865
|
continue;
|
|
3884
3866
|
}
|
|
3885
|
-
if (obj
|
|
3867
|
+
if ((obj === null || obj === void 0 ? void 0 : obj.common) &&
|
|
3886
3868
|
obj.common.name === idOrName &&
|
|
3887
3869
|
(!type || ('type' in obj.common && obj.common.type === type))) {
|
|
3888
3870
|
return db_base_1.tools.maybeCallbackWithError(callback, null, obj._id, idOrName);
|
|
@@ -3906,7 +3888,7 @@ class ObjectsInRedisClient {
|
|
|
3906
3888
|
if (!callback) {
|
|
3907
3889
|
return new Promise((resolve, reject) => this.findObject(idOrName, type, options, (err, id, _idOrName) => (err ? reject(err) : resolve(id))));
|
|
3908
3890
|
}
|
|
3909
|
-
if (options
|
|
3891
|
+
if (options === null || options === void 0 ? void 0 : options.acl) {
|
|
3910
3892
|
options.acl = null;
|
|
3911
3893
|
}
|
|
3912
3894
|
if (typeof callback === 'function') {
|
|
@@ -4125,6 +4107,7 @@ class ObjectsInRedisClient {
|
|
|
4125
4107
|
* @return number of migrated sets
|
|
4126
4108
|
*/
|
|
4127
4109
|
async migrateToSets() {
|
|
4110
|
+
var _a;
|
|
4128
4111
|
if (!this.useSets) {
|
|
4129
4112
|
return 0;
|
|
4130
4113
|
}
|
|
@@ -4150,7 +4133,7 @@ class ObjectsInRedisClient {
|
|
|
4150
4133
|
noMigrated += migrated;
|
|
4151
4134
|
}
|
|
4152
4135
|
// check for custom
|
|
4153
|
-
if (obj.value.common
|
|
4136
|
+
if ((_a = obj.value.common) === null || _a === void 0 ? void 0 : _a.custom) {
|
|
4154
4137
|
const migrated = await this.client.sadd(`${this.setNamespace}object.common.custom`, this.objNamespace + obj.id);
|
|
4155
4138
|
noMigrated += migrated;
|
|
4156
4139
|
}
|