@resolveio/server-lib 9.0.32 → 9.0.34
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/client-server-app.js +7 -48
- package/client-server-app.js.map +1 -1
- package/collections/app-status.collection.js +8 -11
- package/collections/app-status.collection.js.map +1 -1
- package/collections/app-version.collection.js +8 -11
- package/collections/app-version.collection.js.map +1 -1
- package/collections/counter.collection.js +8 -11
- package/collections/counter.collection.js.map +1 -1
- package/collections/cron-job-history.collection.js +9 -12
- package/collections/cron-job-history.collection.js.map +1 -1
- package/collections/cron-job.collection.js +8 -11
- package/collections/cron-job.collection.js.map +1 -1
- package/collections/email-history.collection.js +8 -11
- package/collections/email-history.collection.js.map +1 -1
- package/collections/email-verified.collection.js +9 -12
- package/collections/email-verified.collection.js.map +1 -1
- package/collections/file.collection.js +8 -11
- package/collections/file.collection.js.map +1 -1
- package/collections/flag.collection.js +8 -11
- package/collections/flag.collection.js.map +1 -1
- package/collections/log-method-latency.collection.js +11 -14
- package/collections/log-method-latency.collection.js.map +1 -1
- package/collections/log-subscription.collection.js +13 -16
- package/collections/log-subscription.collection.js.map +1 -1
- package/collections/log.collection.js +16 -19
- package/collections/log.collection.js.map +1 -1
- package/collections/logged-in-users.collection.js +9 -12
- package/collections/logged-in-users.collection.js.map +1 -1
- package/collections/method-call.collection.js +10 -13
- package/collections/method-call.collection.js.map +1 -1
- package/collections/method-response.collection.js +10 -13
- package/collections/method-response.collection.js.map +1 -1
- package/collections/monitor-cpu.collection.js +13 -16
- package/collections/monitor-cpu.collection.js.map +1 -1
- package/collections/monitor-https-inbound.collection.js +13 -16
- package/collections/monitor-https-inbound.collection.js.map +1 -1
- package/collections/monitor-https-outbound.collection.js +15 -18
- package/collections/monitor-https-outbound.collection.js.map +1 -1
- package/collections/monitor-memory.collection.js +12 -15
- package/collections/monitor-memory.collection.js.map +1 -1
- package/collections/monitor-mongo.collection.js +12 -15
- package/collections/monitor-mongo.collection.js.map +1 -1
- package/collections/notification.collection.js +8 -11
- package/collections/notification.collection.js.map +1 -1
- package/collections/queue-flag.collection.js +9 -12
- package/collections/queue-flag.collection.js.map +1 -1
- package/collections/queue-method.collection.js +9 -12
- package/collections/queue-method.collection.js.map +1 -1
- package/collections/queue-response.collection.js +9 -12
- package/collections/queue-response.collection.js.map +1 -1
- package/collections/report-builder-dashboard-builder.collection.js +10 -13
- package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
- package/collections/report-builder-library.collection.js +11 -14
- package/collections/report-builder-library.collection.js.map +1 -1
- package/collections/report-builder-report.collection.js +11 -14
- package/collections/report-builder-report.collection.js.map +1 -1
- package/collections/user-group.collection.js +11 -14
- package/collections/user-group.collection.js.map +1 -1
- package/collections/user-guide.collection.js +8 -11
- package/collections/user-guide.collection.js.map +1 -1
- package/collections/user.collection.js +12 -15
- package/collections/user.collection.js.map +1 -1
- package/cron/cron.js +25 -25
- package/cron/cron.js.map +1 -1
- package/fixtures/cron-jobs.js +30 -80
- package/fixtures/cron-jobs.js.map +1 -1
- package/fixtures/init.js +9 -59
- package/fixtures/init.js.map +1 -1
- package/http/auth.js +344 -460
- package/http/auth.js.map +1 -1
- package/http/health.js +1 -5
- package/http/health.js.map +1 -1
- package/http/home.js +7 -11
- package/http/home.js.map +1 -1
- package/index.js +36 -98
- package/index.js.map +1 -1
- package/managers/cron.manager.js +78 -157
- package/managers/cron.manager.js.map +1 -1
- package/managers/method.manager.js +323 -303
- package/managers/method.manager.js.map +1 -1
- package/managers/mongo.manager.d.ts +14 -14
- package/managers/mongo.manager.js +794 -865
- package/managers/mongo.manager.js.map +1 -1
- package/managers/monitor.manager.js +171 -254
- package/managers/monitor.manager.js.map +1 -1
- package/managers/queue-method.manager.js +69 -166
- package/managers/queue-method.manager.js.map +1 -1
- package/managers/subscription.manager.js +515 -708
- package/managers/subscription.manager.js.map +1 -1
- package/methods/accounts.js +111 -183
- package/methods/accounts.js.map +1 -1
- package/methods/aws.js +156 -262
- package/methods/aws.js.map +1 -1
- package/methods/cloudconvert.js +100 -180
- package/methods/cloudconvert.js.map +1 -1
- package/methods/collections.js +114 -530
- package/methods/collections.js.map +1 -1
- package/methods/counters.js +29 -79
- package/methods/counters.js.map +1 -1
- package/methods/cron-jobs.js +819 -884
- package/methods/cron-jobs.js.map +1 -1
- package/methods/flags.js +1 -5
- package/methods/flags.js.map +1 -1
- package/methods/logs.js +258 -313
- package/methods/logs.js.map +1 -1
- package/methods/monitor.js +289 -348
- package/methods/monitor.js.map +1 -1
- package/methods/pdf.js +341 -340
- package/methods/pdf.js.map +1 -1
- package/methods/report-builder.js +565 -657
- package/methods/report-builder.js.map +1 -1
- package/methods/support.js +67 -185
- package/methods/support.js.map +1 -1
- package/models/app-status.model.js +1 -2
- package/models/app-version.model.js +1 -2
- package/models/billing-logged-in-users.model.js +1 -2
- package/models/collection-document.model.js +1 -2
- package/models/counter.model.js +1 -2
- package/models/cron-job-history.model.js +1 -2
- package/models/cron-job.model.js +1 -2
- package/models/dialog.model.js +1 -2
- package/models/email-history.model.js +1 -2
- package/models/email-verified.model.js +1 -2
- package/models/file.model.js +1 -2
- package/models/flag.model.js +1 -2
- package/models/log-method-latency.model.js +1 -2
- package/models/log-subscription.model.js +1 -2
- package/models/log.model.js +1 -2
- package/models/logged-in-users.model.js +1 -2
- package/models/method-call.model.js +1 -2
- package/models/method-response.model.js +1 -2
- package/models/method.model.js +1 -2
- package/models/monitor-cpu.model.js +1 -2
- package/models/monitor-https-inbound.model.js +1 -2
- package/models/monitor-https-outbound.model.js +1 -2
- package/models/monitor-memory.model.js +1 -2
- package/models/monitor-mongo.model.js +1 -2
- package/models/notification.model.js +1 -2
- package/models/pagination.model.js +2 -5
- package/models/pagination.model.js.map +1 -1
- package/models/permission.model.js +1 -2
- package/models/queue-method.model.js +1 -2
- package/models/queue-response.model.js +1 -2
- package/models/report-builder-dashboard-builder.model.js +1 -2
- package/models/report-builder-library.model.js +1 -2
- package/models/report-builder-report.model.js +1 -2
- package/models/report-builder.model.js +1 -2
- package/models/select-data-label.model.js +1 -2
- package/models/server-response.model.js +1 -2
- package/models/subscription.model.js +1 -2
- package/models/support-ticket.model.js +1 -2
- package/models/user-group.model.js +1 -2
- package/models/user-guide.model.js +1 -2
- package/models/user.model.js +1 -2
- package/package.json +1 -1
- package/public_api.js +70 -82
- package/public_api.js.map +1 -1
- package/publications/app-status.js +4 -8
- package/publications/app-status.js.map +1 -1
- package/publications/app-version.js +4 -8
- package/publications/app-version.js.map +1 -1
- package/publications/cron-jobs.js +9 -13
- package/publications/cron-jobs.js.map +1 -1
- package/publications/files.js +11 -15
- package/publications/files.js.map +1 -1
- package/publications/flags.js +7 -11
- package/publications/flags.js.map +1 -1
- package/publications/logs.js +31 -35
- package/publications/logs.js.map +1 -1
- package/publications/method-calls.js +4 -8
- package/publications/method-calls.js.map +1 -1
- package/publications/method-responses.js +4 -8
- package/publications/method-responses.js.map +1 -1
- package/publications/notifications.js +4 -8
- package/publications/notifications.js.map +1 -1
- package/publications/report-builder-dashboard-builders.js +8 -12
- package/publications/report-builder-dashboard-builders.js.map +1 -1
- package/publications/report-builder-libraries.js +16 -66
- package/publications/report-builder-libraries.js.map +1 -1
- package/publications/report-builder-reports.js +17 -21
- package/publications/report-builder-reports.js.map +1 -1
- package/publications/super-admin.js +3 -7
- package/publications/super-admin.js.map +1 -1
- package/publications/user-groups.js +4 -8
- package/publications/user-groups.js.map +1 -1
- package/publications/user-guides.js +4 -8
- package/publications/user-guides.js.map +1 -1
- package/server-app.js +393 -534
- package/server-app.js.map +1 -1
- package/util/common.js +55 -92
- package/util/common.js.map +1 -1
- package/util/schema-report-builder.js +76 -134
- package/util/schema-report-builder.js.map +1 -1
|
@@ -1,73 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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 __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
39
|
-
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
40
|
-
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
41
|
-
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
42
|
-
r[k] = a[j];
|
|
43
|
-
return r;
|
|
44
|
-
};
|
|
45
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.SubscriptionManager = void 0;
|
|
47
|
-
var logs_1 = require("../publications/logs");
|
|
48
|
-
var app_status_1 = require("../publications/app-status");
|
|
49
|
-
var app_version_1 = require("../publications/app-version");
|
|
50
|
-
var files_1 = require("../publications/files");
|
|
51
|
-
var super_admin_1 = require("../publications/super-admin");
|
|
52
|
-
var logged_in_users_collection_1 = require("../collections/logged-in-users.collection");
|
|
53
|
-
var cron_jobs_1 = require("../publications/cron-jobs");
|
|
54
|
-
var flags_1 = require("../publications/flags");
|
|
55
|
-
var method_calls_1 = require("../publications/method-calls");
|
|
56
|
-
var method_responses_1 = require("../publications/method-responses");
|
|
57
|
-
var index_1 = require("../index");
|
|
58
|
-
var notifications_1 = require("../publications/notifications");
|
|
59
|
-
var common_1 = require("../util/common");
|
|
60
|
-
var moment = require("moment");
|
|
61
|
-
var report_builder_reports_1 = require("../publications/report-builder-reports");
|
|
62
|
-
var NodeCache = require("node-cache");
|
|
63
|
-
var report_builder_libraries_1 = require("../publications/report-builder-libraries");
|
|
64
|
-
var user_groups_1 = require("../publications/user-groups");
|
|
65
|
-
var user_guides_1 = require("../publications/user-guides");
|
|
66
|
-
var report_builder_dashboard_builders_1 = require("../publications/report-builder-dashboard-builders");
|
|
67
|
-
var mongo_manager_1 = require("./mongo.manager");
|
|
68
|
-
var SubscriptionManager = /** @class */ (function () {
|
|
69
|
-
function SubscriptionManager(mainServer, wss, serverConfig) {
|
|
70
|
-
var _this = this;
|
|
1
|
+
import { loadLogPublications } from '../publications/logs';
|
|
2
|
+
import { loadAppStatusPublications } from '../publications/app-status';
|
|
3
|
+
import { loadAppVersionPublications } from '../publications/app-version';
|
|
4
|
+
import { loadFilePublications } from '../publications/files';
|
|
5
|
+
import { loadSuperAdminPublications } from '../publications/super-admin';
|
|
6
|
+
import { LoggedInUsers } from '../collections/logged-in-users.collection';
|
|
7
|
+
import { loadCronJobPublications } from '../publications/cron-jobs';
|
|
8
|
+
import { loadFlagsPublications } from '../publications/flags';
|
|
9
|
+
import { loadMethodCallsPublications } from '../publications/method-calls';
|
|
10
|
+
import { loadMethodResponsePublications } from '../publications/method-responses';
|
|
11
|
+
import { ResolveIOServer } from '../index';
|
|
12
|
+
import { loadNotificationPublications } from '../publications/notifications';
|
|
13
|
+
import { deepCopy } from '../util/common';
|
|
14
|
+
import * as moment from 'moment';
|
|
15
|
+
import { loadReportBuilderReportPublications } from '../publications/report-builder-reports';
|
|
16
|
+
import * as NodeCache from 'node-cache';
|
|
17
|
+
import { loadReportBuilderLibraryPublications } from '../publications/report-builder-libraries';
|
|
18
|
+
import { loadUserGroupPublications } from '../publications/user-groups';
|
|
19
|
+
import { loadUserGuidePublications } from '../publications/user-guides';
|
|
20
|
+
import { loadReportBuilderDashboardBuilderPublications } from '../publications/report-builder-dashboard-builders';
|
|
21
|
+
import { objectIdHexString } from './mongo.manager';
|
|
22
|
+
export class SubscriptionManager {
|
|
23
|
+
constructor(mainServer, wss, serverConfig) {
|
|
71
24
|
this._publications = {};
|
|
72
25
|
this._subscriptions = [];
|
|
73
26
|
this._loggedInUsers = [];
|
|
@@ -81,348 +34,269 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
81
34
|
this.serverConfig = serverConfig;
|
|
82
35
|
this._wss = wss;
|
|
83
36
|
// Publications
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
37
|
+
loadSuperAdminPublications(this);
|
|
38
|
+
loadAppVersionPublications(this);
|
|
39
|
+
loadAppStatusPublications(this);
|
|
40
|
+
loadLogPublications(this);
|
|
41
|
+
loadFilePublications(this);
|
|
42
|
+
loadCronJobPublications(this);
|
|
43
|
+
loadFlagsPublications(this);
|
|
44
|
+
loadMethodCallsPublications(this);
|
|
45
|
+
loadMethodResponsePublications(this);
|
|
46
|
+
loadNotificationPublications(this);
|
|
47
|
+
loadReportBuilderReportPublications(this);
|
|
48
|
+
loadReportBuilderLibraryPublications(this);
|
|
49
|
+
loadUserGroupPublications(this);
|
|
50
|
+
loadUserGuidePublications(this);
|
|
51
|
+
loadReportBuilderDashboardBuilderPublications(this);
|
|
99
52
|
this.tailOpLog();
|
|
100
53
|
this.runOpLogQueue();
|
|
101
|
-
setInterval(
|
|
54
|
+
setInterval(() => {
|
|
102
55
|
console.log(new Date());
|
|
103
|
-
console.log('Sub Cache Length: ' +
|
|
104
|
-
console.log('Sub Length: ' +
|
|
105
|
-
console.log(
|
|
56
|
+
console.log('Sub Cache Length: ' + this._subCache.length);
|
|
57
|
+
console.log('Sub Length: ' + this._subscriptions.length);
|
|
58
|
+
console.log(this._nodeCache.getStats().vsize);
|
|
106
59
|
}, 43200000);
|
|
107
|
-
setInterval(
|
|
108
|
-
if (!
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
60
|
+
setInterval(() => {
|
|
61
|
+
if (!this._runningQueue) {
|
|
62
|
+
if (this._sendQueue.length) {
|
|
63
|
+
this._runningQueue = true;
|
|
64
|
+
for (let i = this._sendQueue.length - 1; i >= 0; i--) {
|
|
65
|
+
let ws = this._mainServer.getWS(this._sendQueue[i].id_ws);
|
|
113
66
|
if (ws && ws.readyState === ws.OPEN) {
|
|
114
67
|
if (ws.bufferedAmount < 20480) {
|
|
115
|
-
|
|
116
|
-
ws.send(JSON.stringify(sendItem.data),
|
|
68
|
+
let sendItem = this._sendQueue.pop();
|
|
69
|
+
ws.send(JSON.stringify(sendItem.data), (error) => {
|
|
117
70
|
if (error) {
|
|
118
71
|
console.log('Error on WS: ', error);
|
|
119
|
-
|
|
72
|
+
this.unsubscribeAll(ws);
|
|
120
73
|
}
|
|
121
74
|
});
|
|
122
75
|
}
|
|
123
76
|
}
|
|
124
77
|
else {
|
|
125
|
-
|
|
78
|
+
this._sendQueue.splice(i, 1);
|
|
126
79
|
}
|
|
127
|
-
};
|
|
128
|
-
for (var i = _this._sendQueue.length - 1; i >= 0; i--) {
|
|
129
|
-
_loop_1(i);
|
|
130
80
|
}
|
|
131
|
-
|
|
81
|
+
this._runningQueue = false;
|
|
132
82
|
}
|
|
133
83
|
}
|
|
134
84
|
}, 10);
|
|
135
|
-
setInterval(
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
case 0:
|
|
150
|
-
loggedInUser = userCopy[i];
|
|
151
|
-
if (!(!loggedInUser.date || moment().diff(moment(loggedInUser.date), 'seconds') >= 60)) return [3 /*break*/, 3];
|
|
152
|
-
if (!this_1._mainServer.getWS(loggedInUser.id_ws)) return [3 /*break*/, 1];
|
|
153
|
-
this_1.unsubscribeAll(this_1._mainServer.getWS(loggedInUser.id_ws));
|
|
154
|
-
return [3 /*break*/, 3];
|
|
155
|
-
case 1:
|
|
156
|
-
this_1._subscriptions.forEach(function (sub) {
|
|
157
|
-
for (var j = sub.clients.length - 1; j >= 0; j--) {
|
|
158
|
-
var client = sub.clients[j];
|
|
159
|
-
if (client.id_socket === loggedInUser.id_ws) {
|
|
160
|
-
sub.clients.splice(j, 1);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
return [4 /*yield*/, logged_in_users_collection_1.LoggedInUsers.findById(loggedInUser._id)];
|
|
165
|
-
case 2:
|
|
166
|
-
if (_a.sent()) {
|
|
167
|
-
logged_in_users_collection_1.LoggedInUsers.deleteOne({ _id: loggedInUser._id });
|
|
168
|
-
}
|
|
169
|
-
this_1._loggedInUsers.splice(i, 1);
|
|
170
|
-
_a.label = 3;
|
|
171
|
-
case 3: return [2 /*return*/];
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
};
|
|
175
|
-
this_1 = this;
|
|
176
|
-
i = this._loggedInUsers.length - 1;
|
|
177
|
-
_b.label = 2;
|
|
178
|
-
case 2:
|
|
179
|
-
if (!(i >= 0)) return [3 /*break*/, 5];
|
|
180
|
-
return [5 /*yield**/, _loop_2(i)];
|
|
181
|
-
case 3:
|
|
182
|
-
_b.sent();
|
|
183
|
-
_b.label = 4;
|
|
184
|
-
case 4:
|
|
185
|
-
i--;
|
|
186
|
-
return [3 /*break*/, 2];
|
|
187
|
-
case 5:
|
|
188
|
-
for (i = 0; i < this._subscriptions.length; i++) {
|
|
189
|
-
sub = this._subscriptions[i];
|
|
190
|
-
_loop_3 = function (j) {
|
|
191
|
-
var client = sub.clients[j];
|
|
192
|
-
if (!this_2._loggedInUsers.some(function (a) { return a.id_ws === client.id_socket; })) {
|
|
85
|
+
setInterval(async () => {
|
|
86
|
+
this._loggedInUsers = await LoggedInUsers.find();
|
|
87
|
+
let userCopy = deepCopy(this._loggedInUsers);
|
|
88
|
+
for (let i = this._loggedInUsers.length - 1; i >= 0; i--) {
|
|
89
|
+
let loggedInUser = userCopy[i];
|
|
90
|
+
if (!loggedInUser.date || moment().diff(moment(loggedInUser.date), 'seconds') >= 60) {
|
|
91
|
+
if (this._mainServer.getWS(loggedInUser.id_ws)) {
|
|
92
|
+
this.unsubscribeAll(this._mainServer.getWS(loggedInUser.id_ws));
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
this._subscriptions.forEach(sub => {
|
|
96
|
+
for (let j = sub.clients.length - 1; j >= 0; j--) {
|
|
97
|
+
let client = sub.clients[j];
|
|
98
|
+
if (client.id_socket === loggedInUser.id_ws) {
|
|
193
99
|
sub.clients.splice(j, 1);
|
|
194
100
|
}
|
|
195
|
-
};
|
|
196
|
-
this_2 = this;
|
|
197
|
-
for (j = sub.clients.length - 1; j >= 0; j--) {
|
|
198
|
-
_loop_3(j);
|
|
199
101
|
}
|
|
102
|
+
});
|
|
103
|
+
if (await LoggedInUsers.findById(loggedInUser._id)) {
|
|
104
|
+
LoggedInUsers.deleteOne({ _id: loggedInUser._id });
|
|
200
105
|
}
|
|
201
|
-
|
|
106
|
+
this._loggedInUsers.splice(i, 1);
|
|
107
|
+
}
|
|
202
108
|
}
|
|
203
|
-
}
|
|
204
|
-
|
|
109
|
+
}
|
|
110
|
+
for (let i = 0; i < this._subscriptions.length; i++) {
|
|
111
|
+
let sub = this._subscriptions[i];
|
|
112
|
+
for (let j = sub.clients.length - 1; j >= 0; j--) {
|
|
113
|
+
let client = sub.clients[j];
|
|
114
|
+
if (!this._loggedInUsers.some(a => a.id_ws === client.id_socket)) {
|
|
115
|
+
sub.clients.splice(j, 1);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}, 60000);
|
|
205
120
|
}
|
|
206
121
|
// Add all files to publications private object
|
|
207
|
-
|
|
122
|
+
publications(method) {
|
|
208
123
|
this._publications = Object.assign(this._publications, method);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
_this.unsubscribeAll(ws);
|
|
223
|
-
}
|
|
224
|
-
}, function (err) {
|
|
225
|
-
_this.unsubscribeAll(ws);
|
|
226
|
-
});
|
|
227
|
-
return [2 /*return*/];
|
|
228
|
-
});
|
|
124
|
+
}
|
|
125
|
+
async loggedInLatency(ws) {
|
|
126
|
+
let date = new Date();
|
|
127
|
+
let loggedInUser = this._loggedInUsers.filter(a => a.id_ws === ws['id_socket'])[0];
|
|
128
|
+
if (loggedInUser) {
|
|
129
|
+
loggedInUser.date = date;
|
|
130
|
+
}
|
|
131
|
+
LoggedInUsers.findOneAndUpdate({ id_ws: ws['id_socket'] }, { $set: { latency: ws['latency'], date: date } }).then(res => {
|
|
132
|
+
if (!res) {
|
|
133
|
+
this.unsubscribeAll(ws);
|
|
134
|
+
}
|
|
135
|
+
}, () => {
|
|
136
|
+
this.unsubscribeAll(ws);
|
|
229
137
|
});
|
|
230
|
-
}
|
|
138
|
+
}
|
|
231
139
|
// Subscribe to publication
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
140
|
+
async subscribe(messageDate, ws, messageId, publication, ...subscriptionData) {
|
|
141
|
+
let that = this;
|
|
142
|
+
let pub = that._publications[publication];
|
|
143
|
+
if (!pub) {
|
|
144
|
+
console.error('No Publication: ' + publication);
|
|
145
|
+
return;
|
|
236
146
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
case 0:
|
|
243
|
-
that = this;
|
|
244
|
-
pub = that._publications[publication];
|
|
245
|
-
if (!!pub) return [3 /*break*/, 1];
|
|
246
|
-
console.error('No Publication: ' + publication);
|
|
247
|
-
return [2 /*return*/];
|
|
248
|
-
case 1:
|
|
249
|
-
if (subscriptionData.length > 1 || subscriptionData[0]) {
|
|
250
|
-
if (!pub.check) {
|
|
251
|
-
console.error('No Check Function For Pub ' + publication);
|
|
252
|
-
return [2 /*return*/];
|
|
253
|
-
}
|
|
254
|
-
else if (!pub.check._schema) {
|
|
255
|
-
console.error('No Check Schema For Pub ' + publication);
|
|
256
|
-
return [2 /*return*/];
|
|
257
|
-
}
|
|
258
|
-
else {
|
|
259
|
-
valObj = {};
|
|
260
|
-
valKeys = Object.keys(pub.check._schema);
|
|
261
|
-
rootKeys = valKeys.filter(function (a) { return !a.includes('.'); });
|
|
262
|
-
for (i = 0; i < subscriptionData.length; i++) {
|
|
263
|
-
valObj[rootKeys[i]] = subscriptionData[i];
|
|
264
|
-
}
|
|
265
|
-
try {
|
|
266
|
-
pub.check.validate(valObj);
|
|
267
|
-
}
|
|
268
|
-
catch (errors) {
|
|
269
|
-
if (errors) {
|
|
270
|
-
console.error('Error in Pub Check (' + publication + ')', errors);
|
|
271
|
-
return [2 /*return*/];
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
sub = that._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
|
|
277
|
-
// If sub found (another user watching same data), add client to same sub
|
|
278
|
-
if (sub) {
|
|
279
|
-
sub.clients.push({
|
|
280
|
-
id_user: ws['id_user'],
|
|
281
|
-
messageId: messageId,
|
|
282
|
-
id_socket: ws['id_socket']
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
// If sub not found, create new sub
|
|
286
|
-
else {
|
|
287
|
-
that._subscriptions.push({
|
|
288
|
-
publication: publication,
|
|
289
|
-
subscriptionData: subscriptionData,
|
|
290
|
-
collections: that.getPublicationCollections(publication),
|
|
291
|
-
clients: [{
|
|
292
|
-
id_user: ws['id_user'],
|
|
293
|
-
messageId: messageId,
|
|
294
|
-
id_socket: ws['id_socket']
|
|
295
|
-
}]
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
if (!sub) {
|
|
299
|
-
sub = that._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
|
|
300
|
-
}
|
|
301
|
-
// console.log('Subscribe', new Date(), 'Success', sub);
|
|
302
|
-
// Send pub data to client who just subscribed only, don't want to send to existing clients since nothing has changed
|
|
303
|
-
that.sendPubDataOnce(ws, messageId, sub, 'newSub', that.getPublicationCollections(publication)[0]);
|
|
304
|
-
if (!(that._publications[sub.publication].preFunction && !sub.preSubscriptionData)) return [3 /*break*/, 3];
|
|
305
|
-
_a = sub;
|
|
306
|
-
return [4 /*yield*/, (_b = that._publications[sub.publication]).preFunction.apply(_b, sub.subscriptionData)];
|
|
307
|
-
case 2:
|
|
308
|
-
_a.preSubscriptionData = _c.sent();
|
|
309
|
-
_c.label = 3;
|
|
310
|
-
case 3:
|
|
311
|
-
if (publication === 'appversion') {
|
|
312
|
-
newLoggedInUser = {
|
|
313
|
-
_id: mongo_manager_1.objectIdHexString(),
|
|
314
|
-
__v: 0,
|
|
315
|
-
date: new Date(),
|
|
316
|
-
id_user: ws['id_user'],
|
|
317
|
-
user: ws['user'],
|
|
318
|
-
id_ws: ws['id_socket']
|
|
319
|
-
};
|
|
320
|
-
this._loggedInUsers.push(newLoggedInUser);
|
|
321
|
-
logged_in_users_collection_1.LoggedInUsers.create(newLoggedInUser);
|
|
322
|
-
if (ws['user'] !== 'Admin' && this.serverConfig['CLIENT_NAME'] !== 'ResolveIO') {
|
|
323
|
-
this._mainServer.getMethodManager().callMethodInternal('supportCreateBillingUser', {
|
|
324
|
-
id_user: ws['id_user'],
|
|
325
|
-
user: ws['user'],
|
|
326
|
-
date: new Date(),
|
|
327
|
-
client: index_1.ResolveIOServer.getClientName()
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
return [2 /*return*/];
|
|
147
|
+
else {
|
|
148
|
+
if (subscriptionData.length > 1 || subscriptionData[0]) {
|
|
149
|
+
if (!pub.check) {
|
|
150
|
+
console.error('No Check Function For Pub ' + publication);
|
|
151
|
+
return;
|
|
332
152
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
// Unsubscribe from publication
|
|
337
|
-
SubscriptionManager.prototype.unsubscribe = function (messageDate, ws, messageId, publication) {
|
|
338
|
-
var subscriptionData = [];
|
|
339
|
-
for (var _i = 4; _i < arguments.length; _i++) {
|
|
340
|
-
subscriptionData[_i - 4] = arguments[_i];
|
|
341
|
-
}
|
|
342
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
343
|
-
var that, sub, i;
|
|
344
|
-
return __generator(this, function (_a) {
|
|
345
|
-
that = this;
|
|
346
|
-
// console.log('Before');
|
|
347
|
-
// console.dir(this._subscriptions.map(a => a.publication));
|
|
348
|
-
if (!that._publications[publication]) {
|
|
349
|
-
console.log('No Publication: ' + publication);
|
|
350
|
-
return [2 /*return*/];
|
|
153
|
+
else if (!pub.check._schema) {
|
|
154
|
+
console.error('No Check Schema For Pub ' + publication);
|
|
155
|
+
return;
|
|
351
156
|
}
|
|
352
157
|
else {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
158
|
+
let valObj = {};
|
|
159
|
+
let valKeys = Object.keys(pub.check._schema);
|
|
160
|
+
let rootKeys = valKeys.filter(a => !a.includes('.'));
|
|
161
|
+
for (let i = 0; i < subscriptionData.length; i++) {
|
|
162
|
+
valObj[rootKeys[i]] = subscriptionData[i];
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
pub.check.validate(valObj);
|
|
166
|
+
}
|
|
167
|
+
catch (errors) {
|
|
168
|
+
if (errors) {
|
|
169
|
+
console.error('Error in Pub Check (' + publication + ')', errors);
|
|
170
|
+
return;
|
|
359
171
|
}
|
|
360
172
|
}
|
|
361
173
|
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
174
|
+
}
|
|
175
|
+
let sub = that._subscriptions.filter(a => a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData))[0];
|
|
176
|
+
// If sub found (another user watching same data), add client to same sub
|
|
177
|
+
if (sub) {
|
|
178
|
+
sub.clients.push({
|
|
179
|
+
id_user: ws['id_user'],
|
|
180
|
+
messageId: messageId,
|
|
181
|
+
id_socket: ws['id_socket']
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
// If sub not found, create new sub
|
|
185
|
+
else {
|
|
186
|
+
that._subscriptions.push({
|
|
187
|
+
publication: publication,
|
|
188
|
+
subscriptionData: subscriptionData,
|
|
189
|
+
collections: that.getPublicationCollections(publication),
|
|
190
|
+
clients: [{
|
|
191
|
+
id_user: ws['id_user'],
|
|
192
|
+
messageId: messageId,
|
|
193
|
+
id_socket: ws['id_socket']
|
|
194
|
+
}]
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
if (!sub) {
|
|
198
|
+
sub = that._subscriptions.filter(a => a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData))[0];
|
|
199
|
+
}
|
|
200
|
+
// console.log('Subscribe', new Date(), 'Success', sub);
|
|
201
|
+
// Send pub data to client who just subscribed only, don't want to send to existing clients since nothing has changed
|
|
202
|
+
that.sendPubDataOnce(ws, messageId, sub, 'newSub', that.getPublicationCollections(publication)[0]);
|
|
203
|
+
if (that._publications[sub.publication].preFunction && !sub.preSubscriptionData) {
|
|
204
|
+
sub.preSubscriptionData = await that._publications[sub.publication].preFunction(...sub.subscriptionData);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (publication === 'appversion') {
|
|
208
|
+
let newLoggedInUser = {
|
|
209
|
+
_id: objectIdHexString(),
|
|
210
|
+
__v: 0,
|
|
211
|
+
date: new Date(),
|
|
212
|
+
id_user: ws['id_user'],
|
|
213
|
+
user: ws['user'],
|
|
214
|
+
id_ws: ws['id_socket']
|
|
215
|
+
};
|
|
216
|
+
this._loggedInUsers.push(newLoggedInUser);
|
|
217
|
+
LoggedInUsers.create(newLoggedInUser);
|
|
218
|
+
if (ws['user'] !== 'Admin' && this.serverConfig['CLIENT_NAME'] !== 'ResolveIO') {
|
|
219
|
+
this._mainServer.getMethodManager().callMethodInternal('supportCreateBillingUser', {
|
|
220
|
+
id_user: ws['id_user'],
|
|
221
|
+
user: ws['user'],
|
|
222
|
+
date: new Date(),
|
|
223
|
+
client: ResolveIOServer.getClientName()
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
// Unsubscribe from publication
|
|
229
|
+
async unsubscribe(messageDate, ws, messageId, publication, ...subscriptionData) {
|
|
230
|
+
let that = this;
|
|
231
|
+
// console.log('Before');
|
|
232
|
+
// console.dir(this._subscriptions.map(a => a.publication));
|
|
233
|
+
if (!that._publications[publication]) {
|
|
234
|
+
console.log('No Publication: ' + publication);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
let sub = that._subscriptions.filter(a => a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData))[0];
|
|
239
|
+
if (sub) {
|
|
240
|
+
for (let i = sub.clients.length - 1; i >= 0; i--) {
|
|
241
|
+
if (sub.clients[i].id_user === ws['id_user'] && sub.clients[i].messageId === messageId && sub.clients[i].id_socket === ws['id_socket']) {
|
|
242
|
+
sub.clients.splice(i, 1);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
366
248
|
// Unsubscribe from publication
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
for (i = userSubs.length - 1; i >= 0; i--) {
|
|
385
|
-
sub = userSubs[i];
|
|
386
|
-
for (j = sub.clients.length - 1; j >= 0; j--) {
|
|
387
|
-
if (sub.clients[j].id_socket === ws['id_socket']) {
|
|
388
|
-
sub.clients.splice(j, 1);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
ws.terminate();
|
|
393
|
-
return [2 /*return*/];
|
|
249
|
+
async unsubscribeAll(ws) {
|
|
250
|
+
let that = this;
|
|
251
|
+
// console.log('Before');
|
|
252
|
+
// console.dir(this._subscriptions.map(a => a.publication));
|
|
253
|
+
let loggedInUser = await LoggedInUsers.findOne({ id_ws: ws['id_socket'] });
|
|
254
|
+
if (loggedInUser) {
|
|
255
|
+
if (this._loggedInUsers.map(a => a._id).indexOf(loggedInUser._id) >= 0) {
|
|
256
|
+
this._loggedInUsers.splice(this._loggedInUsers.map(a => a._id).indexOf(loggedInUser._id), 1);
|
|
257
|
+
}
|
|
258
|
+
LoggedInUsers.deleteOne({ _id: loggedInUser._id });
|
|
259
|
+
}
|
|
260
|
+
let userSubs = that._subscriptions.filter(a => a.clients.some(b => b.id_user === ws['id_user'] && b.id_socket === ws['id_socket']));
|
|
261
|
+
for (let i = userSubs.length - 1; i >= 0; i--) {
|
|
262
|
+
let sub = userSubs[i];
|
|
263
|
+
for (let j = sub.clients.length - 1; j >= 0; j--) {
|
|
264
|
+
if (sub.clients[j].id_socket === ws['id_socket']) {
|
|
265
|
+
sub.clients.splice(j, 1);
|
|
394
266
|
}
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
ws.terminate();
|
|
270
|
+
// console.log('After');
|
|
271
|
+
// console.dir(this._subscriptions.map(a => a.publication));
|
|
272
|
+
}
|
|
398
273
|
// Get publication collection
|
|
399
|
-
|
|
274
|
+
getPublicationCollections(publication) {
|
|
400
275
|
return this._publications[publication].collections;
|
|
401
|
-
}
|
|
276
|
+
}
|
|
402
277
|
// Watch (tail) Mongo's operation log on the entire database (all insert/modify/delete will trigger this function)
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
this._oplog
|
|
406
|
-
|
|
407
|
-
var collection = doc.ns.coll;
|
|
278
|
+
tailOpLog() {
|
|
279
|
+
this._oplog = ResolveIOServer.getMainDB().watch([], { fullDocument: 'updateLookup' });
|
|
280
|
+
this._oplog.on('change', (doc) => {
|
|
281
|
+
let collection = doc.ns.coll;
|
|
408
282
|
if (collection && !collection.endsWith('.versions') && !collection.startsWith('monitor-')) {
|
|
409
283
|
if (doc.operationType === 'insert') {
|
|
410
284
|
if (collection === 'queue-methods') {
|
|
411
|
-
|
|
285
|
+
this._mainServer.getQueueManager().runMethodQueue();
|
|
412
286
|
}
|
|
413
287
|
else if (collection === 'queue-responses') {
|
|
414
|
-
|
|
288
|
+
this._mainServer.getQueueManager().runMethodResponse();
|
|
415
289
|
}
|
|
416
290
|
else {
|
|
417
291
|
if (collection === 'cron-jobs') {
|
|
418
|
-
|
|
292
|
+
this._mainServer.getCronManager().checkCronJobsForUpdates();
|
|
419
293
|
}
|
|
420
294
|
else if (collection === 'support-tickets') {
|
|
421
|
-
if (
|
|
422
|
-
|
|
295
|
+
if (this.serverConfig['ROOT_URL'] === 'https://resolveio.com') {
|
|
296
|
+
this._mainServer.getMethodManager().callMethodInternal('sendSupportTicketEmail', doc.fullDocument._id);
|
|
423
297
|
}
|
|
424
298
|
}
|
|
425
|
-
|
|
299
|
+
this._oplogQueue.push({
|
|
426
300
|
type: 'insert',
|
|
427
301
|
collection: collection,
|
|
428
302
|
doc: doc.fullDocument
|
|
@@ -431,437 +305,370 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
431
305
|
}
|
|
432
306
|
else if (doc.operationType === 'update' || doc.operationType === 'replace') {
|
|
433
307
|
if (collection === 'cron-jobs') {
|
|
434
|
-
|
|
308
|
+
this._mainServer.getCronManager().checkCronJobsForUpdates();
|
|
435
309
|
}
|
|
436
|
-
|
|
310
|
+
this._oplogQueue.push({
|
|
437
311
|
type: 'update',
|
|
438
312
|
collection: collection,
|
|
439
313
|
doc: doc.fullDocument
|
|
440
314
|
});
|
|
441
315
|
}
|
|
442
316
|
else if (doc.operationType === 'delete') {
|
|
443
|
-
|
|
317
|
+
this.resendPubsForDelete(collection);
|
|
444
318
|
if (collection === 'cron-jobs') {
|
|
445
|
-
|
|
319
|
+
this._mainServer.getCronManager().checkCronJobsForUpdates();
|
|
446
320
|
}
|
|
447
321
|
}
|
|
448
322
|
}
|
|
449
323
|
});
|
|
450
|
-
this._oplog.on('error',
|
|
324
|
+
this._oplog.on('error', error => {
|
|
451
325
|
console.log('oplog error', error);
|
|
452
326
|
process.exit();
|
|
453
327
|
});
|
|
454
|
-
this._oplog.on('end',
|
|
328
|
+
this._oplog.on('end', () => {
|
|
455
329
|
console.log('oplog ended');
|
|
456
330
|
process.exit();
|
|
457
331
|
});
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
if (!that._subscriptions.some(function (a) { return a.collections.includes(uniqueOplog_1[i].collection); })) {
|
|
473
|
-
for (var j = this_3._subCache.length - 1; j >= 0; j--) {
|
|
474
|
-
if (this_3._subCache[j].collection === uniqueOplog_1[i].collection) {
|
|
475
|
-
this_3._nodeCache.del(this_3._subCache[j].id);
|
|
476
|
-
this_3._subCache.splice(j, 1);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
uniqueOplog_1.splice(i, 1);
|
|
332
|
+
}
|
|
333
|
+
runOpLogQueue() {
|
|
334
|
+
let that = this;
|
|
335
|
+
setInterval(async () => {
|
|
336
|
+
if (this._oplogQueue.length) {
|
|
337
|
+
let uniqueOplog = deepCopy(this._oplogQueue);
|
|
338
|
+
this._oplogQueue = [];
|
|
339
|
+
let uniquePubs = [];
|
|
340
|
+
for (let i = uniqueOplog.length - 1; i >= 0; i--) {
|
|
341
|
+
if (!that._subscriptions.some(a => a.collections.includes(uniqueOplog[i].collection))) {
|
|
342
|
+
for (let j = this._subCache.length - 1; j >= 0; j--) {
|
|
343
|
+
if (this._subCache[j].collection === uniqueOplog[i].collection) {
|
|
344
|
+
this._nodeCache.del(this._subCache[j].id);
|
|
345
|
+
this._subCache.splice(j, 1);
|
|
480
346
|
}
|
|
481
|
-
};
|
|
482
|
-
this_3 = this;
|
|
483
|
-
for (i = uniqueOplog_1.length - 1; i >= 0; i--) {
|
|
484
|
-
_loop_4(i);
|
|
485
347
|
}
|
|
486
|
-
i
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
sub =
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 4];
|
|
508
|
-
if (!sub.clients.length) return [3 /*break*/, 2];
|
|
509
|
-
_a = sub;
|
|
510
|
-
return [4 /*yield*/, (_b = that._publications[sub.publication]).preFunction.apply(_b, sub.subscriptionData)];
|
|
511
|
-
case 1:
|
|
512
|
-
_a.preSubscriptionData = _d.sent();
|
|
348
|
+
uniqueOplog.splice(i, 1);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
for (let i = uniqueOplog.length - 1; i >= 0; i--) {
|
|
352
|
+
let oplog = uniqueOplog[i];
|
|
353
|
+
for (let j = that._subscriptions.length - 1; j >= 0; j--) {
|
|
354
|
+
let sub = that._subscriptions[j];
|
|
355
|
+
if (sub) {
|
|
356
|
+
if (sub.collections.includes(oplog.collection) && !uniquePubs.filter(a => a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)).length) {
|
|
357
|
+
if (sub.preSubscriptionData) {
|
|
358
|
+
if (that._publications[sub.publication].fetchFunction(oplog.doc, sub.preSubscriptionData)) {
|
|
359
|
+
sub['oplog'] = oplog;
|
|
360
|
+
uniquePubs.push(deepCopy(sub));
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
if (that._publications[sub.publication].preFunction) {
|
|
365
|
+
if (sub.clients.length) {
|
|
366
|
+
sub.preSubscriptionData = await that._publications[sub.publication].preFunction(...sub.subscriptionData);
|
|
513
367
|
if (that._publications[sub.publication].fetchFunction(oplog.doc, sub.preSubscriptionData)) {
|
|
514
368
|
sub['oplog'] = oplog;
|
|
515
|
-
uniquePubs.push(
|
|
369
|
+
uniquePubs.push(deepCopy(sub));
|
|
516
370
|
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
for (
|
|
520
|
-
if (
|
|
521
|
-
|
|
522
|
-
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
for (let i = this._subCache.length - 1; i >= 0; i--) {
|
|
374
|
+
if (this._subCache[i].publication === sub.publication && JSON.stringify(this._subCache[i].subscriptionData) === JSON.stringify(sub.subscriptionData)) {
|
|
375
|
+
this._nodeCache.del(this._subCache[i].id);
|
|
376
|
+
this._subCache.splice(i, 1);
|
|
523
377
|
}
|
|
524
378
|
}
|
|
525
|
-
if (that._subscriptions.findIndex(
|
|
526
|
-
that._subscriptions.splice(that._subscriptions.findIndex(
|
|
527
|
-
}
|
|
528
|
-
_d.label = 3;
|
|
529
|
-
case 3: return [3 /*break*/, 5];
|
|
530
|
-
case 4:
|
|
531
|
-
if (that._publications[sub.publication].fetchFunction) {
|
|
532
|
-
if ((_c = that._publications[sub.publication]).fetchFunction.apply(_c, __spreadArrays([oplog.doc], sub.subscriptionData))) {
|
|
533
|
-
sub['oplog'] = oplog;
|
|
534
|
-
uniquePubs.push(common_1.deepCopy(sub));
|
|
535
|
-
}
|
|
379
|
+
if (that._subscriptions.findIndex(a => a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)) >= 0) {
|
|
380
|
+
that._subscriptions.splice(that._subscriptions.findIndex(a => a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)), 1);
|
|
536
381
|
}
|
|
537
|
-
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
if (that._publications[sub.publication].fetchFunction) {
|
|
386
|
+
if (that._publications[sub.publication].fetchFunction(oplog.doc, ...sub.subscriptionData)) {
|
|
538
387
|
sub['oplog'] = oplog;
|
|
539
|
-
uniquePubs.push(
|
|
388
|
+
uniquePubs.push(deepCopy(sub));
|
|
540
389
|
}
|
|
541
|
-
|
|
542
|
-
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
sub['oplog'] = oplog;
|
|
393
|
+
uniquePubs.push(deepCopy(sub));
|
|
394
|
+
}
|
|
543
395
|
}
|
|
544
|
-
}
|
|
545
|
-
};
|
|
546
|
-
this_4 = this;
|
|
547
|
-
j = that._subscriptions.length - 1;
|
|
548
|
-
_a.label = 2;
|
|
549
|
-
case 2:
|
|
550
|
-
if (!(j >= 0)) return [3 /*break*/, 5];
|
|
551
|
-
return [5 /*yield**/, _loop_5(j)];
|
|
552
|
-
case 3:
|
|
553
|
-
_a.sent();
|
|
554
|
-
_a.label = 4;
|
|
555
|
-
case 4:
|
|
556
|
-
j--;
|
|
557
|
-
return [3 /*break*/, 2];
|
|
558
|
-
case 5:
|
|
559
|
-
i--;
|
|
560
|
-
return [3 /*break*/, 1];
|
|
561
|
-
case 6:
|
|
562
|
-
for (i = 0; i < uniquePubs.length; i++) {
|
|
563
|
-
pub = uniquePubs[i];
|
|
564
|
-
this.checkPubsForChanges(pub['oplog'].collection, pub['oplog'].doc, pub['oplog'].type, pub);
|
|
396
|
+
}
|
|
565
397
|
}
|
|
566
|
-
_a.label = 7;
|
|
567
|
-
case 7: return [2 /*return*/];
|
|
568
|
-
}
|
|
569
|
-
});
|
|
570
|
-
}); }, 100);
|
|
571
|
-
};
|
|
572
|
-
SubscriptionManager.prototype.resendPubsForDelete = function (collection) {
|
|
573
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
574
|
-
var that, subCopy, _loop_6, this_5, i, zz, sub, aa, client, bb, ws;
|
|
575
|
-
var _this = this;
|
|
576
|
-
return __generator(this, function (_a) {
|
|
577
|
-
that = this;
|
|
578
|
-
subCopy = common_1.deepCopy(that._subscriptions.filter(function (a) { return a.collections.includes(collection); }));
|
|
579
|
-
_loop_6 = function (i) {
|
|
580
|
-
if (this_5._subCache[i].collection === collection || subCopy.some(function (a) { return a.publication === _this._subCache[i].publication; })) {
|
|
581
|
-
this_5._nodeCache.del(this_5._subCache[i].id);
|
|
582
|
-
this_5._subCache.splice(i, 1);
|
|
583
398
|
}
|
|
584
|
-
};
|
|
585
|
-
this_5 = this;
|
|
586
|
-
for (i = this._subCache.length - 1; i >= 0; i--) {
|
|
587
|
-
_loop_6(i);
|
|
588
399
|
}
|
|
589
|
-
for (
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
400
|
+
for (let i = 0; i < uniquePubs.length; i++) {
|
|
401
|
+
let pub = uniquePubs[i];
|
|
402
|
+
this.checkPubsForChanges(pub['oplog'].collection, pub['oplog'].doc, pub['oplog'].type, pub);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
}, 100);
|
|
406
|
+
}
|
|
407
|
+
async resendPubsForDelete(collection) {
|
|
408
|
+
let that = this;
|
|
409
|
+
let subCopy = deepCopy(that._subscriptions.filter(a => a.collections.includes(collection)));
|
|
410
|
+
for (let i = this._subCache.length - 1; i >= 0; i--) {
|
|
411
|
+
if (this._subCache[i].collection === collection || subCopy.some(a => a.publication === this._subCache[i].publication)) {
|
|
412
|
+
this._nodeCache.del(this._subCache[i].id);
|
|
413
|
+
this._subCache.splice(i, 1);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
for (let zz = subCopy.length - 1; zz >= 0; zz--) {
|
|
417
|
+
let sub = subCopy[zz];
|
|
418
|
+
if (that._publications[sub.publication].ws_specific) {
|
|
419
|
+
for (let aa = 0; aa < sub.clients.length; aa++) {
|
|
420
|
+
let client = sub.clients[aa];
|
|
421
|
+
for (let bb = 0; bb < that._wss.clients.size; bb++) {
|
|
422
|
+
let ws = Array.from(that._wss.clients)[bb];
|
|
423
|
+
if (ws['id_socket'] === client.id_socket) {
|
|
424
|
+
that.sendPubDataOnce(ws, client.messageId, sub, 'delete', collection);
|
|
600
425
|
}
|
|
601
426
|
}
|
|
602
|
-
else {
|
|
603
|
-
that.sendPubData(sub, 'delete', collection);
|
|
604
|
-
}
|
|
605
427
|
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
that.sendPubData(sub, 'delete', collection);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
610
434
|
// Document: Inserted/Modified Document
|
|
611
435
|
// Collection: Collection Document Lives In
|
|
612
436
|
// Check to see if any pubs need to refetch due to Mongo operation
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
for (j = 0; j < that._wss.clients.size; j++) {
|
|
632
|
-
ws = Array.from(that._wss.clients)[j];
|
|
633
|
-
if (ws['id_socket'] === client.id_socket) {
|
|
634
|
-
that.sendPubDataOnce(ws, client.messageId, sub, type, collection);
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
else {
|
|
640
|
-
for (j = 0; j < that._wss.clients.size; j++) {
|
|
641
|
-
ws = Array.from(that._wss.clients)[j];
|
|
642
|
-
if (ws['id_socket'] === client.id_socket) {
|
|
643
|
-
that.sendPubDataOnce(ws, client.messageId, sub, type, collection);
|
|
644
|
-
}
|
|
437
|
+
async checkPubsForChanges(collection, document, type, sub) {
|
|
438
|
+
let that = this;
|
|
439
|
+
if (sub.preSubscriptionData) {
|
|
440
|
+
if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
|
|
441
|
+
that.sendPubData(sub, type, collection);
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
if (!that._publications[sub.publication].preFunction) {
|
|
446
|
+
if (that._publications[sub.publication].ws_specific) {
|
|
447
|
+
for (let k = 0; k < sub.clients.length; k++) {
|
|
448
|
+
let client = sub.clients[k];
|
|
449
|
+
if (that._publications[sub.publication].fetchFunction) {
|
|
450
|
+
if (that._publications[sub.publication].fetchFunction(document, client.id_user, ...sub.subscriptionData)) {
|
|
451
|
+
for (let j = 0; j < that._wss.clients.size; j++) {
|
|
452
|
+
let ws = Array.from(that._wss.clients)[j];
|
|
453
|
+
if (ws['id_socket'] === client.id_socket) {
|
|
454
|
+
that.sendPubDataOnce(ws, client.messageId, sub, type, collection);
|
|
645
455
|
}
|
|
646
456
|
}
|
|
647
457
|
}
|
|
648
458
|
}
|
|
649
459
|
else {
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
460
|
+
for (let j = 0; j < that._wss.clients.size; j++) {
|
|
461
|
+
let ws = Array.from(that._wss.clients)[j];
|
|
462
|
+
if (ws['id_socket'] === client.id_socket) {
|
|
463
|
+
that.sendPubDataOnce(ws, client.messageId, sub, type, collection);
|
|
653
464
|
}
|
|
654
|
-
// else
|
|
655
|
-
}
|
|
656
|
-
else {
|
|
657
|
-
that.sendPubData(sub, type, collection);
|
|
658
465
|
}
|
|
659
466
|
}
|
|
660
467
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
468
|
+
}
|
|
469
|
+
else {
|
|
470
|
+
if (that._publications[sub.publication].fetchFunction) {
|
|
471
|
+
if (that._publications[sub.publication].fetchFunction(document, ...sub.subscriptionData)) {
|
|
472
|
+
that.sendPubData(sub, type, collection);
|
|
473
|
+
}
|
|
474
|
+
// else
|
|
475
|
+
}
|
|
476
|
+
else {
|
|
477
|
+
that.sendPubData(sub, type, collection);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
665
482
|
// Fetch pub once, send to all clients linked to this pub
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
resolve(true);
|
|
483
|
+
sendPubDataOnce(ws, messageId, subscription, type, collection) {
|
|
484
|
+
return new Promise(async (resolve, reject) => {
|
|
485
|
+
let that = this;
|
|
486
|
+
if (!that._publications[subscription.publication].ws_specific) { // Same pub for all users
|
|
487
|
+
if (this._subCache.some(a => a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData))) {
|
|
488
|
+
let serverRes = {
|
|
489
|
+
messageId: messageId,
|
|
490
|
+
hasError: false,
|
|
491
|
+
data: this._nodeCache.get(this._subCache.filter(a => a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData))[0].id)
|
|
492
|
+
};
|
|
493
|
+
this.sendWS(ws, serverRes);
|
|
494
|
+
resolve(true);
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
if (subscription.publication !== 'superadminAPM' && subscription.publication !== 'loggedInUsers') {
|
|
498
|
+
that._mainServer.getMethodManager().callMethodInternal('insertSubscriptionLog', type, subscription.publication, collection, JSON.stringify(subscription.subscriptionData));
|
|
683
499
|
}
|
|
684
|
-
|
|
685
|
-
if (
|
|
686
|
-
|
|
500
|
+
for (let i = this._subCache.length - 1; i >= 0; i--) {
|
|
501
|
+
if (this._subCache[i].publication === subscription.publication && JSON.stringify(this._subCache[i].subscriptionData) === JSON.stringify(subscription.subscriptionData)) {
|
|
502
|
+
this._nodeCache.del(this._subCache[i].id);
|
|
503
|
+
this._subCache.splice(i, 1);
|
|
687
504
|
}
|
|
688
|
-
|
|
505
|
+
}
|
|
506
|
+
that._publications[subscription.publication].function.call(Object.assign({}, that, SubscriptionManager.prototype), ...subscription.subscriptionData).catch(methodErrs => {
|
|
507
|
+
that._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'Error Detected During Subscription ' + subscription.publication + ' - (sendPubDataOnce - No WS)\n\nData \n' + JSON.stringify(subscription.subscriptionData, null, 2) + '\n\nErrors\n' + JSON.stringify(methodErrs, null, 2));
|
|
508
|
+
}).then(res => {
|
|
509
|
+
let nodeCacheSize = this._nodeCache.getStats().vsize;
|
|
510
|
+
if (nodeCacheSize > 500000000) {
|
|
511
|
+
let neededSizeIndex = 0;
|
|
512
|
+
for (let zz = 0; zz < this._subCache.length; zz++) {
|
|
513
|
+
this._nodeCache.del(this._subCache[zz].id);
|
|
514
|
+
if (this._nodeCache.getStats().vsize < 500000000) {
|
|
515
|
+
neededSizeIndex = zz;
|
|
516
|
+
break;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
// console.log('Cache1: ' + 'Too Big - ' + subscription.publication + ' - ' + getBinarySize(JSON.stringify(this._subCache)));
|
|
520
|
+
this._subCache.splice(0, neededSizeIndex);
|
|
521
|
+
}
|
|
522
|
+
for (let i = this._subCache.length - 1; i >= 0; i--) {
|
|
689
523
|
if (this._subCache[i].publication === subscription.publication && JSON.stringify(this._subCache[i].subscriptionData) === JSON.stringify(subscription.subscriptionData)) {
|
|
690
524
|
this._nodeCache.del(this._subCache[i].id);
|
|
691
525
|
this._subCache.splice(i, 1);
|
|
692
526
|
}
|
|
693
527
|
}
|
|
694
|
-
(
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
_this._nodeCache.del(_this._subCache[zz].id);
|
|
700
|
-
if (_this._nodeCache.getStats().vsize < 500000000) {
|
|
701
|
-
neededSizeIndex = zz;
|
|
702
|
-
break;
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
// console.log('Cache1: ' + 'Too Big - ' + subscription.publication + ' - ' + getBinarySize(JSON.stringify(this._subCache)));
|
|
706
|
-
_this._subCache.splice(0, neededSizeIndex);
|
|
707
|
-
}
|
|
708
|
-
for (var i = _this._subCache.length - 1; i >= 0; i--) {
|
|
709
|
-
if (_this._subCache[i].publication === subscription.publication && JSON.stringify(_this._subCache[i].subscriptionData) === JSON.stringify(subscription.subscriptionData)) {
|
|
710
|
-
_this._nodeCache.del(_this._subCache[i].id);
|
|
711
|
-
_this._subCache.splice(i, 1);
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
if (_this._subscriptions.some(function (a) { return a.collections.includes(collection) && a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); })) {
|
|
715
|
-
var cacheId = _this._cacheId++;
|
|
716
|
-
_this._nodeCache.set(cacheId, res);
|
|
717
|
-
_this._subCache.push({ collection: collection, publication: subscription.publication, subscriptionData: subscription.subscriptionData, id: cacheId });
|
|
718
|
-
var serverRes = {
|
|
719
|
-
messageId: messageId,
|
|
720
|
-
hasError: false,
|
|
721
|
-
data: res
|
|
722
|
-
};
|
|
723
|
-
_this.sendWS(ws, serverRes);
|
|
724
|
-
}
|
|
725
|
-
resolve(true);
|
|
726
|
-
}, function (err) {
|
|
727
|
-
var serverRes = {
|
|
528
|
+
if (this._subscriptions.some(a => a.collections.includes(collection) && a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData))) {
|
|
529
|
+
let cacheId = this._cacheId++;
|
|
530
|
+
this._nodeCache.set(cacheId, res);
|
|
531
|
+
this._subCache.push({ collection: collection, publication: subscription.publication, subscriptionData: subscription.subscriptionData, id: cacheId });
|
|
532
|
+
let serverRes = {
|
|
728
533
|
messageId: messageId,
|
|
729
|
-
hasError:
|
|
730
|
-
data:
|
|
534
|
+
hasError: false,
|
|
535
|
+
data: res
|
|
731
536
|
};
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
});
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
else { // Pub is different for each user (Look at users publication) [MUCH SLOWER, RE-RUNS FOR EACH USER]
|
|
738
|
-
(_b = that._publications[subscription.publication].function).call.apply(_b, __spreadArrays([Object.assign({}, that, SubscriptionManager.prototype), ws['id_user']], subscription.subscriptionData)).then(function (res) {
|
|
739
|
-
var serverRes = {
|
|
740
|
-
messageId: messageId,
|
|
741
|
-
hasError: false,
|
|
742
|
-
data: res
|
|
743
|
-
};
|
|
744
|
-
// console.log('Send Pub Data Once 2', new Date(), 'Success', subscription);
|
|
745
|
-
_this.sendWS(ws, serverRes);
|
|
537
|
+
this.sendWS(ws, serverRes);
|
|
538
|
+
}
|
|
746
539
|
resolve(true);
|
|
747
|
-
},
|
|
748
|
-
|
|
540
|
+
}, err => {
|
|
541
|
+
let serverRes = {
|
|
749
542
|
messageId: messageId,
|
|
750
543
|
hasError: true,
|
|
751
544
|
data: err
|
|
752
545
|
};
|
|
753
|
-
|
|
754
|
-
_this.sendWS(ws, serverRes);
|
|
546
|
+
this.sendWS(ws, serverRes);
|
|
755
547
|
reject(err);
|
|
756
548
|
});
|
|
757
549
|
}
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
550
|
+
}
|
|
551
|
+
else { // Pub is different for each user (Look at users publication) [MUCH SLOWER, RE-RUNS FOR EACH USER]
|
|
552
|
+
that._publications[subscription.publication].function.call(Object.assign({}, that, SubscriptionManager.prototype), ws['id_user'], ...subscription.subscriptionData).catch(methodErrs => {
|
|
553
|
+
that._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'Error Detected During Subscription ' + subscription.publication + ' - (sendPubDataOnce - WS)\n\nData \n' + JSON.stringify(subscription.subscriptionData, null, 2) + '\n\nErrors\n' + JSON.stringify(methodErrs, null, 2));
|
|
554
|
+
}).then(res => {
|
|
555
|
+
let serverRes = {
|
|
556
|
+
messageId: messageId,
|
|
557
|
+
hasError: false,
|
|
558
|
+
data: res
|
|
559
|
+
};
|
|
560
|
+
// console.log('Send Pub Data Once 2', new Date(), 'Success', subscription);
|
|
561
|
+
this.sendWS(ws, serverRes);
|
|
562
|
+
resolve(true);
|
|
563
|
+
}, err => {
|
|
564
|
+
let serverRes = {
|
|
565
|
+
messageId: messageId,
|
|
566
|
+
hasError: true,
|
|
567
|
+
data: err
|
|
568
|
+
};
|
|
569
|
+
// console.log('Send Pub Data Once 2', new Date(), 'Error', subscription);
|
|
570
|
+
this.sendWS(ws, serverRes);
|
|
571
|
+
reject(err);
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
}
|
|
762
576
|
// Fetch pub once, send to all clients linked to this pub
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
if (!subscription.clients.length) {
|
|
772
|
-
for (i = this._subCache.length - 1; i >= 0; i--) {
|
|
773
|
-
if (this._subCache[i].publication === subscription.publication && JSON.stringify(this._subCache[i].subscriptionData) === JSON.stringify(subscription.subscriptionData)) {
|
|
774
|
-
this._nodeCache.del(this._subCache[i].id);
|
|
775
|
-
this._subCache.splice(i, 1);
|
|
776
|
-
}
|
|
577
|
+
sendPubData(subscription, type, collection) {
|
|
578
|
+
return new Promise(async (resolve, reject) => {
|
|
579
|
+
let that = this;
|
|
580
|
+
if (!subscription.clients.length) {
|
|
581
|
+
for (let i = this._subCache.length - 1; i >= 0; i--) {
|
|
582
|
+
if (this._subCache[i].publication === subscription.publication && JSON.stringify(this._subCache[i].subscriptionData) === JSON.stringify(subscription.subscriptionData)) {
|
|
583
|
+
this._nodeCache.del(this._subCache[i].id);
|
|
584
|
+
this._subCache.splice(i, 1);
|
|
777
585
|
}
|
|
778
|
-
|
|
779
|
-
|
|
586
|
+
}
|
|
587
|
+
if (that._subscriptions.findIndex(a => a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData)) >= 0) {
|
|
588
|
+
that._subscriptions.splice(that._subscriptions.findIndex(a => a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData)), 1);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
else {
|
|
592
|
+
if (subscription.publication !== 'superadminAPM' && subscription.publication !== 'loggedInUsers') {
|
|
593
|
+
that._mainServer.getMethodManager().callMethodInternal('insertSubscriptionLog', type, subscription.publication, collection, JSON.stringify(subscription.subscriptionData));
|
|
594
|
+
}
|
|
595
|
+
for (let i = this._subCache.length - 1; i >= 0; i--) {
|
|
596
|
+
if (this._subCache[i].publication === subscription.publication && JSON.stringify(this._subCache[i].subscriptionData) === JSON.stringify(subscription.subscriptionData)) {
|
|
597
|
+
this._nodeCache.del(this._subCache[i].id);
|
|
598
|
+
this._subCache.splice(i, 1);
|
|
780
599
|
}
|
|
781
600
|
}
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
601
|
+
that._publications[subscription.publication].function.call(Object.assign({}, that, SubscriptionManager.prototype), ...subscription.subscriptionData).catch(methodErrs => {
|
|
602
|
+
that._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + that.serverConfig['CLIENT_NAME'], 'Error Detected During Subscription ' + subscription.publication + ' - (sendPubData)\n\nData \n' + JSON.stringify(subscription.subscriptionData, null, 2) + '\n\nErrors\n' + JSON.stringify(methodErrs, null, 2));
|
|
603
|
+
}).then(res => {
|
|
604
|
+
let nodeCacheSize = this._nodeCache.getStats().vsize;
|
|
605
|
+
if (nodeCacheSize > 500000000) {
|
|
606
|
+
let neededSizeIndex = 0;
|
|
607
|
+
for (let zz = 0; zz < this._subCache.length; zz++) {
|
|
608
|
+
this._nodeCache.del(this._subCache[zz].id);
|
|
609
|
+
if (this._nodeCache.getStats().vsize < 500000000) {
|
|
610
|
+
neededSizeIndex = zz;
|
|
611
|
+
break;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
// console.log('Cache: ' + 'Too Big - ' + subscription.publication + ' - ' + getBinarySize(JSON.stringify(this._subCache)));
|
|
615
|
+
this._subCache.splice(0, neededSizeIndex);
|
|
785
616
|
}
|
|
786
|
-
for (i = this._subCache.length - 1; i >= 0; i--) {
|
|
617
|
+
for (let i = this._subCache.length - 1; i >= 0; i--) {
|
|
787
618
|
if (this._subCache[i].publication === subscription.publication && JSON.stringify(this._subCache[i].subscriptionData) === JSON.stringify(subscription.subscriptionData)) {
|
|
788
619
|
this._nodeCache.del(this._subCache[i].id);
|
|
789
620
|
this._subCache.splice(i, 1);
|
|
790
621
|
}
|
|
791
622
|
}
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
var neededSizeIndex = 0;
|
|
796
|
-
for (var zz = 0; zz < _this._subCache.length; zz++) {
|
|
797
|
-
_this._nodeCache.del(_this._subCache[zz].id);
|
|
798
|
-
if (_this._nodeCache.getStats().vsize < 500000000) {
|
|
799
|
-
neededSizeIndex = zz;
|
|
800
|
-
break;
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
// console.log('Cache: ' + 'Too Big - ' + subscription.publication + ' - ' + getBinarySize(JSON.stringify(this._subCache)));
|
|
804
|
-
_this._subCache.splice(0, neededSizeIndex);
|
|
805
|
-
}
|
|
806
|
-
for (var i = _this._subCache.length - 1; i >= 0; i--) {
|
|
807
|
-
if (_this._subCache[i].publication === subscription.publication && JSON.stringify(_this._subCache[i].subscriptionData) === JSON.stringify(subscription.subscriptionData)) {
|
|
808
|
-
_this._nodeCache.del(_this._subCache[i].id);
|
|
809
|
-
_this._subCache.splice(i, 1);
|
|
810
|
-
}
|
|
623
|
+
if (!subscription.clients.length) {
|
|
624
|
+
if (that._subscriptions.findIndex(a => a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData)) >= 0) {
|
|
625
|
+
that._subscriptions.splice(that._subscriptions.findIndex(a => a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData)), 1);
|
|
811
626
|
}
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
data: res
|
|
829
|
-
};
|
|
830
|
-
_this.sendWS(ws, serverRes);
|
|
831
|
-
}
|
|
832
|
-
});
|
|
627
|
+
}
|
|
628
|
+
else {
|
|
629
|
+
if (this._subscriptions.some(a => a.collections.includes(collection) && a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData))) {
|
|
630
|
+
let cacheId = this._cacheId++;
|
|
631
|
+
this._nodeCache.set(cacheId, res);
|
|
632
|
+
this._subCache.push({ collection: collection, publication: subscription.publication, subscriptionData: subscription.subscriptionData, id: cacheId });
|
|
633
|
+
subscription.clients.forEach(client => {
|
|
634
|
+
that._wss.clients.forEach(ws => {
|
|
635
|
+
if (ws['id_socket'] === client.id_socket) {
|
|
636
|
+
let serverRes = {
|
|
637
|
+
messageId: client.messageId,
|
|
638
|
+
hasError: false,
|
|
639
|
+
data: res
|
|
640
|
+
};
|
|
641
|
+
this.sendWS(ws, serverRes);
|
|
642
|
+
}
|
|
833
643
|
});
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
resolve(true);
|
|
837
|
-
}, function (err) {
|
|
838
|
-
subscription.clients.forEach(function (client) {
|
|
839
|
-
that._wss.clients.forEach(function (ws) {
|
|
840
|
-
if (ws['id_socket'] === client.id_socket) {
|
|
841
|
-
var serverRes = {
|
|
842
|
-
messageId: client.messageId,
|
|
843
|
-
hasError: true,
|
|
844
|
-
data: err
|
|
845
|
-
};
|
|
846
|
-
_this.sendWS(ws, serverRes);
|
|
847
|
-
}
|
|
848
644
|
});
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
resolve(true);
|
|
648
|
+
}, err => {
|
|
649
|
+
subscription.clients.forEach(client => {
|
|
650
|
+
that._wss.clients.forEach(ws => {
|
|
651
|
+
if (ws['id_socket'] === client.id_socket) {
|
|
652
|
+
let serverRes = {
|
|
653
|
+
messageId: client.messageId,
|
|
654
|
+
hasError: true,
|
|
655
|
+
data: err
|
|
656
|
+
};
|
|
657
|
+
this.sendWS(ws, serverRes);
|
|
658
|
+
}
|
|
849
659
|
});
|
|
850
|
-
reject(err);
|
|
851
660
|
});
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
}
|
|
855
|
-
});
|
|
856
|
-
}
|
|
857
|
-
|
|
661
|
+
reject(err);
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
sendWS(ws, data) {
|
|
858
667
|
this._sendQueue.splice(0, 0, {
|
|
859
668
|
id_ws: ws['id_socket'],
|
|
860
669
|
data: data
|
|
861
670
|
});
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
}());
|
|
865
|
-
exports.SubscriptionManager = SubscriptionManager;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
866
673
|
|
|
867
674
|
//# sourceMappingURL=subscription.manager.js.map
|