cgserver 12.1.1 → 12.2.0

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 支付宝支付整理
@@ -157,13 +157,28 @@ class MongoExt {
157
157
  this._inited = true;
158
158
  Log_1.gLog.info("mongo config=" + JSON.stringify(this._mongocfg));
159
159
  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);
160
+ this._mongoClient.on("connectionCreated", this.onConnectionCreated.bind(this));
161
+ this._mongoClient.on("connectionReady", this.onConnectionReady.bind(this));
162
+ this._mongoClient.on("connectionClosed", this.onConnectionClosed.bind(this));
163
+ this._mongoClient.connect();
164
+ return true;
165
+ }
166
+ onConnectionCreated(event) {
167
+ Log_1.gLog.info({ key: "mongo onConnectionCreated", event });
168
+ }
169
+ onConnectionReady(event) {
170
+ Log_1.gLog.info({ key: "mongo onConnectionReady", event });
161
171
  this.onConnect();
162
172
  this._mongoDb = this._mongoClient.db(this._mongocfg.database);
163
173
  for (let i = 0; i < this._init_cbs.length; ++i) {
164
174
  this._init_cbs[i]();
165
175
  }
166
- return true;
176
+ this._init_cbs = [];
177
+ }
178
+ onConnectionClosed(event) {
179
+ Log_1.gLog.info({ key: "mongo onConnectionClosed", event });
180
+ this._inited = false;
181
+ this.init(this._mongocfg);
167
182
  }
168
183
  close(force = false) {
169
184
  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.0",
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",