import { Result } from "../common/result"; import { Command } from "./command"; import { DomainEvent } from "../domain/domain-event"; export interface SagaStep { readonly stepId: string; readonly name: string; readonly command: Command; readonly compensation?: Command; readonly completed: boolean; readonly compensated: boolean; } export interface Saga { readonly sagaId: string; readonly name: string; readonly status: SagaStatus; readonly steps: SagaStep[]; readonly currentStepIndex: number; executeNextStep(): Promise>; compensate(): Promise>; complete(): Promise>; fail(error: Error): Promise>; } export declare enum SagaStatus { PENDING = "pending", RUNNING = "running", COMPLETED = "completed", FAILED = "failed", COMPENSATED = "compensated" } export interface SagaManager { startSaga(saga: Saga): Promise>; getSaga(sagaId: string): Promise>; getSagas(): Promise>; getSagasByStatus(status: SagaStatus): Promise>; handleSagaEvent(event: DomainEvent): Promise>; } export declare abstract class BaseSaga implements Saga { readonly sagaId: string; readonly name: string; readonly steps: SagaStep[]; private _status; private _currentStepIndex; constructor(name: string, steps?: SagaStep[]); get status(): SagaStatus; get currentStepIndex(): number; private generateSagaId; protected abstract executeCommand(command: Command): Promise>; executeNextStep(): Promise>; compensate(): Promise>; complete(): Promise>; fail(error: Error): Promise>; }