nestjs-event-sourcing-lib
Version:
A comprehensive Event Sourcing and CQRS library for NestJS applications
78 lines • 3.04 kB
TypeScript
import { DynamicModule, Type } from '@nestjs/common';
import { Event } from './core/event';
import { Command } from './core/command';
import { AggregateRoot } from './core/aggregate-root';
import { Projection } from './core/projection';
import { EventStore } from './core/event-store.interface';
import { CommandHandler } from './services/command.handler';
import { EventBus } from './services/event.publisher';
import { PostgresEventStore } from './event-stores/postgres.event-store';
import { MongoDBEventStore } from './event-stores/mongodb.event-store';
export interface EventStoreConfig {
type: 'postgres' | 'mongodb' | 'prisma' | 'eventstore';
connectionString: string;
options?: Record<string, any>;
}
export interface EventSourcingModuleOptions {
eventStore: EventStoreConfig;
snapshotFrequency?: number;
retryPolicy?: {
maxRetries: number;
retryDelay: number;
};
enableMetrics?: boolean;
}
export interface EventSourcingModuleAsyncOptions {
inject?: any[];
useFactory?: (...args: any[]) => Promise<EventSourcingModuleOptions> | EventSourcingModuleOptions;
useClass?: Type<{
createOptions(): Promise<EventSourcingModuleOptions> | EventSourcingModuleOptions;
}>;
useExisting?: Type<{
createOptions(): Promise<EventSourcingModuleOptions> | EventSourcingModuleOptions;
}>;
}
export declare const EVENT_STORE_TOKEN = "EVENT_STORE";
/**
* Main module for Event Sourcing
*/
export declare class EventSourcingModule {
private static readonly logger;
/**
* Synchronous module registration
*/
static forRoot(options: EventSourcingModuleOptions): DynamicModule;
/**
* Asynchronous module registration
*/
static forRootAsync(options: EventSourcingModuleAsyncOptions): DynamicModule;
/**
* Register aggregates for specific module
*/
static forFeature(aggregates?: Type<AggregateRoot>[]): DynamicModule;
/**
* Creates Event Store provider
*/
private static createEventStoreProvider;
/**
* Creates configuration provider
*/
private static createConfigProvider;
/**
* Creates async providers
*/
private static createAsyncProviders;
/**
* Creates Event Store instance based on type
*/
private static createEventStoreInstance;
}
export { Event, Command, AggregateRoot, Projection, EventStore };
export { CommandHandler, EventBus };
export { PostgresEventStore, MongoDBEventStore };
export { AggregateRoot as AggregateRootDecorator } from './decorators/aggregate.decorator';
export { CommandHandler as CommandHandlerDecorator, Command as CommandDecorator } from './decorators/command.decorator';
export { OnEvent, Event as EventDecorator } from './decorators/event.decorator';
export { Projection as ProjectionDecorator } from './decorators/projection.decorator';
export { EventStoreConnectionError, EventStoreSaveError, EventStoreLoadError, } from './core/event-store.interface';
//# sourceMappingURL=event-sourcing.module.d.ts.map