@resolveio/server-lib 4.3.7 → 4.3.8

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/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export declare class ResolveIOServer {
8
8
  private static _clientDir;
9
9
  private static _dontRunSupport;
10
10
  constructor(serverConfig: any, client: string, clientDir: any, _dontRunSupport?: any);
11
- static connectAndRun(): Promise<unknown>;
11
+ static connectAndRun(): Promise<{}>;
12
12
  static getClientName(): string;
13
13
  static getMainServer(): ResolveIOMainServer;
14
14
  static getMainDB(): any;
@@ -16,13 +16,13 @@ export declare class MethodManager {
16
16
  getMainServer(): ResolveIOMainServer;
17
17
  methods(method: MethodModel): void;
18
18
  callMethodCron(method: string, ...methodData: any[]): void;
19
- callMethodQueue(update: QueueMethodModel): Promise<unknown>;
19
+ callMethodQueue(update: QueueMethodModel): Promise<{}>;
20
20
  callMethod(id_methodLatency: string, ws: WebSocket, messageDate: Date, messageId: number, method: string, ...methodData: any[]): void;
21
21
  callMethodInternal(method: any, ...methodData: any[]): Promise<any>;
22
22
  callSupportMethodInternal(supportMethod: any, ...methodData: any[]): Promise<any>;
23
23
  private sendWS;
24
24
  sendEmail(sendTo: string, subject: string, text?: string, html?: string, attachments?: any[], send_from?: string): void;
25
25
  getAWS(): aws.S3;
26
- readFile(fileName: any): Promise<unknown>;
27
- readImage(fileName: any): Promise<unknown>;
26
+ readFile(fileName: any): Promise<{}>;
27
+ readImage(fileName: any): Promise<{}>;
28
28
  }
@@ -416,8 +416,8 @@ var MethodManager = /** @class */ (function () {
416
416
  };
417
417
  // Call/run method (Emit on Socket)
418
418
  MethodManager.prototype.callMethod = function (id_methodLatency, ws, messageDate, messageId, method) {
419
- var _a;
420
419
  var _this = this;
420
+ var _a;
421
421
  var methodData = [];
422
422
  for (var _i = 5; _i < arguments.length; _i++) {
423
423
  methodData[_i - 5] = arguments[_i];
@@ -137,8 +137,7 @@ var SubscriptionManager = /** @class */ (function () {
137
137
  subscriptionData[_i - 4] = arguments[_i];
138
138
  }
139
139
  return __awaiter(this, void 0, void 0, function () {
140
- var that, pub, valObj, valKeys, rootKeys, i, sub, _a, newActiveSub, begDate, endDate, billUser;
141
- var _b;
140
+ var _a, that, pub, valObj, valKeys, rootKeys, i, sub, _b, newActiveSub, begDate, endDate, billUser;
142
141
  return __generator(this, function (_c) {
143
142
  switch (_c.label) {
144
143
  case 0:
@@ -204,10 +203,10 @@ var SubscriptionManager = /** @class */ (function () {
204
203
  // Send pub data to client who just subscribed only, don't want to send to existing clients since nothing has changed
205
204
  that.sendPubDataOnce(ws, messageId, sub, 'newSub', that.getPublicationCollections(publication)[0]);
206
205
  if (!(that._publications[sub.publication].preFunction && !sub.preSubscriptionData)) return [3 /*break*/, 3];
207
- _a = sub;
208
- return [4 /*yield*/, (_b = that._publications[sub.publication]).preFunction.apply(_b, sub.subscriptionData)];
206
+ _b = sub;
207
+ return [4 /*yield*/, (_a = that._publications[sub.publication]).preFunction.apply(_a, sub.subscriptionData)];
209
208
  case 2:
210
- _a.preSubscriptionData = _c.sent();
209
+ _b.preSubscriptionData = _c.sent();
211
210
  _c.label = 3;
212
211
  case 3:
213
212
  newActiveSub = new active_subscription_collection_1.ActiveSubscriptions({
@@ -509,14 +508,15 @@ var SubscriptionManager = /** @class */ (function () {
509
508
  var _this = this;
510
509
  var that = this;
511
510
  setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
512
- var oplogQueue, uniqueOplog_1, needIds_1, _loop_3, i;
511
+ var oplogQueue, uniquePubs_1, uniqueOplog_1, needIds_1, _loop_3, i, i, oplog, _loop_4, i_1;
513
512
  var _this = this;
514
513
  return __generator(this, function (_a) {
515
514
  switch (_a.label) {
516
515
  case 0:
517
- if (!this._oplogQueue.length) return [3 /*break*/, 5];
516
+ if (!this._oplogQueue.length) return [3 /*break*/, 11];
518
517
  oplogQueue = common_1.deepCopy(this._oplogQueue);
519
518
  this._oplogQueue = [];
519
+ uniquePubs_1 = [];
520
520
  uniqueOplog_1 = [];
521
521
  needIds_1 = {};
522
522
  oplogQueue.forEach(function (oplog) {
@@ -576,11 +576,107 @@ var SubscriptionManager = /** @class */ (function () {
576
576
  i++;
577
577
  return [3 /*break*/, 1];
578
578
  case 4:
579
+ i = uniqueOplog_1.length - 1;
580
+ _a.label = 5;
581
+ case 5:
582
+ if (!(i >= 0)) return [3 /*break*/, 10];
583
+ oplog = uniqueOplog_1[i];
584
+ _loop_4 = function (i_1) {
585
+ var _a, sub, _b;
586
+ return __generator(this, function (_c) {
587
+ switch (_c.label) {
588
+ case 0:
589
+ sub = that._subscriptions[i_1];
590
+ if (!sub.collections.includes(oplog.collection)) return [3 /*break*/, 3];
591
+ if (sub.preSubscriptionData) {
592
+ if (that._publications[sub.publication].fetchFunction(oplog.doc, sub.preSubscriptionData)) {
593
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)[0]; })) {
594
+ uniquePubs_1.push(sub);
595
+ }
596
+ else {
597
+ uniqueOplog_1.splice(i_1, 1);
598
+ }
599
+ return [2 /*return*/, "continue"];
600
+ }
601
+ }
602
+ if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 2];
603
+ _b = sub;
604
+ return [4 /*yield*/, that._publications[sub.publication].preFunction(sub.subscriptionData)];
605
+ case 1:
606
+ _b.preSubscriptionData = _c.sent();
607
+ if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
608
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData))[0]; })) {
609
+ uniquePubs_1.push(sub);
610
+ }
611
+ else {
612
+ uniqueOplog_1.splice(i_1, 1);
613
+ }
614
+ return [2 /*return*/, "continue"];
615
+ }
616
+ return [3 /*break*/, 3];
617
+ case 2:
618
+ if (that._publications[sub.publication].ws_specific) {
619
+ sub.clients.forEach(function (client) {
620
+ var _a;
621
+ if (that._publications[sub.publication].fetchFunction) {
622
+ if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, [document, client.id_user].concat(sub.subscriptionData))) {
623
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0]) {
624
+ uniquePubs_1.push(sub);
625
+ }
626
+ else {
627
+ uniqueOplog_1.splice(i_1, 1);
628
+ }
629
+ }
630
+ }
631
+ });
632
+ }
633
+ else {
634
+ if (that._publications[sub.publication].fetchFunction) {
635
+ if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, [document].concat(sub.subscriptionData))) {
636
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData))[0]; })) {
637
+ uniquePubs_1.push(sub);
638
+ }
639
+ else {
640
+ uniqueOplog_1.splice(i_1, 1);
641
+ }
642
+ return [2 /*return*/, "continue"];
643
+ }
644
+ }
645
+ else {
646
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData))[0]; })) {
647
+ uniquePubs_1.push(sub);
648
+ }
649
+ else {
650
+ uniqueOplog_1.splice(i_1, 1);
651
+ }
652
+ return [2 /*return*/, "continue"];
653
+ }
654
+ }
655
+ _c.label = 3;
656
+ case 3: return [2 /*return*/];
657
+ }
658
+ });
659
+ };
660
+ i_1 = 0;
661
+ _a.label = 6;
662
+ case 6:
663
+ if (!(i_1 < that._subscriptions.length)) return [3 /*break*/, 9];
664
+ return [5 /*yield**/, _loop_4(i_1)];
665
+ case 7:
666
+ _a.sent();
667
+ _a.label = 8;
668
+ case 8:
669
+ i_1++;
670
+ return [3 /*break*/, 6];
671
+ case 9:
672
+ i--;
673
+ return [3 /*break*/, 5];
674
+ case 10:
579
675
  uniqueOplog_1.forEach(function (oplog) {
580
676
  _this.checkPubsForChanges(oplog.collection, oplog.doc, oplog.type);
581
677
  });
