@iobroker/db-objects-redis 7.0.2 → 7.0.3

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.
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  return to;
19
19
  };
20
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["/**\n * Get the default port for the database\n *\n * @param host string of host(s)\n */\nexport function getDefaultPort(host: string): number {\n return host.includes(',') ? 26379 : 6379;\n}\nexport const Server = null;\nexport { ObjectsInRedisClient as Client } from '@/lib/objects/objectsInRedisClient.js';\nexport { interview } from '@/lib/objects/interview.js';\nexport * as objectsUtils from '@/lib/objects/objectsUtils.js';\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;AASA,kCAA+C;AAC/C,uBAA0B;AAC1B,mBAA8B;AANxB,SAAU,eAAe,MAAY;AACvC,SAAO,KAAK,SAAS,GAAG,IAAI,QAAQ;AACxC;AACO,MAAM,SAAS;",
4
+ "sourcesContent": ["/// <reference types=\"@iobroker/types-dev\" />\n/**\n * Get the default port for the database\n *\n * @param host string of host(s)\n */\nexport function getDefaultPort(host: string): number {\n return host.includes(',') ? 26379 : 6379;\n}\nexport const Server = null;\nexport { ObjectsInRedisClient as Client } from '@/lib/objects/objectsInRedisClient.js';\nexport { interview } from '@/lib/objects/interview.js';\nexport * as objectsUtils from '@/lib/objects/objectsUtils.js';\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;AAUA,kCAA+C;AAC/C,uBAA0B;AAC1B,mBAA8B;AANxB,SAAU,eAAe,MAAY;AACvC,SAAO,KAAK,SAAS,GAAG,IAAI,QAAQ;AACxC;AACO,MAAM,SAAS;",
6
6
  "names": []
7
7
  }
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/objects/constants.ts"],
4
4
  "sourcesContent": ["export enum ERRORS {\n ERROR_PERMISSION = 'permissionError',\n ERROR_NOT_FOUND = 'Not exists',\n ERROR_DB_CLOSED = 'DB closed',\n}\n\nexport const SYSTEM_ADMIN_USER = 'system.user.admin';\nexport const SYSTEM_ADMIN_GROUP = 'system.group.administrator';\n\nexport const ACCESS_EVERY_EXEC = 0x1;\nexport const ACCESS_EVERY_WRITE = 0x2;\nexport const ACCESS_EVERY_READ = 0x4;\nexport const ACCESS_EVERY_RW = ACCESS_EVERY_WRITE | ACCESS_EVERY_READ;\nexport const ACCESS_EVERY_ALL = ACCESS_EVERY_WRITE | ACCESS_EVERY_READ | ACCESS_EVERY_EXEC;\n\nexport const ACCESS_GROUP_EXEC = 0x10;\nexport const ACCESS_GROUP_WRITE = 0x20;\nexport const ACCESS_GROUP_READ = 0x40;\nexport const ACCESS_GROUP_RW = ACCESS_GROUP_WRITE | ACCESS_GROUP_READ;\nexport const ACCESS_GROUP_ALL = ACCESS_GROUP_WRITE | ACCESS_GROUP_READ | ACCESS_GROUP_EXEC;\n\nexport const ACCESS_USER_EXEC = 0x100;\nexport const ACCESS_USER_WRITE = 0x200;\nexport const ACCESS_USER_READ = 0x400;\nexport const ACCESS_USER_RW = ACCESS_USER_WRITE | ACCESS_USER_READ;\nexport const ACCESS_USER_ALL = ACCESS_USER_WRITE | ACCESS_USER_READ | ACCESS_USER_EXEC;\n\nexport const ACCESS_WRITE = 0x2;\nexport const ACCESS_READ = 0x4;\nexport const ACCESS_LIST = 'list';\nexport const ACCESS_DELETE = 'delete';\nexport const ACCESS_CREATE = 'create';\n\nexport type GenericAccessFlags =\n | typeof ACCESS_WRITE\n | typeof ACCESS_READ\n | typeof ACCESS_LIST\n | typeof ACCESS_DELETE\n | typeof ACCESS_CREATE;\n\nexport const REG_CHECK_ID = /[*?[\\]]|\\$%\\$/;\n\nexport const USER_STARTS_WITH = 'system.user.';\nexport const GROUP_STARTS_WITH = 'system.group.';\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAY;CAAZ,SAAYA,SAAM;AACd,EAAAA,QAAA,sBAAA;AACA,EAAAA,QAAA,qBAAA;AACA,EAAAA,QAAA,qBAAA;AACJ,GAJY,WAAA,SAAM,CAAA,EAAA;AAMX,MAAM,oBAAoB;AAC1B,MAAM,qBAAqB;AAE3B,MAAM,oBAAoB;AAC1B,MAAM,qBAAqB;AAC3B,MAAM,oBAAoB;AAC1B,MAAM,kBAAkB,qBAAqB;AAC7C,MAAM,mBAAmB,qBAAqB,oBAAoB;AAElE,MAAM,oBAAoB;AAC1B,MAAM,qBAAqB;AAC3B,MAAM,oBAAoB;AAC1B,MAAM,kBAAkB,qBAAqB;AAC7C,MAAM,mBAAmB,qBAAqB,oBAAoB;AAElE,MAAM,mBAAmB;AACzB,MAAM,oBAAoB;AAC1B,MAAM,mBAAmB;AACzB,MAAM,iBAAiB,oBAAoB;AAC3C,MAAM,kBAAkB,oBAAoB,mBAAmB;AAE/D,MAAM,eAAe;AACrB,MAAM,cAAc;AACpB,MAAM,cAAc;AACpB,MAAM,gBAAgB;AACtB,MAAM,gBAAgB;AAStB,MAAM,eAAe;AAErB,MAAM,mBAAmB;AACzB,MAAM,oBAAoB;",
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAY;CAAZ,SAAYA,SAAM;AACd,EAAAA,QAAA,kBAAA,IAAA;AACA,EAAAA,QAAA,iBAAA,IAAA;AACA,EAAAA,QAAA,iBAAA,IAAA;AACJ,GAJY,WAAA,SAAM,CAAA,EAAA;AAMX,MAAM,oBAAoB;AAC1B,MAAM,qBAAqB;AAE3B,MAAM,oBAAoB;AAC1B,MAAM,qBAAqB;AAC3B,MAAM,oBAAoB;AAC1B,MAAM,kBAAkB,qBAAqB;AAC7C,MAAM,mBAAmB,qBAAqB,oBAAoB;AAElE,MAAM,oBAAoB;AAC1B,MAAM,qBAAqB;AAC3B,MAAM,oBAAoB;AAC1B,MAAM,kBAAkB,qBAAqB;AAC7C,MAAM,mBAAmB,qBAAqB,oBAAoB;AAElE,MAAM,mBAAmB;AACzB,MAAM,oBAAoB;AAC1B,MAAM,mBAAmB;AACzB,MAAM,iBAAiB,oBAAoB;AAC3C,MAAM,kBAAkB,oBAAoB,mBAAmB;AAE/D,MAAM,eAAe;AACrB,MAAM,cAAc;AACpB,MAAM,cAAc;AACpB,MAAM,gBAAgB;AACtB,MAAM,gBAAgB;AAStB,MAAM,eAAe;AAErB,MAAM,mBAAmB;AACzB,MAAM,oBAAoB;",
6
6
  "names": ["ERRORS"]
7
7
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="@iobroker/types-dev" />
2
1
  /**
3
2
  * Custom interview during setup
4
3
  *
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/objects/interview.ts"],
4
4
  "sourcesContent": ["import { defaultRedisInterview } from '@iobroker/js-controller-common-db';\n\n/**\n * Custom interview during setup\n *\n * @param config the prefilled database config\n * @returns the database options obtained by the answered questionnaire\n */\nexport function interview(config: ioBroker.ObjectsDatabaseOptions): Promise<ioBroker.ObjectsDatabaseOptions> {\n return defaultRedisInterview<ioBroker.ObjectsDatabaseOptions>({ config, type: 'objects' });\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;qCAAsC;AAQhC,SAAU,UAAU,QAAuC;AAC7D,aAAO,sDAAuD,EAAE,QAAQ,MAAM,UAAS,CAAE;AAC7F;",
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,qCAAsC;AAQhC,SAAU,UAAU,QAAuC;AAC7D,aAAO,sDAAuD,EAAE,QAAQ,MAAM,UAAS,CAAE;AAC7F;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="@iobroker/types-dev" />
2
1
  import type { ACLObject, CheckFileRightsCallback, GetUserGroupPromiseReturn } from '../../lib/objects/objectsUtils.js';
3
2
  import type { InternalLogger } from '@iobroker/js-controller-common-db/tools';
4
3
  import type { ConnectionOptions, DbStatus } from '@iobroker/db-base/inMemFileDB';
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  return to;
19
19
  };
20
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
@@ -27,6 +31,7 @@ __export(objectsInRedisClient_exports, {
27
31
  ObjectsInRedisClient: () => ObjectsInRedisClient
28
32
  });
29
33
  module.exports = __toCommonJS(objectsInRedisClient_exports);
34
+ var __import_meta_url = typeof document === "undefined" ? new (require("url".replace("", ""))).URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
30
35
  var import_node = __toESM(require("node.extend"), 1);
31
36
  var import_ioredis = __toESM(require("ioredis"), 1);
32
37
  var import_db_base = require("@iobroker/db-base");
@@ -39,8 +44,7 @@ var utils = __toESM(require("../../lib/objects/objectsUtils.js"), 1);
39
44
  var import_semver = __toESM(require("semver"), 1);
40
45
  var CONSTS = __toESM(require("../../lib/objects/constants.js"), 1);
41
46
  var url = __toESM(require("node:url"), 1);
42
- const import_meta = {};
43
- const thisDir = url.fileURLToPath(new URL(".", import_meta.url || `file://${__filename}`));
47
+ const thisDir = url.fileURLToPath(new URL(".", __import_meta_url || `file://${__filename}`));
44
48
  const ERRORS = CONSTS.ERRORS;
45
49
  class ObjectsInRedisClient {
46
50
  client;
@@ -95,6 +99,9 @@ class ObjectsInRedisClient {
95
99
  this.connectDb();
96
100
  }
97
101
  }
102
+ /**
103
+ * Checks if we are allowed to start and sets the protocol version accordingly
104
+ */
98
105
  async _determineProtocolVersion() {
99
106
  if (!this.client) {
100
107
  throw new Error(ERRORS.ERROR_DB_CLOSED);
@@ -158,6 +165,7 @@ class ObjectsInRedisClient {
158
165
  const defaultPort = Array.isArray(configuredPort) ? null : configuredPort;
159
166
  this.settings.connection.options.sentinels = this.settings.connection.host.map((redisNode, idx) => ({
160
167
  host: redisNode,
168
+ // @ts-expect-error ts does not get that if defPort is null we have an array
161
169
  port: defaultPort === null ? configuredPort[idx] : defaultPort
162
170
  }));
163
171
  this.settings.connection.options.name = this.settings.connection.sentinelName ? this.settings.connection.sentinelName : "mymaster";
@@ -486,6 +494,12 @@ class ObjectsInRedisClient {
486
494
  getStatus() {
487
495
  return { type: "redis", server: false };
488
496
  }
497
+ /**
498
+ * Checks if given ID is a meta-object, else throws error
499
+ *
500
+ * @param id to check
501
+ * @throws Error if id is invalid
502
+ */
489
503
  async validateMetaObject(id) {
490
504
  if (this.existingMetaObjects[id] === void 0) {
491
505
  const obj = await this.getObjectAsync(id);
@@ -502,6 +516,13 @@ class ObjectsInRedisClient {
502
516
  normalizeFilename(name) {
503
517
  return name ? name.replace(/[/\\]+/g, "/") : name;
504
518
  }
519
+ // -------------- FILE FUNCTIONS -------------------------------------------
520
+ /**
521
+ * Sets a buffer to the Redis DB
522
+ *
523
+ * @param id id of the file
524
+ * @param data content, if string is passed it will be converted to a Buffer
525
+ */
505
526
  async _setBinaryState(id, data) {
506
527
  if (!this.client) {
507
528
  throw new Error(ERRORS.ERROR_DB_CLOSED);
@@ -512,12 +533,22 @@ class ObjectsInRedisClient {
512
533
  await this.client.set(id, data);
513
534
  await this.client.publish(id, data.byteLength.toString(10));
514
535
  }
536
+ /**
537
+ * get buffer of given id from redis
538
+ *
539
+ * @param id - id of the data with namespace prefix
540
+ */
515
541
  _getBinaryState(id) {
516
542
  if (!this.client) {
517
543
  throw new Error(ERRORS.ERROR_DB_CLOSED);
518
544
  }
519
545
  return this.client.getBuffer(id);
520
546
  }
547
+ /**
548
+ * deletes binary state of given id from redis db
549
+ *
550
+ * @param id - id to delete, with namespace prefix
551
+ */
521
552
  async _delBinaryState(id) {
522
553
  if (!this.client) {
523
554
  throw new Error(ERRORS.ERROR_DB_CLOSED);
@@ -752,6 +783,12 @@ class ObjectsInRedisClient {
752
783
  }
753
784
  });
754
785
  }
786
+ /**
787
+ * Check if given object exists
788
+ *
789
+ * @param id id of the object
790
+ * @param options optional user context
791
+ */
755
792
  async objectExists(id, options2) {
756
793
  if (!this.client) {
757
794
  throw new Error(ERRORS.ERROR_DB_CLOSED);
@@ -776,6 +813,13 @@ class ObjectsInRedisClient {
776
813
  return Promise.reject(new Error(`Cannot check object existence of "${id}": ${e.message}`));
777
814
  }
778
815
  }
816
+ /**
817
+ * Check if given file exists
818
+ *
819
+ * @param id id of the namespace
820
+ * @param name name of the file
821
+ * @param options optional user context
822
+ */
779
823
  async fileExists(id, name, options2) {
780
824
  if (typeof name !== "string") {
781
825
  name = "";
@@ -1295,6 +1339,7 @@ class ObjectsInRedisClient {
1295
1339
  rmAsync(id, name, options2) {
1296
1340
  return new Promise((resolve, reject) => this.rm(id, name, options2, (err, files) => err ? reject(err) : resolve(files)));
1297
1341
  }
1342
+ // simulate. redis has no dirs
1298
1343
  mkdir(id, dirName, options2, callback) {
1299
1344
  if (typeof options2 === "function") {
1300
1345
  callback = options2;
@@ -1485,6 +1530,13 @@ class ObjectsInRedisClient {
1485
1530
  chownFileAsync(id, name, options2) {
1486
1531
  return new Promise((resolve, reject) => this.chownFile(id, name, options2, (err, processed) => err ? reject(err) : resolve(processed)));
1487
1532
  }
1533
+ /**
1534
+ *
1535
+ * @param keys Key names to handle
1536
+ * @param metas Objects for the keys to handle
1537
+ * @param options options
1538
+ * @param callback callback function
1539
+ */
1488
1540
  async _chmodFileHelper(keys2, metas, options2, callback) {
1489
1541
  if (!keys2 || !keys2.length) {
1490
1542
  return import_db_base.tools.maybeCallback(callback);
@@ -1908,6 +1960,7 @@ class ObjectsInRedisClient {
1908
1960
  owner: this.defaultNewAcl && this.defaultNewAcl.owner || CONSTS.SYSTEM_ADMIN_USER,
1909
1961
  ownerGroup: this.defaultNewAcl && this.defaultNewAcl.ownerGroup || CONSTS.SYSTEM_ADMIN_GROUP,
1910
1962
  object: this.defaultNewAcl && this.defaultNewAcl.object || CONSTS.ACCESS_USER_RW | CONSTS.ACCESS_GROUP_READ | CONSTS.ACCESS_EVERY_READ
1963
+ // '0644'
1911
1964
  };
1912
1965
  if (obj.type === "state") {
1913
1966
  obj.acl.state = this.defaultNewAcl && this.defaultNewAcl.state || CONSTS.ACCESS_USER_RW | CONSTS.ACCESS_GROUP_READ | CONSTS.ACCESS_EVERY_READ;
@@ -2005,6 +2058,7 @@ class ObjectsInRedisClient {
2005
2058
  owner: this.defaultNewAcl && this.defaultNewAcl.owner || CONSTS.SYSTEM_ADMIN_USER,
2006
2059
  ownerGroup: this.defaultNewAcl && this.defaultNewAcl.ownerGroup || CONSTS.SYSTEM_ADMIN_GROUP,
2007
2060
  object: this.defaultNewAcl && this.defaultNewAcl.object || CONSTS.ACCESS_USER_RW | CONSTS.ACCESS_GROUP_READ | CONSTS.ACCESS_EVERY_READ
2061
+ // '0644'
2008
2062
  };
2009
2063
  if (obj.type === "state") {
2010
2064
  obj.acl.state = this.defaultNewAcl && this.defaultNewAcl.state || CONSTS.ACCESS_USER_RW | CONSTS.ACCESS_GROUP_READ | CONSTS.ACCESS_EVERY_READ;
@@ -2109,6 +2163,12 @@ class ObjectsInRedisClient {
2109
2163
  });
2110
2164
  }
2111
2165
  }
2166
+ /**
2167
+ *
2168
+ * @param id
2169
+ * @param options
2170
+ * @deprecated use `getObject` without callback instead
2171
+ */
2112
2172
  getObjectAsync(id, options2) {
2113
2173
  return new Promise((resolve, reject) => this.getObject(id, options2, (err, obj) => err ? reject(err) : resolve(obj)));
2114
2174
  }
@@ -2260,7 +2320,10 @@ class ObjectsInRedisClient {
2260
2320
  options2 = null;
2261
2321
  }
2262
2322
  if (!callback) {
2263
- return new Promise((resolve, reject) => this.getObjects(keys2, options2, (err, objs2) => err ? reject(err) : resolve(objs2), dontModify));
2323
+ return new Promise((resolve, reject) => (
2324
+ // @ts-expect-error need to clarify, that objs is not undefined if no error is provided
2325
+ this.getObjects(keys2, options2, (err, objs2) => err ? reject(err) : resolve(objs2), dontModify)
2326
+ ));
2264
2327
  }
2265
2328
  if (options2?.acl) {
2266
2329
  options2.acl = null;
@@ -2383,7 +2446,11 @@ class ObjectsInRedisClient {
2383
2446
  let objCommon = obj.common;
2384
2447
  if (objCommon && objCommon[commonSetting] === null) {
2385
2448
  delete objCommon[commonSetting];
2386
- } else if (oldObj.common[commonSetting] !== void 0 && (!objCommon || objCommon[commonSetting] === void 0)) {
2449
+ } else if (
2450
+ // if old setting present and new setting is absent
2451
+ // @ts-expect-error https://github.com/ioBroker/adapter-core/issues/455
2452
+ oldObj.common[commonSetting] !== void 0 && (!objCommon || objCommon[commonSetting] === void 0)
2453
+ ) {
2387
2454
  objCommon = objCommon || {};
2388
2455
  objCommon[commonSetting] = oldObj.common[commonSetting];
2389
2456
  }
@@ -2454,6 +2521,16 @@ class ObjectsInRedisClient {
2454
2521
  await this.client.publish(this.objNamespace + id, message);
2455
2522
  return { id };
2456
2523
  }
2524
+ /**
2525
+ * set anew or update object
2526
+ *
2527
+ * This function writes the object into DB
2528
+ *
2529
+ * @param id ID of the object
2530
+ * @param obj
2531
+ * @param options options for access control are optional
2532
+ * @param callback return function
2533
+ */
2457
2534
  setObject(id, obj, options2, callback) {
2458
2535
  if (typeof options2 === "function") {
2459
2536
  callback = options2;
@@ -2477,8 +2554,18 @@ class ObjectsInRedisClient {
2477
2554
  }
2478
2555
  });
2479
2556
  }
2557
+ /**
2558
+ *
2559
+ * @param id
2560
+ * @param obj
2561
+ * @param options
2562
+ * @deprecated use `setObject` without callback instead
2563
+ */
2480
2564
  setObjectAsync(id, obj, options2) {
2481
- return new Promise((resolve, reject) => this.setObject(id, obj, options2, (err, res) => err ? reject(err) : resolve(res)));
2565
+ return new Promise((resolve, reject) => (
2566
+ // @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
2567
+ this.setObject(id, obj, options2, (err, res) => err ? reject(err) : resolve(res))
2568
+ ));
2482
2569
  }
2483
2570
  async _delObject(id, options2) {
2484
2571
  if (!id || typeof id !== "string" || utils.REG_CHECK_ID.test(id)) {
@@ -2554,6 +2641,9 @@ class ObjectsInRedisClient {
2554
2641
  delObjectAsync(id, options2) {
2555
2642
  return this.delObject(id, options2);
2556
2643
  }
2644
+ /**
2645
+ * Function to checks if comparisons will work according to the configured Locale
2646
+ */
2557
2647
  async isSystemLocaleSupported() {
2558
2648
  if (!this.client) {
2559
2649
  throw new Error(ERRORS.ERROR_DB_CLOSED);
@@ -2566,6 +2656,7 @@ class ObjectsInRedisClient {
2566
2656
  return true;
2567
2657
  }
2568
2658
  }
2659
+ // this function is very ineffective. Because reads all objects and then process them
2569
2660
  async _applyViewFunc(func, params, options = {}) {
2570
2661
  if (!this.client) {
2571
2662
  throw new Error(ERRORS.ERROR_DB_CLOSED);
@@ -2676,7 +2767,10 @@ class ObjectsInRedisClient {
2676
2767
  }
2677
2768
  result.rows = filterEntries(result.rows, filterRequired);
2678
2769
  return result;
2679
- } else if (wildCardLastPos && func?.map && this.scripts.script && func.map.includes("doc.common.engineType")) {
2770
+ } else if (
2771
+ // filter by script
2772
+ wildCardLastPos && func?.map && this.scripts.script && func.map.includes("doc.common.engineType")
2773
+ ) {
2680
2774
  let cursor = "0";
2681
2775
  let filterRequired = true;
2682
2776
  do {
@@ -2722,7 +2816,10 @@ class ObjectsInRedisClient {
2722
2816
  } while (cursor !== "0");
2723
2817
  result.rows = filterEntries(result.rows, filterRequired);
2724
2818
  return result;
2725
- } else if (wildCardLastPos && func?.map && this.scripts.programs && func.map.includes("doc.native.TypeName === 'PROGRAM'")) {
2819
+ } else if (
2820
+ // filter by hm-rega programs
2821
+ wildCardLastPos && func?.map && this.scripts.programs && func.map.includes("doc.native.TypeName === 'PROGRAM'")
2822
+ ) {
2726
2823
  let cursor = "0";
2727
2824
  let filterRequired = true;
2728
2825
  do {
@@ -2766,7 +2863,10 @@ class ObjectsInRedisClient {
2766
2863
  } while (cursor !== "0");
2767
2864
  result.rows = filterEntries(result.rows, filterRequired);
2768
2865
  return result;
2769
- } else if (wildCardLastPos && func?.map && this.scripts.variables && func.map.includes("doc.native.TypeName === 'ALARMDP'")) {
2866
+ } else if (
2867
+ // filter by hm-rega variables
2868
+ wildCardLastPos && func?.map && this.scripts.variables && func.map.includes("doc.native.TypeName === 'ALARMDP'")
2869
+ ) {
2770
2870
  let cursor = "0";
2771
2871
  let filterRequired = true;
2772
2872
  do {
@@ -2810,7 +2910,10 @@ class ObjectsInRedisClient {
2810
2910
  } while (cursor !== "0");
2811
2911
  result.rows = filterEntries(result.rows, filterRequired);
2812
2912
  return result;
2813
- } else if (wildCardLastPos && func?.map && this.scripts.custom && func.map.includes("doc.common.custom")) {
2913
+ } else if (
2914
+ // filter by custom, redis also returns if common.custom is not present
2915
+ wildCardLastPos && func?.map && this.scripts.custom && func.map.includes("doc.common.custom")
2916
+ ) {
2814
2917
  let cursor = "0";
2815
2918
  let filterRequired = true;
2816
2919
  do {
@@ -3080,6 +3183,7 @@ class ObjectsInRedisClient {
3080
3183
  getObjectListAsync(params2, options2) {
3081
3184
  return this.getObjectList(params2, options2);
3082
3185
  }
3186
+ // could be optimized, to read object only once. Now it will read 3 times
3083
3187
  async _extendObject(id, obj, options2, callback) {
3084
3188
  if (!id || typeof id !== "string" || utils.REG_CHECK_ID.test(id)) {
3085
3189
  return import_db_base.tools.maybeCallbackWithError(callback, `Invalid ID: ${id}`);
@@ -3212,6 +3316,14 @@ class ObjectsInRedisClient {
3212
3316
  extendObjectAsync(id, obj, options2) {
3213
3317
  return new Promise((resolve, reject) => this.extendObject(id, obj, options2 || null, (err, res) => err ? reject(err) : resolve(res)));
3214
3318
  }
3319
+ /**
3320
+ * Returns the object id if found
3321
+ *
3322
+ * @param idOrName
3323
+ * @param type
3324
+ * @param options
3325
+ * @param callback
3326
+ */
3215
3327
  _findObject(idOrName, type, options2, callback) {
3216
3328
  this._getObject(idOrName, options2, (err, obj) => {
3217
3329
  if (obj && utils.checkObject(obj, options2, CONSTS.ACCESS_READ) && (!type || obj.common && obj.common.type === type)) {
@@ -3273,6 +3385,7 @@ class ObjectsInRedisClient {
3273
3385
  });
3274
3386
  }
3275
3387
  }
3388
+ // can be called only from js-controller
3276
3389
  addPreserveSettings(settings) {
3277
3390
  if (!Array.isArray(settings)) {
3278
3391
  settings = [settings];
@@ -3328,6 +3441,7 @@ class ObjectsInRedisClient {
3328
3441
  destroyDBAsync(options2) {
3329
3442
  return new Promise((resolve, reject) => this.destroyDB(options2, (err) => err ? reject(err) : resolve()));
3330
3443
  }
3444
+ // Destructor of the class. Called by shutting down.
3331
3445
  async destroy() {
3332
3446
  this.stop = true;
3333
3447
  if (this.client) {
@@ -3407,6 +3521,12 @@ class ObjectsInRedisClient {
3407
3521
  this.scripts = {};
3408
3522
  scripts.forEach((e) => this.scripts[e.name] = e.hash);
3409
3523
  }
3524
+ /**
3525
+ * Get all keys matching a pattern using redis SCAN command, duplicates are filtered out
3526
+ *
3527
+ * @param pattern - pattern to match, e. g. io.hm-rpc.0*
3528
+ * @param count - count argument used by redis SCAN, default is 250
3529
+ */
3410
3530
  _getKeysViaScan(pattern, count = 250) {
3411
3531
  return new Promise((resolve, reject) => {
3412
3532
  if (!this.client) {
@@ -3426,6 +3546,11 @@ class ObjectsInRedisClient {
3426
3546
  });
3427
3547
  });
3428
3548
  }
3549
+ /**
3550
+ * Checks if a given set exists
3551
+ *
3552
+ * @param id - id of the set
3553
+ */
3429
3554
  async setExists(id) {
3430
3555
  if (!this.client) {
3431
3556
  throw new Error(ERRORS.ERROR_DB_CLOSED);
@@ -3433,6 +3558,11 @@ class ObjectsInRedisClient {
3433
3558
  const exists = await this.client.exists(this.setNamespace + id);
3434
3559
  return !!exists;
3435
3560
  }
3561
+ /**
3562
+ * Migrate all objects to sets
3563
+ *
3564
+ * @returns number of migrated sets
3565
+ */
3436
3566
  async migrateToSets() {
3437
3567
  if (!this.useSets) {
3438
3568
  return 0;
@@ -3461,12 +3591,22 @@ class ObjectsInRedisClient {
3461
3591
  }
3462
3592
  return noMigrated;
3463
3593
  }
3594
+ /**
3595
+ * Returns the protocol version from DB
3596
+ */
3464
3597
  getProtocolVersion() {
3465
3598
  if (!this.client) {
3466
3599
  throw new Error(ERRORS.ERROR_DB_CLOSED);
3467
3600
  }
3468
3601
  return this.client.get(`${this.metaNamespace}objects.protocolVersion`);
3469
3602
  }
3603
+ /**
3604
+ * Extend the primary host lock time
3605
+ * Value will expire after ms milliseconds
3606
+ *
3607
+ * @param ms - ms until value expires
3608
+ * @returns 1 if extended else 0
3609
+ */
3470
3610
  extendPrimaryHostLock(ms) {
3471
3611
  if (!this.client) {
3472
3612
  throw new Error(ERRORS.ERROR_DB_CLOSED);
@@ -3482,6 +3622,13 @@ class ObjectsInRedisClient {
3482
3622
  ms
3483
3623
  ]);
3484
3624
  }
3625
+ /**
3626
+ * Sets current host as primary if no primary host active
3627
+ * Value will expire after ms milliseconds
3628
+ *
3629
+ * @param ms - ms until value expires
3630
+ * @returns 1 if lock acquired else 0
3631
+ */
3485
3632
  setPrimaryHost(ms) {
3486
3633
  if (!this.client) {
3487
3634
  throw new Error(ERRORS.ERROR_DB_CLOSED);
@@ -3497,6 +3644,9 @@ class ObjectsInRedisClient {
3497
3644
  ms
3498
3645
  ]);
3499
3646
  }
3647
+ /**
3648
+ * Get name of the primary host
3649
+ */
3500
3650
  getPrimaryHost() {
3501
3651
  if (!this.client) {
3502
3652
  throw new Error(ERRORS.ERROR_DB_CLOSED);
@@ -3506,6 +3656,9 @@ class ObjectsInRedisClient {
3506
3656
  }
3507
3657
  return this.client.get(`${this.metaNamespace}objects.primaryHost`);
3508
3658
  }
3659
+ /**
3660
+ * Ensure we are no longer the primary host
3661
+ */
3509
3662
  releasePrimaryHost() {
3510
3663
  if (!this.client) {
3511
3664
  throw new Error(ERRORS.ERROR_DB_CLOSED);
@@ -3522,6 +3675,11 @@ class ObjectsInRedisClient {
3522
3675
  `${this.metaNamespace}objects.primaryHost`
3523
3676
  ]);
3524
3677
  }
3678
+ /**
3679
+ * Sets the protocol version to the DB
3680
+ *
3681
+ * @param version - protocol version
3682
+ */
3525
3683
  async setProtocolVersion(version) {
3526
3684
  if (!this.client) {
3527
3685
  throw new Error(ERRORS.ERROR_DB_CLOSED);
@@ -3534,12 +3692,18 @@ class ObjectsInRedisClient {
3534
3692
  throw new Error("Cannot set an unsupported protocol version on the current host");
3535
3693
  }
3536
3694
  }
3695
+ /**
3696
+ * Subscribe to expired events to get expiration of primary host
3697
+ */
3537
3698
  async subscribePrimaryHost() {
3538
3699
  if (this.subSystem) {
3539
3700
  await this.subSystem.subscribe(`__keyevent@${this.settings.connection.options.db}__:expired`);
3540
3701
  await this.subSystem.subscribe(`__keyevent@${this.settings.connection.options.db}__:evicted`);
3541
3702
  }
3542
3703
  }
3704
+ /**
3705
+ * Activates the usage of sets
3706
+ */
3543
3707
  async activateSets() {
3544
3708
  if (!this.client) {
3545
3709
  throw new Error(ERRORS.ERROR_DB_CLOSED);
@@ -3547,6 +3711,9 @@ class ObjectsInRedisClient {
3547
3711
  await this.client.set(`${this.metaNamespace}objects.features.useSets`, "1");
3548
3712
  this.useSets = true;
3549
3713
  }
3714
+ /**
3715
+ * Deactivates the usage of sets
3716
+ */
3550
3717
  async deactivateSets() {
3551
3718
  if (!this.client) {
3552
3719
  throw new Error(ERRORS.ERROR_DB_CLOSED);
@@ -3554,6 +3721,11 @@ class ObjectsInRedisClient {
3554
3721
  await this.client.set(`${this.metaNamespace}objects.features.useSets`, "0");
3555
3722
  this.useSets = false;
3556
3723
  }
3724
+ /**
3725
+ * Get value from meta namespace
3726
+ *
3727
+ * @param id redis key
3728
+ */
3557
3729
  getMeta(id) {
3558
3730
  if (!this.client) {
3559
3731
  throw new Error(ERRORS.ERROR_DB_CLOSED);