-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.ts
83 lines (77 loc) · 1.74 KB
/
index.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { AbortController, AbortSignal } from "./lib/abort";
import { Body, DataBody, JsonBody, StreamBody } from "./lib/body";
import { Context, ContextOptions } from "./lib/context";
import { PushHandler } from "./lib/context-http2";
import { CookieJar } from "./lib/cookie-jar";
import {
AbortError,
DecodeFunction,
Decoder,
RequestInit,
FetchInit,
HttpProtocols,
Method,
OnTrailers,
TimeoutError,
HttpVersion,
} from "./lib/core";
import { Headers } from "./lib/headers";
import { Request } from "./lib/request";
import { Response } from "./lib/response";
const defaultContext = new Context( );
const setup =
( opts: Partial< ContextOptions > ) =>
defaultContext.setup( opts );
const fetch =
( input: string | Request, init?: Partial< FetchInit > ) =>
defaultContext.fetch( input, init );
const disconnect =
( url: string ) =>
defaultContext.disconnect( url );
const disconnectAll =
( ) =>
defaultContext.disconnectAll( );
const onPush =
( handler?: PushHandler ) =>
defaultContext.onPush( handler );
function context( opts?: Partial< ContextOptions > )
{
const ctx = new Context( opts );
return {
disconnect: ctx.disconnect.bind( ctx ) as typeof disconnect,
disconnectAll: ctx.disconnectAll.bind( ctx ) as typeof disconnectAll,
fetch: ctx.fetch.bind( ctx ) as typeof fetch,
onPush: ctx.onPush.bind( ctx ) as typeof onPush,
setup: ctx.setup.bind( ctx ) as typeof setup,
};
}
export {
setup,
context,
fetch,
disconnect,
disconnectAll,
onPush,
// Re-export
AbortController,
AbortSignal,
RequestInit,
FetchInit,
HttpProtocols,
Body,
JsonBody,
StreamBody,
DataBody,
Headers,
Request,
Response,
AbortError,
TimeoutError,
HttpVersion,
OnTrailers,
ContextOptions,
DecodeFunction,
Decoder,
CookieJar,
Method,
};