/** * @celsian/vura-adapter-cloudflare * * Adapts Vura build output for Cloudflare Workers deployment. * * Because Cloudflare Workers natively use the Web Standard Request/Response API * (the same as CelsianJS), this adapter is thin — it mainly generates: * 1. wrangler.toml configuration * 2. Worker entry files that wire routes to a CelsianJS app * * Supports multiple worker groups, KV namespaces, D1 databases, and R2 buckets. */ import type { ThenAdapter } from '@celsian/vura-core'; import type { ApiRoute } from '@celsian/vura-core'; export interface KVBinding { /** Binding name accessible in env */ binding: string; /** KV namespace ID */ id: string; /** Optional preview ID for local dev */ preview_id?: string; } export interface D1Binding { /** Binding name accessible in env */ binding: string; /** D1 database name */ database_name: string; /** D1 database ID */ database_id: string; } export interface R2Binding { /** Binding name accessible in env */ binding: string; /** R2 bucket name */ bucket_name: string; } export interface WorkerRoute { /** URL pattern, e.g. "example.com/api/*" */ pattern: string; /** Optional zone name */ zone_name?: string; } export interface CloudflareAdapterOptions { /** Worker name (used in wrangler.toml) */ name: string; /** Compatibility date for the Workers runtime (default: today's date) */ compatibilityDate?: string; /** Route patterns to attach the worker to */ routes?: WorkerRoute[]; /** KV namespace bindings */ kv?: KVBinding[]; /** D1 database bindings */ d1?: D1Binding[]; /** R2 bucket bindings */ r2?: R2Binding[]; /** Optional: group routes into separate workers by config key */ workerGroup?: string; } /** * Generate a wrangler.toml configuration string from adapter options and routes. */ export declare function generateWranglerToml(options: CloudflareAdapterOptions, routes: ApiRoute[], taskRoutes?: ApiRoute[], /** Relative path to the emitted static-asset directory, when the app has one. */ assetsDir?: string | null): string; /** * Generate a self-contained Worker entry file that routes requests * to the appropriate handler using @celsian/vura-core's req/reply pattern. * No CelsianJS dependency required — works standalone. * * `globalHooksFile` is the project's conventional hooks file (src/api/_hooks.ts * or src/hooks.ts) when it exists. buildEnd bundles it next to this entry as * hooks.js; the entry imports it and merges its hooks ahead of each route's * own, which is the order the hot server and the generated dist/functions/ * entry both use. Passing null emits an empty stand-in so no import is left * dangling. * * `hasServerPages` wires the sibling pages.js this adapter emits for * `mode: 'server'` pages. Static, client and hybrid pages never reach this * entry: they are files, and Workers Static Assets answers them before the * Worker runs. */ export declare function generateWorkerEntry(routes: ApiRoute[], projectRoot: string, workerDir: string, taskRoutes?: ApiRoute[], globalHooksFile?: string | null, /** True when buildEnd emitted a pages.js beside this entry. */ hasServerPages?: boolean, /** * True when this Worker has a site surface: a page of any mode, or a file * under dist/static or dist/public. It decides the 404 shape, not routing. */ hasPages?: boolean): string; /** * Wrap a CelsianJS app instance as a Cloudflare Worker fetch handler. * * CelsianJS already uses Web Standard Request/Response, so this is a thin wrapper * that passes Cloudflare env bindings and execution context to route handlers * via properties on the request object. * * @example * ```ts * import { createApp } from '@celsian/core'; * import { createWorkerHandler } from '@celsian/vura-adapter-cloudflare'; * * const app = createApp(); * app.get('/hello', (req) => new Response('Hello!')); * * export default createWorkerHandler(app); * ``` */ export declare function createWorkerHandler(app: CelsianApp): CloudflareWorkerHandler; /** * Create a Vura adapter for Cloudflare Workers deployment. * * @example * ```ts * // vura.config.ts * import { defineConfig } from '@celsian/vura-core'; * import { cloudflareAdapter } from '@celsian/vura-adapter-cloudflare'; * * export default defineConfig({ * adapter: cloudflareAdapter({ * name: 'my-api', * compatibilityDate: '2024-12-01', * kv: [{ binding: 'CACHE', id: 'abc123' }], * }), * }); * ``` */ export declare function cloudflareAdapter(options: CloudflareAdapterOptions): ThenAdapter; /** Minimal CelsianJS app interface for the handler wrapper */ export interface CelsianApp { handle(request: Request): Promise | Response; } /** Request with Cloudflare bindings attached */ export interface CloudflareRequest extends Request { __cf_env: Record; __cf_ctx: ExecutionContext; } /** Cloudflare Worker execution context */ export interface ExecutionContext { waitUntil(promise: Promise): void; passThroughOnException(): void; } /** Cloudflare Worker module format handler */ export interface CloudflareWorkerHandler { fetch(request: Request, env: Record, ctx: ExecutionContext): Promise; } //# sourceMappingURL=index.d.ts.map