@tanstack/router-core 0.0.1-beta.9 → 1.97.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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/cjs/Matches.cjs +13 -0
- package/dist/cjs/Matches.cjs.map +1 -0
- package/dist/cjs/Matches.d.cts +28 -0
- package/dist/cjs/RouterProvider.d.cts +18 -0
- package/dist/cjs/defer.cjs +25 -0
- package/dist/cjs/defer.cjs.map +1 -0
- package/dist/cjs/defer.d.cts +20 -0
- package/dist/cjs/index.cjs +50 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +25 -0
- package/dist/cjs/link.cjs +5 -0
- package/dist/cjs/link.cjs.map +1 -0
- package/dist/cjs/link.d.cts +51 -0
- package/dist/cjs/location.d.cts +12 -0
- package/dist/cjs/manifest.d.cts +24 -0
- package/dist/cjs/path.cjs +289 -0
- package/dist/cjs/path.cjs.map +1 -0
- package/dist/cjs/path.d.cts +34 -0
- package/dist/cjs/qss.cjs +51 -0
- package/dist/cjs/qss.cjs.map +1 -0
- package/dist/cjs/qss.d.cts +27 -0
- package/dist/cjs/root.cjs +5 -0
- package/dist/cjs/root.cjs.map +1 -0
- package/dist/cjs/root.d.cts +2 -0
- package/dist/cjs/route.d.cts +148 -0
- package/dist/cjs/router.cjs +19 -0
- package/dist/cjs/router.cjs.map +1 -0
- package/dist/cjs/router.d.cts +31 -0
- package/dist/cjs/searchMiddleware.cjs +42 -0
- package/dist/cjs/searchMiddleware.cjs.map +1 -0
- package/dist/cjs/searchMiddleware.d.cts +5 -0
- package/dist/cjs/searchParams.cjs +61 -0
- package/dist/cjs/searchParams.cjs.map +1 -0
- package/dist/cjs/searchParams.d.cts +7 -0
- package/dist/cjs/serializer.d.cts +15 -0
- package/dist/cjs/structuralSharing.d.cts +4 -0
- package/dist/cjs/utils.cjs +155 -0
- package/dist/cjs/utils.cjs.map +1 -0
- package/dist/cjs/utils.d.cts +81 -0
- package/dist/cjs/validators.d.cts +51 -0
- package/dist/esm/Matches.d.ts +28 -0
- package/dist/esm/Matches.js +13 -0
- package/dist/esm/Matches.js.map +1 -0
- package/dist/esm/RouterProvider.d.ts +18 -0
- package/dist/esm/defer.d.ts +20 -0
- package/dist/esm/defer.js +25 -0
- package/dist/esm/defer.js.map +1 -0
- package/dist/esm/index.d.ts +25 -0
- package/dist/esm/index.js +50 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/link.d.ts +51 -0
- package/dist/esm/link.js +5 -0
- package/dist/esm/link.js.map +1 -0
- package/dist/esm/location.d.ts +12 -0
- package/dist/esm/manifest.d.ts +24 -0
- package/dist/esm/path.d.ts +34 -0
- package/dist/esm/path.js +289 -0
- package/dist/esm/path.js.map +1 -0
- package/dist/esm/qss.d.ts +27 -0
- package/dist/esm/qss.js +51 -0
- package/dist/esm/qss.js.map +1 -0
- package/dist/esm/root.d.ts +2 -0
- package/dist/esm/root.js +5 -0
- package/dist/esm/root.js.map +1 -0
- package/dist/esm/route.d.ts +148 -0
- package/dist/esm/router.d.ts +31 -0
- package/dist/esm/router.js +19 -0
- package/dist/esm/router.js.map +1 -0
- package/dist/esm/searchMiddleware.d.ts +5 -0
- package/dist/esm/searchMiddleware.js +42 -0
- package/dist/esm/searchMiddleware.js.map +1 -0
- package/dist/esm/searchParams.d.ts +7 -0
- package/dist/esm/searchParams.js +61 -0
- package/dist/esm/searchParams.js.map +1 -0
- package/dist/esm/serializer.d.ts +15 -0
- package/dist/esm/structuralSharing.d.ts +4 -0
- package/dist/esm/utils.d.ts +81 -0
- package/dist/esm/utils.js +155 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/esm/validators.d.ts +51 -0
- package/package.json +35 -32
- package/src/Matches.ts +94 -0
- package/src/RouterProvider.ts +20 -0
- package/src/defer.ts +52 -0
- package/src/index.ts +206 -19
- package/src/link.ts +122 -300
- package/src/location.ts +13 -0
- package/src/manifest.ts +32 -0
- package/src/path.ts +238 -47
- package/src/qss.ts +56 -19
- package/src/root.ts +2 -0
- package/src/route.ts +296 -223
- package/src/router.ts +34 -1281
- package/src/searchMiddleware.ts +54 -0
- package/src/searchParams.ts +43 -20
- package/src/serializer.ts +24 -0
- package/src/structuralSharing.ts +7 -0
- package/src/utils.ts +314 -75
- package/src/validators.ts +121 -0
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -33
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
- package/build/cjs/node_modules/history/index.js +0 -815
- package/build/cjs/node_modules/history/index.js.map +0 -1
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
- package/build/cjs/packages/router-core/src/index.js +0 -58
- package/build/cjs/packages/router-core/src/index.js.map +0 -1
- package/build/cjs/packages/router-core/src/path.js +0 -222
- package/build/cjs/packages/router-core/src/path.js.map +0 -1
- package/build/cjs/packages/router-core/src/qss.js +0 -71
- package/build/cjs/packages/router-core/src/qss.js.map +0 -1
- package/build/cjs/packages/router-core/src/route.js +0 -150
- package/build/cjs/packages/router-core/src/route.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeConfig.js +0 -69
- package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeMatch.js +0 -266
- package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
- package/build/cjs/packages/router-core/src/router.js +0 -822
- package/build/cjs/packages/router-core/src/router.js.map +0 -1
- package/build/cjs/packages/router-core/src/searchParams.js +0 -70
- package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
- package/build/cjs/packages/router-core/src/utils.js +0 -125
- package/build/cjs/packages/router-core/src/utils.js.map +0 -1
- package/build/esm/index.js +0 -2481
- package/build/esm/index.js.map +0 -1
- package/build/stats-html.html +0 -4034
- package/build/stats-react.json +0 -493
- package/build/types/index.d.ts +0 -618
- package/build/umd/index.development.js +0 -2514
- package/build/umd/index.development.js.map +0 -1
- package/build/umd/index.production.js +0 -12
- package/build/umd/index.production.js.map +0 -1
- package/src/frameworks.ts +0 -12
- package/src/routeConfig.ts +0 -495
- package/src/routeInfo.ts +0 -228
- package/src/routeMatch.ts +0 -374
package/src/routeConfig.ts
DELETED
|
@@ -1,495 +0,0 @@
|
|
|
1
|
-
import { GetFrameworkGeneric } from './frameworks'
|
|
2
|
-
import { ParsePathParams } from './link'
|
|
3
|
-
import { joinPaths, trimPath, trimPathRight } from './path'
|
|
4
|
-
import { RouteInfo } from './routeInfo'
|
|
5
|
-
import { RouteMatch } from './routeMatch'
|
|
6
|
-
import {
|
|
7
|
-
DeepAwaited,
|
|
8
|
-
Expand,
|
|
9
|
-
IsAny,
|
|
10
|
-
NoInfer,
|
|
11
|
-
PickUnsafe,
|
|
12
|
-
Values,
|
|
13
|
-
} from './utils'
|
|
14
|
-
|
|
15
|
-
export const rootRouteId = '__root__' as const
|
|
16
|
-
export type RootRouteId = typeof rootRouteId
|
|
17
|
-
|
|
18
|
-
export type AnyLoaderData = {}
|
|
19
|
-
export type AnyPathParams = {}
|
|
20
|
-
export type AnySearchSchema = {}
|
|
21
|
-
export interface RouteMeta {}
|
|
22
|
-
|
|
23
|
-
// The parse type here allows a zod schema to be passed directly to the validator
|
|
24
|
-
export type SearchSchemaValidator<TReturn, TParentSchema> =
|
|
25
|
-
| SearchSchemaValidatorObj<TReturn, TParentSchema>
|
|
26
|
-
| SearchSchemaValidatorFn<TReturn, TParentSchema>
|
|
27
|
-
|
|
28
|
-
export type SearchSchemaValidatorObj<TReturn, TParentSchema> = {
|
|
29
|
-
parse?: SearchSchemaValidatorFn<TReturn, TParentSchema>
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export type SearchSchemaValidatorFn<TReturn, TParentSchema> = (
|
|
33
|
-
searchObj: Record<string, unknown>,
|
|
34
|
-
) => {} extends TParentSchema
|
|
35
|
-
? TReturn
|
|
36
|
-
: keyof TReturn extends keyof TParentSchema
|
|
37
|
-
? {
|
|
38
|
-
error: 'Top level search params cannot be redefined by child routes!'
|
|
39
|
-
keys: keyof TReturn & keyof TParentSchema
|
|
40
|
-
}
|
|
41
|
-
: TReturn
|
|
42
|
-
|
|
43
|
-
export type DefinedPathParamWarning =
|
|
44
|
-
'Path params cannot be redefined by child routes!'
|
|
45
|
-
|
|
46
|
-
export type ParentParams<TParentParams> = AnyPathParams extends TParentParams
|
|
47
|
-
? {}
|
|
48
|
-
: {
|
|
49
|
-
[Key in keyof TParentParams]?: DefinedPathParamWarning
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export type LoaderFn<
|
|
53
|
-
TRouteLoaderData extends AnyLoaderData,
|
|
54
|
-
TFullSearchSchema extends AnySearchSchema = {},
|
|
55
|
-
TAllParams extends AnyPathParams = {},
|
|
56
|
-
> = (
|
|
57
|
-
loaderContext: LoaderContext<TFullSearchSchema, TAllParams>,
|
|
58
|
-
) => Promise<TRouteLoaderData>
|
|
59
|
-
|
|
60
|
-
export interface LoaderContext<
|
|
61
|
-
TFullSearchSchema extends AnySearchSchema = {},
|
|
62
|
-
TAllParams extends AnyPathParams = {},
|
|
63
|
-
> {
|
|
64
|
-
params: TAllParams
|
|
65
|
-
search: TFullSearchSchema
|
|
66
|
-
signal?: AbortSignal
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export type ActionFn<TActionPayload = unknown, TActionResponse = unknown> = (
|
|
70
|
-
submission: TActionPayload,
|
|
71
|
-
) => TActionResponse | Promise<TActionResponse>
|
|
72
|
-
|
|
73
|
-
export type UnloaderFn<TPath extends string> = (
|
|
74
|
-
routeMatch: RouteMatch<any, RouteInfo<string, TPath>>,
|
|
75
|
-
) => void
|
|
76
|
-
|
|
77
|
-
export type RouteOptions<
|
|
78
|
-
TRouteId extends string = string,
|
|
79
|
-
TPath extends string = string,
|
|
80
|
-
TRouteLoaderData extends AnyLoaderData = {},
|
|
81
|
-
TLoaderData extends AnyLoaderData = {},
|
|
82
|
-
TActionPayload = unknown,
|
|
83
|
-
TActionResponse = unknown,
|
|
84
|
-
TParentSearchSchema extends {} = {},
|
|
85
|
-
TSearchSchema extends AnySearchSchema = {},
|
|
86
|
-
TFullSearchSchema extends AnySearchSchema = TSearchSchema,
|
|
87
|
-
TParentParams extends AnyPathParams = {},
|
|
88
|
-
TParams extends Record<ParsePathParams<TPath>, unknown> = Record<
|
|
89
|
-
ParsePathParams<TPath>,
|
|
90
|
-
string
|
|
91
|
-
>,
|
|
92
|
-
TAllParams extends AnyPathParams = {},
|
|
93
|
-
> = (
|
|
94
|
-
| {
|
|
95
|
-
// The path to match (relative to the nearest parent `Route` component or root basepath)
|
|
96
|
-
path: TPath
|
|
97
|
-
}
|
|
98
|
-
| {
|
|
99
|
-
id: TRouteId
|
|
100
|
-
}
|
|
101
|
-
) & {
|
|
102
|
-
// If true, this route will be matched as case-sensitive
|
|
103
|
-
caseSensitive?: boolean
|
|
104
|
-
validateSearch?: SearchSchemaValidator<TSearchSchema, TParentSearchSchema>
|
|
105
|
-
// Filter functions that can manipulate search params *before* they are passed to links and navigate
|
|
106
|
-
// calls that match this route.
|
|
107
|
-
preSearchFilters?: SearchFilter<TFullSearchSchema>[]
|
|
108
|
-
// Filter functions that can manipulate search params *after* they are passed to links and navigate
|
|
109
|
-
// calls that match this route.
|
|
110
|
-
postSearchFilters?: SearchFilter<TFullSearchSchema>[]
|
|
111
|
-
// The duration to wait during `loader` execution before showing the `pendingElement`
|
|
112
|
-
pendingMs?: number
|
|
113
|
-
// _If the `pendingElement` is shown_, the minimum duration for which it will be visible.
|
|
114
|
-
pendingMinMs?: number
|
|
115
|
-
// The content to be rendered when the route is matched. If no element is provided, defaults to `<Outlet />`
|
|
116
|
-
element?: GetFrameworkGeneric<'SyncOrAsyncElement'> // , NoInfer<TLoaderData>>
|
|
117
|
-
// The content to be rendered when `loader` encounters an error
|
|
118
|
-
errorElement?: GetFrameworkGeneric<'SyncOrAsyncElement'> // , NoInfer<TLoaderData>>
|
|
119
|
-
// The content to be rendered when rendering encounters an error
|
|
120
|
-
catchElement?: GetFrameworkGeneric<'SyncOrAsyncElement'> // , NoInfer<TLoaderData>>
|
|
121
|
-
// The content to be rendered when the duration of `loader` execution surpasses the `pendingMs` duration
|
|
122
|
-
pendingElement?: GetFrameworkGeneric<'SyncOrAsyncElement'> //, NoInfer<TLoaderData>>
|
|
123
|
-
// An asynchronous function responsible for preparing or fetching data for the route before it is rendered
|
|
124
|
-
loader?: LoaderFn<TRouteLoaderData, TFullSearchSchema, TAllParams>
|
|
125
|
-
// The max age to consider loader data fresh (not-stale) for this route in milliseconds from the time of fetch
|
|
126
|
-
// Defaults to 0. Only stale loader data is refetched.
|
|
127
|
-
loaderMaxAge?: number
|
|
128
|
-
// The max age to cache the loader data for this route in milliseconds from the time of route inactivity
|
|
129
|
-
// before it is garbage collected.
|
|
130
|
-
loaderGcMaxAge?: number
|
|
131
|
-
// An asynchronous function made available to the route for performing asynchronous or mutative actions that
|
|
132
|
-
// might invalidate the route's data.
|
|
133
|
-
action?: ActionFn<TActionPayload, TActionResponse>
|
|
134
|
-
// Set this to true to rethrow errors up the component tree to either the nearest error boundary or
|
|
135
|
-
// route with error element, whichever comes first.
|
|
136
|
-
useErrorBoundary?: boolean
|
|
137
|
-
// This function is called
|
|
138
|
-
// when moving from an inactive state to an active one. Likewise, when moving from
|
|
139
|
-
// an active to an inactive state, the return function (if provided) is called.
|
|
140
|
-
onMatch?: (matchContext: {
|
|
141
|
-
params: TAllParams
|
|
142
|
-
search: TFullSearchSchema
|
|
143
|
-
}) =>
|
|
144
|
-
| void
|
|
145
|
-
| undefined
|
|
146
|
-
| ((match: { params: TAllParams; search: TFullSearchSchema }) => void)
|
|
147
|
-
// This function is called when the route remains active from one transition to the next.
|
|
148
|
-
onTransition?: (match: {
|
|
149
|
-
params: TAllParams
|
|
150
|
-
search: TFullSearchSchema
|
|
151
|
-
}) => void
|
|
152
|
-
// An object of whatever you want! This object is accessible anywhere matches are.
|
|
153
|
-
meta?: RouteMeta // TODO: Make this nested and mergeable
|
|
154
|
-
} & (
|
|
155
|
-
| {
|
|
156
|
-
parseParams?: never
|
|
157
|
-
stringifyParams?: never
|
|
158
|
-
}
|
|
159
|
-
| {
|
|
160
|
-
// Parse params optionally receives path params as strings and returns them in a parsed format (like a number or boolean)
|
|
161
|
-
parseParams: (
|
|
162
|
-
rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>,
|
|
163
|
-
) => TParams
|
|
164
|
-
stringifyParams: (
|
|
165
|
-
params: TParams,
|
|
166
|
-
) => Record<ParsePathParams<TPath>, string>
|
|
167
|
-
}
|
|
168
|
-
) &
|
|
169
|
-
(PickUnsafe<TParentParams, ParsePathParams<TPath>> extends never // Detect if an existing path param is being redefined
|
|
170
|
-
? {}
|
|
171
|
-
: 'Cannot redefined path params in child routes!')
|
|
172
|
-
|
|
173
|
-
export type SearchFilter<T, U = T> = (prev: T) => U
|
|
174
|
-
|
|
175
|
-
export interface RouteConfig<
|
|
176
|
-
TId extends string = string,
|
|
177
|
-
TRouteId extends string = string,
|
|
178
|
-
TPath extends string = string,
|
|
179
|
-
TFullPath extends string = string,
|
|
180
|
-
TRouteLoaderData extends AnyLoaderData = AnyLoaderData,
|
|
181
|
-
TLoaderData extends AnyLoaderData = AnyLoaderData,
|
|
182
|
-
TActionPayload = unknown,
|
|
183
|
-
TActionResponse = unknown,
|
|
184
|
-
TParentSearchSchema extends {} = {},
|
|
185
|
-
TSearchSchema extends AnySearchSchema = {},
|
|
186
|
-
TFullSearchSchema extends AnySearchSchema = {},
|
|
187
|
-
TParentParams extends AnyPathParams = {},
|
|
188
|
-
TParams extends Record<ParsePathParams<TPath>, unknown> = Record<
|
|
189
|
-
ParsePathParams<TPath>,
|
|
190
|
-
string
|
|
191
|
-
>,
|
|
192
|
-
TAllParams extends AnyPathParams = {},
|
|
193
|
-
TKnownChildren = unknown,
|
|
194
|
-
> {
|
|
195
|
-
id: TId
|
|
196
|
-
routeId: TRouteId
|
|
197
|
-
path: NoInfer<TPath>
|
|
198
|
-
fullPath: TFullPath
|
|
199
|
-
options: RouteOptions<
|
|
200
|
-
TRouteId,
|
|
201
|
-
TPath,
|
|
202
|
-
TRouteLoaderData,
|
|
203
|
-
TLoaderData,
|
|
204
|
-
TActionPayload,
|
|
205
|
-
TActionResponse,
|
|
206
|
-
TParentSearchSchema,
|
|
207
|
-
TSearchSchema,
|
|
208
|
-
TFullSearchSchema,
|
|
209
|
-
TParentParams,
|
|
210
|
-
TParams,
|
|
211
|
-
TAllParams
|
|
212
|
-
>
|
|
213
|
-
children?: TKnownChildren
|
|
214
|
-
addChildren: IsAny<
|
|
215
|
-
TId,
|
|
216
|
-
any,
|
|
217
|
-
<TNewChildren extends any>(
|
|
218
|
-
children: TNewChildren extends AnyRouteConfig[]
|
|
219
|
-
? TNewChildren
|
|
220
|
-
: { error: 'Invalid route detected'; route: TNewChildren },
|
|
221
|
-
) => RouteConfig<
|
|
222
|
-
TId,
|
|
223
|
-
TRouteId,
|
|
224
|
-
TPath,
|
|
225
|
-
TFullPath,
|
|
226
|
-
TRouteLoaderData,
|
|
227
|
-
TLoaderData,
|
|
228
|
-
TActionPayload,
|
|
229
|
-
TActionResponse,
|
|
230
|
-
TParentSearchSchema,
|
|
231
|
-
TSearchSchema,
|
|
232
|
-
TFullSearchSchema,
|
|
233
|
-
TParentParams,
|
|
234
|
-
TParams,
|
|
235
|
-
TAllParams,
|
|
236
|
-
TNewChildren
|
|
237
|
-
>
|
|
238
|
-
>
|
|
239
|
-
createChildren: IsAny<
|
|
240
|
-
TId,
|
|
241
|
-
any,
|
|
242
|
-
<TNewChildren extends any>(
|
|
243
|
-
cb: (
|
|
244
|
-
createChildRoute: CreateRouteConfigFn<
|
|
245
|
-
false,
|
|
246
|
-
TId,
|
|
247
|
-
TFullPath,
|
|
248
|
-
TLoaderData,
|
|
249
|
-
TFullSearchSchema,
|
|
250
|
-
TAllParams
|
|
251
|
-
>,
|
|
252
|
-
) => TNewChildren extends AnyRouteConfig[]
|
|
253
|
-
? TNewChildren
|
|
254
|
-
: { error: 'Invalid route detected'; route: TNewChildren },
|
|
255
|
-
) => RouteConfig<
|
|
256
|
-
TId,
|
|
257
|
-
TRouteId,
|
|
258
|
-
TPath,
|
|
259
|
-
TFullPath,
|
|
260
|
-
TRouteLoaderData,
|
|
261
|
-
TLoaderData,
|
|
262
|
-
TActionPayload,
|
|
263
|
-
TActionResponse,
|
|
264
|
-
TParentSearchSchema,
|
|
265
|
-
TSearchSchema,
|
|
266
|
-
TFullSearchSchema,
|
|
267
|
-
TParentParams,
|
|
268
|
-
TParams,
|
|
269
|
-
TAllParams,
|
|
270
|
-
TNewChildren
|
|
271
|
-
>
|
|
272
|
-
>
|
|
273
|
-
createRoute: CreateRouteConfigFn<
|
|
274
|
-
false,
|
|
275
|
-
TId,
|
|
276
|
-
TFullPath,
|
|
277
|
-
TLoaderData,
|
|
278
|
-
TFullSearchSchema,
|
|
279
|
-
TAllParams
|
|
280
|
-
>
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
type CreateRouteConfigFn<
|
|
284
|
-
TIsRoot extends boolean = false,
|
|
285
|
-
TParentId extends string = string,
|
|
286
|
-
TParentPath extends string = string,
|
|
287
|
-
TParentAllLoaderData extends AnyLoaderData = {},
|
|
288
|
-
TParentSearchSchema extends AnySearchSchema = {},
|
|
289
|
-
TParentParams extends AnyPathParams = {},
|
|
290
|
-
> = <
|
|
291
|
-
TRouteId extends string,
|
|
292
|
-
TPath extends string,
|
|
293
|
-
TRouteLoaderData extends AnyLoaderData,
|
|
294
|
-
TActionPayload,
|
|
295
|
-
TActionResponse,
|
|
296
|
-
TSearchSchema extends AnySearchSchema = AnySearchSchema,
|
|
297
|
-
TParams extends Record<ParsePathParams<TPath>, unknown> = Record<
|
|
298
|
-
ParsePathParams<TPath>,
|
|
299
|
-
string
|
|
300
|
-
>,
|
|
301
|
-
TAllParams extends AnyPathParams extends TParams
|
|
302
|
-
? Record<ParsePathParams<TPath>, string>
|
|
303
|
-
: NoInfer<TParams> = AnyPathParams extends TParams
|
|
304
|
-
? Record<ParsePathParams<TPath>, string>
|
|
305
|
-
: NoInfer<TParams>,
|
|
306
|
-
TKnownChildren extends RouteConfig[] = RouteConfig[],
|
|
307
|
-
TResolvedId extends string = string extends TRouteId
|
|
308
|
-
? string extends TPath
|
|
309
|
-
? string
|
|
310
|
-
: TPath
|
|
311
|
-
: TRouteId,
|
|
312
|
-
>(
|
|
313
|
-
options?: TIsRoot extends true
|
|
314
|
-
? Omit<
|
|
315
|
-
RouteOptions<
|
|
316
|
-
TRouteId,
|
|
317
|
-
TPath,
|
|
318
|
-
TRouteLoaderData,
|
|
319
|
-
Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
|
|
320
|
-
TActionPayload,
|
|
321
|
-
TActionResponse,
|
|
322
|
-
TParentSearchSchema,
|
|
323
|
-
TSearchSchema,
|
|
324
|
-
Expand<TParentSearchSchema & TSearchSchema>,
|
|
325
|
-
TParentParams,
|
|
326
|
-
TParams,
|
|
327
|
-
Expand<TParentParams & TAllParams>
|
|
328
|
-
>,
|
|
329
|
-
'path'
|
|
330
|
-
> & { path?: never }
|
|
331
|
-
: RouteOptions<
|
|
332
|
-
TRouteId,
|
|
333
|
-
TPath,
|
|
334
|
-
TRouteLoaderData,
|
|
335
|
-
Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
|
|
336
|
-
TActionPayload,
|
|
337
|
-
TActionResponse,
|
|
338
|
-
TParentSearchSchema,
|
|
339
|
-
TSearchSchema,
|
|
340
|
-
Expand<TParentSearchSchema & TSearchSchema>,
|
|
341
|
-
TParentParams,
|
|
342
|
-
TParams,
|
|
343
|
-
Expand<TParentParams & TAllParams>
|
|
344
|
-
>,
|
|
345
|
-
children?: TKnownChildren,
|
|
346
|
-
isRoot?: boolean,
|
|
347
|
-
parentId?: string,
|
|
348
|
-
parentPath?: string,
|
|
349
|
-
) => RouteConfig<
|
|
350
|
-
RoutePrefix<TParentId, TResolvedId>,
|
|
351
|
-
TResolvedId,
|
|
352
|
-
TPath,
|
|
353
|
-
string extends TPath ? '' : RoutePath<RoutePrefix<TParentPath, TPath>>,
|
|
354
|
-
TRouteLoaderData,
|
|
355
|
-
Expand<TParentAllLoaderData & DeepAwaited<NoInfer<TRouteLoaderData>>>,
|
|
356
|
-
TActionPayload,
|
|
357
|
-
TActionResponse,
|
|
358
|
-
TParentSearchSchema,
|
|
359
|
-
TSearchSchema,
|
|
360
|
-
Expand<TParentSearchSchema & TSearchSchema>,
|
|
361
|
-
TParentParams,
|
|
362
|
-
TParams,
|
|
363
|
-
Expand<TParentParams & TAllParams>,
|
|
364
|
-
TKnownChildren
|
|
365
|
-
>
|
|
366
|
-
|
|
367
|
-
type RoutePath<T extends string> = T extends RootRouteId
|
|
368
|
-
? '/'
|
|
369
|
-
: TrimPathRight<`${T}`>
|
|
370
|
-
|
|
371
|
-
type RoutePrefix<
|
|
372
|
-
TPrefix extends string,
|
|
373
|
-
TId extends string,
|
|
374
|
-
> = string extends TId
|
|
375
|
-
? RootRouteId
|
|
376
|
-
: TId extends string
|
|
377
|
-
? `${TPrefix}/${TId}` extends '/'
|
|
378
|
-
? '/'
|
|
379
|
-
: `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TId>}`>}`
|
|
380
|
-
: never
|
|
381
|
-
|
|
382
|
-
export interface AnyRouteConfig
|
|
383
|
-
extends RouteConfig<
|
|
384
|
-
any,
|
|
385
|
-
any,
|
|
386
|
-
any,
|
|
387
|
-
any,
|
|
388
|
-
any,
|
|
389
|
-
any,
|
|
390
|
-
any,
|
|
391
|
-
any,
|
|
392
|
-
any,
|
|
393
|
-
any,
|
|
394
|
-
any,
|
|
395
|
-
any,
|
|
396
|
-
any,
|
|
397
|
-
any,
|
|
398
|
-
any
|
|
399
|
-
> {}
|
|
400
|
-
|
|
401
|
-
export interface AnyRouteConfigWithChildren<TChildren>
|
|
402
|
-
extends RouteConfig<
|
|
403
|
-
any,
|
|
404
|
-
any,
|
|
405
|
-
any,
|
|
406
|
-
any,
|
|
407
|
-
any,
|
|
408
|
-
any,
|
|
409
|
-
any,
|
|
410
|
-
any,
|
|
411
|
-
any,
|
|
412
|
-
any,
|
|
413
|
-
any,
|
|
414
|
-
any,
|
|
415
|
-
any,
|
|
416
|
-
any,
|
|
417
|
-
TChildren
|
|
418
|
-
> {}
|
|
419
|
-
|
|
420
|
-
type TrimPath<T extends string> = '' extends T
|
|
421
|
-
? ''
|
|
422
|
-
: TrimPathRight<TrimPathLeft<T>>
|
|
423
|
-
|
|
424
|
-
type TrimPathLeft<T extends string> = T extends `${RootRouteId}/${infer U}`
|
|
425
|
-
? TrimPathLeft<U>
|
|
426
|
-
: T extends `/${infer U}`
|
|
427
|
-
? TrimPathLeft<U>
|
|
428
|
-
: T
|
|
429
|
-
type TrimPathRight<T extends string> = T extends '/'
|
|
430
|
-
? '/'
|
|
431
|
-
: T extends `${infer U}/`
|
|
432
|
-
? TrimPathRight<U>
|
|
433
|
-
: T
|
|
434
|
-
|
|
435
|
-
export const createRouteConfig: CreateRouteConfigFn<true> = (
|
|
436
|
-
options = {} as any,
|
|
437
|
-
children,
|
|
438
|
-
isRoot = true,
|
|
439
|
-
parentId,
|
|
440
|
-
parentPath,
|
|
441
|
-
) => {
|
|
442
|
-
if (isRoot) {
|
|
443
|
-
;(options as any).path = rootRouteId
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
// Strip the root from parentIds
|
|
447
|
-
if (parentId === rootRouteId) {
|
|
448
|
-
parentId = ''
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
let path: undefined | string = isRoot ? rootRouteId : options.path
|
|
452
|
-
|
|
453
|
-
// If the path is anything other than an index path, trim it up
|
|
454
|
-
if (path && path !== '/') {
|
|
455
|
-
path = trimPath(path)
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
const routeId = path || (options as { id?: string }).id
|
|
459
|
-
|
|
460
|
-
let id = joinPaths([parentId, routeId])
|
|
461
|
-
|
|
462
|
-
if (path === rootRouteId) {
|
|
463
|
-
path = '/'
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
if (id !== rootRouteId) {
|
|
467
|
-
id = joinPaths(['/', id])
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
const fullPath =
|
|
471
|
-
id === rootRouteId ? '/' : trimPathRight(joinPaths([parentPath, path]))
|
|
472
|
-
|
|
473
|
-
return {
|
|
474
|
-
id: id as any,
|
|
475
|
-
routeId: routeId as any,
|
|
476
|
-
path: path as any,
|
|
477
|
-
fullPath: fullPath as any,
|
|
478
|
-
options: options as any,
|
|
479
|
-
children,
|
|
480
|
-
createChildren: (cb: any) =>
|
|
481
|
-
createRouteConfig(
|
|
482
|
-
options,
|
|
483
|
-
cb((childOptions: any) =>
|
|
484
|
-
createRouteConfig(childOptions, undefined, false, id, fullPath),
|
|
485
|
-
),
|
|
486
|
-
false,
|
|
487
|
-
parentId,
|
|
488
|
-
parentPath,
|
|
489
|
-
),
|
|
490
|
-
addChildren: (children: any) =>
|
|
491
|
-
createRouteConfig(options, children, false, parentId, parentPath),
|
|
492
|
-
createRoute: (childOptions: any) =>
|
|
493
|
-
createRouteConfig(childOptions, undefined, false, id, fullPath) as any,
|
|
494
|
-
}
|
|
495
|
-
}
|
package/src/routeInfo.ts
DELETED
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
import { ParsePathParams } from './link'
|
|
2
|
-
import { Route } from './route'
|
|
3
|
-
import {
|
|
4
|
-
AnyLoaderData,
|
|
5
|
-
AnyPathParams,
|
|
6
|
-
AnyRouteConfig,
|
|
7
|
-
AnyRouteConfigWithChildren,
|
|
8
|
-
AnySearchSchema,
|
|
9
|
-
RootRouteId,
|
|
10
|
-
RouteConfig,
|
|
11
|
-
RouteOptions,
|
|
12
|
-
} from './routeConfig'
|
|
13
|
-
import { IsAny, Values } from './utils'
|
|
14
|
-
|
|
15
|
-
export interface AnyAllRouteInfo {
|
|
16
|
-
routeConfig: AnyRouteConfig
|
|
17
|
-
routeInfo: AnyRouteInfo
|
|
18
|
-
routeInfoById: Record<string, AnyRouteInfo>
|
|
19
|
-
routeInfoByFullPath: Record<string, AnyRouteInfo>
|
|
20
|
-
routeIds: any
|
|
21
|
-
routePaths: any
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface DefaultAllRouteInfo {
|
|
25
|
-
routeConfig: RouteConfig
|
|
26
|
-
routeInfo: RouteInfo
|
|
27
|
-
routeInfoById: Record<string, RouteInfo>
|
|
28
|
-
routeInfoByFullPath: Record<string, RouteInfo>
|
|
29
|
-
routeIds: string
|
|
30
|
-
routePaths: string
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface AllRouteInfo<TRouteConfig extends AnyRouteConfig = RouteConfig>
|
|
34
|
-
extends RoutesInfoInner<TRouteConfig, ParseRouteConfig<TRouteConfig>> {}
|
|
35
|
-
|
|
36
|
-
export type ParseRouteConfig<TRouteConfig = AnyRouteConfig> =
|
|
37
|
-
TRouteConfig extends AnyRouteConfig
|
|
38
|
-
? RouteConfigRoute<TRouteConfig> | ParseRouteChildren<TRouteConfig>
|
|
39
|
-
: never
|
|
40
|
-
|
|
41
|
-
type ParseRouteChildren<TRouteConfig> =
|
|
42
|
-
TRouteConfig extends AnyRouteConfigWithChildren<infer TChildren>
|
|
43
|
-
? unknown extends TChildren
|
|
44
|
-
? never
|
|
45
|
-
: TChildren extends AnyRouteConfig[]
|
|
46
|
-
? Values<{
|
|
47
|
-
[TId in TChildren[number]['id']]: ParseRouteChild<
|
|
48
|
-
TChildren[number],
|
|
49
|
-
TId
|
|
50
|
-
>
|
|
51
|
-
}>
|
|
52
|
-
: never // Children are not routes
|
|
53
|
-
: never // No children
|
|
54
|
-
|
|
55
|
-
type ParseRouteChild<TRouteConfig, TId> = TRouteConfig & {
|
|
56
|
-
id: TId
|
|
57
|
-
} extends AnyRouteConfig
|
|
58
|
-
? ParseRouteConfig<TRouteConfig>
|
|
59
|
-
: never
|
|
60
|
-
|
|
61
|
-
export type RouteConfigRoute<TRouteConfig> = TRouteConfig extends RouteConfig<
|
|
62
|
-
infer TId,
|
|
63
|
-
infer TRouteId,
|
|
64
|
-
infer TPath,
|
|
65
|
-
infer TFullPath,
|
|
66
|
-
infer TRouteLoaderData,
|
|
67
|
-
infer TLoaderData,
|
|
68
|
-
infer TActionPayload,
|
|
69
|
-
infer TActionResponse,
|
|
70
|
-
infer TParentSearchSchema,
|
|
71
|
-
infer TSearchSchema,
|
|
72
|
-
infer TFullSearchSchema,
|
|
73
|
-
infer TParentParams,
|
|
74
|
-
infer TParams,
|
|
75
|
-
infer TAllParams,
|
|
76
|
-
any
|
|
77
|
-
>
|
|
78
|
-
? string extends TRouteId
|
|
79
|
-
? never
|
|
80
|
-
: RouteInfo<
|
|
81
|
-
TId,
|
|
82
|
-
TRouteId,
|
|
83
|
-
TPath,
|
|
84
|
-
TFullPath,
|
|
85
|
-
TRouteLoaderData,
|
|
86
|
-
TLoaderData,
|
|
87
|
-
TActionPayload,
|
|
88
|
-
TActionResponse,
|
|
89
|
-
TParentSearchSchema,
|
|
90
|
-
TSearchSchema,
|
|
91
|
-
TFullSearchSchema,
|
|
92
|
-
TParentParams,
|
|
93
|
-
TParams,
|
|
94
|
-
TAllParams
|
|
95
|
-
>
|
|
96
|
-
: never
|
|
97
|
-
|
|
98
|
-
export interface RoutesInfoInner<
|
|
99
|
-
TRouteConfig extends AnyRouteConfig,
|
|
100
|
-
TRouteInfo extends RouteInfo<
|
|
101
|
-
string,
|
|
102
|
-
string,
|
|
103
|
-
any,
|
|
104
|
-
any,
|
|
105
|
-
any,
|
|
106
|
-
any,
|
|
107
|
-
any,
|
|
108
|
-
any,
|
|
109
|
-
any,
|
|
110
|
-
any,
|
|
111
|
-
any,
|
|
112
|
-
any,
|
|
113
|
-
any,
|
|
114
|
-
any
|
|
115
|
-
> = RouteInfo,
|
|
116
|
-
TRouteInfoById = {
|
|
117
|
-
[TInfo in TRouteInfo as TInfo['id']]: TInfo
|
|
118
|
-
},
|
|
119
|
-
TRouteInfoByFullPath = {
|
|
120
|
-
[TInfo in TRouteInfo as TInfo['fullPath'] extends RootRouteId
|
|
121
|
-
? never
|
|
122
|
-
: string extends TInfo['fullPath']
|
|
123
|
-
? never
|
|
124
|
-
: TInfo['fullPath']]: TInfo
|
|
125
|
-
},
|
|
126
|
-
> {
|
|
127
|
-
routeConfig: TRouteConfig
|
|
128
|
-
routeInfo: TRouteInfo
|
|
129
|
-
routeInfoById: TRouteInfoById
|
|
130
|
-
routeInfoByFullPath: TRouteInfoByFullPath
|
|
131
|
-
routeIds: keyof TRouteInfoById
|
|
132
|
-
routePaths: keyof TRouteInfoByFullPath
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export interface AnyRouteInfo
|
|
136
|
-
extends RouteInfo<
|
|
137
|
-
any,
|
|
138
|
-
any,
|
|
139
|
-
any,
|
|
140
|
-
any,
|
|
141
|
-
any,
|
|
142
|
-
any,
|
|
143
|
-
any,
|
|
144
|
-
any,
|
|
145
|
-
any,
|
|
146
|
-
any,
|
|
147
|
-
any,
|
|
148
|
-
any,
|
|
149
|
-
any,
|
|
150
|
-
any
|
|
151
|
-
> {}
|
|
152
|
-
|
|
153
|
-
export interface RouteInfo<
|
|
154
|
-
TId extends string = string,
|
|
155
|
-
TRouteId extends string = string,
|
|
156
|
-
TPath extends string = string,
|
|
157
|
-
TFullPath extends string = string,
|
|
158
|
-
TRouteLoaderData extends AnyLoaderData = {},
|
|
159
|
-
TLoaderData extends AnyLoaderData = {},
|
|
160
|
-
TActionPayload = unknown,
|
|
161
|
-
TActionResponse = unknown,
|
|
162
|
-
TParentSearchSchema extends {} = {},
|
|
163
|
-
TSearchSchema extends AnySearchSchema = {},
|
|
164
|
-
TFullSearchSchema extends AnySearchSchema = {},
|
|
165
|
-
TParentParams extends AnyPathParams = {},
|
|
166
|
-
TParams extends Record<ParsePathParams<TPath>, unknown> = Record<
|
|
167
|
-
ParsePathParams<TPath>,
|
|
168
|
-
string
|
|
169
|
-
>,
|
|
170
|
-
TAllParams extends AnyPathParams = {},
|
|
171
|
-
> {
|
|
172
|
-
id: TId
|
|
173
|
-
routeId: TRouteId
|
|
174
|
-
path: TPath
|
|
175
|
-
fullPath: TFullPath
|
|
176
|
-
routeLoaderData: TRouteLoaderData
|
|
177
|
-
loaderData: TLoaderData
|
|
178
|
-
actionPayload: TActionPayload
|
|
179
|
-
actionResponse: TActionResponse
|
|
180
|
-
searchSchema: TSearchSchema
|
|
181
|
-
fullSearchSchema: TFullSearchSchema
|
|
182
|
-
parentParams: TParentParams
|
|
183
|
-
params: TParams
|
|
184
|
-
allParams: TAllParams
|
|
185
|
-
options: RouteOptions<
|
|
186
|
-
TRouteId,
|
|
187
|
-
TPath,
|
|
188
|
-
TRouteLoaderData,
|
|
189
|
-
TLoaderData,
|
|
190
|
-
TActionPayload,
|
|
191
|
-
TActionResponse,
|
|
192
|
-
TParentSearchSchema,
|
|
193
|
-
TSearchSchema,
|
|
194
|
-
TFullSearchSchema,
|
|
195
|
-
TParentParams,
|
|
196
|
-
TParams,
|
|
197
|
-
TAllParams
|
|
198
|
-
>
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export type RoutesById<TAllRouteInfo extends AnyAllRouteInfo> = {
|
|
202
|
-
[K in keyof TAllRouteInfo['routeInfoById']]: Route<
|
|
203
|
-
TAllRouteInfo,
|
|
204
|
-
TAllRouteInfo['routeInfoById'][K]
|
|
205
|
-
>
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
export type RouteInfoById<
|
|
209
|
-
TAllRouteInfo extends AnyAllRouteInfo,
|
|
210
|
-
TId,
|
|
211
|
-
> = TId extends keyof TAllRouteInfo['routeInfoById']
|
|
212
|
-
? IsAny<
|
|
213
|
-
TAllRouteInfo['routeInfoById'][TId]['id'],
|
|
214
|
-
RouteInfo,
|
|
215
|
-
TAllRouteInfo['routeInfoById'][TId]
|
|
216
|
-
>
|
|
217
|
-
: never
|
|
218
|
-
|
|
219
|
-
export type RouteInfoByPath<
|
|
220
|
-
TAllRouteInfo extends AnyAllRouteInfo,
|
|
221
|
-
TPath,
|
|
222
|
-
> = TPath extends keyof TAllRouteInfo['routeInfoByFullPath']
|
|
223
|
-
? IsAny<
|
|
224
|
-
TAllRouteInfo['routeInfoByFullPath'][TPath]['id'],
|
|
225
|
-
RouteInfo,
|
|
226
|
-
TAllRouteInfo['routeInfoByFullPath'][TPath]
|
|
227
|
-
>
|
|
228
|
-
: never
|