make-fetch 2.3.0 → 2.3.3
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/index.d.ts +74 -0
- package/index.js +3 -1
- package/package.json +2 -2
- package/tsconfig.json +11 -0
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
|
@@ -67,7 +67,9 @@ class FakeResponse {
|
|
|
67
67
|
|
|
68
68
|
async arrayBuffer () {
|
|
69
69
|
const buffer = await collectBuffers(this.body)
|
|
70
|
-
|
|
70
|
+
const {byteOffset, length} = buffer
|
|
71
|
+
const end = byteOffset + length
|
|
72
|
+
return buffer.buffer.slice(buffer.byteOffset, end)
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
async text () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "make-fetch",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.3",
|
|
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
|
},
|