@resolveio/server-lib 4.2.5-debug-1 → 4.2.5

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];
@@ -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(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>;
15
+ subscribe(ws: WebSocket, messageId: number, publication: string, ...subscriptionData: any[]): Promise<void>;
16
+ unsubscribe(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,14 +131,13 @@ var SubscriptionManager = /** @class */ (function () {
131
131
  });
132
132
  };
133
133
  // Subscribe to publication
134
- SubscriptionManager.prototype.subscribe = function (messageDate, ws, messageId, publication) {
134
+ SubscriptionManager.prototype.subscribe = function (ws, messageId, publication) {
135
135
  var subscriptionData = [];
136
- for (var _i = 4; _i < arguments.length; _i++) {
137
- subscriptionData[_i - 4] = arguments[_i];
136
+ for (var _i = 3; _i < arguments.length; _i++) {
137
+ subscriptionData[_i - 3] = 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:
@@ -200,14 +199,13 @@ var SubscriptionManager = /** @class */ (function () {
200
199
  if (!sub) {
201
200
  sub = that._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
202
201
  }
203
- console.log('Subscribe', new Date(), 'Success', sub);
204
202
  // Send pub data to client who just subscribed only, don't want to send to existing clients since nothing has changed
205
203
  that.sendPubDataOnce(ws, messageId, sub, 'newSub', that.getPublicationCollections(publication)[0]);
206
204
  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)];
205
+ _b = sub;
206
+ return [4 /*yield*/, (_a = that._publications[sub.publication]).preFunction.apply(_a, sub.subscriptionData)];
209
207
  case 2:
210
- _a.preSubscriptionData = _c.sent();
208
+ _b.preSubscriptionData = _c.sent();
211
209
  _c.label = 3;
212
210
  case 3:
213
211
  newActiveSub = new active_subscription_collection_1.ActiveSubscriptions({
@@ -272,10 +270,10 @@ var SubscriptionManager = /** @class */ (function () {
272
270
  });
273
271
  };
274
272
  // Unsubscribe from publication
275
- SubscriptionManager.prototype.unsubscribe = function (messageDate, ws, messageId, publication) {
273
+ SubscriptionManager.prototype.unsubscribe = function (ws, messageId, publication) {
276
274
  var subscriptionData = [];
277
- for (var _i = 4; _i < arguments.length; _i++) {
278
- subscriptionData[_i - 4] = arguments[_i];
275
+ for (var _i = 3; _i < arguments.length; _i++) {
276
+ subscriptionData[_i - 3] = arguments[_i];
279
277
  }
280
278
  return __awaiter(this, void 0, void 0, function () {
281
279
  var that, sub, i, activeSub;
@@ -552,50 +550,87 @@ var SubscriptionManager = /** @class */ (function () {
552
550
  oplogQueue_1.forEach(function (oplog) { return __awaiter(_this, void 0, void 0, function () {
553
551
  var _loop_3, i;
554
552
  return __generator(this, function (_a) {
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);
564
- }
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);
553
+ switch (_a.label) {
554
+ case 0:
555
+ _loop_3 = function (i) {
556
+ var _a, sub, _b;
557
+ return __generator(this, function (_c) {
558
+ switch (_c.label) {
559
+ case 0:
560
+ sub = that._subscriptions[i];
561
+ if (!sub.collections.includes(oplog.collection)) return [3 /*break*/, 3];
562
+ if (sub.preSubscriptionData) {
563
+ if (that._publications[sub.publication].fetchFunction(oplog.doc, sub.preSubscriptionData)) {
564
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0]) {
565
+ uniquePubs_1.push(sub);
566
+ uniqueOplog_1.push(oplog);
567
+ }
568
+ return [2 /*return*/, "continue"];
569
+ }
570
+ }
571
+ if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 2];
572
+ _b = sub;
573
+ return [4 /*yield*/, that._publications[sub.publication].preFunction(sub.subscriptionData)];
574
+ case 1:
575
+ _b.preSubscriptionData = _c.sent();
576
+ if (that._publications[sub.publication].fetchFunction(oplog.doc, sub.preSubscriptionData)) {
577
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)); })[0]) {
578
+ uniquePubs_1.push(sub);
579
+ uniqueOplog_1.push(oplog);
580
+ }
581
+ return [2 /*return*/, "continue"];
582
+ }
583
+ return [3 /*break*/, 3];
584
+ case 2:
585
+ if (that._publications[sub.publication].ws_specific) {
586
+ sub.clients.forEach(function (client) {
587
+ var _a;
588
+ if (that._publications[sub.publication].fetchFunction) {
589
+ if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, [oplog.doc, client.id_user].concat(sub.subscriptionData))) {
590
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0]) {
591
+ uniquePubs_1.push(sub);
592
+ uniqueOplog_1.push(oplog);
593
+ }
594
+ }
595
+ }
596
+ });
597
+ }
598
+ else {
599
+ if (that._publications[sub.publication].fetchFunction) {
600
+ if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, [oplog.doc].concat(sub.subscriptionData))) {
601
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)); })[0]) {
602
+ uniquePubs_1.push(sub);
603
+ uniqueOplog_1.push(oplog);
604
+ }
605
+ return [2 /*return*/, "continue"];
606
+ }
607
+ }
608
+ else {
609
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)); })[0]) {
610
+ uniquePubs_1.push(sub);
611
+ uniqueOplog_1.push(oplog);
612
+ }
613
+ return [2 /*return*/, "continue"];
614
+ }
615
+ }
616
+ _c.label = 3;
617
+ case 3: return [2 /*return*/];
589
618
  }
