/** * FeltDB Execution API * * Event-driven execution runtime for triggering capabilities based on * operations or scheduled events. */ import type { StateFirstDB } from './db.js'; /** * Execution status */ export declare enum ExecutionStatus { Pending = "Pending", Running = "Running", Succeeded = "Succeeded", Failed = "Failed", RetryScheduled = "RetryScheduled", DeadLettered = "DeadLettered" } /** * Retry policy for execution */ export interface RetryPolicy { /** Maximum number of retry attempts */ maxAttempts: number; /** Initial backoff in milliseconds */ initialBackoffMs: number; /** Maximum backoff in milliseconds */ maxBackoffMs: number; /** Backoff multiplier for exponential backoff */ backoffMultiplier: number; /** Timeout per attempt in milliseconds */ timeoutMs: number; } /** * A durable execution record * Tracks the execution of a capability triggered by an operation */ export interface Execution { /** Unique execution identifier */ executionId: string; /** The trigger that caused this execution */ triggerId: string; /** Source operation that triggered this execution */ sourceOperation: { op_id: number; instance_id: string; sequence: number; op_type: 'Insert' | 'Update' | 'Delete'; key: string; value?: any; timestamp_ms: number; rust_type: string; capability: string; }; /** Capability to execute */ capability: string; /** Attempt number (1-based) */ attempt: number; /** Current status */ status: ExecutionStatus; /** Optional result value */ result?: any; /** Optional error message */ error?: string; /** Timestamp when execution was created */ created_ms: number; /** Timestamp when execution started */ started_ms?: number; /** Timestamp when execution completed */ completed_ms?: number; /** Claim token for single-owner execution semantics */ claimed_by?: string; /** Retry policy settings */ retry_policy: RetryPolicy; } /** * Capability-scoped execution runtime * Provides restricted execution context for a capability */ export interface ExecutionContext { /** Execution being performed */ execution: Execution; /** Database reference (scoped to capability permissions) */ db: StateFirstDB; /** Whether this is a retry attempt */ isRetry: boolean; /** Attempt number */ attempt: number; } /** * Execution handler function * Called when an execution event is triggered */ export type ExecutionHandler = (context: ExecutionContext) => Promise; /** * Execution manager for a StateFirstDB instance */ export interface ExecutionManager { /** * Register a handler for a capability * * @example * execManager.handle("process_order", async (ctx) => { * const { execution, db } = ctx; * // Execute capability logic * return { success: true }; * }); */ handle(capability: string, handler: ExecutionHandler): void; /** * Unregister a handler for a capability */ unhandle(capability: string): void; /** * Get pending executions for a capability */ getPending(capability?: string): Promise; /** * Get execution by ID */ get(executionId: string): Promise; /** * Get all executions */ all(): Promise; /** * Mark execution as running */ markRunning(executionId: string): Promise; /** * Mark execution as succeeded */ markSucceeded(executionId: string, result: any): Promise; /** * Mark execution as failed */ markFailed(executionId: string, error: string): Promise; /** * Schedule retry for a failed execution */ scheduleRetry(executionId: string): Promise; /** * Process all pending executions * Runs handlers for matched capabilities */ processPending(): Promise; } //# sourceMappingURL=execution.d.ts.map