@tanstack/router-core 0.0.1-beta.2 → 0.0.1-beta.23
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/build/cjs/packages/router-core/src/index.js +1 -1
- package/build/cjs/packages/router-core/src/path.js +1 -4
- package/build/cjs/packages/router-core/src/path.js.map +1 -1
- package/build/cjs/packages/router-core/src/qss.js +1 -0
- package/build/cjs/packages/router-core/src/qss.js.map +1 -1
- package/build/cjs/packages/router-core/src/route.js +9 -23
- package/build/cjs/packages/router-core/src/route.js.map +1 -1
- package/build/cjs/packages/router-core/src/routeConfig.js.map +1 -1
- package/build/cjs/packages/router-core/src/routeMatch.js +75 -121
- package/build/cjs/packages/router-core/src/routeMatch.js.map +1 -1
- package/build/cjs/packages/router-core/src/router.js +183 -89
- package/build/cjs/packages/router-core/src/router.js.map +1 -1
- package/build/cjs/packages/router-core/src/utils.js +7 -6
- package/build/cjs/packages/router-core/src/utils.js.map +1 -1
- package/build/esm/index.js +271 -237
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +139 -152
- package/build/types/index.d.ts +199 -191
- package/build/umd/index.development.js +271 -237
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -1
- package/src/frameworks.ts +1 -2
- package/src/index.ts +0 -1
- package/src/link.ts +3 -1
- package/src/path.ts +0 -4
- package/src/qss.ts +1 -0
- package/src/route.ts +10 -26
- package/src/routeConfig.ts +30 -21
- package/src/routeInfo.ts +13 -3
- package/src/routeMatch.ts +94 -156
- package/src/router.ts +269 -109
- package/src/utils.ts +12 -5
package/build/types/index.d.ts
CHANGED
|
@@ -14,36 +14,94 @@ export { default as invariant } from 'tiny-invariant';
|
|
|
14
14
|
|
|
15
15
|
interface FrameworkGenerics {
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
type GetFrameworkGeneric<U> = U extends keyof FrameworkGenerics ? FrameworkGenerics[U] : any;
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
interface RouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> extends Route<TAllRouteInfo, TRouteInfo> {
|
|
20
|
+
matchId: string;
|
|
21
|
+
pathname: string;
|
|
22
|
+
params: TRouteInfo['allParams'];
|
|
23
|
+
parentMatch?: RouteMatch;
|
|
24
|
+
childMatches: RouteMatch[];
|
|
25
|
+
routeSearch: TRouteInfo['searchSchema'];
|
|
26
|
+
search: TRouteInfo['fullSearchSchema'];
|
|
27
|
+
status: 'idle' | 'loading' | 'success' | 'error';
|
|
28
|
+
updatedAt?: number;
|
|
29
|
+
error?: unknown;
|
|
30
|
+
isInvalid: boolean;
|
|
31
|
+
getIsInvalid: () => boolean;
|
|
32
|
+
loaderData: TRouteInfo['loaderData'];
|
|
33
|
+
routeLoaderData: TRouteInfo['routeLoaderData'];
|
|
34
|
+
isFetching: boolean;
|
|
35
|
+
invalidAt: number;
|
|
36
|
+
__: {
|
|
37
|
+
component?: GetFrameworkGeneric<'Component'>;
|
|
38
|
+
errorComponent?: GetFrameworkGeneric<'Component'>;
|
|
39
|
+
pendingComponent?: GetFrameworkGeneric<'Component'>;
|
|
40
|
+
loadPromise?: Promise<void>;
|
|
41
|
+
componentsPromise?: Promise<void>;
|
|
42
|
+
dataPromise?: Promise<TRouteInfo['routeLoaderData']>;
|
|
43
|
+
onExit?: void | ((matchContext: {
|
|
44
|
+
params: TRouteInfo['allParams'];
|
|
45
|
+
search: TRouteInfo['fullSearchSchema'];
|
|
46
|
+
}) => void);
|
|
47
|
+
abortController: AbortController;
|
|
48
|
+
latestId: string;
|
|
49
|
+
validate: () => void;
|
|
50
|
+
notify: () => void;
|
|
51
|
+
resolve: () => void;
|
|
52
|
+
};
|
|
53
|
+
cancel: () => void;
|
|
54
|
+
load: (loaderOpts?: {
|
|
55
|
+
preload: true;
|
|
56
|
+
maxAge: number;
|
|
57
|
+
gcMaxAge: number;
|
|
58
|
+
} | {
|
|
59
|
+
preload?: false;
|
|
60
|
+
maxAge?: never;
|
|
61
|
+
gcMaxAge?: never;
|
|
62
|
+
}) => Promise<TRouteInfo['routeLoaderData']>;
|
|
63
|
+
fetch: (opts?: {
|
|
64
|
+
maxAge?: number;
|
|
65
|
+
}) => Promise<TRouteInfo['routeLoaderData']>;
|
|
66
|
+
invalidate: () => void;
|
|
67
|
+
hasLoaders: () => boolean;
|
|
68
|
+
}
|
|
69
|
+
declare function createRouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo>(router: Router<any, any>, route: Route<TAllRouteInfo, TRouteInfo>, opts: {
|
|
70
|
+
parentMatch?: RouteMatch<any, any>;
|
|
71
|
+
matchId: string;
|
|
72
|
+
params: TRouteInfo['allParams'];
|
|
73
|
+
pathname: string;
|
|
74
|
+
}): RouteMatch<TAllRouteInfo, TRouteInfo>;
|
|
75
|
+
|
|
76
|
+
type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
77
|
+
type IsAny<T, Y, N> = 1 extends 0 & T ? Y : N;
|
|
78
|
+
type IsAnyBoolean<T> = 1 extends 0 & T ? true : false;
|
|
79
|
+
type IsKnown<T, Y, N> = unknown extends T ? N : Y;
|
|
80
|
+
type PickAsRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
81
|
+
type PickAsPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
82
|
+
type PickUnsafe<T, K> = K extends keyof T ? Pick<T, K> : never;
|
|
83
|
+
type PickExtra<T, K> = Expand<{
|
|
27
84
|
[TKey in keyof K as string extends TKey ? never : TKey extends keyof T ? never : TKey]: K[TKey];
|
|
28
85
|
}>;
|
|
29
|
-
|
|
86
|
+
type PickRequired<T> = {
|
|
30
87
|
[K in keyof T as undefined extends T[K] ? never : K]: T[K];
|
|
31
88
|
};
|
|
32
|
-
|
|
89
|
+
type Expand<T> = T extends object ? T extends infer O ? {
|
|
33
90
|
[K in keyof O]: O[K];
|
|
34
91
|
} : never : T;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
92
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => any ? I : never;
|
|
93
|
+
type Values<O> = O[ValueKeys<O>];
|
|
94
|
+
type ValueKeys<O> = Extract<keyof O, PropertyKey>;
|
|
95
|
+
type DeepAwaited<T> = T extends Promise<infer A> ? DeepAwaited<A> : T extends Record<infer A, Promise<infer B>> ? {
|
|
38
96
|
[K in A]: DeepAwaited<B>;
|
|
39
97
|
} : T;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
98
|
+
type PathParamMask<TRoutePath extends string> = TRoutePath extends `${infer L}/:${infer C}/${infer R}` ? PathParamMask<`${L}/${string}/${R}`> : TRoutePath extends `${infer L}/:${infer C}` ? PathParamMask<`${L}/${string}`> : TRoutePath;
|
|
99
|
+
type Timeout = ReturnType<typeof setTimeout>;
|
|
100
|
+
type Updater<TPrevious, TResult = TPrevious> = TResult | ((prev?: TPrevious) => TResult);
|
|
101
|
+
type PickExtract<T, U> = {
|
|
44
102
|
[K in keyof T as T[K] extends U ? K : never]: T[K];
|
|
45
103
|
};
|
|
46
|
-
|
|
104
|
+
type PickExclude<T, U> = {
|
|
47
105
|
[K in keyof T as T[K] extends U ? never : K]: T[K];
|
|
48
106
|
};
|
|
49
107
|
/**
|
|
@@ -55,6 +113,7 @@ declare function replaceEqualDeep(prev: any, next: any): any;
|
|
|
55
113
|
declare function last<T>(arr: T[]): T | undefined;
|
|
56
114
|
declare function warning(cond: any, message: string): cond is true;
|
|
57
115
|
declare function functionalUpdate<TResult>(updater: Updater<TResult>, previous: TResult): TResult;
|
|
116
|
+
declare function pick<T, K extends keyof T>(parent: T, keys: K[]): Pick<T, K>;
|
|
58
117
|
|
|
59
118
|
interface LocationState {
|
|
60
119
|
}
|
|
@@ -73,9 +132,9 @@ interface FromLocation {
|
|
|
73
132
|
key?: string;
|
|
74
133
|
hash?: string;
|
|
75
134
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
135
|
+
type SearchSerializer = (searchObj: Record<string, any>) => string;
|
|
136
|
+
type SearchParser = (searchStr: string) => Record<string, any>;
|
|
137
|
+
type FilterRoutesFn = <TRoute extends Route<any, RouteInfo>>(routeConfigs: TRoute[]) => TRoute[];
|
|
79
138
|
interface RouterOptions<TRouteConfig extends AnyRouteConfig> {
|
|
80
139
|
history?: BrowserHistory | MemoryHistory | HashHistory;
|
|
81
140
|
stringifySearch?: SearchSerializer;
|
|
@@ -85,35 +144,36 @@ interface RouterOptions<TRouteConfig extends AnyRouteConfig> {
|
|
|
85
144
|
defaultPreloadMaxAge?: number;
|
|
86
145
|
defaultPreloadGcMaxAge?: number;
|
|
87
146
|
defaultPreloadDelay?: number;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
defaultCatchElement?: GetFrameworkGeneric<'Element'>;
|
|
92
|
-
defaultPendingElement?: GetFrameworkGeneric<'Element'>;
|
|
93
|
-
defaultPendingMs?: number;
|
|
94
|
-
defaultPendingMinMs?: number;
|
|
147
|
+
defaultComponent?: GetFrameworkGeneric<'Component'>;
|
|
148
|
+
defaultErrorComponent?: GetFrameworkGeneric<'Component'>;
|
|
149
|
+
defaultPendingComponent?: GetFrameworkGeneric<'Component'>;
|
|
95
150
|
defaultLoaderMaxAge?: number;
|
|
96
151
|
defaultLoaderGcMaxAge?: number;
|
|
97
152
|
caseSensitive?: boolean;
|
|
98
153
|
routeConfig?: TRouteConfig;
|
|
99
154
|
basepath?: string;
|
|
155
|
+
useServerData?: boolean;
|
|
100
156
|
createRouter?: (router: Router<any, any>) => void;
|
|
101
157
|
createRoute?: (opts: {
|
|
102
158
|
route: AnyRoute;
|
|
103
159
|
router: Router<any, any>;
|
|
104
160
|
}) => void;
|
|
105
|
-
|
|
161
|
+
loadComponent?: (component: GetFrameworkGeneric<'Component'>) => Promise<GetFrameworkGeneric<'Component'>>;
|
|
106
162
|
}
|
|
107
163
|
interface Action<TPayload = unknown, TResponse = unknown> {
|
|
108
|
-
submit: (submission?: TPayload
|
|
164
|
+
submit: (submission?: TPayload, actionOpts?: {
|
|
165
|
+
invalidate?: boolean;
|
|
166
|
+
multi?: boolean;
|
|
167
|
+
}) => Promise<TResponse>;
|
|
109
168
|
current?: ActionState<TPayload, TResponse>;
|
|
110
169
|
latest?: ActionState<TPayload, TResponse>;
|
|
111
|
-
|
|
170
|
+
submissions: ActionState<TPayload, TResponse>[];
|
|
112
171
|
}
|
|
113
172
|
interface ActionState<TPayload = unknown, TResponse = unknown> {
|
|
114
173
|
submittedAt: number;
|
|
115
174
|
status: 'idle' | 'pending' | 'success' | 'error';
|
|
116
175
|
submission: TPayload;
|
|
176
|
+
isMulti: boolean;
|
|
117
177
|
data?: TResponse;
|
|
118
178
|
error?: unknown;
|
|
119
179
|
}
|
|
@@ -136,18 +196,15 @@ interface Loader<TFullSearchSchema extends AnySearchSchema = {}, TAllParams exte
|
|
|
136
196
|
latest?: LoaderState<TFullSearchSchema, TAllParams>;
|
|
137
197
|
pending: LoaderState<TFullSearchSchema, TAllParams>[];
|
|
138
198
|
}
|
|
139
|
-
interface LoaderState<TFullSearchSchema =
|
|
199
|
+
interface LoaderState<TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> {
|
|
140
200
|
loadedAt: number;
|
|
141
201
|
loaderContext: LoaderContext<TFullSearchSchema, TAllParams>;
|
|
142
202
|
}
|
|
143
|
-
interface RouterState {
|
|
203
|
+
interface RouterState<TSearchObj extends AnySearchSchema = {}, TState extends LocationState = LocationState> {
|
|
144
204
|
status: 'idle' | 'loading';
|
|
145
|
-
location: Location
|
|
205
|
+
location: Location<TSearchObj, TState>;
|
|
146
206
|
matches: RouteMatch[];
|
|
147
207
|
lastUpdated: number;
|
|
148
|
-
loaderData: unknown;
|
|
149
|
-
currentAction?: ActionState;
|
|
150
|
-
latestAction?: ActionState;
|
|
151
208
|
actions: Record<string, Action>;
|
|
152
209
|
loaders: Record<string, Loader>;
|
|
153
210
|
pending?: PendingState;
|
|
@@ -158,20 +215,21 @@ interface PendingState {
|
|
|
158
215
|
location: Location;
|
|
159
216
|
matches: RouteMatch[];
|
|
160
217
|
}
|
|
161
|
-
|
|
162
|
-
|
|
218
|
+
type Listener = (router: Router<any, any>) => void;
|
|
219
|
+
type ListenerFn = () => void;
|
|
163
220
|
interface BuildNextOptions {
|
|
164
221
|
to?: string | number | null;
|
|
165
222
|
params?: true | Updater<Record<string, any>>;
|
|
166
223
|
search?: true | Updater<unknown>;
|
|
167
224
|
hash?: true | Updater<string>;
|
|
225
|
+
state?: LocationState;
|
|
168
226
|
key?: string;
|
|
169
227
|
from?: string;
|
|
170
228
|
fromCurrent?: boolean;
|
|
171
229
|
__preSearchFilters?: SearchFilter<any>[];
|
|
172
230
|
__postSearchFilters?: SearchFilter<any>[];
|
|
173
231
|
}
|
|
174
|
-
|
|
232
|
+
type MatchCacheEntry = {
|
|
175
233
|
gc: number;
|
|
176
234
|
match: RouteMatch;
|
|
177
235
|
};
|
|
@@ -186,33 +244,41 @@ interface MatchRouteOptions {
|
|
|
186
244
|
pending: boolean;
|
|
187
245
|
caseSensitive?: boolean;
|
|
188
246
|
}
|
|
247
|
+
interface DehydratedRouterState extends Pick<RouterState, 'status' | 'location' | 'lastUpdated'> {
|
|
248
|
+
matches: DehydratedRouteMatch[];
|
|
249
|
+
}
|
|
250
|
+
interface DehydratedRouteMatch extends Pick<RouteMatch<any, any>, 'matchId' | 'status' | 'routeLoaderData' | 'loaderData' | 'isInvalid' | 'invalidAt'> {
|
|
251
|
+
}
|
|
252
|
+
interface RouterContext {
|
|
253
|
+
}
|
|
189
254
|
interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>> {
|
|
255
|
+
types: {
|
|
256
|
+
RouteConfig: TRouteConfig;
|
|
257
|
+
AllRouteInfo: TAllRouteInfo;
|
|
258
|
+
};
|
|
190
259
|
history: BrowserHistory | MemoryHistory | HashHistory;
|
|
191
260
|
options: PickAsRequired<RouterOptions<TRouteConfig>, 'stringifySearch' | 'parseSearch'>;
|
|
192
261
|
basepath: string;
|
|
193
|
-
|
|
262
|
+
context: RouterContext;
|
|
194
263
|
listeners: Listener[];
|
|
195
|
-
location: Location
|
|
264
|
+
location: Location<TAllRouteInfo['fullSearchSchema']>;
|
|
196
265
|
navigateTimeout?: Timeout;
|
|
197
266
|
nextAction?: 'push' | 'replace';
|
|
198
|
-
state: RouterState
|
|
267
|
+
state: RouterState<TAllRouteInfo['fullSearchSchema']>;
|
|
199
268
|
routeTree: Route<TAllRouteInfo, RouteInfo>;
|
|
200
269
|
routesById: RoutesById<TAllRouteInfo>;
|
|
201
270
|
navigationPromise: Promise<void>;
|
|
202
|
-
removeActionQueue: {
|
|
203
|
-
action: Action;
|
|
204
|
-
actionState: ActionState;
|
|
205
|
-
}[];
|
|
206
271
|
startedLoadingAt: number;
|
|
207
272
|
resolveNavigation: () => void;
|
|
208
273
|
subscribe: (listener: Listener) => () => void;
|
|
274
|
+
reset: () => void;
|
|
209
275
|
notify: () => void;
|
|
210
276
|
mount: () => () => void;
|
|
211
277
|
onFocus: () => void;
|
|
212
278
|
update: <TRouteConfig extends RouteConfig = RouteConfig>(opts?: RouterOptions<TRouteConfig>) => Router<TRouteConfig>;
|
|
213
279
|
buildNext: (opts: BuildNextOptions) => Location;
|
|
214
280
|
cancelMatches: () => void;
|
|
215
|
-
|
|
281
|
+
load: (next?: Location) => Promise<void>;
|
|
216
282
|
matchCache: Record<string, MatchCacheEntry>;
|
|
217
283
|
cleanMatchCache: () => void;
|
|
218
284
|
getRoute: <TId extends keyof TAllRouteInfo['routeInfoById']>(id: TId) => Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][TId]>;
|
|
@@ -225,8 +291,6 @@ interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInf
|
|
|
225
291
|
strictParseParams?: boolean;
|
|
226
292
|
}) => RouteMatch[];
|
|
227
293
|
loadMatches: (resolvedMatches: RouteMatch[], loaderOpts?: {
|
|
228
|
-
withPending?: boolean;
|
|
229
|
-
} & ({
|
|
230
294
|
preload: true;
|
|
231
295
|
maxAge: number;
|
|
232
296
|
gcMaxAge: number;
|
|
@@ -234,13 +298,16 @@ interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInf
|
|
|
234
298
|
preload?: false;
|
|
235
299
|
maxAge?: never;
|
|
236
300
|
gcMaxAge?: never;
|
|
237
|
-
})
|
|
301
|
+
}) => Promise<void>;
|
|
302
|
+
loadMatchData: (routeMatch: RouteMatch<any, any>) => Promise<Record<string, unknown>>;
|
|
238
303
|
invalidateRoute: (opts: MatchLocation) => void;
|
|
239
304
|
reload: () => Promise<void>;
|
|
240
305
|
resolvePath: (from: string, path: string) => string;
|
|
241
306
|
navigate: <TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'>(opts: NavigateOptionsAbsolute<TAllRouteInfo, TFrom, TTo>) => Promise<void>;
|
|
242
307
|
matchRoute: <TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'>(matchLocation: ToOptions<TAllRouteInfo, TFrom, TTo>, opts?: MatchRouteOptions) => boolean;
|
|
243
308
|
buildLink: <TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'>(opts: LinkOptions<TAllRouteInfo, TFrom, TTo>) => LinkInfo;
|
|
309
|
+
dehydrateState: () => DehydratedRouterState;
|
|
310
|
+
hydrateState: (state: DehydratedRouterState) => void;
|
|
244
311
|
__: {
|
|
245
312
|
buildRouteTree: (routeConfig: RouteConfig) => Route<TAllRouteInfo, AnyRouteInfo>;
|
|
246
313
|
parseLocation: (location: History['location'], previousLocation?: Location) => Location;
|
|
@@ -253,72 +320,6 @@ interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInf
|
|
|
253
320
|
}
|
|
254
321
|
declare function createRouter<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>>(userOptions?: RouterOptions<TRouteConfig>): Router<TRouteConfig, TAllRouteInfo>;
|
|
255
322
|
|
|
256
|
-
interface RouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> extends Route<TAllRouteInfo, TRouteInfo> {
|
|
257
|
-
matchId: string;
|
|
258
|
-
pathname: string;
|
|
259
|
-
params: TRouteInfo['params'];
|
|
260
|
-
parentMatch?: RouteMatch;
|
|
261
|
-
childMatches: RouteMatch[];
|
|
262
|
-
routeSearch: TRouteInfo['searchSchema'];
|
|
263
|
-
search: TRouteInfo['fullSearchSchema'];
|
|
264
|
-
status: 'idle' | 'loading' | 'success' | 'error';
|
|
265
|
-
updatedAt?: number;
|
|
266
|
-
error?: unknown;
|
|
267
|
-
isInvalid: boolean;
|
|
268
|
-
getIsInvalid: () => boolean;
|
|
269
|
-
loaderData: TRouteInfo['loaderData'];
|
|
270
|
-
routeLoaderData: TRouteInfo['routeLoaderData'];
|
|
271
|
-
isFetching: boolean;
|
|
272
|
-
isPending: boolean;
|
|
273
|
-
invalidAt: number;
|
|
274
|
-
__: {
|
|
275
|
-
element?: GetFrameworkGeneric<'Element'>;
|
|
276
|
-
errorElement?: GetFrameworkGeneric<'Element'>;
|
|
277
|
-
catchElement?: GetFrameworkGeneric<'Element'>;
|
|
278
|
-
pendingElement?: GetFrameworkGeneric<'Element'>;
|
|
279
|
-
loadPromise?: Promise<void>;
|
|
280
|
-
loaderPromise?: Promise<void>;
|
|
281
|
-
elementsPromise?: Promise<void>;
|
|
282
|
-
dataPromise?: Promise<void>;
|
|
283
|
-
pendingTimeout?: Timeout;
|
|
284
|
-
pendingMinTimeout?: Timeout;
|
|
285
|
-
pendingMinPromise?: Promise<void>;
|
|
286
|
-
onExit?: void | ((matchContext: {
|
|
287
|
-
params: TRouteInfo['allParams'];
|
|
288
|
-
search: TRouteInfo['fullSearchSchema'];
|
|
289
|
-
}) => void);
|
|
290
|
-
abortController: AbortController;
|
|
291
|
-
latestId: string;
|
|
292
|
-
validate: () => void;
|
|
293
|
-
startPending: () => void;
|
|
294
|
-
cancelPending: () => void;
|
|
295
|
-
notify: () => void;
|
|
296
|
-
resolve: () => void;
|
|
297
|
-
};
|
|
298
|
-
cancel: () => void;
|
|
299
|
-
load: (loaderOpts?: {
|
|
300
|
-
withPending?: boolean;
|
|
301
|
-
} & ({
|
|
302
|
-
preload: true;
|
|
303
|
-
maxAge: number;
|
|
304
|
-
gcMaxAge: number;
|
|
305
|
-
} | {
|
|
306
|
-
preload?: false;
|
|
307
|
-
maxAge?: never;
|
|
308
|
-
gcMaxAge?: never;
|
|
309
|
-
})) => Promise<TRouteInfo['routeLoaderData']>;
|
|
310
|
-
fetch: (opts?: {
|
|
311
|
-
maxAge?: number;
|
|
312
|
-
}) => Promise<TRouteInfo['routeLoaderData']>;
|
|
313
|
-
invalidate: () => void;
|
|
314
|
-
hasLoaders: () => boolean;
|
|
315
|
-
}
|
|
316
|
-
declare function createRouteMatch<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo>(router: Router<any, any>, route: Route<TAllRouteInfo, TRouteInfo>, opts: {
|
|
317
|
-
matchId: string;
|
|
318
|
-
params: TRouteInfo['allParams'];
|
|
319
|
-
pathname: string;
|
|
320
|
-
}): RouteMatch<TAllRouteInfo, TRouteInfo>;
|
|
321
|
-
|
|
322
323
|
interface AnyRoute extends Route<any, any> {
|
|
323
324
|
}
|
|
324
325
|
interface Route<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> {
|
|
@@ -337,7 +338,6 @@ interface Route<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRo
|
|
|
337
338
|
loader: unknown extends TRouteInfo['routeLoaderData'] ? Action<LoaderContext<TRouteInfo['fullSearchSchema'], TRouteInfo['allParams']>, TRouteInfo['routeLoaderData']> | undefined : Loader<TRouteInfo['fullSearchSchema'], TRouteInfo['allParams'], TRouteInfo['routeLoaderData']>;
|
|
338
339
|
}
|
|
339
340
|
declare function createRoute<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo>(routeConfig: RouteConfig, options: TRouteInfo['options'], parent: undefined | Route<TAllRouteInfo, any>, router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo>): Route<TAllRouteInfo, TRouteInfo>;
|
|
340
|
-
declare function cascadeLoaderData(matches: RouteMatch<any, any>[]): void;
|
|
341
341
|
|
|
342
342
|
interface AnyAllRouteInfo {
|
|
343
343
|
routeConfig: AnyRouteConfig;
|
|
@@ -346,6 +346,7 @@ interface AnyAllRouteInfo {
|
|
|
346
346
|
routeInfoByFullPath: Record<string, AnyRouteInfo>;
|
|
347
347
|
routeIds: any;
|
|
348
348
|
routePaths: any;
|
|
349
|
+
fullSearchSchema: Record<string, any>;
|
|
349
350
|
}
|
|
350
351
|
interface DefaultAllRouteInfo {
|
|
351
352
|
routeConfig: RouteConfig;
|
|
@@ -354,20 +355,25 @@ interface DefaultAllRouteInfo {
|
|
|
354
355
|
routeInfoByFullPath: Record<string, RouteInfo>;
|
|
355
356
|
routeIds: string;
|
|
356
357
|
routePaths: string;
|
|
358
|
+
fullSearchSchema: AnySearchSchema;
|
|
357
359
|
}
|
|
358
360
|
interface AllRouteInfo<TRouteConfig extends AnyRouteConfig = RouteConfig> extends RoutesInfoInner<TRouteConfig, ParseRouteConfig<TRouteConfig>> {
|
|
359
361
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
+
type ParseRouteConfig<TRouteConfig = AnyRouteConfig> = TRouteConfig extends AnyRouteConfig ? RouteConfigRoute<TRouteConfig> | ParseRouteChildren<TRouteConfig> : never;
|
|
363
|
+
type ParseRouteChildren<TRouteConfig> = TRouteConfig extends AnyRouteConfigWithChildren<infer TChildren> ? unknown extends TChildren ? never : TChildren extends AnyRouteConfig[] ? Values<{
|
|
362
364
|
[TId in TChildren[number]['id']]: ParseRouteChild<TChildren[number], TId>;
|
|
363
365
|
}> : never : never;
|
|
364
|
-
|
|
366
|
+
type ParseRouteChild<TRouteConfig, TId> = TRouteConfig & {
|
|
365
367
|
id: TId;
|
|
366
368
|
} extends AnyRouteConfig ? ParseRouteConfig<TRouteConfig> : never;
|
|
367
|
-
|
|
368
|
-
interface RoutesInfoInner<TRouteConfig extends AnyRouteConfig, TRouteInfo extends RouteInfo<string, string, any, any, any, any, any, any, any, any, any, any, any, any> = RouteInfo, TRouteInfoById = {
|
|
369
|
+
type RouteConfigRoute<TRouteConfig> = TRouteConfig extends RouteConfig<infer TId, infer TRouteId, infer TPath, infer TFullPath, infer TParentLoaderData, infer TRouteLoaderData, infer TLoaderData, infer TActionPayload, infer TActionResponse, infer TParentSearchSchema, infer TSearchSchema, infer TFullSearchSchema, infer TParentParams, infer TParams, infer TAllParams, any> ? string extends TRouteId ? never : RouteInfo<TId, TRouteId, TPath, TFullPath, TParentLoaderData, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams> : never;
|
|
370
|
+
interface RoutesInfoInner<TRouteConfig extends AnyRouteConfig, TRouteInfo extends RouteInfo<string, string, any, any, any, any, any, any, any, any, any, any, any, any, any> = RouteInfo, TRouteInfoById = {
|
|
371
|
+
'/': TRouteInfo;
|
|
372
|
+
} & {
|
|
369
373
|
[TInfo in TRouteInfo as TInfo['id']]: TInfo;
|
|
370
374
|
}, TRouteInfoByFullPath = {
|
|
375
|
+
'/': TRouteInfo;
|
|
376
|
+
} & {
|
|
371
377
|
[TInfo in TRouteInfo as TInfo['fullPath'] extends RootRouteId ? never : string extends TInfo['fullPath'] ? never : TInfo['fullPath']]: TInfo;
|
|
372
378
|
}> {
|
|
373
379
|
routeConfig: TRouteConfig;
|
|
@@ -376,14 +382,16 @@ interface RoutesInfoInner<TRouteConfig extends AnyRouteConfig, TRouteInfo extend
|
|
|
376
382
|
routeInfoByFullPath: TRouteInfoByFullPath;
|
|
377
383
|
routeIds: keyof TRouteInfoById;
|
|
378
384
|
routePaths: keyof TRouteInfoByFullPath;
|
|
385
|
+
fullSearchSchema: Partial<UnionToIntersection<TRouteInfo['fullSearchSchema']>>;
|
|
379
386
|
}
|
|
380
|
-
interface AnyRouteInfo extends RouteInfo<any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
|
|
387
|
+
interface AnyRouteInfo extends RouteInfo<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
|
|
381
388
|
}
|
|
382
|
-
interface RouteInfo<TId extends string = string, TRouteId extends string = string, TPath extends string = string, TFullPath extends string = string, TRouteLoaderData extends AnyLoaderData = {}, TLoaderData extends AnyLoaderData = {}, TActionPayload = unknown, TActionResponse = unknown, TParentSearchSchema extends {} = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = {}, TParentParams extends AnyPathParams = {}, TParams extends Record<ParsePathParams<TPath>, unknown> = Record<ParsePathParams<TPath>, string>, TAllParams extends AnyPathParams = {}> {
|
|
389
|
+
interface RouteInfo<TId extends string = string, TRouteId extends string = string, TPath extends string = string, TFullPath extends string = string, TParentRouteLoaderData extends AnyLoaderData = {}, TRouteLoaderData extends AnyLoaderData = {}, TLoaderData extends AnyLoaderData = {}, TActionPayload = unknown, TActionResponse = unknown, TParentSearchSchema extends {} = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = {}, TParentParams extends AnyPathParams = {}, TParams extends Record<ParsePathParams<TPath>, unknown> = Record<ParsePathParams<TPath>, string>, TAllParams extends AnyPathParams = {}> {
|
|
383
390
|
id: TId;
|
|
384
391
|
routeId: TRouteId;
|
|
385
392
|
path: TPath;
|
|
386
393
|
fullPath: TFullPath;
|
|
394
|
+
parentRouteLoaderData: TParentRouteLoaderData;
|
|
387
395
|
routeLoaderData: TRouteLoaderData;
|
|
388
396
|
loaderData: TLoaderData;
|
|
389
397
|
actionPayload: TActionPayload;
|
|
@@ -393,42 +401,42 @@ interface RouteInfo<TId extends string = string, TRouteId extends string = strin
|
|
|
393
401
|
parentParams: TParentParams;
|
|
394
402
|
params: TParams;
|
|
395
403
|
allParams: TAllParams;
|
|
396
|
-
options: RouteOptions<TRouteId, TPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams>;
|
|
404
|
+
options: RouteOptions<TRouteId, TPath, TParentRouteLoaderData, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams>;
|
|
397
405
|
}
|
|
398
|
-
|
|
406
|
+
type RoutesById<TAllRouteInfo extends AnyAllRouteInfo> = {
|
|
399
407
|
[K in keyof TAllRouteInfo['routeInfoById']]: Route<TAllRouteInfo, TAllRouteInfo['routeInfoById'][K]>;
|
|
400
408
|
};
|
|
401
|
-
|
|
402
|
-
|
|
409
|
+
type RouteInfoById<TAllRouteInfo extends AnyAllRouteInfo, TId> = TId extends keyof TAllRouteInfo['routeInfoById'] ? IsAny<TAllRouteInfo['routeInfoById'][TId]['id'], RouteInfo, TAllRouteInfo['routeInfoById'][TId]> : never;
|
|
410
|
+
type RouteInfoByPath<TAllRouteInfo extends AnyAllRouteInfo, TPath> = TPath extends keyof TAllRouteInfo['routeInfoByFullPath'] ? IsAny<TAllRouteInfo['routeInfoByFullPath'][TPath]['id'], RouteInfo, TAllRouteInfo['routeInfoByFullPath'][TPath]> : never;
|
|
403
411
|
|
|
404
412
|
declare const rootRouteId: "__root__";
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
413
|
+
type RootRouteId = typeof rootRouteId;
|
|
414
|
+
type AnyLoaderData = {};
|
|
415
|
+
type AnyPathParams = {};
|
|
416
|
+
type AnySearchSchema = {};
|
|
409
417
|
interface RouteMeta {
|
|
410
418
|
}
|
|
411
|
-
|
|
412
|
-
|
|
419
|
+
type SearchSchemaValidator<TReturn, TParentSchema> = SearchSchemaValidatorObj<TReturn, TParentSchema> | SearchSchemaValidatorFn<TReturn, TParentSchema>;
|
|
420
|
+
type SearchSchemaValidatorObj<TReturn, TParentSchema> = {
|
|
413
421
|
parse?: SearchSchemaValidatorFn<TReturn, TParentSchema>;
|
|
414
422
|
};
|
|
415
|
-
|
|
423
|
+
type SearchSchemaValidatorFn<TReturn, TParentSchema> = (searchObj: Record<string, unknown>) => {} extends TParentSchema ? TReturn : keyof TReturn extends keyof TParentSchema ? {
|
|
416
424
|
error: 'Top level search params cannot be redefined by child routes!';
|
|
417
425
|
keys: keyof TReturn & keyof TParentSchema;
|
|
418
426
|
} : TReturn;
|
|
419
|
-
|
|
420
|
-
|
|
427
|
+
type DefinedPathParamWarning = 'Path params cannot be redefined by child routes!';
|
|
428
|
+
type ParentParams<TParentParams> = AnyPathParams extends TParentParams ? {} : {
|
|
421
429
|
[Key in keyof TParentParams]?: DefinedPathParamWarning;
|
|
422
430
|
};
|
|
423
|
-
|
|
431
|
+
type LoaderFn<TRouteLoaderData extends AnyLoaderData = {}, TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> = (loaderContext: LoaderContext<TFullSearchSchema, TAllParams>) => Promise<TRouteLoaderData>;
|
|
424
432
|
interface LoaderContext<TFullSearchSchema extends AnySearchSchema = {}, TAllParams extends AnyPathParams = {}> {
|
|
425
433
|
params: TAllParams;
|
|
426
434
|
search: TFullSearchSchema;
|
|
427
435
|
signal?: AbortSignal;
|
|
428
436
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
437
|
+
type ActionFn<TActionPayload = unknown, TActionResponse = unknown> = (submission: TActionPayload) => TActionResponse | Promise<TActionResponse>;
|
|
438
|
+
type UnloaderFn<TPath extends string> = (routeMatch: RouteMatch<any, RouteInfo<string, TPath>>) => void;
|
|
439
|
+
type RouteOptions<TRouteId extends string = string, TPath extends string = string, TParentRouteLoaderData extends AnyLoaderData = {}, TRouteLoaderData extends AnyLoaderData = {}, TLoaderData extends AnyLoaderData = {}, TActionPayload = unknown, TActionResponse = unknown, TParentSearchSchema extends {} = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = TSearchSchema, TParentParams extends AnyPathParams = {}, TParams extends Record<ParsePathParams<TPath>, unknown> = Record<ParsePathParams<TPath>, string>, TAllParams extends AnyPathParams = {}> = ({
|
|
432
440
|
path: TPath;
|
|
433
441
|
} | {
|
|
434
442
|
id: TRouteId;
|
|
@@ -437,18 +445,17 @@ declare type RouteOptions<TRouteId extends string = string, TPath extends string
|
|
|
437
445
|
validateSearch?: SearchSchemaValidator<TSearchSchema, TParentSearchSchema>;
|
|
438
446
|
preSearchFilters?: SearchFilter<TFullSearchSchema>[];
|
|
439
447
|
postSearchFilters?: SearchFilter<TFullSearchSchema>[];
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
errorElement?: GetFrameworkGeneric<'SyncOrAsyncElement'>;
|
|
444
|
-
catchElement?: GetFrameworkGeneric<'SyncOrAsyncElement'>;
|
|
445
|
-
pendingElement?: GetFrameworkGeneric<'SyncOrAsyncElement'>;
|
|
448
|
+
component?: GetFrameworkGeneric<'Component'>;
|
|
449
|
+
errorComponent?: GetFrameworkGeneric<'Component'>;
|
|
450
|
+
pendingComponent?: GetFrameworkGeneric<'Component'>;
|
|
446
451
|
loader?: LoaderFn<TRouteLoaderData, TFullSearchSchema, TAllParams>;
|
|
447
452
|
loaderMaxAge?: number;
|
|
448
453
|
loaderGcMaxAge?: number;
|
|
449
454
|
action?: ActionFn<TActionPayload, TActionResponse>;
|
|
450
|
-
|
|
451
|
-
|
|
455
|
+
beforeLoad?: (opts: {
|
|
456
|
+
context: RouterContext;
|
|
457
|
+
}) => Promise<void> | void;
|
|
458
|
+
onLoaded?: (matchContext: {
|
|
452
459
|
params: TAllParams;
|
|
453
460
|
search: TFullSearchSchema;
|
|
454
461
|
}) => void | undefined | ((match: {
|
|
@@ -467,39 +474,39 @@ declare type RouteOptions<TRouteId extends string = string, TPath extends string
|
|
|
467
474
|
parseParams: (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams;
|
|
468
475
|
stringifyParams: (params: TParams) => Record<ParsePathParams<TPath>, string>;
|
|
469
476
|
}) & (PickUnsafe<TParentParams, ParsePathParams<TPath>> extends never ? {} : 'Cannot redefined path params in child routes!');
|
|
470
|
-
|
|
471
|
-
interface RouteConfig<TId extends string = string, TRouteId extends string = string, TPath extends string = string, TFullPath extends string = string, TRouteLoaderData extends AnyLoaderData = AnyLoaderData, TLoaderData extends AnyLoaderData = AnyLoaderData, TActionPayload = unknown, TActionResponse = unknown, TParentSearchSchema extends {} = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = {}, TParentParams extends AnyPathParams = {}, TParams extends Record<ParsePathParams<TPath>, unknown> = Record<ParsePathParams<TPath>, string>, TAllParams extends AnyPathParams = {}, TKnownChildren = unknown> {
|
|
477
|
+
type SearchFilter<T, U = T> = (prev: T) => U;
|
|
478
|
+
interface RouteConfig<TId extends string = string, TRouteId extends string = string, TPath extends string = string, TFullPath extends string = string, TParentRouteLoaderData extends AnyLoaderData = AnyLoaderData, TRouteLoaderData extends AnyLoaderData = AnyLoaderData, TLoaderData extends AnyLoaderData = AnyLoaderData, TActionPayload = unknown, TActionResponse = unknown, TParentSearchSchema extends {} = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = {}, TParentParams extends AnyPathParams = {}, TParams extends Record<ParsePathParams<TPath>, unknown> = Record<ParsePathParams<TPath>, string>, TAllParams extends AnyPathParams = {}, TKnownChildren = unknown> {
|
|
472
479
|
id: TId;
|
|
473
480
|
routeId: TRouteId;
|
|
474
481
|
path: NoInfer<TPath>;
|
|
475
482
|
fullPath: TFullPath;
|
|
476
|
-
options: RouteOptions<TRouteId, TPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams>;
|
|
483
|
+
options: RouteOptions<TRouteId, TPath, TParentRouteLoaderData, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams>;
|
|
477
484
|
children?: TKnownChildren;
|
|
478
485
|
addChildren: IsAny<TId, any, <TNewChildren extends any>(children: TNewChildren extends AnyRouteConfig[] ? TNewChildren : {
|
|
479
486
|
error: 'Invalid route detected';
|
|
480
487
|
route: TNewChildren;
|
|
481
|
-
}) => RouteConfig<TId, TRouteId, TPath, TFullPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams, TNewChildren>>;
|
|
482
|
-
createChildren: IsAny<TId, any, <TNewChildren extends any>(cb: (createChildRoute: CreateRouteConfigFn<false, TId, TFullPath, TLoaderData, TFullSearchSchema, TAllParams>) => TNewChildren extends AnyRouteConfig[] ? TNewChildren : {
|
|
488
|
+
}) => RouteConfig<TId, TRouteId, TPath, TFullPath, TParentRouteLoaderData, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams, TNewChildren>>;
|
|
489
|
+
createChildren: IsAny<TId, any, <TNewChildren extends any>(cb: (createChildRoute: CreateRouteConfigFn<false, TId, TFullPath, TRouteLoaderData, TLoaderData, TFullSearchSchema, TAllParams>) => TNewChildren extends AnyRouteConfig[] ? TNewChildren : {
|
|
483
490
|
error: 'Invalid route detected';
|
|
484
491
|
route: TNewChildren;
|
|
485
|
-
}) => RouteConfig<TId, TRouteId, TPath, TFullPath, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams, TNewChildren>>;
|
|
486
|
-
createRoute: CreateRouteConfigFn<false, TId, TFullPath, TLoaderData, TFullSearchSchema, TAllParams>;
|
|
492
|
+
}) => RouteConfig<TId, TRouteId, TPath, TFullPath, TParentRouteLoaderData, TRouteLoaderData, TLoaderData, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParentParams, TParams, TAllParams, TNewChildren>>;
|
|
493
|
+
createRoute: CreateRouteConfigFn<false, TId, TFullPath, TRouteLoaderData, TLoaderData, TFullSearchSchema, TAllParams>;
|
|
487
494
|
}
|
|
488
|
-
|
|
495
|
+
type CreateRouteConfigFn<TIsRoot extends boolean = false, TParentId extends string = string, TParentPath extends string = string, TParentRouteLoaderData extends AnyLoaderData = {}, TParentLoaderData extends AnyLoaderData = {}, TParentSearchSchema extends AnySearchSchema = {}, TParentParams extends AnyPathParams = {}> = <TRouteId extends string, TPath extends string, TRouteLoaderData extends AnyLoaderData, TActionPayload, TActionResponse, TSearchSchema extends AnySearchSchema = AnySearchSchema, TParams extends Record<ParsePathParams<TPath>, unknown> = Record<ParsePathParams<TPath>, string>, TAllParams extends AnyPathParams extends TParams ? Record<ParsePathParams<TPath>, string> : NoInfer<TParams> = AnyPathParams extends TParams ? Record<ParsePathParams<TPath>, string> : NoInfer<TParams>, TKnownChildren extends RouteConfig[] = RouteConfig[], TResolvedId extends string = string extends TRouteId ? string extends TPath ? string : TPath : TRouteId>(options?: TIsRoot extends true ? Omit<RouteOptions<TRouteId, TPath, TParentRouteLoaderData, TRouteLoaderData, Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>>, 'path'> & {
|
|
489
496
|
path?: never;
|
|
490
|
-
} : RouteOptions<TRouteId, TPath, TRouteLoaderData, Expand<
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
interface AnyRouteConfig extends RouteConfig<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
|
|
497
|
+
} : RouteOptions<TRouteId, TPath, TParentRouteLoaderData, TRouteLoaderData, Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>>, children?: TKnownChildren, isRoot?: boolean, parentId?: string, parentPath?: string) => RouteConfig<RoutePrefix<TParentId, TResolvedId>, TResolvedId, TPath, string extends TPath ? '' : RoutePath<RoutePrefix<TParentPath, TPath>>, TParentRouteLoaderData, TRouteLoaderData, Expand<TParentLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>, TActionPayload, TActionResponse, TParentSearchSchema, TSearchSchema, Expand<TParentSearchSchema & TSearchSchema>, TParentParams, TParams, Expand<TParentParams & TAllParams>, TKnownChildren>;
|
|
498
|
+
type RoutePath<T extends string> = T extends RootRouteId ? '/' : TrimPathRight<`${T}`>;
|
|
499
|
+
type RoutePrefix<TPrefix extends string, TId extends string> = string extends TId ? RootRouteId : TId extends string ? `${TPrefix}/${TId}` extends '/' ? '/' : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TId>}`>}` : never;
|
|
500
|
+
interface AnyRouteConfig extends RouteConfig<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
|
|
494
501
|
}
|
|
495
|
-
interface AnyRouteConfigWithChildren<TChildren> extends RouteConfig<any, any, any, any, any, any, any, any, any, any, any, any, any, any, TChildren> {
|
|
502
|
+
interface AnyRouteConfigWithChildren<TChildren> extends RouteConfig<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, TChildren> {
|
|
496
503
|
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
504
|
+
type TrimPath<T extends string> = '' extends T ? '' : TrimPathRight<TrimPathLeft<T>>;
|
|
505
|
+
type TrimPathLeft<T extends string> = T extends `${RootRouteId}/${infer U}` ? TrimPathLeft<U> : T extends `/${infer U}` ? TrimPathLeft<U> : T;
|
|
506
|
+
type TrimPathRight<T extends string> = T extends '/' ? '/' : T extends `${infer U}/` ? TrimPathRight<U> : T;
|
|
500
507
|
declare const createRouteConfig: CreateRouteConfigFn<true>;
|
|
501
508
|
|
|
502
|
-
|
|
509
|
+
type LinkInfo = {
|
|
503
510
|
type: 'external';
|
|
504
511
|
href: string;
|
|
505
512
|
} | {
|
|
@@ -512,12 +519,12 @@ declare type LinkInfo = {
|
|
|
512
519
|
isActive: boolean;
|
|
513
520
|
disabled?: boolean;
|
|
514
521
|
};
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
522
|
+
type StartsWith<A, B> = A extends `${B extends string ? B : never}${infer _}` ? true : false;
|
|
523
|
+
type CleanPath<T extends string> = T extends `${infer L}//${infer R}` ? CleanPath<`${CleanPath<L>}/${CleanPath<R>}`> : T extends `${infer L}//` ? `${CleanPath<L>}/` : T extends `//${infer L}` ? `/${CleanPath<L>}` : T;
|
|
524
|
+
type Split<S, TIncludeTrailingSlash = true> = S extends unknown ? string extends S ? string[] : S extends string ? CleanPath<S> extends '' ? [] : TIncludeTrailingSlash extends true ? CleanPath<S> extends `${infer T}/` ? [...Split<T>, '/'] : CleanPath<S> extends `/${infer U}` ? Split<U> : CleanPath<S> extends `${infer T}/${infer U}` ? [...Split<T>, ...Split<U>] : [S] : CleanPath<S> extends `${infer T}/${infer U}` ? [...Split<T>, ...Split<U>] : S extends string ? [S] : never : never : never;
|
|
525
|
+
type ParsePathParams<T extends string> = Split<T>[number] extends infer U ? U extends `:${infer V}` ? V : never : never;
|
|
526
|
+
type Join<T> = T extends [] ? '' : T extends [infer L extends string] ? L : T extends [infer L extends string, ...infer Tail extends [...string[]]] ? CleanPath<`${L}/${Join<Tail>}`> : never;
|
|
527
|
+
type RelativeToPathAutoComplete<AllPaths extends string, TFrom extends string, TTo extends string, SplitPaths extends string[] = Split<AllPaths, false>> = TTo extends `..${infer _}` ? SplitPaths extends [
|
|
521
528
|
...Split<ResolveRelativePath<TFrom, TTo>, false>,
|
|
522
529
|
...infer TToRest
|
|
523
530
|
] ? `${CleanPath<Join<[
|
|
@@ -528,39 +535,40 @@ declare type RelativeToPathAutoComplete<AllPaths extends string, TFrom extends s
|
|
|
528
535
|
...Split<RestTTo, false>,
|
|
529
536
|
...infer RestPath
|
|
530
537
|
] ? `${TTo}${Join<RestPath>}` : never : './' | '../' | AllPaths;
|
|
531
|
-
|
|
538
|
+
type NavigateOptionsAbsolute<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = ToOptions<TAllRouteInfo, TFrom, TTo> & {
|
|
532
539
|
replace?: boolean;
|
|
533
540
|
};
|
|
534
|
-
|
|
541
|
+
type ToOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.', TResolvedTo = ResolveRelativePath<TFrom, NoInfer<TTo>>> = {
|
|
535
542
|
to?: ToPathOption<TAllRouteInfo, TFrom, TTo>;
|
|
536
543
|
hash?: Updater<string>;
|
|
544
|
+
state?: LocationState;
|
|
537
545
|
from?: TFrom;
|
|
538
546
|
} & CheckPath<TAllRouteInfo, NoInfer<TResolvedTo>, {}> & SearchParamOptions<TAllRouteInfo, TFrom, TResolvedTo> & PathParamOptions<TAllRouteInfo, TFrom, TResolvedTo>;
|
|
539
|
-
|
|
547
|
+
type SearchParamOptions<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo, TFromSchema = RouteInfoByPath<TAllRouteInfo, TFrom>['fullSearchSchema'], TToSchema = RouteInfoByPath<TAllRouteInfo, TTo>['fullSearchSchema']> = StartsWith<TFrom, TTo> extends true ? {
|
|
540
548
|
search?: SearchReducer<TFromSchema, TToSchema>;
|
|
541
549
|
} : keyof PickRequired<TToSchema> extends never ? {
|
|
542
550
|
search?: SearchReducer<TFromSchema, TToSchema>;
|
|
543
551
|
} : {
|
|
544
552
|
search: SearchReducer<TFromSchema, TToSchema>;
|
|
545
553
|
};
|
|
546
|
-
|
|
554
|
+
type SearchReducer<TFrom, TTo> = {
|
|
547
555
|
[TKey in keyof TTo]: TTo[TKey];
|
|
548
556
|
} | ((current: TFrom) => TTo);
|
|
549
|
-
|
|
557
|
+
type PathParamOptions<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo, TFromParams = RouteInfoByPath<TAllRouteInfo, TFrom>['allParams'], TToParams = RouteInfoByPath<TAllRouteInfo, TTo>['allParams']> = StartsWith<TFrom, TTo> extends true ? {
|
|
550
558
|
params?: ParamsReducer<TFromParams, TToParams>;
|
|
551
559
|
} : AnyPathParams extends TToParams ? {
|
|
552
560
|
params?: ParamsReducer<TFromParams, Record<string, never>>;
|
|
553
561
|
} : {
|
|
554
562
|
params: ParamsReducer<TFromParams, TToParams>;
|
|
555
563
|
};
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
564
|
+
type ParamsReducer<TFrom, TTo> = TTo | ((current: TFrom) => TTo);
|
|
565
|
+
type ToPathOption<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = TTo | RelativeToPathAutoComplete<TAllRouteInfo['routePaths'], NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>;
|
|
566
|
+
type ToIdOption<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = TTo | RelativeToPathAutoComplete<TAllRouteInfo['routeIds'], NoInfer<TFrom> extends string ? NoInfer<TFrom> : '', NoInfer<TTo> & string>;
|
|
559
567
|
interface ActiveOptions {
|
|
560
568
|
exact?: boolean;
|
|
561
569
|
includeHash?: boolean;
|
|
562
570
|
}
|
|
563
|
-
|
|
571
|
+
type LinkOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TFrom extends ValidFromPath<TAllRouteInfo> = '/', TTo extends string = '.'> = NavigateOptionsAbsolute<TAllRouteInfo, TFrom, TTo> & {
|
|
564
572
|
target?: HTMLAnchorElement['target'];
|
|
565
573
|
activeOptions?: ActiveOptions;
|
|
566
574
|
preload?: false | 'intent';
|
|
@@ -569,22 +577,22 @@ declare type LinkOptions<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRoute
|
|
|
569
577
|
preloadDelay?: number;
|
|
570
578
|
disabled?: boolean;
|
|
571
579
|
};
|
|
572
|
-
|
|
580
|
+
type CheckRelativePath<TAllRouteInfo extends AnyAllRouteInfo, TFrom, TTo> = TTo extends string ? TFrom extends string ? ResolveRelativePath<TFrom, TTo> extends TAllRouteInfo['routePaths'] ? {} : {
|
|
573
581
|
Error: `${TFrom} + ${TTo} resolves to ${ResolveRelativePath<TFrom, TTo>}, which is not a valid route path.`;
|
|
574
582
|
'Valid Route Paths': TAllRouteInfo['routePaths'];
|
|
575
583
|
} : {} : {};
|
|
576
|
-
|
|
577
|
-
|
|
584
|
+
type CheckPath<TAllRouteInfo extends AnyAllRouteInfo, TPath, TPass> = Exclude<TPath, TAllRouteInfo['routePaths']> extends never ? TPass : CheckPathError<TAllRouteInfo, Exclude<TPath, TAllRouteInfo['routePaths']>>;
|
|
585
|
+
type CheckPathError<TAllRouteInfo extends AnyAllRouteInfo, TInvalids> = Expand<{
|
|
578
586
|
Error: `${TInvalids extends string ? TInvalids : never} is not a valid route path.`;
|
|
579
587
|
'Valid Route Paths': TAllRouteInfo['routePaths'];
|
|
580
588
|
}>;
|
|
581
|
-
|
|
582
|
-
|
|
589
|
+
type CheckId<TAllRouteInfo extends AnyAllRouteInfo, TPath, TPass> = Exclude<TPath, TAllRouteInfo['routeIds']> extends never ? TPass : CheckIdError<TAllRouteInfo, Exclude<TPath, TAllRouteInfo['routeIds']>>;
|
|
590
|
+
type CheckIdError<TAllRouteInfo extends AnyAllRouteInfo, TInvalids> = Expand<{
|
|
583
591
|
Error: `${TInvalids extends string ? TInvalids : never} is not a valid route ID.`;
|
|
584
592
|
'Valid Route IDs': TAllRouteInfo['routeIds'];
|
|
585
593
|
}>;
|
|
586
|
-
|
|
587
|
-
|
|
594
|
+
type ResolveRelativePath<TFrom, TTo = '.'> = TFrom extends string ? TTo extends string ? TTo extends '.' ? TFrom : TTo extends `./` ? Join<[TFrom, '/']> : TTo extends `./${infer TRest}` ? ResolveRelativePath<TFrom, TRest> : TTo extends `/${infer TRest}` ? TTo : Split<TTo> extends ['..', ...infer ToRest] ? Split<TFrom> extends [...infer FromRest, infer FromTail] ? ToRest extends ['/'] ? Join<[...FromRest, '/']> : ResolveRelativePath<Join<FromRest>, Join<ToRest>> : never : Split<TTo> extends ['.', ...infer ToRest] ? ToRest extends ['/'] ? Join<[TFrom, '/']> : ResolveRelativePath<TFrom, Join<ToRest>> : CleanPath<Join<['/', ...Split<TFrom>, ...Split<TTo>]>> : never : never;
|
|
595
|
+
type ValidFromPath<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo> = undefined | (string extends TAllRouteInfo['routePaths'] ? string : TAllRouteInfo['routePaths']);
|
|
588
596
|
|
|
589
597
|
interface Segment {
|
|
590
598
|
type: 'pathname' | 'param' | 'wildcard';
|
|
@@ -609,4 +617,4 @@ declare const defaultStringifySearch: (search: Record<string, any>) => string;
|
|
|
609
617
|
declare function parseSearchWith(parser: (str: string) => any): (searchStr: string) => AnySearchSchema;
|
|
610
618
|
declare function stringifySearchWith(stringify: (search: any) => string): (search: Record<string, any>) => string;
|
|
611
619
|
|
|
612
|
-
export { Action, ActionFn, ActionState, AllRouteInfo, AnyAllRouteInfo, AnyLoaderData, AnyPathParams, AnyRoute, AnyRouteConfig, AnyRouteConfigWithChildren, AnyRouteInfo, AnySearchSchema, BuildNextOptions, CheckId, CheckIdError, CheckPath, CheckPathError, CheckRelativePath, DeepAwaited, DefaultAllRouteInfo, DefinedPathParamWarning, Expand, FilterRoutesFn, FrameworkGenerics, FromLocation, GetFrameworkGeneric, IsAny, IsAnyBoolean, IsKnown, LinkInfo, LinkOptions, ListenerFn, Loader, LoaderContext, LoaderFn, LoaderState, Location, LocationState, MatchCacheEntry, MatchLocation, MatchRouteOptions, NavigateOptionsAbsolute, NoInfer, ParentParams, ParsePathParams, ParseRouteConfig, PathParamMask, PendingState, PickAsPartial, PickAsRequired, PickExclude, PickExtra, PickExtract, PickRequired, PickUnsafe, RelativeToPathAutoComplete, ResolveRelativePath, RootRouteId, Route, RouteConfig, RouteConfigRoute, RouteInfo, RouteInfoById, RouteInfoByPath, RouteMatch, RouteMeta, RouteOptions, Router, RouterOptions, RouterState, RoutesById, RoutesInfoInner, SearchFilter, SearchParser, SearchSchemaValidator, SearchSchemaValidatorFn, SearchSchemaValidatorObj, SearchSerializer, Segment, Split, Timeout, ToIdOption, ToOptions, ToPathOption, UnloaderFn, Updater, ValidFromPath, ValueKeys, Values,
|
|
620
|
+
export { Action, ActionFn, ActionState, AllRouteInfo, AnyAllRouteInfo, AnyLoaderData, AnyPathParams, AnyRoute, AnyRouteConfig, AnyRouteConfigWithChildren, AnyRouteInfo, AnySearchSchema, BuildNextOptions, CheckId, CheckIdError, CheckPath, CheckPathError, CheckRelativePath, DeepAwaited, DefaultAllRouteInfo, DefinedPathParamWarning, Expand, FilterRoutesFn, FrameworkGenerics, FromLocation, GetFrameworkGeneric, IsAny, IsAnyBoolean, IsKnown, LinkInfo, LinkOptions, ListenerFn, Loader, LoaderContext, LoaderFn, LoaderState, Location, LocationState, MatchCacheEntry, MatchLocation, MatchRouteOptions, NavigateOptionsAbsolute, NoInfer, ParentParams, ParsePathParams, ParseRouteConfig, PathParamMask, PendingState, PickAsPartial, PickAsRequired, PickExclude, PickExtra, PickExtract, PickRequired, PickUnsafe, RelativeToPathAutoComplete, ResolveRelativePath, RootRouteId, Route, RouteConfig, RouteConfigRoute, RouteInfo, RouteInfoById, RouteInfoByPath, RouteMatch, RouteMeta, RouteOptions, Router, RouterContext, RouterOptions, RouterState, RoutesById, RoutesInfoInner, SearchFilter, SearchParser, SearchSchemaValidator, SearchSchemaValidatorFn, SearchSchemaValidatorObj, SearchSerializer, Segment, Split, Timeout, ToIdOption, ToOptions, ToPathOption, UnionToIntersection, UnloaderFn, Updater, ValidFromPath, ValueKeys, Values, cleanPath, createRoute, createRouteConfig, createRouteMatch, createRouter, decode, defaultParseSearch, defaultStringifySearch, encode, functionalUpdate, interpolatePath, joinPaths, last, matchByPath, matchPathname, parsePathname, parseSearchWith, pick, replaceEqualDeep, resolvePath, rootRouteId, stringifySearchWith, trimPath, trimPathLeft, trimPathRight, warning };
|