smart-saga-pattern
Version:
A library implementing the Saga pattern for microservice architecture
52 lines (51 loc) • 1.57 kB
TypeScript
import { SagaParticipant } from '../choreography/SagaParticipant';
import { SagaContext, SagaOptions, StateStore } from '../types';
import { Saga } from '../core/Saga';
/**
* Options for a DISagaCoordinator
*/
export interface DISagaCoordinatorOptions extends SagaOptions {
name: string;
subscribeTopic: string;
publishTopic: string;
}
/**
* Coordinates a choreography-based Saga using dependency injection
* @template T Type of the context
*/
export declare class DISagaCoordinator<T = any> extends Saga<T> {
private participant;
private stateStore?;
private completionPromise?;
private completionResolve?;
private completionReject?;
/**
* Creates a new DISagaCoordinator
* @param participant Saga participant for communication
* @param options Options for the coordinator
* @param stateStore Optional state store for persistence
*/
constructor(participant: SagaParticipant, options: DISagaCoordinatorOptions, stateStore?: StateStore<T>);
/**
* Executes the Saga
* @param initialData Initial data for the Saga
*/
execute(initialData?: Partial<T>): Promise<SagaContext<T>>;
/**
* Structures the initial data into the format:
* {
* global: initialData,
* steps: {}
* }
* @param initialData Initial data
*/
private structureInitialData;
/**
* Compensates the Saga (rolls back)
*/
compensate(): Promise<SagaContext<T>>;
/**
* Sets up event handlers for the coordinator
*/
private setupEventHandlers;
}