@iobroker/db-objects-redis 7.2.2 → 7.2.3-alpha.1-20260621-61726ea22

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.
@@ -21,6 +21,9 @@ import * as url from 'node:url';
21
21
  // eslint-disable-next-line unicorn/prefer-module
22
22
  const thisDir = url.fileURLToPath(new URL('.', import.meta.url || `file://${__filename}`));
23
23
  const ERRORS = CONSTS.ERRORS;
24
+ /**
25
+ * Client for the objects database backed by Redis (or the in-memory redis-protocol server)
26
+ */
24
27
  export class ObjectsInRedisClient {
25
28
  client;
26
29
  fileNamespace;
@@ -47,6 +50,9 @@ export class ObjectsInRedisClient {
47
50
  noLegacyMultihost;
48
51
  userSubscriptions;
49
52
  systemSubscriptions;
53
+ /**
54
+ * @param settings Settings for the objects client including connection and namespaces
55
+ */
50
56
  constructor(settings) {
51
57
  this.settings = settings || {};
52
58
  this.redisNamespace = `${this.settings.redisNamespace || this.settings.connection?.redisNamespace || 'cfg'}.`;
@@ -107,6 +113,9 @@ export class ObjectsInRedisClient {
107
113
  throw new Error(`This host does not support protocol version "${protoVersion}"`);
108
114
  }
109
115
  }
116
+ /**
117
+ * Connect to the objects database and set up the change and file subscriptions
118
+ */
110
119
  connectDb() {
111
120
  this.settings.connection = this.settings.connection || {};
112
121
  const onChange = this.settings.change; // on change handler
@@ -590,6 +599,9 @@ export class ObjectsInRedisClient {
590
599
  }
591
600
  });
592
601
  }
602
+ /**
603
+ * Get the current status of the database
604
+ */
593
605
  getStatus() {
594
606
  return { type: 'redis', server: false };
595
607
  }
@@ -615,6 +627,11 @@ export class ObjectsInRedisClient {
615
627
  throw new Error(`${id} is not an object of type "meta"`);
616
628
  }
617
629
  }
630
+ /**
631
+ * Normalize a file name by collapsing slashes and backslashes into a single forward slash
632
+ *
633
+ * @param name The file name to normalize
634
+ */
618
635
  normalizeFilename(name) {
619
636
  return name ? name.replace(/[/\\]+/g, '/') : name;
620
637
  }
@@ -660,6 +677,13 @@ export class ObjectsInRedisClient {
660
677
  await this.client.publish(id, 'null'); // inform about deletion
661
678
  }
662
679
  }
680
+ /**
681
+ * Build the internal redis key for a file
682
+ *
683
+ * @param id The id of the object owning the file
684
+ * @param name The file name
685
+ * @param isMeta Whether to return the key of the meta entry (true) or the data entry (false)
686
+ */
663
687
  getFileId(id, name, isMeta) {
664
688
  name = this.normalizeFilename(name);
665
689
  // e.g. ekey.admin and admin/ekey.png
@@ -686,6 +710,15 @@ export class ObjectsInRedisClient {
686
710
  name = normalized.name;
687
711
  return `${this.fileNamespace + id}$%$${name}${isMeta !== undefined ? (isMeta ? '$%$meta' : '$%$data') : ''}`;
688
712
  }
713
+ /**
714
+ * Check whether the current options have the required rights on a file
715
+ *
716
+ * @param id The id of the object owning the file
717
+ * @param name The file name
718
+ * @param options The current request options including the user
719
+ * @param flag The access flag(s) to check for
720
+ * @param callback Called with whether the check failed and the effective options
721
+ */
689
722
  async checkFile(id, name, options, flag, callback) {
690
723
  // read file settings from redis
691
724
  const fileId = this.getFileId(id, name, true);
@@ -720,6 +753,15 @@ export class ObjectsInRedisClient {
720
753
  }
721
754
  return tools.maybeCallback(callback, true, options); // error
722
755
  }
756
+ /**
757
+ * Check whether the current user is allowed to access a file
758
+ *
759
+ * @param id The id of the object owning the file
760
+ * @param name The file name, or null for the whole namespace
761
+ * @param options The current request options including the user
762
+ * @param flag The access flag(s) to check for
763
+ * @param callback Called with the effective options once the rights have been checked
764
+ */
723
765
  checkFileRights(id, name, options, flag, callback) {
724
766
  return utils.checkFileRights(this, id, name, options, flag, callback);
725
767
  }
@@ -737,6 +779,11 @@ export class ObjectsInRedisClient {
737
779
  }
738
780
  }
739
781
  }
