@resolveio/server-lib 4.0.23 → 4.0.24

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];
@@ -136,7 +136,8 @@ var SubscriptionManager = /** @class */ (function () {
136
136
  subscriptionData[_i - 3] = arguments[_i];
137
137
  }
138
138
  return __awaiter(this, void 0, void 0, function () {
139
- var _a, that, pub, valObj, valKeys, rootKeys, i, sub, _b, newActiveSub, begDate, endDate, billUser;
139
+ var that, pub, valObj, valKeys, rootKeys, i, sub, _a, newActiveSub, begDate, endDate, billUser;
140
+ var _b;
140
141
  return __generator(this, function (_c) {
141
142
  switch (_c.label) {
142
143
  case 0:
@@ -201,10 +202,10 @@ var SubscriptionManager = /** @class */ (function () {
201
202
  // Send pub data to client who just subscribed only, don't want to send to existing clients since nothing has changed
202
203
  that.sendPubDataOnce(ws, messageId, sub, 'newSub', that.getPublicationCollections(publication)[0]);
203
204
  if (!(that._publications[sub.publication].preFunction && !sub.preSubscriptionData)) return [3 /*break*/, 3];
204
- _b = sub;
205
- return [4 /*yield*/, (_a = that._publications[sub.publication]).preFunction.apply(_a, sub.subscriptionData)];
205
+ _a = sub;
206
+ return [4 /*yield*/, (_b = that._publications[sub.publication]).preFunction.apply(_b, sub.subscriptionData)];
206
207
  case 2:
207
- _b.preSubscriptionData = _c.sent();
208
+ _a.preSubscriptionData = _c.sent();
208
209
  _c.label = 3;
209
210
  case 3:
210
211
  newActiveSub = new active_subscription_collection_1.ActiveSubscriptions({
@@ -556,7 +557,8 @@ var SubscriptionManager = /** @class */ (function () {
556
557
  if (noFetchFunction === void 0) { noFetchFunction = false; }
557
558
  var that = this;
558
559
  that._subscriptions.filter(function (a) { return a.collections.includes(collection); }).forEach(function (sub) { return __awaiter(_this, void 0, void 0, function () {
559
- var _a, _b, schemaErrors, _c, _d;
560
+ var schemaErrors, _a, _b;
561
+ var _c, _d;
560
562
  return __generator(this, function (_e) {
561
563
  switch (_e.label) {
562
564
  case 0:
@@ -576,18 +578,18 @@ var SubscriptionManager = /** @class */ (function () {
576
578
  if (!sub.preSubscriptionData) return [3 /*break*/, 4];
577
579
  if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 4];
578
580
  that.sendPubData(sub, type, collection);
579
- _c = sub;
580
- return [4 /*yield*/, (_a = that._publications[sub.publication]).preFunction.apply(_a, sub.subscriptionData)];
581
+ _a = sub;
582
+ return [4 /*yield*/, (_c = that._publications[sub.publication]).preFunction.apply(_c, sub.subscriptionData)];
581
583
  case 3:
582
- _c.preSubscriptionData = _e.sent();
584
+ _a.preSubscriptionData = _e.sent();
583
585
  return [2 /*return*/];
584
586
  case 4:
585
587
  if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 7];
586
588
  if (!!noFetchFunction) return [3 /*break*/, 6];
587
- _d = sub;
589
+ _b = sub;
588
590
  return [4 /*yield*/, that._publications[sub.publication].preFunction(sub.subscriptionData)];
589
591
  case 5:
590
- _d.preSubscriptionData = _e.sent();
592
+ _b.preSubscriptionData = _e.sent();
591
593
  if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
592
594
  that.sendPubData(sub, type, collection);
593
595
  }
@@ -620,7 +622,7 @@ var SubscriptionManager = /** @class */ (function () {
620
622
  else {
621
623
  if (that._publications[sub.publication].fetchFunction) {
622
624
  if (!noFetchFunction) {
623
- if ((_b = that._publications[sub.publication]).fetchFunction.apply(_b, [document].concat(sub.subscriptionData))) {
625
+ if ((_d = that._publications[sub.publication]).fetchFunction.apply(_d, [document].concat(sub.subscriptionData))) {
624
626
  that.sendPubData(sub, type, collection);
625
627
  }
626
628
  }
@@ -639,7 +641,8 @@ var SubscriptionManager = /** @class */ (function () {
639
641
  var _this = this;
640
642
  var that = this;
641
643
  that._subscriptions.filter(function (a) { return a.collections.includes(collection); }).forEach(function (sub) { return __awaiter(_this, void 0, void 0, function () {
642
- var _a, _b, _c, schemaErrors, _d, _e;
644
+ var schemaErrors, _a, _b;
645
+ var _c, _d, _e;
643
646
  return __generator(this, function (_f) {
644
647
  switch (_f.label) {
645
648
  case 0:
@@ -659,17 +662,17 @@ var SubscriptionManager = /** @class */ (function () {
659
662
  if (!sub.preSubscriptionData) return [3 /*break*/, 4];
660
663
  if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 4];
661
664
  that.sendPubData(sub, 'support', collection);
662
- _d = sub;
663
- return [4 /*yield*/, (_a = that._publications[sub.publication]).preFunction.apply(_a, sub.subscriptionData)];
665
+ _a = sub;
666
+ return [4 /*yield*/, (_c = that._publications[sub.publication]).preFunction.apply(_c, sub.subscriptionData)];
664
667
  case 3:
665
- _d.preSubscriptionData = _f.sent();
668
+ _a.preSubscriptionData = _f.sent();
666
669
  return [2 /*return*/];
667
670
  case 4:
668
671
  if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 6];
669
- _e = sub;
670
- return [4 /*yield*/, (_b = that._publications[sub.publication]).preFunction.apply(_b, sub.subscriptionData)];
672
+ _b = sub;
673
+ return [4 /*yield*/, (_d = that._publications[sub.publication]).preFunction.apply(_d, sub.subscriptionData)];
671
674
  case 5:
672
- _e.preSubscriptionData = _f.sent();
675
+ _b.preSubscriptionData = _f.sent();
673
676
  if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
674
677
  that.sendPubData(sub, 'support', collection);
675
678
  }
@@ -698,7 +701,7 @@ var SubscriptionManager = /** @class */ (function () {
698
701
  }
699
702
  else {
700
703
  if (that._publications[sub.publication].fetchFunction) {
701
- if ((_c = that._publications[sub.publication]).fetchFunction.apply(_c, [document].concat(sub.subscriptionData))) {
704
+ if ((_e = that._publications[sub.publication]).fetchFunction.apply(_e, [document].concat(sub.subscriptionData))) {
702
705
  that.sendPubData(sub, 'support', collection);
703
706
  }
704
707
  }
@@ -715,7 +718,8 @@ var SubscriptionManager = /** @class */ (function () {
715
718
  // Fetch pub once, send to all clients linked to this pub
716
719
  SubscriptionManager.prototype.sendPubDataOnce = function (ws, messageId, subscription, type, collection) {
717
720
  return __awaiter(this, void 0, void 0, function () {
718
- var _a, _b, that;
721
+ var that;
722
+ var _a, _b;
719
723
  var _this = this;
720
724
  return __generator(this, function (_c) {
721
725
  that = this;
@@ -761,7 +765,8 @@ var SubscriptionManager = /** @class */ (function () {
761
765
  // Fetch pub once, send to all clients linked to this pub
762
766
  SubscriptionManager.prototype.sendPubData = function (subscription, type, collection) {
763
767
  return __awaiter(this, void 0, void 0, function () {
764
- var _a, that;
768
+ var that;
769
+ var _a;
765
770
  var _this = this;
766
771
  return __generator(this, function (_b) {
767
772
  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/methods/logs.js CHANGED
@@ -53,6 +53,33 @@ function loadLogMethods(methodManager) {
53
53
  });
54
54
  },
55
55
  skipValidation: true
56
+ },
57
+ superadminAPM: {
58
+ skipQueue: true,
59
+ function: function (date_start, date_end) {
60
+ return log_method_latency_collection_1.LogMethodLatencies.aggregate([
61
+ {
62
+ $match: {
63
+ $and: [
64
+ {
65
+ createdAt: { $gte: date_start }
66
+ },
67
+ {
68
+ createdAt: { $lte: date_end }
69
+ }
70
+ ]
71
+ }
72
+ },
73
+ {
74
+ $group: {
75
+ _id: '$method',
76
+ count: { $sum: 1 },
77
+ latency_avg: { $avg: '$latency_ms' }
78
+ }
79
+ }
80
+ ]).exec();
81
+ },
82
+ skipValidation: true
56
83
  }
57
84
  });
58
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "4.0.23",
3
+ "version": "4.0.24",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var simpl_schema_1 = require("simpl-schema");
4
4
  var log_collection_1 = require("../collections/log.collection");
5
+ var log_method_latency_collection_1 = require("src/collections/log-method-latency.collection");
5
6
  function loadLogPublications(subscriptionManager) {
6
7
  subscriptionManager.publications({
7
8
  logsWithType: {
@@ -20,6 +21,12 @@ function loadLogPublications(subscriptionManager) {
20
21
  fetchFunction: function (document, type) {
21
22
  return document['type'] === type;
22
23
  }
24
+ },
25
+ methodlatencies: {
26
+ function: function () {
27
+ return log_method_latency_collection_1.LogMethodLatencies.find({}).sort({ date_start: -1 }).exec();
28
+ },
29
+ collections: ['log-method-latencies'],
23
30
  }
24
31
  });
25
32
  }
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: