bun-types 1.2.5-canary.20250302T140537 → 1.2.5-canary.20250304T140606

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/fetch.d.ts CHANGED
@@ -1,14 +1,59 @@
1
- type _Response = typeof globalThis extends { onmessage: any }
2
- ? {}
3
- : import("undici-types").Response;
1
+ interface Headers {
2
+ /**
3
+ * Convert {@link Headers} to a plain JavaScript object.
4
+ *
5
+ * About 10x faster than `Object.fromEntries(headers.entries())`
6
+ *
7
+ * Called when you run `JSON.stringify(headers)`
8
+ *
9
+ * Does not preserve insertion order. Well-known header names are lowercased. Other header names are left as-is.
10
+ */
11
+ toJSON(): Record<string, string>;
12
+ /**
13
+ * Get the total number of headers
14
+ */
15
+ readonly count: number;
16
+ /**
17
+ * Get all headers matching the name
18
+ *
19
+ * Only supports `"Set-Cookie"`. All other headers are empty arrays.
20
+ *
21
+ * @param name - The header name to get
22
+ *
23
+ * @returns An array of header values
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const headers = new Headers();
28
+ * headers.append("Set-Cookie", "foo=bar");
29
+ * headers.append("Set-Cookie", "baz=qux");
30
+ * headers.getAll("Set-Cookie"); // ["foo=bar", "baz=qux"]
31
+ * ```
32
+ */
33
+ getAll(name: "set-cookie" | "Set-Cookie"): string[];
34
+ }
35
+
36
+ var Headers: {
37
+ prototype: Headers;
38
+ new (init?: Bun.HeadersInit): Headers;
39
+ };
4
40
 
5
- export interface Response extends _Response {}
6
- export declare class Response {
7
- constructor(
41
+ interface Request {
42
+ headers: Headers;
43
+ }
44
+
45
+ var Request: {
46
+ prototype: Request;
47
+ new (requestInfo: string, requestInit?: RequestInit): Request;
48
+ new (requestInfo: RequestInit & { url: string }): Request;
49
+ new (requestInfo: Request, requestInit?: RequestInit): Request;
50
+ };
51
+
52
+ var Response: {
53
+ new (
8
54
  body?: Bun.BodyInit | null | undefined,
9
55
  init?: Bun.ResponseInit | undefined,
10
- );
11
-
56
+ ): Response;
12
57
  /**
13
58
  * Create a new {@link Response} with a JSON body
14
59
  *
@@ -32,7 +77,8 @@ export declare class Response {
32
77
  * ```
33
78
  * @link https://github.com/whatwg/fetch/issues/1389
34
79
  */
35
- static json(body?: any, options?: Bun.ResponseInit | number): Response;
80
+ json(body?: any, options?: Bun.ResponseInit | number): Response;
81
+
36
82
  /**
37
83
  * Create a new {@link Response} that redirects to url
38
84
  *
@@ -40,7 +86,7 @@ export declare class Response {
40
86
  * @param status - the HTTP status code to use for the redirect
41
87
  */
42
88
  // tslint:disable-next-line:unified-signatures
43
- static redirect(url: string, status?: number): Response;
89
+ redirect(url: string, status?: number): Response;
44
90
 
45
91
  /**
46
92
  * Create a new {@link Response} that redirects to url
@@ -49,10 +95,75 @@ export declare class Response {
49
95
  * @param options - options to pass to the response
50
96
  */
51
97
  // tslint:disable-next-line:unified-signatures
52
- static redirect(url: string, options?: Bun.ResponseInit): Response;
98
+ redirect(url: string, options?: Bun.ResponseInit): Response;
53
99
 
54
100
  /**
55
101
  * Create a new {@link Response} that has a network error
56
102
  */
57
- static error(): Response;
103
+ error(): Response;
104
+ };
105
+
106
+ type _BunTLSOptions = import("bun").TLSOptions;
107
+ interface BunFetchRequestInitTLS extends _BunTLSOptions {
108
+ /**
109
+ * Custom function to check the server identity
110
+ * @param hostname - The hostname of the server
111
+ * @param cert - The certificate of the server
112
+ * @returns An error if the server is unauthorized, otherwise undefined
113
+ */
114
+ checkServerIdentity?: NonNullable<
115
+ import("node:tls").ConnectionOptions["checkServerIdentity"]
116
+ >;
117
+ }
118
+
119
+ /**
120
+ * BunFetchRequestInit represents additional options that Bun supports in `fetch()` only.
121
+ *
122
+ * Bun extends the `fetch` API with some additional options, except
123
+ * this interface is not quite a `RequestInit`, because they won't work
124
+ * if passed to `new Request()`. This is why it's a separate type.
125
+ */
126
+ interface BunFetchRequestInit extends RequestInit {
127
+ /**
128
+ * Override the default TLS options
129
+ */
130
+ tls?: BunFetchRequestInitTLS;
58
131
  }
132
+
133
+ var fetch: {
134
+ /**
135
+ * Send a HTTP(s) request
136
+ *
137
+ * @param request Request object
138
+ * @param init A structured value that contains settings for the fetch() request.
139
+ *
140
+ * @returns A promise that resolves to {@link Response} object.
141
+ */
142
+ (request: Request, init?: BunFetchRequestInit): Promise<Response>;
143
+
144
+ /**
145
+ * Send a HTTP(s) request
146
+ *
147
+ * @param url URL string
148
+ * @param init A structured value that contains settings for the fetch() request.
149
+ *
150
+ * @returns A promise that resolves to {@link Response} object.
151
+ */
152
+ (url: string | URL | Request, init?: BunFetchRequestInit): Promise<Response>;
153
+
154
+ (
155
+ input: string | URL | globalThis.Request,
156
+ init?: BunFetchRequestInit,
157
+ ): Promise<Response>;
158
+
159
+ /**
160
+ * Start the DNS resolution, TCP connection, and TLS handshake for a request
161
+ * before the request is actually sent.
162
+ *
163
+ * This can reduce the latency of a request when you know there's some
164
+ * long-running task that will delay the request starting.
165
+ *
166
+ * This is a bun-specific API and is not part of the Fetch API specification.
167
+ */
168
+ preconnect(url: string | URL): void;
169
+ };