@devp0nt/route0 1.0.0-next.67 → 1.0.0-next.69

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.
@@ -1,5 +1,17 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
2
 
3
+ type PathToken = {
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
+ };
3
15
  /**
4
16
  * Strongly typed route descriptor and URL builder.
5
17
  *
@@ -11,13 +23,18 @@ import { StandardSchemaV1 } from '@standard-schema/spec';
11
23
  * Instances are callable (same as `.get()`), so `route(input)` and
12
24
  * `route.get(input)` are equivalent.
13
25
  */
14
- declare class Route0<TDefinition extends string> {
26
+ declare class Route0<TDefinition extends string, TSearch extends UnknownSearch = UnknownSearch> {
15
27
  readonly definition: TDefinition;
16
- readonly pathDefinition: _PathDefinition<TDefinition>;
17
- readonly paramsDefinition: _ParamsDefinition<TDefinition>;
18
- readonly searchDefinition: _SearchDefinition<TDefinition>;
19
- readonly hasLooseSearch: HasLooseSearch<TDefinition>;
28
+ readonly params: _ParamsDefinition<TDefinition>;
20
29
  private _origin;
30
+ private _callable;
31
+ Infer: {
32
+ ParamsDefinition: _ParamsDefinition<TDefinition>;
33
+ ParamsInput: _ParamsInput<TDefinition>;
34
+ ParamsInputStringOnly: _ParamsInputStringOnly<TDefinition>;
35
+ ParamsOutput: ParamsOutput<TDefinition>;
36
+ SearchInput: TSearch;
37
+ };
21
38
  /** Base URL used when generating absolute URLs (`abs: true`). */
22
39
  get origin(): string;
23
40
  set origin(origin: string);
@@ -33,67 +50,29 @@ declare class Route0<TDefinition extends string> {
33
50
  *
34
51
  * Unlike `create`, passing a callable route returns the same instance.
35
52
  */
36
- static from<TDefinition extends string>(definition: TDefinition | AnyRoute<TDefinition> | CallableRoute<TDefinition>): CallableRoute<TDefinition>;
37
- private static _splitPathDefinitionAndSearchTailDefinition;
53
+ static from<TDefinition extends string, TSearch extends UnknownSearch>(definition: TDefinition | AnyRoute<TDefinition, TSearch> | CallableRoute<TDefinition, TSearch>): CallableRoute<TDefinition, TSearch>;
38
54
  private static _getAbsPath;
39
- private static _getPathDefinitionBydefinition;
40
- private static _getParamsDefinitionBydefinition;
41
- private static _getSearchDefinitionBydefinition;
42
- private static _hasLooseSearch;
55
+ private static _getParamsDefinitionByDefinition;
56
+ search<TNewSearch extends UnknownSearch>(): CallableRoute<TDefinition, TNewSearch>;
43
57
  /** Extends the current route definition by appending a suffix route. */
44
- extend<TSuffixDefinition extends string>(suffixDefinition: TSuffixDefinition): CallableRoute<PathExtended<TDefinition, TSuffixDefinition>>;
45
- /**
46
- * Builds a URL string from typed params/search input.
47
- *
48
- * - `abs: true` returns absolute URL using `origin`
49
- * - `hash` appends URL fragment
50
- * - `search` accepts named/loose search input based on definition
51
- */
52
- get(input: OnlyIfHasParams<TDefinition, WithParamsInput<TDefinition, {
53
- search?: _LooseSearchInput<TDefinition>;
54
- abs?: boolean | string;
55
- hash?: string | number;
56
- }>>): OnlyIfHasParams<TDefinition, string>;
57
- get(...args: OnlyIfNoParams<TDefinition, [], [never]>): string;
58
- get(input: OnlyIfNoParams<TDefinition, {
59
- search?: _LooseSearchInput<TDefinition>;
60
- abs?: boolean | string;
61
- hash?: string | number;
62
- }>): OnlyIfNoParams<TDefinition, string>;
63
- /**
64
- * Flat input variant of `get()`, where path params + search keys
65
- * are provided in a single object.
66
- */
67
- flat<TLoose extends boolean = HasLooseSearch<TDefinition>>(input: OnlyIfHasParams<TDefinition, WithParamsInput<TDefinition, FlatInput<TDefinition, TLoose> & {
68
- hash?: string | number;
69
- }>>, abs?: boolean | string, loose?: TLoose): OnlyIfHasParams<TDefinition, string>;
70
- flat(...args: OnlyIfNoParams<TDefinition, [], [never]>): string;
71
- flat<TLoose extends boolean = HasLooseSearch<TDefinition>>(input: OnlyIfNoParams<TDefinition, FlatInput<TDefinition, TLoose> & {
72
- hash?: string | number;
73
- }>, abs?: boolean | string, loose?: TLoose): OnlyIfNoParams<TDefinition, string>;
74
- /** Same as `flat()`, but always accepts loose search keys. */
75
- flatLoose(input: OnlyIfHasParams<TDefinition, WithParamsInput<TDefinition, LooseFlatInput<TDefinition> & {
76
- hash?: string | number;
77
- }>>, abs?: boolean | string): OnlyIfHasParams<TDefinition, string>;
78
- flatLoose(...args: OnlyIfNoParams<TDefinition, [], [never]>): string;
79
- flatLoose(input: OnlyIfNoParams<TDefinition, LooseFlatInput<TDefinition> & {
80
- hash?: string | number;
81
- }>, abs?: boolean | string): OnlyIfNoParams<TDefinition, string>;
82
- /** Same as `flat()`, but only allows declared search keys. */
83
- flatStrict(input: OnlyIfHasParams<TDefinition, WithParamsInput<TDefinition, StrictFlatInput<TDefinition> & {
84
- hash?: string | number;
85
- }>>, abs?: boolean | string): OnlyIfHasParams<TDefinition, string>;
86
- flatStrict(...args: OnlyIfNoParams<TDefinition, [], [never]>): string;
87
- flatStrict(input: OnlyIfNoParams<TDefinition, StrictFlatInput<TDefinition> & {
88
- hash?: string | number;
89
- }>, abs?: boolean | string): OnlyIfNoParams<TDefinition, string>;
58
+ extend<TSuffixDefinition extends string>(suffixDefinition: TSuffixDefinition): CallableRoute<PathExtended<TDefinition, TSuffixDefinition>, TSearch>;
59
+ get(...args: IsParamsOptional<TDefinition> extends true ? [abs: boolean | string | undefined] : never): string;
60
+ get(...args: IsParamsOptional<TDefinition> extends true ? [
61
+ input?: (_ParamsInput<TDefinition> & {
62
+ '?'?: TSearch;
63
+ '#'?: string | number;
64
+ }) | undefined,
65
+ abs?: boolean | string | undefined
66
+ ] : [
67
+ input: _ParamsInput<TDefinition> & {
68
+ '?'?: TSearch;
69
+ '#'?: string | number;
70
+ },
71
+ abs?: boolean | string | undefined
72
+ ]): string;
90
73
  /** Returns path param keys extracted from route definition. */
91
74
  getParamsKeys(): string[];
92
- /** Returns named search keys extracted from route definition. */
93
- getSearchKeys(): string[];
94
- /** Returns all flat input keys (`search + params`). */
95
- getFlatKeys(): string[];
96
- getDefinition(): string;
75
+ getPathTokens(): PathToken[];
97
76
  /** Clones route with optional config override. */
98
77
  clone(config?: RouteConfigInput): CallableRoute<TDefinition>;
99
78
  getRegexBaseStrictString(): string;
@@ -141,18 +120,10 @@ declare class Route0<TDefinition extends string> {
141
120
  getLocation(url: AnyLocation): KnownLocation<TDefinition>;
142
121
  getLocation(hrefOrHrefRelOrLocation: string | AnyLocation | URL): KnownLocation<TDefinition>;
143
122
  private _validateParamsInput;
144
- private _validateSearchInput;
145
- private _validateFlatInput;
146
123
  private _safeParseSchemaResult;
147
124
  private _parseSchemaResult;
148
125
  /** Standard Schema for route params input. */
149
- readonly paramsInputSchema: Route0Schema<ParamsInput<TDefinition>, ParamsOutput<TDefinition>>;
150
- /** Standard Schema for strict search input. */
151
- readonly strictSearchInputSchema: Route0Schema<StrictSearchInput<TDefinition>, StrictSearchOutput<TDefinition>>;
152
- /** Standard Schema for loose search input. */
153
- readonly looseSearchInputSchema: Route0Schema<LooseSearchInput<TDefinition>, LooseSearchOutput<TDefinition>>;
154
- /** Standard Schema for route flat input (uses route default strict/loose mode). */
155
- readonly flatInputSchema: Route0Schema<FlatInput<TDefinition, HasLooseSearch<TDefinition>>, FlatOutput<TDefinition, HasLooseSearch<TDefinition>>>;
126
+ readonly paramsSchema: SchemaRoute0<ParamsInput<TDefinition>, ParamsOutput<TDefinition>>;
156
127
  /** True when path structure is equal (param names are ignored). */
157
128
  isSame(other: AnyRoute): boolean;
158
129
  /** Static convenience wrapper for `isSame`. */
@@ -163,6 +134,8 @@ declare class Route0<TDefinition extends string> {
163
134
  isAncestor(other: AnyRoute | string | undefined): boolean;
164
135
  /** True when two route patterns can match the same concrete URL. */
165
136
  isConflict(other: AnyRoute | string | undefined): boolean;
137
+ /** True when paths are same or can overlap when optional parts are omitted. */
138
+ isMayBeSame(other: AnyRoute | string | undefined): boolean;
166
139
  /** Specificity comparator used for deterministic route ordering. */
167
140
  isMoreSpecificThan(other: AnyRoute | string | undefined): boolean;
168
141
  }
@@ -212,9 +185,9 @@ declare class Routes<const T extends RoutesRecord = any> {
212
185
  };
213
186
  }
214
187
  /** Any route instance shape, preserving literal path type when known. */
215
- type AnyRoute<T extends Route0<string> | string = string> = T extends string ? Route0<T> : T;
188
+ type AnyRoute<T extends Route0<string> | string = string, TSearch extends UnknownSearch = UnknownSearch> = T extends string ? Route0<T, TSearch> : T;
216
189
  /** Callable route (`route(input)`) plus route instance methods/properties. */
217
- type CallableRoute<T extends Route0<string> | string = string> = AnyRoute<T> & AnyRoute<T>['get'];
190
+ type CallableRoute<T extends Route0<string> | string = string, TSearch extends UnknownSearch = UnknownSearch> = AnyRoute<T, TSearch> & AnyRoute<T, TSearch>['get'];
218
191
  /** Route input accepted by most APIs: definition string or route object/callable. */
219
192
  type AnyRouteOrDefinition<T extends string = string> = AnyRoute<T> | CallableRoute<T> | T;
220
193
  /** Route-level runtime configuration. */
@@ -232,67 +205,23 @@ type RoutesPretty<TRoutesRecord extends RoutesRecord = any> = RoutesRecordHydrat
232
205
  type ExtractRoutesKeys<TRoutes extends RoutesPretty | RoutesRecord> = TRoutes extends RoutesPretty ? Extract<keyof TRoutes['_']['routes'], string> : TRoutes extends RoutesRecord ? Extract<keyof TRoutes, string> : never;
233
206
  type ExtractRoute<TRoutes extends RoutesPretty | RoutesRecord, TKey extends ExtractRoutesKeys<TRoutes>> = TRoutes extends RoutesPretty ? TRoutes['_']['routes'][TKey] : TRoutes extends RoutesRecord ? TRoutes[TKey] : never;
234
207
  type Definition<T extends AnyRoute | string> = T extends AnyRoute ? T['definition'] : T extends string ? T : never;
235
- type PathDefinition<T extends AnyRoute | string> = T extends AnyRoute ? T['pathDefinition'] : T extends string ? _PathDefinition<T> : never;
236
- type ParamsDefinition<T extends AnyRoute | string> = T extends AnyRoute ? T['paramsDefinition'] : T extends string ? _ParamsDefinition<T> : undefined;
237
- type SearchDefinition<T extends AnyRoute | string> = T extends AnyRoute ? T['searchDefinition'] : T extends string ? _SearchDefinition<T> : undefined;
238
- type Extended<T extends AnyRoute | string | undefined, TSuffixDefinition extends string> = T extends AnyRoute ? Route0<PathExtended<T['definition'], TSuffixDefinition>> : T extends string ? Route0<PathExtended<T, TSuffixDefinition>> : T extends undefined ? Route0<TSuffixDefinition> : never;
239
- type IsAncestor<T extends AnyRoute | string, TAncestor extends AnyRoute | string> = _IsAncestor<PathDefinition<T>, PathDefinition<TAncestor>>;
240
- type IsDescendant<T extends AnyRoute | string, TDescendant extends AnyRoute | string> = _IsDescendant<PathDefinition<T>, PathDefinition<TDescendant>>;
241
- type IsSame<T extends AnyRoute | string, TExact extends AnyRoute | string> = _IsSame<PathDefinition<T>, PathDefinition<TExact>>;
208
+ type ParamsDefinition<T extends AnyRoute | string> = T extends AnyRoute ? T['params'] : T extends string ? _ParamsDefinition<T> : undefined;
209
+ type Extended<T extends AnyRoute | string | undefined, TSuffixDefinition extends string, TSearch extends UnknownSearch = UnknownSearch> = T extends AnyRoute ? Route0<PathExtended<T['definition'], TSuffixDefinition>, TSearch> : T extends string ? Route0<PathExtended<T, TSuffixDefinition>, TSearch> : T extends undefined ? Route0<TSuffixDefinition, TSearch> : never;
210
+ type IsAncestor<T extends AnyRoute | string, TAncestor extends AnyRoute | string> = _IsAncestor<Definition<T>, Definition<TAncestor>>;
211
+ type IsDescendant<T extends AnyRoute | string, TDescendant extends AnyRoute | string> = _IsDescendant<Definition<T>, Definition<TDescendant>>;
212
+ type IsSame<T extends AnyRoute | string, TExact extends AnyRoute | string> = _IsSame<Definition<T>, Definition<TExact>>;
242
213
  type IsSameParams<T1 extends AnyRoute | string, T2 extends AnyRoute | string> = _IsSameParams<ParamsDefinition<T1>, ParamsDefinition<T2>>;
243
- type HasParams<T extends AnyRoute | string> = ExtractPathParams<PathDefinition<T>> extends infer U ? ([U] extends [never] ? false : true) : false;
244
- type HasSearch<T extends AnyRoute | string> = Definition<T> extends `${string}&${string}` ? true : false;
245
- type HasNamedSearch<T extends AnyRoute | string> = SearchTailDefinitionWithoutFirstAndLastAmp<Definition<T>> extends '' ? false : true;
246
- type HasLooseSearch<T extends AnyRoute | string> = Definition<T> extends `${string}&` ? true : false;
214
+ type HasParams<T extends AnyRoute | string> = keyof _ParamsDefinition<Definition<T>> extends never ? false : true;
215
+ type HasRequiredParams<T extends AnyRoute | string> = _RequiredParamKeys<Definition<T>> extends never ? false : true;
247
216
  type ParamsOutput<T extends AnyRoute | string> = {
248
- [K in keyof ParamsDefinition<T>]: string;
249
- };
250
- type LooseSearchOutput<T extends AnyRoute | string = string> = Partial<{
251
- [K in keyof SearchDefinition<T>]?: string;
252
- } & Record<string, string | undefined>>;
253
- type StrictSearchOutput<T extends AnyRoute | string> = Partial<{
254
- [K in keyof SearchDefinition<T>]?: string | undefined;
255
- }>;
256
- type LooseFlatOutput<T extends AnyRoute | string = string> = HasParams<Definition<T>> extends true ? ParamsOutput<T> & LooseSearchOutput<T> : LooseSearchOutput<T>;
257
- type StrictFlatOutput<T extends AnyRoute | string> = HasParams<Definition<T>> extends true ? ParamsOutput<T> & StrictSearchOutput<T> : StrictSearchOutput<T>;
258
- type FlatOutput<T extends AnyRoute | string, TLoose extends boolean = HasLooseSearch<T>> = TLoose extends true ? LooseFlatOutput<T> : StrictFlatOutput<T>;
259
- type LooseFlatOutputWithHash<T extends AnyRoute | string = string> = LooseFlatOutput<T> & {
260
- hash?: string | undefined;
217
+ [K in keyof ParamsDefinition<T>]: ParamsDefinition<T>[K] extends true ? string : string | undefined;
261
218
  };
262
- type StrictFlatOutputWithHash<T extends AnyRoute | string> = StrictFlatOutput<T> & {
263
- hash?: string | undefined;
264
- };
265
- type FlatOutputWithHash<T extends AnyRoute | string, TLoose extends boolean = HasLooseSearch<T>> = FlatOutput<T, TLoose> & {
266
- hash?: string | undefined;
267
- };
268
- type ParamsInput<T extends AnyRoute | string = string> = _ParamsInput<PathDefinition<T>>;
269
- type LooseSearchInput<T extends AnyRoute | string = string> = _LooseSearchInput<Definition<T>>;
270
- type StrictSearchInput<T extends AnyRoute | string> = _StrictSearchInput<Definition<T>>;
271
- type LooseFlatInput<T extends AnyRoute | string> = _LooseFlatInput<Definition<T>>;
272
- type StrictFlatInput<T extends AnyRoute | string> = _StrictFlatInput<Definition<T>>;
273
- type FlatInput<T extends AnyRoute | string, TLoose extends boolean = HasLooseSearch<T>> = TLoose extends true ? LooseFlatInput<T> : StrictFlatInput<T>;
274
- type LooseFlatInputWithHash<T extends AnyRoute | string> = LooseFlatInput<T> & {
275
- hash?: string | number;
276
- };
277
- type StrictFlatInputWithHash<T extends AnyRoute | string> = StrictFlatInput<T> & {
278
- hash?: string | number;
279
- };
280
- type FlatInputWithHash<T extends AnyRoute | string, TLoose extends boolean = HasLooseSearch<T>> = FlatInput<T, TLoose> & {
281
- hash?: string | number;
282
- };
283
- type CanInputBeEmpty<T extends AnyRoute | string> = HasParams<Definition<T>> extends true ? false : true;
284
- type ParamsInputStringOnly<T extends AnyRoute | string = string> = _ParamsInputStringOnly<PathDefinition<T>>;
285
- type LooseSearchInputStringOnly<T extends AnyRoute | string = string> = _LooseSearchInputStringOnly<Definition<T>>;
286
- type StrictSearchInputStringOnly<T extends AnyRoute | string> = _StrictSearchInputStringOnly<Definition<T>>;
287
- type LooseFlatInputStringOnly<T extends AnyRoute | string> = _LooseFlatInputStringOnly<Definition<T>>;
288
- type StrictFlatInputStringOnly<T extends AnyRoute | string> = _StrictFlatInputStringOnly<Definition<T>>;
289
- type FlatInputStringOnly<T extends AnyRoute | string, TLoose extends boolean = HasLooseSearch<T>> = TLoose extends true ? LooseFlatInputStringOnly<T> : StrictFlatInputStringOnly<T>;
219
+ type ParamsInput<T extends AnyRoute | string = string> = _ParamsInput<Definition<T>>;
220
+ type IsParamsOptional<T extends AnyRoute | string> = HasRequiredParams<Definition<T>> extends true ? false : true;
221
+ type ParamsInputStringOnly<T extends AnyRoute | string = string> = _ParamsInputStringOnly<Definition<T>>;
290
222
  type LocationParams<TDefinition extends string> = {
291
- [K in keyof _ParamsDefinition<TDefinition>]: string;
223
+ [K in keyof _ParamsDefinition<TDefinition>]: _ParamsDefinition<TDefinition>[K] extends true ? string : string | undefined;
292
224
  };
293
- type LocationSearch<TDefinition extends string = string> = {
294
- [K in keyof _SearchDefinition<TDefinition>]: string | undefined;
295
- } & Record<string, string | undefined>;
296
225
  /**
297
226
  * URL location primitives independent from route-matching state.
298
227
  *
@@ -308,20 +237,19 @@ type _GeneralLocation = {
308
237
  */
309
238
  pathname: string;
310
239
  /**
311
- * Raw query string with leading `?`, if present.
240
+ * Parsed query object.
312
241
  *
313
242
  * Example:
314
- * - `?tab=posts&sort=desc`
243
+ * - `{ tab: "posts", sort: "desc" }`
315
244
  */
316
- search: string;
245
+ search: UnknownSearch;
317
246
  /**
318
- * Parsed query map (first value per key).
247
+ * Raw query string with leading `?`, if present.
319
248
  *
320
249
  * Example:
321
- * - search: `?tab=posts&sort=desc`
322
- * - searchParams: `{ tab: 'posts', sort: 'desc' }`
250
+ * - `?tab=posts&sort=desc`
323
251
  */
324
- searchParams: Record<string, string | undefined>;
252
+ searchString: string;
325
253
  /**
326
254
  * Raw hash with leading `#`, if present.
327
255
  *
@@ -371,7 +299,6 @@ type UnknownLocationState = {
371
299
  known: false;
372
300
  route: undefined;
373
301
  params: undefined;
374
- searchParams: LooseSearchOutput;
375
302
  exact: false;
376
303
  ancestor: false;
377
304
  descendant: false;
@@ -383,7 +310,6 @@ type UnmatchedLocationState<TRoute extends AnyRoute | string = AnyRoute | string
383
310
  known: true;
384
311
  route: Definition<TRoute>;
385
312
  params: Record<never, never>;
386
- searchParams: Record<string, string | undefined>;
387
313
  exact: false;
388
314
  ancestor: false;
389
315
  descendant: false;
@@ -395,7 +321,6 @@ type ExactLocationState<TRoute extends AnyRoute | string = AnyRoute | string> =
395
321
  known: true;
396
322
  route: Definition<TRoute>;
397
323
  params: ParamsOutput<TRoute>;
398
- searchParams: LooseSearchOutput<TRoute>;
399
324
  exact: true;
400
325
  ancestor: false;
401
326
  descendant: false;
@@ -407,7 +332,6 @@ type AncestorLocationState<TRoute extends AnyRoute | string = AnyRoute | string>
407
332
  known: true;
408
333
  route: Definition<TRoute>;
409
334
  params: ParamsOutput<TRoute>;
410
- searchParams: LooseSearchOutput<TRoute>;
411
335
  exact: false;
412
336
  ancestor: true;
413
337
  descendant: false;
@@ -419,7 +343,6 @@ type WeakAncestorLocationState<TRoute extends AnyRoute | string = AnyRoute | str
419
343
  known: true;
420
344
  route: Definition<TRoute>;
421
345
  params: ParamsOutput<TRoute>;
422
- searchParams: LooseSearchOutput<TRoute>;
423
346
  exact: false;
424
347
  ancestor: true;
425
348
  descendant: false;
@@ -431,19 +354,18 @@ type DescendantLocationState<TRoute extends AnyRoute | string = AnyRoute | strin
431
354
  known: true;
432
355
  route: Definition<TRoute>;
433
356
  params: Partial<ParamsOutput<TRoute>>;
434
- searchParams: LooseSearchOutput<TRoute>;
435
357
  exact: false;
436
358
  ancestor: false;
437
359
  descendant: true;
438
360
  unmatched: false;
439
361
  };
440
362
  type DescendantLocation<TRoute extends AnyRoute | string = AnyRoute | string> = _GeneralLocation & DescendantLocationState<TRoute>;
363
+ type UnknownSearch = Record<string, unknown>;
441
364
  /** It is when route not match at all, but params partially match. */
442
365
  type WeakDescendantLocationState<TRoute extends AnyRoute | string = AnyRoute | string> = {
443
366
  known: true;
444
367
  route: Definition<TRoute>;
445
368
  params: Partial<ParamsOutput<TRoute>>;
446
- searchParams: LooseSearchOutput<TRoute>;
447
369
  exact: false;
448
370
  ancestor: false;
449
371
  descendant: true;
@@ -452,54 +374,50 @@ type WeakDescendantLocationState<TRoute extends AnyRoute | string = AnyRoute | s
452
374
  type WeakDescendantLocation<TRoute extends AnyRoute | string = AnyRoute | string> = _GeneralLocation & WeakDescendantLocationState<TRoute>;
453
375
  type KnownLocation<TRoute extends AnyRoute | string = AnyRoute | string> = UnmatchedLocation<TRoute> | ExactLocation<TRoute> | AncestorLocation<TRoute> | WeakAncestorLocation<TRoute> | DescendantLocation<TRoute> | WeakDescendantLocation<TRoute>;
454
376
  type AnyLocation<TRoute extends AnyRoute | string = AnyRoute | string> = UnknownLocation | KnownLocation<TRoute>;
455
- type _PathDefinition<T extends string> = T extends string ? TrimSearchTailDefinition<T> : never;
456
- type _ParamsDefinition<TDefinition extends string> = ExtractPathParams<PathDefinition<TDefinition>> extends infer U ? [U] extends [never] ? undefined : {
457
- [K in Extract<U, string>]: true;
458
- } : undefined;
459
- type _SearchDefinition<TDefinition extends string> = NonEmpty<SearchTailDefinitionWithoutFirstAndLastAmp<TDefinition>> extends infer Tail extends string ? AmpSplit<Tail> extends infer U ? [U] extends [never] ? undefined : {
460
- [K in Extract<U, string>]: true;
461
- } : undefined : undefined;
462
- type _ParamsInput<TDefinition extends string> = _ParamsDefinition<TDefinition> extends undefined ? Record<never, never> : {
463
- [K in keyof _ParamsDefinition<TDefinition>]: string | number;
464
- };
465
- type _LooseSearchInput<TDefinition extends string> = _SearchDefinition<TDefinition> extends undefined ? Record<string, string | number> : Partial<{
466
- [K in keyof _SearchDefinition<TDefinition>]: string | number;
467
- }> & Record<string, string | number>;
468
- type _StrictSearchInput<TDefinition extends string> = Partial<{
469
- [K in keyof _SearchDefinition<TDefinition>]: string | number;
470
- }>;
471
- type _LooseFlatInput<TDefinition extends string> = HasParams<TDefinition> extends true ? _ParamsInput<TDefinition> & _LooseSearchInput<TDefinition> : _LooseSearchInput<TDefinition>;
472
- type _StrictFlatInput<TDefinition extends string> = HasParams<TDefinition> extends true ? HasNamedSearch<TDefinition> extends true ? _StrictSearchInput<TDefinition> & _ParamsInput<TDefinition> : _ParamsInput<TDefinition> : HasNamedSearch<TDefinition> extends true ? _StrictSearchInput<TDefinition> : Record<never, never>;
473
- type _ParamsInputStringOnly<TDefinition extends string> = _ParamsDefinition<TDefinition> extends undefined ? Record<never, never> : {
474
- [K in keyof _ParamsDefinition<TDefinition>]: string;
377
+ type _ParamsDefinition<TDefinition extends string> = _ExtractParamsDefinitionBySegments<_SplitPathSegments<Definition<TDefinition>>>;
378
+ type _Simplify<T> = {
379
+ [K in keyof T]: T[K];
380
+ } & {};
381
+ type _IfNoKeys<T extends object, TYes, TNo> = keyof T extends never ? TYes : TNo;
382
+ type _ParamsInput<TDefinition extends string> = _ParamsDefinition<TDefinition> extends infer TDef extends Record<string, boolean> ? _IfNoKeys<TDef, Record<never, never>, _Simplify<{
383
+ [K in keyof TDef as TDef[K] extends true ? K : never]: string | number;
384
+ } & {
385
+ [K in keyof TDef as TDef[K] extends false ? K : never]?: string | number | undefined;
386
+ }>> : Record<never, never>;
387
+ type _ParamsInputStringOnly<TDefinition extends string> = _ParamsDefinition<TDefinition> extends infer TDef extends Record<string, boolean> ? _IfNoKeys<TDef, Record<never, never>, _Simplify<{
388
+ [K in keyof TDef as TDef[K] extends true ? K : never]: string;
389
+ } & {
390
+ [K in keyof TDef as TDef[K] extends false ? K : never]?: string | undefined;
391
+ }>> : Record<never, never>;
392
+ 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];
393
+ type _ParamDefinitionFromSegment<TSegment extends string> = TSegment extends `:${infer Name}?` ? {
394
+ [K in Name]: false;
395
+ } : TSegment extends `:${infer Name}` ? {
396
+ [K in Name]: true;
397
+ } : TSegment extends `${string}*?` ? {
398
+ '*': false;
399
+ } : TSegment extends `${string}*` ? {
400
+ '*': true;
401
+ } : Record<never, never>;
402
+ type _MergeParamDefinitions<A extends Record<string, boolean>, B extends Record<string, boolean>> = {
403
+ [K in keyof A | keyof B]: K extends keyof B ? B[K] : K extends keyof A ? A[K] : never;
475
404
  };
476
- type _LooseSearchInputStringOnly<TDefinition extends string> = _SearchDefinition<TDefinition> extends undefined ? Record<string, string> : Partial<{
477
- [K in keyof _SearchDefinition<TDefinition>]: string;
478
- }> & Record<string, string>;
479
- type _StrictSearchInputStringOnly<TDefinition extends string> = Partial<{
480
- [K in keyof _SearchDefinition<TDefinition>]: string;
481
- }>;
482
- type _LooseFlatInputStringOnly<TDefinition extends string> = HasParams<TDefinition> extends true ? _ParamsInputStringOnly<TDefinition> & _LooseSearchInputStringOnly<TDefinition> : _LooseSearchInputStringOnly<TDefinition>;
483
- type _StrictFlatInputStringOnly<TDefinition extends string> = HasParams<TDefinition> extends true ? HasNamedSearch<TDefinition> extends true ? _StrictSearchInputStringOnly<TDefinition> & _ParamsInputStringOnly<TDefinition> : _ParamsInputStringOnly<TDefinition> : HasNamedSearch<TDefinition> extends true ? _StrictSearchInputStringOnly<TDefinition> : Record<never, never>;
484
- type TrimSearchTailDefinition<S extends string> = S extends `${infer P}&${string}` ? P : S;
485
- type SearchTailDefinitionWithoutFirstAmp<S extends string> = S extends `${string}&${infer T}` ? T : '';
486
- type SearchTailDefinitionWithoutFirstAndLastAmp<S extends string> = S extends `${string}&${infer T}&` ? T : S extends `${string}&${infer T}` ? T : '';
487
- type SearchTailDefinitionWithFirstAmp<S extends string> = S extends `${string}&${infer T}` ? `&${T}` : '';
488
- type AmpSplit<S extends string> = S extends `${infer A}&${infer B}` ? A | AmpSplit<B> : S;
489
- type NonEmpty<T> = [T] extends ['' | never] ? never : T;
490
- type ExtractPathParams<S extends string> = S extends `${string}:${infer After}` ? After extends `${infer Name}/${infer Rest}` ? Name | ExtractPathParams<`/${Rest}`> : After : never;
405
+ type _ExtractParamsDefinitionBySegments<TSegments extends string[]> = TSegments extends [
406
+ infer Segment extends string,
407
+ ...infer Rest extends string[]
408
+ ] ? _MergeParamDefinitions<_ParamDefinitionFromSegment<Segment>, _ExtractParamsDefinitionBySegments<Rest>> : Record<never, never>;
409
+ type _RequiredParamKeys<TDefinition extends string> = {
410
+ [K in keyof _ParamsDefinition<TDefinition>]: _ParamsDefinition<TDefinition>[K] extends true ? K : never;
411
+ }[keyof _ParamsDefinition<TDefinition>];
491
412
  type ReplacePathParams<S extends string> = S extends `${infer Head}:${infer Tail}` ? Tail extends `${infer _Param}/${infer Rest}` ? ReplacePathParams<`${Head}${string}/${Rest}`> : `${Head}${string}` : S;
492
413
  type DedupeSlashes<S extends string> = S extends `${infer A}//${infer B}` ? DedupeSlashes<`${A}/${B}`> : S;
493
414
  type EmptyRecord = Record<never, never>;
494
- type JoinPath<Parent extends string, Suffix extends string> = DedupeSlashes<PathDefinition<Parent> extends infer A extends string ? PathDefinition<Suffix> extends infer B extends string ? A extends '' ? B extends '' ? '' : B extends `/${string}` ? B : `/${B}` : B extends '' ? A : A extends `${string}/` ? `${A}${B}` : B extends `/${string}` ? `${A}${B}` : `${A}/${B}` : never : never>;
415
+ type JoinPath<Parent extends string, Suffix extends string> = DedupeSlashes<Definition<Parent> extends infer A extends string ? Definition<Suffix> extends infer B extends string ? A extends '' ? B extends '' ? '' : B extends `/${string}` ? B : `/${B}` : B extends '' ? A : A extends `${string}/` ? `${A}${B}` : B extends `/${string}` ? `${A}${B}` : `${A}/${B}` : never : never>;
495
416
  type OnlyIfNoParams<TRoute extends AnyRoute | string, Yes, No = never> = HasParams<TRoute> extends false ? Yes : No;
496
417
  type OnlyIfHasParams<TRoute extends AnyRoute | string, Yes, No = never> = HasParams<TRoute> extends true ? Yes : No;
497
- type PathExtended<TSourcedefinitionDefinition extends string, TSuffixdefinitionDefinition extends string> = `${JoinPath<TSourcedefinitionDefinition, TSuffixdefinitionDefinition>}${SearchTailDefinitionWithFirstAmp<TSuffixdefinitionDefinition>}`;
498
- type WithParamsInput<TDefinition extends string, T extends {
499
- search?: _LooseSearchInput<any>;
500
- abs?: boolean | string;
501
- hash?: string | number;
502
- } | undefined = undefined> = _ParamsInput<TDefinition> & (T extends undefined ? Record<never, never> : T);
418
+ type PathExtended<TSourceDefinitionDefinition extends string, TSuffixDefinitionDefinition extends string> = `${JoinPath<StripTrailingWildcard<TSourceDefinitionDefinition>, TSuffixDefinitionDefinition>}`;
419
+ type StripTrailingWildcard<TDefinition extends string> = TDefinition extends `${infer TPath}*?` ? TPath : TDefinition extends `${infer TPath}*` ? TPath : TDefinition;
420
+ type IsAny<T> = 0 extends 1 & T ? true : false;
503
421
  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;
504
422
  type _IsAncestor<T extends string, TAncestor extends string> = T extends TAncestor ? false : T extends `${TAncestor}${string}` ? true : false;
505
423
  type _IsDescendant<T extends string, TDescendant extends string> = TDescendant extends T ? false : TDescendant extends `${T}${string}` ? true : false;
@@ -513,11 +431,9 @@ type _SafeParseInputResult<TInputParsed extends Record<string, unknown>> = {
513
431
  data: undefined;
514
432
  error: Error;
515
433
  };
516
- type SafeParseInputStrictResult<TDefinition extends string> = _SafeParseInputResult<StrictFlatOutput<TDefinition>>;
517
- type SafeParseInputLooseResult<TDefinition extends string> = _SafeParseInputResult<LooseFlatOutput<TDefinition>>;
518
- type Route0Schema<TInput extends Record<string, unknown>, TOutput extends Record<string, unknown>> = StandardSchemaV1<TInput, TOutput> & {
434
+ type SchemaRoute0<TInput extends Record<string, unknown>, TOutput extends Record<string, unknown>> = StandardSchemaV1<TInput, TOutput> & {
519
435
  parse: (input: unknown) => TOutput;
520
436
  safeParse: (input: unknown) => _SafeParseInputResult<TOutput>;
521
437
  };
522
438
 
523
- export { type AmpSplit, type AncestorLocation, type AncestorLocationState, type AnyLocation, type AnyRoute, type AnyRouteOrDefinition, type CallableRoute, type CanInputBeEmpty, type DedupeSlashes, type Definition, type DescendantLocation, type DescendantLocationState, type EmptyRecord, type ExactLocation, type ExactLocationState, type Extended, type ExtractPathParams, type ExtractRoute, type ExtractRoutesKeys, type FlatInput, type FlatInputStringOnly, type FlatInputWithHash, type FlatOutput, type FlatOutputWithHash, type HasLooseSearch, type HasNamedSearch, type HasParams, type HasSearch, type IsAncestor, type IsDescendant, type IsSame, type IsSameParams, type JoinPath, type KnownLocation, type LocationParams, type LocationSearch, type LooseFlatInput, type LooseFlatInputStringOnly, type LooseFlatInputWithHash, type LooseFlatOutput, type LooseFlatOutputWithHash, type LooseSearchInput, type LooseSearchInputStringOnly, type LooseSearchOutput, type NonEmpty, type OnlyIfHasParams, type OnlyIfNoParams, type ParamsDefinition, type ParamsInput, type ParamsInputStringOnly, type ParamsOutput, type PathDefinition, type PathExtended, type ReplacePathParams, Route0, type Route0Schema, type RouteConfigInput, Routes, type RoutesPretty, type RoutesRecord, type RoutesRecordHydrated, type SafeParseInputLooseResult, type SafeParseInputStrictResult, type SearchDefinition, type SearchTailDefinitionWithFirstAmp, type SearchTailDefinitionWithoutFirstAmp, type SearchTailDefinitionWithoutFirstAndLastAmp, type StrictFlatInput, type StrictFlatInputStringOnly, type StrictFlatInputWithHash, type StrictFlatOutput, type StrictFlatOutputWithHash, type StrictSearchInput, type StrictSearchInputStringOnly, type StrictSearchOutput, type TrimSearchTailDefinition, type UnknownLocation, type UnknownLocationState, type UnmatchedLocation, type UnmatchedLocationState, type WeakAncestorLocation, type WeakAncestorLocationState, type WeakDescendantLocation, type WeakDescendantLocationState, type WithParamsInput, type _GeneralLocation, type _IsAncestor, type _IsDescendant, type _IsSame, type _IsSameParams, type _LooseFlatInput, type _LooseFlatInputStringOnly, type _LooseSearchInput, type _LooseSearchInputStringOnly, type _ParamsDefinition, type _ParamsInput, type _ParamsInputStringOnly, type _PathDefinition, type _SafeParseInputResult, type _SearchDefinition, type _StrictFlatInput, type _StrictFlatInputStringOnly, type _StrictSearchInput, type _StrictSearchInputStringOnly };
439
+ export { type AncestorLocation, type AncestorLocationState, type AnyLocation, type AnyRoute, type AnyRouteOrDefinition, type CallableRoute, type DedupeSlashes, type Definition, type DescendantLocation, type DescendantLocationState, type EmptyRecord, type ExactLocation, type ExactLocationState, type Extended, type ExtractRoute, type ExtractRoutesKeys, type HasParams, type HasRequiredParams, type IsAncestor, type IsAny, type IsDescendant, type IsParamsOptional, type IsSame, type IsSameParams, type JoinPath, type KnownLocation, type LocationParams, type OnlyIfHasParams, type OnlyIfNoParams, type ParamsDefinition, type ParamsInput, type ParamsInputStringOnly, type ParamsOutput, type PathExtended, type PathToken, type ReplacePathParams, Route0, type RouteConfigInput, Routes, type RoutesPretty, type RoutesRecord, type RoutesRecordHydrated, type SchemaRoute0, type StripTrailingWildcard, type UnknownLocation, type UnknownLocationState, type UnknownSearch, type UnmatchedLocation, type UnmatchedLocationState, type WeakAncestorLocation, type WeakAncestorLocationState, type WeakDescendantLocation, type WeakDescendantLocationState, type _ExtractParamsDefinitionBySegments, type _GeneralLocation, type _IfNoKeys, type _IsAncestor, type _IsDescendant, type _IsSame, type _IsSameParams, type _MergeParamDefinitions, type _ParamDefinitionFromSegment, type _ParamsDefinition, type _ParamsInput, type _ParamsInputStringOnly, type _RequiredParamKeys, type _SafeParseInputResult, type _Simplify, type _SplitPathSegments };