UNPKG

synapse-storage

Version:

Набор инструментов для управления состоянием и апи-запросами

96 lines (93 loc) 2.94 kB
import { a as SynapseStoreWithDispatcher } from './createSynapse-CzeX0ONj.js'; export { A as AnySynapseStore, S as SynapseStoreBasic, b as SynapseStoreWithEffects, c as createSynapse } from './createSynapse-CzeX0ONj.js'; import { j as IStorage } from './storage.interface-2HKvqdAJ.js'; import { D as DispatchFunction, f as DispatchActions } from './dispatcher.module-DjMloBXe.js'; import 'rxjs'; import './selector.interface-CA5y-kD_.js'; interface EventBusEvent { id: string; event: string; data: any; metadata: { ttl?: number | null; priority?: 'low' | 'normal' | 'high'; [key: string]: any; }; timestamp: number; } interface EventBusState { events: Record<string, EventBusEvent>; subscriptions: Record<string, any>; } interface EventBusConfig { name?: string; autoCleanup?: boolean; maxEvents?: number; } /** * Создает EventBus для связи между модулями * * @example * ```typescript * // Создание EventBus * const eventBus = await createEventBus({ * name: 'app-events', * autoCleanup: true, * maxEvents: 500 * }) * * // Использование в Synapse * const mySynapse = await createSynapse({ * dependencies: [eventBus], * createEffectConfig: (dispatcher) => ({ * dispatchers: { * dispatcher, * eventBus: eventBus.dispatcher * } * }), * effects: [ * createEffect((action$, _, __, { eventBus }) => { * // Публикация события * eventBus.dispatch.publish({ * event: 'USER_UPDATED', * data: { userId: 123 } * }) * * // Подписка на события * eventBus.dispatch.subscribe({ * eventPattern: 'CORE_*', * handler: (data, event) => console.log('Received:', event.event, data) * }) * }) * ] * }) * ``` */ declare const createEventBus: (config?: EventBusConfig) => Promise<SynapseStoreWithDispatcher<EventBusState, IStorage<EventBusState>, any, Record<string, DispatchFunction<any, any>> & DispatchActions<{ publish: DispatchFunction<{ event: string; data: any; metadata?: Record<string, any>; }, { eventId: string; event: string; data: any; }>; subscribe: DispatchFunction<{ eventPattern: string; handler: (data: any, event: EventBusEvent) => void | Promise<void>; options?: Record<string, any>; }, { subscriptionId: string; unsubscribe: VoidFunction; }>; getEventHistory: DispatchFunction<{ eventType: string; limit?: number; }, EventBusEvent[]>; clearEvents: DispatchFunction<{ olderThan?: number; } | undefined, void>; getActiveSubscriptions: DispatchFunction<any, any[]>; }>>>; export { type EventBusConfig, type EventBusEvent, type EventBusState, SynapseStoreWithDispatcher, createEventBus };