/** * D1 access for booking reconcile, over Cloudflare's HTTP query API. * * Task 1805 — this module used to return an argv for `npx wrangler d1 execute`, * which `reconcile-bookings.ts` ran through spawnSync once per SQL statement. On * a four-brand laptop that was a continuous ~0.6 of a core: every statement paid * a cold start of npm, then node, then wrangler's cli.js and its esbuild service. * Nothing was failing; the cost was the transport choice, and it scaled with * accounts x statements x tick rate. Task 1350's ENOENT finding (only `npx * wrangler` resolves on the brand server PATH) is not reopened — it is retired, * because no binary is resolved here at all. * * The two bounds the spawn carried are preserved deliberately, not incidentally: * its `timeout: 60_000` becomes a request bound, and its `maxBuffer: 16MB` * becomes a cap enforced *while streaming* the response. Both exist so a stalled * Cloudflare cannot wedge a run that is holding the reconcile PID lock. * * The endpoint is keyed by database uuid but every caller holds a database name, * so the client resolves name -> uuid once per run and caches it. */ /** The bound each request runs under. Inherited from the spawnSync `timeout`. */ export declare const D1_TIMEOUT_MS = 60000; /** The most response bytes we will read. Inherited from the spawnSync `maxBuffer`. */ export declare const D1_RESPONSE_CAP_BYTES: number; export interface D1Response { ok: boolean; status: number; /** * The body as byte chunks. Deliberately not a `text()`: the cap has to be able * to stop the read part-way, which is the property `maxBuffer` provided. A * whole-body accessor could only check the size after paying for it. */ chunks: AsyncIterable; } export interface D1RequestInit { method: string; headers: Record; body?: string; signal: AbortSignal; } /** The HTTP seam. Injectable so the transport is unit-testable without a network. */ export type D1Fetch = (url: string, init: D1RequestInit) => Promise; /** Compose the request that resolves a database name to its uuid. Pure. */ export declare function buildD1LookupRequest(accountId: string, dbName: string, token: string): { url: string; init: Omit; }; /** * Compose the request that runs one SQL statement. Pure. * * `params` binds the statement's values server-side (`?1`, `?2`, … in the SQL). * The spawn this replaced had no parameter channel, so every value reached D1 * folded into the statement text; the HTTP API takes them separately, so the * sweep's bookingId is bound rather than interpolated. * * Typed `string[]` because the API documents this field as an array of string. * A wider type would let a caller pass a value the endpoint rejects at runtime, * on a periodic path where that surfaces as a failed tick rather than a build error. */ export declare function buildD1QueryRequest(accountId: string, databaseId: string, sql: string, token: string, params?: string[]): { url: string; init: Omit; }; export interface D1Client { /** * Run one SQL statement against the named database and return its rows. * Values go in `params` (`?1`, `?2`, … in the SQL), never in the statement text. */ query(dbName: string, sql: string, params?: string[]): Promise[]>; /** SQL statements issued so far. Name lookups are not statements and are excluded. */ readonly statements: number; /** Total wall time spent in this client, lookups included. */ readonly elapsedMs: number; } /** * One client per account run. It owns the name -> uuid cache, so a tick pays one * lookup for its database and then issues statements against the resolved id. */ export declare function createD1Client(opts: { accountId: string; token: string; fetchFn?: D1Fetch; }): D1Client; //# sourceMappingURL=d1-command.d.ts.map