@tanstack/router-core 0.0.1-beta.193 → 0.0.1-beta.194

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.
@@ -56,18 +56,18 @@ export type MetaOptions = keyof PickRequired<RouteMeta> extends never ? {
56
56
  meta: RouteMeta;
57
57
  };
58
58
  export type AnyRouteProps = RegisteredRouteProps<any, any, any, any, any>;
59
- export type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = AnyPathParams, TAllParams extends AnyPathParams = TParams, TParentContext extends Record<string, any> = AnyContext, TAllParentContext extends Record<string, any> = AnyContext, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext> = BaseRouteOptions<TParentRoute, TCustomId, TPath, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext> & UpdatableRouteOptions<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
59
+ export type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = AnyPathParams, TAllParams extends AnyPathParams = TParams, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext> = BaseRouteOptions<TParentRoute, TCustomId, TPath, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext> & UpdatableRouteOptions<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
60
60
  export type ParamsFallback<TPath extends string, TParams> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams;
61
- export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = {}, TAllParams = ParamsFallback<TPath, TParams>, TParentContext extends Record<string, any> = AnyContext, TAllParentContext extends Record<string, any> = AnyContext, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext> = RoutePathOptions<TCustomId, TPath> & {
61
+ export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = {}, TAllParams = ParamsFallback<TPath, TParams>, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext> = RoutePathOptions<TCustomId, TPath> & {
62
62
  getParentRoute: () => TParentRoute;
63
63
  validateSearch?: SearchSchemaValidator<TSearchSchema>;
64
64
  loaderContext?: (opts: {
65
65
  search: TFullSearchSchema;
66
66
  }) => TLoaderContext;
67
67
  } & (keyof PickRequired<RouteContext> extends never ? {
68
- beforeLoad?: BeforeLoadFn<TParentRoute, TAllParams, TAllParentContext, NoInfer<TLoaderContext>, TRouteContext>;
68
+ beforeLoad?: BeforeLoadFn<TParentRoute, TAllParams, NoInfer<TLoaderContext>, TRouteContext>;
69
69
  } : {
70
- beforeLoad: BeforeLoadFn<TParentRoute, TAllParams, TAllParentContext, NoInfer<TLoaderContext>, TRouteContext>;
70
+ beforeLoad: BeforeLoadFn<TParentRoute, TAllParams, NoInfer<TLoaderContext>, TRouteContext>;
71
71
  }) & {
72
72
  loader?: LoaderFn<TLoader, TAllParams, NoInfer<TLoaderContext>, NoInfer<TAllContext>, NoInfer<TRouteContext>>;
73
73
  } & ([TLoader] extends [never] ? {
@@ -79,11 +79,11 @@ export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId
79
79
  stringifyParams?: never;
80
80
  parseParams?: never;
81
81
  });
82
- type BeforeLoadFn<TParentRoute, TAllParams, TParentContext, TLoaderContext, TRouteContext> = (opts: {
82
+ type BeforeLoadFn<TParentRoute extends AnyRoute, TAllParams, TLoaderContext, TRouteContext> = (opts: {
83
83
  abortController: AbortController;
84
84
  preload: boolean;
85
85
  params: TAllParams;
86
- context: Expand<TParentContext & TLoaderContext>;
86
+ context: Expand<TParentRoute['types']['context'] & TLoaderContext>;
87
87
  }) => Promise<TRouteContext> | TRouteContext | void;
88
88
  export type UpdatableRouteOptions<TLoader, TSearchSchema extends Record<string, any>, TFullSearchSchema extends Record<string, any>, TAllParams extends AnyPathParams, TRouteContext extends Record<string, any>, TAllContext extends Record<string, any>> = MetaOptions & {
89
89
  caseSensitive?: boolean;
@@ -135,7 +135,7 @@ export type InferFullSearchSchema<TRoute> = TRoute extends {
135
135
  };
136
136
  } ? TFullSearchSchema : {};
137
137
  export type ResolveFullSearchSchema<TParentRoute, TSearchSchema> = Expand<DeepMerge<InferFullSearchSchema<TParentRoute>, TSearchSchema>>;
138
- export interface AnyRoute extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
138
+ export interface AnyRoute extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
139
139
  }
140
140
  export type MergeFromFromParent<T, U> = IsAny<T, U, T & U>;
141
141
  export type UseLoaderResult<T> = T;
@@ -158,14 +158,17 @@ export type RouteConstraints = {
158
158
  TParams: Record<string, any>;
159
159
  TAllParams: Record<string, any>;
160
160
  TParentContext: AnyContext;
161
- TAllParentContext: AnyContext;
162
161
  TRouteContext: RouteContext;
163
162
  TAllContext: AnyContext;
164
163
  TRouterContext: AnyContext;
165
164
  TChildren: unknown;
166
165
  TRouteTree: AnyRoute;
167
166
  };
168
- export declare class Route<TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute, TPath extends RouteConstraints['TPath'] = '/', TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>, TCustomId extends RouteConstraints['TCustomId'] = string, TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>, TLoaderContext extends RouteConstraints['TLoaderContext'] = AnyContext, TLoader = unknown, TSearchSchema extends RouteConstraints['TSearchSchema'] = {}, TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams extends RouteConstraints['TParams'] = Expand<Record<ParsePathParams<TPath>, string>>, TAllParams extends RouteConstraints['TAllParams'] = ResolveAllParams<TParentRoute, TParams>, TParentContext extends RouteConstraints['TParentContext'] = TParentRoute['types']['routeContext'], TAllParentContext extends RouteConstraints['TAllParentContext'] = TParentRoute['types']['context'], TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext, TAllContext extends RouteConstraints['TAllContext'] = MergeFromFromParent<TParentRoute['types']['context'], TRouteContext>, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> {
167
+ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute, TPath extends RouteConstraints['TPath'] = '/', TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>, TCustomId extends RouteConstraints['TCustomId'] = string, TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>, TLoaderContext extends RouteConstraints['TLoaderContext'] = {}, TLoader = unknown, TSearchSchema extends RouteConstraints['TSearchSchema'] = {}, TFullSearchSchema extends RouteConstraints['TFullSearchSchema'] = ResolveFullSearchSchema<TParentRoute, TSearchSchema>, TParams extends RouteConstraints['TParams'] = Expand<Record<ParsePathParams<TPath>, string>>, TAllParams extends RouteConstraints['TAllParams'] = ResolveAllParams<TParentRoute, TParams>, TRouteContext extends RouteConstraints['TRouteContext'] = RouteContext, TAllContext extends RouteConstraints['TAllContext'] = Expand<DeepMergeAll<[
168
+ IsAny<TParentRoute['types']['context'], {}>,
169
+ TLoaderContext,
170
+ TRouteContext
171
+ ]>>, TRouterContext extends RouteConstraints['TRouterContext'] = AnyContext, TChildren extends RouteConstraints['TChildren'] = unknown, TRouteTree extends RouteConstraints['TRouteTree'] = AnyRoute> {
169
172
  types: {
170
173
  parentRoute: TParentRoute;
171
174
  path: TPath;
@@ -178,8 +181,6 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
178
181
  fullSearchSchema: TFullSearchSchema;
179
182
  params: TParams;
180
183
  allParams: TAllParams;
181
- parentContext: TParentContext;
182
- allParentContext: TAllParentContext;
183
184
  routeContext: TRouteContext;
184
185
  context: TAllContext;
185
186
  children: TChildren;
@@ -187,7 +188,7 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
187
188
  routerContext: TRouterContext;
188
189
  };
189
190
  isRoot: TParentRoute extends Route<any> ? true : false;
190
- options: RouteOptions<TParentRoute, TCustomId, TPath, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext>;
191
+ options: RouteOptions<TParentRoute, TCustomId, TPath, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext>;
191
192
  parentRoute: TParentRoute;
192
193
  id: TId;
193
194
  path: TPath;
@@ -197,22 +198,47 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
197
198
  originalIndex?: number;
198
199
  router?: AnyRouter;
199
200
  rank: number;
200
- constructor(options: RouteOptions<TParentRoute, TCustomId, TPath, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext> & UpdatableRouteOptions<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>);
201
+ constructor(options: RouteOptions<TParentRoute, TCustomId, TPath, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext> & UpdatableRouteOptions<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>);
201
202
  init: (opts: {
202
203
  originalIndex: number;
203
204
  router: AnyRouter;
204
205
  }) => void;
205
- addChildren: <TNewChildren extends AnyRoute[]>(children: TNewChildren) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext, TRouterContext, TNewChildren, TRouteTree>;
206
+ addChildren: <TNewChildren extends AnyRoute[]>(children: TNewChildren) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TLoaderContext, TLoader, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext, TRouterContext, TNewChildren, TRouteTree>;
206
207
  update: (options: UpdatableRouteOptions<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>) => this;
207
208
  static __onInit: (route: any) => void;
208
209
  }
209
210
  export type AnyRootRoute = RootRoute<any, any, any, any>;
210
211
  export declare class RouterContext<TRouterContext extends {}> {
211
212
  constructor();
212
- createRootRoute: <TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, TSearchSchema extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext>(options?: Omit<RouteOptions<AnyRoute, "__root__", "", TLoaderContext, TLoader, TSearchSchema, TSearchSchema, {}, {}, TRouterContext, TRouterContext, TRouteContext, IsAny<TRouterContext, TRouteContext, TRouterContext & TRouteContext>>, "id" | "path" | "getParentRoute" | "stringifyParams" | "parseParams" | "caseSensitive"> | undefined) => RootRoute<TLoaderContext, TLoader, TSearchSchema, TRouteContext, TRouterContext>;
213
+ createRootRoute: <TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, TSearchSchema extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext>(options?: Omit<RouteOptions<AnyRoute, "__root__", "", TLoaderContext, TLoader, TSearchSchema, TSearchSchema, {}, {}, TRouteContext, DeepMerge<TRouterContext, DeepMerge<TLoaderContext, DeepMerge<TRouteContext, {}>>>>, "id" | "path" | "getParentRoute" | "stringifyParams" | "parseParams" | "caseSensitive"> | undefined) => RootRoute<TLoaderContext, TLoader, TSearchSchema, TRouteContext, TRouterContext>;
213
214
  }
214
- export declare class RootRoute<TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, TSearchSchema extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext, TRouterContext extends {} = {}> extends Route<any, '/', '/', string, RootRouteId, TLoaderContext, TLoader, TSearchSchema, TSearchSchema, {}, {}, TRouterContext, TRouterContext, TRouteContext, MergeFromFromParent<TRouterContext, TRouteContext>, TRouterContext, any, any> {
215
- constructor(options?: Omit<RouteOptions<AnyRoute, RootRouteId, '', TLoaderContext, TLoader, TSearchSchema, TSearchSchema, {}, {}, TRouterContext, TRouterContext, TRouteContext, MergeFromFromParent<TRouterContext, TRouteContext>>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams'>);
215
+ export declare class RootRoute<TLoaderContext extends Record<string, any> = AnyContext, TLoader = unknown, TSearchSchema extends Record<string, any> = {}, TRouteContext extends RouteContext = RouteContext, TRouterContext extends {} = {}> extends Route<any, // TParentRoute
216
+ '/', // TPath
217
+ '/', // TFullPath
218
+ string, // TCustomId
219
+ RootRouteId, // TId
220
+ TLoaderContext, // TLoaderContext
221
+ TLoader, // TLoader
222
+ TSearchSchema, // TSearchSchema
223
+ TSearchSchema, // TFullSearchSchema
224
+ {}, // TParams
225
+ {}, // TAllParams
226
+ TRouteContext, // TRouteContext
227
+ DeepMergeAll<[TRouterContext, TLoaderContext, TRouteContext]>, // TAllContext
228
+ TRouterContext, // TRouterContext
229
+ any, // TChildren
230
+ any> {
231
+ constructor(options?: Omit<RouteOptions<AnyRoute, // TParentRoute
232
+ RootRouteId, // TCustomId
233
+ '', // TPath
234
+ TLoaderContext, // TLoaderContext
235
+ TLoader, // TLoader
236
+ TSearchSchema, // TSearchSchema
237
+ TSearchSchema, // TFullSearchSchema
238
+ {}, // TParams
239
+ {}, // TAllParams
240
+ TRouteContext, // TRouteContext
241
+ DeepMergeAll<[TRouterContext, TLoaderContext, TRouteContext]>>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams'>);
216
242
  }
217
243
  export type ResolveFullPath<TParentRoute extends AnyRoute, TPath extends string, TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>> = TPrefixed extends RootRouteId ? '/' : TPrefixed;
218
244
  type RoutePrefix<TPrefix extends string, TPath extends string> = string extends TPath ? RootRouteId : TPath extends string ? TPrefix extends RootRouteId ? TPath extends '/' ? '/' : `/${TrimPath<TPath>}` : `${TPrefix}/${TPath}` extends '/' ? '/' : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}` : never;
@@ -1,7 +1,7 @@
1
1
  import { AnyRoute, Route } from './route';
2
2
  import { Expand, UnionToIntersection } from './utils';
3
3
  export type ParseRoute<TRouteTree extends AnyRoute> = TRouteTree | ParseRouteChildren<TRouteTree>;
4
- export type ParseRouteChildren<TRouteTree extends AnyRoute> = TRouteTree extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, infer TChildren, any> ? unknown extends TChildren ? never : TChildren extends AnyRoute[] ? {
4
+ export type ParseRouteChildren<TRouteTree extends AnyRoute> = TRouteTree extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, infer TChildren, any> ? unknown extends TChildren ? never : TChildren extends AnyRoute[] ? {
5
5
  [TId in TChildren[number]['id'] as string]: ParseRoute<TChildren[number]>;
6
6
  }[string] : never : never;
7
7
  export type RoutesById<TRouteTree extends AnyRoute> = {
@@ -1,5 +1,5 @@
1
1
  export type NoInfer<T> = [T][T extends any ? 0 : never];
2
- export type IsAny<T, Y, N> = 1 extends 0 & T ? Y : N;
2
+ export type IsAny<T, Y, N = T> = 1 extends 0 & T ? Y : N;
3
3
  export type IsAnyBoolean<T> = 1 extends 0 & T ? true : false;
4
4
  export type IsKnown<T, Y, N> = unknown extends T ? N : Y;
5
5
  export type PickAsRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
@@ -1344,7 +1344,7 @@
1344
1344
  };
1345
1345
  this.setRouteMatch(match.id, s => ({
1346
1346
  ...s,
1347
- context
1347
+ context: replaceEqualDeep(s.context, context)
1348
1348
  }));
1349
1349
  } catch (err) {
1350
1350
  handleError(err, 'BEFORE_LOAD');