@pi-r/atlas 0.3.6 → 0.3.7
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/client/index.js +8 -14
- package/package.json +2 -2
package/client/index.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getObjectId = exports.executeBatchQuery = exports.executeQuery = exports.createDatabaseClient = exports.validateDatabase = void 0;
|
|
4
|
+
const mongodb = require("mongodb");
|
|
4
5
|
const types_1 = require("@e-mc/types");
|
|
5
6
|
const util_1 = require("@e-mc/cloud/util");
|
|
6
7
|
const mongodb_1 = require("@pi-r/mongodb");
|
|
7
8
|
const Module = require("@e-mc/module");
|
|
8
9
|
const MONGODB_V3 = Module.checkSemVer('mongodb', 1, 4);
|
|
9
10
|
function sanitizeCredentials(item, credential) {
|
|
11
|
+
var _a;
|
|
10
12
|
const { username, password } = credential;
|
|
11
13
|
if (username) {
|
|
12
14
|
const auth = password ? { username, password } : { username };
|
|
13
15
|
if (MONGODB_V3) {
|
|
14
|
-
credential.auth = password || !credential.auth ||
|
|
16
|
+
credential.auth = password || !((_a = credential.auth) === null || _a === void 0 ? void 0 : _a.password) ? auth : credential.auth;
|
|
15
17
|
}
|
|
16
18
|
else {
|
|
17
19
|
credential.auth || (credential.auth = auth);
|
|
@@ -25,8 +27,8 @@ function sanitizeCredentials(item, credential) {
|
|
|
25
27
|
if (!(0, util_1.hasBasicAuth)(item.uri)) {
|
|
26
28
|
const auth = (0, util_1.getBasicAuth)(credential.auth);
|
|
27
29
|
if (auth) {
|
|
28
|
-
const
|
|
29
|
-
item.uri =
|
|
30
|
+
const [protocol, hostname] = item.uri.split('://');
|
|
31
|
+
item.uri = protocol + '://' + auth + hostname;
|
|
30
32
|
}
|
|
31
33
|
}
|
|
32
34
|
delete credential.auth;
|
|
@@ -38,15 +40,8 @@ function validateDatabase(credential, data) {
|
|
|
38
40
|
}
|
|
39
41
|
exports.validateDatabase = validateDatabase;
|
|
40
42
|
function createDatabaseClient(credential, data) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const { MongoClient } = require('mongodb');
|
|
44
|
-
return new MongoClient(data.uri, credential);
|
|
45
|
-
}
|
|
46
|
-
catch (err) {
|
|
47
|
-
this.checkPackage(err, 'mongodb', { passThrough: true });
|
|
48
|
-
throw err;
|
|
49
|
-
}
|
|
43
|
+
sanitizeCredentials(data, credential);
|
|
44
|
+
return new mongodb.MongoClient(data.uri, credential);
|
|
50
45
|
}
|
|
51
46
|
exports.createDatabaseClient = createDatabaseClient;
|
|
52
47
|
async function executeQuery(credential, data, sessionKey) {
|
|
@@ -195,7 +190,6 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
195
190
|
}
|
|
196
191
|
exports.executeBatchQuery = executeBatchQuery;
|
|
197
192
|
function getObjectId(value) {
|
|
198
|
-
|
|
199
|
-
return { '_id': new ObjectId(value) };
|
|
193
|
+
return { '_id': new mongodb.ObjectId(value) };
|
|
200
194
|
}
|
|
201
195
|
exports.getObjectId = getObjectId;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/atlas",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"description": "MongoDB Atlas cloud functions for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@e-mc/db": "^0.6.16",
|
|
25
25
|
"@e-mc/module": "^0.6.16",
|
|
26
26
|
"@e-mc/types": "^0.6.16",
|
|
27
|
-
"@pi-r/mongodb": "^0.3.
|
|
27
|
+
"@pi-r/mongodb": "^0.3.7",
|
|
28
28
|
"mongodb": "^5.9.2"
|
|
29
29
|
}
|
|
30
30
|
}
|