@iobroker/db-objects-file 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.
- package/build/cjs/lib/objects/objectsInMemFileDB.d.ts +139 -6
- package/build/cjs/lib/objects/objectsInMemFileDB.js +141 -28
- package/build/cjs/lib/objects/objectsInMemFileDB.js.map +2 -2
- package/build/cjs/lib/objects/objectsInMemServerClass.d.ts +17 -0
- package/build/cjs/lib/objects/objectsInMemServerClass.js +20 -0
- package/build/cjs/lib/objects/objectsInMemServerClass.js.map +2 -2
- package/build/cjs/lib/objects/objectsInMemServerRedis.d.ts +2 -8
- package/build/cjs/lib/objects/objectsInMemServerRedis.js +2 -2
- package/build/cjs/lib/objects/objectsInMemServerRedis.js.map +1 -1
- package/build/esm/lib/objects/objectsInMemFileDB.d.ts +139 -6
- package/build/esm/lib/objects/objectsInMemFileDB.d.ts.map +1 -1
- package/build/esm/lib/objects/objectsInMemFileDB.js +142 -29
- package/build/esm/lib/objects/objectsInMemFileDB.js.map +1 -1
- package/build/esm/lib/objects/objectsInMemServerClass.d.ts +17 -0
- package/build/esm/lib/objects/objectsInMemServerClass.d.ts.map +1 -1
- package/build/esm/lib/objects/objectsInMemServerClass.js +23 -0
- package/build/esm/lib/objects/objectsInMemServerClass.js.map +1 -1
- package/build/esm/lib/objects/objectsInMemServerRedis.d.ts +2 -8
- package/build/esm/lib/objects/objectsInMemServerRedis.d.ts.map +1 -1
- package/build/esm/lib/objects/objectsInMemServerRedis.js +2 -2
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
* including the available methods for use by js-controller directly
|
|
4
4
|
*/
|
|
5
5
|
export class ObjectsInMemoryFileDB extends InMemoryFileDB {
|
|
6
|
+
/**
|
|
7
|
+
* @param settings Settings for the objects database
|
|
8
|
+
*/
|
|
6
9
|
constructor(settings: any);
|
|
7
10
|
change: any;
|
|
8
11
|
META_ID: string;
|
|
@@ -16,14 +19,50 @@ export class ObjectsInMemoryFileDB extends InMemoryFileDB {
|
|
|
16
19
|
writeFileInterval: number;
|
|
17
20
|
objectsDir: string;
|
|
18
21
|
existingMetaObjects: {};
|
|
22
|
+
/**
|
|
23
|
+
* Normalize a file name by collapsing slashes and backslashes into a single forward slash
|
|
24
|
+
*
|
|
25
|
+
* @param name The file name to normalize
|
|
26
|
+
*/
|
|
19
27
|
_normalizeFilename(name: any): any;
|
|
28
|
+
/**
|
|
29
|
+
* Schedule writing the file settings (_data.json) to disk
|
|
30
|
+
*
|
|
31
|
+
* @param id The object ID whose file settings should be saved, or a boolean used as the force flag
|
|
32
|
+
* @param force If true, write the settings immediately instead of debounced
|
|
33
|
+
*/
|
|
20
34
|
_saveFileSettings(id: any, force: any): void;
|
|
35
|
+
/**
|
|
36
|
+
* Load the file settings (_data.json) for the given object ID into memory
|
|
37
|
+
*
|
|
38
|
+
* @param id The object ID whose file settings should be loaded
|
|
39
|
+
*/
|
|
21
40
|
_loadFileSettings(id: any): void;
|
|
41
|
+
/**
|
|
42
|
+
* Synchronize the in-memory file metadata with the files actually present on disk (server only)
|
|
43
|
+
*
|
|
44
|
+
* @param limitId Optional object ID to limit the synchronization to
|
|
45
|
+
*/
|
|
22
46
|
syncFileDirectory(limitId: any): {
|
|
23
47
|
numberSuccess: number;
|
|
24
48
|
notifications: any[];
|
|
25
49
|
};
|
|
50
|
+
/**
|
|
51
|
+
* Write a file into an object's file storage (used by the server)
|
|
52
|
+
*
|
|
53
|
+
* @param id The object ID owning the file
|
|
54
|
+
* @param name The file name
|
|
55
|
+
* @param data The file content
|
|
56
|
+
* @param options Optional write options, or the mime type as a string
|
|
57
|
+
*/
|
|
26
58
|
_writeFile(id: any, name: any, data: any, options: any): void;
|
|
59
|
+
/**
|
|
60
|
+
* Read a file from an object's file storage (used by the server)
|
|
61
|
+
*
|
|
62
|
+
* @param id The object ID owning the file
|
|
63
|
+
* @param name The file name
|
|
64
|
+
* @param options Optional read options
|
|
65
|
+
*/
|
|
27
66
|
_readFile(id: any, name: any, options: any): {
|
|
28
67
|
fileContent: any;
|
|
29
68
|
fileMime: any;
|
|
@@ -40,7 +79,7 @@ export class ObjectsInMemoryFileDB extends InMemoryFileDB {
|
|
|
40
79
|
*
|
|
41
80
|
* @param id id of the namespace
|
|
42
81
|
* @param [name] name of the file
|
|
43
|
-
* @returns
|
|
82
|
+
* @returns true if the file exists
|
|
44
83
|
*/
|
|
45
84
|
_fileExists(id: any, name?: any): boolean;
|
|
46
85
|
/**
|
|
@@ -48,10 +87,23 @@ export class ObjectsInMemoryFileDB extends InMemoryFileDB {
|
|
|
48
87
|
*
|
|
49
88
|
* @param id id of the namespace
|
|
50
89
|
* @param [name] name of the directory
|
|
51
|
-
* @returns
|
|
90
|
+
* @returns true if the directory exists
|
|
52
91
|
*/
|
|
53
92
|
dirExists(id: any, name?: any): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Delete a file or directory from an object's file storage (used by the server)
|
|
95
|
+
*
|
|
96
|
+
* @param id The object ID owning the file
|
|
97
|
+
* @param name The file or directory name to delete
|
|
98
|
+
*/
|
|
54
99
|
_unlink(id: any, name: any): void;
|
|
100
|
+
/**
|
|
101
|
+
* List the contents of a directory in an object's file storage (used by the server)
|
|
102
|
+
*
|
|
103
|
+
* @param id The object ID owning the files
|
|
104
|
+
* @param name The directory name to list
|
|
105
|
+
* @param options Optional read options
|
|
106
|
+
*/
|
|
55
107
|
_readDir(id: any, name: any, options: any): {
|
|
56
108
|
file: string;
|
|
57
109
|
stats: fs.Stats;
|
|
@@ -60,31 +112,99 @@ export class ObjectsInMemoryFileDB extends InMemoryFileDB {
|
|
|
60
112
|
modifiedAt: any;
|
|
61
113
|
createdAt: any;
|
|
62
114
|
}[];
|
|
115
|
+
/**
|
|
116
|
+
* Rename a file or directory in an object's file storage (used by the server)
|
|
117
|
+
*
|
|
118
|
+
* @param id The object ID owning the file
|
|
119
|
+
* @param oldName The current file or directory name
|
|
120
|
+
* @param newName The new file or directory name
|
|
121
|
+
*/
|
|
63
122
|
_rename(id: any, oldName: any, newName: any): void;
|
|
123
|
+
/**
|
|
124
|
+
* Create a deep clone of the given object
|
|
125
|
+
*
|
|
126
|
+
* @param obj The object to clone
|
|
127
|
+
*/
|
|
64
128
|
_clone(obj: any): any;
|
|
129
|
+
/**
|
|
130
|
+
* Subscribe a client to meta changes
|
|
131
|
+
*
|
|
132
|
+
* @param client The client to subscribe
|
|
133
|
+
* @param pattern The pattern of meta IDs to subscribe to
|
|
134
|
+
*/
|
|
65
135
|
_subscribeMeta(client: any, pattern: any): void;
|
|
136
|
+
/**
|
|
137
|
+
* Subscribe a client to object changes (used by the server)
|
|
138
|
+
*
|
|
139
|
+
* @param client The client to subscribe
|
|
140
|
+
* @param pattern The pattern of object IDs to subscribe to
|
|
141
|
+
*/
|
|
66
142
|
_subscribeConfigForClient(client: any, pattern: any): void;
|
|
143
|
+
/**
|
|
144
|
+
* Unsubscribe a client from object changes (used by the server)
|
|
145
|
+
*
|
|
146
|
+
* @param client The client to unsubscribe
|
|
147
|
+
* @param pattern The pattern of object IDs to unsubscribe from
|
|
148
|
+
*/
|
|
67
149
|
_unsubscribeConfigForClient(client: any, pattern: any): void;
|
|
150
|
+
/**
|
|
151
|
+
* Subscribe a client to file changes of an object (used by the server)
|
|
152
|
+
*
|
|
153
|
+
* @param client The client to subscribe
|
|
154
|
+
* @param id The object ID owning the files
|
|
155
|
+
* @param pattern One or more file name patterns to subscribe to
|
|
156
|
+
*/
|
|
68
157
|
_subscribeFileForClient(client: any, id: any, pattern: any): void;
|
|
158
|
+
/**
|
|
159
|
+
* Unsubscribe a client from file changes of an object (used by the server)
|
|
160
|
+
*
|
|
161
|
+
* @param client The client to unsubscribe
|
|
162
|
+
* @param id The object ID owning the files
|
|
163
|
+
* @param pattern One or more file name patterns to unsubscribe from
|
|
164
|
+
*/
|
|
69
165
|
_unsubscribeFileForClient(client: any, id: any, pattern: any): void;
|
|
166
|
+
/**
|
|
167
|
+
* Get a single object by its ID (used by the server)
|
|
168
|
+
*
|
|
169
|
+
* @param id The object ID to read
|
|
170
|
+
*/
|
|
70
171
|
_getObject(id: any): any;
|
|
172
|
+
/**
|
|
173
|
+
* Get all object IDs matching the given pattern, sorted (used by the server)
|
|
174
|
+
*
|
|
175
|
+
* @param pattern The pattern to match object IDs against
|
|
176
|
+
*/
|
|
71
177
|
_getKeys(pattern: any): string[];
|
|
178
|
+
/**
|
|
179
|
+
* Get the values of the given object IDs (used by the server)
|
|
180
|
+
*
|
|
181
|
+
* @param keys The object IDs to read
|
|
182
|
+
*/
|
|
72
183
|
_getObjects(keys: any): any;
|
|
184
|
+
/**
|
|
185
|
+
* Get the meta dictionary, creating it if it does not exist yet
|
|
186
|
+
*/
|
|
73
187
|
_ensureMetaDict(): any;
|
|
74
188
|
/**
|
|
75
189
|
* Get value of given meta id
|
|
76
190
|
*
|
|
77
|
-
* @param id
|
|
78
|
-
* @returns
|
|
191
|
+
* @param id The meta ID to read
|
|
192
|
+
* @returns the stored meta value
|
|
79
193
|
*/
|
|
80
194
|
getMeta(id: any): any;
|
|
81
195
|
/**
|
|
82
196
|
* Sets given value to id in metaNamespace
|
|
83
197
|
*
|
|
84
|
-
* @param id
|
|
85
|
-
* @param value
|
|
198
|
+
* @param id The meta ID to write
|
|
199
|
+
* @param value The value to store
|
|
86
200
|
*/
|
|
87
201
|
setMeta(id: any, value: any): void;
|
|
202
|
+
/**
|
|
203
|
+
* Directly set an object value and publish the change (used by the server)
|
|
204
|
+
*
|
|
205
|
+
* @param id The object ID to set
|
|
206
|
+
* @param obj The object to store
|
|
207
|
+
*/
|
|
88
208
|
_setObjectDirect(id: any, obj: any): void;
|
|
89
209
|
/**
|
|
90
210
|
* Delete the given object from the dataset
|
|
@@ -92,9 +212,22 @@ export class ObjectsInMemoryFileDB extends InMemoryFileDB {
|
|
|
92
212
|
* @param id unique id of the object
|
|
93
213
|
*/
|
|
94
214
|
_delObject(id: any): void;
|
|
215
|
+
/**
|
|
216
|
+
* Apply a view's map function over all objects and collect the matching rows
|
|
217
|
+
*
|
|
218
|
+
* @param func The view definition containing the map function
|
|
219
|
+
* @param params Query parameters such as startkey and endkey
|
|
220
|
+
*/
|
|
95
221
|
_applyView(func: any, params: any): {
|
|
96
222
|
rows: never[];
|
|
97
223
|
};
|
|
224
|
+
/**
|
|
225
|
+
* Run a predefined object view (design document) and return the matching rows (used by the server)
|
|
226
|
+
*
|
|
227
|
+
* @param design The design document name
|
|
228
|
+
* @param search The view name within the design document
|
|
229
|
+
* @param params Query parameters such as startkey and endkey
|
|
230
|
+
*/
|
|
98
231
|
_getObjectView(design: any, search: any, params: any): {
|
|
99
232
|
rows: never[];
|
|
100
233
|
};
|
|
@@ -38,9 +38,12 @@ var import_db_base2 = require("@iobroker/db-base");
|
|
|
38
38
|
var import_db_objects_redis = require("@iobroker/db-objects-redis");
|
|
39
39
|
var import_deep_clone = __toESM(require("deep-clone"), 1);
|
|
40
40
|
class ObjectsInMemoryFileDB extends import_db_base.InMemoryFileDB {
|
|
41
|
+
/**
|
|
42
|
+
* @param settings Settings for the objects database
|
|
43
|
+
*/
|
|
41
44
|
constructor(settings) {
|
|
42
|
-
settings
|
|
43
|
-
settings.fileDB
|
|
45
|
+
settings ||= {};
|
|
46
|
+
settings.fileDB ||= {
|
|
44
47
|
fileName: "objects.json",
|
|
45
48
|
backupDirName: "backup-objects"
|
|
46
49
|
};
|
|
@@ -75,12 +78,21 @@ class ObjectsInMemoryFileDB extends import_db_base.InMemoryFileDB {
|
|
|
75
78
|
this.defaultNewAcl = (0, import_deep_clone.default)(configObj.common.defaultNewAcl);
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Normalize a file name by collapsing slashes and backslashes into a single forward slash
|
|
83
|
+
*
|
|
84
|
+
* @param name The file name to normalize
|
|
85
|
+
*/
|
|
79
86
|
_normalizeFilename(name) {
|
|
80
87
|
return name ? name.replace(/[/\\]+/g, "/") : name;
|
|
81
88
|
}
|
|
82
89
|
// -------------- FILE FUNCTIONS -------------------------------------------
|
|
83
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Schedule writing the file settings (_data.json) to disk
|
|
92
|
+
*
|
|
93
|
+
* @param id The object ID whose file settings should be saved, or a boolean used as the force flag
|
|
94
|
+
* @param force If true, write the settings immediately instead of debounced
|
|
95
|
+
*/
|
|
84
96
|
_saveFileSettings(id, force) {
|
|
85
97
|
if (typeof id === "boolean") {
|
|
86
98
|
force = id;
|
|
@@ -115,7 +127,11 @@ class ObjectsInMemoryFileDB extends import_db_base.InMemoryFileDB {
|
|
|
115
127
|
}, 1e3);
|
|
116
128
|
}
|
|
117
129
|
}
|
|
118
|
-
|
|
130
|
+
/**
|
|
131
|
+
* Load the file settings (_data.json) for the given object ID into memory
|
|
132
|
+
*
|
|
133
|
+
* @param id The object ID whose file settings should be loaded
|
|
134
|
+
*/
|
|
119
135
|
_loadFileSettings(id) {
|
|
120
136
|
if (!this.fileOptions[id]) {
|
|
121
137
|
const location = import_node_path.default.join(this.objectsDir, id, "_data.json");
|
|
@@ -148,7 +164,11 @@ class ObjectsInMemoryFileDB extends import_db_base.InMemoryFileDB {
|
|
|
148
164
|
}
|
|
149
165
|
}
|
|
150
166
|
}
|
|
151
|
-
|
|
167
|
+
/**
|
|
168
|
+
* Synchronize the in-memory file metadata with the files actually present on disk (server only)
|
|
169
|
+
*
|
|
170
|
+
* @param limitId Optional object ID to limit the synchronization to
|
|
171
|
+
*/
|
|
152
172
|
syncFileDirectory(limitId) {
|
|
153
173
|
const resNotifies = [];
|
|
154
174
|
let resSynced = 0;
|
|
@@ -229,7 +249,14 @@ class ObjectsInMemoryFileDB extends import_db_base.InMemoryFileDB {
|
|
|
229
249
|
notifications: resNotifies
|
|
230
250
|
};
|
|
231
251
|
}
|
|
232
|
-
|
|
252
|
+
/**
|
|
253
|
+
* Write a file into an object's file storage (used by the server)
|
|
254
|
+
*
|
|
255
|
+
* @param id The object ID owning the file
|
|
256
|
+
* @param name The file name
|
|
257
|
+
* @param data The file content
|
|
258
|
+
* @param options Optional write options, or the mime type as a string
|
|
259
|
+
*/
|
|
233
260
|
_writeFile(id, name, data, options) {
|
|
234
261
|
if (typeof options === "string") {
|
|
235
262
|
options = { mimeType: options };
|
|
@@ -291,7 +318,13 @@ class ObjectsInMemoryFileDB extends import_db_base.InMemoryFileDB {
|
|
|
291
318
|
this.publishAll("files", `${id}$%$${name2}`, size);
|
|
292
319
|
}, name, data.byteLength);
|
|
293
320
|
}
|
|
294
|
-
|
|
321
|
+
/**
|
|
322
|
+
* Read a file from an object's file storage (used by the server)
|
|
323
|
+
*
|
|
324
|
+
* @param id The object ID owning the file
|
|
325
|
+
* @param name The file name
|
|
326
|
+
* @param options Optional read options
|
|
327
|
+
*/
|
|
295
328
|
_readFile(id, name, options) {
|
|
296
329
|
if (options && options.acl) {
|
|
297
330
|
options.acl = null;
|
|
@@ -394,7 +427,7 @@ class ObjectsInMemoryFileDB extends import_db_base.InMemoryFileDB {
|
|
|
394
427
|
*
|
|
395
428
|
* @param id id of the namespace
|
|
396
429
|
* @param [name] name of the file
|
|
397
|
-
* @returns
|
|
430
|
+
* @returns true if the file exists
|
|
398
431
|
*/
|
|
399
432
|
// needed by server
|
|
400
433
|
_fileExists(id, name) {
|
|
@@ -418,7 +451,7 @@ class ObjectsInMemoryFileDB extends import_db_base.InMemoryFileDB {
|
|
|
418
451
|
*
|
|
419
452
|
* @param id id of the namespace
|
|
420
453
|
* @param [name] name of the directory
|
|
421
|
-
* @returns
|
|
454
|
+
* @returns true if the directory exists
|
|
422
455
|
*/
|
|
423
456
|
// special functionality only for Server (used together with SyncFileDirectory)
|
|
424
457
|
dirExists(id, name) {
|
|
@@ -437,7 +470,12 @@ class ObjectsInMemoryFileDB extends import_db_base.InMemoryFileDB {
|
|
|
437
470
|
return false;
|
|
438
471
|
}
|
|
439
472
|
}
|
|
440
|
-
|
|
473
|
+
/**
|
|
474
|
+
* Delete a file or directory from an object's file storage (used by the server)
|
|
475
|
+
*
|
|
476
|
+
* @param id The object ID owning the file
|
|
477
|
+
* @param name The file or directory name to delete
|
|
478
|
+
*/
|
|
441
479
|
_unlink(id, name) {
|
|
442
480
|
const _path = import_db_objects_redis.objectsUtils.sanitizePath(id, name);
|
|
443
481
|
id = _path.id;
|
|
@@ -483,7 +521,13 @@ class ObjectsInMemoryFileDB extends import_db_base.InMemoryFileDB {
|
|
|
483
521
|
}, id, name);
|
|
484
522
|
}
|
|
485
523
|
}
|
|
486
|
-
|
|
524
|
+
/**
|
|
525
|
+
* List the contents of a directory in an object's file storage (used by the server)
|
|
526
|
+
*
|
|
527
|
+
* @param id The object ID owning the files
|
|
528
|
+
* @param name The directory name to list
|
|
529
|
+
* @param options Optional read options
|
|
530
|
+
*/
|
|
487
531
|
_readDir(id, name, options) {
|
|
488
532
|
if (options && options.acl) {
|
|
489
533
|
options.acl = null;
|
|
@@ -592,7 +636,13 @@ class ObjectsInMemoryFileDB extends import_db_base.InMemoryFileDB {
|
|
|
592
636
|
}
|
|
593
637
|
return res;
|
|
594
638
|
}
|
|
595
|
-
|
|
639
|
+
/**
|
|
640
|
+
* Rename a file or directory in an object's file storage (used by the server)
|
|
641
|
+
*
|
|
642
|
+
* @param id The object ID owning the file
|
|
643
|
+
* @param oldName The current file or directory name
|
|
644
|
+
* @param newName The new file or directory name
|
|
645
|
+
*/
|
|
596
646
|
_rename(id, oldName, newName) {
|
|
597
647
|
const _path = import_db_objects_redis.objectsUtils.sanitizePath(id, oldName);
|
|
598
648
|
id = _path.id;
|
|
@@ -622,7 +672,11 @@ class ObjectsInMemoryFileDB extends import_db_base.InMemoryFileDB {
|
|
|
622
672
|
});
|
|
623
673
|
this._saveFileSettings(id, true);
|
|
624
674
|
}
|
|
625
|
-
|
|
675
|
+
/**
|
|
676
|
+
* Create a deep clone of the given object
|
|
677
|
+
*
|
|
678
|
+
* @param obj The object to clone
|
|
679
|
+
*/
|
|
626
680
|
_clone(obj) {
|
|
627
681
|
if (obj === null || obj === void 0 || !import_db_base2.tools.isObject(obj)) {
|
|
628
682
|
return obj;
|
|
@@ -633,18 +687,40 @@ class ObjectsInMemoryFileDB extends import_db_base.InMemoryFileDB {
|
|
|
633
687
|
}
|
|
634
688
|
return temp;
|
|
635
689
|
}
|
|
690
|
+
/**
|
|
691
|
+
* Subscribe a client to meta changes
|
|
692
|
+
*
|
|
693
|
+
* @param client The client to subscribe
|
|
694
|
+
* @param pattern The pattern of meta IDs to subscribe to
|
|
695
|
+
*/
|
|
636
696
|
_subscribeMeta(client, pattern) {
|
|
637
697
|
this.handleSubscribe(client, "meta", pattern);
|
|
638
698
|
}
|
|
639
|
-
|
|
699
|
+
/**
|
|
700
|
+
* Subscribe a client to object changes (used by the server)
|
|
701
|
+
*
|
|
702
|
+
* @param client The client to subscribe
|
|
703
|
+
* @param pattern The pattern of object IDs to subscribe to
|
|
704
|
+
*/
|
|
640
705
|
_subscribeConfigForClient(client, pattern) {
|
|
641
706
|
this.handleSubscribe(client, "objects", pattern);
|
|
642
707
|
}
|
|
643
|
-
|
|
708
|
+
/**
|
|
709
|
+
* Unsubscribe a client from object changes (used by the server)
|
|
710
|
+
*
|
|
711
|
+
* @param client The client to unsubscribe
|
|
712
|
+
* @param pattern The pattern of object IDs to unsubscribe from
|
|
713
|
+
*/
|
|
644
714
|
_unsubscribeConfigForClient(client, pattern) {
|
|
645
715
|
this.handleUnsubscribe(client, "objects", pattern);
|
|
646
716
|
}
|
|
647
|
-
|
|
717
|
+
/**
|
|
718
|
+
* Subscribe a client to file changes of an object (used by the server)
|
|
719
|
+
*
|
|
720
|
+
* @param client The client to subscribe
|
|
721
|
+
* @param id The object ID owning the files
|
|
722
|
+
* @param pattern One or more file name patterns to subscribe to
|
|
723
|
+
*/
|
|
648
724
|
_subscribeFileForClient(client, id, pattern) {
|
|
649
725
|
if (Array.isArray(pattern)) {
|
|
650
726
|
pattern.forEach((pattern2) => this.handleSubscribe(client, "files", `${id}$%$${pattern2}`));
|
|
@@ -652,7 +728,13 @@ class ObjectsInMemoryFileDB extends import_db_base.InMemoryFileDB {
|
|
|
652
728
|
this.handleSubscribe(client, "files", `${id}$%$${pattern}`);
|
|
653
729
|
}
|
|
654
730
|
}
|
|
655
|
-
|
|
731
|
+
/**
|
|
732
|
+
* Unsubscribe a client from file changes of an object (used by the server)
|
|
733
|
+
*
|
|
734
|
+
* @param client The client to unsubscribe
|
|
735
|
+
* @param id The object ID owning the files
|
|
736
|
+
* @param pattern One or more file name patterns to unsubscribe from
|
|
737
|
+
*/
|
|
656
738
|
_unsubscribeFileForClient(client, id, pattern) {
|
|
657
739
|
if (Array.isArray(pattern)) {
|
|
658
740
|
pattern.forEach((pattern2) => this.handleUnsubscribe(client, "files", `${id}$%$${pattern2}`));
|
|
@@ -660,24 +742,39 @@ class ObjectsInMemoryFileDB extends import_db_base.InMemoryFileDB {
|
|
|
660
742
|
this.handleUnsubscribe(client, "files", `${id}$%$${pattern}`);
|
|
661
743
|
}
|
|
662
744
|
}
|
|
663
|
-
|
|
745
|
+
/**
|
|
746
|
+
* Get a single object by its ID (used by the server)
|
|
747
|
+
*
|
|
748
|
+
* @param id The object ID to read
|
|
749
|
+
*/
|
|
664
750
|
_getObject(id) {
|
|
665
751
|
return this.dataset[id];
|
|
666
752
|
}
|
|
667
|
-
|
|
753
|
+
/**
|
|
754
|
+
* Get all object IDs matching the given pattern, sorted (used by the server)
|
|
755
|
+
*
|
|
756
|
+
* @param pattern The pattern to match object IDs against
|
|
757
|
+
*/
|
|
668
758
|
_getKeys(pattern) {
|
|
669
759
|
const r = new RegExp(import_db_base2.tools.pattern2RegEx(pattern));
|
|
670
760
|
const result2 = Object.keys(this.dataset).filter((id) => r.test(id) && id !== this.META_ID);
|
|
671
761
|
result2.sort();
|
|
672
762
|
return result2;
|
|
673
763
|
}
|
|
674
|
-
|
|
764
|
+
/**
|
|
765
|
+
* Get the values of the given object IDs (used by the server)
|
|
766
|
+
*
|
|
767
|
+
* @param keys The object IDs to read
|
|
768
|
+
*/
|
|
675
769
|
_getObjects(keys) {
|
|
676
770
|
if (!keys) {
|
|
677
771
|
throw new Error("no keys");
|
|
678
772
|
}
|
|
679
773
|
return keys.map((id) => this.dataset[id]);
|
|
680
774
|
}
|
|
775
|
+
/**
|
|
776
|
+
* Get the meta dictionary, creating it if it does not exist yet
|
|
777
|
+
*/
|
|
681
778
|
_ensureMetaDict() {
|
|
682
779
|
let meta = this.dataset[this.META_ID];
|
|
683
780
|
if (!meta) {
|
|
@@ -689,8 +786,8 @@ class ObjectsInMemoryFileDB extends import_db_base.InMemoryFileDB {
|
|
|
689
786
|
/**
|
|
690
787
|
* Get value of given meta id
|
|
691
788
|
*
|
|
692
|
-
* @param id
|
|
693
|
-
* @returns
|
|
789
|
+
* @param id The meta ID to read
|
|
790
|
+
* @returns the stored meta value
|
|
694
791
|
*/
|
|
695
792
|
getMeta(id) {
|
|
696
793
|
const meta = this._ensureMetaDict();
|
|
@@ -699,8 +796,8 @@ class ObjectsInMemoryFileDB extends import_db_base.InMemoryFileDB {
|
|
|
699
796
|
/**
|
|
700
797
|
* Sets given value to id in metaNamespace
|
|
701
798
|
*
|
|
702
|
-
* @param id
|
|
703
|
-
* @param value
|
|
799
|
+
* @param id The meta ID to write
|
|
800
|
+
* @param value The value to store
|
|
704
801
|
*/
|
|
705
802
|
setMeta(id, value) {
|
|
706
803
|
const meta = this._ensureMetaDict();
|
|
@@ -714,7 +811,12 @@ class ObjectsInMemoryFileDB extends import_db_base.InMemoryFileDB {
|
|
|
714
811
|
this.stateTimer = setTimeout(() => this.saveState(), this.writeFileInterval);
|
|
715
812
|
}
|
|
716
813
|
}
|
|
717
|
-
|
|
814
|
+
/**
|
|
815
|
+
* Directly set an object value and publish the change (used by the server)
|
|
816
|
+
*
|
|
817
|
+
* @param id The object ID to set
|
|
818
|
+
* @param obj The object to store
|
|
819
|
+
*/
|
|
718
820
|
_setObjectDirect(id, obj) {
|
|
719
821
|
this.dataset[id] = obj;
|
|
720
822
|
if (obj.type === "meta" && this.existingMetaObjects[id] === false) {
|
|
@@ -745,7 +847,12 @@ class ObjectsInMemoryFileDB extends import_db_base.InMemoryFileDB {
|
|
|
745
847
|
this.stateTimer = setTimeout(() => this.saveState(), this.writeFileInterval);
|
|
746
848
|
}
|
|
747
849
|
}
|
|
748
|
-
|
|
850
|
+
/**
|
|
851
|
+
* Apply a view's map function over all objects and collect the matching rows
|
|
852
|
+
*
|
|
853
|
+
* @param func The view definition containing the map function
|
|
854
|
+
* @param params Query parameters such as startkey and endkey
|
|
855
|
+
*/
|
|
749
856
|
_applyView(func, params) {
|
|
750
857
|
const result = {
|
|
751
858
|
rows: []
|
|
@@ -786,7 +893,13 @@ class ObjectsInMemoryFileDB extends import_db_base.InMemoryFileDB {
|
|
|
786
893
|
}
|
|
787
894
|
return result;
|
|
788
895
|
}
|
|
789
|
-
|
|
896
|
+
/**
|
|
897
|
+
* Run a predefined object view (design document) and return the matching rows (used by the server)
|
|
898
|
+
*
|
|
899
|
+
* @param design The design document name
|
|
900
|
+
* @param search The view name within the design document
|
|
901
|
+
* @param params Query parameters such as startkey and endkey
|
|
902
|
+
*/
|
|
790
903
|
_getObjectView(design, search, params2) {
|
|
791
904
|
const designObj = this.dataset[`_design/${design}`];
|
|
792
905
|
if (!designObj) {
|