UNPKG

smart-saga-pattern

Version:

A library implementing the Saga pattern for microservice architecture

57 lines (56 loc) 1.45 kB
import { SagaDefinition } from "./SagaDefinition"; import { SagaContext } from "../types"; /** * Executes a Saga definition 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 StructuredSagaExecutor<T = any, R = any> { private definition; private context; private currentStepIndex; /** * Creates a new StructuredSagaExecutor * @param definition Saga definition to execute * @param context Initial Saga context */ constructor(definition: SagaDefinition<T, R>, context: SagaContext<T & R>); /** * Checks if the context has a steps object */ private hasStepsObject; /** * Initializes the steps object in the context */ private initializeStepsObject; /** * Executes the Saga */ execute(): Promise<SagaContext<T & R>>; /** * Initializes step data in the context * @param stepName Name of the step */ private initializeStepData; /** * Updates step output in the context * @param stepName Name of the step * @param output Output data */ private updateStepOutput; /** * Compensates the Saga */ private compensate; }