782
+ /**
783
+ * Set the default ACL applied to new objects and apply it to all existing objects without an ACL
784
+ *
785
+ * @param defaultNewAcl The default ACL to use, or null to use the built-in default
786
+ */
740
787
  async setDefaultAcl(defaultNewAcl) {
741
788
  this.defaultNewAcl = defaultNewAcl || {
742
789
  owner: CONSTS.SYSTEM_ADMIN_USER,
@@ -756,6 +803,12 @@ export class ObjectsInRedisClient {
756
803
  this.log.error(`${this.namespace} Could not update default acl: ${e.message}`);
757
804
  }
758
805
  }
806
+ /**
807
+ * Determine the groups and effective ACL of the given user
808
+ *
809
+ * @param user The id of the user to look up
810
+ * @param callback Called with the user, its groups and the effective ACL
811
+ */
759
812
  getUserGroup(user, callback) {
760
813
  return utils.getUserGroup(this, user, (error, user, userGroups, userAcl) => {
761
814
  if (error) {
@@ -823,6 +876,15 @@ export class ObjectsInRedisClient {
823
876
  }
824
877
  }
825
878
  }
879
+ /**
880
+ * Write data into a file of an object
881
+ *
882
+ * @param id The id of the object owning the file
883
+ * @param name The file name
884
+ * @param data The data to write
885
+ * @param options The current request options including the user, or the callback
886
+ * @param callback Called once the file has been written
887
+ */
826
888
  async writeFile(id, name, data, options, callback) {
827
889
  if (typeof options === 'function') {
828
890
  callback = options;
@@ -861,6 +923,14 @@ export class ObjectsInRedisClient {
861
923
  return this._writeFile(id, name, data, options, callback, meta);
862
924
  });
863
925
  }
926
+ /**
927
+ * Promise-version of writeFile
928
+ *
929
+ * @param id The id of the object owning the file
930
+ * @param name The file name
931
+ * @param data The data to write
932
+ * @param options The current request options including the user
933
+ */
864
934
  writeFileAsync(id, name, data, options) {
865
935
  return new Promise((resolve, reject) => this.writeFile(id, name, data, options, err => (err ? reject(err) : resolve())));
866
936
  }
@@ -879,6 +949,14 @@ export class ObjectsInRedisClient {
879
949
  }
880
950
  return { file: buffer, mimeType: mimeType };
881
951
  }
952
+ /**
953
+ * Read a file of an object
954
+ *
955
+ * @param id The id of the object owning the file
956
+ * @param name The file name
957
+ * @param options The current request options including the user, or the callback
958
+ * @param callback Called with the file content and mime type
959
+ */
882
960
  readFile(id, name, options, callback) {
883
961
  if (typeof options === 'function') {
884
962
  callback = options;
@@ -991,6 +1069,14 @@ export class ObjectsInRedisClient {
991
1069
  await this._delBinaryState(dataID);
992
1070
  await this.client.del(metaID);
993
1071
  }
1072
+ /**
1073
+ * Delete a file or directory of an object
1074
+ *
1075
+ * @param id The id of the object owning the file
1076
+ * @param name The file or directory name to delete
1077
+ * @param options The current request options including the user, or the callback
1078
+ * @param callback Called with the list of removed files
1079
+ */
994
1080
  unlink(id, name, options, callback) {
995
1081
  if (typeof options === 'function') {
996
1082
  callback = options;
@@ -1021,12 +1107,34 @@ export class ObjectsInRedisClient {
1021
1107
  }
1022
1108
  });
1023
1109
  }
1110
+ /**
1111
+ * Promise-version of unlink
1112
+ *
1113
+ * @param id The id of the object owning the file
1114
+ * @param name The file or directory name to delete
1115
+ * @param options The current request options including the user
1116
+ */
1024
1117
  unlinkAsync(id, name, options) {
1025
1118
  return new Promise((resolve, reject) => this.unlink(id, name, options, err => (err ? reject(err) : resolve())));
1026
1119
  }
1120
+ /**
1121
+ * Delete a file of an object (alias for unlink)
1122
+ *
1123
+ * @param id The id of the object owning the file
1124
+ * @param name The file name to delete
1125
+ * @param options The current request options including the user
1126
+ * @param callback Called once the file has been deleted
1127
+ */
1027
1128
  delFile(id, name, options, callback) {
1028
1129
  return this.unlink(id, name, options, callback);
1029
1130
  }
1131
+ /**
1132
+ * Promise-version of delFile
1133
+ *
1134
+ * @param id The id of the object owning the file
1135
+ * @param name The file name to delete
1136
+ * @param options The current request options including the user
1137
+ */
1030
1138
  delFileAsync(id, name, options) {
1031
1139
  return this.unlinkAsync(id, name, options);
1032
1140
  }
@@ -1174,6 +1282,14 @@ export class ObjectsInRedisClient {
1174
1282
  }
1175
1283
  return tools.maybeCallbackWithError(callback, null, result);
1176
1284
  }
1285
+ /**
1286
+ * List the contents of a directory of an object
1287
+ *
1288
+ * @param id The id of the object owning the files
1289
+ * @param name The directory name to list
1290
+ * @param options The current request options including the user, or the callback
1291
+ * @param callback Called with the directory entries
1292
+ */
1177
1293
  readDir(id, name, options, callback) {
1178
1294
  if (typeof options === 'function') {
1179
1295
  callback = options;
@@ -1202,6 +1318,13 @@ export class ObjectsInRedisClient {
1202
1318
  this._readDir(id, name, options, callback);
1203
1319
  });
1204
1320
  }
1321
+ /**
1322
+ * Promise-version of readDir
1323
+ *
1324
+ * @param id The id of the object owning the files
1325
+ * @param name The directory name to list
1326
+ * @param options The current request options including the user
1327
+ */
1205
1328
  readDirAsync(id, name, options) {
1206
1329
  return new Promise((resolve, reject) => this.readDir(id, name, options, (err, res) => (err ? reject(err) : resolve(res))));
1207
1330
  }
@@ -1318,6 +1441,15 @@ export class ObjectsInRedisClient {
1318
1441
  return tools.maybeCallbackWithRedisError(callback, e);
1319
1442
  }
1320
1443
  }
1444
+ /**
1445
+ * Rename a file or directory of an object
1446
+ *
1447
+ * @param id The id of the object owning the file
1448
+ * @param oldName The current file or directory name
1449
+ * @param newName The new file or directory name
1450
+ * @param options The current request options including the user, or the callback
1451
+ * @param callback Called once the file has been renamed
1452
+ */
1321
1453
  rename(id, oldName, newName, options, callback) {
1322
1454
  if (typeof options === 'function') {
1323
1455
  callback = options;
@@ -1358,6 +1490,14 @@ export class ObjectsInRedisClient {
1358
1490
  this._rename(id, oldName, newName, options, callback, meta);
1359
1491
  });
1360
1492
  }
1493
+ /**
1494
+ * Promise-version of rename
1495
+ *
1496
+ * @param id The id of the object owning the file
1497
+ * @param oldName The current file or directory name
1498
+ * @param newName The new file or directory name
1499
+ * @param options The current request options including the user
1500
+ */
1361
1501
  renameAsync(id, oldName, newName, options) {
1362
1502
  return new Promise((resolve, reject) => this.rename(id, oldName, newName, options, err => (err ? reject(err) : resolve())));
1363
1503
  }
@@ -1378,6 +1518,14 @@ export class ObjectsInRedisClient {
1378
1518
  return tools.maybeCallbackWithRedisError(callback, e);
1379
1519
  }
1380
1520
  }
