reactor-core-ts 3.2.2 → 3.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/core/demand.d.ts +4 -0
- package/dist/core/demand.d.ts.map +1 -1
- package/dist/core/demand.js +12 -4
- package/dist/core/demand.js.map +1 -1
- package/dist/internal/deep-value.d.ts +9 -0
- package/dist/internal/deep-value.d.ts.map +1 -0
- package/dist/internal/deep-value.js +159 -0
- package/dist/internal/deep-value.js.map +1 -0
- package/dist/internal/iterable-transform.d.ts +8 -1
- package/dist/internal/iterable-transform.d.ts.map +1 -1
- package/dist/internal/iterable-transform.js +7 -5
- package/dist/internal/iterable-transform.js.map +1 -1
- package/dist/internal/iteration-demand.d.ts +18 -0
- package/dist/internal/iteration-demand.d.ts.map +1 -0
- package/dist/internal/iteration-demand.js +34 -0
- package/dist/internal/iteration-demand.js.map +1 -0
- package/dist/internal/publisher-terminal.d.ts +25 -0
- package/dist/internal/publisher-terminal.d.ts.map +1 -0
- package/dist/internal/publisher-terminal.js +128 -0
- package/dist/internal/publisher-terminal.js.map +1 -0
- package/dist/publisher/flux.d.ts.map +1 -1
- package/dist/publisher/flux.js +22 -12
- package/dist/publisher/flux.js.map +1 -1
- package/dist/publisher/mono.d.ts.map +1 -1
- package/dist/publisher/mono.js +2 -1
- package/dist/publisher/mono.js.map +1 -1
- package/dist/publisher/operators/aggregate.d.ts.map +1 -1
- package/dist/publisher/operators/aggregate.js +136 -143
- package/dist/publisher/operators/aggregate.js.map +1 -1
- package/dist/publisher/operators/buffer-lift.d.ts +5 -0
- package/dist/publisher/operators/buffer-lift.d.ts.map +1 -0
- package/dist/publisher/operators/buffer-lift.js +197 -0
- package/dist/publisher/operators/buffer-lift.js.map +1 -0
- package/dist/publisher/operators/compat/flux.d.ts.map +1 -1
- package/dist/publisher/operators/compat/flux.js +86 -35
- package/dist/publisher/operators/compat/flux.js.map +1 -1
- package/dist/publisher/operators/coordination.d.ts.map +1 -1
- package/dist/publisher/operators/coordination.js +3 -4
- package/dist/publisher/operators/coordination.js.map +1 -1
- package/dist/publisher/operators/lifecycle.d.ts.map +1 -1
- package/dist/publisher/operators/lifecycle.js +64 -21
- package/dist/publisher/operators/lifecycle.js.map +1 -1
- package/dist/publisher/operators/lift.d.ts +2 -0
- package/dist/publisher/operators/lift.d.ts.map +1 -1
- package/dist/publisher/operators/lift.js +173 -3
- package/dist/publisher/operators/lift.js.map +1 -1
- package/dist/publisher/operators/selection.d.ts +5 -0
- package/dist/publisher/operators/selection.d.ts.map +1 -1
- package/dist/publisher/operators/selection.js +11 -2
- package/dist/publisher/operators/selection.js.map +1 -1
- package/dist/publisher/operators/terminal-mono.d.ts +12 -0
- package/dist/publisher/operators/terminal-mono.d.ts.map +1 -0
- package/dist/publisher/operators/terminal-mono.js +244 -0
- package/dist/publisher/operators/terminal-mono.js.map +1 -0
- package/dist/publisher/operators/terminal.d.ts.map +1 -1
- package/dist/publisher/operators/terminal.js +12 -25
- package/dist/publisher/operators/terminal.js.map +1 -1
- package/dist/publisher/operators/time.d.ts.map +1 -1
- package/dist/publisher/operators/time.js +2 -0
- package/dist/publisher/operators/time.js.map +1 -1
- package/dist/subscription/iterable-subscription.d.ts.map +1 -1
- package/dist/subscription/iterable-subscription.js +5 -2
- package/dist/subscription/iterable-subscription.js.map +1 -1
- package/package.json +1 -1
- package/dist/internal/iterable-terminal.d.ts +0 -12
- package/dist/internal/iterable-terminal.d.ts.map +0 -1
- package/dist/internal/iterable-terminal.js +0 -49
- package/dist/internal/iterable-terminal.js.map +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _defineProperty from "../../_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/defineProperty.js";
|
|
2
2
|
import { Context } from "../../context/context.js";
|
|
3
|
-
import { addCap } from "../../core/demand.js";
|
|
3
|
+
import { UNBOUNDED_DEMAND, addCap, normalizeRequest } from "../../core/demand.js";
|
|
4
|
+
import { ITERATION_DEMAND_HINT, iterationDemandHint } from "../../internal/iteration-demand.js";
|
|
4
5
|
import { Flux } from "../flux.js";
|
|
5
6
|
//#region src/publisher/operators/lift.ts
|
|
6
7
|
/**
|
|
@@ -22,6 +23,10 @@ function liftOneToOne(source, sourceFactory, hooksFactory) {
|
|
|
22
23
|
function liftFilter(source, sourceFactory, predicate) {
|
|
23
24
|
return liftFlux(source, sourceFactory, (subscriber) => new FilterOperatorSubscriber(subscriber, predicate));
|
|
24
25
|
}
|
|
26
|
+
/** Creates a limiting operator that never requests more than its remaining item count. */
|
|
27
|
+
function liftTake(source, sourceFactory, count) {
|
|
28
|
+
return liftFlux(source, sourceFactory, (subscriber) => new TakeOperatorSubscriber(subscriber, count));
|
|
29
|
+
}
|
|
25
30
|
/** Returns the context exposed by a subscriber, or the shared empty context. */
|
|
26
31
|
function subscriberContext(subscriber) {
|
|
27
32
|
return subscriber.currentContext?.() ?? Context.empty();
|
|
@@ -114,6 +119,7 @@ var OneToOneOperatorSubscriber = class {
|
|
|
114
119
|
this.terminateWithError(error, true);
|
|
115
120
|
return;
|
|
116
121
|
}
|
|
122
|
+
if (this.terminated) return;
|
|
117
123
|
this.actual.onNext(mapped);
|
|
118
124
|
}
|
|
119
125
|
/** Forwards an upstream error after running the operator callback. */
|
|
@@ -129,6 +135,7 @@ var OneToOneOperatorSubscriber = class {
|
|
|
129
135
|
this.terminateWithError(error, false);
|
|
130
136
|
return;
|
|
131
137
|
}
|
|
138
|
+
if (this.terminated) return;
|
|
132
139
|
this.terminated = true;
|
|
133
140
|
try {
|
|
134
141
|
this.actual.onComplete();
|
|
@@ -145,6 +152,7 @@ var OneToOneOperatorSubscriber = class {
|
|
|
145
152
|
this.terminateWithError(error, true);
|
|
146
153
|
return;
|
|
147
154
|
}
|
|
155
|
+
if (this.terminated) return;
|
|
148
156
|
this.upstream?.request(n);
|
|
149
157
|
}
|
|
150
158
|
/** Cancels upstream once and reports the cancellation lifecycle hooks. */
|
|
@@ -165,6 +173,10 @@ var OneToOneOperatorSubscriber = class {
|
|
|
165
173
|
currentContext() {
|
|
166
174
|
return this.hooks.currentContext?.() ?? subscriberContext(this.actual);
|
|
167
175
|
}
|
|
176
|
+
/** Propagates a known terminal demand batch through this one-to-one boundary. */
|
|
177
|
+
[ITERATION_DEMAND_HINT]() {
|
|
178
|
+
return iterationDemandHint(this.actual);
|
|
179
|
+
}
|
|
168
180
|
/** Cancels when needed and emits one downstream error signal. */
|
|
169
181
|
terminateWithError(error, cancelUpstream) {
|
|
170
182
|
if (this.terminated) return;
|
|
@@ -284,7 +296,7 @@ var FilterOperatorSubscriber = class {
|
|
|
284
296
|
/** Forwards demand and records when no further compensation is necessary. */
|
|
285
297
|
request(n) {
|
|
286
298
|
if (this.terminated) return;
|
|
287
|
-
if (n ===
|
|
299
|
+
if (n === UNBOUNDED_DEMAND) this.unbounded = true;
|
|
288
300
|
this.requestUpstream(n);
|
|
289
301
|
}
|
|
290
302
|
/** Cancels the upstream once. */
|
|
@@ -297,6 +309,10 @@ var FilterOperatorSubscriber = class {
|
|
|
297
309
|
currentContext() {
|
|
298
310
|
return subscriberContext(this.actual);
|
|
299
311
|
}
|
|
312
|
+
/** Propagates a known unbounded terminal batch through this filtering boundary. */
|
|
313
|
+
[ITERATION_DEMAND_HINT]() {
|
|
314
|
+
return iterationDemandHint(this.actual);
|
|
315
|
+
}
|
|
300
316
|
/** Drains demand iteratively so synchronous sources cannot recurse through dropped values. */
|
|
301
317
|
requestUpstream(n) {
|
|
302
318
|
if (this.requesting) {
|
|
@@ -319,6 +335,160 @@ var FilterOperatorSubscriber = class {
|
|
|
319
335
|
}
|
|
320
336
|
}
|
|
321
337
|
};
|
|
338
|
+
/** Subscriber that caps cumulative upstream demand and completes after a fixed number of values. */
|
|
339
|
+
var TakeOperatorSubscriber = class {
|
|
340
|
+
/** Creates a take subscriber with the provided maximum value count. */
|
|
341
|
+
constructor(actual, count) {
|
|
342
|
+
_defineProperty(this, "actual", void 0);
|
|
343
|
+
_defineProperty(
|
|
344
|
+
this,
|
|
345
|
+
/** Active upstream subscription. */
|
|
346
|
+
"upstream",
|
|
347
|
+
void 0
|
|
348
|
+
);
|
|
349
|
+
_defineProperty(
|
|
350
|
+
this,
|
|
351
|
+
/** Remaining values before this operator completes. */
|
|
352
|
+
"remaining",
|
|
353
|
+
void 0
|
|
354
|
+
);
|
|
355
|
+
_defineProperty(
|
|
356
|
+
this,
|
|
357
|
+
/** Requested upstream values that have not arrived yet. */
|
|
358
|
+
"outstanding",
|
|
359
|
+
0
|
|
360
|
+
);
|
|
361
|
+
_defineProperty(
|
|
362
|
+
this,
|
|
363
|
+
/** Guards synchronous upstream request calls against recursive downstream demand. */
|
|
364
|
+
"requesting",
|
|
365
|
+
false
|
|
366
|
+
);
|
|
367
|
+
_defineProperty(
|
|
368
|
+
this,
|
|
369
|
+
/** Downstream demand accumulated while an upstream request is active. */
|
|
370
|
+
"missedRequested",
|
|
371
|
+
0
|
|
372
|
+
);
|
|
373
|
+
_defineProperty(
|
|
374
|
+
this,
|
|
375
|
+
/** Prevents duplicate subscriptions from replacing the active upstream. */
|
|
376
|
+
"subscribed",
|
|
377
|
+
false
|
|
378
|
+
);
|
|
379
|
+
_defineProperty(
|
|
380
|
+
this,
|
|
381
|
+
/** Suppresses signals after cancellation or termination. */
|
|
382
|
+
"terminated",
|
|
383
|
+
false
|
|
384
|
+
);
|
|
385
|
+
this.actual = actual;
|
|
386
|
+
this.remaining = count;
|
|
387
|
+
}
|
|
388
|
+
/** Stores upstream and exposes the capped subscription downstream. */
|
|
389
|
+
onSubscribe(subscription) {
|
|
390
|
+
if (this.subscribed || this.terminated) {
|
|
391
|
+
cancelSilently(subscription);
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
this.subscribed = true;
|
|
395
|
+
this.upstream = subscription;
|
|
396
|
+
try {
|
|
397
|
+
this.actual.onSubscribe(this);
|
|
398
|
+
} catch (error) {
|
|
399
|
+
this.terminated = true;
|
|
400
|
+
cancelSilently(subscription);
|
|
401
|
+
throw error;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
/** Forwards one value and cancels upstream exactly at the configured limit. */
|
|
405
|
+
onNext(value) {
|
|
406
|
+
if (this.terminated || this.remaining === 0) return;
|
|
407
|
+
if (this.outstanding > 0) this.outstanding -= 1;
|
|
408
|
+
this.remaining -= 1;
|
|
409
|
+
try {
|
|
410
|
+
this.actual.onNext(value);
|
|
411
|
+
} catch (error) {
|
|
412
|
+
if (this.terminated) return;
|
|
413
|
+
this.terminated = true;
|
|
414
|
+
if (this.upstream) cancelSilently(this.upstream);
|
|
415
|
+
this.actual.onError(error);
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
if (this.remaining === 0 && !this.terminated) {
|
|
419
|
+
this.terminated = true;
|
|
420
|
+
if (this.upstream) cancelSilently(this.upstream);
|
|
421
|
+
this.actual.onComplete();
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
/** Forwards the first upstream failure. */
|
|
425
|
+
onError(error) {
|
|
426
|
+
if (this.terminated) return;
|
|
427
|
+
this.terminated = true;
|
|
428
|
+
this.actual.onError(error);
|
|
429
|
+
}
|
|
430
|
+
/** Forwards early upstream completion. */
|
|
431
|
+
onComplete() {
|
|
432
|
+
if (this.terminated) return;
|
|
433
|
+
this.terminated = true;
|
|
434
|
+
this.actual.onComplete();
|
|
435
|
+
}
|
|
436
|
+
/** Requests only demand that still fits below the take limit. */
|
|
437
|
+
request(n) {
|
|
438
|
+
if (this.terminated) return;
|
|
439
|
+
let demand;
|
|
440
|
+
try {
|
|
441
|
+
demand = normalizeRequest(n);
|
|
442
|
+
} catch (error) {
|
|
443
|
+
this.terminated = true;
|
|
444
|
+
if (this.upstream) cancelSilently(this.upstream);
|
|
445
|
+
this.actual.onError(error);
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
if (this.requesting) {
|
|
449
|
+
this.missedRequested = addCap(this.missedRequested, demand);
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
this.requesting = true;
|
|
453
|
+
let nextDemand = demand;
|
|
454
|
+
try {
|
|
455
|
+
while (!this.terminated) {
|
|
456
|
+
const available = this.remaining - this.outstanding;
|
|
457
|
+
if (available > 0) {
|
|
458
|
+
const request = Math.min(nextDemand, available);
|
|
459
|
+
this.outstanding += request;
|
|
460
|
+
this.upstream?.request(request);
|
|
461
|
+
}
|
|
462
|
+
if (this.terminated || this.missedRequested === 0) return;
|
|
463
|
+
nextDemand = this.missedRequested;
|
|
464
|
+
this.missedRequested = 0;
|
|
465
|
+
}
|
|
466
|
+
} catch (error) {
|
|
467
|
+
if (!this.terminated) {
|
|
468
|
+
this.terminated = true;
|
|
469
|
+
if (this.upstream) cancelSilently(this.upstream);
|
|
470
|
+
this.actual.onError(error);
|
|
471
|
+
}
|
|
472
|
+
} finally {
|
|
473
|
+
this.requesting = false;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
/** Cancels the active upstream once. */
|
|
477
|
+
cancel() {
|
|
478
|
+
if (this.terminated) return;
|
|
479
|
+
this.terminated = true;
|
|
480
|
+
this.upstream?.cancel();
|
|
481
|
+
}
|
|
482
|
+
/** Exposes the downstream context unchanged. */
|
|
483
|
+
currentContext() {
|
|
484
|
+
return subscriberContext(this.actual);
|
|
485
|
+
}
|
|
486
|
+
/** Propagates downstream demand metadata while `take` still applies its own cap. */
|
|
487
|
+
[ITERATION_DEMAND_HINT]() {
|
|
488
|
+
const downstream = iterationDemandHint(this.actual);
|
|
489
|
+
return downstream === void 0 ? void 0 : Math.min(downstream, this.remaining);
|
|
490
|
+
}
|
|
491
|
+
};
|
|
322
492
|
/** Signals a lifter assembly failure through a valid Reactive Streams handshake. */
|
|
323
493
|
function signalAssemblyError(subscriber, error) {
|
|
324
494
|
subscriber.onSubscribe(EMPTY_SUBSCRIPTION);
|
|
@@ -338,6 +508,6 @@ var EMPTY_SUBSCRIPTION = Object.freeze({
|
|
|
338
508
|
cancel() {}
|
|
339
509
|
});
|
|
340
510
|
//#endregion
|
|
341
|
-
export { liftFilter, liftFlux, liftOneToOne, subscriberContext };
|
|
511
|
+
export { liftFilter, liftFlux, liftOneToOne, liftTake, subscriberContext };
|
|
342
512
|
|
|
343
513
|
//# sourceMappingURL=lift.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lift.js","names":[],"sources":["../../../src/publisher/operators/lift.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Internal subscriber-lifting primitives for demand-preserving Flux operators.\n */\nimport {Context} from \"@/context/context.js\";\nimport {addCap} from \"@/core/demand.js\";\nimport type {SourceFactory} from \"@/publisher/types.js\";\nimport {Flux} from \"@/publisher/flux.js\";\nimport type {CoreSubscriber} from \"@/subscription/core-subscriber.js\";\nimport type {Subscriber} from \"@/subscription/subscriber.js\";\nimport type {Subscription} from \"@/subscription/subscription.js\";\n\n/** Creates the subscriber that an upstream Flux sees for a downstream subscriber. */\nexport type SubscriberLifter<T, R> = (subscriber: Subscriber<R>) => Subscriber<T>;\n\n/** Hooks used by synchronous one-input/one-output operators. */\nexport interface OneToOneOperatorHooks<T, R> {\n /** Converts one upstream value into exactly one downstream value. */\n onNext(value: T): R;\n\n /** Runs before the downstream receives its subscription. */\n onSubscribe?(subscription: Subscription): void;\n\n /** Runs before an upstream error is forwarded. */\n onError?(error: unknown): void;\n\n /** Runs before downstream demand is forwarded upstream. */\n onRequest?(request: number): void;\n\n /** Runs before successful completion is forwarded. */\n onComplete?(): void;\n\n /** Runs when downstream cancellation is propagated upstream. */\n onCancel?(): void;\n\n /** Runs after the terminal signal or cancellation has been propagated. */\n onFinally?(signal: \"complete\" | \"error\" | \"cancel\"): void;\n\n /** Context exposed to the upstream subscriber. */\n currentContext?(): Context;\n}\n\n/**\n * Lifts a Flux at the Reactive Streams subscriber boundary while keeping an\n * iterable implementation for explicit async-iterator consumption.\n */\nexport function liftFlux<T, R>(\n source: Flux<T>,\n sourceFactory: SourceFactory<R>,\n lifter: SubscriberLifter<T, R>\n): Flux<R> {\n return new LiftedFlux(source, sourceFactory, lifter);\n}\n\n/** Creates a one-to-one operator that forwards downstream demand unchanged. */\nexport function liftOneToOne<T, R>(\n source: Flux<T>,\n sourceFactory: SourceFactory<R>,\n hooksFactory: (subscriber: Subscriber<R>) => OneToOneOperatorHooks<T, R>\n): Flux<R> {\n return liftFlux(source, sourceFactory, subscriber =>\n new OneToOneOperatorSubscriber(subscriber, hooksFactory(subscriber))\n );\n}\n\n/** Creates a filtering operator that replenishes only values dropped from finite demand. */\nexport function liftFilter<T>(\n source: Flux<T>,\n sourceFactory: SourceFactory<T>,\n predicate: (value: T) => boolean\n): Flux<T> {\n return liftFlux(source, sourceFactory, subscriber => new FilterOperatorSubscriber(subscriber, predicate));\n}\n\n/** Returns the context exposed by a subscriber, or the shared empty context. */\nexport function subscriberContext<T>(subscriber: Subscriber<T>): Context {\n return (subscriber as CoreSubscriber<T>).currentContext?.() ?? Context.empty();\n}\n\n/** Flux whose normal subscribe path is assembled through a subscriber lifter. */\nclass LiftedFlux<T, R> extends Flux<R> {\n /** Creates a lifted Flux around an upstream source. */\n public constructor(\n private readonly source: Flux<T>,\n sourceFactory: SourceFactory<R>,\n private readonly lifter: SubscriberLifter<T, R>\n ) {\n super(sourceFactory);\n }\n\n /** Subscribes without crossing the async-iterator bridge. */\n protected override subscribeActual(subscriber: Subscriber<R>): void {\n let upstreamSubscriber: Subscriber<T>;\n try {\n upstreamSubscriber = this.lifter(subscriber);\n } catch (error) {\n signalAssemblyError(subscriber, error);\n return;\n }\n this.source.subscribe(upstreamSubscriber);\n }\n}\n\n/** Subscription/subscriber pair shared by synchronous one-to-one operators. */\nclass OneToOneOperatorSubscriber<T, R> implements CoreSubscriber<T>, Subscription {\n /** Upstream subscription received during the Reactive Streams handshake. */\n private upstream: Subscription | undefined;\n /** Prevents duplicate subscriptions from replacing the active upstream. */\n private subscribed = false;\n /** Suppresses signals and demand after cancellation or termination. */\n private terminated = false;\n\n /** Creates a one-to-one operator subscriber. */\n public constructor(\n private readonly actual: Subscriber<R>,\n private readonly hooks: OneToOneOperatorHooks<T, R>\n ) {\n }\n\n /** Installs the upstream subscription and exposes this forwarding subscription downstream. */\n public onSubscribe(subscription: Subscription): void {\n if (this.subscribed || this.terminated) {\n subscription.cancel();\n return;\n }\n this.subscribed = true;\n this.upstream = subscription;\n\n try {\n this.hooks.onSubscribe?.(subscription);\n } catch (error) {\n this.terminated = true;\n cancelSilently(subscription);\n this.actual.onSubscribe(this);\n this.signalError(error);\n return;\n }\n\n try {\n this.actual.onSubscribe(this);\n } catch (error) {\n this.terminated = true;\n try {\n subscription.cancel();\n } finally {\n this.runFinally(\"cancel\");\n }\n throw error;\n }\n }\n\n /** Converts and forwards one upstream value without changing demand. */\n public onNext(value: T): void {\n if (this.terminated) {\n return;\n }\n let mapped: R;\n try {\n mapped = this.hooks.onNext(value);\n } catch (error) {\n this.terminateWithError(error, true);\n return;\n }\n this.actual.onNext(mapped);\n }\n\n /** Forwards an upstream error after running the operator callback. */\n public onError(error: unknown): void {\n this.terminateWithError(error, false);\n }\n\n /** Forwards successful completion after running the operator callback. */\n public onComplete(): void {\n if (this.terminated) {\n return;\n }\n try {\n this.hooks.onComplete?.();\n } catch (error) {\n this.terminateWithError(error, false);\n return;\n }\n this.terminated = true;\n try {\n this.actual.onComplete();\n } finally {\n this.runFinally(\"complete\");\n }\n }\n\n /** Forwards exactly the requested amount to upstream. */\n public request(n: number): void {\n if (this.terminated) {\n return;\n }\n try {\n this.hooks.onRequest?.(n);\n } catch (error) {\n this.terminateWithError(error, true);\n return;\n }\n this.upstream?.request(n);\n }\n\n /** Cancels upstream once and reports the cancellation lifecycle hooks. */\n public cancel(): void {\n if (this.terminated) {\n return;\n }\n this.terminated = true;\n try {\n this.upstream?.cancel();\n } finally {\n try {\n this.hooks.onCancel?.();\n } finally {\n this.runFinally(\"cancel\");\n }\n }\n }\n\n /** Exposes downstream context to context-aware upstream publishers. */\n public currentContext(): Context {\n return this.hooks.currentContext?.() ?? subscriberContext(this.actual);\n }\n\n /** Cancels when needed and emits one downstream error signal. */\n private terminateWithError(error: unknown, cancelUpstream: boolean): void {\n if (this.terminated) {\n return;\n }\n this.terminated = true;\n if (cancelUpstream && this.upstream) {\n cancelSilently(this.upstream);\n }\n let failure = error;\n try {\n this.hooks.onError?.(error);\n } catch (callbackError) {\n failure = callbackError;\n }\n this.signalError(failure);\n }\n\n /** Delivers an error followed by the final error callback. */\n private signalError(error: unknown): void {\n try {\n this.actual.onError(error);\n } finally {\n this.runFinally(\"error\");\n }\n }\n\n /** Runs a final callback without letting observer code alter terminal semantics. */\n private runFinally(signal: \"complete\" | \"error\" | \"cancel\"): void {\n try {\n this.hooks.onFinally?.(signal);\n } catch {\n // Final observers run after propagation and cannot replace the terminal signal.\n }\n }\n}\n\n/** Filtering subscriber with stack-safe compensation for dropped values. */\nclass FilterOperatorSubscriber<T> implements CoreSubscriber<T>, Subscription {\n /** Upstream subscription received during the Reactive Streams handshake. */\n private upstream: Subscription | undefined;\n /** Prevents duplicate subscriptions from replacing the active upstream. */\n private subscribed = false;\n /** Suppresses signals and demand after cancellation or termination. */\n private terminated = false;\n /** Avoids compensation requests after downstream switches to unbounded demand. */\n private unbounded = false;\n /** Guards synchronous request calls against reentrant compensation. */\n private requesting = false;\n /** Compensation or downstream demand accumulated during an active request call. */\n private missedRequested = 0;\n\n /** Creates a filtering subscriber. */\n public constructor(\n private readonly actual: Subscriber<T>,\n private readonly predicate: (value: T) => boolean\n ) {\n }\n\n /** Installs upstream and exposes the demand-forwarding subscription downstream. */\n public onSubscribe(subscription: Subscription): void {\n if (this.subscribed || this.terminated) {\n subscription.cancel();\n return;\n }\n this.subscribed = true;\n this.upstream = subscription;\n try {\n this.actual.onSubscribe(this);\n } catch (error) {\n this.terminated = true;\n subscription.cancel();\n throw error;\n }\n }\n\n /** Tests one value, forwarding matches and replenishing finite demand for drops. */\n public onNext(value: T): void {\n if (this.terminated) {\n return;\n }\n let accepted: boolean;\n try {\n accepted = this.predicate(value);\n } catch (error) {\n this.terminated = true;\n if (this.upstream) {\n cancelSilently(this.upstream);\n }\n this.actual.onError(error);\n return;\n }\n if (accepted) {\n this.actual.onNext(value);\n } else if (!this.unbounded) {\n this.requestUpstream(1);\n }\n }\n\n /** Forwards one terminal error. */\n public onError(error: unknown): void {\n if (this.terminated) {\n return;\n }\n this.terminated = true;\n this.actual.onError(error);\n }\n\n /** Forwards successful completion once. */\n public onComplete(): void {\n if (this.terminated) {\n return;\n }\n this.terminated = true;\n this.actual.onComplete();\n }\n\n /** Forwards demand and records when no further compensation is necessary. */\n public request(n: number): void {\n if (this.terminated) {\n return;\n }\n if (n === Number.POSITIVE_INFINITY) {\n this.unbounded = true;\n }\n this.requestUpstream(n);\n }\n\n /** Cancels the upstream once. */\n public cancel(): void {\n if (this.terminated) {\n return;\n }\n this.terminated = true;\n this.upstream?.cancel();\n }\n\n /** Exposes the downstream context unchanged. */\n public currentContext(): Context {\n return subscriberContext(this.actual);\n }\n\n /** Drains demand iteratively so synchronous sources cannot recurse through dropped values. */\n private requestUpstream(n: number): void {\n if (this.requesting) {\n this.missedRequested = addCap(this.missedRequested, n);\n return;\n }\n const upstream = this.upstream;\n if (!upstream) {\n return;\n }\n this.requesting = true;\n let request = n;\n try {\n while (!this.terminated) {\n upstream.request(request);\n if (this.terminated || this.missedRequested === 0) {\n return;\n }\n request = this.missedRequested;\n this.missedRequested = 0;\n }\n } finally {\n this.requesting = false;\n }\n }\n}\n\n/** Signals a lifter assembly failure through a valid Reactive Streams handshake. */\nfunction signalAssemblyError<T>(subscriber: Subscriber<T>, error: unknown): void {\n subscriber.onSubscribe(EMPTY_SUBSCRIPTION);\n subscriber.onError(error);\n}\n\n/** Cancels an upstream while preserving the original operator failure. */\nfunction cancelSilently(subscription: Subscription): void {\n try {\n subscription.cancel();\n } catch {\n // The operator failure remains the terminal signal.\n }\n}\n\n/** Shared inert subscription used only when operator assembly fails. */\nconst EMPTY_SUBSCRIPTION: Subscription = Object.freeze({\n /** Ignores requests because the sequence has already failed. */\n request() {\n // no-op\n },\n /** Ignores cancellation because no upstream was subscribed. */\n cancel() {\n // no-op\n }\n});\n"],"mappings":";;;;;;;;;;;;;AA8CA,SAAgB,SACZ,QACA,eACA,QACO;CACP,OAAO,IAAI,WAAW,QAAQ,eAAe,MAAM;AACvD;;AAGA,SAAgB,aACZ,QACA,eACA,cACO;CACP,OAAO,SAAS,QAAQ,gBAAe,eACnC,IAAI,2BAA2B,YAAY,aAAa,UAAU,CAAC,CACvE;AACJ;;AAGA,SAAgB,WACZ,QACA,eACA,WACO;CACP,OAAO,SAAS,QAAQ,gBAAe,eAAc,IAAI,yBAAyB,YAAY,SAAS,CAAC;AAC5G;;AAGA,SAAgB,kBAAqB,YAAoC;CACrE,OAAQ,WAAiC,iBAAiB,KAAK,QAAQ,MAAM;AACjF;;AAGA,IAAM,aAAN,cAA+B,KAAQ;;CAEnC,YACI,QACA,eACA,QACF;EACE,MAAM,aAAa;wBAJF,UAAA,KAAA,CAAA;wBAEA,UAAA,KAAA,CAAA;EAFA,KAAA,SAAA;EAEA,KAAA,SAAA;CAGrB;;CAGA,gBAAmC,YAAiC;EAChE,IAAI;EACJ,IAAI;GACA,qBAAqB,KAAK,OAAO,UAAU;EAC/C,SAAS,OAAO;GACZ,oBAAoB,YAAY,KAAK;GACrC;EACJ;EACA,KAAK,OAAO,UAAU,kBAAkB;CAC5C;AACJ;;AAGA,IAAM,6BAAN,MAAkF;;CAS9E,YACI,QACA,OACF;wBAFmB,UAAA,KAAA,CAAA;wBACA,SAAA,KAAA,CAAA;;;;GATrB;;;;;;GAEA;GAAqB;;;;;GAErB;GAAqB;;EAIA,KAAA,SAAA;EACA,KAAA,QAAA;CAErB;;CAGA,YAAmB,cAAkC;EACjD,IAAI,KAAK,cAAc,KAAK,YAAY;GACpC,aAAa,OAAO;GACpB;EACJ;EACA,KAAK,aAAa;EAClB,KAAK,WAAW;EAEhB,IAAI;GACA,KAAK,MAAM,cAAc,YAAY;EACzC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["/**\n * @packageDocumentation\n * Internal subscriber-lifting primitives for demand-preserving Flux operators.\n */\nimport {Context} from \"@/context/context.js\";\nimport {addCap, normalizeRequest, UNBOUNDED_DEMAND} from \"@/core/demand.js\";\nimport {ITERATION_DEMAND_HINT, iterationDemandHint} from \"@/internal/iteration-demand.js\";\nimport type {SourceFactory} from \"@/publisher/types.js\";\nimport {Flux} from \"@/publisher/flux.js\";\nimport type {CoreSubscriber} from \"@/subscription/core-subscriber.js\";\nimport type {Subscriber} from \"@/subscription/subscriber.js\";\nimport type {Subscription} from \"@/subscription/subscription.js\";\n\n/** Creates the subscriber that an upstream Flux sees for a downstream subscriber. */\nexport type SubscriberLifter<T, R> = (subscriber: Subscriber<R>) => Subscriber<T>;\n\n/** Hooks used by synchronous one-input/one-output operators. */\nexport interface OneToOneOperatorHooks<T, R> {\n /** Converts one upstream value into exactly one downstream value. */\n onNext(value: T): R;\n\n /** Runs before the downstream receives its subscription. */\n onSubscribe?(subscription: Subscription): void;\n\n /** Runs before an upstream error is forwarded. */\n onError?(error: unknown): void;\n\n /** Runs before downstream demand is forwarded upstream. */\n onRequest?(request: number): void;\n\n /** Runs before successful completion is forwarded. */\n onComplete?(): void;\n\n /** Runs when downstream cancellation is propagated upstream. */\n onCancel?(): void;\n\n /** Runs after the terminal signal or cancellation has been propagated. */\n onFinally?(signal: \"complete\" | \"error\" | \"cancel\"): void;\n\n /** Context exposed to the upstream subscriber. */\n currentContext?(): Context;\n}\n\n/**\n * Lifts a Flux at the Reactive Streams subscriber boundary while keeping an\n * iterable implementation for explicit async-iterator consumption.\n */\nexport function liftFlux<T, R>(\n source: Flux<T>,\n sourceFactory: SourceFactory<R>,\n lifter: SubscriberLifter<T, R>\n): Flux<R> {\n return new LiftedFlux(source, sourceFactory, lifter);\n}\n\n/** Creates a one-to-one operator that forwards downstream demand unchanged. */\nexport function liftOneToOne<T, R>(\n source: Flux<T>,\n sourceFactory: SourceFactory<R>,\n hooksFactory: (subscriber: Subscriber<R>) => OneToOneOperatorHooks<T, R>\n): Flux<R> {\n return liftFlux(source, sourceFactory, subscriber =>\n new OneToOneOperatorSubscriber(subscriber, hooksFactory(subscriber))\n );\n}\n\n/** Creates a filtering operator that replenishes only values dropped from finite demand. */\nexport function liftFilter<T>(\n source: Flux<T>,\n sourceFactory: SourceFactory<T>,\n predicate: (value: T) => boolean\n): Flux<T> {\n return liftFlux(source, sourceFactory, subscriber => new FilterOperatorSubscriber(subscriber, predicate));\n}\n\n/** Creates a limiting operator that never requests more than its remaining item count. */\nexport function liftTake<T>(source: Flux<T>, sourceFactory: SourceFactory<T>, count: number): Flux<T> {\n return liftFlux(source, sourceFactory, subscriber => new TakeOperatorSubscriber(subscriber, count));\n}\n\n/** Returns the context exposed by a subscriber, or the shared empty context. */\nexport function subscriberContext<T>(subscriber: Subscriber<T>): Context {\n return (subscriber as CoreSubscriber<T>).currentContext?.() ?? Context.empty();\n}\n\n/** Flux whose normal subscribe path is assembled through a subscriber lifter. */\nclass LiftedFlux<T, R> extends Flux<R> {\n /** Creates a lifted Flux around an upstream source. */\n public constructor(\n private readonly source: Flux<T>,\n sourceFactory: SourceFactory<R>,\n private readonly lifter: SubscriberLifter<T, R>\n ) {\n super(sourceFactory);\n }\n\n /** Subscribes without crossing the async-iterator bridge. */\n protected override subscribeActual(subscriber: Subscriber<R>): void {\n let upstreamSubscriber: Subscriber<T>;\n try {\n upstreamSubscriber = this.lifter(subscriber);\n } catch (error) {\n signalAssemblyError(subscriber, error);\n return;\n }\n this.source.subscribe(upstreamSubscriber);\n }\n}\n\n/** Subscription/subscriber pair shared by synchronous one-to-one operators. */\nclass OneToOneOperatorSubscriber<T, R> implements CoreSubscriber<T>, Subscription {\n /** Upstream subscription received during the Reactive Streams handshake. */\n private upstream: Subscription | undefined;\n /** Prevents duplicate subscriptions from replacing the active upstream. */\n private subscribed = false;\n /** Suppresses signals and demand after cancellation or termination. */\n private terminated = false;\n\n /** Creates a one-to-one operator subscriber. */\n public constructor(\n private readonly actual: Subscriber<R>,\n private readonly hooks: OneToOneOperatorHooks<T, R>\n ) {\n }\n\n /** Installs the upstream subscription and exposes this forwarding subscription downstream. */\n public onSubscribe(subscription: Subscription): void {\n if (this.subscribed || this.terminated) {\n subscription.cancel();\n return;\n }\n this.subscribed = true;\n this.upstream = subscription;\n\n try {\n this.hooks.onSubscribe?.(subscription);\n } catch (error) {\n this.terminated = true;\n cancelSilently(subscription);\n this.actual.onSubscribe(this);\n this.signalError(error);\n return;\n }\n\n try {\n this.actual.onSubscribe(this);\n } catch (error) {\n this.terminated = true;\n try {\n subscription.cancel();\n } finally {\n this.runFinally(\"cancel\");\n }\n throw error;\n }\n }\n\n /** Converts and forwards one upstream value without changing demand. */\n public onNext(value: T): void {\n if (this.terminated) {\n return;\n }\n let mapped: R;\n try {\n mapped = this.hooks.onNext(value);\n } catch (error) {\n this.terminateWithError(error, true);\n return;\n }\n if (this.terminated) {\n return;\n }\n this.actual.onNext(mapped);\n }\n\n /** Forwards an upstream error after running the operator callback. */\n public onError(error: unknown): void {\n this.terminateWithError(error, false);\n }\n\n /** Forwards successful completion after running the operator callback. */\n public onComplete(): void {\n if (this.terminated) {\n return;\n }\n try {\n this.hooks.onComplete?.();\n } catch (error) {\n this.terminateWithError(error, false);\n return;\n }\n if (this.terminated) {\n return;\n }\n this.terminated = true;\n try {\n this.actual.onComplete();\n } finally {\n this.runFinally(\"complete\");\n }\n }\n\n /** Forwards exactly the requested amount to upstream. */\n public request(n: number): void {\n if (this.terminated) {\n return;\n }\n try {\n this.hooks.onRequest?.(n);\n } catch (error) {\n this.terminateWithError(error, true);\n return;\n }\n if (this.terminated) {\n return;\n }\n this.upstream?.request(n);\n }\n\n /** Cancels upstream once and reports the cancellation lifecycle hooks. */\n public cancel(): void {\n if (this.terminated) {\n return;\n }\n this.terminated = true;\n try {\n this.upstream?.cancel();\n } finally {\n try {\n this.hooks.onCancel?.();\n } finally {\n this.runFinally(\"cancel\");\n }\n }\n }\n\n /** Exposes downstream context to context-aware upstream publishers. */\n public currentContext(): Context {\n return this.hooks.currentContext?.() ?? subscriberContext(this.actual);\n }\n\n /** Propagates a known terminal demand batch through this one-to-one boundary. */\n public [ITERATION_DEMAND_HINT](): number | undefined {\n return iterationDemandHint(this.actual);\n }\n\n /** Cancels when needed and emits one downstream error signal. */\n private terminateWithError(error: unknown, cancelUpstream: boolean): void {\n if (this.terminated) {\n return;\n }\n this.terminated = true;\n if (cancelUpstream && this.upstream) {\n cancelSilently(this.upstream);\n }\n let failure = error;\n try {\n this.hooks.onError?.(error);\n } catch (callbackError) {\n failure = callbackError;\n }\n this.signalError(failure);\n }\n\n /** Delivers an error followed by the final error callback. */\n private signalError(error: unknown): void {\n try {\n this.actual.onError(error);\n } finally {\n this.runFinally(\"error\");\n }\n }\n\n /** Runs a final callback without letting observer code alter terminal semantics. */\n private runFinally(signal: \"complete\" | \"error\" | \"cancel\"): void {\n try {\n this.hooks.onFinally?.(signal);\n } catch {\n // Final observers run after propagation and cannot replace the terminal signal.\n }\n }\n}\n\n/** Filtering subscriber with stack-safe compensation for dropped values. */\nclass FilterOperatorSubscriber<T> implements CoreSubscriber<T>, Subscription {\n /** Upstream subscription received during the Reactive Streams handshake. */\n private upstream: Subscription | undefined;\n /** Prevents duplicate subscriptions from replacing the active upstream. */\n private subscribed = false;\n /** Suppresses signals and demand after cancellation or termination. */\n private terminated = false;\n /** Avoids compensation requests after downstream switches to unbounded demand. */\n private unbounded = false;\n /** Guards synchronous request calls against reentrant compensation. */\n private requesting = false;\n /** Compensation or downstream demand accumulated during an active request call. */\n private missedRequested = 0;\n\n /** Creates a filtering subscriber. */\n public constructor(\n private readonly actual: Subscriber<T>,\n private readonly predicate: (value: T) => boolean\n ) {\n }\n\n /** Installs upstream and exposes the demand-forwarding subscription downstream. */\n public onSubscribe(subscription: Subscription): void {\n if (this.subscribed || this.terminated) {\n subscription.cancel();\n return;\n }\n this.subscribed = true;\n this.upstream = subscription;\n try {\n this.actual.onSubscribe(this);\n } catch (error) {\n this.terminated = true;\n subscription.cancel();\n throw error;\n }\n }\n\n /** Tests one value, forwarding matches and replenishing finite demand for drops. */\n public onNext(value: T): void {\n if (this.terminated) {\n return;\n }\n let accepted: boolean;\n try {\n accepted = this.predicate(value);\n } catch (error) {\n this.terminated = true;\n if (this.upstream) {\n cancelSilently(this.upstream);\n }\n this.actual.onError(error);\n return;\n }\n if (accepted) {\n this.actual.onNext(value);\n } else if (!this.unbounded) {\n this.requestUpstream(1);\n }\n }\n\n /** Forwards one terminal error. */\n public onError(error: unknown): void {\n if (this.terminated) {\n return;\n }\n this.terminated = true;\n this.actual.onError(error);\n }\n\n /** Forwards successful completion once. */\n public onComplete(): void {\n if (this.terminated) {\n return;\n }\n this.terminated = true;\n this.actual.onComplete();\n }\n\n /** Forwards demand and records when no further compensation is necessary. */\n public request(n: number): void {\n if (this.terminated) {\n return;\n }\n if (n === UNBOUNDED_DEMAND) {\n this.unbounded = true;\n }\n this.requestUpstream(n);\n }\n\n /** Cancels the upstream once. */\n public cancel(): void {\n if (this.terminated) {\n return;\n }\n this.terminated = true;\n this.upstream?.cancel();\n }\n\n /** Exposes the downstream context unchanged. */\n public currentContext(): Context {\n return subscriberContext(this.actual);\n }\n\n /** Propagates a known unbounded terminal batch through this filtering boundary. */\n public [ITERATION_DEMAND_HINT](): number | undefined {\n return iterationDemandHint(this.actual);\n }\n\n /** Drains demand iteratively so synchronous sources cannot recurse through dropped values. */\n private requestUpstream(n: number): void {\n if (this.requesting) {\n this.missedRequested = addCap(this.missedRequested, n);\n return;\n }\n const upstream = this.upstream;\n if (!upstream) {\n return;\n }\n this.requesting = true;\n let request = n;\n try {\n while (!this.terminated) {\n upstream.request(request);\n if (this.terminated || this.missedRequested === 0) {\n return;\n }\n request = this.missedRequested;\n this.missedRequested = 0;\n }\n } finally {\n this.requesting = false;\n }\n }\n}\n\n/** Subscriber that caps cumulative upstream demand and completes after a fixed number of values. */\nclass TakeOperatorSubscriber<T> implements CoreSubscriber<T>, Subscription {\n /** Active upstream subscription. */\n private upstream: Subscription | undefined;\n /** Remaining values before this operator completes. */\n private remaining: number;\n /** Requested upstream values that have not arrived yet. */\n private outstanding = 0;\n /** Guards synchronous upstream request calls against recursive downstream demand. */\n private requesting = false;\n /** Downstream demand accumulated while an upstream request is active. */\n private missedRequested = 0;\n /** Prevents duplicate subscriptions from replacing the active upstream. */\n private subscribed = false;\n /** Suppresses signals after cancellation or termination. */\n private terminated = false;\n\n /** Creates a take subscriber with the provided maximum value count. */\n public constructor(private readonly actual: Subscriber<T>, count: number) {\n this.remaining = count;\n }\n\n /** Stores upstream and exposes the capped subscription downstream. */\n public onSubscribe(subscription: Subscription): void {\n if (this.subscribed || this.terminated) {\n cancelSilently(subscription);\n return;\n }\n this.subscribed = true;\n this.upstream = subscription;\n try {\n this.actual.onSubscribe(this);\n } catch (error) {\n this.terminated = true;\n cancelSilently(subscription);\n throw error;\n }\n }\n\n /** Forwards one value and cancels upstream exactly at the configured limit. */\n public onNext(value: T): void {\n if (this.terminated || this.remaining === 0) {\n return;\n }\n if (this.outstanding > 0) {\n this.outstanding -= 1;\n }\n this.remaining -= 1;\n try {\n this.actual.onNext(value);\n } catch (error) {\n if (this.terminated) {\n return;\n }\n this.terminated = true;\n if (this.upstream) {\n cancelSilently(this.upstream);\n }\n this.actual.onError(error);\n return;\n }\n if (this.remaining === 0 && !this.terminated) {\n this.terminated = true;\n if (this.upstream) {\n cancelSilently(this.upstream);\n }\n this.actual.onComplete();\n }\n }\n\n /** Forwards the first upstream failure. */\n public onError(error: unknown): void {\n if (this.terminated) {\n return;\n }\n this.terminated = true;\n this.actual.onError(error);\n }\n\n /** Forwards early upstream completion. */\n public onComplete(): void {\n if (this.terminated) {\n return;\n }\n this.terminated = true;\n this.actual.onComplete();\n }\n\n /** Requests only demand that still fits below the take limit. */\n public request(n: number): void {\n if (this.terminated) {\n return;\n }\n let demand: number;\n try {\n demand = normalizeRequest(n);\n } catch (error) {\n this.terminated = true;\n if (this.upstream) {\n cancelSilently(this.upstream);\n }\n this.actual.onError(error);\n return;\n }\n if (this.requesting) {\n this.missedRequested = addCap(this.missedRequested, demand);\n return;\n }\n this.requesting = true;\n let nextDemand = demand;\n try {\n while (!this.terminated) {\n const available = this.remaining - this.outstanding;\n if (available > 0) {\n const request = Math.min(nextDemand, available);\n this.outstanding += request;\n this.upstream?.request(request);\n }\n if (this.terminated || this.missedRequested === 0) {\n return;\n }\n nextDemand = this.missedRequested;\n this.missedRequested = 0;\n }\n } catch (error) {\n if (!this.terminated) {\n this.terminated = true;\n if (this.upstream) {\n cancelSilently(this.upstream);\n }\n this.actual.onError(error);\n }\n } finally {\n this.requesting = false;\n }\n }\n\n /** Cancels the active upstream once. */\n public cancel(): void {\n if (this.terminated) {\n return;\n }\n this.terminated = true;\n this.upstream?.cancel();\n }\n\n /** Exposes the downstream context unchanged. */\n public currentContext(): Context {\n return subscriberContext(this.actual);\n }\n\n /** Propagates downstream demand metadata while `take` still applies its own cap. */\n public [ITERATION_DEMAND_HINT](): number | undefined {\n const downstream = iterationDemandHint(this.actual);\n return downstream === undefined ? undefined : Math.min(downstream, this.remaining);\n }\n}\n\n/** Signals a lifter assembly failure through a valid Reactive Streams handshake. */\nfunction signalAssemblyError<T>(subscriber: Subscriber<T>, error: unknown): void {\n subscriber.onSubscribe(EMPTY_SUBSCRIPTION);\n subscriber.onError(error);\n}\n\n/** Cancels an upstream while preserving the original operator failure. */\nfunction cancelSilently(subscription: Subscription): void {\n try {\n subscription.cancel();\n } catch {\n // The operator failure remains the terminal signal.\n }\n}\n\n/** Shared inert subscription used only when operator assembly fails. */\nconst EMPTY_SUBSCRIPTION: Subscription = Object.freeze({\n /** Ignores requests because the sequence has already failed. */\n request() {\n // no-op\n },\n /** Ignores cancellation because no upstream was subscribed. */\n cancel() {\n // no-op\n }\n});\n"],"mappings":";;;;;;;;;;;;;;AA+CA,SAAgB,SACZ,QACA,eACA,QACO;CACP,OAAO,IAAI,WAAW,QAAQ,eAAe,MAAM;AACvD;;AAGA,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I,aAAa;EACjB,IAAI;GACA,OAAO,CAAC,KAAK,YAAY;IACrB,MAAM,YAAY,KAAK,YAAY,KAAK;IACxC,IAAI,YAAY,GAAG;KACf,MAAM,UAAU,KAAK,IAAI,YAAY,SAAS;KAC9C,KAAK,eAAe;KACpB,KAAK,UAAU,QAAQ,OAAO;IAClC;IACA,IAAI,KAAK,cAAc,KAAK,oBAAoB,GAC5C;IAEJ,aAAa,KAAK;IAClB,KAAK,kBAAkB;GAC3B;EACJ,SAAS,OAAO;GACZ,IAAI,CAAC,KAAK,YAAY;IAClB,KAAK,aAAa;IAClB,IAAI,KAAK,UACL,eAAe,KAAK,QAAQ;IAEhC,KAAK,OAAO,QAAQ,KAAK;GAC7B;EACJ,UAAU;GACN,KAAK,aAAa;EACtB;CACJ;;CAGA,SAAsB;EAClB,IAAI,KAAK,YACL;EAEJ,KAAK,aAAa;EAClB,KAAK,UAAU,OAAO;CAC1B;;CAGA,iBAAiC;EAC7B,OAAO,kBAAkB,KAAK,MAAM;CACxC;;CAGA,CAAQ,yBAA6C;EACjD,MAAM,aAAa,oBAAoB,KAAK,MAAM;EAClD,OAAO,eAAe,SAAY,SAAY,KAAK,IAAI,YAAY,KAAK,SAAS;CACrF;AACJ;;AAGA,SAAS,oBAAuB,YAA2B,OAAsB;CAC7E,WAAW,YAAY,kBAAkB;CACzC,WAAW,QAAQ,KAAK;AAC5B;;AAGA,SAAS,eAAe,cAAkC;CACtD,IAAI;EACA,aAAa,OAAO;CACxB,QAAQ,CAER;AACJ;;AAGA,IAAM,qBAAmC,OAAO,OAAO;;CAEnD,UAAU,CAEV;;CAEA,SAAS,CAET;AACJ,CAAC"}
|
|
@@ -16,6 +16,11 @@ declare module "../flux.js" {
|
|
|
16
16
|
distinct<K = T>(keySelector?: (value: T) => K): Flux<T>;
|
|
17
17
|
/** Drops adjacent values whose selected key is equal to the previous key. */
|
|
18
18
|
distinctUntilChanged<K = T>(keySelector?: (value: T) => K): Flux<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Drops adjacent values with equal nested state. Snapshots arrays, enumerable properties of ordinary objects,
|
|
21
|
+
* and local `Date`, `RegExp`, `Map` and `Set` values; other object types retain identity comparison.
|
|
22
|
+
*/
|
|
23
|
+
distinctUntilChangedDeep<K = T>(keySelector?: (value: T) => K): Flux<T>;
|
|
19
24
|
/** Emits `defaultValue` when the source completes without values. */
|
|
20
25
|
defaultIfEmpty(defaultValue: T): Flux<T>;
|
|
21
26
|
/** Switches to `alternate` when the source completes without values. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selection.d.ts","sourceRoot":"","sources":["../../../src/publisher/operators/selection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"selection.d.ts","sourceRoot":"","sources":["../../../src/publisher/operators/selection.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,sBAAsB,CAAC;AAEzD,OAAO,QAAQ,qBAAqB,CAAC;IACjC,uDAAuD;IACvD,UAAU,IAAI,CAAC,CAAC;QACZ,iDAAiD;QACjD,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEzB,4EAA4E;QAC5E,SAAS,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAErD,mFAAmF;QACnF,SAAS,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAErD,yCAAyC;QACzC,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEzB,2EAA2E;QAC3E,SAAS,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAErD,wDAAwD;QACxD,QAAQ,CAAC,CAAC,GAAG,CAAC,EAAE,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAExD,6EAA6E;QAC7E,oBAAoB,CAAC,CAAC,GAAG,CAAC,EAAE,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEpE;;;WAGG;QACH,wBAAwB,CAAC,CAAC,GAAG,CAAC,EAAE,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAExE,qEAAqE;QACrE,cAAc,CAAC,YAAY,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEzC,wEAAwE;QACxE,aAAa,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;KACxD;CACJ"}
|
|
@@ -2,6 +2,8 @@ import { isAsyncIterable, toAsyncIterator } from "../../internal/iterable.js";
|
|
|
2
2
|
import { defaultIfEmptyIterable, distinctIterable, distinctUntilChangedIterable, skipIterable, skipWhileIterable, takeUntilIterable, takeWhileIterable } from "../../internal/iterable-transform.js";
|
|
3
3
|
import { identity } from "../helpers.js";
|
|
4
4
|
import { Flux } from "../flux.js";
|
|
5
|
+
import { liftTake } from "./lift.js";
|
|
6
|
+
import { deepEqual, snapshotDeep } from "../../internal/deep-value.js";
|
|
5
7
|
//#region src/publisher/operators/selection.ts
|
|
6
8
|
/**
|
|
7
9
|
* @packageDocumentation
|
|
@@ -11,7 +13,7 @@ Flux.prototype.take = function take(n) {
|
|
|
11
13
|
if (!Number.isInteger(n) || n < 0) throw new RangeError("take expects a non-negative integer");
|
|
12
14
|
if (n === 0) return Flux.empty();
|
|
13
15
|
const source = this;
|
|
14
|
-
return
|
|
16
|
+
return liftTake(source, (signal, context) => {
|
|
15
17
|
const controller = new AbortController();
|
|
16
18
|
const abort = () => controller.abort(signal.reason);
|
|
17
19
|
signal.addEventListener("abort", abort, { once: true });
|
|
@@ -60,7 +62,7 @@ Flux.prototype.take = function take(n) {
|
|
|
60
62
|
if (cancelledSource || signal.aborted) await iterator.return?.();
|
|
61
63
|
}
|
|
62
64
|
})();
|
|
63
|
-
});
|
|
65
|
+
}, n);
|
|
64
66
|
};
|
|
65
67
|
Flux.prototype.takeWhile = function takeWhile(predicate) {
|
|
66
68
|
const source = this;
|
|
@@ -88,6 +90,13 @@ Flux.prototype.distinctUntilChanged = function distinctUntilChanged(keySelector
|
|
|
88
90
|
const source = this;
|
|
89
91
|
return new Flux((signal, context) => distinctUntilChangedIterable(source.iterate(signal, context), keySelector));
|
|
90
92
|
};
|
|
93
|
+
Flux.prototype.distinctUntilChangedDeep = function distinctUntilChangedDeep(keySelector = identity) {
|
|
94
|
+
const source = this;
|
|
95
|
+
return new Flux((signal, context) => distinctUntilChangedIterable(source.iterate(signal, context), keySelector, {
|
|
96
|
+
equals: deepEqual,
|
|
97
|
+
snapshot: snapshotDeep
|
|
98
|
+
}));
|
|
99
|
+
};
|
|
91
100
|
Flux.prototype.defaultIfEmpty = function defaultIfEmpty(defaultValue) {
|
|
92
101
|
const source = this;
|
|
93
102
|
return new Flux((signal, context) => defaultIfEmptyIterable(source.iterate(signal, context), defaultValue));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selection.js","names":[],"sources":["../../../src/publisher/operators/selection.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Flux, Mono and operator implementation modules.\n */\nimport {Flux} from \"@/publisher/flux.js\";\nimport {\n type AnyIterable,\n isAsyncIterable,\n toAsyncIterator\n} from \"@/internal/iterable.js\";\nimport {\n defaultIfEmptyIterable,\n distinctIterable,\n distinctUntilChangedIterable,\n skipIterable,\n skipWhileIterable,\n takeUntilIterable,\n takeWhileIterable\n} from \"@/internal/iterable-transform.js\";\nimport {identity} from \"@/publisher/helpers.js\";\nimport type {PublisherInput} from \"@/publisher/types.js\";\n\ndeclare module \"@/publisher/flux.js\" {\n /** Selection and filtering operators added to Flux. */\n interface Flux<T> {\n /** Emits at most the first `n` source values. */\n take(n: number): Flux<T>;\n\n /** Emits values while the predicate returns true, then cancels upstream. */\n takeWhile(predicate: (value: T) => boolean): Flux<T>;\n\n /** Emits values until the predicate returns true, including the matching value. */\n takeUntil(predicate: (value: T) => boolean): Flux<T>;\n\n /** Drops the first `n` source values. */\n skip(n: number): Flux<T>;\n\n /** Drops values while the predicate returns true, then relays the rest. */\n skipWhile(predicate: (value: T) => boolean): Flux<T>;\n\n /** Emits only the first value for each selected key. */\n distinct<K = T>(keySelector?: (value: T) => K): Flux<T>;\n\n /** Drops adjacent values whose selected key is equal to the previous key. */\n distinctUntilChanged<K = T>(keySelector?: (value: T) => K): Flux<T>;\n\n /** Emits `defaultValue` when the source completes without values. */\n defaultIfEmpty(defaultValue: T): Flux<T>;\n\n /** Switches to `alternate` when the source completes without values. */\n switchIfEmpty(alternate: PublisherInput<T>): Flux<T>;\n }\n}\n\nFlux.prototype.take = function take<T>(this: Flux<T>, n: number): Flux<T> {\n if (!Number.isInteger(n) || n < 0) {\n throw new RangeError(\"take expects a non-negative integer\");\n }\n if (n === 0) {\n return Flux.empty<T>();\n }\n const source = this;\n return new Flux((signal, context) => {\n const controller = new AbortController();\n const abort = () => controller.abort(signal.reason);\n signal.addEventListener(\"abort\", abort, {once: true});\n let values: AnyIterable<T>;\n try {\n values = source.iterate(controller.signal, context);\n } catch (error) {\n signal.removeEventListener(\"abort\", abort);\n throw error;\n }\n if (!isAsyncIterable<T>(values)) {\n return (function* () {\n let remaining = n;\n try {\n for (const value of values) {\n yield value;\n remaining -= 1;\n if (remaining === 0) {\n controller.abort();\n return;\n }\n }\n } finally {\n signal.removeEventListener(\"abort\", abort);\n if (signal.aborted && !controller.signal.aborted) {\n controller.abort(signal.reason);\n }\n }\n })();\n }\n return (async function* () {\n const iterator = toAsyncIterator(values);\n let remaining = n;\n let cancelledSource = false;\n try {\n while (!signal.aborted) {\n const result = await iterator.next();\n if (result.done) {\n return;\n }\n yield result.value;\n remaining -= 1;\n if (remaining === 0) {\n cancelledSource = true;\n controller.abort();\n return;\n }\n }\n } finally {\n signal.removeEventListener(\"abort\", abort);\n if (signal.aborted && !controller.signal.aborted) {\n controller.abort(signal.reason);\n }\n if (cancelledSource || signal.aborted) {\n await iterator.return?.();\n }\n }\n })();\n });\n};\n\nFlux.prototype.takeWhile = function takeWhile<T>(this: Flux<T>, predicate: (value: T) => boolean): Flux<T> {\n const source = this;\n return new Flux((signal, context) => takeWhileIterable(source.iterate(signal, context), predicate));\n};\n\nFlux.prototype.takeUntil = function takeUntil<T>(this: Flux<T>, predicate: (value: T) => boolean): Flux<T> {\n const source = this;\n return new Flux((signal, context) => takeUntilIterable(source.iterate(signal, context), predicate));\n};\n\nFlux.prototype.skip = function skip<T>(this: Flux<T>, n: number): Flux<T> {\n if (!Number.isInteger(n) || n < 0) {\n throw new RangeError(\"skip expects a non-negative integer\");\n }\n if (n === 0) {\n return this;\n }\n const source = this;\n return new Flux((signal, context) => skipIterable(source.iterate(signal, context), n));\n};\n\nFlux.prototype.skipWhile = function skipWhile<T>(this: Flux<T>, predicate: (value: T) => boolean): Flux<T> {\n const source = this;\n return new Flux((signal, context) => skipWhileIterable(source.iterate(signal, context), predicate));\n};\n\nFlux.prototype.distinct = function distinct<T, K = T>(\n this: Flux<T>,\n keySelector: (value: T) => K = identity as (value: T) => K\n): Flux<T> {\n const source = this;\n return new Flux((signal, context) => distinctIterable(source.iterate(signal, context), keySelector));\n};\n\nFlux.prototype.distinctUntilChanged = function distinctUntilChanged<T, K = T>(\n this: Flux<T>,\n keySelector: (value: T) => K = identity as (value: T) => K\n): Flux<T> {\n const source = this;\n return new Flux((signal, context) => distinctUntilChangedIterable(source.iterate(signal, context), keySelector));\n};\n\nFlux.prototype.defaultIfEmpty = function defaultIfEmpty<T>(this: Flux<T>, defaultValue: T): Flux<T> {\n const source = this;\n return new Flux((signal, context) => defaultIfEmptyIterable(source.iterate(signal, context), defaultValue));\n};\n\nFlux.prototype.switchIfEmpty = function switchIfEmpty<T>(this: Flux<T>, alternate: PublisherInput<T>): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n let empty = true;\n for await (const value of source.iterate(signal, context)) {\n empty = false;\n yield value;\n }\n if (empty) {\n for await (const value of Flux.from(alternate).iterate(signal, context)) {\n yield value;\n }\n }\n });\n};\n"],"mappings":";;;;;;;;;AAsDA,KAAK,UAAU,OAAO,SAAS,KAAuB,GAAoB;CACtE,IAAI,CAAC,OAAO,UAAU,CAAC,KAAK,IAAI,GAC5B,MAAM,IAAI,WAAW,qCAAqC;CAE9D,IAAI,MAAM,GACN,OAAO,KAAK,MAAS;CAEzB,MAAM,SAAS;CACf,OAAO,IAAI,MAAM,QAAQ,YAAY;EACjC,MAAM,aAAa,IAAI,gBAAgB;EACvC,MAAM,cAAc,WAAW,MAAM,OAAO,MAAM;EAClD,OAAO,iBAAiB,SAAS,OAAO,EAAC,MAAM,KAAI,CAAC;EACpD,IAAI;EACJ,IAAI;GACA,SAAS,OAAO,QAAQ,WAAW,QAAQ,OAAO;EACtD,SAAS,OAAO;GACZ,OAAO,oBAAoB,SAAS,KAAK;GACzC,MAAM;EACV;EACA,IAAI,CAAC,gBAAmB,MAAM,GAC1B,QAAQ,aAAa;GACjB,IAAI,YAAY;GAChB,IAAI;IACA,KAAK,MAAM,SAAS,QAAQ;KACxB,MAAM;KACN,aAAa;KACb,IAAI,cAAc,GAAG;MACjB,WAAW,MAAM;MACjB;KACJ;IACJ;GACJ,UAAU;IACN,OAAO,oBAAoB,SAAS,KAAK;IACzC,IAAI,OAAO,WAAW,CAAC,WAAW,OAAO,SACrC,WAAW,MAAM,OAAO,MAAM;GAEtC;EACJ,EAAA,CAAG;EAEP,QAAQ,mBAAmB;GACvB,MAAM,WAAW,gBAAgB,MAAM;GACvC,IAAI,YAAY;GAChB,IAAI,kBAAkB;GACtB,IAAI;IACA,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YAAY,iBAAiB,OAAO,QAAQ,QAAQ,OAAO,GAAG,WAAW,CAAC;AACvG;AAEA,KAAK,UAAU,uBAAuB,SAAS,qBAE3C,cAA+B,UACxB;CACP,MAAM,SAAS;CACf,OAAO,IAAI,MAAM,QAAQ,YAAY,6BAA6B,OAAO,QAAQ,QAAQ,OAAO,GAAG,WAAW,CAAC;AACnH;AAEA,KAAK,UAAU,iBAAiB,SAAS,eAAiC,cAA0B;CAChG,MAAM,SAAS;CACf,OAAO,IAAI,MAAM,QAAQ,YAAY,uBAAuB,OAAO,QAAQ,QAAQ,OAAO,GAAG,YAAY,CAAC;AAC9G;AAEA,KAAK,UAAU,gBAAgB,SAAS,cAAgC,WAAuC;CAC3G,MAAM,SAAS;CACf,OAAO,IAAI,KAAK,iBAAiB,QAAQ,SAAS;EAC9C,IAAI,QAAQ;EACZ,WAAW,MAAM,SAAS,OAAO,QAAQ,QAAQ,OAAO,GAAG;GACvD,QAAQ;GACR,MAAM;EACV;EACA,IAAI,OACA,WAAW,MAAM,SAAS,KAAK,KAAK,SAAS,CAAC,CAAC,QAAQ,QAAQ,OAAO,GAClE,MAAM;CAGlB,CAAC;AACL"}
|
|
1
|
+
{"version":3,"file":"selection.js","names":[],"sources":["../../../src/publisher/operators/selection.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Flux, Mono and operator implementation modules.\n */\nimport {deepEqual, snapshotDeep} from \"@/internal/deep-value.js\";\nimport {\n type AnyIterable,\n isAsyncIterable,\n toAsyncIterator\n} from \"@/internal/iterable.js\";\nimport {\n defaultIfEmptyIterable,\n distinctIterable,\n distinctUntilChangedIterable,\n skipIterable,\n skipWhileIterable,\n takeUntilIterable,\n takeWhileIterable\n} from \"@/internal/iterable-transform.js\";\nimport {Flux} from \"@/publisher/flux.js\";\nimport {identity} from \"@/publisher/helpers.js\";\nimport {liftTake} from \"@/publisher/operators/lift.js\";\nimport type {PublisherInput} from \"@/publisher/types.js\";\n\ndeclare module \"@/publisher/flux.js\" {\n /** Selection and filtering operators added to Flux. */\n interface Flux<T> {\n /** Emits at most the first `n` source values. */\n take(n: number): Flux<T>;\n\n /** Emits values while the predicate returns true, then cancels upstream. */\n takeWhile(predicate: (value: T) => boolean): Flux<T>;\n\n /** Emits values until the predicate returns true, including the matching value. */\n takeUntil(predicate: (value: T) => boolean): Flux<T>;\n\n /** Drops the first `n` source values. */\n skip(n: number): Flux<T>;\n\n /** Drops values while the predicate returns true, then relays the rest. */\n skipWhile(predicate: (value: T) => boolean): Flux<T>;\n\n /** Emits only the first value for each selected key. */\n distinct<K = T>(keySelector?: (value: T) => K): Flux<T>;\n\n /** Drops adjacent values whose selected key is equal to the previous key. */\n distinctUntilChanged<K = T>(keySelector?: (value: T) => K): Flux<T>;\n\n /**\n * Drops adjacent values with equal nested state. Snapshots arrays, enumerable properties of ordinary objects,\n * and local `Date`, `RegExp`, `Map` and `Set` values; other object types retain identity comparison.\n */\n distinctUntilChangedDeep<K = T>(keySelector?: (value: T) => K): Flux<T>;\n\n /** Emits `defaultValue` when the source completes without values. */\n defaultIfEmpty(defaultValue: T): Flux<T>;\n\n /** Switches to `alternate` when the source completes without values. */\n switchIfEmpty(alternate: PublisherInput<T>): Flux<T>;\n }\n}\n\nFlux.prototype.take = function take<T>(this: Flux<T>, n: number): Flux<T> {\n if (!Number.isInteger(n) || n < 0) {\n throw new RangeError(\"take expects a non-negative integer\");\n }\n if (n === 0) {\n return Flux.empty<T>();\n }\n const source = this;\n return liftTake(source, (signal, context) => {\n const controller = new AbortController();\n const abort = () => controller.abort(signal.reason);\n signal.addEventListener(\"abort\", abort, {once: true});\n let values: AnyIterable<T>;\n try {\n values = source.iterate(controller.signal, context);\n } catch (error) {\n signal.removeEventListener(\"abort\", abort);\n throw error;\n }\n if (!isAsyncIterable<T>(values)) {\n return (function* () {\n let remaining = n;\n try {\n for (const value of values) {\n yield value;\n remaining -= 1;\n if (remaining === 0) {\n controller.abort();\n return;\n }\n }\n } finally {\n signal.removeEventListener(\"abort\", abort);\n if (signal.aborted && !controller.signal.aborted) {\n controller.abort(signal.reason);\n }\n }\n })();\n }\n return (async function* () {\n const iterator = toAsyncIterator(values);\n let remaining = n;\n let cancelledSource = false;\n try {\n while (!signal.aborted) {\n const result = await iterator.next();\n if (result.done) {\n return;\n }\n yield result.value;\n remaining -= 1;\n if (remaining === 0) {\n cancelledSource = true;\n controller.abort();\n return;\n }\n }\n } finally {\n signal.removeEventListener(\"abort\", abort);\n if (signal.aborted && !controller.signal.aborted) {\n controller.abort(signal.reason);\n }\n if (cancelledSource || signal.aborted) {\n await iterator.return?.();\n }\n }\n })();\n }, n);\n};\n\nFlux.prototype.takeWhile = function takeWhile<T>(this: Flux<T>, predicate: (value: T) => boolean): Flux<T> {\n const source = this;\n return new Flux((signal, context) => takeWhileIterable(source.iterate(signal, context), predicate));\n};\n\nFlux.prototype.takeUntil = function takeUntil<T>(this: Flux<T>, predicate: (value: T) => boolean): Flux<T> {\n const source = this;\n return new Flux((signal, context) => takeUntilIterable(source.iterate(signal, context), predicate));\n};\n\nFlux.prototype.skip = function skip<T>(this: Flux<T>, n: number): Flux<T> {\n if (!Number.isInteger(n) || n < 0) {\n throw new RangeError(\"skip expects a non-negative integer\");\n }\n if (n === 0) {\n return this;\n }\n const source = this;\n return new Flux((signal, context) => skipIterable(source.iterate(signal, context), n));\n};\n\nFlux.prototype.skipWhile = function skipWhile<T>(this: Flux<T>, predicate: (value: T) => boolean): Flux<T> {\n const source = this;\n return new Flux((signal, context) => skipWhileIterable(source.iterate(signal, context), predicate));\n};\n\nFlux.prototype.distinct = function distinct<T, K = T>(\n this: Flux<T>,\n keySelector: (value: T) => K = identity as (value: T) => K\n): Flux<T> {\n const source = this;\n return new Flux((signal, context) => distinctIterable(source.iterate(signal, context), keySelector));\n};\n\nFlux.prototype.distinctUntilChanged = function distinctUntilChanged<T, K = T>(\n this: Flux<T>,\n keySelector: (value: T) => K = identity as (value: T) => K\n): Flux<T> {\n const source = this;\n return new Flux((signal, context) => distinctUntilChangedIterable(source.iterate(signal, context), keySelector));\n};\n\nFlux.prototype.distinctUntilChangedDeep = function distinctUntilChangedDeep<T, K = T>(\n this: Flux<T>,\n keySelector: (value: T) => K = identity as (value: T) => K\n): Flux<T> {\n const source = this;\n return new Flux((signal, context) => distinctUntilChangedIterable(source.iterate(signal, context), keySelector, {\n equals: deepEqual,\n snapshot: snapshotDeep\n }));\n};\n\nFlux.prototype.defaultIfEmpty = function defaultIfEmpty<T>(this: Flux<T>, defaultValue: T): Flux<T> {\n const source = this;\n return new Flux((signal, context) => defaultIfEmptyIterable(source.iterate(signal, context), defaultValue));\n};\n\nFlux.prototype.switchIfEmpty = function switchIfEmpty<T>(this: Flux<T>, alternate: PublisherInput<T>): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n let empty = true;\n for await (const value of source.iterate(signal, context)) {\n empty = false;\n yield value;\n }\n if (empty) {\n for await (const value of Flux.from(alternate).iterate(signal, context)) {\n yield value;\n }\n }\n });\n};\n"],"mappings":";;;;;;;;;;;AA8DA,KAAK,UAAU,OAAO,SAAS,KAAuB,GAAoB;CACtE,IAAI,CAAC,OAAO,UAAU,CAAC,KAAK,IAAI,GAC5B,MAAM,IAAI,WAAW,qCAAqC;CAE9D,IAAI,MAAM,GACN,OAAO,KAAK,MAAS;CAEzB,MAAM,SAAS;CACf,OAAO,SAAS,SAAS,QAAQ,YAAY;EACzC,MAAM,aAAa,IAAI,gBAAgB;EACvC,MAAM,cAAc,WAAW,MAAM,OAAO,MAAM;EAClD,OAAO,iBAAiB,SAAS,OAAO,EAAC,MAAM,KAAI,CAAC;EACpD,IAAI;EACJ,IAAI;GACA,SAAS,OAAO,QAAQ,WAAW,QAAQ,OAAO;EACtD,SAAS,OAAO;GACZ,OAAO,oBAAoB,SAAS,KAAK;GACzC,MAAM;EACV;EACA,IAAI,CAAC,gBAAmB,MAAM,GAC1B,QAAQ,aAAa;GACjB,IAAI,YAAY;GAChB,IAAI;IACA,KAAK,MAAM,SAAS,QAAQ;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GAClE,MAAM;CAGlB,CAAC;AACL"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type TerminalCollector } from "../../internal/publisher-terminal.js";
|
|
2
|
+
import { Flux } from "../flux.js";
|
|
3
|
+
import { Mono } from "../mono.js";
|
|
4
|
+
/** Sentinel returned by a terminal collector when its Mono must complete empty. */
|
|
5
|
+
export declare const NO_TERMINAL_VALUE: unique symbol;
|
|
6
|
+
/** Result produced by a terminal collector, including empty Mono completion. */
|
|
7
|
+
export type TerminalValue<T> = T | typeof NO_TERMINAL_VALUE;
|
|
8
|
+
/** Creates fresh terminal reduction state for each subscription. */
|
|
9
|
+
export type TerminalCollectorFactory<T, R> = () => TerminalCollector<T, TerminalValue<R>>;
|
|
10
|
+
/** Creates a Mono that reduces Publisher signals on the native demand path. */
|
|
11
|
+
export declare function terminalMono<T, R>(source: Flux<T>, upstreamRequest: number, collectorFactory: TerminalCollectorFactory<T, R>): Mono<R>;
|
|
12
|
+
//# sourceMappingURL=terminal-mono.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal-mono.d.ts","sourceRoot":"","sources":["../../../src/publisher/operators/terminal-mono.ts"],"names":[],"mappings":"AAOA,OAAO,EAAmB,KAAK,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AAC1F,OAAO,EAAC,IAAI,EAAC,MAAM,qBAAqB,CAAC;AACzC,OAAO,EAAC,IAAI,EAAC,MAAM,qBAAqB,CAAC;AAKzC,mFAAmF;AACnF,eAAO,MAAM,iBAAiB,eAA8B,CAAC;AAE7D,gFAAgF;AAChF,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,iBAAiB,CAAC;AAE5D,oEAAoE;AACpE,MAAM,MAAM,wBAAwB,CAAC,CAAC,EAAE,CAAC,IAAI,MAAM,iBAAiB,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;AAE1F,+EAA+E;AAC/E,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAC7B,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,EACf,eAAe,EAAE,MAAM,EACvB,gBAAgB,EAAE,wBAAwB,CAAC,CAAC,EAAE,CAAC,CAAC,GACjD,IAAI,CAAC,CAAC,CAAC,CAET"}
|