reactor-core-ts 2.1.6 → 3.2.1

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 (269) hide show
  1. package/README.md +927 -658
  2. package/dist/_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/defineProperty.js +12 -0
  3. package/dist/_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/toPrimitive.js +14 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/toPropertyKey.js +9 -0
  5. package/dist/_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/typeof.js +11 -0
  6. package/dist/context/context-view.d.ts +31 -0
  7. package/dist/context/context-view.d.ts.map +1 -0
  8. package/dist/context/context-view.js +58 -0
  9. package/dist/context/context-view.js.map +1 -0
  10. package/dist/context/context.d.ts +46 -0
  11. package/dist/context/context.d.ts.map +1 -0
  12. package/dist/context/context.js +125 -0
  13. package/dist/context/context.js.map +1 -0
  14. package/dist/context/types.d.ts +7 -0
  15. package/dist/context/types.d.ts.map +1 -0
  16. package/dist/core/boolean-disposable.d.ts +19 -0
  17. package/dist/core/boolean-disposable.d.ts.map +1 -0
  18. package/dist/core/boolean-disposable.js +37 -0
  19. package/dist/core/boolean-disposable.js.map +1 -0
  20. package/dist/core/composite-disposable.d.ts +21 -0
  21. package/dist/core/composite-disposable.d.ts.map +1 -0
  22. package/dist/core/composite-disposable.js +64 -0
  23. package/dist/core/composite-disposable.js.map +1 -0
  24. package/dist/core/demand.d.ts +9 -0
  25. package/dist/core/demand.d.ts.map +1 -0
  26. package/dist/core/demand.js +21 -0
  27. package/dist/core/demand.js.map +1 -0
  28. package/dist/core/disposables.d.ts +12 -0
  29. package/dist/core/disposables.d.ts.map +1 -0
  30. package/dist/core/disposables.js +37 -0
  31. package/dist/core/disposables.js.map +1 -0
  32. package/dist/core/teardown.d.ts +4 -0
  33. package/dist/core/teardown.d.ts.map +1 -0
  34. package/dist/core/types.d.ts +14 -0
  35. package/dist/core/types.d.ts.map +1 -0
  36. package/dist/errors/classes.d.ts +37 -0
  37. package/dist/errors/classes.d.ts.map +1 -0
  38. package/dist/errors/classes.js +53 -0
  39. package/dist/errors/classes.js.map +1 -0
  40. package/dist/errors/exceptions.d.ts +15 -0
  41. package/dist/errors/exceptions.d.ts.map +1 -0
  42. package/dist/errors/helpers.d.ts +9 -0
  43. package/dist/errors/helpers.d.ts.map +1 -0
  44. package/dist/errors/helpers.js +18 -0
  45. package/dist/errors/helpers.js.map +1 -0
  46. package/dist/index.d.ts +17 -2556
  47. package/dist/index.d.ts.map +1 -0
  48. package/dist/index.js +8 -2
  49. package/dist/internal/abort.d.ts +5 -0
  50. package/dist/internal/abort.d.ts.map +1 -0
  51. package/dist/internal/abort.js +36 -0
  52. package/dist/internal/abort.js.map +1 -0
  53. package/dist/internal/async-queue.d.ts +48 -0
  54. package/dist/internal/async-queue.d.ts.map +1 -0
  55. package/dist/internal/async-queue.js +187 -0
  56. package/dist/internal/async-queue.js.map +1 -0
  57. package/dist/internal/iterable-terminal.d.ts +12 -0
  58. package/dist/internal/iterable-terminal.d.ts.map +1 -0
  59. package/dist/internal/iterable-terminal.js +49 -0
  60. package/dist/internal/iterable-terminal.js.map +1 -0
  61. package/dist/internal/iterable-transform.d.ts +24 -0
  62. package/dist/internal/iterable-transform.d.ts.map +1 -0
  63. package/dist/internal/iterable-transform.js +159 -0
  64. package/dist/internal/iterable-transform.js.map +1 -0
  65. package/dist/internal/iterable.d.ts +23 -0
  66. package/dist/internal/iterable.d.ts.map +1 -0
  67. package/dist/internal/iterable.js +81 -0
  68. package/dist/internal/iterable.js.map +1 -0
  69. package/dist/internal/microtask.d.ts +7 -0
  70. package/dist/internal/microtask.d.ts.map +1 -0
  71. package/dist/internal/microtask.js +19 -0
  72. package/dist/internal/microtask.js.map +1 -0
  73. package/dist/publisher/browser-sources.d.ts +15 -0
  74. package/dist/publisher/browser-sources.d.ts.map +1 -0
  75. package/dist/publisher/browser-sources.js +92 -0
  76. package/dist/publisher/browser-sources.js.map +1 -0
  77. package/dist/publisher/flux-entrypoint.d.ts +7 -0
  78. package/dist/publisher/flux-entrypoint.d.ts.map +1 -0
  79. package/dist/publisher/flux-entrypoint.js +11 -0
  80. package/dist/publisher/flux-entrypoint.js.map +1 -0
  81. package/dist/publisher/flux.d.ts +121 -0
  82. package/dist/publisher/flux.d.ts.map +1 -0
  83. package/dist/publisher/flux.js +697 -0
  84. package/dist/publisher/flux.js.map +1 -0
  85. package/dist/publisher/helpers.d.ts +19 -0
  86. package/dist/publisher/helpers.d.ts.map +1 -0
  87. package/dist/publisher/helpers.js +84 -0
  88. package/dist/publisher/helpers.js.map +1 -0
  89. package/dist/publisher/mono-entrypoint.d.ts +7 -0
  90. package/dist/publisher/mono-entrypoint.d.ts.map +1 -0
  91. package/dist/publisher/mono-entrypoint.js +11 -0
  92. package/dist/publisher/mono-entrypoint.js.map +1 -0
  93. package/dist/publisher/mono.d.ts +72 -0
  94. package/dist/publisher/mono.d.ts.map +1 -0
  95. package/dist/publisher/mono.js +373 -0
  96. package/dist/publisher/mono.js.map +1 -0
  97. package/dist/publisher/operators/aggregate.d.ts +35 -0
  98. package/dist/publisher/operators/aggregate.d.ts.map +1 -0
  99. package/dist/publisher/operators/aggregate.js +217 -0
  100. package/dist/publisher/operators/aggregate.js.map +1 -0
  101. package/dist/publisher/operators/compat/flux.d.ts +56 -0
  102. package/dist/publisher/operators/compat/flux.d.ts.map +1 -0
  103. package/dist/publisher/operators/compat/flux.js +156 -0
  104. package/dist/publisher/operators/compat/flux.js.map +1 -0
  105. package/dist/publisher/operators/compat/mono.d.ts +82 -0
  106. package/dist/publisher/operators/compat/mono.d.ts.map +1 -0
  107. package/dist/publisher/operators/compat/mono.js +125 -0
  108. package/dist/publisher/operators/compat/mono.js.map +1 -0
  109. package/dist/publisher/operators/coordination.d.ts +82 -0
  110. package/dist/publisher/operators/coordination.d.ts.map +1 -0
  111. package/dist/publisher/operators/coordination.js +345 -0
  112. package/dist/publisher/operators/coordination.js.map +1 -0
  113. package/dist/publisher/operators/error.d.ts +17 -0
  114. package/dist/publisher/operators/error.d.ts.map +1 -0
  115. package/dist/publisher/operators/error.js +48 -0
  116. package/dist/publisher/operators/error.js.map +1 -0
  117. package/dist/publisher/operators/flatten.d.ts +19 -0
  118. package/dist/publisher/operators/flatten.d.ts.map +1 -0
  119. package/dist/publisher/operators/flatten.js +127 -0
  120. package/dist/publisher/operators/flatten.js.map +1 -0
  121. package/dist/publisher/operators/lifecycle.d.ts +103 -0
  122. package/dist/publisher/operators/lifecycle.d.ts.map +1 -0
  123. package/dist/publisher/operators/lifecycle.js +237 -0
  124. package/dist/publisher/operators/lifecycle.js.map +1 -0
  125. package/dist/publisher/operators/mono-parity.d.ts +109 -0
  126. package/dist/publisher/operators/mono-parity.d.ts.map +1 -0
  127. package/dist/publisher/operators/mono-parity.js +144 -0
  128. package/dist/publisher/operators/mono-parity.js.map +1 -0
  129. package/dist/publisher/operators/mono.d.ts +30 -0
  130. package/dist/publisher/operators/mono.d.ts.map +1 -0
  131. package/dist/publisher/operators/mono.js +37 -0
  132. package/dist/publisher/operators/mono.js.map +1 -0
  133. package/dist/publisher/operators/register.d.ts +20 -0
  134. package/dist/publisher/operators/register.d.ts.map +1 -0
  135. package/dist/publisher/operators/register.js +23 -0
  136. package/dist/publisher/operators/register.js.map +1 -0
  137. package/dist/publisher/operators/selection.d.ts +25 -0
  138. package/dist/publisher/operators/selection.d.ts.map +1 -0
  139. package/dist/publisher/operators/selection.js +108 -0
  140. package/dist/publisher/operators/selection.js.map +1 -0
  141. package/dist/publisher/operators/side-effect.d.ts +15 -0
  142. package/dist/publisher/operators/side-effect.d.ts.map +1 -0
  143. package/dist/publisher/operators/side-effect.js +56 -0
  144. package/dist/publisher/operators/side-effect.js.map +1 -0
  145. package/dist/publisher/operators/terminal.d.ts +16 -0
  146. package/dist/publisher/operators/terminal.d.ts.map +1 -0
  147. package/dist/publisher/operators/terminal.js +47 -0
  148. package/dist/publisher/operators/terminal.js.map +1 -0
  149. package/dist/publisher/operators/time.d.ts +20 -0
  150. package/dist/publisher/operators/time.d.ts.map +1 -0
  151. package/dist/publisher/operators/time.js +92 -0
  152. package/dist/publisher/operators/time.js.map +1 -0
  153. package/dist/publisher/operators/transform.d.ts +31 -0
  154. package/dist/publisher/operators/transform.d.ts.map +1 -0
  155. package/dist/publisher/operators/transform.js +74 -0
  156. package/dist/publisher/operators/transform.js.map +1 -0
  157. package/dist/publisher/operators/windowing.d.ts +28 -0
  158. package/dist/publisher/operators/windowing.d.ts.map +1 -0
  159. package/dist/publisher/operators/windowing.js +148 -0
  160. package/dist/publisher/operators/windowing.js.map +1 -0
  161. package/dist/publisher/publisher.d.ts +11 -0
  162. package/dist/publisher/publisher.d.ts.map +1 -0
  163. package/dist/publisher/types.d.ts +51 -0
  164. package/dist/publisher/types.d.ts.map +1 -0
  165. package/dist/schedulers/animation-frame-scheduler.d.ts +11 -0
  166. package/dist/schedulers/animation-frame-scheduler.d.ts.map +1 -0
  167. package/dist/schedulers/animation-frame-scheduler.js +30 -0
  168. package/dist/schedulers/animation-frame-scheduler.js.map +1 -0
  169. package/dist/schedulers/base-scheduler.d.ts +28 -0
  170. package/dist/schedulers/base-scheduler.d.ts.map +1 -0
  171. package/dist/schedulers/base-scheduler.js +77 -0
  172. package/dist/schedulers/base-scheduler.js.map +1 -0
  173. package/dist/schedulers/basic-worker.d.ts +22 -0
  174. package/dist/schedulers/basic-worker.d.ts.map +1 -0
  175. package/dist/schedulers/basic-worker.js +71 -0
  176. package/dist/schedulers/basic-worker.js.map +1 -0
  177. package/dist/schedulers/delay-scheduler.d.ts +12 -0
  178. package/dist/schedulers/delay-scheduler.d.ts.map +1 -0
  179. package/dist/schedulers/delay-scheduler.js +17 -0
  180. package/dist/schedulers/delay-scheduler.js.map +1 -0
  181. package/dist/schedulers/disposed.d.ts +4 -0
  182. package/dist/schedulers/disposed.d.ts.map +1 -0
  183. package/dist/schedulers/disposed.js +14 -0
  184. package/dist/schedulers/disposed.js.map +1 -0
  185. package/dist/schedulers/duration.d.ts +8 -0
  186. package/dist/schedulers/duration.d.ts.map +1 -0
  187. package/dist/schedulers/duration.js +11 -0
  188. package/dist/schedulers/duration.js.map +1 -0
  189. package/dist/schedulers/executor-scheduler.d.ts +13 -0
  190. package/dist/schedulers/executor-scheduler.d.ts.map +1 -0
  191. package/dist/schedulers/executor-scheduler.js +43 -0
  192. package/dist/schedulers/executor-scheduler.js.map +1 -0
  193. package/dist/schedulers/immediate-scheduler.d.ts +15 -0
  194. package/dist/schedulers/immediate-scheduler.d.ts.map +1 -0
  195. package/dist/schedulers/immediate-scheduler.js +24 -0
  196. package/dist/schedulers/immediate-scheduler.js.map +1 -0
  197. package/dist/schedulers/index.d.ts +7 -0
  198. package/dist/schedulers/index.d.ts.map +1 -0
  199. package/dist/schedulers/index.js +2 -0
  200. package/dist/schedulers/interval-scheduler.d.ts +12 -0
  201. package/dist/schedulers/interval-scheduler.d.ts.map +1 -0
  202. package/dist/schedulers/interval-scheduler.js +17 -0
  203. package/dist/schedulers/interval-scheduler.js.map +1 -0
  204. package/dist/schedulers/macro-scheduler.d.ts +19 -0
  205. package/dist/schedulers/macro-scheduler.d.ts.map +1 -0
  206. package/dist/schedulers/macro-scheduler.js +30 -0
  207. package/dist/schedulers/macro-scheduler.js.map +1 -0
  208. package/dist/schedulers/microtask-scheduler.d.ts +11 -0
  209. package/dist/schedulers/microtask-scheduler.d.ts.map +1 -0
  210. package/dist/schedulers/microtask-scheduler.js +34 -0
  211. package/dist/schedulers/microtask-scheduler.js.map +1 -0
  212. package/dist/schedulers/schedulers.d.ts +39 -0
  213. package/dist/schedulers/schedulers.d.ts.map +1 -0
  214. package/dist/schedulers/schedulers.js +83 -0
  215. package/dist/schedulers/schedulers.js.map +1 -0
  216. package/dist/schedulers/timeout-scheduler.d.ts +11 -0
  217. package/dist/schedulers/timeout-scheduler.d.ts.map +1 -0
  218. package/dist/schedulers/types.d.ts +35 -0
  219. package/dist/schedulers/types.d.ts.map +1 -0
  220. package/dist/signal/signal-type.d.ts +26 -0
  221. package/dist/signal/signal-type.d.ts.map +1 -0
  222. package/dist/signal/signal-type.js +31 -0
  223. package/dist/signal/signal-type.js.map +1 -0
  224. package/dist/signal/signal.d.ts +33 -0
  225. package/dist/signal/signal.d.ts.map +1 -0
  226. package/dist/signal/signal.js +70 -0
  227. package/dist/signal/signal.js.map +1 -0
  228. package/dist/sinks/index.d.ts +7 -0
  229. package/dist/sinks/index.d.ts.map +1 -0
  230. package/dist/sinks/index.js +2 -0
  231. package/dist/sinks/many.d.ts +66 -0
  232. package/dist/sinks/many.d.ts.map +1 -0
  233. package/dist/sinks/many.js +193 -0
  234. package/dist/sinks/many.js.map +1 -0
  235. package/dist/sinks/one.d.ts +41 -0
  236. package/dist/sinks/one.d.ts.map +1 -0
  237. package/dist/sinks/one.js +144 -0
  238. package/dist/sinks/one.js.map +1 -0
  239. package/dist/sinks/specs.d.ts +25 -0
  240. package/dist/sinks/specs.d.ts.map +1 -0
  241. package/dist/sinks/specs.js +126 -0
  242. package/dist/sinks/specs.js.map +1 -0
  243. package/dist/sinks/subscribers.d.ts +16 -0
  244. package/dist/sinks/subscribers.d.ts.map +1 -0
  245. package/dist/sinks/subscribers.js +32 -0
  246. package/dist/sinks/subscribers.js.map +1 -0
  247. package/dist/sinks/types.d.ts +137 -0
  248. package/dist/sinks/types.d.ts.map +1 -0
  249. package/dist/sinks/types.js +58 -0
  250. package/dist/sinks/types.js.map +1 -0
  251. package/dist/subscription/core-subscriber.d.ts +12 -0
  252. package/dist/subscription/core-subscriber.d.ts.map +1 -0
  253. package/dist/subscription/iterable-subscription.d.ts +64 -0
  254. package/dist/subscription/iterable-subscription.d.ts.map +1 -0
  255. package/dist/subscription/iterable-subscription.js +281 -0
  256. package/dist/subscription/iterable-subscription.js.map +1 -0
  257. package/dist/subscription/reactive-streams.d.ts +8 -0
  258. package/dist/subscription/reactive-streams.d.ts.map +1 -0
  259. package/dist/subscription/reactive-streams.js +0 -0
  260. package/dist/subscription/subscriber.d.ts +17 -0
  261. package/dist/subscription/subscriber.d.ts.map +1 -0
  262. package/dist/subscription/subscription.d.ts +12 -0
  263. package/dist/subscription/subscription.d.ts.map +1 -0
  264. package/package.json +99 -33
  265. package/LICENSE.md +0 -56
  266. package/dist/index.d.mts +0 -2557
  267. package/dist/index.js.map +0 -1
  268. package/dist/index.mjs +0 -2
  269. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,74 @@