1521
+ /**
1522
+ * Update the modification time of a file
1523
+ *
1524
+ * @param id The id of the object owning the file
1525
+ * @param name The file name
1526
+ * @param options The current request options including the user, or the callback
1527
+ * @param callback Called once the file has been touched
1528
+ */
1381
1529
  touch(id, name, options, callback) {
1382
1530
  if (typeof options === 'function') {
1383
1531
  callback = options;
@@ -1399,6 +1547,13 @@ export class ObjectsInRedisClient {
1399
1547
  return this._touch(id, name, callback, meta);
1400
1548
  });
1401
1549
  }
1550
+ /**
1551
+ * Promise-version of touch
1552
+ *
1553
+ * @param id The id of the object owning the file
1554
+ * @param name The file name
1555
+ * @param options The current request options including the user
1556
+ */
1402
1557
  touchAsync(id, name, options) {
1403
1558
  return new Promise((resolve, reject) => this.touch(id, name, options, err => (err ? reject(err) : resolve())));
1404
1559
  }
@@ -1494,6 +1649,14 @@ export class ObjectsInRedisClient {
1494
1649
  return files;
1495
1650
  }
1496
1651
  }
1652
+ /**
1653
+ * Delete a file or directory of an object
1654
+ *
1655
+ * @param id The id of the object owning the file
1656
+ * @param name The file or directory name to delete
1657
+ * @param options The current request options including the user, or the callback
1658
+ * @param callback Called with the list of removed files
1659
+ */
1497
1660
  rm(id, name, options, callback) {
1498
1661
  if (typeof options === 'function') {
1499
1662
  callback = options;
@@ -1521,10 +1684,25 @@ export class ObjectsInRedisClient {
1521
1684
  }
1522
1685
  });
1523
1686
  }
1687
+ /**
1688
+ * Promise-version of rm
1689
+ *
1690
+ * @param id The id of the object owning the file
1691
+ * @param name The file or directory name to delete
1692
+ * @param options The current request options including the user
1693
+ */
1524
1694
  rmAsync(id, name, options) {
1525
1695
  return new Promise((resolve, reject) => this.rm(id, name, options, (err, files) => (err ? reject(err) : resolve(files))));
1526
1696
  }
1527
1697
  // simulate. redis has no dirs
1698
+ /**
1699
+ * Create a directory for an object's files (simulated, as redis has no real directories)
1700
+ *
1701
+ * @param id The id of the object owning the files
1702
+ * @param dirName The directory name to create
1703
+ * @param options The current request options including the user, or the callback
1704
+ * @param callback Called once the directory has been created
1705
+ */
1528
1706
  mkdir(id, dirName, options, callback) {
1529
1707
  if (typeof options === 'function') {
1530
1708
  callback = options;
@@ -1550,6 +1728,13 @@ export class ObjectsInRedisClient {
1550
1728
  this.writeFile(id, `${realName}_data.json`, '', options, callback);
1551
1729
  });
1552
1730
  }
1731
+ /**
1732
+ * Promise-version of mkdir
1733
+ *
1734
+ * @param id The id of the object owning the files
1735
+ * @param dirName The directory name to create
1736
+ * @param options The current request options including the user
1737
+ */
1553
1738
  mkdirAsync(id, dirName, options) {
1554
1739
  return new Promise((resolve, reject) => this.mkdir(id, dirName, options, err => (err ? reject(err) : resolve())));
1555
1740
  }
