@whatwg-node/node-fetch 0.7.12 → 0.7.13-alpha-20250316014213-6b5d97cf20e1c790fba9f3c11c0cd0f6a3f67fa0

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,37 @@ 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) {
128
- return (0, utils_js_1.fakePromise)([]);
133
+ this._chunks = [];
134
+ return (0, utils_js_1.fakePromise)(this._chunks);
129
135
  }
130
136
  this._chunks = [];
131
137
  _body.readable.on('data', chunk => {
132
138
  this._chunks.push(chunk);
133
139
  });
134
140
  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
- });
141
+ _body.readable.once('end', () => resolve(this._chunks));
142
+ _body.readable.once('error', reject);
141
143
  });
142
144
  }
143
145
  _blob = null;
@@ -156,13 +158,13 @@ class PonyfillBody {
156
158
  });
157
159
  return (0, utils_js_1.fakePromise)(this._blob);
158
160
  }
159
- return this._collectChunksFromReadable().then(chunks => {
161
+ return (0, utils_js_1.fakePromise)((0, promise_helpers_1.handleMaybePromise)(() => this._collectChunksFromReadable(), chunks => {
160
162
  this._blob = new Blob_js_1.PonyfillBlob(chunks, {
161
163
  type: this.contentType || '',
162
164
  size: this.contentLength,
163
165
  });
164
166
  return this._blob;
165
- });
167
+ }));
166
168
  }
167
169
  _formData = null;
168
170
  formData(opts) {
@@ -259,14 +261,14 @@ class PonyfillBody {
259
261
  });
260
262
  }
261
263
  }
262
- return this._collectChunksFromReadable().then(chunks => {
264
+ return (0, utils_js_1.fakePromise)((0, promise_helpers_1.handleMaybePromise)(() => this._collectChunksFromReadable(), chunks => {
263
265
  if (chunks.length === 1) {
264
266
  this._buffer = chunks[0];
265
267
  return this._buffer;
266
268
  }
267
269
  this._buffer = node_buffer_1.Buffer.concat(chunks);
268
270
  return this._buffer;
269
- });
271
+ }));
270
272
  }
271
273
  bytes() {
272
274
  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,37 @@ 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) {
124
- return fakePromise([]);
129
+ this._chunks = [];
130
+ return fakePromise(this._chunks);
125
131
  }
126
132
  this._chunks = [];
127
133
  _body.readable.on('data', chunk => {
128
134
  this._chunks.push(chunk);
129
135
  });
130
136
  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
- });
137
+ _body.readable.once('end', () => resolve(this._chunks));
138
+ _body.readable.once('error', reject);
137
139
  });
138
140
  }
139
141
  _blob = null;
@@ -152,13 +154,13 @@ export class PonyfillBody {
152
154
  });
153
155
  return fakePromise(this._blob);
154
156
  }
155
- return this._collectChunksFromReadable().then(chunks => {
157
+ return fakePromise(handleMaybePromise(() => this._collectChunksFromReadable(), chunks => {
156
158
  this._blob = new PonyfillBlob(chunks, {
157
159
  type: this.contentType || '',
158
160
  size: this.contentLength,
159
161
  });
160
162
  return this._blob;
161
- });
163
+ }));
162
164
  }
163
165
  _formData = null;
164
166
  formData(opts) {
@@ -255,14 +257,14 @@ export class PonyfillBody {
255
257
  });
256
258
  }
257
259
  }
258
- return this._collectChunksFromReadable().then(chunks => {
260
+ return fakePromise(handleMaybePromise(() => this._collectChunksFromReadable(), chunks => {
259
261
  if (chunks.length === 1) {
260
262
  this._buffer = chunks[0];
261
263
  return this._buffer;
262
264
  }
263
265
  this._buffer = Buffer.concat(chunks);
264
266
  return this._buffer;
265
- });
267
+ }));
266
268
  }
267
269
  bytes() {
268
270
  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",
3
+ "version": "0.7.13-alpha-20250316014213-6b5d97cf20e1c790fba9f3c11c0cd0f6a3f67fa0",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
7
7
  "@whatwg-node/disposablestack": "^0.0.6",
8
- "@whatwg-node/promise-helpers": "^1.0.0",
8
+ "@whatwg-node/promise-helpers": "1.2.5-alpha-20250316014213-6b5d97cf20e1c790fba9f3c11c0cd0f6a3f67fa0",
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;