/* auto-generated by NAPI-RS */ /* eslint-disable */ /** Body bridge for a single request. Created in Rust, handed to JS as an argument. */ export declare class BodyIo { /** * Read the next request body chunk. `null` = end of body. * Backpressure JS→Rust: the socket is only read when JS calls read(). */ read(): Promise /** * Write a response body chunk. Resolves once the channel accepts it (backpressure * Rust→JS: hyper drains it as the socket frees up). */ write(chunk: Buffer): Promise /** Finish the response body (close the channel → hyper sees the end). */ endWrite(): void /** * How the request ended: `true` — the client went away before a response was * produced, `false` — it completed normally. * * Hyper dropping the request future is the only disconnect notification available, * so this is what backs `onAbort` and `c.req.signal`. JS subscribes only when a * handler will act on it: the promise costs a pending task per request. */ waitAbort(): Promise /** Next multipart part (skipping the tail of an unread one). `null` = end of form. */ nextPart(): Promise /** Next chunk of the current part. `null` = end of part. */ readPart(): Promise } /** The low-level server. Wrapped by the JS `Server` class. */ export declare class RustServer { constructor() /** * Start HTTP/1.1 on `host:port` with a route table. * * Routing/`404`/`405`/auto-`OPTIONS` happen in Rust; hitting a leaf calls * `dispatch(req) => Promise`. Non-blocking (the accept loop runs in background). */ listen(port: number, host: string, routes: Array, hasNotFound: boolean, options: ListenOptions, dispatch: () => void): void /** * Run a request through the pipeline without a socket (§17, `app.inject`). * * Executes on the server runtime (where the TSFN and state live); the result comes * back through a oneshot. Requires a started server: routes and schemas are compiled * in `listen()` — the wrapper starts one on an ephemeral port when needed, but the * request itself never travels over a socket. */ inject(method: string, path: string, headers: Array, body?: Buffer | undefined | null): Promise /** * Everything queued for the JS dispatcher right now (§19). Called from the * doorbell callback in a loop until it returns an empty array. */ takeBatch(): Array /** * The `BodyIo` of one request (§19) — at most once per request; `null` afterwards * or for an unknown id. Lazy on purpose: a bodyless GET never pays for the class. */ takeBody(reqId: number): BodyIo | null /** * Complete a request (§19): the response crosses the boundary through this * synchronous call — no `Promise` is awaited across threads. Idempotent. */ respond(reqId: number, res: JsResponse): void /** * Purge the native response cache (§18): all routes, or entries whose request path * equals `path` exactly (any query/vary variant). Returns how many entries were * removed. Before `listen()` this is a no-op — there is no cache yet. */ purgeCache(path?: string | undefined | null): number /** * Set readiness from JS (§11): `app.setReady(false)` removes the pod from the * endpoints without touching liveness. The periodic `readinessCheck` pushes its * verdict here too. Before `listen()` this is a no-op (there is no state yet). */ setReady(ready: boolean): void /** * Graceful shutdown (§10). Resolves once in-flight requests have finished (or * `shutdownTimeout` expired). Idempotent: a repeated call is a no-op. * * Order: signal → the accept loop closes the listener (the port frees immediately) * → connections receive `graceful_shutdown` (h2 gets `GOAWAY`) → drain → `done`. * * The runtime is shut down on a separate OS thread via `shutdown_timeout` rather * than `shutdown_background`: the latter returns immediately and **may never destroy * the runtime at all** (tokio docs). Then `Arc` is never dropped, and with it * the listener (port stays busy) and the `ThreadsafeFunction` (holds a ref on the * event loop) stay alive — the Node process never exits. */ close(): Promise } /** Per-route response cache options (§18; normalized by the wrapper). */ export interface CacheOptions { /** Entry lifetime in ms. Must be > 0. */ ttlMs: number /** Request headers (lowercase) whose values become part of the cache key. */ vary?: Array /** Entry cap per route; defaults to 1024. */ maxEntries?: number /** Bodies larger than this are not stored; defaults to 1 MiB. */ maxBodyBytes?: number } /** CORS options from the JS side (normalized by the wrapper). Absent = CORS off. */ export interface CorsOptions { origins: Array methods: Array allowedHeaders?: Array exposedHeaders?: Array credentials: boolean maxAge?: number } /** HTTP/2 options (§6c A1). */ export interface Http2Options { maxConcurrentStreams?: number initialWindowSize?: number maxResetStreamsPerSec?: number } /** `app.inject` response (§17): no socket involved, same shape as a regular response. */ export interface InjectResponse { status: number headers: Array body: Buffer } /** * The response a JS handler passes to `respond()`. * * `headers` — ordered pairs, duplicates allowed (multiple `set-cookie`). * `streamed = true` → the body flows through `BodyIo::write` (a channel-backed * `Body`) and the `body` field is ignored. Otherwise the body is the `body` string. */ export interface JsResponse { status?: number headers?: Array body?: string streamed?: boolean } /** Key-value pair (for query strings, where keys may repeat). */ export interface KvPair { key: string value: string } /** Server options that affect how the context is computed in Rust (§4, §7, §6d). */ export interface ListenOptions { customIpHeaders?: Array customCountryHeaders?: Array requestIdHeader?: string /** Hard request body limit in bytes (authoritative in Rust). null/absent = no limit. */ bodyLimit?: number /** Native CORS. null/absent = disabled. */ cors?: CorsOptions /** TLS (§12). null/absent = plaintext. */ tls?: TlsOptions /** * h2c prior-knowledge on the plaintext port (§19). * * `js_name` is required: napi's auto-conversion yields `h2C` (the letter after a * digit is upper-cased) while the wrapper sends `h2c` — the field was silently lost. */ h2c?: boolean /** Header read timeout in ms (Slowloris, §6c A2). */ headerReadTimeout?: number /** Timeout waiting for a request body chunk, ms (§6c A2) → 408. */ bodyReadTimeout?: number /** Connection idle without reads/writes, ms (§6c A2) → close. */ idleTimeout?: number /** TLS handshake timeout in ms. */ handshakeTimeout?: number /** Limit on the number of headers. */ maxHeaders?: number /** Header block size limit in bytes (§6c B10) → 431. */ maxHeaderSize?: number /** Graceful shutdown deadline in ms (§10). Defaults to 10s. */ shutdownTimeout?: number /** * Pause between dropping readiness and closing the listener, ms (§10 + §11). * Gives the balancer time to remove the pod from endpoints before refusals start. */ preShutdownDelay?: number /** Unix socket path (§6c B9). Set → we listen on it and ignore `port`/`host`. */ unixPath?: string /** Accept queue depth (§6c B9). Defaults to 1024. */ backlog?: number /** `SO_REUSEPORT` — several processes on one port (§6c B9). */ reusePort?: boolean /** `TCP_NODELAY` (§6c B9). Enabled by default. */ noDelay?: boolean /** Cap on concurrent connections (§6c B9). */ maxConnections?: number /** Expect PROXY protocol v1/v2 on every connection (§6c A4). */ proxyProtocol?: boolean /** Number of tokio workers; `0`/absent = auto from the cgroup quota (§6c A3). */ workerThreads?: number /** Liveness probe path (§11). Empty string disables it. */ healthPath?: string /** Readiness probe path (§11). Empty string disables it. */ readyPath?: string /** Prometheus metrics path (§11). Empty string disables it. */ metricsPath?: string /** Separate port for probes/metrics (§11); set → they are absent from the main port. */ adminPort?: number /** JSON access log to stdout (§11). */ accessLog?: boolean /** Cap on concurrently handled requests (§6c C5). Above it — 503. */ maxConcurrentRequests?: number /** How many requests may wait for a slot beyond the limit (§6c C5). 0 = no queue. */ maxQueue?: number /** How long to wait in the queue, ms (§6c C5). Defaults to 1s. */ queueTimeout?: number /** `Retry-After` header value in seconds for 503 (§6c C5). */ retryAfter?: number /** * How long continuous overload must last before readiness drops, ms (§6c C5). * Absent/0 = leave readiness alone. */ overloadShedAfter?: number http2?: Http2Options } /** * A matched request handed to the JS dispatcher inside a batch (§19). * * `req_id` — the ticket for `takeBody`/`respond`. * `leaf_id` — index of the route leaf in the JS handler registry; `-1` = notFound. * `path` — full path (including baseUrl); the wrapper strips the prefix for `c.req.path`. * `ip`/`ips`/`country`/`id` are computed in Rust (§7, §6d B2). */ export interface MatchedRequest { reqId: number leafId: number method: string path: string queryString?: string params: Record query: Array headers: Array ip: string ips: Array country?: string id: string /** * Validated/coerced values (JSON strings) — present when the leaf has a schema. * `c.req.valid('body'|'query'|'params')` in JS then applies the valibot transform. */ validBody?: string validQuery?: string validParams?: string } /** Per-route multipart options (normalized by the wrapper; limits in bytes/counts). */ export interface MultipartOptions { maxFileSize?: number maxFieldSize?: number maxFiles?: number maxFields?: number allowedMimeTypes?: Array allowedExtensions?: Array } /** Multipart part metadata for JS. */ export interface PartMeta { name?: string filename?: string contentType?: string } /** * Route definition from the JS wrapper (path already joined with baseUrl/group prefix). * Schemas are JSON Schema strings (the wrapper converts valibot beforehand). */ export interface RouteDef { method: string path: string leafId: number bodySchema?: string querySchema?: string paramsSchema?: string multipart?: MultipartOptions /** Native response cache for this route (§18). Absent = not cached. */ cache?: CacheOptions } /** TLS certificates (PEM strings; the wrapper resolves path/Buffer). */ export interface TlsOptions { cert: string key: string }