@@ -1679,6 +1864,14 @@ export class ObjectsInRedisClient {
1679
1864
  return tools.maybeCallbackWithError(callback, err, processed);
1680
1865
  });
1681
1866
  }
1867
+ /**
1868
+ * Change the owner and owner group of a file
1869
+ *
1870
+ * @param id The id of the object owning the file
1871
+ * @param name The file name
1872
+ * @param options The current request options including the new owner and the user
1873
+ * @param callback Called with the processed file(s)
1874
+ */
1682
1875
  chownFile(id, name, options, callback) {
1683
1876
  if (typeof options === 'function') {
1684
1877
  callback = options;
@@ -1725,6 +1918,13 @@ export class ObjectsInRedisClient {
1725
1918
  return this._chownFile(id, name, options, callback, meta);
1726
1919
  });
1727
1920
  }
1921
+ /**
1922
+ * Promise-version of chownFile
1923
+ *
1924
+ * @param id The id of the object owning the file
1925
+ * @param name The file name
1926
+ * @param options The current request options including the new owner and the user
1927
+ */
1728
1928
  chownFileAsync(id, name, options) {
1729
1929
  return new Promise((resolve, reject) => this.chownFile(id, name, options, (err, processed) => (err ? reject(err) : resolve(processed))));
1730
1930
  }
@@ -1858,6 +2058,14 @@ export class ObjectsInRedisClient {
1858
2058
  }
1859
2059
  this._chmodFileHelper(keysFiltered, objsFiltered, options, err => tools.maybeCallbackWithError(callback, err, processed));
1860
2060
  }
2061
+ /**
2062
+ * Change the file mode (permissions) of a single file
2063
+ *
2064
+ * @param id The id of the object owning the file
2065
+ * @param name The file name
2066
+ * @param options The current request options including the new mode and the user, or the callback
2067
+ * @param callback Called with the processed file
2068
+ */
1861
2069
  chmodFile(id, name, options, callback) {
1862
2070
  if (typeof options === 'function') {
1863
2071
  callback = options;
@@ -1890,9 +2098,23 @@ export class ObjectsInRedisClient {
1890
2098
  return this._chmodFile(id, name, options, callback, meta);
1891
2099
  });
1892
2100
  }
2101
+ /**
2102
+ * Promise-version of chmodFile
2103
+ *
2104
+ * @param id The id of the object owning the file
2105
+ * @param name The file name
2106
+ * @param options The current request options including the new mode and the user
2107
+ */
1893
2108
  chmodFileAsync(id, name, options) {
1894
2109
  return new Promise((resolve, reject) => this.chmodFile(id, name, options, (err, processed) => (err ? reject(err) : resolve(processed))));
1895
2110
  }
2111
+ /**
2112
+ * Enable or disable the file cache
2113
+ *
2114
+ * @param enabled Whether the file cache should be enabled
2115
+ * @param options The current request options including the user, or the callback
2116
+ * @param callback Called with the resulting cache state
2117
+ */
1896
2118
  enableFileCache(enabled, options, callback) {
1897
2119
  if (typeof options === 'function') {
1898
2120
  callback = options;
@@ -1909,6 +2131,12 @@ export class ObjectsInRedisClient {
1909
2131
  return tools.maybeCallbackWithError(callback, null, false);
1910
2132
  });
1911
2133
  }
2134
+ /**
2135
+ * Promise-version of enableFileCache
2136
+ *
2137
+ * @param enabled Whether the file cache should be enabled
2138
+ * @param options The current request options including the user
2139
+ */
1912
2140
  enableFileCacheAsync(enabled, options) {
1913
2141
  return new Promise((resolve, reject) => this.enableFileCache(enabled, options, (err, res) => (err ? reject(err) : resolve(res))));
1914
2142
  }
@@ -1958,6 +2186,13 @@ export class ObjectsInRedisClient {
1958
2186
  }
1959
2187
  }
1960
2188
  }
