@tomsd/mongodbclient 2.7.2 → 2.7.5

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,13 +22,13 @@ 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>;
27
- upsert(pobj: any): Promise<unknown>;
25
+ connect(): Promise<any>;
26
+ protected getConnected(): Promise<any>;
27
+ upsert(pobj: any): Promise<any>;
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
34
  dbStats(): Promise<any>;
@@ -55,36 +55,30 @@ 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
  }
72
69
  upsert(pobj) {
73
- const that = this;
74
- pobj._id = "_id" in pobj ? pobj._id : uuid_1.v4();
75
- return new Promise(function (resolve, reject) {
76
- that.getConnected()
77
- .then(function (conn) {
78
- conn.collection.updateOne({ _id: pobj._id }, { $set: pobj }, { upsert: true, writeConcern: { w: 1 } })
79
- .then(function (r) {
80
- conn.client.close();
81
- resolve(r);
82
- })
83
- .catch(function (e) {
84
- conn.client.close();
85
- reject(e);
86
- });
87
- }, reject);
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ const savingObj = Object.assign({ _id: uuid_1.v4() }, pobj);
72
+ const connection = yield this.getConnected();
73
+ try {
74
+ return yield connection.collection.updateOne({ _id: savingObj._id }, { $set: savingObj }, { upsert: true, writeConcern: { w: 1 } });
75
+ }
76
+ catch (e) {
77
+ throw e;
78
+ }
79
+ finally {
80
+ connection.client.close();
81
+ }
88
82
  });
89
83
  }
90
84
  read(condition = {}, opt) {
@@ -140,20 +134,17 @@ class MClient {
140
134
  });
141
135
  }
142
136
  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);
137
+ return __awaiter(this, void 0, void 0, function* () {
138
+ const connection = yield this.getConnected();
139
+ try {
140
+ return yield connection.collection.stats();
141
+ }
142
+ catch (e) {
143
+ throw e;
144
+ }
145
+ finally {
146
+ connection.client.close();
147
+ }
157
148
  });
158
149
  }
159
150
  count(condition = {}) {
@@ -22,13 +22,13 @@ 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>;
27
- upsert(pobj: any): Promise<unknown>;
25
+ connect(): Promise<any>;
26
+ protected getConnected(): Promise<any>;
27
+ upsert(pobj: any): Promise<any>;
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
34
  dbStats(): Promise<any>;
@@ -51,36 +51,30 @@ 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
  }
68
65
  upsert(pobj) {
69
- const that = this;
70
- pobj._id = "_id" in pobj ? pobj._id : uuidv4();
71
- return new Promise(function (resolve, reject) {
72
- that.getConnected()
73
- .then(function (conn) {
74
- conn.collection.updateOne({ _id: pobj._id }, { $set: pobj }, { upsert: true, writeConcern: { w: 1 } })
75
- .then(function (r) {
76
- conn.client.close();
77
- resolve(r);
78
- })
79
- .catch(function (e) {
80
- conn.client.close();
81
- reject(e);
82
- });
83
- }, reject);
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const savingObj = Object.assign({ _id: uuidv4() }, pobj);
68
+ const connection = yield this.getConnected();
69
+ try {
70
+ return yield connection.collection.updateOne({ _id: savingObj._id }, { $set: savingObj }, { upsert: true, writeConcern: { w: 1 } });
71
+ }
72
+ catch (e) {
73
+ throw e;
74
+ }
75
+ finally {
76
+ connection.client.close();
77
+ }
84
78
  });
85
79
  }
86
80
  read(condition = {}, opt) {
@@ -136,20 +130,17 @@ export class MClient {
136
130
  });
137
131
  }
138
132
  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);
133
+ return __awaiter(this, void 0, void 0, function* () {
134
+ const connection = yield this.getConnected();
135
+ try {
136
+ return yield connection.collection.stats();
137
+ }
138
+ catch (e) {
139
+ throw e;
140
+ }
141
+ finally {
142
+ connection.client.close();
143
+ }
153
144
  });
154
145
  }
155
146
  count(condition = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomsd/mongodbclient",
3
- "version": "2.7.2",
3
+ "version": "2.7.5",
4
4
  "description": "",
5
5
  "main": "dist/cjs/mongodbclient.js",
6
6
  "module": "dist/esm/mongodbclient.js",