@heliyos/heliyos-api-core 1.0.41 → 1.0.43
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/dist/mongoose.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export declare class MongoConnectionManager {
|
|
|
5
5
|
private initializationPromise;
|
|
6
6
|
private isInitialized;
|
|
7
7
|
private static connectionCount;
|
|
8
|
+
private lastConnectedTimestamp;
|
|
9
|
+
private monitoringInterval;
|
|
8
10
|
private constructor();
|
|
9
11
|
private getConnectionOptions;
|
|
10
12
|
static getInstance(): MongoConnectionManager;
|
|
@@ -13,6 +15,9 @@ export declare class MongoConnectionManager {
|
|
|
13
15
|
getConnection(): mongoose.Connection;
|
|
14
16
|
logConnectionStatus(): void;
|
|
15
17
|
private checkConnectionLatency;
|
|
18
|
+
private startConnectionMonitoring;
|
|
19
|
+
private getDetailedConnectionStatus;
|
|
20
|
+
private getReadyStateText;
|
|
16
21
|
}
|
|
17
22
|
export declare const mongoInstance: MongoConnectionManager;
|
|
18
23
|
export declare const mongooseConnection: mongoose.Connection;
|
package/dist/mongoose.js
CHANGED
|
@@ -38,21 +38,48 @@ class MongoConnectionManager {
|
|
|
38
38
|
constructor() {
|
|
39
39
|
this.initializationPromise = null;
|
|
40
40
|
this.isInitialized = false;
|
|
41
|
-
|
|
41
|
+
this.lastConnectedTimestamp = null;
|
|
42
|
+
this.monitoringInterval = null;
|
|
43
|
+
// Add detailed connection state logging
|
|
44
|
+
mongoose_1.default.connection.on("connecting", () => {
|
|
45
|
+
logger_1.logger.info("MongoDB is attempting to connect...");
|
|
46
|
+
});
|
|
42
47
|
mongoose_1.default.connection.on("error", (err) => {
|
|
43
|
-
logger_1.logger.error("MongoDB connection error:",
|
|
48
|
+
logger_1.logger.error("MongoDB connection error:", {
|
|
49
|
+
error: err,
|
|
50
|
+
state: mongoose_1.default.connection.readyState,
|
|
51
|
+
host: mongoose_1.default.connection.host,
|
|
52
|
+
name: mongoose_1.default.connection.name,
|
|
53
|
+
});
|
|
44
54
|
});
|
|
45
55
|
mongoose_1.default.connection.on("disconnected", () => {
|
|
46
|
-
logger_1.logger.warn("MongoDB disconnected.
|
|
56
|
+
logger_1.logger.warn("MongoDB disconnected.", {
|
|
57
|
+
lastConnectedAt: this.lastConnectedTimestamp,
|
|
58
|
+
timeSinceLastConnection: this.lastConnectedTimestamp
|
|
59
|
+
? Date.now() - this.lastConnectedTimestamp
|
|
60
|
+
: "never connected",
|
|
61
|
+
});
|
|
47
62
|
});
|
|
48
63
|
mongoose_1.default.connection.on("reconnected", () => {
|
|
49
|
-
logger_1.logger.info("MongoDB reconnected"
|
|
64
|
+
logger_1.logger.info("MongoDB reconnected", {
|
|
65
|
+
reconnectAttempts: MongoConnectionManager.connectionCount,
|
|
66
|
+
downtime: this.lastConnectedTimestamp
|
|
67
|
+
? Date.now() - this.lastConnectedTimestamp
|
|
68
|
+
: "unknown",
|
|
69
|
+
});
|
|
50
70
|
this.isInitialized = true;
|
|
71
|
+
this.lastConnectedTimestamp = Date.now();
|
|
51
72
|
});
|
|
52
73
|
mongoose_1.default.connection.on("connected", () => {
|
|
53
|
-
|
|
74
|
+
this.lastConnectedTimestamp = Date.now();
|
|
75
|
+
logger_1.logger.info("MongoDB connected", {
|
|
76
|
+
host: mongoose_1.default.connection.host,
|
|
77
|
+
name: mongoose_1.default.connection.name,
|
|
78
|
+
attemptCount: MongoConnectionManager.connectionCount,
|
|
79
|
+
});
|
|
54
80
|
this.isInitialized = true;
|
|
55
81
|
this.checkConnectionLatency();
|
|
82
|
+
this.startConnectionMonitoring();
|
|
56
83
|
});
|
|
57
84
|
// Add pool monitoring
|
|
58
85
|
mongoose_1.default.connection.on("connected", () => {
|
|
@@ -127,10 +154,15 @@ class MongoConnectionManager {
|
|
|
127
154
|
}
|
|
128
155
|
disconnect() {
|
|
129
156
|
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
+
if (this.monitoringInterval) {
|
|
158
|
+
clearInterval(this.monitoringInterval);
|
|
159
|
+
this.monitoringInterval = null;
|
|
160
|
+
}
|
|
130
161
|
if (mongoose_1.default.connection.readyState === 1) {
|
|
131
162
|
yield mongoose_1.default.disconnect();
|
|
132
163
|
this.isInitialized = false;
|
|
133
164
|
this.initializationPromise = null;
|
|
165
|
+
this.lastConnectedTimestamp = null;
|
|
134
166
|
}
|
|
135
167
|
});
|
|
136
168
|
}
|
|
@@ -164,6 +196,79 @@ class MongoConnectionManager {
|
|
|
164
196
|
}
|
|
165
197
|
});
|
|
166
198
|
}
|
|
199
|
+
// Add new method for continuous connection monitoring
|
|
200
|
+
startConnectionMonitoring() {
|
|
201
|
+
if (this.monitoringInterval) {
|
|
202
|
+
clearInterval(this.monitoringInterval);
|
|
203
|
+
}
|
|
204
|
+
this.monitoringInterval = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
try {
|
|
206
|
+
const start = Date.now();
|
|
207
|
+
const status = yield this.getDetailedConnectionStatus();
|
|
208
|
+
const latency = Date.now() - start;
|
|
209
|
+
logger_1.logger.info("MongoDB Connection Health Check:", Object.assign(Object.assign({}, status), { latency, timestamp: new Date().toISOString() }));
|
|
210
|
+
if (latency > 1000) {
|
|
211
|
+
logger_1.logger.warn("MongoDB Connection Latency Alert:", {
|
|
212
|
+
latency,
|
|
213
|
+
threshold: 1000,
|
|
214
|
+
status,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
logger_1.logger.error("MongoDB Connection Health Check Failed:", {
|
|
220
|
+
error,
|
|
221
|
+
state: mongoose_1.default.connection.readyState,
|
|
222
|
+
timestamp: new Date().toISOString(),
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}), 30000); // Check every 30 seconds
|
|
226
|
+
}
|
|
227
|
+
// Add method to get detailed connection status
|
|
228
|
+
getDetailedConnectionStatus() {
|
|
229
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
230
|
+
const conn = mongoose_1.default.connection;
|
|
231
|
+
try {
|
|
232
|
+
const adminDb = conn.db.admin();
|
|
233
|
+
const serverStatus = yield adminDb.serverStatus();
|
|
234
|
+
return {
|
|
235
|
+
readyState: conn.readyState,
|
|
236
|
+
readyStateText: this.getReadyStateText(conn.readyState),
|
|
237
|
+
host: conn.host,
|
|
238
|
+
port: conn.port,
|
|
239
|
+
name: conn.name,
|
|
240
|
+
connections: serverStatus.connections,
|
|
241
|
+
uptime: serverStatus.uptime,
|
|
242
|
+
lastConnectedAt: this.lastConnectedTimestamp,
|
|
243
|
+
timeSinceLastConnection: this.lastConnectedTimestamp
|
|
244
|
+
? Date.now() - this.lastConnectedTimestamp
|
|
245
|
+
: null,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
logger_1.logger.error("Failed to get detailed server status:", error);
|
|
250
|
+
return {
|
|
251
|
+
readyState: conn.readyState,
|
|
252
|
+
readyStateText: this.getReadyStateText(conn.readyState),
|
|
253
|
+
host: conn.host,
|
|
254
|
+
port: conn.port,
|
|
255
|
+
name: conn.name,
|
|
256
|
+
error: error.message,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
// Helper method to convert readyState to human readable text
|
|
262
|
+
getReadyStateText(state) {
|
|
263
|
+
const states = {
|
|
264
|
+
0: "disconnected",
|
|
265
|
+
1: "connected",
|
|
266
|
+
2: "connecting",
|
|
267
|
+
3: "disconnecting",
|
|
268
|
+
99: "uninitialized",
|
|
269
|
+
};
|
|
270
|
+
return states[state] || "unknown";
|
|
271
|
+
}
|
|
167
272
|
}
|
|
168
273
|
exports.MongoConnectionManager = MongoConnectionManager;
|
|
169
274
|
MongoConnectionManager.connectionCount = 0; // Add connection counter
|
|
@@ -119,5 +119,11 @@ export type ResourcePolicyActionsType = {
|
|
|
119
119
|
UPDATE_GENERATIVE_PAGE: string;
|
|
120
120
|
DELETE_GENERATIVE_PAGE: string;
|
|
121
121
|
};
|
|
122
|
+
CHAT: {
|
|
123
|
+
VIEW_MESSAGE: string;
|
|
124
|
+
UPDATE_MESSAGE: string;
|
|
125
|
+
DELETE_MESSAGE: string;
|
|
126
|
+
ADD_MESSAGE: string;
|
|
127
|
+
};
|
|
122
128
|
};
|
|
123
129
|
export {};
|
|
@@ -114,6 +114,12 @@ exports.authPolicy = {
|
|
|
114
114
|
UPDATE_GENERATIVE_PAGE: "UPDATE_GENERATIVE_PAGE",
|
|
115
115
|
DELETE_GENERATIVE_PAGE: "DELETE_GENERATIVE_PAGE",
|
|
116
116
|
},
|
|
117
|
+
CHAT: {
|
|
118
|
+
VIEW_MESSAGE: "VIEW_MESSAGE",
|
|
119
|
+
UPDATE_MESSAGE: "UPDATE_MESSAGE",
|
|
120
|
+
DELETE_MESSAGE: "DELETE_MESSAGE",
|
|
121
|
+
ADD_MESSAGE: "ADD_MESSAGE",
|
|
122
|
+
},
|
|
117
123
|
},
|
|
118
124
|
ROLES_PERMISSIONS: {
|
|
119
125
|
TEAM_MEMBER: [
|
|
@@ -196,6 +202,11 @@ exports.authPolicy = {
|
|
|
196
202
|
"CREATE_GENERATIVE_PAGE",
|
|
197
203
|
"UPDATE_GENERATIVE_PAGE",
|
|
198
204
|
"DELETE_GENERATIVE_PAGE",
|
|
205
|
+
// Chat
|
|
206
|
+
"VIEW_MESSAGE",
|
|
207
|
+
"UPDATE_MESSAGE",
|
|
208
|
+
"DELETE_MESSAGE",
|
|
209
|
+
"ADD_MESSAGE",
|
|
199
210
|
],
|
|
200
211
|
OWNER: [
|
|
201
212
|
"ADD_USER",
|
|
@@ -282,6 +293,11 @@ exports.authPolicy = {
|
|
|
282
293
|
"CREATE_GENERATIVE_PAGE",
|
|
283
294
|
"UPDATE_GENERATIVE_PAGE",
|
|
284
295
|
"DELETE_GENERATIVE_PAGE",
|
|
296
|
+
// Chat
|
|
297
|
+
"VIEW_MESSAGE",
|
|
298
|
+
"UPDATE_MESSAGE",
|
|
299
|
+
"DELETE_MESSAGE",
|
|
300
|
+
"ADD_MESSAGE",
|
|
285
301
|
],
|
|
286
302
|
ADMIN: [
|
|
287
303
|
"ADD_USER",
|
|
@@ -367,6 +383,11 @@ exports.authPolicy = {
|
|
|
367
383
|
"CREATE_GENERATIVE_PAGE",
|
|
368
384
|
"UPDATE_GENERATIVE_PAGE",
|
|
369
385
|
"DELETE_GENERATIVE_PAGE",
|
|
386
|
+
// Chat
|
|
387
|
+
"VIEW_MESSAGE",
|
|
388
|
+
"UPDATE_MESSAGE",
|
|
389
|
+
"DELETE_MESSAGE",
|
|
390
|
+
"ADD_MESSAGE",
|
|
370
391
|
],
|
|
371
392
|
STAFF: [
|
|
372
393
|
"ADD_USER",
|
|
@@ -453,6 +474,11 @@ exports.authPolicy = {
|
|
|
453
474
|
"CREATE_GENERATIVE_PAGE",
|
|
454
475
|
"UPDATE_GENERATIVE_PAGE",
|
|
455
476
|
"DELETE_GENERATIVE_PAGE",
|
|
477
|
+
// Chat
|
|
478
|
+
"VIEW_MESSAGE",
|
|
479
|
+
"UPDATE_MESSAGE",
|
|
480
|
+
"DELETE_MESSAGE",
|
|
481
|
+
"ADD_MESSAGE",
|
|
456
482
|
],
|
|
457
483
|
SUPPORT: [
|
|
458
484
|
"ADD_USER",
|
|
@@ -539,6 +565,11 @@ exports.authPolicy = {
|
|
|
539
565
|
"CREATE_GENERATIVE_PAGE",
|
|
540
566
|
"UPDATE_GENERATIVE_PAGE",
|
|
541
567
|
"DELETE_GENERATIVE_PAGE",
|
|
568
|
+
// Chat
|
|
569
|
+
"VIEW_MESSAGE",
|
|
570
|
+
"UPDATE_MESSAGE",
|
|
571
|
+
"DELETE_MESSAGE",
|
|
572
|
+
"ADD_MESSAGE",
|
|
542
573
|
],
|
|
543
574
|
SUPER_ADMIN: [
|
|
544
575
|
"ADD_USER",
|
|
@@ -625,6 +656,11 @@ exports.authPolicy = {
|
|
|
625
656
|
"CREATE_GENERATIVE_PAGE",
|
|
626
657
|
"UPDATE_GENERATIVE_PAGE",
|
|
627
658
|
"DELETE_GENERATIVE_PAGE",
|
|
659
|
+
// Chat
|
|
660
|
+
"VIEW_MESSAGE",
|
|
661
|
+
"UPDATE_MESSAGE",
|
|
662
|
+
"DELETE_MESSAGE",
|
|
663
|
+
"ADD_MESSAGE",
|
|
628
664
|
],
|
|
629
665
|
},
|
|
630
666
|
};
|
|
@@ -113,6 +113,12 @@ export const authPolicy: IAuthPolicy = {
|
|
|
113
113
|
UPDATE_GENERATIVE_PAGE: "UPDATE_GENERATIVE_PAGE",
|
|
114
114
|
DELETE_GENERATIVE_PAGE: "DELETE_GENERATIVE_PAGE",
|
|
115
115
|
},
|
|
116
|
+
CHAT: {
|
|
117
|
+
VIEW_MESSAGE: "VIEW_MESSAGE",
|
|
118
|
+
UPDATE_MESSAGE: "UPDATE_MESSAGE",
|
|
119
|
+
DELETE_MESSAGE: "DELETE_MESSAGE",
|
|
120
|
+
ADD_MESSAGE: "ADD_MESSAGE",
|
|
121
|
+
},
|
|
116
122
|
},
|
|
117
123
|
ROLES_PERMISSIONS: {
|
|
118
124
|
TEAM_MEMBER: [
|
|
@@ -205,6 +211,12 @@ export const authPolicy: IAuthPolicy = {
|
|
|
205
211
|
"CREATE_GENERATIVE_PAGE",
|
|
206
212
|
"UPDATE_GENERATIVE_PAGE",
|
|
207
213
|
"DELETE_GENERATIVE_PAGE",
|
|
214
|
+
|
|
215
|
+
// Chat
|
|
216
|
+
"VIEW_MESSAGE",
|
|
217
|
+
"UPDATE_MESSAGE",
|
|
218
|
+
"DELETE_MESSAGE",
|
|
219
|
+
"ADD_MESSAGE",
|
|
208
220
|
],
|
|
209
221
|
OWNER: [
|
|
210
222
|
"ADD_USER",
|
|
@@ -301,6 +313,12 @@ export const authPolicy: IAuthPolicy = {
|
|
|
301
313
|
"CREATE_GENERATIVE_PAGE",
|
|
302
314
|
"UPDATE_GENERATIVE_PAGE",
|
|
303
315
|
"DELETE_GENERATIVE_PAGE",
|
|
316
|
+
|
|
317
|
+
// Chat
|
|
318
|
+
"VIEW_MESSAGE",
|
|
319
|
+
"UPDATE_MESSAGE",
|
|
320
|
+
"DELETE_MESSAGE",
|
|
321
|
+
"ADD_MESSAGE",
|
|
304
322
|
],
|
|
305
323
|
ADMIN: [
|
|
306
324
|
"ADD_USER",
|
|
@@ -396,6 +414,12 @@ export const authPolicy: IAuthPolicy = {
|
|
|
396
414
|
"CREATE_GENERATIVE_PAGE",
|
|
397
415
|
"UPDATE_GENERATIVE_PAGE",
|
|
398
416
|
"DELETE_GENERATIVE_PAGE",
|
|
417
|
+
|
|
418
|
+
// Chat
|
|
419
|
+
"VIEW_MESSAGE",
|
|
420
|
+
"UPDATE_MESSAGE",
|
|
421
|
+
"DELETE_MESSAGE",
|
|
422
|
+
"ADD_MESSAGE",
|
|
399
423
|
],
|
|
400
424
|
|
|
401
425
|
STAFF: [
|
|
@@ -493,6 +517,12 @@ export const authPolicy: IAuthPolicy = {
|
|
|
493
517
|
"CREATE_GENERATIVE_PAGE",
|
|
494
518
|
"UPDATE_GENERATIVE_PAGE",
|
|
495
519
|
"DELETE_GENERATIVE_PAGE",
|
|
520
|
+
|
|
521
|
+
// Chat
|
|
522
|
+
"VIEW_MESSAGE",
|
|
523
|
+
"UPDATE_MESSAGE",
|
|
524
|
+
"DELETE_MESSAGE",
|
|
525
|
+
"ADD_MESSAGE",
|
|
496
526
|
],
|
|
497
527
|
SUPPORT: [
|
|
498
528
|
"ADD_USER",
|
|
@@ -589,6 +619,12 @@ export const authPolicy: IAuthPolicy = {
|
|
|
589
619
|
"CREATE_GENERATIVE_PAGE",
|
|
590
620
|
"UPDATE_GENERATIVE_PAGE",
|
|
591
621
|
"DELETE_GENERATIVE_PAGE",
|
|
622
|
+
|
|
623
|
+
// Chat
|
|
624
|
+
"VIEW_MESSAGE",
|
|
625
|
+
"UPDATE_MESSAGE",
|
|
626
|
+
"DELETE_MESSAGE",
|
|
627
|
+
"ADD_MESSAGE",
|
|
592
628
|
],
|
|
593
629
|
SUPER_ADMIN: [
|
|
594
630
|
"ADD_USER",
|
|
@@ -685,6 +721,12 @@ export const authPolicy: IAuthPolicy = {
|
|
|
685
721
|
"CREATE_GENERATIVE_PAGE",
|
|
686
722
|
"UPDATE_GENERATIVE_PAGE",
|
|
687
723
|
"DELETE_GENERATIVE_PAGE",
|
|
724
|
+
|
|
725
|
+
// Chat
|
|
726
|
+
"VIEW_MESSAGE",
|
|
727
|
+
"UPDATE_MESSAGE",
|
|
728
|
+
"DELETE_MESSAGE",
|
|
729
|
+
"ADD_MESSAGE",
|
|
688
730
|
],
|
|
689
731
|
},
|
|
690
732
|
};
|
|
@@ -816,4 +858,10 @@ export type ResourcePolicyActionsType = {
|
|
|
816
858
|
UPDATE_GENERATIVE_PAGE: string;
|
|
817
859
|
DELETE_GENERATIVE_PAGE: string;
|
|
818
860
|
};
|
|
861
|
+
CHAT: {
|
|
862
|
+
VIEW_MESSAGE: string;
|
|
863
|
+
UPDATE_MESSAGE: string;
|
|
864
|
+
DELETE_MESSAGE: string;
|
|
865
|
+
ADD_MESSAGE: string;
|
|
866
|
+
};
|
|
819
867
|
};
|