make-fetch 2.2.1 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/index.d.ts +74 -0
- package/index.js +2 -1
- package/package.json +2 -2
- package/tsconfig.json +11 -0
package/README.md
CHANGED
|
@@ -35,4 +35,4 @@ console.log(await response.text())
|
|
|
35
35
|
## Gotchas
|
|
36
36
|
|
|
37
37
|
- The `response.body` is an Async Iterable of Buffer objects rather than a WHATWG ReadableStream
|
|
38
|
-
- Eventually ReadableStream will become
|
|
38
|
+
- Eventually ReadableStream will become async iterable so you'll be able to iterate either normally
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
declare module 'make-fetch' {
|
|
2
|
+
export interface NormalizedRequest {
|
|
3
|
+
url: string
|
|
4
|
+
headers: RawHeaders
|
|
5
|
+
method: string
|
|
6
|
+
body: AsyncIterableIterator<Uint8Array>
|
|
7
|
+
referrer?: string
|
|
8
|
+
|
|
9
|
+
// Hard to add types for. 😂
|
|
10
|
+
signal?: any
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface HandlerResponse {
|
|
14
|
+
statusCode?: number
|
|
15
|
+
statusText?: string
|
|
16
|
+
headers?: RawHeaders
|
|
17
|
+
data?: AsyncIterableIterator<Uint8Array | string>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface RawHeaders {
|
|
21
|
+
[name: string]: string | undefined
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// TODO: Support actual fetch Headers
|
|
25
|
+
export interface Headers {
|
|
26
|
+
append(name: string, value: string) : void
|
|
27
|
+
delete(name: string) : void
|
|
28
|
+
entries() : IterableIterator<[string, string]>
|
|
29
|
+
get(name: string): string | undefined
|
|
30
|
+
has(name: string) : boolean
|
|
31
|
+
keys() : IterableIterator<string>
|
|
32
|
+
set(name: string, value: string) : void
|
|
33
|
+
values() : IterableIterator<string>
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface Request {
|
|
37
|
+
// This is kind of a pain to document
|
|
38
|
+
session?: any
|
|
39
|
+
signal?: any
|
|
40
|
+
|
|
41
|
+
url?: string
|
|
42
|
+
headers?: Headers | RawHeaders
|
|
43
|
+
method?: string,
|
|
44
|
+
body?: string | Uint8Array | AsyncIterableIterator<Uint8Array|string>,
|
|
45
|
+
referrer?: string,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface Body {
|
|
49
|
+
// TODO: Fill this in
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface Response {
|
|
53
|
+
url: string
|
|
54
|
+
headers: Headers
|
|
55
|
+
status: number
|
|
56
|
+
statusText: string
|
|
57
|
+
ok: boolean
|
|
58
|
+
useFinalURL: true
|
|
59
|
+
body: Body
|
|
60
|
+
arrayBuffer() : Promise<ArrayBuffer>
|
|
61
|
+
text(): Promise<string>
|
|
62
|
+
json(): Promise<any>
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface Fetch {
|
|
66
|
+
(request: string | Request, info? : Request): Promise<Response>
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface FetchHandler {
|
|
70
|
+
(request: NormalizedRequest): Promise<HandlerResponse>
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export default function makeFetch(handler: FetchHandler) : Fetch
|
|
74
|
+
}
|
package/index.js
CHANGED
|
@@ -14,6 +14,7 @@ module.exports = function makeFetch (handler) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const {
|
|
17
|
+
session,
|
|
17
18
|
url,
|
|
18
19
|
headers: rawHeaders,
|
|
19
20
|
method: rawMethod,
|
|
@@ -24,7 +25,7 @@ module.exports = function makeFetch (handler) {
|
|
|
24
25
|
|
|
25
26
|
const headers = rawHeaders ? headersToObject(rawHeaders) : {}
|
|
26
27
|
const method = (rawMethod || 'GET').toUpperCase()
|
|
27
|
-
const body = rawBody ? bodyToIterator(rawBody) : null
|
|
28
|
+
const body = rawBody ? bodyToIterator(rawBody, session) : null
|
|
28
29
|
|
|
29
30
|
const {
|
|
30
31
|
statusCode,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "make-fetch",
|
|
3
|
-
"version": "2.2
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"description": "Implement your own `fetch()` with node.js streams",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"concat-stream": "^2.0.0",
|
|
27
27
|
"fetch-headers": "^2.0.0",
|
|
28
|
-
"fetch-request-body-to-async-iterator": "^1.0.
|
|
28
|
+
"fetch-request-body-to-async-iterator": "^1.0.3",
|
|
29
29
|
"statuses": "^2.0.0",
|
|
30
30
|
"web-streams-polyfill": "^3.0.0"
|
|
31
31
|
},
|