1 | import type { StaticPath, StaticPropsContext } from './utils/router';
|
2 | import type { createPrefetch } from './utils/prefetch';
|
3 | import { ComponentProps, JSX, ComponentType } from "preact";
|
4 | declare type RestParam<S extends string> = S extends `...${infer A}` ? A : never;
|
5 | declare type StandardParam<S extends string> = S extends `...${infer A}` ? never : S;
|
6 | declare type ExtractParams<S extends string> = S extends `[${infer A}]` ? A : never;
|
7 | declare type TupleToUnion<T extends any[]> = T[number];
|
8 | declare type Split<S extends string> = string extends S ? string[] : S extends '' ? [] : S extends `${infer T}/${infer U}` ? [T, ...Split<U>] : [
|
9 | S
|
10 | ];
|
11 | declare type NormalizePath<S extends string> = S extends `/${infer T}` ? T : S;
|
12 | declare type AllPathParams<S extends string, P extends string = ExtractParams<TupleToUnion<Split<NormalizePath<S>>>>> = {
|
13 | [param in P]: string | string[];
|
14 | };
|
15 | declare type RestParams<S extends string, Base extends string = keyof AllPathParams<S>> = {
|
16 | [a in RestParam<Base>]: string[];
|
17 | };
|
18 | declare type StandardParams<S extends string, Base extends string = keyof AllPathParams<S>> = {
|
19 | [a in StandardParam<Base>]: string;
|
20 | };
|
21 | export declare type PathParams<S extends string> = RestParams<S> & StandardParams<S>;
|
22 | export interface GetStaticPaths<Path extends string, P extends PathParams<Path>> {
|
23 | (ctx: {
|
24 | prefetch?: ReturnType<typeof createPrefetch>;
|
25 | }): Promise<{
|
26 | paths: StaticPath<P>[];
|
27 | } | string | null>;
|
28 | }
|
29 | export interface GetStaticProps<T extends ComponentType<any> | keyof JSX.IntrinsicElements, Path extends string, P extends PathParams<Path>> {
|
30 | (ctx: StaticPropsContext<P> & {
|
31 | prefetch?: ReturnType<typeof createPrefetch>;
|
32 | }): Promise<{
|
33 | props: ComponentProps<T>;
|
34 | } | string | null>;
|
35 | }
|
36 | export interface Page<T extends ComponentType<any> | keyof JSX.IntrinsicElements, Path extends string, P extends PathParams<Path>> {
|
37 | path?: Path;
|
38 | getStaticPaths?: GetStaticPaths<Path, P>;
|
39 | getStaticProps?: GetStaticProps<T, Path, P>;
|
40 | }
|
41 | export declare function definePage<T extends ComponentType<any> | keyof JSX.IntrinsicElements, Path extends string, P extends PathParams<Path>>(Component: T, page?: Page<T, Path, P>): {
|
42 | path?: Path;
|
43 | getStaticPaths?: GetStaticPaths<Path, P>;
|
44 | getStaticProps?: GetStaticProps<T, Path, P>;
|
45 | Component: T;
|
46 | };
|
47 | export {};
|