@tanstack/router-core 0.0.1-beta.30 → 0.0.1-beta.31

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.30",
4
+ "version": "0.0.1-beta.31",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
package/src/link.ts CHANGED
@@ -5,7 +5,13 @@ import {
5
5
  RouteInfoByPath,
6
6
  } from './routeInfo'
7
7
  import { Location, LocationState } from './router'
8
- import { Expand, NoInfer, PickRequired, Updater } from './utils'
8
+ import {
9
+ Expand,
10
+ NoInfer,
11
+ PickRequired,
12
+ UnionToIntersection,
13
+ Updater,
14
+ } from './utils'
9
15
 
10
16
  export type LinkInfo =
11
17
  | {
@@ -140,21 +146,37 @@ type SearchParamOptions<
140
146
  TAllRouteInfo extends AnyAllRouteInfo,
141
147
  TFrom,
142
148
  TTo,
143
- TFromSchema = RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema'],
144
- TToSchema = RouteInfoByPath<TAllRouteInfo, TTo>['fullSearchSchema'],
145
- > = StartsWith<TFrom, TTo> extends true
146
- ? // If the next route search extend or cover the from route, params will be optional
147
- {
148
- search?: SearchReducer<TFromSchema, TToSchema>
149
- }
150
- : // Optional search params? Allow it
151
- keyof PickRequired<TToSchema> extends never
149
+ TFromSchema = Expand<
150
+ UnionToIntersection<
151
+ TAllRouteInfo['fullSearchSchema'] &
152
+ RouteInfoByPath<TAllRouteInfo, TFrom> extends never
153
+ ? {}
154
+ : RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema']
155
+ >
156
+ >,
157
+ // Find the schema for the new path, and make optional any keys
158
+ // that are already defined in the current schema
159
+ TToSchema = Partial<
160
+ RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema']
161
+ > &
162
+ Omit<
163
+ RouteInfoByPath<TAllRouteInfo, TTo>['fullSearchSchema'],
164
+ keyof PickRequired<
165
+ RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema']
166
+ >
167
+ >,
168
+ TFromFullSchema = Expand<
169
+ UnionToIntersection<TAllRouteInfo['fullSearchSchema'] & TFromSchema>
170
+ >,
171
+ TToFullSchema = Expand<
172
+ UnionToIntersection<TAllRouteInfo['fullSearchSchema'] & TToSchema>
173
+ >,
174
+ > = keyof PickRequired<TToSchema> extends never
152
175
  ? {
153
- search?: SearchReducer<TFromSchema, TToSchema>
176
+ search?: true | SearchReducer<TFromFullSchema, TToFullSchema>
154
177
  }
155
178
  : {
156
- // Must have required search params, enforce it
157
- search: SearchReducer<TFromSchema, TToSchema>
179
+ search: SearchReducer<TFromFullSchema, TToFullSchema>
158
180
  }
159
181
 
160
182
  type SearchReducer<TFrom, TTo> =
@@ -165,23 +187,33 @@ type PathParamOptions<
165
187
  TAllRouteInfo extends AnyAllRouteInfo,
166
188
  TFrom,
167
189
  TTo,
168
- TFromParams = RouteInfoByPath<TAllRouteInfo, TFrom>['allParams'],
169
- TToParams = RouteInfoByPath<TAllRouteInfo, TTo>['allParams'],
170
- > =
171
- // If the next routes params extend or cover the from route, params will be optional
172
- StartsWith<TFrom, TTo> extends true
173
- ? {
174
- params?: ParamsReducer<TFromParams, TToParams>
175
- }
176
- : // If the next route doesn't have params, warn if any have been passed
177
- AnyPathParams extends TToParams
178
- ? {
179
- params?: ParamsReducer<TFromParams, Record<string, never>>
180
- }
181
- : // If the next route has params, enforce them
182
- {
183
- params: ParamsReducer<TFromParams, TToParams>
184
- }
190
+ TFromSchema = Expand<
191
+ UnionToIntersection<
192
+ RouteInfoByPath<TAllRouteInfo, TFrom> extends never
193
+ ? {}
194
+ : RouteInfoByPath<TAllRouteInfo, TFrom>['allParams']
195
+ >
196
+ >,
197
+ // Find the schema for the new path, and make optional any keys
198
+ // that are already defined in the current schema
199
+ TToSchema = Partial<RouteInfoByPath<TAllRouteInfo, TFrom>['allParams']> &
200
+ Omit<
201
+ RouteInfoByPath<TAllRouteInfo, TTo>['allParams'],
202
+ keyof PickRequired<RouteInfoByPath<TAllRouteInfo, TFrom>['allParams']>
203
+ >,
204
+ TFromFullParams = Expand<
205
+ UnionToIntersection<TAllRouteInfo['allParams'] & TFromSchema>
206
+ >,
207
+ TToFullParams = Expand<
208
+ UnionToIntersection<TAllRouteInfo['allParams'] & TToSchema>
209
+ >,
210
+ > = keyof PickRequired<TToSchema> extends never
211
+ ? {
212
+ params?: ParamsReducer<TFromFullParams, TToFullParams>
213
+ }
214
+ : {
215
+ params: ParamsReducer<TFromFullParams, TToFullParams>
216
+ }
185
217
 
186
218
  type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo)
187
219
 
package/src/route.ts CHANGED
@@ -225,7 +225,7 @@ export function createRoute<
225
225
  from: fullPath,
226
226
  } as any,
227
227
  opts,
228
- )
228
+ ) as any
229
229
  },
230
230
  }
231
231
 
package/src/routeInfo.ts CHANGED
@@ -20,6 +20,7 @@ export interface AnyAllRouteInfo {
20
20
  routeIds: any
21
21
  routePaths: any
22
22
  fullSearchSchema: Record<string, any>
23
+ allParams: Record<string, any>
23
24
  }
24
25
 
25
26
  export interface DefaultAllRouteInfo {
@@ -30,6 +31,7 @@ export interface DefaultAllRouteInfo {
30
31
  routeIds: string
31
32
  routePaths: string
32
33
  fullSearchSchema: AnySearchSchema
34
+ allParams: AnyPathParams
33
35
  }
34
36
 
35
37
  export interface AllRouteInfo<TRouteConfig extends AnyRouteConfig = RouteConfig>
@@ -140,6 +142,7 @@ export interface RoutesInfoInner<
140
142
  routeIds: keyof TRouteInfoById
141
143
  routePaths: keyof TRouteInfoByFullPath
142
144
  fullSearchSchema: Partial<UnionToIntersection<TRouteInfo['fullSearchSchema']>>
145
+ allParams: Partial<UnionToIntersection<TRouteInfo['allParams']>>
143
146
  }
144
147
 
145
148
  export interface AnyRouteInfo
@@ -166,7 +169,7 @@ export interface RouteInfo<
166
169
  TId extends string = string,
167
170
  TRouteId extends string = string,
168
171
  TPath extends string = string,
169
- TFullPath extends string = string,
172
+ TFullPath extends string = '/',
170
173
  TParentRouteLoaderData extends AnyLoaderData = {},
171
174
  TRouteLoaderData extends AnyLoaderData = {},
172
175
  TParentLoaderData extends AnyLoaderData = {},
package/src/routeMatch.ts CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  RouteInfo,
8
8
  } from './routeInfo'
9
9
  import { Router } from './router'
10
- import { replaceEqualDeep } from './utils'
10
+ import { Expand, replaceEqualDeep } from './utils'
11
11
 
12
12
  export interface RouteMatch<
13
13
  TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,
@@ -19,7 +19,9 @@ export interface RouteMatch<
19
19
  parentMatch?: RouteMatch
20
20
  childMatches: RouteMatch[]
21
21
  routeSearch: TRouteInfo['searchSchema']
22
- search: TRouteInfo['fullSearchSchema']
22
+ search: Expand<
23
+ TAllRouteInfo['fullSearchSchema'] & TRouteInfo['fullSearchSchema']
24
+ >
23
25
  status: 'idle' | 'loading' | 'success' | 'error'
24
26
  updatedAt?: number
25
27
  error?: unknown
@@ -85,7 +87,7 @@ export function createRouteMatch<
85
87
  ...opts,
86
88
  router,
87
89
  routeSearch: {},
88
- search: {},
90
+ search: {} as any,
89
91
  childMatches: [],
90
92
  status: 'idle',
91
93
  routeLoaderData: {} as TRouteInfo['routeLoaderData'],
@@ -109,7 +111,7 @@ export function createRouteMatch<
109
111
  validate: () => {
110
112
  // Validate the search params and stabilize them
111
113
  const parentSearch =
112
- routeMatch.parentMatch?.search ?? router.location.search
114
+ routeMatch.parentMatch?.search ?? router.__location.search
113
115
 
114
116
  try {
115
117
  const prevSearch = routeMatch.routeSearch
package/src/router.ts CHANGED
@@ -221,7 +221,7 @@ export type ListenerFn = () => void
221
221
 
222
222
  export interface BuildNextOptions {
223
223
  to?: string | number | null
224
- params?: true | Updater<Record<string, any>>
224
+ params?: true | Updater<unknown>
225
225
  search?: true | Updater<unknown>
226
226
  hash?: true | Updater<string>
227
227
  state?: LocationState
@@ -263,7 +263,7 @@ export interface DehydratedRouterState
263
263
  }
264
264
 
265
265
  export interface DehydratedRouter<TRouterContext = unknown> {
266
- location: Router['location']
266
+ location: Router['__location']
267
267
  state: DehydratedRouterState
268
268
  context: TRouterContext
269
269
  }
@@ -302,7 +302,7 @@ export interface Router<
302
302
  basepath: string
303
303
  // Internal:
304
304
  listeners: Listener[]
305
- location: Location<TAllRouteInfo['fullSearchSchema']>
305
+ __location: Location<TAllRouteInfo['fullSearchSchema']>
306
306
  navigateTimeout?: Timeout
307
307
  nextAction?: 'push' | 'replace'
308
308
  state: RouterState<TAllRouteInfo['fullSearchSchema']>
@@ -442,7 +442,7 @@ export function createRouter<
442
442
  basepath: '',
443
443
  routeTree: undefined!,
444
444
  routesById: {} as any,
445
- location: undefined!,
445
+ __location: undefined!,
446
446
  //
447
447
  resolveNavigation: () => {},
448
448
  matchCache: {},
@@ -489,7 +489,7 @@ export function createRouter<
489
489
 
490
490
  dehydrate: () => {
491
491
  return {
492
- location: router.location,
492
+ location: router.__location,
493
493
  state: {
494
494
  ...pick(router.state, [
495
495
  'status',
@@ -514,13 +514,13 @@ export function createRouter<
514
514
 
515
515
  hydrate: (dehydratedState) => {
516
516
  // Update the location
517
- router.location = dehydratedState.location
517
+ router.__location = dehydratedState.location
518
518
 
519
519
  // Update the context
520
520
  router.options.context = dehydratedState.context
521
521
 
522
522
  // Match the routes
523
- const matches = router.matchRoutes(router.location.pathname, {
523
+ const matches = router.matchRoutes(router.__location.pathname, {
524
524
  strictParseParams: true,
525
525
  })
526
526
 
@@ -551,7 +551,7 @@ export function createRouter<
551
551
 
552
552
  // If the current location isn't updated, trigger a navigation
553
553
  // to the current location. Otherwise, load the current location.
554
- if (next.href !== router.location.href) {
554
+ if (next.href !== router.__location.href) {
555
555
  router.__.commitLocation(next, true)
556
556
  }
557
557
 
@@ -560,7 +560,7 @@ export function createRouter<
560
560
  }
561
561
 
562
562
  const unsub = router.history.listen((event) => {
563
- router.load(router.__.parseLocation(event.location, router.location))
563
+ router.load(router.__.parseLocation(event.location, router.__location))
564
564
  })
565
565
 
566
566
  // addEventListener does not exist in React Native, but window does
@@ -587,12 +587,12 @@ export function createRouter<
587
587
 
588
588
  update: (opts) => {
589
589
  const newHistory = opts?.history !== router.history
590
- if (!router.location || newHistory) {
590
+ if (!router.__location || newHistory) {
591
591
  if (opts?.history) {
592
592
  router.history = opts.history
593
593
  }
594
- router.location = router.__.parseLocation(router.history.location)
595
- router.state.location = router.location
594
+ router.__location = router.__.parseLocation(router.history.location)
595
+ router.state.location = router.__location
596
596
  }
597
597
 
598
598
  Object.assign(router.options, opts)
@@ -624,14 +624,14 @@ export function createRouter<
624
624
 
625
625
  if (next) {
626
626
  // Ingest the new location
627
- router.location = next
627
+ router.__location = next
628
628
  }
629
629
 
630
630
  // Cancel any pending matches
631
631
  router.cancelMatches()
632
632
 
633
633
  // Match the routes
634
- const matches = router.matchRoutes(router.location.pathname, {
634
+ const matches = router.matchRoutes(router.__location.pathname, {
635
635
  strictParseParams: true,
636
636
  })
637
637
 
@@ -640,7 +640,7 @@ export function createRouter<
640
640
  ...router.state,
641
641
  pending: {
642
642
  matches: matches,
643
- location: router.location,
643
+ location: router.__location,
644
644
  },
645
645
  status: 'loading',
646
646
  }
@@ -648,7 +648,7 @@ export function createRouter<
648
648
  router.state = {
649
649
  ...router.state,
650
650
  matches: matches,
651
- location: router.location,
651
+ location: router.__location,
652
652
  status: 'loading',
653
653
  }
654
654
  }
@@ -752,7 +752,7 @@ export function createRouter<
752
752
 
753
753
  router.state = {
754
754
  ...router.state,
755
- location: router.location,
755
+ location: router.__location,
756
756
  matches,
757
757
  pending: undefined,
758
758
  status: 'idle',
@@ -783,7 +783,7 @@ export function createRouter<
783
783
  })
784
784
  },
785
785
 
786
- loadRoute: async (navigateOpts = router.location) => {
786
+ loadRoute: async (navigateOpts = router.__location) => {
787
787
  const next = router.buildNext(navigateOpts)
788
788
  const matches = router.matchRoutes(next.pathname, {
789
789
  strictParseParams: true,
@@ -792,7 +792,7 @@ export function createRouter<
792
792
  return matches
793
793
  },
794
794
 
795
- preloadRoute: async (navigateOpts = router.location, loaderOpts) => {
795
+ preloadRoute: async (navigateOpts = router.__location, loaderOpts) => {
796
796
  const next = router.buildNext(navigateOpts)
797
797
  const matches = router.matchRoutes(next.pathname, {
798
798
  strictParseParams: true,
@@ -1282,11 +1282,9 @@ export function createRouter<
1282
1282
  },
1283
1283
 
1284
1284
  buildLocation: (dest: BuildNextOptions = {}): Location => {
1285
- // const resolvedFrom: Location = {
1286
- // ...router.location,
1287
1285
  const fromPathname = dest.fromCurrent
1288
- ? router.location.pathname
1289
- : dest.from ?? router.location.pathname
1286
+ ? router.__location.pathname
1287
+ : dest.from ?? router.__location.pathname
1290
1288
 
1291
1289
  let pathname = resolvePath(
1292
1290
  router.basepath ?? '/',
@@ -1294,7 +1292,7 @@ export function createRouter<
1294
1292
  `${dest.to ?? '.'}`,
1295
1293
  )
1296
1294
 
1297
- const fromMatches = router.matchRoutes(router.location.pathname, {
1295
+ const fromMatches = router.matchRoutes(router.__location.pathname, {
1298
1296
  strictParseParams: true,
1299
1297
  })
1300
1298
 
@@ -1322,9 +1320,9 @@ export function createRouter<
1322
1320
  const preFilteredSearch = dest.__preSearchFilters?.length
1323
1321
  ? dest.__preSearchFilters.reduce(
1324
1322
  (prev, next) => next(prev),
1325
- router.location.search,
1323
+ router.__location.search,
1326
1324
  )
1327
- : router.location.search
1325
+ : router.__location.search
1328
1326
 
1329
1327
  // Then the link/navigate function
1330
1328
  const destSearch =
@@ -1345,22 +1343,22 @@ export function createRouter<
1345
1343
  : destSearch
1346
1344
 
1347
1345
  const search = replaceEqualDeep(
1348
- router.location.search,
1346
+ router.__location.search,
1349
1347
  postFilteredSearch,
1350
1348
  )
1351
1349
 
1352
1350
  const searchStr = router.options.stringifySearch(search)
1353
1351
  let hash =
1354
1352
  dest.hash === true
1355
- ? router.location.hash
1356
- : functionalUpdate(dest.hash!, router.location.hash)
1353
+ ? router.__location.hash
1354
+ : functionalUpdate(dest.hash!, router.__location.hash)
1357
1355
  hash = hash ? `#${hash}` : ''
1358
1356
 
1359
1357
  return {
1360
1358
  pathname,
1361
1359
  search,
1362
1360
  searchStr,
1363
- state: router.location.state,
1361
+ state: router.__location.state,
1364
1362
  hash,
1365
1363
  href: `${pathname}${searchStr}${hash}`,
1366
1364
  key: dest.key,