dt-common-device
Version:
A secure and robust device management library for IoT applications
45 lines (44 loc) • 1.87 kB
TypeScript
import { DeviceEvent } from "./interfaces/DeviceEvent";
import { IEventHandler } from "./interfaces/IEventHandler";
import { ILogger } from "../config/config.types";
import { LocalDeviceService } from "../entities/device/local/services/Device.service";
import { IAuditProperties } from "../audit/IAuditProperties";
export declare abstract class BaseEventHandler implements IEventHandler {
protected readonly supportedEventTypes: string[];
protected readonly priority: number;
protected readonly logger: ILogger;
protected readonly localDeviceService: LocalDeviceService;
constructor(supportedEventTypes: string[], priority?: number);
/**
* Handle a single event - to be implemented by specific handlers
*/
handleEvent(event: DeviceEvent): Promise<void>;
beforeEvent(event: DeviceEvent): Promise<void>;
abstract onEvent(event: DeviceEvent): Promise<void>;
afterEvent(deviceId: string, event: DeviceEvent, auditBody: IAuditProperties, actionPayload: any, eventType?: string): Promise<void>;
/**
* Handle multiple events - default implementation processes them sequentially
*/
handleEvents(events: DeviceEvent[]): Promise<void>;
onStateChange(deviceId: string, state: Record<string, any>, auditProperties: IAuditProperties, eventType?: string): Promise<void>;
/**
* Check if this handler can process the given event type
*/
canHandle(eventType: string): boolean;
/**
* Get the priority of this handler
*/
getPriority(): number;
/**
* Get the event types this handler can process
*/
getSupportedEventTypes(): string[];
/**
* Common validation method
*/
protected validateEvent(event: DeviceEvent): boolean;
/**
* Common error handling method
*/
protected handleError(error: any, context: string): Promise<void>;
}