reactor-core-ts 3.2.1 → 3.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +56 -0
- package/dist/core/demand.js +2 -2
- package/dist/core/demand.js.map +1 -1
- package/dist/publisher/flux.d.ts.map +1 -1
- package/dist/publisher/flux.js +92 -22
- package/dist/publisher/flux.js.map +1 -1
- package/dist/publisher/operators/lifecycle.d.ts.map +1 -1
- package/dist/publisher/operators/lifecycle.js +29 -3
- package/dist/publisher/operators/lifecycle.js.map +1 -1
- package/dist/publisher/operators/lift.d.ts +42 -0
- package/dist/publisher/operators/lift.d.ts.map +1 -0
- package/dist/publisher/operators/lift.js +343 -0
- package/dist/publisher/operators/lift.js.map +1 -0
- package/dist/publisher/operators/side-effect.d.ts.map +1 -1
- package/dist/publisher/operators/side-effect.js +34 -9
- package/dist/publisher/operators/side-effect.js.map +1 -1
- package/dist/publisher/operators/transform.d.ts.map +1 -1
- package/dist/publisher/operators/transform.js +3 -2
- package/dist/publisher/operators/transform.js.map +1 -1
- package/dist/subscription/iterable-subscription.js +1 -1
- package/package.json +2 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Schedulers } from "../../schedulers/schedulers.js";
|
|
2
2
|
import { scheduleDelay } from "../helpers.js";
|
|
3
3
|
import { Flux } from "../flux.js";
|
|
4
|
+
import { liftOneToOne, subscriberContext } from "./lift.js";
|
|
4
5
|
import { Signal } from "../../signal/signal.js";
|
|
5
6
|
//#region src/publisher/operators/lifecycle.ts
|
|
6
7
|
Flux.prototype.cache = function cache(_ttl, _scheduler) {
|
|
@@ -34,9 +35,16 @@ Flux.prototype.contextCapture = function contextCapture() {
|
|
|
34
35
|
};
|
|
35
36
|
Flux.prototype.contextWrite = function contextWrite(contextUpdate) {
|
|
36
37
|
const source = this;
|
|
37
|
-
return
|
|
38
|
+
return liftOneToOne(source, (signal, context) => {
|
|
38
39
|
const nextContext = typeof contextUpdate === "function" ? contextUpdate(context) : context.putAll(contextUpdate);
|
|
39
40
|
return source.iterate(signal, nextContext);
|
|
41
|
+
}, (subscriber) => {
|
|
42
|
+
const context = subscriberContext(subscriber);
|
|
43
|
+
const nextContext = typeof contextUpdate === "function" ? contextUpdate(context) : context.putAll(contextUpdate);
|
|
44
|
+
return {
|
|
45
|
+
onNext: passThrough,
|
|
46
|
+
currentContext: () => nextContext
|
|
47
|
+
};
|
|
40
48
|
});
|
|
41
49
|
};
|
|
42
50
|
Flux.prototype.delaySequence = function delaySequence(delay, scheduler) {
|
|
@@ -104,10 +112,24 @@ Flux.prototype.doOnEach = function doOnEach(callback) {
|
|
|
104
112
|
});
|
|
105
113
|
};
|
|
106
114
|
Flux.prototype.doOnRequest = function doOnRequest(callback) {
|
|
107
|
-
|
|
115
|
+
const source = this;
|
|
116
|
+
return liftOneToOne(source, (signal, context) => {
|
|
117
|
+
callback(Number.POSITIVE_INFINITY);
|
|
118
|
+
return source.iterate(signal, context);
|
|
119
|
+
}, () => ({
|
|
120
|
+
onNext: passThrough,
|
|
121
|
+
onRequest: callback
|
|
122
|
+
}));
|
|
108
123
|
};
|
|
109
124
|
Flux.prototype.doOnSubscribe = function doOnSubscribe(callback) {
|
|
110
|
-
|
|
125
|
+
const source = this;
|
|
126
|
+
return liftOneToOne(source, (signal, context) => {
|
|
127
|
+
callback(noopSubscription());
|
|
128
|
+
return source.iterate(signal, context);
|
|
129
|
+
}, () => ({
|
|
130
|
+
onNext: passThrough,
|
|
131
|
+
onSubscribe: callback
|
|
132
|
+
}));
|
|
111
133
|
};
|
|
112
134
|
Flux.prototype.doOnTerminate = function doOnTerminate(callback) {
|
|
113
135
|
const source = this;
|
|
@@ -232,6 +254,10 @@ function noopSubscription() {
|
|
|
232
254
|
cancel() {}
|
|
233
255
|
};
|
|
234
256
|
}
|
|
257
|
+
/** Returns an operator value unchanged. */
|
|
258
|
+
function passThrough(value) {
|
|
259
|
+
return value;
|
|
260
|
+
}
|
|
235
261
|
//#endregion
|
|
236
262
|
|
|
237
263
|
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle.js","names":[],"sources":["../../../src/publisher/operators/lifecycle.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Reactor lifecycle, context, logging and browser backpressure compatibility operators.\n */\nimport {Context} from \"@/context/context.js\";\nimport {ContextView} from \"@/context/context-view.js\";\nimport {Flux} from \"@/publisher/flux.js\";\nimport {scheduleDelay} from \"@/publisher/helpers.js\";\nimport type {PublisherInput} from \"@/publisher/types.js\";\nimport {Schedulers} from \"@/schedulers/schedulers.js\";\nimport type {DurationInput, Scheduler} from \"@/schedulers/types.js\";\nimport {Signal} from \"@/signal/signal.js\";\nimport type {Subscription} from \"@/subscription/subscription.js\";\n\n/** Listener shape accepted by the lightweight `tap` compatibility operator. */\nexport interface FluxTapListener<T> {\n /** Invoked for each next value. */\n onNext?(value: T): void;\n\n /** Invoked when the sequence fails. */\n onError?(error: unknown): void;\n\n /** Invoked when the sequence completes. */\n onComplete?(): void;\n\n /** Invoked when the sequence is cancelled. */\n onCancel?(): void;\n\n /** Invoked for materialized next, error and complete signals. */\n onSignal?(signal: Signal<T>): void;\n}\n\ndeclare module \"@/publisher/flux.js\" {\n /** Lifecycle, context and browser backpressure compatibility operators added to Flux. */\n interface Flux<T> {\n /** Replays the collected source values to later subscribers. */\n cache(ttl?: DurationInput, scheduler?: Scheduler): Flux<T>;\n\n /** Schedules cancellation on the provided scheduler when supported by the source. */\n cancelOn(scheduler: Scheduler): Flux<T>;\n\n /** Adds an assembly checkpoint marker. Browser implementation keeps the source unchanged. */\n checkpoint(description?: string, forceStackTrace?: boolean): Flux<T>;\n\n /** Captures ambient context when an integration provides it. Browser implementation keeps the source unchanged. */\n contextCapture(): Flux<T>;\n\n /** Writes subscriber context for upstream operators. */\n contextWrite(context: ContextView | Context | ((context: Context) => Context)): Flux<T>;\n\n /** Delays subscribing to the source. */\n delaySequence(delay: DurationInput, scheduler?: Scheduler): Flux<T>;\n\n /** Delays subscribing to the source by time or until another publisher signals. */\n delaySubscription(delay: DurationInput | PublisherInput<unknown>, scheduler?: Scheduler): Flux<T>;\n\n /** Delays each value until the trigger publisher derived from that value completes. */\n delayUntil(triggerProvider: (value: T) => PublisherInput<unknown>): Flux<T>;\n\n /** Invokes a callback after successful or failed termination. */\n doAfterTerminate(callback: () => void): Flux<T>;\n\n /** Invokes a callback before source iteration starts. */\n doFirst(callback: () => void): Flux<T>;\n\n /** Invokes a callback when the subscription is cancelled. */\n doOnCancel(callback: () => void): Flux<T>;\n\n /** Registers a discard hook. Browser implementation keeps values unchanged. */\n doOnDiscard<R>(type: new (...args: never[]) => R, callback: (value: R) => void): Flux<T>;\n\n /** Invokes a callback for every materialized source signal. */\n doOnEach(callback: (signal: Signal<T>) => void): Flux<T>;\n\n /** Invokes a callback when unbounded demand is requested by the async bridge. */\n doOnRequest(callback: (request: number) => void): Flux<T>;\n\n /** Invokes a callback with a synthetic subscription before source iteration starts. */\n doOnSubscribe(callback: (subscription: Subscription) => void): Flux<T>;\n\n /** Invokes a callback before successful or failed termination. */\n doOnTerminate(callback: () => void): Flux<T>;\n\n /** Keeps request batching metadata. Browser async iteration returns this source unchanged. */\n limitRate(highTide: number, lowTide?: number): Flux<T>;\n\n /** Limits the total number of requested values. */\n limitRequest(n: number): Flux<T>;\n\n /** Logs source signals to the console. */\n log(category?: string): Flux<T>;\n\n /** Keeps metrics compatibility metadata. Browser implementation returns this source unchanged. */\n metrics(): Flux<T>;\n\n /** Keeps a human-readable sequence name. Browser implementation returns this source unchanged. */\n name(name: string): Flux<T>;\n\n /** Buffers on backpressure. Browser async iteration already buffers by pull demand. */\n onBackpressureBuffer(...args: unknown[]): Flux<T>;\n\n /** Drops on backpressure. Browser async iteration keeps pull demand and returns this source unchanged. */\n onBackpressureDrop(callback?: (value: T) => void): Flux<T>;\n\n /** Fails on backpressure. Browser async iteration keeps pull demand and returns this source unchanged. */\n onBackpressureError(): Flux<T>;\n\n /** Keeps only the latest value on backpressure. Browser async iteration returns this source unchanged. */\n onBackpressureLatest(): Flux<T>;\n\n /** Completes instead of failing when the optional predicate accepts the error. */\n onErrorComplete(predicate?: (error: unknown) => boolean): Flux<T>;\n\n /** Continues with completion after invoking an error continuation callback. */\n onErrorContinue(callback: (error: unknown, value: T | undefined) => void): Flux<T>;\n\n /** Stops error continuation mode. Browser implementation returns this source unchanged. */\n onErrorStop(): Flux<T>;\n\n /** Drops terminal-reference retention hints. Browser implementation returns this source unchanged. */\n onTerminateDetach(): Flux<T>;\n\n /** Transforms a shared source or returns a shared source view. */\n publish<R = T>(transformer?: (source: Flux<T>) => PublisherInput<R>): Flux<R>;\n\n /** Returns a Mono with the next value from this source. */\n publishNext(): import(\"@/publisher/mono.js\").Mono<T>;\n\n /** Returns a replaying view of this source. */\n replay(...args: unknown[]): Flux<T>;\n\n /** Returns a shared browser view of this source. */\n share(): Flux<T>;\n\n /** Returns a Mono with the next value from a shared source. */\n shareNext(): import(\"@/publisher/mono.js\").Mono<T>;\n\n /** Stores a metadata tag. Browser implementation returns this source unchanged. */\n tag(key: string, value: string): Flux<T>;\n\n /** Installs listener callbacks for values, terminal signals, and cancellation. */\n tap(listener: FluxTapListener<T> | (() => FluxTapListener<T>)): Flux<T>;\n\n /** Returns an async iterator stream view of this Flux. */\n toStream(): AsyncIterable<T>;\n }\n}\n\nFlux.prototype.cache = function cache<T>(this: Flux<T>, _ttl?: DurationInput, _scheduler?: Scheduler): Flux<T> {\n const source = this;\n let values: T[] | undefined;\n let failure: unknown;\n let loaded: Promise<void> | undefined;\n return new Flux(async function* (signal, context) {\n loaded ??= (async () => {\n const nextValues: T[] = [];\n try {\n for await (const value of source.iterate(signal, context)) {\n nextValues.push(value);\n }\n values = nextValues;\n } catch (error) {\n failure = error;\n }\n })();\n await loaded;\n if (failure !== undefined) {\n throw failure;\n }\n yield* values ?? [];\n });\n};\n\nFlux.prototype.cancelOn = function cancelOn<T>(this: Flux<T>, _scheduler: Scheduler): Flux<T> {\n return this;\n};\n\nFlux.prototype.checkpoint = function checkpoint<T>(\n this: Flux<T>,\n _description?: string,\n _forceStackTrace?: boolean\n): Flux<T> {\n return this;\n};\n\nFlux.prototype.contextCapture = function contextCapture<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.contextWrite = function contextWrite<T>(\n this: Flux<T>,\n contextUpdate: ContextView | Context | ((context: Context) => Context)\n): Flux<T> {\n const source = this;\n return new Flux((signal, context) => {\n const nextContext =\n typeof contextUpdate === \"function\"\n ? contextUpdate(context)\n : context.putAll(contextUpdate);\n return source.iterate(signal, nextContext);\n });\n};\n\nFlux.prototype.delaySequence = function delaySequence<T>(\n this: Flux<T>,\n delay: DurationInput,\n scheduler?: Scheduler\n): Flux<T> {\n return this.delaySubscription(delay, scheduler);\n};\n\nFlux.prototype.delaySubscription = function delaySubscription<T>(\n this: Flux<T>,\n delay: DurationInput | PublisherInput<unknown>,\n scheduler?: Scheduler\n): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n if (isDuration(delay)) {\n await scheduleDelay(scheduler ?? Schedulers.timeout(), delay, signal);\n } else {\n await drain(delay, signal, context);\n }\n for await (const value of source.iterate(signal, context)) {\n yield value;\n }\n });\n};\n\nFlux.prototype.delayUntil = function delayUntil<T>(\n this: Flux<T>,\n triggerProvider: (value: T) => PublisherInput<unknown>\n): 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 await drain(triggerProvider(value), signal, context);\n yield value;\n }\n });\n};\n\nFlux.prototype.doAfterTerminate = function doAfterTerminate<T>(this: Flux<T>, callback: () => void): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n let terminated = false;\n try {\n for await (const value of source.iterate(signal, context)) {\n yield value;\n }\n terminated = true;\n } finally {\n if (terminated) {\n callback();\n }\n }\n });\n};\n\nFlux.prototype.doFirst = function doFirst<T>(this: Flux<T>, callback: () => void): Flux<T> {\n const source = this;\n return new Flux((signal, context) => {\n callback();\n return source.iterate(signal, context);\n });\n};\n\nFlux.prototype.doOnCancel = function doOnCancel<T>(this: Flux<T>, callback: () => void): Flux<T> {\n const source = this;\n return new Flux((signal, context) => {\n signal.addEventListener(\"abort\", callback, {once: true});\n return source.iterate(signal, context);\n });\n};\n\nFlux.prototype.doOnDiscard = function doOnDiscard<T, R>(\n this: Flux<T>,\n _type: new (...args: never[]) => R,\n _callback: (value: R) => void\n): Flux<T> {\n return this;\n};\n\nFlux.prototype.doOnEach = function doOnEach<T>(this: Flux<T>, callback: (signal: Signal<T>) => 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 callback(Signal.next(value));\n yield value;\n }\n callback(Signal.complete());\n } catch (error) {\n callback(Signal.error(error));\n throw error;\n }\n });\n};\n\nFlux.prototype.doOnRequest = function doOnRequest<T>(this: Flux<T>, callback: (request: number) => void): Flux<T> {\n return this.doFirst(() => callback(Number.POSITIVE_INFINITY));\n};\n\nFlux.prototype.doOnSubscribe = function doOnSubscribe<T>(\n this: Flux<T>,\n callback: (subscription: Subscription) => void\n): Flux<T> {\n return this.doFirst(() => callback(noopSubscription()));\n};\n\nFlux.prototype.doOnTerminate = function doOnTerminate<T>(this: Flux<T>, callback: () => 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 callback();\n } catch (error) {\n callback();\n throw error;\n }\n });\n};\n\nFlux.prototype.limitRate = function limitRate<T>(this: Flux<T>, _highTide: number, _lowTide?: number): Flux<T> {\n return this;\n};\n\nFlux.prototype.limitRequest = function limitRequest<T>(this: Flux<T>, n: number): Flux<T> {\n return this.take(n);\n};\n\nFlux.prototype.log = function log<T>(this: Flux<T>, category = \"Flux\"): Flux<T> {\n return this.doOnEach(signal => console.debug(category, signal.type, signal.value ?? signal.error));\n};\n\nFlux.prototype.metrics = function metrics<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.name = function name<T>(this: Flux<T>, _name: string): Flux<T> {\n return this;\n};\n\nFlux.prototype.onBackpressureBuffer = function onBackpressureBuffer<T>(this: Flux<T>, ..._args: unknown[]): Flux<T> {\n return this;\n};\n\nFlux.prototype.onBackpressureDrop = function onBackpressureDrop<T>(\n this: Flux<T>,\n _callback?: (value: T) => void\n): Flux<T> {\n return this;\n};\n\nFlux.prototype.onBackpressureError = function onBackpressureError<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.onBackpressureLatest = function onBackpressureLatest<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.onErrorComplete = function onErrorComplete<T>(\n this: Flux<T>,\n predicate: (error: unknown) => boolean = () => true\n): 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 if (!predicate(error)) {\n throw error;\n }\n }\n });\n};\n\nFlux.prototype.onErrorContinue = function onErrorContinue<T>(\n this: Flux<T>,\n callback: (error: unknown, value: T | undefined) => void\n): Flux<T> {\n return this.onErrorResume(error => {\n callback(error, undefined);\n return Flux.empty<T>();\n });\n};\n\nFlux.prototype.onErrorStop = function onErrorStop<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.onTerminateDetach = function onTerminateDetach<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.publish = function publish<T, R = T>(\n this: Flux<T>,\n transformer?: (source: Flux<T>) => PublisherInput<R>\n): Flux<R> {\n return transformer ? Flux.from(transformer(this.share())) : (this.share() as unknown as Flux<R>);\n};\n\nFlux.prototype.publishNext = function publishNext<T>(this: Flux<T>) {\n return this.next();\n};\n\nFlux.prototype.replay = function replay<T>(this: Flux<T>, ..._args: unknown[]): Flux<T> {\n return this.cache();\n};\n\nFlux.prototype.share = function share<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.shareNext = function shareNext<T>(this: Flux<T>) {\n return this.next();\n};\n\nFlux.prototype.tag = function tag<T>(this: Flux<T>, _key: string, _value: string): Flux<T> {\n return this;\n};\n\nFlux.prototype.tap = function tap<T>(this: Flux<T>, listener: FluxTapListener<T> | (() => FluxTapListener<T>)): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n const actual = typeof listener === \"function\" ? listener() : listener;\n signal.addEventListener(\"abort\", () => actual.onCancel?.(), {once: true});\n try {\n for await (const value of source.iterate(signal, context)) {\n actual.onNext?.(value);\n actual.onSignal?.(Signal.next(value));\n yield value;\n }\n actual.onComplete?.();\n actual.onSignal?.(Signal.complete());\n } catch (error) {\n actual.onError?.(error);\n actual.onSignal?.(Signal.error(error));\n throw error;\n }\n });\n};\n\nFlux.prototype.toStream = function toStream<T>(this: Flux<T>): AsyncIterable<T> {\n return this;\n};\n\n/** Returns true when a value can be treated as a duration input. */\nfunction isDuration(value: unknown): value is DurationInput {\n return typeof value === \"number\" || (typeof value === \"object\" && value !== null && !isPublisherLike(value));\n}\n\n/** Returns true when a value looks like a publisher or iterable source. */\nfunction isPublisherLike(value: object): boolean {\n return (\n typeof (value as { subscribe?: unknown }).subscribe === \"function\" ||\n typeof (value as { then?: unknown }).then === \"function\" ||\n typeof (value as { [Symbol.iterator]?: unknown })[Symbol.iterator] === \"function\" ||\n typeof (value as { [Symbol.asyncIterator]?: unknown })[Symbol.asyncIterator] === \"function\"\n );\n}\n\n/** Consumes a publisher input and ignores all emitted values. */\nasync function drain(source: PublisherInput<unknown>, signal: AbortSignal, context: Context): Promise<void> {\n for await (const _ of Flux.from(source).iterate(signal, context)) {\n // ignored\n }\n}\n\n/** Creates a no-op subscription object for doOnSubscribe callbacks. */\nfunction noopSubscription(): Subscription {\n return {\n /** Ignores request accounting for synthetic subscriptions. */\n request() {\n // no-op\n },\n /** Ignores cancellation for synthetic subscriptions. */\n cancel() {\n // no-op\n }\n };\n}\n"],"mappings":";;;;;AAoJA,KAAK,UAAU,QAAQ,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AAQ,OAAO,GAAG;IACvD,OAAO,SAAS,KAAK;IACrB,OAAO,WAAW,OAAO,KAAK,KAAK,CAAC;IACpC,MAAM;GACV;GACA,OAAO,aAAa;GACpB,OAAO,WAAW,OAAO,SAAS,CAAC;EACvC,SAAS,OAAO;GACZ,OAAO,UAAU,KAAK;GACtB,OAAO,WAAW,OAAO,MAAM,KAAK,CAAC;GACrC,MAAM;EACV;CACJ,CAAC;AACL;AAEA,KAAK,UAAU,WAAW,SAAS,WAA6C;CAC5E,OAAO;AACX;;AAGA,SAAS,WAAW,OAAwC;CACxD,OAAO,OAAO,UAAU,YAAa,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,gBAAgB,KAAK;AAC9G;;AAGA,SAAS,gBAAgB,OAAwB;CAC7C,OACI,OAAQ,MAAkC,cAAc,cACxD,OAAQ,MAA6B,SAAS,cAC9C,OAAQ,MAA0C,OAAO,cAAc,cACvE,OAAQ,MAA+C,OAAO,mBAAmB;AAEzF;;AAGA,eAAe,MAAM,QAAiC,QAAqB,SAAiC;CACxG,WAAW,MAAM,KAAK,KAAK,KAAK,MAAM,CAAC,CAAC,QAAQ,QAAQ,OAAO;AAGnE;;AAGA,SAAS,mBAAiC;CACtC,OAAO;;EAEH,UAAU,CAEV;;EAEA,SAAS,CAET;CACJ;AACJ"}
|
|
1
|
+
{"version":3,"file":"lifecycle.js","names":[],"sources":["../../../src/publisher/operators/lifecycle.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Reactor lifecycle, context, logging and browser backpressure compatibility operators.\n */\nimport {Context} from \"@/context/context.js\";\nimport {ContextView} from \"@/context/context-view.js\";\nimport {Flux} from \"@/publisher/flux.js\";\nimport {scheduleDelay} from \"@/publisher/helpers.js\";\nimport {liftOneToOne, subscriberContext} from \"@/publisher/operators/lift.js\";\nimport type {PublisherInput} from \"@/publisher/types.js\";\nimport {Schedulers} from \"@/schedulers/schedulers.js\";\nimport type {DurationInput, Scheduler} from \"@/schedulers/types.js\";\nimport {Signal} from \"@/signal/signal.js\";\nimport type {Subscription} from \"@/subscription/subscription.js\";\n\n/** Listener shape accepted by the lightweight `tap` compatibility operator. */\nexport interface FluxTapListener<T> {\n /** Invoked for each next value. */\n onNext?(value: T): void;\n\n /** Invoked when the sequence fails. */\n onError?(error: unknown): void;\n\n /** Invoked when the sequence completes. */\n onComplete?(): void;\n\n /** Invoked when the sequence is cancelled. */\n onCancel?(): void;\n\n /** Invoked for materialized next, error and complete signals. */\n onSignal?(signal: Signal<T>): void;\n}\n\ndeclare module \"@/publisher/flux.js\" {\n /** Lifecycle, context and browser backpressure compatibility operators added to Flux. */\n interface Flux<T> {\n /** Replays the collected source values to later subscribers. */\n cache(ttl?: DurationInput, scheduler?: Scheduler): Flux<T>;\n\n /** Schedules cancellation on the provided scheduler when supported by the source. */\n cancelOn(scheduler: Scheduler): Flux<T>;\n\n /** Adds an assembly checkpoint marker. Browser implementation keeps the source unchanged. */\n checkpoint(description?: string, forceStackTrace?: boolean): Flux<T>;\n\n /** Captures ambient context when an integration provides it. Browser implementation keeps the source unchanged. */\n contextCapture(): Flux<T>;\n\n /** Writes subscriber context for upstream operators. */\n contextWrite(context: ContextView | Context | ((context: Context) => Context)): Flux<T>;\n\n /** Delays subscribing to the source. */\n delaySequence(delay: DurationInput, scheduler?: Scheduler): Flux<T>;\n\n /** Delays subscribing to the source by time or until another publisher signals. */\n delaySubscription(delay: DurationInput | PublisherInput<unknown>, scheduler?: Scheduler): Flux<T>;\n\n /** Delays each value until the trigger publisher derived from that value completes. */\n delayUntil(triggerProvider: (value: T) => PublisherInput<unknown>): Flux<T>;\n\n /** Invokes a callback after successful or failed termination. */\n doAfterTerminate(callback: () => void): Flux<T>;\n\n /** Invokes a callback before source iteration starts. */\n doFirst(callback: () => void): Flux<T>;\n\n /** Invokes a callback when the subscription is cancelled. */\n doOnCancel(callback: () => void): Flux<T>;\n\n /** Registers a discard hook. Browser implementation keeps values unchanged. */\n doOnDiscard<R>(type: new (...args: never[]) => R, callback: (value: R) => void): Flux<T>;\n\n /** Invokes a callback for every materialized source signal. */\n doOnEach(callback: (signal: Signal<T>) => void): Flux<T>;\n\n /** Invokes a callback when unbounded demand is requested by the async bridge. */\n doOnRequest(callback: (request: number) => void): Flux<T>;\n\n /** Invokes a callback with a synthetic subscription before source iteration starts. */\n doOnSubscribe(callback: (subscription: Subscription) => void): Flux<T>;\n\n /** Invokes a callback before successful or failed termination. */\n doOnTerminate(callback: () => void): Flux<T>;\n\n /** Keeps request batching metadata. Browser async iteration returns this source unchanged. */\n limitRate(highTide: number, lowTide?: number): Flux<T>;\n\n /** Limits the total number of requested values. */\n limitRequest(n: number): Flux<T>;\n\n /** Logs source signals to the console. */\n log(category?: string): Flux<T>;\n\n /** Keeps metrics compatibility metadata. Browser implementation returns this source unchanged. */\n metrics(): Flux<T>;\n\n /** Keeps a human-readable sequence name. Browser implementation returns this source unchanged. */\n name(name: string): Flux<T>;\n\n /** Buffers on backpressure. Browser async iteration already buffers by pull demand. */\n onBackpressureBuffer(...args: unknown[]): Flux<T>;\n\n /** Drops on backpressure. Browser async iteration keeps pull demand and returns this source unchanged. */\n onBackpressureDrop(callback?: (value: T) => void): Flux<T>;\n\n /** Fails on backpressure. Browser async iteration keeps pull demand and returns this source unchanged. */\n onBackpressureError(): Flux<T>;\n\n /** Keeps only the latest value on backpressure. Browser async iteration returns this source unchanged. */\n onBackpressureLatest(): Flux<T>;\n\n /** Completes instead of failing when the optional predicate accepts the error. */\n onErrorComplete(predicate?: (error: unknown) => boolean): Flux<T>;\n\n /** Continues with completion after invoking an error continuation callback. */\n onErrorContinue(callback: (error: unknown, value: T | undefined) => void): Flux<T>;\n\n /** Stops error continuation mode. Browser implementation returns this source unchanged. */\n onErrorStop(): Flux<T>;\n\n /** Drops terminal-reference retention hints. Browser implementation returns this source unchanged. */\n onTerminateDetach(): Flux<T>;\n\n /** Transforms a shared source or returns a shared source view. */\n publish<R = T>(transformer?: (source: Flux<T>) => PublisherInput<R>): Flux<R>;\n\n /** Returns a Mono with the next value from this source. */\n publishNext(): import(\"@/publisher/mono.js\").Mono<T>;\n\n /** Returns a replaying view of this source. */\n replay(...args: unknown[]): Flux<T>;\n\n /** Returns a shared browser view of this source. */\n share(): Flux<T>;\n\n /** Returns a Mono with the next value from a shared source. */\n shareNext(): import(\"@/publisher/mono.js\").Mono<T>;\n\n /** Stores a metadata tag. Browser implementation returns this source unchanged. */\n tag(key: string, value: string): Flux<T>;\n\n /** Installs listener callbacks for values, terminal signals, and cancellation. */\n tap(listener: FluxTapListener<T> | (() => FluxTapListener<T>)): Flux<T>;\n\n /** Returns an async iterator stream view of this Flux. */\n toStream(): AsyncIterable<T>;\n }\n}\n\nFlux.prototype.cache = function cache<T>(this: Flux<T>, _ttl?: DurationInput, _scheduler?: Scheduler): Flux<T> {\n const source = this;\n let values: T[] | undefined;\n let failure: unknown;\n let loaded: Promise<void> | undefined;\n return new Flux(async function* (signal, context) {\n loaded ??= (async () => {\n const nextValues: T[] = [];\n try {\n for await (const value of source.iterate(signal, context)) {\n nextValues.push(value);\n }\n values = nextValues;\n } catch (error) {\n failure = error;\n }\n })();\n await loaded;\n if (failure !== undefined) {\n throw failure;\n }\n yield* values ?? [];\n });\n};\n\nFlux.prototype.cancelOn = function cancelOn<T>(this: Flux<T>, _scheduler: Scheduler): Flux<T> {\n return this;\n};\n\nFlux.prototype.checkpoint = function checkpoint<T>(\n this: Flux<T>,\n _description?: string,\n _forceStackTrace?: boolean\n): Flux<T> {\n return this;\n};\n\nFlux.prototype.contextCapture = function contextCapture<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.contextWrite = function contextWrite<T>(\n this: Flux<T>,\n contextUpdate: ContextView | Context | ((context: Context) => Context)\n): Flux<T> {\n const source = this;\n return liftOneToOne(\n source,\n (signal, context) => {\n const nextContext =\n typeof contextUpdate === \"function\"\n ? contextUpdate(context)\n : context.putAll(contextUpdate);\n return source.iterate(signal, nextContext);\n },\n subscriber => {\n const context = subscriberContext(subscriber);\n const nextContext =\n typeof contextUpdate === \"function\"\n ? contextUpdate(context)\n : context.putAll(contextUpdate);\n return {\n onNext: passThrough,\n currentContext: () => nextContext\n };\n }\n );\n};\n\nFlux.prototype.delaySequence = function delaySequence<T>(\n this: Flux<T>,\n delay: DurationInput,\n scheduler?: Scheduler\n): Flux<T> {\n return this.delaySubscription(delay, scheduler);\n};\n\nFlux.prototype.delaySubscription = function delaySubscription<T>(\n this: Flux<T>,\n delay: DurationInput | PublisherInput<unknown>,\n scheduler?: Scheduler\n): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n if (isDuration(delay)) {\n await scheduleDelay(scheduler ?? Schedulers.timeout(), delay, signal);\n } else {\n await drain(delay, signal, context);\n }\n for await (const value of source.iterate(signal, context)) {\n yield value;\n }\n });\n};\n\nFlux.prototype.delayUntil = function delayUntil<T>(\n this: Flux<T>,\n triggerProvider: (value: T) => PublisherInput<unknown>\n): 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 await drain(triggerProvider(value), signal, context);\n yield value;\n }\n });\n};\n\nFlux.prototype.doAfterTerminate = function doAfterTerminate<T>(this: Flux<T>, callback: () => void): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n let terminated = false;\n try {\n for await (const value of source.iterate(signal, context)) {\n yield value;\n }\n terminated = true;\n } finally {\n if (terminated) {\n callback();\n }\n }\n });\n};\n\nFlux.prototype.doFirst = function doFirst<T>(this: Flux<T>, callback: () => void): Flux<T> {\n const source = this;\n return new Flux((signal, context) => {\n callback();\n return source.iterate(signal, context);\n });\n};\n\nFlux.prototype.doOnCancel = function doOnCancel<T>(this: Flux<T>, callback: () => void): Flux<T> {\n const source = this;\n return new Flux((signal, context) => {\n signal.addEventListener(\"abort\", callback, {once: true});\n return source.iterate(signal, context);\n });\n};\n\nFlux.prototype.doOnDiscard = function doOnDiscard<T, R>(\n this: Flux<T>,\n _type: new (...args: never[]) => R,\n _callback: (value: R) => void\n): Flux<T> {\n return this;\n};\n\nFlux.prototype.doOnEach = function doOnEach<T>(this: Flux<T>, callback: (signal: Signal<T>) => 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 callback(Signal.next(value));\n yield value;\n }\n callback(Signal.complete());\n } catch (error) {\n callback(Signal.error(error));\n throw error;\n }\n });\n};\n\nFlux.prototype.doOnRequest = function doOnRequest<T>(this: Flux<T>, callback: (request: number) => void): Flux<T> {\n const source = this;\n return liftOneToOne(\n source,\n (signal, context) => {\n callback(Number.POSITIVE_INFINITY);\n return source.iterate(signal, context);\n },\n () => ({\n onNext: passThrough,\n onRequest: callback\n })\n );\n};\n\nFlux.prototype.doOnSubscribe = function doOnSubscribe<T>(\n this: Flux<T>,\n callback: (subscription: Subscription) => void\n): Flux<T> {\n const source = this;\n return liftOneToOne(\n source,\n (signal, context) => {\n callback(noopSubscription());\n return source.iterate(signal, context);\n },\n () => ({\n onNext: passThrough,\n onSubscribe: callback\n })\n );\n};\n\nFlux.prototype.doOnTerminate = function doOnTerminate<T>(this: Flux<T>, callback: () => 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 callback();\n } catch (error) {\n callback();\n throw error;\n }\n });\n};\n\nFlux.prototype.limitRate = function limitRate<T>(this: Flux<T>, _highTide: number, _lowTide?: number): Flux<T> {\n return this;\n};\n\nFlux.prototype.limitRequest = function limitRequest<T>(this: Flux<T>, n: number): Flux<T> {\n return this.take(n);\n};\n\nFlux.prototype.log = function log<T>(this: Flux<T>, category = \"Flux\"): Flux<T> {\n return this.doOnEach(signal => console.debug(category, signal.type, signal.value ?? signal.error));\n};\n\nFlux.prototype.metrics = function metrics<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.name = function name<T>(this: Flux<T>, _name: string): Flux<T> {\n return this;\n};\n\nFlux.prototype.onBackpressureBuffer = function onBackpressureBuffer<T>(this: Flux<T>, ..._args: unknown[]): Flux<T> {\n return this;\n};\n\nFlux.prototype.onBackpressureDrop = function onBackpressureDrop<T>(\n this: Flux<T>,\n _callback?: (value: T) => void\n): Flux<T> {\n return this;\n};\n\nFlux.prototype.onBackpressureError = function onBackpressureError<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.onBackpressureLatest = function onBackpressureLatest<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.onErrorComplete = function onErrorComplete<T>(\n this: Flux<T>,\n predicate: (error: unknown) => boolean = () => true\n): 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 if (!predicate(error)) {\n throw error;\n }\n }\n });\n};\n\nFlux.prototype.onErrorContinue = function onErrorContinue<T>(\n this: Flux<T>,\n callback: (error: unknown, value: T | undefined) => void\n): Flux<T> {\n return this.onErrorResume(error => {\n callback(error, undefined);\n return Flux.empty<T>();\n });\n};\n\nFlux.prototype.onErrorStop = function onErrorStop<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.onTerminateDetach = function onTerminateDetach<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.publish = function publish<T, R = T>(\n this: Flux<T>,\n transformer?: (source: Flux<T>) => PublisherInput<R>\n): Flux<R> {\n return transformer ? Flux.from(transformer(this.share())) : (this.share() as unknown as Flux<R>);\n};\n\nFlux.prototype.publishNext = function publishNext<T>(this: Flux<T>) {\n return this.next();\n};\n\nFlux.prototype.replay = function replay<T>(this: Flux<T>, ..._args: unknown[]): Flux<T> {\n return this.cache();\n};\n\nFlux.prototype.share = function share<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.shareNext = function shareNext<T>(this: Flux<T>) {\n return this.next();\n};\n\nFlux.prototype.tag = function tag<T>(this: Flux<T>, _key: string, _value: string): Flux<T> {\n return this;\n};\n\nFlux.prototype.tap = function tap<T>(this: Flux<T>, listener: FluxTapListener<T> | (() => FluxTapListener<T>)): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n const actual = typeof listener === \"function\" ? listener() : listener;\n signal.addEventListener(\"abort\", () => actual.onCancel?.(), {once: true});\n try {\n for await (const value of source.iterate(signal, context)) {\n actual.onNext?.(value);\n actual.onSignal?.(Signal.next(value));\n yield value;\n }\n actual.onComplete?.();\n actual.onSignal?.(Signal.complete());\n } catch (error) {\n actual.onError?.(error);\n actual.onSignal?.(Signal.error(error));\n throw error;\n }\n });\n};\n\nFlux.prototype.toStream = function toStream<T>(this: Flux<T>): AsyncIterable<T> {\n return this;\n};\n\n/** Returns true when a value can be treated as a duration input. */\nfunction isDuration(value: unknown): value is DurationInput {\n return typeof value === \"number\" || (typeof value === \"object\" && value !== null && !isPublisherLike(value));\n}\n\n/** Returns true when a value looks like a publisher or iterable source. */\nfunction isPublisherLike(value: object): boolean {\n return (\n typeof (value as { subscribe?: unknown }).subscribe === \"function\" ||\n typeof (value as { then?: unknown }).then === \"function\" ||\n typeof (value as { [Symbol.iterator]?: unknown })[Symbol.iterator] === \"function\" ||\n typeof (value as { [Symbol.asyncIterator]?: unknown })[Symbol.asyncIterator] === \"function\"\n );\n}\n\n/** Consumes a publisher input and ignores all emitted values. */\nasync function drain(source: PublisherInput<unknown>, signal: AbortSignal, context: Context): Promise<void> {\n for await (const _ of Flux.from(source).iterate(signal, context)) {\n // ignored\n }\n}\n\n/** Creates a no-op subscription object for doOnSubscribe callbacks. */\nfunction noopSubscription(): Subscription {\n return {\n /** Ignores request accounting for synthetic subscriptions. */\n request() {\n // no-op\n },\n /** Ignores cancellation for synthetic subscriptions. */\n cancel() {\n // no-op\n }\n };\n}\n\n/** Returns an operator value unchanged. */\nfunction passThrough<T>(value: T): T {\n return value;\n}\n"],"mappings":";;;;;;AAqJA,KAAK,UAAU,QAAQ,SAAS,MAAwB,MAAsB,YAAiC;CAC3G,MAAM,SAAS;CACf,IAAI;CACJ,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|
+
* @packageDocumentation
|
|
3
|
+
* Internal subscriber-lifting primitives for demand-preserving Flux operators.
|
|
4
|
+
*/
|
|
5
|
+
import { Context } from "../../context/context.js";
|
|
6
|
+
import type { SourceFactory } from "../types.js";
|
|
7
|
+
import { Flux } from "../flux.js";
|
|
8
|
+
import type { Subscriber } from "../../subscription/subscriber.js";
|
|
9
|
+
import type { Subscription } from "../../subscription/subscription.js";
|
|
10
|
+
/** Creates the subscriber that an upstream Flux sees for a downstream subscriber. */
|
|
11
|
+
export type SubscriberLifter<T, R> = (subscriber: Subscriber<R>) => Subscriber<T>;
|
|
12
|
+
/** Hooks used by synchronous one-input/one-output operators. */
|
|
13
|
+
export interface OneToOneOperatorHooks<T, R> {
|
|
14
|
+
/** Converts one upstream value into exactly one downstream value. */
|
|
15
|
+
onNext(value: T): R;
|
|
16
|
+
/** Runs before the downstream receives its subscription. */
|
|
17
|
+
onSubscribe?(subscription: Subscription): void;
|
|
18
|
+
/** Runs before an upstream error is forwarded. */
|
|
19
|
+
onError?(error: unknown): void;
|
|
20
|
+
/** Runs before downstream demand is forwarded upstream. */
|
|
21
|
+
onRequest?(request: number): void;
|
|
22
|
+
/** Runs before successful completion is forwarded. */
|
|
23
|
+
onComplete?(): void;
|
|
24
|
+
/** Runs when downstream cancellation is propagated upstream. */
|
|
25
|
+
onCancel?(): void;
|
|
26
|
+
/** Runs after the terminal signal or cancellation has been propagated. */
|
|
27
|
+
onFinally?(signal: "complete" | "error" | "cancel"): void;
|
|
28
|
+
/** Context exposed to the upstream subscriber. */
|
|
29
|
+
currentContext?(): Context;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Lifts a Flux at the Reactive Streams subscriber boundary while keeping an
|
|
33
|
+
* iterable implementation for explicit async-iterator consumption.
|
|
34
|
+
*/
|
|
35
|
+
export declare function liftFlux<T, R>(source: Flux<T>, sourceFactory: SourceFactory<R>, lifter: SubscriberLifter<T, R>): Flux<R>;
|
|
36
|
+
/** Creates a one-to-one operator that forwards downstream demand unchanged. */
|
|
37
|
+
export declare function liftOneToOne<T, R>(source: Flux<T>, sourceFactory: SourceFactory<R>, hooksFactory: (subscriber: Subscriber<R>) => OneToOneOperatorHooks<T, R>): Flux<R>;
|
|
38
|
+
/** Creates a filtering operator that replenishes only values dropped from finite demand. */
|
|
39
|
+
export declare function liftFilter<T>(source: Flux<T>, sourceFactory: SourceFactory<T>, predicate: (value: T) => boolean): Flux<T>;
|
|
40
|
+
/** Returns the context exposed by a subscriber, or the shared empty context. */
|
|
41
|
+
export declare function subscriberContext<T>(subscriber: Subscriber<T>): Context;
|
|
42
|
+
//# sourceMappingURL=lift.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lift.d.ts","sourceRoot":"","sources":["../../../src/publisher/operators/lift.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAC,OAAO,EAAC,MAAM,sBAAsB,CAAC;AAE7C,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAC,IAAI,EAAC,MAAM,qBAAqB,CAAC;AAEzC,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,8BAA8B,CAAC;AAC7D,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,gCAAgC,CAAC;AAEjE,qFAAqF;AACrF,MAAM,MAAM,gBAAgB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC;AAElF,gEAAgE;AAChE,MAAM,WAAW,qBAAqB,CAAC,CAAC,EAAE,CAAC;IACvC,qEAAqE;IACrE,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;IAEpB,4DAA4D;IAC5D,WAAW,CAAC,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;IAE/C,kDAAkD;IAClD,OAAO,CAAC,CAAC,KAAK,EAAE,OAAO,GAAG,IA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
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,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I,KAAK,YACL;EAEJ,KAAK,aAAa;EAClB,KAAK,OAAO,WAAW;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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"side-effect.d.ts","sourceRoot":"","sources":["../../../src/publisher/operators/side-effect.ts"],"names":[],"mappings":"
|
|
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"}
|