@resolveio/server-lib 4.1.5 → 4.2.0-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.
@@ -21,13 +21,6 @@ var schema = {
21
21
  type: Date,
22
22
  optional: true
23
23
  },
24
- readonly: {
25
- type: Boolean,
26
- optional: true
27
- },
28
- active: {
29
- type: Boolean
30
- },
31
24
  attempts: {
32
25
  type: Number,
33
26
  optional: true
@@ -64,53 +57,67 @@ var schema = {
64
57
  type: String
65
58
  },
66
59
  roles: {
60
+ type: Object
61
+ },
62
+ 'roles.super_admin': {
63
+ type: Boolean
64
+ },
65
+ 'roles.approvals': {
67
66
  type: Array
68
67
  },
69
- 'roles.$': {
68
+ 'roles.approvals.$': {
69
+ type: Object
70
+ },
71
+ 'roles.approvals.$.name': {
70
72
  type: String
71
73
  },
72
- phonenumber: {
73
- type: String,
74
- optional: true
74
+ 'roles.approvals.$.type': {
75
+ type: String
75
76
  },
76
- other: {
77
- type: Object,
78
- blackbox: true,
79
- optional: true
77
+ 'roles.approvals.$.accounting_code': {
78
+ type: String
80
79
  },
81
- assets: {
82
- type: Array,
83
- optional: true
80
+ 'roles.groups': {
81
+ type: Array
84
82
  },
85
- 'assets.$': {
83
+ 'roles.groups.$': {
86
84
  type: Object
87
85
  },
88
- 'assets.$.type': {
86
+ 'roles.groups.$.name': {
89
87
  type: String
90
88
  },
91
- 'assets.$.id_asset': {
92
- type: String
89
+ 'roles.groups.$.views': {
90
+ type: Array
93
91
  },
94
- 'assets.$.asset_number': {
92
+ 'roles.groups.$.views.$': {
95
93
  type: String
96
94
  },
97
- 'assets.$.ownership': {
98
- type: String
95
+ 'roles.groups.$.yard': {
96
+ type: String,
97
+ optional: true
98
+ },
99
+ 'roles.notifications': {
100
+ type: Array
99
101
  },
100
- 'assets.$.ownership_driver': {
102
+ 'roles.notifications.$': {
101
103
  type: String
102
104
  },
103
- 'assets.$.date_start': {
104
- type: Date
105
+ 'roles.miscs': {
106
+ type: Array
105
107
  },
106
- 'assets.$.date_end': {
107
- type: Date,
108
- optional: true
108
+ 'roles.miscs.$': {
109
+ type: String
109
110
  },
110
- id_function: {
111
+ active: Boolean,
112
+ phonenumber: {
111
113
  type: String,
112
114
  optional: true
113
115
  },
116
+ other: {
117
+ type: Object,
118
+ optional: true,
119
+ blackbox: true
120
+ },
114
121
  customers: {
115
122
  type: Array,
116
123
  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;
@@ -51,6 +51,7 @@ 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");
54
55
  var billing_logged_in_users_collection_1 = require("../collections/billing-logged-in-users.collection");
55
56
  var moment = require("moment");
56
57
  var billing_logged_in_users_1 = require("../publications/billing-logged-in-users");
@@ -501,35 +502,144 @@ var SubscriptionManager = /** @class */ (function () {
501
502
  };
502
503
  SubscriptionManager.prototype.runOpLogQueue = function () {
503
504
  var _this = this;
505
+ var that = this;
504
506
  setInterval(function () {
505
507
  if (_this._oplogQueue.length) {
506
- var oplog = _this._oplogQueue.pop();
507
- _this.checkPubsForChanges(oplog.collection, oplog.doc, oplog.type);
508
+ var oplogQueue_1 = common_1.deepCopy(_this._oplogQueue);
509
+ _this._oplogQueue = [];
510
+ var uniquePubs_1 = [];
511
+ var uniqueOplog_1 = [];
512
+ var needIds_1 = {};
513
+ oplogQueue_1.forEach(function (oplog) {
514
+ for (var i = 0; i < that._subscriptions.length; i++) {
515
+ var sub = that._subscriptions[i];
516
+ if (sub.collections.includes(oplog.collection)) {
517
+ var schemaErrors = null;
518
+ try {
519
+ index_1.ResolveIOServer.getMainDB().model(oplog.collection)['simplschema'].validate(sub.preSubscriptionData);
520
+ }
521
+ catch (errors) {
522
+ schemaErrors = errors;
523
+ }
524
+ if (schemaErrors) {
525
+ if (!needIds_1[oplog.collection]) {
526
+ needIds_1[oplog.collection] = [oplog.doc['_id']];
527
+ }
528
+ else {
529
+ if (!needIds_1[oplog.collection].filter(function (a) { return a === oplog.doc['_id']; })[0]) {
530
+ needIds_1[oplog.collection].push(oplog.doc['_id']);
531
+ }
532
+ }
533
+ }
534
+ }
535
+ }
536
+ });
537
+ Object.keys(needIds_1).forEach(function (collection) { return __awaiter(_this, void 0, void 0, function () {
538
+ var docs;
539
+ return __generator(this, function (_a) {
540
+ switch (_a.label) {
541
+ case 0: return [4 /*yield*/, index_1.ResolveIOServer.getMainDB().model(collection).find({ _id: { $in: needIds_1[collection] } })];
542
+ case 1:
543
+ docs = _a.sent();
544
+ needIds_1[collection].forEach(function (id_doc) {
545
+ oplogQueue_1.filter(function (a) { return a.doc._id === id_doc; })[0].doc = docs.filter(function (a) { return a._id === id_doc; });
546
+ });
547
+ return [2 /*return*/];
548
+ }
549
+ });
550
+ }); });
551
+ oplogQueue_1.forEach(function (oplog) { return __awaiter(_this, void 0, void 0, function () {
552
+ var _loop_3, i;
553
+ return __generator(this, function (_a) {
554
+ switch (_a.label) {
555
+ case 0:
556
+ _loop_3 = function (i) {
557
+ var sub, _a;
558
+ var _b;
559
+ return __generator(this, function (_c) {
560
+ switch (_c.label) {
561
+ case 0:
562
+ sub = that._subscriptions[i];
563
+ if (!sub.collections.includes(oplog.collection)) return [3 /*break*/, 3];
564
+ if (sub.preSubscriptionData) {
565
+ if (that._publications[sub.publication].fetchFunction(oplog.doc, sub.preSubscriptionData)) {
566
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData)[0]; })) {
567
+ uniquePubs_1.push(sub);
568
+ uniqueOplog_1.push(oplog);
569
+ }
570
+ return [2 /*return*/, "continue"];
571
+ }
572
+ }
573
+ if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 2];
574
+ _a = sub;
575
+ return [4 /*yield*/, that._publications[sub.publication].preFunction(sub.subscriptionData)];
576
+ case 1:
577
+ _a.preSubscriptionData = _c.sent();
578
+ if (that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) {
579
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData))[0]; })) {
580
+ uniquePubs_1.push(sub);
581
+ uniqueOplog_1.push(oplog);
582
+ }
583
+ return [2 /*return*/, "continue"];
584
+ }
585
+ return [3 /*break*/, 3];
586
+ case 2:
587
+ if (that._publications[sub.publication].ws_specific) {
588
+ sub.clients.forEach(function (client) {
589
+ var _a;
590
+ if (that._publications[sub.publication].fetchFunction) {
591
+ if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, [document, client.id_user].concat(sub.subscriptionData))) {
592
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0]) {
593
+ uniquePubs_1.push(sub);
594
+ uniqueOplog_1.push(oplog);
595
+ }
596
+ }
597
+ }
598
+ });
599
+ }
600
+ else {
601
+ if (that._publications[sub.publication].fetchFunction) {
602
+ if ((_b = that._publications[sub.publication]).fetchFunction.apply(_b, [document].concat(sub.subscriptionData))) {
603
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData))[0]; })) {
604
+ uniquePubs_1.push(sub);
605
+ uniqueOplog_1.push(oplog);
606
+ }
607
+ return [2 /*return*/, "continue"];
608
+ }
609
+ }
610
+ else {
611
+ if (!uniquePubs_1.filter(function (a) { return a.publication === sub.publication && ((!a.subscriptionData && !sub.subscriptionData) || JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData))[0]; })) {
612
+ uniquePubs_1.push(sub);
613
+ uniqueOplog_1.push(oplog);
614
+ }
615
+ return [2 /*return*/, "continue"];
616
+ }
617
+ }
618
+ _c.label = 3;
619
+ case 3: return [2 /*return*/];
620
+ }
621
+ });
622
+ };
623
+ i = 0;
624
+ _a.label = 1;
625
+ case 1:
626
+ if (!(i < that._subscriptions.length)) return [3 /*break*/, 4];
627
+ return [5 /*yield**/, _loop_3(i)];
628
+ case 2:
629
+ _a.sent();
630
+ _a.label = 3;
631
+ case 3:
632
+ i++;
633
+ return [3 /*break*/, 1];
634
+ case 4: return [2 /*return*/];
635
+ }
636
+ });
637
+ }); });
638
+ uniqueOplog_1.forEach(function (oplog) {
639
+ _this.checkPubsForChanges(oplog.collection, oplog.doc, oplog.type);
640
+ });
508
641
  }
