cgserver 12.1.1 → 12.2.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.
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # 版本更新日志
2
2
 
3
+ ## v12.2.0
4
+ - mongo 添加了重连功能
3
5
  ## v12.1.0
4
6
  - alisms 阿里云短信整理
5
7
  - alipay 支付宝支付整理
@@ -150,20 +150,33 @@ class MongoExt {
150
150
  if (this._inited) {
151
151
  return false;
152
152
  }
153
- if (this._mongoDb) {
154
- return true;
155
- }
156
153
  this._mongocfg = cfg;
157
154
  this._inited = true;
158
155
  Log_1.gLog.info("mongo config=" + JSON.stringify(this._mongocfg));
159
156
  this._mongoClient = new mongo.MongoClient("mongodb://" + this._mongocfg.host + ":" + this._mongocfg.port, this._mongocfg.options);
160
- await Core_1.core.safeCall(this._mongoClient.connect, this._mongoClient);
157
+ this._mongoClient.on("connectionCreated", this.onConnectionCreated.bind(this));
158
+ this._mongoClient.on("connectionReady", this.onConnectionReady.bind(this));
159
+ this._mongoClient.on("connectionClosed", this.onConnectionClosed.bind(this));
160
+ this._mongoClient.connect();
161
+ return true;
162
+ }
163
+ onConnectionCreated(event) {
164
+ Log_1.gLog.info({ key: "mongo onConnectionCreated", event });
165
+ }
166
+ onConnectionReady(event) {
167
+ Log_1.gLog.info({ key: "mongo onConnectionReady", event });
161
168
  this.onConnect();
162
169
  this._mongoDb = this._mongoClient.db(this._mongocfg.database);
163
170
  for (let i = 0; i < this._init_cbs.length; ++i) {
164
171
  this._init_cbs[i]();
165
172
  }
166
- return true;
173
+ this._init_cbs = [];
174
+ }
175
+ onConnectionClosed(event) {
176
+ Log_1.gLog.info({ key: "mongo onConnectionClosed", event });
177
+ this._inited = false;
178
+ this._mongoDb = null;
179
+ this.init(this._mongocfg);
167
180
  }
168
181
  close(force = false) {
169
182
  this._mongoClient.close(force);
@@ -58,6 +58,9 @@ export declare class MongoExt {
58
58
  get isValid(): boolean;
59
59
  constructor();
60
60
  init(cfg: MongoConfig): Promise<boolean>;
61
+ onConnectionCreated(event: mongo.ConnectionCreatedEvent): void;
62
+ onConnectionReady(event: mongo.ConnectionReadyEvent): void;
63
+ onConnectionClosed(event: mongo.ConnectionClosedEvent): void;
61
64
  close(force?: boolean): void;
62
65
  registerInitCb(cb: Function): void;
63
66
  onConnect(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cgserver",
3
- "version": "12.1.1",
3
+ "version": "12.2.1",
4
4
  "author": "trojan",
5
5
  "type": "commonjs",
6
6
  "description": "free for all.Websocket or Http",
@@ -64,7 +64,7 @@
64
64
  "log4js": "^6.9.1",
65
65
  "mime": "^3.0.0",
66
66
  "minimist": "^1.2.8",
67
- "mongodb": "^6.10.0",
67
+ "mongodb": "^6.15.0",
68
68
  "mssql": "^11.0.1",
69
69
  "mysql2": "^3.10.2",
70
70
  "nodemailer": "^6.9.10",