@tanstack/router-core 0.0.1-beta.14 → 0.0.1-beta.146

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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/build/cjs/fileRoute.js +29 -0
  3. package/build/cjs/fileRoute.js.map +1 -0
  4. package/build/cjs/history.js +226 -0
  5. package/build/cjs/history.js.map +1 -0
  6. package/build/cjs/index.js +78 -0
  7. package/build/cjs/{packages/router-core/src/index.js.map → index.js.map} +1 -1
  8. package/build/cjs/{packages/router-core/src/path.js → path.js} +45 -56
  9. package/build/cjs/path.js.map +1 -0
  10. package/build/cjs/{packages/router-core/src/qss.js → qss.js} +10 -16
  11. package/build/cjs/qss.js.map +1 -0
  12. package/build/cjs/route.js +103 -0
  13. package/build/cjs/route.js.map +1 -0
  14. package/build/cjs/router.js +1102 -0
  15. package/build/cjs/router.js.map +1 -0
  16. package/build/cjs/{packages/router-core/src/searchParams.js → searchParams.js} +11 -13
  17. package/build/cjs/searchParams.js.map +1 -0
  18. package/build/cjs/{packages/router-core/src/utils.js → utils.js} +54 -64
  19. package/build/cjs/utils.js.map +1 -0
  20. package/build/esm/index.js +1403 -2096
  21. package/build/esm/index.js.map +1 -1
  22. package/build/stats-html.html +59 -49
  23. package/build/stats-react.json +203 -234
  24. package/build/types/index.d.ts +603 -422
  25. package/build/umd/index.development.js +1629 -2218
  26. package/build/umd/index.development.js.map +1 -1
  27. package/build/umd/index.production.js +13 -2
  28. package/build/umd/index.production.js.map +1 -1
  29. package/package.json +11 -7
  30. package/src/fileRoute.ts +122 -0
  31. package/src/history.ts +292 -0
  32. package/src/index.ts +3 -10
  33. package/src/link.ts +118 -113
  34. package/src/path.ts +37 -17
  35. package/src/qss.ts +1 -2
  36. package/src/route.ts +891 -218
  37. package/src/routeInfo.ts +121 -197
  38. package/src/router.ts +1481 -1018
  39. package/src/searchParams.ts +1 -1
  40. package/src/utils.ts +80 -49
  41. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -33
  42. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  43. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
  44. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
  45. package/build/cjs/node_modules/history/index.js +0 -815
  46. package/build/cjs/node_modules/history/index.js.map +0 -1
  47. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
  48. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
  49. package/build/cjs/packages/router-core/src/index.js +0 -58
  50. package/build/cjs/packages/router-core/src/path.js.map +0 -1
  51. package/build/cjs/packages/router-core/src/qss.js.map +0 -1
  52. package/build/cjs/packages/router-core/src/route.js +0 -147
  53. package/build/cjs/packages/router-core/src/route.js.map +0 -1
  54. package/build/cjs/packages/router-core/src/routeConfig.js +0 -69
  55. package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
  56. package/build/cjs/packages/router-core/src/routeMatch.js +0 -226
  57. package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
  58. package/build/cjs/packages/router-core/src/router.js +0 -832
  59. package/build/cjs/packages/router-core/src/router.js.map +0 -1
  60. package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
  61. package/build/cjs/packages/router-core/src/utils.js.map +0 -1
  62. package/src/frameworks.ts +0 -11
  63. package/src/routeConfig.ts +0 -489
  64. package/src/routeMatch.ts +0 -312
package/src/routeInfo.ts CHANGED
@@ -1,228 +1,152 @@
1
- import { ParsePathParams } from './link'
2
- import { Route } from './route'
3
- import {
4
- AnyLoaderData,
5
- AnyPathParams,
6
- AnyRouteConfig,
7
- AnyRouteConfigWithChildren,
8
- AnySearchSchema,
9
- RootRouteId,
10
- RouteConfig,
11
- RouteOptions,
12
- } from './routeConfig'
13
- import { IsAny, Values } from './utils'
1
+ import { AnyRoute, Route } from './route'
2
+ import { AnyPathParams, AnySearchSchema, RootRouteId } from './route'
3
+ import { IsAny, MergeUnion, Values } from './utils'
14
4
 
