/** * Saga Orchestrator * * Manages distributed transactions across multiple data sources using * the Saga pattern with compensating transactions for rollback. */ import { ISagaTransaction, ISagaState, ISagaResult, IRetryConfig, IWarehouseQuery, IWarehouseResult } from '../types'; /** * Step executor function */ export type StepExecutor = (operation: Omit) => Promise; /** * Saga orchestrator options */ export interface ISagaOrchestratorOptions { /** Default timeout for steps (ms) */ defaultTimeout?: number; /** Default retry configuration */ defaultRetry?: IRetryConfig; /** Persist saga state callback */ persistState?: (state: ISagaState) => Promise; /** Load saga state callback */ loadState?: (sagaId: string) => Promise; } /** * Saga Orchestrator * * Coordinates execution of distributed transactions using the Saga pattern. * Handles step execution, compensation on failure, and state management. */ export declare class SagaOrchestrator { private readonly executor; private readonly options; private readonly activeSagas; constructor(executor: StepExecutor, options?: ISagaOrchestratorOptions); /** * Execute a saga transaction */ execute(mainOperation: Omit, transaction: ISagaTransaction): Promise; /** * Resume a saga from persisted state */ resume(sagaId: string): Promise; /** * Get current saga state */ getState(sagaId: string): ISagaState | undefined; /** * Initialize saga state */ private initializeSagaState; /** * Execute all saga steps */ private executeSteps; /** * Execute a single step with retry logic */ private executeStepWithRetry; /** * Check if an error should trigger a retry */ private shouldRetry; /** * Handle saga failure - compensate or abort */ private handleSagaFailure; /** * Execute compensation for completed steps (in reverse order) */ private executeCompensations; /** * Build execution order respecting dependencies */ private buildExecutionOrder; /** * Get step by index */ private getStepByIndex; /** * Build saga result */ private buildResult; /** * Persist saga state */ private persistState; /** * Sleep for a given duration */ private sleep; }