@resolveio/server-lib 6.3.6 → 6.3.7-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 +157 -166
- 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,MAAM,GAAQ;IACjB,GAAG,EAAE;QACJ,IAAI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AAY,EAAG,CAAC,KAAK,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;CACzF;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> = (<any>ResolveIOServer.getMainDB()).model('users', DefaultSchema);\n\nexport let ClientUsers: PassportLocalModel<ResolveIOModel> = null;\n\nif (ResolveIOServer.getSupportDB()) {\n\tClientUsers = (<any>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);"]}
|
|
@@ -232,78 +232,80 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
232
232
|
subscriptionData[_i - 4] = arguments[_i];
|
|
233
233
|
}
|
|
234
234
|
return __awaiter(this, void 0, void 0, function () {
|
|
235
|
-
var that, pub, valObj, valKeys, rootKeys, i, sub, newLoggedInUser, begDate, endDate, billUser;
|
|
236
|
-
var
|
|
237
|
-
return __generator(this, function (
|
|
238
|
-
switch (
|
|
235
|
+
var that, pub, valObj, valKeys, rootKeys, i, sub, _a, newLoggedInUser, begDate, endDate, billUser;
|
|
236
|
+
var _b;
|
|
237
|
+
return __generator(this, function (_c) {
|
|
238
|
+
switch (_c.label) {
|
|
239
239
|
case 0:
|
|
240
240
|
that = this;
|
|
241
241
|
pub = that._publications[publication];
|
|
242
|
-
if (
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
if (
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
242
|
+
if (!!pub) return [3 /*break*/, 1];
|
|
243
|
+
console.error('No Publication: ' + publication);
|
|
244
|
+
return [2 /*return*/];
|
|
245
|
+
case 1:
|
|
246
|
+
if (subscriptionData.length > 1 || subscriptionData[0]) {
|
|
247
|
+
if (!pub.check) {
|
|
248
|
+
console.error('No Check Function For Pub ' + publication);
|
|
249
|
+
return [2 /*return*/];
|
|
250
|
+
}
|
|
251
|
+
else if (!pub.check._schema) {
|
|
252
|
+
console.error('No Check Schema For Pub ' + publication);
|
|
253
|
+
return [2 /*return*/];
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
valObj = {};
|
|
257
|
+
valKeys = Object.keys(pub.check._schema);
|
|
258
|
+
rootKeys = valKeys.filter(function (a) { return !a.includes('.'); });
|
|
259
|
+
for (i = 0; i < subscriptionData.length; i++) {
|
|
260
|
+
valObj[rootKeys[i]] = subscriptionData[i];
|
|
251
261
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
return [2 /*return*/];
|
|
262
|
+
try {
|
|
263
|
+
pub.check.validate(valObj);
|
|
255
264
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
}
|
|
265
|
+
catch (errors) {
|
|
266
|
+
if (errors) {
|
|
267
|
+
console.error('Error in Pub Check (' + publication + ')', errors);
|
|
268
|
+
return [2 /*return*/];
|
|
271
269
|
}
|
|
272
270
|
}
|
|
273
271
|
}
|
|
272
|
+
}
|
|
273
|
+
sub = that._subscriptions.filter(function (a) { return a.publication === publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscriptionData); })[0];
|
|
274
|
+
// If sub found (another user watching same data), add client to same sub
|
|
275
|
+
if (sub) {
|
|
276
|
+
sub.clients.push({
|
|
277
|
+
id_user: ws['id_user'],
|
|
278
|
+
messageId: messageId,
|
|
279
|
+
id_socket: ws['id_socket']
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
// If sub not found, create new sub
|
|
283
|
+
else {
|
|
284
|
+
that._subscriptions.push({
|
|
285
|
+
publication: publication,
|
|
286
|
+
subscriptionData: subscriptionData,
|
|
287
|
+
collections: that.getPublicationCollections(publication),
|
|
288
|
+
clients: [{
|
|
289
|
+
id_user: ws['id_user'],
|
|
290
|
+
messageId: messageId,
|
|
291
|
+
id_socket: ws['id_socket']
|
|
292
|
+
}]
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
if (!sub) {
|
|
274
296
|
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
|
-
}
|
|
305
297
|
}
|
|
306
|
-
|
|
298
|
+
// console.log('Subscribe', new Date(), 'Success', sub);
|
|
299
|
+
// Send pub data to client who just subscribed only, don't want to send to existing clients since nothing has changed
|
|
300
|
+
that.sendPubDataOnce(ws, messageId, sub, 'newSub', that.getPublicationCollections(publication)[0]);
|
|
301
|
+
if (!(that._publications[sub.publication].preFunction && !sub.preSubscriptionData)) return [3 /*break*/, 3];
|
|
302
|
+
_a = sub;
|
|
303
|
+
return [4 /*yield*/, (_b = that._publications[sub.publication]).preFunction.apply(_b, sub.subscriptionData)];
|
|
304
|
+
case 2:
|
|
305
|
+
_a.preSubscriptionData = _c.sent();
|
|
306
|
+
_c.label = 3;
|
|
307
|
+
case 3:
|
|
308
|
+
if (!(publication === 'appversion')) return [3 /*break*/, 5];
|
|
307
309
|
newLoggedInUser = {
|
|
308
310
|
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
309
311
|
__v: 0,
|
|
@@ -314,7 +316,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
314
316
|
};
|
|
315
317
|
this._loggedInUsers.push(newLoggedInUser);
|
|
316
318
|
logged_in_users_collection_1.LoggedInUsers.create(newLoggedInUser);
|
|
317
|
-
if (!(ws['user'] !== 'Admin' && index_1.ResolveIOServer.getSupportDB())) return [3 /*break*/,
|
|
319
|
+
if (!(ws['user'] !== 'Admin' && index_1.ResolveIOServer.getSupportDB())) return [3 /*break*/, 5];
|
|
318
320
|
begDate = moment().startOf('month');
|
|
319
321
|
endDate = moment().endOf('month');
|
|
320
322
|
return [4 /*yield*/, billing_logged_in_users_collection_1.BillingLoggedInUsers.findOne({
|
|
@@ -333,8 +335,8 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
333
335
|
}
|
|
334
336
|
]
|
|
335
337
|
})];
|
|
336
|
-
case
|
|
337
|
-
billUser =
|
|
338
|
+
case 4:
|
|
339
|
+
billUser = _c.sent();
|
|
338
340
|
if (!billUser) {
|
|
339
341
|
billing_logged_in_users_collection_1.BillingLoggedInUsers.create({
|
|
340
342
|
_id: mongoose_1.Types.ObjectId().toHexString(),
|
|
@@ -345,8 +347,8 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
345
347
|
client: index_1.ResolveIOServer.getClientName()
|
|
346
348
|
});
|
|
347
349
|
}
|
|
348
|
-
|
|
349
|
-
case
|
|
350
|
+
_c.label = 5;
|
|
351
|
+
case 5: return [2 /*return*/];
|
|
350
352
|
}
|
|
351
353
|
});
|
|
352
354
|
});
|
|
@@ -376,9 +378,6 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
376
378
|
}
|
|
377
379
|
}
|
|
378
380
|
}
|
|
379
|
-
else {
|
|
380
|
-
console.log(ws['user'] + ' - Did not find sub on unsubscribe - publication: ' + publication + ', subData: ' + JSON.stringify(subscriptionData, null, 2));
|
|
381
|
-
}
|
|
382
381
|
}
|
|
383
382
|
return [2 /*return*/];
|
|
384
383
|
});
|
|
@@ -532,51 +531,31 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
532
531
|
if (sub.preSubscriptionData) {
|
|
533
532
|
if (that._publications[sub.publication].fetchFunction(oplog.doc, sub.preSubscriptionData)) {
|
|
534
533
|
if (!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }).length) {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
}
|
|
538
|
-
else {
|
|
539
|
-
sub['oplog'] = oplog;
|
|
540
|
-
uniquePubs.push(common_1.deepCopy(sub));
|
|
541
|
-
}
|
|
534
|
+
sub['oplog'] = oplog;
|
|
535
|
+
uniquePubs.push(common_1.deepCopy(sub));
|
|
542
536
|
}
|
|
543
537
|
return "continue";
|
|
544
538
|
}
|
|
545
539
|
}
|
|
546
540
|
if (that._publications[sub.publication].preFunction) {
|
|
547
|
-
if (!sub.
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
else {
|
|
551
|
-
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) {
|
|
552
|
-
sub['oplog'] = oplog;
|
|
553
|
-
uniquePubs.push(common_1.deepCopy(sub));
|
|
554
|
-
}
|
|
541
|
+
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) {
|
|
542
|
+
sub['oplog'] = oplog;
|
|
543
|
+
uniquePubs.push(common_1.deepCopy(sub));
|
|
555
544
|
}
|
|
556
545
|
}
|
|
557
546
|
else {
|
|
558
547
|
if (that._publications[sub.publication].fetchFunction) {
|
|
559
548
|
if ((_a = that._publications[sub.publication]).fetchFunction.apply(_a, __spreadArrays([oplog.doc], sub.subscriptionData))) {
|
|
560
549
|
if (!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }).length) {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
}
|
|
564
|
-
else {
|
|
565
|
-
sub['oplog'] = oplog;
|
|
566
|
-
uniquePubs.push(common_1.deepCopy(sub));
|
|
567
|
-
}
|
|
550
|
+
sub['oplog'] = oplog;
|
|
551
|
+
uniquePubs.push(common_1.deepCopy(sub));
|
|
568
552
|
}
|
|
569
553
|
}
|
|
570
554
|
}
|
|
571
555
|
else {
|
|
572
556
|
if (!uniquePubs.filter(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }).length) {
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
}
|
|
576
|
-
else {
|
|
577
|
-
sub['oplog'] = oplog;
|
|
578
|
-
uniquePubs.push(common_1.deepCopy(sub));
|
|
579
|
-
}
|
|
557
|
+
sub['oplog'] = oplog;
|
|
558
|
+
uniquePubs.push(common_1.deepCopy(sub));
|
|
580
559
|
}
|
|
581
560
|
}
|
|
582
561
|
}
|
|
@@ -601,7 +580,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
601
580
|
};
|
|
602
581
|
SubscriptionManager.prototype.resendPubsForDelete = function (collection) {
|
|
603
582
|
return __awaiter(this, void 0, void 0, function () {
|
|
604
|
-
var that, subCopy, _loop_7, this_3, jj,
|
|
583
|
+
var that, subCopy, _loop_7, this_3, jj, zz, sub, aa, client, bb, ws;
|
|
605
584
|
var _this = this;
|
|
606
585
|
return __generator(this, function (_a) {
|
|
607
586
|
that = this;
|
|
@@ -616,13 +595,13 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
616
595
|
for (jj = this._subCache.length - 1; jj >= 0; jj--) {
|
|
617
596
|
_loop_7(jj);
|
|
618
597
|
}
|
|
619
|
-
|
|
620
|
-
|
|
598
|
+
for (zz = subCopy.length - 1; zz >= 0; zz--) {
|
|
599
|
+
sub = subCopy[zz];
|
|
621
600
|
if (that._publications[sub.publication].ws_specific) {
|
|
622
|
-
for (
|
|
623
|
-
|
|
624
|
-
for (
|
|
625
|
-
|
|
601
|
+
for (aa = 0; aa < sub.clients.length; aa++) {
|
|
602
|
+
client = sub.clients[aa];
|
|
603
|
+
for (bb = 0; bb < that._wss.clients.size; bb++) {
|
|
604
|
+
ws = Array.from(that._wss.clients)[bb];
|
|
626
605
|
if (ws['id_socket'] === client.id_socket) {
|
|
627
606
|
that.sendPubDataOnce(ws, client.messageId, sub, 'delete', collection);
|
|
628
607
|
}
|
|
@@ -630,18 +609,8 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
630
609
|
}
|
|
631
610
|
}
|
|
632
611
|
else {
|
|
633
|
-
|
|
634
|
-
if (that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }) >= 0) {
|
|
635
|
-
that._subscriptions.splice(that._subscriptions.findIndex(function (a) { return a.publication === sub.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(sub.subscriptionData); }), 1);
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
else {
|
|
639
|
-
that.sendPubData(sub, 'delete', collection);
|
|
640
|
-
}
|
|
612
|
+
that.sendPubData(sub, 'delete', collection);
|
|
641
613
|
}
|
|
642
|
-
};
|
|
643
|
-
for (zz = subCopy.length - 1; zz >= 0; zz--) {
|
|
644
|
-
_loop_8(zz);
|
|
645
614
|
}
|
|
646
615
|
return [2 /*return*/];
|
|
647
616
|
});
|
|
@@ -816,8 +785,11 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
816
785
|
// console.log('Cache1: ' + 'Too Big - ' + subscription.publication + ' - ' + getBinarySize(JSON.stringify(this._subCache)));
|
|
817
786
|
_this._subCache.splice(0, neededSizeIndex);
|
|
818
787
|
}
|
|
819
|
-
if (_this._subCache.some(function (a) { return a.
|
|
820
|
-
_this._subCache.
|
|
788
|
+
if (_this._subCache.some(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); })) {
|
|
789
|
+
_this._subCache.filter(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); }).forEach(function (subCache) {
|
|
790
|
+
_this._nodeCache.del(_this._subCache.filter(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); })[0].id);
|
|
791
|
+
_this._subCache.splice(_this._subCache.findIndex(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); }), 1);
|
|
792
|
+
});
|
|
821
793
|
}
|
|
822
794
|
var cacheId = _this._cacheId++;
|
|
823
795
|
_this._nodeCache.set(cacheId, res);
|
|
@@ -875,58 +847,77 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
875
847
|
var _this = this;
|
|
876
848
|
return __generator(this, function (_b) {
|
|
877
849
|
that = this;
|
|
878
|
-
if (subscription.
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
var neededSizeIndex = 0;
|
|
885
|
-
for (var zz = 0; zz < _this._subCache.length; zz++) {
|
|
886
|
-
_this._nodeCache.del(_this._subCache[zz].id);
|
|
887
|
-
if (_this._nodeCache.getStats().vsize < 500000000) {
|
|
888
|
-
neededSizeIndex = zz;
|
|
889
|
-
break;
|
|
890
|
-
}
|
|
891
|
-
}
|
|
892
|
-
// console.log('Cache: ' + 'Too Big - ' + subscription.publication + ' - ' + getBinarySize(JSON.stringify(this._subCache)));
|
|
893
|
-
_this._subCache.splice(0, neededSizeIndex);
|
|
850
|
+
if (!subscription.clients.length) {
|
|
851
|
+
if (this._subCache.some(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); })) {
|
|
852
|
+
this._subCache.filter(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); }).forEach(function (subCache) {
|
|
853
|
+
_this._nodeCache.del(_this._subCache.filter(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); })[0].id);
|
|
854
|
+
_this._subCache.splice(_this._subCache.findIndex(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); }), 1);
|
|
855
|
+
});
|
|
894
856
|
}
|
|
895
|
-
|
|
896
|
-
|
|
857
|
+
that._subscriptions.splice(that._subscriptions.findIndex(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); }), 1);
|
|
858
|
+
}
|
|
859
|
+
else {
|
|
860
|
+
if (subscription.publication !== 'superadminAPM' && subscription.publication !== 'loggedInUsers') {
|
|
861
|
+
that._mainServer.getMethodManager().callMethodInternal('insertSubscriptionLog', type, subscription.publication, collection, JSON.stringify(subscription.subscriptionData));
|
|
897
862
|
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
data: res
|
|
909
|
-
};
|
|
910
|
-
_this.sendWS(ws, serverRes);
|
|
911
|
-
}
|
|
912
|
-
});
|
|
913
|
-
});
|
|
914
|
-
resolve(true);
|
|
915
|
-
}, function (err) {
|
|
916
|
-
subscription.clients.forEach(function (client) {
|
|
917
|
-
that._wss.clients.forEach(function (ws) {
|
|
918
|
-
if (ws['id_socket'] === client.id_socket) {
|
|
919
|
-
var serverRes = {
|
|
920
|
-
messageId: client.messageId,
|
|
921
|
-
hasError: true,
|
|
922
|
-
data: err
|
|
923
|
-
};
|
|
924
|
-
_this.sendWS(ws, serverRes);
|
|
863
|
+
(_a = that._publications[subscription.publication].function).call.apply(_a, __spreadArrays([Object.assign({}, that, SubscriptionManager.prototype)], subscription.subscriptionData)).then(function (res) {
|
|
864
|
+
var nodeCacheSize = _this._nodeCache.getStats().vsize;
|
|
865
|
+
if (nodeCacheSize > 500000000) {
|
|
866
|
+
var neededSizeIndex = 0;
|
|
867
|
+
for (var zz = 0; zz < _this._subCache.length; zz++) {
|
|
868
|
+
_this._nodeCache.del(_this._subCache[zz].id);
|
|
869
|
+
if (_this._nodeCache.getStats().vsize < 500000000) {
|
|
870
|
+
neededSizeIndex = zz;
|
|
871
|
+
break;
|
|
872
|
+
}
|
|
925
873
|
}
|
|
874
|
+
// console.log('Cache: ' + 'Too Big - ' + subscription.publication + ' - ' + getBinarySize(JSON.stringify(this._subCache)));
|
|
875
|
+
_this._subCache.splice(0, neededSizeIndex);
|
|
876
|
+
}
|
|
877
|
+
if (_this._subCache.some(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); })) {
|
|
878
|
+
_this._subCache.filter(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); }).forEach(function (subCache) {
|
|
879
|
+
_this._nodeCache.del(_this._subCache.filter(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); })[0].id);
|
|
880
|
+
_this._subCache.splice(_this._subCache.findIndex(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); }), 1);
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
if (!subscription.clients.length) {
|
|
884
|
+
that._subscriptions.splice(that._subscriptions.findIndex(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); }), 1);
|
|
885
|
+
}
|
|
886
|
+
else {
|
|
887
|
+
var cacheId = _this._cacheId++;
|
|
888
|
+
_this._nodeCache.set(cacheId, res);
|
|
889
|
+
_this._subCache.push({ collection: collection, publication: subscription.publication, subscriptionData: subscription.subscriptionData, id: cacheId });
|
|
890
|
+
// console.log('Cache: ' + 'Create - ' + subscription.publication + ' - ' + getBinarySize(JSON.stringify(this._subCache)));
|
|
891
|
+
subscription.clients.forEach(function (client) {
|
|
892
|
+
that._wss.clients.forEach(function (ws) {
|
|
893
|
+
if (ws['id_socket'] === client.id_socket) {
|
|
894
|
+
var serverRes = {
|
|
895
|
+
messageId: client.messageId,
|
|
896
|
+
hasError: false,
|
|
897
|
+
data: res
|
|
898
|
+
};
|
|
899
|
+
_this.sendWS(ws, serverRes);
|
|
900
|
+
}
|
|
901
|
+
});
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
resolve(true);
|
|
905
|
+
}, function (err) {
|
|
906
|
+
subscription.clients.forEach(function (client) {
|
|
907
|
+
that._wss.clients.forEach(function (ws) {
|
|
908
|
+
if (ws['id_socket'] === client.id_socket) {
|
|
909
|
+
var serverRes = {
|
|
910
|
+
messageId: client.messageId,
|
|
911
|
+
hasError: true,
|
|
912
|
+
data: err
|
|
913
|
+
};
|
|
914
|
+
_this.sendWS(ws, serverRes);
|
|
915
|
+
}
|
|
916
|
+
});
|
|
926
917
|
});
|
|
918
|
+
reject(err);
|
|
927
919
|
});
|
|
928
|
-
|
|
929
|
-
});
|
|
920
|
+
}
|
|
930
921
|
return [2 /*return*/];
|
|
931
922
|
});
|
|
932
923
|
}); });
|