import { type Generated, type Insertable, type Selectable } from 'kysely'; import type * as Webhooks from '../../internal/Webhooks.js'; import type * as Db from '../Db.js'; import * as WebhookQueueCompletions from './webhookQueueCompletions.js'; import type * as db_Schema from '../Schema.js'; /** Columns of the `webhook_queue_events` table, derived from `Schema.WebhookQueueEvent`. */ export type Table = Omit & { /** Delivery attempts claimed so far; database default 0. */ attemptCount: Generated; /** ISO timestamp of the current claim; database default null. */ attemptingAt: Generated; /** Legacy dedupe deadline; unwritten since completions took over. */ expiresAt: Generated; /** ISO retry due time; database default null (due immediately). */ nextAttemptAt: Generated; /** ISO head-observation stamp; database default null (replays carry none). */ observedAt: Generated; /** Delivery-obligation lifecycle status; database default `pending`. */ status: Generated; }; /** A stored webhook Queue event. */ export type Record = Selectable; /** * Reads one pending envelope. The status filter only ever excludes rows * completed before the completions split; completions now leave the table. */ export declare function get(db: Db.Db, reference: Webhooks.QueueReference): Promise; /** * Stages envelopes as fresh obligations. Unexpired completions and any * existing row suppress the replay; a replay stages only when neither exists, * which a completion past its dedupe window guarantees for completed work. */ export declare function ensure(db: Db.Db, rows: readonly Insertable
[]): Promise; /** Claims one due pending obligation with a single atomic update. */ export declare function claim(db: Db.Db, reference: Webhooks.QueueReference, options: claim.Options): Promise; export declare namespace claim { /** Claim clock bounds. */ type Options = { /** Current ISO timestamp; becomes the claim marker. */ now: string; /** ISO cutoff below which an existing claim counts as stale. */ staleBefore: string; }; /** Atomic claim outcome. */ type Result = { type: 'attempting'; } | { record: Record; type: 'claimed'; } | { type: 'missing'; } | { nextAttemptAt: string | null; type: 'scheduled'; } | { status: WebhookQueueCompletions.TerminalStatus; type: 'terminal'; }; } /** * Marks a claimed obligation terminal: one atomic statement deletes the queue * row and writes the insert-only completion that starts the dedupe window. * The `attemptingAt` predicate fences stale claimants. */ export declare function complete(db: Db.Db, reference: Webhooks.QueueReference, options: complete.Options): Promise; export declare namespace complete { /** Fenced terminal transition. */ type Options = { /** Claim marker returned by {@link claim}; fences stale claimants. */ claimedAt: string; /** ISO retention deadline for the dedupe completion. */ expiresAt: string; /** Terminal outcome. */ status: WebhookQueueCompletions.TerminalStatus; }; } /** Releases a claim and schedules the next attempt; fenced like {@link complete}. */ export declare function schedule(db: Db.Db, reference: Webhooks.QueueReference, options: schedule.Options): Promise; export declare namespace schedule { /** Fenced retry scheduling. */ type Options = { /** Claim marker returned by {@link claim}; fences stale claimants. */ claimedAt: string; /** ISO due time of the next attempt. */ nextAttemptAt: string; }; } /** Lists due pending references for the sweeper, most overdue first. */ export declare function due(db: Db.Db, options: due.Options): Promise; export declare namespace due { /** Sweep bounds. */ type Options = { /** Maximum references to return. */ limit: number; /** Current ISO timestamp. */ now: string; /** ISO cutoff below which an existing claim counts as stale. */ staleBefore: string; }; } /** Returns the pending-obligation snapshot, split by due-and-unclaimed work. */ export declare function pending(db: Db.Db, options: pending.Options): Promise; export declare namespace pending { /** Snapshot clock bounds; the read-only subset of {@link claim.Options}. */ type Options = Pick; /** Pending-work snapshot. */ type Result = { /** Pending obligations, including in-flight claims and scheduled retries. */ count: number; /** Obligations due now with no live claim; the sweeper's backlog. */ dueCount: number; /** Oldest pending staging timestamp, or null when none. */ oldestAt: string | null; /** Oldest due-and-unclaimed retry time, or null when none; drives the stall alert. */ oldestDueAt: string | null; }; } //# sourceMappingURL=webhookQueueEvents.d.ts.map