Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@elysiajs/websocket

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@elysiajs/websocket - npm Package Compare versions

Comparing version 0.1.0-rc.1 to 0.1.0-rc.2

51

dist/index.d.ts

@@ -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;
}
}

53

dist/types.d.ts
/// <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
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc