@pi-r/atlas 0.8.0 → 0.8.2
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 +31 -6
- package/package.json +30 -30
package/client/index.js
CHANGED
|
@@ -21,7 +21,32 @@ function sanitizeCredentials(credential) {
|
|
|
21
21
|
}
|
|
22
22
|
function validateDatabase(credential, data) {
|
|
23
23
|
const auth = credential.auth;
|
|
24
|
-
|
|
24
|
+
if (data.table && Cloud.isURL(data.uri)) {
|
|
25
|
+
if (auth?.username || credential.username || (0, util_1.hasBasicAuth)(data.uri)) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
const setAuthSource = () => credential.authSource ||= '$external';
|
|
29
|
+
switch (credential.authMechanism) {
|
|
30
|
+
case 'MONGODB-X509':
|
|
31
|
+
if (credential.tlsCertificateKeyFile) {
|
|
32
|
+
credential.tls = true;
|
|
33
|
+
setAuthSource();
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
break;
|
|
37
|
+
case 'MONGODB-AWS':
|
|
38
|
+
if (credential.authMechanismProperties) {
|
|
39
|
+
setAuthSource();
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
case 'PLAIN':
|
|
44
|
+
credential.maxPoolSize ??= 1;
|
|
45
|
+
setAuthSource();
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
25
50
|
}
|
|
26
51
|
function createDatabaseClient(credential, data) {
|
|
27
52
|
sanitizeCredentials(credential);
|
|
@@ -38,7 +63,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
38
63
|
const coercing = this.hasCoerce("atlas", 'options');
|
|
39
64
|
const cacheValue = { value: this.valueOfKey(credential, 'cache'), sessionKey };
|
|
40
65
|
const createClient = async (item, options) => {
|
|
41
|
-
return clients[(0, types_1.hashKey)(item.uri + Cloud.asString(options, true))] ||= await createDatabaseClient.call(this, options, item).connect();
|
|
66
|
+
return clients[length > 1 ? (0, types_1.hashKey)(item.uri + Cloud.asString(options, true)) : '_'] ||= await createDatabaseClient.call(this, options, item).connect();
|
|
42
67
|
};
|
|
43
68
|
const closeClient = () => {
|
|
44
69
|
for (const key in clients) {
|
|
@@ -105,16 +130,16 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
105
130
|
}
|
|
106
131
|
}
|
|
107
132
|
if (pipeline) {
|
|
108
|
-
const
|
|
133
|
+
const aggOptions = (0, types_1.isPlainObject)(aggregate) ? aggregate.options : undefined;
|
|
109
134
|
if (coercing) {
|
|
110
135
|
for (const doc of pipeline) {
|
|
111
136
|
(0, types_1.coerceObject)(doc);
|
|
112
137
|
}
|
|
113
|
-
if (
|
|
114
|
-
(0, types_1.coerceObject)(
|
|
138
|
+
if (aggOptions) {
|
|
139
|
+
(0, types_1.coerceObject)(aggOptions);
|
|
115
140
|
}
|
|
116
141
|
}
|
|
117
|
-
const items = collection.aggregate(pipeline,
|
|
142
|
+
const items = collection.aggregate(pipeline, aggOptions);
|
|
118
143
|
if (sort) {
|
|
119
144
|
items.sort((0, mongodb_1.getSortValue)(sort, coercing)[0]);
|
|
120
145
|
}
|
package/package.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@pi-r/atlas",
|
|
3
|
-
"version": "0.8.
|
|
4
|
-
"description": "MongoDB Atlas cloud functions for E-mc.",
|
|
5
|
-
"main": "client/index.js",
|
|
6
|
-
"publishConfig": {
|
|
7
|
-
"access": "public"
|
|
8
|
-
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
12
|
-
"directory": "src/cloud/atlas"
|
|
13
|
-
},
|
|
14
|
-
"keywords": [
|
|
15
|
-
"squared",
|
|
16
|
-
"e-mc",
|
|
17
|
-
"squared-functions"
|
|
18
|
-
],
|
|
19
|
-
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
-
"license": "MIT",
|
|
21
|
-
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "^0.10.
|
|
24
|
-
"@e-mc/db": "^0.10.
|
|
25
|
-
"@e-mc/module": "^0.10.
|
|
26
|
-
"@e-mc/types": "^0.10.
|
|
27
|
-
"@pi-r/mongodb": "^0.8.
|
|
28
|
-
"mongodb": "^6.
|
|
29
|
-
}
|
|
30
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@pi-r/atlas",
|
|
3
|
+
"version": "0.8.2",
|
|
4
|
+
"description": "MongoDB Atlas cloud functions for E-mc.",
|
|
5
|
+
"main": "client/index.js",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
12
|
+
"directory": "src/cloud/atlas"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"squared",
|
|
16
|
+
"e-mc",
|
|
17
|
+
"squared-functions"
|
|
18
|
+
],
|
|
19
|
+
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@e-mc/cloud": "^0.10.2",
|
|
24
|
+
"@e-mc/db": "^0.10.2",
|
|
25
|
+
"@e-mc/module": "^0.10.2",
|
|
26
|
+
"@e-mc/types": "^0.10.2",
|
|
27
|
+
"@pi-r/mongodb": "^0.8.2",
|
|
28
|
+
"mongodb": "^6.9.0"
|
|
29
|
+
}
|
|
30
|
+
}
|