2189
+ /**
2190
+ * Subscribe a user to file changes of an object
2191
+ *
2192
+ * @param id The id of the object owning the files
2193
+ * @param pattern One or more file name patterns to subscribe to
2194
+ * @param options The current request options including the user
2195
+ */
1961
2196
  subscribeUserFile(id, pattern, options) {
1962
2197
  return new Promise((resolve, reject) => {
1963
2198
  utils.checkObjectRights(this, null, null, options, 'list', err => {
@@ -1972,6 +2207,13 @@ export class ObjectsInRedisClient {
1972
2207
  });
1973
2208
  });
1974
2209
  }
2210
+ /**
2211
+ * Unsubscribe a user from file changes of an object
2212
+ *
2213
+ * @param id The id of the object owning the files
2214
+ * @param pattern One or more file name patterns to unsubscribe from
2215
+ * @param options The current request options including the user
2216
+ */
1975
2217
  unsubscribeUserFile(id, pattern, options) {
1976
2218
  return new Promise((resolve, reject) => {
1977
2219
  utils.checkObjectRights(this, null, null, options, 'list', err => {
@@ -2025,6 +2267,13 @@ export class ObjectsInRedisClient {
2025
2267
  return this._subscribe(pattern, false, callback);
2026
2268
  });
2027
2269
  }
2270
+ /**
2271
+ * Subscribe to object changes matching the given pattern
2272
+ *
2273
+ * @param pattern One or more patterns to subscribe to
2274
+ * @param options The current request options including the user, or the callback
2275
+ * @param callback Called once the subscription is registered
2276
+ */
2028
2277
  subscribe(pattern, options, callback) {
2029
2278
  if (typeof options === 'function') {
2030
2279
  callback = options;
@@ -2032,9 +2281,22 @@ export class ObjectsInRedisClient {
2032
2281
  }
2033
2282
  return this.subscribeConfig(pattern, options, callback);
2034
2283
  }
2284
+ /**
2285
+ * Promise-version of subscribe
2286
+ *
2287
+ * @param pattern One or more patterns to subscribe to
2288
+ * @param options The current request options including the user
2289
+ */
2035
2290
  subscribeAsync(pattern, options) {
2036
2291
  return new Promise((resolve, reject) => this.subscribe(pattern, options, err => (err ? reject(err) : resolve())));
2037
2292
  }
2293
+ /**
2294
+ * Subscribe a user to object changes matching the given pattern
2295
+ *
2296
+ * @param pattern One or more patterns to subscribe to
2297
+ * @param options The current request options including the user, or the callback
2298
+ * @param callback Called once the subscription is registered
2299
+ */
2038
2300
  subscribeUser(pattern, options, callback) {
2039
2301
  if (typeof options === 'function') {
2040
2302
  callback = options;
@@ -2047,6 +2309,12 @@ export class ObjectsInRedisClient {
2047
2309
  return this._subscribe(pattern, true, callback);
2048
2310
  });
2049
2311
  }
2312
+ /**
2313
+ * Promise-version of subscribeUser
2314
+ *
2315
+ * @param pattern One or more patterns to subscribe to
2316
+ * @param options The current request options including the user
2317
+ */
2050
2318
  subscribeUserAsync(pattern, options) {
2051
2319
  return new Promise((resolve, reject) => this.subscribeUser(pattern, options, err => (err ? reject(err) : resolve())));
2052
2320
  }
@@ -2088,6 +2356,13 @@ export class ObjectsInRedisClient {
2088
2356
  }
2089
2357
  });
2090
2358
  }
2359
+ /**
2360
+ * Unsubscribe from object changes matching the given pattern
2361
+ *
2362
+ * @param pattern One or more patterns to unsubscribe from
2363
+ * @param options The current request options including the user, or the callback
2364
+ * @param callback Called once the subscription is removed
2365
+ */
2091
2366
  unsubscribe(pattern, options, callback) {
2092
2367
  if (typeof options === 'function') {
2093
2368
  callback = options;
@@ -2095,9 +2370,22 @@ export class ObjectsInRedisClient {
2095
2370
  }
2096
2371
  return this.unsubscribeConfig(pattern, options, callback);
2097
2372
  }
2373
+ /**
2374
+ * Promise-version of unsubscribe
2375
+ *
2376
+ * @param pattern One or more patterns to unsubscribe from
2377
+ * @param options The current request options including the user
2378
+ */
2098
2379
  unsubscribeAsync(pattern, options) {
2099
2380
  return new Promise((resolve, reject) => this.unsubscribe(pattern, options, err => (err ? reject(err) : resolve())));
2100
2381
  }
2382
+ /**
2383
+ * Unsubscribe a user from object changes matching the given pattern
2384
+ *
2385
+ * @param pattern One or more patterns to unsubscribe from
2386
+ * @param options The current request options including the user, or the callback
2387
+ * @param callback Called once the subscription is removed
2388
+ */
2101
2389
  unsubscribeUser(pattern, options, callback) {
2102
2390
  if (typeof options === 'function') {
2103
2391
  callback = options;
@@ -2116,6 +2404,12 @@ export class ObjectsInRedisClient {
2116
2404
  }
2117
2405
  });
2118
2406
  }
2407
+ /**
2408
+ * Promise-version of unsubscribeUser
2409
+ *
2410
+ * @param pattern One or more patterns to unsubscribe from
2411
+ * @param options The current request options including the user
2412
+ */
2119
2413
  unsubscribeUserAsync(pattern, options) {
2120
2414
  return new Promise((resolve, reject) => this.unsubscribeUser(pattern, options, err => (err ? reject(err) : resolve())));
2121
2415
  }
@@ -2214,6 +2508,13 @@ export class ObjectsInRedisClient {
2214
2508
  return tools.maybeCallbackWithError(callback, null, filteredObjs);
2215
2509
  }, true);
2216
2510
  }
2511
+ /**
2512
+ * Change the owner and owner group of all objects matching the given pattern
2513
+ *
2514
+ * @param pattern The pattern of object ids whose owner should be changed
2515
+ * @param options The current request options including the new owner and the user, or the callback
2516
+ * @param callback Called with the list of changed objects
2517
+ */
2217
2518
  chownObject(pattern, options, callback) {
2218
2519
  if (typeof options === 'function') {
2219
2520
  callback = options;
@@ -2255,6 +2556,12 @@ export class ObjectsInRedisClient {
2255
2556
  return this._chownObject(pattern, options, callback);
2256
2557
  });
2257
2558
  }
