UNPKG

nestjs-event-sourcing-lib

Version:

A comprehensive Event Sourcing and CQRS library for NestJS applications

104 lines 2.96 kB
import { BaseEventStore, EventStoreConnectionOptions, SaveEventsResult, GetEventsOptions, GetEventsResult, AggregateSnapshot, EventStoreStats } from '../core/event-store.interface'; import { Event } from '../core/event'; interface TypeORMDataSource { isInitialized: boolean; initialize(): Promise<void>; destroy(): Promise<void>; getRepository(entity: any): any; createQueryRunner(): any; } /** * Entity for storing events in PostgreSQL */ export declare class EventEntity { event_id: string; aggregate_id: string; event_type: string; payload: any; version: number; timestamp: Date; aggregate_type?: string; correlation_id?: string; causation_id?: string; user_id?: string; metadata?: any; } /** * Entity for storing snapshots in PostgreSQL */ export declare class SnapshotEntity { aggregate_id: string; aggregate_type: string; version: number; data: any; timestamp: Date; } /** * PostgreSQL Event Store implementation */ export declare class PostgresEventStore extends BaseEventStore { private readonly customDataSource?; private readonly logger; private dataSource?; private eventRepository?; private snapshotRepository?; constructor(options: EventStoreConnectionOptions, customDataSource?: TypeORMDataSource | undefined); /** * Connects to PostgreSQL */ connect(): Promise<void>; /** * Disconnects from PostgreSQL */ disconnect(): Promise<void>; /** * Saves events for aggregate */ saveEvents(aggregateId: string, events: Event[], expectedVersion?: number): Promise<SaveEventsResult>; /** * Gets events for aggregate */ getEvents(aggregateId: string, options?: GetEventsOptions): Promise<GetEventsResult>; /** * Saves aggregate snapshot */ saveSnapshot(snapshot: AggregateSnapshot): Promise<void>; /** * Gets the latest snapshot for aggregate */ getSnapshot(aggregateId: string): Promise<AggregateSnapshot | null>; /** * Deletes aggregate snapshot */ deleteSnapshot(aggregateId: string): Promise<void>; /** * Gets events by type */ getEventsByType(eventType: string, options?: GetEventsOptions): Promise<GetEventsResult>; /** * Gets events in time range */ getEventsByTimeRange(from: Date, to: Date, options?: GetEventsOptions): Promise<GetEventsResult>; /** * Deletes all events for aggregate */ deleteAggregate(aggregateId: string): Promise<void>; /** * Gets Event Store statistics */ getStats(): Promise<EventStoreStats>; /** * Clears all data (used for testing) */ clear(): Promise<void>; /** * Checks Event Store health */ healthCheck(): Promise<boolean>; /** * Converts EventEntity to Event */ private entityToEvent; } export {}; //# sourceMappingURL=postgres.event-store.d.ts.map