@pi-r/mongodb 0.6.1 → 0.6.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/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ### @pi-r/mongodb
2
2
 
3
+ https://e-mc.readthedocs.io/en/latest/db/mongodb.html
4
+
3
5
  ### LICENSE
4
6
 
5
7
  MIT
package/client/index.js CHANGED
@@ -69,15 +69,9 @@ function getCacheObject(item) {
69
69
  return { uri: item.uri, options: item.options, uuidKey: credential?.uuidKey };
70
70
  }
71
71
  function getPoolKey(credential) {
72
- const options = credential.options;
73
- if (options && credential.uri) {
74
- const auth = options.auth;
75
- let result = credential.uri + (auth ? '_' + (auth.username || '') + '@' + (auth.password || '') : '') + '_' + (options.authMechanism || '') + Db.asString(options.authMechanismProperties, true);
76
- if (options.tls || options.ssl) {
77
- const { tlsCertificateKeyFile = '', tlsCAFile = '', tlsCRLFile = '', tlsCertificateKeyFilePassword = '', tlsAllowInvalidHostnames, tlsAllowInvalidCertificates, tlsInsecure } = options;
78
- result += tlsCertificateKeyFile + tlsCAFile + tlsCRLFile + tlsCertificateKeyFilePassword + (tlsAllowInvalidHostnames ? '1' : '0') + (tlsAllowInvalidCertificates ? '1' : '0') + (tlsInsecure ? '1' : '0');
79
- }
80
- return result;
72
+ const { options, uri } = credential;
73
+ if (uri && options) {
74
+ return uri + JSON.stringify(credential.options);
81
75
  }
82
76
  }
83
77
  function setCredential(item) {
@@ -179,22 +173,19 @@ function setCredential(item) {
179
173
  return;
180
174
  }
181
175
  let username, password, pool;
182
- if (typeof usePool === 'string' && (username = options.auth?.username || item.uri && (0, util_1.parseConnectionString)(item.uri)?.username)) {
183
- [password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
184
- if (pool) {
185
- pool.add(item, password);
176
+ if ((0, types_1.isString)(usePool)) {
177
+ if (username = options.auth?.username || item.uri && (0, util_1.parseConnectionString)(item.uri)?.username) {
178
+ [password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
179
+ if (pool) {
180
+ pool.add(item, password);
181
+ return;
182
+ }
183
+ }
184
+ if (!password) {
185
+ item.usePool = '';
186
186
  return;
187
187
  }
188
188
  }
189
- const poolKey = getPoolKey(item);
190
- if (!poolKey) {
191
- item.usePool = false;
192
- return;
193
- }
194
- if ((pool = POOL_STATE[poolKey]) && !pool.closed) {
195
- pool.add(item);
196
- return;
197
- }
198
189
  const config = this.getPoolConfig("mongodb" /* STRINGS.MODULE_NAME */, password);
199
190
  if (config) {
200
191
  const { min, max, idle, queue_max, queue_idle, timeout, socket_timeout } = config;
@@ -220,6 +211,11 @@ function setCredential(item) {
220
211
  options.socketTimeoutMS ?? (options.socketTimeoutMS = socket_timeout);
221
212
  }
222
213
  }
214
+ const poolKey = getPoolKey(item);
215
+ if ((pool = POOL_STATE[poolKey]) && !pool.closed) {
216
+ pool.add(item);
217
+ return;
218
+ }
223
219
  new MongoDBPool(new mongodb.MongoClient(item.uri, options), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
224
220
  }
225
221
  exports.setCredential = setCredential;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mongodb",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "MongoDB client driver for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "types": "client/index.d.ts",
@@ -21,9 +21,9 @@
21
21
  "license": "MIT",
22
22
  "homepage": "https://github.com/anpham6/pi-r#readme",
23
23
  "dependencies": {
24
- "@e-mc/db": "^0.8.1",
25
- "@e-mc/request": "^0.8.1",
26
- "@e-mc/types": "^0.8.1",
24
+ "@e-mc/db": "^0.8.2",
25
+ "@e-mc/request": "^0.8.2",
26
+ "@e-mc/types": "^0.8.2",
27
27
  "mongodb": "^6.3.0"
28
28
  }
29
29
  }