@tomsd/mongodbclient 2.7.3 → 2.7.6

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.
@@ -24,11 +24,11 @@ export declare class MClient {
24
24
  get collection(): string;
25
25
  connect(): Promise<any>;
26
26
  protected getConnected(): Promise<any>;
27
- upsert(pobj: any): Promise<unknown>;
28
- read(condition?: any, opt?: any): Promise<unknown>;
27
+ upsert(pobj: any): Promise<any>;
28
+ read(condition?: any, opt?: any): Promise<any>;
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>;
@@ -67,39 +67,35 @@ class MClient {
67
67
  });
68
68
  }
69
69
  upsert(pobj) {
70
- const that = this;
71
- pobj._id = "_id" in pobj ? pobj._id : uuid_1.v4();
72
- return new Promise(function (resolve, reject) {
73
- that.getConnected()
74
- .then(function (conn) {
75
- conn.collection.updateOne({ _id: pobj._id }, { $set: pobj }, { upsert: true, writeConcern: { w: 1 } })
76
- .then(function (r) {
77
- conn.client.close();
78
- resolve(r);
79
- })
80
- .catch(function (e) {
81
- conn.client.close();
82
- reject(e);
83
- });
84
- }, 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
+ }
85
82
  });
86
83
  }
87
84
  read(condition = {}, opt) {
88
- const that = this;
89
- return new Promise(function (resolve, reject) {
90
- that.getConnected()
91
- .then(function (conn) {
92
- conn.collection.find(condition, opt)
93
- .toArray()
94
- .then(function (docs) {
95
- conn.client.close();
96
- resolve(docs);
97
- })
98
- .catch(function (e) {
99
- conn.client.close();
100
- reject(e);
101
- });
102
- });
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ const connection = yield this.getConnected();
87
+ try {
88
+ return yield connection
89
+ .collection
90
+ .find(condition, opt)
91
+ .toArray();
92
+ }
93
+ catch (e) {
94
+ throw e;
95
+ }
96
+ finally {
97
+ connection.client.close();
98
+ }
103
99
  });
104
100
  }
105
101
  distinct(key, condition = {}) {
@@ -137,20 +133,17 @@ class MClient {
137
133
  });
138
134
  }
139
135
  stats() {
140
- const that = this;
141
- return new Promise(function (resolve, reject) {
142
- that.getConnected()
143
- .then(function (conn) {
144
- conn.collection.stats()
145
- .then(function (r) {
146
- conn.client.close();
147
- resolve(r);
148
- })
149
- .catch(function (e) {
150
- conn.client.close();
151
- reject(e);
152
- });
153
- }, 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
+ }
154
147
  });
155
148
  }
156
149
  count(condition = {}) {
@@ -24,11 +24,11 @@ export declare class MClient {
24
24
  get collection(): string;
25
25
  connect(): Promise<any>;
26
26
  protected getConnected(): Promise<any>;
27
- upsert(pobj: any): Promise<unknown>;
28
- read(condition?: any, opt?: any): Promise<unknown>;
27
+ upsert(pobj: any): Promise<any>;
28
+ read(condition?: any, opt?: any): Promise<any>;
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>;
@@ -63,39 +63,35 @@ export class MClient {
63
63
  });
64
64
  }
65
65
  upsert(pobj) {
66
- const that = this;
67
- pobj._id = "_id" in pobj ? pobj._id : uuidv4();
68
- return new Promise(function (resolve, reject) {
69
- that.getConnected()
70
- .then(function (conn) {
71
- conn.collection.updateOne({ _id: pobj._id }, { $set: pobj }, { upsert: true, writeConcern: { w: 1 } })
72
- .then(function (r) {
73
- conn.client.close();
74
- resolve(r);
75
- })
76
- .catch(function (e) {
77
- conn.client.close();
78
- reject(e);
79
- });
80
- }, 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
+ }
81
78
  });
82
79
  }
83
80
  read(condition = {}, opt) {
84
- const that = this;
85
- return new Promise(function (resolve, reject) {
86
- that.getConnected()
87
- .then(function (conn) {
88
- conn.collection.find(condition, opt)
89
- .toArray()
90
- .then(function (docs) {
91
- conn.client.close();
92
- resolve(docs);
93
- })
94
- .catch(function (e) {
95
- conn.client.close();
96
- reject(e);
97
- });
98
- });
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ const connection = yield this.getConnected();
83
+ try {
84
+ return yield connection
85
+ .collection
86
+ .find(condition, opt)
87
+ .toArray();
88
+ }
89
+ catch (e) {
90
+ throw e;
91
+ }
92
+ finally {
93
+ connection.client.close();
94
+ }
99
95
  });
100
96
  }
101
97
  distinct(key, condition = {}) {
@@ -133,20 +129,17 @@ export class MClient {
133
129
  });
134
130
  }
135
131
  stats() {
136
- const that = this;
137
- return new Promise(function (resolve, reject) {
138
- that.getConnected()
139
- .then(function (conn) {
140
- conn.collection.stats()
141
- .then(function (r) {
142
- conn.client.close();
143
- resolve(r);
144
- })
145
- .catch(function (e) {
146
- conn.client.close();
147
- reject(e);
148
- });
149
- }, reject);
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ const connection = yield this.getConnected();
134
+ try {
135
+ return yield connection.collection.stats();
136
+ }
137
+ catch (e) {
138
+ throw e;
139
+ }
140
+ finally {
141
+ connection.client.close();
142
+ }
150
143
  });
151
144
  }
152
145
  count(condition = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomsd/mongodbclient",
3
- "version": "2.7.3",
3
+ "version": "2.7.6",
4
4
  "description": "",
5
5
  "main": "dist/cjs/mongodbclient.js",
6
6
  "module": "dist/esm/mongodbclient.js",