@whatwg-node/node-fetch 0.7.12-rc-20250225131304-4190dbdf70ce9831363d3828914f7283fca0ffd7 → 0.7.13-alpha-20250316013348-3c5910f2427d78311ae177c7ba02ffe499a1a399

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,6 +6,7 @@ const tslib_1 = require("tslib");
6
6
  const node_buffer_1 = require("node:buffer");
7
7
  const node_stream_1 = require("node:stream");
8
8
  const busboy_1 = tslib_1.__importDefault(require("busboy"));
9
+ const promise_helpers_1 = require("@whatwg-node/promise-helpers");
9
10
  const Blob_js_1 = require("./Blob.js");
10
11
  const File_js_1 = require("./File.js");
11
12
  const FormData_js_1 = require("./FormData.js");
@@ -108,36 +109,36 @@ class PonyfillBody {
108
109
  return (0, utils_js_1.fakePromise)(this._chunks);
109
110
  }
110
111
  if (this.bodyType === BodyInitType.AsyncIterable) {
111
- const iterator = this.bodyInit[Symbol.asyncIterator]();
112
- const collectValue = () => {
113
- return iterator.next().then(({ value, done }) => {
114
- this._chunks ||= [];
115
- if (value) {
116
- this._chunks.push(value);
117
- }
118
- if (!done) {
119
- return collectValue();
120
- }
112
+ if (Array.fromAsync) {
113
+ return (0, promise_helpers_1.handleMaybePromise)(() => Array.fromAsync(this.bodyInit), chunks => {
114
+ this._chunks = chunks;
121
115
  return this._chunks;
122
116
  });
123
- };
117
+ }
118
+ const iterator = this.bodyInit[Symbol.asyncIterator]();
119
+ const collectValue = () => (0, promise_helpers_1.handleMaybePromise)(() => iterator.next(), ({ value, done }) => {
120
+ this._chunks ||= [];
121
+ if (value) {
122
+ this._chunks.push(value);
123
+ }
124
+ if (!done) {
125
+ return collectValue();
126
+ }
127
+ return this._chunks;
128
+ });
124
129
  return collectValue();
125
130
  }
126
131
  const _body = this.generateBody();
127
132
  if (!_body) {
133
+ this._chunks = [];
128
134
  return (0, utils_js_1.fakePromise)([]);
129
135
  }
130
- this._chunks = [];
131
136
  _body.readable.on('data', chunk => {
132
137
  this._chunks.push(chunk);
133
138
  });
134
139
  return new Promise((resolve, reject) => {
135
- _body.readable.once('end', () => {
136
- resolve(this._chunks);
137
- });
138
- _body.readable.once('error', e => {
139
- reject(e);
140
- });
140
+ _body.readable.once('end', () => resolve(this._chunks));
141
+ _body.readable.once('error', reject);
141
142
  });
142
143
  }
143
144
  _blob = null;
@@ -156,13 +157,13 @@ class PonyfillBody {
156
157
  });
157
158
  return (0, utils_js_1.fakePromise)(this._blob);
158
159
  }
159
- return this._collectChunksFromReadable().then(chunks => {
160
+ return (0, utils_js_1.fakePromise)((0, promise_helpers_1.handleMaybePromise)(() => this._collectChunksFromReadable(), chunks => {
160
161
  this._blob = new Blob_js_1.PonyfillBlob(chunks, {
161
162
  type: this.contentType || '',
162
163
  size: this.contentLength,
163
164
  });
164
165
  return this._blob;
165
- });
166
+ }));
166
167
  }
167
168
  _formData = null;
168
169
  formData(opts) {
@@ -259,14 +260,14 @@ class PonyfillBody {
259
260
  });
260
261
  }
261
262
  }
262
- return this._collectChunksFromReadable().then(chunks => {
263
+ return (0, utils_js_1.fakePromise)((0, promise_helpers_1.handleMaybePromise)(() => this._collectChunksFromReadable(), chunks => {
263
264
  if (chunks.length === 1) {
264
265
  this._buffer = chunks[0];
265
266
  return this._buffer;
266
267
  }
267
268
  this._buffer = node_buffer_1.Buffer.concat(chunks);
268
269
  return this._buffer;
269
- });
270
+ }));
270
271
  }
271
272
  bytes() {
272
273
  return this.buffer();
package/esm/Body.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { Buffer } from 'node:buffer';
3
3
  import { Readable } from 'node:stream';
4
4
  import busboy from 'busboy';
5
+ import { handleMaybePromise } from '@whatwg-node/promise-helpers';
5
6
  import { hasArrayBufferMethod, hasBufferMethod, hasBytesMethod, PonyfillBlob } from './Blob.js';
6
7
  import { PonyfillFile } from './File.js';
7
8
  import { getStreamFromFormData, PonyfillFormData } from './FormData.js';
@@ -104,36 +105,36 @@ export class PonyfillBody {
104
105
  return fakePromise(this._chunks);
105
106
  }
106
107
  if (this.bodyType === BodyInitType.AsyncIterable) {
107
- const iterator = this.bodyInit[Symbol.asyncIterator]();
108
- const collectValue = () => {
109
- return iterator.next().then(({ value, done }) => {
110
- this._chunks ||= [];
111
- if (value) {
112
- this._chunks.push(value);
113
- }
114
- if (!done) {
115
- return collectValue();
116
- }
108
+ if (Array.fromAsync) {
109
+ return handleMaybePromise(() => Array.fromAsync(this.bodyInit), chunks => {
110
+ this._chunks = chunks;
117
111
  return this._chunks;
118
112
  });
119
- };
113
+ }
114
+ const iterator = this.bodyInit[Symbol.asyncIterator]();
115
+ const collectValue = () => handleMaybePromise(() => iterator.next(), ({ value, done }) => {
116
+ this._chunks ||= [];
117
+ if (value) {
118
+ this._chunks.push(value);
119
+ }
120
+ if (!done) {
121
+ return collectValue();
122
+ }
123
+ return this._chunks;
124
+ });
120
125
  return collectValue();
121
126
  }
122
127
  const _body = this.generateBody();
123
128
  if (!_body) {
129
+ this._chunks = [];
124
130
  return fakePromise([]);
125
131
  }
126
- this._chunks = [];
127
132
  _body.readable.on('data', chunk => {
128
133
  this._chunks.push(chunk);
129
134
  });
130
135
  return new Promise((resolve, reject) => {
131
- _body.readable.once('end', () => {
132
- resolve(this._chunks);
133
- });
134
- _body.readable.once('error', e => {
135
- reject(e);
136
- });
136
+ _body.readable.once('end', () => resolve(this._chunks));
137
+ _body.readable.once('error', reject);
137
138
  });
138
139
  }
139
140
  _blob = null;
@@ -152,13 +153,13 @@ export class PonyfillBody {
152
153
  });
153
154
  return fakePromise(this._blob);
154
155
  }
155
- return this._collectChunksFromReadable().then(chunks => {
156
+ return fakePromise(handleMaybePromise(() => this._collectChunksFromReadable(), chunks => {
156
157
  this._blob = new PonyfillBlob(chunks, {
157
158
  type: this.contentType || '',
158
159
  size: this.contentLength,
159
160
  });
160
161
  return this._blob;
161
- });
162
+ }));
162
163
  }
163
164
  _formData = null;
164
165
  formData(opts) {
@@ -255,14 +256,14 @@ export class PonyfillBody {
255
256
  });
256
257
  }
257
258
  }
258
- return this._collectChunksFromReadable().then(chunks => {
259
+ return fakePromise(handleMaybePromise(() => this._collectChunksFromReadable(), chunks => {
259
260
  if (chunks.length === 1) {
260
261
  this._buffer = chunks[0];
261
262
  return this._buffer;
262
263
  }
263
264
  this._buffer = Buffer.concat(chunks);
264
265
  return this._buffer;
265
- });
266
+ }));
266
267
  }
267
268
  bytes() {
268
269
  return this.buffer();
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.7.12-rc-20250225131304-4190dbdf70ce9831363d3828914f7283fca0ffd7",
3
+ "version": "0.7.13-alpha-20250316013348-3c5910f2427d78311ae177c7ba02ffe499a1a399",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
7
- "@whatwg-node/disposablestack": "0.0.6-rc-20250225131304-4190dbdf70ce9831363d3828914f7283fca0ffd7",
8
- "@whatwg-node/promise-helpers": "1.0.0-rc-20250225131304-4190dbdf70ce9831363d3828914f7283fca0ffd7",
7
+ "@whatwg-node/disposablestack": "^0.0.6",
8
+ "@whatwg-node/promise-helpers": "1.2.5-alpha-20250316013348-3c5910f2427d78311ae177c7ba02ffe499a1a399",
9
9
  "busboy": "^1.6.0",
10
10
  "tslib": "^2.6.3"
11
11
  },
@@ -1,5 +1,6 @@
1
1
  import { Buffer } from 'node:buffer';
2
2
  import { Readable } from 'node:stream';
3
+ import { MaybePromise } from '@whatwg-node/promise-helpers';
3
4
  import { PonyfillBlob } from './Blob.cjs';
4
5
  import { PonyfillFormData } from './FormData.cjs';
5
6
  import { PonyfillReadableStream } from './ReadableStream.cjs';
@@ -33,7 +34,7 @@ export declare class PonyfillBody<TJSON = any> implements Body {
33
34
  }, forceSet?: boolean): void;
34
35
  get body(): PonyfillReadableStream<Uint8Array> | null;
35
36
  _chunks: Uint8Array[] | null;
36
- _collectChunksFromReadable(): Promise<Uint8Array<ArrayBufferLike>[]>;
37
+ _collectChunksFromReadable(): MaybePromise<Uint8Array<ArrayBufferLike>[]>;
37
38
  _blob: PonyfillBlob | null;
38
39
  blob(): Promise<PonyfillBlob>;
39
40
  _formData: PonyfillFormData | null;
package/typings/Body.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Buffer } from 'node:buffer';
2
2
  import { Readable } from 'node:stream';
3
+ import { MaybePromise } from '@whatwg-node/promise-helpers';
3
4
  import { PonyfillBlob } from './Blob.js';
4
5
  import { PonyfillFormData } from './FormData.js';
5
6
  import { PonyfillReadableStream } from './ReadableStream.js';
@@ -33,7 +34,7 @@ export declare class PonyfillBody<TJSON = any> implements Body {
33
34
  }, forceSet?: boolean): void;
34
35
  get body(): PonyfillReadableStream<Uint8Array> | null;
35
36
  _chunks: Uint8Array[] | null;
36
- _collectChunksFromReadable(): Promise<Uint8Array<ArrayBufferLike>[]>;
37
+ _collectChunksFromReadable(): MaybePromise<Uint8Array<ArrayBufferLike>[]>;
37
38
  _blob: PonyfillBlob | null;
38
39
  blob(): Promise<PonyfillBlob>;
39
40
  _formData: PonyfillFormData | null;