1 | import { AsyncMapper, AsyncPredicate, ErrorMode } from '@naturalcycles/js-lib';
|
2 | import { TransformTyped } from '../stream.model';
|
3 | export interface TransformMapOptions<IN = any, OUT = IN> {
|
4 | /**
|
5 | * @default true
|
6 | */
|
7 | objectMode?: boolean;
|
8 | /**
|
9 | * @default false
|
10 | * Set true to support "multiMap" - possibility to return [] and emit 1 result for each item in the array.
|
11 | */
|
12 | flattenArrayOutput?: boolean;
|
13 | /**
|
14 | * Predicate to filter outgoing results (after mapper).
|
15 | * Allows to not emit all results.
|
16 | *
|
17 | * @default to filter out undefined/null values, but pass anything else
|
18 | *
|
19 | * Set to `r => r` (passthrough predicate) to pass ANY value (including undefined/null)
|
20 | */
|
21 | predicate?: AsyncPredicate<OUT>;
|
22 | /**
|
23 | * Number of concurrently pending promises returned by `mapper`.
|
24 | *
|
25 | * @default 16 (to match default highWatermark option for objectMode streams)
|
26 | */
|
27 | concurrency?: number;
|
28 | /**
|
29 | * @default THROW_IMMEDIATELY
|
30 | */
|
31 | errorMode?: ErrorMode;
|
32 | /**
|
33 | * If defined - will be called on every error happening in the stream.
|
34 | * Called BEFORE observable will emit error (unless skipErrors is set to true).
|
35 | */
|
36 | onError?: (err: Error, input: IN) => any;
|
37 | /**
|
38 | * Progress metric
|
39 | *
|
40 | * @default `stream`
|
41 | */
|
42 | metric?: string;
|
43 | /**
|
44 | * If defined - called BEFORE `final()` callback is called.
|
45 | */
|
46 | beforeFinal?: () => any;
|
47 | /**
|
48 | * If defined - called AFTER final chunk was processed.
|
49 | */
|
50 | afterFinal?: () => any;
|
51 | }
|
52 | export declare function notNullishPredicate(item: any): boolean;
|
53 | /**
|
54 | * Like pMap, but for streams.
|
55 | * Inspired by `through2`.
|
56 | * Main feature is concurrency control (implemented via `through2-concurrent`) and convenient options.
|
57 | * Using this allows native stream .pipe() to work and use backpressure.
|
58 | *
|
59 | * Only works in objectMode (due to through2Concurrent).
|
60 | *
|
61 | * Concurrency defaults to 16.
|
62 | *
|
63 | * If an Array is returned by `mapper` - it will be flattened and multiple results will be emitted from it. Tested by Array.isArray().
|
64 | */
|
65 | export declare function transformMap<IN = any, OUT = IN>(mapper: AsyncMapper<IN, OUT>, opt?: TransformMapOptions<IN, OUT>): TransformTyped<IN, OUT>;
|