import { p as StorageAdapter, f as FlowState, A as AcquireLockOptions, h as Lock } from '../types-D8r3B8Ax.js'; /** * Structural subset of `pg.Pool` — we only need `query` and `connect`. * Import `Pool` from `pg` and pass an instance; avoids a hard dep on `pg`. */ interface PgPoolLike { query(text: string, values?: readonly unknown[]): Promise<{ rows: R[]; }>; connect(): Promise; } interface PgClientLike { query(text: string, values?: readonly unknown[]): Promise<{ rows: R[]; }>; release(err?: unknown): void; } interface PostgresStorageOptions { pool: PgPoolLike; /** Table name for flow state. Default: `kompensa_states`. */ tableName?: string; /** * Identifier used to namespace Postgres advisory locks, avoiding collision * with locks used by other subsystems. Default: `kompensa`. */ lockNamespace?: string; /** Polling interval while waiting for a contested lock, in ms. Default: 50. */ lockPollMs?: number; } /** * Durable Postgres-backed storage. Uses JSONB for state and session-level * advisory locks for multi-worker safety. * * Locks automatically release when the holding connection closes — so worker * crashes don't permanently wedge an idempotency key. Advisory locks do not * have a server-side TTL; the `ttlMs` option is advisory only and ignored. * * @example * import { Pool } from 'pg'; * import { PostgresStorage } from 'kompensa/storage/postgres'; * * const storage = new PostgresStorage({ * pool: new Pool({ connectionString: process.env.DATABASE_URL }), * }); * await storage.ensureSchema(); * * const flow = createFlow('checkout', { storage }).step(...) */ declare class PostgresStorage implements StorageAdapter { private readonly pool; private readonly tableName; private readonly lockNamespace; private readonly lockPollMs; constructor(opts: PostgresStorageOptions); load(flowName: string, flowId: string): Promise; save(state: FlowState): Promise; delete(flowName: string, flowId: string): Promise; acquireLock(flowName: string, flowId: string, options: AcquireLockOptions): Promise; private tryLock; private makeLock; /** * Create the state table if it doesn't exist. Safe to call repeatedly. * Use this once at startup or migrate via your preferred migration tool * using the SQL in `kompensa/storage/postgres/schema.sql`. */ ensureSchema(): Promise; } declare function createPostgresStorage(opts: PostgresStorageOptions): PostgresStorage; export { type PgClientLike, type PgPoolLike, PostgresStorage, type PostgresStorageOptions, createPostgresStorage };