@tanstack/router-core 0.0.1-beta.150 → 0.0.1-beta.152

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/router-core",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.0.1-beta.150",
4
+ "version": "0.0.1-beta.152",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
@@ -43,7 +43,7 @@
43
43
  "tiny-invariant": "^1.3.1",
44
44
  "tiny-warning": "^1.0.3",
45
45
  "@gisatcz/cross-package-react-context": "^0.2.0",
46
- "@tanstack/react-store": "0.0.1-beta.150"
46
+ "@tanstack/react-store": "0.0.1-beta.152"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "rollup --config rollup.config.js",
package/src/fileRoute.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Last, ParsePathParams, Split } from './link'
1
+ import { T } from 'vitest/dist/types-198fd1d9'
2
+ import { CleanPath, Last, ParsePathParams, Split } from './link'
2
3
  import {
3
4
  AnyRoute,
4
5
  ResolveFullPath,
@@ -12,6 +13,9 @@ import {
12
13
  InferFullSearchSchema,
13
14
  UpdatableRouteOptions,
14
15
  Route,
16
+ AnyPathParams,
17
+ RootRouteId,
18
+ TrimPathLeft,
15
19
  } from './route'
16
20
  import { DefaultRoutesInfo } from './routeInfo'
17
21
 
@@ -21,36 +25,71 @@ export interface FileRoutesByPath {
21
25
  // }
22
26
  }
23
27
 
24
- type Test = Last<Split<'/test/:id'>>
28
+ type Replace<
29
+ S extends string,
30
+ From extends string,
31
+ To extends string,
32
+ > = S extends `${infer Start}${From}${infer Rest}`
33
+ ? `${Start}${To}${Replace<Rest, From, To>}`
34
+ : S
35
+
36
+ export type TrimLeft<
37
+ T extends string,
38
+ S extends string,
39
+ > = T extends `${S}${infer U}` ? U : T
40
+
41
+ export type TrimRight<
42
+ T extends string,
43
+ S extends string,
44
+ > = T extends `${infer U}${S}` ? U : T
45
+
46
+ export type Trim<T extends string, S extends string> = TrimLeft<
47
+ TrimRight<T, S>,
48
+ S
49
+ >
50
+
51
+ export type ResolveFilePath<
52
+ TParentRoute extends AnyRoute,
53
+ TFilePath extends string,
54
+ > = TParentRoute['id'] extends RootRouteId
55
+ ? TrimPathLeft<TFilePath>
56
+ : Replace<
57
+ TrimPathLeft<TFilePath>,
58
+ TrimPathLeft<TParentRoute['__types']['customId']>,
59
+ ''
60
+ >
61
+
62
+ export type FileRoutePath<
63
+ TParentRoute extends AnyRoute,
64
+ TFilePath extends string,
65
+ > = ResolveFilePath<TParentRoute, TFilePath> extends `_${infer _}`
66
+ ? string
67
+ : ResolveFilePath<TParentRoute, TFilePath>
25
68
 
26
69
  export class FileRoute<
27
70
  TFilePath extends keyof FileRoutesByPath,
28
71
  TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],
29
- TPath extends string = Last<Split<TFilePath>>,
30
- TCustomId extends string = TPath extends `_${infer T}` ? T : string,
72
+ TId extends string = TFilePath,
73
+ TPath extends string = FileRoutePath<TParentRoute, TFilePath>,
74
+ TFullPath extends string = ResolveFullPath<TParentRoute, TPath>,
31
75
  > {
32
76
  constructor(public path: TFilePath) {}
33
77
 
34
78
  createRoute = <
35
- TFullPath extends ResolveFullPath<TParentRoute, TPath> = ResolveFullPath<
36
- TParentRoute,
37
- TPath
38
- >,
39
- TId extends ResolveId<TParentRoute, TCustomId, TPath> = ResolveId<
40
- TParentRoute,
41
- TCustomId,
42
- TPath
43
- >,
44
79
  TLoader = unknown,
45
80
  TSearchSchema extends AnySearchSchema = {},
46
81
  TFullSearchSchema extends AnySearchSchema = ResolveFullSearchSchema<
47
82
  TParentRoute,
48
83
  TSearchSchema
49
84
  >,
50
- TParams extends Record<ParsePathParams<TPath>, any> = Record<
51
- ParsePathParams<TPath>,
52
- string
53
- >,
85
+ TParams extends ParsePathParams<TPath> extends never
86
+ ? AnyPathParams
87
+ : Record<
88
+ ParsePathParams<TPath>,
89
+ any
90
+ > = ParsePathParams<TPath> extends never
91
+ ? AnyPathParams
92
+ : Record<ParsePathParams<TPath>, string>,
54
93
  TAllParams extends MergeParamsFromParent<
55
94
  TParentRoute['__types']['allParams'],
56
95
  TParams
@@ -72,13 +111,12 @@ export class FileRoute<
72
111
  options: Omit<
73
112
  RouteOptions<
74
113
  TParentRoute,
75
- TCustomId,
76
- TPath,
114
+ string,
115
+ string,
77
116
  TLoader,
78
117
  InferFullSearchSchema<TParentRoute>,
79
118
  TSearchSchema,
80
119
  TFullSearchSchema,
81
- TParentRoute['__types']['allParams'],
82
120
  TParams,
83
121
  TAllParams,
84
122
  TParentContext,
@@ -100,7 +138,7 @@ export class FileRoute<
100
138
  TParentRoute,
101
139
  TPath,
102
140
  TFullPath,
103
- TCustomId,
141
+ TFilePath,
104
142
  TId,
105
143
  TLoader,
106
144
  TSearchSchema,
package/src/link.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Trim } from './fileRoute'
1
2
  import { AnyRoutesInfo, RouteByPath } from './routeInfo'
2
3
  import { ParsedLocation, LocationState, RegisteredRoutesInfo } from './router'
3
4
  import { NoInfer, PickRequired, UnionToIntersection, Updater } from './utils'
@@ -19,7 +20,7 @@ export type LinkInfo =
19
20
  disabled?: boolean
20
21
  }
21
22
 
22
- type CleanPath<T extends string> = T extends `${infer L}//${infer R}`
23
+ export type CleanPath<T extends string> = T extends `${infer L}//${infer R}`
23
24
  ? CleanPath<`${CleanPath<L>}/${CleanPath<R>}`>
24
25
  : T extends `${infer L}//`
25
26
  ? `${CleanPath<L>}/`
@@ -49,11 +50,9 @@ export type Split<S, TIncludeTrailingSlash = true> = S extends unknown
49
50
  : never
50
51
  : never
51
52
 
52
- export type ParsePathParams<T extends string> = Split<T>[number] extends infer U
53
- ? U extends `$${infer V}`
54
- ? V
55
- : never
56
- : never
53
+ export type ParsePathParams<T extends string> = keyof {
54
+ [K in Trim<Split<T>[number], '_'> as K extends `$${infer L}` ? L : never]: K
55
+ }
57
56
 
58
57
  export type Join<T, Delimiter extends string = '/'> = T extends []
59
58
  ? ''
package/src/route.ts CHANGED
@@ -135,24 +135,12 @@ export type RouteOptions<
135
135
  TParentSearchSchema extends AnySearchSchema = {},
136
136
  TSearchSchema extends AnySearchSchema = {},
137
137
  TFullSearchSchema extends AnySearchSchema = TSearchSchema,
138
- TParentParams extends AnyPathParams = AnyPathParams,
139
- TParams extends AnyPathParams = Record<ParsePathParams<TPath>, string>,
138
+ TParams extends AnyPathParams = AnyPathParams,
140
139
  TAllParams extends AnyPathParams = TParams,
141
140
  TParentContext extends AnyContext = AnyContext,
142
- TAllParentContext extends IsAny<
143
- TParentRoute['__types']['allParams'],
144
- TParentContext,
145
- TParentRoute['__types']['allParams'] & TParentContext
146
- > = IsAny<
147
- TParentRoute['__types']['allParams'],
148
- TParentContext,
149
- TParentRoute['__types']['allParams'] & TParentContext
150
- >,
141
+ TAllParentContext extends AnyContext = AnyContext,
151
142
  TRouteContext extends RouteContext = RouteContext,
152
- TContext extends MergeParamsFromParent<
153
- TAllParentContext,
154
- TRouteContext
155
- > = MergeParamsFromParent<TAllParentContext, TRouteContext>,
143
+ TContext extends AnyContext = AnyContext,
156
144
  > = BaseRouteOptions<
157
145
  TParentRoute,
158
146
  TCustomId,
@@ -161,7 +149,6 @@ export type RouteOptions<
161
149
  TParentSearchSchema,
162
150
  TSearchSchema,
163
151
  TFullSearchSchema,
164
- TParentParams,
165
152
  TParams,
166
153
  TAllParams,
167
154
  TParentContext,
@@ -183,6 +170,14 @@ export type ParamsFallback<
183
170
  TParams,
184
171
  > = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams
185
172
 
