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