wingbot-mongodb
Advanced tools
Comparing version 2.19.1 to 2.20.0
@@ -1,1 +0,1 @@ | ||
{"processes":{"8e3ceac5-95c5-4bf9-a069-da51cccc2525":{"parent":null,"children":[]}},"files":{"/Users/david/Downloads/wingbot-mongodb/src/AttachmentCache.js":["8e3ceac5-95c5-4bf9-a069-da51cccc2525"],"/Users/david/Downloads/wingbot-mongodb/src/AuditLogStorage.js":["8e3ceac5-95c5-4bf9-a069-da51cccc2525"],"/Users/david/Downloads/wingbot-mongodb/src/BaseStorage.js":["8e3ceac5-95c5-4bf9-a069-da51cccc2525"],"/Users/david/Downloads/wingbot-mongodb/src/BotConfigStorage.js":["8e3ceac5-95c5-4bf9-a069-da51cccc2525"],"/Users/david/Downloads/wingbot-mongodb/src/BotTokenStorage.js":["8e3ceac5-95c5-4bf9-a069-da51cccc2525"],"/Users/david/Downloads/wingbot-mongodb/src/tokenFactory.js":["8e3ceac5-95c5-4bf9-a069-da51cccc2525"],"/Users/david/Downloads/wingbot-mongodb/src/ChatLogStorage.js":["8e3ceac5-95c5-4bf9-a069-da51cccc2525"],"/Users/david/Downloads/wingbot-mongodb/src/NotificationsStorage.js":["8e3ceac5-95c5-4bf9-a069-da51cccc2525"],"/Users/david/Downloads/wingbot-mongodb/src/StateStorage.js":["8e3ceac5-95c5-4bf9-a069-da51cccc2525"]},"externalIds":{}} | ||
{"processes":{"aa11686d-390e-407a-a6db-ecee5afa6347":{"parent":null,"children":[]}},"files":{"/Users/david/Downloads/wingbot-mongodb/src/AttachmentCache.js":["aa11686d-390e-407a-a6db-ecee5afa6347"],"/Users/david/Downloads/wingbot-mongodb/src/AuditLogStorage.js":["aa11686d-390e-407a-a6db-ecee5afa6347"],"/Users/david/Downloads/wingbot-mongodb/src/BaseStorage.js":["aa11686d-390e-407a-a6db-ecee5afa6347"],"/Users/david/Downloads/wingbot-mongodb/src/BotConfigStorage.js":["aa11686d-390e-407a-a6db-ecee5afa6347"],"/Users/david/Downloads/wingbot-mongodb/src/BotTokenStorage.js":["aa11686d-390e-407a-a6db-ecee5afa6347"],"/Users/david/Downloads/wingbot-mongodb/src/tokenFactory.js":["aa11686d-390e-407a-a6db-ecee5afa6347"],"/Users/david/Downloads/wingbot-mongodb/src/ChatLogStorage.js":["aa11686d-390e-407a-a6db-ecee5afa6347"],"/Users/david/Downloads/wingbot-mongodb/src/NotificationsStorage.js":["aa11686d-390e-407a-a6db-ecee5afa6347"],"/Users/david/Downloads/wingbot-mongodb/src/StateStorage.js":["aa11686d-390e-407a-a6db-ecee5afa6347"]},"externalIds":{}} |
{ | ||
"name": "wingbot-mongodb", | ||
"version": "2.19.1", | ||
"version": "2.20.0", | ||
"description": "MongoDB storage for wingbot.ai", | ||
@@ -5,0 +5,0 @@ "main": "src/main.js", |
@@ -60,5 +60,18 @@ /** | ||
this._secret = null; | ||
this.systemIndexes = ['_id_', '_id']; | ||
this._fixtures = []; | ||
} | ||
/** | ||
* Insert defalt document to DB | ||
* | ||
* @param {...any} objects | ||
*/ | ||
addFixtureDoc (...objects) { | ||
this._fixtures.push(...objects); | ||
} | ||
/** | ||
* Add custom indexing rule | ||
@@ -87,2 +100,3 @@ * | ||
if (this._isCosmo) { | ||
// @ts-ignore | ||
const collections = await db.collections(); | ||
@@ -139,3 +153,3 @@ | ||
await existing | ||
.filter((e) => !['_id_', '_id'].includes(e.name) | ||
.filter((e) => !this.systemIndexes.includes(e.name) | ||
&& !indexes.some((i) => e.name === i.options.name)) | ||
@@ -153,3 +167,3 @@ .reduce((p, e) => { | ||
await indexes | ||
const updated = await indexes | ||
.filter((i) => !existing.some((e) => e.name === i.options.name)) | ||
@@ -162,4 +176,19 @@ .reduce((p, i) => { | ||
this._log.error(`failed to create index ${i.options.name} on ${collection.collectionName}`, e); | ||
}); | ||
}, Promise.resolve()); | ||
}) | ||
.then(() => true); | ||
}, Promise.resolve(false)); | ||
if (updated || existing.every((i) => this.systemIndexes.includes(i.name))) { | ||
// upsert fixtures | ||
await this._fixtures.reduce((p, o) => p | ||
.then(() => collection.insertOne(o)) | ||
.then(() => this._log.log(`DB> Inserted fixture doc to "${this._collectionName}"`)) | ||
.catch((e) => { | ||
if (e.code !== 11000) { | ||
this._log.error(`DB> failed to insert fixture doc to "${this._collectionName}"`, e); | ||
} | ||
}), | ||
Promise.resolve()); | ||
} | ||
} | ||
@@ -166,0 +195,0 @@ |
@@ -39,3 +39,3 @@ /* | ||
*/ | ||
constructor (mongoDb, collectionName = 'chatlogs', log = console, isCosmo = false) { | ||
constructor (mongoDb, collectionName = 'states', log = console, isCosmo = false) { | ||
super(mongoDb, collectionName, log, isCosmo); | ||
@@ -42,0 +42,0 @@ |
227771
2115