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