wingbot-mongodb 2.22.0-alpha.5 → 3.0.0-alpha.8
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 → 38fa2b60-0502-4dbc-9c7f-c478802fb2de.json} +1 -1
- package/.nyc_output/processinfo/38fa2b60-0502-4dbc-9c7f-c478802fb2de.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -1
- package/package.json +3 -3
- package/src/BaseStorage.js +36 -10
- package/src/StateStorage.js +12 -2
- package/.nyc_output/processinfo/1f0c249b-861d-4ebb-a415-267bb18646dd.json +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":null,"pid":52036,"argv":["/usr/local/bin/node","/Users/david/Development/wingbot-mongodb/node_modules/.bin/mocha","./test"],"execArgv":[],"cwd":"/Users/david/Development/wingbot-mongodb","time":1655802879208,"ppid":52035,"coverageFilename":"/Users/david/Development/wingbot-mongodb/.nyc_output/38fa2b60-0502-4dbc-9c7f-c478802fb2de.json","externalId":"","uuid":"38fa2b60-0502-4dbc-9c7f-c478802fb2de","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":{"38fa2b60-0502-4dbc-9c7f-c478802fb2de":{"parent":null,"children":[]}},"files":{"/Users/david/Development/wingbot-mongodb/src/BaseStorage.js":["38fa2b60-0502-4dbc-9c7f-c478802fb2de"],"/Users/david/Development/wingbot-mongodb/src/defaultLogger.js":["38fa2b60-0502-4dbc-9c7f-c478802fb2de"],"/Users/david/Development/wingbot-mongodb/src/AttachmentCache.js":["38fa2b60-0502-4dbc-9c7f-c478802fb2de"],"/Users/david/Development/wingbot-mongodb/src/AuditLogStorage.js":["38fa2b60-0502-4dbc-9c7f-c478802fb2de"],"/Users/david/Development/wingbot-mongodb/src/BotConfigStorage.js":["38fa2b60-0502-4dbc-9c7f-c478802fb2de"],"/Users/david/Development/wingbot-mongodb/src/BotTokenStorage.js":["38fa2b60-0502-4dbc-9c7f-c478802fb2de"],"/Users/david/Development/wingbot-mongodb/src/tokenFactory.js":["38fa2b60-0502-4dbc-9c7f-c478802fb2de"],"/Users/david/Development/wingbot-mongodb/src/ChatLogStorage.js":["38fa2b60-0502-4dbc-9c7f-c478802fb2de"],"/Users/david/Development/wingbot-mongodb/src/NotificationsStorage.js":["38fa2b60-0502-4dbc-9c7f-c478802fb2de"],"/Users/david/Development/wingbot-mongodb/src/StateStorage.js":["38fa2b60-0502-4dbc-9c7f-c478802fb2de"]},"externalIds":{}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wingbot-mongodb",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.8",
|
|
4
4
|
"description": "MongoDB storage for wingbot.ai",
|
|
5
5
|
"main": "src/main.js",
|
|
6
6
|
"scripts": {
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"jsdoc-to-markdown": "^7.1.1",
|
|
46
46
|
"jsdoc-tsimport-plugin": "^1.0.5",
|
|
47
47
|
"mocha": "^9.2.2",
|
|
48
|
-
"mongodb": "^4.
|
|
48
|
+
"mongodb": "^4.7.0",
|
|
49
49
|
"nyc": "^15.1.0",
|
|
50
|
-
"wingbot": "^3.
|
|
50
|
+
"wingbot": "^3.34.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"mongodb": "^4.0.0"
|
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({
|
|
@@ -63,6 +83,16 @@ class BaseStorage {
|
|
|
63
83
|
this.systemIndexes = ['_id_', '_id'];
|
|
64
84
|
|
|
65
85
|
this._fixtures = [];
|
|
86
|
+
|
|
87
|
+
if (isCosmo) {
|
|
88
|
+
process.nextTick(() => {
|
|
89
|
+
const hasUniqueIndex = this._indexes.some((i) => i.options.unique);
|
|
90
|
+
|
|
91
|
+
if (hasUniqueIndex) {
|
|
92
|
+
this._getCollection();
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
66
96
|
}
|
|
67
97
|
|
|
68
98
|
/**
|
|
@@ -108,20 +138,16 @@ class BaseStorage {
|
|
|
108
138
|
|
|
109
139
|
/**
|
|
110
140
|
*
|
|
111
|
-
* @
|
|
112
|
-
* @param {string} attr
|
|
141
|
+
* @param {string|null} attr
|
|
113
142
|
* @param {{[key: string]: any}} obj
|
|
143
|
+
* @param {boolean} [nested]
|
|
114
144
|
* @returns {{[key: string]: any}}
|
|
115
145
|
*/
|
|
116
|
-
_expandObjectToSet (attr, obj) {
|
|
117
|
-
|
|
118
|
-
if (keys.length === 0) {
|
|
146
|
+
_expandObjectToSet (attr, obj, nested = false) {
|
|
147
|
+
if (Object.keys(obj).length === 0) {
|
|
119
148
|
return null;
|
|
120
149
|
}
|
|
121
|
-
return
|
|
122
|
-
.reduce((o, key) => Object.assign(o, {
|
|
123
|
-
[`${attr}.${key}`]: obj[key]
|
|
124
|
-
}), {});
|
|
150
|
+
return getNestedObjects(obj, nested, attr);
|
|
125
151
|
}
|
|
126
152
|
|
|
127
153
|
async _getOrCreateCollection (name) {
|
package/src/StateStorage.js
CHANGED
|
@@ -9,6 +9,7 @@ const defaultLogger = require('./defaultLogger');
|
|
|
9
9
|
const USER_INDEX = 'senderId_1_pageId_1';
|
|
10
10
|
const LAST_INTERACTION_INDEX = 'lastInteraction_1';
|
|
11
11
|
const SEARCH = 'search-text';
|
|
12
|
+
const NAME = 'name_1';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* @typedef {object} State
|
|
@@ -50,7 +51,12 @@ class StateStorage extends BaseStorage {
|
|
|
50
51
|
{ name: LAST_INTERACTION_INDEX }
|
|
51
52
|
);
|
|
52
53
|
|
|
53
|
-
if (
|
|
54
|
+
if (isCosmo) {
|
|
55
|
+
this.addIndex(
|
|
56
|
+
{ name: 1 },
|
|
57
|
+
{ name: NAME }
|
|
58
|
+
);
|
|
59
|
+
} else {
|
|
54
60
|
this.addIndex(
|
|
55
61
|
{ '$**': 'text' },
|
|
56
62
|
{ name: SEARCH }
|
|
@@ -160,8 +166,12 @@ class StateStorage extends BaseStorage {
|
|
|
160
166
|
|
|
161
167
|
if (searchStates) {
|
|
162
168
|
if (this._isCosmo) {
|
|
169
|
+
const $regex = `^${condition.search.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&')}`;
|
|
163
170
|
Object.assign(useCondition, {
|
|
164
|
-
|
|
171
|
+
$or: [
|
|
172
|
+
{ senderId: { $regex } },
|
|
173
|
+
{ name: { $regex } }
|
|
174
|
+
]
|
|
165
175
|
});
|
|
166
176
|
} else {
|
|
167
177
|
Object.assign(useCondition, {
|
|
@@ -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"]}
|