@resolveio/server-lib 4.3.2 → 4.3.3

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<{}>;
11
+ static connectAndRun(): Promise<unknown>;
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<{}>;
19
+ callMethodQueue(update: QueueMethodModel): Promise<unknown>;
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<{}>;
27
- readImage(fileName: any): Promise<{}>;
26
+ readFile(fileName: any): Promise<unknown>;
27
+ readImage(fileName: any): Promise<unknown>;
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 _this = this;
420
419
  var _a;
420
+ var _this = this;
421
421
  var methodData = [];
422
422
  for (var _i = 5; _i < arguments.length; _i++) {
423
423
  methodData[_i - 5] = arguments[_i];
@@ -137,7 +137,8 @@ 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 _a, that, pub, valObj, valKeys, rootKeys, i, sub, _b, newActiveSub, begDate, endDate, billUser;
140
+ var that, pub, valObj, valKeys, rootKeys, i, sub, _a, newActiveSub, begDate, endDate, billUser;
141
+ var _b;
141
142
  return __generator(this, function (_c) {
142
143
  switch (_c.label) {
143
144
  case 0:
@@ -203,10 +204,10 @@ var SubscriptionManager = /** @class */ (function () {
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];
206
- _b = sub;
207
- return [4 /*yield*/, (_a = that._publications[sub.publication]).preFunction.apply(_a, sub.subscriptionData)];
207
+ _a = sub;
208
+ return [4 /*yield*/, (_b = that._publications[sub.publication]).preFunction.apply(_b, sub.subscriptionData)];
208
209
  case 2:
209
- _b.preSubscriptionData = _c.sent();
210
+ _a.preSubscriptionData = _c.sent();
210
211
  _c.label = 3;
211
212
  case 3:
212
213
  newActiveSub = new active_subscription_collection_1.ActiveSubscriptions({
@@ -504,38 +505,37 @@ var SubscriptionManager = /** @class */ (function () {
504
505
  var _this = this;
505
506
  var that = this;
506
507
  setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
507
- var oplogQueue_1, uniquePubs_1, uniqueOplog_1, needIds_1, _loop_3, i;
508
+ var oplogQueue, uniqueOplog_1, needIds_1, _loop_3, i;
508
509
  var _this = this;
509
510
  return __generator(this, function (_a) {
510
511
  switch (_a.label) {
511
512
  case 0:
512
513
  if (!this._oplogQueue.length) return [3 /*break*/, 5];
513
- oplogQueue_1 = common_1.deepCopy(this._oplogQueue);
514
+ oplogQueue = common_1.deepCopy(this._oplogQueue);
514
515
  this._oplogQueue = [];
515
- uniquePubs_1 = [];
516
516
  uniqueOplog_1 = [];
517
517
  needIds_1 = {};
518
- // console.log('----------------OPLOG QUEUE START BEFORE DATA--------------------', new Date(), oplogQueue.length);
519
- oplogQueue_1.forEach(function (oplog) {
520
- for (var i = 0; i < that._subscriptions.length; i++) {
521
- var sub = that._subscriptions[i];
522
- if (sub.collections.includes(oplog.collection)) {
523
- var schemaErrors = null;
524
- try {
525
- index_1.ResolveIOServer.getMainDB().model(oplog.collection)['simplschema'].validate(oplog.doc);
526
- }
527
- catch (errors) {
528
- schemaErrors = errors;
529
- }
530
- if (schemaErrors) {
531
- if (!needIds_1[oplog.collection]) {
532
- needIds_1[oplog.collection] = [oplog.doc['_id']];
533
- }
534
- else {
535
- if (!needIds_1[oplog.collection].filter(function (a) { return a === oplog.doc['_id']; })[0]) {
536
- needIds_1[oplog.collection].push(oplog.doc['_id']);
537
- }
538
- }
518
+ console.log('----------------OPLOG QUEUE START BEFORE DATA--------------------', new Date(), oplogQueue.length);
519
+ oplogQueue.forEach(function (oplog) {
520
+ if (!uniqueOplog_1.filter(function (a) { return JSON.stringify(a) === JSON.stringify(oplog); }).length) {
521
+ uniqueOplog_1.push(oplog);
522
+ }
523
+ });
524
+ uniqueOplog_1.forEach(function (oplog) {
525
+ var schemaErrors = null;
526
+ try {
527
+ index_1.ResolveIOServer.getMainDB().model(oplog.collection)['simplschema'].validate(oplog.doc);
528
+ }
529
+ catch (errors) {
530
+ schemaErrors = errors;
531
+ }
532
+ if (schemaErrors) {
533
+ if (!needIds_1[oplog.collection]) {
534
+ needIds_1[oplog.collection] = [oplog.doc['_id']];
535
+ }
536
+ else {
537
+ if (!needIds_1[oplog.collection].filter(function (a) { return a === oplog.doc['_id']; })[0]) {
538
+ needIds_1[oplog.collection].push(oplog.doc['_id']);
539
539
  }
540
540
  }
541
541
  }
@@ -550,7 +550,7 @@ var SubscriptionManager = /** @class */ (function () {
550
550
  case 1:
551
551
  docs = _a.sent();
552
552
  needIds_1[collection].forEach(function (id_doc) {
553
- oplogQueue_1.filter(function (a) { return a.doc._id === id_doc; })[0].doc = docs.filter(function (a) { return a._id === id_doc; })[0];
553
+ uniqueOplog_1.filter(function (a) { return a.doc._id === id_doc; })[0].doc = docs.filter(function (a) { return a._id === id_doc; })[0];
554
554
  });
555
555
  return [2 /*return*/];
556
556
  }
@@ -568,58 +568,7 @@ var SubscriptionManager = /** @class */ (function () {
568
568
  i++;
569
569
  return [3 /*break*/, 1];
570
570
  case 4:
571
- // console.log('----------------OPLOG QUEUE START AFTER DATA--------------------', new Date(), oplogQueue.length);
572
- oplogQueue_1.forEach(function (oplog) { return __awaiter(_this, void 0, void 0, function () {
573
- var _loop_4, i;
574
- return __generator(this, function (_a) {
575
- _loop_4 = function (i) {
576
- var _a;
577
- var sub = that._subscriptions[i];
578
- if (sub.collections.includes(oplog.collection)) {
579
- if (sub.preSubscriptionData) {
580
- if (that._publications[sub.publication].fetchFunction(oplog.doc, sub.preSubscriptionData)) {
581
- if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)); })[0]) {
582
- uniquePubs_1.push(sub);
583
- uniqueOplog_1.push(oplog);
584
- }
585
- return "continue";
586
- }
587
- }
588
- if (that._publications[sub.publication].preFunction) {
589
- if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)); })[0]) {
590
- uniquePubs_1.push(sub);
591
- uniqueOplog_1.push(oplog);
592
- }
593
- return "continue";
594
- }
595
- else {
596
- if (that._publications[sub.publication].fetchFunction) {
597
- if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, [oplog.doc].concat(sub.subscriptionData))) {
598
- if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)); })[0]) {
599
- uniquePubs_1.push(sub);
600
- uniqueOplog_1.push(oplog);
601
- }
602
- return "continue";
603
- }
604
- }
605
- else {
606
- if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)); })[0]) {
607
- uniquePubs_1.push(sub);
608
- uniqueOplog_1.push(oplog);
609
- }
610
- return "continue";
611
- }
612
- }
613
- }
614
- };
615
- // console.log('OPLOG QUEUE START - Oplog', oplog);
616
- for (i = 0; i < that._subscriptions.length; i++) {
617
- _loop_4(i);
618
- }
619
- return [2 /*return*/];
620
- });
621
- }); });
622
- // // console.log('----------------OPLOG QUEUE END--------------------', new Date(), uniqueOplog.length);
571
+ console.log('----------------OPLOG QUEUE END--------------------', new Date(), uniqueOplog_1.length);
623
572
  uniqueOplog_1.forEach(function (oplog) {
624
573
  // console.log('OPLOG QUEUE END - Oplog', oplog);
625
574
  _this.checkPubsForChanges(oplog.collection, oplog.doc, oplog.type);
@@ -654,24 +603,25 @@ var SubscriptionManager = /** @class */ (function () {
654
603
  var _this = this;
655
604
  var that = this;
656
605
  that._subscriptions.filter(function (a) { return a.collections.includes(collection); }).forEach(function (sub) { return __awaiter(_this, void 0, void 0, function () {
657
- var _a, _b, _c, _d;
606
+ var _a, _b;
607
+ var _c, _d;
658
608
  return __generator(this, function (_e) {
659
609
  switch (_e.label) {
660
610
  case 0:
661
611
  if (!sub.preSubscriptionData) return [3 /*break*/, 2];
662
612
  if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 2];
663
613
  that.sendPubData(sub, type, collection);
664
- _c = sub;
665
- return [4 /*yield*/, (_a = that._publications[sub.publication]).preFunction.apply(_a, sub.subscriptionData)];
614
+ _a = sub;
615
+ return [4 /*yield*/, (_c = that._publications[sub.publication]).preFunction.apply(_c, sub.subscriptionData)];
666
616
  case 1:
667
- _c.preSubscriptionData = _e.sent();
617
+ _a.preSubscriptionData = _e.sent();
668
618
  _e.label = 2;
669
619
  case 2:
670
620
  if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 4];
671
- _d = sub;
621
+ _b = sub;
672
622
  return [4 /*yield*/, that._publications[sub.publication].preFunction(sub.subscriptionData)];
673
623
  case 3:
674
- _d.preSubscriptionData = _e.sent();
624
+ _b.preSubscriptionData = _e.sent();
675
625
  if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
676
626
  that.sendPubData(sub, type, collection);
677
627
  }
@@ -700,7 +650,7 @@ var SubscriptionManager = /** @class */ (function () {
700
650
  }
701
651
  else {
702
652
  if (that._publications[sub.publication].fetchFunction) {
703
- if ((_b = that._publications[sub.publication]).fetchFunction.apply(_b, [document].concat(sub.subscriptionData))) {
653
+ if ((_d = that._publications[sub.publication]).fetchFunction.apply(_d, [document].concat(sub.subscriptionData))) {
704
654
  that.sendPubData(sub, type, collection);
705
655
  }
706
656
  // else
@@ -719,7 +669,8 @@ var SubscriptionManager = /** @class */ (function () {
719
669
  var _this = this;
720
670
  var that = this;
721
671
  that._subscriptions.filter(function (a) { return a.collections.includes(collection); }).forEach(function (sub) { return __awaiter(_this, void 0, void 0, function () {
722
- var _a, _b, _c, schemaErrors, _d, _e;
672
+ var schemaErrors, _a, _b;
673
+ var _c, _d, _e;
723
674
  return __generator(this, function (_f) {
724
675
  switch (_f.label) {
725
676
  case 0:
@@ -739,17 +690,17 @@ var SubscriptionManager = /** @class */ (function () {
739
690
  if (!sub.preSubscriptionData) return [3 /*break*/, 4];
740
691
  if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 4];
741
692
  that.sendPubData(sub, 'support', collection);
742
- _d = sub;
743
- return [4 /*yield*/, (_a = that._publications[sub.publication]).preFunction.apply(_a, sub.subscriptionData)];
693
+ _a = sub;
694
+ return [4 /*yield*/, (_c = that._publications[sub.publication]).preFunction.apply(_c, sub.subscriptionData)];
744
695
  case 3:
745
- _d.preSubscriptionData = _f.sent();
696
+ _a.preSubscriptionData = _f.sent();
746
697
  return [2 /*return*/];
747
698
  case 4:
748
699
  if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 6];
749
- _e = sub;
750
- return [4 /*yield*/, (_b = that._publications[sub.publication]).preFunction.apply(_b, sub.subscriptionData)];
700
+ _b = sub;
701
+ return [4 /*yield*/, (_d = that._publications[sub.publication]).preFunction.apply(_d, sub.subscriptionData)];
751
702
  case 5:
752
- _e.preSubscriptionData = _f.sent();
703
+ _b.preSubscriptionData = _f.sent();
753
704
  if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
754
705
  that.sendPubData(sub, 'support', collection);
755
706
  }
@@ -778,7 +729,7 @@ var SubscriptionManager = /** @class */ (function () {
778
729
  }
779
730
  else {
780
731
  if (that._publications[sub.publication].fetchFunction) {
781
- if ((_c = that._publications[sub.publication]).fetchFunction.apply(_c, [document].concat(sub.subscriptionData))) {
732
+ if ((_e = that._publications[sub.publication]).fetchFunction.apply(_e, [document].concat(sub.subscriptionData))) {
782
733
  that.sendPubData(sub, 'support', collection);
783
734
  }
784
735
  }
@@ -795,7 +746,8 @@ var SubscriptionManager = /** @class */ (function () {
795
746
  // Fetch pub once, send to all clients linked to this pub
796
747
  SubscriptionManager.prototype.sendPubDataOnce = function (ws, messageId, subscription, type, collection) {
797
748
  return __awaiter(this, void 0, void 0, function () {
798
- var _a, _b, that;
749
+ var that;
750
+ var _a, _b;
799
751
  var _this = this;
800
752
  return __generator(this, function (_c) {
801
753
  that = this;
@@ -847,7 +799,8 @@ var SubscriptionManager = /** @class */ (function () {
847
799
  // Fetch pub once, send to all clients linked to this pub
848
800
  SubscriptionManager.prototype.sendPubData = function (subscription, type, collection) {
849
801
  return __awaiter(this, void 0, void 0, function () {
850
- var _a, that;
802
+ var that;
803
+ var _a;
851
804
  var _this = this;
852
805
  return __generator(this, function (_b) {
853
806
  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<{}>;
21
- readImage(fileName: any): Promise<{}>;
20
+ readFile(fileName: any): Promise<unknown>;
21
+ readImage(fileName: any): Promise<unknown>;
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 _this = this;
106
105
  var _a;
106
+ var _this = this;
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.2",
3
+ "version": "4.3.3",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {
package/server-app.js CHANGED
@@ -254,7 +254,8 @@ 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 _a, _b, socketData, data, messageDate, messageId, type, subType, pub;
257
+ var socketData, data, messageDate, messageId, type, subType, pub;
258
+ var _a, _b;
258
259
  var _this = this;
259
260
  return __generator(this, function (_c) {
260
261
  socketData = JSON.parse(message, common_1.dateReviver);
@@ -329,7 +330,8 @@ var ResolveIOMainServer = /** @class */ (function () {
329
330
  if (!!this._msgQueueRunning) return [3 /*break*/, 5];
330
331
  this._msgQueueRunning = true;
331
332
  _loop_1 = function (i) {
332
- var _a, _b, msg, data, ws, messageDate, messageId, type, method, methodLatency, serverRes, query, methodCall, supportMethod, serverRes;
333
+ var msg, data, ws, messageDate, messageId, type, method, methodLatency, serverRes, query, methodCall, supportMethod, serverRes;
334
+ var _a, _b;
333
335
  return __generator(this, function (_c) {
334
336
  switch (_c.label) {
335
337
  case 0: