reactor-core-ts 3.2.1 → 3.2.3

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.
Files changed (34) hide show
  1. package/LICENSE.md +56 -0
  2. package/README.md +5 -0
  3. package/dist/core/demand.js +2 -2
  4. package/dist/core/demand.js.map +1 -1
  5. package/dist/internal/deep-value.d.ts +9 -0
  6. package/dist/internal/deep-value.d.ts.map +1 -0
  7. package/dist/internal/deep-value.js +159 -0
  8. package/dist/internal/deep-value.js.map +1 -0
  9. package/dist/internal/iterable-transform.d.ts +8 -1
  10. package/dist/internal/iterable-transform.d.ts.map +1 -1
  11. package/dist/internal/iterable-transform.js +7 -5
  12. package/dist/internal/iterable-transform.js.map +1 -1
  13. package/dist/publisher/flux.d.ts.map +1 -1
  14. package/dist/publisher/flux.js +92 -22
  15. package/dist/publisher/flux.js.map +1 -1
  16. package/dist/publisher/operators/lifecycle.d.ts.map +1 -1
  17. package/dist/publisher/operators/lifecycle.js +29 -3
  18. package/dist/publisher/operators/lifecycle.js.map +1 -1
  19. package/dist/publisher/operators/lift.d.ts +42 -0
  20. package/dist/publisher/operators/lift.d.ts.map +1 -0
  21. package/dist/publisher/operators/lift.js +343 -0
  22. package/dist/publisher/operators/lift.js.map +1 -0
  23. package/dist/publisher/operators/selection.d.ts +5 -0
  24. package/dist/publisher/operators/selection.d.ts.map +1 -1
  25. package/dist/publisher/operators/selection.js +8 -0
  26. package/dist/publisher/operators/selection.js.map +1 -1
  27. package/dist/publisher/operators/side-effect.d.ts.map +1 -1
  28. package/dist/publisher/operators/side-effect.js +34 -9
  29. package/dist/publisher/operators/side-effect.js.map +1 -1
  30. package/dist/publisher/operators/transform.d.ts.map +1 -1
  31. package/dist/publisher/operators/transform.js +3 -2
  32. package/dist/publisher/operators/transform.js.map +1 -1
  33. package/dist/subscription/iterable-subscription.js +1 -1
  34. package/package.json +2 -1