173
+ type Prefix<T extends string, U extends string> = U extends `${T}${infer _}`
174
+ ? U
175
+ : never
176
+
177
+ type PrefixOrExact<T extends string, U extends string> = U extends T
178
+ ? U
179
+ : Prefix<T, U>
180
+
186
181
  export type BaseRouteOptions<
187
182
  TParentRoute extends AnyRoute = AnyRoute,
188
183
  TCustomId extends string = string,
@@ -191,25 +186,14 @@ export type BaseRouteOptions<
191
186
  TParentSearchSchema extends AnySearchSchema = {},
192
187
  TSearchSchema extends AnySearchSchema = {},
193
188
  TFullSearchSchema extends AnySearchSchema = TSearchSchema,
194
- TParentParams extends AnyPathParams = AnyPathParams,
195
189
  TParams = unknown,
196
190
  TAllParams = ParamsFallback<TPath, TParams>,
197
191
  TParentContext extends AnyContext = AnyContext,
198
- TAllParentContext extends IsAny<
199
- TParentRoute['__types']['allParams'],
200
- TParentContext,
201
- TParentRoute['__types']['allParams'] & TParentContext
202
- > = IsAny<
203
- TParentRoute['__types']['allParams'],
204
- TParentContext,
205
- TParentRoute['__types']['allParams'] & TParentContext
206
- >,
192
+ TAllParentContext extends AnyContext = AnyContext,
207
193
  TRouteContext extends RouteContext = RouteContext,