590
- return "continue";
591
- }
592
- }
593
- }
594
- };
595
- for (i = 0; i < that._subscriptions.length; i++) {
596
- _loop_3(i);
619
+ });
620
+ };
621
+ i = 0;
622
+ _a.label = 1;
623
+ case 1:
624
+ if (!(i < that._subscriptions.length)) return [3 /*break*/, 4];
625
+ return [5 /*yield**/, _loop_3(i)];
626
+ case 2:
627
+ _a.sent();
628
+ _a.label = 3;
629
+ case 3:
630
+ i++;
631
+ return [3 /*break*/, 1];
632
+ case 4: return [2 /*return*/];
597
633
  }
598
- return [2 /*return*/];
599
634
  });
600
635
  }); });
601
636
  uniqueOplog_1.forEach(function (oplog) {
@@ -628,25 +663,24 @@ var SubscriptionManager = /** @class */ (function () {
628
663
  var _this = this;
629
664
  var that = this;
630
665
  that._subscriptions.filter(function (a) { return a.collections.includes(collection); }).forEach(function (sub) { return __awaiter(_this, void 0, void 0, function () {
631
- var _a, _b;
632
- var _c, _d;
666
+ var _a, _b, _c, _d;
633
667
  return __generator(this, function (_e) {
634
668
  switch (_e.label) {
635
669
  case 0:
636
670
  if (!sub.preSubscriptionData) return [3 /*break*/, 2];
637
671
  if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 2];
638
672
  that.sendPubData(sub, type, collection);
639
- _a = sub;
640
- return [4 /*yield*/, (_c = that._publications[sub.publication]).preFunction.apply(_c, sub.subscriptionData)];
673
+ _c = sub;
674
+ return [4 /*yield*/, (_a = that._publications[sub.publication]).preFunction.apply(_a, sub.subscriptionData)];
641
675
  case 1:
642
- _a.preSubscriptionData = _e.sent();
676
+ _c.preSubscriptionData = _e.sent();
643
677
  _e.label = 2;
644
678
  case 2:
645
679
  if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 4];
646
- _b = sub;
680
+ _d = sub;
647
681
  return [4 /*yield*/, that._publications[sub.publication].preFunction(sub.subscriptionData)];
648
682
  case 3:
649
- _b.preSubscriptionData = _e.sent();
683
+ _d.preSubscriptionData = _e.sent();
650
684
  if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
651
685
  that.sendPubData(sub, type, collection);
652
686
  }
@@ -675,7 +709,7 @@ var SubscriptionManager = /** @class */ (function () {
675
709
  }
676
710
  else {
677
711
  if (that._publications[sub.publication].fetchFunction) {
678
- if ((_d = that._publications[sub.publication]).fetchFunction.apply(_d, [document].concat(sub.subscriptionData))) {
712
+ if ((_b = that._publications[sub.publication]).fetchFunction.apply(_b, [document].concat(sub.subscriptionData))) {
679
713
  that.sendPubData(sub, type, collection);
680
714
  }
681
715
  }
@@ -693,8 +727,7 @@ var SubscriptionManager = /** @class */ (function () {
693
727
  var _this = this;
694
728
  var that = this;
695
729
  that._subscriptions.filter(function (a) { return a.collections.includes(collection); }).forEach(function (sub) { return __awaiter(_this, void 0, void 0, function () {
696
- var schemaErrors, _a, _b;
697
- var _c, _d, _e;
730
+ var _a, _b, _c, schemaErrors, _d, _e;
698
731
  return __generator(this, function (_f) {
699
732
  switch (_f.label) {
700
733
  case 0:
@@ -714,17 +747,17 @@ var SubscriptionManager = /** @class */ (function () {
714
747
  if (!sub.preSubscriptionData) return [3 /*break*/, 4];
715
748
  if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 4];
716
749
  that.sendPubData(sub, 'support', collection);
717
- _a = sub;
718
- return [4 /*yield*/, (_c = that._publications[sub.publication]).preFunction.apply(_c, sub.subscriptionData)];
750
+ _d = sub;
751
+ return [4 /*yield*/, (_a = that._publications[sub.publication]).preFunction.apply(_a, sub.subscriptionData)];
719
752
  case 3:
720
- _a.preSubscriptionData = _f.sent();
753
+ _d.preSubscriptionData = _f.sent();
721
754
  return [2 /*return*/];
722
755
  case 4:
723
756
  if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 6];
724
- _b = sub;
725
- return [4 /*yield*/, (_d = that._publications[sub.publication]).preFunction.apply(_d, sub.subscriptionData)];
757
+ _e = sub;
758
+ return [4 /*yield*/, (_b = that._publications[sub.publication]).preFunction.apply(_b, sub.subscriptionData)];
726
759
  case 5:
727
- _b.preSubscriptionData = _f.sent();
760
+ _e.preSubscriptionData = _f.sent();
728
761
  if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
729
762
  that.sendPubData(sub, 'support', collection);
730
763
  }
@@ -753,7 +786,7 @@ var SubscriptionManager = /** @class */ (function () {
753
786
  }
754
787
  else {
755
788
  if (that._publications[sub.publication].fetchFunction) {
756
- if ((_e = that._publications[sub.publication]).fetchFunction.apply(_e, [document].concat(sub.subscriptionData))) {
789
+ if ((_c = that._publications[sub.publication]).fetchFunction.apply(_c, [document].concat(sub.subscriptionData))) {
757
790
  that.sendPubData(sub, 'support', collection);
758
791
  }
759
792
  }
@@ -770,8 +803,7 @@ var SubscriptionManager = /** @class */ (function () {
770
803
  // Fetch pub once, send to all clients linked to this pub
771
804
  SubscriptionManager.prototype.sendPubDataOnce = function (ws, messageId, subscription, type, collection) {
772
805
  return __awaiter(this, void 0, void 0, function () {
773
- var that;
774
- var _a, _b;
806
+ var _a, _b, that;
775
807
  var _this = this;
776
808
  return __generator(this, function (_c) {
777
809
  that = this;
@@ -785,7 +817,6 @@ var SubscriptionManager = /** @class */ (function () {
785
817
  hasError: false,
786
818
  data: res
787
819
  };
788
- console.log('Send Pub Data Once 1', new Date(), 'Success', subscription);
789
820
  _this.sendWS(ws, serverRes);
790
821
  }, function (err) {
791
822
  var serverRes = {
@@ -793,7 +824,6 @@ var SubscriptionManager = /** @class */ (function () {
793
824
  hasError: true,
794
825
  data: err
795
826
  };
796
- console.log('Send Pub Data Once 1', new Date(), 'Error', subscription);
797
827
  _this.sendWS(ws, serverRes);
798
828
  });
799
829
  }
@@ -804,7 +834,6 @@ var SubscriptionManager = /** @class */ (function () {
804
834
  hasError: false,
805
835
  data: res
806
836
  };
807
- console.log('Send Pub Data Once 2', new Date(), 'Success', subscription);
808
837
  _this.sendWS(ws, serverRes);
809
838
  }, function (err) {
810
839
  var serverRes = {
@@ -812,7 +841,6 @@ var SubscriptionManager = /** @class */ (function () {
812
841
  hasError: true,
813
842
  data: err
814
843
  };
815
- console.log('Send Pub Data Once 2', new Date(), 'Error', subscription);
816
844
  _this.sendWS(ws, serverRes);
817
845
  });
818
846
  }
@@ -823,8 +851,7 @@ var SubscriptionManager = /** @class */ (function () {
823
851
  // Fetch pub once, send to all clients linked to this pub
824
852
  SubscriptionManager.prototype.sendPubData = function (subscription, type, collection) {
825
853
  return __awaiter(this, void 0, void 0, function () {
826
- var that;
827
- var _a;
854
+ var _a, that;
828
855
  var _this = this;
829
856
  return __generator(this, function (_b) {
830
857
  that = this;
@@ -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.2.5-debug-1",
3
+ "version": "4.2.5",
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);
@@ -279,11 +278,11 @@ var ResolveIOMainServer = /** @class */ (function () {
279
278
  pub = data.shift();
280
279
  // Subscribe
281
280
  if (subType === 'sub') {
282
- (_a = this._subscriptionManager).subscribe.apply(_a, [messageDate, ws, messageId, pub].concat(data));
281
+ (_a = this._subscriptionManager).subscribe.apply(_a, [ws, messageId, pub].concat(data));
283
282
  }
284
283
  // Unsubscribe
285
284
  else {
286
- (_b = this._subscriptionManager).unsubscribe.apply(_b, [messageDate, ws, messageId, pub].concat(data));
285
+ (_b = this._subscriptionManager).unsubscribe.apply(_b, [ws, messageId, pub].concat(data));
287
286
  }
288
287
  }
289
288
  else {
@@ -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: