/** * Types for Idempotency Pattern */ import { AsyncFunction, Logger } from "./common"; /** * Idempotency record status */ export declare enum IdempotencyStatus { /** * Operation in progress */ IN_PROGRESS = "IN_PROGRESS", /** * Operation completed successfully */ COMPLETED = "COMPLETED", /** * Operation failed */ FAILED = "FAILED" } /** * Concurrent request behavior */ export declare enum ConcurrentBehavior { /** * Wait for the concurrent request to complete */ WAIT = "WAIT", /** * Immediately reject concurrent request */ REJECT = "REJECT" } /** * Idempotency record */ export interface IdempotencyRecord { /** * Idempotency key */ key: string; /** * Operation result */ result: T; /** * Creation timestamp */ createdAt: number; /** * Expiration timestamp */ expiresAt: number; /** * Status */ status: IdempotencyStatus; /** * Error (if failed) */ error?: Error; /** * Number of cache hits */ hitCount: number; } /** * Interface for custom idempotency store */ export interface IdempotencyStore { getRecord(key: string): Promise | null>; set(key: string, record: IdempotencyRecord): Promise; delete(key: string): Promise; clear(): Promise; } /** * Options for idempotency pattern */ export interface IdempotencyOptions { /** * Function to execute with idempotency */ execute: AsyncFunction; /** * Idempotency key (if not provided, uses keyGenerator) */ key?: string; /** * Function to generate idempotency key * Default: generates random key (not recommended for production) */ keyGenerator?: () => string; /** * Cache TTL in milliseconds * @default 3600000 (1 hour) */ ttl?: number; /** * Custom store for persistence */ store?: IdempotencyStore; /** * Logger */ logger?: Logger; /** * Behavior for concurrent requests * @default ConcurrentBehavior.WAIT */ concurrentBehavior?: ConcurrentBehavior; /** * Timeout for waiting on concurrent request (ms) * @default 30000 */ waitTimeout?: number; /** * Callback on cache hit */ onCacheHit?: (key: string) => void; /** * Callback on cache miss */ onCacheMiss?: (key: string) => void; } /** * In-memory store implementation using GlobalStorage */ export declare class InMemoryStore implements IdempotencyStore { private storage; private readonly namespace; constructor(); getRecord(key: string): Promise | null>; set(key: string, record: IdempotencyRecord): Promise; delete(key: string): Promise; clear(): Promise; /** * Start automatic cleanup of expired entries */ startCleanup(_intervalMs?: number): void; /** * Stop automatic cleanup */ stopCleanup(): void; } /** * Default key generator (simple hash) */ export declare function defaultKeyGenerator(...args: any[]): string; //# sourceMappingURL=idempotency.d.ts.map