Expose Decorator
This file defines the Expose
method decorator for the @sodacore/core
WebSocket (WS) module. It marks a controller method as callable via WebSocket commands, allowing the method to be invoked remotely using the namespace/methodName
command format.
Features
- Method Exposure: Marks controller methods as exposed for WebSocket command invocation.
- Metadata Management: Stores metadata about exposed methods for later discovery and routing by the WebSocket framework.
- Command Routing: Enables remote clients to call specific controller methods using the
namespace/methodName
command format.
Usage
typescript
import Expose from './decorators/expose';
class ChatController {
@Expose()
async sendMessage(context, data) {
// Handle sending a chat message
}
}
API
Expose(): MethodDecorator
- Returns: A method decorator function that registers the method as exposed for WebSocket commands.
How It Works
- Retrieves the current list of exposed methods from the controller's metadata.
- Adds the decorated method's property key to the list.
- Updates the metadata so the WebSocket router can discover and invoke the method when the corresponding command is received.
Notes
- Only methods decorated with
@Expose()
can be called via WebSocket commands. - The command format for invocation is
namespace/methodName
, wherenamespace
is defined by the controller's@Controller
decorator. - This decorator is intended for use within WebSocket controller classes in the Sodacore framework.