@okikio/observables 1.0.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.
Files changed (131) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +578 -0
  3. package/esm/_dnt.polyfills.d.ts +20 -0
  4. package/esm/_dnt.polyfills.d.ts.map +1 -0
  5. package/esm/_dnt.polyfills.js +12 -0
  6. package/esm/_spec.d.ts +260 -0
  7. package/esm/_spec.d.ts.map +1 -0
  8. package/esm/_spec.js +1 -0
  9. package/esm/_types.d.ts +141 -0
  10. package/esm/_types.d.ts.map +1 -0
  11. package/esm/_types.js +20 -0
  12. package/esm/error.d.ts +331 -0
  13. package/esm/error.d.ts.map +1 -0
  14. package/esm/error.js +408 -0
  15. package/esm/events.d.ts +320 -0
  16. package/esm/events.d.ts.map +1 -0
  17. package/esm/events.js +451 -0
  18. package/esm/helpers/_types.d.ts +188 -0
  19. package/esm/helpers/_types.d.ts.map +1 -0
  20. package/esm/helpers/_types.js +1 -0
  21. package/esm/helpers/mod.d.ts +90 -0
  22. package/esm/helpers/mod.d.ts.map +1 -0
  23. package/esm/helpers/mod.js +90 -0
  24. package/esm/helpers/operations/batch.d.ts +109 -0
  25. package/esm/helpers/operations/batch.d.ts.map +1 -0
  26. package/esm/helpers/operations/batch.js +140 -0
  27. package/esm/helpers/operations/combination.d.ts +162 -0
  28. package/esm/helpers/operations/combination.d.ts.map +1 -0
  29. package/esm/helpers/operations/combination.js +350 -0
  30. package/esm/helpers/operations/conditional.d.ts +211 -0
  31. package/esm/helpers/operations/conditional.d.ts.map +1 -0
  32. package/esm/helpers/operations/conditional.js +280 -0
  33. package/esm/helpers/operations/core.d.ts +198 -0
  34. package/esm/helpers/operations/core.d.ts.map +1 -0
  35. package/esm/helpers/operations/core.js +264 -0
  36. package/esm/helpers/operations/errors.d.ts +277 -0
  37. package/esm/helpers/operations/errors.d.ts.map +1 -0
  38. package/esm/helpers/operations/errors.js +378 -0
  39. package/esm/helpers/operations/mod.d.ts +26 -0
  40. package/esm/helpers/operations/mod.d.ts.map +1 -0
  41. package/esm/helpers/operations/mod.js +25 -0
  42. package/esm/helpers/operations/timing.d.ts +206 -0
  43. package/esm/helpers/operations/timing.d.ts.map +1 -0
  44. package/esm/helpers/operations/timing.js +457 -0
  45. package/esm/helpers/operators.d.ts +520 -0
  46. package/esm/helpers/operators.d.ts.map +1 -0
  47. package/esm/helpers/operators.js +563 -0
  48. package/esm/helpers/pipe.d.ts +118 -0
  49. package/esm/helpers/pipe.d.ts.map +1 -0
  50. package/esm/helpers/pipe.js +129 -0
  51. package/esm/helpers/utils.d.ts +142 -0
  52. package/esm/helpers/utils.d.ts.map +1 -0
  53. package/esm/helpers/utils.js +193 -0
  54. package/esm/mod.d.ts +863 -0
  55. package/esm/mod.d.ts.map +1 -0
  56. package/esm/mod.js +861 -0
  57. package/esm/observable.d.ts +1610 -0
  58. package/esm/observable.d.ts.map +1 -0
  59. package/esm/observable.js +1970 -0
  60. package/esm/package.json +3 -0
  61. package/esm/queue.d.ts +201 -0
  62. package/esm/queue.d.ts.map +1 -0
  63. package/esm/queue.js +273 -0
  64. package/esm/symbol.d.ts +60 -0
  65. package/esm/symbol.d.ts.map +1 -0
  66. package/esm/symbol.js +132 -0
  67. package/package.json +96 -0
  68. package/script/_dnt.polyfills.d.ts +20 -0
  69. package/script/_dnt.polyfills.d.ts.map +1 -0
  70. package/script/_dnt.polyfills.js +13 -0
  71. package/script/_spec.d.ts +260 -0
  72. package/script/_spec.d.ts.map +1 -0
  73. package/script/_spec.js +2 -0
  74. package/script/_types.d.ts +141 -0
  75. package/script/_types.d.ts.map +1 -0
  76. package/script/_types.js +22 -0
  77. package/script/error.d.ts +331 -0
  78. package/script/error.d.ts.map +1 -0
  79. package/script/error.js +414 -0
  80. package/script/events.d.ts +320 -0
  81. package/script/events.d.ts.map +1 -0
  82. package/script/events.js +458 -0
  83. package/script/helpers/_types.d.ts +188 -0
  84. package/script/helpers/_types.d.ts.map +1 -0
  85. package/script/helpers/_types.js +2 -0
  86. package/script/helpers/mod.d.ts +90 -0
  87. package/script/helpers/mod.d.ts.map +1 -0
  88. package/script/helpers/mod.js +106 -0
  89. package/script/helpers/operations/batch.d.ts +109 -0
  90. package/script/helpers/operations/batch.d.ts.map +1 -0
  91. package/script/helpers/operations/batch.js +144 -0
  92. package/script/helpers/operations/combination.d.ts +162 -0
  93. package/script/helpers/operations/combination.d.ts.map +1 -0
  94. package/script/helpers/operations/combination.js +355 -0
  95. package/script/helpers/operations/conditional.d.ts +211 -0
  96. package/script/helpers/operations/conditional.d.ts.map +1 -0
  97. package/script/helpers/operations/conditional.js +286 -0
  98. package/script/helpers/operations/core.d.ts +198 -0
  99. package/script/helpers/operations/core.d.ts.map +1 -0
  100. package/script/helpers/operations/core.js +272 -0
  101. package/script/helpers/operations/errors.d.ts +277 -0
  102. package/script/helpers/operations/errors.d.ts.map +1 -0
  103. package/script/helpers/operations/errors.js +387 -0
  104. package/script/helpers/operations/mod.d.ts +26 -0
  105. package/script/helpers/operations/mod.d.ts.map +1 -0
  106. package/script/helpers/operations/mod.js +41 -0
  107. package/script/helpers/operations/timing.d.ts +206 -0
  108. package/script/helpers/operations/timing.d.ts.map +1 -0
  109. package/script/helpers/operations/timing.js +464 -0
  110. package/script/helpers/operators.d.ts +520 -0
  111. package/script/helpers/operators.d.ts.map +1 -0
  112. package/script/helpers/operators.js +570 -0
  113. package/script/helpers/pipe.d.ts +118 -0
  114. package/script/helpers/pipe.d.ts.map +1 -0
  115. package/script/helpers/pipe.js +132 -0
  116. package/script/helpers/utils.d.ts +142 -0
  117. package/script/helpers/utils.d.ts.map +1 -0
  118. package/script/helpers/utils.js +200 -0
  119. package/script/mod.d.ts +863 -0
  120. package/script/mod.d.ts.map +1 -0
  121. package/script/mod.js +877 -0
  122. package/script/observable.d.ts +1610 -0
  123. package/script/observable.d.ts.map +1 -0
  124. package/script/observable.js +1984 -0
  125. package/script/package.json +3 -0
  126. package/script/queue.d.ts +201 -0
  127. package/script/queue.d.ts.map +1 -0
  128. package/script/queue.js +286 -0
  129. package/script/symbol.d.ts +60 -0
  130. package/script/symbol.d.ts.map +1 -0
  131. package/script/symbol.js +135 -0
