@whatwg-node/node-fetch 0.0.1-alpha-20221228110205-1d6dcac → 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 +20 -36
- package/index.mjs +20 -36
- 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) {
|
@@ -397,7 +386,7 @@ class PonyfillBody {
|
|
397
386
|
}
|
398
387
|
return readableProp;
|
399
388
|
}
|
400
|
-
}
|
389
|
+
},
|
401
390
|
});
|
402
391
|
}
|
403
392
|
return null;
|
@@ -434,10 +423,10 @@ class PonyfillBody {
|
|
434
423
|
var _a;
|
435
424
|
const bb = busboy({
|
436
425
|
headers: {
|
437
|
-
'content-type': this.contentType || ''
|
426
|
+
'content-type': this.contentType || '',
|
438
427
|
},
|
439
428
|
limits: formDataLimits,
|
440
|
-
defParamCharset: 'utf-8'
|
429
|
+
defParamCharset: 'utf-8',
|
441
430
|
});
|
442
431
|
bb.on('field', (name, value, { nameTruncated, valueTruncated }) => {
|
443
432
|
if (nameTruncated) {
|
@@ -456,7 +445,7 @@ class PonyfillBody {
|
|
456
445
|
fileStream.on('limit', () => {
|
457
446
|
reject(new Error(`File size limit exceeded: ${formDataLimits === null || formDataLimits === void 0 ? void 0 : formDataLimits.fileSize} bytes`));
|
458
447
|
});
|
459
|
-
fileStream.on('data',
|
448
|
+
fileStream.on('data', chunk => {
|
460
449
|
chunks.push(Buffer.from(chunk));
|
461
450
|
});
|
462
451
|
fileStream.on('close', () => {
|
@@ -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) {
|
@@ -391,7 +380,7 @@ class PonyfillBody {
|
|
391
380
|
}
|
392
381
|
return readableProp;
|
393
382
|
}
|
394
|
-
}
|
383
|
+
},
|
395
384
|
});
|
396
385
|
}
|
397
386
|
return null;
|
@@ -428,10 +417,10 @@ class PonyfillBody {
|
|
428
417
|
var _a;
|
429
418
|
const bb = busboy({
|
430
419
|
headers: {
|
431
|
-
'content-type': this.contentType || ''
|
420
|
+
'content-type': this.contentType || '',
|
432
421
|
},
|
433
422
|
limits: formDataLimits,
|
434
|
-
defParamCharset: 'utf-8'
|
423
|
+
defParamCharset: 'utf-8',
|
435
424
|
});
|
436
425
|
bb.on('field', (name, value, { nameTruncated, valueTruncated }) => {
|
437
426
|
if (nameTruncated) {
|
@@ -450,7 +439,7 @@ class PonyfillBody {
|
|
450
439
|
fileStream.on('limit', () => {
|
451
440
|
reject(new Error(`File size limit exceeded: ${formDataLimits === null || formDataLimits === void 0 ? void 0 : formDataLimits.fileSize} bytes`));
|
452
441
|
});
|
453
|
-
fileStream.on('data',
|
442
|
+
fileStream.on('data', chunk => {
|
454
443
|
chunks.push(Buffer.from(chunk));
|
455
444
|
});
|
456
445
|
fileStream.on('close', () => {
|
@@ -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