import { _ as LooseTypedRequest, a as RouteTree, b as TypedResponse, c as HTTPMethod, d as ResponseHeaderMap, f as ResponseHeaderName, g as LooseTypedHeaders, h as MimeType, i as Endpoints, l as RequestHeaders, m as RequestHeaderName, n as Endpoint, o as StaticParam, p as RequestHeaderMap, s as WildcardParam, t as DynamicParam, u as ResponseHeaders, v as TypedHeaders, y as TypedRequest } from "./tree-DXKy8PY7.mjs"; //#region src/http/url.d.ts interface TypedURLSearchParams | unknown = Partial>> extends Omit { /** * Appends a specified key/value pair as a new search parameter. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/append) */ append: | string & {}>(name: Name, value: Name extends keyof QueryMap ? QueryMap[Name] extends string ? QueryMap[Name] : string : string) => void; /** * Deletes the given search parameter, and its associated value, from the list of all search parameters. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/delete) */ delete: | string & {}>(name: Name, value?: Name extends keyof QueryMap ? QueryMap[Name] extends string ? QueryMap[Name] : string : string) => void; /** * Returns the first value associated to the given search parameter. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/get) */ get: | string & {}>(name: Name) => (Name extends keyof QueryMap ? QueryMap[Name] extends string ? QueryMap[Name] : string : string) | null; /** * Returns all the values association with a given search parameter. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/getAll) */ getAll: | string & {}>(name: Name) => Array; /** * Returns a Boolean indicating if such a search parameter exists. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/has) */ has: | string & {}>(name: Name, value?: Name extends keyof QueryMap ? QueryMap[Name] extends string ? QueryMap[Name] : string : string) => boolean; /** * Sets the value associated to a given search parameter to the given value. If there were several values, delete the others. * * [MDN Reference](https://developer.mozilla.org/docs/Web/API/URLSearchParams/set) */ set: | string & {}>(name: Name, value: Name extends keyof QueryMap ? QueryMap[Name] extends string ? QueryMap[Name] : string : string) => void; forEach: (callbackfn: (value: Extract | string & {}, key: Extract | string & {}, parent: URLSearchParams) => void, thisArg?: any) => void; } //#endregion //#region src/utils.d.ts type RespectOptionality = (Key extends keyof T ? T[Key] extends NonNullable ? { [K in Key]-?: T[Key]; } : { [K in Key]?: T[Key]; } : { [K in Key]?: Fallback; }); type WithoutQuery = T extends `${infer U}?${string}` ? U : T; type WithoutHash = T extends `${infer U}#${string}` ? U : T; type WithoutQueryOrHash = WithoutQuery>; type WithoutTrailingSlash = T extends `${infer U}/` ? U : T; type Trimmed = WithoutTrailingSlash>; //#endregion //#region src/inference.d.ts /** A method in either case, as a router compares them case-insensitively. */ type AnyHTTPMethod = HTTPMethod | Lowercase; /** The uppercase form of a method, leaving the method-agnostic `''` alone. */ type NormalizeMethod = Method extends "" ? "" : Uppercase; /** Whether an endpoint answers `Method`. A `GET` route also answers `HEAD`, as in a router. */ type HasMethod = Method extends keyof Endpoints ? true : Method extends "HEAD" ? "GET" extends keyof Endpoints ? true : false : false; /** * The shape any path may take, for constraining the parameter a path is inferred into. * * A pattern rather than `string`: a literal inferred into a parameter constrained by `string` widens, * and keeps its literal type where the constraint is a pattern. */ type AnyFetchPath = `/${string}` | `${string}://${string}`; /** * Every path in `Schema`, optionally narrowed to those answering `Method`. * * Materialise it before using it as a constraint (`Extract, string>`), or a * union holding template literal members is re-instantiated at every call site. Applying `Extract` * here instead exhausts the instantiation depth limit. */ type TypedFetchInput = TypedFetchPath>; /** The path a walk arriving at an endpoint has built. A root endpoint is requested as `/`. */ type PathSoFar = Base extends "" ? "/" : Base; type TypedFetchPath = { [K in keyof Schema]: K extends typeof Endpoint ? "" extends Method ? PathSoFar : HasMethod extends true ? PathSoFar : never : K extends StaticParam ? Schema[K] extends Record ? TypedFetchPath : never : K extends typeof DynamicParam ? Schema[K] extends Record ? TypedFetchPath : never : K extends typeof WildcardParam ? Schema[K] extends Record ? TypedFetchPath | TypedFetchPath : never : never; }[keyof Schema]; /** * Whether `Path` resolves to an endpoint, for use in parameter position: * `input: T & ValidFetchInput`. A path that resolves gives `unknown`, leaving the * parameter as `T`; one that does not gives a type no string satisfies, whose single key carries the * reason. The text of that key is a diagnostic and may change. * * Intersect it with the whole parameter, never with the path inside it: TypeScript cannot infer * through an intersection, so `MaybeRefOrGetter>` leaves `T` at its * constraint. For the same reason a signature that must accept `` `/users/${id}` `` validates the * method instead; see {@link TypedFetchMethods}. * * An input that is not a path, such as a `Request`, carries nothing to check and is accepted. */ type ValidFetchInput = [Path] extends [string] ? [UnmatchedPath] extends [never] ? unknown : { [K in FetchInputError, Method>]: never; } : unknown; /** * The members of `Path` that resolve to no endpoint. Every member must resolve, so a value narrowed * to one of several paths cannot pass on the strength of one, and a path known only to be a `string` * is rejected. */ type UnmatchedPath = Path extends string ? [TypedFetchResolvedMeta] extends [never] ? Path : never : never; type FetchInputError = "" extends Method ? `fetchdts: no route matches '${Path}'` : `fetchdts: no ${Uppercase} route matches '${Path}'`; /** * Metadata for the endpoint `Path` resolves to, parameters included, as a router would resolve it. * {@link TypedFetchMeta} considers static segments only. */ type TypedFetchResolvedMeta = TypedFetchMeta : Path, Method, "dynamic">; type RequestInitFor = { [K in keyof Omit]?: K extends keyof Meta ? Meta[K] : RequestInit[K]; } & ("method" extends keyof Meta ? "GET" extends Meta["method"] ? { method?: WritableMethod; } : { method: WritableMethod; } : { method?: RequestInit["method"]; }) & RespectOptionality; /** A method as it may be written at a call site, in either case. */ type WritableMethod = Method | Lowercase; /** * The init for a request to `Path`. Pass `Method` where it is known: a path may reach one endpoint * for one method and another for a second, so a method-agnostic init describes only what they share. */ type TypedFetchRequestInit = RequestInitFor>; /** * How a path is matched against a schema. * * - `exact`: static segments only. * - `dynamic`: parameters are considered where no static segment matches. * - `ambiguous`: as `dynamic`, but a parameter has consumed a segment known only at runtime, so the * request could also have matched a static sibling. Every sibling the segment could be is * followed, and {@link EndpointMetadata.ambiguousResponse} is preferred where an endpoint declares * one. */ type MatchPattern = "exact" | "dynamic" | "ambiguous"; /** * Endpoints reached by matching `Path` against the static keys of `Schema`. * * The leading segment is looked up as a key, which costs the same whatever the node holds. The scan * remains for a key spanning several segments, which a lookup cannot find. */ type StaticMatch = LookupHead, Path, Method, Pattern>; /** The key `Path` begins with: its first segment, or its origin. `never` where it has neither. */ type HeadKey = Path extends `/${infer Rest}` ? Rest extends `${infer Head}/${string}` ? Head extends "" ? never : `/${Head}` : Rest extends "" ? never : Path : Path extends `${infer Scheme}://${infer Rest}` ? Rest extends `${infer Host}/${string}` ? `${Scheme}://${Host}` : Path : never; /** The remainder of `Path` after the key {@link HeadKey} consumed. */ type AfterHead = Path extends `/${string}` ? AfterSegment : Path extends `${string}://${infer Rest}` ? Rest extends `${infer Host}/${string}` ? Path extends `${string}://${Host}${infer Tail}` ? Tail : never : "" : never; type LookupHead = [Head] extends [never] ? ScannedStaticMatch : Head extends keyof Schema ? OrScanned, Method, Pattern>, Schema, Path, Method, Pattern> : ScannedStaticMatch; /** * The lookup, or the scan where it found nothing: a node may hold a key spanning several segments * beside a key for the first of them. */ type OrScanned = [Keyed] extends [never] ? ScannedStaticMatch : Keyed; /** Endpoints reached by matching `Path` against each static key of `Schema` in turn. */ type ScannedStaticMatch = { [K in keyof Schema]: K extends StaticParam ? Path extends `${K}${infer Rest}` ? MatchPath : never : never; }[keyof Schema]; /** * Endpoints reached where the segment being consumed is not fully known, so a key it *could* be is * followed as well as one it is: `` `/api/${string}/posts` `` reaches `/api/me/posts`. * * Only a single-segment key qualifies, since a parameter consumes one segment; a key spanning several * is assignable to `` `/${string}` `` and would be reached by a path a router resolves elsewhere. */ type PartialStaticMatch = { [K in keyof Schema]: K extends StaticParam ? Path extends `${K}${infer Rest}` ? MatchPath : SingleSegment extends true ? Overlaps, K> extends true ? MatchPath, Method, "ambiguous"> : never : never : never; }[keyof Schema]; /** Whether a key holds exactly one path segment, which is what a parameter consumes. */ type SingleSegment = Key extends `/${infer Rest}` ? Rest extends `${string}/${string}` ? false : true : false; /** Whether two segments have any instantiation in common. */ type Overlaps = [Segment] extends [Key] ? true : [Key] extends [Segment] ? true : false; /** Endpoints reached by consuming a segment of `Path` with a dynamic parameter. */ type DynamicMatch = { [K in keyof Schema]: K extends typeof DynamicParam ? MatchPath, Method, LiteralSegment extends false ? "ambiguous" : Pattern> : never; }[keyof Schema]; /** * Endpoints reached by consuming the remainder of `Path` with a wildcard, which takes zero or more * segments: `/files/**` answers `/files` as well as `/files/a/b`. The remainder must begin at a * segment boundary, so `/filesystem` does not reach the wildcard under `/files`. * * A wildcard is terminal, so its endpoints are read directly: walking into it would re-enter this * type, which against an unresolved path expands both branches at every level. */ type WildcardMatch = Path extends "" | `/${string}` ? { [K in keyof Schema]: K extends typeof WildcardParam ? NodeMeta : never; }[keyof Schema] : never; /** * The static match, or the parameter match where there is none. Where no method was requested, a * parameter sibling still answers the methods the static node does not. * * The static match is passed in rather than computed here, since an unresolved path defers every * conditional in the walk and the chain has a limit. */ type PreferStatic = [Static] extends [never] ? ParamMatch : "" extends Method ? Static | ExceptMethods, MethodsOf> : Static; /** * Endpoints reached by consuming a segment of `Path` with a parameter. A dynamic parameter is more * specific than a wildcard, as it is in a router, so the wildcard is consulted only for what the * dynamic parameter does not answer. */ type ParamMatch = [DynamicMatch] extends [never] ? WildcardMatch : "" extends Method ? DynamicMatch | ExceptMethods, MethodsOf>> : DynamicMatch; type MethodsOf = Meta extends { method: infer Method; } ? Method : never; type ExceptMethods = Meta extends { method: infer Method; } ? [Method] extends [Methods] ? never : Meta : never; /** * Metadata for the endpoints registered directly on a node, narrowed by `Method` * when one is provided. */ type EndpointMeta = "" extends Method ? { [M in keyof Endpoints]: { method: M; } & Ambiguate; }[keyof Endpoints] | HeadMeta : Method extends keyof Endpoints ? Ambiguate & { method: Method; } : Method extends "HEAD" ? [GetEndpoint] extends [never] ? never : Ambiguate, Pattern> & { method: "HEAD"; } : never; /** The `GET` endpoint of a node, or `never` where it has none. */ type GetEndpoint = Endpoints[Extract<"GET", keyof Endpoints>]; /** The implicit `HEAD` endpoint a `GET` route provides, unless the node registers one itself. */ type HeadMeta = "HEAD" extends keyof Endpoints ? never : [GetEndpoint] extends [never] ? never : { method: "HEAD"; } & Ambiguate, Pattern>; /** * Replaces `response` with `ambiguousResponse` where a parameter consumed a segment known only at * runtime and the endpoint declares one. Otherwise the alternatives come from the static siblings the * request could also have matched. */ type Ambiguate = Pattern extends "ambiguous" ? "ambiguousResponse" extends keyof Metadata ? { [K in Exclude]: K extends "response" ? Metadata["ambiguousResponse"] : Metadata[K]; } : Metadata : Metadata; /** Whether the segment `Path` is about to consume is a literal rather than `string`-like. */ type LiteralSegment = Path extends `/${infer Rest}` ? Rest extends `${infer Head}/${string}` ? string extends Head ? false : true : string extends Rest ? false : true : true; /** * Whether the segment `Path` is about to consume is known in full. One holding a placeholder * anywhere, including behind a literal prefix (`/item-${string}`), may turn out to be a sibling. */ type KnownSegment = EmptyObject extends Record ? [Segment] extends [never] ? true : EmptyObject extends Record, 1> ? false : true : true; type EmptyObject = Record; /** Metadata for the endpoints registered on a node itself. */ type NodeMeta = typeof Endpoint extends keyof Schema ? EndpointMeta : never; /** The first non-empty segment of `Path`, including its leading slash. */ type Segment = Path extends `/${infer Rest}` ? Rest extends `${infer Head}/${string}` ? Head extends "" ? never : `/${Head}` : Rest extends "" ? never : Path : never; /** The remainder of `Path` after consuming a single non-empty segment. */ type AfterSegment = Path extends `/${infer Rest}` ? Rest extends `${infer Head}/${string}` ? Head extends "" ? never : Path extends `/${Head}${infer Tail}` ? Tail : never : Rest extends "" ? never : "" : never; type TypedFetchMeta = MatchPath, Pattern>; type MatchPath = Path extends "" ? Pattern extends "dynamic" | "ambiguous" ? [NodeMeta] extends [never] ? WildcardMatch : "" extends Method ? NodeMeta | ExceptMethods, MethodsOf>> : NodeMeta : NodeMeta : Path extends string ? Pattern extends "dynamic" | "ambiguous" ? KnownSegment extends false ? PartialStaticMatch | ParamMatch : PreferStatic, Schema, Path, Method, Pattern> : StaticMatch : never; /** * The response body, or `unknown` where the endpoint declares none, so a route registered without a * return type stays callable. A path that matches nothing, or an unregistered method, is `never`. */ type TypedFetchResponseBody = [Endpoint] extends [string] ? ResolvedResponseBody : unknown; type ResolvedResponseBody = "response" extends keyof TypedFetchResolvedMeta ? TypedFetchResolvedMeta["response"] : [TypedFetchResolvedMeta] extends [never] ? never : unknown; /** * The body a request fails with, where the endpoint declares one. `unknown` where it does not, since * declaring nothing says nothing about failure rather than ruling it out. */ type TypedFetchErrorBody = [Endpoint] extends [string] ? "errorResponse" extends keyof TypedFetchResolvedMeta ? TypedFetchResolvedMeta["errorResponse"] : unknown : unknown; /** * The shape an endpoint declares for one field of the request, or `Fallback` where it declares none. * * A whole request init cannot be extended by an interface, since an interface may only extend a type * whose members are statically known and a deferred conditional's are not (`TS2312`). An extensible * options type writes the keys itself and takes the values from here. * * Pass `never` as the fallback to tell a declared shape from an absent one, which is what lets a * client widen only the declared case: an endpoint declares the headers it requires, not the only * ones a request may carry. */ type TypedFetchRequestBody = DeclaredField; type TypedFetchRequestQuery> = DeclaredField; type TypedFetchRequestHeaders = DeclaredField; type DeclaredField = [TypedFetchResolvedMeta] extends [never] ? Fallback : Field extends keyof TypedFetchResolvedMeta ? TypedFetchResolvedMeta[Field] : Fallback; /** * Whether the endpoint requires `Field`, for a consumer deciding which members of its own options * type to make required. A field declared optional, or not declared, is not required. */ type TypedFetchRequires = [TypedFetchResolvedMeta] extends [never] ? false : Field extends keyof TypedFetchResolvedMeta ? [TypedFetchResolvedMeta[Field]] extends [NonNullable[Field]>] ? true : false : false; /** * The methods a path answers, in either case, or every method where it resolves to nothing. * * A path union carries no method, so a signature constrained by one accepts a path the schema knows * for a method it does not. Constrain the method with this rather than intersecting a validator onto * the path, which stops a template literal argument from inferring as one: * `init?: { method?: M & TypedFetchMethods }`. */ type TypedFetchMethods = [TypedFetchResolvedMeta] extends [never] ? AnyHTTPMethod : TypedFetchResolvedMeta extends { method: infer Method; } ? WritableMethod : AnyHTTPMethod; type TypedFetchResponseHeaders = "responseHeaders" extends keyof TypedFetchResolvedMeta ? TypedFetchResolvedMeta["responseHeaders"] : never; //#endregion export { type AnyFetchPath, type AnyHTTPMethod, DynamicParam, Endpoint, type Endpoints, type HTTPMethod, type LooseTypedHeaders, type LooseTypedRequest, type MatchPattern, type MimeType, type RequestHeaderMap, type RequestHeaderName, type RequestHeaders, type ResponseHeaderMap, type ResponseHeaderName, type ResponseHeaders, type RouteTree, type TypedFetchErrorBody, type TypedFetchInput, type TypedFetchMeta, type TypedFetchMethods, type TypedFetchPath, type TypedFetchRequestBody, type TypedFetchRequestHeaders, type TypedFetchRequestInit, type TypedFetchRequestQuery, type TypedFetchRequires, type TypedFetchResolvedMeta, type TypedFetchResponseBody as TypedFetchResponse, type TypedFetchResponseBody, type TypedFetchResponseHeaders, type TypedHeaders, type TypedRequest, type TypedResponse, type TypedURLSearchParams, type ValidFetchInput, WildcardParam };