@resolveio/server-lib 4.0.15 → 4.0.16

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.
@@ -0,0 +1,7 @@
1
+ import { Model, Document } from 'mongoose';
2
+ import { LogSubscriptionModel } from '../models/log-subscription.model';
3
+ interface ResolveIOModel extends LogSubscriptionModel, Document {
4
+ }
5
+ export declare const LogSubscriptions: Model<ResolveIOModel>;
6
+ export declare const LogSubscriptionVersions: Model<ResolveIOModel>;
7
+ export {};
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var mongoose_1 = require("mongoose");
4
+ var index_1 = require("../index");
5
+ var schema = {
6
+ _id: {
7
+ type: String,
8
+ optional: true
9
+ },
10
+ __v: {
11
+ type: Number,
12
+ optional: true
13
+ },
14
+ updatedAt: {
15
+ type: Date,
16
+ optional: true
17
+ },
18
+ createdAt: {
19
+ type: Date,
20
+ optional: true
21
+ },
22
+ date: {
23
+ type: Date
24
+ },
25
+ type: {
26
+ type: String
27
+ },
28
+ subscription: {
29
+ type: String
30
+ },
31
+ collection: {
32
+ type: String
33
+ }
34
+ };
35
+ var DefaultSchema = new mongoose_1.Schema(schema, {
36
+ skipVersioning: true,
37
+ versionKey: false,
38
+ timestamps: true
39
+ });
40
+ DefaultSchema.index({ date: 1 }, { expireAfterSeconds: 60 * 60 * 24 * 30 });
41
+ DefaultSchema.index({ type: 1 });
42
+ DefaultSchema.index({ subscription: 1 });
43
+ DefaultSchema.index({ collection_name: 1 });
44
+ DefaultSchema.index({ date: 1, type: 1 });
45
+ exports.LogSubscriptions = index_1.ResolveIOServer.getMainDB().model('log-subscriptions', DefaultSchema);
46
+ schema._id = {
47
+ type: mongoose_1.Schema.Types.Mixed
48
+ };
49
+ var VersionSchema = new mongoose_1.Schema(schema, {
50
+ skipVersioning: true,
51
+ versionKey: false,
52
+ timestamps: true
53
+ });
54
+ exports.LogSubscriptions['versionCollection'] = 'log-subscriptions.versions';
55
+ exports.LogSubscriptionVersions = index_1.ResolveIOServer.getMainDB().model(exports.LogSubscriptions['versionCollection'], VersionSchema);
@@ -51,7 +51,6 @@ var method_responses_1 = require("../publications/method-responses");
51
51
  var support_tickets_1 = require("../publications/support-tickets");
52
52
  var index_1 = require("../index");
53
53
  var notifications_1 = require("../publications/notifications");
54
- var common_1 = require("../util/common");
55
54
  var billing_logged_in_users_collection_1 = require("../collections/billing-logged-in-users.collection");
56
55
  var moment = require("moment");
57
56
  var billing_logged_in_users_1 = require("../publications/billing-logged-in-users");
