import type { LinkProps } from "next/link"; import type { Struct } from "superstruct"; import { SitemapGeneratorOptions, SitemapGeneratorType, SitemapRouteResolvers } from "./sitemap-generator"; import { RouteDefinition, RoutesDefinition } from "./types"; export type ExtractSchema = T extends { schema: Struct; } ? U : null; type Options = { shouldBeAbsolute?: boolean; }; type LocaleOptions = { locale: Locales[number]; }; export type FunctionParametersGenerator> = { [K in keyof RouteList]: RouteList[K]["path"] extends string ? "schema" extends keyof RouteList[K] ? [K, ExtractSchema, Options?] : [K, null?, Options?] : "schema" extends keyof RouteList[K] ? [K, ExtractSchema, Options & LocaleOptions] : [K, null, Options & LocaleOptions]; }[keyof RouteList]; export type FunctionParametersGeneratorWithPartialParams> = { [K in keyof RouteList]: "schema" extends keyof RouteList[K] ? [K, Partial>?] : [K, null?]; }[keyof RouteList]; type RouteFunction> = (...args: FunctionParametersGenerator) => LinkProps["href"]; type RouteToUrlFunction> = (...args: FunctionParametersGenerator) => string; export type RouteMatcher = (pathname: string, pathParams?: Record) => boolean; export type RouteInfo = { pathname: string; routeName: string; routeDefinition: RouteDefinition; }; /** * The router. Contains only pure URL/route helpers – no React hooks and no client-only imports * (`next/navigation`, `next/router`), so it is safe to import into React Server Components. * * For the React hooks (`useQueryParams`, `usePageParams`, …) use `createClientRouter` * from `@uxf/router/client`, which is a superset of this router. */ export type Router> = { route: RouteFunction; routeToUrl: RouteToUrlFunction; createSitemapGenerator: (resolvers: SitemapRouteResolvers, options?: SitemapGeneratorOptions) => SitemapGeneratorType; routes: RouteList; getRouteInfo: (pathname: string) => RouteInfo | null; createRouteMatcher: (...args: FunctionParametersGeneratorWithPartialParams) => RouteMatcher; }; export type RouterOptions = { baseUrl?: string; locales?: L; }; export type ExtendedRouteDefinition = RouteDefinition & { regex: RegExp[]; }; export type ExtendedRoutesDefinition = Record>; /** * Creates the router – URL building, route matching and sitemap generation. * * This is the server-safe default: it contains no React hooks and no client-only imports, so it can * be used anywhere, including React Server Components. If you need the React hooks (`useQueryParams`, * `usePageParams`, …) use `createClientRouter` from `@uxf/router/client` instead – it returns * everything this router does plus the hooks. */ export declare function createRouter>(routes: RouteList, routerOptions: RouterOptions): Router; export {};