@resolveio/server-lib 6.3.4 → 6.3.5-newrole
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/collections/user.collection.js +39 -32
- package/collections/user.collection.js.map +1 -1
- package/managers/subscription.manager.js +246 -312
- package/managers/subscription.manager.js.map +1 -1
- package/methods/accounts.js.map +1 -1
- package/methods/cron-jobs.js.map +1 -1
- package/package.json +1 -1
|
@@ -147,10 +147,10 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
147
147
|
switch (_a.label) {
|
|
148
148
|
case 0:
|
|
149
149
|
loggedInUser = userCopy[i];
|
|
150
|
-
if (!(!loggedInUser.date || moment().diff(moment(loggedInUser.date), 'seconds') >= 60)) return [3 /*break*/,
|
|
150
|
+
if (!(!loggedInUser.date || moment().diff(moment(loggedInUser.date), 'seconds') >= 60)) return [3 /*break*/, 3];
|
|
151
151
|
if (!this_1._mainServer.getWS(loggedInUser.id_ws)) return [3 /*break*/, 1];
|
|
152
152
|
this_1.unsubscribeAll(this_1._mainServer.getWS(loggedInUser.id_ws));
|
|
153
|
-
return [3 /*break*/,
|
|
153
|
+
return [3 /*break*/, 3];
|
|
154
154
|
case 1:
|
|
155
155
|
this_1._subscriptions.forEach(function (sub) {
|
|
156
156
|
for (var j = sub.clients.length - 1; j >= 0; j--) {
|
|
@@ -162,15 +162,12 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
162
162
|
});
|
|
163
163
|
return [4 /*yield*/, logged_in_users_collection_1.LoggedInUsers.findById(loggedInUser._id)];
|
|
164
164
|
case 2:
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
_a.sent();
|
|
169
|
-
_a.label = 4;
|
|
170
|
-
case 4:
|
|
165
|
+
if (_a.sent()) {
|
|
166
|
+
logged_in_users_collection_1.LoggedInUsers.deleteOne({ _id: loggedInUser._id }).exec();
|
|
167
|
+
}
|
|
171
168
|
this_1._loggedInUsers.splice(i, 1);
|
|
172
|
-
_a.label =
|
|
173
|
-
case
|
|
169
|
+
_a.label = 3;
|
|
170
|
+
case 3: return [2 /*return*/];
|
|
174
171
|
}
|
|
175
172
|
});
|
|
176
173
|
};
|
|
@@ -235,80 +232,78 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
235
232
|
subscriptionData[_i - 4] = arguments[_i];
|
|
236
233
|
}
|
|
237
234
|
return __awaiter(this, void 0, void 0, function () {
|
|
238
|
-
var that, pub, valObj, valKeys, rootKeys, i, sub,
|
|
239
|
-
var
|
|
240
|
-
return __generator(this, function (
|
|
241
|
-
switch (
|
|
235
|
+
var that, pub, valObj, valKeys, rootKeys, i, sub, newLoggedInUser, begDate, endDate, billUser;
|
|
236
|
+
var _a;
|
|
237
|
+
return __generator(this, function (_b) {
|
|
238
|
+
switch (_b.label) {
|
|
242
239
|
case 0:
|
|
243
240
|
that = this;
|
|
244
241
|
pub = that._publications[publication];
|
|
245
|
-
if (
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
if (
|
|
251
|
-
|
|
252
|
-
|
|
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];
|
|
242
|
+
if (!pub) {
|
|
243
|
+
console.error('No Publication: ' + publication);
|
|
244
|
+
return [2 /*return*/];
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
if (subscriptionData.length > 1 || subscriptionData[0]) {
|
|
248
|
+
if (!pub.check) {
|
|
249
|
+
console.error('No Check Function For Pub ' + publication);
|
|
250
|
+
return [2 /*return*/];
|
|
264
251
|
}
|
|
265
|
-
|
|
266
|
-
|
|
252
|
+
else if (!pub.check._schema) {
|
|
253
|
+
console.error('No Check Schema For Pub ' + publication);
|
|
254
|
+
return [2 /*return*/];
|
|
267
255
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
256
|
+
else {
|
|
257
|
+
valObj = {};
|
|
258
|
+
valKeys = Object.keys(pub.check._schema);
|
|
259
|
+
rootKeys = valKeys.filter(function (a) { return !a.includes('.'); });
|
|
260
|
+
for (i = 0; i < subscriptionData.length; i++) {
|
|
261
|
+
valObj[rootKeys[i]] = subscriptionData[i];
|
|
262
|
+
}
|
|
263
|
+
try {
|
|
264
|
+
pub.check.validate(valObj);
|
|
265
|
+
}
|
|
266
|
+
catch (errors) {
|
|
267
|
+
if (errors) {
|
|
268
|
+
console.error('Error in Pub Check (' + publication + ')', errors);
|
|
269
|
+
return [2 /*return*/];
|
|
270
|
+
}
|
|
272
271
|
}
|
|
273
272
|
}
|
|
274
273
|
}
|
|
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
274
|
sub = that._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
|
|
275
|
+
// If sub found (another user watching same data), add client to same sub
|
|
276
|
+
if (sub) {
|
|
277
|
+
sub.clients.push({
|
|
278
|
+
id_user: ws['id_user'],
|
|
279
|
+
messageId: messageId,
|
|
280
|
+
id_socket: ws['id_socket']
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
// If sub not found, create new sub
|
|
284
|
+
else {
|
|
285
|
+
that._subscriptions.push({
|
|
286
|
+
publication: publication,
|
|
287
|
+
subscriptionData: subscriptionData,
|
|
288
|
+
collections: that.getPublicationCollections(publication),
|
|
289
|
+
clients: [{
|
|
290
|
+
id_user: ws['id_user'],
|
|
291
|
+
messageId: messageId,
|
|
292
|
+
id_socket: ws['id_socket']
|
|
293
|
+
}]
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
if (!sub) {
|
|
297
|
+
sub = that._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
|
|
298
|
+
}
|
|
299
|
+
// console.log('Subscribe', new Date(), 'Success', sub);
|
|
300
|
+
// Send pub data to client who just subscribed only, don't want to send to existing clients since nothing has changed
|
|
301
|
+
that.sendPubDataOnce(ws, messageId, sub, 'newSub', that.getPublicationCollections(publication)[0]);
|
|
302
|
+
if (that._publications[sub.publication].preFunction && !sub.preSubscriptionData) {
|
|
303
|
+
sub.preSubscriptionData = (_a = that._publications[sub.publication]).preFunction.apply(_a, sub.subscriptionData);
|
|
304
|
+
}
|
|
300
305
|
}
|
|
301
|
-
|
|
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')) return [3 /*break*/, 5];
|
|
306
|
+
if (!(publication === 'appversion')) return [3 /*break*/, 2];
|
|
312
307
|
newLoggedInUser = {
|
|
313
308
|
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
314
309
|
__v: 0,
|
|
@@ -319,7 +314,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
319
314
|
};
|
|
320
315
|
this._loggedInUsers.push(newLoggedInUser);
|
|
321
316
|
logged_in_users_collection_1.LoggedInUsers.create(newLoggedInUser);
|
|
322
|
-
if (!(ws['user'] !== 'Admin' && index_1.ResolveIOServer.getSupportDB())) return [3 /*break*/,
|
|
317
|
+
if (!(ws['user'] !== 'Admin' && index_1.ResolveIOServer.getSupportDB())) return [3 /*break*/, 2];
|
|
323
318
|
begDate = moment().startOf('month');
|
|
324
319
|
endDate = moment().endOf('month');
|
|
325
320
|
return [4 /*yield*/, billing_logged_in_users_collection_1.BillingLoggedInUsers.findOne({
|
|
@@ -338,8 +333,8 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
338
333
|
}
|
|
339
334
|
]
|
|
340
335
|
})];
|
|
341
|
-
case
|
|
342
|
-
billUser =
|
|
336
|
+
case 1:
|
|
337
|
+
billUser = _b.sent();
|
|
343
338
|
if (!billUser) {
|
|
344
339
|
billing_logged_in_users_collection_1.BillingLoggedInUsers.create({
|
|
345
340
|
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
@@ -350,8 +345,8 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
350
345
|
client: index_1.ResolveIOServer.getClientName()
|
|
351
346
|
});
|
|
352
347
|
}
|
|
353
|
-
|
|
354
|
-
case
|
|
348
|
+
_b.label = 2;
|
|
349
|
+
case 2: return [2 /*return*/];
|
|
355
350
|
}
|
|
356
351
|
});
|
|
357
352
|
});
|
|
@@ -515,79 +510,61 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
515
510
|
setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
516
511
|
var uniqueOplog_1, uniquePubs, _loop_4, i, _loop_5, this_3, i, i, pub;
|
|
517
512
|
return __generator(this, function (_a) {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
if (!that._subscriptions.some(function (a) { return a.collections.includes(uniqueOplog_1[i].collection); })) {
|
|
526
|
-
uniqueOplog_1.splice(i, 1);
|
|
527
|
-
}
|
|
528
|
-
};
|
|
529
|
-
for (i = uniqueOplog_1.length - 1; i >= 0; i--) {
|
|
530
|
-
_loop_4(i);
|
|
513
|
+
if (this._oplogQueue.length) {
|
|
514
|
+
uniqueOplog_1 = common_1.deepCopy(this._oplogQueue);
|
|
515
|
+
this._oplogQueue = [];
|
|
516
|
+
uniquePubs = [];
|
|
517
|
+
_loop_4 = function (i) {
|
|
518
|
+
if (!that._subscriptions.some(function (a) { return a.collections.includes(uniqueOplog_1[i].collection); })) {
|
|
519
|
+
uniqueOplog_1.splice(i, 1);
|
|
531
520
|
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
}
|
|
521
|
+
};
|
|
522
|
+
for (i = uniqueOplog_1.length - 1; i >= 0; i--) {
|
|
523
|
+
_loop_4(i);
|
|
524
|
+
}
|
|
525
|
+
_loop_5 = function (i) {
|
|
526
|
+
var oplog = uniqueOplog_1[i];
|
|
527
|
+
var _loop_6 = function (j) {
|
|
528
|
+
var _a;
|
|
529
|
+
var sub = that._subscriptions[j];
|
|
530
|
+
if (sub) {
|
|
531
|
+
if (sub.collections.includes(oplog.collection)) {
|
|
532
|
+
if (sub.preSubscriptionData) {
|
|
533
|
+
if (that._publications[sub.publication].fetchFunction(oplog.doc, sub.preSubscriptionData)) {
|
|
534
|
+
if (!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData) && JSON.stringify(oplog) === JSON.stringify(a.oplog); }).length) {
|
|
535
|
+
if (!sub.clients.length) {
|
|
536
|
+
that._subscriptions.splice(j, 1);
|
|
537
|
+
}
|
|
538
|
+
else {
|
|
539
|
+
sub['oplog'] = oplog;
|
|
540
|
+
uniquePubs.push(common_1.deepCopy(sub));
|
|
553
541
|
}
|
|
554
|
-
return "continue";
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
if (that._publications[sub.publication].preFunction) {
|
|
558
|
-
if (!sub.clients.length) {
|
|
559
|
-
that._subscriptions.splice(j, 1);
|
|
560
542
|
if (this_3._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
561
543
|
this_3._nodeCache.del(this_3._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
562
544
|
this_3._subCache.splice(this_3._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
563
545
|
}
|
|
564
546
|
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
547
|
+
return "continue";
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
if (that._publications[sub.publication].preFunction) {
|
|
551
|
+
if (!sub.clients.length) {
|
|
552
|
+
that._subscriptions.splice(j, 1);
|
|
553
|
+
if (this_3._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
554
|
+
this_3._nodeCache.del(this_3._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
555
|
+
this_3._subCache.splice(this_3._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
570
556
|
}
|
|
571
557
|
}
|
|
572
558
|
else {
|
|
573
|
-
if (
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
if (!sub.clients.length) {
|
|
577
|
-
that._subscriptions.splice(j, 1);
|
|
578
|
-
if (this_3._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
579
|
-
this_3._nodeCache.del(this_3._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
580
|
-
this_3._subCache.splice(this_3._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
else {
|
|
584
|
-
sub['oplog'] = oplog;
|
|
585
|
-
uniquePubs.push(common_1.deepCopy(sub));
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
}
|
|
559
|
+
if (!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData) && JSON.stringify(oplog) === JSON.stringify(a.oplog); }).length) {
|
|
560
|
+
sub['oplog'] = oplog;
|
|
561
|
+
uniquePubs.push(common_1.deepCopy(sub));
|
|
589
562
|
}
|
|
590
|
-
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
else {
|
|
566
|
+
if (that._publications[sub.publication].fetchFunction) {
|
|
567
|
+
if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, __spreadArrays([oplog.doc], sub.subscriptionData))) {
|
|
591
568
|
if (!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }).length) {
|
|
592
569
|
if (!sub.clients.length) {
|
|
593
570
|
that._subscriptions.splice(j, 1);
|
|
@@ -603,31 +580,39 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
603
580
|
}
|
|
604
581
|
}
|
|
605
582
|
}
|
|
583
|
+
else {
|
|
584
|
+
if (!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }).length) {
|
|
585
|
+
if (!sub.clients.length) {
|
|
586
|
+
that._subscriptions.splice(j, 1);
|
|
587
|
+
if (this_3._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
588
|
+
this_3._nodeCache.del(this_3._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
589
|
+
this_3._subCache.splice(this_3._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
else {
|
|
593
|
+
sub['oplog'] = oplog;
|
|
594
|
+
uniquePubs.push(common_1.deepCopy(sub));
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
}
|
|
606
598
|
}
|
|
607
599
|
}
|
|
608
|
-
};
|
|
609
|
-
for (var j = that._subscriptions.length - 1; j >= 0; j--) {
|
|
610
|
-
_loop_6(j);
|
|
611
600
|
}
|
|
612
601
|
};
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
_loop_5(i);
|
|
602
|
+
for (var j = that._subscriptions.length - 1; j >= 0; j--) {
|
|
603
|
+
_loop_6(j);
|
|
616
604
|
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
605
|
+
};
|
|
606
|
+
this_3 = this;
|
|
607
|
+
for (i = uniqueOplog_1.length - 1; i >= 0; i--) {
|
|
608
|
+
_loop_5(i);
|
|
609
|
+
}
|
|
610
|
+
for (i = 0; i < uniquePubs.length; i++) {
|
|
621
611
|
pub = uniquePubs[i];
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
_a.sent();
|
|
625
|
-
_a.label = 3;
|
|
626
|
-
case 3:
|
|
627
|
-
i++;
|
|
628
|
-
return [3 /*break*/, 1];
|
|
629
|
-
case 4: return [2 /*return*/];
|
|
612
|
+
this.checkPubsForChanges(pub['oplog'].collection, pub['oplog'].doc, pub['oplog'].type, pub);
|
|
613
|
+
}
|
|
630
614
|
}
|
|
615
|
+
return [2 /*return*/];
|
|
631
616
|
});
|
|
632
617
|
}); }, 250);
|
|
633
618
|
};
|
|
@@ -636,76 +621,46 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
636
621
|
var that, subCopy, _loop_7, this_4, jj, _loop_8, zz;
|
|
637
622
|
var _this = this;
|
|
638
623
|
return __generator(this, function (_a) {
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
624
|
+
that = this;
|
|
625
|
+
subCopy = common_1.deepCopy(that._subscriptions.filter(function (a) { return a.collections.includes(collection); }));
|
|
626
|
+
_loop_7 = function (jj) {
|
|
627
|
+
if (this_4._subCache[jj].collection === collection || subCopy.some(function (a) { return a.publication === _this._subCache[jj].publication; })) {
|
|
628
|
+
this_4._nodeCache.del(this_4._subCache[jj].id);
|
|
629
|
+
this_4._subCache.splice(jj, 1);
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
this_4 = this;
|
|
633
|
+
for (jj = this._subCache.length - 1; jj >= 0; jj--) {
|
|
634
|
+
_loop_7(jj);
|
|
635
|
+
}
|
|
636
|
+
_loop_8 = function (zz) {
|
|
637
|
+
var sub = subCopy[zz];
|
|
638
|
+
if (that._publications[sub.publication].ws_specific) {
|
|
639
|
+
for (var aa = 0; aa < sub.clients.length; aa++) {
|
|
640
|
+
var client = sub.clients[aa];
|
|
641
|
+
for (var bb = 0; bb < that._wss.clients.size; bb++) {
|
|
642
|
+
var ws = Array.from(that._wss.clients)[bb];
|
|
643
|
+
if (ws['id_socket'] === client.id_socket) {
|
|
644
|
+
that.sendPubDataOnce(ws, client.messageId, sub, 'delete', collection);
|
|
645
|
+
}
|
|
647
646
|
}
|
|
648
|
-
};
|
|
649
|
-
this_4 = this;
|
|
650
|
-
for (jj = this._subCache.length - 1; jj >= 0; jj--) {
|
|
651
|
-
_loop_7(jj);
|
|
652
647
|
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
case 2:
|
|
668
|
-
if (!(bb < that._wss.clients.size)) return [3 /*break*/, 5];
|
|
669
|
-
ws = Array.from(that._wss.clients)[bb];
|
|
670
|
-
if (!(ws['id_socket'] === client.id_socket)) return [3 /*break*/, 4];
|
|
671
|
-
return [4 /*yield*/, that.sendPubDataOnce(ws, client.messageId, sub, 'delete', collection)];
|
|
672
|
-
case 3:
|
|
673
|
-
_a.sent();
|
|
674
|
-
_a.label = 4;
|
|
675
|
-
case 4:
|
|
676
|
-
bb++;
|
|
677
|
-
return [3 /*break*/, 2];
|
|
678
|
-
case 5:
|
|
679
|
-
aa++;
|
|
680
|
-
return [3 /*break*/, 1];
|
|
681
|
-
case 6: return [3 /*break*/, 10];
|
|
682
|
-
case 7:
|
|
683
|
-
if (!!sub.clients.length) return [3 /*break*/, 8];
|
|
684
|
-
if (that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
685
|
-
that._subscriptions.splice(that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
686
|
-
}
|
|
687
|
-
return [3 /*break*/, 10];
|
|
688
|
-
case 8: return [4 /*yield*/, that.sendPubData(sub, 'delete', collection)];
|
|
689
|
-
case 9:
|
|
690
|
-
_a.sent();
|
|
691
|
-
_a.label = 10;
|
|
692
|
-
case 10: return [2 /*return*/];
|
|
693
|
-
}
|
|
694
|
-
});
|
|
695
|
-
};
|
|
696
|
-
zz = subCopy.length - 1;
|
|
697
|
-
_a.label = 1;
|
|
698
|
-
case 1:
|
|
699
|
-
if (!(zz >= 0)) return [3 /*break*/, 4];
|
|
700
|
-
return [5 /*yield**/, _loop_8(zz)];
|
|
701
|
-
case 2:
|
|
702
|
-
_a.sent();
|
|
703
|
-
_a.label = 3;
|
|
704
|
-
case 3:
|
|
705
|
-
zz--;
|
|
706
|
-
return [3 /*break*/, 1];
|
|
707
|
-
case 4: return [2 /*return*/];
|
|
648
|
+
}
|
|
649
|
+
else {
|
|
650
|
+
if (!sub.clients.length) {
|
|
651
|
+
if (that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
652
|
+
that._subscriptions.splice(that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
else {
|
|
656
|
+
that.sendPubData(sub, 'delete', collection);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
for (zz = subCopy.length - 1; zz >= 0; zz--) {
|
|
661
|
+
_loop_8(zz);
|
|
708
662
|
}
|
|
663
|
+
return [2 /*return*/];
|
|
709
664
|
});
|
|
710
665
|
});
|
|
711
666
|
};
|
|
@@ -720,99 +675,78 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
720
675
|
switch (_d.label) {
|
|
721
676
|
case 0:
|
|
722
677
|
that = this;
|
|
723
|
-
if (
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
678
|
+
if (sub.preSubscriptionData) {
|
|
679
|
+
if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
|
|
680
|
+
if (this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
681
|
+
this._nodeCache.del(this._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
682
|
+
this._subCache.splice(this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
683
|
+
}
|
|
684
|
+
that.sendPubData(sub, type, collection);
|
|
685
|
+
return [2 /*return*/];
|
|
686
|
+
}
|
|
728
687
|
}
|
|
729
|
-
return [
|
|
730
|
-
case 1:
|
|
731
|
-
_d.sent();
|
|
732
|
-
return [2 /*return*/];
|
|
733
|
-
case 2:
|
|
734
|
-
if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 6];
|
|
688
|
+
if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 2];
|
|
735
689
|
_a = sub;
|
|
736
690
|
return [4 /*yield*/, that._publications[sub.publication].preFunction(sub.subscriptionData)];
|
|
737
|
-
case
|
|
691
|
+
case 1:
|
|
738
692
|
_a.preSubscriptionData = _d.sent();
|
|
739
|
-
if (
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
case 4:
|
|
746
|
-
_d.sent();
|
|
747
|
-
_d.label = 5;
|
|
748
|
-
case 5: return [3 /*break*/, 23];
|
|
749
|
-
case 6:
|
|
750
|
-
if (!that._publications[sub.publication].ws_specific) return [3 /*break*/, 18];
|
|
751
|
-
if (this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
752
|
-
this._nodeCache.del(this._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
753
|
-
this._subCache.splice(this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
693
|
+
if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
|
|
694
|
+
if (this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
695
|
+
this._nodeCache.del(this._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
696
|
+
this._subCache.splice(this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
697
|
+
}
|
|
698
|
+
that.sendPubData(sub, type, collection);
|
|
754
699
|
}
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
return [4 /*yield*/, that.sendPubDataOnce(ws, client.messageId, sub, type, collection)];
|
|
784
|
-
case 14:
|
|
785
|
-
_d.sent();
|
|
786
|
-
_d.label = 15;
|
|
787
|
-
case 15:
|
|
788
|
-
j++;
|
|
789
|
-
return [3 /*break*/, 13];
|
|
790
|
-
case 16:
|
|
791
|
-
k++;
|
|
792
|
-
return [3 /*break*/, 7];
|
|
793
|
-
case 17: return [3 /*break*/, 23];
|
|
794
|
-
case 18:
|
|
795
|
-
if (!that._publications[sub.publication].fetchFunction) return [3 /*break*/, 21];
|
|
796
|
-
if (!(_c = that._publications[sub.publication]).fetchFunction.apply(_c, __spreadArrays([document], sub.subscriptionData))) return [3 /*break*/, 20];
|
|
797
|
-
if (this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
798
|
-
this._nodeCache.del(this._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
799
|
-
this._subCache.splice(this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
700
|
+
return [3 /*break*/, 3];
|
|
701
|
+
case 2:
|
|
702
|
+
if (that._publications[sub.publication].ws_specific) {
|
|
703
|
+
if (this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
704
|
+
this._nodeCache.del(this._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
705
|
+
this._subCache.splice(this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
706
|
+
}
|
|
707
|
+
for (k = 0; k < sub.clients.length; k++) {
|
|
708
|
+
client = sub.clients[k];
|
|
709
|
+
if (that._publications[sub.publication].fetchFunction) {
|
|
710
|
+
if ((_b = that._publications[sub.publication]).fetchFunction.apply(_b, __spreadArrays([document, client.id_user], sub.subscriptionData))) {
|
|
711
|
+
for (j = 0; j < that._wss.clients.size; j++) {
|
|
712
|
+
ws = Array.from(that._wss.clients)[j];
|
|
713
|
+
if (ws['id_socket'] === client.id_socket) {
|
|
714
|
+
that.sendPubDataOnce(ws, client.messageId, sub, type, collection);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
else {
|
|
720
|
+
for (j = 0; j < that._wss.clients.size; j++) {
|
|
721
|
+
ws = Array.from(that._wss.clients)[j];
|
|
722
|
+
if (ws['id_socket'] === client.id_socket) {
|
|
723
|
+
that.sendPubDataOnce(ws, client.messageId, sub, type, collection);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
}
|
|
800
728
|
}
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
729
|
+
else {
|
|
730
|
+
if (that._publications[sub.publication].fetchFunction) {
|
|
731
|
+
if ((_c = that._publications[sub.publication]).fetchFunction.apply(_c, __spreadArrays([document], sub.subscriptionData))) {
|
|
732
|
+
if (this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
733
|
+
this._nodeCache.del(this._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
734
|
+
this._subCache.splice(this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
735
|
+
}
|
|
736
|
+
that.sendPubData(sub, type, collection);
|
|
737
|
+
}
|
|
738
|
+
// else
|
|
739
|
+
}
|
|
740
|
+
else {
|
|
741
|
+
if (this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
742
|
+
this._nodeCache.del(this._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
743
|
+
this._subCache.splice(this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
744
|
+
}
|
|
745
|
+
that.sendPubData(sub, type, collection);
|
|
746
|
+
}
|
|
810
747
|
}
|
|
811
|
-
|
|
812
|
-
case
|
|
813
|
-
_d.sent();
|
|
814
|
-
_d.label = 23;
|
|
815
|
-
case 23: return [2 /*return*/];
|
|
748
|
+
_d.label = 3;
|
|
749
|
+
case 3: return [2 /*return*/];
|
|
816
750
|
}
|
|
817
751
|
});
|
|
818
752
|
});
|