@resolveio/server-lib 20.12.36 → 20.12.37

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.
@@ -48,59 +48,27 @@ function loadReportBuilderMethods(methodManager) {
48
48
  check: new simpl_schema_1.default({
49
49
  collection_root: {
50
50
  type: String
51
- },
52
- collectionJoins: {
53
- type: Array,
54
- optional: true
55
- },
56
- 'collectionJoins.$': {
57
- type: Object
58
- },
59
- 'collectionJoins.$.collection': {
60
- type: String
61
- },
62
- 'collectionJoins.$.alias': {
63
- type: String,
64
- optional: true
65
- },
66
- 'collectionJoins.$.local_key': {
67
- type: String
68
- },
69
- 'collectionJoins.$.foreign_key': {
70
- type: String
71
51
  }
72
52
  }),
73
- function: function (collection_root, collectionJoins) {
74
- if (collectionJoins === void 0) { collectionJoins = []; }
75
- var baseRootTree = buildCollectionTree(collection_root);
76
- var collectionTrees = [
77
- {
78
- collection: collection_root,
79
- alias: (0, common_1.toTitleCase)(collection_root.replace(/\_/g, ' ').replace(/-/g, ' ')),
80
- lookup_as: '',
81
- tree: (0, common_1.deepCopy)(baseRootTree)
82
- }
83
- ];
84
- var rootTree = baseRootTree;
85
- (collectionJoins || []).forEach(function (join, joinIndex) {
86
- var joinAlias = buildJoinAlias(join, joinIndex);
87
- var joinNode = buildJoinLookupNode(collection_root, join, joinAlias);
88
- var joinTree = buildCollectionTree(join.collection, joinNode);
89
- joinNode.children = joinTree.children;
90
- joinNode.is_join = true;
91
- rootTree.children.push(joinNode);
92
- collectionTrees.push({
93
- collection: join.collection,
94
- alias: joinAlias,
95
- lookup_as: joinNode.lookup_as,
96
- tree: (0, common_1.deepCopy)(joinTree)
53
+ function: function (collection_root) {
54
+ var lookupSchemaData = (0, schema_report_builder_1.getReportLookupSchemas)(collection_root).sort(function (a, b) { return a.collection_name.localeCompare(b.collection_name); });
55
+ var lookupSchemaTree = lookupSchemaData.find(function (a) { return a.is_root === true; }).tree;
56
+ var treeItems = (0, schema_report_builder_1.buildTree)(collection_root, lookupSchemaTree);
57
+ Object.keys(lookupSchemaTree).filter(function (a) { return a.endsWith('(Lookup)'); }).forEach(function (lookup) {
58
+ var fieldPath = lookup.split('.');
59
+ var field = null;
60
+ fieldPath.forEach(function (path) {
61
+ if (!field) {
62
+ field = treeItems.find(function (a) { return a.fieldName === path; });
63
+ }
64
+ else {
65
+ field = field.children.find(function (a) { return a.fieldName === path; });
66
+ }
97
67
  });
68
+ field.children = (0, schema_report_builder_1.buildTree)(lookupSchemaTree[lookup].lookup_collection, lookupSchemaData.find(function (a) { return a.collection_name === lookupSchemaTree[lookup].lookup_collection; }).tree, field);
98
69
  });
99
- return Promise.resolve({
100
- isLeaf: false,
101
- children: rootTree.children,
102
- trees: collectionTrees
103
- });
70
+ // console.log('----------- Tree Items -----------', treeItems);
71
+ return Promise.resolve({ isLeaf: false, children: treeItems });
104
72
  }
105
73
  },
106
74
  reportBuilderGetDistinctValue: {
@@ -114,8 +82,8 @@ function loadReportBuilderMethods(methodManager) {
114
82
  return __awaiter(this, void 0, void 0, function () {
115
83
  return __generator(this, function (_a) {
116
84
  if (treeLeaf.fieldType === 'String') {
117
- if (treeLeaf.fieldPath.includes('(Lookup') || treeLeaf.lookup_collection) {
118
- return [2 /*return*/, (0, schema_report_builder_1.mongoCommand)('distinct', treeLeaf.collection_name, treeLeaf.fieldPath.replace(/^.+\(.+\) \(Lookup.*\)\.\$\./g, '').replace(/\.\$/g, ''))];
85
+ if (treeLeaf.fieldPath.includes('(Lookup)')) {
86
+ return [2 /*return*/, (0, schema_report_builder_1.mongoCommand)('distinct', treeLeaf.collection_name, treeLeaf.fieldPath.replace(/^.+\(.+\) \(Lookup\)\.\$\./g, '').replace(/\.\$/g, ''))];
119
87
  }
120
88
  else {
121
89
  return [2 /*return*/, (0, schema_report_builder_1.mongoCommand)('distinct', treeLeaf.collection_name, treeLeaf.fieldPath.replace(/\.\$/g, ''))];
@@ -253,14 +221,14 @@ function loadReportBuilderMethods(methodManager) {
253
221
  // ]
254
222
  // });
255
223
  // });
256
- if (filters.filter(function (a) { return (!a['$or'] && !Object.keys(a).some(function (b) { return b.includes('(Lookup'); })) || (a['$or'] && !a['$or'].some(function (b) { return Object.keys(b).some(function (c) { return c.includes('(Lookup'); }); })); }).length) {
257
- filters.filter(function (a) { return (!a['$or'] && !Object.keys(a).some(function (b) { return b.includes('(Lookup'); })) || (a['$or'] && !a['$or'].some(function (b) { return Object.keys(b).some(function (c) { return c.includes('(Lookup'); }); })); }).forEach(function (filter) {
224
+ if (filters.filter(function (a) { return (!a['$or'] && !Object.keys(a).some(function (b) { return b.includes('(Lookup)'); })) || (a['$or'] && !a['$or'].some(function (b) { return Object.keys(b).some(function (c) { return c.includes('(Lookup)'); }); })); }).length) {
225
+ filters.filter(function (a) { return (!a['$or'] && !Object.keys(a).some(function (b) { return b.includes('(Lookup)'); })) || (a['$or'] && !a['$or'].some(function (b) { return Object.keys(b).some(function (c) { return c.includes('(Lookup)'); }); })); }).forEach(function (filter) {
258
226
  initialQueryMatchCondition_1['$and'].push(filter);
259
227
  });
260
228
  }
261
229
  // Add filter to query
262
- // if (filters.filter(a => (!a['$or'] && !Object.keys(a).some(b => b.includes('(Lookup'))) || (a['$or'] && !a['$or'].some(b => Object.keys(b).some(c => c.includes('(Lookup)'))))).length || selectedFields.filter(a => !a.fieldPath.includes('(Lookup')).length) {
263
- if (filters.filter(function (a) { return (!a['$or'] && !Object.keys(a).some(function (b) { return b.includes('(Lookup'); })) || (a['$or'] && !a['$or'].some(function (b) { return Object.keys(b).some(function (c) { return c.includes('(Lookup'); }); })); }).length) {
230
+ // if (filters.filter(a => (!a['$or'] && !Object.keys(a).some(b => b.includes('(Lookup)'))) || (a['$or'] && !a['$or'].some(b => Object.keys(b).some(c => c.includes('(Lookup)'))))).length || selectedFields.filter(a => !a.fieldPath.includes('(Lookup')).length) {
231
+ if (filters.filter(function (a) { return (!a['$or'] && !Object.keys(a).some(function (b) { return b.includes('(Lookup)'); })) || (a['$or'] && !a['$or'].some(function (b) { return Object.keys(b).some(function (c) { return c.includes('(Lookup)'); }); })); }).length) {
264
232
  query_1.push({
265
233
  $match: initialQueryMatchCondition_1
266
234
  });
@@ -274,12 +242,12 @@ function loadReportBuilderMethods(methodManager) {
274
242
  var fieldPath = '';
275
243
  for (var i = 0; i < fieldData.length - 1; i++) {
276
244
  fieldPath += fieldData[i];
277
- if (filterField.lookup_collection || fieldPath.split('.$')[fieldPath.split('.$').length - 1].includes('(Lookup')) {
245
+ if (fieldPath.split('.$')[fieldPath.split('.$').length - 1].includes('(Lookup)')) {
278
246
  if (!query_1.some(function (a) { return a.$lookup && a.$lookup.as === filterField.lookup_as.replace(/\.\$/g, ''); })) {
279
247
  query_1.push({ $lookup: {
280
248
  from: filterField.lookup_collection,
281
- localField: normalizeLookupField(filterField.lookup_local_key),
282
- foreignField: normalizeLookupField(filterField.lookup_foreign_key),
249
+ localField: filterField.lookup_local_key,
250
+ foreignField: filterField.lookup_foreign_key,
283
251
  as: filterField.lookup_as.replace(/\.\$/g, '')
284
252
  } });
285
253
  sizes_1.push(filterField.lookup_as.replace(/\.\$\./g, '_').replace(/\./g, '_'));
@@ -299,18 +267,17 @@ function loadReportBuilderMethods(methodManager) {
299
267
  // Groups - Lookups / Sizes / Unwinds
300
268
  groupsRow.forEach(function (row) {
301
269
  var _a, _b;
302
- var _c;
303
270
  if (row.field.includes('$')) {
304
271
  var fieldData = row.field.split('.$');
305
272
  var fieldPath_1 = '';
306
273
  for (var i = 0; i < fieldData.length - 1; i++) {
307
274
  fieldPath_1 += fieldData[i];
308
- if (((_c = row.treeItem) === null || _c === void 0 ? void 0 : _c.lookup_collection) || fieldPath_1.split('.$')[fieldPath_1.split('.$').length - 1].includes('(Lookup')) {
275
+ if (fieldPath_1.split('.$')[fieldPath_1.split('.$').length - 1].includes('(Lookup)')) {
309
276
  if (!query_1.some(function (a) { return a.$lookup && a.$lookup.as === row.treeItem.lookup_as.replace(/\.\$/g, ''); })) {
310
277
  query_1.push({ $lookup: {
311
278
  from: row.treeItem.lookup_collection,
312
- localField: normalizeLookupField(row.treeItem.lookup_local_key),
313
- foreignField: normalizeLookupField(row.treeItem.lookup_foreign_key),
279
+ localField: row.treeItem.lookup_local_key,
280
+ foreignField: row.treeItem.lookup_foreign_key,
314
281
  as: row.treeItem.lookup_as.replace(/\.\$/g, '')
315
282
  } });
316
283
  sizes_1.push(row.treeItem.lookup_as.replace(/\.\$\./g, '_').replace(/\./g, '_'));
@@ -337,12 +304,12 @@ function loadReportBuilderMethods(methodManager) {
337
304
  var fieldPath_2 = '';
338
305
  for (var i = 0; i < fieldData.length - 1; i++) {
339
306
  fieldPath_2 += fieldData[i];
340
- if (field.lookup_collection || fieldPath_2.split('.$')[fieldPath_2.split('.$').length - 1].includes('(Lookup')) {
307
+ if (fieldPath_2.split('.$')[fieldPath_2.split('.$').length - 1].includes('(Lookup)')) {
341
308
  if (!query_1.some(function (a) { return a.$lookup && a.$lookup.as === field.lookup_as.replace(/\.\$/g, ''); })) {
342
309
  query_1.push({ $lookup: {
343
310
  from: field.lookup_collection,
344
- localField: normalizeLookupField(field.lookup_local_key),
345
- foreignField: normalizeLookupField(field.lookup_foreign_key),
311
+ localField: field.lookup_local_key,
312
+ foreignField: field.lookup_foreign_key,
346
313
  as: field.lookup_as.replace(/\.\$/g, '')
347
314
  } });
348
315
  sizes_1.push(field.lookup_as.replace(/\.\$\./g, '_').replace(/\./g, '_'));
@@ -350,7 +317,7 @@ function loadReportBuilderMethods(methodManager) {
350
317
  query_1.push({ '$unwind': { path: '$' + field.lookup_as.replace(/\.\$/g, ''), preserveNullAndEmptyArrays: true } });
351
318
  }
352
319
  else {
353
- if (!fieldData[i].includes('(Lookup')) {
320
+ if (!fieldData[i].includes('(Lookup)')) {
354
321
  if (!query_1.some(function (a) { return a.$addFields && Object.keys(a.$addFields).includes('size_' + fieldPath_2.replace(/\./g, '_')); })) {
355
322
  sizes_1.push(fieldPath_2.replace(/\./g, '_'));
356
323
  query_1.push({ $addFields: (_b = {}, _b['size_' + fieldPath_2.replace(/\./g, '_')] = { $size: { $ifNull: ['$' + fieldPath_2, []] } }, _b) });
@@ -525,8 +492,8 @@ function loadReportBuilderMethods(methodManager) {
525
492
  queryMatchConditionLookup_1 = {
526
493
  $and: []
527
494
  };
528
- if (filters.filter(function (a) { return (!a['$or'] && Object.keys(a).some(function (b) { return b.includes('(Lookup'); })) || (a['$or'] && a['$or'].some(function (b) { return Object.keys(b).some(function (c) { return c.includes('(Lookup'); }); })); }).length) {
529
- filters.filter(function (a) { return (!a['$or'] && Object.keys(a).some(function (b) { return b.includes('(Lookup'); })) || (a['$or'] && a['$or'].some(function (b) { return Object.keys(b).some(function (c) { return c.includes('(Lookup'); }); })); }).forEach(function (filter) {
495
+ if (filters.filter(function (a) { return (!a['$or'] && Object.keys(a).some(function (b) { return b.includes('(Lookup)'); })) || (a['$or'] && a['$or'].some(function (b) { return Object.keys(b).some(function (c) { return c.includes('(Lookup)'); }); })); }).length) {
496
+ filters.filter(function (a) { return (!a['$or'] && Object.keys(a).some(function (b) { return b.includes('(Lookup)'); })) || (a['$or'] && a['$or'].some(function (b) { return Object.keys(b).some(function (c) { return c.includes('(Lookup)'); }); })); }).forEach(function (filter) {
530
497
  queryMatchConditionLookup_1['$and'].push(filter);
531
498
  });
532
499
  }
@@ -869,84 +836,5 @@ function loadReportBuilderMethods(methodManager) {
869
836
  }
870
837
  });
871
838
  }
872
- function buildCollectionTree(collectionName, lookupNode) {
873
- var _a;
874
- var lookupSchemaData = (0, schema_report_builder_1.getReportLookupSchemas)(collectionName).sort(function (a, b) { return a.collection_name.localeCompare(b.collection_name); });
875
- var lookupSchemaTree = ((_a = lookupSchemaData.find(function (a) { return a.is_root === true; })) === null || _a === void 0 ? void 0 : _a.tree) || {};
876
- var treeItems = (0, schema_report_builder_1.buildTree)(collectionName, lookupSchemaTree, lookupNode);
877
- attachLookupChildren(treeItems, lookupSchemaData, lookupSchemaTree);
878
- return { isLeaf: false, children: treeItems };
879
- }
880
- function attachLookupChildren(treeItems, lookupSchemaData, lookupSchemaTree) {
881
- Object.keys(lookupSchemaTree || {}).filter(function (a) { return a.endsWith('(Lookup)'); }).forEach(function (lookup) {
882
- var field = findFieldByPath(treeItems, lookup);
883
- if (field) {
884
- var lookupTree = lookupSchemaData.find(function (a) { return a.collection_name === lookupSchemaTree[lookup].lookup_collection; });
885
- if (lookupTree) {
886
- var childTree = (0, schema_report_builder_1.buildTree)(lookupSchemaTree[lookup].lookup_collection, lookupTree.tree, field);
887
- attachLookupChildren(childTree, lookupSchemaData, lookupTree.tree);
888
- field.children = childTree;
889
- }
890
- }
891
- });
892
- }
893
- function findFieldByPath(treeItems, lookupPath) {
894
- var fieldPath = lookupPath.split('.');
895
- var field = null;
896
- fieldPath.forEach(function (path) {
897
- if (!field) {
898
- field = treeItems.find(function (a) { return a.fieldName === path; });
899
- }
900
- else if (field.children) {
901
- field = field.children.find(function (a) { return a.fieldName === path; });
902
- }
903
- });
904
- return field;
905
- }
906
- function buildJoinLookupNode(collection_root, join, alias) {
907
- return {
908
- collection_name: collection_root,
909
- columnName: alias,
910
- fieldName: alias,
911
- fieldType: 'Lookup',
912
- fieldTypeName: 'Lookup',
913
- distinctFieldValues: [],
914
- fieldPath: alias,
915
- fieldPathName: alias,
916
- path: alias,
917
- lookup_collection: join.collection,
918
- lookup_local_key: join.local_key,
919
- lookup_foreign_key: join.foreign_key,
920
- lookup_as: alias,
921
- text: alias,
922
- value: alias,
923
- isLeaf: false,
924
- isActive: false,
925
- isSelected: false,
926
- is_join: false,
927
- depth: 0,
928
- leafValueType: '',
929
- leafFormatType: '',
930
- children: []
931
- };
932
- }
933
- function buildJoinAlias(join, joinIndex) {
934
- if (join.alias && join.alias.trim()) {
935
- return join.alias.trim();
936
- }
937
- var joinName = (0, common_1.toTitleCase)(join.collection.replace(/\_/g, ' ').replace(/-/g, ' '));
938
- var joinPath = (0, common_1.toTitleCase)(join.local_key.replace(/\.\$\./g, ' -> ').replace(/\./g, ' -> ').replace(/\_/g, ' '));
939
- return "".concat(joinName, " (").concat(joinPath || 'Join', ") (Lookup ").concat(joinIndex + 1, ")");
940
- }
941
- function normalizeLookupField(path) {
942
- if (!path) {
943
- return path;
944
- }
945
- // Strip any lookup alias prefixes and ".$" tokens
946
- var cleaned = path.replace(/\.\$/g, '');
947
- // Remove leading alias like "Alias (Lookup 1)." or "Alias (Lookup 1).$."
948
- cleaned = cleaned.replace(/^[^\.]*\(.*?Lookup.*?\)\.?/, '');
949
- return cleaned;
950
- }
951
839
 
952
840
  //# sourceMappingURL=report-builder.js.map