15
- export interface AnyAllRouteInfo {
16
- routeConfig: AnyRouteConfig
17
- routeInfo: AnyRouteInfo
18
- routeInfoById: Record<string, AnyRouteInfo>
19
- routeInfoByFullPath: Record<string, AnyRouteInfo>
5
+ export interface AnyRoutesInfo {
6
+ routeTree: AnyRoute
7
+ routeUnion: AnyRoute
8
+ routesById: Record<string, AnyRoute>
9
+ routesByFullPath: Record<string, AnyRoute>
20
10
  routeIds: any
21
11
  routePaths: any
12
+ routeIntersection: AnyRoute
13
+ fullSearchSchema: Record<string, any>
14
+ allParams: Record<string, any>
22
15
  }
23
16
 
24
- export interface DefaultAllRouteInfo {
25
- routeConfig: RouteConfig
26
- routeInfo: RouteInfo
27
- routeInfoById: Record<string, RouteInfo>
28
- routeInfoByFullPath: Record<string, RouteInfo>
17
+ export interface DefaultRoutesInfo {
18
+ routeTree: AnyRoute
19
+ routeUnion: AnyRoute
20
+ routesById: Record<string, Route>
21
+ routesByFullPath: Record<string, Route>
29
22
  routeIds: string
30
23
  routePaths: string
24
+ routeIntersection: AnyRoute
25
+ fullSearchSchema: AnySearchSchema
26
+ allParams: AnyPathParams
31
27
  }
32
28
 
33
- export interface AllRouteInfo<TRouteConfig extends AnyRouteConfig = RouteConfig>
34
- extends RoutesInfoInner<TRouteConfig, ParseRouteConfig<TRouteConfig>> {}
35
-
36
- export type ParseRouteConfig<TRouteConfig = AnyRouteConfig> =
37
- TRouteConfig extends AnyRouteConfig
38
- ? RouteConfigRoute<TRouteConfig> | ParseRouteChildren<TRouteConfig>
39
- : never
40
-
41
- type ParseRouteChildren<TRouteConfig> =
42
- TRouteConfig extends AnyRouteConfigWithChildren<infer TChildren>
43
- ? unknown extends TChildren
44
- ? never
45
- : TChildren extends AnyRouteConfig[]
46
- ? Values<{
47
- [TId in TChildren[number]['id']]: ParseRouteChild<
48
- TChildren[number],
49
- TId
50
- >
51
- }>
52
- : never // Children are not routes
53
- : never // No children
54
-
55
- type ParseRouteChild<TRouteConfig, TId> = TRouteConfig & {
56
- id: TId
57
- } extends AnyRouteConfig
58
- ? ParseRouteConfig<TRouteConfig>
59
- : never
60
-
61
- export type RouteConfigRoute<TRouteConfig> = TRouteConfig extends RouteConfig<
62
- infer TId,
63
- infer TRouteId,
64
- infer TPath,
65
- infer TFullPath,
66
- infer TRouteLoaderData,
67
- infer TLoaderData,
68
- infer TActionPayload,
69
- infer TActionResponse,
70
- infer TParentSearchSchema,
71
- infer TSearchSchema,
72
- infer TFullSearchSchema,
73
- infer TParentParams,
74
- infer TParams,
75
- infer TAllParams,
76
- any
77
- >
78
- ? string extends TRouteId
79
- ? never
80
- : RouteInfo<
81
- TId,
82
- TRouteId,
83
- TPath,
84
- TFullPath,
85
- TRouteLoaderData,
86
- TLoaderData,
87
- TActionPayload,
88
- TActionResponse,
89
- TParentSearchSchema,
90
- TSearchSchema,
91
- TFullSearchSchema,
92
- TParentParams,
93
- TParams,
94
- TAllParams
95
- >
96
- : never
29
+ export interface RoutesInfo<TRouteTree extends AnyRoute = Route>
30
+ extends RoutesInfoInner<TRouteTree, ParseRoute<TRouteTree>> {}
97
31
 
98
32
  export interface RoutesInfoInner<
99
- TRouteConfig extends AnyRouteConfig,
100
- TRouteInfo extends RouteInfo<
101
- string,
102
- string,
103
- any,
104
- any,
105
- any,
106
- any,
107
- any,
108
- any,
109
- any,
110
- any,
111
- any,
112
- any,
113
- any,
114
- any
115
- > = RouteInfo,
116
- TRouteInfoById = {
117
- [TInfo in TRouteInfo as TInfo['id']]: TInfo
33
+ TRouteTree extends AnyRoute,
34
+ TRouteUnion extends AnyRoute = Route,
35
+ TRoutesById = { '/': TRouteUnion } & {
36
+ [TRoute in TRouteUnion as TRoute['id']]: TRoute
118
37
  },
119
- TRouteInfoByFullPath = {
120
- [TInfo in TRouteInfo as TInfo['fullPath'] extends RootRouteId
38
+ // RoutePaths should always use index routes if possible, but not
39
+ // force trailing slashes. To do this, we check if each route
40
+ // has an index route registered and if it does, we omit the layout
41
+ // route. Then for any index routes, we remove the trailing slash
42
+ TRoutesByFullPath = { '/': TRouteUnion } & {
43
+ [TRoute in TRouteUnion as TRoute['fullPath'] extends RootRouteId
121
44
  ? never
122
- : string extends TInfo['fullPath']
45
+ : string extends TRoute['fullPath']
123
46
  ? never
124
- : TInfo['fullPath']]: TInfo
47
+ : `${TRoute['fullPath']}/` extends keyof TRoutesById
48
+ ? never
49
+ : TRoute['fullPath'] extends `${infer Trimmed}/`
50
+ ? Trimmed
51
+ : TRoute['fullPath']]: TRoute
125
52
  },
126
53
  > {
127
- routeConfig: TRouteConfig
128
- routeInfo: TRouteInfo
129
- routeInfoById: TRouteInfoById
130
- routeInfoByFullPath: TRouteInfoByFullPath
131
- routeIds: keyof TRouteInfoById
132
- routePaths: keyof TRouteInfoByFullPath
54
+ routeTree: TRouteTree
55
+ routeUnion: TRouteUnion
56
+ routesById: TRoutesById
57
+ routesByFullPath: TRoutesByFullPath
58
+ routeIds: keyof TRoutesById
59
+ routePaths: keyof TRoutesByFullPath
60
+ routeIntersection: Route<
61
+ TRouteUnion['__types']['parentRoute'], // TParentRoute,
62
+ TRouteUnion['__types']['path'], // TPath,
63
+ TRouteUnion['__types']['fullPath'], // TFullPath,
64
+ TRouteUnion['__types']['customId'], // TCustomId,
65
+ TRouteUnion['__types']['id'], // TId,
66
+ TRouteUnion['__types']['loader'], // TId,
67
+ MergeUnion<TRouteUnion['__types']['searchSchema']> & {}, // TSearchSchema,
68
+ MergeUnion<TRouteUnion['__types']['fullSearchSchema']> & {}, // TFullSearchSchema,
69
+ MergeUnion<TRouteUnion['__types']['params']>, // TParams,
70
+ MergeUnion<TRouteUnion['__types']['allParams']>, // TAllParams,
71
+ MergeUnion<TRouteUnion['__types']['parentContext']>, // TParentContext,
72
+ MergeUnion<TRouteUnion['__types']['allParentContext']>, // TAllParentContext,
73
+ MergeUnion<TRouteUnion['__types']['routeContext']> & {}, // TRouteContext,
74
+ MergeUnion<TRouteUnion['__types']['context']> & {}, // TContext,
75
+ MergeUnion<TRouteUnion['__types']['routerContext']> & {}, // TRouterContext,
76
+ TRouteUnion['__types']['children'], // TChildren,
77
+ TRouteUnion['__types']['routesInfo'] // TRoutesInfo,
78
+ >
79
+ fullSearchSchema: Partial<
80
+ MergeUnion<TRouteUnion['__types']['fullSearchSchema']>
81
+ >
82
+ allParams: Partial<MergeUnion<TRouteUnion['__types']['allParams']>>
133
83
  }
134
84
 
135
- export interface AnyRouteInfo
136
- extends RouteInfo<
137
- any,
138
- any,
139
- any,
140
- any,
141
- any,
142
- any,
143
- any,
144
- any,
145
- any,
146
- any,
147
- any,
148
- any,
149
- any,
150
- any
151
- > {}
85
+ export type ParseRoute<TRouteTree> = TRouteTree extends AnyRoute
86
+ ? TRouteTree | ParseRouteChildren<TRouteTree>
87
+ : never
152
88
 
153
- export interface RouteInfo<
154
- TId extends string = string,
155
- TRouteId extends string = string,
156
- TPath extends string = string,
157
- TFullPath extends string = string,
158
- TRouteLoaderData extends AnyLoaderData = {},
159
- TLoaderData extends AnyLoaderData = {},
160
- TActionPayload = unknown,
161
- TActionResponse = unknown,
162
- TParentSearchSchema extends {} = {},
163
- TSearchSchema extends AnySearchSchema = {},
164
- TFullSearchSchema extends AnySearchSchema = {},
165
- TParentParams extends AnyPathParams = {},
166
- TParams extends Record<ParsePathParams<TPath>, unknown> = Record<
167
- ParsePathParams<TPath>,
168
- string
169
- >,
170
- TAllParams extends AnyPathParams = {},
171
- > {
172
- id: TId
173
- routeId: TRouteId
174
- path: TPath
175
- fullPath: TFullPath
176
- routeLoaderData: TRouteLoaderData
177
- loaderData: TLoaderData
178
- actionPayload: TActionPayload
179
- actionResponse: TActionResponse
180
- searchSchema: TSearchSchema
181
- fullSearchSchema: TFullSearchSchema
182
- parentParams: TParentParams
183
- params: TParams
184
- allParams: TAllParams
185
- options: RouteOptions<
186
- TRouteId,
187
- TPath,
188
- TRouteLoaderData,
189
- TLoaderData,
190
- TActionPayload,
191
- TActionResponse,
192
- TParentSearchSchema,
193
- TSearchSchema,
194
- TFullSearchSchema,
195
- TParentParams,
196
- TParams,
197
- TAllParams
198
- >
199
- }
89
+ export type ParseRouteChildren<TRouteTree> = TRouteTree extends Route<
90
+ any,
91
+ any,
92
+ any,
93
+ any,
94
+ any,
95
+ any,
96
+ any,
97
+ any,
98
+ any,
99
+ any,
100
+ any,
101
+ any,
102
+ any,
103
+ any,
104
+ any,
105
+ infer TChildren,
106
+ any
107
+ >
108
+ ? unknown extends TChildren
109
+ ? never
110
+ : TChildren extends AnyRoute[]
111
+ ? Values<{
112
+ [TId in TChildren[number]['id']]: ParseRouteChild<
113
+ TChildren[number],
114
+ TId
115
+ >
116
+ }>
117
+ : never
118
+ : never
200
119
 
201
- export type RoutesById<TAllRouteInfo extends AnyAllRouteInfo> = {
202
- [K in keyof TAllRouteInfo['routeInfoById']]: Route<
203
- TAllRouteInfo,
204
- TAllRouteInfo['routeInfoById'][K]
205
- >
120
+ export type ParseRouteChild<TRoute, TId> = TRoute extends AnyRoute
121
+ ? ParseRoute<TRoute>
122
+ : never
123
+
124
+ export type RoutesById<TRoutesInfo extends AnyRoutesInfo> = {
125
+ [K in keyof TRoutesInfo['routesById']]: TRoutesInfo['routesById'][K]
206
126
  }
207
127
 
208
- export type RouteInfoById<
209
- TAllRouteInfo extends AnyAllRouteInfo,
128
+ export type RouteById<
129
+ TRoutesInfo extends AnyRoutesInfo,
210
130
  TId,
211
- > = TId extends keyof TAllRouteInfo['routeInfoById']
131
+ > = TId extends keyof TRoutesInfo['routesById']
212
132
  ? IsAny<
213
- TAllRouteInfo['routeInfoById'][TId]['id'],
214
- RouteInfo,
215
- TAllRouteInfo['routeInfoById'][TId]
133
+ TRoutesInfo['routesById'][TId]['id'],
134
+ Route,
135
+ TRoutesInfo['routesById'][TId]
216
136
  >
217
137
  : never
218
138
 
219
- export type RouteInfoByPath<
220
- TAllRouteInfo extends AnyAllRouteInfo,
139
+ export type RoutesByPath<TRoutesInfo extends AnyRoutesInfo> = {
140
+ [K in keyof TRoutesInfo['routesByFullPath']]: TRoutesInfo['routesByFullPath'][K]
141
+ }
142
+
143
+ export type RouteByPath<
144
+ TRoutesInfo extends AnyRoutesInfo,
221
145
  TPath,
222
- > = TPath extends keyof TAllRouteInfo['routeInfoByFullPath']
146
+ > = TPath extends keyof TRoutesInfo['routesByFullPath']
223
147
  ? IsAny<
224
- TAllRouteInfo['routeInfoByFullPath'][TPath]['id'],
225
- RouteInfo,
226
- TAllRouteInfo['routeInfoByFullPath'][TPath]
148
+ TRoutesInfo['routesByFullPath'][TPath]['id'],
149
+ Route,
150
+ TRoutesInfo['routesByFullPath'][TPath]
227
151
  >
228
152
  : never