import { Dialect, Kysely } from "kysely"; //#region src/db/d1.d.ts /** * D1 configuration (runtime type — matches the config-time type in index.ts) */ interface D1Config { binding: string; session?: "disabled" | "auto" | "primary-first"; bookmarkCookie?: string; coalesce?: boolean; } /** * Create a D1 dialect from config. Used for the singleton Kysely instance * (no session — queries go through the raw binding). */ declare function createDialect(config: D1Config): Dialect; /** * Coalescing D1 dialect for the runtime's cold-start read phase, where the * core runtime batches its init reads into one `batch()` round trip. Carries * no Sessions-API bookmark — cold-start reads need no read-your-writes * guarantee — so plain coalescing over the raw binding suffices. Each call * returns a fresh dialect; this must never back the long-lived singleton, * whose coalescing buffer would be shared across requests. */ declare function createCoalescingDialect(config: D1Config): Dialect; /** * A cookie interface minimally compatible with Astro's AstroCookies. Declared * here (not imported from astro) so this module stays free of astro types. */ interface CookieJar { get(name: string): { value: string; } | undefined; set(name: string, value: string, options: Record): void; } interface RequestScopedDbOpts { config: D1Config; isAuthenticated: boolean; isWrite: boolean; cookies: CookieJar; url: URL; } interface RequestScopedDb { /** Per-request Kysely instance backed by a D1 Sessions API session. */ db: Kysely; /** * Persist any per-request session state (e.g. the resulting D1 bookmark) * as a cookie. Idempotent; safe to call once after next() returns. */ commit: () => void; } /** * Create a per-request session-backed Kysely, or null when D1 sessions are * disabled or the binding is missing. Core middleware calls this once per * request, stashes `db` in ALS for the duration of next(), then invokes * `commit()` on the response path. */ declare function createRequestScopedDb(opts: RequestScopedDbOpts): RequestScopedDb | null; //#endregion export { RequestScopedDb, RequestScopedDbOpts, createCoalescingDialect, createDialect, createRequestScopedDb };