import type { ApprovalDecision, Checkpoint, RunFilter, WorkflowQueueItem, WorkflowRun } from "../types.js"; import { type BackendConfig, type PersistedPendingApproval, type PersistedPendingEventWait, type RunEventDeliveryClaim, type RunEventEnvelope, type WorkflowBackend, type WorkflowRunObservation, type WorkflowRunStateSnapshot, type WorkflowRunUpdate } from "./types.js"; /** * Memory backend configuration */ interface MemoryBackendConfig extends BackendConfig { /** Maximum queue size (default: 10000) */ maxQueueSize?: number; } /** Implement memory backend. */ export declare class MemoryBackend implements WorkflowBackend { /** updateRun patches merge context and node-state maps by key. */ readonly supportsRunPatchKeyMerge = true; private runs; private checkpoints; private approvals; private eventWaits; private runEvents; private nextRunEventPublicationOrder; private runEventClaims; private queue; private locks; private stalledClaims; private runRevisions; private runObservers; private config; constructor(config?: MemoryBackendConfig); createRun(run: WorkflowRun): Promise; getRun(runId: string): Promise; updateRun(runId: string, patch: WorkflowRunUpdate): Promise; updateRunIfStatus(runId: string, expectedStatuses: WorkflowRun["status"][], patch: Partial): Promise; updateRunIfStatusAndWorker(runId: string, expectedStatuses: WorkflowRun["status"][], expectedWorkerId: string, patch: Partial): Promise; restoreRunStateIfStatus(runId: string, expectedStatuses: WorkflowRun["status"][], snapshot: WorkflowRunStateSnapshot, expectedWorkerId?: string): Promise; deleteRun(runId: string): Promise; openRunObservation(runId: string, options?: { signal?: AbortSignal; }): Promise; private publishRunObservation; private closeRunObservers; listRuns(filter: RunFilter): Promise; countRuns(filter: RunFilter): Promise; saveCheckpoint(runId: string, checkpoint: Checkpoint): Promise; saveCheckpointIfStatusAndWorker(storageRunId: string, ownershipRunId: string, expectedStatuses: WorkflowRun["status"][], expectedWorkerId: string, checkpoint: Checkpoint): Promise; getLatestCheckpoint(runId: string): Promise; getCheckpoints(runId: string): Promise; deleteCheckpoint(runId: string, checkpointId: string): Promise; deleteCheckpoints(runId: string, checkpointIds: string[]): Promise; savePendingApproval(runId: string, approval: PersistedPendingApproval): Promise; savePendingApprovalIfAbsent(runId: string, approval: PersistedPendingApproval): Promise; savePendingApprovalIfStatusAndWorker(runId: string, expectedStatuses: WorkflowRun["status"][], expectedWorkerId: string, approval: PersistedPendingApproval): Promise; updatePendingApproval(runId: string, approvalId: string, patch: Partial): Promise; getPendingApprovals(runId: string): Promise; getPendingApproval(runId: string, approvalId: string): Promise; updateApproval(runId: string, approvalId: string, decision: ApprovalDecision): Promise; listApprovalDecisionClaims(runId?: string): Promise>; reserveApprovalDecisionClaim(runId: string, approvalId: string, recoveryClaimId: string, claimedAt: Date, staleBefore: Date): Promise; releaseApprovalDecisionClaim(runId: string, approvalId: string, recoveryClaimId: string): Promise; finalizeApprovalDecision(runId: string, approvalId: string, recoveryClaimId?: string): Promise; listPendingApprovals(filter?: { workflowId?: string; approver?: string; status?: "pending" | "expired"; }): Promise>; savePendingEventWait(runId: string, wait: PersistedPendingEventWait): Promise; savePendingEventWaitIfStatusAndWorker(runId: string, expectedStatuses: WorkflowRun["status"][], expectedWorkerId: string, wait: PersistedPendingEventWait): Promise; getPendingEventWaits(runId: string): Promise; listPendingEventWaits(): Promise>; resolvePendingEventWait(runId: string, waitId: string, status: "delivered" | "expired" | "cancelled"): Promise; restorePendingEventWait(runId: string, waitId: string): Promise; listTimedEventWaitClaims(runId?: string): Promise; reserveTimedEventWaitClaim(runId: string, waitId: string, claimedAt: Date, staleBefore: Date): Promise; finalizeTimedEventWaitClaim(runId: string, waitId: string): Promise; appendRunEvent(runId: string, event: RunEventEnvelope): Promise; removeRunEvent(runId: string, eventId: string): Promise; /** * Drop the oldest mailboxes that no wait can ever claim from again, once the * mailbox count is over its bound. Publishing to a run id before the run * exists is supported, so a caller publishing to ids that never become runs * would otherwise accumulate mailboxes forever, and a run that reached a * completed or cancelled will never park on anything again, so its buffered * events are equally unclaimable. Failed runs remain retryable and retain * their mail just like active runs. */ private evictOrphanRunEventMailboxes; takeRunEvent(runId: string, eventName: string): Promise; peekRunEvent(runId: string, eventName: string): Promise; /** Claim the oldest matching event and its pending wait as one synchronous mutation. */ claimRunEventForWait(runId: string, waitId: string, eventName: string, publishedBefore?: Date): Promise; listRunEventDeliveryClaims(runId?: string): Promise; reserveRunEventDeliveryClaim(runId: string, waitId: string, eventId: string, claimedAt: Date, staleBefore: Date): Promise; restoreRunEvent(runId: string, event: RunEventEnvelope): Promise; /** * Undo a claimed-but-undelivered delivery: the wait returns to pending and * the event to its publication-order mailbox position as one step. * * Every mutation is one synchronous in-memory state transition, so callers * cannot observe the restored wait before its event returns to the mailbox. * A durable backend must implement this as a single atomic operation (a * transaction or script) instead. */ restoreRunEventDelivery(runId: string, waitId: string, event: RunEventEnvelope): Promise; finalizeRunEventDelivery(runId: string, eventId: string, delivered: boolean): Promise; hasRunEventDeliveryReceipt(runId: string, eventId: string): Promise; private persistRunEventDeliveryReceipts; private releaseRunEventClaim; private deleteEmptyRunEventMailbox; enqueue(job: WorkflowQueueItem): Promise; dequeue(): Promise; acknowledge(runId: string): Promise; nack(runId: string): Promise; acquireLock(runId: string, duration: number): Promise; releaseLock(runId: string, lockId?: string): Promise; extendLock(runId: string, duration: number, lockId?: string): Promise; isLocked(runId: string): Promise; findStalledRuns(stalledThreshold: number): Promise; claimStalledRun(runId: string, workerId: string, stalledThreshold: number): Promise; initialize(): Promise; healthCheck(): Promise; destroy(): Promise; getStats(): { runs: number; checkpoints: number; approvals: number; queueLength: number; locks: number; }; clear(): Promise; } export {}; //# sourceMappingURL=memory.d.ts.map