import type { Observable } from 'rxjs'; import type { BaseEventInput, CanRevertResult, CreatedEvent, EventFlow, EventOutputState, IEventStoreEntity, IEventStoreRepo, PreviewRevertResult, RevertResult } from '@schemeless/event-store-types'; import { makeReplay } from './makeReplay'; /** * Emitted by `on('processed', handler)` and the deprecated `output$` stream. * * In v5, only `EventOutputState.success` and `EventOutputState.invalid` are emitted. * `SideEffectsState` and `EventObserverState` values are never emitted — they were * part of the v3 observable pipeline which has been removed. */ export interface EventOutput { state: EventOutputState; error?: Error; event: CreatedEvent; } export interface AggregateResult { state: State; sequence: number; } export interface EventStoreOptions { /** * Concurrency for the main event queue. * @default 1 (sequential processing to maintain event ordering) */ mainQueueConcurrent?: number; /** * Concurrency for the side effect queue. * @default 1 */ sideEffectQueueConcurrent?: number; } export interface EventStoreCapabilities { /** * Indicates whether getAggregate is available for this repository. */ aggregate: boolean; } export interface EventStore { /** * @deprecated Internal implementation detail. Do not use directly. * Use `submit()` for sending events and `on('processed', handler)` for notifications. * Will be removed in v5. */ mainQueue: any; /** * @deprecated Internal implementation detail. Do not use directly. * Will be removed in v5. */ sideEffectQueue: any; /** * @deprecated Use `submit(flow, input)` instead. Will be removed in v5. */ receive: (flow: EventFlow) => (input: BaseEventInput) => Promise<[CreatedEvent, ...Array>]>; /** * Submit an event for processing. This is the preferred API over `receive`. * Validates, applies, persists, runs side effects, and notifies observers. * * @param flow - The EventFlow definition for this event type * @param input - The event input (payload, identifier, etc.) * @returns All created events (root + consequent events) * @throws ValidationError if validation fails */ submit: (flow: EventFlow, input: BaseEventInput) => Promise<[CreatedEvent, ...Array>]>; replay: ReturnType; eventStoreRepo: IEventStoreRepo; capabilities: EventStoreCapabilities; /** * @deprecated Use `on('processed', handler)` instead. Will be removed in v5. * Requires RxJS subscription. */ output$: Observable; /** * Subscribe to event processing notifications. * Alternative to output$ that doesn't require RxJS. * * @returns Unsubscribe function */ on: (event: 'processed', handler: (output: EventOutput) => void) => () => void; /** * Load aggregate state by replaying events (with optional snapshot optimization). * Requires aggregate capability support from the repo. * * @throws Error if aggregate replay is not supported by the adapter */ getAggregate: (domain: string, identifier: string, reducer: (state: State, event: IEventStoreEntity) => State, initialState: State) => Promise>; /** * Checks if an event and all its descendants can be reverted. * Returns information about missing compensate hooks. */ canRevert: (eventId: string) => Promise; /** * Preview which events would be affected by a revert operation. * Does not execute any changes. */ previewRevert: (eventId: string) => Promise; /** * Reverts a root event and all its descendants. * Generates compensating events for each reverted event. * * @throws Error if the event is not a root event or any event lacks a compensate hook */ revert: (eventId: string) => Promise; /** * Gracefully shuts down the event store. * - Stops accepting new events * - Waits for queued events to complete (up to timeout) * - Releases all resources * * @param timeout - Maximum time to wait for shutdown in ms (default: 5000) * @throws Error if shutdown times out */ shutdown: (timeout?: number) => Promise; } export * from '@schemeless/event-store-types';