smart-saga-pattern
Version:
A library implementing the Saga pattern for microservice architecture
48 lines (47 loc) • 1.51 kB
TypeScript
import { CompensationFunction, TransactionStatus } from "../types";
/**
* Represents a compensation step in a Saga
*/
export declare class Compensation<TInput = any, TTransactionOutput = any> {
private id;
private name;
private status;
private action;
private error;
private transactionId;
/**
* Creates a new Compensation
* @param id Compensation ID
* @param name Compensation name
* @param transactionId ID of the transaction being compensated
* @param action Function to execute for this compensation
*/
constructor(id: string, name: string, transactionId: string, action: CompensationFunction<TInput, TTransactionOutput>);
/**
* Gets the ID of the compensation
*/
getId(): string;
/**
* Gets the name of the compensation
*/
getName(): string;
/**
* Gets the status of the compensation
*/
getStatus(): TransactionStatus;
/**
* Gets the error of the compensation if it failed
*/
getError(): Error | null;
/**
* Executes the compensation
* @param context Context to pass to the compensation function
* @param transactionOutput Output from the transaction being compensated
* @param transactionName Name of the transaction being compensated
*/
execute(context: TInput, transactionOutput?: TTransactionOutput, transactionName?: string): Promise<void>;
/**
* Resets the compensation to its initial state
*/
reset(): void;
}