import { Effect } from 'effect'; import { HttpClient } from '@effect/platform'; import { Schema } from 'effect'; import { Scope } from 'effect'; import { Server } from 'node:http'; export declare interface RunningServer { readonly server: Server; readonly port: number; readonly host: string; readonly routes: ReadonlyArray; readonly close: () => Promise; } export declare interface ServeOptions { readonly port?: number; readonly host?: string; /** Env exposed to every handler via `ctx.env` (defaults to `process.env`). */ readonly env?: Record; /** * CORS allow-origin for responses + OPTIONS preflight. A serverless function * is almost always called cross-origin (the static site that fetches it lives * on a different host) — Cloudflare/Scaleway add these headers at the edge, so * the local runner matches by default. `'*'` (default) allows any origin; * pass a concrete origin to lock it down, or `false` to send no CORS headers. */ readonly cors?: string | false; } /** * Platform-agnostic per-invocation context handed to a handler. The framework * fills it from whatever the host passes — Cloudflare's `env` bindings + * `ExecutionContext`, Scaleway's `process.env`, etc. — so handler code never * branches on the platform. */ declare interface ServerlessContext { /** Env vars / secrets injected by the platform. Cloudflare → the worker `env` * bindings; Scaleway / Node → `process.env`. */ readonly env: Record; /** The raw incoming Web `Request` (method, url, headers) for advanced use. */ readonly request: Request; /** Schedule work that outlives the response — Cloudflare * `ExecutionContext.waitUntil`; a best-effort fire-and-forget elsewhere. */ readonly waitUntil: (promise: Promise) => void; } /** * A serverless function definition. The handler is Effect-first and may require * `HttpClient` (provided by the framework's base layer); decode/encode of the * JSON wire body is driven by the `input`/`output` schemas. */ declare interface ServerlessDefinition { /** Deployment identifier — kebab-case, DNS-safe (it names the deployed * function/worker). */ readonly name: string; /** HTTP method the function answers on (default `POST`). A `GET` reads its * input from the query string; everything else from the JSON body. */ readonly method?: ServerlessMethod; /** Path the function answers on within its host (default `/`). */ readonly path?: string; /** Decodes the request body/query into the handler's typed input. */ readonly input: Schema.Schema; /** Encodes the handler's result into the JSON response body. */ readonly output: Schema.Schema; /** The work. Effect-first; may `yield* HttpClient.HttpClient` and use scoped * effects (e.g. `http.get(url)` + reading the body) directly — the framework * runs the handler inside a `Scope`, so you never write `Effect.scoped`. */ readonly handler: (input: I, ctx: ServerlessContext) => Effect.Effect; /** Deploy hints (memory / timeout / region / scale). */ readonly runtime?: ServerlessRuntimeHints; } /** HTTP method a function answers on. */ declare type ServerlessMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'; /** Platform deploy hints — best-effort; a host ignores what it can't honour. */ declare interface ServerlessRuntimeHints { readonly memoryMb?: number; readonly timeoutSeconds?: number; /** Provider region (e.g. `fr-par` for Scaleway). Cloudflare is global. */ readonly region?: string; /** Warm/cap instance counts (provider best-effort). */ readonly minScale?: number; readonly maxScale?: number; } export declare interface ServeRoute { readonly name: string; readonly method: string; readonly path: string; } /** * Start an http server for the given functions. Resolves once listening; the * returned handle exposes the effective route table and a `close()`. Rejects * only if the port can't be bound. */ export declare const serveServerless: (defs: ReadonlyArray>, opts?: ServeOptions) => Promise; export { }