@sprucelabs/data-stores 19.1.18 → 19.1.20
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.
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Log } from '@sprucelabs/spruce-skill-utils';
|
|
2
|
+
import { MongoClientOptions, MongoClient } from 'mongodb';
|
|
2
3
|
import { Database } from '../types/database.types';
|
|
3
4
|
import { QueryOptions } from '../types/query.types';
|
|
4
5
|
export declare const MONGO_TEST_URI = "mongodb://localhost:27017";
|
|
5
6
|
export default class MongoDatabase implements Database {
|
|
6
|
-
|
|
7
|
+
protected mongo: MongoClient;
|
|
7
8
|
private db?;
|
|
8
9
|
private dbName;
|
|
9
10
|
private disableAutoGeneratedIdsOnTheseCollections;
|
|
10
11
|
private _isConnected;
|
|
11
12
|
constructor(url: string, options?: MongoClientOptions & {
|
|
12
13
|
dbName?: string;
|
|
14
|
+
log?: Log;
|
|
13
15
|
});
|
|
14
16
|
count(collection: string, query?: Record<string, any>): Promise<number>;
|
|
15
17
|
generateId(): string;
|
|
@@ -15,6 +15,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.MONGO_TEST_URI = void 0;
|
|
18
|
+
const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
|
|
18
19
|
const differenceWith_1 = __importDefault(require("lodash/differenceWith"));
|
|
19
20
|
const isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
20
21
|
const mongodb_1 = require("mongodb");
|
|
@@ -26,7 +27,7 @@ class MongoDatabase {
|
|
|
26
27
|
constructor(url, options) {
|
|
27
28
|
this.disableAutoGeneratedIdsOnTheseCollections = [];
|
|
28
29
|
this._isConnected = false;
|
|
29
|
-
const _a = options !== null && options !== void 0 ? options : {}, { dbName } = _a, rest = __rest(_a, ["dbName"]);
|
|
30
|
+
const _a = options !== null && options !== void 0 ? options : {}, { dbName, log = (0, spruce_skill_utils_1.buildLog)('Mongodb') } = _a, rest = __rest(_a, ["dbName", "log"]);
|
|
30
31
|
if (dbName === 'undefined') {
|
|
31
32
|
throw new SpruceError_1.default({
|
|
32
33
|
code: 'INVALID_DATABASE_NAME',
|
|
@@ -35,6 +36,10 @@ class MongoDatabase {
|
|
|
35
36
|
}
|
|
36
37
|
try {
|
|
37
38
|
this.mongo = new mongodb_1.MongoClient(url, Object.assign(Object.assign({}, (rest || {})), { serverSelectionTimeoutMS: 5000 }));
|
|
39
|
+
this.mongo.on('error', (err) => {
|
|
40
|
+
var _a;
|
|
41
|
+
log.error('MONGO ERROR', (_a = err.stack) !== null && _a !== void 0 ? _a : err.message);
|
|
42
|
+
});
|
|
38
43
|
}
|
|
39
44
|
catch (err) {
|
|
40
45
|
if (err.message.includes('Invalid scheme')) {
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Log } from '@sprucelabs/spruce-skill-utils';
|
|
2
|
+
import { MongoClientOptions, MongoClient } from 'mongodb';
|
|
2
3
|
import { Database } from '../types/database.types';
|
|
3
4
|
import { QueryOptions } from '../types/query.types';
|
|
4
5
|
export declare const MONGO_TEST_URI = "mongodb://localhost:27017";
|
|
5
6
|
export default class MongoDatabase implements Database {
|
|
6
|
-
|
|
7
|
+
protected mongo: MongoClient;
|
|
7
8
|
private db?;
|
|
8
9
|
private dbName;
|
|
9
10
|
private disableAutoGeneratedIdsOnTheseCollections;
|
|
10
11
|
private _isConnected;
|
|
11
12
|
constructor(url: string, options?: MongoClientOptions & {
|
|
12
13
|
dbName?: string;
|
|
14
|
+
log?: Log;
|
|
13
15
|
});
|
|
14
16
|
count(collection: string, query?: Record<string, any>): Promise<number>;
|
|
15
17
|
generateId(): string;
|
|
@@ -18,6 +18,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
18
18
|
}
|
|
19
19
|
return t;
|
|
20
20
|
};
|
|
21
|
+
import { buildLog } from '@sprucelabs/spruce-skill-utils';
|
|
21
22
|
import differenceWith from 'lodash/differenceWith.js';
|
|
22
23
|
import isEqual from 'lodash/isEqual.js';
|
|
23
24
|
import { MongoClient, MongoError } from 'mongodb';
|
|
@@ -29,7 +30,7 @@ export default class MongoDatabase {
|
|
|
29
30
|
constructor(url, options) {
|
|
30
31
|
this.disableAutoGeneratedIdsOnTheseCollections = [];
|
|
31
32
|
this._isConnected = false;
|
|
32
|
-
const _a = options !== null && options !== void 0 ? options : {}, { dbName } = _a, rest = __rest(_a, ["dbName"]);
|
|
33
|
+
const _a = options !== null && options !== void 0 ? options : {}, { dbName, log = buildLog('Mongodb') } = _a, rest = __rest(_a, ["dbName", "log"]);
|
|
33
34
|
if (dbName === 'undefined') {
|
|
34
35
|
throw new SpruceError({
|
|
35
36
|
code: 'INVALID_DATABASE_NAME',
|
|
@@ -38,6 +39,10 @@ export default class MongoDatabase {
|
|
|
38
39
|
}
|
|
39
40
|
try {
|
|
40
41
|
this.mongo = new MongoClient(url, Object.assign(Object.assign({}, (rest || {})), { serverSelectionTimeoutMS: 5000 }));
|
|
42
|
+
this.mongo.on('error', (err) => {
|
|
43
|
+
var _a;
|
|
44
|
+
log.error('MONGO ERROR', (_a = err.stack) !== null && _a !== void 0 ? _a : err.message);
|
|
45
|
+
});
|
|
41
46
|
}
|
|
42
47
|
catch (err) {
|
|
43
48
|
if (err.message.includes('Invalid scheme')) {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "19.1.
|
|
6
|
+
"version": "19.1.20",
|
|
7
7
|
"files": [
|
|
8
8
|
"build/**/*",
|
|
9
9
|
"!build/__tests__",
|
|
@@ -72,9 +72,9 @@
|
|
|
72
72
|
"upgrade.packages.test": "yarn upgrade.packages.all && yarn lint && yarn build.dev && yarn test"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@sprucelabs/error": "^5.0.
|
|
76
|
-
"@sprucelabs/schema": "^28.5.
|
|
77
|
-
"@sprucelabs/spruce-skill-utils": "^28.1.
|
|
75
|
+
"@sprucelabs/error": "^5.0.557",
|
|
76
|
+
"@sprucelabs/schema": "^28.5.91",
|
|
77
|
+
"@sprucelabs/spruce-skill-utils": "^28.1.24",
|
|
78
78
|
"globby": "^11.0.4",
|
|
79
79
|
"just-clone": "^6.2.0",
|
|
80
80
|
"lodash": "^4.17.21",
|
|
@@ -82,13 +82,13 @@
|
|
|
82
82
|
"nedb": "^1.8.0"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
|
-
"@sprucelabs/esm-postbuild": "^2.0.
|
|
86
|
-
"@sprucelabs/jest-json-reporter": "^6.0.
|
|
85
|
+
"@sprucelabs/esm-postbuild": "^2.0.56",
|
|
86
|
+
"@sprucelabs/jest-json-reporter": "^6.0.542",
|
|
87
87
|
"@sprucelabs/jest-sheets-reporter": "^2.0.21",
|
|
88
|
-
"@sprucelabs/resolve-path-aliases": "^1.1.
|
|
88
|
+
"@sprucelabs/resolve-path-aliases": "^1.1.147",
|
|
89
89
|
"@sprucelabs/semantic-release": "^4.0.8",
|
|
90
|
-
"@sprucelabs/test": "^7.7.
|
|
91
|
-
"@sprucelabs/test-utils": "^3.2.
|
|
90
|
+
"@sprucelabs/test": "^7.7.401",
|
|
91
|
+
"@sprucelabs/test-utils": "^3.2.79",
|
|
92
92
|
"@types/lodash": "^4.14.191",
|
|
93
93
|
"@types/nedb": "^1.8.12",
|
|
94
94
|
"@types/node": "17.0.5",
|