@tanstack/react-router 1.26.10 → 1.26.12
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/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +4 -4
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +17 -17
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +3 -5
- package/dist/esm/fileRoute.d.ts +4 -4
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/route.d.ts +17 -17
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/utils.d.ts +3 -5
- package/dist/esm/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/fileRoute.ts +10 -15
- package/src/route.ts +41 -58
- package/src/utils.ts +7 -62
package/src/fileRoute.ts
CHANGED
|
@@ -40,9 +40,10 @@ type Replace<
|
|
|
40
40
|
TValue extends string,
|
|
41
41
|
TFrom extends string,
|
|
42
42
|
TTo extends string,
|
|
43
|
+
TAcc extends string = '',
|
|
43
44
|
> = TValue extends `${infer Start}${TFrom}${infer Rest}`
|
|
44
|
-
?
|
|
45
|
-
: TValue
|
|
45
|
+
? Replace<Rest, TFrom, TTo, `${TAcc}${Start}${TTo}`>
|
|
46
|
+
: `${TAcc}${TValue}`
|
|
46
47
|
|
|
47
48
|
export type TrimLeft<
|
|
48
49
|
TValue extends string,
|
|
@@ -97,12 +98,12 @@ export type ResolveFilePath<
|
|
|
97
98
|
export type FileRoutePath<
|
|
98
99
|
TParentRoute extends AnyRoute,
|
|
99
100
|
TFilePath extends string,
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
TResolvedFilePath = ResolveFilePath<TParentRoute, TFilePath>,
|
|
102
|
+
> = TResolvedFilePath extends `_${infer _}`
|
|
103
|
+
? ''
|
|
104
|
+
: TResolvedFilePath extends `/_${infer _}`
|
|
102
105
|
? ''
|
|
103
|
-
:
|
|
104
|
-
? ''
|
|
105
|
-
: ResolveFilePath<TParentRoute, TFilePath>
|
|
106
|
+
: TResolvedFilePath
|
|
106
107
|
|
|
107
108
|
export function createFileRoute<
|
|
108
109
|
TFilePath extends keyof FileRoutesByPath,
|
|
@@ -164,11 +165,7 @@ export class FileRoute<
|
|
|
164
165
|
TParentRoute,
|
|
165
166
|
TSearchSchemaUsed
|
|
166
167
|
>,
|
|
167
|
-
TFullSearchSchema
|
|
168
|
-
RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
|
|
169
|
-
TParentRoute,
|
|
170
|
-
TSearchSchema
|
|
171
|
-
>,
|
|
168
|
+
TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,
|
|
172
169
|
TParams extends RouteConstraints['TParams'] = Expand<
|
|
173
170
|
Record<ParsePathParams<TPath>, string>
|
|
174
171
|
>,
|
|
@@ -183,9 +180,7 @@ export class FileRoute<
|
|
|
183
180
|
] extends [never]
|
|
184
181
|
? RouteContext
|
|
185
182
|
: TRouteContextReturn,
|
|
186
|
-
TAllContext
|
|
187
|
-
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
|
|
188
|
-
> = Expand<
|
|
183
|
+
TAllContext = Expand<
|
|
189
184
|
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
|
|
190
185
|
>,
|
|
191
186
|
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
package/src/route.ts
CHANGED
|
@@ -61,13 +61,13 @@ export type RouteOptions<
|
|
|
61
61
|
TSearchSchema extends Record<string, any> = {},
|
|
62
62
|
TSearchSchemaUsed extends Record<string, any> = {},
|
|
63
63
|
TFullSearchSchemaInput extends Record<string, any> = TSearchSchemaUsed,
|
|
64
|
-
TFullSearchSchema
|
|
64
|
+
TFullSearchSchema = TSearchSchema,
|
|
65
65
|
TParams extends AnyPathParams = AnyPathParams,
|
|
66
66
|
TAllParams extends AnyPathParams = TParams,
|
|
67
67
|
TRouteContextReturn extends RouteContext = RouteContext,
|
|
68
68
|
TRouteContext extends RouteContext = RouteContext,
|
|
69
69
|
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
70
|
-
TAllContext
|
|
70
|
+
TAllContext = AnyContext,
|
|
71
71
|
TLoaderDeps extends Record<string, any> = {},
|
|
72
72
|
TLoaderDataReturn = unknown,
|
|
73
73
|
TLoaderData = [TLoaderDataReturn] extends [never]
|
|
@@ -107,13 +107,13 @@ export type FileBaseRouteOptions<
|
|
|
107
107
|
TPath extends string = string,
|
|
108
108
|
TSearchSchemaInput extends Record<string, any> = {},
|
|
109
109
|
TSearchSchema extends Record<string, any> = {},
|
|
110
|
-
TFullSearchSchema
|
|
110
|
+
TFullSearchSchema = TSearchSchema,
|
|
111
111
|
TParams extends AnyPathParams = {},
|
|
112
112
|
TAllParams = ParamsFallback<TPath, TParams>,
|
|
113
113
|
TRouteContextReturn extends RouteContext = RouteContext,
|
|
114
114
|
TRouteContext extends RouteContext = RouteContext,
|
|
115
115
|
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
116
|
-
TAllContext
|
|
116
|
+
TAllContext = AnyContext,
|
|
117
117
|
TLoaderDeps extends Record<string, any> = {},
|
|
118
118
|
TLoaderDataReturn = unknown,
|
|
119
119
|
> = {
|
|
@@ -173,13 +173,13 @@ export type BaseRouteOptions<
|
|
|
173
173
|
TSearchSchema extends Record<string, any> = {},
|
|
174
174
|
TSearchSchemaUsed extends Record<string, any> = {},
|
|
175
175
|
TFullSearchSchemaInput extends Record<string, any> = TSearchSchemaUsed,
|
|
176
|
-
TFullSearchSchema
|
|
176
|
+
TFullSearchSchema = TSearchSchema,
|
|
177
177
|
TParams extends AnyPathParams = {},
|
|
178
178
|
TAllParams = ParamsFallback<TPath, TParams>,
|
|
179
179
|
TRouteContextReturn extends RouteContext = RouteContext,
|
|
180
180
|
TRouteContext extends RouteContext = RouteContext,
|
|
181
181
|
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
182
|
-
TAllContext
|
|
182
|
+
TAllContext = AnyContext,
|
|
183
183
|
TLoaderDeps extends Record<string, any> = {},
|
|
184
184
|
TLoaderDataReturn = unknown,
|
|
185
185
|
> = RoutePathOptions<TCustomId, TPath> &
|
|
@@ -202,7 +202,7 @@ export type BaseRouteOptions<
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
type BeforeLoadFn<
|
|
205
|
-
TFullSearchSchema
|
|
205
|
+
TFullSearchSchema,
|
|
206
206
|
TParentRoute extends AnyRoute,
|
|
207
207
|
TAllParams,
|
|
208
208
|
TRouteContextReturn extends RouteContext,
|
|
@@ -222,7 +222,7 @@ type BeforeLoadFn<
|
|
|
222
222
|
|
|
223
223
|
export type UpdatableRouteOptions<
|
|
224
224
|
TAllParams extends Record<string, any>,
|
|
225
|
-
TFullSearchSchema
|
|
225
|
+
TFullSearchSchema,
|
|
226
226
|
TLoaderData,
|
|
227
227
|
> = {
|
|
228
228
|
// test?: (args: TAllContext) => void
|
|
@@ -325,7 +325,7 @@ export type SearchSchemaValidatorFn<TInput, TReturn> = (
|
|
|
325
325
|
export type RouteLoaderFn<
|
|
326
326
|
TAllParams = {},
|
|
327
327
|
TLoaderDeps extends Record<string, any> = {},
|
|
328
|
-
TAllContext
|
|
328
|
+
TAllContext = AnyContext,
|
|
329
329
|
TRouteContext extends Record<string, any> = AnyContext,
|
|
330
330
|
TLoaderData = unknown,
|
|
331
331
|
> = (
|
|
@@ -334,8 +334,8 @@ export type RouteLoaderFn<
|
|
|
334
334
|
|
|
335
335
|
export interface LoaderFnContext<
|
|
336
336
|
TAllParams = {},
|
|
337
|
-
TLoaderDeps
|
|
338
|
-
TAllContext
|
|
337
|
+
TLoaderDeps = {},
|
|
338
|
+
TAllContext = AnyContext,
|
|
339
339
|
TRouteContext extends Record<string, any> = AnyContext,
|
|
340
340
|
> {
|
|
341
341
|
abortController: AbortController
|
|
@@ -376,20 +376,27 @@ export type InferFullSearchSchemaInput<TRoute> = TRoute extends {
|
|
|
376
376
|
? TFullSearchSchemaInput
|
|
377
377
|
: {}
|
|
378
378
|
|
|
379
|
-
export type ResolveFullSearchSchema<
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
379
|
+
export type ResolveFullSearchSchema<
|
|
380
|
+
TParentRoute extends AnyRoute,
|
|
381
|
+
TSearchSchema,
|
|
382
|
+
> = Assign<
|
|
383
|
+
TParentRoute['isRoot'] extends true
|
|
384
|
+
? TParentRoute['types']['searchSchema']
|
|
385
|
+
: TParentRoute['types']['fullSearchSchema'],
|
|
386
|
+
TSearchSchema,
|
|
387
|
+
keyof RootSearchSchema
|
|
384
388
|
>
|
|
385
389
|
|
|
386
|
-
export type ResolveFullSearchSchemaInput<
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
390
|
+
export type ResolveFullSearchSchemaInput<
|
|
391
|
+
TParentRoute extends AnyRoute,
|
|
392
|
+
TSearchSchemaUsed,
|
|
393
|
+
> = Assign<
|
|
394
|
+
TParentRoute['isRoot'] extends true
|
|
395
|
+
? TParentRoute['types']['searchSchemaInput']
|
|
396
|
+
: TParentRoute['types']['fullSearchSchemaInput'],
|
|
397
|
+
TSearchSchemaUsed,
|
|
398
|
+
keyof RootSearchSchema
|
|
399
|
+
>
|
|
393
400
|
|
|
394
401
|
export interface AnyRoute
|
|
395
402
|
extends Route<
|
|
@@ -450,12 +457,9 @@ export type RouteConstraints = {
|
|
|
450
457
|
export function getRouteApi<
|
|
451
458
|
TId extends RouteIds<RegisteredRouter['routeTree']>,
|
|
452
459
|
TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,
|
|
453
|
-
TFullSearchSchema
|
|
454
|
-
string,
|
|
455
|
-
any
|
|
456
|
-
> = TRoute['types']['fullSearchSchema'],
|
|
460
|
+
TFullSearchSchema = TRoute['types']['fullSearchSchema'],
|
|
457
461
|
TAllParams extends AnyPathParams = TRoute['types']['allParams'],
|
|
458
|
-
TAllContext
|
|
462
|
+
TAllContext = TRoute['types']['allContext'],
|
|
459
463
|
TLoaderDeps extends Record<string, any> = TRoute['types']['loaderDeps'],
|
|
460
464
|
TLoaderData = TRoute['types']['loaderData'],
|
|
461
465
|
>(id: TId) {
|
|
@@ -473,12 +477,9 @@ export function getRouteApi<
|
|
|
473
477
|
export class RouteApi<
|
|
474
478
|
TId extends RouteIds<RegisteredRouter['routeTree']>,
|
|
475
479
|
TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,
|
|
476
|
-
TFullSearchSchema
|
|
477
|
-
string,
|
|
478
|
-
any
|
|
479
|
-
> = TRoute['types']['fullSearchSchema'],
|
|
480
|
+
TFullSearchSchema = TRoute['types']['fullSearchSchema'],
|
|
480
481
|
TAllParams extends AnyPathParams = TRoute['types']['allParams'],
|
|
481
|
-
TAllContext
|
|
482
|
+
TAllContext = TRoute['types']['allContext'],
|
|
482
483
|
TLoaderDeps extends Record<string, any> = TRoute['types']['loaderDeps'],
|
|
483
484
|
TLoaderData = TRoute['types']['loaderData'],
|
|
484
485
|
> {
|
|
@@ -568,11 +569,7 @@ export class Route<
|
|
|
568
569
|
string,
|
|
569
570
|
any
|
|
570
571
|
> = ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed>,
|
|
571
|
-
TFullSearchSchema
|
|
572
|
-
RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
|
|
573
|
-
TParentRoute,
|
|
574
|
-
TSearchSchema
|
|
575
|
-
>,
|
|
572
|
+
TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,
|
|
576
573
|
TParams extends RouteConstraints['TParams'] = Expand<
|
|
577
574
|
Record<ParsePathParams<TPath>, string>
|
|
578
575
|
>,
|
|
@@ -586,9 +583,7 @@ export class Route<
|
|
|
586
583
|
] extends [never]
|
|
587
584
|
? RouteContext
|
|
588
585
|
: TRouteContextReturn,
|
|
589
|
-
in out TAllContext
|
|
590
|
-
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
|
|
591
|
-
> = Expand<
|
|
586
|
+
in out TAllContext = Expand<
|
|
592
587
|
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
|
|
593
588
|
>,
|
|
594
589
|
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
@@ -918,11 +913,7 @@ export function createRoute<
|
|
|
918
913
|
string,
|
|
919
914
|
any
|
|
920
915
|
> = ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed>,
|
|
921
|
-
TFullSearchSchema
|
|
922
|
-
RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
|
|
923
|
-
TParentRoute,
|
|
924
|
-
TSearchSchema
|
|
925
|
-
>,
|
|
916
|
+
TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,
|
|
926
917
|
TParams extends RouteConstraints['TParams'] = Expand<
|
|
927
918
|
Record<ParsePathParams<TPath>, string>
|
|
928
919
|
>,
|
|
@@ -936,9 +927,7 @@ export function createRoute<
|
|
|
936
927
|
] extends [never]
|
|
937
928
|
? RouteContext
|
|
938
929
|
: TRouteContextReturn,
|
|
939
|
-
TAllContext
|
|
940
|
-
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
|
|
941
|
-
> = Expand<
|
|
930
|
+
TAllContext = Expand<
|
|
942
931
|
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
|
|
943
932
|
>,
|
|
944
933
|
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
|
@@ -1091,7 +1080,7 @@ export class RootRoute<
|
|
|
1091
1080
|
{}, // TAllParams
|
|
1092
1081
|
TRouteContextReturn, // TRouteContextReturn
|
|
1093
1082
|
TRouteContext, // TRouteContext
|
|
1094
|
-
|
|
1083
|
+
Assign<TRouterContext, TRouteContext>, // TAllContext
|
|
1095
1084
|
TRouterContext, // TRouterContext
|
|
1096
1085
|
TLoaderDeps,
|
|
1097
1086
|
TLoaderDataReturn,
|
|
@@ -1298,16 +1287,10 @@ export class NotFoundRoute<
|
|
|
1298
1287
|
TParentRoute,
|
|
1299
1288
|
TSearchSchemaUsed
|
|
1300
1289
|
>,
|
|
1301
|
-
TFullSearchSchema
|
|
1302
|
-
RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
|
|
1303
|
-
TParentRoute,
|
|
1304
|
-
TSearchSchema
|
|
1305
|
-
>,
|
|
1290
|
+
TFullSearchSchema = ResolveFullSearchSchema<TParentRoute, TSearchSchema>,
|
|
1306
1291
|
TRouteContextReturn extends RouteConstraints['TRouteContext'] = AnyContext,
|
|
1307
1292
|
TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext,
|
|
1308
|
-
TAllContext
|
|
1309
|
-
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
|
|
1310
|
-
> = Expand<
|
|
1293
|
+
TAllContext = Expand<
|
|
1311
1294
|
Assign<IsAny<TParentRoute['types']['allContext'], {}>, TRouteContext>
|
|
1312
1295
|
>,
|
|
1313
1296
|
TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext,
|
package/src/utils.ts
CHANGED
|
@@ -49,68 +49,13 @@ export type IsUnion<T, U extends T = T> = (
|
|
|
49
49
|
? false
|
|
50
50
|
: true
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
// } & {
|
|
60
|
-
// [K in AllKeys<T>]?: T extends any
|
|
61
|
-
// ? K extends keyof T
|
|
62
|
-
// ? T[K]
|
|
63
|
-
// : never
|
|
64
|
-
// : never
|
|
65
|
-
// }
|
|
66
|
-
// >
|
|
67
|
-
|
|
68
|
-
export type Assign<TLeft, TRight> = Omit<TLeft, keyof TRight> & TRight
|
|
69
|
-
|
|
70
|
-
export type AssignAll<T extends Array<any>> = T extends [
|
|
71
|
-
infer Left,
|
|
72
|
-
...infer Right,
|
|
73
|
-
]
|
|
74
|
-
? Right extends Array<any>
|
|
75
|
-
? Assign<Left, AssignAll<Right>>
|
|
76
|
-
: Left
|
|
77
|
-
: {}
|
|
78
|
-
|
|
79
|
-
// // Sample types to merge
|
|
80
|
-
// type TypeA = {
|
|
81
|
-
// shared: string
|
|
82
|
-
// onlyInA: string
|
|
83
|
-
// nested: {
|
|
84
|
-
// shared: string
|
|
85
|
-
// aProp: string
|
|
86
|
-
// }
|
|
87
|
-
// array: string[]
|
|
88
|
-
// }
|
|
89
|
-
|
|
90
|
-
// type TypeB = {
|
|
91
|
-
// shared: number
|
|
92
|
-
// onlyInB: number
|
|
93
|
-
// nested: {
|
|
94
|
-
// shared: number
|
|
95
|
-
// bProp: number
|
|
96
|
-
// }
|
|
97
|
-
// array: number[]
|
|
98
|
-
// }
|
|
99
|
-
|
|
100
|
-
// type TypeC = {
|
|
101
|
-
// shared: boolean
|
|
102
|
-
// onlyInC: boolean
|
|
103
|
-
// nested: {
|
|
104
|
-
// shared: boolean
|
|
105
|
-
// cProp: boolean
|
|
106
|
-
// }
|
|
107
|
-
// array: boolean[]
|
|
108
|
-
// }
|
|
109
|
-
|
|
110
|
-
// type Test = Expand<Assign<TypeA, TypeB>>
|
|
111
|
-
|
|
112
|
-
// // Using DeepMerge to merge TypeA and TypeB
|
|
113
|
-
// type MergedType = Expand<AssignAll<[TypeA, TypeB, TypeC]>>
|
|
52
|
+
export type Assign<TLeft, TRight, TExclude = never> = {
|
|
53
|
+
[K in Exclude<keyof TLeft | keyof TRight, TExclude>]: K extends keyof TRight
|
|
54
|
+
? TRight[K]
|
|
55
|
+
: K extends keyof TLeft
|
|
56
|
+
? TLeft[K]
|
|
57
|
+
: never
|
|
58
|
+
}
|
|
114
59
|
|
|
115
60
|
export type Timeout = ReturnType<typeof setTimeout>
|
|
116
61
|
|