Completed
Push — master ( cdadad...8d09a6 )
by Dimas
36:02 queued 17:12
created

libs/typings/node/stream.d.ts   F

Complexity

Total Complexity 162
Complexity/F 1

Size

Lines of Code 351
Function Count 162

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 306
dl 0
loc 351
rs 2
c 0
b 0
f 0
wmc 162
mnd 0
bc 0
fnc 162
bpm 0
cpm 1
noi 0

52 Functions

Rating   Name   Duplication   Size   Complexity  
A Writable._writev 0 1 1
A Readable.on 0 2 1
A Writable.uncork 0 1 1
A Transform._flush 0 1 1
A Readable.emit 0 2 1
A stream.d.ts ➔ finished 0 1 1
A Transform._transform 0 1 1
A Writable.once 0 2 1
A Writable.end 0 1 1
A Writable._write 0 1 2
A Duplex.setDefaultEncoding 0 1 1
A Writable.removeListener 0 2 1
A Writable._destroy 0 1 1
A Duplex._write 0 1 1
A Readable.pause 0 1 1
A Duplex.uncork 0 1 1
A Readable.push 0 1 1
A Readable.addListener 0 13 1
A Writable.on 0 2 1
A Writable.emit 0 2 1
A Readable.from 0 4 1
A Writable.destroy 0 1 1
A Readable.wrap 0 1 1
A Duplex._final 0 1 1
A internal.pipe 0 1 1
A Writable.write 0 1 1
A Duplex.end 0 1 1
A Readable.removeListener 0 2 1
A stream.d.ts ➔ pipeline 0 2 1
A Readable.unpipe 0 1 1
A Readable.read 0 1 1
A Writable.setDefaultEncoding 0 1 1
A Writable.cork 0 1 1
A Readable._read 0 1 1
A Readable.resume 0 1 1
A Readable.prependOnceListener 0 2 1
A Readable._destroy 0 1 1
A Duplex.cork 0 1 1
A Writable.prependListener 0 2 1
A Readable.isPaused 0 1 1
A Readable.prependListener 0 2 1
A Duplex._destroy 0 1 1
A Readable.unshift 0 1 1
A Writable._final 0 1 1
A Writable.prependOnceListener 0 2 1
A Duplex.write 0 1 1
A Duplex._writev 0 1 1
A Writable.addListener 0 12 1
A Readable.setEncoding 0 1 1
A Readable.once 0 2 1
A stream.d.ts ➔ ___promisify__ 0 1 1
A Readable.destroy 0 1 1

How to fix   Complexity   

Complexity

Complex classes like libs/typings/node/stream.d.ts often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
declare module "stream" {
2
    import * as events from "events";
3
4
    class internal extends events.EventEmitter {
5
        pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean; }): T;
6
    }
