@resolveio/server-lib 5.1.8 → 5.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/managers/subscription.manager.js +187 -224
- package/package.json +1 -1
|
@@ -510,7 +510,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
510
510
|
var _this = this;
|
|
511
511
|
var that = this;
|
|
512
512
|
setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
513
|
-
var uniqueOplog_1, uniquePubs, needIds_1, _loop_2, i, _loop_3, i, i, oplog, _loop_4, j;
|
|
513
|
+
var uniqueOplog_1, uniquePubs, needIds_1, _loop_2, i, _loop_3, i, i, oplog, _loop_4, this_1, j;
|
|
514
514
|
var _this = this;
|
|
515
515
|
return __generator(this, function (_a) {
|
|
516
516
|
switch (_a.label) {
|
|
@@ -593,68 +593,129 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
593
593
|
switch (_c.label) {
|
|
594
594
|
case 0:
|
|
595
595
|
sub = that._subscriptions[j];
|
|
596
|
-
if (!sub.collections.includes(oplog.collection)) return [3 /*break*/,
|
|
597
|
-
if (sub.preSubscriptionData)
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
596
|
+
if (!sub.collections.includes(oplog.collection)) return [3 /*break*/, 17];
|
|
597
|
+
if (!sub.preSubscriptionData) return [3 /*break*/, 5];
|
|
598
|
+
if (!that._publications[sub.publication].fetchFunction(oplog.doc, sub.preSubscriptionData)) return [3 /*break*/, 5];
|
|
599
|
+
if (!!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }).length) return [3 /*break*/, 4];
|
|
600
|
+
if (!!sub.clients.length) return [3 /*break*/, 2];
|
|
601
|
+
that._subscriptions.splice(j, 1);
|
|
602
|
+
return [4 /*yield*/, active_subscription_collection_1.ActiveSubscriptions.deleteOne({
|
|
603
|
+
$and: [
|
|
604
|
+
{ publication: sub.publication },
|
|
605
|
+
{ subData: JSON.stringify(sub.subscriptionData) }
|
|
606
|
+
]
|
|
607
|
+
}).exec()];
|
|
608
|
+
case 1:
|
|
609
|
+
_c.sent();
|
|
610
|
+
return [3 /*break*/, 3];
|
|
611
|
+
case 2:
|
|
612
|
+
sub['oplog'] = oplog;
|
|
613
|
+
uniquePubs.push(sub);
|
|
614
|
+
_c.label = 3;
|
|
615
|
+
case 3:
|
|
616
|
+
if (this_1._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
617
|
+
this_1._nodeCache.del(this_1._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
618
|
+
this_1._subCache.splice(this_1._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
605
619
|
}
|
|
606
|
-
|
|
620
|
+
_c.label = 4;
|
|
621
|
+
case 4: return [2 /*return*/, "continue"];
|
|
622
|
+
case 5:
|
|
623
|
+
if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 10];
|
|
624
|
+
if (!!sub.clients.length) return [3 /*break*/, 7];
|
|
625
|
+
that._subscriptions.splice(j, 1);
|
|
626
|
+
return [4 /*yield*/, active_subscription_collection_1.ActiveSubscriptions.deleteOne({
|
|
627
|
+
$and: [
|
|
628
|
+
{ publication: sub.publication },
|
|
629
|
+
{ subData: JSON.stringify(sub.subscriptionData) }
|
|
630
|
+
]
|
|
631
|
+
}).exec()];
|
|
632
|
+
case 6:
|
|
633
|
+
_c.sent();
|
|
634
|
+
if (this_1._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
635
|
+
this_1._nodeCache.del(this_1._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
636
|
+
this_1._subCache.splice(this_1._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
637
|
+
}
|
|
638
|
+
return [3 /*break*/, 9];
|
|
639
|
+
case 7:
|
|
607
640
|
_b = sub;
|
|
608
641
|
return [4 /*yield*/, that._publications[sub.publication].preFunction(sub.subscriptionData)];
|
|
609
|
-
case
|
|
642
|
+
case 8:
|
|
610
643
|
_b.preSubscriptionData = _c.sent();
|
|
611
644
|
if (that._publications[sub.publication].fetchFunction(oplog.doc, sub.preSubscriptionData)) {
|
|
612
645
|
if (!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }).length) {
|
|
613
646
|
sub['oplog'] = oplog;
|
|
614
647
|
uniquePubs.push(sub);
|
|
615
648
|
}
|
|
616
|
-
return [2 /*return*/, "continue"];
|
|
617
649
|
}
|
|
618
|
-
|
|
619
|
-
case
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
650
|
+
_c.label = 9;
|
|
651
|
+
case 9: return [3 /*break*/, 17];
|
|
652
|
+
case 10:
|
|
653
|
+
if (!that._publications[sub.publication].fetchFunction) return [3 /*break*/, 14];
|
|
654
|
+
if (!(_a = that._publications[sub.publication]).fetchFunction.apply(_a, [oplog.doc].concat(sub.subscriptionData))) return [3 /*break*/, 13];
|
|
655
|
+
if (!!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }).length) return [3 /*break*/, 13];
|
|
656
|
+
if (!!sub.clients.length) return [3 /*break*/, 12];
|
|
657
|
+
that._subscriptions.splice(j, 1);
|
|
658
|
+
return [4 /*yield*/, active_subscription_collection_1.ActiveSubscriptions.deleteOne({
|
|
659
|
+
$and: [
|
|
660
|
+
{ publication: sub.publication },
|
|
661
|
+
{ subData: JSON.stringify(sub.subscriptionData) }
|
|
662
|
+
]
|
|
663
|
+
}).exec()];
|
|
664
|
+
case 11:
|
|
665
|
+
_c.sent();
|
|
666
|
+
if (this_1._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
667
|
+
this_1._nodeCache.del(this_1._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
668
|
+
this_1._subCache.splice(this_1._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
628
669
|
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
670
|
+
return [3 /*break*/, 13];
|
|
671
|
+
case 12:
|
|
672
|
+
sub['oplog'] = oplog;
|
|
673
|
+
uniquePubs.push(sub);
|
|
674
|
+
_c.label = 13;
|
|
675
|
+
case 13: return [3 /*break*/, 17];
|
|
676
|
+
case 14:
|
|
677
|
+
if (!!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }).length) return [3 /*break*/, 17];
|
|
678
|
+
if (!!sub.clients.length) return [3 /*break*/, 16];
|
|
679
|
+
that._subscriptions.splice(j, 1);
|
|
680
|
+
return [4 /*yield*/, active_subscription_collection_1.ActiveSubscriptions.deleteOne({
|
|
681
|
+
$and: [
|
|
682
|
+
{ publication: sub.publication },
|
|
683
|
+
{ subData: JSON.stringify(sub.subscriptionData) }
|
|
684
|
+
]
|
|
685
|
+
}).exec()];
|
|
686
|
+
case 15:
|
|
687
|
+
_c.sent();
|
|
688
|
+
if (this_1._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
689
|
+
this_1._nodeCache.del(this_1._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
690
|
+
this_1._subCache.splice(this_1._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
635
691
|
}
|
|
636
|
-
|
|
637
|
-
case
|
|
692
|
+
return [3 /*break*/, 17];
|
|
693
|
+
case 16:
|
|
694
|
+
sub['oplog'] = oplog;
|
|
695
|
+
uniquePubs.push(sub);
|
|
696
|
+
_c.label = 17;
|
|
697
|
+
case 17: return [2 /*return*/];
|
|
638
698
|
}
|
|
639
699
|
});
|
|
640
700
|
};
|
|
641
|
-
|
|
701
|
+
this_1 = this;
|
|
702
|
+
j = that._subscriptions.length - 1;
|
|
642
703
|
_a.label = 6;
|
|
643
704
|
case 6:
|
|
644
|
-
if (!(j
|
|
705
|
+
if (!(j >= 0)) return [3 /*break*/, 9];
|
|
645
706
|
return [5 /*yield**/, _loop_4(j)];
|
|
646
707
|
case 7:
|
|
647
708
|
_a.sent();
|
|
648
709
|
_a.label = 8;
|
|
649
710
|
case 8:
|
|
650
|
-
j
|
|
711
|
+
j--;
|
|
651
712
|
return [3 /*break*/, 6];
|
|
652
713
|
case 9:
|
|
653
714
|
i--;
|
|
654
715
|
return [3 /*break*/, 5];
|
|
655
716
|
case 10:
|
|
656
717
|
uniquePubs.forEach(function (pub) {
|
|
657
|
-
_this.checkPubsForChanges(pub['oplog'].collection, pub['oplog'].doc, pub['oplog'].type);
|
|
718
|
+
_this.checkPubsForChanges(pub['oplog'].collection, pub['oplog'].doc, pub['oplog'].type, pub.publication);
|
|
658
719
|
});
|
|
659
720
|
_a.label = 11;
|
|
660
721
|
case 11: return [2 /*return*/];
|
|
@@ -664,7 +725,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
664
725
|
};
|
|
665
726
|
SubscriptionManager.prototype.resendPubsForDelete = function (collection) {
|
|
666
727
|
return __awaiter(this, void 0, void 0, function () {
|
|
667
|
-
var that, subCopy, _loop_5,
|
|
728
|
+
var that, subCopy, _loop_5, this_2, jj, _loop_6, zz;
|
|
668
729
|
var _this = this;
|
|
669
730
|
return __generator(this, function (_a) {
|
|
670
731
|
switch (_a.label) {
|
|
@@ -672,12 +733,12 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
672
733
|
that = this;
|
|
673
734
|
subCopy = common_1.deepCopy(that._subscriptions.filter(function (a) { return a.collections.includes(collection); }));
|
|
674
735
|
_loop_5 = function (jj) {
|
|
675
|
-
if (
|
|
676
|
-
|
|
677
|
-
|
|
736
|
+
if (this_2._subCache[jj].collection === collection || subCopy.some(function (a) { return a.publication === _this._subCache[jj].publication; })) {
|
|
737
|
+
this_2._nodeCache.del(this_2._subCache[jj].id);
|
|
738
|
+
this_2._subCache.splice(jj, 1);
|
|
678
739
|
}
|
|
679
740
|
};
|
|
680
|
-
|
|
741
|
+
this_2 = this;
|
|
681
742
|
for (jj = this._subCache.length - 1; jj >= 0; jj--) {
|
|
682
743
|
_loop_5(jj);
|
|
683
744
|
}
|
|
@@ -687,17 +748,21 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
687
748
|
switch (_a.label) {
|
|
688
749
|
case 0:
|
|
689
750
|
sub = subCopy[zz];
|
|
690
|
-
if (!that._publications[sub.publication].ws_specific) return [3 /*break*/,
|
|
691
|
-
if (
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
751
|
+
if (!that._publications[sub.publication].ws_specific) return [3 /*break*/, 1];
|
|
752
|
+
if (sub.clients.length) {
|
|
753
|
+
sub.clients.forEach(function (client) {
|
|
754
|
+
that._wss.clients.forEach(function (ws) {
|
|
755
|
+
if (ws['id_socket'] === client.id_socket) {
|
|
756
|
+
that.sendPubDataOnce(ws, client.messageId, sub, 'delete', collection);
|
|
757
|
+
}
|
|
758
|
+
});
|
|
697
759
|
});
|
|
698
|
-
}
|
|
699
|
-
|
|
760
|
+
}
|
|
761
|
+
else {
|
|
762
|
+
}
|
|
763
|
+
return [3 /*break*/, 4];
|
|
700
764
|
case 1:
|
|
765
|
+
if (!!sub.clients.length) return [3 /*break*/, 3];
|
|
701
766
|
if (that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
702
767
|
that._subscriptions.splice(that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
703
768
|
}
|
|
@@ -709,26 +774,11 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
709
774
|
}).exec()];
|
|
710
775
|
case 2:
|
|
711
776
|
_a.sent();
|
|
712
|
-
|
|
713
|
-
case 3:
|
|
714
|
-
case 4:
|
|
715
|
-
if (!!sub.clients.length) return [3 /*break*/, 6];
|
|
716
|
-
if (that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
717
|
-
that._subscriptions.splice(that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
718
|
-
}
|
|
719
|
-
return [4 /*yield*/, active_subscription_collection_1.ActiveSubscriptions.deleteOne({
|
|
720
|
-
$and: [
|
|
721
|
-
{ publication: sub.publication },
|
|
722
|
-
{ subData: JSON.stringify(sub.subscriptionData) }
|
|
723
|
-
]
|
|
724
|
-
}).exec()];
|
|
725
|
-
case 5:
|
|
726
|
-
_a.sent();
|
|
727
|
-
return [3 /*break*/, 7];
|
|
728
|
-
case 6:
|
|
777
|
+
return [3 /*break*/, 4];
|
|
778
|
+
case 3:
|
|
729
779
|
that.sendPubData(sub, 'delete', collection);
|
|
730
|
-
_a.label =
|
|
731
|
-
case
|
|
780
|
+
_a.label = 4;
|
|
781
|
+
case 4: return [2 /*return*/];
|
|
732
782
|
}
|
|
733
783
|
});
|
|
734
784
|
};
|
|
@@ -751,169 +801,82 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
751
801
|
// Document: Inserted/Modified/Deleted Document
|
|
752
802
|
// Collection: Collection Document Lives In
|
|
753
803
|
// Check to see if any pubs need to refetch due to Mongo operation
|
|
754
|
-
SubscriptionManager.prototype.checkPubsForChanges = function (collection, document, type) {
|
|
804
|
+
SubscriptionManager.prototype.checkPubsForChanges = function (collection, document, type, sub) {
|
|
755
805
|
return __awaiter(this, void 0, void 0, function () {
|
|
756
|
-
var
|
|
757
|
-
return __generator(this, function (
|
|
758
|
-
switch (
|
|
806
|
+
var _a, _b, that, _c, _d;
|
|
807
|
+
return __generator(this, function (_e) {
|
|
808
|
+
switch (_e.label) {
|
|
759
809
|
case 0:
|
|
760
810
|
that = this;
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
return
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
case 2: return [2 /*return*/, "continue"];
|
|
797
|
-
case 3:
|
|
798
|
-
if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 5];
|
|
799
|
-
_d = sub;
|
|
800
|
-
return [4 /*yield*/, that._publications[sub.publication].preFunction(sub.subscriptionData)];
|
|
801
|
-
case 4:
|
|
802
|
-
_d.preSubscriptionData = _e.sent();
|
|
803
|
-
if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
|
|
804
|
-
removed = false;
|
|
805
|
-
if (this_2._subCache.some(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })) {
|
|
806
|
-
if (!sub.clients.length) {
|
|
807
|
-
that._subscriptions.splice(that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
808
|
-
active_subscription_collection_1.ActiveSubscriptions.deleteOne({
|
|
809
|
-
$and: [
|
|
810
|
-
{ publication: sub.publication },
|
|
811
|
-
{ subData: JSON.stringify(sub.subscriptionData) }
|
|
812
|
-
]
|
|
813
|
-
}).exec();
|
|
814
|
-
removed = true;
|
|
815
|
-
}
|
|
816
|
-
this_2._nodeCache.del(this_2._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
817
|
-
this_2._subCache.splice(this_2._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
818
|
-
}
|
|
819
|
-
if (!removed) {
|
|
820
|
-
that.sendPubData(sub, type, collection);
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
return [3 /*break*/, 6];
|
|
824
|
-
case 5:
|
|
825
|
-
if (that._publications[sub.publication].ws_specific) {
|
|
826
|
-
sub.clients.forEach(function (client) {
|
|
827
|
-
var _a;
|
|
828
|
-
if (that._publications[sub.publication].fetchFunction) {
|
|
829
|
-
if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, [document, client.id_user].concat(sub.subscriptionData))) {
|
|
830
|
-
that._wss.clients.forEach(function (ws) {
|
|
831
|
-
if (ws['id_socket'] === client.id_socket) {
|
|
832
|
-
that.sendPubDataOnce(ws, client.messageId, sub, type, collection);
|
|
833
|
-
}
|
|
834
|
-
});
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
else {
|
|
838
|
-
that._wss.clients.forEach(function (ws) {
|
|
839
|
-
if (ws['id_socket'] === client.id_socket) {
|
|
840
|
-
that.sendPubDataOnce(ws, client.messageId, sub, type, collection);
|
|
841
|
-
}
|
|
842
|
-
});
|
|
843
|
-
}
|
|
844
|
-
});
|
|
845
|
-
}
|
|
846
|
-
else {
|
|
847
|
-
if (that._publications[sub.publication].fetchFunction) {
|
|
848
|
-
if ((_b = that._publications[sub.publication]).fetchFunction.apply(_b, [document].concat(sub.subscriptionData))) {
|
|
849
|
-
removed = false;
|
|
850
|
-
if (this_2._subCache.some(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })) {
|
|
851
|
-
if (!sub.clients.length) {
|
|
852
|
-
if (that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
853
|
-
that._subscriptions.splice(that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
854
|
-
}
|
|
855
|
-
active_subscription_collection_1.ActiveSubscriptions.deleteOne({
|
|
856
|
-
$and: [
|
|
857
|
-
{ publication: sub.publication },
|
|
858
|
-
{ subData: JSON.stringify(sub.subscriptionData) }
|
|
859
|
-
]
|
|
860
|
-
}).exec();
|
|
861
|
-
removed = true;
|
|
862
|
-
}
|
|
863
|
-
this_2._nodeCache.del(this_2._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
864
|
-
if (this_2._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
865
|
-
this_2._subCache.splice(this_2._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
if (!removed) {
|
|
869
|
-
that.sendPubData(sub, type, collection);
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
// else
|
|
873
|
-
}
|
|
874
|
-
else {
|
|
875
|
-
removed = false;
|
|
876
|
-
if (this_2._subCache.some(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })) {
|
|
877
|
-
if (!sub.clients.length) {
|
|
878
|
-
if (that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
879
|
-
that._subscriptions.splice(that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
880
|
-
}
|
|
881
|
-
active_subscription_collection_1.ActiveSubscriptions.deleteOne({
|
|
882
|
-
$and: [
|
|
883
|
-
{ publication: sub.publication },
|
|
884
|
-
{ subData: JSON.stringify(sub.subscriptionData) }
|
|
885
|
-
]
|
|
886
|
-
}).exec();
|
|
887
|
-
removed = true;
|
|
888
|
-
}
|
|
889
|
-
this_2._nodeCache.del(this_2._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
890
|
-
if (this_2._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
891
|
-
this_2._subCache.splice(this_2._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
|
-
if (!removed) {
|
|
895
|
-
that.sendPubData(sub, type, collection);
|
|
896
|
-
}
|
|
811
|
+
if (!sub.preSubscriptionData) return [3 /*break*/, 2];
|
|
812
|
+
if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 2];
|
|
813
|
+
if (this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
814
|
+
this._nodeCache.del(this._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
815
|
+
this._subCache.splice(this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
816
|
+
}
|
|
817
|
+
that.sendPubData(sub, type, collection);
|
|
818
|
+
_c = sub;
|
|
819
|
+
return [4 /*yield*/, (_a = that._publications[sub.publication]).preFunction.apply(_a, sub.subscriptionData)];
|
|
820
|
+
case 1:
|
|
821
|
+
_c.preSubscriptionData = _e.sent();
|
|
822
|
+
_e.label = 2;
|
|
823
|
+
case 2:
|
|
824
|
+
if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 4];
|
|
825
|
+
_d = sub;
|
|
826
|
+
return [4 /*yield*/, that._publications[sub.publication].preFunction(sub.subscriptionData)];
|
|
827
|
+
case 3:
|
|
828
|
+
_d.preSubscriptionData = _e.sent();
|
|
829
|
+
if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
|
|
830
|
+
if (this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
831
|
+
this._nodeCache.del(this._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
832
|
+
this._subCache.splice(this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
833
|
+
}
|
|
834
|
+
that.sendPubData(sub, type, collection);
|
|
835
|
+
}
|
|
836
|
+
return [3 /*break*/, 5];
|
|
837
|
+
case 4:
|
|
838
|
+
if (that._publications[sub.publication].ws_specific) {
|
|
839
|
+
sub.clients.forEach(function (client) {
|
|
840
|
+
var _a;
|
|
841
|
+
if (that._publications[sub.publication].fetchFunction) {
|
|
842
|
+
if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, [document, client.id_user].concat(sub.subscriptionData))) {
|
|
843
|
+
that._wss.clients.forEach(function (ws) {
|
|
844
|
+
if (ws['id_socket'] === client.id_socket) {
|
|
845
|
+
that.sendPubDataOnce(ws, client.messageId, sub, type, collection);
|
|
897
846
|
}
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
else {
|
|
851
|
+
that._wss.clients.forEach(function (ws) {
|
|
852
|
+
if (ws['id_socket'] === client.id_socket) {
|
|
853
|
+
that.sendPubDataOnce(ws, client.messageId, sub, type, collection);
|
|
898
854
|
}
|
|
899
|
-
|
|
900
|
-
case 6: return [2 /*return*/];
|
|
855
|
+
});
|
|
901
856
|
}
|
|
902
857
|
});
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
858
|
+
}
|
|
859
|
+
else {
|
|
860
|
+
if (that._publications[sub.publication].fetchFunction) {
|
|
861
|
+
if ((_b = that._publications[sub.publication]).fetchFunction.apply(_b, [document].concat(sub.subscriptionData))) {
|
|
862
|
+
if (this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
863
|
+
this._nodeCache.del(this._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
864
|
+
this._subCache.splice(this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
865
|
+
}
|
|
866
|
+
that.sendPubData(sub, type, collection);
|
|
867
|
+
}
|
|
868
|
+
// else
|
|
869
|
+
}
|
|
870
|
+
else {
|
|
871
|
+
if (this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
872
|
+
this._nodeCache.del(this._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
873
|
+
this._subCache.splice(this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
874
|
+
}
|
|
875
|
+
that.sendPubData(sub, type, collection);
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
_e.label = 5;
|
|
879
|
+
case 5: return [2 /*return*/];
|
|
917
880
|
}
|
|
918
881
|
});
|
|
919
882
|
});
|