@whatwg-node/node-fetch 0.0.1-alpha-20221225173053-f9310f6 → 0.0.1-alpha-20221226141545-8392bc6

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 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
@@ -69,7 +69,7 @@ function createController(desiredSize, readable) {
69
69
  },
70
70
  get enqueued() {
71
71
  return enqueued;
72
- }
72
+ },
73
73
  };
74
74
  }
75
75
  class PonyfillReadableStream {
@@ -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
- return null;
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
- return new PonyfillReadableStream(stream.Readable.from(buffer));
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
- return this.bodyInit;
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
- return new PonyfillReadableStream(blobStream);
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
- return new PonyfillReadableStream({
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
- return new PonyfillReadableStream(stream.Readable.from(this.bodyInit));
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
- return new PonyfillReadableStream(stream.Readable.from(Buffer.from(this.bodyInit)));
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
- return new PonyfillReadableStream(this.bodyInit);
352
+ this.body = new PonyfillReadableStream(this.bodyInit);
363
353
  }
364
354
  else {
365
355
  throw new Error('Unknown body type');
@@ -476,6 +466,12 @@ class PonyfillHeaders {
476
466
  callback(value, key, this);
477
467
  });
478
468
  }
469
+ entries() {
470
+ return this.map.entries();
471
+ }
472
+ [Symbol.iterator]() {
473
+ return this.map.entries();
474
+ }
479
475
  }
480
476
 
481
477
  function isRequest(input) {
@@ -502,7 +498,6 @@ class PonyfillRequest extends PonyfillBody {
502
498
  requestInit = options;
503
499
  }
504
500
  super(bodyInit);
505
- this.postProcessedBody = false;
506
501
  this.destination = '';
507
502
  this.priority = 'auto';
508
503
  this.cache = (requestInit === null || requestInit === void 0 ? void 0 : requestInit.cache) || 'default';
@@ -522,15 +517,6 @@ class PonyfillRequest extends PonyfillBody {
522
517
  this.headers.set('connection', 'keep-alive');
523
518
  }
524
519
  }
525
- }
526
- get body() {
527
- const actualBody = super.body;
528
- if (!this.postProcessedBody) {
529
- this.postProcessBody();
530
- }
531
- return actualBody;
532
- }
533
- postProcessBody() {
534
520
  if (!this.headers.has('content-type')) {
535
521
  if (this.contentType) {
536
522
  this.headers.set('content-type', this.contentType);
package/index.mjs CHANGED
@@ -65,7 +65,7 @@ function createController(desiredSize, readable) {
65
65
  },
66
66
  get enqueued() {
67
67
  return enqueued;
68
- }
68
+ },
69
69
  };
70
70
  }
71
71
  class PonyfillReadableStream {
@@ -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
- return null;
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
- return new PonyfillReadableStream(Readable.from(buffer));
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
- return this.bodyInit;
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
- return new PonyfillReadableStream(blobStream);
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
- return new PonyfillReadableStream({
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
- return new PonyfillReadableStream(Readable.from(this.bodyInit));
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
- return new PonyfillReadableStream(Readable.from(Buffer.from(this.bodyInit)));
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
- return new PonyfillReadableStream(this.bodyInit);
348
+ this.body = new PonyfillReadableStream(this.bodyInit);
359
349
  }
360
350
  else {
361
351
  throw new Error('Unknown body type');
@@ -472,6 +462,12 @@ class PonyfillHeaders {
472
462
  callback(value, key, this);
473
463
  });
474
464
  }
465
+ entries() {
466
+ return this.map.entries();
467
+ }
468
+ [Symbol.iterator]() {
469
+ return this.map.entries();
470
+ }
475
471
  }
476
472
 
477
473
  function isRequest(input) {
@@ -498,7 +494,6 @@ class PonyfillRequest extends PonyfillBody {
498
494
  requestInit = options;
499
495
  }
500
496
  super(bodyInit);
501
- this.postProcessedBody = false;
502
497
  this.destination = '';
503
498
  this.priority = 'auto';
504
499
  this.cache = (requestInit === null || requestInit === void 0 ? void 0 : requestInit.cache) || 'default';
@@ -518,15 +513,6 @@ class PonyfillRequest extends PonyfillBody {
518
513
  this.headers.set('connection', 'keep-alive');
519
514
  }
520
515
  }
521
- }
522
- get body() {
523
- const actualBody = super.body;
524
- if (!this.postProcessedBody) {
525
- this.postProcessBody();
526
- }
527
- return actualBody;
528
- }
529
- postProcessBody() {
530
516
  if (!this.headers.has('content-type')) {
531
517
  if (this.contentType) {
532
518
  this.headers.set('content-type', this.contentType);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.0.1-alpha-20221225173053-f9310f6",
3
+ "version": "0.0.1-alpha-20221226141545-8392bc6",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {