UNPKG

@naturalcycles/nodejs-lib

Version:
56 lines (55 loc) 2.1 kB
import type { AbortableSignal } from '@naturalcycles/js-lib'; import { ErrorMode } from '@naturalcycles/js-lib/error'; import type { IndexedMapper, Predicate } from '@naturalcycles/js-lib/types'; import { END, SKIP } from '@naturalcycles/js-lib/types'; import type { TransformOptions, TransformTyped } from '../stream.model.js'; import type { TransformMapStats } from './transformMap.js'; export interface TransformMapSyncOptions<IN = any, OUT = IN> extends TransformOptions { /** * @default true */ objectMode?: boolean; /** * Predicate to filter outgoing results (after mapper). * Allows to not emit all results. * * Defaults to "pass everything". * Simpler way to skip individual entries is to return SKIP symbol. */ predicate?: Predicate<OUT>; /** * @default THROW_IMMEDIATELY */ errorMode?: ErrorMode; /** * If defined - will be called on every error happening in the stream. * Called BEFORE observable will emit error (unless skipErrors is set to true). */ onError?: (err: Error, input: IN) => any; /** * A hook that is called when the last item is finished processing. * stats object is passed, containing countIn and countOut - * number of items that entered the transform and number of items that left it. * * Callback is called **before** [possible] Aggregated error is thrown, * and before [possible] THROW_IMMEDIATELY error. * * onDone callback will be called before Error is thrown. */ onDone?: (stats: TransformMapStats) => any; /** * Progress metric * * @default `stream` */ metric?: string; /** * Allows to abort (gracefully stop) the stream from inside the Transform. */ signal?: AbortableSignal; } /** * Sync (not async) version of transformMap. * Supposedly faster, for cases when async is not needed. */ export declare function transformMapSync<IN = any, OUT = IN>(mapper: IndexedMapper<IN, OUT | typeof SKIP | typeof END>, opt?: TransformMapSyncOptions): TransformTyped<IN, OUT>;