@devp0nt/route0 1.0.0-next.8 → 1.0.0-next.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +955 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +447 -91
- package/dist/esm/index.d.ts +447 -91
- package/dist/esm/index.js +892 -96
- package/dist/esm/index.js.map +1 -1
- package/package.json +48 -25
- package/dist/cjs/index.js +0 -158
- package/dist/cjs/index.js.map +0 -1
- package/src/index.test.ts +0 -206
- package/src/index.ts +0 -365
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,99 +1,455 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
|
|
3
|
+
type RouteToken = {
|
|
4
|
+
kind: 'static';
|
|
5
|
+
value: string;
|
|
6
|
+
} | {
|
|
7
|
+
kind: 'param';
|
|
8
|
+
name: string;
|
|
9
|
+
optional: boolean;
|
|
10
|
+
} | {
|
|
11
|
+
kind: 'wildcard';
|
|
12
|
+
prefix: string;
|
|
13
|
+
optional: boolean;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Strongly typed route descriptor and URL builder.
|
|
17
|
+
*
|
|
18
|
+
* A route definition uses:
|
|
19
|
+
* - path params: `/users/:id`
|
|
20
|
+
* - named search keys: `/users&tab&sort`
|
|
21
|
+
* - loose search mode: trailing `&`, e.g. `/users&`
|
|
22
|
+
*
|
|
23
|
+
* Instances are callable (same as `.get()`), so `route(input)` and
|
|
24
|
+
* `route.get(input)` are equivalent.
|
|
25
|
+
*/
|
|
26
|
+
declare class Route0<TDefinition extends string, TSearchInput extends UnknownSearchInput = UnknownSearchInput> {
|
|
27
|
+
readonly definition: TDefinition;
|
|
28
|
+
readonly params: _ParamsDefinition<TDefinition>;
|
|
29
|
+
private _origin;
|
|
30
|
+
private _callable;
|
|
31
|
+
private _routeSegments?;
|
|
32
|
+
private _routeTokens?;
|
|
33
|
+
private _routePatternCandidates?;
|
|
34
|
+
private _pathParamsDefinition?;
|
|
35
|
+
private _definitionWithoutTrailingWildcard?;
|
|
36
|
+
private _routeRegexBaseStringRaw?;
|
|
37
|
+
private _regexBaseString?;
|
|
38
|
+
private _regexString?;
|
|
39
|
+
private _regex?;
|
|
40
|
+
private _regexAncestor?;
|
|
41
|
+
private _regexDescendantMatchers?;
|
|
42
|
+
private _captureKeys?;
|
|
43
|
+
private _normalizedDefinition?;
|
|
44
|
+
private _definitionParts?;
|
|
45
|
+
static normalizeSlash: (value: string) => string;
|
|
46
|
+
private static _getRouteSegments;
|
|
47
|
+
private static _validateRouteDefinition;
|
|
48
|
+
Infer: {
|
|
49
|
+
ParamsDefinition: _ParamsDefinition<TDefinition>;
|
|
50
|
+
ParamsInput: _ParamsInput<TDefinition>;
|
|
51
|
+
ParamsInputStringOnly: _ParamsInputStringOnly<TDefinition>;
|
|
52
|
+
ParamsOutput: ParamsOutput<TDefinition>;
|
|
53
|
+
SearchInput: TSearchInput;
|
|
54
|
+
};
|
|
55
|
+
/** Base URL used when generating absolute URLs (`abs: true`). */
|
|
56
|
+
get origin(): string;
|
|
57
|
+
set origin(origin: string);
|
|
7
58
|
private constructor();
|
|
8
|
-
|
|
9
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Creates a callable route instance.
|
|
61
|
+
*
|
|
62
|
+
* If an existing route/callable route is provided, it is cloned.
|
|
63
|
+
*/
|
|
64
|
+
static create<TDefinition extends string>(definition: TDefinition | AnyRoute<TDefinition> | CallableRoute<TDefinition>, config?: RouteConfigInput): CallableRoute<NormalizeRouteDefinition<TDefinition>>;
|
|
65
|
+
/**
|
|
66
|
+
* Normalizes a definition/route into a callable route.
|
|
67
|
+
*
|
|
68
|
+
* Unlike `create`, passing a callable route returns the same instance.
|
|
69
|
+
*/
|
|
70
|
+
static from<TDefinition extends string, TSearchInput extends UnknownSearchInput>(definition: TDefinition | AnyRoute<TDefinition, TSearchInput> | CallableRoute<TDefinition, TSearchInput>): CallableRoute<NormalizeRouteDefinition<TDefinition>, TSearchInput>;
|
|
10
71
|
private static _getAbsPath;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
get(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
get(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
get(
|
|
33
|
-
get(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
72
|
+
search<TNewSearchInput extends UnknownSearchInput>(): CallableRoute<TDefinition, TNewSearchInput>;
|
|
73
|
+
/** Extends the current route definition by appending a suffix route. */
|
|
74
|
+
extend<TSuffixDefinition extends string>(suffixDefinition: TSuffixDefinition): CallableRoute<PathExtended<TDefinition, TSuffixDefinition>, TSearchInput>;
|
|
75
|
+
get(...args: IsParamsOptional<TDefinition> extends true ? [abs: boolean | string | undefined] : never): string;
|
|
76
|
+
get(...args: IsParamsOptional<TDefinition> extends true ? [input?: GetPathInput<TDefinition, TSearchInput> | undefined, abs?: boolean | string | undefined] : [input: GetPathInput<TDefinition, TSearchInput>, abs?: boolean | string | undefined]): string;
|
|
77
|
+
/** Returns path param keys extracted from route definition. */
|
|
78
|
+
getParamsKeys(): string[];
|
|
79
|
+
getTokens(): RouteToken[];
|
|
80
|
+
/** Clones route with optional config override. */
|
|
81
|
+
clone(config?: RouteConfigInput): CallableRoute<TDefinition>;
|
|
82
|
+
get regexBaseString(): string;
|
|
83
|
+
get regexString(): string;
|
|
84
|
+
get regex(): RegExp;
|
|
85
|
+
get regexAncestor(): RegExp;
|
|
86
|
+
private get regexDescendantMatchers();
|
|
87
|
+
private get captureKeys();
|
|
88
|
+
private get routeSegments();
|
|
89
|
+
private get routeTokens();
|
|
90
|
+
private get routePatternCandidates();
|
|
91
|
+
private get pathParamsDefinition();
|
|
92
|
+
private get definitionWithoutTrailingWildcard();
|
|
93
|
+
private get routeRegexBaseStringRaw();
|
|
94
|
+
private get normalizedDefinition();
|
|
95
|
+
private get definitionParts();
|
|
96
|
+
/** Fast pathname exact match check without building a full relation object. */
|
|
97
|
+
isExact(pathname: string, normalize?: boolean): boolean;
|
|
98
|
+
/** Fast pathname exact or ancestor match check without building a full relation object. */
|
|
99
|
+
isExactOrAncestor(pathname: string, normalize?: boolean): boolean;
|
|
100
|
+
/** True when route is ancestor of pathname (pathname is deeper). */
|
|
101
|
+
isAncestor(pathname: string, normalize?: boolean): boolean;
|
|
102
|
+
/** True when route is descendant of pathname (pathname is shallower). */
|
|
103
|
+
isDescendant(pathname: string, normalize?: boolean): boolean;
|
|
104
|
+
/** Creates a grouped regex pattern string from many routes. */
|
|
105
|
+
static getRegexStringGroup(routes: AnyRoute[]): string;
|
|
106
|
+
/** Creates a grouped regex from many routes. */
|
|
107
|
+
static getRegexGroup(routes: AnyRoute[]): RegExp;
|
|
108
|
+
/** Converts any location shape to relative form (removes host/origin fields). */
|
|
109
|
+
static toRelLocation<TLocation extends AnyLocation>(location: TLocation): TLocation;
|
|
110
|
+
/** Converts a location to absolute form using provided origin URL. */
|
|
111
|
+
static toAbsLocation<TLocation extends AnyLocation>(location: TLocation, origin: string): TLocation;
|
|
112
|
+
/**
|
|
113
|
+
* Parses a URL-like input into raw location object (without route knowledge).
|
|
114
|
+
*
|
|
115
|
+
* Result is always `UnknownLocation` because no route matching is applied.
|
|
116
|
+
*/
|
|
117
|
+
static getLocation(href: `${string}://${string}`): UnknownLocation;
|
|
118
|
+
static getLocation(hrefRel: `/${string}`): UnknownLocation;
|
|
119
|
+
static getLocation(hrefOrHrefRel: string): UnknownLocation;
|
|
120
|
+
static getLocation(location: AnyLocation): UnknownLocation;
|
|
121
|
+
static getLocation(url: URL): UnknownLocation;
|
|
122
|
+
static getLocation(hrefOrHrefRelOrLocation: string | AnyLocation | URL): UnknownLocation;
|
|
123
|
+
/**
|
|
124
|
+
* Parses input and evaluates pathname relation to this route.
|
|
125
|
+
*/
|
|
126
|
+
getRelation(href: `${string}://${string}`): RouteRelation<TDefinition>;
|
|
127
|
+
getRelation(hrefRel: `/${string}`): RouteRelation<TDefinition>;
|
|
128
|
+
getRelation(hrefOrHrefRel: string): RouteRelation<TDefinition>;
|
|
129
|
+
getRelation(location: AnyLocation): RouteRelation<TDefinition>;
|
|
130
|
+
getRelation(url: URL): RouteRelation<TDefinition>;
|
|
131
|
+
getRelation(hrefOrHrefRelOrLocation: string | AnyLocation | URL): RouteRelation<TDefinition>;
|
|
132
|
+
private _validateParamsInput;
|
|
133
|
+
private _safeParseSchemaResult;
|
|
134
|
+
private _parseSchemaResult;
|
|
135
|
+
/** Standard Schema for route params input. */
|
|
136
|
+
readonly schema: SchemaRoute0<ParamsInput<TDefinition>, ParamsOutput<TDefinition>>;
|
|
137
|
+
/** True when two route patterns can match the same concrete URL. */
|
|
138
|
+
isOverlap(other: AnyRoute | string | undefined): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* True when overlap is not resolvable by route ordering inside one route set.
|
|
141
|
+
*
|
|
142
|
+
* Non-conflicting overlap means one route is a strict subset of another
|
|
143
|
+
* (e.g. `/x/y` is a strict subset of `/x/:id`) and can be safely ordered first.
|
|
144
|
+
*/
|
|
145
|
+
isConflict(other: AnyRoute | string | undefined): boolean;
|
|
146
|
+
/** Specificity comparator used for deterministic route ordering. */
|
|
147
|
+
isMoreSpecificThan(other: AnyRoute | string | undefined): boolean;
|
|
51
148
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
149
|
+
/**
|
|
150
|
+
* Typed route collection with deterministic matching order.
|
|
151
|
+
*
|
|
152
|
+
* `Routes.create()` accepts either plain string definitions or route objects
|
|
153
|
+
* and returns a "pretty" object with direct route access + helper methods under `._`.
|
|
154
|
+
*/
|
|
155
|
+
declare class Routes<const T extends RoutesRecord = any> {
|
|
156
|
+
_routes: RoutesRecordHydrated<T>;
|
|
157
|
+
_pathsOrdering: string[];
|
|
158
|
+
_keysOrdering: string[];
|
|
159
|
+
_ordered: CallableRoute[];
|
|
160
|
+
_: {
|
|
161
|
+
routes: Routes<T>['_routes'];
|
|
162
|
+
getLocation: Routes<T>['_getLocation'];
|
|
163
|
+
clone: Routes<T>['_clone'];
|
|
164
|
+
pathsOrdering: Routes<T>['_pathsOrdering'];
|
|
165
|
+
keysOrdering: Routes<T>['_keysOrdering'];
|
|
166
|
+
ordered: Routes<T>['_ordered'];
|
|
56
167
|
};
|
|
57
|
-
|
|
58
|
-
|
|
168
|
+
private constructor();
|
|
169
|
+
/** Creates and hydrates a typed routes collection. */
|
|
170
|
+
static create<const T extends RoutesRecord>(routes: T, override?: RouteConfigInput): RoutesPretty<T>;
|
|
171
|
+
private static prettify;
|
|
172
|
+
private static hydrate;
|
|
173
|
+
/**
|
|
174
|
+
* Matches an input URL against collection routes.
|
|
175
|
+
*
|
|
176
|
+
* Returns first exact match according to precomputed ordering,
|
|
177
|
+
* otherwise returns `UnknownLocation`.
|
|
178
|
+
*/
|
|
179
|
+
_getLocation(href: `${string}://${string}`): UnknownLocation | ExactLocation;
|
|
180
|
+
_getLocation(hrefRel: `/${string}`): UnknownLocation | ExactLocation;
|
|
181
|
+
_getLocation(hrefOrHrefRel: string): UnknownLocation | ExactLocation;
|
|
182
|
+
_getLocation(location: AnyLocation): UnknownLocation | ExactLocation;
|
|
183
|
+
_getLocation(url: URL): UnknownLocation | ExactLocation;
|
|
184
|
+
_getLocation(hrefOrHrefRelOrLocation: string | AnyLocation | URL): UnknownLocation | ExactLocation;
|
|
185
|
+
private static makeOrdering;
|
|
186
|
+
/** Returns a cloned routes collection with config applied to each route. */
|
|
187
|
+
_clone(config: RouteConfigInput): RoutesPretty<T>;
|
|
188
|
+
static _: {
|
|
189
|
+
prettify: typeof Routes.prettify;
|
|
190
|
+
hydrate: typeof Routes.hydrate;
|
|
191
|
+
makeOrdering: typeof Routes.makeOrdering;
|
|
59
192
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
193
|
+
}
|
|
194
|
+
/** Any route instance shape, preserving literal path type when known. */
|
|
195
|
+
type AnyRoute<T extends Route0<string> | string = string, TSearch extends UnknownSearchInput = UnknownSearchInput> = T extends string ? Route0<T, TSearch> : T;
|
|
196
|
+
/** Callable route (`route(input)`) plus route instance methods/properties. */
|
|
197
|
+
type CallableRoute<T extends Route0<string> | string = string, TSearch extends UnknownSearchInput = UnknownSearchInput> = AnyRoute<T, TSearch> & AnyRoute<T, TSearch>['get'];
|
|
198
|
+
/** Route input accepted by most APIs: definition string or route object/callable. */
|
|
199
|
+
type AnyRouteOrDefinition<T extends string = string> = AnyRoute<T> | CallableRoute<T> | T;
|
|
200
|
+
/** Route-level runtime configuration. */
|
|
201
|
+
type RouteConfigInput = {
|
|
202
|
+
origin?: string;
|
|
203
|
+
};
|
|
204
|
+
/** User-provided routes map (plain definitions or route instances). */
|
|
205
|
+
type RoutesRecord = Record<string, AnyRoute | string>;
|
|
206
|
+
/** Same as `RoutesRecord` but all values normalized to callable routes. */
|
|
207
|
+
type RoutesRecordHydrated<TRoutesRecord extends RoutesRecord = any> = {
|
|
208
|
+
[K in keyof TRoutesRecord]: CallableRoute<TRoutesRecord[K]>;
|
|
209
|
+
};
|
|
210
|
+
/** Public shape returned by `Routes.create()`. Default `any` so `satisfies RoutesPretty` accepts any created routes. */
|
|
211
|
+
type RoutesPretty<TRoutesRecord extends RoutesRecord = any> = RoutesRecordHydrated<TRoutesRecord> & Omit<Routes<TRoutesRecord>, '_routes' | '_getLocation' | '_clone' | '_pathsOrdering' | '_keysOrdering' | '_ordered'>;
|
|
212
|
+
type ExtractRoutesKeys<TRoutes extends RoutesPretty | RoutesRecord> = TRoutes extends RoutesPretty ? Extract<keyof TRoutes['_']['routes'], string> : TRoutes extends RoutesRecord ? Extract<keyof TRoutes, string> : never;
|
|
213
|
+
type ExtractRoute<TRoutes extends RoutesPretty | RoutesRecord, TKey extends ExtractRoutesKeys<TRoutes>> = TRoutes extends RoutesPretty ? TRoutes['_']['routes'][TKey] : TRoutes extends RoutesRecord ? TRoutes[TKey] : never;
|
|
214
|
+
type Definition<T extends AnyRoute | string> = T extends AnyRoute ? T['definition'] : T extends string ? T : never;
|
|
215
|
+
type ParamsDefinition<T extends AnyRoute | string> = T extends AnyRoute ? T['params'] : T extends string ? _ParamsDefinition<T> : undefined;
|
|
216
|
+
type Extended<T extends AnyRoute | string | undefined, TSuffixDefinition extends string, TSearchInput extends UnknownSearchInput = UnknownSearchInput> = T extends AnyRoute ? Route0<PathExtended<T['definition'], TSuffixDefinition>, TSearchInput> : T extends string ? Route0<PathExtended<T, TSuffixDefinition>, TSearchInput> : T extends undefined ? Route0<TSuffixDefinition, TSearchInput> : never;
|
|
217
|
+
type IsSameParams<T1 extends AnyRoute | string, T2 extends AnyRoute | string> = _IsSameParams<ParamsDefinition<T1>, ParamsDefinition<T2>>;
|
|
218
|
+
type HasParams<T extends AnyRoute | string> = keyof _ParamsDefinition<Definition<T>> extends never ? false : true;
|
|
219
|
+
type HasWildcard<T extends AnyRoute | string> = Definition<T> extends `${string}*${string}` ? true : false;
|
|
220
|
+
type HasRequiredParams<T extends AnyRoute | string> = _RequiredParamKeys<Definition<T>> extends never ? false : true;
|
|
221
|
+
type ParamsOutput<T extends AnyRoute | string> = {
|
|
222
|
+
[K in keyof ParamsDefinition<T>]: ParamsDefinition<T>[K] extends true ? string : string | undefined;
|
|
223
|
+
};
|
|
224
|
+
type ParamsInput<T extends AnyRoute | string = string> = _ParamsInput<Definition<T>>;
|
|
225
|
+
type IsParamsOptional<T extends AnyRoute | string> = HasRequiredParams<Definition<T>> extends true ? false : true;
|
|
226
|
+
type ParamsInputStringOnly<T extends AnyRoute | string = string> = _ParamsInputStringOnly<Definition<T>>;
|
|
227
|
+
type LocationParams<TDefinition extends string> = {
|
|
228
|
+
[K in keyof _ParamsDefinition<TDefinition>]: _ParamsDefinition<TDefinition>[K] extends true ? string : string | undefined;
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* URL location primitives independent from route-matching state.
|
|
232
|
+
*
|
|
233
|
+
* `hrefRel` is relative href and includes `pathname + search + hash`.
|
|
234
|
+
*/
|
|
235
|
+
type _GeneralLocation = {
|
|
236
|
+
/**
|
|
237
|
+
* Path without search/hash (normalized for trailing slash).
|
|
238
|
+
*
|
|
239
|
+
* Example:
|
|
240
|
+
* - input: `https://example.com/users/42?tab=posts#section`
|
|
241
|
+
* - pathname: `/users/42`
|
|
242
|
+
*/
|
|
243
|
+
pathname: string;
|
|
244
|
+
/**
|
|
245
|
+
* Parsed query object.
|
|
246
|
+
*
|
|
247
|
+
* Example:
|
|
248
|
+
* - `{ tab: "posts", sort: "desc" }`
|
|
249
|
+
*/
|
|
250
|
+
search: UnknownSearchParsed;
|
|
251
|
+
/**
|
|
252
|
+
* Raw query string with leading `?`, if present, else empty string.
|
|
253
|
+
*
|
|
254
|
+
* Example:
|
|
255
|
+
* - `?tab=posts&sort=desc`
|
|
256
|
+
*/
|
|
257
|
+
searchString: string;
|
|
258
|
+
/**
|
|
259
|
+
* Raw hash with leading `#`, if present, else empty string.
|
|
260
|
+
*
|
|
261
|
+
* Example:
|
|
262
|
+
* - `#section`
|
|
263
|
+
*/
|
|
264
|
+
hash: string;
|
|
265
|
+
/**
|
|
266
|
+
* URL origin for absolute inputs.
|
|
267
|
+
*
|
|
268
|
+
* Example:
|
|
269
|
+
* - href: `https://example.com/users/42`
|
|
270
|
+
* - origin: `https://example.com`
|
|
271
|
+
*/
|
|
272
|
+
origin: string | undefined;
|
|
273
|
+
/**
|
|
274
|
+
* Full absolute href for absolute inputs.
|
|
275
|
+
*
|
|
276
|
+
* Example:
|
|
277
|
+
* - `https://example.com/users/42?tab=posts#section`
|
|
278
|
+
*/
|
|
279
|
+
href: string | undefined;
|
|
280
|
+
/**
|
|
281
|
+
* Relative href (`pathname + search + hash`).
|
|
282
|
+
*
|
|
283
|
+
* Example:
|
|
284
|
+
* - pathname: `/users/42`
|
|
285
|
+
* - search: `?tab=posts`
|
|
286
|
+
* - hash: `#section`
|
|
287
|
+
* - hrefRel: `/users/42?tab=posts#section`
|
|
288
|
+
*/
|
|
289
|
+
hrefRel: string;
|
|
290
|
+
/**
|
|
291
|
+
* Whether input was absolute URL.
|
|
292
|
+
*
|
|
293
|
+
* Examples:
|
|
294
|
+
* - `https://example.com/users/42` -> `true`
|
|
295
|
+
* - `/users/42` -> `false`
|
|
296
|
+
*/
|
|
297
|
+
abs: boolean;
|
|
298
|
+
port: string | undefined;
|
|
299
|
+
host: string | undefined;
|
|
300
|
+
hostname: string | undefined;
|
|
301
|
+
};
|
|
302
|
+
/** Location state before matching against a concrete route. */
|
|
303
|
+
type UnknownLocationState = {
|
|
304
|
+
route: undefined;
|
|
305
|
+
params: undefined;
|
|
306
|
+
};
|
|
307
|
+
type UnknownLocation = _GeneralLocation & UnknownLocationState;
|
|
308
|
+
/** Exact match state for a known route. */
|
|
309
|
+
type ExactLocationState<TRoute extends AnyRoute | string = AnyRoute | string> = {
|
|
310
|
+
route: Definition<TRoute>;
|
|
311
|
+
params: ParamsOutput<TRoute>;
|
|
312
|
+
};
|
|
313
|
+
type ExactLocation<TRoute extends AnyRoute | string = AnyRoute | string> = _GeneralLocation & ExactLocationState<TRoute>;
|
|
314
|
+
type ExactRouteRelation<TRoute extends AnyRoute | string = AnyRoute | string> = {
|
|
315
|
+
type: 'exact';
|
|
316
|
+
route: Definition<TRoute>;
|
|
317
|
+
params: ParamsOutput<TRoute>;
|
|
318
|
+
exact: true;
|
|
319
|
+
ascendant: false;
|
|
320
|
+
descendant: false;
|
|
321
|
+
unmatched: false;
|
|
322
|
+
};
|
|
323
|
+
type AscendantRouteRelation<TRoute extends AnyRoute | string = AnyRoute | string> = {
|
|
324
|
+
type: 'ascendant';
|
|
325
|
+
route: Definition<TRoute>;
|
|
326
|
+
params: ParamsOutput<TRoute> & {
|
|
327
|
+
[key: string]: string | undefined;
|
|
85
328
|
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
329
|
+
exact: false;
|
|
330
|
+
ascendant: true;
|
|
331
|
+
descendant: false;
|
|
332
|
+
unmatched: false;
|
|
333
|
+
};
|
|
334
|
+
type DescendantRouteRelation<TRoute extends AnyRoute | string = AnyRoute | string> = {
|
|
335
|
+
type: 'descendant';
|
|
336
|
+
route: Definition<TRoute>;
|
|
337
|
+
params: Partial<ParamsOutput<TRoute>>;
|
|
338
|
+
exact: false;
|
|
339
|
+
ascendant: false;
|
|
340
|
+
descendant: true;
|
|
341
|
+
unmatched: false;
|
|
342
|
+
};
|
|
343
|
+
type UnmatchedRouteRelation<TRoute extends AnyRoute | string = AnyRoute | string> = {
|
|
344
|
+
type: 'unmatched';
|
|
345
|
+
route: Definition<TRoute>;
|
|
346
|
+
params: Record<never, never>;
|
|
347
|
+
exact: false;
|
|
348
|
+
ascendant: false;
|
|
349
|
+
descendant: false;
|
|
350
|
+
unmatched: true;
|
|
351
|
+
};
|
|
352
|
+
type RouteRelation<TRoute extends AnyRoute | string = AnyRoute | string> = ExactRouteRelation<TRoute> | AscendantRouteRelation<TRoute> | DescendantRouteRelation<TRoute> | UnmatchedRouteRelation<TRoute>;
|
|
353
|
+
type UnknownSearchParsedValue = string | UnknownSearchParsed | Array<UnknownSearchParsedValue>;
|
|
354
|
+
interface UnknownSearchParsed {
|
|
355
|
+
[key: string]: UnknownSearchParsedValue;
|
|
97
356
|
}
|
|
357
|
+
type UnknownSearchInput = Record<string, unknown>;
|
|
358
|
+
/** Input URL is a descendant of route definition (route is ancestor). */
|
|
359
|
+
type AncestorLocationState<TRoute extends AnyRoute | string = AnyRoute | string> = {
|
|
360
|
+
route: string;
|
|
361
|
+
params: IsAny<TRoute> extends true ? any : ParamsOutput<TRoute> & {
|
|
362
|
+
[key: string]: string | undefined;
|
|
363
|
+
};
|
|
364
|
+
};
|
|
365
|
+
type AncestorLocation<TRoute extends AnyRoute | string = AnyRoute | string> = _GeneralLocation & AncestorLocationState<TRoute>;
|
|
366
|
+
/** It is when route not match at all, but params match. */
|
|
367
|
+
type WeakAncestorLocationState<TRoute extends AnyRoute | string = AnyRoute | string> = {
|
|
368
|
+
route: string;
|
|
369
|
+
params: IsAny<TRoute> extends true ? any : ParamsOutput<TRoute> & {
|
|
370
|
+
[key: string]: string | undefined;
|
|
371
|
+
};
|
|
372
|
+
};
|
|
373
|
+
type WeakAncestorLocation<TRoute extends AnyRoute | string = AnyRoute | string> = _GeneralLocation & WeakAncestorLocationState<TRoute>;
|
|
374
|
+
/** Input URL is an ancestor prefix of route definition (route is descendant). */
|
|
375
|
+
type DescendantLocationState<TRoute extends AnyRoute | string = AnyRoute | string> = {
|
|
376
|
+
route: string;
|
|
377
|
+
params: Partial<ParamsOutput<TRoute>>;
|
|
378
|
+
};
|
|
379
|
+
type DescendantLocation<TRoute extends AnyRoute | string = AnyRoute | string> = _GeneralLocation & DescendantLocationState<TRoute>;
|
|
380
|
+
/** It is when route not match at all, but params partially match. */
|
|
381
|
+
type WeakDescendantLocationState<TRoute extends AnyRoute | string = AnyRoute | string> = {
|
|
382
|
+
route: string;
|
|
383
|
+
params: Partial<ParamsOutput<TRoute>>;
|
|
384
|
+
};
|
|
385
|
+
type WeakDescendantLocation<TRoute extends AnyRoute | string = AnyRoute | string> = _GeneralLocation & WeakDescendantLocationState<TRoute>;
|
|
386
|
+
type KnownLocation<TRoute extends AnyRoute | string = AnyRoute | string> = ExactLocation<TRoute> | AncestorLocation<TRoute> | WeakAncestorLocation<TRoute> | DescendantLocation<TRoute> | WeakDescendantLocation<TRoute>;
|
|
387
|
+
type AnyLocation<TRoute extends AnyRoute | string = AnyRoute | string> = UnknownLocation | KnownLocation<TRoute>;
|
|
388
|
+
type _ParamsDefinition<TDefinition extends string> = _ExtractParamsDefinitionBySegments<_SplitPathSegments<Definition<TDefinition>>>;
|
|
389
|
+
type _Simplify<T> = {
|
|
390
|
+
[K in keyof T]: T[K];
|
|
391
|
+
} & {};
|
|
392
|
+
type _IfNoKeys<T extends object, TYes, TNo> = keyof T extends never ? TYes : TNo;
|
|
393
|
+
type _ParamsInput<TDefinition extends string> = _ParamsDefinition<TDefinition> extends infer TDef extends Record<string, boolean> ? _IfNoKeys<TDef, Record<never, never>, _Simplify<{
|
|
394
|
+
[K in keyof TDef as TDef[K] extends true ? K : never]: string | number;
|
|
395
|
+
} & {
|
|
396
|
+
[K in keyof TDef as TDef[K] extends false ? K : never]?: string | number | undefined;
|
|
397
|
+
}>> : Record<never, never>;
|
|
398
|
+
type _ParamsInputStringOnly<TDefinition extends string> = _ParamsDefinition<TDefinition> extends infer TDef extends Record<string, boolean> ? _IfNoKeys<TDef, Record<never, never>, _Simplify<{
|
|
399
|
+
[K in keyof TDef as TDef[K] extends true ? K : never]: string;
|
|
400
|
+
} & {
|
|
401
|
+
[K in keyof TDef as TDef[K] extends false ? K : never]?: string | undefined;
|
|
402
|
+
}>> : Record<never, never>;
|
|
403
|
+
type _SplitPathSegments<TPath extends string> = TPath extends '' ? [] : TPath extends '/' ? [] : TPath extends `/${infer Rest}` ? _SplitPathSegments<Rest> : TPath extends `${infer Segment}/${infer Rest}` ? Segment extends '' ? _SplitPathSegments<Rest> : [Segment, ..._SplitPathSegments<Rest>] : TPath extends '' ? [] : [TPath];
|
|
404
|
+
type _ParamDefinitionFromSegment<TSegment extends string> = TSegment extends `:${infer Name}?` ? {
|
|
405
|
+
[K in Name]: false;
|
|
406
|
+
} : TSegment extends `:${infer Name}` ? {
|
|
407
|
+
[K in Name]: true;
|
|
408
|
+
} : TSegment extends `${string}*?` ? {
|
|
409
|
+
'*': false;
|
|
410
|
+
} : TSegment extends `${string}*` ? {
|
|
411
|
+
'*': true;
|
|
412
|
+
} : Record<never, never>;
|
|
413
|
+
type _MergeParamDefinitions<A extends Record<string, boolean>, B extends Record<string, boolean>> = {
|
|
414
|
+
[K in keyof A | keyof B]: K extends keyof B ? B[K] : K extends keyof A ? A[K] : never;
|
|
415
|
+
};
|
|
416
|
+
type _ExtractParamsDefinitionBySegments<TSegments extends string[]> = TSegments extends [
|
|
417
|
+
infer Segment extends string,
|
|
418
|
+
...infer Rest extends string[]
|
|
419
|
+
] ? _MergeParamDefinitions<_ParamDefinitionFromSegment<Segment>, _ExtractParamsDefinitionBySegments<Rest>> : Record<never, never>;
|
|
420
|
+
type _RequiredParamKeys<TDefinition extends string> = {
|
|
421
|
+
[K in keyof _ParamsDefinition<TDefinition>]: _ParamsDefinition<TDefinition>[K] extends true ? K : never;
|
|
422
|
+
}[keyof _ParamsDefinition<TDefinition>];
|
|
423
|
+
type ReplacePathParams<S extends string> = S extends `${infer Head}:${infer Tail}` ? Tail extends `${infer _Param}/${infer Rest}` ? ReplacePathParams<`${Head}${string}/${Rest}`> : `${Head}${string}` : S;
|
|
424
|
+
type DedupeSlashes<S extends string> = S extends `${infer A}//${infer B}` ? DedupeSlashes<`${A}/${B}`> : S;
|
|
425
|
+
type EnsureLeadingSlash<S extends string> = S extends '' ? '/' : S extends `/${string}` ? S : `/${S}`;
|
|
426
|
+
type TrimTrailingSlash<S extends string> = S extends '/' ? '/' : S extends `${infer V}/` ? TrimTrailingSlash<V> : S;
|
|
427
|
+
type NormalizeRouteDefinition<S extends string> = TrimTrailingSlash<EnsureLeadingSlash<DedupeSlashes<S>>>;
|
|
428
|
+
type EmptyRecord = Record<never, never>;
|
|
429
|
+
type JoinPath<Parent extends string, Suffix extends string> = NormalizeRouteDefinition<Definition<Parent> extends infer A extends string ? Definition<Suffix> extends infer B extends string ? NormalizeRouteDefinition<A> extends infer ANormalized extends string ? NormalizeRouteDefinition<B> extends infer BNormalized extends string ? BNormalized extends '/' ? ANormalized : ANormalized extends '/' ? BNormalized : `${ANormalized}/${BNormalized}` : never : never : never : never>;
|
|
430
|
+
type PathExtended<TSourceDefinitionDefinition extends string, TSuffixDefinitionDefinition extends string> = `${NormalizeRouteDefinition<JoinPath<StripTrailingWildcard<TSourceDefinitionDefinition>, TSuffixDefinitionDefinition>>}`;
|
|
431
|
+
type StripTrailingWildcard<TDefinition extends string> = TDefinition extends `${infer TPath}*?` ? NormalizeRouteDefinition<TPath> : TDefinition extends `${infer TPath}*` ? NormalizeRouteDefinition<TPath> : NormalizeRouteDefinition<TDefinition>;
|
|
432
|
+
type OnlyIfNoParams<TRoute extends AnyRoute | string, Yes, No = never> = HasParams<TRoute> extends false ? Yes : No;
|
|
433
|
+
type OnlyIfHasParams<TRoute extends AnyRoute | string, Yes, No = never> = HasParams<TRoute> extends true ? Yes : No;
|
|
434
|
+
type GetPathInput<TDefinition extends string, TSearchInput extends UnknownSearchInput> = _ParamsInput<TDefinition> & {
|
|
435
|
+
'?'?: TSearchInput;
|
|
436
|
+
'#'?: string | number;
|
|
437
|
+
};
|
|
438
|
+
type GetPathInputByRoute<TRoute extends AnyRoute | CallableRoute | string> = TRoute extends AnyRoute<any, infer TSearchInput> ? GetPathInput<Definition<TRoute>, TSearchInput> : TRoute extends string ? GetPathInput<TRoute, UnknownSearchInput> : never;
|
|
439
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
440
|
+
type _IsSameParams<T1 extends object | undefined, T2 extends object | undefined> = T1 extends undefined ? T2 extends undefined ? true : false : T2 extends undefined ? false : T1 extends T2 ? T2 extends T1 ? true : false : false;
|
|
441
|
+
type _SafeParseInputResult<TInputParsed extends Record<string, unknown>> = {
|
|
442
|
+
success: true;
|
|
443
|
+
data: TInputParsed;
|
|
444
|
+
error: undefined;
|
|
445
|
+
} | {
|
|
446
|
+
success: false;
|
|
447
|
+
data: undefined;
|
|
448
|
+
error: Error;
|
|
449
|
+
};
|
|
450
|
+
type SchemaRoute0<TInput extends Record<string, unknown>, TOutput extends Record<string, unknown>> = StandardSchemaV1<TInput, TOutput> & {
|
|
451
|
+
parse: (input: unknown) => TOutput;
|
|
452
|
+
safeParse: (input: unknown) => _SafeParseInputResult<TOutput>;
|
|
453
|
+
};
|
|
98
454
|
|
|
99
|
-
export { Route0 };
|
|
455
|
+
export { type AncestorLocation, type AncestorLocationState, type AnyLocation, type AnyRoute, type AnyRouteOrDefinition, type AscendantRouteRelation, type CallableRoute, type DedupeSlashes, type Definition, type DescendantLocation, type DescendantLocationState, type DescendantRouteRelation, type EmptyRecord, type EnsureLeadingSlash, type ExactLocation, type ExactLocationState, type ExactRouteRelation, type Extended, type ExtractRoute, type ExtractRoutesKeys, type GetPathInput, type GetPathInputByRoute, type HasParams, type HasRequiredParams, type HasWildcard, type IsAny, type IsParamsOptional, type IsSameParams, type JoinPath, type KnownLocation, type LocationParams, type NormalizeRouteDefinition, type OnlyIfHasParams, type OnlyIfNoParams, type ParamsDefinition, type ParamsInput, type ParamsInputStringOnly, type ParamsOutput, type PathExtended, type ReplacePathParams, Route0, type RouteConfigInput, type RouteRelation, type RouteToken, Routes, type RoutesPretty, type RoutesRecord, type RoutesRecordHydrated, type SchemaRoute0, type StripTrailingWildcard, type TrimTrailingSlash, type UnknownLocation, type UnknownLocationState, type UnknownSearchInput, type UnknownSearchParsed, type UnknownSearchParsedValue, type UnmatchedRouteRelation, type WeakAncestorLocation, type WeakAncestorLocationState, type WeakDescendantLocation, type WeakDescendantLocationState, type _ExtractParamsDefinitionBySegments, type _GeneralLocation, type _IfNoKeys, type _IsSameParams, type _MergeParamDefinitions, type _ParamDefinitionFromSegment, type _ParamsDefinition, type _ParamsInput, type _ParamsInputStringOnly, type _RequiredParamKeys, type _SafeParseInputResult, type _Simplify, type _SplitPathSegments };
|