@eslym/sveltekit-adapter-bun 1.0.8 → 1.0.9

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.
Files changed (2) hide show
  1. package/dist/types.d.ts +52 -3
  2. package/package.json +1 -1
package/dist/types.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  /// <reference types="bun-types" />
2
+ /// <reference types="node" />
2
3
  /// <reference types="bun-types" />
3
- import type { WebSocketHandler as BunWSHandler } from 'bun';
4
+ import type { WebSocketHandler as BunWSHandler, ServerWebSocket } from 'bun';
4
5
  import type { Server } from 'bun';
5
6
  export type ServeOptions = {
6
7
  port: number;
@@ -13,7 +14,55 @@ export type ServeOptions = {
13
14
  xffDepth?: number;
14
15
  };
15
16
  export type WebSocketOptions = Omit<BunWSHandler, 'message' | 'open' | 'close' | 'ping' | 'pong' | 'drain'>;
16
- export type WebSocketHandler<T extends WebSocketHandler<any>> = Pick<BunWSHandler<T>, 'message' | 'open' | 'drain' | 'ping' | 'pong' | 'close'>;
17
+ export interface WebSocketHandler {
18
+ /**
19
+ * Called when the server receives an incoming message.
20
+ *
21
+ * If the message is not a `string`, its type is based on the value of `binaryType`.
22
+ * - if `nodebuffer`, then the message is a `Buffer`.
23
+ * - if `arraybuffer`, then the message is an `ArrayBuffer`.
24
+ * - if `uint8array`, then the message is a `Uint8Array`.
25
+ *
26
+ * @param ws The websocket that sent the message
27
+ * @param message The message received
28
+ */
29
+ message(ws: ServerWebSocket<this>, message: string | Buffer): void | Promise<void>;
30
+ /**
31
+ * Called when a connection is opened.
32
+ *
33
+ * @param ws The websocket that was opened
34
+ */
35
+ open?(ws: ServerWebSocket<this>): void | Promise<void>;
36
+ /**
37
+ * Called when a connection was previously under backpressure,
38
+ * meaning it had too many queued messages, but is now ready to receive more data.
39
+ *
40
+ * @param ws The websocket that is ready for more data
41
+ */
42
+ drain?(ws: ServerWebSocket<this>): void | Promise<void>;
43
+ /**
44
+ * Called when a connection is closed.
45
+ *
46
+ * @param ws The websocket that was closed
47
+ * @param code The close code
48
+ * @param message The close message
49
+ */
50
+ close?(ws: ServerWebSocket<this>, code: number, reason: string): void | Promise<void>;
51
+ /**
52
+ * Called when a ping is sent.
53
+ *
54
+ * @param ws The websocket that received the ping
55
+ * @param data The data sent with the ping
56
+ */
57
+ ping?(ws: ServerWebSocket<this>, data: Buffer): void | Promise<void>;
58
+ /**
59
+ * Called when a pong is received.
60
+ *
61
+ * @param ws The websocket that received the ping
62
+ * @param data The data sent with the ping
63
+ */
64
+ pong?(ws: ServerWebSocket<this>, data: Buffer): void | Promise<void>;
65
+ }
17
66
  export interface AdapterPlatform {
18
67
  /**
19
68
  * The original request received from Bun.serve
@@ -32,7 +81,7 @@ export interface AdapterPlatform {
32
81
  * @param response The response to mark
33
82
  * @param ws The websocket handler
34
83
  */
35
- markForUpgrade(response: Response, ws: WebSocketHandler<any>): Response;
84
+ markForUpgrade(response: Response, ws: WebSocketHandler): Response;
36
85
  }
37
86
  export type PreCompressOptions = {
38
87
  [k in 'gzip' | 'brotli']?: boolean;
package/package.json CHANGED
@@ -34,5 +34,5 @@
34
34
  "@rollup/plugin-node-resolve": "^15.2.3",
35
35
  "rollup": "^4.18.0"
36
36
  },
37
- "version": "1.0.8"
37
+ "version": "1.0.9"
38
38
  }