@tanstack/react-router 1.0.9 → 1.1.0

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/react-router",
3
3
  "author": "Tanner Linsley",
4
- "version": "1.0.9",
4
+ "version": "1.1.0",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
@@ -44,7 +44,7 @@
44
44
  "@tanstack/store": "^0.1.3",
45
45
  "tiny-invariant": "^1.3.1",
46
46
  "tiny-warning": "^1.0.3",
47
- "@tanstack/history": "1.0.9"
47
+ "@tanstack/history": "1.1.0"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "rollup --config rollup.config.js"
package/src/fileRoute.ts CHANGED
@@ -13,6 +13,8 @@ import {
13
13
  RootRouteId,
14
14
  TrimPathLeft,
15
15
  RouteConstraints,
16
+ ResolveFullSearchSchemaInput,
17
+ SearchSchemaInput,
16
18
  } from './route'
17
19
  import { Assign, Expand, IsAny } from './utils'
18
20
 
@@ -85,7 +87,19 @@ export class FileRoute<
85
87
  constructor(public path: TFilePath) {}
86
88
 
87
89
  createRoute = <
90
+ TSearchSchemaInput extends RouteConstraints['TSearchSchema'] = {},
88
91
  TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
92
+ TSearchSchemaUsed extends Record<
93
+ string,
94
+ any
95
+ > = TSearchSchemaInput extends SearchSchemaInput
96
+ ? TSearchSchemaInput
97
+ : TSearchSchema,
98
+ TFullSearchSchemaInput extends
99
+ RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchemaInput<
100
+ TParentRoute,
101
+ TSearchSchemaUsed
102
+ >,
89
103
  TFullSearchSchema extends
90
104
  RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
91
105
  TParentRoute,
@@ -115,7 +129,10 @@ export class FileRoute<
115
129
  TParentRoute,
116
130
  string,
117
131
  TPath,
132
+ TSearchSchemaInput,
118
133
  TSearchSchema,
134
+ TSearchSchemaUsed,
135
+ TFullSearchSchemaInput,
119
136
  TFullSearchSchema,
120
137
  TParams,
121
138
  TAllParams,
@@ -133,7 +150,10 @@ export class FileRoute<
133
150
  TFullPath,
134
151
  TFilePath,
135
152
  TId,
153
+ TSearchSchemaInput,
136
154
  TSearchSchema,
155
+ TSearchSchemaUsed,
156
+ TFullSearchSchemaInput,
137
157
  TFullSearchSchema,
138
158
  TParams,
139
159
  TAllParams,
package/src/link.tsx CHANGED
@@ -167,18 +167,21 @@ export type ToSubOptions<
167
167
 
168
168
  type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo)
169
169
 
170
+ type ParamVariant = 'PATH' | 'SEARCH';
170
171
  export type ParamOptions<
171
172
  TRouteTree extends AnyRoute,
172
173
  TFrom,
173
174
  TTo,
174
175
  TResolved,
175
- TParamVariant extends 'allParams' | 'fullSearchSchema',
176
- TFromParams = Expand<RouteByPath<TRouteTree, TFrom>['types'][TParamVariant]>,
176
+ TParamVariant extends ParamVariant,
177
+ TFromRouteType extends 'allParams' | 'fullSearchSchema' = TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchema',
178
+ TToRouteType extends 'allParams' | 'fullSearchSchemaInput' = TParamVariant extends 'PATH' ? 'allParams' : 'fullSearchSchemaInput',
179
+ TFromParams = Expand<RouteByPath<TRouteTree, TFrom>['types'][TFromRouteType]>,
177
180
  TToParams = TTo extends ''
178
181
  ? TFromParams
179
182
  : never extends TResolved
180
- ? Expand<RouteByPath<TRouteTree, TTo>['types'][TParamVariant]>
181
- : Expand<RouteByPath<TRouteTree, TResolved>['types'][TParamVariant]>,
183
+ ? Expand<RouteByPath<TRouteTree, TTo>['types'][TToRouteType]>
184
+ : Expand<RouteByPath<TRouteTree, TResolved>['types'][TToRouteType]>,
182
185
  TReducer = ParamsReducer<TFromParams, TToParams>,
183
186
  > = Expand<WithoutEmpty<PickRequired<TToParams>>> extends never
184
187
  ? Partial<MakeParamOption<TParamVariant, true | TReducer>>
@@ -187,9 +190,9 @@ export type ParamOptions<
187
190
  : MakeParamOption<TParamVariant, TReducer>
188
191
 
189
192
  type MakeParamOption<
190
- TParamVariant extends 'allParams' | 'fullSearchSchema',
193
+ TParamVariant extends ParamVariant,
191
194
  T,
192
- > = TParamVariant extends 'allParams'
195
+ > = TParamVariant extends 'PATH'
193
196
  ? MakePathParamOptions<T>
194
197
  : MakeSearchParamOptions<T>
195
198
  type MakeSearchParamOptions<T> = { search: T }
@@ -200,14 +203,14 @@ export type SearchParamOptions<
200
203
  TFrom,
201
204
  TTo,
202
205
  TResolved,
203
- > = ParamOptions<TRouteTree, TFrom, TTo, TResolved, 'fullSearchSchema'>
206
+ > = ParamOptions<TRouteTree, TFrom, TTo, TResolved, 'SEARCH'>
204
207
 
205
208
  export type PathParamOptions<
206
209
  TRouteTree extends AnyRoute,
207
210
  TFrom,
208
211
  TTo,
209
212
  TResolved,
210
- > = ParamOptions<TRouteTree, TFrom, TTo, TResolved, 'allParams'>
213
+ > = ParamOptions<TRouteTree, TFrom, TTo, TResolved, 'PATH'>
211
214
 
212
215
  export type ToPathOption<
213
216
  TRouteTree extends AnyRoute = AnyRoute,
package/src/route.ts CHANGED
@@ -23,6 +23,10 @@ export const rootRouteId = '__root__' as const
23
23
  export type RootRouteId = typeof rootRouteId
24
24
  export type AnyPathParams = {}
25
25
 
26
+ export type SearchSchemaInput = {
27
+ __TSearchSchemaInput__: 'TSearchSchemaInput'
28
+ }
29
+
26
30
  export type AnySearchSchema = {}
27
31
 
28
32
  export type AnyContext = {}
@@ -56,7 +60,10 @@ export type RouteOptions<
56
60
  TParentRoute extends AnyRoute = AnyRoute,
57
61
  TCustomId extends string = string,
58
62
  TPath extends string = string,
63
+ TSearchSchemaInput extends Record<string, any> = {},
59
64
  TSearchSchema extends Record<string, any> = {},
65
+ TSearchSchemaUsed extends Record<string, any> = {},
66
+ TFullSearchSchemaInput extends Record<string, any> = TSearchSchemaUsed,
60
67
  TFullSearchSchema extends Record<string, any> = TSearchSchema,
61
68
  TParams extends AnyPathParams = AnyPathParams,
62
69
  TAllParams extends AnyPathParams = TParams,
@@ -68,7 +75,10 @@ export type RouteOptions<
68
75
  TParentRoute,
69
76
  TCustomId,
70
77
  TPath,
78
+ TSearchSchemaInput,
71
79
  TSearchSchema,
80
+ TSearchSchemaUsed,
81
+ TFullSearchSchemaInput,
72
82
  TFullSearchSchema,
73
83
  TParams,
74
84
  TAllParams,
@@ -88,7 +98,10 @@ export type BaseRouteOptions<
88
98
  TParentRoute extends AnyRoute = AnyRoute,
89
99
  TCustomId extends string = string,
90
100
  TPath extends string = string,
101
+ TSearchSchemaInput extends Record<string, any> = {},
91
102
  TSearchSchema extends Record<string, any> = {},
