@graphrefly/graphrefly 0.1.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/LICENSE +21 -0
- package/README.md +234 -0
- package/dist/chunk-5X3LAO3B.js +1571 -0
- package/dist/chunk-5X3LAO3B.js.map +1 -0
- package/dist/chunk-6W5SGIGB.js +1793 -0
- package/dist/chunk-6W5SGIGB.js.map +1 -0
- package/dist/chunk-CP6MNKAA.js +97 -0
- package/dist/chunk-CP6MNKAA.js.map +1 -0
- package/dist/chunk-HP7OKEOE.js +107 -0
- package/dist/chunk-HP7OKEOE.js.map +1 -0
- package/dist/chunk-KWXPDASV.js +781 -0
- package/dist/chunk-KWXPDASV.js.map +1 -0
- package/dist/chunk-O3PI7W45.js +68 -0
- package/dist/chunk-O3PI7W45.js.map +1 -0
- package/dist/chunk-QW7H3ICI.js +1372 -0
- package/dist/chunk-QW7H3ICI.js.map +1 -0
- package/dist/chunk-VPS7L64N.js +4785 -0
- package/dist/chunk-VPS7L64N.js.map +1 -0
- package/dist/chunk-Z4Y4FMQN.js +1097 -0
- package/dist/chunk-Z4Y4FMQN.js.map +1 -0
- package/dist/compat/nestjs/index.cjs +4883 -0
- package/dist/compat/nestjs/index.cjs.map +1 -0
- package/dist/compat/nestjs/index.d.cts +7 -0
- package/dist/compat/nestjs/index.d.ts +7 -0
- package/dist/compat/nestjs/index.js +84 -0
- package/dist/compat/nestjs/index.js.map +1 -0
- package/dist/core/index.cjs +1632 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +2 -0
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +90 -0
- package/dist/core/index.js.map +1 -0
- package/dist/extra/index.cjs +6885 -0
- package/dist/extra/index.cjs.map +1 -0
- package/dist/extra/index.d.cts +5 -0
- package/dist/extra/index.d.ts +5 -0
- package/dist/extra/index.js +290 -0
- package/dist/extra/index.js.map +1 -0
- package/dist/graph/index.cjs +3225 -0
- package/dist/graph/index.cjs.map +1 -0
- package/dist/graph/index.d.cts +3 -0
- package/dist/graph/index.d.ts +3 -0
- package/dist/graph/index.js +25 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph-CL_ZDAj9.d.cts +605 -0
- package/dist/graph-D18qmsNm.d.ts +605 -0
- package/dist/index-B6SsZs2h.d.cts +3463 -0
- package/dist/index-B7eOdgEx.d.ts +449 -0
- package/dist/index-BHUvlQ3v.d.ts +3463 -0
- package/dist/index-BtK55IE2.d.ts +231 -0
- package/dist/index-BvhgZRHK.d.cts +231 -0
- package/dist/index-Bvy_6CaN.d.ts +452 -0
- package/dist/index-C3BMRmmp.d.cts +449 -0
- package/dist/index-C5mqLhMX.d.cts +452 -0
- package/dist/index-CP_QvbWu.d.ts +940 -0
- package/dist/index-D_geH2Bm.d.cts +940 -0
- package/dist/index.cjs +14843 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1517 -0
- package/dist/index.d.ts +1517 -0
- package/dist/index.js +3649 -0
- package/dist/index.js.map +1 -0
- package/dist/meta-BsF6Sag9.d.cts +607 -0
- package/dist/meta-BsF6Sag9.d.ts +607 -0
- package/dist/patterns/reactive-layout/index.cjs +4143 -0
- package/dist/patterns/reactive-layout/index.cjs.map +1 -0
- package/dist/patterns/reactive-layout/index.d.cts +3 -0
- package/dist/patterns/reactive-layout/index.d.ts +3 -0
- package/dist/patterns/reactive-layout/index.js +38 -0
- package/dist/patterns/reactive-layout/index.js.map +1 -0
- package/dist/reactive-log-BfvfNWQh.d.cts +137 -0
- package/dist/reactive-log-ohLmTXoZ.d.ts +137 -0
- package/package.json +256 -0
|
@@ -0,0 +1,3463 @@
|
|
|
1
|
+
import { N as Node, a as NodeOptions, M as Message, i as Messages } from './meta-BsF6Sag9.js';
|
|
2
|
+
import { q as GraphPersistSnapshot, G as Graph } from './graph-D18qmsNm.js';
|
|
3
|
+
import { V as Versioned, a as ReactiveLogBundle, b as ReactiveLogOptions, R as ReactiveLogSnapshot, l as logSlice, o as observeGraph$, c as observeNode$, r as reactiveLog, t as toMessages$, d as toObservable } from './reactive-log-ohLmTXoZ.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Backoff strategies for {@link retry} (roadmap §3.1). Delays are in **nanoseconds**.
|
|
7
|
+
*
|
|
8
|
+
* Convention: all graphrefly-ts timestamps and durations use nanoseconds (`_ns` suffix).
|
|
9
|
+
* 1 second = 1_000_000_000 ns, 1 ms = 1_000_000 ns.
|
|
10
|
+
*/
|
|
11
|
+
declare const NS_PER_MS = 1000000;
|
|
12
|
+
declare const NS_PER_SEC = 1000000000;
|
|
13
|
+
type JitterMode = "none" | "full" | "equal";
|
|
14
|
+
type BackoffPreset = "constant" | "linear" | "exponential" | "fibonacci" | "decorrelatedJitter";
|
|
15
|
+
/** `(attempt, error?, previousDelayNs?) => delayNs | null` — `null` means zero delay. */
|
|
16
|
+
type BackoffStrategy = (attempt: number, error?: unknown, prevDelayNs?: number | null) => number | null;
|
|
17
|
+
/**
|
|
18
|
+
* Builds a strategy that always returns the same delay in nanoseconds.
|
|
19
|
+
*
|
|
20
|
+
* @param delayNs - Non-negative delay in nanoseconds; values below zero are clamped to zero.
|
|
21
|
+
* @returns `BackoffStrategy` for use with {@link retry} or custom timers.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { constant, retry, NS_PER_SEC } from "@graphrefly/graphrefly-ts";
|
|
26
|
+
*
|
|
27
|
+
* const out = retry(source, { count: 3, backoff: constant(0.25 * NS_PER_SEC) });
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @category extra
|
|
31
|
+
*/
|
|
32
|
+
declare function constant(delayNs: number): BackoffStrategy;
|
|
33
|
+
/**
|
|
34
|
+
* Builds linear backoff: `baseNs + stepNs * attempt` (`stepNs` defaults to `baseNs`).
|
|
35
|
+
*
|
|
36
|
+
* @param baseNs - Base delay in nanoseconds (clamped non-negative).
|
|
37
|
+
* @param stepNs - Added per retry attempt in nanoseconds (clamped non-negative).
|
|
38
|
+
* @returns `BackoffStrategy` for {@link retry}.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { linear, retry, NS_PER_SEC } from "@graphrefly/graphrefly-ts";
|
|
43
|
+
*
|
|
44
|
+
* // Attempt 0 → 1 s, attempt 1 → 2 s, attempt 2 → 3 s …
|
|
45
|
+
* const out = retry(source, { count: 4, backoff: linear(NS_PER_SEC) });
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @category extra
|
|
49
|
+
*/
|
|
50
|
+
declare function linear(baseNs: number, stepNs?: number): BackoffStrategy;
|
|
51
|
+
type ExponentialBackoffOptions = {
|
|
52
|
+
baseNs?: number;
|
|
53
|
+
factor?: number;
|
|
54
|
+
maxDelayNs?: number;
|
|
55
|
+
jitter?: JitterMode;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Builds exponential backoff in nanoseconds, capped by `maxDelayNs`, with optional jitter.
|
|
59
|
+
*
|
|
60
|
+
* @param options - Base, factor, cap, and jitter mode.
|
|
61
|
+
* @returns `BackoffStrategy` for {@link retry}.
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
* **Jitter:** `"full"` spreads delay across `[0, delay]`; `"equal"` uses `[delay/2, delay]`.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { exponential, retry, NS_PER_SEC } from "@graphrefly/graphrefly-ts";
|
|
69
|
+
*
|
|
70
|
+
* // 100 ms → 200 ms → 400 ms … capped at 30 s, with full jitter
|
|
71
|
+
* const out = retry(source, {
|
|
72
|
+
* count: 5,
|
|
73
|
+
* backoff: exponential({ baseNs: 100 * NS_PER_SEC / 1000, jitter: "full" }),
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @category extra
|
|
78
|
+
*/
|
|
79
|
+
declare function exponential(options?: ExponentialBackoffOptions): BackoffStrategy;
|
|
80
|
+
/**
|
|
81
|
+
* Builds Fibonacci-scaled delays: `1, 2, 3, 5, … × baseNs`, capped at `maxDelayNs`.
|
|
82
|
+
*
|
|
83
|
+
* @param baseNs - Multiplier applied to the Fibonacci unit (default `100ms` in nanoseconds).
|
|
84
|
+
* @param maxDelayNs - Upper bound in nanoseconds (default `30s`).
|
|
85
|
+
* @returns `BackoffStrategy` for {@link retry}.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* import { fibonacci, retry, NS_PER_MS } from "@graphrefly/graphrefly-ts";
|
|
90
|
+
*
|
|
91
|
+
* // Delays: 100 ms, 200 ms, 300 ms, 500 ms, 800 ms … (× 100 ms base)
|
|
92
|
+
* const out = retry(source, { count: 5, backoff: fibonacci(100 * NS_PER_MS) });
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @category extra
|
|
96
|
+
*/
|
|
97
|
+
declare function fibonacci(baseNs?: number, maxDelayNs?: number): BackoffStrategy;
|
|
98
|
+
/**
|
|
99
|
+
* Decorrelated jitter (AWS-recommended): `random(baseNs, min(maxNs, lastDelay * 3))`.
|
|
100
|
+
*
|
|
101
|
+
* Stateless — uses `prevDelayNs` (passed by the consumer) instead of closure state.
|
|
102
|
+
* Safe to share across concurrent retry sequences.
|
|
103
|
+
*
|
|
104
|
+
* @param baseNs - Floor of the random range (default `100ms` in nanoseconds).
|
|
105
|
+
* @param maxNs - Ceiling cap (default `30s` in nanoseconds).
|
|
106
|
+
* @returns `BackoffStrategy` for {@link retry}.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* import { decorrelatedJitter, retry, NS_PER_MS, NS_PER_SEC } from "@graphrefly/graphrefly-ts";
|
|
111
|
+
*
|
|
112
|
+
* const out = retry(source, {
|
|
113
|
+
* count: 6,
|
|
114
|
+
* backoff: decorrelatedJitter(100 * NS_PER_MS, 10 * NS_PER_SEC),
|
|
115
|
+
* });
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @category extra
|
|
119
|
+
*/
|
|
120
|
+
declare function decorrelatedJitter(baseNs?: number, maxNs?: number): BackoffStrategy;
|
|
121
|
+
/**
|
|
122
|
+
* Decorator that caps any strategy at `maxAttempts`. Returns `null` (stop retrying) after the cap.
|
|
123
|
+
*
|
|
124
|
+
* @param strategy - Inner strategy to wrap.
|
|
125
|
+
* @param maxAttempts - Maximum number of attempts (inclusive).
|
|
126
|
+
* @returns Wrapped `BackoffStrategy`.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* import { withMaxAttempts, exponential } from "@graphrefly/graphrefly-ts";
|
|
131
|
+
*
|
|
132
|
+
* const capped = withMaxAttempts(exponential(), 3);
|
|
133
|
+
* capped(3); // null — no more retries beyond attempt 3
|
|
134
|
+
* ```
|
|
135
|
+
*
|
|
136
|
+
* @category extra
|
|
137
|
+
*/
|
|
138
|
+
declare function withMaxAttempts(strategy: BackoffStrategy, maxAttempts: number): BackoffStrategy;
|
|
139
|
+
/**
|
|
140
|
+
* Maps a preset name to a concrete {@link BackoffStrategy} with library-default parameters.
|
|
141
|
+
*
|
|
142
|
+
* @param name - One of `constant`, `linear`, `exponential`, `fibonacci`, or `decorrelatedJitter`.
|
|
143
|
+
* @returns Configured strategy with default parameters.
|
|
144
|
+
* @throws Error when `name` is not a known preset.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* import { resolveBackoffPreset, retry } from "@graphrefly/graphrefly-ts";
|
|
149
|
+
*
|
|
150
|
+
* const out = retry(source, { count: 3, backoff: resolveBackoffPreset("exponential") });
|
|
151
|
+
* // Equivalent to retry(source, { count: 3, backoff: exponential() })
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* @category extra
|
|
155
|
+
*/
|
|
156
|
+
declare function resolveBackoffPreset(name: BackoffPreset): BackoffStrategy;
|
|
157
|
+
|
|
158
|
+
type RetryOptions = {
|
|
159
|
+
/** Max retry attempts after each terminal `ERROR` (not counting the first failure). */
|
|
160
|
+
count?: number;
|
|
161
|
+
/** Delay between attempts; strategies use **nanoseconds**. */
|
|
162
|
+
backoff?: BackoffStrategy | BackoffPreset;
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* Resubscribes to the upstream node after each terminal `ERROR`, after an optional delay.
|
|
166
|
+
*
|
|
167
|
+
* @param source - Upstream node (should use `resubscribable: true`).
|
|
168
|
+
* @param opts - `count` caps attempts; `backoff` supplies delay in **nanoseconds** (or a preset name).
|
|
169
|
+
* @returns Node that retries on error.
|
|
170
|
+
*
|
|
171
|
+
* @remarks
|
|
172
|
+
* **Resubscribable sources:** The upstream should use `resubscribable: true` if it must emit again after `ERROR`.
|
|
173
|
+
* **Protocol:** Forwards unknown message tuples unchanged; handles `DIRTY`, `DATA`, `RESOLVED`, `COMPLETE`, `ERROR`.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* import { ERROR, NS_PER_SEC, pipe, producer, retry, constant } from "@graphrefly/graphrefly-ts";
|
|
178
|
+
*
|
|
179
|
+
* const src = producer(
|
|
180
|
+
* (_d, a) => {
|
|
181
|
+
* a.down([[ERROR, new Error("x")]]);
|
|
182
|
+
* },
|
|
183
|
+
* { resubscribable: true },
|
|
184
|
+
* );
|
|
185
|
+
* const out = retry(src, { count: 2, backoff: constant(0.25 * NS_PER_SEC) });
|
|
186
|
+
* ```
|
|
187
|
+
*
|
|
188
|
+
* @category extra
|
|
189
|
+
*/
|
|
190
|
+
declare function retry<T>(source: Node<T>, opts?: RetryOptions): Node<T>;
|
|
191
|
+
type CircuitState = "closed" | "open" | "half-open";
|
|
192
|
+
/**
|
|
193
|
+
* Thrown when {@link withBreaker} is configured with `onOpen: "error"` and the breaker rejects work.
|
|
194
|
+
*
|
|
195
|
+
* @category extra
|
|
196
|
+
*/
|
|
197
|
+
declare class CircuitOpenError extends Error {
|
|
198
|
+
name: string;
|
|
199
|
+
constructor();
|
|
200
|
+
}
|
|
201
|
+
interface CircuitBreakerOptions {
|
|
202
|
+
/** Number of consecutive failures before opening. Default: 5. */
|
|
203
|
+
failureThreshold?: number;
|
|
204
|
+
/** Base cooldown in nanoseconds before transitioning to half-open. Default: 30s. */
|
|
205
|
+
cooldownNs?: number;
|
|
206
|
+
/** Backoff strategy for cooldown escalation across consecutive open cycles. Overrides `cooldownNs` when provided. */
|
|
207
|
+
cooldown?: BackoffStrategy;
|
|
208
|
+
/** Max trial requests allowed in half-open state. Default: 1. */
|
|
209
|
+
halfOpenMax?: number;
|
|
210
|
+
/** Clock function returning nanoseconds (for testability). Default: `monotonicNs`. */
|
|
211
|
+
now?: () => number;
|
|
212
|
+
}
|
|
213
|
+
interface CircuitBreaker {
|
|
214
|
+
/** Whether a request should be allowed through. Triggers open→half-open transition when cooldown expires. */
|
|
215
|
+
canExecute(): boolean;
|
|
216
|
+
/** Record a successful execution. Resets to closed. */
|
|
217
|
+
recordSuccess(): void;
|
|
218
|
+
/** Record a failed execution. May transition to open. */
|
|
219
|
+
recordFailure(error?: unknown): void;
|
|
220
|
+
/** Current circuit state (read-only, does not trigger transitions). */
|
|
221
|
+
readonly state: CircuitState;
|
|
222
|
+
/** Number of consecutive failures in the current closed period. */
|
|
223
|
+
readonly failureCount: number;
|
|
224
|
+
/** Manually reset to closed state, clearing all counters. */
|
|
225
|
+
reset(): void;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Factory for a synchronous circuit breaker with `closed`, `open`, and `half-open` states.
|
|
229
|
+
*
|
|
230
|
+
* Supports escalating cooldown via an optional {@link BackoffStrategy} — each consecutive
|
|
231
|
+
* open→half-open→open cycle increments the backoff attempt.
|
|
232
|
+
*
|
|
233
|
+
* @param options - Threshold, cooldown, half-open limit, and optional clock override.
|
|
234
|
+
* @returns {@link CircuitBreaker} instance.
|
|
235
|
+
*
|
|
236
|
+
* @remarks
|
|
237
|
+
* **Timing:** Uses `monotonicNs()` by default (nanoseconds). Override `now` for tests.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```ts
|
|
241
|
+
* import { circuitBreaker, exponential, NS_PER_SEC } from "@graphrefly/graphrefly-ts";
|
|
242
|
+
*
|
|
243
|
+
* const b = circuitBreaker({
|
|
244
|
+
* failureThreshold: 3,
|
|
245
|
+
* cooldown: exponential({ baseNs: 1 * NS_PER_SEC }),
|
|
246
|
+
* });
|
|
247
|
+
* ```
|
|
248
|
+
*
|
|
249
|
+
* @category extra
|
|
250
|
+
*/
|
|
251
|
+
declare function circuitBreaker(options?: CircuitBreakerOptions): CircuitBreaker;
|
|
252
|
+
type WithBreakerBundle<T> = {
|
|
253
|
+
node: Node<T>;
|
|
254
|
+
breakerState: Node<CircuitState>;
|
|
255
|
+
};
|
|
256
|
+
/**
|
|
257
|
+
* Returns a unary wrapper that gates upstream `DATA` through a {@link CircuitBreaker}.
|
|
258
|
+
*
|
|
259
|
+
* @param breaker - Shared breaker instance (typically one per resource).
|
|
260
|
+
* @param options - `onOpen: "skip"` emits `RESOLVED` when open; `"error"` emits {@link CircuitOpenError}.
|
|
261
|
+
* @returns Function mapping `Node<T>` to `{ node, breakerState }` companion nodes.
|
|
262
|
+
*
|
|
263
|
+
* @remarks
|
|
264
|
+
* **Success path:** `COMPLETE` calls {@link CircuitBreaker.recordSuccess}. **Failure path:** upstream `ERROR` calls {@link CircuitBreaker.recordFailure} and is forwarded.
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```ts
|
|
268
|
+
* import { state, withBreaker, circuitBreaker } from "@graphrefly/graphrefly-ts";
|
|
269
|
+
*
|
|
270
|
+
* const b = circuitBreaker({ failureThreshold: 2 });
|
|
271
|
+
* const s = state(1);
|
|
272
|
+
* const { node, breakerState } = withBreaker(b)(s);
|
|
273
|
+
* ```
|
|
274
|
+
*
|
|
275
|
+
* @category extra
|
|
276
|
+
*/
|
|
277
|
+
declare function withBreaker<T>(breaker: CircuitBreaker, options?: {
|
|
278
|
+
onOpen?: "skip" | "error";
|
|
279
|
+
}): (source: Node<T>) => WithBreakerBundle<T>;
|
|
280
|
+
interface TokenBucket {
|
|
281
|
+
/** Number of tokens currently available (after refill). */
|
|
282
|
+
available(): number;
|
|
283
|
+
/** Try to consume `cost` tokens. Returns `true` if successful. */
|
|
284
|
+
tryConsume(cost?: number): boolean;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Token-bucket meter (capacity + refill rate per second). Use with {@link rateLimiter} or custom gates.
|
|
288
|
+
*
|
|
289
|
+
* @param capacity - Maximum tokens (must be positive).
|
|
290
|
+
* @param refillPerSecond - Tokens added per elapsed second (non-negative).
|
|
291
|
+
* @returns {@link TokenBucket} instance.
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* ```ts
|
|
295
|
+
* import { tokenBucket } from "@graphrefly/graphrefly-ts";
|
|
296
|
+
*
|
|
297
|
+
* const bucket = tokenBucket(10, 2); // capacity 10, refill 2 tokens/sec
|
|
298
|
+
* bucket.tryConsume(3); // true — 7 tokens remaining
|
|
299
|
+
* bucket.available(); // ~7 (plus any elapsed refill)
|
|
300
|
+
* ```
|
|
301
|
+
*
|
|
302
|
+
* @category extra
|
|
303
|
+
*/
|
|
304
|
+
declare function tokenBucket(capacity: number, refillPerSecond: number): TokenBucket;
|
|
305
|
+
/**
|
|
306
|
+
* Same behavior as {@link tokenBucket}. Exposed for naming parity with graphrefly-py (`token_tracker`).
|
|
307
|
+
*
|
|
308
|
+
* @param capacity - Maximum tokens (must be positive).
|
|
309
|
+
* @param refillPerSecond - Tokens added per elapsed second (non-negative).
|
|
310
|
+
* @returns A {@link TokenBucket} instance.
|
|
311
|
+
*
|
|
312
|
+
* @example
|
|
313
|
+
* ```ts
|
|
314
|
+
* import { tokenTracker } from "@graphrefly/graphrefly-ts";
|
|
315
|
+
*
|
|
316
|
+
* const tracker = tokenTracker(100, 10); // 100-token capacity, 10/sec refill
|
|
317
|
+
* tracker.tryConsume(5); // true
|
|
318
|
+
* ```
|
|
319
|
+
*
|
|
320
|
+
* @category extra
|
|
321
|
+
*/
|
|
322
|
+
declare function tokenTracker(capacity: number, refillPerSecond: number): TokenBucket;
|
|
323
|
+
/**
|
|
324
|
+
* Enforces a sliding window: at most `maxEvents` `DATA` values per `windowNs`.
|
|
325
|
+
*
|
|
326
|
+
* @param source - Upstream node.
|
|
327
|
+
* @param maxEvents - Maximum `DATA` emissions per window (must be positive).
|
|
328
|
+
* @param windowNs - Window length in nanoseconds (must be positive).
|
|
329
|
+
* @returns Node that queues excess values FIFO until a slot frees.
|
|
330
|
+
*
|
|
331
|
+
* @remarks
|
|
332
|
+
* **Terminal:** `COMPLETE` / `ERROR` cancel timers, drop pending queue, and clear window state.
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* ```ts
|
|
336
|
+
* import { rateLimiter, state, NS_PER_SEC } from "@graphrefly/graphrefly-ts";
|
|
337
|
+
*
|
|
338
|
+
* const src = state(0);
|
|
339
|
+
* // Allow at most 5 DATA values per second
|
|
340
|
+
* const limited = rateLimiter(src, 5, NS_PER_SEC);
|
|
341
|
+
* limited.subscribe((msgs) => console.log(msgs));
|
|
342
|
+
* ```
|
|
343
|
+
*
|
|
344
|
+
* @category extra
|
|
345
|
+
*/
|
|
346
|
+
declare function rateLimiter<T>(source: Node<T>, maxEvents: number, windowNs: number): Node<T>;
|
|
347
|
+
type StatusValue = "pending" | "active" | "completed" | "errored";
|
|
348
|
+
type WithStatusBundle<T> = {
|
|
349
|
+
node: Node<T>;
|
|
350
|
+
status: Node<StatusValue>;
|
|
351
|
+
error: Node<unknown | null>;
|
|
352
|
+
};
|
|
353
|
+
/**
|
|
354
|
+
* Wraps `src` with `status` and `error` {@link state} companions for UI or meta snapshots.
|
|
355
|
+
*
|
|
356
|
+
* @param src - Upstream node to mirror.
|
|
357
|
+
* @param options - `initialStatus` defaults to `"pending"`.
|
|
358
|
+
* @returns `{ node, status, error }` where `error` holds the last `ERROR` payload.
|
|
359
|
+
*
|
|
360
|
+
* @remarks
|
|
361
|
+
* **Recovery:** After `errored`, the next `DATA` clears `error` and sets `active` inside {@link batch} (matches graphrefly-py).
|
|
362
|
+
*
|
|
363
|
+
* @example
|
|
364
|
+
* ```ts
|
|
365
|
+
* import { withStatus, state } from "@graphrefly/graphrefly-ts";
|
|
366
|
+
*
|
|
367
|
+
* const src = state<number>(0);
|
|
368
|
+
* const { node, status, error } = withStatus(src);
|
|
369
|
+
*
|
|
370
|
+
* status.subscribe((msgs) => console.log("status:", msgs));
|
|
371
|
+
* src.down([[DATA, 42]]); // status → "active"
|
|
372
|
+
* ```
|
|
373
|
+
*
|
|
374
|
+
* @category extra
|
|
375
|
+
*/
|
|
376
|
+
declare function withStatus<T>(src: Node<T>, options?: {
|
|
377
|
+
initialStatus?: StatusValue;
|
|
378
|
+
}): WithStatusBundle<T>;
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Core reactive sources, sinks, and utilities (roadmap §2.3).
|
|
382
|
+
*
|
|
383
|
+
* Each API returns a {@link Node} built with {@link node}, {@link producer},
|
|
384
|
+
* {@link derived}, or {@link effect} — no second protocol.
|
|
385
|
+
*
|
|
386
|
+
* Protocol/system/ingest adapters (fromHTTP, fromWebSocket, fromKafka, etc.)
|
|
387
|
+
* live in {@link ./adapters.ts}.
|
|
388
|
+
*/
|
|
389
|
+
|
|
390
|
+
type ExtraOpts$2 = Omit<NodeOptions, "describeKind">;
|
|
391
|
+
/** Options for {@link fromTimer} / {@link fromPromise} / {@link fromAsyncIter}. */
|
|
392
|
+
type AsyncSourceOpts = ExtraOpts$2 & {
|
|
393
|
+
signal?: AbortSignal;
|
|
394
|
+
};
|
|
395
|
+
/**
|
|
396
|
+
* Values accepted by {@link fromAny}.
|
|
397
|
+
*
|
|
398
|
+
* @category extra
|
|
399
|
+
*/
|
|
400
|
+
type NodeInput<T> = Node<T> | PromiseLike<T> | AsyncIterable<T> | Iterable<T> | T;
|
|
401
|
+
/** Options for {@link fromCron}. */
|
|
402
|
+
type FromCronOptions = ExtraOpts$2 & {
|
|
403
|
+
/** Polling interval in ms. Default `60_000`. */
|
|
404
|
+
tickMs?: number;
|
|
405
|
+
/** Output format: `"timestamp_ns"` (default) emits wall-clock nanoseconds; `"date"` emits a `Date` object. */
|
|
406
|
+
output?: "timestamp_ns" | "date";
|
|
407
|
+
};
|
|
408
|
+
/** DOM-style event target (browser or `node:events`). */
|
|
409
|
+
type EventTargetLike = {
|
|
410
|
+
addEventListener(type: string, listener: (ev: unknown) => void, options?: boolean | {
|
|
411
|
+
capture?: boolean;
|
|
412
|
+
passive?: boolean;
|
|
413
|
+
once?: boolean;
|
|
414
|
+
}): void;
|
|
415
|
+
removeEventListener(type: string, listener: (ev: unknown) => void, options?: boolean | {
|
|
416
|
+
capture?: boolean;
|
|
417
|
+
passive?: boolean;
|
|
418
|
+
once?: boolean;
|
|
419
|
+
}): void;
|
|
420
|
+
};
|
|
421
|
+
type FSEventType = "change" | "rename" | "create" | "delete";
|
|
422
|
+
type FSEvent = {
|
|
423
|
+
type: FSEventType;
|
|
424
|
+
path: string;
|
|
425
|
+
root: string;
|
|
426
|
+
relative_path: string;
|
|
427
|
+
src_path?: string;
|
|
428
|
+
dest_path?: string;
|
|
429
|
+
timestamp_ns: number;
|
|
430
|
+
};
|
|
431
|
+
type FromFSWatchOptions = ExtraOpts$2 & {
|
|
432
|
+
recursive?: boolean;
|
|
433
|
+
debounce?: number;
|
|
434
|
+
include?: string[];
|
|
435
|
+
exclude?: string[];
|
|
436
|
+
};
|
|
437
|
+
/** @internal Shared with adapters.ts for glob matching in fromFSWatch / fromGitHook. */
|
|
438
|
+
declare function escapeRegexChar(ch: string): string;
|
|
439
|
+
/** @internal */
|
|
440
|
+
declare function globToRegExp(glob: string): RegExp;
|
|
441
|
+
/** @internal */
|
|
442
|
+
declare function matchesAnyPattern(path: string, patterns: RegExp[]): boolean;
|
|
443
|
+
/**
|
|
444
|
+
* Builds a timer-driven source: one-shot (first tick then `COMPLETE`) or periodic (`0`, `1`, `2`, …).
|
|
445
|
+
*
|
|
446
|
+
* @param ms - Milliseconds before the first emission.
|
|
447
|
+
* @param opts - Producer options plus optional `period` for repeating ticks and optional `signal` (`AbortSignal`) to cancel with `ERROR`.
|
|
448
|
+
* @returns `Node<number>` — tick counter from `0`; teardown clears timers.
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* ```ts
|
|
452
|
+
* import { fromTimer } from "@graphrefly/graphrefly-ts";
|
|
453
|
+
*
|
|
454
|
+
* fromTimer(250, { period: 1_000 });
|
|
455
|
+
* ```
|
|
456
|
+
*
|
|
457
|
+
* @category extra
|
|
458
|
+
*/
|
|
459
|
+
declare function fromTimer(ms: number, opts?: AsyncSourceOpts & {
|
|
460
|
+
period?: number;
|
|
461
|
+
}): Node<number>;
|
|
462
|
+
/**
|
|
463
|
+
* Polls on an interval; when the current minute matches a 5-field cron expression, emits once (see {@link parseCron}).
|
|
464
|
+
*
|
|
465
|
+
* @param expr - Cron string (`min hour dom month dow`).
|
|
466
|
+
* @param opts - Producer options plus `tickMs` (default `60_000`) and `output` (`timestamp_ns` default, or `date` for `Date` values).
|
|
467
|
+
* @returns `Node<number>` (nanosecond timestamp) or `Node<Date>` when `output: "date"`.
|
|
468
|
+
*
|
|
469
|
+
* @example
|
|
470
|
+
* ```ts
|
|
471
|
+
* import { fromCron } from "@graphrefly/graphrefly-ts";
|
|
472
|
+
*
|
|
473
|
+
* fromCron("0 9 * * 1");
|
|
474
|
+
* ```
|
|
475
|
+
*
|
|
476
|
+
* @category extra
|
|
477
|
+
*/
|
|
478
|
+
declare function fromCron(expr: string, opts?: FromCronOptions & {
|
|
479
|
+
output: "date";
|
|
480
|
+
}): Node<Date>;
|
|
481
|
+
declare function fromCron(expr: string, opts?: FromCronOptions): Node<number>;
|
|
482
|
+
/**
|
|
483
|
+
* Wraps a DOM-style `addEventListener` target; each event becomes a `DATA` emission.
|
|
484
|
+
*
|
|
485
|
+
* @param target - Object with `addEventListener` / `removeEventListener`.
|
|
486
|
+
* @param type - Event name (e.g. `"click"`).
|
|
487
|
+
* @param opts - Producer options plus listener options (`capture`, `passive`, `once`).
|
|
488
|
+
* @returns `Node<T>` — event payloads; teardown removes the listener.
|
|
489
|
+
*
|
|
490
|
+
* @example
|
|
491
|
+
* ```ts
|
|
492
|
+
* import { fromEvent } from "@graphrefly/graphrefly-ts";
|
|
493
|
+
*
|
|
494
|
+
* fromEvent(document.body, "click");
|
|
495
|
+
* ```
|
|
496
|
+
*
|
|
497
|
+
* @category extra
|
|
498
|
+
*/
|
|
499
|
+
declare function fromEvent<T = unknown>(target: EventTargetLike, type: string, opts?: ExtraOpts$2 & {
|
|
500
|
+
capture?: boolean;
|
|
501
|
+
passive?: boolean;
|
|
502
|
+
once?: boolean;
|
|
503
|
+
}): Node<T>;
|
|
504
|
+
/**
|
|
505
|
+
* Watches filesystem paths and emits debounced change events.
|
|
506
|
+
*
|
|
507
|
+
* Uses `fs.watch` only (no polling fallback). Teardown closes all watchers.
|
|
508
|
+
*
|
|
509
|
+
* @category extra
|
|
510
|
+
*/
|
|
511
|
+
declare function fromFSWatch(paths: string | string[], opts?: FromFSWatchOptions): Node<FSEvent>;
|
|
512
|
+
/**
|
|
513
|
+
* Drains a synchronous iterable; each item is `DATA`, then `COMPLETE`, or `ERROR` if iteration throws.
|
|
514
|
+
*
|
|
515
|
+
* @param iterable - Values to emit in order.
|
|
516
|
+
* @param opts - Optional producer options.
|
|
517
|
+
* @returns `Node<T>` — one emission per element.
|
|
518
|
+
*
|
|
519
|
+
* @example
|
|
520
|
+
* ```ts
|
|
521
|
+
* import { fromIter } from "@graphrefly/graphrefly-ts";
|
|
522
|
+
*
|
|
523
|
+
* fromIter([1, 2, 3]);
|
|
524
|
+
* ```
|
|
525
|
+
*
|
|
526
|
+
* @category extra
|
|
527
|
+
*/
|
|
528
|
+
declare function fromIter<T>(iterable: Iterable<T>, opts?: ExtraOpts$2): Node<T>;
|
|
529
|
+
/**
|
|
530
|
+
* Lifts a Promise (or thenable) to a single-value stream: one `DATA` then `COMPLETE`, or `ERROR` on rejection.
|
|
531
|
+
*
|
|
532
|
+
* @param p - Promise to await.
|
|
533
|
+
* @param opts - Producer options plus optional `signal` for abort → `ERROR` with reason.
|
|
534
|
+
* @returns `Node<T>` — settles once.
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
* ```ts
|
|
538
|
+
* import { fromPromise } from "@graphrefly/graphrefly-ts";
|
|
539
|
+
*
|
|
540
|
+
* fromPromise(Promise.resolve(42));
|
|
541
|
+
* ```
|
|
542
|
+
*
|
|
543
|
+
* @category extra
|
|
544
|
+
*/
|
|
545
|
+
declare function fromPromise<T>(p: Promise<T> | PromiseLike<T>, opts?: AsyncSourceOpts): Node<T>;
|
|
546
|
+
/**
|
|
547
|
+
* Reads an async iterable; each `next()` value becomes `DATA`; `COMPLETE` when done; `ERROR` on failure.
|
|
548
|
+
*
|
|
549
|
+
* @param iterable - Async source (`for await` shape).
|
|
550
|
+
* @param opts - Producer options plus optional `signal` to abort the pump.
|
|
551
|
+
* @returns `Node<T>` — async pull stream.
|
|
552
|
+
*
|
|
553
|
+
* @example
|
|
554
|
+
* ```ts
|
|
555
|
+
* import { fromAsyncIter } from "@graphrefly/graphrefly-ts";
|
|
556
|
+
*
|
|
557
|
+
* async function* gen() {
|
|
558
|
+
* yield 1;
|
|
559
|
+
* }
|
|
560
|
+
* fromAsyncIter(gen());
|
|
561
|
+
* ```
|
|
562
|
+
*
|
|
563
|
+
* @category extra
|
|
564
|
+
*/
|
|
565
|
+
declare function fromAsyncIter<T>(iterable: AsyncIterable<T>, opts?: AsyncSourceOpts): Node<T>;
|
|
566
|
+
/**
|
|
567
|
+
* Coerces a value to a `Node` by shape: existing `Node` passthrough, thenable → {@link fromPromise},
|
|
568
|
+
* async iterable → {@link fromAsyncIter}, sync iterable → {@link fromIter}, else scalar → {@link of}.
|
|
569
|
+
*
|
|
570
|
+
* @param input - Any value to wrap.
|
|
571
|
+
* @param opts - Passed through when a Promise/async path is chosen.
|
|
572
|
+
* @returns `Node` of the inferred element type.
|
|
573
|
+
*
|
|
574
|
+
* @example
|
|
575
|
+
* ```ts
|
|
576
|
+
* import { fromAny, state } from "@graphrefly/graphrefly-ts";
|
|
577
|
+
*
|
|
578
|
+
* fromAny(state(1));
|
|
579
|
+
* fromAny(Promise.resolve(2));
|
|
580
|
+
* ```
|
|
581
|
+
*
|
|
582
|
+
* @category extra
|
|
583
|
+
*/
|
|
584
|
+
declare function fromAny<T>(input: NodeInput<T>, opts?: AsyncSourceOpts): Node<T>;
|
|
585
|
+
/**
|
|
586
|
+
* Emits each argument as `DATA` in order, then `COMPLETE` (implemented via {@link fromIter}).
|
|
587
|
+
*
|
|
588
|
+
* @param values - Values to emit.
|
|
589
|
+
* @returns `Node<T>` — finite sequence.
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* ```ts
|
|
593
|
+
* import { of } from "@graphrefly/graphrefly-ts";
|
|
594
|
+
*
|
|
595
|
+
* of(1, 2, 3);
|
|
596
|
+
* ```
|
|
597
|
+
*
|
|
598
|
+
* @category extra
|
|
599
|
+
*/
|
|
600
|
+
declare function of<T>(...values: T[]): Node<T>;
|
|
601
|
+
/**
|
|
602
|
+
* Completes immediately with no `DATA` (cold `EMPTY` analogue).
|
|
603
|
+
*
|
|
604
|
+
* @param opts - Optional producer options.
|
|
605
|
+
* @returns `Node<T>` — terminal `COMPLETE` only.
|
|
606
|
+
*
|
|
607
|
+
* @example
|
|
608
|
+
* ```ts
|
|
609
|
+
* import { empty } from "@graphrefly/graphrefly-ts";
|
|
610
|
+
*
|
|
611
|
+
* empty();
|
|
612
|
+
* ```
|
|
613
|
+
*
|
|
614
|
+
* @category extra
|
|
615
|
+
*/
|
|
616
|
+
declare function empty<T = never>(opts?: ExtraOpts$2): Node<T>;
|
|
617
|
+
/**
|
|
618
|
+
* Never emits and never completes until teardown (cold `NEVER` analogue).
|
|
619
|
+
*
|
|
620
|
+
* @param opts - Optional producer options.
|
|
621
|
+
* @returns `Node<T>` — silent until unsubscribed.
|
|
622
|
+
*
|
|
623
|
+
* @example
|
|
624
|
+
* ```ts
|
|
625
|
+
* import { never } from "@graphrefly/graphrefly-ts";
|
|
626
|
+
*
|
|
627
|
+
* never();
|
|
628
|
+
* ```
|
|
629
|
+
*
|
|
630
|
+
* @category extra
|
|
631
|
+
*/
|
|
632
|
+
declare function never<T = never>(opts?: ExtraOpts$2): Node<T>;
|
|
633
|
+
/**
|
|
634
|
+
* Emits `ERROR` as soon as the producer starts (cold error source).
|
|
635
|
+
*
|
|
636
|
+
* @param err - Error payload forwarded as `ERROR` data.
|
|
637
|
+
* @param opts - Optional producer options.
|
|
638
|
+
* @returns `Node<never>` — terminates with `ERROR`.
|
|
639
|
+
*
|
|
640
|
+
* @example
|
|
641
|
+
* ```ts
|
|
642
|
+
* import { throwError } from "@graphrefly/graphrefly-ts";
|
|
643
|
+
*
|
|
644
|
+
* throwError(new Error("fail"));
|
|
645
|
+
* ```
|
|
646
|
+
*
|
|
647
|
+
* @category extra
|
|
648
|
+
*/
|
|
649
|
+
declare function throwError(err: unknown, opts?: ExtraOpts$2): Node<never>;
|
|
650
|
+
/**
|
|
651
|
+
* Subscribes immediately and runs `fn` for each upstream `DATA`; returns unsubscribe.
|
|
652
|
+
*
|
|
653
|
+
* @param source - Upstream node.
|
|
654
|
+
* @param fn - Side effect per value.
|
|
655
|
+
* @param opts - Effect node options.
|
|
656
|
+
* @returns Unsubscribe function (idempotent).
|
|
657
|
+
*
|
|
658
|
+
* @example
|
|
659
|
+
* ```ts
|
|
660
|
+
* import { forEach, state } from "@graphrefly/graphrefly-ts";
|
|
661
|
+
*
|
|
662
|
+
* const u = forEach(state(1), (v) => console.log(v));
|
|
663
|
+
* u();
|
|
664
|
+
* ```
|
|
665
|
+
*
|
|
666
|
+
* @category extra
|
|
667
|
+
*/
|
|
668
|
+
declare function forEach<T>(source: Node<T>, fn: (value: T) => void, opts?: ExtraOpts$2): () => void;
|
|
669
|
+
/**
|
|
670
|
+
* Buffers every `DATA`; on upstream `COMPLETE` emits one `DATA` with the full array then `COMPLETE`.
|
|
671
|
+
*
|
|
672
|
+
* @param source - Upstream node.
|
|
673
|
+
* @param opts - Optional node options (operator describe kind).
|
|
674
|
+
* @returns `Node<T[]>` — single array emission before completion.
|
|
675
|
+
*
|
|
676
|
+
* @example
|
|
677
|
+
* ```ts
|
|
678
|
+
* import { of, toArray } from "@graphrefly/graphrefly-ts";
|
|
679
|
+
*
|
|
680
|
+
* toArray(of(1, 2, 3));
|
|
681
|
+
* ```
|
|
682
|
+
*
|
|
683
|
+
* @category extra
|
|
684
|
+
*/
|
|
685
|
+
declare function toArray<T>(source: Node<T>, opts?: ExtraOpts$2): Node<T[]>;
|
|
686
|
+
/**
|
|
687
|
+
* Multicasts upstream: one subscription to `source` while this wrapper has subscribers (via {@link producer}).
|
|
688
|
+
*
|
|
689
|
+
* @param source - Upstream node to share.
|
|
690
|
+
* @param opts - Producer options; `initial` seeds from `source.get()` when set by factory.
|
|
691
|
+
* @returns `Node<T>` — hot ref-counted bridge.
|
|
692
|
+
*
|
|
693
|
+
* @example
|
|
694
|
+
* ```ts
|
|
695
|
+
* import { share, state } from "@graphrefly/graphrefly-ts";
|
|
696
|
+
*
|
|
697
|
+
* share(state(0));
|
|
698
|
+
* ```
|
|
699
|
+
*
|
|
700
|
+
* @category extra
|
|
701
|
+
*/
|
|
702
|
+
declare function share<T>(source: Node<T>, opts?: ExtraOpts$2): Node<T>;
|
|
703
|
+
/**
|
|
704
|
+
* Like {@link share} with a bounded replay buffer: new subscribers receive the last `bufferSize`
|
|
705
|
+
* `DATA` payloads (as separate batches) before live updates.
|
|
706
|
+
*
|
|
707
|
+
* @param source - Upstream node.
|
|
708
|
+
* @param bufferSize - Maximum past values to replay (≥ 1).
|
|
709
|
+
* @param opts - Producer options.
|
|
710
|
+
* @returns `Node<T>` — multicast with replay on subscribe.
|
|
711
|
+
*
|
|
712
|
+
* @example
|
|
713
|
+
* ```ts
|
|
714
|
+
* import { replay, state } from "@graphrefly/graphrefly-ts";
|
|
715
|
+
*
|
|
716
|
+
* replay(state(0), 3);
|
|
717
|
+
* ```
|
|
718
|
+
*
|
|
719
|
+
* @category extra
|
|
720
|
+
*/
|
|
721
|
+
declare function replay<T>(source: Node<T>, bufferSize: number, opts?: ExtraOpts$2): Node<T>;
|
|
722
|
+
/**
|
|
723
|
+
* {@link replay} with `bufferSize === 1` — replays the latest `DATA` to new subscribers.
|
|
724
|
+
*
|
|
725
|
+
* @param source - Upstream node.
|
|
726
|
+
* @param opts - Producer options.
|
|
727
|
+
* @returns `Node<T>` — share + last-value replay.
|
|
728
|
+
*
|
|
729
|
+
* @example
|
|
730
|
+
* ```ts
|
|
731
|
+
* import { cached, state } from "@graphrefly/graphrefly-ts";
|
|
732
|
+
*
|
|
733
|
+
* cached(state(0));
|
|
734
|
+
* ```
|
|
735
|
+
*
|
|
736
|
+
* @category extra
|
|
737
|
+
*/
|
|
738
|
+
declare function cached<T>(source: Node<T>, opts?: ExtraOpts$2): Node<T>;
|
|
739
|
+
/**
|
|
740
|
+
* Converts the first `DATA` on `source` into a Promise; rejects on `ERROR` or `COMPLETE` without data.
|
|
741
|
+
*
|
|
742
|
+
* @param source - Node to read once.
|
|
743
|
+
* @returns Promise of the first value.
|
|
744
|
+
*
|
|
745
|
+
* @example
|
|
746
|
+
* ```ts
|
|
747
|
+
* import { firstValueFrom, of } from "@graphrefly/graphrefly-ts";
|
|
748
|
+
*
|
|
749
|
+
* await firstValueFrom(of(42));
|
|
750
|
+
* ```
|
|
751
|
+
*
|
|
752
|
+
* @category extra
|
|
753
|
+
*/
|
|
754
|
+
declare function firstValueFrom<T>(source: Node<T>): Promise<T>;
|
|
755
|
+
/**
|
|
756
|
+
* RxJS-named alias for {@link replay} — multicast with a replay buffer of size `bufferSize`.
|
|
757
|
+
*
|
|
758
|
+
* @param source - Upstream node.
|
|
759
|
+
* @param bufferSize - Replay depth (≥ 1).
|
|
760
|
+
* @param opts - Producer options.
|
|
761
|
+
* @returns Same behavior as `replay`.
|
|
762
|
+
*
|
|
763
|
+
* @example
|
|
764
|
+
* ```ts
|
|
765
|
+
* import { shareReplay, state } from "@graphrefly/graphrefly-ts";
|
|
766
|
+
*
|
|
767
|
+
* shareReplay(state(0), 5);
|
|
768
|
+
* ```
|
|
769
|
+
*
|
|
770
|
+
* @category extra
|
|
771
|
+
*/
|
|
772
|
+
declare const shareReplay: typeof replay;
|
|
773
|
+
|
|
774
|
+
/**
|
|
775
|
+
* Protocol, system, and ingest adapters (roadmap §5.2, §5.2c).
|
|
776
|
+
*
|
|
777
|
+
* Each adapter wraps an external protocol or system as a reactive {@link Node}
|
|
778
|
+
* built on {@link producer} / {@link node} — no second protocol.
|
|
779
|
+
*
|
|
780
|
+
* **Moved from sources.ts:** fromHTTP, fromWebSocket/toWebSocket, fromWebhook,
|
|
781
|
+
* toSSE, fromMCP, fromGitHook.
|
|
782
|
+
*
|
|
783
|
+
* **New (5.2c):** fromOTel, fromSyslog, fromStatsD, fromPrometheus,
|
|
784
|
+
* fromKafka/toKafka, fromRedisStream/toRedisStream, fromCSV, fromNDJSON,
|
|
785
|
+
* fromClickHouseWatch.
|
|
786
|
+
*/
|
|
787
|
+
|
|
788
|
+
/** Structured callback for sink transport failures (Kafka, Redis, etc.). */
|
|
789
|
+
type SinkTransportError = {
|
|
790
|
+
stage: "serialize" | "send";
|
|
791
|
+
error: Error;
|
|
792
|
+
value: unknown;
|
|
793
|
+
};
|
|
794
|
+
type ExtraOpts$1 = Omit<NodeOptions, "describeKind">;
|
|
795
|
+
/** WebSocket-like transport accepted by {@link fromWebSocket} / {@link toWebSocket}. */
|
|
796
|
+
type WebSocketLike = {
|
|
797
|
+
send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
|
|
798
|
+
close(code?: number, reason?: string): void;
|
|
799
|
+
addEventListener(type: "message" | "error" | "close", listener: (ev: unknown) => void): void;
|
|
800
|
+
removeEventListener(type: "message" | "error" | "close", listener: (ev: unknown) => void): void;
|
|
801
|
+
};
|
|
802
|
+
type WebSocketMessageEventLike = {
|
|
803
|
+
data: unknown;
|
|
804
|
+
};
|
|
805
|
+
type WebSocketRegister<T> = (emit: (payload: T) => void, error: (err: unknown) => void, complete: () => void) => () => void;
|
|
806
|
+
/**
|
|
807
|
+
* Wraps a WebSocket as a GraphReFly producer source.
|
|
808
|
+
*
|
|
809
|
+
* Incoming socket messages are emitted as `DATA`; socket `error` emits `ERROR`; socket `close`
|
|
810
|
+
* emits `COMPLETE`. Teardown detaches listeners and optionally closes the socket.
|
|
811
|
+
*
|
|
812
|
+
* @category extra
|
|
813
|
+
*/
|
|
814
|
+
declare function fromWebSocket<T = unknown>(socket: WebSocketLike, opts?: ExtraOpts$1 & {
|
|
815
|
+
parse?: (payload: unknown, event: unknown) => T;
|
|
816
|
+
closeOnTeardown?: boolean;
|
|
817
|
+
}): Node<T>;
|
|
818
|
+
declare function fromWebSocket<T = unknown>(register: WebSocketRegister<T>, opts?: ExtraOpts$1 & {
|
|
819
|
+
parse?: (payload: unknown, event: unknown) => T;
|
|
820
|
+
closeOnTeardown?: boolean;
|
|
821
|
+
}): Node<T>;
|
|
822
|
+
/** Registration callback for {@link fromWebhook}. */
|
|
823
|
+
type WebhookRegister<T> = (handlers: {
|
|
824
|
+
/** Push one webhook payload downstream as `[[DATA, payload]]`. */
|
|
825
|
+
emit: (payload: T) => void;
|
|
826
|
+
/** Push terminal error as `[[ERROR, err]]`. */
|
|
827
|
+
error: (err: unknown) => void;
|
|
828
|
+
/** Push terminal completion as `[[COMPLETE]]`. */
|
|
829
|
+
complete: () => void;
|
|
830
|
+
}) => (() => void) | undefined;
|
|
831
|
+
/**
|
|
832
|
+
* Bridges HTTP webhook callbacks into a GraphReFly source.
|
|
833
|
+
*
|
|
834
|
+
* The `register` callback wires your runtime/framework callback to GraphReFly and may return a
|
|
835
|
+
* cleanup function. This keeps the adapter runtime-agnostic while following the same producer
|
|
836
|
+
* pattern as {@link fromEvent}.
|
|
837
|
+
*
|
|
838
|
+
* @param register - Registers webhook handlers (`emit`, `error`, `complete`) and optionally returns cleanup.
|
|
839
|
+
* @param opts - Optional producer options.
|
|
840
|
+
* @returns `Node<T>` — webhook payloads as `DATA`; teardown runs returned cleanup.
|
|
841
|
+
*
|
|
842
|
+
* @example
|
|
843
|
+
* ```ts
|
|
844
|
+
* import express from "express";
|
|
845
|
+
* import { fromWebhook } from "@graphrefly/graphrefly-ts";
|
|
846
|
+
*
|
|
847
|
+
* type HookPayload = { event: string; data: unknown };
|
|
848
|
+
* const app = express();
|
|
849
|
+
* app.use(express.json());
|
|
850
|
+
*
|
|
851
|
+
* const hook$ = fromWebhook<HookPayload>(({ emit, error }) => {
|
|
852
|
+
* const handler = (req: express.Request, res: express.Response) => {
|
|
853
|
+
* try {
|
|
854
|
+
* emit(req.body as HookPayload);
|
|
855
|
+
* res.status(200).send("ok");
|
|
856
|
+
* } catch (e) {
|
|
857
|
+
* error(e);
|
|
858
|
+
* res.status(500).send("error");
|
|
859
|
+
* }
|
|
860
|
+
* };
|
|
861
|
+
* app.post("/webhook", handler);
|
|
862
|
+
* return () => {
|
|
863
|
+
* // Express has no direct route-removal API in common use.
|
|
864
|
+
* };
|
|
865
|
+
* });
|
|
866
|
+
* ```
|
|
867
|
+
*
|
|
868
|
+
* @example Fastify
|
|
869
|
+
* ```ts
|
|
870
|
+
* import Fastify from "fastify";
|
|
871
|
+
* import { fromWebhook } from "@graphrefly/graphrefly-ts";
|
|
872
|
+
*
|
|
873
|
+
* const fastify = Fastify();
|
|
874
|
+
* const hook$ = fromWebhook<any>(({ emit, error }) => {
|
|
875
|
+
* const handler = async (req: any, reply: any) => {
|
|
876
|
+
* try {
|
|
877
|
+
* emit(req.body);
|
|
878
|
+
* reply.code(200).send({ ok: true });
|
|
879
|
+
* } catch (e) {
|
|
880
|
+
* error(e);
|
|
881
|
+
* reply.code(500).send({ ok: false });
|
|
882
|
+
* }
|
|
883
|
+
* };
|
|
884
|
+
* fastify.post("/webhook", handler);
|
|
885
|
+
* return () => {};
|
|
886
|
+
* });
|
|
887
|
+
* ```
|
|
888
|
+
*
|
|
889
|
+
* @category extra
|
|
890
|
+
*/
|
|
891
|
+
declare function fromWebhook<T = unknown>(register: WebhookRegister<T>, opts?: ExtraOpts$1): Node<T>;
|
|
892
|
+
/**
|
|
893
|
+
* Options for {@link fromHTTP}.
|
|
894
|
+
*
|
|
895
|
+
* @category extra
|
|
896
|
+
*/
|
|
897
|
+
interface FromHTTPOptions extends AsyncSourceOpts {
|
|
898
|
+
/** HTTP method. Default: `"GET"`. */
|
|
899
|
+
method?: string;
|
|
900
|
+
/** Request headers. */
|
|
901
|
+
headers?: Record<string, string>;
|
|
902
|
+
/** Request body (for POST/PUT/PATCH). */
|
|
903
|
+
body?: any;
|
|
904
|
+
/** Transform the Response before emitting. Default: `response.json()`. */
|
|
905
|
+
transform?: (response: Response) => any | Promise<any>;
|
|
906
|
+
/** Request timeout in **nanoseconds**. Default: `30s` (30 * NS_PER_SEC). */
|
|
907
|
+
timeoutNs?: number;
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* Result of {@link fromHTTP}: main source plus status, error, and fetch count companions.
|
|
911
|
+
*
|
|
912
|
+
* @category extra
|
|
913
|
+
*/
|
|
914
|
+
type HTTPBundle<T> = WithStatusBundle<T> & {
|
|
915
|
+
/** Number of successful fetches. */
|
|
916
|
+
fetchCount: Node<number>;
|
|
917
|
+
/** Nanosecond wall-clock timestamp of the last successful fetch. */
|
|
918
|
+
lastUpdated: Node<number>;
|
|
919
|
+
};
|
|
920
|
+
/**
|
|
921
|
+
* Creates a one-shot fetch-based HTTP source with lifecycle tracking.
|
|
922
|
+
*
|
|
923
|
+
* @category extra
|
|
924
|
+
*/
|
|
925
|
+
declare function fromHTTP<T = any>(url: string, opts?: FromHTTPOptions): HTTPBundle<T>;
|
|
926
|
+
/** Options for {@link toSSE}. */
|
|
927
|
+
type ToSSEOptions = {
|
|
928
|
+
/** Custom payload serializer for non-string payloads. Default: `JSON.stringify` fallback to `String(value)`. */
|
|
929
|
+
serialize?: (value: unknown) => string;
|
|
930
|
+
/** Event name for DATA tuples. Default: `"data"`. */
|
|
931
|
+
dataEvent?: string;
|
|
932
|
+
/** Event name for ERROR tuples. Default: `"error"`. */
|
|
933
|
+
errorEvent?: string;
|
|
934
|
+
/** Event name for COMPLETE tuples. Default: `"complete"`. */
|
|
935
|
+
completeEvent?: string;
|
|
936
|
+
/** Emit `event: resolved` when RESOLVED arrives. Default: `false`. */
|
|
937
|
+
includeResolved?: boolean;
|
|
938
|
+
/** Emit `event: dirty` when DIRTY arrives. Default: `false`. */
|
|
939
|
+
includeDirty?: boolean;
|
|
940
|
+
/** Add SSE comment keepalive frames (`: keepalive`) on an interval. Disabled when unset. */
|
|
941
|
+
keepAliveMs?: number;
|
|
942
|
+
/** Optional abort signal to terminate the stream early. */
|
|
943
|
+
signal?: AbortSignal;
|
|
944
|
+
/** Maps custom message types to SSE event names. */
|
|
945
|
+
eventNameResolver?: (type: symbol) => string;
|
|
946
|
+
};
|
|
947
|
+
/**
|
|
948
|
+
* Creates a standard Server-Sent Events stream from node messages.
|
|
949
|
+
*
|
|
950
|
+
* @category extra
|
|
951
|
+
*/
|
|
952
|
+
declare function toSSE<T>(source: Node<T>, opts?: ToSSEOptions): ReadableStream<Uint8Array>;
|
|
953
|
+
/** Options for {@link toWebSocket}. */
|
|
954
|
+
type ToWebSocketOptions<T> = {
|
|
955
|
+
/** Serialize DATA payloads before `socket.send(...)`. */
|
|
956
|
+
serialize?: (value: T) => string | ArrayBufferLike | Blob | ArrayBufferView;
|
|
957
|
+
/** Close socket when upstream emits COMPLETE. Default: `true`. */
|
|
958
|
+
closeOnComplete?: boolean;
|
|
959
|
+
/** Close socket when upstream emits ERROR. Default: `true`. */
|
|
960
|
+
closeOnError?: boolean;
|
|
961
|
+
/** Optional close code used when close is triggered by terminal tuples. */
|
|
962
|
+
closeCode?: number;
|
|
963
|
+
/** Optional close reason used when close is triggered by terminal tuples. */
|
|
964
|
+
closeReason?: string;
|
|
965
|
+
/** Structured callback for serialize/send/close transport failures. */
|
|
966
|
+
onTransportError?: (event: ToWebSocketTransportError) => void;
|
|
967
|
+
};
|
|
968
|
+
type ToWebSocketTransportError = {
|
|
969
|
+
stage: "serialize" | "send" | "close";
|
|
970
|
+
error: Error;
|
|
971
|
+
message: Message | undefined;
|
|
972
|
+
};
|
|
973
|
+
/**
|
|
974
|
+
* Forwards upstream `DATA` payloads to a WebSocket via `send`.
|
|
975
|
+
*
|
|
976
|
+
* @category extra
|
|
977
|
+
*/
|
|
978
|
+
declare function toWebSocket<T>(source: Node<T>, socket: WebSocketLike, opts?: ToWebSocketOptions<T>): () => void;
|
|
979
|
+
/**
|
|
980
|
+
* Duck-typed MCP (Model Context Protocol) client — only the notification
|
|
981
|
+
* registration surface is required so callers are not coupled to a specific SDK.
|
|
982
|
+
*/
|
|
983
|
+
type MCPClientLike = {
|
|
984
|
+
setNotificationHandler(method: string, handler: (notification: unknown) => void): void;
|
|
985
|
+
};
|
|
986
|
+
/** Options for {@link fromMCP}. */
|
|
987
|
+
type FromMCPOptions = ExtraOpts$1 & {
|
|
988
|
+
/** MCP notification method to subscribe to. Default `"notifications/message"`. */
|
|
989
|
+
method?: string;
|
|
990
|
+
onDisconnect?: (cb: (err?: unknown) => void) => void;
|
|
991
|
+
};
|
|
992
|
+
/**
|
|
993
|
+
* Wraps an MCP client's server-push notifications as a reactive source.
|
|
994
|
+
*
|
|
995
|
+
* @category extra
|
|
996
|
+
*/
|
|
997
|
+
declare function fromMCP<T = unknown>(client: MCPClientLike, opts?: FromMCPOptions): Node<T>;
|
|
998
|
+
/** Git hook type for {@link fromGitHook}. */
|
|
999
|
+
type GitHookType = "post-commit" | "post-merge" | "post-checkout" | "post-rewrite";
|
|
1000
|
+
/** Structured git event emitted by {@link fromGitHook}. */
|
|
1001
|
+
type GitEvent = {
|
|
1002
|
+
hook: GitHookType;
|
|
1003
|
+
commit: string;
|
|
1004
|
+
files: string[];
|
|
1005
|
+
message: string;
|
|
1006
|
+
author: string;
|
|
1007
|
+
timestamp_ns: number;
|
|
1008
|
+
};
|
|
1009
|
+
/** Options for {@link fromGitHook}. */
|
|
1010
|
+
type FromGitHookOptions = ExtraOpts$1 & {
|
|
1011
|
+
pollMs?: number;
|
|
1012
|
+
include?: string[];
|
|
1013
|
+
exclude?: string[];
|
|
1014
|
+
};
|
|
1015
|
+
/**
|
|
1016
|
+
* Git change detection as a reactive source.
|
|
1017
|
+
*
|
|
1018
|
+
* @category extra
|
|
1019
|
+
*/
|
|
1020
|
+
declare function fromGitHook(repoPath: string, opts?: FromGitHookOptions): Node<GitEvent>;
|
|
1021
|
+
/** Standard handler triple for adapters that accept injected registrations. */
|
|
1022
|
+
type AdapterHandlers<T> = {
|
|
1023
|
+
emit: (payload: T) => void;
|
|
1024
|
+
error: (err: unknown) => void;
|
|
1025
|
+
complete: () => void;
|
|
1026
|
+
};
|
|
1027
|
+
/** Structured OTel span. */
|
|
1028
|
+
type OTelSpan = {
|
|
1029
|
+
traceId: string;
|
|
1030
|
+
spanId: string;
|
|
1031
|
+
operationName: string;
|
|
1032
|
+
serviceName: string;
|
|
1033
|
+
startTimeNs: number;
|
|
1034
|
+
endTimeNs: number;
|
|
1035
|
+
status: "OK" | "ERROR" | "UNSET";
|
|
1036
|
+
attributes: Record<string, unknown>;
|
|
1037
|
+
events: Array<{
|
|
1038
|
+
name: string;
|
|
1039
|
+
timestampNs: number;
|
|
1040
|
+
attributes?: Record<string, unknown>;
|
|
1041
|
+
}>;
|
|
1042
|
+
};
|
|
1043
|
+
/** Structured OTel metric data point. */
|
|
1044
|
+
type OTelMetric = {
|
|
1045
|
+
name: string;
|
|
1046
|
+
description?: string;
|
|
1047
|
+
unit?: string;
|
|
1048
|
+
type: "gauge" | "sum" | "histogram" | "summary";
|
|
1049
|
+
value: number;
|
|
1050
|
+
attributes: Record<string, unknown>;
|
|
1051
|
+
timestampNs: number;
|
|
1052
|
+
};
|
|
1053
|
+
/** Structured OTel log record. */
|
|
1054
|
+
type OTelLog = {
|
|
1055
|
+
timestampNs: number;
|
|
1056
|
+
severityNumber?: number;
|
|
1057
|
+
severityText?: string;
|
|
1058
|
+
body: unknown;
|
|
1059
|
+
attributes: Record<string, unknown>;
|
|
1060
|
+
traceId?: string;
|
|
1061
|
+
spanId?: string;
|
|
1062
|
+
};
|
|
1063
|
+
/** Registration callback for the OTLP/HTTP receiver. */
|
|
1064
|
+
type OTelRegister = (handlers: {
|
|
1065
|
+
onTraces: (spans: OTelSpan[]) => void;
|
|
1066
|
+
onMetrics: (metrics: OTelMetric[]) => void;
|
|
1067
|
+
onLogs: (logs: OTelLog[]) => void;
|
|
1068
|
+
onError: (err: unknown) => void;
|
|
1069
|
+
}) => (() => void) | undefined;
|
|
1070
|
+
/** Options for {@link fromOTel}. */
|
|
1071
|
+
type FromOTelOptions = ExtraOpts$1 & {};
|
|
1072
|
+
/** Bundle returned by {@link fromOTel}. */
|
|
1073
|
+
type OTelBundle = {
|
|
1074
|
+
traces: Node<OTelSpan>;
|
|
1075
|
+
metrics: Node<OTelMetric>;
|
|
1076
|
+
logs: Node<OTelLog>;
|
|
1077
|
+
};
|
|
1078
|
+
/**
|
|
1079
|
+
* OTLP/HTTP receiver — accepts traces, metrics, and logs as separate reactive nodes.
|
|
1080
|
+
*
|
|
1081
|
+
* The caller owns the HTTP server. `fromOTel` receives a `register` callback that
|
|
1082
|
+
* wires OTLP POST endpoints to the three signal handlers. Each signal type gets
|
|
1083
|
+
* its own `Node` so downstream can subscribe selectively.
|
|
1084
|
+
*
|
|
1085
|
+
* @param register - Wires OTLP HTTP routes to `onTraces`, `onMetrics`, `onLogs` handlers.
|
|
1086
|
+
* @param opts - Optional producer options.
|
|
1087
|
+
* @returns {@link OTelBundle} — `{ traces, metrics, logs }` nodes.
|
|
1088
|
+
*
|
|
1089
|
+
* @example
|
|
1090
|
+
* ```ts
|
|
1091
|
+
* import express from "express";
|
|
1092
|
+
* import { fromOTel } from "@graphrefly/graphrefly-ts";
|
|
1093
|
+
*
|
|
1094
|
+
* const app = express();
|
|
1095
|
+
* app.use(express.json());
|
|
1096
|
+
*
|
|
1097
|
+
* const otel = fromOTel(({ onTraces, onMetrics, onLogs }) => {
|
|
1098
|
+
* app.post("/v1/traces", (req, res) => { onTraces(req.body.resourceSpans ?? []); res.sendStatus(200); });
|
|
1099
|
+
* app.post("/v1/metrics", (req, res) => { onMetrics(req.body.resourceMetrics ?? []); res.sendStatus(200); });
|
|
1100
|
+
* app.post("/v1/logs", (req, res) => { onLogs(req.body.resourceLogs ?? []); res.sendStatus(200); });
|
|
1101
|
+
* return () => {};
|
|
1102
|
+
* });
|
|
1103
|
+
* ```
|
|
1104
|
+
*
|
|
1105
|
+
* @category extra
|
|
1106
|
+
*/
|
|
1107
|
+
declare function fromOTel(register: OTelRegister, opts?: FromOTelOptions): OTelBundle;
|
|
1108
|
+
/** Parsed syslog message (RFC 5424). */
|
|
1109
|
+
type SyslogMessage = {
|
|
1110
|
+
facility: number;
|
|
1111
|
+
severity: number;
|
|
1112
|
+
timestamp: string;
|
|
1113
|
+
hostname: string;
|
|
1114
|
+
appName: string;
|
|
1115
|
+
procId: string;
|
|
1116
|
+
msgId: string;
|
|
1117
|
+
message: string;
|
|
1118
|
+
timestampNs: number;
|
|
1119
|
+
};
|
|
1120
|
+
/** Registration callback for syslog receiver. */
|
|
1121
|
+
type SyslogRegister = (handlers: AdapterHandlers<SyslogMessage>) => (() => void) | undefined;
|
|
1122
|
+
/** Options for {@link fromSyslog}. */
|
|
1123
|
+
type FromSyslogOptions = ExtraOpts$1 & {};
|
|
1124
|
+
/**
|
|
1125
|
+
* RFC 5424 syslog receiver as a reactive source.
|
|
1126
|
+
*
|
|
1127
|
+
* The caller owns the UDP/TCP socket. `fromSyslog` receives a `register` callback
|
|
1128
|
+
* that wires socket data events to the `emit` handler with parsed syslog messages.
|
|
1129
|
+
*
|
|
1130
|
+
* @param register - Wires socket to emit/error/complete handlers.
|
|
1131
|
+
* @param opts - Optional producer options.
|
|
1132
|
+
* @returns `Node<SyslogMessage>` — one `DATA` per syslog message.
|
|
1133
|
+
*
|
|
1134
|
+
* @example
|
|
1135
|
+
* ```ts
|
|
1136
|
+
* import dgram from "node:dgram";
|
|
1137
|
+
* import { fromSyslog, parseSyslog } from "@graphrefly/graphrefly-ts";
|
|
1138
|
+
*
|
|
1139
|
+
* const server = dgram.createSocket("udp4");
|
|
1140
|
+
* const syslog$ = fromSyslog(({ emit, error }) => {
|
|
1141
|
+
* server.on("message", (buf) => {
|
|
1142
|
+
* try { emit(parseSyslog(buf.toString())); }
|
|
1143
|
+
* catch (e) { error(e); }
|
|
1144
|
+
* });
|
|
1145
|
+
* server.bind(514);
|
|
1146
|
+
* return () => server.close();
|
|
1147
|
+
* });
|
|
1148
|
+
* ```
|
|
1149
|
+
*
|
|
1150
|
+
* @category extra
|
|
1151
|
+
*/
|
|
1152
|
+
declare function fromSyslog(register: SyslogRegister, opts?: FromSyslogOptions): Node<SyslogMessage>;
|
|
1153
|
+
/**
|
|
1154
|
+
* Parses a raw RFC 5424 syslog line into a structured {@link SyslogMessage}.
|
|
1155
|
+
*
|
|
1156
|
+
* Format: `<PRI>VERSION TIMESTAMP HOSTNAME APP-NAME PROCID MSGID MSG`
|
|
1157
|
+
*
|
|
1158
|
+
* @category extra
|
|
1159
|
+
*/
|
|
1160
|
+
declare function parseSyslog(raw: string): SyslogMessage;
|
|
1161
|
+
/** Parsed StatsD metric. */
|
|
1162
|
+
type StatsDMetric = {
|
|
1163
|
+
name: string;
|
|
1164
|
+
value: number;
|
|
1165
|
+
type: "counter" | "gauge" | "timer" | "histogram" | "set" | "distribution";
|
|
1166
|
+
sampleRate?: number;
|
|
1167
|
+
tags: Record<string, string>;
|
|
1168
|
+
timestampNs: number;
|
|
1169
|
+
};
|
|
1170
|
+
/** Registration callback for StatsD receiver. */
|
|
1171
|
+
type StatsDRegister = (handlers: AdapterHandlers<StatsDMetric>) => (() => void) | undefined;
|
|
1172
|
+
/** Options for {@link fromStatsD}. */
|
|
1173
|
+
type FromStatsDOptions = ExtraOpts$1 & {};
|
|
1174
|
+
/**
|
|
1175
|
+
* StatsD/DogStatsD UDP receiver as a reactive source.
|
|
1176
|
+
*
|
|
1177
|
+
* The caller owns the UDP socket. `fromStatsD` receives a `register` callback
|
|
1178
|
+
* that wires datagrams to the `emit` handler with parsed metrics.
|
|
1179
|
+
*
|
|
1180
|
+
* @param register - Wires socket to emit/error/complete handlers.
|
|
1181
|
+
* @param opts - Optional producer options.
|
|
1182
|
+
* @returns `Node<StatsDMetric>` — one `DATA` per metric line.
|
|
1183
|
+
*
|
|
1184
|
+
* @example
|
|
1185
|
+
* ```ts
|
|
1186
|
+
* import dgram from "node:dgram";
|
|
1187
|
+
* import { fromStatsD, parseStatsD } from "@graphrefly/graphrefly-ts";
|
|
1188
|
+
*
|
|
1189
|
+
* const server = dgram.createSocket("udp4");
|
|
1190
|
+
* const stats$ = fromStatsD(({ emit, error }) => {
|
|
1191
|
+
* server.on("message", (buf) => {
|
|
1192
|
+
* for (const line of buf.toString().split("\\n")) {
|
|
1193
|
+
* if (line.trim()) {
|
|
1194
|
+
* try { emit(parseStatsD(line)); }
|
|
1195
|
+
* catch (e) { error(e); }
|
|
1196
|
+
* }
|
|
1197
|
+
* }
|
|
1198
|
+
* });
|
|
1199
|
+
* server.bind(8125);
|
|
1200
|
+
* return () => server.close();
|
|
1201
|
+
* });
|
|
1202
|
+
* ```
|
|
1203
|
+
*
|
|
1204
|
+
* @category extra
|
|
1205
|
+
*/
|
|
1206
|
+
declare function fromStatsD(register: StatsDRegister, opts?: FromStatsDOptions): Node<StatsDMetric>;
|
|
1207
|
+
/**
|
|
1208
|
+
* Parses a raw StatsD/DogStatsD line into a structured {@link StatsDMetric}.
|
|
1209
|
+
*
|
|
1210
|
+
* Format: `metric.name:value|type|@sampleRate|#tag1:val1,tag2:val2`
|
|
1211
|
+
*
|
|
1212
|
+
* @category extra
|
|
1213
|
+
*/
|
|
1214
|
+
declare function parseStatsD(line: string): StatsDMetric;
|
|
1215
|
+
/** Parsed Prometheus metric. */
|
|
1216
|
+
type PrometheusMetric = {
|
|
1217
|
+
name: string;
|
|
1218
|
+
labels: Record<string, string>;
|
|
1219
|
+
value: number;
|
|
1220
|
+
timestampMs?: number;
|
|
1221
|
+
type?: "counter" | "gauge" | "histogram" | "summary" | "untyped";
|
|
1222
|
+
help?: string;
|
|
1223
|
+
timestampNs: number;
|
|
1224
|
+
};
|
|
1225
|
+
/** Options for {@link fromPrometheus}. */
|
|
1226
|
+
type FromPrometheusOptions = AsyncSourceOpts & {
|
|
1227
|
+
/** Scrape interval in nanoseconds. Default `15 * NS_PER_SEC` (15s). */
|
|
1228
|
+
intervalNs?: number;
|
|
1229
|
+
/** Request headers for the scrape. */
|
|
1230
|
+
headers?: Record<string, string>;
|
|
1231
|
+
/** Request timeout in nanoseconds. Default `10 * NS_PER_SEC` (10s). */
|
|
1232
|
+
timeoutNs?: number;
|
|
1233
|
+
};
|
|
1234
|
+
/**
|
|
1235
|
+
* Scrapes a Prometheus `/metrics` endpoint on a reactive timer interval.
|
|
1236
|
+
*
|
|
1237
|
+
* Each scrape parses the exposition format and emits one `DATA` per metric line.
|
|
1238
|
+
* Uses `fromTimer` semantics internally (reactive timer source, not polling).
|
|
1239
|
+
*
|
|
1240
|
+
* @param endpoint - URL of the Prometheus metrics endpoint.
|
|
1241
|
+
* @param opts - Scrape interval, headers, timeout.
|
|
1242
|
+
* @returns `Node<PrometheusMetric>` — one `DATA` per metric per scrape.
|
|
1243
|
+
*
|
|
1244
|
+
* @example
|
|
1245
|
+
* ```ts
|
|
1246
|
+
* import { fromPrometheus } from "@graphrefly/graphrefly-ts";
|
|
1247
|
+
*
|
|
1248
|
+
* const prom$ = fromPrometheus("http://localhost:9090/metrics", { intervalNs: 30 * NS_PER_SEC });
|
|
1249
|
+
* ```
|
|
1250
|
+
*
|
|
1251
|
+
* @category extra
|
|
1252
|
+
*/
|
|
1253
|
+
declare function fromPrometheus(endpoint: string, opts?: FromPrometheusOptions): Node<PrometheusMetric>;
|
|
1254
|
+
/**
|
|
1255
|
+
* Parses Prometheus exposition format text into structured metrics.
|
|
1256
|
+
*
|
|
1257
|
+
* @category extra
|
|
1258
|
+
*/
|
|
1259
|
+
declare function parsePrometheusText(text: string): PrometheusMetric[];
|
|
1260
|
+
/** Duck-typed Kafka consumer (compatible with kafkajs, confluent-kafka, Pulsar KoP). */
|
|
1261
|
+
type KafkaConsumerLike = {
|
|
1262
|
+
subscribe(opts: {
|
|
1263
|
+
topic: string;
|
|
1264
|
+
fromBeginning?: boolean;
|
|
1265
|
+
}): Promise<void>;
|
|
1266
|
+
run(opts: {
|
|
1267
|
+
eachMessage: (payload: {
|
|
1268
|
+
topic: string;
|
|
1269
|
+
partition: number;
|
|
1270
|
+
message: {
|
|
1271
|
+
key: Buffer | null;
|
|
1272
|
+
value: Buffer | null;
|
|
1273
|
+
headers?: Record<string, Buffer | string | undefined>;
|
|
1274
|
+
offset: string;
|
|
1275
|
+
timestamp: string;
|
|
1276
|
+
};
|
|
1277
|
+
}) => Promise<void>;
|
|
1278
|
+
}): Promise<void>;
|
|
1279
|
+
disconnect(): Promise<void>;
|
|
1280
|
+
};
|
|
1281
|
+
/** Duck-typed Kafka producer. */
|
|
1282
|
+
type KafkaProducerLike = {
|
|
1283
|
+
send(record: {
|
|
1284
|
+
topic: string;
|
|
1285
|
+
messages: Array<{
|
|
1286
|
+
key?: string | Buffer | null;
|
|
1287
|
+
value: string | Buffer | null;
|
|
1288
|
+
headers?: Record<string, string | Buffer>;
|
|
1289
|
+
}>;
|
|
1290
|
+
}): Promise<void>;
|
|
1291
|
+
disconnect(): Promise<void>;
|
|
1292
|
+
};
|
|
1293
|
+
/** Structured Kafka message. */
|
|
1294
|
+
type KafkaMessage<T = unknown> = {
|
|
1295
|
+
topic: string;
|
|
1296
|
+
partition: number;
|
|
1297
|
+
key: string | null;
|
|
1298
|
+
value: T;
|
|
1299
|
+
headers: Record<string, string>;
|
|
1300
|
+
offset: string;
|
|
1301
|
+
timestamp: string;
|
|
1302
|
+
timestampNs: number;
|
|
1303
|
+
};
|
|
1304
|
+
/** Options for {@link fromKafka}. */
|
|
1305
|
+
type FromKafkaOptions = ExtraOpts$1 & {
|
|
1306
|
+
/** Start from beginning of topic. Default: `false`. */
|
|
1307
|
+
fromBeginning?: boolean;
|
|
1308
|
+
/** Deserialize message value. Default: `JSON.parse(buffer.toString())`. */
|
|
1309
|
+
deserialize?: (value: Buffer | null) => unknown;
|
|
1310
|
+
};
|
|
1311
|
+
/**
|
|
1312
|
+
* Kafka consumer as a reactive source.
|
|
1313
|
+
*
|
|
1314
|
+
* Wraps a KafkaJS-compatible consumer. Each message becomes a `DATA` emission.
|
|
1315
|
+
* Compatible with Pulsar via KoP (Kafka-on-Pulsar).
|
|
1316
|
+
*
|
|
1317
|
+
* @param consumer - KafkaJS-compatible consumer instance (caller owns connect/disconnect lifecycle).
|
|
1318
|
+
* @param topic - Topic to consume from.
|
|
1319
|
+
* @param opts - Deserialization and source options.
|
|
1320
|
+
* @returns `Node<KafkaMessage<T>>` — one `DATA` per Kafka message.
|
|
1321
|
+
*
|
|
1322
|
+
* @example
|
|
1323
|
+
* ```ts
|
|
1324
|
+
* import { Kafka } from "kafkajs";
|
|
1325
|
+
* import { fromKafka } from "@graphrefly/graphrefly-ts";
|
|
1326
|
+
*
|
|
1327
|
+
* const kafka = new Kafka({ brokers: ["localhost:9092"] });
|
|
1328
|
+
* const consumer = kafka.consumer({ groupId: "my-group" });
|
|
1329
|
+
* await consumer.connect();
|
|
1330
|
+
*
|
|
1331
|
+
* const events$ = fromKafka(consumer, "events", { deserialize: (buf) => JSON.parse(buf!.toString()) });
|
|
1332
|
+
* ```
|
|
1333
|
+
*
|
|
1334
|
+
* @category extra
|
|
1335
|
+
*/
|
|
1336
|
+
declare function fromKafka<T = unknown>(consumer: KafkaConsumerLike, topic: string, opts?: FromKafkaOptions): Node<KafkaMessage<T>>;
|
|
1337
|
+
/** Options for {@link toKafka}. */
|
|
1338
|
+
type ToKafkaOptions<T> = ExtraOpts$1 & {
|
|
1339
|
+
/** Serialize value for Kafka. Default: `JSON.stringify`. */
|
|
1340
|
+
serialize?: (value: T) => string | Buffer;
|
|
1341
|
+
/** Extract message key from value. Default: `null` (no key). */
|
|
1342
|
+
keyExtractor?: (value: T) => string | null;
|
|
1343
|
+
/** Called on serialization or send failures. */
|
|
1344
|
+
onTransportError?: (err: SinkTransportError) => void;
|
|
1345
|
+
};
|
|
1346
|
+
/**
|
|
1347
|
+
* Kafka producer sink — forwards upstream `DATA` to a Kafka topic.
|
|
1348
|
+
*
|
|
1349
|
+
* @param source - Upstream node to forward.
|
|
1350
|
+
* @param kafkaProducer - KafkaJS-compatible producer instance.
|
|
1351
|
+
* @param topic - Target topic.
|
|
1352
|
+
* @param opts - Serialization and key extraction options.
|
|
1353
|
+
* @returns Unsubscribe function.
|
|
1354
|
+
*
|
|
1355
|
+
* @category extra
|
|
1356
|
+
*/
|
|
1357
|
+
declare function toKafka<T>(source: Node<T>, kafkaProducer: KafkaProducerLike, topic: string, opts?: ToKafkaOptions<T>): () => void;
|
|
1358
|
+
/** Duck-typed Redis client (compatible with ioredis, redis). */
|
|
1359
|
+
type RedisClientLike = {
|
|
1360
|
+
xadd(key: string, id: string, ...fieldsAndValues: string[]): Promise<string>;
|
|
1361
|
+
xread(...args: Array<string | number>): Promise<Array<[string, Array<[string, string[]]>]> | null>;
|
|
1362
|
+
disconnect(): void;
|
|
1363
|
+
};
|
|
1364
|
+
/** Structured Redis Stream entry. */
|
|
1365
|
+
type RedisStreamEntry<T = unknown> = {
|
|
1366
|
+
id: string;
|
|
1367
|
+
key: string;
|
|
1368
|
+
data: T;
|
|
1369
|
+
timestampNs: number;
|
|
1370
|
+
};
|
|
1371
|
+
/** Options for {@link fromRedisStream}. */
|
|
1372
|
+
type FromRedisStreamOptions = ExtraOpts$1 & {
|
|
1373
|
+
/** Block timeout in ms for XREAD. Default: `5000`. */
|
|
1374
|
+
blockMs?: number;
|
|
1375
|
+
/** Start ID. Default: `"$"` (new entries only). */
|
|
1376
|
+
startId?: string;
|
|
1377
|
+
/** Parse raw Redis hash fields to structured data. Default: parses `data` field as JSON. */
|
|
1378
|
+
parse?: (fields: string[]) => unknown;
|
|
1379
|
+
};
|
|
1380
|
+
/**
|
|
1381
|
+
* Redis Streams consumer as a reactive source.
|
|
1382
|
+
*
|
|
1383
|
+
* Uses XREAD with BLOCK to reactively consume stream entries.
|
|
1384
|
+
*
|
|
1385
|
+
* @param client - ioredis/redis-compatible client (caller owns connection).
|
|
1386
|
+
* @param key - Redis stream key.
|
|
1387
|
+
* @param opts - Block timeout, start ID, and parsing options.
|
|
1388
|
+
* @returns `Node<RedisStreamEntry<T>>` — one `DATA` per stream entry.
|
|
1389
|
+
*
|
|
1390
|
+
* @category extra
|
|
1391
|
+
*/
|
|
1392
|
+
declare function fromRedisStream<T = unknown>(client: RedisClientLike, key: string, opts?: FromRedisStreamOptions): Node<RedisStreamEntry<T>>;
|
|
1393
|
+
/** Options for {@link toRedisStream}. */
|
|
1394
|
+
type ToRedisStreamOptions<T> = ExtraOpts$1 & {
|
|
1395
|
+
/** Serialize value to Redis hash fields. Default: `["data", JSON.stringify(value)]`. */
|
|
1396
|
+
serialize?: (value: T) => string[];
|
|
1397
|
+
/** Max stream length (MAXLEN ~). Default: no trimming. */
|
|
1398
|
+
maxLen?: number;
|
|
1399
|
+
/** Called on serialization or send failures. */
|
|
1400
|
+
onTransportError?: (err: SinkTransportError) => void;
|
|
1401
|
+
};
|
|
1402
|
+
/**
|
|
1403
|
+
* Redis Streams producer sink — forwards upstream `DATA` to a Redis stream.
|
|
1404
|
+
*
|
|
1405
|
+
* @param source - Upstream node to forward.
|
|
1406
|
+
* @param client - ioredis/redis-compatible client.
|
|
1407
|
+
* @param key - Redis stream key.
|
|
1408
|
+
* @param opts - Serialization options.
|
|
1409
|
+
* @returns Unsubscribe function.
|
|
1410
|
+
*
|
|
1411
|
+
* @category extra
|
|
1412
|
+
*/
|
|
1413
|
+
declare function toRedisStream<T>(source: Node<T>, client: RedisClientLike, key: string, opts?: ToRedisStreamOptions<T>): () => void;
|
|
1414
|
+
/** Parsed CSV row. */
|
|
1415
|
+
type CSVRow = Record<string, string>;
|
|
1416
|
+
/** Options for {@link fromCSV}. */
|
|
1417
|
+
type FromCSVOptions = ExtraOpts$1 & {
|
|
1418
|
+
/** Column delimiter. Default: `","`. */
|
|
1419
|
+
delimiter?: string;
|
|
1420
|
+
/** Whether the first row is a header. Default: `true`. */
|
|
1421
|
+
hasHeader?: boolean;
|
|
1422
|
+
/** Explicit column names (overrides header row). */
|
|
1423
|
+
columns?: string[];
|
|
1424
|
+
/** Custom line parser (e.g. wrapping a library like `csv-parse`). Overrides built-in parser + delimiter. */
|
|
1425
|
+
parseLine?: (line: string) => string[];
|
|
1426
|
+
};
|
|
1427
|
+
/**
|
|
1428
|
+
* CSV file/stream ingest for batch replay.
|
|
1429
|
+
*
|
|
1430
|
+
* Reads a CSV from a `ReadableStream<string>` or an `AsyncIterable<string>` of lines,
|
|
1431
|
+
* emitting one `DATA` per row. `COMPLETE` after all rows are emitted.
|
|
1432
|
+
*
|
|
1433
|
+
* @param source - Async iterable of CSV text chunks (lines or multi-line chunks).
|
|
1434
|
+
* @param opts - Delimiter, header, and column options.
|
|
1435
|
+
* @returns `Node<CSVRow>` — one `DATA` per parsed row.
|
|
1436
|
+
*
|
|
1437
|
+
* @example
|
|
1438
|
+
* ```ts
|
|
1439
|
+
* import { createReadStream } from "node:fs";
|
|
1440
|
+
* import { fromCSV } from "@graphrefly/graphrefly-ts";
|
|
1441
|
+
*
|
|
1442
|
+
* const csv$ = fromCSV(createReadStream("data.csv", "utf-8"));
|
|
1443
|
+
* ```
|
|
1444
|
+
*
|
|
1445
|
+
* @category extra
|
|
1446
|
+
*/
|
|
1447
|
+
declare function fromCSV(source: AsyncIterable<string>, opts?: FromCSVOptions): Node<CSVRow>;
|
|
1448
|
+
/** Options for {@link fromNDJSON}. */
|
|
1449
|
+
type FromNDJSONOptions = ExtraOpts$1 & {};
|
|
1450
|
+
/**
|
|
1451
|
+
* Newline-delimited JSON stream ingest for batch replay.
|
|
1452
|
+
*
|
|
1453
|
+
* Reads an async iterable of text chunks, splits by newline, parses each line
|
|
1454
|
+
* as JSON, and emits one `DATA` per parsed object. `COMPLETE` after stream ends.
|
|
1455
|
+
*
|
|
1456
|
+
* @param source - Async iterable of NDJSON text chunks.
|
|
1457
|
+
* @param opts - Optional producer options.
|
|
1458
|
+
* @returns `Node<T>` — one `DATA` per JSON line.
|
|
1459
|
+
*
|
|
1460
|
+
* @example
|
|
1461
|
+
* ```ts
|
|
1462
|
+
* import { createReadStream } from "node:fs";
|
|
1463
|
+
* import { fromNDJSON } from "@graphrefly/graphrefly-ts";
|
|
1464
|
+
*
|
|
1465
|
+
* const logs$ = fromNDJSON(createReadStream("logs.ndjson", "utf-8"));
|
|
1466
|
+
* ```
|
|
1467
|
+
*
|
|
1468
|
+
* @category extra
|
|
1469
|
+
*/
|
|
1470
|
+
declare function fromNDJSON<T = unknown>(source: AsyncIterable<string>, opts?: FromNDJSONOptions): Node<T>;
|
|
1471
|
+
/** Structured ClickHouse query result row. */
|
|
1472
|
+
type ClickHouseRow = Record<string, unknown>;
|
|
1473
|
+
/** Duck-typed ClickHouse client. */
|
|
1474
|
+
type ClickHouseClientLike = {
|
|
1475
|
+
query(opts: {
|
|
1476
|
+
query: string;
|
|
1477
|
+
format?: string;
|
|
1478
|
+
}): Promise<{
|
|
1479
|
+
json<T = unknown>(): Promise<T[]>;
|
|
1480
|
+
}>;
|
|
1481
|
+
};
|
|
1482
|
+
/** Options for {@link fromClickHouseWatch}. */
|
|
1483
|
+
type FromClickHouseWatchOptions = AsyncSourceOpts & {
|
|
1484
|
+
/** Polling interval in nanoseconds. Default: `5 * NS_PER_SEC` (5s). */
|
|
1485
|
+
intervalNs?: number;
|
|
1486
|
+
/** JSON format to request. Default: `"JSONEachRow"`. */
|
|
1487
|
+
format?: string;
|
|
1488
|
+
};
|
|
1489
|
+
/**
|
|
1490
|
+
* ClickHouse live materialized view as a reactive source.
|
|
1491
|
+
*
|
|
1492
|
+
* Polls a ClickHouse query on a reactive timer interval and emits new/changed rows.
|
|
1493
|
+
* Uses a timer-driven approach (not busy-wait polling).
|
|
1494
|
+
*
|
|
1495
|
+
* @param client - ClickHouse client instance (caller owns connection).
|
|
1496
|
+
* @param query - SQL query to execute on each interval.
|
|
1497
|
+
* @param opts - Polling interval and format options.
|
|
1498
|
+
* @returns `Node<ClickHouseRow>` — one `DATA` per result row per scrape.
|
|
1499
|
+
*
|
|
1500
|
+
* @example
|
|
1501
|
+
* ```ts
|
|
1502
|
+
* import { createClient } from "@clickhouse/client";
|
|
1503
|
+
* import { fromClickHouseWatch } from "@graphrefly/graphrefly-ts";
|
|
1504
|
+
*
|
|
1505
|
+
* const client = createClient({ url: "http://localhost:8123" });
|
|
1506
|
+
* const rows$ = fromClickHouseWatch(client, "SELECT * FROM errors_mv ORDER BY timestamp DESC LIMIT 100");
|
|
1507
|
+
* ```
|
|
1508
|
+
*
|
|
1509
|
+
* @category extra
|
|
1510
|
+
*/
|
|
1511
|
+
declare function fromClickHouseWatch(client: ClickHouseClientLike, query: string, opts?: FromClickHouseWatchOptions): Node<ClickHouseRow>;
|
|
1512
|
+
|
|
1513
|
+
/**
|
|
1514
|
+
* Watermark-based backpressure controller — reactive PAUSE/RESUME flow control.
|
|
1515
|
+
*
|
|
1516
|
+
* Purely synchronous, event-driven. No timers, no polling, no Promises.
|
|
1517
|
+
* Each controller instance uses a unique lockId so multiple controllers
|
|
1518
|
+
* on the same upstream node do not collide.
|
|
1519
|
+
*
|
|
1520
|
+
* @module
|
|
1521
|
+
*/
|
|
1522
|
+
|
|
1523
|
+
type WatermarkOptions = {
|
|
1524
|
+
/** Pending count at which PAUSE is sent upstream. */
|
|
1525
|
+
highWaterMark: number;
|
|
1526
|
+
/** Pending count at which RESUME is sent upstream (after being paused). */
|
|
1527
|
+
lowWaterMark: number;
|
|
1528
|
+
};
|
|
1529
|
+
type WatermarkController = {
|
|
1530
|
+
/** Call when a DATA message is buffered/enqueued. Returns `true` if PAUSE was just sent. */
|
|
1531
|
+
onEnqueue(): boolean;
|
|
1532
|
+
/** Call when a buffered item is consumed. Returns `true` if RESUME was just sent. */
|
|
1533
|
+
onDequeue(): boolean;
|
|
1534
|
+
/** Current un-consumed item count. */
|
|
1535
|
+
readonly pending: number;
|
|
1536
|
+
/** Whether upstream is currently paused by this controller. */
|
|
1537
|
+
readonly paused: boolean;
|
|
1538
|
+
/** Dispose: if paused, sends RESUME to unblock upstream. */
|
|
1539
|
+
dispose(): void;
|
|
1540
|
+
};
|
|
1541
|
+
/**
|
|
1542
|
+
* Creates a watermark-based backpressure controller.
|
|
1543
|
+
*
|
|
1544
|
+
* @param sendUp - Callback that delivers messages upstream (typically `handle.up`).
|
|
1545
|
+
* @param opts - High/low watermark thresholds (item counts).
|
|
1546
|
+
* @returns A {@link WatermarkController}.
|
|
1547
|
+
*
|
|
1548
|
+
* @example
|
|
1549
|
+
* ```ts
|
|
1550
|
+
* const handle = graph.observe("fast-source");
|
|
1551
|
+
* const wm = createWatermarkController(
|
|
1552
|
+
* (msgs) => handle.up(msgs),
|
|
1553
|
+
* { highWaterMark: 64, lowWaterMark: 16 },
|
|
1554
|
+
* );
|
|
1555
|
+
*
|
|
1556
|
+
* // In sink callback:
|
|
1557
|
+
* handle.subscribe((msgs) => {
|
|
1558
|
+
* for (const msg of msgs) {
|
|
1559
|
+
* if (msg[0] === DATA) {
|
|
1560
|
+
* buffer.push(msg[1]);
|
|
1561
|
+
* wm.onEnqueue();
|
|
1562
|
+
* }
|
|
1563
|
+
* }
|
|
1564
|
+
* });
|
|
1565
|
+
*
|
|
1566
|
+
* // When consumer drains:
|
|
1567
|
+
* const item = buffer.shift();
|
|
1568
|
+
* wm.onDequeue();
|
|
1569
|
+
* ```
|
|
1570
|
+
*
|
|
1571
|
+
* @category extra
|
|
1572
|
+
*/
|
|
1573
|
+
declare function createWatermarkController(sendUp: (messages: Messages) => void, opts: WatermarkOptions): WatermarkController;
|
|
1574
|
+
|
|
1575
|
+
/**
|
|
1576
|
+
* Checkpoint adapters and {@link Graph} save/restore helpers (roadmap §3.1).
|
|
1577
|
+
*/
|
|
1578
|
+
|
|
1579
|
+
/**
|
|
1580
|
+
* Persists {@link GraphPersistSnapshot} blobs (single save/load contract, roadmap §3.1).
|
|
1581
|
+
*/
|
|
1582
|
+
interface CheckpointAdapter {
|
|
1583
|
+
save(data: GraphPersistSnapshot): void;
|
|
1584
|
+
load(): GraphPersistSnapshot | null;
|
|
1585
|
+
}
|
|
1586
|
+
/**
|
|
1587
|
+
* In-memory adapter (process-local; useful for tests).
|
|
1588
|
+
*
|
|
1589
|
+
* @category extra
|
|
1590
|
+
*/
|
|
1591
|
+
declare class MemoryCheckpointAdapter implements CheckpointAdapter {
|
|
1592
|
+
#private;
|
|
1593
|
+
save(data: GraphPersistSnapshot): void;
|
|
1594
|
+
load(): GraphPersistSnapshot | null;
|
|
1595
|
+
}
|
|
1596
|
+
/**
|
|
1597
|
+
* Stores JSON-cloned snapshots under a key inside a caller-owned record (tests / embedding).
|
|
1598
|
+
*
|
|
1599
|
+
* @category extra
|
|
1600
|
+
*/
|
|
1601
|
+
declare class DictCheckpointAdapter implements CheckpointAdapter {
|
|
1602
|
+
#private;
|
|
1603
|
+
constructor(storage: Record<string, unknown>, key?: string);
|
|
1604
|
+
save(data: GraphPersistSnapshot): void;
|
|
1605
|
+
load(): GraphPersistSnapshot | null;
|
|
1606
|
+
}
|
|
1607
|
+
/**
|
|
1608
|
+
* Atomic JSON file persistence (temp file in the target directory, then `rename`).
|
|
1609
|
+
*
|
|
1610
|
+
* @remarks
|
|
1611
|
+
* **Errors:** `load()` returns `null` for missing files, empty files, or invalid JSON (no throw).
|
|
1612
|
+
*
|
|
1613
|
+
* @category extra
|
|
1614
|
+
*/
|
|
1615
|
+
declare class FileCheckpointAdapter implements CheckpointAdapter {
|
|
1616
|
+
#private;
|
|
1617
|
+
constructor(path: string);
|
|
1618
|
+
save(data: GraphPersistSnapshot): void;
|
|
1619
|
+
load(): GraphPersistSnapshot | null;
|
|
1620
|
+
}
|
|
1621
|
+
/**
|
|
1622
|
+
* Persists one JSON blob under a fixed key using Node.js `node:sqlite` ({@link DatabaseSync}).
|
|
1623
|
+
*
|
|
1624
|
+
* @remarks
|
|
1625
|
+
* **Runtime:** Requires Node 22.5+ with `node:sqlite` enabled (experimental in some releases). Call `close()` when discarding the adapter.
|
|
1626
|
+
*
|
|
1627
|
+
* @category extra
|
|
1628
|
+
*/
|
|
1629
|
+
declare class SqliteCheckpointAdapter implements CheckpointAdapter {
|
|
1630
|
+
#private;
|
|
1631
|
+
constructor(path: string, key?: string);
|
|
1632
|
+
save(data: GraphPersistSnapshot): void;
|
|
1633
|
+
load(): GraphPersistSnapshot | null;
|
|
1634
|
+
/** Close the underlying SQLite connection (safe to call more than once). */
|
|
1635
|
+
close(): void;
|
|
1636
|
+
}
|
|
1637
|
+
/**
|
|
1638
|
+
* Writes {@link Graph.snapshot} through `adapter.save`.
|
|
1639
|
+
*
|
|
1640
|
+
* @param graph - Target graph instance.
|
|
1641
|
+
* @param adapter - Sync persistence backend.
|
|
1642
|
+
* @returns `void` — side-effect only; the snapshot is written to `adapter`.
|
|
1643
|
+
*
|
|
1644
|
+
* @example
|
|
1645
|
+
* ```ts
|
|
1646
|
+
* import { saveGraphCheckpoint, MemoryCheckpointAdapter, Graph } from "@graphrefly/graphrefly-ts";
|
|
1647
|
+
*
|
|
1648
|
+
* const g = new Graph("app");
|
|
1649
|
+
* const adapter = new MemoryCheckpointAdapter();
|
|
1650
|
+
* saveGraphCheckpoint(g, adapter);
|
|
1651
|
+
* ```
|
|
1652
|
+
*
|
|
1653
|
+
* @category extra
|
|
1654
|
+
*/
|
|
1655
|
+
declare function saveGraphCheckpoint(graph: Graph, adapter: CheckpointAdapter): void;
|
|
1656
|
+
/**
|
|
1657
|
+
* Loads a snapshot via `adapter.load` and applies {@link Graph.restore} when data exists.
|
|
1658
|
+
*
|
|
1659
|
+
* @param graph - Graph whose topology matches the snapshot.
|
|
1660
|
+
* @param adapter - Sync persistence backend.
|
|
1661
|
+
* @returns `true` if data was present and `restore` ran; `false` if `load()` returned `null`.
|
|
1662
|
+
*
|
|
1663
|
+
* @example
|
|
1664
|
+
* ```ts
|
|
1665
|
+
* import {
|
|
1666
|
+
* saveGraphCheckpoint,
|
|
1667
|
+
* restoreGraphCheckpoint,
|
|
1668
|
+
* MemoryCheckpointAdapter,
|
|
1669
|
+
* Graph,
|
|
1670
|
+
* } from "@graphrefly/graphrefly-ts";
|
|
1671
|
+
*
|
|
1672
|
+
* const g = new Graph("app");
|
|
1673
|
+
* const adapter = new MemoryCheckpointAdapter();
|
|
1674
|
+
* saveGraphCheckpoint(g, adapter);
|
|
1675
|
+
*
|
|
1676
|
+
* const g2 = new Graph("app");
|
|
1677
|
+
* restoreGraphCheckpoint(g2, adapter); // true
|
|
1678
|
+
* ```
|
|
1679
|
+
*
|
|
1680
|
+
* @category extra
|
|
1681
|
+
*/
|
|
1682
|
+
declare function restoreGraphCheckpoint(graph: Graph, adapter: CheckpointAdapter): boolean;
|
|
1683
|
+
/**
|
|
1684
|
+
* Minimal JSON-shaped payload for a single node's cached value (custom adapters).
|
|
1685
|
+
*
|
|
1686
|
+
* @param n - Any {@link Node}.
|
|
1687
|
+
* @returns `{ version: 1, value }` from {@link Node.get}.
|
|
1688
|
+
*
|
|
1689
|
+
* @example
|
|
1690
|
+
* ```ts
|
|
1691
|
+
* import { checkpointNodeValue, state } from "@graphrefly/graphrefly-ts";
|
|
1692
|
+
*
|
|
1693
|
+
* const s = state(42);
|
|
1694
|
+
* checkpointNodeValue(s); // { version: 1, value: 42 }
|
|
1695
|
+
* ```
|
|
1696
|
+
*
|
|
1697
|
+
* @category extra
|
|
1698
|
+
*/
|
|
1699
|
+
declare function checkpointNodeValue<T>(n: Node<T>): {
|
|
1700
|
+
version: number;
|
|
1701
|
+
value: T | undefined;
|
|
1702
|
+
};
|
|
1703
|
+
type IndexedDbCheckpointSpec = {
|
|
1704
|
+
dbName: string;
|
|
1705
|
+
storeName: string;
|
|
1706
|
+
/** @default "graphrefly_checkpoint" */
|
|
1707
|
+
key?: string;
|
|
1708
|
+
version?: number;
|
|
1709
|
+
};
|
|
1710
|
+
/**
|
|
1711
|
+
* Wraps an `IDBRequest` as a one-shot reactive source.
|
|
1712
|
+
*
|
|
1713
|
+
* @param req - Request whose callbacks are converted to protocol messages.
|
|
1714
|
+
* @returns `Node<T>` that emits `DATA` once on success, then `COMPLETE`; emits `ERROR` on failure.
|
|
1715
|
+
*
|
|
1716
|
+
* @example
|
|
1717
|
+
* ```ts
|
|
1718
|
+
* import { fromIDBRequest } from "@graphrefly/graphrefly-ts";
|
|
1719
|
+
*
|
|
1720
|
+
* const req = indexedDB.open("myDb", 1);
|
|
1721
|
+
* fromIDBRequest(req).subscribe((msgs) => console.log(msgs));
|
|
1722
|
+
* // Emits [[DATA, IDBDatabase], [COMPLETE]] on success
|
|
1723
|
+
* ```
|
|
1724
|
+
*
|
|
1725
|
+
* @category extra
|
|
1726
|
+
*/
|
|
1727
|
+
declare function fromIDBRequest<T>(req: IDBRequest<T>): Node<T>;
|
|
1728
|
+
/**
|
|
1729
|
+
* Wraps an `IDBTransaction` terminal lifecycle as a one-shot reactive source.
|
|
1730
|
+
*
|
|
1731
|
+
* @param tx - Transaction to observe.
|
|
1732
|
+
* @returns `Node<void>` that emits `DATA` (`undefined`) then `COMPLETE` on success; emits `ERROR` on `error`/`abort`.
|
|
1733
|
+
*
|
|
1734
|
+
* @example
|
|
1735
|
+
* ```ts
|
|
1736
|
+
* import { fromIDBTransaction } from "@graphrefly/graphrefly-ts";
|
|
1737
|
+
*
|
|
1738
|
+
* const db: IDBDatabase = ...; // obtained from indexedDB.open
|
|
1739
|
+
* const tx = db.transaction("store", "readwrite");
|
|
1740
|
+
* fromIDBTransaction(tx).subscribe((msgs) => console.log(msgs));
|
|
1741
|
+
* // Emits [[DATA, undefined], [COMPLETE]] when the transaction commits
|
|
1742
|
+
* ```
|
|
1743
|
+
*
|
|
1744
|
+
* @category extra
|
|
1745
|
+
*/
|
|
1746
|
+
declare function fromIDBTransaction(tx: IDBTransaction): Node<void>;
|
|
1747
|
+
/**
|
|
1748
|
+
* Persists {@link Graph.snapshot} under `spec.key` (browser IndexedDB).
|
|
1749
|
+
*
|
|
1750
|
+
* @param graph - Graph to snapshot.
|
|
1751
|
+
* @param spec - Database name, object store name, optional `key` and schema `version`.
|
|
1752
|
+
* @returns A reactive `Node<void>` that emits `DATA` (`undefined`) then `COMPLETE` on success, or `ERROR` on failure.
|
|
1753
|
+
*
|
|
1754
|
+
* @remarks
|
|
1755
|
+
* **Environment:** Emits `ERROR` if `indexedDB` is undefined (e.g. Node without a polyfill).
|
|
1756
|
+
*
|
|
1757
|
+
* @example
|
|
1758
|
+
* ```ts
|
|
1759
|
+
* import { saveGraphCheckpointIndexedDb, Graph } from "@graphrefly/graphrefly-ts";
|
|
1760
|
+
*
|
|
1761
|
+
* const g = new Graph("app");
|
|
1762
|
+
* const save$ = saveGraphCheckpointIndexedDb(g, {
|
|
1763
|
+
* dbName: "myApp",
|
|
1764
|
+
* storeName: "checkpoints",
|
|
1765
|
+
* });
|
|
1766
|
+
* save$.subscribe((msgs) => console.log("saved:", msgs));
|
|
1767
|
+
* ```
|
|
1768
|
+
*
|
|
1769
|
+
* @category extra
|
|
1770
|
+
*/
|
|
1771
|
+
declare function saveGraphCheckpointIndexedDb(graph: Graph, spec: IndexedDbCheckpointSpec): Node<void>;
|
|
1772
|
+
/**
|
|
1773
|
+
* Loads a snapshot from IndexedDB and applies {@link Graph.restore} when present.
|
|
1774
|
+
*
|
|
1775
|
+
* @param graph - Graph whose topology matches the stored snapshot.
|
|
1776
|
+
* @param spec - Same `dbName` / `storeName` / `key` / `version` as save.
|
|
1777
|
+
* @returns A reactive `Node<boolean>`: emits `true` if a snapshot was restored, `false` if missing or not a plain object, then `COMPLETE`; or `ERROR` on I/O failure.
|
|
1778
|
+
*
|
|
1779
|
+
* @example
|
|
1780
|
+
* ```ts
|
|
1781
|
+
* import { restoreGraphCheckpointIndexedDb, Graph } from "@graphrefly/graphrefly-ts";
|
|
1782
|
+
*
|
|
1783
|
+
* const g = new Graph("app");
|
|
1784
|
+
* const restore$ = restoreGraphCheckpointIndexedDb(g, {
|
|
1785
|
+
* dbName: "myApp",
|
|
1786
|
+
* storeName: "checkpoints",
|
|
1787
|
+
* });
|
|
1788
|
+
* restore$.subscribe((msgs) => console.log("restored:", msgs));
|
|
1789
|
+
* // Emits [[DATA, true], [COMPLETE]] if a snapshot was found and applied
|
|
1790
|
+
* ```
|
|
1791
|
+
*
|
|
1792
|
+
* @category extra
|
|
1793
|
+
*/
|
|
1794
|
+
declare function restoreGraphCheckpointIndexedDb(graph: Graph, spec: IndexedDbCheckpointSpec): Node<boolean>;
|
|
1795
|
+
|
|
1796
|
+
type ReactiveMapSnapshot<K, V> = Versioned<{
|
|
1797
|
+
map: ReadonlyMap<K, V>;
|
|
1798
|
+
}>;
|
|
1799
|
+
type ReactiveMapOptions = {
|
|
1800
|
+
/** Optional registry name for `describe()` / debugging. */
|
|
1801
|
+
name?: string;
|
|
1802
|
+
/** When set, evicts least-recently-used keys after inserts that exceed this size. */
|
|
1803
|
+
maxSize?: number;
|
|
1804
|
+
/** Default TTL in seconds. Used when `set` omits per-call `ttl`. */
|
|
1805
|
+
defaultTtl?: number;
|
|
1806
|
+
} & Omit<NodeOptions, "initial" | "describeKind" | "equals">;
|
|
1807
|
+
type ReactiveMapBundle<K, V> = {
|
|
1808
|
+
/** Emits {@link ReactiveMapSnapshot} on each structural change (two-phase). */
|
|
1809
|
+
node: Node<ReactiveMapSnapshot<K, V>>;
|
|
1810
|
+
get: (key: K) => V | undefined;
|
|
1811
|
+
set: (key: K, value: V, opts?: {
|
|
1812
|
+
ttl?: number;
|
|
1813
|
+
}) => void;
|
|
1814
|
+
delete: (key: K) => void;
|
|
1815
|
+
clear: () => void;
|
|
1816
|
+
has: (key: K) => boolean;
|
|
1817
|
+
readonly size: number;
|
|
1818
|
+
/** Removes expired entries (monotonic clock), emitting if the visible map changes. */
|
|
1819
|
+
pruneExpired: () => void;
|
|
1820
|
+
};
|
|
1821
|
+
/**
|
|
1822
|
+
* Creates a reactive `Map` with optional per-key TTL and optional LRU max size.
|
|
1823
|
+
*
|
|
1824
|
+
* @param options - Node options plus `maxSize` / `defaultTtl` (seconds).
|
|
1825
|
+
* @returns `ReactiveMapBundle` — imperative `get` / `set` / `delete` / `clear` / `pruneExpired` and a `node` emitting versioned readonly map snapshots.
|
|
1826
|
+
*
|
|
1827
|
+
* @remarks
|
|
1828
|
+
* **TTL:** Expiry is checked on `get`, `has`, `size`, `pruneExpired`, and before each
|
|
1829
|
+
* snapshot emission (expired keys are pruned first). There is no
|
|
1830
|
+
* background timer; monotonic-clock–expired keys may still appear in the last-emitted
|
|
1831
|
+
* snapshot on `node` until a read or `pruneExpired` removes them.
|
|
1832
|
+
* Uses `monotonicNs()` — immune to wall-clock adjustments.
|
|
1833
|
+
*
|
|
1834
|
+
* **LRU:** Uses native `Map` insertion order — `get` / `has` refreshes position; under
|
|
1835
|
+
* `maxSize` pressure the first key in iteration order is evicted. When `maxSize` is
|
|
1836
|
+
* omitted or is less than 1, no size-based eviction runs.
|
|
1837
|
+
*
|
|
1838
|
+
* @example
|
|
1839
|
+
* ```ts
|
|
1840
|
+
* import { reactiveMap } from "@graphrefly/graphrefly-ts";
|
|
1841
|
+
*
|
|
1842
|
+
* const m = reactiveMap<string, number>({ name: "cache", maxSize: 100, defaultTtl: 60 });
|
|
1843
|
+
* m.set("x", 1);
|
|
1844
|
+
* m.node.subscribe((msgs) => {
|
|
1845
|
+
* console.log(msgs);
|
|
1846
|
+
* });
|
|
1847
|
+
* ```
|
|
1848
|
+
*
|
|
1849
|
+
* @category extra
|
|
1850
|
+
*/
|
|
1851
|
+
declare function reactiveMap<K, V>(options?: ReactiveMapOptions): ReactiveMapBundle<K, V>;
|
|
1852
|
+
|
|
1853
|
+
/**
|
|
1854
|
+
* Composite data patterns (roadmap §3.2b).
|
|
1855
|
+
*
|
|
1856
|
+
* These helpers compose existing primitives (`node`, `switchMap`, `reactiveMap`,
|
|
1857
|
+
* `dynamicNode`, `fromAny`) without introducing new protocol semantics.
|
|
1858
|
+
*/
|
|
1859
|
+
|
|
1860
|
+
/**
|
|
1861
|
+
* Verification payload shape is intentionally user-defined.
|
|
1862
|
+
*/
|
|
1863
|
+
type VerifyValue = unknown;
|
|
1864
|
+
type VerifiableOptions<TVerify = VerifyValue> = Omit<NodeOptions, "describeKind" | "initial"> & {
|
|
1865
|
+
/** Reactive re-verification trigger. */
|
|
1866
|
+
trigger?: NodeInput<unknown>;
|
|
1867
|
+
/** Re-run verification whenever `source` settles. */
|
|
1868
|
+
autoVerify?: boolean;
|
|
1869
|
+
/** Initial verification companion value. */
|
|
1870
|
+
initialVerified?: TVerify | null;
|
|
1871
|
+
};
|
|
1872
|
+
type VerifiableBundle<T, TVerify = VerifyValue> = {
|
|
1873
|
+
/** Coerced source node. */
|
|
1874
|
+
node: Node<T>;
|
|
1875
|
+
/** Latest verification result (`null` before first verification). */
|
|
1876
|
+
verified: Node<TVerify | null>;
|
|
1877
|
+
/** Effective trigger node used for verification, if any. */
|
|
1878
|
+
trigger: Node<unknown> | null;
|
|
1879
|
+
};
|
|
1880
|
+
/**
|
|
1881
|
+
* Composes a value node with a reactive verification companion.
|
|
1882
|
+
*
|
|
1883
|
+
* Uses `switchMap` so newer triggers cancel stale in-flight verification work.
|
|
1884
|
+
*/
|
|
1885
|
+
declare function verifiable<T, TVerify = VerifyValue>(source: NodeInput<T>, verifyFn: (value: T) => NodeInput<TVerify>, opts?: VerifiableOptions<TVerify>): VerifiableBundle<T, TVerify>;
|
|
1886
|
+
type Extraction<TMem> = {
|
|
1887
|
+
upsert: Array<{
|
|
1888
|
+
key: string;
|
|
1889
|
+
value: TMem;
|
|
1890
|
+
}>;
|
|
1891
|
+
remove?: string[];
|
|
1892
|
+
};
|
|
1893
|
+
type DistillOptions<TMem> = {
|
|
1894
|
+
score: (mem: TMem, context: unknown) => number;
|
|
1895
|
+
cost: (mem: TMem) => number;
|
|
1896
|
+
budget?: number;
|
|
1897
|
+
evict?: (key: string, mem: TMem) => boolean | Node<boolean>;
|
|
1898
|
+
consolidate?: (entries: ReadonlyMap<string, TMem>) => NodeInput<Extraction<TMem>>;
|
|
1899
|
+
consolidateTrigger?: NodeInput<unknown>;
|
|
1900
|
+
context?: NodeInput<unknown>;
|
|
1901
|
+
mapOptions?: ReactiveMapOptions;
|
|
1902
|
+
};
|
|
1903
|
+
type DistillBundle<TMem> = {
|
|
1904
|
+
store: ReactiveMapBundle<string, TMem>;
|
|
1905
|
+
compact: Node<Array<{
|
|
1906
|
+
key: string;
|
|
1907
|
+
value: TMem;
|
|
1908
|
+
score: number;
|
|
1909
|
+
}>>;
|
|
1910
|
+
size: Node<number>;
|
|
1911
|
+
};
|
|
1912
|
+
/**
|
|
1913
|
+
* Budget-constrained reactive memory composition.
|
|
1914
|
+
*/
|
|
1915
|
+
declare function distill<TRaw, TMem>(source: NodeInput<TRaw>, extractFn: (raw: TRaw, existing: ReadonlyMap<string, TMem>) => NodeInput<Extraction<TMem>>, opts: DistillOptions<TMem>): DistillBundle<TMem>;
|
|
1916
|
+
|
|
1917
|
+
/**
|
|
1918
|
+
* Minimal 5-field cron parser and matcher (minute hour day-of-month month day-of-week).
|
|
1919
|
+
* Ported from callbag-recharge `extra/cron.ts` for `fromCron` (roadmap §2.3).
|
|
1920
|
+
*/
|
|
1921
|
+
interface CronSchedule {
|
|
1922
|
+
minutes: Set<number>;
|
|
1923
|
+
hours: Set<number>;
|
|
1924
|
+
daysOfMonth: Set<number>;
|
|
1925
|
+
months: Set<number>;
|
|
1926
|
+
daysOfWeek: Set<number>;
|
|
1927
|
+
}
|
|
1928
|
+
/**
|
|
1929
|
+
* Parses a standard 5-field cron expression into a {@link CronSchedule}.
|
|
1930
|
+
*
|
|
1931
|
+
* Supports `*`, ranges (`1-5`), steps (`*\/5`, `0-30/10`), and comma-separated
|
|
1932
|
+
* lists. Fields are: minute (0–59), hour (0–23), day-of-month (1–31),
|
|
1933
|
+
* month (1–12), day-of-week (0–6, Sunday = 0).
|
|
1934
|
+
*
|
|
1935
|
+
* @param expr - Five-field whitespace-separated cron string (e.g. `"0 9 * * 1-5"`).
|
|
1936
|
+
* @returns Parsed {@link CronSchedule} with one `Set<number>` per field.
|
|
1937
|
+
* @throws Error when the expression does not have exactly 5 fields, contains
|
|
1938
|
+
* out-of-range values, or uses an invalid step.
|
|
1939
|
+
*
|
|
1940
|
+
* @example
|
|
1941
|
+
* ```ts
|
|
1942
|
+
* import { parseCron } from "@graphrefly/graphrefly-ts";
|
|
1943
|
+
*
|
|
1944
|
+
* const sched = parseCron("0 9 * * 1-5"); // weekdays at 09:00
|
|
1945
|
+
* sched.hours; // Set { 9 }
|
|
1946
|
+
* sched.daysOfWeek; // Set { 1, 2, 3, 4, 5 }
|
|
1947
|
+
* ```
|
|
1948
|
+
*/
|
|
1949
|
+
declare function parseCron(expr: string): CronSchedule;
|
|
1950
|
+
/**
|
|
1951
|
+
* Returns `true` if `date` satisfies every field of `schedule`.
|
|
1952
|
+
*
|
|
1953
|
+
* @param schedule - Parsed schedule from {@link parseCron}.
|
|
1954
|
+
* @param date - Moment to test (local time via `getMinutes`, `getHours`, etc.).
|
|
1955
|
+
* @returns `true` when all five cron fields match the given date.
|
|
1956
|
+
*
|
|
1957
|
+
* @example
|
|
1958
|
+
* ```ts
|
|
1959
|
+
* import { parseCron, matchesCron } from "@graphrefly/graphrefly-ts";
|
|
1960
|
+
*
|
|
1961
|
+
* const sched = parseCron("30 8 * * 1"); // Mondays at 08:30
|
|
1962
|
+
* const monday = new Date("2026-03-30T08:30:00"); // a Monday
|
|
1963
|
+
* matchesCron(sched, monday); // true
|
|
1964
|
+
* ```
|
|
1965
|
+
*/
|
|
1966
|
+
declare function matchesCron(schedule: CronSchedule, date: Date): boolean;
|
|
1967
|
+
|
|
1968
|
+
/**
|
|
1969
|
+
* Tier 1 sync operators (roadmap §2.1) and Tier 2 async/dynamic operators (roadmap §2.2) —
|
|
1970
|
+
* each returns a {@link Node} built with {@link node} (or {@link producer} for cold sources).
|
|
1971
|
+
*/
|
|
1972
|
+
|
|
1973
|
+
type ExtraOpts = Omit<NodeOptions, "describeKind">;
|
|
1974
|
+
/**
|
|
1975
|
+
* Maps each settled value from `source` through `project`.
|
|
1976
|
+
*
|
|
1977
|
+
* @param source - Upstream node.
|
|
1978
|
+
* @param project - Transform for each value.
|
|
1979
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
1980
|
+
* @returns `Node<R>` - Derived node emitting mapped values.
|
|
1981
|
+
*
|
|
1982
|
+
* @example
|
|
1983
|
+
* ```ts
|
|
1984
|
+
* import { map, state } from "@graphrefly/graphrefly-ts";
|
|
1985
|
+
*
|
|
1986
|
+
* const n = map(state(2), (x) => x * 3);
|
|
1987
|
+
* ```
|
|
1988
|
+
*
|
|
1989
|
+
* @category extra
|
|
1990
|
+
*/
|
|
1991
|
+
declare function map<T, R>(source: Node<T>, project: (value: T) => R, opts?: ExtraOpts): Node<R>;
|
|
1992
|
+
/**
|
|
1993
|
+
* Forwards values that satisfy `predicate`; otherwise emits `RESOLVED` with no `DATA` (two-phase semantics).
|
|
1994
|
+
*
|
|
1995
|
+
* @param source - Upstream node.
|
|
1996
|
+
* @param predicate - Inclusion test.
|
|
1997
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
1998
|
+
* @returns `Node<T>` - Filtered node.
|
|
1999
|
+
*
|
|
2000
|
+
* @example
|
|
2001
|
+
* ```ts
|
|
2002
|
+
* import { filter, state } from "@graphrefly/graphrefly-ts";
|
|
2003
|
+
*
|
|
2004
|
+
* const n = filter(state(1), (x) => x > 0);
|
|
2005
|
+
* ```
|
|
2006
|
+
*
|
|
2007
|
+
* @category extra
|
|
2008
|
+
*/
|
|
2009
|
+
declare function filter<T>(source: Node<T>, predicate: (value: T) => boolean, opts?: ExtraOpts): Node<T>;
|
|
2010
|
+
/**
|
|
2011
|
+
* Folds each upstream value into an accumulator; emits the new accumulator every time.
|
|
2012
|
+
*
|
|
2013
|
+
* Unlike RxJS, `seed` is always required — there is no seedless mode where the first
|
|
2014
|
+
* value silently becomes the accumulator.
|
|
2015
|
+
*
|
|
2016
|
+
* @param source - Upstream node.
|
|
2017
|
+
* @param reducer - `(acc, value) => nextAcc`.
|
|
2018
|
+
* @param seed - Initial accumulator (required).
|
|
2019
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2020
|
+
* @returns `Node<R>` - Scan node.
|
|
2021
|
+
*
|
|
2022
|
+
* @example
|
|
2023
|
+
* ```ts
|
|
2024
|
+
* import { scan, state } from "@graphrefly/graphrefly-ts";
|
|
2025
|
+
*
|
|
2026
|
+
* const n = scan(state(1), (a, x) => a + x, 0);
|
|
2027
|
+
* ```
|
|
2028
|
+
*
|
|
2029
|
+
* @category extra
|
|
2030
|
+
*/
|
|
2031
|
+
declare function scan<T, R>(source: Node<T>, reducer: (acc: R, value: T) => R, seed: R, opts?: ExtraOpts): Node<R>;
|
|
2032
|
+
/**
|
|
2033
|
+
* Reduces to one value emitted when `source` completes; if no `DATA` arrived, emits `seed`.
|
|
2034
|
+
*
|
|
2035
|
+
* Unlike RxJS, `seed` is always required. If the source completes without emitting
|
|
2036
|
+
* DATA, the seed value is emitted (RxJS would throw without a seed).
|
|
2037
|
+
*
|
|
2038
|
+
* @param source - Upstream node.
|
|
2039
|
+
* @param reducer - `(acc, value) => nextAcc`.
|
|
2040
|
+
* @param seed - Empty-completion default and initial accumulator (required).
|
|
2041
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2042
|
+
* @returns `Node<R>` - Node that emits once on completion.
|
|
2043
|
+
*
|
|
2044
|
+
* @example
|
|
2045
|
+
* ```ts
|
|
2046
|
+
* import { reduce, state } from "@graphrefly/graphrefly-ts";
|
|
2047
|
+
*
|
|
2048
|
+
* const n = reduce(state(1), (a, x) => a + x, 0);
|
|
2049
|
+
* ```
|
|
2050
|
+
*
|
|
2051
|
+
* @category extra
|
|
2052
|
+
*/
|
|
2053
|
+
declare function reduce<T, R>(source: Node<T>, reducer: (acc: R, value: T) => R, seed: R, opts?: ExtraOpts): Node<R>;
|
|
2054
|
+
/**
|
|
2055
|
+
* Emits at most `count` **`DATA`** values, then **`COMPLETE`**. `RESOLVED` does not advance the counter.
|
|
2056
|
+
*
|
|
2057
|
+
* @param source - Upstream node.
|
|
2058
|
+
* @param count - Maximum `DATA` emissions (≤0 completes immediately).
|
|
2059
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2060
|
+
* @returns `Node<T>` - Limited stream.
|
|
2061
|
+
*
|
|
2062
|
+
* @example
|
|
2063
|
+
* ```ts
|
|
2064
|
+
* import { take, state } from "@graphrefly/graphrefly-ts";
|
|
2065
|
+
*
|
|
2066
|
+
* const n = take(state(0), 3);
|
|
2067
|
+
* ```
|
|
2068
|
+
*
|
|
2069
|
+
* @category extra
|
|
2070
|
+
*/
|
|
2071
|
+
declare function take<T>(source: Node<T>, count: number, opts?: ExtraOpts): Node<T>;
|
|
2072
|
+
/**
|
|
2073
|
+
* Skips the first `count` **`DATA`** emissions. `RESOLVED` does not advance the counter.
|
|
2074
|
+
*
|
|
2075
|
+
* @param source - Upstream node.
|
|
2076
|
+
* @param count - Number of `DATA` values to drop.
|
|
2077
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2078
|
+
* @returns `Node<T>` - Skipped stream.
|
|
2079
|
+
*
|
|
2080
|
+
* @example
|
|
2081
|
+
* ```ts
|
|
2082
|
+
* import { skip, state } from "@graphrefly/graphrefly-ts";
|
|
2083
|
+
*
|
|
2084
|
+
* const n = skip(state(0), 2);
|
|
2085
|
+
* ```
|
|
2086
|
+
*
|
|
2087
|
+
* @category extra
|
|
2088
|
+
*/
|
|
2089
|
+
declare function skip<T>(source: Node<T>, count: number, opts?: ExtraOpts): Node<T>;
|
|
2090
|
+
/**
|
|
2091
|
+
* Emits while `predicate` holds; on first false, sends **`COMPLETE`**.
|
|
2092
|
+
*
|
|
2093
|
+
* @param source - Upstream node.
|
|
2094
|
+
* @param predicate - Continuation test.
|
|
2095
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2096
|
+
* @returns `Node<T>` - Truncated stream.
|
|
2097
|
+
*
|
|
2098
|
+
* @example
|
|
2099
|
+
* ```ts
|
|
2100
|
+
* import { takeWhile, state } from "@graphrefly/graphrefly-ts";
|
|
2101
|
+
*
|
|
2102
|
+
* const n = takeWhile(state(1), (x) => x < 10);
|
|
2103
|
+
* ```
|
|
2104
|
+
*
|
|
2105
|
+
* @category extra
|
|
2106
|
+
*/
|
|
2107
|
+
declare function takeWhile<T>(source: Node<T>, predicate: (value: T) => boolean, opts?: ExtraOpts): Node<T>;
|
|
2108
|
+
/**
|
|
2109
|
+
* Forwards `source` until `notifier` matches `predicate` (default: notifier **`DATA`**), then **`COMPLETE`**.
|
|
2110
|
+
*
|
|
2111
|
+
* @param source - Main upstream.
|
|
2112
|
+
* @param notifier - Triggers completion when `predicate(msg)` is true.
|
|
2113
|
+
* @param opts - Optional {@link NodeOptions}, plus `predicate` for custom notifier matching.
|
|
2114
|
+
* @returns `Node<T>` - Truncated stream.
|
|
2115
|
+
*
|
|
2116
|
+
* @example
|
|
2117
|
+
* ```ts
|
|
2118
|
+
* import { producer, takeUntil, state } from "@graphrefly/graphrefly-ts";
|
|
2119
|
+
*
|
|
2120
|
+
* const src = state(1);
|
|
2121
|
+
* const stop = producer((_d, a) => a.emit(undefined));
|
|
2122
|
+
* const n = takeUntil(src, stop);
|
|
2123
|
+
* ```
|
|
2124
|
+
*
|
|
2125
|
+
* @category extra
|
|
2126
|
+
*/
|
|
2127
|
+
declare function takeUntil<T>(source: Node<T>, notifier: Node, opts?: ExtraOpts & {
|
|
2128
|
+
predicate?: (msg: Message) => boolean;
|
|
2129
|
+
}): Node<T>;
|
|
2130
|
+
/**
|
|
2131
|
+
* Emits the first **`DATA`** then **`COMPLETE`** (same as `take(source, 1)`).
|
|
2132
|
+
*
|
|
2133
|
+
* @param source - Upstream node.
|
|
2134
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2135
|
+
* @returns `Node<T>` - Single-value stream.
|
|
2136
|
+
*
|
|
2137
|
+
* @example
|
|
2138
|
+
* ```ts
|
|
2139
|
+
* import { first, state } from "@graphrefly/graphrefly-ts";
|
|
2140
|
+
*
|
|
2141
|
+
* const n = first(state(42));
|
|
2142
|
+
* ```
|
|
2143
|
+
*
|
|
2144
|
+
* @category extra
|
|
2145
|
+
*/
|
|
2146
|
+
declare function first<T>(source: Node<T>, opts?: ExtraOpts): Node<T>;
|
|
2147
|
+
/**
|
|
2148
|
+
* Buffers values and emits the last **`DATA`** on **`COMPLETE`**; optional `defaultValue` if none arrived.
|
|
2149
|
+
*
|
|
2150
|
+
* @param source - Upstream node.
|
|
2151
|
+
* @param options - Optional {@link NodeOptions} and `defaultValue` when empty.
|
|
2152
|
+
* @returns `Node<T>` - Last-or-default node.
|
|
2153
|
+
*
|
|
2154
|
+
* @example
|
|
2155
|
+
* ```ts
|
|
2156
|
+
* import { last, state } from "@graphrefly/graphrefly-ts";
|
|
2157
|
+
*
|
|
2158
|
+
* const n = last(state(1), { defaultValue: 0 });
|
|
2159
|
+
* ```
|
|
2160
|
+
*
|
|
2161
|
+
* @category extra
|
|
2162
|
+
*/
|
|
2163
|
+
declare function last<T>(source: Node<T>, options?: ExtraOpts & {
|
|
2164
|
+
defaultValue?: T;
|
|
2165
|
+
}): Node<T>;
|
|
2166
|
+
/**
|
|
2167
|
+
* Emits the first value matching `predicate`, then **`COMPLETE`**.
|
|
2168
|
+
*
|
|
2169
|
+
* @param source - Upstream node.
|
|
2170
|
+
* @param predicate - Match test.
|
|
2171
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2172
|
+
* @returns `Node<T>` - First-match stream.
|
|
2173
|
+
*
|
|
2174
|
+
* @example
|
|
2175
|
+
* ```ts
|
|
2176
|
+
* import { find, state } from "@graphrefly/graphrefly-ts";
|
|
2177
|
+
*
|
|
2178
|
+
* const n = find(state(1), (x) => x > 0);
|
|
2179
|
+
* ```
|
|
2180
|
+
*
|
|
2181
|
+
* @category extra
|
|
2182
|
+
*/
|
|
2183
|
+
declare function find<T>(source: Node<T>, predicate: (value: T) => boolean, opts?: ExtraOpts): Node<T>;
|
|
2184
|
+
/**
|
|
2185
|
+
* Emits the `index`th **`DATA`** (zero-based), then **`COMPLETE`**.
|
|
2186
|
+
*
|
|
2187
|
+
* @param source - Upstream node.
|
|
2188
|
+
* @param index - Zero-based emission index.
|
|
2189
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2190
|
+
* @returns `Node<T>` - Single indexed value.
|
|
2191
|
+
*
|
|
2192
|
+
* @example
|
|
2193
|
+
* ```ts
|
|
2194
|
+
* import { elementAt, state } from "@graphrefly/graphrefly-ts";
|
|
2195
|
+
*
|
|
2196
|
+
* const n = elementAt(state(0), 2);
|
|
2197
|
+
* ```
|
|
2198
|
+
*
|
|
2199
|
+
* @category extra
|
|
2200
|
+
*/
|
|
2201
|
+
declare function elementAt<T>(source: Node<T>, index: number, opts?: ExtraOpts): Node<T>;
|
|
2202
|
+
/**
|
|
2203
|
+
* Prepends `initial` as **`DATA`**, then forwards every value from `source`.
|
|
2204
|
+
*
|
|
2205
|
+
* @param source - Upstream node.
|
|
2206
|
+
* @param initial - Value emitted before upstream.
|
|
2207
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2208
|
+
* @returns `Node<T>` - Prefixed stream.
|
|
2209
|
+
*
|
|
2210
|
+
* @example
|
|
2211
|
+
* ```ts
|
|
2212
|
+
* import { startWith, state } from "@graphrefly/graphrefly-ts";
|
|
2213
|
+
*
|
|
2214
|
+
* const n = startWith(state(2), 0);
|
|
2215
|
+
* ```
|
|
2216
|
+
*
|
|
2217
|
+
* @category extra
|
|
2218
|
+
*/
|
|
2219
|
+
declare function startWith<T>(source: Node<T>, initial: T, opts?: ExtraOpts): Node<T>;
|
|
2220
|
+
/**
|
|
2221
|
+
* Observer shape for {@link tap} — side effects for data, error, and/or complete.
|
|
2222
|
+
*/
|
|
2223
|
+
type TapObserver<T> = {
|
|
2224
|
+
data?: (value: T) => void;
|
|
2225
|
+
error?: (err: unknown) => void;
|
|
2226
|
+
complete?: () => void;
|
|
2227
|
+
};
|
|
2228
|
+
/**
|
|
2229
|
+
* Invokes side effects; values pass through unchanged.
|
|
2230
|
+
*
|
|
2231
|
+
* Accepts either a function (called on each DATA) or an observer object
|
|
2232
|
+
* `{ data?, error?, complete? }` for lifecycle-aware side effects.
|
|
2233
|
+
*
|
|
2234
|
+
* @param source - Upstream node.
|
|
2235
|
+
* @param fnOrObserver - Side effect function or observer object.
|
|
2236
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2237
|
+
* @returns `Node<T>` - Passthrough node.
|
|
2238
|
+
*
|
|
2239
|
+
* @example
|
|
2240
|
+
* ```ts
|
|
2241
|
+
* import { tap, state } from "@graphrefly/graphrefly-ts";
|
|
2242
|
+
*
|
|
2243
|
+
* // Function form (DATA only)
|
|
2244
|
+
* tap(state(1), (x) => console.log(x));
|
|
2245
|
+
*
|
|
2246
|
+
* // Observer form (DATA + ERROR + COMPLETE)
|
|
2247
|
+
* tap(state(1), { data: console.log, error: console.error, complete: () => console.log("done") });
|
|
2248
|
+
* ```
|
|
2249
|
+
*
|
|
2250
|
+
* @category extra
|
|
2251
|
+
*/
|
|
2252
|
+
declare function tap<T>(source: Node<T>, fnOrObserver: ((value: T) => void) | TapObserver<T>, opts?: ExtraOpts): Node<T>;
|
|
2253
|
+
/**
|
|
2254
|
+
* Suppresses adjacent duplicates using `equals` (default `Object.is`).
|
|
2255
|
+
*
|
|
2256
|
+
* @param source - Upstream node.
|
|
2257
|
+
* @param equals - Optional equality for consecutive values.
|
|
2258
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2259
|
+
* @returns `Node<T>` - Deduped stream.
|
|
2260
|
+
*
|
|
2261
|
+
* @example
|
|
2262
|
+
* ```ts
|
|
2263
|
+
* import { distinctUntilChanged, state } from "@graphrefly/graphrefly-ts";
|
|
2264
|
+
*
|
|
2265
|
+
* const n = distinctUntilChanged(state(1));
|
|
2266
|
+
* ```
|
|
2267
|
+
*
|
|
2268
|
+
* @category extra
|
|
2269
|
+
*/
|
|
2270
|
+
declare function distinctUntilChanged<T>(source: Node<T>, equals?: (a: T, b: T) => boolean, opts?: ExtraOpts): Node<T>;
|
|
2271
|
+
/**
|
|
2272
|
+
* Emits `[previous, current]` pairs starting after the second value (first pair uses `RESOLVED` only).
|
|
2273
|
+
*
|
|
2274
|
+
* @param source - Upstream node.
|
|
2275
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2276
|
+
* @returns `Node<readonly [T, T]>` - Pair stream.
|
|
2277
|
+
*
|
|
2278
|
+
* @example
|
|
2279
|
+
* ```ts
|
|
2280
|
+
* import { pairwise, state } from "@graphrefly/graphrefly-ts";
|
|
2281
|
+
*
|
|
2282
|
+
* const n = pairwise(state(0));
|
|
2283
|
+
* ```
|
|
2284
|
+
*
|
|
2285
|
+
* @category extra
|
|
2286
|
+
*/
|
|
2287
|
+
declare function pairwise<T>(source: Node<T>, opts?: ExtraOpts): Node<readonly [T, T]>;
|
|
2288
|
+
/**
|
|
2289
|
+
* Combines the latest value from each dependency whenever any dep settles (combineLatest).
|
|
2290
|
+
*
|
|
2291
|
+
* @param sources - Nodes to combine (variadic).
|
|
2292
|
+
* @returns `Node<T>` - Tuple of latest values.
|
|
2293
|
+
*
|
|
2294
|
+
* @example
|
|
2295
|
+
* ```ts
|
|
2296
|
+
* import { combine, state } from "@graphrefly/graphrefly-ts";
|
|
2297
|
+
*
|
|
2298
|
+
* const n = combine(state(1), state("a"));
|
|
2299
|
+
* ```
|
|
2300
|
+
*
|
|
2301
|
+
* @remarks
|
|
2302
|
+
* Unlike RxJS `combineLatest`, this is named `combine`. Use the {@link combineLatest} alias
|
|
2303
|
+
* if you prefer the RxJS name. Seed is always required for `scan`/`reduce` (no seedless mode).
|
|
2304
|
+
*
|
|
2305
|
+
* @category extra
|
|
2306
|
+
*/
|
|
2307
|
+
declare function combine<const T extends readonly unknown[]>(...sources: {
|
|
2308
|
+
[K in keyof T]: Node<T[K]>;
|
|
2309
|
+
}): Node<T>;
|
|
2310
|
+
/**
|
|
2311
|
+
* When `primary` settles, emits `[primary, latestSecondary]`. `secondary` alone updates cache only.
|
|
2312
|
+
*
|
|
2313
|
+
* @param primary - Main stream.
|
|
2314
|
+
* @param secondary - Latest value is paired on each primary emission.
|
|
2315
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2316
|
+
* @returns `Node<readonly [A, B]>` - Paired stream.
|
|
2317
|
+
*
|
|
2318
|
+
* @example
|
|
2319
|
+
* ```ts
|
|
2320
|
+
* import { state, withLatestFrom } from "@graphrefly/graphrefly-ts";
|
|
2321
|
+
*
|
|
2322
|
+
* const n = withLatestFrom(state(1), state("x"));
|
|
2323
|
+
* ```
|
|
2324
|
+
*
|
|
2325
|
+
* @category extra
|
|
2326
|
+
*/
|
|
2327
|
+
declare function withLatestFrom<A, B>(primary: Node<A>, secondary: Node<B>, opts?: ExtraOpts): Node<readonly [A, B]>;
|
|
2328
|
+
/**
|
|
2329
|
+
* Merges **`DATA`** from any source with correct two-phase dirty tracking. **`COMPLETE`** after **all** sources complete (spec §1.3.5).
|
|
2330
|
+
*
|
|
2331
|
+
* @param sources - Nodes to merge (variadic; empty completes immediately).
|
|
2332
|
+
* @returns `Node<T>` - Merged stream.
|
|
2333
|
+
*
|
|
2334
|
+
* @remarks
|
|
2335
|
+
* **Ordering:** DIRTY/RESOLVED rules follow multi-source semantics in `~/src/graphrefly/GRAPHREFLY-SPEC.md`.
|
|
2336
|
+
*
|
|
2337
|
+
* @example
|
|
2338
|
+
* ```ts
|
|
2339
|
+
* import { merge, state } from "@graphrefly/graphrefly-ts";
|
|
2340
|
+
*
|
|
2341
|
+
* const n = merge(state(1), state(2));
|
|
2342
|
+
* ```
|
|
2343
|
+
*
|
|
2344
|
+
* @category extra
|
|
2345
|
+
*/
|
|
2346
|
+
declare function merge<T>(...sources: readonly Node<T>[]): Node<T>;
|
|
2347
|
+
/**
|
|
2348
|
+
* Zips one **`DATA`** from each source per cycle into a tuple. Only **`DATA`** enqueues (spec §1.3.3).
|
|
2349
|
+
*
|
|
2350
|
+
* @param sources - Nodes to zip (variadic).
|
|
2351
|
+
* @returns `Node<T>` - Zipped tuples.
|
|
2352
|
+
*
|
|
2353
|
+
* @example
|
|
2354
|
+
* ```ts
|
|
2355
|
+
* import { state, zip } from "@graphrefly/graphrefly-ts";
|
|
2356
|
+
*
|
|
2357
|
+
* const n = zip(state(1), state(2));
|
|
2358
|
+
* ```
|
|
2359
|
+
*
|
|
2360
|
+
* @category extra
|
|
2361
|
+
*/
|
|
2362
|
+
declare function zip<const T extends readonly unknown[]>(...sources: {
|
|
2363
|
+
[K in keyof T]: Node<T[K]>;
|
|
2364
|
+
}): Node<T>;
|
|
2365
|
+
/**
|
|
2366
|
+
* Plays all of `firstSrc`, then all of `secondSrc`. **`DATA`** from `secondSrc` during phase one is buffered until handoff.
|
|
2367
|
+
*
|
|
2368
|
+
* @param firstSrc - First segment.
|
|
2369
|
+
* @param secondSrc - Second segment.
|
|
2370
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2371
|
+
* @returns `Node<T>` - Concatenated stream.
|
|
2372
|
+
*
|
|
2373
|
+
* @example
|
|
2374
|
+
* ```ts
|
|
2375
|
+
* import { concat, state } from "@graphrefly/graphrefly-ts";
|
|
2376
|
+
*
|
|
2377
|
+
* const n = concat(state(1), state(2));
|
|
2378
|
+
* ```
|
|
2379
|
+
*
|
|
2380
|
+
* @category extra
|
|
2381
|
+
*/
|
|
2382
|
+
declare function concat<T>(firstSrc: Node<T>, secondSrc: Node<T>, opts?: ExtraOpts): Node<T>;
|
|
2383
|
+
/**
|
|
2384
|
+
* First source to emit **`DATA`** wins; later traffic follows only the winner (Rx-style `race`).
|
|
2385
|
+
*
|
|
2386
|
+
* @param sources - Contestants (variadic; empty completes immediately; one node is identity).
|
|
2387
|
+
* @returns `Node<T>` - Winning stream.
|
|
2388
|
+
*
|
|
2389
|
+
* @example
|
|
2390
|
+
* ```ts
|
|
2391
|
+
* import { race, state } from "@graphrefly/graphrefly-ts";
|
|
2392
|
+
*
|
|
2393
|
+
* const n = race(state(1), state(2));
|
|
2394
|
+
* ```
|
|
2395
|
+
*
|
|
2396
|
+
* @category extra
|
|
2397
|
+
*/
|
|
2398
|
+
declare function race<T>(...sources: readonly Node<T>[]): Node<T>;
|
|
2399
|
+
/**
|
|
2400
|
+
* Maps each settled value to an inner node; unsubscribes the previous inner (Rx-style `switchMap`).
|
|
2401
|
+
*
|
|
2402
|
+
* @param source - Upstream node.
|
|
2403
|
+
* @param project - Maps each outer value to an inner source shape (`Node`, scalar, `PromiseLike`, `Iterable`, or `AsyncIterable`) coerced via {@link fromAny}.
|
|
2404
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2405
|
+
* @returns `Node<R>` - Emissions from the active inner subscription.
|
|
2406
|
+
* @example
|
|
2407
|
+
* ```ts
|
|
2408
|
+
* import { switchMap, state } from "@graphrefly/graphrefly-ts";
|
|
2409
|
+
*
|
|
2410
|
+
* const src = state(0);
|
|
2411
|
+
* switchMap(src, (n) => state((n as number) * 2));
|
|
2412
|
+
* ```
|
|
2413
|
+
*
|
|
2414
|
+
* @category extra
|
|
2415
|
+
*/
|
|
2416
|
+
declare function switchMap<T, R>(source: Node<T>, project: (value: T) => NodeInput<R>, opts?: ExtraOpts): Node<R>;
|
|
2417
|
+
/**
|
|
2418
|
+
* Like {@link switchMap}, but ignores outer `DATA` while an inner subscription is active (`exhaustMap`).
|
|
2419
|
+
*
|
|
2420
|
+
* @param source - Upstream node.
|
|
2421
|
+
* @param project - Maps each outer value to an inner source shape (`Node`, scalar, `PromiseLike`, `Iterable`, or `AsyncIterable`) coerced via {@link fromAny}.
|
|
2422
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2423
|
+
* @returns `Node<R>` - Emissions from the active inner while it runs.
|
|
2424
|
+
* @example
|
|
2425
|
+
* ```ts
|
|
2426
|
+
* import { exhaustMap, state } from "@graphrefly/graphrefly-ts";
|
|
2427
|
+
*
|
|
2428
|
+
* exhaustMap(state(0), () => state(1));
|
|
2429
|
+
* ```
|
|
2430
|
+
*
|
|
2431
|
+
* @category extra
|
|
2432
|
+
*/
|
|
2433
|
+
declare function exhaustMap<T, R>(source: Node<T>, project: (value: T) => NodeInput<R>, opts?: ExtraOpts): Node<R>;
|
|
2434
|
+
/**
|
|
2435
|
+
* Enqueues each outer value and subscribes to inners one at a time (`concatMap`).
|
|
2436
|
+
*
|
|
2437
|
+
* @param source - Upstream node.
|
|
2438
|
+
* @param project - Maps each outer value to an inner source shape (`Node`, scalar, `PromiseLike`, `Iterable`, or `AsyncIterable`) coerced via {@link fromAny}.
|
|
2439
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2440
|
+
* @returns `Node<R>` - Sequential concatenation of inner streams.
|
|
2441
|
+
* @example
|
|
2442
|
+
* ```ts
|
|
2443
|
+
* import { concatMap, state } from "@graphrefly/graphrefly-ts";
|
|
2444
|
+
*
|
|
2445
|
+
* concatMap(state(0), (n) => state((n as number) + 1));
|
|
2446
|
+
* ```
|
|
2447
|
+
*
|
|
2448
|
+
* @category extra
|
|
2449
|
+
*/
|
|
2450
|
+
declare function concatMap<T, R>(source: Node<T>, project: (value: T) => NodeInput<R>, opts?: ExtraOpts & {
|
|
2451
|
+
maxBuffer?: number;
|
|
2452
|
+
}): Node<R>;
|
|
2453
|
+
/** Options for {@link mergeMap}. */
|
|
2454
|
+
type MergeMapOptions = ExtraOpts & {
|
|
2455
|
+
/** Maximum number of concurrent inner subscriptions. Default: `Infinity` (unbounded). */
|
|
2456
|
+
concurrent?: number;
|
|
2457
|
+
};
|
|
2458
|
+
/**
|
|
2459
|
+
* Subscribes to inner nodes in parallel (up to `concurrent`) and merges outputs (`mergeMap` / `flatMap`).
|
|
2460
|
+
*
|
|
2461
|
+
* @param source - Upstream node.
|
|
2462
|
+
* @param project - Maps each outer value to an inner source shape (`Node`, scalar, `PromiseLike`, `Iterable`, or `AsyncIterable`) coerced via {@link fromAny}.
|
|
2463
|
+
* @param opts - Optional options including `concurrent` limit.
|
|
2464
|
+
* @returns `Node<R>` - Merged output of all active inners; completes when the outer and every inner complete.
|
|
2465
|
+
* @example
|
|
2466
|
+
* ```ts
|
|
2467
|
+
* import { mergeMap, state } from "@graphrefly/graphrefly-ts";
|
|
2468
|
+
*
|
|
2469
|
+
* // Unbounded (default)
|
|
2470
|
+
* mergeMap(state(0), (n) => state((n as number) + 1));
|
|
2471
|
+
*
|
|
2472
|
+
* // Limited concurrency
|
|
2473
|
+
* mergeMap(state(0), (n) => state((n as number) + 1), { concurrent: 3 });
|
|
2474
|
+
* ```
|
|
2475
|
+
*
|
|
2476
|
+
* @category extra
|
|
2477
|
+
*/
|
|
2478
|
+
declare function mergeMap<T, R>(source: Node<T>, project: (value: T) => NodeInput<R>, opts?: MergeMapOptions): Node<R>;
|
|
2479
|
+
/**
|
|
2480
|
+
* RxJS-named alias for {@link mergeMap} — projects each `DATA` to an inner node and merges outputs.
|
|
2481
|
+
*
|
|
2482
|
+
* @param source - Upstream node.
|
|
2483
|
+
* @param project - Returns an inner `Node<R>` per value.
|
|
2484
|
+
* @param opts - Optional concurrency cap and node options (excluding `describeKind`).
|
|
2485
|
+
* @returns Merged projection; behavior matches `mergeMap`.
|
|
2486
|
+
*
|
|
2487
|
+
* @example
|
|
2488
|
+
* ```ts
|
|
2489
|
+
* import { flatMap, state } from "@graphrefly/graphrefly-ts";
|
|
2490
|
+
*
|
|
2491
|
+
* flatMap(state(0), (n) => state(n));
|
|
2492
|
+
* ```
|
|
2493
|
+
*
|
|
2494
|
+
* @category extra
|
|
2495
|
+
*/
|
|
2496
|
+
declare const flatMap: typeof mergeMap;
|
|
2497
|
+
/**
|
|
2498
|
+
* Delays phase-2 emissions by `ms` (timers). `DIRTY` still forwards immediately.
|
|
2499
|
+
*
|
|
2500
|
+
* @param source - Upstream node.
|
|
2501
|
+
* @param ms - Delay in milliseconds.
|
|
2502
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2503
|
+
* @returns `Node<T>` - Same values, shifted in time.
|
|
2504
|
+
* @example
|
|
2505
|
+
* ```ts
|
|
2506
|
+
* import { delay, state } from "@graphrefly/graphrefly-ts";
|
|
2507
|
+
*
|
|
2508
|
+
* delay(state(1), 100);
|
|
2509
|
+
* ```
|
|
2510
|
+
*
|
|
2511
|
+
* @category extra
|
|
2512
|
+
*/
|
|
2513
|
+
declare function delay<T>(source: Node<T>, ms: number, opts?: ExtraOpts): Node<T>;
|
|
2514
|
+
/**
|
|
2515
|
+
* Emits the latest value only after `ms` quiet time since the last trigger (`debounce`).
|
|
2516
|
+
*
|
|
2517
|
+
* @param source - Upstream node.
|
|
2518
|
+
* @param ms - Quiet window in milliseconds.
|
|
2519
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2520
|
+
* @returns `Node<T>` - Debounced stream.
|
|
2521
|
+
* @example
|
|
2522
|
+
* ```ts
|
|
2523
|
+
* import { debounce, state } from "@graphrefly/graphrefly-ts";
|
|
2524
|
+
*
|
|
2525
|
+
* debounce(state(0), 50);
|
|
2526
|
+
* ```
|
|
2527
|
+
*
|
|
2528
|
+
* @category extra
|
|
2529
|
+
*/
|
|
2530
|
+
declare function debounce<T>(source: Node<T>, ms: number, opts?: ExtraOpts): Node<T>;
|
|
2531
|
+
type ThrottleOptions = {
|
|
2532
|
+
leading?: boolean;
|
|
2533
|
+
trailing?: boolean;
|
|
2534
|
+
};
|
|
2535
|
+
/**
|
|
2536
|
+
* Rate-limits emissions to at most once per `ms` window (`throttleTime`).
|
|
2537
|
+
*
|
|
2538
|
+
* @param source - Upstream node.
|
|
2539
|
+
* @param ms - Minimum spacing in milliseconds.
|
|
2540
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`) plus `leading` / `trailing`.
|
|
2541
|
+
* @returns `Node<T>` - Throttled stream.
|
|
2542
|
+
* @example
|
|
2543
|
+
* ```ts
|
|
2544
|
+
* import { throttle, state } from "@graphrefly/graphrefly-ts";
|
|
2545
|
+
*
|
|
2546
|
+
* throttle(state(0), 1_000, { trailing: false });
|
|
2547
|
+
* ```
|
|
2548
|
+
*
|
|
2549
|
+
* @category extra
|
|
2550
|
+
*/
|
|
2551
|
+
declare function throttle<T>(source: Node<T>, ms: number, opts?: ExtraOpts & ThrottleOptions): Node<T>;
|
|
2552
|
+
/**
|
|
2553
|
+
* Emits the most recent source value whenever `notifier` settles (`sample`).
|
|
2554
|
+
*
|
|
2555
|
+
* @param source - Node whose latest value is sampled.
|
|
2556
|
+
* @param notifier - When this node settles (`DATA` / `RESOLVED`), a sample is taken.
|
|
2557
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2558
|
+
* @returns `Node<T>` - Sampled snapshots of `source`.
|
|
2559
|
+
* @remarks **Undefined payload:** If `T` includes `undefined`, `get() === undefined` is treated as “no snapshot” and the operator emits `RESOLVED` instead of `DATA`.
|
|
2560
|
+
* @example
|
|
2561
|
+
* ```ts
|
|
2562
|
+
* import { sample, state } from "@graphrefly/graphrefly-ts";
|
|
2563
|
+
*
|
|
2564
|
+
* sample(state(1), state(0));
|
|
2565
|
+
* ```
|
|
2566
|
+
*
|
|
2567
|
+
* @category extra
|
|
2568
|
+
*/
|
|
2569
|
+
declare function sample<T>(source: Node<T>, notifier: Node<unknown>, opts?: ExtraOpts): Node<T>;
|
|
2570
|
+
/**
|
|
2571
|
+
* After each source `DATA`, waits `ms` then emits the latest value if another `DATA` has not arrived (`auditTime` / trailing window).
|
|
2572
|
+
*
|
|
2573
|
+
* @param source - Upstream node.
|
|
2574
|
+
* @param ms - Window in milliseconds after each `DATA`.
|
|
2575
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2576
|
+
* @returns `Node<T>` - Trailing-edge sampled stream.
|
|
2577
|
+
* @example
|
|
2578
|
+
* ```ts
|
|
2579
|
+
* import { audit, state } from "@graphrefly/graphrefly-ts";
|
|
2580
|
+
*
|
|
2581
|
+
* audit(state(0), 100);
|
|
2582
|
+
* ```
|
|
2583
|
+
*
|
|
2584
|
+
* @category extra
|
|
2585
|
+
*/
|
|
2586
|
+
declare function audit<T>(source: Node<T>, ms: number, opts?: ExtraOpts): Node<T>;
|
|
2587
|
+
/**
|
|
2588
|
+
* Errors if no `DATA` arrives within `ms` after subscribe or after the previous `DATA`.
|
|
2589
|
+
*
|
|
2590
|
+
* @param source - Upstream node.
|
|
2591
|
+
* @param ms - Idle budget in milliseconds.
|
|
2592
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`) and `with` for a custom error payload.
|
|
2593
|
+
* @returns `Node<T>` - Pass-through with idle watchdog.
|
|
2594
|
+
* @example
|
|
2595
|
+
* ```ts
|
|
2596
|
+
* import { timeout, state } from "@graphrefly/graphrefly-ts";
|
|
2597
|
+
*
|
|
2598
|
+
* timeout(state(0), 5_000);
|
|
2599
|
+
* ```
|
|
2600
|
+
*
|
|
2601
|
+
* @category extra
|
|
2602
|
+
*/
|
|
2603
|
+
declare function timeout<T>(source: Node<T>, ms: number, opts?: ExtraOpts & {
|
|
2604
|
+
with?: unknown;
|
|
2605
|
+
}): Node<T>;
|
|
2606
|
+
/**
|
|
2607
|
+
* Buffers source `DATA` values; flushes an array when `notifier` settles (`buffer`).
|
|
2608
|
+
*
|
|
2609
|
+
* @param source - Upstream node.
|
|
2610
|
+
* @param notifier - Flush trigger on each settlement.
|
|
2611
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2612
|
+
* @returns `Node<T[]>` - Emits buffered arrays (may be empty-handled via `RESOLVED` when nothing buffered).
|
|
2613
|
+
* @example
|
|
2614
|
+
* ```ts
|
|
2615
|
+
* import { buffer, state } from "@graphrefly/graphrefly-ts";
|
|
2616
|
+
*
|
|
2617
|
+
* buffer(state(0), state(0));
|
|
2618
|
+
* ```
|
|
2619
|
+
*
|
|
2620
|
+
* @category extra
|
|
2621
|
+
*/
|
|
2622
|
+
declare function buffer<T>(source: Node<T>, notifier: Node<unknown>, opts?: ExtraOpts): Node<T[]>;
|
|
2623
|
+
/**
|
|
2624
|
+
* Batches consecutive `DATA` values into arrays of length `count` (`bufferCount` / `windowCount`).
|
|
2625
|
+
*
|
|
2626
|
+
* @param source - Upstream node.
|
|
2627
|
+
* @param count - Buffer size before emit; must be > 0.
|
|
2628
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2629
|
+
* @returns `Node<T[]>` - Emits fixed-size arrays; remainder flushes on `COMPLETE`.
|
|
2630
|
+
* @example
|
|
2631
|
+
* ```ts
|
|
2632
|
+
* import { bufferCount, state } from "@graphrefly/graphrefly-ts";
|
|
2633
|
+
*
|
|
2634
|
+
* bufferCount(state(0), 3);
|
|
2635
|
+
* ```
|
|
2636
|
+
*
|
|
2637
|
+
* @category extra
|
|
2638
|
+
*/
|
|
2639
|
+
declare function bufferCount<T>(source: Node<T>, count: number, opts?: ExtraOpts): Node<T[]>;
|
|
2640
|
+
/**
|
|
2641
|
+
* Splits source `DATA` into sub-nodes of `count` values each. Each sub-node completes after `count` items or when source completes.
|
|
2642
|
+
*
|
|
2643
|
+
* @param source - Upstream node.
|
|
2644
|
+
* @param count - Items per window.
|
|
2645
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2646
|
+
* @returns `Node<Node<T>>` - Each emission is a sub-node carrying that window's values.
|
|
2647
|
+
*
|
|
2648
|
+
* @example
|
|
2649
|
+
* ```ts
|
|
2650
|
+
* import { windowCount, state } from "@graphrefly/graphrefly-ts";
|
|
2651
|
+
*
|
|
2652
|
+
* windowCount(state(0), 3);
|
|
2653
|
+
* ```
|
|
2654
|
+
*
|
|
2655
|
+
* @category extra
|
|
2656
|
+
*/
|
|
2657
|
+
declare function windowCount<T>(source: Node<T>, count: number, opts?: ExtraOpts): Node<Node<T>>;
|
|
2658
|
+
/**
|
|
2659
|
+
* Flushes buffered `DATA` values every `ms` (`bufferTime` / `windowTime`).
|
|
2660
|
+
*
|
|
2661
|
+
* @param source - Upstream node.
|
|
2662
|
+
* @param ms - Flush interval in milliseconds.
|
|
2663
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2664
|
+
* @returns `Node<T[]>` - Time-windowed batches.
|
|
2665
|
+
* @example
|
|
2666
|
+
* ```ts
|
|
2667
|
+
* import { bufferTime, state } from "@graphrefly/graphrefly-ts";
|
|
2668
|
+
*
|
|
2669
|
+
* bufferTime(state(0), 250);
|
|
2670
|
+
* ```
|
|
2671
|
+
*
|
|
2672
|
+
* @category extra
|
|
2673
|
+
*/
|
|
2674
|
+
declare function bufferTime<T>(source: Node<T>, ms: number, opts?: ExtraOpts): Node<T[]>;
|
|
2675
|
+
/**
|
|
2676
|
+
* Splits source `DATA` into time-windowed sub-nodes; each window lasts `ms`.
|
|
2677
|
+
*
|
|
2678
|
+
* @param source - Upstream node.
|
|
2679
|
+
* @param ms - Window duration in milliseconds.
|
|
2680
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2681
|
+
* @returns `Node<Node<T>>` - Each emission is a sub-node carrying that window's values.
|
|
2682
|
+
*
|
|
2683
|
+
* @example
|
|
2684
|
+
* ```ts
|
|
2685
|
+
* import { windowTime, state } from "@graphrefly/graphrefly-ts";
|
|
2686
|
+
*
|
|
2687
|
+
* windowTime(state(0), 500);
|
|
2688
|
+
* ```
|
|
2689
|
+
*
|
|
2690
|
+
* @category extra
|
|
2691
|
+
*/
|
|
2692
|
+
declare function windowTime<T>(source: Node<T>, ms: number, opts?: ExtraOpts): Node<Node<T>>;
|
|
2693
|
+
/**
|
|
2694
|
+
* Splits source `DATA` into sub-nodes, opening a new window each time `notifier` emits `DATA`.
|
|
2695
|
+
*
|
|
2696
|
+
* @param source - Upstream node.
|
|
2697
|
+
* @param notifier - Each `DATA` from `notifier` closes the current window and opens a new one.
|
|
2698
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2699
|
+
* @returns `Node<Node<T>>` - Each emission is a sub-node carrying that window's values.
|
|
2700
|
+
*
|
|
2701
|
+
* @example
|
|
2702
|
+
* ```ts
|
|
2703
|
+
* import { state, window } from "@graphrefly/graphrefly-ts";
|
|
2704
|
+
*
|
|
2705
|
+
* window(state(0), state(0));
|
|
2706
|
+
* ```
|
|
2707
|
+
*
|
|
2708
|
+
* @category extra
|
|
2709
|
+
*/
|
|
2710
|
+
declare function window<T>(source: Node<T>, notifier: Node<unknown>, opts?: ExtraOpts): Node<Node<T>>;
|
|
2711
|
+
/**
|
|
2712
|
+
* Increments on each tick (`interval`); uses `setInterval` via {@link producer}.
|
|
2713
|
+
*
|
|
2714
|
+
* @param periodMs - Time between ticks.
|
|
2715
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2716
|
+
* @returns `Node<number>` - Emits `0`, `1`, `2`, … while subscribed.
|
|
2717
|
+
* @example
|
|
2718
|
+
* ```ts
|
|
2719
|
+
* import { interval } from "@graphrefly/graphrefly-ts";
|
|
2720
|
+
*
|
|
2721
|
+
* interval(1_000);
|
|
2722
|
+
* ```
|
|
2723
|
+
*
|
|
2724
|
+
* @category extra
|
|
2725
|
+
*/
|
|
2726
|
+
declare function interval(periodMs: number, opts?: ExtraOpts): Node<number>;
|
|
2727
|
+
/**
|
|
2728
|
+
* Subscribes to `source` repeatedly (`count` times, sequentially). Best with a fresh or `resubscribable` source.
|
|
2729
|
+
*
|
|
2730
|
+
* @param source - Upstream node to replay.
|
|
2731
|
+
* @param count - Number of subscription rounds.
|
|
2732
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2733
|
+
* @returns `Node<T>` - Forwards each round then completes after the last inner `COMPLETE`.
|
|
2734
|
+
* @example
|
|
2735
|
+
* ```ts
|
|
2736
|
+
* import { repeat, state } from "@graphrefly/graphrefly-ts";
|
|
2737
|
+
*
|
|
2738
|
+
* repeat(state(1, { resubscribable: true }), 2);
|
|
2739
|
+
* ```
|
|
2740
|
+
*
|
|
2741
|
+
* @category extra
|
|
2742
|
+
*/
|
|
2743
|
+
declare function repeat<T>(source: Node<T>, count: number, opts?: ExtraOpts): Node<T>;
|
|
2744
|
+
/**
|
|
2745
|
+
* While `PAUSE` is in effect, buffers `DIRTY` / `DATA` / `RESOLVED`; flushes on `RESUME`.
|
|
2746
|
+
*
|
|
2747
|
+
* @param source - Upstream node.
|
|
2748
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2749
|
+
* @returns `Node<T>` - Pass-through with pause buffering.
|
|
2750
|
+
* @example
|
|
2751
|
+
* ```ts
|
|
2752
|
+
* import { pausable, state, PAUSE, RESUME } from "@graphrefly/graphrefly-ts";
|
|
2753
|
+
*
|
|
2754
|
+
* const s = state(0);
|
|
2755
|
+
* pausable(s);
|
|
2756
|
+
* s.down([[PAUSE]]);
|
|
2757
|
+
* s.down([[RESUME]]);
|
|
2758
|
+
* ```
|
|
2759
|
+
*
|
|
2760
|
+
* @category extra
|
|
2761
|
+
*/
|
|
2762
|
+
declare function pausable<T>(source: Node<T>, opts?: ExtraOpts): Node<T>;
|
|
2763
|
+
/**
|
|
2764
|
+
* Replaces an upstream `ERROR` with a recovered value (`catchError`-style).
|
|
2765
|
+
*
|
|
2766
|
+
* @param source - Upstream node.
|
|
2767
|
+
* @param recover - Maps the error payload to a replacement value; if it throws, `ERROR` is forwarded.
|
|
2768
|
+
* @param opts - Optional {@link NodeOptions} (excluding `describeKind`).
|
|
2769
|
+
* @returns `Node<T>` - Recovered stream.
|
|
2770
|
+
* @example
|
|
2771
|
+
* ```ts
|
|
2772
|
+
* import { rescue, state } from "@graphrefly/graphrefly-ts";
|
|
2773
|
+
*
|
|
2774
|
+
* rescue(state(0), () => 0);
|
|
2775
|
+
* ```
|
|
2776
|
+
*
|
|
2777
|
+
* @category extra
|
|
2778
|
+
*/
|
|
2779
|
+
declare function rescue<T>(source: Node<T>, recover: (err: unknown) => T, opts?: ExtraOpts): Node<T>;
|
|
2780
|
+
/**
|
|
2781
|
+
* Forwards upstream `DATA` only while `control.get()` is truthy; when closed, emits `RESOLVED`
|
|
2782
|
+
* instead of repeating the last value (value-level gate). For protocol pause/resume, use {@link pausable}.
|
|
2783
|
+
*
|
|
2784
|
+
* @param source - Upstream value node.
|
|
2785
|
+
* @param control - Boolean node; when falsy, output stays “closed” for that tick.
|
|
2786
|
+
* @param opts - Optional node options (excluding `describeKind`).
|
|
2787
|
+
* @returns `Node<T>` gated by `control`.
|
|
2788
|
+
*
|
|
2789
|
+
* @example
|
|
2790
|
+
* ```ts
|
|
2791
|
+
* import { gate, state } from "@graphrefly/graphrefly-ts";
|
|
2792
|
+
*
|
|
2793
|
+
* const data = state(1);
|
|
2794
|
+
* const open = state(true);
|
|
2795
|
+
* gate(data, open);
|
|
2796
|
+
* ```
|
|
2797
|
+
*
|
|
2798
|
+
* @category extra
|
|
2799
|
+
*/
|
|
2800
|
+
declare function gate<T>(source: Node<T>, control: Node<boolean>, opts?: ExtraOpts): Node<T>;
|
|
2801
|
+
/**
|
|
2802
|
+
* RxJS-named alias for {@link combine} — emits when any dep updates with latest tuple of values.
|
|
2803
|
+
*
|
|
2804
|
+
* @param sources - Upstream nodes as separate arguments (same calling shape as `combine`).
|
|
2805
|
+
* @returns Combined node; signature matches `combine`.
|
|
2806
|
+
*
|
|
2807
|
+
* @example
|
|
2808
|
+
* ```ts
|
|
2809
|
+
* import { combineLatest, state } from "@graphrefly/graphrefly-ts";
|
|
2810
|
+
*
|
|
2811
|
+
* const n = combineLatest(state(1), state("a"));
|
|
2812
|
+
* ```
|
|
2813
|
+
*
|
|
2814
|
+
* @category extra
|
|
2815
|
+
*/
|
|
2816
|
+
declare const combineLatest: typeof combine;
|
|
2817
|
+
/**
|
|
2818
|
+
* RxJS-named alias for {@link debounce} — drops rapid `DATA` until `ms` of quiet.
|
|
2819
|
+
*
|
|
2820
|
+
* @param source - Upstream node.
|
|
2821
|
+
* @param ms - Quiet period in milliseconds.
|
|
2822
|
+
* @param opts - Optional node options (excluding `describeKind`).
|
|
2823
|
+
* @returns Debounced node; behavior matches `debounce`.
|
|
2824
|
+
*
|
|
2825
|
+
* @example
|
|
2826
|
+
* ```ts
|
|
2827
|
+
* import { debounceTime, state } from "@graphrefly/graphrefly-ts";
|
|
2828
|
+
*
|
|
2829
|
+
* debounceTime(state(0), 100);
|
|
2830
|
+
* ```
|
|
2831
|
+
*
|
|
2832
|
+
* @category extra
|
|
2833
|
+
*/
|
|
2834
|
+
declare const debounceTime: typeof debounce;
|
|
2835
|
+
/**
|
|
2836
|
+
* RxJS-named alias for {@link throttle} — emits on leading/trailing edges within `ms`.
|
|
2837
|
+
*
|
|
2838
|
+
* @param source - Upstream node.
|
|
2839
|
+
* @param ms - Minimum spacing in milliseconds.
|
|
2840
|
+
* @param opts - Optional throttle shape (`leading` / `trailing`) and node options.
|
|
2841
|
+
* @returns Throttled node; behavior matches `throttle`.
|
|
2842
|
+
*
|
|
2843
|
+
* @example
|
|
2844
|
+
* ```ts
|
|
2845
|
+
* import { throttleTime, state } from "@graphrefly/graphrefly-ts";
|
|
2846
|
+
*
|
|
2847
|
+
* throttleTime(state(0), 100);
|
|
2848
|
+
* ```
|
|
2849
|
+
*
|
|
2850
|
+
* @category extra
|
|
2851
|
+
*/
|
|
2852
|
+
declare const throttleTime: typeof throttle;
|
|
2853
|
+
/**
|
|
2854
|
+
* RxJS-named alias for {@link rescue} — replaces upstream `ERROR` with a recovered value.
|
|
2855
|
+
*
|
|
2856
|
+
* @param source - Upstream node.
|
|
2857
|
+
* @param recover - Maps error payload to replacement value.
|
|
2858
|
+
* @param opts - Optional node options (excluding `describeKind`).
|
|
2859
|
+
* @returns Recovered stream; behavior matches `rescue`.
|
|
2860
|
+
*
|
|
2861
|
+
* @example
|
|
2862
|
+
* ```ts
|
|
2863
|
+
* import { catchError, state } from "@graphrefly/graphrefly-ts";
|
|
2864
|
+
*
|
|
2865
|
+
* catchError(state(0), () => 0);
|
|
2866
|
+
* ```
|
|
2867
|
+
*
|
|
2868
|
+
* @category extra
|
|
2869
|
+
*/
|
|
2870
|
+
declare const catchError: typeof rescue;
|
|
2871
|
+
|
|
2872
|
+
/**
|
|
2873
|
+
* Lazy per-topic manual nodes (roadmap §3.2) — create topics on first access, publish with two-phase push.
|
|
2874
|
+
*/
|
|
2875
|
+
|
|
2876
|
+
/**
|
|
2877
|
+
* In-memory lazy topic registry: each topic is an independent {@link state} node.
|
|
2878
|
+
*
|
|
2879
|
+
* @category extra
|
|
2880
|
+
*/
|
|
2881
|
+
interface PubSubHub {
|
|
2882
|
+
/**
|
|
2883
|
+
* Returns the topic node, creating it on first use.
|
|
2884
|
+
*
|
|
2885
|
+
* @param name - Topic key.
|
|
2886
|
+
* @returns `Node` whose value is the last published payload (initially `undefined`).
|
|
2887
|
+
*/
|
|
2888
|
+
topic(name: string): Node<unknown>;
|
|
2889
|
+
/**
|
|
2890
|
+
* Pushes a value to the topic (two-phase `DIRTY` then `DATA`, matching other manual sources here).
|
|
2891
|
+
*
|
|
2892
|
+
* @param name - Topic key.
|
|
2893
|
+
* @param value - Payload.
|
|
2894
|
+
*/
|
|
2895
|
+
publish(name: string, value: unknown): void;
|
|
2896
|
+
/**
|
|
2897
|
+
* Removes a topic and tears down its node. Returns `true` if the topic existed.
|
|
2898
|
+
*
|
|
2899
|
+
* @param name - Topic key.
|
|
2900
|
+
*/
|
|
2901
|
+
removeTopic(name: string): boolean;
|
|
2902
|
+
}
|
|
2903
|
+
/**
|
|
2904
|
+
* Creates an empty {@link PubSubHub} for lazy topic nodes.
|
|
2905
|
+
*
|
|
2906
|
+
* @returns A new hub with no topics until {@link PubSubHub.topic} or {@link PubSubHub.publish} runs.
|
|
2907
|
+
*
|
|
2908
|
+
* @example
|
|
2909
|
+
* ```ts
|
|
2910
|
+
* import { pubsub } from "@graphrefly/graphrefly-ts";
|
|
2911
|
+
*
|
|
2912
|
+
* const hub = pubsub();
|
|
2913
|
+
* const t = hub.topic("events");
|
|
2914
|
+
* t.subscribe((msgs) => console.log(msgs));
|
|
2915
|
+
* hub.publish("events", { ok: true });
|
|
2916
|
+
* hub.removeTopic("events"); // tears down the node
|
|
2917
|
+
* ```
|
|
2918
|
+
*
|
|
2919
|
+
* @category extra
|
|
2920
|
+
*/
|
|
2921
|
+
declare function pubsub(): PubSubHub;
|
|
2922
|
+
|
|
2923
|
+
type IndexRow<K, V = unknown> = {
|
|
2924
|
+
readonly primary: K;
|
|
2925
|
+
readonly secondary: unknown;
|
|
2926
|
+
readonly value: V;
|
|
2927
|
+
};
|
|
2928
|
+
type ReactiveIndexSnapshot<K, V = unknown> = Versioned<{
|
|
2929
|
+
rows: readonly IndexRow<K, V>[];
|
|
2930
|
+
}>;
|
|
2931
|
+
type ReactiveIndexOptions = {
|
|
2932
|
+
name?: string;
|
|
2933
|
+
};
|
|
2934
|
+
type ReactiveIndexBundle<K, V = unknown> = {
|
|
2935
|
+
/** Rows sorted by `(secondary, primary)`; versioned snapshots. */
|
|
2936
|
+
readonly ordered: Node<ReactiveIndexSnapshot<K, V>>;
|
|
2937
|
+
/** Map from primary key to stored value. */
|
|
2938
|
+
readonly byPrimary: Node<ReadonlyMap<K, V>>;
|
|
2939
|
+
upsert: (primary: K, secondary: unknown, value: V) => void;
|
|
2940
|
+
delete: (primary: K) => void;
|
|
2941
|
+
clear: () => void;
|
|
2942
|
+
};
|
|
2943
|
+
/**
|
|
2944
|
+
* Creates a reactive index: unique primary key per row, rows sorted by `(secondary, primary)` for ordered scans.
|
|
2945
|
+
*
|
|
2946
|
+
* @param options - Optional `name` for `describe()` / debugging.
|
|
2947
|
+
* @returns Bundle with `ordered` (versioned rows), `byPrimary` (map), and imperative `upsert` / `delete` / `clear`.
|
|
2948
|
+
*
|
|
2949
|
+
* @remarks
|
|
2950
|
+
* **Ordering:** `secondary` and `primary` are compared via a small total order: same primitive `typeof` uses
|
|
2951
|
+
* numeric/string/boolean/bigint comparison; mixed or object keys fall back to `String(a).localeCompare(String(b))`
|
|
2952
|
+
* (not identical to Python’s rich comparison for exotic types).
|
|
2953
|
+
*
|
|
2954
|
+
* @example
|
|
2955
|
+
* ```ts
|
|
2956
|
+
* import { reactiveIndex } from "@graphrefly/graphrefly-ts";
|
|
2957
|
+
*
|
|
2958
|
+
* const idx = reactiveIndex<string, string>();
|
|
2959
|
+
* idx.upsert("id1", 10, "row-a");
|
|
2960
|
+
* idx.upsert("id2", 5, "row-b");
|
|
2961
|
+
* ```
|
|
2962
|
+
*
|
|
2963
|
+
* @category extra
|
|
2964
|
+
*/
|
|
2965
|
+
declare function reactiveIndex<K, V = unknown>(options?: ReactiveIndexOptions): ReactiveIndexBundle<K, V>;
|
|
2966
|
+
|
|
2967
|
+
type ReactiveListSnapshot<T> = Versioned<{
|
|
2968
|
+
items: readonly T[];
|
|
2969
|
+
}>;
|
|
2970
|
+
type ReactiveListOptions = {
|
|
2971
|
+
name?: string;
|
|
2972
|
+
};
|
|
2973
|
+
type ReactiveListBundle<T> = {
|
|
2974
|
+
/** Emits {@link ReactiveListSnapshot} on each structural change (two-phase). */
|
|
2975
|
+
readonly items: Node<ReactiveListSnapshot<T>>;
|
|
2976
|
+
append: (value: T) => void;
|
|
2977
|
+
insert: (index: number, value: T) => void;
|
|
2978
|
+
pop: (index?: number) => T;
|
|
2979
|
+
clear: () => void;
|
|
2980
|
+
};
|
|
2981
|
+
/**
|
|
2982
|
+
* Creates a reactive list with versioned immutable array snapshots.
|
|
2983
|
+
*
|
|
2984
|
+
* @param initial - Optional initial items (copied).
|
|
2985
|
+
* @param options - Optional `name` for `describe()` / debugging.
|
|
2986
|
+
* @returns Bundle with `items` (state node) and `append` / `insert` / `pop` / `clear`.
|
|
2987
|
+
*
|
|
2988
|
+
* @example
|
|
2989
|
+
* ```ts
|
|
2990
|
+
* import { reactiveList } from "@graphrefly/graphrefly-ts";
|
|
2991
|
+
*
|
|
2992
|
+
* const list = reactiveList<string>(["a"], { name: "queue" });
|
|
2993
|
+
* list.append("b");
|
|
2994
|
+
* ```
|
|
2995
|
+
*
|
|
2996
|
+
* @category extra
|
|
2997
|
+
*/
|
|
2998
|
+
declare function reactiveList<T>(initial?: readonly T[], options?: ReactiveListOptions): ReactiveListBundle<T>;
|
|
2999
|
+
|
|
3000
|
+
/**
|
|
3001
|
+
* WorkerTransport — normalized message channel for all worker types.
|
|
3002
|
+
*
|
|
3003
|
+
* Abstracts Worker, SharedWorker, ServiceWorker, BroadcastChannel, and
|
|
3004
|
+
* MessagePort behind a uniform post/listen/terminate interface.
|
|
3005
|
+
*/
|
|
3006
|
+
/** Normalized bidirectional message channel. */
|
|
3007
|
+
interface WorkerTransport {
|
|
3008
|
+
/** Send data to the other side. Optional transferables for zero-copy. */
|
|
3009
|
+
post(data: unknown, transfer?: Transferable[]): void;
|
|
3010
|
+
/** Listen for incoming messages. Returns unsubscribe function. */
|
|
3011
|
+
listen(handler: (data: unknown) => void): () => void;
|
|
3012
|
+
/** Terminate the connection (if supported by the underlying transport). */
|
|
3013
|
+
terminate?(): void;
|
|
3014
|
+
}
|
|
3015
|
+
/**
|
|
3016
|
+
* Auto-detect transport type and create a normalized WorkerTransport.
|
|
3017
|
+
*
|
|
3018
|
+
* Supports:
|
|
3019
|
+
* - `Worker` — direct postMessage/onmessage
|
|
3020
|
+
* - `SharedWorker` — port-based postMessage/onmessage
|
|
3021
|
+
* - `ServiceWorker` — postMessage via controller, listen via navigator.serviceWorker
|
|
3022
|
+
* - `BroadcastChannel` — postMessage/onmessage (no Transferable support)
|
|
3023
|
+
* - `MessagePort` — direct postMessage/onmessage (worker-side SharedWorker port)
|
|
3024
|
+
*/
|
|
3025
|
+
declare function createTransport(target: unknown): WorkerTransport;
|
|
3026
|
+
|
|
3027
|
+
/**
|
|
3028
|
+
* workerBridge — main-thread reactive node bridge to a worker.
|
|
3029
|
+
*
|
|
3030
|
+
* Creates proxy nodes for imported worker nodes, subscribes to exposed
|
|
3031
|
+
* nodes and sends values across the wire. Uses derived() + effect() for
|
|
3032
|
+
* natural batch coalescing via two-phase push + bitmask resolution.
|
|
3033
|
+
*
|
|
3034
|
+
* Wire filtering: messages with {@link messageTier} >= 2 cross the wire.
|
|
3035
|
+
* DATA values go through the coalescing path; RESOLVED, COMPLETE, ERROR,
|
|
3036
|
+
* TEARDOWN, and unknown {@link Symbol.for} types go through the signal
|
|
3037
|
+
* subscription. Tier 0–1 (DIRTY, INVALIDATE, PAUSE, RESUME) stay local.
|
|
3038
|
+
*
|
|
3039
|
+
* Handshake:
|
|
3040
|
+
* 1. Main creates bridge, starts listening
|
|
3041
|
+
* 2. Worker sends { t: 'r', stores: { name: initialValue, ... } }
|
|
3042
|
+
* 3. Main creates proxy nodes, marks meta.status "connected"
|
|
3043
|
+
* 4. Main sends { t: 'i', stores: { name: currentValue, ... } }
|
|
3044
|
+
* 5. Bidirectional value flow begins
|
|
3045
|
+
*/
|
|
3046
|
+
|
|
3047
|
+
interface WorkerBridgeOptions<TExpose extends Record<string, Node<any>>, TImport extends readonly string[]> {
|
|
3048
|
+
/** Nodes to send to the worker. */
|
|
3049
|
+
expose?: TExpose;
|
|
3050
|
+
/** Node names the worker will provide. */
|
|
3051
|
+
import?: TImport;
|
|
3052
|
+
/** Per-node transferable extractors for zero-copy ArrayBuffer passing. */
|
|
3053
|
+
transfer?: Partial<Record<keyof TExpose, (value: any) => Transferable[]>>;
|
|
3054
|
+
/** Debug name. */
|
|
3055
|
+
name?: string;
|
|
3056
|
+
/**
|
|
3057
|
+
* Handshake timeout in milliseconds. If the worker doesn't send READY
|
|
3058
|
+
* within this window, `meta.status` transitions to `"closed"` and
|
|
3059
|
+
* `meta.error` is set. Default: no timeout.
|
|
3060
|
+
*/
|
|
3061
|
+
timeoutMs?: number;
|
|
3062
|
+
}
|
|
3063
|
+
/** Proxy nodes created from imported worker node names. */
|
|
3064
|
+
type ImportedNodes<T extends readonly string[]> = {
|
|
3065
|
+
readonly [K in T[number]]: Node<any>;
|
|
3066
|
+
};
|
|
3067
|
+
type WorkerBridge<_TExpose extends Record<string, Node<any>>, TImport extends readonly string[]> = ImportedNodes<TImport> & {
|
|
3068
|
+
/** Connection status meta node. */
|
|
3069
|
+
meta: {
|
|
3070
|
+
status: Node<"connecting" | "connected" | "closed">;
|
|
3071
|
+
error: Node<Error | null>;
|
|
3072
|
+
};
|
|
3073
|
+
/** Destroy the bridge: sends TEARDOWN, disconnects, terminates worker. */
|
|
3074
|
+
destroy(): void;
|
|
3075
|
+
};
|
|
3076
|
+
declare function workerBridge<TExpose extends Record<string, Node<any>>, TImport extends readonly string[]>(target: unknown | WorkerTransport, opts: WorkerBridgeOptions<TExpose, TImport>): WorkerBridge<TExpose, TImport>;
|
|
3077
|
+
|
|
3078
|
+
/**
|
|
3079
|
+
* Wire protocol for worker bridge communication.
|
|
3080
|
+
*
|
|
3081
|
+
* Messages with {@link messageTier} >= 2 cross the wire (DATA values via
|
|
3082
|
+
* coalescing, RESOLVED/COMPLETE/TEARDOWN as signals, ERROR as serialized
|
|
3083
|
+
* payloads). Tier 0–1 (DIRTY, INVALIDATE, PAUSE, RESUME) stay local to
|
|
3084
|
+
* each side's reactive graph.
|
|
3085
|
+
*
|
|
3086
|
+
* Lifecycle signals serialize as string names since Symbols can't survive
|
|
3087
|
+
* structured clone. Unknown {@link Symbol.for} symbols are round-tripped
|
|
3088
|
+
* via their registered key.
|
|
3089
|
+
*/
|
|
3090
|
+
/** Value update — one node changed. */
|
|
3091
|
+
interface ValueMessage {
|
|
3092
|
+
t: "v";
|
|
3093
|
+
/** Node name. */
|
|
3094
|
+
s: string;
|
|
3095
|
+
/** Serialized value. */
|
|
3096
|
+
d: unknown;
|
|
3097
|
+
}
|
|
3098
|
+
/** Lifecycle signal — serialized symbol name. */
|
|
3099
|
+
interface SignalMessage {
|
|
3100
|
+
t: "s";
|
|
3101
|
+
/** Node name, or `"*"` for bridge-wide. */
|
|
3102
|
+
s: string;
|
|
3103
|
+
/** Signal name string (e.g. "TEARDOWN"). */
|
|
3104
|
+
sig: string;
|
|
3105
|
+
/** Optional payload for custom symbols (spec §1.3.6 forward unchanged). */
|
|
3106
|
+
d?: unknown;
|
|
3107
|
+
}
|
|
3108
|
+
/** Ready — worker declares its exported nodes with initial values. */
|
|
3109
|
+
interface ReadyMessage {
|
|
3110
|
+
t: "r";
|
|
3111
|
+
stores: Record<string, unknown>;
|
|
3112
|
+
}
|
|
3113
|
+
/** Init — main sends initial values of its exposed nodes. */
|
|
3114
|
+
interface InitMessage {
|
|
3115
|
+
t: "i";
|
|
3116
|
+
stores: Record<string, unknown>;
|
|
3117
|
+
}
|
|
3118
|
+
/** Batch value update — multiple nodes changed in one reactive cycle. */
|
|
3119
|
+
interface BatchMessage {
|
|
3120
|
+
t: "b";
|
|
3121
|
+
u: Record<string, unknown>;
|
|
3122
|
+
/** V0 versions per node for delta sync — peer skips if version <= lastSeen (§6.0b). */
|
|
3123
|
+
v?: Record<string, number>;
|
|
3124
|
+
}
|
|
3125
|
+
/** Error payload — serialized since Error objects don't survive structured clone. */
|
|
3126
|
+
interface ErrorMessage {
|
|
3127
|
+
t: "e";
|
|
3128
|
+
/** Node name. */
|
|
3129
|
+
s: string;
|
|
3130
|
+
/** Serialized error. */
|
|
3131
|
+
err: {
|
|
3132
|
+
message: string;
|
|
3133
|
+
name: string;
|
|
3134
|
+
stack?: string;
|
|
3135
|
+
};
|
|
3136
|
+
}
|
|
3137
|
+
type BridgeMessage = ValueMessage | SignalMessage | ReadyMessage | InitMessage | BatchMessage | ErrorMessage;
|
|
3138
|
+
/**
|
|
3139
|
+
* Serialize a message type symbol to a string for structured clone transfer.
|
|
3140
|
+
*
|
|
3141
|
+
* Known GraphReFly symbols map to their canonical names. Unknown symbols
|
|
3142
|
+
* registered via {@link Symbol.for} use their registered key. Unregistered
|
|
3143
|
+
* symbols return `"UNKNOWN"`.
|
|
3144
|
+
*/
|
|
3145
|
+
declare function signalToName(s: symbol): string;
|
|
3146
|
+
/**
|
|
3147
|
+
* Deserialize a string back to a message type symbol.
|
|
3148
|
+
*
|
|
3149
|
+
* Known GraphReFly names map to their canonical symbols. Other non-empty
|
|
3150
|
+
* strings are reconstructed via {@link Symbol.for} (round-trip safe for
|
|
3151
|
+
* custom message types). Returns `undefined` for `"UNKNOWN"`.
|
|
3152
|
+
*/
|
|
3153
|
+
declare function nameToSignal(name: string): symbol | undefined;
|
|
3154
|
+
/** Serialize an error for structured clone transfer. */
|
|
3155
|
+
declare function serializeError(err: unknown): {
|
|
3156
|
+
message: string;
|
|
3157
|
+
name: string;
|
|
3158
|
+
stack?: string;
|
|
3159
|
+
};
|
|
3160
|
+
/** Deserialize an error payload back to an Error object. */
|
|
3161
|
+
declare function deserializeError(payload: {
|
|
3162
|
+
message: string;
|
|
3163
|
+
name: string;
|
|
3164
|
+
stack?: string;
|
|
3165
|
+
}): Error;
|
|
3166
|
+
|
|
3167
|
+
/**
|
|
3168
|
+
* workerSelf — worker-side reactive node bridge.
|
|
3169
|
+
*
|
|
3170
|
+
* Mirror of workerBridge() for the worker side. Creates proxy nodes for
|
|
3171
|
+
* imports from main thread, exposes local nodes via the same wire protocol.
|
|
3172
|
+
* Uses derived() + effect() for batch coalescing.
|
|
3173
|
+
*
|
|
3174
|
+
* Wire filtering: messages with {@link messageTier} >= 2 cross the wire.
|
|
3175
|
+
* DATA values go through the coalescing path; RESOLVED, COMPLETE, ERROR,
|
|
3176
|
+
* TEARDOWN, and unknown {@link Symbol.for} types go through the signal
|
|
3177
|
+
* subscription. Tier 0–1 (DIRTY, INVALIDATE, PAUSE, RESUME) stay local.
|
|
3178
|
+
*
|
|
3179
|
+
* Handshake (worker perspective):
|
|
3180
|
+
* 1. workerSelf() called — creates proxy nodes for imports
|
|
3181
|
+
* 2. Runs expose factory with proxy nodes -> gets nodes to expose
|
|
3182
|
+
* 3. Sends { t: 'r', stores: { name: initialValue, ... } } to main
|
|
3183
|
+
* 4. Receives { t: 'i', stores: { name: value, ... } } from main
|
|
3184
|
+
* 5. Updates proxy nodes -> triggers local effects
|
|
3185
|
+
*/
|
|
3186
|
+
|
|
3187
|
+
interface WorkerSelfOptions<TImport extends readonly string[]> {
|
|
3188
|
+
/** Node names that the main thread will provide. */
|
|
3189
|
+
import?: TImport;
|
|
3190
|
+
/** Factory that receives imported proxy nodes and returns nodes to expose. */
|
|
3191
|
+
expose: (imported: WorkerImported<TImport>) => Record<string, Node<any>>;
|
|
3192
|
+
/** Per-node transferable extractors for zero-copy ArrayBuffer passing. */
|
|
3193
|
+
transfer?: Record<string, (value: any) => Transferable[]>;
|
|
3194
|
+
}
|
|
3195
|
+
/** Proxy nodes available inside the worker from main-thread exposed nodes. */
|
|
3196
|
+
type WorkerImported<T extends readonly string[]> = {
|
|
3197
|
+
readonly [K in T[number]]: Node<any>;
|
|
3198
|
+
};
|
|
3199
|
+
interface WorkerSelfHandle {
|
|
3200
|
+
/** Dispose all subscriptions and stop the bridge. */
|
|
3201
|
+
destroy(): void;
|
|
3202
|
+
}
|
|
3203
|
+
declare function workerSelf<TImport extends readonly string[]>(target: unknown | WorkerTransport, opts: WorkerSelfOptions<TImport>): WorkerSelfHandle;
|
|
3204
|
+
|
|
3205
|
+
/**
|
|
3206
|
+
* Extra layer: operators, sources, sinks (Phase 2+).
|
|
3207
|
+
*/
|
|
3208
|
+
|
|
3209
|
+
type index_AdapterHandlers<T> = AdapterHandlers<T>;
|
|
3210
|
+
type index_AsyncSourceOpts = AsyncSourceOpts;
|
|
3211
|
+
type index_BackoffPreset = BackoffPreset;
|
|
3212
|
+
type index_BackoffStrategy = BackoffStrategy;
|
|
3213
|
+
type index_BatchMessage = BatchMessage;
|
|
3214
|
+
type index_BridgeMessage = BridgeMessage;
|
|
3215
|
+
type index_CSVRow = CSVRow;
|
|
3216
|
+
type index_CheckpointAdapter = CheckpointAdapter;
|
|
3217
|
+
type index_CircuitBreaker = CircuitBreaker;
|
|
3218
|
+
type index_CircuitBreakerOptions = CircuitBreakerOptions;
|
|
3219
|
+
type index_CircuitOpenError = CircuitOpenError;
|
|
3220
|
+
declare const index_CircuitOpenError: typeof CircuitOpenError;
|
|
3221
|
+
type index_CircuitState = CircuitState;
|
|
3222
|
+
type index_ClickHouseClientLike = ClickHouseClientLike;
|
|
3223
|
+
type index_ClickHouseRow = ClickHouseRow;
|
|
3224
|
+
type index_CronSchedule = CronSchedule;
|
|
3225
|
+
type index_DictCheckpointAdapter = DictCheckpointAdapter;
|
|
3226
|
+
declare const index_DictCheckpointAdapter: typeof DictCheckpointAdapter;
|
|
3227
|
+
type index_DistillBundle<TMem> = DistillBundle<TMem>;
|
|
3228
|
+
type index_DistillOptions<TMem> = DistillOptions<TMem>;
|
|
3229
|
+
type index_ErrorMessage = ErrorMessage;
|
|
3230
|
+
type index_EventTargetLike = EventTargetLike;
|
|
3231
|
+
type index_ExponentialBackoffOptions = ExponentialBackoffOptions;
|
|
3232
|
+
type index_Extraction<TMem> = Extraction<TMem>;
|
|
3233
|
+
type index_FSEvent = FSEvent;
|
|
3234
|
+
type index_FSEventType = FSEventType;
|
|
3235
|
+
type index_FileCheckpointAdapter = FileCheckpointAdapter;
|
|
3236
|
+
declare const index_FileCheckpointAdapter: typeof FileCheckpointAdapter;
|
|
3237
|
+
type index_FromCSVOptions = FromCSVOptions;
|
|
3238
|
+
type index_FromClickHouseWatchOptions = FromClickHouseWatchOptions;
|
|
3239
|
+
type index_FromCronOptions = FromCronOptions;
|
|
3240
|
+
type index_FromFSWatchOptions = FromFSWatchOptions;
|
|
3241
|
+
type index_FromGitHookOptions = FromGitHookOptions;
|
|
3242
|
+
type index_FromHTTPOptions = FromHTTPOptions;
|
|
3243
|
+
type index_FromKafkaOptions = FromKafkaOptions;
|
|
3244
|
+
type index_FromMCPOptions = FromMCPOptions;
|
|
3245
|
+
type index_FromNDJSONOptions = FromNDJSONOptions;
|
|
3246
|
+
type index_FromOTelOptions = FromOTelOptions;
|
|
3247
|
+
type index_FromPrometheusOptions = FromPrometheusOptions;
|
|
3248
|
+
type index_FromRedisStreamOptions = FromRedisStreamOptions;
|
|
3249
|
+
type index_FromStatsDOptions = FromStatsDOptions;
|
|
3250
|
+
type index_FromSyslogOptions = FromSyslogOptions;
|
|
3251
|
+
type index_GitEvent = GitEvent;
|
|
3252
|
+
type index_GitHookType = GitHookType;
|
|
3253
|
+
type index_HTTPBundle<T> = HTTPBundle<T>;
|
|
3254
|
+
type index_IndexRow<K, V = unknown> = IndexRow<K, V>;
|
|
3255
|
+
type index_IndexedDbCheckpointSpec = IndexedDbCheckpointSpec;
|
|
3256
|
+
type index_InitMessage = InitMessage;
|
|
3257
|
+
type index_JitterMode = JitterMode;
|
|
3258
|
+
type index_KafkaConsumerLike = KafkaConsumerLike;
|
|
3259
|
+
type index_KafkaMessage<T = unknown> = KafkaMessage<T>;
|
|
3260
|
+
type index_KafkaProducerLike = KafkaProducerLike;
|
|
3261
|
+
type index_MCPClientLike = MCPClientLike;
|
|
3262
|
+
type index_MemoryCheckpointAdapter = MemoryCheckpointAdapter;
|
|
3263
|
+
declare const index_MemoryCheckpointAdapter: typeof MemoryCheckpointAdapter;
|
|
3264
|
+
type index_MergeMapOptions = MergeMapOptions;
|
|
3265
|
+
declare const index_NS_PER_MS: typeof NS_PER_MS;
|
|
3266
|
+
declare const index_NS_PER_SEC: typeof NS_PER_SEC;
|
|
3267
|
+
type index_NodeInput<T> = NodeInput<T>;
|
|
3268
|
+
type index_OTelBundle = OTelBundle;
|
|
3269
|
+
type index_OTelLog = OTelLog;
|
|
3270
|
+
type index_OTelMetric = OTelMetric;
|
|
3271
|
+
type index_OTelRegister = OTelRegister;
|
|
3272
|
+
type index_OTelSpan = OTelSpan;
|
|
3273
|
+
type index_PrometheusMetric = PrometheusMetric;
|
|
3274
|
+
type index_PubSubHub = PubSubHub;
|
|
3275
|
+
type index_ReactiveIndexBundle<K, V = unknown> = ReactiveIndexBundle<K, V>;
|
|
3276
|
+
type index_ReactiveIndexOptions = ReactiveIndexOptions;
|
|
3277
|
+
type index_ReactiveIndexSnapshot<K, V = unknown> = ReactiveIndexSnapshot<K, V>;
|
|
3278
|
+
type index_ReactiveListBundle<T> = ReactiveListBundle<T>;
|
|
3279
|
+
type index_ReactiveListOptions = ReactiveListOptions;
|
|
3280
|
+
type index_ReactiveListSnapshot<T> = ReactiveListSnapshot<T>;
|
|
3281
|
+
declare const index_ReactiveLogBundle: typeof ReactiveLogBundle;
|
|
3282
|
+
declare const index_ReactiveLogOptions: typeof ReactiveLogOptions;
|
|
3283
|
+
declare const index_ReactiveLogSnapshot: typeof ReactiveLogSnapshot;
|
|
3284
|
+
type index_ReactiveMapBundle<K, V> = ReactiveMapBundle<K, V>;
|
|
3285
|
+
type index_ReactiveMapOptions = ReactiveMapOptions;
|
|
3286
|
+
type index_ReactiveMapSnapshot<K, V> = ReactiveMapSnapshot<K, V>;
|
|
3287
|
+
type index_ReadyMessage = ReadyMessage;
|
|
3288
|
+
type index_RedisClientLike = RedisClientLike;
|
|
3289
|
+
type index_RedisStreamEntry<T = unknown> = RedisStreamEntry<T>;
|
|
3290
|
+
type index_RetryOptions = RetryOptions;
|
|
3291
|
+
type index_SignalMessage = SignalMessage;
|
|
3292
|
+
type index_SinkTransportError = SinkTransportError;
|
|
3293
|
+
type index_SqliteCheckpointAdapter = SqliteCheckpointAdapter;
|
|
3294
|
+
declare const index_SqliteCheckpointAdapter: typeof SqliteCheckpointAdapter;
|
|
3295
|
+
type index_StatsDMetric = StatsDMetric;
|
|
3296
|
+
type index_StatsDRegister = StatsDRegister;
|
|
3297
|
+
type index_StatusValue = StatusValue;
|
|
3298
|
+
type index_SyslogMessage = SyslogMessage;
|
|
3299
|
+
type index_SyslogRegister = SyslogRegister;
|
|
3300
|
+
type index_TapObserver<T> = TapObserver<T>;
|
|
3301
|
+
type index_ThrottleOptions = ThrottleOptions;
|
|
3302
|
+
type index_ToKafkaOptions<T> = ToKafkaOptions<T>;
|
|
3303
|
+
type index_ToRedisStreamOptions<T> = ToRedisStreamOptions<T>;
|
|
3304
|
+
type index_ToSSEOptions = ToSSEOptions;
|
|
3305
|
+
type index_ToWebSocketOptions<T> = ToWebSocketOptions<T>;
|
|
3306
|
+
type index_ToWebSocketTransportError = ToWebSocketTransportError;
|
|
3307
|
+
type index_TokenBucket = TokenBucket;
|
|
3308
|
+
type index_ValueMessage = ValueMessage;
|
|
3309
|
+
type index_VerifiableBundle<T, TVerify = VerifyValue> = VerifiableBundle<T, TVerify>;
|
|
3310
|
+
type index_VerifiableOptions<TVerify = VerifyValue> = VerifiableOptions<TVerify>;
|
|
3311
|
+
type index_VerifyValue = VerifyValue;
|
|
3312
|
+
type index_WatermarkController = WatermarkController;
|
|
3313
|
+
type index_WatermarkOptions = WatermarkOptions;
|
|
3314
|
+
type index_WebSocketLike = WebSocketLike;
|
|
3315
|
+
type index_WebSocketMessageEventLike = WebSocketMessageEventLike;
|
|
3316
|
+
type index_WebSocketRegister<T> = WebSocketRegister<T>;
|
|
3317
|
+
type index_WebhookRegister<T> = WebhookRegister<T>;
|
|
3318
|
+
type index_WithBreakerBundle<T> = WithBreakerBundle<T>;
|
|
3319
|
+
type index_WithStatusBundle<T> = WithStatusBundle<T>;
|
|
3320
|
+
type index_WorkerBridge<_TExpose extends Record<string, Node<any>>, TImport extends readonly string[]> = WorkerBridge<_TExpose, TImport>;
|
|
3321
|
+
type index_WorkerBridgeOptions<TExpose extends Record<string, Node<any>>, TImport extends readonly string[]> = WorkerBridgeOptions<TExpose, TImport>;
|
|
3322
|
+
type index_WorkerSelfHandle = WorkerSelfHandle;
|
|
3323
|
+
type index_WorkerSelfOptions<TImport extends readonly string[]> = WorkerSelfOptions<TImport>;
|
|
3324
|
+
type index_WorkerTransport = WorkerTransport;
|
|
3325
|
+
declare const index_audit: typeof audit;
|
|
3326
|
+
declare const index_buffer: typeof buffer;
|
|
3327
|
+
declare const index_bufferCount: typeof bufferCount;
|
|
3328
|
+
declare const index_bufferTime: typeof bufferTime;
|
|
3329
|
+
declare const index_cached: typeof cached;
|
|
3330
|
+
declare const index_catchError: typeof catchError;
|
|
3331
|
+
declare const index_checkpointNodeValue: typeof checkpointNodeValue;
|
|
3332
|
+
declare const index_circuitBreaker: typeof circuitBreaker;
|
|
3333
|
+
declare const index_combine: typeof combine;
|
|
3334
|
+
declare const index_combineLatest: typeof combineLatest;
|
|
3335
|
+
declare const index_concat: typeof concat;
|
|
3336
|
+
declare const index_concatMap: typeof concatMap;
|
|
3337
|
+
declare const index_constant: typeof constant;
|
|
3338
|
+
declare const index_createTransport: typeof createTransport;
|
|
3339
|
+
declare const index_createWatermarkController: typeof createWatermarkController;
|
|
3340
|
+
declare const index_debounce: typeof debounce;
|
|
3341
|
+
declare const index_debounceTime: typeof debounceTime;
|
|
3342
|
+
declare const index_decorrelatedJitter: typeof decorrelatedJitter;
|
|
3343
|
+
declare const index_delay: typeof delay;
|
|
3344
|
+
declare const index_deserializeError: typeof deserializeError;
|
|
3345
|
+
declare const index_distill: typeof distill;
|
|
3346
|
+
declare const index_distinctUntilChanged: typeof distinctUntilChanged;
|
|
3347
|
+
declare const index_elementAt: typeof elementAt;
|
|
3348
|
+
declare const index_empty: typeof empty;
|
|
3349
|
+
declare const index_escapeRegexChar: typeof escapeRegexChar;
|
|
3350
|
+
declare const index_exhaustMap: typeof exhaustMap;
|
|
3351
|
+
declare const index_exponential: typeof exponential;
|
|
3352
|
+
declare const index_fibonacci: typeof fibonacci;
|
|
3353
|
+
declare const index_filter: typeof filter;
|
|
3354
|
+
declare const index_find: typeof find;
|
|
3355
|
+
declare const index_first: typeof first;
|
|
3356
|
+
declare const index_firstValueFrom: typeof firstValueFrom;
|
|
3357
|
+
declare const index_flatMap: typeof flatMap;
|
|
3358
|
+
declare const index_forEach: typeof forEach;
|
|
3359
|
+
declare const index_fromAny: typeof fromAny;
|
|
3360
|
+
declare const index_fromAsyncIter: typeof fromAsyncIter;
|
|
3361
|
+
declare const index_fromCSV: typeof fromCSV;
|
|
3362
|
+
declare const index_fromClickHouseWatch: typeof fromClickHouseWatch;
|
|
3363
|
+
declare const index_fromCron: typeof fromCron;
|
|
3364
|
+
declare const index_fromEvent: typeof fromEvent;
|
|
3365
|
+
declare const index_fromFSWatch: typeof fromFSWatch;
|
|
3366
|
+
declare const index_fromGitHook: typeof fromGitHook;
|
|
3367
|
+
declare const index_fromHTTP: typeof fromHTTP;
|
|
3368
|
+
declare const index_fromIDBRequest: typeof fromIDBRequest;
|
|
3369
|
+
declare const index_fromIDBTransaction: typeof fromIDBTransaction;
|
|
3370
|
+
declare const index_fromIter: typeof fromIter;
|
|
3371
|
+
declare const index_fromKafka: typeof fromKafka;
|
|
3372
|
+
declare const index_fromMCP: typeof fromMCP;
|
|
3373
|
+
declare const index_fromNDJSON: typeof fromNDJSON;
|
|
3374
|
+
declare const index_fromOTel: typeof fromOTel;
|
|
3375
|
+
declare const index_fromPrometheus: typeof fromPrometheus;
|
|
3376
|
+
declare const index_fromPromise: typeof fromPromise;
|
|
3377
|
+
declare const index_fromRedisStream: typeof fromRedisStream;
|
|
3378
|
+
declare const index_fromStatsD: typeof fromStatsD;
|
|
3379
|
+
declare const index_fromSyslog: typeof fromSyslog;
|
|
3380
|
+
declare const index_fromTimer: typeof fromTimer;
|
|
3381
|
+
declare const index_fromWebSocket: typeof fromWebSocket;
|
|
3382
|
+
declare const index_fromWebhook: typeof fromWebhook;
|
|
3383
|
+
declare const index_gate: typeof gate;
|
|
3384
|
+
declare const index_globToRegExp: typeof globToRegExp;
|
|
3385
|
+
declare const index_interval: typeof interval;
|
|
3386
|
+
declare const index_last: typeof last;
|
|
3387
|
+
declare const index_linear: typeof linear;
|
|
3388
|
+
declare const index_logSlice: typeof logSlice;
|
|
3389
|
+
declare const index_map: typeof map;
|
|
3390
|
+
declare const index_matchesAnyPattern: typeof matchesAnyPattern;
|
|
3391
|
+
declare const index_matchesCron: typeof matchesCron;
|
|
3392
|
+
declare const index_merge: typeof merge;
|
|
3393
|
+
declare const index_mergeMap: typeof mergeMap;
|
|
3394
|
+
declare const index_nameToSignal: typeof nameToSignal;
|
|
3395
|
+
declare const index_never: typeof never;
|
|
3396
|
+
declare const index_observeGraph$: typeof observeGraph$;
|
|
3397
|
+
declare const index_observeNode$: typeof observeNode$;
|
|
3398
|
+
declare const index_of: typeof of;
|
|
3399
|
+
declare const index_pairwise: typeof pairwise;
|
|
3400
|
+
declare const index_parseCron: typeof parseCron;
|
|
3401
|
+
declare const index_parsePrometheusText: typeof parsePrometheusText;
|
|
3402
|
+
declare const index_parseStatsD: typeof parseStatsD;
|
|
3403
|
+
declare const index_parseSyslog: typeof parseSyslog;
|
|
3404
|
+
declare const index_pausable: typeof pausable;
|
|
3405
|
+
declare const index_pubsub: typeof pubsub;
|
|
3406
|
+
declare const index_race: typeof race;
|
|
3407
|
+
declare const index_rateLimiter: typeof rateLimiter;
|
|
3408
|
+
declare const index_reactiveIndex: typeof reactiveIndex;
|
|
3409
|
+
declare const index_reactiveList: typeof reactiveList;
|
|
3410
|
+
declare const index_reactiveLog: typeof reactiveLog;
|
|
3411
|
+
declare const index_reactiveMap: typeof reactiveMap;
|
|
3412
|
+
declare const index_reduce: typeof reduce;
|
|
3413
|
+
declare const index_repeat: typeof repeat;
|
|
3414
|
+
declare const index_replay: typeof replay;
|
|
3415
|
+
declare const index_rescue: typeof rescue;
|
|
3416
|
+
declare const index_resolveBackoffPreset: typeof resolveBackoffPreset;
|
|
3417
|
+
declare const index_restoreGraphCheckpoint: typeof restoreGraphCheckpoint;
|
|
3418
|
+
declare const index_restoreGraphCheckpointIndexedDb: typeof restoreGraphCheckpointIndexedDb;
|
|
3419
|
+
declare const index_retry: typeof retry;
|
|
3420
|
+
declare const index_sample: typeof sample;
|
|
3421
|
+
declare const index_saveGraphCheckpoint: typeof saveGraphCheckpoint;
|
|
3422
|
+
declare const index_saveGraphCheckpointIndexedDb: typeof saveGraphCheckpointIndexedDb;
|
|
3423
|
+
declare const index_scan: typeof scan;
|
|
3424
|
+
declare const index_serializeError: typeof serializeError;
|
|
3425
|
+
declare const index_share: typeof share;
|
|
3426
|
+
declare const index_shareReplay: typeof shareReplay;
|
|
3427
|
+
declare const index_signalToName: typeof signalToName;
|
|
3428
|
+
declare const index_skip: typeof skip;
|
|
3429
|
+
declare const index_startWith: typeof startWith;
|
|
3430
|
+
declare const index_switchMap: typeof switchMap;
|
|
3431
|
+
declare const index_take: typeof take;
|
|
3432
|
+
declare const index_takeUntil: typeof takeUntil;
|
|
3433
|
+
declare const index_takeWhile: typeof takeWhile;
|
|
3434
|
+
declare const index_tap: typeof tap;
|
|
3435
|
+
declare const index_throttle: typeof throttle;
|
|
3436
|
+
declare const index_throttleTime: typeof throttleTime;
|
|
3437
|
+
declare const index_throwError: typeof throwError;
|
|
3438
|
+
declare const index_timeout: typeof timeout;
|
|
3439
|
+
declare const index_toArray: typeof toArray;
|
|
3440
|
+
declare const index_toKafka: typeof toKafka;
|
|
3441
|
+
declare const index_toMessages$: typeof toMessages$;
|
|
3442
|
+
declare const index_toObservable: typeof toObservable;
|
|
3443
|
+
declare const index_toRedisStream: typeof toRedisStream;
|
|
3444
|
+
declare const index_toSSE: typeof toSSE;
|
|
3445
|
+
declare const index_toWebSocket: typeof toWebSocket;
|
|
3446
|
+
declare const index_tokenBucket: typeof tokenBucket;
|
|
3447
|
+
declare const index_tokenTracker: typeof tokenTracker;
|
|
3448
|
+
declare const index_verifiable: typeof verifiable;
|
|
3449
|
+
declare const index_window: typeof window;
|
|
3450
|
+
declare const index_windowCount: typeof windowCount;
|
|
3451
|
+
declare const index_windowTime: typeof windowTime;
|
|
3452
|
+
declare const index_withBreaker: typeof withBreaker;
|
|
3453
|
+
declare const index_withLatestFrom: typeof withLatestFrom;
|
|
3454
|
+
declare const index_withMaxAttempts: typeof withMaxAttempts;
|
|
3455
|
+
declare const index_withStatus: typeof withStatus;
|
|
3456
|
+
declare const index_workerBridge: typeof workerBridge;
|
|
3457
|
+
declare const index_workerSelf: typeof workerSelf;
|
|
3458
|
+
declare const index_zip: typeof zip;
|
|
3459
|
+
declare namespace index {
|
|
3460
|
+
export { type index_AdapterHandlers as AdapterHandlers, type index_AsyncSourceOpts as AsyncSourceOpts, type index_BackoffPreset as BackoffPreset, type index_BackoffStrategy as BackoffStrategy, type index_BatchMessage as BatchMessage, type index_BridgeMessage as BridgeMessage, type index_CSVRow as CSVRow, type index_CheckpointAdapter as CheckpointAdapter, type index_CircuitBreaker as CircuitBreaker, type index_CircuitBreakerOptions as CircuitBreakerOptions, index_CircuitOpenError as CircuitOpenError, type index_CircuitState as CircuitState, type index_ClickHouseClientLike as ClickHouseClientLike, type index_ClickHouseRow as ClickHouseRow, type index_CronSchedule as CronSchedule, index_DictCheckpointAdapter as DictCheckpointAdapter, type index_DistillBundle as DistillBundle, type index_DistillOptions as DistillOptions, type index_ErrorMessage as ErrorMessage, type index_EventTargetLike as EventTargetLike, type index_ExponentialBackoffOptions as ExponentialBackoffOptions, type index_Extraction as Extraction, type index_FSEvent as FSEvent, type index_FSEventType as FSEventType, index_FileCheckpointAdapter as FileCheckpointAdapter, type index_FromCSVOptions as FromCSVOptions, type index_FromClickHouseWatchOptions as FromClickHouseWatchOptions, type index_FromCronOptions as FromCronOptions, type index_FromFSWatchOptions as FromFSWatchOptions, type index_FromGitHookOptions as FromGitHookOptions, type index_FromHTTPOptions as FromHTTPOptions, type index_FromKafkaOptions as FromKafkaOptions, type index_FromMCPOptions as FromMCPOptions, type index_FromNDJSONOptions as FromNDJSONOptions, type index_FromOTelOptions as FromOTelOptions, type index_FromPrometheusOptions as FromPrometheusOptions, type index_FromRedisStreamOptions as FromRedisStreamOptions, type index_FromStatsDOptions as FromStatsDOptions, type index_FromSyslogOptions as FromSyslogOptions, type index_GitEvent as GitEvent, type index_GitHookType as GitHookType, type index_HTTPBundle as HTTPBundle, type index_IndexRow as IndexRow, type index_IndexedDbCheckpointSpec as IndexedDbCheckpointSpec, type index_InitMessage as InitMessage, type index_JitterMode as JitterMode, type index_KafkaConsumerLike as KafkaConsumerLike, type index_KafkaMessage as KafkaMessage, type index_KafkaProducerLike as KafkaProducerLike, type index_MCPClientLike as MCPClientLike, index_MemoryCheckpointAdapter as MemoryCheckpointAdapter, type index_MergeMapOptions as MergeMapOptions, index_NS_PER_MS as NS_PER_MS, index_NS_PER_SEC as NS_PER_SEC, type index_NodeInput as NodeInput, type index_OTelBundle as OTelBundle, type index_OTelLog as OTelLog, type index_OTelMetric as OTelMetric, type index_OTelRegister as OTelRegister, type index_OTelSpan as OTelSpan, type index_PrometheusMetric as PrometheusMetric, type index_PubSubHub as PubSubHub, type index_ReactiveIndexBundle as ReactiveIndexBundle, type index_ReactiveIndexOptions as ReactiveIndexOptions, type index_ReactiveIndexSnapshot as ReactiveIndexSnapshot, type index_ReactiveListBundle as ReactiveListBundle, type index_ReactiveListOptions as ReactiveListOptions, type index_ReactiveListSnapshot as ReactiveListSnapshot, index_ReactiveLogBundle as ReactiveLogBundle, index_ReactiveLogOptions as ReactiveLogOptions, index_ReactiveLogSnapshot as ReactiveLogSnapshot, type index_ReactiveMapBundle as ReactiveMapBundle, type index_ReactiveMapOptions as ReactiveMapOptions, type index_ReactiveMapSnapshot as ReactiveMapSnapshot, type index_ReadyMessage as ReadyMessage, type index_RedisClientLike as RedisClientLike, type index_RedisStreamEntry as RedisStreamEntry, type index_RetryOptions as RetryOptions, type index_SignalMessage as SignalMessage, type index_SinkTransportError as SinkTransportError, index_SqliteCheckpointAdapter as SqliteCheckpointAdapter, type index_StatsDMetric as StatsDMetric, type index_StatsDRegister as StatsDRegister, type index_StatusValue as StatusValue, type index_SyslogMessage as SyslogMessage, type index_SyslogRegister as SyslogRegister, type index_TapObserver as TapObserver, type index_ThrottleOptions as ThrottleOptions, type index_ToKafkaOptions as ToKafkaOptions, type index_ToRedisStreamOptions as ToRedisStreamOptions, type index_ToSSEOptions as ToSSEOptions, type index_ToWebSocketOptions as ToWebSocketOptions, type index_ToWebSocketTransportError as ToWebSocketTransportError, type index_TokenBucket as TokenBucket, type index_ValueMessage as ValueMessage, type index_VerifiableBundle as VerifiableBundle, type index_VerifiableOptions as VerifiableOptions, type index_VerifyValue as VerifyValue, type index_WatermarkController as WatermarkController, type index_WatermarkOptions as WatermarkOptions, type index_WebSocketLike as WebSocketLike, type index_WebSocketMessageEventLike as WebSocketMessageEventLike, type index_WebSocketRegister as WebSocketRegister, type index_WebhookRegister as WebhookRegister, type index_WithBreakerBundle as WithBreakerBundle, type index_WithStatusBundle as WithStatusBundle, type index_WorkerBridge as WorkerBridge, type index_WorkerBridgeOptions as WorkerBridgeOptions, type index_WorkerSelfHandle as WorkerSelfHandle, type index_WorkerSelfOptions as WorkerSelfOptions, type index_WorkerTransport as WorkerTransport, index_audit as audit, index_buffer as buffer, index_bufferCount as bufferCount, index_bufferTime as bufferTime, index_cached as cached, index_catchError as catchError, index_checkpointNodeValue as checkpointNodeValue, index_circuitBreaker as circuitBreaker, index_combine as combine, index_combineLatest as combineLatest, index_concat as concat, index_concatMap as concatMap, index_constant as constant, index_createTransport as createTransport, index_createWatermarkController as createWatermarkController, index_debounce as debounce, index_debounceTime as debounceTime, index_decorrelatedJitter as decorrelatedJitter, index_delay as delay, index_deserializeError as deserializeError, index_distill as distill, index_distinctUntilChanged as distinctUntilChanged, index_elementAt as elementAt, index_empty as empty, index_escapeRegexChar as escapeRegexChar, index_exhaustMap as exhaustMap, index_exponential as exponential, index_fibonacci as fibonacci, index_filter as filter, index_find as find, index_first as first, index_firstValueFrom as firstValueFrom, index_flatMap as flatMap, index_forEach as forEach, index_fromAny as fromAny, index_fromAsyncIter as fromAsyncIter, index_fromCSV as fromCSV, index_fromClickHouseWatch as fromClickHouseWatch, index_fromCron as fromCron, index_fromEvent as fromEvent, index_fromFSWatch as fromFSWatch, index_fromGitHook as fromGitHook, index_fromHTTP as fromHTTP, index_fromIDBRequest as fromIDBRequest, index_fromIDBTransaction as fromIDBTransaction, index_fromIter as fromIter, index_fromKafka as fromKafka, index_fromMCP as fromMCP, index_fromNDJSON as fromNDJSON, index_fromOTel as fromOTel, index_fromPrometheus as fromPrometheus, index_fromPromise as fromPromise, index_fromRedisStream as fromRedisStream, index_fromStatsD as fromStatsD, index_fromSyslog as fromSyslog, index_fromTimer as fromTimer, index_fromWebSocket as fromWebSocket, index_fromWebhook as fromWebhook, index_gate as gate, index_globToRegExp as globToRegExp, index_interval as interval, index_last as last, index_linear as linear, index_logSlice as logSlice, index_map as map, index_matchesAnyPattern as matchesAnyPattern, index_matchesCron as matchesCron, index_merge as merge, index_mergeMap as mergeMap, index_nameToSignal as nameToSignal, index_never as never, index_observeGraph$ as observeGraph$, index_observeNode$ as observeNode$, index_of as of, index_pairwise as pairwise, index_parseCron as parseCron, index_parsePrometheusText as parsePrometheusText, index_parseStatsD as parseStatsD, index_parseSyslog as parseSyslog, index_pausable as pausable, index_pubsub as pubsub, index_race as race, index_rateLimiter as rateLimiter, index_reactiveIndex as reactiveIndex, index_reactiveList as reactiveList, index_reactiveLog as reactiveLog, index_reactiveMap as reactiveMap, index_reduce as reduce, index_repeat as repeat, index_replay as replay, index_rescue as rescue, index_resolveBackoffPreset as resolveBackoffPreset, index_restoreGraphCheckpoint as restoreGraphCheckpoint, index_restoreGraphCheckpointIndexedDb as restoreGraphCheckpointIndexedDb, index_retry as retry, index_sample as sample, index_saveGraphCheckpoint as saveGraphCheckpoint, index_saveGraphCheckpointIndexedDb as saveGraphCheckpointIndexedDb, index_scan as scan, index_serializeError as serializeError, index_share as share, index_shareReplay as shareReplay, index_signalToName as signalToName, index_skip as skip, index_startWith as startWith, index_switchMap as switchMap, index_take as take, index_takeUntil as takeUntil, index_takeWhile as takeWhile, index_tap as tap, index_throttle as throttle, index_throttleTime as throttleTime, index_throwError as throwError, index_timeout as timeout, index_toArray as toArray, index_toKafka as toKafka, index_toMessages$ as toMessages$, index_toObservable as toObservable, index_toRedisStream as toRedisStream, index_toSSE as toSSE, index_toWebSocket as toWebSocket, index_tokenBucket as tokenBucket, index_tokenTracker as tokenTracker, index_verifiable as verifiable, index_window as window, index_windowCount as windowCount, index_windowTime as windowTime, index_withBreaker as withBreaker, index_withLatestFrom as withLatestFrom, index_withMaxAttempts as withMaxAttempts, index_withStatus as withStatus, index_workerBridge as workerBridge, index_workerSelf as workerSelf, index_zip as zip };
|
|
3461
|
+
}
|
|
3462
|
+
|
|
3463
|
+
export { MemoryCheckpointAdapter as $, type AdapterHandlers as A, type BackoffPreset as B, type CSVRow as C, type DistillBundle as D, type Extraction as E, type FSEvent as F, type FromKafkaOptions as G, type FromMCPOptions as H, type FromNDJSONOptions as I, type FromOTelOptions as J, type FromPrometheusOptions as K, type FromRedisStreamOptions as L, type FromStatsDOptions as M, type NodeInput as N, type FromSyslogOptions as O, type GitEvent as P, type GitHookType as Q, type ReactiveListSnapshot as R, type HTTPBundle as S, type IndexRow as T, type IndexedDbCheckpointSpec as U, type InitMessage as V, type JitterMode as W, type KafkaConsumerLike as X, type KafkaMessage as Y, type KafkaProducerLike as Z, type MCPClientLike as _, type ReactiveMapSnapshot as a, combineLatest as a$, type MergeMapOptions as a0, NS_PER_MS as a1, NS_PER_SEC as a2, type OTelBundle as a3, type OTelLog as a4, type OTelMetric as a5, type OTelRegister as a6, type OTelSpan as a7, type PrometheusMetric as a8, type PubSubHub as a9, type TokenBucket as aA, type ValueMessage as aB, type VerifiableBundle as aC, type VerifiableOptions as aD, type VerifyValue as aE, type WatermarkController as aF, type WatermarkOptions as aG, type WebSocketLike as aH, type WebSocketMessageEventLike as aI, type WebSocketRegister as aJ, type WebhookRegister as aK, type WithBreakerBundle as aL, type WithStatusBundle as aM, type WorkerBridge as aN, type WorkerBridgeOptions as aO, type WorkerSelfHandle as aP, type WorkerSelfOptions as aQ, type WorkerTransport as aR, audit as aS, buffer as aT, bufferCount as aU, bufferTime as aV, cached as aW, catchError as aX, checkpointNodeValue as aY, circuitBreaker as aZ, combine as a_, type ReactiveIndexBundle as aa, type ReactiveIndexOptions as ab, type ReactiveIndexSnapshot as ac, type ReactiveListBundle as ad, type ReactiveListOptions as ae, type ReactiveMapBundle as af, type ReactiveMapOptions as ag, type ReadyMessage as ah, type RedisClientLike as ai, type RedisStreamEntry as aj, type RetryOptions as ak, type SignalMessage as al, type SinkTransportError as am, SqliteCheckpointAdapter as an, type StatsDMetric as ao, type StatsDRegister as ap, type StatusValue as aq, type SyslogMessage as ar, type SyslogRegister as as, type TapObserver as at, type ThrottleOptions as au, type ToKafkaOptions as av, type ToRedisStreamOptions as aw, type ToSSEOptions as ax, type ToWebSocketOptions as ay, type ToWebSocketTransportError as az, type AsyncSourceOpts as b, parseCron as b$, concat as b0, concatMap as b1, constant as b2, createTransport as b3, createWatermarkController as b4, debounce as b5, debounceTime as b6, decorrelatedJitter as b7, delay as b8, deserializeError as b9, fromIter as bA, fromKafka as bB, fromMCP as bC, fromNDJSON as bD, fromOTel as bE, fromPrometheus as bF, fromPromise as bG, fromRedisStream as bH, fromStatsD as bI, fromSyslog as bJ, fromTimer as bK, fromWebSocket as bL, fromWebhook as bM, gate as bN, globToRegExp as bO, interval as bP, last as bQ, linear as bR, map as bS, matchesAnyPattern as bT, matchesCron as bU, merge as bV, mergeMap as bW, nameToSignal as bX, never as bY, of as bZ, pairwise as b_, distill as ba, distinctUntilChanged as bb, elementAt as bc, empty as bd, escapeRegexChar as be, exhaustMap as bf, exponential as bg, index as bh, fibonacci as bi, filter as bj, find as bk, first as bl, firstValueFrom as bm, flatMap as bn, forEach as bo, fromAny as bp, fromAsyncIter as bq, fromCSV as br, fromClickHouseWatch as bs, fromCron as bt, fromEvent as bu, fromFSWatch as bv, fromGitHook as bw, fromHTTP as bx, fromIDBRequest as by, fromIDBTransaction as bz, type BackoffStrategy as c, parsePrometheusText as c0, parseStatsD as c1, parseSyslog as c2, pausable as c3, pubsub as c4, race as c5, rateLimiter as c6, reactiveIndex as c7, reactiveList as c8, reactiveMap as c9, timeout as cA, toArray as cB, toKafka as cC, toRedisStream as cD, toSSE as cE, toWebSocket as cF, tokenBucket as cG, tokenTracker as cH, verifiable as cI, window as cJ, windowCount as cK, windowTime as cL, withBreaker as cM, withLatestFrom as cN, withMaxAttempts as cO, withStatus as cP, workerBridge as cQ, workerSelf as cR, zip as cS, reduce as ca, repeat as cb, replay as cc, rescue as cd, resolveBackoffPreset as ce, restoreGraphCheckpoint as cf, restoreGraphCheckpointIndexedDb as cg, retry as ch, sample as ci, saveGraphCheckpoint as cj, saveGraphCheckpointIndexedDb as ck, scan as cl, serializeError as cm, share as cn, shareReplay as co, signalToName as cp, skip as cq, startWith as cr, switchMap as cs, take as ct, takeUntil as cu, takeWhile as cv, tap as cw, throttle as cx, throttleTime as cy, throwError as cz, type BatchMessage as d, type BridgeMessage as e, type CheckpointAdapter as f, type CircuitBreaker as g, type CircuitBreakerOptions as h, CircuitOpenError as i, type CircuitState as j, type ClickHouseClientLike as k, type ClickHouseRow as l, type CronSchedule as m, DictCheckpointAdapter as n, type DistillOptions as o, type ErrorMessage as p, type EventTargetLike as q, type ExponentialBackoffOptions as r, type FSEventType as s, FileCheckpointAdapter as t, type FromCSVOptions as u, type FromClickHouseWatchOptions as v, type FromCronOptions as w, type FromFSWatchOptions as x, type FromGitHookOptions as y, type FromHTTPOptions as z };
|