import type { MatchedRoute, ServeOptions, Server, WebSocketHandler } from "bun"; import type { FC, JSX, ReactNode } from "react"; export type ServerProps = { params: Record; searchParams: Record; headers: Headers; cookies: Record; body: any; method: string; url: string; pathname: string; query: Record; search: string; hash: string; }; export type StaticProps = { params: Record; searchParams: Record; headers: Headers; cookies: Record; body: any; method: string; url: string; pathname: string; query: Record; search: string; hash: string; }; export type StaticPaths = string[]; export type StaticParams = Record; export type PageModule = { component: React.ComponentType; serverProps: ServerProps; staticProps: StaticProps; staticPaths: StaticPaths; staticParams: StaticParams; }; export type BunextConfig = { distDir?: string; assetsPrefix?: string; origin?: string; globalVars?: { [k: string]: any; }; port?: number; development?: boolean; middleware?: (params: BunextConfigMiddlewareParams) => Promise | Response | Request | undefined; defaultCacheExpiry?: number; websocket?: WebSocketHandler; serverOptions?: ServeOptions; }; export type BunextConfigMiddlewareParams = { req: Request; url: URL; }; export type GetRouteReturn = { match: MatchedRoute; module: PageModule; component: React.ComponentType; serverProps: ServerProps; staticProps: StaticProps; staticPaths: StaticPaths; staticParams: StaticParams; }; export type BunxRouteParams = { req: Request; url: URL; body?: any; query?: any; /** * Intercept and Transform the response object */ resTransform?: (res: Response) => Promise | Response; server?: Server; }; export interface PostInsertReturn { fieldCount?: number; affectedRows?: number; insertId?: number; serverStatus?: number; warningCount?: number; message?: string; protocol41?: boolean; changedRows?: number; } export type APIResponseObject = { success: boolean; payload?: T[] | null; singleRes?: T | null; stringRes?: string | null; numberRes?: number | null; postInsertReturn?: PostInsertReturn | null; payloadBase64?: string; payloadThumbnailBase64?: string; payloadURL?: string; payloadThumbnailURL?: string; error?: any; msg?: string; queryObject?: any; countQueryObject?: any; status?: number; count?: number; errors?: any[]; debug?: any; batchPayload?: any[][] | null; errorData?: any; token?: string; csrf?: string; cookieNames?: any; key?: string; userId?: string | number; code?: string; createdAt?: number; email?: string; requestOptions?: any; logoutUser?: boolean; redirect?: string; }; export type BunextServerRouteConfig = { maxRequestBodyMB?: number; }; export type PageDistGenParams = { pageName: string; page_file: string; }; export type LivePageDistGenParams = { component: ReactNode; head?: FC; pageProps?: any; module?: BunextPageModule; bundledMap?: BundlerCTXMap; meta?: BunextPageModuleMeta; routeParams?: BunxRouteParams; debug?: boolean; }; export type BunextPageHeadFCProps = { serverRes: BunextPageModuleServerReturn; ctx?: BunxRouteParams; }; export type BunextPageModule = { default: FC; server?: BunextPageServerFn; meta?: BunextPageModuleMeta | BunextPageModuleMetaFn; Head?: FC; config?: BunextRouteConfig; }; export type BunextPageModuleMetaFn = (params: { ctx: BunxRouteParams; serverRes?: BunextPageModuleServerReturn; }) => Promise; export type BunextPageModuleMeta = { title?: string; description?: string; keywords?: string | string[]; author?: string; robots?: string; canonical?: string; themeColor?: string; og?: { title?: string; description?: string; image?: string; url?: string; type?: string; siteName?: string; locale?: string; }; twitter?: { card?: "summary" | "summary_large_image" | "app" | "player"; title?: string; description?: string; image?: string; site?: string; creator?: string; }; }; export type BunextPageServerFn = (ctx: Omit) => Promise>; export type BunextRouteConfig = { cachePage?: boolean; /** * Expiry time of the cache in seconds */ cacheExpiry?: number; }; export type BunextPageModuleServerReturn = { props?: T; query?: Q; redirect?: BunextPageModuleServerRedirect; responseOptions?: ResponseInit; cachePage?: boolean; /** * Expiry time of the cache in seconds */ cacheExpiry?: number; url?: BunextPageModuleServerReturnURLObject; }; export type BunextPageProps = BunextPageModuleServerReturn; export type BunextPageModuleServerReturnURLObject = URL & {}; export type BunextPageModuleServerRedirect = { destination: string; permanent?: boolean; status_code?: number; }; export type BunextPageModuleMetadata = { title?: string; description?: string; }; export type GrabPageComponentRes = { component: JSX.Element; serverRes?: BunextPageModuleServerReturn; routeParams?: BunxRouteParams; bundledMap?: BundlerCTXMap; module: BunextPageModule; meta?: BunextPageModuleMeta; head?: FC; debug?: boolean; }; export type GrabPageReactBundledComponentRes = { component: JSX.Element; server_res?: BunextPageModuleServerReturn; tsx?: string; }; export type PageFiles = { local_path: string; url_path: string; file_name: string; }; export type BundlerCTXMap = { path: string; hash: string; type: string; entrypoint: string; local_path: string; url_path: string; file_name: string; css_path?: string; }; export type GlobalHMRControllerObject = { controller: ReadableStreamDefaultController; page_url: string; target_map?: BundlerCTXMap; page_props?: any; }; export type BunextCacheFileMeta = { date_created: number; paradigm: "html" | "json"; expiry_seconds?: number; };