@@ -0,0 +1,343 @@
1
+ import _defineProperty from "../../_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/defineProperty.js";
2
+ import { Context } from "../../context/context.js";
3
+ import { addCap } from "../../core/demand.js";
4
+ import { Flux } from "../flux.js";
5
+ //#region src/publisher/operators/lift.ts
6
+ /**
7
+ * @packageDocumentation
8
+ * Internal subscriber-lifting primitives for demand-preserving Flux operators.
9
+ */
10
+ /**
11
+ * Lifts a Flux at the Reactive Streams subscriber boundary while keeping an
12
+ * iterable implementation for explicit async-iterator consumption.
13
+ */
14
+ function liftFlux(source, sourceFactory, lifter) {
15
+ return new LiftedFlux(source, sourceFactory, lifter);
16
+ }
17
+ /** Creates a one-to-one operator that forwards downstream demand unchanged. */
18
+ function liftOneToOne(source, sourceFactory, hooksFactory) {
19
+ return liftFlux(source, sourceFactory, (subscriber) => new OneToOneOperatorSubscriber(subscriber, hooksFactory(subscriber)));
20
+ }
21
+ /** Creates a filtering operator that replenishes only values dropped from finite demand. */
22
+ function liftFilter(source, sourceFactory, predicate) {
23
+ return liftFlux(source, sourceFactory, (subscriber) => new FilterOperatorSubscriber(subscriber, predicate));
24
+ }
25
+ /** Returns the context exposed by a subscriber, or the shared empty context. */
26
+ function subscriberContext(subscriber) {
27
+ return subscriber.currentContext?.() ?? Context.empty();
28
+ }
29
+ /** Flux whose normal subscribe path is assembled through a subscriber lifter. */
30
+ var LiftedFlux = class extends Flux {
31
+ /** Creates a lifted Flux around an upstream source. */
32
+ constructor(source, sourceFactory, lifter) {
33
+ super(sourceFactory);
34
+ _defineProperty(this, "source", void 0);
35
+ _defineProperty(this, "lifter", void 0);
36
+ this.source = source;
37
+ this.lifter = lifter;
38
+ }
39
+ /** Subscribes without crossing the async-iterator bridge. */
40
+ subscribeActual(subscriber) {
41
+ let upstreamSubscriber;
42
+ try {
43
+ upstreamSubscriber = this.lifter(subscriber);
44
+ } catch (error) {
45
+ signalAssemblyError(subscriber, error);
46
+ return;
47
+ }
48
+ this.source.subscribe(upstreamSubscriber);
49
+ }
50
+ };
51
+ /** Subscription/subscriber pair shared by synchronous one-to-one operators. */
52
+ var OneToOneOperatorSubscriber = class {
53
+ /** Creates a one-to-one operator subscriber. */
54
+ constructor(actual, hooks) {
55
+ _defineProperty(this, "actual", void 0);
56
+ _defineProperty(this, "hooks", void 0);
57
+ _defineProperty(
58
+ this,
59
+ /** Upstream subscription received during the Reactive Streams handshake. */
60
+ "upstream",
61
+ void 0
62
+ );
63
+ _defineProperty(
64
+ this,
65
+ /** Prevents duplicate subscriptions from replacing the active upstream. */
66
+ "subscribed",
67
+ false
68
+ );
69
+ _defineProperty(
70
+ this,
71
+ /** Suppresses signals and demand after cancellation or termination. */
72
+ "terminated",
73
+ false
74
+ );
75
+ this.actual = actual;
76
+ this.hooks = hooks;
77
+ }
78
+ /** Installs the upstream subscription and exposes this forwarding subscription downstream. */
79
+ onSubscribe(subscription) {
80
+ if (this.subscribed || this.terminated) {
81
+ subscription.cancel();
82
+ return;
83
+ }
84
+ this.subscribed = true;
85
+ this.upstream = subscription;
86
+ try {
87
+ this.hooks.onSubscribe?.(subscription);
88
+ } catch (error) {
89
+ this.terminated = true;
90
+ cancelSilently(subscription);
91
+ this.actual.onSubscribe(this);
92
+ this.signalError(error);
93
+ return;
94
+ }
95
+ try {
96
+ this.actual.onSubscribe(this);
97
+ } catch (error) {
98
+ this.terminated = true;
99
+ try {
100
+ subscription.cancel();
101
+ } finally {
102
+ this.runFinally("cancel");
103
+ }
104
+ throw error;
105
+ }
106
+ }
107
+ /** Converts and forwards one upstream value without changing demand. */
108
+ onNext(value) {
109
+ if (this.terminated) return;
110
+ let mapped;
111
+ try {
112
+ mapped = this.hooks.onNext(value);
113
+ } catch (error) {
114
+ this.terminateWithError(error, true);
115
+ return;
116
+ }
117
+ this.actual.onNext(mapped);
118
+ }
119
+ /** Forwards an upstream error after running the operator callback. */
120
+ onError(error) {
121
+ this.terminateWithError(error, false);
122
+ }
123
+ /** Forwards successful completion after running the operator callback. */
124
+ onComplete() {
125
+ if (this.terminated) return;
126
+ try {
127
+ this.hooks.onComplete?.();
128
+ } catch (error) {
129
+ this.terminateWithError(error, false);
130
+ return;
131
+ }
132
+ this.terminated = true;
133
+ try {
134
+ this.actual.onComplete();
135
+ } finally {
136
+ this.runFinally("complete");
137
+ }
138
+ }
139
+ /** Forwards exactly the requested amount to upstream. */
140
+ request(n) {
141
+ if (this.terminated) return;
142
+ try {
143
+ this.hooks.onRequest?.(n);
144
+ } catch (error) {
145
+ this.terminateWithError(error, true);
146
+ return;
147
+ }
148
+ this.upstream?.request(n);
149
+ }
150
+ /** Cancels upstream once and reports the cancellation lifecycle hooks. */
151
+ cancel() {
152
+ if (this.terminated) return;
153
+ this.terminated = true;
154
+ try {
155
+ this.upstream?.cancel();
156
+ } finally {
157
+ try {
158
+ this.hooks.onCancel?.();
159
+ } finally {
160
+ this.runFinally("cancel");
161
+ }
162
+ }
163
+ }
164
+ /** Exposes downstream context to context-aware upstream publishers. */
165
+ currentContext() {
166
+ return this.hooks.currentContext?.() ?? subscriberContext(this.actual);
167
+ }
168
+ /** Cancels when needed and emits one downstream error signal. */
169
+ terminateWithError(error, cancelUpstream) {
170
+ if (this.terminated) return;
171
+ this.terminated = true;
172
+ if (cancelUpstream && this.upstream) cancelSilently(this.upstream);
173
+ let failure = error;
174
+ try {
175
+ this.hooks.onError?.(error);
176
+ } catch (callbackError) {
177
+ failure = callbackError;
178
+ }
179
+ this.signalError(failure);
180
+ }
181
+ /** Delivers an error followed by the final error callback. */
182
+ signalError(error) {
183
+ try {
184
+ this.actual.onError(error);
185
+ } finally {
186
+ this.runFinally("error");
187
+ }
188
+ }
189
+ /** Runs a final callback without letting observer code alter terminal semantics. */
190
+ runFinally(signal) {
191
+ try {
192
+ this.hooks.onFinally?.(signal);
193
+ } catch {}
194
+ }
195
+ };
196
+ /** Filtering subscriber with stack-safe compensation for dropped values. */
197
+ var FilterOperatorSubscriber = class {
198
+ /** Creates a filtering subscriber. */
199
+ constructor(actual, predicate) {
200
+ _defineProperty(this, "actual", void 0);
201
+ _defineProperty(this, "predicate", void 0);
202
+ _defineProperty(
203
+ this,
204
+ /** Upstream subscription received during the Reactive Streams handshake. */
205
+ "upstream",
206
+ void 0
207
+ );
208
+ _defineProperty(
209
+ this,
210
+ /** Prevents duplicate subscriptions from replacing the active upstream. */
211
+ "subscribed",
212
+ false
213
+ );
214
+ _defineProperty(
215
+ this,
216
+ /** Suppresses signals and demand after cancellation or termination. */
217
+ "terminated",
218
+ false
219
+ );
220
+ _defineProperty(
221
+ this,
222
+ /** Avoids compensation requests after downstream switches to unbounded demand. */
223
+ "unbounded",
224
+ false
225
+ );
226
+ _defineProperty(
227
+ this,
228
+ /** Guards synchronous request calls against reentrant compensation. */
229
+ "requesting",
230
+ false
231
+ );
232
+ _defineProperty(
233
+ this,
234
+ /** Compensation or downstream demand accumulated during an active request call. */
235
+ "missedRequested",
236
+ 0
237
+ );
238
+ this.actual = actual;
239
+ this.predicate = predicate;
240
+ }
241
+ /** Installs upstream and exposes the demand-forwarding subscription downstream. */
242
+ onSubscribe(subscription) {
243
+ if (this.subscribed || this.terminated) {
244
+ subscription.cancel();
245
+ return;
246
+ }
247
+ this.subscribed = true;
248
+ this.upstream = subscription;
249
+ try {
250
+ this.actual.onSubscribe(this);
251
+ } catch (error) {
252
+ this.terminated = true;
253
+ subscription.cancel();
254
+ throw error;
255
+ }
256
+ }
257
+ /** Tests one value, forwarding matches and replenishing finite demand for drops. */
258
+ onNext(value) {
259
+ if (this.terminated) return;
260
+ let accepted;
261
+ try {
262
+ accepted = this.predicate(value);
263
+ } catch (error) {
264
+ this.terminated = true;
265
+ if (this.upstream) cancelSilently(this.upstream);
266
+ this.actual.onError(error);
267
+ return;
268
+ }
269
+ if (accepted) this.actual.onNext(value);
270
+ else if (!this.unbounded) this.requestUpstream(1);
271
+ }
272
+ /** Forwards one terminal error. */
273
+ onError(error) {
274
+ if (this.terminated) return;
275
+ this.terminated = true;
276
+ this.actual.onError(error);
277
+ }
278
+ /** Forwards successful completion once. */
279
+ onComplete() {
280
+ if (this.terminated) return;
281
+ this.terminated = true;
282
+ this.actual.onComplete();
283
+ }
284
+ /** Forwards demand and records when no further compensation is necessary. */
285
+ request(n) {
286
+ if (this.terminated) return;
287
+ if (n === Number.POSITIVE_INFINITY) this.unbounded = true;
288
+ this.requestUpstream(n);
289
+ }
290
+ /** Cancels the upstream once. */
291
+ cancel() {
292
+ if (this.terminated) return;
293
+ this.terminated = true;
294
+ this.upstream?.cancel();
295
+ }
296
+ /** Exposes the downstream context unchanged. */
297
+ currentContext() {
298
+ return subscriberContext(this.actual);
299
+ }
300
+ /** Drains demand iteratively so synchronous sources cannot recurse through dropped values. */
301
+ requestUpstream(n) {
302
+ if (this.requesting) {
303
+ this.missedRequested = addCap(this.missedRequested, n);
304
+ return;
305
+ }
306
+ const upstream = this.upstream;
307
+ if (!upstream) return;
308
+ this.requesting = true;
309
+ let request = n;
310
+ try {
311
+ while (!this.terminated) {
312
+ upstream.request(request);
313
+ if (this.terminated || this.missedRequested === 0) return;
314
+ request = this.missedRequested;
315
+ this.missedRequested = 0;
316
+ }
317
+ } finally {
318
+ this.requesting = false;
319
+ }
320
+ }
321
+ };
322
+ /** Signals a lifter assembly failure through a valid Reactive Streams handshake. */
323
+ function signalAssemblyError(subscriber, error) {
324
+ subscriber.onSubscribe(EMPTY_SUBSCRIPTION);
325
+ subscriber.onError(error);
326
+ }
327
+ /** Cancels an upstream while preserving the original operator failure. */
328
+ function cancelSilently(subscription) {
329
+ try {
330
+ subscription.cancel();
331
+ } catch {}
332
+ }
333
+ /** Shared inert subscription used only when operator assembly fails. */
334
+ var EMPTY_SUBSCRIPTION = Object.freeze({
335
+ /** Ignores requests because the sequence has already failed. */
336
+ request() {},
337
+ /** Ignores cancellation because no upstream was subscribed. */
338
+ cancel() {}
339
+ });
340
+ //#endregion
341
+ export { liftFilter, liftFlux, liftOneToOne, subscriberContext };
342
+
343
+ //# sourceMappingURL=lift.js.map
@@ -0,0 +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,eAC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AW;CAC3B;;CAGA,QAAe,GAAiB;EAC5B,IAAI,KAAK,YACL;EAEJ,IAAI,MAAM,OAAO,mBACb,KAAK,YAAY;EAErB,KAAK,gBAAgB,CAAC;CAC1B;;CAGA,SAAsB;EAClB,IAAI,KAAK,YACL;EAEJ,KAAK,aAAa;EAClB,KAAK,UAAU,OAAO;CAC1B;;CAGA,iBAAiC;EAC7B,OAAO,kBAAkB,KAAK,MAAM;CACxC;;CAGA,gBAAwB,GAAiB;EACrC,IAAI,KAAK,YAAY;GACjB,KAAK,kBAAkB,OAAO,KAAK,iBAAiB,CAAC;GACrD;EACJ;EACA,MAAM,WAAW,KAAK;EACtB,IAAI,CAAC,UACD;EAEJ,KAAK,aAAa;EAClB,IAAI,UAAU;EACd,IAAI;GACA,OAAO,CAAC,KAAK,YAAY;IACrB,SAAS,QAAQ,OAAO;IACxB,IAAI,KAAK,cAAc,KAAK,oBAAoB,GAC5C;IAEJ,UAAU,KAAK;IACf,KAAK,kBAAkB;GAC3B;EACJ,UAAU;GACN,KAAK,aAAa;EACtB;CACJ;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":"AAoBA,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,qEAAqE;QACrE,cAAc,CAAC,YAAY,E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AAwB,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,7 @@ 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 { deepEqual, snapshotDeep } from "../../internal/deep-value.js";
5
6
  //#region src/publisher/operators/selection.ts