2559
+ /**
2560
+ * Promise-version of chownObject
2561
+ *
2562
+ * @param pattern The pattern of object ids whose owner should be changed
2563
+ * @param options The current request options including the new owner and the user
2564
+ */
2258
2565
  chownObjectAsync(pattern, options) {
2259
2566
  return new Promise((resolve, reject) => this.chownObject(pattern, options, (err, list) => (err ? reject(err) : resolve(list))));
2260
2567
  }
@@ -2321,6 +2628,13 @@ export class ObjectsInRedisClient {
2321
2628
  }
2322
2629
  }, true);
2323
2630
  }
2631
+ /**
2632
+ * Change the file mode (permissions) of all files matching the given pattern
2633
+ *
2634
+ * @param pattern The pattern of object ids whose files should be changed
2635
+ * @param options The current request options including the new mode and the user, or the callback
2636
+ * @param callback Called with the list of changed objects
2637
+ */
2324
2638
  chmodObject(pattern, options, callback) {
2325
2639
  if (typeof options === 'function') {
2326
2640
  callback = options;
@@ -2351,6 +2665,12 @@ export class ObjectsInRedisClient {
2351
2665
  return this._chmodObject(pattern, options, callback);
2352
2666
  });
2353
2667
  }
2668
+ /**
2669
+ * Promise-version of chmodObject
2670
+ *
2671
+ * @param pattern The pattern of object ids whose files should be changed
2672
+ * @param options The current request options including the new mode and the user
2673
+ */
2354
2674
  chmodObjectAsync(pattern, options) {
2355
2675
  return new Promise((resolve, reject) => this.chmodObject(pattern, options, (err, list) => (err ? reject(err) : resolve(list))));
2356
2676
  }
@@ -2388,6 +2708,13 @@ export class ObjectsInRedisClient {
2388
2708
  }
2389
2709
  return tools.maybeCallbackWithRedisError(callback, err, obj);
2390
2710
  }
2711
+ /**
2712
+ * Get a single object by its id
2713
+ *
2714
+ * @param id The id of the object to read
2715
+ * @param options The current request options including the user, or the callback
2716
+ * @param callback Called with the read object
2717
+ */
2391
2718
  getObject(id, options, callback) {
2392
2719
  if (typeof options === 'function') {
2393
2720
  callback = options;
@@ -2409,9 +2736,10 @@ export class ObjectsInRedisClient {
2409
2736
  }
2410
2737
  }
2411
2738
  /**
2739
+ * Promise-version of getObject
2412
2740
  *
2413
- * @param id
2414
- * @param options
2741
+ * @param id The id of the object to read
2742
+ * @param options The current request options including the user
2415
2743
  * @deprecated use `getObject` without callback instead
2416
2744
  */
2417
2745
  getObjectAsync(id, options) {
@@ -2488,6 +2816,14 @@ export class ObjectsInRedisClient {
2488
2816
  }
2489
2817
  return tools.maybeCallbackWithError(callback, null, result);
2490
2818
  }
2819
+ /**
2820
+ * Get all object ids matching the given pattern
2821
+ *
2822
+ * @param pattern The pattern to match object ids against
2823
+ * @param options The current request options including the user, or the callback
2824
+ * @param callback Called with the matching keys
2825
+ * @param dontModify If true, the returned keys are not stripped of the namespace
2826
+ */
2491
2827
  getKeys(pattern, options, callback, dontModify) {
2492
2828
  if (typeof options === 'function') {
2493
2829
  callback = options;
@@ -2505,8 +2841,14 @@ export class ObjectsInRedisClient {
2505
2841
  });
2506
2842
  }
2507
2843
  }
2508
- getKeysAsync(id, options) {
2509
- return this.getKeys(id, options);
2844
+ /**
2845
+ * Promise-version of getKeys
2846
+ *
2847
+ * @param pattern The pattern to match object ids against
2848
+ * @param options The current request options including the user
2849
+ */
2850
+ getKeysAsync(pattern, options) {
2851
+ return this.getKeys(pattern, options);
2510
2852
  }
2511
2853
  async _getObjects(keys, options, callback, dontModify) {
2512
2854
  if (!keys) {
@@ -2579,6 +2921,14 @@ export class ObjectsInRedisClient {
2579
2921
  }
2580
2922
  return tools.maybeCallbackWithError(callback, null, result);
2581
2923
  }
2924
+ /**
2925
+ * Get multiple objects by their ids
2926
+ *
2927
+ * @param keys The ids of the objects to read
2928
+ * @param options The current request options including the user, or the callback
2929
+ * @param callback Called with the read objects
2930
+ * @param dontModify If true, the returned objects are not cloned/modified
2931
+ */
2582
2932
  getObjects(keys, options, callback, dontModify) {
2583
2933
  if (typeof options === 'function') {
2584
2934
  callback = options;
@@ -2601,6 +2951,12 @@ export class ObjectsInRedisClient {
2601
2951
  });
2602
2952
  }
2603
2953
  }
2954
+ /**
2955
+ * Promise-version of getObjects
2956
+ *
2957
+ * @param keys The ids of the objects to read
2958
+ * @param options The current request options including the user
2959
+ */
2604
2960
  getObjectsAsync(keys, options) {
2605
2961
  return this.getObjects(keys, options);
2606
2962
  }
@@ -2626,6 +2982,13 @@ export class ObjectsInRedisClient {
2626
2982
  }
2627
2983
  this._getObjects(keys, options, callback, true);
2628
2984
  }