509
- // let oplogQueue = deepCopy(this._oplogQueue);
510
- // let uniqueCollectionOplogQueue = oplogQueue.map(a => a.collection).filter((elem, index, self) => {
511
- // return index === self.indexOf(elem);
512
- // });
513
- // uniqueCollectionOplogQueue.forEach(collection => {
514
- // let oplogQueueFiltered = oplogQueue.filter(a => a.collection === collection);
515
- // if (oplogQueueFiltered.length === 1) {
516
- // this.checkPubsForChanges(oplogQueueFiltered[0].collection, oplogQueueFiltered[0].doc);
517
- // this._oplogQueue.splice(this._oplogQueue.map(a => a.collection).indexOf(collection), 1);
518
- // }
519
- // else {
520
- // oplogQueueFiltered.forEach(item => {
521
- // this.checkPubsForChanges(item.collection, item.doc, true);
522
- // });
523
- // this.checkPubsForChanges(oplogQueueFiltered[oplogQueueFiltered.length - 1].collection, oplogQueueFiltered[oplogQueueFiltered.length - 1].doc, false, true);
524
- // for (let i = this._oplogQueue.length - 1; i >= 0; i--) {
525
- // let item = this._oplogQueue[i];
526
- // if (item.collection === collection) {
527
- // this._oplogQueue.splice(i, 1);
528
- // }
529
- // }
530
- // }
531
- // });
532
- }, 25);
642
+ }, 100);
533
643
  };
534
644
  SubscriptionManager.prototype.resendPubsForDelete = function (collection) {
535
645
  var that = this;
@@ -582,7 +692,7 @@ var SubscriptionManager = /** @class */ (function () {
582
692
  return [4 /*yield*/, (_c = that._publications[sub.publication]).preFunction.apply(_c, sub.subscriptionData)];
583
693
  case 3:
584
694
  _a.preSubscriptionData = _e.sent();
585
- return [2 /*return*/];
695
+ _e.label = 4;
586
696
  case 4:
587
697
  if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 7];
588
698
  if (!!noFetchFunction) return [3 /*break*/, 6];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "4.1.5",
3
+ "version": "4.2.0-newrole",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {