WSOperation
Package: @opra/common
WSOperation is the runtime class that represents a single WebSocket operation within a WSController. An operation maps a socket event name (or pattern) to a handler, declares the argument types it accepts, and optionally declares a response type for request-response flows.
Inheritance
DocumentElement
└── WSOperation
Properties
| Property | Type | Description |
|---|---|---|
name | string | Operation name as registered on the controller. |
description | string | undefined | Human-readable description. |
event | string | RegExp | The socket event name or pattern this operation handles. Defaults to the operation name if not explicitly set. |
arguments | WSOperationArgument[] | Declared argument descriptors — each carries a type: DataType, a parameterIndex: number, and an optional required flag. |
types | DataTypeMap | Local data types scoped to this operation. |
response | DataType | undefined | Expected response type for request-response flows. undefined for fire-and-forget operations. |
WSOperationArgument
| Property | Type | Description |
|---|---|---|
type | DataType | Data type used to validate the argument at this position. |
parameterIndex | number | Zero-based index of the argument in the handler's parameter list. |
required | boolean | undefined | Whether the argument must be present. |
Methods
toJSON()
Returns a plain OpraSchema.WSOperation object for schema export.
toJSON(): OpraSchema.WSOperation
Event matching
When event is a string it must match exactly. When it is a RegExp, the framework tests incoming event names against the pattern. In decorator usage, a string starting with / is automatically parsed as a regular expression:
@WSOperation({ event: /^room:.+/ })
joinRoom(ctx: SocketioContext, payload: JoinRoomDto) { ... }
Obtaining a WSOperation instance
import { WSApi } from '@opra/common';
const document = await ApiDocumentFactory.createDocument({ ... });
if (document.api instanceof WSApi) {
const op = document.api.findOperation('ChatController', 'sendMessage');
if (op) {
console.log(op.name); // 'sendMessage'
console.log(op.event); // 'sendMessage' or /pattern/
console.log(op.arguments); // [{ type: MessageType, parameterIndex: 0 }]
console.log(op.response?.name); // response type name, if any
}
}
→ WSController · WSApi