@graphrefly/graphrefly 0.25.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/README.md +8 -0
- 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-QOWVNWOC.js → chunk-3ZWCKRHX.js} +27 -25
- package/dist/{chunk-QOWVNWOC.js.map → chunk-3ZWCKRHX.js.map} +1 -1
- package/dist/chunk-APFNLIRG.js +62 -0
- package/dist/chunk-APFNLIRG.js.map +1 -0
- package/dist/chunk-AT5LKYNL.js +395 -0
- package/dist/chunk-AT5LKYNL.js.map +1 -0
- package/dist/{chunk-IAHGTNOZ.js → chunk-BQ6RQQFF.js} +351 -2095
- package/dist/chunk-BQ6RQQFF.js.map +1 -0
- package/dist/{chunk-L2GLW2U7.js → chunk-BVZYTZ5H.js} +9 -103
- package/dist/chunk-BVZYTZ5H.js.map +1 -0
- package/dist/{chunk-EVR6UFUV.js → chunk-DST5DKZS.js} +19 -15
- package/dist/{chunk-EVR6UFUV.js.map → chunk-DST5DKZS.js.map} +1 -1
- package/dist/{chunk-TKE3JGOH.js → chunk-GTE6PWRZ.js} +5 -692
- package/dist/chunk-GTE6PWRZ.js.map +1 -0
- package/dist/chunk-HXZEYDUR.js +94 -0
- package/dist/chunk-HXZEYDUR.js.map +1 -0
- package/dist/chunk-J22W6HV3.js +107 -0
- package/dist/chunk-J22W6HV3.js.map +1 -0
- package/dist/{chunk-PY4XCDLR.js → chunk-J2VBW3DZ.js} +6 -95
- package/dist/chunk-J2VBW3DZ.js.map +1 -0
- package/dist/{chunk-HWPIFSW2.js → chunk-JSCT3CR4.js} +6 -4
- package/dist/{chunk-HWPIFSW2.js.map → chunk-JSCT3CR4.js.map} +1 -1
- package/dist/chunk-JWBCY4NC.js +330 -0
- package/dist/chunk-JWBCY4NC.js.map +1 -0
- package/dist/chunk-K2AUJHVP.js +2251 -0
- package/dist/chunk-K2AUJHVP.js.map +1 -0
- package/dist/chunk-MJ2NKQQL.js +119 -0
- package/dist/chunk-MJ2NKQQL.js.map +1 -0
- package/dist/chunk-N6UR7YVY.js +198 -0
- package/dist/chunk-N6UR7YVY.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-OHISZPOJ.js +97 -0
- package/dist/chunk-OHISZPOJ.js.map +1 -0
- package/dist/chunk-OU5CQKNW.js +102 -0
- package/dist/chunk-OU5CQKNW.js.map +1 -0
- package/dist/{chunk-XOFWRC73.js → chunk-PF7GRZMW.js} +316 -21
- package/dist/chunk-PF7GRZMW.js.map +1 -0
- package/dist/{chunk-5DJTTKX3.js → chunk-PHOUUNK7.js} +74 -111
- package/dist/chunk-PHOUUNK7.js.map +1 -0
- package/dist/chunk-RNHBMHKA.js +1665 -0
- package/dist/chunk-RNHBMHKA.js.map +1 -0
- package/dist/chunk-SX52TAR4.js +110 -0
- package/dist/chunk-SX52TAR4.js.map +1 -0
- package/dist/{chunk-H4RVA4VE.js → chunk-VYPWMZ6H.js} +2 -2
- package/dist/chunk-WBZOVTYK.js +171 -0
- package/dist/chunk-WBZOVTYK.js.map +1 -0
- package/dist/chunk-WKNUIZOY.js +354 -0
- package/dist/chunk-WKNUIZOY.js.map +1 -0
- package/dist/chunk-X3VMZYBT.js +713 -0
- package/dist/chunk-X3VMZYBT.js.map +1 -0
- package/dist/chunk-X5R3GL6H.js +525 -0
- package/dist/chunk-X5R3GL6H.js.map +1 -0
- package/dist/chunk-XGPU467M.js +136 -0
- package/dist/chunk-XGPU467M.js.map +1 -0
- package/dist/compat/index.cjs +7656 -0
- package/dist/compat/index.cjs.map +1 -0
- package/dist/compat/index.d.cts +18 -0
- package/dist/compat/index.d.ts +18 -0
- package/dist/compat/index.js +50 -0
- package/dist/compat/index.js.map +1 -0
- package/dist/compat/jotai/index.cjs +2048 -0
- package/dist/compat/jotai/index.cjs.map +1 -0
- package/dist/compat/jotai/index.d.cts +2 -0
- package/dist/compat/jotai/index.d.ts +2 -0
- package/dist/compat/jotai/index.js +9 -0
- package/dist/compat/jotai/index.js.map +1 -0
- package/dist/compat/nanostores/index.cjs +2175 -0
- package/dist/compat/nanostores/index.cjs.map +1 -0
- package/dist/compat/nanostores/index.d.cts +2 -0
- package/dist/compat/nanostores/index.d.ts +2 -0
- package/dist/compat/nanostores/index.js +23 -0
- package/dist/compat/nanostores/index.js.map +1 -0
- package/dist/compat/nestjs/index.cjs +350 -16
- package/dist/compat/nestjs/index.cjs.map +1 -1
- package/dist/compat/nestjs/index.d.cts +6 -6
- package/dist/compat/nestjs/index.d.ts +6 -6
- package/dist/compat/nestjs/index.js +11 -9
- package/dist/compat/react/index.cjs +141 -0
- package/dist/compat/react/index.cjs.map +1 -0
- package/dist/compat/react/index.d.cts +2 -0
- package/dist/compat/react/index.d.ts +2 -0
- package/dist/compat/react/index.js +12 -0
- package/dist/compat/react/index.js.map +1 -0
- package/dist/compat/solid/index.cjs +128 -0
- package/dist/compat/solid/index.cjs.map +1 -0
- package/dist/compat/solid/index.d.cts +2 -0
- package/dist/compat/solid/index.d.ts +2 -0
- package/dist/compat/solid/index.js +12 -0
- package/dist/compat/solid/index.js.map +1 -0
- package/dist/compat/svelte/index.cjs +131 -0
- package/dist/compat/svelte/index.cjs.map +1 -0
- package/dist/compat/svelte/index.d.cts +2 -0
- package/dist/compat/svelte/index.d.ts +2 -0
- package/dist/compat/svelte/index.js +12 -0
- package/dist/compat/svelte/index.js.map +1 -0
- package/dist/compat/vue/index.cjs +146 -0
- package/dist/compat/vue/index.cjs.map +1 -0
- package/dist/compat/vue/index.d.cts +3 -0
- package/dist/compat/vue/index.d.ts +3 -0
- package/dist/compat/vue/index.js +12 -0
- package/dist/compat/vue/index.js.map +1 -0
- package/dist/compat/zustand/index.cjs +4931 -0
- package/dist/compat/zustand/index.cjs.map +1 -0
- package/dist/compat/zustand/index.d.cts +5 -0
- package/dist/compat/zustand/index.d.ts +5 -0
- package/dist/compat/zustand/index.js +12 -0
- package/dist/compat/zustand/index.js.map +1 -0
- package/dist/composite-C7PcQvcs.d.cts +303 -0
- package/dist/composite-aUCvjZVR.d.ts +303 -0
- package/dist/core/index.cjs +53 -4
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +4 -3
- package/dist/core/index.d.ts +4 -3
- package/dist/core/index.js +26 -24
- package/dist/demo-shell-BDkOptd6.d.ts +102 -0
- package/dist/demo-shell-Crid1WdR.d.cts +102 -0
- package/dist/extra/index.cjs +222 -110
- package/dist/extra/index.cjs.map +1 -1
- package/dist/extra/index.d.cts +6 -4
- package/dist/extra/index.d.ts +6 -4
- package/dist/extra/index.js +72 -65
- package/dist/extra/sources.cjs +2486 -0
- package/dist/extra/sources.cjs.map +1 -0
- package/dist/extra/sources.d.cts +465 -0
- package/dist/extra/sources.d.ts +465 -0
- package/dist/extra/sources.js +57 -0
- package/dist/extra/sources.js.map +1 -0
- package/dist/graph/index.cjs +408 -14
- package/dist/graph/index.cjs.map +1 -1
- package/dist/graph/index.d.cts +5 -5
- package/dist/graph/index.d.ts +5 -5
- package/dist/graph/index.js +13 -5
- package/dist/{graph-D-3JIQme.d.cts → graph-CCwGKLCm.d.ts} +195 -4
- package/dist/{graph-B6NFqv3z.d.ts → graph-DNCrvZSn.d.cts} +195 -4
- package/dist/index-3lsddbbS.d.ts +86 -0
- package/dist/index-B1tloyhO.d.cts +34 -0
- package/dist/{index-CYkjxu3s.d.ts → index-B6D3QNSA.d.ts} +33 -4
- package/dist/index-B6EhDnjH.d.cts +37 -0
- package/dist/index-B9B7_HEY.d.ts +37 -0
- package/dist/{index-Ds23Wvou.d.ts → index-BHlKbUwO.d.cts} +131 -883
- package/dist/{index-DiobMNwE.d.ts → index-BPVt8kqc.d.ts} +3 -3
- package/dist/index-BaSM3aYt.d.ts +195 -0
- package/dist/index-BuEoe-Qu.d.ts +121 -0
- package/dist/{index-Ch0IpIO0.d.cts → index-BwfLUNw4.d.ts} +131 -883
- package/dist/index-ByQxazQJ.d.cts +86 -0
- package/dist/index-C0svESO4.d.ts +127 -0
- package/dist/{index-OXImXMq6.d.ts → index-C8oil6M6.d.ts} +18 -196
- package/dist/{index-DKE1EATr.d.cts → index-CI3DprxP.d.cts} +18 -196
- package/dist/{index-AMWewNDe.d.cts → index-CO8uBlUh.d.cts} +33 -4
- package/dist/index-CxFrXH4m.d.ts +45 -0
- package/dist/index-D8wS_PeY.d.cts +121 -0
- package/dist/index-DO_6JN9Z.d.cts +127 -0
- package/dist/index-DVGiGFGT.d.cts +195 -0
- package/dist/index-DYme44FM.d.cts +44 -0
- package/dist/{index-J7Kc0oIQ.d.cts → index-DlLp-2Xn.d.cts} +3 -3
- package/dist/index-Dzk2hrlR.d.ts +44 -0
- package/dist/index-VHqptjhu.d.cts +45 -0
- package/dist/index-VdHQMPy1.d.ts +36 -0
- package/dist/index-Xi3u0HCQ.d.cts +36 -0
- package/dist/index-wEn0eFe8.d.ts +34 -0
- package/dist/index.cjs +1780 -176
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +784 -2082
- package/dist/index.d.ts +784 -2082
- package/dist/index.js +955 -4349
- 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-DWbkoq1s.d.cts → meta-BxCA7rcr.d.cts} +1 -1
- package/dist/{meta-CnkLA_43.d.ts → meta-CbznRPYJ.d.ts} +1 -1
- package/dist/{node-B-f-Lu-k.d.cts → node-BmerH3kS.d.cts} +26 -1
- package/dist/{node-B-f-Lu-k.d.ts → node-BmerH3kS.d.ts} +26 -1
- package/dist/{observable-uP-wy_uK.d.ts → observable-BgGUwcqp.d.ts} +1 -1
- package/dist/{observable-DBnrwcar.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.cjs +5604 -0
- package/dist/patterns/demo-shell.cjs.map +1 -0
- package/dist/patterns/demo-shell.d.cts +6 -0
- package/dist/patterns/demo-shell.d.ts +6 -0
- package/dist/patterns/demo-shell.js +15 -0
- package/dist/patterns/demo-shell.js.map +1 -0
- 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.cjs +355 -13
- package/dist/patterns/reactive-layout/index.cjs.map +1 -1
- package/dist/patterns/reactive-layout/index.d.cts +6 -5
- package/dist/patterns/reactive-layout/index.d.ts +6 -5
- package/dist/patterns/reactive-layout/index.js +15 -12
- package/dist/reactive-layout-MQP--J3F.d.cts +183 -0
- package/dist/reactive-layout-u5Ulnqag.d.ts +183 -0
- package/dist/{storage-BuTdpCI1.d.cts → storage-CMjUUuxn.d.ts} +10 -2
- package/dist/{storage-F2X1U1x0.d.ts → storage-DdWlZo6U.d.cts} +10 -2
- package/dist/sugar-CCOxXK1e.d.ts +201 -0
- package/dist/sugar-D02n5JjF.d.cts +201 -0
- package/package.json +63 -3
- package/dist/chunk-5DJTTKX3.js.map +0 -1
- package/dist/chunk-IAHGTNOZ.js.map +0 -1
- package/dist/chunk-L2GLW2U7.js.map +0 -1
- package/dist/chunk-MW4VAKAO.js +0 -47
- package/dist/chunk-MW4VAKAO.js.map +0 -1
- package/dist/chunk-PY4XCDLR.js.map +0 -1
- package/dist/chunk-TKE3JGOH.js.map +0 -1
- package/dist/chunk-XOFWRC73.js.map +0 -1
- package/dist/index-BJB7t9gg.d.cts +0 -392
- package/dist/index-C-TXEa7C.d.ts +0 -392
- /package/dist/{chunk-H4RVA4VE.js.map → chunk-VYPWMZ6H.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,
|
|
@@ -15,7 +82,6 @@ import {
|
|
|
15
82
|
fromAsyncIter,
|
|
16
83
|
fromCron,
|
|
17
84
|
fromEvent,
|
|
18
|
-
fromFSWatch,
|
|
19
85
|
fromIter,
|
|
20
86
|
fromPromise,
|
|
21
87
|
fromRaf,
|
|
@@ -33,11 +99,22 @@ import {
|
|
|
33
99
|
shareReplay,
|
|
34
100
|
throwError,
|
|
35
101
|
toArray
|
|
36
|
-
} from "./chunk-
|
|
102
|
+
} from "./chunk-BVZYTZ5H.js";
|
|
37
103
|
import {
|
|
38
104
|
ResettableTimer,
|
|
39
105
|
RingBuffer
|
|
40
106
|
} from "./chunk-7TAQJHQV.js";
|
|
107
|
+
import {
|
|
108
|
+
batch,
|
|
109
|
+
defaultConfig,
|
|
110
|
+
derived,
|
|
111
|
+
effect,
|
|
112
|
+
monotonicNs,
|
|
113
|
+
node,
|
|
114
|
+
producer,
|
|
115
|
+
state,
|
|
116
|
+
wallClockNs
|
|
117
|
+
} from "./chunk-PHOUUNK7.js";
|
|
41
118
|
import {
|
|
42
119
|
COMPLETE,
|
|
43
120
|
DATA,
|
|
@@ -47,20 +124,10 @@ import {
|
|
|
47
124
|
PAUSE,
|
|
48
125
|
RESOLVED,
|
|
49
126
|
RESUME,
|
|
50
|
-
START,
|
|
51
127
|
TEARDOWN,
|
|
52
128
|
__export,
|
|
53
|
-
__require
|
|
54
|
-
|
|
55
|
-
defaultConfig,
|
|
56
|
-
derived,
|
|
57
|
-
effect,
|
|
58
|
-
monotonicNs,
|
|
59
|
-
node,
|
|
60
|
-
producer,
|
|
61
|
-
state,
|
|
62
|
-
wallClockNs
|
|
63
|
-
} from "./chunk-5DJTTKX3.js";
|
|
129
|
+
__require
|
|
130
|
+
} from "./chunk-SX52TAR4.js";
|
|
64
131
|
|
|
65
132
|
// src/extra/index.ts
|
|
66
133
|
var extra_exports = {};
|
|
@@ -248,99 +315,6 @@ __export(extra_exports, {
|
|
|
248
315
|
zip: () => zip
|
|
249
316
|
});
|
|
250
317
|
|
|
251
|
-
// src/extra/backoff.ts
|
|
252
|
-
var NS_PER_MS = 1e6;
|
|
253
|
-
var NS_PER_SEC = 1e9;
|
|
254
|
-
function clampNonNegative(value) {
|
|
255
|
-
return value < 0 ? 0 : value;
|
|
256
|
-
}
|
|
257
|
-
function applyJitter(delay2, jitter) {
|
|
258
|
-
if (jitter === "none") return delay2;
|
|
259
|
-
if (jitter === "full") return Math.random() * delay2;
|
|
260
|
-
return delay2 / 2 + Math.random() * (delay2 / 2);
|
|
261
|
-
}
|
|
262
|
-
function randomBetween(min, max) {
|
|
263
|
-
return min + Math.random() * (max - min);
|
|
264
|
-
}
|
|
265
|
-
function constant(delayNs) {
|
|
266
|
-
const safe = clampNonNegative(delayNs);
|
|
267
|
-
return () => safe;
|
|
268
|
-
}
|
|
269
|
-
function linear(baseNs, stepNs) {
|
|
270
|
-
const safeBase = clampNonNegative(baseNs);
|
|
271
|
-
const safeStep = stepNs === void 0 ? safeBase : clampNonNegative(stepNs);
|
|
272
|
-
return (attempt) => safeBase + safeStep * Math.max(0, attempt);
|
|
273
|
-
}
|
|
274
|
-
function exponential(options) {
|
|
275
|
-
const baseNs = clampNonNegative(options?.baseNs ?? 100 * NS_PER_MS);
|
|
276
|
-
const factor = options?.factor !== void 0 && options.factor < 1 ? 1 : options?.factor ?? 2;
|
|
277
|
-
const maxDelayNs = clampNonNegative(options?.maxDelayNs ?? 30 * NS_PER_SEC);
|
|
278
|
-
const jitter = options?.jitter ?? "none";
|
|
279
|
-
return (attempt) => {
|
|
280
|
-
let delay2;
|
|
281
|
-
if (baseNs === 0) {
|
|
282
|
-
delay2 = 0;
|
|
283
|
-
} else if (factor === 1) {
|
|
284
|
-
delay2 = baseNs;
|
|
285
|
-
} else {
|
|
286
|
-
const capRatio = maxDelayNs / baseNs;
|
|
287
|
-
let growth = 1;
|
|
288
|
-
for (let i = 0; i < Math.max(0, attempt); i++) {
|
|
289
|
-
if (growth >= capRatio) {
|
|
290
|
-
growth = capRatio;
|
|
291
|
-
break;
|
|
292
|
-
}
|
|
293
|
-
growth *= factor;
|
|
294
|
-
}
|
|
295
|
-
delay2 = baseNs * growth;
|
|
296
|
-
if (delay2 > maxDelayNs) delay2 = maxDelayNs;
|
|
297
|
-
}
|
|
298
|
-
return applyJitter(delay2, jitter);
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
function fibonacci(baseNs = 100 * NS_PER_MS, maxDelayNs = 30 * NS_PER_SEC) {
|
|
302
|
-
const safeBase = clampNonNegative(baseNs);
|
|
303
|
-
const safeMax = clampNonNegative(maxDelayNs);
|
|
304
|
-
function fibUnit(attempt) {
|
|
305
|
-
if (attempt <= 0) return 1;
|
|
306
|
-
let prev = 1;
|
|
307
|
-
let cur = 2;
|
|
308
|
-
for (let i = 1; i < attempt; i++) {
|
|
309
|
-
const next = prev + cur;
|
|
310
|
-
prev = cur;
|
|
311
|
-
cur = next;
|
|
312
|
-
}
|
|
313
|
-
return cur;
|
|
314
|
-
}
|
|
315
|
-
return (attempt) => {
|
|
316
|
-
const raw = fibUnit(attempt) * safeBase;
|
|
317
|
-
return raw <= safeMax ? raw : safeMax;
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
function decorrelatedJitter(baseNs = 100 * NS_PER_MS, maxNs = 30 * NS_PER_SEC) {
|
|
321
|
-
return (_attempt, _error, prevDelayNs) => {
|
|
322
|
-
const last2 = prevDelayNs ?? baseNs;
|
|
323
|
-
const ceiling = Math.min(maxNs, last2 * 3);
|
|
324
|
-
return randomBetween(baseNs, ceiling);
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
function withMaxAttempts(strategy, maxAttempts) {
|
|
328
|
-
return (attempt, error, prevDelayNs) => {
|
|
329
|
-
if (attempt >= maxAttempts) return null;
|
|
330
|
-
return strategy(attempt, error, prevDelayNs);
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
function resolveBackoffPreset(name) {
|
|
334
|
-
if (name === "constant") return constant(1 * NS_PER_SEC);
|
|
335
|
-
if (name === "linear") return linear(1 * NS_PER_SEC);
|
|
336
|
-
if (name === "exponential") return exponential();
|
|
337
|
-
if (name === "fibonacci") return fibonacci();
|
|
338
|
-
if (name === "decorrelatedJitter") return decorrelatedJitter();
|
|
339
|
-
throw new Error(
|
|
340
|
-
`Unknown backoff preset: "${String(name)}". Use one of: constant, linear, exponential, fibonacci, decorrelatedJitter`
|
|
341
|
-
);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
318
|
// src/extra/external-register.ts
|
|
345
319
|
function sourceOpts(opts) {
|
|
346
320
|
return { describeKind: "producer", ...opts };
|
|
@@ -434,1363 +408,28 @@ function externalBundle(register, channels, opts) {
|
|
|
434
408
|
bundle.complete = () => {
|
|
435
409
|
if (!active) return;
|
|
436
410
|
active = false;
|
|
437
|
-
batch(() => {
|
|
438
|
-
for (const n of channelNodes) n.down([[COMPLETE]]);
|
|
439
|
-
});
|
|
440
|
-
finishCleanup();
|
|
441
|
-
};
|
|
442
|
-
const ret = register(bundle);
|
|
443
|
-
cleanup = typeof ret === "function" ? ret : void 0;
|
|
444
|
-
const dispose = () => {
|
|
445
|
-
if (!active) return;
|
|
446
|
-
active = false;
|
|
447
|
-
batch(() => {
|
|
448
|
-
for (const n of channelNodes) {
|
|
449
|
-
try {
|
|
450
|
-
n.down([[COMPLETE]]);
|
|
451
|
-
} catch {
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
});
|
|
455
|
-
finishCleanup();
|
|
456
|
-
};
|
|
457
|
-
return Object.assign(nodes, { dispose });
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
// src/extra/operators.ts
|
|
461
|
-
function operatorOpts(opts) {
|
|
462
|
-
return { describeKind: "derived", ...opts };
|
|
463
|
-
}
|
|
464
|
-
function map(source, project, opts) {
|
|
465
|
-
return node(
|
|
466
|
-
[source],
|
|
467
|
-
(data, a) => {
|
|
468
|
-
const batch0 = data[0];
|
|
469
|
-
if (batch0 == null || batch0.length === 0) {
|
|
470
|
-
a.down([[RESOLVED]]);
|
|
471
|
-
return;
|
|
472
|
-
}
|
|
473
|
-
for (const v of batch0) {
|
|
474
|
-
a.emit(project(v));
|
|
475
|
-
}
|
|
476
|
-
},
|
|
477
|
-
operatorOpts(opts)
|
|
478
|
-
);
|
|
479
|
-
}
|
|
480
|
-
function filter(source, predicate, opts) {
|
|
481
|
-
return node(
|
|
482
|
-
[source],
|
|
483
|
-
(data, a) => {
|
|
484
|
-
const batch0 = data[0];
|
|
485
|
-
if (batch0 == null || batch0.length === 0) {
|
|
486
|
-
a.down([[RESOLVED]]);
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
let emitted = false;
|
|
490
|
-
for (const v of batch0) {
|
|
491
|
-
if (predicate(v)) {
|
|
492
|
-
a.emit(v);
|
|
493
|
-
emitted = true;
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
if (!emitted) a.down([[RESOLVED]]);
|
|
497
|
-
},
|
|
498
|
-
operatorOpts(opts)
|
|
499
|
-
);
|
|
500
|
-
}
|
|
501
|
-
function scan(source, reducer, seed, opts) {
|
|
502
|
-
return node(
|
|
503
|
-
[source],
|
|
504
|
-
(data, a, ctx) => {
|
|
505
|
-
if (!("acc" in ctx.store)) ctx.store.acc = seed;
|
|
506
|
-
const batch0 = data[0];
|
|
507
|
-
if (batch0 == null || batch0.length === 0) {
|
|
508
|
-
a.down([[RESOLVED]]);
|
|
509
|
-
return;
|
|
510
|
-
}
|
|
511
|
-
for (const v of batch0) {
|
|
512
|
-
ctx.store.acc = reducer(ctx.store.acc, v);
|
|
513
|
-
a.emit(ctx.store.acc);
|
|
514
|
-
}
|
|
515
|
-
},
|
|
516
|
-
{ ...operatorOpts(opts), initial: seed, resetOnTeardown: true }
|
|
517
|
-
);
|
|
518
|
-
}
|
|
519
|
-
function reduce(source, reducer, seed, opts) {
|
|
520
|
-
return node(
|
|
521
|
-
[source],
|
|
522
|
-
(data, a, ctx) => {
|
|
523
|
-
if (!("acc" in ctx.store)) ctx.store.acc = seed;
|
|
524
|
-
if (ctx.terminalDeps[0] === true) {
|
|
525
|
-
a.emit(ctx.store.acc);
|
|
526
|
-
a.down([[COMPLETE]]);
|
|
527
|
-
return;
|
|
528
|
-
}
|
|
529
|
-
const batch0 = data[0];
|
|
530
|
-
if (batch0 == null || batch0.length === 0) {
|
|
531
|
-
a.down([[RESOLVED]]);
|
|
532
|
-
return;
|
|
533
|
-
}
|
|
534
|
-
for (const v of batch0) {
|
|
535
|
-
ctx.store.acc = reducer(ctx.store.acc, v);
|
|
536
|
-
}
|
|
537
|
-
},
|
|
538
|
-
{
|
|
539
|
-
...operatorOpts(opts),
|
|
540
|
-
completeWhenDepsComplete: false
|
|
541
|
-
}
|
|
542
|
-
);
|
|
543
|
-
}
|
|
544
|
-
function take(source, count, opts) {
|
|
545
|
-
if (count <= 0) {
|
|
546
|
-
return node(
|
|
547
|
-
[source],
|
|
548
|
-
(_d, a, ctx) => {
|
|
549
|
-
if (ctx.store.completed) return;
|
|
550
|
-
ctx.store.completed = true;
|
|
551
|
-
a.down([[COMPLETE]]);
|
|
552
|
-
},
|
|
553
|
-
{
|
|
554
|
-
...operatorOpts(opts),
|
|
555
|
-
completeWhenDepsComplete: false
|
|
556
|
-
}
|
|
557
|
-
);
|
|
558
|
-
}
|
|
559
|
-
return node(
|
|
560
|
-
[source],
|
|
561
|
-
(data, a, ctx) => {
|
|
562
|
-
if (!("taken" in ctx.store)) ctx.store.taken = 0;
|
|
563
|
-
if (ctx.store.done) {
|
|
564
|
-
a.down([[RESOLVED]]);
|
|
565
|
-
return;
|
|
566
|
-
}
|
|
567
|
-
if (ctx.terminalDeps[0] === true) {
|
|
568
|
-
ctx.store.done = true;
|
|
569
|
-
a.down([[COMPLETE]]);
|
|
570
|
-
return;
|
|
571
|
-
}
|
|
572
|
-
const batch0 = data[0];
|
|
573
|
-
if (batch0 == null || batch0.length === 0) {
|
|
574
|
-
a.down([[RESOLVED]]);
|
|
575
|
-
return;
|
|
576
|
-
}
|
|
577
|
-
for (const v of batch0) {
|
|
578
|
-
ctx.store.taken++;
|
|
579
|
-
a.emit(v);
|
|
580
|
-
if (ctx.store.taken >= count) {
|
|
581
|
-
ctx.store.done = true;
|
|
582
|
-
a.down([[COMPLETE]]);
|
|
583
|
-
return;
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
},
|
|
587
|
-
{
|
|
588
|
-
...operatorOpts(opts),
|
|
589
|
-
completeWhenDepsComplete: false
|
|
590
|
-
}
|
|
591
|
-
);
|
|
592
|
-
}
|
|
593
|
-
function skip(source, count, opts) {
|
|
594
|
-
return node(
|
|
595
|
-
[source],
|
|
596
|
-
(data, a, ctx) => {
|
|
597
|
-
if (!("skipped" in ctx.store)) ctx.store.skipped = 0;
|
|
598
|
-
const batch0 = data[0];
|
|
599
|
-
if (batch0 == null || batch0.length === 0) {
|
|
600
|
-
a.down([[RESOLVED]]);
|
|
601
|
-
return;
|
|
602
|
-
}
|
|
603
|
-
let emitted = false;
|
|
604
|
-
for (const v of batch0) {
|
|
605
|
-
ctx.store.skipped++;
|
|
606
|
-
if (ctx.store.skipped <= count) {
|
|
607
|
-
} else {
|
|
608
|
-
a.emit(v);
|
|
609
|
-
emitted = true;
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
if (!emitted) a.down([[RESOLVED]]);
|
|
613
|
-
},
|
|
614
|
-
operatorOpts(opts)
|
|
615
|
-
);
|
|
616
|
-
}
|
|
617
|
-
function takeWhile(source, predicate, opts) {
|
|
618
|
-
return node(
|
|
619
|
-
[source],
|
|
620
|
-
(data, a, ctx) => {
|
|
621
|
-
if (ctx.store.done) {
|
|
622
|
-
a.down([[RESOLVED]]);
|
|
623
|
-
return;
|
|
624
|
-
}
|
|
625
|
-
const batch0 = data[0];
|
|
626
|
-
if (batch0 == null || batch0.length === 0) {
|
|
627
|
-
a.down([[RESOLVED]]);
|
|
628
|
-
return;
|
|
629
|
-
}
|
|
630
|
-
for (const v of batch0) {
|
|
631
|
-
if (!predicate(v)) {
|
|
632
|
-
ctx.store.done = true;
|
|
633
|
-
a.down([[COMPLETE]]);
|
|
634
|
-
return;
|
|
635
|
-
}
|
|
636
|
-
a.emit(v);
|
|
637
|
-
}
|
|
638
|
-
},
|
|
639
|
-
{
|
|
640
|
-
...operatorOpts(opts),
|
|
641
|
-
completeWhenDepsComplete: false
|
|
642
|
-
}
|
|
643
|
-
);
|
|
644
|
-
}
|
|
645
|
-
function takeUntil(source, notifier, opts) {
|
|
646
|
-
const pred = opts?.predicate ?? ((m) => m[0] === DATA);
|
|
647
|
-
const { predicate: _, ...restOpts } = opts ?? {};
|
|
648
|
-
return producer(
|
|
649
|
-
(a) => {
|
|
650
|
-
let stopped = false;
|
|
651
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
652
|
-
if (stopped) return;
|
|
653
|
-
for (const m of msgs) {
|
|
654
|
-
if (stopped) return;
|
|
655
|
-
if (m[0] === DATA) a.emit(m[1]);
|
|
656
|
-
else if (m[0] === COMPLETE || m[0] === ERROR) {
|
|
657
|
-
stopped = true;
|
|
658
|
-
a.down([m]);
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
});
|
|
662
|
-
const notUnsub = notifier.subscribe((msgs) => {
|
|
663
|
-
if (stopped) return;
|
|
664
|
-
for (const m of msgs) {
|
|
665
|
-
if (stopped) return;
|
|
666
|
-
if (pred(m)) {
|
|
667
|
-
stopped = true;
|
|
668
|
-
a.down([[COMPLETE]]);
|
|
669
|
-
return;
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
});
|
|
673
|
-
return () => {
|
|
674
|
-
srcUnsub();
|
|
675
|
-
notUnsub();
|
|
676
|
-
};
|
|
677
|
-
},
|
|
678
|
-
operatorOpts(restOpts)
|
|
679
|
-
);
|
|
680
|
-
}
|
|
681
|
-
function first(source, opts) {
|
|
682
|
-
return take(source, 1, opts);
|
|
683
|
-
}
|
|
684
|
-
function last(source, options) {
|
|
685
|
-
const { defaultValue, ...rest } = options ?? {};
|
|
686
|
-
const useDefault = options != null && Object.hasOwn(options, "defaultValue");
|
|
687
|
-
return node(
|
|
688
|
-
[source],
|
|
689
|
-
(data, a, ctx) => {
|
|
690
|
-
if (ctx.terminalDeps[0] === true) {
|
|
691
|
-
if (ctx.store.has) {
|
|
692
|
-
a.emit(ctx.store.latest);
|
|
693
|
-
} else if (useDefault) {
|
|
694
|
-
a.emit(defaultValue);
|
|
695
|
-
}
|
|
696
|
-
a.down([[COMPLETE]]);
|
|
697
|
-
return;
|
|
698
|
-
}
|
|
699
|
-
const batch0 = data[0];
|
|
700
|
-
if (batch0 == null || batch0.length === 0) {
|
|
701
|
-
a.down([[RESOLVED]]);
|
|
702
|
-
return;
|
|
703
|
-
}
|
|
704
|
-
ctx.store.latest = batch0.at(-1);
|
|
705
|
-
ctx.store.has = true;
|
|
706
|
-
},
|
|
707
|
-
{
|
|
708
|
-
...operatorOpts(rest),
|
|
709
|
-
completeWhenDepsComplete: false
|
|
710
|
-
}
|
|
711
|
-
);
|
|
712
|
-
}
|
|
713
|
-
function find(source, predicate, opts) {
|
|
714
|
-
return take(filter(source, predicate, opts), 1, opts);
|
|
715
|
-
}
|
|
716
|
-
function elementAt(source, index, opts) {
|
|
717
|
-
return take(skip(source, index, opts), 1, opts);
|
|
718
|
-
}
|
|
719
|
-
function tap(source, fnOrObserver, opts) {
|
|
720
|
-
if (typeof fnOrObserver === "function") {
|
|
721
|
-
return node(
|
|
722
|
-
[source],
|
|
723
|
-
(data, a) => {
|
|
724
|
-
const batch0 = data[0];
|
|
725
|
-
if (batch0 == null || batch0.length === 0) {
|
|
726
|
-
a.down([[RESOLVED]]);
|
|
727
|
-
return;
|
|
728
|
-
}
|
|
729
|
-
for (const v of batch0) {
|
|
730
|
-
fnOrObserver(v);
|
|
731
|
-
a.emit(v);
|
|
732
|
-
}
|
|
733
|
-
},
|
|
734
|
-
operatorOpts(opts)
|
|
735
|
-
);
|
|
736
|
-
}
|
|
737
|
-
const obs = fnOrObserver;
|
|
738
|
-
return node(
|
|
739
|
-
[source],
|
|
740
|
-
(data, a, ctx) => {
|
|
741
|
-
if (ctx.terminalDeps[0] !== void 0) {
|
|
742
|
-
if (ctx.terminalDeps[0] === true) {
|
|
743
|
-
obs.complete?.();
|
|
744
|
-
a.down([[COMPLETE]]);
|
|
745
|
-
} else {
|
|
746
|
-
obs.error?.(ctx.terminalDeps[0]);
|
|
747
|
-
a.down([[ERROR, ctx.terminalDeps[0]]]);
|
|
748
|
-
}
|
|
749
|
-
return;
|
|
750
|
-
}
|
|
751
|
-
const batch0 = data[0];
|
|
752
|
-
if (batch0 == null || batch0.length === 0) {
|
|
753
|
-
a.down([[RESOLVED]]);
|
|
754
|
-
return;
|
|
755
|
-
}
|
|
756
|
-
for (const v of batch0) {
|
|
757
|
-
obs.data?.(v);
|
|
758
|
-
a.emit(v);
|
|
759
|
-
}
|
|
760
|
-
},
|
|
761
|
-
{
|
|
762
|
-
...operatorOpts(opts),
|
|
763
|
-
completeWhenDepsComplete: false
|
|
764
|
-
}
|
|
765
|
-
);
|
|
766
|
-
}
|
|
767
|
-
function distinctUntilChanged(source, equals = Object.is, opts) {
|
|
768
|
-
return node(
|
|
769
|
-
[source],
|
|
770
|
-
(data, a, ctx) => {
|
|
771
|
-
const batch0 = data[0];
|
|
772
|
-
if (batch0 == null || batch0.length === 0) {
|
|
773
|
-
a.down([[RESOLVED]]);
|
|
774
|
-
return;
|
|
775
|
-
}
|
|
776
|
-
let emitted = false;
|
|
777
|
-
for (const val of batch0) {
|
|
778
|
-
if (ctx.store.hasPrev && equals(ctx.store.prev, val)) {
|
|
779
|
-
} else {
|
|
780
|
-
ctx.store.prev = val;
|
|
781
|
-
ctx.store.hasPrev = true;
|
|
782
|
-
a.emit(val);
|
|
783
|
-
emitted = true;
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
if (!emitted) a.down([[RESOLVED]]);
|
|
787
|
-
},
|
|
788
|
-
operatorOpts(opts)
|
|
789
|
-
);
|
|
790
|
-
}
|
|
791
|
-
function pairwise(source, opts) {
|
|
792
|
-
return node(
|
|
793
|
-
[source],
|
|
794
|
-
(data, a, ctx) => {
|
|
795
|
-
const batch0 = data[0];
|
|
796
|
-
if (batch0 == null || batch0.length === 0) {
|
|
797
|
-
a.down([[RESOLVED]]);
|
|
798
|
-
return;
|
|
799
|
-
}
|
|
800
|
-
let emitted = false;
|
|
801
|
-
for (const x of batch0) {
|
|
802
|
-
if (!ctx.store.hasPrev) {
|
|
803
|
-
ctx.store.prev = x;
|
|
804
|
-
ctx.store.hasPrev = true;
|
|
805
|
-
} else {
|
|
806
|
-
const pair = [ctx.store.prev, x];
|
|
807
|
-
ctx.store.prev = x;
|
|
808
|
-
a.emit(pair);
|
|
809
|
-
emitted = true;
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
if (!emitted) a.down([[RESOLVED]]);
|
|
813
|
-
},
|
|
814
|
-
operatorOpts(opts)
|
|
815
|
-
);
|
|
816
|
-
}
|
|
817
|
-
function combine(...sources) {
|
|
818
|
-
const deps = [...sources];
|
|
819
|
-
return derived(deps, (vals) => vals, {
|
|
820
|
-
...operatorOpts(),
|
|
821
|
-
equals: (a, b) => {
|
|
822
|
-
if (a.length !== b.length) return false;
|
|
823
|
-
for (let i = 0; i < a.length; i++) {
|
|
824
|
-
if (!Object.is(a[i], b[i])) return false;
|
|
825
|
-
}
|
|
826
|
-
return true;
|
|
827
|
-
}
|
|
828
|
-
});
|
|
829
|
-
}
|
|
830
|
-
function withLatestFrom(primary, secondary, opts) {
|
|
831
|
-
return node(
|
|
832
|
-
[primary, secondary],
|
|
833
|
-
(data, a, ctx) => {
|
|
834
|
-
const batch0 = data[0];
|
|
835
|
-
const batch1 = data[1];
|
|
836
|
-
const secondaryVal = batch1 != null && batch1.length > 0 ? batch1.at(-1) : ctx.prevData[1];
|
|
837
|
-
if (batch0 != null && batch0.length > 0) {
|
|
838
|
-
if (!(batch1 != null && batch1.length > 0) && ctx.prevData[1] === void 0) {
|
|
839
|
-
a.down([[RESOLVED]]);
|
|
840
|
-
return;
|
|
841
|
-
}
|
|
842
|
-
for (const v of batch0) {
|
|
843
|
-
a.emit([v, secondaryVal]);
|
|
844
|
-
}
|
|
845
|
-
} else {
|
|
846
|
-
a.down([[RESOLVED]]);
|
|
847
|
-
}
|
|
848
|
-
},
|
|
849
|
-
operatorOpts(opts)
|
|
850
|
-
);
|
|
851
|
-
}
|
|
852
|
-
function merge(...sources) {
|
|
853
|
-
if (sources.length === 0) {
|
|
854
|
-
return producer((a) => {
|
|
855
|
-
a.down([[COMPLETE]]);
|
|
856
|
-
}, operatorOpts());
|
|
857
|
-
}
|
|
858
|
-
return producer((a) => {
|
|
859
|
-
const n = sources.length;
|
|
860
|
-
let completed = 0;
|
|
861
|
-
const unsubs = [];
|
|
862
|
-
for (const src of sources) {
|
|
863
|
-
const u = src.subscribe((msgs) => {
|
|
864
|
-
for (const m of msgs) {
|
|
865
|
-
if (m[0] === DATA) {
|
|
866
|
-
a.emit(m[1]);
|
|
867
|
-
} else if (m[0] === COMPLETE) {
|
|
868
|
-
completed += 1;
|
|
869
|
-
if (completed >= n) {
|
|
870
|
-
a.down([[COMPLETE]]);
|
|
871
|
-
}
|
|
872
|
-
} else if (m[0] === ERROR) {
|
|
873
|
-
a.down([m]);
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
});
|
|
877
|
-
unsubs.push(u);
|
|
878
|
-
}
|
|
879
|
-
return () => {
|
|
880
|
-
for (const u of unsubs) u();
|
|
881
|
-
};
|
|
882
|
-
}, operatorOpts());
|
|
883
|
-
}
|
|
884
|
-
function zip(...sources) {
|
|
885
|
-
const n = sources.length;
|
|
886
|
-
if (n === 0) {
|
|
887
|
-
return producer((a) => {
|
|
888
|
-
a.emit([]);
|
|
889
|
-
a.down([[COMPLETE]]);
|
|
890
|
-
}, operatorOpts());
|
|
891
|
-
}
|
|
892
|
-
return producer((a) => {
|
|
893
|
-
const queues = Array.from({ length: n }, () => []);
|
|
894
|
-
let active = n;
|
|
895
|
-
function tryEmit() {
|
|
896
|
-
while (queues.every((q) => q.length > 0)) {
|
|
897
|
-
const tuple = queues.map((q) => q.shift());
|
|
898
|
-
a.emit(tuple);
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
const unsubs = [];
|
|
902
|
-
for (let i = 0; i < n; i++) {
|
|
903
|
-
const idx = i;
|
|
904
|
-
const u = sources[i].subscribe((msgs) => {
|
|
905
|
-
for (const m of msgs) {
|
|
906
|
-
if (m[0] === DATA) {
|
|
907
|
-
queues[idx].push(m[1]);
|
|
908
|
-
tryEmit();
|
|
909
|
-
} else if (m[0] === COMPLETE) {
|
|
910
|
-
active -= 1;
|
|
911
|
-
if (active === 0 || queues[idx].length === 0) {
|
|
912
|
-
a.down([[COMPLETE]]);
|
|
913
|
-
}
|
|
914
|
-
} else if (m[0] === ERROR) {
|
|
915
|
-
a.down([m]);
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
});
|
|
919
|
-
unsubs.push(u);
|
|
920
|
-
}
|
|
921
|
-
return () => {
|
|
922
|
-
for (const u of unsubs) u();
|
|
923
|
-
};
|
|
924
|
-
}, operatorOpts());
|
|
925
|
-
}
|
|
926
|
-
function concat(firstSrc, secondSrc, opts) {
|
|
927
|
-
return producer((a) => {
|
|
928
|
-
let phase = 0;
|
|
929
|
-
const pending = [];
|
|
930
|
-
let firstUnsub;
|
|
931
|
-
let secondUnsub;
|
|
932
|
-
secondUnsub = secondSrc.subscribe((msgs) => {
|
|
933
|
-
for (const m of msgs) {
|
|
934
|
-
if (phase === 0) {
|
|
935
|
-
if (m[0] === DATA) pending.push(m[1]);
|
|
936
|
-
else if (m[0] === ERROR) a.down([m]);
|
|
937
|
-
} else {
|
|
938
|
-
if (m[0] === DATA) a.emit(m[1]);
|
|
939
|
-
else if (m[0] === COMPLETE || m[0] === ERROR) a.down([m]);
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
});
|
|
943
|
-
firstUnsub = firstSrc.subscribe((msgs) => {
|
|
944
|
-
for (const m of msgs) {
|
|
945
|
-
if (phase === 0) {
|
|
946
|
-
if (m[0] === DATA) {
|
|
947
|
-
a.emit(m[1]);
|
|
948
|
-
} else if (m[0] === COMPLETE) {
|
|
949
|
-
phase = 1;
|
|
950
|
-
for (const v of pending) {
|
|
951
|
-
a.emit(v);
|
|
952
|
-
}
|
|
953
|
-
pending.length = 0;
|
|
954
|
-
} else if (m[0] === ERROR) {
|
|
955
|
-
a.down([m]);
|
|
956
|
-
}
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
});
|
|
960
|
-
return () => {
|
|
961
|
-
firstUnsub?.();
|
|
962
|
-
secondUnsub?.();
|
|
963
|
-
};
|
|
964
|
-
}, operatorOpts(opts));
|
|
965
|
-
}
|
|
966
|
-
function race(...sources) {
|
|
967
|
-
if (sources.length === 0) {
|
|
968
|
-
return producer((a) => {
|
|
969
|
-
a.down([[COMPLETE]]);
|
|
970
|
-
}, operatorOpts());
|
|
971
|
-
}
|
|
972
|
-
if (sources.length === 1) {
|
|
973
|
-
return node(
|
|
974
|
-
[sources[0]],
|
|
975
|
-
(data, a) => {
|
|
976
|
-
const batch0 = data[0];
|
|
977
|
-
if (batch0 == null || batch0.length === 0) {
|
|
978
|
-
a.down([[RESOLVED]]);
|
|
979
|
-
return;
|
|
980
|
-
}
|
|
981
|
-
for (const v of batch0) a.emit(v);
|
|
982
|
-
},
|
|
983
|
-
operatorOpts()
|
|
984
|
-
);
|
|
985
|
-
}
|
|
986
|
-
return producer((a) => {
|
|
987
|
-
let winner = null;
|
|
988
|
-
const unsubs = [];
|
|
989
|
-
for (let i = 0; i < sources.length; i++) {
|
|
990
|
-
const idx = i;
|
|
991
|
-
const u = sources[i].subscribe((msgs) => {
|
|
992
|
-
for (const m of msgs) {
|
|
993
|
-
if (winner !== null && idx !== winner) return;
|
|
994
|
-
if (m[0] === DATA) {
|
|
995
|
-
if (winner === null) winner = idx;
|
|
996
|
-
a.emit(m[1]);
|
|
997
|
-
} else if (m[0] === COMPLETE || m[0] === ERROR) {
|
|
998
|
-
if (winner === null || idx === winner) {
|
|
999
|
-
a.down([m]);
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
});
|
|
1004
|
-
unsubs.push(u);
|
|
1005
|
-
}
|
|
1006
|
-
return () => {
|
|
1007
|
-
for (const u of unsubs) u();
|
|
1008
|
-
};
|
|
1009
|
-
}, operatorOpts());
|
|
1010
|
-
}
|
|
1011
|
-
function forwardInner(inner, a, onInnerComplete) {
|
|
1012
|
-
let unsub;
|
|
1013
|
-
let finished = false;
|
|
1014
|
-
const finish = () => {
|
|
1015
|
-
if (finished) return;
|
|
1016
|
-
finished = true;
|
|
1017
|
-
onInnerComplete();
|
|
1018
|
-
};
|
|
1019
|
-
unsub = inner.subscribe((msgs) => {
|
|
1020
|
-
let sawComplete = false;
|
|
1021
|
-
let sawError = false;
|
|
1022
|
-
for (const m of msgs) {
|
|
1023
|
-
if (m[0] === START) continue;
|
|
1024
|
-
if (m[0] === DATA) {
|
|
1025
|
-
a.emit(m[1]);
|
|
1026
|
-
} else if (m[0] === COMPLETE) {
|
|
1027
|
-
sawComplete = true;
|
|
1028
|
-
} else if (m[0] === ERROR) {
|
|
1029
|
-
sawError = true;
|
|
1030
|
-
a.down([m]);
|
|
1031
|
-
} else if (m[0] === DIRTY || m[0] === RESOLVED) {
|
|
1032
|
-
a.down([m]);
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1035
|
-
if (sawError) {
|
|
1036
|
-
unsub?.();
|
|
1037
|
-
unsub = void 0;
|
|
1038
|
-
finish();
|
|
1039
|
-
} else if (sawComplete) {
|
|
1040
|
-
finish();
|
|
1041
|
-
}
|
|
1042
|
-
});
|
|
1043
|
-
return () => {
|
|
1044
|
-
unsub?.();
|
|
1045
|
-
unsub = void 0;
|
|
1046
|
-
};
|
|
1047
|
-
}
|
|
1048
|
-
function switchMap(source, project, opts) {
|
|
1049
|
-
let innerUnsub;
|
|
1050
|
-
let sourceDone = false;
|
|
1051
|
-
function clearInner() {
|
|
1052
|
-
innerUnsub?.();
|
|
1053
|
-
innerUnsub = void 0;
|
|
1054
|
-
}
|
|
1055
|
-
return node(
|
|
1056
|
-
[source],
|
|
1057
|
-
(data, a, ctx) => {
|
|
1058
|
-
if (ctx.terminalDeps[0] != null && ctx.terminalDeps[0] !== true) {
|
|
1059
|
-
clearInner();
|
|
1060
|
-
return;
|
|
1061
|
-
}
|
|
1062
|
-
if (ctx.terminalDeps[0] === true) {
|
|
1063
|
-
sourceDone = true;
|
|
1064
|
-
if (!innerUnsub) a.down([[COMPLETE]]);
|
|
1065
|
-
return;
|
|
1066
|
-
}
|
|
1067
|
-
const batch0 = data[0];
|
|
1068
|
-
if (batch0 == null || batch0.length === 0) return;
|
|
1069
|
-
clearInner();
|
|
1070
|
-
innerUnsub = forwardInner(fromAny(project(batch0[batch0.length - 1])), a, () => {
|
|
1071
|
-
clearInner();
|
|
1072
|
-
if (sourceDone) a.down([[COMPLETE]]);
|
|
1073
|
-
});
|
|
1074
|
-
return {
|
|
1075
|
-
deactivation: () => {
|
|
1076
|
-
clearInner();
|
|
1077
|
-
sourceDone = false;
|
|
1078
|
-
}
|
|
1079
|
-
};
|
|
1080
|
-
},
|
|
1081
|
-
{ ...operatorOpts(opts), completeWhenDepsComplete: false }
|
|
1082
|
-
);
|
|
1083
|
-
}
|
|
1084
|
-
function exhaustMap(source, project, opts) {
|
|
1085
|
-
let innerUnsub;
|
|
1086
|
-
let sourceDone = false;
|
|
1087
|
-
function clearInner() {
|
|
1088
|
-
innerUnsub?.();
|
|
1089
|
-
innerUnsub = void 0;
|
|
1090
|
-
}
|
|
1091
|
-
return node(
|
|
1092
|
-
[source],
|
|
1093
|
-
(data, a, ctx) => {
|
|
1094
|
-
if (ctx.terminalDeps[0] != null && ctx.terminalDeps[0] !== true) {
|
|
1095
|
-
clearInner();
|
|
1096
|
-
return;
|
|
1097
|
-
}
|
|
1098
|
-
if (ctx.terminalDeps[0] === true) {
|
|
1099
|
-
sourceDone = true;
|
|
1100
|
-
if (!innerUnsub) a.down([[COMPLETE]]);
|
|
1101
|
-
return;
|
|
1102
|
-
}
|
|
1103
|
-
const batch0 = data[0];
|
|
1104
|
-
if (batch0 == null || batch0.length === 0) return;
|
|
1105
|
-
if (innerUnsub === void 0) {
|
|
1106
|
-
innerUnsub = forwardInner(fromAny(project(batch0[0])), a, () => {
|
|
1107
|
-
clearInner();
|
|
1108
|
-
if (sourceDone) a.down([[COMPLETE]]);
|
|
1109
|
-
});
|
|
1110
|
-
} else {
|
|
1111
|
-
a.down([[RESOLVED]]);
|
|
1112
|
-
}
|
|
1113
|
-
return {
|
|
1114
|
-
deactivation: () => {
|
|
1115
|
-
clearInner();
|
|
1116
|
-
sourceDone = false;
|
|
1117
|
-
}
|
|
1118
|
-
};
|
|
1119
|
-
},
|
|
1120
|
-
{ ...operatorOpts(opts), completeWhenDepsComplete: false }
|
|
1121
|
-
);
|
|
1122
|
-
}
|
|
1123
|
-
function concatMap(source, project, opts) {
|
|
1124
|
-
const { maxBuffer: maxBuf, ...concatNodeOpts } = opts ?? {};
|
|
1125
|
-
const queue = [];
|
|
1126
|
-
let innerUnsub;
|
|
1127
|
-
let sourceDone = false;
|
|
1128
|
-
let actions;
|
|
1129
|
-
function clearInner() {
|
|
1130
|
-
innerUnsub?.();
|
|
1131
|
-
innerUnsub = void 0;
|
|
1132
|
-
}
|
|
1133
|
-
function tryPump() {
|
|
1134
|
-
if (!actions || innerUnsub !== void 0) return;
|
|
1135
|
-
if (queue.length === 0) {
|
|
1136
|
-
if (sourceDone) actions.down([[COMPLETE]]);
|
|
1137
|
-
return;
|
|
1138
|
-
}
|
|
1139
|
-
const v = queue.shift();
|
|
1140
|
-
innerUnsub = forwardInner(fromAny(project(v)), actions, () => {
|
|
1141
|
-
clearInner();
|
|
1142
|
-
tryPump();
|
|
1143
|
-
});
|
|
1144
|
-
}
|
|
1145
|
-
function enqueue(v) {
|
|
1146
|
-
if (maxBuf && maxBuf > 0 && queue.length >= maxBuf) queue.shift();
|
|
1147
|
-
queue.push(v);
|
|
1148
|
-
tryPump();
|
|
1149
|
-
}
|
|
1150
|
-
return node(
|
|
1151
|
-
[source],
|
|
1152
|
-
(data, a, ctx) => {
|
|
1153
|
-
actions = a;
|
|
1154
|
-
if (ctx.terminalDeps[0] != null && ctx.terminalDeps[0] !== true) {
|
|
1155
|
-
clearInner();
|
|
1156
|
-
queue.length = 0;
|
|
1157
|
-
return;
|
|
1158
|
-
}
|
|
1159
|
-
if (ctx.terminalDeps[0] === true) {
|
|
1160
|
-
sourceDone = true;
|
|
1161
|
-
tryPump();
|
|
1162
|
-
return;
|
|
1163
|
-
}
|
|
1164
|
-
const batch0 = data[0];
|
|
1165
|
-
if (batch0 == null || batch0.length === 0) return;
|
|
1166
|
-
for (const v of batch0) {
|
|
1167
|
-
enqueue(v);
|
|
1168
|
-
}
|
|
1169
|
-
return {
|
|
1170
|
-
deactivation: () => {
|
|
1171
|
-
clearInner();
|
|
1172
|
-
queue.length = 0;
|
|
1173
|
-
sourceDone = false;
|
|
1174
|
-
}
|
|
1175
|
-
};
|
|
1176
|
-
},
|
|
1177
|
-
{ ...operatorOpts(concatNodeOpts), completeWhenDepsComplete: false }
|
|
1178
|
-
);
|
|
1179
|
-
}
|
|
1180
|
-
function mergeMap(source, project, opts) {
|
|
1181
|
-
const { concurrent: concurrentOpt, ...mergeNodeOpts } = opts ?? {};
|
|
1182
|
-
const maxConcurrent = concurrentOpt != null && concurrentOpt > 0 ? concurrentOpt : Number.POSITIVE_INFINITY;
|
|
1183
|
-
let active = 0;
|
|
1184
|
-
let sourceDone = false;
|
|
1185
|
-
const innerStops = /* @__PURE__ */ new Set();
|
|
1186
|
-
const buffer2 = [];
|
|
1187
|
-
let actions;
|
|
1188
|
-
function tryComplete() {
|
|
1189
|
-
if (sourceDone && active === 0 && buffer2.length === 0 && actions) {
|
|
1190
|
-
actions.down([[COMPLETE]]);
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
function spawn(v) {
|
|
1194
|
-
if (!actions) return;
|
|
1195
|
-
active++;
|
|
1196
|
-
let stop;
|
|
1197
|
-
stop = forwardInner(fromAny(project(v)), actions, () => {
|
|
1198
|
-
if (stop) innerStops.delete(stop);
|
|
1199
|
-
active--;
|
|
1200
|
-
drainBuffer();
|
|
1201
|
-
tryComplete();
|
|
1202
|
-
});
|
|
1203
|
-
innerStops.add(stop);
|
|
1204
|
-
}
|
|
1205
|
-
function drainBuffer() {
|
|
1206
|
-
while (buffer2.length > 0 && active < maxConcurrent) {
|
|
1207
|
-
spawn(buffer2.shift());
|
|
1208
|
-
}
|
|
1209
|
-
}
|
|
1210
|
-
function enqueue(v) {
|
|
1211
|
-
if (active < maxConcurrent) spawn(v);
|
|
1212
|
-
else buffer2.push(v);
|
|
1213
|
-
}
|
|
1214
|
-
function clearAll() {
|
|
1215
|
-
for (const u of innerStops) u();
|
|
1216
|
-
innerStops.clear();
|
|
1217
|
-
active = 0;
|
|
1218
|
-
buffer2.length = 0;
|
|
1219
|
-
}
|
|
1220
|
-
return node(
|
|
1221
|
-
[source],
|
|
1222
|
-
(data, a, ctx) => {
|
|
1223
|
-
actions = a;
|
|
1224
|
-
if (ctx.terminalDeps[0] != null && ctx.terminalDeps[0] !== true) {
|
|
1225
|
-
clearAll();
|
|
1226
|
-
return;
|
|
1227
|
-
}
|
|
1228
|
-
if (ctx.terminalDeps[0] === true) {
|
|
1229
|
-
sourceDone = true;
|
|
1230
|
-
tryComplete();
|
|
1231
|
-
return;
|
|
1232
|
-
}
|
|
1233
|
-
const batch0 = data[0];
|
|
1234
|
-
if (batch0 == null || batch0.length === 0) return;
|
|
1235
|
-
for (const v of batch0) {
|
|
1236
|
-
enqueue(v);
|
|
1237
|
-
}
|
|
1238
|
-
return {
|
|
1239
|
-
deactivation: () => {
|
|
1240
|
-
clearAll();
|
|
1241
|
-
sourceDone = false;
|
|
1242
|
-
}
|
|
1243
|
-
};
|
|
1244
|
-
},
|
|
1245
|
-
{ ...operatorOpts(mergeNodeOpts), completeWhenDepsComplete: false }
|
|
1246
|
-
);
|
|
1247
|
-
}
|
|
1248
|
-
var flatMap = mergeMap;
|
|
1249
|
-
function delay(source, ms, opts) {
|
|
1250
|
-
return producer((a) => {
|
|
1251
|
-
const timers = /* @__PURE__ */ new Set();
|
|
1252
|
-
function clearAll() {
|
|
1253
|
-
for (const id of timers) clearTimeout(id);
|
|
1254
|
-
timers.clear();
|
|
1255
|
-
}
|
|
1256
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1257
|
-
for (const m of msgs) {
|
|
1258
|
-
if (m[0] === DATA) {
|
|
1259
|
-
const id = setTimeout(() => {
|
|
1260
|
-
timers.delete(id);
|
|
1261
|
-
a.emit(m[1]);
|
|
1262
|
-
}, ms);
|
|
1263
|
-
timers.add(id);
|
|
1264
|
-
} else if (m[0] === COMPLETE) {
|
|
1265
|
-
const id = setTimeout(() => {
|
|
1266
|
-
timers.delete(id);
|
|
1267
|
-
a.down([[COMPLETE]]);
|
|
1268
|
-
}, ms);
|
|
1269
|
-
timers.add(id);
|
|
1270
|
-
} else if (m[0] === ERROR) {
|
|
1271
|
-
clearAll();
|
|
1272
|
-
a.down([m]);
|
|
1273
|
-
}
|
|
1274
|
-
}
|
|
1275
|
-
});
|
|
1276
|
-
return () => {
|
|
1277
|
-
srcUnsub();
|
|
1278
|
-
clearAll();
|
|
1279
|
-
};
|
|
1280
|
-
}, operatorOpts(opts));
|
|
1281
|
-
}
|
|
1282
|
-
function debounce(source, ms, opts) {
|
|
1283
|
-
return producer((a) => {
|
|
1284
|
-
let timer;
|
|
1285
|
-
let pending;
|
|
1286
|
-
function clearTimer() {
|
|
1287
|
-
if (timer !== void 0) {
|
|
1288
|
-
clearTimeout(timer);
|
|
1289
|
-
timer = void 0;
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1293
|
-
for (const m of msgs) {
|
|
1294
|
-
if (m[0] === DATA) {
|
|
1295
|
-
clearTimer();
|
|
1296
|
-
pending = m[1];
|
|
1297
|
-
timer = setTimeout(() => {
|
|
1298
|
-
timer = void 0;
|
|
1299
|
-
a.emit(pending);
|
|
1300
|
-
}, ms);
|
|
1301
|
-
} else if (m[0] === COMPLETE) {
|
|
1302
|
-
if (timer !== void 0) {
|
|
1303
|
-
clearTimer();
|
|
1304
|
-
a.emit(pending);
|
|
1305
|
-
}
|
|
1306
|
-
a.down([[COMPLETE]]);
|
|
1307
|
-
} else if (m[0] === ERROR) {
|
|
1308
|
-
clearTimer();
|
|
1309
|
-
a.down([m]);
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
});
|
|
1313
|
-
return () => {
|
|
1314
|
-
srcUnsub();
|
|
1315
|
-
clearTimer();
|
|
1316
|
-
};
|
|
1317
|
-
}, operatorOpts(opts));
|
|
1318
|
-
}
|
|
1319
|
-
function throttle(source, ms, opts) {
|
|
1320
|
-
const { leading: leadingOpt, trailing: trailingOpt, ...throttleNodeOpts } = opts ?? {};
|
|
1321
|
-
const leading = leadingOpt !== false;
|
|
1322
|
-
const trailing = trailingOpt === true;
|
|
1323
|
-
const windowNs = ms * NS_PER_MS;
|
|
1324
|
-
return producer((a) => {
|
|
1325
|
-
let timer;
|
|
1326
|
-
let lastEmitNs = -Infinity;
|
|
1327
|
-
let pending;
|
|
1328
|
-
let hasPending = false;
|
|
1329
|
-
function clearTimer() {
|
|
1330
|
-
if (timer !== void 0) {
|
|
1331
|
-
clearTimeout(timer);
|
|
1332
|
-
timer = void 0;
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1336
|
-
for (const m of msgs) {
|
|
1337
|
-
if (m[0] === DATA) {
|
|
1338
|
-
const v = m[1];
|
|
1339
|
-
const nowNs = monotonicNs();
|
|
1340
|
-
if (leading && nowNs - lastEmitNs >= windowNs) {
|
|
1341
|
-
lastEmitNs = nowNs;
|
|
1342
|
-
a.emit(v);
|
|
1343
|
-
clearTimer();
|
|
1344
|
-
if (trailing) {
|
|
1345
|
-
timer = setTimeout(() => {
|
|
1346
|
-
timer = void 0;
|
|
1347
|
-
if (hasPending) {
|
|
1348
|
-
lastEmitNs = monotonicNs();
|
|
1349
|
-
a.emit(pending);
|
|
1350
|
-
hasPending = false;
|
|
1351
|
-
}
|
|
1352
|
-
}, ms);
|
|
1353
|
-
}
|
|
1354
|
-
} else if (trailing) {
|
|
1355
|
-
pending = v;
|
|
1356
|
-
hasPending = true;
|
|
1357
|
-
if (timer === void 0) {
|
|
1358
|
-
const elapsedMs = (nowNs - lastEmitNs) / NS_PER_MS;
|
|
1359
|
-
timer = setTimeout(
|
|
1360
|
-
() => {
|
|
1361
|
-
timer = void 0;
|
|
1362
|
-
if (hasPending) {
|
|
1363
|
-
lastEmitNs = monotonicNs();
|
|
1364
|
-
a.emit(pending);
|
|
1365
|
-
hasPending = false;
|
|
1366
|
-
}
|
|
1367
|
-
},
|
|
1368
|
-
Math.max(0, ms - elapsedMs)
|
|
1369
|
-
);
|
|
1370
|
-
}
|
|
1371
|
-
}
|
|
1372
|
-
} else if (m[0] === COMPLETE || m[0] === ERROR) {
|
|
1373
|
-
clearTimer();
|
|
1374
|
-
a.down([m]);
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
});
|
|
1378
|
-
return () => {
|
|
1379
|
-
srcUnsub();
|
|
1380
|
-
clearTimer();
|
|
1381
|
-
};
|
|
1382
|
-
}, operatorOpts(throttleNodeOpts));
|
|
1383
|
-
}
|
|
1384
|
-
function sample(source, notifier, opts) {
|
|
1385
|
-
return producer((a) => {
|
|
1386
|
-
let lastSourceValue;
|
|
1387
|
-
let terminated = false;
|
|
1388
|
-
let sourceCompleted = false;
|
|
1389
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1390
|
-
if (terminated) return;
|
|
1391
|
-
for (const m of msgs) {
|
|
1392
|
-
if (terminated) return;
|
|
1393
|
-
if (m[0] === DATA) {
|
|
1394
|
-
lastSourceValue = { v: m[1] };
|
|
1395
|
-
} else if (m[0] === ERROR) {
|
|
1396
|
-
terminated = true;
|
|
1397
|
-
a.down([m]);
|
|
1398
|
-
} else if (m[0] === COMPLETE) {
|
|
1399
|
-
sourceCompleted = true;
|
|
1400
|
-
lastSourceValue = void 0;
|
|
1401
|
-
}
|
|
1402
|
-
}
|
|
1403
|
-
});
|
|
1404
|
-
const notUnsub = notifier.subscribe((msgs) => {
|
|
1405
|
-
if (terminated) return;
|
|
1406
|
-
for (const m of msgs) {
|
|
1407
|
-
if (terminated) return;
|
|
1408
|
-
if (m[0] === DATA) {
|
|
1409
|
-
if (lastSourceValue !== void 0 && !sourceCompleted) {
|
|
1410
|
-
a.emit(lastSourceValue.v);
|
|
1411
|
-
}
|
|
1412
|
-
} else if (m[0] === ERROR) {
|
|
1413
|
-
terminated = true;
|
|
1414
|
-
a.down([m]);
|
|
1415
|
-
} else if (m[0] === COMPLETE) {
|
|
1416
|
-
terminated = true;
|
|
1417
|
-
a.down([[COMPLETE]]);
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
});
|
|
1421
|
-
return () => {
|
|
1422
|
-
srcUnsub();
|
|
1423
|
-
notUnsub();
|
|
1424
|
-
};
|
|
1425
|
-
}, operatorOpts(opts));
|
|
1426
|
-
}
|
|
1427
|
-
function audit(source, ms, opts) {
|
|
1428
|
-
return producer((a) => {
|
|
1429
|
-
let timer;
|
|
1430
|
-
let latest;
|
|
1431
|
-
let has = false;
|
|
1432
|
-
function clearTimer() {
|
|
1433
|
-
if (timer !== void 0) {
|
|
1434
|
-
clearTimeout(timer);
|
|
1435
|
-
timer = void 0;
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1438
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1439
|
-
for (const m of msgs) {
|
|
1440
|
-
if (m[0] === DATA) {
|
|
1441
|
-
latest = m[1];
|
|
1442
|
-
has = true;
|
|
1443
|
-
clearTimer();
|
|
1444
|
-
timer = setTimeout(() => {
|
|
1445
|
-
timer = void 0;
|
|
1446
|
-
if (has) {
|
|
1447
|
-
has = false;
|
|
1448
|
-
a.emit(latest);
|
|
1449
|
-
}
|
|
1450
|
-
}, ms);
|
|
1451
|
-
} else if (m[0] === COMPLETE || m[0] === ERROR) {
|
|
1452
|
-
clearTimer();
|
|
1453
|
-
a.down([m]);
|
|
1454
|
-
}
|
|
1455
|
-
}
|
|
1456
|
-
});
|
|
1457
|
-
return () => {
|
|
1458
|
-
srcUnsub();
|
|
1459
|
-
clearTimer();
|
|
1460
|
-
};
|
|
1461
|
-
}, operatorOpts(opts));
|
|
1462
|
-
}
|
|
1463
|
-
function buffer(source, notifier, opts) {
|
|
1464
|
-
return producer((a) => {
|
|
1465
|
-
const buf = [];
|
|
1466
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1467
|
-
for (const m of msgs) {
|
|
1468
|
-
if (m[0] === DATA) {
|
|
1469
|
-
buf.push(m[1]);
|
|
1470
|
-
} else if (m[0] === COMPLETE) {
|
|
1471
|
-
if (buf.length > 0) a.emit([...buf]);
|
|
1472
|
-
buf.length = 0;
|
|
1473
|
-
a.down([[COMPLETE]]);
|
|
1474
|
-
} else if (m[0] === ERROR) {
|
|
1475
|
-
a.down([m]);
|
|
1476
|
-
}
|
|
1477
|
-
}
|
|
1478
|
-
});
|
|
1479
|
-
const notUnsub = notifier.subscribe((msgs) => {
|
|
1480
|
-
for (const m of msgs) {
|
|
1481
|
-
if (m[0] === DATA) {
|
|
1482
|
-
if (buf.length > 0) {
|
|
1483
|
-
a.emit([...buf]);
|
|
1484
|
-
buf.length = 0;
|
|
1485
|
-
}
|
|
1486
|
-
} else if (m[0] === COMPLETE) {
|
|
1487
|
-
a.down([[COMPLETE]]);
|
|
1488
|
-
} else if (m[0] === ERROR) {
|
|
1489
|
-
a.down([m]);
|
|
1490
|
-
}
|
|
1491
|
-
}
|
|
1492
|
-
});
|
|
1493
|
-
return () => {
|
|
1494
|
-
srcUnsub();
|
|
1495
|
-
notUnsub();
|
|
1496
|
-
buf.length = 0;
|
|
1497
|
-
};
|
|
1498
|
-
}, operatorOpts(opts));
|
|
1499
|
-
}
|
|
1500
|
-
function bufferCount(source, count, opts) {
|
|
1501
|
-
if (count <= 0) throw new RangeError("bufferCount expects count > 0");
|
|
1502
|
-
return producer((a) => {
|
|
1503
|
-
const buf = [];
|
|
1504
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1505
|
-
for (const m of msgs) {
|
|
1506
|
-
if (m[0] === DATA) {
|
|
1507
|
-
buf.push(m[1]);
|
|
1508
|
-
if (buf.length >= count) {
|
|
1509
|
-
a.emit(buf.splice(0, buf.length));
|
|
1510
|
-
}
|
|
1511
|
-
} else if (m[0] === COMPLETE) {
|
|
1512
|
-
if (buf.length > 0) a.emit([...buf]);
|
|
1513
|
-
buf.length = 0;
|
|
1514
|
-
a.down([[COMPLETE]]);
|
|
1515
|
-
} else if (m[0] === ERROR) {
|
|
1516
|
-
a.down([m]);
|
|
1517
|
-
}
|
|
1518
|
-
}
|
|
1519
|
-
});
|
|
1520
|
-
return () => {
|
|
1521
|
-
srcUnsub();
|
|
1522
|
-
buf.length = 0;
|
|
1523
|
-
};
|
|
1524
|
-
}, operatorOpts(opts));
|
|
1525
|
-
}
|
|
1526
|
-
function windowCount(source, count, opts) {
|
|
1527
|
-
if (count <= 0) throw new RangeError("windowCount expects count > 0");
|
|
1528
|
-
return producer((a) => {
|
|
1529
|
-
let winDown;
|
|
1530
|
-
let n = 0;
|
|
1531
|
-
function openWindow() {
|
|
1532
|
-
const s = producer((actions) => {
|
|
1533
|
-
winDown = actions.down.bind(actions);
|
|
1534
|
-
return () => {
|
|
1535
|
-
winDown = void 0;
|
|
1536
|
-
};
|
|
1537
|
-
}, operatorOpts());
|
|
1538
|
-
n = 0;
|
|
1539
|
-
a.emit(s);
|
|
1540
|
-
}
|
|
1541
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1542
|
-
for (const m of msgs) {
|
|
1543
|
-
if (m[0] === DATA) {
|
|
1544
|
-
if (!winDown) openWindow();
|
|
1545
|
-
winDown?.([[DATA, m[1]]]);
|
|
1546
|
-
n += 1;
|
|
1547
|
-
if (n >= count) {
|
|
1548
|
-
winDown?.([[COMPLETE]]);
|
|
1549
|
-
winDown = void 0;
|
|
1550
|
-
}
|
|
1551
|
-
} else if (m[0] === COMPLETE) {
|
|
1552
|
-
winDown?.([[COMPLETE]]);
|
|
1553
|
-
winDown = void 0;
|
|
1554
|
-
a.down([[COMPLETE]]);
|
|
1555
|
-
} else if (m[0] === ERROR) {
|
|
1556
|
-
winDown?.([m]);
|
|
1557
|
-
winDown = void 0;
|
|
1558
|
-
a.down([m]);
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1561
|
-
});
|
|
1562
|
-
return () => {
|
|
1563
|
-
srcUnsub();
|
|
1564
|
-
winDown?.([[COMPLETE]]);
|
|
1565
|
-
winDown = void 0;
|
|
1566
|
-
};
|
|
1567
|
-
}, operatorOpts(opts));
|
|
1568
|
-
}
|
|
1569
|
-
function bufferTime(source, ms, opts) {
|
|
1570
|
-
return producer((a) => {
|
|
1571
|
-
const buf = [];
|
|
1572
|
-
const iv = setInterval(() => {
|
|
1573
|
-
if (buf.length > 0) {
|
|
1574
|
-
a.emit([...buf]);
|
|
1575
|
-
buf.length = 0;
|
|
1576
|
-
}
|
|
1577
|
-
}, ms);
|
|
1578
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1579
|
-
for (const m of msgs) {
|
|
1580
|
-
if (m[0] === DATA) {
|
|
1581
|
-
buf.push(m[1]);
|
|
1582
|
-
} else if (m[0] === COMPLETE) {
|
|
1583
|
-
clearInterval(iv);
|
|
1584
|
-
if (buf.length > 0) a.emit([...buf]);
|
|
1585
|
-
buf.length = 0;
|
|
1586
|
-
a.down([[COMPLETE]]);
|
|
1587
|
-
} else if (m[0] === ERROR) {
|
|
1588
|
-
clearInterval(iv);
|
|
1589
|
-
a.down([m]);
|
|
1590
|
-
}
|
|
1591
|
-
}
|
|
1592
|
-
});
|
|
1593
|
-
return () => {
|
|
1594
|
-
srcUnsub();
|
|
1595
|
-
clearInterval(iv);
|
|
1596
|
-
buf.length = 0;
|
|
1597
|
-
};
|
|
1598
|
-
}, operatorOpts(opts));
|
|
1599
|
-
}
|
|
1600
|
-
function windowTime(source, ms, opts) {
|
|
1601
|
-
return producer((a) => {
|
|
1602
|
-
let winDown;
|
|
1603
|
-
function closeWindow() {
|
|
1604
|
-
winDown?.([[COMPLETE]]);
|
|
1605
|
-
winDown = void 0;
|
|
1606
|
-
}
|
|
1607
|
-
function openWindow() {
|
|
1608
|
-
const s = producer((actions) => {
|
|
1609
|
-
winDown = actions.down.bind(actions);
|
|
1610
|
-
return () => {
|
|
1611
|
-
winDown = void 0;
|
|
1612
|
-
};
|
|
1613
|
-
}, operatorOpts());
|
|
1614
|
-
a.emit(s);
|
|
1615
|
-
}
|
|
1616
|
-
openWindow();
|
|
1617
|
-
const iv = setInterval(() => {
|
|
1618
|
-
closeWindow();
|
|
1619
|
-
openWindow();
|
|
1620
|
-
}, ms);
|
|
1621
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1622
|
-
for (const m of msgs) {
|
|
1623
|
-
if (m[0] === DATA) {
|
|
1624
|
-
winDown?.([[DATA, m[1]]]);
|
|
1625
|
-
} else if (m[0] === COMPLETE) {
|
|
1626
|
-
clearInterval(iv);
|
|
1627
|
-
closeWindow();
|
|
1628
|
-
a.down([[COMPLETE]]);
|
|
1629
|
-
} else if (m[0] === ERROR) {
|
|
1630
|
-
clearInterval(iv);
|
|
1631
|
-
winDown?.([m]);
|
|
1632
|
-
closeWindow();
|
|
1633
|
-
a.down([m]);
|
|
1634
|
-
}
|
|
1635
|
-
}
|
|
1636
|
-
});
|
|
1637
|
-
return () => {
|
|
1638
|
-
srcUnsub();
|
|
1639
|
-
clearInterval(iv);
|
|
1640
|
-
closeWindow();
|
|
1641
|
-
};
|
|
1642
|
-
}, operatorOpts(opts));
|
|
1643
|
-
}
|
|
1644
|
-
function window(source, notifier, opts) {
|
|
1645
|
-
return producer((a) => {
|
|
1646
|
-
let winDown;
|
|
1647
|
-
function closeWindow() {
|
|
1648
|
-
winDown?.([[COMPLETE]]);
|
|
1649
|
-
winDown = void 0;
|
|
1650
|
-
}
|
|
1651
|
-
function openWindow() {
|
|
1652
|
-
const s = producer((actions) => {
|
|
1653
|
-
winDown = actions.down.bind(actions);
|
|
1654
|
-
return () => {
|
|
1655
|
-
winDown = void 0;
|
|
1656
|
-
};
|
|
1657
|
-
}, operatorOpts());
|
|
1658
|
-
a.emit(s);
|
|
1659
|
-
}
|
|
1660
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1661
|
-
for (const m of msgs) {
|
|
1662
|
-
if (m[0] === DATA) {
|
|
1663
|
-
if (!winDown) openWindow();
|
|
1664
|
-
winDown?.([[DATA, m[1]]]);
|
|
1665
|
-
} else if (m[0] === COMPLETE) {
|
|
1666
|
-
closeWindow();
|
|
1667
|
-
a.down([[COMPLETE]]);
|
|
1668
|
-
} else if (m[0] === ERROR) {
|
|
1669
|
-
winDown?.([m]);
|
|
1670
|
-
winDown = void 0;
|
|
1671
|
-
a.down([m]);
|
|
1672
|
-
}
|
|
1673
|
-
}
|
|
1674
|
-
});
|
|
1675
|
-
const notUnsub = notifier.subscribe((msgs) => {
|
|
1676
|
-
for (const m of msgs) {
|
|
1677
|
-
if (m[0] === DATA) {
|
|
1678
|
-
closeWindow();
|
|
1679
|
-
openWindow();
|
|
1680
|
-
}
|
|
1681
|
-
}
|
|
411
|
+
batch(() => {
|
|
412
|
+
for (const n of channelNodes) n.down([[COMPLETE]]);
|
|
1682
413
|
});
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
ctx.store.n = ctx.store.n + 1;
|
|
1696
|
-
}, periodMs);
|
|
1697
|
-
return () => clearInterval(id);
|
|
1698
|
-
}, operatorOpts(opts));
|
|
1699
|
-
}
|
|
1700
|
-
function repeat(source, count, opts) {
|
|
1701
|
-
if (count <= 0) throw new RangeError("repeat expects count > 0");
|
|
1702
|
-
return producer((a) => {
|
|
1703
|
-
let remaining = count;
|
|
1704
|
-
let innerU;
|
|
1705
|
-
const start = () => {
|
|
1706
|
-
innerU?.();
|
|
1707
|
-
innerU = source.subscribe((msgs) => {
|
|
1708
|
-
let completed = false;
|
|
1709
|
-
const fwd = [];
|
|
1710
|
-
for (const m of msgs) {
|
|
1711
|
-
if (m[0] === COMPLETE) completed = true;
|
|
1712
|
-
else fwd.push(m);
|
|
1713
|
-
}
|
|
1714
|
-
if (fwd.length > 0) a.down(fwd);
|
|
1715
|
-
if (completed) {
|
|
1716
|
-
innerU?.();
|
|
1717
|
-
innerU = void 0;
|
|
1718
|
-
remaining -= 1;
|
|
1719
|
-
if (remaining > 0) start();
|
|
1720
|
-
else a.down([[COMPLETE]]);
|
|
1721
|
-
}
|
|
1722
|
-
});
|
|
1723
|
-
};
|
|
1724
|
-
start();
|
|
1725
|
-
return () => {
|
|
1726
|
-
innerU?.();
|
|
1727
|
-
};
|
|
1728
|
-
}, operatorOpts(opts));
|
|
1729
|
-
}
|
|
1730
|
-
function pausable(source, opts) {
|
|
1731
|
-
return node(
|
|
1732
|
-
[source],
|
|
1733
|
-
(data, a) => {
|
|
1734
|
-
const batch0 = data[0];
|
|
1735
|
-
if (batch0 == null || batch0.length === 0) {
|
|
1736
|
-
a.down([[RESOLVED]]);
|
|
1737
|
-
return;
|
|
1738
|
-
}
|
|
1739
|
-
for (const v of batch0) a.emit(v);
|
|
1740
|
-
},
|
|
1741
|
-
operatorOpts(opts)
|
|
1742
|
-
);
|
|
1743
|
-
}
|
|
1744
|
-
function rescue(source, recover, opts) {
|
|
1745
|
-
return producer((a) => {
|
|
1746
|
-
const srcUnsub = source.subscribe((msgs) => {
|
|
1747
|
-
for (const m of msgs) {
|
|
1748
|
-
if (m[0] === DATA) {
|
|
1749
|
-
a.emit(m[1]);
|
|
1750
|
-
} else if (m[0] === ERROR) {
|
|
1751
|
-
try {
|
|
1752
|
-
a.emit(recover(m[1]));
|
|
1753
|
-
} catch (recoverErr) {
|
|
1754
|
-
a.down([[ERROR, recoverErr]]);
|
|
1755
|
-
}
|
|
1756
|
-
} else if (m[0] === COMPLETE) {
|
|
1757
|
-
a.down([[COMPLETE]]);
|
|
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 {
|
|
1758
426
|
}
|
|
1759
427
|
}
|
|
1760
428
|
});
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
}, operatorOpts(opts));
|
|
1765
|
-
}
|
|
1766
|
-
function valve(source, control, opts) {
|
|
1767
|
-
return node(
|
|
1768
|
-
[source, control],
|
|
1769
|
-
(data, a, ctx) => {
|
|
1770
|
-
const batch1 = data[1];
|
|
1771
|
-
const controlValue = batch1 != null && batch1.length > 0 ? batch1.at(-1) : ctx.prevData[1];
|
|
1772
|
-
if (!controlValue) {
|
|
1773
|
-
a.down([[RESOLVED]]);
|
|
1774
|
-
return;
|
|
1775
|
-
}
|
|
1776
|
-
const batch0 = data[0];
|
|
1777
|
-
if (batch0 != null && batch0.length > 0) {
|
|
1778
|
-
for (const v of batch0) a.emit(v);
|
|
1779
|
-
return;
|
|
1780
|
-
}
|
|
1781
|
-
if (batch1 != null && batch1.length > 0 && ctx.prevData[0] !== void 0) {
|
|
1782
|
-
a.emit(ctx.prevData[0]);
|
|
1783
|
-
return;
|
|
1784
|
-
}
|
|
1785
|
-
a.down([[RESOLVED]]);
|
|
1786
|
-
},
|
|
1787
|
-
operatorOpts(opts)
|
|
1788
|
-
);
|
|
429
|
+
finishCleanup();
|
|
430
|
+
};
|
|
431
|
+
return Object.assign(nodes, { dispose });
|
|
1789
432
|
}
|
|
1790
|
-
var combineLatest = combine;
|
|
1791
|
-
var debounceTime = debounce;
|
|
1792
|
-
var throttleTime = throttle;
|
|
1793
|
-
var catchError = rescue;
|
|
1794
433
|
|
|
1795
434
|
// src/extra/reactive-sink.ts
|
|
1796
435
|
var BackpressureBuffer = class {
|
|
@@ -2206,10 +845,10 @@ function reactiveSink(source, config) {
|
|
|
2206
845
|
}
|
|
2207
846
|
|
|
2208
847
|
// src/extra/resilience.ts
|
|
2209
|
-
function
|
|
848
|
+
function operatorOpts(opts) {
|
|
2210
849
|
return { describeKind: "derived", ...opts };
|
|
2211
850
|
}
|
|
2212
|
-
function
|
|
851
|
+
function clampNonNegative(value) {
|
|
2213
852
|
return value < 0 ? 0 : value;
|
|
2214
853
|
}
|
|
2215
854
|
function msgVal(m) {
|
|
@@ -2299,7 +938,7 @@ function retry(source, opts) {
|
|
|
2299
938
|
};
|
|
2300
939
|
},
|
|
2301
940
|
{
|
|
2302
|
-
...
|
|
941
|
+
...operatorOpts(),
|
|
2303
942
|
initial: source.cache
|
|
2304
943
|
}
|
|
2305
944
|
);
|
|
@@ -2389,7 +1028,7 @@ function retrySource(factory, opts) {
|
|
|
2389
1028
|
};
|
|
2390
1029
|
},
|
|
2391
1030
|
{
|
|
2392
|
-
...
|
|
1031
|
+
...operatorOpts(),
|
|
2393
1032
|
initial: opts?.initial
|
|
2394
1033
|
}
|
|
2395
1034
|
);
|
|
@@ -2402,7 +1041,7 @@ var CircuitOpenError = class extends Error {
|
|
|
2402
1041
|
};
|
|
2403
1042
|
function circuitBreaker(options) {
|
|
2404
1043
|
const threshold = Math.max(1, options?.failureThreshold ?? 5);
|
|
2405
|
-
const baseCooldownNs =
|
|
1044
|
+
const baseCooldownNs = clampNonNegative(options?.cooldownNs ?? 30 * NS_PER_SEC);
|
|
2406
1045
|
const cooldownStrategy = options?.cooldown ?? null;
|
|
2407
1046
|
const halfOpenMax = Math.max(1, options?.halfOpenMax ?? 1);
|
|
2408
1047
|
const now = options?.now ?? monotonicNs;
|
|
@@ -2516,7 +1155,7 @@ function withBreaker(breaker, options) {
|
|
|
2516
1155
|
return unsub;
|
|
2517
1156
|
},
|
|
2518
1157
|
{
|
|
2519
|
-
...
|
|
1158
|
+
...operatorOpts(),
|
|
2520
1159
|
meta: { breakerState: breaker.state },
|
|
2521
1160
|
completeWhenDepsComplete: false,
|
|
2522
1161
|
initial: source.cache
|
|
@@ -2634,7 +1273,7 @@ function rateLimiter(source, opts) {
|
|
|
2634
1273
|
};
|
|
2635
1274
|
},
|
|
2636
1275
|
{
|
|
2637
|
-
...
|
|
1276
|
+
...operatorOpts(),
|
|
2638
1277
|
initial: source.cache
|
|
2639
1278
|
}
|
|
2640
1279
|
);
|
|
@@ -2681,7 +1320,7 @@ function withStatus(src, options) {
|
|
|
2681
1320
|
return unsub;
|
|
2682
1321
|
},
|
|
2683
1322
|
{
|
|
2684
|
-
...
|
|
1323
|
+
...operatorOpts(),
|
|
2685
1324
|
meta: { status: initialStatus, error: null },
|
|
2686
1325
|
completeWhenDepsComplete: false,
|
|
2687
1326
|
resubscribable: true,
|
|
@@ -2750,7 +1389,7 @@ function fallback(source, fb) {
|
|
|
2750
1389
|
};
|
|
2751
1390
|
},
|
|
2752
1391
|
{
|
|
2753
|
-
...
|
|
1392
|
+
...operatorOpts(),
|
|
2754
1393
|
initial: source.cache
|
|
2755
1394
|
}
|
|
2756
1395
|
);
|
|
@@ -2805,7 +1444,7 @@ function timeout(source, timeoutNs) {
|
|
|
2805
1444
|
};
|
|
2806
1445
|
},
|
|
2807
1446
|
{
|
|
2808
|
-
...
|
|
1447
|
+
...operatorOpts(),
|
|
2809
1448
|
initial: source.cache
|
|
2810
1449
|
}
|
|
2811
1450
|
);
|
|
@@ -5060,443 +3699,81 @@ function cascadingCache(tiers, opts) {
|
|
|
5060
3699
|
if (clearFn) fireAndForget(clearFn.call(tiers[j], key));
|
|
5061
3700
|
} catch {
|
|
5062
3701
|
}
|
|
5063
|
-
}
|
|
5064
|
-
}
|
|
5065
|
-
nd.down([[TEARDOWN]]);
|
|
5066
|
-
}
|
|
5067
|
-
entries.delete(key);
|
|
5068
|
-
}
|
|
5069
|
-
}
|
|
5070
|
-
}
|
|
5071
|
-
return {
|
|
5072
|
-
load(key) {
|
|
5073
|
-
const existing = entries.get(key);
|
|
5074
|
-
if (existing) {
|
|
5075
|
-
policy?.touch(key);
|
|
5076
|
-
return existing;
|
|
5077
|
-
}
|
|
5078
|
-
if (policy && maxSize > 0 && policy.size() >= maxSize) {
|
|
5079
|
-
evictIfNeeded();
|
|
5080
|
-
}
|
|
5081
|
-
const nd = state(void 0);
|
|
5082
|
-
entries.set(key, nd);
|
|
5083
|
-
policy?.insert(key);
|
|
5084
|
-
cascade(key, nd);
|
|
5085
|
-
return nd;
|
|
5086
|
-
},
|
|
5087
|
-
save(key, value) {
|
|
5088
|
-
if (writeThrough) {
|
|
5089
|
-
for (const tier of tiers) {
|
|
5090
|
-
try {
|
|
5091
|
-
fireAndForget(tier.save(key, value));
|
|
5092
|
-
} catch {
|
|
5093
|
-
}
|
|
5094
|
-
}
|
|
5095
|
-
} else if (tiers[0]) {
|
|
5096
|
-
try {
|
|
5097
|
-
fireAndForget(tiers[0].save(key, value));
|
|
5098
|
-
} catch {
|
|
5099
|
-
}
|
|
5100
|
-
}
|
|
5101
|
-
const existing = entries.get(key);
|
|
5102
|
-
if (existing) {
|
|
5103
|
-
existing.down([[DATA, value]]);
|
|
5104
|
-
policy?.touch(key);
|
|
5105
|
-
} else {
|
|
5106
|
-
if (policy && maxSize > 0 && policy.size() >= maxSize) {
|
|
5107
|
-
evictIfNeeded();
|
|
5108
|
-
}
|
|
5109
|
-
const nd = state(value);
|
|
5110
|
-
entries.set(key, nd);
|
|
5111
|
-
policy?.insert(key);
|
|
5112
|
-
}
|
|
5113
|
-
},
|
|
5114
|
-
invalidate(key) {
|
|
5115
|
-
const existing = entries.get(key);
|
|
5116
|
-
if (existing) cascade(key, existing);
|
|
5117
|
-
},
|
|
5118
|
-
delete(key) {
|
|
5119
|
-
policy?.delete(key);
|
|
5120
|
-
const nd = entries.get(key);
|
|
5121
|
-
if (nd) nd.down([[TEARDOWN]]);
|
|
5122
|
-
entries.delete(key);
|
|
5123
|
-
for (const tier of tiers) {
|
|
5124
|
-
try {
|
|
5125
|
-
const clearFn = tier.clear;
|
|
5126
|
-
if (clearFn) fireAndForget(clearFn.call(tier, key));
|
|
5127
|
-
} catch {
|
|
5128
|
-
}
|
|
5129
|
-
}
|
|
5130
|
-
},
|
|
5131
|
-
has(key) {
|
|
5132
|
-
return entries.has(key);
|
|
5133
|
-
},
|
|
5134
|
-
get size() {
|
|
5135
|
-
return entries.size;
|
|
5136
|
-
}
|
|
5137
|
-
};
|
|
5138
|
-
}
|
|
5139
|
-
|
|
5140
|
-
// src/extra/reactive-map.ts
|
|
5141
|
-
var NativeMapBackend = class {
|
|
5142
|
-
_version = 0;
|
|
5143
|
-
_store = /* @__PURE__ */ new Map();
|
|
5144
|
-
_maxSize;
|
|
5145
|
-
_defaultTtl;
|
|
5146
|
-
constructor(options = {}) {
|
|
5147
|
-
const { maxSize, defaultTtl } = options;
|
|
5148
|
-
if (maxSize !== void 0 && maxSize < 1) {
|
|
5149
|
-
throw new RangeError("maxSize must be >= 1");
|
|
5150
|
-
}
|
|
5151
|
-
if (defaultTtl !== void 0 && defaultTtl <= 0) {
|
|
5152
|
-
throw new RangeError("defaultTtl must be positive");
|
|
5153
|
-
}
|
|
5154
|
-
this._maxSize = maxSize;
|
|
5155
|
-
this._defaultTtl = defaultTtl;
|
|
5156
|
-
}
|
|
5157
|
-
get version() {
|
|
5158
|
-
return this._version;
|
|
5159
|
-
}
|
|
5160
|
-
get size() {
|
|
5161
|
-
return this._store.size;
|
|
5162
|
-
}
|
|
5163
|
-
has(key) {
|
|
5164
|
-
const e = this._store.get(key);
|
|
5165
|
-
if (e === void 0) return false;
|
|
5166
|
-
if (this._isExpired(e)) {
|
|
5167
|
-
this._store.delete(key);
|
|
5168
|
-
this._version += 1;
|
|
5169
|
-
return false;
|
|
5170
|
-
}
|
|
5171
|
-
this._touchLru(key, e);
|
|
5172
|
-
return true;
|
|
5173
|
-
}
|
|
5174
|
-
get(key) {
|
|
5175
|
-
const e = this._store.get(key);
|
|
5176
|
-
if (e === void 0) return void 0;
|
|
5177
|
-
if (this._isExpired(e)) {
|
|
5178
|
-
this._store.delete(key);
|
|
5179
|
-
this._version += 1;
|
|
5180
|
-
return void 0;
|
|
5181
|
-
}
|
|
5182
|
-
this._touchLru(key, e);
|
|
5183
|
-
return e.value;
|
|
5184
|
-
}
|
|
5185
|
-
set(key, value, ttl) {
|
|
5186
|
-
const expiresAt = this._resolveExpiresAt(ttl);
|
|
5187
|
-
if (this._store.has(key)) this._store.delete(key);
|
|
5188
|
-
this._store.set(key, { value, expiresAt });
|
|
5189
|
-
this._evictLruWhileOver();
|
|
5190
|
-
this._version += 1;
|
|
5191
|
-
}
|
|
5192
|
-
setMany(entries, ttl) {
|
|
5193
|
-
const expiresAt = this._resolveExpiresAt(ttl);
|
|
5194
|
-
let count = 0;
|
|
5195
|
-
try {
|
|
5196
|
-
for (const [key, value] of entries) {
|
|
5197
|
-
if (this._store.has(key)) this._store.delete(key);
|
|
5198
|
-
this._store.set(key, { value, expiresAt });
|
|
5199
|
-
count += 1;
|
|
5200
|
-
}
|
|
5201
|
-
} finally {
|
|
5202
|
-
if (count > 0) {
|
|
5203
|
-
this._evictLruWhileOver();
|
|
5204
|
-
this._version += 1;
|
|
5205
|
-
}
|
|
5206
|
-
}
|
|
5207
|
-
}
|
|
5208
|
-
delete(key) {
|
|
5209
|
-
const had = this._store.delete(key);
|
|
5210
|
-
if (had) this._version += 1;
|
|
5211
|
-
return had;
|
|
5212
|
-
}
|
|
5213
|
-
deleteMany(keys) {
|
|
5214
|
-
let removed = 0;
|
|
5215
|
-
try {
|
|
5216
|
-
for (const k of keys) {
|
|
5217
|
-
if (this._store.delete(k)) removed += 1;
|
|
5218
|
-
}
|
|
5219
|
-
} finally {
|
|
5220
|
-
if (removed > 0) this._version += 1;
|
|
5221
|
-
}
|
|
5222
|
-
return removed;
|
|
5223
|
-
}
|
|
5224
|
-
clear() {
|
|
5225
|
-
const n = this._store.size;
|
|
5226
|
-
if (n === 0) return 0;
|
|
5227
|
-
this._store.clear();
|
|
5228
|
-
this._version += 1;
|
|
5229
|
-
return n;
|
|
5230
|
-
}
|
|
5231
|
-
pruneExpired() {
|
|
5232
|
-
const now = monotonicNs();
|
|
5233
|
-
let removed = 0;
|
|
5234
|
-
for (const [k, e] of this._store) {
|
|
5235
|
-
if (this._isExpired(e, now)) {
|
|
5236
|
-
this._store.delete(k);
|
|
5237
|
-
removed += 1;
|
|
5238
|
-
}
|
|
5239
|
-
}
|
|
5240
|
-
if (removed > 0) this._version += 1;
|
|
5241
|
-
return removed;
|
|
5242
|
-
}
|
|
5243
|
-
toMap() {
|
|
5244
|
-
const now = monotonicNs();
|
|
5245
|
-
const out = /* @__PURE__ */ new Map();
|
|
5246
|
-
for (const [k, e] of this._store) {
|
|
5247
|
-
if (!this._isExpired(e, now)) out.set(k, e.value);
|
|
5248
|
-
}
|
|
5249
|
-
return out;
|
|
5250
|
-
}
|
|
5251
|
-
_resolveExpiresAt(ttl) {
|
|
5252
|
-
const effectiveTtl = ttl ?? this._defaultTtl;
|
|
5253
|
-
if (effectiveTtl === void 0) return void 0;
|
|
5254
|
-
if (!Number.isFinite(effectiveTtl) || effectiveTtl <= 0) {
|
|
5255
|
-
throw new RangeError(
|
|
5256
|
-
`MapBackend: ttl must be a positive finite number (got ${effectiveTtl})`
|
|
5257
|
-
);
|
|
5258
|
-
}
|
|
5259
|
-
return monotonicNs() + effectiveTtl * 1e9;
|
|
5260
|
-
}
|
|
5261
|
-
_isExpired(e, now) {
|
|
5262
|
-
if (e.expiresAt === void 0) return false;
|
|
5263
|
-
return (now ?? monotonicNs()) >= e.expiresAt;
|
|
5264
|
-
}
|
|
5265
|
-
_touchLru(key, entry) {
|
|
5266
|
-
this._store.delete(key);
|
|
5267
|
-
this._store.set(key, entry);
|
|
5268
|
-
}
|
|
5269
|
-
_evictLruWhileOver() {
|
|
5270
|
-
if (this._maxSize === void 0) return;
|
|
5271
|
-
while (this._store.size > this._maxSize) {
|
|
5272
|
-
const first2 = this._store.keys().next().value;
|
|
5273
|
-
if (first2 === void 0) break;
|
|
5274
|
-
this._store.delete(first2);
|
|
5275
|
-
}
|
|
5276
|
-
}
|
|
5277
|
-
};
|
|
5278
|
-
function reactiveMap(options = {}) {
|
|
5279
|
-
const { name, maxSize, defaultTtl, versioning, backend: userBackend } = options;
|
|
5280
|
-
const backend = userBackend ?? new NativeMapBackend({ maxSize, defaultTtl });
|
|
5281
|
-
const n = state(backend.toMap(), {
|
|
5282
|
-
name,
|
|
5283
|
-
describeKind: "state",
|
|
5284
|
-
equals: (a, b) => a === b,
|
|
5285
|
-
...versioning != null ? { versioning } : {}
|
|
5286
|
-
});
|
|
5287
|
-
function pushSnapshot() {
|
|
5288
|
-
const map2 = backend.toMap();
|
|
5289
|
-
batch(() => {
|
|
5290
|
-
n.down([[DIRTY]]);
|
|
5291
|
-
n.down([[DATA, map2]]);
|
|
5292
|
-
});
|
|
5293
|
-
}
|
|
5294
|
-
function wrapMutation(op) {
|
|
5295
|
-
const prev = backend.version;
|
|
5296
|
-
try {
|
|
5297
|
-
return op();
|
|
5298
|
-
} finally {
|
|
5299
|
-
if (backend.version !== prev) pushSnapshot();
|
|
5300
|
-
}
|
|
5301
|
-
}
|
|
5302
|
-
return {
|
|
5303
|
-
entries: n,
|
|
5304
|
-
has(key) {
|
|
5305
|
-
return wrapMutation(() => backend.has(key));
|
|
5306
|
-
},
|
|
5307
|
-
get(key) {
|
|
5308
|
-
return wrapMutation(() => backend.get(key));
|
|
5309
|
-
},
|
|
5310
|
-
set(key, value, opts) {
|
|
5311
|
-
wrapMutation(() => backend.set(key, value, opts?.ttl));
|
|
5312
|
-
},
|
|
5313
|
-
setMany(entries, opts) {
|
|
5314
|
-
wrapMutation(() => backend.setMany(entries, opts?.ttl));
|
|
5315
|
-
},
|
|
5316
|
-
delete(key) {
|
|
5317
|
-
wrapMutation(() => backend.delete(key));
|
|
5318
|
-
},
|
|
5319
|
-
deleteMany(keys) {
|
|
5320
|
-
wrapMutation(() => backend.deleteMany(keys));
|
|
5321
|
-
},
|
|
5322
|
-
clear() {
|
|
5323
|
-
wrapMutation(() => backend.clear());
|
|
5324
|
-
},
|
|
5325
|
-
pruneExpired() {
|
|
5326
|
-
wrapMutation(() => backend.pruneExpired());
|
|
5327
|
-
},
|
|
5328
|
-
/**
|
|
5329
|
-
* Current raw entry count — O(1), **pure read**. May include
|
|
5330
|
-
* not-yet-pruned expired entries on TTL maps until the next mutation
|
|
5331
|
-
* or an explicit `pruneExpired()` / `has` / `get` triggers a prune.
|
|
5332
|
-
*
|
|
5333
|
-
* Previously this getter ran `pruneExpired()` inline and emitted a
|
|
5334
|
-
* snapshot as a side effect — that violated spec §5.8 "no
|
|
5335
|
-
* side-effectful reads" and created a re-entrancy hazard when a
|
|
5336
|
-
* subscriber to `entries` read `.size` from its own callback. D2(a).
|
|
5337
|
-
*
|
|
5338
|
-
* For a live count that excludes expired entries, call
|
|
5339
|
-
* `bundle.pruneExpired()` first.
|
|
5340
|
-
*/
|
|
5341
|
-
get size() {
|
|
5342
|
-
return backend.size;
|
|
5343
|
-
},
|
|
5344
|
-
dispose() {
|
|
5345
|
-
}
|
|
5346
|
-
};
|
|
5347
|
-
}
|
|
5348
|
-
|
|
5349
|
-
// src/extra/composite.ts
|
|
5350
|
-
function isNodeLike(value) {
|
|
5351
|
-
return typeof value === "object" && value !== null && "cache" in value && typeof value.subscribe === "function";
|
|
5352
|
-
}
|
|
5353
|
-
function verifiable(source, verifyFn, opts) {
|
|
5354
|
-
const sourceNode = fromAny(source);
|
|
5355
|
-
const hasSourceVersioning = sourceNode.v != null;
|
|
5356
|
-
const verified = state(opts?.initialVerified ?? null, {
|
|
5357
|
-
...hasSourceVersioning ? { meta: { sourceVersion: null } } : {}
|
|
5358
|
-
});
|
|
5359
|
-
const hasTrigger = opts?.trigger !== void 0 && opts.trigger !== null;
|
|
5360
|
-
let triggerNode = null;
|
|
5361
|
-
if (hasTrigger && opts?.autoVerify) {
|
|
5362
|
-
triggerNode = merge(fromAny(opts.trigger), sourceNode);
|
|
5363
|
-
} else if (hasTrigger) {
|
|
5364
|
-
triggerNode = fromAny(opts.trigger);
|
|
5365
|
-
} else if (opts?.autoVerify) {
|
|
5366
|
-
triggerNode = sourceNode;
|
|
5367
|
-
}
|
|
5368
|
-
if (triggerNode !== null) {
|
|
5369
|
-
let verifyStream;
|
|
5370
|
-
if (triggerNode === sourceNode) {
|
|
5371
|
-
verifyStream = switchMap(sourceNode, (src) => verifyFn(src));
|
|
5372
|
-
} else {
|
|
5373
|
-
let latestSource = sourceNode.cache;
|
|
5374
|
-
sourceNode.subscribe((msgs) => {
|
|
5375
|
-
for (const m of msgs) {
|
|
5376
|
-
if (m[0] === DATA) latestSource = m[1];
|
|
5377
|
-
}
|
|
5378
|
-
});
|
|
5379
|
-
verifyStream = switchMap(triggerNode, () => verifyFn(latestSource));
|
|
5380
|
-
}
|
|
5381
|
-
forEach(verifyStream, (value) => {
|
|
5382
|
-
batch(() => {
|
|
5383
|
-
verified.down([[DATA, value]]);
|
|
5384
|
-
if (hasSourceVersioning) {
|
|
5385
|
-
const sv = sourceNode.v;
|
|
5386
|
-
if (sv != null) {
|
|
5387
|
-
verified.meta.sourceVersion.down([[DATA, { id: sv.id, version: sv.version }]]);
|
|
5388
|
-
}
|
|
5389
|
-
}
|
|
5390
|
-
});
|
|
5391
|
-
});
|
|
5392
|
-
}
|
|
5393
|
-
return { node: sourceNode, verified, trigger: triggerNode };
|
|
5394
|
-
}
|
|
5395
|
-
function keepalive2(node2) {
|
|
5396
|
-
node2.subscribe(() => void 0);
|
|
5397
|
-
}
|
|
5398
|
-
function mapFromSnapshot(snapshot) {
|
|
5399
|
-
if (snapshot instanceof Map) return snapshot;
|
|
5400
|
-
return /* @__PURE__ */ new Map();
|
|
5401
|
-
}
|
|
5402
|
-
function applyExtraction(store, extraction) {
|
|
5403
|
-
if (!Array.isArray(extraction.upsert)) {
|
|
5404
|
-
throw new TypeError("distill extraction requires upsert: Array<{ key, value }>");
|
|
5405
|
-
}
|
|
5406
|
-
batch(() => {
|
|
5407
|
-
for (const { key, value } of extraction.upsert) {
|
|
5408
|
-
store.set(key, value);
|
|
5409
|
-
}
|
|
5410
|
-
for (const key of extraction.remove ?? []) {
|
|
5411
|
-
store.delete(key);
|
|
5412
|
-
}
|
|
5413
|
-
});
|
|
5414
|
-
}
|
|
5415
|
-
function distill(source, extractFn, opts) {
|
|
5416
|
-
const sourceNode = fromAny(source);
|
|
5417
|
-
const store = reactiveMap(opts.mapOptions ?? {});
|
|
5418
|
-
const budget = opts.budget ?? 2e3;
|
|
5419
|
-
const hasContext = opts.context !== void 0 && opts.context !== null;
|
|
5420
|
-
const contextNode = hasContext ? fromAny(opts.context) : state(null);
|
|
5421
|
-
let latestStore = mapFromSnapshot(store.entries.cache);
|
|
5422
|
-
store.entries.subscribe((msgs) => {
|
|
5423
|
-
for (const m of msgs) {
|
|
5424
|
-
if (m[0] === DATA) latestStore = mapFromSnapshot(m[1]);
|
|
5425
|
-
}
|
|
5426
|
-
});
|
|
5427
|
-
const extractionStream = switchMap(sourceNode, (raw) => extractFn(raw, latestStore));
|
|
5428
|
-
forEach(extractionStream, (extraction) => {
|
|
5429
|
-
applyExtraction(store, extraction);
|
|
5430
|
-
});
|
|
5431
|
-
if (opts.evict) {
|
|
5432
|
-
const verdictUnsubs = /* @__PURE__ */ new Map();
|
|
5433
|
-
const evictionKeys = derived([store.entries], ([snapshot]) => {
|
|
5434
|
-
const out = [];
|
|
5435
|
-
const entries = mapFromSnapshot(snapshot);
|
|
5436
|
-
for (const key of verdictUnsubs.keys()) {
|
|
5437
|
-
if (!entries.has(key)) {
|
|
5438
|
-
verdictUnsubs.get(key)();
|
|
5439
|
-
verdictUnsubs.delete(key);
|
|
3702
|
+
}
|
|
3703
|
+
}
|
|
3704
|
+
nd.down([[TEARDOWN]]);
|
|
5440
3705
|
}
|
|
3706
|
+
entries.delete(key);
|
|
5441
3707
|
}
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
|
|
5447
|
-
|
|
5448
|
-
|
|
5449
|
-
|
|
5450
|
-
|
|
5451
|
-
|
|
3708
|
+
}
|
|
3709
|
+
}
|
|
3710
|
+
return {
|
|
3711
|
+
load(key) {
|
|
3712
|
+
const existing = entries.get(key);
|
|
3713
|
+
if (existing) {
|
|
3714
|
+
policy?.touch(key);
|
|
3715
|
+
return existing;
|
|
3716
|
+
}
|
|
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 {
|
|
5452
3732
|
}
|
|
5453
|
-
continue;
|
|
5454
3733
|
}
|
|
5455
|
-
|
|
5456
|
-
|
|
5457
|
-
|
|
3734
|
+
} else if (tiers[0]) {
|
|
3735
|
+
try {
|
|
3736
|
+
fireAndForget(tiers[0].save(key, value));
|
|
3737
|
+
} catch {
|
|
5458
3738
|
}
|
|
5459
|
-
throw new TypeError("distill evict() must return boolean or Node<boolean>");
|
|
5460
3739
|
}
|
|
5461
|
-
|
|
5462
|
-
|
|
5463
|
-
|
|
5464
|
-
|
|
5465
|
-
|
|
5466
|
-
|
|
5467
|
-
|
|
5468
|
-
|
|
5469
|
-
|
|
5470
|
-
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5479
|
-
|
|
5480
|
-
key
|
|
5481
|
-
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
if (item.cost <= remaining) {
|
|
5490
|
-
packed.push({ key: item.key, value: item.value, score: item.score });
|
|
5491
|
-
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
|
+
}
|
|
5492
3768
|
}
|
|
3769
|
+
},
|
|
3770
|
+
has(key) {
|
|
3771
|
+
return entries.has(key);
|
|
3772
|
+
},
|
|
3773
|
+
get size() {
|
|
3774
|
+
return entries.size;
|
|
5493
3775
|
}
|
|
5494
|
-
|
|
5495
|
-
});
|
|
5496
|
-
const size = derived([store.entries], ([snapshot]) => mapFromSnapshot(snapshot).size);
|
|
5497
|
-
keepalive2(compact);
|
|
5498
|
-
keepalive2(size);
|
|
5499
|
-
return { store, compact, size };
|
|
3776
|
+
};
|
|
5500
3777
|
}
|
|
5501
3778
|
|
|
5502
3779
|
// src/extra/pubsub.ts
|
|
@@ -5792,139 +4069,118 @@ function reactiveIndex(options = {}) {
|
|
|
5792
4069
|
};
|
|
5793
4070
|
}
|
|
5794
4071
|
|
|
5795
|
-
// src/extra/
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
|
|
5804
|
-
|
|
5805
|
-
get size() {
|
|
5806
|
-
return this._buf.length;
|
|
5807
|
-
}
|
|
5808
|
-
at(index) {
|
|
5809
|
-
if (!Number.isInteger(index)) return void 0;
|
|
5810
|
-
const i = index >= 0 ? index : this._buf.length + index;
|
|
5811
|
-
if (i < 0 || i >= this._buf.length) return void 0;
|
|
5812
|
-
return this._buf[i];
|
|
5813
|
-
}
|
|
5814
|
-
append(value) {
|
|
5815
|
-
this._buf.push(value);
|
|
5816
|
-
this._version += 1;
|
|
5817
|
-
}
|
|
5818
|
-
appendMany(values) {
|
|
5819
|
-
if (values.length === 0) return;
|
|
5820
|
-
const oldLen = this._buf.length;
|
|
5821
|
-
this._buf.length = oldLen + values.length;
|
|
5822
|
-
for (let i = 0; i < values.length; i++) {
|
|
5823
|
-
this._buf[oldLen + i] = values[i];
|
|
5824
|
-
}
|
|
5825
|
-
this._version += 1;
|
|
5826
|
-
}
|
|
5827
|
-
insert(index, value) {
|
|
5828
|
-
if (!Number.isInteger(index) || index < 0 || index > this._buf.length) {
|
|
5829
|
-
throw new RangeError(`insert: index ${index} out of range [0, ${this._buf.length}]`);
|
|
5830
|
-
}
|
|
5831
|
-
this._buf.splice(index, 0, value);
|
|
5832
|
-
this._version += 1;
|
|
5833
|
-
}
|
|
5834
|
-
insertMany(index, values) {
|
|
5835
|
-
if (!Number.isInteger(index) || index < 0 || index > this._buf.length) {
|
|
5836
|
-
throw new RangeError(`insertMany: index ${index} out of range [0, ${this._buf.length}]`);
|
|
5837
|
-
}
|
|
5838
|
-
if (values.length === 0) return;
|
|
5839
|
-
this._buf.splice(index, 0, ...values);
|
|
5840
|
-
this._version += 1;
|
|
5841
|
-
}
|
|
5842
|
-
pop(index) {
|
|
5843
|
-
if (this._buf.length === 0) {
|
|
5844
|
-
throw new RangeError("pop from empty list");
|
|
5845
|
-
}
|
|
5846
|
-
if (!Number.isInteger(index)) {
|
|
5847
|
-
throw new RangeError(`pop: index ${index} must be an integer`);
|
|
5848
|
-
}
|
|
5849
|
-
const i = index >= 0 ? index : this._buf.length + index;
|
|
5850
|
-
if (i < 0 || i >= this._buf.length) {
|
|
5851
|
-
throw new RangeError(`pop: index ${index} out of range`);
|
|
5852
|
-
}
|
|
5853
|
-
const [v] = this._buf.splice(i, 1);
|
|
5854
|
-
this._version += 1;
|
|
5855
|
-
return v;
|
|
5856
|
-
}
|
|
5857
|
-
clear() {
|
|
5858
|
-
const n = this._buf.length;
|
|
5859
|
-
if (n === 0) return 0;
|
|
5860
|
-
this._buf.length = 0;
|
|
5861
|
-
this._version += 1;
|
|
5862
|
-
return n;
|
|
5863
|
-
}
|
|
5864
|
-
toArray() {
|
|
5865
|
-
return [...this._buf];
|
|
5866
|
-
}
|
|
5867
|
-
};
|
|
5868
|
-
function reactiveList(initial, options = {}) {
|
|
5869
|
-
const { name, versioning, backend: userBackend } = options;
|
|
5870
|
-
const backend = userBackend ?? new NativeListBackend(initial);
|
|
5871
|
-
const items = state(backend.toArray(), {
|
|
5872
|
-
name,
|
|
5873
|
-
describeKind: "state",
|
|
5874
|
-
equals: (a, b) => a === b,
|
|
5875
|
-
...versioning != null ? { versioning } : {}
|
|
5876
|
-
});
|
|
5877
|
-
function pushSnapshot() {
|
|
5878
|
-
const snapshot = backend.toArray();
|
|
5879
|
-
batch(() => {
|
|
5880
|
-
items.down([[DIRTY]]);
|
|
5881
|
-
items.down([[DATA, snapshot]]);
|
|
5882
|
-
});
|
|
4072
|
+
// src/extra/sources-fs.ts
|
|
4073
|
+
import { existsSync, watch } from "node:fs";
|
|
4074
|
+
import { resolve as resolvePath } from "node:path";
|
|
4075
|
+
function sourceOpts3(opts) {
|
|
4076
|
+
return { describeKind: "producer", ...opts };
|
|
4077
|
+
}
|
|
4078
|
+
function fromFSWatch(paths, opts) {
|
|
4079
|
+
const list = Array.isArray(paths) ? paths : [paths];
|
|
4080
|
+
if (list.length === 0) {
|
|
4081
|
+
throw new RangeError("fromFSWatch expects at least one path");
|
|
5883
4082
|
}
|
|
5884
|
-
|
|
5885
|
-
|
|
4083
|
+
const { recursive = true, debounce: debounce2 = 100, include, exclude, ...rest } = opts ?? {};
|
|
4084
|
+
const includePatterns = include?.map(globToRegExp) ?? [];
|
|
4085
|
+
const excludePatterns = (exclude ?? ["**/node_modules/**", "**/.git/**", "**/dist/**"]).map(
|
|
4086
|
+
globToRegExp
|
|
4087
|
+
);
|
|
4088
|
+
return producer((a) => {
|
|
4089
|
+
const pending = /* @__PURE__ */ new Map();
|
|
4090
|
+
const watchers = [];
|
|
4091
|
+
let stopped = false;
|
|
4092
|
+
let terminalEmitted = false;
|
|
4093
|
+
let generation = 0;
|
|
4094
|
+
const closeWatchers = () => {
|
|
4095
|
+
for (const watcher of watchers.splice(0)) watcher.close();
|
|
4096
|
+
};
|
|
4097
|
+
const emitError = (err) => {
|
|
4098
|
+
if (terminalEmitted) return;
|
|
4099
|
+
terminalEmitted = true;
|
|
4100
|
+
stopped = true;
|
|
4101
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
4102
|
+
timer = void 0;
|
|
4103
|
+
pending.clear();
|
|
4104
|
+
closeWatchers();
|
|
4105
|
+
a.down([[ERROR, err]]);
|
|
4106
|
+
};
|
|
4107
|
+
let timer;
|
|
4108
|
+
const flush = (token) => {
|
|
4109
|
+
timer = void 0;
|
|
4110
|
+
if (stopped || terminalEmitted) return;
|
|
4111
|
+
if (pending.size === 0) return;
|
|
4112
|
+
const batchMessages = [];
|
|
4113
|
+
for (const evt of pending.values()) batchMessages.push([DATA, evt]);
|
|
4114
|
+
pending.clear();
|
|
4115
|
+
if (stopped || terminalEmitted || token !== generation) return;
|
|
4116
|
+
a.down(batchMessages);
|
|
4117
|
+
};
|
|
5886
4118
|
try {
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
5892
|
-
|
|
5893
|
-
|
|
5894
|
-
|
|
5895
|
-
|
|
5896
|
-
|
|
5897
|
-
|
|
5898
|
-
|
|
5899
|
-
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
|
|
5909
|
-
|
|
5910
|
-
|
|
5911
|
-
|
|
5912
|
-
|
|
5913
|
-
|
|
5914
|
-
|
|
5915
|
-
|
|
5916
|
-
|
|
5917
|
-
|
|
5918
|
-
|
|
4119
|
+
for (const basePath of list) {
|
|
4120
|
+
const watcher = watch(
|
|
4121
|
+
basePath,
|
|
4122
|
+
{ recursive },
|
|
4123
|
+
(eventType, fileName) => {
|
|
4124
|
+
if (stopped || terminalEmitted) return;
|
|
4125
|
+
if (fileName == null) return;
|
|
4126
|
+
const rel = String(fileName).replaceAll("\\", "/");
|
|
4127
|
+
const abs = resolvePath(basePath, String(fileName));
|
|
4128
|
+
const normalized = abs.replaceAll("\\", "/");
|
|
4129
|
+
const root = resolvePath(basePath).replaceAll("\\", "/");
|
|
4130
|
+
const relForMatch = rel.startsWith("./") ? rel.slice(2) : rel;
|
|
4131
|
+
const included = includePatterns.length === 0 || matchesAnyPattern(normalized, includePatterns) || matchesAnyPattern(relForMatch, includePatterns);
|
|
4132
|
+
if (!included) return;
|
|
4133
|
+
const excluded = matchesAnyPattern(normalized, excludePatterns) || matchesAnyPattern(relForMatch, excludePatterns);
|
|
4134
|
+
if (excluded) return;
|
|
4135
|
+
let kind = "change";
|
|
4136
|
+
if (eventType === "rename") {
|
|
4137
|
+
try {
|
|
4138
|
+
kind = existsSync(normalized) ? "create" : "delete";
|
|
4139
|
+
} catch {
|
|
4140
|
+
kind = "rename";
|
|
4141
|
+
}
|
|
4142
|
+
}
|
|
4143
|
+
pending.set(normalized, {
|
|
4144
|
+
type: kind,
|
|
4145
|
+
path: normalized,
|
|
4146
|
+
root,
|
|
4147
|
+
relative_path: relForMatch,
|
|
4148
|
+
timestamp_ns: wallClockNs()
|
|
4149
|
+
});
|
|
4150
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
4151
|
+
const token = generation;
|
|
4152
|
+
timer = setTimeout(() => flush(token), debounce2);
|
|
4153
|
+
}
|
|
4154
|
+
);
|
|
4155
|
+
watcher.on("error", (err) => emitError(err));
|
|
4156
|
+
watchers.push(watcher);
|
|
4157
|
+
}
|
|
4158
|
+
} catch (err) {
|
|
4159
|
+
emitError(err);
|
|
5919
4160
|
}
|
|
5920
|
-
|
|
4161
|
+
return () => {
|
|
4162
|
+
stopped = true;
|
|
4163
|
+
generation += 1;
|
|
4164
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
4165
|
+
timer = void 0;
|
|
4166
|
+
closeWatchers();
|
|
4167
|
+
pending.clear();
|
|
4168
|
+
};
|
|
4169
|
+
}, sourceOpts3(rest));
|
|
5921
4170
|
}
|
|
5922
4171
|
|
|
5923
4172
|
// src/extra/storage.ts
|
|
5924
|
-
import { randomBytes } from "crypto";
|
|
5925
|
-
import {
|
|
5926
|
-
|
|
5927
|
-
|
|
4173
|
+
import { randomBytes } from "node:crypto";
|
|
4174
|
+
import {
|
|
4175
|
+
mkdirSync,
|
|
4176
|
+
readdirSync,
|
|
4177
|
+
readFileSync,
|
|
4178
|
+
renameSync,
|
|
4179
|
+
unlinkSync,
|
|
4180
|
+
writeFileSync
|
|
4181
|
+
} from "node:fs";
|
|
4182
|
+
import { basename, dirname, join } from "node:path";
|
|
4183
|
+
import { DatabaseSync } from "node:sqlite";
|
|
5928
4184
|
function sortJsonValue(value) {
|
|
5929
4185
|
if (value === null || typeof value !== "object") return value;
|
|
5930
4186
|
if (Array.isArray(value)) return value.map(sortJsonValue);
|
|
@@ -5949,6 +4205,9 @@ function memoryStorage() {
|
|
|
5949
4205
|
},
|
|
5950
4206
|
clear(key) {
|
|
5951
4207
|
data.delete(key);
|
|
4208
|
+
},
|
|
4209
|
+
list() {
|
|
4210
|
+
return [...data.keys()].sort();
|
|
5952
4211
|
}
|
|
5953
4212
|
};
|
|
5954
4213
|
}
|
|
@@ -5963,16 +4222,54 @@ function dictStorage(storage) {
|
|
|
5963
4222
|
},
|
|
5964
4223
|
clear(key) {
|
|
5965
4224
|
delete storage[key];
|
|
4225
|
+
},
|
|
4226
|
+
list() {
|
|
4227
|
+
return Object.keys(storage).sort();
|
|
5966
4228
|
}
|
|
5967
4229
|
};
|
|
5968
4230
|
}
|
|
5969
4231
|
function fileStorage(dir) {
|
|
4232
|
+
const encoder = new TextEncoder();
|
|
4233
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
5970
4234
|
const pathFor = (key) => {
|
|
5971
|
-
|
|
5972
|
-
|
|
5973
|
-
(
|
|
5974
|
-
|
|
5975
|
-
|
|
4235
|
+
let out = "";
|
|
4236
|
+
for (const ch of key) {
|
|
4237
|
+
if (ch.length === 1 && /[a-zA-Z0-9_-]/.test(ch)) {
|
|
4238
|
+
out += ch;
|
|
4239
|
+
continue;
|
|
4240
|
+
}
|
|
4241
|
+
for (const byte of encoder.encode(ch)) {
|
|
4242
|
+
out += `%${byte.toString(16).padStart(2, "0")}`;
|
|
4243
|
+
}
|
|
4244
|
+
}
|
|
4245
|
+
return join(dir, `${out}.json`);
|
|
4246
|
+
};
|
|
4247
|
+
const keyFromFilename = (filename) => {
|
|
4248
|
+
if (!filename.endsWith(".json")) return null;
|
|
4249
|
+
const stem = filename.slice(0, -".json".length);
|
|
4250
|
+
const bytes = [];
|
|
4251
|
+
const encodeAscii = (s) => {
|
|
4252
|
+
for (let i2 = 0; i2 < s.length; i2++) bytes.push(s.charCodeAt(i2));
|
|
4253
|
+
};
|
|
4254
|
+
let i = 0;
|
|
4255
|
+
while (i < stem.length) {
|
|
4256
|
+
const ch = stem[i];
|
|
4257
|
+
if (ch === "%" && i + 2 < stem.length) {
|
|
4258
|
+
const hex = stem.slice(i + 1, i + 3);
|
|
4259
|
+
if (/^[0-9a-f]{2}$/i.test(hex)) {
|
|
4260
|
+
bytes.push(Number.parseInt(hex, 16));
|
|
4261
|
+
i += 3;
|
|
4262
|
+
continue;
|
|
4263
|
+
}
|
|
4264
|
+
}
|
|
4265
|
+
encodeAscii(ch);
|
|
4266
|
+
i += 1;
|
|
4267
|
+
}
|
|
4268
|
+
try {
|
|
4269
|
+
return decoder.decode(new Uint8Array(bytes));
|
|
4270
|
+
} catch {
|
|
4271
|
+
return null;
|
|
4272
|
+
}
|
|
5976
4273
|
};
|
|
5977
4274
|
return {
|
|
5978
4275
|
save(key, record) {
|
|
@@ -6009,6 +4306,21 @@ function fileStorage(dir) {
|
|
|
6009
4306
|
} catch (e) {
|
|
6010
4307
|
if (e.code !== "ENOENT") throw e;
|
|
6011
4308
|
}
|
|
4309
|
+
},
|
|
4310
|
+
list() {
|
|
4311
|
+
try {
|
|
4312
|
+
const entries = readdirSync(dir);
|
|
4313
|
+
const keys = [];
|
|
4314
|
+
for (const entry of entries) {
|
|
4315
|
+
if (entry.startsWith(".")) continue;
|
|
4316
|
+
const k = keyFromFilename(entry);
|
|
4317
|
+
if (k !== null) keys.push(k);
|
|
4318
|
+
}
|
|
4319
|
+
return keys.sort();
|
|
4320
|
+
} catch (e) {
|
|
4321
|
+
if (e.code === "ENOENT") return [];
|
|
4322
|
+
throw e;
|
|
4323
|
+
}
|
|
6012
4324
|
}
|
|
6013
4325
|
};
|
|
6014
4326
|
}
|
|
@@ -6031,6 +4343,10 @@ function sqliteStorage(path) {
|
|
|
6031
4343
|
clear(key) {
|
|
6032
4344
|
db.prepare(`DELETE FROM graphrefly_checkpoint WHERE k = ?`).run(key);
|
|
6033
4345
|
},
|
|
4346
|
+
list() {
|
|
4347
|
+
const rows = db.prepare(`SELECT k FROM graphrefly_checkpoint ORDER BY k`).all();
|
|
4348
|
+
return rows.map((r) => r.k);
|
|
4349
|
+
},
|
|
6034
4350
|
close() {
|
|
6035
4351
|
try {
|
|
6036
4352
|
db.close();
|
|
@@ -6678,63 +4994,8 @@ function workerSelf(target, opts) {
|
|
|
6678
4994
|
}
|
|
6679
4995
|
|
|
6680
4996
|
export {
|
|
6681
|
-
NS_PER_MS,
|
|
6682
|
-
NS_PER_SEC,
|
|
6683
|
-
constant,
|
|
6684
|
-
linear,
|
|
6685
|
-
exponential,
|
|
6686
|
-
fibonacci,
|
|
6687
|
-
decorrelatedJitter,
|
|
6688
|
-
withMaxAttempts,
|
|
6689
|
-
resolveBackoffPreset,
|
|
6690
4997
|
externalProducer,
|
|
6691
4998
|
externalBundle,
|
|
6692
|
-
map,
|
|
6693
|
-
filter,
|
|
6694
|
-
scan,
|
|
6695
|
-
reduce,
|
|
6696
|
-
take,
|
|
6697
|
-
skip,
|
|
6698
|
-
takeWhile,
|
|
6699
|
-
takeUntil,
|
|
6700
|
-
first,
|
|
6701
|
-
last,
|
|
6702
|
-
find,
|
|
6703
|
-
elementAt,
|
|
6704
|
-
tap,
|
|
6705
|
-
distinctUntilChanged,
|
|
6706
|
-
pairwise,
|
|
6707
|
-
combine,
|
|
6708
|
-
withLatestFrom,
|
|
6709
|
-
merge,
|
|
6710
|
-
zip,
|
|
6711
|
-
concat,
|
|
6712
|
-
race,
|
|
6713
|
-
switchMap,
|
|
6714
|
-
exhaustMap,
|
|
6715
|
-
concatMap,
|
|
6716
|
-
mergeMap,
|
|
6717
|
-
flatMap,
|
|
6718
|
-
delay,
|
|
6719
|
-
debounce,
|
|
6720
|
-
throttle,
|
|
6721
|
-
sample,
|
|
6722
|
-
audit,
|
|
6723
|
-
buffer,
|
|
6724
|
-
bufferCount,
|
|
6725
|
-
windowCount,
|
|
6726
|
-
bufferTime,
|
|
6727
|
-
windowTime,
|
|
6728
|
-
window,
|
|
6729
|
-
interval,
|
|
6730
|
-
repeat,
|
|
6731
|
-
pausable,
|
|
6732
|
-
rescue,
|
|
6733
|
-
valve,
|
|
6734
|
-
combineLatest,
|
|
6735
|
-
debounceTime,
|
|
6736
|
-
throttleTime,
|
|
6737
|
-
catchError,
|
|
6738
4999
|
reactiveSink,
|
|
6739
5000
|
retry,
|
|
6740
5001
|
retrySource,
|
|
@@ -6802,16 +5063,11 @@ export {
|
|
|
6802
5063
|
fromKysely,
|
|
6803
5064
|
lru,
|
|
6804
5065
|
cascadingCache,
|
|
6805
|
-
NativeMapBackend,
|
|
6806
|
-
reactiveMap,
|
|
6807
|
-
verifiable,
|
|
6808
|
-
distill,
|
|
6809
5066
|
NativePubSubBackend,
|
|
6810
5067
|
pubsub,
|
|
6811
5068
|
NativeIndexBackend,
|
|
6812
5069
|
reactiveIndex,
|
|
6813
|
-
|
|
6814
|
-
reactiveList,
|
|
5070
|
+
fromFSWatch,
|
|
6815
5071
|
memoryStorage,
|
|
6816
5072
|
dictStorage,
|
|
6817
5073
|
fileStorage,
|
|
@@ -6828,4 +5084,4 @@ export {
|
|
|
6828
5084
|
workerSelf,
|
|
6829
5085
|
extra_exports
|
|
6830
5086
|
};
|
|
6831
|
-
//# sourceMappingURL=chunk-
|
|
5087
|
+
//# sourceMappingURL=chunk-BQ6RQQFF.js.map
|