@resolveio/server-lib 20.14.31 → 20.14.33

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.
@@ -944,17 +944,22 @@ function executeAiAssistantMongoRead(payload, context) {
944
944
  sanitizedDocuments = isSuperAdmin
945
945
  ? documents
946
946
  : documents.map(function (doc) { return redactSensitiveFields((0, common_1.deepCopy)(doc)); });
947
- return [2 /*return*/, {
948
- documents: sanitizedDocuments,
949
- total: total
950
- }];
947
+ return [2 /*return*/, __assign({ documents: sanitizedDocuments, total: total }, (isSuperAdmin ? {
948
+ debug: {
949
+ collection: collection,
950
+ database: dbName,
951
+ query: scopedQuery,
952
+ options: normalized.findOptions,
953
+ includeTotal: normalized.includeTotal
954
+ }
955
+ } : {}))];
951
956
  }
952
957
  });
953
958
  });
954
959
  }
955
960
  function executeAiAssistantMongoAggregate(payload, context) {
956
961
  return __awaiter(this, void 0, void 0, function () {
957
- var input, collection, _a, user, isSuperAdmin, customerId, dbName, db, baseQuery, userId, normalizedClient, shouldScopeByClient, _b, clientScopedQuery, scopedQuery, normalizedPipeline, pipelineWithScope, normalizedOptions, limitedPipeline, documents, fallback, fallbackPipeline, fallbackDocs, unwindFallback, fallbackPipeline, fallbackDocs, sanitizedDocuments;
962
+ var input, collection, _a, user, isSuperAdmin, customerId, dbName, db, baseQuery, userId, normalizedClient, shouldScopeByClient, _b, clientScopedQuery, scopedQuery, normalizedPipeline, pipelineWithScope, normalizedOptions, limitedPipeline, documents, executedPipeline, fallbackMeta, fallback, fallbackPipeline, fallbackDocs, unwindFallback, fallbackPipeline, fallbackDocs, sanitizedDocuments;
958
963
  var _c;
959
964
  return __generator(this, function (_d) {
960
965
  switch (_d.label) {
@@ -1010,9 +1015,12 @@ function executeAiAssistantMongoAggregate(payload, context) {
1010
1015
  .toArray()];
1011
1016
  case 5:
1012
1017
  documents = _d.sent();
1018
+ executedPipeline = limitedPipeline;
1019
+ fallbackMeta = {};
1013
1020
  if (!!documents.length) return [3 /*break*/, 7];
1014
1021
  fallback = resolveAggregateDateFieldFallback(limitedPipeline);
1015
1022
  if (!fallback) return [3 /*break*/, 7];
1023
+ fallbackMeta.dateField = __assign(__assign({}, fallback), { attempted: true, used: false });
1016
1024
  fallbackPipeline = replaceAggregateDateField(limitedPipeline, fallback.from, fallback.to);
1017
1025
  if (!!containsForbiddenMongoOperators(fallbackPipeline)) return [3 /*break*/, 7];
1018
1026
  return [4 /*yield*/, db.collection(collection)
@@ -1022,13 +1030,16 @@ function executeAiAssistantMongoAggregate(payload, context) {
1022
1030
  fallbackDocs = _d.sent();
1023
1031
  if (fallbackDocs.length) {
1024
1032
  documents = fallbackDocs;
1033
+ executedPipeline = fallbackPipeline;
1034
+ fallbackMeta.dateField.used = true;
1025
1035
  }
1026
1036
  _d.label = 7;
1027
1037
  case 7:
1028
1038
  if (!(documents.length <= 1)) return [3 /*break*/, 9];
1029
- unwindFallback = resolveAggregateUnwindFallback(limitedPipeline);
1039
+ unwindFallback = resolveAggregateUnwindFallback(executedPipeline);
1030
1040
  if (!unwindFallback) return [3 /*break*/, 9];
1031
- fallbackPipeline = buildAggregateUnwindFallbackPipeline(limitedPipeline, unwindFallback);
1041
+ fallbackMeta.unwind = { path: unwindFallback.path, attempted: true, used: false };
1042
+ fallbackPipeline = buildAggregateUnwindFallbackPipeline(executedPipeline, unwindFallback);
1032
1043
  if (!!containsForbiddenMongoOperators(fallbackPipeline)) return [3 /*break*/, 9];
1033
1044
  return [4 /*yield*/, db.collection(collection)
1034
1045
  .aggregate(fallbackPipeline, normalizedOptions.aggregateOptions)
@@ -1037,15 +1048,25 @@ function executeAiAssistantMongoAggregate(payload, context) {
1037
1048
  fallbackDocs = _d.sent();
1038
1049
  if (fallbackDocs.length > documents.length) {
1039
1050
  documents = fallbackDocs;
1051
+ executedPipeline = fallbackPipeline;
1052
+ fallbackMeta.unwind.used = true;
1040
1053
  }
1041
1054
  _d.label = 9;
1042
1055
  case 9:
1043
1056
  sanitizedDocuments = isSuperAdmin
1044
1057
  ? documents
1045
1058
  : documents.map(function (doc) { return redactSensitiveFields((0, common_1.deepCopy)(doc)); });
1046
- return [2 /*return*/, {
1047
- documents: sanitizedDocuments
1048
- }];
1059
+ return [2 /*return*/, __assign({ documents: sanitizedDocuments }, (isSuperAdmin ? {
1060
+ debug: {
1061
+ collection: collection,
1062
+ database: dbName,
1063
+ query: scopedQuery,
1064
+ options: normalizedOptions.aggregateOptions,
1065
+ originalPipeline: limitedPipeline,
1066
+ executedPipeline: executedPipeline,
1067
+ fallbacks: fallbackMeta
1068
+ }
1069
+ } : {}))];
1049
1070
  }
1050
1071
  });
1051
1072
  });