6
7
  /**
7
8
  * @packageDocumentation
@@ -88,6 +89,13 @@ Flux.prototype.distinctUntilChanged = function distinctUntilChanged(keySelector
88
89
  const source = this;
89
90
  return new Flux((signal, context) => distinctUntilChangedIterable(source.iterate(signal, context), keySelector));
90
91
  };
92
+ Flux.prototype.distinctUntilChangedDeep = function distinctUntilChangedDeep(keySelector = identity) {
93
+ const source = this;
94
+ return new Flux((signal, context) => distinctUntilChangedIterable(source.iterate(signal, context), keySelector, {
95
+ equals: deepEqual,
96
+ snapshot: snapshotDeep
97
+ }));
98
+ };
91
99
  Flux.prototype.defaultIfEmpty = function defaultIfEmpty(defaultValue) {
92
100
  const source = this;
93
101
  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;GAC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AAK,UAAU,YAAY,SAAS,UAA4B,WAA2C;CACvG,MAAM,SAAS;CACf,OAAO,IAAI,MAAM,QAAQ,YAAY,kBAAkB,OAAO,QAAQ,QAAQ,OAAO,GAAG,SAAS,CAAC;AACtG;AAEA,KAAK,UAAU,WAAW,SAAS,SAE/B,cAA+B,UACxB;CACP,MAAM,SAAS;CACf,OAAO,IAAI,MAAM,QAAQ,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 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 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.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":";;;;;;;;;;AA6DA,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,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S;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 +1 @@
1
- {"version":3,"file":"side-effect.d.ts","sourceRoot":"","sources":["../../../src/publisher/operators/side-effect.ts"],"names":[],"mappings":"AAMA,OAAO,QAAQ,qBAAqB,CAAC;IACjC,oDAAoD;IACpD,UAAU,IAAI,CAAC,CAAC;QACZ,uEAAuE;QACvE,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEhD,6EAA6E;QAC7E,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEvD,kEAAkE;QAClE,YAAY,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAE5C,wEAAwE;QACxE,SAAS,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,GAAG,QAAQ,KAAK,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;KACnF;CACJ"}
1
+ {"version":3,"file":"side-effect.d.ts","sourceRoot":"","sources":["../../../src/publisher/operators/side-effect.ts"],"names":[],"mappings":"AAOA,OAAO,QAAQ,qBAAqB,CAAC;IACjC,oDAAoD;IACpD,UAAU,IAAI,CAAC,CAAC;QACZ,uEAAuE;QACvE,QAAQ,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEhD,6EAA6E;QAC7E,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEvD,kEAAkE;QAClE,YAAY,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAE5C,wEAAwE;QACxE,SAAS,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,GAAG,QAAQ,KAAK,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;KACnF;CACJ"}
@@ -1,4 +1,5 @@
1
1
  import { Flux } from "../flux.js";
2
+ import { liftOneToOne } from "./lift.js";
2
3
  //#region src/publisher/operators/side-effect.ts
3
4
  /**
4
5
  * @packageDocumentation
@@ -6,34 +7,45 @@ import { Flux } from "../flux.js";
6
7
  */
7
8
  Flux.prototype.doOnNext = function doOnNext(callback) {
8
9
  const source = this;
9
- return new Flux(async function* (signal, context) {
10
+ return liftOneToOne(source, async function* (signal, context) {
10
11
  for await (const value of source.iterate(signal, context)) {
11
12
  callback(value);
12
13
  yield value;
13
14
  }
14
- });
15
+ }, () => ({
16
+ /** Runs the side effect and retains the original value. */
17
+ onNext(value) {
18
+ callback(value);
19
+ return value;
20
+ } }));
15
21
  };
16
22
  Flux.prototype.doOnError = function doOnError(callback) {
17
23
  const source = this;
18
- return new Flux(async function* (signal, context) {
24
+ return liftOneToOne(source, async function* (signal, context) {
19
25
  try {
20
26
  for await (const value of source.iterate(signal, context)) yield value;
21
27
  } catch (error) {
22
28
  callback(error);
23
29
  throw error;
24
30
  }
25
- });
31
+ }, () => ({
32
+ onNext: passThrough,
33
+ onError: callback
34
+ }));
26
35
  };
27
36
  Flux.prototype.doOnComplete = function doOnComplete(callback) {
28
37
  const source = this;
29
- return new Flux(async function* (signal, context) {
38
+ return liftOneToOne(source, async function* (signal, context) {
30
39
  for await (const value of source.iterate(signal, context)) yield value;
31
40
  callback();
32
- });
41
+ }, () => ({
42
+ onNext: passThrough,
43
+ onComplete: callback
44
+ }));
33
45
  };
