@pi-r/mongodb 0.2.3 → 0.2.8
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 +23 -23
- package/package.json +6 -6
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2023
|
|
1
|
+
Copyright 2023 Mile Square Park
|
|
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
|
@@ -7,10 +7,10 @@ const util_1 = require("@e-mc/db/util");
|
|
|
7
7
|
const Db = require("@e-mc/db");
|
|
8
8
|
const Request = require("@e-mc/request");
|
|
9
9
|
const DbPool = require('@e-mc/db/pool');
|
|
10
|
-
const MONGODB_V3 = Db.checkSemVer("mongodb"
|
|
11
|
-
const MONGODB_V330 = Db.checkSemVer("mongodb"
|
|
12
|
-
const MONGODB_V333 = Db.checkSemVer("mongodb"
|
|
13
|
-
const MONGODB_V360 = Db.checkSemVer("mongodb"
|
|
10
|
+
const MONGODB_V3 = Db.checkSemVer("mongodb", 1, 4);
|
|
11
|
+
const MONGODB_V330 = Db.checkSemVer("mongodb", '3.3.0');
|
|
12
|
+
const MONGODB_V333 = Db.checkSemVer("mongodb", '3.3.0', '3.3.3');
|
|
13
|
+
const MONGODB_V360 = Db.checkSemVer("mongodb", '3.6.0');
|
|
14
14
|
const MONGODB_TOPOLOGY = MONGODB_V3 && MONGODB_V330;
|
|
15
15
|
const MONGODB_NOPOOL = MONGODB_V3 && !MONGODB_V330;
|
|
16
16
|
class MongoDBPool extends DbPool {
|
|
@@ -132,7 +132,7 @@ function setCredential(item) {
|
|
|
132
132
|
const options = item.options || (item.options = {});
|
|
133
133
|
let uri = item.uri;
|
|
134
134
|
if (credential) {
|
|
135
|
-
let { protocol, server, hostname, port, username, password } = (0, util_1.parseServerAuth)(credential, 27017
|
|
135
|
+
let { protocol, server, hostname, port, username, password } = (0, util_1.parseServerAuth)(credential, 27017), { auth, authMechanism = 'DEFAULT', authSource, authMechanismProperties } = credential, authentication = '';
|
|
136
136
|
if (authMechanism === 'GSSAPI') {
|
|
137
137
|
const principal = auth?.username || username || options.auth?.username;
|
|
138
138
|
if ((0, types_1.isString)(principal)) {
|
|
@@ -153,10 +153,10 @@ function setCredential(item) {
|
|
|
153
153
|
authentication = (0, util_1.getBasicAuth)(username, password);
|
|
154
154
|
}
|
|
155
155
|
if (!server && hostname) {
|
|
156
|
-
server = hostname + ':' + (port || 27017
|
|
156
|
+
server = hostname + ':' + (port || 27017);
|
|
157
157
|
}
|
|
158
158
|
if (!server) {
|
|
159
|
-
throw (0, types_1.errorMessage)("mongodb"
|
|
159
|
+
throw (0, types_1.errorMessage)("mongodb", 'Not defined - server address');
|
|
160
160
|
}
|
|
161
161
|
uri = (protocol || 'mongodb:') + '//' + authentication + server;
|
|
162
162
|
}
|
|
@@ -252,7 +252,7 @@ function setCredential(item) {
|
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
254
|
if (!valid) {
|
|
255
|
-
throw (0, types_1.errorMessage)("mongodb"
|
|
255
|
+
throw (0, types_1.errorMessage)("mongodb", 'Missing TLS/SSL credentials');
|
|
256
256
|
}
|
|
257
257
|
authSource || (authSource = '$external');
|
|
258
258
|
break;
|
|
@@ -270,7 +270,7 @@ function setCredential(item) {
|
|
|
270
270
|
else if ((0, types_1.isString)(authMechanismProperties)) {
|
|
271
271
|
serviceName = authMechanismProperties;
|
|
272
272
|
}
|
|
273
|
-
serviceName || (serviceName = "mongodb"
|
|
273
|
+
serviceName || (serviceName = "mongodb");
|
|
274
274
|
uri += !MONGODB_V3 ? '&authMechanismProperties=' + encodeURIComponent('SERVICE_NAME:' + serviceName) : '&gssapiServiceName=' + encodeURIComponent(serviceName);
|
|
275
275
|
break;
|
|
276
276
|
}
|
|
@@ -291,7 +291,7 @@ function setCredential(item) {
|
|
|
291
291
|
item.uri = uri;
|
|
292
292
|
}
|
|
293
293
|
else if (!(0, types_1.isString)(uri)) {
|
|
294
|
-
throw (0, types_1.errorMessage)("mongodb"
|
|
294
|
+
throw (0, types_1.errorMessage)("mongodb", 'Not defined - credentials');
|
|
295
295
|
}
|
|
296
296
|
if (MONGODB_TOPOLOGY) {
|
|
297
297
|
options.useUnifiedTopology = true;
|
|
@@ -313,7 +313,7 @@ function setCredential(item) {
|
|
|
313
313
|
const poolKey = getPoolKey(item);
|
|
314
314
|
if (poolKey) {
|
|
315
315
|
if (!(pool = POOL_STATE[poolKey]) || pool.closed) {
|
|
316
|
-
const config = this.getPoolConfig("mongodb"
|
|
316
|
+
const config = this.getPoolConfig("mongodb", password);
|
|
317
317
|
if (config) {
|
|
318
318
|
const { min, max, idle, queue_max, queue_idle } = config;
|
|
319
319
|
if (MONGODB_V360) {
|
|
@@ -342,7 +342,7 @@ function setCredential(item) {
|
|
|
342
342
|
}
|
|
343
343
|
}
|
|
344
344
|
}
|
|
345
|
-
const db = require("mongodb"
|
|
345
|
+
const db = require("mongodb");
|
|
346
346
|
new MongoDBPool(new db.MongoClient(item.uri, options), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
|
|
347
347
|
}
|
|
348
348
|
else {
|
|
@@ -364,7 +364,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
364
364
|
if (length === 0) {
|
|
365
365
|
return [];
|
|
366
366
|
}
|
|
367
|
-
const db = require("mongodb"
|
|
367
|
+
const db = require("mongodb");
|
|
368
368
|
let parallel, checkObject, connectOnce, errorQuery, sessionKey, outCacheMiss;
|
|
369
369
|
if ((0, types_1.isPlainObject)(options)) {
|
|
370
370
|
({ parallel, checkObject, connectOnce, errorQuery, sessionKey, outCacheMiss } = options);
|
|
@@ -385,12 +385,12 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
385
385
|
if (!parallel) {
|
|
386
386
|
outResult || (outResult = new Array(length));
|
|
387
387
|
}
|
|
388
|
-
const caching = this.hasCache("mongodb"
|
|
388
|
+
const caching = this.hasCache("mongodb", sessionKey);
|
|
389
389
|
const tasks = new Array(length);
|
|
390
390
|
const clients = [];
|
|
391
391
|
let mongoClient, mongoCredential, mongoCache = 0, onceCredential = connectOnce ? getCacheObject(batch[0]) : undefined;
|
|
392
392
|
const getConnection = async (item, credential) => {
|
|
393
|
-
item.transactionState = 64
|
|
393
|
+
item.transactionState = 64;
|
|
394
394
|
const pool = item.usePool && DbPool.findKey(POOL_STATE, item.usePool, getPoolKey(connectOnce ? batch[0] : item), ...connectOnce ? [item, batch[0]] : [item]);
|
|
395
395
|
let client;
|
|
396
396
|
if (pool) {
|
|
@@ -418,7 +418,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
418
418
|
mongoClient = client;
|
|
419
419
|
mongoCredential = credential;
|
|
420
420
|
}
|
|
421
|
-
item.transactionState &= ~64
|
|
421
|
+
item.transactionState &= ~64;
|
|
422
422
|
return client;
|
|
423
423
|
};
|
|
424
424
|
for (let i = 0; i < length; ++i) {
|
|
@@ -426,7 +426,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
426
426
|
const { source, name, table, id, aggregate, sort, client, cacheObjectKey, ignoreCache } = item;
|
|
427
427
|
let { query, update, streamRow, limit = 0 } = item;
|
|
428
428
|
if (!table) {
|
|
429
|
-
const error = (0, types_1.errorMessage)(source, "Missing database table"
|
|
429
|
+
const error = (0, types_1.errorMessage)(source, "Missing database table");
|
|
430
430
|
++mongoCache;
|
|
431
431
|
if (this.handleFail(error, item, { errorQuery })) {
|
|
432
432
|
if (!parallel) {
|
|
@@ -443,12 +443,12 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
443
443
|
}
|
|
444
444
|
continue;
|
|
445
445
|
}
|
|
446
|
-
item.transactionState = 1
|
|
446
|
+
item.transactionState = 1;
|
|
447
447
|
const getCollection = (target) => target.db(name, client?.db).collection(table, client?.collection);
|
|
448
448
|
const credential = mongoCredential || onceCredential || getCacheObject(item);
|
|
449
449
|
const renewCache = ignoreCache === 0;
|
|
450
450
|
const cacheValue = renewCache ? { sessionKey, renewCache } : sessionKey;
|
|
451
|
-
const coercing = this.hasCoerce("mongodb"
|
|
451
|
+
const coercing = this.hasCoerce("mongodb", 'options', credential.uuidKey);
|
|
452
452
|
const targetObject = typeof checkObject === 'string' ? coercing && (0, types_1.asFunction)(checkObject) : checkObject;
|
|
453
453
|
if (typeof streamRow === 'string') {
|
|
454
454
|
streamRow = coercing && (0, types_1.asFunction)(streamRow);
|
|
@@ -474,7 +474,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
474
474
|
else {
|
|
475
475
|
outResult[i] = rows;
|
|
476
476
|
}
|
|
477
|
-
this.add(item, 4
|
|
477
|
+
this.add(item, 4 | 128);
|
|
478
478
|
return true;
|
|
479
479
|
}
|
|
480
480
|
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.2.
|
|
3
|
+
"version": "0.2.8",
|
|
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.5.
|
|
25
|
-
"@e-mc/request": "^0.5.
|
|
26
|
-
"@e-mc/types": "^0.5.
|
|
27
|
-
"mongodb": "^5.
|
|
24
|
+
"@e-mc/db": "^0.5.4",
|
|
25
|
+
"@e-mc/request": "^0.5.4",
|
|
26
|
+
"@e-mc/types": "^0.5.4",
|
|
27
|
+
"mongodb": "^5.9.2"
|
|
28
28
|
}
|
|
29
29
|
}
|