UNPKG

smart-saga-pattern

Version:

A library implementing the Saga pattern for microservice architecture

42 lines (41 loc) 1.27 kB
import { Saga } from '../core/Saga'; import { SagaParticipant } from './SagaParticipant'; import { SagaContext, SagaOptions, StateStore } from '../types'; /** * Options for a SagaCoordinator */ export interface SagaCoordinatorOptions extends SagaOptions { name: string; subscribeTopic: string; publishTopic: string; } /** * Coordinates a choreography-based Saga */ export declare class SagaCoordinator extends Saga { private participant; private stateStore?; private completionPromise?; private completionResolve?; private completionReject?; /** * Creates a new SagaCoordinator * @param participant Saga participant for communication * @param options Options for the coordinator * @param stateStore Optional state store for persistence */ constructor(participant: SagaParticipant, options: SagaCoordinatorOptions, stateStore?: StateStore); /** * Executes the Saga * @param initialData Initial data for the Saga */ execute(initialData?: Record<string, any>): Promise<SagaContext>; /** * Compensates the Saga (rolls back) */ compensate(): Promise<SagaContext>; /** * Sets up event handlers for the coordinator */ private setupEventHandlers; }