wingbot-mongodb 3.2.2 → 3.2.4

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.
@@ -0,0 +1 @@
1
+ {"parent":null,"pid":4692,"argv":["/usr/local/bin/node","/Users/david/Development/wingbot-mongodb/node_modules/.bin/mocha","./test"],"execArgv":[],"cwd":"/Users/david/Development/wingbot-mongodb","time":1681800952490,"ppid":4686,"coverageFilename":"/Users/david/Development/wingbot-mongodb/.nyc_output/8db620e2-5deb-4db5-b239-32d4e6eb824a.json","externalId":"","uuid":"8db620e2-5deb-4db5-b239-32d4e6eb824a","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":{"98a862df-b2a1-4d14-9176-6b0bada108f7":{"parent":null,"children":[]}},"files":{"/Users/david/Development/wingbot-mongodb/src/BaseStorage.js":["98a862df-b2a1-4d14-9176-6b0bada108f7"],"/Users/david/Development/wingbot-mongodb/src/defaultLogger.js":["98a862df-b2a1-4d14-9176-6b0bada108f7"],"/Users/david/Development/wingbot-mongodb/src/AttachmentCache.js":["98a862df-b2a1-4d14-9176-6b0bada108f7"],"/Users/david/Development/wingbot-mongodb/src/AuditLogStorage.js":["98a862df-b2a1-4d14-9176-6b0bada108f7"],"/Users/david/Development/wingbot-mongodb/src/BotConfigStorage.js":["98a862df-b2a1-4d14-9176-6b0bada108f7"],"/Users/david/Development/wingbot-mongodb/src/BotTokenStorage.js":["98a862df-b2a1-4d14-9176-6b0bada108f7"],"/Users/david/Development/wingbot-mongodb/src/tokenFactory.js":["98a862df-b2a1-4d14-9176-6b0bada108f7"],"/Users/david/Development/wingbot-mongodb/src/ChatLogStorage.js":["98a862df-b2a1-4d14-9176-6b0bada108f7"],"/Users/david/Development/wingbot-mongodb/src/NotificationsStorage.js":["98a862df-b2a1-4d14-9176-6b0bada108f7"],"/Users/david/Development/wingbot-mongodb/src/StateStorage.js":["98a862df-b2a1-4d14-9176-6b0bada108f7"]},"externalIds":{}}
1
+ {"processes":{"8db620e2-5deb-4db5-b239-32d4e6eb824a":{"parent":null,"children":[]}},"files":{"/Users/david/Development/wingbot-mongodb/src/BaseStorage.js":["8db620e2-5deb-4db5-b239-32d4e6eb824a"],"/Users/david/Development/wingbot-mongodb/src/defaultLogger.js":["8db620e2-5deb-4db5-b239-32d4e6eb824a"],"/Users/david/Development/wingbot-mongodb/src/AttachmentCache.js":["8db620e2-5deb-4db5-b239-32d4e6eb824a"],"/Users/david/Development/wingbot-mongodb/src/AuditLogStorage.js":["8db620e2-5deb-4db5-b239-32d4e6eb824a"],"/Users/david/Development/wingbot-mongodb/src/BotConfigStorage.js":["8db620e2-5deb-4db5-b239-32d4e6eb824a"],"/Users/david/Development/wingbot-mongodb/src/BotTokenStorage.js":["8db620e2-5deb-4db5-b239-32d4e6eb824a"],"/Users/david/Development/wingbot-mongodb/src/tokenFactory.js":["8db620e2-5deb-4db5-b239-32d4e6eb824a"],"/Users/david/Development/wingbot-mongodb/src/ChatLogStorage.js":["8db620e2-5deb-4db5-b239-32d4e6eb824a"],"/Users/david/Development/wingbot-mongodb/src/NotificationsStorage.js":["8db620e2-5deb-4db5-b239-32d4e6eb824a"],"/Users/david/Development/wingbot-mongodb/src/StateStorage.js":["8db620e2-5deb-4db5-b239-32d4e6eb824a"]},"externalIds":{}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wingbot-mongodb",
3
- "version": "3.2.2",
3
+ "version": "3.2.4",
4
4
  "description": "MongoDB storage for wingbot.ai",
5
5
  "main": "src/main.js",
6
6
  "scripts": {
@@ -270,6 +270,12 @@ class BaseStorage {
270
270
  return this._collection;
271
271
  }
272
272
 
273
+ /**
274
+ *
275
+ * @param {object[]} indexes
276
+ * @param {Collection} collection
277
+ * @returns {Promise}
278
+ */
273
279
  async _ensureIndexes (indexes, collection) {
274
280
  let existing;
275
281
  try {
@@ -290,7 +296,7 @@ class BaseStorage {
290
296
  });
291
297
  }, Promise.resolve());
292
298
 
293
- const updated = await indexes
299
+ let updated = await indexes
294
300
  .filter((i) => !existing.some((e) => e.name === i.options.name))
295
301
  .reduce((p, i) => {
296
302
  this._log.log(`DB.${this._collectionName} creating index ${i.options.name}`);
@@ -302,21 +308,47 @@ class BaseStorage {
302
308
  .then(() => true);
303
309
  }, Promise.resolve(false));
304
310
 
305
- if (updated || existing.every((i) => this.systemIndexes.includes(i.name))) {
306
- // upsert fixtures
311
+ if (!updated) {
312
+ updated = existing.every((i) => this.systemIndexes.includes(i.name));
313
+ }
307
314
 
308
- await this._fixtures.reduce(
309
- (p, o) => p
310
- .then(() => collection.insertOne(o))
311
- .then(() => this._log.log(`DB.${this._collectionName} Inserted fixture doc to "${this._collectionName}"`))
312
- .catch((e) => {
313
- if (e.code !== 11000) {
314
- this._log.error(`DB.${this._collectionName} failed to insert fixture doc to "${this._collectionName}"`, e);
315
- }
316
- }),
317
- Promise.resolve()
318
- );
315
+ let fixtures = this._fixtures;
316
+
317
+ const $in = fixtures
318
+ .map((f) => f._id)
319
+ .filter((f) => !!f);
320
+
321
+ if (!updated && $in.length !== 0) {
322
+ const found = await collection
323
+ .find({ _id: { $in } })
324
+ .project({ _id: 1 })
325
+ .map((doc) => doc._id.toString())
326
+ .toArray();
327
+
328
+ if (found.length !== $in.length) {
329
+ updated = true;
330
+ fixtures = fixtures
331
+ .filter((f) => !f._id || !found.includes(f._id.toString()));
332
+ }
319
333
  }
334
+
335
+ if (!updated || fixtures.length === 0) {
336
+ return;
337
+ }
338
+
339
+ await fixtures.reduce(
340
+ (p, o) => p
341
+ .then(() => collection.insertOne(o))
342
+ .then(() => this._log.log(`DB.${this._collectionName} Inserted fixture doc to "${this._collectionName}"`))
343
+ .catch((e) => {
344
+ if (e.code === 11000) {
345
+ this._log.log(`DB.${this._collectionName} fixture not inserted: ${e.message}`);
346
+ } else {
347
+ this._log.error(`DB.${this._collectionName} failed to insert fixture doc to "${this._collectionName}"`, e);
348
+ }
349
+ }),
350
+ Promise.resolve()
351
+ );
320
352
  }
321
353
 
322
354
  /**
@@ -1 +0,0 @@
1
- {"parent":null,"pid":81134,"argv":["/usr/local/bin/node","/Users/david/Development/wingbot-mongodb/node_modules/.bin/mocha","./test"],"execArgv":[],"cwd":"/Users/david/Development/wingbot-mongodb","time":1676533760202,"ppid":81133,"coverageFilename":"/Users/david/Development/wingbot-mongodb/.nyc_output/98a862df-b2a1-4d14-9176-6b0bada108f7.json","externalId":"","uuid":"98a862df-b2a1-4d14-9176-6b0bada108f7","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"]}