wingbot-mongodb 2.21.1 → 2.22.0-alpha.2

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/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "wingbot-mongodb",
3
- "version": "2.21.1",
3
+ "version": "2.22.0-alpha.2",
4
4
  "description": "MongoDB storage for wingbot.ai",
5
5
  "main": "src/main.js",
6
6
  "scripts": {
7
7
  "test": "npm run test:lint && npm run test:coverage && npm run test:coverage:threshold",
8
- "test:unit": "mocha ./test/**/*.test.js",
8
+ "test:unit": "mocha ./test/**/*.js",
9
9
  "test:unit:watch": "npm run test:unit -- --watch",
10
10
  "test:cosmos": "cross-env DB_TYPE=cosmos mocha ./test",
11
11
  "test:coverage": "nyc --reporter=html mocha ./test && nyc report",
@@ -45,12 +45,12 @@
45
45
  "jsdoc-to-markdown": "^7.1.1",
46
46
  "jsdoc-tsimport-plugin": "^1.0.5",
47
47
  "mocha": "^9.2.2",
48
- "mongodb": "^3.7.3",
48
+ "mongodb": "^4.5.0",
49
49
  "nyc": "^15.1.0",
50
- "wingbot": "^3.30.0"
50
+ "wingbot": "^3.30.2"
51
51
  },
52
52
  "peerDependencies": {
53
- "mongodb": "^3.0.0"
53
+ "mongodb": "^4.0.0"
54
54
  },
