@whatwg-node/node-fetch 0.7.23-alpha-20250725201224-a3738367f9a514964b76715b19d4bb76c0bc0411 → 0.7.23-alpha-20250726003115-27dea3e7c5dae7285bf9c837cce54f387e269df2
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/Body.js +2 -24
- package/cjs/Request.js +2 -0
- package/cjs/fetchCurl.js +5 -12
- package/cjs/fetchNodeHttp.js +5 -12
- package/cjs/utils.js +0 -44
- package/esm/Body.js +4 -26
- package/esm/Request.js +2 -0
- package/esm/fetchCurl.js +6 -13
- package/esm/fetchNodeHttp.js +7 -14
- package/esm/utils.js +0 -43
- package/package.json +1 -1
- package/typings/Body.d.cts +0 -1
- package/typings/Body.d.ts +0 -1
- package/typings/Request.d.cts +1 -0
- package/typings/Request.d.ts +1 -0
- package/typings/utils.d.cts +0 -6
- package/typings/utils.d.ts +0 -6
package/cjs/Body.js
CHANGED
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PonyfillBody = void 0;
|
4
4
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
5
5
|
const node_buffer_1 = require("node:buffer");
|
6
|
-
const node_http_1 = require("node:http");
|
7
6
|
const node_stream_1 = require("node:stream");
|
8
7
|
const busboy_1 = require("@fastify/busboy");
|
9
8
|
const promise_helpers_1 = require("@whatwg-node/promise-helpers");
|
@@ -28,12 +27,10 @@ class PonyfillBody {
|
|
28
27
|
bodyUsed = false;
|
29
28
|
contentType = null;
|
30
29
|
contentLength = null;
|
31
|
-
_signal = null;
|
32
30
|
constructor(bodyInit, options = {}) {
|
33
31
|
this.bodyInit = bodyInit;
|
34
32
|
this.options = options;
|
35
|
-
|
36
|
-
const { bodyFactory, contentType, contentLength, bodyType, buffer } = processBodyInit(bodyInit, options?.signal);
|
33
|
+
const { bodyFactory, contentType, contentLength, bodyType, buffer } = processBodyInit(bodyInit);
|
37
34
|
this._bodyFactory = bodyFactory;
|
38
35
|
this.contentType = contentType;
|
39
36
|
this.contentLength = contentLength;
|
@@ -218,9 +215,6 @@ class PonyfillBody {
|
|
218
215
|
limits: formDataLimits,
|
219
216
|
defCharset: 'utf-8',
|
220
217
|
});
|
221
|
-
if (this._signal) {
|
222
|
-
(0, node_stream_1.addAbortSignal)(this._signal, bb);
|
223
|
-
}
|
224
218
|
let completed = false;
|
225
219
|
const complete = (err) => {
|
226
220
|
if (completed)
|
@@ -373,7 +367,7 @@ class PonyfillBody {
|
|
373
367
|
}
|
374
368
|
}
|
375
369
|
exports.PonyfillBody = PonyfillBody;
|
376
|
-
function processBodyInit(bodyInit
|
370
|
+
function processBodyInit(bodyInit) {
|
377
371
|
if (bodyInit == null) {
|
378
372
|
return {
|
379
373
|
bodyFactory: () => null,
|
@@ -456,22 +450,6 @@ function processBodyInit(bodyInit, signal) {
|
|
456
450
|
},
|
457
451
|
};
|
458
452
|
}
|
459
|
-
if (bodyInit instanceof node_http_1.IncomingMessage) {
|
460
|
-
const passThrough = new node_stream_1.PassThrough();
|
461
|
-
(0, utils_js_1.pipeThrough)({
|
462
|
-
src: bodyInit,
|
463
|
-
dest: passThrough,
|
464
|
-
signal,
|
465
|
-
});
|
466
|
-
return {
|
467
|
-
bodyType: BodyInitType.Readable,
|
468
|
-
contentType: null,
|
469
|
-
contentLength: null,
|
470
|
-
bodyFactory() {
|
471
|
-
return new ReadableStream_js_1.PonyfillReadableStream(passThrough);
|
472
|
-
},
|
473
|
-
};
|
474
|
-
}
|
475
453
|
if (bodyInit instanceof node_stream_1.Readable) {
|
476
454
|
return {
|
477
455
|
bodyType: BodyInitType.Readable,
|
package/cjs/Request.js
CHANGED
@@ -76,6 +76,7 @@ class PonyfillRequest extends Body_js_1.PonyfillBody {
|
|
76
76
|
this.agent = requestInit.agent;
|
77
77
|
}
|
78
78
|
}
|
79
|
+
this._signal = requestInit?.signal || undefined;
|
79
80
|
}
|
80
81
|
headersSerializer;
|
81
82
|
cache;
|
@@ -91,6 +92,7 @@ class PonyfillRequest extends Body_js_1.PonyfillBody {
|
|
91
92
|
referrer;
|
92
93
|
referrerPolicy;
|
93
94
|
_url;
|
95
|
+
_signal;
|
94
96
|
get signal() {
|
95
97
|
this._signal ||= new AbortController().signal;
|
96
98
|
return this._signal;
|
package/cjs/fetchCurl.js
CHANGED
@@ -28,9 +28,6 @@ function fetchCurl(fetchRequest) {
|
|
28
28
|
else if (fetchRequest._signal) {
|
29
29
|
signal = fetchRequest._signal;
|
30
30
|
}
|
31
|
-
else {
|
32
|
-
signal = fetchRequest.signal;
|
33
|
-
}
|
34
31
|
curlHandle.setStreamProgressCallback(function () {
|
35
32
|
return signal?.aborted ? (process.env.DEBUG ? CurlProgressFunc.Continue : 1) : 0;
|
36
33
|
});
|
@@ -107,12 +104,8 @@ function fetchCurl(fetchRequest) {
|
|
107
104
|
}
|
108
105
|
});
|
109
106
|
curlHandle.once('stream', function streamListener(stream, status, headersBuf) {
|
110
|
-
const
|
111
|
-
|
112
|
-
src: stream,
|
113
|
-
dest: passThrough,
|
114
|
-
signal,
|
115
|
-
onError: deferredPromise.reject,
|
107
|
+
const outputStream = stream.pipe(new node_stream_1.PassThrough(), {
|
108
|
+
end: true,
|
116
109
|
});
|
117
110
|
const headersFlat = headersBuf
|
118
111
|
.toString('utf8')
|
@@ -125,7 +118,7 @@ function fetchCurl(fetchRequest) {
|
|
125
118
|
if (!stream.destroyed) {
|
126
119
|
stream.resume();
|
127
120
|
}
|
128
|
-
|
121
|
+
outputStream.destroy();
|
129
122
|
deferredPromise.reject(new Error('redirect is not allowed'));
|
130
123
|
}
|
131
124
|
return true;
|
@@ -133,14 +126,14 @@ function fetchCurl(fetchRequest) {
|
|
133
126
|
return false;
|
134
127
|
});
|
135
128
|
const headersInit = headersFlat.map(headerFlat => headerFlat.split(/:\s(.+)/).slice(0, 2));
|
136
|
-
const ponyfillResponse = new Response_js_1.PonyfillResponse(
|
129
|
+
const ponyfillResponse = new Response_js_1.PonyfillResponse(outputStream, {
|
137
130
|
status,
|
138
131
|
headers: headersInit,
|
139
132
|
url: curlHandle.getInfo(Curl.info.REDIRECT_URL)?.toString() || fetchRequest.url,
|
140
133
|
redirected: Number(curlHandle.getInfo(Curl.info.REDIRECT_COUNT)) > 0,
|
141
134
|
});
|
142
135
|
deferredPromise.resolve(ponyfillResponse);
|
143
|
-
streamResolved =
|
136
|
+
streamResolved = outputStream;
|
144
137
|
});
|
145
138
|
setImmediate(() => {
|
146
139
|
curlHandle.perform();
|
package/cjs/fetchNodeHttp.js
CHANGED
@@ -29,15 +29,12 @@ function fetchNodeHttp(fetchRequest) {
|
|
29
29
|
nodeHeaders['accept-encoding'] = 'gzip, deflate, br';
|
30
30
|
}
|
31
31
|
let signal;
|
32
|
-
if (fetchRequest._signal
|
32
|
+
if (fetchRequest._signal == null) {
|
33
33
|
signal = undefined;
|
34
34
|
}
|
35
35
|
else if (fetchRequest._signal) {
|
36
36
|
signal = fetchRequest._signal;
|
37
37
|
}
|
38
|
-
else {
|
39
|
-
signal = fetchRequest.signal;
|
40
|
-
}
|
41
38
|
let nodeRequest;
|
42
39
|
// If it is our ponyfilled Request, it should have `parsedUrl` which is a `URL` object
|
43
40
|
if (fetchRequest.parsedUrl) {
|
@@ -95,14 +92,10 @@ function fetchNodeHttp(fetchRequest) {
|
|
95
92
|
return;
|
96
93
|
}
|
97
94
|
}
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
signal,
|
103
|
-
onError: reject,
|
104
|
-
});
|
105
|
-
}
|
95
|
+
outputStream ||= new node_stream_1.PassThrough();
|
96
|
+
nodeResponse.pipe(outputStream, {
|
97
|
+
end: true,
|
98
|
+
});
|
106
99
|
const statusCode = nodeResponse.statusCode || 200;
|
107
100
|
let statusText = nodeResponse.statusMessage || node_http_1.STATUS_CODES[statusCode];
|
108
101
|
if (statusText == null) {
|
package/cjs/utils.js
CHANGED
@@ -7,7 +7,6 @@ exports.isArrayBufferView = isArrayBufferView;
|
|
7
7
|
exports.isNodeReadable = isNodeReadable;
|
8
8
|
exports.isIterable = isIterable;
|
9
9
|
exports.shouldRedirect = shouldRedirect;
|
10
|
-
exports.pipeThrough = pipeThrough;
|
11
10
|
exports.endStream = endStream;
|
12
11
|
exports.safeWrite = safeWrite;
|
13
12
|
const node_events_1 = require("node:events");
|
@@ -49,42 +48,6 @@ function isIterable(value) {
|
|
49
48
|
function shouldRedirect(status) {
|
50
49
|
return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
|
51
50
|
}
|
52
|
-
function pipeThrough({ src, dest, signal, onError, }) {
|
53
|
-
if (onError) {
|
54
|
-
// listen for errors on the destination stream if necessary. if the readable
|
55
|
-
// stream (src) emits an error, the writable destination (dest) will be
|
56
|
-
// destroyed with that error (see below)
|
57
|
-
dest.once('error', onError);
|
58
|
-
}
|
59
|
-
src.once('error', (e) => {
|
60
|
-
// if the readable stream (src) emits an error during pipe, the writable
|
61
|
-
// destination (dest) is not closed automatically. that needs to be
|
62
|
-
// done manually. the readable stream is closed when error is emitted,
|
63
|
-
// so only the writable destination needs to be destroyed
|
64
|
-
dest.destroy(e);
|
65
|
-
});
|
66
|
-
if (signal) {
|
67
|
-
// this is faster than `import('node:signal').addAbortSignal(signal, src)`
|
68
|
-
const srcRef = new WeakRef(src);
|
69
|
-
const signalRef = new WeakRef(signal);
|
70
|
-
function cleanup() {
|
71
|
-
signalRef.deref()?.removeEventListener('abort', onAbort);
|
72
|
-
srcRef.deref()?.removeListener('end', cleanup);
|
73
|
-
srcRef.deref()?.removeListener('error', cleanup);
|
74
|
-
srcRef.deref()?.removeListener('close', cleanup);
|
75
|
-
}
|
76
|
-
function onAbort() {
|
77
|
-
srcRef.deref()?.destroy(new AbortError());
|
78
|
-
cleanup();
|
79
|
-
}
|
80
|
-
signal.addEventListener('abort', onAbort, { once: true });
|
81
|
-
// this is faster than `import('node:signal').finished(src, cleanup)`
|
82
|
-
src.once('end', cleanup);
|
83
|
-
src.once('error', cleanup);
|
84
|
-
src.once('close', cleanup);
|
85
|
-
}
|
86
|
-
src.pipe(dest, { end: true /* already default */ });
|
87
|
-
}
|
88
51
|
function endStream(stream) {
|
89
52
|
// @ts-expect-error Avoid arguments adaptor trampoline https://v8.dev/blog/adaptor-frame
|
90
53
|
return stream.end(null, null, null);
|
@@ -95,10 +58,3 @@ function safeWrite(chunk, stream) {
|
|
95
58
|
return (0, node_events_1.once)(stream, 'drain');
|
96
59
|
}
|
97
60
|
}
|
98
|
-
// https://github.com/nodejs/node/blob/f692878dec6354c0a82241f224906981861bc840/lib/internal/errors.js#L961-L973
|
99
|
-
class AbortError extends Error {
|
100
|
-
constructor(message = 'The operation was aborted', options = undefined) {
|
101
|
-
super(message, options);
|
102
|
-
this.name = 'AbortError';
|
103
|
-
}
|
104
|
-
}
|
package/esm/Body.js
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
2
2
|
import { Buffer } from 'node:buffer';
|
3
|
-
import {
|
4
|
-
import { addAbortSignal, PassThrough, Readable } from 'node:stream';
|
3
|
+
import { Readable } from 'node:stream';
|
5
4
|
import { Busboy } from '@fastify/busboy';
|
6
5
|
import { handleMaybePromise } from '@whatwg-node/promise-helpers';
|
7
6
|
import { hasArrayBufferMethod, hasBufferMethod, hasBytesMethod, PonyfillBlob } from './Blob.js';
|
8
7
|
import { PonyfillFile } from './File.js';
|
9
8
|
import { getStreamFromFormData, PonyfillFormData } from './FormData.js';
|
10
9
|
import { PonyfillReadableStream } from './ReadableStream.js';
|
11
|
-
import { fakePromise, isArrayBufferView
|
10
|
+
import { fakePromise, isArrayBufferView } from './utils.js';
|
12
11
|
var BodyInitType;
|
13
12
|
(function (BodyInitType) {
|
14
13
|
BodyInitType["ReadableStream"] = "ReadableStream";
|
@@ -25,12 +24,10 @@ export class PonyfillBody {
|
|
25
24
|
bodyUsed = false;
|
26
25
|
contentType = null;
|
27
26
|
contentLength = null;
|
28
|
-
_signal = null;
|
29
27
|
constructor(bodyInit, options = {}) {
|
30
28
|
this.bodyInit = bodyInit;
|
31
29
|
this.options = options;
|
32
|
-
|
33
|
-
const { bodyFactory, contentType, contentLength, bodyType, buffer } = processBodyInit(bodyInit, options?.signal);
|
30
|
+
const { bodyFactory, contentType, contentLength, bodyType, buffer } = processBodyInit(bodyInit);
|
34
31
|
this._bodyFactory = bodyFactory;
|
35
32
|
this.contentType = contentType;
|
36
33
|
this.contentLength = contentLength;
|
@@ -215,9 +212,6 @@ export class PonyfillBody {
|
|
215
212
|
limits: formDataLimits,
|
216
213
|
defCharset: 'utf-8',
|
217
214
|
});
|
218
|
-
if (this._signal) {
|
219
|
-
addAbortSignal(this._signal, bb);
|
220
|
-
}
|
221
215
|
let completed = false;
|
222
216
|
const complete = (err) => {
|
223
217
|
if (completed)
|
@@ -369,7 +363,7 @@ export class PonyfillBody {
|
|
369
363
|
});
|
370
364
|
}
|
371
365
|
}
|
372
|
-
function processBodyInit(bodyInit
|
366
|
+
function processBodyInit(bodyInit) {
|
373
367
|
if (bodyInit == null) {
|
374
368
|
return {
|
375
369
|
bodyFactory: () => null,
|
@@ -452,22 +446,6 @@ function processBodyInit(bodyInit, signal) {
|
|
452
446
|
},
|
453
447
|
};
|
454
448
|
}
|
455
|
-
if (bodyInit instanceof IncomingMessage) {
|
456
|
-
const passThrough = new PassThrough();
|
457
|
-
pipeThrough({
|
458
|
-
src: bodyInit,
|
459
|
-
dest: passThrough,
|
460
|
-
signal,
|
461
|
-
});
|
462
|
-
return {
|
463
|
-
bodyType: BodyInitType.Readable,
|
464
|
-
contentType: null,
|
465
|
-
contentLength: null,
|
466
|
-
bodyFactory() {
|
467
|
-
return new PonyfillReadableStream(passThrough);
|
468
|
-
},
|
469
|
-
};
|
470
|
-
}
|
471
449
|
if (bodyInit instanceof Readable) {
|
472
450
|
return {
|
473
451
|
bodyType: BodyInitType.Readable,
|
package/esm/Request.js
CHANGED
@@ -73,6 +73,7 @@ export class PonyfillRequest extends PonyfillBody {
|
|
73
73
|
this.agent = requestInit.agent;
|
74
74
|
}
|
75
75
|
}
|
76
|
+
this._signal = requestInit?.signal || undefined;
|
76
77
|
}
|
77
78
|
headersSerializer;
|
78
79
|
cache;
|
@@ -88,6 +89,7 @@ export class PonyfillRequest extends PonyfillBody {
|
|
88
89
|
referrer;
|
89
90
|
referrerPolicy;
|
90
91
|
_url;
|
92
|
+
_signal;
|
91
93
|
get signal() {
|
92
94
|
this._signal ||= new AbortController().signal;
|
93
95
|
return this._signal;
|
package/esm/fetchCurl.js
CHANGED
@@ -2,7 +2,7 @@ import { PassThrough, Readable } from 'node:stream';
|
|
2
2
|
import { rootCertificates } from 'node:tls';
|
3
3
|
import { createDeferredPromise } from '@whatwg-node/promise-helpers';
|
4
4
|
import { PonyfillResponse } from './Response.js';
|
5
|
-
import { defaultHeadersSerializer, isNodeReadable,
|
5
|
+
import { defaultHeadersSerializer, isNodeReadable, shouldRedirect } from './utils.js';
|
6
6
|
export function fetchCurl(fetchRequest) {
|
7
7
|
const { Curl, CurlFeature, CurlPause, CurlProgressFunc } = globalThis['libcurl'];
|
8
8
|
const curlHandle = new Curl();
|
@@ -25,9 +25,6 @@ export function fetchCurl(fetchRequest) {
|
|
25
25
|
else if (fetchRequest._signal) {
|
26
26
|
signal = fetchRequest._signal;
|
27
27
|
}
|
28
|
-
else {
|
29
|
-
signal = fetchRequest.signal;
|
30
|
-
}
|
31
28
|
curlHandle.setStreamProgressCallback(function () {
|
32
29
|
return signal?.aborted ? (process.env.DEBUG ? CurlProgressFunc.Continue : 1) : 0;
|
33
30
|
});
|
@@ -104,12 +101,8 @@ export function fetchCurl(fetchRequest) {
|
|
104
101
|
}
|
105
102
|
});
|
106
103
|
curlHandle.once('stream', function streamListener(stream, status, headersBuf) {
|
107
|
-
const
|
108
|
-
|
109
|
-
src: stream,
|
110
|
-
dest: passThrough,
|
111
|
-
signal,
|
112
|
-
onError: deferredPromise.reject,
|
104
|
+
const outputStream = stream.pipe(new PassThrough(), {
|
105
|
+
end: true,
|
113
106
|
});
|
114
107
|
const headersFlat = headersBuf
|
115
108
|
.toString('utf8')
|
@@ -122,7 +115,7 @@ export function fetchCurl(fetchRequest) {
|
|
122
115
|
if (!stream.destroyed) {
|
123
116
|
stream.resume();
|
124
117
|
}
|
125
|
-
|
118
|
+
outputStream.destroy();
|
126
119
|
deferredPromise.reject(new Error('redirect is not allowed'));
|
127
120
|
}
|
128
121
|
return true;
|
@@ -130,14 +123,14 @@ export function fetchCurl(fetchRequest) {
|
|
130
123
|
return false;
|
131
124
|
});
|
132
125
|
const headersInit = headersFlat.map(headerFlat => headerFlat.split(/:\s(.+)/).slice(0, 2));
|
133
|
-
const ponyfillResponse = new PonyfillResponse(
|
126
|
+
const ponyfillResponse = new PonyfillResponse(outputStream, {
|
134
127
|
status,
|
135
128
|
headers: headersInit,
|
136
129
|
url: curlHandle.getInfo(Curl.info.REDIRECT_URL)?.toString() || fetchRequest.url,
|
137
130
|
redirected: Number(curlHandle.getInfo(Curl.info.REDIRECT_COUNT)) > 0,
|
138
131
|
});
|
139
132
|
deferredPromise.resolve(ponyfillResponse);
|
140
|
-
streamResolved =
|
133
|
+
streamResolved = outputStream;
|
141
134
|
});
|
142
135
|
setImmediate(() => {
|
143
136
|
curlHandle.perform();
|
package/esm/fetchNodeHttp.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
import { request as httpRequest, STATUS_CODES } from 'node:http';
|
2
2
|
import { request as httpsRequest } from 'node:https';
|
3
|
-
import { Readable } from 'node:stream';
|
3
|
+
import { PassThrough, Readable } from 'node:stream';
|
4
4
|
import { createBrotliDecompress, createGunzip, createInflate, createInflateRaw } from 'node:zlib';
|
5
5
|
import { handleMaybePromise } from '@whatwg-node/promise-helpers';
|
6
6
|
import { PonyfillRequest } from './Request.js';
|
7
7
|
import { PonyfillResponse } from './Response.js';
|
8
8
|
import { PonyfillURL } from './URL.js';
|
9
|
-
import { endStream, getHeadersObj, isNodeReadable,
|
9
|
+
import { endStream, getHeadersObj, isNodeReadable, safeWrite, shouldRedirect } from './utils.js';
|
10
10
|
function getRequestFnForProtocol(url) {
|
11
11
|
if (url.startsWith('http:')) {
|
12
12
|
return httpRequest;
|
@@ -26,15 +26,12 @@ export function fetchNodeHttp(fetchRequest) {
|
|
26
26
|
nodeHeaders['accept-encoding'] = 'gzip, deflate, br';
|
27
27
|
}
|
28
28
|
let signal;
|
29
|
-
if (fetchRequest._signal
|
29
|
+
if (fetchRequest._signal == null) {
|
30
30
|
signal = undefined;
|
31
31
|
}
|
32
32
|
else if (fetchRequest._signal) {
|
33
33
|
signal = fetchRequest._signal;
|
34
34
|
}
|
35
|
-
else {
|
36
|
-
signal = fetchRequest.signal;
|
37
|
-
}
|
38
35
|
let nodeRequest;
|
39
36
|
// If it is our ponyfilled Request, it should have `parsedUrl` which is a `URL` object
|
40
37
|
if (fetchRequest.parsedUrl) {
|
@@ -92,14 +89,10 @@ export function fetchNodeHttp(fetchRequest) {
|
|
92
89
|
return;
|
93
90
|
}
|
94
91
|
}
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
signal,
|
100
|
-
onError: reject,
|
101
|
-
});
|
102
|
-
}
|
92
|
+
outputStream ||= new PassThrough();
|
93
|
+
nodeResponse.pipe(outputStream, {
|
94
|
+
end: true,
|
95
|
+
});
|
103
96
|
const statusCode = nodeResponse.statusCode || 200;
|
104
97
|
let statusText = nodeResponse.statusMessage || STATUS_CODES[statusCode];
|
105
98
|
if (statusText == null) {
|
package/esm/utils.js
CHANGED
@@ -36,42 +36,6 @@ export function isIterable(value) {
|
|
36
36
|
export function shouldRedirect(status) {
|
37
37
|
return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
|
38
38
|
}
|
39
|
-
export function pipeThrough({ src, dest, signal, onError, }) {
|
40
|
-
if (onError) {
|
41
|
-
// listen for errors on the destination stream if necessary. if the readable
|
42
|
-
// stream (src) emits an error, the writable destination (dest) will be
|
43
|
-
// destroyed with that error (see below)
|
44
|
-
dest.once('error', onError);
|
45
|
-
}
|
46
|
-
src.once('error', (e) => {
|
47
|
-
// if the readable stream (src) emits an error during pipe, the writable
|
48
|
-
// destination (dest) is not closed automatically. that needs to be
|
49
|
-
// done manually. the readable stream is closed when error is emitted,
|
50
|
-
// so only the writable destination needs to be destroyed
|
51
|
-
dest.destroy(e);
|
52
|
-
});
|
53
|
-
if (signal) {
|
54
|
-
// this is faster than `import('node:signal').addAbortSignal(signal, src)`
|
55
|
-
const srcRef = new WeakRef(src);
|
56
|
-
const signalRef = new WeakRef(signal);
|
57
|
-
function cleanup() {
|
58
|
-
signalRef.deref()?.removeEventListener('abort', onAbort);
|
59
|
-
srcRef.deref()?.removeListener('end', cleanup);
|
60
|
-
srcRef.deref()?.removeListener('error', cleanup);
|
61
|
-
srcRef.deref()?.removeListener('close', cleanup);
|
62
|
-
}
|
63
|
-
function onAbort() {
|
64
|
-
srcRef.deref()?.destroy(new AbortError());
|
65
|
-
cleanup();
|
66
|
-
}
|
67
|
-
signal.addEventListener('abort', onAbort, { once: true });
|
68
|
-
// this is faster than `import('node:signal').finished(src, cleanup)`
|
69
|
-
src.once('end', cleanup);
|
70
|
-
src.once('error', cleanup);
|
71
|
-
src.once('close', cleanup);
|
72
|
-
}
|
73
|
-
src.pipe(dest, { end: true /* already default */ });
|
74
|
-
}
|
75
39
|
export function endStream(stream) {
|
76
40
|
// @ts-expect-error Avoid arguments adaptor trampoline https://v8.dev/blog/adaptor-frame
|
77
41
|
return stream.end(null, null, null);
|
@@ -82,10 +46,3 @@ export function safeWrite(chunk, stream) {
|
|
82
46
|
return once(stream, 'drain');
|
83
47
|
}
|
84
48
|
}
|
85
|
-
// https://github.com/nodejs/node/blob/f692878dec6354c0a82241f224906981861bc840/lib/internal/errors.js#L961-L973
|
86
|
-
class AbortError extends Error {
|
87
|
-
constructor(message = 'The operation was aborted', options = undefined) {
|
88
|
-
super(message, options);
|
89
|
-
this.name = 'AbortError';
|
90
|
-
}
|
91
|
-
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@whatwg-node/node-fetch",
|
3
|
-
"version": "0.7.23-alpha-
|
3
|
+
"version": "0.7.23-alpha-20250726003115-27dea3e7c5dae7285bf9c837cce54f387e269df2",
|
4
4
|
"description": "Fetch API implementation for Node",
|
5
5
|
"sideEffects": false,
|
6
6
|
"dependencies": {
|
package/typings/Body.d.cts
CHANGED
@@ -24,7 +24,6 @@ export declare class PonyfillBody<TJSON = any> implements Body {
|
|
24
24
|
bodyUsed: boolean;
|
25
25
|
contentType: string | null;
|
26
26
|
contentLength: number | null;
|
27
|
-
_signal?: AbortSignal | null;
|
28
27
|
constructor(bodyInit: BodyPonyfillInit | null, options?: PonyfillBodyOptions);
|
29
28
|
private bodyType?;
|
30
29
|
private _bodyFactory;
|
package/typings/Body.d.ts
CHANGED
@@ -24,7 +24,6 @@ export declare class PonyfillBody<TJSON = any> implements Body {
|
|
24
24
|
bodyUsed: boolean;
|
25
25
|
contentType: string | null;
|
26
26
|
contentLength: number | null;
|
27
|
-
_signal?: AbortSignal | null;
|
28
27
|
constructor(bodyInit: BodyPonyfillInit | null, options?: PonyfillBodyOptions);
|
29
28
|
private bodyType?;
|
30
29
|
private _bodyFactory;
|
package/typings/Request.d.cts
CHANGED
@@ -26,6 +26,7 @@ export declare class PonyfillRequest<TJSON = any> extends PonyfillBody<TJSON> im
|
|
26
26
|
referrer: string;
|
27
27
|
referrerPolicy: ReferrerPolicy;
|
28
28
|
_url: string | undefined;
|
29
|
+
_signal: AbortSignal | undefined;
|
29
30
|
get signal(): AbortSignal;
|
30
31
|
get url(): string;
|
31
32
|
_parsedUrl: URL | undefined;
|
package/typings/Request.d.ts
CHANGED
@@ -26,6 +26,7 @@ export declare class PonyfillRequest<TJSON = any> extends PonyfillBody<TJSON> im
|
|
26
26
|
referrer: string;
|
27
27
|
referrerPolicy: ReferrerPolicy;
|
28
28
|
_url: string | undefined;
|
29
|
+
_signal: AbortSignal | undefined;
|
29
30
|
get signal(): AbortSignal;
|
30
31
|
get url(): string;
|
31
32
|
_parsedUrl: URL | undefined;
|
package/typings/utils.d.cts
CHANGED
@@ -6,12 +6,6 @@ export declare function isArrayBufferView(obj: any): obj is ArrayBufferView;
|
|
6
6
|
export declare function isNodeReadable(obj: any): obj is Readable;
|
7
7
|
export declare function isIterable(value: any): value is Iterable<unknown>;
|
8
8
|
export declare function shouldRedirect(status?: number): boolean;
|
9
|
-
export declare function pipeThrough({ src, dest, signal, onError, }: {
|
10
|
-
src: Readable;
|
11
|
-
dest: Writable;
|
12
|
-
signal?: AbortSignal | undefined;
|
13
|
-
onError?: ((e: Error) => void) | undefined;
|
14
|
-
}): void;
|
15
9
|
export declare function endStream(stream: {
|
16
10
|
end: () => void;
|
17
11
|
}): void;
|
package/typings/utils.d.ts
CHANGED
@@ -6,12 +6,6 @@ export declare function isArrayBufferView(obj: any): obj is ArrayBufferView;
|
|
6
6
|
export declare function isNodeReadable(obj: any): obj is Readable;
|
7
7
|
export declare function isIterable(value: any): value is Iterable<unknown>;
|
8
8
|
export declare function shouldRedirect(status?: number): boolean;
|
9
|
-
export declare function pipeThrough({ src, dest, signal, onError, }: {
|
10
|
-
src: Readable;
|
11
|
-
dest: Writable;
|
12
|
-
signal?: AbortSignal | undefined;
|
13
|
-
onError?: ((e: Error) => void) | undefined;
|
14
|
-
}): void;
|
15
9
|
export declare function endStream(stream: {
|
16
10
|
end: () => void;
|
17
11
|
}): void;
|