@pi-r/mongodb 0.3.6 → 0.3.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/client/index.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DB_SOURCE_TYPE = exports.DB_SOURCE_CLIENT = exports.getSortValue = exports.getFilterValue = exports.checkTimeout = exports.executeBatchQuery = exports.executeQuery = exports.setCredential = void 0;
4
4
  const path = require("path");
5
+ const mongodb = require("mongodb");
5
6
  const types_1 = require("@e-mc/types");
6
7
  const util_1 = require("@e-mc/db/util");
7
8
  const Db = require("@e-mc/db");
@@ -25,7 +26,7 @@ class MongoDBPool extends DbPool {
25
26
  return this.client.close(force);
26
27
  }
27
28
  isEmpty() {
28
- var _a;
29
+ var _a, _b;
29
30
  if (this.closed) {
30
31
  return true;
31
32
  }
@@ -37,7 +38,7 @@ class MongoDBPool extends DbPool {
37
38
  return (0, util_1.checkEmpty)(topology[name]);
38
39
  }
39
40
  }
40
- return (0, util_1.checkEmpty)((_a = topology.s) === null || _a === void 0 ? void 0 : _a.sessions);
41
+ return (0, util_1.checkEmpty)((_a = topology.s) === null || _a === void 0 ? void 0 : _a.sessions) && (0, util_1.checkEmpty)((_b = topology.s) === null || _b === void 0 ? void 0 : _b.servers);
41
42
  }
42
43
  return false;
43
44
  }
@@ -346,8 +347,7 @@ function setCredential(item) {
346
347
  }
347
348
  }
348
349
  }
349
- const db = require("mongodb");
350
- new MongoDBPool(new db.MongoClient(item.uri, options), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
350
+ new MongoDBPool(new mongodb.MongoClient(item.uri, options), poolKey, username && password ? { username, password } : undefined).add(item).parent = POOL_STATE;
351
351
  }
352
352
  else {
353
353
  pool.add(item);
@@ -368,7 +368,6 @@ async function executeBatchQuery(batch, options = '', outResult) {
368
368
  if (length === 0) {
369
369
  return [];
370
370
  }
371
- const db = require("mongodb");
372
371
  let parallel, checkObject, connectOnce, errorQuery, sessionKey, outCacheMiss;
373
372
  if ((0, types_1.isPlainObject)(options)) {
374
373
  ({ parallel, checkObject, connectOnce, errorQuery, sessionKey, outCacheMiss } = options);
@@ -416,7 +415,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
416
415
  credential.options.maxPoolSize = size;
417
416
  }
418
417
  }
419
- clients.push(client = await new db.MongoClient(credential.uri, credential.options).connect());
418
+ clients.push(client = await new mongodb.MongoClient(credential.uri, credential.options).connect());
420
419
  }
421
420
  if (connectOnce) {
422
421
  mongoClient = client;
@@ -465,7 +464,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
465
464
  pipeline = Array.isArray(aggregate) ? aggregate : aggregate.pipeline;
466
465
  }
467
466
  if (id && (!query || limit === 1) && !pipeline) {
468
- query = { '_id': new db.ObjectId(id) };
467
+ query = { '_id': new mongodb.ObjectId(id) };
469
468
  limit = 1;
470
469
  }
471
470
  if (queryString) {
@@ -489,7 +488,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
489
488
  continue;
490
489
  }
491
490
  }
492
- else if (!aggregate && setResult()) {
491
+ else if (!aggregate && !update && setResult()) {
493
492
  continue;
494
493
  }
495
494
  if (!ignoreCache && outCacheMiss) {
@@ -570,6 +569,7 @@ async function executeBatchQuery(batch, options = '', outResult) {
570
569
  if (updateOptions && coercing) {
571
570
  (0, types_1.coerceObject)(updateOptions);
572
571
  }
572
+ await collection.updateMany(filter, update, updateOptions);
573
573
  }
574
574
  cursor = collection.find(filter, command);
575
575
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/mongodb",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
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.6.16",
25
- "@e-mc/request": "^0.6.16",
26
- "@e-mc/types": "^0.6.16",
24
+ "@e-mc/db": "^0.6.19",
25
+ "@e-mc/request": "^0.6.19",
26
+ "@e-mc/types": "^0.6.19",
27
27
  "mongodb": "^5.9.2"
28
28
  }
29
29
  }
package/client/pool.js DELETED
@@ -1,65 +0,0 @@
1
- "use strict";
2
- const util_1 = require("@e-mc/db/util");
3
- const DbPool = require('@e-mc/db/pool');
4
- const POOL_ACTIVE = new WeakSet();
5
- class MongoDBPool extends DbPool {
6
- static CACHE_UNUSED = ['maxPoolSize', 'minPoolSize', 'connectTimeoutMS', 'socketTimeoutMS', 'maxConnecting', 'maxIdleTimeMS', 'waitQueueTimeoutMS', 'maxStalenessSeconds', 'localThresholdMS', 'serverSelectionTimeoutMS', 'heartbeatFrequencyMS', 'minHeartbeatFrequencyMS', 'timeoutMS', 'compressors', 'zlibCompressionLevel', 'srvMaxHosts', 'mongodbLogPath', 'mongodbLogComponentSeverities', 'mongodbLogMaxDocumentLength'];
7
- static CACHE_IGNORE = ['pkFactory'];
8
- static asString(credential) {
9
- const { options, uri } = credential;
10
- if (uri && options) {
11
- return uri + JSON.stringify(options);
12
- }
13
- return super.asString(credential);
14
- }
15
- static sanitize(credential) {
16
- if (!this.canCache(credential)) {
17
- return;
18
- }
19
- const target = credential.options;
20
- if (!target || !POOL_ACTIVE.has(credential) || credential.uuidKey) {
21
- return credential;
22
- }
23
- const options = super.sanitize(target);
24
- return options !== target ? { uri: credential.uri, options } : credential;
25
- }
26
- async detach(force) {
27
- this.remove();
28
- if (this.closed) {
29
- return;
30
- }
31
- return this.close(force);
32
- }
33
- get closeable() {
34
- const topology = this.client.topology;
35
- return topology ? super.closeable || topology.s.state === 'closing' : true;
36
- }
37
- async getConnection(credential) {
38
- if (credential) {
39
- POOL_ACTIVE.add(credential);
40
- }
41
- return this.client.connect();
42
- }
43
- async close(force = false) {
44
- return this.client.close(force);
45
- }
46
- isEmpty() {
47
- if (this.closed) {
48
- return true;
49
- }
50
- const topology = this.client.topology;
51
- if (topology) {
52
- const name = Object.getOwnPropertySymbols(topology).find(sym => sym.toString() === 'Symbol(waitQueue)');
53
- return (0, util_1.checkEmpty)(name ? topology[name] : topology.s.servers);
54
- }
55
- return false;
56
- }
57
- get closed() {
58
- const topology = this.client.topology;
59
- if (topology && (this.success > 0 || this.failed > 0)) {
60
- return topology.isDestroyed();
61
- }
62
- return this.client.s?.hasBeenClosed === true;
63
- }
64
- }
65
- module.exports = MongoDBPool;