import type { EmptyObject } from 'type-fest'; import type Resolver from './resolver.js'; import type { NotFoundResult } from './utils.js'; /** * Represents either a value or a promise of a value. * * @typeParam T - The type of the value. */ export type MaybePromise = Promise | T; /** * A result of a {@link Route.action}. * * @typeParam T - The type of the result. */ export type ActionResult = T | NotFoundResult | null | undefined | void; /** * A function that dynamically creates children of a route. * * @typeParam T - The type of the result produced by the route. * @typeParam R - The type of additional route-specific data. Defaults to an * empty object. * @typeParam C - The type of user-defined context-specific data. Defaults to an * empty object. * * @param context - The context of the current route. * * @deprecated The route children callback is deprecated and will be removed in * the next major version. * * @interface */ export type ChildrenCallback = (context: RouteChildrenContext) => MaybePromise | ReadonlyArray> | void>; /** * Defines a single route. * * A route represents a single or multiple sections in the URL. It defines the * behavior of a page in response to URL updates. A route can act as a content * producer or as middleware for child routes. * * @typeParam T - The type of the result produced by the route. * @typeParam R - The type of additional route-specific data. Defaults to an * empty object. * @typeParam C - The type of user-defined context-specific data. Defaults to an * empty object. * * @interface */ export type Route = Readonly<{ /** * The name of the route. */ name?: string; /** * The path pattern that the route matches. */ path: string; /** * An action that is executed when the route is resolved. * * Actions are executed recursively from the root route to the child route and * can either produce content or perform actions before or after the child's * action. * * @param context - The context of the current route. * * @returns The result of the route resolution. It could be either a value * produced by the action or a new context to continue the resolution process. * * @internal */ action?(this: Route, context: RouteContext, commands: never): MaybePromise>>; }> & { /** @internal */ __children?: ReadonlyArray>; /** @internal */ __synthetic?: true; children?: ReadonlyArray> | ChildrenCallback; parent?: Route; fullPath?: string; } & R; /** * A matched route with its associated path. * * @typeParam T - The type of the result produced by the route. * @typeParam R - The type of additional route-specific data. Defaults to an * empty object. * @typeParam C - The type of user-defined context-specific data. Defaults to an * empty object. * * @internal */ export type Match = Readonly<{ /** The path of the matched route. */ path: string; /** The route object associated with the matched path. */ route?: Route; }>; /** * An item of the resolved route sequence. * * @typeParam T - The type of the result produced by the route. * @typeParam R - The type of additional route-specific data. Defaults to an * empty object. * @typeParam C - The type of user-defined context-specific data. Defaults to an * empty object. * * @interface */ export type ChainItem = { /** A DOM element associated with the route. */ element?: Element; /** The path of the route. */ path: string; /** The route object containing route-specific information. */ route: Route; }; /** * The context for a `resolve` operation that can be extended with * the user-defined properties. * * @typeParam C - The type of user-defined context-specific data. Defaults to an * empty object. * * @interface */ export type ResolveContext = Readonly<{ /** The current location. */ pathname: string; }> & C; /** * The context for a {@link Route.action} that could be used to access the * route-specific data during the resolution process. * * @typeParam T - The type of the result produced by the route. * @typeParam R - The type of additional route-specific data. Defaults to * `EmptyObject`. * @typeParam C - The type of additional context-specific data. Defaults to * `EmptyObject`. * * @interface */ export type RouteContext = Readonly<{ /** * The {@link https://developer.mozilla.org/en-US/docs/Web/API/URL/hash | hash} * fragment of the URL. */ hash?: string; /** * The {@link https://developer.mozilla.org/en-US/docs/Web/API/URL/search | search} * query string of the URL. */ search?: string; /** * The sequence of the resolved route items, so said the path from the root * route to the current route. */ chain?: Array>; /** * The parameters resolved from the current URL. */ params: IndexedParams; /** * The resolver instance. */ resolver?: Resolver; /** * The URL from which a redirect occurred. */ redirectFrom?: string; /** * The current route. */ route: Route; /** * Proceed to the next route in the chain, down the route tree. */ next(resume?: boolean, parent?: Route, prevResult?: ActionResult>): Promise>>; }> & { /** @internal */ __divergedChainIndex?: number; /** @internal */ __redirectCount?: number; /** @internal */ __renderId: number; /** @internal */ __skipAttach?: boolean; /** * The result of the route resolution. It could be either a value produced by * the {@link Route.action} or a new context to continue the resolution * process. */ result?: T | RouteContext; } & ResolveContext; /** * Represents the context that is accessible from the route children callback. * It is the a {@link RouteContext} without the 'next' property. * * @typeParam T - The type of the route parameters. * @typeParam R - The type of the route's resolved data. Defaults to `EmptyObject`. * @typeParam C - The type of the route's context. Defaults to `EmptyObject`. * * @deprecated The route children callback is deprecated and will be removed in * the next major version. * * @interface */ export type RouteChildrenContext = Omit, 'next'>; export type PrimitiveParamValue = string | number | null; /** * The value of a parameter resolved from the URL. */ export type ParamValue = PrimitiveParamValue | readonly PrimitiveParamValue[]; /** * The collection of parameters resolved from the URL. * * @remarks * Parameters are the parts of the URL represented by the placeholders in the * route path. Placeholders are often named, and these names become the keys of * the `IndexedParams` object. * * If a placeholder is unnamed, its index in the path becomes the key. */ export type IndexedParams = Readonly>; export type Params = IndexedParams | ParamValue[]; //# sourceMappingURL=types.t.d.ts.map