wingbot-mongodb 4.2.5 → 4.2.6
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/.github/workflows/test.yml +2 -2
- package/baseStorage.d.ts +23 -4
- package/package.json +1 -1
- package/src/BaseStorage.js +6 -7
|
@@ -19,7 +19,7 @@ jobs:
|
|
|
19
19
|
|
|
20
20
|
strategy:
|
|
21
21
|
matrix:
|
|
22
|
-
node-version: [
|
|
22
|
+
node-version: [20.x]
|
|
23
23
|
|
|
24
24
|
steps:
|
|
25
25
|
|
|
@@ -27,7 +27,7 @@ jobs:
|
|
|
27
27
|
uses: actions/checkout@v2
|
|
28
28
|
|
|
29
29
|
- name: Node.js ${{ matrix.node-version }} setup
|
|
30
|
-
uses: actions/setup-node@
|
|
30
|
+
uses: actions/setup-node@v4
|
|
31
31
|
with:
|
|
32
32
|
node-version: ${{ matrix.node-version }}
|
|
33
33
|
cache: 'npm'
|
package/baseStorage.d.ts
CHANGED
|
@@ -6,26 +6,45 @@ declare namespace wingbotmongodb {
|
|
|
6
6
|
type Db = import('mongodb').Db;
|
|
7
7
|
type CreateIndexesOptions = import('mongodb').CreateIndexesOptions;
|
|
8
8
|
type ObjectId = import('mongodb').ObjectId;
|
|
9
|
+
export interface Logger {
|
|
10
|
+
log: {(...any): void}
|
|
11
|
+
error: {(...any): void}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type WithId<T extends object> = T & { _id: ObjectId };
|
|
9
15
|
|
|
10
16
|
export class BaseStorage<T = {}> {
|
|
11
17
|
|
|
12
|
-
constructor (
|
|
18
|
+
constructor (
|
|
19
|
+
mongoDb: Db|{():Promise<Db>},
|
|
20
|
+
collectionName: string,
|
|
21
|
+
log?: Logger,
|
|
22
|
+
isCosmo?: boolean
|
|
23
|
+
)
|
|
13
24
|
|
|
14
|
-
_getCollection (forRead?: boolean): Promise<Collection<T
|
|
25
|
+
_getCollection (forRead?: boolean): Promise<Collection<WithId<T>>>
|
|
15
26
|
|
|
16
|
-
public addFixtureDoc (...any:
|
|
27
|
+
public addFixtureDoc (...any: T)
|
|
17
28
|
|
|
18
29
|
public addIndex (index: object, options: CreateIndexesOptions)
|
|
19
30
|
|
|
20
31
|
protected _id (id: string): ObjectId
|
|
21
32
|
|
|
22
|
-
protected _expandObjectToSet (
|
|
33
|
+
protected _expandObjectToSet (
|
|
34
|
+
attr: string|null,
|
|
35
|
+
obj: {[key: string]: any},
|
|
36
|
+
nested?: boolean
|
|
37
|
+
): {[key: string]: any}
|
|
23
38
|
|
|
24
39
|
protected _log: { log: Function, error: Function };
|
|
25
40
|
|
|
26
41
|
public preHeat(): Promise<void>
|
|
27
42
|
|
|
28
43
|
public drop (): Promise<void>
|
|
44
|
+
|
|
45
|
+
protected _catchNetworkIssues<I> (fn: {():I}): Promise<I>
|
|
46
|
+
|
|
47
|
+
protected _detectNetworkIssueException<E extends Error> (e: E): E
|
|
29
48
|
}
|
|
30
49
|
|
|
31
50
|
}
|
package/package.json
CHANGED
package/src/BaseStorage.js
CHANGED
|
@@ -91,9 +91,8 @@ class BaseStorage {
|
|
|
91
91
|
this._isCosmo = typeof isCosmo === 'number' || isCosmo;
|
|
92
92
|
this._log = log;
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
*/
|
|
94
|
+
// eslint-disable-next-line max-len
|
|
95
|
+
/** @type {import('mongodb').Collection<wingbotmongodb.WithId<T>>|Promise<import('mongodb').Collection<wingbotmongodb.WithId<T>>>} */
|
|
97
96
|
this._collection = null;
|
|
98
97
|
|
|
99
98
|
this._indexes = [];
|
|
@@ -228,14 +227,14 @@ class BaseStorage {
|
|
|
228
227
|
/**
|
|
229
228
|
*
|
|
230
229
|
* @param {string} name
|
|
231
|
-
* @returns {Promise<import('mongodb').Collection<T
|
|
230
|
+
* @returns {Promise<import('mongodb').Collection<wingbotmongodb.WithId<T>>>}
|
|
232
231
|
*/
|
|
233
232
|
async _getOrCreateCollection (name) {
|
|
234
233
|
const db = typeof this._mongoDb === 'function'
|
|
235
234
|
? await this._mongoDb()
|
|
236
235
|
: this._mongoDb;
|
|
237
236
|
|
|
238
|
-
/** @type {import('mongodb').Collection<T
|
|
237
|
+
/** @type {import('mongodb').Collection<wingbotmongodb.WithId<T>>} */
|
|
239
238
|
let collection;
|
|
240
239
|
|
|
241
240
|
if (this._isCosmo) {
|
|
@@ -281,7 +280,7 @@ class BaseStorage {
|
|
|
281
280
|
*
|
|
282
281
|
* @protected
|
|
283
282
|
* @param {boolean} [forRead]
|
|
284
|
-
* @returns {Promise<import('mongodb').Collection<T
|
|
283
|
+
* @returns {Promise<import('mongodb').Collection<wingbotmongodb.WithId<T>>>}
|
|
285
284
|
*/
|
|
286
285
|
async _getCollection (forRead = false) {
|
|
287
286
|
if (this._collection === null) {
|
|
@@ -312,7 +311,7 @@ class BaseStorage {
|
|
|
312
311
|
/**
|
|
313
312
|
*
|
|
314
313
|
* @param {object[]} indexes
|
|
315
|
-
* @param {import('mongodb').Collection<T
|
|
314
|
+
* @param {import('mongodb').Collection<wingbotmongodb.WithId<T>>} collection
|
|
316
315
|
* @returns {Promise}
|
|
317
316
|
*/
|
|
318
317
|
async _ensureIndexes (indexes, collection) {
|