@pi-r/mongodb 0.6.4 → 0.6.6
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 +6 -3
- package/client/index.js +17 -18
- package/package.json +5 -5
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
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
# @pi-r/mongodb
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Documentation
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
- [E-mc](https://e-mc.readthedocs.io/en/latest/db/mongodb.html)
|
|
6
|
+
- [squared](https://squared.readthedocs.io)
|
|
7
|
+
|
|
8
|
+
## LICENSE
|
|
6
9
|
|
|
7
10
|
MIT
|
package/client/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
exports.DB_SOURCE_TYPE = exports.DB_SOURCE_CLIENT = exports.getSortValue = exports.getFilterValue = exports.checkTimeout = exports.executeBatchQuery = exports.executeQuery = exports.setCredential = void 0;
|
|
4
3
|
const path = require("path");
|
|
5
4
|
const mongodb = require("mongodb");
|
|
@@ -80,7 +79,7 @@ function setCredential(item) {
|
|
|
80
79
|
const options = item.options || (item.options = {});
|
|
81
80
|
let uri = item.uri;
|
|
82
81
|
if (credential) {
|
|
83
|
-
let { protocol, server, hostname, port, username, password } = (0, util_1.parseServerAuth)(credential, 27017
|
|
82
|
+
let { protocol, server, hostname, port, username, password } = (0, util_1.parseServerAuth)(credential, 27017), { auth, authMechanism = 'DEFAULT', authSource, authMechanismProperties } = credential, authentication = '';
|
|
84
83
|
if (authMechanism === 'GSSAPI') {
|
|
85
84
|
const principal = auth?.username || username || options.auth?.username;
|
|
86
85
|
if ((0, types_1.isString)(principal)) {
|
|
@@ -95,10 +94,10 @@ function setCredential(item) {
|
|
|
95
94
|
authentication = (0, util_1.getBasicAuth)(username, password);
|
|
96
95
|
}
|
|
97
96
|
if (!server && hostname) {
|
|
98
|
-
server = hostname + ':' + (port || 27017
|
|
97
|
+
server = hostname + ':' + (port || 27017);
|
|
99
98
|
}
|
|
100
99
|
if (!server) {
|
|
101
|
-
throw (0, types_1.errorMessage)("mongodb"
|
|
100
|
+
throw (0, types_1.errorMessage)("mongodb", 'Not defined - server address');
|
|
102
101
|
}
|
|
103
102
|
uri = (protocol || 'mongodb:') + '//' + authentication + server;
|
|
104
103
|
}
|
|
@@ -143,7 +142,7 @@ function setCredential(item) {
|
|
|
143
142
|
uri += '&tls=true';
|
|
144
143
|
}
|
|
145
144
|
else {
|
|
146
|
-
throw (0, types_1.errorMessage)("mongodb"
|
|
145
|
+
throw (0, types_1.errorMessage)("mongodb", 'Missing TLS/SSL credentials');
|
|
147
146
|
}
|
|
148
147
|
authSource || (authSource = '$external');
|
|
149
148
|
break;
|
|
@@ -167,7 +166,7 @@ function setCredential(item) {
|
|
|
167
166
|
item.uri = uri;
|
|
168
167
|
}
|
|
169
168
|
else if (!(0, types_1.isString)(uri)) {
|
|
170
|
-
throw (0, types_1.errorMessage)("mongodb"
|
|
169
|
+
throw (0, types_1.errorMessage)("mongodb", 'Not defined - credentials');
|
|
171
170
|
}
|
|
172
171
|
const usePool = item.usePool;
|
|
173
172
|
if (!usePool) {
|
|
@@ -187,7 +186,7 @@ function setCredential(item) {
|
|
|
187
186
|
return;
|
|
188
187
|
}
|
|
189
188
|
}
|
|
190
|
-
const config = this.getPoolConfig("mongodb"
|
|
189
|
+
const config = this.getPoolConfig("mongodb", password);
|
|
191
190
|
if (config) {
|
|
192
191
|
const { min, max, idle, queue_max, queue_idle, timeout, socket_timeout } = config;
|
|
193
192
|
if (min >= 0) {
|
|
@@ -249,12 +248,12 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
249
248
|
if (!parallel) {
|
|
250
249
|
outResult || (outResult = new Array(length));
|
|
251
250
|
}
|
|
252
|
-
const caching = this.hasCache("mongodb"
|
|
251
|
+
const caching = this.hasCache("mongodb", sessionKey);
|
|
253
252
|
const tasks = new Array(length);
|
|
254
253
|
const clients = [];
|
|
255
254
|
let mongoClient, mongoCredential, mongoCache = 0, onceCredential = connectOnce ? getCacheObject(batch[0]) : undefined;
|
|
256
255
|
const getConnection = async (item, credential) => {
|
|
257
|
-
item.transactionState = 64
|
|
256
|
+
item.transactionState = 64;
|
|
258
257
|
const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(connectOnce ? batch[0] : item), ...connectOnce ? [item, batch[0]] : [item]);
|
|
259
258
|
let client;
|
|
260
259
|
if (pool) {
|
|
@@ -283,7 +282,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
283
282
|
mongoClient = client;
|
|
284
283
|
mongoCredential = credential;
|
|
285
284
|
}
|
|
286
|
-
item.transactionState &= ~64
|
|
285
|
+
item.transactionState &= ~64;
|
|
287
286
|
return client;
|
|
288
287
|
};
|
|
289
288
|
if (this.host?.username) {
|
|
@@ -294,7 +293,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
294
293
|
const { source, name, table, id, aggregate, sort, client, cacheObjectKey, ignoreCache } = item;
|
|
295
294
|
let { query, update, streamRow, limit = 0 } = item;
|
|
296
295
|
if (!table) {
|
|
297
|
-
const error = (0, types_1.errorMessage)(source, "Missing database table"
|
|
296
|
+
const error = (0, types_1.errorMessage)(source, "Missing database table");
|
|
298
297
|
++mongoCache;
|
|
299
298
|
if (this.handleFail(error, item, { errorQuery })) {
|
|
300
299
|
if (!parallel) {
|
|
@@ -311,13 +310,13 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
311
310
|
}
|
|
312
311
|
continue;
|
|
313
312
|
}
|
|
314
|
-
item.transactionState = 1
|
|
313
|
+
item.transactionState = 1;
|
|
315
314
|
const getInstance = (target) => target.db(name, client?.db);
|
|
316
315
|
const getCollection = (target) => getInstance(target).collection(table, client?.collection);
|
|
317
316
|
const runCommand = async (target, document) => getInstance(target).command(document, client?.command);
|
|
318
317
|
const credential = mongoCredential || onceCredential || getCacheObject(item);
|
|
319
318
|
const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
|
|
320
|
-
const coercing = this.hasCoerce("mongodb"
|
|
319
|
+
const coercing = this.hasCoerce("mongodb", 'options', credential.uuidKey);
|
|
321
320
|
const targetObject = typeof checkObject === 'string' ? coercing && (0, types_1.asFunction)(checkObject) : checkObject;
|
|
322
321
|
if (typeof streamRow === 'string') {
|
|
323
322
|
streamRow = coercing && (0, types_1.asFunction)(streamRow);
|
|
@@ -343,7 +342,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
343
342
|
else {
|
|
344
343
|
outResult[i] = rows;
|
|
345
344
|
}
|
|
346
|
-
this.add(item, 4
|
|
345
|
+
this.add(item, 4 | 128);
|
|
347
346
|
return true;
|
|
348
347
|
}
|
|
349
348
|
return false;
|
|
@@ -378,7 +377,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
378
377
|
const command = item.command;
|
|
379
378
|
if (command) {
|
|
380
379
|
await Promise.all((!Array.isArray(command) ? [command] : command).map(async (cmd) => runCommand(instance, cmd)))
|
|
381
|
-
.then(items => items.forEach(output => this.addLog(this.statusType.INFO, output, "mongodb"
|
|
380
|
+
.then(items => items.forEach(output => this.addLog(this.statusType.INFO, output, "mongodb", 'runCommand')));
|
|
382
381
|
}
|
|
383
382
|
const collection = getCollection(instance);
|
|
384
383
|
if (update && coercing) {
|
|
@@ -482,7 +481,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
482
481
|
reject(error);
|
|
483
482
|
}
|
|
484
483
|
else {
|
|
485
|
-
this.add(item, 4
|
|
484
|
+
this.add(item, 4);
|
|
486
485
|
resolve(!error ? this.setQueryResult(source, removePoolProperties(mongoCredential || credential), queryString, rows, cacheValue) : rows);
|
|
487
486
|
}
|
|
488
487
|
})
|
|
@@ -493,14 +492,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
493
492
|
}
|
|
494
493
|
}
|
|
495
494
|
if (rows) {
|
|
496
|
-
this.add(item, 4
|
|
495
|
+
this.add(item, 4);
|
|
497
496
|
if (targetObject) {
|
|
498
497
|
rows = targetObject(item, rows);
|
|
499
498
|
}
|
|
500
499
|
resolve(this.setQueryResult(source, removePoolProperties(mongoCredential || credential), queryString, rows, cacheValue));
|
|
501
500
|
}
|
|
502
501
|
else {
|
|
503
|
-
throw (0, types_1.errorMessage)(source, "Missing database query"
|
|
502
|
+
throw (0, types_1.errorMessage)(source, "Missing database query");
|
|
504
503
|
}
|
|
505
504
|
}
|
|
506
505
|
catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/mongodb",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
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.8.
|
|
25
|
-
"@e-mc/request": "^0.8.
|
|
26
|
-
"@e-mc/types": "^0.8.
|
|
27
|
-
"mongodb": "^6.
|
|
24
|
+
"@e-mc/db": "^0.8.7",
|
|
25
|
+
"@e-mc/request": "^0.8.7",
|
|
26
|
+
"@e-mc/types": "^0.8.7",
|
|
27
|
+
"mongodb": "^6.5.0"
|
|
28
28
|
}
|
|
29
29
|
}
|