582
- _a.label = 5;
583
- case 5: return [2 /*return*/];
678
+ _a.label = 11;
679
+ case 11: return [2 /*return*/];
584
680
  }
585
681
  });
586
682
  }); }, 500);
@@ -607,14 +703,13 @@ var SubscriptionManager = /** @class */ (function () {
607
703
  // Check to see if any pubs need to refetch due to Mongo operation
608
704
  SubscriptionManager.prototype.checkPubsForChanges = function (collection, document, type) {
609
705
  return __awaiter(this, void 0, void 0, function () {
610
- var that, _loop_4, i;
706
+ var that, _loop_5, i;
611
707
  return __generator(this, function (_a) {
612
708
  switch (_a.label) {
613
709
  case 0:
614
710
  that = this;
615
- _loop_4 = function (i) {
616
- var sub, _a, _b;
617
- var _c, _d;
711
+ _loop_5 = function (i) {
712
+ var _a, _b, sub, _c, _d;
618
713
  return __generator(this, function (_e) {
619
714
  switch (_e.label) {
620
715
  case 0:
@@ -622,17 +717,17 @@ var SubscriptionManager = /** @class */ (function () {
622
717
  if (!sub.preSubscriptionData) return [3 /*break*/, 2];
623
718
  if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 2];
624
719
  that.sendPubData(sub, type, collection);
625
- _a = sub;
626
- return [4 /*yield*/, (_c = that._publications[sub.publication]).preFunction.apply(_c, sub.subscriptionData)];
720
+ _c = sub;
721
+ return [4 /*yield*/, (_a = that._publications[sub.publication]).preFunction.apply(_a, sub.subscriptionData)];
627
722
  case 1:
628
- _a.preSubscriptionData = _e.sent();
723
+ _c.preSubscriptionData = _e.sent();
629
724
  return [2 /*return*/, "continue"];
630
725
  case 2:
631
726
  if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 4];
632
- _b = sub;
727
+ _d = sub;
633
728
  return [4 /*yield*/, that._publications[sub.publication].preFunction(sub.subscriptionData)];
634
729
  case 3:
635
- _b.preSubscriptionData = _e.sent();
730
+ _d.preSubscriptionData = _e.sent();
636
731
  if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
637
732
  that.sendPubData(sub, type, collection);
638
733
  }
@@ -661,7 +756,7 @@ var SubscriptionManager = /** @class */ (function () {
661
756
  }
662
757
  else {
663
758
  if (that._publications[sub.publication].fetchFunction) {
664
- if ((_d = that._publications[sub.publication]).fetchFunction.apply(_d, [document].concat(sub.subscriptionData))) {
759
+ if ((_b = that._publications[sub.publication]).fetchFunction.apply(_b, [document].concat(sub.subscriptionData))) {
665
760
  that.sendPubData(sub, type, collection);
666
761
  }
667
762
  // else
@@ -679,7 +774,7 @@ var SubscriptionManager = /** @class */ (function () {
679
774
  _a.label = 1;
680
775
  case 1:
681
776
  if (!(i < that._subscriptions.filter(function (a) { return a.collections.includes(collection); }).length)) return [3 /*break*/, 4];
682
- return [5 /*yield**/, _loop_4(i)];
777
+ return [5 /*yield**/, _loop_5(i)];
683
778
  case 2:
684
779
  _a.sent();
685
780
  _a.label = 3;
@@ -695,8 +790,7 @@ var SubscriptionManager = /** @class */ (function () {
695
790
  var _this = this;
696
791
  var that = this;
697
792
  that._subscriptions.filter(function (a) { return a.collections.includes(collection); }).forEach(function (sub) { return __awaiter(_this, void 0, void 0, function () {
698
- var schemaErrors, _a, _b;
699
- var _c, _d, _e;
793
+ var _a, _b, _c, schemaErrors, _d, _e;
700
794
  return __generator(this, function (_f) {
701
795
  switch (_f.label) {
702
796
  case 0:
@@ -716,17 +810,17 @@ var SubscriptionManager = /** @class */ (function () {
716
810
  if (!sub.preSubscriptionData) return [3 /*break*/, 4];
717
811
  if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 4];
718
812
  that.sendPubData(sub, 'support', collection);
719
- _a = sub;
720
- return [4 /*yield*/, (_c = that._publications[sub.publication]).preFunction.apply(_c, sub.subscriptionData)];
813
+ _d = sub;
814
+ return [4 /*yield*/, (_a = that._publications[sub.publication]).preFunction.apply(_a, sub.subscriptionData)];
721
815
  case 3:
722
- _a.preSubscriptionData = _f.sent();
816
+ _d.preSubscriptionData = _f.sent();
723
817
  return [2 /*return*/];
724
818
  case 4:
725
819
  if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 6];
726
- _b = sub;
727
- return [4 /*yield*/, (_d = that._publications[sub.publication]).preFunction.apply(_d, sub.subscriptionData)];
820
+ _e = sub;
821
+ return [4 /*yield*/, (_b = that._publications[sub.publication]).preFunction.apply(_b, sub.subscriptionData)];
728
822
  case 5:
729
- _b.preSubscriptionData = _f.sent();
823
+ _e.preSubscriptionData = _f.sent();
730
824
  if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
731
825
  that.sendPubData(sub, 'support', collection);
732
826
  }
@@ -755,7 +849,7 @@ var SubscriptionManager = /** @class */ (function () {
755
849
  }
756
850
  else {
757
851
  if (that._publications[sub.publication].fetchFunction) {
758
- if ((_e = that._publications[sub.publication]).fetchFunction.apply(_e, [document].concat(sub.subscriptionData))) {
852
+ if ((_c = that._publications[sub.publication]).fetchFunction.apply(_c, [document].concat(sub.subscriptionData))) {
759
853
  that.sendPubData(sub, 'support', collection);
760
854
  }
761
855
  }
@@ -772,12 +866,11 @@ var SubscriptionManager = /** @class */ (function () {
772
866
  // Fetch pub once, send to all clients linked to this pub
773
867
  SubscriptionManager.prototype.sendPubDataOnce = function (ws, messageId, subscription, type, collection) {
774
868
  return __awaiter(this, void 0, void 0, function () {
775
- var that;
776
- var _a, _b;
869
+ var _a, _b, that;
777
870
  var _this = this;
778
871
  return __generator(this, function (_c) {
779
872
  that = this;
780
- if (subscription.publication !== 'superadminAPM') {
873
+ if (subscription.publication !== 'superadminAPM' && subscription.publication !== 'loggedInUsers') {
781
874
  that._mainServer.getMethodManager().callMethodInternal('insertSubscriptionLog', type, subscription.publication, collection, subscription.subscriptionData);
782
875
  }
783
876
  if (!that._publications[subscription.publication].ws_specific) { // Same pub for all users
@@ -825,12 +918,11 @@ var SubscriptionManager = /** @class */ (function () {
825
918
  // Fetch pub once, send to all clients linked to this pub
826
919
  SubscriptionManager.prototype.sendPubData = function (subscription, type, collection) {
827
920
  return __awaiter(this, void 0, void 0, function () {
828
- var that;
829
- var _a;
921
+ var _a, that;
830
922
  var _this = this;
831
923
  return __generator(this, function (_b) {
832
924
  that = this;
833
- if (subscription.publication !== 'superadminAPM') {
925
+ if (subscription.publication !== 'superadminAPM' && subscription.publication !== 'loggedInUsers') {
834
926
  that._mainServer.getMethodManager().callMethodInternal('insertSubscriptionLog', type, subscription.publication, collection, subscription.subscriptionData);
835
927
  }
836
928
  (_a = that._publications[subscription.publication].function).call.apply(_a, [Object.assign({}, that, SubscriptionManager.prototype)].concat(subscription.subscriptionData)).then(function (res) {
@@ -17,6 +17,6 @@ export declare class SupportManager {
17
17
  callMethodInternal(method: any, ...methodData: any[]): Promise<any>;
18
18
  private sendWS;
19
19
  sendEmail(sendTo: string, subject: string, text?: string, html?: string, attachments?: any[], from?: string): void;
20
- readFile(fileName: any): Promise<unknown>;
21
- readImage(fileName: any): Promise<unknown>;
20
+ readFile(fileName: any): Promise<{}>;
21
+ readImage(fileName: any): Promise<{}>;
22
22
  }
@@ -102,8 +102,8 @@ var SupportManager = /** @class */ (function () {
102
102
  };
103
103
  // Call/run method (Emit on Socket)
104
104
  SupportManager.prototype.callSupportMethod = function (ws, messageId, supportMethod) {
105
- var _a;
106
105
  var _this = this;
106
+ var _a;
107
107
  var methodData = [];
108
108
  for (var _i = 3; _i < arguments.length; _i++) {
109
109
  methodData[_i - 3] = arguments[_i];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "4.3.7",
3
+ "version": "4.3.8",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {
package/server-app.js CHANGED
@@ -254,8 +254,7 @@ var ResolveIOMainServer = /** @class */ (function () {
254
254
  }, 10000);
255
255
  // On data received (message)
256
256
  ws.on('message', function (message) { return __awaiter(_this, void 0, void 0, function () {
257
- var socketData, data, messageDate, messageId, type, subType, pub;
258
- var _a, _b;
257
+ var _a, _b, socketData, data, messageDate, messageId, type, subType, pub;
259
258
  var _this = this;
260
259
  return __generator(this, function (_c) {
261
260
  socketData = JSON.parse(message, common_1.dateReviver);
@@ -330,8 +329,7 @@ var ResolveIOMainServer = /** @class */ (function () {
330
329
  if (!!this._msgQueueRunning) return [3 /*break*/, 5];
331
330
  this._msgQueueRunning = true;
332
331
  _loop_1 = function (i) {
333
- var msg, data, ws, messageDate, messageId, type, method, methodLatency, serverRes, query, methodCall, supportMethod, serverRes;
334
- var _a, _b;
332
+ var _a, _b, msg, data, ws, messageDate, messageId, type, method, methodLatency, serverRes, query, methodCall, supportMethod, serverRes;
335
333
  return __generator(this, function (_c) {
336
334
  switch (_c.label) {
337
335
  case 0: