@tanstack/router-core 0.0.1-beta.9 → 1.97.24

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 (140) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/dist/cjs/Matches.cjs +13 -0
  4. package/dist/cjs/Matches.cjs.map +1 -0
  5. package/dist/cjs/Matches.d.cts +28 -0
  6. package/dist/cjs/RouterProvider.d.cts +18 -0
  7. package/dist/cjs/defer.cjs +25 -0
  8. package/dist/cjs/defer.cjs.map +1 -0
  9. package/dist/cjs/defer.d.cts +20 -0
  10. package/dist/cjs/index.cjs +50 -0
  11. package/dist/cjs/index.cjs.map +1 -0
  12. package/dist/cjs/index.d.cts +25 -0
  13. package/dist/cjs/link.cjs +5 -0
  14. package/dist/cjs/link.cjs.map +1 -0
  15. package/dist/cjs/link.d.cts +51 -0
  16. package/dist/cjs/location.d.cts +12 -0
  17. package/dist/cjs/manifest.d.cts +24 -0
  18. package/dist/cjs/path.cjs +289 -0
  19. package/dist/cjs/path.cjs.map +1 -0
  20. package/dist/cjs/path.d.cts +34 -0
  21. package/dist/cjs/qss.cjs +51 -0
  22. package/dist/cjs/qss.cjs.map +1 -0
  23. package/dist/cjs/qss.d.cts +27 -0
  24. package/dist/cjs/root.cjs +5 -0
  25. package/dist/cjs/root.cjs.map +1 -0
  26. package/dist/cjs/root.d.cts +2 -0
  27. package/dist/cjs/route.d.cts +148 -0
  28. package/dist/cjs/router.cjs +19 -0
  29. package/dist/cjs/router.cjs.map +1 -0
  30. package/dist/cjs/router.d.cts +31 -0
  31. package/dist/cjs/searchMiddleware.cjs +42 -0
  32. package/dist/cjs/searchMiddleware.cjs.map +1 -0
  33. package/dist/cjs/searchMiddleware.d.cts +5 -0
  34. package/dist/cjs/searchParams.cjs +61 -0
  35. package/dist/cjs/searchParams.cjs.map +1 -0
  36. package/dist/cjs/searchParams.d.cts +7 -0
  37. package/dist/cjs/serializer.d.cts +15 -0
  38. package/dist/cjs/structuralSharing.d.cts +4 -0
  39. package/dist/cjs/utils.cjs +155 -0
  40. package/dist/cjs/utils.cjs.map +1 -0
  41. package/dist/cjs/utils.d.cts +81 -0
  42. package/dist/cjs/validators.d.cts +51 -0
  43. package/dist/esm/Matches.d.ts +28 -0
  44. package/dist/esm/Matches.js +13 -0
  45. package/dist/esm/Matches.js.map +1 -0
  46. package/dist/esm/RouterProvider.d.ts +18 -0
  47. package/dist/esm/defer.d.ts +20 -0
  48. package/dist/esm/defer.js +25 -0
  49. package/dist/esm/defer.js.map +1 -0
  50. package/dist/esm/index.d.ts +25 -0
  51. package/dist/esm/index.js +50 -0
  52. package/dist/esm/index.js.map +1 -0
  53. package/dist/esm/link.d.ts +51 -0
  54. package/dist/esm/link.js +5 -0
  55. package/dist/esm/link.js.map +1 -0
  56. package/dist/esm/location.d.ts +12 -0
  57. package/dist/esm/manifest.d.ts +24 -0
  58. package/dist/esm/path.d.ts +34 -0
  59. package/dist/esm/path.js +289 -0
  60. package/dist/esm/path.js.map +1 -0
  61. package/dist/esm/qss.d.ts +27 -0
  62. package/dist/esm/qss.js +51 -0
  63. package/dist/esm/qss.js.map +1 -0
  64. package/dist/esm/root.d.ts +2 -0
  65. package/dist/esm/root.js +5 -0
  66. package/dist/esm/root.js.map +1 -0
  67. package/dist/esm/route.d.ts +148 -0
  68. package/dist/esm/router.d.ts +31 -0
  69. package/dist/esm/router.js +19 -0
  70. package/dist/esm/router.js.map +1 -0
  71. package/dist/esm/searchMiddleware.d.ts +5 -0
  72. package/dist/esm/searchMiddleware.js +42 -0
  73. package/dist/esm/searchMiddleware.js.map +1 -0
  74. package/dist/esm/searchParams.d.ts +7 -0
  75. package/dist/esm/searchParams.js +61 -0
  76. package/dist/esm/searchParams.js.map +1 -0
  77. package/dist/esm/serializer.d.ts +15 -0
  78. package/dist/esm/structuralSharing.d.ts +4 -0
  79. package/dist/esm/utils.d.ts +81 -0
  80. package/dist/esm/utils.js +155 -0
  81. package/dist/esm/utils.js.map +1 -0
  82. package/dist/esm/validators.d.ts +51 -0
  83. package/package.json +35 -32
  84. package/src/Matches.ts +94 -0
  85. package/src/RouterProvider.ts +20 -0
  86. package/src/defer.ts +52 -0
  87. package/src/index.ts +206 -19
  88. package/src/link.ts +122 -300
  89. package/src/location.ts +13 -0
  90. package/src/manifest.ts +32 -0
  91. package/src/path.ts +238 -47
  92. package/src/qss.ts +56 -19
  93. package/src/root.ts +2 -0
  94. package/src/route.ts +296 -223
  95. package/src/router.ts +34 -1281
  96. package/src/searchMiddleware.ts +54 -0
  97. package/src/searchParams.ts +43 -20
  98. package/src/serializer.ts +24 -0
  99. package/src/structuralSharing.ts +7 -0
  100. package/src/utils.ts +314 -75
  101. package/src/validators.ts +121 -0
  102. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -33
  103. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  104. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
  105. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
  106. package/build/cjs/node_modules/history/index.js +0 -815
  107. package/build/cjs/node_modules/history/index.js.map +0 -1
  108. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
  109. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
  110. package/build/cjs/packages/router-core/src/index.js +0 -58
  111. package/build/cjs/packages/router-core/src/index.js.map +0 -1
  112. package/build/cjs/packages/router-core/src/path.js +0 -222
  113. package/build/cjs/packages/router-core/src/path.js.map +0 -1
  114. package/build/cjs/packages/router-core/src/qss.js +0 -71
  115. package/build/cjs/packages/router-core/src/qss.js.map +0 -1
  116. package/build/cjs/packages/router-core/src/route.js +0 -150
  117. package/build/cjs/packages/router-core/src/route.js.map +0 -1
  118. package/build/cjs/packages/router-core/src/routeConfig.js +0 -69
  119. package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
  120. package/build/cjs/packages/router-core/src/routeMatch.js +0 -266
  121. package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
  122. package/build/cjs/packages/router-core/src/router.js +0 -822
  123. package/build/cjs/packages/router-core/src/router.js.map +0 -1
  124. package/build/cjs/packages/router-core/src/searchParams.js +0 -70
  125. package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
  126. package/build/cjs/packages/router-core/src/utils.js +0 -125
  127. package/build/cjs/packages/router-core/src/utils.js.map +0 -1
  128. package/build/esm/index.js +0 -2481
  129. package/build/esm/index.js.map +0 -1
  130. package/build/stats-html.html +0 -4034
  131. package/build/stats-react.json +0 -493
  132. package/build/types/index.d.ts +0 -618
  133. package/build/umd/index.development.js +0 -2514
  134. package/build/umd/index.development.js.map +0 -1
  135. package/build/umd/index.production.js +0 -12
  136. package/build/umd/index.production.js.map +0 -1
  137. package/src/frameworks.ts +0 -12
  138. package/src/routeConfig.ts +0 -495
  139. package/src/routeInfo.ts +0 -228
  140. package/src/routeMatch.ts +0 -374
package/src/route.ts CHANGED
@@ -1,230 +1,303 @@
1
- import {
2
- CheckRelativePath,
3
- LinkInfo,
4
- LinkOptions,
5
- ResolveRelativePath,
6
- ToOptions,
7
- } from './link'
8
- import { LoaderContext, RouteConfig, RouteOptions } from './routeConfig'
9
- import {
10
- AnyAllRouteInfo,
11
- AnyRouteInfo,
12
- DefaultAllRouteInfo,
13
- RouteInfo,
14
- RouteInfoByPath,
15
- } from './routeInfo'
16
- import { RouteMatch } from './routeMatch'
17
- import {
18
- Action,
19
- ActionState,
20
- Loader,
21
- LoaderState,
22
- MatchRouteOptions,
23
- Router,
24
- } from './router'
25
- import { NoInfer, replaceEqualDeep } from './utils'
26
-
27
- export interface AnyRoute extends Route<any, any> {}
28
-
29
- export interface Route<
30
- TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,
31
- TRouteInfo extends AnyRouteInfo = RouteInfo,
32
- > {
33
- routeId: TRouteInfo['id']
34
- routeRouteId: TRouteInfo['routeId']
35
- routePath: TRouteInfo['path']
36
- fullPath: TRouteInfo['fullPath']
37
- parentRoute?: AnyRoute
38
- childRoutes?: AnyRoute[]
39
- options: RouteOptions
40
- router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo>
41
- buildLink: <TTo extends string = '.'>(
42
- options: Omit<
43
- LinkOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>,
44
- 'from'
45
- >,
46
- ) => LinkInfo
47
- matchRoute: <
48
- TTo extends string = '.',
49
- TResolved extends string = ResolveRelativePath<TRouteInfo['id'], TTo>,
50
- >(
51
- matchLocation: CheckRelativePath<
52
- TAllRouteInfo,
53
- TRouteInfo['fullPath'],
54
- NoInfer<TTo>
55
- > &
56
- Omit<ToOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>, 'from'>,
57
- opts?: MatchRouteOptions,
58
- ) => RouteInfoByPath<TAllRouteInfo, TResolved>['allParams']
59
- navigate: <TTo extends string = '.'>(
60
- options: Omit<LinkOptions<TAllRouteInfo, TRouteInfo['id'], TTo>, 'from'>,
61
- ) => Promise<void>
62
- action: unknown extends TRouteInfo['actionResponse']
63
- ?
64
- | Action<TRouteInfo['actionPayload'], TRouteInfo['actionResponse']>
65
- | undefined
66
- : Action<TRouteInfo['actionPayload'], TRouteInfo['actionResponse']>
67
- loader: unknown extends TRouteInfo['routeLoaderData']
68
- ?
69
- | Action<
70
- LoaderContext<
71
- TRouteInfo['fullSearchSchema'],
72
- TRouteInfo['allParams']
73
- >,
74
- TRouteInfo['routeLoaderData']
75
- >
76
- | undefined
77
- : Loader<
78
- TRouteInfo['fullSearchSchema'],
79
- TRouteInfo['allParams'],
80
- TRouteInfo['routeLoaderData']
81
- >
1
+ import type { ParsePathParams } from './link'
2
+ import type { RootRouteId } from './root'
3
+ import type { Assign } from './utils'
4
+ import type {
5
+ AnySchema,
6
+ AnyStandardSchemaValidator,
7
+ AnyValidatorAdapter,
8
+ AnyValidatorObj,
9
+ StandardSchemaValidator,
10
+ ValidatorAdapter,
11
+ ValidatorFn,
12
+ ValidatorObj,
13
+ } from './validators'
14
+
15
+ export type AnyPathParams = {}
16
+
17
+ export type SearchSchemaInput = {
18
+ __TSearchSchemaInput__: 'TSearchSchemaInput'
82
19
  }
83
20
 
84
- export function createRoute<
85
- TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo,
86
- TRouteInfo extends AnyRouteInfo = RouteInfo,
87
- >(
88
- routeConfig: RouteConfig,
89
- options: TRouteInfo['options'],
90
- parent: undefined | Route<TAllRouteInfo, any>,
91
- router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo>,
92
- ): Route<TAllRouteInfo, TRouteInfo> {
93
- const { id, routeId, path: routePath, fullPath } = routeConfig
94
-
95
- const action =
96
- router.state.actions[id] ||
97
- (() => {
98
- router.state.actions[id] = {
99
- pending: [],
100
- submit: async <T, U>(
101
- submission: T,
102
- actionOpts?: { invalidate?: boolean },
103
- ) => {
104
- if (!route) {
105
- return
106
- }
107
-
108
- const invalidate = actionOpts?.invalidate ?? true
109
-
110
- const actionState: ActionState<T, U> = {
111
- submittedAt: Date.now(),
112
- status: 'pending',
113
- submission,
114
- }
115
-
116
- action.current = actionState
117
- action.latest = actionState
118
- action.pending.push(actionState)
119
-
120
- router.state = {
121
- ...router.state,
122
- currentAction: actionState,
123
- latestAction: actionState,
124
- }
125
-
126
- router.notify()
127
-
128
- try {
129
- const res = await route.options.action?.(submission)
130
- actionState.data = res as U
131
- if (invalidate) {
132
- router.invalidateRoute({ to: '.', fromCurrent: true })
133
- await router.reload()
134
- }
135
- actionState.status = 'success'
136
- return res
137
- } catch (err) {
138
- console.error(err)
139
- actionState.error = err
140
- actionState.status = 'error'
141
- } finally {
142
- action.pending = action.pending.filter((d) => d !== actionState)
143
- router.removeActionQueue.push({ action, actionState })
144
- router.notify()
145
- }
146
- },
147
- }
148
- return router.state.actions[id]!
149
- })()
150
-
151
- const loader =
152
- router.state.loaders[id] ||
153
- (() => {
154
- router.state.loaders[id] = {
155
- pending: [],
156
- fetch: (async (loaderContext: LoaderContext<any, any>) => {
157
- if (!route) {
158
- return
159
- }
160
-
161
- const loaderState: LoaderState<any, any> = {
162
- loadedAt: Date.now(),
163
- loaderContext,
164
- }
165
-
166
- loader.current = loaderState
167
- loader.latest = loaderState
168
- loader.pending.push(loaderState)
169
-
170
- // router.state = {
171
- // ...router.state,
172
- // currentAction: loaderState,
173
- // latestAction: loaderState,
174
- // }
175
-
176
- router.notify()
177
-
178
- try {
179
- return await route.options.loader?.(loaderContext)
180
- } finally {
181
- loader.pending = loader.pending.filter((d) => d !== loaderState)
182
- // router.removeActionQueue.push({ loader, loaderState })
183
- router.notify()
184
- }
185
- }) as any,
21
+ export type AnyContext = {}
22
+
23
+ export interface RouteContext {}
24
+
25
+ export type PreloadableObj = { preload?: () => Promise<void> }
26
+
27
+ export type RoutePathOptions<TCustomId, TPath> =
28
+ | {
29
+ path: TPath
30
+ }
31
+ | {
32
+ id: TCustomId
33
+ }
34
+
35
+ export interface StaticDataRouteOption {}
36
+
37
+ export type RoutePathOptionsIntersection<TCustomId, TPath> = {
38
+ path: TPath
39
+ id: TCustomId
40
+ }
41
+
42
+ export type SearchFilter<TInput, TResult = TInput> = (prev: TInput) => TResult
43
+
44
+ export type SearchMiddlewareContext<TSearchSchema> = {
45
+ search: TSearchSchema
46
+ next: (newSearch: TSearchSchema) => TSearchSchema
47
+ }
48
+
49
+ export type SearchMiddleware<TSearchSchema> = (
50
+ ctx: SearchMiddlewareContext<TSearchSchema>,
51
+ ) => TSearchSchema
52
+
53
+ export type ResolveId<
54
+ TParentRoute,
55
+ TCustomId extends string,
56
+ TPath extends string,
57
+ > = TParentRoute extends { id: infer TParentId extends string }
58
+ ? RoutePrefix<TParentId, string extends TCustomId ? TPath : TCustomId>
59
+ : RootRouteId
60
+
61
+ export type InferFullSearchSchema<TRoute> = TRoute extends {
62
+ types: {
63
+ fullSearchSchema: infer TFullSearchSchema
64
+ }
65
+ }
66
+ ? TFullSearchSchema
67
+ : {}
68
+
69
+ export type InferFullSearchSchemaInput<TRoute> = TRoute extends {
70
+ types: {
71
+ fullSearchSchemaInput: infer TFullSearchSchemaInput
72
+ }
73
+ }
74
+ ? TFullSearchSchemaInput
75
+ : {}
76
+
77
+ export type InferAllParams<TRoute> = TRoute extends {
78
+ types: {
79
+ allParams: infer TAllParams
80
+ }
81
+ }
82
+ ? TAllParams
83
+ : {}
84
+
85
+ export type InferAllContext<TRoute> = unknown extends TRoute
86
+ ? TRoute
87
+ : TRoute extends {
88
+ types: {
89
+ allContext: infer TAllContext
90
+ }
186
91
  }
187
- return router.state.loaders[id]!
188
- })()
189
-
190
- let route: Route<TAllRouteInfo, TRouteInfo> = {
191
- routeId: id,
192
- routeRouteId: routeId,
193
- routePath,
194
- fullPath,
195
- options,
196
- router,
197
- childRoutes: undefined!,
198
- parentRoute: parent,
199
- action,
200
- loader: loader as any,
201
-
202
- buildLink: (options) => {
203
- return router.buildLink({
204
- ...options,
205
- from: fullPath,
206
- } as any) as any
207
- },
208
-
209
- navigate: (options) => {
210
- return router.navigate({
211
- ...options,
212
- from: fullPath,
213
- } as any) as any
214
- },
215
-
216
- matchRoute: (matchLocation, opts) => {
217
- return router.matchRoute(
218
- {
219
- ...matchLocation,
220
- from: fullPath,
221
- } as any,
222
- opts,
223
- )
224
- },
92
+ ? TAllContext
93
+ : {}
94
+
95
+ export type ResolveSearchSchemaFnInput<TSearchValidator> =
96
+ TSearchValidator extends (input: infer TSearchSchemaInput) => any
97
+ ? TSearchSchemaInput extends SearchSchemaInput
98
+ ? Omit<TSearchSchemaInput, keyof SearchSchemaInput>
99
+ : ResolveSearchSchemaFn<TSearchValidator>
100
+ : AnySchema
101
+
102
+ export type ResolveSearchSchemaInput<TSearchValidator> =
103
+ TSearchValidator extends AnyStandardSchemaValidator
104
+ ? NonNullable<TSearchValidator['~standard']['types']>['input']
105
+ : TSearchValidator extends AnyValidatorAdapter
106
+ ? TSearchValidator['types']['input']
107
+ : TSearchValidator extends AnyValidatorObj
108
+ ? ResolveSearchSchemaFnInput<TSearchValidator['parse']>
109
+ : ResolveSearchSchemaFnInput<TSearchValidator>
110
+
111
+ export type ResolveSearchSchemaFn<TSearchValidator> = TSearchValidator extends (
112
+ ...args: any
113
+ ) => infer TSearchSchema
114
+ ? TSearchSchema
115
+ : AnySchema
116
+
117
+ export type ResolveSearchSchema<TSearchValidator> =
118
+ unknown extends TSearchValidator
119
+ ? TSearchValidator
120
+ : TSearchValidator extends AnyStandardSchemaValidator
121
+ ? NonNullable<TSearchValidator['~standard']['types']>['output']
122
+ : TSearchValidator extends AnyValidatorAdapter
123
+ ? TSearchValidator['types']['output']
124
+ : TSearchValidator extends AnyValidatorObj
125
+ ? ResolveSearchSchemaFn<TSearchValidator['parse']>
126
+ : ResolveSearchSchemaFn<TSearchValidator>
127
+
128
+ export type ParseSplatParams<TPath extends string> = TPath &
129
+ `${string}$` extends never
130
+ ? TPath & `${string}$/${string}` extends never
131
+ ? never
132
+ : '_splat'
133
+ : '_splat'
134
+
135
+ export interface SplatParams {
136
+ _splat?: string
137
+ }
138
+
139
+ export type ResolveParams<TPath extends string> =
140
+ ParseSplatParams<TPath> extends never
141
+ ? Record<ParsePathParams<TPath>, string>
142
+ : Record<ParsePathParams<TPath>, string> & SplatParams
143
+
144
+ export type ParseParamsFn<in out TPath extends string, in out TParams> = (
145
+ rawParams: ResolveParams<TPath>,
146
+ ) => TParams extends Record<ParsePathParams<TPath>, any>
147
+ ? TParams
148
+ : Record<ParsePathParams<TPath>, any>
149
+
150
+ export type StringifyParamsFn<in out TPath extends string, in out TParams> = (
151
+ params: TParams,
152
+ ) => ResolveParams<TPath>
153
+
154
+ export type ParamsOptions<in out TPath extends string, in out TParams> = {
155
+ params?: {
156
+ parse?: ParseParamsFn<TPath, TParams>
157
+ stringify?: StringifyParamsFn<TPath, TParams>
225
158
  }
226
159
 
227
- router.options.createRoute?.({ router, route })
160
+ /**
161
+ @deprecated Use params.parse instead
162
+ */
163
+ parseParams?: ParseParamsFn<TPath, TParams>
164
+
165
+ /**
166
+ @deprecated Use params.stringify instead
167
+ */
168
+ stringifyParams?: StringifyParamsFn<TPath, TParams>
169
+ }
170
+
171
+ interface RequiredStaticDataRouteOption {
172
+ staticData: StaticDataRouteOption
173
+ }
174
+
175
+ interface OptionalStaticDataRouteOption {
176
+ staticData?: StaticDataRouteOption
177
+ }
178
+
179
+ export type UpdatableStaticRouteOption = {} extends StaticDataRouteOption
180
+ ? OptionalStaticDataRouteOption
181
+ : RequiredStaticDataRouteOption
182
+
183
+ export type MetaDescriptor =
184
+ | { charSet: 'utf-8' }
185
+ | { title: string }
186
+ | { name: string; content: string }
187
+ | { property: string; content: string }
188
+ | { httpEquiv: string; content: string }
189
+ | { 'script:ld+json': LdJsonObject }
190
+ | { tagName: 'meta' | 'link'; [name: string]: string }
191
+ | Record<string, unknown>
228
192
 
229
- return route
193
+ type LdJsonObject = { [Key in string]: LdJsonValue } & {
194
+ [Key in string]?: LdJsonValue | undefined
230
195
  }
196
+ type LdJsonArray = Array<LdJsonValue> | ReadonlyArray<LdJsonValue>
197
+ type LdJsonPrimitive = string | number | boolean | null
198
+ type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray
199
+
200
+ export type RouteLinkEntry = {}
201
+
202
+ export type SearchValidator<TInput, TOutput> =
203
+ | ValidatorObj<TInput, TOutput>
204
+ | ValidatorFn<TInput, TOutput>
205
+ | ValidatorAdapter<TInput, TOutput>
206
+ | StandardSchemaValidator<TInput, TOutput>
207
+ | undefined
208
+
209
+ export type AnySearchValidator = SearchValidator<any, any>
210
+
211
+ export type DefaultSearchValidator = SearchValidator<
212
+ Record<string, unknown>,
213
+ AnySchema
214
+ >
215
+
216
+ export type LooseReturnType<T> = T extends (
217
+ ...args: Array<any>
218
+ ) => infer TReturn
219
+ ? TReturn
220
+ : never
221
+
222
+ export type LooseAsyncReturnType<T> = T extends (
223
+ ...args: Array<any>
224
+ ) => infer TReturn
225
+ ? TReturn extends Promise<infer TReturn>
226
+ ? TReturn
227
+ : TReturn
228
+ : never
229
+
230
+ export type ContextReturnType<TContextFn> = unknown extends TContextFn
231
+ ? TContextFn
232
+ : LooseReturnType<TContextFn> extends never
233
+ ? AnyContext
234
+ : LooseReturnType<TContextFn>
235
+
236
+ export type ContextAsyncReturnType<TContextFn> = unknown extends TContextFn
237
+ ? TContextFn
238
+ : LooseAsyncReturnType<TContextFn> extends never
239
+ ? AnyContext
240
+ : LooseAsyncReturnType<TContextFn>
241
+
242
+ export type ResolveRouteContext<TRouteContextFn, TBeforeLoadFn> = Assign<
243
+ ContextReturnType<TRouteContextFn>,
244
+ ContextAsyncReturnType<TBeforeLoadFn>
245
+ >
246
+
247
+ export type ResolveLoaderData<TLoaderFn> = unknown extends TLoaderFn
248
+ ? TLoaderFn
249
+ : LooseAsyncReturnType<TLoaderFn> extends never
250
+ ? {}
251
+ : LooseAsyncReturnType<TLoaderFn>
252
+
253
+ export type RoutePrefix<
254
+ TPrefix extends string,
255
+ TPath extends string,
256
+ > = string extends TPath
257
+ ? RootRouteId
258
+ : TPath extends string
259
+ ? TPrefix extends RootRouteId
260
+ ? TPath extends '/'
261
+ ? '/'
262
+ : `/${TrimPath<TPath>}`
263
+ : `${TPrefix}/${TPath}` extends '/'
264
+ ? '/'
265
+ : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}`
266
+ : never
267
+
268
+ export type TrimPath<T extends string> = '' extends T
269
+ ? ''
270
+ : TrimPathRight<TrimPathLeft<T>>
271
+
272
+ export type TrimPathLeft<T extends string> =
273
+ T extends `${RootRouteId}/${infer U}`
274
+ ? TrimPathLeft<U>
275
+ : T extends `/${infer U}`
276
+ ? TrimPathLeft<U>
277
+ : T
278
+ export type TrimPathRight<T extends string> = T extends '/'
279
+ ? '/'
280
+ : T extends `${infer U}/`
281
+ ? TrimPathRight<U>
282
+ : T
283
+
284
+ /**
285
+ * @deprecated Use `ErrorComponentProps` instead.
286
+ */
287
+ export type ErrorRouteProps = {
288
+ error: unknown
289
+ info?: { componentStack: string }
290
+ reset: () => void
291
+ }
292
+
293
+ export type ErrorComponentProps = {
294
+ error: Error
295
+ info?: { componentStack: string }
296
+ reset: () => void
297
+ }
298
+ export type NotFoundRouteProps = {
299
+ // TODO: Make sure this is `| null | undefined` (this is for global not-founds)
300
+ data: unknown
301
+ }
302
+
303
+ //