@whatwg-node/node-fetch 0.7.21-alpha-20250520143422-ffbac774c074784de6e135e38979f3a14ba4982f → 0.7.22-alpha-20250526145249-5592a2aa5cd5a8603f5016376c1e6ef0f84f7aab
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 +25 -13
- package/cjs/fetchNodeHttp.js +1 -1
- package/cjs/utils.js +2 -4
- package/esm/Body.js +26 -14
- package/esm/fetchNodeHttp.js +1 -1
- package/esm/utils.js +2 -4
- package/package.json +1 -1
- package/typings/utils.d.cts +1 -1
- package/typings/utils.d.ts +1 -1
package/cjs/Body.js
CHANGED
@@ -109,14 +109,14 @@ class PonyfillBody {
|
|
109
109
|
_doCollectChunksFromReadableJob() {
|
110
110
|
if (this.bodyType === BodyInitType.AsyncIterable) {
|
111
111
|
if (Array.fromAsync) {
|
112
|
-
return
|
112
|
+
return Array.fromAsync(this.bodyInit).then(chunks => {
|
113
113
|
this._chunks = chunks;
|
114
114
|
return this._chunks;
|
115
115
|
});
|
116
116
|
}
|
117
117
|
const iterator = this.bodyInit[Symbol.asyncIterator]();
|
118
118
|
const chunks = [];
|
119
|
-
const collectValue = () =>
|
119
|
+
const collectValue = () => iterator.next().then(({ value, done }) => {
|
120
120
|
if (value) {
|
121
121
|
chunks.push(value);
|
122
122
|
}
|
@@ -131,17 +131,25 @@ class PonyfillBody {
|
|
131
131
|
const _body = this.generateBody();
|
132
132
|
if (!_body) {
|
133
133
|
this._chunks = [];
|
134
|
-
return (0, utils_js_1.fakePromise)(this._chunks);
|
135
|
-
}
|
136
|
-
return _body.readable.toArray().then(chunks => {
|
137
|
-
this._chunks = chunks;
|
138
134
|
return this._chunks;
|
135
|
+
}
|
136
|
+
const chunks = [];
|
137
|
+
const deferred = (0, promise_helpers_1.createDeferredPromise)();
|
138
|
+
_body.readable.on('data', function nextChunk(chunk) {
|
139
|
+
chunks.push(chunk);
|
140
|
+
});
|
141
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
142
|
+
const _this = this;
|
143
|
+
_body.readable.once('end', function endOfStream() {
|
144
|
+
_this._chunks = chunks;
|
145
|
+
deferred.resolve(chunks);
|
146
|
+
});
|
147
|
+
_body.readable.once('error', function errorOnStream(err) {
|
148
|
+
deferred.reject(err);
|
139
149
|
});
|
150
|
+
return deferred.promise;
|
140
151
|
}
|
141
152
|
_collectChunksFromReadable() {
|
142
|
-
if (this._chunks) {
|
143
|
-
return (0, utils_js_1.fakePromise)(this._chunks);
|
144
|
-
}
|
145
153
|
this._chunks ||= this._doCollectChunksFromReadableJob();
|
146
154
|
return this._chunks;
|
147
155
|
}
|
@@ -168,13 +176,15 @@ class PonyfillBody {
|
|
168
176
|
});
|
169
177
|
return (0, utils_js_1.fakePromise)(this._blob);
|
170
178
|
}
|
171
|
-
return (0, utils_js_1.fakePromise)(
|
179
|
+
return (0, utils_js_1.fakePromise)()
|
180
|
+
.then(() => this._collectChunksFromReadable())
|
181
|
+
.then(chunks => {
|
172
182
|
this._blob = new Blob_js_1.PonyfillBlob(chunks, {
|
173
183
|
type: this.contentType || '',
|
174
184
|
size: this.contentLength,
|
175
185
|
});
|
176
186
|
return this._blob;
|
177
|
-
})
|
187
|
+
});
|
178
188
|
}
|
179
189
|
_formData = null;
|
180
190
|
formData(opts) {
|
@@ -317,14 +327,16 @@ class PonyfillBody {
|
|
317
327
|
});
|
318
328
|
}
|
319
329
|
}
|
320
|
-
return (0, utils_js_1.fakePromise)(
|
330
|
+
return (0, utils_js_1.fakePromise)()
|
331
|
+
.then(() => this._collectChunksFromReadable())
|
332
|
+
.then(chunks => {
|
321
333
|
if (chunks.length === 1) {
|
322
334
|
this._buffer = chunks[0];
|
323
335
|
return this._buffer;
|
324
336
|
}
|
325
337
|
this._buffer = node_buffer_1.Buffer.concat(chunks);
|
326
338
|
return this._buffer;
|
327
|
-
})
|
339
|
+
});
|
328
340
|
}
|
329
341
|
bytes() {
|
330
342
|
return this.buffer();
|
package/cjs/fetchNodeHttp.js
CHANGED
@@ -118,7 +118,7 @@ function fetchNodeHttp(fetchRequest) {
|
|
118
118
|
resolve(ponyfillResponse);
|
119
119
|
});
|
120
120
|
if (fetchRequest['_buffer'] != null) {
|
121
|
-
(0, promise_helpers_1.handleMaybePromise)(() => (0, utils_js_1.safeWrite)(fetchRequest['_buffer'], nodeRequest
|
121
|
+
(0, promise_helpers_1.handleMaybePromise)(() => (0, utils_js_1.safeWrite)(fetchRequest['_buffer'], nodeRequest), () => (0, utils_js_1.endStream)(nodeRequest), reject);
|
122
122
|
}
|
123
123
|
else {
|
124
124
|
const nodeReadable = (fetchRequest.body != null
|
package/cjs/utils.js
CHANGED
@@ -70,11 +70,9 @@ function endStream(stream) {
|
|
70
70
|
// @ts-expect-error Avoid arguments adaptor trampoline https://v8.dev/blog/adaptor-frame
|
71
71
|
return stream.end(null, null, null);
|
72
72
|
}
|
73
|
-
function safeWrite(chunk, stream
|
73
|
+
function safeWrite(chunk, stream) {
|
74
74
|
const result = stream.write(chunk);
|
75
75
|
if (!result) {
|
76
|
-
return (0, node_events_1.once)(stream, 'drain'
|
77
|
-
signal,
|
78
|
-
});
|
76
|
+
return (0, node_events_1.once)(stream, 'drain');
|
79
77
|
}
|
80
78
|
}
|
package/esm/Body.js
CHANGED
@@ -3,7 +3,7 @@ import { Buffer } from 'node:buffer';
|
|
3
3
|
import { IncomingMessage } from 'node:http';
|
4
4
|
import { addAbortSignal, Readable } from 'node:stream';
|
5
5
|
import { Busboy } from '@fastify/busboy';
|
6
|
-
import {
|
6
|
+
import { createDeferredPromise } from '@whatwg-node/promise-helpers';
|
7
7
|
import { hasArrayBufferMethod, hasBufferMethod, hasBytesMethod, PonyfillBlob } from './Blob.js';
|
8
8
|
import { PonyfillFile } from './File.js';
|
9
9
|
import { getStreamFromFormData, PonyfillFormData } from './FormData.js';
|
@@ -106,14 +106,14 @@ export class PonyfillBody {
|
|
106
106
|
_doCollectChunksFromReadableJob() {
|
107
107
|
if (this.bodyType === BodyInitType.AsyncIterable) {
|
108
108
|
if (Array.fromAsync) {
|
109
|
-
return
|
109
|
+
return Array.fromAsync(this.bodyInit).then(chunks => {
|
110
110
|
this._chunks = chunks;
|
111
111
|
return this._chunks;
|
112
112
|
});
|
113
113
|
}
|
114
114
|
const iterator = this.bodyInit[Symbol.asyncIterator]();
|
115
115
|
const chunks = [];
|
116
|
-
const collectValue = () =>
|
116
|
+
const collectValue = () => iterator.next().then(({ value, done }) => {
|
117
117
|
if (value) {
|
118
118
|
chunks.push(value);
|
119
119
|
}
|
@@ -128,17 +128,25 @@ export class PonyfillBody {
|
|
128
128
|
const _body = this.generateBody();
|
129
129
|
if (!_body) {
|
130
130
|
this._chunks = [];
|
131
|
-
return fakePromise(this._chunks);
|
132
|
-
}
|
133
|
-
return _body.readable.toArray().then(chunks => {
|
134
|
-
this._chunks = chunks;
|
135
131
|
return this._chunks;
|
132
|
+
}
|
133
|
+
const chunks = [];
|
134
|
+
const deferred = createDeferredPromise();
|
135
|
+
_body.readable.on('data', function nextChunk(chunk) {
|
136
|
+
chunks.push(chunk);
|
137
|
+
});
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
139
|
+
const _this = this;
|
140
|
+
_body.readable.once('end', function endOfStream() {
|
141
|
+
_this._chunks = chunks;
|
142
|
+
deferred.resolve(chunks);
|
143
|
+
});
|
144
|
+
_body.readable.once('error', function errorOnStream(err) {
|
145
|
+
deferred.reject(err);
|
136
146
|
});
|
147
|
+
return deferred.promise;
|
137
148
|
}
|
138
149
|
_collectChunksFromReadable() {
|
139
|
-
if (this._chunks) {
|
140
|
-
return fakePromise(this._chunks);
|
141
|
-
}
|
142
150
|
this._chunks ||= this._doCollectChunksFromReadableJob();
|
143
151
|
return this._chunks;
|
144
152
|
}
|
@@ -165,13 +173,15 @@ export class PonyfillBody {
|
|
165
173
|
});
|
166
174
|
return fakePromise(this._blob);
|
167
175
|
}
|
168
|
-
return fakePromise(
|
176
|
+
return fakePromise()
|
177
|
+
.then(() => this._collectChunksFromReadable())
|
178
|
+
.then(chunks => {
|
169
179
|
this._blob = new PonyfillBlob(chunks, {
|
170
180
|
type: this.contentType || '',
|
171
181
|
size: this.contentLength,
|
172
182
|
});
|
173
183
|
return this._blob;
|
174
|
-
})
|
184
|
+
});
|
175
185
|
}
|
176
186
|
_formData = null;
|
177
187
|
formData(opts) {
|
@@ -314,14 +324,16 @@ export class PonyfillBody {
|
|
314
324
|
});
|
315
325
|
}
|
316
326
|
}
|
317
|
-
return fakePromise(
|
327
|
+
return fakePromise()
|
328
|
+
.then(() => this._collectChunksFromReadable())
|
329
|
+
.then(chunks => {
|
318
330
|
if (chunks.length === 1) {
|
319
331
|
this._buffer = chunks[0];
|
320
332
|
return this._buffer;
|
321
333
|
}
|
322
334
|
this._buffer = Buffer.concat(chunks);
|
323
335
|
return this._buffer;
|
324
|
-
})
|
336
|
+
});
|
325
337
|
}
|
326
338
|
bytes() {
|
327
339
|
return this.buffer();
|
package/esm/fetchNodeHttp.js
CHANGED
@@ -115,7 +115,7 @@ export function fetchNodeHttp(fetchRequest) {
|
|
115
115
|
resolve(ponyfillResponse);
|
116
116
|
});
|
117
117
|
if (fetchRequest['_buffer'] != null) {
|
118
|
-
handleMaybePromise(() => safeWrite(fetchRequest['_buffer'], nodeRequest
|
118
|
+
handleMaybePromise(() => safeWrite(fetchRequest['_buffer'], nodeRequest), () => endStream(nodeRequest), reject);
|
119
119
|
}
|
120
120
|
else {
|
121
121
|
const nodeReadable = (fetchRequest.body != null
|
package/esm/utils.js
CHANGED
@@ -57,11 +57,9 @@ export function endStream(stream) {
|
|
57
57
|
// @ts-expect-error Avoid arguments adaptor trampoline https://v8.dev/blog/adaptor-frame
|
58
58
|
return stream.end(null, null, null);
|
59
59
|
}
|
60
|
-
export function safeWrite(chunk, stream
|
60
|
+
export function safeWrite(chunk, stream) {
|
61
61
|
const result = stream.write(chunk);
|
62
62
|
if (!result) {
|
63
|
-
return once(stream, 'drain'
|
64
|
-
signal,
|
65
|
-
});
|
63
|
+
return once(stream, 'drain');
|
66
64
|
}
|
67
65
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@whatwg-node/node-fetch",
|
3
|
-
"version": "0.7.
|
3
|
+
"version": "0.7.22-alpha-20250526145249-5592a2aa5cd5a8603f5016376c1e6ef0f84f7aab",
|
4
4
|
"description": "Fetch API implementation for Node",
|
5
5
|
"sideEffects": false,
|
6
6
|
"dependencies": {
|
package/typings/utils.d.cts
CHANGED
@@ -16,4 +16,4 @@ export declare function wrapIncomingMessageWithPassthrough({ incomingMessage, si
|
|
16
16
|
export declare function endStream(stream: {
|
17
17
|
end: () => void;
|
18
18
|
}): void;
|
19
|
-
export declare function safeWrite(chunk: any, stream: Writable
|
19
|
+
export declare function safeWrite(chunk: any, stream: Writable): Promise<any[]> | undefined;
|
package/typings/utils.d.ts
CHANGED
@@ -16,4 +16,4 @@ export declare function wrapIncomingMessageWithPassthrough({ incomingMessage, si
|
|
16
16
|
export declare function endStream(stream: {
|
17
17
|
end: () => void;
|
18
18
|
}): void;
|
19
|
-
export declare function safeWrite(chunk: any, stream: Writable
|
19
|
+
export declare function safeWrite(chunk: any, stream: Writable): Promise<any[]> | undefined;
|