@pi-r/mongodb 0.5.1 → 0.5.3
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 +4 -2
- package/client/index.js +17 -17
- package/package.json +6 -6
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2023
|
|
1
|
+
Copyright 2023 Haruhi Suzumiya
|
|
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
|
@@ -50,7 +50,7 @@ function removePoolProperties(credential) {
|
|
|
50
50
|
let result;
|
|
51
51
|
for (let i = 0, length = POOL_UNUSED.length; i < length; ++i) {
|
|
52
52
|
const attr = POOL_UNUSED[i];
|
|
53
|
-
if (attr in
|
|
53
|
+
if (attr in credential) {
|
|
54
54
|
result || (result = { ...options });
|
|
55
55
|
delete result[attr];
|
|
56
56
|
}
|
|
@@ -82,7 +82,7 @@ function setCredential(item) {
|
|
|
82
82
|
const options = item.options || (item.options = {});
|
|
83
83
|
let uri = item.uri;
|
|
84
84
|
if (credential) {
|
|
85
|
-
let { protocol, server, hostname, port, username, password } = (0, util_1.parseServerAuth)(credential, 27017
|
|
85
|
+
let { protocol, server, hostname, port, username, password } = (0, util_1.parseServerAuth)(credential, 27017), { auth, authMechanism = 'DEFAULT', authSource, authMechanismProperties } = credential, authentication = '';
|
|
86
86
|
if (authMechanism === 'GSSAPI') {
|
|
87
87
|
const principal = auth?.username || username || options.auth?.username;
|
|
88
88
|
if ((0, types_1.isString)(principal)) {
|
|
@@ -97,10 +97,10 @@ function setCredential(item) {
|
|
|
97
97
|
authentication = (0, util_1.getBasicAuth)(username, password);
|
|
98
98
|
}
|
|
99
99
|
if (!server && hostname) {
|
|
100
|
-
server = hostname + ':' + (port || 27017
|
|
100
|
+
server = hostname + ':' + (port || 27017);
|
|
101
101
|
}
|
|
102
102
|
if (!server) {
|
|
103
|
-
throw (0, types_1.errorMessage)("mongodb"
|
|
103
|
+
throw (0, types_1.errorMessage)("mongodb", 'Not defined - server address');
|
|
104
104
|
}
|
|
105
105
|
uri = (protocol || 'mongodb:') + '//' + authentication + server;
|
|
106
106
|
}
|
|
@@ -148,7 +148,7 @@ function setCredential(item) {
|
|
|
148
148
|
uri += '&tls=true';
|
|
149
149
|
}
|
|
150
150
|
else {
|
|
151
|
-
throw (0, types_1.errorMessage)("mongodb"
|
|
151
|
+
throw (0, types_1.errorMessage)("mongodb", 'Missing TLS/SSL credentials');
|
|
152
152
|
}
|
|
153
153
|
authSource || (authSource = '$external');
|
|
154
154
|
break;
|
|
@@ -172,7 +172,7 @@ function setCredential(item) {
|
|
|
172
172
|
item.uri = uri;
|
|
173
173
|
}
|
|
174
174
|
else if (!(0, types_1.isString)(uri)) {
|
|
175
|
-
throw (0, types_1.errorMessage)("mongodb"
|
|
175
|
+
throw (0, types_1.errorMessage)("mongodb", 'Not defined - credentials');
|
|
176
176
|
}
|
|
177
177
|
const usePool = item.usePool;
|
|
178
178
|
if (usePool) {
|
|
@@ -187,7 +187,7 @@ function setCredential(item) {
|
|
|
187
187
|
const poolKey = getPoolKey(item);
|
|
188
188
|
if (poolKey) {
|
|
189
189
|
if (!(pool = POOL_STATE[poolKey]) || pool.closed) {
|
|
190
|
-
const config = this.getPoolConfig("mongodb"
|
|
190
|
+
const config = this.getPoolConfig("mongodb", password);
|
|
191
191
|
if (config) {
|
|
192
192
|
const { min, max, idle, queue_max, queue_idle, timeout, socket_timeout } = config;
|
|
193
193
|
if (min >= 0) {
|
|
@@ -253,12 +253,12 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
253
253
|
if (!parallel) {
|
|
254
254
|
outResult || (outResult = new Array(length));
|
|
255
255
|
}
|
|
256
|
-
const caching = this.hasCache("mongodb"
|
|
256
|
+
const caching = this.hasCache("mongodb", sessionKey);
|
|
257
257
|
const tasks = new Array(length);
|
|
258
258
|
const clients = [];
|
|
259
259
|
let mongoClient, mongoCredential, mongoCache = 0, onceCredential = connectOnce ? getCacheObject(batch[0]) : undefined;
|
|
260
260
|
const getConnection = async (item, credential) => {
|
|
261
|
-
item.transactionState = 64
|
|
261
|
+
item.transactionState = 64;
|
|
262
262
|
const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(connectOnce ? batch[0] : item), ...connectOnce ? [item, batch[0]] : [item]);
|
|
263
263
|
let client;
|
|
264
264
|
if (pool) {
|
|
@@ -286,7 +286,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
286
286
|
mongoClient = client;
|
|
287
287
|
mongoCredential = credential;
|
|
288
288
|
}
|
|
289
|
-
item.transactionState &= ~64
|
|
289
|
+
item.transactionState &= ~64;
|
|
290
290
|
return client;
|
|
291
291
|
};
|
|
292
292
|
for (let i = 0; i < length; ++i) {
|
|
@@ -294,7 +294,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
294
294
|
const { source, name, table, id, aggregate, sort, client, cacheObjectKey, ignoreCache } = item;
|
|
295
295
|
let { query, update, streamRow, limit = 0 } = item;
|
|
296
296
|
if (!table) {
|
|
297
|
-
const error = (0, types_1.errorMessage)(source, "Missing database table"
|
|
297
|
+
const error = (0, types_1.errorMessage)(source, "Missing database table");
|
|
298
298
|
++mongoCache;
|
|
299
299
|
if (this.handleFail(error, item, { errorQuery })) {
|
|
300
300
|
if (!parallel) {
|
|
@@ -311,12 +311,12 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
311
311
|
}
|
|
312
312
|
continue;
|
|
313
313
|
}
|
|
314
|
-
item.transactionState = 1
|
|
314
|
+
item.transactionState = 1;
|
|
315
315
|
const getCollection = (target) => target.db(name, client?.db).collection(table, client?.collection);
|
|
316
316
|
const credential = mongoCredential || onceCredential || getCacheObject(item);
|
|
317
317
|
const renewCache = ignoreCache === 0;
|
|
318
318
|
const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
|
|
319
|
-
const coercing = this.hasCoerce("mongodb"
|
|
319
|
+
const coercing = this.hasCoerce("mongodb", 'options', credential.uuidKey);
|
|
320
320
|
const targetObject = typeof checkObject === 'string' ? coercing && (0, types_1.asFunction)(checkObject) : checkObject;
|
|
321
321
|
if (typeof streamRow === 'string') {
|
|
322
322
|
streamRow = coercing && (0, types_1.asFunction)(streamRow);
|
|
@@ -342,7 +342,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
342
342
|
else {
|
|
343
343
|
outResult[i] = rows;
|
|
344
344
|
}
|
|
345
|
-
this.add(item, 4
|
|
345
|
+
this.add(item, 4 | 128);
|
|
346
346
|
return true;
|
|
347
347
|
}
|
|
348
348
|
return false;
|
|
@@ -477,7 +477,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
477
477
|
reject(error);
|
|
478
478
|
}
|
|
479
479
|
else {
|
|
480
|
-
this.add(item, 4
|
|
480
|
+
this.add(item, 4);
|
|
481
481
|
resolve(!error ? this.setQueryResult(source, removePoolProperties(mongoCredential || credential), queryString, rows, cacheValue) : rows);
|
|
482
482
|
}
|
|
483
483
|
})
|
|
@@ -488,14 +488,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
488
488
|
}
|
|
489
489
|
}
|
|
490
490
|
if (rows) {
|
|
491
|
-
this.add(item, 4
|
|
491
|
+
this.add(item, 4);
|
|
492
492
|
if (targetObject) {
|
|
493
493
|
rows = targetObject(item, rows);
|
|
494
494
|
}
|
|
495
495
|
resolve(this.setQueryResult(source, removePoolProperties(mongoCredential || credential), queryString, rows, cacheValue));
|
|
496
496
|
}
|
|
497
497
|
else {
|
|
498
|
-
throw (0, types_1.errorMessage)(source, "Missing database query"
|
|
498
|
+
throw (0, types_1.errorMessage)(source, "Missing database query");
|
|
499
499
|
}
|
|
500
500
|
}
|
|
501
501
|
catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/mongodb",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "MongoDB client driver for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"types": "client/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/anpham6/pi-r.git",
|
|
12
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
13
13
|
"directory": "src/db/mongodb"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
@@ -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.
|
|
27
|
-
"mongodb": "^6.
|
|
24
|
+
"@e-mc/db": "^0.7.3",
|
|
25
|
+
"@e-mc/request": "^0.7.3",
|
|
26
|
+
"@e-mc/types": "^0.7.3",
|
|
27
|
+
"mongodb": "^6.5.0"
|
|
28
28
|
}
|
|
29
29
|
}
|