@pi-r/mongodb 0.9.4 → 0.10.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 +22 -15
- package/client/pool.js +5 -1
- package/package.json +5 -5
package/client/index.js
CHANGED
|
@@ -56,13 +56,12 @@ function setCredential(item) {
|
|
|
56
56
|
switch (authMechanism) {
|
|
57
57
|
case 'MONGODB-X509': {
|
|
58
58
|
for (const attr of ['tlsCertificateKeyFile', 'tlsCAFile', 'tlsCRLFile']) {
|
|
59
|
-
|
|
59
|
+
const value = credential[attr];
|
|
60
60
|
if ((0, types_1.isString)(value)) {
|
|
61
|
-
if (Db.isPath(value
|
|
61
|
+
if (Db.isPath(value, true)) {
|
|
62
62
|
const pathname = path.resolve(value);
|
|
63
63
|
if (this.canRead(pathname, { ownPermissionOnly: true })) {
|
|
64
64
|
options[attr] = pathname;
|
|
65
|
-
continue;
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
67
|
else if (Request.isCert(value)) {
|
|
@@ -82,14 +81,14 @@ function setCredential(item) {
|
|
|
82
81
|
}
|
|
83
82
|
}
|
|
84
83
|
if (key.length > 0) {
|
|
85
|
-
options.key = Buffer.from(key.join('\n'), '
|
|
84
|
+
options.key = Buffer.from(key.join('\n'), 'utf8');
|
|
86
85
|
}
|
|
87
86
|
if (cert.length > 0) {
|
|
88
|
-
options.cert = Buffer.from(cert.join('\n'), '
|
|
87
|
+
options.cert = Buffer.from(cert.join('\n'), 'utf8');
|
|
89
88
|
}
|
|
90
89
|
}
|
|
91
90
|
else {
|
|
92
|
-
options[attr === 'tlsCAFile' ? 'ca' : 'crl'] = Buffer.from(value, '
|
|
91
|
+
options[attr === 'tlsCAFile' ? 'ca' : 'crl'] = Buffer.from(value, 'utf8');
|
|
93
92
|
}
|
|
94
93
|
}
|
|
95
94
|
}
|
|
@@ -140,14 +139,18 @@ function setCredential(item) {
|
|
|
140
139
|
}
|
|
141
140
|
item.uri = uri;
|
|
142
141
|
if (!options.writeConcern && ('w' in options || 'wtimeoutMS' in options || 'journal' in options)) {
|
|
143
|
-
options.writeConcern =
|
|
142
|
+
options.writeConcern = {
|
|
143
|
+
w: options.w,
|
|
144
|
+
wtimeoutMS: options.wtimeoutMS,
|
|
145
|
+
journal: options.journal
|
|
146
|
+
};
|
|
144
147
|
delete options.w;
|
|
145
148
|
delete options.wtimeoutMS;
|
|
146
149
|
delete options.journal;
|
|
147
150
|
}
|
|
148
151
|
}
|
|
149
|
-
else if (!
|
|
150
|
-
throw (0, types_1.errorMessage)("mongodb",
|
|
152
|
+
else if (!uri) {
|
|
153
|
+
throw (0, types_1.errorMessage)("mongodb", "Invalid credentials", 'uri');
|
|
151
154
|
}
|
|
152
155
|
const usePool = item.usePool;
|
|
153
156
|
if (!usePool) {
|
|
@@ -155,7 +158,8 @@ function setCredential(item) {
|
|
|
155
158
|
}
|
|
156
159
|
let username, password, pool;
|
|
157
160
|
if ((0, types_1.isString)(usePool)) {
|
|
158
|
-
|
|
161
|
+
username = options.auth?.username || item.uri && (0, util_1.parseConnectionString)(item.uri)?.username;
|
|
162
|
+
if (username) {
|
|
159
163
|
[password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
|
|
160
164
|
if (pool) {
|
|
161
165
|
pool.add(item, password);
|
|
@@ -169,7 +173,7 @@ function setCredential(item) {
|
|
|
169
173
|
}
|
|
170
174
|
const config = this.getPoolConfig("mongodb", password);
|
|
171
175
|
if (config) {
|
|
172
|
-
const { min, max, idle, queue_max, queue_idle, timeout, socket_timeout } = config;
|
|
176
|
+
const { min, max, idle, queue_max, queue_idle, timeout, socket_timeout, server_timeout } = config;
|
|
173
177
|
if (min >= 0) {
|
|
174
178
|
options.minPoolSize ??= min;
|
|
175
179
|
}
|
|
@@ -191,6 +195,9 @@ function setCredential(item) {
|
|
|
191
195
|
if (socket_timeout > 0) {
|
|
192
196
|
options.socketTimeoutMS ??= socket_timeout;
|
|
193
197
|
}
|
|
198
|
+
if (server_timeout > 0) {
|
|
199
|
+
options.serverSelectionTimeoutMS ??= server_timeout;
|
|
200
|
+
}
|
|
194
201
|
}
|
|
195
202
|
const poolKey = DbPool.asString(item);
|
|
196
203
|
if ((pool = POOL_STATE[poolKey]) && !pool.closed) {
|
|
@@ -301,7 +308,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
301
308
|
}
|
|
302
309
|
let queryString = '', rows, pipeline;
|
|
303
310
|
if (caching && ignoreCache !== true && (!targetObject || typeof cacheObjectKey === 'string') && !streamRow) {
|
|
304
|
-
queryString = (name || '') + '_' + table + '_' + limit + Db.asString(sort, true) + Db.asString(client, true) + (targetObject ? targetObject.toString() + cacheObjectKey : '');
|
|
311
|
+
queryString = (name || '') + '_' + table + '_' + (limit > 0 ? limit.toString() : '0') + Db.asString(sort, true) + Db.asString(client, true) + (targetObject ? targetObject.toString() + cacheObjectKey : '');
|
|
305
312
|
}
|
|
306
313
|
if (aggregate) {
|
|
307
314
|
pipeline = Array.isArray(aggregate) ? aggregate : aggregate.pipeline;
|
|
@@ -496,7 +503,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
496
503
|
}
|
|
497
504
|
}
|
|
498
505
|
}
|
|
499
|
-
return this.processRows(batch, tasks, {
|
|
506
|
+
return this.processRows(batch, tasks, clients.length === 0 ? parallel : {
|
|
500
507
|
parallel,
|
|
501
508
|
disconnect() {
|
|
502
509
|
for (const item of clients) {
|
|
@@ -514,7 +521,7 @@ async function initCollection(target, item) {
|
|
|
514
521
|
await Promise.all((!Array.isArray(item.command) ? [item.command] : item.command).map(async (cmd) => db.command(document, cmd)))
|
|
515
522
|
.then(items => {
|
|
516
523
|
for (const output of items) {
|
|
517
|
-
this.addLog(this.statusType.INFO, output,
|
|
524
|
+
this.addLog(this.statusType.INFO, output, "mongodb", 'runCommand');
|
|
518
525
|
}
|
|
519
526
|
});
|
|
520
527
|
}
|
|
@@ -525,7 +532,7 @@ async function initCollection(target, item) {
|
|
|
525
532
|
this.addLog(this.statusType.INFO, `inserted: ${insertedCount}, upserted: ${upsertedCount}, matched: ${matchedCount}, modified: ${modifiedCount}, deleted: ${deletedCount}`, "mongodb", 'bulkWrite');
|
|
526
533
|
}
|
|
527
534
|
else {
|
|
528
|
-
this.addLog(this.statusType.WARN, 'Operation was not acknowledged',
|
|
535
|
+
this.addLog(this.statusType.WARN, 'Operation was not acknowledged', "mongodb", 'bulkWrite');
|
|
529
536
|
}
|
|
530
537
|
});
|
|
531
538
|
}
|
package/client/pool.js
CHANGED
|
@@ -3,6 +3,8 @@ const util_1 = require("@e-mc/db/util");
|
|
|
3
3
|
const DbPool = require('@e-mc/db/pool');
|
|
4
4
|
const POOL_ACTIVE = new WeakSet();
|
|
5
5
|
class MongoDBPool extends DbPool {
|
|
6
|
+
static CACHE_UNUSED = ['maxPoolSize', 'minPoolSize', 'connectTimeoutMS', 'socketTimeoutMS', 'maxConnecting', 'maxIdleTimeMS', 'waitQueueTimeoutMS', 'maxStalenessSeconds', 'localThresholdMS', 'serverSelectionTimeoutMS', 'heartbeatFrequencyMS', 'minHeartbeatFrequencyMS', 'timeoutMS', 'compressors', 'zlibCompressionLevel', 'srvMaxHosts', 'mongodbLogPath', 'mongodbLogComponentSeverities', 'mongodbLogMaxDocumentLength'];
|
|
7
|
+
static CACHE_IGNORE = ['pkFactory'];
|
|
6
8
|
static asString(credential) {
|
|
7
9
|
const { options, uri } = credential;
|
|
8
10
|
if (uri && options) {
|
|
@@ -11,6 +13,9 @@ class MongoDBPool extends DbPool {
|
|
|
11
13
|
return super.asString(credential);
|
|
12
14
|
}
|
|
13
15
|
static sanitize(credential) {
|
|
16
|
+
if (!this.canCache(credential)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
14
19
|
const target = credential.options;
|
|
15
20
|
if (!target || !POOL_ACTIVE.has(credential) || credential.uuidKey) {
|
|
16
21
|
return credential;
|
|
@@ -57,5 +62,4 @@ class MongoDBPool extends DbPool {
|
|
|
57
62
|
return this.client.s?.hasBeenClosed === true;
|
|
58
63
|
}
|
|
59
64
|
}
|
|
60
|
-
MongoDBPool.CACHE_UNUSED = ['maxPoolSize', 'minPoolSize', 'connectTimeoutMS', 'socketTimeoutMS', 'maxConnecting', 'maxIdleTimeMS', 'waitQueueTimeoutMS', 'maxStalenessSeconds', 'localThresholdMS', 'serverSelectionTimeoutMS', 'heartbeatFrequencyMS', 'minHeartbeatFrequencyMS', 'compressors', 'zlibCompressionLevel', 'srvMaxHosts'];
|
|
61
65
|
module.exports = MongoDBPool;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/mongodb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "MongoDB client driver for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"types": "client/index.d.ts",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/db": "^0.
|
|
24
|
-
"@e-mc/request": "^0.
|
|
25
|
-
"@e-mc/types": "^0.
|
|
26
|
-
"mongodb": "^6.
|
|
23
|
+
"@e-mc/db": "^0.12.3",
|
|
24
|
+
"@e-mc/request": "^0.12.3",
|
|
25
|
+
"@e-mc/types": "^0.12.3",
|
|
26
|
+
"mongodb": "^6.16.0"
|
|
27
27
|
}
|
|
28
28
|
}
|