103
+ TSearchSchemaUsed extends Record<string, any> = {},
104
+ TFullSearchSchemaInput extends Record<string, any> = TSearchSchemaUsed,
92
105
  TFullSearchSchema extends Record<string, any> = TSearchSchema,
93
106
  TParams extends AnyPathParams = {},
94
107
  TAllParams = ParamsFallback<TPath, TParams>,
@@ -98,7 +111,7 @@ export type BaseRouteOptions<
98
111
  TLoaderData extends any = unknown,
99
112
  > = RoutePathOptions<TCustomId, TPath> & {
100
113
  getParentRoute: () => TParentRoute
101
- validateSearch?: SearchSchemaValidator<TSearchSchema>
114
+ validateSearch?: SearchSchemaValidator<TSearchSchemaInput, TSearchSchema>
102
115
  shouldReload?:
103
116
  | boolean
104
117
  | ((
@@ -221,16 +234,16 @@ export type ParseParamsObj<TPath extends string, TParams> = {
221
234
  }
222
235
 
223
236
  // The parse type here allows a zod schema to be passed directly to the validator
224
- export type SearchSchemaValidator<TReturn> =
225
- | SearchSchemaValidatorObj<TReturn>
226
- | SearchSchemaValidatorFn<TReturn>
237
+ export type SearchSchemaValidator<TInput, TReturn> =
238
+ | SearchSchemaValidatorObj<TInput, TReturn>
239
+ | SearchSchemaValidatorFn<TInput, TReturn>
227
240
 
228
- export type SearchSchemaValidatorObj<TReturn> = {
229
- parse?: SearchSchemaValidatorFn<TReturn>
241
+ export type SearchSchemaValidatorObj<TInput, TReturn> = {
242
+ parse?: SearchSchemaValidatorFn<TInput, TReturn>
230
243
  }
231
244
 
232
- export type SearchSchemaValidatorFn<TReturn> = (
233
- searchObj: Record<string, unknown>,
245
+ export type SearchSchemaValidatorFn<TInput, TReturn> = (
246
+ searchObj: TInput,
234
247
  ) => TReturn
235
248
 
236
249
  export type DefinedPathParamWarning =
@@ -287,10 +300,21 @@ export type InferFullSearchSchema<TRoute> = TRoute extends {
287
300
  ? TFullSearchSchema
288
301
  : {}
289
302
 
303
+ export type InferFullSearchSchemaInput<TRoute> = TRoute extends {
304
+ types: {
305
+ fullSearchSchemaInput: infer TFullSearchSchemaInput
306
+ }
307
+ }
308
+ ? TFullSearchSchemaInput
309
+ : {}
310
+
290
311
  export type ResolveFullSearchSchema<TParentRoute, TSearchSchema> = Expand<
291
312
  Assign<InferFullSearchSchema<TParentRoute>, TSearchSchema>
292
313
  >
293
314
 
315
+ export type ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed> =
316
+ Expand<Assign<InferFullSearchSchemaInput<TParentRoute>, TSearchSchemaUsed>>
317
+
294
318
  export interface AnyRoute
295
319
  extends Route<
296
320
  any,
@@ -308,6 +332,9 @@ export interface AnyRoute
308
332
  any,
309
333
  any,
310
334
  any,
335
+ any,
336
+ any,
337
+ any,
311
338
  any
312
339
  > {}
313
340
 
@@ -412,7 +439,18 @@ export class Route<
412
439
  TCustomId,
413
440
  TPath
414
441
  >,
442
+ TSearchSchemaInput extends RouteConstraints['TSearchSchema'] = {},
415
443
  TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
444
+ TSearchSchemaUsed extends Record<
445
+ string,
446
+ any
447
+ > = TSearchSchemaInput extends SearchSchemaInput
448
+ ? Omit<TSearchSchemaInput, keyof SearchSchemaInput>
449
+ : TSearchSchema,
450
+ TFullSearchSchemaInput extends Record<
451
+ string,
452
+ any
453
+ > = ResolveFullSearchSchemaInput<TParentRoute, TSearchSchemaUsed>,
416
454
  TFullSearchSchema extends
417
455
  RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
418
456
  TParentRoute,
@@ -442,7 +480,10 @@ export class Route<
442
480
  TParentRoute,
443
481
  TCustomId,
444
482
  TPath,
483
+ TSearchSchemaInput,
445
484
  TSearchSchema,
485
+ TSearchSchemaUsed,
486
+ TFullSearchSchemaInput,
446
487
  TFullSearchSchema,
447
488
  TParams,
448
489
  TAllParams,
@@ -475,7 +516,10 @@ export class Route<
475
516
  TParentRoute,
476
517
  TCustomId,
477
518
  TPath,
519
+ TSearchSchemaInput,
478
520
  TSearchSchema,
521
+ TSearchSchemaUsed,
522
+ TFullSearchSchemaInput,
479
523
  TFullSearchSchema,
480
524
  TParams,
481
525
  TAllParams,
@@ -502,7 +546,10 @@ export class Route<
502
546
  customId: TCustomId
503
547
  id: TId
504
548
  searchSchema: TSearchSchema
549
+ searchSchemaInput: TSearchSchemaInput
550
+ searchSchemaUsed: TSearchSchemaUsed
505
551
  fullSearchSchema: TFullSearchSchema
552
+ fullSearchSchemaInput: TFullSearchSchemaInput
506
553
  params: TParams
507
554
  allParams: TAllParams
508
555
  routeContext: TRouteContext
@@ -521,7 +568,10 @@ export class Route<
521
568
  TParentRoute,
522
569
  TCustomId,
523
570
  TPath,
571
+ TSearchSchemaInput,
524
572
  TSearchSchema,
573
+ TSearchSchemaUsed,
574
+ TFullSearchSchemaInput,
525
575
  TFullSearchSchema,
526
576
  TParams,
527
577
  TAllParams,
@@ -590,7 +640,10 @@ export class Route<
590
640
  TFullPath,
591
641
  TCustomId,
592
642
  TId,
643
+ TSearchSchemaInput,
593
644
  TSearchSchema,
645
+ TSearchSchemaUsed,
646
+ TFullSearchSchemaInput,
594
647
  TFullSearchSchema,
595
648
  TParams,
596
649
  TAllParams,
@@ -652,11 +705,13 @@ export class Route<
652
705
  }
653
706
  }
654
707
 
655
- export type AnyRootRoute = RootRoute<any, any, any, any>
708
+ export type AnyRootRoute = RootRoute<any, any, any, any, any, any, any>
656
709
 
657
710
  export function rootRouteWithContext<TRouterContext extends {}>() {
658
711
  return <
712
+ TSearchSchemaInput extends Record<string, any> = {},
659
713
  TSearchSchema extends Record<string, any> = {},
714
+ TSearchSchemaUsed extends Record<string, any> = {},
660
715
  TRouteContext extends RouteContext = RouteContext,
661
716
  TLoaderDeps extends Record<string, any> = {},
662
717
  TLoaderData extends any = unknown,
@@ -666,7 +721,10 @@ export function rootRouteWithContext<TRouterContext extends {}>() {
666
721
  AnyRoute, // TParentRoute
667
722
  RootRouteId, // TCustomId
668
723
  '', // TPath
724
+ TSearchSchemaInput, // TSearchSchemaInput
669
725
  TSearchSchema, // TSearchSchema
726
+ TSearchSchemaUsed,
727
+ TSearchSchemaUsed, //TFullSearchSchemaInput
670
728
  TSearchSchema, // TFullSearchSchema
671
729
  {}, // TParams
672
730
  {}, // TAllParams
@@ -682,13 +740,21 @@ export function rootRouteWithContext<TRouterContext extends {}>() {
682
740
  | 'parseParams'
683
741
  | 'stringifyParams'
684
742
  >,
685
- ): RootRoute<TSearchSchema, TRouteContext, TRouterContext> => {
743
+ ): RootRoute<
744
+ TSearchSchemaInput,
745
+ TSearchSchema,
746
+ TSearchSchemaUsed,
747
+ TRouteContext,
748
+ TRouterContext
749
+ > => {
686
750
  return new RootRoute(options) as any
687
751
  }
688
752
  }
689
753
 
690
754
  export class RootRoute<
755
+ TSearchSchemaInput extends Record<string, any> = {},
691
756
  TSearchSchema extends Record<string, any> = {},
757
+ TSearchSchemaUsed extends Record<string, any> = {},
692
758
  TRouteContext extends RouteContext = RouteContext,
693
759
  TRouterContext extends {} = {},
694
760
  TLoaderDeps extends Record<string, any> = {},
@@ -699,7 +765,10 @@ export class RootRoute<
699
765
  '/', // TFullPath
700
766
  string, // TCustomId
701
767
  RootRouteId, // TId
768
+ TSearchSchemaInput, // TSearchSchemaInput
702
769
  TSearchSchema, // TSearchSchema
770
+ TSearchSchemaUsed,
771
+ TSearchSchemaUsed, // TFullSearchSchemaInput
703
772
  TSearchSchema, // TFullSearchSchema
704
773
  {}, // TParams
705
774
  {}, // TAllParams
@@ -717,7 +786,10 @@ export class RootRoute<
717
786
  AnyRoute, // TParentRoute
718
787
  RootRouteId, // TCustomId
719
788
  '', // TPath
789
+ TSearchSchemaInput, // TSearchSchemaInput
720
790
  TSearchSchema, // TSearchSchema
791
+ TSearchSchemaUsed,
792
+ TSearchSchemaUsed, // TFullSearchSchemaInput
721
793
  TSearchSchema, // TFullSearchSchema
722
794
  {}, // TParams
723
795
  {}, // TAllParams
@@ -821,7 +893,14 @@ export type ErrorRouteComponent = RouteComponent<ErrorRouteProps>
821
893
 
822
894
  export class NotFoundRoute<
823
895
  TParentRoute extends AnyRootRoute,
896
+ TSearchSchemaInput extends Record<string, any> = {},
824
897
  TSearchSchema extends RouteConstraints['TSearchSchema'] = {},
898
+ TSearchSchemaUsed extends RouteConstraints['TSearchSchema'] = {},
899
+ TFullSearchSchemaInput extends
900
+ RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchemaInput<
901
+ TParentRoute,
902
+ TSearchSchemaUsed
903
+ >,
825
904
  TFullSearchSchema extends
826
905
  RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<
827
906
  TParentRoute,
@@ -844,7 +923,10 @@ export class NotFoundRoute<
844
923
  '/404',
845
924
  '404',
846
925
  '404',
926
+ TSearchSchemaInput,
847
927
  TSearchSchema,
928
+ TSearchSchemaUsed,
929
+ TFullSearchSchemaInput,
848
930
  TFullSearchSchema,
849
931
  {},
850
932
  {},
@@ -862,7 +944,10 @@ export class NotFoundRoute<
862
944
  TParentRoute,
863
945
  string,
864
946
  string,
947
+ TSearchSchemaInput,
865
948
  TSearchSchema,
949
+ TSearchSchemaUsed,
950
+ TFullSearchSchemaInput,
866
951
  TFullSearchSchema,
867
952
  {},
868
953
  {},
package/src/routeInfo.ts CHANGED
@@ -21,6 +21,9 @@ export type ParseRouteChildren<TRouteTree extends AnyRoute> =
21
21
  any,
22
22
  any,
23
23
  any,
24
+ any,
25
+ any,
26
+ any,
24
27
  infer TChildren,
25
28
  any
26
29
  >