wingbot-mongodb 2.19.1 → 2.20.0
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/aa11686d-390e-407a-a6db-ecee5afa6347.json +1 -0
- package/.nyc_output/processinfo/{8e3ceac5-95c5-4bf9-a069-da51cccc2525.json → aa11686d-390e-407a-a6db-ecee5afa6347.json} +1 -1
- package/.nyc_output/processinfo/index.json +1 -1
- package/package.json +1 -1
- package/src/BaseStorage.js +33 -4
- package/src/StateStorage.js +1 -1
- package/.nyc_output/8e3ceac5-95c5-4bf9-a069-da51cccc2525.json +0 -1
package/package.json
CHANGED
package/src/BaseStorage.js
CHANGED
|
@@ -57,6 +57,19 @@ class BaseStorage {
|
|
|
57
57
|
|
|
58
58
|
this.ignoredSignatureKeys = ['_id', 'sign'];
|
|
59
59
|
this._secret = null;
|
|
60
|
+
|
|
61
|
+
this.systemIndexes = ['_id_', '_id'];
|
|
62
|
+
|
|
63
|
+
this._fixtures = [];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Insert defalt document to DB
|
|
68
|
+
*
|
|
69
|
+
* @param {...any} objects
|
|
70
|
+
*/
|
|
71
|
+
addFixtureDoc (...objects) {
|
|
72
|
+
this._fixtures.push(...objects);
|
|
60
73
|
}
|
|
61
74
|
|
|
62
75
|
/**
|
|
@@ -83,6 +96,7 @@ class BaseStorage {
|
|
|
83
96
|
let collection;
|
|
84
97
|
|
|
85
98
|
if (this._isCosmo) {
|
|
99
|
+
// @ts-ignore
|
|
86
100
|
const collections = await db.collections();
|
|
87
101
|
|
|
88
102
|
collection = collections
|
|
@@ -134,7 +148,7 @@ class BaseStorage {
|
|
|
134
148
|
}
|
|
135
149
|
|
|
136
150
|
await existing
|
|
137
|
-
.filter((e) => !
|
|
151
|
+
.filter((e) => !this.systemIndexes.includes(e.name)
|
|
138
152
|
&& !indexes.some((i) => e.name === i.options.name))
|
|
139
153
|
.reduce((p, e) => {
|
|
140
154
|
// eslint-disable-next-line no-console
|
|
@@ -147,7 +161,7 @@ class BaseStorage {
|
|
|
147
161
|
});
|
|
148
162
|
}, Promise.resolve());
|
|
149
163
|
|
|
150
|
-
await indexes
|
|
164
|
+
const updated = await indexes
|
|
151
165
|
.filter((i) => !existing.some((e) => e.name === i.options.name))
|
|
152
166
|
.reduce((p, i) => {
|
|
153
167
|
this._log.log(`creating index ${i.name}`);
|
|
@@ -155,8 +169,23 @@ class BaseStorage {
|
|
|
155
169
|
.then(() => collection.createIndex(i.index, i.options))
|
|
156
170
|
.catch((e) => {
|
|
157
171
|
this._log.error(`failed to create index ${i.options.name} on ${collection.collectionName}`, e);
|
|
158
|
-
})
|
|
159
|
-
|
|
172
|
+
})
|
|
173
|
+
.then(() => true);
|
|
174
|
+
}, Promise.resolve(false));
|
|
175
|
+
|
|
176
|
+
if (updated || existing.every((i) => this.systemIndexes.includes(i.name))) {
|
|
177
|
+
// upsert fixtures
|
|
178
|
+
|
|
179
|
+
await this._fixtures.reduce((p, o) => p
|
|
180
|
+
.then(() => collection.insertOne(o))
|
|
181
|
+
.then(() => this._log.log(`DB> Inserted fixture doc to "${this._collectionName}"`))
|
|
182
|
+
.catch((e) => {
|
|
183
|
+
if (e.code !== 11000) {
|
|
184
|
+
this._log.error(`DB> failed to insert fixture doc to "${this._collectionName}"`, e);
|
|
185
|
+
}
|
|
186
|
+
}),
|
|
187
|
+
Promise.resolve());
|
|
188
|
+
}
|
|
160
189
|
}
|
|
161
190
|
|
|
162
191
|
async _sign (object) {
|
package/src/StateStorage.js
CHANGED
|
@@ -36,7 +36,7 @@ class StateStorage extends BaseStorage {
|
|
|
36
36
|
* @param {{error:Function,log:Function}} [log] - console like logger
|
|
37
37
|
* @param {boolean} isCosmo
|
|
38
38
|
*/
|
|
39
|
-
constructor (mongoDb, collectionName = '
|
|
39
|
+
constructor (mongoDb, collectionName = 'states', log = console, isCosmo = false) {
|
|
40
40
|
super(mongoDb, collectionName, log, isCosmo);
|
|
41
41
|
|
|
42
42
|
this.addIndex(
|