import type { BackpressureOptions } from "./backpressure.js"; import { type Task, type TaskStatus } from "./models.js"; import type { ListInput, PurgeInput, SubmitInput, TaskStore } from "./store/base.js"; import { type TaskDef } from "./task.js"; export type SubmitOptions = Omit; export interface CallOptions extends SubmitOptions { waitTimeoutMs?: number; pollMs?: number; } /** Options this handle configures on the store it wraps, rather than the * store's own constructor arguments. */ export type ClientOptions = Partial; /** API-side handle. Thin wrapper over a TaskStore + SDK-orchestrated wait/call. */ export declare class CairnQ { private readonly _store; constructor(_store: TaskStore, opts?: ClientOptions); static sqlite(path: string, opts?: { busyTimeoutMs?: number; } & ClientOptions): CairnQ; /** Multi-host backend. `dsn` is a libpq connection string; requires the * optional `pg` package. */ static postgres(dsn: string, opts?: { max?: number; } & ClientOptions): CairnQ; get store(): TaskStore; connect(): Promise; close(): Promise; /** Enqueue a task. With `maxQueueDepth` configured this blocks while the * target queue is at its limit, and raises QueueFull if it stays there for * `maxQueueWaitMs` — see QueueDepthGate for why that bound is approximate * across several producers. */ submit(name: string, payload?: unknown, opts?: SubmitOptions): Promise; submit(task: TaskDef, payload?: P, opts?: SubmitOptions): Promise; /** How many more tasks fit on `queue` under `maxDepth` — 0 once it is full. * The non-blocking read behind `maxQueueDepth`, for a producer that would * rather shed load or pick another queue than wait. Cheaper than `stats()`: * bounded at `maxDepth` index entries instead of aggregating the table. */ queueDepth(queue: string, maxDepth: number): Promise; get(taskId: string): Promise; getByKey(key: string): Promise; list(input?: ListInput): Promise; cancel(taskId: string): Promise; cancelByKey(key: string): Promise; retry(taskId: string, opts?: { resetAttempt?: boolean; }): Promise; retryByKey(key: string, opts?: { resetAttempt?: boolean; }): Promise; /** Delete terminal tasks that finished more than `olderThanMs` ago and return * their ids. Nothing else in CairnQ removes rows, so a long-lived database * needs this on a schedule. Each call is bounded by `limit` to keep the write * short; loop until it returns fewer than `limit`. */ purge(input?: PurgeInput): Promise; /** Task counts per queue, keyed by status and zero-filled across all statuses * — `(await stats()).default.queued` is the backlog of a queue. */ stats(): Promise>>; wait(taskId: string, opts?: { timeoutMs?: number; pollMs?: number; }): Promise; /** submit + wait. Resolves with the result on success; rejects with * TaskFailed / TaskCanceled / TaskTimeout otherwise. Pass a TaskDef and the * resolved value is typed as its Result. */ call(name: string, payload?: unknown, opts?: CallOptions): Promise; call(task: TaskDef, payload?: P, opts?: CallOptions): Promise; }