@resolveio/server-lib 4.5.1 → 4.5.3
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/methods/report-builder.js +92 -44
- package/package.json +1 -1
- package/server-app.js +10 -0
|
@@ -196,7 +196,7 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
196
196
|
if (date_field === void 0) { date_field = ''; }
|
|
197
197
|
if (date_interval === void 0) { date_interval = ''; }
|
|
198
198
|
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
199
|
-
var _a, uniqueSelectedFieldCollections, modelCollection, queryMatchCondition, queryLookups, queryGroupUnwindCollectionPaths, queryUnwindCollectionPaths, initialProjection, queryGroups, queryGroupUnwind, initialGroup, secondInitialGroup, zipLayers, cnt, _loop_1, correctSort_1, _loop_2, i, queryProjection, queryTotals, query, i, res, err_1;
|
|
199
|
+
var _a, uniqueSelectedFieldCollections, modelCollection, queryMatchCondition, queryLookups, queryGroupUnwindCollectionPaths, queryUnwindCollectionPaths, initialProjection, queryGroups, queryGroupUnwind, initialGroup, secondInitialGroup, zipLayers, initialNonSumFilterProj, initialNonSumElemAtProj, initialNonSumValueProj, cnt, _loop_1, correctSort_1, _loop_2, i, queryProjection, queryTotals, query, i, res, err_1;
|
|
200
200
|
return __generator(this, function (_b) {
|
|
201
201
|
switch (_b.label) {
|
|
202
202
|
case 0:
|
|
@@ -346,7 +346,7 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
346
346
|
initialGroup = { _id: {} };
|
|
347
347
|
groupsRow.forEach(function (row) {
|
|
348
348
|
initialGroup._id[row.id] = '$' + row.field.replace(/\.\$/g, '');
|
|
349
|
-
initialGroup.rb_arrays_0 = { '$
|
|
349
|
+
initialGroup.rb_arrays_0 = { '$push': '$rb_arrays_0' };
|
|
350
350
|
initialGroup.count = { '$sum': '$count' };
|
|
351
351
|
selectedFields.filter(function (a) { return !a.fieldPath.includes('$') && a.collection_name === rootCollectionName; }).forEach(function (field) {
|
|
352
352
|
if (field.leafValueType === 'Average') {
|
|
@@ -425,6 +425,70 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
425
425
|
});
|
|
426
426
|
}
|
|
427
427
|
}
|
|
428
|
+
initialNonSumFilterProj = null;
|
|
429
|
+
initialNonSumElemAtProj = null;
|
|
430
|
+
initialNonSumValueProj = null;
|
|
431
|
+
if (selectedFields.some(function (a) { return a.fieldPath.split('.$').length === 2 && (a.leafValueType !== 'Average' && a.leafValueType !== 'Sum'); })) {
|
|
432
|
+
initialNonSumFilterProj = { $addFields: {} };
|
|
433
|
+
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === 2; }).forEach(function (field) {
|
|
434
|
+
var _a;
|
|
435
|
+
initialNonSumFilterProj.$addFields['rb_arrays_0_' + field.id] = {
|
|
436
|
+
$filter: {
|
|
437
|
+
input: '$rb_arrays_0',
|
|
438
|
+
cond: {
|
|
439
|
+
$and: [
|
|
440
|
+
{ $ne: ['$$this', null] },
|
|
441
|
+
{ $ne: ['$$this.' + field.fieldPath.split('.$.')[0], null] },
|
|
442
|
+
{ $ne: ['$$this.' + field.fieldPath.split('.$.')[0] + field.fieldPath.split('.$')[1], null] }
|
|
443
|
+
]
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
if (filterArrayPaths.some(function (a) { return a === field.fieldPath; })) {
|
|
448
|
+
var tmpOr_1 = [];
|
|
449
|
+
var filter = common_1.deepCopy(filterArrays[filterArrayPaths.indexOf(field.fieldPath)]);
|
|
450
|
+
if (filter['$or']) {
|
|
451
|
+
filter['$or'].forEach(function (orVal) {
|
|
452
|
+
var _a;
|
|
453
|
+
tmpOr_1.push((_a = {},
|
|
454
|
+
_a[Object.keys(orVal[Object.keys(orVal)[0]])[0]] = ['$$this.' + field.fieldPath.split('.$.')[0] + field.fieldPath.split('.$')[1], orVal[Object.keys(orVal)[0]][Object.keys(orVal[Object.keys(orVal)[0]])[0]]],
|
|
455
|
+
_a));
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
else {
|
|
459
|
+
initialNonSumFilterProj.$addFields['rb_arrays_0_' + field.id].$filter.cond.$and.push((_a = {}, _a[Object.keys(filter[Object.keys(filter)[0]])[0]] = ['$$this.' + field.fieldPath.split('.$.')[0] + field.fieldPath.split('.$')[1], filter[Object.keys(filter)[0]][Object.keys(filter[Object.keys(filter)[0]])[0]]], _a));
|
|
460
|
+
}
|
|
461
|
+
if (tmpOr_1.length) {
|
|
462
|
+
initialNonSumFilterProj.$addFields['rb_arrays_0_' + field.id].$filter.cond.$and.push({ $or: tmpOr_1 });
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
initialNonSumElemAtProj = { $addFields: {} };
|
|
467
|
+
initialNonSumValueProj = { $addFields: {} };
|
|
468
|
+
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === 2; }).forEach(function (field) {
|
|
469
|
+
initialNonSumElemAtProj.$addFields['rb_arrays_0_' + field.id] = '$rb_arrays_0_' + field.id + '.' + field.fieldPath.split('.$')[0];
|
|
470
|
+
});
|
|
471
|
+
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === 2; }).forEach(function (field) {
|
|
472
|
+
if (field.leafValueType === 'Count') {
|
|
473
|
+
initialNonSumValueProj.$addFields[field.id] = { '$size': '$rb_arrays_0_' + field.id + field.fieldPath.split('.$')[1] };
|
|
474
|
+
}
|
|
475
|
+
else if (field.leafValueType === 'Minimum') {
|
|
476
|
+
initialNonSumValueProj.$addFields[field.id] = { '$min': '$rb_arrays_0_' + field.id + field.fieldPath.split('.$')[1] };
|
|
477
|
+
}
|
|
478
|
+
else if (field.leafValueType === 'Maximum') {
|
|
479
|
+
initialNonSumValueProj.$addFields[field.id] = { '$max': '$rb_arrays_0_' + field.id + field.fieldPath.split('.$')[1] };
|
|
480
|
+
}
|
|
481
|
+
else if (field.leafValueType === 'First') {
|
|
482
|
+
initialNonSumValueProj.$addFields[field.id] = { '$arrayElemAt': ['$rb_arrays_0_' + field.id + field.fieldPath.split('.$')[1], 0] };
|
|
483
|
+
}
|
|
484
|
+
else if (field.leafValueType === 'Last') {
|
|
485
|
+
initialNonSumValueProj.$addFields[field.id] = { '$arrayElemAt': ['$rb_arrays_0_' + field.id + field.fieldPath.split('.$')[1], -1] };
|
|
486
|
+
}
|
|
487
|
+
else { //push
|
|
488
|
+
initialNonSumValueProj.$addFields[field.id] = '$rb_arrays_0_' + field.id + field.fieldPath.split('.$')[1];
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
}
|
|
428
492
|
cnt = 1;
|
|
429
493
|
_loop_1 = function () {
|
|
430
494
|
var group = { $group: { _id: {} } };
|
|
@@ -463,12 +527,12 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
463
527
|
}
|
|
464
528
|
zipLayers.push(group);
|
|
465
529
|
}
|
|
466
|
-
var proj = { $
|
|
530
|
+
var proj = { $addFields: {} };
|
|
467
531
|
selectedFields.filter(function (a) { return a.fieldPath.split('.$').length <= cnt + 1; }).forEach(function (field) {
|
|
468
|
-
proj.$
|
|
532
|
+
proj.$addFields[field.id] = 1;
|
|
469
533
|
});
|
|
470
534
|
if (selectedFields.some(function (a) { return a.fieldPath.split('.$').length === cnt + 2; })) {
|
|
471
|
-
proj.$
|
|
535
|
+
proj.$addFields['rb_arrays_' + cnt] = {
|
|
472
536
|
$map: {
|
|
473
537
|
input: {
|
|
474
538
|
$zip: {
|
|
@@ -485,10 +549,10 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
485
549
|
for (var i = 1; i < cnt + 1; i++) {
|
|
486
550
|
fieldPath += field.fieldPath.split('.$')[i];
|
|
487
551
|
}
|
|
488
|
-
if (!proj.$
|
|
489
|
-
if (!proj.$
|
|
490
|
-
proj.$
|
|
491
|
-
proj.$
|
|
552
|
+
if (!proj.$addFields['rb_arrays_' + cnt].$map.input.$zip.inputs.some(function (a) { return a === '$' + fieldPath; })) {
|
|
553
|
+
if (!proj.$addFields['rb_arrays_' + cnt].$map.input.$zip.inputs.some(function (a) { return a === '$rb_arrays_' + (cnt - 1) + '.' + fieldPath; })) {
|
|
554
|
+
proj.$addFields['rb_arrays_' + cnt].$map.input.$zip.inputs.push('$rb_arrays_' + (cnt - 1) + '.' + fieldPath);
|
|
555
|
+
proj.$addFields['rb_arrays_' + cnt].$map.in[field.fieldPath.split('.$.')[cnt]] = {
|
|
492
556
|
$arrayElemAt: ['$$zipped', index]
|
|
493
557
|
};
|
|
494
558
|
}
|
|
@@ -499,37 +563,6 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
499
563
|
path: '$rb_arrays_' + cnt,
|
|
500
564
|
preserveNullAndEmptyArrays: true
|
|
501
565
|
} });
|
|
502
|
-
var tmpMatch = {
|
|
503
|
-
"$match": {
|
|
504
|
-
$and: []
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
var newfilterArrays_1 = [];
|
|
508
|
-
filterArrayPaths.forEach(function (filterPath, index) {
|
|
509
|
-
var _a;
|
|
510
|
-
var tmpOr = [];
|
|
511
|
-
if (filterPath.split('.$').length === cnt + 2) {
|
|
512
|
-
var filter = common_1.deepCopy(filterArrays[index]);
|
|
513
|
-
if (filter['$or']) {
|
|
514
|
-
filter['$or'].forEach(function (orVal) {
|
|
515
|
-
var _a;
|
|
516
|
-
var filterProp = '$rb_arrays_' + cnt + '.' + Object.keys(orVal)[0];
|
|
517
|
-
tmpOr.push((_a = {}, _a[filterProp] = orVal[Object.keys(orVal)[0]], _a));
|
|
518
|
-
});
|
|
519
|
-
}
|
|
520
|
-
else {
|
|
521
|
-
var filterProp = '$rb_arrays_' + cnt + '.' + Object.keys(filter)[0];
|
|
522
|
-
newfilterArrays_1.push((_a = {}, _a[filterProp] = filter[Object.keys(filter)[0]], _a));
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
if (tmpOr.length) {
|
|
526
|
-
newfilterArrays_1.push({ $or: tmpOr });
|
|
527
|
-
}
|
|
528
|
-
});
|
|
529
|
-
tmpMatch.$match.$and = newfilterArrays_1;
|
|
530
|
-
if (tmpMatch.$match.$and.length) {
|
|
531
|
-
zipLayers.push(tmpMatch);
|
|
532
|
-
}
|
|
533
566
|
}
|
|
534
567
|
cnt++;
|
|
535
568
|
};
|
|
@@ -738,17 +771,32 @@ function loadReportBuilderMethods(methodManager) {
|
|
|
738
771
|
$group: initialGroup
|
|
739
772
|
});
|
|
740
773
|
}
|
|
774
|
+
if (secondInitialGroup) {
|
|
775
|
+
query.push({
|
|
776
|
+
$group: secondInitialGroup
|
|
777
|
+
});
|
|
778
|
+
}
|
|
741
779
|
query.push({
|
|
742
780
|
$unwind: {
|
|
743
781
|
"path": "$rb_arrays_0",
|
|
744
782
|
"preserveNullAndEmptyArrays": true
|
|
745
783
|
}
|
|
746
784
|
});
|
|
747
|
-
if (
|
|
748
|
-
query.push(
|
|
749
|
-
$group: secondInitialGroup
|
|
750
|
-
});
|
|
785
|
+
if (initialNonSumFilterProj) {
|
|
786
|
+
query.push(initialNonSumFilterProj);
|
|
751
787
|
}
|
|
788
|
+
if (initialNonSumElemAtProj) {
|
|
789
|
+
query.push(initialNonSumElemAtProj);
|
|
790
|
+
}
|
|
791
|
+
if (initialNonSumValueProj) {
|
|
792
|
+
query.push(initialNonSumValueProj);
|
|
793
|
+
}
|
|
794
|
+
query.push({
|
|
795
|
+
$unwind: {
|
|
796
|
+
"path": "$rb_arrays_0",
|
|
797
|
+
"preserveNullAndEmptyArrays": true
|
|
798
|
+
}
|
|
799
|
+
});
|
|
752
800
|
for (i = 0; i < zipLayers.length; i++) {
|
|
753
801
|
query.push(zipLayers[i]);
|
|
754
802
|
}
|
package/package.json
CHANGED
package/server-app.js
CHANGED
|
@@ -64,6 +64,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
64
64
|
function ResolveIOMainServer(mainServer, serverConfig, clientDir) {
|
|
65
65
|
this._msgQueue = [];
|
|
66
66
|
this._msgQueueRunning = false;
|
|
67
|
+
console.log('Starting ResolveIO Server');
|
|
67
68
|
this._resolveioServer = mainServer;
|
|
68
69
|
this._serverConfig = serverConfig;
|
|
69
70
|
this._clientDir = clientDir;
|
|
@@ -75,8 +76,10 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
75
76
|
this._app.use(bodyParser.urlencoded({ limit: '5mb', extended: true }));
|
|
76
77
|
// Set port
|
|
77
78
|
this._port = process.env.PORT || serverConfig['PORT'];
|
|
79
|
+
console.log('Setup ports');
|
|
78
80
|
// Create http server and websock server
|
|
79
81
|
this.createServer();
|
|
82
|
+
console.log('Create server');
|
|
80
83
|
// Set CORS
|
|
81
84
|
this._app.use(function (req, res, next) {
|
|
82
85
|
// Website you wish to allow to connect
|
|
@@ -93,9 +96,11 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
93
96
|
// Pass to next layer of middleware
|
|
94
97
|
next();
|
|
95
98
|
});
|
|
99
|
+
console.log('Setup cors');
|
|
96
100
|
// Set up http login route
|
|
97
101
|
auth_1.setupAuthRoutes(this, this._app, serverConfig);
|
|
98
102
|
health_1.setupHealthRoutes(this._app, serverConfig);
|
|
103
|
+
console.log('Setup express routes');
|
|
99
104
|
}
|
|
100
105
|
ResolveIOMainServer.prototype.getWS = function (id_ws) {
|
|
101
106
|
var res = null;
|
|
@@ -140,6 +145,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
140
145
|
var infoData, token;
|
|
141
146
|
var _this = this;
|
|
142
147
|
return __generator(this, function (_a) {
|
|
148
|
+
console.log('Verify Client', info, cb);
|
|
143
149
|
infoData = info.req.headers['sec-websocket-protocol'].split(/,/);
|
|
144
150
|
if (info.origin !== this._serverConfig['ROOT_URL'] && info.origin !== this._serverConfig['SEC_ROOT_URL'] && info.origin !== this._serverConfig['RESOLVEIO_URL'] && info.origin !== this._serverConfig['RESOLVEIO_SECONDARY_URL']) {
|
|
145
151
|
cb(false, 401, 'Unauthorized');
|
|
@@ -208,12 +214,14 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
208
214
|
__setOptions.apply(this, arguments);
|
|
209
215
|
return this;
|
|
210
216
|
};
|
|
217
|
+
console.log('Start Managers');
|
|
211
218
|
// Start Managers
|
|
212
219
|
this._subscriptionManager = new subscription_manager_1.SubscriptionManager(this, this._wss, this._serverConfig);
|
|
213
220
|
this._methodManager = new method_manager_1.MethodManager(this, this._serverConfig, this._clientDir);
|
|
214
221
|
this._supportManager = new support_manager_1.SupportManager(this, this._serverConfig, this._clientDir);
|
|
215
222
|
this._cronManager = new cron_manager_1.CronManager(this);
|
|
216
223
|
this._queueManager = new queue_method_manager_1.QueueMethodManager(this);
|
|
224
|
+
console.log('End Managers');
|
|
217
225
|
this.listen();
|
|
218
226
|
mongoose.set('useFindAndModify', false);
|
|
219
227
|
// mongoose.set('useCreateIndexes', true);
|
|
@@ -240,6 +248,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
240
248
|
ws['user_readonly'] = req.user_readonly;
|
|
241
249
|
ws['id_socket'] = uuid();
|
|
242
250
|
ws['retryCnt'] = 0;
|
|
251
|
+
console.log('Connection from: ' + req.user);
|
|
243
252
|
// Use for keeping connection alive (ping/pong)
|
|
244
253
|
ws['isAlive'] = true;
|
|
245
254
|
ws.on('pong', function () {
|
|
@@ -257,6 +266,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
257
266
|
var _a, _b, socketData, data, messageDate, messageId, type, subType, pub;
|
|
258
267
|
var _this = this;
|
|
259
268
|
return __generator(this, function (_c) {
|
|
269
|
+
console.log('Message from: ' + ws['user'], message);
|
|
260
270
|
socketData = JSON.parse(message, common_1.dateReviver);
|
|
261
271
|
data = common_2.deepCopy(socketData);
|
|
262
272
|
if (data[0] === 'ping') {
|