@resolveio/server-lib 22.0.5 → 22.0.6
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/ai-terminal.d.ts +1 -0
- package/methods/ai-terminal.js +564 -344
- package/methods/ai-terminal.js.map +1 -1
- package/package.json +1 -1
package/methods/ai-terminal.js
CHANGED
|
@@ -114,6 +114,7 @@ exports.serializeMongoValue = serializeMongoValue;
|
|
|
114
114
|
exports.flattenForTable = flattenForTable;
|
|
115
115
|
exports.buildDisplayTable = buildDisplayTable;
|
|
116
116
|
exports.formatDisplayTableMarkdown = formatDisplayTableMarkdown;
|
|
117
|
+
exports.rewriteMatchExpressionsToExpr = rewriteMatchExpressionsToExpr;
|
|
117
118
|
exports.stripQueryFieldPathsDeep = stripQueryFieldPathsDeep;
|
|
118
119
|
exports.stripScopedFieldsFromPipeline = stripScopedFieldsFromPipeline;
|
|
119
120
|
exports.rewriteEmbeddedMatchObjects = rewriteEmbeddedMatchObjects;
|
|
@@ -2074,10 +2075,10 @@ function executeAiAssistantMongoRead(payload, context) {
|
|
|
2074
2075
|
}
|
|
2075
2076
|
function executeAiAssistantMongoAggregate(payload, context) {
|
|
2076
2077
|
return __awaiter(this, void 0, void 0, function () {
|
|
2077
|
-
var input, rawCollection, dbName, db, collectionResolution, collection, schemaFields, _a, user, isSuperAdmin, customerId, fallbackMeta, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, clientScopedQuery, scopedQuery, normalizedPipeline, sanitizedPipeline, strippedPipeline, pipelineWithScope, normalizedOptions, limitedPipeline, dateField, aggregateOptions, documents, executedPipeline, probeDocs, fallback, fallbackPipeline, fallbackDocs, createdFallback, createdPipeline, createdDocs, expanded, expandedDocs, completionFallback, fallbackPipeline, fallbackDocs, completionExprFallback, fallbackPipeline, fallbackDocs, unwindFallback, fallbackPipeline, fallbackDocs, nameFallback, fallbackPipeline, fallbackDocs,
|
|
2078
|
-
var
|
|
2079
|
-
return __generator(this, function (
|
|
2080
|
-
switch (
|
|
2078
|
+
var input, rawCollection, dbName, db, collectionResolution, collection, schemaFields, _a, user, isSuperAdmin, customerId, fallbackMeta, baseQuery, stripped, userId, normalizedClient, shouldScopeByClient, _b, clientScopedQuery, scopedQuery, normalizedPipeline, sanitizedPipeline, strippedPipeline, pipelineWithScope, normalizedOptions, limitedPipeline, dateField, aggregateOptions, documents, executedPipeline, probeDocs, fallback, fallbackPipeline, fallbackDocs, createdFallback, createdPipeline, createdDocs, expanded, expandedDocs, completionFallback, fallbackPipeline, fallbackDocs, completionExprFallback, fallbackPipeline, fallbackDocs, unwindFallback, shouldUnwind, _c, _d, fallbackPipeline, fallbackDocs, nameFallback, fallbackPipeline, fallbackDocs, _e, _loop_1, i, state_1, matchFields_1, _f, aliases, rewrittenPipeline, fallbackDocs, _loop_2, i, state_2, baseCollection, fallbackPayload, fallbackResult, existingFallbacks, matchStages, diagnostics, combinedMatch, nameFields, dateFields, queryNoName, _g, queryNoDate, _h, _j, _k, _l, allCollections, base, alt, altCount, _m, sanitizedDocuments, includeIds, displayDocs, idLookupDisplay, display;
|
|
2079
|
+
var _o, _p;
|
|
2080
|
+
return __generator(this, function (_q) {
|
|
2081
|
+
switch (_q.label) {
|
|
2081
2082
|
case 0:
|
|
2082
2083
|
input = payload || {};
|
|
2083
2084
|
rawCollection = normalizeOptionalString(input.collection);
|
|
@@ -2088,16 +2089,16 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
2088
2089
|
db = resolveio_server_app_1.ResolveIOServer.getMongoConnection().db(dbName);
|
|
2089
2090
|
return [4 /*yield*/, resolveAssistantCollectionName(db, dbName, rawCollection)];
|
|
2090
2091
|
case 1:
|
|
2091
|
-
collectionResolution =
|
|
2092
|
+
collectionResolution = _q.sent();
|
|
2092
2093
|
collection = collectionResolution.name || rawCollection;
|
|
2093
2094
|
schemaFields = getCollectionSchemaFieldNames(collection);
|
|
2094
2095
|
return [4 /*yield*/, ensureAssistantReadAccess(context, input.permissionView, collection)];
|
|
2095
2096
|
case 2:
|
|
2096
|
-
_a =
|
|
2097
|
+
_a = _q.sent(), user = _a.user, isSuperAdmin = _a.isSuperAdmin;
|
|
2097
2098
|
if (!isSuperAdmin && AI_ASSISTANT_BLOCKED_COLLECTIONS.has(collection)) {
|
|
2098
2099
|
throw new Error('AI assistant mongo aggregate: Access denied.');
|
|
2099
2100
|
}
|
|
2100
|
-
customerId = normalizeOptionalString((
|
|
2101
|
+
customerId = normalizeOptionalString((_o = user === null || user === void 0 ? void 0 : user.other) === null || _o === void 0 ? void 0 : _o.id_customer);
|
|
2101
2102
|
fallbackMeta = {};
|
|
2102
2103
|
baseQuery = normalizeMongoQuery(input.query);
|
|
2103
2104
|
if (!isSuperAdmin && customerId) {
|
|
@@ -2122,18 +2123,18 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
2122
2123
|
if (!(!isSuperAdmin && normalizedClient)) return [3 /*break*/, 4];
|
|
2123
2124
|
return [4 /*yield*/, collectionHasClientIndex(db, dbName, collection)];
|
|
2124
2125
|
case 3:
|
|
2125
|
-
_b =
|
|
2126
|
+
_b = _q.sent();
|
|
2126
2127
|
return [3 /*break*/, 5];
|
|
2127
2128
|
case 4:
|
|
2128
2129
|
_b = false;
|
|
2129
|
-
|
|
2130
|
+
_q.label = 5;
|
|
2130
2131
|
case 5:
|
|
2131
2132
|
shouldScopeByClient = _b;
|
|
2132
2133
|
clientScopedQuery = shouldScopeByClient
|
|
2133
2134
|
? applyClientScopeFilter(baseQuery, normalizedClient, isSuperAdmin)
|
|
2134
2135
|
: baseQuery;
|
|
2135
2136
|
scopedQuery = applyCustomerScopeFilter(clientScopedQuery, collection, customerId, isSuperAdmin);
|
|
2136
|
-
normalizedPipeline = normalizeAssistantAggregatePipeline(input.pipeline);
|
|
2137
|
+
normalizedPipeline = normalizeAssistantAggregatePipeline(input.pipeline, collection);
|
|
2137
2138
|
sanitizedPipeline = normalizedPipeline;
|
|
2138
2139
|
if (!isSuperAdmin && customerId) {
|
|
2139
2140
|
strippedPipeline = stripScopedFieldsFromPipelineWithMeta(normalizedPipeline, ['id_customer', 'other.id_customer']);
|
|
@@ -2156,7 +2157,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
2156
2157
|
.aggregate(limitedPipeline, aggregateOptions)
|
|
2157
2158
|
.toArray()];
|
|
2158
2159
|
case 6:
|
|
2159
|
-
documents =
|
|
2160
|
+
documents = _q.sent();
|
|
2160
2161
|
executedPipeline = limitedPipeline;
|
|
2161
2162
|
probeDocs = null;
|
|
2162
2163
|
if (!(!documents.length && dateField)) return [3 /*break*/, 10];
|
|
@@ -2169,13 +2170,13 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
2169
2170
|
.aggregate(fallbackPipeline, aggregateOptions)
|
|
2170
2171
|
.toArray()];
|
|
2171
2172
|
case 7:
|
|
2172
|
-
fallbackDocs =
|
|
2173
|
+
fallbackDocs = _q.sent();
|
|
2173
2174
|
if (fallbackDocs.length) {
|
|
2174
2175
|
documents = fallbackDocs;
|
|
2175
2176
|
executedPipeline = fallbackPipeline;
|
|
2176
2177
|
fallbackMeta.dateField.used = true;
|
|
2177
2178
|
}
|
|
2178
|
-
|
|
2179
|
+
_q.label = 8;
|
|
2179
2180
|
case 8:
|
|
2180
2181
|
if (!(!documents.length && dateField !== 'createdAt')) return [3 /*break*/, 10];
|
|
2181
2182
|
createdFallback = { from: dateField, to: 'createdAt', attempted: true, used: false };
|
|
@@ -2186,13 +2187,13 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
2186
2187
|
.aggregate(createdPipeline, aggregateOptions)
|
|
2187
2188
|
.toArray()];
|
|
2188
2189
|
case 9:
|
|
2189
|
-
createdDocs =
|
|
2190
|
+
createdDocs = _q.sent();
|
|
2190
2191
|
if (createdDocs.length) {
|
|
2191
2192
|
documents = createdDocs;
|
|
2192
2193
|
executedPipeline = createdPipeline;
|
|
2193
2194
|
fallbackMeta.dateFieldCreatedAt.used = true;
|
|
2194
2195
|
}
|
|
2195
|
-
|
|
2196
|
+
_q.label = 10;
|
|
2196
2197
|
case 10:
|
|
2197
2198
|
if (!!documents.length) return [3 /*break*/, 12];
|
|
2198
2199
|
expanded = expandAggregateDateMatchFallback(executedPipeline);
|
|
@@ -2207,13 +2208,13 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
2207
2208
|
.aggregate(expanded.pipeline, aggregateOptions)
|
|
2208
2209
|
.toArray()];
|
|
2209
2210
|
case 11:
|
|
2210
|
-
expandedDocs =
|
|
2211
|
+
expandedDocs = _q.sent();
|
|
2211
2212
|
if (expandedDocs.length) {
|
|
2212
2213
|
documents = expandedDocs;
|
|
2213
2214
|
executedPipeline = expanded.pipeline;
|
|
2214
2215
|
fallbackMeta.dateFieldsExpanded.used = true;
|
|
2215
2216
|
}
|
|
2216
|
-
|
|
2217
|
+
_q.label = 12;
|
|
2217
2218
|
case 12:
|
|
2218
2219
|
if (!!documents.length) return [3 /*break*/, 16];
|
|
2219
2220
|
completionFallback = resolveAggregateCompletionFallback(executedPipeline);
|
|
@@ -2232,13 +2233,13 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
2232
2233
|
.aggregate(fallbackPipeline, aggregateOptions)
|
|
2233
2234
|
.toArray()];
|
|
2234
2235
|
case 13:
|
|
2235
|
-
fallbackDocs =
|
|
2236
|
+
fallbackDocs = _q.sent();
|
|
2236
2237
|
if (fallbackDocs.length) {
|
|
2237
2238
|
documents = fallbackDocs;
|
|
2238
2239
|
executedPipeline = fallbackPipeline;
|
|
2239
2240
|
fallbackMeta.completion.used = true;
|
|
2240
2241
|
}
|
|
2241
|
-
|
|
2242
|
+
_q.label = 14;
|
|
2242
2243
|
case 14:
|
|
2243
2244
|
if (!!documents.length) return [3 /*break*/, 16];
|
|
2244
2245
|
completionExprFallback = resolveAggregateCompletionExprFallback(executedPipeline);
|
|
@@ -2257,35 +2258,66 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
2257
2258
|
.aggregate(fallbackPipeline, aggregateOptions)
|
|
2258
2259
|
.toArray()];
|
|
2259
2260
|
case 15:
|
|
2260
|
-
fallbackDocs =
|
|
2261
|
+
fallbackDocs = _q.sent();
|
|
2261
2262
|
if (fallbackDocs.length) {
|
|
2262
2263
|
documents = fallbackDocs;
|
|
2263
2264
|
executedPipeline = fallbackPipeline;
|
|
2264
2265
|
fallbackMeta.completion.used = true;
|
|
2265
2266
|
}
|
|
2266
|
-
|
|
2267
|
+
_q.label = 16;
|
|
2267
2268
|
case 16:
|
|
2268
|
-
if (!(documents.length <= 1)) return [3 /*break*/,
|
|
2269
|
+
if (!(documents.length <= 1)) return [3 /*break*/, 25];
|
|
2269
2270
|
unwindFallback = resolveAggregateUnwindFallback(executedPipeline);
|
|
2270
|
-
if (!unwindFallback) return [3 /*break*/,
|
|
2271
|
+
if (!unwindFallback) return [3 /*break*/, 25];
|
|
2271
2272
|
fallbackMeta.unwind = { path: unwindFallback.path, attempted: true, used: false };
|
|
2273
|
+
shouldUnwind = false;
|
|
2274
|
+
_q.label = 17;
|
|
2275
|
+
case 17:
|
|
2276
|
+
_q.trys.push([17, 20, , 21]);
|
|
2277
|
+
_c = probeDocs;
|
|
2278
|
+
if (_c) return [3 /*break*/, 19];
|
|
2279
|
+
return [4 /*yield*/, fetchAssistantProbeDocs({
|
|
2280
|
+
db: db,
|
|
2281
|
+
collection: collection,
|
|
2282
|
+
idClient: normalizedClient,
|
|
2283
|
+
idCustomer: customerId,
|
|
2284
|
+
isSuperAdmin: isSuperAdmin,
|
|
2285
|
+
includeClientScope: shouldScopeByClient
|
|
2286
|
+
})];
|
|
2287
|
+
case 18:
|
|
2288
|
+
_c = (_q.sent());
|
|
2289
|
+
_q.label = 19;
|
|
2290
|
+
case 19:
|
|
2291
|
+
probeDocs = _c;
|
|
2292
|
+
shouldUnwind = probeDocs.length ? hasArrayValueAtPath(probeDocs, unwindFallback.path) : false;
|
|
2293
|
+
return [3 /*break*/, 21];
|
|
2294
|
+
case 20:
|
|
2295
|
+
_d = _q.sent();
|
|
2296
|
+
shouldUnwind = false;
|
|
2297
|
+
return [3 /*break*/, 21];
|
|
2298
|
+
case 21:
|
|
2299
|
+
if (!shouldUnwind) return [3 /*break*/, 24];
|
|
2272
2300
|
fallbackPipeline = buildAggregateUnwindFallbackPipeline(executedPipeline, unwindFallback);
|
|
2273
|
-
if (!!containsForbiddenMongoOperators(fallbackPipeline)) return [3 /*break*/,
|
|
2301
|
+
if (!!containsForbiddenMongoOperators(fallbackPipeline)) return [3 /*break*/, 23];
|
|
2274
2302
|
return [4 /*yield*/, db.collection(collection)
|
|
2275
2303
|
.aggregate(fallbackPipeline, aggregateOptions)
|
|
2276
2304
|
.toArray()];
|
|
2277
|
-
case
|
|
2278
|
-
fallbackDocs =
|
|
2305
|
+
case 22:
|
|
2306
|
+
fallbackDocs = _q.sent();
|
|
2279
2307
|
if (fallbackDocs.length > documents.length) {
|
|
2280
2308
|
documents = fallbackDocs;
|
|
2281
2309
|
executedPipeline = fallbackPipeline;
|
|
2282
2310
|
fallbackMeta.unwind.used = true;
|
|
2283
2311
|
}
|
|
2284
|
-
|
|
2285
|
-
case
|
|
2286
|
-
|
|
2312
|
+
_q.label = 23;
|
|
2313
|
+
case 23: return [3 /*break*/, 25];
|
|
2314
|
+
case 24:
|
|
2315
|
+
fallbackMeta.unwind.skipped = 'not_array';
|
|
2316
|
+
_q.label = 25;
|
|
2317
|
+
case 25:
|
|
2318
|
+
if (!!documents.length) return [3 /*break*/, 27];
|
|
2287
2319
|
nameFallback = resolveAggregateNameMatchFallback(executedPipeline);
|
|
2288
|
-
if (!nameFallback) return [3 /*break*/,
|
|
2320
|
+
if (!nameFallback) return [3 /*break*/, 27];
|
|
2289
2321
|
fallbackMeta.nameMatch = {
|
|
2290
2322
|
field: nameFallback.field,
|
|
2291
2323
|
fields: nameFallback.fields,
|
|
@@ -2293,22 +2325,22 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
2293
2325
|
used: false
|
|
2294
2326
|
};
|
|
2295
2327
|
fallbackPipeline = buildAggregateNameMatchFallbackPipeline(executedPipeline, nameFallback);
|
|
2296
|
-
if (!(fallbackPipeline.length && !containsForbiddenMongoOperators(fallbackPipeline))) return [3 /*break*/,
|
|
2328
|
+
if (!(fallbackPipeline.length && !containsForbiddenMongoOperators(fallbackPipeline))) return [3 /*break*/, 27];
|
|
2297
2329
|
return [4 /*yield*/, db.collection(collection)
|
|
2298
2330
|
.aggregate(fallbackPipeline, aggregateOptions)
|
|
2299
2331
|
.toArray()];
|
|
2300
|
-
case
|
|
2301
|
-
fallbackDocs =
|
|
2332
|
+
case 26:
|
|
2333
|
+
fallbackDocs = _q.sent();
|
|
2302
2334
|
if (fallbackDocs.length) {
|
|
2303
2335
|
documents = fallbackDocs;
|
|
2304
2336
|
executedPipeline = fallbackPipeline;
|
|
2305
2337
|
fallbackMeta.nameMatch.used = true;
|
|
2306
2338
|
}
|
|
2307
|
-
|
|
2308
|
-
case
|
|
2309
|
-
if (!!documents.length) return [3 /*break*/,
|
|
2310
|
-
|
|
2311
|
-
if (
|
|
2339
|
+
_q.label = 27;
|
|
2340
|
+
case 27:
|
|
2341
|
+
if (!!documents.length) return [3 /*break*/, 33];
|
|
2342
|
+
_e = probeDocs;
|
|
2343
|
+
if (_e) return [3 /*break*/, 29];
|
|
2312
2344
|
return [4 /*yield*/, fetchAssistantProbeDocs({
|
|
2313
2345
|
db: db,
|
|
2314
2346
|
collection: collection,
|
|
@@ -2317,15 +2349,15 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
2317
2349
|
isSuperAdmin: isSuperAdmin,
|
|
2318
2350
|
includeClientScope: shouldScopeByClient
|
|
2319
2351
|
})];
|
|
2320
|
-
case
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
case
|
|
2324
|
-
probeDocs =
|
|
2352
|
+
case 28:
|
|
2353
|
+
_e = (_q.sent());
|
|
2354
|
+
_q.label = 29;
|
|
2355
|
+
case 29:
|
|
2356
|
+
probeDocs = _e;
|
|
2325
2357
|
_loop_1 = function (i) {
|
|
2326
2358
|
var stage, chemicalLookup, rewrittenPipeline, fallbackDocs;
|
|
2327
|
-
return __generator(this, function (
|
|
2328
|
-
switch (
|
|
2359
|
+
return __generator(this, function (_r) {
|
|
2360
|
+
switch (_r.label) {
|
|
2329
2361
|
case 0:
|
|
2330
2362
|
stage = executedPipeline[i];
|
|
2331
2363
|
if (!stage || typeof stage !== 'object' || !stage.$match || typeof stage.$match !== 'object') {
|
|
@@ -2341,7 +2373,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
2341
2373
|
probeDocs: probeDocs || undefined
|
|
2342
2374
|
})];
|
|
2343
2375
|
case 1:
|
|
2344
|
-
chemicalLookup =
|
|
2376
|
+
chemicalLookup = _r.sent();
|
|
2345
2377
|
if (!chemicalLookup) {
|
|
2346
2378
|
return [2 /*return*/, "continue"];
|
|
2347
2379
|
}
|
|
@@ -2352,33 +2384,33 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
2352
2384
|
.aggregate(rewrittenPipeline, aggregateOptions)
|
|
2353
2385
|
.toArray()];
|
|
2354
2386
|
case 2:
|
|
2355
|
-
fallbackDocs =
|
|
2387
|
+
fallbackDocs = _r.sent();
|
|
2356
2388
|
if (fallbackDocs.length) {
|
|
2357
2389
|
documents = fallbackDocs;
|
|
2358
2390
|
executedPipeline = rewrittenPipeline;
|
|
2359
2391
|
fallbackMeta.chemicalLookup.used = true;
|
|
2360
2392
|
return [2 /*return*/, "break"];
|
|
2361
2393
|
}
|
|
2362
|
-
|
|
2394
|
+
_r.label = 3;
|
|
2363
2395
|
case 3: return [2 /*return*/];
|
|
2364
2396
|
}
|
|
2365
2397
|
});
|
|
2366
2398
|
};
|
|
2367
2399
|
i = 0;
|
|
2368
|
-
|
|
2369
|
-
case
|
|
2370
|
-
if (!(i < (executedPipeline || []).length)) return [3 /*break*/,
|
|
2400
|
+
_q.label = 30;
|
|
2401
|
+
case 30:
|
|
2402
|
+
if (!(i < (executedPipeline || []).length)) return [3 /*break*/, 33];
|
|
2371
2403
|
return [5 /*yield**/, _loop_1(i)];
|
|
2372
|
-
case
|
|
2373
|
-
state_1 =
|
|
2404
|
+
case 31:
|
|
2405
|
+
state_1 = _q.sent();
|
|
2374
2406
|
if (state_1 === "break")
|
|
2375
|
-
return [3 /*break*/,
|
|
2376
|
-
|
|
2377
|
-
case
|
|
2407
|
+
return [3 /*break*/, 33];
|
|
2408
|
+
_q.label = 32;
|
|
2409
|
+
case 32:
|
|
2378
2410
|
i += 1;
|
|
2379
|
-
return [3 /*break*/,
|
|
2380
|
-
case
|
|
2381
|
-
if (!!documents.length) return [3 /*break*/,
|
|
2411
|
+
return [3 /*break*/, 30];
|
|
2412
|
+
case 33:
|
|
2413
|
+
if (!!documents.length) return [3 /*break*/, 37];
|
|
2382
2414
|
matchFields_1 = new Set();
|
|
2383
2415
|
(executedPipeline || []).forEach(function (stage) {
|
|
2384
2416
|
if (stage && typeof stage === 'object' && stage.$match && typeof stage.$match === 'object') {
|
|
@@ -2387,9 +2419,9 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
2387
2419
|
.forEach(function (field) { return matchFields_1.add(field); });
|
|
2388
2420
|
}
|
|
2389
2421
|
});
|
|
2390
|
-
if (!matchFields_1.size) return [3 /*break*/,
|
|
2391
|
-
|
|
2392
|
-
if (
|
|
2422
|
+
if (!matchFields_1.size) return [3 /*break*/, 37];
|
|
2423
|
+
_f = probeDocs;
|
|
2424
|
+
if (_f) return [3 /*break*/, 35];
|
|
2393
2425
|
return [4 /*yield*/, fetchAssistantProbeDocs({
|
|
2394
2426
|
db: db,
|
|
2395
2427
|
collection: collection,
|
|
@@ -2398,14 +2430,14 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
2398
2430
|
isSuperAdmin: isSuperAdmin,
|
|
2399
2431
|
includeClientScope: shouldScopeByClient
|
|
2400
2432
|
})];
|
|
2401
|
-
case
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
case
|
|
2405
|
-
probeDocs =
|
|
2406
|
-
if (!probeDocs.length) return [3 /*break*/,
|
|
2433
|
+
case 34:
|
|
2434
|
+
_f = (_q.sent());
|
|
2435
|
+
_q.label = 35;
|
|
2436
|
+
case 35:
|
|
2437
|
+
probeDocs = _f;
|
|
2438
|
+
if (!probeDocs.length) return [3 /*break*/, 37];
|
|
2407
2439
|
aliases = resolveFieldAliases(probeDocs, Array.from(matchFields_1), schemaFields);
|
|
2408
|
-
if (!Object.keys(aliases).length) return [3 /*break*/,
|
|
2440
|
+
if (!Object.keys(aliases).length) return [3 /*break*/, 37];
|
|
2409
2441
|
fallbackMeta.queryFieldAliases = {
|
|
2410
2442
|
aliases: aliases,
|
|
2411
2443
|
attempted: true,
|
|
@@ -2416,31 +2448,31 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
2416
2448
|
var _b = __read(_a, 2), from = _b[0], to = _b[1];
|
|
2417
2449
|
return replaceFieldPathDeep(acc, from, to);
|
|
2418
2450
|
}, executedPipeline);
|
|
2419
|
-
if (!!containsForbiddenMongoOperators(rewrittenPipeline)) return [3 /*break*/,
|
|
2451
|
+
if (!!containsForbiddenMongoOperators(rewrittenPipeline)) return [3 /*break*/, 37];
|
|
2420
2452
|
return [4 /*yield*/, db.collection(collection)
|
|
2421
2453
|
.aggregate(rewrittenPipeline, aggregateOptions)
|
|
2422
2454
|
.toArray()];
|
|
2423
|
-
case
|
|
2424
|
-
fallbackDocs =
|
|
2455
|
+
case 36:
|
|
2456
|
+
fallbackDocs = _q.sent();
|
|
2425
2457
|
if (fallbackDocs.length) {
|
|
2426
2458
|
documents = fallbackDocs;
|
|
2427
2459
|
executedPipeline = rewrittenPipeline;
|
|
2428
2460
|
fallbackMeta.queryFieldAliases.used = true;
|
|
2429
2461
|
}
|
|
2430
|
-
|
|
2431
|
-
case
|
|
2432
|
-
if (!!documents.length) return [3 /*break*/,
|
|
2462
|
+
_q.label = 37;
|
|
2463
|
+
case 37:
|
|
2464
|
+
if (!!documents.length) return [3 /*break*/, 41];
|
|
2433
2465
|
_loop_2 = function (i) {
|
|
2434
|
-
var stage,
|
|
2435
|
-
return __generator(this, function (
|
|
2436
|
-
switch (
|
|
2466
|
+
var stage, _s, idLookup, rewrittenPipeline, fallbackDocs;
|
|
2467
|
+
return __generator(this, function (_t) {
|
|
2468
|
+
switch (_t.label) {
|
|
2437
2469
|
case 0:
|
|
2438
2470
|
stage = executedPipeline[i];
|
|
2439
2471
|
if (!stage || typeof stage !== 'object' || !stage.$match || typeof stage.$match !== 'object') {
|
|
2440
2472
|
return [2 /*return*/, "continue"];
|
|
2441
2473
|
}
|
|
2442
|
-
|
|
2443
|
-
if (
|
|
2474
|
+
_s = probeDocs;
|
|
2475
|
+
if (_s) return [3 /*break*/, 2];
|
|
2444
2476
|
return [4 /*yield*/, fetchAssistantProbeDocs({
|
|
2445
2477
|
db: db,
|
|
2446
2478
|
collection: collection,
|
|
@@ -2450,10 +2482,10 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
2450
2482
|
includeClientScope: shouldScopeByClient
|
|
2451
2483
|
})];
|
|
2452
2484
|
case 1:
|
|
2453
|
-
|
|
2454
|
-
|
|
2485
|
+
_s = (_t.sent());
|
|
2486
|
+
_t.label = 2;
|
|
2455
2487
|
case 2:
|
|
2456
|
-
probeDocs =
|
|
2488
|
+
probeDocs = _s;
|
|
2457
2489
|
return [4 /*yield*/, applyIdLookupFallbackToQuery({
|
|
2458
2490
|
query: stage.$match,
|
|
2459
2491
|
db: db,
|
|
@@ -2464,7 +2496,7 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
2464
2496
|
probeDocs: probeDocs || undefined
|
|
2465
2497
|
})];
|
|
2466
2498
|
case 3:
|
|
2467
|
-
idLookup =
|
|
2499
|
+
idLookup = _t.sent();
|
|
2468
2500
|
if (!idLookup) {
|
|
2469
2501
|
return [2 /*return*/, "continue"];
|
|
2470
2502
|
}
|
|
@@ -2475,41 +2507,41 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
2475
2507
|
.aggregate(rewrittenPipeline, aggregateOptions)
|
|
2476
2508
|
.toArray()];
|
|
2477
2509
|
case 4:
|
|
2478
|
-
fallbackDocs =
|
|
2510
|
+
fallbackDocs = _t.sent();
|
|
2479
2511
|
if (fallbackDocs.length) {
|
|
2480
2512
|
documents = fallbackDocs;
|
|
2481
2513
|
executedPipeline = rewrittenPipeline;
|
|
2482
2514
|
fallbackMeta.idLookup.used = true;
|
|
2483
2515
|
return [2 /*return*/, "break"];
|
|
2484
2516
|
}
|
|
2485
|
-
|
|
2517
|
+
_t.label = 5;
|
|
2486
2518
|
case 5: return [2 /*return*/];
|
|
2487
2519
|
}
|
|
2488
2520
|
});
|
|
2489
2521
|
};
|
|
2490
2522
|
i = 0;
|
|
2491
|
-
|
|
2492
|
-
case
|
|
2493
|
-
if (!(i < (executedPipeline || []).length)) return [3 /*break*/,
|
|
2523
|
+
_q.label = 38;
|
|
2524
|
+
case 38:
|
|
2525
|
+
if (!(i < (executedPipeline || []).length)) return [3 /*break*/, 41];
|
|
2494
2526
|
return [5 /*yield**/, _loop_2(i)];
|
|
2495
|
-
case
|
|
2496
|
-
state_2 =
|
|
2527
|
+
case 39:
|
|
2528
|
+
state_2 = _q.sent();
|
|
2497
2529
|
if (state_2 === "break")
|
|
2498
|
-
return [3 /*break*/,
|
|
2499
|
-
|
|
2500
|
-
case
|
|
2530
|
+
return [3 /*break*/, 41];
|
|
2531
|
+
_q.label = 40;
|
|
2532
|
+
case 40:
|
|
2501
2533
|
i += 1;
|
|
2502
|
-
return [3 /*break*/,
|
|
2503
|
-
case
|
|
2504
|
-
if (!!documents.length) return [3 /*break*/,
|
|
2534
|
+
return [3 /*break*/, 38];
|
|
2535
|
+
case 41:
|
|
2536
|
+
if (!!documents.length) return [3 /*break*/, 44];
|
|
2505
2537
|
return [4 /*yield*/, resolveBaseCollectionFromReport(db, dbName, collection)];
|
|
2506
|
-
case
|
|
2507
|
-
baseCollection =
|
|
2508
|
-
if (!(baseCollection && baseCollection !== collection)) return [3 /*break*/,
|
|
2538
|
+
case 42:
|
|
2539
|
+
baseCollection = _q.sent();
|
|
2540
|
+
if (!(baseCollection && baseCollection !== collection)) return [3 /*break*/, 44];
|
|
2509
2541
|
fallbackPayload = __assign(__assign({}, input), { collection: baseCollection });
|
|
2510
2542
|
return [4 /*yield*/, executeAiAssistantMongoAggregate(fallbackPayload, context)];
|
|
2511
|
-
case
|
|
2512
|
-
fallbackResult =
|
|
2543
|
+
case 43:
|
|
2544
|
+
fallbackResult = _q.sent();
|
|
2513
2545
|
if (Array.isArray(fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.documents) && fallbackResult.documents.length) {
|
|
2514
2546
|
if (isSuperAdmin && (fallbackResult === null || fallbackResult === void 0 ? void 0 : fallbackResult.debug) && typeof fallbackResult.debug === 'object') {
|
|
2515
2547
|
existingFallbacks = fallbackResult.debug.fallbacks && typeof fallbackResult.debug.fallbacks === 'object'
|
|
@@ -2526,48 +2558,48 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
2526
2558
|
if (isSuperAdmin) {
|
|
2527
2559
|
fallbackMeta.reportFallback = { from: collection, to: baseCollection, attempted: true, used: false };
|
|
2528
2560
|
}
|
|
2529
|
-
|
|
2530
|
-
case
|
|
2531
|
-
if (!(!documents.length && isSuperAdmin)) return [3 /*break*/,
|
|
2561
|
+
_q.label = 44;
|
|
2562
|
+
case 44:
|
|
2563
|
+
if (!(!documents.length && isSuperAdmin)) return [3 /*break*/, 61];
|
|
2532
2564
|
matchStages = (executedPipeline || []).filter(function (stage) { return stage && typeof stage === 'object' && stage.$match && typeof stage.$match === 'object'; });
|
|
2533
2565
|
diagnostics = {};
|
|
2534
|
-
if (!matchStages.length) return [3 /*break*/,
|
|
2566
|
+
if (!matchStages.length) return [3 /*break*/, 61];
|
|
2535
2567
|
combinedMatch = matchStages.reduce(function (acc, stage) { return ({ $and: __spreadArray(__spreadArray([], __read((acc.$and || [])), false), [stage.$match], false) }); }, { $and: [] });
|
|
2536
2568
|
nameFields = collectMatchFieldsByCondition(combinedMatch, function (field, condition) { return isRegexMatchCondition(condition)
|
|
2537
2569
|
|| (typeof condition === 'string' && shouldApplyAssistantNameRegex(field)); });
|
|
2538
2570
|
dateFields = collectMatchFieldsByCondition(combinedMatch, function (_field, condition) { return isDateCondition(condition); });
|
|
2539
2571
|
diagnostics.nameFields = nameFields.length ? nameFields : undefined;
|
|
2540
2572
|
diagnostics.dateFields = dateFields.length ? dateFields : undefined;
|
|
2541
|
-
|
|
2542
|
-
case
|
|
2543
|
-
|
|
2544
|
-
if (!nameFields.length) return [3 /*break*/,
|
|
2573
|
+
_q.label = 45;
|
|
2574
|
+
case 45:
|
|
2575
|
+
_q.trys.push([45, 50, , 51]);
|
|
2576
|
+
if (!nameFields.length) return [3 /*break*/, 47];
|
|
2545
2577
|
queryNoName = stripMatchFields(combinedMatch, nameFields);
|
|
2546
|
-
|
|
2578
|
+
_g = diagnostics;
|
|
2547
2579
|
return [4 /*yield*/, db.collection(collection).countDocuments(queryNoName, {
|
|
2548
2580
|
readPreference: AI_ASSISTANT_READ_PREFERENCE
|
|
2549
2581
|
})];
|
|
2550
|
-
case
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
case
|
|
2554
|
-
if (!dateFields.length) return [3 /*break*/,
|
|
2582
|
+
case 46:
|
|
2583
|
+
_g.recentCount = _q.sent();
|
|
2584
|
+
_q.label = 47;
|
|
2585
|
+
case 47:
|
|
2586
|
+
if (!dateFields.length) return [3 /*break*/, 49];
|
|
2555
2587
|
queryNoDate = stripMatchFields(combinedMatch, dateFields);
|
|
2556
|
-
|
|
2588
|
+
_h = diagnostics;
|
|
2557
2589
|
return [4 /*yield*/, db.collection(collection).countDocuments(queryNoDate, {
|
|
2558
2590
|
readPreference: AI_ASSISTANT_READ_PREFERENCE
|
|
2559
2591
|
})];
|
|
2560
|
-
case
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
case
|
|
2564
|
-
case
|
|
2565
|
-
|
|
2566
|
-
return [3 /*break*/,
|
|
2567
|
-
case
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
if (
|
|
2592
|
+
case 48:
|
|
2593
|
+
_h.nameMatchCount = _q.sent();
|
|
2594
|
+
_q.label = 49;
|
|
2595
|
+
case 49: return [3 /*break*/, 51];
|
|
2596
|
+
case 50:
|
|
2597
|
+
_j = _q.sent();
|
|
2598
|
+
return [3 /*break*/, 51];
|
|
2599
|
+
case 51:
|
|
2600
|
+
_q.trys.push([51, 54, , 55]);
|
|
2601
|
+
_k = probeDocs;
|
|
2602
|
+
if (_k) return [3 /*break*/, 53];
|
|
2571
2603
|
return [4 /*yield*/, fetchAssistantProbeDocs({
|
|
2572
2604
|
db: db,
|
|
2573
2605
|
collection: collection,
|
|
@@ -2576,44 +2608,44 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
2576
2608
|
isSuperAdmin: isSuperAdmin,
|
|
2577
2609
|
includeClientScope: shouldScopeByClient
|
|
2578
2610
|
})];
|
|
2579
|
-
case
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
case
|
|
2583
|
-
probeDocs =
|
|
2611
|
+
case 52:
|
|
2612
|
+
_k = (_q.sent());
|
|
2613
|
+
_q.label = 53;
|
|
2614
|
+
case 53:
|
|
2615
|
+
probeDocs = _k;
|
|
2584
2616
|
if (probeDocs.length && nameFields.length) {
|
|
2585
2617
|
diagnostics.chemicalIdDetected = detectChemicalIdFromProbe(probeDocs, nameFields);
|
|
2586
2618
|
}
|
|
2587
|
-
return [3 /*break*/,
|
|
2588
|
-
case
|
|
2589
|
-
|
|
2590
|
-
return [3 /*break*/,
|
|
2591
|
-
case
|
|
2592
|
-
|
|
2619
|
+
return [3 /*break*/, 55];
|
|
2620
|
+
case 54:
|
|
2621
|
+
_l = _q.sent();
|
|
2622
|
+
return [3 /*break*/, 55];
|
|
2623
|
+
case 55:
|
|
2624
|
+
_q.trys.push([55, 59, , 60]);
|
|
2593
2625
|
return [4 /*yield*/, listAssistantCollections(db, dbName)];
|
|
2594
|
-
case
|
|
2595
|
-
allCollections =
|
|
2626
|
+
case 56:
|
|
2627
|
+
allCollections = _q.sent();
|
|
2596
2628
|
base = stripVersionSuffix(collection.startsWith('report-') ? collection.slice('report-'.length) : collection);
|
|
2597
2629
|
alt = collection.startsWith('report-') ? base : "report-".concat(base);
|
|
2598
|
-
if (!(alt && alt !== collection && allCollections.includes(alt))) return [3 /*break*/,
|
|
2630
|
+
if (!(alt && alt !== collection && allCollections.includes(alt))) return [3 /*break*/, 58];
|
|
2599
2631
|
return [4 /*yield*/, db.collection(alt).countDocuments({}, { readPreference: AI_ASSISTANT_READ_PREFERENCE })];
|
|
2600
|
-
case
|
|
2601
|
-
altCount =
|
|
2632
|
+
case 57:
|
|
2633
|
+
altCount = _q.sent();
|
|
2602
2634
|
diagnostics.alternateCollection = alt;
|
|
2603
2635
|
diagnostics.alternateCollectionCount = altCount;
|
|
2604
|
-
|
|
2605
|
-
case
|
|
2606
|
-
case
|
|
2607
|
-
|
|
2608
|
-
return [3 /*break*/,
|
|
2609
|
-
case
|
|
2636
|
+
_q.label = 58;
|
|
2637
|
+
case 58: return [3 /*break*/, 60];
|
|
2638
|
+
case 59:
|
|
2639
|
+
_m = _q.sent();
|
|
2640
|
+
return [3 /*break*/, 60];
|
|
2641
|
+
case 60:
|
|
2610
2642
|
fallbackMeta.zeroDiagnostics = diagnostics;
|
|
2611
|
-
|
|
2612
|
-
case
|
|
2643
|
+
_q.label = 61;
|
|
2644
|
+
case 61:
|
|
2613
2645
|
sanitizedDocuments = isSuperAdmin
|
|
2614
2646
|
? documents
|
|
2615
2647
|
: documents.map(function (doc) { return redactSensitiveFields((0, common_1.deepCopy)(doc)); });
|
|
2616
|
-
includeIds = ((
|
|
2648
|
+
includeIds = ((_p = input.options) === null || _p === void 0 ? void 0 : _p.includeIds) === true;
|
|
2617
2649
|
displayDocs = sanitizedDocuments;
|
|
2618
2650
|
return [4 /*yield*/, applyIdLookupDisplayEnrichment({
|
|
2619
2651
|
docs: displayDocs,
|
|
@@ -2624,8 +2656,8 @@ function executeAiAssistantMongoAggregate(payload, context) {
|
|
|
2624
2656
|
idCustomer: customerId,
|
|
2625
2657
|
isSuperAdmin: isSuperAdmin
|
|
2626
2658
|
})];
|
|
2627
|
-
case
|
|
2628
|
-
idLookupDisplay =
|
|
2659
|
+
case 62:
|
|
2660
|
+
idLookupDisplay = _q.sent();
|
|
2629
2661
|
if (idLookupDisplay === null || idLookupDisplay === void 0 ? void 0 : idLookupDisplay.docs) {
|
|
2630
2662
|
displayDocs = idLookupDisplay.docs;
|
|
2631
2663
|
}
|
|
@@ -3357,21 +3389,44 @@ function getValueAtPath(obj, path) {
|
|
|
3357
3389
|
};
|
|
3358
3390
|
return walk(obj, 0);
|
|
3359
3391
|
}
|
|
3392
|
+
function hasArrayValueAtPath(docs, path) {
|
|
3393
|
+
var e_1, _a;
|
|
3394
|
+
if (!Array.isArray(docs) || !docs.length || !path) {
|
|
3395
|
+
return false;
|
|
3396
|
+
}
|
|
3397
|
+
try {
|
|
3398
|
+
for (var docs_1 = __values(docs), docs_1_1 = docs_1.next(); !docs_1_1.done; docs_1_1 = docs_1.next()) {
|
|
3399
|
+
var doc = docs_1_1.value;
|
|
3400
|
+
var value = getValueAtPath(doc, path);
|
|
3401
|
+
if (Array.isArray(value)) {
|
|
3402
|
+
return true;
|
|
3403
|
+
}
|
|
3404
|
+
}
|
|
3405
|
+
}
|
|
3406
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
3407
|
+
finally {
|
|
3408
|
+
try {
|
|
3409
|
+
if (docs_1_1 && !docs_1_1.done && (_a = docs_1.return)) _a.call(docs_1);
|
|
3410
|
+
}
|
|
3411
|
+
finally { if (e_1) throw e_1.error; }
|
|
3412
|
+
}
|
|
3413
|
+
return false;
|
|
3414
|
+
}
|
|
3360
3415
|
function inferIdFieldStorageTypeFromDocs(docs, fieldPath) {
|
|
3361
|
-
var
|
|
3416
|
+
var e_2, _a, e_3, _b;
|
|
3362
3417
|
if (!Array.isArray(docs) || !fieldPath) {
|
|
3363
3418
|
return 'unknown';
|
|
3364
3419
|
}
|
|
3365
3420
|
var sawString = false;
|
|
3366
3421
|
try {
|
|
3367
|
-
for (var
|
|
3368
|
-
var doc =
|
|
3422
|
+
for (var docs_2 = __values(docs), docs_2_1 = docs_2.next(); !docs_2_1.done; docs_2_1 = docs_2.next()) {
|
|
3423
|
+
var doc = docs_2_1.value;
|
|
3369
3424
|
var value = fieldPath.includes('.')
|
|
3370
3425
|
? getValueAtPath(doc, fieldPath)
|
|
3371
3426
|
: doc === null || doc === void 0 ? void 0 : doc[fieldPath];
|
|
3372
3427
|
var queue = Array.isArray(value) ? value : [value];
|
|
3373
3428
|
try {
|
|
3374
|
-
for (var queue_1 = (
|
|
3429
|
+
for (var queue_1 = (e_3 = void 0, __values(queue)), queue_1_1 = queue_1.next(); !queue_1_1.done; queue_1_1 = queue_1.next()) {
|
|
3375
3430
|
var entry = queue_1_1.value;
|
|
3376
3431
|
if (entry === null || entry === undefined) {
|
|
3377
3432
|
continue;
|
|
@@ -3384,21 +3439,21 @@ function inferIdFieldStorageTypeFromDocs(docs, fieldPath) {
|
|
|
3384
3439
|
}
|
|
3385
3440
|
}
|
|
3386
3441
|
}
|
|
3387
|
-
catch (
|
|
3442
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
3388
3443
|
finally {
|
|
3389
3444
|
try {
|
|
3390
3445
|
if (queue_1_1 && !queue_1_1.done && (_b = queue_1.return)) _b.call(queue_1);
|
|
3391
3446
|
}
|
|
3392
|
-
finally { if (
|
|
3447
|
+
finally { if (e_3) throw e_3.error; }
|
|
3393
3448
|
}
|
|
3394
3449
|
}
|
|
3395
3450
|
}
|
|
3396
|
-
catch (
|
|
3451
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
3397
3452
|
finally {
|
|
3398
3453
|
try {
|
|
3399
|
-
if (
|
|
3454
|
+
if (docs_2_1 && !docs_2_1.done && (_a = docs_2.return)) _a.call(docs_2);
|
|
3400
3455
|
}
|
|
3401
|
-
finally { if (
|
|
3456
|
+
finally { if (e_2) throw e_2.error; }
|
|
3402
3457
|
}
|
|
3403
3458
|
return sawString ? 'string' : 'unknown';
|
|
3404
3459
|
}
|
|
@@ -3493,7 +3548,7 @@ function normalizeLookupKeyValue(value) {
|
|
|
3493
3548
|
return '';
|
|
3494
3549
|
}
|
|
3495
3550
|
function collectTopLevelIdFieldValues(docs, options) {
|
|
3496
|
-
var
|
|
3551
|
+
var e_4, _a, e_5, _b;
|
|
3497
3552
|
if (!Array.isArray(docs) || !docs.length) {
|
|
3498
3553
|
return [];
|
|
3499
3554
|
}
|
|
@@ -3505,8 +3560,8 @@ function collectTopLevelIdFieldValues(docs, options) {
|
|
|
3505
3560
|
: AI_ASSISTANT_ID_DISPLAY_LOOKUP_MAX_IDS;
|
|
3506
3561
|
var fieldMap = new Map();
|
|
3507
3562
|
try {
|
|
3508
|
-
for (var
|
|
3509
|
-
var doc =
|
|
3563
|
+
for (var docs_3 = __values(docs), docs_3_1 = docs_3.next(); !docs_3_1.done; docs_3_1 = docs_3.next()) {
|
|
3564
|
+
var doc = docs_3_1.value;
|
|
3510
3565
|
if (!doc || typeof doc !== 'object') {
|
|
3511
3566
|
continue;
|
|
3512
3567
|
}
|
|
@@ -3541,26 +3596,26 @@ function collectTopLevelIdFieldValues(docs, options) {
|
|
|
3541
3596
|
});
|
|
3542
3597
|
};
|
|
3543
3598
|
try {
|
|
3544
|
-
for (var keys_1 = (
|
|
3599
|
+
for (var keys_1 = (e_5 = void 0, __values(keys)), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
|
|
3545
3600
|
var key = keys_1_1.value;
|
|
3546
3601
|
_loop_3(key);
|
|
3547
3602
|
}
|
|
3548
3603
|
}
|
|
3549
|
-
catch (
|
|
3604
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
3550
3605
|
finally {
|
|
3551
3606
|
try {
|
|
3552
3607
|
if (keys_1_1 && !keys_1_1.done && (_b = keys_1.return)) _b.call(keys_1);
|
|
3553
3608
|
}
|
|
3554
|
-
finally { if (
|
|
3609
|
+
finally { if (e_5) throw e_5.error; }
|
|
3555
3610
|
}
|
|
3556
3611
|
}
|
|
3557
3612
|
}
|
|
3558
|
-
catch (
|
|
3613
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
3559
3614
|
finally {
|
|
3560
3615
|
try {
|
|
3561
|
-
if (
|
|
3616
|
+
if (docs_3_1 && !docs_3_1.done && (_a = docs_3.return)) _a.call(docs_3);
|
|
3562
3617
|
}
|
|
3563
|
-
finally { if (
|
|
3618
|
+
finally { if (e_4) throw e_4.error; }
|
|
3564
3619
|
}
|
|
3565
3620
|
return Array.from(fieldMap.entries()).map(function (_a) {
|
|
3566
3621
|
var _b = __read(_a, 2), field = _b[0], values = _b[1];
|
|
@@ -3571,7 +3626,7 @@ function collectTopLevelIdFieldValues(docs, options) {
|
|
|
3571
3626
|
});
|
|
3572
3627
|
}
|
|
3573
3628
|
function resolveLookupDisplayField(baseToken, probeDocs, schemaFields) {
|
|
3574
|
-
var
|
|
3629
|
+
var e_6, _a, e_7, _b;
|
|
3575
3630
|
var normalizedBase = normalizeOptionalString(baseToken);
|
|
3576
3631
|
if (!normalizedBase) {
|
|
3577
3632
|
return null;
|
|
@@ -3589,12 +3644,12 @@ function resolveLookupDisplayField(baseToken, probeDocs, schemaFields) {
|
|
|
3589
3644
|
}
|
|
3590
3645
|
}
|
|
3591
3646
|
}
|
|
3592
|
-
catch (
|
|
3647
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
3593
3648
|
finally {
|
|
3594
3649
|
try {
|
|
3595
3650
|
if (schemaCandidates_1_1 && !schemaCandidates_1_1.done && (_a = schemaCandidates_1.return)) _a.call(schemaCandidates_1);
|
|
3596
3651
|
}
|
|
3597
|
-
finally { if (
|
|
3652
|
+
finally { if (e_6) throw e_6.error; }
|
|
3598
3653
|
}
|
|
3599
3654
|
return schemaCandidates[0];
|
|
3600
3655
|
}
|
|
@@ -3607,12 +3662,12 @@ function resolveLookupDisplayField(baseToken, probeDocs, schemaFields) {
|
|
|
3607
3662
|
}
|
|
3608
3663
|
}
|
|
3609
3664
|
}
|
|
3610
|
-
catch (
|
|
3665
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
3611
3666
|
finally {
|
|
3612
3667
|
try {
|
|
3613
3668
|
if (candidates_1_1 && !candidates_1_1.done && (_b = candidates_1.return)) _b.call(candidates_1);
|
|
3614
3669
|
}
|
|
3615
|
-
finally { if (
|
|
3670
|
+
finally { if (e_7) throw e_7.error; }
|
|
3616
3671
|
}
|
|
3617
3672
|
return candidates.length ? candidates[0] : null;
|
|
3618
3673
|
}
|
|
@@ -3625,8 +3680,8 @@ function resolveLookupMappingsForField(field, mappings) {
|
|
|
3625
3680
|
}
|
|
3626
3681
|
function applyIdLookupDisplayEnrichment(params) {
|
|
3627
3682
|
return __awaiter(this, void 0, void 0, function () {
|
|
3628
|
-
var docs, collection, db, dbName, idClient, idCustomer, isSuperAdmin, idFields, lookupMappings, allCollections, collectionProbeCache, collectionSchemaCache, lookupMeta, enrichedDocs, _loop_4, idFields_1, idFields_1_1, fieldEntry,
|
|
3629
|
-
var
|
|
3683
|
+
var docs, collection, db, dbName, idClient, idCustomer, isSuperAdmin, idFields, lookupMappings, allCollections, collectionProbeCache, collectionSchemaCache, lookupMeta, enrichedDocs, _loop_4, idFields_1, idFields_1_1, fieldEntry, e_8_1;
|
|
3684
|
+
var e_8, _a;
|
|
3630
3685
|
return __generator(this, function (_b) {
|
|
3631
3686
|
switch (_b.label) {
|
|
3632
3687
|
case 0:
|
|
@@ -3650,8 +3705,8 @@ function applyIdLookupDisplayEnrichment(params) {
|
|
|
3650
3705
|
lookupMeta = [];
|
|
3651
3706
|
enrichedDocs = docs.map(function (doc) { return (__assign({}, doc)); });
|
|
3652
3707
|
_loop_4 = function (fieldEntry) {
|
|
3653
|
-
var values, baseToken, mappingMatches, candidateCollections, filteredCandidates, _loop_5, filteredCandidates_1, filteredCandidates_1_1, candidate, state_3,
|
|
3654
|
-
var
|
|
3708
|
+
var values, baseToken, mappingMatches, candidateCollections, filteredCandidates, _loop_5, filteredCandidates_1, filteredCandidates_1_1, candidate, state_3, e_9_1;
|
|
3709
|
+
var e_9, _c;
|
|
3655
3710
|
return __generator(this, function (_d) {
|
|
3656
3711
|
switch (_d.label) {
|
|
3657
3712
|
case 0:
|
|
@@ -3800,7 +3855,7 @@ function applyIdLookupDisplayEnrichment(params) {
|
|
|
3800
3855
|
_d.label = 1;
|
|
3801
3856
|
case 1:
|
|
3802
3857
|
_d.trys.push([1, 6, 7, 8]);
|
|
3803
|
-
filteredCandidates_1 = (
|
|
3858
|
+
filteredCandidates_1 = (e_9 = void 0, __values(filteredCandidates)), filteredCandidates_1_1 = filteredCandidates_1.next();
|
|
3804
3859
|
_d.label = 2;
|
|
3805
3860
|
case 2:
|
|
3806
3861
|
if (!!filteredCandidates_1_1.done) return [3 /*break*/, 5];
|
|
@@ -3816,14 +3871,14 @@ function applyIdLookupDisplayEnrichment(params) {
|
|
|
3816
3871
|
return [3 /*break*/, 2];
|
|
3817
3872
|
case 5: return [3 /*break*/, 8];
|
|
3818
3873
|
case 6:
|
|
3819
|
-
|
|
3820
|
-
|
|
3874
|
+
e_9_1 = _d.sent();
|
|
3875
|
+
e_9 = { error: e_9_1 };
|
|
3821
3876
|
return [3 /*break*/, 8];
|
|
3822
3877
|
case 7:
|
|
3823
3878
|
try {
|
|
3824
3879
|
if (filteredCandidates_1_1 && !filteredCandidates_1_1.done && (_c = filteredCandidates_1.return)) _c.call(filteredCandidates_1);
|
|
3825
3880
|
}
|
|
3826
|
-
finally { if (
|
|
3881
|
+
finally { if (e_9) throw e_9.error; }
|
|
3827
3882
|
return [7 /*endfinally*/];
|
|
3828
3883
|
case 8: return [2 /*return*/];
|
|
3829
3884
|
}
|
|
@@ -3846,14 +3901,14 @@ function applyIdLookupDisplayEnrichment(params) {
|
|
|
3846
3901
|
return [3 /*break*/, 3];
|
|
3847
3902
|
case 6: return [3 /*break*/, 9];
|
|
3848
3903
|
case 7:
|
|
3849
|
-
|
|
3850
|
-
|
|
3904
|
+
e_8_1 = _b.sent();
|
|
3905
|
+
e_8 = { error: e_8_1 };
|
|
3851
3906
|
return [3 /*break*/, 9];
|
|
3852
3907
|
case 8:
|
|
3853
3908
|
try {
|
|
3854
3909
|
if (idFields_1_1 && !idFields_1_1.done && (_a = idFields_1.return)) _a.call(idFields_1);
|
|
3855
3910
|
}
|
|
3856
|
-
finally { if (
|
|
3911
|
+
finally { if (e_8) throw e_8.error; }
|
|
3857
3912
|
return [7 /*endfinally*/];
|
|
3858
3913
|
case 9:
|
|
3859
3914
|
if (!lookupMeta.length) {
|
|
@@ -3872,14 +3927,14 @@ function applyIdLookupDisplayEnrichment(params) {
|
|
|
3872
3927
|
});
|
|
3873
3928
|
}
|
|
3874
3929
|
function hasNonEmptyValue(docs, fieldPath, options) {
|
|
3875
|
-
var
|
|
3930
|
+
var e_10, _a;
|
|
3876
3931
|
if (!Array.isArray(docs) || !fieldPath) {
|
|
3877
3932
|
return false;
|
|
3878
3933
|
}
|
|
3879
3934
|
var usePath = fieldPath.includes('.');
|
|
3880
3935
|
try {
|
|
3881
|
-
for (var
|
|
3882
|
-
var doc =
|
|
3936
|
+
for (var docs_4 = __values(docs), docs_4_1 = docs_4.next(); !docs_4_1.done; docs_4_1 = docs_4.next()) {
|
|
3937
|
+
var doc = docs_4_1.value;
|
|
3883
3938
|
var value = usePath ? getValueAtPath(doc, fieldPath) : doc === null || doc === void 0 ? void 0 : doc[fieldPath];
|
|
3884
3939
|
if ((options === null || options === void 0 ? void 0 : options.treatObjectLikeAsEmpty) && isDisplayObjectLike(value)) {
|
|
3885
3940
|
continue;
|
|
@@ -3889,12 +3944,12 @@ function hasNonEmptyValue(docs, fieldPath, options) {
|
|
|
3889
3944
|
}
|
|
3890
3945
|
}
|
|
3891
3946
|
}
|
|
3892
|
-
catch (
|
|
3947
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
3893
3948
|
finally {
|
|
3894
3949
|
try {
|
|
3895
|
-
if (
|
|
3950
|
+
if (docs_4_1 && !docs_4_1.done && (_a = docs_4.return)) _a.call(docs_4);
|
|
3896
3951
|
}
|
|
3897
|
-
finally { if (
|
|
3952
|
+
finally { if (e_10) throw e_10.error; }
|
|
3898
3953
|
}
|
|
3899
3954
|
return false;
|
|
3900
3955
|
}
|
|
@@ -4166,35 +4221,45 @@ function replaceFieldPathDeep(value, fromField, toField) {
|
|
|
4166
4221
|
return next_1;
|
|
4167
4222
|
}
|
|
4168
4223
|
if (typeof value === 'string') {
|
|
4169
|
-
|
|
4170
|
-
|
|
4224
|
+
var fromRef = "$".concat(fromField);
|
|
4225
|
+
if (value === fromRef) {
|
|
4226
|
+
return "$".concat(toField);
|
|
4227
|
+
}
|
|
4228
|
+
if (value.startsWith("".concat(fromRef, "."))) {
|
|
4229
|
+
return "$".concat(toField).concat(value.slice(fromRef.length));
|
|
4171
4230
|
}
|
|
4172
4231
|
return value;
|
|
4173
4232
|
}
|
|
4174
4233
|
return value;
|
|
4175
4234
|
}
|
|
4176
4235
|
function replaceQueryFieldCondition(query, field, condition) {
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
return query;
|
|
4182
|
-
}
|
|
4183
|
-
var next = __assign({}, query);
|
|
4184
|
-
Object.keys(next).forEach(function (key) {
|
|
4185
|
-
if (key === field) {
|
|
4186
|
-
next[key] = condition;
|
|
4187
|
-
return;
|
|
4188
|
-
}
|
|
4189
|
-
if (key.startsWith('$')) {
|
|
4190
|
-
next[key] = replaceQueryFieldCondition(next[key], field, condition);
|
|
4191
|
-
return;
|
|
4236
|
+
var hasPath = field.includes('.');
|
|
4237
|
+
var replaceValue = function (value, prefix) {
|
|
4238
|
+
if (Array.isArray(value)) {
|
|
4239
|
+
return value.map(function (entry) { return replaceValue(entry, prefix); });
|
|
4192
4240
|
}
|
|
4193
|
-
if (
|
|
4194
|
-
|
|
4241
|
+
if (!value || typeof value !== 'object') {
|
|
4242
|
+
return value;
|
|
4195
4243
|
}
|
|
4196
|
-
|
|
4197
|
-
|
|
4244
|
+
var next = __assign({}, value);
|
|
4245
|
+
Object.keys(next).forEach(function (key) {
|
|
4246
|
+
var currentPath = prefix ? "".concat(prefix, ".").concat(key) : key;
|
|
4247
|
+
var matches = hasPath ? currentPath === field : key === field;
|
|
4248
|
+
if (matches) {
|
|
4249
|
+
next[key] = condition;
|
|
4250
|
+
return;
|
|
4251
|
+
}
|
|
4252
|
+
if (key.startsWith('$')) {
|
|
4253
|
+
next[key] = replaceValue(next[key], prefix);
|
|
4254
|
+
return;
|
|
4255
|
+
}
|
|
4256
|
+
if (next[key] && typeof next[key] === 'object') {
|
|
4257
|
+
next[key] = replaceValue(next[key], currentPath);
|
|
4258
|
+
}
|
|
4259
|
+
});
|
|
4260
|
+
return next;
|
|
4261
|
+
};
|
|
4262
|
+
return replaceValue(query, '');
|
|
4198
4263
|
}
|
|
4199
4264
|
function formatDisplayColumnName(column) {
|
|
4200
4265
|
var trimmed = String(column || '').trim();
|
|
@@ -4748,21 +4813,154 @@ function sanitizeAssistantProjection(projection) {
|
|
|
4748
4813
|
}
|
|
4749
4814
|
return projection;
|
|
4750
4815
|
}
|
|
4751
|
-
|
|
4816
|
+
var AGG_MATCH_EXPR_OPERATORS = new Set(['$eq', '$ne', '$gt', '$gte', '$lt', '$lte']);
|
|
4817
|
+
function isMatchExpressionOperand(value) {
|
|
4818
|
+
if (typeof value === 'string') {
|
|
4819
|
+
return value.startsWith('$$');
|
|
4820
|
+
}
|
|
4821
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
4822
|
+
return false;
|
|
4823
|
+
}
|
|
4824
|
+
if (value instanceof Date || value instanceof RegExp || isMongoObjectId(value)) {
|
|
4825
|
+
return false;
|
|
4826
|
+
}
|
|
4827
|
+
return Object.keys(value).some(function (key) { return key.startsWith('$'); });
|
|
4828
|
+
}
|
|
4829
|
+
function mergeMatchExpr(existing, clauses) {
|
|
4830
|
+
if (!clauses.length) {
|
|
4831
|
+
return existing;
|
|
4832
|
+
}
|
|
4833
|
+
if (!existing) {
|
|
4834
|
+
return clauses.length === 1 ? clauses[0] : { $and: clauses };
|
|
4835
|
+
}
|
|
4836
|
+
if (existing && typeof existing === 'object' && !Array.isArray(existing)) {
|
|
4837
|
+
var existingAnd = existing.$and;
|
|
4838
|
+
if (Array.isArray(existingAnd)) {
|
|
4839
|
+
return __assign(__assign({}, existing), { $and: __spreadArray(__spreadArray([], __read(existingAnd), false), __read(clauses), false) });
|
|
4840
|
+
}
|
|
4841
|
+
}
|
|
4842
|
+
return { $and: __spreadArray([existing], __read(clauses), false) };
|
|
4843
|
+
}
|
|
4844
|
+
function rewriteMatchExpressionsToExpr(match) {
|
|
4845
|
+
var rewriteValue = function (value) {
|
|
4846
|
+
if (Array.isArray(value)) {
|
|
4847
|
+
return value.map(function (entry) { return rewriteValue(entry); });
|
|
4848
|
+
}
|
|
4849
|
+
if (!value || typeof value !== 'object' || value instanceof Date || value instanceof RegExp || isMongoObjectId(value)) {
|
|
4850
|
+
return value;
|
|
4851
|
+
}
|
|
4852
|
+
var result = {};
|
|
4853
|
+
var exprClauses = [];
|
|
4854
|
+
Object.keys(value).forEach(function (key) {
|
|
4855
|
+
var entry = value[key];
|
|
4856
|
+
if (key === '$expr') {
|
|
4857
|
+
result[key] = entry;
|
|
4858
|
+
return;
|
|
4859
|
+
}
|
|
4860
|
+
if (key.startsWith('$')) {
|
|
4861
|
+
result[key] = rewriteValue(entry);
|
|
4862
|
+
return;
|
|
4863
|
+
}
|
|
4864
|
+
if (entry && typeof entry === 'object' && !Array.isArray(entry) && !(entry instanceof Date) && !(entry instanceof RegExp) && !isMongoObjectId(entry)) {
|
|
4865
|
+
var nextEntry_1 = __assign({}, entry);
|
|
4866
|
+
var moved_1 = false;
|
|
4867
|
+
Object.keys(nextEntry_1).forEach(function (op) {
|
|
4868
|
+
var _a;
|
|
4869
|
+
if (!AGG_MATCH_EXPR_OPERATORS.has(op)) {
|
|
4870
|
+
return;
|
|
4871
|
+
}
|
|
4872
|
+
var operand = nextEntry_1[op];
|
|
4873
|
+
if (isMatchExpressionOperand(operand)) {
|
|
4874
|
+
exprClauses.push((_a = {}, _a[op] = ["$".concat(key), operand], _a));
|
|
4875
|
+
delete nextEntry_1[op];
|
|
4876
|
+
moved_1 = true;
|
|
4877
|
+
}
|
|
4878
|
+
});
|
|
4879
|
+
if (Object.keys(nextEntry_1).length) {
|
|
4880
|
+
result[key] = rewriteValue(nextEntry_1);
|
|
4881
|
+
}
|
|
4882
|
+
else if (!moved_1) {
|
|
4883
|
+
result[key] = entry;
|
|
4884
|
+
}
|
|
4885
|
+
return;
|
|
4886
|
+
}
|
|
4887
|
+
if (typeof entry === 'string' && entry.startsWith('$$')) {
|
|
4888
|
+
exprClauses.push({ $eq: ["$".concat(key), entry] });
|
|
4889
|
+
return;
|
|
4890
|
+
}
|
|
4891
|
+
result[key] = entry;
|
|
4892
|
+
});
|
|
4893
|
+
if (exprClauses.length) {
|
|
4894
|
+
result.$expr = mergeMatchExpr(result.$expr, exprClauses);
|
|
4895
|
+
}
|
|
4896
|
+
return result;
|
|
4897
|
+
};
|
|
4898
|
+
return rewriteValue(match);
|
|
4899
|
+
}
|
|
4900
|
+
function buildInvoiceStatusRegex(value) {
|
|
4901
|
+
var normalized = String(value || '').toLowerCase();
|
|
4902
|
+
if (!normalized) {
|
|
4903
|
+
return null;
|
|
4904
|
+
}
|
|
4905
|
+
var tokens = normalized.split(/[^a-z0-9]+/g).filter(Boolean);
|
|
4906
|
+
if (!tokens.includes('paid') || !tokens.includes('closed')) {
|
|
4907
|
+
return null;
|
|
4908
|
+
}
|
|
4909
|
+
return /paid|closed/i;
|
|
4910
|
+
}
|
|
4911
|
+
function normalizeInvoiceStatusMatch(match) {
|
|
4912
|
+
var rewriteValue = function (value) {
|
|
4913
|
+
if (Array.isArray(value)) {
|
|
4914
|
+
return value.map(function (entry) { return rewriteValue(entry); });
|
|
4915
|
+
}
|
|
4916
|
+
if (!value || typeof value !== 'object' || value instanceof Date || value instanceof RegExp || isMongoObjectId(value)) {
|
|
4917
|
+
return value;
|
|
4918
|
+
}
|
|
4919
|
+
var result = {};
|
|
4920
|
+
Object.keys(value).forEach(function (key) {
|
|
4921
|
+
var entry = value[key];
|
|
4922
|
+
if (key.startsWith('$')) {
|
|
4923
|
+
result[key] = rewriteValue(entry);
|
|
4924
|
+
return;
|
|
4925
|
+
}
|
|
4926
|
+
var field = key.split('.').pop() || key;
|
|
4927
|
+
if (field === 'status' && typeof entry === 'string') {
|
|
4928
|
+
var regex = buildInvoiceStatusRegex(entry);
|
|
4929
|
+
if (regex) {
|
|
4930
|
+
result[key] = regex;
|
|
4931
|
+
return;
|
|
4932
|
+
}
|
|
4933
|
+
}
|
|
4934
|
+
if (entry && typeof entry === 'object') {
|
|
4935
|
+
result[key] = rewriteValue(entry);
|
|
4936
|
+
return;
|
|
4937
|
+
}
|
|
4938
|
+
result[key] = entry;
|
|
4939
|
+
});
|
|
4940
|
+
return result;
|
|
4941
|
+
};
|
|
4942
|
+
return rewriteValue(match);
|
|
4943
|
+
}
|
|
4944
|
+
function normalizeAssistantAggregatePipeline(pipeline, collection) {
|
|
4752
4945
|
if (!Array.isArray(pipeline)) {
|
|
4753
4946
|
return [];
|
|
4754
4947
|
}
|
|
4948
|
+
var isInvoiceCollection = ['invoice', 'invoices', 'invoice-versions'].includes(String(collection || '').toLowerCase());
|
|
4755
4949
|
return pipeline
|
|
4756
4950
|
.filter(function (stage) { return stage && typeof stage === 'object' && !Array.isArray(stage); })
|
|
4757
4951
|
.map(function (stage) {
|
|
4758
4952
|
var next = __assign({}, stage);
|
|
4759
4953
|
if (next.$match && typeof next.$match === 'object') {
|
|
4760
4954
|
var rewritten = rewriteEmbeddedMatchObjects(next.$match);
|
|
4761
|
-
|
|
4955
|
+
var exprRewritten = rewriteMatchExpressionsToExpr(rewritten);
|
|
4956
|
+
var statusNormalized = isInvoiceCollection ? normalizeInvoiceStatusMatch(exprRewritten) : exprRewritten;
|
|
4957
|
+
next.$match = applyAssistantNameRegexToQuery(statusNormalized);
|
|
4762
4958
|
}
|
|
4763
4959
|
if (next.$geoNear && typeof next.$geoNear === 'object' && next.$geoNear.query) {
|
|
4764
4960
|
var rewritten = rewriteEmbeddedMatchObjects(next.$geoNear.query);
|
|
4765
|
-
|
|
4961
|
+
var exprRewritten = rewriteMatchExpressionsToExpr(rewritten);
|
|
4962
|
+
var statusNormalized = isInvoiceCollection ? normalizeInvoiceStatusMatch(exprRewritten) : exprRewritten;
|
|
4963
|
+
next.$geoNear = __assign(__assign({}, next.$geoNear), { query: applyAssistantNameRegexToQuery(statusNormalized) });
|
|
4766
4964
|
}
|
|
4767
4965
|
return next;
|
|
4768
4966
|
});
|
|
@@ -4815,7 +5013,7 @@ function findAggregateLimit(pipeline) {
|
|
|
4815
5013
|
}
|
|
4816
5014
|
var limit = stage.$limit;
|
|
4817
5015
|
if (typeof limit === 'number' && Number.isFinite(limit)) {
|
|
4818
|
-
return limit;
|
|
5016
|
+
return { index: i, limit: limit };
|
|
4819
5017
|
}
|
|
4820
5018
|
}
|
|
4821
5019
|
return null;
|
|
@@ -4828,12 +5026,13 @@ function applyAssistantAggregateLimit(pipeline, limit, maxLimit, defaultLimit) {
|
|
|
4828
5026
|
? Math.min(limit, maxLimit)
|
|
4829
5027
|
: defaultLimit;
|
|
4830
5028
|
var existingLimit = findAggregateLimit(normalizedPipeline);
|
|
4831
|
-
if (existingLimit
|
|
5029
|
+
if (!existingLimit) {
|
|
4832
5030
|
normalizedPipeline.push({ $limit: requestedLimit });
|
|
4833
5031
|
return normalizedPipeline;
|
|
4834
5032
|
}
|
|
4835
|
-
if (existingLimit > maxLimit) {
|
|
4836
|
-
|
|
5033
|
+
if (existingLimit.limit > maxLimit) {
|
|
5034
|
+
var stage = normalizedPipeline[existingLimit.index];
|
|
5035
|
+
normalizedPipeline[existingLimit.index] = __assign(__assign({}, stage), { $limit: maxLimit });
|
|
4837
5036
|
}
|
|
4838
5037
|
return normalizedPipeline;
|
|
4839
5038
|
}
|
|
@@ -4893,7 +5092,7 @@ function matchContainsField(value, field) {
|
|
|
4893
5092
|
});
|
|
4894
5093
|
}
|
|
4895
5094
|
function resolveAggregateCompletionFallback(pipeline) {
|
|
4896
|
-
var
|
|
5095
|
+
var e_11, _a;
|
|
4897
5096
|
if (!Array.isArray(pipeline)) {
|
|
4898
5097
|
return null;
|
|
4899
5098
|
}
|
|
@@ -4906,7 +5105,7 @@ function resolveAggregateCompletionFallback(pipeline) {
|
|
|
4906
5105
|
}
|
|
4907
5106
|
var addFields = stage.$addFields;
|
|
4908
5107
|
try {
|
|
4909
|
-
for (var _b = (
|
|
5108
|
+
for (var _b = (e_11 = void 0, __values(Object.keys(addFields))), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
4910
5109
|
var key = _c.value;
|
|
4911
5110
|
if (!isCompletionFieldName(key)) {
|
|
4912
5111
|
continue;
|
|
@@ -4920,12 +5119,12 @@ function resolveAggregateCompletionFallback(pipeline) {
|
|
|
4920
5119
|
}
|
|
4921
5120
|
}
|
|
4922
5121
|
}
|
|
4923
|
-
catch (
|
|
5122
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
4924
5123
|
finally {
|
|
4925
5124
|
try {
|
|
4926
5125
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
4927
5126
|
}
|
|
4928
|
-
finally { if (
|
|
5127
|
+
finally { if (e_11) throw e_11.error; }
|
|
4929
5128
|
}
|
|
4930
5129
|
if (candidateField) {
|
|
4931
5130
|
break;
|
|
@@ -5081,7 +5280,7 @@ function buildCompletionFallbackSources(field) {
|
|
|
5081
5280
|
]);
|
|
5082
5281
|
}
|
|
5083
5282
|
function resolveAggregateCompletionExprFallback(pipeline) {
|
|
5084
|
-
var
|
|
5283
|
+
var e_12, _a;
|
|
5085
5284
|
if (!Array.isArray(pipeline)) {
|
|
5086
5285
|
return null;
|
|
5087
5286
|
}
|
|
@@ -5101,7 +5300,7 @@ function resolveAggregateCompletionExprFallback(pipeline) {
|
|
|
5101
5300
|
}
|
|
5102
5301
|
if (!candidateField) {
|
|
5103
5302
|
try {
|
|
5104
|
-
for (var _b = (
|
|
5303
|
+
for (var _b = (e_12 = void 0, __values(Object.keys(matchStage))), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
5105
5304
|
var key = _c.value;
|
|
5106
5305
|
if (key.startsWith('$')) {
|
|
5107
5306
|
continue;
|
|
@@ -5116,12 +5315,12 @@ function resolveAggregateCompletionExprFallback(pipeline) {
|
|
|
5116
5315
|
}
|
|
5117
5316
|
}
|
|
5118
5317
|
}
|
|
5119
|
-
catch (
|
|
5318
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
5120
5319
|
finally {
|
|
5121
5320
|
try {
|
|
5122
5321
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
5123
5322
|
}
|
|
5124
|
-
finally { if (
|
|
5323
|
+
finally { if (e_12) throw e_12.error; }
|
|
5125
5324
|
}
|
|
5126
5325
|
}
|
|
5127
5326
|
if (!candidateField) {
|
|
@@ -5291,7 +5490,7 @@ function isRegexMatchCondition(value) {
|
|
|
5291
5490
|
return false;
|
|
5292
5491
|
}
|
|
5293
5492
|
function findRegexMatchInMatchObject(match, prefix) {
|
|
5294
|
-
var
|
|
5493
|
+
var e_13, _a, e_14, _b;
|
|
5295
5494
|
if (prefix === void 0) { prefix = ''; }
|
|
5296
5495
|
if (Array.isArray(match)) {
|
|
5297
5496
|
try {
|
|
@@ -5303,12 +5502,12 @@ function findRegexMatchInMatchObject(match, prefix) {
|
|
|
5303
5502
|
}
|
|
5304
5503
|
}
|
|
5305
5504
|
}
|
|
5306
|
-
catch (
|
|
5505
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
5307
5506
|
finally {
|
|
5308
5507
|
try {
|
|
5309
5508
|
if (match_1_1 && !match_1_1.done && (_a = match_1.return)) _a.call(match_1);
|
|
5310
5509
|
}
|
|
5311
|
-
finally { if (
|
|
5510
|
+
finally { if (e_13) throw e_13.error; }
|
|
5312
5511
|
}
|
|
5313
5512
|
return null;
|
|
5314
5513
|
}
|
|
@@ -5339,12 +5538,12 @@ function findRegexMatchInMatchObject(match, prefix) {
|
|
|
5339
5538
|
}
|
|
5340
5539
|
}
|
|
5341
5540
|
}
|
|
5342
|
-
catch (
|
|
5541
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
5343
5542
|
finally {
|
|
5344
5543
|
try {
|
|
5345
5544
|
if (keys_2_1 && !keys_2_1.done && (_b = keys_2.return)) _b.call(keys_2);
|
|
5346
5545
|
}
|
|
5347
|
-
finally { if (
|
|
5546
|
+
finally { if (e_14) throw e_14.error; }
|
|
5348
5547
|
}
|
|
5349
5548
|
return null;
|
|
5350
5549
|
}
|
|
@@ -5499,39 +5698,45 @@ function isEmptyMatchValue(value) {
|
|
|
5499
5698
|
return false;
|
|
5500
5699
|
}
|
|
5501
5700
|
function stripMatchField(match, field) {
|
|
5502
|
-
|
|
5503
|
-
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
|
|
5509
|
-
return match;
|
|
5510
|
-
}
|
|
5511
|
-
var result = {};
|
|
5512
|
-
Object.keys(match).forEach(function (key) {
|
|
5513
|
-
if (key === field) {
|
|
5514
|
-
return;
|
|
5701
|
+
var hasPath = field.includes('.');
|
|
5702
|
+
var stripValue = function (value, prefix) {
|
|
5703
|
+
if (Array.isArray(value)) {
|
|
5704
|
+
var strippedArray = value
|
|
5705
|
+
.map(function (entry) { return stripValue(entry, prefix); })
|
|
5706
|
+
.filter(function (entry) { return !isEmptyMatchValue(entry); });
|
|
5707
|
+
return strippedArray;
|
|
5515
5708
|
}
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5519
|
-
|
|
5709
|
+
if (!value || typeof value !== 'object') {
|
|
5710
|
+
return value;
|
|
5711
|
+
}
|
|
5712
|
+
var result = {};
|
|
5713
|
+
Object.keys(value).forEach(function (key) {
|
|
5714
|
+
var entry = value[key];
|
|
5715
|
+
var currentPath = prefix ? "".concat(prefix, ".").concat(key) : key;
|
|
5716
|
+
var matches = hasPath ? currentPath === field : key === field;
|
|
5717
|
+
if (matches) {
|
|
5520
5718
|
return;
|
|
5521
5719
|
}
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
if (!isEmptyMatchValue(stripped)) {
|
|
5720
|
+
if (key.startsWith('$')) {
|
|
5721
|
+
var stripped = stripValue(entry, prefix);
|
|
5722
|
+
if (isEmptyMatchValue(stripped) && (key === '$and' || key === '$or')) {
|
|
5723
|
+
return;
|
|
5724
|
+
}
|
|
5528
5725
|
result[key] = stripped;
|
|
5726
|
+
return;
|
|
5529
5727
|
}
|
|
5530
|
-
|
|
5531
|
-
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5728
|
+
if (entry && typeof entry === 'object') {
|
|
5729
|
+
var stripped = stripValue(entry, currentPath);
|
|
5730
|
+
if (!isEmptyMatchValue(stripped)) {
|
|
5731
|
+
result[key] = stripped;
|
|
5732
|
+
}
|
|
5733
|
+
return;
|
|
5734
|
+
}
|
|
5735
|
+
result[key] = entry;
|
|
5736
|
+
});
|
|
5737
|
+
return result;
|
|
5738
|
+
};
|
|
5739
|
+
return stripValue(match, '');
|
|
5535
5740
|
}
|
|
5536
5741
|
function collectMatchFieldsByCondition(match, predicate, prefix) {
|
|
5537
5742
|
if (prefix === void 0) { prefix = ''; }
|
|
@@ -5562,7 +5767,7 @@ function collectMatchFieldsByCondition(match, predicate, prefix) {
|
|
|
5562
5767
|
return results;
|
|
5563
5768
|
}
|
|
5564
5769
|
function findMatchConditionForField(match, targetField, prefix) {
|
|
5565
|
-
var
|
|
5770
|
+
var e_15, _a, e_16, _b;
|
|
5566
5771
|
if (prefix === void 0) { prefix = ''; }
|
|
5567
5772
|
if (!match || typeof match !== 'object') {
|
|
5568
5773
|
return undefined;
|
|
@@ -5577,12 +5782,12 @@ function findMatchConditionForField(match, targetField, prefix) {
|
|
|
5577
5782
|
}
|
|
5578
5783
|
}
|
|
5579
5784
|
}
|
|
5580
|
-
catch (
|
|
5785
|
+
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
5581
5786
|
finally {
|
|
5582
5787
|
try {
|
|
5583
5788
|
if (match_2_1 && !match_2_1.done && (_a = match_2.return)) _a.call(match_2);
|
|
5584
5789
|
}
|
|
5585
|
-
finally { if (
|
|
5790
|
+
finally { if (e_15) throw e_15.error; }
|
|
5586
5791
|
}
|
|
5587
5792
|
return undefined;
|
|
5588
5793
|
}
|
|
@@ -5609,12 +5814,12 @@ function findMatchConditionForField(match, targetField, prefix) {
|
|
|
5609
5814
|
}
|
|
5610
5815
|
}
|
|
5611
5816
|
}
|
|
5612
|
-
catch (
|
|
5817
|
+
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
5613
5818
|
finally {
|
|
5614
5819
|
try {
|
|
5615
5820
|
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
5616
5821
|
}
|
|
5617
|
-
finally { if (
|
|
5822
|
+
finally { if (e_16) throw e_16.error; }
|
|
5618
5823
|
}
|
|
5619
5824
|
return undefined;
|
|
5620
5825
|
}
|
|
@@ -5657,7 +5862,7 @@ function detectIdLikeValue(value) {
|
|
|
5657
5862
|
return false;
|
|
5658
5863
|
}
|
|
5659
5864
|
function detectChemicalIdFromProbe(probeDocs, fields) {
|
|
5660
|
-
var
|
|
5865
|
+
var e_17, _a, e_18, _b;
|
|
5661
5866
|
if (!Array.isArray(probeDocs) || !probeDocs.length) {
|
|
5662
5867
|
return false;
|
|
5663
5868
|
}
|
|
@@ -5669,7 +5874,7 @@ function detectChemicalIdFromProbe(probeDocs, fields) {
|
|
|
5669
5874
|
for (var probeDocs_1 = __values(probeDocs), probeDocs_1_1 = probeDocs_1.next(); !probeDocs_1_1.done; probeDocs_1_1 = probeDocs_1.next()) {
|
|
5670
5875
|
var doc = probeDocs_1_1.value;
|
|
5671
5876
|
try {
|
|
5672
|
-
for (var targets_1 = (
|
|
5877
|
+
for (var targets_1 = (e_18 = void 0, __values(targets)), targets_1_1 = targets_1.next(); !targets_1_1.done; targets_1_1 = targets_1.next()) {
|
|
5673
5878
|
var field = targets_1_1.value;
|
|
5674
5879
|
var value = getValueAtPath(doc, field);
|
|
5675
5880
|
if (Array.isArray(value)) {
|
|
@@ -5682,21 +5887,21 @@ function detectChemicalIdFromProbe(probeDocs, fields) {
|
|
|
5682
5887
|
}
|
|
5683
5888
|
}
|
|
5684
5889
|
}
|
|
5685
|
-
catch (
|
|
5890
|
+
catch (e_18_1) { e_18 = { error: e_18_1 }; }
|
|
5686
5891
|
finally {
|
|
5687
5892
|
try {
|
|
5688
5893
|
if (targets_1_1 && !targets_1_1.done && (_b = targets_1.return)) _b.call(targets_1);
|
|
5689
5894
|
}
|
|
5690
|
-
finally { if (
|
|
5895
|
+
finally { if (e_18) throw e_18.error; }
|
|
5691
5896
|
}
|
|
5692
5897
|
}
|
|
5693
5898
|
}
|
|
5694
|
-
catch (
|
|
5899
|
+
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
5695
5900
|
finally {
|
|
5696
5901
|
try {
|
|
5697
5902
|
if (probeDocs_1_1 && !probeDocs_1_1.done && (_a = probeDocs_1.return)) _a.call(probeDocs_1);
|
|
5698
5903
|
}
|
|
5699
|
-
finally { if (
|
|
5904
|
+
finally { if (e_17) throw e_17.error; }
|
|
5700
5905
|
}
|
|
5701
5906
|
return false;
|
|
5702
5907
|
}
|
|
@@ -5846,9 +6051,9 @@ function isIdLookupCondition(value) {
|
|
|
5846
6051
|
}
|
|
5847
6052
|
function collectIdFieldConditions(match) {
|
|
5848
6053
|
var results = [];
|
|
5849
|
-
var visit = function (value) {
|
|
6054
|
+
var visit = function (value, prefix) {
|
|
5850
6055
|
if (Array.isArray(value)) {
|
|
5851
|
-
value.forEach(function (entry) { return visit(entry); });
|
|
6056
|
+
value.forEach(function (entry) { return visit(entry, prefix); });
|
|
5852
6057
|
return;
|
|
5853
6058
|
}
|
|
5854
6059
|
if (!value || typeof value !== 'object') {
|
|
@@ -5857,19 +6062,20 @@ function collectIdFieldConditions(match) {
|
|
|
5857
6062
|
Object.keys(value).forEach(function (key) {
|
|
5858
6063
|
var entry = value[key];
|
|
5859
6064
|
if (key.startsWith('$')) {
|
|
5860
|
-
visit(entry);
|
|
6065
|
+
visit(entry, prefix);
|
|
5861
6066
|
return;
|
|
5862
6067
|
}
|
|
6068
|
+
var currentPath = prefix ? "".concat(prefix, ".").concat(key) : key;
|
|
5863
6069
|
if (isAssistantIdField(key) && isIdLookupCondition(entry)) {
|
|
5864
|
-
results.push({ field:
|
|
6070
|
+
results.push({ field: currentPath, condition: entry });
|
|
5865
6071
|
return;
|
|
5866
6072
|
}
|
|
5867
6073
|
if (entry && typeof entry === 'object') {
|
|
5868
|
-
visit(entry);
|
|
6074
|
+
visit(entry, currentPath);
|
|
5869
6075
|
}
|
|
5870
6076
|
});
|
|
5871
6077
|
};
|
|
5872
|
-
visit(match);
|
|
6078
|
+
visit(match, '');
|
|
5873
6079
|
return results;
|
|
5874
6080
|
}
|
|
5875
6081
|
function resolveLocalNameFieldFromDocs(docs, baseToken) {
|
|
@@ -5916,8 +6122,8 @@ function buildChemicalIdFieldCandidates(field) {
|
|
|
5916
6122
|
}
|
|
5917
6123
|
function applyChemicalNameLookupFallbackToQuery(params) {
|
|
5918
6124
|
return __awaiter(this, void 0, void 0, function () {
|
|
5919
|
-
var query, db, dbName, idClient, idCustomer, isSuperAdmin, probeDocs, chemicalFields, targetField, condition, regex, sampleDocs, collectionNames, candidates, _loop_6, candidates_2, candidates_2_1, candidate, state_4,
|
|
5920
|
-
var
|
|
6125
|
+
var query, db, dbName, idClient, idCustomer, isSuperAdmin, probeDocs, chemicalFields, targetField, condition, regex, sampleDocs, collectionNames, candidates, _loop_6, candidates_2, candidates_2_1, candidate, state_4, e_19_1;
|
|
6126
|
+
var e_19, _a;
|
|
5921
6127
|
var _b;
|
|
5922
6128
|
return __generator(this, function (_c) {
|
|
5923
6129
|
switch (_c.label) {
|
|
@@ -6030,14 +6236,14 @@ function applyChemicalNameLookupFallbackToQuery(params) {
|
|
|
6030
6236
|
return [3 /*break*/, 3];
|
|
6031
6237
|
case 6: return [3 /*break*/, 9];
|
|
6032
6238
|
case 7:
|
|
6033
|
-
|
|
6034
|
-
|
|
6239
|
+
e_19_1 = _c.sent();
|
|
6240
|
+
e_19 = { error: e_19_1 };
|
|
6035
6241
|
return [3 /*break*/, 9];
|
|
6036
6242
|
case 8:
|
|
6037
6243
|
try {
|
|
6038
6244
|
if (candidates_2_1 && !candidates_2_1.done && (_a = candidates_2.return)) _a.call(candidates_2);
|
|
6039
6245
|
}
|
|
6040
|
-
finally { if (
|
|
6246
|
+
finally { if (e_19) throw e_19.error; }
|
|
6041
6247
|
return [7 /*endfinally*/];
|
|
6042
6248
|
case 9: return [2 /*return*/, null];
|
|
6043
6249
|
}
|
|
@@ -6131,8 +6337,8 @@ function lookupIdsForNameMatch(params) {
|
|
|
6131
6337
|
}
|
|
6132
6338
|
function applyIdLookupFallbackToQuery(params) {
|
|
6133
6339
|
return __awaiter(this, void 0, void 0, function () {
|
|
6134
|
-
var query, db, dbName, idClient, idCustomer, isSuperAdmin, probeDocs, conditions, collectionNames, _a, conditions_1, conditions_1_1, condition, regex, baseToken, targetFieldType, nextValue, localNameField, candidates, candidates_3, candidates_3_1, candidate, candidateHasClientScope, _b, candidateProbe, lookup, targetFieldType, normalizedIds, idsForQuery,
|
|
6135
|
-
var
|
|
6340
|
+
var query, db, dbName, idClient, idCustomer, isSuperAdmin, probeDocs, conditions, collectionNames, _a, conditions_1, conditions_1_1, condition, regex, baseToken, targetFieldType, nextValue, localNameField, candidates, candidates_3, candidates_3_1, candidate, candidateHasClientScope, _b, candidateProbe, lookup, targetFieldType, normalizedIds, idsForQuery, e_20_1, e_21_1;
|
|
6341
|
+
var e_21, _c, e_20, _d;
|
|
6136
6342
|
var _e;
|
|
6137
6343
|
return __generator(this, function (_f) {
|
|
6138
6344
|
switch (_f.label) {
|
|
@@ -6202,7 +6408,7 @@ function applyIdLookupFallbackToQuery(params) {
|
|
|
6202
6408
|
_f.label = 5;
|
|
6203
6409
|
case 5:
|
|
6204
6410
|
_f.trys.push([5, 14, 15, 16]);
|
|
6205
|
-
candidates_3 = (
|
|
6411
|
+
candidates_3 = (e_20 = void 0, __values(candidates)), candidates_3_1 = candidates_3.next();
|
|
6206
6412
|
_f.label = 6;
|
|
6207
6413
|
case 6:
|
|
6208
6414
|
if (!!candidates_3_1.done) return [3 /*break*/, 13];
|
|
@@ -6269,28 +6475,28 @@ function applyIdLookupFallbackToQuery(params) {
|
|
|
6269
6475
|
return [3 /*break*/, 6];
|
|
6270
6476
|
case 13: return [3 /*break*/, 16];
|
|
6271
6477
|
case 14:
|
|
6272
|
-
|
|
6273
|
-
|
|
6478
|
+
e_20_1 = _f.sent();
|
|
6479
|
+
e_20 = { error: e_20_1 };
|
|
6274
6480
|
return [3 /*break*/, 16];
|
|
6275
6481
|
case 15:
|
|
6276
6482
|
try {
|
|
6277
6483
|
if (candidates_3_1 && !candidates_3_1.done && (_d = candidates_3.return)) _d.call(candidates_3);
|
|
6278
6484
|
}
|
|
6279
|
-
finally { if (
|
|
6485
|
+
finally { if (e_20) throw e_20.error; }
|
|
6280
6486
|
return [7 /*endfinally*/];
|
|
6281
6487
|
case 16:
|
|
6282
6488
|
conditions_1_1 = conditions_1.next();
|
|
6283
6489
|
return [3 /*break*/, 4];
|
|
6284
6490
|
case 17: return [3 /*break*/, 20];
|
|
6285
6491
|
case 18:
|
|
6286
|
-
|
|
6287
|
-
|
|
6492
|
+
e_21_1 = _f.sent();
|
|
6493
|
+
e_21 = { error: e_21_1 };
|
|
6288
6494
|
return [3 /*break*/, 20];
|
|
6289
6495
|
case 19:
|
|
6290
6496
|
try {
|
|
6291
6497
|
if (conditions_1_1 && !conditions_1_1.done && (_c = conditions_1.return)) _c.call(conditions_1);
|
|
6292
6498
|
}
|
|
6293
|
-
finally { if (
|
|
6499
|
+
finally { if (e_21) throw e_21.error; }
|
|
6294
6500
|
return [7 /*endfinally*/];
|
|
6295
6501
|
case 20: return [2 /*return*/, null];
|
|
6296
6502
|
}
|
|
@@ -6384,8 +6590,12 @@ function replaceAggregateDateField(pipeline, fromField, toField) {
|
|
|
6384
6590
|
return next_2;
|
|
6385
6591
|
}
|
|
6386
6592
|
if (typeof value === 'string') {
|
|
6387
|
-
|
|
6388
|
-
|
|
6593
|
+
var fromRef = "$".concat(fromField);
|
|
6594
|
+
if (value === fromRef) {
|
|
6595
|
+
return "$".concat(toField);
|
|
6596
|
+
}
|
|
6597
|
+
if (value.startsWith("".concat(fromRef, "."))) {
|
|
6598
|
+
return "$".concat(toField).concat(value.slice(fromRef.length));
|
|
6389
6599
|
}
|
|
6390
6600
|
return value;
|
|
6391
6601
|
}
|
|
@@ -6437,8 +6647,17 @@ function buildTokenizedRegex(value) {
|
|
|
6437
6647
|
var tokenPattern = tokens.map(function (token) { return escapeRegexValue(token); }).join('[\\s\\-_]*.*');
|
|
6438
6648
|
return new RegExp(tokenPattern, 'i');
|
|
6439
6649
|
}
|
|
6440
|
-
function applyAssistantNameRegexToQuery(query) {
|
|
6650
|
+
function applyAssistantNameRegexToQuery(query, fieldContext) {
|
|
6441
6651
|
if (Array.isArray(query)) {
|
|
6652
|
+
if (fieldContext && shouldApplyAssistantNameRegex(fieldContext)) {
|
|
6653
|
+
return query.map(function (entry) {
|
|
6654
|
+
if (typeof entry === 'string') {
|
|
6655
|
+
var trimmed = entry.trim();
|
|
6656
|
+
return trimmed ? buildTokenizedRegex(trimmed) : entry;
|
|
6657
|
+
}
|
|
6658
|
+
return applyAssistantNameRegexToQuery(entry, fieldContext);
|
|
6659
|
+
});
|
|
6660
|
+
}
|
|
6442
6661
|
return query.map(function (entry) { return applyAssistantNameRegexToQuery(entry); });
|
|
6443
6662
|
}
|
|
6444
6663
|
if (!query || typeof query !== 'object' || query instanceof Date || query instanceof RegExp || isMongoObjectId(query)) {
|
|
@@ -6448,7 +6667,7 @@ function applyAssistantNameRegexToQuery(query) {
|
|
|
6448
6667
|
Object.keys(query).forEach(function (key) {
|
|
6449
6668
|
var value = query[key];
|
|
6450
6669
|
if (key.startsWith('$')) {
|
|
6451
|
-
result[key] = applyAssistantNameRegexToQuery(value);
|
|
6670
|
+
result[key] = applyAssistantNameRegexToQuery(value, fieldContext);
|
|
6452
6671
|
return;
|
|
6453
6672
|
}
|
|
6454
6673
|
if (typeof value === 'string' && shouldApplyAssistantNameRegex(key)) {
|
|
@@ -6457,7 +6676,7 @@ function applyAssistantNameRegexToQuery(query) {
|
|
|
6457
6676
|
return;
|
|
6458
6677
|
}
|
|
6459
6678
|
if (value && typeof value === 'object') {
|
|
6460
|
-
result[key] = applyAssistantNameRegexToQuery(value);
|
|
6679
|
+
result[key] = applyAssistantNameRegexToQuery(value, key);
|
|
6461
6680
|
return;
|
|
6462
6681
|
}
|
|
6463
6682
|
result[key] = value;
|
|
@@ -6480,13 +6699,13 @@ function hasOperatorKeys(value) {
|
|
|
6480
6699
|
return Object.keys(value).some(function (key) { return key.startsWith('$'); });
|
|
6481
6700
|
}
|
|
6482
6701
|
function rewriteEmbeddedMatchObjects(query) {
|
|
6483
|
-
var
|
|
6484
|
-
|
|
6702
|
+
var isLogicalOperatorKey = function (key) { return key === '$or' || key === '$and' || key === '$nor'; };
|
|
6703
|
+
var rewriteValue = function (value, allowArrayRewrite, context) {
|
|
6485
6704
|
if (Array.isArray(value)) {
|
|
6486
6705
|
if (!allowArrayRewrite) {
|
|
6487
6706
|
return value;
|
|
6488
6707
|
}
|
|
6489
|
-
return value.map(function (entry) { return rewriteValue(entry, true,
|
|
6708
|
+
return value.map(function (entry) { return rewriteValue(entry, true, context); });
|
|
6490
6709
|
}
|
|
6491
6710
|
if (!value || typeof value !== 'object' || value instanceof Date || value instanceof RegExp || isMongoObjectId(value)) {
|
|
6492
6711
|
return value;
|
|
@@ -6495,38 +6714,39 @@ function rewriteEmbeddedMatchObjects(query) {
|
|
|
6495
6714
|
Object.keys(value).forEach(function (key) {
|
|
6496
6715
|
var entry = value[key];
|
|
6497
6716
|
if (key.startsWith('$')) {
|
|
6498
|
-
|
|
6717
|
+
var nextContext = isLogicalOperatorKey(key) ? 'logical' : 'fieldOperator';
|
|
6718
|
+
result[key] = rewriteValue(entry, true, nextContext);
|
|
6499
6719
|
return;
|
|
6500
6720
|
}
|
|
6501
|
-
if (
|
|
6502
|
-
var flattened = flattenMatchObject(entry, key,
|
|
6721
|
+
if (context !== 'fieldOperator' && isPlainMatchObject(entry) && !Array.isArray(entry) && !hasOperatorKeys(entry)) {
|
|
6722
|
+
var flattened = flattenMatchObject(entry, key, context);
|
|
6503
6723
|
Object.assign(result, flattened);
|
|
6504
6724
|
return;
|
|
6505
6725
|
}
|
|
6506
6726
|
if (isPlainMatchObject(entry) && !Array.isArray(entry)) {
|
|
6507
|
-
result[key] = rewriteValue(entry, true,
|
|
6727
|
+
result[key] = rewriteValue(entry, true, context);
|
|
6508
6728
|
return;
|
|
6509
6729
|
}
|
|
6510
6730
|
if (Array.isArray(entry)) {
|
|
6511
|
-
result[key] = allowArrayRewrite ? entry.map(function (item) { return rewriteValue(item, true,
|
|
6731
|
+
result[key] = allowArrayRewrite ? entry.map(function (item) { return rewriteValue(item, true, context); }) : entry;
|
|
6512
6732
|
return;
|
|
6513
6733
|
}
|
|
6514
6734
|
result[key] = entry;
|
|
6515
6735
|
});
|
|
6516
6736
|
return result;
|
|
6517
6737
|
};
|
|
6518
|
-
var flattenMatchObject = function (value, prefix,
|
|
6738
|
+
var flattenMatchObject = function (value, prefix, context) {
|
|
6519
6739
|
var result = {};
|
|
6520
6740
|
Object.keys(value || {}).forEach(function (key) {
|
|
6521
6741
|
var entry = value[key];
|
|
6522
6742
|
var currentPath = "".concat(prefix, ".").concat(key);
|
|
6523
6743
|
if (isPlainMatchObject(entry) && !Array.isArray(entry) && !hasOperatorKeys(entry)) {
|
|
6524
|
-
var flattened = flattenMatchObject(entry, currentPath,
|
|
6744
|
+
var flattened = flattenMatchObject(entry, currentPath, context);
|
|
6525
6745
|
Object.assign(result, flattened);
|
|
6526
6746
|
return;
|
|
6527
6747
|
}
|
|
6528
6748
|
if (isPlainMatchObject(entry) && !Array.isArray(entry)) {
|
|
6529
|
-
result[currentPath] = rewriteValue(entry, true,
|
|
6749
|
+
result[currentPath] = rewriteValue(entry, true, context);
|
|
6530
6750
|
return;
|
|
6531
6751
|
}
|
|
6532
6752
|
if (Array.isArray(entry)) {
|
|
@@ -6537,7 +6757,7 @@ function rewriteEmbeddedMatchObjects(query) {
|
|
|
6537
6757
|
});
|
|
6538
6758
|
return result;
|
|
6539
6759
|
};
|
|
6540
|
-
return rewriteValue(query, true);
|
|
6760
|
+
return rewriteValue(query, true, 'root');
|
|
6541
6761
|
}
|
|
6542
6762
|
function buildRegexFromCondition(condition) {
|
|
6543
6763
|
if (!condition) {
|
|
@@ -7072,7 +7292,7 @@ function resolveAssistantCollectionName(db, dbName, requested) {
|
|
|
7072
7292
|
});
|
|
7073
7293
|
}
|
|
7074
7294
|
function findQueryDateField(query) {
|
|
7075
|
-
var
|
|
7295
|
+
var e_22, _a, e_23, _b;
|
|
7076
7296
|
if (!query || typeof query !== 'object') {
|
|
7077
7297
|
return null;
|
|
7078
7298
|
}
|
|
@@ -7086,12 +7306,12 @@ function findQueryDateField(query) {
|
|
|
7086
7306
|
}
|
|
7087
7307
|
}
|
|
7088
7308
|
}
|
|
7089
|
-
catch (
|
|
7309
|
+
catch (e_22_1) { e_22 = { error: e_22_1 }; }
|
|
7090
7310
|
finally {
|
|
7091
7311
|
try {
|
|
7092
7312
|
if (query_1_1 && !query_1_1.done && (_a = query_1.return)) _a.call(query_1);
|
|
7093
7313
|
}
|
|
7094
|
-
finally { if (
|
|
7314
|
+
finally { if (e_22) throw e_22.error; }
|
|
7095
7315
|
}
|
|
7096
7316
|
return null;
|
|
7097
7317
|
}
|
|
@@ -7110,12 +7330,12 @@ function findQueryDateField(query) {
|
|
|
7110
7330
|
}
|
|
7111
7331
|
}
|
|
7112
7332
|
}
|
|
7113
|
-
catch (
|
|
7333
|
+
catch (e_23_1) { e_23 = { error: e_23_1 }; }
|
|
7114
7334
|
finally {
|
|
7115
7335
|
try {
|
|
7116
7336
|
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
7117
7337
|
}
|
|
7118
|
-
finally { if (
|
|
7338
|
+
finally { if (e_23) throw e_23.error; }
|
|
7119
7339
|
}
|
|
7120
7340
|
return null;
|
|
7121
7341
|
}
|
|
@@ -7337,7 +7557,7 @@ function resolveQueryDateFieldFallback(query) {
|
|
|
7337
7557
|
return { from: dateField, to: fallback };
|
|
7338
7558
|
}
|
|
7339
7559
|
function containsForbiddenMongoOperators(value) {
|
|
7340
|
-
var
|
|
7560
|
+
var e_24, _a;
|
|
7341
7561
|
if (!value || typeof value !== 'object') {
|
|
7342
7562
|
return false;
|
|
7343
7563
|
}
|
|
@@ -7356,12 +7576,12 @@ function containsForbiddenMongoOperators(value) {
|
|
|
7356
7576
|
}
|
|
7357
7577
|
}
|
|
7358
7578
|
}
|
|
7359
|
-
catch (
|
|
7579
|
+
catch (e_24_1) { e_24 = { error: e_24_1 }; }
|
|
7360
7580
|
finally {
|
|
7361
7581
|
try {
|
|
7362
7582
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
7363
7583
|
}
|
|
7364
|
-
finally { if (
|
|
7584
|
+
finally { if (e_24) throw e_24.error; }
|
|
7365
7585
|
}
|
|
7366
7586
|
return false;
|
|
7367
7587
|
}
|
|
@@ -7652,8 +7872,8 @@ function applyCodexStreamStatusHandler(runOptions, streamStatusHandler) {
|
|
|
7652
7872
|
}
|
|
7653
7873
|
function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
7654
7874
|
return __awaiter(this, void 0, void 0, function () {
|
|
7655
|
-
var _a, _b, _c, _d, message, payload, status_1,
|
|
7656
|
-
var _e,
|
|
7875
|
+
var _a, _b, _c, _d, message, payload, status_1, e_25_1;
|
|
7876
|
+
var _e, e_25, _f, _g;
|
|
7657
7877
|
return __generator(this, function (_h) {
|
|
7658
7878
|
switch (_h.label) {
|
|
7659
7879
|
case 0:
|
|
@@ -7680,8 +7900,8 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
|
7680
7900
|
return [3 /*break*/, 1];
|
|
7681
7901
|
case 4: return [3 /*break*/, 11];
|
|
7682
7902
|
case 5:
|
|
7683
|
-
|
|
7684
|
-
|
|
7903
|
+
e_25_1 = _h.sent();
|
|
7904
|
+
e_25 = { error: e_25_1 };
|
|
7685
7905
|
return [3 /*break*/, 11];
|
|
7686
7906
|
case 6:
|
|
7687
7907
|
_h.trys.push([6, , 9, 10]);
|
|
@@ -7692,7 +7912,7 @@ function waitForCodexWorkerMessage(worker, streamStatusHandler) {
|
|
|
7692
7912
|
_h.label = 8;
|
|
7693
7913
|
case 8: return [3 /*break*/, 10];
|
|
7694
7914
|
case 9:
|
|
7695
|
-
if (
|
|
7915
|
+
if (e_25) throw e_25.error;
|
|
7696
7916
|
return [7 /*endfinally*/];
|
|
7697
7917
|
case 10: return [7 /*endfinally*/];
|
|
7698
7918
|
case 11: throw new CodexWorkerBootstrapError('Codex worker exited before completing.');
|
|
@@ -8300,7 +8520,7 @@ function normalizeRouteMatchKey(value) {
|
|
|
8300
8520
|
return normalizeRouteKey(value).toLowerCase();
|
|
8301
8521
|
}
|
|
8302
8522
|
function buildClientRouteIndex() {
|
|
8303
|
-
var
|
|
8523
|
+
var e_26, _a;
|
|
8304
8524
|
var _b;
|
|
8305
8525
|
var routes = ((_b = resolveio_server_app_1.ResolveIOServer.getClientRoutes) === null || _b === void 0 ? void 0 : _b.call(resolveio_server_app_1.ResolveIOServer)) || [];
|
|
8306
8526
|
var set = new Set();
|
|
@@ -8319,12 +8539,12 @@ function buildClientRouteIndex() {
|
|
|
8319
8539
|
}
|
|
8320
8540
|
}
|
|
8321
8541
|
}
|
|
8322
|
-
catch (
|
|
8542
|
+
catch (e_26_1) { e_26 = { error: e_26_1 }; }
|
|
8323
8543
|
finally {
|
|
8324
8544
|
try {
|
|
8325
8545
|
if (routes_1_1 && !routes_1_1.done && (_a = routes_1.return)) _a.call(routes_1);
|
|
8326
8546
|
}
|
|
8327
|
-
finally { if (
|
|
8547
|
+
finally { if (e_26) throw e_26.error; }
|
|
8328
8548
|
}
|
|
8329
8549
|
return { set: set, map: map, size: routes.length };
|
|
8330
8550
|
}
|
|
@@ -8471,7 +8691,7 @@ function sanitizeAssistantResponse(value) {
|
|
|
8471
8691
|
return normalizeAssistantRoutes(normalizedCurrency);
|
|
8472
8692
|
}
|
|
8473
8693
|
function evaluateAssistantGuardrails(message) {
|
|
8474
|
-
var
|
|
8694
|
+
var e_27, _a;
|
|
8475
8695
|
var normalized = String(message || '').toLowerCase();
|
|
8476
8696
|
var patterns = [
|
|
8477
8697
|
{
|
|
@@ -8517,12 +8737,12 @@ function evaluateAssistantGuardrails(message) {
|
|
|
8517
8737
|
}
|
|
8518
8738
|
}
|
|
8519
8739
|
}
|
|
8520
|
-
catch (
|
|
8740
|
+
catch (e_27_1) { e_27 = { error: e_27_1 }; }
|
|
8521
8741
|
finally {
|
|
8522
8742
|
try {
|
|
8523
8743
|
if (patterns_1_1 && !patterns_1_1.done && (_a = patterns_1.return)) _a.call(patterns_1);
|
|
8524
8744
|
}
|
|
8525
|
-
finally { if (
|
|
8745
|
+
finally { if (e_27) throw e_27.error; }
|
|
8526
8746
|
}
|
|
8527
8747
|
return null;
|
|
8528
8748
|
}
|
|
@@ -8637,7 +8857,7 @@ function tokenizeArithmeticExpression(expression) {
|
|
|
8637
8857
|
return tokens;
|
|
8638
8858
|
}
|
|
8639
8859
|
function evaluateArithmeticExpression(expression) {
|
|
8640
|
-
var
|
|
8860
|
+
var e_28, _a, e_29, _b;
|
|
8641
8861
|
var tokens = tokenizeArithmeticExpression(expression);
|
|
8642
8862
|
if (!tokens || !tokens.length) {
|
|
8643
8863
|
return null;
|
|
@@ -8694,12 +8914,12 @@ function evaluateArithmeticExpression(expression) {
|
|
|
8694
8914
|
prevToken = token;
|
|
8695
8915
|
}
|
|
8696
8916
|
}
|
|
8697
|
-
catch (
|
|
8917
|
+
catch (e_28_1) { e_28 = { error: e_28_1 }; }
|
|
8698
8918
|
finally {
|
|
8699
8919
|
try {
|
|
8700
8920
|
if (tokens_1_1 && !tokens_1_1.done && (_a = tokens_1.return)) _a.call(tokens_1);
|
|
8701
8921
|
}
|
|
8702
|
-
finally { if (
|
|
8922
|
+
finally { if (e_28) throw e_28.error; }
|
|
8703
8923
|
}
|
|
8704
8924
|
while (ops.length) {
|
|
8705
8925
|
var op = ops.pop();
|
|
@@ -8739,12 +8959,12 @@ function evaluateArithmeticExpression(expression) {
|
|
|
8739
8959
|
stack.push(Number(token));
|
|
8740
8960
|
}
|
|
8741
8961
|
}
|
|
8742
|
-
catch (
|
|
8962
|
+
catch (e_29_1) { e_29 = { error: e_29_1 }; }
|
|
8743
8963
|
finally {
|
|
8744
8964
|
try {
|
|
8745
8965
|
if (output_1_1 && !output_1_1.done && (_b = output_1.return)) _b.call(output_1);
|
|
8746
8966
|
}
|
|
8747
|
-
finally { if (
|
|
8967
|
+
finally { if (e_29) throw e_29.error; }
|
|
8748
8968
|
}
|
|
8749
8969
|
if (stack.length !== 1 || Number.isNaN(stack[0])) {
|
|
8750
8970
|
return null;
|
|
@@ -8928,8 +9148,8 @@ function handleCodexUpload(id_conversation, file_name, content_base64, size, con
|
|
|
8928
9148
|
}
|
|
8929
9149
|
function readAttachmentContents(attachments) {
|
|
8930
9150
|
return __awaiter(this, void 0, void 0, function () {
|
|
8931
|
-
var limits, totalBytes, totalChars, chunks, cleaned, attachments_1, attachments_1_1, attachment, localPath, safe, stat, ext, name_1, type, readable, content, _a,
|
|
8932
|
-
var
|
|
9151
|
+
var limits, totalBytes, totalChars, chunks, cleaned, attachments_1, attachments_1_1, attachment, localPath, safe, stat, ext, name_1, type, readable, content, _a, e_30_1;
|
|
9152
|
+
var e_30, _b;
|
|
8933
9153
|
return __generator(this, function (_c) {
|
|
8934
9154
|
switch (_c.label) {
|
|
8935
9155
|
case 0:
|
|
@@ -9008,14 +9228,14 @@ function readAttachmentContents(attachments) {
|
|
|
9008
9228
|
return [3 /*break*/, 2];
|
|
9009
9229
|
case 10: return [3 /*break*/, 13];
|
|
9010
9230
|
case 11:
|
|
9011
|
-
|
|
9012
|
-
|
|
9231
|
+
e_30_1 = _c.sent();
|
|
9232
|
+
e_30 = { error: e_30_1 };
|
|
9013
9233
|
return [3 /*break*/, 13];
|
|
9014
9234
|
case 12:
|
|
9015
9235
|
try {
|
|
9016
9236
|
if (attachments_1_1 && !attachments_1_1.done && (_b = attachments_1.return)) _b.call(attachments_1);
|
|
9017
9237
|
}
|
|
9018
|
-
finally { if (
|
|
9238
|
+
finally { if (e_30) throw e_30.error; }
|
|
9019
9239
|
return [7 /*endfinally*/];
|
|
9020
9240
|
case 13: return [2 /*return*/, {
|
|
9021
9241
|
promptText: chunks.length ? "\n\nAttachments:\n".concat(chunks.join('\n\n')) : '',
|
|
@@ -9203,7 +9423,7 @@ function estimateUsage(messages, responseText, model) {
|
|
|
9203
9423
|
};
|
|
9204
9424
|
}
|
|
9205
9425
|
function evaluateGuardrails(message) {
|
|
9206
|
-
var
|
|
9426
|
+
var e_31, _a;
|
|
9207
9427
|
var normalized = String(message || '').toLowerCase();
|
|
9208
9428
|
var patterns = [
|
|
9209
9429
|
{ pattern: /\b(source\s*code|full\s*code|entire\s*code|repo\s*dump|repository|git\s*clone)\b/i, reason: 'Code access is restricted.' },
|
|
@@ -9225,12 +9445,12 @@ function evaluateGuardrails(message) {
|
|
|
9225
9445
|
}
|
|
9226
9446
|
}
|
|
9227
9447
|
}
|
|
9228
|
-
catch (
|
|
9448
|
+
catch (e_31_1) { e_31 = { error: e_31_1 }; }
|
|
9229
9449
|
finally {
|
|
9230
9450
|
try {
|
|
9231
9451
|
if (patterns_2_1 && !patterns_2_1.done && (_a = patterns_2.return)) _a.call(patterns_2);
|
|
9232
9452
|
}
|
|
9233
|
-
finally { if (
|
|
9453
|
+
finally { if (e_31) throw e_31.error; }
|
|
9234
9454
|
}
|
|
9235
9455
|
return null;
|
|
9236
9456
|
}
|