import { R2Bucket, DurableObjectNamespace } from '@cloudflare/workers-types';

/**
 * `@cimplify/sdk/server/tanstack` - TanStack Start/Nitro cache support.
 *
 * The deployment adapter binds:
 *   - CIMPLIFY_CACHE_R2_BUCKET
 *   - CIMPLIFY_CACHE_R2_PREFIX
 *   - CIMPLIFY_PATH_INDEX
 *
 * This driver consumes those bindings and mirrors the Next/OpenNext eviction
 * contract: write to R2, then register cimplify:* tags in PathIndex so the
 * central eviction worker can delete the exact R2 object and purge route URLs.
 */

declare const TANSTACK_R2_BUCKET_BINDING = "CIMPLIFY_CACHE_R2_BUCKET";
declare const TANSTACK_R2_PREFIX_ENV = "CIMPLIFY_CACHE_R2_PREFIX";
declare const TANSTACK_PATH_INDEX_BINDING = "CIMPLIFY_PATH_INDEX";
declare const TANSTACK_CACHE_NAMESPACE = "nitro";
declare const CIMPLIFY_TAG_PREFIX = "cimplify:";
declare const CIMPLIFY_CACHE_META_FIELD = "__cimplifyCache";
type Awaitable<T> = T | Promise<T>;
type R2PutValue = NonNullable<Parameters<R2Bucket["put"]>[1]>;
interface CimplifyTanstackCacheEnv {
    [TANSTACK_R2_BUCKET_BINDING]?: R2Bucket;
    [TANSTACK_R2_PREFIX_ENV]?: string;
    [TANSTACK_PATH_INDEX_BINDING]?: DurableObjectNamespace;
}
interface CimplifyCacheIndexMetadata {
    tags?: readonly string[];
    cacheKey?: string;
    isFetch?: boolean;
}
interface CimplifyTanstackCacheSetOptions {
    tags?: readonly string[];
    cimplifyTags?: readonly string[];
    cacheTags?: readonly string[];
    cacheKey?: string;
    cimplifyCacheKey?: string;
    isFetch?: boolean;
    cimplifyIsFetch?: boolean;
    [CIMPLIFY_CACHE_META_FIELD]?: CimplifyCacheIndexMetadata;
    [key: string]: unknown;
}
interface CimplifyTanstackCacheDriverOptions {
    env?: CimplifyTanstackCacheEnv;
    getEnv?: () => Awaitable<CimplifyTanstackCacheEnv | undefined>;
    prefix?: string;
    namespace?: string;
    tags?: readonly string[] | ((key: string, value: unknown, options?: unknown) => readonly string[]);
    cacheKey?: string | ((key: string, value: unknown, options?: unknown) => string | undefined);
    isFetch?: boolean | ((key: string, value: unknown, options?: unknown) => boolean);
}
interface CimplifyTanstackCacheDriver {
    name: string;
    options: CimplifyTanstackCacheDriverOptions;
    hasItem(key: string): Promise<boolean>;
    getItem<T = unknown>(key: string): Promise<T | null>;
    getItemRaw(key: string): Promise<string | null>;
    setItem(key: string, value: unknown, options?: CimplifyTanstackCacheSetOptions): Promise<void>;
    setItemRaw(key: string, value: R2PutValue, options?: CimplifyTanstackCacheSetOptions): Promise<void>;
    removeItem(key: string): Promise<void>;
    getKeys(base?: string): Promise<string[]>;
    clear(base?: string): Promise<void>;
}
declare function cimplifyTanstackR2Key(prefix: string, key: string, namespace?: string): string;
declare function cimplifyTanstackCacheOptions(metadata: CimplifyCacheIndexMetadata): CimplifyTanstackCacheSetOptions;
declare function withCimplifyCacheMetadata<T extends Record<string, unknown>>(value: T, metadata: CimplifyCacheIndexMetadata): T & {
    [CIMPLIFY_CACHE_META_FIELD]: CimplifyCacheIndexMetadata;
};
declare function createCimplifyTanstackCacheDriver(options?: CimplifyTanstackCacheDriverOptions): CimplifyTanstackCacheDriver;
declare const cimplifyTanstackCacheDriver: typeof createCimplifyTanstackCacheDriver;

export { CIMPLIFY_CACHE_META_FIELD, CIMPLIFY_TAG_PREFIX, type CimplifyCacheIndexMetadata, type CimplifyTanstackCacheDriver, type CimplifyTanstackCacheDriverOptions, type CimplifyTanstackCacheEnv, type CimplifyTanstackCacheSetOptions, TANSTACK_CACHE_NAMESPACE, TANSTACK_PATH_INDEX_BINDING, TANSTACK_R2_BUCKET_BINDING, TANSTACK_R2_PREFIX_ENV, cimplifyTanstackCacheDriver, cimplifyTanstackCacheOptions, cimplifyTanstackR2Key, createCimplifyTanstackCacheDriver, withCimplifyCacheMetadata };
