smart-saga-pattern
Version:
A library implementing the Saga pattern for microservice architecture
49 lines (48 loc) • 1.46 kB
TypeScript
import { Saga } from "../core/Saga";
import { SagaDefinition } from "./SagaDefinition";
import { SagaContext, SagaOptions, StateStore } from "../types";
/**
* Orchestrator for executing Sagas with structured context
* The context is structured as:
* {
* global: { ... },
* steps: {
* "Step Name": {
* input: { ... },
* output: { ... },
* compensation: { ... }
* }
* }
* }
* @template T Type of the input data
* @template R Type of the result data
*/
export declare class StructuredSagaOrchestrator<T = Record<string, any>, R = Record<string, any>> extends Saga<T & R> {
private definition;
private stateStore?;
/**
* Creates a new StructuredSagaOrchestrator
* @param definition Saga definition to orchestrate
* @param options Saga options
* @param stateStore Optional state store for persistence
*/
constructor(definition: SagaDefinition<T>, options?: SagaOptions, stateStore?: StateStore<T & R>);
/**
* Executes the Saga
* @param initialData Initial data for the Saga
*/
execute(initialData?: Partial<T>): Promise<SagaContext<T & R>>;
/**
* 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 & R>>;
}