@whatwg-node/node-fetch 0.7.15-alpha-20250323023432-5c31277f5c8544821b18ae941f15b1014132c37f → 0.7.15-alpha-20250324114328-290d8363ab5adbcacb8cd300791dcd5694b9669d
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 +35 -12
- package/cjs/fetchCurl.js +3 -1
- package/esm/Body.js +35 -12
- package/esm/fetchCurl.js +3 -1
- package/package.json +1 -1
- package/typings/Body.d.cts +2 -1
- package/typings/Body.d.ts +2 -1
package/cjs/Body.js
CHANGED
@@ -6,6 +6,7 @@ const tslib_1 = require("tslib");
|
|
6
6
|
const node_buffer_1 = require("node:buffer");
|
7
7
|
const node_http_1 = require("node:http");
|
8
8
|
const node_stream_1 = require("node:stream");
|
9
|
+
const promises_1 = require("node:stream/promises");
|
9
10
|
const busboy_1 = tslib_1.__importDefault(require("busboy"));
|
10
11
|
const promise_helpers_1 = require("@whatwg-node/promise-helpers");
|
11
12
|
const Blob_js_1 = require("./Blob.js");
|
@@ -105,10 +106,7 @@ class PonyfillBody {
|
|
105
106
|
return null;
|
106
107
|
}
|
107
108
|
_chunks = null;
|
108
|
-
|
109
|
-
if (this._chunks) {
|
110
|
-
return (0, utils_js_1.fakePromise)(this._chunks);
|
111
|
-
}
|
109
|
+
_doCollectChunksFromReadableJob() {
|
112
110
|
if (this.bodyType === BodyInitType.AsyncIterable) {
|
113
111
|
if (Array.fromAsync) {
|
114
112
|
return (0, promise_helpers_1.handleMaybePromise)(() => Array.fromAsync(this.bodyInit), chunks => {
|
@@ -117,31 +115,43 @@ class PonyfillBody {
|
|
117
115
|
});
|
118
116
|
}
|
119
117
|
const iterator = this.bodyInit[Symbol.asyncIterator]();
|
118
|
+
const chunks = [];
|
120
119
|
const collectValue = () => (0, promise_helpers_1.handleMaybePromise)(() => iterator.next(), ({ value, done }) => {
|
121
|
-
this._chunks ||= [];
|
122
120
|
if (value) {
|
123
|
-
|
121
|
+
chunks.push(value);
|
124
122
|
}
|
125
123
|
if (!done) {
|
126
124
|
return collectValue();
|
127
125
|
}
|
126
|
+
this._chunks = chunks;
|
128
127
|
return this._chunks;
|
129
128
|
});
|
130
129
|
return collectValue();
|
131
130
|
}
|
132
131
|
const _body = this.generateBody();
|
133
|
-
this._chunks = [];
|
134
132
|
if (!_body) {
|
133
|
+
this._chunks = [];
|
135
134
|
return (0, utils_js_1.fakePromise)(this._chunks);
|
136
135
|
}
|
136
|
+
const chunks = [];
|
137
137
|
_body.readable.on('data', chunk => {
|
138
|
-
|
138
|
+
chunks.push(chunk);
|
139
139
|
});
|
140
140
|
return new Promise((resolve, reject) => {
|
141
|
-
_body.readable.once('end', () =>
|
141
|
+
_body.readable.once('end', () => {
|
142
|
+
this._chunks = chunks;
|
143
|
+
resolve(this._chunks);
|
144
|
+
});
|
142
145
|
_body.readable.once('error', reject);
|
143
146
|
});
|
144
147
|
}
|
148
|
+
_collectChunksFromReadable() {
|
149
|
+
if (this._chunks) {
|
150
|
+
return (0, utils_js_1.fakePromise)(this._chunks);
|
151
|
+
}
|
152
|
+
this._chunks ||= this._doCollectChunksFromReadableJob();
|
153
|
+
return this._chunks;
|
154
|
+
}
|
145
155
|
_blob = null;
|
146
156
|
blob() {
|
147
157
|
if (this._blob) {
|
@@ -397,11 +407,24 @@ function processBodyInit(bodyInit, signal) {
|
|
397
407
|
};
|
398
408
|
}
|
399
409
|
if (bodyInit instanceof node_http_1.IncomingMessage) {
|
400
|
-
const
|
401
|
-
|
402
|
-
// @ts-expect-error - `signal` is not in the type definition
|
410
|
+
const originalStream = bodyInit;
|
411
|
+
const passthrough = (bodyInit = bodyInit.pipe(new node_stream_1.PassThrough({
|
403
412
|
signal,
|
413
|
+
}), {
|
414
|
+
end: true,
|
404
415
|
}));
|
416
|
+
(0, promises_1.pipeline)(originalStream, passthrough, {
|
417
|
+
end: true,
|
418
|
+
signal,
|
419
|
+
})
|
420
|
+
.then(() => {
|
421
|
+
if (!originalStream.destroyed) {
|
422
|
+
originalStream.resume();
|
423
|
+
}
|
424
|
+
})
|
425
|
+
.catch(e => {
|
426
|
+
passthrough.destroy(e);
|
427
|
+
});
|
405
428
|
return {
|
406
429
|
bodyType: BodyInitType.Readable,
|
407
430
|
contentType: null,
|
package/cjs/fetchCurl.js
CHANGED
@@ -102,7 +102,9 @@ function fetchCurl(fetchRequest) {
|
|
102
102
|
}
|
103
103
|
});
|
104
104
|
curlHandle.once('stream', function streamListener(stream, status, headersBuf) {
|
105
|
-
const outputStream = new node_stream_1.PassThrough(
|
105
|
+
const outputStream = new node_stream_1.PassThrough({
|
106
|
+
signal: fetchRequest.signal,
|
107
|
+
});
|
106
108
|
(0, promises_1.pipeline)(stream, outputStream, {
|
107
109
|
end: true,
|
108
110
|
signal: fetchRequest.signal,
|
package/esm/Body.js
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
import { Buffer } from 'node:buffer';
|
3
3
|
import { IncomingMessage } from 'node:http';
|
4
4
|
import { PassThrough, Readable } from 'node:stream';
|
5
|
+
import { pipeline } from 'node:stream/promises';
|
5
6
|
import busboy from 'busboy';
|
6
7
|
import { handleMaybePromise } from '@whatwg-node/promise-helpers';
|
7
8
|
import { hasArrayBufferMethod, hasBufferMethod, hasBytesMethod, PonyfillBlob } from './Blob.js';
|
@@ -101,10 +102,7 @@ export class PonyfillBody {
|
|
101
102
|
return null;
|
102
103
|
}
|
103
104
|
_chunks = null;
|
104
|
-
|
105
|
-
if (this._chunks) {
|
106
|
-
return fakePromise(this._chunks);
|
107
|
-
}
|
105
|
+
_doCollectChunksFromReadableJob() {
|
108
106
|
if (this.bodyType === BodyInitType.AsyncIterable) {
|
109
107
|
if (Array.fromAsync) {
|
110
108
|
return handleMaybePromise(() => Array.fromAsync(this.bodyInit), chunks => {
|
@@ -113,31 +111,43 @@ export class PonyfillBody {
|
|
113
111
|
});
|
114
112
|
}
|
115
113
|
const iterator = this.bodyInit[Symbol.asyncIterator]();
|
114
|
+
const chunks = [];
|
116
115
|
const collectValue = () => handleMaybePromise(() => iterator.next(), ({ value, done }) => {
|
117
|
-
this._chunks ||= [];
|
118
116
|
if (value) {
|
119
|
-
|
117
|
+
chunks.push(value);
|
120
118
|
}
|
121
119
|
if (!done) {
|
122
120
|
return collectValue();
|
123
121
|
}
|
122
|
+
this._chunks = chunks;
|
124
123
|
return this._chunks;
|
125
124
|
});
|
126
125
|
return collectValue();
|
127
126
|
}
|
128
127
|
const _body = this.generateBody();
|
129
|
-
this._chunks = [];
|
130
128
|
if (!_body) {
|
129
|
+
this._chunks = [];
|
131
130
|
return fakePromise(this._chunks);
|
132
131
|
}
|
132
|
+
const chunks = [];
|
133
133
|
_body.readable.on('data', chunk => {
|
134
|
-
|
134
|
+
chunks.push(chunk);
|
135
135
|
});
|
136
136
|
return new Promise((resolve, reject) => {
|
137
|
-
_body.readable.once('end', () =>
|
137
|
+
_body.readable.once('end', () => {
|
138
|
+
this._chunks = chunks;
|
139
|
+
resolve(this._chunks);
|
140
|
+
});
|
138
141
|
_body.readable.once('error', reject);
|
139
142
|
});
|
140
143
|
}
|
144
|
+
_collectChunksFromReadable() {
|
145
|
+
if (this._chunks) {
|
146
|
+
return fakePromise(this._chunks);
|
147
|
+
}
|
148
|
+
this._chunks ||= this._doCollectChunksFromReadableJob();
|
149
|
+
return this._chunks;
|
150
|
+
}
|
141
151
|
_blob = null;
|
142
152
|
blob() {
|
143
153
|
if (this._blob) {
|
@@ -392,11 +402,24 @@ function processBodyInit(bodyInit, signal) {
|
|
392
402
|
};
|
393
403
|
}
|
394
404
|
if (bodyInit instanceof IncomingMessage) {
|
395
|
-
const
|
396
|
-
|
397
|
-
// @ts-expect-error - `signal` is not in the type definition
|
405
|
+
const originalStream = bodyInit;
|
406
|
+
const passthrough = (bodyInit = bodyInit.pipe(new PassThrough({
|
398
407
|
signal,
|
408
|
+
}), {
|
409
|
+
end: true,
|
399
410
|
}));
|
411
|
+
pipeline(originalStream, passthrough, {
|
412
|
+
end: true,
|
413
|
+
signal,
|
414
|
+
})
|
415
|
+
.then(() => {
|
416
|
+
if (!originalStream.destroyed) {
|
417
|
+
originalStream.resume();
|
418
|
+
}
|
419
|
+
})
|
420
|
+
.catch(e => {
|
421
|
+
passthrough.destroy(e);
|
422
|
+
});
|
400
423
|
return {
|
401
424
|
bodyType: BodyInitType.Readable,
|
402
425
|
contentType: null,
|
package/esm/fetchCurl.js
CHANGED
@@ -99,7 +99,9 @@ export function fetchCurl(fetchRequest) {
|
|
99
99
|
}
|
100
100
|
});
|
101
101
|
curlHandle.once('stream', function streamListener(stream, status, headersBuf) {
|
102
|
-
const outputStream = new PassThrough(
|
102
|
+
const outputStream = new PassThrough({
|
103
|
+
signal: fetchRequest.signal,
|
104
|
+
});
|
103
105
|
pipeline(stream, outputStream, {
|
104
106
|
end: true,
|
105
107
|
signal: fetchRequest.signal,
|
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-20250324114328-290d8363ab5adbcacb8cd300791dcd5694b9669d",
|
4
4
|
"description": "Fetch API implementation for Node",
|
5
5
|
"sideEffects": false,
|
6
6
|
"dependencies": {
|
package/typings/Body.d.cts
CHANGED
@@ -34,7 +34,8 @@ export declare class PonyfillBody<TJSON = any> implements Body {
|
|
34
34
|
headers: Headers;
|
35
35
|
}, forceSet?: boolean): void;
|
36
36
|
get body(): PonyfillReadableStream<Uint8Array> | null;
|
37
|
-
_chunks: Uint8Array[] | null;
|
37
|
+
_chunks: MaybePromise<Uint8Array[]> | null;
|
38
|
+
_doCollectChunksFromReadableJob(): MaybePromise<Uint8Array<ArrayBufferLike>[]>;
|
38
39
|
_collectChunksFromReadable(): MaybePromise<Uint8Array<ArrayBufferLike>[]>;
|
39
40
|
_blob: PonyfillBlob | null;
|
40
41
|
blob(): Promise<PonyfillBlob>;
|
package/typings/Body.d.ts
CHANGED
@@ -34,7 +34,8 @@ export declare class PonyfillBody<TJSON = any> implements Body {
|
|
34
34
|
headers: Headers;
|
35
35
|
}, forceSet?: boolean): void;
|
36
36
|
get body(): PonyfillReadableStream<Uint8Array> | null;
|
37
|
-
_chunks: Uint8Array[] | null;
|
37
|
+
_chunks: MaybePromise<Uint8Array[]> | null;
|
38
|
+
_doCollectChunksFromReadableJob(): MaybePromise<Uint8Array<ArrayBufferLike>[]>;
|
38
39
|
_collectChunksFromReadable(): MaybePromise<Uint8Array<ArrayBufferLike>[]>;
|
39
40
|
_blob: PonyfillBlob | null;
|
40
41
|
blob(): Promise<PonyfillBlob>;
|