@whatwg-node/node-fetch 0.0.1-alpha-20230102102521-2e7c4e5 → 0.0.1-alpha-20230117081522-969e299

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
@@ -16,7 +16,7 @@ export interface FormDataLimits {
16
16
  export interface PonyfillBodyOptions {
17
17
  formDataLimits?: FormDataLimits;
18
18
  }
19
- export declare class PonyfillBody implements Body {
19
+ export declare class PonyfillBody<TJSON = any> implements Body {
20
20
  private bodyInit;
21
21
  private options;
22
22
  bodyUsed: boolean;
@@ -31,6 +31,6 @@ export declare class PonyfillBody implements Body {
31
31
  formData(opts?: {
32
32
  formDataLimits: FormDataLimits;
33
33
  }): Promise<PonyfillFormData>;
34
- json(): Promise<any>;
34
+ json(): Promise<TJSON>;
35
35
  text(): Promise<string>;
36
36
  }
package/Request.d.ts CHANGED
@@ -4,7 +4,7 @@ export type RequestPonyfillInit = PonyfillBodyOptions & Omit<RequestInit, 'body'
4
4
  body?: BodyPonyfillInit | null;
5
5
  headers?: PonyfillHeadersInit;
6
6
  };
7
- export declare class PonyfillRequest extends PonyfillBody implements Request {
7
+ export declare class PonyfillRequest<TJSON = any> extends PonyfillBody<TJSON> implements Request {
8
8
  constructor(input: RequestInfo | URL, options?: RequestPonyfillInit);
9
9
  cache: RequestCache;
10
10
  credentials: RequestCredentials;
package/Response.d.ts CHANGED
@@ -4,8 +4,9 @@ export type ResponsePonyfilInit = PonyfillBodyOptions & Omit<ResponseInit, 'head
4
4
  url?: string;
5
5
  redirected?: boolean;
6
6
  headers?: PonyfillHeadersInit;
7
+ type?: ResponseType;
7
8
  };
8
- export declare class PonyfillResponse extends PonyfillBody implements Response {
9
+ export declare class PonyfillResponse<TJSON = any> extends PonyfillBody<TJSON> implements Response {
9
10
  constructor(body?: BodyPonyfillInit | null, init?: ResponsePonyfilInit);
10
11
  headers: Headers;
11
12
  get ok(): boolean;
@@ -14,8 +15,8 @@ export declare class PonyfillResponse extends PonyfillBody implements Response {
14
15
  url: string;
15
16
  redirected: boolean;
16
17
  type: ResponseType;
17
- clone(): PonyfillResponse;
18
- static error(): PonyfillResponse;
19
- static redirect(url: string, status?: number): PonyfillResponse;
20
- static json(data: any, init?: RequestInit): PonyfillResponse;
18
+ clone(): PonyfillResponse<any>;
19
+ static error(): PonyfillResponse<any>;
20
+ static redirect(url: string, status?: number): PonyfillResponse<any>;
21
+ static json<T = any>(data: T, init?: RequestInit): PonyfillResponse<T>;
21
22
  }
package/fetch.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import { PonyfillRequest, RequestPonyfillInit } from './Request';
2
2
  import { PonyfillResponse } from './Response';
3
- export declare const fetchPonyfill: (info: string | PonyfillRequest | URL, init?: RequestPonyfillInit) => Promise<PonyfillResponse>;
3
+ export declare function fetchPonyfill<TResponseJSON = any, TRequestJSON = any>(info: string | PonyfillRequest<TRequestJSON> | URL, init?: RequestPonyfillInit): Promise<PonyfillResponse<TResponseJSON>>;
package/index.js CHANGED
@@ -10,6 +10,7 @@ const events = require('@whatwg-node/events');
10
10
  const buffer = require('buffer');
11
11
  const stream = require('stream');
12
12
  const busboy = _interopDefault(require('busboy'));
13
+ const headerCase = require('header-case');
13
14
  const url = require('url');
14
15
  const fs = require('fs');
15
16
 
@@ -580,26 +581,26 @@ class PonyfillHeaders {
580
581
  }
581
582
  }
582
583
  append(name, value) {
583
- const key = name.toLowerCase();
584
+ const key = headerCase.headerCase(name);
584
585
  if (this.map.has(key)) {
585
586
  value = this.map.get(key) + ', ' + value;
586
587
  }
587
588
  this.map.set(key, value);
588
589
  }
589
590
  get(name) {
590
- const key = name.toLowerCase();
591
+ const key = headerCase.headerCase(name);
591
592
  return this.map.get(key) || null;
592
593
  }
593
594
  has(name) {
594
- const key = name.toLowerCase();
595
+ const key = headerCase.headerCase(name);
595
596
  return this.map.has(key);
596
597
  }
597
598
  set(name, value) {
598
- const key = name.toLowerCase();
599
+ const key = headerCase.headerCase(name);
599
600
  this.map.set(key, value);
600
601
  }
601
602
  delete(name) {
602
- const key = name.toLowerCase();
603
+ const key = headerCase.headerCase(name);
603
604
  this.map.delete(key);
604
605
  }
605
606
  forEach(callback) {
@@ -697,6 +698,7 @@ class PonyfillResponse extends PonyfillBody {
697
698
  this.statusText = init.statusText || 'OK';
698
699
  this.url = init.url || '';
699
700
  this.redirected = init.redirected || false;
701
+ this.type = init.type || 'default';
700
702
  }
701
703
  }
702
704
  get ok() {
@@ -706,11 +708,10 @@ class PonyfillResponse extends PonyfillBody {
706
708
  return new PonyfillResponse(this.body, this);
707
709
  }
708
710
  static error() {
709
- const response = new PonyfillResponse(null, {
711
+ return new PonyfillResponse(null, {
710
712
  status: 500,
711
713
  statusText: 'Internal Server Error',
712
714
  });
713
- return response;
714
715
  }
715
716
  static redirect(url, status = 301) {
716
717
  if (status < 300 || status > 399) {
@@ -759,7 +760,7 @@ function getRequestFnForProtocol(protocol) {
759
760
  }
760
761
  throw new Error(`Unsupported protocol: ${protocol}`);
761
762
  }
762
- const fetchPonyfill = (info, init) => {
763
+ function fetchPonyfill(info, init) {
763
764
  if (typeof info === 'string' || info instanceof URL) {
764
765
  const ponyfillRequest = new PonyfillRequest(info, init);
765
766
  return fetchPonyfill(ponyfillRequest);
@@ -830,7 +831,7 @@ const fetchPonyfill = (info, init) => {
830
831
  reject(e);
831
832
  }
832
833
  });
833
- };
834
+ }
834
835
 
835
836
  class PonyfillTextEncoder {
836
837
  constructor(encoding = 'utf-8') {
package/index.mjs CHANGED
@@ -4,6 +4,7 @@ import { EventTarget, CustomEvent } from '@whatwg-node/events';
4
4
  import { Blob } from 'buffer';
5
5
  import { Readable } from 'stream';
6
6
  import busboy from 'busboy';
7
+ import { headerCase } from 'header-case';
7
8
  import { fileURLToPath } from 'url';
8
9
  import { createReadStream } from 'fs';
9
10
 
@@ -574,26 +575,26 @@ class PonyfillHeaders {
574
575
  }
575
576
  }
576
577
  append(name, value) {
577
- const key = name.toLowerCase();
578
+ const key = headerCase(name);
578
579
  if (this.map.has(key)) {
579
580
  value = this.map.get(key) + ', ' + value;
580
581
  }
581
582
  this.map.set(key, value);
582
583
  }
583
584
  get(name) {
584
- const key = name.toLowerCase();
585
+ const key = headerCase(name);
585
586
  return this.map.get(key) || null;
586
587
  }
587
588
  has(name) {
588
- const key = name.toLowerCase();
589
+ const key = headerCase(name);
589
590
  return this.map.has(key);
590
591
  }
591
592
  set(name, value) {
592
- const key = name.toLowerCase();
593
+ const key = headerCase(name);
593
594
  this.map.set(key, value);
594
595
  }
595
596
  delete(name) {
596
- const key = name.toLowerCase();
597
+ const key = headerCase(name);
597
598
  this.map.delete(key);
598
599
  }
599
600
  forEach(callback) {
@@ -691,6 +692,7 @@ class PonyfillResponse extends PonyfillBody {
691
692
  this.statusText = init.statusText || 'OK';
692
693
  this.url = init.url || '';
693
694
  this.redirected = init.redirected || false;
695
+ this.type = init.type || 'default';
694
696
  }
695
697
  }
696
698
  get ok() {
@@ -700,11 +702,10 @@ class PonyfillResponse extends PonyfillBody {
700
702
  return new PonyfillResponse(this.body, this);
701
703
  }
702
704
  static error() {
703
- const response = new PonyfillResponse(null, {
705
+ return new PonyfillResponse(null, {
704
706
  status: 500,
705
707
  statusText: 'Internal Server Error',
706
708
  });
707
- return response;
708
709
  }
709
710
  static redirect(url, status = 301) {
710
711
  if (status < 300 || status > 399) {
@@ -753,7 +754,7 @@ function getRequestFnForProtocol(protocol) {
753
754
  }
754
755
  throw new Error(`Unsupported protocol: ${protocol}`);
755
756
  }
756
- const fetchPonyfill = (info, init) => {
757
+ function fetchPonyfill(info, init) {
757
758
  if (typeof info === 'string' || info instanceof URL) {
758
759
  const ponyfillRequest = new PonyfillRequest(info, init);
759
760
  return fetchPonyfill(ponyfillRequest);
@@ -824,7 +825,7 @@ const fetchPonyfill = (info, init) => {
824
825
  reject(e);
825
826
  }
826
827
  });
827
- };
828
+ }
828
829
 
829
830
  class PonyfillTextEncoder {
830
831
  constructor(encoding = 'utf-8') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whatwg-node/node-fetch",
3
- "version": "0.0.1-alpha-20230102102521-2e7c4e5",
3
+ "version": "0.0.1-alpha-20230117081522-969e299",
4
4
  "description": "Fetch API implementation for Node",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -9,6 +9,7 @@
9
9
  "dependencies": {
10
10
  "@whatwg-node/events": "0.0.2",
11
11
  "busboy": "1.6.0",
12
+ "header-case": "^2.0.4",
12
13
  "tslib": "^2.3.1"
13
14
  },
14
15
  "repository": {