@pi-r/mongodb 0.3.1 → 0.3.2
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 +21 -21
- package/package.json +6 -6
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2023
|
|
1
|
+
Copyright 2023 Studio Trigger
|
|
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
|
@@ -8,10 +8,10 @@ const util_1 = require("@e-mc/db/util");
|
|
|
8
8
|
const Db = require("@e-mc/db");
|
|
9
9
|
const Request = require("@e-mc/request");
|
|
10
10
|
const DbPool = require('@e-mc/db/pool');
|
|
11
|
-
const MONGODB_V3 = Db.checkSemVer("mongodb"
|
|
12
|
-
const MONGODB_V330 = Db.checkSemVer("mongodb"
|
|
13
|
-
const MONGODB_V333 = Db.checkSemVer("mongodb"
|
|
14
|
-
const MONGODB_V360 = Db.checkSemVer("mongodb"
|
|
11
|
+
const MONGODB_V3 = Db.checkSemVer("mongodb", 1, 4);
|
|
12
|
+
const MONGODB_V330 = Db.checkSemVer("mongodb", '3.3.0');
|
|
13
|
+
const MONGODB_V333 = Db.checkSemVer("mongodb", '3.3.0', '3.3.3');
|
|
14
|
+
const MONGODB_V360 = Db.checkSemVer("mongodb", '3.6.0');
|
|
15
15
|
const MONGODB_TOPOLOGY = MONGODB_V3 && MONGODB_V330;
|
|
16
16
|
const MONGODB_NOPOOL = MONGODB_V3 && !MONGODB_V330;
|
|
17
17
|
class MongoDBPool extends DbPool {
|
|
@@ -133,7 +133,7 @@ function setCredential(item) {
|
|
|
133
133
|
const options = item.options || (item.options = {});
|
|
134
134
|
let uri = item.uri;
|
|
135
135
|
if (credential) {
|
|
136
|
-
let { protocol, server, hostname, port, username, password } = (0, util_1.parseServerAuth)(credential, 27017
|
|
136
|
+
let { protocol, server, hostname, port, username, password } = (0, util_1.parseServerAuth)(credential, 27017), { auth, authMechanism = 'DEFAULT', authSource, authMechanismProperties } = credential, authentication = '';
|
|
137
137
|
if (authMechanism === 'GSSAPI') {
|
|
138
138
|
const principal = auth?.username || username || options.auth?.username;
|
|
139
139
|
if ((0, types_1.isString)(principal)) {
|
|
@@ -154,10 +154,10 @@ function setCredential(item) {
|
|
|
154
154
|
authentication = (0, util_1.getBasicAuth)(username, password);
|
|
155
155
|
}
|
|
156
156
|
if (!server && hostname) {
|
|
157
|
-
server = hostname + ':' + (port || 27017
|
|
157
|
+
server = hostname + ':' + (port || 27017);
|
|
158
158
|
}
|
|
159
159
|
if (!server) {
|
|
160
|
-
throw (0, types_1.errorMessage)("mongodb"
|
|
160
|
+
throw (0, types_1.errorMessage)("mongodb", 'Not defined - server address');
|
|
161
161
|
}
|
|
162
162
|
uri = (protocol || 'mongodb:') + '//' + authentication + server;
|
|
163
163
|
}
|
|
@@ -253,7 +253,7 @@ function setCredential(item) {
|
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
if (!valid) {
|
|
256
|
-
throw (0, types_1.errorMessage)("mongodb"
|
|
256
|
+
throw (0, types_1.errorMessage)("mongodb", 'Missing TLS/SSL credentials');
|
|
257
257
|
}
|
|
258
258
|
authSource || (authSource = '$external');
|
|
259
259
|
break;
|
|
@@ -271,7 +271,7 @@ function setCredential(item) {
|
|
|
271
271
|
else if ((0, types_1.isString)(authMechanismProperties)) {
|
|
272
272
|
serviceName = authMechanismProperties;
|
|
273
273
|
}
|
|
274
|
-
serviceName || (serviceName = "mongodb"
|
|
274
|
+
serviceName || (serviceName = "mongodb");
|
|
275
275
|
uri += !MONGODB_V3 ? '&authMechanismProperties=' + encodeURIComponent('SERVICE_NAME:' + serviceName) : '&gssapiServiceName=' + encodeURIComponent(serviceName);
|
|
276
276
|
break;
|
|
277
277
|
}
|
|
@@ -292,7 +292,7 @@ function setCredential(item) {
|
|
|
292
292
|
item.uri = uri;
|
|
293
293
|
}
|
|
294
294
|
else if (!(0, types_1.isString)(uri)) {
|
|
295
|
-
throw (0, types_1.errorMessage)("mongodb"
|
|
295
|
+
throw (0, types_1.errorMessage)("mongodb", 'Not defined - credentials');
|
|
296
296
|
}
|
|
297
297
|
if (MONGODB_TOPOLOGY) {
|
|
298
298
|
options.useUnifiedTopology = true;
|
|
@@ -314,7 +314,7 @@ function setCredential(item) {
|
|
|
314
314
|
const poolKey = getPoolKey(item);
|
|
315
315
|
if (poolKey) {
|
|
316
316
|
if (!(pool = POOL_STATE[poolKey]) || pool.closed) {
|
|
317
|
-
const config = this.getPoolConfig("mongodb"
|
|
317
|
+
const config = this.getPoolConfig("mongodb", password);
|
|
318
318
|
if (config) {
|
|
319
319
|
const { min, max, idle, queue_max, queue_idle } = config;
|
|
320
320
|
if (MONGODB_V360) {
|
|
@@ -384,12 +384,12 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
384
384
|
if (!parallel) {
|
|
385
385
|
outResult || (outResult = new Array(length));
|
|
386
386
|
}
|
|
387
|
-
const caching = this.hasCache("mongodb"
|
|
387
|
+
const caching = this.hasCache("mongodb", sessionKey);
|
|
388
388
|
const tasks = new Array(length);
|
|
389
389
|
const clients = [];
|
|
390
390
|
let mongoClient, mongoCredential, mongoCache = 0, onceCredential = connectOnce ? getCacheObject(batch[0]) : undefined;
|
|
391
391
|
const getConnection = async (item, credential) => {
|
|
392
|
-
item.transactionState = 64
|
|
392
|
+
item.transactionState = 64;
|
|
393
393
|
const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(connectOnce ? batch[0] : item), ...connectOnce ? [item, batch[0]] : [item]);
|
|
394
394
|
let client;
|
|
395
395
|
if (pool) {
|
|
@@ -417,7 +417,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
417
417
|
mongoClient = client;
|
|
418
418
|
mongoCredential = credential;
|
|
419
419
|
}
|
|
420
|
-
item.transactionState &= ~64
|
|
420
|
+
item.transactionState &= ~64;
|
|
421
421
|
return client;
|
|
422
422
|
};
|
|
423
423
|
for (let i = 0; i < length; ++i) {
|
|
@@ -425,7 +425,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
425
425
|
const { source, name, table, id, aggregate, sort, client, cacheObjectKey, ignoreCache } = item;
|
|
426
426
|
let { query, update, streamRow, limit = 0 } = item;
|
|
427
427
|
if (!table) {
|
|
428
|
-
const error = (0, types_1.errorMessage)(source, "Missing database table"
|
|
428
|
+
const error = (0, types_1.errorMessage)(source, "Missing database table");
|
|
429
429
|
++mongoCache;
|
|
430
430
|
if (this.handleFail(error, item, { errorQuery })) {
|
|
431
431
|
if (!parallel) {
|
|
@@ -442,12 +442,12 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
442
442
|
}
|
|
443
443
|
continue;
|
|
444
444
|
}
|
|
445
|
-
item.transactionState = 1
|
|
445
|
+
item.transactionState = 1;
|
|
446
446
|
const getCollection = (target) => target.db(name, client?.db).collection(table, client?.collection);
|
|
447
447
|
const credential = mongoCredential || onceCredential || getCacheObject(item);
|
|
448
448
|
const renewCache = ignoreCache === 0;
|
|
449
449
|
const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
|
|
450
|
-
const coercing = this.hasCoerce("mongodb"
|
|
450
|
+
const coercing = this.hasCoerce("mongodb", 'options', credential.uuidKey);
|
|
451
451
|
const targetObject = typeof checkObject === 'string' ? coercing && (0, types_1.asFunction)(checkObject) : checkObject;
|
|
452
452
|
if (typeof streamRow === 'string') {
|
|
453
453
|
streamRow = coercing && (0, types_1.asFunction)(streamRow);
|
|
@@ -473,7 +473,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
473
473
|
else {
|
|
474
474
|
outResult[i] = rows;
|
|
475
475
|
}
|
|
476
|
-
this.add(item, 4
|
|
476
|
+
this.add(item, 4 | 128);
|
|
477
477
|
return true;
|
|
478
478
|
}
|
|
479
479
|
return false;
|
|
@@ -608,7 +608,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
608
608
|
reject(error);
|
|
609
609
|
}
|
|
610
610
|
else {
|
|
611
|
-
this.add(item, 4
|
|
611
|
+
this.add(item, 4);
|
|
612
612
|
resolve(!error ? this.setQueryResult(source, removePoolProperties(mongoCredential || credential), queryString, rows, cacheValue) : rows);
|
|
613
613
|
}
|
|
614
614
|
})
|
|
@@ -619,14 +619,14 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
619
619
|
}
|
|
620
620
|
}
|
|
621
621
|
if (rows) {
|
|
622
|
-
this.add(item, 4
|
|
622
|
+
this.add(item, 4);
|
|
623
623
|
if (targetObject) {
|
|
624
624
|
rows = targetObject(item, rows);
|
|
625
625
|
}
|
|
626
626
|
resolve(this.setQueryResult(source, removePoolProperties(mongoCredential || credential), queryString, rows, cacheValue));
|
|
627
627
|
}
|
|
628
628
|
else {
|
|
629
|
-
throw (0, types_1.errorMessage)(source, "Missing database query"
|
|
629
|
+
throw (0, types_1.errorMessage)(source, "Missing database query");
|
|
630
630
|
}
|
|
631
631
|
}
|
|
632
632
|
catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/mongodb",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
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.6.
|
|
25
|
-
"@e-mc/request": "^0.6.
|
|
26
|
-
"@e-mc/types": "^0.6.
|
|
27
|
-
"mongodb": "^5.9.
|
|
24
|
+
"@e-mc/db": "^0.6.1",
|
|
25
|
+
"@e-mc/request": "^0.6.1",
|
|
26
|
+
"@e-mc/types": "^0.6.1",
|
|
27
|
+
"mongodb": "^5.9.2"
|
|
28
28
|
}
|
|
29
29
|
}
|