import { env } from "cloudflare:workers"; export async function withEnvBinding(name: keyof Env, value: string, run: () => Promise): Promise { const bindings = env as unknown as Record; const previous = bindings[name as string]; bindings[name as string] = value; try { return await run(); } finally { if (previous === undefined) delete bindings[name as string]; else bindings[name as string] = previous; } }