@resolveio/server-lib 20.9.10 → 20.9.11
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/package.json
CHANGED
|
@@ -62,6 +62,15 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
62
62
|
}
|
|
63
63
|
return ar;
|
|
64
64
|
};
|
|
65
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
66
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
67
|
+
if (ar || !(i in from)) {
|
|
68
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
69
|
+
ar[i] = from[i];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
73
|
+
};
|
|
65
74
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
66
75
|
exports.recordAggregateDependencies = exports.recordDependencyResult = exports.withDependencyTracking = void 0;
|
|
67
76
|
var async_hooks_1 = require("async_hooks");
|
|
@@ -119,6 +128,7 @@ function recordDependencyResult(collection, result, options) {
|
|
|
119
128
|
context.filters.set(collection, filterList);
|
|
120
129
|
}
|
|
121
130
|
filterList.push((0, common_1.deepCopy)(options.filter));
|
|
131
|
+
context.watchAllCollections.delete(collection);
|
|
122
132
|
}
|
|
123
133
|
if (options === null || options === void 0 ? void 0 : options.meta) {
|
|
124
134
|
var metaList = context.queryMetadata.get(collection);
|
|
@@ -134,6 +144,7 @@ function recordDependencyResult(collection, result, options) {
|
|
|
134
144
|
collectIdsFromFilter(options.filter, ids);
|
|
135
145
|
}
|
|
136
146
|
if (ids.size) {
|
|
147
|
+
context.watchAllCollections.delete(collection);
|
|
137
148
|
var existing = context.dependencies.get(collection);
|
|
138
149
|
if (!existing) {
|
|
139
150
|
existing = new Set();
|
|
@@ -159,7 +170,7 @@ function recordDependencyResult(collection, result, options) {
|
|
|
159
170
|
}
|
|
160
171
|
exports.recordDependencyResult = recordDependencyResult;
|
|
161
172
|
function recordAggregateDependencies(collection, pipeline, result) {
|
|
162
|
-
var e_2, _a;
|
|
173
|
+
var e_2, _a, e_3, _b, e_4, _c;
|
|
163
174
|
var context = dependencyStorage.getStore();
|
|
164
175
|
if (!context) {
|
|
165
176
|
return;
|
|
@@ -179,12 +190,61 @@ function recordAggregateDependencies(collection, pipeline, result) {
|
|
|
179
190
|
var target = lookupTargets_1_1.value;
|
|
180
191
|
var nestedValues = [];
|
|
181
192
|
collectLookupValues(result, target.as, nestedValues);
|
|
193
|
+
var rootDocs = Array.isArray(result) ? result : [result];
|
|
194
|
+
var pipelineFilters = [];
|
|
195
|
+
var pipelineUnresolved = false;
|
|
196
|
+
try {
|
|
197
|
+
for (var rootDocs_1 = (e_3 = void 0, __values(rootDocs)), rootDocs_1_1 = rootDocs_1.next(); !rootDocs_1_1.done; rootDocs_1_1 = rootDocs_1.next()) {
|
|
198
|
+
var rootDoc = rootDocs_1_1.value;
|
|
199
|
+
var _d = buildLookupPipelineFilters(rootDoc, target), filtersFromPipeline = _d.filters, unresolved = _d.unresolved;
|
|
200
|
+
if (unresolved) {
|
|
201
|
+
pipelineUnresolved = true;
|
|
202
|
+
}
|
|
203
|
+
if (filtersFromPipeline === null || filtersFromPipeline === void 0 ? void 0 : filtersFromPipeline.length) {
|
|
204
|
+
pipelineFilters.push.apply(pipelineFilters, __spreadArray([], __read(filtersFromPipeline), false));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
209
|
+
finally {
|
|
210
|
+
try {
|
|
211
|
+
if (rootDocs_1_1 && !rootDocs_1_1.done && (_b = rootDocs_1.return)) _b.call(rootDocs_1);
|
|
212
|
+
}
|
|
213
|
+
finally { if (e_3) throw e_3.error; }
|
|
214
|
+
}
|
|
182
215
|
var filter = buildLookupFilter(result, target.localField, target.foreignField);
|
|
183
|
-
|
|
216
|
+
var uniquePipelineFilters = dedupeFilters(pipelineFilters);
|
|
217
|
+
if (nestedValues.length) {
|
|
184
218
|
recordDependencyResult(target.from, nestedValues, filter ? { filter: filter } : undefined);
|
|
185
219
|
}
|
|
186
|
-
|
|
187
|
-
|
|
220
|
+
if (uniquePipelineFilters.length) {
|
|
221
|
+
var pipelineMeta = extractAggregationMetaFromPipeline(target.pipeline);
|
|
222
|
+
try {
|
|
223
|
+
for (var uniquePipelineFilters_1 = (e_4 = void 0, __values(uniquePipelineFilters)), uniquePipelineFilters_1_1 = uniquePipelineFilters_1.next(); !uniquePipelineFilters_1_1.done; uniquePipelineFilters_1_1 = uniquePipelineFilters_1.next()) {
|
|
224
|
+
var pipelineFilter = uniquePipelineFilters_1_1.value;
|
|
225
|
+
recordDependencyResult(target.from, [], { filter: pipelineFilter, meta: pipelineMeta });
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
229
|
+
finally {
|
|
230
|
+
try {
|
|
231
|
+
if (uniquePipelineFilters_1_1 && !uniquePipelineFilters_1_1.done && (_c = uniquePipelineFilters_1.return)) _c.call(uniquePipelineFilters_1);
|
|
232
|
+
}
|
|
233
|
+
finally { if (e_4) throw e_4.error; }
|
|
234
|
+
}
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
if (!nestedValues.length && filter) {
|
|
238
|
+
recordDependencyResult(target.from, [], { filter: filter });
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
if (!nestedValues.length) {
|
|
242
|
+
if (pipelineUnresolved) {
|
|
243
|
+
context.watchAllCollections.add(target.from);
|
|
244
|
+
}
|
|
245
|
+
else if (!target.pipeline || !target.pipeline.length) {
|
|
246
|
+
context.watchAllCollections.add(target.from);
|
|
247
|
+
}
|
|
188
248
|
}
|
|
189
249
|
}
|
|
190
250
|
}
|
|
@@ -198,7 +258,7 @@ function recordAggregateDependencies(collection, pipeline, result) {
|
|
|
198
258
|
}
|
|
199
259
|
exports.recordAggregateDependencies = recordAggregateDependencies;
|
|
200
260
|
function extractLookupTargets(pipeline) {
|
|
201
|
-
var
|
|
261
|
+
var e_5, _a;
|
|
202
262
|
var lookups = [];
|
|
203
263
|
if (!Array.isArray(pipeline)) {
|
|
204
264
|
return lookups;
|
|
@@ -213,23 +273,25 @@ function extractLookupTargets(pipeline) {
|
|
|
213
273
|
from: lookup.from,
|
|
214
274
|
as: lookup.as,
|
|
215
275
|
localField: typeof lookup.localField === 'string' ? lookup.localField : undefined,
|
|
216
|
-
foreignField: typeof lookup.foreignField === 'string' ? lookup.foreignField : undefined
|
|
276
|
+
foreignField: typeof lookup.foreignField === 'string' ? lookup.foreignField : undefined,
|
|
277
|
+
let: lookup.let && typeof lookup.let === 'object' ? lookup.let : undefined,
|
|
278
|
+
pipeline: Array.isArray(lookup.pipeline) ? lookup.pipeline : undefined
|
|
217
279
|
});
|
|
218
280
|
}
|
|
219
281
|
}
|
|
220
282
|
}
|
|
221
283
|
}
|
|
222
|
-
catch (
|
|
284
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
223
285
|
finally {
|
|
224
286
|
try {
|
|
225
287
|
if (pipeline_1_1 && !pipeline_1_1.done && (_a = pipeline_1.return)) _a.call(pipeline_1);
|
|
226
288
|
}
|
|
227
|
-
finally { if (
|
|
289
|
+
finally { if (e_5) throw e_5.error; }
|
|
228
290
|
}
|
|
229
291
|
return lookups;
|
|
230
292
|
}
|
|
231
293
|
function extractMatchFilter(pipeline) {
|
|
232
|
-
var
|
|
294
|
+
var e_6, _a;
|
|
233
295
|
if (!Array.isArray(pipeline)) {
|
|
234
296
|
return null;
|
|
235
297
|
}
|
|
@@ -242,12 +304,12 @@ function extractMatchFilter(pipeline) {
|
|
|
242
304
|
}
|
|
243
305
|
}
|
|
244
306
|
}
|
|
245
|
-
catch (
|
|
307
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
246
308
|
finally {
|
|
247
309
|
try {
|
|
248
310
|
if (pipeline_2_1 && !pipeline_2_1.done && (_a = pipeline_2.return)) _a.call(pipeline_2);
|
|
249
311
|
}
|
|
250
|
-
finally { if (
|
|
312
|
+
finally { if (e_6) throw e_6.error; }
|
|
251
313
|
}
|
|
252
314
|
if (!filters.length) {
|
|
253
315
|
return null;
|
|
@@ -258,7 +320,7 @@ function extractMatchFilter(pipeline) {
|
|
|
258
320
|
return { $and: filters };
|
|
259
321
|
}
|
|
260
322
|
function extractAggregateMeta(pipeline) {
|
|
261
|
-
var
|
|
323
|
+
var e_7, _a;
|
|
262
324
|
if (!Array.isArray(pipeline)) {
|
|
263
325
|
return null;
|
|
264
326
|
}
|
|
@@ -279,12 +341,53 @@ function extractAggregateMeta(pipeline) {
|
|
|
279
341
|
}
|
|
280
342
|
}
|
|
281
343
|
}
|
|
282
|
-
catch (
|
|
344
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
283
345
|
finally {
|
|
284
346
|
try {
|
|
285
347
|
if (pipeline_3_1 && !pipeline_3_1.done && (_a = pipeline_3.return)) _a.call(pipeline_3);
|
|
286
348
|
}
|
|
287
|
-
finally { if (
|
|
349
|
+
finally { if (e_7) throw e_7.error; }
|
|
350
|
+
}
|
|
351
|
+
var meta = {};
|
|
352
|
+
if (limit !== undefined) {
|
|
353
|
+
meta.limit = limit;
|
|
354
|
+
}
|
|
355
|
+
if (skip !== undefined) {
|
|
356
|
+
meta.skip = skip;
|
|
357
|
+
}
|
|
358
|
+
if (sort) {
|
|
359
|
+
meta.sort = sort;
|
|
360
|
+
}
|
|
361
|
+
return Object.keys(meta).length ? meta : null;
|
|
362
|
+
}
|
|
363
|
+
function extractAggregationMetaFromPipeline(pipeline) {
|
|
364
|
+
var e_8, _a;
|
|
365
|
+
if (!Array.isArray(pipeline)) {
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
var limit = undefined;
|
|
369
|
+
var skip = undefined;
|
|
370
|
+
var sort = null;
|
|
371
|
+
try {
|
|
372
|
+
for (var pipeline_4 = __values(pipeline), pipeline_4_1 = pipeline_4.next(); !pipeline_4_1.done; pipeline_4_1 = pipeline_4.next()) {
|
|
373
|
+
var stage = pipeline_4_1.value;
|
|
374
|
+
if ((stage === null || stage === void 0 ? void 0 : stage.$limit) !== undefined && typeof stage.$limit === 'number') {
|
|
375
|
+
limit = stage.$limit;
|
|
376
|
+
}
|
|
377
|
+
else if ((stage === null || stage === void 0 ? void 0 : stage.$skip) !== undefined && typeof stage.$skip === 'number') {
|
|
378
|
+
skip = stage.$skip;
|
|
379
|
+
}
|
|
380
|
+
else if ((stage === null || stage === void 0 ? void 0 : stage.$sort) && typeof stage.$sort === 'object') {
|
|
381
|
+
sort = (0, common_1.deepCopy)(stage.$sort);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
386
|
+
finally {
|
|
387
|
+
try {
|
|
388
|
+
if (pipeline_4_1 && !pipeline_4_1.done && (_a = pipeline_4.return)) _a.call(pipeline_4);
|
|
389
|
+
}
|
|
390
|
+
finally { if (e_8) throw e_8.error; }
|
|
288
391
|
}
|
|
289
392
|
var meta = {};
|
|
290
393
|
if (limit !== undefined) {
|
|
@@ -299,7 +402,7 @@ function extractAggregateMeta(pipeline) {
|
|
|
299
402
|
return Object.keys(meta).length ? meta : null;
|
|
300
403
|
}
|
|
301
404
|
function collectLookupValues(source, path, output) {
|
|
302
|
-
var
|
|
405
|
+
var e_9, _a;
|
|
303
406
|
if (!source) {
|
|
304
407
|
return;
|
|
305
408
|
}
|
|
@@ -310,12 +413,12 @@ function collectLookupValues(source, path, output) {
|
|
|
310
413
|
collectLookupValues(item, path, output);
|
|
311
414
|
}
|
|
312
415
|
}
|
|
313
|
-
catch (
|
|
416
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
314
417
|
finally {
|
|
315
418
|
try {
|
|
316
419
|
if (source_1_1 && !source_1_1.done && (_a = source_1.return)) _a.call(source_1);
|
|
317
420
|
}
|
|
318
|
-
finally { if (
|
|
421
|
+
finally { if (e_9) throw e_9.error; }
|
|
319
422
|
}
|
|
320
423
|
return;
|
|
321
424
|
}
|
|
@@ -326,7 +429,7 @@ function collectLookupValues(source, path, output) {
|
|
|
326
429
|
collectLookupPathValues(source, pathSegments, 0, output);
|
|
327
430
|
}
|
|
328
431
|
function collectLookupPathValues(value, path, index, output) {
|
|
329
|
-
var
|
|
432
|
+
var e_10, _a;
|
|
330
433
|
if (!value) {
|
|
331
434
|
return;
|
|
332
435
|
}
|
|
@@ -347,12 +450,12 @@ function collectLookupPathValues(value, path, index, output) {
|
|
|
347
450
|
}
|
|
348
451
|
}
|
|
349
452
|
}
|
|
350
|
-
catch (
|
|
453
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
351
454
|
finally {
|
|
352
455
|
try {
|
|
353
456
|
if (current_1_1 && !current_1_1.done && (_a = current_1.return)) _a.call(current_1);
|
|
354
457
|
}
|
|
355
|
-
finally { if (
|
|
458
|
+
finally { if (e_10) throw e_10.error; }
|
|
356
459
|
}
|
|
357
460
|
}
|
|
358
461
|
else if (current && typeof current === 'object') {
|
|
@@ -378,7 +481,7 @@ function buildLookupFilter(result, localField, foreignField) {
|
|
|
378
481
|
_a;
|
|
379
482
|
}
|
|
380
483
|
function collectFieldValues(source, path, index, output) {
|
|
381
|
-
var
|
|
484
|
+
var e_11, _a, e_12, _b;
|
|
382
485
|
if (!source) {
|
|
383
486
|
return;
|
|
384
487
|
}
|
|
@@ -389,12 +492,12 @@ function collectFieldValues(source, path, index, output) {
|
|
|
389
492
|
collectFieldValues(item, path, index, output);
|
|
390
493
|
}
|
|
391
494
|
}
|
|
392
|
-
catch (
|
|
495
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
393
496
|
finally {
|
|
394
497
|
try {
|
|
395
498
|
if (source_2_1 && !source_2_1.done && (_a = source_2.return)) _a.call(source_2);
|
|
396
499
|
}
|
|
397
|
-
finally { if (
|
|
500
|
+
finally { if (e_11) throw e_11.error; }
|
|
398
501
|
}
|
|
399
502
|
return;
|
|
400
503
|
}
|
|
@@ -418,12 +521,12 @@ function collectFieldValues(source, path, index, output) {
|
|
|
418
521
|
collectFieldValues(item, path, index + 1, output);
|
|
419
522
|
}
|
|
420
523
|
}
|
|
421
|
-
catch (
|
|
524
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
422
525
|
finally {
|
|
423
526
|
try {
|
|
424
527
|
if (current_2_1 && !current_2_1.done && (_b = current_2.return)) _b.call(current_2);
|
|
425
528
|
}
|
|
426
|
-
finally { if (
|
|
529
|
+
finally { if (e_12) throw e_12.error; }
|
|
427
530
|
}
|
|
428
531
|
}
|
|
429
532
|
else {
|
|
@@ -431,7 +534,7 @@ function collectFieldValues(source, path, index, output) {
|
|
|
431
534
|
}
|
|
432
535
|
}
|
|
433
536
|
function appendFilterValue(output, value) {
|
|
434
|
-
var
|
|
537
|
+
var e_13, _a;
|
|
435
538
|
if (value === undefined || value === null) {
|
|
436
539
|
return;
|
|
437
540
|
}
|
|
@@ -442,19 +545,19 @@ function appendFilterValue(output, value) {
|
|
|
442
545
|
appendFilterValue(output, item);
|
|
443
546
|
}
|
|
444
547
|
}
|
|
445
|
-
catch (
|
|
548
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
446
549
|
finally {
|
|
447
550
|
try {
|
|
448
551
|
if (value_1_1 && !value_1_1.done && (_a = value_1.return)) _a.call(value_1);
|
|
449
552
|
}
|
|
450
|
-
finally { if (
|
|
553
|
+
finally { if (e_13) throw e_13.error; }
|
|
451
554
|
}
|
|
452
555
|
return;
|
|
453
556
|
}
|
|
454
557
|
output.push(value);
|
|
455
558
|
}
|
|
456
559
|
function dedupeFilterValues(values) {
|
|
457
|
-
var
|
|
560
|
+
var e_14, _a;
|
|
458
561
|
var unique = new Map();
|
|
459
562
|
try {
|
|
460
563
|
for (var values_1 = __values(values), values_1_1 = values_1.next(); !values_1_1.done; values_1_1 = values_1.next()) {
|
|
@@ -465,12 +568,12 @@ function dedupeFilterValues(values) {
|
|
|
465
568
|
}
|
|
466
569
|
}
|
|
467
570
|
}
|
|
468
|
-
catch (
|
|
571
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
469
572
|
finally {
|
|
470
573
|
try {
|
|
471
574
|
if (values_1_1 && !values_1_1.done && (_a = values_1.return)) _a.call(values_1);
|
|
472
575
|
}
|
|
473
|
-
finally { if (
|
|
576
|
+
finally { if (e_14) throw e_14.error; }
|
|
474
577
|
}
|
|
475
578
|
return Array.from(unique.values());
|
|
476
579
|
}
|
|
@@ -498,7 +601,7 @@ function serializeFilterValue(value) {
|
|
|
498
601
|
return String(value);
|
|
499
602
|
}
|
|
500
603
|
function collectIdsFromResult(source, ids, visited) {
|
|
501
|
-
var
|
|
604
|
+
var e_15, _a, e_16, _b;
|
|
502
605
|
if (visited === void 0) { visited = new WeakSet(); }
|
|
503
606
|
if (!source) {
|
|
504
607
|
return;
|
|
@@ -510,12 +613,12 @@ function collectIdsFromResult(source, ids, visited) {
|
|
|
510
613
|
collectIdsFromResult(item, ids, visited);
|
|
511
614
|
}
|
|
512
615
|
}
|
|
513
|
-
catch (
|
|
616
|
+
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
514
617
|
finally {
|
|
515
618
|
try {
|
|
516
619
|
if (source_3_1 && !source_3_1.done && (_a = source_3.return)) _a.call(source_3);
|
|
517
620
|
}
|
|
518
|
-
finally { if (
|
|
621
|
+
finally { if (e_15) throw e_15.error; }
|
|
519
622
|
}
|
|
520
623
|
return;
|
|
521
624
|
}
|
|
@@ -539,16 +642,16 @@ function collectIdsFromResult(source, ids, visited) {
|
|
|
539
642
|
}
|
|
540
643
|
}
|
|
541
644
|
}
|
|
542
|
-
catch (
|
|
645
|
+
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
543
646
|
finally {
|
|
544
647
|
try {
|
|
545
648
|
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
546
649
|
}
|
|
547
|
-
finally { if (
|
|
650
|
+
finally { if (e_16) throw e_16.error; }
|
|
548
651
|
}
|
|
549
652
|
}
|
|
550
653
|
function collectIdsFromFilter(filter, ids) {
|
|
551
|
-
var
|
|
654
|
+
var e_17, _a, e_18, _b, e_19, _c;
|
|
552
655
|
if (!filter) {
|
|
553
656
|
return;
|
|
554
657
|
}
|
|
@@ -559,12 +662,12 @@ function collectIdsFromFilter(filter, ids) {
|
|
|
559
662
|
collectIdsFromFilter(item, ids);
|
|
560
663
|
}
|
|
561
664
|
}
|
|
562
|
-
catch (
|
|
665
|
+
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
563
666
|
finally {
|
|
564
667
|
try {
|
|
565
668
|
if (filter_1_1 && !filter_1_1.done && (_a = filter_1.return)) _a.call(filter_1);
|
|
566
669
|
}
|
|
567
|
-
finally { if (
|
|
670
|
+
finally { if (e_17) throw e_17.error; }
|
|
568
671
|
}
|
|
569
672
|
return;
|
|
570
673
|
}
|
|
@@ -581,17 +684,17 @@ function collectIdsFromFilter(filter, ids) {
|
|
|
581
684
|
if (key === '$or' || key === '$and' || key === '$nor') {
|
|
582
685
|
if (Array.isArray(value)) {
|
|
583
686
|
try {
|
|
584
|
-
for (var value_2 = (
|
|
687
|
+
for (var value_2 = (e_19 = void 0, __values(value)), value_2_1 = value_2.next(); !value_2_1.done; value_2_1 = value_2.next()) {
|
|
585
688
|
var item = value_2_1.value;
|
|
586
689
|
collectIdsFromFilter(item, ids);
|
|
587
690
|
}
|
|
588
691
|
}
|
|
589
|
-
catch (
|
|
692
|
+
catch (e_19_1) { e_19 = { error: e_19_1 }; }
|
|
590
693
|
finally {
|
|
591
694
|
try {
|
|
592
695
|
if (value_2_1 && !value_2_1.done && (_c = value_2.return)) _c.call(value_2);
|
|
593
696
|
}
|
|
594
|
-
finally { if (
|
|
697
|
+
finally { if (e_19) throw e_19.error; }
|
|
595
698
|
}
|
|
596
699
|
}
|
|
597
700
|
}
|
|
@@ -600,16 +703,16 @@ function collectIdsFromFilter(filter, ids) {
|
|
|
600
703
|
}
|
|
601
704
|
}
|
|
602
705
|
}
|
|
603
|
-
catch (
|
|
706
|
+
catch (e_18_1) { e_18 = { error: e_18_1 }; }
|
|
604
707
|
finally {
|
|
605
708
|
try {
|
|
606
709
|
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
|
|
607
710
|
}
|
|
608
|
-
finally { if (
|
|
711
|
+
finally { if (e_18) throw e_18.error; }
|
|
609
712
|
}
|
|
610
713
|
}
|
|
611
714
|
function collectIdsFromFilterValue(value, ids) {
|
|
612
|
-
var
|
|
715
|
+
var e_20, _a, e_21, _b;
|
|
613
716
|
if (value === null || value === undefined) {
|
|
614
717
|
return;
|
|
615
718
|
}
|
|
@@ -620,12 +723,12 @@ function collectIdsFromFilterValue(value, ids) {
|
|
|
620
723
|
collectIdsFromFilterValue(item, ids);
|
|
621
724
|
}
|
|
622
725
|
}
|
|
623
|
-
catch (
|
|
726
|
+
catch (e_20_1) { e_20 = { error: e_20_1 }; }
|
|
624
727
|
finally {
|
|
625
728
|
try {
|
|
626
729
|
if (value_3_1 && !value_3_1.done && (_a = value_3.return)) _a.call(value_3);
|
|
627
730
|
}
|
|
628
|
-
finally { if (
|
|
731
|
+
finally { if (e_20) throw e_20.error; }
|
|
629
732
|
}
|
|
630
733
|
return;
|
|
631
734
|
}
|
|
@@ -647,12 +750,12 @@ function collectIdsFromFilterValue(value, ids) {
|
|
|
647
750
|
}
|
|
648
751
|
}
|
|
649
752
|
}
|
|
650
|
-
catch (
|
|
753
|
+
catch (e_21_1) { e_21 = { error: e_21_1 }; }
|
|
651
754
|
finally {
|
|
652
755
|
try {
|
|
653
756
|
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
654
757
|
}
|
|
655
|
-
finally { if (
|
|
758
|
+
finally { if (e_21) throw e_21.error; }
|
|
656
759
|
}
|
|
657
760
|
return;
|
|
658
761
|
}
|
|
@@ -690,7 +793,7 @@ function normalizeId(value) {
|
|
|
690
793
|
return null;
|
|
691
794
|
}
|
|
692
795
|
function cloneDependencyMap(original) {
|
|
693
|
-
var
|
|
796
|
+
var e_22, _a;
|
|
694
797
|
var cloned = new Map();
|
|
695
798
|
try {
|
|
696
799
|
for (var _b = __values(original.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -698,17 +801,17 @@ function cloneDependencyMap(original) {
|
|
|
698
801
|
cloned.set(collection, new Set(ids));
|
|
699
802
|
}
|
|
700
803
|
}
|
|
701
|
-
catch (
|
|
804
|
+
catch (e_22_1) { e_22 = { error: e_22_1 }; }
|
|
702
805
|
finally {
|
|
703
806
|
try {
|
|
704
807
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
705
808
|
}
|
|
706
|
-
finally { if (
|
|
809
|
+
finally { if (e_22) throw e_22.error; }
|
|
707
810
|
}
|
|
708
811
|
return cloned;
|
|
709
812
|
}
|
|
710
813
|
function cloneFilterMap(original) {
|
|
711
|
-
var
|
|
814
|
+
var e_23, _a;
|
|
712
815
|
var cloned = new Map();
|
|
713
816
|
try {
|
|
714
817
|
for (var _b = __values(original.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -716,17 +819,17 @@ function cloneFilterMap(original) {
|
|
|
716
819
|
cloned.set(collection, filters.map(function (filter) { return (0, common_1.deepCopy)(filter); }));
|
|
717
820
|
}
|
|
718
821
|
}
|
|
719
|
-
catch (
|
|
822
|
+
catch (e_23_1) { e_23 = { error: e_23_1 }; }
|
|
720
823
|
finally {
|
|
721
824
|
try {
|
|
722
825
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
723
826
|
}
|
|
724
|
-
finally { if (
|
|
827
|
+
finally { if (e_23) throw e_23.error; }
|
|
725
828
|
}
|
|
726
829
|
return cloned;
|
|
727
830
|
}
|
|
728
831
|
function cloneQueryMetaMap(original) {
|
|
729
|
-
var
|
|
832
|
+
var e_24, _a;
|
|
730
833
|
var cloned = new Map();
|
|
731
834
|
try {
|
|
732
835
|
for (var _b = __values(original.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
@@ -734,14 +837,281 @@ function cloneQueryMetaMap(original) {
|
|
|
734
837
|
cloned.set(collection, metaList.map(function (meta) { return (0, common_1.deepCopy)(meta); }));
|
|
735
838
|
}
|
|
736
839
|
}
|
|
737
|
-
catch (
|
|
840
|
+
catch (e_24_1) { e_24 = { error: e_24_1 }; }
|
|
738
841
|
finally {
|
|
739
842
|
try {
|
|
740
843
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
741
844
|
}
|
|
742
|
-
finally { if (
|
|
845
|
+
finally { if (e_24) throw e_24.error; }
|
|
743
846
|
}
|
|
744
847
|
return cloned;
|
|
745
848
|
}
|
|
849
|
+
function buildLookupPipelineFilters(rootDoc, target) {
|
|
850
|
+
var e_25, _a;
|
|
851
|
+
if (!target.pipeline || !target.pipeline.length) {
|
|
852
|
+
return { filters: [], unresolved: false };
|
|
853
|
+
}
|
|
854
|
+
var matchStages = target.pipeline.map(function (stage) { return ({ stage: stage, base: stage.$match }); }).filter(function (entry) { return entry.base; });
|
|
855
|
+
if (!matchStages.length) {
|
|
856
|
+
return buildLookupPipelineFromStack(target.pipeline, [], rootDoc, target.let);
|
|
857
|
+
}
|
|
858
|
+
var letValuesResult = resolveLetVariables(rootDoc, target.let);
|
|
859
|
+
if (!letValuesResult.resolved) {
|
|
860
|
+
return { filters: [], unresolved: true };
|
|
861
|
+
}
|
|
862
|
+
var combinedMatches = [];
|
|
863
|
+
try {
|
|
864
|
+
for (var matchStages_1 = __values(matchStages), matchStages_1_1 = matchStages_1.next(); !matchStages_1_1.done; matchStages_1_1 = matchStages_1.next()) {
|
|
865
|
+
var base = matchStages_1_1.value.base;
|
|
866
|
+
var substitutionState = { unresolved: false };
|
|
867
|
+
var substituted = substituteLetVariables(base, letValuesResult.values, rootDoc, substitutionState);
|
|
868
|
+
if (substitutionState.unresolved || containsUnresolvedLetReference(substituted)) {
|
|
869
|
+
return { filters: [], unresolved: true };
|
|
870
|
+
}
|
|
871
|
+
combinedMatches.push(substituted);
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
catch (e_25_1) { e_25 = { error: e_25_1 }; }
|
|
875
|
+
finally {
|
|
876
|
+
try {
|
|
877
|
+
if (matchStages_1_1 && !matchStages_1_1.done && (_a = matchStages_1.return)) _a.call(matchStages_1);
|
|
878
|
+
}
|
|
879
|
+
finally { if (e_25) throw e_25.error; }
|
|
880
|
+
}
|
|
881
|
+
if (!combinedMatches.length) {
|
|
882
|
+
return buildLookupPipelineFromStack(target.pipeline, [], rootDoc, target.let);
|
|
883
|
+
}
|
|
884
|
+
if (combinedMatches.length === 1) {
|
|
885
|
+
return { filters: [combinedMatches[0]], unresolved: false };
|
|
886
|
+
}
|
|
887
|
+
return { filters: [{ $and: combinedMatches }], unresolved: false };
|
|
888
|
+
}
|
|
889
|
+
function buildLookupPipelineFromStack(pipeline, initialFilters, rootDoc, letMap) {
|
|
890
|
+
var currentFilters = initialFilters.slice();
|
|
891
|
+
var unresolved = false;
|
|
892
|
+
var entries = pipeline.map(function (stage) { return stage ? Object.keys(stage)[0] : null; });
|
|
893
|
+
for (var i = 0; i < pipeline.length; i++) {
|
|
894
|
+
var stage = pipeline[i];
|
|
895
|
+
var stageType = entries[i];
|
|
896
|
+
if (stageType === '$match' && stage.$match) {
|
|
897
|
+
var letValuesResult = resolveLetVariables(rootDoc, letMap);
|
|
898
|
+
if (!letValuesResult.resolved) {
|
|
899
|
+
unresolved = true;
|
|
900
|
+
break;
|
|
901
|
+
}
|
|
902
|
+
var substitutionState = { unresolved: false };
|
|
903
|
+
var substituted = substituteLetVariables(stage.$match, letValuesResult.values, rootDoc, substitutionState);
|
|
904
|
+
if (substitutionState.unresolved || containsUnresolvedLetReference(substituted)) {
|
|
905
|
+
unresolved = true;
|
|
906
|
+
break;
|
|
907
|
+
}
|
|
908
|
+
currentFilters.push(substituted);
|
|
909
|
+
}
|
|
910
|
+
else if (stageType === '$match') {
|
|
911
|
+
unresolved = true;
|
|
912
|
+
break;
|
|
913
|
+
}
|
|
914
|
+
else if (stageType === '$facet') {
|
|
915
|
+
unresolved = true;
|
|
916
|
+
break;
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
if (!currentFilters.length) {
|
|
920
|
+
return { filters: [], unresolved: unresolved };
|
|
921
|
+
}
|
|
922
|
+
if (currentFilters.length === 1) {
|
|
923
|
+
return { filters: currentFilters, unresolved: unresolved };
|
|
924
|
+
}
|
|
925
|
+
return { filters: [{ $and: currentFilters }], unresolved: unresolved };
|
|
926
|
+
}
|
|
927
|
+
function resolveLetVariables(rootDoc, letMap) {
|
|
928
|
+
var e_26, _a;
|
|
929
|
+
if (!letMap || typeof letMap !== 'object') {
|
|
930
|
+
return { resolved: true, values: {} };
|
|
931
|
+
}
|
|
932
|
+
var values = {};
|
|
933
|
+
try {
|
|
934
|
+
for (var _b = __values(Object.entries(letMap)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
935
|
+
var _d = __read(_c.value, 2), key = _d[0], expression = _d[1];
|
|
936
|
+
var evaluation = evaluateLetExpression(rootDoc, expression);
|
|
937
|
+
if (!evaluation.resolved) {
|
|
938
|
+
return { resolved: false, values: null };
|
|
939
|
+
}
|
|
940
|
+
values[key] = evaluation.value;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
catch (e_26_1) { e_26 = { error: e_26_1 }; }
|
|
944
|
+
finally {
|
|
945
|
+
try {
|
|
946
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
947
|
+
}
|
|
948
|
+
finally { if (e_26) throw e_26.error; }
|
|
949
|
+
}
|
|
950
|
+
return { resolved: true, values: values };
|
|
951
|
+
}
|
|
952
|
+
function evaluateLetExpression(rootDoc, expression) {
|
|
953
|
+
if (typeof expression === 'string') {
|
|
954
|
+
if (expression.startsWith('$$ROOT.')) {
|
|
955
|
+
var path = expression.slice('$$ROOT.'.length);
|
|
956
|
+
return { resolved: true, value: getValueByPath(rootDoc, path) };
|
|
957
|
+
}
|
|
958
|
+
else if (expression === '$$ROOT') {
|
|
959
|
+
return { resolved: true, value: rootDoc };
|
|
960
|
+
}
|
|
961
|
+
else if (expression.startsWith('$$')) {
|
|
962
|
+
return { resolved: false, value: null };
|
|
963
|
+
}
|
|
964
|
+
else if (expression.startsWith('$')) {
|
|
965
|
+
var path = expression.slice(1);
|
|
966
|
+
return { resolved: true, value: getValueByPath(rootDoc, path) };
|
|
967
|
+
}
|
|
968
|
+
else {
|
|
969
|
+
return { resolved: true, value: expression };
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
else if (Array.isArray(expression)) {
|
|
973
|
+
return { resolved: false, value: null };
|
|
974
|
+
}
|
|
975
|
+
else if (expression && typeof expression === 'object') {
|
|
976
|
+
return { resolved: false, value: null };
|
|
977
|
+
}
|
|
978
|
+
return { resolved: true, value: expression };
|
|
979
|
+
}
|
|
980
|
+
function substituteLetVariables(node, letValues, rootDoc, state) {
|
|
981
|
+
var e_27, _a;
|
|
982
|
+
if (Array.isArray(node)) {
|
|
983
|
+
return node.map(function (item) { return substituteLetVariables(item, letValues, rootDoc, state); });
|
|
984
|
+
}
|
|
985
|
+
if (node && typeof node === 'object') {
|
|
986
|
+
var output = {};
|
|
987
|
+
try {
|
|
988
|
+
for (var _b = __values(Object.entries(node)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
989
|
+
var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
|
|
990
|
+
output[key] = substituteLetVariables(value, letValues, rootDoc, state);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
catch (e_27_1) { e_27 = { error: e_27_1 }; }
|
|
994
|
+
finally {
|
|
995
|
+
try {
|
|
996
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
997
|
+
}
|
|
998
|
+
finally { if (e_27) throw e_27.error; }
|
|
999
|
+
}
|
|
1000
|
+
return output;
|
|
1001
|
+
}
|
|
1002
|
+
if (typeof node === 'string') {
|
|
1003
|
+
if (node.startsWith('$$ROOT.')) {
|
|
1004
|
+
var path = node.slice('$$ROOT.'.length);
|
|
1005
|
+
return getValueByPath(rootDoc, path);
|
|
1006
|
+
}
|
|
1007
|
+
if (node === '$$ROOT') {
|
|
1008
|
+
return rootDoc;
|
|
1009
|
+
}
|
|
1010
|
+
if (node.startsWith('$$')) {
|
|
1011
|
+
var varName = node.slice(2);
|
|
1012
|
+
if (Object.prototype.hasOwnProperty.call(letValues, varName)) {
|
|
1013
|
+
return letValues[varName];
|
|
1014
|
+
}
|
|
1015
|
+
state.unresolved = true;
|
|
1016
|
+
return node;
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
return node;
|
|
1020
|
+
}
|
|
1021
|
+
function containsUnresolvedLetReference(node) {
|
|
1022
|
+
if (typeof node === 'string') {
|
|
1023
|
+
return node.includes('$$');
|
|
1024
|
+
}
|
|
1025
|
+
if (Array.isArray(node)) {
|
|
1026
|
+
return node.some(function (item) { return containsUnresolvedLetReference(item); });
|
|
1027
|
+
}
|
|
1028
|
+
if (node && typeof node === 'object') {
|
|
1029
|
+
return Object.values(node).some(function (value) { return containsUnresolvedLetReference(value); });
|
|
1030
|
+
}
|
|
1031
|
+
return false;
|
|
1032
|
+
}
|
|
1033
|
+
function getValueByPath(source, path) {
|
|
1034
|
+
var e_28, _a;
|
|
1035
|
+
if (!source || !path) {
|
|
1036
|
+
return undefined;
|
|
1037
|
+
}
|
|
1038
|
+
var segments = path.split('.');
|
|
1039
|
+
var current = source;
|
|
1040
|
+
try {
|
|
1041
|
+
for (var segments_1 = __values(segments), segments_1_1 = segments_1.next(); !segments_1_1.done; segments_1_1 = segments_1.next()) {
|
|
1042
|
+
var segment = segments_1_1.value;
|
|
1043
|
+
if (current === null || current === undefined) {
|
|
1044
|
+
return undefined;
|
|
1045
|
+
}
|
|
1046
|
+
if (Array.isArray(current)) {
|
|
1047
|
+
var index = parseInt(segment, 10);
|
|
1048
|
+
if (isNaN(index) || index < 0 || index >= current.length) {
|
|
1049
|
+
return undefined;
|
|
1050
|
+
}
|
|
1051
|
+
current = current[index];
|
|
1052
|
+
}
|
|
1053
|
+
else {
|
|
1054
|
+
current = current[segment];
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
catch (e_28_1) { e_28 = { error: e_28_1 }; }
|
|
1059
|
+
finally {
|
|
1060
|
+
try {
|
|
1061
|
+
if (segments_1_1 && !segments_1_1.done && (_a = segments_1.return)) _a.call(segments_1);
|
|
1062
|
+
}
|
|
1063
|
+
finally { if (e_28) throw e_28.error; }
|
|
1064
|
+
}
|
|
1065
|
+
return current;
|
|
1066
|
+
}
|
|
1067
|
+
function canonicalizeFilter(filter) {
|
|
1068
|
+
return JSON.stringify(sortKeys(filter));
|
|
1069
|
+
}
|
|
1070
|
+
function sortKeys(value) {
|
|
1071
|
+
var e_29, _a;
|
|
1072
|
+
if (Array.isArray(value)) {
|
|
1073
|
+
return value.map(function (item) { return sortKeys(item); });
|
|
1074
|
+
}
|
|
1075
|
+
if (value && typeof value === 'object') {
|
|
1076
|
+
var sorted = {};
|
|
1077
|
+
var keys = Object.keys(value).sort();
|
|
1078
|
+
try {
|
|
1079
|
+
for (var keys_1 = __values(keys), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
|
|
1080
|
+
var key = keys_1_1.value;
|
|
1081
|
+
sorted[key] = sortKeys(value[key]);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
catch (e_29_1) { e_29 = { error: e_29_1 }; }
|
|
1085
|
+
finally {
|
|
1086
|
+
try {
|
|
1087
|
+
if (keys_1_1 && !keys_1_1.done && (_a = keys_1.return)) _a.call(keys_1);
|
|
1088
|
+
}
|
|
1089
|
+
finally { if (e_29) throw e_29.error; }
|
|
1090
|
+
}
|
|
1091
|
+
return sorted;
|
|
1092
|
+
}
|
|
1093
|
+
return value;
|
|
1094
|
+
}
|
|
1095
|
+
function dedupeFilters(filters) {
|
|
1096
|
+
var e_30, _a;
|
|
1097
|
+
var map = new Map();
|
|
1098
|
+
try {
|
|
1099
|
+
for (var filters_1 = __values(filters), filters_1_1 = filters_1.next(); !filters_1_1.done; filters_1_1 = filters_1.next()) {
|
|
1100
|
+
var filter = filters_1_1.value;
|
|
1101
|
+
var key = canonicalizeFilter(filter);
|
|
1102
|
+
if (!map.has(key)) {
|
|
1103
|
+
map.set(key, filter);
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
catch (e_30_1) { e_30 = { error: e_30_1 }; }
|
|
1108
|
+
finally {
|
|
1109
|
+
try {
|
|
1110
|
+
if (filters_1_1 && !filters_1_1.done && (_a = filters_1.return)) _a.call(filters_1);
|
|
1111
|
+
}
|
|
1112
|
+
finally { if (e_30) throw e_30.error; }
|
|
1113
|
+
}
|
|
1114
|
+
return Array.from(map.values());
|
|
1115
|
+
}
|
|
746
1116
|
|
|
747
1117
|
//# sourceMappingURL=subscription-dependency-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/util/subscription-dependency-context.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAgD;AAChD,mCAAoC;AAwBpC,IAAM,iBAAiB,GAAG,IAAI,+BAAiB,EAAqB,CAAC;AAErE,SAAsB,sBAAsB,CAAI,EAAoB;;;;;;;oBAC7D,OAAO,GAAsB;wBAClC,YAAY,EAAE,IAAI,GAAG,EAAE;wBACvB,OAAO,EAAE,IAAI,GAAG,EAAE;wBAClB,mBAAmB,EAAE,IAAI,GAAG,EAAE;wBAC9B,aAAa,EAAE,IAAI,GAAG,EAAE;qBACxB,CAAC;oBAIF,qBAAM,iBAAiB,CAAC,GAAG,CAAC,OAAO,EAAE;;;4CAC3B,qBAAM,EAAE,E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AA,gBAAA,4BAAE;YAA9C,IAAA,KAAA,mBAAsB,EAArB,UAAU,QAAA,EAAE,QAAQ,QAAA;YAC/B,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG,CAAC,UAAA,IAAI,IAAI,OAAA,IAAA,iBAAQ,EAAC,IAAI,CAAC,EAAd,CAAc,CAAC,CAAC,CAAC;SAC7D;;;;;;;;;IAED,OAAO,MAAM,CAAC;AACf,CAAC","file":"subscription-dependency-context.js","sourcesContent":["import { AsyncLocalStorage } from 'async_hooks';\nimport { deepCopy } from './common';\n\nexport interface QueryMeta {\n\tlimit?: number;\n\tskip?: number;\n\tsort?: any;\n}\n\nexport interface DependencyContextSnapshot {\n\tdependencies: Map<string, Set<string>>;\n\tfilters: Map<string, any[]>;\n\twatchAllCollections: Set<string>;\n\tqueryMetadata: Map<string, QueryMeta[]>;\n}\n\ninterface LookupTarget {\n\tfrom: string;\n\tas: string;\n\tlocalField?: string;\n\tforeignField?: string;\n}\n\ninterface DependencyContext extends DependencyContextSnapshot {}\n\nconst dependencyStorage = new AsyncLocalStorage<DependencyContext>();\n\nexport async function withDependencyTracking<T>(fn: () => Promise<T>): Promise<{ result: T; snapshot: DependencyContextSnapshot }> {\n\tconst context: DependencyContext = {\n\t\tdependencies: new Map(),\n\t\tfilters: new Map(),\n\t\twatchAllCollections: new Set(),\n\t\tqueryMetadata: new Map()\n\t};\n\n\tlet result: T;\n\n\tawait dependencyStorage.run(context, async () => {\n\t\tresult = await fn();\n\t});\n\n\treturn {\n\t\tresult,\n\t\tsnapshot: {\n\t\t\tdependencies: cloneDependencyMap(context.dependencies),\n\t\t\tfilters: cloneFilterMap(context.filters),\n\t\t\twatchAllCollections: new Set(context.watchAllCollections),\n\t\t\tqueryMetadata: cloneQueryMetaMap(context.queryMetadata)\n\t\t}\n\t};\n}\n\nexport function recordDependencyResult(collection: string, result: unknown, options?: { filter?: any, meta?: QueryMeta }) {\n\tconst context = dependencyStorage.getStore();\n\n\tif (!context) {\n\t\treturn;\n\t}\n\n\tif (options?.filter) {\n\t\tlet filterList = context.filters.get(collection);\n\n\t\tif (!filterList) {\n\t\t\tfilterList = [];\n\t\t\tcontext.filters.set(collection, filterList);\n\t\t}\n\n\t\tfilterList.push(deepCopy(options.filter));\n\t}\n\n\tif (options?.meta) {\n\t\tlet metaList = context.queryMetadata.get(collection);\n\n\t\tif (!metaList) {\n\t\t\tmetaList = [];\n\t\t\tcontext.queryMetadata.set(collection, metaList);\n\t\t}\n\n\t\tmetaList.push(deepCopy(options.meta));\n\t}\n\n\tconst ids = new Set<string>();\n\tcollectIdsFromResult(result, ids);\n\n\tif (!ids.size && options?.filter) {\n\t\tcollectIdsFromFilter(options.filter, ids);\n\t}\n\n\tif (ids.size) {\n\t\tlet existing = context.dependencies.get(collection);\n\n\t\tif (!existing) {\n\t\t\texisting = new Set();\n\t\t\tcontext.dependencies.set(collection, existing);\n\t\t}\n\n\t\tfor (const id of ids) {\n\t\t\texisting.add(id);\n\t\t}\n\t}\n\telse if (!options?.filter) {\n\t\tcontext.watchAllCollections.add(collection);\n\t}\n}\n\nexport function recordAggregateDependencies(collection: string, pipeline: any[], result: unknown) {\n\tconst context = dependencyStorage.getStore();\n\n\tif (!context) {\n\t\treturn;\n\t}\n\n\tconst matchFilter = extractMatchFilter(pipeline);\n\tconst meta = extractAggregateMeta(pipeline);\n\trecordDependencyResult(collection, result, {\n\t\tfilter: matchFilter,\n\t\tmeta\n\t});\n\n\tconst lookupTargets = extractLookupTargets(pipeline);\n\n\tif (!lookupTargets.length) {\n\t\treturn;\n\t}\n\n\tfor (const target of lookupTargets) {\n\t\tconst nestedValues: unknown[] = [];\n\t\tcollectLookupValues(result, target.as, nestedValues);\n\n\t\tconst filter = buildLookupFilter(result, target.localField, target.foreignField);\n\n\t\tif (nestedValues.length || filter) {\n\t\t\trecordDependencyResult(target.from, nestedValues, filter ? { filter } : undefined);\n\t\t}\n\t\telse {\n\t\t\tcontext.watchAllCollections.add(target.from);\n\t\t}\n\t}\n}\n\nfunction extractLookupTargets(pipeline: any[]): LookupTarget[] {\n\tconst lookups: LookupTarget[] = [];\n\n\tif (!Array.isArray(pipeline)) {\n\t\treturn lookups;\n\t}\n\n\tfor (const stage of pipeline) {\n\t\tif (stage && stage.$lookup && typeof stage.$lookup === 'object') {\n\t\t\tconst lookup = stage.$lookup;\n\t\t\tif (typeof lookup.from === 'string' && typeof lookup.as === 'string') {\n\t\t\t\tlookups.push({\n\t\t\t\t\tfrom: lookup.from,\n\t\t\t\t\tas: lookup.as,\n\t\t\t\t\tlocalField: typeof lookup.localField === 'string' ? lookup.localField : undefined,\n\t\t\t\t\tforeignField: typeof lookup.foreignField === 'string' ? lookup.foreignField : undefined\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\treturn lookups;\n}\n\nfunction extractMatchFilter(pipeline: any[]): any {\n\tif (!Array.isArray(pipeline)) {\n\t\treturn null;\n\t}\n\n\tconst filters: any[] = [];\n\n\tfor (const stage of pipeline) {\n\t\tif (stage && stage.$match && typeof stage.$match === 'object') {\n\t\t\tfilters.push(deepCopy(stage.$match));\n\t\t}\n\t}\n\n\tif (!filters.length) {\n\t\treturn null;\n\t}\n\n\tif (filters.length === 1) {\n\t\treturn filters[0];\n\t}\n\n\treturn { $and: filters };\n}\n\nfunction extractAggregateMeta(pipeline: any[]): QueryMeta {\n\tif (!Array.isArray(pipeline)) {\n\t\treturn null;\n\t}\n\n\tlet limit = undefined;\n\tlet skip = undefined;\n\tlet sort = null;\n\n\tfor (const stage of pipeline) {\n\t\tif (stage?.$limit !== undefined && typeof stage.$limit === 'number') {\n\t\t\tlimit = stage.$limit;\n\t\t}\n\t\telse if (stage?.$skip !== undefined && typeof stage.$skip === 'number') {\n\t\t\tskip = stage.$skip;\n\t\t}\n\t\telse if (stage?.$sort && typeof stage.$sort === 'object') {\n\t\t\tsort = deepCopy(stage.$sort);\n\t\t}\n\t}\n\n\tconst meta: QueryMeta = {};\n\n\tif (limit !== undefined) {\n\t\tmeta.limit = limit;\n\t}\n\n\tif (skip !== undefined) {\n\t\tmeta.skip = skip;\n\t}\n\n\tif (sort) {\n\t\tmeta.sort = sort;\n\t}\n\n\treturn Object.keys(meta).length ? meta : null;\n}\n\nfunction collectLookupValues(source: unknown, path: string, output: unknown[]) {\n\tif (!source) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(source)) {\n\t\tfor (const item of source) {\n\t\t\tcollectLookupValues(item, path, output);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (typeof source !== 'object') {\n\t\treturn;\n\t}\n\n\tconst pathSegments = path.split('.');\n\tcollectLookupPathValues(source as Record<string, unknown>, pathSegments, 0, output);\n}\n\nfunction collectLookupPathValues(value: Record<string, unknown>, path: string[], index: number, output: unknown[]) {\n\tif (!value) {\n\t\treturn;\n\t}\n\n\tconst current = value[path[index]];\n\n\tif (current === undefined) {\n\t\treturn;\n\t}\n\n\tif (index === path.length - 1) {\n\t\toutput.push(current);\n\t\treturn;\n\t}\n\n\tif (Array.isArray(current)) {\n\t\tfor (const item of current) {\n\t\t\tif (item && typeof item === 'object') {\n\t\t\t\tcollectLookupPathValues(item as Record<string, unknown>, path, index + 1, output);\n\t\t\t}\n\t\t}\n\t}\n\telse if (current && typeof current === 'object') {\n\t\tcollectLookupPathValues(current as Record<string, unknown>, path, index + 1, output);\n\t}\n}\n\nfunction buildLookupFilter(result: unknown, localField?: string, foreignField?: string) {\n\tif (!localField || !foreignField) {\n\t\treturn null;\n\t}\n\n\tconst values: any[] = [];\n\tconst segments = localField.split('.');\n\tcollectFieldValues(result, segments, 0, values);\n\n\tconst uniqueValues = dedupeFilterValues(values);\n\n\tif (!uniqueValues.length) {\n\t\treturn null;\n\t}\n\n\treturn {\n\t\t[foreignField]: {\n\t\t\t$in: uniqueValues\n\t\t}\n\t};\n}\n\nfunction collectFieldValues(source: unknown, path: string[], index: number, output: any[]) {\n\tif (!source) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(source)) {\n\t\tfor (const item of source) {\n\t\t\tcollectFieldValues(item, path, index, output);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (typeof source !== 'object') {\n\t\treturn;\n\t}\n\n\tconst obj = source as Record<string, unknown>;\n\tconst key = path[index];\n\tconst current = obj[key];\n\n\tif (current === undefined) {\n\t\treturn;\n\t}\n\n\tif (index === path.length - 1) {\n\t\tappendFilterValue(output, current);\n\t\treturn;\n\t}\n\n\tif (Array.isArray(current)) {\n\t\tfor (const item of current) {\n\t\t\tcollectFieldValues(item, path, index + 1, output);\n\t\t}\n\t}\n\telse {\n\t\tcollectFieldValues(current, path, index + 1, output);\n\t}\n}\n\nfunction appendFilterValue(output: any[], value: any) {\n\tif (value === undefined || value === null) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(value)) {\n\t\tfor (const item of value) {\n\t\t\tappendFilterValue(output, item);\n\t\t}\n\t\treturn;\n\t}\n\n\toutput.push(value);\n}\n\nfunction dedupeFilterValues(values: any[]): any[] {\n\tconst unique = new Map<string, any>();\n\n\tfor (const value of values) {\n\t\tconst key = serializeFilterValue(value);\n\t\tif (!unique.has(key)) {\n\t\t\tunique.set(key, value);\n\t\t}\n\t}\n\n\treturn Array.from(unique.values());\n}\n\nfunction serializeFilterValue(value: any): string {\n\tif (value === null || value === undefined) {\n\t\treturn 'null';\n\t}\n\n\tif (typeof value === 'object') {\n\t\tif (typeof value.toHexString === 'function') {\n\t\t\treturn value.toHexString();\n\t\t}\n\n\t\tif (value instanceof Date) {\n\t\t\treturn value.toISOString();\n\t\t}\n\n\t\tif (typeof value.toString === 'function' && value.toString !== Object.prototype.toString) {\n\t\t\treturn value.toString();\n\t\t}\n\n\t\ttry {\n\t\t\treturn JSON.stringify(value);\n\t\t}\n\t\tcatch {\n\t\t\treturn '[object]';\n\t\t}\n\t}\n\n\treturn String(value);\n}\n\nfunction collectIdsFromResult(source: unknown, ids: Set<string>, visited = new WeakSet<object>()) {\n\tif (!source) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(source)) {\n\t\tfor (const item of source) {\n\t\t\tcollectIdsFromResult(item, ids, visited);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (typeof source !== 'object') {\n\t\treturn;\n\t}\n\n\tconst objectSource = source as Record<string, unknown>;\n\n\tif (visited.has(objectSource)) {\n\t\treturn;\n\t}\n\n\tvisited.add(objectSource);\n\n\tconst normalizedId = normalizeId(objectSource._id);\n\n\tif (normalizedId) {\n\t\tids.add(normalizedId);\n\t}\n\n\tfor (const value of Object.values(objectSource)) {\n\t\tif (value && (typeof value === 'object' || Array.isArray(value))) {\n\t\t\tcollectIdsFromResult(value, ids, visited);\n\t\t}\n\t}\n}\n\nfunction collectIdsFromFilter(filter: unknown, ids: Set<string>) {\n\tif (!filter) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(filter)) {\n\t\tfor (const item of filter) {\n\t\t\tcollectIdsFromFilter(item, ids);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (typeof filter !== 'object') {\n\t\treturn;\n\t}\n\n\tconst filterObject = filter as Record<string, unknown>;\n\n\tif (filterObject._id !== undefined) {\n\t\tcollectIdsFromFilterValue(filterObject._id, ids);\n\t}\n\n\tfor (const [key, value] of Object.entries(filterObject)) {\n\t\tif (key === '$or' || key === '$and' || key === '$nor') {\n\t\t\tif (Array.isArray(value)) {\n\t\t\t\tfor (const item of value) {\n\t\t\t\t\tcollectIdsFromFilter(item, ids);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse if (key !== '_id' && value && typeof value === 'object') {\n\t\t\tcollectIdsFromFilter(value, ids);\n\t\t}\n\t}\n}\n\nfunction collectIdsFromFilterValue(value: unknown, ids: Set<string>) {\n\tif (value === null || value === undefined) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(value)) {\n\t\tfor (const item of value) {\n\t\t\tcollectIdsFromFilterValue(item, ids);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (typeof value === 'object') {\n\t\tfor (const [key, inner] of Object.entries(value as Record<string, unknown>)) {\n\t\t\tif (key === '$in' || key === '$nin' || key === '$all') {\n\t\t\t\tcollectIdsFromFilterValue(inner, ids);\n\t\t\t}\n\t\t\telse if (key === '$eq' || key === '$ne') {\n\t\t\t\tcollectIdsFromFilterValue(inner, ids);\n\t\t\t}\n\t\t\telse if (key === '$or' || key === '$and' || key === '$nor') {\n\t\t\t\tcollectIdsFromFilterValue(inner, ids);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcollectIdsFromFilterValue(inner, ids);\n\t\t\t}\n\t\t}\n\t\treturn;\n\t}\n\n\tconst normalized = normalizeId(value);\n\n\tif (normalized) {\n\t\tids.add(normalized);\n\t}\n}\n\nfunction normalizeId(value: unknown): string {\n\tif (value === null || value === undefined) {\n\t\treturn null;\n\t}\n\n\tif (typeof value === 'string') {\n\t\tconst trimmed = value.trim();\n\t\treturn trimmed.length ? trimmed : null;\n\t}\n\n\tif (typeof value === 'number' || typeof value === 'bigint') {\n\t\treturn value.toString();\n\t}\n\n\tif (typeof value === 'object') {\n\t\tconst objValue = value as { toHexString?: () => string, toString?: () => string };\n\n\t\tif (typeof objValue.toHexString === 'function') {\n\t\t\treturn objValue.toHexString();\n\t\t}\n\n\t\tif (value instanceof Date) {\n\t\t\treturn value.toISOString();\n\t\t}\n\n\t\tif (typeof objValue.toString === 'function') {\n\t\t\tconst str = objValue.toString();\n\t\t\tif (str && str !== '[object Object]') {\n\t\t\t\treturn str;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn null;\n}\n\nfunction cloneDependencyMap(original: Map<string, Set<string>>): Map<string, Set<string>> {\n\tconst cloned = new Map<string, Set<string>>();\n\n\tfor (const [collection, ids] of original.entries()) {\n\t\tcloned.set(collection, new Set(ids));\n\t}\n\n\treturn cloned;\n}\n\nfunction cloneFilterMap(original: Map<string, any[]>): Map<string, any[]> {\n\tconst cloned = new Map<string, any[]>();\n\n\tfor (const [collection, filters] of original.entries()) {\n\t\tcloned.set(collection, filters.map(filter => deepCopy(filter)));\n\t}\n\n\treturn cloned;\n}\n\nfunction cloneQueryMetaMap(original: Map<string, QueryMeta[]>): Map<string, QueryMeta[]> {\n\tconst cloned = new Map<string, QueryMeta[]>();\n\n\tfor (const [collection, metaList] of original.entries()) {\n\t\tcloned.set(collection, metaList.map(meta => deepCopy(meta)));\n\t}\n\n\treturn cloned;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/util/subscription-dependency-context.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAgD;AAChD,mCAAoC;AA0BpC,IAAM,iBAAiB,GAAG,IAAI,+BAAiB,EAAqB,CAAC;AAErE,SAAsB,sBAAsB,CAAI,EAAoB;;;;;;;oBAC7D,OAAO,GAAsB;wBAClC,YAAY,EAAE,IAAI,GAAG,EAAE;wBACvB,OAAO,EAAE,IAAI,GAAG,EAAE;wBAClB,mBAAmB,EAAE,IAAI,GAAG,EAAE;wBAC9B,aAAa,EAAE,IAAI,GAAG,EAAE;qBACxB,CAAC;oBAIF,qBAAM,iBAAiB,CAAC,GAAG,CAAC,OAAO,EAAE;;;4CAC3B,qBAAM,EAAE,EAAE,EAAA;;wCAAnB,MAAM,GAAG,SAAU,CAAC;;;;6BACpB,CAAC,EAAA;;oBAFF,SAEE,CAAC;oBAEH,sBAAO;4BACN,MAAM,QAAA;4BACN,QAAQ,EAAE;gCACT,YAAY,EAAE,kBAAkB,CAAC,OAAO,CAAC,YAAY,CAAC;gCACtD,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC;gCACxC,mBAAmB,EAAE,IAAI,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC;gCACzD,aAAa,EAAE,iBAAiB,CAAC,OAAO,CAAC,aAAa,CAAC;6BACvD;yBACD,EAAC;;;;CACF;AAvBD,wDAuBC;AAED,SAAgB,sBAAsB,CAAC,UAAkB,EAAE,MAAe,EAAE,OAA4C;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ACtC,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,QAAQ,CAAC,KAAU;;IAC3B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACzB,OAAO,KAAK,CAAC,GAAG,CAAC,UAAA,IAAI,IAAI,OAAA,QAAQ,CAAC,IAAI,CAAC,EAAd,CAAc,CAAC,CAAC;KACzC;IAED,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QACvC,IAAM,MAAM,GAAG,EAAE,CAAC;QAClB,IAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;;YAEvC,KAAkB,IAAA,SAAA,SAAA,IAAI,CAAA,0BAAA,4CAAE;gBAAnB,IAAM,GAAG,iBAAA;gBACb,MAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;aACnC;;;;;;;;;QAED,OAAO,MAAM,CAAC;KACd;IAED,OAAO,KAAK,CAAC;AACd,CAAC;AAED,SAAS,aAAa,CAAC,OAAc;;IACpC,IAAM,GAAG,GAAG,IAAI,GAAG,EAAe,CAAC;;QAEnC,KAAqB,IAAA,YAAA,SAAA,OAAO,CAAA,gCAAA,qDAAE;YAAzB,IAAM,MAAM,oBAAA;YAChB,IAAM,GAAG,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;YAEvC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;gBAClB,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;aACrB;SACD;;;;;;;;;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;AACjC,CAAC","file":"subscription-dependency-context.js","sourcesContent":["import { AsyncLocalStorage } from 'async_hooks';\nimport { deepCopy } from './common';\n\nexport interface QueryMeta {\n\tlimit?: number;\n\tskip?: number;\n\tsort?: any;\n}\n\nexport interface DependencyContextSnapshot {\n\tdependencies: Map<string, Set<string>>;\n\tfilters: Map<string, any[]>;\n\twatchAllCollections: Set<string>;\n\tqueryMetadata: Map<string, QueryMeta[]>;\n}\n\ninterface LookupTarget {\n\tfrom: string;\n\tas: string;\n\tlocalField?: string;\n\tforeignField?: string;\n\tlet?: Record<string, any>;\n\tpipeline?: any[];\n}\n\ninterface DependencyContext extends DependencyContextSnapshot {}\n\nconst dependencyStorage = new AsyncLocalStorage<DependencyContext>();\n\nexport async function withDependencyTracking<T>(fn: () => Promise<T>): Promise<{ result: T; snapshot: DependencyContextSnapshot }> {\n\tconst context: DependencyContext = {\n\t\tdependencies: new Map(),\n\t\tfilters: new Map(),\n\t\twatchAllCollections: new Set(),\n\t\tqueryMetadata: new Map()\n\t};\n\n\tlet result: T;\n\n\tawait dependencyStorage.run(context, async () => {\n\t\tresult = await fn();\n\t});\n\n\treturn {\n\t\tresult,\n\t\tsnapshot: {\n\t\t\tdependencies: cloneDependencyMap(context.dependencies),\n\t\t\tfilters: cloneFilterMap(context.filters),\n\t\t\twatchAllCollections: new Set(context.watchAllCollections),\n\t\t\tqueryMetadata: cloneQueryMetaMap(context.queryMetadata)\n\t\t}\n\t};\n}\n\nexport function recordDependencyResult(collection: string, result: unknown, options?: { filter?: any, meta?: QueryMeta }) {\n\tconst context = dependencyStorage.getStore();\n\n\tif (!context) {\n\t\treturn;\n\t}\n\n\tif (options?.filter) {\n\t\tlet filterList = context.filters.get(collection);\n\n\t\tif (!filterList) {\n\t\t\tfilterList = [];\n\t\t\tcontext.filters.set(collection, filterList);\n\t\t}\n\n\t\tfilterList.push(deepCopy(options.filter));\n\t\tcontext.watchAllCollections.delete(collection);\n\t}\n\n\tif (options?.meta) {\n\t\tlet metaList = context.queryMetadata.get(collection);\n\n\t\tif (!metaList) {\n\t\t\tmetaList = [];\n\t\t\tcontext.queryMetadata.set(collection, metaList);\n\t\t}\n\n\t\tmetaList.push(deepCopy(options.meta));\n\t}\n\n\tconst ids = new Set<string>();\n\tcollectIdsFromResult(result, ids);\n\n\tif (!ids.size && options?.filter) {\n\t\tcollectIdsFromFilter(options.filter, ids);\n\t}\n\n\tif (ids.size) {\n\t\tcontext.watchAllCollections.delete(collection);\n\t\tlet existing = context.dependencies.get(collection);\n\n\t\tif (!existing) {\n\t\t\texisting = new Set();\n\t\t\tcontext.dependencies.set(collection, existing);\n\t\t}\n\n\t\tfor (const id of ids) {\n\t\t\texisting.add(id);\n\t\t}\n\t}\n\telse if (!options?.filter) {\n\t\tcontext.watchAllCollections.add(collection);\n\t}\n}\n\nexport function recordAggregateDependencies(collection: string, pipeline: any[], result: unknown) {\n\tconst context = dependencyStorage.getStore();\n\n\tif (!context) {\n\t\treturn;\n\t}\n\n\tconst matchFilter = extractMatchFilter(pipeline);\n\tconst meta = extractAggregateMeta(pipeline);\n\trecordDependencyResult(collection, result, {\n\t\tfilter: matchFilter,\n\t\tmeta\n\t});\n\n\tconst lookupTargets = extractLookupTargets(pipeline);\n\n\tif (!lookupTargets.length) {\n\t\treturn;\n\t}\n\n\tfor (const target of lookupTargets) {\n\t\tconst nestedValues: unknown[] = [];\n\t\tcollectLookupValues(result, target.as, nestedValues);\n\t\tconst rootDocs = Array.isArray(result) ? result : [result];\n\t\tconst pipelineFilters: any[] = [];\n\t\tlet pipelineUnresolved = false;\n\n\t\tfor (const rootDoc of rootDocs) {\n\t\t\tconst { filters: filtersFromPipeline, unresolved } = buildLookupPipelineFilters(rootDoc, target);\n\t\t\tif (unresolved) {\n\t\t\t\tpipelineUnresolved = true;\n\t\t\t}\n\t\t\tif (filtersFromPipeline?.length) {\n\t\t\t\tpipelineFilters.push(...filtersFromPipeline);\n\t\t\t}\n\t\t}\n\n\t\tconst filter = buildLookupFilter(result, target.localField, target.foreignField);\n\n\t\tconst uniquePipelineFilters = dedupeFilters(pipelineFilters);\n\n\t\tif (nestedValues.length) {\n\t\t\trecordDependencyResult(target.from, nestedValues, filter ? { filter } : undefined);\n\t\t}\n\n\t\tif (uniquePipelineFilters.length) {\n\t\t\tconst pipelineMeta = extractAggregationMetaFromPipeline(target.pipeline);\n\t\t\tfor (const pipelineFilter of uniquePipelineFilters) {\n\t\t\t\trecordDependencyResult(target.from, [], { filter: pipelineFilter, meta: pipelineMeta });\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (!nestedValues.length && filter) {\n\t\t\trecordDependencyResult(target.from, [], { filter });\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (!nestedValues.length) {\n\t\t\tif (pipelineUnresolved) {\n\t\t\t\tcontext.watchAllCollections.add(target.from);\n\t\t\t}\n\t\t\telse if (!target.pipeline || !target.pipeline.length) {\n\t\t\t\tcontext.watchAllCollections.add(target.from);\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction extractLookupTargets(pipeline: any[]): LookupTarget[] {\nconst lookups: LookupTarget[] = [];\n\n\tif (!Array.isArray(pipeline)) {\n\t\treturn lookups;\n\t}\n\n\tfor (const stage of pipeline) {\n\t\tif (stage && stage.$lookup && typeof stage.$lookup === 'object') {\n\t\t\tconst lookup = stage.$lookup;\n\t\t\tif (typeof lookup.from === 'string' && typeof lookup.as === 'string') {\n\t\t\t\tlookups.push({\n\t\t\t\t\tfrom: lookup.from,\n\t\t\t\t\tas: lookup.as,\n\t\t\t\t\tlocalField: typeof lookup.localField === 'string' ? lookup.localField : undefined,\n\t\t\t\t\tforeignField: typeof lookup.foreignField === 'string' ? lookup.foreignField : undefined,\n\t\t\t\t\tlet: lookup.let && typeof lookup.let === 'object' ? lookup.let : undefined,\n\t\t\t\t\tpipeline: Array.isArray(lookup.pipeline) ? lookup.pipeline : undefined\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\treturn lookups;\n}\n\nfunction extractMatchFilter(pipeline: any[]): any {\n\tif (!Array.isArray(pipeline)) {\n\t\treturn null;\n\t}\n\n\tconst filters: any[] = [];\n\n\tfor (const stage of pipeline) {\n\t\tif (stage && stage.$match && typeof stage.$match === 'object') {\n\t\t\tfilters.push(deepCopy(stage.$match));\n\t\t}\n\t}\n\n\tif (!filters.length) {\n\t\treturn null;\n\t}\n\n\tif (filters.length === 1) {\n\t\treturn filters[0];\n\t}\n\n\treturn { $and: filters };\n}\n\nfunction extractAggregateMeta(pipeline: any[]): QueryMeta {\n\tif (!Array.isArray(pipeline)) {\n\t\treturn null;\n\t}\n\n\tlet limit = undefined;\n\tlet skip = undefined;\n\tlet sort = null;\n\n\tfor (const stage of pipeline) {\n\t\tif (stage?.$limit !== undefined && typeof stage.$limit === 'number') {\n\t\t\tlimit = stage.$limit;\n\t\t}\n\t\telse if (stage?.$skip !== undefined && typeof stage.$skip === 'number') {\n\t\t\tskip = stage.$skip;\n\t\t}\n\t\telse if (stage?.$sort && typeof stage.$sort === 'object') {\n\t\t\tsort = deepCopy(stage.$sort);\n\t\t}\n\t}\n\n\tconst meta: QueryMeta = {};\n\n\tif (limit !== undefined) {\n\t\tmeta.limit = limit;\n\t}\n\n\tif (skip !== undefined) {\n\t\tmeta.skip = skip;\n\t}\n\n\tif (sort) {\n\t\tmeta.sort = sort;\n\t}\n\n\treturn Object.keys(meta).length ? meta : null;\n}\n\nfunction extractAggregationMetaFromPipeline(pipeline: any[]): QueryMeta {\n\tif (!Array.isArray(pipeline)) {\n\t\treturn null;\n\t}\n\n\tlet limit = undefined;\n\tlet skip = undefined;\n\tlet sort = null;\n\n\tfor (const stage of pipeline) {\n\t\tif (stage?.$limit !== undefined && typeof stage.$limit === 'number') {\n\t\t\tlimit = stage.$limit;\n\t\t}\n\t\telse if (stage?.$skip !== undefined && typeof stage.$skip === 'number') {\n\t\t\tskip = stage.$skip;\n\t\t}\n\t\telse if (stage?.$sort && typeof stage.$sort === 'object') {\n\t\t\tsort = deepCopy(stage.$sort);\n\t\t}\n\t}\n\n\tconst meta: QueryMeta = {};\n\n\tif (limit !== undefined) {\n\t\tmeta.limit = limit;\n\t}\n\n\tif (skip !== undefined) {\n\t\tmeta.skip = skip;\n\t}\n\n\tif (sort) {\n\t\tmeta.sort = sort;\n\t}\n\n\treturn Object.keys(meta).length ? meta : null;\n}\n\nfunction collectLookupValues(source: unknown, path: string, output: unknown[]) {\n\tif (!source) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(source)) {\n\t\tfor (const item of source) {\n\t\t\tcollectLookupValues(item, path, output);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (typeof source !== 'object') {\n\t\treturn;\n\t}\n\n\tconst pathSegments = path.split('.');\n\tcollectLookupPathValues(source as Record<string, unknown>, pathSegments, 0, output);\n}\n\nfunction collectLookupPathValues(value: Record<string, unknown>, path: string[], index: number, output: unknown[]) {\n\tif (!value) {\n\t\treturn;\n\t}\n\n\tconst current = value[path[index]];\n\n\tif (current === undefined) {\n\t\treturn;\n\t}\n\n\tif (index === path.length - 1) {\n\t\toutput.push(current);\n\t\treturn;\n\t}\n\n\tif (Array.isArray(current)) {\n\t\tfor (const item of current) {\n\t\t\tif (item && typeof item === 'object') {\n\t\t\t\tcollectLookupPathValues(item as Record<string, unknown>, path, index + 1, output);\n\t\t\t}\n\t\t}\n\t}\n\telse if (current && typeof current === 'object') {\n\t\tcollectLookupPathValues(current as Record<string, unknown>, path, index + 1, output);\n\t}\n}\n\nfunction buildLookupFilter(result: unknown, localField?: string, foreignField?: string) {\n\tif (!localField || !foreignField) {\n\t\treturn null;\n\t}\n\n\tconst values: any[] = [];\n\tconst segments = localField.split('.');\n\tcollectFieldValues(result, segments, 0, values);\n\n\tconst uniqueValues = dedupeFilterValues(values);\n\n\tif (!uniqueValues.length) {\n\t\treturn null;\n\t}\n\n\treturn {\n\t\t[foreignField]: {\n\t\t\t$in: uniqueValues\n\t\t}\n\t};\n}\n\nfunction collectFieldValues(source: unknown, path: string[], index: number, output: any[]) {\n\tif (!source) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(source)) {\n\t\tfor (const item of source) {\n\t\t\tcollectFieldValues(item, path, index, output);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (typeof source !== 'object') {\n\t\treturn;\n\t}\n\n\tconst obj = source as Record<string, unknown>;\n\tconst key = path[index];\n\tconst current = obj[key];\n\n\tif (current === undefined) {\n\t\treturn;\n\t}\n\n\tif (index === path.length - 1) {\n\t\tappendFilterValue(output, current);\n\t\treturn;\n\t}\n\n\tif (Array.isArray(current)) {\n\t\tfor (const item of current) {\n\t\t\tcollectFieldValues(item, path, index + 1, output);\n\t\t}\n\t}\n\telse {\n\t\tcollectFieldValues(current, path, index + 1, output);\n\t}\n}\n\nfunction appendFilterValue(output: any[], value: any) {\n\tif (value === undefined || value === null) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(value)) {\n\t\tfor (const item of value) {\n\t\t\tappendFilterValue(output, item);\n\t\t}\n\t\treturn;\n\t}\n\n\toutput.push(value);\n}\n\nfunction dedupeFilterValues(values: any[]): any[] {\n\tconst unique = new Map<string, any>();\n\n\tfor (const value of values) {\n\t\tconst key = serializeFilterValue(value);\n\t\tif (!unique.has(key)) {\n\t\t\tunique.set(key, value);\n\t\t}\n\t}\n\n\treturn Array.from(unique.values());\n}\n\nfunction serializeFilterValue(value: any): string {\n\tif (value === null || value === undefined) {\n\t\treturn 'null';\n\t}\n\n\tif (typeof value === 'object') {\n\t\tif (typeof value.toHexString === 'function') {\n\t\t\treturn value.toHexString();\n\t\t}\n\n\t\tif (value instanceof Date) {\n\t\t\treturn value.toISOString();\n\t\t}\n\n\t\tif (typeof value.toString === 'function' && value.toString !== Object.prototype.toString) {\n\t\t\treturn value.toString();\n\t\t}\n\n\t\ttry {\n\t\t\treturn JSON.stringify(value);\n\t\t}\n\t\tcatch {\n\t\t\treturn '[object]';\n\t\t}\n\t}\n\n\treturn String(value);\n}\n\nfunction collectIdsFromResult(source: unknown, ids: Set<string>, visited = new WeakSet<object>()) {\n\tif (!source) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(source)) {\n\t\tfor (const item of source) {\n\t\t\tcollectIdsFromResult(item, ids, visited);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (typeof source !== 'object') {\n\t\treturn;\n\t}\n\n\tconst objectSource = source as Record<string, unknown>;\n\n\tif (visited.has(objectSource)) {\n\t\treturn;\n\t}\n\n\tvisited.add(objectSource);\n\n\tconst normalizedId = normalizeId(objectSource._id);\n\n\tif (normalizedId) {\n\t\tids.add(normalizedId);\n\t}\n\n\tfor (const value of Object.values(objectSource)) {\n\t\tif (value && (typeof value === 'object' || Array.isArray(value))) {\n\t\t\tcollectIdsFromResult(value, ids, visited);\n\t\t}\n\t}\n}\n\nfunction collectIdsFromFilter(filter: unknown, ids: Set<string>) {\n\tif (!filter) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(filter)) {\n\t\tfor (const item of filter) {\n\t\t\tcollectIdsFromFilter(item, ids);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (typeof filter !== 'object') {\n\t\treturn;\n\t}\n\n\tconst filterObject = filter as Record<string, unknown>;\n\n\tif (filterObject._id !== undefined) {\n\t\tcollectIdsFromFilterValue(filterObject._id, ids);\n\t}\n\n\tfor (const [key, value] of Object.entries(filterObject)) {\n\t\tif (key === '$or' || key === '$and' || key === '$nor') {\n\t\t\tif (Array.isArray(value)) {\n\t\t\t\tfor (const item of value) {\n\t\t\t\t\tcollectIdsFromFilter(item, ids);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse if (key !== '_id' && value && typeof value === 'object') {\n\t\t\tcollectIdsFromFilter(value, ids);\n\t\t}\n\t}\n}\n\nfunction collectIdsFromFilterValue(value: unknown, ids: Set<string>) {\n\tif (value === null || value === undefined) {\n\t\treturn;\n\t}\n\n\tif (Array.isArray(value)) {\n\t\tfor (const item of value) {\n\t\t\tcollectIdsFromFilterValue(item, ids);\n\t\t}\n\t\treturn;\n\t}\n\n\tif (typeof value === 'object') {\n\t\tfor (const [key, inner] of Object.entries(value as Record<string, unknown>)) {\n\t\t\tif (key === '$in' || key === '$nin' || key === '$all') {\n\t\t\t\tcollectIdsFromFilterValue(inner, ids);\n\t\t\t}\n\t\t\telse if (key === '$eq' || key === '$ne') {\n\t\t\t\tcollectIdsFromFilterValue(inner, ids);\n\t\t\t}\n\t\t\telse if (key === '$or' || key === '$and' || key === '$nor') {\n\t\t\t\tcollectIdsFromFilterValue(inner, ids);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcollectIdsFromFilterValue(inner, ids);\n\t\t\t}\n\t\t}\n\t\treturn;\n\t}\n\n\tconst normalized = normalizeId(value);\n\n\tif (normalized) {\n\t\tids.add(normalized);\n\t}\n}\n\nfunction normalizeId(value: unknown): string {\n\tif (value === null || value === undefined) {\n\t\treturn null;\n\t}\n\n\tif (typeof value === 'string') {\n\t\tconst trimmed = value.trim();\n\t\treturn trimmed.length ? trimmed : null;\n\t}\n\n\tif (typeof value === 'number' || typeof value === 'bigint') {\n\t\treturn value.toString();\n\t}\n\n\tif (typeof value === 'object') {\n\t\tconst objValue = value as { toHexString?: () => string, toString?: () => string };\n\n\t\tif (typeof objValue.toHexString === 'function') {\n\t\t\treturn objValue.toHexString();\n\t\t}\n\n\t\tif (value instanceof Date) {\n\t\t\treturn value.toISOString();\n\t\t}\n\n\t\tif (typeof objValue.toString === 'function') {\n\t\t\tconst str = objValue.toString();\n\t\t\tif (str && str !== '[object Object]') {\n\t\t\t\treturn str;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn null;\n}\n\nfunction cloneDependencyMap(original: Map<string, Set<string>>): Map<string, Set<string>> {\n\tconst cloned = new Map<string, Set<string>>();\n\n\tfor (const [collection, ids] of original.entries()) {\n\t\tcloned.set(collection, new Set(ids));\n\t}\n\n\treturn cloned;\n}\n\nfunction cloneFilterMap(original: Map<string, any[]>): Map<string, any[]> {\n\tconst cloned = new Map<string, any[]>();\n\n\tfor (const [collection, filters] of original.entries()) {\n\t\tcloned.set(collection, filters.map(filter => deepCopy(filter)));\n\t}\n\n\treturn cloned;\n}\n\nfunction cloneQueryMetaMap(original: Map<string, QueryMeta[]>): Map<string, QueryMeta[]> {\n\tconst cloned = new Map<string, QueryMeta[]>();\n\n\tfor (const [collection, metaList] of original.entries()) {\n\t\tcloned.set(collection, metaList.map(meta => deepCopy(meta)));\n\t}\n\n\treturn cloned;\n}\n\n\nfunction buildLookupPipelineFilters(rootDoc: any, target: LookupTarget): { filters: any[], unresolved: boolean } {\n\tif (!target.pipeline || !target.pipeline.length) {\n\t\treturn { filters: [], unresolved: false };\n\t}\n\nconst matchStages = target.pipeline.map(stage => ({ stage, base: stage.$match })).filter(entry => entry.base);\n\n\tif (!matchStages.length) {\n\t\treturn buildLookupPipelineFromStack(target.pipeline, [], rootDoc, target.let);\n\t}\n\n\tconst letValuesResult = resolveLetVariables(rootDoc, target.let);\n\n\tif (!letValuesResult.resolved) {\n\t\treturn { filters: [], unresolved: true };\n\t}\n\n\tconst combinedMatches = [];\n\n\tfor (const { base } of matchStages) {\n\t\tconst substitutionState = { unresolved: false };\n\t\tconst substituted = substituteLetVariables(base, letValuesResult.values, rootDoc, substitutionState);\n\n\t\tif (substitutionState.unresolved || containsUnresolvedLetReference(substituted)) {\n\t\t\treturn { filters: [], unresolved: true };\n\t\t}\n\n\t\tcombinedMatches.push(substituted);\n\t}\n\n\tif (!combinedMatches.length) {\n\t\treturn buildLookupPipelineFromStack(target.pipeline, [], rootDoc, target.let);\n\t}\n\n\tif (combinedMatches.length === 1) {\n\t\treturn { filters: [combinedMatches[0]], unresolved: false };\n\t}\n\n\treturn { filters: [{ $and: combinedMatches }], unresolved: false };\n}\n\nfunction buildLookupPipelineFromStack(pipeline: any[], initialFilters: any[], rootDoc: any, letMap: Record<string, any>) {\n\tlet currentFilters = initialFilters.slice();\n\tlet unresolved = false;\n\n\tconst entries = pipeline.map(stage => stage ? Object.keys(stage)[0] : null);\n\n\tfor (let i = 0; i < pipeline.length; i++) {\n\t\tconst stage = pipeline[i];\n\t\tconst stageType = entries[i];\n\n\t\tif (stageType === '$match' && stage.$match) {\n\t\t\tconst letValuesResult = resolveLetVariables(rootDoc, letMap);\n\t\t\tif (!letValuesResult.resolved) {\n\t\t\t\tunresolved = true;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst substitutionState = { unresolved: false };\n\t\t\tconst substituted = substituteLetVariables(stage.$match, letValuesResult.values, rootDoc, substitutionState);\n\n\t\t\tif (substitutionState.unresolved || containsUnresolvedLetReference(substituted)) {\n\t\t\t\tunresolved = true;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcurrentFilters.push(substituted);\n\t\t}\n\t\telse if (stageType === '$match') {\n\t\t\tunresolved = true;\n\t\t\tbreak;\n\t\t}\n\t\telse if (stageType === '$facet') {\n\t\t\tunresolved = true;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif (!currentFilters.length) {\n\t\treturn { filters: [], unresolved };\n\t}\n\n\tif (currentFilters.length === 1) {\n\t\treturn { filters: currentFilters, unresolved };\n\t}\n\n\treturn { filters: [{ $and: currentFilters }], unresolved };\n}\n\nfunction resolveLetVariables(rootDoc: any, letMap: Record<string, any>) {\n\tif (!letMap || typeof letMap !== 'object') {\n\t\treturn { resolved: true, values: {} };\n\t}\n\n\tconst values = {};\n\n\tfor (const [key, expression] of Object.entries(letMap)) {\n\t\tconst evaluation = evaluateLetExpression(rootDoc, expression);\n\n\t\tif (!evaluation.resolved) {\n\t\t\treturn { resolved: false, values: null };\n\t\t}\n\n\t\tvalues[key] = evaluation.value;\n\t}\n\n\treturn { resolved: true, values };\n}\n\nfunction evaluateLetExpression(rootDoc: any, expression: any): { resolved: boolean, value: any } {\n\tif (typeof expression === 'string') {\n\t\tif (expression.startsWith('$$ROOT.')) {\n\t\t\tconst path = expression.slice('$$ROOT.'.length);\n\t\t\treturn { resolved: true, value: getValueByPath(rootDoc, path) };\n\t\t}\n\t\telse if (expression === '$$ROOT') {\n\t\t\treturn { resolved: true, value: rootDoc };\n\t\t}\n\t\telse if (expression.startsWith('$$')) {\n\t\t\treturn { resolved: false, value: null };\n\t\t}\n\t\telse if (expression.startsWith('$')) {\n\t\t\tconst path = expression.slice(1);\n\t\t\treturn { resolved: true, value: getValueByPath(rootDoc, path) };\n\t\t}\n\t\telse {\n\t\t\treturn { resolved: true, value: expression };\n\t\t}\n\t}\n\telse if (Array.isArray(expression)) {\n\t\treturn { resolved: false, value: null };\n\t}\n\telse if (expression && typeof expression === 'object') {\n\t\treturn { resolved: false, value: null };\n\t}\n\n\treturn { resolved: true, value: expression };\n}\n\nfunction substituteLetVariables(node: any, letValues: Record<string, any>, rootDoc: any, state: { unresolved: boolean }) {\n\tif (Array.isArray(node)) {\n\t\treturn node.map(item => substituteLetVariables(item, letValues, rootDoc, state));\n\t}\n\n\tif (node && typeof node === 'object') {\n\t\tconst output = {};\n\n\t\tfor (const [key, value] of Object.entries(node)) {\n\t\t\toutput[key] = substituteLetVariables(value, letValues, rootDoc, state);\n\t\t}\n\n\t\treturn output;\n\t}\n\n\tif (typeof node === 'string') {\n\t\tif (node.startsWith('$$ROOT.')) {\n\t\t\tconst path = node.slice('$$ROOT.'.length);\n\t\t\treturn getValueByPath(rootDoc, path);\n\t\t}\n\n\t\tif (node === '$$ROOT') {\n\t\t\treturn rootDoc;\n\t\t}\n\n\t\tif (node.startsWith('$$')) {\n\t\t\tconst varName = node.slice(2);\n\n\t\t\tif (Object.prototype.hasOwnProperty.call(letValues, varName)) {\n\t\t\t\treturn letValues[varName];\n\t\t\t}\n\n\t\t\tstate.unresolved = true;\n\t\t\treturn node;\n\t\t}\n\t}\n\n\treturn node;\n}\n\nfunction containsUnresolvedLetReference(node: any): boolean {\n\tif (typeof node === 'string') {\n\t\treturn node.includes('$$');\n\t}\n\n\tif (Array.isArray(node)) {\n\t\treturn node.some(item => containsUnresolvedLetReference(item));\n\t}\n\n\tif (node && typeof node === 'object') {\n\t\treturn Object.values(node).some(value => containsUnresolvedLetReference(value));\n\t}\n\n\treturn false;\n}\n\nfunction getValueByPath(source: any, path: string) {\n\tif (!source || !path) {\n\t\treturn undefined;\n\t}\n\n\tconst segments = path.split('.');\n\tlet current = source;\n\n\tfor (const segment of segments) {\n\t\tif (current === null || current === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (Array.isArray(current)) {\n\t\t\tconst index = parseInt(segment, 10);\n\n\t\t\tif (isNaN(index) || index < 0 || index >= current.length) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\tcurrent = current[index];\n\t\t}\n\t\telse {\n\t\t\tcurrent = current[segment];\n\t\t}\n\t}\n\n\treturn current;\n}\n\nfunction canonicalizeFilter(filter: any): string {\n\treturn JSON.stringify(sortKeys(filter));\n}\n\nfunction sortKeys(value: any): any {\n\tif (Array.isArray(value)) {\n\t\treturn value.map(item => sortKeys(item));\n\t}\n\n\tif (value && typeof value === 'object') {\n\t\tconst sorted = {};\n\t\tconst keys = Object.keys(value).sort();\n\n\t\tfor (const key of keys) {\n\t\t\tsorted[key] = sortKeys(value[key]);\n\t\t}\n\n\t\treturn sorted;\n\t}\n\n\treturn value;\n}\n\nfunction dedupeFilters(filters: any[]): any[] {\n\tconst map = new Map<string, any>();\n\n\tfor (const filter of filters) {\n\t\tconst key = canonicalizeFilter(filter);\n\n\t\tif (!map.has(key)) {\n\t\t\tmap.set(key, filter);\n\t\t}\n\t}\n\n\treturn Array.from(map.values());\n}\n"]}
|