@pi-r/mongodb 0.5.3 → 0.5.4
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/README.md +1 -1
- package/client/index.js +19 -16
- 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/README.md
CHANGED
package/client/index.js
CHANGED
|
@@ -35,11 +35,12 @@ class MongoDBPool extends DbPool {
|
|
|
35
35
|
return topology ? super.closeable || topology.s.state === 'closing' : true;
|
|
36
36
|
}
|
|
37
37
|
get closed() {
|
|
38
|
+
var _a;
|
|
38
39
|
const topology = this.client.topology;
|
|
39
40
|
if (topology && (this.success > 0 || this.failed > 0)) {
|
|
40
41
|
return topology.isDestroyed();
|
|
41
42
|
}
|
|
42
|
-
return this.client.s
|
|
43
|
+
return ((_a = this.client.s) === null || _a === void 0 ? void 0 : _a.hasBeenClosed) === true;
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
const POOL_STATE = {};
|
|
@@ -63,7 +64,7 @@ function removePoolProperties(credential) {
|
|
|
63
64
|
}
|
|
64
65
|
function getCacheObject(item) {
|
|
65
66
|
const credential = item.credential;
|
|
66
|
-
return { uri: item.uri, options: item.options, uuidKey: credential
|
|
67
|
+
return { uri: item.uri, options: item.options, uuidKey: credential === null || credential === void 0 ? void 0 : credential.uuidKey };
|
|
67
68
|
}
|
|
68
69
|
function getPoolKey(credential) {
|
|
69
70
|
const options = credential.options;
|
|
@@ -78,18 +79,19 @@ function getPoolKey(credential) {
|
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
function setCredential(item) {
|
|
82
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
81
83
|
const credential = this.getCredential(item);
|
|
82
84
|
const options = item.options || (item.options = {});
|
|
83
85
|
let uri = item.uri;
|
|
84
86
|
if (credential) {
|
|
85
87
|
let { protocol, server, hostname, port, username, password } = (0, util_1.parseServerAuth)(credential, 27017), { auth, authMechanism = 'DEFAULT', authSource, authMechanismProperties } = credential, authentication = '';
|
|
86
88
|
if (authMechanism === 'GSSAPI') {
|
|
87
|
-
const principal = auth
|
|
89
|
+
const principal = (auth === null || auth === void 0 ? void 0 : auth.username) || username || ((_a = options.auth) === null || _a === void 0 ? void 0 : _a.username);
|
|
88
90
|
if ((0, types_1.isString)(principal)) {
|
|
89
91
|
authentication = encodeURIComponent(principal) + '@';
|
|
90
92
|
}
|
|
91
93
|
}
|
|
92
|
-
else if (auth
|
|
94
|
+
else if (auth === null || auth === void 0 ? void 0 : auth.username) {
|
|
93
95
|
options.auth = auth;
|
|
94
96
|
}
|
|
95
97
|
if (!uri || !Db.isURL(uri)) {
|
|
@@ -177,7 +179,7 @@ function setCredential(item) {
|
|
|
177
179
|
const usePool = item.usePool;
|
|
178
180
|
if (usePool) {
|
|
179
181
|
let username, password, pool;
|
|
180
|
-
if (typeof usePool === 'string' && (username = options.auth
|
|
182
|
+
if (typeof usePool === 'string' && (username = ((_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))) {
|
|
181
183
|
[password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
|
|
182
184
|
if (pool) {
|
|
183
185
|
pool.add(item, password);
|
|
@@ -191,25 +193,25 @@ function setCredential(item) {
|
|
|
191
193
|
if (config) {
|
|
192
194
|
const { min, max, idle, queue_max, queue_idle, timeout, socket_timeout } = config;
|
|
193
195
|
if (min >= 0) {
|
|
194
|
-
options.minPoolSize
|
|
196
|
+
(_d = options.minPoolSize) !== null && _d !== void 0 ? _d : (options.minPoolSize = min);
|
|
195
197
|
}
|
|
196
198
|
if (max > 0) {
|
|
197
|
-
options.maxPoolSize
|
|
199
|
+
(_e = options.maxPoolSize) !== null && _e !== void 0 ? _e : (options.maxPoolSize = max);
|
|
198
200
|
}
|
|
199
201
|
if (idle >= 0) {
|
|
200
|
-
options.maxIdleTimeMS
|
|
202
|
+
(_f = options.maxIdleTimeMS) !== null && _f !== void 0 ? _f : (options.maxIdleTimeMS = idle);
|
|
201
203
|
}
|
|
202
204
|
if (queue_max > 0) {
|
|
203
|
-
options.maxConnecting
|
|
205
|
+
(_g = options.maxConnecting) !== null && _g !== void 0 ? _g : (options.maxConnecting = queue_max);
|
|
204
206
|
}
|
|
205
207
|
if (queue_idle >= 0) {
|
|
206
|
-
options.waitQueueTimeoutMS
|
|
208
|
+
(_h = options.waitQueueTimeoutMS) !== null && _h !== void 0 ? _h : (options.waitQueueTimeoutMS = queue_idle);
|
|
207
209
|
}
|
|
208
210
|
if (timeout > 0) {
|
|
209
|
-
options.connectTimeoutMS
|
|
211
|
+
(_j = options.connectTimeoutMS) !== null && _j !== void 0 ? _j : (options.connectTimeoutMS = timeout);
|
|
210
212
|
}
|
|
211
213
|
if (socket_timeout > 0) {
|
|
212
|
-
options.socketTimeoutMS
|
|
214
|
+
(_k = options.socketTimeoutMS) !== null && _k !== void 0 ? _k : (options.socketTimeoutMS = socket_timeout);
|
|
213
215
|
}
|
|
214
216
|
}
|
|
215
217
|
new MongoDBPool(new mongodb.MongoClient(item.uri, options), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
|
|
@@ -312,7 +314,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
312
314
|
continue;
|
|
313
315
|
}
|
|
314
316
|
item.transactionState = 1;
|
|
315
|
-
const getCollection = (target) => target.db(name, client
|
|
317
|
+
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);
|
|
316
318
|
const credential = mongoCredential || onceCredential || getCacheObject(item);
|
|
317
319
|
const renewCache = ignoreCache === 0;
|
|
318
320
|
const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
|
|
@@ -371,13 +373,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
371
373
|
onceCredential = undefined;
|
|
372
374
|
}
|
|
373
375
|
tasks[i] = new Promise(async (resolve, reject) => {
|
|
376
|
+
var _a, _b;
|
|
374
377
|
let commandType;
|
|
375
378
|
try {
|
|
376
379
|
let cursor;
|
|
377
380
|
if (pipeline || query) {
|
|
378
381
|
const collection = getCollection(mongoClient || await getConnection(item, credential));
|
|
379
382
|
if (pipeline) {
|
|
380
|
-
const aggregateOptions = aggregate
|
|
383
|
+
const aggregateOptions = aggregate === null || aggregate === void 0 ? void 0 : aggregate.options;
|
|
381
384
|
if (coercing) {
|
|
382
385
|
pipeline.forEach(doc => (0, types_1.coerceObject)(doc));
|
|
383
386
|
if (aggregateOptions) {
|
|
@@ -399,7 +402,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
399
402
|
}
|
|
400
403
|
if ((0, types_1.isArray)(update)) {
|
|
401
404
|
commandType = this.commandType.INSERT;
|
|
402
|
-
const insertOptions = item.execute
|
|
405
|
+
const insertOptions = (_a = item.execute) === null || _a === void 0 ? void 0 : _a.insert;
|
|
403
406
|
if (insertOptions && coercing) {
|
|
404
407
|
(0, types_1.coerceObject)(insertOptions);
|
|
405
408
|
}
|
|
@@ -429,7 +432,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
429
432
|
else {
|
|
430
433
|
if (update) {
|
|
431
434
|
commandType = this.commandType.UPDATE;
|
|
432
|
-
const updateOptions = item.execute
|
|
435
|
+
const updateOptions = (_b = item.execute) === null || _b === void 0 ? void 0 : _b.update;
|
|
433
436
|
if (updateOptions && coercing) {
|
|
434
437
|
(0, types_1.coerceObject)(updateOptions);
|
|
435
438
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/mongodb",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
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.7.
|
|
25
|
-
"@e-mc/request": "^0.7.
|
|
26
|
-
"@e-mc/types": "^0.7.
|
|
24
|
+
"@e-mc/db": "^0.7.5",
|
|
25
|
+
"@e-mc/request": "^0.7.5",
|
|
26
|
+
"@e-mc/types": "^0.7.5",
|
|
27
27
|
"mongodb": "^6.5.0"
|
|
28
28
|
}
|
|
29
29
|
}
|