@tomsd/mongodbclient 2.7.1 → 2.7.4

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.
@@ -22,16 +22,16 @@ export declare class MClient {
22
22
  get uri(): string;
23
23
  get db(): string;
24
24
  get collection(): string;
25
- connect(): Promise<MongoConnection>;
26
- protected getConnected(): Promise<MongoConnection>;
25
+ connect(): Promise<any>;
26
+ protected getConnected(): Promise<any>;
27
27
  upsert(pobj: any): Promise<unknown>;
28
28
  read(condition?: any, opt?: any): Promise<unknown>;
29
29
  distinct(key: string, condition?: any): Promise<unknown>;
30
30
  remove(condition: any): Promise<unknown>;
31
- stats(): Promise<unknown>;
31
+ stats(): Promise<any>;
32
32
  count(condition?: any): Promise<number>;
33
33
  insertMany(items: any[]): Promise<unknown>;
34
- dbStats(): Promise<unknown>;
34
+ dbStats(): Promise<any>;
35
35
  getCollections(): Promise<any>;
36
36
  }
37
37
  export default MClient;
@@ -55,17 +55,14 @@ class MClient {
55
55
  return this.getConnected();
56
56
  }
57
57
  getConnected() {
58
- const that = this;
59
- const client = new MongoClient(that.m_uri, { useUnifiedTopology: true });
60
- return new Promise(function (resolve, reject) {
61
- client.connect()
62
- .then(function (client) {
63
- const db = client.db(that.m_db);
64
- const collection = db.collection(that.m_collection);
65
- resolve(new MongoConnection(client, db, collection));
66
- })
67
- .catch(function (e) {
68
- reject(e);
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const client = new MongoClient(this.m_uri, { useUnifiedTopology: true });
60
+ return client
61
+ .connect()
62
+ .then((client) => {
63
+ const db = client.db(this.m_db);
64
+ const collection = db.collection(this.m_collection);
65
+ return new MongoConnection(client, db, collection);
69
66
  });
70
67
  });
71
68
  }
@@ -140,20 +137,17 @@ class MClient {
140
137
  });
141
138
  }
