Interface IKosTopicHandlerParams<Response, Model, TransformedResponse>

Configuration parameters for defining a Kos topic handler function within a Kos Data Model class.

Typeparam

Response - The type of the raw response payload received from the topic.

Typeparam

Model - The type of the Kos Data Model to which the topic handler belongs.

Typeparam

TransformedResponse - The type of the transformed response payload after applying the transformation function.

interface IKosTopicHandlerParams<Response, Model, TransformedResponse> {
    topic: string | string[];
    condition?: ((payload, model) => boolean);
    transform?: ((payload) => TransformedResponse);
    websocket?: boolean;
}

Type Parameters

  • Response = any
  • Model extends IKosDataModel = any
  • TransformedResponse = Response

Properties

topic: string | string[]

The topic or array of topics to which the handler should respond.

condition?: ((payload, model) => boolean)

A conditional function that determines whether the handler should be invoked based on the received payload and the Kos Data Model instance. If not provided, the handler will always be invoked when a matching topic is received.

Type declaration

    • (payload, model): boolean
    • Parameters

      • payload: TransformedResponse

        The transformed payload received from the topic.

      • model: Model

        The Kos Data Model instance to which the topic handler belongs.

      Returns boolean

Returns

true if the handler should be invoked, false otherwise.

transform?: ((payload) => TransformedResponse)

A transformation function that converts the raw response payload into a desired format. If not provided, the payload will be used as is.

Type declaration

Returns

The transformed payload in the desired format.

websocket?: boolean

Indicates whether the topic handler should listen for WebSocket messages. If set to true, the handler will be invoked when WebSocket messages with matching topics are received. Default is false.