@resolveio/server-lib 5.2.52 → 5.2.53-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/fixtures/init.js +1 -1
- package/fixtures/init.js.map +1 -1
- package/managers/subscription.manager.js +145 -97
- 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
|
@@ -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
|
-
|
|
74
|
-
type: String
|
|
75
|
-
optional: true
|
|
75
|
+
'roles.approvals.$.type': {
|
|
76
|
+
type: String
|
|
76
77
|
},
|
|
77
|
-
|
|
78
|
-
type:
|
|
79
|
-
blackbox: true,
|
|
80
|
-
optional: true
|
|
78
|
+
'roles.approvals.$.accounting_code': {
|
|
79
|
+
type: String
|
|
81
80
|
},
|
|
82
|
-
|
|
83
|
-
type: Array
|
|
84
|
-
optional: true
|
|
81
|
+
'roles.groups': {
|
|
82
|
+
type: Array
|
|
85
83
|
},
|
|
86
|
-
'
|
|
84
|
+
'roles.groups.$': {
|
|
87
85
|
type: Object
|
|
88
86
|
},
|
|
89
|
-
'
|
|
87
|
+
'roles.groups.$.name': {
|
|
90
88
|
type: String
|
|
91
89
|
},
|
|
92
|
-
'
|
|
93
|
-
type:
|
|
90
|
+
'roles.groups.$.views': {
|
|
91
|
+
type: Array
|
|
94
92
|
},
|
|
95
|
-
'
|
|
93
|
+
'roles.groups.$.views.$': {
|
|
96
94
|
type: String
|
|
97
95
|
},
|
|
98
|
-
'
|
|
99
|
-
type: String
|
|
96
|
+
'roles.groups.$.yard': {
|
|
97
|
+
type: String,
|
|
98
|
+
optional: true
|
|
99
|
+
},
|
|
100
|
+
'roles.notifications': {
|
|
101
|
+
type: Array
|
|
100
102
|
},
|
|
101
|
-
'
|
|
103
|
+
'roles.notifications.$': {
|
|
102
104
|
type: String
|
|
103
105
|
},
|
|
104
|
-
'
|
|
105
|
-
type:
|
|
106
|
+
'roles.miscs': {
|
|
107
|
+
type: Array
|
|
106
108
|
},
|
|
107
|
-
'
|
|
108
|
-
type:
|
|
109
|
-
optional: true
|
|
109
|
+
'roles.miscs.$': {
|
|
110
|
+
type: String
|
|
110
111
|
},
|
|
111
|
-
|
|
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,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/collections/user.collection.ts"],"names":[],"mappings":";;AAAA,qCAAwG;AACxG,+DAAiE;AACjE,6CAAwC;AACxC,kCAA2C;AAG3C,uEAA8E;AAE9E,IAAI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E,EAAE;IACnC,mBAAW,GAAG,uBAAe,CAAC,YAAY,EAAE,CAAC,KAAK,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;CAClF;AAED,aAAK,CAAC,aAAa,CAAC,GAAG,IAAI,sBAAY,CAAC,MAAM,CAAC,CAAC;AAEhD,MAAM,CAAC,GAAG,GAAG;IACZ,IAAI,EAAE,iBAAM,CAAC,KAAK,CAAC,KAAK;CACxB,CAAC;AAEF,IAAI,aAAa,GAAG,IAAI,iBAAM,CAAC,MAAM,EAAE;IACtC,cAAc,EAAE,IAAI;IACpB,UAAU,EAAE,KAAK;IACjB,UAAU,EAAE,IAAI;CAChB,CAAC,CAAC;AAEH,aAAK,CAAC,mBAAmB,CAAC,GAAG,gBAAgB,CAAC;AAEjC,QAAA,YAAY,GAA0B,uBAAe,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,aAAK,CAAC,mBAAmB,CAAC,EAAE,aAAa,CAAC,CAAC;AAEhI,qCAAqC;AACrC,IAAI,SAAS,GAAmB,EAAE,CAAC;AAEnC,IAAI,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,sCAAc,CAAC,SAAS,EAAE,aAAa,EAAE,EAAE,CAAC,CAAC,CAAC;AACnF,aAAK,CAAC,UAAU,CAAC,GAAG,qCAAa,CAAC,QAAQ,CAAC,CAAC","file":"user.collection.js","sourcesContent":["import { Schema, Model, PassportLocalDocument, PassportLocalModel, PassportLocalSchema} from 'mongoose';\nimport * as passportLocalMongoose from 'passport-local-mongoose';\nimport SimpleSchema from 'simpl-schema';\nimport { ResolveIOServer } from '../index';\nimport { UserModel } from '../models/user.model';\nimport { LookupTables } from '../models/report-builder.model';\nimport { buildRbSchema, buildRbLookups } from '../util/schema-report-builder';\n\nlet schema: any = {\n\t_id: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\t__v: {\n\t\ttype: Number,\n\t\toptional: true\n\t},\n\tupdatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tcreatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tattempts: {\n\t\ttype: Number,\n\t\toptional: true\n\t},\n\tlast: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tservices: {\n\t\ttype: Object,\n\t\toptional: true\n\t},\n\t'services.enrollment': {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\t'services.forgot_password': {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\t'services.reset_password': {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tusername: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\temail: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tfullname: {\n\t\ttype: String\n\t},\n\troles: {\n\t\ttype: Object\n\t},\n\t'roles.super_admin': {\n\t\ttype: Boolean\n\t},\n\t'roles.approvals': {\n\t\ttype: Array\n\t},\n\t'roles.approvals.$': {\n\t\ttype: Object\n\t},\n\t'roles.approvals.$.name': {\n\t\ttype: String\n\t},\n\t'roles.approvals.$.type': {\n\t\ttype: String\n\t},\n\t'roles.approvals.$.accounting_code': {\n\t\ttype: String\n\t},\n\t'roles.groups': {\n\t\ttype: Array\n\t},\n\t'roles.groups.$': {\n\t\ttype: Object\n\t},\n\t'roles.groups.$.name': {\n\t\ttype: String\n\t},\n\t'roles.groups.$.views': {\n\t\ttype: Array\n\t},\n\t'roles.groups.$.views.$': {\n\t\ttype: String\n\t},\n\t'roles.groups.$.yard': {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\t'roles.notifications': {\n\t\ttype: Array\n\t},\n\t'roles.notifications.$': {\n\t\ttype: String\n\t},\n\t'roles.miscs': {\n\t\ttype: Array\n\t},\n\t'roles.miscs.$': {\n\t\ttype: String\n\t},\n\tactive: Boolean,\n\tphonenumber: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tother: {\n\t\ttype: Object,\n\t\toptional: true,\n\t\tblackbox: true\n\t},\n\tcustomers: {\n\t\ttype: Array,\n\t\toptional: true,\n\t},\n\t'customers.$': {\n\t\ttype: Object\n\t},\n\t'customers.$.id_customer': {\n\t\ttype: String\n\t},\n\t'customers.$.customer': {\n\t\ttype: String\n\t},\n\tid_customer: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tcustomer: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tcustomer_type: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tdepartments: {\n\t\ttype: Array,\n\t\toptional: true\n\t},\n\t'departments.$': {\n\t\ttype: Object\n\t},\n\t'departments.$.id_department': {\n\t\ttype: String\n\t},\n\t'departments.$.department': {\n\t\ttype: String\n\t}\n};\n\nconst DefaultSchema = <PassportLocalSchema>new Schema(schema, {\n\tskipVersioning: true,\n\tversionKey: false,\n\ttimestamps: true\n});\n\nDefaultSchema.plugin(passportLocalMongoose, {\n\tusernameUnique: true,\n\tlimitAttempts: true,\n\tmaxAttempts: 5,\n\tfindByUsername: (mongooseModel, queryParameters) => {\n\t\t// Add additional query parameter - AND condition - active: true\n\t\tqueryParameters.active = true;\n\t\treturn mongooseModel.findOne(queryParameters);\n\t}\n});\n\ninterface ResolveIOModel extends UserModel, PassportLocalDocument {}\nexport const Users: PassportLocalModel<ResolveIOModel> = ResolveIOServer.getMainDB().model('users', DefaultSchema);\n\nexport let ClientUsers: PassportLocalModel<ResolveIOModel> = null;\n\nif (ResolveIOServer.getSupportDB()) {\n\tClientUsers = ResolveIOServer.getSupportDB().model('client-users', DefaultSchema);\n}\n\nUsers['simplschema'] = new SimpleSchema(schema);\n\nschema._id = {\n\ttype: Schema.Types.Mixed\n};\n\nlet VersionSchema = new Schema(schema, {\n\tskipVersioning: true,\n\tversionKey: false,\n\ttimestamps: true\n});\n\nUsers['versionCollection'] = 'users.versions';\n\nexport const UserVersions: Model<ResolveIOModel> = ResolveIOServer.getMainDB().model(Users['versionCollection'], VersionSchema);\n\n//------------- Report Builder Schema\nlet rbLookups: LookupTables[] = [];\n\nlet rbSchema = Object.assign(schema, buildRbLookups(rbLookups, DefaultSchema, []));\nUsers['rbSchema'] = buildRbSchema(rbSchema);"]}
|
package/fixtures/init.js
CHANGED
|
@@ -36,8 +36,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
var app_version_collection_1 = require("../collections/app-version.collection");
|
|
39
|
-
var active_subscription_collection_1 = require("../collections/active-subscription.collection");
|
|
40
39
|
var mongoose_1 = require("mongoose");
|
|
40
|
+
var active_subscription_collection_1 = require("../collections/active-subscription.collection");
|
|
41
41
|
function loadServerInit() {
|
|
42
42
|
return __awaiter(this, void 0, void 0, function () {
|
|
43
43
|
var appVersion;
|
package/fixtures/init.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/fixtures/init.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gFAAoE;
|
|
1
|
+
{"version":3,"sources":["../../src/fixtures/init.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gFAAoE;AACpE,qCAAiC;AACjC,gGAAoF;AAEpF,SAAsB,cAAc;;;;;wBAClB,qBAAM,oCAAW,CAAC,OAAO,EAAE,EAAA;;oBAAxC,UAAU,GAAG,SAA2B;oBAE5C,IAAI,CAAC,UAAU,EAAE;wBAChB,oCAAW,CAAC,MAAM,CAAC;4BAClB,GAAG,EAAE,gBAAK,CAAC,QAAQ,EAAE,CAAC,WAAW,EAAE;4BACnC,OAAO,EAAE,CAAC;yBACV,CAAC,CAAC;qBACH;oBAED,qBAAM,oDAAmB,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,EAAA;;oBAA/C,SAA+C,CAAC;;;;;CAChD;AAXD,wCAWC","file":"init.js","sourcesContent":["import { AppVersions } from '../collections/app-version.collection';\nimport { Types } from 'mongoose';\nimport { ActiveSubscriptions } from '../collections/active-subscription.collection';\n\nexport async function loadServerInit() {\n\tlet appVersion = await AppVersions.findOne();\n\n\tif (!appVersion) {\n\t\tAppVersions.create({\n\t\t\t_id: Types.ObjectId().toHexString(),\n\t\t\tversion: 1\n\t\t});\n\t}\n\n\tawait ActiveSubscriptions.deleteMany({}).exec();\n}"]}
|
|
@@ -845,26 +845,36 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
845
845
|
_loop_7(jj);
|
|
846
846
|
}
|
|
847
847
|
_loop_8 = function (zz) {
|
|
848
|
-
var sub;
|
|
848
|
+
var sub, aa, client, bb, ws;
|
|
849
849
|
return __generator(this, function (_a) {
|
|
850
850
|
switch (_a.label) {
|
|
851
851
|
case 0:
|
|
852
852
|
sub = subCopy[zz];
|
|
853
|
-
if (!that._publications[sub.publication].ws_specific) return [3 /*break*/,
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
that._wss.clients.forEach(function (ws) {
|
|
857
|
-
if (ws['id_socket'] === client.id_socket) {
|
|
858
|
-
that.sendPubDataOnce(ws, client.messageId, sub, 'delete', collection);
|
|
859
|
-
}
|
|
860
|
-
});
|
|
861
|
-
});
|
|
862
|
-
}
|
|
863
|
-
else {
|
|
864
|
-
}
|
|
865
|
-
return [3 /*break*/, 4];
|
|
853
|
+
if (!that._publications[sub.publication].ws_specific) return [3 /*break*/, 7];
|
|
854
|
+
aa = 0;
|
|
855
|
+
_a.label = 1;
|
|
866
856
|
case 1:
|
|
867
|
-
if (
|
|
857
|
+
if (!(aa < sub.clients.length)) return [3 /*break*/, 6];
|
|
858
|
+
client = sub.clients[aa];
|
|
859
|
+
bb = 0;
|
|
860
|
+
_a.label = 2;
|
|
861
|
+
case 2:
|
|
862
|
+
if (!(bb < that._wss.clients.size)) return [3 /*break*/, 5];
|
|
863
|
+
ws = that._wss.clients[bb];
|
|
864
|
+
if (!(ws['id_socket'] === client.id_socket)) return [3 /*break*/, 4];
|
|
865
|
+
return [4 /*yield*/, that.sendPubDataOnce(ws, client.messageId, sub, 'delete', collection)];
|
|
866
|
+
case 3:
|
|
867
|
+
_a.sent();
|
|
868
|
+
_a.label = 4;
|
|
869
|
+
case 4:
|
|
870
|
+
bb++;
|
|
871
|
+
return [3 /*break*/, 2];
|
|
872
|
+
case 5:
|
|
873
|
+
aa++;
|
|
874
|
+
return [3 /*break*/, 1];
|
|
875
|
+
case 6: return [3 /*break*/, 11];
|
|
876
|
+
case 7:
|
|
877
|
+
if (!!sub.clients.length) return [3 /*break*/, 9];
|
|
868
878
|
if (that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
869
879
|
that._subscriptions.splice(that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
870
880
|
}
|
|
@@ -874,13 +884,14 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
874
884
|
{ subData: JSON.stringify(sub.subscriptionData) }
|
|
875
885
|
]
|
|
876
886
|
}).exec()];
|
|
877
|
-
case
|
|
887
|
+
case 8:
|
|
878
888
|
_a.sent();
|
|
879
|
-
return [3 /*break*/,
|
|
880
|
-
case
|
|
881
|
-
|
|
882
|
-
_a.
|
|
883
|
-
|
|
889
|
+
return [3 /*break*/, 11];
|
|
890
|
+
case 9: return [4 /*yield*/, that.sendPubData(sub, 'delete', collection)];
|
|
891
|
+
case 10:
|
|
892
|
+
_a.sent();
|
|
893
|
+
_a.label = 11;
|
|
894
|
+
case 11: return [2 /*return*/];
|
|
884
895
|
}
|
|
885
896
|
});
|
|
886
897
|
};
|
|
@@ -905,77 +916,104 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
905
916
|
// Check to see if any pubs need to refetch due to Mongo operation
|
|
906
917
|
SubscriptionManager.prototype.checkPubsForChanges = function (collection, document, type, sub) {
|
|
907
918
|
return __awaiter(this, void 0, void 0, function () {
|
|
908
|
-
var _a, that,
|
|
909
|
-
return __generator(this, function (
|
|
910
|
-
switch (
|
|
919
|
+
var _a, _b, that, _c, k, client, j, ws, j, ws;
|
|
920
|
+
return __generator(this, function (_d) {
|
|
921
|
+
switch (_d.label) {
|
|
911
922
|
case 0:
|
|
912
923
|
that = this;
|
|
913
|
-
if (sub.preSubscriptionData)
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
}
|
|
919
|
-
that.sendPubData(sub, type, collection);
|
|
920
|
-
return [2 /*return*/];
|
|
921
|
-
}
|
|
924
|
+
if (!sub.preSubscriptionData) return [3 /*break*/, 2];
|
|
925
|
+
if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 2];
|
|
926
|
+
if (this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
927
|
+
this._nodeCache.del(this._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
928
|
+
this._subCache.splice(this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
922
929
|
}
|
|
923
|
-
|
|
924
|
-
_b = sub;
|
|
925
|
-
return [4 /*yield*/, that._publications[sub.publication].preFunction(sub.subscriptionData)];
|
|
930
|
+
return [4 /*yield*/, that.sendPubData(sub, type, collection)];
|
|
926
931
|
case 1:
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
if (this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
930
|
-
this._nodeCache.del(this._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
931
|
-
this._subCache.splice(this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
932
|
-
}
|
|
933
|
-
that.sendPubData(sub, type, collection);
|
|
934
|
-
}
|
|
935
|
-
return [3 /*break*/, 3];
|
|
932
|
+
_d.sent();
|
|
933
|
+
return [2 /*return*/];
|
|
936
934
|
case 2:
|
|
937
|
-
if (that._publications[sub.publication].
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
});
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
else {
|
|
950
|
-
that._wss.clients.forEach(function (ws) {
|
|
951
|
-
if (ws['id_socket'] === client.id_socket) {
|
|
952
|
-
that.sendPubDataOnce(ws, client.messageId, sub, type, collection);
|
|
953
|
-
}
|
|
954
|
-
});
|
|
955
|
-
}
|
|
956
|
-
});
|
|
935
|
+
if (!that._publications[sub.publication].preFunction) return [3 /*break*/, 6];
|
|
936
|
+
_c = sub;
|
|
937
|
+
return [4 /*yield*/, that._publications[sub.publication].preFunction(sub.subscriptionData)];
|
|
938
|
+
case 3:
|
|
939
|
+
_c.preSubscriptionData = _d.sent();
|
|
940
|
+
if (!that._publications[sub.publication].fetchFunction(document, sub.preSubscriptionData)) return [3 /*break*/, 5];
|
|
941
|
+
if (this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
942
|
+
this._nodeCache.del(this._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
943
|
+
this._subCache.splice(this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
957
944
|
}
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
}
|
|
969
|
-
else {
|
|
970
|
-
if (this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
971
|
-
this._nodeCache.del(this._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
972
|
-
this._subCache.splice(this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
973
|
-
}
|
|
974
|
-
that.sendPubData(sub, type, collection);
|
|
975
|
-
}
|
|
945
|
+
return [4 /*yield*/, that.sendPubData(sub, type, collection)];
|
|
946
|
+
case 4:
|
|
947
|
+
_d.sent();
|
|
948
|
+
_d.label = 5;
|
|
949
|
+
case 5: return [3 /*break*/, 23];
|
|
950
|
+
case 6:
|
|
951
|
+
if (!that._publications[sub.publication].ws_specific) return [3 /*break*/, 18];
|
|
952
|
+
if (this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
953
|
+
this._nodeCache.del(this._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
954
|
+
this._subCache.splice(this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
976
955
|
}
|
|
977
|
-
|
|
978
|
-
|
|
956
|
+
k = 0;
|
|
957
|
+
_d.label = 7;
|
|
958
|
+
case 7:
|
|
959
|
+
if (!(k < sub.clients.length)) return [3 /*break*/, 17];
|
|
960
|
+
client = sub.clients[k];
|
|
961
|
+
if (!that._publications[sub.publication].fetchFunction) return [3 /*break*/, 12];
|
|
962
|
+
if (!(_a = that._publications[sub.publication]).fetchFunction.apply(_a, [document, client.id_user].concat(sub.subscriptionData))) return [3 /*break*/, 11];
|
|
963
|
+
j = 0;
|
|
964
|
+
_d.label = 8;
|
|
965
|
+
case 8:
|
|
966
|
+
if (!(j < that._wss.clients.size)) return [3 /*break*/, 11];
|
|
967
|
+
ws = that._wss.clients[j];
|
|
968
|
+
if (!(ws['id_socket'] === client.id_socket)) return [3 /*break*/, 10];
|
|
969
|
+
return [4 /*yield*/, that.sendPubDataOnce(ws, client.messageId, sub, type, collection)];
|
|
970
|
+
case 9:
|
|
971
|
+
_d.sent();
|
|
972
|
+
_d.label = 10;
|
|
973
|
+
case 10:
|
|
974
|
+
j++;
|
|
975
|
+
return [3 /*break*/, 8];
|
|
976
|
+
case 11: return [3 /*break*/, 16];
|
|
977
|
+
case 12:
|
|
978
|
+
j = 0;
|
|
979
|
+
_d.label = 13;
|
|
980
|
+
case 13:
|
|
981
|
+
if (!(j < that._wss.clients.size)) return [3 /*break*/, 16];
|
|
982
|
+
ws = that._wss.clients[j];
|
|
983
|
+
if (!(ws['id_socket'] === client.id_socket)) return [3 /*break*/, 15];
|
|
984
|
+
return [4 /*yield*/, that.sendPubDataOnce(ws, client.messageId, sub, type, collection)];
|
|
985
|
+
case 14:
|
|
986
|
+
_d.sent();
|
|
987
|
+
_d.label = 15;
|
|
988
|
+
case 15:
|
|
989
|
+
j++;
|
|
990
|
+
return [3 /*break*/, 13];
|
|
991
|
+
case 16:
|
|
992
|
+
k++;
|
|
993
|
+
return [3 /*break*/, 7];
|
|
994
|
+
case 17: return [3 /*break*/, 23];
|
|
995
|
+
case 18:
|
|
996
|
+
if (!that._publications[sub.publication].fetchFunction) return [3 /*break*/, 21];
|
|
997
|
+
if (!(_b = that._publications[sub.publication]).fetchFunction.apply(_b, [document].concat(sub.subscriptionData))) return [3 /*break*/, 20];
|
|
998
|
+
if (this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
999
|
+
this._nodeCache.del(this._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
1000
|
+
this._subCache.splice(this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
1001
|
+
}
|
|
1002
|
+
return [4 /*yield*/, that.sendPubData(sub, type, collection)];
|
|
1003
|
+
case 19:
|
|
1004
|
+
_d.sent();
|
|
1005
|
+
_d.label = 20;
|
|
1006
|
+
case 20: return [3 /*break*/, 23];
|
|
1007
|
+
case 21:
|
|
1008
|
+
if (this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
1009
|
+
this._nodeCache.del(this._subCache.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); })[0].id);
|
|
1010
|
+
this._subCache.splice(this._subCache.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
1011
|
+
}
|
|
1012
|
+
return [4 /*yield*/, that.sendPubData(sub, type, collection)];
|
|
1013
|
+
case 22:
|
|
1014
|
+
_d.sent();
|
|
1015
|
+
_d.label = 23;
|
|
1016
|
+
case 23: return [2 /*return*/];
|
|
979
1017
|
}
|
|
980
1018
|
});
|
|
981
1019
|
});
|
|
@@ -1059,7 +1097,8 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
1059
1097
|
};
|
|
1060
1098
|
// Fetch pub once, send to all clients linked to this pub
|
|
1061
1099
|
SubscriptionManager.prototype.sendPubDataOnce = function (ws, messageId, subscription, type, collection) {
|
|
1062
|
-
|
|
1100
|
+
var _this = this;
|
|
1101
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
1063
1102
|
var _a, _b, that, serverRes;
|
|
1064
1103
|
var _this = this;
|
|
1065
1104
|
return __generator(this, function (_c) {
|
|
@@ -1072,6 +1111,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
1072
1111
|
data: this._nodeCache.get(this._subCache.filter(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); })[0].id)
|
|
1073
1112
|
};
|
|
1074
1113
|
this.sendWS(ws, serverRes);
|
|
1114
|
+
resolve(true);
|
|
1075
1115
|
}
|
|
1076
1116
|
else {
|
|
1077
1117
|
if (subscription.publication !== 'superadminAPM' && subscription.publication !== 'loggedInUsers') {
|
|
@@ -1091,11 +1131,12 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
1091
1131
|
// console.log('Cache1: ' + 'Too Big - ' + subscription.publication + ' - ' + getBinarySize(JSON.stringify(this._subCache)));
|
|
1092
1132
|
_this._subCache.splice(0, neededSizeIndex);
|
|
1093
1133
|
}
|
|
1094
|
-
if (
|
|
1095
|
-
|
|
1096
|
-
_this._nodeCache.set(cacheId, res);
|
|
1097
|
-
_this._subCache.push({ collection: collection, publication: subscription.publication, subscriptionData: subscription.subscriptionData, id: cacheId });
|
|
1134
|
+
if (_this._subCache.some(function (a) { return a.collection === collection && a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); })) {
|
|
1135
|
+
_this._subCache.splice(_this._subCache.findIndex(function (a) { return a.collection === collection && a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); }), 1);
|
|
1098
1136
|
}
|
|
1137
|
+
var cacheId = _this._cacheId++;
|
|
1138
|
+
_this._nodeCache.set(cacheId, res);
|
|
1139
|
+
_this._subCache.push({ collection: collection, publication: subscription.publication, subscriptionData: subscription.subscriptionData, id: cacheId });
|
|
1099
1140
|
// console.log('Cache1: ' + 'Create - ' + subscription.publication + ' - ' + getBinarySize(JSON.stringify(this._subCache)));
|
|
1100
1141
|
var serverRes = {
|
|
1101
1142
|
messageId: messageId,
|
|
@@ -1103,6 +1144,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
1103
1144
|
data: res
|
|
1104
1145
|
};
|
|
1105
1146
|
_this.sendWS(ws, serverRes);
|
|
1147
|
+
resolve(true);
|
|
1106
1148
|
}, function (err) {
|
|
1107
1149
|
var serverRes = {
|
|
1108
1150
|
messageId: messageId,
|
|
@@ -1110,6 +1152,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
1110
1152
|
data: err
|
|
1111
1153
|
};
|
|
1112
1154
|
_this.sendWS(ws, serverRes);
|
|
1155
|
+
reject(err);
|
|
1113
1156
|
});
|
|
1114
1157
|
}
|
|
1115
1158
|
}
|
|
@@ -1134,11 +1177,12 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
1134
1177
|
}
|
|
1135
1178
|
return [2 /*return*/];
|
|
1136
1179
|
});
|
|
1137
|
-
});
|
|
1180
|
+
}); });
|
|
1138
1181
|
};
|
|
1139
1182
|
// Fetch pub once, send to all clients linked to this pub
|
|
1140
1183
|
SubscriptionManager.prototype.sendPubData = function (subscription, type, collection) {
|
|
1141
|
-
|
|
1184
|
+
var _this = this;
|
|
1185
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
1142
1186
|
var _a, that;
|
|
1143
1187
|
var _this = this;
|
|
1144
1188
|
return __generator(this, function (_b) {
|
|
@@ -1154,6 +1198,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
1154
1198
|
};
|
|
1155
1199
|
// console.log('Cache: ' + 'Found - ' + subscription.publication + ' - ' + getBinarySize(JSON.stringify(this._subCache)));
|
|
1156
1200
|
_this.sendWS(ws, serverRes);
|
|
1201
|
+
resolve(true);
|
|
1157
1202
|
}
|
|
1158
1203
|
});
|
|
1159
1204
|
});
|
|
@@ -1176,11 +1221,12 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
1176
1221
|
// console.log('Cache: ' + 'Too Big - ' + subscription.publication + ' - ' + getBinarySize(JSON.stringify(this._subCache)));
|
|
1177
1222
|
_this._subCache.splice(0, neededSizeIndex);
|
|
1178
1223
|
}
|
|
1179
|
-
if (
|
|
1180
|
-
|
|
1181
|
-
_this._nodeCache.set(cacheId, res);
|
|
1182
|
-
_this._subCache.push({ collection: collection, publication: subscription.publication, subscriptionData: subscription.subscriptionData, id: cacheId });
|
|
1224
|
+
if (_this._subCache.some(function (a) { return a.collection === collection && a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); })) {
|
|
1225
|
+
_this._subCache.splice(_this._subCache.findIndex(function (a) { return a.collection === collection && a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); }), 1);
|
|
1183
1226
|
}
|
|
1227
|
+
var cacheId = _this._cacheId++;
|
|
1228
|
+
_this._nodeCache.set(cacheId, res);
|
|
1229
|
+
_this._subCache.push({ collection: collection, publication: subscription.publication, subscriptionData: subscription.subscriptionData, id: cacheId });
|
|
1184
1230
|
// console.log('Cache: ' + 'Create - ' + subscription.publication + ' - ' + getBinarySize(JSON.stringify(this._subCache)));
|
|
1185
1231
|
subscription.clients.forEach(function (client) {
|
|
1186
1232
|
that._wss.clients.forEach(function (ws) {
|
|
@@ -1194,6 +1240,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
1194
1240
|
}
|
|
1195
1241
|
});
|
|
1196
1242
|
});
|
|
1243
|
+
resolve(true);
|
|
1197
1244
|
}, function (err) {
|
|
1198
1245
|
subscription.clients.forEach(function (client) {
|
|
1199
1246
|
that._wss.clients.forEach(function (ws) {
|
|
@@ -1207,11 +1254,12 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
1207
1254
|
}
|
|
1208
1255
|
});
|
|
1209
1256
|
});
|
|
1257
|
+
reject(err);
|
|
1210
1258
|
});
|
|
1211
1259
|
}
|
|
1212
1260
|
return [2 /*return*/];
|
|
1213
1261
|
});
|
|
1214
|
-
});
|
|
1262
|
+
}); });
|
|
1215
1263
|
};
|
|
1216
1264
|
SubscriptionManager.prototype.sendWS = function (ws, data) {
|
|
1217
1265
|
this._sendQueue.splice(0, 0, {
|