@whatwg-node/node-fetch 0.0.1-alpha-20221225172458-8684a84 → 0.0.1-alpha-20221225175918-b8ec28d
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 +1 -4
- package/Headers.d.ts +2 -0
- package/Request.d.ts +0 -3
- package/index.js +17 -33
- package/index.mjs +17 -33
- package/package.json +1 -1
package/Body.d.ts
CHANGED
@@ -7,14 +7,11 @@ export type BodyPonyfillInit = XMLHttpRequestBodyInit | Readable | PonyfillReada
|
|
7
7
|
export declare class PonyfillBody implements Body {
|
8
8
|
private bodyInit;
|
9
9
|
bodyUsed: boolean;
|
10
|
+
readonly body: PonyfillReadableStream<Uint8Array> | null;
|
10
11
|
contentType: string | null;
|
11
12
|
contentLength: number | null;
|
12
13
|
constructor(bodyInit: BodyPonyfillInit | null);
|
13
14
|
private bodyType?;
|
14
|
-
private _bodyProcessed;
|
15
|
-
private _processedBody;
|
16
|
-
get body(): PonyfillReadableStream<Uint8Array> | null;
|
17
|
-
private processBody;
|
18
15
|
arrayBuffer(): Promise<ArrayBuffer>;
|
19
16
|
blob(): Promise<PonyfillBlob>;
|
20
17
|
formData(): Promise<PonyfillFormData>;
|
package/Headers.d.ts
CHANGED
@@ -8,4 +8,6 @@ export declare class PonyfillHeaders implements Headers {
|
|
8
8
|
set(name: string, value: string): void;
|
9
9
|
delete(name: string): void;
|
10
10
|
forEach(callback: (value: string, key: string, parent: Headers) => void): void;
|
11
|
+
entries(): IterableIterator<[string, string]>;
|
12
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
11
13
|
}
|
package/Request.d.ts
CHANGED
@@ -6,9 +6,6 @@ export type RequestPonyfillInit = Omit<RequestInit, 'body' | 'headers'> & {
|
|
6
6
|
};
|
7
7
|
export declare class PonyfillRequest extends PonyfillBody implements Request {
|
8
8
|
constructor(input: RequestInfo | URL, options?: RequestPonyfillInit);
|
9
|
-
get body(): import("./ReadableStream").PonyfillReadableStream<Uint8Array> | null;
|
10
|
-
private postProcessedBody;
|
11
|
-
private postProcessBody;
|
12
9
|
cache: RequestCache;
|
13
10
|
credentials: RequestCredentials;
|
14
11
|
destination: RequestDestination;
|
package/index.js
CHANGED
@@ -276,46 +276,36 @@ class PonyfillBody {
|
|
276
276
|
constructor(bodyInit) {
|
277
277
|
this.bodyInit = bodyInit;
|
278
278
|
this.bodyUsed = false;
|
279
|
+
this.body = null;
|
279
280
|
this.contentType = null;
|
280
281
|
this.contentLength = null;
|
281
|
-
this._bodyProcessed = false;
|
282
|
-
this._processedBody = null;
|
283
|
-
}
|
284
|
-
get body() {
|
285
|
-
if (!this._bodyProcessed) {
|
286
|
-
this._processedBody = this.processBody();
|
287
|
-
this._bodyProcessed = true;
|
288
|
-
}
|
289
|
-
return this._processedBody;
|
290
|
-
}
|
291
|
-
processBody() {
|
292
282
|
if (this.bodyInit == null) {
|
293
|
-
|
283
|
+
this.body = null;
|
294
284
|
}
|
295
|
-
if (typeof this.bodyInit === 'string') {
|
285
|
+
else if (typeof this.bodyInit === 'string') {
|
296
286
|
this.bodyType = BodyInitType.String;
|
297
287
|
const buffer = Buffer.from(this.bodyInit);
|
298
288
|
this.contentType = 'text/plain;charset=UTF-8';
|
299
289
|
this.contentLength = buffer.length;
|
300
|
-
|
290
|
+
this.body = new PonyfillReadableStream(stream.Readable.from(buffer));
|
301
291
|
}
|
302
292
|
else if (this.bodyInit instanceof PonyfillReadableStream) {
|
303
293
|
this.bodyType = BodyInitType.ReadableStream;
|
304
|
-
|
294
|
+
this.body = this.bodyInit;
|
305
295
|
}
|
306
296
|
else if (this.bodyInit instanceof PonyfillBlob) {
|
307
297
|
this.bodyType = BodyInitType.Blob;
|
308
298
|
const blobStream = this.bodyInit.stream();
|
309
299
|
this.contentType = this.bodyInit.type;
|
310
300
|
this.contentLength = this.bodyInit.size;
|
311
|
-
|
301
|
+
this.body = new PonyfillReadableStream(blobStream);
|
312
302
|
}
|
313
303
|
else if (this.bodyInit instanceof PonyfillFormData) {
|
314
304
|
this.bodyType = BodyInitType.FormData;
|
315
305
|
const boundary = Math.random().toString(36).substr(2);
|
316
306
|
const formData = this.bodyInit;
|
317
307
|
this.contentType = `multipart/form-data; boundary=${boundary}`;
|
318
|
-
|
308
|
+
this.body = new PonyfillReadableStream({
|
319
309
|
start: async (controller) => {
|
320
310
|
controller.enqueue(Buffer.from(`--${boundary}\r\n`));
|
321
311
|
const entries = [];
|
@@ -350,16 +340,16 @@ class PonyfillBody {
|
|
350
340
|
}
|
351
341
|
else if ('buffer' in this.bodyInit) {
|
352
342
|
this.contentLength = this.bodyInit.byteLength;
|
353
|
-
|
343
|
+
this.body = new PonyfillReadableStream(stream.Readable.from(this.bodyInit));
|
354
344
|
}
|
355
345
|
else if (this.bodyInit instanceof ArrayBuffer) {
|
356
346
|
this.bodyType = BodyInitType.ArrayBuffer;
|
357
347
|
this.contentLength = this.bodyInit.byteLength;
|
358
|
-
|
348
|
+
this.body = new PonyfillReadableStream(stream.Readable.from(Buffer.from(this.bodyInit)));
|
359
349
|
}
|
360
350
|
else if (this.bodyInit instanceof stream.Readable) {
|
361
351
|
this.bodyType = BodyInitType.Readable;
|
362
|
-
|
352
|
+
this.body = new PonyfillReadableStream(this.bodyInit);
|
363
353
|
}
|
364
354
|
else {
|
365
355
|
throw new Error('Unknown body type');
|
@@ -453,9 +443,7 @@ class PonyfillHeaders {
|
|
453
443
|
if (this.map.has(key)) {
|
454
444
|
value = this.map.get(key) + ', ' + value;
|
455
445
|
}
|
456
|
-
|
457
|
-
this.map.set(key, value);
|
458
|
-
}
|
446
|
+
this.map.set(key, value);
|
459
447
|
}
|
460
448
|
get(name) {
|
461
449
|
const key = name.toLowerCase();
|
@@ -478,6 +466,12 @@ class PonyfillHeaders {
|
|
478
466
|
callback(value, key, this);
|
479
467
|
});
|
480
468
|
}
|
469
|
+
entries() {
|
470
|
+
return this.map.entries();
|
471
|
+
}
|
472
|
+
[Symbol.iterator]() {
|
473
|
+
return this.map.entries();
|
474
|
+
}
|
481
475
|
}
|
482
476
|
|
483
477
|
function isRequest(input) {
|
@@ -504,7 +498,6 @@ class PonyfillRequest extends PonyfillBody {
|
|
504
498
|
requestInit = options;
|
505
499
|
}
|
506
500
|
super(bodyInit);
|
507
|
-
this.postProcessedBody = false;
|
508
501
|
this.destination = '';
|
509
502
|
this.priority = 'auto';
|
510
503
|
this.cache = (requestInit === null || requestInit === void 0 ? void 0 : requestInit.cache) || 'default';
|
@@ -524,15 +517,6 @@ class PonyfillRequest extends PonyfillBody {
|
|
524
517
|
this.headers.set('connection', 'keep-alive');
|
525
518
|
}
|
526
519
|
}
|
527
|
-
}
|
528
|
-
get body() {
|
529
|
-
const actualBody = super.body;
|
530
|
-
if (!this.postProcessedBody) {
|
531
|
-
this.postProcessBody();
|
532
|
-
}
|
533
|
-
return actualBody;
|
534
|
-
}
|
535
|
-
postProcessBody() {
|
536
520
|
if (!this.headers.has('content-type')) {
|
537
521
|
if (this.contentType) {
|
538
522
|
this.headers.set('content-type', this.contentType);
|
package/index.mjs
CHANGED
@@ -272,46 +272,36 @@ class PonyfillBody {
|
|
272
272
|
constructor(bodyInit) {
|
273
273
|
this.bodyInit = bodyInit;
|
274
274
|
this.bodyUsed = false;
|
275
|
+
this.body = null;
|
275
276
|
this.contentType = null;
|
276
277
|
this.contentLength = null;
|
277
|
-
this._bodyProcessed = false;
|
278
|
-
this._processedBody = null;
|
279
|
-
}
|
280
|
-
get body() {
|
281
|
-
if (!this._bodyProcessed) {
|
282
|
-
this._processedBody = this.processBody();
|
283
|
-
this._bodyProcessed = true;
|
284
|
-
}
|
285
|
-
return this._processedBody;
|
286
|
-
}
|
287
|
-
processBody() {
|
288
278
|
if (this.bodyInit == null) {
|
289
|
-
|
279
|
+
this.body = null;
|
290
280
|
}
|
291
|
-
if (typeof this.bodyInit === 'string') {
|
281
|
+
else if (typeof this.bodyInit === 'string') {
|
292
282
|
this.bodyType = BodyInitType.String;
|
293
283
|
const buffer = Buffer.from(this.bodyInit);
|
294
284
|
this.contentType = 'text/plain;charset=UTF-8';
|
295
285
|
this.contentLength = buffer.length;
|
296
|
-
|
286
|
+
this.body = new PonyfillReadableStream(Readable.from(buffer));
|
297
287
|
}
|
298
288
|
else if (this.bodyInit instanceof PonyfillReadableStream) {
|
299
289
|
this.bodyType = BodyInitType.ReadableStream;
|
300
|
-
|
290
|
+
this.body = this.bodyInit;
|
301
291
|
}
|
302
292
|
else if (this.bodyInit instanceof PonyfillBlob) {
|
303
293
|
this.bodyType = BodyInitType.Blob;
|
304
294
|
const blobStream = this.bodyInit.stream();
|
305
295
|
this.contentType = this.bodyInit.type;
|
306
296
|
this.contentLength = this.bodyInit.size;
|
307
|
-
|
297
|
+
this.body = new PonyfillReadableStream(blobStream);
|
308
298
|
}
|
309
299
|
else if (this.bodyInit instanceof PonyfillFormData) {
|
310
300
|
this.bodyType = BodyInitType.FormData;
|
311
301
|
const boundary = Math.random().toString(36).substr(2);
|
312
302
|
const formData = this.bodyInit;
|
313
303
|
this.contentType = `multipart/form-data; boundary=${boundary}`;
|
314
|
-
|
304
|
+
this.body = new PonyfillReadableStream({
|
315
305
|
start: async (controller) => {
|
316
306
|
controller.enqueue(Buffer.from(`--${boundary}\r\n`));
|
317
307
|
const entries = [];
|
@@ -346,16 +336,16 @@ class PonyfillBody {
|
|
346
336
|
}
|
347
337
|
else if ('buffer' in this.bodyInit) {
|
348
338
|
this.contentLength = this.bodyInit.byteLength;
|
349
|
-
|
339
|
+
this.body = new PonyfillReadableStream(Readable.from(this.bodyInit));
|
350
340
|
}
|
351
341
|
else if (this.bodyInit instanceof ArrayBuffer) {
|
352
342
|
this.bodyType = BodyInitType.ArrayBuffer;
|
353
343
|
this.contentLength = this.bodyInit.byteLength;
|
354
|
-
|
344
|
+
this.body = new PonyfillReadableStream(Readable.from(Buffer.from(this.bodyInit)));
|
355
345
|
}
|
356
346
|
else if (this.bodyInit instanceof Readable) {
|
357
347
|
this.bodyType = BodyInitType.Readable;
|
358
|
-
|
348
|
+
this.body = new PonyfillReadableStream(this.bodyInit);
|
359
349
|
}
|
360
350
|
else {
|
361
351
|
throw new Error('Unknown body type');
|
@@ -449,9 +439,7 @@ class PonyfillHeaders {
|
|
449
439
|
if (this.map.has(key)) {
|
450
440
|
value = this.map.get(key) + ', ' + value;
|
451
441
|
}
|
452
|
-
|
453
|
-
this.map.set(key, value);
|
454
|
-
}
|
442
|
+
this.map.set(key, value);
|
455
443
|
}
|
456
444
|
get(name) {
|
457
445
|
const key = name.toLowerCase();
|
@@ -474,6 +462,12 @@ class PonyfillHeaders {
|
|
474
462
|
callback(value, key, this);
|
475
463
|
});
|
476
464
|
}
|
465
|
+
entries() {
|
466
|
+
return this.map.entries();
|
467
|
+
}
|
468
|
+
[Symbol.iterator]() {
|
469
|
+
return this.map.entries();
|
470
|
+
}
|
477
471
|
}
|
478
472
|
|
479
473
|
function isRequest(input) {
|
@@ -500,7 +494,6 @@ class PonyfillRequest extends PonyfillBody {
|
|
500
494
|
requestInit = options;
|
501
495
|
}
|
502
496
|
super(bodyInit);
|
503
|
-
this.postProcessedBody = false;
|
504
497
|
this.destination = '';
|
505
498
|
this.priority = 'auto';
|
506
499
|
this.cache = (requestInit === null || requestInit === void 0 ? void 0 : requestInit.cache) || 'default';
|
@@ -520,15 +513,6 @@ class PonyfillRequest extends PonyfillBody {
|
|
520
513
|
this.headers.set('connection', 'keep-alive');
|
521
514
|
}
|
522
515
|
}
|
523
|
-
}
|
524
|
-
get body() {
|
525
|
-
const actualBody = super.body;
|
526
|
-
if (!this.postProcessedBody) {
|
527
|
-
this.postProcessBody();
|
528
|
-
}
|
529
|
-
return actualBody;
|
530
|
-
}
|
531
|
-
postProcessBody() {
|
532
516
|
if (!this.headers.has('content-type')) {
|
533
517
|
if (this.contentType) {
|
534
518
|
this.headers.set('content-type', this.contentType);
|
package/package.json
CHANGED