@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.
Files changed (2) hide show
  1. package/client/index.js +31 -6
  2. 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
- 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 '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 aggregateOptions = (0, types_1.isPlainObject)(aggregate) ? aggregate.options : undefined;
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 (aggregateOptions) {
114
- (0, types_1.coerceObject)(aggregateOptions);
138
+ if (aggOptions) {
139
+ (0, types_1.coerceObject)(aggOptions);
115
140
  }
116
141
  }
117
- const items = collection.aggregate(pipeline, aggregateOptions);
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.0",
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.0",
24
- "@e-mc/db": "^0.10.0",
25
- "@e-mc/module": "^0.10.0",
26
- "@e-mc/types": "^0.10.0",
27
- "@pi-r/mongodb": "^0.8.0",
28
- "mongodb": "^6.8.0"
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
+ }