cgserver 13.2.2 → 13.2.3

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,4 +1,6 @@
1
1
  # 版本更新日志
2
+ ## v13.2.3
3
+ - Improve MongoDB connection validation and error handling
2
4
  ## v13.2.2
3
5
  - Fix MongoDB connection initialization logic
4
6
  ## v13.2.1
@@ -23,11 +23,15 @@ class MongoBaseService {
23
23
  if (this._model) {
24
24
  return this._model;
25
25
  }
26
- if (mongoose_1.default.connection.readyState !== 1) {
26
+ if (!this.mongo) {
27
+ Log_1.gLog.error("MongoDB connection is not established, please check the connection settings.");
28
+ throw new Error("MongoDB connection is not established");
29
+ }
30
+ if (!this.mongo.connected) {
27
31
  Log_1.gLog.error("MongoDB connection is not ready, please check the connection settings. Current state: " + mongoose_1.default.connection.readyState);
28
32
  throw new Error("MongoDB connection is not ready");
29
33
  }
30
- let db = mongoose_1.default.connection.db;
34
+ let db = this.mongo.connection.db;
31
35
  if (!db || db.databaseName == "test") {
32
36
  Log_1.gLog.error("MongoDB connection is not valid, please check the connection settings.");
33
37
  throw new Error("MongoDB connection is not valid");
@@ -122,6 +122,9 @@ class MongoExt {
122
122
  get connection() {
123
123
  return this._connection;
124
124
  }
125
+ get connected() {
126
+ return this._connection && this._connection.readyState === 1;
127
+ }
125
128
  constructor() {
126
129
  }
127
130
  async init(cfg) {
@@ -60,6 +60,7 @@ export declare class MongoExt {
60
60
  get debug(): boolean;
61
61
  protected _connection: mongoose.Connection;
62
62
  get connection(): mongoose.Connection;
63
+ get connected(): boolean;
63
64
  constructor();
64
65
  init(cfg: MongoConfig): Promise<boolean>;
65
66
  onConnect(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cgserver",
3
- "version": "13.2.2",
3
+ "version": "13.2.3",
4
4
  "author": "trojan",
5
5
  "type": "commonjs",
6
6
  "description": "free for all.Websocket or Http",