@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.
Files changed (2) hide show
  1. package/client/index.js +32 -6
  2. 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
- return !!(data.table && Cloud.isURL(data.uri) && (auth?.username || credential.username || (0, util_1.hasBasicAuth)(data.uri)));
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 aggregateOptions = (0, types_1.isPlainObject)(aggregate) ? aggregate.options : undefined;
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 (aggregateOptions) {
114
- (0, types_1.coerceObject)(aggregateOptions);
139
+ if (aggOptions) {
140
+ (0, types_1.coerceObject)(aggOptions);
115
141
  }
116
142
  }
117
- const items = collection.aggregate(pipeline, aggregateOptions);
143
+ const items = collection.aggregate(pipeline, aggOptions);
118
144
  if (sort) {
119
145
  items.sort((0, mongodb_1.getSortValue)(sort, coercing)[0]);
120
146
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/atlas",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "MongoDB Atlas cloud functions for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "publishConfig": {