@whatwg-node/node-fetch 0.5.26 → 0.5.27-rc-20241021101607-5245fc7b06565b5acb9f6206add370e6dd49bde3
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 +18 -0
- package/esm/Body.js +18 -0
- package/package.json +1 -1
package/cjs/Body.js
CHANGED
@@ -17,6 +17,7 @@ var BodyInitType;
|
|
17
17
|
BodyInitType["String"] = "String";
|
18
18
|
BodyInitType["Readable"] = "Readable";
|
19
19
|
BodyInitType["Buffer"] = "Buffer";
|
20
|
+
BodyInitType["AsyncIterable"] = "AsyncIterable";
|
20
21
|
})(BodyInitType || (BodyInitType = {}));
|
21
22
|
class PonyfillBody {
|
22
23
|
bodyInit;
|
@@ -104,6 +105,22 @@ class PonyfillBody {
|
|
104
105
|
if (this._chunks) {
|
105
106
|
return (0, utils_js_1.fakePromise)(this._chunks);
|
106
107
|
}
|
108
|
+
if (this.bodyType === BodyInitType.AsyncIterable) {
|
109
|
+
const iterator = this.bodyInit[Symbol.asyncIterator]();
|
110
|
+
const collectValue = () => {
|
111
|
+
return iterator.next().then(({ value, done }) => {
|
112
|
+
this._chunks ||= [];
|
113
|
+
if (value) {
|
114
|
+
this._chunks.push(value);
|
115
|
+
}
|
116
|
+
if (!done) {
|
117
|
+
return collectValue();
|
118
|
+
}
|
119
|
+
return this._chunks;
|
120
|
+
});
|
121
|
+
};
|
122
|
+
return collectValue();
|
123
|
+
}
|
107
124
|
const _body = this.generateBody();
|
108
125
|
if (!_body) {
|
109
126
|
return (0, utils_js_1.fakePromise)([]);
|
@@ -418,6 +435,7 @@ function processBodyInit(bodyInit) {
|
|
418
435
|
return {
|
419
436
|
contentType: null,
|
420
437
|
contentLength: null,
|
438
|
+
bodyType: BodyInitType.AsyncIterable,
|
421
439
|
bodyFactory() {
|
422
440
|
const readable = stream_1.Readable.from(bodyInit);
|
423
441
|
return new ReadableStream_js_1.PonyfillReadableStream(readable);
|
package/esm/Body.js
CHANGED
@@ -13,6 +13,7 @@ var BodyInitType;
|
|
13
13
|
BodyInitType["String"] = "String";
|
14
14
|
BodyInitType["Readable"] = "Readable";
|
15
15
|
BodyInitType["Buffer"] = "Buffer";
|
16
|
+
BodyInitType["AsyncIterable"] = "AsyncIterable";
|
16
17
|
})(BodyInitType || (BodyInitType = {}));
|
17
18
|
export class PonyfillBody {
|
18
19
|
bodyInit;
|
@@ -100,6 +101,22 @@ export class PonyfillBody {
|
|
100
101
|
if (this._chunks) {
|
101
102
|
return fakePromise(this._chunks);
|
102
103
|
}
|
104
|
+
if (this.bodyType === BodyInitType.AsyncIterable) {
|
105
|
+
const iterator = this.bodyInit[Symbol.asyncIterator]();
|
106
|
+
const collectValue = () => {
|
107
|
+
return iterator.next().then(({ value, done }) => {
|
108
|
+
this._chunks ||= [];
|
109
|
+
if (value) {
|
110
|
+
this._chunks.push(value);
|
111
|
+
}
|
112
|
+
if (!done) {
|
113
|
+
return collectValue();
|
114
|
+
}
|
115
|
+
return this._chunks;
|
116
|
+
});
|
117
|
+
};
|
118
|
+
return collectValue();
|
119
|
+
}
|
103
120
|
const _body = this.generateBody();
|
104
121
|
if (!_body) {
|
105
122
|
return fakePromise([]);
|
@@ -413,6 +430,7 @@ function processBodyInit(bodyInit) {
|
|
413
430
|
return {
|
414
431
|
contentType: null,
|
415
432
|
contentLength: null,
|
433
|
+
bodyType: BodyInitType.AsyncIterable,
|
416
434
|
bodyFactory() {
|
417
435
|
const readable = Readable.from(bodyInit);
|
418
436
|
return new PonyfillReadableStream(readable);
|
package/package.json
CHANGED