@resolveio/server-lib 4.5.3 → 4.5.5

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.
@@ -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, initialNonSumFilterProj, initialNonSumElemAtProj, initialNonSumValueProj, 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, group, 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:
@@ -491,46 +491,7 @@ function loadReportBuilderMethods(methodManager) {
491
491
  }
492
492
  cnt = 1;
493
493
  _loop_1 = function () {
494
- var group = { $group: { _id: {} } };
495
- if (selectedFields.some(function (a) { return a.fieldPath.split('.$').length === cnt + 1 && (a.leafValueType === 'Average' || a.leafValueType === 'Sum'); })) {
496
- groupsRow.forEach(function (row) {
497
- group.$group._id[row.id] = '$_id.' + row.id;
498
- });
499
- group.$group['rb_arrays_' + (cnt - 1)] = { '$push': '$rb_arrays_' + (cnt - 1) };
500
- selectedFields.filter(function (a) { return a.fieldPath.split('.$').length <= cnt; }).forEach(function (field) {
501
- group.$group[field.id] = { $first: '$' + field.id };
502
- });
503
- selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === cnt + 1; }).forEach(function (field) {
504
- var tmpPath = field.fieldPath.split('.$.')[cnt - 1] + field.fieldPath.split('.$')[cnt];
505
- if (field.leafValueType === 'Average') {
506
- group.$group[field.id] = { '$avg': '$rb_arrays_' + (cnt - 1) + '.' + tmpPath };
507
- }
508
- else if (field.leafValueType === 'Sum') {
509
- group.$group[field.id] = { '$sum': '$rb_arrays_' + (cnt - 1) + '.' + tmpPath };
510
- }
511
- });
512
- if (fieldsTotal.length) {
513
- fieldsTotal.forEach(function (total) {
514
- selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.fieldPath.split('.$').length === 1; }).forEach(function (field) {
515
- group.$group[total.id + '_' + field.id] = { $first: '$' + field.fieldPath.replace(/\.\$/g, '') };
516
- });
517
- selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.fieldPath.split('.$').length < cnt + 1 && a.fieldPath.split('.$').length > 1; }).forEach(function (field) {
518
- var tmpPath = field.fieldPath.split('.$.')[cnt - 1] + field.fieldPath.split('.$')[cnt];
519
- group.$group[total.id + '_' + field.id] = { $first: '$rb_arrays_' + (cnt - 1) + '.' + tmpPath };
520
- });
521
- selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.fieldPath.split('.$').length === cnt + 1; }).forEach(function (field) {
522
- var _a;
523
- var tmpPath = field.fieldPath.split('.$.')[cnt - 1] + field.fieldPath.split('.$')[cnt];
524
- group.$group[total.id + '_' + field.id] = (_a = {}, _a['$' + total.type] = '$rb_arrays_' + (cnt - 1) + '.' + tmpPath, _a);
525
- });
526
- });
527
- }
528
- zipLayers.push(group);
529
- }
530
494
  var proj = { $addFields: {} };
531
- selectedFields.filter(function (a) { return a.fieldPath.split('.$').length <= cnt + 1; }).forEach(function (field) {
532
- proj.$addFields[field.id] = 1;
533
- });
534
495
  if (selectedFields.some(function (a) { return a.fieldPath.split('.$').length === cnt + 2; })) {
535
496
  proj.$addFields['rb_arrays_' + cnt] = {
536
497
  $map: {
@@ -559,10 +520,112 @@ function loadReportBuilderMethods(methodManager) {
559
520
  }
560
521
  });
561
522
  zipLayers.push(proj);
562
- zipLayers.push({ $unwind: {
563
- path: '$rb_arrays_' + cnt,
564
- preserveNullAndEmptyArrays: true
565
- } });
523
+ if (selectedFields.some(function (a) { return a.fieldPath.split('.$').length === cnt + 2; })) {
524
+ var proj_1 = { $addFields: {} };
525
+ selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === cnt + 2; }).forEach(function (field) {
526
+ var _a;
527
+ proj_1.$addFields['rb_arrays_' + cnt + '_' + field.id] = {
528
+ $filter: {
529
+ input: '$rb_arrays_' + cnt,
530
+ cond: {
531
+ $and: [
532
+ { $ne: ['$$this', null] }
533
+ ]
534
+ }
535
+ }
536
+ };
537
+ var path = '$$this';
538
+ for (var k = 0; k <= cnt; k++) {
539
+ path += '.' + field.fieldPath.split('.$.')[k];
540
+ proj_1.$addFields['rb_arrays_' + cnt + '_' + field.id].$filter.cond.$and.push({ $ne: [path, null] });
541
+ }
542
+ if (filterArrayPaths.some(function (a) { return a === field.fieldPath; })) {
543
+ var tmpOr_2 = [];
544
+ var filter = common_1.deepCopy(filterArrays[filterArrayPaths.indexOf(field.fieldPath)]);
545
+ if (filter['$or']) {
546
+ filter['$or'].forEach(function (orVal) {
547
+ var _a;
548
+ tmpOr_2.push((_a = {},
549
+ _a[Object.keys(orVal[Object.keys(orVal)[0]])[0]] = [path, orVal[Object.keys(orVal)[0]][Object.keys(orVal[Object.keys(orVal)[0]])[0]]],
550
+ _a));
551
+ });
552
+ }
553
+ else {
554
+ proj_1.$addFields['rb_arrays_' + cnt + '_' + field.id].$filter.cond.$and.push((_a = {}, _a[Object.keys(filter[Object.keys(filter)[0]])[0]] = [path, filter[Object.keys(filter)[0]][Object.keys(filter[Object.keys(filter)[0]])[0]]], _a));
555
+ }
556
+ if (tmpOr_2.length) {
557
+ proj_1.$addFields['rb_arrays_' + cnt + '_' + field.id].$filter.cond.$and.push({ $or: tmpOr_2 });
558
+ }
559
+ }
560
+ zipLayers.push(proj_1);
561
+ });
562
+ proj_1 = { $addFields: {} };
563
+ selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === cnt + 2; }).forEach(function (field) {
564
+ proj_1.$addFields['rb_arrays_' + cnt + '_' + field.id] = '$rb_arrays_' + cnt + '_' + field.id + field.fieldPath.split('.$')[cnt];
565
+ });
566
+ zipLayers.push(proj_1);
567
+ proj_1 = { $addFields: {} };
568
+ selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === cnt + 2; }).forEach(function (field) {
569
+ if (field.leafValueType === 'Count') {
570
+ proj_1.$addFields[field.id] = { '$size': '$rb_arrays_' + cnt + '_' + field.id + field.fieldPath.split('.$')[cnt + 1] };
571
+ }
572
+ else if (field.leafValueType === 'Minimum') {
573
+ proj_1.$addFields[field.id] = { '$min': '$rb_arrays_' + cnt + '_' + field.id + field.fieldPath.split('.$')[cnt + 1] };
574
+ }
575
+ else if (field.leafValueType === 'Maximum') {
576
+ proj_1.$addFields[field.id] = { '$max': '$rb_arrays_' + cnt + '_' + field.id + field.fieldPath.split('.$')[cnt + 1] };
577
+ }
578
+ else if (field.leafValueType === 'First') {
579
+ proj_1.$addFields[field.id] = { '$arrayElemAt': ['$rb_arrays_' + cnt + '_' + field.id + field.fieldPath.split('.$')[cnt + 1], 0] };
580
+ }
581
+ else if (field.leafValueType === 'Last') {
582
+ proj_1.$addFields[field.id] = { '$arrayElemAt': ['$rb_arrays_' + cnt + '_' + field.id + field.fieldPath.split('.$')[cnt + 1], -1] };
583
+ }
584
+ else if (field.leafValueType === 'Sum') {
585
+ proj_1.$addFields[field.id] = { '$sum': '$rb_arrays_' + cnt + '_' + field.id + field.fieldPath.split('.$')[cnt + 1] };
586
+ }
587
+ else if (field.leafValueType === 'Average') {
588
+ proj_1.$addFields[field.id] = { '$avg': '$rb_arrays_' + cnt + '_' + field.id + field.fieldPath.split('.$')[cnt + 1] };
589
+ }
590
+ else { //push
591
+ proj_1.$addFields[field.id] = '$rb_arrays_' + cnt + '_' + field.id + field.fieldPath.split('.$')[cnt + 1];
592
+ }
593
+ });
594
+ zipLayers.push(proj_1);
595
+ group = { $group: { _id: {} } };
596
+ if (selectedFields.some(function (a) { return a.fieldPath.split('.$').length > cnt + 1; })) {
597
+ groupsRow.forEach(function (row) {
598
+ group.$group._id[row.id] = '$_id.' + row.id;
599
+ });
600
+ group.$group['rb_arrays_' + (cnt - 1)] = { '$push': '$rb_arrays_' + (cnt - 1) };
601
+ selectedFields.filter(function (a) { return a.fieldPath.split('.$').length <= cnt + 2; }).forEach(function (field) {
602
+ group.$group[field.id] = { $first: '$' + field.id };
603
+ });
604
+ if (fieldsTotal.length) {
605
+ fieldsTotal.forEach(function (total) {
606
+ selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.fieldPath.split('.$').length === 1; }).forEach(function (field) {
607
+ group.$group[total.id + '_' + field.id] = { $first: '$' + total.id + '_' + field.id };
608
+ });
609
+ selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.fieldPath.split('.$').length < cnt + 2 && a.fieldPath.split('.$').length > 1; }).forEach(function (field) {
610
+ var tmpPath = field.fieldPath.split('.$.')[cnt - 1] + field.fieldPath.split('.$')[cnt];
611
+ group.$group[total.id + '_' + field.id] = { $first: '$rb_arrays_' + (cnt - 1) + '.' + tmpPath };
612
+ });
613
+ selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.fieldPath.split('.$').length === cnt + 2; }).forEach(function (field) {
614
+ var _a;
615
+ var tmpPath = field.fieldPath.split('.$.')[cnt - 1] + field.fieldPath.split('.$')[cnt];
616
+ group.$group[total.id + '_' + field.id] = (_a = {}, _a['$' + total.type] = '$' + field.id, _a);
617
+ });
618
+ });
619
+ }
620
+ zipLayers.push(group);
621
+ }
622
+ }
623
+ if (selectedFields.some(function (a) { return a.fieldPath.split('.$').length > cnt + 2; })) {
624
+ zipLayers.push({ $unwind: {
625
+ path: '$rb_arrays_' + cnt,
626
+ preserveNullAndEmptyArrays: true
627
+ } });
628
+ }
566
629
  }
567
630
  cnt++;
568
631
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "4.5.3",
3
+ "version": "4.5.5",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {
package/server-app.d.ts CHANGED
@@ -14,6 +14,7 @@ export default class ResolveIOMainServer {
14
14
  private _clientDir;
15
15
  private _msgQueue;
16
16
  private _msgQueueRunning;
17
+ private LOGGER;
17
18
  private _resolveioServer;
18
19
  private _subscriptionManager;
19
20
  private _methodManager;
package/server-app.js CHANGED
@@ -64,7 +64,10 @@ 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
+ this.LOGGER = 'ERROR'; //ERROR / DEBUG
68
+ if (this.LOGGER === 'DEBUG') {
69
+ console.log('Starting ResolveIO Server');
70
+ }
68
71
  this._resolveioServer = mainServer;
69
72
  this._serverConfig = serverConfig;
70
73
  this._clientDir = clientDir;
@@ -76,10 +79,14 @@ var ResolveIOMainServer = /** @class */ (function () {
76
79
  this._app.use(bodyParser.urlencoded({ limit: '5mb', extended: true }));
77
80
  // Set port
78
81
  this._port = process.env.PORT || serverConfig['PORT'];
79
- console.log('Setup ports');
82
+ if (this.LOGGER === 'DEBUG') {
83
+ console.log('Setup ports');
84
+ }
80
85
  // Create http server and websock server
81
86
  this.createServer();
82
- console.log('Create server');
87
+ if (this.LOGGER === 'DEBUG') {
88
+ console.log('Create server');
89
+ }
83
90
  // Set CORS
84
91
  this._app.use(function (req, res, next) {
85
92
  // Website you wish to allow to connect
@@ -96,11 +103,15 @@ var ResolveIOMainServer = /** @class */ (function () {
96
103
  // Pass to next layer of middleware
97
104
  next();
98
105
  });
99
- console.log('Setup cors');
106
+ if (this.LOGGER === 'DEBUG') {
107
+ console.log('Setup cors');
108
+ }
100
109
  // Set up http login route
101
110
  auth_1.setupAuthRoutes(this, this._app, serverConfig);
102
111
  health_1.setupHealthRoutes(this._app, serverConfig);
103
- console.log('Setup express routes');
112
+ if (this.LOGGER === 'DEBUG') {
113
+ console.log('Setup express routes');
114
+ }
104
115
  }
105
116
  ResolveIOMainServer.prototype.getWS = function (id_ws) {
106
117
  var res = null;
@@ -145,7 +156,9 @@ var ResolveIOMainServer = /** @class */ (function () {
145
156
  var infoData, token;
146
157
  var _this = this;
147
158
  return __generator(this, function (_a) {
148
- console.log('Verify Client', info, cb);
159
+ if (this.LOGGER === 'DEBUG') {
160
+ console.log('Verify Client', info, cb);
161
+ }
149
162
  infoData = info.req.headers['sec-websocket-protocol'].split(/,/);
150
163
  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']) {
151
164
  cb(false, 401, 'Unauthorized');
@@ -214,14 +227,18 @@ var ResolveIOMainServer = /** @class */ (function () {
214
227
  __setOptions.apply(this, arguments);
215
228
  return this;
216
229
  };
217
- console.log('Start Managers');
230
+ if (this.LOGGER === 'DEBUG') {
231
+ console.log('Start Managers');
232
+ }
218
233
  // Start Managers
219
234
  this._subscriptionManager = new subscription_manager_1.SubscriptionManager(this, this._wss, this._serverConfig);
220
235
  this._methodManager = new method_manager_1.MethodManager(this, this._serverConfig, this._clientDir);
221
236
  this._supportManager = new support_manager_1.SupportManager(this, this._serverConfig, this._clientDir);
222
237
  this._cronManager = new cron_manager_1.CronManager(this);
223
238
  this._queueManager = new queue_method_manager_1.QueueMethodManager(this);
224
- console.log('End Managers');
239
+ if (this.LOGGER === 'DEBUG') {
240
+ console.log('End Managers');
241
+ }
225
242
  this.listen();
226
243
  mongoose.set('useFindAndModify', false);
227
244
  // mongoose.set('useCreateIndexes', true);
@@ -248,7 +265,9 @@ var ResolveIOMainServer = /** @class */ (function () {
248
265
  ws['user_readonly'] = req.user_readonly;
249
266
  ws['id_socket'] = uuid();
250
267
  ws['retryCnt'] = 0;
251
- console.log('Connection from: ' + req.user);
268
+ if (_this.LOGGER === 'DEBUG') {
269
+ console.log('Connection from: ' + req.user);
270
+ }
252
271
  // Use for keeping connection alive (ping/pong)
253
272
  ws['isAlive'] = true;
254
273
  ws.on('pong', function () {
@@ -266,7 +285,9 @@ var ResolveIOMainServer = /** @class */ (function () {
266
285
  var _a, _b, socketData, data, messageDate, messageId, type, subType, pub;
267
286
  var _this = this;
268
287
  return __generator(this, function (_c) {
269
- console.log('Message from: ' + ws['user'], message);
288
+ if (this.LOGGER === 'DEBUG') {
289
+ console.log('Message from: ' + ws['user'], message);
290
+ }
270
291
  socketData = JSON.parse(message, common_1.dateReviver);
271
292
  data = common_2.deepCopy(socketData);
272
293
  if (data[0] === 'ping') {