@pi-r/mongodb 0.6.5 → 0.6.7

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,5 +1,7 @@
1
1
  # @pi-r/mongodb
2
2
 
3
+ PEP 402 - Forever Dodgers
4
+
3
5
  ## Documentation
4
6
 
5
7
  - [E-mc](https://e-mc.readthedocs.io/en/latest/db/mongodb.html)
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");
@@ -38,11 +37,12 @@ class MongoDBPool extends DbPool {
38
37
  return topology ? super.closeable || topology.s.state === 'closing' : true;
39
38
  }
40
39
  get closed() {
40
+ var _a;
41
41
  const topology = this.client.topology;
42
42
  if (topology && (this.success > 0 || this.failed > 0)) {
43
43
  return topology.isDestroyed();
44
44
  }
45
- return this.client.s?.hasBeenClosed === true;
45
+ return ((_a = this.client.s) === null || _a === void 0 ? void 0 : _a.hasBeenClosed) === true;
46
46
  }
47
47
  }
48
48
  const POOL_STATE = {};
@@ -67,7 +67,7 @@ function removePoolProperties(credential) {
67
67
  }
68
68
  function getCacheObject(item) {
69
69
  const credential = item.credential;
70
- return { uri: item.uri, options: item.options, uuidKey: credential?.uuidKey };
70
+ return { uri: item.uri, options: item.options, uuidKey: credential === null || credential === void 0 ? void 0 : credential.uuidKey };
71
71
  }
72
72
  function getPoolKey(credential) {
73
73
  const { options, uri } = credential;
@@ -76,18 +76,19 @@ function getPoolKey(credential) {
76
76
  }
77
77
  }
