@resolveio/server-lib 9.0.34 → 9.0.35

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.
Files changed (192) hide show
  1. package/client-server-app.js +48 -7
  2. package/client-server-app.js.map +1 -1
  3. package/collections/app-status.collection.js +11 -8
  4. package/collections/app-status.collection.js.map +1 -1
  5. package/collections/app-version.collection.js +11 -8
  6. package/collections/app-version.collection.js.map +1 -1
  7. package/collections/counter.collection.js +11 -8
  8. package/collections/counter.collection.js.map +1 -1
  9. package/collections/cron-job-history.collection.js +12 -9
  10. package/collections/cron-job-history.collection.js.map +1 -1
  11. package/collections/cron-job.collection.js +11 -8
  12. package/collections/cron-job.collection.js.map +1 -1
  13. package/collections/email-history.collection.js +11 -8
  14. package/collections/email-history.collection.js.map +1 -1
  15. package/collections/email-verified.collection.js +12 -9
  16. package/collections/email-verified.collection.js.map +1 -1
  17. package/collections/file.collection.js +11 -8
  18. package/collections/file.collection.js.map +1 -1
  19. package/collections/flag.collection.js +11 -8
  20. package/collections/flag.collection.js.map +1 -1
  21. package/collections/log-method-latency.collection.js +14 -11
  22. package/collections/log-method-latency.collection.js.map +1 -1
  23. package/collections/log-subscription.collection.js +16 -13
  24. package/collections/log-subscription.collection.js.map +1 -1
  25. package/collections/log.collection.js +19 -16
  26. package/collections/log.collection.js.map +1 -1
  27. package/collections/logged-in-users.collection.js +12 -9
  28. package/collections/logged-in-users.collection.js.map +1 -1
  29. package/collections/method-call.collection.js +13 -10
  30. package/collections/method-call.collection.js.map +1 -1
  31. package/collections/method-response.collection.js +13 -10
  32. package/collections/method-response.collection.js.map +1 -1
  33. package/collections/monitor-cpu.collection.js +16 -13
  34. package/collections/monitor-cpu.collection.js.map +1 -1
  35. package/collections/monitor-https-inbound.collection.js +16 -13
  36. package/collections/monitor-https-inbound.collection.js.map +1 -1
  37. package/collections/monitor-https-outbound.collection.js +18 -15
  38. package/collections/monitor-https-outbound.collection.js.map +1 -1
  39. package/collections/monitor-memory.collection.js +15 -12
  40. package/collections/monitor-memory.collection.js.map +1 -1
  41. package/collections/monitor-mongo.collection.js +15 -12
  42. package/collections/monitor-mongo.collection.js.map +1 -1
  43. package/collections/notification.collection.js +11 -8
  44. package/collections/notification.collection.js.map +1 -1
  45. package/collections/queue-flag.collection.js +12 -9
  46. package/collections/queue-flag.collection.js.map +1 -1
  47. package/collections/queue-method.collection.js +12 -9
  48. package/collections/queue-method.collection.js.map +1 -1
  49. package/collections/queue-response.collection.js +12 -9
  50. package/collections/queue-response.collection.js.map +1 -1
  51. package/collections/report-builder-dashboard-builder.collection.js +13 -10
  52. package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
  53. package/collections/report-builder-library.collection.js +14 -11
  54. package/collections/report-builder-library.collection.js.map +1 -1
  55. package/collections/report-builder-report.collection.js +14 -11
  56. package/collections/report-builder-report.collection.js.map +1 -1
  57. package/collections/user-group.collection.js +14 -11
  58. package/collections/user-group.collection.js.map +1 -1
  59. package/collections/user-guide.collection.js +11 -8
  60. package/collections/user-guide.collection.js.map +1 -1
  61. package/collections/user.collection.js +15 -12
  62. package/collections/user.collection.js.map +1 -1
  63. package/cron/cron.js +25 -25
  64. package/cron/cron.js.map +1 -1
  65. package/fixtures/cron-jobs.js +80 -30
  66. package/fixtures/cron-jobs.js.map +1 -1
  67. package/fixtures/init.js +59 -9
  68. package/fixtures/init.js.map +1 -1
  69. package/http/auth.js +460 -344
  70. package/http/auth.js.map +1 -1
  71. package/http/health.js +5 -1
  72. package/http/health.js.map +1 -1
  73. package/http/home.js +11 -7
  74. package/http/home.js.map +1 -1
  75. package/index.js +98 -36
  76. package/index.js.map +1 -1
  77. package/managers/cron.manager.js +157 -78
  78. package/managers/cron.manager.js.map +1 -1
  79. package/managers/method.manager.js +302 -314
  80. package/managers/method.manager.js.map +1 -1
  81. package/managers/mongo.manager.js +1001 -739
  82. package/managers/mongo.manager.js.map +1 -1
  83. package/managers/monitor.manager.js +254 -171
  84. package/managers/monitor.manager.js.map +1 -1
  85. package/managers/queue-method.manager.js +166 -69
  86. package/managers/queue-method.manager.js.map +1 -1
  87. package/managers/subscription.manager.js +714 -515
  88. package/managers/subscription.manager.js.map +1 -1
  89. package/methods/accounts.js +183 -111
  90. package/methods/accounts.js.map +1 -1
  91. package/methods/aws.js +262 -156
  92. package/methods/aws.js.map +1 -1
  93. package/methods/cloudconvert.js +180 -100
  94. package/methods/cloudconvert.js.map +1 -1
  95. package/methods/collections.js +110 -103
  96. package/methods/collections.js.map +1 -1
  97. package/methods/counters.js +79 -29
  98. package/methods/counters.js.map +1 -1
  99. package/methods/cron-jobs.js +884 -819
  100. package/methods/cron-jobs.js.map +1 -1
  101. package/methods/flags.js +5 -1
  102. package/methods/flags.js.map +1 -1
  103. package/methods/logs.js +313 -258
  104. package/methods/logs.js.map +1 -1
  105. package/methods/monitor.js +348 -289
  106. package/methods/monitor.js.map +1 -1
  107. package/methods/pdf.js +340 -341
  108. package/methods/pdf.js.map +1 -1
  109. package/methods/report-builder.js +657 -565
  110. package/methods/report-builder.js.map +1 -1
  111. package/methods/support.js +185 -67
  112. package/methods/support.js.map +1 -1
  113. package/models/app-status.model.js +2 -1
  114. package/models/app-version.model.js +2 -1
  115. package/models/billing-logged-in-users.model.js +2 -1
  116. package/models/collection-document.model.js +2 -1
  117. package/models/counter.model.js +2 -1
  118. package/models/cron-job-history.model.js +2 -1
  119. package/models/cron-job.model.js +2 -1
  120. package/models/dialog.model.js +2 -1
  121. package/models/email-history.model.js +2 -1
  122. package/models/email-verified.model.js +2 -1
  123. package/models/file.model.js +2 -1
  124. package/models/flag.model.js +2 -1
  125. package/models/log-method-latency.model.js +2 -1
  126. package/models/log-subscription.model.js +2 -1
  127. package/models/log.model.js +2 -1
  128. package/models/logged-in-users.model.js +2 -1
  129. package/models/method-call.model.js +2 -1
  130. package/models/method-response.model.js +2 -1
  131. package/models/method.model.js +2 -1
  132. package/models/monitor-cpu.model.js +2 -1
  133. package/models/monitor-https-inbound.model.js +2 -1
  134. package/models/monitor-https-outbound.model.js +2 -1
  135. package/models/monitor-memory.model.js +2 -1
  136. package/models/monitor-mongo.model.js +2 -1
  137. package/models/notification.model.js +2 -1
  138. package/models/pagination.model.js +5 -2
  139. package/models/pagination.model.js.map +1 -1
  140. package/models/permission.model.js +2 -1
  141. package/models/queue-method.model.js +2 -1
  142. package/models/queue-response.model.js +2 -1
  143. package/models/report-builder-dashboard-builder.model.js +2 -1
  144. package/models/report-builder-library.model.js +2 -1
  145. package/models/report-builder-report.model.js +2 -1
  146. package/models/report-builder.model.js +2 -1
  147. package/models/select-data-label.model.js +2 -1
  148. package/models/server-response.model.js +2 -1
  149. package/models/subscription.model.js +2 -1
  150. package/models/support-ticket.model.js +2 -1
  151. package/models/user-group.model.js +2 -1
  152. package/models/user-guide.model.js +2 -1
  153. package/models/user.model.js +2 -1
  154. package/package.json +1 -1
  155. package/public_api.js +82 -70
  156. package/public_api.js.map +1 -1
  157. package/publications/app-status.js +8 -4
  158. package/publications/app-status.js.map +1 -1
  159. package/publications/app-version.js +8 -4
  160. package/publications/app-version.js.map +1 -1
  161. package/publications/cron-jobs.js +13 -9
  162. package/publications/cron-jobs.js.map +1 -1
  163. package/publications/files.js +15 -11
  164. package/publications/files.js.map +1 -1
  165. package/publications/flags.js +11 -7
  166. package/publications/flags.js.map +1 -1
  167. package/publications/logs.js +35 -31
  168. package/publications/logs.js.map +1 -1
  169. package/publications/method-calls.js +8 -4
  170. package/publications/method-calls.js.map +1 -1
  171. package/publications/method-responses.js +8 -4
  172. package/publications/method-responses.js.map +1 -1
  173. package/publications/notifications.js +8 -4
  174. package/publications/notifications.js.map +1 -1
  175. package/publications/report-builder-dashboard-builders.js +12 -8
  176. package/publications/report-builder-dashboard-builders.js.map +1 -1
  177. package/publications/report-builder-libraries.js +66 -16
  178. package/publications/report-builder-libraries.js.map +1 -1
  179. package/publications/report-builder-reports.js +21 -17
  180. package/publications/report-builder-reports.js.map +1 -1
  181. package/publications/super-admin.js +7 -3
  182. package/publications/super-admin.js.map +1 -1
  183. package/publications/user-groups.js +8 -4
  184. package/publications/user-groups.js.map +1 -1
  185. package/publications/user-guides.js +8 -4
  186. package/publications/user-guides.js.map +1 -1
  187. package/server-app.js +534 -393
  188. package/server-app.js.map +1 -1
  189. package/util/common.js +92 -55
  190. package/util/common.js.map +1 -1
  191. package/util/schema-report-builder.js +134 -76
  192. package/util/schema-report-builder.js.map +1 -1
