import { Temporal } from "@js-temporal/polyfill";
import { URLPattern } from "urlpattern-polyfill";
import { HttpMessageSignaturesSpecDeterminer } from "./http-BbO0ejuk.js";
import { KvKey, KvStore } from "./kv-BKNZ-Tb-.js";
import { TracerProvider } from "@opentelemetry/api";
import { DocumentLoader, DocumentLoaderFactoryOptions } from "@fedify/vocab-runtime";

//#region src/utils/docloader.d.ts
/**
 * Options for {@link getAuthenticatedDocumentLoader}.
 * @see {@link getAuthenticatedDocumentLoader}
 * @since 1.3.0
 */
interface GetAuthenticatedDocumentLoaderOptions extends DocumentLoaderFactoryOptions {
  /**
   * An optional spec determiner for HTTP Message Signatures.
   * It determines the spec to use for signing requests.
   * It is used for double-knocking
   * (see <https://swicg.github.io/activitypub-http-signature/#how-to-upgrade-supported-versions>).
   * @since 1.6.0
   */
  specDeterminer?: HttpMessageSignaturesSpecDeterminer;
  /**
   * The OpenTelemetry tracer provider.  If omitted, the global tracer provider
   * is used.
   * @since 1.6.0
   */
  tracerProvider?: TracerProvider;
}
/**
 * Gets an authenticated {@link DocumentLoader} for the given identity.
 * Note that an authenticated document loader intentionally does not cache
 * the fetched documents.
 * @param identity The identity to get the document loader for.
 *                 The actor's key pair.
 * @param options The options for the document loader.
 * @returns The authenticated document loader.
 * @throws {TypeError} If the key is invalid or unsupported.
 * @since 0.4.0
 */
declare function getAuthenticatedDocumentLoader(identity: {
  keyId: URL;
  privateKey: CryptoKey;
}, {
  allowPrivateAddress,
  userAgent,
  specDeterminer,
  tracerProvider
}?: GetAuthenticatedDocumentLoaderOptions): DocumentLoader;
/**
 * A JSON-LD document loader that utilizes the browser's `fetch` API.
 *
 * This loader preloads the below frequently used contexts:
 *
 * - <https://www.w3.org/ns/activitystreams>
 * - <https://w3id.org/security/v1>
 * - <https://w3id.org/security/data-integrity/v1>
 * - <https://www.w3.org/ns/did/v1>
 * - <https://w3id.org/security/multikey/v1>
 * - <https://purl.archive.org/socialweb/webfinger>
 * - <http://schema.org/>
 * @param url The URL of the document to load.
 * @param allowPrivateAddress Whether to allow fetching private network
 *                            addresses.  Turned off by default.
 * @returns The remote document.
 * @deprecated Use {@link getDocumentLoader} instead.
 */
//#endregion
//#region src/utils/kv-cache.d.ts
/**
 * The parameters for {@link kvCache} function.
 */
interface KvCacheParameters {
  /**
   * The document loader to decorate with a cache.
   */
  loader: DocumentLoader;
  /**
   * The key–value store to use for backing the cache.
   */
  kv: KvStore;
  /**
   * The key prefix to use for namespacing the cache.
   * `["_fedify", "remoteDocument"]` by default.
   */
  prefix?: KvKey;
  /**
   * The per-URL cache rules in the array of `[urlPattern, duration]` pairs
   * where `urlPattern` is either a string, a {@link URL}, or
   * a {@link URLPattern} and `duration` is a {@link Temporal.DurationLike}.
   * The `duration` is allowed to be at most 30 days.
   *
   * By default, 5 minutes for all URLs.
   */
  rules?: [string | URL | URLPattern, Temporal.Duration | Temporal.DurationLike][];
}
/**
 * Decorates a {@link DocumentLoader} with a cache backed by a {@link Deno.Kv}.
 * @param parameters The parameters for the cache.
 * @returns The decorated document loader which is cache-enabled.
 */
declare function kvCache({
  loader,
  kv,
  prefix,
  rules
}: KvCacheParameters): DocumentLoader;
//#endregion
export { getAuthenticatedDocumentLoader, kvCache };