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

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 +1113 -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 +1417 -2105
  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 +604 -426
  25. package/build/umd/index.development.js +1640 -2224
  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 -204
  38. package/src/router.ts +1494 -1017
  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 -231
  57. package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
  58. package/build/cjs/packages/router-core/src/router.js +0 -833
  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 -514
  64. package/src/routeMatch.ts +0 -319
package/src/routeInfo.ts CHANGED
@@ -1,235 +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 TParentLoaderData,
67
- infer TRouteLoaderData,
68
- infer TLoaderData,
69
- infer TActionPayload,
70
- infer TActionResponse,
71
- infer TParentSearchSchema,
72
- infer TSearchSchema,
73
- infer TFullSearchSchema,
74
- infer TParentParams,
75
- infer TParams,
76
- infer TAllParams,
77
- any
78
- >
79
- ? string extends TRouteId
80
- ? never
81
- : RouteInfo<
82
- TId,
83
- TRouteId,
84
- TPath,
85
- TFullPath,
86
- TParentLoaderData,
87
- TRouteLoaderData,
88
- TLoaderData,
89
- TActionPayload,
90
- TActionResponse,
91
- TParentSearchSchema,
92
- TSearchSchema,
93
- TFullSearchSchema,
94
- TParentParams,
95
- TParams,
96
- TAllParams
97
- >
98
- : never
29
+ export interface RoutesInfo<TRouteTree extends AnyRoute = Route>
30
+ extends RoutesInfoInner<TRouteTree, ParseRoute<TRouteTree>> {}
99
31
 
100
32
  export interface RoutesInfoInner<
101
- TRouteConfig extends AnyRouteConfig,
102
- TRouteInfo extends RouteInfo<
103
- string,
104
- string,
105
- any,
106
- any,
107
- any,
108
- any,
109
- any,
110
- any,
111
- any,
112
- any,
113
- any,
114
- any,
115
- any,
116
- any,
117
- any
118
- > = RouteInfo,
119
- TRouteInfoById = {
120
- [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
121
37
  },
122
- TRouteInfoByFullPath = {
123
- [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
124
44
  ? never
125
- : string extends TInfo['fullPath']
45
+ : string extends TRoute['fullPath']
126
46
  ? never
127
- : TInfo['fullPath']]: TInfo
47
+ : `${TRoute['fullPath']}/` extends keyof TRoutesById
48
+ ? never
49
+ : TRoute['fullPath'] extends `${infer Trimmed}/`
50
+ ? Trimmed
51
+ : TRoute['fullPath']]: TRoute
128
52
  },
129
53
  > {
130
- routeConfig: TRouteConfig
131
- routeInfo: TRouteInfo
132
- routeInfoById: TRouteInfoById
133
- routeInfoByFullPath: TRouteInfoByFullPath
134
- routeIds: keyof TRouteInfoById
135
- 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']>>
136
83
  }
137
84
 
138
- export interface AnyRouteInfo
139
- extends RouteInfo<
140
- any,
141
- any,
142
- any,
143
- any,
144
- any,
145
- any,
146
- any,
147
- any,
148
- any,
149
- any,
150
- any,
151
- any,
152
- any,
153
- any,
154
- any
155
- > {}
85
+ export type ParseRoute<TRouteTree> = TRouteTree extends AnyRoute
86
+ ? TRouteTree | ParseRouteChildren<TRouteTree>
87
+ : never
156
88
 
157
- export interface RouteInfo<
158
- TId extends string = string,
159
- TRouteId extends string = string,
160
- TPath extends string = string,
161
- TFullPath extends string = string,
162
- TParentRouteLoaderData extends AnyLoaderData = {},
163
- TRouteLoaderData extends AnyLoaderData = {},
164
- TLoaderData extends AnyLoaderData = {},
165
- TActionPayload = unknown,
166
- TActionResponse = unknown,
167
- TParentSearchSchema extends {} = {},
168
- TSearchSchema extends AnySearchSchema = {},
169
- TFullSearchSchema extends AnySearchSchema = {},
170
- TParentParams extends AnyPathParams = {},
171
- TParams extends Record<ParsePathParams<TPath>, unknown> = Record<
172
- ParsePathParams<TPath>,
173
- string
174
- >,
175
- TAllParams extends AnyPathParams = {},
176
- > {
177
- id: TId
178
- routeId: TRouteId
179
- path: TPath
180
- fullPath: TFullPath
181
- parentRouteLoaderData: TParentRouteLoaderData
182
- routeLoaderData: TRouteLoaderData
183
- loaderData: TLoaderData
184
- actionPayload: TActionPayload
185
- actionResponse: TActionResponse
186
- searchSchema: TSearchSchema
187
- fullSearchSchema: TFullSearchSchema
188
- parentParams: TParentParams
189
- params: TParams
190
- allParams: TAllParams
191
- options: RouteOptions<
192
- TRouteId,
193
- TPath,
194
- TParentRouteLoaderData,
195
- TRouteLoaderData,
196
- TLoaderData,
197
- TActionPayload,
198
- TActionResponse,
199
- TParentSearchSchema,
200
- TSearchSchema,
201
- TFullSearchSchema,
202
- TParentParams,
203
- TParams,
204
- TAllParams
205
- >
206
- }
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
207
119
 
208
- export type RoutesById<TAllRouteInfo extends AnyAllRouteInfo> = {
209
- [K in keyof TAllRouteInfo['routeInfoById']]: Route<
210
- TAllRouteInfo,
211
- TAllRouteInfo['routeInfoById'][K]
212
- >
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]
213
126
  }
214
127
 
215
- export type RouteInfoById<
216
- TAllRouteInfo extends AnyAllRouteInfo,
128
+ export type RouteById<
129
+ TRoutesInfo extends AnyRoutesInfo,
217
130
  TId,
218
- > = TId extends keyof TAllRouteInfo['routeInfoById']
131
+ > = TId extends keyof TRoutesInfo['routesById']
219
132
  ? IsAny<
220
- TAllRouteInfo['routeInfoById'][TId]['id'],
221
- RouteInfo,
222
- TAllRouteInfo['routeInfoById'][TId]
133
+ TRoutesInfo['routesById'][TId]['id'],
134
+ Route,
135
+ TRoutesInfo['routesById'][TId]
223
136
  >
224
137
  : never
225
138
 
226
- export type RouteInfoByPath<
227
- 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,
228
145
  TPath,
229
- > = TPath extends keyof TAllRouteInfo['routeInfoByFullPath']
146
+ > = TPath extends keyof TRoutesInfo['routesByFullPath']
230
147
  ? IsAny<
231
- TAllRouteInfo['routeInfoByFullPath'][TPath]['id'],
232
- RouteInfo,
233
- TAllRouteInfo['routeInfoByFullPath'][TPath]
148
+ TRoutesInfo['routesByFullPath'][TPath]['id'],
149
+ Route,
150
+ TRoutesInfo['routesByFullPath'][TPath]
234
151
  >
235
152
  : never