wingbot-mongodb 2.22.0-alpha.6 → 3.0.0-alpha.10

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.
@@ -1 +1 @@
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":{}}
1
+ {"processes":{"feb4a098-7fff-42f7-b475-9771b6201741":{"parent":null,"children":[]}},"files":{"/Users/david/Development/wingbot-mongodb/src/AttachmentCache.js":["feb4a098-7fff-42f7-b475-9771b6201741"],"/Users/david/Development/wingbot-mongodb/src/AuditLogStorage.js":["feb4a098-7fff-42f7-b475-9771b6201741"],"/Users/david/Development/wingbot-mongodb/src/BaseStorage.js":["feb4a098-7fff-42f7-b475-9771b6201741"],"/Users/david/Development/wingbot-mongodb/src/BotConfigStorage.js":["feb4a098-7fff-42f7-b475-9771b6201741"],"/Users/david/Development/wingbot-mongodb/src/BotTokenStorage.js":["feb4a098-7fff-42f7-b475-9771b6201741"],"/Users/david/Development/wingbot-mongodb/src/tokenFactory.js":["feb4a098-7fff-42f7-b475-9771b6201741"],"/Users/david/Development/wingbot-mongodb/src/ChatLogStorage.js":["feb4a098-7fff-42f7-b475-9771b6201741"],"/Users/david/Development/wingbot-mongodb/src/NotificationsStorage.js":["feb4a098-7fff-42f7-b475-9771b6201741"],"/Users/david/Development/wingbot-mongodb/src/StateStorage.js":["feb4a098-7fff-42f7-b475-9771b6201741"]},"externalIds":{}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wingbot-mongodb",
3
- "version": "2.22.0-alpha.6",
3
+ "version": "3.0.0-alpha.10",
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.5.0",
48
+ "mongodb": "^4.7.0",
49
49
  "nyc": "^15.1.0",
50
- "wingbot": "^3.30.2"
50
+ "wingbot": "^3.34.0"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "mongodb": "^4.0.0"
@@ -83,6 +83,17 @@ class BaseStorage {
83
83
  this.systemIndexes = ['_id_', '_id'];
84
84
 
85
85
  this._fixtures = [];
86
+
87
+ if (isCosmo && !process.argv.some((a) => a.endsWith('mocha'))) {
88
+ process.nextTick(() => {
89
+ const hasUniqueIndex = this._indexes.some((i) => i.options.unique);
90
+
91
+ if (hasUniqueIndex) {
92
+ this._getCollection()
93
+ .catch((e) => log.error(`DB.${this._collectionName} index pre-heat FAILED`, e));
94
+ }
95
+ });
96
+ }
86
97
  }
87
98
 
88
99
  /**
@@ -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 (!isCosmo) {
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
- name: { $regex: condition.search, $options: 'i' }
171
+ $or: [
172
+ { senderId: { $regex } },
173
+ { name: { $regex } }
174
+ ]
165
175
  });
166
176
  } else {
167
177
  Object.assign(useCondition, {