@resolveio/server-lib 12.5.52 → 12.5.54
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/.nodemon.json +5 -0
- package/.vscode/settings.json +3 -0
- package/README.md +22 -0
- package/compileDTS.pl +64 -0
- package/gulpfile.js +127 -0
- package/mongodbensurers.js +2 -0
- package/mongostop.js +3 -0
- package/package.json +1 -1
- package/settings.development.json +13 -0
- package/src/client-server-app.ts +7 -0
- package/src/collections/app-status.collection.ts +51 -0
- package/src/collections/counter.collection.ts +54 -0
- package/src/collections/cron-job-history.collection.ts +82 -0
- package/src/collections/cron-job.collection.ts +85 -0
- package/src/collections/email-history.collection.ts +66 -0
- package/src/collections/email-verified.collection.ts +61 -0
- package/src/collections/file.collection.ts +73 -0
- package/src/collections/flag.collection.ts +56 -0
- package/src/collections/log-method-latency.collection.ts +64 -0
- package/src/collections/log-subscription.collection.ts +68 -0
- package/src/collections/log-ts.collection.ts +78 -0
- package/src/collections/log.collection.ts +77 -0
- package/src/collections/logged-in-users.collection.ts +65 -0
- package/src/collections/method-response.collection.ts +66 -0
- package/src/collections/monitor-cpu.collection.ts +63 -0
- package/src/collections/monitor-memory.collection.ts +75 -0
- package/src/collections/monitor-mongo.collection.ts +69 -0
- package/src/collections/notification.collection.ts +51 -0
- package/src/collections/report-builder-dashboard-builder.collection.ts +109 -0
- package/src/collections/report-builder-library.collection.ts +89 -0
- package/src/collections/report-builder-report.collection.ts +149 -0
- package/src/collections/user-group.collection.ts +90 -0
- package/src/collections/user-guide.collection.ts +57 -0
- package/src/collections/user.collection.ts +259 -0
- package/src/cron/cron.ts +188 -0
- package/src/fixtures/cron-jobs.ts +25 -0
- package/src/fixtures/init.ts +10 -0
- package/src/http/auth.ts +732 -0
- package/src/http/health.ts +7 -0
- package/src/http/home.ts +71 -0
- package/src/index.ts +71 -0
- package/src/managers/cron.manager.ts +208 -0
- package/src/managers/method.manager.ts +607 -0
- package/src/managers/mongo.manager.ts +2282 -0
- package/src/managers/monitor.manager.ts +323 -0
- package/src/managers/subscription.manager.ts +1196 -0
- package/{managers/subscription.performance.js → src/managers/subscription.performance.ts} +68 -33
- package/src/methods/accounts.ts +202 -0
- package/src/methods/aws.ts +507 -0
- package/src/methods/collections.ts +512 -0
- package/src/methods/counters.ts +75 -0
- package/src/methods/cron-jobs.ts +1454 -0
- package/src/methods/flags.ts +7 -0
- package/src/methods/logs.ts +327 -0
- package/src/methods/monitor.ts +548 -0
- package/src/methods/pdf.ts +615 -0
- package/src/methods/report-builder.ts +876 -0
- package/src/methods/support.ts +146 -0
- package/{models/app-status.model.d.ts → src/models/app-status.model.ts} +3 -2
- package/{models/billing-logged-in-users.model.d.ts → src/models/billing-logged-in-users.model.ts} +5 -4
- package/src/models/collection-document.model.ts +22 -0
- package/{models/counter.model.d.ts → src/models/counter.model.ts} +4 -3
- package/src/models/cron-job-history.model.ts +13 -0
- package/src/models/cron-job.model.ts +14 -0
- package/src/models/dialog.model.ts +25 -0
- package/{models/email-history.model.d.ts → src/models/email-history.model.ts} +8 -7
- package/{models/email-verified.model.d.ts → src/models/email-verified.model.ts} +6 -5
- package/{models/file.model.d.ts → src/models/file.model.ts} +8 -7
- package/{models/flag.model.d.ts → src/models/flag.model.ts} +4 -3
- package/{models/log-method-latency.model.d.ts → src/models/log-method-latency.model.ts} +5 -4
- package/{models/log-subscription.model.d.ts → src/models/log-subscription.model.ts} +8 -6
- package/{models/log.model.d.ts → src/models/log.model.ts} +12 -10
- package/{models/logged-in-users.model.d.ts → src/models/logged-in-users.model.ts} +6 -5
- package/{models/method-response.model.d.ts → src/models/method-response.model.ts} +7 -6
- package/src/models/method.model.ts +11 -0
- package/{models/monitor-cpu.model.d.ts → src/models/monitor-cpu.model.ts} +9 -7
- package/src/models/monitor-memory.model.ts +17 -0
- package/src/models/monitor-mongo.model.ts +15 -0
- package/{models/notification.model.d.ts → src/models/notification.model.ts} +3 -2
- package/src/models/pagination.model.ts +30 -0
- package/src/models/permission.model.ts +14 -0
- package/src/models/report-builder-dashboard-builder.model.ts +29 -0
- package/src/models/report-builder-library.model.ts +20 -0
- package/src/models/report-builder-report.model.ts +110 -0
- package/src/models/report-builder.model.ts +68 -0
- package/src/models/select-data-label.model.ts +9 -0
- package/src/models/server-response.model.ts +5 -0
- package/src/models/subscription.model.ts +64 -0
- package/src/models/support-ticket.model.ts +81 -0
- package/src/models/user-group.model.ts +23 -0
- package/{models/user-guide.model.d.ts → src/models/user-guide.model.ts} +5 -4
- package/src/models/user.model.ts +79 -0
- package/{public_api.d.ts → src/public_api.ts} +1 -1
- package/src/publications/app-status.ts +13 -0
- package/src/publications/cron-jobs.ts +30 -0
- package/src/publications/files.ts +34 -0
- package/src/publications/flags.ts +20 -0
- package/src/publications/logs.ts +164 -0
- package/src/publications/method-responses.ts +13 -0
- package/src/publications/notifications.ts +13 -0
- package/src/publications/report-builder-dashboard-builders.ts +39 -0
- package/src/publications/report-builder-libraries.ts +41 -0
- package/src/publications/report-builder-reports.ts +48 -0
- package/src/publications/super-admin.ts +13 -0
- package/src/publications/user-groups.ts +12 -0
- package/src/publications/user-guides.ts +12 -0
- package/src/server-app.ts +769 -0
- package/src/util/common.ts +519 -0
- package/src/util/schema-report-builder.ts +413 -0
- package/tsconfig.json +30 -0
- package/tslint.json +143 -0
- package/client-server-app.d.ts +0 -1
- package/client-server-app.js +0 -48
- package/client-server-app.js.map +0 -1
- package/collections/app-status.collection.d.ts +0 -3
- package/collections/app-status.collection.js +0 -51
- package/collections/app-status.collection.js.map +0 -1
- package/collections/counter.collection.d.ts +0 -3
- package/collections/counter.collection.js +0 -54
- package/collections/counter.collection.js.map +0 -1
- package/collections/cron-job-history.collection.d.ts +0 -3
- package/collections/cron-job-history.collection.js +0 -82
- package/collections/cron-job-history.collection.js.map +0 -1
- package/collections/cron-job.collection.d.ts +0 -3
- package/collections/cron-job.collection.js +0 -85
- package/collections/cron-job.collection.js.map +0 -1
- package/collections/email-history.collection.d.ts +0 -3
- package/collections/email-history.collection.js +0 -66
- package/collections/email-history.collection.js.map +0 -1
- package/collections/email-verified.collection.d.ts +0 -3
- package/collections/email-verified.collection.js +0 -61
- package/collections/email-verified.collection.js.map +0 -1
- package/collections/file.collection.d.ts +0 -3
- package/collections/file.collection.js +0 -73
- package/collections/file.collection.js.map +0 -1
- package/collections/flag.collection.d.ts +0 -3
- package/collections/flag.collection.js +0 -56
- package/collections/flag.collection.js.map +0 -1
- package/collections/log-method-latency.collection.d.ts +0 -3
- package/collections/log-method-latency.collection.js +0 -64
- package/collections/log-method-latency.collection.js.map +0 -1
- package/collections/log-subscription.collection.d.ts +0 -3
- package/collections/log-subscription.collection.js +0 -68
- package/collections/log-subscription.collection.js.map +0 -1
- package/collections/log-ts.collection.d.ts +0 -3
- package/collections/log-ts.collection.js +0 -78
- package/collections/log-ts.collection.js.map +0 -1
- package/collections/log.collection.d.ts +0 -3
- package/collections/log.collection.js +0 -77
- package/collections/log.collection.js.map +0 -1
- package/collections/logged-in-users.collection.d.ts +0 -3
- package/collections/logged-in-users.collection.js +0 -65
- package/collections/logged-in-users.collection.js.map +0 -1
- package/collections/method-response.collection.d.ts +0 -3
- package/collections/method-response.collection.js +0 -66
- package/collections/method-response.collection.js.map +0 -1
- package/collections/monitor-cpu.collection.d.ts +0 -3
- package/collections/monitor-cpu.collection.js +0 -63
- package/collections/monitor-cpu.collection.js.map +0 -1
- package/collections/monitor-memory.collection.d.ts +0 -3
- package/collections/monitor-memory.collection.js +0 -75
- package/collections/monitor-memory.collection.js.map +0 -1
- package/collections/monitor-mongo.collection.d.ts +0 -3
- package/collections/monitor-mongo.collection.js +0 -69
- package/collections/monitor-mongo.collection.js.map +0 -1
- package/collections/notification.collection.d.ts +0 -3
- package/collections/notification.collection.js +0 -51
- package/collections/notification.collection.js.map +0 -1
- package/collections/report-builder-dashboard-builder.collection.d.ts +0 -3
- package/collections/report-builder-dashboard-builder.collection.js +0 -109
- package/collections/report-builder-dashboard-builder.collection.js.map +0 -1
- package/collections/report-builder-library.collection.d.ts +0 -3
- package/collections/report-builder-library.collection.js +0 -87
- package/collections/report-builder-library.collection.js.map +0 -1
- package/collections/report-builder-report.collection.d.ts +0 -4
- package/collections/report-builder-report.collection.js +0 -149
- package/collections/report-builder-report.collection.js.map +0 -1
- package/collections/user-group.collection.d.ts +0 -4
- package/collections/user-group.collection.js +0 -90
- package/collections/user-group.collection.js.map +0 -1
- package/collections/user-guide.collection.d.ts +0 -3
- package/collections/user-guide.collection.js +0 -57
- package/collections/user-guide.collection.js.map +0 -1
- package/collections/user.collection.d.ts +0 -4
- package/collections/user.collection.js +0 -259
- package/collections/user.collection.js.map +0 -1
- package/cron/cron.d.ts +0 -5
- package/cron/cron.js +0 -162
- package/cron/cron.js.map +0 -1
- package/fixtures/cron-jobs.d.ts +0 -1
- package/fixtures/cron-jobs.js +0 -73
- package/fixtures/cron-jobs.js.map +0 -1
- package/fixtures/init.d.ts +0 -1
- package/fixtures/init.js +0 -59
- package/fixtures/init.js.map +0 -1
- package/http/auth.d.ts +0 -2
- package/http/auth.js +0 -763
- package/http/auth.js.map +0 -1
- package/http/health.d.ts +0 -1
- package/http/health.js +0 -12
- package/http/health.js.map +0 -1
- package/http/home.d.ts +0 -2
- package/http/home.js +0 -66
- package/http/home.js.map +0 -1
- package/index.d.ts +0 -23
- package/index.js +0 -127
- package/index.js.map +0 -1
- package/managers/cron.manager.d.ts +0 -17
- package/managers/cron.manager.js +0 -242
- package/managers/cron.manager.js.map +0 -1
- package/managers/method.manager.d.ts +0 -38
- package/managers/method.manager.js +0 -595
- package/managers/method.manager.js.map +0 -1
- package/managers/mongo.manager.d.ts +0 -178
- package/managers/mongo.manager.js +0 -2221
- package/managers/mongo.manager.js.map +0 -1
- package/managers/monitor.manager.d.ts +0 -59
- package/managers/monitor.manager.js +0 -351
- package/managers/monitor.manager.js.map +0 -1
- package/managers/subscription.manager.d.ts +0 -50
- package/managers/subscription.manager.js +0 -1091
- package/managers/subscription.manager.js.map +0 -1
- package/managers/subscription.performance.d.ts +0 -1
- package/managers/subscription.performance.js.map +0 -1
- package/methods/accounts.d.ts +0 -2
- package/methods/accounts.js +0 -274
- package/methods/accounts.js.map +0 -1
- package/methods/aws.d.ts +0 -2
- package/methods/aws.js +0 -617
- package/methods/aws.js.map +0 -1
- package/methods/collections.d.ts +0 -2
- package/methods/collections.js +0 -499
- package/methods/collections.js.map +0 -1
- package/methods/counters.d.ts +0 -2
- package/methods/counters.js +0 -122
- package/methods/counters.js.map +0 -1
- package/methods/cron-jobs.d.ts +0 -2
- package/methods/cron-jobs.js +0 -1315
- package/methods/cron-jobs.js.map +0 -1
- package/methods/flags.d.ts +0 -2
- package/methods/flags.js +0 -9
- package/methods/flags.js.map +0 -1
- package/methods/logs.d.ts +0 -2
- package/methods/logs.js +0 -371
- package/methods/logs.js.map +0 -1
- package/methods/monitor.d.ts +0 -2
- package/methods/monitor.js +0 -565
- package/methods/monitor.js.map +0 -1
- package/methods/pdf.d.ts +0 -2
- package/methods/pdf.js +0 -324
- package/methods/pdf.js.map +0 -1
- package/methods/report-builder.d.ts +0 -2
- package/methods/report-builder.js +0 -858
- package/methods/report-builder.js.map +0 -1
- package/methods/support.d.ts +0 -2
- package/methods/support.js +0 -246
- package/methods/support.js.map +0 -1
- package/models/app-status.model.js +0 -4
- package/models/app-status.model.js.map +0 -1
- package/models/billing-logged-in-users.model.js +0 -4
- package/models/billing-logged-in-users.model.js.map +0 -1
- package/models/collection-document.model.d.ts +0 -19
- package/models/collection-document.model.js +0 -4
- package/models/collection-document.model.js.map +0 -1
- package/models/counter.model.js +0 -4
- package/models/counter.model.js.map +0 -1
- package/models/cron-job-history.model.d.ts +0 -12
- package/models/cron-job-history.model.js +0 -4
- package/models/cron-job-history.model.js.map +0 -1
- package/models/cron-job.model.d.ts +0 -13
- package/models/cron-job.model.js +0 -4
- package/models/cron-job.model.js.map +0 -1
- package/models/dialog.model.d.ts +0 -23
- package/models/dialog.model.js +0 -4
- package/models/dialog.model.js.map +0 -1
- package/models/email-history.model.js +0 -4
- package/models/email-history.model.js.map +0 -1
- package/models/email-verified.model.js +0 -4
- package/models/email-verified.model.js.map +0 -1
- package/models/file.model.js +0 -4
- package/models/file.model.js.map +0 -1
- package/models/flag.model.js +0 -4
- package/models/flag.model.js.map +0 -1
- package/models/log-method-latency.model.js +0 -4
- package/models/log-method-latency.model.js.map +0 -1
- package/models/log-subscription.model.js +0 -4
- package/models/log-subscription.model.js.map +0 -1
- package/models/log.model.js +0 -4
- package/models/log.model.js.map +0 -1
- package/models/logged-in-users.model.js +0 -4
- package/models/logged-in-users.model.js.map +0 -1
- package/models/method-response.model.js +0 -4
- package/models/method-response.model.js.map +0 -1
- package/models/method.model.d.ts +0 -9
- package/models/method.model.js +0 -4
- package/models/method.model.js.map +0 -1
- package/models/monitor-cpu.model.js +0 -4
- package/models/monitor-cpu.model.js.map +0 -1
- package/models/monitor-memory.model.d.ts +0 -15
- package/models/monitor-memory.model.js +0 -4
- package/models/monitor-memory.model.js.map +0 -1
- package/models/monitor-mongo.model.d.ts +0 -13
- package/models/monitor-mongo.model.js +0 -4
- package/models/monitor-mongo.model.js.map +0 -1
- package/models/notification.model.js +0 -4
- package/models/notification.model.js.map +0 -1
- package/models/pagination.model.d.ts +0 -10
- package/models/pagination.model.js +0 -24
- package/models/pagination.model.js.map +0 -1
- package/models/permission.model.d.ts +0 -12
- package/models/permission.model.js +0 -4
- package/models/permission.model.js.map +0 -1
- package/models/report-builder-dashboard-builder.model.d.ts +0 -25
- package/models/report-builder-dashboard-builder.model.js +0 -4
- package/models/report-builder-dashboard-builder.model.js.map +0 -1
- package/models/report-builder-library.model.d.ts +0 -17
- package/models/report-builder-library.model.js +0 -4
- package/models/report-builder-library.model.js.map +0 -1
- package/models/report-builder-report.model.d.ts +0 -98
- package/models/report-builder-report.model.js +0 -4
- package/models/report-builder-report.model.js.map +0 -1
- package/models/report-builder.model.d.ts +0 -61
- package/models/report-builder.model.js +0 -4
- package/models/report-builder.model.js.map +0 -1
- package/models/select-data-label.model.d.ts +0 -9
- package/models/select-data-label.model.js +0 -4
- package/models/select-data-label.model.js.map +0 -1
- package/models/server-response.model.d.ts +0 -5
- package/models/server-response.model.js +0 -4
- package/models/server-response.model.js.map +0 -1
- package/models/subscription.model.d.ts +0 -23
- package/models/subscription.model.js +0 -4
- package/models/subscription.model.js.map +0 -1
- package/models/support-ticket.model.d.ts +0 -72
- package/models/support-ticket.model.js +0 -4
- package/models/support-ticket.model.js.map +0 -1
- package/models/user-group.model.d.ts +0 -19
- package/models/user-group.model.js +0 -4
- package/models/user-group.model.js.map +0 -1
- package/models/user-guide.model.js +0 -4
- package/models/user-guide.model.js.map +0 -1
- package/models/user.model.d.ts +0 -70
- package/models/user.model.js +0 -4
- package/models/user.model.js.map +0 -1
- package/public_api.js +0 -75
- package/public_api.js.map +0 -1
- package/publications/app-status.d.ts +0 -2
- package/publications/app-status.js +0 -17
- package/publications/app-status.js.map +0 -1
- package/publications/cron-jobs.d.ts +0 -2
- package/publications/cron-jobs.js +0 -33
- package/publications/cron-jobs.js.map +0 -1
- package/publications/files.d.ts +0 -2
- package/publications/files.js +0 -37
- package/publications/files.js.map +0 -1
- package/publications/flags.d.ts +0 -2
- package/publications/flags.js +0 -23
- package/publications/flags.js.map +0 -1
- package/publications/logs.d.ts +0 -2
- package/publications/logs.js +0 -165
- package/publications/logs.js.map +0 -1
- package/publications/method-responses.d.ts +0 -2
- package/publications/method-responses.js +0 -17
- package/publications/method-responses.js.map +0 -1
- package/publications/notifications.d.ts +0 -2
- package/publications/notifications.js +0 -17
- package/publications/notifications.js.map +0 -1
- package/publications/report-builder-dashboard-builders.d.ts +0 -2
- package/publications/report-builder-dashboard-builders.js +0 -43
- package/publications/report-builder-dashboard-builders.js.map +0 -1
- package/publications/report-builder-libraries.d.ts +0 -2
- package/publications/report-builder-libraries.js +0 -90
- package/publications/report-builder-libraries.js.map +0 -1
- package/publications/report-builder-reports.d.ts +0 -2
- package/publications/report-builder-reports.js +0 -51
- package/publications/report-builder-reports.js.map +0 -1
- package/publications/super-admin.d.ts +0 -2
- package/publications/super-admin.js +0 -17
- package/publications/super-admin.js.map +0 -1
- package/publications/user-groups.d.ts +0 -1
- package/publications/user-groups.js +0 -17
- package/publications/user-groups.js.map +0 -1
- package/publications/user-guides.d.ts +0 -1
- package/publications/user-guides.js +0 -17
- package/publications/user-guides.js.map +0 -1
- package/server-app.d.ts +0 -52
- package/server-app.js +0 -739
- package/server-app.js.map +0 -1
- package/util/common.d.ts +0 -25
- package/util/common.js +0 -524
- package/util/common.js.map +0 -1
- package/util/schema-report-builder.d.ts +0 -6
- package/util/schema-report-builder.js +0 -453
- package/util/schema-report-builder.js.map +0 -1
- /package/{private → src/private}/email-templates/enrollment.html +0 -0
- /package/{private → src/private}/email-templates/forgot-password.html +0 -0
- /package/{private → src/private}/email-templates/support-ticket-deleted.html +0 -0
- /package/{private → src/private}/email-templates/support-ticket-modified.html +0 -0
- /package/{private → src/private}/email-templates/support-ticket.html +0 -0
- /package/{private → src/private}/images/ResolveIO.png +0 -0
|
@@ -1,1091 +0,0 @@
|
|
|
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 (g && (g = 0, op[0] && (_ = 0)), _) 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
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
-
if (ar || !(i in from)) {
|
|
41
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
-
ar[i] = from[i];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
-
};
|
|
47
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.SubscriptionManager = void 0;
|
|
49
|
-
var logs_1 = require("../publications/logs");
|
|
50
|
-
var app_status_1 = require("../publications/app-status");
|
|
51
|
-
var files_1 = require("../publications/files");
|
|
52
|
-
var super_admin_1 = require("../publications/super-admin");
|
|
53
|
-
var logged_in_users_collection_1 = require("../collections/logged-in-users.collection");
|
|
54
|
-
var cron_jobs_1 = require("../publications/cron-jobs");
|
|
55
|
-
var flags_1 = require("../publications/flags");
|
|
56
|
-
var method_responses_1 = require("../publications/method-responses");
|
|
57
|
-
var index_1 = require("../index");
|
|
58
|
-
var notifications_1 = require("../publications/notifications");
|
|
59
|
-
var report_builder_reports_1 = require("../publications/report-builder-reports");
|
|
60
|
-
var report_builder_libraries_1 = require("../publications/report-builder-libraries");
|
|
61
|
-
var user_groups_1 = require("../publications/user-groups");
|
|
62
|
-
var user_guides_1 = require("../publications/user-guides");
|
|
63
|
-
var report_builder_dashboard_builders_1 = require("../publications/report-builder-dashboard-builders");
|
|
64
|
-
var mongo_manager_1 = require("./mongo.manager");
|
|
65
|
-
var common_1 = require("../util/common");
|
|
66
|
-
var NodeCache = require("node-cache");
|
|
67
|
-
var flag_collection_1 = require("../collections/flag.collection");
|
|
68
|
-
var os_1 = require("os");
|
|
69
|
-
var numCPUs = (0, os_1.cpus)().length;
|
|
70
|
-
var v8 = require('v8');
|
|
71
|
-
// interface CurrentPerformanceMonitor {
|
|
72
|
-
// _id: number;
|
|
73
|
-
// function: string;
|
|
74
|
-
// publication: string;
|
|
75
|
-
// subscriptionData: any[];
|
|
76
|
-
// date_start: Date;
|
|
77
|
-
// date_end: Date;
|
|
78
|
-
// duration: number;
|
|
79
|
-
// result: string;
|
|
80
|
-
// }
|
|
81
|
-
var SubscriptionManager = /** @class */ (function () {
|
|
82
|
-
// private currentPerfomanceMonitor: CurrentPerformanceMonitor[] = [];
|
|
83
|
-
// private idPerformance: number = 0;
|
|
84
|
-
// private performanceThread;
|
|
85
|
-
function SubscriptionManager(mainServer, wss, serverConfig, monitorManagerFunction) {
|
|
86
|
-
var _this = this;
|
|
87
|
-
this._publications = {};
|
|
88
|
-
this._subscriptions = [];
|
|
89
|
-
this._loggedInUsers = [];
|
|
90
|
-
this._mongoQueue = [];
|
|
91
|
-
this._mongoQueueId = 0;
|
|
92
|
-
this._sendQueue = [];
|
|
93
|
-
this._runningQueue = false;
|
|
94
|
-
this._cacheId = 1;
|
|
95
|
-
this._heapStats = v8.getHeapStatistics();
|
|
96
|
-
this._heapLimit = this._heapStats.heap_size_limit / numCPUs / 8;
|
|
97
|
-
this._enableDebug = false;
|
|
98
|
-
this._debugOplogCollections = [];
|
|
99
|
-
this._debugOplogHits = 0;
|
|
100
|
-
this._debugSubCollections = [];
|
|
101
|
-
this._debugSubHits = 0;
|
|
102
|
-
this._debugUnSubHits = 0;
|
|
103
|
-
this._debugUnSubAllHits = 0;
|
|
104
|
-
this._debugMongoQueueHits = 0;
|
|
105
|
-
this._debugMongoQueueCollections = [];
|
|
106
|
-
this._debugSendQueueHits = 0;
|
|
107
|
-
this._debugRemoveCacheHits = 0;
|
|
108
|
-
this._oplogRetryCount = 0;
|
|
109
|
-
this._mainServer = mainServer;
|
|
110
|
-
this._monitorManagerFunction = monitorManagerFunction;
|
|
111
|
-
this._nodeCache = new NodeCache({ stdTTL: 0, checkperiod: 0 });
|
|
112
|
-
// setTimeout(() => {
|
|
113
|
-
// console.log('Setting up performance thread');
|
|
114
|
-
// this.performanceThread = new Worker(path.join(__dirname, './subscription.performance.js'));
|
|
115
|
-
// this.performanceThread.on('exit', code => {
|
|
116
|
-
// console.error(new Date(), 'THREAD EXITED!!!!!!!!!!!!!!!!!!', code);
|
|
117
|
-
// });
|
|
118
|
-
// this.performanceThread.on('error', code => {
|
|
119
|
-
// console.error(new Date(), 'THREAD RECV ERROR !!!!!!!!!!!!!!!!!!', code);
|
|
120
|
-
// });
|
|
121
|
-
// }, 5000);
|
|
122
|
-
// setInterval(() => {
|
|
123
|
-
// console.log('Post thread msg');
|
|
124
|
-
// this.performanceThread.postMessage(this.currentPerfomanceMonitor);
|
|
125
|
-
// this.currentPerfomanceMonitor = [];
|
|
126
|
-
// }, 10000);
|
|
127
|
-
this.serverConfig = serverConfig;
|
|
128
|
-
this._wss = wss;
|
|
129
|
-
// Publications
|
|
130
|
-
(0, super_admin_1.loadSuperAdminPublications)(this);
|
|
131
|
-
(0, app_status_1.loadAppStatusPublications)(this);
|
|
132
|
-
(0, logs_1.loadLogPublications)(this);
|
|
133
|
-
(0, files_1.loadFilePublications)(this);
|
|
134
|
-
(0, cron_jobs_1.loadCronJobPublications)(this);
|
|
135
|
-
(0, flags_1.loadFlagsPublications)(this);
|
|
136
|
-
(0, method_responses_1.loadMethodResponsePublications)(this);
|
|
137
|
-
(0, notifications_1.loadNotificationPublications)(this);
|
|
138
|
-
(0, report_builder_reports_1.loadReportBuilderReportPublications)(this);
|
|
139
|
-
(0, report_builder_libraries_1.loadReportBuilderLibraryPublications)(this);
|
|
140
|
-
(0, user_groups_1.loadUserGroupPublications)(this);
|
|
141
|
-
(0, user_guides_1.loadUserGuidePublications)(this);
|
|
142
|
-
(0, report_builder_dashboard_builders_1.loadReportBuilderDashboardBuilderPublications)(this);
|
|
143
|
-
this.tailOpLog();
|
|
144
|
-
setInterval(function () {
|
|
145
|
-
_this._oplogRetryCount = 0;
|
|
146
|
-
}, 15000);
|
|
147
|
-
setInterval(function () {
|
|
148
|
-
if (_this.getEnableDebug()) {
|
|
149
|
-
console.log(new Date(), 'Sub Manager', 'Subs', _this._subscriptions.length);
|
|
150
|
-
console.log(new Date(), 'Sub Manager', 'Logged In Users', _this._loggedInUsers.length);
|
|
151
|
-
console.log(new Date(), 'Sub Manager', 'Mongo Queue', _this._mongoQueue.length);
|
|
152
|
-
console.log(new Date(), 'Sub Manager', 'Mongo Queue Hits', _this._debugMongoQueueHits);
|
|
153
|
-
console.log(new Date(), 'Sub Manager', 'Mongo Queue Collections', JSON.stringify(_this._debugMongoQueueCollections.sort(function (a, b) { return a.collection.localeCompare(b.collection) || a.publication.localeCompare(b.publication); }), null, 2));
|
|
154
|
-
console.log(new Date(), 'Sub Manager', 'Oplog Hits', _this._debugOplogHits);
|
|
155
|
-
console.log(new Date(), 'Sub Manager', 'Oplog Collections', JSON.stringify(_this._debugOplogCollections.sort(function (a, b) { return a.collection.localeCompare(b.collection) || a.type.localeCompare(b.type); }), null, 2));
|
|
156
|
-
console.log(new Date(), 'Sub Manager', 'Send Queue Hits', _this._debugSendQueueHits);
|
|
157
|
-
console.log(new Date(), 'Sub Manager', 'Sub Hits', _this._debugSubHits);
|
|
158
|
-
console.log(new Date(), 'Sub Manager', 'Sub Collections', JSON.stringify(_this._debugSubCollections.sort(function (a, b) { return a.publication.localeCompare(b.publication); }), null, 2));
|
|
159
|
-
console.log(new Date(), 'Sub Manager', 'Unsub Hits', _this._debugUnSubHits);
|
|
160
|
-
console.log(new Date(), 'Sub Manager', 'Unsub All Hits', _this._debugUnSubAllHits);
|
|
161
|
-
console.log(new Date(), 'Sub Manager', 'Cache Cleanup Hits', _this._debugRemoveCacheHits);
|
|
162
|
-
}
|
|
163
|
-
_this._debugOplogHits = 0;
|
|
164
|
-
_this._debugOplogCollections = [];
|
|
165
|
-
_this._debugSubCollections = [];
|
|
166
|
-
_this._debugMongoQueueHits = 0;
|
|
167
|
-
_this._debugMongoQueueCollections = [];
|
|
168
|
-
_this._debugSendQueueHits = 0;
|
|
169
|
-
_this._debugSubHits = 0;
|
|
170
|
-
_this._debugUnSubHits = 0;
|
|
171
|
-
_this._debugUnSubAllHits = 0;
|
|
172
|
-
_this._debugRemoveCacheHits = 0;
|
|
173
|
-
}, 60000);
|
|
174
|
-
setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
175
|
-
var _loop_1, this_1, i, queueArr, _loop_2, this_2, i;
|
|
176
|
-
var _this = this;
|
|
177
|
-
return __generator(this, function (_a) {
|
|
178
|
-
if (!this._runningQueue) {
|
|
179
|
-
this._runningQueue = true;
|
|
180
|
-
if (this._sendQueue.length) {
|
|
181
|
-
_loop_1 = function (i) {
|
|
182
|
-
this_1._debugSendQueueHits += 1;
|
|
183
|
-
var ws = this_1._mainServer.getWS(this_1._sendQueue[i].id_ws);
|
|
184
|
-
if (ws && ws.readyState === ws.OPEN) {
|
|
185
|
-
if (ws.bufferedAmount < 20480) {
|
|
186
|
-
var sendItem = this_1._sendQueue.pop();
|
|
187
|
-
ws.send(JSON.stringify(sendItem.data), function (error) {
|
|
188
|
-
if (error) {
|
|
189
|
-
console.log('Error on WS: ', error);
|
|
190
|
-
if (_this.getEnableDebug()) {
|
|
191
|
-
console.log(new Date(), 'Sub Manager', 'Unsub WS', ws['user'], ws['id_socket'], 1);
|
|
192
|
-
}
|
|
193
|
-
_this.unsubscribeAll(ws);
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
this_1._sendQueue.splice(i, 1);
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
this_1 = this;
|
|
203
|
-
// let startDate = new Date();
|
|
204
|
-
for (i = this._sendQueue.length - 1; i >= 0; i--) {
|
|
205
|
-
_loop_1(i);
|
|
206
|
-
}
|
|
207
|
-
// let endDate = new Date();
|
|
208
|
-
// this.currentPerfomanceMonitor.push({
|
|
209
|
-
// _id: this.idPerformance++,
|
|
210
|
-
// function: 'sendInterval',
|
|
211
|
-
// publication: '',
|
|
212
|
-
// subscriptionData: [],
|
|
213
|
-
// date_start: startDate,
|
|
214
|
-
// date_end: endDate,
|
|
215
|
-
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
216
|
-
// result: 'Done'
|
|
217
|
-
// });
|
|
218
|
-
}
|
|
219
|
-
queueArr = this._mongoQueue.filter(function (a) { return !a.running; });
|
|
220
|
-
if (queueArr.length) {
|
|
221
|
-
queueArr.forEach(function (entry) {
|
|
222
|
-
entry.running = true;
|
|
223
|
-
});
|
|
224
|
-
_loop_2 = function (i) {
|
|
225
|
-
this_2._debugMongoQueueHits += 1;
|
|
226
|
-
var mongoQueue = queueArr[i];
|
|
227
|
-
if (!this_2._debugMongoQueueCollections.some(function (a) { return a.collection === mongoQueue.collection && a.publication === mongoQueue.subscription.publication; })) {
|
|
228
|
-
this_2._debugMongoQueueCollections.push({
|
|
229
|
-
collection: mongoQueue.collection,
|
|
230
|
-
publication: mongoQueue.subscription.publication,
|
|
231
|
-
hits: 1
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
this_2._debugMongoQueueCollections.filter(function (a) { return a.collection === mongoQueue.collection && a.publication === mongoQueue.subscription.publication; })[0].hits += 1;
|
|
236
|
-
}
|
|
237
|
-
if (this_2._publications[mongoQueue.subscription.publication].user_specific) {
|
|
238
|
-
var promises = [];
|
|
239
|
-
var _loop_3 = function (j) {
|
|
240
|
-
var client = mongoQueue.subscription.clients[j];
|
|
241
|
-
var ws = this_2._mainServer.getWS(client.id_socket);
|
|
242
|
-
if (ws && ws['id_socket'] === client.id_socket) {
|
|
243
|
-
promises.push(this_2.sendDataToOne(ws, client.messageId, mongoQueue.subscription, mongoQueue.type, mongoQueue.collection).catch(function (err) {
|
|
244
|
-
_this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + _this.serverConfig['CLIENT_NAME'], 'Error Detected During sendDataToOne - User Specific - Socket: ' + client.id_socket + ', User: ' + client.id_user + ', MessageId: ' + client.messageId + ', Pub: ' + mongoQueue.subscription.publication + ', Err: ' + JSON.stringify(err, null, 2));
|
|
245
|
-
return null;
|
|
246
|
-
}));
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
for (var j = 0; j < mongoQueue.subscription.clients.length; j++) {
|
|
250
|
-
_loop_3(j);
|
|
251
|
-
}
|
|
252
|
-
Promise.all(promises).then(function () {
|
|
253
|
-
if (mongoQueue.run_again) {
|
|
254
|
-
mongoQueue.running = false;
|
|
255
|
-
mongoQueue.run_again = false;
|
|
256
|
-
}
|
|
257
|
-
else {
|
|
258
|
-
if (_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id) >= 0) {
|
|
259
|
-
_this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id), 1);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
else {
|
|
265
|
-
this_2.sendDataToAll(mongoQueue).then(function () {
|
|
266
|
-
if (mongoQueue.run_again) {
|
|
267
|
-
mongoQueue.running = false;
|
|
268
|
-
mongoQueue.run_again = false;
|
|
269
|
-
}
|
|
270
|
-
else {
|
|
271
|
-
if (_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id) >= 0) {
|
|
272
|
-
_this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id), 1);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}, function () {
|
|
276
|
-
if (_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id) >= 0) {
|
|
277
|
-
_this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id), 1);
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
this_2 = this;
|
|
283
|
-
for (i = queueArr.length - 1; i >= 0; i--) {
|
|
284
|
-
_loop_2(i);
|
|
285
|
-
}
|
|
286
|
-
// let endDate = new Date();
|
|
287
|
-
// this.currentPerfomanceMonitor.push({
|
|
288
|
-
// _id: this.idPerformance++,
|
|
289
|
-
// function: 'mongoQueue',
|
|
290
|
-
// publication: '',
|
|
291
|
-
// subscriptionData: [],
|
|
292
|
-
// date_start: startDate,
|
|
293
|
-
// date_end: endDate,
|
|
294
|
-
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
295
|
-
// result: 'Done'
|
|
296
|
-
// });
|
|
297
|
-
}
|
|
298
|
-
this._runningQueue = false;
|
|
299
|
-
}
|
|
300
|
-
return [2 /*return*/];
|
|
301
|
-
});
|
|
302
|
-
}); }, 25);
|
|
303
|
-
setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
304
|
-
var _a, userCopy, _loop_4, this_3, i, i, sub, _loop_5, this_4, j;
|
|
305
|
-
return __generator(this, function (_b) {
|
|
306
|
-
switch (_b.label) {
|
|
307
|
-
case 0:
|
|
308
|
-
_a = this;
|
|
309
|
-
return [4 /*yield*/, logged_in_users_collection_1.LoggedInUsers.find()];
|
|
310
|
-
case 1:
|
|
311
|
-
_a._loggedInUsers = _b.sent();
|
|
312
|
-
userCopy = (0, common_1.deepCopy)(this._loggedInUsers);
|
|
313
|
-
_loop_4 = function (i) {
|
|
314
|
-
var loggedInUser = userCopy[i];
|
|
315
|
-
if (!loggedInUser.date || Date.now() - loggedInUser.date.getTime() > 120000) {
|
|
316
|
-
if (this_3._mainServer.getWS(loggedInUser.id_ws)) {
|
|
317
|
-
if (this_3.getEnableDebug()) {
|
|
318
|
-
console.log(new Date(), 'Sub Manager', 'Unsub WS', this_3._mainServer.getWS(loggedInUser.id_ws)['user'], this_3._mainServer.getWS(loggedInUser.id_ws)['id_socket'], 2);
|
|
319
|
-
}
|
|
320
|
-
this_3.unsubscribeAll(this_3._mainServer.getWS(loggedInUser.id_ws));
|
|
321
|
-
}
|
|
322
|
-
else {
|
|
323
|
-
this_3._subscriptions.forEach(function (sub) {
|
|
324
|
-
for (var j = sub.clients.length - 1; j >= 0; j--) {
|
|
325
|
-
var client = sub.clients[j];
|
|
326
|
-
if (client.id_socket === loggedInUser.id_ws) {
|
|
327
|
-
sub.clients.splice(j, 1);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
});
|
|
331
|
-
logged_in_users_collection_1.LoggedInUsers.deleteOne({ _id: loggedInUser._id });
|
|
332
|
-
if (this_3._loggedInUsers.findIndex(function (a) { return a._id === loggedInUser._id; }) >= 0) {
|
|
333
|
-
this_3._loggedInUsers.splice(this_3._loggedInUsers.findIndex(function (a) { return a._id === loggedInUser._id; }), 1);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
};
|
|
338
|
-
this_3 = this;
|
|
339
|
-
for (i = this._loggedInUsers.length - 1; i >= 0; i--) {
|
|
340
|
-
_loop_4(i);
|
|
341
|
-
}
|
|
342
|
-
for (i = 0; i < this._subscriptions.length; i++) {
|
|
343
|
-
sub = this._subscriptions[i];
|
|
344
|
-
_loop_5 = function (j) {
|
|
345
|
-
var client = sub.clients[j];
|
|
346
|
-
if (!this_4._loggedInUsers.some(function (a) { return a.id_ws === client.id_socket; })) {
|
|
347
|
-
sub.clients.splice(j, 1);
|
|
348
|
-
}
|
|
349
|
-
};
|
|
350
|
-
this_4 = this;
|
|
351
|
-
for (j = sub.clients.length - 1; j >= 0; j--) {
|
|
352
|
-
_loop_5(j);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
return [2 /*return*/];
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
}); }, 30000);
|
|
359
|
-
flag_collection_1.Flags.findOne({ type: 'Enable Debug' }).then(function (flag) {
|
|
360
|
-
if (flag && flag.value) {
|
|
361
|
-
_this._enableDebug = true;
|
|
362
|
-
}
|
|
363
|
-
else {
|
|
364
|
-
_this._enableDebug = false;
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
SubscriptionManager.prototype.addToQueue = function (mongoQueue) {
|
|
369
|
-
// let startDate = new Date();
|
|
370
|
-
var _mongoQueue = this._mongoQueue.filter(function (a) { return a.subscription.publication === mongoQueue.subscription.publication && JSON.stringify(a.subscription.subscriptionData) === JSON.stringify(mongoQueue.subscription.subscriptionData); })[0];
|
|
371
|
-
if (_mongoQueue) {
|
|
372
|
-
if (_mongoQueue.running) {
|
|
373
|
-
_mongoQueue.run_again = true;
|
|
374
|
-
// let endDate = new Date();
|
|
375
|
-
// this.currentPerfomanceMonitor.push({
|
|
376
|
-
// _id: this.idPerformance++,
|
|
377
|
-
// function: 'addToQueue',
|
|
378
|
-
// publication: mongoQueue.subscription.publication,
|
|
379
|
-
// // subscriptionData: mongoQueue.subscription.subscriptionData,
|
|
380
|
-
// subscriptionData: [],
|
|
381
|
-
// date_start: startDate,
|
|
382
|
-
// date_end: endDate,
|
|
383
|
-
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
384
|
-
// result: 'Run Again'
|
|
385
|
-
// });
|
|
386
|
-
}
|
|
387
|
-
// else {
|
|
388
|
-
// let endDate = new Date();
|
|
389
|
-
// this.currentPerfomanceMonitor.push({
|
|
390
|
-
// _id: this.idPerformance++,
|
|
391
|
-
// function: 'addToQueue',
|
|
392
|
-
// publication: mongoQueue.subscription.publication,
|
|
393
|
-
// // subscriptionData: mongoQueue.subscription.subscriptionData,
|
|
394
|
-
// subscriptionData: [],
|
|
395
|
-
// date_start: startDate,
|
|
396
|
-
// date_end: endDate,
|
|
397
|
-
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
398
|
-
// result: 'Not Running Yet'
|
|
399
|
-
// });
|
|
400
|
-
// }
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
mongoQueue._id = this._mongoQueueId;
|
|
404
|
-
this._mongoQueueId += 1;
|
|
405
|
-
this._mongoQueue.splice(0, 0, mongoQueue);
|
|
406
|
-
// let endDate = new Date();
|
|
407
|
-
// this.currentPerfomanceMonitor.push({
|
|
408
|
-
// _id: this.idPerformance++,
|
|
409
|
-
// function: 'addToQueue',
|
|
410
|
-
// publication: mongoQueue.subscription.publication,
|
|
411
|
-
// // subscriptionData: mongoQueue.subscription.subscriptionData,
|
|
412
|
-
// subscriptionData: [],
|
|
413
|
-
// date_start: startDate,
|
|
414
|
-
// date_end: endDate,
|
|
415
|
-
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
416
|
-
// result: 'Add to Queue'
|
|
417
|
-
// });
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
SubscriptionManager.prototype.invalidatePubsCache = function (collection, type) {
|
|
421
|
-
// let startDate = new Date();
|
|
422
|
-
index_1.ResolveIOServer.getMongoManager().invalidateQueryCache(collection);
|
|
423
|
-
var collSubs = this._subscriptions.filter(function (a) { return a.collections.includes(collection); });
|
|
424
|
-
for (var i = collSubs.length - 1; i >= 0; i--) {
|
|
425
|
-
var sub = collSubs[i];
|
|
426
|
-
this.addToQueue({
|
|
427
|
-
_id: 0,
|
|
428
|
-
type: type,
|
|
429
|
-
collection: collection,
|
|
430
|
-
subscription: sub,
|
|
431
|
-
running: false,
|
|
432
|
-
run_again: false
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
// let endDate = new Date();
|
|
436
|
-
// this.currentPerfomanceMonitor.push({
|
|
437
|
-
// _id: this.idPerformance++,
|
|
438
|
-
// function: 'invalidatePubsCache',
|
|
439
|
-
// publication: collection,
|
|
440
|
-
// subscriptionData: [],
|
|
441
|
-
// date_start: startDate,
|
|
442
|
-
// date_end: endDate,
|
|
443
|
-
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
444
|
-
// result: 'Done'
|
|
445
|
-
// });
|
|
446
|
-
};
|
|
447
|
-
// Add all files to publications private object
|
|
448
|
-
SubscriptionManager.prototype.publications = function (method) {
|
|
449
|
-
this._publications = Object.assign(this._publications, method);
|
|
450
|
-
};
|
|
451
|
-
SubscriptionManager.prototype.loggedInLatency = function (ws) {
|
|
452
|
-
var _this = this;
|
|
453
|
-
var loggedInUser = this._loggedInUsers.filter(function (a) { return a.id_ws === ws['id_socket']; })[0];
|
|
454
|
-
if (loggedInUser) {
|
|
455
|
-
loggedInUser.date = new Date();
|
|
456
|
-
logged_in_users_collection_1.LoggedInUsers.updateOne({ id_ws: ws['id_socket'] }, { $set: { latency: ws['latency'], date: loggedInUser.date } }).then(function (res) {
|
|
457
|
-
if (!res) {
|
|
458
|
-
_this.unsubscribeAll(ws);
|
|
459
|
-
if (_this.getEnableDebug()) {
|
|
460
|
-
console.log(new Date(), 'Sub Manager', 'Unsub WS', ws['user'], ws['id_socket'], 3);
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
}, function () {
|
|
464
|
-
_this.unsubscribeAll(ws);
|
|
465
|
-
if (_this.getEnableDebug()) {
|
|
466
|
-
console.log(new Date(), 'Sub Manager', 'Unsub WS', ws['user'], ws['id_socket'], 4);
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
};
|
|
471
|
-
// Subscribe to publication
|
|
472
|
-
SubscriptionManager.prototype.subscribe = function (messageRoute, messageDate, ws, messageId, publication, subscriptionData) {
|
|
473
|
-
var _this = this;
|
|
474
|
-
// let startDate = new Date();
|
|
475
|
-
this._debugSubHits += 1;
|
|
476
|
-
if (!this._debugSubCollections.some(function (a) { return a.publication === publication; })) {
|
|
477
|
-
this._debugSubCollections.push({
|
|
478
|
-
publication: publication,
|
|
479
|
-
hits: 1
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
else {
|
|
483
|
-
this._debugSubCollections.filter(function (a) { return a.publication === publication; })[0].hits += 1;
|
|
484
|
-
}
|
|
485
|
-
var pub = this._publications[publication];
|
|
486
|
-
if (!pub) {
|
|
487
|
-
console.error(new Date(), 'No Publication: ' + publication);
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
else {
|
|
491
|
-
if (subscriptionData.length > 1 || subscriptionData[0]) {
|
|
492
|
-
if (!pub.check) {
|
|
493
|
-
console.error(new Date(), 'No Check Function For Pub ' + publication);
|
|
494
|
-
return;
|
|
495
|
-
}
|
|
496
|
-
else if (!pub.check._schema) {
|
|
497
|
-
console.error(new Date(), 'No Check Schema For Pub ' + publication);
|
|
498
|
-
return;
|
|
499
|
-
}
|
|
500
|
-
else {
|
|
501
|
-
var valObj = {};
|
|
502
|
-
var valKeys = Object.keys(pub.check._schema);
|
|
503
|
-
var rootKeys = valKeys.filter(function (a) { return !a.includes('.'); });
|
|
504
|
-
for (var i = 0; i < subscriptionData.length; i++) {
|
|
505
|
-
valObj[rootKeys[i]] = subscriptionData[i];
|
|
506
|
-
}
|
|
507
|
-
try {
|
|
508
|
-
pub.check.validate(valObj);
|
|
509
|
-
}
|
|
510
|
-
catch (errors) {
|
|
511
|
-
if (errors) {
|
|
512
|
-
console.error(new Date(), 'Error in Pub Check (' + publication + ')', errors);
|
|
513
|
-
return;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
if (messageRoute !== 'Bypass') {
|
|
519
|
-
var urlData = messageRoute.split('/');
|
|
520
|
-
var urlModule_1 = '';
|
|
521
|
-
var urlNext = urlData[0];
|
|
522
|
-
if (urlData[0] === '') {
|
|
523
|
-
urlModule_1 = '/';
|
|
524
|
-
urlNext = urlData[1];
|
|
525
|
-
}
|
|
526
|
-
urlModule_1 += urlNext;
|
|
527
|
-
if (urlData.length > 1) {
|
|
528
|
-
urlModule_1 += '/';
|
|
529
|
-
}
|
|
530
|
-
var otherRouteSubs = this._subscriptions.filter(function (a) { return a.clients.some(function (b) { return b.id_socket === ws['id_socket'] && b.messageRoute !== 'Bypass' && b.messageRoute !== '/' && b.messageRoute !== messageRoute && !b.messageRoute.startsWith(urlModule_1); }); });
|
|
531
|
-
if (otherRouteSubs.length) {
|
|
532
|
-
this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Detected Undestroyed Subscription - ' + this.serverConfig['CLIENT_NAME'], 'USER: ' + ws['user'] + ' (Socket: ' + ws['id_socket'] + ') ' + ' is on route: ' + messageRoute + ' but has the following subscriptions on other routes:' + JSON.stringify(otherRouteSubs, null, 2));
|
|
533
|
-
otherRouteSubs.forEach(function (otherSub) {
|
|
534
|
-
otherSub.clients.filter(function (a) { return a.id_socket === ws['id_socket']; }).forEach(function (client) {
|
|
535
|
-
_this.unsubscribe(client.messageRoute, new Date(), ws, client.messageId, otherSub.publication, otherSub.subscriptionData);
|
|
536
|
-
});
|
|
537
|
-
});
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
var sub_1 = this._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
|
|
541
|
-
// If sub found (another user watching same data), add client to same sub
|
|
542
|
-
if (sub_1) {
|
|
543
|
-
if (!sub_1.clients.some(function (a) { return a.id_socket === ws['id_socket'] && a.messageId === messageId; })) {
|
|
544
|
-
sub_1.clients.push({
|
|
545
|
-
id_user: ws['id_user'],
|
|
546
|
-
messageId: messageId,
|
|
547
|
-
id_socket: ws['id_socket'],
|
|
548
|
-
messageRoute: messageRoute
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
// If sub not found, create new sub
|
|
553
|
-
else {
|
|
554
|
-
this._subscriptions.push({
|
|
555
|
-
publication: publication,
|
|
556
|
-
subscriptionData: subscriptionData,
|
|
557
|
-
collections: this.getPublicationCollections(publication),
|
|
558
|
-
clients: [{
|
|
559
|
-
id_user: ws['id_user'],
|
|
560
|
-
messageId: messageId,
|
|
561
|
-
id_socket: ws['id_socket'],
|
|
562
|
-
messageRoute: messageRoute
|
|
563
|
-
}],
|
|
564
|
-
cacheId: 0
|
|
565
|
-
});
|
|
566
|
-
}
|
|
567
|
-
if (!sub_1) {
|
|
568
|
-
sub_1 = this._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
|
|
569
|
-
}
|
|
570
|
-
if (!sub_1.cacheId && !this._mongoQueue.some(function (a) { return a.subscription.publication === sub_1.publication && JSON.stringify(a.subscription.subscriptionData) === JSON.stringify(sub_1.subscriptionData); })) {
|
|
571
|
-
this.addToQueue({
|
|
572
|
-
_id: 0,
|
|
573
|
-
type: 'newSub',
|
|
574
|
-
collection: '',
|
|
575
|
-
subscription: sub_1,
|
|
576
|
-
running: false,
|
|
577
|
-
run_again: false
|
|
578
|
-
});
|
|
579
|
-
// let endDate = new Date();
|
|
580
|
-
// this.currentPerfomanceMonitor.push({
|
|
581
|
-
// _id: this.idPerformance++,
|
|
582
|
-
// function: 'subscribe',
|
|
583
|
-
// publication: publication,
|
|
584
|
-
// // subscriptionData: subscriptionData,
|
|
585
|
-
// subscriptionData: [],
|
|
586
|
-
// date_start: startDate,
|
|
587
|
-
// date_end: endDate,
|
|
588
|
-
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
589
|
-
// result: 'Add to Queue'
|
|
590
|
-
// });
|
|
591
|
-
}
|
|
592
|
-
else if (sub_1.cacheId) {
|
|
593
|
-
this.sendDataToOne(ws, messageId, sub_1, 'newSub', publication);
|
|
594
|
-
// let endDate = new Date();
|
|
595
|
-
// this.currentPerfomanceMonitor.push({
|
|
596
|
-
// _id: this.idPerformance++,
|
|
597
|
-
// function: 'subscribe',
|
|
598
|
-
// publication: publication,
|
|
599
|
-
// // subscriptionData: subscriptionData,
|
|
600
|
-
// subscriptionData: [],
|
|
601
|
-
// date_start: startDate,
|
|
602
|
-
// date_end: endDate,
|
|
603
|
-
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
604
|
-
// result: 'Send Pub Data Once'
|
|
605
|
-
// });
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
};
|
|
609
|
-
SubscriptionManager.prototype.createLoggedInUser = function (id_ws) {
|
|
610
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
611
|
-
var _this = this;
|
|
612
|
-
return __generator(this, function (_a) {
|
|
613
|
-
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
614
|
-
var ws, user;
|
|
615
|
-
return __generator(this, function (_a) {
|
|
616
|
-
ws = this._mainServer.getWS(id_ws);
|
|
617
|
-
if (ws) {
|
|
618
|
-
user = {
|
|
619
|
-
_id: (0, mongo_manager_1.objectIdHexString)(),
|
|
620
|
-
__v: 0,
|
|
621
|
-
date: new Date(),
|
|
622
|
-
id_user: ws['id_user'],
|
|
623
|
-
user: ws['user'],
|
|
624
|
-
id_ws: ws['id_socket']
|
|
625
|
-
};
|
|
626
|
-
this._loggedInUsers.push(user);
|
|
627
|
-
logged_in_users_collection_1.LoggedInUsers.insertOne(user);
|
|
628
|
-
resolve(user);
|
|
629
|
-
}
|
|
630
|
-
else {
|
|
631
|
-
resolve(null);
|
|
632
|
-
}
|
|
633
|
-
return [2 /*return*/];
|
|
634
|
-
});
|
|
635
|
-
}); })];
|
|
636
|
-
});
|
|
637
|
-
});
|
|
638
|
-
};
|
|
639
|
-
// Unsubscribe from publication
|
|
640
|
-
SubscriptionManager.prototype.unsubscribe = function (messageRoute, messageDate, ws, messageId, publication, subscriptionData) {
|
|
641
|
-
this._debugUnSubHits += 1;
|
|
642
|
-
// let startDate = new Date();
|
|
643
|
-
// console.log('Before');
|
|
644
|
-
// console.dir(this._subscriptions.map(a => a.publication));
|
|
645
|
-
if (!this._publications[publication]) {
|
|
646
|
-
console.log('No Publication: ' + publication);
|
|
647
|
-
return;
|
|
648
|
-
}
|
|
649
|
-
else {
|
|
650
|
-
var sub = this._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
|
|
651
|
-
if (sub) {
|
|
652
|
-
for (var i = sub.clients.length - 1; i >= 0; i--) {
|
|
653
|
-
if (sub.clients[i].id_user === ws['id_user'] && sub.clients[i].messageId === messageId && sub.clients[i].id_socket === ws['id_socket']) {
|
|
654
|
-
sub.clients.splice(i, 1);
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
// let endDate = new Date();
|
|
660
|
-
// this.currentPerfomanceMonitor.push({
|
|
661
|
-
// _id: this.idPerformance++,
|
|
662
|
-
// function: 'unsubscribe',
|
|
663
|
-
// publication: publication,
|
|
664
|
-
// // subscriptionData: subscriptionData,
|
|
665
|
-
// subscriptionData: [],
|
|
666
|
-
// date_start: startDate,
|
|
667
|
-
// date_end: endDate,
|
|
668
|
-
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
669
|
-
// result: 'Done'
|
|
670
|
-
// });
|
|
671
|
-
};
|
|
672
|
-
// Unsubscribe from publication
|
|
673
|
-
SubscriptionManager.prototype.unsubscribeAll = function (ws) {
|
|
674
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
675
|
-
var loggedInUser, userSubs, i, sub, j;
|
|
676
|
-
return __generator(this, function (_a) {
|
|
677
|
-
switch (_a.label) {
|
|
678
|
-
case 0:
|
|
679
|
-
this._debugUnSubAllHits += 1;
|
|
680
|
-
if (!ws) return [3 /*break*/, 2];
|
|
681
|
-
return [4 /*yield*/, logged_in_users_collection_1.LoggedInUsers.findOne({ id_ws: ws['id_socket'] })];
|
|
682
|
-
case 1:
|
|
683
|
-
loggedInUser = _a.sent();
|
|
684
|
-
if (loggedInUser) {
|
|
685
|
-
if (this._loggedInUsers.map(function (a) { return a._id; }).indexOf(loggedInUser._id) >= 0) {
|
|
686
|
-
this._loggedInUsers.splice(this._loggedInUsers.map(function (a) { return a._id; }).indexOf(loggedInUser._id), 1);
|
|
687
|
-
}
|
|
688
|
-
logged_in_users_collection_1.LoggedInUsers.deleteOne({ _id: loggedInUser._id });
|
|
689
|
-
}
|
|
690
|
-
userSubs = this._subscriptions.filter(function (a) { return a.clients.some(function (b) { return b.id_user === ws['id_user'] && b.id_socket === ws['id_socket']; }); });
|
|
691
|
-
for (i = userSubs.length - 1; i >= 0; i--) {
|
|
692
|
-
sub = userSubs[i];
|
|
693
|
-
for (j = sub.clients.length - 1; j >= 0; j--) {
|
|
694
|
-
if (sub.clients[j].id_socket === ws['id_socket']) {
|
|
695
|
-
sub.clients.splice(j, 1);
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
ws.close();
|
|
700
|
-
process.nextTick(function () {
|
|
701
|
-
if ([ws.OPEN, ws.CLOSING].includes(ws.readyState)) {
|
|
702
|
-
// Socket still hangs, hard close
|
|
703
|
-
ws.terminate();
|
|
704
|
-
}
|
|
705
|
-
});
|
|
706
|
-
_a.label = 2;
|
|
707
|
-
case 2: return [2 /*return*/];
|
|
708
|
-
}
|
|
709
|
-
});
|
|
710
|
-
});
|
|
711
|
-
};
|
|
712
|
-
SubscriptionManager.prototype.getActiveSubscriptions = function () {
|
|
713
|
-
return this._subscriptions;
|
|
714
|
-
};
|
|
715
|
-
// Get publication collection
|
|
716
|
-
SubscriptionManager.prototype.getPublicationCollections = function (publication) {
|
|
717
|
-
return this._publications[publication].collections;
|
|
718
|
-
};
|
|
719
|
-
// Watch (tail) Mongo's operation log on the entire database (all insert/modify/delete will trigger this function)
|
|
720
|
-
SubscriptionManager.prototype.tailOpLog = function (resumeToken) {
|
|
721
|
-
var _this = this;
|
|
722
|
-
if (!this._oplog || this._oplog.closed) {
|
|
723
|
-
this._oplogRetryCount += 1;
|
|
724
|
-
if (this._oplogRetryCount > 10) {
|
|
725
|
-
console.error('****************** TAIL OPLOG ERROR, RETRYING A BUNCH OF TIMES, KILLING PROCESS **************************');
|
|
726
|
-
process.exit(1);
|
|
727
|
-
}
|
|
728
|
-
var lastResumeToken_1;
|
|
729
|
-
if (resumeToken) {
|
|
730
|
-
lastResumeToken_1 = resumeToken;
|
|
731
|
-
try {
|
|
732
|
-
this._oplog = index_1.ResolveIOServer.getMainDB().watch([], { resumeAfter: resumeToken });
|
|
733
|
-
}
|
|
734
|
-
catch (errOp) {
|
|
735
|
-
if (this._oplog && !this._oplog.closed) {
|
|
736
|
-
this._oplog.close();
|
|
737
|
-
}
|
|
738
|
-
else {
|
|
739
|
-
this._oplog = index_1.ResolveIOServer.getMainDB().watch();
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
else {
|
|
744
|
-
this._oplog = index_1.ResolveIOServer.getMainDB().watch();
|
|
745
|
-
}
|
|
746
|
-
console.log(new Date(), 'oplog started');
|
|
747
|
-
this._oplog.on('change', function (doc) {
|
|
748
|
-
// let startDate = new Date();
|
|
749
|
-
if (doc.ns) {
|
|
750
|
-
var collection = doc.ns.coll;
|
|
751
|
-
if (!_this._debugOplogCollections.some(function (a) { return a.collection === doc.ns.coll && a.type === doc.operationType; })) {
|
|
752
|
-
_this._debugOplogCollections.push({
|
|
753
|
-
collection: doc.ns.coll,
|
|
754
|
-
type: doc.operationType,
|
|
755
|
-
hits: 1
|
|
756
|
-
});
|
|
757
|
-
}
|
|
758
|
-
else {
|
|
759
|
-
_this._debugOplogCollections.filter(function (a) { return a.collection === doc.ns.coll && a.type === doc.operationType; })[0].hits += 1;
|
|
760
|
-
}
|
|
761
|
-
// console.log(new Date(), 'Op log doc', doc.operationType, collection);
|
|
762
|
-
if (collection && !collection.endsWith('.versions') && !collection.startsWith('monitor-') && collection !== 'logs' && collection !== 'log-method-latencies' && collection !== 'log-subscriptions') {
|
|
763
|
-
_this._debugOplogHits += 1;
|
|
764
|
-
if (doc.operationType === 'insert') {
|
|
765
|
-
if (collection === 'support-tickets') {
|
|
766
|
-
if (_this.serverConfig['ROOT_URL'] === 'https://resolveio.com') {
|
|
767
|
-
_this._mainServer.getMethodManager().callMethodInternal.call(_this._mainServer.getMethodManager(), 'sendSupportTicketEmail', doc.documentKey['_id']);
|
|
768
|
-
_this.invalidatePubsCache(collection, 'insert');
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
if (collection !== 'method-responses') {
|
|
772
|
-
_this.invalidatePubsCache(collection, 'insert');
|
|
773
|
-
}
|
|
774
|
-
// let endDate = new Date();
|
|
775
|
-
// this.currentPerfomanceMonitor.push({
|
|
776
|
-
// _id: this.idPerformance++,
|
|
777
|
-
// function: 'oplog',
|
|
778
|
-
// publication: collection,
|
|
779
|
-
// subscriptionData: [],
|
|
780
|
-
// date_start: startDate,
|
|
781
|
-
// date_end: endDate,
|
|
782
|
-
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
783
|
-
// result: 'Insert'
|
|
784
|
-
// });
|
|
785
|
-
}
|
|
786
|
-
else if (doc.operationType === 'update' || doc.operationType === 'replace') {
|
|
787
|
-
if (collection !== 'method-responses') {
|
|
788
|
-
_this.invalidatePubsCache(collection, 'update');
|
|
789
|
-
}
|
|
790
|
-
// let endDate = new Date();
|
|
791
|
-
// this.currentPerfomanceMonitor.push({
|
|
792
|
-
// _id: this.idPerformance++,
|
|
793
|
-
// function: 'oplog',
|
|
794
|
-
// publication: collection,
|
|
795
|
-
// subscriptionData: [],
|
|
796
|
-
// date_start: startDate,
|
|
797
|
-
// date_end: endDate,
|
|
798
|
-
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
799
|
-
// result: 'Update'
|
|
800
|
-
// });
|
|
801
|
-
}
|
|
802
|
-
else if (doc.operationType === 'delete') {
|
|
803
|
-
if (collection !== 'method-responses') {
|
|
804
|
-
_this.invalidatePubsCache(collection, 'delete');
|
|
805
|
-
}
|
|
806
|
-
// let endDate = new Date();
|
|
807
|
-
// this.currentPerfomanceMonitor.push({
|
|
808
|
-
// _id: this.idPerformance++,
|
|
809
|
-
// function: 'oplog',
|
|
810
|
-
// publication: collection,
|
|
811
|
-
// subscriptionData: [],
|
|
812
|
-
// date_start: startDate,
|
|
813
|
-
// date_end: endDate,
|
|
814
|
-
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
815
|
-
// result: 'Delete'
|
|
816
|
-
// });
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
if (collection === 'flags') {
|
|
820
|
-
flag_collection_1.Flags.findOne({ type: 'Enable Debug' }).then(function (flag) {
|
|
821
|
-
if (flag && flag.value) {
|
|
822
|
-
_this._enableDebug = true;
|
|
823
|
-
}
|
|
824
|
-
else {
|
|
825
|
-
_this._enableDebug = false;
|
|
826
|
-
}
|
|
827
|
-
});
|
|
828
|
-
}
|
|
829
|
-
lastResumeToken_1 = doc._id;
|
|
830
|
-
}
|
|
831
|
-
});
|
|
832
|
-
this._oplog.on('error', function (error) {
|
|
833
|
-
console.log(new Date(), 'oplog error', error);
|
|
834
|
-
_this._oplog.close();
|
|
835
|
-
});
|
|
836
|
-
this._oplog.on('end', function () {
|
|
837
|
-
console.log(new Date(), 'oplog end');
|
|
838
|
-
_this._oplog.close();
|
|
839
|
-
});
|
|
840
|
-
this._oplog.on('close', function () {
|
|
841
|
-
_this._oplog = null;
|
|
842
|
-
console.log(new Date(), 'oplog close');
|
|
843
|
-
_this.tailOpLog(lastResumeToken_1);
|
|
844
|
-
});
|
|
845
|
-
}
|
|
846
|
-
else {
|
|
847
|
-
this._oplog.close();
|
|
848
|
-
}
|
|
849
|
-
};
|
|
850
|
-
// Fetch pub once, send to all clients linked to this pub
|
|
851
|
-
SubscriptionManager.prototype.sendDataToOne = function (ws, messageId, subscription, type, collection) {
|
|
852
|
-
var _this = this;
|
|
853
|
-
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
854
|
-
var cacheData, serverRes, monitor_1;
|
|
855
|
-
var _a;
|
|
856
|
-
var _this = this;
|
|
857
|
-
return __generator(this, function (_b) {
|
|
858
|
-
// let startDate = new Date();
|
|
859
|
-
if (!this._publications[subscription.publication].user_specific) { // Same pub for all users
|
|
860
|
-
if (subscription.cacheId) {
|
|
861
|
-
try {
|
|
862
|
-
cacheData = JSON.parse(this._nodeCache.get(subscription.cacheId), common_1.dateReviver);
|
|
863
|
-
serverRes = {
|
|
864
|
-
messageId: messageId,
|
|
865
|
-
hasError: false,
|
|
866
|
-
data: cacheData
|
|
867
|
-
};
|
|
868
|
-
this.sendWS(ws, serverRes);
|
|
869
|
-
}
|
|
870
|
-
catch (err) {
|
|
871
|
-
this._nodeCache.del(subscription.cacheId);
|
|
872
|
-
subscription.cacheId = 0;
|
|
873
|
-
this.addToQueue({
|
|
874
|
-
_id: 0,
|
|
875
|
-
type: 'newSub',
|
|
876
|
-
collection: '',
|
|
877
|
-
subscription: subscription,
|
|
878
|
-
running: false,
|
|
879
|
-
run_again: false
|
|
880
|
-
});
|
|
881
|
-
}
|
|
882
|
-
// let endDate = new Date();
|
|
883
|
-
// this.currentPerfomanceMonitor.push({
|
|
884
|
-
// _id: this.idPerformance++,
|
|
885
|
-
// function: 'sendDataToOne',
|
|
886
|
-
// publication: subscription.publication,
|
|
887
|
-
// // subscriptionData: subscription.subscriptionData,
|
|
888
|
-
// subscriptionData: [],
|
|
889
|
-
// date_start: startDate,
|
|
890
|
-
// date_end: endDate,
|
|
891
|
-
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
892
|
-
// result: 'Send cache'
|
|
893
|
-
// });
|
|
894
|
-
resolve(true);
|
|
895
|
-
}
|
|
896
|
-
else {
|
|
897
|
-
this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'Error Detected During sendDataToOne - No Cache! - ' + subscription.publication + '\n\nData \n' + JSON.stringify(subscription.subscriptionData, null, 2));
|
|
898
|
-
resolve(false);
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
else { // Pub is different for each user (Look at users publication) [MUCH SLOWER, RE-RUNS FOR EACH USER]
|
|
902
|
-
monitor_1 = this._monitorManagerFunction.startMonitorFunction('User Specific Publication', subscription.publication, '', '', subscription.subscriptionData);
|
|
903
|
-
(_a = this._publications[subscription.publication].function).call.apply(_a, __spreadArray([Object.assign({}, this, SubscriptionManager.prototype), ws['id_user']], subscription.subscriptionData, false)).then(function (res) {
|
|
904
|
-
_this._monitorManagerFunction.finishMonitorFunction(monitor_1);
|
|
905
|
-
var serverRes = {
|
|
906
|
-
messageId: messageId,
|
|
907
|
-
hasError: false,
|
|
908
|
-
data: res
|
|
909
|
-
};
|
|
910
|
-
// console.log('Send Pub Data Once 2', new Date(), 'Success', subscription);
|
|
911
|
-
_this.sendWS(ws, serverRes);
|
|
912
|
-
// let endDate = new Date();
|
|
913
|
-
// this.currentPerfomanceMonitor.push({
|
|
914
|
-
// _id: this.idPerformance++,
|
|
915
|
-
// function: 'sendDataToOne',
|
|
916
|
-
// publication: subscription.publication,
|
|
917
|
-
// // subscriptionData: subscription.subscriptionData,
|
|
918
|
-
// subscriptionData: [],
|
|
919
|
-
// date_start: startDate,
|
|
920
|
-
// date_end: endDate,
|
|
921
|
-
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
922
|
-
// result: 'Send ws spec data'
|
|
923
|
-
// });
|
|
924
|
-
resolve(true);
|
|
925
|
-
}, function (err) {
|
|
926
|
-
_this._monitorManagerFunction.finishMonitorFunction(monitor_1);
|
|
927
|
-
var serverRes = {
|
|
928
|
-
messageId: messageId,
|
|
929
|
-
hasError: true,
|
|
930
|
-
data: err
|
|
931
|
-
};
|
|
932
|
-
// console.log('Send Pub Data Once 2', new Date(), 'Error', subscription);
|
|
933
|
-
_this.sendWS(ws, serverRes);
|
|
934
|
-
_this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + _this.serverConfig['CLIENT_NAME'], 'Error Detected During Subscription ' + subscription.publication + ' - (sendDataToOne - WS)\n\nData \n' + JSON.stringify(subscription.subscriptionData, null, 2) + '\n\nErrors\n' + JSON.stringify(err, null, 2));
|
|
935
|
-
reject(err);
|
|
936
|
-
});
|
|
937
|
-
}
|
|
938
|
-
return [2 /*return*/];
|
|
939
|
-
});
|
|
940
|
-
}); });
|
|
941
|
-
};
|
|
942
|
-
// Fetch pub once, send to all clients linked to this pub
|
|
943
|
-
SubscriptionManager.prototype.sendDataToAll = function (mongoQueue) {
|
|
944
|
-
var _this = this;
|
|
945
|
-
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
946
|
-
var monitor_2;
|
|
947
|
-
var _a;
|
|
948
|
-
var _this = this;
|
|
949
|
-
return __generator(this, function (_b) {
|
|
950
|
-
// let startDate = new Date();
|
|
951
|
-
if (!mongoQueue.subscription.clients.length) {
|
|
952
|
-
if (mongoQueue.subscription.cacheId) {
|
|
953
|
-
this._nodeCache.del(mongoQueue.subscription.cacheId);
|
|
954
|
-
}
|
|
955
|
-
if (this._subscriptions.findIndex(function (a) { return a.publication === mongoQueue.subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(mongoQueue.subscription.subscriptionData); }) >= 0) {
|
|
956
|
-
this._subscriptions.splice(this._subscriptions.findIndex(function (a) { return a.publication === mongoQueue.subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(mongoQueue.subscription.subscriptionData); }), 1);
|
|
957
|
-
}
|
|
958
|
-
resolve(false);
|
|
959
|
-
}
|
|
960
|
-
else {
|
|
961
|
-
if (mongoQueue.subscription.publication !== 'superadminAPM' && mongoQueue.subscription.publication !== 'loggedInUsers') {
|
|
962
|
-
this._mainServer.getMethodManager().callMethodInternal.call(this._mainServer.getMethodManager(), 'insertSubscriptionLog', mongoQueue.type, mongoQueue.subscription.publication, mongoQueue.collection, JSON.stringify(mongoQueue.subscription.subscriptionData));
|
|
963
|
-
}
|
|
964
|
-
monitor_2 = this._monitorManagerFunction.startMonitorFunction('Publication', mongoQueue.subscription.publication, '', '', mongoQueue.subscription.subscriptionData);
|
|
965
|
-
(_a = this._publications[mongoQueue.subscription.publication].function).call.apply(_a, __spreadArray([Object.assign({}, this, SubscriptionManager.prototype)], mongoQueue.subscription.subscriptionData, false)).then(function (res) {
|
|
966
|
-
_this._monitorManagerFunction.finishMonitorFunction(monitor_2);
|
|
967
|
-
if (!mongoQueue.subscription.clients.length) {
|
|
968
|
-
var nodeCacheSize = _this._nodeCache.getStats().vsize;
|
|
969
|
-
if (nodeCacheSize > _this._heapLimit) {
|
|
970
|
-
var deleteCount = 0;
|
|
971
|
-
var subArr = _this._subscriptions.filter(function (a) { return a.cacheId && !a.clients.length; });
|
|
972
|
-
for (var zz = 0; zz < subArr.length; zz++) {
|
|
973
|
-
_this._debugRemoveCacheHits += 1;
|
|
974
|
-
_this._nodeCache.del(subArr[zz].cacheId);
|
|
975
|
-
subArr[zz].cacheId = 0;
|
|
976
|
-
deleteCount += 1;
|
|
977
|
-
nodeCacheSize = _this._nodeCache.getStats().vsize;
|
|
978
|
-
if (nodeCacheSize < _this._heapLimit * 0.75) {
|
|
979
|
-
break;
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
console.log('Sub Cache: ' + 'Too Big - ' + mongoQueue.subscription.publication + ' - Deleted: ' + deleteCount + ' - ' + nodeCacheSize);
|
|
983
|
-
}
|
|
984
|
-
if (mongoQueue.subscription.cacheId) {
|
|
985
|
-
_this._nodeCache.del(mongoQueue.subscription.cacheId);
|
|
986
|
-
}
|
|
987
|
-
var cacheId = _this._cacheId;
|
|
988
|
-
_this._cacheId += 1;
|
|
989
|
-
_this._nodeCache.set(cacheId, JSON.stringify(res));
|
|
990
|
-
mongoQueue.subscription.cacheId = cacheId;
|
|
991
|
-
// let endDate = new Date();
|
|
992
|
-
// this.currentPerfomanceMonitor.push({
|
|
993
|
-
// _id: this.idPerformance++,
|
|
994
|
-
// function: 'sendPubData',
|
|
995
|
-
// publication: subscription.publication,
|
|
996
|
-
// // subscriptionData: subscription.subscriptionData,
|
|
997
|
-
// subscriptionData: [],
|
|
998
|
-
// date_start: startDate,
|
|
999
|
-
// date_end: endDate,
|
|
1000
|
-
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
1001
|
-
// result: 'No clients'
|
|
1002
|
-
// });
|
|
1003
|
-
resolve(false);
|
|
1004
|
-
}
|
|
1005
|
-
else {
|
|
1006
|
-
if (!mongoQueue.subscription.cacheId || _this._nodeCache.get(mongoQueue.subscription.cacheId) !== JSON.stringify(res)) {
|
|
1007
|
-
mongoQueue.subscription.clients.forEach(function (client) {
|
|
1008
|
-
var ws = _this._mainServer.getWS(client.id_socket);
|
|
1009
|
-
if (ws) {
|
|
1010
|
-
var serverRes = {
|
|
1011
|
-
messageId: client.messageId,
|
|
1012
|
-
hasError: false,
|
|
1013
|
-
data: res
|
|
1014
|
-
};
|
|
1015
|
-
_this.sendWS(ws, serverRes);
|
|
1016
|
-
}
|
|
1017
|
-
});
|
|
1018
|
-
var nodeCacheSize = _this._nodeCache.getStats().vsize;
|
|
1019
|
-
if (nodeCacheSize > _this._heapLimit) {
|
|
1020
|
-
var deleteCount = 0;
|
|
1021
|
-
var subArr = _this._subscriptions.filter(function (a) { return a.cacheId && !a.clients.length; });
|
|
1022
|
-
for (var zz = 0; zz < subArr.length; zz++) {
|
|
1023
|
-
_this._nodeCache.del(subArr[zz].cacheId);
|
|
1024
|
-
subArr[zz].cacheId = 0;
|
|
1025
|
-
deleteCount += 1;
|
|
1026
|
-
nodeCacheSize = _this._nodeCache.getStats().vsize;
|
|
1027
|
-
if (nodeCacheSize < _this._heapLimit * 0.75) {
|
|
1028
|
-
break;
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
console.log('Sub Cache: ' + 'Too Big - ' + mongoQueue.subscription.publication + ' - Deleted: ' + deleteCount + ' - ' + nodeCacheSize);
|
|
1032
|
-
}
|
|
1033
|
-
if (mongoQueue.subscription.cacheId) {
|
|
1034
|
-
_this._nodeCache.del(mongoQueue.subscription.cacheId);
|
|
1035
|
-
}
|
|
1036
|
-
var cacheId = _this._cacheId;
|
|
1037
|
-
_this._cacheId += 1;
|
|
1038
|
-
_this._nodeCache.set(cacheId, JSON.stringify(res));
|
|
1039
|
-
mongoQueue.subscription.cacheId = cacheId;
|
|
1040
|
-
// let endDate = new Date();
|
|
1041
|
-
// this.currentPerfomanceMonitor.push({
|
|
1042
|
-
// _id: this.idPerformance++,
|
|
1043
|
-
// function: 'sendPubData',
|
|
1044
|
-
// publication: subscription.publication,
|
|
1045
|
-
// // subscriptionData: subscription.subscriptionData,
|
|
1046
|
-
// subscriptionData: [],
|
|
1047
|
-
// date_start: startDate,
|
|
1048
|
-
// date_end: endDate,
|
|
1049
|
-
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
1050
|
-
// result: 'Same data'
|
|
1051
|
-
// });
|
|
1052
|
-
}
|
|
1053
|
-
resolve(true);
|
|
1054
|
-
}
|
|
1055
|
-
}, function (err) {
|
|
1056
|
-
_this._monitorManagerFunction.finishMonitorFunction(monitor_2);
|
|
1057
|
-
_this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + _this.serverConfig['CLIENT_NAME'], 'Error Detected During Subscription ' + mongoQueue.subscription.publication + ' - (sendPubData)\n\nData \n' + JSON.stringify(mongoQueue.subscription.subscriptionData, null, 2) + '\n\nErrors\n' + JSON.stringify(err, null, 2));
|
|
1058
|
-
mongoQueue.subscription.clients.forEach(function (client) {
|
|
1059
|
-
var ws = _this._mainServer.getWS(client.id_socket);
|
|
1060
|
-
if (ws) {
|
|
1061
|
-
if (ws['id_socket'] === client.id_socket) {
|
|
1062
|
-
var serverRes = {
|
|
1063
|
-
messageId: client.messageId,
|
|
1064
|
-
hasError: true,
|
|
1065
|
-
data: err
|
|
1066
|
-
};
|
|
1067
|
-
_this.sendWS(ws, serverRes);
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
});
|
|
1071
|
-
reject(err);
|
|
1072
|
-
});
|
|
1073
|
-
}
|
|
1074
|
-
return [2 /*return*/];
|
|
1075
|
-
});
|
|
1076
|
-
}); });
|
|
1077
|
-
};
|
|
1078
|
-
SubscriptionManager.prototype.sendWS = function (ws, data) {
|
|
1079
|
-
this._sendQueue.splice(0, 0, {
|
|
1080
|
-
id_ws: ws['id_socket'],
|
|
1081
|
-
data: data
|
|
1082
|
-
});
|
|
1083
|
-
};
|
|
1084
|
-
SubscriptionManager.prototype.getEnableDebug = function () {
|
|
1085
|
-
return this._enableDebug;
|
|
1086
|
-
};
|
|
1087
|
-
return SubscriptionManager;
|
|
1088
|
-
}());
|
|
1089
|
-
exports.SubscriptionManager = SubscriptionManager;
|
|
1090
|
-
|
|
1091
|
-
//# sourceMappingURL=subscription.manager.js.map
|