import type { ReactNode } from 'react'; import type { Config } from '../config.js'; import type { Etags } from './utils-isomorphic/etags.js'; type Elements = Record; /** * Serializes slots, an optional server function return value, and validators * into a Flight stream. */ export type RenderRsc = (elements: Elements, options?: { value?: unknown; etags?: Etags; unstable_clientModuleCallback?: (ids: string[]) => void; }) => Promise; /** Renders an HTML document using a Flight stream and an HTML tree containing Slots. */ export type RenderHtml = (elementsStream: ReadableStream, html: ReactNode, options: { rscPath: string; formState?: unknown; status?: number; nonce?: string; unstable_extraScriptContent?: string; }) => Promise; export type RenderHtmlFallback = (options?: { nonce?: string; unstable_extraScriptContent?: string; }) => Promise; export type EmitFile = (filePath: string, body: ReadableStream) => Promise; /** * Dispatches payload, server function, and HTTP requests; return null to leave * a request unhandled. Returning `'fallback'`, or leaving `/` unhandled, serves * the HTML fallback; both are deprecated, so return `renderHtmlFallback()`. */ export type HandleRequest = (input: ({ type: 'rsc'; rscPath: string; rscParams: unknown; } | { type: 'call'; fn: (...args: unknown[]) => Promise; args: unknown[]; } | { type: 'http'; tryAction?: () => Promise<{ action: true; formState: unknown; } | { action: false; formData: FormData; }>; }) & { pathname: string; req: Request; etags?: Etags; }, utils: { renderRsc: RenderRsc; renderHtml: RenderHtml; renderHtmlFallback: RenderHtmlFallback; loadBuildMetadata: (key: string) => Promise; }) => Promise; /** Emits prerendered payloads, HTML and build metadata through the supplied utilities. */ export type HandleBuild = (utils: { renderRsc: RenderRsc; renderHtml: RenderHtml; rscPathToFileName: (rscPath: string) => string; saveBuildMetadata: (key: string, value: string) => Promise; generateFile: (fileName: string, body: ReadableStream | string) => Promise; generateDefaultHtml: (fileName: string, options?: Parameters[0]) => Promise; unstable_registerPrunableFile: (srcPath: string) => void; }) => Promise; /** Runtime and build handlers passed to a Waku adapter. */ export type Handlers = { handleRequest: HandleRequest; handleBuild: HandleBuild; [someOtherProperty: string]: unknown; }; /** Complete request and build entry produced by an adapter, or authored directly. */ export type ServerEntry = { fetch: (req: Request, ...args: any[]) => Response | Promise; build: (utils: { emitFile: EmitFile; unstable_registerPrunableFile: (srcPath: string) => void; }, ...args: any[]) => Promise; buildOptions?: Record; buildEnhancers?: string[]; defaultExport?: unknown; [someOtherProperty: string]: unknown; }; export type ProcessRequest = (arg: Parameters[0]) => Promise; export type ProcessBuild = (arg: Parameters[0]) => Promise; export type CreateServerEntryAdapter = (fn: (args: { handlers: Handlers; processRequest: ProcessRequest; processBuild: ProcessBuild; unstable_setAllEnv: (newEnv: Readonly>) => void; config: Omit, 'vite'>; isBuild: boolean; /** * @deprecated Will be removed in a future release. Leave unhandled * requests to Hono's not-found handler. */ notFoundHtml: string; }, options?: Options) => ServerEntry) => (handlers: Handlers, options?: Options) => ServerEntry; export {};