/** * Copyright © 2024 650 Industries. * Copyright © 2024 2023 Daishi Kato * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * https://github.com/dai-shi/waku/blob/3d1cc7d714b67b142c847e879c30f0724fc457a7/packages/waku/src/router/create-pages.ts#L1 */ import type { FunctionComponent, ReactNode } from 'react'; import type { RouteProps } from './common.js'; import type { BuildConfig } from '../server.js'; /** * Type version of `String.prototype.split()`. Splits the first string argument by the second string argument * @example * ```ts * // ['a', 'b', 'c'] * type Case1 = Split<'abc', ''> * // ['a', 'b', 'c'] * type Case2 = Split<'a,b,c', ','> * ``` */ type Split = string extends Str ? string[] : '' extends Str ? [] : Str extends `${infer T}${Del}${infer U}` ? [T, ...Split] : [Str]; /** Assumes that the path is a part of a slug path. */ type IsValidPathItem = T extends `/${infer _}` ? false : T extends '[]' | '' ? 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; type _GetSlugs, Result extends string[] = []> = SplitRoute extends [] ? Result : SplitRoute extends [`${infer MaybeSlug}`, ...infer Rest] ? Rest extends string[] ? MaybeSlug extends `[${infer Slug}]` ? _GetSlugs : _GetSlugs : never : Result; export type GetSlugs = _GetSlugs; export type StaticSlugRoutePathsTuple, Result extends string[] = []> = Slugs extends [] ? Result : Slugs extends [infer _, ...infer Rest] ? StaticSlugRoutePathsTuple : never; type StaticSlugRoutePaths = HasWildcardInPath extends true ? string[] | string[][] : StaticSlugRoutePathsTuple extends [string] ? 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; export type PathWithWildcard = PathWithSlug; export type CreatePage = (page: ({ render: 'static'; path: PathWithoutSlug; component: FunctionComponent; } | { render: 'static'; path: PathWithStaticSlugs; staticPaths: StaticSlugRoutePaths; component: FunctionComponent>; } | { render: 'dynamic'; path: PathWithoutSlug; component: FunctionComponent; } | { render: 'dynamic'; path: PathWithWildcard; component: FunctionComponent & Record>; }) & { unstable_disableSSR?: boolean; }) => void; export type CreateLayout = (layout: { render: 'static' | 'dynamic'; path: PathWithoutSlug; component: FunctionComponent & { children: ReactNode; }>; }) => void; export declare function createPages(fn: (fns: { createPage: CreatePage; createLayout: CreateLayout; unstable_setBuildData: (path: string, data: unknown) => void; }, opts: { unstable_buildConfig: BuildConfig | undefined; }) => Promise): { renderEntries: import("../server.js").RenderEntries; getBuildConfig: import("../server.js").GetBuildConfig | undefined; getSsrConfig: import("../server.js").GetSsrConfig | undefined; }; export {}; //# sourceMappingURL=create-pages.d.ts.map