fetch.js.flow 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* @flow strict */
  2. type CredentialsType = 'omit' | 'same-origin' | 'include'
  3. type ResponseType = 'default' | 'error'
  4. type BodyInit = string | URLSearchParams | FormData | Blob | ArrayBuffer | $ArrayBufferView
  5. type RequestInfo = Request | URL | string
  6. type RequestOptions = {|
  7. body?: ?BodyInit;
  8. credentials?: CredentialsType;
  9. headers?: HeadersInit;
  10. method?: string;
  11. mode?: string;
  12. referrer?: string;
  13. signal?: ?AbortSignal;
  14. |}
  15. type ResponseOptions = {|
  16. status?: number;
  17. statusText?: string;
  18. headers?: HeadersInit;
  19. |}
  20. type HeadersInit = Headers | {[string]: string}
  21. // https://github.com/facebook/flow/blob/f68b89a5012bd995ab3509e7a41b7325045c4045/lib/bom.js#L902-L914
  22. declare class Headers {
  23. @@iterator(): Iterator<[string, string]>;
  24. constructor(init?: HeadersInit): void;
  25. append(name: string, value: string): void;
  26. delete(name: string): void;
  27. entries(): Iterator<[string, string]>;
  28. forEach((value: string, name: string, headers: Headers) => any, thisArg?: any): void;
  29. get(name: string): null | string;
  30. has(name: string): boolean;
  31. keys(): Iterator<string>;
  32. set(name: string, value: string): void;
  33. values(): Iterator<string>;
  34. }
  35. // https://github.com/facebook/flow/pull/6548
  36. interface AbortSignal {
  37. aborted: boolean;
  38. addEventListener(type: string, listener: (Event) => mixed, options?: EventListenerOptionsOrUseCapture): void;
  39. removeEventListener(type: string, listener: (Event) => mixed, options?: EventListenerOptionsOrUseCapture): void;
  40. }
  41. // https://github.com/facebook/flow/blob/f68b89a5012bd995ab3509e7a41b7325045c4045/lib/bom.js#L994-L1018
  42. // unsupported in polyfill:
  43. // - cache
  44. // - integrity
  45. // - redirect
  46. // - referrerPolicy
  47. declare class Request {
  48. constructor(input: RequestInfo, init?: RequestOptions): void;
  49. clone(): Request;
  50. url: string;
  51. credentials: CredentialsType;
  52. headers: Headers;
  53. method: string;
  54. mode: ModeType;
  55. referrer: string;
  56. signal: ?AbortSignal;
  57. // Body methods and attributes
  58. bodyUsed: boolean;
  59. arrayBuffer(): Promise<ArrayBuffer>;
  60. blob(): Promise<Blob>;
  61. formData(): Promise<FormData>;
  62. json(): Promise<any>;
  63. text(): Promise<string>;
  64. }
  65. // https://github.com/facebook/flow/blob/f68b89a5012bd995ab3509e7a41b7325045c4045/lib/bom.js#L968-L992
  66. // unsupported in polyfill:
  67. // - body
  68. // - redirected
  69. // - trailer
  70. declare class Response {
  71. constructor(input?: ?BodyInit, init?: ResponseOptions): void;
  72. clone(): Response;
  73. static error(): Response;
  74. static redirect(url: string, status?: number): Response;
  75. type: ResponseType;
  76. url: string;
  77. ok: boolean;
  78. status: number;
  79. statusText: string;
  80. headers: Headers;
  81. // Body methods and attributes
  82. bodyUsed: boolean;
  83. arrayBuffer(): Promise<ArrayBuffer>;
  84. blob(): Promise<Blob>;
  85. formData(): Promise<FormData>;
  86. json(): Promise<any>;
  87. text(): Promise<string>;
  88. }
  89. declare class DOMException extends Error {
  90. constructor(message?: string, name?: string): void;
  91. }
  92. declare module.exports: {
  93. fetch(input: RequestInfo, init?: RequestOptions): Promise<Response>;
  94. Headers: typeof Headers;
  95. Request: typeof Request;
  96. Response: typeof Response;
  97. DOMException: typeof DOMException;
  98. }