Skip to content

WebSocket Package Entry Point (index.ts)

This file serves as the main entry point for the @sodacore/core WebSocket (WS) integration package. It re-exports all primary decorators, context classes, middleware, providers, services, and types, making them available for import from a single location. The default export is the WsPlugin for easy integration with the Sodacore application.


Features

  • Centralized Exports: Exposes all WebSocket-related decorators, context classes, middleware, providers, and services for easy import.
  • Decorator Exports: Provides decorators for WebSocket controllers, method exposure, and middleware.
  • Context and Service Exports: Exports the main WebSocket context class, upgrade middleware, connections provider, and core WebSocket service.
  • Type Exports: Exports the core WebSocket configuration type for strong typing in plugins and services.
  • Default Plugin Export: Exports WsPlugin as the default, enabling quick registration with the Sodacore application.

Usage

Import WebSocket features directly from the package root:

typescript
import WsPlugin, {
	Controller,
	Expose,
	Middleware,
	UpgradeMiddleware,
	WsConnections,
	WsContext,
	WsService,
	IConfig,
} from '@sodacore/core/ws';

Register the plugin with your Sodacore application:

typescript
import WsPlugin from '@sodacore/core/ws';
app.register(WsPlugin);

API

Default Export

  • WsPlugin The main plugin class for integrating WebSocket functionality with the Sodacore application.

Named Exports

  • Decorators:

    • Controller (class decorator for WebSocket controllers)
    • Expose (method decorator for exposing WebSocket commands)
    • Middleware (class decorator for WebSocket middleware)
  • Middleware:

    • UpgradeMiddleware (handles HTTP-to-WebSocket upgrades)
  • Context & Services:

    • WsContext (WebSocket context class)
    • WsConnections (manages active WebSocket connections)
    • WsService (core WebSocket service)
  • Types:

    • IConfig (WebSocket configuration type)

Notes

  • This file is intended to be the single import point for all WebSocket features in the Sodacore ecosystem.
  • All exports are organized for clarity and ease of use, supporting both application and library development.
  • Type exports ensure strong typing and IntelliSense support in TypeScript projects.

Released under the Apache-2.0 License.