@resolveio/server-lib 4.5.7 → 4.5.9

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, group, correctSort_1, _loop_2, i, queryProjection, queryTotals, query, i, res, err_1;
199
+ var _a, uniqueSelectedFieldCollections, modelCollection, queryMatchCondition, initalLookups, initialProjection, tmpIndex_1, 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:
@@ -236,11 +236,11 @@ function loadReportBuilderMethods(methodManager) {
236
236
  queryMatchCondition['$and'].push(filter);
237
237
  // queryMatchConditionLookup['$and'].push(filter);
238
238
  });
239
- queryLookups = [];
239
+ initalLookups = [];
240
240
  // Lookup Groups
241
- groupsRow.filter(function (a) { return a.treeItem.collection_name !== rootCollectionName; }).forEach(function (group) {
242
- if (!queryLookups.filter(function (a) { return a.as === group.treeItem.lookup_as.replace(/\.\$/g, ''); }).length) {
243
- queryLookups.push({
241
+ groupsRow.filter(function (a) { return a.treeItem.collection_name !== rootCollectionName && a.treeItem.fieldPath.split('.$').length === 2; }).forEach(function (group) {
242
+ if (!initalLookups.filter(function (a) { return a.as === group.treeItem.lookup_as.replace(/\.\$/g, ''); }).length) {
243
+ initalLookups.push({
244
244
  from: group.treeItem.lookup_collection,
245
245
  localField: group.treeItem.lookup_local_key,
246
246
  foreignField: group.treeItem.lookup_foreign_key,
@@ -251,8 +251,8 @@ function loadReportBuilderMethods(methodManager) {
251
251
  // Lookup Selected Fields
252
252
  uniqueSelectedFieldCollections.filter(function (a) { return a !== rootCollectionName; }).forEach(function (uniqueCollection) {
253
253
  selectedFields.filter(function (a) { return a.collection_name === uniqueCollection; }).forEach(function (field) {
254
- if (!queryLookups.filter(function (a) { return a.as === field.lookup_as.replace(/\.\$/g, ''); }).length) {
255
- queryLookups.push({
254
+ if (!initalLookups.filter(function (a) { return a.as === field.lookup_as.replace(/\.\$/g, ''); }).length && field.fieldPath.split('.$').length === 2) {
255
+ initalLookups.push({
256
256
  from: field.lookup_collection,
257
257
  localField: field.lookup_local_key,
258
258
  foreignField: field.lookup_foreign_key,
@@ -261,37 +261,12 @@ function loadReportBuilderMethods(methodManager) {
261
261
  }
262
262
  });
263
263
  });
264
- queryGroupUnwindCollectionPaths = [];
265
- groupsRow.filter(function (a) { return a.treeItem.fieldPath.includes('$'); }).forEach(function (field) {
266
- var arrayPartData = field.treeItem.fieldPath.split('.$');
267
- var path = '$';
268
- for (var i = 0; i < arrayPartData.length - 1; i++) {
269
- path += arrayPartData[i];
270
- if (!queryGroupUnwindCollectionPaths.filter(function (a) { return a === path; })[0]) {
271
- queryGroupUnwindCollectionPaths.push(path);
272
- }
273
- }
274
- });
275
- queryUnwindCollectionPaths = [];
276
- selectedFields.filter(function (a) { return a.fieldPath.includes('$'); }).forEach(function (field) {
277
- var arrayPartData = field.fieldPath.split('.$');
278
- var path = '$';
279
- for (var i = 0; i < arrayPartData.length - 1; i++) {
280
- path += arrayPartData[i];
281
- if (!queryUnwindCollectionPaths.some(function (a) { return a === path; }) && !queryGroupUnwindCollectionPaths.some(function (a) { return a === path; })) {
282
- queryUnwindCollectionPaths.push(path);
283
- }
284
- }
285
- });
286
264
  initialProjection = { _id: 1, count: { $sum: 1 } };
287
265
  // Projection
288
- groupsRow.filter(function (a) { return !a.treeItem.fieldPath.includes('$'); }).forEach(function (row) {
289
- initialProjection[row.treeItem.fieldPath] = 1;
290
- });
291
- selectedFields.filter(function (a) { return !a.fieldPath.includes('$'); }).forEach(function (field) {
292
- initialProjection[field.fieldPath] = 1;
266
+ groupsRow.forEach(function (row) {
267
+ initialProjection[row.treeItem.fieldPath.split('.$')[0]] = 1;
293
268
  });
294
- selectedFields.filter(function (a) { return a.fieldPath.includes('$'); }).forEach(function (field) {
269
+ selectedFields.forEach(function (field) {
295
270
  initialProjection[field.fieldPath.split('.$')[0]] = 1;
296
271
  });
297
272
  if (selectedFields.some(function (a) { return a.fieldPath.includes('$'); }) || groupsRow.some(function (a) { return a.field.includes('$') || a.field.includes('(Lookup)'); })) {
@@ -330,19 +305,21 @@ function loadReportBuilderMethods(methodManager) {
330
305
  }
331
306
  }
332
307
  };
333
- groupsRow.filter(function (a) { return a.field.includes('$'); }).forEach(function (field, index) {
308
+ tmpIndex_1 = 0;
309
+ groupsRow.filter(function (a) { return a.field.includes('$'); }).forEach(function (field) {
334
310
  if (!initialProjection['rb_arrays_0'].$map.input.$zip.inputs.some(function (a) { return a === '$' + field.field.split('.$')[0]; })) {
335
311
  initialProjection['rb_arrays_0'].$map.input.$zip.inputs.push('$' + field.field.split('.$')[0]);
336
- initialProjection['rb_arrays_0'].$map.in[field.field.split('.$')[0]] = {
337
- $arrayElemAt: ['$$zipped', index]
312
+ initialProjection['rb_arrays_0'].$map.in[field.field.split('.$')[0].replace(new RegExp(/\./g), '_')] = {
313
+ $arrayElemAt: ['$$zipped', tmpIndex_1++]
338
314
  };
339
315
  }
340
316
  });
341
- selectedFields.filter(function (a) { return a.fieldPath.includes('$'); }).forEach(function (field, index) {
317
+ tmpIndex_1 = 0;
318
+ selectedFields.filter(function (a) { return a.fieldPath.includes('$'); }).forEach(function (field) {
342
319
  if (!initialProjection['rb_arrays_0'].$map.input.$zip.inputs.some(function (a) { return a === '$' + field.fieldPath.split('.$')[0]; })) {
343
320
  initialProjection['rb_arrays_0'].$map.input.$zip.inputs.push('$' + field.fieldPath.split('.$')[0]);
344
- initialProjection['rb_arrays_0'].$map.in[field.fieldPath.split('.$')[0]] = {
345
- $arrayElemAt: ['$$zipped', index]
321
+ initialProjection['rb_arrays_0'].$map.in[field.fieldPath.split('.$')[0].replace(new RegExp(/\./g), '_')] = {
322
+ $arrayElemAt: ['$$zipped', tmpIndex_1++]
346
323
  };
347
324
  }
348
325
  });
@@ -478,7 +455,7 @@ function loadReportBuilderMethods(methodManager) {
478
455
  initialNonSumElemAtProj = { $addFields: {} };
479
456
  initialNonSumValueProj = { $addFields: {} };
480
457
  selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === 2; }).forEach(function (field) {
481
- initialNonSumElemAtProj.$addFields['rb_arrays_0_' + field.id] = '$rb_arrays_0_' + field.id + '.' + field.fieldPath.split('.$')[0];
458
+ initialNonSumElemAtProj.$addFields['rb_arrays_0_' + field.id] = '$rb_arrays_0_' + field.id + '.' + field.fieldPath.split('.$')[0].replace(new RegExp(/\./g), '_');
482
459
  });
483
460
  selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === 2; }).forEach(function (field) {
484
461
  if (field.leafValueType === 'Count') {
@@ -503,6 +480,35 @@ function loadReportBuilderMethods(methodManager) {
503
480
  }
504
481
  cnt = 1;
505
482
  _loop_1 = function () {
483
+ // Lookups
484
+ var queryLookups = [];
485
+ // Lookup Groups
486
+ groupsRow.filter(function (a) { return a.treeItem.collection_name !== rootCollectionName && a.treeItem.fieldPath.split('.$').length === cnt + 2; }).forEach(function (group) {
487
+ if (!queryLookups.filter(function (a) { return a.as === group.treeItem.lookup_as.replace(/\.\$/g, ''); }).length) {
488
+ queryLookups.push({
489
+ from: group.treeItem.lookup_collection,
490
+ localField: 'rb_arrays_' + (cnt - 1) + '.' + group.treeItem.lookup_local_key,
491
+ foreignField: group.treeItem.lookup_foreign_key,
492
+ as: 'rb_arrays_' + (cnt - 1) + '.' + group.treeItem.lookup_as.replace(/\.\$/g, '')
493
+ });
494
+ }
495
+ });
496
+ // Lookup Selected Fields
497
+ uniqueSelectedFieldCollections.filter(function (a) { return a !== rootCollectionName; }).forEach(function (uniqueCollection) {
498
+ selectedFields.filter(function (a) { return a.collection_name === uniqueCollection; }).forEach(function (field) {
499
+ if (!queryLookups.filter(function (a) { return a.as === field.lookup_as.replace(/\.\$/g, ''); }).length && field.fieldPath.split('.$').length === cnt + 2) {
500
+ queryLookups.push({
501
+ from: field.lookup_collection,
502
+ localField: 'rb_arrays_' + (cnt - 1) + '.' + field.lookup_local_key,
503
+ foreignField: field.lookup_foreign_key,
504
+ as: 'rb_arrays_' + (cnt - 1) + '.' + field.lookup_as.replace(/\.\$/g, '')
505
+ });
506
+ }
507
+ });
508
+ });
509
+ queryLookups.forEach(function (lookup) {
510
+ zipLayers.push({ $lookup: lookup });
511
+ });
506
512
  var proj = { $addFields: {} };
507
513
  if (selectedFields.some(function (a) { return a.fieldPath.split('.$').length === cnt + 2; })) {
508
514
  proj.$addFields['rb_arrays_' + cnt] = {
@@ -517,7 +523,8 @@ function loadReportBuilderMethods(methodManager) {
517
523
  in: {}
518
524
  }
519
525
  };
520
- selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === cnt + 2; }).forEach(function (field, index) {
526
+ var indexCnt_1 = 0;
527
+ selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === cnt + 2; }).forEach(function (field) {
521
528
  var fieldPath = field.fieldPath.split('.$')[0];
522
529
  for (var i = 1; i < cnt + 1; i++) {
523
530
  fieldPath += field.fieldPath.split('.$')[i];
@@ -525,8 +532,8 @@ function loadReportBuilderMethods(methodManager) {
525
532
  if (!proj.$addFields['rb_arrays_' + cnt].$map.input.$zip.inputs.some(function (a) { return a === '$' + fieldPath; })) {
526
533
  if (!proj.$addFields['rb_arrays_' + cnt].$map.input.$zip.inputs.some(function (a) { return a === '$rb_arrays_' + (cnt - 1) + '.' + fieldPath; })) {
527
534
  proj.$addFields['rb_arrays_' + cnt].$map.input.$zip.inputs.push('$rb_arrays_' + (cnt - 1) + '.' + fieldPath);
528
- proj.$addFields['rb_arrays_' + cnt].$map.in[field.fieldPath.split('.$.')[cnt]] = {
529
- $arrayElemAt: ['$$zipped', index]
535
+ proj.$addFields['rb_arrays_' + cnt].$map.in[field.fieldPath.split('.$.')[cnt].replace(new RegExp(/\./g), '_')] = {
536
+ $arrayElemAt: ['$$zipped', indexCnt_1++]
530
537
  };
531
538
  }
532
539
  }
@@ -582,8 +589,8 @@ function loadReportBuilderMethods(methodManager) {
582
589
  proj_1.$addFields['rb_arrays_' + cnt + '_' + field.id].$filter.cond.$and.push({ $or: tmpOr_2 });
583
590
  }
584
591
  }
585
- zipLayers.push(proj_1);
586
592
  });
593
+ zipLayers.push(proj_1);
587
594
  proj_1 = { $addFields: {} };
588
595
  selectedFields.filter(function (a) { return a.fieldPath.split('.$').length === cnt + 2; }).forEach(function (field) {
589
596
  proj_1.$addFields['rb_arrays_' + cnt + '_' + field.id] = '$rb_arrays_' + cnt + '_' + field.id + field.fieldPath.split('.$')[cnt];
@@ -850,6 +857,9 @@ function loadReportBuilderMethods(methodManager) {
850
857
  $match: queryMatchCondition
851
858
  });
852
859
  }
860
+ initalLookups.forEach(function (lookup) {
861
+ query.push({ $lookup: lookup });
862
+ });
853
863
  // Group w/ root properties & all arrays needed
854
864
  query.push({
855
865
  $project: initialProjection
@@ -879,12 +889,14 @@ function loadReportBuilderMethods(methodManager) {
879
889
  if (initialNonSumValueProj) {
880
890
  query.push(initialNonSumValueProj);
881
891
  }
882
- query.push({
883
- $unwind: {
884
- "path": "$rb_arrays_0",
885
- "preserveNullAndEmptyArrays": true
886
- }
887
- });
892
+ if (selectedFields.some(function (a) { return a.fieldPath.split('.$').length > 2; })) {
893
+ query.push({
894
+ $unwind: {
895
+ "path": "$rb_arrays_0",
896
+ "preserveNullAndEmptyArrays": true
897
+ }
898
+ });
899
+ }
888
900
  for (i = 0; i < zipLayers.length; i++) {
889
901
  query.push(zipLayers[i]);
890
902
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "4.5.7",
3
+ "version": "4.5.9",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {