@resolveio/server-lib 2.1.0 → 2.1.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.
|
@@ -17,8 +17,8 @@ export declare class SubscriptionManager {
|
|
|
17
17
|
unsubscribeAll(ws: WebSocket): Promise<void>;
|
|
18
18
|
private getPublicationCollections;
|
|
19
19
|
private tailOpLog;
|
|
20
|
-
private runOpLogQueue;
|
|
21
20
|
private tailOpLogSupport;
|
|
21
|
+
private runOpLogQueue;
|
|
22
22
|
private resendPubsForDelete;
|
|
23
23
|
private checkPubsForChanges;
|
|
24
24
|
private checkSupportPubsForChanges;
|
|
@@ -413,34 +413,6 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
413
413
|
console.log('oplog stopped');
|
|
414
414
|
});
|
|
415
415
|
};
|
|
416
|
-
SubscriptionManager.prototype.runOpLogQueue = function () {
|
|
417
|
-
var _this = this;
|
|
418
|
-
setInterval(function () {
|
|
419
|
-
var oplogQueue = common_1.deepCopy(_this._oplogQueue);
|
|
420
|
-
var uniqueCollectionOplogQueue = oplogQueue.map(function (a) { return a.collection; }).filter(function (elem, index, self) {
|
|
421
|
-
return index === self.indexOf(elem);
|
|
422
|
-
});
|
|
423
|
-
uniqueCollectionOplogQueue.forEach(function (collection) {
|
|
424
|
-
var oplogQueueFiltered = oplogQueue.filter(function (a) { return a.collection === collection; });
|
|
425
|
-
if (oplogQueueFiltered.length === 1) {
|
|
426
|
-
_this.checkPubsForChanges(oplogQueueFiltered[0].collection, oplogQueueFiltered[0].doc);
|
|
427
|
-
_this._oplogQueue.splice(_this._oplogQueue.map(function (a) { return a.collection; }).indexOf(collection), 1);
|
|
428
|
-
}
|
|
429
|
-
else {
|
|
430
|
-
oplogQueueFiltered.forEach(function (item) {
|
|
431
|
-
_this.checkPubsForChanges(item.collection, item.doc, true);
|
|
432
|
-
});
|
|
433
|
-
_this.checkPubsForChanges(oplogQueueFiltered[oplogQueueFiltered.length - 1].collection, oplogQueueFiltered[oplogQueueFiltered.length - 1].doc);
|
|
434
|
-
for (var i = _this._oplogQueue.length - 1; i >= 0; i--) {
|
|
435
|
-
var item = _this._oplogQueue[i];
|
|
436
|
-
if (item.collection === collection) {
|
|
437
|
-
_this._oplogQueue.splice(i, 1);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
});
|
|
442
|
-
}, 1000);
|
|
443
|
-
};
|
|
444
416
|
SubscriptionManager.prototype.tailOpLogSupport = function () {
|
|
445
417
|
var that = this;
|
|
446
418
|
var oplog = MongoOplog(that.serverConfig['RESOLVEIO_SUPPORT_OPLOG_URL']);
|
|
@@ -489,6 +461,34 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
489
461
|
console.log('oplog stopped support');
|
|
490
462
|
});
|
|
491
463
|
};
|
|
464
|
+
SubscriptionManager.prototype.runOpLogQueue = function () {
|
|
465
|
+
var _this = this;
|
|
466
|
+
setInterval(function () {
|
|
467
|
+
var oplogQueue = common_1.deepCopy(_this._oplogQueue);
|
|
468
|
+
var uniqueCollectionOplogQueue = oplogQueue.map(function (a) { return a.collection; }).filter(function (elem, index, self) {
|
|
469
|
+
return index === self.indexOf(elem);
|
|
470
|
+
});
|
|
471
|
+
uniqueCollectionOplogQueue.forEach(function (collection) {
|
|
472
|
+
var oplogQueueFiltered = oplogQueue.filter(function (a) { return a.collection === collection; });
|
|
473
|
+
if (oplogQueueFiltered.length === 1) {
|
|
474
|
+
_this.checkPubsForChanges(oplogQueueFiltered[0].collection, oplogQueueFiltered[0].doc);
|
|
475
|
+
_this._oplogQueue.splice(_this._oplogQueue.map(function (a) { return a.collection; }).indexOf(collection), 1);
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
oplogQueueFiltered.forEach(function (item) {
|
|
479
|
+
_this.checkPubsForChanges(item.collection, item.doc, true);
|
|
480
|
+
});
|
|
481
|
+
_this.checkPubsForChanges(oplogQueueFiltered[oplogQueueFiltered.length - 1].collection, oplogQueueFiltered[oplogQueueFiltered.length - 1].doc, false, true);
|
|
482
|
+
for (var i = _this._oplogQueue.length - 1; i >= 0; i--) {
|
|
483
|
+
var item = _this._oplogQueue[i];
|
|
484
|
+
if (item.collection === collection) {
|
|
485
|
+
_this._oplogQueue.splice(i, 1);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
}, 1000);
|
|
491
|
+
};
|
|
492
492
|
SubscriptionManager.prototype.resendPubsForDelete = function (collection) {
|
|
493
493
|
var that = this;
|
|
494
494
|
that._subscriptions.filter(function (a) { return a.collections.includes(collection); }).forEach(function (sub) {
|
|
@@ -509,9 +509,10 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
509
509
|
// Document: Inserted/Modified/Deleted Document
|
|
510
510
|
// Collection: Collection Document Lives In
|
|
511
511
|
// Check to see if any pubs need to refetch due to Mongo operation
|
|
512
|
-
SubscriptionManager.prototype.checkPubsForChanges = function (collection, document, fetchFunctionOnly) {
|
|
512
|
+
SubscriptionManager.prototype.checkPubsForChanges = function (collection, document, fetchFunctionOnly, noFetchFunction) {
|
|
513
513
|
var _this = this;
|
|
514
514
|
if (fetchFunctionOnly === void 0) { fetchFunctionOnly = false; }
|
|
515
|
+
if (noFetchFunction === void 0) { noFetchFunction = false; }
|
|
515
516
|
var that = this;
|
|
516
517
|
that._subscriptions.filter(function (a) { return a.collections.includes(collection); }).forEach(function (sub) { return __awaiter(_this, void 0, void 0, function () {
|
|
517
518
|
var _a, schemaErrors, _b;
|
|
@@ -531,7 +532,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
531
532
|
document = _c.sent();
|
|
532
533
|
_c.label = 2;
|
|
533
534
|
case 2:
|
|
534
|
-
if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 4];
|
|
535
|
+
if (!(that._publications[sub.publication].preFunction && !noFetchFunction)) return [3 /*break*/, 4];
|
|
535
536
|
_b = sub;
|
|
536
537
|
return [4 /*yield*/, that._publications[sub.publication].preFunction(sub.subscriptionData)];
|
|
537
538
|
case 3:
|
|
@@ -544,7 +545,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
544
545
|
if (that._publications[sub.publication].ws_specific) {
|
|
545
546
|
sub.clients.forEach(function (client) {
|
|
546
547
|
var _a;
|
|
547
|
-
if (that._publications[sub.publication].fetchFunction) {
|
|
548
|
+
if (that._publications[sub.publication].fetchFunction && !noFetchFunction) {
|
|
548
549
|
if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, [document, client.id_user].concat(sub.subscriptionData))) {
|
|
549
550
|
that._wss.clients.forEach(function (ws) {
|
|
550
551
|
if (ws['id_socket'] === client.id_socket) {
|
|
@@ -563,7 +564,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
563
564
|
});
|
|
564
565
|
}
|
|
565
566
|
else {
|
|
566
|
-
if (that._publications[sub.publication].fetchFunction) {
|
|
567
|
+
if (that._publications[sub.publication].fetchFunction && !noFetchFunction) {
|
|
567
568
|
if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, [document].concat(sub.subscriptionData))) {
|
|
568
569
|
that.sendPubData(sub);
|
|
569
570
|
}
|