@whatwg-node/node-fetch 0.7.15-alpha-20250324173008-e214682794a80d23e60fa5a3ee070fdb4871da83 → 0.7.15-alpha-20250324185339-daa21e16c396158104a59781d00308c832a5948a
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 +8 -10
- package/cjs/Request.js +1 -1
- package/esm/Body.js +9 -11
- package/esm/Request.js +1 -1
- package/package.json +1 -1
- package/typings/Body.d.cts +1 -0
- package/typings/Body.d.ts +1 -0
package/cjs/Body.js
CHANGED
@@ -29,9 +29,11 @@ class PonyfillBody {
|
|
29
29
|
bodyUsed = false;
|
30
30
|
contentType = null;
|
31
31
|
contentLength = null;
|
32
|
+
signal = null;
|
32
33
|
constructor(bodyInit, options = {}) {
|
33
34
|
this.bodyInit = bodyInit;
|
34
35
|
this.options = options;
|
36
|
+
this.signal = options.signal || null;
|
35
37
|
const { bodyFactory, contentType, contentLength, bodyType, buffer } = processBodyInit(bodyInit, options?.signal);
|
36
38
|
this._bodyFactory = bodyFactory;
|
37
39
|
this.contentType = contentType;
|
@@ -52,6 +54,9 @@ class PonyfillBody {
|
|
52
54
|
}
|
53
55
|
const body = this._bodyFactory();
|
54
56
|
this._generatedBody = body;
|
57
|
+
if (body?.readable && this.signal) {
|
58
|
+
(0, node_stream_1.addAbortSignal)(this.signal, body.readable);
|
59
|
+
}
|
55
60
|
return body;
|
56
61
|
}
|
57
62
|
handleContentLengthHeader(forceSet = false) {
|
@@ -132,16 +137,9 @@ class PonyfillBody {
|
|
132
137
|
this._chunks = [];
|
133
138
|
return (0, utils_js_1.fakePromise)(this._chunks);
|
134
139
|
}
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
});
|
139
|
-
return new Promise((resolve, reject) => {
|
140
|
-
_body.readable.once('end', () => {
|
141
|
-
this._chunks = chunks;
|
142
|
-
resolve(this._chunks);
|
143
|
-
});
|
144
|
-
_body.readable.once('error', reject);
|
140
|
+
return _body.readable.toArray({ signal: this.signal }).then(chunks => {
|
141
|
+
this._chunks = chunks;
|
142
|
+
return this._chunks;
|
145
143
|
});
|
146
144
|
}
|
147
145
|
_collectChunksFromReadable() {
|
package/cjs/Request.js
CHANGED
@@ -41,7 +41,7 @@ class PonyfillRequest extends Body_js_1.PonyfillBody {
|
|
41
41
|
bodyInit = options.body || null;
|
42
42
|
requestInit = options;
|
43
43
|
}
|
44
|
-
super(bodyInit,
|
44
|
+
super(bodyInit, requestInit);
|
45
45
|
this._url = _url;
|
46
46
|
this._parsedUrl = _parsedUrl;
|
47
47
|
this.cache = requestInit?.cache || 'default';
|
package/esm/Body.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
2
2
|
import { Buffer } from 'node:buffer';
|
3
3
|
import { IncomingMessage } from 'node:http';
|
4
|
-
import { PassThrough, Readable } from 'node:stream';
|
4
|
+
import { addAbortSignal, PassThrough, Readable } from 'node:stream';
|
5
5
|
import busboy from 'busboy';
|
6
6
|
import { handleMaybePromise } from '@whatwg-node/promise-helpers';
|
7
7
|
import { hasArrayBufferMethod, hasBufferMethod, hasBytesMethod, PonyfillBlob } from './Blob.js';
|
@@ -25,9 +25,11 @@ export class PonyfillBody {
|
|
25
25
|
bodyUsed = false;
|
26
26
|
contentType = null;
|
27
27
|
contentLength = null;
|
28
|
+
signal = null;
|
28
29
|
constructor(bodyInit, options = {}) {
|
29
30
|
this.bodyInit = bodyInit;
|
30
31
|
this.options = options;
|
32
|
+
this.signal = options.signal || null;
|
31
33
|
const { bodyFactory, contentType, contentLength, bodyType, buffer } = processBodyInit(bodyInit, options?.signal);
|
32
34
|
this._bodyFactory = bodyFactory;
|
33
35
|
this.contentType = contentType;
|
@@ -48,6 +50,9 @@ export class PonyfillBody {
|
|
48
50
|
}
|
49
51
|
const body = this._bodyFactory();
|
50
52
|
this._generatedBody = body;
|
53
|
+
if (body?.readable && this.signal) {
|
54
|
+
addAbortSignal(this.signal, body.readable);
|
55
|
+
}
|
51
56
|
return body;
|
52
57
|
}
|
53
58
|
handleContentLengthHeader(forceSet = false) {
|
@@ -128,16 +133,9 @@ export class PonyfillBody {
|
|
128
133
|
this._chunks = [];
|
129
134
|
return fakePromise(this._chunks);
|
130
135
|
}
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
});
|
135
|
-
return new Promise((resolve, reject) => {
|
136
|
-
_body.readable.once('end', () => {
|
137
|
-
this._chunks = chunks;
|
138
|
-
resolve(this._chunks);
|
139
|
-
});
|
140
|
-
_body.readable.once('error', reject);
|
136
|
+
return _body.readable.toArray({ signal: this.signal }).then(chunks => {
|
137
|
+
this._chunks = chunks;
|
138
|
+
return this._chunks;
|
141
139
|
});
|
142
140
|
}
|
143
141
|
_collectChunksFromReadable() {
|
package/esm/Request.js
CHANGED
@@ -38,7 +38,7 @@ export class PonyfillRequest extends PonyfillBody {
|
|
38
38
|
bodyInit = options.body || null;
|
39
39
|
requestInit = options;
|
40
40
|
}
|
41
|
-
super(bodyInit,
|
41
|
+
super(bodyInit, requestInit);
|
42
42
|
this._url = _url;
|
43
43
|
this._parsedUrl = _parsedUrl;
|
44
44
|
this.cache = requestInit?.cache || 'default';
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@whatwg-node/node-fetch",
|
3
|
-
"version": "0.7.15-alpha-
|
3
|
+
"version": "0.7.15-alpha-20250324185339-daa21e16c396158104a59781d00308c832a5948a",
|
4
4
|
"description": "Fetch API implementation for Node",
|
5
5
|
"sideEffects": false,
|
6
6
|
"dependencies": {
|
package/typings/Body.d.cts
CHANGED
@@ -24,6 +24,7 @@ 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;
|
27
28
|
constructor(bodyInit: BodyPonyfillInit | null, options?: PonyfillBodyOptions);
|
28
29
|
private bodyType?;
|
29
30
|
private _bodyFactory;
|
package/typings/Body.d.ts
CHANGED
@@ -24,6 +24,7 @@ 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;
|
27
28
|
constructor(bodyInit: BodyPonyfillInit | null, options?: PonyfillBodyOptions);
|
28
29
|
private bodyType?;
|
29
30
|
private _bodyFactory;
|