@pi-r/mongodb 0.3.3 → 0.3.5
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/LICENSE +1 -1
- package/client/index.js +23 -18
- package/package.json +4 -4
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/client/index.js
CHANGED
|
@@ -26,6 +26,7 @@ class MongoDBPool extends DbPool {
|
|
|
26
26
|
return this.client.close(force);
|
|
27
27
|
}
|
|
28
28
|
isEmpty() {
|
|
29
|
+
var _a, _b;
|
|
29
30
|
if (this.closed) {
|
|
30
31
|
return true;
|
|
31
32
|
}
|
|
@@ -37,15 +38,17 @@ class MongoDBPool extends DbPool {
|
|
|
37
38
|
return (0, util_1.checkEmpty)(topology[name]);
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
|
-
return (0, util_1.checkEmpty)(topology.s
|
|
41
|
+
return (0, util_1.checkEmpty)((_a = topology.s) === null || _a === void 0 ? void 0 : _a.sessions) && (0, util_1.checkEmpty)((_b = topology.s) === null || _b === void 0 ? void 0 : _b.servers);
|
|
41
42
|
}
|
|
42
43
|
return false;
|
|
43
44
|
}
|
|
44
45
|
get closeable() {
|
|
46
|
+
var _a;
|
|
45
47
|
const topology = this.client.topology;
|
|
46
|
-
return topology ? super.closeable || !MONGODB_V333 && topology.s
|
|
48
|
+
return topology ? super.closeable || !MONGODB_V333 && ((_a = topology.s) === null || _a === void 0 ? void 0 : _a.state) === 'closing' : true;
|
|
47
49
|
}
|
|
48
50
|
get closed() {
|
|
51
|
+
var _a;
|
|
49
52
|
const topology = this.client.topology;
|
|
50
53
|
if (topology && (this.success > 0 || this.failed > 0)) {
|
|
51
54
|
if (MONGODB_V333) {
|
|
@@ -55,7 +58,7 @@ class MongoDBPool extends DbPool {
|
|
|
55
58
|
return topology.isDestroyed();
|
|
56
59
|
}
|
|
57
60
|
}
|
|
58
|
-
return this.client.s
|
|
61
|
+
return ((_a = this.client.s) === null || _a === void 0 ? void 0 : _a.hasBeenClosed) === true;
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
64
|
const POOL_STATE = {};
|
|
@@ -84,7 +87,7 @@ function removePoolProperties(credential) {
|
|
|
84
87
|
}
|
|
85
88
|
function getCacheObject(item) {
|
|
86
89
|
const credential = item.credential;
|
|
87
|
-
return { uri: item.uri, options: item.options, uuidKey: credential
|
|
90
|
+
return { uri: item.uri, options: item.options, uuidKey: credential === null || credential === void 0 ? void 0 : credential.uuidKey };
|
|
88
91
|
}
|
|
89
92
|
function getPoolKey(credential) {
|
|
90
93
|
const options = credential.options;
|
|
@@ -129,18 +132,19 @@ function checkBuffer(value) {
|
|
|
129
132
|
return '';
|
|
130
133
|
}
|
|
131
134
|
function setCredential(item) {
|
|
135
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
132
136
|
const credential = this.getCredential(item);
|
|
133
137
|
const options = item.options || (item.options = {});
|
|
134
138
|
let uri = item.uri;
|
|
135
139
|
if (credential) {
|
|
136
140
|
let { protocol, server, hostname, port, username, password } = (0, util_1.parseServerAuth)(credential, 27017), { auth, authMechanism = 'DEFAULT', authSource, authMechanismProperties } = credential, authentication = '';
|
|
137
141
|
if (authMechanism === 'GSSAPI') {
|
|
138
|
-
const principal = auth
|
|
142
|
+
const principal = (auth === null || auth === void 0 ? void 0 : auth.username) || username || ((_a = options.auth) === null || _a === void 0 ? void 0 : _a.username);
|
|
139
143
|
if ((0, types_1.isString)(principal)) {
|
|
140
144
|
authentication = encodeURIComponent(principal) + '@';
|
|
141
145
|
}
|
|
142
146
|
}
|
|
143
|
-
else if (auth
|
|
147
|
+
else if (auth === null || auth === void 0 ? void 0 : auth.username) {
|
|
144
148
|
if (!MONGODB_V3) {
|
|
145
149
|
options.auth = auth;
|
|
146
150
|
}
|
|
@@ -304,7 +308,7 @@ function setCredential(item) {
|
|
|
304
308
|
return;
|
|
305
309
|
}
|
|
306
310
|
let username, password, pool;
|
|
307
|
-
if (typeof usePool === 'string' && (username = !MONGODB_V3 && options.auth
|
|
311
|
+
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))) {
|
|
308
312
|
[password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
|
|
309
313
|
if (pool) {
|
|
310
314
|
pool.add(item, password);
|
|
@@ -319,27 +323,27 @@ function setCredential(item) {
|
|
|
319
323
|
const { min, max, idle, queue_max, queue_idle } = config;
|
|
320
324
|
if (MONGODB_V360) {
|
|
321
325
|
if (min >= 0) {
|
|
322
|
-
options.minPoolSize
|
|
326
|
+
(_d = options.minPoolSize) !== null && _d !== void 0 ? _d : (options.minPoolSize = min);
|
|
323
327
|
}
|
|
324
328
|
if (max > 0) {
|
|
325
|
-
options.maxPoolSize
|
|
329
|
+
(_e = options.maxPoolSize) !== null && _e !== void 0 ? _e : (options.maxPoolSize = max);
|
|
326
330
|
}
|
|
327
331
|
if (idle >= 0) {
|
|
328
|
-
options.maxIdleTimeMS
|
|
332
|
+
(_f = options.maxIdleTimeMS) !== null && _f !== void 0 ? _f : (options.maxIdleTimeMS = idle);
|
|
329
333
|
}
|
|
330
334
|
if (queue_max > 0 && !MONGODB_V3) {
|
|
331
|
-
options.maxConnecting
|
|
335
|
+
(_g = options.maxConnecting) !== null && _g !== void 0 ? _g : (options.maxConnecting = queue_max);
|
|
332
336
|
}
|
|
333
337
|
if (queue_idle >= 0) {
|
|
334
|
-
options.waitQueueTimeoutMS
|
|
338
|
+
(_h = options.waitQueueTimeoutMS) !== null && _h !== void 0 ? _h : (options.waitQueueTimeoutMS = queue_idle);
|
|
335
339
|
}
|
|
336
340
|
}
|
|
337
341
|
else {
|
|
338
342
|
if (min >= 0) {
|
|
339
|
-
options.minSize
|
|
343
|
+
(_j = options.minSize) !== null && _j !== void 0 ? _j : (options.minSize = min);
|
|
340
344
|
}
|
|
341
345
|
if (max > 0) {
|
|
342
|
-
options.poolSize
|
|
346
|
+
(_k = options.poolSize) !== null && _k !== void 0 ? _k : (options.poolSize = max);
|
|
343
347
|
}
|
|
344
348
|
}
|
|
345
349
|
}
|
|
@@ -443,7 +447,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
443
447
|
continue;
|
|
444
448
|
}
|
|
445
449
|
item.transactionState = 1;
|
|
446
|
-
const getCollection = (target) => target.db(name, client
|
|
450
|
+
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);
|
|
447
451
|
const credential = mongoCredential || onceCredential || getCacheObject(item);
|
|
448
452
|
const renewCache = ignoreCache === 0;
|
|
449
453
|
const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
|
|
@@ -502,13 +506,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
502
506
|
onceCredential = undefined;
|
|
503
507
|
}
|
|
504
508
|
tasks[i] = new Promise(async (resolve, reject) => {
|
|
509
|
+
var _a, _b;
|
|
505
510
|
let commandType;
|
|
506
511
|
try {
|
|
507
512
|
let cursor;
|
|
508
513
|
if (pipeline || query) {
|
|
509
514
|
const collection = getCollection(mongoClient || await getConnection(item, credential));
|
|
510
515
|
if (pipeline) {
|
|
511
|
-
const aggregateOptions = aggregate
|
|
516
|
+
const aggregateOptions = aggregate === null || aggregate === void 0 ? void 0 : aggregate.options;
|
|
512
517
|
if (coercing) {
|
|
513
518
|
pipeline.forEach(doc => (0, types_1.coerceObject)(doc));
|
|
514
519
|
if (aggregateOptions) {
|
|
@@ -530,7 +535,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
530
535
|
}
|
|
531
536
|
if ((0, types_1.isArray)(update)) {
|
|
532
537
|
commandType = this.commandType.INSERT;
|
|
533
|
-
const insertOptions = item.execute
|
|
538
|
+
const insertOptions = (_a = item.execute) === null || _a === void 0 ? void 0 : _a.insert;
|
|
534
539
|
if (insertOptions && coercing) {
|
|
535
540
|
(0, types_1.coerceObject)(insertOptions);
|
|
536
541
|
}
|
|
@@ -560,7 +565,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
560
565
|
else {
|
|
561
566
|
if (update) {
|
|
562
567
|
commandType = this.commandType.UPDATE;
|
|
563
|
-
const updateOptions = item.execute
|
|
568
|
+
const updateOptions = (_b = item.execute) === null || _b === void 0 ? void 0 : _b.update;
|
|
564
569
|
if (updateOptions && coercing) {
|
|
565
570
|
(0, types_1.coerceObject)(updateOptions);
|
|
566
571
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/mongodb",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
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.6.
|
|
25
|
-
"@e-mc/request": "^0.6.
|
|
26
|
-
"@e-mc/types": "^0.6.
|
|
24
|
+
"@e-mc/db": "^0.6.7",
|
|
25
|
+
"@e-mc/request": "^0.6.7",
|
|
26
|
+
"@e-mc/types": "^0.6.7",
|
|
27
27
|
"mongodb": "^5.9.2"
|
|
28
28
|
}
|
|
29
29
|
}
|