• Decorator for defining a Kos topic handler function within a Kos Data Model class.

    Type Parameters

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

    Parameters

    Returns ((target, _propertyKey, descriptor) => void)

    A decorator function.

      • (target, _propertyKey, descriptor): void
      • Parameters

        • target: any
        • _propertyKey: string
        • descriptor: PropertyDescriptor

        Returns void

    Example: Basic usage:

    @kosTopicHandler({
    topic: 'temperature/update',
    websocket: true
    })
    handleTemperature(payload: TemperatureData) { }

    Example: Debounced handling:

    @kosTopicHandler({
    topic: 'rapid/updates',
    websocket: true,
    debounce: 1000 // Wait 1 second after last event
    })
    handleRapidUpdates(payload: UpdateData) { }

    Example: Buffered batch processing:

    @kosTopicHandler({
    topic: 'log/entry',
    websocket: true,
    buffer: { time: 5000, maxSize: 100 }
    })
    handleLogBatch(entries: LogEntry[]) { }

    Example: Trailing wildcard with custom name:

    @kosTopicHandler({
    topic: '/config/system/*',
    websocket: true,
    wildcardName: 'configPath'
    })
    handleConfigUpdate(payload: ConfigData, raw: ApiCallbackWithWildcard<any>) {
    // raw.wildcardCapture.configPath = "network/timeout" (everything after "/config/system/")
    }

    Example: Trailing wildcard with PropKeys:

    const DEVICE_ID = createPropKey<DeviceModel>('deviceId');

    @kosTopicHandler({
    topic: `/devices/${DEVICE_ID}/sensors/*`,
    websocket: true,
    wildcardName: 'sensorPath'
    })
    handleSensorEvent(payload: SensorData, raw: ApiCallbackWithWildcard<any>) {
    // raw.wildcardCapture.sensorPath = "temperature/reading" (everything after device-specific prefix)
    }