import type { FunctionComponent, ReactNode } from 'react'; import type { ApiHandler, HandlerInterceptor, RuntimeConfig } from './create-pages-utils/config.js'; import type { AnyPage, GetSlugs, PropsForPages, RouteParams, SharedLayoutParams } from './create-pages-utils/inferred-path-types.js'; import { getPathMapping } from './isomorphic-utils/path-spec.js'; import type { SearchCodec } from './isomorphic-utils/search-codec.js'; type Method = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH' | 'QUERY'; export declare const getPathMappingWithoutGroupsForTest: typeof getPathMapping; type IsValidPathItem = T extends `/${string}` | '[]' | '' ? false : true; type IsValidPathInSlugPath = T extends `/${infer L}/${infer R}` ? IsValidPathItem extends true ? IsValidPathInSlugPath<`/${R}`> : false : T extends `/${infer U}` ? IsValidPathItem : false; export type IsValidPathInSlugPathForTest = IsValidPathInSlugPath; type HasSlugInPath = T extends `/${string}[${K}]${string}/${infer _Rest}` ? true : T extends `/${infer _}/${infer U}` ? HasSlugInPath<`/${U}`, K> : T extends `/${string}[${K}]${string}` ? true : false; export type HasSlugInPathForTest = HasSlugInPath; type HasWildcardInPath = T extends `/[...${string}]/${string}` ? true : T extends `/${infer _}/${infer U}` ? HasWildcardInPath<`/${U}`> : T extends `/[...${string}]` ? true : false; export type HasWildcardInPathForTest = HasWildcardInPath; type PathWithSlug = IsValidPathInSlugPath extends true ? HasSlugInPath extends true ? T : never : never; export type PathWithSlugForTest = PathWithSlug; type StaticSlugRoutePathsTuple, Result extends readonly string[] = []> = Slugs extends [] ? Result : Slugs extends [infer _, ...infer Rest] ? StaticSlugRoutePathsTuple : never; export type StaticSlugRoutePathsTupleForTest, Result extends readonly string[] = []> = StaticSlugRoutePathsTuple; type StaticSlugRoutePaths = HasWildcardInPath extends true ? readonly string[] | readonly string[][] : StaticSlugRoutePathsTuple extends readonly [string] ? readonly string[] : StaticSlugRoutePathsTuple[]; 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; type PathWithWildcard = PathWithSlug; export type PathWithWildcardForTest = PathWithWildcard; /** * Returns a `dynamic` slot's element tag (etag). While the tag is unchanged the * client reuses its cached element instead of receiving it again. Only consulted * for dynamic slots. * * - Opaque to Waku; compared with `===`. * - Must change whenever the rendered content would. * - Keep it a short ASCII string (a hash or version): the client echoes its * tags in a header. A non-header-safe or empty value is treated as no tag. * - Return `undefined` for no tag: the element is always sent, overriding the * client's cache for the slot. */ type GetEtag = (props: Props) => Promise; export type CreatePage = , ExactPath extends boolean | undefined = undefined, Slices extends string[] = []>(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>; } | { component: null; }) & { unstable_noSsr?: boolean; /** * If true, the path will be matched exactly, without wildcards or slugs. * File-based pages set it in `getConfig`. */ exactPath?: ExactPath; /** * List of slice ids used in the component. * This is _required_ to send the slices along with the component. */ slices?: Slices; /** * Source file path of the page module, relative to `/` * (e.g. `pages/foo.tsx`). When set, the framework can prune the module's * chunks from the runtime server bundle if the route is fully static. */ unstable_sourceFile?: string | undefined; /** * Per-render element tag (etag) for a `dynamic` page. Ignored for `static` * pages. */ unstable_getEtag?: GetEtag>; /** * Bring-your-own search-params codec for this route. The server parses the * `query` with it (rejecting a malformed query as 400 and injecting a typed * `search` prop). Share the codec with a local href factory or search hooks. * The page's `search` type is declared via `SearchCodecsConfig` or generated * by fs-router typegen. */ unstable_searchCodec?: SearchCodec; }) => Omit, { render: 'static' | 'dynamic'; }>, 'unstable_noSsr'>; export type CreateLayout = | undefined = undefined>(layout: ({ render: 'dynamic'; path: Path; component: FunctionComponent<{ children: ReactNode; } & RouteParams>; unstable_sourceFile?: string | undefined; } | { render: 'static'; path: Path; component: FunctionComponent<{ children: ReactNode; } & (StaticPaths extends undefined ? SharedLayoutParams : RouteParams)>; /** * The param values to prerender the layout with. Dynamic pages below * it answer only these values; other values are not found. Without * it, dynamic pages share one render with unknown params `undefined`. */ staticPaths?: StaticPaths; unstable_sourceFile?: string | undefined; } | { component: null; }) & { /** * Per-render element tag (etag) for a `dynamic` layout. Ignored for `static` * layouts. */ unstable_getEtag?: GetEtag>; }) => void; export type CreateApi = (params: { render: 'static'; path: Path; method: 'GET'; handler: ApiHandler; staticPaths?: (string | string[])[] | undefined; unstable_sourceFile?: string | undefined; } | { render: 'dynamic'; path: Path; /** * Handlers by named method. Use `all` to handle all methods. * Named methods will take precedence over `all`. */ handlers: Partial>; unstable_sourceFile?: string | undefined; } | { render: 'static'; handler: null; } | { render: 'dynamic'; handlers: null; }) => void; type SlugPropsFromId = GetSlugs<`/${ID}`> extends never[] ? {} : GetSlugs<`/${ID}`> extends string[] ? { [K in GetSlugs<`/${ID}`>[number]]: string; } : {}; export type CreateSlice = >(slice: ({ render: 'dynamic'; id: ID; component: FunctionComponent<{ children: ReactNode; } & SlugPropsFromId>; unstable_sourceFile?: string | undefined; } | { render: 'static'; id: PathWithoutSlug<`/${ID}`> extends never ? never : ID; component: FunctionComponent<{ children: ReactNode; }>; unstable_sourceFile?: string | undefined; } | { render: 'static'; id: PathWithStaticSlugs<`/${ID}`> extends never ? never : ID; component: FunctionComponent<{ children: ReactNode; } & SlugPropsFromId>; staticPaths: StaticPaths; unstable_sourceFile?: string | undefined; } | { component: null; }) & { /** * Per-render element tag (etag) for a `dynamic` slice. Ignored for `static` * slices. */ unstable_getEtag?: GetEtag>; }) => void; type RootItem = { render: 'static' | 'dynamic'; component: FunctionComponent<{ children: ReactNode; }>; unstable_sourceFile?: string | undefined; /** * Per-render element tag (etag) for a `dynamic` root. Ignored for a `static` * root. The root takes no props, so the getter is parameterless. */ unstable_getEtag?: () => Promise; }; export type CreateRoot = (root: RootItem | { component: null; }) => void; export type CreateInterceptor = (interceptor: HandlerInterceptor) => void; export declare function createPages)[]>(fn: (fns: { createPage: CreatePage; createLayout: CreateLayout; createRoot: CreateRoot; createApi: CreateApi; createSlice: CreateSlice; createInterceptor: CreateInterceptor; }) => Promise, options?: { unstable_skipBuild?: (routePath: string) => boolean; }): { unstable_getRouterConfigs: () => Promise; handleRequest: import("../lib/types.js").HandleRequest; handleBuild: import("../lib/types.js").HandleBuild; unstable_routerOptions: { resolve: import("./define-router-utils/route-entries.js").Resolve; getBuildPaths?: () => Promise>; getBuildElementIds?: () => Promise>; resolveElement?: import("./define-router-utils/route-entries.js").ResolveElement; getHas404?: () => Promise; unstable_interceptors?: import("./define-router.js").HandlerInterceptor[]; initialize?: () => Promise; getPrunableFiles?: () => Promise>; }; } & { /** 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 {};