iterflow 0.7.0 → 0.9.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 +44 -0
- package/dist/fn/index.cjs.map +1 -1
- package/dist/fn/index.js.map +1 -1
- package/dist/index.cjs +378 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +152 -5
- package/dist/index.d.ts +152 -5
- package/dist/index.js +377 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -73,6 +73,25 @@ declare class iterflow<T> implements Iterable<T> {
|
|
|
73
73
|
* ```
|
|
74
74
|
*/
|
|
75
75
|
take(limit: number): iterflow<T>;
|
|
76
|
+
/**
|
|
77
|
+
* Limits the maximum number of iterations to prevent infinite loops.
|
|
78
|
+
* Unlike `take()` which silently stops at the limit, this method throws
|
|
79
|
+
* an OperationError if the limit is exceeded, making infinite loops explicit.
|
|
80
|
+
*
|
|
81
|
+
* @param maxIterations - Maximum number of iterations allowed (must be at least 1)
|
|
82
|
+
* @returns A new iterflow that will throw if limit is exceeded
|
|
83
|
+
* @throws {ValidationError} If maxIterations is not a positive integer
|
|
84
|
+
* @throws {OperationError} If iteration count exceeds maxIterations
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* // Safely process potentially infinite iterator
|
|
88
|
+
* iter.range(Infinity).limit(1000).toArray(); // Throws after 1000 iterations
|
|
89
|
+
*
|
|
90
|
+
* // Regular finite iterator works normally
|
|
91
|
+
* iter([1, 2, 3]).limit(10).toArray(); // [1, 2, 3]
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
limit(maxIterations: number): iterflow<T>;
|
|
76
95
|
/**
|
|
77
96
|
* Skips the first `count` elements from the iterator.
|
|
78
97
|
*
|
|
@@ -205,13 +224,23 @@ declare class iterflow<T> implements Iterable<T> {
|
|
|
205
224
|
* Collects all elements into an array.
|
|
206
225
|
* This is a terminal operation that consumes the iterator.
|
|
207
226
|
*
|
|
208
|
-
* @
|
|
227
|
+
* @param maxSize - Optional maximum array size. If provided and the iterator produces
|
|
228
|
+
* more elements, collection stops at maxSize (no error thrown).
|
|
229
|
+
* This is useful for safely collecting from potentially large iterators.
|
|
230
|
+
* @returns Array containing all elements (up to maxSize if specified)
|
|
231
|
+
* @throws {ValidationError} If maxSize is provided but not a positive integer
|
|
209
232
|
* @example
|
|
210
233
|
* ```typescript
|
|
211
234
|
* iter([1, 2, 3]).map(x => x * 2).toArray(); // [2, 4, 6]
|
|
235
|
+
*
|
|
236
|
+
* // Safely collect from large/infinite iterator
|
|
237
|
+
* iter.range(Infinity).toArray(1000); // [0, 1, 2, ..., 999]
|
|
238
|
+
*
|
|
239
|
+
* // Works with finite iterators too
|
|
240
|
+
* iter([1, 2, 3]).toArray(10); // [1, 2, 3] (stops early)
|
|
212
241
|
* ```
|
|
213
242
|
*/
|
|
214
|
-
toArray(): T[];
|
|
243
|
+
toArray(maxSize?: number): T[];
|
|
215
244
|
/**
|
|
216
245
|
* Counts the total number of elements in the iterator.
|
|
217
246
|
* This is a terminal operation that consumes the iterator.
|
|
@@ -729,11 +758,15 @@ declare class iterflow<T> implements Iterable<T> {
|
|
|
729
758
|
/**
|
|
730
759
|
* Alias for stdDev() method for compatibility.
|
|
731
760
|
* Calculates the standard deviation of all numeric elements.
|
|
761
|
+
*
|
|
762
|
+
* @deprecated Use stdDev() instead. This alias will be removed in v1.0.0.
|
|
732
763
|
*/
|
|
733
764
|
stddev(this: iterflow<number>): number | undefined;
|
|
734
765
|
/**
|
|
735
766
|
* Alias for drop() method for compatibility.
|
|
736
767
|
* Skips the first `count` elements from the iterator.
|
|
768
|
+
*
|
|
769
|
+
* @deprecated Use drop() instead. This alias will be removed in v1.0.0.
|
|
737
770
|
*/
|
|
738
771
|
skip(count: number): iterflow<T>;
|
|
739
772
|
/**
|
|
@@ -847,6 +880,25 @@ declare class Asynciterflow<T> implements AsyncIterable<T> {
|
|
|
847
880
|
* ```
|
|
848
881
|
*/
|
|
849
882
|
drop(count: number): Asynciterflow<T>;
|
|
883
|
+
/**
|
|
884
|
+
* Limits the maximum number of iterations to prevent infinite loops.
|
|
885
|
+
* Unlike `take()` which silently stops at the limit, this method throws
|
|
886
|
+
* an OperationError if the limit is exceeded, making infinite loops explicit.
|
|
887
|
+
*
|
|
888
|
+
* @param maxIterations - Maximum number of iterations allowed (must be at least 1)
|
|
889
|
+
* @returns A new async iterflow that will throw if limit is exceeded
|
|
890
|
+
* @throws {ValidationError} If maxIterations is not a positive integer
|
|
891
|
+
* @throws {OperationError} If iteration count exceeds maxIterations
|
|
892
|
+
* @example
|
|
893
|
+
* ```typescript
|
|
894
|
+
* // Safely process potentially infinite async iterator
|
|
895
|
+
* await asyncIter.range(Infinity).limit(1000).toArray(); // Throws after 1000 iterations
|
|
896
|
+
*
|
|
897
|
+
* // Regular finite iterator works normally
|
|
898
|
+
* await asyncIter([1, 2, 3]).limit(10).toArray(); // [1, 2, 3]
|
|
899
|
+
* ```
|
|
900
|
+
*/
|
|
901
|
+
limit(maxIterations: number): Asynciterflow<T>;
|
|
850
902
|
/**
|
|
851
903
|
* Maps each element to an async iterable and flattens the results.
|
|
852
904
|
*
|
|
@@ -950,13 +1002,20 @@ declare class Asynciterflow<T> implements AsyncIterable<T> {
|
|
|
950
1002
|
* Collects all elements into an array.
|
|
951
1003
|
* This is a terminal operation that consumes the async iterator.
|
|
952
1004
|
*
|
|
953
|
-
* @
|
|
1005
|
+
* @param maxSize - Optional maximum array size. If provided and the iterator produces
|
|
1006
|
+
* more elements, collection stops at maxSize (no error thrown).
|
|
1007
|
+
* This is useful for safely collecting from potentially large iterators.
|
|
1008
|
+
* @returns Promise of array containing all elements (up to maxSize if specified)
|
|
1009
|
+
* @throws {ValidationError} If maxSize is provided but not a positive integer
|
|
954
1010
|
* @example
|
|
955
1011
|
* ```typescript
|
|
956
1012
|
* await asyncIter([1, 2, 3]).map(async x => x * 2).toArray(); // [2, 4, 6]
|
|
1013
|
+
*
|
|
1014
|
+
* // Safely collect from large async iterator
|
|
1015
|
+
* await asyncIter(infiniteStream).toArray(1000); // First 1000 items
|
|
957
1016
|
* ```
|
|
958
1017
|
*/
|
|
959
|
-
toArray(): Promise<T[]>;
|
|
1018
|
+
toArray(maxSize?: number): Promise<T[]>;
|
|
960
1019
|
/**
|
|
961
1020
|
* Counts the total number of elements in the async iterator.
|
|
962
1021
|
* This is a terminal operation that consumes the async iterator.
|
|
@@ -1545,6 +1604,80 @@ declare class Asynciterflow<T> implements AsyncIterable<T> {
|
|
|
1545
1604
|
* ```
|
|
1546
1605
|
*/
|
|
1547
1606
|
onError(handler: (error: unknown, value?: T) => void | Promise<void>): Asynciterflow<T>;
|
|
1607
|
+
/**
|
|
1608
|
+
* Adds a timeout to async iteration operations.
|
|
1609
|
+
* If any single iteration (next() call) takes longer than the specified timeout,
|
|
1610
|
+
* a TimeoutError is thrown. Each iteration gets its own timeout window.
|
|
1611
|
+
*
|
|
1612
|
+
* @param ms - Timeout duration in milliseconds (must be positive)
|
|
1613
|
+
* @returns A new async iterflow with timeout protection
|
|
1614
|
+
* @throws {ValidationError} If ms is not a positive number
|
|
1615
|
+
* @throws {TimeoutError} If any iteration exceeds the timeout
|
|
1616
|
+
* @example
|
|
1617
|
+
* ```typescript
|
|
1618
|
+
* // Protect against slow async operations
|
|
1619
|
+
* await asyncIter([1, 2, 3])
|
|
1620
|
+
* .map(async x => {
|
|
1621
|
+
* await slowOperation(x); // Each must complete within 5000ms
|
|
1622
|
+
* return x;
|
|
1623
|
+
* })
|
|
1624
|
+
* .timeout(5000)
|
|
1625
|
+
* .toArray();
|
|
1626
|
+
* ```
|
|
1627
|
+
*/
|
|
1628
|
+
timeout(ms: number): Asynciterflow<T>;
|
|
1629
|
+
/**
|
|
1630
|
+
* Adds AbortSignal support to the async iteration.
|
|
1631
|
+
* If the signal is aborted, iteration stops immediately with an AbortError.
|
|
1632
|
+
* Checks the signal before each iteration and listens for abort events.
|
|
1633
|
+
*
|
|
1634
|
+
* @param signal - AbortSignal to control iteration cancellation
|
|
1635
|
+
* @returns A new async iterflow with abort support
|
|
1636
|
+
* @throws {AbortError} If the signal is aborted
|
|
1637
|
+
* @example
|
|
1638
|
+
* ```typescript
|
|
1639
|
+
* const controller = new AbortController();
|
|
1640
|
+
*
|
|
1641
|
+
* // Cancel after 5 seconds
|
|
1642
|
+
* setTimeout(() => controller.abort('Timeout reached'), 5000);
|
|
1643
|
+
*
|
|
1644
|
+
* try {
|
|
1645
|
+
* await asyncIter(largeDataset)
|
|
1646
|
+
* .withSignal(controller.signal)
|
|
1647
|
+
* .map(processItem)
|
|
1648
|
+
* .toArray();
|
|
1649
|
+
* } catch (error) {
|
|
1650
|
+
* if (error instanceof AbortError) {
|
|
1651
|
+
* console.log('Operation cancelled:', error.reason);
|
|
1652
|
+
* }
|
|
1653
|
+
* }
|
|
1654
|
+
* ```
|
|
1655
|
+
*/
|
|
1656
|
+
withSignal(signal: AbortSignal): Asynciterflow<T>;
|
|
1657
|
+
/**
|
|
1658
|
+
* Interleaves elements from this async iterator with elements from other async/sync iterables.
|
|
1659
|
+
* Takes one element from each iterable in round-robin fashion.
|
|
1660
|
+
*
|
|
1661
|
+
* @param others - Variable number of async/sync iterables to interleave with
|
|
1662
|
+
* @returns A new async iterflow with elements from all iterables interleaved
|
|
1663
|
+
* @example
|
|
1664
|
+
* ```typescript
|
|
1665
|
+
* await asyncIter([1, 2, 3]).interleave([4, 5, 6]).toArray(); // [1, 4, 2, 5, 3, 6]
|
|
1666
|
+
* ```
|
|
1667
|
+
*/
|
|
1668
|
+
interleave(...others: Array<AsyncIterable<T> | Iterable<T>>): Asynciterflow<T>;
|
|
1669
|
+
/**
|
|
1670
|
+
* Merges this async iterator with other sorted async/sync iterables into a single sorted async iterator.
|
|
1671
|
+
* Assumes all input iterables are already sorted in ascending order.
|
|
1672
|
+
*
|
|
1673
|
+
* @param others - Variable number of sorted async/sync iterables to merge with
|
|
1674
|
+
* @returns A new async iterflow with all elements merged in sorted order
|
|
1675
|
+
* @example
|
|
1676
|
+
* ```typescript
|
|
1677
|
+
* await asyncIter([1, 3, 5]).merge([2, 4, 6]).toArray(); // [1, 2, 3, 4, 5, 6]
|
|
1678
|
+
* ```
|
|
1679
|
+
*/
|
|
1680
|
+
merge(...others: Array<AsyncIterable<T> | Iterable<T>>): Asynciterflow<T>;
|
|
1548
1681
|
}
|
|
1549
1682
|
/**
|
|
1550
1683
|
* Creates an async iterflow instance from an async iterable or iterable.
|
|
@@ -1761,6 +1894,20 @@ declare class TypeConversionError extends iterflowError {
|
|
|
1761
1894
|
readonly expectedType: string;
|
|
1762
1895
|
constructor(value: unknown, expectedType: string, operation?: string);
|
|
1763
1896
|
}
|
|
1897
|
+
/**
|
|
1898
|
+
* Error thrown when an operation exceeds its timeout duration
|
|
1899
|
+
*/
|
|
1900
|
+
declare class TimeoutError extends iterflowError {
|
|
1901
|
+
readonly timeoutMs: number;
|
|
1902
|
+
constructor(timeoutMs: number, operation?: string);
|
|
1903
|
+
}
|
|
1904
|
+
/**
|
|
1905
|
+
* Error thrown when an operation is aborted via AbortSignal
|
|
1906
|
+
*/
|
|
1907
|
+
declare class AbortError extends iterflowError {
|
|
1908
|
+
readonly reason?: string;
|
|
1909
|
+
constructor(operation?: string, reason?: string);
|
|
1910
|
+
}
|
|
1764
1911
|
|
|
1765
1912
|
/**
|
|
1766
1913
|
* Input validation utilities for iterflow operations
|
|
@@ -2127,4 +2274,4 @@ declare namespace iter {
|
|
|
2127
2274
|
function chain<T>(...iterables: Iterable<T>[]): iterflow<T>;
|
|
2128
2275
|
}
|
|
2129
2276
|
|
|
2130
|
-
export { Asynciterflow, type DebugConfig, EmptySequenceError, type ErrorHandler, IndexOutOfBoundsError, OperationError, type Result, type RetryOptions, type TraceEntry, TypeConversionError, ValidationError, addTrace, asyncIter, clearTraces, disableDebug, enableDebug, errorBoundary, getDebugConfig, getTraceSummary, getTraces, getTracesForOperation, isDebugEnabled, iter, iterflow, iterflowError, safeComparator, safePredicate, toInteger, toNumber, toResult, toResultAsync, traceOperation, traceOperationAsync, tryCatch, tryCatchAsync, tryOr, validateComparator, validateFiniteNumber, validateFunction, validateIndex, validateIterable, validateNonEmpty, validateNonNegativeInteger, validateNonZero, validatePositiveInteger, validateRange, withDefault, withErrorRecovery, withRetry, withRetryAsync };
|
|
2277
|
+
export { AbortError, Asynciterflow, type DebugConfig, EmptySequenceError, type ErrorHandler, IndexOutOfBoundsError, OperationError, type Result, type RetryOptions, TimeoutError, type TraceEntry, TypeConversionError, ValidationError, addTrace, asyncIter, clearTraces, disableDebug, enableDebug, errorBoundary, getDebugConfig, getTraceSummary, getTraces, getTracesForOperation, isDebugEnabled, iter, iterflow, iterflowError, safeComparator, safePredicate, toInteger, toNumber, toResult, toResultAsync, traceOperation, traceOperationAsync, tryCatch, tryCatchAsync, tryOr, validateComparator, validateFiniteNumber, validateFunction, validateIndex, validateIterable, validateNonEmpty, validateNonNegativeInteger, validateNonZero, validatePositiveInteger, validateRange, withDefault, withErrorRecovery, withRetry, withRetryAsync };
|
package/dist/index.d.ts
CHANGED
|
@@ -73,6 +73,25 @@ declare class iterflow<T> implements Iterable<T> {
|
|
|
73
73
|
* ```
|
|
74
74
|
*/
|
|
75
75
|
take(limit: number): iterflow<T>;
|
|
76
|
+
/**
|
|
77
|
+
* Limits the maximum number of iterations to prevent infinite loops.
|
|
78
|
+
* Unlike `take()` which silently stops at the limit, this method throws
|
|
79
|
+
* an OperationError if the limit is exceeded, making infinite loops explicit.
|
|
80
|
+
*
|
|
81
|
+
* @param maxIterations - Maximum number of iterations allowed (must be at least 1)
|
|
82
|
+
* @returns A new iterflow that will throw if limit is exceeded
|
|
83
|
+
* @throws {ValidationError} If maxIterations is not a positive integer
|
|
84
|
+
* @throws {OperationError} If iteration count exceeds maxIterations
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* // Safely process potentially infinite iterator
|
|
88
|
+
* iter.range(Infinity).limit(1000).toArray(); // Throws after 1000 iterations
|
|
89
|
+
*
|
|
90
|
+
* // Regular finite iterator works normally
|
|
91
|
+
* iter([1, 2, 3]).limit(10).toArray(); // [1, 2, 3]
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
limit(maxIterations: number): iterflow<T>;
|
|
76
95
|
/**
|
|
77
96
|
* Skips the first `count` elements from the iterator.
|
|
78
97
|
*
|
|
@@ -205,13 +224,23 @@ declare class iterflow<T> implements Iterable<T> {
|
|
|
205
224
|
* Collects all elements into an array.
|
|
206
225
|
* This is a terminal operation that consumes the iterator.
|
|
207
226
|
*
|
|
208
|
-
* @
|
|
227
|
+
* @param maxSize - Optional maximum array size. If provided and the iterator produces
|
|
228
|
+
* more elements, collection stops at maxSize (no error thrown).
|
|
229
|
+
* This is useful for safely collecting from potentially large iterators.
|
|
230
|
+
* @returns Array containing all elements (up to maxSize if specified)
|
|
231
|
+
* @throws {ValidationError} If maxSize is provided but not a positive integer
|
|
209
232
|
* @example
|
|
210
233
|
* ```typescript
|
|
211
234
|
* iter([1, 2, 3]).map(x => x * 2).toArray(); // [2, 4, 6]
|
|
235
|
+
*
|
|
236
|
+
* // Safely collect from large/infinite iterator
|
|
237
|
+
* iter.range(Infinity).toArray(1000); // [0, 1, 2, ..., 999]
|
|
238
|
+
*
|
|
239
|
+
* // Works with finite iterators too
|
|
240
|
+
* iter([1, 2, 3]).toArray(10); // [1, 2, 3] (stops early)
|
|
212
241
|
* ```
|
|
213
242
|
*/
|
|
214
|
-
toArray(): T[];
|
|
243
|
+
toArray(maxSize?: number): T[];
|
|
215
244
|
/**
|
|
216
245
|
* Counts the total number of elements in the iterator.
|
|
217
246
|
* This is a terminal operation that consumes the iterator.
|
|
@@ -729,11 +758,15 @@ declare class iterflow<T> implements Iterable<T> {
|
|
|
729
758
|
/**
|
|
730
759
|
* Alias for stdDev() method for compatibility.
|
|
731
760
|
* Calculates the standard deviation of all numeric elements.
|
|
761
|
+
*
|
|
762
|
+
* @deprecated Use stdDev() instead. This alias will be removed in v1.0.0.
|
|
732
763
|
*/
|
|
733
764
|
stddev(this: iterflow<number>): number | undefined;
|
|
734
765
|
/**
|
|
735
766
|
* Alias for drop() method for compatibility.
|
|
736
767
|
* Skips the first `count` elements from the iterator.
|
|
768
|
+
*
|
|
769
|
+
* @deprecated Use drop() instead. This alias will be removed in v1.0.0.
|
|
737
770
|
*/
|
|
738
771
|
skip(count: number): iterflow<T>;
|
|
739
772
|
/**
|
|
@@ -847,6 +880,25 @@ declare class Asynciterflow<T> implements AsyncIterable<T> {
|
|
|
847
880
|
* ```
|
|
848
881
|
*/
|
|
849
882
|
drop(count: number): Asynciterflow<T>;
|
|
883
|
+
/**
|
|
884
|
+
* Limits the maximum number of iterations to prevent infinite loops.
|
|
885
|
+
* Unlike `take()` which silently stops at the limit, this method throws
|
|
886
|
+
* an OperationError if the limit is exceeded, making infinite loops explicit.
|
|
887
|
+
*
|
|
888
|
+
* @param maxIterations - Maximum number of iterations allowed (must be at least 1)
|
|
889
|
+
* @returns A new async iterflow that will throw if limit is exceeded
|
|
890
|
+
* @throws {ValidationError} If maxIterations is not a positive integer
|
|
891
|
+
* @throws {OperationError} If iteration count exceeds maxIterations
|
|
892
|
+
* @example
|
|
893
|
+
* ```typescript
|
|
894
|
+
* // Safely process potentially infinite async iterator
|
|
895
|
+
* await asyncIter.range(Infinity).limit(1000).toArray(); // Throws after 1000 iterations
|
|
896
|
+
*
|
|
897
|
+
* // Regular finite iterator works normally
|
|
898
|
+
* await asyncIter([1, 2, 3]).limit(10).toArray(); // [1, 2, 3]
|
|
899
|
+
* ```
|
|
900
|
+
*/
|
|
901
|
+
limit(maxIterations: number): Asynciterflow<T>;
|
|
850
902
|
/**
|
|
851
903
|
* Maps each element to an async iterable and flattens the results.
|
|
852
904
|
*
|
|
@@ -950,13 +1002,20 @@ declare class Asynciterflow<T> implements AsyncIterable<T> {
|
|
|
950
1002
|
* Collects all elements into an array.
|
|
951
1003
|
* This is a terminal operation that consumes the async iterator.
|
|
952
1004
|
*
|
|
953
|
-
* @
|
|
1005
|
+
* @param maxSize - Optional maximum array size. If provided and the iterator produces
|
|
1006
|
+
* more elements, collection stops at maxSize (no error thrown).
|
|
1007
|
+
* This is useful for safely collecting from potentially large iterators.
|
|
1008
|
+
* @returns Promise of array containing all elements (up to maxSize if specified)
|
|
1009
|
+
* @throws {ValidationError} If maxSize is provided but not a positive integer
|
|
954
1010
|
* @example
|
|
955
1011
|
* ```typescript
|
|
956
1012
|
* await asyncIter([1, 2, 3]).map(async x => x * 2).toArray(); // [2, 4, 6]
|
|
1013
|
+
*
|
|
1014
|
+
* // Safely collect from large async iterator
|
|
1015
|
+
* await asyncIter(infiniteStream).toArray(1000); // First 1000 items
|
|
957
1016
|
* ```
|
|
958
1017
|
*/
|
|
959
|
-
toArray(): Promise<T[]>;
|
|
1018
|
+
toArray(maxSize?: number): Promise<T[]>;
|
|
960
1019
|
/**
|
|
961
1020
|
* Counts the total number of elements in the async iterator.
|
|
962
1021
|
* This is a terminal operation that consumes the async iterator.
|
|
@@ -1545,6 +1604,80 @@ declare class Asynciterflow<T> implements AsyncIterable<T> {
|
|
|
1545
1604
|
* ```
|
|
1546
1605
|
*/
|
|
1547
1606
|
onError(handler: (error: unknown, value?: T) => void | Promise<void>): Asynciterflow<T>;
|
|
1607
|
+
/**
|
|
1608
|
+
* Adds a timeout to async iteration operations.
|
|
1609
|
+
* If any single iteration (next() call) takes longer than the specified timeout,
|
|
1610
|
+
* a TimeoutError is thrown. Each iteration gets its own timeout window.
|
|
1611
|
+
*
|
|
1612
|
+
* @param ms - Timeout duration in milliseconds (must be positive)
|
|
1613
|
+
* @returns A new async iterflow with timeout protection
|
|
1614
|
+
* @throws {ValidationError} If ms is not a positive number
|
|
1615
|
+
* @throws {TimeoutError} If any iteration exceeds the timeout
|
|
1616
|
+
* @example
|
|
1617
|
+
* ```typescript
|
|
1618
|
+
* // Protect against slow async operations
|
|
1619
|
+
* await asyncIter([1, 2, 3])
|
|
1620
|
+
* .map(async x => {
|
|
1621
|
+
* await slowOperation(x); // Each must complete within 5000ms
|
|
1622
|
+
* return x;
|
|
1623
|
+
* })
|
|
1624
|
+
* .timeout(5000)
|
|
1625
|
+
* .toArray();
|
|
1626
|
+
* ```
|
|
1627
|
+
*/
|
|
1628
|
+
timeout(ms: number): Asynciterflow<T>;
|
|
1629
|
+
/**
|
|
1630
|
+
* Adds AbortSignal support to the async iteration.
|
|
1631
|
+
* If the signal is aborted, iteration stops immediately with an AbortError.
|
|
1632
|
+
* Checks the signal before each iteration and listens for abort events.
|
|
1633
|
+
*
|
|
1634
|
+
* @param signal - AbortSignal to control iteration cancellation
|
|
1635
|
+
* @returns A new async iterflow with abort support
|
|
1636
|
+
* @throws {AbortError} If the signal is aborted
|
|
1637
|
+
* @example
|
|
1638
|
+
* ```typescript
|
|
1639
|
+
* const controller = new AbortController();
|
|
1640
|
+
*
|
|
1641
|
+
* // Cancel after 5 seconds
|
|
1642
|
+
* setTimeout(() => controller.abort('Timeout reached'), 5000);
|
|
1643
|
+
*
|
|
1644
|
+
* try {
|
|
1645
|
+
* await asyncIter(largeDataset)
|
|
1646
|
+
* .withSignal(controller.signal)
|
|
1647
|
+
* .map(processItem)
|
|
1648
|
+
* .toArray();
|
|
1649
|
+
* } catch (error) {
|
|
1650
|
+
* if (error instanceof AbortError) {
|
|
1651
|
+
* console.log('Operation cancelled:', error.reason);
|
|
1652
|
+
* }
|
|
1653
|
+
* }
|
|
1654
|
+
* ```
|
|
1655
|
+
*/
|
|
1656
|
+
withSignal(signal: AbortSignal): Asynciterflow<T>;
|
|
1657
|
+
/**
|
|
1658
|
+
* Interleaves elements from this async iterator with elements from other async/sync iterables.
|
|
1659
|
+
* Takes one element from each iterable in round-robin fashion.
|
|
1660
|
+
*
|
|
1661
|
+
* @param others - Variable number of async/sync iterables to interleave with
|
|
1662
|
+
* @returns A new async iterflow with elements from all iterables interleaved
|
|
1663
|
+
* @example
|
|
1664
|
+
* ```typescript
|
|
1665
|
+
* await asyncIter([1, 2, 3]).interleave([4, 5, 6]).toArray(); // [1, 4, 2, 5, 3, 6]
|
|
1666
|
+
* ```
|
|
1667
|
+
*/
|
|
1668
|
+
interleave(...others: Array<AsyncIterable<T> | Iterable<T>>): Asynciterflow<T>;
|
|
1669
|
+
/**
|
|
1670
|
+
* Merges this async iterator with other sorted async/sync iterables into a single sorted async iterator.
|
|
1671
|
+
* Assumes all input iterables are already sorted in ascending order.
|
|
1672
|
+
*
|
|
1673
|
+
* @param others - Variable number of sorted async/sync iterables to merge with
|
|
1674
|
+
* @returns A new async iterflow with all elements merged in sorted order
|
|
1675
|
+
* @example
|
|
1676
|
+
* ```typescript
|
|
1677
|
+
* await asyncIter([1, 3, 5]).merge([2, 4, 6]).toArray(); // [1, 2, 3, 4, 5, 6]
|
|
1678
|
+
* ```
|
|
1679
|
+
*/
|
|
1680
|
+
merge(...others: Array<AsyncIterable<T> | Iterable<T>>): Asynciterflow<T>;
|
|
1548
1681
|
}
|
|
1549
1682
|
/**
|
|
1550
1683
|
* Creates an async iterflow instance from an async iterable or iterable.
|
|
@@ -1761,6 +1894,20 @@ declare class TypeConversionError extends iterflowError {
|
|
|
1761
1894
|
readonly expectedType: string;
|
|
1762
1895
|
constructor(value: unknown, expectedType: string, operation?: string);
|
|
1763
1896
|
}
|
|
1897
|
+
/**
|
|
1898
|
+
* Error thrown when an operation exceeds its timeout duration
|
|
1899
|
+
*/
|
|
1900
|
+
declare class TimeoutError extends iterflowError {
|
|
1901
|
+
readonly timeoutMs: number;
|
|
1902
|
+
constructor(timeoutMs: number, operation?: string);
|
|
1903
|
+
}
|
|
1904
|
+
/**
|
|
1905
|
+
* Error thrown when an operation is aborted via AbortSignal
|
|
1906
|
+
*/
|
|
1907
|
+
declare class AbortError extends iterflowError {
|
|
1908
|
+
readonly reason?: string;
|
|
1909
|
+
constructor(operation?: string, reason?: string);
|
|
1910
|
+
}
|
|
1764
1911
|
|
|
1765
1912
|
/**
|
|
1766
1913
|
* Input validation utilities for iterflow operations
|
|
@@ -2127,4 +2274,4 @@ declare namespace iter {
|
|
|
2127
2274
|
function chain<T>(...iterables: Iterable<T>[]): iterflow<T>;
|
|
2128
2275
|
}
|
|
2129
2276
|
|
|
2130
|
-
export { Asynciterflow, type DebugConfig, EmptySequenceError, type ErrorHandler, IndexOutOfBoundsError, OperationError, type Result, type RetryOptions, type TraceEntry, TypeConversionError, ValidationError, addTrace, asyncIter, clearTraces, disableDebug, enableDebug, errorBoundary, getDebugConfig, getTraceSummary, getTraces, getTracesForOperation, isDebugEnabled, iter, iterflow, iterflowError, safeComparator, safePredicate, toInteger, toNumber, toResult, toResultAsync, traceOperation, traceOperationAsync, tryCatch, tryCatchAsync, tryOr, validateComparator, validateFiniteNumber, validateFunction, validateIndex, validateIterable, validateNonEmpty, validateNonNegativeInteger, validateNonZero, validatePositiveInteger, validateRange, withDefault, withErrorRecovery, withRetry, withRetryAsync };
|
|
2277
|
+
export { AbortError, Asynciterflow, type DebugConfig, EmptySequenceError, type ErrorHandler, IndexOutOfBoundsError, OperationError, type Result, type RetryOptions, TimeoutError, type TraceEntry, TypeConversionError, ValidationError, addTrace, asyncIter, clearTraces, disableDebug, enableDebug, errorBoundary, getDebugConfig, getTraceSummary, getTraces, getTracesForOperation, isDebugEnabled, iter, iterflow, iterflowError, safeComparator, safePredicate, toInteger, toNumber, toResult, toResultAsync, traceOperation, traceOperationAsync, tryCatch, tryCatchAsync, tryOr, validateComparator, validateFiniteNumber, validateFunction, validateIndex, validateIterable, validateNonEmpty, validateNonNegativeInteger, validateNonZero, validatePositiveInteger, validateRange, withDefault, withErrorRecovery, withRetry, withRetryAsync };
|