@whatwg-node/node-fetch 0.7.15-alpha-20250324152850-1b681df1e3d925eec62c6484005be529f840b2e8 → 0.7.15-alpha-20250324173553-1c494d807956f93726a5088943b9a352670208b0

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 CHANGED
@@ -6,7 +6,6 @@ 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");
10
9
  const busboy_1 = tslib_1.__importDefault(require("busboy"));
11
10
  const promise_helpers_1 = require("@whatwg-node/promise-helpers");
12
11
  const Blob_js_1 = require("./Blob.js");
@@ -133,16 +132,9 @@ class PonyfillBody {
133
132
  this._chunks = [];
134
133
  return (0, utils_js_1.fakePromise)(this._chunks);
135
134
  }
136
- const chunks = [];
137
- _body.readable.on('data', chunk => {
138
- chunks.push(chunk);
139
- });
140
- return new Promise((resolve, reject) => {
141
- _body.readable.once('end', () => {
142
- this._chunks = chunks;
143
- resolve(this._chunks);
144
- });
145
- _body.readable.once('error', reject);
135
+ return _body.readable.toArray({ signal: this.signal }).then(chunks => {
136
+ this._chunks = chunks;
137
+ return this._chunks;
146
138
  });
147
139
  }
148
140
  _collectChunksFromReadable() {
@@ -407,27 +399,17 @@ function processBodyInit(bodyInit, signal) {
407
399
  };
408
400
  }
409
401
  if (bodyInit instanceof node_http_1.IncomingMessage) {
410
- const passthrough = new node_stream_1.PassThrough({
402
+ const passThrough = bodyInit.pipe(new node_stream_1.PassThrough({
411
403
  signal,
412
- });
413
- (0, promises_1.pipeline)(bodyInit, passthrough, {
404
+ }), {
414
405
  end: true,
415
- signal,
416
- })
417
- .then(() => {
418
- if (!bodyInit.destroyed) {
419
- bodyInit.resume();
420
- }
421
- })
422
- .catch(e => {
423
- passthrough.destroy(e);
424
406
  });
425
407
  return {
426
408
  bodyType: BodyInitType.Readable,
427
409
  contentType: null,
428
410
  contentLength: null,
429
411
  bodyFactory() {
430
- return new ReadableStream_js_1.PonyfillReadableStream(passthrough);
412
+ return new ReadableStream_js_1.PonyfillReadableStream(passThrough);
431
413
  },
432
414
  };
433
415
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PonyfillReadableStream = void 0;
4
4
  const node_buffer_1 = require("node:buffer");
5
5
  const node_stream_1 = require("node:stream");
6
+ const promise_helpers_1 = require("@whatwg-node/promise-helpers");
6
7
  const utils_js_1 = require("./utils.js");
7
8
  function createController(desiredSize, readable) {
8
9
  let chunks = [];
@@ -66,20 +67,31 @@ class PonyfillReadableStream {
66
67
  else {
67
68
  let started = false;
68
69
  let ongoing = false;
69
- const readImpl = async (desiredSize) => {
70
+ const handleStart = (desiredSize) => {
70
71
  if (!started) {
71
72
  const controller = createController(desiredSize, this.readable);
72
73
  started = true;
73
- await underlyingSource?.start?.(controller);
74
- controller._flush();
75
- if (controller._closed) {
74
+ return (0, promise_helpers_1.handleMaybePromise)(() => underlyingSource?.start?.(controller), () => {
75
+ controller._flush();
76
+ if (controller._closed) {
77
+ return false;
78
+ }
79
+ return true;
80
+ });
81
+ }
82
+ return true;
83
+ };
84
+ const readImpl = (desiredSize) => {
85
+ return (0, promise_helpers_1.handleMaybePromise)(() => handleStart(desiredSize), shouldContinue => {
86
+ if (!shouldContinue) {
76
87
  return;
77
88
  }
78
- }
79
- const controller = createController(desiredSize, this.readable);
80
- await underlyingSource?.pull?.(controller);
81
- controller._flush();
82
- ongoing = false;
89
+ const controller = createController(desiredSize, this.readable);
90
+ return (0, promise_helpers_1.handleMaybePromise)(() => underlyingSource?.pull?.(controller), () => {
91
+ controller._flush();
92
+ ongoing = false;
93
+ });
94
+ });
83
95
  };
84
96
  this.readable = new node_stream_1.Readable({
85
97
  read(desiredSize) {
package/esm/Body.js CHANGED
@@ -2,7 +2,6 @@
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';
6
5
  import busboy from 'busboy';
7
6
  import { handleMaybePromise } from '@whatwg-node/promise-helpers';
8
7
  import { hasArrayBufferMethod, hasBufferMethod, hasBytesMethod, PonyfillBlob } from './Blob.js';
@@ -129,16 +128,9 @@ export class PonyfillBody {
129
128
  this._chunks = [];
130
129
  return fakePromise(this._chunks);
131
130
  }
132
- const chunks = [];
133
- _body.readable.on('data', chunk => {
134
- chunks.push(chunk);
135
- });
136
- return new Promise((resolve, reject) => {
137
- _body.readable.once('end', () => {
138
- this._chunks = chunks;
139
- resolve(this._chunks);
140
- });
141
- _body.readable.once('error', reject);
131
+ return _body.readable.toArray({ signal: this.signal }).then(chunks => {
132
+ this._chunks = chunks;
133
+ return this._chunks;
142
134
  });
143
135
  }
144
136
  _collectChunksFromReadable() {
@@ -402,27 +394,17 @@ function processBodyInit(bodyInit, signal) {
402
394
  };
403
395
  }
404
396
  if (bodyInit instanceof IncomingMessage) {
405
- const passthrough = new PassThrough({
397
+ const passThrough = bodyInit.pipe(new PassThrough({
406
398
  signal,
407
- });
408
- pipeline(bodyInit, passthrough, {
399
+ }), {
409
400
  end: true,
410
- signal,
411
- })
412
- .then(() => {
413
- if (!bodyInit.destroyed) {
414
- bodyInit.resume();
415
- }
416
- })
417
- .catch(e => {
418
- passthrough.destroy(e);
419
401
  });
420
402
  return {
421
403
  bodyType: BodyInitType.Readable,
422
404
  contentType: null,
423
405
  contentLength: null,
424
406
  bodyFactory() {
425
- return new PonyfillReadableStream(passthrough);
407
+ return new PonyfillReadableStream(passThrough);
426
408
  },
427
409
  };
428
410
  }
@@ -1,5 +1,6 @@
1
1
  import { Buffer } from 'node:buffer';
2
2
  import { Readable } from 'node:stream';
3
+ import { handleMaybePromise } from '@whatwg-node/promise-helpers';
3
4
  import { fakePromise } from './utils.js';
4
5
  function createController(desiredSize, readable) {
5
6
  let chunks = [];
@@ -63,20 +64,31 @@ export class PonyfillReadableStream {
63
64
  else {
64
65
  let started = false;
65
66
  let ongoing = false;
66
- const readImpl = async (desiredSize) => {
67
+ const handleStart = (desiredSize) => {
67
68
  if (!started) {
68
69
  const controller = createController(desiredSize, this.readable);
69
70
  started = true;
70
- await underlyingSource?.start?.(controller);
71
- controller._flush();
72
- if (controller._closed) {
71
+ return handleMaybePromise(() => underlyingSource?.start?.(controller), () => {
72
+ controller._flush();
73
+ if (controller._closed) {
74
+ return false;
75
+ }
76
+ return true;
77
+ });
78
+ }
79
+ return true;
80
+ };
81
+ const readImpl = (desiredSize) => {
82
+ return handleMaybePromise(() => handleStart(desiredSize), shouldContinue => {
83
+ if (!shouldContinue) {
73
84
  return;
74
85
  }
75
- }
76
- const controller = createController(desiredSize, this.readable);
77
- await underlyingSource?.pull?.(controller);
78
- controller._flush();
79
- ongoing = false;
86
+ const controller = createController(desiredSize, this.readable);
87
+ return handleMaybePromise(() => underlyingSource?.pull?.(controller), () => {
88
+ controller._flush();
89
+ ongoing = false;
90
+ });
91
+ });
80
92
  };
81
93
  this.readable = new Readable({
82
94
  read(desiredSize) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.7.15-alpha-20250324152850-1b681df1e3d925eec62c6484005be529f840b2e8",
3
+ "version": "0.7.15-alpha-20250324173553-1c494d807956f93726a5088943b9a352670208b0",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {