@resolveio/server-lib 20.14.18 → 20.14.20

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.
@@ -55,10 +55,37 @@ export declare class SubscriptionManager {
55
55
  private _pendingInvalidations;
56
56
  private readonly DEBOUNCE_DELAY;
57
57
  private readonly MAX_WAIT_TIME;
58
+ private _warmupEnabled;
59
+ private _warmupEndsAtMs;
60
+ private _warmupQueue;
61
+ private _warmupQueueKeys;
62
+ private _warmupTimer;
63
+ private _warmupInFlight;
64
+ private _warmupProcessing;
65
+ private _warmupMaxInFlight;
66
+ private _warmupMaxPerTick;
67
+ private _warmupTickMs;
68
+ private _warmupQueueLimit;
69
+ private _warmupLogIntervalMs;
70
+ private _warmupLastLogMs;
71
+ private _warmupAllowPublications;
58
72
  constructor();
59
73
  static create(wss: WebSocket.Server, serverConfig: any, monitorManagerFunction: MonitorManagerFunction): SubscriptionManager;
60
74
  private initialize;
61
75
  private setCacheLimit;
76
+ private configureWarmup;
77
+ private parseBoolean;
78
+ private isWarmupGateActive;
79
+ private shouldQueueWarmup;
80
+ private buildWarmupKey;
81
+ private queueWarmupSubscription;
82
+ private startWarmupTimer;
83
+ private stopWarmupTimerIfIdle;
84
+ private processWarmupQueue;
85
+ private processWarmupItem;
86
+ private processWarmupItemWithCleanup;
87
+ private requeueWarmupItem;
88
+ private logWarmupStatus;
62
89
  invalidatePubsCache(collection: string, type: string, documentId?: any, document?: any): Promise<void>;
63
90
  private _executeInvalidation;
64
91
  private subscriptionReferencesCollection;
@@ -170,6 +170,20 @@ var SubscriptionManager = /** @class */ (function () {
170
170
  this._pendingInvalidations = new Map();
171
171
  this.DEBOUNCE_DELAY = 100; // 100ms debounce window
172
172
  this.MAX_WAIT_TIME = 500; // 500ms maximum delay
173
+ this._warmupEnabled = false;
174
+ this._warmupEndsAtMs = 0;
175
+ this._warmupQueue = [];
176
+ this._warmupQueueKeys = new Set();
177
+ this._warmupTimer = null;
178
+ this._warmupInFlight = 0;
179
+ this._warmupProcessing = false;
180
+ this._warmupMaxInFlight = 2;
181
+ this._warmupMaxPerTick = 2;
182
+ this._warmupTickMs = 200;
183
+ this._warmupQueueLimit = 0;
184
+ this._warmupLogIntervalMs = 10000;
185
+ this._warmupLastLogMs = 0;
186
+ this._warmupAllowPublications = new Set();
173
187
  }
174
188
  SubscriptionManager.create = function (wss, serverConfig, monitorManagerFunction) {
175
189
  var _this = this;
@@ -368,6 +382,7 @@ var SubscriptionManager = /** @class */ (function () {
368
382
  this._enableDependencyDebug = process.env.ENABLE_DEPENDENCY_DEBUG === 'true';
369
383
  }
370
384
  this.setCacheLimit();
385
+ this.configureWarmup();
371
386
  return [2 /*return*/];
372
387
  }
373
388
  });
@@ -381,6 +396,287 @@ var SubscriptionManager = /** @class */ (function () {
381
396
  this._heapLimit = this._heapSize * 0.3; // Use 50% of total heap size
382
397
  }
383
398
  };
399
+ SubscriptionManager.prototype.configureWarmup = function () {
400
+ var _a, _b, _c, _d, _e, _f, _g, _h;
401
+ var config = this.serverConfig || resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
402
+ var enabledRaw = (_a = process.env.SUBSCRIPTION_WARMUP_ENABLED) !== null && _a !== void 0 ? _a : config['SUBSCRIPTION_WARMUP_ENABLED'];
403
+ var warmupMs = this.parsePositiveNumber((_b = process.env.SUBSCRIPTION_WARMUP_MS) !== null && _b !== void 0 ? _b : config['SUBSCRIPTION_WARMUP_MS']);
404
+ var enabled = this.parseBoolean(enabledRaw) || warmupMs > 0;
405
+ if (!enabled) {
406
+ this._warmupEnabled = false;
407
+ return;
408
+ }
409
+ var durationMs = warmupMs || 60000;
410
+ this._warmupEnabled = true;
411
+ this._warmupEndsAtMs = Date.now() + durationMs;
412
+ this._warmupTickMs = this.parsePositiveNumber((_c = process.env.SUBSCRIPTION_WARMUP_TICK_MS) !== null && _c !== void 0 ? _c : config['SUBSCRIPTION_WARMUP_TICK_MS']) || this._warmupTickMs;
413
+ this._warmupMaxPerTick = this.parsePositiveNumber((_d = process.env.SUBSCRIPTION_WARMUP_MAX_PER_TICK) !== null && _d !== void 0 ? _d : config['SUBSCRIPTION_WARMUP_MAX_PER_TICK']) || this._warmupMaxPerTick;
414
+ this._warmupMaxInFlight = this.parsePositiveNumber((_e = process.env.SUBSCRIPTION_WARMUP_MAX_IN_FLIGHT) !== null && _e !== void 0 ? _e : config['SUBSCRIPTION_WARMUP_MAX_IN_FLIGHT']) || Math.max(1, this._warmupMaxPerTick);
415
+ this._warmupQueueLimit = this.parsePositiveNumber((_f = process.env.SUBSCRIPTION_WARMUP_QUEUE_LIMIT) !== null && _f !== void 0 ? _f : config['SUBSCRIPTION_WARMUP_QUEUE_LIMIT']) || this._warmupQueueLimit;
416
+ this._warmupLogIntervalMs = this.parsePositiveNumber((_g = process.env.SUBSCRIPTION_WARMUP_LOG_INTERVAL_MS) !== null && _g !== void 0 ? _g : config['SUBSCRIPTION_WARMUP_LOG_INTERVAL_MS']) || this._warmupLogIntervalMs;
417
+ var allowRaw = (_h = process.env.SUBSCRIPTION_WARMUP_ALLOW_PUBS) !== null && _h !== void 0 ? _h : config['SUBSCRIPTION_WARMUP_ALLOW_PUBS'];
418
+ if (typeof allowRaw === 'string' && allowRaw.trim()) {
419
+ this._warmupAllowPublications = new Set(allowRaw
420
+ .split(',')
421
+ .map(function (entry) { return entry.trim(); })
422
+ .filter(Boolean));
423
+ }
424
+ this.startWarmupTimer();
425
+ console.log(new Date(), 'Sub Manager', 'Warmup enabled', {
426
+ durationMs: durationMs,
427
+ tickMs: this._warmupTickMs,
428
+ maxPerTick: this._warmupMaxPerTick,
429
+ maxInFlight: this._warmupMaxInFlight,
430
+ queueLimit: this._warmupQueueLimit,
431
+ allowPubs: Array.from(this._warmupAllowPublications.values())
432
+ });
433
+ };
434
+ SubscriptionManager.prototype.parseBoolean = function (value) {
435
+ if (value === true) {
436
+ return true;
437
+ }
438
+ if (value === false || value === null || value === undefined) {
439
+ return false;
440
+ }
441
+ if (typeof value === 'number') {
442
+ return value === 1;
443
+ }
444
+ if (typeof value === 'string') {
445
+ var normalized = value.trim().toLowerCase();
446
+ return ['1', 'true', 'yes', 'y', 'on'].includes(normalized);
447
+ }
448
+ return false;
449
+ };
450
+ SubscriptionManager.prototype.isWarmupGateActive = function () {
451
+ return this._warmupEnabled && Date.now() < this._warmupEndsAtMs;
452
+ };
453
+ SubscriptionManager.prototype.shouldQueueWarmup = function (publication, messageRoute) {
454
+ if (!this.isWarmupGateActive()) {
455
+ return false;
456
+ }
457
+ if (messageRoute === 'Bypass') {
458
+ return false;
459
+ }
460
+ if (this._warmupAllowPublications.has(publication)) {
461
+ return false;
462
+ }
463
+ return true;
464
+ };
465
+ SubscriptionManager.prototype.buildWarmupKey = function (socketId, messageId, publication, subscriptionData) {
466
+ var normalizedSubscriptionData = Array.isArray(subscriptionData) ? subscriptionData : [];
467
+ return "".concat(socketId, ":").concat(messageId, ":").concat(publication, ":").concat(JSON.stringify(normalizedSubscriptionData));
468
+ };
469
+ SubscriptionManager.prototype.queueWarmupSubscription = function (params) {
470
+ var _a;
471
+ if (!this.isWarmupGateActive()) {
472
+ return false;
473
+ }
474
+ if (this._warmupQueueLimit > 0 && this._warmupQueue.length >= this._warmupQueueLimit) {
475
+ if (this._enableDebug) {
476
+ console.log(new Date(), 'Sub Manager', 'Warmup queue full; processing immediately', this._warmupQueue.length);
477
+ }
478
+ return false;
479
+ }
480
+ var socketId = (_a = params.ws) === null || _a === void 0 ? void 0 : _a['id_socket'];
481
+ if (!socketId) {
482
+ return false;
483
+ }
484
+ var key = this.buildWarmupKey(socketId, params.messageId, params.publication, params.subscriptionData);
485
+ if (this._warmupQueueKeys.has(key)) {
486
+ return true;
487
+ }
488
+ this._warmupQueue.push({
489
+ key: key,
490
+ socketId: socketId,
491
+ messageRoute: params.messageRoute,
492
+ messageDate: params.messageDate,
493
+ messageId: params.messageId,
494
+ publication: params.publication,
495
+ subscriptionData: params.subscriptionData,
496
+ enqueuedAt: Date.now()
497
+ });
498
+ this._warmupQueueKeys.add(key);
499
+ this.startWarmupTimer();
500
+ this.logWarmupStatus('queued');
501
+ return true;
502
+ };
503
+ SubscriptionManager.prototype.startWarmupTimer = function () {
504
+ var _this = this;
505
+ if (this._warmupTimer) {
506
+ return;
507
+ }
508
+ this._warmupTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
509
+ var error_1;
510
+ return __generator(this, function (_a) {
511
+ switch (_a.label) {
512
+ case 0:
513
+ _a.trys.push([0, 2, , 3]);
514
+ return [4 /*yield*/, this.processWarmupQueue()];
515
+ case 1:
516
+ _a.sent();
517
+ return [3 /*break*/, 3];
518
+ case 2:
519
+ error_1 = _a.sent();
520
+ console.error(new Date(), 'Sub Manager', 'Warmup queue processing failed', error_1);
521
+ return [3 /*break*/, 3];
522
+ case 3: return [2 /*return*/];
523
+ }
524
+ });
525
+ }); }, this._warmupTickMs);
526
+ };
527
+ SubscriptionManager.prototype.stopWarmupTimerIfIdle = function () {
528
+ if (!this._warmupTimer) {
529
+ return;
530
+ }
531
+ if (this._warmupQueue.length > 0 || this._warmupInFlight > 0 || this.isWarmupGateActive()) {
532
+ return;
533
+ }
534
+ clearInterval(this._warmupTimer);
535
+ this._warmupTimer = null;
536
+ };
537
+ SubscriptionManager.prototype.processWarmupQueue = function () {
538
+ return __awaiter(this, void 0, void 0, function () {
539
+ var pendingTasks, now, processed, _loop_3, this_3, state_1;
540
+ var _a;
541
+ return __generator(this, function (_b) {
542
+ switch (_b.label) {
543
+ case 0:
544
+ if (this._warmupProcessing) {
545
+ return [2 /*return*/];
546
+ }
547
+ this._warmupProcessing = true;
548
+ _b.label = 1;
549
+ case 1:
550
+ _b.trys.push([1, , 4, 5]);
551
+ pendingTasks = [];
552
+ now = Date.now();
553
+ if (this._warmupEnabled && now >= this._warmupEndsAtMs) {
554
+ this._warmupEnabled = false;
555
+ console.log(new Date(), 'Sub Manager', 'Warmup window ended', {
556
+ queued: this._warmupQueue.length
557
+ });
558
+ }
559
+ if (!this._warmupQueue.length) {
560
+ this.stopWarmupTimerIfIdle();
561
+ return [2 /*return*/];
562
+ }
563
+ processed = 0;
564
+ _loop_3 = function () {
565
+ var item = this_3._warmupQueue.shift();
566
+ if (!item) {
567
+ return "break";
568
+ }
569
+ this_3._warmupQueueKeys.delete(item.key);
570
+ var wasLastItem = this_3._warmupQueue.length === 0;
571
+ var ws = this_3._websocketManager.getWebSocket(item.socketId);
572
+ if (!ws || ws.readyState !== ws.OPEN) {
573
+ return "continue";
574
+ }
575
+ var normalizedSubscriptionData = Array.isArray(item.subscriptionData) ? item.subscriptionData : [];
576
+ var subscriptionKey = JSON.stringify(normalizedSubscriptionData);
577
+ var sub = this_3._subscriptions.find(function (a) { return a.publication === item.publication && a.subscriptionKey === subscriptionKey; });
578
+ if (!sub || !((_a = sub.clients) === null || _a === void 0 ? void 0 : _a.length)) {
579
+ return "continue";
580
+ }
581
+ if (sub.running) {
582
+ this_3.requeueWarmupItem(item);
583
+ processed += 1;
584
+ if (wasLastItem) {
585
+ return "break";
586
+ }
587
+ return "continue";
588
+ }
589
+ this_3._warmupInFlight += 1;
590
+ processed += 1;
591
+ pendingTasks.push(this_3.processWarmupItemWithCleanup(item, ws, sub));
592
+ };
593
+ this_3 = this;
594
+ while (this._warmupQueue.length &&
595
+ processed < this._warmupMaxPerTick &&
596
+ this._warmupInFlight < this._warmupMaxInFlight) {
597
+ state_1 = _loop_3();
598
+ if (state_1 === "break")
599
+ break;
600
+ }
601
+ if (!pendingTasks.length) return [3 /*break*/, 3];
602
+ return [4 /*yield*/, Promise.allSettled(pendingTasks)];
603
+ case 2:
604
+ _b.sent();
605
+ _b.label = 3;
606
+ case 3:
607
+ this.logWarmupStatus('tick');
608
+ return [3 /*break*/, 5];
609
+ case 4:
610
+ this._warmupProcessing = false;
611
+ return [7 /*endfinally*/];
612
+ case 5: return [2 /*return*/];
613
+ }
614
+ });
615
+ });
616
+ };
617
+ SubscriptionManager.prototype.processWarmupItem = function (item, ws, sub) {
618
+ return __awaiter(this, void 0, void 0, function () {
619
+ return __generator(this, function (_a) {
620
+ switch (_a.label) {
621
+ case 0: return [4 /*yield*/, this.processSubscription(sub, ws, item.messageId)];
622
+ case 1:
623
+ _a.sent();
624
+ return [2 /*return*/];
625
+ }
626
+ });
627
+ });
628
+ };
629
+ SubscriptionManager.prototype.processWarmupItemWithCleanup = function (item, ws, sub) {
630
+ return __awaiter(this, void 0, void 0, function () {
631
+ var error_2;
632
+ return __generator(this, function (_a) {
633
+ switch (_a.label) {
634
+ case 0:
635
+ _a.trys.push([0, 2, 3, 4]);
636
+ return [4 /*yield*/, this.processWarmupItem(item, ws, sub)];
637
+ case 1:
638
+ _a.sent();
639
+ return [3 /*break*/, 4];
640
+ case 2:
641
+ error_2 = _a.sent();
642
+ console.error(new Date(), 'Sub Manager', 'Warmup item failed', error_2);
643
+ return [3 /*break*/, 4];
644
+ case 3:
645
+ this._warmupInFlight -= 1;
646
+ this.stopWarmupTimerIfIdle();
647
+ return [7 /*endfinally*/];
648
+ case 4: return [2 /*return*/];
649
+ }
650
+ });
651
+ });
652
+ };
653
+ SubscriptionManager.prototype.requeueWarmupItem = function (item) {
654
+ if (this._warmupQueueKeys.has(item.key)) {
655
+ return;
656
+ }
657
+ item.enqueuedAt = Date.now();
658
+ this._warmupQueue.push(item);
659
+ this._warmupQueueKeys.add(item.key);
660
+ };
661
+ SubscriptionManager.prototype.logWarmupStatus = function (reason) {
662
+ if (!this._warmupLogIntervalMs) {
663
+ return;
664
+ }
665
+ var now = Date.now();
666
+ if (now - this._warmupLastLogMs < this._warmupLogIntervalMs) {
667
+ return;
668
+ }
669
+ this._warmupLastLogMs = now;
670
+ console.log(new Date(), 'Sub Manager', 'Warmup status', {
671
+ reason: reason,
672
+ enabled: this._warmupEnabled,
673
+ endsInMs: this._warmupEnabled ? Math.max(0, this._warmupEndsAtMs - now) : 0,
674
+ queued: this._warmupQueue.length,
675
+ inFlight: this._warmupInFlight,
676
+ maxPerTick: this._warmupMaxPerTick,
677
+ maxInFlight: this._warmupMaxInFlight
678
+ });
679
+ };
384
680
  SubscriptionManager.prototype.invalidatePubsCache = function (collection, type, documentId, document) {
385
681
  return __awaiter(this, void 0, void 0, function () {
386
682
  var queue, debounceKey, now, firstInvalidationTime, waitedTooLong;
@@ -724,7 +1020,7 @@ var SubscriptionManager = /** @class */ (function () {
724
1020
  // Method to flush buffered latency updates in bulk
725
1021
  SubscriptionManager.prototype.flushThrottledLatencyUpdates = function () {
726
1022
  return __awaiter(this, void 0, void 0, function () {
727
- var pendingEntries, updates, error_1, pendingEntries_1, pendingEntries_1_1, _a, id_ws, payload, current;
1023
+ var pendingEntries, updates, error_3, pendingEntries_1, pendingEntries_1_1, _a, id_ws, payload, current;
728
1024
  var e_3, _b;
729
1025
  var _this = this;
730
1026
  return __generator(this, function (_c) {
@@ -759,7 +1055,7 @@ var SubscriptionManager = /** @class */ (function () {
759
1055
  }
760
1056
  return [3 /*break*/, 5];
761
1057
  case 3:
762
- error_1 = _c.sent();
1058
+ error_3 = _c.sent();
763
1059
  try {
764
1060
  for (pendingEntries_1 = __values(pendingEntries), pendingEntries_1_1 = pendingEntries_1.next(); !pendingEntries_1_1.done; pendingEntries_1_1 = pendingEntries_1.next()) {
765
1061
  _a = __read(pendingEntries_1_1.value, 2), id_ws = _a[0], payload = _a[1];
@@ -776,7 +1072,7 @@ var SubscriptionManager = /** @class */ (function () {
776
1072
  }
777
1073
  finally { if (e_3) throw e_3.error; }
778
1074
  }
779
- console.error(new Date(), 'Sub Manager', 'Throttled latency batch update failed', error_1);
1075
+ console.error(new Date(), 'Sub Manager', 'Throttled latency batch update failed', error_3);
780
1076
  return [3 /*break*/, 5];
781
1077
  case 4:
782
1078
  this._latencyFlushInProgress = false;
@@ -793,7 +1089,7 @@ var SubscriptionManager = /** @class */ (function () {
793
1089
  // Subscribe to publication
794
1090
  SubscriptionManager.prototype.subscribe = function (messageRoute, messageDate, ws, messageId, publication, subscriptionData) {
795
1091
  return __awaiter(this, void 0, void 0, function () {
796
- var pub, valObj, valKeys, rootKeys, i, staleRouteMessage, urlData, urlModule_1, urlNext, otherRouteSubs, normalizedSubscriptionData, subscriptionKey_1, sub;
1092
+ var pub, valObj, valKeys, rootKeys, i, staleRouteMessage, urlData, urlModule_1, urlNext, otherRouteSubs, normalizedSubscriptionData, subscriptionKey_1, sub, queued;
797
1093
  var _this = this;
798
1094
  return __generator(this, function (_a) {
799
1095
  switch (_a.label) {
@@ -906,6 +1202,19 @@ var SubscriptionManager = /** @class */ (function () {
906
1202
  if (this._enableDebug) {
907
1203
  console.log(new Date(), 'New Sub', sub.publication, sub.running, sub.runAgain, sub.clients.length);
908
1204
  }
1205
+ if (this.shouldQueueWarmup(publication, messageRoute)) {
1206
+ queued = this.queueWarmupSubscription({
1207
+ ws: ws,
1208
+ messageRoute: messageRoute,
1209
+ messageDate: messageDate,
1210
+ messageId: messageId,
1211
+ publication: publication,
1212
+ subscriptionData: normalizedSubscriptionData
1213
+ });
1214
+ if (queued) {
1215
+ return [2 /*return*/];
1216
+ }
1217
+ }
909
1218
  // Immediately send data to the new client
910
1219
  return [4 /*yield*/, this.processSubscription(sub, ws, messageId)];
911
1220
  case 2:
@@ -1177,7 +1486,7 @@ var SubscriptionManager = /** @class */ (function () {
1177
1486
  };
1178
1487
  SubscriptionManager.prototype.loadResumeToken = function () {
1179
1488
  return __awaiter(this, void 0, void 0, function () {
1180
- var db, doc, error_2;
1489
+ var db, doc, error_4;
1181
1490
  return __generator(this, function (_a) {
1182
1491
  switch (_a.label) {
1183
1492
  case 0:
@@ -1191,8 +1500,8 @@ var SubscriptionManager = /** @class */ (function () {
1191
1500
  doc = _a.sent();
1192
1501
  return [2 /*return*/, (doc === null || doc === void 0 ? void 0 : doc.token) || null];
1193
1502
  case 2:
1194
- error_2 = _a.sent();
1195
- console.log(new Date(), 'Sub Manager', 'Failed to load oplog resume token', error_2);
1503
+ error_4 = _a.sent();
1504
+ console.log(new Date(), 'Sub Manager', 'Failed to load oplog resume token', error_4);
1196
1505
  return [2 /*return*/, null];
1197
1506
  case 3: return [2 /*return*/];
1198
1507
  }
@@ -1201,7 +1510,7 @@ var SubscriptionManager = /** @class */ (function () {
1201
1510
  };
1202
1511
  SubscriptionManager.prototype.saveResumeToken = function (token) {
1203
1512
  return __awaiter(this, void 0, void 0, function () {
1204
- var db, error_3;
1513
+ var db, error_5;
1205
1514
  return __generator(this, function (_a) {
1206
1515
  switch (_a.label) {
1207
1516
  case 0:
@@ -1220,8 +1529,8 @@ var SubscriptionManager = /** @class */ (function () {
1220
1529
  _a.sent();
1221
1530
  return [3 /*break*/, 4];
1222
1531
  case 3:
1223
- error_3 = _a.sent();
1224
- console.log(new Date(), 'Sub Manager', 'Failed to persist oplog resume token', error_3);
1532
+ error_5 = _a.sent();
1533
+ console.log(new Date(), 'Sub Manager', 'Failed to persist oplog resume token', error_5);
1225
1534
  return [3 /*break*/, 4];
1226
1535
  case 4: return [2 /*return*/];
1227
1536
  }
@@ -1230,7 +1539,7 @@ var SubscriptionManager = /** @class */ (function () {
1230
1539
  };
1231
1540
  SubscriptionManager.prototype.clearResumeToken = function () {
1232
1541
  return __awaiter(this, void 0, void 0, function () {
1233
- var db, error_4;
1542
+ var db, error_6;
1234
1543
  return __generator(this, function (_a) {
1235
1544
  switch (_a.label) {
1236
1545
  case 0:
@@ -1244,8 +1553,8 @@ var SubscriptionManager = /** @class */ (function () {
1244
1553
  _a.sent();
1245
1554
  return [3 /*break*/, 3];
1246
1555
  case 2:
1247
- error_4 = _a.sent();
1248
- console.log(new Date(), 'Sub Manager', 'Failed to clear oplog resume token', error_4);
1556
+ error_6 = _a.sent();
1557
+ console.log(new Date(), 'Sub Manager', 'Failed to clear oplog resume token', error_6);
1249
1558
  return [3 /*break*/, 3];
1250
1559
  case 3: return [2 /*return*/];
1251
1560
  }
@@ -1316,7 +1625,7 @@ var SubscriptionManager = /** @class */ (function () {
1316
1625
  };
1317
1626
  SubscriptionManager.prototype.fullResyncSubscriptions = function (reason) {
1318
1627
  return __awaiter(this, void 0, void 0, function () {
1319
- var subs, subs_1, subs_1_1, sub, pub, _a, _b, client, ws, _c, e_4_1, e_5_1, error_5;
1628
+ var subs, subs_1, subs_1_1, sub, pub, _a, _b, client, ws, _c, e_4_1, e_5_1, error_7;
1320
1629
  var e_5, _d, e_4, _e;
1321
1630
  var _f, _g, _h, _j, _k;
1322
1631
  return __generator(this, function (_l) {
@@ -1414,8 +1723,8 @@ var SubscriptionManager = /** @class */ (function () {
1414
1723
  return [7 /*endfinally*/];
1415
1724
  case 19: return [3 /*break*/, 21];
1416
1725
  case 20:
1417
- error_5 = _l.sent();
1418
- console.log(new Date(), 'Sub Manager', 'Full resync failed', reason, error_5);
1726
+ error_7 = _l.sent();
1727
+ console.log(new Date(), 'Sub Manager', 'Full resync failed', reason, error_7);
1419
1728
  return [3 /*break*/, 21];
1420
1729
  case 21: return [2 /*return*/];
1421
1730
  }
@@ -1425,7 +1734,7 @@ var SubscriptionManager = /** @class */ (function () {
1425
1734
  // Watch (tail) Mongo's operation log on the entire database (all insert/modify/delete will trigger this function)
1426
1735
  SubscriptionManager.prototype.tailOpLog = function (resumeToken) {
1427
1736
  return __awaiter(this, void 0, void 0, function () {
1428
- var watchDatabases, pipeline, lastResumeToken_1, startedWithResumeToken, error_6, innerError_1, error_7;
1737
+ var watchDatabases, pipeline, lastResumeToken_1, startedWithResumeToken, error_8, innerError_1, error_9;
1429
1738
  var _this = this;
1430
1739
  return __generator(this, function (_a) {
1431
1740
  switch (_a.label) {
@@ -1486,9 +1795,9 @@ var SubscriptionManager = /** @class */ (function () {
1486
1795
  startedWithResumeToken = true;
1487
1796
  return [3 /*break*/, 16];
1488
1797
  case 5:
1489
- error_6 = _a.sent();
1490
- if (!this.isChangeStreamUnsupported(error_6)) return [3 /*break*/, 7];
1491
- return [4 /*yield*/, this.enableLocalOplogFallback('change-stream-unsupported', error_6)];
1798
+ error_8 = _a.sent();
1799
+ if (!this.isChangeStreamUnsupported(error_8)) return [3 /*break*/, 7];
1800
+ return [4 /*yield*/, this.enableLocalOplogFallback('change-stream-unsupported', error_8)];
1492
1801
  case 6:
1493
1802
  _a.sent();
1494
1803
  return [2 /*return*/];
@@ -1504,7 +1813,7 @@ var SubscriptionManager = /** @class */ (function () {
1504
1813
  case 10:
1505
1814
  _a.sent();
1506
1815
  lastResumeToken_1 = null;
1507
- console.log(new Date(), 'oplog resumeAfter failed, starting fresh', error_6);
1816
+ console.log(new Date(), 'oplog resumeAfter failed, starting fresh', error_8);
1508
1817
  _a.label = 11;
1509
1818
  case 11:
1510
1819
  _a.trys.push([11, 12, , 15]);
@@ -1528,13 +1837,13 @@ var SubscriptionManager = /** @class */ (function () {
1528
1837
  this._oplog$ = resolveio_server_app_1.ResolveIOServer.getMongoConnection().watch(pipeline, { fullDocument: 'updateLookup' });
1529
1838
  return [3 /*break*/, 21];
1530
1839
  case 18:
1531
- error_7 = _a.sent();
1532
- if (!this.isChangeStreamUnsupported(error_7)) return [3 /*break*/, 20];
1533
- return [4 /*yield*/, this.enableLocalOplogFallback('change-stream-unsupported', error_7)];
1840
+ error_9 = _a.sent();
1841
+ if (!this.isChangeStreamUnsupported(error_9)) return [3 /*break*/, 20];
1842
+ return [4 /*yield*/, this.enableLocalOplogFallback('change-stream-unsupported', error_9)];
1534
1843
  case 19:
1535
1844
  _a.sent();
1536
1845
  return [2 /*return*/];
1537
- case 20: throw error_7;
1846
+ case 20: throw error_9;
1538
1847
  case 21:
1539
1848
  console.log(new Date(), 'oplog started', startedWithResumeToken ? '(resumeAfter)' : '');
1540
1849
  this._oplog$.on('change', function (doc) { return __awaiter(_this, void 0, void 0, function () {