@pi-r/mongodb 0.6.5 → 0.7.0
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/README.md +3 -6
- package/client/index.js +17 -16
- package/package.json +5 -5
- package/types/index.d.ts +1 -6
package/README.md
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
### @pi-r/mongodb
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
https://e-mc.readthedocs.io/en/latest/db/mongodb.html
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
- [squared](https://squared.readthedocs.io)
|
|
7
|
-
|
|
8
|
-
## LICENSE
|
|
5
|
+
### LICENSE
|
|
9
6
|
|
|
10
7
|
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");
|
|
@@ -55,7 +54,7 @@ function removePoolProperties(credential) {
|
|
|
55
54
|
for (let i = 0, length = POOL_UNUSED.length; i < length; ++i) {
|
|
56
55
|
const attr = POOL_UNUSED[i];
|
|
57
56
|
if (attr in options) {
|
|
58
|
-
result
|
|
57
|
+
result ||= { ...options };
|
|
59
58
|
delete result[attr];
|
|
60
59
|
}
|
|
61
60
|
}
|
|
@@ -77,7 +76,7 @@ function getPoolKey(credential) {
|
|
|
77
76
|
}
|
|
78
77
|
function setCredential(item) {
|
|
79
78
|
const credential = this.getCredential(item);
|
|
80
|
-
const options = item.options
|
|
79
|
+
const options = item.options ||= {};
|
|
81
80
|
let uri = item.uri;
|
|
82
81
|
if (credential) {
|
|
83
82
|
let { protocol, server, hostname, port, username, password } = (0, util_1.parseServerAuth)(credential, 27017), { auth, authMechanism = 'DEFAULT', authSource, authMechanismProperties } = credential, authentication = '';
|
|
@@ -103,7 +102,7 @@ function setCredential(item) {
|
|
|
103
102
|
uri = (protocol || 'mongodb:') + '//' + authentication + server;
|
|
104
103
|
}
|
|
105
104
|
else {
|
|
106
|
-
options.auth
|
|
105
|
+
options.auth ||= { username, password };
|
|
107
106
|
}
|
|
108
107
|
if (!uri.includes('?')) {
|
|
109
108
|
uri += (uri.endsWith('/') ? '' : '/') + '?';
|
|
@@ -145,7 +144,7 @@ function setCredential(item) {
|
|
|
145
144
|
else {
|
|
146
145
|
throw (0, types_1.errorMessage)("mongodb", 'Missing TLS/SSL credentials');
|
|
147
146
|
}
|
|
148
|
-
authSource
|
|
147
|
+
authSource ||= '$external';
|
|
149
148
|
break;
|
|
150
149
|
}
|
|
151
150
|
case 'GSSAPI':
|
|
@@ -153,12 +152,12 @@ function setCredential(item) {
|
|
|
153
152
|
if ((0, types_1.isObject)(authMechanismProperties)) {
|
|
154
153
|
options.authMechanismProperties = authMechanismProperties;
|
|
155
154
|
}
|
|
156
|
-
authSource
|
|
155
|
+
authSource ||= '$external';
|
|
157
156
|
break;
|
|
158
157
|
}
|
|
159
158
|
case 'PLAIN':
|
|
160
159
|
uri += '&maxPoolSize=1';
|
|
161
|
-
authSource
|
|
160
|
+
authSource ||= '$external';
|
|
162
161
|
break;
|
|
163
162
|
}
|
|
164
163
|
if (authSource) {
|
|
@@ -191,25 +190,25 @@ function setCredential(item) {
|
|
|
191
190
|
if (config) {
|
|
192
191
|
const { min, max, idle, queue_max, queue_idle, timeout, socket_timeout } = config;
|
|
193
192
|
if (min >= 0) {
|
|
194
|
-
options.minPoolSize
|
|
193
|
+
options.minPoolSize ??= min;
|
|
195
194
|
}
|
|
196
195
|
if (max > 0) {
|
|
197
|
-
options.maxPoolSize
|
|
196
|
+
options.maxPoolSize ??= max;
|
|
198
197
|
}
|
|
199
198
|
if (idle >= 0) {
|
|
200
|
-
options.maxIdleTimeMS
|
|
199
|
+
options.maxIdleTimeMS ??= idle;
|
|
201
200
|
}
|
|
202
201
|
if (queue_max > 0) {
|
|
203
|
-
options.maxConnecting
|
|
202
|
+
options.maxConnecting ??= queue_max;
|
|
204
203
|
}
|
|
205
204
|
if (queue_idle >= 0) {
|
|
206
|
-
options.waitQueueTimeoutMS
|
|
205
|
+
options.waitQueueTimeoutMS ??= queue_idle;
|
|
207
206
|
}
|
|
208
207
|
if (timeout > 0) {
|
|
209
|
-
options.connectTimeoutMS
|
|
208
|
+
options.connectTimeoutMS ??= timeout;
|
|
210
209
|
}
|
|
211
210
|
if (socket_timeout > 0) {
|
|
212
|
-
options.socketTimeoutMS
|
|
211
|
+
options.socketTimeoutMS ??= socket_timeout;
|
|
213
212
|
}
|
|
214
213
|
}
|
|
215
214
|
const poolKey = getPoolKey(item);
|
|
@@ -247,7 +246,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
247
246
|
parallel = !batch.some(item => item.parallel === false);
|
|
248
247
|
}
|
|
249
248
|
if (!parallel) {
|
|
250
|
-
outResult
|
|
249
|
+
outResult ||= new Array(length);
|
|
251
250
|
}
|
|
252
251
|
const caching = this.hasCache("mongodb", sessionKey);
|
|
253
252
|
const tasks = new Array(length);
|
|
@@ -523,7 +522,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
|
|
|
523
522
|
}
|
|
524
523
|
}
|
|
525
524
|
return this.processRows(batch, tasks, {
|
|
526
|
-
disconnect: () => clients.forEach(
|
|
525
|
+
disconnect: () => clients.forEach(item => {
|
|
526
|
+
item.close(true);
|
|
527
|
+
}),
|
|
527
528
|
parallel
|
|
528
529
|
}, outResult);
|
|
529
530
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/mongodb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
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.
|
|
25
|
-
"@e-mc/request": "^0.
|
|
26
|
-
"@e-mc/types": "^0.
|
|
27
|
-
"mongodb": "^6.
|
|
24
|
+
"@e-mc/db": "^0.9.0",
|
|
25
|
+
"@e-mc/request": "^0.9.0",
|
|
26
|
+
"@e-mc/types": "^0.9.0",
|
|
27
|
+
"mongodb": "^6.5.0"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { CascadeAction, ServerAuth } from '@e-mc/types/lib/db';
|
|
|
4
4
|
|
|
5
5
|
import type { AggregateOptions, CollectionOptions, CommandOperationOptions, DbOptions, Document, Filter, MongoClientOptions, OptionalUnlessRequiredId, RunCommandOptions, Sort, SortDirection, UpdateFilter } from 'mongodb';
|
|
6
6
|
|
|
7
|
-
export interface MongoDBDataSource extends DbDataSource<Filter<Document> |
|
|
7
|
+
export interface MongoDBDataSource extends DbDataSource<Filter<Document> | MongoDBFilterValue, MongoClientOptions, UpdateFilter<Document> | OptionalUnlessRequiredId<unknown>[], MongoDBCredential, string>, MongoDBClientDBOptions, CascadeAction {
|
|
8
8
|
source: "mongodb";
|
|
9
9
|
id?: string;
|
|
10
10
|
updateType?: 0 | 1 | 2 | 3;
|
|
@@ -37,11 +37,6 @@ export interface MongoDBClientDBOptions {
|
|
|
37
37
|
sort?: Sort | string | MongoDBSortValue;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export interface MongoDBQueryWithOptions {
|
|
41
|
-
value: Filter<Document>;
|
|
42
|
-
options: CommandOperationOptions;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
40
|
export interface MongoDBFilterValue {
|
|
46
41
|
value?: Filter<Document>;
|
|
47
42
|
options?: CommandOperationOptions;
|