@resolveio/server-lib 4.2.3 → 4.2.5-debug-1
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.
|
@@ -12,8 +12,8 @@ export declare class SubscriptionManager {
|
|
|
12
12
|
constructor(mainServer: any, wss: WebSocket.Server, serverConfig: any);
|
|
13
13
|
publications(method: SubscriptionModel): void;
|
|
14
14
|
loggedInLatency(ws: WebSocket): Promise<void>;
|
|
15
|
-
subscribe(ws: WebSocket, messageId: number, publication: string, ...subscriptionData: any[]): Promise<void>;
|
|
16
|
-
unsubscribe(ws: WebSocket, messageId: number, publication: string, ...subscriptionData: any[]): Promise<void>;
|
|
15
|
+
subscribe(messageDate: Date, ws: WebSocket, messageId: number, publication: string, ...subscriptionData: any[]): Promise<void>;
|
|
16
|
+
unsubscribe(messageDate: Date, ws: WebSocket, messageId: number, publication: string, ...subscriptionData: any[]): Promise<void>;
|
|
17
17
|
unsubscribeAll(ws: WebSocket): Promise<void>;
|
|
18
18
|
private getPublicationCollections;
|
|
19
19
|
private tailOpLog;
|
|
@@ -131,10 +131,10 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
131
131
|
});
|
|
132
132
|
};
|
|
133
133
|
// Subscribe to publication
|
|
134
|
-
SubscriptionManager.prototype.subscribe = function (ws, messageId, publication) {
|
|
134
|
+
SubscriptionManager.prototype.subscribe = function (messageDate, ws, messageId, publication) {
|
|
135
135
|
var subscriptionData = [];
|
|
136
|
-
for (var _i =
|
|
137
|
-
subscriptionData[_i -
|
|
136
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
|
137
|
+
subscriptionData[_i - 4] = arguments[_i];
|
|
138
138
|
}
|
|
139
139
|
return __awaiter(this, void 0, void 0, function () {
|
|
140
140
|
var that, pub, valObj, valKeys, rootKeys, i, sub, _a, newActiveSub, begDate, endDate, billUser;
|
|
@@ -200,6 +200,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
200
200
|
if (!sub) {
|
|
201
201
|
sub = that._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
|
|
202
202
|
}
|
|
203
|
+
console.log('Subscribe', new Date(), 'Success', sub);
|
|
203
204
|
// Send pub data to client who just subscribed only, don't want to send to existing clients since nothing has changed
|
|
204
205
|
that.sendPubDataOnce(ws, messageId, sub, 'newSub', that.getPublicationCollections(publication)[0]);
|
|
205
206
|
if (!(that._publications[sub.publication].preFunction && !sub.preSubscriptionData)) return [3 /*break*/, 3];
|
|
@@ -271,10 +272,10 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
271
272
|
});
|
|
272
273
|
};
|
|
273
274
|
// Unsubscribe from publication
|
|
274
|
-
SubscriptionManager.prototype.unsubscribe = function (ws, messageId, publication) {
|
|
275
|
+
SubscriptionManager.prototype.unsubscribe = function (messageDate, ws, messageId, publication) {
|
|
275
276
|
var subscriptionData = [];
|
|
276
|
-
for (var _i =
|
|
277
|
-
subscriptionData[_i -
|
|
277
|
+
for (var _i = 4; _i < arguments.length; _i++) {
|
|
278
|
+
subscriptionData[_i - 4] = arguments[_i];
|
|
278
279
|
}
|
|
279
280
|
return __awaiter(this, void 0, void 0, function () {
|
|
280
281
|
var that, sub, i, activeSub;
|
|
@@ -551,88 +552,50 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
551
552
|
oplogQueue_1.forEach(function (oplog) { return __awaiter(_this, void 0, void 0, function () {
|
|
552
553
|
var _loop_3, i;
|
|
553
554
|
return __generator(this, function (_a) {
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
if (!sub.collections.includes(oplog.collection)) return [3 /*break*/, 3];
|
|
564
|
-
if (sub.preSubscriptionData) {
|
|
565
|
-
if (that._publications[sub.publication].fetchFunction(oplog.doc, sub.preSubscriptionData)) {
|
|
566
|
-
if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0]) {
|
|
567
|
-
uniquePubs_1.push(sub);
|
|
568
|
-
uniqueOplog_1.push(oplog);
|
|
569
|
-
}
|
|
570
|
-
return [2 /*return*/, "continue"];
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 2];
|
|
574
|
-
_a = sub;
|
|
575
|
-
return [4 /*yield*/, that._publications[sub.publication].preFunction(sub.subscriptionData)];
|
|
576
|
-
case 1:
|
|
577
|
-
_a.preSubscriptionData = _c.sent();
|
|
578
|
-
if (that._publications[sub.publication].fetchFunction(oplog.doc, sub.preSubscriptionData)) {
|
|
579
|
-
if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)); })[0]) {
|
|
580
|
-
uniquePubs_1.push(sub);
|
|
581
|
-
uniqueOplog_1.push(oplog);
|
|
582
|
-
}
|
|
583
|
-
return [2 /*return*/, "continue"];
|
|
584
|
-
}
|
|
585
|
-
return [3 /*break*/, 3];
|
|
586
|
-
case 2:
|
|
587
|
-
if (that._publications[sub.publication].ws_specific) {
|
|
588
|
-
sub.clients.forEach(function (client) {
|
|
589
|
-
var _a;
|
|
590
|
-
if (that._publications[sub.publication].fetchFunction) {
|
|
591
|
-
if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, [oplog.doc, client.id_user].concat(sub.subscriptionData))) {
|
|
592
|
-
if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0]) {
|
|
593
|
-
uniquePubs_1.push(sub);
|
|
594
|
-
uniqueOplog_1.push(oplog);
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
});
|
|
599
|
-
}
|
|
600
|
-
else {
|
|
601
|
-
if (that._publications[sub.publication].fetchFunction) {
|
|
602
|
-
if ((_b = that._publications[sub.publication]).fetchFunction.apply(_b, [oplog.doc].concat(sub.subscriptionData))) {
|
|
603
|
-
if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)); })[0]) {
|
|
604
|
-
uniquePubs_1.push(sub);
|
|
605
|
-
uniqueOplog_1.push(oplog);
|
|
606
|
-
}
|
|
607
|
-
return [2 /*return*/, "continue"];
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
else {
|
|
611
|
-
if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)); })[0]) {
|
|
612
|
-
uniquePubs_1.push(sub);
|
|
613
|
-
uniqueOplog_1.push(oplog);
|
|
614
|
-
}
|
|
615
|
-
return [2 /*return*/, "continue"];
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
_c.label = 3;
|
|
619
|
-
case 3: return [2 /*return*/];
|
|
555
|
+
_loop_3 = function (i) {
|
|
556
|
+
var _a;
|
|
557
|
+
var sub = that._subscriptions[i];
|
|
558
|
+
if (sub.collections.includes(oplog.collection)) {
|
|
559
|
+
if (sub.preSubscriptionData) {
|
|
560
|
+
if (that._publications[sub.publication].fetchFunction(oplog.doc, sub.preSubscriptionData)) {
|
|
561
|
+
if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)); })[0]) {
|
|
562
|
+
uniquePubs_1.push(sub);
|
|
563
|
+
uniqueOplog_1.push(oplog);
|
|
620
564
|
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
565
|
+
return "continue";
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
if (that._publications[sub.publication].preFunction) {
|
|
569
|
+
if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)); })[0]) {
|
|
570
|
+
uniquePubs_1.push(sub);
|
|
571
|
+
uniqueOplog_1.push(oplog);
|
|
572
|
+
}
|
|
573
|
+
return "continue";
|
|
574
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
if (that._publications[sub.publication].fetchFunction) {
|
|
577
|
+
if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, [oplog.doc].concat(sub.subscriptionData))) {
|
|
578
|
+
if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)); })[0]) {
|
|
579
|
+
uniquePubs_1.push(sub);
|
|
580
|
+
uniqueOplog_1.push(oplog);
|
|
581
|
+
}
|
|
582
|
+
return "continue";
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)); })[0]) {
|
|
587
|
+
uniquePubs_1.push(sub);
|
|
588
|
+
uniqueOplog_1.push(oplog);
|
|
589
|
+
}
|
|
590
|
+
return "continue";
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
for (i = 0; i < that._subscriptions.length; i++) {
|
|
596
|
+
_loop_3(i);
|
|
635
597
|
}
|
|
598
|
+
return [2 /*return*/];
|
|
636
599
|
});
|
|
637
600
|
}); });
|
|
638
601
|
uniqueOplog_1.forEach(function (oplog) {
|
|
@@ -661,66 +624,47 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
661
624
|
// Document: Inserted/Modified/Deleted Document
|
|
662
625
|
// Collection: Collection Document Lives In
|
|
663
626
|
// Check to see if any pubs need to refetch due to Mongo operation
|
|
664
|
-
SubscriptionManager.prototype.checkPubsForChanges = function (collection, document, type
|
|
627
|
+
SubscriptionManager.prototype.checkPubsForChanges = function (collection, document, type) {
|
|
665
628
|
var _this = this;
|
|
666
|
-
if (fetchFunctionOnly === void 0) { fetchFunctionOnly = false; }
|
|
667
|
-
if (noFetchFunction === void 0) { noFetchFunction = false; }
|
|
668
629
|
var that = this;
|
|
669
630
|
that._subscriptions.filter(function (a) { return a.collections.includes(collection); }).forEach(function (sub) { return __awaiter(_this, void 0, void 0, function () {
|
|
670
|
-
var
|
|
631
|
+
var _a, _b;
|
|
671
632
|
var _c, _d;
|
|
672
633
|
return __generator(this, function (_e) {
|
|
673
634
|
switch (_e.label) {
|
|
674
635
|
case 0:
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
index_1.ResolveIOServer.getMainDB().model(collection)['simplschema'].validate(document);
|
|
678
|
-
}
|
|
679
|
-
catch (errors) {
|
|
680
|
-
schemaErrors = errors;
|
|
681
|
-
}
|
|
682
|
-
if (!schemaErrors) return [3 /*break*/, 2];
|
|
683
|
-
return [4 /*yield*/, index_1.ResolveIOServer.getMainDB().model(collection).findById(document['_id'])];
|
|
684
|
-
case 1:
|
|
685
|
-
document = _e.sent();
|
|
686
|
-
_e.label = 2;
|
|
687
|
-
case 2:
|
|
688
|
-
if (!sub.preSubscriptionData) return [3 /*break*/, 4];
|
|
689
|
-
if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 4];
|
|
636
|
+
if (!sub.preSubscriptionData) return [3 /*break*/, 2];
|
|
637
|
+
if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 2];
|
|
690
638
|
that.sendPubData(sub, type, collection);
|
|
691
639
|
_a = sub;
|
|
692
640
|
return [4 /*yield*/, (_c = that._publications[sub.publication]).preFunction.apply(_c, sub.subscriptionData)];
|
|
693
|
-
case
|
|
641
|
+
case 1:
|
|
694
642
|
_a.preSubscriptionData = _e.sent();
|
|
695
|
-
_e.label =
|
|
696
|
-
case
|
|
697
|
-
if (!that._publications[sub.publication].preFunction) return [3 /*break*/,
|
|
698
|
-
if (!!noFetchFunction) return [3 /*break*/, 6];
|
|
643
|
+
_e.label = 2;
|
|
644
|
+
case 2:
|
|
645
|
+
if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 4];
|
|
699
646
|
_b = sub;
|
|
700
647
|
return [4 /*yield*/, that._publications[sub.publication].preFunction(sub.subscriptionData)];
|
|
701
|
-
case
|
|
648
|
+
case 3:
|
|
702
649
|
_b.preSubscriptionData = _e.sent();
|
|
703
650
|
if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
|
|
704
651
|
that.sendPubData(sub, type, collection);
|
|
705
652
|
}
|
|
706
|
-
|
|
707
|
-
case
|
|
708
|
-
case 7:
|
|
653
|
+
return [3 /*break*/, 5];
|
|
654
|
+
case 4:
|
|
709
655
|
if (that._publications[sub.publication].ws_specific) {
|
|
710
656
|
sub.clients.forEach(function (client) {
|
|
711
657
|
var _a;
|
|
712
658
|
if (that._publications[sub.publication].fetchFunction) {
|
|
713
|
-
if (
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
});
|
|
720
|
-
}
|
|
659
|
+
if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, [document, client.id_user].concat(sub.subscriptionData))) {
|
|
660
|
+
that._wss.clients.forEach(function (ws) {
|
|
661
|
+
if (ws['id_socket'] === client.id_socket) {
|
|
662
|
+
that.sendPubDataOnce(ws, client.messageId, sub, type, collection);
|
|
663
|
+
}
|
|
664
|
+
});
|
|
721
665
|
}
|
|
722
666
|
}
|
|
723
|
-
else
|
|
667
|
+
else {
|
|
724
668
|
that._wss.clients.forEach(function (ws) {
|
|
725
669
|
if (ws['id_socket'] === client.id_socket) {
|
|
726
670
|
that.sendPubDataOnce(ws, client.messageId, sub, type, collection);
|
|
@@ -731,18 +675,16 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
731
675
|
}
|
|
732
676
|
else {
|
|
733
677
|
if (that._publications[sub.publication].fetchFunction) {
|
|
734
|
-
if (
|
|
735
|
-
|
|
736
|
-
that.sendPubData(sub, type, collection);
|
|
737
|
-
}
|
|
678
|
+
if ((_d = that._publications[sub.publication]).fetchFunction.apply(_d, [document].concat(sub.subscriptionData))) {
|
|
679
|
+
that.sendPubData(sub, type, collection);
|
|
738
680
|
}
|
|
739
681
|
}
|
|
740
|
-
else
|
|
682
|
+
else {
|
|
741
683
|
that.sendPubData(sub, type, collection);
|
|
742
684
|
}
|
|
743
685
|
}
|
|
744
|
-
_e.label =
|
|
745
|
-
case
|
|
686
|
+
_e.label = 5;
|
|
687
|
+
case 5: return [2 /*return*/];
|
|
746
688
|
}
|
|
747
689
|
});
|
|
748
690
|
}); });
|
|
@@ -843,6 +785,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
843
785
|
hasError: false,
|
|
844
786
|
data: res
|
|
845
787
|
};
|
|
788
|
+
console.log('Send Pub Data Once 1', new Date(), 'Success', subscription);
|
|
846
789
|
_this.sendWS(ws, serverRes);
|
|
847
790
|
}, function (err) {
|
|
848
791
|
var serverRes = {
|
|
@@ -850,6 +793,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
850
793
|
hasError: true,
|
|
851
794
|
data: err
|
|
852
795
|
};
|
|
796
|
+
console.log('Send Pub Data Once 1', new Date(), 'Error', subscription);
|
|
853
797
|
_this.sendWS(ws, serverRes);
|
|
854
798
|
});
|
|
855
799
|
}
|
|
@@ -860,6 +804,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
860
804
|
hasError: false,
|
|
861
805
|
data: res
|
|
862
806
|
};
|
|
807
|
+
console.log('Send Pub Data Once 2', new Date(), 'Success', subscription);
|
|
863
808
|
_this.sendWS(ws, serverRes);
|
|
864
809
|
}, function (err) {
|
|
865
810
|
var serverRes = {
|
|
@@ -867,6 +812,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
867
812
|
hasError: true,
|
|
868
813
|
data: err
|
|
869
814
|
};
|
|
815
|
+
console.log('Send Pub Data Once 2', new Date(), 'Error', subscription);
|
|
870
816
|
_this.sendWS(ws, serverRes);
|
|
871
817
|
});
|
|
872
818
|
}
|
package/package.json
CHANGED
package/server-app.js
CHANGED
|
@@ -279,11 +279,11 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
279
279
|
pub = data.shift();
|
|
280
280
|
// Subscribe
|
|
281
281
|
if (subType === 'sub') {
|
|
282
|
-
(_a = this._subscriptionManager).subscribe.apply(_a, [ws, messageId, pub].concat(data));
|
|
282
|
+
(_a = this._subscriptionManager).subscribe.apply(_a, [messageDate, ws, messageId, pub].concat(data));
|
|
283
283
|
}
|
|
284
284
|
// Unsubscribe
|
|
285
285
|
else {
|
|
286
|
-
(_b = this._subscriptionManager).unsubscribe.apply(_b, [ws, messageId, pub].concat(data));
|
|
286
|
+
(_b = this._subscriptionManager).unsubscribe.apply(_b, [messageDate, ws, messageId, pub].concat(data));
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
289
|
else {
|