@resolveio/server-lib 20.9.6 → 20.9.7
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.
|
@@ -35,6 +35,7 @@ export declare class SubscriptionManager {
|
|
|
35
35
|
private readonly LATENCY_UPDATE_THRESHOLD_MS;
|
|
36
36
|
private _invalidationDebounceTimers;
|
|
37
37
|
private _invalidationPendingTimestamps;
|
|
38
|
+
private _pendingInvalidations;
|
|
38
39
|
private readonly DEBOUNCE_DELAY;
|
|
39
40
|
private readonly MAX_WAIT_TIME;
|
|
40
41
|
constructor();
|
|
@@ -66,8 +67,10 @@ export declare class SubscriptionManager {
|
|
|
66
67
|
private convertDocumentIdForQuery;
|
|
67
68
|
private documentMatchesFilter;
|
|
68
69
|
private shouldInvalidateSubscription;
|
|
70
|
+
private shouldInvalidateSubscriptionForEvents;
|
|
69
71
|
private sendWS;
|
|
70
72
|
getEnableDebug(): boolean;
|
|
71
73
|
private dependencyDebug;
|
|
74
|
+
private summarizeEvents;
|
|
72
75
|
private logDependencySnapshot;
|
|
73
76
|
}
|
|
@@ -139,6 +139,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
139
139
|
// private performanceThread;
|
|
140
140
|
this._invalidationDebounceTimers = new Map();
|
|
141
141
|
this._invalidationPendingTimestamps = new Map();
|
|
142
|
+
this._pendingInvalidations = new Map();
|
|
142
143
|
this.DEBOUNCE_DELAY = 100; // 100ms debounce window
|
|
143
144
|
this.MAX_WAIT_TIME = 500; // 500ms maximum delay
|
|
144
145
|
}
|
|
@@ -341,11 +342,17 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
341
342
|
};
|
|
342
343
|
SubscriptionManager.prototype.invalidatePubsCache = function (collection, type, documentId) {
|
|
343
344
|
return __awaiter(this, void 0, void 0, function () {
|
|
344
|
-
var debounceKey, now, firstInvalidationTime, waitedTooLong;
|
|
345
|
+
var queue, debounceKey, now, firstInvalidationTime, waitedTooLong;
|
|
345
346
|
var _this = this;
|
|
346
347
|
return __generator(this, function (_a) {
|
|
347
348
|
switch (_a.label) {
|
|
348
349
|
case 0:
|
|
350
|
+
queue = this._pendingInvalidations.get(collection);
|
|
351
|
+
if (!queue) {
|
|
352
|
+
queue = { events: [] };
|
|
353
|
+
this._pendingInvalidations.set(collection, queue);
|
|
354
|
+
}
|
|
355
|
+
queue.events.push({ type: type, documentId: documentId });
|
|
349
356
|
debounceKey = collection;
|
|
350
357
|
now = Date.now();
|
|
351
358
|
firstInvalidationTime = this._invalidationPendingTimestamps.get(debounceKey) || now;
|
|
@@ -358,7 +365,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
358
365
|
if (!waitedTooLong) return [3 /*break*/, 2];
|
|
359
366
|
// Immediate execution path
|
|
360
367
|
this._invalidationPendingTimestamps.delete(debounceKey);
|
|
361
|
-
return [4 /*yield*/, this._executeInvalidation(collection
|
|
368
|
+
return [4 /*yield*/, this._executeInvalidation(collection)];
|
|
362
369
|
case 1:
|
|
363
370
|
_a.sent();
|
|
364
371
|
return [3 /*break*/, 3];
|
|
@@ -369,7 +376,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
369
376
|
switch (_a.label) {
|
|
370
377
|
case 0:
|
|
371
378
|
this._invalidationPendingTimestamps.delete(debounceKey);
|
|
372
|
-
return [4 /*yield*/, this._executeInvalidation(collection
|
|
379
|
+
return [4 /*yield*/, this._executeInvalidation(collection)];
|
|
373
380
|
case 1:
|
|
374
381
|
_a.sent();
|
|
375
382
|
return [2 /*return*/];
|
|
@@ -382,9 +389,9 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
382
389
|
});
|
|
383
390
|
});
|
|
384
391
|
};
|
|
385
|
-
SubscriptionManager.prototype._executeInvalidation = function (collection
|
|
392
|
+
SubscriptionManager.prototype._executeInvalidation = function (collection) {
|
|
386
393
|
return __awaiter(this, void 0, void 0, function () {
|
|
387
|
-
var
|
|
394
|
+
var queued, events, collSubs, collSubs_1, collSubs_1_1, sub, batchType, _a, _b, client, ws, _c, e_1_1, e_2_1;
|
|
388
395
|
var e_2, _d, e_1, _e;
|
|
389
396
|
return __generator(this, function (_f) {
|
|
390
397
|
switch (_f.label) {
|
|
@@ -394,10 +401,15 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
394
401
|
clearTimeout(this._invalidationDebounceTimers.get(collection));
|
|
395
402
|
this._invalidationDebounceTimers.delete(collection);
|
|
396
403
|
}
|
|
404
|
+
queued = this._pendingInvalidations.get(collection);
|
|
405
|
+
this._pendingInvalidations.delete(collection);
|
|
406
|
+
if (!queued || !queued.events.length) {
|
|
407
|
+
return [2 /*return*/];
|
|
408
|
+
}
|
|
409
|
+
events = queued.events;
|
|
397
410
|
// Original invalidation logic
|
|
398
411
|
resolveio_server_app_1.ResolveIOServer.getMongoManager().invalidateQueryCache(collection);
|
|
399
412
|
collSubs = this._subscriptions.filter(function (a) { return a.collections.includes(collection); });
|
|
400
|
-
normalizedDocumentId = this.normalizeDocumentId(documentId);
|
|
401
413
|
_f.label = 1;
|
|
402
414
|
case 1:
|
|
403
415
|
_f.trys.push([1, 18, 19, 20]);
|
|
@@ -409,18 +421,19 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
409
421
|
if (this._enableDebug) {
|
|
410
422
|
console.log(new Date(), 'Invalidate Sub', sub.publication, sub.running, sub.runAgain);
|
|
411
423
|
}
|
|
412
|
-
return [4 /*yield*/, this.
|
|
424
|
+
return [4 /*yield*/, this.shouldInvalidateSubscriptionForEvents(sub, collection, events)];
|
|
413
425
|
case 3:
|
|
414
426
|
if (!(_f.sent())) {
|
|
415
427
|
return [3 /*break*/, 16];
|
|
416
428
|
}
|
|
417
429
|
if (sub.running) {
|
|
418
430
|
sub.runAgain = true;
|
|
419
|
-
this.dependencyDebug('Subscription busy, scheduling rerun', { publication: sub.publication, collection: collection,
|
|
431
|
+
this.dependencyDebug('Subscription busy, scheduling rerun', { publication: sub.publication, collection: collection, events: this.summarizeEvents(events) });
|
|
420
432
|
return [3 /*break*/, 16];
|
|
421
433
|
}
|
|
434
|
+
batchType = events.length === 1 ? events[0].type : events.map(function (event) { return event.type; }).join(',');
|
|
422
435
|
if (!this._publications[sub.publication].user_specific) return [3 /*break*/, 14];
|
|
423
|
-
this.dependencyDebug('Triggering user-specific invalidation', { publication: sub.publication, collection: collection,
|
|
436
|
+
this.dependencyDebug('Triggering user-specific invalidation', { publication: sub.publication, collection: collection, events: this.summarizeEvents(events), clientCount: sub.clients.length });
|
|
424
437
|
_f.label = 4;
|
|
425
438
|
case 4:
|
|
426
439
|
_f.trys.push([4, 11, 12, 13]);
|
|
@@ -434,7 +447,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
434
447
|
_f.label = 6;
|
|
435
448
|
case 6:
|
|
436
449
|
_f.trys.push([6, 8, , 9]);
|
|
437
|
-
return [4 /*yield*/, this.sendDataToOneWithRetry(ws, client.messageId, sub, collection,
|
|
450
|
+
return [4 /*yield*/, this.sendDataToOneWithRetry(ws, client.messageId, sub, collection, batchType)];
|
|
438
451
|
case 7:
|
|
439
452
|
_f.sent();
|
|
440
453
|
return [3 /*break*/, 9];
|
|
@@ -457,8 +470,8 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
457
470
|
return [7 /*endfinally*/];
|
|
458
471
|
case 13: return [3 /*break*/, 16];
|
|
459
472
|
case 14:
|
|
460
|
-
this.dependencyDebug('Triggering broadcast invalidation', { publication: sub.publication, collection: collection,
|
|
461
|
-
return [4 /*yield*/, this.sendDataToAllWithRetry(sub, collection,
|
|
473
|
+
this.dependencyDebug('Triggering broadcast invalidation', { publication: sub.publication, collection: collection, events: this.summarizeEvents(events), clientCount: sub.clients.length });
|
|
474
|
+
return [4 /*yield*/, this.sendDataToAllWithRetry(sub, collection, batchType)];
|
|
462
475
|
case 15:
|
|
463
476
|
_f.sent();
|
|
464
477
|
_f.label = 16;
|
|
@@ -1491,6 +1504,45 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
1491
1504
|
});
|
|
1492
1505
|
});
|
|
1493
1506
|
};
|
|
1507
|
+
SubscriptionManager.prototype.shouldInvalidateSubscriptionForEvents = function (sub, collection, events) {
|
|
1508
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1509
|
+
var events_1, events_1_1, event_1, normalizedDocumentId, e_7_1;
|
|
1510
|
+
var e_7, _a;
|
|
1511
|
+
return __generator(this, function (_b) {
|
|
1512
|
+
switch (_b.label) {
|
|
1513
|
+
case 0:
|
|
1514
|
+
_b.trys.push([0, 5, 6, 7]);
|
|
1515
|
+
events_1 = __values(events), events_1_1 = events_1.next();
|
|
1516
|
+
_b.label = 1;
|
|
1517
|
+
case 1:
|
|
1518
|
+
if (!!events_1_1.done) return [3 /*break*/, 4];
|
|
1519
|
+
event_1 = events_1_1.value;
|
|
1520
|
+
normalizedDocumentId = this.normalizeDocumentId(event_1.documentId);
|
|
1521
|
+
return [4 /*yield*/, this.shouldInvalidateSubscription(sub, collection, event_1.type, normalizedDocumentId)];
|
|
1522
|
+
case 2:
|
|
1523
|
+
if (_b.sent()) {
|
|
1524
|
+
return [2 /*return*/, true];
|
|
1525
|
+
}
|
|
1526
|
+
_b.label = 3;
|
|
1527
|
+
case 3:
|
|
1528
|
+
events_1_1 = events_1.next();
|
|
1529
|
+
return [3 /*break*/, 1];
|
|
1530
|
+
case 4: return [3 /*break*/, 7];
|
|
1531
|
+
case 5:
|
|
1532
|
+
e_7_1 = _b.sent();
|
|
1533
|
+
e_7 = { error: e_7_1 };
|
|
1534
|
+
return [3 /*break*/, 7];
|
|
1535
|
+
case 6:
|
|
1536
|
+
try {
|
|
1537
|
+
if (events_1_1 && !events_1_1.done && (_a = events_1.return)) _a.call(events_1);
|
|
1538
|
+
}
|
|
1539
|
+
finally { if (e_7) throw e_7.error; }
|
|
1540
|
+
return [7 /*endfinally*/];
|
|
1541
|
+
case 7: return [2 /*return*/, false];
|
|
1542
|
+
}
|
|
1543
|
+
});
|
|
1544
|
+
});
|
|
1545
|
+
};
|
|
1494
1546
|
SubscriptionManager.prototype.sendWS = function (ws, data) {
|
|
1495
1547
|
this._websocketManager.send(ws, data);
|
|
1496
1548
|
};
|
|
@@ -1508,6 +1560,13 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
1508
1560
|
console.log(new Date(), '[Dependency Debug]', message);
|
|
1509
1561
|
}
|
|
1510
1562
|
};
|
|
1563
|
+
SubscriptionManager.prototype.summarizeEvents = function (events) {
|
|
1564
|
+
var _this = this;
|
|
1565
|
+
return events.map(function (event) { return ({
|
|
1566
|
+
type: event.type,
|
|
1567
|
+
documentId: _this.normalizeDocumentId(event.documentId)
|
|
1568
|
+
}); });
|
|
1569
|
+
};
|
|
1511
1570
|
SubscriptionManager.prototype.logDependencySnapshot = function (sub, context) {
|
|
1512
1571
|
if (!this._enableDependencyDebug) {
|
|
1513
1572
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/managers/subscription.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAA+K;AAC/K,sCAAwC;AACxC,yBAA0B;AAE1B,kEAAuD;AACvD,wFAA0E;AAI1E,yDAAuE;AACvE,uDAAoE;AACpE,+CAA6D;AAC7D,+CAA8D;AAC9D,6DAA2E;AAC3E,6CAA2D;AAC3D,+DAA6E;AAC7E,uGAAkH;AAClH,qFAAgG;AAChG,iFAA6F;AAC7F,2DAAyE;AACzE,2DAAwE;AACxE,2DAAwE;AACxE,gEAA0D;AAC1D,yCAAyF;AACzF,2FAA4G;AAG5G,IAAM,OAAO,GAAG,IAAA,SAAI,GAAE,CAAC,MAAM,CAAC;AAC9B,IAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAezB,wCAAwC;AACxC,gBAAgB;AAChB,qBAAqB;AACrB,wBAAwB;AACxB,4BAA4B;AAC5B,qBAAqB;AACrB,mBAAmB;AACnB,qBAAqB;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BAAmB,IAAI,EAAE,CAAC,CAAC;QAE3D,IAAI,CAAC,eAAe,CAAC,6BAA6B,EAAE;YACnD,OAAO,SAAA;YACP,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,YAAY,EAAE,iBAAiB;YAC/B,sBAAsB,EAAE,aAAa;YACrC,QAAQ,UAAA;SACR,CAAC,CAAC;IACJ,CAAC;IACF,0BAAC;AAAD,CA1tCA,AA0tCC,IAAA;AA1tCY,kDAAmB","file":"subscription.manager.js","sourcesContent":["import { ChangeStream, ChangeStreamDeleteDocument, ChangeStreamInsertDocument, ChangeStreamReplaceDocument, ChangeStreamUpdateDocument, ObjectId, ResumeToken } from 'mongodb';\nimport * as NodeCache from 'node-cache';\nimport { cpus } from 'os';\nimport * as WebSocket from 'ws';\nimport { Flags } from '../collections/flag.collection';\nimport { LoggedInUsers } from '../collections/logged-in-users.collection';\nimport { LoggedInUserModel } from '../models/logged-in-users.model';\nimport { ServerResponseModel } from '../models/server-message.model';\nimport { ActiveSubscriptionModel, SubscriptionModel } from '../models/subscription.model';\nimport { loadAppStatusPublications } from '../publications/app-status';\nimport { loadCronJobPublications } from '../publications/cron-jobs';\nimport { loadFilePublications } from '../publications/files';\nimport { loadFlagsPublications } from '../publications/flags';\nimport { loadFlagsUpdatePublications } from '../publications/flags-update';\nimport { loadLogPublications } from '../publications/logs';\nimport { loadNotificationPublications } from '../publications/notifications';\nimport { loadReportBuilderDashboardBuilderPublications } from '../publications/report-builder-dashboard-builders';\nimport { loadReportBuilderLibraryPublications } from '../publications/report-builder-libraries';\nimport { loadReportBuilderReportPublications } from '../publications/report-builder-reports';\nimport { loadSuperAdminPublications } from '../publications/super-admin';\nimport { loadUserGroupPublications } from '../publications/user-groups';\nimport { loadUserGuidePublications } from '../publications/user-guides';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { dateReviver, deepCopy, getBinarySize, objectIdHexString } from '../util/common';\nimport { DependencyContextSnapshot, withDependencyTracking } from '../util/subscription-dependency-context';\nimport { MonitorManagerFunction } from './monitor.manager';\nimport { WebSocketManager } from './websocket.manager';\nconst numCPUs = cpus().length;\nconst v8 = require('v8');\n\n// Performance Dependencies\n// import * as path from 'path';\n// import { Worker } from 'worker_threads';\n\ninterface MongoQueueModel {\n\t_id: number,\n\ttype: string;\n\tcollection: string;\n\tsubscription: ActiveSubscriptionModel;\n\trunning: boolean;\n\trun_again: boolean;\n}\n\n// interface CurrentPerformanceMonitor {\n// \t_id: number;\n// \tfunction: string;\n// \tpublication: string;\n// \tsubscriptionData: any[];\n// \tdate_start: Date;\n// \tdate_end: Date;\n// \tduration: number;\n// \tresult: string;\n// }\n\nexport class SubscriptionManager {\n\tprivate _websocketManager: WebSocketManager;\n\tprivate _publications: SubscriptionModel = {};\n\tprivate _subscriptions: ActiveSubscriptionModel[] = [];\n\tprivate _wss: WebSocket.Server;\n\tprivate _loggedInUsers: LoggedInUserModel[] = [];\n\n\tprivate _mongoQueue: MongoQueueModel[] = [];\n\tprivate _mongoQueueId = 0;\n\t\n\tprivate _oplog$: ChangeStream;\n\n\tprivate _nodeCache;\n\tprivate _cacheId = 1;\n\n\tprivate _heapSize = v8.getHeapStatistics() / numCPUs;\n\tprivate _heapLimit: number;\n\n\tprivate serverConfig;\n\n\tprivate _monitorManagerFunction: MonitorManagerFunction;\n\n\tprivate _enableDebug = false;\n\tprivate _enableDependencyDebug = false;\n\tprivate _debugOplogCollections = [];\n\tprivate _debugOplogHits = 0;\n\tprivate _debugSubCollections = [];\n\tprivate _debugSubHits = 0;\n\tprivate _debugUnSubHits = 0;\n\tprivate _debugUnSubAllHits = 0;\n\tprivate _debugMongoQueueHits = 0;\n\tprivate _debugMongoQueueCollections = [];\n\tprivate _debugSendQueueHits = 0;\n\tprivate _debugRemoveCacheHits = 0;\n\n\tprivate _oplogRetryCount = 0;\n\n\t// Buffer to store throttled latency updates with timestamps\n\tprivate latencyBuffer = new Map<string, { latency: number, lastUpdate: Date }>();\n\n\t// Interval to flush latency updates in MongoDB\n\tprivate readonly LATENCY_UPDATE_INTERVAL = 60000;\n\n\t// Minimum time difference between two latency updates for the same user\n\tprivate readonly LATENCY_UPDATE_THRESHOLD_MS = 30000;\n\n\t// private currentPerfomanceMonitor: CurrentPerformanceMonitor[] = [];\n\t// private idPerformance: number = 0;\n\t// private performanceThread;\n\n\tprivate _invalidationDebounceTimers = new Map<string, NodeJS.Timeout>();\n\tprivate _invalidationPendingTimestamps = new Map<string, number>();\n\tprivate readonly DEBOUNCE_DELAY = 100; // 100ms debounce window\n\tprivate readonly MAX_WAIT_TIME = 500; // 500ms maximum delay\n\n\n\tconstructor() {}\n\t\n\tstatic create(wss: WebSocket.Server, serverConfig, monitorManagerFunction: MonitorManagerFunction) {\n\t\tconst subscriptionManager = new SubscriptionManager();\n\t\tsetImmediate(async () => {\n\t\t\tawait subscriptionManager.initialize(wss, serverConfig, monitorManagerFunction);\n\t\t});\n\t\treturn subscriptionManager;\n\t}\n\t\n\tprivate async initialize(wss: WebSocket.Server, serverConfig, monitorManagerFunction: MonitorManagerFunction) {\n\t\tthis._websocketManager = ResolveIOServer.getMainServer().getWebSocketManager();\n\t\tthis._monitorManagerFunction = monitorManagerFunction;\n\n\t\tthis._nodeCache = new NodeCache( { stdTTL: 0, checkperiod: 0 } );\n\n\t\tsetInterval(() => this.flushThrottledLatencyUpdates(), this.LATENCY_UPDATE_INTERVAL);\n\n\t\t// setTimeout(() => {\n\t\t// \tconsole.log('Setting up performance thread');\n\n\t\t// \tthis.performanceThread = new Worker(path.join(__dirname, './subscription.performance.js'));\n\n\t\t// \tthis.performanceThread.on('exit', code => {\n\t\t// \t\tconsole.error(new Date(), 'THREAD EXITED!!!!!!!!!!!!!!!!!!', code);\n\t\t// \t});\n\n\t\t// \tthis.performanceThread.on('error', code => {\n\t\t// \t\tconsole.error(new Date(), 'THREAD RECV ERROR !!!!!!!!!!!!!!!!!!', code);\n\t\t// \t});\n\t\t// }, 5000);\n\n\t\t// setInterval(() => {\n\t\t// \tconsole.log('Post thread msg');\n\t\t// \tthis.performanceThread.postMessage(this.currentPerfomanceMonitor);\n\t\t// \tthis.currentPerfomanceMonitor = [];\n\t\t// }, 10000);\n\n\t\tthis.serverConfig = serverConfig;\n\t\tthis._wss = wss;\n\n\t\t// Publications\n\t\tloadSuperAdminPublications(this);\n\t\tloadAppStatusPublications(this);\n\t\tloadLogPublications(this);\n\t\tloadFilePublications(this);\n\t\tloadCronJobPublications(this);\n\t\tloadFlagsUpdatePublications(this);\n\t\tloadFlagsPublications(this);\n\t\tloadNotificationPublications(this);\n\t\tloadReportBuilderReportPublications(this);\n\t\tloadReportBuilderLibraryPublications(this);\n\t\tloadUserGroupPublications(this);\n\t\tloadUserGuidePublications(this);\n\t\tloadReportBuilderDashboardBuilderPublications(this);\n\n\t\tawait this.tailOpLog();\n\n\t\tsetInterval(() => {\n\t\t\tthis._oplogRetryCount = 0;\n\t\t}, 15000);\n\n\t\tsetInterval(() => {\n\t\t\tif (this.getEnableDebug()) {\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Subs', this._subscriptions.length);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Logged In Users', this._loggedInUsers.length);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Mongo Queue', this._mongoQueue.length);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Mongo Queue Hits', this._debugMongoQueueHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Mongo Queue Collections', JSON.stringify(this._debugMongoQueueCollections.sort((a, b) => a.collection.localeCompare(b.collection) || a.publication.localeCompare(b.publication)), null, 2));\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Oplog Hits', this._debugOplogHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Oplog Collections', JSON.stringify(this._debugOplogCollections.sort((a, b) => a.collection.localeCompare(b.collection) || a.type.localeCompare(b.type)), null, 2));\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Send Queue Hits', this._debugSendQueueHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Sub Hits', this._debugSubHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Sub Collections', JSON.stringify(this._debugSubCollections.sort((a, b) => a.publication.localeCompare(b.publication)), null, 2));\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub Hits', this._debugUnSubHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub All Hits', this._debugUnSubAllHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Cache Cleanup Hits', this._debugRemoveCacheHits);\n\t\t\t}\n\t\t\t\n\t\t\tthis._debugOplogHits = 0;\n\t\t\tthis._debugOplogCollections = [];\n\t\t\tthis._debugSubCollections = [];\n\t\t\tthis._debugMongoQueueHits = 0;\n\t\t\tthis._debugMongoQueueCollections = [];\n\t\t\tthis._debugSendQueueHits = 0;\n\t\t\tthis._debugSubHits = 0;\n\t\t\tthis._debugUnSubHits = 0;\n\t\t\tthis._debugUnSubAllHits = 0;\n\t\t\tthis._debugRemoveCacheHits = 0;\n\t\t}, 60000);\n\n\t\tsetInterval(async () => {\n\t\t\tthis._loggedInUsers = await LoggedInUsers.find();\n\t\n\t\t\tlet userCopy = deepCopy(this._loggedInUsers);\n\t\t\tfor (let i = this._loggedInUsers.length - 1; i >= 0; i--) {\n\t\t\t\tlet loggedInUser = userCopy[i];\n\n\t\t\t\tif (!loggedInUser.date || Date.now() - loggedInUser.date.getTime() > 120000) {\n\t\t\t\t\tif (this._websocketManager.getWebSocket(loggedInUser.id_ws)) {\n\t\t\t\t\t\tif (this.getEnableDebug()) {\n\t\t\t\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub WS', this._websocketManager.getWebSocket(loggedInUser.id_ws)['user'], this._websocketManager.getWebSocket(loggedInUser.id_ws)['id_socket'], 2);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tawait this.unsubscribeAll(this._websocketManager.getWebSocket(loggedInUser.id_ws));\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis._subscriptions.forEach(sub => {\n\t\t\t\t\t\t\tfor (let j = sub.clients.length - 1; j >= 0; j--) {\n\t\t\t\t\t\t\t\tlet client = sub.clients[j];\n\n\t\t\t\t\t\t\t\tif (client.id_socket === loggedInUser.id_ws) {\n\t\t\t\t\t\t\t\t\tsub.clients.splice(j, 1);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tawait LoggedInUsers.deleteOne({_id: loggedInUser._id});\n\n\t\t\t\t\t\tif (this._loggedInUsers.findIndex(a => a._id === loggedInUser._id) >= 0) {\n\t\t\t\t\t\t\tthis._loggedInUsers.splice(this._loggedInUsers.findIndex(a => a._id === loggedInUser._id), 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (let i = 0; i < this._subscriptions.length; i++) {\n\t\t\t\tlet sub = this._subscriptions[i];\n\n\t\t\t\tfor (let j = sub.clients.length - 1; j >= 0; j--) {\n\t\t\t\t\tlet client = sub.clients[j];\n\n\t\t\t\t\tif (!this._loggedInUsers.some(a => a.id_ws === client.id_socket)) {\n\t\t\t\t\t\tsub.clients.splice(j, 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}, 30000);\n\n\t\tlet flag = await Flags.findOne({type: 'Enable Debug'});\n\t\tlet dependencyFlag = await Flags.findOne({type: 'Enable Dependency Debug'});\n\n\t\tif (flag && flag.value) {\n\t\t\tthis._enableDebug = true;\n\t\t}\n\t\telse {\n\t\t\tthis._enableDebug = false;\n\t\t}\n\n\t\tif (dependencyFlag && dependencyFlag.value) {\n\t\t\tthis._enableDependencyDebug = true;\n\t\t}\n\t\telse {\n\t\t\tthis._enableDependencyDebug = process.env.ENABLE_DEPENDENCY_DEBUG === 'true';\n\t\t}\n\n\t\tthis.setCacheLimit();\n\t}\n\n\tprivate setCacheLimit() {\t\n\t\tif (process.env.IS_WORKERS_ENABLED === 'true') {\n\t\t\tthis._heapLimit = this._heapSize * 0.4;\n\t\t}\n\t\telse {\n\t\t\tthis._heapLimit = this._heapSize * 0.3; // Use 50% of total heap size\n\t\t}\n\t}\n\n\tpublic async invalidatePubsCache(collection: string, type: string, documentId?: any) {\n\t\tconst debounceKey = collection;\n\t\tconst now = Date.now();\n\t\n\t\t// Initialize or get existing timestamp\n\t\tconst firstInvalidationTime = this._invalidationPendingTimestamps.get(debounceKey) || now;\n\t\tthis._invalidationPendingTimestamps.set(debounceKey, firstInvalidationTime);\n\t\n\t\t// Clear any existing timer\n\t\tif (this._invalidationDebounceTimers.has(debounceKey)) {\n\t\t\tclearTimeout(this._invalidationDebounceTimers.get(debounceKey));\n\t\t}\n\t\n\t\t// Check if we've waited too long\n\t\tconst waitedTooLong = (now - firstInvalidationTime) >= this.MAX_WAIT_TIME;\n\t\t\n\t\tif (waitedTooLong) {\n\t\t\t// Immediate execution path\n\t\t\tthis._invalidationPendingTimestamps.delete(debounceKey);\n\t\t\tawait this._executeInvalidation(collection, type, documentId);\n\t\t} else {\n\t\t\t// Normal debounce path\n\t\t\tthis._invalidationDebounceTimers.set(\n\t\t\t\tdebounceKey,\n\t\t\t\tsetTimeout(async () => {\n\t\t\t\t\tthis._invalidationPendingTimestamps.delete(debounceKey);\n\t\t\t\t\tawait this._executeInvalidation(collection, type, documentId);\n\t\t\t\t}, this.DEBOUNCE_DELAY)\n\t\t\t);\n\t\t}\n\t}\n\t\n\tprivate async _executeInvalidation(collection: string, type: string, documentId?: any) {\n\t\t// Clean up any existing timer (defensive)\n\t\tif (this._invalidationDebounceTimers.has(collection)) {\n\t\t\tclearTimeout(this._invalidationDebounceTimers.get(collection));\n\t\t\tthis._invalidationDebounceTimers.delete(collection);\n\t\t}\n\t\n\t\t// Original invalidation logic\n\t\tResolveIOServer.getMongoManager().invalidateQueryCache(collection);\n\t\n\t\tconst collSubs = this._subscriptions.filter(a => a.collections.includes(collection));\n\t\tconst normalizedDocumentId = this.normalizeDocumentId(documentId);\n\t\n\t\tfor (const sub of collSubs) {\n\t\t\tif (this._enableDebug) {\n\t\t\t\tconsole.log(new Date(), 'Invalidate Sub', sub.publication, sub.running, sub.runAgain);\n\t\t\t}\n\n\t\t\tif (!(await this.shouldInvalidateSubscription(sub, collection, type, normalizedDocumentId))) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (sub.running) {\n\t\t\t\tsub.runAgain = true;\n\t\t\t\tthis.dependencyDebug('Subscription busy, scheduling rerun', { publication: sub.publication, collection, type });\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (this._publications[sub.publication].user_specific) {\n\t\t\t\tthis.dependencyDebug('Triggering user-specific invalidation', { publication: sub.publication, collection, type, documentId: normalizedDocumentId, clientCount: sub.clients.length });\n\t\t\t\tfor (let client of sub.clients) {\n\t\t\t\t\tconst ws = this._websocketManager.getWebSocket(client.id_socket);\n\t\t\t\t\tif (ws?.readyState === ws.OPEN) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait this.sendDataToOneWithRetry(ws, client.messageId, sub, collection, type);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcatch {\n\t\t\t\t\t\t\t// Error handling\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis.dependencyDebug('Triggering broadcast invalidation', { publication: sub.publication, collection, type, documentId: normalizedDocumentId, clientCount: sub.clients.length });\n\t\t\t\tawait this.sendDataToAllWithRetry(sub, collection, type);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async delay(ms: number) {\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\treturn new Promise(resolve => setTimeout(resolve, ms));\n\t}\n\n\tprivate async sendDataToAllWithRetry(sub: ActiveSubscriptionModel, collection: string, type: string) {\n\t\tsub.running = true;\n\n\t\tdo {\n\t\t\tif (this._enableDebug) {\n\t\t\t\tconsole.log(new Date(), 'Running sendDataToAll Sub', sub.publication);\n\t\t\t}\n\n\t\t\tsub.runAgain = false;\n\t\t\tawait this.sendDataToAll(sub, collection, type);\n\n\t\t\tif (this._enableDebug) {\n\t\t\t\tconsole.log(new Date(), 'Done sendDataToAll Sub', sub.publication, sub.runAgain);\n\t\t\t}\n\n\t\t\tif (sub.runAgain) {\n\t\t\t\tawait this.delay(500); // delay, adjust as needed\n\t\t\t}\n\t\t} while (sub.runAgain);\n\n\t\tsub.running = false;\n\t}\n\n\tprivate async sendDataToOneWithRetry(ws: WebSocket, messageId: number, sub: ActiveSubscriptionModel, collection: string, type: string) {\n\t\tsub.running = true;\n\n\t\tdo {\n\t\t\tif (this._enableDebug) {\n\t\t\t\tconsole.log(new Date(), 'Running sendDataToOne Sub', sub.publication);\n\t\t\t}\n\n\t\t\tsub.runAgain = false;\n\t\t\tawait this.sendDataToOne(ws, messageId, sub, collection, type);\n\n\t\t\tif (this._enableDebug) {\n\t\t\t\tconsole.log(new Date(), 'Done sendDataToOne Sub', sub.publication, sub.runAgain);\n\t\t\t}\n\n\t\t\tif (sub.runAgain) {\n\t\t\t\tawait this.delay(500); // delay, adjust as needed\n\t\t\t}\n\t\t} while (sub.runAgain);\n\t\tsub.running = false;\n\t}\n\n\t// Add all files to publications private object\n\tpublic publications(method: SubscriptionModel) {\n\t\tthis._publications = Object.assign(this._publications, method);\n\t}\n\n\t// Throttled `loggedInLatency` method\n\tpublic loggedInLatency(ws: WebSocket) {\n\t\tlet loggedInUser = this._loggedInUsers.find(a => a.id_ws === ws['id_socket']);\n\t\tif (!loggedInUser) return;\n\n\t\tconst now = new Date();\n\t\tconst existingEntry = this.latencyBuffer.get(ws['id_socket']);\n\t\tconst newLatency = ws['latency'];\n\n\t\t// Throttle updates: only update if time threshold has passed or latency has significantly changed\n\t\tif (\n\t\t\t!existingEntry || \n\t\t\t(now.getTime() - existingEntry.lastUpdate.getTime() >= this.LATENCY_UPDATE_THRESHOLD_MS) || \n\t\t\t(Math.abs(newLatency - existingEntry.latency) > 100) // Optional: log only significant changes\n\t\t) {\n\t\t\t// Update in-memory and buffer\n\t\t\tloggedInUser.date = now;\n\t\t\tthis.latencyBuffer.set(ws['id_socket'], { latency: newLatency, lastUpdate: now });\n\t\t}\n\t}\n\n\t// Method to flush buffered latency updates in bulk\n\tprivate async flushThrottledLatencyUpdates() {\n\t\tif (this.latencyBuffer.size === 0) return; // No updates to flush\n\n\t\tconst updates = Array.from(this.latencyBuffer.entries()).map(([id_ws, { latency, lastUpdate }]) => ({\n\t\t\tupdateOne: {\n\t\t\t\tfilter: { id_ws },\n\t\t\t\tupdate: { $set: { latency, date: lastUpdate } }\n\t\t\t}\n\t\t}));\n\n\t\ttry {\n\t\t\tawait LoggedInUsers.bulkWrite(updates);\n\t\t\tthis.latencyBuffer.clear(); // Clear buffer after successful update\n\n\t\t\tif (this.getEnableDebug()) {\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Throttled latency batch update successful', updates.length);\n\t\t\t}\n\t\t}\n\t\tcatch (error) {\n\t\t\tconsole.error(new Date(), 'Sub Manager', 'Throttled latency batch update failed', error);\n\t\t\t// Optional: implement retry logic or logging for failed updates\n\t\t}\n\t}\n\n\t// Subscribe to publication\n\tpublic async subscribe(messageRoute: string, messageDate: Date, ws: WebSocket, messageId: number, publication: string, subscriptionData: any[]) {\n\t\tthis._debugSubHits += 1;\n\n\t\tif (!this._debugSubCollections.some(a => a.publication === publication)) {\n\t\t\tthis._debugSubCollections.push({\n\t\t\t\tpublication: publication,\n\t\t\t\thits: 1\n\t\t\t});\n\t\t}\n\t\telse {\n\t\t\tthis._debugSubCollections.find(a => a.publication === publication).hits += 1;\n\t\t}\n\n\t\tlet pub = this._publications[publication];\n\n\t\tif (!pub) {\n\t\t\tconsole.error(new Date(), 'No Publication: ' + publication);\n\t\t\treturn;\n\t\t}\n\t\telse {\n\t\t\tif (subscriptionData.length > 1 || subscriptionData[0]) {\n\t\t\t\tif (!pub.check) {\n\t\t\t\t\tconsole.error(new Date(), 'No Check Function For Pub ' + publication);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\telse if (!pub.check._schema) {\n\t\t\t\t\tconsole.error(new Date(), 'No Check Schema For Pub ' + publication);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet valObj = {};\n\t\t\t\t\tlet valKeys = Object.keys(pub.check._schema);\n\n\t\t\t\t\tlet rootKeys = valKeys.filter(a => !a.includes('.'));\n\n\t\t\t\t\tfor (let i = 0; i < subscriptionData.length; i++) {\n\t\t\t\t\t\tvalObj[rootKeys[i]] = subscriptionData[i];\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tpub.check.validate(valObj);\n\t\t\t\t\t}\n\t\t\t\t\tcatch (errors) {\n\t\t\t\t\t\tif (errors) {\n\t\t\t\t\t\t\tconsole.error(new Date(), 'Error in Pub Check (' + publication + ')', errors);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (messageRoute !== 'Bypass') {\n\t\t\t\tlet urlData = messageRoute.split('/');\n\t\t\t\tlet urlModule = '';\n\t\t\t\tlet urlNext = urlData[0];\n\n\t\t\t\tif (urlData[0] === '') {\n\t\t\t\t\turlModule = '/';\n\t\t\t\t\turlNext = urlData[1];\n\t\t\t\t}\n\n\t\t\t\turlModule += urlNext;\n\n\t\t\t\tif (urlData.length > 1) {\n\t\t\t\t\turlModule += '/';\n\t\t\t\t}\n\n\t\t\t\tlet otherRouteSubs = this._subscriptions.filter(a => a.clients.some(b => b.id_socket === ws['id_socket'] && b.messageRoute !== 'Bypass' && b.messageRoute !== '/' && b.messageRoute !== messageRoute && !b.messageRoute.startsWith(urlModule)));\n\n\t\t\t\tif (otherRouteSubs.length) {\n\t\t\t\t\t// ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Detected Undestroyed Subscription - ' + this.serverConfig['CLIENT_NAME'], 'USER: ' + ws['user'] + ' (Socket: ' + ws['id_socket'] + ') ' + ' is on route: ' + messageRoute + ' but has the following subscriptions on other routes:' + JSON.stringify(otherRouteSubs, null, 2));\n\n\t\t\t\t\totherRouteSubs.forEach(otherSub => {\n\t\t\t\t\t\totherSub.clients.filter(a => a.id_socket === ws['id_socket']).forEach(client => {\n\t\t\t\t\t\t\tthis.unsubscribe(client.messageRoute, new Date(), ws, client.messageId, otherSub.publication, otherSub.subscriptionData);\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst normalizedSubscriptionData = Array.isArray(subscriptionData) ? subscriptionData : [];\n\t\t\tconst subscriptionKey = JSON.stringify(normalizedSubscriptionData);\n\t\t\tlet sub = this._subscriptions.find(a => a.publication === publication && a.subscriptionKey === subscriptionKey);\n\n\t\t\t// If sub found (another user watching same data), add client to same sub\n\t\t\tif (sub) {\n\t\t\t\tif (!sub.clients.some(a => a.id_socket === ws['id_socket'] && a.messageId === messageId)) {\n\t\t\t\t\tsub.clients.push({\n\t\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\tid_socket: ws['id_socket'],\n\t\t\t\t\t\tmessageRoute: messageRoute\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\t// If sub not found, create new sub\n\t\t\telse {\n\t\t\t\tthis._subscriptions.push({\n\t\t\t\t\tpublication: publication,\n\t\t\t\t\tsubscriptionKey: subscriptionKey,\n\t\t\t\t\tsubscriptionData: normalizedSubscriptionData,\n\t\t\t\t\tcollections: this.getPublicationCollections(publication),\n\t\t\t\t\tclients: [{\n\t\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\tid_socket: ws['id_socket'],\n\t\t\t\t\t\tmessageRoute: messageRoute,\n\t\t\t\t\t}],\n\t\t\t\t\tcacheId: 0,\n\t\t\t\t\trunning: false,\n\t\t\t\t\trunAgain: false,\n\t\t\t\t\tcollectionDependencies: new Map(),\n\t\t\t\t\tcollectionFilters: new Map(),\n\t\t\t\t\twatchAllCollections: new Set()\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (!sub) {\n\t\t\t\tsub = this._subscriptions.find(a => a.publication === publication && a.subscriptionKey === subscriptionKey);\n\t\t\t}\n\n\t\t\tthis.ensureDependencyContainers(sub);\n\n\t\t\tif (this._enableDebug) {\n\t\t\t\tconsole.log(new Date(), 'New Sub', sub.publication, sub.running, sub.runAgain, sub.clients.length);\n\t\t\t}\n\n\t\t\t// Immediately send data to the new client\n\t\t\tawait this.processSubscription(sub, ws, messageId);\n\t\t}\n\t}\n\n\tpublic async createLoggedInUser(id_ws: string): Promise<LoggedInUserModel> {\n\t\tlet ws = this._websocketManager.getWebSocket(id_ws);\n\n\t\tif (ws) {\n\t\t\tlet user = {\n\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t__v: 0,\n\t\t\t\tdate: new Date(),\n\t\t\t\tid_user: ws['id_user'],\n\t\t\t\tuser: ws['user'],\n\t\t\t\tid_ws: ws['id_socket']\n\t\t\t};\n\t\t\t\n\t\t\tthis._loggedInUsers.push(user);\n\t\t\tawait LoggedInUsers.insertOne(user);\n\t\t\t\n\t\t\treturn user;\n\t\t}\n\t\telse {\n\t\t\tthrow new Error('Error in Create Logged In User: No WS');\n\t\t}\n\t}\n\n\t// Unsubscribe from publication \n\tpublic unsubscribe(messageRoute: string, messageDate: Date, ws: WebSocket, messageId: number, publication: string, subscriptionData: any[]) {\t\t\n\t\tthis._debugUnSubHits += 1;\n\n\t\tif (!this._publications[publication]) {\n\t\t\tconsole.log('No Publication: ' + publication);\n\t\t\treturn;\n\t\t}\n\t\telse {\n\t\t\tconst normalizedSubscriptionData = Array.isArray(subscriptionData) ? subscriptionData : [];\n\t\t\tconst subscriptionKey = JSON.stringify(normalizedSubscriptionData);\n\t\t\tlet sub = this._subscriptions.find(a => a.publication === publication && a.subscriptionKey === subscriptionKey);\n\n\t\t\tif (sub) {\n\t\t\t\tfor (let i = sub.clients.length - 1; i >= 0; i--) {\n\t\t\t\t\tif (sub.clients[i].id_user === ws['id_user'] && sub.clients[i].messageId === messageId && sub.clients[i].id_socket === ws['id_socket']) {\n\t\t\t\t\t\tsub.clients.splice(i, 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (this._enableDebug) {\n\t\t\t\t\tconsole.log(new Date(), 'Unsub', sub.publication, sub.running, sub.runAgain, sub.clients.length);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\n\t// Unsubscribe from publication\n\tpublic async unsubscribeAll(ws: WebSocket) {\n\t\tthis._debugUnSubAllHits += 1;\n\n\t\tif (ws) {\n\t\t\t// Check if WebSocket has already been unsubscribed\n\t\t\tif (ws['isUnsubscribed']) {\n\t\t\t\treturn; // Skip if already unsubscribed\n\t\t\t}\n\t\t\t\n\t\t\t// Mark the WebSocket as unsubscribed to prevent further calls\n\t\t\tws['isUnsubscribed'] = true;\n\t\t\t\n\t\t\tif (this._loggedInUsers.map(a => a.id_ws).indexOf(ws['id_socket']) >= 0) {\n\t\t\t\tthis._loggedInUsers.splice(this._loggedInUsers.map(a => a.id_ws).indexOf(ws['id_socket']), 1);\n\t\t\t}\n\t\t\t\n\t\t\tawait LoggedInUsers.deleteOne({ id_ws: ws['id_socket'] });\n\n\t\t\tlet userSubs = this._subscriptions.filter(a => a.clients.some(b => b.id_user === ws['id_user'] && b.id_socket === ws['id_socket']));\n\n\t\t\tfor (let i = userSubs.length - 1; i >= 0; i--) {\n\t\t\t\tlet sub = userSubs[i];\n\n\t\t\t\tfor (let j = sub.clients.length - 1; j >= 0; j--) {\n\t\t\t\t\tif (sub.clients[j].id_socket === ws['id_socket']) {\n\t\t\t\t\t\tsub.clients.splice(j, 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis._websocketManager.removeWebSocket(ws);\n\t\t}\n\t}\n\n\tpublic getActiveSubscriptions() {\n\t\treturn this._subscriptions;\n\t}\n\n\t// Get publication collection\n\tprivate getPublicationCollections(publication: string) {\n\t\treturn this._publications[publication].collections;\n\t}\n\n\tprivate getWatchedDatabases(): string[] {\n\t\tconst mongoManager = ResolveIOServer.getMongoManager();\n\t\tconst managerDatabases = mongoManager?.getWatchedDatabases() || [];\n\n\t\tif (managerDatabases.length) {\n\t\t\treturn managerDatabases;\n\t\t}\n\n\t\tconst config = this.serverConfig || ResolveIOServer.getServerConfig();\n\t\tconst mainDb = config && typeof config['DATABASE'] === 'string' ? config['DATABASE'] : '';\n\n\t\treturn mainDb ? [mainDb] : [];\n\t}\n\n\t// Watch (tail) Mongo's operation log on the entire database (all insert/modify/delete will trigger this function)\n\tprivate async tailOpLog(resumeToken?: ResumeToken) {\n\t\tif (this._oplog$ && !this._oplog$.closed) {\n\t\t\tthis._oplog$.removeAllListeners();\n\t\t\tawait this._oplog$.close();\n\t\t\tthis._oplog$ = null;\n\t\t}\n\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\tawait new Promise(resolve => setTimeout(resolve, 1000));\n\n\t\tif (!this._oplog$ || this._oplog$.closed) {\n\t\t\tthis._oplogRetryCount += 1;\n\n\t\t\tif (this._oplogRetryCount > 5) {\n\t\t\t\tconsole.error('****************** TAIL OPLOG ERROR, RETRYING A BUNCH OF TIMES, KILLING PROCESS **************************');\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\tconst watchDatabases = this.getWatchedDatabases();\n\t\t\tconst pipeline = [\n\t\t\t\t{\n\t\t\t\t\t$match: {\n\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t...(watchDatabases.length ? [{ 'ns.db': { $in: watchDatabases } }] : []),\n\t\t\t\t\t\t\t{'ns.coll': { $nin: [\n\t\t\t\t\t\t\t\t'log-method-latencies', \n\t\t\t\t\t\t\t\t'log-subscriptions', \n\t\t\t\t\t\t\t\t'logs', \n\t\t\t\t\t\t\t\t'counters', \n\t\t\t\t\t\t\t\t'cron-job-histories', \n\t\t\t\t\t\t\t\t'email-histories',\n\t\t\t\t\t\t\t\t'qb-soap-request-histories', \n\t\t\t\t\t\t\t\t'qb-soap-request-responses', \n\t\t\t\t\t\t\t\t'qb-soap-requests',\n\t\t\t\t\t\t\t\t'qb-soap-retries'\n\t\t\t\t\t\t\t] }},\n\t\t\t\t\t\t\t{'ns.coll': { $not: /.*\\.versions$/ }},\n\t\t\t\t\t\t\t{'ns.coll': { $not: /^monitor-/ }},\n\t\t\t\t\t\t]\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\n\t\t\tlet lastResumeToken: ResumeToken;\n\n\t\t\tif (resumeToken) {\n\t\t\t\tlastResumeToken = resumeToken;\n\t\t\t\ttry {\n\t\t\t\t\tthis._oplog$ = ResolveIOServer.getMongoConnection().watch(pipeline, { resumeAfter: resumeToken });\n\t\t\t\t}\n\t\t\t\tcatch {\n\t\t\t\t\tif (this._oplog$) {\n\t\t\t\t\t\tthis._oplog$.removeAllListeners();\n\t\t\t\t\t\tawait this._oplog$.close();\n\t\t\t\t\t\tthis._oplog$ = null;\n\t\t\t\t\t}\n\n\t\t\t\t\tawait this.tailOpLog(resumeToken);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis._oplog$ = ResolveIOServer.getMongoConnection().watch(pipeline);\n\t\t\t}\n\n\t\t\tconsole.log(new Date(), 'oplog started');\n\n\t\t\tthis._oplog$.on('change', async (doc: ChangeStreamInsertDocument | ChangeStreamUpdateDocument | ChangeStreamReplaceDocument | ChangeStreamDeleteDocument) => {\n\t\t\t\tif (doc.ns) {\n\t\t\t\t\tif (this._enableDebug) {\n\t\t\t\t\t\tconsole.log(new Date(), 'Oplog Hit', doc.ns);\n\t\t\t\t\t}\n\n\t\t\t\t\tlet collection = doc.ns.coll;\n\n\t\t\t\t\tif (!this._debugOplogCollections.some(a => a.collection === doc.ns.coll && a.type === doc.operationType)) {\n\t\t\t\t\t\tthis._debugOplogCollections.push({\n\t\t\t\t\t\t\tcollection: doc.ns.coll,\n\t\t\t\t\t\t\ttype: doc.operationType,\n\t\t\t\t\t\t\thits: 1\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis._debugOplogCollections.find(a => a.collection === doc.ns.coll && a.type === doc.operationType).hits += 1;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (collection) {\n\t\t\t\t\t\tthis._debugOplogHits += 1;\n\t\t\t\t\t\tconst docId = doc.documentKey && doc.documentKey['_id'] !== undefined ? doc.documentKey['_id'] : (doc['fullDocument'] && doc['fullDocument']['_id'] !== undefined ? doc['fullDocument']['_id'] : null);\n\n\t\t\t\t\t\tif (doc.operationType === 'insert') {\n\t\t\t\t\t\t\tif (collection === 'support-tickets') {\n\t\t\t\t\t\t\t\tif (this.serverConfig['ROOT_URL'] === 'https://resolveio.com') {\n\t\t\t\t\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().callMethod.call(ResolveIOServer.getMainServer().getMethodManager(), 'sendSupportTicketEmail', doc.documentKey['_id']);\n\t\t\t\t\t\t\t\t\tawait this.invalidatePubsCache(collection, 'insert', docId);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (collection !== 'method-responses') {\n\t\t\t\t\t\t\t\tawait this.invalidatePubsCache(collection, 'insert', docId);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (doc.operationType === 'update' || doc.operationType === 'replace') {\n\t\t\t\t\t\t\tif (collection !== 'method-responses') {\n\t\t\t\t\t\t\t\tawait this.invalidatePubsCache(collection, 'update', docId);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (doc.operationType === 'delete') {\n\t\t\t\t\t\t\tif (collection !== 'method-responses') {\n\t\t\t\t\t\t\t\tawait this.invalidatePubsCache(collection, 'delete', docId);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (collection === 'flags') {\n\t\t\t\t\t\tlet flag = await Flags.findOne({ type: 'Enable Debug' });\n\t\t\t\t\t\tlet dependencyFlag = await Flags.findOne({ type: 'Enable Dependency Debug' });\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (flag && flag.value) {\n\t\t\t\t\t\t\tthis._enableDebug = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tthis._enableDebug = false;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (dependencyFlag && dependencyFlag.value) {\n\t\t\t\t\t\t\tthis._enableDependencyDebug = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tthis._enableDependencyDebug = process.env.ENABLE_DEPENDENCY_DEBUG === 'true';\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tlastResumeToken = doc._id;\n\n\t\t\t\t\tif ((!process.env.NODE_APP_INSTANCE || process.env.NODE_APP_INSTANCE === '0') && (process.env.IS_WORKERS_ENABLED === 'false' || (process.env.IS_WORKER_INSTANCE === 'true' && process.env.WORKER_INDEX === '0'))) {\n\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tthis._oplog$.on('error', async error => {\n\t\t\t\tconsole.log(new Date(), 'oplog error', error);\n\t\t\t\tawait this._oplog$.close();\n\t\t\t});\n\n\t\t\tthis._oplog$.on('end', async () => {\n\t\t\t\tconsole.log(new Date(), 'oplog end');\n\t\t\t\tawait this._oplog$.close();\n\t\t\t});\n\n\t\t\tthis._oplog$.on('close', async () => {\n\t\t\t\tconsole.log(new Date(), 'oplog close');\n\t\t\t\tthis._oplog$.removeAllListeners();\n\t\t\t\tthis._oplog$ = null;\n\t\t\t\tawait this.tailOpLog(lastResumeToken);\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate async processSubscription(sub: ActiveSubscriptionModel, ws: WebSocket, messageId: number) {\n\t\tif (!this._publications[sub.publication].user_specific) {\t\t\t\n\t\t\tif (sub.cacheId) {\n\t\t\t\ttry {\n\t\t\t\t\tlet cacheData = JSON.parse(this._nodeCache.get(sub.cacheId), dateReviver);\n\n\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\tdata: cacheData\n\t\t\t\t\t};\n\n\t\t\t\t\tif (this._enableDebug) {\n\t\t\t\t\t\tconsole.log(new Date(), 'Process Sub, Cache', sub.publication);\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\t}\n\t\t\t\tcatch {\n\t\t\t\t\tthis._nodeCache.del(sub.cacheId);\n\t\t\t\t\tsub.cacheId = 0;\n\n\t\t\t\t\tawait this.sendDataToAllWithRetry(sub, '', 'newSub');\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (this._enableDebug) {\n\t\t\t\t\tconsole.log(new Date(), 'Process Sub, Non - Cache', sub.publication, sub.running);\n\t\t\t\t}\n\n\t\t\t\tif (sub.running) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tawait this.sendDataToAllWithRetry(sub, '', 'newSub');\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tif (this._enableDebug) {\n\t\t\t\tconsole.log(new Date(), 'Process Sub Specific, Non - Cache', sub.publication, sub.running);\n\t\t\t}\n\n\t\t\tif (sub.running) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tawait this.sendDataToOneWithRetry(ws, messageId, sub, '', 'newSub');\n\t\t}\n\t}\n\n\tprivate async sendDataToOne(ws: WebSocket, messageId: number, sub: ActiveSubscriptionModel, collection: string, type: string) {\n\t\tlet monitor = this._monitorManagerFunction.startMonitorFunction('User Specific Publication', sub.publication, '', '', sub.subscriptionData);\n\t\tlet dependencySnapshot: DependencyContextSnapshot;\n\t\tlet res;\n\t\ttry {\n\t\t\tResolveIOServer.getMainServer().getMethodManager().callMethod.call(ResolveIOServer.getMainServer().getMethodManager(), 'insertSubscriptionLog', type, sub.publication, collection, JSON.stringify(sub.subscriptionData));\n\n\t\t\tconst execution = await withDependencyTracking(() => this._publications[sub.publication].function.call(Object.assign({}, this, SubscriptionManager.prototype), ws['id_user'], ...sub.subscriptionData));\n\t\t\tres = execution.result;\n\t\t\tdependencySnapshot = execution.snapshot;\n\t\t\tthis.updateSubscriptionDependencies(sub, dependencySnapshot);\n\n\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\tmessageId: messageId,\n\t\t\t\thasError: false,\n\t\t\t\tdata: res\n\t\t\t};\n\n\t\t\tthis.sendWS(ws, serverRes);\n\t\t}\n\t\tcatch (err) {\n\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\tmessageId: messageId,\n\t\t\t\thasError: true,\n\t\t\t\tdata: err\n\t\t\t};\n\t\t\t\n\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\n\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'Error Detected During Subscription ' + sub.publication + ' - (sendDataToOne - WS)\\n\\nData \\n' + JSON.stringify(sub.subscriptionData, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(err, null, 2));\n\t\t}\n\t\tfinally {\n\t\t\tawait this._monitorManagerFunction.finishMonitorFunction(monitor);\n\t\t}\n\t}\n\n\t// Fetch pub once, send to all clients linked to this pub\n\tprivate async sendDataToAll(sub: ActiveSubscriptionModel, collection: string, type: string) {\n\t\tif (!sub.clients.length) {\n\t\t\tif (sub.cacheId) {\n\t\t\t\tthis._nodeCache.del(sub.cacheId);\n\t\t\t\tsub.cacheId = 0;\n\t\t\t}\n\n\t\t\tlet subIndex = this._subscriptions.findIndex(a => a.publication === sub.publication && a.subscriptionKey === sub.subscriptionKey);\n\t\t\tif (subIndex >= 0) {\n\t\t\t\tthis._subscriptions.splice(subIndex, 1);\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\t\telse {\n\t\t\tlet monitor = this._monitorManagerFunction.startMonitorFunction('Publication', sub.publication, '', '', sub.subscriptionData);\n\t\t\tlet res;\n\t\t\tlet dependencySnapshot: DependencyContextSnapshot;\n\n\t\t\ttry {\n\t\t\t\tif (sub.publication !== 'superadminAPM' && sub.publication !== 'loggedInUsers') {\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().callMethod.call(ResolveIOServer.getMainServer().getMethodManager(), 'insertSubscriptionLog', type, sub.publication, collection, JSON.stringify(sub.subscriptionData));\n\t\t\t\t}\n\n\t\t\t\tconst execution = await withDependencyTracking(() => this._publications[sub.publication].function.call(Object.assign({}, this, SubscriptionManager.prototype), ...sub.subscriptionData));\n\t\t\t\tres = execution.result;\n\t\t\t\tdependencySnapshot = execution.snapshot;\n\t\t\t\tthis.updateSubscriptionDependencies(sub, dependencySnapshot);\n\n\t\t\t\tif (sub.cacheId) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tlet cacheData = JSON.parse(this._nodeCache.get(sub.cacheId), dateReviver);\n\t\n\t\t\t\t\t\tif (JSON.stringify(cacheData) !== JSON.stringify(res)) {\n\t\t\t\t\t\t\tfor (let client of sub.clients) {\n\t\t\t\t\t\t\t\tlet ws = this._websocketManager.getWebSocket(client.id_socket);\n\t\t\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\t\t\t\tmessageId: client.messageId,\n\t\t\t\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\t\t\t\tdata: res\n\t\t\t\t\t\t\t\t\t};\n\t\t\n\t\t\t\t\t\t\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tthis._nodeCache.del(sub.cacheId);\n\n\t\t\t\t\t\t\tif (getBinarySize(JSON.stringify(res)) < 1000000 && \n\t\t\t\t\t\t\t\t!sub.collections.includes('logs') &&\n\t\t\t\t\t\t\t\t!sub.collections.find(a => a.endsWith('.versions')) &&\n\t\t\t\t\t\t\t\t!sub.collections.find(a => a.startsWith('monitor-'))\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tthis._nodeCache.set(sub.cacheId, JSON.stringify(res));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tsub.cacheId = 0;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcatch {\n\t\t\t\t\t\tsub.clients.map(client => {\n\t\t\t\t\t\t\tlet ws = this._websocketManager.getWebSocket(client.id_socket);\n\t\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\t\t\tmessageId: client.messageId,\n\t\t\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\t\t\tdata: res\n\t\t\t\t\t\t\t\t};\n\t\n\t\t\t\t\t\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tthis._nodeCache.del(sub.cacheId);\n\n\t\t\t\t\t\tif (getBinarySize(JSON.stringify(res)) < 1000000 && \n\t\t\t\t\t\t\t!sub.collections.includes('logs') &&\n\t\t\t\t\t\t\t!sub.collections.find(a => a.endsWith('.versions')) &&\n\t\t\t\t\t\t\t!sub.collections.find(a => a.startsWith('monitor-'))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthis._nodeCache.set(sub.cacheId, JSON.stringify(res));\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tsub.cacheId = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tfor (let client of sub.clients) {\n\t\t\t\t\t\tlet ws = this._websocketManager.getWebSocket(client.id_socket);\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\t\tmessageId: client.messageId,\n\t\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\t\tdata: res\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif (getBinarySize(JSON.stringify(res)) < 1000000 && \n\t\t\t\t\t\t!sub.collections.includes('logs') &&\n\t\t\t\t\t\t!sub.collections.find(a => a.endsWith('.versions')) &&\n\t\t\t\t\t\t!sub.collections.find(a => a.startsWith('monitor-'))\n\t\t\t\t\t) {\n\t\t\t\t\t\tsub.cacheId = this._cacheId++;\n\t\t\t\t\t\tthis._nodeCache.set(sub.cacheId, JSON.stringify(res));\n\n\t\t\t\t\t\tconst nodeCacheSize = this._nodeCache.getStats().vsize;\n\n\t\t\t\t\t\tif (nodeCacheSize > this._heapLimit) {\n\t\t\t\t\t\t\t// Evict cache entries as needed\n\t\t\t\t\t\t\tlet deleteCount = 0;\n\t\t\t\t\t\t\tconst subArr = this._subscriptions.filter(a => a.cacheId && !a.clients.length);\n\t\t\t\t\t\n\t\t\t\t\t\t\tfor (let zz = 0; zz < subArr.length; zz++) {\n\t\t\t\t\t\t\t\tthis._debugRemoveCacheHits += 1;\n\t\t\t\t\t\t\t\tthis._nodeCache.del(subArr[zz].cacheId);\n\t\t\t\t\t\t\t\tsubArr[zz].cacheId = 0;\n\t\t\t\t\t\t\t\tdeleteCount += 1;\n\t\t\t\t\t\t\t\tif (this._nodeCache.getStats().vsize < this._heapLimit * 0.75) {\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (this._enableDebug) {\n\t\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t\t'Sub Cache: ' +\n\t\t\t\t\t\t\t\t\t'Too Big - ' +\n\t\t\t\t\t\t\t\t\tsub.publication +\n\t\t\t\t\t\t\t\t\t' - Deleted: ' +\n\t\t\t\t\t\t\t\t\tdeleteCount +\n\t\t\t\t\t\t\t\t\t' - ' +\n\t\t\t\t\t\t\t\t\tnodeCacheSize\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tsub.cacheId = 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (err) {\n\t\t\t\tfor (let client of sub.clients) {\n\t\t\t\t\tlet ws = this._websocketManager.getWebSocket(client.id_socket);\n\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\tmessageId: client.messageId,\n\t\t\t\t\t\t\thasError: true,\n\t\t\t\t\t\t\tdata: err\n\t\t\t\t\t\t};\n\t\t\t\t\t\t\n\t\t\t\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'Error Detected During Subscription ' + sub.publication + ' - (sendPubData)\\n\\nData \\n' + JSON.stringify(sub.subscriptionData, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(err, null, 2));\n\t\t\t}\n\t\t\tfinally {\n\t\t\t\tawait this._monitorManagerFunction.finishMonitorFunction(monitor);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate ensureDependencyContainers(sub: ActiveSubscriptionModel) {\n\t\tif (!sub.collectionDependencies) {\n\t\t\tsub.collectionDependencies = new Map();\n\t\t}\n\n\t\tif (!sub.collectionFilters) {\n\t\t\tsub.collectionFilters = new Map();\n\t\t}\n\n\t\tif (!sub.watchAllCollections) {\n\t\t\tsub.watchAllCollections = new Set();\n\t\t}\n\t}\n\n\tprivate updateSubscriptionDependencies(sub: ActiveSubscriptionModel, snapshot?: DependencyContextSnapshot) {\n\t\tthis.ensureDependencyContainers(sub);\n\n\t\tif (!snapshot) {\n\t\t\tsub.collectionDependencies.clear();\n\t\t\tsub.collectionFilters.clear();\n\t\t\tsub.watchAllCollections.clear();\n\t\t\tthis.dependencyDebug('Cleared dependency snapshot', { publication: sub.publication });\n\t\t\treturn;\n\t\t}\n\n\t\tsub.collectionDependencies = snapshot.dependencies;\n\t\tsub.collectionFilters = snapshot.filters;\n\t\tsub.watchAllCollections = snapshot.watchAllCollections;\n\t\tthis.logDependencySnapshot(sub, 'Snapshot updated');\n\t}\n\n\tprivate normalizeDocumentId(rawId: any): string {\n\t\tif (rawId === null || rawId === undefined) {\n\t\t\treturn null;\n\t\t}\n\n\t\tif (typeof rawId === 'string') {\n\t\t\treturn rawId;\n\t\t}\n\n\t\tif (typeof rawId === 'object' && typeof rawId.toHexString === 'function') {\n\t\t\treturn rawId.toHexString();\n\t\t}\n\n\t\tif (typeof rawId?.toString === 'function') {\n\t\t\tconst str = rawId.toString();\n\t\t\tif (str && str !== '[object Object]') {\n\t\t\t\treturn str;\n\t\t\t}\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tprivate convertDocumentIdForQuery(documentId: string) {\n\t\tif (!documentId) {\n\t\t\treturn documentId;\n\t\t}\n\n\t\tif (/^[a-fA-F0-9]{24}$/.test(documentId)) {\n\t\t\ttry {\n\t\t\t\treturn new ObjectId(documentId);\n\t\t\t}\n\t\t\tcatch {}\n\t\t}\n\n\t\treturn documentId;\n\t}\n\n\tprivate async documentMatchesFilter(collection: string, documentId: string, filter: any): Promise<boolean> {\n\t\ttry {\n\t\t\tconst db = ResolveIOServer.getMainDB();\n\t\t\tconst filterCopy = deepCopy(filter) || {};\n\t\t\tconst idValue = this.convertDocumentIdForQuery(documentId);\n\t\t\tconst combinedFilter = {\n\t\t\t\t$and: [\n\t\t\t\t\t{ _id: idValue },\n\t\t\t\t\tfilterCopy\n\t\t\t\t]\n\t\t\t};\n\n\t\t\tconst doc = await db.collection(collection).findOne(combinedFilter);\n\t\t\treturn !!doc;\n\t\t}\n\t\tcatch {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\tprivate async shouldInvalidateSubscription(sub: ActiveSubscriptionModel, collection: string, type: string, documentId?: string): Promise<boolean> {\n\t\tthis.ensureDependencyContainers(sub);\n\n\t\tif (!documentId) {\n\t\t\tthis.dependencyDebug('Invalidate due to missing documentId', { publication: sub.publication, collection, type });\n\t\t\treturn true;\n\t\t}\n\n\t\tif (sub.watchAllCollections.has(collection)) {\n\t\t\tthis.dependencyDebug('Invalidate due to watch-all collection', { publication: sub.publication, collection, type });\n\t\t\treturn true;\n\t\t}\n\n\t\tconst trackedIds = sub.collectionDependencies.get(collection);\n\n\t\tif (trackedIds && trackedIds.has(documentId)) {\n\t\t\tthis.dependencyDebug('Invalidate due to tracked id', { publication: sub.publication, collection, type, documentId });\n\t\t\treturn true;\n\t\t}\n\n\t\tif (type === 'delete') {\n\t\t\tthis.dependencyDebug('Skip invalidation on delete for unknown id', { publication: sub.publication, collection, type, documentId });\n\t\t\treturn false;\n\t\t}\n\n\t\tconst filters = sub.collectionFilters.get(collection);\n\n\t\tif (filters && filters.length) {\n\t\t\tfor (const filter of filters) {\n\t\t\t\tif (await this.documentMatchesFilter(collection, documentId, filter)) {\n\t\t\t\t\tthis.dependencyDebug('Invalidate due to filter match', { publication: sub.publication, collection, type, documentId, filter });\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis.dependencyDebug('Skip invalidation after dependency checks', { publication: sub.publication, collection, type, documentId });\n\t\treturn false;\n\t}\n\n\tprivate sendWS(ws: WebSocket, data: ServerResponseModel) {\n\t\tthis._websocketManager.send(ws, data);\n\t}\n\n\tpublic getEnableDebug() {\n\t\treturn this._enableDebug;\n\t}\n\n\tprivate dependencyDebug(message: string, details?: Record<string, unknown>) {\n\t\tif (!this._enableDependencyDebug) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (details) {\n\t\t\tconsole.log(new Date(), '[Dependency Debug]', message, JSON.stringify(details, null, 2));\n\t\t}\n\t\telse {\n\t\t\tconsole.log(new Date(), '[Dependency Debug]', message);\n\t\t}\n\t}\n\n\tprivate logDependencySnapshot(sub: ActiveSubscriptionModel, context: string) {\n\t\tif (!this._enableDependencyDebug) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst dependencySummary = Array.from(sub.collectionDependencies.entries()).map(([collectionName, ids]) => {\n\t\t\tconst idList = Array.from(ids || []);\n\t\t\treturn {\n\t\t\t\tcollection: collectionName,\n\t\t\t\tcount: idList.length,\n\t\t\t\tsample: idList.slice(0, 10)\n\t\t\t};\n\t\t});\n\n\t\tconst filterSummary = Array.from(sub.collectionFilters.entries()).map(([collectionName, filters]) => ({\n\t\t\tcollection: collectionName,\n\t\t\tcount: filters.length\n\t\t}));\n\n\t\tconst watchAll = Array.from(sub.watchAllCollections || []);\n\n\t\tthis.dependencyDebug('Dependency snapshot updated', {\n\t\t\tcontext,\n\t\t\tpublication: sub.publication,\n\t\t\tdependencies: dependencySummary,\n\t\t\tcollectionsWithFilters: filterSummary,\n\t\t\twatchAll\n\t\t});\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/managers/subscription.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAA+K;AAC/K,sCAAwC;AACxC,yBAA0B;AAE1B,kEAAuD;AACvD,wFAA0E;AAI1E,yDAAuE;AACvE,uDAAoE;AACpE,+CAA6D;AAC7D,+CAA8D;AAC9D,6DAA2E;AAC3E,6CAA2D;AAC3D,+DAA6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E,GAAG,QAAA;YACnG,IAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC;YACrC,OAAO;gBACN,UAAU,EAAE,cAAc;gBAC1B,KAAK,EAAE,MAAM,CAAC,MAAM;gBACpB,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;aAC3B,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,IAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,UAAC,EAAyB;gBAAzB,KAAA,aAAyB,EAAxB,cAAc,QAAA,EAAE,OAAO,QAAA;YAAM,OAAA,CAAC;gBACrG,UAAU,EAAE,cAAc;gBAC1B,KAAK,EAAE,OAAO,CAAC,MAAM;aACrB,CAAC;QAHmG,CAGnG,CAAC,CAAC;QAEJ,IAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,mBAAmB,IAAI,EAAE,CAAC,CAAC;QAE3D,IAAI,CAAC,eAAe,CAAC,6BAA6B,EAAE;YACnD,OAAO,SAAA;YACP,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,YAAY,EAAE,iBAAiB;YAC/B,sBAAsB,EAAE,aAAa;YACrC,QAAQ,UAAA;SACR,CAAC,CAAC;IACJ,CAAC;IACF,0BAAC;AAAD,CA9vCA,AA8vCC,IAAA;AA9vCY,kDAAmB","file":"subscription.manager.js","sourcesContent":["import { ChangeStream, ChangeStreamDeleteDocument, ChangeStreamInsertDocument, ChangeStreamReplaceDocument, ChangeStreamUpdateDocument, ObjectId, ResumeToken } from 'mongodb';\nimport * as NodeCache from 'node-cache';\nimport { cpus } from 'os';\nimport * as WebSocket from 'ws';\nimport { Flags } from '../collections/flag.collection';\nimport { LoggedInUsers } from '../collections/logged-in-users.collection';\nimport { LoggedInUserModel } from '../models/logged-in-users.model';\nimport { ServerResponseModel } from '../models/server-message.model';\nimport { ActiveSubscriptionModel, SubscriptionModel } from '../models/subscription.model';\nimport { loadAppStatusPublications } from '../publications/app-status';\nimport { loadCronJobPublications } from '../publications/cron-jobs';\nimport { loadFilePublications } from '../publications/files';\nimport { loadFlagsPublications } from '../publications/flags';\nimport { loadFlagsUpdatePublications } from '../publications/flags-update';\nimport { loadLogPublications } from '../publications/logs';\nimport { loadNotificationPublications } from '../publications/notifications';\nimport { loadReportBuilderDashboardBuilderPublications } from '../publications/report-builder-dashboard-builders';\nimport { loadReportBuilderLibraryPublications } from '../publications/report-builder-libraries';\nimport { loadReportBuilderReportPublications } from '../publications/report-builder-reports';\nimport { loadSuperAdminPublications } from '../publications/super-admin';\nimport { loadUserGroupPublications } from '../publications/user-groups';\nimport { loadUserGuidePublications } from '../publications/user-guides';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { dateReviver, deepCopy, getBinarySize, objectIdHexString } from '../util/common';\nimport { DependencyContextSnapshot, withDependencyTracking } from '../util/subscription-dependency-context';\nimport { MonitorManagerFunction } from './monitor.manager';\nimport { WebSocketManager } from './websocket.manager';\nconst numCPUs = cpus().length;\nconst v8 = require('v8');\n\n// Performance Dependencies\n// import * as path from 'path';\n// import { Worker } from 'worker_threads';\n\ninterface MongoQueueModel {\n\t_id: number,\n\ttype: string;\n\tcollection: string;\n\tsubscription: ActiveSubscriptionModel;\n\trunning: boolean;\n\trun_again: boolean;\n}\n\n// interface CurrentPerformanceMonitor {\n// \t_id: number;\n// \tfunction: string;\n// \tpublication: string;\n// \tsubscriptionData: any[];\n// \tdate_start: Date;\n// \tdate_end: Date;\n// \tduration: number;\n// \tresult: string;\n// }\n\nexport class SubscriptionManager {\n\tprivate _websocketManager: WebSocketManager;\n\tprivate _publications: SubscriptionModel = {};\n\tprivate _subscriptions: ActiveSubscriptionModel[] = [];\n\tprivate _wss: WebSocket.Server;\n\tprivate _loggedInUsers: LoggedInUserModel[] = [];\n\n\tprivate _mongoQueue: MongoQueueModel[] = [];\n\tprivate _mongoQueueId = 0;\n\t\n\tprivate _oplog$: ChangeStream;\n\n\tprivate _nodeCache;\n\tprivate _cacheId = 1;\n\n\tprivate _heapSize = v8.getHeapStatistics() / numCPUs;\n\tprivate _heapLimit: number;\n\n\tprivate serverConfig;\n\n\tprivate _monitorManagerFunction: MonitorManagerFunction;\n\n\tprivate _enableDebug = false;\n\tprivate _enableDependencyDebug = false;\n\tprivate _debugOplogCollections = [];\n\tprivate _debugOplogHits = 0;\n\tprivate _debugSubCollections = [];\n\tprivate _debugSubHits = 0;\n\tprivate _debugUnSubHits = 0;\n\tprivate _debugUnSubAllHits = 0;\n\tprivate _debugMongoQueueHits = 0;\n\tprivate _debugMongoQueueCollections = [];\n\tprivate _debugSendQueueHits = 0;\n\tprivate _debugRemoveCacheHits = 0;\n\n\tprivate _oplogRetryCount = 0;\n\n\t// Buffer to store throttled latency updates with timestamps\n\tprivate latencyBuffer = new Map<string, { latency: number, lastUpdate: Date }>();\n\n\t// Interval to flush latency updates in MongoDB\n\tprivate readonly LATENCY_UPDATE_INTERVAL = 60000;\n\n\t// Minimum time difference between two latency updates for the same user\n\tprivate readonly LATENCY_UPDATE_THRESHOLD_MS = 30000;\n\n\t// private currentPerfomanceMonitor: CurrentPerformanceMonitor[] = [];\n\t// private idPerformance: number = 0;\n\t// private performanceThread;\n\n\tprivate _invalidationDebounceTimers = new Map<string, NodeJS.Timeout>();\n\tprivate _invalidationPendingTimestamps = new Map<string, number>();\n\tprivate _pendingInvalidations = new Map<string, { events: { type: string, documentId?: any }[] }>();\n\tprivate readonly DEBOUNCE_DELAY = 100; // 100ms debounce window\n\tprivate readonly MAX_WAIT_TIME = 500; // 500ms maximum delay\n\n\n\tconstructor() {}\n\t\n\tstatic create(wss: WebSocket.Server, serverConfig, monitorManagerFunction: MonitorManagerFunction) {\n\t\tconst subscriptionManager = new SubscriptionManager();\n\t\tsetImmediate(async () => {\n\t\t\tawait subscriptionManager.initialize(wss, serverConfig, monitorManagerFunction);\n\t\t});\n\t\treturn subscriptionManager;\n\t}\n\t\n\tprivate async initialize(wss: WebSocket.Server, serverConfig, monitorManagerFunction: MonitorManagerFunction) {\n\t\tthis._websocketManager = ResolveIOServer.getMainServer().getWebSocketManager();\n\t\tthis._monitorManagerFunction = monitorManagerFunction;\n\n\t\tthis._nodeCache = new NodeCache( { stdTTL: 0, checkperiod: 0 } );\n\n\t\tsetInterval(() => this.flushThrottledLatencyUpdates(), this.LATENCY_UPDATE_INTERVAL);\n\n\t\t// setTimeout(() => {\n\t\t// \tconsole.log('Setting up performance thread');\n\n\t\t// \tthis.performanceThread = new Worker(path.join(__dirname, './subscription.performance.js'));\n\n\t\t// \tthis.performanceThread.on('exit', code => {\n\t\t// \t\tconsole.error(new Date(), 'THREAD EXITED!!!!!!!!!!!!!!!!!!', code);\n\t\t// \t});\n\n\t\t// \tthis.performanceThread.on('error', code => {\n\t\t// \t\tconsole.error(new Date(), 'THREAD RECV ERROR !!!!!!!!!!!!!!!!!!', code);\n\t\t// \t});\n\t\t// }, 5000);\n\n\t\t// setInterval(() => {\n\t\t// \tconsole.log('Post thread msg');\n\t\t// \tthis.performanceThread.postMessage(this.currentPerfomanceMonitor);\n\t\t// \tthis.currentPerfomanceMonitor = [];\n\t\t// }, 10000);\n\n\t\tthis.serverConfig = serverConfig;\n\t\tthis._wss = wss;\n\n\t\t// Publications\n\t\tloadSuperAdminPublications(this);\n\t\tloadAppStatusPublications(this);\n\t\tloadLogPublications(this);\n\t\tloadFilePublications(this);\n\t\tloadCronJobPublications(this);\n\t\tloadFlagsUpdatePublications(this);\n\t\tloadFlagsPublications(this);\n\t\tloadNotificationPublications(this);\n\t\tloadReportBuilderReportPublications(this);\n\t\tloadReportBuilderLibraryPublications(this);\n\t\tloadUserGroupPublications(this);\n\t\tloadUserGuidePublications(this);\n\t\tloadReportBuilderDashboardBuilderPublications(this);\n\n\t\tawait this.tailOpLog();\n\n\t\tsetInterval(() => {\n\t\t\tthis._oplogRetryCount = 0;\n\t\t}, 15000);\n\n\t\tsetInterval(() => {\n\t\t\tif (this.getEnableDebug()) {\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Subs', this._subscriptions.length);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Logged In Users', this._loggedInUsers.length);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Mongo Queue', this._mongoQueue.length);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Mongo Queue Hits', this._debugMongoQueueHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Mongo Queue Collections', JSON.stringify(this._debugMongoQueueCollections.sort((a, b) => a.collection.localeCompare(b.collection) || a.publication.localeCompare(b.publication)), null, 2));\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Oplog Hits', this._debugOplogHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Oplog Collections', JSON.stringify(this._debugOplogCollections.sort((a, b) => a.collection.localeCompare(b.collection) || a.type.localeCompare(b.type)), null, 2));\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Send Queue Hits', this._debugSendQueueHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Sub Hits', this._debugSubHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Sub Collections', JSON.stringify(this._debugSubCollections.sort((a, b) => a.publication.localeCompare(b.publication)), null, 2));\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub Hits', this._debugUnSubHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub All Hits', this._debugUnSubAllHits);\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Cache Cleanup Hits', this._debugRemoveCacheHits);\n\t\t\t}\n\t\t\t\n\t\t\tthis._debugOplogHits = 0;\n\t\t\tthis._debugOplogCollections = [];\n\t\t\tthis._debugSubCollections = [];\n\t\t\tthis._debugMongoQueueHits = 0;\n\t\t\tthis._debugMongoQueueCollections = [];\n\t\t\tthis._debugSendQueueHits = 0;\n\t\t\tthis._debugSubHits = 0;\n\t\t\tthis._debugUnSubHits = 0;\n\t\t\tthis._debugUnSubAllHits = 0;\n\t\t\tthis._debugRemoveCacheHits = 0;\n\t\t}, 60000);\n\n\t\tsetInterval(async () => {\n\t\t\tthis._loggedInUsers = await LoggedInUsers.find();\n\t\n\t\t\tlet userCopy = deepCopy(this._loggedInUsers);\n\t\t\tfor (let i = this._loggedInUsers.length - 1; i >= 0; i--) {\n\t\t\t\tlet loggedInUser = userCopy[i];\n\n\t\t\t\tif (!loggedInUser.date || Date.now() - loggedInUser.date.getTime() > 120000) {\n\t\t\t\t\tif (this._websocketManager.getWebSocket(loggedInUser.id_ws)) {\n\t\t\t\t\t\tif (this.getEnableDebug()) {\n\t\t\t\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Unsub WS', this._websocketManager.getWebSocket(loggedInUser.id_ws)['user'], this._websocketManager.getWebSocket(loggedInUser.id_ws)['id_socket'], 2);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tawait this.unsubscribeAll(this._websocketManager.getWebSocket(loggedInUser.id_ws));\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis._subscriptions.forEach(sub => {\n\t\t\t\t\t\t\tfor (let j = sub.clients.length - 1; j >= 0; j--) {\n\t\t\t\t\t\t\t\tlet client = sub.clients[j];\n\n\t\t\t\t\t\t\t\tif (client.id_socket === loggedInUser.id_ws) {\n\t\t\t\t\t\t\t\t\tsub.clients.splice(j, 1);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tawait LoggedInUsers.deleteOne({_id: loggedInUser._id});\n\n\t\t\t\t\t\tif (this._loggedInUsers.findIndex(a => a._id === loggedInUser._id) >= 0) {\n\t\t\t\t\t\t\tthis._loggedInUsers.splice(this._loggedInUsers.findIndex(a => a._id === loggedInUser._id), 1);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfor (let i = 0; i < this._subscriptions.length; i++) {\n\t\t\t\tlet sub = this._subscriptions[i];\n\n\t\t\t\tfor (let j = sub.clients.length - 1; j >= 0; j--) {\n\t\t\t\t\tlet client = sub.clients[j];\n\n\t\t\t\t\tif (!this._loggedInUsers.some(a => a.id_ws === client.id_socket)) {\n\t\t\t\t\t\tsub.clients.splice(j, 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}, 30000);\n\n\t\tlet flag = await Flags.findOne({type: 'Enable Debug'});\n\t\tlet dependencyFlag = await Flags.findOne({type: 'Enable Dependency Debug'});\n\n\t\tif (flag && flag.value) {\n\t\t\tthis._enableDebug = true;\n\t\t}\n\t\telse {\n\t\t\tthis._enableDebug = false;\n\t\t}\n\n\t\tif (dependencyFlag && dependencyFlag.value) {\n\t\t\tthis._enableDependencyDebug = true;\n\t\t}\n\t\telse {\n\t\t\tthis._enableDependencyDebug = process.env.ENABLE_DEPENDENCY_DEBUG === 'true';\n\t\t}\n\n\t\tthis.setCacheLimit();\n\t}\n\n\tprivate setCacheLimit() {\t\n\t\tif (process.env.IS_WORKERS_ENABLED === 'true') {\n\t\t\tthis._heapLimit = this._heapSize * 0.4;\n\t\t}\n\t\telse {\n\t\t\tthis._heapLimit = this._heapSize * 0.3; // Use 50% of total heap size\n\t\t}\n\t}\n\n\tpublic async invalidatePubsCache(collection: string, type: string, documentId?: any) {\n\t\tlet queue = this._pendingInvalidations.get(collection);\n\t\tif (!queue) {\n\t\t\tqueue = { events: [] };\n\t\t\tthis._pendingInvalidations.set(collection, queue);\n\t\t}\n\t\tqueue.events.push({ type, documentId });\n\n\t\tconst debounceKey = collection;\n\t\tconst now = Date.now();\n\t\n\t\t// Initialize or get existing timestamp\n\t\tconst firstInvalidationTime = this._invalidationPendingTimestamps.get(debounceKey) || now;\n\t\tthis._invalidationPendingTimestamps.set(debounceKey, firstInvalidationTime);\n\t\n\t\t// Clear any existing timer\n\t\tif (this._invalidationDebounceTimers.has(debounceKey)) {\n\t\t\tclearTimeout(this._invalidationDebounceTimers.get(debounceKey));\n\t\t}\n\t\n\t\t// Check if we've waited too long\n\t\tconst waitedTooLong = (now - firstInvalidationTime) >= this.MAX_WAIT_TIME;\n\t\t\n\t\tif (waitedTooLong) {\n\t\t\t// Immediate execution path\n\t\t\tthis._invalidationPendingTimestamps.delete(debounceKey);\n\t\t\tawait this._executeInvalidation(collection);\n\t\t} else {\n\t\t\t// Normal debounce path\n\t\t\tthis._invalidationDebounceTimers.set(\n\t\t\t\tdebounceKey,\n\t\t\t\tsetTimeout(async () => {\n\t\t\t\t\tthis._invalidationPendingTimestamps.delete(debounceKey);\n\t\t\t\t\tawait this._executeInvalidation(collection);\n\t\t\t\t}, this.DEBOUNCE_DELAY)\n\t\t\t);\n\t\t}\n\t}\n\t\n\tprivate async _executeInvalidation(collection: string) {\n\t\t// Clean up any existing timer (defensive)\n\t\tif (this._invalidationDebounceTimers.has(collection)) {\n\t\t\tclearTimeout(this._invalidationDebounceTimers.get(collection));\n\t\t\tthis._invalidationDebounceTimers.delete(collection);\n\t\t}\n\n\t\tconst queued = this._pendingInvalidations.get(collection);\n\t\tthis._pendingInvalidations.delete(collection);\n\n\t\tif (!queued || !queued.events.length) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst events = queued.events;\n\t\n\t\t// Original invalidation logic\n\t\tResolveIOServer.getMongoManager().invalidateQueryCache(collection);\n\t\n\t\tconst collSubs = this._subscriptions.filter(a => a.collections.includes(collection));\n\t\n\t\tfor (const sub of collSubs) {\n\t\t\tif (this._enableDebug) {\n\t\t\t\tconsole.log(new Date(), 'Invalidate Sub', sub.publication, sub.running, sub.runAgain);\n\t\t\t}\n\n\t\t\tif (!(await this.shouldInvalidateSubscriptionForEvents(sub, collection, events))) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\n\t\t\tif (sub.running) {\n\t\t\t\tsub.runAgain = true;\n\t\t\t\tthis.dependencyDebug('Subscription busy, scheduling rerun', { publication: sub.publication, collection, events: this.summarizeEvents(events) });\n\t\t\t\tcontinue;\n\t\t\t}\n\t\n\t\t\tconst batchType = events.length === 1 ? events[0].type : events.map(event => event.type).join(',');\n\n\t\t\tif (this._publications[sub.publication].user_specific) {\n\t\t\t\tthis.dependencyDebug('Triggering user-specific invalidation', { publication: sub.publication, collection, events: this.summarizeEvents(events), clientCount: sub.clients.length });\n\t\t\t\tfor (let client of sub.clients) {\n\t\t\t\t\tconst ws = this._websocketManager.getWebSocket(client.id_socket);\n\t\t\t\t\tif (ws?.readyState === ws.OPEN) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait this.sendDataToOneWithRetry(ws, client.messageId, sub, collection, batchType);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcatch {\n\t\t\t\t\t\t\t// Error handling\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis.dependencyDebug('Triggering broadcast invalidation', { publication: sub.publication, collection, events: this.summarizeEvents(events), clientCount: sub.clients.length });\n\t\t\t\tawait this.sendDataToAllWithRetry(sub, collection, batchType);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async delay(ms: number) {\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\treturn new Promise(resolve => setTimeout(resolve, ms));\n\t}\n\n\tprivate async sendDataToAllWithRetry(sub: ActiveSubscriptionModel, collection: string, type: string) {\n\t\tsub.running = true;\n\n\t\tdo {\n\t\t\tif (this._enableDebug) {\n\t\t\t\tconsole.log(new Date(), 'Running sendDataToAll Sub', sub.publication);\n\t\t\t}\n\n\t\t\tsub.runAgain = false;\n\t\t\tawait this.sendDataToAll(sub, collection, type);\n\n\t\t\tif (this._enableDebug) {\n\t\t\t\tconsole.log(new Date(), 'Done sendDataToAll Sub', sub.publication, sub.runAgain);\n\t\t\t}\n\n\t\t\tif (sub.runAgain) {\n\t\t\t\tawait this.delay(500); // delay, adjust as needed\n\t\t\t}\n\t\t} while (sub.runAgain);\n\n\t\tsub.running = false;\n\t}\n\n\tprivate async sendDataToOneWithRetry(ws: WebSocket, messageId: number, sub: ActiveSubscriptionModel, collection: string, type: string) {\n\t\tsub.running = true;\n\n\t\tdo {\n\t\t\tif (this._enableDebug) {\n\t\t\t\tconsole.log(new Date(), 'Running sendDataToOne Sub', sub.publication);\n\t\t\t}\n\n\t\t\tsub.runAgain = false;\n\t\t\tawait this.sendDataToOne(ws, messageId, sub, collection, type);\n\n\t\t\tif (this._enableDebug) {\n\t\t\t\tconsole.log(new Date(), 'Done sendDataToOne Sub', sub.publication, sub.runAgain);\n\t\t\t}\n\n\t\t\tif (sub.runAgain) {\n\t\t\t\tawait this.delay(500); // delay, adjust as needed\n\t\t\t}\n\t\t} while (sub.runAgain);\n\t\tsub.running = false;\n\t}\n\n\t// Add all files to publications private object\n\tpublic publications(method: SubscriptionModel) {\n\t\tthis._publications = Object.assign(this._publications, method);\n\t}\n\n\t// Throttled `loggedInLatency` method\n\tpublic loggedInLatency(ws: WebSocket) {\n\t\tlet loggedInUser = this._loggedInUsers.find(a => a.id_ws === ws['id_socket']);\n\t\tif (!loggedInUser) return;\n\n\t\tconst now = new Date();\n\t\tconst existingEntry = this.latencyBuffer.get(ws['id_socket']);\n\t\tconst newLatency = ws['latency'];\n\n\t\t// Throttle updates: only update if time threshold has passed or latency has significantly changed\n\t\tif (\n\t\t\t!existingEntry || \n\t\t\t(now.getTime() - existingEntry.lastUpdate.getTime() >= this.LATENCY_UPDATE_THRESHOLD_MS) || \n\t\t\t(Math.abs(newLatency - existingEntry.latency) > 100) // Optional: log only significant changes\n\t\t) {\n\t\t\t// Update in-memory and buffer\n\t\t\tloggedInUser.date = now;\n\t\t\tthis.latencyBuffer.set(ws['id_socket'], { latency: newLatency, lastUpdate: now });\n\t\t}\n\t}\n\n\t// Method to flush buffered latency updates in bulk\n\tprivate async flushThrottledLatencyUpdates() {\n\t\tif (this.latencyBuffer.size === 0) return; // No updates to flush\n\n\t\tconst updates = Array.from(this.latencyBuffer.entries()).map(([id_ws, { latency, lastUpdate }]) => ({\n\t\t\tupdateOne: {\n\t\t\t\tfilter: { id_ws },\n\t\t\t\tupdate: { $set: { latency, date: lastUpdate } }\n\t\t\t}\n\t\t}));\n\n\t\ttry {\n\t\t\tawait LoggedInUsers.bulkWrite(updates);\n\t\t\tthis.latencyBuffer.clear(); // Clear buffer after successful update\n\n\t\t\tif (this.getEnableDebug()) {\n\t\t\t\tconsole.log(new Date(), 'Sub Manager', 'Throttled latency batch update successful', updates.length);\n\t\t\t}\n\t\t}\n\t\tcatch (error) {\n\t\t\tconsole.error(new Date(), 'Sub Manager', 'Throttled latency batch update failed', error);\n\t\t\t// Optional: implement retry logic or logging for failed updates\n\t\t}\n\t}\n\n\t// Subscribe to publication\n\tpublic async subscribe(messageRoute: string, messageDate: Date, ws: WebSocket, messageId: number, publication: string, subscriptionData: any[]) {\n\t\tthis._debugSubHits += 1;\n\n\t\tif (!this._debugSubCollections.some(a => a.publication === publication)) {\n\t\t\tthis._debugSubCollections.push({\n\t\t\t\tpublication: publication,\n\t\t\t\thits: 1\n\t\t\t});\n\t\t}\n\t\telse {\n\t\t\tthis._debugSubCollections.find(a => a.publication === publication).hits += 1;\n\t\t}\n\n\t\tlet pub = this._publications[publication];\n\n\t\tif (!pub) {\n\t\t\tconsole.error(new Date(), 'No Publication: ' + publication);\n\t\t\treturn;\n\t\t}\n\t\telse {\n\t\t\tif (subscriptionData.length > 1 || subscriptionData[0]) {\n\t\t\t\tif (!pub.check) {\n\t\t\t\t\tconsole.error(new Date(), 'No Check Function For Pub ' + publication);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\telse if (!pub.check._schema) {\n\t\t\t\t\tconsole.error(new Date(), 'No Check Schema For Pub ' + publication);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet valObj = {};\n\t\t\t\t\tlet valKeys = Object.keys(pub.check._schema);\n\n\t\t\t\t\tlet rootKeys = valKeys.filter(a => !a.includes('.'));\n\n\t\t\t\t\tfor (let i = 0; i < subscriptionData.length; i++) {\n\t\t\t\t\t\tvalObj[rootKeys[i]] = subscriptionData[i];\n\t\t\t\t\t}\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tpub.check.validate(valObj);\n\t\t\t\t\t}\n\t\t\t\t\tcatch (errors) {\n\t\t\t\t\t\tif (errors) {\n\t\t\t\t\t\t\tconsole.error(new Date(), 'Error in Pub Check (' + publication + ')', errors);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (messageRoute !== 'Bypass') {\n\t\t\t\tlet urlData = messageRoute.split('/');\n\t\t\t\tlet urlModule = '';\n\t\t\t\tlet urlNext = urlData[0];\n\n\t\t\t\tif (urlData[0] === '') {\n\t\t\t\t\turlModule = '/';\n\t\t\t\t\turlNext = urlData[1];\n\t\t\t\t}\n\n\t\t\t\turlModule += urlNext;\n\n\t\t\t\tif (urlData.length > 1) {\n\t\t\t\t\turlModule += '/';\n\t\t\t\t}\n\n\t\t\t\tlet otherRouteSubs = this._subscriptions.filter(a => a.clients.some(b => b.id_socket === ws['id_socket'] && b.messageRoute !== 'Bypass' && b.messageRoute !== '/' && b.messageRoute !== messageRoute && !b.messageRoute.startsWith(urlModule)));\n\n\t\t\t\tif (otherRouteSubs.length) {\n\t\t\t\t\t// ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Detected Undestroyed Subscription - ' + this.serverConfig['CLIENT_NAME'], 'USER: ' + ws['user'] + ' (Socket: ' + ws['id_socket'] + ') ' + ' is on route: ' + messageRoute + ' but has the following subscriptions on other routes:' + JSON.stringify(otherRouteSubs, null, 2));\n\n\t\t\t\t\totherRouteSubs.forEach(otherSub => {\n\t\t\t\t\t\totherSub.clients.filter(a => a.id_socket === ws['id_socket']).forEach(client => {\n\t\t\t\t\t\t\tthis.unsubscribe(client.messageRoute, new Date(), ws, client.messageId, otherSub.publication, otherSub.subscriptionData);\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst normalizedSubscriptionData = Array.isArray(subscriptionData) ? subscriptionData : [];\n\t\t\tconst subscriptionKey = JSON.stringify(normalizedSubscriptionData);\n\t\t\tlet sub = this._subscriptions.find(a => a.publication === publication && a.subscriptionKey === subscriptionKey);\n\n\t\t\t// If sub found (another user watching same data), add client to same sub\n\t\t\tif (sub) {\n\t\t\t\tif (!sub.clients.some(a => a.id_socket === ws['id_socket'] && a.messageId === messageId)) {\n\t\t\t\t\tsub.clients.push({\n\t\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\tid_socket: ws['id_socket'],\n\t\t\t\t\t\tmessageRoute: messageRoute\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t\t// If sub not found, create new sub\n\t\t\telse {\n\t\t\t\tthis._subscriptions.push({\n\t\t\t\t\tpublication: publication,\n\t\t\t\t\tsubscriptionKey: subscriptionKey,\n\t\t\t\t\tsubscriptionData: normalizedSubscriptionData,\n\t\t\t\t\tcollections: this.getPublicationCollections(publication),\n\t\t\t\t\tclients: [{\n\t\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\tid_socket: ws['id_socket'],\n\t\t\t\t\t\tmessageRoute: messageRoute,\n\t\t\t\t\t}],\n\t\t\t\t\tcacheId: 0,\n\t\t\t\t\trunning: false,\n\t\t\t\t\trunAgain: false,\n\t\t\t\t\tcollectionDependencies: new Map(),\n\t\t\t\t\tcollectionFilters: new Map(),\n\t\t\t\t\twatchAllCollections: new Set()\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (!sub) {\n\t\t\t\tsub = this._subscriptions.find(a => a.publication === publication && a.subscriptionKey === subscriptionKey);\n\t\t\t}\n\n\t\t\tthis.ensureDependencyContainers(sub);\n\n\t\t\tif (this._enableDebug) {\n\t\t\t\tconsole.log(new Date(), 'New Sub', sub.publication, sub.running, sub.runAgain, sub.clients.length);\n\t\t\t}\n\n\t\t\t// Immediately send data to the new client\n\t\t\tawait this.processSubscription(sub, ws, messageId);\n\t\t}\n\t}\n\n\tpublic async createLoggedInUser(id_ws: string): Promise<LoggedInUserModel> {\n\t\tlet ws = this._websocketManager.getWebSocket(id_ws);\n\n\t\tif (ws) {\n\t\t\tlet user = {\n\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t__v: 0,\n\t\t\t\tdate: new Date(),\n\t\t\t\tid_user: ws['id_user'],\n\t\t\t\tuser: ws['user'],\n\t\t\t\tid_ws: ws['id_socket']\n\t\t\t};\n\t\t\t\n\t\t\tthis._loggedInUsers.push(user);\n\t\t\tawait LoggedInUsers.insertOne(user);\n\t\t\t\n\t\t\treturn user;\n\t\t}\n\t\telse {\n\t\t\tthrow new Error('Error in Create Logged In User: No WS');\n\t\t}\n\t}\n\n\t// Unsubscribe from publication \n\tpublic unsubscribe(messageRoute: string, messageDate: Date, ws: WebSocket, messageId: number, publication: string, subscriptionData: any[]) {\t\t\n\t\tthis._debugUnSubHits += 1;\n\n\t\tif (!this._publications[publication]) {\n\t\t\tconsole.log('No Publication: ' + publication);\n\t\t\treturn;\n\t\t}\n\t\telse {\n\t\t\tconst normalizedSubscriptionData = Array.isArray(subscriptionData) ? subscriptionData : [];\n\t\t\tconst subscriptionKey = JSON.stringify(normalizedSubscriptionData);\n\t\t\tlet sub = this._subscriptions.find(a => a.publication === publication && a.subscriptionKey === subscriptionKey);\n\n\t\t\tif (sub) {\n\t\t\t\tfor (let i = sub.clients.length - 1; i >= 0; i--) {\n\t\t\t\t\tif (sub.clients[i].id_user === ws['id_user'] && sub.clients[i].messageId === messageId && sub.clients[i].id_socket === ws['id_socket']) {\n\t\t\t\t\t\tsub.clients.splice(i, 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (this._enableDebug) {\n\t\t\t\t\tconsole.log(new Date(), 'Unsub', sub.publication, sub.running, sub.runAgain, sub.clients.length);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\n\t// Unsubscribe from publication\n\tpublic async unsubscribeAll(ws: WebSocket) {\n\t\tthis._debugUnSubAllHits += 1;\n\n\t\tif (ws) {\n\t\t\t// Check if WebSocket has already been unsubscribed\n\t\t\tif (ws['isUnsubscribed']) {\n\t\t\t\treturn; // Skip if already unsubscribed\n\t\t\t}\n\t\t\t\n\t\t\t// Mark the WebSocket as unsubscribed to prevent further calls\n\t\t\tws['isUnsubscribed'] = true;\n\t\t\t\n\t\t\tif (this._loggedInUsers.map(a => a.id_ws).indexOf(ws['id_socket']) >= 0) {\n\t\t\t\tthis._loggedInUsers.splice(this._loggedInUsers.map(a => a.id_ws).indexOf(ws['id_socket']), 1);\n\t\t\t}\n\t\t\t\n\t\t\tawait LoggedInUsers.deleteOne({ id_ws: ws['id_socket'] });\n\n\t\t\tlet userSubs = this._subscriptions.filter(a => a.clients.some(b => b.id_user === ws['id_user'] && b.id_socket === ws['id_socket']));\n\n\t\t\tfor (let i = userSubs.length - 1; i >= 0; i--) {\n\t\t\t\tlet sub = userSubs[i];\n\n\t\t\t\tfor (let j = sub.clients.length - 1; j >= 0; j--) {\n\t\t\t\t\tif (sub.clients[j].id_socket === ws['id_socket']) {\n\t\t\t\t\t\tsub.clients.splice(j, 1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis._websocketManager.removeWebSocket(ws);\n\t\t}\n\t}\n\n\tpublic getActiveSubscriptions() {\n\t\treturn this._subscriptions;\n\t}\n\n\t// Get publication collection\n\tprivate getPublicationCollections(publication: string) {\n\t\treturn this._publications[publication].collections;\n\t}\n\n\tprivate getWatchedDatabases(): string[] {\n\t\tconst mongoManager = ResolveIOServer.getMongoManager();\n\t\tconst managerDatabases = mongoManager?.getWatchedDatabases() || [];\n\n\t\tif (managerDatabases.length) {\n\t\t\treturn managerDatabases;\n\t\t}\n\n\t\tconst config = this.serverConfig || ResolveIOServer.getServerConfig();\n\t\tconst mainDb = config && typeof config['DATABASE'] === 'string' ? config['DATABASE'] : '';\n\n\t\treturn mainDb ? [mainDb] : [];\n\t}\n\n\t// Watch (tail) Mongo's operation log on the entire database (all insert/modify/delete will trigger this function)\n\tprivate async tailOpLog(resumeToken?: ResumeToken) {\n\t\tif (this._oplog$ && !this._oplog$.closed) {\n\t\t\tthis._oplog$.removeAllListeners();\n\t\t\tawait this._oplog$.close();\n\t\t\tthis._oplog$ = null;\n\t\t}\n\n\t\t// eslint-disable-next-line no-restricted-syntax\n\t\tawait new Promise(resolve => setTimeout(resolve, 1000));\n\n\t\tif (!this._oplog$ || this._oplog$.closed) {\n\t\t\tthis._oplogRetryCount += 1;\n\n\t\t\tif (this._oplogRetryCount > 5) {\n\t\t\t\tconsole.error('****************** TAIL OPLOG ERROR, RETRYING A BUNCH OF TIMES, KILLING PROCESS **************************');\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\n\t\t\tconst watchDatabases = this.getWatchedDatabases();\n\t\t\tconst pipeline = [\n\t\t\t\t{\n\t\t\t\t\t$match: {\n\t\t\t\t\t\t$and: [\n\t\t\t\t\t\t\t...(watchDatabases.length ? [{ 'ns.db': { $in: watchDatabases } }] : []),\n\t\t\t\t\t\t\t{'ns.coll': { $nin: [\n\t\t\t\t\t\t\t\t'log-method-latencies', \n\t\t\t\t\t\t\t\t'log-subscriptions', \n\t\t\t\t\t\t\t\t'logs', \n\t\t\t\t\t\t\t\t'counters', \n\t\t\t\t\t\t\t\t'cron-job-histories', \n\t\t\t\t\t\t\t\t'email-histories',\n\t\t\t\t\t\t\t\t'qb-soap-request-histories', \n\t\t\t\t\t\t\t\t'qb-soap-request-responses', \n\t\t\t\t\t\t\t\t'qb-soap-requests',\n\t\t\t\t\t\t\t\t'qb-soap-retries'\n\t\t\t\t\t\t\t] }},\n\t\t\t\t\t\t\t{'ns.coll': { $not: /.*\\.versions$/ }},\n\t\t\t\t\t\t\t{'ns.coll': { $not: /^monitor-/ }},\n\t\t\t\t\t\t]\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\n\t\t\tlet lastResumeToken: ResumeToken;\n\n\t\t\tif (resumeToken) {\n\t\t\t\tlastResumeToken = resumeToken;\n\t\t\t\ttry {\n\t\t\t\t\tthis._oplog$ = ResolveIOServer.getMongoConnection().watch(pipeline, { resumeAfter: resumeToken });\n\t\t\t\t}\n\t\t\t\tcatch {\n\t\t\t\t\tif (this._oplog$) {\n\t\t\t\t\t\tthis._oplog$.removeAllListeners();\n\t\t\t\t\t\tawait this._oplog$.close();\n\t\t\t\t\t\tthis._oplog$ = null;\n\t\t\t\t\t}\n\n\t\t\t\t\tawait this.tailOpLog(resumeToken);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis._oplog$ = ResolveIOServer.getMongoConnection().watch(pipeline);\n\t\t\t}\n\n\t\t\tconsole.log(new Date(), 'oplog started');\n\n\t\t\tthis._oplog$.on('change', async (doc: ChangeStreamInsertDocument | ChangeStreamUpdateDocument | ChangeStreamReplaceDocument | ChangeStreamDeleteDocument) => {\n\t\t\t\tif (doc.ns) {\n\t\t\t\t\tif (this._enableDebug) {\n\t\t\t\t\t\tconsole.log(new Date(), 'Oplog Hit', doc.ns);\n\t\t\t\t\t}\n\n\t\t\t\t\tlet collection = doc.ns.coll;\n\n\t\t\t\t\tif (!this._debugOplogCollections.some(a => a.collection === doc.ns.coll && a.type === doc.operationType)) {\n\t\t\t\t\t\tthis._debugOplogCollections.push({\n\t\t\t\t\t\t\tcollection: doc.ns.coll,\n\t\t\t\t\t\t\ttype: doc.operationType,\n\t\t\t\t\t\t\thits: 1\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis._debugOplogCollections.find(a => a.collection === doc.ns.coll && a.type === doc.operationType).hits += 1;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (collection) {\n\t\t\t\t\t\tthis._debugOplogHits += 1;\n\t\t\t\t\t\tconst docId = doc.documentKey && doc.documentKey['_id'] !== undefined ? doc.documentKey['_id'] : (doc['fullDocument'] && doc['fullDocument']['_id'] !== undefined ? doc['fullDocument']['_id'] : null);\n\n\t\t\t\t\t\tif (doc.operationType === 'insert') {\n\t\t\t\t\t\t\tif (collection === 'support-tickets') {\n\t\t\t\t\t\t\t\tif (this.serverConfig['ROOT_URL'] === 'https://resolveio.com') {\n\t\t\t\t\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().callMethod.call(ResolveIOServer.getMainServer().getMethodManager(), 'sendSupportTicketEmail', doc.documentKey['_id']);\n\t\t\t\t\t\t\t\t\tawait this.invalidatePubsCache(collection, 'insert', docId);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (collection !== 'method-responses') {\n\t\t\t\t\t\t\t\tawait this.invalidatePubsCache(collection, 'insert', docId);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (doc.operationType === 'update' || doc.operationType === 'replace') {\n\t\t\t\t\t\t\tif (collection !== 'method-responses') {\n\t\t\t\t\t\t\t\tawait this.invalidatePubsCache(collection, 'update', docId);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (doc.operationType === 'delete') {\n\t\t\t\t\t\t\tif (collection !== 'method-responses') {\n\t\t\t\t\t\t\t\tawait this.invalidatePubsCache(collection, 'delete', docId);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (collection === 'flags') {\n\t\t\t\t\t\tlet flag = await Flags.findOne({ type: 'Enable Debug' });\n\t\t\t\t\t\tlet dependencyFlag = await Flags.findOne({ type: 'Enable Dependency Debug' });\n\t\t\t\t\t\t\n\t\t\t\t\t\tif (flag && flag.value) {\n\t\t\t\t\t\t\tthis._enableDebug = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tthis._enableDebug = false;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (dependencyFlag && dependencyFlag.value) {\n\t\t\t\t\t\t\tthis._enableDependencyDebug = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tthis._enableDependencyDebug = process.env.ENABLE_DEPENDENCY_DEBUG === 'true';\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tlastResumeToken = doc._id;\n\n\t\t\t\t\tif ((!process.env.NODE_APP_INSTANCE || process.env.NODE_APP_INSTANCE === '0') && (process.env.IS_WORKERS_ENABLED === 'false' || (process.env.IS_WORKER_INSTANCE === 'true' && process.env.WORKER_INDEX === '0'))) {\n\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tthis._oplog$.on('error', async error => {\n\t\t\t\tconsole.log(new Date(), 'oplog error', error);\n\t\t\t\tawait this._oplog$.close();\n\t\t\t});\n\n\t\t\tthis._oplog$.on('end', async () => {\n\t\t\t\tconsole.log(new Date(), 'oplog end');\n\t\t\t\tawait this._oplog$.close();\n\t\t\t});\n\n\t\t\tthis._oplog$.on('close', async () => {\n\t\t\t\tconsole.log(new Date(), 'oplog close');\n\t\t\t\tthis._oplog$.removeAllListeners();\n\t\t\t\tthis._oplog$ = null;\n\t\t\t\tawait this.tailOpLog(lastResumeToken);\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate async processSubscription(sub: ActiveSubscriptionModel, ws: WebSocket, messageId: number) {\n\t\tif (!this._publications[sub.publication].user_specific) {\t\t\t\n\t\t\tif (sub.cacheId) {\n\t\t\t\ttry {\n\t\t\t\t\tlet cacheData = JSON.parse(this._nodeCache.get(sub.cacheId), dateReviver);\n\n\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\tdata: cacheData\n\t\t\t\t\t};\n\n\t\t\t\t\tif (this._enableDebug) {\n\t\t\t\t\t\tconsole.log(new Date(), 'Process Sub, Cache', sub.publication);\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\t}\n\t\t\t\tcatch {\n\t\t\t\t\tthis._nodeCache.del(sub.cacheId);\n\t\t\t\t\tsub.cacheId = 0;\n\n\t\t\t\t\tawait this.sendDataToAllWithRetry(sub, '', 'newSub');\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (this._enableDebug) {\n\t\t\t\t\tconsole.log(new Date(), 'Process Sub, Non - Cache', sub.publication, sub.running);\n\t\t\t\t}\n\n\t\t\t\tif (sub.running) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tawait this.sendDataToAllWithRetry(sub, '', 'newSub');\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tif (this._enableDebug) {\n\t\t\t\tconsole.log(new Date(), 'Process Sub Specific, Non - Cache', sub.publication, sub.running);\n\t\t\t}\n\n\t\t\tif (sub.running) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tawait this.sendDataToOneWithRetry(ws, messageId, sub, '', 'newSub');\n\t\t}\n\t}\n\n\tprivate async sendDataToOne(ws: WebSocket, messageId: number, sub: ActiveSubscriptionModel, collection: string, type: string) {\n\t\tlet monitor = this._monitorManagerFunction.startMonitorFunction('User Specific Publication', sub.publication, '', '', sub.subscriptionData);\n\t\tlet dependencySnapshot: DependencyContextSnapshot;\n\t\tlet res;\n\t\ttry {\n\t\t\tResolveIOServer.getMainServer().getMethodManager().callMethod.call(ResolveIOServer.getMainServer().getMethodManager(), 'insertSubscriptionLog', type, sub.publication, collection, JSON.stringify(sub.subscriptionData));\n\n\t\t\tconst execution = await withDependencyTracking(() => this._publications[sub.publication].function.call(Object.assign({}, this, SubscriptionManager.prototype), ws['id_user'], ...sub.subscriptionData));\n\t\t\tres = execution.result;\n\t\t\tdependencySnapshot = execution.snapshot;\n\t\t\tthis.updateSubscriptionDependencies(sub, dependencySnapshot);\n\n\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\tmessageId: messageId,\n\t\t\t\thasError: false,\n\t\t\t\tdata: res\n\t\t\t};\n\n\t\t\tthis.sendWS(ws, serverRes);\n\t\t}\n\t\tcatch (err) {\n\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\tmessageId: messageId,\n\t\t\t\thasError: true,\n\t\t\t\tdata: err\n\t\t\t};\n\t\t\t\n\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\n\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'Error Detected During Subscription ' + sub.publication + ' - (sendDataToOne - WS)\\n\\nData \\n' + JSON.stringify(sub.subscriptionData, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(err, null, 2));\n\t\t}\n\t\tfinally {\n\t\t\tawait this._monitorManagerFunction.finishMonitorFunction(monitor);\n\t\t}\n\t}\n\n\t// Fetch pub once, send to all clients linked to this pub\n\tprivate async sendDataToAll(sub: ActiveSubscriptionModel, collection: string, type: string) {\n\t\tif (!sub.clients.length) {\n\t\t\tif (sub.cacheId) {\n\t\t\t\tthis._nodeCache.del(sub.cacheId);\n\t\t\t\tsub.cacheId = 0;\n\t\t\t}\n\n\t\t\tlet subIndex = this._subscriptions.findIndex(a => a.publication === sub.publication && a.subscriptionKey === sub.subscriptionKey);\n\t\t\tif (subIndex >= 0) {\n\t\t\t\tthis._subscriptions.splice(subIndex, 1);\n\t\t\t}\n\n\t\t\treturn;\n\t\t}\n\t\telse {\n\t\t\tlet monitor = this._monitorManagerFunction.startMonitorFunction('Publication', sub.publication, '', '', sub.subscriptionData);\n\t\t\tlet res;\n\t\t\tlet dependencySnapshot: DependencyContextSnapshot;\n\n\t\t\ttry {\n\t\t\t\tif (sub.publication !== 'superadminAPM' && sub.publication !== 'loggedInUsers') {\n\t\t\t\t\tResolveIOServer.getMainServer().getMethodManager().callMethod.call(ResolveIOServer.getMainServer().getMethodManager(), 'insertSubscriptionLog', type, sub.publication, collection, JSON.stringify(sub.subscriptionData));\n\t\t\t\t}\n\n\t\t\t\tconst execution = await withDependencyTracking(() => this._publications[sub.publication].function.call(Object.assign({}, this, SubscriptionManager.prototype), ...sub.subscriptionData));\n\t\t\t\tres = execution.result;\n\t\t\t\tdependencySnapshot = execution.snapshot;\n\t\t\t\tthis.updateSubscriptionDependencies(sub, dependencySnapshot);\n\n\t\t\t\tif (sub.cacheId) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tlet cacheData = JSON.parse(this._nodeCache.get(sub.cacheId), dateReviver);\n\t\n\t\t\t\t\t\tif (JSON.stringify(cacheData) !== JSON.stringify(res)) {\n\t\t\t\t\t\t\tfor (let client of sub.clients) {\n\t\t\t\t\t\t\t\tlet ws = this._websocketManager.getWebSocket(client.id_socket);\n\t\t\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\t\t\t\tmessageId: client.messageId,\n\t\t\t\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\t\t\t\tdata: res\n\t\t\t\t\t\t\t\t\t};\n\t\t\n\t\t\t\t\t\t\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tthis._nodeCache.del(sub.cacheId);\n\n\t\t\t\t\t\t\tif (getBinarySize(JSON.stringify(res)) < 1000000 && \n\t\t\t\t\t\t\t\t!sub.collections.includes('logs') &&\n\t\t\t\t\t\t\t\t!sub.collections.find(a => a.endsWith('.versions')) &&\n\t\t\t\t\t\t\t\t!sub.collections.find(a => a.startsWith('monitor-'))\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tthis._nodeCache.set(sub.cacheId, JSON.stringify(res));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tsub.cacheId = 0;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tcatch {\n\t\t\t\t\t\tsub.clients.map(client => {\n\t\t\t\t\t\t\tlet ws = this._websocketManager.getWebSocket(client.id_socket);\n\t\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\t\t\tmessageId: client.messageId,\n\t\t\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\t\t\tdata: res\n\t\t\t\t\t\t\t\t};\n\t\n\t\t\t\t\t\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tthis._nodeCache.del(sub.cacheId);\n\n\t\t\t\t\t\tif (getBinarySize(JSON.stringify(res)) < 1000000 && \n\t\t\t\t\t\t\t!sub.collections.includes('logs') &&\n\t\t\t\t\t\t\t!sub.collections.find(a => a.endsWith('.versions')) &&\n\t\t\t\t\t\t\t!sub.collections.find(a => a.startsWith('monitor-'))\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthis._nodeCache.set(sub.cacheId, JSON.stringify(res));\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tsub.cacheId = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tfor (let client of sub.clients) {\n\t\t\t\t\t\tlet ws = this._websocketManager.getWebSocket(client.id_socket);\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\t\tmessageId: client.messageId,\n\t\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\t\tdata: res\n\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif (getBinarySize(JSON.stringify(res)) < 1000000 && \n\t\t\t\t\t\t!sub.collections.includes('logs') &&\n\t\t\t\t\t\t!sub.collections.find(a => a.endsWith('.versions')) &&\n\t\t\t\t\t\t!sub.collections.find(a => a.startsWith('monitor-'))\n\t\t\t\t\t) {\n\t\t\t\t\t\tsub.cacheId = this._cacheId++;\n\t\t\t\t\t\tthis._nodeCache.set(sub.cacheId, JSON.stringify(res));\n\n\t\t\t\t\t\tconst nodeCacheSize = this._nodeCache.getStats().vsize;\n\n\t\t\t\t\t\tif (nodeCacheSize > this._heapLimit) {\n\t\t\t\t\t\t\t// Evict cache entries as needed\n\t\t\t\t\t\t\tlet deleteCount = 0;\n\t\t\t\t\t\t\tconst subArr = this._subscriptions.filter(a => a.cacheId && !a.clients.length);\n\t\t\t\t\t\n\t\t\t\t\t\t\tfor (let zz = 0; zz < subArr.length; zz++) {\n\t\t\t\t\t\t\t\tthis._debugRemoveCacheHits += 1;\n\t\t\t\t\t\t\t\tthis._nodeCache.del(subArr[zz].cacheId);\n\t\t\t\t\t\t\t\tsubArr[zz].cacheId = 0;\n\t\t\t\t\t\t\t\tdeleteCount += 1;\n\t\t\t\t\t\t\t\tif (this._nodeCache.getStats().vsize < this._heapLimit * 0.75) {\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (this._enableDebug) {\n\t\t\t\t\t\t\t\tconsole.log(\n\t\t\t\t\t\t\t\t\t'Sub Cache: ' +\n\t\t\t\t\t\t\t\t\t'Too Big - ' +\n\t\t\t\t\t\t\t\t\tsub.publication +\n\t\t\t\t\t\t\t\t\t' - Deleted: ' +\n\t\t\t\t\t\t\t\t\tdeleteCount +\n\t\t\t\t\t\t\t\t\t' - ' +\n\t\t\t\t\t\t\t\t\tnodeCacheSize\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tsub.cacheId = 0;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (err) {\n\t\t\t\tfor (let client of sub.clients) {\n\t\t\t\t\tlet ws = this._websocketManager.getWebSocket(client.id_socket);\n\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\tmessageId: client.messageId,\n\t\t\t\t\t\t\thasError: true,\n\t\t\t\t\t\t\tdata: err\n\t\t\t\t\t\t};\n\t\t\t\t\t\t\n\t\t\t\t\t\tthis.sendWS(ws, serverRes);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tawait ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'Error Detected During Subscription ' + sub.publication + ' - (sendPubData)\\n\\nData \\n' + JSON.stringify(sub.subscriptionData, null, 2) + '\\n\\nErrors\\n' + JSON.stringify(err, null, 2));\n\t\t\t}\n\t\t\tfinally {\n\t\t\t\tawait this._monitorManagerFunction.finishMonitorFunction(monitor);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate ensureDependencyContainers(sub: ActiveSubscriptionModel) {\n\t\tif (!sub.collectionDependencies) {\n\t\t\tsub.collectionDependencies = new Map();\n\t\t}\n\n\t\tif (!sub.collectionFilters) {\n\t\t\tsub.collectionFilters = new Map();\n\t\t}\n\n\t\tif (!sub.watchAllCollections) {\n\t\t\tsub.watchAllCollections = new Set();\n\t\t}\n\t}\n\n\tprivate updateSubscriptionDependencies(sub: ActiveSubscriptionModel, snapshot?: DependencyContextSnapshot) {\n\t\tthis.ensureDependencyContainers(sub);\n\n\t\tif (!snapshot) {\n\t\t\tsub.collectionDependencies.clear();\n\t\t\tsub.collectionFilters.clear();\n\t\t\tsub.watchAllCollections.clear();\n\t\t\tthis.dependencyDebug('Cleared dependency snapshot', { publication: sub.publication });\n\t\t\treturn;\n\t\t}\n\n\t\tsub.collectionDependencies = snapshot.dependencies;\n\t\tsub.collectionFilters = snapshot.filters;\n\t\tsub.watchAllCollections = snapshot.watchAllCollections;\n\t\tthis.logDependencySnapshot(sub, 'Snapshot updated');\n\t}\n\n\tprivate normalizeDocumentId(rawId: any): string {\n\t\tif (rawId === null || rawId === undefined) {\n\t\t\treturn null;\n\t\t}\n\n\t\tif (typeof rawId === 'string') {\n\t\t\treturn rawId;\n\t\t}\n\n\t\tif (typeof rawId === 'object' && typeof rawId.toHexString === 'function') {\n\t\t\treturn rawId.toHexString();\n\t\t}\n\n\t\tif (typeof rawId?.toString === 'function') {\n\t\t\tconst str = rawId.toString();\n\t\t\tif (str && str !== '[object Object]') {\n\t\t\t\treturn str;\n\t\t\t}\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tprivate convertDocumentIdForQuery(documentId: string) {\n\t\tif (!documentId) {\n\t\t\treturn documentId;\n\t\t}\n\n\t\tif (/^[a-fA-F0-9]{24}$/.test(documentId)) {\n\t\t\ttry {\n\t\t\t\treturn new ObjectId(documentId);\n\t\t\t}\n\t\t\tcatch {}\n\t\t}\n\n\t\treturn documentId;\n\t}\n\n\tprivate async documentMatchesFilter(collection: string, documentId: string, filter: any): Promise<boolean> {\n\t\ttry {\n\t\t\tconst db = ResolveIOServer.getMainDB();\n\t\t\tconst filterCopy = deepCopy(filter) || {};\n\t\t\tconst idValue = this.convertDocumentIdForQuery(documentId);\n\t\t\tconst combinedFilter = {\n\t\t\t\t$and: [\n\t\t\t\t\t{ _id: idValue },\n\t\t\t\t\tfilterCopy\n\t\t\t\t]\n\t\t\t};\n\n\t\t\tconst doc = await db.collection(collection).findOne(combinedFilter);\n\t\t\treturn !!doc;\n\t\t}\n\t\tcatch {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\tprivate async shouldInvalidateSubscription(sub: ActiveSubscriptionModel, collection: string, type: string, documentId?: string): Promise<boolean> {\n\t\tthis.ensureDependencyContainers(sub);\n\n\t\tif (!documentId) {\n\t\t\tthis.dependencyDebug('Invalidate due to missing documentId', { publication: sub.publication, collection, type });\n\t\t\treturn true;\n\t\t}\n\n\t\tif (sub.watchAllCollections.has(collection)) {\n\t\t\tthis.dependencyDebug('Invalidate due to watch-all collection', { publication: sub.publication, collection, type });\n\t\t\treturn true;\n\t\t}\n\n\t\tconst trackedIds = sub.collectionDependencies.get(collection);\n\n\t\tif (trackedIds && trackedIds.has(documentId)) {\n\t\t\tthis.dependencyDebug('Invalidate due to tracked id', { publication: sub.publication, collection, type, documentId });\n\t\t\treturn true;\n\t\t}\n\n\t\tif (type === 'delete') {\n\t\t\tthis.dependencyDebug('Skip invalidation on delete for unknown id', { publication: sub.publication, collection, type, documentId });\n\t\t\treturn false;\n\t\t}\n\n\t\tconst filters = sub.collectionFilters.get(collection);\n\n\t\tif (filters && filters.length) {\n\t\t\tfor (const filter of filters) {\n\t\t\t\tif (await this.documentMatchesFilter(collection, documentId, filter)) {\n\t\t\t\t\tthis.dependencyDebug('Invalidate due to filter match', { publication: sub.publication, collection, type, documentId, filter });\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis.dependencyDebug('Skip invalidation after dependency checks', { publication: sub.publication, collection, type, documentId });\n\t\treturn false;\n\t}\n\n\tprivate async shouldInvalidateSubscriptionForEvents(sub: ActiveSubscriptionModel, collection: string, events: { type: string, documentId?: any }[]): Promise<boolean> {\n\t\tfor (const event of events) {\n\t\t\tconst normalizedDocumentId = this.normalizeDocumentId(event.documentId);\n\t\t\tif (await this.shouldInvalidateSubscription(sub, collection, event.type, normalizedDocumentId)) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n\n\tprivate sendWS(ws: WebSocket, data: ServerResponseModel) {\n\t\tthis._websocketManager.send(ws, data);\n\t}\n\n\tpublic getEnableDebug() {\n\t\treturn this._enableDebug;\n\t}\n\n\tprivate dependencyDebug(message: string, details?: Record<string, unknown>) {\n\t\tif (!this._enableDependencyDebug) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (details) {\n\t\t\tconsole.log(new Date(), '[Dependency Debug]', message, JSON.stringify(details, null, 2));\n\t\t}\n\t\telse {\n\t\t\tconsole.log(new Date(), '[Dependency Debug]', message);\n\t\t}\n\t}\n\n\tprivate summarizeEvents(events: { type: string, documentId?: any }[]) {\n\t\treturn events.map(event => ({\n\t\t\ttype: event.type,\n\t\t\tdocumentId: this.normalizeDocumentId(event.documentId)\n\t\t}));\n\t}\n\n\tprivate logDependencySnapshot(sub: ActiveSubscriptionModel, context: string) {\n\t\tif (!this._enableDependencyDebug) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst dependencySummary = Array.from(sub.collectionDependencies.entries()).map(([collectionName, ids]) => {\n\t\t\tconst idList = Array.from(ids || []);\n\t\t\treturn {\n\t\t\t\tcollection: collectionName,\n\t\t\t\tcount: idList.length,\n\t\t\t\tsample: idList.slice(0, 10)\n\t\t\t};\n\t\t});\n\n\t\tconst filterSummary = Array.from(sub.collectionFilters.entries()).map(([collectionName, filters]) => ({\n\t\t\tcollection: collectionName,\n\t\t\tcount: filters.length\n\t\t}));\n\n\t\tconst watchAll = Array.from(sub.watchAllCollections || []);\n\n\t\tthis.dependencyDebug('Dependency snapshot updated', {\n\t\t\tcontext,\n\t\t\tpublication: sub.publication,\n\t\t\tdependencies: dependencySummary,\n\t\t\tcollectionsWithFilters: filterSummary,\n\t\t\twatchAll\n\t\t});\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -154,8 +154,7 @@ function recordAggregateDependencies(collection, pipeline, result) {
|
|
|
154
154
|
if (!context) {
|
|
155
155
|
return;
|
|
156
156
|
}
|
|
157
|
-
|
|
158
|
-
recordDependencyResult(collection, result, matchFilter ? { filter: matchFilter } : undefined);
|
|
157
|
+
recordDependencyResult(collection, result);
|
|
159
158
|
var lookupTargets = extractLookupTargets(pipeline);
|
|
160
159
|
if (!lookupTargets.length) {
|
|
161
160
|
return;
|
|
@@ -214,37 +213,8 @@ function extractLookupTargets(pipeline) {
|
|
|
214
213
|
}
|
|
215
214
|
return lookups;
|
|
216
215
|
}
|
|
217
|
-
function extractMatchFilter(pipeline) {
|
|
218
|
-
var e_4, _a;
|
|
219
|
-
if (!Array.isArray(pipeline)) {
|
|
220
|
-
return null;
|
|
221
|
-
}
|
|
222
|
-
var filters = [];
|
|
223
|
-
try {
|
|
224
|
-
for (var pipeline_2 = __values(pipeline), pipeline_2_1 = pipeline_2.next(); !pipeline_2_1.done; pipeline_2_1 = pipeline_2.next()) {
|
|
225
|
-
var stage = pipeline_2_1.value;
|
|
226
|
-
if (stage && stage.$match && typeof stage.$match === 'object') {
|
|
227
|
-
filters.push((0, common_1.deepCopy)(stage.$match));
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
232
|
-
finally {
|
|
233
|
-
try {
|
|
234
|
-
if (pipeline_2_1 && !pipeline_2_1.done && (_a = pipeline_2.return)) _a.call(pipeline_2);
|
|
235
|
-
}
|
|
236
|
-
finally { if (e_4) throw e_4.error; }
|
|
237
|
-
}
|
|
238
|
-
if (!filters.length) {
|
|
239
|
-
return null;
|
|
240
|
-
}
|
|
241
|
-
if (filters.length === 1) {
|
|
242
|
-
return filters[0];
|
|
243
|
-
}
|
|
244
|
-
return { $and: filters };
|
|
245
|
-
}
|
|
246
216
|
function collectLookupValues(source, path, output) {
|
|
247
|
-
var
|
|
217
|
+
var e_4, _a;
|
|
248
218
|
if (!source) {
|
|
249
219
|
return;
|
|
250
220
|
}
|
|
@@ -255,12 +225,12 @@ function collectLookupValues(source, path, output) {
|
|
|
255
225
|
collectLookupValues(item, path, output);
|
|
256
226
|
}
|
|
257
227
|
}
|
|
258
|
-
catch (
|
|
228
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
259
229
|
finally {
|
|
260
230
|
try {
|
|
261
231
|
if (source_1_1 && !source_1_1.done && (_a = source_1.return)) _a.call(source_1);
|
|
262
232
|
}
|
|
263
|
-
finally { if (
|
|
233
|
+
finally { if (e_4) throw e_4.error; }
|
|
264
234
|
}
|
|
265
235
|
return;
|
|
266
236
|
}
|
|
@@ -271,7 +241,7 @@ function collectLookupValues(source, path, output) {
|
|
|
271
241
|
collectLookupPathValues(source, pathSegments, 0, output);
|
|
272
242
|
}
|
|
273
243
|
function collectLookupPathValues(value, path, index, output) {
|
|
274
|
-
var
|
|
244
|
+
var e_5, _a;
|
|
275
245
|
if (!value) {
|
|
276
246
|
return;
|
|
277
247
|
}
|
|
@@ -292,12 +262,12 @@ function collectLookupPathValues(value, path, index, output) {
|
|
|
292
262
|
}
|
|
293
263
|
}
|
|
294
264
|
}
|
|
295
|
-
catch (
|
|
265
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
296
266
|
finally {
|
|
297
267
|
try {
|
|
298
268
|
if (current_1_1 && !current_1_1.done && (_a = current_1.return)) _a.call(current_1);
|
|
299
269
|
}
|
|
300
|
-
finally { if (
|
|
270
|
+
finally { if (e_5) throw e_5.error; }
|
|
301
271
|
}
|
|
302
272
|
}
|
|
303
273
|
else if (current && typeof current === 'object') {
|
|
@@ -323,7 +293,7 @@ function buildLookupFilter(result, localField, foreignField) {
|
|
|
323
293
|
_a;
|
|
324
294
|
}
|
|
325
295
|
function collectFieldValues(source, path, index, output) {
|
|
326
|
-
var
|
|
296
|
+
var e_6, _a, e_7, _b;
|
|
327
297
|
if (!source) {
|
|
328
298
|
return;
|
|
329
299
|
}
|
|
@@ -334,12 +304,12 @@ function collectFieldValues(source, path, index, output) {
|
|
|
334
304
|
collectFieldValues(item, path, index, output);
|
|
335
305
|
}
|
|
336
306
|
}
|
|
337
|
-
catch (
|
|
307
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
338
308
|
finally {
|
|
339
309
|
try {
|
|
340
310
|
if (source_2_1 && !source_2_1.done && (_a = source_2.return)) _a.call(source_2);
|
|
341
311
|
}
|
|
342
|
-
finally { if (
|
|
312
|
+
finally { if (e_6) throw e_6.error; }
|
|
343
313
|
}
|
|
344
314
|
return;
|
|
345
315
|
}
|
|
@@ -363,12 +333,12 @@ function collectFieldValues(source, path, index, output) {
|
|
|
363
333
|
collectFieldValues(item, path, index + 1, output);
|
|
364
334
|
}
|
|
365
335
|
}
|
|
366
|
-
catch (
|
|
336
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
367
337
|
finally {
|
|
368
338
|
try {
|
|
369
339
|
if (current_2_1 && !current_2_1.done && (_b = current_2.return)) _b.call(current_2);
|
|
370
340
|
}
|
|
371
|
-
finally { if (
|
|
341
|
+
finally { if (e_7) throw e_7.error; }
|
|
372
342
|
}
|
|
373
343
|
}
|
|
374
344
|
else {
|
|
@@ -376,7 +346,7 @@ function collectFieldValues(source, path, index, output) {
|
|
|
376
346
|
}
|
|
377
347
|
}
|
|
378
348
|
function appendFilterValue(output, value) {
|
|
379
|
-
var
|
|
349
|
+
var e_8, _a;
|
|
380
350
|
if (value === undefined || value === null) {
|
|
381
351
|
return;
|
|
382
352
|
}
|
|
@@ -387,19 +357,19 @@ function appendFilterValue(output, value) {
|
|
|
387
357
|
appendFilterValue(output, item);
|
|
388
358
|
}
|
|
389
359
|
}
|
|
390
|
-
catch (
|
|
360
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
391
361
|
finally {
|
|
392
362
|
try {
|
|
393
363
|
if (value_1_1 && !value_1_1.done && (_a = value_1.return)) _a.call(value_1);
|
|
394
364
|
}
|
|
395
|
-
finally { if (
|
|
365
|
+
finally { if (e_8) throw e_8.error; }
|
|
396
366
|
}
|
|
397
367
|
return;
|
|
398
368
|
}
|
|
399
369
|
output.push(value);
|
|
400
370
|
}
|
|
401
371
|
function dedupeFilterValues(values) {
|
|
402
|
-
var
|
|
372
|
+
var e_9, _a;
|
|
403
373
|
var unique = new Map();
|
|
404
374
|
try {
|
|
405
375
|
for (var values_1 = __values(values), values_1_1 = values_1.next(); !values_1_1.done; values_1_1 = values_1.next()) {
|
|
@@ -410,12 +380,12 @@ function dedupeFilterValues(values) {
|
|
|
410
380
|
}
|
|
411
381
|
}
|
|
412
382
|
}
|
|
413
|
-
catch (
|
|
383
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
414
384
|
finally {
|
|
415
385
|
try {
|
|
416
386
|
if (values_1_1 && !values_1_1.done && (_a = values_1.return)) _a.call(values_1);
|
|
417
387
|
}
|
|
418
|
-
finally { if (
|
|
388
|
+
finally { if (e_9) throw e_9.error; }
|
|
419
389
|
}
|
|
420
390
|
return Array.from(unique.values());
|
|
421
391
|
}
|
|
@@ -443,7 +413,7 @@ function serializeFilterValue(value) {
|
|
|
443
413
|
return String(value);
|
|
444
414
|
}
|
|
445
415
|
function collectIdsFromResult(source, ids, visited) {
|
|
446
|
-
var
|
|
416
|
+
var e_10, _a, e_11, _b;
|
|
447
417
|
if (visited === void 0) { visited = new WeakSet(); }
|
|
448
418
|
if (!source) {
|
|
449
419
|
return;
|
|
@@ -455,12 +425,12 @@ function collectIdsFromResult(source, ids, visited) {
|
|
|
455
425
|
collectIdsFromResult(item, ids, visited);
|
|
456
426
|
}
|
|
457
427
|
}
|
|
458
|
-
catch (
|
|
428
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
459
429
|
finally {
|
|
460
430
|
try {
|
|
461
431
|
if (source_3_1 && !source_3_1.done && (_a = source_3.return)) _a.call(source_3);
|
|
462
432
|
}
|
|
463
|
-
finally { if (
|
|
433
|
+
finally { if (e_10) throw e_10.error; }
|
|
464
434
|
}
|
|
465
435
|
return;
|
|
466
436
|
}
|
|
@@ -484,16 +454,16 @@ function collectIdsFromResult(source, ids, visited) {
|
|
|
484
454
|
}
|
|
485
455
|
}
|
|
486
456
|
}
|
|
487
|
-
catch (
|
|
457
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
488
458
|
finally {
|
|
489
459
|
try {
|
|
490
460
|
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
491
461
|
}
|
|
492
|
-
finally { if (
|
|
462
|
+
finally { if (e_11) throw e_11.error; }
|
|
493
463
|
}
|
|
494
464
|
}
|
|
495
465
|
function collectIdsFromFilter(filter, ids) {
|
|
496
|
-
var
|
|
466
|
+
var e_12, _a, e_13, _b, e_14, _c;
|
|
497
467
|
if (!filter) {
|
|
498
468
|
return;
|
|
499
469
|
}
|
|
@@ -504,12 +474,12 @@ function collectIdsFromFilter(filter, ids) {
|
|
|
504
474
|
collectIdsFromFilter(item, ids);
|
|
505
475
|
}
|
|
506
476
|
}
|
|
507
|
-
catch (
|
|
477
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
508
478
|
finally {
|
|
509
479
|
try {
|
|
510
480
|
if (filter_1_1 && !filter_1_1.done && (_a = filter_1.return)) _a.call(filter_1);
|
|
511
481
|
}
|
|
512
|
-
finally { if (
|
|
482
|
+
finally { if (e_12) throw e_12.error; }
|
|
513
483
|
}
|
|
514
484
|
return;
|
|
515
485
|
}
|
|
@@ -526,17 +496,17 @@ function collectIdsFromFilter(filter, ids) {
|
|
|
526
496
|
if (key === '$or' || key === '$and' || key === '$nor') {
|
|
527
497
|
if (Array.isArray(value)) {
|
|
528
498
|
try {
|
|
529
|
-
for (var value_2 = (
|
|
499
|
+
for (var value_2 = (e_14 = void 0, __values(value)), value_2_1 = value_2.next(); !value_2_1.done; value_2_1 = value_2.next()) {
|
|
530
500
|
var item = value_2_1.value;
|
|
531
501
|
collectIdsFromFilter(item, ids);
|
|
532
502
|
}
|
|
533
503
|
}
|
|
534
|
-
catch (
|
|
504
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
535
505
|
finally {
|
|
536
506
|
try {
|
|
537
507
|
if (value_2_1 && !value_2_1.done && (_c = value_2.return)) _c.call(value_2);
|
|
538
508
|
}
|
|
539
|
-
finally { if (
|
|
509
|
+
finally { if (e_14) throw e_14.error; }
|
|
540
510
|
}
|
|
541
511
|
}
|
|
542
512
|
}
|
|
@@ -545,16 +515,16 @@ function collectIdsFromFilter(filter, ids) {
|
|
|
545
515
|
}
|
|
546
516
|
}
|
|
547
517
|
}
|
|
548
|
-
catch (
|
|
518
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
549
519
|
finally {
|
|
550
520
|
try {
|
|
551
521
|
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
|
|
552
522
|
}
|
|
553
|
-
finally { if (
|
|
523
|
+
finally { if (e_13) throw e_13.error; }
|
|
554
524
|
}
|
|
555
525
|
}
|
|
556
526
|
function collectIdsFromFilterValue(value, ids) {
|
|
557
|
-
var
|
|
527
|
+
var e_15, _a, e_16, _b;
|
|
558
528
|
if (value === null || value === undefined) {
|
|
559
529
|
return;
|
|
560
530
|
}
|
|
@@ -565,12 +535,12 @@ function collectIdsFromFilterValue(value, ids) {
|
|
|
565
535
|
collectIdsFromFilterValue(item, ids);
|
|
566
536
|
}
|
|
567
537
|
}
|
|
568
|
-
catch (
|
|
538
|
+
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
569
539
|
finally {
|
|
570
540
|
try {
|
|
571
541
|
if (value_3_1 && !value_3_1.done && (_a = value_3.return)) _a.call(value_3);
|
|
572
542
|
}
|
|
573
|
-
finally { if (
|
|
543
|
+
finally { if (e_15) throw e_15.error; }
|
|
574
544
|
}
|
|
575
545
|
return;
|
|
576
546
|
}
|
|
@@ -592,12 +562,12 @@ function collectIdsFromFilterValue(value, ids) {
|
|
|
592
562
|
}
|
|
593
563
|
}
|
|
594
564
|
}
|
|
595
|
-
catch (
|
|
565
|
+
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
596
566
|
finally {
|
|
597
567
|
try {
|
|
598
568
|
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
599
569
|
}
|
|
600
|
-
finally { if (
|
|
570
|
+
finally { if (e_16) throw e_16.error; }
|
|
601
571
|
}
|
|
602
572
|
return;
|
|
603
573
|
}
|
|
@@ -635,7 +605,7 @@ function normalizeId(value) {
|
|
|
635
605
|
return null;
|
|
636
606
|
}
|
|
637
607
|
function cloneDependencyMap(original) {
|
|
638
|
-
var
|
|
608
|
+
var e_17, _a;
|
|
639
609
|
var cloned = new Map();
|
|
640
610
|
try {
|
|
641
611
|
for (var _b = __values(original.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -643,17 +613,17 @@ function cloneDependencyMap(original) {
|
|
|
643
613
|
cloned.set(collection, new Set(ids));
|
|
644
614
|
}
|
|
645
615
|
}
|
|
646
|
-
catch (
|
|
616
|
+
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
647
617
|
finally {
|
|
648
618
|
try {
|
|
649
619
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
650
620
|
}
|
|
651
|
-
finally { if (
|
|
621
|
+
finally { if (e_17) throw e_17.error; }
|
|
652
622
|
}
|
|
653
623
|
return cloned;
|
|
654
624
|
}
|
|
655
625
|
function cloneFilterMap(original) {
|
|
656
|
-
var
|
|
626
|
+
var e_18, _a;
|
|
657
627
|
var cloned = new Map();
|
|
658
628
|
try {
|
|
659
629
|
for (var _b = __values(original.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -661,12 +631,12 @@ function cloneFilterMap(original) {
|
|
|
661
631
|
cloned.set(collection, filters.map(function (filter) { return (0, common_1.deepCopy)(filter); }));
|
|
662
632
|
}
|
|
663
633
|
}
|
|
664
|
-
catch (
|
|
634
|
+
catch (e_18_1) { e_18 = { error: e_18_1 }; }
|
|
665
635
|
finally {
|
|
666
636
|
try {
|
|
667
637
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
668
638
|
}
|
|
669
|
-
finally { if (
|
|
639
|
+
finally { if (e_18) throw e_18.error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from './common';\n\nexport interface DependencyContextSnapshot {\n\tdependencies: Map<string, Set<string>>;\n\tfilters: Map<string, any[]>;\n\twatchAllCollections: Set<string>;\n}\n\ninterface LookupTarget {\n\tfrom: string;\n\tas: string;\n\tlocalField?: string;\n\tforeignField?: string;\n}\n\ninterface DependencyContext extends DependencyContextSnapshot {}\n\nconst dependencyStorage = new AsyncLocalStorage<DependencyContext>();\n\nexport async function withDependencyTracking<T>(fn: () => Promise<T>): Promise<{ result: T; snapshot: DependencyContextSnapshot }> {\n\tconst context: DependencyContext = {\n\t\tdependencies: new Map(),\n\t\tfilters: new Map(),\n\t\twatchAllCollections: new Set()\n\t};\n\n\tlet result: T;\n\n\tawait dependencyStorage.run(context, async () => {\n\t\tresult = await fn();\n\t});\n\n\treturn {\n\t\tresult,\n\t\tsnapshot: {\n\t\t\tdependencies: cloneDependencyMap(context.dependencies),\n\t\t\tfilters: cloneFilterMap(context.filters),\n\t\t\twatchAllCollections: new Set(context.watchAllCollections)\n\t\t}\n\t};\n}\n\nexport function recordDependencyResult(collection: string, result: unknown, options?: { filter?: any }) {\n\tconst context = dependencyStorage.getStore();\n\n\tif (!context) {\n\t\treturn;\n\t}\n\n\tif (options?.filter) {\n\t\tlet filterList = context.filters.get(collection);\n\n\t\tif (!filterList) {\n\t\t\tfilterList = [];\n\t\t\tcontext.filters.set(collection, filterList);\n\t\t}\n\n\t\tfilterList.push(deepCopy(options.filter));\n\t}\n\n\tconst ids = new Set<string>();\n\tcollectIdsFromResult(result, ids);\n\n\tif (!ids.size && options?.filter) {\n\t\tcollectIdsFromFilter(options.filter, ids);\n\t}\n\n\tif (ids.size) {\n\t\tlet existing = context.dependencies.get(collection);\n\n\t\tif (!existing) {\n\t\t\texisting = new Set();\n\t\t\tcontext.dependencies.set(collection, existing);\n\t\t}\n\n\t\tfor (const id of ids) {\n\t\t\texisting.add(id);\n\t\t}\n\t}\n\telse if (!options?.filter) {\n\t\tcontext.watchAllCollections.add(collection);\n\t}\n}\n\nexport function recordAggregateDependencies(collection: string, pipeline: any[], result: unknown) {\n\tconst context = dependencyStorage.getStore();\n\n\tif (!context) {\n\t\treturn;\n\t}\n\n\tconst matchFilter = extractMatchFilter(pipeline);\n\n\trecordDependencyResult(collection, result, matchFilter ? { filter: matchFilter } : undefined);\n\n\tconst lookupTargets = extractLookupTargets(pipeline);\n\n\tif (!lookupTargets.length) {\n\t\treturn;\n\t}\n\n\tfor (const target of lookupTargets) {\n\t\tconst nestedValues: unknown[] = [];\n\t\tcollectLookupValues(result, target.as, nestedValues);\n\n\t\tconst filter = buildLookupFilter(result, target.localField, target.foreignField);\n\n\t\tif (nestedValues.length || filter) {\n\t\t\trecordDependencyResult(target.from, nestedValues, filter ? { filter } : undefined);\n\t\t}\n\t\telse {\n\t\t\tcontext.watchAllCollections.add(target.from);\n\t\t}\n\t}\n}\n\nfunction extractLookupTargets(pipeline: any[]): LookupTarget[] {\n\tconst lookups: LookupTarget[] = [];\n\n\tif (!Array.isArray(pipeline)) {\n\t\treturn lookups;\n\t}\n\n\tfor (const stage of pipeline) {\n\t\tif (stage && stage.$lookup && typeof stage.$lookup === 'object') {\n\t\t\tconst lookup = stage.$lookup;\n\t\t\tif (typeof lookup.from === 'string' && typeof lookup.as === 'string') {\n\t\t\t\tlookups.push({\n\t\t\t\t\tfrom: lookup.from,\n\t\t\t\t\tas: lookup.as,\n\t\t\t\t\tlocalField: typeof lookup.localField === 'string' ? lookup.localField : undefined,\n\t\t\t\t\tforeignField: typeof lookup.foreignField === 'string' ? lookup.foreignField : undefined\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\treturn lookups;\n}\n\nfunction extractMatchFilter(pipeline: any[]): any {\n\tif (!Array.isArray(pipeline)) {\n\t\treturn null;\n\t}\n\n\tconst filters: any[] = [];\n\n\tfor (const stage of pipeline) {\n\t\tif (stage && stage.$match && typeof stage.$match === 'object') {\n\t\t\tfilters.push(deepCopy(stage.$match));\n\t\t}\n\t}\n\n\tif (!filters.length) {\n\t\treturn null;\n\t}\n\n\tif (filters.length === 1) {\n\t\treturn filters[0];\n\t}\n\n\treturn { $and: filters };\n}\n\nfunction collectLookupValues(source: unknown, path: string, output: unknown[]) {\n\tif (!source) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(source)) {\n\t\tfor (const item of source) {\n\t\t\tcollectLookupValues(item, path, output);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (typeof source !== 'object') {\n\t\treturn;\n\t}\n\n\tconst pathSegments = path.split('.');\n\tcollectLookupPathValues(source as Record<string, unknown>, pathSegments, 0, output);\n}\n\nfunction collectLookupPathValues(value: Record<string, unknown>, path: string[], index: number, output: unknown[]) {\n\tif (!value) {\n\t\treturn;\n\t}\n\n\tconst current = value[path[index]];\n\n\tif (current === undefined) {\n\t\treturn;\n\t}\n\n\tif (index === path.length - 1) {\n\t\toutput.push(current);\n\t\treturn;\n\t}\n\n\tif (Array.isArray(current)) {\n\t\tfor (const item of current) {\n\t\t\tif (item && typeof item === 'object') {\n\t\t\t\tcollectLookupPathValues(item as Record<string, unknown>, path, index + 1, output);\n\t\t\t}\n\t\t}\n\t}\n\telse if (current && typeof current === 'object') {\n\t\tcollectLookupPathValues(current as Record<string, unknown>, path, index + 1, output);\n\t}\n}\n\nfunction buildLookupFilter(result: unknown, localField?: string, foreignField?: string) {\n\tif (!localField || !foreignField) {\n\t\treturn null;\n\t}\n\n\tconst values: any[] = [];\n\tconst segments = localField.split('.');\n\tcollectFieldValues(result, segments, 0, values);\n\n\tconst uniqueValues = dedupeFilterValues(values);\n\n\tif (!uniqueValues.length) {\n\t\treturn null;\n\t}\n\n\treturn {\n\t\t[foreignField]: {\n\t\t\t$in: uniqueValues\n\t\t}\n\t};\n}\n\nfunction collectFieldValues(source: unknown, path: string[], index: number, output: any[]) {\n\tif (!source) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(source)) {\n\t\tfor (const item of source) {\n\t\t\tcollectFieldValues(item, path, index, output);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (typeof source !== 'object') {\n\t\treturn;\n\t}\n\n\tconst obj = source as Record<string, unknown>;\n\tconst key = path[index];\n\tconst current = obj[key];\n\n\tif (current === undefined) {\n\t\treturn;\n\t}\n\n\tif (index === path.length - 1) {\n\t\tappendFilterValue(output, current);\n\t\treturn;\n\t}\n\n\tif (Array.isArray(current)) {\n\t\tfor (const item of current) {\n\t\t\tcollectFieldValues(item, path, index + 1, output);\n\t\t}\n\t}\n\telse {\n\t\tcollectFieldValues(current, path, index + 1, output);\n\t}\n}\n\nfunction appendFilterValue(output: any[], value: any) {\n\tif (value === undefined || value === null) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(value)) {\n\t\tfor (const item of value) {\n\t\t\tappendFilterValue(output, item);\n\t\t}\n\t\treturn;\n\t}\n\n\toutput.push(value);\n}\n\nfunction dedupeFilterValues(values: any[]): any[] {\n\tconst unique = new Map<string, any>();\n\n\tfor (const value of values) {\n\t\tconst key = serializeFilterValue(value);\n\t\tif (!unique.has(key)) {\n\t\t\tunique.set(key, value);\n\t\t}\n\t}\n\n\treturn Array.from(unique.values());\n}\n\nfunction serializeFilterValue(value: any): string {\n\tif (value === null || value === undefined) {\n\t\treturn 'null';\n\t}\n\n\tif (typeof value === 'object') {\n\t\tif (typeof value.toHexString === 'function') {\n\t\t\treturn value.toHexString();\n\t\t}\n\n\t\tif (value instanceof Date) {\n\t\t\treturn value.toISOString();\n\t\t}\n\n\t\tif (typeof value.toString === 'function' && value.toString !== Object.prototype.toString) {\n\t\t\treturn value.toString();\n\t\t}\n\n\t\ttry {\n\t\t\treturn JSON.stringify(value);\n\t\t}\n\t\tcatch {\n\t\t\treturn '[object]';\n\t\t}\n\t}\n\n\treturn String(value);\n}\n\nfunction collectIdsFromResult(source: unknown, ids: Set<string>, visited = new WeakSet<object>()) {\n\tif (!source) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(source)) {\n\t\tfor (const item of source) {\n\t\t\tcollectIdsFromResult(item, ids, visited);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (typeof source !== 'object') {\n\t\treturn;\n\t}\n\n\tconst objectSource = source as Record<string, unknown>;\n\n\tif (visited.has(objectSource)) {\n\t\treturn;\n\t}\n\n\tvisited.add(objectSource);\n\n\tconst normalizedId = normalizeId(objectSource._id);\n\n\tif (normalizedId) {\n\t\tids.add(normalizedId);\n\t}\n\n\tfor (const value of Object.values(objectSource)) {\n\t\tif (value && (typeof value === 'object' || Array.isArray(value))) {\n\t\t\tcollectIdsFromResult(value, ids, visited);\n\t\t}\n\t}\n}\n\nfunction collectIdsFromFilter(filter: unknown, ids: Set<string>) {\n\tif (!filter) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(filter)) {\n\t\tfor (const item of filter) {\n\t\t\tcollectIdsFromFilter(item, ids);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (typeof filter !== 'object') {\n\t\treturn;\n\t}\n\n\tconst filterObject = filter as Record<string, unknown>;\n\n\tif (filterObject._id !== undefined) {\n\t\tcollectIdsFromFilterValue(filterObject._id, ids);\n\t}\n\n\tfor (const [key, value] of Object.entries(filterObject)) {\n\t\tif (key === '$or' || key === '$and' || key === '$nor') {\n\t\t\tif (Array.isArray(value)) {\n\t\t\t\tfor (const item of value) {\n\t\t\t\t\tcollectIdsFromFilter(item, ids);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse if (key !== '_id' && value && typeof value === 'object') {\n\t\t\tcollectIdsFromFilter(value, ids);\n\t\t}\n\t}\n}\n\nfunction collectIdsFromFilterValue(value: unknown, ids: Set<string>) {\n\tif (value === null || value === undefined) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(value)) {\n\t\tfor (const item of value) {\n\t\t\tcollectIdsFromFilterValue(item, ids);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (typeof value === 'object') {\n\t\tfor (const [key, inner] of Object.entries(value as Record<string, unknown>)) {\n\t\t\tif (key === '$in' || key === '$nin' || key === '$all') {\n\t\t\t\tcollectIdsFromFilterValue(inner, ids);\n\t\t\t}\n\t\t\telse if (key === '$eq' || key === '$ne') {\n\t\t\t\tcollectIdsFromFilterValue(inner, ids);\n\t\t\t}\n\t\t\telse if (key === '$or' || key === '$and' || key === '$nor') {\n\t\t\t\tcollectIdsFromFilterValue(inner, ids);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcollectIdsFromFilterValue(inner, ids);\n\t\t\t}\n\t\t}\n\t\treturn;\n\t}\n\n\tconst normalized = normalizeId(value);\n\n\tif (normalized) {\n\t\tids.add(normalized);\n\t}\n}\n\nfunction normalizeId(value: unknown): string {\n\tif (value === null || value === undefined) {\n\t\treturn null;\n\t}\n\n\tif (typeof value === 'string') {\n\t\tconst trimmed = value.trim();\n\t\treturn trimmed.length ? trimmed : null;\n\t}\n\n\tif (typeof value === 'number' || typeof value === 'bigint') {\n\t\treturn value.toString();\n\t}\n\n\tif (typeof value === 'object') {\n\t\tconst objValue = value as { toHexString?: () => string, toString?: () => string };\n\n\t\tif (typeof objValue.toHexString === 'function') {\n\t\t\treturn objValue.toHexString();\n\t\t}\n\n\t\tif (value instanceof Date) {\n\t\t\treturn value.toISOString();\n\t\t}\n\n\t\tif (typeof objValue.toString === 'function') {\n\t\t\tconst str = objValue.toString();\n\t\t\tif (str && str !== '[object Object]') {\n\t\t\t\treturn str;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn null;\n}\n\nfunction cloneDependencyMap(original: Map<string, Set<string>>): Map<string, Set<string>> {\n\tconst cloned = new Map<string, Set<string>>();\n\n\tfor (const [collection, ids] of original.entries()) {\n\t\tcloned.set(collection, new Set(ids));\n\t}\n\n\treturn cloned;\n}\n\nfunction cloneFilterMap(original: Map<string, any[]>): Map<string, any[]> {\n\tconst cloned = new Map<string, any[]>();\n\n\tfor (const [collection, filters] of original.entries()) {\n\t\tcloned.set(collection, filters.map(filter => deepCopy(filter)));\n\t}\n\n\treturn cloned;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/util/subscription-dependency-context.ts"],"names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AE,OAAO,QAAA;YAC9B,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,UAAA,MAAM,IAAI,OAAA,IAAA,iBAAQ,EAAC,MAAM,CAAC,EAAhB,CAAgB,CAAC,CAAC,CAAC;SAChE;;;;;;;;;IAED,OAAO,MAAM,CAAC;AACf,CAAC","file":"subscription-dependency-context.js","sourcesContent":["import { AsyncLocalStorage } from 'async_hooks';\nimport { deepCopy } from './common';\n\nexport interface DependencyContextSnapshot {\n\tdependencies: Map<string, Set<string>>;\n\tfilters: Map<string, any[]>;\n\twatchAllCollections: Set<string>;\n}\n\ninterface LookupTarget {\n\tfrom: string;\n\tas: string;\n\tlocalField?: string;\n\tforeignField?: string;\n}\n\ninterface DependencyContext extends DependencyContextSnapshot {}\n\nconst dependencyStorage = new AsyncLocalStorage<DependencyContext>();\n\nexport async function withDependencyTracking<T>(fn: () => Promise<T>): Promise<{ result: T; snapshot: DependencyContextSnapshot }> {\n\tconst context: DependencyContext = {\n\t\tdependencies: new Map(),\n\t\tfilters: new Map(),\n\t\twatchAllCollections: new Set()\n\t};\n\n\tlet result: T;\n\n\tawait dependencyStorage.run(context, async () => {\n\t\tresult = await fn();\n\t});\n\n\treturn {\n\t\tresult,\n\t\tsnapshot: {\n\t\t\tdependencies: cloneDependencyMap(context.dependencies),\n\t\t\tfilters: cloneFilterMap(context.filters),\n\t\t\twatchAllCollections: new Set(context.watchAllCollections)\n\t\t}\n\t};\n}\n\nexport function recordDependencyResult(collection: string, result: unknown, options?: { filter?: any }) {\n\tconst context = dependencyStorage.getStore();\n\n\tif (!context) {\n\t\treturn;\n\t}\n\n\tif (options?.filter) {\n\t\tlet filterList = context.filters.get(collection);\n\n\t\tif (!filterList) {\n\t\t\tfilterList = [];\n\t\t\tcontext.filters.set(collection, filterList);\n\t\t}\n\n\t\tfilterList.push(deepCopy(options.filter));\n\t}\n\n\tconst ids = new Set<string>();\n\tcollectIdsFromResult(result, ids);\n\n\tif (!ids.size && options?.filter) {\n\t\tcollectIdsFromFilter(options.filter, ids);\n\t}\n\n\tif (ids.size) {\n\t\tlet existing = context.dependencies.get(collection);\n\n\t\tif (!existing) {\n\t\t\texisting = new Set();\n\t\t\tcontext.dependencies.set(collection, existing);\n\t\t}\n\n\t\tfor (const id of ids) {\n\t\t\texisting.add(id);\n\t\t}\n\t}\n\telse if (!options?.filter) {\n\t\tcontext.watchAllCollections.add(collection);\n\t}\n}\n\nexport function recordAggregateDependencies(collection: string, pipeline: any[], result: unknown) {\n\tconst context = dependencyStorage.getStore();\n\n\tif (!context) {\n\t\treturn;\n\t}\n\n\trecordDependencyResult(collection, result);\n\n\tconst lookupTargets = extractLookupTargets(pipeline);\n\n\tif (!lookupTargets.length) {\n\t\treturn;\n\t}\n\n\tfor (const target of lookupTargets) {\n\t\tconst nestedValues: unknown[] = [];\n\t\tcollectLookupValues(result, target.as, nestedValues);\n\n\t\tconst filter = buildLookupFilter(result, target.localField, target.foreignField);\n\n\t\tif (nestedValues.length || filter) {\n\t\t\trecordDependencyResult(target.from, nestedValues, filter ? { filter } : undefined);\n\t\t}\n\t\telse {\n\t\t\tcontext.watchAllCollections.add(target.from);\n\t\t}\n\t}\n}\n\nfunction extractLookupTargets(pipeline: any[]): LookupTarget[] {\n\tconst lookups: LookupTarget[] = [];\n\n\tif (!Array.isArray(pipeline)) {\n\t\treturn lookups;\n\t}\n\n\tfor (const stage of pipeline) {\n\t\tif (stage && stage.$lookup && typeof stage.$lookup === 'object') {\n\t\t\tconst lookup = stage.$lookup;\n\t\t\tif (typeof lookup.from === 'string' && typeof lookup.as === 'string') {\n\t\t\t\tlookups.push({\n\t\t\t\t\tfrom: lookup.from,\n\t\t\t\t\tas: lookup.as,\n\t\t\t\t\tlocalField: typeof lookup.localField === 'string' ? lookup.localField : undefined,\n\t\t\t\t\tforeignField: typeof lookup.foreignField === 'string' ? lookup.foreignField : undefined\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\treturn lookups;\n}\n\nfunction collectLookupValues(source: unknown, path: string, output: unknown[]) {\n\tif (!source) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(source)) {\n\t\tfor (const item of source) {\n\t\t\tcollectLookupValues(item, path, output);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (typeof source !== 'object') {\n\t\treturn;\n\t}\n\n\tconst pathSegments = path.split('.');\n\tcollectLookupPathValues(source as Record<string, unknown>, pathSegments, 0, output);\n}\n\nfunction collectLookupPathValues(value: Record<string, unknown>, path: string[], index: number, output: unknown[]) {\n\tif (!value) {\n\t\treturn;\n\t}\n\n\tconst current = value[path[index]];\n\n\tif (current === undefined) {\n\t\treturn;\n\t}\n\n\tif (index === path.length - 1) {\n\t\toutput.push(current);\n\t\treturn;\n\t}\n\n\tif (Array.isArray(current)) {\n\t\tfor (const item of current) {\n\t\t\tif (item && typeof item === 'object') {\n\t\t\t\tcollectLookupPathValues(item as Record<string, unknown>, path, index + 1, output);\n\t\t\t}\n\t\t}\n\t}\n\telse if (current && typeof current === 'object') {\n\t\tcollectLookupPathValues(current as Record<string, unknown>, path, index + 1, output);\n\t}\n}\n\nfunction buildLookupFilter(result: unknown, localField?: string, foreignField?: string) {\n\tif (!localField || !foreignField) {\n\t\treturn null;\n\t}\n\n\tconst values: any[] = [];\n\tconst segments = localField.split('.');\n\tcollectFieldValues(result, segments, 0, values);\n\n\tconst uniqueValues = dedupeFilterValues(values);\n\n\tif (!uniqueValues.length) {\n\t\treturn null;\n\t}\n\n\treturn {\n\t\t[foreignField]: {\n\t\t\t$in: uniqueValues\n\t\t}\n\t};\n}\n\nfunction collectFieldValues(source: unknown, path: string[], index: number, output: any[]) {\n\tif (!source) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(source)) {\n\t\tfor (const item of source) {\n\t\t\tcollectFieldValues(item, path, index, output);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (typeof source !== 'object') {\n\t\treturn;\n\t}\n\n\tconst obj = source as Record<string, unknown>;\n\tconst key = path[index];\n\tconst current = obj[key];\n\n\tif (current === undefined) {\n\t\treturn;\n\t}\n\n\tif (index === path.length - 1) {\n\t\tappendFilterValue(output, current);\n\t\treturn;\n\t}\n\n\tif (Array.isArray(current)) {\n\t\tfor (const item of current) {\n\t\t\tcollectFieldValues(item, path, index + 1, output);\n\t\t}\n\t}\n\telse {\n\t\tcollectFieldValues(current, path, index + 1, output);\n\t}\n}\n\nfunction appendFilterValue(output: any[], value: any) {\n\tif (value === undefined || value === null) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(value)) {\n\t\tfor (const item of value) {\n\t\t\tappendFilterValue(output, item);\n\t\t}\n\t\treturn;\n\t}\n\n\toutput.push(value);\n}\n\nfunction dedupeFilterValues(values: any[]): any[] {\n\tconst unique = new Map<string, any>();\n\n\tfor (const value of values) {\n\t\tconst key = serializeFilterValue(value);\n\t\tif (!unique.has(key)) {\n\t\t\tunique.set(key, value);\n\t\t}\n\t}\n\n\treturn Array.from(unique.values());\n}\n\nfunction serializeFilterValue(value: any): string {\n\tif (value === null || value === undefined) {\n\t\treturn 'null';\n\t}\n\n\tif (typeof value === 'object') {\n\t\tif (typeof value.toHexString === 'function') {\n\t\t\treturn value.toHexString();\n\t\t}\n\n\t\tif (value instanceof Date) {\n\t\t\treturn value.toISOString();\n\t\t}\n\n\t\tif (typeof value.toString === 'function' && value.toString !== Object.prototype.toString) {\n\t\t\treturn value.toString();\n\t\t}\n\n\t\ttry {\n\t\t\treturn JSON.stringify(value);\n\t\t}\n\t\tcatch {\n\t\t\treturn '[object]';\n\t\t}\n\t}\n\n\treturn String(value);\n}\n\nfunction collectIdsFromResult(source: unknown, ids: Set<string>, visited = new WeakSet<object>()) {\n\tif (!source) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(source)) {\n\t\tfor (const item of source) {\n\t\t\tcollectIdsFromResult(item, ids, visited);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (typeof source !== 'object') {\n\t\treturn;\n\t}\n\n\tconst objectSource = source as Record<string, unknown>;\n\n\tif (visited.has(objectSource)) {\n\t\treturn;\n\t}\n\n\tvisited.add(objectSource);\n\n\tconst normalizedId = normalizeId(objectSource._id);\n\n\tif (normalizedId) {\n\t\tids.add(normalizedId);\n\t}\n\n\tfor (const value of Object.values(objectSource)) {\n\t\tif (value && (typeof value === 'object' || Array.isArray(value))) {\n\t\t\tcollectIdsFromResult(value, ids, visited);\n\t\t}\n\t}\n}\n\nfunction collectIdsFromFilter(filter: unknown, ids: Set<string>) {\n\tif (!filter) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(filter)) {\n\t\tfor (const item of filter) {\n\t\t\tcollectIdsFromFilter(item, ids);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (typeof filter !== 'object') {\n\t\treturn;\n\t}\n\n\tconst filterObject = filter as Record<string, unknown>;\n\n\tif (filterObject._id !== undefined) {\n\t\tcollectIdsFromFilterValue(filterObject._id, ids);\n\t}\n\n\tfor (const [key, value] of Object.entries(filterObject)) {\n\t\tif (key === '$or' || key === '$and' || key === '$nor') {\n\t\t\tif (Array.isArray(value)) {\n\t\t\t\tfor (const item of value) {\n\t\t\t\t\tcollectIdsFromFilter(item, ids);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse if (key !== '_id' && value && typeof value === 'object') {\n\t\t\tcollectIdsFromFilter(value, ids);\n\t\t}\n\t}\n}\n\nfunction collectIdsFromFilterValue(value: unknown, ids: Set<string>) {\n\tif (value === null || value === undefined) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(value)) {\n\t\tfor (const item of value) {\n\t\t\tcollectIdsFromFilterValue(item, ids);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (typeof value === 'object') {\n\t\tfor (const [key, inner] of Object.entries(value as Record<string, unknown>)) {\n\t\t\tif (key === '$in' || key === '$nin' || key === '$all') {\n\t\t\t\tcollectIdsFromFilterValue(inner, ids);\n\t\t\t}\n\t\t\telse if (key === '$eq' || key === '$ne') {\n\t\t\t\tcollectIdsFromFilterValue(inner, ids);\n\t\t\t}\n\t\t\telse if (key === '$or' || key === '$and' || key === '$nor') {\n\t\t\t\tcollectIdsFromFilterValue(inner, ids);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcollectIdsFromFilterValue(inner, ids);\n\t\t\t}\n\t\t}\n\t\treturn;\n\t}\n\n\tconst normalized = normalizeId(value);\n\n\tif (normalized) {\n\t\tids.add(normalized);\n\t}\n}\n\nfunction normalizeId(value: unknown): string {\n\tif (value === null || value === undefined) {\n\t\treturn null;\n\t}\n\n\tif (typeof value === 'string') {\n\t\tconst trimmed = value.trim();\n\t\treturn trimmed.length ? trimmed : null;\n\t}\n\n\tif (typeof value === 'number' || typeof value === 'bigint') {\n\t\treturn value.toString();\n\t}\n\n\tif (typeof value === 'object') {\n\t\tconst objValue = value as { toHexString?: () => string, toString?: () => string };\n\n\t\tif (typeof objValue.toHexString === 'function') {\n\t\t\treturn objValue.toHexString();\n\t\t}\n\n\t\tif (value instanceof Date) {\n\t\t\treturn value.toISOString();\n\t\t}\n\n\t\tif (typeof objValue.toString === 'function') {\n\t\t\tconst str = objValue.toString();\n\t\t\tif (str && str !== '[object Object]') {\n\t\t\t\treturn str;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn null;\n}\n\nfunction cloneDependencyMap(original: Map<string, Set<string>>): Map<string, Set<string>> {\n\tconst cloned = new Map<string, Set<string>>();\n\n\tfor (const [collection, ids] of original.entries()) {\n\t\tcloned.set(collection, new Set(ids));\n\t}\n\n\treturn cloned;\n}\n\nfunction cloneFilterMap(original: Map<string, any[]>): Map<string, any[]> {\n\tconst cloned = new Map<string, any[]>();\n\n\tfor (const [collection, filters] of original.entries()) {\n\t\tcloned.set(collection, filters.map(filter => deepCopy(filter)));\n\t}\n\n\treturn cloned;\n}\n"]}
|