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