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