import "@js-temporal/polyfill";
import "urlpattern-polyfill";
globalThis.addEventListener = () => {};
import { getLogger } from "@logtape/logtape";
import "es-toolkit";
//#region src/x/denokv.ts
/**
* `KvStore` & `MessageQueue` adapters for Deno's KV store
* =======================================================
*
* This module provides `KvStore` and `MessageQueue` implementations that use
* Deno's KV store.  The `DenoKvStore` class implements the `KvStore` interface
* using Deno's KV store, and the `DenoKvMessageQueue` class implements the
* `MessageQueue` interface using Deno's KV store.
*
* @deprecated This module has been moved to a separate package.
*             Install and import from `@fedify/denokv` instead.
*             This module will be removed in Fedify v2.0.
*
* @module
* @since 0.5.0
*/
/**
* Represents a message queue adapter that uses Deno KV store.
*
* @deprecated This class has been moved to `@fedify/denokv` package.
*             Import `DenoKvMessageQueue` from `@fedify/denokv` instead.
*             This class will be removed in Fedify v2.0.
*/
var DenoKvMessageQueue = class {
	#kv;
	/**
	* Deno KV queues provide automatic retry with exponential backoff.
	* @since 1.7.0
	*/
	nativeRetrial = true;
	/**
	* Constructs a new {@link DenoKvMessageQueue} adapter with the given Deno KV
	* store.
	* @param kv The Deno KV store to use.
	*/
	constructor(kv) {
		getLogger(["fedify", "denokv"]).warn("The `@fedify/fedify/x/denokv` module is deprecated; use `DenoKvMessageQueue` from `@fedify/denokv` package instead.");
		this.#kv = kv;
	}
	async enqueue(message, options) {
		await this.#kv.enqueue(message, options?.delay == null ? void 0 : { delay: Math.max(options.delay.total("millisecond"), 0) });
	}
	listen(handler, options = {}) {
		options.signal?.addEventListener("abort", () => {
			try {
				this.#kv.close();
			} catch (e) {
				if (!(e instanceof Deno.errors.BadResource)) throw e;
			}
		}, { once: true });
		return this.#kv.listenQueue(handler);
	}
	[Symbol.dispose]() {
		try {
			this.#kv.close();
		} catch (e) {
			if (!(e instanceof Deno.errors.BadResource)) throw e;
		}
	}
};
//#endregion
export { DenoKvMessageQueue };
