/** * Wrangler Resource Provisioning * * Pure logic + a thin wrangler client for `quickback deploy`: * * - parse the compiler-generated wrangler.toml for D1 / KV / R2 / Hyperdrive * sections * - detect the compiler's placeholder ids — self-describing * `placeholder-*` values plus the legacy `local`/`local-*` set (see * @quickback-dev/deploy-contract/placeholders, the source of truth for * this predicate; the compiler emits these whenever the corresponding * provider-config key is unset) * - map each placeholder back to the quickback.config.ts provider-config * key the compiler reads the real id from * - parse `wrangler d1 create` / `wrangler kv namespace create` output * (both the JSON snippet emitted by current wrangler and the legacy * TOML snippet) * * All Cloudflare calls go through an injected {@link CaptureRunner} so * tests never touch the network. */ export interface D1Entry { binding: string; databaseName: string; databaseId: string; migrationsDir?: string; } export interface KvEntry { binding: string; id: string; } export interface R2Entry { binding: string; bucketName: string; } export interface HyperdriveEntry { binding: string; id: string; } export interface WranglerResources { /** Top-level `name = "..."` — the worker name. */ workerName?: string; d1: D1Entry[]; kv: KvEntry[]; r2: R2Entry[]; hyperdrive: HyperdriveEntry[]; } /** * Line-based parser for the compiler-emitted wrangler.toml. Tracks the * current `[[table]]` header and collects `key = "value"` pairs until the * next header. Deliberately minimal — it only needs to understand the * shape our own config generator emits. */ export declare function parseWranglerToml(toml: string): WranglerResources; export declare function isPlaceholderId(id: string | undefined): boolean; /** * Resolve which providers.database.config key should receive the real id * for a D1 section. Placeholder literal first (stable across binding * renames), binding name as fallback. */ export declare function configKeyForD1(entry: D1Entry): string | null; export interface ProvisionPlan { /** D1 databases whose wrangler.toml id is a placeholder. */ d1ToProvision: D1Entry[]; /** D1 databases that already carry a real id. */ d1Ready: D1Entry[]; /** KV namespaces whose id is a placeholder. */ kvToProvision: KvEntry[]; kvReady: KvEntry[]; /** R2 buckets are named (no id) — existence is ensured on every run. */ r2ToEnsure: R2Entry[]; /** Hyperdrive placeholders — can't be auto-created (needs a connection string). */ hyperdriveUnresolved: HyperdriveEntry[]; hasWork: boolean; } export declare function buildProvisionPlan(resources: WranglerResources): ProvisionPlan; /** * Extract the database id from `wrangler d1 create` output. Handles the * JSON snippet emitted by current wrangler versions and the legacy TOML * snippet; falls back to the first UUID anywhere in the output. */ export declare function parseD1CreateOutput(output: string): string | null; /** * Extract the namespace id from `wrangler kv namespace create` output. * Handles JSON and TOML snippet forms; falls back to the first 32-char * hex token. */ export declare function parseKvCreateOutput(output: string): string | null; /** `wrangler d1 list --json` → Map of database name → uuid. */ export declare function parseD1ListOutput(output: string): Map; /** `wrangler kv namespace list` → Map of namespace title → id. */ export declare function parseKvListOutput(output: string): Map; export interface RunResult { code: number; stdout: string; stderr: string; } /** Runs `wrangler ` and captures output. Injected so tests stay offline. */ export type CaptureRunner = (args: string[], opts?: { cwd?: string; }) => Promise; export declare class WranglerError extends Error { readonly result?: RunResult | undefined; constructor(message: string, result?: RunResult | undefined); } export declare class WranglerClient { private readonly runner; private readonly cwd?; constructor(runner: CaptureRunner, cwd?: string | undefined); private run; /** Returns the wrangler version string, or null when wrangler isn't runnable. */ version(): Promise; /** Checks `wrangler whoami`. */ whoami(): Promise<{ ok: boolean; detail: string; }>; /** Map of existing D1 database name → uuid. */ d1List(): Promise>; /** Creates a D1 database and returns its id. Falls back to a list lookup when the output can't be parsed. */ d1Create(name: string): Promise; /** Map of existing KV namespace title → id. */ kvList(): Promise>; /** Creates a KV namespace for `binding` and returns its id. */ kvCreate(binding: string, expectedTitle: string): Promise; /** True when the R2 bucket already exists. */ r2Exists(bucketName: string): Promise; /** Creates an R2 bucket; treats "already exists" as success. */ r2Create(bucketName: string): Promise<'created' | 'exists'>; } //# sourceMappingURL=wrangler-resources.d.ts.map