@pi-r/mongodb 0.6.1 → 0.6.3
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 +2 -0
- package/client/index.js +18 -22
- package/package.json +5 -5
- package/types/index.d.ts +1 -1
package/README.md
CHANGED
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
|
|
73
|
-
if (
|
|
74
|
-
|
|
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 (
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
pool
|
|
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.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "MongoDB client driver for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"types": "client/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/anpham6/pi-r.git",
|
|
12
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
13
13
|
"directory": "src/db/mongodb"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
@@ -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.
|
|
25
|
-
"@e-mc/request": "^0.8.
|
|
26
|
-
"@e-mc/types": "^0.8.
|
|
24
|
+
"@e-mc/db": "^0.8.3",
|
|
25
|
+
"@e-mc/request": "^0.8.3",
|
|
26
|
+
"@e-mc/types": "^0.8.3",
|
|
27
27
|
"mongodb": "^6.3.0"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export interface MongoDBDataSource extends DbDataSource<Filter<Document> | Mongo
|
|
|
10
10
|
updateType?: 0 | 1 | 2 | 3;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export interface MongoDBCredential extends ServerAuth, Pick<MongoClientOptions, "auth" | "authMechanism" | "authSource" | "
|
|
13
|
+
export interface MongoDBCredential extends ServerAuth, Pick<MongoClientOptions, "auth" | "authMechanism" | "authSource" | "tlsCertificateKeyFile" | "tlsCertificateKeyFilePassword" | "tlsCAFile" | "tlsCRLFile" | "tlsAllowInvalidHostnames" | "tlsAllowInvalidCertificates" | "tlsInsecure"> {}
|
|
14
14
|
|
|
15
15
|
export interface MongoDBSortValue {
|
|
16
16
|
value?: Sort;
|