@iobroker/db-objects-redis 5.0.17 → 5.0.18-alpha.0-20231211-5b429316
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/objects/objectsInRedisClient.js +54 -36
- package/build/lib/objects/objectsInRedisClient.js.map +1 -1
- package/build/lib/objects/objectsUtils.d.ts +1 -1
- package/build/lib/objects/objectsUtils.d.ts.map +1 -1
- package/build/lib/objects/objectsUtils.js +11 -11
- package/build/lib/objects/objectsUtils.js.map +1 -1
- package/package.json +3 -3
|
@@ -48,6 +48,31 @@ 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;
|
|
51
76
|
constructor(settings) {
|
|
52
77
|
this.settings = settings || {};
|
|
53
78
|
this.redisNamespace = `${this.settings.redisNamespace ||
|
|
@@ -814,7 +839,7 @@ class ObjectsInRedisClient {
|
|
|
814
839
|
if (typeof options === 'string') {
|
|
815
840
|
options = { mimeType: options };
|
|
816
841
|
}
|
|
817
|
-
if (options
|
|
842
|
+
if (options?.acl) {
|
|
818
843
|
options.acl = null;
|
|
819
844
|
}
|
|
820
845
|
if (!callback) {
|
|
@@ -2157,7 +2182,6 @@ class ObjectsInRedisClient {
|
|
|
2157
2182
|
return new Promise((resolve, reject) => this.unsubscribeUser(pattern, options, err => (err ? reject(err) : resolve())));
|
|
2158
2183
|
}
|
|
2159
2184
|
async _objectHelper(keys, objs) {
|
|
2160
|
-
var _a;
|
|
2161
2185
|
if (!keys.length) {
|
|
2162
2186
|
return;
|
|
2163
2187
|
}
|
|
@@ -2175,7 +2199,7 @@ class ObjectsInRedisClient {
|
|
|
2175
2199
|
// add the object to the set + set object atomic
|
|
2176
2200
|
commands.push(['sadd', `${this.setNamespace}object.type.${obj.type}`, id]);
|
|
2177
2201
|
}
|
|
2178
|
-
if (
|
|
2202
|
+
if (obj.common?.custom) {
|
|
2179
2203
|
// add to "common" set
|
|
2180
2204
|
commands.push(['sadd', `${this.setNamespace}object.common.custom`, id]);
|
|
2181
2205
|
}
|
|
@@ -2451,7 +2475,7 @@ class ObjectsInRedisClient {
|
|
|
2451
2475
|
return new Promise((resolve, reject) => this.getObject(id, options, (err, obj) => (err ? reject(err) : resolve(obj))));
|
|
2452
2476
|
}
|
|
2453
2477
|
if (typeof callback === 'function') {
|
|
2454
|
-
if (options
|
|
2478
|
+
if (options?.acl) {
|
|
2455
2479
|
options.acl = null;
|
|
2456
2480
|
}
|
|
2457
2481
|
utils.checkObjectRights(this, null, null, options, CONSTS.ACCESS_READ, (err, options) => {
|
|
@@ -2709,7 +2733,6 @@ class ObjectsInRedisClient {
|
|
|
2709
2733
|
return new Promise((resolve, reject) => this.getObjectsByPattern(pattern, options, (err, objs) => (err ? reject(err) : resolve(objs))));
|
|
2710
2734
|
}
|
|
2711
2735
|
async _setObject(id, obj, options) {
|
|
2712
|
-
var _a, _b, _c, _d, _e;
|
|
2713
2736
|
if (!id || typeof id !== 'string' || utils.REG_CHECK_ID.test(id)) {
|
|
2714
2737
|
throw new Error(`Invalid ID: ${id}`);
|
|
2715
2738
|
}
|
|
@@ -2740,9 +2763,9 @@ class ObjectsInRedisClient {
|
|
|
2740
2763
|
throw new Error('Invalid password for update of vendor information');
|
|
2741
2764
|
}
|
|
2742
2765
|
// we need to know if custom has been added/deleted
|
|
2743
|
-
const oldObjHasCustom =
|
|
2766
|
+
const oldObjHasCustom = oldObj?.common?.custom;
|
|
2744
2767
|
// do not delete common settings, like "history" or "mobile". It can be erased only with "null"
|
|
2745
|
-
if (oldObj
|
|
2768
|
+
if (oldObj?.common) {
|
|
2746
2769
|
for (const commonSetting of this.preserveSettings) {
|
|
2747
2770
|
// special case if "custom"
|
|
2748
2771
|
if (commonSetting === 'custom') {
|
|
@@ -2766,7 +2789,7 @@ class ObjectsInRedisClient {
|
|
|
2766
2789
|
obj.common = obj.common || {};
|
|
2767
2790
|
obj.common.custom = oldObj.common.custom;
|
|
2768
2791
|
}
|
|
2769
|
-
else if (
|
|
2792
|
+
else if (obj.common?.custom && oldObj.common.custom) {
|
|
2770
2793
|
// merge together
|
|
2771
2794
|
for (const attr of Object.keys(oldObj.common.custom)) {
|
|
2772
2795
|
if (obj.common.custom[attr] === null) {
|
|
@@ -2778,7 +2801,7 @@ class ObjectsInRedisClient {
|
|
|
2778
2801
|
}
|
|
2779
2802
|
}
|
|
2780
2803
|
// remove custom if no one attribute inside
|
|
2781
|
-
if (
|
|
2804
|
+
if (obj.common?.custom) {
|
|
2782
2805
|
for (const attr of Object.keys(obj.common.custom)) {
|
|
2783
2806
|
if (obj.common.custom[attr] === null) {
|
|
2784
2807
|
delete obj.common.custom[attr];
|
|
@@ -2826,7 +2849,7 @@ class ObjectsInRedisClient {
|
|
|
2826
2849
|
}
|
|
2827
2850
|
}
|
|
2828
2851
|
}
|
|
2829
|
-
if (
|
|
2852
|
+
if (oldObj?.acl && !obj.acl) {
|
|
2830
2853
|
obj.acl = oldObj.acl;
|
|
2831
2854
|
}
|
|
2832
2855
|
// add user default rights if no acl provided
|
|
@@ -2853,7 +2876,7 @@ class ObjectsInRedisClient {
|
|
|
2853
2876
|
const message = JSON.stringify(obj);
|
|
2854
2877
|
const commands = [];
|
|
2855
2878
|
if (this.useSets) {
|
|
2856
|
-
if (obj.type && !
|
|
2879
|
+
if (obj.type && !oldObj?.type) {
|
|
2857
2880
|
// new object or oldObj had no type -> add to set + set object
|
|
2858
2881
|
commands.push(['sadd', `${this.setNamespace}object.type.${obj.type}`, this.objNamespace + id]);
|
|
2859
2882
|
}
|
|
@@ -2861,16 +2884,16 @@ class ObjectsInRedisClient {
|
|
|
2861
2884
|
// the old obj had a type which differs from the new type -> rem old, add new
|
|
2862
2885
|
commands.push(['sadd', `${this.setNamespace}object.type.${obj.type}`, this.objNamespace + id], ['srem', `${this.setNamespace}object.type.${oldObj.type}`, this.objNamespace + id]);
|
|
2863
2886
|
}
|
|
2864
|
-
else if (
|
|
2887
|
+
else if (oldObj?.type && !obj.type) {
|
|
2865
2888
|
// the oldObj had a type, the new one has no -> rem
|
|
2866
2889
|
// @ts-expect-error TODO remove in v5.1, for now support objs without type for legacy design objects
|
|
2867
2890
|
commands.push(['srem', `${this.setNamespace}object.type.${obj.type}`, this.objNamespace + id]);
|
|
2868
2891
|
}
|
|
2869
|
-
if (
|
|
2892
|
+
if (obj.common?.custom && !oldObjHasCustom) {
|
|
2870
2893
|
// we now have custom, old object had no custom
|
|
2871
2894
|
commands.push(['sadd', `${this.setNamespace}object.common.custom`, this.objNamespace + id]);
|
|
2872
2895
|
}
|
|
2873
|
-
else if (oldObjHasCustom && !
|
|
2896
|
+
else if (oldObjHasCustom && !obj.common?.custom) {
|
|
2874
2897
|
// we no longer have custom
|
|
2875
2898
|
commands.push(['srem', `${this.setNamespace}object.common.custom`, this.objNamespace + id]);
|
|
2876
2899
|
}
|
|
@@ -2884,7 +2907,7 @@ class ObjectsInRedisClient {
|
|
|
2884
2907
|
await this.client.multi(commands).exec();
|
|
2885
2908
|
}
|
|
2886
2909
|
// object updated -> if type changed to meta -> cache
|
|
2887
|
-
if (
|
|
2910
|
+
if (oldObj?.type === 'meta' && this.existingMetaObjects[id] === false) {
|
|
2888
2911
|
this.existingMetaObjects[id] = true;
|
|
2889
2912
|
}
|
|
2890
2913
|
await this.client.publish(this.objNamespace + id, message);
|
|
@@ -2933,7 +2956,6 @@ class ObjectsInRedisClient {
|
|
|
2933
2956
|
this.setObject(id, obj, options, (err, res) => (err ? reject(err) : resolve(res))));
|
|
2934
2957
|
}
|
|
2935
2958
|
async _delObject(id, options) {
|
|
2936
|
-
var _a;
|
|
2937
2959
|
if (!id || typeof id !== 'string' || utils.REG_CHECK_ID.test(id)) {
|
|
2938
2960
|
throw new Error(`Invalid ID: ${id}`);
|
|
2939
2961
|
}
|
|
@@ -2973,7 +2995,7 @@ class ObjectsInRedisClient {
|
|
|
2973
2995
|
// del the object from the set + del object atomic
|
|
2974
2996
|
commands.push(['srem', `${this.setNamespace}object.type.${oldObj.type}`, this.objNamespace + id]);
|
|
2975
2997
|
}
|
|
2976
|
-
if (
|
|
2998
|
+
if (oldObj.common?.custom) {
|
|
2977
2999
|
// del the object from "custom" set
|
|
2978
3000
|
commands.push(['srem', `${this.setNamespace}object.common.custom`, this.objNamespace + id]);
|
|
2979
3001
|
}
|
|
@@ -3002,7 +3024,7 @@ class ObjectsInRedisClient {
|
|
|
3002
3024
|
if (!callback) {
|
|
3003
3025
|
return new Promise((resolve, reject) => this.delObject(id, options, err => (err ? reject(err) : resolve())));
|
|
3004
3026
|
}
|
|
3005
|
-
if (options
|
|
3027
|
+
if (options?.acl) {
|
|
3006
3028
|
options.acl = null;
|
|
3007
3029
|
}
|
|
3008
3030
|
utils.checkObjectRights(this, null, null, options, CONSTS.ACCESS_DELETE, async (err, options) => {
|
|
@@ -3041,7 +3063,6 @@ class ObjectsInRedisClient {
|
|
|
3041
3063
|
}
|
|
3042
3064
|
// this function is very ineffective. Because reads all objects and then process them
|
|
3043
3065
|
async _applyViewFunc(func, params, options = {}) {
|
|
3044
|
-
var _a;
|
|
3045
3066
|
if (!this.client) {
|
|
3046
3067
|
throw new Error(ERRORS.ERROR_DB_CLOSED);
|
|
3047
3068
|
}
|
|
@@ -3088,7 +3109,7 @@ class ObjectsInRedisClient {
|
|
|
3088
3109
|
}
|
|
3089
3110
|
const matches = func.map.match(/if\s\(doc\.type\s?===?\s?'(\w+)'\)\semit\(([^,]+),\s?doc\s?\)/);
|
|
3090
3111
|
// filter by type
|
|
3091
|
-
if (wildCardLastPos &&
|
|
3112
|
+
if (wildCardLastPos && func?.map && this.scripts.filter && matches) {
|
|
3092
3113
|
let cursor = '0';
|
|
3093
3114
|
let filterRequired = true;
|
|
3094
3115
|
do {
|
|
@@ -3182,7 +3203,7 @@ class ObjectsInRedisClient {
|
|
|
3182
3203
|
else if (
|
|
3183
3204
|
// filter by script
|
|
3184
3205
|
wildCardLastPos &&
|
|
3185
|
-
|
|
3206
|
+
func?.map &&
|
|
3186
3207
|
this.scripts.script &&
|
|
3187
3208
|
func.map.includes('doc.common.engineType')) {
|
|
3188
3209
|
let cursor = '0';
|
|
@@ -3239,7 +3260,7 @@ class ObjectsInRedisClient {
|
|
|
3239
3260
|
else if (
|
|
3240
3261
|
// filter by hm-rega programs
|
|
3241
3262
|
wildCardLastPos &&
|
|
3242
|
-
|
|
3263
|
+
func?.map &&
|
|
3243
3264
|
this.scripts.programs &&
|
|
3244
3265
|
func.map.includes("doc.native.TypeName === 'PROGRAM'")) {
|
|
3245
3266
|
let cursor = '0';
|
|
@@ -3294,7 +3315,7 @@ class ObjectsInRedisClient {
|
|
|
3294
3315
|
else if (
|
|
3295
3316
|
// filter by hm-rega variables
|
|
3296
3317
|
wildCardLastPos &&
|
|
3297
|
-
|
|
3318
|
+
func?.map &&
|
|
3298
3319
|
this.scripts.variables &&
|
|
3299
3320
|
func.map.includes("doc.native.TypeName === 'ALARMDP'")) {
|
|
3300
3321
|
let cursor = '0';
|
|
@@ -3349,7 +3370,7 @@ class ObjectsInRedisClient {
|
|
|
3349
3370
|
else if (
|
|
3350
3371
|
// filter by custom, redis also returns if common.custom is not present
|
|
3351
3372
|
wildCardLastPos &&
|
|
3352
|
-
|
|
3373
|
+
func?.map &&
|
|
3353
3374
|
this.scripts.custom &&
|
|
3354
3375
|
func.map.includes('doc.common.custom')) {
|
|
3355
3376
|
let cursor = '0';
|
|
@@ -3393,7 +3414,7 @@ class ObjectsInRedisClient {
|
|
|
3393
3414
|
this.log.error(`${this.namespace} Cannot parse JSON: ${_obj}`);
|
|
3394
3415
|
continue;
|
|
3395
3416
|
}
|
|
3396
|
-
if (
|
|
3417
|
+
if (obj?.common?.custom) {
|
|
3397
3418
|
if (useFullObject) {
|
|
3398
3419
|
result.rows.push({ id: obj._id, value: obj });
|
|
3399
3420
|
}
|
|
@@ -3500,7 +3521,6 @@ class ObjectsInRedisClient {
|
|
|
3500
3521
|
}
|
|
3501
3522
|
}
|
|
3502
3523
|
async _getObjectView(design, search, params, options) {
|
|
3503
|
-
var _a;
|
|
3504
3524
|
if (!this.client) {
|
|
3505
3525
|
throw new Error(ERRORS.ERROR_DB_CLOSED);
|
|
3506
3526
|
}
|
|
@@ -3520,7 +3540,7 @@ class ObjectsInRedisClient {
|
|
|
3520
3540
|
this.log.error(`${this.namespace} Cannot parse JSON: ${obj}`);
|
|
3521
3541
|
throw new Error(`Cannot parse JSON: "_design/${design}" / "${obj}"`);
|
|
3522
3542
|
}
|
|
3523
|
-
if (
|
|
3543
|
+
if (obj.views?.[search]) {
|
|
3524
3544
|
return this._applyViewFunc(obj.views[search], params, options);
|
|
3525
3545
|
}
|
|
3526
3546
|
else {
|
|
@@ -3541,7 +3561,7 @@ class ObjectsInRedisClient {
|
|
|
3541
3561
|
if (!callback) {
|
|
3542
3562
|
return new Promise((resolve, reject) => this.getObjectView(design, search, params, options, (err, obj) => (err ? reject(err) : resolve(obj))));
|
|
3543
3563
|
}
|
|
3544
|
-
if (options
|
|
3564
|
+
if (options?.acl) {
|
|
3545
3565
|
options.acl = null;
|
|
3546
3566
|
}
|
|
3547
3567
|
if (typeof callback === 'function') {
|
|
@@ -3637,7 +3657,7 @@ class ObjectsInRedisClient {
|
|
|
3637
3657
|
if (!callback) {
|
|
3638
3658
|
return new Promise((resolve, reject) => this.getObjectList(params, options, (err, obj) => (err ? reject(err) : resolve(obj))));
|
|
3639
3659
|
}
|
|
3640
|
-
if (options
|
|
3660
|
+
if (options?.acl) {
|
|
3641
3661
|
options.acl = null;
|
|
3642
3662
|
}
|
|
3643
3663
|
if (typeof callback === 'function') {
|
|
@@ -3662,7 +3682,6 @@ class ObjectsInRedisClient {
|
|
|
3662
3682
|
}
|
|
3663
3683
|
// could be optimized, to read object only once. Now it will read 3 times
|
|
3664
3684
|
async _extendObject(id, obj, options, callback) {
|
|
3665
|
-
var _a;
|
|
3666
3685
|
if (!id || typeof id !== 'string' || utils.REG_CHECK_ID.test(id)) {
|
|
3667
3686
|
// @ts-expect-error we fix when removing cb
|
|
3668
3687
|
return db_base_1.tools.maybeCallbackWithError(callback, `Invalid ID: ${id}`);
|
|
@@ -3689,12 +3708,12 @@ class ObjectsInRedisClient {
|
|
|
3689
3708
|
return db_base_1.tools.maybeCallbackWithError(callback, ERRORS.ERROR_PERMISSION);
|
|
3690
3709
|
}
|
|
3691
3710
|
let _oldObj;
|
|
3692
|
-
if (oldObj
|
|
3711
|
+
if (oldObj?.nonEdit) {
|
|
3693
3712
|
// copy object
|
|
3694
3713
|
_oldObj = (0, deep_clone_1.default)(oldObj);
|
|
3695
3714
|
}
|
|
3696
3715
|
// we need to know if custom has been added/deleted
|
|
3697
|
-
const oldObjHasCustom = !!
|
|
3716
|
+
const oldObjHasCustom = !!oldObj?.common?.custom;
|
|
3698
3717
|
oldObj = oldObj || {};
|
|
3699
3718
|
obj = (0, deep_clone_1.default)(obj); // copy here to prevent "sandboxed" objects from JavaScript adapter
|
|
3700
3719
|
if (oldObj.common &&
|
|
@@ -3867,7 +3886,7 @@ class ObjectsInRedisClient {
|
|
|
3867
3886
|
this.log.error(`${this.namespace} Cannot parse JSON ${keys[i]}: ${objs[i]}`);
|
|
3868
3887
|
continue;
|
|
3869
3888
|
}
|
|
3870
|
-
if (
|
|
3889
|
+
if (obj?.common &&
|
|
3871
3890
|
obj.common.name === idOrName &&
|
|
3872
3891
|
(!type || ('type' in obj.common && obj.common.type === type))) {
|
|
3873
3892
|
return db_base_1.tools.maybeCallbackWithError(callback, null, obj._id, idOrName);
|
|
@@ -3891,7 +3910,7 @@ class ObjectsInRedisClient {
|
|
|
3891
3910
|
if (!callback) {
|
|
3892
3911
|
return new Promise((resolve, reject) => this.findObject(idOrName, type, options, (err, id, _idOrName) => (err ? reject(err) : resolve(id))));
|
|
3893
3912
|
}
|
|
3894
|
-
if (options
|
|
3913
|
+
if (options?.acl) {
|
|
3895
3914
|
options.acl = null;
|
|
3896
3915
|
}
|
|
3897
3916
|
if (typeof callback === 'function') {
|
|
@@ -4110,7 +4129,6 @@ class ObjectsInRedisClient {
|
|
|
4110
4129
|
* @return number of migrated sets
|
|
4111
4130
|
*/
|
|
4112
4131
|
async migrateToSets() {
|
|
4113
|
-
var _a;
|
|
4114
4132
|
if (!this.useSets) {
|
|
4115
4133
|
return 0;
|
|
4116
4134
|
}
|
|
@@ -4136,7 +4154,7 @@ class ObjectsInRedisClient {
|
|
|
4136
4154
|
noMigrated += migrated;
|
|
4137
4155
|
}
|
|
4138
4156
|
// check for custom
|
|
4139
|
-
if (
|
|
4157
|
+
if (obj.value.common?.custom) {
|
|
4140
4158
|
const migrated = await this.client.sadd(`${this.setNamespace}object.common.custom`, this.objNamespace + obj.id);
|
|
4141
4159
|
noMigrated += migrated;
|
|
4142
4160
|
}
|