142
139
  stats() {
143
- const that = this;
144
- return new Promise(function (resolve, reject) {
145
- that.getConnected()
146
- .then(function (conn) {
147
- conn.collection.stats()
148
- .then(function (r) {
149
- conn.client.close();
150
- resolve(r);
151
- })
152
- .catch(function (e) {
153
- conn.client.close();
154
- reject(e);
155
- });
156
- }, reject);
140
+ return __awaiter(this, void 0, void 0, function* () {
141
+ const connection = yield this.getConnected();
142
+ try {
143
+ return yield connection.collection.stats();
144
+ }
145
+ catch (e) {
146
+ throw e;
147
+ }
148
+ finally {
149
+ connection.client.close();
150
+ }
157
151
  });
158
152
  }
159
153
  count(condition = {}) {
@@ -191,20 +185,17 @@ class MClient {
191
185
  });
192
186
  }
193
187
  dbStats() {
194
- const that = this;
195
- return new Promise(function (resolve, reject) {
196
- that.getConnected()
197
- .then(function (conn) {
198
- conn.db.stats()
199
- .then(function (r) {
200
- conn.client.close();
201
- resolve(r);
202
- })
203
- .catch(function (e) {
204
- conn.client.close();
205
- reject(e);
206
- });
207
- }, reject);
188
+ return __awaiter(this, void 0, void 0, function* () {
189
+ const connection = yield this.getConnected();
190
+ try {
191
+ return yield connection.db.stats();
192
+ }
193
+ catch (e) {
194
+ throw e;
195
+ }
196
+ finally {
197
+ connection.client.close();
198
+ }
208
199
  });
209
200
  }
210
201
  getCollections() {
@@ -22,16 +22,16 @@ export declare class MClient {
22
22
  get uri(): string;
23
23
  get db(): string;
24
24
  get collection(): string;
25
- connect(): Promise<MongoConnection>;
26
- protected getConnected(): Promise<MongoConnection>;
25
+ connect(): Promise<any>;
26
+ protected getConnected(): Promise<any>;
27
27
  upsert(pobj: any): Promise<unknown>;
28
28
  read(condition?: any, opt?: any): Promise<unknown>;
29
29
  distinct(key: string, condition?: any): Promise<unknown>;
30
30
  remove(condition: any): Promise<unknown>;
31
- stats(): Promise<unknown>;
31
+ stats(): Promise<any>;
32
32
  count(condition?: any): Promise<number>;
33
33
  insertMany(items: any[]): Promise<unknown>;
34
- dbStats(): Promise<unknown>;
34
+ dbStats(): Promise<any>;
35
35
  getCollections(): Promise<any>;
36
36
  }
37
37
  export default MClient;
@@ -51,17 +51,14 @@ export class MClient {
51
51
  return this.getConnected();
52
52
  }
53
53
  getConnected() {
54
- const that = this;
55
- const client = new MongoClient(that.m_uri, { useUnifiedTopology: true });
56
- return new Promise(function (resolve, reject) {
57
- client.connect()
58
- .then(function (client) {
59
- const db = client.db(that.m_db);
60
- const collection = db.collection(that.m_collection);
61
- resolve(new MongoConnection(client, db, collection));
62
- })
63
- .catch(function (e) {
64
- reject(e);
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ const client = new MongoClient(this.m_uri, { useUnifiedTopology: true });
56
+ return client
57
+ .connect()
58
+ .then((client) => {
59
+ const db = client.db(this.m_db);
60
+ const collection = db.collection(this.m_collection);
61
+ return new MongoConnection(client, db, collection);
65
62
  });
66
63
  });
67
64
  }
@@ -136,20 +133,17 @@ export class MClient {
136
133
  });
137
134
  }
138
135
  stats() {
139
- const that = this;
140
- return new Promise(function (resolve, reject) {
141
- that.getConnected()
142
- .then(function (conn) {
143
- conn.collection.stats()
144
- .then(function (r) {
145
- conn.client.close();
146
- resolve(r);
147
- })
148
- .catch(function (e) {
149
- conn.client.close();
150
- reject(e);
151
- });
152
- }, reject);
136
+ return __awaiter(this, void 0, void 0, function* () {
137
+ const connection = yield this.getConnected();
138
+ try {
139
+ return yield connection.collection.stats();
140
+ }
141
+ catch (e) {
142
+ throw e;
143
+ }
144
+ finally {
145
+ connection.client.close();
146
+ }
153
147
  });
154
148
  }
155
149
  count(condition = {}) {
@@ -187,20 +181,17 @@ export class MClient {
187
181
  });
188
182
  }
189
183
  dbStats() {
190
- const that = this;
191
- return new Promise(function (resolve, reject) {
192
- that.getConnected()
193
- .then(function (conn) {
194
- conn.db.stats()
195
- .then(function (r) {
196
- conn.client.close();
197
- resolve(r);
198
- })
199
- .catch(function (e) {
200
- conn.client.close();
201
- reject(e);
202
- });
203
- }, reject);
184
+ return __awaiter(this, void 0, void 0, function* () {
185
+ const connection = yield this.getConnected();
186
+ try {
187
+ return yield connection.db.stats();
188
+ }
189
+ catch (e) {
190
+ throw e;
191
+ }
192
+ finally {
193
+ connection.client.close();
194
+ }
204
195
  });
205
196
  }
206
197
  getCollections() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomsd/mongodbclient",
3
- "version": "2.7.1",
3
+ "version": "2.7.4",
4
4
  "description": "",
5
5
  "main": "dist/cjs/mongodbclient.js",
6
6
  "module": "dist/esm/mongodbclient.js",