2985
+ /**
2986
+ * Get all objects whose id matches the given pattern
2987
+ *
2988
+ * @param pattern The pattern to match object ids against
2989
+ * @param options The current request options including the user, or the callback
2990
+ * @param callback Called with the matching objects
2991
+ */
2629
2992
  getObjectsByPattern(pattern, options, callback) {
2630
2993
  if (typeof options === 'function') {
2631
2994
  callback = options;
@@ -2646,6 +3009,12 @@ export class ObjectsInRedisClient {
2646
3009
  });
2647
3010
  }
2648
3011
  }
3012
+ /**
3013
+ * Promise-version of getObjectsByPattern
3014
+ *
3015
+ * @param pattern The pattern to match object ids against
3016
+ * @param options The current request options including the user
3017
+ */
2649
3018
  getObjectsByPatternAsync(pattern, options) {
2650
3019
  return new Promise((resolve, reject) => this.getObjectsByPattern(pattern, options, (err, objs) => (err ? reject(err) : resolve(objs))));
2651
3020
  }
@@ -2833,7 +3202,7 @@ export class ObjectsInRedisClient {
2833
3202
  * This function writes the object into DB
2834
3203
  *
2835
3204
  * @param id ID of the object
2836
- * @param obj
3205
+ * @param obj The object to write
2837
3206
  * @param options options for access control are optional
2838
3207
  * @param callback return function
2839
3208
  */
@@ -2863,10 +3232,11 @@ export class ObjectsInRedisClient {
2863
3232
  });
2864
3233
  }
2865
3234
  /**
3235
+ * Promise-version of setObject
2866
3236
  *
2867
- * @param id
2868
- * @param obj
2869
- * @param options
3237
+ * @param id ID of the object
3238
+ * @param obj The object to write
3239
+ * @param options options for access control are optional
2870
3240
  * @deprecated use `setObject` without callback instead
2871
3241
  */
2872
3242
  setObjectAsync(id, obj, options) {
@@ -2935,6 +3305,13 @@ export class ObjectsInRedisClient {
2935
3305
  await this.client.publish(this.objNamespace + id, 'null');
2936
3306
  }
2937
3307
  }
3308
+ /**
3309
+ * Delete an object
3310
+ *
3311
+ * @param id The id of the object to delete
3312
+ * @param options The current request options including the user, or the callback
3313
+ * @param callback Called once the object has been deleted
3314
+ */
2938
3315
  delObject(id, options, callback) {
2939
3316
  if (typeof options === 'function') {
2940
3317
  callback = options;
@@ -2959,6 +3336,12 @@ export class ObjectsInRedisClient {
2959
3336
  }
2960
3337
  });
2961
3338
  }
3339
+ /**
3340
+ * Promise-version of delObject
3341
+ *
3342
+ * @param id The id of the object to delete
3343
+ * @param options The current request options including the user
3344
+ */
2962
3345
  delObjectAsync(id, options) {
2963
3346
  return this.delObject(id, options);
2964
3347
  }
@@ -3454,6 +3837,15 @@ export class ObjectsInRedisClient {
3454
3837
  throw new Error(`Cannot find view "${design}"`);
3455
3838
  }
3456
3839
  }
3840
+ /**
3841
+ * Run a predefined object view (design document) and return the matching rows
3842
+ *
3843
+ * @param design The design document name
3844
+ * @param search The view name within the design document
3845
+ * @param params Query parameters such as startkey and endkey
3846
+ * @param options The current request options including the user, or the callback
3847
+ * @param callback Called with the matching rows
3848
+ */
3457
3849
  getObjectView(design, search, params, options, callback) {
3458
3850
  if (typeof options === 'function') {
3459
3851
  callback = options;
@@ -3480,6 +3872,14 @@ export class ObjectsInRedisClient {
3480
3872
  });
3481
3873
  }
3482
3874
  }
3875
+ /**
3876
+ * Promise-version of getObjectView
3877
+ *
3878
+ * @param design The design document name
3879
+ * @param search The view name within the design document
3880
+ * @param params Query parameters such as startkey and endkey
3881
+ * @param options The current request options including the user
3882
+ */
3483
3883
  getObjectViewAsync(design, search, params, options) {
3484
3884
  return this.getObjectView(design, search, params, options);
3485
3885
  }
@@ -3547,6 +3947,13 @@ export class ObjectsInRedisClient {
3547
3947
  }
3548
3948
  return result;
3549
3949
  }
3950
+ /**
3951
+ * Get the list of objects matching the given parameters
3952
+ *
3953
+ * @param params Query parameters such as startkey and endkey
3954
+ * @param options The current request options including the user, or the callback
3955
+ * @param callback Called with the matching objects
3956
+ */
3550
3957
  getObjectList(params, options, callback) {
3551
3958
  if (typeof options === 'function') {
3552
3959
  callback = options;
@@ -3573,6 +3980,12 @@ export class ObjectsInRedisClient {
3573
3980
  });
3574
3981
  }
