import React from "react"; import * as ReactDOM from "react-dom/server"; import type { AppProps } from "./app.js"; import type { HeadOptions, TailOptions } from "./document.js"; /** * Headers sent to the server for the request. */ export interface Headers { get(name: string): string | null; getAll(name: string): string[]; has(name: string): boolean; } /** * Parameters sent using form encoding to the server. */ export interface FormParams { get(name: string): string | null; getAll(name: string): string[]; has(name: string): boolean; } /** * Standardized request format for server implementations. */ export interface Request { method: string; pathname: string; search: URLSearchParams; headers: Headers; form: () => Promise; text: () => Promise; json: () => Promise; arrayBuffer: () => Promise; } /** * Parameters provided from matching path segments, e.g. `/[param]`. */ export declare type Params = ReadonlyMap; /** * The request context used for server side functions. */ export interface ServerSideContext { key: string; request: Request; params: Params; context: C; render: () => Promise; formData: object | undefined; } /** * Valid return type of `getServerSideProps`. */ export interface ServerSideProps

{ props: P; hydrate?: boolean; status?: number; redirect?: { url: string; }; } /** * Function signature for `getServerSideProps`. */ export declare type GetServerSideProps = (context: ServerSideContext) => ServerSideProps

| undefined | null; /** * Stream rendering options. */ export interface StreamOptions { head?: string; tail?: string; onError?: (error: unknown) => void; signal?: AbortSignal; waitForAllReady?: boolean; } /** * Raw node.js stream result. */ export interface NodeStream { prefix: () => string; suffix: () => string; stream: ReactDOM.PipeableStream; } /** * Raw web stream result. */ export interface ReadableStream { prefix: () => Uint8Array; suffix: () => Uint8Array; stream: ReactDOM.ReactDOMServerReadableStream; } /** * Supported body interfaces. */ export interface Body { nodeStream(options?: StreamOptions): Promise; readableStream(options?: StreamOptions): Promise; } /** * Simple `Response` interface for returning site pages. */ export interface Response { status: number; headers: ReadonlyMap; body: Body | string | undefined; } /** * Handle all incoming requests to the current route. */ export declare type OnRequestHandler = (context: ServerSideContext, next: () => Promise) => Response | Promise; /** * The server module page allows creation of loader and form handling. */ export interface PageServerModule { getServerSideProps?: GetServerSideProps<{}, C>; onRequest?: Record | undefined>; } /** * The page component exports the component to be rendered as HTML. */ export interface PageModule { default?: React.ComponentType<{}>; } /** * The application module exports a react component that wraps every page. */ export interface AppModule { default?: React.ComponentType; } /** * The document module exports a function that returns the HTML header and footer. */ export interface DocumentModule { renderHead?: (options: HeadOptions) => string; renderTail?: (options: TailOptions) => string; } /** * Supported component loader input types (promises and functions). */ export declare type ServerLoader = T | Promise | (() => T | Promise); /** * Server-side only components. */ export interface ServerFile { module: ServerLoader; } /** * Server-side page component. */ export interface ServerPage { module?: ServerLoader; serverModule?: ServerLoader>; scripts?: string[]; css?: string[]; } /** * Create a server instance from pages. */ export interface ServerOptions { pages: Record>; notFound?: ServerPage; app?: ServerFile; document?: ServerFile; } /** * The server is just a `Request` in and `Response` out. */ export declare type Server = (request: Request, context: C) => Promise; /** * Create a simple SSR service given pages and apps. */ export declare function createServer(options: ServerOptions): Server; /** * Format JSON as response. */ export declare function json(json: unknown, status?: number): Response; /** * Format redirect as a response. */ export declare function redirect(location: string, status?: number): Response; /** * Handle form submission on the server-side. */ export declare type OnFormSubmitHandler = (context: ServerSideContext) => object | Promise; /** * Handle form submissions for `onRequest`. */ export declare function onFormSubmit(process: OnFormSubmitHandler): OnRequestHandler;