@graphrefly/graphrefly 0.26.0 → 0.27.0
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/dist/ai-CaR_912Q.d.cts +1033 -0
- package/dist/ai-WlRltJV7.d.ts +1033 -0
- package/dist/audit-ClmqGOCx.d.cts +245 -0
- package/dist/audit-DRlSzBu9.d.ts +245 -0
- package/dist/{chunk-JYXEWPH4.js → chunk-APFNLIRG.js} +2 -2
- package/dist/chunk-AT5LKYNL.js +395 -0
- package/dist/chunk-AT5LKYNL.js.map +1 -0
- package/dist/{chunk-AMCG74RZ.js → chunk-BQ6RQQFF.js} +215 -2128
- package/dist/chunk-BQ6RQQFF.js.map +1 -0
- package/dist/{chunk-IZYUSJC7.js → chunk-DST5DKZS.js} +6 -4
- package/dist/{chunk-IZYUSJC7.js.map → chunk-DST5DKZS.js.map} +1 -1
- package/dist/{chunk-LCE3GF5P.js → chunk-GTE6PWRZ.js} +2 -2
- package/dist/{chunk-RB6QPHJ7.js → chunk-J2VBW3DZ.js} +2 -93
- package/dist/chunk-J2VBW3DZ.js.map +1 -0
- package/dist/{chunk-FQMKGR6L.js → chunk-JWBCY4NC.js} +3 -3
- package/dist/chunk-K2AUJHVP.js +2251 -0
- package/dist/chunk-K2AUJHVP.js.map +1 -0
- package/dist/chunk-NC6S43JJ.js +456 -0
- package/dist/chunk-NC6S43JJ.js.map +1 -0
- package/dist/chunk-OFVJBJXR.js +98 -0
- package/dist/chunk-OFVJBJXR.js.map +1 -0
- package/dist/{chunk-6LDQFTYS.js → chunk-OU5CQKNW.js} +2 -2
- package/dist/{chunk-THTWHNU4.js → chunk-PF7GRZMW.js} +5 -5
- package/dist/chunk-RNHBMHKA.js +1665 -0
- package/dist/chunk-RNHBMHKA.js.map +1 -0
- package/dist/{chunk-SN4YWWYO.js → chunk-WBZOVTYK.js} +11 -11
- package/dist/chunk-WKNUIZOY.js +354 -0
- package/dist/chunk-WKNUIZOY.js.map +1 -0
- package/dist/{chunk-ZQMEI34O.js → chunk-X3VMZYBT.js} +3 -3
- package/dist/chunk-X5R3GL6H.js +525 -0
- package/dist/chunk-X5R3GL6H.js.map +1 -0
- package/dist/compat/index.d.cts +14 -14
- package/dist/compat/index.d.ts +14 -14
- package/dist/compat/index.js +17 -16
- package/dist/compat/jotai/index.d.cts +2 -2
- package/dist/compat/jotai/index.d.ts +2 -2
- package/dist/compat/nanostores/index.d.cts +2 -2
- package/dist/compat/nanostores/index.d.ts +2 -2
- package/dist/compat/nestjs/index.d.cts +6 -6
- package/dist/compat/nestjs/index.d.ts +6 -6
- package/dist/compat/nestjs/index.js +7 -6
- package/dist/compat/react/index.d.cts +2 -2
- package/dist/compat/react/index.d.ts +2 -2
- package/dist/compat/solid/index.d.cts +2 -2
- package/dist/compat/solid/index.d.ts +2 -2
- package/dist/compat/svelte/index.d.cts +2 -2
- package/dist/compat/svelte/index.d.ts +2 -2
- package/dist/compat/vue/index.d.cts +2 -2
- package/dist/compat/vue/index.d.ts +2 -2
- package/dist/compat/zustand/index.d.cts +5 -5
- package/dist/compat/zustand/index.d.ts +5 -5
- package/dist/compat/zustand/index.js +3 -3
- package/dist/composite-C7PcQvcs.d.cts +303 -0
- package/dist/composite-aUCvjZVR.d.ts +303 -0
- package/dist/core/index.d.cts +4 -3
- package/dist/core/index.d.ts +4 -3
- package/dist/{demo-shell-DEp-nMTl.d.ts → demo-shell-BDkOptd6.d.ts} +2 -2
- package/dist/{demo-shell-26p5fVxn.d.cts → demo-shell-Crid1WdR.d.cts} +2 -2
- package/dist/extra/index.d.cts +5 -4
- package/dist/extra/index.d.ts +5 -4
- package/dist/extra/index.js +68 -62
- package/dist/extra/sources.d.cts +1 -1
- package/dist/extra/sources.d.ts +1 -1
- package/dist/graph/index.d.cts +5 -5
- package/dist/graph/index.d.ts +5 -5
- package/dist/graph/index.js +3 -3
- package/dist/{graph-DQ69XU0g.d.ts → graph-CCwGKLCm.d.ts} +4 -4
- package/dist/{graph-6tZ5jEzr.d.cts → graph-DNCrvZSn.d.cts} +4 -4
- package/dist/{index-qldRdbQw.d.ts → index-3lsddbbS.d.ts} +1 -1
- package/dist/{index-Bxb5ZYc9.d.cts → index-B1tloyhO.d.cts} +1 -1
- package/dist/{index-eJ6T_qGM.d.ts → index-B6D3QNSA.d.ts} +2 -2
- package/dist/{index-B4MP_8V_.d.cts → index-B6EhDnjH.d.cts} +1 -1
- package/dist/{index-CmnuOibw.d.ts → index-B9B7_HEY.d.ts} +1 -1
- package/dist/{index-BeIdBfcb.d.cts → index-BHlKbUwO.d.cts} +16 -315
- package/dist/{index-CuYwdKO-.d.ts → index-BPVt8kqc.d.ts} +3 -3
- package/dist/index-BaSM3aYt.d.ts +195 -0
- package/dist/{index-BjI6ty9z.d.ts → index-BuEoe-Qu.d.ts} +9 -9
- package/dist/{index-DdD5MVDL.d.ts → index-BwfLUNw4.d.ts} +16 -315
- package/dist/{index-QBpffFW-.d.cts → index-ByQxazQJ.d.cts} +1 -1
- package/dist/{index-xdGjv0nO.d.ts → index-C0svESO4.d.ts} +1 -1
- package/dist/{index-BW1z3BN9.d.ts → index-C8oil6M6.d.ts} +3 -3
- package/dist/{index-C8mdwMXc.d.cts → index-CI3DprxP.d.cts} +3 -3
- package/dist/{index-CUwyr1Kk.d.cts → index-CO8uBlUh.d.cts} +2 -2
- package/dist/{index-DrISNAOm.d.ts → index-CxFrXH4m.d.ts} +1 -1
- package/dist/{index-BEfE8H_G.d.cts → index-D8wS_PeY.d.cts} +9 -9
- package/dist/{index-CUyrtuOf.d.cts → index-DO_6JN9Z.d.cts} +1 -1
- package/dist/index-DVGiGFGT.d.cts +195 -0
- package/dist/{index-DFhjO4Gg.d.cts → index-DYme44FM.d.cts} +1 -1
- package/dist/{index-_oMEWlDq.d.cts → index-DlLp-2Xn.d.cts} +3 -3
- package/dist/{index-CPgZ5wRl.d.ts → index-Dzk2hrlR.d.ts} +1 -1
- package/dist/{index-Bd_fwmLf.d.cts → index-VHqptjhu.d.cts} +1 -1
- package/dist/{index-CDAjUFIv.d.ts → index-VdHQMPy1.d.ts} +1 -1
- package/dist/{index-B_IP40nB.d.cts → index-Xi3u0HCQ.d.cts} +1 -1
- package/dist/{index-BYOHF0zP.d.ts → index-wEn0eFe8.d.ts} +1 -1
- package/dist/index.d.cts +35 -1692
- package/dist/index.d.ts +35 -1692
- package/dist/index.js +307 -3731
- package/dist/index.js.map +1 -1
- package/dist/memory-C6Z2tGpC.d.cts +139 -0
- package/dist/memory-li6FL5RM.d.ts +139 -0
- package/dist/messaging-Gt4LPbyA.d.cts +269 -0
- package/dist/messaging-XDoYablx.d.ts +269 -0
- package/dist/{meta-C0-8XW6Q.d.cts → meta-BxCA7rcr.d.cts} +1 -1
- package/dist/{meta-BGqSZ7mt.d.ts → meta-CbznRPYJ.d.ts} +1 -1
- package/dist/{node-C_IBuvX2.d.cts → node-BmerH3kS.d.cts} +1 -1
- package/dist/{node-C_IBuvX2.d.ts → node-BmerH3kS.d.ts} +1 -1
- package/dist/{observable-DCk45RH5.d.ts → observable-BgGUwcqp.d.ts} +1 -1
- package/dist/{observable-Crr1jgzx.d.cts → observable-DJt_AxzQ.d.cts} +1 -1
- package/dist/patterns/ai.cjs +7930 -0
- package/dist/patterns/ai.cjs.map +1 -0
- package/dist/patterns/ai.d.cts +10 -0
- package/dist/patterns/ai.d.ts +10 -0
- package/dist/patterns/ai.js +71 -0
- package/dist/patterns/ai.js.map +1 -0
- package/dist/patterns/audit.cjs +5805 -0
- package/dist/patterns/audit.cjs.map +1 -0
- package/dist/patterns/audit.d.cts +6 -0
- package/dist/patterns/audit.d.ts +6 -0
- package/dist/patterns/audit.js +29 -0
- package/dist/patterns/audit.js.map +1 -0
- package/dist/patterns/demo-shell.d.cts +6 -6
- package/dist/patterns/demo-shell.d.ts +6 -6
- package/dist/patterns/demo-shell.js +4 -4
- package/dist/patterns/memory.cjs +5283 -0
- package/dist/patterns/memory.cjs.map +1 -0
- package/dist/patterns/memory.d.cts +5 -0
- package/dist/patterns/memory.d.ts +5 -0
- package/dist/patterns/memory.js +20 -0
- package/dist/patterns/memory.js.map +1 -0
- package/dist/patterns/reactive-layout/index.d.cts +6 -6
- package/dist/patterns/reactive-layout/index.d.ts +6 -6
- package/dist/patterns/reactive-layout/index.js +4 -4
- package/dist/{reactive-layout-BaOQefHu.d.cts → reactive-layout-MQP--J3F.d.cts} +2 -2
- package/dist/{reactive-layout-D9gejYXE.d.ts → reactive-layout-u5Ulnqag.d.ts} +2 -2
- package/dist/{storage-BMycWEh2.d.ts → storage-CMjUUuxn.d.ts} +2 -2
- package/dist/{storage-DiqWHzVI.d.cts → storage-DdWlZo6U.d.cts} +2 -2
- package/dist/sugar-CCOxXK1e.d.ts +201 -0
- package/dist/sugar-D02n5JjF.d.cts +201 -0
- package/package.json +32 -2
- package/dist/chunk-AMCG74RZ.js.map +0 -1
- package/dist/chunk-RB6QPHJ7.js.map +0 -1
- package/dist/index-C0ZXMaXO.d.cts +0 -392
- package/dist/index-CY2TljO4.d.ts +0 -392
- /package/dist/{chunk-JYXEWPH4.js.map → chunk-APFNLIRG.js.map} +0 -0
- /package/dist/{chunk-LCE3GF5P.js.map → chunk-GTE6PWRZ.js.map} +0 -0
- /package/dist/{chunk-FQMKGR6L.js.map → chunk-JWBCY4NC.js.map} +0 -0
- /package/dist/{chunk-6LDQFTYS.js.map → chunk-OU5CQKNW.js.map} +0 -0
- /package/dist/{chunk-THTWHNU4.js.map → chunk-PF7GRZMW.js.map} +0 -0
- /package/dist/{chunk-SN4YWWYO.js.map → chunk-WBZOVTYK.js.map} +0 -0
- /package/dist/{chunk-ZQMEI34O.js.map → chunk-X3VMZYBT.js.map} +0 -0
|
@@ -1,9 +1,76 @@
|
|
|
1
1
|
import {
|
|
2
|
-
NativeLogBackend,
|
|
3
2
|
createWatermarkController,
|
|
4
|
-
reactiveLog,
|
|
5
3
|
toObservable
|
|
6
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-OFVJBJXR.js";
|
|
5
|
+
import {
|
|
6
|
+
NS_PER_MS,
|
|
7
|
+
NS_PER_SEC,
|
|
8
|
+
audit,
|
|
9
|
+
buffer,
|
|
10
|
+
bufferCount,
|
|
11
|
+
bufferTime,
|
|
12
|
+
catchError,
|
|
13
|
+
combine,
|
|
14
|
+
combineLatest,
|
|
15
|
+
concat,
|
|
16
|
+
concatMap,
|
|
17
|
+
constant,
|
|
18
|
+
debounce,
|
|
19
|
+
debounceTime,
|
|
20
|
+
decorrelatedJitter,
|
|
21
|
+
delay,
|
|
22
|
+
distill,
|
|
23
|
+
distinctUntilChanged,
|
|
24
|
+
elementAt,
|
|
25
|
+
exhaustMap,
|
|
26
|
+
exponential,
|
|
27
|
+
fibonacci,
|
|
28
|
+
filter,
|
|
29
|
+
find,
|
|
30
|
+
first,
|
|
31
|
+
flatMap,
|
|
32
|
+
interval,
|
|
33
|
+
last,
|
|
34
|
+
linear,
|
|
35
|
+
map,
|
|
36
|
+
merge,
|
|
37
|
+
mergeMap,
|
|
38
|
+
pairwise,
|
|
39
|
+
pausable,
|
|
40
|
+
race,
|
|
41
|
+
reduce,
|
|
42
|
+
repeat,
|
|
43
|
+
rescue,
|
|
44
|
+
resolveBackoffPreset,
|
|
45
|
+
sample,
|
|
46
|
+
scan,
|
|
47
|
+
skip,
|
|
48
|
+
switchMap,
|
|
49
|
+
take,
|
|
50
|
+
takeUntil,
|
|
51
|
+
takeWhile,
|
|
52
|
+
tap,
|
|
53
|
+
throttle,
|
|
54
|
+
throttleTime,
|
|
55
|
+
valve,
|
|
56
|
+
verifiable,
|
|
57
|
+
window,
|
|
58
|
+
windowCount,
|
|
59
|
+
windowTime,
|
|
60
|
+
withLatestFrom,
|
|
61
|
+
withMaxAttempts,
|
|
62
|
+
zip
|
|
63
|
+
} from "./chunk-RNHBMHKA.js";
|
|
64
|
+
import {
|
|
65
|
+
NativeListBackend,
|
|
66
|
+
NativeMapBackend,
|
|
67
|
+
reactiveList,
|
|
68
|
+
reactiveMap
|
|
69
|
+
} from "./chunk-WKNUIZOY.js";
|
|
70
|
+
import {
|
|
71
|
+
NativeLogBackend,
|
|
72
|
+
reactiveLog
|
|
73
|
+
} from "./chunk-J2VBW3DZ.js";
|
|
7
74
|
import {
|
|
8
75
|
cached,
|
|
9
76
|
empty,
|
|
@@ -57,7 +124,6 @@ import {
|
|
|
57
124
|
PAUSE,
|
|
58
125
|
RESOLVED,
|
|
59
126
|
RESUME,
|
|
60
|
-
START,
|
|
61
127
|
TEARDOWN,
|
|
62
128
|
__export,
|
|
63
129
|
__require
|
|
@@ -249,99 +315,6 @@ __export(extra_exports, {
|
|
|
249
315
|
zip: () => zip
|
|
250
316
|
});
|
|
251
317
|
|
|
252
|
-
// src/extra/backoff.ts
|
|
253
|
-
var NS_PER_MS = 1e6;
|
|
254
|
-
var NS_PER_SEC = 1e9;
|
|
255
|
-
function clampNonNegative(value) {
|
|
256
|
-
return value < 0 ? 0 : value;
|
|
257
|
-
}
|
|
258
|
-
function applyJitter(delay2, jitter) {
|
|
259
|
-
if (jitter === "none") return delay2;
|
|
260
|
-
if (jitter === "full") return Math.random() * delay2;
|
|
261
|
-
return delay2 / 2 + Math.random() * (delay2 / 2);
|
|
262
|
-
}
|
|
263
|
-
function randomBetween(min, max) {
|
|
264
|
-
return min + Math.random() * (max - min);
|
|
265
|
-
}
|
|
266
|
-
function constant(delayNs) {
|
|
267
|
-
const safe = clampNonNegative(delayNs);
|
|
268
|
-
return () => safe;
|
|
269
|
-
}
|
|
270
|
-
function linear(baseNs, stepNs) {
|
|
271
|
-
const safeBase = clampNonNegative(baseNs);
|
|
272
|
-
const safeStep = stepNs === void 0 ? safeBase : clampNonNegative(stepNs);
|
|
273
|
-
return (attempt) => safeBase + safeStep * Math.max(0, attempt);
|
|
274
|
-
}
|
|
275
|
-
function exponential(options) {
|
|
276
|
-
const baseNs = clampNonNegative(options?.baseNs ?? 100 * NS_PER_MS);
|
|
277
|
-
const factor = options?.factor !== void 0 && options.factor < 1 ? 1 : options?.factor ?? 2;
|
|
278
|
-
const maxDelayNs = clampNonNegative(options?.maxDelayNs ?? 30 * NS_PER_SEC);
|
|
279
|
-
const jitter = options?.jitter ?? "none";
|
|
280
|
-
return (attempt) => {
|
|
281
|
-
let delay2;
|
|
282
|
-
if (baseNs === 0) {
|
|
283
|
-
delay2 = 0;
|
|
284
|
-
} else if (factor === 1) {
|
|
285
|
-
delay2 = baseNs;
|
|
286
|
-
} else {
|
|
287
|
-
const capRatio = maxDelayNs / baseNs;
|
|
288
|
-
let growth = 1;
|
|
289
|
-
for (let i = 0; i < Math.max(0, attempt); i++) {
|
|
290
|
-
if (growth >= capRatio) {
|
|
291
|
-
growth = capRatio;
|
|
292
|
-
break;
|
|
293
|
-
}
|
|
294
|
-
growth *= factor;
|
|
295
|
-
}
|
|
296
|
-
delay2 = baseNs * growth;
|
|
297
|
-
if (delay2 > maxDelayNs) delay2 = maxDelayNs;
|
|
298
|
-
}
|
|
299
|
-
return applyJitter(delay2, jitter);
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
function fibonacci(baseNs = 100 * NS_PER_MS, maxDelayNs = 30 * NS_PER_SEC) {
|
|
303
|
-
const safeBase = clampNonNegative(baseNs);
|
|
304
|
-
const safeMax = clampNonNegative(maxDelayNs);
|
|
305
|
-
function fibUnit(attempt) {
|
|
306
|
-
if (attempt <= 0) return 1;
|
|
307
|
-
let prev = 1;
|
|
308
|
-
let cur = 2;
|
|
309
|
-
for (let i = 1; i < attempt; i++) {
|
|
310
|
-
const next = prev + cur;
|
|
311
|
-
prev = cur;
|
|
312
|
-
cur = next;
|
|
313
|
-
}
|
|
314
|
-
return cur;
|
|
315
|
-
}
|
|
316
|
-
return (attempt) => {
|
|
317
|
-
const raw = fibUnit(attempt) * safeBase;
|
|
318
|
-
return raw <= safeMax ? raw : safeMax;
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
function decorrelatedJitter(baseNs = 100 * NS_PER_MS, maxNs = 30 * NS_PER_SEC) {
|
|
322
|
-
return (_attempt, _error, prevDelayNs) => {
|
|
323
|
-
const last2 = prevDelayNs ?? baseNs;
|
|
324
|
-
const ceiling = Math.min(maxNs, last2 * 3);
|
|
325
|
-
return randomBetween(baseNs, ceiling);
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
function withMaxAttempts(strategy, maxAttempts) {
|
|
329
|
-
return (attempt, error, prevDelayNs) => {
|
|
330
|
-
if (attempt >= maxAttempts) return null;
|
|
331
|
-
return strategy(attempt, error, prevDelayNs);
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
function resolveBackoffPreset(name) {
|
|
335
|
-
if (name === "constant") return constant(1 * NS_PER_SEC);
|
|
336
|
-
if (name === "linear") return linear(1 * NS_PER_SEC);
|
|
337
|
-
if (name === "exponential") return exponential();
|
|
338
|
-
if (name === "fibonacci") return fibonacci();
|
|
339
|
-
if (name === "decorrelatedJitter") return decorrelatedJitter();
|
|
340
|
-
throw new Error(
|
|
341
|
-
`Unknown backoff preset: "${String(name)}". Use one of: constant, linear, exponential, fibonacci, decorrelatedJitter`
|
|
342
|
-
);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
318
|
// src/extra/external-register.ts
|
|
346
319
|
function sourceOpts(opts) {
|
|
347
320
|
return { describeKind: "producer", ...opts };
|
|
@@ -406,1392 +379,57 @@ function externalBundle(register, channels, opts) {
|
|
|
406
379
|
(_a) => {
|
|
407
380
|
activatedCount++;
|
|
408
381
|
return () => {
|
|
409
|
-
teardownCount++;
|
|
410
|
-
if (activatedCount > 0 && teardownCount >= activatedCount && teardownCount >= channels.length) {
|
|
411
|
-
finishCleanup();
|
|
412
|
-
}
|
|
413
|
-
};
|
|
414
|
-
},
|
|
415
|
-
sourceOpts({ ...chOpts, name })
|
|
416
|
-
);
|
|
417
|
-
nodes[ch] = n;
|
|
418
|
-
channelNodes.push(n);
|
|
419
|
-
}
|
|
420
|
-
const bundle = {};
|
|
421
|
-
for (const ch of channels) {
|
|
422
|
-
bundle[ch] = (value) => {
|
|
423
|
-
if (!active) return;
|
|
424
|
-
nodes[ch].down([[DATA, value]]);
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
bundle.error = (err) => {
|
|
428
|
-
if (!active) return;
|
|
429
|
-
active = false;
|
|
430
|
-
batch(() => {
|
|
431
|
-
for (const n of channelNodes) n.down([[ERROR, err]]);
|
|
432
|
-
});
|
|
433
|
-
finishCleanup();
|
|
434
|
-
};
|
|
435
|
-
bundle.complete = () => {
|
|
436
|
-
if (!active) return;
|
|
437
|
-
active = false;
|
|
438
|
-
batch(() => {
|
|
439
|
-
for (const n of channelNodes) n.down([[COMPLETE]]);
|
|
440
|
-
});
|
|
441
|
-
finishCleanup();
|
|
442
|
-
};
|
|
443
|
-
const ret = register(bundle);
|
|
444
|
-
cleanup = typeof ret === "function" ? ret : void 0;
|
|
445
|
-
const dispose = () => {
|
|
446
|
-
if (!active) return;
|
|
447
|
-
active = false;
|
|
448
|
-
batch(() => {
|
|
449
|
-
for (const n of channelNodes) {
|
|
450
|
-
try {
|
|
451
|
-
n.down([[COMPLETE]]);
|
|
452
|
-
} catch {
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
});
|
|
456
|
-
finishCleanup();
|
|
457
|
-
};
|
|
458
|
-
return Object.assign(nodes, { dispose });
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
// src/extra/operators.ts
|
|
462
|
-
function operatorOpts(opts) {
|
|
463
|
-
return { describeKind: "derived", ...opts };
|
|
464
|
-
}
|
|
465
|
-
function map(source, project, opts) {
|
|
466
|
-
return node(
|
|
467
|
-
[source],
|
|
468
|
-
(data, a) => {
|
|
469
|
-
const batch0 = data[0];
|
|
470
|
-
if (batch0 == null || batch0.length === 0) {
|
|
471
|
-
a.down([[RESOLVED]]);
|
|
472
|
-
return;
|
|
473
|
-
}
|
|
474
|
-
for (const v of batch0) {
|
|
475
|
-
a.emit(project(v));
|
|
476
|
-
}
|
|
477
|
-
},
|
|
478
|
-
operatorOpts(opts)
|
|
479
|
-
);
|
|
480
|
-
}
|
|
481
|
-
function filter(source, predicate, opts) {
|
|
482
|
-
return node(
|
|
483
|
-
[source],
|
|
484
|
-
(data, a) => {
|
|
485
|
-
const batch0 = data[0];
|
|
486
|
-
if (batch0 == null || batch0.length === 0) {
|
|
487
|
-
a.down([[RESOLVED]]);
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
let emitted = false;
|
|
491
|
-
for (const v of batch0) {
|
|
492
|
-
if (predicate(v)) {
|
|
493
|
-
a.emit(v);
|
|
494
|
-
emitted = true;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
if (!emitted) a.down([[RESOLVED]]);
|
|
498
|
-
},
|
|
499
|
-
operatorOpts(opts)
|
|
500
|
-
);
|
|
501
|
-
}
|
|
502
|
-
function scan(source, reducer, seed, opts) {
|
|
503
|
-
return node(
|
|
504
|
-
[source],
|
|
505
|
-
(data, a, ctx) => {
|
|
506
|
-
if (!("acc" in ctx.store)) ctx.store.acc = seed;
|
|
507
|
-
const batch0 = data[0];
|
|
508
|
-
if (batch0 == null || batch0.length === 0) {
|
|
509
|
-
a.down([[RESOLVED]]);
|
|
510
|
-
return;
|
|
511
|
-
}
|
|
512
|
-
for (const v of batch0) {
|
|
513
|
-
ctx.store.acc = reducer(ctx.store.acc, v);
|
|
514
|
-
a.emit(ctx.store.acc);
|
|
515
|
-
}
|
|
516
|
-
},
|
|
517
|
-
{ ...operatorOpts(opts), initial: seed, resetOnTeardown: true }
|
|
518
|
-
);
|
|
519
|
-
}
|
|
520
|
-
function reduce(source, reducer, seed, opts) {
|
|
521
|
-
return node(
|
|
522
|
-
[source],
|
|
523
|
-
(data, a, ctx) => {
|
|
524
|
-
if (!("acc" in ctx.store)) ctx.store.acc = seed;
|
|
525
|
-
if (ctx.terminalDeps[0] === true) {
|
|
526
|
-
a.emit(ctx.store.acc);
|
|
527
|
-
a.down([[COMPLETE]]);
|
|
528
|
-
return;
|
|
529
|
-
}
|
|
530
|
-
const batch0 = data[0];
|
|
531
|
-
if (batch0 == null || batch0.length === 0) {
|
|
532
|
-
a.down([[RESOLVED]]);
|
|
533
|
-
return;
|
|
534
|
-
}
|
|
535
|
-
for (const v of batch0) {
|
|
536
|
-
ctx.store.acc = reducer(ctx.store.acc, v);
|
|
537
|
-
}
|
|
538
|
-
},
|
|
539
|
-
{
|
|
540
|
-
...operatorOpts(opts),
|
|
541
|
-
completeWhenDepsComplete: false
|
|
542
|
-
}
|
|
543
|
-
);
|
|
544
|
-
}
|
|
545
|
-
function take(source, count, opts) {
|
|
546
|
-
if (count <= 0) {
|
|
547
|
-
return node(
|
|
548
|
-
[source],
|
|
549
|
-
(_d, a, ctx) => {
|
|
550
|
-
if (ctx.store.completed) return;
|
|
551
|
-
ctx.store.completed = true;
|
|
552
|
-
a.down([[COMPLETE]]);
|
|
553
|
-
},
|
|
554
|
-
{
|
|
555
|
-
...operatorOpts(opts),
|
|
556
|
-
completeWhenDepsComplete: false
|
|
557
|
-
}
|
|
558
|
-
);
|
|
559
|
-
}
|
|
560
|
-
return node(
|
|
561
|
-
[source],
|
|
562
|
-
(data, a, ctx) => {
|
|
563
|
-
if (!("taken" in ctx.store)) ctx.store.taken = 0;
|
|
564
|
-
if (ctx.store.done) {
|
|
565
|
-
a.down([[RESOLVED]]);
|
|
566
|
-
return;
|
|
567
|
-
}
|
|
568
|
-
if (ctx.terminalDeps[0] === true) {
|
|
569
|
-
ctx.store.done = true;
|
|
570
|
-
a.down([[COMPLETE]]);
|
|
571
|
-
return;
|
|
572
|
-
}
|
|
573
|
-
const batch0 = data[0];
|
|
574
|
-
if (batch0 == null || batch0.length === 0) {
|
|
575
|
-
a.down([[RESOLVED]]);
|
|
576
|
-
return;
|
|
577
|
-
}
|
|
578
|
-
for (const v of batch0) {
|
|
579
|
-
ctx.store.taken++;
|
|
580
|
-
a.emit(v);
|
|
581
|
-
if (ctx.store.taken >= count) {
|
|
582
|
-
ctx.store.done = true;
|
|
583
|
-
a.down([[COMPLETE]]);
|
|
584
|
-
return;
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
},
|
|
588
|
-
{
|
|
589
|
-
...operatorOpts(opts),
|
|
590
|
-
completeWhenDepsComplete: false
|
|
591
|
-
}
|
|
592
|
-
);
|
|
593
|
-
}
|
|
594
|
-
function skip(source, count, opts) {
|
|
595
|
-
return node(
|
|
596
|
-
[source],
|
|
597
|
-
(data, a, ctx) => {
|
|
598
|
-
if (!("skipped" in ctx.store)) ctx.store.skipped = 0;
|
|
599
|
-
const batch0 = data[0];
|
|
600
|
-
if (batch0 == null || batch0.length === 0) {
|
|
601
|
-
a.down([[RESOLVED]]);
|
|
602
|
-
return;
|
|
603
|
-
}
|
|
604
|
-
let emitted = false;
|
|
605
|
-
for (const v of batch0) {
|
|
606
|
-
ctx.store.skipped++;
|
|
607
|
-
if (ctx.store.skipped <= count) {
|
|
608
|
-
} else {
|
|
609
|
-
a.emit(v);
|
|
610
|
-
emitted = true;
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
if (!emitted) a.down([[RESOLVED]]);
|
|
614
|
-
},
|
|
615
|
-
operatorOpts(opts)
|
|
616
|
-
);
|
|
617
|
-
}
|
|
618
|
-
function takeWhile(source, predicate, opts) {
|
|
619
|
-
return node(
|
|
620
|
-
[source],
|
|
621
|
-
(data, a, ctx) => {
|
|
622
|
-
if (ctx.store.done) {
|
|
623
|
-
a.down([[RESOLVED]]);
|
|
624
|
-
return;
|
|
625
|
-
}
|
|
626
|
-
const batch0 = data[0];
|
|
627
|
-
if (batch0 == null || batch0.length === 0) {
|
|
628
|
-
a.down([[RESOLVED]]);
|
|
629
|
-
return;
|
|
630
|
-
}
|
|
631
|
-
for (const v of batch0) {
|
|
632
|
-
if (!predicate(v)) {
|
|
633
|
-
ctx.store.done = true;
|
|
634
|
-
a.down([[COMPLETE]]);
|
|
635
|
-
return;
|
|
636
|
-
}
|
|
637
|
-
a.emit(v);
|
|
638
|
-
}
|
|
639
|
-
},
|
|
640
|
-
{
|
|
641
|
-
...operatorOpts(opts),
|
|
642
|
-
completeWhenDepsComplete: false
|
|
643
|
-
}
|
|
644
|
-
);
|
|
645
|
-
}
|
|
646
|
-
function takeUntil(source, notifier, opts) {
|
|
647
|
-
const pred = opts?.predicate ?? ((m) => m[0] === DATA);
|
|
648
|
-
const { predicate: _, ...restOpts } = opts ?? {};
|
|
649
|
-
return producer(
|
|
650
|
-
(a) => {
|
|
651
|
-
let stopped = false;
|
|
652
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
653
|
-
if (stopped) return;
|
|
654
|
-
for (const m of msgs) {
|
|
655
|
-
if (stopped) return;
|
|
656
|
-
if (m[0] === DATA) a.emit(m[1]);
|
|
657
|
-
else if (m[0] === COMPLETE || m[0] === ERROR) {
|
|
658
|
-
stopped = true;
|
|
659
|
-
a.down([m]);
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
});
|
|
663
|
-
const notUnsub = notifier.subscribe((msgs) => {
|
|
664
|
-
if (stopped) return;
|
|
665
|
-
for (const m of msgs) {
|
|
666
|
-
if (stopped) return;
|
|
667
|
-
if (pred(m)) {
|
|
668
|
-
stopped = true;
|
|
669
|
-
a.down([[COMPLETE]]);
|
|
670
|
-
return;
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
});
|
|
674
|
-
return () => {
|
|
675
|
-
srcUnsub();
|
|
676
|
-
notUnsub();
|
|
677
|
-
};
|
|
678
|
-
},
|
|
679
|
-
operatorOpts(restOpts)
|
|
680
|
-
);
|
|
681
|
-
}
|
|
682
|
-
function first(source, opts) {
|
|
683
|
-
return take(source, 1, opts);
|
|
684
|
-
}
|
|
685
|
-
function last(source, options) {
|
|
686
|
-
const { defaultValue, ...rest } = options ?? {};
|
|
687
|
-
const useDefault = options != null && Object.hasOwn(options, "defaultValue");
|
|
688
|
-
return node(
|
|
689
|
-
[source],
|
|
690
|
-
(data, a, ctx) => {
|
|
691
|
-
if (ctx.terminalDeps[0] === true) {
|
|
692
|
-
if (ctx.store.has) {
|
|
693
|
-
a.emit(ctx.store.latest);
|
|
694
|
-
} else if (useDefault) {
|
|
695
|
-
a.emit(defaultValue);
|
|
696
|
-
}
|
|
697
|
-
a.down([[COMPLETE]]);
|
|
698
|
-
return;
|
|
699
|
-
}
|
|
700
|
-
const batch0 = data[0];
|
|
701
|
-
if (batch0 == null || batch0.length === 0) {
|
|
702
|
-
a.down([[RESOLVED]]);
|
|
703
|
-
return;
|
|
704
|
-
}
|
|
705
|
-
ctx.store.latest = batch0.at(-1);
|
|
706
|
-
ctx.store.has = true;
|
|
707
|
-
},
|
|
708
|
-
{
|
|
709
|
-
...operatorOpts(rest),
|
|
710
|
-
completeWhenDepsComplete: false
|
|
711
|
-
}
|
|
712
|
-
);
|
|
713
|
-
}
|
|
714
|
-
function find(source, predicate, opts) {
|
|
715
|
-
return take(filter(source, predicate, opts), 1, opts);
|
|
716
|
-
}
|
|
717
|
-
function elementAt(source, index, opts) {
|
|
718
|
-
return take(skip(source, index, opts), 1, opts);
|
|
719
|
-
}
|
|
720
|
-
function tap(source, fnOrObserver, opts) {
|
|
721
|
-
if (typeof fnOrObserver === "function") {
|
|
722
|
-
return node(
|
|
723
|
-
[source],
|
|
724
|
-
(data, a) => {
|
|
725
|
-
const batch0 = data[0];
|
|
726
|
-
if (batch0 == null || batch0.length === 0) {
|
|
727
|
-
a.down([[RESOLVED]]);
|
|
728
|
-
return;
|
|
729
|
-
}
|
|
730
|
-
for (const v of batch0) {
|
|
731
|
-
fnOrObserver(v);
|
|
732
|
-
a.emit(v);
|
|
733
|
-
}
|
|
734
|
-
},
|
|
735
|
-
operatorOpts(opts)
|
|
736
|
-
);
|
|
737
|
-
}
|
|
738
|
-
const obs = fnOrObserver;
|
|
739
|
-
return node(
|
|
740
|
-
[source],
|
|
741
|
-
(data, a, ctx) => {
|
|
742
|
-
if (ctx.terminalDeps[0] !== void 0) {
|
|
743
|
-
if (ctx.terminalDeps[0] === true) {
|
|
744
|
-
obs.complete?.();
|
|
745
|
-
a.down([[COMPLETE]]);
|
|
746
|
-
} else {
|
|
747
|
-
obs.error?.(ctx.terminalDeps[0]);
|
|
748
|
-
a.down([[ERROR, ctx.terminalDeps[0]]]);
|
|
749
|
-
}
|
|
750
|
-
return;
|
|
751
|
-
}
|
|
752
|
-
const batch0 = data[0];
|
|
753
|
-
if (batch0 == null || batch0.length === 0) {
|
|
754
|
-
a.down([[RESOLVED]]);
|
|
755
|
-
return;
|
|
756
|
-
}
|
|
757
|
-
for (const v of batch0) {
|
|
758
|
-
obs.data?.(v);
|
|
759
|
-
a.emit(v);
|
|
760
|
-
}
|
|
761
|
-
},
|
|
762
|
-
{
|
|
763
|
-
...operatorOpts(opts),
|
|
764
|
-
completeWhenDepsComplete: false
|
|
765
|
-
}
|
|
766
|
-
);
|
|
767
|
-
}
|
|
768
|
-
function distinctUntilChanged(source, equals = Object.is, opts) {
|
|
769
|
-
return node(
|
|
770
|
-
[source],
|
|
771
|
-
(data, a, ctx) => {
|
|
772
|
-
const batch0 = data[0];
|
|
773
|
-
if (batch0 == null || batch0.length === 0) {
|
|
774
|
-
a.down([[RESOLVED]]);
|
|
775
|
-
return;
|
|
776
|
-
}
|
|
777
|
-
let emitted = false;
|
|
778
|
-
for (const val of batch0) {
|
|
779
|
-
if (ctx.store.hasPrev && equals(ctx.store.prev, val)) {
|
|
780
|
-
} else {
|
|
781
|
-
ctx.store.prev = val;
|
|
782
|
-
ctx.store.hasPrev = true;
|
|
783
|
-
a.emit(val);
|
|
784
|
-
emitted = true;
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
if (!emitted) a.down([[RESOLVED]]);
|
|
788
|
-
},
|
|
789
|
-
operatorOpts(opts)
|
|
790
|
-
);
|
|
791
|
-
}
|
|
792
|
-
function pairwise(source, opts) {
|
|
793
|
-
return node(
|
|
794
|
-
[source],
|
|
795
|
-
(data, a, ctx) => {
|
|
796
|
-
const batch0 = data[0];
|
|
797
|
-
if (batch0 == null || batch0.length === 0) {
|
|
798
|
-
a.down([[RESOLVED]]);
|
|
799
|
-
return;
|
|
800
|
-
}
|
|
801
|
-
let emitted = false;
|
|
802
|
-
for (const x of batch0) {
|
|
803
|
-
if (!ctx.store.hasPrev) {
|
|
804
|
-
ctx.store.prev = x;
|
|
805
|
-
ctx.store.hasPrev = true;
|
|
806
|
-
} else {
|
|
807
|
-
const pair = [ctx.store.prev, x];
|
|
808
|
-
ctx.store.prev = x;
|
|
809
|
-
a.emit(pair);
|
|
810
|
-
emitted = true;
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
if (!emitted) a.down([[RESOLVED]]);
|
|
814
|
-
},
|
|
815
|
-
operatorOpts(opts)
|
|
816
|
-
);
|
|
817
|
-
}
|
|
818
|
-
function combine(...sources) {
|
|
819
|
-
const deps = [...sources];
|
|
820
|
-
return derived(deps, (vals) => vals, {
|
|
821
|
-
...operatorOpts(),
|
|
822
|
-
equals: (a, b) => {
|
|
823
|
-
if (a.length !== b.length) return false;
|
|
824
|
-
for (let i = 0; i < a.length; i++) {
|
|
825
|
-
if (!Object.is(a[i], b[i])) return false;
|
|
826
|
-
}
|
|
827
|
-
return true;
|
|
828
|
-
}
|
|
829
|
-
});
|
|
830
|
-
}
|
|
831
|
-
function withLatestFrom(primary, secondary, opts) {
|
|
832
|
-
return node(
|
|
833
|
-
[primary, secondary],
|
|
834
|
-
(data, a, ctx) => {
|
|
835
|
-
const batch0 = data[0];
|
|
836
|
-
const batch1 = data[1];
|
|
837
|
-
const secondaryVal = batch1 != null && batch1.length > 0 ? batch1.at(-1) : ctx.prevData[1];
|
|
838
|
-
if (batch0 != null && batch0.length > 0) {
|
|
839
|
-
if (!(batch1 != null && batch1.length > 0) && ctx.prevData[1] === void 0) {
|
|
840
|
-
a.down([[RESOLVED]]);
|
|
841
|
-
return;
|
|
842
|
-
}
|
|
843
|
-
for (const v of batch0) {
|
|
844
|
-
a.emit([v, secondaryVal]);
|
|
845
|
-
}
|
|
846
|
-
} else {
|
|
847
|
-
a.down([[RESOLVED]]);
|
|
848
|
-
}
|
|
849
|
-
},
|
|
850
|
-
operatorOpts(opts)
|
|
851
|
-
);
|
|
852
|
-
}
|
|
853
|
-
function merge(...sources) {
|
|
854
|
-
if (sources.length === 0) {
|
|
855
|
-
return producer((a) => {
|
|
856
|
-
a.down([[COMPLETE]]);
|
|
857
|
-
}, operatorOpts());
|
|
858
|
-
}
|
|
859
|
-
return producer((a) => {
|
|
860
|
-
const n = sources.length;
|
|
861
|
-
let completed = 0;
|
|
862
|
-
const unsubs = [];
|
|
863
|
-
for (const src of sources) {
|
|
864
|
-
const u = src.subscribe((msgs) => {
|
|
865
|
-
for (const m of msgs) {
|
|
866
|
-
if (m[0] === DATA) {
|
|
867
|
-
a.emit(m[1]);
|
|
868
|
-
} else if (m[0] === COMPLETE) {
|
|
869
|
-
completed += 1;
|
|
870
|
-
if (completed >= n) {
|
|
871
|
-
a.down([[COMPLETE]]);
|
|
872
|
-
}
|
|
873
|
-
} else if (m[0] === ERROR) {
|
|
874
|
-
a.down([m]);
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
});
|
|
878
|
-
unsubs.push(u);
|
|
879
|
-
}
|
|
880
|
-
return () => {
|
|
881
|
-
for (const u of unsubs) u();
|
|
882
|
-
};
|
|
883
|
-
}, operatorOpts());
|
|
884
|
-
}
|
|
885
|
-
function zip(...sources) {
|
|
886
|
-
const n = sources.length;
|
|
887
|
-
if (n === 0) {
|
|
888
|
-
return producer((a) => {
|
|
889
|
-
a.emit([]);
|
|
890
|
-
a.down([[COMPLETE]]);
|
|
891
|
-
}, operatorOpts());
|
|
892
|
-
}
|
|
893
|
-
return producer((a) => {
|
|
894
|
-
const queues = Array.from({ length: n }, () => []);
|
|
895
|
-
let active = n;
|
|
896
|
-
function tryEmit() {
|
|
897
|
-
while (queues.every((q) => q.length > 0)) {
|
|
898
|
-
const tuple = queues.map((q) => q.shift());
|
|
899
|
-
a.emit(tuple);
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
const unsubs = [];
|
|
903
|
-
for (let i = 0; i < n; i++) {
|
|
904
|
-
const idx = i;
|
|
905
|
-
const u = sources[i].subscribe((msgs) => {
|
|
906
|
-
for (const m of msgs) {
|
|
907
|
-
if (m[0] === DATA) {
|
|
908
|
-
queues[idx].push(m[1]);
|
|
909
|
-
tryEmit();
|
|
910
|
-
} else if (m[0] === COMPLETE) {
|
|
911
|
-
active -= 1;
|
|
912
|
-
if (active === 0 || queues[idx].length === 0) {
|
|
913
|
-
a.down([[COMPLETE]]);
|
|
914
|
-
}
|
|
915
|
-
} else if (m[0] === ERROR) {
|
|
916
|
-
a.down([m]);
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
});
|
|
920
|
-
unsubs.push(u);
|
|
921
|
-
}
|
|
922
|
-
return () => {
|
|
923
|
-
for (const u of unsubs) u();
|
|
924
|
-
};
|
|
925
|
-
}, operatorOpts());
|
|
926
|
-
}
|
|
927
|
-
function concat(firstSrc, secondSrc, opts) {
|
|
928
|
-
return producer((a) => {
|
|
929
|
-
let phase = 0;
|
|
930
|
-
const pending = [];
|
|
931
|
-
let firstUnsub;
|
|
932
|
-
let secondUnsub;
|
|
933
|
-
secondUnsub = secondSrc.subscribe((msgs) => {
|
|
934
|
-
for (const m of msgs) {
|
|
935
|
-
if (phase === 0) {
|
|
936
|
-
if (m[0] === DATA) pending.push(m[1]);
|
|
937
|
-
else if (m[0] === ERROR) a.down([m]);
|
|
938
|
-
} else {
|
|
939
|
-
if (m[0] === DATA) a.emit(m[1]);
|
|
940
|
-
else if (m[0] === COMPLETE || m[0] === ERROR) a.down([m]);
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
});
|
|
944
|
-
firstUnsub = firstSrc.subscribe((msgs) => {
|
|
945
|
-
for (const m of msgs) {
|
|
946
|
-
if (phase === 0) {
|
|
947
|
-
if (m[0] === DATA) {
|
|
948
|
-
a.emit(m[1]);
|
|
949
|
-
} else if (m[0] === COMPLETE) {
|
|
950
|
-
phase = 1;
|
|
951
|
-
for (const v of pending) {
|
|
952
|
-
a.emit(v);
|
|
953
|
-
}
|
|
954
|
-
pending.length = 0;
|
|
955
|
-
} else if (m[0] === ERROR) {
|
|
956
|
-
a.down([m]);
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
});
|
|
961
|
-
return () => {
|
|
962
|
-
firstUnsub?.();
|
|
963
|
-
secondUnsub?.();
|
|
964
|
-
};
|
|
965
|
-
}, operatorOpts(opts));
|
|
966
|
-
}
|
|
967
|
-
function race(...sources) {
|
|
968
|
-
if (sources.length === 0) {
|
|
969
|
-
return producer((a) => {
|
|
970
|
-
a.down([[COMPLETE]]);
|
|
971
|
-
}, operatorOpts());
|
|
972
|
-
}
|
|
973
|
-
if (sources.length === 1) {
|
|
974
|
-
return node(
|
|
975
|
-
[sources[0]],
|
|
976
|
-
(data, a) => {
|
|
977
|
-
const batch0 = data[0];
|
|
978
|
-
if (batch0 == null || batch0.length === 0) {
|
|
979
|
-
a.down([[RESOLVED]]);
|
|
980
|
-
return;
|
|
981
|
-
}
|
|
982
|
-
for (const v of batch0) a.emit(v);
|
|
983
|
-
},
|
|
984
|
-
operatorOpts()
|
|
985
|
-
);
|
|
986
|
-
}
|
|
987
|
-
return producer((a) => {
|
|
988
|
-
let winner = null;
|
|
989
|
-
const unsubs = [];
|
|
990
|
-
for (let i = 0; i < sources.length; i++) {
|
|
991
|
-
const idx = i;
|
|
992
|
-
const u = sources[i].subscribe((msgs) => {
|
|
993
|
-
for (const m of msgs) {
|
|
994
|
-
if (winner !== null && idx !== winner) return;
|
|
995
|
-
if (m[0] === DATA) {
|
|
996
|
-
if (winner === null) winner = idx;
|
|
997
|
-
a.emit(m[1]);
|
|
998
|
-
} else if (m[0] === COMPLETE || m[0] === ERROR) {
|
|
999
|
-
if (winner === null || idx === winner) {
|
|
1000
|
-
a.down([m]);
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
});
|
|
1005
|
-
unsubs.push(u);
|
|
1006
|
-
}
|
|
1007
|
-
return () => {
|
|
1008
|
-
for (const u of unsubs) u();
|
|
1009
|
-
};
|
|
1010
|
-
}, operatorOpts());
|
|
1011
|
-
}
|
|
1012
|
-
function forwardInner(inner, a, onInnerComplete) {
|
|
1013
|
-
let unsub;
|
|
1014
|
-
let finished = false;
|
|
1015
|
-
const finish = () => {
|
|
1016
|
-
if (finished) return;
|
|
1017
|
-
finished = true;
|
|
1018
|
-
onInnerComplete();
|
|
1019
|
-
};
|
|
1020
|
-
unsub = inner.subscribe((msgs) => {
|
|
1021
|
-
let sawComplete = false;
|
|
1022
|
-
let sawError = false;
|
|
1023
|
-
for (const m of msgs) {
|
|
1024
|
-
if (m[0] === START) continue;
|
|
1025
|
-
if (m[0] === DATA) {
|
|
1026
|
-
a.emit(m[1]);
|
|
1027
|
-
} else if (m[0] === COMPLETE) {
|
|
1028
|
-
sawComplete = true;
|
|
1029
|
-
} else if (m[0] === ERROR) {
|
|
1030
|
-
sawError = true;
|
|
1031
|
-
a.down([m]);
|
|
1032
|
-
} else if (m[0] === DIRTY || m[0] === RESOLVED) {
|
|
1033
|
-
a.down([m]);
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
if (sawError) {
|
|
1037
|
-
unsub?.();
|
|
1038
|
-
unsub = void 0;
|
|
1039
|
-
finish();
|
|
1040
|
-
} else if (sawComplete) {
|
|
1041
|
-
finish();
|
|
1042
|
-
}
|
|
1043
|
-
});
|
|
1044
|
-
return () => {
|
|
1045
|
-
unsub?.();
|
|
1046
|
-
unsub = void 0;
|
|
1047
|
-
};
|
|
1048
|
-
}
|
|
1049
|
-
function switchMap(source, project, opts) {
|
|
1050
|
-
let innerUnsub;
|
|
1051
|
-
let sourceDone = false;
|
|
1052
|
-
function clearInner() {
|
|
1053
|
-
innerUnsub?.();
|
|
1054
|
-
innerUnsub = void 0;
|
|
1055
|
-
}
|
|
1056
|
-
return node(
|
|
1057
|
-
[source],
|
|
1058
|
-
(data, a, ctx) => {
|
|
1059
|
-
if (ctx.terminalDeps[0] != null && ctx.terminalDeps[0] !== true) {
|
|
1060
|
-
clearInner();
|
|
1061
|
-
return;
|
|
1062
|
-
}
|
|
1063
|
-
if (ctx.terminalDeps[0] === true) {
|
|
1064
|
-
sourceDone = true;
|
|
1065
|
-
if (!innerUnsub) a.down([[COMPLETE]]);
|
|
1066
|
-
return;
|
|
1067
|
-
}
|
|
1068
|
-
const batch0 = data[0];
|
|
1069
|
-
if (batch0 == null || batch0.length === 0) return;
|
|
1070
|
-
clearInner();
|
|
1071
|
-
innerUnsub = forwardInner(fromAny(project(batch0[batch0.length - 1])), a, () => {
|
|
1072
|
-
clearInner();
|
|
1073
|
-
if (sourceDone) a.down([[COMPLETE]]);
|
|
1074
|
-
});
|
|
1075
|
-
return {
|
|
1076
|
-
deactivation: () => {
|
|
1077
|
-
clearInner();
|
|
1078
|
-
sourceDone = false;
|
|
1079
|
-
}
|
|
1080
|
-
};
|
|
1081
|
-
},
|
|
1082
|
-
{ ...operatorOpts(opts), completeWhenDepsComplete: false }
|
|
1083
|
-
);
|
|
1084
|
-
}
|
|
1085
|
-
function exhaustMap(source, project, opts) {
|
|
1086
|
-
let innerUnsub;
|
|
1087
|
-
let sourceDone = false;
|
|
1088
|
-
function clearInner() {
|
|
1089
|
-
innerUnsub?.();
|
|
1090
|
-
innerUnsub = void 0;
|
|
1091
|
-
}
|
|
1092
|
-
return node(
|
|
1093
|
-
[source],
|
|
1094
|
-
(data, a, ctx) => {
|
|
1095
|
-
if (ctx.terminalDeps[0] != null && ctx.terminalDeps[0] !== true) {
|
|
1096
|
-
clearInner();
|
|
1097
|
-
return;
|
|
1098
|
-
}
|
|
1099
|
-
if (ctx.terminalDeps[0] === true) {
|
|
1100
|
-
sourceDone = true;
|
|
1101
|
-
if (!innerUnsub) a.down([[COMPLETE]]);
|
|
1102
|
-
return;
|
|
1103
|
-
}
|
|
1104
|
-
const batch0 = data[0];
|
|
1105
|
-
if (batch0 == null || batch0.length === 0) return;
|
|
1106
|
-
if (innerUnsub === void 0) {
|
|
1107
|
-
innerUnsub = forwardInner(fromAny(project(batch0[0])), a, () => {
|
|
1108
|
-
clearInner();
|
|
1109
|
-
if (sourceDone) a.down([[COMPLETE]]);
|
|
1110
|
-
});
|
|
1111
|
-
} else {
|
|
1112
|
-
a.down([[RESOLVED]]);
|
|
1113
|
-
}
|
|
1114
|
-
return {
|
|
1115
|
-
deactivation: () => {
|
|
1116
|
-
clearInner();
|
|
1117
|
-
sourceDone = false;
|
|
1118
|
-
}
|
|
1119
|
-
};
|
|
1120
|
-
},
|
|
1121
|
-
{ ...operatorOpts(opts), completeWhenDepsComplete: false }
|
|
1122
|
-
);
|
|
1123
|
-
}
|
|
1124
|
-
function concatMap(source, project, opts) {
|
|
1125
|
-
const { maxBuffer: maxBuf, ...concatNodeOpts } = opts ?? {};
|
|
1126
|
-
const queue = [];
|
|
1127
|
-
let innerUnsub;
|
|
1128
|
-
let sourceDone = false;
|
|
1129
|
-
let actions;
|
|
1130
|
-
function clearInner() {
|
|
1131
|
-
innerUnsub?.();
|
|
1132
|
-
innerUnsub = void 0;
|
|
1133
|
-
}
|
|
1134
|
-
function tryPump() {
|
|
1135
|
-
if (!actions || innerUnsub !== void 0) return;
|
|
1136
|
-
if (queue.length === 0) {
|
|
1137
|
-
if (sourceDone) actions.down([[COMPLETE]]);
|
|
1138
|
-
return;
|
|
1139
|
-
}
|
|
1140
|
-
const v = queue.shift();
|
|
1141
|
-
innerUnsub = forwardInner(fromAny(project(v)), actions, () => {
|
|
1142
|
-
clearInner();
|
|
1143
|
-
tryPump();
|
|
1144
|
-
});
|
|
1145
|
-
}
|
|
1146
|
-
function enqueue(v) {
|
|
1147
|
-
if (maxBuf && maxBuf > 0 && queue.length >= maxBuf) queue.shift();
|
|
1148
|
-
queue.push(v);
|
|
1149
|
-
tryPump();
|
|
1150
|
-
}
|
|
1151
|
-
return node(
|
|
1152
|
-
[source],
|
|
1153
|
-
(data, a, ctx) => {
|
|
1154
|
-
actions = a;
|
|
1155
|
-
if (ctx.terminalDeps[0] != null && ctx.terminalDeps[0] !== true) {
|
|
1156
|
-
clearInner();
|
|
1157
|
-
queue.length = 0;
|
|
1158
|
-
return;
|
|
1159
|
-
}
|
|
1160
|
-
if (ctx.terminalDeps[0] === true) {
|
|
1161
|
-
sourceDone = true;
|
|
1162
|
-
tryPump();
|
|
1163
|
-
return;
|
|
1164
|
-
}
|
|
1165
|
-
const batch0 = data[0];
|
|
1166
|
-
if (batch0 == null || batch0.length === 0) return;
|
|
1167
|
-
for (const v of batch0) {
|
|
1168
|
-
enqueue(v);
|
|
1169
|
-
}
|
|
1170
|
-
return {
|
|
1171
|
-
deactivation: () => {
|
|
1172
|
-
clearInner();
|
|
1173
|
-
queue.length = 0;
|
|
1174
|
-
sourceDone = false;
|
|
1175
|
-
}
|
|
1176
|
-
};
|
|
1177
|
-
},
|
|
1178
|
-
{ ...operatorOpts(concatNodeOpts), completeWhenDepsComplete: false }
|
|
1179
|
-
);
|
|
1180
|
-
}
|
|
1181
|
-
function mergeMap(source, project, opts) {
|
|
1182
|
-
const { concurrent: concurrentOpt, ...mergeNodeOpts } = opts ?? {};
|
|
1183
|
-
const maxConcurrent = concurrentOpt != null && concurrentOpt > 0 ? concurrentOpt : Number.POSITIVE_INFINITY;
|
|
1184
|
-
let active = 0;
|
|
1185
|
-
let sourceDone = false;
|
|
1186
|
-
const innerStops = /* @__PURE__ */ new Set();
|
|
1187
|
-
const buffer2 = [];
|
|
1188
|
-
let actions;
|
|
1189
|
-
function tryComplete() {
|
|
1190
|
-
if (sourceDone && active === 0 && buffer2.length === 0 && actions) {
|
|
1191
|
-
actions.down([[COMPLETE]]);
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
function spawn(v) {
|
|
1195
|
-
if (!actions) return;
|
|
1196
|
-
active++;
|
|
1197
|
-
let stop;
|
|
1198
|
-
stop = forwardInner(fromAny(project(v)), actions, () => {
|
|
1199
|
-
if (stop) innerStops.delete(stop);
|
|
1200
|
-
active--;
|
|
1201
|
-
drainBuffer();
|
|
1202
|
-
tryComplete();
|
|
1203
|
-
});
|
|
1204
|
-
innerStops.add(stop);
|
|
1205
|
-
}
|
|
1206
|
-
function drainBuffer() {
|
|
1207
|
-
while (buffer2.length > 0 && active < maxConcurrent) {
|
|
1208
|
-
spawn(buffer2.shift());
|
|
1209
|
-
}
|
|
1210
|
-
}
|
|
1211
|
-
function enqueue(v) {
|
|
1212
|
-
if (active < maxConcurrent) spawn(v);
|
|
1213
|
-
else buffer2.push(v);
|
|
1214
|
-
}
|
|
1215
|
-
function clearAll() {
|
|
1216
|
-
for (const u of innerStops) u();
|
|
1217
|
-
innerStops.clear();
|
|
1218
|
-
active = 0;
|
|
1219
|
-
buffer2.length = 0;
|
|
1220
|
-
}
|
|
1221
|
-
return node(
|
|
1222
|
-
[source],
|
|
1223
|
-
(data, a, ctx) => {
|
|
1224
|
-
actions = a;
|
|
1225
|
-
if (ctx.terminalDeps[0] != null && ctx.terminalDeps[0] !== true) {
|
|
1226
|
-
clearAll();
|
|
1227
|
-
return;
|
|
1228
|
-
}
|
|
1229
|
-
if (ctx.terminalDeps[0] === true) {
|
|
1230
|
-
sourceDone = true;
|
|
1231
|
-
tryComplete();
|
|
1232
|
-
return;
|
|
1233
|
-
}
|
|
1234
|
-
const batch0 = data[0];
|
|
1235
|
-
if (batch0 == null || batch0.length === 0) return;
|
|
1236
|
-
for (const v of batch0) {
|
|
1237
|
-
enqueue(v);
|
|
1238
|
-
}
|
|
1239
|
-
return {
|
|
1240
|
-
deactivation: () => {
|
|
1241
|
-
clearAll();
|
|
1242
|
-
sourceDone = false;
|
|
1243
|
-
}
|
|
1244
|
-
};
|
|
1245
|
-
},
|
|
1246
|
-
{ ...operatorOpts(mergeNodeOpts), completeWhenDepsComplete: false }
|
|
1247
|
-
);
|
|
1248
|
-
}
|
|
1249
|
-
var flatMap = mergeMap;
|
|
1250
|
-
function delay(source, ms, opts) {
|
|
1251
|
-
return producer((a) => {
|
|
1252
|
-
const timers = /* @__PURE__ */ new Set();
|
|
1253
|
-
function clearAll() {
|
|
1254
|
-
for (const id of timers) clearTimeout(id);
|
|
1255
|
-
timers.clear();
|
|
1256
|
-
}
|
|
1257
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1258
|
-
for (const m of msgs) {
|
|
1259
|
-
if (m[0] === DATA) {
|
|
1260
|
-
const id = setTimeout(() => {
|
|
1261
|
-
timers.delete(id);
|
|
1262
|
-
a.emit(m[1]);
|
|
1263
|
-
}, ms);
|
|
1264
|
-
timers.add(id);
|
|
1265
|
-
} else if (m[0] === COMPLETE) {
|
|
1266
|
-
const id = setTimeout(() => {
|
|
1267
|
-
timers.delete(id);
|
|
1268
|
-
a.down([[COMPLETE]]);
|
|
1269
|
-
}, ms);
|
|
1270
|
-
timers.add(id);
|
|
1271
|
-
} else if (m[0] === ERROR) {
|
|
1272
|
-
clearAll();
|
|
1273
|
-
a.down([m]);
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1276
|
-
});
|
|
1277
|
-
return () => {
|
|
1278
|
-
srcUnsub();
|
|
1279
|
-
clearAll();
|
|
1280
|
-
};
|
|
1281
|
-
}, operatorOpts(opts));
|
|
1282
|
-
}
|
|
1283
|
-
function debounce(source, ms, opts) {
|
|
1284
|
-
return producer((a) => {
|
|
1285
|
-
let timer;
|
|
1286
|
-
let pending;
|
|
1287
|
-
function clearTimer() {
|
|
1288
|
-
if (timer !== void 0) {
|
|
1289
|
-
clearTimeout(timer);
|
|
1290
|
-
timer = void 0;
|
|
1291
|
-
}
|
|
1292
|
-
}
|
|
1293
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1294
|
-
for (const m of msgs) {
|
|
1295
|
-
if (m[0] === DATA) {
|
|
1296
|
-
clearTimer();
|
|
1297
|
-
pending = m[1];
|
|
1298
|
-
timer = setTimeout(() => {
|
|
1299
|
-
timer = void 0;
|
|
1300
|
-
a.emit(pending);
|
|
1301
|
-
}, ms);
|
|
1302
|
-
} else if (m[0] === COMPLETE) {
|
|
1303
|
-
if (timer !== void 0) {
|
|
1304
|
-
clearTimer();
|
|
1305
|
-
a.emit(pending);
|
|
1306
|
-
}
|
|
1307
|
-
a.down([[COMPLETE]]);
|
|
1308
|
-
} else if (m[0] === ERROR) {
|
|
1309
|
-
clearTimer();
|
|
1310
|
-
a.down([m]);
|
|
1311
|
-
}
|
|
1312
|
-
}
|
|
1313
|
-
});
|
|
1314
|
-
return () => {
|
|
1315
|
-
srcUnsub();
|
|
1316
|
-
clearTimer();
|
|
1317
|
-
};
|
|
1318
|
-
}, operatorOpts(opts));
|
|
1319
|
-
}
|
|
1320
|
-
function throttle(source, ms, opts) {
|
|
1321
|
-
const { leading: leadingOpt, trailing: trailingOpt, ...throttleNodeOpts } = opts ?? {};
|
|
1322
|
-
const leading = leadingOpt !== false;
|
|
1323
|
-
const trailing = trailingOpt === true;
|
|
1324
|
-
const windowNs = ms * NS_PER_MS;
|
|
1325
|
-
return producer((a) => {
|
|
1326
|
-
let timer;
|
|
1327
|
-
let lastEmitNs = -Infinity;
|
|
1328
|
-
let pending;
|
|
1329
|
-
let hasPending = false;
|
|
1330
|
-
function clearTimer() {
|
|
1331
|
-
if (timer !== void 0) {
|
|
1332
|
-
clearTimeout(timer);
|
|
1333
|
-
timer = void 0;
|
|
1334
|
-
}
|
|
1335
|
-
}
|
|
1336
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1337
|
-
for (const m of msgs) {
|
|
1338
|
-
if (m[0] === DATA) {
|
|
1339
|
-
const v = m[1];
|
|
1340
|
-
const nowNs = monotonicNs();
|
|
1341
|
-
if (leading && nowNs - lastEmitNs >= windowNs) {
|
|
1342
|
-
lastEmitNs = nowNs;
|
|
1343
|
-
a.emit(v);
|
|
1344
|
-
clearTimer();
|
|
1345
|
-
if (trailing) {
|
|
1346
|
-
timer = setTimeout(() => {
|
|
1347
|
-
timer = void 0;
|
|
1348
|
-
if (hasPending) {
|
|
1349
|
-
lastEmitNs = monotonicNs();
|
|
1350
|
-
a.emit(pending);
|
|
1351
|
-
hasPending = false;
|
|
1352
|
-
}
|
|
1353
|
-
}, ms);
|
|
1354
|
-
}
|
|
1355
|
-
} else if (trailing) {
|
|
1356
|
-
pending = v;
|
|
1357
|
-
hasPending = true;
|
|
1358
|
-
if (timer === void 0) {
|
|
1359
|
-
const elapsedMs = (nowNs - lastEmitNs) / NS_PER_MS;
|
|
1360
|
-
timer = setTimeout(
|
|
1361
|
-
() => {
|
|
1362
|
-
timer = void 0;
|
|
1363
|
-
if (hasPending) {
|
|
1364
|
-
lastEmitNs = monotonicNs();
|
|
1365
|
-
a.emit(pending);
|
|
1366
|
-
hasPending = false;
|
|
1367
|
-
}
|
|
1368
|
-
},
|
|
1369
|
-
Math.max(0, ms - elapsedMs)
|
|
1370
|
-
);
|
|
1371
|
-
}
|
|
1372
|
-
}
|
|
1373
|
-
} else if (m[0] === COMPLETE || m[0] === ERROR) {
|
|
1374
|
-
clearTimer();
|
|
1375
|
-
a.down([m]);
|
|
1376
|
-
}
|
|
1377
|
-
}
|
|
1378
|
-
});
|
|
1379
|
-
return () => {
|
|
1380
|
-
srcUnsub();
|
|
1381
|
-
clearTimer();
|
|
1382
|
-
};
|
|
1383
|
-
}, operatorOpts(throttleNodeOpts));
|
|
1384
|
-
}
|
|
1385
|
-
function sample(source, notifier, opts) {
|
|
1386
|
-
return producer((a) => {
|
|
1387
|
-
let lastSourceValue;
|
|
1388
|
-
let terminated = false;
|
|
1389
|
-
let sourceCompleted = false;
|
|
1390
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1391
|
-
if (terminated) return;
|
|
1392
|
-
for (const m of msgs) {
|
|
1393
|
-
if (terminated) return;
|
|
1394
|
-
if (m[0] === DATA) {
|
|
1395
|
-
lastSourceValue = { v: m[1] };
|
|
1396
|
-
} else if (m[0] === ERROR) {
|
|
1397
|
-
terminated = true;
|
|
1398
|
-
a.down([m]);
|
|
1399
|
-
} else if (m[0] === COMPLETE) {
|
|
1400
|
-
sourceCompleted = true;
|
|
1401
|
-
lastSourceValue = void 0;
|
|
1402
|
-
}
|
|
1403
|
-
}
|
|
1404
|
-
});
|
|
1405
|
-
const notUnsub = notifier.subscribe((msgs) => {
|
|
1406
|
-
if (terminated) return;
|
|
1407
|
-
for (const m of msgs) {
|
|
1408
|
-
if (terminated) return;
|
|
1409
|
-
if (m[0] === DATA) {
|
|
1410
|
-
if (lastSourceValue !== void 0 && !sourceCompleted) {
|
|
1411
|
-
a.emit(lastSourceValue.v);
|
|
1412
|
-
}
|
|
1413
|
-
} else if (m[0] === ERROR) {
|
|
1414
|
-
terminated = true;
|
|
1415
|
-
a.down([m]);
|
|
1416
|
-
} else if (m[0] === COMPLETE) {
|
|
1417
|
-
terminated = true;
|
|
1418
|
-
a.down([[COMPLETE]]);
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
});
|
|
1422
|
-
return () => {
|
|
1423
|
-
srcUnsub();
|
|
1424
|
-
notUnsub();
|
|
1425
|
-
};
|
|
1426
|
-
}, operatorOpts(opts));
|
|
1427
|
-
}
|
|
1428
|
-
function audit(source, ms, opts) {
|
|
1429
|
-
return producer((a) => {
|
|
1430
|
-
let timer;
|
|
1431
|
-
let latest;
|
|
1432
|
-
let has = false;
|
|
1433
|
-
function clearTimer() {
|
|
1434
|
-
if (timer !== void 0) {
|
|
1435
|
-
clearTimeout(timer);
|
|
1436
|
-
timer = void 0;
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1440
|
-
for (const m of msgs) {
|
|
1441
|
-
if (m[0] === DATA) {
|
|
1442
|
-
latest = m[1];
|
|
1443
|
-
has = true;
|
|
1444
|
-
clearTimer();
|
|
1445
|
-
timer = setTimeout(() => {
|
|
1446
|
-
timer = void 0;
|
|
1447
|
-
if (has) {
|
|
1448
|
-
has = false;
|
|
1449
|
-
a.emit(latest);
|
|
1450
|
-
}
|
|
1451
|
-
}, ms);
|
|
1452
|
-
} else if (m[0] === COMPLETE || m[0] === ERROR) {
|
|
1453
|
-
clearTimer();
|
|
1454
|
-
a.down([m]);
|
|
1455
|
-
}
|
|
1456
|
-
}
|
|
1457
|
-
});
|
|
1458
|
-
return () => {
|
|
1459
|
-
srcUnsub();
|
|
1460
|
-
clearTimer();
|
|
1461
|
-
};
|
|
1462
|
-
}, operatorOpts(opts));
|
|
1463
|
-
}
|
|
1464
|
-
function buffer(source, notifier, opts) {
|
|
1465
|
-
return producer((a) => {
|
|
1466
|
-
const buf = [];
|
|
1467
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1468
|
-
for (const m of msgs) {
|
|
1469
|
-
if (m[0] === DATA) {
|
|
1470
|
-
buf.push(m[1]);
|
|
1471
|
-
} else if (m[0] === COMPLETE) {
|
|
1472
|
-
if (buf.length > 0) a.emit([...buf]);
|
|
1473
|
-
buf.length = 0;
|
|
1474
|
-
a.down([[COMPLETE]]);
|
|
1475
|
-
} else if (m[0] === ERROR) {
|
|
1476
|
-
a.down([m]);
|
|
1477
|
-
}
|
|
1478
|
-
}
|
|
1479
|
-
});
|
|
1480
|
-
const notUnsub = notifier.subscribe((msgs) => {
|
|
1481
|
-
for (const m of msgs) {
|
|
1482
|
-
if (m[0] === DATA) {
|
|
1483
|
-
if (buf.length > 0) {
|
|
1484
|
-
a.emit([...buf]);
|
|
1485
|
-
buf.length = 0;
|
|
1486
|
-
}
|
|
1487
|
-
} else if (m[0] === COMPLETE) {
|
|
1488
|
-
a.down([[COMPLETE]]);
|
|
1489
|
-
} else if (m[0] === ERROR) {
|
|
1490
|
-
a.down([m]);
|
|
1491
|
-
}
|
|
1492
|
-
}
|
|
1493
|
-
});
|
|
1494
|
-
return () => {
|
|
1495
|
-
srcUnsub();
|
|
1496
|
-
notUnsub();
|
|
1497
|
-
buf.length = 0;
|
|
1498
|
-
};
|
|
1499
|
-
}, operatorOpts(opts));
|
|
1500
|
-
}
|
|
1501
|
-
function bufferCount(source, count, opts) {
|
|
1502
|
-
if (count <= 0) throw new RangeError("bufferCount expects count > 0");
|
|
1503
|
-
return producer((a) => {
|
|
1504
|
-
const buf = [];
|
|
1505
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1506
|
-
for (const m of msgs) {
|
|
1507
|
-
if (m[0] === DATA) {
|
|
1508
|
-
buf.push(m[1]);
|
|
1509
|
-
if (buf.length >= count) {
|
|
1510
|
-
a.emit(buf.splice(0, buf.length));
|
|
1511
|
-
}
|
|
1512
|
-
} else if (m[0] === COMPLETE) {
|
|
1513
|
-
if (buf.length > 0) a.emit([...buf]);
|
|
1514
|
-
buf.length = 0;
|
|
1515
|
-
a.down([[COMPLETE]]);
|
|
1516
|
-
} else if (m[0] === ERROR) {
|
|
1517
|
-
a.down([m]);
|
|
1518
|
-
}
|
|
1519
|
-
}
|
|
1520
|
-
});
|
|
1521
|
-
return () => {
|
|
1522
|
-
srcUnsub();
|
|
1523
|
-
buf.length = 0;
|
|
1524
|
-
};
|
|
1525
|
-
}, operatorOpts(opts));
|
|
1526
|
-
}
|
|
1527
|
-
function windowCount(source, count, opts) {
|
|
1528
|
-
if (count <= 0) throw new RangeError("windowCount expects count > 0");
|
|
1529
|
-
return producer((a) => {
|
|
1530
|
-
let winDown;
|
|
1531
|
-
let n = 0;
|
|
1532
|
-
function openWindow() {
|
|
1533
|
-
const s = producer((actions) => {
|
|
1534
|
-
winDown = actions.down.bind(actions);
|
|
1535
|
-
return () => {
|
|
1536
|
-
winDown = void 0;
|
|
1537
|
-
};
|
|
1538
|
-
}, operatorOpts());
|
|
1539
|
-
n = 0;
|
|
1540
|
-
a.emit(s);
|
|
1541
|
-
}
|
|
1542
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1543
|
-
for (const m of msgs) {
|
|
1544
|
-
if (m[0] === DATA) {
|
|
1545
|
-
if (!winDown) openWindow();
|
|
1546
|
-
winDown?.([[DATA, m[1]]]);
|
|
1547
|
-
n += 1;
|
|
1548
|
-
if (n >= count) {
|
|
1549
|
-
winDown?.([[COMPLETE]]);
|
|
1550
|
-
winDown = void 0;
|
|
1551
|
-
}
|
|
1552
|
-
} else if (m[0] === COMPLETE) {
|
|
1553
|
-
winDown?.([[COMPLETE]]);
|
|
1554
|
-
winDown = void 0;
|
|
1555
|
-
a.down([[COMPLETE]]);
|
|
1556
|
-
} else if (m[0] === ERROR) {
|
|
1557
|
-
winDown?.([m]);
|
|
1558
|
-
winDown = void 0;
|
|
1559
|
-
a.down([m]);
|
|
1560
|
-
}
|
|
1561
|
-
}
|
|
1562
|
-
});
|
|
1563
|
-
return () => {
|
|
1564
|
-
srcUnsub();
|
|
1565
|
-
winDown?.([[COMPLETE]]);
|
|
1566
|
-
winDown = void 0;
|
|
1567
|
-
};
|
|
1568
|
-
}, operatorOpts(opts));
|
|
1569
|
-
}
|
|
1570
|
-
function bufferTime(source, ms, opts) {
|
|
1571
|
-
return producer((a) => {
|
|
1572
|
-
const buf = [];
|
|
1573
|
-
const iv = setInterval(() => {
|
|
1574
|
-
if (buf.length > 0) {
|
|
1575
|
-
a.emit([...buf]);
|
|
1576
|
-
buf.length = 0;
|
|
1577
|
-
}
|
|
1578
|
-
}, ms);
|
|
1579
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1580
|
-
for (const m of msgs) {
|
|
1581
|
-
if (m[0] === DATA) {
|
|
1582
|
-
buf.push(m[1]);
|
|
1583
|
-
} else if (m[0] === COMPLETE) {
|
|
1584
|
-
clearInterval(iv);
|
|
1585
|
-
if (buf.length > 0) a.emit([...buf]);
|
|
1586
|
-
buf.length = 0;
|
|
1587
|
-
a.down([[COMPLETE]]);
|
|
1588
|
-
} else if (m[0] === ERROR) {
|
|
1589
|
-
clearInterval(iv);
|
|
1590
|
-
a.down([m]);
|
|
1591
|
-
}
|
|
1592
|
-
}
|
|
1593
|
-
});
|
|
1594
|
-
return () => {
|
|
1595
|
-
srcUnsub();
|
|
1596
|
-
clearInterval(iv);
|
|
1597
|
-
buf.length = 0;
|
|
1598
|
-
};
|
|
1599
|
-
}, operatorOpts(opts));
|
|
1600
|
-
}
|
|
1601
|
-
function windowTime(source, ms, opts) {
|
|
1602
|
-
return producer((a) => {
|
|
1603
|
-
let winDown;
|
|
1604
|
-
function closeWindow() {
|
|
1605
|
-
winDown?.([[COMPLETE]]);
|
|
1606
|
-
winDown = void 0;
|
|
1607
|
-
}
|
|
1608
|
-
function openWindow() {
|
|
1609
|
-
const s = producer((actions) => {
|
|
1610
|
-
winDown = actions.down.bind(actions);
|
|
1611
|
-
return () => {
|
|
1612
|
-
winDown = void 0;
|
|
1613
|
-
};
|
|
1614
|
-
}, operatorOpts());
|
|
1615
|
-
a.emit(s);
|
|
1616
|
-
}
|
|
1617
|
-
openWindow();
|
|
1618
|
-
const iv = setInterval(() => {
|
|
1619
|
-
closeWindow();
|
|
1620
|
-
openWindow();
|
|
1621
|
-
}, ms);
|
|
1622
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1623
|
-
for (const m of msgs) {
|
|
1624
|
-
if (m[0] === DATA) {
|
|
1625
|
-
winDown?.([[DATA, m[1]]]);
|
|
1626
|
-
} else if (m[0] === COMPLETE) {
|
|
1627
|
-
clearInterval(iv);
|
|
1628
|
-
closeWindow();
|
|
1629
|
-
a.down([[COMPLETE]]);
|
|
1630
|
-
} else if (m[0] === ERROR) {
|
|
1631
|
-
clearInterval(iv);
|
|
1632
|
-
winDown?.([m]);
|
|
1633
|
-
closeWindow();
|
|
1634
|
-
a.down([m]);
|
|
1635
|
-
}
|
|
1636
|
-
}
|
|
1637
|
-
});
|
|
1638
|
-
return () => {
|
|
1639
|
-
srcUnsub();
|
|
1640
|
-
clearInterval(iv);
|
|
1641
|
-
closeWindow();
|
|
1642
|
-
};
|
|
1643
|
-
}, operatorOpts(opts));
|
|
1644
|
-
}
|
|
1645
|
-
function window(source, notifier, opts) {
|
|
1646
|
-
return producer((a) => {
|
|
1647
|
-
let winDown;
|
|
1648
|
-
function closeWindow() {
|
|
1649
|
-
winDown?.([[COMPLETE]]);
|
|
1650
|
-
winDown = void 0;
|
|
1651
|
-
}
|
|
1652
|
-
function openWindow() {
|
|
1653
|
-
const s = producer((actions) => {
|
|
1654
|
-
winDown = actions.down.bind(actions);
|
|
1655
|
-
return () => {
|
|
1656
|
-
winDown = void 0;
|
|
1657
|
-
};
|
|
1658
|
-
}, operatorOpts());
|
|
1659
|
-
a.emit(s);
|
|
1660
|
-
}
|
|
1661
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1662
|
-
for (const m of msgs) {
|
|
1663
|
-
if (m[0] === DATA) {
|
|
1664
|
-
if (!winDown) openWindow();
|
|
1665
|
-
winDown?.([[DATA, m[1]]]);
|
|
1666
|
-
} else if (m[0] === COMPLETE) {
|
|
1667
|
-
closeWindow();
|
|
1668
|
-
a.down([[COMPLETE]]);
|
|
1669
|
-
} else if (m[0] === ERROR) {
|
|
1670
|
-
winDown?.([m]);
|
|
1671
|
-
winDown = void 0;
|
|
1672
|
-
a.down([m]);
|
|
1673
|
-
}
|
|
1674
|
-
}
|
|
1675
|
-
});
|
|
1676
|
-
const notUnsub = notifier.subscribe((msgs) => {
|
|
1677
|
-
for (const m of msgs) {
|
|
1678
|
-
if (m[0] === DATA) {
|
|
1679
|
-
closeWindow();
|
|
1680
|
-
openWindow();
|
|
1681
|
-
}
|
|
1682
|
-
}
|
|
1683
|
-
});
|
|
1684
|
-
return () => {
|
|
1685
|
-
srcUnsub();
|
|
1686
|
-
notUnsub();
|
|
1687
|
-
closeWindow();
|
|
1688
|
-
};
|
|
1689
|
-
}, operatorOpts(opts));
|
|
1690
|
-
}
|
|
1691
|
-
function interval(periodMs, opts) {
|
|
1692
|
-
return producer((a, ctx) => {
|
|
1693
|
-
if (!("n" in ctx.store)) ctx.store.n = 0;
|
|
1694
|
-
const id = setInterval(() => {
|
|
1695
|
-
a.emit(ctx.store.n);
|
|
1696
|
-
ctx.store.n = ctx.store.n + 1;
|
|
1697
|
-
}, periodMs);
|
|
1698
|
-
return () => clearInterval(id);
|
|
1699
|
-
}, operatorOpts(opts));
|
|
1700
|
-
}
|
|
1701
|
-
function repeat(source, count, opts) {
|
|
1702
|
-
if (count <= 0) throw new RangeError("repeat expects count > 0");
|
|
1703
|
-
return producer((a) => {
|
|
1704
|
-
let remaining = count;
|
|
1705
|
-
let innerU;
|
|
1706
|
-
const start = () => {
|
|
1707
|
-
innerU?.();
|
|
1708
|
-
innerU = source.subscribe((msgs) => {
|
|
1709
|
-
let completed = false;
|
|
1710
|
-
const fwd = [];
|
|
1711
|
-
for (const m of msgs) {
|
|
1712
|
-
if (m[0] === COMPLETE) completed = true;
|
|
1713
|
-
else fwd.push(m);
|
|
1714
|
-
}
|
|
1715
|
-
if (fwd.length > 0) a.down(fwd);
|
|
1716
|
-
if (completed) {
|
|
1717
|
-
innerU?.();
|
|
1718
|
-
innerU = void 0;
|
|
1719
|
-
remaining -= 1;
|
|
1720
|
-
if (remaining > 0) start();
|
|
1721
|
-
else a.down([[COMPLETE]]);
|
|
1722
|
-
}
|
|
1723
|
-
});
|
|
1724
|
-
};
|
|
1725
|
-
start();
|
|
1726
|
-
return () => {
|
|
1727
|
-
innerU?.();
|
|
1728
|
-
};
|
|
1729
|
-
}, operatorOpts(opts));
|
|
1730
|
-
}
|
|
1731
|
-
function pausable(source, opts) {
|
|
1732
|
-
return node(
|
|
1733
|
-
[source],
|
|
1734
|
-
(data, a) => {
|
|
1735
|
-
const batch0 = data[0];
|
|
1736
|
-
if (batch0 == null || batch0.length === 0) {
|
|
1737
|
-
a.down([[RESOLVED]]);
|
|
1738
|
-
return;
|
|
1739
|
-
}
|
|
1740
|
-
for (const v of batch0) a.emit(v);
|
|
1741
|
-
},
|
|
1742
|
-
operatorOpts(opts)
|
|
1743
|
-
);
|
|
1744
|
-
}
|
|
1745
|
-
function rescue(source, recover, opts) {
|
|
1746
|
-
return producer((a) => {
|
|
1747
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1748
|
-
for (const m of msgs) {
|
|
1749
|
-
if (m[0] === DATA) {
|
|
1750
|
-
a.emit(m[1]);
|
|
1751
|
-
} else if (m[0] === ERROR) {
|
|
1752
|
-
try {
|
|
1753
|
-
a.emit(recover(m[1]));
|
|
1754
|
-
} catch (recoverErr) {
|
|
1755
|
-
a.down([[ERROR, recoverErr]]);
|
|
382
|
+
teardownCount++;
|
|
383
|
+
if (activatedCount > 0 && teardownCount >= activatedCount && teardownCount >= channels.length) {
|
|
384
|
+
finishCleanup();
|
|
1756
385
|
}
|
|
1757
|
-
}
|
|
1758
|
-
|
|
386
|
+
};
|
|
387
|
+
},
|
|
388
|
+
sourceOpts({ ...chOpts, name })
|
|
389
|
+
);
|
|
390
|
+
nodes[ch] = n;
|
|
391
|
+
channelNodes.push(n);
|
|
392
|
+
}
|
|
393
|
+
const bundle = {};
|
|
394
|
+
for (const ch of channels) {
|
|
395
|
+
bundle[ch] = (value) => {
|
|
396
|
+
if (!active) return;
|
|
397
|
+
nodes[ch].down([[DATA, value]]);
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
bundle.error = (err) => {
|
|
401
|
+
if (!active) return;
|
|
402
|
+
active = false;
|
|
403
|
+
batch(() => {
|
|
404
|
+
for (const n of channelNodes) n.down([[ERROR, err]]);
|
|
405
|
+
});
|
|
406
|
+
finishCleanup();
|
|
407
|
+
};
|
|
408
|
+
bundle.complete = () => {
|
|
409
|
+
if (!active) return;
|
|
410
|
+
active = false;
|
|
411
|
+
batch(() => {
|
|
412
|
+
for (const n of channelNodes) n.down([[COMPLETE]]);
|
|
413
|
+
});
|
|
414
|
+
finishCleanup();
|
|
415
|
+
};
|
|
416
|
+
const ret = register(bundle);
|
|
417
|
+
cleanup = typeof ret === "function" ? ret : void 0;
|
|
418
|
+
const dispose = () => {
|
|
419
|
+
if (!active) return;
|
|
420
|
+
active = false;
|
|
421
|
+
batch(() => {
|
|
422
|
+
for (const n of channelNodes) {
|
|
423
|
+
try {
|
|
424
|
+
n.down([[COMPLETE]]);
|
|
425
|
+
} catch {
|
|
1759
426
|
}
|
|
1760
427
|
}
|
|
1761
428
|
});
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
}, operatorOpts(opts));
|
|
1766
|
-
}
|
|
1767
|
-
function valve(source, control, opts) {
|
|
1768
|
-
return node(
|
|
1769
|
-
[source, control],
|
|
1770
|
-
(data, a, ctx) => {
|
|
1771
|
-
const batch1 = data[1];
|
|
1772
|
-
const controlValue = batch1 != null && batch1.length > 0 ? batch1.at(-1) : ctx.prevData[1];
|
|
1773
|
-
if (!controlValue) {
|
|
1774
|
-
a.down([[RESOLVED]]);
|
|
1775
|
-
return;
|
|
1776
|
-
}
|
|
1777
|
-
const batch0 = data[0];
|
|
1778
|
-
if (batch0 != null && batch0.length > 0) {
|
|
1779
|
-
for (const v of batch0) a.emit(v);
|
|
1780
|
-
return;
|
|
1781
|
-
}
|
|
1782
|
-
if (batch1 != null && batch1.length > 0 && ctx.prevData[0] !== void 0) {
|
|
1783
|
-
a.emit(ctx.prevData[0]);
|
|
1784
|
-
return;
|
|
1785
|
-
}
|
|
1786
|
-
a.down([[RESOLVED]]);
|
|
1787
|
-
},
|
|
1788
|
-
operatorOpts(opts)
|
|
1789
|
-
);
|
|
429
|
+
finishCleanup();
|
|
430
|
+
};
|
|
431
|
+
return Object.assign(nodes, { dispose });
|
|
1790
432
|
}
|
|
1791
|
-
var combineLatest = combine;
|
|
1792
|
-
var debounceTime = debounce;
|
|
1793
|
-
var throttleTime = throttle;
|
|
1794
|
-
var catchError = rescue;
|
|
1795
433
|
|
|
1796
434
|
// src/extra/reactive-sink.ts
|
|
1797
435
|
var BackpressureBuffer = class {
|
|
@@ -2207,10 +845,10 @@ function reactiveSink(source, config) {
|
|
|
2207
845
|
}
|
|
2208
846
|
|
|
2209
847
|
// src/extra/resilience.ts
|
|
2210
|
-
function
|
|
848
|
+
function operatorOpts(opts) {
|
|
2211
849
|
return { describeKind: "derived", ...opts };
|
|
2212
850
|
}
|
|
2213
|
-
function
|
|
851
|
+
function clampNonNegative(value) {
|
|
2214
852
|
return value < 0 ? 0 : value;
|
|
2215
853
|
}
|
|
2216
854
|
function msgVal(m) {
|
|
@@ -2300,7 +938,7 @@ function retry(source, opts) {
|
|
|
2300
938
|
};
|
|
2301
939
|
},
|
|
2302
940
|
{
|
|
2303
|
-
...
|
|
941
|
+
...operatorOpts(),
|
|
2304
942
|
initial: source.cache
|
|
2305
943
|
}
|
|
2306
944
|
);
|
|
@@ -2390,7 +1028,7 @@ function retrySource(factory, opts) {
|
|
|
2390
1028
|
};
|
|
2391
1029
|
},
|
|
2392
1030
|
{
|
|
2393
|
-
...
|
|
1031
|
+
...operatorOpts(),
|
|
2394
1032
|
initial: opts?.initial
|
|
2395
1033
|
}
|
|
2396
1034
|
);
|
|
@@ -2403,7 +1041,7 @@ var CircuitOpenError = class extends Error {
|
|
|
2403
1041
|
};
|
|
2404
1042
|
function circuitBreaker(options) {
|
|
2405
1043
|
const threshold = Math.max(1, options?.failureThreshold ?? 5);
|
|
2406
|
-
const baseCooldownNs =
|
|
1044
|
+
const baseCooldownNs = clampNonNegative(options?.cooldownNs ?? 30 * NS_PER_SEC);
|
|
2407
1045
|
const cooldownStrategy = options?.cooldown ?? null;
|
|
2408
1046
|
const halfOpenMax = Math.max(1, options?.halfOpenMax ?? 1);
|
|
2409
1047
|
const now = options?.now ?? monotonicNs;
|
|
@@ -2517,7 +1155,7 @@ function withBreaker(breaker, options) {
|
|
|
2517
1155
|
return unsub;
|
|
2518
1156
|
},
|
|
2519
1157
|
{
|
|
2520
|
-
...
|
|
1158
|
+
...operatorOpts(),
|
|
2521
1159
|
meta: { breakerState: breaker.state },
|
|
2522
1160
|
completeWhenDepsComplete: false,
|
|
2523
1161
|
initial: source.cache
|
|
@@ -2635,7 +1273,7 @@ function rateLimiter(source, opts) {
|
|
|
2635
1273
|
};
|
|
2636
1274
|
},
|
|
2637
1275
|
{
|
|
2638
|
-
...
|
|
1276
|
+
...operatorOpts(),
|
|
2639
1277
|
initial: source.cache
|
|
2640
1278
|
}
|
|
2641
1279
|
);
|
|
@@ -2682,7 +1320,7 @@ function withStatus(src, options) {
|
|
|
2682
1320
|
return unsub;
|
|
2683
1321
|
},
|
|
2684
1322
|
{
|
|
2685
|
-
...
|
|
1323
|
+
...operatorOpts(),
|
|
2686
1324
|
meta: { status: initialStatus, error: null },
|
|
2687
1325
|
completeWhenDepsComplete: false,
|
|
2688
1326
|
resubscribable: true,
|
|
@@ -2751,7 +1389,7 @@ function fallback(source, fb) {
|
|
|
2751
1389
|
};
|
|
2752
1390
|
},
|
|
2753
1391
|
{
|
|
2754
|
-
...
|
|
1392
|
+
...operatorOpts(),
|
|
2755
1393
|
initial: source.cache
|
|
2756
1394
|
}
|
|
2757
1395
|
);
|
|
@@ -2806,7 +1444,7 @@ function timeout(source, timeoutNs) {
|
|
|
2806
1444
|
};
|
|
2807
1445
|
},
|
|
2808
1446
|
{
|
|
2809
|
-
...
|
|
1447
|
+
...operatorOpts(),
|
|
2810
1448
|
initial: source.cache
|
|
2811
1449
|
}
|
|
2812
1450
|
);
|
|
@@ -5036,468 +3674,106 @@ function cascadingCache(tiers, opts) {
|
|
|
5036
3674
|
if (result !== void 0 && result !== null) {
|
|
5037
3675
|
nd.down([[DATA, result]]);
|
|
5038
3676
|
promote(key, result, tierIndex);
|
|
5039
|
-
return;
|
|
5040
|
-
}
|
|
5041
|
-
}
|
|
5042
|
-
}
|
|
5043
|
-
function evictIfNeeded() {
|
|
5044
|
-
if (!policy || maxSize <= 0) return;
|
|
5045
|
-
while (policy.size() >= maxSize) {
|
|
5046
|
-
const victims = policy.evict(1);
|
|
5047
|
-
if (victims.length === 0) break;
|
|
5048
|
-
for (const key of victims) {
|
|
5049
|
-
const nd = entries.get(key);
|
|
5050
|
-
if (nd) {
|
|
5051
|
-
const value = nd.cache;
|
|
5052
|
-
if (nd.status !== "sentinel" && tiers.length > 0) {
|
|
5053
|
-
const lastIndex = tiers.length - 1;
|
|
5054
|
-
try {
|
|
5055
|
-
fireAndForget(tiers[lastIndex].save(key, value));
|
|
5056
|
-
} catch {
|
|
5057
|
-
}
|
|
5058
|
-
for (let j = 0; j < lastIndex; j++) {
|
|
5059
|
-
try {
|
|
5060
|
-
const clearFn = tiers[j].clear;
|
|
5061
|
-
if (clearFn) fireAndForget(clearFn.call(tiers[j], key));
|
|
5062
|
-
} catch {
|
|
5063
|
-
}
|
|
5064
|
-
}
|
|
5065
|
-
}
|
|
5066
|
-
nd.down([[TEARDOWN]]);
|
|
5067
|
-
}
|
|
5068
|
-
entries.delete(key);
|
|
5069
|
-
}
|
|
5070
|
-
}
|
|
5071
|
-
}
|
|
5072
|
-
return {
|
|
5073
|
-
load(key) {
|
|
5074
|
-
const existing = entries.get(key);
|
|
5075
|
-
if (existing) {
|
|
5076
|
-
policy?.touch(key);
|
|
5077
|
-
return existing;
|
|
5078
|
-
}
|
|
5079
|
-
if (policy && maxSize > 0 && policy.size() >= maxSize) {
|
|
5080
|
-
evictIfNeeded();
|
|
5081
|
-
}
|
|
5082
|
-
const nd = state(void 0);
|
|
5083
|
-
entries.set(key, nd);
|
|
5084
|
-
policy?.insert(key);
|
|
5085
|
-
cascade(key, nd);
|
|
5086
|
-
return nd;
|
|
5087
|
-
},
|
|
5088
|
-
save(key, value) {
|
|
5089
|
-
if (writeThrough) {
|
|
5090
|
-
for (const tier of tiers) {
|
|
5091
|
-
try {
|
|
5092
|
-
fireAndForget(tier.save(key, value));
|
|
5093
|
-
} catch {
|
|
5094
|
-
}
|
|
5095
|
-
}
|
|
5096
|
-
} else if (tiers[0]) {
|
|
5097
|
-
try {
|
|
5098
|
-
fireAndForget(tiers[0].save(key, value));
|
|
5099
|
-
} catch {
|
|
5100
|
-
}
|
|
5101
|
-
}
|
|
5102
|
-
const existing = entries.get(key);
|
|
5103
|
-
if (existing) {
|
|
5104
|
-
existing.down([[DATA, value]]);
|
|
5105
|
-
policy?.touch(key);
|
|
5106
|
-
} else {
|
|
5107
|
-
if (policy && maxSize > 0 && policy.size() >= maxSize) {
|
|
5108
|
-
evictIfNeeded();
|
|
5109
|
-
}
|
|
5110
|
-
const nd = state(value);
|
|
5111
|
-
entries.set(key, nd);
|
|
5112
|
-
policy?.insert(key);
|
|
5113
|
-
}
|
|
5114
|
-
},
|
|
5115
|
-
invalidate(key) {
|
|
5116
|
-
const existing = entries.get(key);
|
|
5117
|
-
if (existing) cascade(key, existing);
|
|
5118
|
-
},
|
|
5119
|
-
delete(key) {
|
|
5120
|
-
policy?.delete(key);
|
|
5121
|
-
const nd = entries.get(key);
|
|
5122
|
-
if (nd) nd.down([[TEARDOWN]]);
|
|
5123
|
-
entries.delete(key);
|
|
5124
|
-
for (const tier of tiers) {
|
|
5125
|
-
try {
|
|
5126
|
-
const clearFn = tier.clear;
|
|
5127
|
-
if (clearFn) fireAndForget(clearFn.call(tier, key));
|
|
5128
|
-
} catch {
|
|
5129
|
-
}
|
|
5130
|
-
}
|
|
5131
|
-
},
|
|
5132
|
-
has(key) {
|
|
5133
|
-
return entries.has(key);
|
|
5134
|
-
},
|
|
5135
|
-
get size() {
|
|
5136
|
-
return entries.size;
|
|
5137
|
-
}
|
|
5138
|
-
};
|
|
5139
|
-
}
|
|
5140
|
-
|
|
5141
|
-
// src/extra/reactive-map.ts
|
|
5142
|
-
var NativeMapBackend = class {
|
|
5143
|
-
_version = 0;
|
|
5144
|
-
_store = /* @__PURE__ */ new Map();
|
|
5145
|
-
_maxSize;
|
|
5146
|
-
_defaultTtl;
|
|
5147
|
-
constructor(options = {}) {
|
|
5148
|
-
const { maxSize, defaultTtl } = options;
|
|
5149
|
-
if (maxSize !== void 0 && maxSize < 1) {
|
|
5150
|
-
throw new RangeError("maxSize must be >= 1");
|
|
5151
|
-
}
|
|
5152
|
-
if (defaultTtl !== void 0 && defaultTtl <= 0) {
|
|
5153
|
-
throw new RangeError("defaultTtl must be positive");
|
|
5154
|
-
}
|
|
5155
|
-
this._maxSize = maxSize;
|
|
5156
|
-
this._defaultTtl = defaultTtl;
|
|
5157
|
-
}
|
|
5158
|
-
get version() {
|
|
5159
|
-
return this._version;
|
|
5160
|
-
}
|
|
5161
|
-
get size() {
|
|
5162
|
-
return this._store.size;
|
|
5163
|
-
}
|
|
5164
|
-
has(key) {
|
|
5165
|
-
const e = this._store.get(key);
|
|
5166
|
-
if (e === void 0) return false;
|
|
5167
|
-
if (this._isExpired(e)) {
|
|
5168
|
-
this._store.delete(key);
|
|
5169
|
-
this._version += 1;
|
|
5170
|
-
return false;
|
|
5171
|
-
}
|
|
5172
|
-
this._touchLru(key, e);
|
|
5173
|
-
return true;
|
|
5174
|
-
}
|
|
5175
|
-
get(key) {
|
|
5176
|
-
const e = this._store.get(key);
|
|
5177
|
-
if (e === void 0) return void 0;
|
|
5178
|
-
if (this._isExpired(e)) {
|
|
5179
|
-
this._store.delete(key);
|
|
5180
|
-
this._version += 1;
|
|
5181
|
-
return void 0;
|
|
5182
|
-
}
|
|
5183
|
-
this._touchLru(key, e);
|
|
5184
|
-
return e.value;
|
|
5185
|
-
}
|
|
5186
|
-
set(key, value, ttl) {
|
|
5187
|
-
const expiresAt = this._resolveExpiresAt(ttl);
|
|
5188
|
-
if (this._store.has(key)) this._store.delete(key);
|
|
5189
|
-
this._store.set(key, { value, expiresAt });
|
|
5190
|
-
this._evictLruWhileOver();
|
|
5191
|
-
this._version += 1;
|
|
5192
|
-
}
|
|
5193
|
-
setMany(entries, ttl) {
|
|
5194
|
-
const expiresAt = this._resolveExpiresAt(ttl);
|
|
5195
|
-
let count = 0;
|
|
5196
|
-
try {
|
|
5197
|
-
for (const [key, value] of entries) {
|
|
5198
|
-
if (this._store.has(key)) this._store.delete(key);
|
|
5199
|
-
this._store.set(key, { value, expiresAt });
|
|
5200
|
-
count += 1;
|
|
5201
|
-
}
|
|
5202
|
-
} finally {
|
|
5203
|
-
if (count > 0) {
|
|
5204
|
-
this._evictLruWhileOver();
|
|
5205
|
-
this._version += 1;
|
|
5206
|
-
}
|
|
5207
|
-
}
|
|
5208
|
-
}
|
|
5209
|
-
delete(key) {
|
|
5210
|
-
const had = this._store.delete(key);
|
|
5211
|
-
if (had) this._version += 1;
|
|
5212
|
-
return had;
|
|
5213
|
-
}
|
|
5214
|
-
deleteMany(keys) {
|
|
5215
|
-
let removed = 0;
|
|
5216
|
-
try {
|
|
5217
|
-
for (const k of keys) {
|
|
5218
|
-
if (this._store.delete(k)) removed += 1;
|
|
5219
|
-
}
|
|
5220
|
-
} finally {
|
|
5221
|
-
if (removed > 0) this._version += 1;
|
|
5222
|
-
}
|
|
5223
|
-
return removed;
|
|
5224
|
-
}
|
|
5225
|
-
clear() {
|
|
5226
|
-
const n = this._store.size;
|
|
5227
|
-
if (n === 0) return 0;
|
|
5228
|
-
this._store.clear();
|
|
5229
|
-
this._version += 1;
|
|
5230
|
-
return n;
|
|
5231
|
-
}
|
|
5232
|
-
pruneExpired() {
|
|
5233
|
-
const now = monotonicNs();
|
|
5234
|
-
let removed = 0;
|
|
5235
|
-
for (const [k, e] of this._store) {
|
|
5236
|
-
if (this._isExpired(e, now)) {
|
|
5237
|
-
this._store.delete(k);
|
|
5238
|
-
removed += 1;
|
|
5239
|
-
}
|
|
5240
|
-
}
|
|
5241
|
-
if (removed > 0) this._version += 1;
|
|
5242
|
-
return removed;
|
|
5243
|
-
}
|
|
5244
|
-
toMap() {
|
|
5245
|
-
const now = monotonicNs();
|
|
5246
|
-
const out = /* @__PURE__ */ new Map();
|
|
5247
|
-
for (const [k, e] of this._store) {
|
|
5248
|
-
if (!this._isExpired(e, now)) out.set(k, e.value);
|
|
5249
|
-
}
|
|
5250
|
-
return out;
|
|
5251
|
-
}
|
|
5252
|
-
_resolveExpiresAt(ttl) {
|
|
5253
|
-
const effectiveTtl = ttl ?? this._defaultTtl;
|
|
5254
|
-
if (effectiveTtl === void 0) return void 0;
|
|
5255
|
-
if (!Number.isFinite(effectiveTtl) || effectiveTtl <= 0) {
|
|
5256
|
-
throw new RangeError(
|
|
5257
|
-
`MapBackend: ttl must be a positive finite number (got ${effectiveTtl})`
|
|
5258
|
-
);
|
|
5259
|
-
}
|
|
5260
|
-
return monotonicNs() + effectiveTtl * 1e9;
|
|
5261
|
-
}
|
|
5262
|
-
_isExpired(e, now) {
|
|
5263
|
-
if (e.expiresAt === void 0) return false;
|
|
5264
|
-
return (now ?? monotonicNs()) >= e.expiresAt;
|
|
5265
|
-
}
|
|
5266
|
-
_touchLru(key, entry) {
|
|
5267
|
-
this._store.delete(key);
|
|
5268
|
-
this._store.set(key, entry);
|
|
5269
|
-
}
|
|
5270
|
-
_evictLruWhileOver() {
|
|
5271
|
-
if (this._maxSize === void 0) return;
|
|
5272
|
-
while (this._store.size > this._maxSize) {
|
|
5273
|
-
const first2 = this._store.keys().next().value;
|
|
5274
|
-
if (first2 === void 0) break;
|
|
5275
|
-
this._store.delete(first2);
|
|
5276
|
-
}
|
|
5277
|
-
}
|
|
5278
|
-
};
|
|
5279
|
-
function reactiveMap(options = {}) {
|
|
5280
|
-
const { name, maxSize, defaultTtl, versioning, backend: userBackend } = options;
|
|
5281
|
-
const backend = userBackend ?? new NativeMapBackend({ maxSize, defaultTtl });
|
|
5282
|
-
const n = state(backend.toMap(), {
|
|
5283
|
-
name,
|
|
5284
|
-
describeKind: "state",
|
|
5285
|
-
equals: (a, b) => a === b,
|
|
5286
|
-
...versioning != null ? { versioning } : {}
|
|
5287
|
-
});
|
|
5288
|
-
function pushSnapshot() {
|
|
5289
|
-
const map2 = backend.toMap();
|
|
5290
|
-
batch(() => {
|
|
5291
|
-
n.down([[DIRTY]]);
|
|
5292
|
-
n.down([[DATA, map2]]);
|
|
5293
|
-
});
|
|
5294
|
-
}
|
|
5295
|
-
function wrapMutation(op) {
|
|
5296
|
-
const prev = backend.version;
|
|
5297
|
-
try {
|
|
5298
|
-
return op();
|
|
5299
|
-
} finally {
|
|
5300
|
-
if (backend.version !== prev) pushSnapshot();
|
|
5301
|
-
}
|
|
5302
|
-
}
|
|
5303
|
-
return {
|
|
5304
|
-
entries: n,
|
|
5305
|
-
has(key) {
|
|
5306
|
-
return wrapMutation(() => backend.has(key));
|
|
5307
|
-
},
|
|
5308
|
-
get(key) {
|
|
5309
|
-
return wrapMutation(() => backend.get(key));
|
|
5310
|
-
},
|
|
5311
|
-
set(key, value, opts) {
|
|
5312
|
-
wrapMutation(() => backend.set(key, value, opts?.ttl));
|
|
5313
|
-
},
|
|
5314
|
-
setMany(entries, opts) {
|
|
5315
|
-
wrapMutation(() => backend.setMany(entries, opts?.ttl));
|
|
5316
|
-
},
|
|
5317
|
-
delete(key) {
|
|
5318
|
-
wrapMutation(() => backend.delete(key));
|
|
5319
|
-
},
|
|
5320
|
-
deleteMany(keys) {
|
|
5321
|
-
wrapMutation(() => backend.deleteMany(keys));
|
|
5322
|
-
},
|
|
5323
|
-
clear() {
|
|
5324
|
-
wrapMutation(() => backend.clear());
|
|
5325
|
-
},
|
|
5326
|
-
pruneExpired() {
|
|
5327
|
-
wrapMutation(() => backend.pruneExpired());
|
|
5328
|
-
},
|
|
5329
|
-
/**
|
|
5330
|
-
* Current raw entry count — O(1), **pure read**. May include
|
|
5331
|
-
* not-yet-pruned expired entries on TTL maps until the next mutation
|
|
5332
|
-
* or an explicit `pruneExpired()` / `has` / `get` triggers a prune.
|
|
5333
|
-
*
|
|
5334
|
-
* Previously this getter ran `pruneExpired()` inline and emitted a
|
|
5335
|
-
* snapshot as a side effect — that violated spec §5.8 "no
|
|
5336
|
-
* side-effectful reads" and created a re-entrancy hazard when a
|
|
5337
|
-
* subscriber to `entries` read `.size` from its own callback. D2(a).
|
|
5338
|
-
*
|
|
5339
|
-
* For a live count that excludes expired entries, call
|
|
5340
|
-
* `bundle.pruneExpired()` first.
|
|
5341
|
-
*/
|
|
5342
|
-
get size() {
|
|
5343
|
-
return backend.size;
|
|
5344
|
-
},
|
|
5345
|
-
dispose() {
|
|
3677
|
+
return;
|
|
3678
|
+
}
|
|
5346
3679
|
}
|
|
5347
|
-
};
|
|
5348
|
-
}
|
|
5349
|
-
|
|
5350
|
-
// src/extra/composite.ts
|
|
5351
|
-
function isNodeLike(value) {
|
|
5352
|
-
return typeof value === "object" && value !== null && "cache" in value && typeof value.subscribe === "function";
|
|
5353
|
-
}
|
|
5354
|
-
function verifiable(source, verifyFn, opts) {
|
|
5355
|
-
const sourceNode = fromAny(source);
|
|
5356
|
-
const hasSourceVersioning = sourceNode.v != null;
|
|
5357
|
-
const verified = state(opts?.initialVerified ?? null, {
|
|
5358
|
-
...hasSourceVersioning ? { meta: { sourceVersion: null } } : {}
|
|
5359
|
-
});
|
|
5360
|
-
const hasTrigger = opts?.trigger !== void 0 && opts.trigger !== null;
|
|
5361
|
-
let triggerNode = null;
|
|
5362
|
-
if (hasTrigger && opts?.autoVerify) {
|
|
5363
|
-
triggerNode = merge(fromAny(opts.trigger), sourceNode);
|
|
5364
|
-
} else if (hasTrigger) {
|
|
5365
|
-
triggerNode = fromAny(opts.trigger);
|
|
5366
|
-
} else if (opts?.autoVerify) {
|
|
5367
|
-
triggerNode = sourceNode;
|
|
5368
3680
|
}
|
|
5369
|
-
|
|
5370
|
-
|
|
5371
|
-
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
3681
|
+
function evictIfNeeded() {
|
|
3682
|
+
if (!policy || maxSize <= 0) return;
|
|
3683
|
+
while (policy.size() >= maxSize) {
|
|
3684
|
+
const victims = policy.evict(1);
|
|
3685
|
+
if (victims.length === 0) break;
|
|
3686
|
+
for (const key of victims) {
|
|
3687
|
+
const nd = entries.get(key);
|
|
3688
|
+
if (nd) {
|
|
3689
|
+
const value = nd.cache;
|
|
3690
|
+
if (nd.status !== "sentinel" && tiers.length > 0) {
|
|
3691
|
+
const lastIndex = tiers.length - 1;
|
|
3692
|
+
try {
|
|
3693
|
+
fireAndForget(tiers[lastIndex].save(key, value));
|
|
3694
|
+
} catch {
|
|
3695
|
+
}
|
|
3696
|
+
for (let j = 0; j < lastIndex; j++) {
|
|
3697
|
+
try {
|
|
3698
|
+
const clearFn = tiers[j].clear;
|
|
3699
|
+
if (clearFn) fireAndForget(clearFn.call(tiers[j], key));
|
|
3700
|
+
} catch {
|
|
3701
|
+
}
|
|
3702
|
+
}
|
|
5389
3703
|
}
|
|
3704
|
+
nd.down([[TEARDOWN]]);
|
|
5390
3705
|
}
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
}
|
|
5394
|
-
return { node: sourceNode, verified, trigger: triggerNode };
|
|
5395
|
-
}
|
|
5396
|
-
function keepalive2(node2) {
|
|
5397
|
-
node2.subscribe(() => void 0);
|
|
5398
|
-
}
|
|
5399
|
-
function mapFromSnapshot(snapshot) {
|
|
5400
|
-
if (snapshot instanceof Map) return snapshot;
|
|
5401
|
-
return /* @__PURE__ */ new Map();
|
|
5402
|
-
}
|
|
5403
|
-
function applyExtraction(store, extraction) {
|
|
5404
|
-
if (!Array.isArray(extraction.upsert)) {
|
|
5405
|
-
throw new TypeError("distill extraction requires upsert: Array<{ key, value }>");
|
|
5406
|
-
}
|
|
5407
|
-
batch(() => {
|
|
5408
|
-
for (const { key, value } of extraction.upsert) {
|
|
5409
|
-
store.set(key, value);
|
|
5410
|
-
}
|
|
5411
|
-
for (const key of extraction.remove ?? []) {
|
|
5412
|
-
store.delete(key);
|
|
5413
|
-
}
|
|
5414
|
-
});
|
|
5415
|
-
}
|
|
5416
|
-
function distill(source, extractFn, opts) {
|
|
5417
|
-
const sourceNode = fromAny(source);
|
|
5418
|
-
const store = reactiveMap(opts.mapOptions ?? {});
|
|
5419
|
-
const budget = opts.budget ?? 2e3;
|
|
5420
|
-
const hasContext = opts.context !== void 0 && opts.context !== null;
|
|
5421
|
-
const contextNode = hasContext ? fromAny(opts.context) : state(null);
|
|
5422
|
-
let latestStore = mapFromSnapshot(store.entries.cache);
|
|
5423
|
-
store.entries.subscribe((msgs) => {
|
|
5424
|
-
for (const m of msgs) {
|
|
5425
|
-
if (m[0] === DATA) latestStore = mapFromSnapshot(m[1]);
|
|
3706
|
+
entries.delete(key);
|
|
3707
|
+
}
|
|
5426
3708
|
}
|
|
5427
|
-
}
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5434
|
-
const evictionKeys = derived([store.entries], ([snapshot]) => {
|
|
5435
|
-
const out = [];
|
|
5436
|
-
const entries = mapFromSnapshot(snapshot);
|
|
5437
|
-
for (const key of verdictUnsubs.keys()) {
|
|
5438
|
-
if (!entries.has(key)) {
|
|
5439
|
-
verdictUnsubs.get(key)();
|
|
5440
|
-
verdictUnsubs.delete(key);
|
|
5441
|
-
}
|
|
3709
|
+
}
|
|
3710
|
+
return {
|
|
3711
|
+
load(key) {
|
|
3712
|
+
const existing = entries.get(key);
|
|
3713
|
+
if (existing) {
|
|
3714
|
+
policy?.touch(key);
|
|
3715
|
+
return existing;
|
|
5442
3716
|
}
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
5452
|
-
|
|
3717
|
+
if (policy && maxSize > 0 && policy.size() >= maxSize) {
|
|
3718
|
+
evictIfNeeded();
|
|
3719
|
+
}
|
|
3720
|
+
const nd = state(void 0);
|
|
3721
|
+
entries.set(key, nd);
|
|
3722
|
+
policy?.insert(key);
|
|
3723
|
+
cascade(key, nd);
|
|
3724
|
+
return nd;
|
|
3725
|
+
},
|
|
3726
|
+
save(key, value) {
|
|
3727
|
+
if (writeThrough) {
|
|
3728
|
+
for (const tier of tiers) {
|
|
3729
|
+
try {
|
|
3730
|
+
fireAndForget(tier.save(key, value));
|
|
3731
|
+
} catch {
|
|
5453
3732
|
}
|
|
5454
|
-
continue;
|
|
5455
3733
|
}
|
|
5456
|
-
|
|
5457
|
-
|
|
5458
|
-
|
|
3734
|
+
} else if (tiers[0]) {
|
|
3735
|
+
try {
|
|
3736
|
+
fireAndForget(tiers[0].save(key, value));
|
|
3737
|
+
} catch {
|
|
5459
3738
|
}
|
|
5460
|
-
throw new TypeError("distill evict() must return boolean or Node<boolean>");
|
|
5461
3739
|
}
|
|
5462
|
-
|
|
5463
|
-
|
|
5464
|
-
|
|
5465
|
-
|
|
5466
|
-
|
|
5467
|
-
|
|
5468
|
-
|
|
5469
|
-
|
|
5470
|
-
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
|
|
5481
|
-
key
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
if (item.cost <= remaining) {
|
|
5491
|
-
packed.push({ key: item.key, value: item.value, score: item.score });
|
|
5492
|
-
remaining -= item.cost;
|
|
3740
|
+
const existing = entries.get(key);
|
|
3741
|
+
if (existing) {
|
|
3742
|
+
existing.down([[DATA, value]]);
|
|
3743
|
+
policy?.touch(key);
|
|
3744
|
+
} else {
|
|
3745
|
+
if (policy && maxSize > 0 && policy.size() >= maxSize) {
|
|
3746
|
+
evictIfNeeded();
|
|
3747
|
+
}
|
|
3748
|
+
const nd = state(value);
|
|
3749
|
+
entries.set(key, nd);
|
|
3750
|
+
policy?.insert(key);
|
|
3751
|
+
}
|
|
3752
|
+
},
|
|
3753
|
+
invalidate(key) {
|
|
3754
|
+
const existing = entries.get(key);
|
|
3755
|
+
if (existing) cascade(key, existing);
|
|
3756
|
+
},
|
|
3757
|
+
delete(key) {
|
|
3758
|
+
policy?.delete(key);
|
|
3759
|
+
const nd = entries.get(key);
|
|
3760
|
+
if (nd) nd.down([[TEARDOWN]]);
|
|
3761
|
+
entries.delete(key);
|
|
3762
|
+
for (const tier of tiers) {
|
|
3763
|
+
try {
|
|
3764
|
+
const clearFn = tier.clear;
|
|
3765
|
+
if (clearFn) fireAndForget(clearFn.call(tier, key));
|
|
3766
|
+
} catch {
|
|
3767
|
+
}
|
|
5493
3768
|
}
|
|
3769
|
+
},
|
|
3770
|
+
has(key) {
|
|
3771
|
+
return entries.has(key);
|
|
3772
|
+
},
|
|
3773
|
+
get size() {
|
|
3774
|
+
return entries.size;
|
|
5494
3775
|
}
|
|
5495
|
-
|
|
5496
|
-
});
|
|
5497
|
-
const size = derived([store.entries], ([snapshot]) => mapFromSnapshot(snapshot).size);
|
|
5498
|
-
keepalive2(compact);
|
|
5499
|
-
keepalive2(size);
|
|
5500
|
-
return { store, compact, size };
|
|
3776
|
+
};
|
|
5501
3777
|
}
|
|
5502
3778
|
|
|
5503
3779
|
// src/extra/pubsub.ts
|
|
@@ -5793,134 +4069,6 @@ function reactiveIndex(options = {}) {
|
|
|
5793
4069
|
};
|
|
5794
4070
|
}
|
|
5795
4071
|
|
|
5796
|
-
// src/extra/reactive-list.ts
|
|
5797
|
-
var NativeListBackend = class {
|
|
5798
|
-
_version = 0;
|
|
5799
|
-
_buf;
|
|
5800
|
-
constructor(initial) {
|
|
5801
|
-
this._buf = initial ? [...initial] : [];
|
|
5802
|
-
}
|
|
5803
|
-
get version() {
|
|
5804
|
-
return this._version;
|
|
5805
|
-
}
|
|
5806
|
-
get size() {
|
|
5807
|
-
return this._buf.length;
|
|
5808
|
-
}
|
|
5809
|
-
at(index) {
|
|
5810
|
-
if (!Number.isInteger(index)) return void 0;
|
|
5811
|
-
const i = index >= 0 ? index : this._buf.length + index;
|
|
5812
|
-
if (i < 0 || i >= this._buf.length) return void 0;
|
|
5813
|
-
return this._buf[i];
|
|
5814
|
-
}
|
|
5815
|
-
append(value) {
|
|
5816
|
-
this._buf.push(value);
|
|
5817
|
-
this._version += 1;
|
|
5818
|
-
}
|
|
5819
|
-
appendMany(values) {
|
|
5820
|
-
if (values.length === 0) return;
|
|
5821
|
-
const oldLen = this._buf.length;
|
|
5822
|
-
this._buf.length = oldLen + values.length;
|
|
5823
|
-
for (let i = 0; i < values.length; i++) {
|
|
5824
|
-
this._buf[oldLen + i] = values[i];
|
|
5825
|
-
}
|
|
5826
|
-
this._version += 1;
|
|
5827
|
-
}
|
|
5828
|
-
insert(index, value) {
|
|
5829
|
-
if (!Number.isInteger(index) || index < 0 || index > this._buf.length) {
|
|
5830
|
-
throw new RangeError(`insert: index ${index} out of range [0, ${this._buf.length}]`);
|
|
5831
|
-
}
|
|
5832
|
-
this._buf.splice(index, 0, value);
|
|
5833
|
-
this._version += 1;
|
|
5834
|
-
}
|
|
5835
|
-
insertMany(index, values) {
|
|
5836
|
-
if (!Number.isInteger(index) || index < 0 || index > this._buf.length) {
|
|
5837
|
-
throw new RangeError(`insertMany: index ${index} out of range [0, ${this._buf.length}]`);
|
|
5838
|
-
}
|
|
5839
|
-
if (values.length === 0) return;
|
|
5840
|
-
this._buf.splice(index, 0, ...values);
|
|
5841
|
-
this._version += 1;
|
|
5842
|
-
}
|
|
5843
|
-
pop(index) {
|
|
5844
|
-
if (this._buf.length === 0) {
|
|
5845
|
-
throw new RangeError("pop from empty list");
|
|
5846
|
-
}
|
|
5847
|
-
if (!Number.isInteger(index)) {
|
|
5848
|
-
throw new RangeError(`pop: index ${index} must be an integer`);
|
|
5849
|
-
}
|
|
5850
|
-
const i = index >= 0 ? index : this._buf.length + index;
|
|
5851
|
-
if (i < 0 || i >= this._buf.length) {
|
|
5852
|
-
throw new RangeError(`pop: index ${index} out of range`);
|
|
5853
|
-
}
|
|
5854
|
-
const [v] = this._buf.splice(i, 1);
|
|
5855
|
-
this._version += 1;
|
|
5856
|
-
return v;
|
|
5857
|
-
}
|
|
5858
|
-
clear() {
|
|
5859
|
-
const n = this._buf.length;
|
|
5860
|
-
if (n === 0) return 0;
|
|
5861
|
-
this._buf.length = 0;
|
|
5862
|
-
this._version += 1;
|
|
5863
|
-
return n;
|
|
5864
|
-
}
|
|
5865
|
-
toArray() {
|
|
5866
|
-
return [...this._buf];
|
|
5867
|
-
}
|
|
5868
|
-
};
|
|
5869
|
-
function reactiveList(initial, options = {}) {
|
|
5870
|
-
const { name, versioning, backend: userBackend } = options;
|
|
5871
|
-
const backend = userBackend ?? new NativeListBackend(initial);
|
|
5872
|
-
const items = state(backend.toArray(), {
|
|
5873
|
-
name,
|
|
5874
|
-
describeKind: "state",
|
|
5875
|
-
equals: (a, b) => a === b,
|
|
5876
|
-
...versioning != null ? { versioning } : {}
|
|
5877
|
-
});
|
|
5878
|
-
function pushSnapshot() {
|
|
5879
|
-
const snapshot = backend.toArray();
|
|
5880
|
-
batch(() => {
|
|
5881
|
-
items.down([[DIRTY]]);
|
|
5882
|
-
items.down([[DATA, snapshot]]);
|
|
5883
|
-
});
|
|
5884
|
-
}
|
|
5885
|
-
function wrapMutation(op) {
|
|
5886
|
-
const prev = backend.version;
|
|
5887
|
-
try {
|
|
5888
|
-
return op();
|
|
5889
|
-
} finally {
|
|
5890
|
-
if (backend.version !== prev) pushSnapshot();
|
|
5891
|
-
}
|
|
5892
|
-
}
|
|
5893
|
-
return {
|
|
5894
|
-
items,
|
|
5895
|
-
get size() {
|
|
5896
|
-
return backend.size;
|
|
5897
|
-
},
|
|
5898
|
-
at(index) {
|
|
5899
|
-
return backend.at(index);
|
|
5900
|
-
},
|
|
5901
|
-
append(value) {
|
|
5902
|
-
wrapMutation(() => backend.append(value));
|
|
5903
|
-
},
|
|
5904
|
-
appendMany(values) {
|
|
5905
|
-
wrapMutation(() => backend.appendMany(values));
|
|
5906
|
-
},
|
|
5907
|
-
insert(index, value) {
|
|
5908
|
-
wrapMutation(() => backend.insert(index, value));
|
|
5909
|
-
},
|
|
5910
|
-
insertMany(index, values) {
|
|
5911
|
-
wrapMutation(() => backend.insertMany(index, values));
|
|
5912
|
-
},
|
|
5913
|
-
pop(index = -1) {
|
|
5914
|
-
return wrapMutation(() => backend.pop(index));
|
|
5915
|
-
},
|
|
5916
|
-
clear() {
|
|
5917
|
-
wrapMutation(() => backend.clear());
|
|
5918
|
-
},
|
|
5919
|
-
dispose() {
|
|
5920
|
-
}
|
|
5921
|
-
};
|
|
5922
|
-
}
|
|
5923
|
-
|
|
5924
4072
|
// src/extra/sources-fs.ts
|
|
5925
4073
|
import { existsSync, watch } from "node:fs";
|
|
5926
4074
|
import { resolve as resolvePath } from "node:path";
|
|
@@ -6846,63 +4994,8 @@ function workerSelf(target, opts) {
|
|
|
6846
4994
|
}
|
|
6847
4995
|
|
|
6848
4996
|
export {
|
|
6849
|
-
NS_PER_MS,
|
|
6850
|
-
NS_PER_SEC,
|
|
6851
|
-
constant,
|
|
6852
|
-
linear,
|
|
6853
|
-
exponential,
|
|
6854
|
-
fibonacci,
|
|
6855
|
-
decorrelatedJitter,
|
|
6856
|
-
withMaxAttempts,
|
|
6857
|
-
resolveBackoffPreset,
|
|
6858
4997
|
externalProducer,
|
|
6859
4998
|
externalBundle,
|
|
6860
|
-
map,
|
|
6861
|
-
filter,
|
|
6862
|
-
scan,
|
|
6863
|
-
reduce,
|
|
6864
|
-
take,
|
|
6865
|
-
skip,
|
|
6866
|
-
takeWhile,
|
|
6867
|
-
takeUntil,
|
|
6868
|
-
first,
|
|
6869
|
-
last,
|
|
6870
|
-
find,
|
|
6871
|
-
elementAt,
|
|
6872
|
-
tap,
|
|
6873
|
-
distinctUntilChanged,
|
|
6874
|
-
pairwise,
|
|
6875
|
-
combine,
|
|
6876
|
-
withLatestFrom,
|
|
6877
|
-
merge,
|
|
6878
|
-
zip,
|
|
6879
|
-
concat,
|
|
6880
|
-
race,
|
|
6881
|
-
switchMap,
|
|
6882
|
-
exhaustMap,
|
|
6883
|
-
concatMap,
|
|
6884
|
-
mergeMap,
|
|
6885
|
-
flatMap,
|
|
6886
|
-
delay,
|
|
6887
|
-
debounce,
|
|
6888
|
-
throttle,
|
|
6889
|
-
sample,
|
|
6890
|
-
audit,
|
|
6891
|
-
buffer,
|
|
6892
|
-
bufferCount,
|
|
6893
|
-
windowCount,
|
|
6894
|
-
bufferTime,
|
|
6895
|
-
windowTime,
|
|
6896
|
-
window,
|
|
6897
|
-
interval,
|
|
6898
|
-
repeat,
|
|
6899
|
-
pausable,
|
|
6900
|
-
rescue,
|
|
6901
|
-
valve,
|
|
6902
|
-
combineLatest,
|
|
6903
|
-
debounceTime,
|
|
6904
|
-
throttleTime,
|
|
6905
|
-
catchError,
|
|
6906
4999
|
reactiveSink,
|
|
6907
5000
|
retry,
|
|
6908
5001
|
retrySource,
|
|
@@ -6970,16 +5063,10 @@ export {
|
|
|
6970
5063
|
fromKysely,
|
|
6971
5064
|
lru,
|
|
6972
5065
|
cascadingCache,
|
|
6973
|
-
NativeMapBackend,
|
|
6974
|
-
reactiveMap,
|
|
6975
|
-
verifiable,
|
|
6976
|
-
distill,
|
|
6977
5066
|
NativePubSubBackend,
|
|
6978
5067
|
pubsub,
|
|
6979
5068
|
NativeIndexBackend,
|
|
6980
5069
|
reactiveIndex,
|
|
6981
|
-
NativeListBackend,
|
|
6982
|
-
reactiveList,
|
|
6983
5070
|
fromFSWatch,
|
|
6984
5071
|
memoryStorage,
|
|
6985
5072
|
dictStorage,
|
|
@@ -6997,4 +5084,4 @@ export {
|
|
|
6997
5084
|
workerSelf,
|
|
6998
5085
|
extra_exports
|
|
6999
5086
|
};
|
|
7000
|
-
//# sourceMappingURL=chunk-
|
|
5087
|
+
//# sourceMappingURL=chunk-BQ6RQQFF.js.map
|