UNPKG

smart-saga-pattern

Version:

A library implementing the Saga pattern for microservice architecture

82 lines (81 loc) 2.08 kB
import "reflect-metadata"; export declare const SAGA_STEP_METADATA = "saga:step"; export declare const INVOKE_METADATA = "saga:invoke"; export declare const COMPENSATION_METADATA = "saga:compensation"; /** * Options for the SagaStep decorator */ export interface SagaStepOptions { /** * Order of the step in the saga * Lower numbers execute first * @default 0 */ order?: number; /** * Whether this step requires compensation in case of failure * @default true */ requiresCompensation?: boolean; /** * Description of the step */ description?: string; } /** * Decorator to mark a class as a Saga step * @param options Options for the step */ export declare function SagaStepDecorator(options?: SagaStepOptions): ClassDecorator; /** * Options for the Invoke decorator */ export interface InvokeOptions { /** * Description of the invoke method */ description?: string; } /** * Decorator to mark a method as the invoke function for a Saga step * @param options Options for the invoke method */ export declare function Invoke(options?: InvokeOptions): any; /** * Options for the Compensation decorator */ export interface CompensationOptions { /** * Description of the compensation method */ description?: string; } /** * Decorator to mark a method as the compensation function for a Saga step * @param options Options for the compensation method */ export declare function CompensationDecorator(options?: CompensationOptions): any; /** * Container for Saga steps */ export declare class SagaStepContainer { private static steps; /** * Registers a step with the container * @param stepClass Step class to register */ static registerStep(stepClass: any): void; /** * Gets a step by name * @param name Name of the step */ static getStep(name: string): any; /** * Gets all registered steps */ static getAllSteps(): any[]; /** * Clears all registered steps */ static clear(): void; }