smart-saga-pattern
Version:
A library implementing the Saga pattern for microservice architecture
50 lines (49 loc) • 1.35 kB
TypeScript
import { TransactionFunction, TransactionStatus } from "../types";
/**
* Represents a transaction step in a Saga
*/
export declare class Transaction<T = any, R = any> {
private id;
private name;
private status;
private action;
private result;
private error;
/**
* Creates a new Transaction
* @param id Transaction ID
* @param name Transaction name
* @param action Function to execute for this transaction
*/
constructor(id: string, name: string, action: TransactionFunction<T, R>);
/**
* Gets the ID of the transaction
*/
getId(): string;
/**
* Gets the name of the transaction
*/
getName(): string;
/**
* Gets the status of the transaction
*/
getStatus(): TransactionStatus;
/**
* Gets the result of the transaction
*/
getResult(): R | null;
/**
* Gets the error of the transaction if it failed
*/
getError(): Error | null;
/**
* Executes the transaction
* @param context Context to pass to the transaction function
* @param requiresCompensation Whether this transaction requires compensation in case of failure
*/
execute(context: T, requiresCompensation?: boolean): Promise<R>;
/**
* Resets the transaction to its initial state
*/
reset(): void;
}