@@ -1,37 +1,77 @@
1
- import { QueueFlags } from '../collections/queue-flag.collection';
2
- import { QueueMethods } from '../collections/queue-method.collection';
3
- import { QueueResponses } from '../collections/queue-response.collection';
4
- import { MethodResponses } from '../collections/method-response.collection';
5
- import { Logs } from '../collections/log.collection';
6
- import { getBinarySize, dateReviver } from '../util/common';
7
- import { objectIdHexString } from './mongo.manager';
8
- export class QueueMethodManager {
9
- constructor(mainServer) {
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.QueueMethodManager = void 0;
40
+ var queue_flag_collection_1 = require("../collections/queue-flag.collection");
41
+ var queue_method_collection_1 = require("../collections/queue-method.collection");
42
+ var queue_response_collection_1 = require("../collections/queue-response.collection");
43
+ var method_response_collection_1 = require("../collections/method-response.collection");
44
+ var log_collection_1 = require("../collections/log.collection");
45
+ var common_1 = require("../util/common");
46
+ var mongo_manager_1 = require("./mongo.manager");
47
+ var QueueMethodManager = /** @class */ (function () {
48
+ function QueueMethodManager(mainServer) {
49
+ var _this = this;
10
50
  this._sendQueue = [];
11
51
  this._runningQueue = false;
12
52
  this._mainServer = mainServer;
13
- setInterval(() => {
14
- if (!this._runningQueue) {
15
- if (this._sendQueue.length) {
16
- this._runningQueue = true;
17
- for (let i = this._sendQueue.length - 1; i >= 0; i--) {
18
- let ws = this._mainServer.getWS(this._sendQueue[i].id_ws);
53
+ setInterval(function () {
54
+ if (!_this._runningQueue) {
55
+ if (_this._sendQueue.length) {
56
+ _this._runningQueue = true;
57
+ var _loop_1 = function (i) {
58
+ var ws = _this._mainServer.getWS(_this._sendQueue[i].id_ws);
19
59
  if (ws && ws.readyState === ws.OPEN) {
20
60
  if (ws.bufferedAmount < 20480) {
21
- let sendItem = this._sendQueue.pop();
22
- ws.send(JSON.stringify(sendItem.response), (error) => {
61
+ var sendItem = _this._sendQueue.pop();
62
+ ws.send(JSON.stringify(sendItem.response), function (error) {
23
63
  if (error) {
24
64
  console.log('Error on WS: ', error);
25
- this._mainServer.unsubscribeWS(ws);
65
+ _this._mainServer.unsubscribeWS(ws);
26
66
  }
27
67
  });
28
68
  if (sendItem.method !== 'reportBuilderGetResults' && sendItem.method !== 'reportBuilderGetDistinctValue' && sendItem.method !== 'reportBuilderBuildTree' && sendItem.method !== 'generatePDF' && sendItem.method !== 'getWOOfflineData' && sendItem.method !== 'countQuery' && sendItem.method !== 'countWithQuery' && sendItem.method !== 'countCollectionWithQuery' && sendItem.method !== 'find' && sendItem.method !== 'findOne' && sendItem.method !== 'findWithOptions' && sendItem.method !== 'setWSAppVersion' && sendItem.method !== 'uploadFileAndSave' && sendItem.method !== 'getDrivers') {
29
- Logs.create({
30
- _id: objectIdHexString(),
69
+ log_collection_1.Logs.create({
70
+ _id: mongo_manager_1.objectIdHexString(),
31
71
  type: 'client-response',
32
72
  collection: '',
33
73
  id_document: '',
34
- payload: getBinarySize(JSON.stringify([sendItem.methodData, sendItem.response])) < 200000 ? JSON.stringify([sendItem.methodData, sendItem.response], null, 2) : 'Too Big',
74
+ payload: common_1.getBinarySize(JSON.stringify([sendItem.methodData, sendItem.response])) < 200000 ? JSON.stringify([sendItem.methodData, sendItem.response], null, 2) : 'Too Big',
35
75
  method: sendItem.method,
36
76
  id_user: ws['id_user'],
37
77
  user: ws['user'],
@@ -39,27 +79,30 @@ export class QueueMethodManager {
39
79
  route: ''
40
80
  });
41
81
  }
42
- MethodResponses.create({
43
- _id: objectIdHexString(),
82
+ method_response_collection_1.MethodResponses.create({
83
+ _id: mongo_manager_1.objectIdHexString(),
44
84
  __v: 0,
45
85
  id_user: sendItem.id_user,
46
86
  message_id: sendItem.messageId,
47
- response: getBinarySize(JSON.stringify(sendItem.response)) < 200000 ? sendItem.response : 'Too Big',
87
+ response: common_1.getBinarySize(JSON.stringify(sendItem.response)) < 200000 ? sendItem.response : 'Too Big',
48
88
  method: sendItem.method,
49
89
  date: sendItem.date
50
90
  });
51
91
  }
52
92
  }
93
+ };
94
+ for (var i = _this._sendQueue.length - 1; i >= 0; i--) {
95
+ _loop_1(i);
53
96
  }
54
- this._runningQueue = false;
97
+ _this._runningQueue = false;
55
98
  }
56
99
  }
57
100
  }, 10);
58
101
  }
59
- addMethodToQueue(id_methodLatency, id_ws, id_user, user, messageDate, messageId, method, data) {
102
+ QueueMethodManager.prototype.addMethodToQueue = function (id_methodLatency, id_ws, id_user, user, messageDate, messageId, method, data) {
60
103
  // console.log('Add Method To Queue', method);
61
- QueueMethods.create({
62
- _id: objectIdHexString(),
104
+ queue_method_collection_1.QueueMethods.create({
105
+ _id: mongo_manager_1.objectIdHexString(),
63
106
  __v: 0,
64
107
  id_ws: id_ws,
65
108
  messageId: messageId,
@@ -71,32 +114,72 @@ export class QueueMethodManager {
71
114
  date: messageDate,
72
115
  id_methodLatency: id_methodLatency
73
116
  });
74
- }
75
- async runMethodQueue(count) {
76
- let updateCnt = count ? count : await QueueMethods.countDocuments();
77
- if (updateCnt) {
78
- // console.log('Run Method Queue', updateCnt);
79
- QueueFlags.insertOne({ _id: 'method-queue', __v: 0 }).then(async (res) => {
80
- if (res) {
81
- let updates = await QueueMethods.find({}, { sort: { createdAt: 1 } });
82
- for (let i = 0; i < updates.length; i++) {
83
- let update = updates[i];
84
- update.method_data = JSON.parse(update.method_data_string, dateReviver);
85
- await this._mainServer.getMethodManager().callMethodQueue(update);
86
- await QueueMethods.deleteOne({ _id: update._id });
87
- }
88
- QueueFlags.deleteOne({ _id: 'method-queue' });
89
- updateCnt = await QueueMethods.countDocuments();
90
- if (updateCnt) {
91
- this.runMethodQueue(updateCnt);
92
- }
117
+ };
118
+ QueueMethodManager.prototype.runMethodQueue = function (count) {
119
+ return __awaiter(this, void 0, void 0, function () {
120
+ var updateCnt, _a;
121
+ var _this = this;
122
+ return __generator(this, function (_b) {
123
+ switch (_b.label) {
124
+ case 0:
125
+ if (!count) return [3 /*break*/, 1];
126
+ _a = count;
127
+ return [3 /*break*/, 3];
128
+ case 1: return [4 /*yield*/, queue_method_collection_1.QueueMethods.countDocuments()];
129
+ case 2:
130
+ _a = _b.sent();
131
+ _b.label = 3;
132
+ case 3:
133
+ updateCnt = _a;
134
+ if (updateCnt) {
135
+ // console.log('Run Method Queue', updateCnt);
136
+ queue_flag_collection_1.QueueFlags.insertOne({ _id: 'method-queue', __v: 0 }).then(function (res) { return __awaiter(_this, void 0, void 0, function () {
137
+ var updates, i, update;
138
+ return __generator(this, function (_a) {
139
+ switch (_a.label) {
140
+ case 0:
141
+ if (!res) return [3 /*break*/, 8];
142
+ return [4 /*yield*/, queue_method_collection_1.QueueMethods.find({}, { sort: { createdAt: 1 } })];
143
+ case 1:
144
+ updates = _a.sent();
145
+ i = 0;
146
+ _a.label = 2;
147
+ case 2:
148
+ if (!(i < updates.length)) return [3 /*break*/, 6];
149
+ update = updates[i];
150
+ update.method_data = JSON.parse(update.method_data_string, common_1.dateReviver);
151
+ return [4 /*yield*/, this._mainServer.getMethodManager().callMethodQueue(update)];
152
+ case 3:
153
+ _a.sent();
154
+ return [4 /*yield*/, queue_method_collection_1.QueueMethods.deleteOne({ _id: update._id })];
155
+ case 4:
156
+ _a.sent();
157
+ _a.label = 5;
158
+ case 5:
159
+ i++;
160
+ return [3 /*break*/, 2];
161
+ case 6:
162
+ queue_flag_collection_1.QueueFlags.deleteOne({ _id: 'method-queue' });
163
+ return [4 /*yield*/, queue_method_collection_1.QueueMethods.countDocuments()];
164
+ case 7:
165
+ updateCnt = _a.sent();
166
+ if (updateCnt) {
167
+ this.runMethodQueue(updateCnt);
168
+ }
169
+ _a.label = 8;
170
+ case 8: return [2 /*return*/];
171
+ }
172
+ });
173
+ }); }, function () { });
174
+ }
175
+ return [2 /*return*/];
93
176
  }
94
- }, () => { });
95
- }
96
- }
97
- addMethodResponse(update, response) {
98
- QueueResponses.create({
99
- _id: objectIdHexString(),
177
+ });
178
+ });
179
+ };
180
+ QueueMethodManager.prototype.addMethodResponse = function (update, response) {
181
+ queue_response_collection_1.QueueResponses.create({
182
+ _id: mongo_manager_1.objectIdHexString(),
100
183
  __v: 0,
101
184
  id_ws: update.id_ws,
102
185
  id_user: update.id_user,
@@ -106,21 +189,35 @@ export class QueueMethodManager {
106
189
  method: update.method,
107
190
  date: update.date
108
191
  });
109
- }
110
- async runMethodResponse() {
111
- let responseCnt = await QueueResponses.countDocuments();
112
- if (responseCnt && !this._runningMethodResponse) {
113
- this._runningMethodResponse = true;
114
- let wsList = this._mainServer.getWSList();
115
- let responses = await QueueResponses.find({ id_ws: { $in: wsList } });
116
- for (let i = 0; i < responses.length; i++) {
117
- let response = responses[i];
118
- this._sendQueue.splice(0, 0, response);
119
- QueueResponses.deleteOne({ _id: response._id });
120
- }
121
- this._runningMethodResponse = false;
122
- }
123
- }
124
- }
192
+ };
193
+ QueueMethodManager.prototype.runMethodResponse = function () {
194
+ return __awaiter(this, void 0, void 0, function () {
195
+ var responseCnt, wsList, responses, i, response;
196
+ return __generator(this, function (_a) {
197
+ switch (_a.label) {
198
+ case 0: return [4 /*yield*/, queue_response_collection_1.QueueResponses.countDocuments()];
199
+ case 1:
200
+ responseCnt = _a.sent();
201
+ if (!(responseCnt && !this._runningMethodResponse)) return [3 /*break*/, 3];
202
+ this._runningMethodResponse = true;
203
+ wsList = this._mainServer.getWSList();
204
+ return [4 /*yield*/, queue_response_collection_1.QueueResponses.find({ id_ws: { $in: wsList } })];
205
+ case 2:
206
+ responses = _a.sent();
207
+ for (i = 0; i < responses.length; i++) {
208
+ response = responses[i];
209
+ this._sendQueue.splice(0, 0, response);
210
+ queue_response_collection_1.QueueResponses.deleteOne({ _id: response._id });
211
+ }
212
+ this._runningMethodResponse = false;
213
+ _a.label = 3;
214
+ case 3: return [2 /*return*/];
215
+ }
216
+ });
217
+ });
218
+ };
219
+ return QueueMethodManager;
220
+ }());
221
+ exports.QueueMethodManager = QueueMethodManager;
125
222
 
126
223
  //# sourceMappingURL=queue-method.manager.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/managers/queue-method.manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAElE,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAE1E,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAC5E,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,MAAM,OAAO,kBAAkB;IAQ9B,YAAY,UAAU;QALd,eAAU,GAAG,EAAE,CAAC;QAChB,kBAAa,GAAG,KAAK,CAAC;QAK7B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAE9B,WAAW,CAAC,GAAG,EAAE;YAChB,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;gBACxB,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE;oBAC3B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;oBAC1B,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;wBACrD,IAAI,EAAE,GAAG,IAAI,CAAC,WAAW,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,CAAC,CAAC,CAAC;gBAE5B,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;gBAEvC,cAAc,CAAC,SAAS,CAAC,EAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,EAAC,CAAC,CAAC;aAC9C;YAED,IAAI,CAAC,sBAAsB,GAAG,KAAK,CAAC;SACpC;IACF,CAAC;CACD","file":"queue-method.manager.js","sourcesContent":["import { QueueFlags } from '../collections/queue-flag.collection';\nimport { QueueMethodModel } from '../models/queue-method.model';\nimport { QueueMethods } from '../collections/queue-method.collection';\nimport { QueueResponses } from '../collections/queue-response.collection';\nimport { ServerResponseModel } from '../models/server-response.model';\nimport { MethodResponses } from '../collections/method-response.collection';\nimport { Logs } from '../collections/log.collection';\nimport { getBinarySize, dateReviver } from '../util/common';\nimport ResolveIOMainServer from '../server-app';\nimport { objectIdHexString } from './mongo.manager';\n\nexport class QueueMethodManager {\n\n\tprivate _mainServer: ResolveIOMainServer;\n\tprivate _sendQueue = [];\n\tprivate _runningQueue = false;\n\n\tprivate _runningMethodResponse;\n\n\tconstructor(mainServer) {\n\t\tthis._mainServer = mainServer;\n\n\t\tsetInterval(() => {\n\t\t\tif (!this._runningQueue) {\n\t\t\t\tif (this._sendQueue.length) {\n\t\t\t\t\tthis._runningQueue = true;\n\t\t\t\t\tfor (let i = this._sendQueue.length - 1; i >= 0; i--) {\n\t\t\t\t\t\tlet ws = this._mainServer.getWS(this._sendQueue[i].id_ws);\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tif (ws.bufferedAmount < 20480) {\n\t\t\t\t\t\t\t\tlet sendItem = this._sendQueue.pop();\n\t\t\t\t\t\t\t\tws.send(JSON.stringify(sendItem.response), (error) => {\n\t\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\t\tthis._mainServer.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tif (sendItem.method !== 'reportBuilderGetResults' && sendItem.method !== 'reportBuilderGetDistinctValue' && sendItem.method !== 'reportBuilderBuildTree' && sendItem.method !== 'generatePDF' && sendItem.method !== 'getWOOfflineData' && sendItem.method !== 'countQuery' && sendItem.method !== 'countWithQuery' && sendItem.method !== 'countCollectionWithQuery' && sendItem.method !== 'find' && sendItem.method !== 'findOne' && sendItem.method !== 'findWithOptions' && sendItem.method !== 'setWSAppVersion' && sendItem.method !== 'uploadFileAndSave' && sendItem.method !== 'getDrivers') {\n\t\t\t\t\t\t\t\t\tLogs.create({\n\t\t\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\t\t\ttype: 'client-response',\n\t\t\t\t\t\t\t\t\t\tcollection: '',\n\t\t\t\t\t\t\t\t\t\tid_document: '',\n\t\t\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([sendItem.methodData, sendItem.response])) < 200000 ? JSON.stringify([sendItem.methodData, sendItem.response], null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\t\t\tmethod: sendItem.method,\n\t\t\t\t\t\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\t\t\t\t\t\tuser: ws['user'],\n\t\t\t\t\t\t\t\t\t\tmessageId: sendItem.messageId,\n\t\t\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tMethodResponses.create({\n\t\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\t\t\t\tid_user: sendItem.id_user,\n\t\t\t\t\t\t\t\t\tmessage_id: sendItem.messageId,\n\t\t\t\t\t\t\t\t\tresponse: getBinarySize(JSON.stringify(sendItem.response)) < 200000 ? sendItem.response : 'Too Big',\n\t\t\t\t\t\t\t\t\tmethod: sendItem.method,\n\t\t\t\t\t\t\t\t\tdate: sendItem.date\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tthis._runningQueue = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}, 10);\n\t}\n\n\tpublic addMethodToQueue(id_methodLatency: string, id_ws: string, id_user: string, user: string, messageDate: Date, messageId: number, method: string, data: any[]) {\n\n\t\t// console.log('Add Method To Queue', method);\n\n\t\tQueueMethods.create({\n\t\t\t_id: objectIdHexString(),\n\t\t\t__v: 0,\n\t\t\tid_ws: id_ws,\n\t\t\tmessageId: messageId,\n\t\t\tmethod: method,\n\t\t\tmethod_data: [],\n\t\t\tmethod_data_string: JSON.stringify(data),\n\t\t\tid_user: id_user,\n\t\t\tuser: user,\n\t\t\tdate: messageDate,\n\t\t\tid_methodLatency: id_methodLatency\n\t\t});\n\t}\n\n\tpublic async runMethodQueue(count?: number) {\n\t\tlet updateCnt = count ? count : await QueueMethods.countDocuments();\n\t\t\n\t\tif (updateCnt) {\n\t\t\t// console.log('Run Method Queue', updateCnt);\n\n\t\t\tQueueFlags.insertOne({_id: 'method-queue', __v: 0}).then(async res => {\n\t\t\t\tif (res) {\n\t\t\t\t\tlet updates = await QueueMethods.find({}, {sort: {createdAt: 1}});\n\n\t\t\t\t\tfor (let i = 0; i < updates.length; i++) {\n\t\t\t\t\t\tlet update = updates[i];\n\n\t\t\t\t\t\tupdate.method_data = JSON.parse(update.method_data_string, dateReviver);\n\n\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodQueue(update);\n\t\t\t\t\t\tawait QueueMethods.deleteOne({_id: update._id});\n\t\t\t\t\t}\n\n\t\t\t\t\tQueueFlags.deleteOne({_id: 'method-queue'});\n\n\t\t\t\t\tupdateCnt = await QueueMethods.countDocuments();\n\n\t\t\t\t\tif (updateCnt) {\n\t\t\t\t\t\tthis.runMethodQueue(updateCnt);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, () => {});\n\t\t}\n\t}\n\n\tpublic addMethodResponse(update: QueueMethodModel, response: ServerResponseModel) {\n\t\tQueueResponses.create({\n\t\t\t_id: objectIdHexString(),\n\t\t\t__v: 0,\n\t\t\tid_ws: update.id_ws,\n\t\t\tid_user: update.id_user,\n\t\t\tuser: update.user,\n\t\t\tmessageId: update.messageId,\n\t\t\tresponse: response,\n\t\t\tmethod: update.method,\n\t\t\tdate: update.date\n\t\t});\n\t}\n\n\tpublic async runMethodResponse() {\n\t\tlet responseCnt = await QueueResponses.countDocuments();\n\n\t\tif (responseCnt && !this._runningMethodResponse) {\n\t\t\tthis._runningMethodResponse = true;\n\n\t\t\tlet wsList = this._mainServer.getWSList();\n\n\t\t\tlet responses = await QueueResponses.find({id_ws: {$in: wsList}});\n\n\t\t\tfor (let i = 0; i < responses.length; i++) {\n\t\t\t\tlet response = responses[i];\n\n\t\t\t\tthis._sendQueue.splice(0, 0, response);\n\n\t\t\t\tQueueResponses.deleteOne({_id: response._id});\n\t\t\t}\n\n\t\t\tthis._runningMethodResponse = false;\n\t\t}\n\t}\n}"]}
1
+ {"version":3,"sources":["../../src/managers/queue-method.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8EAAkE;AAElE,kFAAsE;AACtE,sFAA0E;AAE1E,wFAA4E;AAC5E,gEAAqD;AACrD,yCAA4D;AAE5D,iDAAoD;AAEpD;IAQC,4BAAY,UAAU;QAAtB,iBAmDC;QAxDO,eAAU,GAAG,EAAE,CAAC;QAChB,kBAAa,GAAG,KAAK,CAAC;QAK7B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAE9B,WAAW,CAAC;YACX,IAAI,CAAC,KAAI,CAAC,aAAa,EAAE;gBACxB,IAAI,KAAI,CAAC,UAAU,CAAC,MAAM,EAAE;oBAC3B,KAAI,CAAC,aAAa,GAAG,IAAI,CAAC;4CACjB,CAAC;wBACT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,CAAC;wBAE/B,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC;wBAE1B,qBAAM,0CAAc,CAAC,IAAI,CAAC,EAAC,KAAK,EAAE,EAAC,GAAG,EAAE,MAAM,EAAC,EAAC,CAAC,EAAA;;wBAA7D,SAAS,GAAG,SAAiD;wBAEjE,KAAS,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;4BACtC,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;4BAE5B,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;4BAEvC,0CAAc,CAAC,SAAS,CAAC,EAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,EAAC,CAAC,CAAC;yBAC9C;wBAED,IAAI,CAAC,sBAAsB,GAAG,KAAK,CAAC;;;;;;KAErC;IACF,yBAAC;AAAD,CAlJA,AAkJC,IAAA;AAlJY,gDAAkB","file":"queue-method.manager.js","sourcesContent":["import { QueueFlags } from '../collections/queue-flag.collection';\nimport { QueueMethodModel } from '../models/queue-method.model';\nimport { QueueMethods } from '../collections/queue-method.collection';\nimport { QueueResponses } from '../collections/queue-response.collection';\nimport { ServerResponseModel } from '../models/server-response.model';\nimport { MethodResponses } from '../collections/method-response.collection';\nimport { Logs } from '../collections/log.collection';\nimport { getBinarySize, dateReviver } from '../util/common';\nimport ResolveIOMainServer from '../server-app';\nimport { objectIdHexString } from './mongo.manager';\n\nexport class QueueMethodManager {\n\n\tprivate _mainServer: ResolveIOMainServer;\n\tprivate _sendQueue = [];\n\tprivate _runningQueue = false;\n\n\tprivate _runningMethodResponse;\n\n\tconstructor(mainServer) {\n\t\tthis._mainServer = mainServer;\n\n\t\tsetInterval(() => {\n\t\t\tif (!this._runningQueue) {\n\t\t\t\tif (this._sendQueue.length) {\n\t\t\t\t\tthis._runningQueue = true;\n\t\t\t\t\tfor (let i = this._sendQueue.length - 1; i >= 0; i--) {\n\t\t\t\t\t\tlet ws = this._mainServer.getWS(this._sendQueue[i].id_ws);\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tif (ws.bufferedAmount < 20480) {\n\t\t\t\t\t\t\t\tlet sendItem = this._sendQueue.pop();\n\t\t\t\t\t\t\t\tws.send(JSON.stringify(sendItem.response), (error) => {\n\t\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\t\tthis._mainServer.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tif (sendItem.method !== 'reportBuilderGetResults' && sendItem.method !== 'reportBuilderGetDistinctValue' && sendItem.method !== 'reportBuilderBuildTree' && sendItem.method !== 'generatePDF' && sendItem.method !== 'getWOOfflineData' && sendItem.method !== 'countQuery' && sendItem.method !== 'countWithQuery' && sendItem.method !== 'countCollectionWithQuery' && sendItem.method !== 'find' && sendItem.method !== 'findOne' && sendItem.method !== 'findWithOptions' && sendItem.method !== 'setWSAppVersion' && sendItem.method !== 'uploadFileAndSave' && sendItem.method !== 'getDrivers') {\n\t\t\t\t\t\t\t\t\tLogs.create({\n\t\t\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\t\t\ttype: 'client-response',\n\t\t\t\t\t\t\t\t\t\tcollection: '',\n\t\t\t\t\t\t\t\t\t\tid_document: '',\n\t\t\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([sendItem.methodData, sendItem.response])) < 200000 ? JSON.stringify([sendItem.methodData, sendItem.response], null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\t\t\tmethod: sendItem.method,\n\t\t\t\t\t\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\t\t\t\t\t\tuser: ws['user'],\n\t\t\t\t\t\t\t\t\t\tmessageId: sendItem.messageId,\n\t\t\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tMethodResponses.create({\n\t\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\t\t\t\tid_user: sendItem.id_user,\n\t\t\t\t\t\t\t\t\tmessage_id: sendItem.messageId,\n\t\t\t\t\t\t\t\t\tresponse: getBinarySize(JSON.stringify(sendItem.response)) < 200000 ? sendItem.response : 'Too Big',\n\t\t\t\t\t\t\t\t\tmethod: sendItem.method,\n\t\t\t\t\t\t\t\t\tdate: sendItem.date\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tthis._runningQueue = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}, 10);\n\t}\n\n\tpublic addMethodToQueue(id_methodLatency: string, id_ws: string, id_user: string, user: string, messageDate: Date, messageId: number, method: string, data: any[]) {\n\n\t\t// console.log('Add Method To Queue', method);\n\n\t\tQueueMethods.create({\n\t\t\t_id: objectIdHexString(),\n\t\t\t__v: 0,\n\t\t\tid_ws: id_ws,\n\t\t\tmessageId: messageId,\n\t\t\tmethod: method,\n\t\t\tmethod_data: [],\n\t\t\tmethod_data_string: JSON.stringify(data),\n\t\t\tid_user: id_user,\n\t\t\tuser: user,\n\t\t\tdate: messageDate,\n\t\t\tid_methodLatency: id_methodLatency\n\t\t});\n\t}\n\n\tpublic async runMethodQueue(count?: number) {\n\t\tlet updateCnt = count ? count : await QueueMethods.countDocuments();\n\t\t\n\t\tif (updateCnt) {\n\t\t\t// console.log('Run Method Queue', updateCnt);\n\n\t\t\tQueueFlags.insertOne({_id: 'method-queue', __v: 0}).then(async res => {\n\t\t\t\tif (res) {\n\t\t\t\t\tlet updates = await QueueMethods.find({}, {sort: {createdAt: 1}});\n\n\t\t\t\t\tfor (let i = 0; i < updates.length; i++) {\n\t\t\t\t\t\tlet update = updates[i];\n\n\t\t\t\t\t\tupdate.method_data = JSON.parse(update.method_data_string, dateReviver);\n\n\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodQueue(update);\n\t\t\t\t\t\tawait QueueMethods.deleteOne({_id: update._id});\n\t\t\t\t\t}\n\n\t\t\t\t\tQueueFlags.deleteOne({_id: 'method-queue'});\n\n\t\t\t\t\tupdateCnt = await QueueMethods.countDocuments();\n\n\t\t\t\t\tif (updateCnt) {\n\t\t\t\t\t\tthis.runMethodQueue(updateCnt);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, () => {});\n\t\t}\n\t}\n\n\tpublic addMethodResponse(update: QueueMethodModel, response: ServerResponseModel) {\n\t\tQueueResponses.create({\n\t\t\t_id: objectIdHexString(),\n\t\t\t__v: 0,\n\t\t\tid_ws: update.id_ws,\n\t\t\tid_user: update.id_user,\n\t\t\tuser: update.user,\n\t\t\tmessageId: update.messageId,\n\t\t\tresponse: response,\n\t\t\tmethod: update.method,\n\t\t\tdate: update.date\n\t\t});\n\t}\n\n\tpublic async runMethodResponse() {\n\t\tlet responseCnt = await QueueResponses.countDocuments();\n\n\t\tif (responseCnt && !this._runningMethodResponse) {\n\t\t\tthis._runningMethodResponse = true;\n\n\t\t\tlet wsList = this._mainServer.getWSList();\n\n\t\t\tlet responses = await QueueResponses.find({id_ws: {$in: wsList}});\n\n\t\t\tfor (let i = 0; i < responses.length; i++) {\n\t\t\t\tlet response = responses[i];\n\n\t\t\t\tthis._sendQueue.splice(0, 0, response);\n\n\t\t\t\tQueueResponses.deleteOne({_id: response._id});\n\t\t\t}\n\n\t\t\tthis._runningMethodResponse = false;\n\t\t}\n\t}\n}"]}