import type { FunctionComponent, ReactNode } from 'react'; import type { RouteProps } from './common.js'; import type { AnyPage, GetSlugs, PropsForPages } from './create-pages-utils/inferred-path-types.js'; export declare const METHODS: readonly ["GET", "HEAD", "POST", "PUT", "DELETE", "CONNECT", "OPTIONS", "TRACE", "PATCH"]; export type Method = (typeof METHODS)[number]; /** Assumes that the path is a part of a slug path. */ type IsValidPathItem = T extends `/${string}` | '[]' | '' ? false : true; /** * This is a helper type to check if a path is valid in a slug path. */ export type IsValidPathInSlugPath = T extends `/${infer L}/${infer R}` ? IsValidPathItem extends true ? IsValidPathInSlugPath<`/${R}`> : false : T extends `/${infer U}` ? IsValidPathItem : false; /** Checks if a particular slug name exists in a path. */ export type HasSlugInPath = T extends `/[${K}]/${infer _}` ? true : T extends `/${infer _}/${infer U}` ? HasSlugInPath<`/${U}`, K> : T extends `/[${K}]` ? true : false; export type HasWildcardInPath = T extends `/[...${string}]/${string}` ? true : T extends `/${infer _}/${infer U}` ? HasWildcardInPath<`/${U}`> : T extends `/[...${string}]` ? true : false; export type PathWithSlug = IsValidPathInSlugPath extends true ? HasSlugInPath extends true ? T : never : never; export type StaticSlugRoutePathsTuple, Result extends readonly string[] = []> = Slugs extends [] ? Result : Slugs extends [infer _, ...infer Rest] ? StaticSlugRoutePathsTuple : never; type StaticSlugRoutePaths = HasWildcardInPath extends true ? readonly string[] | readonly string[][] : StaticSlugRoutePathsTuple extends readonly [string] ? readonly string[] : StaticSlugRoutePathsTuple[]; /** Remove Slug from Path */ export type PathWithoutSlug = T extends '/' ? T : IsValidPathInSlugPath extends true ? HasSlugInPath extends true ? never : T : never; type PathWithStaticSlugs = T extends `/` ? T : IsValidPathInSlugPath extends true ? T : never; export type PathWithWildcard = PathWithSlug; export type CreatePage = , ExactPath extends boolean | undefined = undefined>(page: ({ render: Extract; path: PathWithoutSlug; component: FunctionComponent>; } | ({ render: Extract; path: PathWithStaticSlugs; component: FunctionComponent>; } & (ExactPath extends true ? {} : { staticPaths: StaticPaths; })) | { render: Extract; path: PathWithoutSlug; component: FunctionComponent>; } | { render: Extract; path: PathWithWildcard; component: FunctionComponent>; }) & { unstable_disableSSR?: boolean; /** * If true, the path will be matched exactly, without wildcards or slugs. * This is intended for extending support to create custom routers. */ exactPath?: ExactPath; }) => Omit, 'unstable_disableSSR'>; export type CreateLayout = (layout: { render: 'dynamic'; path: Path; component: FunctionComponent & { children: ReactNode; }>; } | { render: 'static'; path: Path; component: FunctionComponent<{ children: ReactNode; }>; }) => void; type ApiHandler = (req: Request) => Promise; export type CreateApi = (params: { render: 'static'; path: Path; method: 'GET'; handler: ApiHandler; } | { render: 'dynamic'; path: Path; handlers: Partial>; }) => void; type RootItem = { render: 'static' | 'dynamic'; component: FunctionComponent<{ children: ReactNode; }>; }; export type CreateRoot = (root: RootItem) => void; export declare const createPages: )[]>(fn: (fns: { createPage: CreatePage; createLayout: CreateLayout; createRoot: CreateRoot; createApi: CreateApi; }) => Promise) => { handleRequest: import("../lib/types.js").HandleRequest; handleBuild: import("../lib/types.js").HandleBuild; } & { /** This for type inference of the router only. We do not actually return anything for this type. */ DO_NOT_USE_pages: Exclude | undefined, undefined>>, void>[number], void>; }; export {};