UNPKG

@sailboat-computer/data-storage

Version:

Shared data storage library for sailboat computer v3

94 lines (93 loc) 2.34 kB
/** * Event Bus for Data Storage * * This module provides a simple event bus implementation for the data storage package. */ import { common } from '@sailboat-computer/sailboat-types'; export declare const EventCategory: { DATA: common.EventCategory; ALERT: common.EventCategory; CONFIGURATION: common.EventCategory; SYSTEM: common.EventCategory; USER_ACTION: common.EventCategory; }; export type EventCategoryType = common.EventCategory; /** * Event options */ export interface EventOptions { /** * Event category */ category: EventCategoryType; /** * Event priority */ priority: 'low' | 'normal' | 'high' | 'critical'; } /** * Event handler */ export type EventHandler = (data: any) => void | Promise<void>; /** * Event bus interface */ export interface EventBus { /** * Publish an event * * @param eventType - Event type * @param data - Event data * @param options - Event options */ publish(eventType: string, data: any, options?: EventOptions): Promise<void>; /** * Subscribe to an event * * @param eventType - Event type * @param handler - Event handler * @returns Subscription ID */ subscribe(eventType: string, handler: EventHandler): string; /** * Unsubscribe from an event * * @param subscriptionId - Subscription ID */ unsubscribe(subscriptionId: string): void; } /** * In-memory event bus implementation */ export declare class InMemoryEventBus implements EventBus { private subscriptions; /** * Publish an event * * @param eventType - Event type * @param data - Event data * @param options - Event options */ publish(eventType: string, data: any, options?: EventOptions): Promise<void>; /** * Subscribe to an event * * @param eventType - Event type * @param handler - Event handler * @returns Subscription ID */ subscribe(eventType: string, handler: EventHandler): string; /** * Unsubscribe from an event * * @param subscriptionId - Subscription ID */ unsubscribe(subscriptionId: string): void; } /** * Create a new event bus * * @returns Event bus */ export declare function createEventBus(): EventBus; export declare const eventBus: EventBus;