@resolveio/server-lib 5.2.18 → 5.2.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.
@@ -189,11 +189,16 @@ var SubscriptionManager = /** @class */ (function () {
189
189
  sub = that._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
190
190
  // If sub found (another user watching same data), add client to same sub
191
191
  if (sub) {
192
- sub.clients.push({
193
- id_user: ws['id_user'],
194
- messageId: messageId,
195
- id_socket: ws['id_socket']
196
- });
192
+ if (!sub.clients.some(function (a) { return a.id_user === ws['id_user'] && a.id_socket === ws['id_socket']; })) {
193
+ sub.clients.push({
194
+ id_user: ws['id_user'],
195
+ messageId: messageId,
196
+ id_socket: ws['id_socket']
197
+ });
198
+ }
199
+ else {
200
+ this._mainServer.getMethodManager().callMethodInternal('sendEmail', 'dev@resolveio.com', 'SERVER - Subscription Error Detected (Same socket and user) - ' + that.serverConfig['CLIENT_NAME'], 'Pub: ' + sub.publication + ', id_user: ' + ws['id_user']);
201
+ }
197
202
  }
198
203
  // If sub not found, create new sub
199
204
  else {
@@ -510,12 +515,12 @@ var SubscriptionManager = /** @class */ (function () {
510
515
  var _this = this;
511
516
  var that = this;
512
517
  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, this_1, j;
518
+ var uniqueOplog_1, uniquePubs, needIds_1, _loop_2, i, _loop_3, i, i, oplog, _loop_4, this_1, j, i, pub;
514
519
  var _this = this;
515
520
  return __generator(this, function (_a) {
516
521
  switch (_a.label) {
517
522
  case 0:
518
- if (!this._oplogQueue.length) return [3 /*break*/, 11];
523
+ if (!this._oplogQueue.length) return [3 /*break*/, 14];
519
524
  uniqueOplog_1 = common_1.deepCopy(this._oplogQueue);
520
525
  this._oplogQueue = [];
521
526
  uniquePubs = [];
@@ -563,7 +568,7 @@ var SubscriptionManager = /** @class */ (function () {
563
568
  });
564
569
  }
565
570
  else {
566
- console.log('PROBLEMAAAAAAAA');
571
+ _this._mainServer.getMethodManager().callMethodInternal('sendEmail', 'dev@resolveio.com', 'SERVER - Oplog Doc Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'id_doc: ' + id_doc + ', UniqueOplogs: ' + JSON.stringify(uniqueOplog_1, null, 2));
567
572
  }
568
573
  });
569
574
  return [2 /*return*/];
@@ -708,11 +713,19 @@ var SubscriptionManager = /** @class */ (function () {
708
713
  i--;
709
714
  return [3 /*break*/, 5];
710
715
  case 10:
711
- uniquePubs.forEach(function (pub) {
712
- _this.checkPubsForChanges(pub['oplog'].collection, pub['oplog'].doc, pub['oplog'].type, pub);
713
- });
716
+ i = 0;
714
717
  _a.label = 11;
715
- case 11: return [2 /*return*/];
718
+ case 11:
719
+ if (!(i < uniquePubs.length)) return [3 /*break*/, 14];
720
+ pub = uniquePubs[i];
721
+ return [4 /*yield*/, this.checkPubsForChanges(pub['oplog'].collection, pub['oplog'].doc, pub['oplog'].type, pub)];
722
+ case 12:
723
+ _a.sent();
724
+ _a.label = 13;
725
+ case 13:
726
+ i++;
727
+ return [3 /*break*/, 11];
728
+ case 14: return [2 /*return*/];
716
729
  }
717
730
  });
718
731
  }); }, 500);
@@ -792,34 +805,31 @@ var SubscriptionManager = /** @class */ (function () {
792
805
  });
793
806
  });
794
807
  };
795
- // Document: Inserted/Modified/Deleted Document
808
+ // Document: Inserted/Modified Document
796
809
  // Collection: Collection Document Lives In
797
810
  // Check to see if any pubs need to refetch due to Mongo operation
798
811
  SubscriptionManager.prototype.checkPubsForChanges = function (collection, document, type, sub) {
799
812
  return __awaiter(this, void 0, void 0, function () {
800
- var _a, _b, that, _c, _d;
801
- return __generator(this, function (_e) {
802
- switch (_e.label) {
813
+ var _a, that, _b;
814
+ return __generator(this, function (_c) {
815
+ switch (_c.label) {
803
816
  case 0:
804
817
  that = this;
805
- if (!sub.preSubscriptionData) return [3 /*break*/, 2];
806
- if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 2];
807
- if (this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
808
- this._nodeCache.del(this._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
809
- this._subCache.splice(this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
818
+ if (sub.preSubscriptionData) {
819
+ if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
820
+ if (this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
821
+ this._nodeCache.del(this._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
822
+ this._subCache.splice(this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
823
+ }
824
+ that.sendPubData(sub, type, collection);
825
+ return [2 /*return*/];
826
+ }
810
827
  }
811
- that.sendPubData(sub, type, collection);
812
- _c = sub;
813
- return [4 /*yield*/, (_a = that._publications[sub.publication]).preFunction.apply(_a, sub.subscriptionData)];
814
- case 1:
815
- _c.preSubscriptionData = _e.sent();
816
- return [2 /*return*/];
817
- case 2:
818
- if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 4];
819
- _d = sub;
828
+ if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 2];
829
+ _b = sub;
820
830
  return [4 /*yield*/, that._publications[sub.publication].preFunction(sub.subscriptionData)];
821
- case 3:
822
- _d.preSubscriptionData = _e.sent();
831
+ case 1:
832
+ _b.preSubscriptionData = _c.sent();
823
833
  if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
824
834
  if (this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
825
835
  this._nodeCache.del(this._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
@@ -827,8 +837,8 @@ var SubscriptionManager = /** @class */ (function () {
827
837
  }
828
838
  that.sendPubData(sub, type, collection);
829
839
  }
830
- return [3 /*break*/, 5];
831
- case 4:
840
+ return [3 /*break*/, 3];
841
+ case 2:
832
842
  if (that._publications[sub.publication].ws_specific) {
833
843
  sub.clients.forEach(function (client) {
834
844
  var _a;
@@ -852,7 +862,7 @@ var SubscriptionManager = /** @class */ (function () {
852
862
  }
853
863
  else {
854
864
  if (that._publications[sub.publication].fetchFunction) {
855
- if ((_b = that._publications[sub.publication]).fetchFunction.apply(_b, [document].concat(sub.subscriptionData))) {
865
+ if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, [document].concat(sub.subscriptionData))) {
856
866
  if (this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
857
867
  this._nodeCache.del(this._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
858
868
  this._subCache.splice(this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
@@ -869,8 +879,8 @@ var SubscriptionManager = /** @class */ (function () {
869
879
  that.sendPubData(sub, type, collection);
870
880
  }
871
881
  }
872
- _e.label = 5;
873
- case 5: return [2 /*return*/];
882
+ _c.label = 3;
883
+ case 3: return [2 /*return*/];
874
884
  }
875
885
  });
876
886
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "5.2.18",
3
+ "version": "5.2.20",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {