@whatwg-node/node-fetch 0.0.1-alpha-20221228110541-2aa6aea → 0.0.1-alpha-20221228115139-6b81aa1
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/Body.d.ts +0 -1
- package/index.js +16 -32
- package/index.mjs +16 -32
- package/package.json +1 -1
package/Body.d.ts
CHANGED
package/index.js
CHANGED
@@ -95,17 +95,13 @@ class PonyfillReadableStream {
|
|
95
95
|
}
|
96
96
|
else if (underlyingSource && 'getReader' in underlyingSource) {
|
97
97
|
let reader;
|
98
|
+
let started = false;
|
98
99
|
this.readable = new stream.Readable({
|
99
|
-
|
100
|
-
|
100
|
+
read() {
|
101
|
+
if (!started) {
|
102
|
+
started = true;
|
101
103
|
reader = underlyingSource.getReader();
|
102
|
-
callback(null);
|
103
104
|
}
|
104
|
-
catch (err) {
|
105
|
-
callback(err);
|
106
|
-
}
|
107
|
-
},
|
108
|
-
read() {
|
109
105
|
reader
|
110
106
|
.read()
|
111
107
|
.then(({ value, done }) => {
|
@@ -126,23 +122,16 @@ class PonyfillReadableStream {
|
|
126
122
|
});
|
127
123
|
}
|
128
124
|
else {
|
125
|
+
let started = false;
|
129
126
|
this.readable = new stream.Readable({
|
130
|
-
async construct(callback) {
|
131
|
-
var _a;
|
132
|
-
try {
|
133
|
-
const controller = createController(0, this);
|
134
|
-
await ((_a = underlyingSource === null || underlyingSource === void 0 ? void 0 : underlyingSource.start) === null || _a === void 0 ? void 0 : _a.call(underlyingSource, controller));
|
135
|
-
controller._flush();
|
136
|
-
callback(null);
|
137
|
-
}
|
138
|
-
catch (err) {
|
139
|
-
callback(err);
|
140
|
-
}
|
141
|
-
},
|
142
127
|
async read(desiredSize) {
|
143
|
-
var _a;
|
128
|
+
var _a, _b;
|
144
129
|
const controller = createController(desiredSize, this);
|
145
|
-
|
130
|
+
if (!started) {
|
131
|
+
started = true;
|
132
|
+
await ((_a = underlyingSource === null || underlyingSource === void 0 ? void 0 : underlyingSource.start) === null || _a === void 0 ? void 0 : _a.call(underlyingSource, controller));
|
133
|
+
}
|
134
|
+
await ((_b = underlyingSource === null || underlyingSource === void 0 ? void 0 : underlyingSource.pull) === null || _b === void 0 ? void 0 : _b.call(underlyingSource, controller));
|
146
135
|
controller._flush();
|
147
136
|
},
|
148
137
|
async destroy(err, callback) {
|
@@ -493,15 +482,6 @@ class PonyfillBody {
|
|
493
482
|
const blob = await this.blob();
|
494
483
|
return blob.text();
|
495
484
|
}
|
496
|
-
readable() {
|
497
|
-
if (this.bodyType === BodyInitType.Readable) {
|
498
|
-
return this.bodyInit;
|
499
|
-
}
|
500
|
-
if (this._body != null) {
|
501
|
-
return this._body.readable;
|
502
|
-
}
|
503
|
-
return null;
|
504
|
-
}
|
505
485
|
}
|
506
486
|
|
507
487
|
class PonyfillHeaders {
|
@@ -735,7 +715,11 @@ const fetchPonyfill = (info, init) => {
|
|
735
715
|
return;
|
736
716
|
}
|
737
717
|
const requestFn = getRequestFnForProtocol(protocol);
|
738
|
-
const nodeReadable = fetchRequest.body
|
718
|
+
const nodeReadable = (fetchRequest.body != null
|
719
|
+
? 'pipe' in fetchRequest.body
|
720
|
+
? fetchRequest.body
|
721
|
+
: stream.Readable.from(fetchRequest.body)
|
722
|
+
: null);
|
739
723
|
const nodeHeaders = getHeadersObj(fetchRequest.headers);
|
740
724
|
const abortListener = function abortListener(event) {
|
741
725
|
nodeRequest.destroy();
|
package/index.mjs
CHANGED
@@ -89,17 +89,13 @@ class PonyfillReadableStream {
|
|
89
89
|
}
|
90
90
|
else if (underlyingSource && 'getReader' in underlyingSource) {
|
91
91
|
let reader;
|
92
|
+
let started = false;
|
92
93
|
this.readable = new Readable({
|
93
|
-
|
94
|
-
|
94
|
+
read() {
|
95
|
+
if (!started) {
|
96
|
+
started = true;
|
95
97
|
reader = underlyingSource.getReader();
|
96
|
-
callback(null);
|
97
98
|
}
|
98
|
-
catch (err) {
|
99
|
-
callback(err);
|
100
|
-
}
|
101
|
-
},
|
102
|
-
read() {
|
103
99
|
reader
|
104
100
|
.read()
|
105
101
|
.then(({ value, done }) => {
|
@@ -120,23 +116,16 @@ class PonyfillReadableStream {
|
|
120
116
|
});
|
121
117
|
}
|
122
118
|
else {
|
119
|
+
let started = false;
|
123
120
|
this.readable = new Readable({
|
124
|
-
async construct(callback) {
|
125
|
-
var _a;
|
126
|
-
try {
|
127
|
-
const controller = createController(0, this);
|
128
|
-
await ((_a = underlyingSource === null || underlyingSource === void 0 ? void 0 : underlyingSource.start) === null || _a === void 0 ? void 0 : _a.call(underlyingSource, controller));
|
129
|
-
controller._flush();
|
130
|
-
callback(null);
|
131
|
-
}
|
132
|
-
catch (err) {
|
133
|
-
callback(err);
|
134
|
-
}
|
135
|
-
},
|
136
121
|
async read(desiredSize) {
|
137
|
-
var _a;
|
122
|
+
var _a, _b;
|
138
123
|
const controller = createController(desiredSize, this);
|
139
|
-
|
124
|
+
if (!started) {
|
125
|
+
started = true;
|
126
|
+
await ((_a = underlyingSource === null || underlyingSource === void 0 ? void 0 : underlyingSource.start) === null || _a === void 0 ? void 0 : _a.call(underlyingSource, controller));
|
127
|
+
}
|
128
|
+
await ((_b = underlyingSource === null || underlyingSource === void 0 ? void 0 : underlyingSource.pull) === null || _b === void 0 ? void 0 : _b.call(underlyingSource, controller));
|
140
129
|
controller._flush();
|
141
130
|
},
|
142
131
|
async destroy(err, callback) {
|
@@ -487,15 +476,6 @@ class PonyfillBody {
|
|
487
476
|
const blob = await this.blob();
|
488
477
|
return blob.text();
|
489
478
|
}
|
490
|
-
readable() {
|
491
|
-
if (this.bodyType === BodyInitType.Readable) {
|
492
|
-
return this.bodyInit;
|
493
|
-
}
|
494
|
-
if (this._body != null) {
|
495
|
-
return this._body.readable;
|
496
|
-
}
|
497
|
-
return null;
|
498
|
-
}
|
499
479
|
}
|
500
480
|
|
501
481
|
class PonyfillHeaders {
|
@@ -729,7 +709,11 @@ const fetchPonyfill = (info, init) => {
|
|
729
709
|
return;
|
730
710
|
}
|
731
711
|
const requestFn = getRequestFnForProtocol(protocol);
|
732
|
-
const nodeReadable = fetchRequest.body
|
712
|
+
const nodeReadable = (fetchRequest.body != null
|
713
|
+
? 'pipe' in fetchRequest.body
|
714
|
+
? fetchRequest.body
|
715
|
+
: Readable.from(fetchRequest.body)
|
716
|
+
: null);
|
733
717
|
const nodeHeaders = getHeadersObj(fetchRequest.headers);
|
734
718
|
const abortListener = function abortListener(event) {
|
735
719
|
nodeRequest.destroy();
|
package/package.json
CHANGED