@pi-r/mongodb 0.2.10 → 0.2.11
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 +23 -18
- package/package.json +1 -1
package/client/index.js
CHANGED
|
@@ -25,6 +25,7 @@ class MongoDBPool extends DbPool {
|
|
|
25
25
|
return this.client.close(force);
|
|
26
26
|
}
|
|
27
27
|
isEmpty() {
|
|
28
|
+
var _a;
|
|
28
29
|
if (this.closed) {
|
|
29
30
|
return true;
|
|
30
31
|
}
|
|
@@ -36,15 +37,17 @@ class MongoDBPool extends DbPool {
|
|
|
36
37
|
return (0, util_1.checkEmpty)(topology[name]);
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
|
-
return (0, util_1.checkEmpty)(topology.s
|
|
40
|
+
return (0, util_1.checkEmpty)((_a = topology.s) === null || _a === void 0 ? void 0 : _a.sessions);
|
|
40
41
|
}
|
|
41
42
|
return false;
|
|
42
43
|
}
|
|
43
44
|
get closeable() {
|
|
45
|
+
var _a;
|
|
44
46
|
const topology = this.client.topology;
|
|
45
|
-
return topology ? super.closeable || !MONGODB_V333 && topology.s
|
|
47
|
+
return topology ? super.closeable || !MONGODB_V333 && ((_a = topology.s) === null || _a === void 0 ? void 0 : _a.state) === 'closing' : true;
|
|
46
48
|
}
|
|
47
49
|
get closed() {
|
|
50
|
+
var _a;
|
|
48
51
|
const topology = this.client.topology;
|
|
49
52
|
if (topology && (this.success > 0 || this.failed > 0)) {
|
|
50
53
|
if (MONGODB_V333) {
|
|
@@ -54,7 +57,7 @@ class MongoDBPool extends DbPool {
|
|
|
54
57
|
return topology.isDestroyed();
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
|
-
return this.client.s
|
|
60
|
+
return ((_a = this.client.s) === null || _a === void 0 ? void 0 : _a.hasBeenClosed) === true;
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
63
|
const POOL_STATE = {};
|
|
@@ -83,7 +86,7 @@ function removePoolProperties(credential) {
|
|
|
83
86
|
}
|
|
84
87
|
function getCacheObject(item) {
|
|
85
88
|
const credential = item.credential;
|
|
86
|
-
return { uri: item.uri, options: item.options, uuidKey: credential
|
|
89
|
+
return { uri: item.uri, options: item.options, uuidKey: credential === null || credential === void 0 ? void 0 : credential.uuidKey };
|
|
87
90
|
}
|
|
88
91
|
function getPoolKey(credential) {
|
|
89
92
|
const options = credential.options;
|
|
@@ -128,18 +131,19 @@ function checkBuffer(value) {
|
|
|
128
131
|
return '';
|
|
129
132
|
}
|
|
130
133
|
function setCredential(item) {
|
|
134
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
131
135
|
const credential = this.getCredential(item);
|
|
132
136
|
const options = item.options || (item.options = {});
|
|
133
137
|
let uri = item.uri;
|
|
134
138
|
if (credential) {
|
|
135
139
|
let { protocol, server, hostname, port, username, password } = (0, util_1.parseServerAuth)(credential, 27017), { auth, authMechanism = 'DEFAULT', authSource, authMechanismProperties } = credential, authentication = '';
|
|
136
140
|
if (authMechanism === 'GSSAPI') {
|
|
137
|
-
const principal = auth
|
|
141
|
+
const principal = (auth === null || auth === void 0 ? void 0 : auth.username) || username || ((_a = options.auth) === null || _a === void 0 ? void 0 : _a.username);
|
|
138
142
|
if ((0, types_1.isString)(principal)) {
|
|
139
143
|
authentication = encodeURIComponent(principal) + '@';
|
|
140
144
|
}
|
|
141
145
|
}
|
|
142
|
-
else if (auth
|
|
146
|
+
else if (auth === null || auth === void 0 ? void 0 : auth.username) {
|
|
143
147
|
if (!MONGODB_V3) {
|
|
144
148
|
options.auth = auth;
|
|
145
149
|
}
|
|
@@ -303,7 +307,7 @@ function setCredential(item) {
|
|
|
303
307
|
return;
|
|
304
308
|
}
|
|
305
309
|
let username, password, pool;
|
|
306
|
-
if (typeof usePool === 'string' && (username = !MONGODB_V3 && options.auth
|
|
310
|
+
if (typeof usePool === 'string' && (username = !MONGODB_V3 && ((_b = options.auth) === null || _b === void 0 ? void 0 : _b.username) || item.uri && ((_c = (0, util_1.parseConnectionString)(item.uri)) === null || _c === void 0 ? void 0 : _c.username))) {
|
|
307
311
|
[password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
|
|
308
312
|
if (pool) {
|
|
309
313
|
pool.add(item, password);
|
|
@@ -318,27 +322,27 @@ function setCredential(item) {
|
|
|
318
322
|
const { min, max, idle, queue_max, queue_idle } = config;
|
|
319
323
|
if (MONGODB_V360) {
|
|
320
324
|
if (min >= 0) {
|
|
321
|
-
options.minPoolSize
|
|
325
|
+
(_d = options.minPoolSize) !== null && _d !== void 0 ? _d : (options.minPoolSize = min);
|
|
322
326
|
}
|
|
323
327
|
if (max > 0) {
|
|
324
|
-
options.maxPoolSize
|
|
328
|
+
(_e = options.maxPoolSize) !== null && _e !== void 0 ? _e : (options.maxPoolSize = max);
|
|
325
329
|
}
|
|
326
330
|
if (idle >= 0) {
|
|
327
|
-
options.maxIdleTimeMS
|
|
331
|
+
(_f = options.maxIdleTimeMS) !== null && _f !== void 0 ? _f : (options.maxIdleTimeMS = idle);
|
|
328
332
|
}
|
|
329
333
|
if (queue_max > 0 && !MONGODB_V3) {
|
|
330
|
-
options.maxConnecting
|
|
334
|
+
(_g = options.maxConnecting) !== null && _g !== void 0 ? _g : (options.maxConnecting = queue_max);
|
|
331
335
|
}
|
|
332
336
|
if (queue_idle >= 0) {
|
|
333
|
-
options.waitQueueTimeoutMS
|
|
337
|
+
(_h = options.waitQueueTimeoutMS) !== null && _h !== void 0 ? _h : (options.waitQueueTimeoutMS = queue_idle);
|
|
334
338
|
}
|
|
335
339
|
}
|
|
336
340
|
else {
|
|
337
341
|
if (min >= 0) {
|
|
338
|
-
options.minSize
|
|
342
|
+
(_j = options.minSize) !== null && _j !== void 0 ? _j : (options.minSize = min);
|
|
339
343
|
}
|
|
340
344
|
if (max > 0) {
|
|
341
|
-
options.poolSize
|
|
345
|
+
(_k = options.poolSize) !== null && _k !== void 0 ? _k : (options.poolSize = max);
|
|
342
346
|
}
|
|
343
347
|
}
|
|
344
348
|
}
|
|
@@ -444,7 +448,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
444
448
|
continue;
|
|
445
449
|
}
|
|
446
450
|
item.transactionState = 1;
|
|
447
|
-
const getCollection = (target) => target.db(name, client
|
|
451
|
+
const getCollection = (target) => target.db(name, client === null || client === void 0 ? void 0 : client.db).collection(table, client === null || client === void 0 ? void 0 : client.collection);
|
|
448
452
|
const credential = mongoCredential || onceCredential || getCacheObject(item);
|
|
449
453
|
const renewCache = ignoreCache === 0;
|
|
450
454
|
const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
|
|
@@ -503,13 +507,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
503
507
|
onceCredential = undefined;
|
|
504
508
|
}
|
|
505
509
|
tasks[i] = new Promise(async (resolve, reject) => {
|
|
510
|
+
var _a, _b;
|
|
506
511
|
let commandType;
|
|
507
512
|
try {
|
|
508
513
|
let cursor;
|
|
509
514
|
if (pipeline || query) {
|
|
510
515
|
const collection = getCollection(mongoClient || await getConnection(item, credential));
|
|
511
516
|
if (pipeline) {
|
|
512
|
-
const aggregateOptions = aggregate
|
|
517
|
+
const aggregateOptions = aggregate === null || aggregate === void 0 ? void 0 : aggregate.options;
|
|
513
518
|
if (coercing) {
|
|
514
519
|
pipeline.forEach(doc => (0, types_1.coerceObject)(doc));
|
|
515
520
|
if (aggregateOptions) {
|
|
@@ -531,7 +536,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
531
536
|
}
|
|
532
537
|
if ((0, types_1.isArray)(update)) {
|
|
533
538
|
commandType = this.commandType.INSERT;
|
|
534
|
-
const insertOptions = item.execute
|
|
539
|
+
const insertOptions = (_a = item.execute) === null || _a === void 0 ? void 0 : _a.insert;
|
|
535
540
|
if (insertOptions && coercing) {
|
|
536
541
|
(0, types_1.coerceObject)(insertOptions);
|
|
537
542
|
}
|
|
@@ -561,7 +566,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
561
566
|
else {
|
|
562
567
|
if (update) {
|
|
563
568
|
commandType = this.commandType.UPDATE;
|
|
564
|
-
const updateOptions = item.execute
|
|
569
|
+
const updateOptions = (_b = item.execute) === null || _b === void 0 ? void 0 : _b.update;
|
|
565
570
|
if (updateOptions && coercing) {
|
|
566
571
|
(0, types_1.coerceObject)(updateOptions);
|
|
567
572
|
}
|