@elysiajs/websocket
Advanced tools
Comparing version 0.1.0-rc.1 to 0.1.0-rc.2
@@ -0,3 +1,7 @@ | ||
/// <reference types="bun-types" /> | ||
import type { WebSocketHandler } from 'bun'; | ||
import { Elysia } from 'elysia'; | ||
import { Elysia, Router, type Context } from 'elysia'; | ||
import type { Static } from '@sinclair/typebox'; | ||
import type { HookHandler, WithArray } from 'elysia/dist/types'; | ||
import type { ElysiaWebSocket, WebSocketHeaderHandler, WebSocketSchema, WebSocketSchemaToTypedSchema } from './types'; | ||
/** | ||
@@ -26,1 +30,46 @@ * Register websocket config for Elysia | ||
export default websocket; | ||
declare module 'elysia' { | ||
interface Elysia { | ||
websocketRouter: Router; | ||
ws<Schema extends WebSocketSchema = WebSocketSchema, Path extends string = string>( | ||
/** | ||
* Path to register websocket to | ||
*/ | ||
path: Path, options: Omit<Partial<WebSocketHandler<Context>>, 'open' | 'message' | 'close' | 'drain'> & { | ||
schema?: Schema; | ||
beforeHandle?: WithArray<HookHandler<WebSocketSchemaToTypedSchema<Schema>>>; | ||
/** | ||
* Headers to register to websocket before `upgrade` | ||
*/ | ||
headers?: HeadersInit | WebSocketHeaderHandler<WebSocketSchemaToTypedSchema<Schema>>; | ||
/** | ||
* The {@link ServerWebSocket} has been opened | ||
* | ||
* @param ws The {@link ServerWebSocket} that was opened | ||
*/ | ||
open?: (ws: ElysiaWebSocket<Schema, Path>) => void | Promise<void>; | ||
/** | ||
* Handle an incoming message to a {@link ServerWebSocket} | ||
* | ||
* @param ws The {@link ServerWebSocket} that received the message | ||
* @param message The message received | ||
* | ||
* To change `message` to be an `ArrayBuffer` instead of a `Uint8Array`, set `ws.binaryType = "arraybuffer"` | ||
*/ | ||
message?: (ws: ElysiaWebSocket<Schema, Path>, message: Schema['message'] extends NonNullable<Schema['message']> ? Static<NonNullable<Schema['message']>> : string) => any; | ||
/** | ||
* The {@link ServerWebSocket} is being closed | ||
* @param ws The {@link ServerWebSocket} that was closed | ||
* @param code The close code | ||
* @param message The close message | ||
*/ | ||
close?: (ws: ElysiaWebSocket<Schema, Path>) => any; | ||
/** | ||
* The {@link ServerWebSocket} is ready for more data | ||
* | ||
* @param ws The {@link ServerWebSocket} that is ready | ||
*/ | ||
drain?: (ws: ElysiaWebSocket<Schema, Path>, code: number, reason: string) => any; | ||
}): this; | ||
} | ||
} |
/// <reference types="bun-types" /> | ||
import type { ServerWebSocket, WebSocketHandler } from 'bun'; | ||
import type { Context, TypedSchema, HookHandler, UnwrapSchema, Router } from 'elysia'; | ||
import type { ExtractPath, TypedRoute, TypedSchemaToRoute, WithArray } from 'elysia/dist/types'; | ||
import type { Static, TSchema } from '@sinclair/typebox'; | ||
import type { ServerWebSocket } from 'bun'; | ||
import type { Context, TypedSchema, UnwrapSchema } from 'elysia'; | ||
import type { ExtractPath, TypedRoute, TypedSchemaToRoute } from 'elysia/dist/types'; | ||
import type { TSchema } from '@sinclair/typebox'; | ||
import type { TypeCheck } from '@sinclair/typebox/compiler'; | ||
@@ -41,46 +41,1 @@ export declare type WebSocketSchema = Omit<TypedSchema, 'body' | 'response'> & { | ||
}>; | ||
declare module 'elysia' { | ||
interface Elysia { | ||
websocketRouter: Router; | ||
ws<Schema extends WebSocketSchema = WebSocketSchema, Path extends string = string>( | ||
/** | ||
* Path to register websocket to | ||
*/ | ||
path: Path, options: Omit<Partial<WebSocketHandler<Context>>, 'open' | 'message' | 'close' | 'drain'> & { | ||
schema?: Schema; | ||
beforeHandle?: WithArray<HookHandler<WebSocketSchemaToTypedSchema<Schema>>>; | ||
/** | ||
* Headers to register to websocket before `upgrade` | ||
*/ | ||
headers?: HeadersInit | WebSocketHeaderHandler<WebSocketSchemaToTypedSchema<Schema>>; | ||
/** | ||
* The {@link ServerWebSocket} has been opened | ||
* | ||
* @param ws The {@link ServerWebSocket} that was opened | ||
*/ | ||
open?: (ws: ElysiaWebSocket<Schema, Path>) => void | Promise<void>; | ||
/** | ||
* Handle an incoming message to a {@link ServerWebSocket} | ||
* | ||
* @param ws The {@link ServerWebSocket} that received the message | ||
* @param message The message received | ||
* | ||
* To change `message` to be an `ArrayBuffer` instead of a `Uint8Array`, set `ws.binaryType = "arraybuffer"` | ||
*/ | ||
message?: (ws: ElysiaWebSocket<Schema, Path>, message: Schema['message'] extends NonNullable<Schema['message']> ? Static<NonNullable<Schema['message']>> : string) => any; | ||
/** | ||
* The {@link ServerWebSocket} is being closed | ||
* @param ws The {@link ServerWebSocket} that was closed | ||
* @param code The close code | ||
* @param message The close message | ||
*/ | ||
close?: (ws: ElysiaWebSocket<Schema, Path>) => any; | ||
/** | ||
* The {@link ServerWebSocket} is ready for more data | ||
* | ||
* @param ws The {@link ServerWebSocket} that is ready | ||
*/ | ||
drain?: (ws: ElysiaWebSocket<Schema, Path>, code: number, reason: string) => any; | ||
}): this; | ||
} | ||
} |
{ | ||
"name": "@elysiajs/websocket", | ||
"version": "0.1.0-rc.1", | ||
"version": "0.1.0-rc.2", | ||
"description": "Plugin for Elysia that add support for websocket", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -13,4 +13,10 @@ import type { WebSocketHandler } from 'bun' | ||
import type { ElysiaWebSocket } from './types' | ||
import type { TSchema } from '@sinclair/typebox' | ||
import type { Static, TSchema } from '@sinclair/typebox' | ||
import type { HookHandler, WithArray } from 'elysia/dist/types' | ||
import type { | ||
ElysiaWebSocket, | ||
WebSocketHeaderHandler, | ||
WebSocketSchema, | ||
WebSocketSchemaToTypedSchema | ||
} from './types' | ||
@@ -160,1 +166,79 @@ /** | ||
export default websocket | ||
declare module 'elysia' { | ||
interface Elysia { | ||
websocketRouter: Router | ||
ws< | ||
Schema extends WebSocketSchema = WebSocketSchema, | ||
Path extends string = string | ||
>( | ||
/** | ||
* Path to register websocket to | ||
*/ | ||
path: Path, | ||
options: Omit< | ||
Partial<WebSocketHandler<Context>>, | ||
'open' | 'message' | 'close' | 'drain' | ||
> & { | ||
schema?: Schema | ||
beforeHandle?: WithArray< | ||
HookHandler<WebSocketSchemaToTypedSchema<Schema>> | ||
> | ||
/** | ||
* Headers to register to websocket before `upgrade` | ||
*/ | ||
headers?: | ||
| HeadersInit | ||
| WebSocketHeaderHandler< | ||
WebSocketSchemaToTypedSchema<Schema> | ||
> | ||
/** | ||
* The {@link ServerWebSocket} has been opened | ||
* | ||
* @param ws The {@link ServerWebSocket} that was opened | ||
*/ | ||
open?: ( | ||
ws: ElysiaWebSocket<Schema, Path> | ||
) => void | Promise<void> | ||
/** | ||
* Handle an incoming message to a {@link ServerWebSocket} | ||
* | ||
* @param ws The {@link ServerWebSocket} that received the message | ||
* @param message The message received | ||
* | ||
* To change `message` to be an `ArrayBuffer` instead of a `Uint8Array`, set `ws.binaryType = "arraybuffer"` | ||
*/ | ||
message?: ( | ||
ws: ElysiaWebSocket<Schema, Path>, | ||
message: Schema['message'] extends NonNullable< | ||
Schema['message'] | ||
> | ||
? Static<NonNullable<Schema['message']>> | ||
: string | ||
) => any | ||
/** | ||
* The {@link ServerWebSocket} is being closed | ||
* @param ws The {@link ServerWebSocket} that was closed | ||
* @param code The close code | ||
* @param message The close message | ||
*/ | ||
close?: (ws: ElysiaWebSocket<Schema, Path>) => any | ||
/** | ||
* The {@link ServerWebSocket} is ready for more data | ||
* | ||
* @param ws The {@link ServerWebSocket} that is ready | ||
*/ | ||
drain?: ( | ||
ws: ElysiaWebSocket<Schema, Path>, | ||
code: number, | ||
reason: string | ||
) => any | ||
} | ||
): this | ||
} | ||
} |
@@ -88,79 +88,1 @@ import type { ServerWebSocket, WebSocketHandler } from 'bun' | ||
> | ||
declare module 'elysia' { | ||
interface Elysia { | ||
websocketRouter: Router | ||
ws< | ||
Schema extends WebSocketSchema = WebSocketSchema, | ||
Path extends string = string | ||
>( | ||
/** | ||
* Path to register websocket to | ||
*/ | ||
path: Path, | ||
options: Omit< | ||
Partial<WebSocketHandler<Context>>, | ||
'open' | 'message' | 'close' | 'drain' | ||
> & { | ||
schema?: Schema | ||
beforeHandle?: WithArray< | ||
HookHandler<WebSocketSchemaToTypedSchema<Schema>> | ||
> | ||
/** | ||
* Headers to register to websocket before `upgrade` | ||
*/ | ||
headers?: | ||
| HeadersInit | ||
| WebSocketHeaderHandler< | ||
WebSocketSchemaToTypedSchema<Schema> | ||
> | ||
/** | ||
* The {@link ServerWebSocket} has been opened | ||
* | ||
* @param ws The {@link ServerWebSocket} that was opened | ||
*/ | ||
open?: ( | ||
ws: ElysiaWebSocket<Schema, Path> | ||
) => void | Promise<void> | ||
/** | ||
* Handle an incoming message to a {@link ServerWebSocket} | ||
* | ||
* @param ws The {@link ServerWebSocket} that received the message | ||
* @param message The message received | ||
* | ||
* To change `message` to be an `ArrayBuffer` instead of a `Uint8Array`, set `ws.binaryType = "arraybuffer"` | ||
*/ | ||
message?: ( | ||
ws: ElysiaWebSocket<Schema, Path>, | ||
message: Schema['message'] extends NonNullable< | ||
Schema['message'] | ||
> | ||
? Static<NonNullable<Schema['message']>> | ||
: string | ||
) => any | ||
/** | ||
* The {@link ServerWebSocket} is being closed | ||
* @param ws The {@link ServerWebSocket} that was closed | ||
* @param code The close code | ||
* @param message The close message | ||
*/ | ||
close?: (ws: ElysiaWebSocket<Schema, Path>) => any | ||
/** | ||
* The {@link ServerWebSocket} is ready for more data | ||
* | ||
* @param ws The {@link ServerWebSocket} that is ready | ||
*/ | ||
drain?: ( | ||
ws: ElysiaWebSocket<Schema, Path>, | ||
code: number, | ||
reason: string | ||
) => any | ||
} | ||
): this | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
50260
832
0