@iobroker/db-objects-file 4.0.0-alpha.49-20220121-e7aa4308 → 4.0.0-alpha.52-20220126-dad3d5b3

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.
@@ -58,24 +58,18 @@ class ObjectsInMemoryFileDB extends InMemoryFileDB {
58
58
 
59
59
  // Handle some < js-controller 2.0 broken objects and correct them
60
60
  for (const key of Object.keys(this.dataset)) {
61
- if (
62
- typeof this.dataset[key] === 'object' &&
63
- this.dataset[key].acl &&
64
- this.dataset[key].acl.permissions &&
65
- !this.dataset[key].acl.object
66
- ) {
67
- this.dataset[key].acl.object = this.dataset[key].acl.permissions;
68
- delete this.dataset[key].acl.permissions;
61
+ const obj = this.dataset[key];
62
+ if (tools.isObject(obj) && obj.acl && obj.acl.permissions && !obj.acl.object) {
63
+ obj.acl.object = obj.acl.permissions;
64
+ delete obj.acl.permissions;
65
+ this.dataset[key] = obj;
69
66
  }
70
67
  }
71
68
 
72
69
  // init default new acl
73
- if (
74
- this.dataset['system.config'] &&
75
- this.dataset['system.config'].common &&
76
- this.dataset['system.config'].common.defaultNewAcl
77
- ) {
78
- this.defaultNewAcl = deepClone(this.dataset['system.config'].common.defaultNewAcl);
70
+ const configObj = this.dataset['system.config'];
71
+ if (configObj && configObj.common && configObj.common.defaultNewAcl) {
72
+ this.defaultNewAcl = deepClone(configObj.common.defaultNewAcl);
79
73
  }
80
74
  }
81
75
 
@@ -835,6 +829,15 @@ class ObjectsInMemoryFileDB extends InMemoryFileDB {
835
829
  return keys.map(id => this.dataset[id]);
836
830
  }
837
831
 
832
+ _ensureMetaDict() {
833
+ let meta = this.dataset['**META**'];
834
+ if (!meta) {
835
+ meta = {};
836
+ this.dataset['**META**'] = meta;
837
+ }
838
+ return meta;
839
+ }
840
+
838
841
  /**
839
842
  * Get value of given meta id
840
843
  *
@@ -842,11 +845,8 @@ class ObjectsInMemoryFileDB extends InMemoryFileDB {
842
845
  * @returns {*}
843
846
  */
844
847
  getMeta(id) {
845
- if (!this.dataset['**META**']) {
846
- this.dataset['**META**'] = {};
847
- }
848
-
849
- return this.dataset['**META**'][id];
848
+ const meta = this._ensureMetaDict();
849
+ return meta[id];
850
850
  }
851
851
 
852
852
  /**
@@ -856,11 +856,10 @@ class ObjectsInMemoryFileDB extends InMemoryFileDB {
856
856
  * @param {string} value
857
857
  */
858
858
  setMeta(id, value) {
859
- if (!this.dataset['**META**']) {
860
- this.dataset['**META**'] = {};
861
- }
862
-
863
- this.dataset['**META**'][id] = value;
859
+ const meta = this._ensureMetaDict();
860
+ meta[id] = value;
861
+ // Make sure the object gets re-written, especially when using an external DB
862
+ this.dataset['**META**'] = meta;
864
863
 
865
864
  setImmediate(() => {
866
865
  // publish event in states
@@ -878,7 +877,7 @@ class ObjectsInMemoryFileDB extends InMemoryFileDB {
878
877
  this.dataset[id] = obj;
879
878
 
880
879
  // object updated -> if type changed to meta -> cache
881
- if (this.dataset[id].type === 'meta' && this.existingMetaObjects[id] === false) {
880
+ if (obj.type === 'meta' && this.existingMetaObjects[id] === false) {
882
881
  this.existingMetaObjects[id] = true;
883
882
  }
884
883
 
@@ -889,11 +888,12 @@ class ObjectsInMemoryFileDB extends InMemoryFileDB {
889
888
 
890
889
  // needed by server
891
890
  _delObject(id) {
892
- if (!this.dataset[id]) {
891
+ const obj = this.dataset[id];
892
+ if (!obj) {
893
893
  throw new Error(utils.ERRORS.ERROR_NOT_FOUND);
894
894
  }
895
895
 
896
- if (this.dataset[id].common && this.dataset[id].common.dontDelete) {
896
+ if (obj.common && obj.common.dontDelete) {
897
897
  throw new Error('Object is marked as non deletable');
898
898
  }
899
899
 
@@ -933,9 +933,10 @@ class ObjectsInMemoryFileDB extends InMemoryFileDB {
933
933
  continue;
934
934
  }
935
935
  }
936
- if (this.dataset[id]) {
936
+ const obj = this.dataset[id];
937
+ if (obj) {
937
938
  try {
938
- f(this.dataset[id]);
939
+ f(obj);
939
940
  } catch (e) {
940
941
  this.log.warn(`${this.namespace} Cannot execute map: ${e.message}`);
941
942
  }
@@ -961,15 +962,16 @@ class ObjectsInMemoryFileDB extends InMemoryFileDB {
961
962
 
962
963
  // needed by server
963
964
  _getObjectView(design, search, params) {
964
- if (!this.dataset['_design/' + design]) {
965
+ const designObj = this.dataset[`_design/${design}`];
966
+ if (!designObj) {
965
967
  this.log.error(`${this.namespace} Cannot find view "${design}"`);
966
968
  throw new Error(`Cannot find view "${design}"`);
967
969
  }
968
- if (!this.dataset[`_design/${design}`].views && this.dataset['_design/' + design].views[search]) {
970
+ if (!(designObj.views && designObj.views[search])) {
969
971
  this.log.warn(`${this.namespace} Cannot find search "${search}" in "${design}"`);
970
972
  throw new Error(`Cannot find search "${search}" in "${design}"`);
971
973
  }
972
- return this._applyView(this.dataset[`_design/${design}`].views[search], params);
974
+ return this._applyView(designObj.views[search], params);
973
975
  }
974
976
 
975
977
  // Destructor of the class. Called by shutting down.
@@ -349,7 +349,7 @@ class ObjectsInMemoryServer extends ObjectsInMemoryFileDB {
349
349
  )
350
350
  );
351
351
  }
352
- const res = objs.rows.map(obj => JSON.stringify(this.dataset[obj.value._id || obj.id]));
352
+ const res = objs.rows.map(obj => JSON.stringify(obj.value));
353
353
  handler.sendArray(responseId, res);
354
354
  }
355
355
  } else if (this.knownScripts[data[0]].func && data.length > 4) {
@@ -362,7 +362,7 @@ class ObjectsInMemoryServer extends ObjectsInMemoryFileDB {
362
362
  endkey: data[4],
363
363
  include_docs: true
364
364
  });
365
- const res = objs.rows.map(obj => JSON.stringify(this.dataset[obj.value._id || obj.id]));
365
+ const res = objs.rows.map(obj => JSON.stringify(obj.value));
366
366
 
367
367
  return void handler.sendArray(responseId, res);
368
368
  } else if (this.knownScripts[data[0]].redlock) {
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@iobroker/db-objects-file",
3
- "version": "4.0.0-alpha.49-20220121-e7aa4308",
3
+ "version": "4.0.0-alpha.52-20220126-dad3d5b3",
4
4
  "engines": {
5
5
  "node": ">=12.0.0"
6
6
  },
7
7
  "dependencies": {
8
- "@iobroker/db-base": "4.0.0-alpha.49-20220121-e7aa4308",
9
- "@iobroker/db-objects-redis": "4.0.0-alpha.49-20220121-e7aa4308",
8
+ "@iobroker/db-base": "4.0.0-alpha.52-20220126-dad3d5b3",
9
+ "@iobroker/db-objects-redis": "4.0.0-alpha.52-20220126-dad3d5b3",
10
10
  "deep-clone": "^3.0.3",
11
11
  "fs-extra": "^10.0.0"
12
12
  },
@@ -35,5 +35,5 @@
35
35
  "lib/",
36
36
  "index.js"
37
37
  ],
38
- "gitHead": "f42f117b74d3c4bfac0bc872c087d382ca897b7c"
38
+ "gitHead": "42c56c6be45fb2f407f75cb8ecbc22800292ac98"
39
39
  }