@pi-r/atlas 0.2.2 → 0.3.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/client/index.js +18 -18
- package/package.json +7 -7
package/client/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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");
|
|
@@ -11,7 +12,7 @@ function sanitizeCredentials(item, credential) {
|
|
|
11
12
|
if (username) {
|
|
12
13
|
const auth = password ? { username, password } : { username };
|
|
13
14
|
if (MONGODB_V3) {
|
|
14
|
-
credential.auth = password || !credential.auth
|
|
15
|
+
credential.auth = password || !credential.auth?.password ? auth : credential.auth;
|
|
15
16
|
}
|
|
16
17
|
else {
|
|
17
18
|
credential.auth || (credential.auth = auth);
|
|
@@ -25,8 +26,8 @@ function sanitizeCredentials(item, credential) {
|
|
|
25
26
|
if (!(0, util_1.hasBasicAuth)(item.uri)) {
|
|
26
27
|
const auth = (0, util_1.getBasicAuth)(credential.auth);
|
|
27
28
|
if (auth) {
|
|
28
|
-
const
|
|
29
|
-
item.uri =
|
|
29
|
+
const [protocol, hostname] = item.uri.split('://');
|
|
30
|
+
item.uri = protocol + '://' + auth + hostname;
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
delete credential.auth;
|
|
@@ -38,15 +39,8 @@ function validateDatabase(credential, data) {
|
|
|
38
39
|
}
|
|
39
40
|
exports.validateDatabase = validateDatabase;
|
|
40
41
|
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
|
-
}
|
|
42
|
+
sanitizeCredentials(data, credential);
|
|
43
|
+
return new mongodb.MongoClient(data.uri, credential);
|
|
50
44
|
}
|
|
51
45
|
exports.createDatabaseClient = createDatabaseClient;
|
|
52
46
|
async function executeQuery(credential, data, sessionKey) {
|
|
@@ -133,11 +127,14 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
133
127
|
}
|
|
134
128
|
if ((0, types_1.isArray)(update)) {
|
|
135
129
|
const insertOptions = item.execute?.insert;
|
|
136
|
-
if (insertOptions) {
|
|
137
|
-
|
|
130
|
+
if (insertOptions && coercing) {
|
|
131
|
+
(0, types_1.coerceObject)(insertOptions);
|
|
132
|
+
}
|
|
133
|
+
if (update.length === 1) {
|
|
134
|
+
await collection.insertOne(update[0], insertOptions);
|
|
138
135
|
}
|
|
139
136
|
else {
|
|
140
|
-
await collection.insertMany(update);
|
|
137
|
+
await collection.insertMany(update, insertOptions);
|
|
141
138
|
}
|
|
142
139
|
update = undefined;
|
|
143
140
|
}
|
|
@@ -150,7 +147,11 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
150
147
|
}
|
|
151
148
|
else {
|
|
152
149
|
if (update) {
|
|
153
|
-
|
|
150
|
+
const updateOptions = item.execute?.update;
|
|
151
|
+
if (updateOptions && coercing) {
|
|
152
|
+
(0, types_1.coerceObject)(updateOptions);
|
|
153
|
+
}
|
|
154
|
+
await collection.updateMany(filter, update, updateOptions);
|
|
154
155
|
}
|
|
155
156
|
const items = collection.find(filter, command);
|
|
156
157
|
if (sort) {
|
|
@@ -187,7 +188,6 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
187
188
|
}
|
|
188
189
|
exports.executeBatchQuery = executeBatchQuery;
|
|
189
190
|
function getObjectId(value) {
|
|
190
|
-
|
|
191
|
-
return { '_id': new ObjectId(value) };
|
|
191
|
+
return { '_id': new mongodb.ObjectId(value) };
|
|
192
192
|
}
|
|
193
193
|
exports.getObjectId = getObjectId;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/atlas",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "MongoDB Atlas cloud functions for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "^0.
|
|
24
|
-
"@e-mc/db": "^0.
|
|
25
|
-
"@e-mc/module": "^0.
|
|
26
|
-
"@e-mc/types": "^0.
|
|
27
|
-
"@pi-r/mongodb": "^0.
|
|
28
|
-
"mongodb": "^5.
|
|
23
|
+
"@e-mc/cloud": "^0.6.0",
|
|
24
|
+
"@e-mc/db": "^0.6.0",
|
|
25
|
+
"@e-mc/module": "^0.6.0",
|
|
26
|
+
"@e-mc/types": "^0.6.0",
|
|
27
|
+
"@pi-r/mongodb": "^0.3.0",
|
|
28
|
+
"mongodb": "^5.7.0"
|
|
29
29
|
}
|
|
30
30
|
}
|