@pi-r/atlas 0.8.0 → 0.8.1
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 +32 -6
- package/package.json +1 -1
package/client/index.js
CHANGED
|
@@ -21,7 +21,33 @@ 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 'GSSAPI':
|
|
38
|
+
case 'MONGODB-AWS':
|
|
39
|
+
if ((0, types_1.isPlainObject)(credential.authMechanismProperties)) {
|
|
40
|
+
setAuthSource();
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
44
|
+
case 'PLAIN':
|
|
45
|
+
credential.maxPoolSize ??= 1;
|
|
46
|
+
setAuthSource();
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
25
51
|
}
|
|
26
52
|
function createDatabaseClient(credential, data) {
|
|
27
53
|
sanitizeCredentials(credential);
|
|
@@ -38,7 +64,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
38
64
|
const coercing = this.hasCoerce("atlas", 'options');
|
|
39
65
|
const cacheValue = { value: this.valueOfKey(credential, 'cache'), sessionKey };
|
|
40
66
|
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();
|
|
67
|
+
return clients[length > 1 ? (0, types_1.hashKey)(item.uri + Cloud.asString(options, true)) : '_'] ||= await createDatabaseClient.call(this, options, item).connect();
|
|
42
68
|
};
|
|
43
69
|
const closeClient = () => {
|
|
44
70
|
for (const key in clients) {
|
|
@@ -105,16 +131,16 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
105
131
|
}
|
|
106
132
|
}
|
|
107
133
|
if (pipeline) {
|
|
108
|
-
const
|
|
134
|
+
const aggOptions = (0, types_1.isPlainObject)(aggregate) ? aggregate.options : undefined;
|
|
109
135
|
if (coercing) {
|
|
110
136
|
for (const doc of pipeline) {
|
|
111
137
|
(0, types_1.coerceObject)(doc);
|
|
112
138
|
}
|
|
113
|
-
if (
|
|
114
|
-
(0, types_1.coerceObject)(
|
|
139
|
+
if (aggOptions) {
|
|
140
|
+
(0, types_1.coerceObject)(aggOptions);
|
|
115
141
|
}
|
|
116
142
|
}
|
|
117
|
-
const items = collection.aggregate(pipeline,
|
|
143
|
+
const items = collection.aggregate(pipeline, aggOptions);
|
|
118
144
|
if (sort) {
|
|
119
145
|
items.sort((0, mongodb_1.getSortValue)(sort, coercing)[0]);
|
|
120
146
|
}
|