34
46
  Flux.prototype.doFinally = function doFinally(callback) {
35
47
  const source = this;
36
- return new Flux(async function* (signal, context) {
48
+ return liftOneToOne(source, async function* (signal, context) {
37
49
  let terminal = "complete";
38
50
  try {
39
51
  for await (const value of source.iterate(signal, context)) {
@@ -47,10 +59,23 @@ Flux.prototype.doFinally = function doFinally(callback) {
47
59
  terminal = signal.aborted ? "cancel" : "error";
48
60
  throw error;
49
61
  } finally {
50
- callback(signal.aborted ? "cancel" : terminal);
62
+ runFinallyCallback(callback, signal.aborted ? "cancel" : terminal);
51
63
  }
52
- });
64
+ }, () => ({
65
+ onNext: passThrough,
66
+ onFinally: callback
67
+ }));
53
68
  };
69
+ /** Returns an operator value unchanged. */
70
+ function passThrough(value) {
71
+ return value;
72
+ }
73
+ /** Runs a final observer without allowing it to replace sequence termination. */
74
+ function runFinallyCallback(callback, signal) {
75
+ try {
76
+ callback(signal);
77
+ } catch {}
78
+ }
54
79
  //#endregion
55
80
 
56
81
  //# sourceMappingURL=side-effect.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"side-effect.js","names":[],"sources":["../../../src/publisher/operators/side-effect.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Flux, Mono and operator implementation modules.\n */\nimport {Flux} from \"@/publisher/flux.js\";\n\ndeclare module \"@/publisher/flux.js\" {\n /** Side-effect callback operators added to Flux. */\n interface Flux<T> {\n /** Invokes a callback for each value without changing the sequence. */\n doOnNext(callback: (value: T) => void): Flux<T>;\n\n /** Invokes a callback when the source fails without recovering the error. */\n doOnError(callback: (error: unknown) => void): Flux<T>;\n\n /** Invokes a callback after the source completes successfully. */\n doOnComplete(callback: () => void): Flux<T>;\n\n /** Invokes a callback once after completion, error, or cancellation. */\n doFinally(callback: (signal: \"complete\" | \"error\" | \"cancel\") => void): Flux<T>;\n }\n}\n\nFlux.prototype.doOnNext = function doOnNext<T>(this: Flux<T>, callback: (value: T) => void): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n for await (const value of source.iterate(signal, context)) {\n callback(value);\n yield value;\n }\n });\n};\n\nFlux.prototype.doOnError = function doOnError<T>(this: Flux<T>, callback: (error: unknown) => void): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n try {\n for await (const value of source.iterate(signal, context)) {\n yield value;\n }\n } catch (error) {\n callback(error);\n throw error;\n }\n });\n};\n\nFlux.prototype.doOnComplete = function doOnComplete<T>(this: Flux<T>, callback: () => void): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n for await (const value of source.iterate(signal, context)) {\n yield value;\n }\n callback();\n });\n};\n\nFlux.prototype.doFinally = function doFinally<T>(\n this: Flux<T>,\n callback: (signal: \"complete\" | \"error\" | \"cancel\") => void\n): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n let terminal: \"complete\" | \"error\" | \"cancel\" = \"complete\";\n try {\n for await (const value of source.iterate(signal, context)) {\n if (signal.aborted) {\n terminal = \"cancel\";\n return;\n }\n yield value;\n }\n } catch (error) {\n terminal = signal.aborted ? \"cancel\" : \"error\";\n throw error;\n } finally {\n callback(signal.aborted ? \"cancel\" : terminal);\n }\n });\n};\n"],"mappings":";;;;;;AAuBA,KAAK,UAAU,WAAW,SAAS,SAA2B,UAAuC;CACjG,MAAM,SAAS;CACf,OAAO,IAAI,KAAK,iBAAiB,QAAQ,SAAS;EAC9C,WAAW,MAAM,SAAS,OAAO,QAAQ,QAAQ,OAAO,GAAG;GACvD,SAAS,KAAK;GACd,MAAM;EACV;CACJ,CAAC;AACL;AAEA,KAAK,UAAU,YAAY,SAAS,UAA4B,UAA6C;CACzG,MAAM,SAAS;CACf,OAAO,IAAI,KAAK,iBAAiB,QAAQ,SAAS;EAC9C,IAAI;GACA,WAAW,MAAM,SAAS,OAAO,QAAQ,QAAQ,OAAO,GACpD,MAAM;EAEd,SAAS,OAAO;GACZ,SAAS,KAAK;GACd,MAAM;EACV;CACJ,CAAC;AACL;AAEA,KAAK,UAAU,eAAe,SAAS,aAA+B,UAA+B;CACjG,MAAM,SAAS;CACf,OAAO,IAAI,KAAK,iBAAiB,QAAQ,SAAS;EAC9C,WAAW,MAAM,SAAS,OAAO,QAAQ,QAAQ,OAAO,GACpD,MAAM;EAEV,SAAS;CACb,CAAC;AACL;AAEA,KAAK,UAAU,YAAY,SAAS,UAEhC,UACO;CACP,MAAM,SAAS;CACf,OAAO,IAAI,KAAK,iBAAiB,QAAQ,SAAS;EAC9C,IAAI,WAA4C;EAChD,IAAI;GACA,WAAW,MAAM,SAAS,OAAO,QAAQ,QAAQ,OAAO,GAAG;IACvD,IAAI,OAAO,SAAS;KAChB,WAAW;KACX;IACJ;IACA,MAAM;GACV;EACJ,SAAS,OAAO;GACZ,WAAW,OAAO,UAAU,WAAW;GACvC,MAAM;EACV,UAAU;GACN,SAAS,OAAO,UAAU,WAAW,QAAQ;EACjD;CACJ,CAAC;AACL"}
1
+ {"version":3,"file":"side-effect.js","names":[],"sources":["../../../src/publisher/operators/side-effect.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Flux, Mono and operator implementation modules.\n */\nimport {Flux} from \"@/publisher/flux.js\";\nimport {liftOneToOne} from \"@/publisher/operators/lift.js\";\n\ndeclare module \"@/publisher/flux.js\" {\n /** Side-effect callback operators added to Flux. */\n interface Flux<T> {\n /** Invokes a callback for each value without changing the sequence. */\n doOnNext(callback: (value: T) => void): Flux<T>;\n\n /** Invokes a callback when the source fails without recovering the error. */\n doOnError(callback: (error: unknown) => void): Flux<T>;\n\n /** Invokes a callback after the source completes successfully. */\n doOnComplete(callback: () => void): Flux<T>;\n\n /** Invokes a callback once after completion, error, or cancellation. */\n doFinally(callback: (signal: \"complete\" | \"error\" | \"cancel\") => void): Flux<T>;\n }\n}\n\nFlux.prototype.doOnNext = function doOnNext<T>(this: Flux<T>, callback: (value: T) => void): Flux<T> {\n const source = this;\n return liftOneToOne(\n source,\n async function* (signal, context) {\n for await (const value of source.iterate(signal, context)) {\n callback(value);\n yield value;\n }\n },\n () => ({\n /** Runs the side effect and retains the original value. */\n onNext(value) {\n callback(value);\n return value;\n }\n })\n );\n};\n\nFlux.prototype.doOnError = function doOnError<T>(this: Flux<T>, callback: (error: unknown) => void): Flux<T> {\n const source = this;\n return liftOneToOne(\n source,\n async function* (signal, context) {\n try {\n for await (const value of source.iterate(signal, context)) {\n yield value;\n }\n } catch (error) {\n callback(error);\n throw error;\n }\n },\n () => ({\n onNext: passThrough,\n onError: callback\n })\n );\n};\n\nFlux.prototype.doOnComplete = function doOnComplete<T>(this: Flux<T>, callback: () => void): Flux<T> {\n const source = this;\n return liftOneToOne(\n source,\n async function* (signal, context) {\n for await (const value of source.iterate(signal, context)) {\n yield value;\n }\n callback();\n },\n () => ({\n onNext: passThrough,\n onComplete: callback\n })\n );\n};\n\nFlux.prototype.doFinally = function doFinally<T>(\n this: Flux<T>,\n callback: (signal: \"complete\" | \"error\" | \"cancel\") => void\n): Flux<T> {\n const source = this;\n return liftOneToOne(\n source,\n async function* (signal, context) {\n let terminal: \"complete\" | \"error\" | \"cancel\" = \"complete\";\n try {\n for await (const value of source.iterate(signal, context)) {\n if (signal.aborted) {\n terminal = \"cancel\";\n return;\n }\n yield value;\n }\n } catch (error) {\n terminal = signal.aborted ? \"cancel\" : \"error\";\n throw error;\n } finally {\n runFinallyCallback(callback, signal.aborted ? \"cancel\" : terminal);\n }\n },\n () => ({\n onNext: passThrough,\n onFinally: callback\n })\n );\n};\n\n/** Returns an operator value unchanged. */\nfunction passThrough<T>(value: T): T {\n return value;\n}\n\n/** Runs a final observer without allowing it to replace sequence termination. */\nfunction runFinallyCallback(\n callback: (signal: \"complete\" | \"error\" | \"cancel\") => void,\n signal: \"complete\" | \"error\" | \"cancel\"\n): void {\n try {\n callback(signal);\n } catch {\n // Final observers run after propagation and cannot replace the terminal signal.\n }\n}\n"],"mappings":";;;;;;;AAwBA,KAAK,UAAU,WAAW,SAAS,SAA2B,UAAuC;CACjG,MAAM,SAAS;CACf,OAAO,aACH,QACA,iBAAiB,QAAQ,SAAS;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,CAAC,CAAC,CAAC,CAAC;QAE1E,gEAAgE;QAChE,WAAW,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QAE/B,4EAA4E;QAC5E,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEjD,4EAA4E;QAC5E,SAAS,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAE3E,8DAA8D;QAC9D,iBAAiB,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEnF,oFAAoF;QACpF,2BAA2B,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,KAAK,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;KACtH;CACJ"}
@@ -1,17 +1,18 @@
1
1
  import { filterIterable, mapIterable } from "../../internal/iterable-transform.js";
2
2
  import { Flux } from "../flux.js";
3
+ import { liftFilter, liftOneToOne } from "./lift.js";
3
4
  import { Signal } from "../../signal/signal.js";
4
5
  //#region src/publisher/operators/transform.ts
5
6
  Flux.prototype.map = function map(mapper) {
6
7
  const source = this;
7
- return new Flux((signal, context) => mapIterable(source.iterate(signal, context), mapper));
8
+ return liftOneToOne(source, (signal, context) => mapIterable(source.iterate(signal, context), mapper), () => ({ onNext: mapper }));
8
9
  };
9
10
  Flux.prototype.cast = function cast() {
10
11
  return this;
11
12
  };
12
13
  Flux.prototype.filter = function filter(predicate) {
13
14
  const source = this;
14
- return new Flux((signal, context) => filterIterable(source.iterate(signal, context), predicate));
15
+ return liftFilter(source, (signal, context) => filterIterable(source.iterate(signal, context), predicate), predicate);
15
16
  };
16
17
  Flux.prototype.handle = function handle(handler) {
17
18
  const source = this;