bun-types 0.8.0 → 0.8.1
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/package.json +1 -1
- package/tsconfig.json +1 -1
- package/types.d.ts +166 -37
package/package.json
CHANGED
package/tsconfig.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Type definitions for bun 0.8.
|
|
1
|
+
// Type definitions for bun 0.8.1
|
|
2
2
|
// Project: https://github.com/oven-sh/bun
|
|
3
3
|
// Definitions by: Jarred Sumner <https://github.com/Jarred-Sumner>
|
|
4
4
|
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
@@ -5051,7 +5051,7 @@ interface BlobInterface {
|
|
|
5051
5051
|
type BlobPart = string | Blob | BufferSource;
|
|
5052
5052
|
interface BlobPropertyBag {
|
|
5053
5053
|
/** Set a default "type". Not yet implemented. */
|
|
5054
|
-
|
|
5054
|
+
type?: string;
|
|
5055
5055
|
/** Not implemented in Bun yet. */
|
|
5056
5056
|
// endings?: "transparent" | "native";
|
|
5057
5057
|
}
|
|
@@ -9061,8 +9061,12 @@ declare module "bun" {
|
|
|
9061
9061
|
export type Serve<WebSocketDataType = undefined> =
|
|
9062
9062
|
| ServeOptions
|
|
9063
9063
|
| TLSServeOptions
|
|
9064
|
+
| UnixServeOptions
|
|
9065
|
+
| UnixTLSServeOptions
|
|
9064
9066
|
| WebSocketServeOptions<WebSocketDataType>
|
|
9065
|
-
| TLSWebSocketServeOptions<WebSocketDataType
|
|
9067
|
+
| TLSWebSocketServeOptions<WebSocketDataType>
|
|
9068
|
+
| UnixWebSocketServeOptions<WebSocketDataType>
|
|
9069
|
+
| UnixTLSWebSocketServeOptions<WebSocketDataType>;
|
|
9066
9070
|
|
|
9067
9071
|
/**
|
|
9068
9072
|
* Start a fast HTTP server.
|
|
@@ -9100,13 +9104,7 @@ declare module "bun" {
|
|
|
9100
9104
|
* });
|
|
9101
9105
|
* ```
|
|
9102
9106
|
*/
|
|
9103
|
-
export function serve<T>(
|
|
9104
|
-
options:
|
|
9105
|
-
| ServeOptions
|
|
9106
|
-
| TLSServeOptions
|
|
9107
|
-
| WebSocketServeOptions<T>
|
|
9108
|
-
| TLSWebSocketServeOptions<T>,
|
|
9109
|
-
): Server;
|
|
9107
|
+
export function serve<T>(options: Serve<T>): Server;
|
|
9110
9108
|
|
|
9111
9109
|
/**
|
|
9112
9110
|
* Synchronously resolve a `moduleId` as though it were imported from `parent`
|
|
@@ -10772,32 +10770,7 @@ declare module "bun" {
|
|
|
10772
10770
|
|
|
10773
10771
|
interface GenericServeOptions {
|
|
10774
10772
|
/**
|
|
10775
|
-
* What port should the server listen on?
|
|
10776
|
-
* @default process.env.PORT || "3000"
|
|
10777
|
-
*/
|
|
10778
|
-
port?: string | number;
|
|
10779
|
-
|
|
10780
|
-
/**
|
|
10781
|
-
* What hostname should the server listen on?
|
|
10782
|
-
*
|
|
10783
|
-
* @default
|
|
10784
|
-
* ```js
|
|
10785
|
-
* "0.0.0.0" // listen on all interfaces
|
|
10786
|
-
* ```
|
|
10787
|
-
* @example
|
|
10788
|
-
* ```js
|
|
10789
|
-
* "127.0.0.1" // Only listen locally
|
|
10790
|
-
* ```
|
|
10791
|
-
* @example
|
|
10792
|
-
* ```js
|
|
10793
|
-
* "remix.run" // Only listen on remix.run
|
|
10794
|
-
* ````
|
|
10795
10773
|
*
|
|
10796
|
-
* note: hostname should not include a {@link port}
|
|
10797
|
-
*/
|
|
10798
|
-
hostname?: string;
|
|
10799
|
-
|
|
10800
|
-
/**
|
|
10801
10774
|
* What URI should be used to make {@link Request.url} absolute?
|
|
10802
10775
|
*
|
|
10803
10776
|
* By default, looks at {@link hostname}, {@link port}, and whether or not SSL is enabled to generate one
|
|
@@ -10816,7 +10789,6 @@ declare module "bun" {
|
|
|
10816
10789
|
*
|
|
10817
10790
|
* @example
|
|
10818
10791
|
* "http://localhost:3000"
|
|
10819
|
-
*
|
|
10820
10792
|
*/
|
|
10821
10793
|
// baseURI?: string;
|
|
10822
10794
|
|
|
@@ -10840,6 +10812,38 @@ declare module "bun" {
|
|
|
10840
10812
|
|
|
10841
10813
|
export type AnyFunction = (..._: any[]) => any;
|
|
10842
10814
|
export interface ServeOptions extends GenericServeOptions {
|
|
10815
|
+
/**
|
|
10816
|
+
* What port should the server listen on?
|
|
10817
|
+
* @default process.env.PORT || "3000"
|
|
10818
|
+
*/
|
|
10819
|
+
port?: string | number;
|
|
10820
|
+
|
|
10821
|
+
/**
|
|
10822
|
+
* What hostname should the server listen on?
|
|
10823
|
+
*
|
|
10824
|
+
* @default
|
|
10825
|
+
* ```js
|
|
10826
|
+
* "0.0.0.0" // listen on all interfaces
|
|
10827
|
+
* ```
|
|
10828
|
+
* @example
|
|
10829
|
+
* ```js
|
|
10830
|
+
* "127.0.0.1" // Only listen locally
|
|
10831
|
+
* ```
|
|
10832
|
+
* @example
|
|
10833
|
+
* ```js
|
|
10834
|
+
* "remix.run" // Only listen on remix.run
|
|
10835
|
+
* ````
|
|
10836
|
+
*
|
|
10837
|
+
* note: hostname should not include a {@link port}
|
|
10838
|
+
*/
|
|
10839
|
+
hostname?: string;
|
|
10840
|
+
|
|
10841
|
+
/**
|
|
10842
|
+
* If set, the HTTP server will listen on a unix socket instead of a port.
|
|
10843
|
+
* (Cannot be used with hostname+port)
|
|
10844
|
+
*/
|
|
10845
|
+
unix?: never;
|
|
10846
|
+
|
|
10843
10847
|
/**
|
|
10844
10848
|
* Handle HTTP requests
|
|
10845
10849
|
*
|
|
@@ -10853,8 +10857,113 @@ declare module "bun" {
|
|
|
10853
10857
|
): Response | Promise<Response>;
|
|
10854
10858
|
}
|
|
10855
10859
|
|
|
10860
|
+
export interface UnixServeOptions extends GenericServeOptions {
|
|
10861
|
+
/**
|
|
10862
|
+
* If set, the HTTP server will listen on a unix socket instead of a port.
|
|
10863
|
+
* (Cannot be used with hostname+port)
|
|
10864
|
+
*/
|
|
10865
|
+
unix: string;
|
|
10866
|
+
/**
|
|
10867
|
+
* Handle HTTP requests
|
|
10868
|
+
*
|
|
10869
|
+
* Respond to {@link Request} objects with a {@link Response} object.
|
|
10870
|
+
*/
|
|
10871
|
+
fetch(
|
|
10872
|
+
this: Server,
|
|
10873
|
+
request: Request,
|
|
10874
|
+
server: Server,
|
|
10875
|
+
): Response | Promise<Response>;
|
|
10876
|
+
}
|
|
10877
|
+
|
|
10856
10878
|
export interface WebSocketServeOptions<WebSocketDataType = undefined>
|
|
10857
10879
|
extends GenericServeOptions {
|
|
10880
|
+
/**
|
|
10881
|
+
* What port should the server listen on?
|
|
10882
|
+
* @default process.env.PORT || "3000"
|
|
10883
|
+
*/
|
|
10884
|
+
port?: string | number;
|
|
10885
|
+
|
|
10886
|
+
/**
|
|
10887
|
+
* What hostname should the server listen on?
|
|
10888
|
+
*
|
|
10889
|
+
* @default
|
|
10890
|
+
* ```js
|
|
10891
|
+
* "0.0.0.0" // listen on all interfaces
|
|
10892
|
+
* ```
|
|
10893
|
+
* @example
|
|
10894
|
+
* ```js
|
|
10895
|
+
* "127.0.0.1" // Only listen locally
|
|
10896
|
+
* ```
|
|
10897
|
+
* @example
|
|
10898
|
+
* ```js
|
|
10899
|
+
* "remix.run" // Only listen on remix.run
|
|
10900
|
+
* ````
|
|
10901
|
+
*
|
|
10902
|
+
* note: hostname should not include a {@link port}
|
|
10903
|
+
*/
|
|
10904
|
+
hostname?: string;
|
|
10905
|
+
|
|
10906
|
+
/**
|
|
10907
|
+
* Enable websockets with {@link Bun.serve}
|
|
10908
|
+
*
|
|
10909
|
+
* For simpler type safety, see {@link Bun.websocket}
|
|
10910
|
+
*
|
|
10911
|
+
* @example
|
|
10912
|
+
* ```js
|
|
10913
|
+
*import { serve } from "bun";
|
|
10914
|
+
*serve({
|
|
10915
|
+
* websocket: {
|
|
10916
|
+
* open: (ws) => {
|
|
10917
|
+
* console.log("Client connected");
|
|
10918
|
+
* },
|
|
10919
|
+
* message: (ws, message) => {
|
|
10920
|
+
* console.log("Client sent message", message);
|
|
10921
|
+
* },
|
|
10922
|
+
* close: (ws) => {
|
|
10923
|
+
* console.log("Client disconnected");
|
|
10924
|
+
* },
|
|
10925
|
+
* },
|
|
10926
|
+
* fetch(req, server) {
|
|
10927
|
+
* const url = new URL(req.url);
|
|
10928
|
+
* if (url.pathname === "/chat") {
|
|
10929
|
+
* const upgraded = server.upgrade(req);
|
|
10930
|
+
* if (!upgraded) {
|
|
10931
|
+
* return new Response("Upgrade failed", { status: 400 });
|
|
10932
|
+
* }
|
|
10933
|
+
* }
|
|
10934
|
+
* return new Response("Hello World");
|
|
10935
|
+
* },
|
|
10936
|
+
*});
|
|
10937
|
+
*```
|
|
10938
|
+
* Upgrade a {@link Request} to a {@link ServerWebSocket} via {@link Server.upgrade}
|
|
10939
|
+
*
|
|
10940
|
+
* Pass `data` in @{link Server.upgrade} to attach data to the {@link ServerWebSocket.data} property
|
|
10941
|
+
*
|
|
10942
|
+
*
|
|
10943
|
+
*/
|
|
10944
|
+
websocket: WebSocketHandler<WebSocketDataType>;
|
|
10945
|
+
|
|
10946
|
+
/**
|
|
10947
|
+
* Handle HTTP requests or upgrade them to a {@link ServerWebSocket}
|
|
10948
|
+
*
|
|
10949
|
+
* Respond to {@link Request} objects with a {@link Response} object.
|
|
10950
|
+
*
|
|
10951
|
+
*/
|
|
10952
|
+
fetch(
|
|
10953
|
+
this: Server,
|
|
10954
|
+
request: Request,
|
|
10955
|
+
server: Server,
|
|
10956
|
+
): Response | undefined | Promise<Response | undefined>;
|
|
10957
|
+
}
|
|
10958
|
+
|
|
10959
|
+
export interface UnixWebSocketServeOptions<WebSocketDataType = undefined>
|
|
10960
|
+
extends GenericServeOptions {
|
|
10961
|
+
/**
|
|
10962
|
+
* If set, the HTTP server will listen on a unix socket instead of a port.
|
|
10963
|
+
* (Cannot be used with hostname+port)
|
|
10964
|
+
*/
|
|
10965
|
+
unix: string;
|
|
10966
|
+
|
|
10858
10967
|
/**
|
|
10859
10968
|
* Enable websockets with {@link Bun.serve}
|
|
10860
10969
|
*
|
|
@@ -10911,6 +11020,17 @@ declare module "bun" {
|
|
|
10911
11020
|
export interface TLSWebSocketServeOptions<WebSocketDataType = undefined>
|
|
10912
11021
|
extends WebSocketServeOptions<WebSocketDataType>,
|
|
10913
11022
|
TLSOptions {
|
|
11023
|
+
unix?: never;
|
|
11024
|
+
tls?: TLSOptions;
|
|
11025
|
+
}
|
|
11026
|
+
export interface UnixTLSWebSocketServeOptions<WebSocketDataType = undefined>
|
|
11027
|
+
extends UnixWebSocketServeOptions<WebSocketDataType>,
|
|
11028
|
+
TLSOptions {
|
|
11029
|
+
/**
|
|
11030
|
+
* If set, the HTTP server will listen on a unix socket instead of a port.
|
|
11031
|
+
* (Cannot be used with hostname+port)
|
|
11032
|
+
*/
|
|
11033
|
+
unix: string;
|
|
10914
11034
|
tls?: TLSOptions;
|
|
10915
11035
|
}
|
|
10916
11036
|
export interface Errorlike extends Error {
|
|
@@ -11027,6 +11147,16 @@ declare module "bun" {
|
|
|
11027
11147
|
tls?: TLSOptions;
|
|
11028
11148
|
}
|
|
11029
11149
|
|
|
11150
|
+
export interface UnixTLSServeOptions extends UnixServeOptions, TLSOptions {
|
|
11151
|
+
/**
|
|
11152
|
+
* The keys are [SNI](https://en.wikipedia.org/wiki/Server_Name_Indication) hostnames.
|
|
11153
|
+
* The values are SSL options objects.
|
|
11154
|
+
*/
|
|
11155
|
+
serverNames?: Record<string, TLSOptions>;
|
|
11156
|
+
|
|
11157
|
+
tls?: TLSOptions;
|
|
11158
|
+
}
|
|
11159
|
+
|
|
11030
11160
|
/**
|
|
11031
11161
|
* HTTP & HTTPS Server
|
|
11032
11162
|
*
|
|
@@ -11037,7 +11167,6 @@ declare module "bun" {
|
|
|
11037
11167
|
* avoid starting and stopping the server often (unless it's a new instance of bun).
|
|
11038
11168
|
*
|
|
11039
11169
|
* Powered by a fork of [uWebSockets](https://github.com/uNetworking/uWebSockets). Thank you @alexhultman.
|
|
11040
|
-
*
|
|
11041
11170
|
*/
|
|
11042
11171
|
export interface Server {
|
|
11043
11172
|
/**
|