The topic or array of topics to which the handler should respond.
Optional conditionA 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.
The transformed payload received from the topic.
The Kos Data Model instance to which the topic handler belongs.
true if the handler should be invoked, false otherwise.
Optional transformA transformation function that converts the raw response payload into a desired format. If not provided, the payload will be used as is.
The raw response payload received from the topic.
The transformed payload in the desired format.
Optional websocketIndicates 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.
Optional debounceDebounce events - only emit after a period of inactivity
Optional discardIf true, only keeps the last value. If false (default), accumulates all values
debounce: 1000 // Wait 1 second after last event
debounce: { delay: 1000, discardIntermediate: true } // Only keep last value
Optional throttleThrottle events - limit emissions to once per interval
Optional discardIf true, only keeps the first value in window. If false (default), accumulates all values
throttle: 500 // At most once every 500ms
throttle: { interval: 500, discardIntermediate: true } // Only keep first value in window
Optional bufferBuffer events and emit them as an array after time window or max size
Time window to collect events (ms)
Optional maxMaximum number of events to buffer
Optional filterFilter events based on a predicate function Note: This operates on the raw payload before transformation
Optional onceOnly handle the event once, then automatically unsubscribe
Optional replayReplay the last N events to new handlers
Number of events to remember and replay
Optional wildcardNamed wildcard capture for trailing /* patterns. When enabled, the portion after the /* is parsed and passed to the handler. You can optionally specify a name for the captured segment.
@kosTopicHandler({
topic: "/config/system/*",
websocket: true,
wildcardName: "configPath"
})
handleConfigUpdate(payload: ConfigData, raw: ApiCallbackWithWildcard<any>) {
// raw.wildcardCapture.configPath contains everything after "/config/system/"
}
Optional flowAdvanced flow control options using async iterators internally. Enables sophisticated event processing patterns like batching, backpressure, on-the-fly transforms, and rate limiting.
@kosTopicHandler({
topic: 'sensor.data',
websocket: true,
flow: {
batch: { size: 50, window: 1000 },
transform: (events) => aggregateEvents(events),
backpressure: { maxConcurrent: 3 }
}
})
handleProcessedEvents(aggregatedData) {
// Receives transformed, batched data with backpressure control
}
Optional requiresBaseline dependency configuration for baseline-delta race condition handling. When specified, this handler will wait for the baseline service request to complete before processing events, and will intelligently replay queued events based on temporal comparison with the baseline request/response timing.
@kosTopicHandler({
topic: TOPIC_INGREDIENT_UPDATE,
websocket: true,
lifecycle: DependencyLifecycle.READY,
requiresBaseline: {
path: PATH_INGREDIENTS,
method: 'get',
replayStrategy: 'after-request'
}
})
handleIngredientUpdate(payload: IngredientUpdatePayload) {
// Framework guarantees:
// 1. Baseline loaded before this handler executes
// 2. Queued events replayed with temporal filtering
// 3. Only events newer than baseline are processed
}
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.