wingbot-mongodb 2.22.0-alpha.5 → 2.22.0-alpha.6
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/.nyc_output/{1f0c249b-861d-4ebb-a415-267bb18646dd.json → 81c4e49f-c93d-4e44-b749-eec4d22cfcf1.json} +1 -1
- package/.nyc_output/processinfo/81c4e49f-c93d-4e44-b749-eec4d22cfcf1.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -1
- package/package.json +1 -1
- package/src/BaseStorage.js +26 -10
- package/.nyc_output/processinfo/1f0c249b-861d-4ebb-a415-267bb18646dd.json +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":null,"pid":85364,"argv":["/usr/local/bin/node","/Users/david/Development/wingbot-mongodb/node_modules/.bin/mocha","./test"],"execArgv":[],"cwd":"/Users/david/Development/wingbot-mongodb","time":1651496192378,"ppid":85363,"coverageFilename":"/Users/david/Development/wingbot-mongodb/.nyc_output/81c4e49f-c93d-4e44-b749-eec4d22cfcf1.json","externalId":"","uuid":"81c4e49f-c93d-4e44-b749-eec4d22cfcf1","files":["/Users/david/Development/wingbot-mongodb/src/BaseStorage.js","/Users/david/Development/wingbot-mongodb/src/defaultLogger.js","/Users/david/Development/wingbot-mongodb/src/AttachmentCache.js","/Users/david/Development/wingbot-mongodb/src/AuditLogStorage.js","/Users/david/Development/wingbot-mongodb/src/BotConfigStorage.js","/Users/david/Development/wingbot-mongodb/src/BotTokenStorage.js","/Users/david/Development/wingbot-mongodb/src/tokenFactory.js","/Users/david/Development/wingbot-mongodb/src/ChatLogStorage.js","/Users/david/Development/wingbot-mongodb/src/NotificationsStorage.js","/Users/david/Development/wingbot-mongodb/src/StateStorage.js"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"processes":{"
|
|
1
|
+
{"processes":{"81c4e49f-c93d-4e44-b749-eec4d22cfcf1":{"parent":null,"children":[]}},"files":{"/Users/david/Development/wingbot-mongodb/src/BaseStorage.js":["81c4e49f-c93d-4e44-b749-eec4d22cfcf1"],"/Users/david/Development/wingbot-mongodb/src/defaultLogger.js":["81c4e49f-c93d-4e44-b749-eec4d22cfcf1"],"/Users/david/Development/wingbot-mongodb/src/AttachmentCache.js":["81c4e49f-c93d-4e44-b749-eec4d22cfcf1"],"/Users/david/Development/wingbot-mongodb/src/AuditLogStorage.js":["81c4e49f-c93d-4e44-b749-eec4d22cfcf1"],"/Users/david/Development/wingbot-mongodb/src/BotConfigStorage.js":["81c4e49f-c93d-4e44-b749-eec4d22cfcf1"],"/Users/david/Development/wingbot-mongodb/src/BotTokenStorage.js":["81c4e49f-c93d-4e44-b749-eec4d22cfcf1"],"/Users/david/Development/wingbot-mongodb/src/tokenFactory.js":["81c4e49f-c93d-4e44-b749-eec4d22cfcf1"],"/Users/david/Development/wingbot-mongodb/src/ChatLogStorage.js":["81c4e49f-c93d-4e44-b749-eec4d22cfcf1"],"/Users/david/Development/wingbot-mongodb/src/NotificationsStorage.js":["81c4e49f-c93d-4e44-b749-eec4d22cfcf1"],"/Users/david/Development/wingbot-mongodb/src/StateStorage.js":["81c4e49f-c93d-4e44-b749-eec4d22cfcf1"]},"externalIds":{}}
|
package/package.json
CHANGED
package/src/BaseStorage.js
CHANGED
|
@@ -11,6 +11,26 @@ const defaultLogger = require('./defaultLogger');
|
|
|
11
11
|
/** @typedef {import('mongodb').Collection} Collection */
|
|
12
12
|
/** @typedef {import('mongodb').CreateIndexesOptions} CreateIndexesOptions */
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param {any} obj
|
|
17
|
+
* @param {boolean} nested
|
|
18
|
+
* @param {string} [attr]
|
|
19
|
+
* @param {object} [ret]
|
|
20
|
+
* @returns {object}
|
|
21
|
+
*/
|
|
22
|
+
function getNestedObjects (obj, nested, attr = null, ret = {}) {
|
|
23
|
+
if (typeof obj !== 'object' || !obj || nested === null || Array.isArray(obj)) {
|
|
24
|
+
Object.assign(ret, { [attr]: obj === undefined ? null : obj });
|
|
25
|
+
} else {
|
|
26
|
+
Object.entries(obj)
|
|
27
|
+
.forEach(([key, val]) => {
|
|
28
|
+
getNestedObjects(val, nested || null, attr ? `${attr}.${key}` : key, ret);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return ret;
|
|
32
|
+
}
|
|
33
|
+
|
|
14
34
|
class BaseStorage {
|
|
15
35
|
|
|
16
36
|
/**
|
|
@@ -25,7 +45,7 @@ class BaseStorage {
|
|
|
25
45
|
*
|
|
26
46
|
* class MyCoolDataStorage extends BaseStorage {
|
|
27
47
|
*
|
|
28
|
-
* constructor (mongoDb, collectionName
|
|
48
|
+
* constructor (mongoDb, collectionName, log = undefined, isCosmo = false) {
|
|
29
49
|
* super(mongoDb, collectionName, log, isCosmo);
|
|
30
50
|
*
|
|
31
51
|
* this.addIndex({
|
|
@@ -108,20 +128,16 @@ class BaseStorage {
|
|
|
108
128
|
|
|
109
129
|
/**
|
|
110
130
|
*
|
|
111
|
-
* @
|
|
112
|
-
* @param {string} attr
|
|
131
|
+
* @param {string|null} attr
|
|
113
132
|
* @param {{[key: string]: any}} obj
|
|
133
|
+
* @param {boolean} [nested]
|
|
114
134
|
* @returns {{[key: string]: any}}
|
|
115
135
|
*/
|
|
116
|
-
_expandObjectToSet (attr, obj) {
|
|
117
|
-
|
|
118
|
-
if (keys.length === 0) {
|
|
136
|
+
_expandObjectToSet (attr, obj, nested = false) {
|
|
137
|
+
if (Object.keys(obj).length === 0) {
|
|
119
138
|
return null;
|
|
120
139
|
}
|
|
121
|
-
return
|
|
122
|
-
.reduce((o, key) => Object.assign(o, {
|
|
123
|
-
[`${attr}.${key}`]: obj[key]
|
|
124
|
-
}), {});
|
|
140
|
+
return getNestedObjects(obj, nested, attr);
|
|
125
141
|
}
|
|
126
142
|
|
|
127
143
|
async _getOrCreateCollection (name) {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"parent":null,"pid":83585,"argv":["/usr/local/bin/node","/Users/david/Development/wingbot-mongodb/node_modules/.bin/mocha","./test"],"execArgv":[],"cwd":"/Users/david/Development/wingbot-mongodb","time":1650546848107,"ppid":83584,"coverageFilename":"/Users/david/Development/wingbot-mongodb/.nyc_output/1f0c249b-861d-4ebb-a415-267bb18646dd.json","externalId":"","uuid":"1f0c249b-861d-4ebb-a415-267bb18646dd","files":["/Users/david/Development/wingbot-mongodb/src/AttachmentCache.js","/Users/david/Development/wingbot-mongodb/src/AuditLogStorage.js","/Users/david/Development/wingbot-mongodb/src/BaseStorage.js","/Users/david/Development/wingbot-mongodb/src/defaultLogger.js","/Users/david/Development/wingbot-mongodb/src/BotConfigStorage.js","/Users/david/Development/wingbot-mongodb/src/BotTokenStorage.js","/Users/david/Development/wingbot-mongodb/src/tokenFactory.js","/Users/david/Development/wingbot-mongodb/src/ChatLogStorage.js","/Users/david/Development/wingbot-mongodb/src/NotificationsStorage.js","/Users/david/Development/wingbot-mongodb/src/StateStorage.js"]}
|