1
+ import { filterIterable, mapIterable } from "../../internal/iterable-transform.js";
2
+ import { Flux } from "../flux.js";
3
+ import { Signal } from "../../signal/signal.js";
4
+ //#region src/publisher/operators/transform.ts
5
+ Flux.prototype.map = function map(mapper) {
6
+ const source = this;
7
+ return new Flux((signal, context) => mapIterable(source.iterate(signal, context), mapper));
8
+ };
9
+ Flux.prototype.cast = function cast() {
10
+ return this;
11
+ };
12
+ Flux.prototype.filter = function filter(predicate) {
13
+ const source = this;
14
+ return new Flux((signal, context) => filterIterable(source.iterate(signal, context), predicate));
15
+ };
16
+ Flux.prototype.handle = function handle(handler) {
17
+ const source = this;
18
+ return new Flux(async function* (signal, context) {
19
+ for await (const value of source.iterate(signal, context)) {
20
+ let done = false;
21
+ let output;
22
+ handler(value, {
23
+ /** Emits one mapped value for the current source value. */
24
+ next(nextValue) {
25
+ if (done) throw new Error("SynchronousSink allows only one signal per source value");
26
+ output = nextValue;
27
+ done = true;
28
+ },
29
+ /** Suppresses emission for the current source value. */
30
+ complete() {
31
+ done = true;
32
+ },
33
+ /** Fails the sequence with the provided error. */
34
+ error(error) {
35
+ throw error;
36
+ }
37
+ });
38
+ if (done && output !== void 0) yield output;
39
+ }
40
+ });
41
+ };
42
+ Flux.prototype.materialize = function materialize() {
43
+ const source = this;
44
+ return new Flux(async function* (signal, context) {
45
+ try {
46
+ for await (const value of source.iterate(signal, context)) yield Signal.next(value);
47
+ yield Signal.complete();
48
+ } catch (error) {
49
+ yield Signal.error(error);
50
+ }
51
+ });
52
+ };
53
+ Flux.prototype.dematerialize = function dematerialize() {
54
+ const source = this;
55
+ return new Flux(async function* (signal, context) {
56
+ for await (const signalValue of source.iterate(signal, context)) if (signalValue.isOnNext()) yield signalValue.get();
57
+ else if (signalValue.isOnError()) throw signalValue.getThrowable();
58
+ else if (signalValue.isOnComplete()) return;
59
+ });
60
+ };
61
+ Flux.prototype.transform = function transform(transformer) {
62
+ return Flux.from(transformer(this));
63
+ };
64
+ Flux.prototype.transformDeferred = function transformDeferred(transformer) {
65
+ const source = this;
66
+ return Flux.defer(() => transformer(source));
67
+ };
68
+ Flux.prototype.transformDeferredContextual = function transformDeferredContextual(transformer) {
69
+ const source = this;
70
+ return new Flux((signal, context) => Flux.from(transformer(source, context.readOnly())).iterate(signal, context));
71
+ };
72
+ //#endregion
73
+
74
+ //# sourceMappingURL=transform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transform.js","names":[],"sources":["../../../src/publisher/operators/transform.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Flux, Mono and operator implementation modules.\n */\nimport type {ContextView} from \"@/context/context-view.js\";\nimport {filterIterable, mapIterable} from \"@/internal/iterable-transform.js\";\nimport {Flux} from \"@/publisher/flux.js\";\nimport type {Mapper, PublisherInput, SynchronousSink} from \"@/publisher/types.js\";\nimport {Signal} from \"@/signal/signal.js\";\n\ndeclare module \"@/publisher/flux.js\" {\n /** Transforming and materialization operators added to Flux. */\n interface Flux<T> {\n /** Maps each source value with the provided function. */\n map<R>(mapper: Mapper<T, R>): Flux<R>;\n\n /** Treats this Flux as a Flux of another TypeScript type. */\n cast<R>(): Flux<R>;\n\n /** Keeps only source values accepted by the predicate. */\n filter(predicate: (value: T) => boolean): Flux<T>;\n\n /** Handles each value with a synchronous sink that may emit, complete, or fail. */\n handle<R>(handler: (value: T, sink: SynchronousSink<R>) => void): Flux<R>;\n\n /** Converts values and terminal events into `Signal` values. */\n materialize(): Flux<Signal<T>>;\n\n /** Converts `Signal` values back into normal values and terminal events. */\n dematerialize<R>(this: Flux<Signal<R>>): Flux<R>;\n\n /** Applies a transformer to this Flux immediately and adapts its result. */\n transform<R>(transformer: (source: Flux<T>) => PublisherInput<R>): Flux<R>;\n\n /** Applies a transformer separately for each subscription. */\n transformDeferred<R>(transformer: (source: Flux<T>) => PublisherInput<R>): Flux<R>;\n\n /** Applies a transformer per subscription with access to the subscriber context. */\n transformDeferredContextual<R>(transformer: (source: Flux<T>, context: ContextView) => PublisherInput<R>): Flux<R>;\n }\n}\n\nFlux.prototype.map = function map<T, R>(this: Flux<T>, mapper: Mapper<T, R>): Flux<R> {\n const source = this;\n return new Flux((signal, context) => mapIterable(source.iterate(signal, context), mapper));\n};\n\nFlux.prototype.cast = function cast<T, R>(this: Flux<T>): Flux<R> {\n return this as unknown as Flux<R>;\n};\n\nFlux.prototype.filter = function filter<T>(this: Flux<T>, predicate: (value: T) => boolean): Flux<T> {\n const source = this;\n return new Flux((signal, context) => filterIterable(source.iterate(signal, context), predicate));\n};\n\nFlux.prototype.handle = function handle<T, R>(\n this: Flux<T>,\n handler: (value: T, sink: SynchronousSink<R>) => void\n): Flux<R> {\n const source = this;\n return new Flux(async function* (signal, context) {\n for await (const value of source.iterate(signal, context)) {\n let done = false;\n let output: R | undefined;\n const sink: SynchronousSink<R> = {\n /** Emits one mapped value for the current source value. */\n next(nextValue) {\n if (done) {\n throw new Error(\"SynchronousSink allows only one signal per source value\");\n }\n output = nextValue;\n done = true;\n },\n /** Suppresses emission for the current source value. */\n complete() {\n done = true;\n },\n /** Fails the sequence with the provided error. */\n error(error) {\n throw error;\n }\n };\n handler(value, sink);\n if (done && output !== undefined) {\n yield output;\n }\n }\n });\n};\n\nFlux.prototype.materialize = function materialize<T>(this: Flux<T>): Flux<Signal<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 Signal.next(value);\n }\n yield Signal.complete();\n } catch (error) {\n yield Signal.error(error);\n }\n });\n};\n\nFlux.prototype.dematerialize = function dematerialize<R>(this: Flux<Signal<R>>): Flux<R> {\n const source = this;\n return new Flux(async function* (signal, context) {\n for await (const signalValue of source.iterate(signal, context)) {\n if (signalValue.isOnNext()) {\n yield signalValue.get() as R;\n } else if (signalValue.isOnError()) {\n throw signalValue.getThrowable();\n } else if (signalValue.isOnComplete()) {\n return;\n }\n }\n });\n};\n\nFlux.prototype.transform = function transform<T, R>(\n this: Flux<T>,\n transformer: (source: Flux<T>) => PublisherInput<R>\n): Flux<R> {\n return Flux.from(transformer(this));\n};\n\nFlux.prototype.transformDeferred = function transformDeferred<T, R>(\n this: Flux<T>,\n transformer: (source: Flux<T>) => PublisherInput<R>\n): Flux<R> {\n const source = this;\n return Flux.defer(() => transformer(source));\n};\n\nFlux.prototype.transformDeferredContextual = function transformDeferredContextual<T, R>(\n this: Flux<T>,\n transformer: (source: Flux<T>, context: ContextView) => PublisherInput<R>\n): Flux<R> {\n const source = this;\n return new Flux((signal, context) => Flux.from(transformer(source, context.readOnly())).iterate(signal, context));\n};\n"],"mappings":";;;;AA0CA,KAAK,UAAU,MAAM,SAAS,IAAyB,QAA+B;CAClF,MAAM,SAAS;CACf,OAAO,IAAI,MAAM,QAAQ,YAAY,YAAY,OAAO,QAAQ,QAAQ,OAAO,GAAG,MAAM,CAAC;AAC7F;AAEA,KAAK,UAAU,OAAO,SAAS,OAAmC;CAC9D,OAAO;AACX;AAEA,KAAK,UAAU,SAAS,SAAS,OAAyB,WAA2C;CACjG,MAAM,SAAS;CACf,OAAO,IAAI,MAAM,QAAQ,YAAY,eAAe,OAAO,QAAQ,QAAQ,OAAO,GAAG,SAAS,CAAC;AACnG;AAEA,KAAK,UAAU,SAAS,SAAS,OAE7B,SACO;CACP,MAAM,SAAS;CACf,OAAO,IAAI,KAAK,iBAAiB,QAAQ,SAAS;EAC9C,WAAW,MAAM,SAAS,OAAO,QAAQ,QAAQ,OAAO,GAAG;GACvD,IAAI,OAAO;GACX,IAAI;GAmBJ,QAAQ,OAAO;;I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
1
+ import type { PublisherInput } from "../types.js";
2
+ import type { DurationInput, Scheduler } from "../../schedulers/types.js";
3
+ declare module "../flux.js" {
4
+ /** Advanced buffer and window operators added to Flux. */
5
+ interface Flux<T> {
6
+ /** Buffers values until `maxSize` is reached or `maxTime` elapses after the first buffered value. */
7
+ bufferTimeout(maxSize: number, maxTime: DurationInput, scheduler?: Scheduler): Flux<T[]>;
8
+ /** Buffers values until the predicate matches, optionally cutting before the matching value. */
9
+ bufferUntil(predicate: (value: T) => boolean, cutBefore?: boolean): Flux<T[]>;
10
+ /** Buffers adjacent values while the selected key stays equal. */
11
+ bufferUntilChanged<K = T>(keySelector?: (value: T) => K, comparator?: (left: K, right: K) => boolean): Flux<T[]>;
12
+ /** Buffers values between an opening signal and the corresponding closing publisher. */
13
+ bufferWhen(openings: PublisherInput<unknown>, closeSelector: (opening: unknown) => PublisherInput<unknown>): Flux<T[]>;
14
+ /** Buffers consecutive values while the predicate matches. */
15
+ bufferWhile(predicate: (value: T) => boolean): Flux<T[]>;
16
+ /** Windows values until `maxSize` is reached or `maxTime` elapses after the first value. */
17
+ windowTimeout(maxSize: number, maxTime: DurationInput, scheduler?: Scheduler): Flux<Flux<T>>;
18
+ /** Windows values until the predicate matches, optionally cutting before the matching value. */
19
+ windowUntil(predicate: (value: T) => boolean, cutBefore?: boolean): Flux<Flux<T>>;
20
+ /** Windows adjacent values while the selected key stays equal. */
21
+ windowUntilChanged<K = T>(keySelector?: (value: T) => K, comparator?: (left: K, right: K) => boolean): Flux<Flux<T>>;
22
+ /** Windows values between an opening signal and the corresponding closing publisher. */
23
+ windowWhen(openings: PublisherInput<unknown>, closeSelector: (opening: unknown) => PublisherInput<unknown>): Flux<Flux<T>>;
24
+ /** Windows consecutive values while the predicate matches. */
25
+ windowWhile(predicate: (value: T) => boolean): Flux<Flux<T>>;
26
+ }
27
+ }
28
+ //# sourceMappingURL=windowing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"windowing.d.ts","sourceRoot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I,CAAC,CAAC,CAAC,CAAC,CAAC;QAE7F,gGAAgG;QAChG,WAAW,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,EAAE,SAAS,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAElF,kEAAkE;QAClE,kBAAkB,CAAC,CAAC,GAAG,CAAC,EAAE,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAErH,wFAAwF;QACxF,UAAU,CAAC,QAAQ,EAAE,cAAc,CAAC,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,cAAc,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAE3H,8DAA8D;QAC9D,WAAW,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;KAChE;CACJ"}
@@ -0,0 +1,148 @@
1
+ import { toAsyncIterator } from "../../internal/iterable.js";
2
+ import { AsyncQueue } from "../../internal/async-queue.js";
3
+ import { Schedulers } from "../../schedulers/schedulers.js";
4
+ import { TIMEOUT, identity, raceIteratorWithTimeout } from "../helpers.js";
5
+ import { Flux } from "../flux.js";
6
+ //#region src/publisher/operators/windowing.ts
7
+ Flux.prototype.bufferTimeout = function bufferTimeout(maxSize, maxTime, scheduler = Schedulers.timeout()) {
8
+ if (!Number.isInteger(maxSize) || maxSize <= 0) throw new RangeError("bufferTimeout expects a strictly positive integer maxSize");
9
+ const source = this;
10
+ return new Flux(async function* (signal, context) {
11
+ const iterator = toAsyncIterator(source.iterate(signal, context));
12
+ let bucket = [];
13
+ try {
14
+ while (!signal.aborted) {
15
+ const result = bucket.length === 0 ? await iterator.next() : await raceIteratorWithTimeout(iterator, maxTime, scheduler, signal);
16
+ if (result === TIMEOUT) {
17
+ if (bucket.length > 0) {
18
+ yield bucket;
19
+ bucket = [];
20
+ }
21
+ continue;
22
+ }
23
+ if (result.done) break;
24
+ bucket.push(result.value);
25
+ if (bucket.length >= maxSize) {
26
+ yield bucket;
27
+ bucket = [];
28
+ }
29
+ }
30
+ if (bucket.length > 0) yield bucket;
31
+ } finally {
32
+ await iterator.return?.();
33
+ }
34
+ });
35
+ };
36
+ Flux.prototype.bufferUntil = function bufferUntil(predicate, cutBefore = false) {
37
+ const source = this;
38
+ return new Flux(async function* (signal, context) {
39
+ let bucket = [];
40
+ for await (const value of source.iterate(signal, context)) {
41
+ if (cutBefore && predicate(value)) {
42
+ if (bucket.length > 0) yield bucket;
43
+ bucket = [value];
44
+ continue;
45
+ }
46
+ bucket.push(value);
47
+ if (!cutBefore && predicate(value)) {
48
+ yield bucket;
49
+ bucket = [];
50
+ }
51
+ }
52
+ if (bucket.length > 0) yield bucket;
53
+ });
54
+ };
55
+ Flux.prototype.bufferUntilChanged = function bufferUntilChanged(keySelector = identity, comparator = Object.is) {
56
+ const source = this;
57
+ return new Flux(async function* (signal, context) {
58
+ let bucket = [];
59
+ let previousKey;
60
+ let hasKey = false;
61
+ for await (const value of source.iterate(signal, context)) {
62
+ const key = keySelector(value);
63
+ if (hasKey && !comparator(previousKey, key)) {
64
+ yield bucket;
65
+ bucket = [];
66
+ }
67
+ bucket.push(value);
68
+ previousKey = key;
69
+ hasKey = true;
70
+ }
71
+ if (bucket.length > 0) yield bucket;
72
+ });
73
+ };
74
+ Flux.prototype.bufferWhen = function bufferWhen(openings, closeSelector) {
75
+ const source = this;
76
+ return new Flux(async function* (signal, context) {
77
+ const opening = await firstOpening(openings, signal, context);
78
+ if (opening.done) return;
79
+ const closeSignal = Symbol("close");
80
+ const close = firstOpening(closeSelector(opening.value), signal, context).then(() => closeSignal);
81
+ const iterator = toAsyncIterator(source.iterate(signal, context));
82
+ const bucket = [];
83
+ try {
84
+ while (!signal.aborted) {
85
+ const result = await Promise.race([iterator.next(), close]);
86
+ if (result === closeSignal || result.done) break;
87
+ bucket.push(result.value);
88
+ }
89
+ } finally {
90
+ await iterator.return?.();
91
+ }
92
+ if (bucket.length > 0) yield bucket;
93
+ });
94
+ };
95
+ Flux.prototype.bufferWhile = function bufferWhile(predicate) {
96
+ const source = this;
97
+ return new Flux(async function* (signal, context) {
98
+ let bucket = [];
99
+ for await (const value of source.iterate(signal, context)) if (predicate(value)) bucket.push(value);
100
+ else if (bucket.length > 0) {
101
+ yield bucket;
102
+ bucket = [];
103
+ }
104
+ if (bucket.length > 0) yield bucket;
105
+ });
106
+ };
107
+ Flux.prototype.windowTimeout = function windowTimeout(maxSize, maxTime, scheduler) {
108
+ return windowsFromBuffers(this.bufferTimeout(maxSize, maxTime, scheduler));
109
+ };
110
+ Flux.prototype.windowUntil = function windowUntil(predicate, cutBefore) {
111
+ return windowsFromBuffers(this.bufferUntil(predicate, cutBefore));
112
+ };
113
+ Flux.prototype.windowUntilChanged = function windowUntilChanged(keySelector, comparator) {
114
+ return windowsFromBuffers(this.bufferUntilChanged(keySelector, comparator));
115
+ };
116
+ Flux.prototype.windowWhen = function windowWhen(openings, closeSelector) {
117
+ return windowsFromBuffers(this.bufferWhen(openings, closeSelector));
118
+ };
119
+ Flux.prototype.windowWhile = function windowWhile(predicate) {
120
+ return windowsFromBuffers(this.bufferWhile(predicate));
121
+ };
122
+ /** Resolves the first opening or closing signal from a publisher input. */
123
+ async function firstOpening(source, signal, context) {
124
+ const iterator = toAsyncIterator(Flux.from(source).iterate(signal, context));
125
+ try {
126
+ return await iterator.next();
127
+ } finally {
128
+ await iterator.return?.();
129
+ }
130
+ }
131
+ /** Converts buffered arrays into window Flux values without yielding thenable publishers from an async generator. */
132
+ function windowsFromBuffers(buffers) {
133
+ return new Flux((signal, context) => {
134
+ const queue = new AsyncQueue(signal);
135
+ (async () => {
136
+ try {
137
+ for await (const values of buffers.iterate(signal, context)) queue.push(Flux.fromIterable(values));
138
+ queue.complete();
139
+ } catch (error) {
140
+ queue.error(error);
141
+ }
142
+ })();
143
+ return queue;
144
+ });
145
+ }
146
+ //#endregion
147
+
148
+ //# sourceMappingURL=windowing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"windowing.js","names":[],"sources":["../../../src/publisher/operators/windowing.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Advanced Reactor buffer and window compatibility operators for Flux.\n */\nimport {Context} from \"@/context/context.js\";\nimport {AsyncQueue} from \"@/internal/async-queue.js\";\nimport {toAsyncIterator} from \"@/internal/iterable.js\";\nimport {Flux} from \"@/publisher/flux.js\";\nimport {identity, raceIteratorWithTimeout, TIMEOUT} 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\";\n\ndeclare module \"@/publisher/flux.js\" {\n /** Advanced buffer and window operators added to Flux. */\n interface Flux<T> {\n /** Buffers values until `maxSize` is reached or `maxTime` elapses after the first buffered value. */\n bufferTimeout(maxSize: number, maxTime: DurationInput, scheduler?: Scheduler): Flux<T[]>;\n\n /** Buffers values until the predicate matches, optionally cutting before the matching value. */\n bufferUntil(predicate: (value: T) => boolean, cutBefore?: boolean): Flux<T[]>;\n\n /** Buffers adjacent values while the selected key stays equal. */\n bufferUntilChanged<K = T>(keySelector?: (value: T) => K, comparator?: (left: K, right: K) => boolean): Flux<T[]>;\n\n /** Buffers values between an opening signal and the corresponding closing publisher. */\n bufferWhen(openings: PublisherInput<unknown>, closeSelector: (opening: unknown) => PublisherInput<unknown>): Flux<T[]>;\n\n /** Buffers consecutive values while the predicate matches. */\n bufferWhile(predicate: (value: T) => boolean): Flux<T[]>;\n\n /** Windows values until `maxSize` is reached or `maxTime` elapses after the first value. */\n windowTimeout(maxSize: number, maxTime: DurationInput, scheduler?: Scheduler): Flux<Flux<T>>;\n\n /** Windows values until the predicate matches, optionally cutting before the matching value. */\n windowUntil(predicate: (value: T) => boolean, cutBefore?: boolean): Flux<Flux<T>>;\n\n /** Windows adjacent values while the selected key stays equal. */\n windowUntilChanged<K = T>(keySelector?: (value: T) => K, comparator?: (left: K, right: K) => boolean): Flux<Flux<T>>;\n\n /** Windows values between an opening signal and the corresponding closing publisher. */\n windowWhen(openings: PublisherInput<unknown>, closeSelector: (opening: unknown) => PublisherInput<unknown>): Flux<Flux<T>>;\n\n /** Windows consecutive values while the predicate matches. */\n windowWhile(predicate: (value: T) => boolean): Flux<Flux<T>>;\n }\n}\n\nFlux.prototype.bufferTimeout = function bufferTimeout<T>(\n this: Flux<T>,\n maxSize: number,\n maxTime: DurationInput,\n scheduler: Scheduler = Schedulers.timeout()\n): Flux<T[]> {\n if (!Number.isInteger(maxSize) || maxSize <= 0) {\n throw new RangeError(\"bufferTimeout expects a strictly positive integer maxSize\");\n }\n const source = this;\n return new Flux(async function* (signal, context) {\n const iterator = toAsyncIterator(source.iterate(signal, context));\n let bucket: T[] = [];\n try {\n while (!signal.aborted) {\n const result =\n bucket.length === 0\n ? await iterator.next()\n : await raceIteratorWithTimeout(iterator, maxTime, scheduler, signal);\n if (result === TIMEOUT) {\n if (bucket.length > 0) {\n yield bucket;\n bucket = [];\n }\n continue;\n }\n if (result.done) {\n break;\n }\n bucket.push(result.value);\n if (bucket.length >= maxSize) {\n yield bucket;\n bucket = [];\n }\n }\n if (bucket.length > 0) {\n yield bucket;\n }\n } finally {\n await iterator.return?.();\n }\n });\n};\n\nFlux.prototype.bufferUntil = function bufferUntil<T>(\n this: Flux<T>,\n predicate: (value: T) => boolean,\n cutBefore = false\n): Flux<T[]> {\n const source = this;\n return new Flux(async function* (signal, context) {\n let bucket: T[] = [];\n for await (const value of source.iterate(signal, context)) {\n if (cutBefore && predicate(value)) {\n if (bucket.length > 0) {\n yield bucket;\n }\n bucket = [value];\n continue;\n }\n bucket.push(value);\n if (!cutBefore && predicate(value)) {\n yield bucket;\n bucket = [];\n }\n }\n if (bucket.length > 0) {\n yield bucket;\n }\n });\n};\n\nFlux.prototype.bufferUntilChanged = function bufferUntilChanged<T, K = T>(\n this: Flux<T>,\n keySelector: (value: T) => K = identity as (value: T) => K,\n comparator: (left: K, right: K) => boolean = Object.is\n): Flux<T[]> {\n const source = this;\n return new Flux(async function* (signal, context) {\n let bucket: T[] = [];\n let previousKey: K | undefined;\n let hasKey = false;\n for await (const value of source.iterate(signal, context)) {\n const key = keySelector(value);\n if (hasKey && !comparator(previousKey as K, key)) {\n yield bucket;\n bucket = [];\n }\n bucket.push(value);\n previousKey = key;\n hasKey = true;\n }\n if (bucket.length > 0) {\n yield bucket;\n }\n });\n};\n\nFlux.prototype.bufferWhen = function bufferWhen<T>(\n this: Flux<T>,\n openings: PublisherInput<unknown>,\n closeSelector: (opening: unknown) => PublisherInput<unknown>\n): Flux<T[]> {\n const source = this;\n return new Flux(async function* (signal, context) {\n const opening = await firstOpening(openings, signal, context);\n if (opening.done) {\n return;\n }\n const closeSignal = Symbol(\"close\");\n const close: Promise<typeof closeSignal> = firstOpening(closeSelector(opening.value), signal, context).then(() => closeSignal);\n const iterator = toAsyncIterator(source.iterate(signal, context));\n const bucket: T[] = [];\n try {\n while (!signal.aborted) {\n const result = await Promise.race<IteratorResult<T> | typeof closeSignal>([iterator.next(), close]);\n if (result === closeSignal || result.done) {\n break;\n }\n bucket.push(result.value);\n }\n } finally {\n await iterator.return?.();\n }\n if (bucket.length > 0) {\n yield bucket;\n }\n });\n};\n\nFlux.prototype.bufferWhile = function bufferWhile<T>(this: Flux<T>, predicate: (value: T) => boolean): Flux<T[]> {\n const source = this;\n return new Flux(async function* (signal, context) {\n let bucket: T[] = [];\n for await (const value of source.iterate(signal, context)) {\n if (predicate(value)) {\n bucket.push(value);\n } else if (bucket.length > 0) {\n yield bucket;\n bucket = [];\n }\n }\n if (bucket.length > 0) {\n yield bucket;\n }\n });\n};\n\nFlux.prototype.windowTimeout = function windowTimeout<T>(\n this: Flux<T>,\n maxSize: number,\n maxTime: DurationInput,\n scheduler?: Scheduler\n): Flux<Flux<T>> {\n return windowsFromBuffers(this.bufferTimeout(maxSize, maxTime, scheduler));\n};\n\nFlux.prototype.windowUntil = function windowUntil<T>(\n this: Flux<T>,\n predicate: (value: T) => boolean,\n cutBefore?: boolean\n): Flux<Flux<T>> {\n return windowsFromBuffers(this.bufferUntil(predicate, cutBefore));\n};\n\nFlux.prototype.windowUntilChanged = function windowUntilChanged<T, K = T>(\n this: Flux<T>,\n keySelector?: (value: T) => K,\n comparator?: (left: K, right: K) => boolean\n): Flux<Flux<T>> {\n return windowsFromBuffers(this.bufferUntilChanged(keySelector, comparator));\n};\n\nFlux.prototype.windowWhen = function windowWhen<T>(\n this: Flux<T>,\n openings: PublisherInput<unknown>,\n closeSelector: (opening: unknown) => PublisherInput<unknown>\n): Flux<Flux<T>> {\n return windowsFromBuffers(this.bufferWhen(openings, closeSelector));\n};\n\nFlux.prototype.windowWhile = function windowWhile<T>(this: Flux<T>, predicate: (value: T) => boolean): Flux<Flux<T>> {\n return windowsFromBuffers(this.bufferWhile(predicate));\n};\n\n/** Resolves the first opening or closing signal from a publisher input. */\nasync function firstOpening(source: PublisherInput<unknown>, signal: AbortSignal, context: Context): Promise<IteratorResult<unknown>> {\n const iterator = toAsyncIterator(Flux.from(source).iterate(signal, context));\n try {\n return await iterator.next();\n } finally {\n await iterator.return?.();\n }\n}\n\n/** Converts buffered arrays into window Flux values without yielding thenable publishers from an async generator. */\nfunction windowsFromBuffers<T>(buffers: Flux<T[]>): Flux<Flux<T>> {\n return new Flux((signal, context) => {\n const queue = new AsyncQueue<Flux<T>>(signal);\n void (async () => {\n try {\n for await (const values of buffers.iterate(signal, context)) {\n queue.push(Flux.fromIterable(values));\n }\n queue.complete();\n } catch (error) {\n queue.error(error);\n }\n })();\n return queue;\n });\n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ExC,MAAM,SAAS;GACnB,SAAS,OAAO;IACZ,MAAM,MAAM,KAAK;GACrB;EACJ,EAAA,CAAG;EACH,OAAO;CACX,CAAC;AACL"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * Publisher contract used by Flux, Mono and Reactive Streams adapters.
4
+ */
5
+ import type { Subscriber } from "../subscription/subscriber.js";
6
+ /** Reactive Streams publisher that can be subscribed to by a subscriber. */
7
+ export interface Publisher<T> {
8
+ /** Subscribes the given subscriber to this publisher. */
9
+ subscribe(subscriber: Subscriber<T>): void;
10
+ }
11
+ //# sourceMappingURL=publisher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publisher.d.ts","sourceRoot":"","sources":["../../src/publisher/publisher.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,8BAA8B,CAAC;AAE7D,4EAA4E;AAC5E,MAAM,WAAW,SAAS,CAAC,CAAC;IACxB,yDAAyD;IACzD,SAAS,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CAC9C"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * Flux, Mono and operator implementation modules.
4
+ */
5
+ import type { Publisher } from "./publisher.js";
6
+ import type { Context } from "../context/context.js";
7
+ import type { AnyIterable } from "../internal/iterable.js";
8
+ /** Lazy factory backing Flux and Mono sources. */
9
+ export type SourceFactory<T> = (signal: AbortSignal, context: Context) => AnyIterable<T>;
10
+ /** Callback that consumes a value. */
11
+ export type Consumer<T> = (value: T) => void;
12
+ /** Predicate callback used by filtering operators. */
13
+ export type Predicate<T> = (value: T) => boolean;
14
+ /** Mapping callback used by transformation operators. */
15
+ export type Mapper<T, R> = (value: T) => R;
16
+ /** Input type accepted by publisher adaptation methods. */
17
+ export type PublisherInput<T> = Publisher<T> | Iterable<T> | AsyncIterable<T> | PromiseLike<T>;
18
+ /** Callback used by `Flux.create`. */
19
+ export type FluxSinkCallback<T> = (sink: FluxSink<T>) => void;
20
+ /** Callback used by `Mono.create`. */
21
+ export type MonoSinkCallback<T> = (sink: MonoSink<T>) => void;
22
+ /** Imperative sink exposed to `Flux.create` callbacks. */
23
+ export interface FluxSink<T> {
24
+ /** Pushes one value to the created Flux. */
25
+ next(value: T): void;
26
+ /** Terminates the sequence with an error. */
27
+ error(error: unknown): void;
28
+ /** Completes the created Flux successfully. */
29
+ complete(): void;
30
+ /** Registers a callback invoked on cancellation. */
31
+ onCancel(callback: () => void): FluxSink<T>;
32
+ /** Returns true when the subscriber cancelled the sequence. */
33
+ isCancelled(): boolean;
34
+ }
35
+ /** Imperative sink exposed to `Mono.create` callbacks. */
36
+ export interface MonoSink<T> extends FluxSink<T> {
37
+ /** Completes the Mono with an optional value. */
38
+ success(value?: T): void;
39
+ /** Registers a callback invoked on cancellation. */
40
+ onCancel(callback: () => void): MonoSink<T>;
41
+ }
42
+ /** Synchronous one-signal sink used by handle operators. */
43
+ export interface SynchronousSink<T> {
44
+ /** Emits one value for the currently handled input. */
45
+ next(value: T): void;
46
+ /** Completes without emitting a value for the current input. */
47
+ complete(): void;
48
+ /** Fails the sequence with an error. */
49
+ error(error: unknown): void;
50
+ }
51
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/publisher/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,0BAA0B,CAAC;AACxD,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,wBAAwB,CAAC;AAExD,kDAAkD;AAClD,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC;AACzF,sCAAsC;AACtC,MA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K,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;IAEzB,oDAAoD;IACpD,QAAQ,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;CAC/C;AAED,4DAA4D;AAC5D,MAAM,WAAW,eAAe,CAAC,CAAC;IAC9B,uDAAuD;IACvD,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IAErB,gEAAgE;IAChE,QAAQ,IAAI,IAAI,CAAC;IAEjB,wCAAwC;IACxC,KAAK,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;CAC/B"}
@@ -0,0 +1,11 @@
1
+ import type { Disposable } from "../core/types.js";
2
+ import { BaseScheduler } from "./base-scheduler.js";
3
+ import type { DurationInput } from "./types.js";
4
+ /** Scheduler that queues zero-delay tasks with `requestAnimationFrame` when available. */
5
+ export declare class AnimationFrameScheduler extends BaseScheduler {
6
+ /** Creates an animation-frame scheduler. */
7
+ constructor(name?: string);
8
+ /** Schedules a task with `requestAnimationFrame`, falling back to timeout scheduling. */
9
+ schedule(task: () => void, delay?: DurationInput): Disposable;
10
+ }
11
+ //# sourceMappingURL=animation-frame-scheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"animation-frame-scheduler.d.ts","sourceRoot":"","sources":["../../src/schedulers/animation-frame-scheduler.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAC,aAAa,EAAC,MAAM,gCAAgC,CAAC;AAC7D,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAC;AAEzD,0FAA0F;AAC1F,qBAAa,uBAAwB,SAAQ,aAAa;IACtD,4CAA4C;IAC5C,YAAmB,IAAI,SAAmB,EAEzC;IAED,yFAAyF;IAClF,QAAQ,CAAC,IAAI,EAAE,MAAM,IAAI,EAAE,KAAK,CAAC,EAAE,aAAa,GAAG,UAAU,CAenE;CACJ"}
@@ -0,0 +1,30 @@
1
+ import { BooleanDisposable } from "../core/boolean-disposable.js";
2
+ import { toMillis } from "./duration.js";
3
+ import { BaseScheduler } from "./base-scheduler.js";
4
+ //#region src/schedulers/animation-frame-scheduler.ts
5
+ /**
6
+ * @packageDocumentation
7
+ * Browser scheduler implementations and contracts.
8
+ */
9
+ /** Scheduler that queues zero-delay tasks with `requestAnimationFrame` when available. */
10
+ var AnimationFrameScheduler = class extends BaseScheduler {
11
+ /** Creates an animation-frame scheduler. */
12
+ constructor(name = "animationFrame") {
13
+ super(name);
14
+ }
15
+ /** Schedules a task with `requestAnimationFrame`, falling back to timeout scheduling. */
16
+ schedule(task, delay) {
17
+ const disposedDisposable = this.disposedIfNeeded();
18
+ if (disposedDisposable) return disposedDisposable;
19
+ const delayMs = toMillis(delay);
20
+ if (delayMs > 0 || typeof requestAnimationFrame !== "function") return this.scheduleTimeout(task, delayMs);
21
+ const id = requestAnimationFrame(() => {
22
+ if (!this.isDisposed()) task();
23
+ });
24
+ return new BooleanDisposable(() => cancelAnimationFrame(id));
25
+ }
26
+ };
27
+ //#endregion
28
+ export { AnimationFrameScheduler };
29
+
30
+ //# sourceMappingURL=animation-frame-scheduler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"animation-frame-scheduler.js","names":[],"sources":["../../src/schedulers/animation-frame-scheduler.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Browser scheduler implementations and contracts.\n */\nimport {BooleanDisposable} from \"@/core/boolean-disposable.js\";\nimport type {Disposable} from \"@/core/types.js\";\nimport {toMillis} from \"@/schedulers/duration.js\";\nimport {BaseScheduler} from \"@/schedulers/base-scheduler.js\";\nimport type {DurationInput} from \"@/schedulers/types.js\";\n\n/** Scheduler that queues zero-delay tasks with `requestAnimationFrame` when available. */\nexport class AnimationFrameScheduler extends BaseScheduler {\n /** Creates an animation-frame scheduler. */\n public constructor(name = \"animationFrame\") {\n super(name);\n }\n\n /** Schedules a task with `requestAnimationFrame`, falling back to timeout scheduling. */\n public schedule(task: () => void, delay?: DurationInput): Disposable {\n const disposedDisposable = this.disposedIfNeeded();\n if (disposedDisposable) {\n return disposedDisposable;\n }\n const delayMs = toMillis(delay);\n if (delayMs > 0 || typeof requestAnimationFrame !== \"function\") {\n return this.scheduleTimeout(task, delayMs);\n }\n const id = requestAnimationFrame(() => {\n if (!this.isDisposed()) {\n task();\n }\n });\n return new BooleanDisposable(() => cancelAnimationFrame(id));\n }\n}\n"],"mappings":";;;;;;;;;AAWA,IAAa,0BAAb,cAA6C,cAAc;;CAEvD,YAAmB,OAAO,kBAAkB;EACxC,MAAM,IAAI;CACd;;CAGA,SAAgB,MAAkB,OAAmC;EACjE,MAAM,qBAAqB,KAAK,iBAAiB;EACjD,IAAI,oBACA,OAAO;EAEX,MAAM,UAAU,SAAS,KAAK;EAC9B,IAAI,UAAU,KAAK,OAAO,0BAA0B,YAChD,OAAO,KAAK,gBAAgB,MAAM,OAAO;EAE7C,MAAM,KAAK,4BAA4B;GACnC,IAAI,CAAC,KAAK,WAAW,GACjB,KAAK;EAEb,CAAC;EACD,OAAO,IAAI,wBAAwB,qBAAqB,EAAE,CAAC;CAC/D;AACJ"}
@@ -0,0 +1,28 @@
1
+ import type { Disposable } from "../core/types.js";
2
+ import type { DurationInput, Scheduler, SchedulerWorker } from "./types.js";
3
+ /** Base implementation for browser schedulers that share lifecycle behavior. */
4
+ export declare abstract class BaseScheduler implements Scheduler {
5
+ /** Human-readable scheduler name. */
6
+ readonly name: string;
7
+ /** Tracks whether this scheduler has been disposed. */
8
+ private disposed;
9
+ /** Creates a scheduler base with the provided name. */
10
+ constructor(name: string);
11
+ /** Returns the current wall-clock time in milliseconds. */
12
+ now(): number;
13
+ /** Schedules a single task, optionally after a delay. */
14
+ abstract schedule(task: () => void, delay?: DurationInput): Disposable;
15
+ /** Schedules a periodic task using this scheduler for the first execution. */
16
+ schedulePeriodically(task: () => void, initialDelay?: DurationInput, period?: DurationInput): Disposable;
17
+ /** Creates a worker that tracks tasks for grouped disposal. */
18
+ createWorker(): SchedulerWorker;
19
+ /** Marks this scheduler as disposed. */
20
+ dispose(): void;
21
+ /** Returns true when this scheduler is disposed. */
22
+ isDisposed(): boolean;
23
+ /** Returns an already-disposed disposable when this scheduler is disposed. */
24
+ protected disposedIfNeeded(): Disposable | undefined;
25
+ /** Schedules a timeout-backed task with disposal and disposed-state checks. */
26
+ protected scheduleTimeout(task: () => void, delayMs?: number): Disposable;
27
+ }
28
+ //# sourceMappingURL=base-scheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-scheduler.d.ts","sourceRoot":"","sources":["../../src/schedulers/base-scheduler.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAIhD,OAAO,KAAK,EAAC,aAAa,EAAE,SAAS,EAAE,eAAe,EAAC,MAAM,uBAAuB,CAAC;AAErF,gFAAgF;AAChF,8BAAsB,aAAc,YAAW,SAAS;IACpD,qCAAqC;IACrC,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,uDAAuD;IACvD,OAAO,CAAC,QAAQ,CAAS;IAEzB,uDAAuD;IACvD,YAAmB,IAAI,EAAE,MAAM,EAE9B;IAED,2DAA2D;IACpD,GAAG,IAAI,MAAM,CAEnB;IAED,yDAAyD;IACzD,SAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,IAAI,EAAE,KAAK,CAAC,EAAE,aAAa,GAAG,UAAU,CAAC;IAE9E,8EAA8E;IACvE,oBAAoB,CAAC,IAAI,EAAE,MAAM,IAAI,EAAE,YAAY,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,UAAU,CAmB9G;IAED,+DAA+D;IACxD,YAAY,IAAI,eAAe,CAErC;IAED,wCAAwC;IACjC,OAAO,IAAI,IAAI,CAErB;IAED,oDAAoD;IAC7C,UAAU,IAAI,OAAO,CAE3B;IAED,8EAA8E;IAC9E,SAAS,CAAC,gBAAgB,IAAI,UAAU,GAAG,SAAS,CAEnD;IAED,+EAA+E;IAC/E,SAAS,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,IAAI,EAAE,OAAO,SAAI,GAAG,UAAU,CAUnE;CACJ"}
@@ -0,0 +1,77 @@
1
+ import _defineProperty from "../_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/defineProperty.js";
2
+ import { BooleanDisposable } from "../core/boolean-disposable.js";
3
+ import { toMillis } from "./duration.js";
4
+ import { CompositeDisposable } from "../core/composite-disposable.js";
5
+ import { disposed } from "./disposed.js";
6
+ import { BasicWorker } from "./basic-worker.js";
7
+ //#region src/schedulers/base-scheduler.ts
8
+ /**
9
+ * @packageDocumentation
10
+ * Browser scheduler implementations and contracts.
11
+ */
12
+ /** Base implementation for browser schedulers that share lifecycle behavior. */
13
+ var BaseScheduler = class {
14
+ /** Creates a scheduler base with the provided name. */
15
+ constructor(name) {
16
+ _defineProperty(
17
+ this,
18
+ /** Human-readable scheduler name. */
19
+ "name",
20
+ void 0
21
+ );
22
+ _defineProperty(
23
+ this,
24
+ /** Tracks whether this scheduler has been disposed. */
25
+ "disposed",
26
+ false
27
+ );
28
+ this.name = name;
29
+ }
30
+ /** Returns the current wall-clock time in milliseconds. */
31
+ now() {
32
+ return Date.now();
33
+ }
34
+ /** Schedules a periodic task using this scheduler for the first execution. */
35
+ schedulePeriodically(task, initialDelay, period) {
36
+ if (this.disposed) return disposed();
37
+ const composite = new CompositeDisposable();
38
+ const start = this.schedule(() => {
39
+ if (composite.isDisposed()) return;
40
+ task();
41
+ const id = setInterval(() => {
42
+ if (!composite.isDisposed() && !this.disposed) task();
43
+ }, Math.max(1, toMillis(period)));
44
+ composite.add(new BooleanDisposable(() => clearInterval(id)));
45
+ }, initialDelay);
46
+ composite.add(start);
47
+ return composite;
48
+ }
49
+ /** Creates a worker that tracks tasks for grouped disposal. */
50
+ createWorker() {
51
+ return new BasicWorker(this);
52
+ }
53
+ /** Marks this scheduler as disposed. */
54
+ dispose() {
55
+ this.disposed = true;
56
+ }
57
+ /** Returns true when this scheduler is disposed. */
58
+ isDisposed() {
59
+ return this.disposed;
60
+ }
61
+ /** Returns an already-disposed disposable when this scheduler is disposed. */
62
+ disposedIfNeeded() {
63
+ return this.disposed ? disposed() : void 0;
64
+ }
65
+ /** Schedules a timeout-backed task with disposal and disposed-state checks. */
66
+ scheduleTimeout(task, delayMs = 0) {
67
+ if (this.disposed) return disposed();
68
+ const id = setTimeout(() => {
69
+ if (!this.disposed) task();
70
+ }, delayMs);
71
+ return new BooleanDisposable(() => clearTimeout(id));
72
+ }
73
+ };
74
+ //#endregion
75
+ export { BaseScheduler };
76
+
77
+ //# sourceMappingURL=base-scheduler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-scheduler.js","names":[],"sources":["../../src/schedulers/base-scheduler.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Browser scheduler implementations and contracts.\n */\nimport {BooleanDisposable} from \"@/core/boolean-disposable.js\";\nimport {CompositeDisposable} from \"@/core/composite-disposable.js\";\nimport type {Disposable} from \"@/core/types.js\";\nimport {BasicWorker} from \"@/schedulers/basic-worker.js\";\nimport {disposed} from \"@/schedulers/disposed.js\";\nimport {toMillis} from \"@/schedulers/duration.js\";\nimport type {DurationInput, Scheduler, SchedulerWorker} from \"@/schedulers/types.js\";\n\n/** Base implementation for browser schedulers that share lifecycle behavior. */\nexport abstract class BaseScheduler implements Scheduler {\n /** Human-readable scheduler name. */\n public readonly name: string;\n /** Tracks whether this scheduler has been disposed. */\n private disposed = false;\n\n /** Creates a scheduler base with the provided name. */\n public constructor(name: string) {\n this.name = name;\n }\n\n /** Returns the current wall-clock time in milliseconds. */\n public now(): number {\n return Date.now();\n }\n\n /** Schedules a single task, optionally after a delay. */\n public abstract schedule(task: () => void, delay?: DurationInput): Disposable;\n\n /** Schedules a periodic task using this scheduler for the first execution. */\n public schedulePeriodically(task: () => void, initialDelay?: DurationInput, period?: DurationInput): Disposable {\n if (this.disposed) {\n return disposed();\n }\n const composite = new CompositeDisposable();\n const start = this.schedule(() => {\n if (composite.isDisposed()) {\n return;\n }\n task();\n const id = setInterval(() => {\n if (!composite.isDisposed() && !this.disposed) {\n task();\n }\n }, Math.max(1, toMillis(period)));\n composite.add(new BooleanDisposable(() => clearInterval(id)));\n }, initialDelay);\n composite.add(start);\n return composite;\n }\n\n /** Creates a worker that tracks tasks for grouped disposal. */\n public createWorker(): SchedulerWorker {\n return new BasicWorker(this);\n }\n\n /** Marks this scheduler as disposed. */\n public dispose(): void {\n this.disposed = true;\n }\n\n /** Returns true when this scheduler is disposed. */\n public isDisposed(): boolean {\n return this.disposed;\n }\n\n /** Returns an already-disposed disposable when this scheduler is disposed. */\n protected disposedIfNeeded(): Disposable | undefined {\n return this.disposed ? disposed() : undefined;\n }\n\n /** Schedules a timeout-backed task with disposal and disposed-state checks. */\n protected scheduleTimeout(task: () => void, delayMs = 0): Disposable {\n if (this.disposed) {\n return disposed();\n }\n const id = setTimeout(() => {\n if (!this.disposed) {\n task();\n }\n }, delayMs);\n return new BooleanDisposable(() => clearTimeout(id));\n }\n}\n"],"mappings":";;;;;;;;;;;;AAaA,IAAsB,gBAAtB,MAAyD;;CAOrD,YAAmB,MAAc;;;;GALjC;;;;;;GAEA;GAAmB;;EAIf,KAAK,OAAO;CAChB;;CAGA,MAAqB;EACjB,OAAO,KAAK,IAAI;CACpB;;CAMA,qBAA4B,MAAkB,cAA8B,QAAoC;EAC5G,IAAI,KAAK,UACL,OAAO,SAAS;EAEpB,MAAM,YAAY,IAAI,oBAAoB;EAC1C,MAAM,QAAQ,KAAK,eAAe;GAC9B,IAAI,UAAU,WAAW,GACrB;GAEJ,KAAK;GACL,MAAM,KAAK,kBAAkB;IACzB,IAAI,CAAC,UAAU,WAAW,KAAK,CAAC,KAAK,UACjC,KAAK;GAEb,GAAG,KAAK,IAAI,GAAG,SAAS,MAAM,CAAC,CAAC;GAChC,UAAU,IAAI,IAAI,wBAAwB,cAAc,EAAE,CAAC,CAAC;EAChE,GAAG,YAAY;EACf,UAAU,IAAI,KAAK;EACnB,OAAO;CACX;;CAGA,eAAuC;EACnC,OAAO,IAAI,YAAY,IAAI;CAC/B;;CAGA,UAAuB;EACnB,KAAK,WAAW;CACpB;;CAGA,aAA6B;EACzB,OAAO,KAAK;CAChB;;CAGA,mBAAqD;EACjD,OAAO,KAAK,WAAW,SAAS,IAAI;CACxC;;CAGA,gBAA0B,MAAkB,UAAU,GAAe;EACjE,IAAI,KAAK,UACL,OAAO,SAAS;EAEpB,MAAM,KAAK,iBAAiB;GACxB,IAAI,CAAC,KAAK,UACN,KAAK;EAEb,GAAG,OAAO;EACV,OAAO,IAAI,wBAAwB,aAAa,EAAE,CAAC;CACvD;AACJ"}
@@ -0,0 +1,22 @@
1
+ import type { Disposable } from "../core/types.js";
2
+ import type { DurationInput, Scheduler, SchedulerWorker } from "./types.js";
3
+ /** Scheduler worker that tracks child tasks in a composite disposable. */
4
+ export declare class BasicWorker implements SchedulerWorker {
5
+ /** Tasks currently owned by this worker, allocated only after a task needs tracking. */
6
+ private tasks;
7
+ /** Tracks whether this worker has been disposed. */
8
+ private disposed;
9
+ /** Scheduler used to create tracked tasks. */
10
+ private readonly scheduler;
11
+ /** Creates a worker backed by the provided scheduler. */
12
+ constructor(scheduler: Scheduler);
13
+ /** Schedules a task and tracks it for disposal. */
14
+ schedule(task: () => void, delay?: DurationInput): Disposable;
15
+ /** Schedules a periodic task and tracks it for disposal. */
16
+ schedulePeriodically(task: () => void, initialDelay?: DurationInput, period?: DurationInput): Disposable;
17
+ /** Disposes all tasks scheduled through this worker. */
18
+ dispose(): void;
19
+ /** Returns true after this worker has been disposed. */
20
+ isDisposed(): boolean;
21
+ }
22
+ //# sourceMappingURL=basic-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basic-worker.d.ts","sourceRoot":"","sources":["../../src/schedulers/basic-worker.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAC,aAAa,EAAE,SAAS,EAAE,eAAe,EAAC,MAAM,uBAAuB,CAAC;AAGrF,0EAA0E;AAC1E,qBAAa,WAAY,YAAW,eAAe;IAC/C,wFAAwF;IACxF,OAAO,CAAC,KAAK,CAAkC;IAC/C,oDAAoD;IACpD,OAAO,CAAC,QAAQ,CAAS;IACzB,8CAA8C;IAC9C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;IAEtC,yDAAyD;IACzD,YAAmB,SAAS,EAAE,SAAS,EAEtC;IAED,mDAAmD;IAC5C,QAAQ,CAAC,IAAI,EAAE,MAAM,IAAI,EAAE,KAAK,CAAC,EAAE,aAAa,GAAG,UAAU,CAqBnE;IAED,4DAA4D;IACrD,oBAAoB,CAAC,IAAI,EAAE,MAAM,IAAI,EAAE,YAAY,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,UAAU,CAW9G;IAED,wDAAwD;IACjD,OAAO,IAAI,IAAI,CAOrB;IAED,wDAAwD;IACjD,UAAU,IAAI,OAAO,CAE3B;CACJ"}