78
78
  function setCredential(item) {
79
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
79
80
  const credential = this.getCredential(item);
80
81
  const options = item.options || (item.options = {});
81
82
  let uri = item.uri;
82
83
  if (credential) {
83
84
  let { protocol, server, hostname, port, username, password } = (0, util_1.parseServerAuth)(credential, 27017), { auth, authMechanism = 'DEFAULT', authSource, authMechanismProperties } = credential, authentication = '';
84
85
  if (authMechanism === 'GSSAPI') {
85
- const principal = auth?.username || username || options.auth?.username;
86
+ const principal = (auth === null || auth === void 0 ? void 0 : auth.username) || username || ((_a = options.auth) === null || _a === void 0 ? void 0 : _a.username);
86
87
  if ((0, types_1.isString)(principal)) {
87
88
  authentication = encodeURIComponent(principal) + '@';
88
89
  }
89
90
  }
90
- else if (auth?.username) {
91
+ else if (auth === null || auth === void 0 ? void 0 : auth.username) {
91
92
  options.auth = auth;
92
93
  }
93
94
  if (!uri || !Db.isURL(uri)) {
@@ -175,7 +176,7 @@ function setCredential(item) {
175
176
  }
176
177
  let username, password, pool;
177
178
  if ((0, types_1.isString)(usePool)) {
178
- if (username = options.auth?.username || item.uri && (0, util_1.parseConnectionString)(item.uri)?.username) {
179
+ if (username = ((_b = options.auth) === null || _b === void 0 ? void 0 : _b.username) || item.uri && ((_c = (0, util_1.parseConnectionString)(item.uri)) === null || _c === void 0 ? void 0 : _c.username)) {
179
180
  [password, pool] = DbPool.validateKey(POOL_STATE, username, usePool);
180
181
  if (pool) {
181
182
  pool.add(item, password);
@@ -191,25 +192,25 @@ function setCredential(item) {
191
192
  if (config) {
192
193
  const { min, max, idle, queue_max, queue_idle, timeout, socket_timeout } = config;
193
194
  if (min >= 0) {
194
- options.minPoolSize ?? (options.minPoolSize = min);
195
+ (_d = options.minPoolSize) !== null && _d !== void 0 ? _d : (options.minPoolSize = min);
195
196
  }
196
197
  if (max > 0) {
197
- options.maxPoolSize ?? (options.maxPoolSize = max);
198
+ (_e = options.maxPoolSize) !== null && _e !== void 0 ? _e : (options.maxPoolSize = max);
198
199
  }
199
200
  if (idle >= 0) {
200
- options.maxIdleTimeMS ?? (options.maxIdleTimeMS = idle);
201
+ (_f = options.maxIdleTimeMS) !== null && _f !== void 0 ? _f : (options.maxIdleTimeMS = idle);
201
202
  }
202
203
  if (queue_max > 0) {
203
- options.maxConnecting ?? (options.maxConnecting = queue_max);
204
+ (_g = options.maxConnecting) !== null && _g !== void 0 ? _g : (options.maxConnecting = queue_max);
204
205
  }
205
206
  if (queue_idle >= 0) {
206
- options.waitQueueTimeoutMS ?? (options.waitQueueTimeoutMS = queue_idle);
207
+ (_h = options.waitQueueTimeoutMS) !== null && _h !== void 0 ? _h : (options.waitQueueTimeoutMS = queue_idle);
207
208
  }
208
209
  if (timeout > 0) {
209
- options.connectTimeoutMS ?? (options.connectTimeoutMS = timeout);
210
+ (_j = options.connectTimeoutMS) !== null && _j !== void 0 ? _j : (options.connectTimeoutMS = timeout);
210
211
  }
211
212
  if (socket_timeout > 0) {
212
- options.socketTimeoutMS ?? (options.socketTimeoutMS = socket_timeout);
213
+ (_k = options.socketTimeoutMS) !== null && _k !== void 0 ? _k : (options.socketTimeoutMS = socket_timeout);
213
214
  }
214
215
  }
215
216
  const poolKey = getPoolKey(item);
@@ -225,6 +226,7 @@ async function executeQuery(item, options) {
225
226
  }
226
227
  exports.executeQuery = executeQuery;
227
228
  async function executeBatchQuery(batch, options = '', outResult) {
229
+ var _a;
228
230
  const length = batch.length;
229
231
  if (length === 0) {
230
232
  return [];
@@ -286,7 +288,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
286
288
  item.transactionState &= ~64;
287
289
  return client;
288
290
  };
289
- if (this.host?.username) {
291
+ if ((_a = this.host) === null || _a === void 0 ? void 0 : _a.username) {
290
292
  this.applyCommand(...batch);
291
293
  }
292
294
  for (let i = 0; i < length; ++i) {
@@ -312,9 +314,9 @@ async function executeBatchQuery(batch, options = '', outResult) {
312
314
  continue;
313
315
  }
314
316
  item.transactionState = 1;
315
- const getInstance = (target) => target.db(name, client?.db);
316
- const getCollection = (target) => getInstance(target).collection(table, client?.collection);
317
- const runCommand = async (target, document) => getInstance(target).command(document, client?.command);
317
+ const getInstance = (target) => target.db(name, client === null || client === void 0 ? void 0 : client.db);
318
+ const getCollection = (target) => getInstance(target).collection(table, client === null || client === void 0 ? void 0 : client.collection);
319
+ const runCommand = async (target, document) => getInstance(target).command(document, client === null || client === void 0 ? void 0 : client.command);
318
320
  const credential = mongoCredential || onceCredential || getCacheObject(item);
319
321
  const cacheValue = ignoreCache === undefined ? sessionKey : Array.isArray(ignoreCache) ? { sessionKey, exclusiveOf: ignoreCache } : { sessionKey, renewCache: ignoreCache === 0 };
320
322
  const coercing = this.hasCoerce("mongodb", 'options', credential.uuidKey);
@@ -372,6 +374,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
372
374
  onceCredential = undefined;
373
375
  }
374
376
  tasks[i] = new Promise(async (resolve, reject) => {
377
+ var _a, _b;
375
378
  let commandType;
376
379
  try {
377
380
  const instance = mongoClient || await getConnection(item, credential);
@@ -386,7 +389,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
386
389
  }
387
390
  if (Array.isArray(update)) {
388
391
  commandType = this.commandType.INSERT;
389
- const insertOptions = item.execute?.insert;
392
+ const insertOptions = (_a = item.execute) === null || _a === void 0 ? void 0 : _a.insert;
390
393
  if (insertOptions && coercing) {
391
394
  (0, types_1.coerceObject)(insertOptions);
392
395
  }
@@ -434,7 +437,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
434
437
  else {
435
438
  if (update && updateType === 1) {
436
439
  commandType = this.commandType.UPDATE;
437
- const updateOptions = item.execute?.update;
440
+ const updateOptions = (_b = item.execute) === null || _b === void 0 ? void 0 : _b.update;
438
441
  if (updateOptions && coercing) {
439
442
  (0, types_1.coerceObject)(updateOptions);
440
443
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mongodb",
3
- "version": "0.6.5",
3
+ "version": "0.6.7",
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.6",
25
- "@e-mc/request": "^0.8.6",
26
- "@e-mc/types": "^0.8.6",
27
- "mongodb": "^6.4.0"
24
+ "@e-mc/db": "^0.8.8",
25
+ "@e-mc/request": "^0.8.8",
26
+ "@e-mc/types": "^0.8.8",
27
+ "mongodb": "^6.5.0"
28
28
  }
29
29
  }