55
55
  "optionalDependencies": {
56
56
  "wingbot": "^3.0.0"
@@ -3,7 +3,8 @@
3
3
  */
4
4
  'use strict';
5
5
 
6
- const mongodb = require('mongodb'); // eslint-disable-line no-unused-vars
6
+ /** @typedef {import('mongodb').Db} Db */
7
+ /** @typedef {import('mongodb').Collection} Collection */
7
8
 
8
9
  /**
9
10
  * Cache storage for Facebook attachments
@@ -14,7 +15,7 @@ class AttachmentCache {
14
15
 
15
16
  /**
16
17
  *
17
- * @param {mongodb.Db|{():Promise<mongodb.Db>}} mongoDb
18
+ * @param {Db|{():Promise<Db>}} mongoDb
18
19
  * @param {string} collectionName
19
20
  */
20
21
  constructor (mongoDb, collectionName = 'attachments') {
@@ -22,13 +23,13 @@ class AttachmentCache {
22
23
  this._collectionName = collectionName;
23
24
 
24
25
  /**
25
- * @type {mongodb.Collection}
26
+ * @type {Collection}
26
27
  */
27
28
  this._collection = null;
28
29
  }
29
30
 
30
31
  /**
31
- * @returns {Promise<mongodb.Collection>}
32
+ * @returns {Promise<Collection>}
32
33
  */
33
34
  async _getCollection () {
34
35
  if (this._collection === null) {
@@ -6,8 +6,6 @@
6
6
  const jsonwebtoken = require('jsonwebtoken');
7
7
  const BaseStorage = require('./BaseStorage');
8
8
 
9
- /** @typedef {import('mongodb/lib/db')} Db */
10
-
11
9
  const LEVEL_CRITICAL = 'Critical';
12
10
  const LEVEL_IMPORTANT = 'Important';
13
11
  const LEVEL_DEBUG = 'Debug';
@@ -91,6 +89,9 @@ const TYPE_INFO = 'Info';
91
89
  * @returns {Promise}
92
90
  */
93
91
 
92
+ /** @typedef {import('mongodb').Db} Db */
93
+ /** @typedef {import('mongodb').Collection} Collection */
94
+
94
95
  /**
95
96
  * Storage for audit logs with signatures chain
96
97
  */
@@ -6,8 +6,9 @@
6
6
  const mongodb = require('mongodb'); // eslint-disable-line no-unused-vars
7
7
  const crypto = require('crypto');
8
8
 
9
- /** @typedef {import('mongodb/lib/db')} Db */
10
- /** @typedef {import('mongodb/lib/collection')} Collection */
9
+ /** @typedef {import('mongodb').Db} Db */
10
+ /** @typedef {import('mongodb').Collection} Collection */
11
+ /** @typedef {import('mongodb').CreateIndexesOptions} CreateIndexesOptions */
11
12
 
12
13
  class BaseStorage {
13
14
 
@@ -76,7 +77,7 @@ class BaseStorage {
76
77
  * Add custom indexing rule
77
78
  *
78
79
  * @param {object} index
79
- * @param {mongodb.IndexOptions} options
80
+ * @param {CreateIndexesOptions} options
80
81
  */
81
82
  addIndex (index, options) {
82
83
  if (!options.name) {
@@ -209,7 +210,7 @@ class BaseStorage {
209
210
 
210
211
  /**
211
212
  *
212
- * @private
213
+ * @protected
213
214
  * @template T
214
215
  * @param {T} object
215
216
  * @returns {T}
@@ -11,8 +11,8 @@ try {
11
11
  // noop
12
12
  }
13
13
 
14
- /** @typedef {import('mongodb/lib/db')} Db */
15
- /** @typedef {import('mongodb/lib/collection')} Collection */
14
+ /** @typedef {import('mongodb').Db} Db */
15
+ /** @typedef {import('mongodb').Collection} Collection */
16
16
 
17
17
  const CONFIG_ID = 'config';
18
18
 
@@ -3,7 +3,6 @@
3
3
  */
4
4
  'use strict';
5
5
 
6
- const mongodb = require('mongodb'); // eslint-disable-line no-unused-vars
7
6
  const tokenFactory = require('./tokenFactory');
8
7
 
9
8
  const TOKEN_INDEX = 'token-index';
@@ -16,6 +15,9 @@ const USER_INDEX = 'user-page-index';
16
15
  * @prop {string} token
17
16
  */
18
17
 
18
+ /** @typedef {import('mongodb').Db} Db */
19
+ /** @typedef {import('mongodb').Collection} Collection */
20
+
19
21
  /**
20
22
  * Storage for webview tokens
21
23
  *
@@ -25,7 +27,7 @@ class BotTokenStorage {
25
27
 
26
28
  /**
27
29
  *
28
- * @param {mongodb.Db|{():Promise<mongodb.Db>}} mongoDb
30
+ * @param {Db|{():Promise<Db>}} mongoDb
29
31
  * @param {string} collectionName
30
32
  */
31
33
  constructor (mongoDb, collectionName = 'tokens') {
@@ -33,13 +35,13 @@ class BotTokenStorage {
33
35
  this._collectionName = collectionName;
34
36
 
35
37
  /**
36
- * @type {mongodb.Collection}
38
+ * @type {Collection}
37
39
  */
38
40
  this._collection = null;
39
41
  }
40
42
 
41
43
  /**
42
- * @returns {Promise<mongodb.Collection>}
44
+ * @returns {Promise<Collection>}
43
45
  */
44
46
  async _getCollection () {
45
47
  if (this._collection === null) {
@@ -60,8 +62,7 @@ class BotTokenStorage {
60
62
  token: 1
61
63
  }, {
62
64
  unique: true,
63
- name: TOKEN_INDEX,
64
- dropDups: true
65
+ name: TOKEN_INDEX
65
66
  });
66
67
  }
67
68
  try {
@@ -75,8 +76,7 @@ class BotTokenStorage {
75
76
  pageId: 1
76
77
  }, {
77
78
  unique: true,
78
- name: USER_INDEX,
79
- dropDups: true
79
+ name: USER_INDEX
80
80
  });
81
81
  }
82
82
  }
@@ -8,7 +8,7 @@ const BaseStorage = require('./BaseStorage');
8
8
  const PAGE_SENDER_TIMESTAMP = 'pageId_1_senderId_1_timestamp_-1';
9
9
  const TIMESTAMP = 'timestamp_1';
10
10
 
11
- /** @typedef {import('mongodb/lib/db')} Db */
11
+ /** @typedef {import('mongodb').Db} Db */
12
12
 
13
13
  /**
14
14
  * Storage for conversation logs
@@ -793,7 +793,13 @@ class NotificationsStorage {
793
793
  update: { $addToSet: { subs: tag } },
794
794
  upsert: !onlyToKnown
795
795
  }
796
- }))
796
+ })),
797
+ {
798
+ ordered: false,
799
+ writeConcern: {
800
+ w: onlyToKnown ? 0 : 1
801
+ }
802
+ }
797
803
  );
798
804
  }
799
805
 
@@ -3,7 +3,6 @@
3
3
  */
4
4
  'use strict';
5
5
 
6
- const mongodb = require('mongodb'); // eslint-disable-line no-unused-vars
7
6
  const BaseStorage = require('./BaseStorage');
8
7
 
9
8
  const USER_INDEX = 'senderId_1_pageId_1';
@@ -22,6 +21,8 @@ const SEARCH = 'search-text';
22
21
  * @prop {string} [search]
23
22
  */
24
23
 
24
+ /** @typedef {import('mongodb').Db} Db */
25
+
25
26
  /**
26
27
  * Storage for chat states
27
28
  *
@@ -31,7 +32,7 @@ class StateStorage extends BaseStorage {
31
32
 
32
33
  /**
33
34
  *
34
- * @param {mongodb.Db|{():Promise<mongodb.Db>}} mongoDb
35
+ * @param {Db|{():Promise<Db>}} mongoDb
35
36
  * @param {string} collectionName
36
37
  * @param {{error:Function,log:Function}} [log] - console like logger
37
38
  * @param {boolean} isCosmo
@@ -41,7 +42,7 @@ class StateStorage extends BaseStorage {
41
42
 
42
43
  this.addIndex(
43
44
  { senderId: 1, pageId: 1 },
44
- { name: USER_INDEX, unique: true, dropDups: true }
45
+ { name: USER_INDEX, unique: true }
45
46
  );
46
47
  this.addIndex(
47
48
  { lastInteraction: isCosmo ? 1 : -1 },
@@ -77,7 +78,9 @@ class StateStorage extends BaseStorage {
77
78
  */
78
79
  async getState (senderId, pageId) {
79
80
  const c = await this._getCollection();
80
- return c.findOne({ senderId, pageId }, { projection: { _id: 0 } });
81
+ const doc = await c.findOne({ senderId, pageId }, { projection: { _id: 0 } });
82
+ // @ts-ignore
83
+ return doc;
81
84
  }
82
85
 
83
86
  /**