@@ -0,0 +1,264 @@
1
+ import "../../_dnt.polyfills.js";
2
+ import { createOperator, createStatefulOperator } from "../operators.js";
3
+ /**
4
+ * Core transformation and terminal operators for everyday stream work.
5
+ *
6
+ * This module is the closest match to familiar array helpers. It exports the
7
+ * operators you reach for first when you want to transform values, filter them,
8
+ * accumulate state, or stop after a condition has been met. In practice, this
9
+ * is where most pipelines start before you add timing or concurrency behavior.
10
+ *
11
+ * The important difference from arrays is error handling. These operators are
12
+ * designed to work with the library's pass-through model, so your callbacks see
13
+ * clean data values while `ObservableError` instances continue downstream
14
+ * unchanged until a dedicated error-handling step decides what to do with them.
15
+ *
16
+ * @module
17
+ */
18
+ /**
19
+ * Transforms each data item, automatically skipping errors.
20
+ *
21
+ * Like `Array.map()`, but errors flow through unchanged:
22
+ *
23
+ * ```ts
24
+ * // Array.map() transforms everything
25
+ * [1, 2, 3].map(n => n * 2) // [2, 4, 6]
26
+ *
27
+ * // Stream map() transforms only data
28
+ * pipe([1, Error, 3], map(n => n * 2)) // [2, Error, 6]
29
+ * ```
30
+ *
31
+ * Your function only receives clean data, never errors:
32
+ *
33
+ * ```ts
34
+ * pipe(
35
+ * userIds,
36
+ * map(id => fetchUser(id)), // Some API calls fail
37
+ * map(user => user.name), // Only runs on real users
38
+ * map(name => name.toUpperCase()) // Only runs on real names
39
+ * );
40
+ * // Result: [Name, Error, Name] - clean transformations, errors preserved
41
+ * ```
42
+ *
43
+ * @param project - Function that transforms each data item
44
+ */
45
+ export function map(project) {
46
+ return createStatefulOperator({
47
+ name: "map",
48
+ createState: () => ({ index: 0 }),
49
+ transform(chunk, state, controller) {
50
+ const result = project(chunk, state.index++);
51
+ controller.enqueue(result);
52
+ },
53
+ });
54
+ }
55
+ /**
56
+ * Keeps data items that pass your test, always preserves errors.
57
+ *
58
+ * Like `Array.filter()`, but errors automatically pass through:
59
+ *
60
+ * ```ts
61
+ * // Array.filter() tests everything
62
+ * [1, 2, 3, 4].filter(n => n > 2) // [3, 4]
63
+ *
64
+ * // Stream filter() tests only data
65
+ * pipe([1, Error, 3, 4], filter(n => n > 2)) // [Error, 3, 4]
66
+ * ```
67
+ *
68
+ * Your test function only receives clean data:
69
+ *
70
+ * ```ts
71
+ * pipe(
72
+ * users,
73
+ * filter(user => user.isActive), // Only tests real users
74
+ * filter(user => user.age >= 18) // Chain multiple filters
75
+ * );
76
+ * // Result: filtered users + all errors preserved
77
+ * ```
78
+ *
79
+ * @param predicate - Test function that decides which data items to keep
80
+ */
81
+ export function filter(predicate) {
82
+ return createStatefulOperator({
83
+ name: "filter",
84
+ createState: () => ({ index: 0 }),
85
+ transform(chunk, state, controller) {
86
+ if (predicate(chunk, state.index++)) {
87
+ controller.enqueue(chunk);
88
+ }
89
+ },
90
+ });
91
+ }
92
+ /**
93
+ * Takes the first N data items, errors don't count toward the limit.
94
+ *
95
+ * Like `Array.slice(0, N)`, but counts only successful data:
96
+ *
97
+ * ```ts
98
+ * // Array.slice() counts everything
99
+ * [1, "error", 2, 3].slice(0, 2) // [1, "error"] - 2 items total
100
+ *
101
+ * // Stream take() counts only data
102
+ * pipe([1, Error, 2, 3], take(2)) // [1, Error, 2] - 2 data items
103
+ * ```
104
+ *
105
+ * Perfect for pagination and "top N" scenarios:
106
+ *
107
+ * ```ts
108
+ * pipe(
109
+ * productIds,
110
+ * map(id => fetchProduct(id)), // Some API calls fail
111
+ * filter(p => p.rating > 4), // Only high-rated products
112
+ * take(10) // Exactly 10 products + any errors
113
+ * );
114
+ * // Guarantees 10 actual products for your UI
115
+ * ```
116
+ *
117
+ * Stream stops immediately after collecting N data items.
118
+ *
119
+ * @param count - How many data items to take
120
+ */
121
+ export function take(count) {
122
+ return createStatefulOperator({
123
+ name: "take",
124
+ createState: () => ({ taken: 0 }),
125
+ transform(chunk, state, controller) {
126
+ if (state.taken < count) {
127
+ controller.enqueue(chunk);
128
+ state.taken++;
129
+ // If we've taken enough values, terminate the stream
130
+ if (state.taken >= count) {
131
+ controller.terminate();
132
+ }
133
+ }
134
+ },
135
+ });
136
+ }
137
+ /**
138
+ * Skips the first N data items, errors don't count toward the skip count.
139
+ *
140
+ * Like `Array.slice(N)`, but counts only successful data:
141
+ *
142
+ * ```ts
143
+ * // Array.slice() counts everything
144
+ * [1, "error", 2, 3].slice(2) // [2, 3] - skipped first 2 items
145
+ *
146
+ * // Stream drop() counts only data
147
+ * pipe([1, Error, 2, 3], drop(2)) // [Error, 3] - skipped first 2 data items
148
+ * ```
149
+ *
150
+ * Perfect for pagination - skip to the right page regardless of errors:
151
+ *
152
+ * ```ts
153
+ * // Page 2: skip first 20 successful products
154
+ * pipe(
155
+ * productIds,
156
+ * map(id => fetchProduct(id)), // Some API calls fail
157
+ * drop(20), // Skip first 20 real products
158
+ * take(20) // Next 20 products
159
+ * );
160
+ * // Errors flow through immediately, don't affect page positioning
161
+ * ```
162
+ *
163
+ * @param count - How many data items to skip
164
+ */
165
+ export function drop(count) {
166
+ return createStatefulOperator({
167
+ name: "drop",
168
+ createState: () => ({ dropped: 0 }),
169
+ transform(chunk, state, controller) {
170
+ if (state.dropped < count) {
171
+ state.dropped++;
172
+ }
173
+ else {
174
+ controller.enqueue(chunk);
175
+ }
176
+ },
177
+ });
178
+ }
179
+ /**
180
+ * Runs side effects on data items, automatically skipping errors.
181
+ *
182
+ * Like adding `console.log()` to debug, but only logs clean data:
183
+ *
184
+ * ```ts
185
+ * // Regular debugging sees everything (messy)
186
+ * data.map(x => { console.log('Item:', x); return transform(x); })
187
+ *
188
+ * // Stream tap() sees only data (clean)
189
+ * pipe(
190
+ * data,
191
+ * map(x => transform(x)),
192
+ * tap(x => console.log('Processed:', x)) // Only logs real data
193
+ * )
194
+ * ```
195
+ *
196
+ * Perfect for logging, analytics, caching, progress tracking:
197
+ *
198
+ * ```ts
199
+ * pipe(
200
+ * userIds,
201
+ * map(id => fetchUser(id)), // Some API calls fail
202
+ * tap(user => console.log('Loaded:', user.name)), // Clean logs
203
+ * tap(user => analytics.track('user_loaded')), // Business events only
204
+ * filter(user => user.isActive)
205
+ * );
206
+ * // Logs show only successful operations, errors flow silently
207
+ * ```
208
+ *
209
+ * Data flows through unchanged - `tap` just observes.
210
+ *
211
+ * @param fn - Function to run on each data item (for side effects)
212
+ */
213
+ export function tap(fn) {
214
+ return createOperator({
215
+ name: "tap",
216
+ transform(chunk, controller) {
217
+ fn(chunk);
218
+ controller.enqueue(chunk);
219
+ },
220
+ });
221
+ }
222
+ /**
223
+ * Builds running totals from data, automatically skipping errors.
224
+ *
225
+ * Like `Array.reduce()`, but shows each step and handles errors:
226
+ *
227
+ * ```ts
228
+ * // Array.reduce() gives final result only
229
+ * [1, 2, 3].reduce((sum, n) => sum + n, 0) // 6
230
+ *
231
+ * // Stream scan() shows progressive results
232
+ * pipe([1, Error, 3], scan((sum, n) => sum + n, 0)) // [0, 1, Error, 4]
233
+ * ```
234
+ *
235
+ * Perfect for running totals, counters, building objects:
236
+ *
237
+ * ```ts
238
+ * pipe(
239
+ * productIds,
240
+ * map(id => fetchPrice(id)), // Some API calls fail
241
+ * scan((total, price) => total + price, 0) // Running cart total
242
+ * );
243
+ * // Result: [0, 10, Error, 35, 40] - total ignores errors
244
+ * ```
245
+ *
246
+ * Always starts by emitting your initial value immediately.
247
+ *
248
+ * @param accumulator - Function that combines current total with new data
249
+ * @param seed - Starting value (emitted first)
250
+ */
251
+ export function scan(accumulator, seed) {
252
+ return createStatefulOperator({
253
+ name: "scan",
254
+ createState: () => ({ acc: seed, index: 0 }),
255
+ start(state, controller) {
256
+ // Emit the seed value immediately
257
+ controller.enqueue(state.acc);
258
+ },
259
+ transform(chunk, state, controller) {
260
+ state.acc = accumulator(state.acc, chunk, state.index++);
261
+ controller.enqueue(state.acc);
262
+ },
263
+ });
264
+ }
@@ -0,0 +1,277 @@
1
+ /**
2
+ * Error-focused operators for recovering from or reshaping stream failures.
3
+ *
4
+ * This entrypoint is for pipelines that expect some work to fail and want to
5
+ * keep going. It exports helpers for dropping wrapped errors, mapping them to
6
+ * fallback values, logging them, or converting them into a shape that fits the
7
+ * rest of the pipeline.
8
+ *
9
+ * These operators are most useful with the library's pass-through error mode,
10
+ * where failures travel as `ObservableError` values instead of immediately
11
+ * terminating the whole stream.
12
+ *
13
+ * @module
14
+ */
15
+ import "../../_dnt.polyfills.js";
16
+ import type { ExcludeError, Operator } from "../_types.js";
17
+ import { ObservableError } from "../../error.js";
18
+ /**
19
+ * Removes all errors from the stream, keeping only successful data.
20
+ *
21
+ * Like a filter that only allows non-error values to pass. It's a simple way
22
+ * to clean up a stream when you don't need to handle failures.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import { pipe, ignoreErrors, from } from "./helpers/mod.ts";
27
+ *
28
+ * // Array behavior (conceptual)
29
+ * const mixedData = [1, new Error("fail"), 2, 3];
30
+ * const goodData = mixedData.filter(item => !(item instanceof Error)); // [1, 2, 3]
31
+ *
32
+ * // Stream behavior
33
+ * const sourceStream = from([1, new ObservableError("fail"), 2, 3]);
34
+ * const cleanStream = pipe(sourceStream, ignoreErrors()); // Emits 1, 2, 3
35
+ * ```
36
+ *
37
+ * ## Practical Use Case
38
+ *
39
+ * Use `ignoreErrors` when processing a batch of items where some failures are
40
+ * expected and acceptable. For example, fetching a list of URLs where some
41
+ * might be broken. You only want to process the ones that work.
42
+ *
43
+ * ## Key Insight
44
+ *
45
+ * `ignoreErrors` provides a "fire-and-forget" approach to error handling. It's
46
+ * useful for non-critical tasks or when partial success is sufficient.
47
+ *
48
+ * @template T The type of good data in your stream
49
+ * @returns A stream operator that silently removes all errors
50
+ */
51
+ export declare function ignoreErrors<T>(): Operator<T | ObservableError, ExcludeError<T>>;
52
+ /**
53
+ * Replaces any error in the stream with a fallback value.
54
+ *
55
+ * Like a `try...catch` block for each item in a stream, but instead of just
56
+ * handling the error, you provide a default value to take its place.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * import { pipe, catchErrors, from } from "./helpers/mod.ts";
61
+ *
62
+ * // Conceptual equivalent
63
+ * function process(item) {
64
+ * try {
65
+ * if (item instanceof Error) throw item;
66
+ * return item;
67
+ * } catch {
68
+ * return "default";
69
+ * }
70
+ * }
71
+ * const results = [1, new Error("fail")].map(process); // [1, "default"]
72
+ *
73
+ * // Stream behavior
74
+ * const sourceStream = from([1, new ObservableError("fail")]);
75
+ * const safeStream = pipe(sourceStream, catchErrors("default")); // Emits 1, "default"
76
+ * ```
77
+ *
78
+ * ## Practical Use Case
79
+ *
80
+ * Use `catchErrors` to provide a default state or value when an operation
81
+ * fails. For example, if fetching a user's profile fails, you could return a
82
+ * default "Guest" profile instead of letting the error propagate.
83
+ *
84
+ * ## Key Insight
85
+ *
86
+ * `catchErrors` ensures your stream continues with a predictable structure,
87
+ * even when individual operations fail. It maintains the flow of data by
88
+ * substituting errors with safe, default values.
89
+ *
90
+ * @template T The type of data in your stream.
91
+ * @template R The type of the fallback value.
92
+ * @param fallback The value to use whenever an error occurs.
93
+ * @returns A stream operator that replaces errors with a fallback value.
94
+ */
95
+ export declare function catchErrors<T, R>(fallback: R): Operator<T | ObservableError, ExcludeError<T> | R>;
96
+ /**
97
+ * Transforms errors into custom values using a mapping function.
98
+ *
99
+ * This is a more powerful version of `catchErrors`. Instead of a single
100
+ * fallback, you can inspect each error and decide what to replace it with.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * import { pipe, mapErrors, from } from "./helpers/mod.ts";
105
+ *
106
+ * // Stream behavior
107
+ * const sourceStream = from([
108
+ * 1,
109
+ * new ObservableError("Not Found"),
110
+ * new ObservableError("Server Error")
111
+ * ]);
112
+ *
113
+ * const handledStream = pipe(
114
+ * sourceStream,
115
+ * mapErrors(err => {
116
+ * if (err.message === "Not Found") return { status: 404 };
117
+ * return { status: 500 };
118
+ * })
119
+ * );
120
+ * // Emits 1, { status: 404 }, { status: 500 }
121
+ * ```
122
+ *
123
+ * ## Practical Use Case
124
+ *
125
+ * Use `mapErrors` to convert different types of errors into meaningful data.
126
+ * For example, a "Not Found" error could be mapped to `null`, while a "Server
127
+ * Error" could be mapped to an object that triggers a retry mechanism.
128
+ *
129
+ * ## Key Insight
130
+ *
131
+ * `mapErrors` treats errors as data. It allows you to create a resilient
132
+ * stream that can intelligently respond to different failure modes without
133
+ * stopping.
134
+ *
135
+ * @template T The type of successful data in your stream.
136
+ * @template E The type your errors will be mapped to.
137
+ * @param errorMapper A function that receives an error and returns a new value.
138
+ * @returns A stream operator that transforms errors.
139
+ */
140
+ export declare function mapErrors<T, E>(errorMapper: (error: ObservableError) => E): Operator<T | ObservableError, ExcludeError<T> | E>;
141
+ /**
142
+ * Keeps only the errors from the stream, discarding successful data.
143
+ *
144
+ * This is the inverse of `ignoreErrors`. It's useful for creating a dedicated
145
+ * error-handling pipeline.
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * import { pipe, onlyErrors, from } from "./helpers/mod.ts";
150
+ *
151
+ * // Stream behavior
152
+ * const sourceStream = from([1, new ObservableError("fail"), 2]);
153
+ * const errorStream = pipe(sourceStream, onlyErrors()); // Emits ObservableError("fail")
154
+ * ```
155
+ *
156
+ * ## Practical Use Case
157
+ *
158
+ * Use `onlyErrors` to separate the error stream from the data stream. You can
159
+ * then log these errors, send them to a monitoring service, or trigger alerts
160
+ * without interfering with the main data processing flow.
161
+ *
162
+ * ## Key Insight
163
+ *
164
+ * `onlyErrors` allows you to create a side-channel for failures, enabling
165
+ * robust monitoring and debugging.
166
+ *
167
+ * @template T The type of data in the source stream.
168
+ * @returns An operator that filters for errors.
169
+ */
170
+ export declare function onlyErrors<T>(): Operator<T | ObservableError, ObservableError>;
171
+ /**
172
+ * Summarizes the stream into a final count of successes and errors.
173
+ *
174
+ * This operator waits for the stream to complete and then emits a single
175
+ * object with the total counts.
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * import { pipe, summarizeErrors, from } from "./helpers/mod.ts";
180
+ *
181
+ * // Stream behavior
182
+ * const sourceStream = from([1, new ObservableError("fail"), 2, 3]);
183
+ * const summary = await pipe(sourceStream, summarizeErrors()).toPromise();
184
+ * // { successCount: 3, errorCount: 1, totalProcessed: 4, successRate: 0.75 }
185
+ * ```
186
+ *
187
+ * ## Practical Use Case
188
+ *
189
+ * Use `summarizeErrors` at the end of a batch processing job to get a report
190
+ * on how many items were processed successfully and how many failed. This is
191
+
192
+ * useful for logging, monitoring, and generating reports.
193
+ *
194
+ * ## Key Insight
195
+ *
196
+ * `summarizeErrors` is a terminal operator that provides a high-level overview
197
+ * of a stream's health and completeness.
198
+ *
199
+ * @template T The type of data in the source stream.
200
+ * @returns An operator that emits a summary of successes and errors.
201
+ */
202
+ export declare function summarizeErrors<T>(): Operator<T | ObservableError, {
203
+ successCount: number;
204
+ errorCount: number;
205
+ totalProcessed: number;
206
+ successRate: number;
207
+ }>;
208
+ /**
209
+ * Performs a side effect for each error without modifying the stream.
210
+ *
211
+ * Like `Array.prototype.forEach` but only for errors. It's useful for logging
212
+ * or debugging without altering the data flow.
213
+ *
214
+ * @example
215
+ * ```ts
216
+ * import { pipe, tapError, from } from "./helpers/mod.ts";
217
+ *
218
+ * // Stream behavior
219
+ * const sourceStream = from([1, new ObservableError("fail")]);
220
+ * const tappedStream = pipe(
221
+ * sourceStream,
222
+ * tapError(err => console.error("Found an error:", err))
223
+ * );
224
+ * // Logs the error, then emits 1 and the error object.
225
+ * ```
226
+ *
227
+ * ## Practical Use Case
228
+ *
229
+ * Use `tapError` to log errors to the console or a monitoring service as they
230
+ * happen, without stopping or changing the stream. This is invaluable for
231
+ * real-time debugging.
232
+ *
233
+ * ## Key Insight
234
+ *
235
+ * `tapError` gives you a window into the stream's errors without affecting the
236
+ * stream itself.
237
+ *
238
+ * @template T The type of data in the stream.
239
+ * @param sideEffect A function to call for each error.
240
+ * @returns An operator that performs a side effect on errors.
241
+ */
242
+ export declare function tapError<T>(sideEffect: (error: ObservableError) => void): Operator<T | ObservableError, T | ObservableError>;
243
+ /**
244
+ * Throws an error if it encounters one in the stream.
245
+ *
246
+ * This operator is useful for enforcing strict error handling. If an error is
247
+ * encountered, it will throw immediately, stopping the iteration.
248
+ *
249
+ * @example
250
+ * ```ts
251
+ * import { pipe, throwErrors, from } from "./helpers/mod.ts";
252
+ *
253
+ * // Stream behavior
254
+ * const sourceStream = from([1, new ObservableError("fail"), 2]);
255
+ * const throwingStream = pipe(sourceStream, throwErrors());
256
+ *
257
+ * for await (const item of throwingStream) {
258
+ * console.log(item); // Will log 1, then throw on "fail"
259
+ * }
260
+ * ```
261
+ *
262
+ * ## Practical Use Case
263
+ *
264
+ * Use `throwErrors` when you want to ensure that any error in the stream is
265
+ * treated as a critical failure. This is useful in scenarios where errors must
266
+ * be handled immediately and cannot be ignored.
267
+ *
268
+ * ## Key Insight
269
+ *
270
+ * `throwErrors` provides a way to enforce strict error handling in streams,
271
+ * ensuring that no errors go unnoticed.
272
+ *
273
+ * @template T The type of data in the stream.
274
+ * @returns An operator that throws on errors.
275
+ */
276
+ export declare function throwErrors<T>(): Operator<T | ObservableError, T>;
277
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/helpers/operations/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAqB,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,YAAY,CAAC,CAAC,KAAK,QAAQ,CACzC,CAAC,GAAG,eAAe,EACnB,YAAY,CAAC,CAAC,CAAC,CAChB,CASA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAC9B,QAAQ,EAAE,CAAC,GACV,QAAQ,CAAC,CAAC,GAAG,eAAe,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAYpD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAC5B,WAAW,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,CAAC,GACzC,QAAQ,CAAC,CAAC,GAAG,eAAe,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CA6BpD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,UAAU,CAAC,CAAC,KAAK,QAAQ,CACvC,CAAC,GAAG,eAAe,EACnB,eAAe,CAChB,CAWA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,eAAe,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,GAAG,eAAe,EAAE;IAClE,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC,CA2BD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,UAAU,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,GAC3C,QAAQ,CAAC,CAAC,GAAG,eAAe,EAAE,CAAC,GAAG,eAAe,CAAC,CAgBpD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,WAAW,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,GAAG,eAAe,EAAE,CAAC,CAAC,CASjE"}