UNPKG

1.58 kBTypeScriptView Raw
1/// <reference types="node" />
2import { Readable } from 'stream';
3import { CommonLogger } from '@naturalcycles/js-lib';
4import { AbortableTransform } from '../../index';
5import { TransformOptions, TransformTyped } from '../stream.model';
6export interface TransformLimitOptions extends TransformOptions {
7 /**
8 * Nullish value (e.g 0 or undefined) would mean "no limit"
9 */
10 limit?: number;
11 /**
12 * If provided (recommended!) - it will call readable.destroy() on limit.
13 * Without it - it will only stop the downstream consumers, but won't stop
14 * the Readable ("source" of the stream).
15 * It is almost always crucial to stop the Source too, so, please provide the Readable here!
16 */
17 sourceReadable?: Readable;
18 /**
19 * Please provide it (a Promise that resolves when the Stream is done, e.g finished consuming things)
20 * to be able to wait for Consumers before calling `readable.destroy`.
21 * Has no effect if `readable` is not provided.
22 */
23 streamDone?: Promise<void>;
24 logger?: CommonLogger;
25 /**
26 * Set to true to enable additional debug messages, e.g it'll log
27 * when readable still emits values after the limit is reached.
28 */
29 debug?: boolean;
30}
31/**
32 * Class only exists to be able to do `instanceof TransformLimit`
33 * and to set sourceReadable+streamDone to it in `_pipeline`.
34 */
35export declare class TransformLimit extends AbortableTransform {
36}
37/**
38 * 0 or falsy value means "no limit"
39 */
40export declare function transformLimit<IN>(opt?: TransformLimitOptions): TransformTyped<IN, IN>;