@okikio/observables 1.0.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -280,7 +280,7 @@ Observable.of(1, 2, 3); // From values
280
280
  Observable.from(fetch("/api/data")); // From promises/iterables
281
281
  ```
282
282
 
283
- ### Operators (19+ included)
283
+ ### Operators (including combination, conditional, and recovery helpers)
284
284
 
285
285
  ```ts
286
286
  import { debounce, filter, map, pipe, switchMap } from "@okikio/observables";
@@ -295,6 +295,15 @@ pipe(
295
295
  );
296
296
  ```
297
297
 
298
+ The built-in operator set covers the common array-like transforms plus the
299
+ stream-specific coordination helpers you usually reach for next:
300
+
301
+ - `map`, `filter`, `scan`, `take`, `drop`
302
+ - `find`, `findIndex`, `first`, `elementAt`
303
+ - `mergeMap`, `concatMap`, `switchMap`
304
+ - `withLatestFrom`, `combineLatestWith`, `zipWith`, `raceWith`
305
+ - `changed`, `unique`, `catchErrors`, `ignoreErrors`
306
+
298
307
  ### EventBus & EventDispatcher
299
308
 
300
309
  ```ts
@@ -448,6 +457,103 @@ function movingAverage(windowSize: number) {
448
457
  }
449
458
  ```
450
459
 
460
+ ### Native Stream and RxJS Interop
461
+
462
+ The library stays on Web Streams internally, but you can still bring in
463
+ platform transforms and foreign operator ecosystems when that is the cheapest
464
+ way to solve a problem.
465
+
466
+ If you already have a readable/writable pair such as `CompressionStream`, use
467
+ `fromStreamPair()` to treat it like a normal operator:
468
+
469
+ ```ts
470
+ import {
471
+ fromStreamPair,
472
+ Observable,
473
+ pipe,
474
+ } from "@okikio/observables";
475
+
476
+ const gzip = fromStreamPair<Uint8Array, Uint8Array>(
477
+ () => new CompressionStream("gzip"),
478
+ );
479
+
480
+ const compressed = pipe(
481
+ Observable.of(new TextEncoder().encode("hello world")),
482
+ gzip,
483
+ );
484
+ ```
485
+
486
+ If you want to reuse RxJS operator functions, `fromObservableOperator()` wraps
487
+ that operator shape and keeps the rest of your pipeline in this library.
488
+
489
+ That helper is intentionally a little wider than `Observable.from()`. The core
490
+ `Observable.from()` conversion path stays aligned with spec-style inputs such as
491
+ iterables, promises, async iterables, array-like values, and objects that
492
+ implement `[Symbol.observable]()`. The interop helper also accepts direct
493
+ subscribables returned by third-party operator ecosystems, so you can reuse an
494
+ RxJS stage without first forcing its output through the stricter `from()`
495
+ contract.
496
+
497
+ Use the standard RxJS names when you are only talking to RxJS inside the
498
+ adapter:
499
+
500
+ ```ts
501
+ import { fromObservableOperator, Observable, pipe } from "@okikio/observables";
502
+ import { from, map, pipe as rxPipe, take } from "rxjs";
503
+
504
+ const rxStage = fromObservableOperator<number, number>(
505
+ rxPipe(
506
+ map((value) => value + 1),
507
+ take(2),
508
+ ),
509
+ { sourceAdapter: (source) => from(source) },
510
+ );
511
+
512
+ const result = pipe(Observable.of(1, 2, 3), rxStage);
513
+ ```
514
+
515
+ Alias the RxJS imports when you want local operators and RxJS operators in the
516
+ same file:
517
+
518
+ ```ts
519
+ import {
520
+ fromObservableOperator,
521
+ map,
522
+ Observable,
523
+ pipe,
524
+ } from "@okikio/observables";
525
+ import {
526
+ from as rxFrom,
527
+ map as rxMap,
528
+ pipe as rxPipe,
529
+ take as rxTake,
530
+ } from "rxjs";
531
+
532
+ const result = pipe(
533
+ Observable.of(1, 2, 3, 4),
534
+ map((value) => value * 10),
535
+ fromObservableOperator<number, number>(
536
+ rxPipe(
537
+ rxMap((value) => value + 1),
538
+ rxTake(2),
539
+ ),
540
+ { sourceAdapter: (source) => rxFrom(source) },
541
+ ),
542
+ );
543
+ ```
544
+
545
+ `sourceAdapter` is the important piece for standard RxJS operators. RxJS
546
+ operator functions expect an RxJS `Observable` on the input side, so the
547
+ adapter converts this library's Observable into that source shape before the
548
+ foreign operator runs. On the output side, `fromObservableOperator()` can read
549
+ either a normal `Observable.from()` input or a direct subscribable returned by
550
+ RxJS.
551
+
552
+ Some operators have the same name in both ecosystems, such as `switchMap`,
553
+ `mergeMap`, `concatMap`, `findIndex`, `first`, and `elementAt`. Others map by
554
+ intent rather than by exact name. For example, this library's `changed()` is
555
+ closest to RxJS `distinctUntilChanged()`.
556
+
451
557
  ## Performance
452
558
 
453
559
  We built this on Web Streams for good reason, native backpressure and memory
@@ -459,6 +565,12 @@ efficiency come for free. Here's what you get:
459
565
  - **Tree Shaking**: Import only what you use (most apps need <4KB)
460
566
  - **TypeScript Native**: Zero runtime overhead for type safety
461
567
 
568
+ Interop helpers are intentionally thin, but they still add one adaptation
569
+ boundary. If raw throughput is the main goal, prefer built-in operators first,
570
+ then reach for `fromStreamPair()` or `fromObservableOperator()` when reusing an
571
+ existing platform transform or foreign operator saves more code than it costs
572
+ in adapter overhead.
573
+
462
574
  Performance varies by use case, but here's how different error modes stack up:
463
575
 
464
576
  | Error Mode | Performance | When We Use It |
@@ -500,9 +612,8 @@ like a stream of search results, mouse movements, or WebSocket messages.
500
612
 
501
613
  ### Why not just use RxJS?
502
614
 
503
- RxJS is powerful but can be overwhelming. We've all been there, 100+ operators,
504
- steep learning curve, 35KB bundle size. This library gives you the essential
505
- Observable patterns you actually use day-to-day, following the TC39 proposal so
615
+ RxJS is powerful but can be overwhelming. 100+ operators, a steep learning curve, 35KB bundle size, it can be very overwhelming. `@okikio/observables` gives you the essential
616
+ Observable patterns you actually need day-to-day, following the TC39 proposal so
506
617
  you're future-ready.
507
618
 
508
619
  ### EventBus vs Observable, when do I use which?
@@ -525,9 +636,9 @@ Pick the mode that fits your situation:
525
636
 
526
637
  ### Is this actually production ready?
527
638
 
528
- We use it in production. It follows the TC39 proposal, has comprehensive tests,
639
+ It follows the TC39 proposal, has comprehensive tests,
529
640
  and handles resource management properly. The Web Streams foundation is
530
- battle-tested across browsers and runtimes.
641
+ battle-tested across browsers and runtimes. I'd say it's good enough for prime-time, but as with any library, test it in your specific use case first.
531
642
 
532
643
  ## Contributing
533
644
 
@@ -1,5 +1,6 @@
1
1
  import type { ObservableError } from "../error.js";
2
2
  import type { Observable } from "../observable.js";
3
+ import type { SpecObservable } from "../_spec.js";
3
4
  /**
4
5
  * Type representing a stream operator function
5
6
  * Transforms a ReadableStream of type In to a ReadableStream of type Out
@@ -67,6 +68,67 @@ export interface BaseTransformOptions {
67
68
  */
68
69
  name?: string;
69
70
  }
71
+ /**
72
+ * Structural readable/writable pair used by platform transforms such as
73
+ * `CompressionStream`.
74
+ */
75
+ export interface StreamPair<TIn, TOut> {
76
+ /** Readable side exposed by the transform-like object. */
77
+ readable: ReadableStream<TOut>;
78
+ /** Writable side exposed by the transform-like object. */
79
+ writable: WritableStream<TIn>;
80
+ }
81
+ /**
82
+ * Minimal subscribable shape used by foreign Observable implementations.
83
+ */
84
+ export interface SubscribableLike<T> {
85
+ /** Subscribe to values from the foreign Observable-like object. */
86
+ subscribe(observer: {
87
+ next?(value: T): void;
88
+ error?(error: unknown): void;
89
+ complete?(): void;
90
+ }): {
91
+ unsubscribe?(): void;
92
+ } | void;
93
+ }
94
+ /**
95
+ * Observable-like values that can be converted through `Observable.from()`.
96
+ */
97
+ export type ObservableInputLike<T> = SpecObservable<T> | AsyncIterable<T> | Iterable<T> | PromiseLike<T>;
98
+ /**
99
+ * Wider Observable-like values accepted by interop helpers that adapt foreign
100
+ * operator ecosystems.
101
+ *
102
+ * This is intentionally wider than `ObservableInputLike<T>`. `Observable.from()`
103
+ * stays aligned with the library's spec-facing conversion contract, while
104
+ * interop helpers may also need to consume direct subscribables returned by
105
+ * third-party libraries such as RxJS.
106
+ */
107
+ export type ObservableInteropInputLike<T> = ObservableInputLike<T> | SubscribableLike<T>;
108
+ /**
109
+ * Foreign operator shape used by libraries that transform one Observable-like
110
+ * source into another Observable-like result.
111
+ */
112
+ export type ObservableOperatorInterop<TIn, TOut, TSource = Observable<TIn>> = (source: TSource) => ObservableInteropInputLike<TOut>;
113
+ /**
114
+ * Configuration for adapting foreign Observable-style operators.
115
+ *
116
+ * Some libraries, such as RxJS, require their own Observable class on the
117
+ * input side even when the returned operator shape is still `(source) =>
118
+ * output`. `sourceAdapter` lets callers convert this library's Observable into
119
+ * that foreign source type before the operator runs.
120
+ */
121
+ export interface ObservableOperatorInteropOptions<TIn, TSource = Observable<TIn>> {
122
+ /**
123
+ * Converts this library's Observable into the source type expected by the
124
+ * foreign operator.
125
+ */
126
+ sourceAdapter?: (source: Observable<TIn>) => TSource;
127
+ /**
128
+ * Context label used when the foreign output reports an error.
129
+ */
130
+ errorContext?: string;
131
+ }
70
132
  /**
71
133
  * Options for using an existing TransformStream
72
134
  */
@@ -1 +1 @@
1
- {"version":3,"file":"_types.d.ts","sourceRoot":"","sources":["../../src/helpers/_types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,QAAQ,CAAC,EAAE,EAAE,GAAG,IAAI,CAC9B,MAAM,EAAE,cAAc,CAAC,EAAE,CAAC,KACvB,cAAc,CAAC,GAAG,CAAC,CAAC;AAEzB;;;GAGG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC;AAE1D;;;GAGG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;AAE/E;;;GAGG;AACH,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,OAAO,IAAI,OAAO,SAC5D,UAAU,CAAC,OAAO,CAAC,GAAG,mBAAmB,CAAC,OAAO,CAAC,GAChD,OAAO,SAAS,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,GAC5C,2BAA2B,CAAC,OAAO,CAAC,GACtC,OAAO,CAAC;AAEZ;;GAEG;AACH,MAAM,MAAM,2BAA2B,CACrC,OAAO,SAAS,YAAY,CAAC,GAA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AAC,CAAC,KAC5C,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1B;;;OAGG;IACH,MAAM,CAAC,EAAE,CACP,KAAK,EAAE,CAAC,EACR,MAAM,CAAC,EAAE,OAAO,KACb,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,uBAAuB,CAAC,CAAC,SAAS,OAAO,GAAG,SAAS;IACpE;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;OAEG;IACH,KAAK,CAAC,EAAE,CAAC,CAAC;CACX"}
@@ -18,6 +18,51 @@ import "../../_dnt.polyfills.js";
18
18
  import type { SpecObservable } from "../../_spec.js";
19
19
  import type { ExcludeError, Operator } from "../_types.js";
20
20
  import { ObservableError } from "../../error.js";
21
+ /**
22
+ * Creates a follow-up Observable for each source value.
23
+ *
24
+ * These higher-order operators all work in two stages:
25
+ * they read an outer source value, then use this callback to start an inner
26
+ * Observable whose values are forwarded according to the operator's policy.
27
+ *
28
+ * ```text
29
+ * outer value ---> createFollowUp(value, index) ---> inner Observable
30
+ * ```
31
+ *
32
+ * The operators in this module differ in what they do after that point:
33
+ *
34
+ * ```text
35
+ * mergeMap -> keep many inners running at once
36
+ * concatMap -> queue inners and run one at a time
37
+ * switchMap -> cancel the old inner and keep only the latest one
38
+ * ```
39
+ *
40
+ * @typeParam T - Value type from the outer source
41
+ * @typeParam R - Value type emitted by each follow-up Observable
42
+ */
43
+ export type FollowUpProject<T, R> = (value: ExcludeError<T>, index: number) => SpecObservable<R>;
44
+ /**
45
+ * Tuple of values emitted by a source and one or more companion Observables.
46
+ *
47
+ * Operators such as `withLatestFrom`, `combineLatestWith`, and `zipWith`
48
+ * return tuples so callers can decide how to shape the combined values in a
49
+ * later `map()` step without losing type information.
50
+ *
51
+ * @typeParam T - Value type from the primary source
52
+ * @typeParam TOthers - Value types from the companion Observables
53
+ */
54
+ export type CombinationTuple<T, TOthers extends readonly unknown[]> = [
55
+ T,
56
+ ...TOthers
57
+ ];
58
+ /**
59
+ * Tuple-shaped list of companion Observables used by the combination helpers.
60
+ *
61
+ * @typeParam TValues - Value types emitted by each companion Observable
62
+ */
63
+ export type CombinationSources<TValues extends readonly unknown[]> = {
64
+ [K in keyof TValues]: SpecObservable<TValues[K]>;
65
+ };
21
66
  /**
22
67
  * Transforms each item into a new stream and merges their outputs, running
23
68
  * them in parallel.
@@ -63,7 +108,7 @@ import { ObservableError } from "../../error.js";
63
108
  * to concurrently. Default is Infinity.
64
109
  * @returns An operator function that maps and flattens values
65
110
  */
66
- export declare function mergeMap<T, R>(project: (value: ExcludeError<T>, index: number) => SpecObservable<R>, concurrent?: number): Operator<T | ObservableError, R | ObservableError>;
111
+ export declare function mergeMap<T, R>(project: FollowUpProject<T, R>, concurrent?: number): Operator<T | ObservableError, R | ObservableError>;
67
112
  /**
68
113
  * Transforms each item into a new stream and runs them one after another, in
69
114
  * strict order.
@@ -113,7 +158,7 @@ export declare function mergeMap<T, R>(project: (value: ExcludeError<T>, index:
113
158
  * @param project - Function that maps a source value to an Observable
114
159
  * @returns An operator function that maps and concatenates values
115
160
  */
116
- export declare function concatMap<T, R>(project: (value: ExcludeError<T>, index: number) => SpecObservable<R>): Operator<T | ObservableError, R | ObservableError>;
161
+ export declare function concatMap<T, R>(project: FollowUpProject<T, R>): Operator<T | ObservableError, R | ObservableError>;
117
162
  /**
118
163
  * Transforms items into new streams, but cancels the previous stream when a new
119
164
  * item arrives.
@@ -158,5 +203,69 @@ export declare function concatMap<T, R>(project: (value: ExcludeError<T>, index:
158
203
  * @param project - Function that maps a source value to an Observable
159
204
  * @returns An operator function that maps and switches between values
160
205
  */
161
- export declare function switchMap<T, R>(project: (value: ExcludeError<T>, index: number) => SpecObservable<R>): Operator<T | ObservableError, R | ObservableError>;
206
+ export declare function switchMap<T, R>(project: FollowUpProject<T, R>): Operator<T | ObservableError, R | ObservableError>;
207
+ /**
208
+ * Emits each source value together with the latest value from every companion
209
+ * Observable.
210
+ *
211
+ * This operator waits until every companion Observable has produced at least
212
+ * one value. After that gate opens, each new source value emits a tuple that
213
+ * includes the source value followed by the most recent companion values.
214
+ *
215
+ * ```text
216
+ * companion A: ---a----b-------c--
217
+ * companion B: -----x-------y-----
218
+ * source: ------1--2------3--
219
+ * output: ------[1,a,x][2,b,x][3,c,y]
220
+ * ```
221
+ *
222
+ * The source still decides when outputs happen. Companion Observables only
223
+ * update the remembered latest values.
224
+ *
225
+ * @typeParam T - Value type from the primary source
226
+ * @typeParam TOthers - Value types from the companion Observables
227
+ * @param others - Companion Observables whose latest values should be attached
228
+ * @returns An operator that emits tuples of the source value and latest others
229
+ */
230
+ export declare function withLatestFrom<T, TOthers extends readonly unknown[]>(...others: CombinationSources<TOthers>): Operator<T | ObservableError, CombinationTuple<ExcludeError<T>, TOthers> | ObservableError>;
231
+ /**
232
+ * Combines the source with companion Observables using combine-latest timing.
233
+ *
234
+ * Once every source has emitted at least one value, any new value from the
235
+ * primary source or a companion Observable emits a new tuple containing the
236
+ * latest value from each source.
237
+ *
238
+ * @typeParam T - Value type from the primary source
239
+ * @typeParam TOthers - Value types from the companion Observables
240
+ * @param others - Companion Observables that participate in the latest-value set
241
+ * @returns An operator that emits tuples of the latest value from every source
242
+ */
243
+ export declare function combineLatestWith<T, TOthers extends readonly unknown[]>(...others: CombinationSources<TOthers>): Operator<T | ObservableError, CombinationTuple<ExcludeError<T>, TOthers> | ObservableError>;
244
+ /**
245
+ * Pairs source values with companion values in strict arrival order.
246
+ *
247
+ * `zipWith` waits until it has one value from the source and one value from
248
+ * each companion. It then emits a tuple and removes those values from the
249
+ * queues before waiting for the next full set.
250
+ *
251
+ * @typeParam T - Value type from the primary source
252
+ * @typeParam TOthers - Value types from the companion Observables
253
+ * @param others - Companion Observables to align by arrival order
254
+ * @returns An operator that emits tuples aligned by position instead of time
255
+ */
256
+ export declare function zipWith<T, TOthers extends readonly unknown[]>(...others: CombinationSources<TOthers>): Operator<T | ObservableError, CombinationTuple<ExcludeError<T>, TOthers> | ObservableError>;
257
+ /**
258
+ * Mirrors whichever Observable emits first: the source or one of the
259
+ * companions.
260
+ *
261
+ * If the primary source wins, future source values keep flowing and companion
262
+ * Observables are cancelled. If a companion wins, the source is ignored from
263
+ * that point on and the winning companion continues to drive the output.
264
+ *
265
+ * @typeParam T - Value type from the primary source
266
+ * @typeParam TOthers - Value types from the companion Observables
267
+ * @param others - Companion Observables racing against the source
268
+ * @returns An operator that mirrors the winning Observable
269
+ */
270
+ export declare function raceWith<T, TOthers extends readonly unknown[]>(...others: CombinationSources<TOthers>): Operator<T | ObservableError, ExcludeError<T> | TOthers[number] | ObservableError>;
162
271
  //# sourceMappingURL=combination.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"combination.d.ts","sourceRoot":"","sources":["../../../src/helpers/operations/combination.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,yBAAyB,CAAC;AAGjC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG3D,OAAO,EAAqB,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAC3B,OAAO,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,cAAc,CAAC,CAAC,CAAC,EACrE,UAAU,GAAE,MAAiB,GAC5B,QAAQ,CAAC,CAAC,GAAG,eAAe,EAAE,CAAC,GAAG,eAAe,CAAC,CAkHpD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,wBAA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