@@ -201,7 +200,7 @@ var SubscriptionManager = /** @class */ (function () {
201
200
  sub = that._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
202
201
  }
203
202
  // Send pub data to client who just subscribed only, don't want to send to existing clients since nothing has changed
204
- that.sendPubDataOnce(ws, messageId, sub);
203
+ that.sendPubDataOnce(ws, messageId, sub, 'newSub', that.getPublicationCollections(publication)[0]);
205
204
  if (!(that._publications[sub.publication].preFunction && !sub.preSubscriptionData)) return [3 /*break*/, 3];
206
205
  _a = sub;
207
206
  return [4 /*yield*/, (_b = that._publications[sub.publication]).preFunction.apply(_b, sub.subscriptionData)];
@@ -503,29 +502,31 @@ var SubscriptionManager = /** @class */ (function () {
503
502
  SubscriptionManager.prototype.runOpLogQueue = function () {
504
503
  var _this = this;
505
504
  setInterval(function () {
506
- var oplogQueue = common_1.deepCopy(_this._oplogQueue);
507
- var uniqueCollectionOplogQueue = oplogQueue.map(function (a) { return a.collection; }).filter(function (elem, index, self) {
508
- return index === self.indexOf(elem);
509
- });
510
- uniqueCollectionOplogQueue.forEach(function (collection) {
511
- var oplogQueueFiltered = oplogQueue.filter(function (a) { return a.collection === collection; });
512
- if (oplogQueueFiltered.length === 1) {
513
- _this.checkPubsForChanges(oplogQueueFiltered[0].collection, oplogQueueFiltered[0].doc);
514
- _this._oplogQueue.splice(_this._oplogQueue.map(function (a) { return a.collection; }).indexOf(collection), 1);
515
- }
516
- else {
517
- oplogQueueFiltered.forEach(function (item) {
518
- _this.checkPubsForChanges(item.collection, item.doc, true);
519
- });
520
- _this.checkPubsForChanges(oplogQueueFiltered[oplogQueueFiltered.length - 1].collection, oplogQueueFiltered[oplogQueueFiltered.length - 1].doc, false, true);
521
- for (var i = _this._oplogQueue.length - 1; i >= 0; i--) {
522
- var item = _this._oplogQueue[i];
523
- if (item.collection === collection) {
524
- _this._oplogQueue.splice(i, 1);
525
- }
526
- }
527
- }
528
- });
505
+ var oplog = _this._oplogQueue.pop();
506
+ _this.checkPubsForChanges(oplog.collection, oplog.doc, oplog.type);
507
+ // let oplogQueue = deepCopy(this._oplogQueue);
508
+ // let uniqueCollectionOplogQueue = oplogQueue.map(a => a.collection).filter((elem, index, self) => {
509
+ // return index === self.indexOf(elem);
510
+ // });
511
+ // uniqueCollectionOplogQueue.forEach(collection => {
512
+ // let oplogQueueFiltered = oplogQueue.filter(a => a.collection === collection);
513
+ // if (oplogQueueFiltered.length === 1) {
514
+ // this.checkPubsForChanges(oplogQueueFiltered[0].collection, oplogQueueFiltered[0].doc);
515
+ // this._oplogQueue.splice(this._oplogQueue.map(a => a.collection).indexOf(collection), 1);
516
+ // }
517
+ // else {
518
+ // oplogQueueFiltered.forEach(item => {
519
+ // this.checkPubsForChanges(item.collection, item.doc, true);
520
+ // });
521
+ // this.checkPubsForChanges(oplogQueueFiltered[oplogQueueFiltered.length - 1].collection, oplogQueueFiltered[oplogQueueFiltered.length - 1].doc, false, true);
522
+ // for (let i = this._oplogQueue.length - 1; i >= 0; i--) {
523
+ // let item = this._oplogQueue[i];
524
+ // if (item.collection === collection) {
525
+ // this._oplogQueue.splice(i, 1);
526
+ // }
527
+ // }
528
+ // }
529
+ // });
529
530
  }, 25);
530
531
  };
531
532
  SubscriptionManager.prototype.resendPubsForDelete = function (collection) {
@@ -535,20 +536,20 @@ var SubscriptionManager = /** @class */ (function () {
535
536
  sub.clients.forEach(function (client) {
536
537
  that._wss.clients.forEach(function (ws) {
537
538
  if (ws['id_socket'] === client.id_socket) {
538
- that.sendPubDataOnce(ws, client.messageId, sub);
539
+ that.sendPubDataOnce(ws, client.messageId, sub, 'delete', collection);
539
540
  }
540
541
  });
541
542
  });
542
543
  }
543
544
  else {
544
- that.sendPubData(sub);
545
+ that.sendPubData(sub, 'delete', collection);
545
546
  }
546
547
  });
547
548
  };
548
549
  // Document: Inserted/Modified/Deleted Document
549
550
  // Collection: Collection Document Lives In
550
551
  // Check to see if any pubs need to refetch due to Mongo operation
551
- SubscriptionManager.prototype.checkPubsForChanges = function (collection, document, fetchFunctionOnly, noFetchFunction) {
552
+ SubscriptionManager.prototype.checkPubsForChanges = function (collection, document, type, fetchFunctionOnly, noFetchFunction) {
552
553
  var _this = this;
553
554
  if (fetchFunctionOnly === void 0) { fetchFunctionOnly = false; }
554
555
  if (noFetchFunction === void 0) { noFetchFunction = false; }
@@ -574,7 +575,7 @@ var SubscriptionManager = /** @class */ (function () {
574
575
  case 2:
575
576
  if (!sub.preSubscriptionData) return [3 /*break*/, 4];
576
577
  if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 4];
577
- that.sendPubData(sub);
578
+ that.sendPubData(sub, type, collection);
578
579
  _a = sub;
579
580
  return [4 /*yield*/, (_c = that._publications[sub.publication]).preFunction.apply(_c, sub.subscriptionData)];
580
581
  case 3:
@@ -588,7 +589,7 @@ var SubscriptionManager = /** @class */ (function () {
588
589
  case 5:
589
590
  _b.preSubscriptionData = _e.sent();
590
591
  if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
591
- that.sendPubData(sub);
592
+ that.sendPubData(sub, type, collection);
592
593
  }
593
594
  _e.label = 6;
594
595
  case 6: return [3 /*break*/, 8];
@@ -601,7 +602,7 @@ var SubscriptionManager = /** @class */ (function () {
601
602
  if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, [document, client.id_user].concat(sub.subscriptionData))) {
602
603
  that._wss.clients.forEach(function (ws) {
603
604
  if (ws['id_socket'] === client.id_socket) {
604
- that.sendPubDataOnce(ws, client.messageId, sub);
605
+ that.sendPubDataOnce(ws, client.messageId, sub, type, collection);
605
606
  }
606
607
  });
607
608
  }
@@ -610,7 +611,7 @@ var SubscriptionManager = /** @class */ (function () {
610
611
  else if (!fetchFunctionOnly) {
611
612
  that._wss.clients.forEach(function (ws) {
612
613
  if (ws['id_socket'] === client.id_socket) {
613
- that.sendPubDataOnce(ws, client.messageId, sub);
614
+ that.sendPubDataOnce(ws, client.messageId, sub, type, collection);
614
615
  }
615
616
  });
616
617
  }
@@ -620,12 +621,12 @@ var SubscriptionManager = /** @class */ (function () {
620
621
  if (that._publications[sub.publication].fetchFunction) {
621
622
  if (!noFetchFunction) {
622
623
  if ((_d = that._publications[sub.publication]).fetchFunction.apply(_d, [document].concat(sub.subscriptionData))) {
623
- that.sendPubData(sub);
624
+ that.sendPubData(sub, type, collection);
624
625
  }
625
626
  }
626
627
  }
627
628
  else if (!fetchFunctionOnly) {
628
- that.sendPubData(sub);
629
+ that.sendPubData(sub, type, collection);
629
630
  }
630
631
  }
631
632
  _e.label = 8;
@@ -658,7 +659,7 @@ var SubscriptionManager = /** @class */ (function () {
658
659
  case 2:
659
660
  if (!sub.preSubscriptionData) return [3 /*break*/, 4];
660
661
  if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 4];
661
- that.sendPubData(sub);
662
+ that.sendPubData(sub, 'support', collection);
662
663
  _a = sub;
663
664
  return [4 /*yield*/, (_c = that._publications[sub.publication]).preFunction.apply(_c, sub.subscriptionData)];
664
665
  case 3:
@@ -671,7 +672,7 @@ var SubscriptionManager = /** @class */ (function () {
671
672
  case 5:
672
673
  _b.preSubscriptionData = _f.sent();
673
674
  if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
674
- that.sendPubData(sub);
675
+ that.sendPubData(sub, 'support', collection);
675
676
  }
676
677
  return [3 /*break*/, 7];
677
678
  case 6:
@@ -682,7 +683,7 @@ var SubscriptionManager = /** @class */ (function () {
682
683
  if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, [document, client.id_user].concat(sub.subscriptionData))) {
683
684
  that._wss.clients.forEach(function (ws) {
684
685
  if (ws['id_socket'] === client.id_socket) {
685
- that.sendPubDataOnce(ws, client.messageId, sub);
686
+ that.sendPubDataOnce(ws, client.messageId, sub, 'support', collection);
686
687
  }
687
688
  });
688
689
  }
@@ -690,7 +691,7 @@ var SubscriptionManager = /** @class */ (function () {
690
691
  else {
691
692
  that._wss.clients.forEach(function (ws) {
692
693
  if (ws['id_socket'] === client.id_socket) {
693
- that.sendPubDataOnce(ws, client.messageId, sub);
694
+ that.sendPubDataOnce(ws, client.messageId, sub, 'support', collection);
694
695
  }
695
696
  });
696
697
  }
@@ -699,11 +700,11 @@ var SubscriptionManager = /** @class */ (function () {
699
700
  else {
700
701
  if (that._publications[sub.publication].fetchFunction) {
701
702
  if ((_e = that._publications[sub.publication]).fetchFunction.apply(_e, [document].concat(sub.subscriptionData))) {
702
- that.sendPubData(sub);
703
+ that.sendPubData(sub, 'support', collection);
703
704
  }
704
705
  }
705
706
  else {
706
- that.sendPubData(sub);
707
+ that.sendPubData(sub, 'support', collection);
707
708
  }
708
709
  }
709
710
  _f.label = 7;
@@ -713,7 +714,7 @@ var SubscriptionManager = /** @class */ (function () {
713
714
  }); });
714
715
  };
715
716
  // Fetch pub once, send to all clients linked to this pub
716
- SubscriptionManager.prototype.sendPubDataOnce = function (ws, messageId, subscription) {
717
+ SubscriptionManager.prototype.sendPubDataOnce = function (ws, messageId, subscription, type, collection) {
717
718
  return __awaiter(this, void 0, void 0, function () {
718
719
  var that;
719
720
  var _a, _b;
@@ -759,13 +760,14 @@ var SubscriptionManager = /** @class */ (function () {
759
760
  });
760
761
  };
761
762
  // Fetch pub once, send to all clients linked to this pub
762
- SubscriptionManager.prototype.sendPubData = function (subscription) {
763
+ SubscriptionManager.prototype.sendPubData = function (subscription, type, collection) {
763
764
  return __awaiter(this, void 0, void 0, function () {
764
765
  var that;
765
766
  var _a;
766
767
  var _this = this;
767
768
  return __generator(this, function (_b) {
768
769
  that = this;
770
+ that._mainServer.getMethodManager().callMethodInternal('insertLogSubscription', type, subscription.publication, collection);
769
771
  (_a = that._publications[subscription.publication].function).call.apply(_a, [Object.assign({}, that, SubscriptionManager.prototype)].concat(subscription.subscriptionData)).then(function (res) {
770
772
  subscription.clients.forEach(function (client) {
771
773
  that._wss.clients.forEach(function (ws) {
package/methods/logs.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var mongoose_1 = require("mongoose");
4
4
  var log_collection_1 = require("../collections/log.collection");
5
+ var log_subscription_collection_1 = require("../collections/log-subscription.collection");
5
6
  var index_1 = require("../index");
6
7
  function loadLogMethods(methodManager) {
7
8
  methodManager.methods({
@@ -23,6 +24,19 @@ function loadLogMethods(methodManager) {
23
24
  });
24
25
  },
25
26
  skipValidation: true
27
+ },
28
+ insertSubscriptionLog: {
29
+ skipQueue: true,
30
+ function: function (type, subscription, collection_name) {
31
+ return log_subscription_collection_1.LogSubscriptions.create({
32
+ _id: mongoose_1.Types.ObjectId().toHexString(),
33
+ __v: 0,
34
+ date: new Date(),
35
+ type: type,
36
+ subscription: subscription,
37
+ collection_name: collection_name
38
+ });
39
+ }
26
40
  }
27
41
  });
28
42
  }
@@ -0,0 +1,8 @@
1
+ import { CollectionDocument } from './collection-document.model';
2
+ export interface LogSubscriptionModel extends CollectionDocument {
3
+ date: Date;
4
+ type: LogSubscriptionType;
5
+ subscription: string;
6
+ collection_name: string;
7
+ }
8
+ export declare type LogSubscriptionType = 'insert' | 'update' | 'delete';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "4.0.15",
3
+ "version": "4.0.16",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {