@resolveio/server-lib 5.0.2 → 5.0.3-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.
@@ -22,13 +22,6 @@ var schema = {
22
22
  type: Date,
23
23
  optional: true
24
24
  },
25
- readonly: {
26
- type: Boolean,
27
- optional: true
28
- },
29
- active: {
30
- type: Boolean
31
- },
32
25
  attempts: {
33
26
  type: Number,
34
27
  optional: true
@@ -65,53 +58,67 @@ var schema = {
65
58
  type: String
66
59
  },
67
60
  roles: {
61
+ type: Object
62
+ },
63
+ 'roles.super_admin': {
64
+ type: Boolean
65
+ },
66
+ 'roles.approvals': {
68
67
  type: Array
69
68
  },
70
- 'roles.$': {
69
+ 'roles.approvals.$': {
70
+ type: Object
71
+ },
72
+ 'roles.approvals.$.name': {
71
73
  type: String
72
74
  },
73
- phonenumber: {
74
- type: String,
75
- optional: true
75
+ 'roles.approvals.$.type': {
76
+ type: String
76
77
  },
77
- other: {
78
- type: Object,
79
- blackbox: true,
80
- optional: true
78
+ 'roles.approvals.$.accounting_code': {
79
+ type: String
81
80
  },
82
- assets: {
83
- type: Array,
84
- optional: true
81
+ 'roles.groups': {
82
+ type: Array
85
83
  },
86
- 'assets.$': {
84
+ 'roles.groups.$': {
87
85
  type: Object
88
86
  },
89
- 'assets.$.type': {
87
+ 'roles.groups.$.name': {
90
88
  type: String
91
89
  },
92
- 'assets.$.id_asset': {
93
- type: String
90
+ 'roles.groups.$.views': {
91
+ type: Array
94
92
  },
95
- 'assets.$.asset_number': {
93
+ 'roles.groups.$.views.$': {
96
94
  type: String
97
95
  },
98
- 'assets.$.ownership': {
99
- type: String
96
+ 'roles.groups.$.yard': {
97
+ type: String,
98
+ optional: true
99
+ },
100
+ 'roles.notifications': {
101
+ type: Array
100
102
  },
101
- 'assets.$.ownership_driver': {
103
+ 'roles.notifications.$': {
102
104
  type: String
103
105
  },
104
- 'assets.$.date_start': {
105
- type: Date
106
+ 'roles.miscs': {
107
+ type: Array
106
108
  },
107
- 'assets.$.date_end': {
108
- type: Date,
109
- optional: true
109
+ 'roles.miscs.$': {
110
+ type: String
110
111
  },
111
- id_function: {
112
+ active: Boolean,
113
+ phonenumber: {
112
114
  type: String,
113
115
  optional: true
114
116
  },
117
+ other: {
118
+ type: Object,
119
+ optional: true,
120
+ blackbox: true
121
+ },
115
122
  customers: {
116
123
  type: Array,
117
124
  optional: true,
package/fixtures/init.js CHANGED
@@ -37,8 +37,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  var app_version_collection_1 = require("../collections/app-version.collection");
39
39
  var logged_in_users_collection_1 = require("../collections/logged-in-users.collection");
40
- var active_subscription_collection_1 = require("../collections/active-subscription.collection");
41
40
  var mongoose_1 = require("mongoose");
41
+ var active_subscription_collection_1 = require("../collections/active-subscription.collection");
42
42
  function loadServerInit() {
43
43
  return __awaiter(this, void 0, void 0, function () {
44
44
  var appVersion;
@@ -5,6 +5,7 @@ export declare class SubscriptionManager {
5
5
  private _publications;
6
6
  private _subscriptions;
7
7
  private _wss;
8
+ private _oplogQueue;
8
9
  private _subCache;
9
10
  private _sendQueue;
10
11
  private _runningQueue;
@@ -18,6 +19,7 @@ export declare class SubscriptionManager {
18
19
  private getPublicationCollections;
19
20
  private tailOpLog;
20
21
  private tailOpLogSupport;
22
+ private runOpLogQueue;
21
23
  private resendPubsForDelete;
22
24
  private checkPubsForChanges;
23
25
  private checkSupportPubsForChanges;
@@ -61,6 +61,7 @@ var SubscriptionManager = /** @class */ (function () {
61
61
  var _this = this;
62
62
  this._publications = {};
63
63
  this._subscriptions = [];
64
+ this._oplogQueue = [];
64
65
  this._subCache = [];
65
66
  this._sendQueue = [];
66
67
  this._runningQueue = false;
@@ -81,6 +82,7 @@ var SubscriptionManager = /** @class */ (function () {
81
82
  notifications_1.loadNotificationPublications(this);
82
83
  report_builder_reports_1.loadReportBuilderReportPublications(this);
83
84
  this.tailOpLog();
85
+ this.runOpLogQueue();
84
86
  if (index_1.ResolveIOServer.getSupportDB()) {
85
87
  support_tickets_1.loadSupportTicketPublications(this);
86
88
  this.tailOpLogSupport();
@@ -410,7 +412,11 @@ var SubscriptionManager = /** @class */ (function () {
410
412
  _this._mainServer.getMethodManager().callMethodInternal('sendSupportTicketEmail', doc.o._id);
411
413
  }
412
414
  if (!collection.endsWith('.versions') && !collection.startsWith('system.')) {
413
- _this.checkPubsForChanges(collection, doc.o, 'insert');
415
+ _this._oplogQueue.push({
416
+ type: 'insert',
417
+ collection: collection,
418
+ doc: doc.o
419
+ });
414
420
  }
415
421
  });
416
422
  oplog.on('update', function (doc) {
@@ -424,7 +430,11 @@ var SubscriptionManager = /** @class */ (function () {
424
430
  _this._mainServer.getCronManager().checkCronJobsForUpdates();
425
431
  }
426
432
  if (!collection.endsWith('.versions') && !collection.startsWith('system.')) {
427
- _this.checkPubsForChanges(collection, doc.o, 'update');
433
+ _this._oplogQueue.push({
434
+ type: 'update',
435
+ collection: collection,
436
+ doc: doc.o
437
+ });
428
438
  }
429
439
  });
430
440
  oplog.on('delete', function (doc) {
@@ -497,6 +507,174 @@ var SubscriptionManager = /** @class */ (function () {
497
507
  console.log('oplog stopped support');
498
508
  });
499
509
  };
510
+ SubscriptionManager.prototype.runOpLogQueue = function () {
511
+ var _this = this;
512
+ var that = this;
513
+ setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
514
+ var uniqueOplog_1, uniquePubs, needIds_1, _loop_3, i, _loop_4, i, i, oplog, _loop_5, j, state_1;
515
+ var _this = this;
516
+ return __generator(this, function (_a) {
517
+ switch (_a.label) {
518
+ case 0:
519
+ if (!this._oplogQueue.length) return [3 /*break*/, 11];
520
+ uniqueOplog_1 = common_1.deepCopy(this._oplogQueue);
521
+ this._oplogQueue = [];
522
+ uniquePubs = [];
523
+ needIds_1 = {};
524
+ _loop_3 = function (i) {
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_3(i);
531
+ }
532
+ uniqueOplog_1.forEach(function (oplog) {
533
+ var schemaErrors = null;
534
+ try {
535
+ index_1.ResolveIOServer.getMainDB().model(oplog.collection)['simplschema'].validate(oplog.doc);
536
+ }
537
+ catch (errors) {
538
+ schemaErrors = errors;
539
+ }
540
+ if (schemaErrors) {
541
+ if (!needIds_1[oplog.collection]) {
542
+ needIds_1[oplog.collection] = [oplog.doc['_id']];
543
+ }
544
+ else {
545
+ if (!needIds_1[oplog.collection].filter(function (a) { return a === oplog.doc['_id']; })[0]) {
546
+ needIds_1[oplog.collection].push(oplog.doc['_id']);
547
+ }
548
+ }
549
+ }
550
+ });
551
+ _loop_4 = function (i) {
552
+ var collection, docs;
553
+ return __generator(this, function (_a) {
554
+ switch (_a.label) {
555
+ case 0:
556
+ collection = Object.keys(needIds_1)[i];
557
+ return [4 /*yield*/, index_1.ResolveIOServer.getMainDB().model(collection).find({ _id: { $in: needIds_1[collection] } })];
558
+ case 1:
559
+ docs = _a.sent();
560
+ needIds_1[collection].forEach(function (id_doc) {
561
+ if (uniqueOplog_1.filter(function (a) { return a.doc && a.doc._id === id_doc; })[0]) {
562
+ uniqueOplog_1.filter(function (a) { return a.doc && a.doc._id === id_doc; })[0].doc = docs.filter(function (a) { return a._id === id_doc; })[0];
563
+ }
564
+ else {
565
+ console.log('PROBLEMAAAAAAAA');
566
+ }
567
+ });
568
+ return [2 /*return*/];
569
+ }
570
+ });
571
+ };
572
+ i = 0;
573
+ _a.label = 1;
574
+ case 1:
575
+ if (!(i < Object.keys(needIds_1).length)) return [3 /*break*/, 4];
576
+ return [5 /*yield**/, _loop_4(i)];
577
+ case 2:
578
+ _a.sent();
579
+ _a.label = 3;
580
+ case 3:
581
+ i++;
582
+ return [3 /*break*/, 1];
583
+ case 4:
584
+ i = uniqueOplog_1.length - 1;
585
+ _a.label = 5;
586
+ case 5:
587
+ if (!(i >= 0)) return [3 /*break*/, 10];
588
+ oplog = uniqueOplog_1[i];
589
+ _loop_5 = function (j) {
590
+ var _a, sub, _b;
591
+ return __generator(this, function (_c) {
592
+ switch (_c.label) {
593
+ case 0:
594
+ sub = that._subscriptions[j];
595
+ if (!sub.collections.includes(oplog.collection)) return [3 /*break*/, 3];
596
+ if (sub.preSubscriptionData) {
597
+ if (that._publications[sub.publication].fetchFunction(oplog.doc, sub.preSubscriptionData)) {
598
+ if (!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }).length) {
599
+ sub['oplog'] = oplog;
600
+ uniquePubs.push(sub);
601
+ }
602
+ else {
603
+ uniqueOplog_1.splice(i, 1);
604
+ }
605
+ return [2 /*return*/, "break"];
606
+ }
607
+ }
608
+ if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 2];
609
+ _b = sub;
610
+ return [4 /*yield*/, that._publications[sub.publication].preFunction(sub.subscriptionData)];
611
+ case 1:
612
+ _b.preSubscriptionData = _c.sent();
613
+ if (that._publications[sub.publication].fetchFunction(oplog.doc, sub.preSubscriptionData)) {
614
+ if (!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }).length) {
615
+ sub['oplog'] = oplog;
616
+ uniquePubs.push(sub);
617
+ }
618
+ else {
619
+ uniqueOplog_1.splice(i, 1);
620
+ }
621
+ return [2 /*return*/, "break"];
622
+ }
623
+ return [3 /*break*/, 3];
624
+ case 2:
625
+ if (that._publications[sub.publication].fetchFunction) {
626
+ if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, [oplog.doc].concat(sub.subscriptionData))) {
627
+ if (!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }).length) {
628
+ sub['oplog'] = oplog;
629
+ uniquePubs.push(sub);
630
+ }
631
+ else {
632
+ uniqueOplog_1.splice(i, 1);
633
+ }
634
+ return [2 /*return*/, "break"];
635
+ }
636
+ }
637
+ else {
638
+ if (!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }).length) {
639
+ sub['oplog'] = oplog;
640
+ uniquePubs.push(sub);
641
+ }
642
+ else {
643
+ uniqueOplog_1.splice(i, 1);
644
+ }
645
+ return [2 /*return*/, "break"];
646
+ }
647
+ _c.label = 3;
648
+ case 3: return [2 /*return*/];
649
+ }
650
+ });
651
+ };
652
+ j = 0;
653
+ _a.label = 6;
654
+ case 6:
655
+ if (!(j < that._subscriptions.length)) return [3 /*break*/, 9];
656
+ return [5 /*yield**/, _loop_5(j)];
657
+ case 7:
658
+ state_1 = _a.sent();
659
+ if (state_1 === "break")
660
+ return [3 /*break*/, 9];
661
+ _a.label = 8;
662
+ case 8:
663
+ j++;
664
+ return [3 /*break*/, 6];
665
+ case 9:
666
+ i--;
667
+ return [3 /*break*/, 5];
668
+ case 10:
669
+ uniquePubs.forEach(function (pub) {
670
+ _this.checkPubsForChanges(pub['oplog'].collection, pub['oplog'].doc, pub['oplog'].type);
671
+ });
672
+ _a.label = 11;
673
+ case 11: return [2 /*return*/];
674
+ }
675
+ });
676
+ }); }, 500);
677
+ };
500
678
  SubscriptionManager.prototype.resendPubsForDelete = function (collection) {
501
679
  var that = this;
502
680
  that._subscriptions.filter(function (a) { return a.collections.includes(collection); }).forEach(function (sub) {
@@ -519,46 +697,33 @@ var SubscriptionManager = /** @class */ (function () {
519
697
  // Check to see if any pubs need to refetch due to Mongo operation
520
698
  SubscriptionManager.prototype.checkPubsForChanges = function (collection, document, type) {
521
699
  return __awaiter(this, void 0, void 0, function () {
522
- var that, _loop_3, this_1, i;
700
+ var that, _loop_6, this_1, i;
523
701
  return __generator(this, function (_a) {
524
702
  switch (_a.label) {
525
703
  case 0:
526
704
  that = this;
527
- _loop_3 = function (i) {
528
- var _a, _b, schemaErrors, sub, _c, _d;
705
+ _loop_6 = function (i) {
706
+ var _a, _b, sub, _c, _d;
529
707
  return __generator(this, function (_e) {
530
708
  switch (_e.label) {
531
709
  case 0:
532
- schemaErrors = null;
533
- try {
534
- index_1.ResolveIOServer.getMainDB().model(collection)['simplschema'].validate(document);
535
- }
536
- catch (errors) {
537
- schemaErrors = errors;
538
- }
539
- if (!schemaErrors) return [3 /*break*/, 2];
540
- return [4 /*yield*/, index_1.ResolveIOServer.getMainDB().model(collection).findById(document['_id'])];
541
- case 1:
542
- document = _e.sent();
543
- _e.label = 2;
544
- case 2:
545
710
  sub = that._subscriptions.filter(function (a) { return a.collections.includes(collection); })[i];
546
- if (!sub.preSubscriptionData) return [3 /*break*/, 4];
547
- if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 4];
711
+ if (!sub.preSubscriptionData) return [3 /*break*/, 2];
712
+ if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 2];
548
713
  if (this_1._subCache.some(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })) {
549
714
  this_1._subCache.splice(this_1._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
550
715
  }
551
716
  that.sendPubData(sub, type, collection);
552
717
  _c = sub;
553
718
  return [4 /*yield*/, (_a = that._publications[sub.publication]).preFunction.apply(_a, sub.subscriptionData)];
554
- case 3:
719
+ case 1:
555
720
  _c.preSubscriptionData = _e.sent();
556
721
  return [2 /*return*/, "continue"];
557
- case 4:
558
- if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 6];
722
+ case 2:
723
+ if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 4];
559
724
  _d = sub;
560
725
  return [4 /*yield*/, that._publications[sub.publication].preFunction(sub.subscriptionData)];
561
- case 5:
726
+ case 3:
562
727
  _d.preSubscriptionData = _e.sent();
563
728
  if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
564
729
  if (this_1._subCache.some(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })) {
@@ -566,8 +731,8 @@ var SubscriptionManager = /** @class */ (function () {
566
731
  }
567
732
  that.sendPubData(sub, type, collection);
568
733
  }
569
- return [3 /*break*/, 7];
570
- case 6:
734
+ return [3 /*break*/, 5];
735
+ case 4:
571
736
  if (that._publications[sub.publication].ws_specific) {
572
737
  sub.clients.forEach(function (client) {
573
738
  var _a;
@@ -606,8 +771,8 @@ var SubscriptionManager = /** @class */ (function () {
606
771
  that.sendPubData(sub, type, collection);
607
772
  }
608
773
  }
609
- _e.label = 7;
610
- case 7: return [2 /*return*/];
774
+ _e.label = 5;
775
+ case 5: return [2 /*return*/];
611
776
  }
612
777
  });
613
778
  };
@@ -616,7 +781,7 @@ var SubscriptionManager = /** @class */ (function () {
616
781
  _a.label = 1;
617
782
  case 1:
618
783
  if (!(i < that._subscriptions.filter(function (a) { return a.collections.includes(collection); }).length)) return [3 /*break*/, 4];
619
- return [5 /*yield**/, _loop_3(i)];
784
+ return [5 /*yield**/, _loop_6(i)];
620
785
  case 2:
621
786
  _a.sent();
622
787
  _a.label = 3;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "5.0.2",
3
+ "version": "5.0.3-newrole",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {