import { OptionalUrlParam, UrlQueryPart, ToUrlQueryPart, RequiredUrlParam, ToUrlPart, UrlParams, UrlPart } from '../services/withParams'; import { ExtractParamType } from './params'; import { AllPropertiesAreOptional, Identity } from './utilities'; import { UrlString } from './urlString'; import { ParamGetSet } from './paramTypes'; import { MakeOptional } from '../utilities/makeOptional'; export declare const IS_URL_SYMBOL: unique symbol; export type UrlInternal = { [IS_URL_SYMBOL]: true; schema: Record; params: {}; }; export type CreateUrlOptions = { host?: string | UrlPart | undefined; path?: string | UrlPart | undefined; query?: string | UrlQueryPart | undefined; hash?: string | UrlPart | undefined; }; export type ToUrl = Url['params'] & ToUrlPart['params'] & ToUrlQueryPart['params'] & ToUrlPart['params']>>; export declare function isUrl(url: unknown): url is Url & UrlInternal; export type ParseUrlOptions = { /** * Whether to remove trailing slashes from the path. When true, trailing slashes will be removed from the path. * @default true */ removeTrailingSlashes?: boolean; }; /** * Represents the structure of a url parts. Can be used to create a url with support for params. */ export type Url = { /** * @internal * The parameters type for the url. Non functional and undefined at runtime. */ params: TParams; /** * Converts the url parts to a full url. */ stringify(...params: UrlParamsArgs): UrlString; /** * Parses the url supplied and returns any params found. */ parse(url: string, options?: ParseUrlOptions): ToUrlParamsReading; /** * Parses the url supplied and returns any params found. */ tryParse(url: string, options?: ParseUrlOptions): { success: true; params: ToUrlParamsReading; } | { success: false; params: {}; error: Error; }; /** * True if the url is relative. False if the url is absolute. */ isRelative: boolean; }; type UrlParamsArgs = AllPropertiesAreOptional> extends true ? [params?: ToUrlParamsWriting] : [params: ToUrlParamsWriting]; /** * Extracts combined types of path and query parameters for a given url, creating a unified parameter object. * @template TUrl - The url type from which to extract and merge parameter types. * @returns A record of parameter names to their respective types, extracted and merged from both path and query parameters. */ export type UrlParamsReading = ToUrlParamsReading; type ToUrlParamsReading = Identity ? TParam extends Required ? ExtractParamType : ExtractParamType | undefined : TParams[K] extends RequiredUrlParam ? ExtractParamType : unknown; }>>; /** * Extracts combined types of path and query parameters for a given url, creating a unified parameter object. * Differs from ExtractRouteParamTypesReading in that optional params with defaults will remain optional. * @template TUrl - The url type from which to extract and merge parameter types. * @returns A record of parameter names to their respective types, extracted and merged from both path and query parameters. */ export type UrlParamsWriting = ToUrlParamsWriting; type ToUrlParamsWriting = Identity ? ExtractParamType | undefined : TParams[K] extends RequiredUrlParam ? ExtractParamType : unknown; }>>; export {};