Skip to content

Commit

Permalink
chore: don't gitignore manual types
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Dec 7, 2023
1 parent af705a6 commit ec9330b
Show file tree
Hide file tree
Showing 4 changed files with 10,839 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
node_modules
coverage
dist
types
.vscode
.DS_Store
.eslintcache
Expand Down
60 changes: 60 additions & 0 deletions types/bun.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Reference: https://bun.sh/docs/api/websockets

export interface BunWSOptions {
message: (
ws: BunServerWebSocket,
message: string | ArrayBuffer | Uint8Array,
) => void;
open?: (ws: BunServerWebSocket) => void;
close?: (ws: BunServerWebSocket) => void;
error?: (ws: BunServerWebSocket, error: Error) => void;
drain?: (ws: BunServerWebSocket) => void;
perMessageDeflate?:
| boolean
| {
compress?: boolean | BunWSCompressor;
decompress?: boolean | BunWSCompressor;
};
}

type BunWSCompressor =
| `"disable"`
| `"shared"`
| `"dedicated"`
| `"3KB"`
| `"4KB"`
| `"8KB"`
| `"16KB"`
| `"32KB"`
| `"64KB"`
| `"128KB"`
| `"256KB"`;

export interface BunWSServer {
pendingWebsockets: number;
publish(
topic: string,
data: string | ArrayBufferView | ArrayBuffer,
compress?: boolean,
): number;
upgrade(
req: Request,
options?: {
headers?: HeadersInit;
data?: any;
},
): boolean;
}

export interface BunServerWebSocket {
readonly data: any;
readonly readyState: number;
readonly remoteAddress: string;
send(message: string | ArrayBuffer | Uint8Array, compress?: boolean): number;
close(code?: number, reason?: string): void;
subscribe(topic: string): void;
unsubscribe(topic: string): void;
publish(topic: string, message: string | ArrayBuffer | Uint8Array): void;
isSubscribed(topic: string): boolean;
cork(cb: (ws: BunServerWebSocket) => void): void;
}
Loading

0 comments on commit ec9330b

Please sign in to comment.