7
8
    namespace internal {
9
        class Stream extends internal {
10
            constructor(opts?: ReadableOptions);
11
        }
12
13
        interface ReadableOptions {
14
            highWaterMark?: number;
15
            encoding?: BufferEncoding;
16
            objectMode?: boolean;
17
            read?(this: Readable, size: number): void;
18
            destroy?(this: Readable, error: Error | null, callback: (error: Error | null) => void): void;
19
            autoDestroy?: boolean;
20
        }
21
22
        class Readable extends Stream implements NodeJS.ReadableStream {
23
            /**
24
             * A utility method for creating Readable Streams out of iterators.
25
             */
26
            static from(iterable: Iterable<any> | AsyncIterable<any>, options?: ReadableOptions): Readable;
27
28
            readable: boolean;
29
            readonly readableEncoding: BufferEncoding | null;
30
            readonly readableEnded: boolean;
31
            readonly readableHighWaterMark: number;
32
            readonly readableLength: number;
33
            readonly readableObjectMode: boolean;
34
            destroyed: boolean;
35
            constructor(opts?: ReadableOptions);
36
            _read(size: number): void;
37
            read(size?: number): any;
38
            setEncoding(encoding: BufferEncoding): this;
39
            pause(): this;
40
            resume(): this;
41
            isPaused(): boolean;
42
            unpipe(destination?: NodeJS.WritableStream): this;
43
            unshift(chunk: any, encoding?: BufferEncoding): void;
44
            wrap(oldStream: NodeJS.ReadableStream): this;
45
            push(chunk: any, encoding?: BufferEncoding): boolean;
46
            _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
47
            destroy(error?: Error): void;
48
49
            /**
50
             * Event emitter
51
             * The defined events on documents including:
52
             * 1. close
53
             * 2. data
54
             * 3. end
55
             * 4. error
56
             * 5. pause
57
             * 6. readable
58
             * 7. resume
59
             */
60
            addListener(event: "close", listener: () => void): this;
61
            addListener(event: "data", listener: (chunk: any) => void): this;
62
            addListener(event: "end", listener: () => void): this;
63
            addListener(event: "error", listener: (err: Error) => void): this;
64
            addListener(event: "pause", listener: () => void): this;
65
            addListener(event: "readable", listener: () => void): this;
66
            addListener(event: "resume", listener: () => void): this;
67
            addListener(event: string | symbol, listener: (...args: any[]) => void): this;
68
69
            emit(event: "close"): boolean;
70
            emit(event: "data", chunk: any): boolean;
71
            emit(event: "end"): boolean;
72
            emit(event: "error", err: Error): boolean;
73
            emit(event: "pause"): boolean;
74
            emit(event: "readable"): boolean;
75
            emit(event: "resume"): boolean;
76
            emit(event: string | symbol, ...args: any[]): boolean;
77
78
            on(event: "close", listener: () => void): this;
79
            on(event: "data", listener: (chunk: any) => void): this;
80
            on(event: "end", listener: () => void): this;
81
            on(event: "error", listener: (err: Error) => void): this;
82
            on(event: "pause", listener: () => void): this;
83
            on(event: "readable", listener: () => void): this;
84
            on(event: "resume", listener: () => void): this;
85
            on(event: string | symbol, listener: (...args: any[]) => void): this;
86
87
            once(event: "close", listener: () => void): this;
88
            once(event: "data", listener: (chunk: any) => void): this;
89
            once(event: "end", listener: () => void): this;
90
            once(event: "error", listener: (err: Error) => void): this;
91
            once(event: "pause", listener: () => void): this;
92
            once(event: "readable", listener: () => void): this;
93
            once(event: "resume", listener: () => void): this;
94
            once(event: string | symbol, listener: (...args: any[]) => void): this;
95
96
            prependListener(event: "close", listener: () => void): this;
97
            prependListener(event: "data", listener: (chunk: any) => void): this;
98
            prependListener(event: "end", listener: () => void): this;
99
            prependListener(event: "error", listener: (err: Error) => void): this;
100
            prependListener(event: "pause", listener: () => void): this;
101
            prependListener(event: "readable", listener: () => void): this;
102
            prependListener(event: "resume", listener: () => void): this;
103
            prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
104
105
            prependOnceListener(event: "close", listener: () => void): this;
106
            prependOnceListener(event: "data", listener: (chunk: any) => void): this;
107
            prependOnceListener(event: "end", listener: () => void): this;
108
            prependOnceListener(event: "error", listener: (err: Error) => void): this;
109
            prependOnceListener(event: "pause", listener: () => void): this;
110
            prependOnceListener(event: "readable", listener: () => void): this;
111
            prependOnceListener(event: "resume", listener: () => void): this;
112
            prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
113
114
            removeListener(event: "close", listener: () => void): this;
115
            removeListener(event: "data", listener: (chunk: any) => void): this;
116
            removeListener(event: "end", listener: () => void): this;
117
            removeListener(event: "error", listener: (err: Error) => void): this;
118
            removeListener(event: "pause", listener: () => void): this;
119
            removeListener(event: "readable", listener: () => void): this;
120
            removeListener(event: "resume", listener: () => void): this;
121
            removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
122
123
            [Symbol.asyncIterator](): AsyncIterableIterator<any>;
124
        }
125
126
        interface WritableOptions {
127
            highWaterMark?: number;
128
            decodeStrings?: boolean;
129
            defaultEncoding?: BufferEncoding;
130
            objectMode?: boolean;
131
            emitClose?: boolean;
132
            write?(this: Writable, chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
133
            writev?(this: Writable, chunks: Array<{ chunk: any, encoding: BufferEncoding }>, callback: (error?: Error | null) => void): void;
134
            destroy?(this: Writable, error: Error | null, callback: (error: Error | null) => void): void;
135
            final?(this: Writable, callback: (error?: Error | null) => void): void;
136
            autoDestroy?: boolean;
137
        }
138
139
        class Writable extends Stream implements NodeJS.WritableStream {
140
            readonly writable: boolean;
141
            readonly writableEnded: boolean;
142
            readonly writableFinished: boolean;
143
            readonly writableHighWaterMark: number;
144
            readonly writableLength: number;
145
            readonly writableObjectMode: boolean;
146
            readonly writableCorked: number;
147
            destroyed: boolean;
148
            constructor(opts?: WritableOptions);
149
            _write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
150
            _writev?(chunks: Array<{ chunk: any, encoding: BufferEncoding }>, callback: (error?: Error | null) => void): void;
151
            _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
152
            _final(callback: (error?: Error | null) => void): void;
153
            write(chunk: any, cb?: (error: Error | null | undefined) => void): boolean;
154
            write(chunk: any, encoding: BufferEncoding, cb?: (error: Error | null | undefined) => void): boolean;
155
            setDefaultEncoding(encoding: BufferEncoding): this;
156
            end(cb?: () => void): void;
157
            end(chunk: any, cb?: () => void): void;
158
            end(chunk: any, encoding: BufferEncoding, cb?: () => void): void;
159
            cork(): void;
160
            uncork(): void;
161
            destroy(error?: Error): void;
162
163
            /**
164
             * Event emitter
165
             * The defined events on documents including:
166
             * 1. close
167
             * 2. drain
168
             * 3. error
169
             * 4. finish
170
             * 5. pipe
171
             * 6. unpipe
172
             */
173
            addListener(event: "close", listener: () => void): this;
174
            addListener(event: "drain", listener: () => void): this;
175
            addListener(event: "error", listener: (err: Error) => void): this;
176
            addListener(event: "finish", listener: () => void): this;
177
            addListener(event: "pipe", listener: (src: Readable) => void): this;
178
            addListener(event: "unpipe", listener: (src: Readable) => void): this;
179
            addListener(event: string | symbol, listener: (...args: any[]) => void): this;
180
181
            emit(event: "close"): boolean;
182
            emit(event: "drain"): boolean;
183
            emit(event: "error", err: Error): boolean;
184
            emit(event: "finish"): boolean;
185
            emit(event: "pipe", src: Readable): boolean;
186
            emit(event: "unpipe", src: Readable): boolean;
187
            emit(event: string | symbol, ...args: any[]): boolean;
188
189
            on(event: "close", listener: () => void): this;
190
            on(event: "drain", listener: () => void): this;
191
            on(event: "error", listener: (err: Error) => void): this;
192
            on(event: "finish", listener: () => void): this;
193
            on(event: "pipe", listener: (src: Readable) => void): this;
194
            on(event: "unpipe", listener: (src: Readable) => void): this;
195
            on(event: string | symbol, listener: (...args: any[]) => void): this;
196
197
            once(event: "close", listener: () => void): this;
198
            once(event: "drain", listener: () => void): this;
199
            once(event: "error", listener: (err: Error) => void): this;
200
            once(event: "finish", listener: () => void): this;
201
            once(event: "pipe", listener: (src: Readable) => void): this;
202
            once(event: "unpipe", listener: (src: Readable) => void): this;
203
            once(event: string | symbol, listener: (...args: any[]) => void): this;
204
205
            prependListener(event: "close", listener: () => void): this;
206
            prependListener(event: "drain", listener: () => void): this;
207
            prependListener(event: "error", listener: (err: Error) => void): this;
208
            prependListener(event: "finish", listener: () => void): this;
209
            prependListener(event: "pipe", listener: (src: Readable) => void): this;
210
            prependListener(event: "unpipe", listener: (src: Readable) => void): this;
211
            prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
212
213
            prependOnceListener(event: "close", listener: () => void): this;
214
            prependOnceListener(event: "drain", listener: () => void): this;
215
            prependOnceListener(event: "error", listener: (err: Error) => void): this;
216
            prependOnceListener(event: "finish", listener: () => void): this;
217
            prependOnceListener(event: "pipe", listener: (src: Readable) => void): this;
218
            prependOnceListener(event: "unpipe", listener: (src: Readable) => void): this;
219
            prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
220
221
            removeListener(event: "close", listener: () => void): this;
222
            removeListener(event: "drain", listener: () => void): this;
223
            removeListener(event: "error", listener: (err: Error) => void): this;
224
            removeListener(event: "finish", listener: () => void): this;
225
            removeListener(event: "pipe", listener: (src: Readable) => void): this;
226
            removeListener(event: "unpipe", listener: (src: Readable) => void): this;
227
            removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
228
        }
229
230
        interface DuplexOptions extends ReadableOptions, WritableOptions {
231
            allowHalfOpen?: boolean;
232
            readableObjectMode?: boolean;
233
            writableObjectMode?: boolean;
234
            readableHighWaterMark?: number;
235
            writableHighWaterMark?: number;
236
            writableCorked?: number;
237
            read?(this: Duplex, size: number): void;
238
            write?(this: Duplex, chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
239
            writev?(this: Duplex, chunks: Array<{ chunk: any, encoding: BufferEncoding }>, callback: (error?: Error | null) => void): void;
240
            final?(this: Duplex, callback: (error?: Error | null) => void): void;
241
            destroy?(this: Duplex, error: Error | null, callback: (error: Error | null) => void): void;
242
        }
243
244
        // Note: Duplex extends both Readable and Writable.
245
        class Duplex extends Readable implements Writable {
246
            readonly writable: boolean;
247
            readonly writableEnded: boolean;
248
            readonly writableFinished: boolean;
249
            readonly writableHighWaterMark: number;
250
            readonly writableLength: number;
251
            readonly writableObjectMode: boolean;
252
            readonly writableCorked: number;
253
            constructor(opts?: DuplexOptions);
254
            _write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
255
            _writev?(chunks: Array<{ chunk: any, encoding: BufferEncoding }>, callback: (error?: Error | null) => void): void;
256
            _destroy(error: Error | null, callback: (error: Error | null) => void): void;
257
            _final(callback: (error?: Error | null) => void): void;
258
            write(chunk: any, encoding?: BufferEncoding, cb?: (error: Error | null | undefined) => void): boolean;
259
            write(chunk: any, cb?: (error: Error | null | undefined) => void): boolean;
260
            setDefaultEncoding(encoding: BufferEncoding): this;
261
            end(cb?: () => void): void;
262
            end(chunk: any, cb?: () => void): void;
263
            end(chunk: any, encoding?: BufferEncoding, cb?: () => void): void;
264
            cork(): void;
265
            uncork(): void;
266
        }
267
268
        type TransformCallback = (error?: Error | null, data?: any) => void;
269
270
        interface TransformOptions extends DuplexOptions {
271
            read?(this: Transform, size: number): void;
272
            write?(this: Transform, chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
273
            writev?(this: Transform, chunks: Array<{ chunk: any, encoding: BufferEncoding }>, callback: (error?: Error | null) => void): void;
274
            final?(this: Transform, callback: (error?: Error | null) => void): void;
275
            destroy?(this: Transform, error: Error | null, callback: (error: Error | null) => void): void;
276
            transform?(this: Transform, chunk: any, encoding: BufferEncoding, callback: TransformCallback): void;
277
            flush?(this: Transform, callback: TransformCallback): void;
278
        }
279
280
        class Transform extends Duplex {
281
            constructor(opts?: TransformOptions);
282
            _transform(chunk: any, encoding: BufferEncoding, callback: TransformCallback): void;
283
            _flush(callback: TransformCallback): void;
284
        }
285
286
        class PassThrough extends Transform { }
287
288
        interface FinishedOptions {
289
            error?: boolean;
290
            readable?: boolean;
291
            writable?: boolean;
292
        }
293
        function finished(stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream, options: FinishedOptions, callback: (err?: NodeJS.ErrnoException | null) => void): () => void;
294
        function finished(stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream, callback: (err?: NodeJS.ErrnoException | null) => void): () => void;
295
        namespace finished {
296
            function __promisify__(stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream, options?: FinishedOptions): Promise<void>;
297
        }
298
299
        function pipeline<T extends NodeJS.WritableStream>(stream1: NodeJS.ReadableStream, stream2: T, callback?: (err: NodeJS.ErrnoException | null) => void): T;
300
        function pipeline<T extends NodeJS.WritableStream>(stream1: NodeJS.ReadableStream, stream2: NodeJS.ReadWriteStream, stream3: T, callback?: (err: NodeJS.ErrnoException | null) => void): T;
301
        function pipeline<T extends NodeJS.WritableStream>(
302
            stream1: NodeJS.ReadableStream,
303
            stream2: NodeJS.ReadWriteStream,
304
            stream3: NodeJS.ReadWriteStream,
305
            stream4: T,
306
            callback?: (err: NodeJS.ErrnoException | null) => void,
307
        ): T;
308
        function pipeline<T extends NodeJS.WritableStream>(
309
            stream1: NodeJS.ReadableStream,
310
            stream2: NodeJS.ReadWriteStream,
311
            stream3: NodeJS.ReadWriteStream,
312
            stream4: NodeJS.ReadWriteStream,
313
            stream5: T,
314
            callback?: (err: NodeJS.ErrnoException | null) => void,
315
        ): T;
316
        function pipeline(streams: Array<NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream>, callback?: (err: NodeJS.ErrnoException | null) => void): NodeJS.WritableStream;
317
        function pipeline(
318
            stream1: NodeJS.ReadableStream,
319
            stream2: NodeJS.ReadWriteStream | NodeJS.WritableStream,
320
            ...streams: Array<NodeJS.ReadWriteStream | NodeJS.WritableStream | ((err: NodeJS.ErrnoException | null) => void)>,
321
        ): NodeJS.WritableStream;
322
        namespace pipeline {
323
            function __promisify__(stream1: NodeJS.ReadableStream, stream2: NodeJS.WritableStream): Promise<void>;
324
            function __promisify__(stream1: NodeJS.ReadableStream, stream2: NodeJS.ReadWriteStream, stream3: NodeJS.WritableStream): Promise<void>;
325
            function __promisify__(stream1: NodeJS.ReadableStream, stream2: NodeJS.ReadWriteStream, stream3: NodeJS.ReadWriteStream, stream4: NodeJS.WritableStream): Promise<void>;
326
            function __promisify__(
327
                stream1: NodeJS.ReadableStream,
328
                stream2: NodeJS.ReadWriteStream,
329
                stream3: NodeJS.ReadWriteStream,
330
                stream4: NodeJS.ReadWriteStream,
331
                stream5: NodeJS.WritableStream,
332
            ): Promise<void>;
333
            function __promisify__(streams: Array<NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream>): Promise<void>;
334
            function __promisify__(
335
                stream1: NodeJS.ReadableStream,
336
                stream2: NodeJS.ReadWriteStream | NodeJS.WritableStream,
337
                ...streams: Array<NodeJS.ReadWriteStream | NodeJS.WritableStream>,
338
            ): Promise<void>;
339
        }
340
341
        interface Pipe {
342
            close(): void;
343
            hasRef(): boolean;
344
            ref(): void;
345
            unref(): void;
346
        }
347
    }
348
349
    export = internal;
350
}
351