@resolveio/server-lib 4.3.2 → 4.3.4

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({
@@ -408,11 +409,13 @@ var SubscriptionManager = /** @class */ (function () {
408
409
  else if (collection === 'support-tickets') {
409
410
  _this._mainServer.getMethodManager().callMethodInternal('sendSupportTicketEmail', doc.o._id);
410
411
  }
411
- _this._oplogQueue.push({
412
- type: 'insert',
413
- collection: collection,
414
- doc: doc.o
415
- });
412
+ if (!collection.endsWith('.versions')) {
413
+ _this._oplogQueue.push({
414
+ type: 'insert',
415
+ collection: collection,
416
+ doc: doc.o
417
+ });
418
+ }
416
419
  });
417
420
  oplog.on('update', function (doc) {
418
421
  var nsArray = doc.ns.split('.');
@@ -424,11 +427,13 @@ var SubscriptionManager = /** @class */ (function () {
424
427
  if (collection === 'cron-jobs') {
425
428
  _this._mainServer.getCronManager().checkCronJobsForUpdates();
426
429
  }
427
- _this._oplogQueue.push({
428
- type: 'update',
429
- collection: collection,
430
- doc: doc.o
431
- });
430
+ if (!collection.endsWith('.versions')) {
431
+ _this._oplogQueue.push({
432
+ type: 'update',
433
+ collection: collection,
434
+ doc: doc.o
435
+ });
436
+ }
432
437
  });
433
438
  oplog.on('delete', function (doc) {
434
439
  var nsArray = doc.ns.split('.');
@@ -504,38 +509,37 @@ var SubscriptionManager = /** @class */ (function () {
504
509
  var _this = this;
505
510
  var that = this;
506
511
  setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
507
- var oplogQueue_1, uniquePubs_1, uniqueOplog_1, needIds_1, _loop_3, i;
512
+ var oplogQueue, uniqueOplog_1, needIds_1, _loop_3, i;
508
513
  var _this = this;
509
514
  return __generator(this, function (_a) {
510
515
  switch (_a.label) {
511
516
  case 0:
512
517
  if (!this._oplogQueue.length) return [3 /*break*/, 5];
513
- oplogQueue_1 = common_1.deepCopy(this._oplogQueue);
518
+ oplogQueue = common_1.deepCopy(this._oplogQueue);
514
519
  this._oplogQueue = [];
515
- uniquePubs_1 = [];
516
520
  uniqueOplog_1 = [];
517
521
  needIds_1 = {};
518
522
  // 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
- }
523
+ oplogQueue.forEach(function (oplog) {
524
+ if (!uniqueOplog_1.filter(function (a) { return JSON.stringify(a) === JSON.stringify(oplog); }).length) {
525
+ uniqueOplog_1.push(oplog);
526
+ }
527
+ });
528
+ uniqueOplog_1.forEach(function (oplog) {
529
+ var schemaErrors = null;
530
+ try {
531
+ index_1.ResolveIOServer.getMainDB().model(oplog.collection)['simplschema'].validate(oplog.doc);
532
+ }
533
+ catch (errors) {
534
+ schemaErrors = errors;
535
+ }
536
+ if (schemaErrors) {
537
+ if (!needIds_1[oplog.collection]) {
538
+ needIds_1[oplog.collection] = [oplog.doc['_id']];
539
+ }
540
+ else {
541
+ if (!needIds_1[oplog.collection].filter(function (a) { return a === oplog.doc['_id']; })[0]) {
542
+ needIds_1[oplog.collection].push(oplog.doc['_id']);
539
543
  }
540
544
  }
541
545
  }
@@ -550,7 +554,12 @@ var SubscriptionManager = /** @class */ (function () {
550
554
  case 1:
551
555
  docs = _a.sent();
552
556
  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];
557
+ if (uniqueOplog_1.filter(function (a) { return a.doc && a.doc._id === id_doc; })[0]) {
558
+ uniqueOplog_1.filter(function (a) { return a.doc && a.doc._id === id_doc; })[0].doc = docs.filter(function (a) { return a._id === id_doc; })[0];
559
+ }
560
+ else {
561
+ console.log('PROBLEMAAAAAAAA');
562
+ }
554
563
  });
555
564
  return [2 /*return*/];
556
565
  }
@@ -568,58 +577,7 @@ var SubscriptionManager = /** @class */ (function () {
568
577
  i++;
569
578
  return [3 /*break*/, 1];
570
579
  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);
580
+ // console.log('----------------OPLOG QUEUE END--------------------', new Date(), uniqueOplog.length);
623
581
  uniqueOplog_1.forEach(function (oplog) {
624
582
  // console.log('OPLOG QUEUE END - Oplog', oplog);
625
583
  _this.checkPubsForChanges(oplog.collection, oplog.doc, oplog.type);
@@ -654,24 +612,25 @@ var SubscriptionManager = /** @class */ (function () {
654
612
  var _this = this;
655
613
  var that = this;
656
614
  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;
615
+ var _a, _b;
616
+ var _c, _d;
658
617
  return __generator(this, function (_e) {
659
618
  switch (_e.label) {
660
619
  case 0:
661
620
  if (!sub.preSubscriptionData) return [3 /*break*/, 2];
662
621
  if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 2];
663
622
  that.sendPubData(sub, type, collection);
664
- _c = sub;
665
- return [4 /*yield*/, (_a = that._publications[sub.publication]).preFunction.apply(_a, sub.subscriptionData)];
623
+ _a = sub;
624
+ return [4 /*yield*/, (_c = that._publications[sub.publication]).preFunction.apply(_c, sub.subscriptionData)];
666
625
  case 1:
667
- _c.preSubscriptionData = _e.sent();
626
+ _a.preSubscriptionData = _e.sent();
668
627
  _e.label = 2;
669
628
  case 2:
670
629
  if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 4];
671
- _d = sub;
630
+ _b = sub;
672
631
  return [4 /*yield*/, that._publications[sub.publication].preFunction(sub.subscriptionData)];
673
632
  case 3:
674
- _d.preSubscriptionData = _e.sent();
633
+ _b.preSubscriptionData = _e.sent();
675
634
  if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
676
635
  that.sendPubData(sub, type, collection);
677
636
  }
@@ -700,7 +659,7 @@ var SubscriptionManager = /** @class */ (function () {
700
659
  }
701
660
  else {
702
661
  if (that._publications[sub.publication].fetchFunction) {
703
- if ((_b = that._publications[sub.publication]).fetchFunction.apply(_b, [document].concat(sub.subscriptionData))) {
662
+ if ((_d = that._publications[sub.publication]).fetchFunction.apply(_d, [document].concat(sub.subscriptionData))) {
704
663
  that.sendPubData(sub, type, collection);
705
664
  }
706
665
  // else
@@ -719,7 +678,8 @@ var SubscriptionManager = /** @class */ (function () {
719
678
  var _this = this;
720
679
  var that = this;
721
680
  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;
681
+ var schemaErrors, _a, _b;
682
+ var _c, _d, _e;
723
683
  return __generator(this, function (_f) {
724
684
  switch (_f.label) {
725
685
  case 0:
@@ -739,17 +699,17 @@ var SubscriptionManager = /** @class */ (function () {
739
699
  if (!sub.preSubscriptionData) return [3 /*break*/, 4];
740
700
  if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 4];
741
701
  that.sendPubData(sub, 'support', collection);
742
- _d = sub;
743
- return [4 /*yield*/, (_a = that._publications[sub.publication]).preFunction.apply(_a, sub.subscriptionData)];
702
+ _a = sub;
703
+ return [4 /*yield*/, (_c = that._publications[sub.publication]).preFunction.apply(_c, sub.subscriptionData)];
744
704
  case 3:
745
- _d.preSubscriptionData = _f.sent();
705
+ _a.preSubscriptionData = _f.sent();
746
706
  return [2 /*return*/];
747
707
  case 4:
748
708
  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)];
709
+ _b = sub;
710
+ return [4 /*yield*/, (_d = that._publications[sub.publication]).preFunction.apply(_d, sub.subscriptionData)];
751
711
  case 5:
752
- _e.preSubscriptionData = _f.sent();
712
+ _b.preSubscriptionData = _f.sent();
753
713
  if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
754
714
  that.sendPubData(sub, 'support', collection);
755
715
  }
@@ -778,7 +738,7 @@ var SubscriptionManager = /** @class */ (function () {
778
738
  }
779
739
  else {
780
740
  if (that._publications[sub.publication].fetchFunction) {
781
- if ((_c = that._publications[sub.publication]).fetchFunction.apply(_c, [document].concat(sub.subscriptionData))) {
741
+ if ((_e = that._publications[sub.publication]).fetchFunction.apply(_e, [document].concat(sub.subscriptionData))) {
782
742
  that.sendPubData(sub, 'support', collection);
783
743
  }
784
744
  }
@@ -795,7 +755,8 @@ var SubscriptionManager = /** @class */ (function () {
795
755
  // Fetch pub once, send to all clients linked to this pub
796
756
  SubscriptionManager.prototype.sendPubDataOnce = function (ws, messageId, subscription, type, collection) {
797
757
  return __awaiter(this, void 0, void 0, function () {
798
- var _a, _b, that;
758
+ var that;
759
+ var _a, _b;
799
760
  var _this = this;
800
761
  return __generator(this, function (_c) {
801
762
  that = this;
@@ -847,7 +808,8 @@ var SubscriptionManager = /** @class */ (function () {
847
808
  // Fetch pub once, send to all clients linked to this pub
848
809
  SubscriptionManager.prototype.sendPubData = function (subscription, type, collection) {
849
810
  return __awaiter(this, void 0, void 0, function () {
850
- var _a, that;
811
+ var that;
812
+ var _a;
851
813
  var _this = this;
852
814
  return __generator(this, function (_b) {
853
815
  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.4",
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: