@tanstack/router-core 0.0.1-beta.25 → 0.0.1-beta.29

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 (52) hide show
  1. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -2
  2. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
  3. package/build/cjs/{packages/router-core/src/index.js → index.js} +22 -6
  4. package/build/cjs/{packages/router-core/src/index.js.map → index.js.map} +1 -1
  5. package/build/cjs/{packages/router-core/src/path.js → path.js} +6 -30
  6. package/build/cjs/path.js.map +1 -0
  7. package/build/cjs/{packages/router-core/src/qss.js → qss.js} +8 -13
  8. package/build/cjs/qss.js.map +1 -0
  9. package/build/cjs/{packages/router-core/src/route.js → route.js} +7 -16
  10. package/build/cjs/route.js.map +1 -0
  11. package/build/cjs/{packages/router-core/src/routeConfig.js → routeConfig.js} +13 -12
  12. package/build/cjs/routeConfig.js.map +1 -0
  13. package/build/cjs/{packages/router-core/src/routeMatch.js → routeMatch.js} +15 -35
  14. package/build/cjs/routeMatch.js.map +1 -0
  15. package/build/cjs/{packages/router-core/src/router.js → router.js} +103 -159
  16. package/build/cjs/router.js.map +1 -0
  17. package/build/cjs/{packages/router-core/src/searchParams.js → searchParams.js} +7 -10
  18. package/build/cjs/searchParams.js.map +1 -0
  19. package/build/cjs/{packages/router-core/src/utils.js → utils.js} +10 -24
  20. package/build/cjs/utils.js.map +1 -0
  21. package/build/esm/index.js +156 -1116
  22. package/build/esm/index.js.map +1 -1
  23. package/build/stats-html.html +59 -49
  24. package/build/stats-react.json +160 -154
  25. package/build/types/index.d.ts +53 -40
  26. package/build/umd/index.development.js +151 -294
  27. package/build/umd/index.development.js.map +1 -1
  28. package/build/umd/index.production.js +1 -1
  29. package/build/umd/index.production.js.map +1 -1
  30. package/package.json +2 -2
  31. package/src/link.ts +2 -2
  32. package/src/path.ts +2 -2
  33. package/src/route.ts +8 -5
  34. package/src/routeConfig.ts +77 -63
  35. package/src/routeInfo.ts +11 -6
  36. package/src/routeMatch.ts +1 -1
  37. package/src/router.ts +114 -51
  38. package/src/utils.ts +2 -2
  39. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
  40. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
  41. package/build/cjs/node_modules/history/index.js +0 -815
  42. package/build/cjs/node_modules/history/index.js.map +0 -1
  43. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
  44. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
  45. package/build/cjs/packages/router-core/src/path.js.map +0 -1
  46. package/build/cjs/packages/router-core/src/qss.js.map +0 -1
  47. package/build/cjs/packages/router-core/src/route.js.map +0 -1
  48. package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
  49. package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
  50. package/build/cjs/packages/router-core/src/router.js.map +0 -1
  51. package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
  52. package/build/cjs/packages/router-core/src/utils.js.map +0 -1
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.25",
4
+ "version": "0.0.1-beta.29",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
@@ -23,7 +23,7 @@
23
23
  "url": "https://github.com/sponsors/tannerlinsley"
24
24
  },
25
25
  "module": "build/esm/index.js",
26
- "main": "build/cjs/packages/router-core/src/index.js",
26
+ "main": "build/cjs/index.js",
27
27
  "browser": "build/umd/index.production.js",
28
28
  "types": "build/types/index.d.ts",
29
29
  "engines": {
package/src/link.ts CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  RouteInfoByPath,
6
6
  } from './routeInfo'
7
7
  import { Location, LocationState } from './router'
8
- import { Expand, NoInfer, PickAsRequired, PickRequired, Updater } from './utils'
8
+ import { Expand, NoInfer, PickRequired, Updater } from './utils'
9
9
 
10
10
  export type LinkInfo =
11
11
  | {
@@ -58,7 +58,7 @@ export type Split<S, TIncludeTrailingSlash = true> = S extends unknown
58
58
  : never
59
59
 
60
60
  export type ParsePathParams<T extends string> = Split<T>[number] extends infer U
61
- ? U extends `:${infer V}`
61
+ ? U extends `$${infer V}`
62
62
  ? V
63
63
  : never
64
64
  : never
package/src/path.ts CHANGED
@@ -97,7 +97,7 @@ export function parsePathname(pathname?: string): Segment[] {
97
97
  }
98
98
  }
99
99
 
100
- if (part.charAt(0) === ':') {
100
+ if (part.charAt(0) === '$') {
101
101
  return {
102
102
  type: 'param',
103
103
  value: part,
@@ -215,7 +215,7 @@ export function matchByPath(
215
215
  if (baseSegment?.value === '/') {
216
216
  return false
217
217
  }
218
- if (!baseSegment.value.startsWith(':')) {
218
+ if (baseSegment.value.charAt(0) !== '$') {
219
219
  params[routeSegment.value.substring(1)] = baseSegment.value
220
220
  }
221
221
  }
package/src/route.ts CHANGED
@@ -23,11 +23,12 @@ import {
23
23
  } from './router'
24
24
  import { NoInfer } from './utils'
25
25
 
26
- export interface AnyRoute extends Route<any, any> {}
26
+ export interface AnyRoute extends Route<any, any, any> {}
27
27
 
28
28
  export interface Route<
29
29
  TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,
30
30
  TRouteInfo extends AnyRouteInfo = RouteInfo,
31
+ TRouterContext = unknown,
31
32
  > {
32
33
  routeInfo: TRouteInfo
33
34
  routeId: TRouteInfo['id']
@@ -37,7 +38,7 @@ export interface Route<
37
38
  parentRoute?: AnyRoute
38
39
  childRoutes?: AnyRoute[]
39
40
  options: RouteOptions
40
- router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo>
41
+ router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo, TRouterContext>
41
42
  buildLink: <TTo extends string = '.'>(
42
43
  options: Omit<
43
44
  LinkOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>,
@@ -87,12 +88,13 @@ export interface Route<
87
88
  export function createRoute<
88
89
  TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,
89
90
  TRouteInfo extends AnyRouteInfo = RouteInfo,
91
+ TRouterContext = unknown,
90
92
  >(
91
93
  routeConfig: RouteConfig,
92
94
  options: TRouteInfo['options'],
93
95
  parent: undefined | Route<TAllRouteInfo, any>,
94
- router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo>,
95
- ): Route<TAllRouteInfo, TRouteInfo> {
96
+ router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo, TRouterContext>,
97
+ ): Route<TAllRouteInfo, TRouteInfo, TRouterContext> {
96
98
  const { id, routeId, path: routePath, fullPath } = routeConfig
97
99
 
98
100
  const action =
@@ -138,6 +140,7 @@ export function createRoute<
138
140
  actionState.status = 'success'
139
141
  return res
140
142
  } catch (err) {
143
+ console.log('tanner')
141
144
  console.error(err)
142
145
  actionState.error = err
143
146
  actionState.status = 'error'
@@ -188,7 +191,7 @@ export function createRoute<
188
191
  return router.state.loaders[id]!
189
192
  })()
190
193
 
191
- let route: Route<TAllRouteInfo, TRouteInfo> = {
194
+ let route: Route<TAllRouteInfo, TRouteInfo, TRouterContext> = {
192
195
  routeInfo: undefined!,
193
196
  routeId: id,
194
197
  routeRouteId: routeId,
@@ -1,17 +1,11 @@
1
+ import invariant from 'tiny-invariant'
1
2
  import { GetFrameworkGeneric } from './frameworks'
2
3
  import { ParsePathParams } from './link'
3
4
  import { joinPaths, trimPath, trimPathRight } from './path'
4
5
  import { RouteInfo } from './routeInfo'
5
6
  import { RouteMatch } from './routeMatch'
6
- import { RouterContext } from './router'
7
- import {
8
- DeepAwaited,
9
- Expand,
10
- IsAny,
11
- NoInfer,
12
- PickUnsafe,
13
- Values,
14
- } from './utils'
7
+ import { RegisteredRouter, Router } from './router'
8
+ import { Expand, IsAny, NoInfer, PickUnsafe } from './utils'
15
9
 
16
10
  export const rootRouteId = '__root__' as const
17
11
  export type RootRouteId = typeof rootRouteId
@@ -56,7 +50,7 @@ export type LoaderFn<
56
50
  TAllParams extends AnyPathParams = {},
57
51
  > = (
58
52
  loaderContext: LoaderContext<TFullSearchSchema, TAllParams>,
59
- ) => Promise<TRouteLoaderData>
53
+ ) => TRouteLoaderData | Promise<TRouteLoaderData>
60
54
 
61
55
  export interface LoaderContext<
62
56
  TFullSearchSchema extends AnySearchSchema = {},
@@ -81,6 +75,7 @@ export type RouteOptions<
81
75
  TPath extends string = string,
82
76
  TParentRouteLoaderData extends AnyLoaderData = {},
83
77
  TRouteLoaderData extends AnyLoaderData = {},
78
+ TParentLoaderData extends AnyLoaderData = {},
84
79
  TLoaderData extends AnyLoaderData = {},
85
80
  TActionPayload = unknown,
86
81
  TActionResponse = unknown,
@@ -130,7 +125,10 @@ export type RouteOptions<
130
125
  action?: ActionFn<TActionPayload, TActionResponse>
131
126
  // This async function is called before a route is loaded. If an error is thrown, the navigation is cancelled.
132
127
  // If you want to redirect instead, throw a call to the `router.navigate()` function
133
- beforeLoad?: (opts: { context: RouterContext }) => Promise<void> | void
128
+ beforeLoad?: (opts: {
129
+ router: Router<any, any, unknown>
130
+ match: RouteMatch
131
+ }) => Promise<void> | void
134
132
  // This function is called
135
133
  // when moving from an inactive state to an active one. Likewise, when moving from
136
134
  // an active to an inactive state, the return function (if provided) is called.
@@ -176,6 +174,7 @@ export interface RouteConfig<
176
174
  TFullPath extends string = string,
177
175
  TParentRouteLoaderData extends AnyLoaderData = AnyLoaderData,
178
176
  TRouteLoaderData extends AnyLoaderData = AnyLoaderData,
177
+ TParentLoaderData extends AnyLoaderData = {},
179
178
  TLoaderData extends AnyLoaderData = AnyLoaderData,
180
179
  TActionPayload = unknown,
181
180
  TActionResponse = unknown,
@@ -183,10 +182,7 @@ export interface RouteConfig<
183
182
  TSearchSchema extends AnySearchSchema = {},
184
183
  TFullSearchSchema extends AnySearchSchema = {},
185
184
  TParentParams extends AnyPathParams = {},
186
- TParams extends Record<ParsePathParams<TPath>, unknown> = Record<
187
- ParsePathParams<TPath>,
188
- string
189
- >,
185
+ TParams extends AnyPathParams = {},
190
186
  TAllParams extends AnyPathParams = {},
191
187
  TKnownChildren = unknown,
192
188
  > {
@@ -199,6 +195,7 @@ export interface RouteConfig<
199
195
  TPath,
200
196
  TParentRouteLoaderData,
201
197
  TRouteLoaderData,
198
+ TParentLoaderData,
202
199
  TLoaderData,
203
200
  TActionPayload,
204
201
  TActionResponse,
@@ -224,6 +221,7 @@ export interface RouteConfig<
224
221
  TFullPath,
225
222
  TParentRouteLoaderData,
226
223
  TRouteLoaderData,
224
+ TParentLoaderData,
227
225
  TLoaderData,
228
226
  TActionPayload,
229
227
  TActionResponse,
@@ -236,52 +234,67 @@ export interface RouteConfig<
236
234
  TNewChildren
237
235
  >
238
236
  >
239
- createChildren: IsAny<
237
+ createRoute: CreateRouteConfigFn<
238
+ false,
240
239
  TId,
241
- any,
242
- <TNewChildren extends any>(
243
- cb: (
244
- createChildRoute: CreateRouteConfigFn<
245
- false,
246
- TId,
247
- TFullPath,
248
- TRouteLoaderData,
249
- TLoaderData,
250
- TFullSearchSchema,
251
- TAllParams
252
- >,
253
- ) => TNewChildren extends AnyRouteConfig[]
254
- ? TNewChildren
255
- : { error: 'Invalid route detected'; route: TNewChildren },
256
- ) => RouteConfig<
257
- TId,
240
+ TFullPath,
241
+ TRouteLoaderData,
242
+ TLoaderData,
243
+ TFullSearchSchema,
244
+ TAllParams
245
+ >
246
+ generate: GenerateFn<
247
+ TRouteId,
248
+ TPath,
249
+ TParentRouteLoaderData,
250
+ TParentLoaderData,
251
+ TParentSearchSchema,
252
+ TParentParams
253
+ >
254
+ }
255
+
256
+ type GenerateFn<
257
+ TRouteId extends string = string,
258
+ TPath extends string = string,
259
+ TParentRouteLoaderData extends AnyLoaderData = AnyLoaderData,
260
+ TParentLoaderData extends AnyLoaderData = {},
261
+ TParentSearchSchema extends {} = {},
262
+ TParentParams extends AnyPathParams = {},
263
+ > = <
264
+ TRouteLoaderData extends AnyLoaderData = AnyLoaderData,
265
+ TActionPayload = unknown,
266
+ TActionResponse = unknown,
267
+ TSearchSchema extends AnySearchSchema = {},
268
+ TParams extends Record<ParsePathParams<TPath>, unknown> = Record<
269
+ ParsePathParams<TPath>,
270
+ string
271
+ >,
272
+ TAllParams extends AnyPathParams extends TParams
273
+ ? Record<ParsePathParams<TPath>, string>
274
+ : NoInfer<TParams> = AnyPathParams extends TParams
275
+ ? Record<ParsePathParams<TPath>, string>
276
+ : NoInfer<TParams>,
277
+ >(
278
+ options: Omit<
279
+ RouteOptions<
258
280
  TRouteId,
259
281
  TPath,
260
- TFullPath,
261
282
  TParentRouteLoaderData,
262
283
  TRouteLoaderData,
263
- TLoaderData,
284
+ TParentLoaderData,
285
+ Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>,
264
286
  TActionPayload,
265
287
  TActionResponse,
266
288
  TParentSearchSchema,
267
289
  TSearchSchema,
268
- TFullSearchSchema,
290
+ Expand<TParentSearchSchema & TSearchSchema>,
269
291
  TParentParams,
270
292
  TParams,
271
- TAllParams,
272
- TNewChildren
273
- >
274
- >
275
- createRoute: CreateRouteConfigFn<
276
- false,
277
- TId,
278
- TFullPath,
279
- TRouteLoaderData,
280
- TLoaderData,
281
- TFullSearchSchema,
282
- TAllParams
283
- >
284
- }
293
+ Expand<TParentParams & TAllParams>
294
+ >,
295
+ 'path'
296
+ >,
297
+ ) => void
285
298
 
286
299
  type CreateRouteConfigFn<
287
300
  TIsRoot extends boolean = false,
@@ -321,7 +334,8 @@ type CreateRouteConfigFn<
321
334
  TPath,
322
335
  TParentRouteLoaderData,
323
336
  TRouteLoaderData,
324
- Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
337
+ TParentLoaderData,
338
+ Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>,
325
339
  TActionPayload,
326
340
  TActionResponse,
327
341
  TParentSearchSchema,
@@ -338,7 +352,8 @@ type CreateRouteConfigFn<
338
352
  TPath,
339
353
  TParentRouteLoaderData,
340
354
  TRouteLoaderData,
341
- Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
355
+ TParentLoaderData,
356
+ Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>,
342
357
  TActionPayload,
343
358
  TActionResponse,
344
359
  TParentSearchSchema,
@@ -359,7 +374,8 @@ type CreateRouteConfigFn<
359
374
  string extends TPath ? '' : RoutePath<RoutePrefix<TParentPath, TPath>>,
360
375
  TParentRouteLoaderData,
361
376
  TRouteLoaderData,
362
- Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
377
+ TParentLoaderData,
378
+ Expand<TParentLoaderData & NoInfer<TRouteLoaderData>>,
363
379
  TActionPayload,
364
380
  TActionResponse,
365
381
  TParentSearchSchema,
@@ -403,6 +419,7 @@ export interface AnyRouteConfig
403
419
  any,
404
420
  any,
405
421
  any,
422
+ any,
406
423
  any
407
424
  > {}
408
425
 
@@ -423,6 +440,7 @@ export interface AnyRouteConfigWithChildren<TChildren>
423
440
  any,
424
441
  any,
425
442
  any,
443
+ any,
426
444
  TChildren
427
445
  > {}
428
446
 
@@ -486,19 +504,15 @@ export const createRouteConfig: CreateRouteConfigFn<true> = (
486
504
  fullPath: fullPath as any,
487
505
  options: options as any,
488
506
  children,
489
- createChildren: (cb: any) =>
490
- createRouteConfig(
491
- options,
492
- cb((childOptions: any) =>
493
- createRouteConfig(childOptions, undefined, false, id, fullPath),
494
- ),
495
- false,
496
- parentId,
497
- parentPath,
498
- ),
499
507
  addChildren: (children: any) =>
500
508
  createRouteConfig(options, children, false, parentId, parentPath),
501
509
  createRoute: (childOptions: any) =>
502
510
  createRouteConfig(childOptions, undefined, false, id, fullPath) as any,
511
+ generate: () => {
512
+ invariant(
513
+ false,
514
+ `routeConfig.generate() is used by TanStack Router's file-based routing code generation and should not actually be called during runtime. `,
515
+ )
516
+ },
503
517
  }
504
518
  }
package/src/routeInfo.ts CHANGED
@@ -60,13 +60,15 @@ type ParseRouteChild<TRouteConfig, TId> = TRouteConfig & {
60
60
  ? ParseRouteConfig<TRouteConfig>
61
61
  : never
62
62
 
63
+ // Generics!
63
64
  export type RouteConfigRoute<TRouteConfig> = TRouteConfig extends RouteConfig<
64
65
  infer TId,
65
66
  infer TRouteId,
66
67
  infer TPath,
67
68
  infer TFullPath,
68
- infer TParentLoaderData,
69
+ infer TParentRouteLoaderData,
69
70
  infer TRouteLoaderData,
71
+ infer TParentLoaderData,
70
72
  infer TLoaderData,
71
73
  infer TActionPayload,
72
74
  infer TActionResponse,
@@ -85,8 +87,9 @@ export type RouteConfigRoute<TRouteConfig> = TRouteConfig extends RouteConfig<
85
87
  TRouteId,
86
88
  TPath,
87
89
  TFullPath,
88
- TParentLoaderData,
90
+ TParentRouteLoaderData,
89
91
  TRouteLoaderData,
92
+ TParentLoaderData,
90
93
  TLoaderData,
91
94
  TActionPayload,
92
95
  TActionResponse,
@@ -116,6 +119,7 @@ export interface RoutesInfoInner<
116
119
  any,
117
120
  any,
118
121
  any,
122
+ any,
119
123
  any
120
124
  > = RouteInfo,
121
125
  TRouteInfoById = { '/': TRouteInfo } & {
@@ -154,6 +158,7 @@ export interface AnyRouteInfo
154
158
  any,
155
159
  any,
156
160
  any,
161
+ any,
157
162
  any
158
163
  > {}
159
164
 
@@ -164,6 +169,7 @@ export interface RouteInfo<
164
169
  TFullPath extends string = string,
165
170
  TParentRouteLoaderData extends AnyLoaderData = {},
166
171
  TRouteLoaderData extends AnyLoaderData = {},
172
+ TParentLoaderData extends AnyLoaderData = {},
167
173
  TLoaderData extends AnyLoaderData = {},
168
174
  TActionPayload = unknown,
169
175
  TActionResponse = unknown,
@@ -171,10 +177,7 @@ export interface RouteInfo<
171
177
  TSearchSchema extends AnySearchSchema = {},
172
178
  TFullSearchSchema extends AnySearchSchema = {},
173
179
  TParentParams extends AnyPathParams = {},
174
- TParams extends Record<ParsePathParams<TPath>, unknown> = Record<
175
- ParsePathParams<TPath>,
176
- string
177
- >,
180
+ TParams extends AnyPathParams = {},
178
181
  TAllParams extends AnyPathParams = {},
179
182
  > {
180
183
  id: TId
@@ -183,6 +186,7 @@ export interface RouteInfo<
183
186
  fullPath: TFullPath
184
187
  parentRouteLoaderData: TParentRouteLoaderData
185
188
  routeLoaderData: TRouteLoaderData
189
+ parentLoaderData: TParentLoaderData
186
190
  loaderData: TLoaderData
187
191
  actionPayload: TActionPayload
188
192
  actionResponse: TActionResponse
@@ -196,6 +200,7 @@ export interface RouteInfo<
196
200
  TPath,
197
201
  TParentRouteLoaderData,
198
202
  TRouteLoaderData,
203
+ TParentLoaderData,
199
204
  TLoaderData,
200
205
  TActionPayload,
201
206
  TActionResponse,
package/src/routeMatch.ts CHANGED
@@ -71,7 +71,7 @@ export function createRouteMatch<
71
71
  TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,
72
72
  TRouteInfo extends AnyRouteInfo = RouteInfo,
73
73
  >(
74
- router: Router<any, any>,
74
+ router: Router<any, any, any>,
75
75
  route: Route<TAllRouteInfo, TRouteInfo>,
76
76
  opts: {
77
77
  parentMatch?: RouteMatch<any, any>