/** * Core types and interfaces for Atomic API Operations * Based on the Saga pattern and distributed transaction principles */ export interface IdempotencyKey { key: string; expiresAt: Date; } export interface TransactionStep { id: string; name: string; action: (input: TInput) => Promise; compensation?: (input: TInput, output?: TOutput) => Promise; retryPolicy?: RetryPolicy; timeout?: number; } export interface RetryPolicy { maxAttempts: number; backoffMs: number; backoffMultiplier: number; } export interface SagaDefinition { id: string; name: string; steps: TransactionStep[]; context?: TContext; onSuccess?: (context: TContext) => Promise; onFailure?: (context: TContext, error: Error) => Promise; } export interface SagaExecution { id: string; sagaId: string; status: SagaStatus; currentStep?: number; context: any; startedAt: Date; completedAt?: Date; error?: Error; stepResults: StepResult[]; } export type SagaStatus = 'PENDING' | 'RUNNING' | 'COMPLETED' | 'FAILED' | 'COMPENSATING' | 'COMPENSATED'; export interface StepResult { stepId: string; stepName: string; status: 'SUCCESS' | 'FAILED' | 'COMPENSATED'; input?: any; output?: any; error?: Error; startedAt: Date; completedAt?: Date; attempts: number; } export interface OutboxEvent { id: string; sagaId: string; stepId: string; eventType: string; payload: any; status: 'PENDING' | 'PUBLISHED' | 'FAILED'; createdAt: Date; publishedAt?: Date; retryCount: number; } export interface IdempotencyStore { get(key: string): Promise; set(key: string, expiresAt: Date): Promise; delete(key: string): Promise; } export interface SagaStore { saveExecution(execution: SagaExecution): Promise; getExecution(id: string): Promise; updateExecution(execution: SagaExecution): Promise; listExecutions(sagaId?: string, status?: SagaStatus): Promise; } export interface OutboxStore { saveEvent(event: OutboxEvent): Promise; getPendingEvents(): Promise; markEventPublished(id: string): Promise; markEventFailed(id: string, error: string): Promise; deleteEvent(id: string): Promise; } export interface MessageBroker { publish(topic: string, message: any): Promise; subscribe(topic: string, handler: (message: any) => Promise): Promise; unsubscribe(topic: string): Promise; } export interface Logger { info(message: string, meta?: any): void; error(message: string, error?: Error, meta?: any): void; warn(message: string, meta?: any): void; debug(message: string, meta?: any): void; } export interface AtomicApiConfig { idempotencyStore: IdempotencyStore; sagaStore: SagaStore; outboxStore?: OutboxStore; messageBroker?: MessageBroker; logger?: Logger; defaultRetryPolicy?: RetryPolicy; defaultTimeout?: number; } export interface IdempotentRequest { idempotencyKey: string; method: string; path: string; body?: any; headers?: Record; } export interface IdempotentResponse { idempotencyKey: string; statusCode: number; body: any; headers: Record; } //# sourceMappingURL=index.d.ts.map