208
- TContext extends MergeParamsFromParent<
209
- TAllParentContext,
210
- TRouteContext
211
- > = MergeParamsFromParent<TAllParentContext, TRouteContext>,
194
+ TContext extends AnyContext = AnyContext,
212
195
  > = RoutePathOptions<TCustomId, TPath> & {
196
+ layoutLimit?: string
213
197
  getParentRoute: () => TParentRoute
214
198
  validateSearch?: SearchSchemaValidator<TSearchSchema, TParentSearchSchema>
215
199
  loader?: LoaderFn<
@@ -555,43 +539,62 @@ export type StreamedPromise<T> = {
555
539
  resolve: (value: T) => void
556
540
  }
557
541
 
542
+ export type RouteConstraints = {
543
+ TParentRoute: AnyRoute
544
+ TPath: string
545
+ TFullPath: string
546
+ TCustomId: string
547
+ TId: string
548
+ TSearchSchema: AnySearchSchema
549
+ TFullSearchSchema: AnySearchSchema
550
+ TParams: Record<string, any>
551
+ TAllParams: Record<string, any>
552
+ TParentContext: AnyContext
553
+ TAllParentContext: AnyContext
554
+ TRouteContext: RouteContext
555
+ TContext: AnyContext
556
+ TRouterContext: AnyContext
557
+ TChildren: unknown
558
+ TRoutesInfo: DefaultRoutesInfo
559
+ }
560
+
558
561
  export class Route<
559
- TParentRoute extends AnyRoute = AnyRoute,
560
- TPath extends string = '/',
561
- TFullPath extends ResolveFullPath<TParentRoute, TPath> = ResolveFullPath<
562
+ TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,
563
+ TPath extends RouteConstraints['TPath'] = '/',
564
+ TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
562
565
  TParentRoute,
563
566
  TPath
564
567
  >,
565
- TCustomId extends string = string,
566
- TId extends ResolveId<TParentRoute, TCustomId, TPath> = ResolveId<
568
+ TCustomId extends RouteConstraints['TCustomId'] = string,
569
+ TId extends RouteConstraints['TId'] = ResolveId<
567
570
  TParentRoute,
568
571
  TCustomId,
569
572
  TPath
570
573
  >,
571
574
  TLoader = unknown,
572
- TSearchSchema extends AnySearchSchema = {},
573
- TFullSearchSchema extends AnySearchSchema = ResolveFullSearchSchema<
575
+ TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
576
+ TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
574
577
  TParentRoute,
575
578
  TSearchSchema
576
579
  >,
577
- TParams extends Record<ParsePathParams<TPath>, any> = Record<
580
+ TParams extends RouteConstraints['TParams'] = Record<
578
581
  ParsePathParams<TPath>,
579
582
  string
580
583
  >,
581
- TAllParams extends MergeParamsFromParent<
584
+ TAllParams extends RouteConstraints['TAllParams'] = MergeParamsFromParent<
582
585
  TParentRoute['__types']['allParams'],
583
586
  TParams
584
- > = MergeParamsFromParent<TParentRoute['__types']['allParams'], TParams>,
585
- TParentContext extends TParentRoute['__types']['routeContext'] = TParentRoute['__types']['routeContext'],
586
- TAllParentContext extends TParentRoute['__types']['context'] = TParentRoute['__types']['context'],
587
- TRouteContext extends RouteContext = RouteContext,
588
- TContext extends MergeParamsFromParent<
587
+ >,
588
+ TParentContext extends RouteConstraints['TParentContext'] = TParentRoute['__types']['routeContext'],
589
+ TAllParentContext extends RouteConstraints['TAllParentContext'] = TParentRoute['__types']['context'],
590
+ TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,
591
+ TContext extends RouteConstraints['TContext'] = MergeParamsFromParent<
589
592
  TParentRoute['__types']['context'],
590
593
  TRouteContext
591
- > = MergeParamsFromParent<TParentRoute['__types']['context'], TRouteContext>,
592
- TRouterContext extends AnyContext = AnyContext,
593
- TChildren extends unknown = unknown,
594
- TRoutesInfo extends DefaultRoutesInfo = DefaultRoutesInfo,
594
+ >,
595
+ TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
596
+ TChildren extends RouteConstraints['TChildren'] = unknown,
597
+ TRoutesInfo extends RouteConstraints['TRoutesInfo'] = DefaultRoutesInfo,
595
598
  > {
596
599
  __types!: {
597
600
  parentRoute: TParentRoute
@@ -622,7 +625,6 @@ export class Route<
622
625
  InferFullSearchSchema<TParentRoute>,
623
626
  TSearchSchema,
624
627
  TFullSearchSchema,
625
- TParentRoute['__types']['allParams'],
626
628
  TParams,
627
629
  TAllParams,
628
630
  TParentContext,
@@ -662,7 +664,6 @@ export class Route<
662
664
  InferFullSearchSchema<TParentRoute>,
663
665
  TSearchSchema,
664
666
  TFullSearchSchema,
665
- TParentRoute['__types']['allParams'],
666
667
  TParams,
667
668
  TAllParams,
668
669
  TParentContext,
@@ -694,7 +695,6 @@ export class Route<
694
695
  TPath,
695
696
  InferFullSearchSchema<TParentRoute>,
696
697
  TSearchSchema,
697
- TParentRoute['__types']['allParams'],
698
698
  TParams
699
699
  > &
700
700
  RoutePathOptionsIntersection<TCustomId, TPath>
@@ -805,7 +805,7 @@ export class RouterContext<TRouterContext extends {}> {
805
805
  TContext extends RouteContext = RouteContext,
806
806
  >(
807
807
  options?: Omit<
808
- RouteOptions<AnyRoute, RootRouteId, '', {}, TSearchSchema, {}, {}>,
808
+ RouteOptions<AnyRoute, RootRouteId, '', {}, TSearchSchema, {}>,
809
809
  | 'path'
810
810
  | 'id'
811
811
  | 'getParentRoute'
@@ -846,7 +846,7 @@ export class RootRoute<
846
846
  > {
847
847
  constructor(
848
848
  options?: Omit<
849
- RouteOptions<AnyRoute, RootRouteId, '', TLoader, TSearchSchema, {}, {}>,
849
+ RouteOptions<AnyRoute, RootRouteId, '', TLoader, TSearchSchema, {}>,
850
850
  | 'path'
851
851
  | 'id'
852
852
  | 'getParentRoute'
@@ -862,10 +862,7 @@ export class RootRoute<
862
862
  export type ResolveFullPath<
863
863
  TParentRoute extends AnyRoute,
864
864
  TPath extends string,
865
- TPrefixed extends RoutePrefix<TParentRoute['fullPath'], TPath> = RoutePrefix<
866
- TParentRoute['fullPath'],
867
- TPath
868
- >,
865
+ TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>,
869
866
  > = TPrefixed extends RootRouteId ? '/' : TPrefixed
870
867
 
871
868
  type RoutePrefix<
package/src/router.ts CHANGED
@@ -649,10 +649,11 @@ export class Router<
649
649
  return false
650
650
  })
651
651
 
652
- let routeCursor = foundRoute || (this.routesById['__root__'] as any)
652
+ let routeCursor: AnyRoute =
653
+ foundRoute || (this.routesById['__root__'] as any)
653
654
 
654
655
  let matchedRoutes: AnyRoute[] = [routeCursor]
655
-
656
+ // let includingLayouts = true
656
657
  while (routeCursor?.parentRoute) {
657
658
  routeCursor = routeCursor.parentRoute
658
659
  if (routeCursor) matchedRoutes.unshift(routeCursor)