@whatwg-node/node-fetch 0.7.8-alpha-20250124174946-bf76ab63fc7e7c5ee6898f3bf12f95ef0ac79a63 → 0.7.8-alpha-20250205002109-e61c2d65aed8aa582581368511e66b20e33632b8
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/cjs/Request.js +2 -10
- package/cjs/WritableStream.js +6 -46
- package/cjs/fetch.js +4 -31
- package/cjs/fetchCurl.js +6 -10
- package/cjs/fetchNodeHttp.js +3 -3
- package/esm/Request.js +2 -10
- package/esm/WritableStream.js +6 -46
- package/esm/fetch.js +5 -32
- package/esm/fetchCurl.js +6 -10
- package/esm/fetchNodeHttp.js +3 -3
- package/package.json +1 -1
- package/typings/Request.d.cts +1 -2
- package/typings/Request.d.ts +1 -2
package/cjs/Request.js
CHANGED
@@ -57,7 +57,7 @@ class PonyfillRequest extends Body_js_1.PonyfillBody {
|
|
57
57
|
this.redirect = requestInit?.redirect || 'follow';
|
58
58
|
this.referrer = requestInit?.referrer || 'about:client';
|
59
59
|
this.referrerPolicy = requestInit?.referrerPolicy || 'no-referrer';
|
60
|
-
this.
|
60
|
+
this.signal = requestInit?.signal || new AbortController().signal;
|
61
61
|
this.headersSerializer = requestInit?.headersSerializer;
|
62
62
|
this.duplex = requestInit?.duplex || 'half';
|
63
63
|
this.destination = 'document';
|
@@ -117,15 +117,7 @@ class PonyfillRequest extends Body_js_1.PonyfillBody {
|
|
117
117
|
}
|
118
118
|
duplex;
|
119
119
|
agent;
|
120
|
-
|
121
|
-
get signal() {
|
122
|
-
// Create a new signal only if needed
|
123
|
-
// Because the creation of signal is expensive
|
124
|
-
if (!this._signal) {
|
125
|
-
this._signal = new AbortController().signal;
|
126
|
-
}
|
127
|
-
return this._signal;
|
128
|
-
}
|
120
|
+
signal;
|
129
121
|
clone() {
|
130
122
|
return this;
|
131
123
|
}
|
package/cjs/WritableStream.js
CHANGED
@@ -44,55 +44,15 @@ class PonyfillWritableStream {
|
|
44
44
|
},
|
45
45
|
});
|
46
46
|
this.writable = writable;
|
47
|
-
|
48
|
-
let reason;
|
47
|
+
const abortCtrl = new AbortController();
|
49
48
|
const controller = {
|
50
|
-
signal:
|
51
|
-
|
52
|
-
|
53
|
-
},
|
54
|
-
get reason() {
|
55
|
-
return reason;
|
56
|
-
},
|
57
|
-
get aborted() {
|
58
|
-
return writable.destroyed;
|
59
|
-
},
|
60
|
-
addEventListener: (_event, eventListener) => {
|
61
|
-
writable.once('error', eventListener);
|
62
|
-
writable.once('close', eventListener);
|
63
|
-
},
|
64
|
-
removeEventListener: (_event, eventListener) => {
|
65
|
-
writable.off('error', eventListener);
|
66
|
-
writable.off('close', eventListener);
|
67
|
-
},
|
68
|
-
dispatchEvent: (_event) => {
|
69
|
-
return false;
|
70
|
-
},
|
71
|
-
get onabort() {
|
72
|
-
return onabort;
|
73
|
-
},
|
74
|
-
set onabort(value) {
|
75
|
-
if (onabort) {
|
76
|
-
this.removeEventListener('abort', onabort);
|
77
|
-
}
|
78
|
-
onabort = value;
|
79
|
-
if (onabort) {
|
80
|
-
this.addEventListener('abort', onabort);
|
81
|
-
}
|
82
|
-
},
|
83
|
-
throwIfAborted() {
|
84
|
-
if (writable.destroyed) {
|
85
|
-
throw reason;
|
86
|
-
}
|
87
|
-
},
|
88
|
-
},
|
89
|
-
error: e => {
|
90
|
-
this.writable.destroy(e);
|
49
|
+
signal: abortCtrl.signal,
|
50
|
+
error(e) {
|
51
|
+
writable.destroy(e);
|
91
52
|
},
|
92
53
|
};
|
93
|
-
|
94
|
-
|
95
|
-
});
|
54
|
+
writable.once('error', err => abortCtrl.abort(err));
|
55
|
+
writable.once('close', () => abortCtrl.abort());
|
96
56
|
}
|
97
57
|
else {
|
98
58
|
this.writable = new node_stream_1.Writable();
|
package/cjs/fetch.js
CHANGED
@@ -11,37 +11,10 @@ const Response_js_1 = require("./Response.js");
|
|
11
11
|
const URL_js_1 = require("./URL.js");
|
12
12
|
const utils_js_1 = require("./utils.js");
|
13
13
|
const BASE64_SUFFIX = ';base64';
|
14
|
-
|
14
|
+
function getResponseForFile(url) {
|
15
15
|
const path = (0, node_url_1.fileURLToPath)(url);
|
16
|
-
|
17
|
-
|
18
|
-
bigint: true,
|
19
|
-
});
|
20
|
-
const readable = (0, node_fs_1.createReadStream)(path);
|
21
|
-
return new Response_js_1.PonyfillResponse(readable, {
|
22
|
-
status: 200,
|
23
|
-
statusText: 'OK',
|
24
|
-
headers: {
|
25
|
-
'content-type': 'application/octet-stream',
|
26
|
-
'last-modified': stats.mtime.toUTCString(),
|
27
|
-
},
|
28
|
-
});
|
29
|
-
}
|
30
|
-
catch (err) {
|
31
|
-
if (err.code === 'ENOENT') {
|
32
|
-
return new Response_js_1.PonyfillResponse(null, {
|
33
|
-
status: 404,
|
34
|
-
statusText: 'Not Found',
|
35
|
-
});
|
36
|
-
}
|
37
|
-
else if (err.code === 'EACCES') {
|
38
|
-
return new Response_js_1.PonyfillResponse(null, {
|
39
|
-
status: 403,
|
40
|
-
statusText: 'Forbidden',
|
41
|
-
});
|
42
|
-
}
|
43
|
-
throw err;
|
44
|
-
}
|
16
|
+
const readable = (0, node_fs_1.createReadStream)(path);
|
17
|
+
return new Response_js_1.PonyfillResponse(readable);
|
45
18
|
}
|
46
19
|
function getResponseForDataUri(url) {
|
47
20
|
const [mimeType = 'text/plain', ...datas] = url.substring(5).split(',');
|
@@ -93,7 +66,7 @@ function fetchPonyfill(info, init) {
|
|
93
66
|
}
|
94
67
|
if (fetchRequest.url.startsWith('file:')) {
|
95
68
|
const response = getResponseForFile(fetchRequest.url);
|
96
|
-
return response;
|
69
|
+
return (0, utils_js_1.fakePromise)(response);
|
97
70
|
}
|
98
71
|
if (fetchRequest.url.startsWith('blob:')) {
|
99
72
|
const response = getResponseForBlob(fetchRequest.url);
|
package/cjs/fetchCurl.js
CHANGED
@@ -22,11 +22,7 @@ function fetchCurl(fetchRequest) {
|
|
22
22
|
}
|
23
23
|
curlHandle.enable(CurlFeature.StreamResponse);
|
24
24
|
curlHandle.setStreamProgressCallback(function () {
|
25
|
-
return fetchRequest
|
26
|
-
? process.env.DEBUG
|
27
|
-
? CurlProgressFunc.Continue
|
28
|
-
: 1
|
29
|
-
: 0;
|
25
|
+
return fetchRequest.signal.aborted ? (process.env.DEBUG ? CurlProgressFunc.Continue : 1) : 0;
|
30
26
|
});
|
31
27
|
if (fetchRequest['bodyType'] === 'String') {
|
32
28
|
curlHandle.setOpt('POSTFIELDS', fetchRequest['bodyInit']);
|
@@ -73,8 +69,8 @@ function fetchCurl(fetchRequest) {
|
|
73
69
|
}
|
74
70
|
}
|
75
71
|
}
|
76
|
-
if (fetchRequest
|
77
|
-
fetchRequest
|
72
|
+
if (fetchRequest.signal) {
|
73
|
+
fetchRequest.signal.addEventListener('abort', onAbort, { once: true });
|
78
74
|
}
|
79
75
|
curlHandle.once('end', function endListener() {
|
80
76
|
try {
|
@@ -83,8 +79,8 @@ function fetchCurl(fetchRequest) {
|
|
83
79
|
catch (e) {
|
84
80
|
deferredPromise.reject(e);
|
85
81
|
}
|
86
|
-
if (fetchRequest
|
87
|
-
fetchRequest
|
82
|
+
if (fetchRequest.signal) {
|
83
|
+
fetchRequest.signal.removeEventListener('abort', onAbort);
|
88
84
|
}
|
89
85
|
});
|
90
86
|
curlHandle.once('error', function errorListener(error) {
|
@@ -108,7 +104,7 @@ function fetchCurl(fetchRequest) {
|
|
108
104
|
const outputStream = new node_stream_1.PassThrough();
|
109
105
|
(0, promises_1.pipeline)(stream, outputStream, {
|
110
106
|
end: true,
|
111
|
-
signal: fetchRequest
|
107
|
+
signal: fetchRequest.signal,
|
112
108
|
})
|
113
109
|
.then(() => {
|
114
110
|
if (!stream.destroyed) {
|
package/cjs/fetchNodeHttp.js
CHANGED
@@ -39,7 +39,7 @@ function fetchNodeHttp(fetchRequest) {
|
|
39
39
|
nodeRequest = requestFn(fetchRequest.parsedUrl, {
|
40
40
|
method: fetchRequest.method,
|
41
41
|
headers: nodeHeaders,
|
42
|
-
signal: fetchRequest
|
42
|
+
signal: fetchRequest.signal,
|
43
43
|
agent: fetchRequest.agent,
|
44
44
|
});
|
45
45
|
}
|
@@ -47,7 +47,7 @@ function fetchNodeHttp(fetchRequest) {
|
|
47
47
|
nodeRequest = requestFn(fetchRequest.url, {
|
48
48
|
method: fetchRequest.method,
|
49
49
|
headers: nodeHeaders,
|
50
|
-
signal: fetchRequest
|
50
|
+
signal: fetchRequest.signal,
|
51
51
|
agent: fetchRequest.agent,
|
52
52
|
});
|
53
53
|
}
|
@@ -92,7 +92,7 @@ function fetchNodeHttp(fetchRequest) {
|
|
92
92
|
}
|
93
93
|
}
|
94
94
|
(0, promises_1.pipeline)(nodeResponse, outputStream, {
|
95
|
-
signal: fetchRequest
|
95
|
+
signal: fetchRequest.signal,
|
96
96
|
end: true,
|
97
97
|
})
|
98
98
|
.then(() => {
|
package/esm/Request.js
CHANGED
@@ -54,7 +54,7 @@ export class PonyfillRequest extends PonyfillBody {
|
|
54
54
|
this.redirect = requestInit?.redirect || 'follow';
|
55
55
|
this.referrer = requestInit?.referrer || 'about:client';
|
56
56
|
this.referrerPolicy = requestInit?.referrerPolicy || 'no-referrer';
|
57
|
-
this.
|
57
|
+
this.signal = requestInit?.signal || new AbortController().signal;
|
58
58
|
this.headersSerializer = requestInit?.headersSerializer;
|
59
59
|
this.duplex = requestInit?.duplex || 'half';
|
60
60
|
this.destination = 'document';
|
@@ -114,15 +114,7 @@ export class PonyfillRequest extends PonyfillBody {
|
|
114
114
|
}
|
115
115
|
duplex;
|
116
116
|
agent;
|
117
|
-
|
118
|
-
get signal() {
|
119
|
-
// Create a new signal only if needed
|
120
|
-
// Because the creation of signal is expensive
|
121
|
-
if (!this._signal) {
|
122
|
-
this._signal = new AbortController().signal;
|
123
|
-
}
|
124
|
-
return this._signal;
|
125
|
-
}
|
117
|
+
signal;
|
126
118
|
clone() {
|
127
119
|
return this;
|
128
120
|
}
|
package/esm/WritableStream.js
CHANGED
@@ -41,55 +41,15 @@ export class PonyfillWritableStream {
|
|
41
41
|
},
|
42
42
|
});
|
43
43
|
this.writable = writable;
|
44
|
-
|
45
|
-
let reason;
|
44
|
+
const abortCtrl = new AbortController();
|
46
45
|
const controller = {
|
47
|
-
signal:
|
48
|
-
|
49
|
-
|
50
|
-
},
|
51
|
-
get reason() {
|
52
|
-
return reason;
|
53
|
-
},
|
54
|
-
get aborted() {
|
55
|
-
return writable.destroyed;
|
56
|
-
},
|
57
|
-
addEventListener: (_event, eventListener) => {
|
58
|
-
writable.once('error', eventListener);
|
59
|
-
writable.once('close', eventListener);
|
60
|
-
},
|
61
|
-
removeEventListener: (_event, eventListener) => {
|
62
|
-
writable.off('error', eventListener);
|
63
|
-
writable.off('close', eventListener);
|
64
|
-
},
|
65
|
-
dispatchEvent: (_event) => {
|
66
|
-
return false;
|
67
|
-
},
|
68
|
-
get onabort() {
|
69
|
-
return onabort;
|
70
|
-
},
|
71
|
-
set onabort(value) {
|
72
|
-
if (onabort) {
|
73
|
-
this.removeEventListener('abort', onabort);
|
74
|
-
}
|
75
|
-
onabort = value;
|
76
|
-
if (onabort) {
|
77
|
-
this.addEventListener('abort', onabort);
|
78
|
-
}
|
79
|
-
},
|
80
|
-
throwIfAborted() {
|
81
|
-
if (writable.destroyed) {
|
82
|
-
throw reason;
|
83
|
-
}
|
84
|
-
},
|
85
|
-
},
|
86
|
-
error: e => {
|
87
|
-
this.writable.destroy(e);
|
46
|
+
signal: abortCtrl.signal,
|
47
|
+
error(e) {
|
48
|
+
writable.destroy(e);
|
88
49
|
},
|
89
50
|
};
|
90
|
-
|
91
|
-
|
92
|
-
});
|
51
|
+
writable.once('error', err => abortCtrl.abort(err));
|
52
|
+
writable.once('close', () => abortCtrl.abort());
|
93
53
|
}
|
94
54
|
else {
|
95
55
|
this.writable = new Writable();
|
package/esm/fetch.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
2
|
-
import { createReadStream
|
2
|
+
import { createReadStream } from 'node:fs';
|
3
3
|
import { fileURLToPath } from 'node:url';
|
4
4
|
import { fetchCurl } from './fetchCurl.js';
|
5
5
|
import { fetchNodeHttp } from './fetchNodeHttp.js';
|
@@ -8,37 +8,10 @@ import { PonyfillResponse } from './Response.js';
|
|
8
8
|
import { PonyfillURL } from './URL.js';
|
9
9
|
import { fakePromise } from './utils.js';
|
10
10
|
const BASE64_SUFFIX = ';base64';
|
11
|
-
|
11
|
+
function getResponseForFile(url) {
|
12
12
|
const path = fileURLToPath(url);
|
13
|
-
|
14
|
-
|
15
|
-
bigint: true,
|
16
|
-
});
|
17
|
-
const readable = createReadStream(path);
|
18
|
-
return new PonyfillResponse(readable, {
|
19
|
-
status: 200,
|
20
|
-
statusText: 'OK',
|
21
|
-
headers: {
|
22
|
-
'content-type': 'application/octet-stream',
|
23
|
-
'last-modified': stats.mtime.toUTCString(),
|
24
|
-
},
|
25
|
-
});
|
26
|
-
}
|
27
|
-
catch (err) {
|
28
|
-
if (err.code === 'ENOENT') {
|
29
|
-
return new PonyfillResponse(null, {
|
30
|
-
status: 404,
|
31
|
-
statusText: 'Not Found',
|
32
|
-
});
|
33
|
-
}
|
34
|
-
else if (err.code === 'EACCES') {
|
35
|
-
return new PonyfillResponse(null, {
|
36
|
-
status: 403,
|
37
|
-
statusText: 'Forbidden',
|
38
|
-
});
|
39
|
-
}
|
40
|
-
throw err;
|
41
|
-
}
|
13
|
+
const readable = createReadStream(path);
|
14
|
+
return new PonyfillResponse(readable);
|
42
15
|
}
|
43
16
|
function getResponseForDataUri(url) {
|
44
17
|
const [mimeType = 'text/plain', ...datas] = url.substring(5).split(',');
|
@@ -90,7 +63,7 @@ export function fetchPonyfill(info, init) {
|
|
90
63
|
}
|
91
64
|
if (fetchRequest.url.startsWith('file:')) {
|
92
65
|
const response = getResponseForFile(fetchRequest.url);
|
93
|
-
return response;
|
66
|
+
return fakePromise(response);
|
94
67
|
}
|
95
68
|
if (fetchRequest.url.startsWith('blob:')) {
|
96
69
|
const response = getResponseForBlob(fetchRequest.url);
|
package/esm/fetchCurl.js
CHANGED
@@ -19,11 +19,7 @@ export function fetchCurl(fetchRequest) {
|
|
19
19
|
}
|
20
20
|
curlHandle.enable(CurlFeature.StreamResponse);
|
21
21
|
curlHandle.setStreamProgressCallback(function () {
|
22
|
-
return fetchRequest
|
23
|
-
? process.env.DEBUG
|
24
|
-
? CurlProgressFunc.Continue
|
25
|
-
: 1
|
26
|
-
: 0;
|
22
|
+
return fetchRequest.signal.aborted ? (process.env.DEBUG ? CurlProgressFunc.Continue : 1) : 0;
|
27
23
|
});
|
28
24
|
if (fetchRequest['bodyType'] === 'String') {
|
29
25
|
curlHandle.setOpt('POSTFIELDS', fetchRequest['bodyInit']);
|
@@ -70,8 +66,8 @@ export function fetchCurl(fetchRequest) {
|
|
70
66
|
}
|
71
67
|
}
|
72
68
|
}
|
73
|
-
if (fetchRequest
|
74
|
-
fetchRequest
|
69
|
+
if (fetchRequest.signal) {
|
70
|
+
fetchRequest.signal.addEventListener('abort', onAbort, { once: true });
|
75
71
|
}
|
76
72
|
curlHandle.once('end', function endListener() {
|
77
73
|
try {
|
@@ -80,8 +76,8 @@ export function fetchCurl(fetchRequest) {
|
|
80
76
|
catch (e) {
|
81
77
|
deferredPromise.reject(e);
|
82
78
|
}
|
83
|
-
if (fetchRequest
|
84
|
-
fetchRequest
|
79
|
+
if (fetchRequest.signal) {
|
80
|
+
fetchRequest.signal.removeEventListener('abort', onAbort);
|
85
81
|
}
|
86
82
|
});
|
87
83
|
curlHandle.once('error', function errorListener(error) {
|
@@ -105,7 +101,7 @@ export function fetchCurl(fetchRequest) {
|
|
105
101
|
const outputStream = new PassThrough();
|
106
102
|
pipeline(stream, outputStream, {
|
107
103
|
end: true,
|
108
|
-
signal: fetchRequest
|
104
|
+
signal: fetchRequest.signal,
|
109
105
|
})
|
110
106
|
.then(() => {
|
111
107
|
if (!stream.destroyed) {
|
package/esm/fetchNodeHttp.js
CHANGED
@@ -36,7 +36,7 @@ export function fetchNodeHttp(fetchRequest) {
|
|
36
36
|
nodeRequest = requestFn(fetchRequest.parsedUrl, {
|
37
37
|
method: fetchRequest.method,
|
38
38
|
headers: nodeHeaders,
|
39
|
-
signal: fetchRequest
|
39
|
+
signal: fetchRequest.signal,
|
40
40
|
agent: fetchRequest.agent,
|
41
41
|
});
|
42
42
|
}
|
@@ -44,7 +44,7 @@ export function fetchNodeHttp(fetchRequest) {
|
|
44
44
|
nodeRequest = requestFn(fetchRequest.url, {
|
45
45
|
method: fetchRequest.method,
|
46
46
|
headers: nodeHeaders,
|
47
|
-
signal: fetchRequest
|
47
|
+
signal: fetchRequest.signal,
|
48
48
|
agent: fetchRequest.agent,
|
49
49
|
});
|
50
50
|
}
|
@@ -89,7 +89,7 @@ export function fetchNodeHttp(fetchRequest) {
|
|
89
89
|
}
|
90
90
|
}
|
91
91
|
pipeline(nodeResponse, outputStream, {
|
92
|
-
signal: fetchRequest
|
92
|
+
signal: fetchRequest.signal,
|
93
93
|
end: true,
|
94
94
|
})
|
95
95
|
.then(() => {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@whatwg-node/node-fetch",
|
3
|
-
"version": "0.7.8-alpha-
|
3
|
+
"version": "0.7.8-alpha-20250205002109-e61c2d65aed8aa582581368511e66b20e33632b8",
|
4
4
|
"description": "Fetch API implementation for Node",
|
5
5
|
"sideEffects": false,
|
6
6
|
"dependencies": {
|
package/typings/Request.d.cts
CHANGED
@@ -31,8 +31,7 @@ export declare class PonyfillRequest<TJSON = any> extends PonyfillBody<TJSON> im
|
|
31
31
|
get parsedUrl(): URL;
|
32
32
|
duplex: 'half' | 'full';
|
33
33
|
agent: HTTPAgent | HTTPSAgent | false | undefined;
|
34
|
-
|
35
|
-
get signal(): AbortSignal;
|
34
|
+
signal: AbortSignal;
|
36
35
|
clone(): PonyfillRequest<TJSON>;
|
37
36
|
[Symbol.toStringTag]: string;
|
38
37
|
}
|
package/typings/Request.d.ts
CHANGED
@@ -31,8 +31,7 @@ export declare class PonyfillRequest<TJSON = any> extends PonyfillBody<TJSON> im
|
|
31
31
|
get parsedUrl(): URL;
|
32
32
|
duplex: 'half' | 'full';
|
33
33
|
agent: HTTPAgent | HTTPSAgent | false | undefined;
|
34
|
-
|
35
|
-
get signal(): AbortSignal;
|
34
|
+
signal: AbortSignal;
|
36
35
|
clone(): PonyfillRequest<TJSON>;
|
37
36
|
[Symbol.toStringTag]: string;
|
38
37
|
}
|