@resolveio/server-lib 20.9.4 → 20.9.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/managers/mongo.manager.js +15 -0
- package/managers/mongo.manager.js.map +1 -1
- package/managers/subscription.manager.d.ts +10 -1
- package/managers/subscription.manager.js +311 -76
- package/managers/subscription.manager.js.map +1 -1
- package/models/subscription.model.d.ts +3 -0
- package/models/subscription.model.js.map +1 -1
- package/package.json +5 -3
- package/util/subscription-dependency-context.d.ts +13 -0
- package/util/subscription-dependency-context.js +674 -0
- package/util/subscription-dependency-context.js.map +1 -0
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __values = (this && this.__values) || function(o) {
|
|
39
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
40
|
+
if (m) return m.call(o);
|
|
41
|
+
if (o && typeof o.length === "number") return {
|
|
42
|
+
next: function () {
|
|
43
|
+
if (o && i >= o.length) o = void 0;
|
|
44
|
+
return { value: o && o[i++], done: !o };
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
48
|
+
};
|
|
49
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
50
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
51
|
+
if (!m) return o;
|
|
52
|
+
var i = m.call(o), r, ar = [], e;
|
|
53
|
+
try {
|
|
54
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
55
|
+
}
|
|
56
|
+
catch (error) { e = { error: error }; }
|
|
57
|
+
finally {
|
|
58
|
+
try {
|
|
59
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
60
|
+
}
|
|
61
|
+
finally { if (e) throw e.error; }
|
|
62
|
+
}
|
|
63
|
+
return ar;
|
|
64
|
+
};
|
|
65
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
66
|
+
exports.recordAggregateDependencies = exports.recordDependencyResult = exports.withDependencyTracking = void 0;
|
|
67
|
+
var async_hooks_1 = require("async_hooks");
|
|
68
|
+
var common_1 = require("./common");
|
|
69
|
+
var dependencyStorage = new async_hooks_1.AsyncLocalStorage();
|
|
70
|
+
function withDependencyTracking(fn) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
+
var context, result;
|
|
73
|
+
var _this = this;
|
|
74
|
+
return __generator(this, function (_a) {
|
|
75
|
+
switch (_a.label) {
|
|
76
|
+
case 0:
|
|
77
|
+
context = {
|
|
78
|
+
dependencies: new Map(),
|
|
79
|
+
filters: new Map(),
|
|
80
|
+
watchAllCollections: new Set()
|
|
81
|
+
};
|
|
82
|
+
return [4 /*yield*/, dependencyStorage.run(context, function () { return __awaiter(_this, void 0, void 0, function () {
|
|
83
|
+
return __generator(this, function (_a) {
|
|
84
|
+
switch (_a.label) {
|
|
85
|
+
case 0: return [4 /*yield*/, fn()];
|
|
86
|
+
case 1:
|
|
87
|
+
result = _a.sent();
|
|
88
|
+
return [2 /*return*/];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}); })];
|
|
92
|
+
case 1:
|
|
93
|
+
_a.sent();
|
|
94
|
+
return [2 /*return*/, {
|
|
95
|
+
result: result,
|
|
96
|
+
snapshot: {
|
|
97
|
+
dependencies: cloneDependencyMap(context.dependencies),
|
|
98
|
+
filters: cloneFilterMap(context.filters),
|
|
99
|
+
watchAllCollections: new Set(context.watchAllCollections)
|
|
100
|
+
}
|
|
101
|
+
}];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
exports.withDependencyTracking = withDependencyTracking;
|
|
107
|
+
function recordDependencyResult(collection, result, options) {
|
|
108
|
+
var e_1, _a;
|
|
109
|
+
var context = dependencyStorage.getStore();
|
|
110
|
+
if (!context) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (options === null || options === void 0 ? void 0 : options.filter) {
|
|
114
|
+
var filterList = context.filters.get(collection);
|
|
115
|
+
if (!filterList) {
|
|
116
|
+
filterList = [];
|
|
117
|
+
context.filters.set(collection, filterList);
|
|
118
|
+
}
|
|
119
|
+
filterList.push((0, common_1.deepCopy)(options.filter));
|
|
120
|
+
}
|
|
121
|
+
var ids = new Set();
|
|
122
|
+
collectIdsFromResult(result, ids);
|
|
123
|
+
if (!ids.size && (options === null || options === void 0 ? void 0 : options.filter)) {
|
|
124
|
+
collectIdsFromFilter(options.filter, ids);
|
|
125
|
+
}
|
|
126
|
+
if (ids.size) {
|
|
127
|
+
var existing = context.dependencies.get(collection);
|
|
128
|
+
if (!existing) {
|
|
129
|
+
existing = new Set();
|
|
130
|
+
context.dependencies.set(collection, existing);
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
for (var ids_1 = __values(ids), ids_1_1 = ids_1.next(); !ids_1_1.done; ids_1_1 = ids_1.next()) {
|
|
134
|
+
var id = ids_1_1.value;
|
|
135
|
+
existing.add(id);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
139
|
+
finally {
|
|
140
|
+
try {
|
|
141
|
+
if (ids_1_1 && !ids_1_1.done && (_a = ids_1.return)) _a.call(ids_1);
|
|
142
|
+
}
|
|
143
|
+
finally { if (e_1) throw e_1.error; }
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
else if (!(options === null || options === void 0 ? void 0 : options.filter)) {
|
|
147
|
+
context.watchAllCollections.add(collection);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.recordDependencyResult = recordDependencyResult;
|
|
151
|
+
function recordAggregateDependencies(collection, pipeline, result) {
|
|
152
|
+
var e_2, _a;
|
|
153
|
+
var context = dependencyStorage.getStore();
|
|
154
|
+
if (!context) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
var matchFilter = extractMatchFilter(pipeline);
|
|
158
|
+
recordDependencyResult(collection, result, matchFilter ? { filter: matchFilter } : undefined);
|
|
159
|
+
var lookupTargets = extractLookupTargets(pipeline);
|
|
160
|
+
if (!lookupTargets.length) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
for (var lookupTargets_1 = __values(lookupTargets), lookupTargets_1_1 = lookupTargets_1.next(); !lookupTargets_1_1.done; lookupTargets_1_1 = lookupTargets_1.next()) {
|
|
165
|
+
var target = lookupTargets_1_1.value;
|
|
166
|
+
var nestedValues = [];
|
|
167
|
+
collectLookupValues(result, target.as, nestedValues);
|
|
168
|
+
var filter = buildLookupFilter(result, target.localField, target.foreignField);
|
|
169
|
+
if (nestedValues.length || filter) {
|
|
170
|
+
recordDependencyResult(target.from, nestedValues, filter ? { filter: filter } : undefined);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
context.watchAllCollections.add(target.from);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
178
|
+
finally {
|
|
179
|
+
try {
|
|
180
|
+
if (lookupTargets_1_1 && !lookupTargets_1_1.done && (_a = lookupTargets_1.return)) _a.call(lookupTargets_1);
|
|
181
|
+
}
|
|
182
|
+
finally { if (e_2) throw e_2.error; }
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
exports.recordAggregateDependencies = recordAggregateDependencies;
|
|
186
|
+
function extractLookupTargets(pipeline) {
|
|
187
|
+
var e_3, _a;
|
|
188
|
+
var lookups = [];
|
|
189
|
+
if (!Array.isArray(pipeline)) {
|
|
190
|
+
return lookups;
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
for (var pipeline_1 = __values(pipeline), pipeline_1_1 = pipeline_1.next(); !pipeline_1_1.done; pipeline_1_1 = pipeline_1.next()) {
|
|
194
|
+
var stage = pipeline_1_1.value;
|
|
195
|
+
if (stage && stage.$lookup && typeof stage.$lookup === 'object') {
|
|
196
|
+
var lookup = stage.$lookup;
|
|
197
|
+
if (typeof lookup.from === 'string' && typeof lookup.as === 'string') {
|
|
198
|
+
lookups.push({
|
|
199
|
+
from: lookup.from,
|
|
200
|
+
as: lookup.as,
|
|
201
|
+
localField: typeof lookup.localField === 'string' ? lookup.localField : undefined,
|
|
202
|
+
foreignField: typeof lookup.foreignField === 'string' ? lookup.foreignField : undefined
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
209
|
+
finally {
|
|
210
|
+
try {
|
|
211
|
+
if (pipeline_1_1 && !pipeline_1_1.done && (_a = pipeline_1.return)) _a.call(pipeline_1);
|
|
212
|
+
}
|
|
213
|
+
finally { if (e_3) throw e_3.error; }
|
|
214
|
+
}
|
|
215
|
+
return lookups;
|
|
216
|
+
}
|
|
217
|
+
function extractMatchFilter(pipeline) {
|
|
218
|
+
var e_4, _a;
|
|
219
|
+
if (!Array.isArray(pipeline)) {
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
var filters = [];
|
|
223
|
+
try {
|
|
224
|
+
for (var pipeline_2 = __values(pipeline), pipeline_2_1 = pipeline_2.next(); !pipeline_2_1.done; pipeline_2_1 = pipeline_2.next()) {
|
|
225
|
+
var stage = pipeline_2_1.value;
|
|
226
|
+
if (stage && stage.$match && typeof stage.$match === 'object') {
|
|
227
|
+
filters.push((0, common_1.deepCopy)(stage.$match));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
232
|
+
finally {
|
|
233
|
+
try {
|
|
234
|
+
if (pipeline_2_1 && !pipeline_2_1.done && (_a = pipeline_2.return)) _a.call(pipeline_2);
|
|
235
|
+
}
|
|
236
|
+
finally { if (e_4) throw e_4.error; }
|
|
237
|
+
}
|
|
238
|
+
if (!filters.length) {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
if (filters.length === 1) {
|
|
242
|
+
return filters[0];
|
|
243
|
+
}
|
|
244
|
+
return { $and: filters };
|
|
245
|
+
}
|
|
246
|
+
function collectLookupValues(source, path, output) {
|
|
247
|
+
var e_5, _a;
|
|
248
|
+
if (!source) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (Array.isArray(source)) {
|
|
252
|
+
try {
|
|
253
|
+
for (var source_1 = __values(source), source_1_1 = source_1.next(); !source_1_1.done; source_1_1 = source_1.next()) {
|
|
254
|
+
var item = source_1_1.value;
|
|
255
|
+
collectLookupValues(item, path, output);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
259
|
+
finally {
|
|
260
|
+
try {
|
|
261
|
+
if (source_1_1 && !source_1_1.done && (_a = source_1.return)) _a.call(source_1);
|
|
262
|
+
}
|
|
263
|
+
finally { if (e_5) throw e_5.error; }
|
|
264
|
+
}
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (typeof source !== 'object') {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
var pathSegments = path.split('.');
|
|
271
|
+
collectLookupPathValues(source, pathSegments, 0, output);
|
|
272
|
+
}
|
|
273
|
+
function collectLookupPathValues(value, path, index, output) {
|
|
274
|
+
var e_6, _a;
|
|
275
|
+
if (!value) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
var current = value[path[index]];
|
|
279
|
+
if (current === undefined) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
if (index === path.length - 1) {
|
|
283
|
+
output.push(current);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
if (Array.isArray(current)) {
|
|
287
|
+
try {
|
|
288
|
+
for (var current_1 = __values(current), current_1_1 = current_1.next(); !current_1_1.done; current_1_1 = current_1.next()) {
|
|
289
|
+
var item = current_1_1.value;
|
|
290
|
+
if (item && typeof item === 'object') {
|
|
291
|
+
collectLookupPathValues(item, path, index + 1, output);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
296
|
+
finally {
|
|
297
|
+
try {
|
|
298
|
+
if (current_1_1 && !current_1_1.done && (_a = current_1.return)) _a.call(current_1);
|
|
299
|
+
}
|
|
300
|
+
finally { if (e_6) throw e_6.error; }
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
else if (current && typeof current === 'object') {
|
|
304
|
+
collectLookupPathValues(current, path, index + 1, output);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
function buildLookupFilter(result, localField, foreignField) {
|
|
308
|
+
var _a;
|
|
309
|
+
if (!localField || !foreignField) {
|
|
310
|
+
return null;
|
|
311
|
+
}
|
|
312
|
+
var values = [];
|
|
313
|
+
var segments = localField.split('.');
|
|
314
|
+
collectFieldValues(result, segments, 0, values);
|
|
315
|
+
var uniqueValues = dedupeFilterValues(values);
|
|
316
|
+
if (!uniqueValues.length) {
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
return _a = {},
|
|
320
|
+
_a[foreignField] = {
|
|
321
|
+
$in: uniqueValues
|
|
322
|
+
},
|
|
323
|
+
_a;
|
|
324
|
+
}
|
|
325
|
+
function collectFieldValues(source, path, index, output) {
|
|
326
|
+
var e_7, _a, e_8, _b;
|
|
327
|
+
if (!source) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
if (Array.isArray(source)) {
|
|
331
|
+
try {
|
|
332
|
+
for (var source_2 = __values(source), source_2_1 = source_2.next(); !source_2_1.done; source_2_1 = source_2.next()) {
|
|
333
|
+
var item = source_2_1.value;
|
|
334
|
+
collectFieldValues(item, path, index, output);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
338
|
+
finally {
|
|
339
|
+
try {
|
|
340
|
+
if (source_2_1 && !source_2_1.done && (_a = source_2.return)) _a.call(source_2);
|
|
341
|
+
}
|
|
342
|
+
finally { if (e_7) throw e_7.error; }
|
|
343
|
+
}
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
if (typeof source !== 'object') {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
var obj = source;
|
|
350
|
+
var key = path[index];
|
|
351
|
+
var current = obj[key];
|
|
352
|
+
if (current === undefined) {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
if (index === path.length - 1) {
|
|
356
|
+
appendFilterValue(output, current);
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
if (Array.isArray(current)) {
|
|
360
|
+
try {
|
|
361
|
+
for (var current_2 = __values(current), current_2_1 = current_2.next(); !current_2_1.done; current_2_1 = current_2.next()) {
|
|
362
|
+
var item = current_2_1.value;
|
|
363
|
+
collectFieldValues(item, path, index + 1, output);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
367
|
+
finally {
|
|
368
|
+
try {
|
|
369
|
+
if (current_2_1 && !current_2_1.done && (_b = current_2.return)) _b.call(current_2);
|
|
370
|
+
}
|
|
371
|
+
finally { if (e_8) throw e_8.error; }
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
collectFieldValues(current, path, index + 1, output);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
function appendFilterValue(output, value) {
|
|
379
|
+
var e_9, _a;
|
|
380
|
+
if (value === undefined || value === null) {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
if (Array.isArray(value)) {
|
|
384
|
+
try {
|
|
385
|
+
for (var value_1 = __values(value), value_1_1 = value_1.next(); !value_1_1.done; value_1_1 = value_1.next()) {
|
|
386
|
+
var item = value_1_1.value;
|
|
387
|
+
appendFilterValue(output, item);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
391
|
+
finally {
|
|
392
|
+
try {
|
|
393
|
+
if (value_1_1 && !value_1_1.done && (_a = value_1.return)) _a.call(value_1);
|
|
394
|
+
}
|
|
395
|
+
finally { if (e_9) throw e_9.error; }
|
|
396
|
+
}
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
output.push(value);
|
|
400
|
+
}
|
|
401
|
+
function dedupeFilterValues(values) {
|
|
402
|
+
var e_10, _a;
|
|
403
|
+
var unique = new Map();
|
|
404
|
+
try {
|
|
405
|
+
for (var values_1 = __values(values), values_1_1 = values_1.next(); !values_1_1.done; values_1_1 = values_1.next()) {
|
|
406
|
+
var value = values_1_1.value;
|
|
407
|
+
var key = serializeFilterValue(value);
|
|
408
|
+
if (!unique.has(key)) {
|
|
409
|
+
unique.set(key, value);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
414
|
+
finally {
|
|
415
|
+
try {
|
|
416
|
+
if (values_1_1 && !values_1_1.done && (_a = values_1.return)) _a.call(values_1);
|
|
417
|
+
}
|
|
418
|
+
finally { if (e_10) throw e_10.error; }
|
|
419
|
+
}
|
|
420
|
+
return Array.from(unique.values());
|
|
421
|
+
}
|
|
422
|
+
function serializeFilterValue(value) {
|
|
423
|
+
if (value === null || value === undefined) {
|
|
424
|
+
return 'null';
|
|
425
|
+
}
|
|
426
|
+
if (typeof value === 'object') {
|
|
427
|
+
if (typeof value.toHexString === 'function') {
|
|
428
|
+
return value.toHexString();
|
|
429
|
+
}
|
|
430
|
+
if (value instanceof Date) {
|
|
431
|
+
return value.toISOString();
|
|
432
|
+
}
|
|
433
|
+
if (typeof value.toString === 'function' && value.toString !== Object.prototype.toString) {
|
|
434
|
+
return value.toString();
|
|
435
|
+
}
|
|
436
|
+
try {
|
|
437
|
+
return JSON.stringify(value);
|
|
438
|
+
}
|
|
439
|
+
catch (_a) {
|
|
440
|
+
return '[object]';
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return String(value);
|
|
444
|
+
}
|
|
445
|
+
function collectIdsFromResult(source, ids, visited) {
|
|
446
|
+
var e_11, _a, e_12, _b;
|
|
447
|
+
if (visited === void 0) { visited = new WeakSet(); }
|
|
448
|
+
if (!source) {
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
if (Array.isArray(source)) {
|
|
452
|
+
try {
|
|
453
|
+
for (var source_3 = __values(source), source_3_1 = source_3.next(); !source_3_1.done; source_3_1 = source_3.next()) {
|
|
454
|
+
var item = source_3_1.value;
|
|
455
|
+
collectIdsFromResult(item, ids, visited);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
459
|
+
finally {
|
|
460
|
+
try {
|
|
461
|
+
if (source_3_1 && !source_3_1.done && (_a = source_3.return)) _a.call(source_3);
|
|
462
|
+
}
|
|
463
|
+
finally { if (e_11) throw e_11.error; }
|
|
464
|
+
}
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
if (typeof source !== 'object') {
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
var objectSource = source;
|
|
471
|
+
if (visited.has(objectSource)) {
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
visited.add(objectSource);
|
|
475
|
+
var normalizedId = normalizeId(objectSource._id);
|
|
476
|
+
if (normalizedId) {
|
|
477
|
+
ids.add(normalizedId);
|
|
478
|
+
}
|
|
479
|
+
try {
|
|
480
|
+
for (var _c = __values(Object.values(objectSource)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
481
|
+
var value = _d.value;
|
|
482
|
+
if (value && (typeof value === 'object' || Array.isArray(value))) {
|
|
483
|
+
collectIdsFromResult(value, ids, visited);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
488
|
+
finally {
|
|
489
|
+
try {
|
|
490
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
491
|
+
}
|
|
492
|
+
finally { if (e_12) throw e_12.error; }
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
function collectIdsFromFilter(filter, ids) {
|
|
496
|
+
var e_13, _a, e_14, _b, e_15, _c;
|
|
497
|
+
if (!filter) {
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
if (Array.isArray(filter)) {
|
|
501
|
+
try {
|
|
502
|
+
for (var filter_1 = __values(filter), filter_1_1 = filter_1.next(); !filter_1_1.done; filter_1_1 = filter_1.next()) {
|
|
503
|
+
var item = filter_1_1.value;
|
|
504
|
+
collectIdsFromFilter(item, ids);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
508
|
+
finally {
|
|
509
|
+
try {
|
|
510
|
+
if (filter_1_1 && !filter_1_1.done && (_a = filter_1.return)) _a.call(filter_1);
|
|
511
|
+
}
|
|
512
|
+
finally { if (e_13) throw e_13.error; }
|
|
513
|
+
}
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
if (typeof filter !== 'object') {
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
var filterObject = filter;
|
|
520
|
+
if (filterObject._id !== undefined) {
|
|
521
|
+
collectIdsFromFilterValue(filterObject._id, ids);
|
|
522
|
+
}
|
|
523
|
+
try {
|
|
524
|
+
for (var _d = __values(Object.entries(filterObject)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
525
|
+
var _f = __read(_e.value, 2), key = _f[0], value = _f[1];
|
|
526
|
+
if (key === '$or' || key === '$and' || key === '$nor') {
|
|
527
|
+
if (Array.isArray(value)) {
|
|
528
|
+
try {
|
|
529
|
+
for (var value_2 = (e_15 = void 0, __values(value)), value_2_1 = value_2.next(); !value_2_1.done; value_2_1 = value_2.next()) {
|
|
530
|
+
var item = value_2_1.value;
|
|
531
|
+
collectIdsFromFilter(item, ids);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
535
|
+
finally {
|
|
536
|
+
try {
|
|
537
|
+
if (value_2_1 && !value_2_1.done && (_c = value_2.return)) _c.call(value_2);
|
|
538
|
+
}
|
|
539
|
+
finally { if (e_15) throw e_15.error; }
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
else if (key !== '_id' && value && typeof value === 'object') {
|
|
544
|
+
collectIdsFromFilter(value, ids);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
549
|
+
finally {
|
|
550
|
+
try {
|
|
551
|
+
if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
|
|
552
|
+
}
|
|
553
|
+
finally { if (e_14) throw e_14.error; }
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
function collectIdsFromFilterValue(value, ids) {
|
|
557
|
+
var e_16, _a, e_17, _b;
|
|
558
|
+
if (value === null || value === undefined) {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
if (Array.isArray(value)) {
|
|
562
|
+
try {
|
|
563
|
+
for (var value_3 = __values(value), value_3_1 = value_3.next(); !value_3_1.done; value_3_1 = value_3.next()) {
|
|
564
|
+
var item = value_3_1.value;
|
|
565
|
+
collectIdsFromFilterValue(item, ids);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
569
|
+
finally {
|
|
570
|
+
try {
|
|
571
|
+
if (value_3_1 && !value_3_1.done && (_a = value_3.return)) _a.call(value_3);
|
|
572
|
+
}
|
|
573
|
+
finally { if (e_16) throw e_16.error; }
|
|
574
|
+
}
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
if (typeof value === 'object') {
|
|
578
|
+
try {
|
|
579
|
+
for (var _c = __values(Object.entries(value)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
580
|
+
var _e = __read(_d.value, 2), key = _e[0], inner = _e[1];
|
|
581
|
+
if (key === '$in' || key === '$nin' || key === '$all') {
|
|
582
|
+
collectIdsFromFilterValue(inner, ids);
|
|
583
|
+
}
|
|
584
|
+
else if (key === '$eq' || key === '$ne') {
|
|
585
|
+
collectIdsFromFilterValue(inner, ids);
|
|
586
|
+
}
|
|
587
|
+
else if (key === '$or' || key === '$and' || key === '$nor') {
|
|
588
|
+
collectIdsFromFilterValue(inner, ids);
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
collectIdsFromFilterValue(inner, ids);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
596
|
+
finally {
|
|
597
|
+
try {
|
|
598
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
599
|
+
}
|
|
600
|
+
finally { if (e_17) throw e_17.error; }
|
|
601
|
+
}
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
var normalized = normalizeId(value);
|
|
605
|
+
if (normalized) {
|
|
606
|
+
ids.add(normalized);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
function normalizeId(value) {
|
|
610
|
+
if (value === null || value === undefined) {
|
|
611
|
+
return null;
|
|
612
|
+
}
|
|
613
|
+
if (typeof value === 'string') {
|
|
614
|
+
var trimmed = value.trim();
|
|
615
|
+
return trimmed.length ? trimmed : null;
|
|
616
|
+
}
|
|
617
|
+
if (typeof value === 'number' || typeof value === 'bigint') {
|
|
618
|
+
return value.toString();
|
|
619
|
+
}
|
|
620
|
+
if (typeof value === 'object') {
|
|
621
|
+
var objValue = value;
|
|
622
|
+
if (typeof objValue.toHexString === 'function') {
|
|
623
|
+
return objValue.toHexString();
|
|
624
|
+
}
|
|
625
|
+
if (value instanceof Date) {
|
|
626
|
+
return value.toISOString();
|
|
627
|
+
}
|
|
628
|
+
if (typeof objValue.toString === 'function') {
|
|
629
|
+
var str = objValue.toString();
|
|
630
|
+
if (str && str !== '[object Object]') {
|
|
631
|
+
return str;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
return null;
|
|
636
|
+
}
|
|
637
|
+
function cloneDependencyMap(original) {
|
|
638
|
+
var e_18, _a;
|
|
639
|
+
var cloned = new Map();
|
|
640
|
+
try {
|
|
641
|
+
for (var _b = __values(original.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
642
|
+
var _d = __read(_c.value, 2), collection = _d[0], ids = _d[1];
|
|
643
|
+
cloned.set(collection, new Set(ids));
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
catch (e_18_1) { e_18 = { error: e_18_1 }; }
|
|
647
|
+
finally {
|
|
648
|
+
try {
|
|
649
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
650
|
+
}
|
|
651
|
+
finally { if (e_18) throw e_18.error; }
|
|
652
|
+
}
|
|
653
|
+
return cloned;
|
|
654
|
+
}
|
|
655
|
+
function cloneFilterMap(original) {
|
|
656
|
+
var e_19, _a;
|
|
657
|
+
var cloned = new Map();
|
|
658
|
+
try {
|
|
659
|
+
for (var _b = __values(original.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
660
|
+
var _d = __read(_c.value, 2), collection = _d[0], filters = _d[1];
|
|
661
|
+
cloned.set(collection, filters.map(function (filter) { return (0, common_1.deepCopy)(filter); }));
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
catch (e_19_1) { e_19 = { error: e_19_1 }; }
|
|
665
|
+
finally {
|
|
666
|
+
try {
|
|
667
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
668
|
+
}
|
|
669
|
+
finally { if (e_19) throw e_19.error; }
|
|
670
|
+
}
|
|
671
|
+
return cloned;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
//# sourceMappingURL=subscription-dependency-context.js.map
|