import { E as EmailOptions } 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"; import 'node:buffer'; type StorageValue = null | string | number | boolean | object; type WatchEvent = "update" | "remove"; type WatchCallback = (event: WatchEvent, key: string) => any; type MaybePromise = T | Promise; type MaybeDefined = T extends any ? T : any; type Unwatch = () => MaybePromise; interface StorageMeta { atime?: Date; mtime?: Date; ttl?: number; [key: string]: StorageValue | Date | undefined; } type TransactionOptions = Record; type GetKeysOptions = TransactionOptions & { maxDepth?: number; }; interface DriverFlags { maxDepth?: boolean; ttl?: boolean; } interface Driver { name?: string; flags?: DriverFlags; options?: OptionsT; getInstance?: () => InstanceT; hasItem: (key: string, opts: TransactionOptions) => MaybePromise; getItem: (key: string, opts?: TransactionOptions) => MaybePromise; /** @experimental */ getItems?: (items: { key: string; options?: TransactionOptions; }[], commonOptions?: TransactionOptions) => MaybePromise<{ key: string; value: StorageValue; }[]>; /** @experimental */ getItemRaw?: (key: string, opts: TransactionOptions) => MaybePromise; setItem?: (key: string, value: string, opts: TransactionOptions) => MaybePromise; /** @experimental */ setItems?: (items: { key: string; value: string; options?: TransactionOptions; }[], commonOptions?: TransactionOptions) => MaybePromise; /** @experimental */ setItemRaw?: (key: string, value: any, opts: TransactionOptions) => MaybePromise; removeItem?: (key: string, opts: TransactionOptions) => MaybePromise; getMeta?: (key: string, opts: TransactionOptions) => MaybePromise; getKeys: (base: string, opts: GetKeysOptions) => MaybePromise; clear?: (base: string, opts: TransactionOptions) => MaybePromise; dispose?: () => MaybePromise; watch?: (callback: WatchCallback) => MaybePromise; } type StorageDefinition = { items: unknown; [key: string]: unknown; }; type StorageItemMap = T extends StorageDefinition ? T["items"] : T; type StorageItemType = K extends keyof StorageItemMap ? StorageItemMap[K] : T extends StorageDefinition ? StorageValue : T; interface Storage { hasItem, K extends keyof StorageItemMap>(key: K, opts?: TransactionOptions): Promise; hasItem(key: string, opts?: TransactionOptions): Promise; getItem, K extends string & keyof StorageItemMap>(key: K, ops?: TransactionOptions): Promise | null>; getItem>(key: string, opts?: TransactionOptions): Promise; /** @experimental */ getItems: (items: (string | { key: string; options?: TransactionOptions; })[], commonOptions?: TransactionOptions) => Promise<{ key: string; value: U; }[]>; /** @experimental See https://github.com/unjs/unstorage/issues/142 */ getItemRaw: (key: string, opts?: TransactionOptions) => Promise | null>; setItem, K extends keyof StorageItemMap>(key: K, value: StorageItemType, opts?: TransactionOptions): Promise; setItem(key: string, value: U, opts?: TransactionOptions): Promise; /** @experimental */ setItems: (items: { key: string; value: U; options?: TransactionOptions; }[], commonOptions?: TransactionOptions) => Promise; /** @experimental See https://github.com/unjs/unstorage/issues/142 */ setItemRaw: (key: string, value: MaybeDefined, opts?: TransactionOptions) => Promise; removeItem, K extends keyof StorageItemMap>(key: K, opts?: (TransactionOptions & { removeMeta?: boolean; }) | boolean): Promise; removeItem(key: string, opts?: (TransactionOptions & { removeMeta?: boolean; }) | boolean): Promise; getMeta: (key: string, opts?: (TransactionOptions & { nativeOnly?: boolean; }) | boolean) => MaybePromise; setMeta: (key: string, value: StorageMeta, opts?: TransactionOptions) => Promise; removeMeta: (key: string, opts?: TransactionOptions) => Promise; getKeys: (base?: string, opts?: GetKeysOptions) => Promise; clear: (base?: string, opts?: TransactionOptions) => Promise; dispose: () => Promise; watch: (callback: WatchCallback) => Promise; unwatch: () => Promise; mount: (base: string, driver: Driver) => Storage; unmount: (base: string, dispose?: boolean) => Promise; getMount: (key?: string) => { base: string; driver: Driver; }; getMounts: (base?: string, options?: { parents?: boolean; }) => { base: string; driver: Driver; }[]; keys: Storage["getKeys"]; get: Storage["getItem"]; set: Storage["setItem"]; has: Storage["hasItem"]; del: Storage["removeItem"]; remove: Storage["removeItem"]; } /** * Options for {@link UnstorageQueue}. */ interface UnstorageQueueOptions { /** * Time source in milliseconds — injectable for tests. Defaults to `Date.now`. */ now?: () => number; /** * Key prefix under which jobs are stored. * @default "email:queue" */ prefix?: string; /** * How long, in milliseconds, a reserved job stays hidden before becoming deliverable again. * @default 30000 */ visibilityTimeout?: number; } /** * A durable {@link EmailQueue} backed by an [unstorage](https://unstorage.unjs.io/) `Storage`. * * Because unstorage abstracts many backends (memory, filesystem, Redis, Cloudflare KV, Postgres, …), * a single adapter persists the queue across all of them. The stored `message` must be * JSON-serializable (avoid `Buffer` attachments — pass `path`/`href`/base64 `content` instead). * * Note: unstorage has no transactions, so {@link UnstorageQueue.reserve} is best-effort under * concurrent workers; the visibility timeout bounds duplicate delivery on a crash. */ declare class UnstorageQueue implements EmailQueue { private readonly storage; private readonly prefix; private readonly visibilityTimeout; private readonly now; /** * @param storage The unstorage instance to persist jobs in. * @param options Adapter options. See {@link UnstorageQueueOptions}. */ constructor(storage: Storage, options?: UnstorageQueueOptions); /** * Persists a message to the store. * @param message The message to send later. * @param options Optional scheduling. See {@link EnqueueOptions}. * @returns The new job id. */ enqueue(message: EmailOptions, options?: EnqueueOptions): Promise; /** * Reserves the next ready job, hiding it for the visibility window. * @returns The next deliverable job, or `undefined` when none is ready. */ reserve(): Promise; /** * Removes a processed job from the store. * @param id The job id. */ ack(id: string): Promise; /** * Requeues a job 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): Promise; /** * Counts the jobs currently in the store. * @returns The number of stored (ready plus reserved) jobs. */ size(): Promise; private keyOf; } /** * Creates an {@link UnstorageQueue}. * @param storage The unstorage instance to persist jobs in. * @param options Adapter options. See {@link UnstorageQueueOptions}. * @returns A new {@link UnstorageQueue}. */ declare const createUnstorageQueue: (storage: Storage, options?: UnstorageQueueOptions) => UnstorageQueue; export { UnstorageQueue, UnstorageQueueOptions, createUnstorageQueue };