import { E as EmailOptions, a as EmailResult, R as Result } from "../packem_shared/types.d-CyiC9uRC.js"; import { E as EnqueueOptions, Q as QueueJob, a as EmailQueue } from "../packem_shared/types.d-B5iH_mgb.js"; export { UnstorageQueue, type UnstorageQueueOptions, createUnstorageQueue } from "./unstorage-queue.js"; import 'node:buffer'; /** * Options for {@link MemoryQueue}. */ interface MemoryQueueOptions { /** * Time source in milliseconds — injectable for tests. Defaults to `Date.now`. */ now?: () => number; /** * How long, in milliseconds, a reserved job stays hidden before it becomes deliverable again * (in case the worker crashed mid-process). * @default 30000 */ visibilityTimeout?: number; } /** * An in-memory {@link EmailQueue} with `scheduledAt` support and a reservation visibility timeout. * * Suitable for tests, single-process apps, and as a reference for adapter authors. Jobs do not survive * a process restart — use a durable adapter in production. */ declare class MemoryQueue implements EmailQueue { private readonly jobs; private readonly visibilityTimeout; private readonly now; private sequence; /** * @param options Queue options. See {@link MemoryQueueOptions}. */ constructor(options?: MemoryQueueOptions); /** * Adds a message to the queue. * @param message The message to send later. * @param options Optional scheduling. See {@link EnqueueOptions}. * @returns The new job id. */ enqueue(message: EmailOptions, options?: EnqueueOptions): string; /** * Reserves the next ready job, hiding it for the visibility window. * @returns The next deliverable job, or `undefined` when none is ready. */ reserve(): QueueJob | undefined; /** * Marks a reserved job as processed and removes it. * @param id The job id. */ ack(id: string): void; /** * Returns a job to the queue after a delay, incrementing its attempt count. * @param id The job id. * @param delayMs Milliseconds to wait before the job becomes ready again. */ retry(id: string, delayMs?: number): void; /** * Reports how many jobs remain (ready plus reserved). * @returns The count of ready and reserved jobs. */ size(): number; } /** * Options for {@link createWorker}. */ interface WorkerOptions { /** * Retry backoff: returns the delay (ms) before re-attempting after `attempts` failures. * @default attempts => 1000 * 2 ** (attempts - 1) */ backoff?: (attempts: number) => number; /** * How many jobs to process concurrently. * @default 1 */ concurrency?: number; /** * Maximum delivery attempts before a job is dead-lettered. A failure whose error is flagged * `permanent` is dead-lettered on its first attempt regardless of this limit. * @default 3 */ maxAttempts?: number; /** * Called when a job exhausts its attempts and is dropped. * @param job The dead-lettered job. * @param result The final failed result. */ onDeadLetter?: (job: QueueJob, result: Result) => void; /** * Called on every failed attempt (before any retry). * @param job The job that failed. * @param result The failed result (or thrown error wrapped). */ onError?: (job: QueueJob, result: Result) => void; /** * Called when `queue.reserve()` itself rejects (e.g. a transient store error). The poll loop keeps * running regardless; this hook just surfaces the failure. * @param error The reserve error. */ onReserveError?: (error: Error) => void; /** * Idle poll interval, in milliseconds, when no job is ready. * @default 1000 */ pollInterval?: number; /** * The queue to consume. */ queue: EmailQueue; /** * The send function — typically `mail.send.bind(mail)`. */ send: (message: EmailOptions) => Promise>; } /** * A running queue worker. */ interface Worker { /** * Processes ready jobs until the queue has none currently deliverable, then resolves. * * Does not wait for future-scheduled jobs. Useful in tests and one-shot drains. */ drain: () => Promise; /** * Begins polling and processing jobs in the background. */ start: () => void; /** * Stops polling. In-flight jobs are allowed to finish. */ stop: () => void; } /** * Creates a worker that durably processes queued messages with bounded concurrency, retry/backoff, and * dead-lettering. * @param options Worker configuration. See {@link WorkerOptions}. * @returns The worker handle. See {@link Worker}. * @example * ```ts * const queue = new MemoryQueue(); * const worker = createWorker({ queue, send: mail.send.bind(mail), concurrency: 5 }); * worker.start(); * ``` */ declare const createWorker: (options: WorkerOptions) => Worker; export { type EmailQueue, type EnqueueOptions, MemoryQueue, type MemoryQueueOptions, type QueueJob, type Worker, type WorkerOptions, createWorker };