import * as pb from "../proto/orchestrator_service_pb"; import { OrchestrationStatus as ClientOrchestrationStatus } from "../orchestration/enum/orchestration-status.enum"; import { ParentOrchestrationInstance } from "../types/parent-orchestration-instance.type"; /** * Internal orchestration instance state stored by the in-memory backend. */ export interface OrchestrationInstance { instanceId: string; executionId: string; name: string; status: pb.OrchestrationStatus; input?: string; output?: string; customStatus?: string; createdAt: Date; lastUpdatedAt: Date; failureDetails?: pb.TaskFailureDetails; history: pb.HistoryEvent[]; pendingEvents: pb.HistoryEvent[]; completionToken: number; } /** * Activity work item that needs to be executed. */ export interface ActivityWorkItem { instanceId: string; name: string; taskId: number; input?: string; completionToken: number; } /** * In-memory backend for durable orchestrations suitable for testing. * * This backend stores all orchestration state in memory and processes * work items synchronously within the same process. It is designed for * unit testing and integration testing scenarios where a sidecar process * or external storage is not desired. * * Thread-safety: All state mutations are performed synchronously via * the event loop. The backend uses a simple work queue pattern to ensure * that orchestration and activity processing happens in a predictable order. */ export declare class InMemoryOrchestrationBackend { private readonly instances; private readonly orchestrationQueue; private readonly orchestrationQueueSet; private readonly activityQueue; private readonly stateWaiters; private readonly pendingTimers; private readonly instanceTimers; private nextCompletionToken; private readonly maxHistorySize; /** * Creates a new in-memory backend. * @param maxHistorySize Maximum number of history events per orchestration (default 10000) */ constructor(maxHistorySize?: number); /** * Creates a new orchestration instance. */ createInstance(instanceId: string, name: string, input?: string, scheduledStartTime?: Date, parentInstance?: ParentOrchestrationInstance): string; /** * Gets an orchestration instance by ID. */ getInstance(instanceId: string): OrchestrationInstance | undefined; /** * Raises an external event for an orchestration instance. */ raiseEvent(instanceId: string, eventName: string, input?: string): void; /** * Terminates an orchestration instance. */ terminate(instanceId: string, output?: string): void; /** * Suspends an orchestration instance. */ suspend(instanceId: string): void; /** * Resumes a suspended orchestration instance. */ resume(instanceId: string): void; /** * Purges an orchestration instance from the store. */ purge(instanceId: string): boolean; /** * Rewinds a failed orchestration instance. * * Validates the instance is in a failed state, then appends an ExecutionRewoundEvent to the * pending events, resets the status to RUNNING, and re-enqueues the orchestration so the * worker can replay it and produce a RewindOrchestrationAction with the corrected history. * The actual history rewrite is performed by the SDK worker (see buildRewindResult); this * backend merely applies the result. Any change to that rewrite must be mirrored here. * * @param instanceId The instance to rewind. * @param reason Optional human-readable reason for the rewind. * @throws Error with a "not found" message if the instance does not exist. * @throws Error with a "not in a failed state" message if the instance is not FAILED. */ rewindInstance(instanceId: string, reason?: string): void; /** * Gets the next orchestration work item to process, if any. */ getNextOrchestrationWorkItem(): OrchestrationInstance | undefined; /** * Gets the next activity work item to process, if any. */ getNextActivityWorkItem(): ActivityWorkItem | undefined; /** * Completes an orchestration execution with the given actions. */ completeOrchestration(instanceId: string, completionToken: number, actions: pb.OrchestratorAction[], customStatus?: string): void; /** * Completes an activity execution. */ completeActivity(instanceId: string, taskId: number, result?: string, error?: Error): void; /** * Waits for an orchestration to reach a state matching the predicate. */ waitForState(instanceId: string, predicate: (instance: OrchestrationInstance) => boolean, timeoutMs?: number): Promise; /** * Checks if there are any pending work items. */ hasPendingWork(): boolean; /** * Resets the backend, clearing all state. */ reset(): void; /** * Converts internal status to client status. */ toClientStatus(status: pb.OrchestrationStatus): ClientOrchestrationStatus; private enqueueOrchestration; private isTerminalStatus; private processAction; private processCompleteOrchestrationAction; private processScheduleTaskAction; private processCreateTimerAction; private processCreateSubOrchestrationAction; private watchSubOrchestration; private prepareRewind; private processRewindOrchestrationAction; private processSendEventAction; private addInstanceTimer; private removeInstanceTimer; private cancelInstanceTimers; private notifyWaiters; }