@whatwg-node/node-fetch 0.7.15-alpha-20250322121446-0a8732f1758546d618a797e18a1da953697eb27c → 0.7.15-alpha-20250322145808-458c0d572d10c5277497e947a182be65760c50ff
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 -6
- package/esm/Body.js +26 -7
- package/package.json +1 -1
- package/typings/Body.d.cts +1 -0
- package/typings/Body.d.ts +1 -0
package/cjs/Body.js
CHANGED
@@ -4,6 +4,7 @@ exports.PonyfillBody = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
5
5
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
6
6
|
const node_buffer_1 = require("node:buffer");
|
7
|
+
const node_http_1 = require("node:http");
|
7
8
|
const node_stream_1 = require("node:stream");
|
8
9
|
const busboy_1 = tslib_1.__importDefault(require("busboy"));
|
9
10
|
const promise_helpers_1 = require("@whatwg-node/promise-helpers");
|
@@ -31,7 +32,7 @@ class PonyfillBody {
|
|
31
32
|
constructor(bodyInit, options = {}) {
|
32
33
|
this.bodyInit = bodyInit;
|
33
34
|
this.options = options;
|
34
|
-
const { bodyFactory, contentType, contentLength, bodyType, buffer } = processBodyInit(bodyInit);
|
35
|
+
const { bodyFactory, contentType, contentLength, bodyType, buffer } = processBodyInit(bodyInit, options?.signal);
|
35
36
|
this._bodyFactory = bodyFactory;
|
36
37
|
this.contentType = contentType;
|
37
38
|
this.contentLength = contentLength;
|
@@ -130,7 +131,7 @@ class PonyfillBody {
|
|
130
131
|
}
|
131
132
|
const _body = this.generateBody();
|
132
133
|
this._chunks = [];
|
133
|
-
if (!_body
|
134
|
+
if (!_body) {
|
134
135
|
return (0, utils_js_1.fakePromise)(this._chunks);
|
135
136
|
}
|
136
137
|
_body.readable.on('data', chunk => {
|
@@ -310,7 +311,7 @@ class PonyfillBody {
|
|
310
311
|
}
|
311
312
|
}
|
312
313
|
exports.PonyfillBody = PonyfillBody;
|
313
|
-
function processBodyInit(bodyInit) {
|
314
|
+
function processBodyInit(bodyInit, signal) {
|
314
315
|
if (bodyInit == null) {
|
315
316
|
return {
|
316
317
|
bodyFactory: () => null,
|
@@ -333,13 +334,14 @@ function processBodyInit(bodyInit) {
|
|
333
334
|
};
|
334
335
|
}
|
335
336
|
if (node_buffer_1.Buffer.isBuffer(bodyInit)) {
|
337
|
+
const buffer = bodyInit;
|
336
338
|
return {
|
337
339
|
bodyType: BodyInitType.Buffer,
|
338
340
|
contentType: null,
|
339
341
|
contentLength: bodyInit.length,
|
340
342
|
buffer: bodyInit,
|
341
343
|
bodyFactory() {
|
342
|
-
const readable = node_stream_1.Readable.from(
|
344
|
+
const readable = node_stream_1.Readable.from(buffer);
|
343
345
|
const body = new ReadableStream_js_1.PonyfillReadableStream(readable);
|
344
346
|
return body;
|
345
347
|
},
|
@@ -360,20 +362,22 @@ function processBodyInit(bodyInit) {
|
|
360
362
|
};
|
361
363
|
}
|
362
364
|
if (bodyInit instanceof ReadableStream_js_1.PonyfillReadableStream && bodyInit.readable != null) {
|
365
|
+
const readableStream = bodyInit;
|
363
366
|
return {
|
364
367
|
bodyType: BodyInitType.ReadableStream,
|
365
|
-
bodyFactory: () =>
|
368
|
+
bodyFactory: () => readableStream,
|
366
369
|
contentType: null,
|
367
370
|
contentLength: null,
|
368
371
|
};
|
369
372
|
}
|
370
373
|
if (isBlob(bodyInit)) {
|
374
|
+
const blob = bodyInit;
|
371
375
|
return {
|
372
376
|
bodyType: BodyInitType.Blob,
|
373
377
|
contentType: bodyInit.type,
|
374
378
|
contentLength: bodyInit.size,
|
375
379
|
bodyFactory() {
|
376
|
-
return
|
380
|
+
return blob.stream();
|
377
381
|
},
|
378
382
|
};
|
379
383
|
}
|
@@ -392,6 +396,21 @@ function processBodyInit(bodyInit) {
|
|
392
396
|
},
|
393
397
|
};
|
394
398
|
}
|
399
|
+
if (bodyInit instanceof node_http_1.IncomingMessage) {
|
400
|
+
const passthrough = (bodyInit = bodyInit.pipe(new node_stream_1.PassThrough(), {
|
401
|
+
end: true,
|
402
|
+
// @ts-expect-error - `signal` is not in the type definition
|
403
|
+
signal,
|
404
|
+
}));
|
405
|
+
return {
|
406
|
+
bodyType: BodyInitType.Readable,
|
407
|
+
contentType: null,
|
408
|
+
contentLength: null,
|
409
|
+
bodyFactory() {
|
410
|
+
return new ReadableStream_js_1.PonyfillReadableStream(passthrough);
|
411
|
+
},
|
412
|
+
};
|
413
|
+
}
|
395
414
|
if (bodyInit instanceof node_stream_1.Readable) {
|
396
415
|
return {
|
397
416
|
bodyType: BodyInitType.Readable,
|
package/esm/Body.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
2
2
|
import { Buffer } from 'node:buffer';
|
3
|
-
import {
|
3
|
+
import { IncomingMessage } from 'node:http';
|
4
|
+
import { PassThrough, Readable } from 'node:stream';
|
4
5
|
import busboy from 'busboy';
|
5
6
|
import { handleMaybePromise } from '@whatwg-node/promise-helpers';
|
6
7
|
import { hasArrayBufferMethod, hasBufferMethod, hasBytesMethod, PonyfillBlob } from './Blob.js';
|
@@ -27,7 +28,7 @@ export class PonyfillBody {
|
|
27
28
|
constructor(bodyInit, options = {}) {
|
28
29
|
this.bodyInit = bodyInit;
|
29
30
|
this.options = options;
|
30
|
-
const { bodyFactory, contentType, contentLength, bodyType, buffer } = processBodyInit(bodyInit);
|
31
|
+
const { bodyFactory, contentType, contentLength, bodyType, buffer } = processBodyInit(bodyInit, options?.signal);
|
31
32
|
this._bodyFactory = bodyFactory;
|
32
33
|
this.contentType = contentType;
|
33
34
|
this.contentLength = contentLength;
|
@@ -126,7 +127,7 @@ export class PonyfillBody {
|
|
126
127
|
}
|
127
128
|
const _body = this.generateBody();
|
128
129
|
this._chunks = [];
|
129
|
-
if (!_body
|
130
|
+
if (!_body) {
|
130
131
|
return fakePromise(this._chunks);
|
131
132
|
}
|
132
133
|
_body.readable.on('data', chunk => {
|
@@ -305,7 +306,7 @@ export class PonyfillBody {
|
|
305
306
|
});
|
306
307
|
}
|
307
308
|
}
|
308
|
-
function processBodyInit(bodyInit) {
|
309
|
+
function processBodyInit(bodyInit, signal) {
|
309
310
|
if (bodyInit == null) {
|
310
311
|
return {
|
311
312
|
bodyFactory: () => null,
|
@@ -328,13 +329,14 @@ function processBodyInit(bodyInit) {
|
|
328
329
|
};
|
329
330
|
}
|
330
331
|
if (Buffer.isBuffer(bodyInit)) {
|
332
|
+
const buffer = bodyInit;
|
331
333
|
return {
|
332
334
|
bodyType: BodyInitType.Buffer,
|
333
335
|
contentType: null,
|
334
336
|
contentLength: bodyInit.length,
|
335
337
|
buffer: bodyInit,
|
336
338
|
bodyFactory() {
|
337
|
-
const readable = Readable.from(
|
339
|
+
const readable = Readable.from(buffer);
|
338
340
|
const body = new PonyfillReadableStream(readable);
|
339
341
|
return body;
|
340
342
|
},
|
@@ -355,20 +357,22 @@ function processBodyInit(bodyInit) {
|
|
355
357
|
};
|
356
358
|
}
|
357
359
|
if (bodyInit instanceof PonyfillReadableStream && bodyInit.readable != null) {
|
360
|
+
const readableStream = bodyInit;
|
358
361
|
return {
|
359
362
|
bodyType: BodyInitType.ReadableStream,
|
360
|
-
bodyFactory: () =>
|
363
|
+
bodyFactory: () => readableStream,
|
361
364
|
contentType: null,
|
362
365
|
contentLength: null,
|
363
366
|
};
|
364
367
|
}
|
365
368
|
if (isBlob(bodyInit)) {
|
369
|
+
const blob = bodyInit;
|
366
370
|
return {
|
367
371
|
bodyType: BodyInitType.Blob,
|
368
372
|
contentType: bodyInit.type,
|
369
373
|
contentLength: bodyInit.size,
|
370
374
|
bodyFactory() {
|
371
|
-
return
|
375
|
+
return blob.stream();
|
372
376
|
},
|
373
377
|
};
|
374
378
|
}
|
@@ -387,6 +391,21 @@ function processBodyInit(bodyInit) {
|
|
387
391
|
},
|
388
392
|
};
|
389
393
|
}
|
394
|
+
if (bodyInit instanceof IncomingMessage) {
|
395
|
+
const passthrough = (bodyInit = bodyInit.pipe(new PassThrough(), {
|
396
|
+
end: true,
|
397
|
+
// @ts-expect-error - `signal` is not in the type definition
|
398
|
+
signal,
|
399
|
+
}));
|
400
|
+
return {
|
401
|
+
bodyType: BodyInitType.Readable,
|
402
|
+
contentType: null,
|
403
|
+
contentLength: null,
|
404
|
+
bodyFactory() {
|
405
|
+
return new PonyfillReadableStream(passthrough);
|
406
|
+
},
|
407
|
+
};
|
408
|
+
}
|
390
409
|
if (bodyInit instanceof Readable) {
|
391
410
|
return {
|
392
411
|
bodyType: BodyInitType.Readable,
|
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-20250322145808-458c0d572d10c5277497e947a182be65760c50ff",
|
4
4
|
"description": "Fetch API implementation for Node",
|
5
5
|
"sideEffects": false,
|
6
6
|
"dependencies": {
|
package/typings/Body.d.cts
CHANGED
package/typings/Body.d.ts
CHANGED