@tomsd/mongodbclient 2.5.0 → 2.7.1

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.
@@ -29,9 +29,9 @@ export declare class MClient {
29
29
  distinct(key: string, condition?: any): Promise<unknown>;
30
30
  remove(condition: any): Promise<unknown>;
31
31
  stats(): Promise<unknown>;
32
- count(condition: any): Promise<number>;
32
+ count(condition?: any): Promise<number>;
33
33
  insertMany(items: any[]): Promise<unknown>;
34
34
  dbStats(): Promise<unknown>;
35
- getCollections(): Promise<any[]>;
35
+ getCollections(): Promise<any>;
36
36
  }
37
37
  export default MClient;
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.MClient = exports.MongoConnection = void 0;
4
13
  /*!
@@ -147,21 +156,18 @@ class MClient {
147
156
  }, reject);
148
157
  });
149
158
  }
150
- count(condition) {
151
- const that = this;
152
- return new Promise(function (resolve, reject) {
153
- that.getConnected()
154
- .then(function (conn) {
155
- conn.collection.countDocuments(condition)
156
- .then(function (r) {
157
- conn.client.close();
158
- resolve(r);
159
- })
160
- .catch(function (e) {
161
- conn.client.close();
162
- reject(e);
163
- });
164
- }, reject);
159
+ count(condition = {}) {
160
+ return __awaiter(this, void 0, void 0, function* () {
161
+ const connection = yield this.getConnected();
162
+ try {
163
+ return yield connection.collection.countDocuments(condition);
164
+ }
165
+ catch (e) {
166
+ throw e;
167
+ }
168
+ finally {
169
+ connection.client.close();
170
+ }
165
171
  });
166
172
  }
167
173
  insertMany(items) {
@@ -202,20 +208,17 @@ class MClient {
202
208
  });
203
209
  }
204
210
  getCollections() {
205
- const that = this;
206
- return new Promise(function (resolve, reject) {
207
- that.getConnected()
208
- .then(function (conn) {
209
- conn.db.collections()
210
- .then(function (r) {
211
- conn.client.close();
212
- resolve(r);
213
- })
214
- .catch(function (e) {
215
- conn.client.close();
216
- reject(e);
217
- });
218
- }, reject);
211
+ return __awaiter(this, void 0, void 0, function* () {
212
+ const connection = yield this.getConnected();
213
+ try {
214
+ return yield connection.db.collections();
215
+ }
216
+ catch (e) {
217
+ throw e;
218
+ }
219
+ finally {
220
+ connection.client.close();
221
+ }
219
222
  });
220
223
  }
221
224
  }
@@ -29,9 +29,9 @@ export declare class MClient {
29
29
  distinct(key: string, condition?: any): Promise<unknown>;
30
30
  remove(condition: any): Promise<unknown>;
31
31
  stats(): Promise<unknown>;
32
- count(condition: any): Promise<number>;
32
+ count(condition?: any): Promise<number>;
33
33
  insertMany(items: any[]): Promise<unknown>;
34
34
  dbStats(): Promise<unknown>;
35
- getCollections(): Promise<any[]>;
35
+ getCollections(): Promise<any>;
36
36
  }
37
37
  export default MClient;
@@ -1,3 +1,12 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  /*!
2
11
  * @license mongodbclient
3
12
  * (c) 2020 tom
@@ -143,21 +152,18 @@ export class MClient {
143
152
  }, reject);
144
153
  });
145
154
  }
146
- count(condition) {
147
- const that = this;
148
- return new Promise(function (resolve, reject) {
149
- that.getConnected()
150
- .then(function (conn) {
151
- conn.collection.countDocuments(condition)
152
- .then(function (r) {
153
- conn.client.close();
154
- resolve(r);
155
- })
156
- .catch(function (e) {
157
- conn.client.close();
158
- reject(e);
159
- });
160
- }, reject);
155
+ count(condition = {}) {
156
+ return __awaiter(this, void 0, void 0, function* () {
157
+ const connection = yield this.getConnected();
158
+ try {
159
+ return yield connection.collection.countDocuments(condition);
160
+ }
161
+ catch (e) {
162
+ throw e;
163
+ }
164
+ finally {
165
+ connection.client.close();
166
+ }
161
167
  });
162
168
  }
163
169
  insertMany(items) {
@@ -198,20 +204,17 @@ export class MClient {
198
204
  });
199
205
  }
200
206
  getCollections() {
201
- const that = this;
202
- return new Promise(function (resolve, reject) {
203
- that.getConnected()
204
- .then(function (conn) {
205
- conn.db.collections()
206
- .then(function (r) {
207
- conn.client.close();
208
- resolve(r);
209
- })
210
- .catch(function (e) {
211
- conn.client.close();
212
- reject(e);
213
- });
214
- }, reject);
207
+ return __awaiter(this, void 0, void 0, function* () {
208
+ const connection = yield this.getConnected();
209
+ try {
210
+ return yield connection.db.collections();
211
+ }
212
+ catch (e) {
213
+ throw e;
214
+ }
215
+ finally {
216
+ connection.client.close();
217
+ }
215
218
  });
216
219
  }
217
220
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomsd/mongodbclient",
3
- "version": "2.5.0",
3
+ "version": "2.7.1",
4
4
  "description": "",
5
5
  "main": "dist/cjs/mongodbclient.js",
6
6
  "module": "dist/esm/mongodbclient.js",
package/test/test.ts CHANGED
@@ -47,6 +47,11 @@ describe("MClient", () => {
47
47
  assert.equal(names.length, 4);
48
48
  });
49
49
 
50
+ it("dbStats()", async () => {
51
+ const { storageSize } = (await mdbc.dbStats()) as { storageSize: number };
52
+ assert(storageSize > 0);
53
+ });
54
+
50
55
  it("stats()", async () => {
51
56
  const { storageSize } = (await mdbc.stats()) as { storageSize: number };
52
57
  assert(storageSize > 0);