3575
3982
  }
3983
+ /**
3984
+ * Promise-version of getObjectList
3985
+ *
3986
+ * @param params Query parameters such as startkey and endkey
3987
+ * @param options The current request options including the user
3988
+ */
3576
3989
  getObjectListAsync(params, options) {
3577
3990
  return this.getObjectList(params, options);
3578
3991
  }
@@ -3715,6 +4128,14 @@ export class ObjectsInRedisClient {
3715
4128
  return tools.maybeCallbackWithRedisError(callback, e);
3716
4129
  }
3717
4130
  }
4131
+ /**
4132
+ * Extend an existing object with the given partial object, creating it if it does not exist
4133
+ *
4134
+ * @param id The id of the object to extend
4135
+ * @param obj The partial object to merge into the existing object
4136
+ * @param options The current request options including the user, or the callback
4137
+ * @param callback Called with the resulting object and its id
4138
+ */
3718
4139
  extendObject(id, obj, options, callback) {
3719
4140
  if (typeof options === 'function') {
3720
4141
  callback = options;
@@ -3734,16 +4155,23 @@ export class ObjectsInRedisClient {
3734
4155
  return this._extendObject(id, obj, options, callback);
3735
4156
  });
3736
4157
  }
4158
+ /**
4159
+ * Promise-version of extendObject
4160
+ *
4161
+ * @param id The id of the object to extend
4162
+ * @param obj The partial object to merge into the existing object
4163
+ * @param options The current request options including the user
4164
+ */
3737
4165
  extendObjectAsync(id, obj, options) {
3738
4166
  return new Promise((resolve, reject) => this.extendObject(id, obj, options || null, (err, res) => (err ? reject(err) : resolve(res))));
3739
4167
  }
3740
4168
  /**
3741
4169
  * Returns the object id if found
3742
4170
  *
3743
- * @param idOrName
3744
- * @param type
3745
- * @param options
3746
- * @param callback
4171
+ * @param idOrName The id or name to search for
4172
+ * @param type The expected common type, or null for any
4173
+ * @param options The current request options (may include a language)
4174
+ * @param callback Called with the found id and the original id/name
3747
4175
  */
3748
4176
  _findObject(idOrName, type, options, callback) {
3749
4177
  // Try to read by ID
@@ -3793,6 +4221,14 @@ export class ObjectsInRedisClient {
3793
4221
  }, true);
3794
4222
  });
3795
4223
  }
4224
+ /**
4225
+ * Find an object by its id or name
4226
+ *
4227
+ * @param idOrName The id or name to search for
4228
+ * @param type The expected common type, or null for any
4229
+ * @param options The current request options (may include a language), or the callback
4230
+ * @param callback Called with the found id and the original id/name
4231
+ */
3796
4232
  findObject(idOrName, type, options, callback) {
3797
4233
  if (typeof type === 'function') {
3798
4234
  callback = type;
@@ -3819,6 +4255,11 @@ export class ObjectsInRedisClient {
3819
4255
  }
3820
4256
  }
3821
4257
  // can be called only from js-controller
4258
+ /**
4259
+ * Add object property paths that should be preserved when an object is overwritten (controller only)
4260
+ *
4261
+ * @param settings One or more property paths to preserve
4262
+ */
3822
4263
  addPreserveSettings(settings) {
3823
4264
  if (!Array.isArray(settings)) {
3824
4265
  settings = [settings];
@@ -3860,6 +4301,12 @@ export class ObjectsInRedisClient {
3860
4301
  return tools.maybeCallbackWithRedisError(callback, e);
3861
4302
  }
3862
4303
  }
4304
+ /**
4305
+ * Delete the whole objects database (requires admin rights)
4306
+ *
4307
+ * @param options The current request options including the user, or the callback
4308
+ * @param callback Called once the database has been destroyed
4309
+ */
3863
4310
  destroyDB(options, callback) {
3864
4311
  if (typeof options === 'function') {
3865
4312
  callback = options;
@@ -3876,10 +4323,17 @@ export class ObjectsInRedisClient {
3876
4323
  return this._destroyDB(callback);
3877
4324
  });
3878
4325
  }
4326
+ /**
4327
+ * Promise-version of destroyDB
4328
+ *
4329
+ * @param options The current request options including the user
4330
+ */
3879
4331
  destroyDBAsync(options) {
3880
4332
  return new Promise((resolve, reject) => this.destroyDB(options, err => (err ? reject(err) : resolve())));
3881
4333
  }
3882
- // Destructor of the class. Called by shutting down.
4334
+ /**
4335
+ * Destructor of the class. Called when shutting down to close the redis connections.
4336
+ */
3883
4337
  async destroy() {
3884
4338
  this.stop = true;
3885
4339
  if (this.client) {
@@ -3913,6 +4367,9 @@ export class ObjectsInRedisClient {
3913
4367
  }
3914
4368
  }
3915
4369
  }
4370
+ /**
4371
+ * Load and register the Lua scripts used for atomic operations on the redis server
4372
+ */
3916
4373
  async loadLuaScripts() {
3917
4374
  let luaDirName;
3918
4375
  if (this.noLegacyMultihost && this.useSets) {