-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.d.ts
47 lines (40 loc) · 1.51 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
export interface Options {
/**
* Setting this to true will yield an array. In other words; instead of yielding once for every payload—we collect
* all complete payloads for a chunk and then yield.
*
* @default false
*/
multiple: boolean;
}
export type Part<Body, Fallback> =
| { json: false; headers: Record<string, string>; body: Fallback }
| { json: true; headers: Record<string, string>; body: Body };
// TODO: is there a way to compose the `meros/{node,browser}` here without having to duplicate the entire signature? And maintain jsdocs
// -- NODE
import type { IncomingMessage } from 'node:http';
export function meros<T = object>(
response: IncomingMessage,
options: { multiple: true },
): Promise<IncomingMessage | AsyncGenerator<ReadonlyArray<Part<T, Buffer>>>>;
export function meros<T = object>(
response: IncomingMessage,
options?: { multiple: false },
): Promise<IncomingMessage | AsyncGenerator<Part<T, Buffer>>>;
export function meros<T = object>(
response: IncomingMessage,
options?: Options,
): Promise<IncomingMessage | AsyncGenerator<Part<T, Buffer>>>;
// -- BROWSER
export function meros<T = object>(
response: Response,
options: { multiple: true },
): Promise<Response | AsyncGenerator<ReadonlyArray<Part<T, string>>>>;
export function meros<T = object>(
response: Response,
options?: { multiple: false },
): Promise<Response | AsyncGenerator<Part<T, string>>>;
export function meros<T = object>(
response: Response,
options?: Options,
): Promise<Response | AsyncGenerator<Part<T, string>>>;