import { n as DOQueryStatement, r as DurableObjectsConfig, t as DOQueryResult } from "../do-sql-types-BRfvIdoO.mjs"; import { DurableObject } from "cloudflare:workers"; import { Dialect, Kysely } from "kysely"; //#region src/db/do-sql-class.d.ts declare class EmDashDB extends DurableObject { #private; /** * Execute a single SQL statement. Called via RPC from the Kysely driver. * * @param opts.bookmark On a replica read, wait until this instance has * caught up to the given bookmark before serving (read-your-writes). */ query(sql: string, params?: unknown[], opts?: { bookmark?: string; }): Promise; /** * Execute several read statements in a single RPC, returning one result per * statement in order. This is the round-trip win: a page that issues ~17 * reads becomes one RPC instead of N. * * Read-only by construction -- the coalescing dialect only ever buffers * plain SELECTs (writes take the single-`query` path). So we wait on the * bookmark once for the whole batch, then run each `exec` synchronously * (a consistent snapshot, since a DO is single-threaded and there are no * awaits between execs) and return just rows. No per-statement bookmark is * minted (reads don't advance the write bookmark). * * If any statement throws, the whole RPC rejects; the caller falls back to * running each statement via `query()` individually, which preserves * per-statement error semantics and the readonly-retry path. */ batchQuery(statements: DOQueryStatement[], opts?: { bookmark?: string; }): Promise; } //#endregion //#region src/db/do-sql.d.ts /** * Create a DO SQL dialect from config. Used for the singleton Kysely instance * (runtime-init migrations, scheduled tasks, and any query outside a request * scope). * * This dialect is cached across requests on globalThis, so it must NOT hold a * stub: a DO stub is a per-request I/O object. We resolve a fresh stub on every * query instead. The hot read/write path uses `createRequestScopedDb`, which * reuses one stub for the whole request. */ declare function createDialect(config: DurableObjectsConfig): Dialect; /** * Coalescing DO SQL dialect for the runtime's cold-start read phase, where the * core runtime batches its init reads into one `batchQuery` RPC. Shares the * singleton's bookmark sink so reads issued right after a migration (run on the * singleton) wait for the replica to catch up — read-your-writes across the two * connections. Resolves a fresh stub per query like {@link createDialect}. 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: DurableObjectsConfig): Dialect; interface CookieJar { get(name: string): { value: string; } | undefined; set(name: string, value: string, options: Record): void; } interface RequestScopedDbOpts { config: DurableObjectsConfig; isAuthenticated: boolean; /** * Whether this request mutates. Part of the shared adapter contract (the D1 * adapter pins writes to `first-primary`). The DO backend does NOT use it for * routing: DO exposes no Worker-side "give me the primary" handle -- a write * is proxied to the primary by the DO itself, and read-your-writes is * provided by the per-request bookmark feedback (a write records its bookmark * in the sink; later reads in the same request wait for it). So correctness * doesn't depend on knowing up front that the request writes. */ isWrite: boolean; cookies: CookieJar; url: URL; } interface RequestScopedDb { db: Kysely; commit: () => void; } declare function createRequestScopedDb(opts: RequestScopedDbOpts): RequestScopedDb | null; //#endregion export { EmDashDB, RequestScopedDb, RequestScopedDbOpts, createCoalescingDialect, createDialect, createRequestScopedDb };