@tolki/types 1.1.5 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.d.ts +1 -0
- package/src/routes.d.ts +558 -0
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
package/src/routes.d.ts
ADDED
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata for a single route argument.
|
|
3
|
+
*
|
|
4
|
+
* - `_routeKey` indicates model binding (extract `value[_routeKey]` from objects).
|
|
5
|
+
* - `_enumValues` indicates enum binding (restrict to backing values).
|
|
6
|
+
* - Plain scalar args have only `name` and `required`.
|
|
7
|
+
*/
|
|
8
|
+
export type RouteArgMeta = {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly required?: boolean;
|
|
11
|
+
readonly _routeKey?: string;
|
|
12
|
+
readonly _enumValues?: readonly (string | number)[];
|
|
13
|
+
readonly where?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Resolve the TypeScript input type for a single route arg from its metadata.
|
|
18
|
+
*
|
|
19
|
+
* - Model-bound (`_routeKey`): accepts scalar or object with the route key field.
|
|
20
|
+
* - Enum-bound (`_enumValues`): accepts a backing value or object with `.value`.
|
|
21
|
+
* - Plain scalar: accepts `string | number`.
|
|
22
|
+
*/
|
|
23
|
+
export type ResolveArgInputType<TArg extends RouteArgMeta> = TArg extends {
|
|
24
|
+
readonly _routeKey: infer TKey extends string;
|
|
25
|
+
}
|
|
26
|
+
?
|
|
27
|
+
| string
|
|
28
|
+
| number
|
|
29
|
+
| ({ readonly [K in TKey]: string | number } & Record<
|
|
30
|
+
string,
|
|
31
|
+
unknown
|
|
32
|
+
>)
|
|
33
|
+
| ({ readonly id: string | number } & Record<string, unknown>)
|
|
34
|
+
: TArg extends {
|
|
35
|
+
readonly _enumValues: infer TValues extends readonly (
|
|
36
|
+
| string
|
|
37
|
+
| number
|
|
38
|
+
)[];
|
|
39
|
+
}
|
|
40
|
+
? TValues[number] | { readonly value: TValues[number] }
|
|
41
|
+
: string | number;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Required args from the tuple — properties that must be provided.
|
|
45
|
+
*/
|
|
46
|
+
type RequiredArgsObject<TArgs extends readonly RouteArgMeta[]> = {
|
|
47
|
+
[TArg in TArgs[number] as TArg extends { readonly required: false }
|
|
48
|
+
? never
|
|
49
|
+
: TArg["name"]]: ResolveArgInputType<TArg>;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Optional args from the tuple — properties that can be omitted.
|
|
54
|
+
*/
|
|
55
|
+
type OptionalArgsObject<TArgs extends readonly RouteArgMeta[]> = {
|
|
56
|
+
[TArg in TArgs[number] as TArg extends { readonly required: false }
|
|
57
|
+
? TArg["name"]
|
|
58
|
+
: never]?: ResolveArgInputType<TArg> | null;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Build the named args object from a const-tuple of arg metas.
|
|
63
|
+
* Required args must be provided; optional args (required: false) can be omitted.
|
|
64
|
+
*/
|
|
65
|
+
export type ArgsObject<TArgs extends readonly RouteArgMeta[]> =
|
|
66
|
+
RequiredArgsObject<TArgs> & OptionalArgsObject<TArgs>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Recursively builds a positional tuple, making args with `required: false`
|
|
70
|
+
* into optional tuple elements (`[req, opt?]`) via variadic tuple spread.
|
|
71
|
+
*/
|
|
72
|
+
type BuildPositionalTuple<
|
|
73
|
+
TArgs extends readonly RouteArgMeta[],
|
|
74
|
+
TAcc extends readonly unknown[] = [],
|
|
75
|
+
> = TArgs extends readonly []
|
|
76
|
+
? TAcc
|
|
77
|
+
: TArgs extends readonly [
|
|
78
|
+
infer TFirst extends RouteArgMeta,
|
|
79
|
+
...infer TRest extends readonly RouteArgMeta[],
|
|
80
|
+
]
|
|
81
|
+
? TFirst extends { readonly required: false }
|
|
82
|
+
? BuildPositionalTuple<TRest, [...TAcc, ResolveArgInputType<TFirst>?]>
|
|
83
|
+
: BuildPositionalTuple<TRest, [...TAcc, ResolveArgInputType<TFirst>]>
|
|
84
|
+
: TAcc;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Positional tuple — each index maps to the resolved type of the arg at that position.
|
|
88
|
+
* Args with `required: false` become optional tuple elements.
|
|
89
|
+
*/
|
|
90
|
+
export type PositionalTuple<TArgs extends readonly RouteArgMeta[]> =
|
|
91
|
+
BuildPositionalTuple<TArgs>;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* All valid ways to pass args to a route — named object or positional array.
|
|
95
|
+
*/
|
|
96
|
+
export type RouteInput<TArgs extends readonly RouteArgMeta[]> =
|
|
97
|
+
| ArgsObject<TArgs>
|
|
98
|
+
| PositionalTuple<TArgs>;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Options for query string and other route call extras.
|
|
102
|
+
*/
|
|
103
|
+
export type RouteQueryOptions = {
|
|
104
|
+
readonly _query?: Record<string, unknown>;
|
|
105
|
+
readonly mergeQuery?: Record<string, unknown>;
|
|
106
|
+
readonly [key: string]: unknown;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The result of calling a route — contains url, method, and toString().
|
|
111
|
+
*/
|
|
112
|
+
export type RouteCallResult<TMethod extends string = string> = {
|
|
113
|
+
readonly url: string;
|
|
114
|
+
readonly method: TMethod;
|
|
115
|
+
toString(): string;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Valid component types for route metadata.
|
|
120
|
+
* - `string` for single-component routes (e.g. `'Dashboard'`).
|
|
121
|
+
* - `Readonly<Record<string, string>>` for multi-component routes
|
|
122
|
+
* (e.g. `{ authenticated: 'Auth/Dashboard', guest: 'Guest/Welcome' } as const`).
|
|
123
|
+
*/
|
|
124
|
+
export type RouteComponentType = string | Readonly<Record<string, string>>;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Route metadata shape as passed to `defineRoute`.
|
|
128
|
+
*/
|
|
129
|
+
export type RouteMetadata<
|
|
130
|
+
TMethods extends readonly string[] = readonly string[],
|
|
131
|
+
TArgs extends readonly RouteArgMeta[] = readonly RouteArgMeta[],
|
|
132
|
+
TComponent extends RouteComponentType | undefined = undefined,
|
|
133
|
+
> = {
|
|
134
|
+
readonly name?: string | null;
|
|
135
|
+
readonly url: string;
|
|
136
|
+
readonly domain?: string | null;
|
|
137
|
+
readonly methods: TMethods;
|
|
138
|
+
readonly args?: TArgs;
|
|
139
|
+
readonly component?: TComponent;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Helper type: check if all args in a tuple are optional.
|
|
144
|
+
*/
|
|
145
|
+
type AllArgsOptional<TArgs extends readonly RouteArgMeta[]> = {
|
|
146
|
+
[I in keyof TArgs]: TArgs[I] extends { readonly required: false }
|
|
147
|
+
? true
|
|
148
|
+
: false;
|
|
149
|
+
}[number] extends true
|
|
150
|
+
? true
|
|
151
|
+
: false;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Callable signatures for routes with args.
|
|
155
|
+
*/
|
|
156
|
+
type RouteCallableWithArgs<
|
|
157
|
+
TMethod extends string,
|
|
158
|
+
TArgs extends readonly RouteArgMeta[],
|
|
159
|
+
> =
|
|
160
|
+
AllArgsOptional<TArgs> extends true
|
|
161
|
+
? {
|
|
162
|
+
(
|
|
163
|
+
args?: ArgsObject<TArgs> & Record<string, unknown>,
|
|
164
|
+
options?: RouteQueryOptions,
|
|
165
|
+
): RouteCallResult<TMethod>;
|
|
166
|
+
(
|
|
167
|
+
args: (string | number | Record<string, unknown>)[],
|
|
168
|
+
options?: RouteQueryOptions,
|
|
169
|
+
): RouteCallResult<TMethod>;
|
|
170
|
+
(
|
|
171
|
+
...args: [...PositionalTuple<TArgs>, RouteQueryOptions]
|
|
172
|
+
): RouteCallResult<TMethod>;
|
|
173
|
+
(...args: PositionalTuple<TArgs>): RouteCallResult<TMethod>;
|
|
174
|
+
}
|
|
175
|
+
: {
|
|
176
|
+
(
|
|
177
|
+
args: ArgsObject<TArgs> & Record<string, unknown>,
|
|
178
|
+
options?: RouteQueryOptions,
|
|
179
|
+
): RouteCallResult<TMethod>;
|
|
180
|
+
(
|
|
181
|
+
args: (string | number | Record<string, unknown>)[],
|
|
182
|
+
options?: RouteQueryOptions,
|
|
183
|
+
): RouteCallResult<TMethod>;
|
|
184
|
+
(
|
|
185
|
+
...args: [...PositionalTuple<TArgs>, RouteQueryOptions]
|
|
186
|
+
): RouteCallResult<TMethod>;
|
|
187
|
+
(...args: PositionalTuple<TArgs>): RouteCallResult<TMethod>;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Callable signatures for routes without args.
|
|
192
|
+
*/
|
|
193
|
+
type RouteCallableNoArgs<TMethod extends string> = {
|
|
194
|
+
(options?: RouteQueryOptions): RouteCallResult<TMethod>;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* URL method signatures for routes with args.
|
|
199
|
+
*/
|
|
200
|
+
type RouteUrlWithArgs<TArgs extends readonly RouteArgMeta[]> =
|
|
201
|
+
AllArgsOptional<TArgs> extends true
|
|
202
|
+
? {
|
|
203
|
+
(
|
|
204
|
+
args?: ArgsObject<TArgs> & Record<string, unknown>,
|
|
205
|
+
options?: RouteQueryOptions,
|
|
206
|
+
): string;
|
|
207
|
+
(
|
|
208
|
+
args: (string | number | Record<string, unknown>)[],
|
|
209
|
+
options?: RouteQueryOptions,
|
|
210
|
+
): string;
|
|
211
|
+
(...args: [...PositionalTuple<TArgs>, RouteQueryOptions]): string;
|
|
212
|
+
(...args: PositionalTuple<TArgs>): string;
|
|
213
|
+
}
|
|
214
|
+
: {
|
|
215
|
+
(
|
|
216
|
+
args: ArgsObject<TArgs> & Record<string, unknown>,
|
|
217
|
+
options?: RouteQueryOptions,
|
|
218
|
+
): string;
|
|
219
|
+
(
|
|
220
|
+
args: (string | number | Record<string, unknown>)[],
|
|
221
|
+
options?: RouteQueryOptions,
|
|
222
|
+
): string;
|
|
223
|
+
(...args: [...PositionalTuple<TArgs>, RouteQueryOptions]): string;
|
|
224
|
+
(...args: PositionalTuple<TArgs>): string;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* URL method signatures for routes without args.
|
|
229
|
+
*/
|
|
230
|
+
type RouteUrlNoArgs = {
|
|
231
|
+
(options?: RouteQueryOptions): string;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Per-verb method types for routes with args.
|
|
236
|
+
*/
|
|
237
|
+
type VerbMethodsWithArgs<
|
|
238
|
+
TMethods extends readonly string[],
|
|
239
|
+
TArgs extends readonly RouteArgMeta[],
|
|
240
|
+
> = {
|
|
241
|
+
[K in TMethods[number]]: RouteCallableWithArgs<K, TArgs>;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Per-verb method types for routes without args.
|
|
246
|
+
*/
|
|
247
|
+
type VerbMethodsNoArgs<TMethods extends readonly string[]> = {
|
|
248
|
+
[K in TMethods[number]]: RouteCallableNoArgs<K>;
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* The full return type of `defineRoute` for routes with args.
|
|
253
|
+
*/
|
|
254
|
+
export type DefineRouteResultWithArgs<
|
|
255
|
+
TMethods extends readonly string[],
|
|
256
|
+
TArgs extends readonly RouteArgMeta[],
|
|
257
|
+
TComponent extends RouteComponentType | undefined = undefined,
|
|
258
|
+
> = RouteCallableWithArgs<TMethods[0], TArgs> & {
|
|
259
|
+
url: RouteUrlWithArgs<TArgs>;
|
|
260
|
+
definition: RouteMetadata<TMethods, TArgs, TComponent>;
|
|
261
|
+
form: FormWithArgs<TMethods, TArgs>;
|
|
262
|
+
toString(): string;
|
|
263
|
+
} & VerbMethodsWithArgs<TMethods, TArgs> &
|
|
264
|
+
ComponentMixin<TComponent, TMethods, TArgs>;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* The full return type of `defineRoute` for routes without args.
|
|
268
|
+
*/
|
|
269
|
+
export type DefineRouteResultNoArgs<
|
|
270
|
+
TMethods extends readonly string[],
|
|
271
|
+
TComponent extends RouteComponentType | undefined = undefined,
|
|
272
|
+
> = RouteCallableNoArgs<TMethods[0]> & {
|
|
273
|
+
url: RouteUrlNoArgs;
|
|
274
|
+
definition: RouteMetadata<TMethods, readonly [], TComponent>;
|
|
275
|
+
form: FormNoArgs<TMethods>;
|
|
276
|
+
toString(): string;
|
|
277
|
+
} & VerbMethodsNoArgs<TMethods> &
|
|
278
|
+
ComponentMixin<TComponent, TMethods, readonly []>;
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* The full return type of `defineRoute`.
|
|
282
|
+
* Discriminates on whether `args` is present in metadata.
|
|
283
|
+
*/
|
|
284
|
+
export type DefineRouteResult<
|
|
285
|
+
TMethods extends readonly string[] = readonly string[],
|
|
286
|
+
TArgs extends readonly RouteArgMeta[] = readonly RouteArgMeta[],
|
|
287
|
+
TComponent extends RouteComponentType | undefined = undefined,
|
|
288
|
+
> = [TArgs] extends [readonly []] | [readonly never[]]
|
|
289
|
+
? DefineRouteResultNoArgs<TMethods, TComponent>
|
|
290
|
+
: DefineRouteResultWithArgs<TMethods, TArgs, TComponent>;
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* The result of calling `.form()` — contains action (URL), method, and toString().
|
|
294
|
+
*/
|
|
295
|
+
export type RouteFormResult<TMethod extends string = string> = {
|
|
296
|
+
readonly action: string;
|
|
297
|
+
readonly method: TMethod extends "get" | "head" ? "get" : "post";
|
|
298
|
+
toString(): string;
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* The result of calling `.withComponent()` — route call result enriched with a component.
|
|
303
|
+
*/
|
|
304
|
+
export type RouteCallResultWithComponent<
|
|
305
|
+
TComponent extends string = string,
|
|
306
|
+
TMethod extends string = string,
|
|
307
|
+
> = RouteCallResult<TMethod> & {
|
|
308
|
+
readonly component: TComponent;
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* WithComponent callable for single-component routes without args.
|
|
313
|
+
*/
|
|
314
|
+
type WithComponentSingleNoArgs<
|
|
315
|
+
TComponent extends string,
|
|
316
|
+
TMethod extends string,
|
|
317
|
+
> = {
|
|
318
|
+
(
|
|
319
|
+
options?: RouteQueryOptions,
|
|
320
|
+
): RouteCallResultWithComponent<TComponent, TMethod>;
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* WithComponent callable for single-component routes with args.
|
|
325
|
+
*/
|
|
326
|
+
type WithComponentSingleWithArgs<
|
|
327
|
+
TComponent extends string,
|
|
328
|
+
TMethod extends string,
|
|
329
|
+
TArgs extends readonly RouteArgMeta[],
|
|
330
|
+
> =
|
|
331
|
+
AllArgsOptional<TArgs> extends true
|
|
332
|
+
? {
|
|
333
|
+
(
|
|
334
|
+
args?: ArgsObject<TArgs> & Record<string, unknown>,
|
|
335
|
+
options?: RouteQueryOptions,
|
|
336
|
+
): RouteCallResultWithComponent<TComponent, TMethod>;
|
|
337
|
+
(
|
|
338
|
+
args: (string | number | Record<string, unknown>)[],
|
|
339
|
+
options?: RouteQueryOptions,
|
|
340
|
+
): RouteCallResultWithComponent<TComponent, TMethod>;
|
|
341
|
+
(
|
|
342
|
+
...args: [...PositionalTuple<TArgs>, RouteQueryOptions]
|
|
343
|
+
): RouteCallResultWithComponent<TComponent, TMethod>;
|
|
344
|
+
(
|
|
345
|
+
...args: PositionalTuple<TArgs>
|
|
346
|
+
): RouteCallResultWithComponent<TComponent, TMethod>;
|
|
347
|
+
}
|
|
348
|
+
: {
|
|
349
|
+
(
|
|
350
|
+
args: ArgsObject<TArgs> & Record<string, unknown>,
|
|
351
|
+
options?: RouteQueryOptions,
|
|
352
|
+
): RouteCallResultWithComponent<TComponent, TMethod>;
|
|
353
|
+
(
|
|
354
|
+
args: (string | number | Record<string, unknown>)[],
|
|
355
|
+
options?: RouteQueryOptions,
|
|
356
|
+
): RouteCallResultWithComponent<TComponent, TMethod>;
|
|
357
|
+
(
|
|
358
|
+
...args: [...PositionalTuple<TArgs>, RouteQueryOptions]
|
|
359
|
+
): RouteCallResultWithComponent<TComponent, TMethod>;
|
|
360
|
+
(
|
|
361
|
+
...args: PositionalTuple<TArgs>
|
|
362
|
+
): RouteCallResultWithComponent<TComponent, TMethod>;
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* WithComponent callable for multi-component routes without args.
|
|
367
|
+
* First argument selects which component to use.
|
|
368
|
+
*/
|
|
369
|
+
type WithComponentMultiNoArgs<
|
|
370
|
+
TComponent extends Readonly<Record<string, string>>,
|
|
371
|
+
TMethod extends string,
|
|
372
|
+
> = {
|
|
373
|
+
(
|
|
374
|
+
component: TComponent[keyof TComponent],
|
|
375
|
+
options?: RouteQueryOptions,
|
|
376
|
+
): RouteCallResultWithComponent<TComponent[keyof TComponent], TMethod>;
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* WithComponent callable for multi-component routes with args.
|
|
381
|
+
* First argument selects which component, followed by the same calling
|
|
382
|
+
* conventions as the route itself (named object, array, positional spread).
|
|
383
|
+
*/
|
|
384
|
+
type WithComponentMultiWithArgs<
|
|
385
|
+
TComponent extends Readonly<Record<string, string>>,
|
|
386
|
+
TMethod extends string,
|
|
387
|
+
TArgs extends readonly RouteArgMeta[],
|
|
388
|
+
> =
|
|
389
|
+
AllArgsOptional<TArgs> extends true
|
|
390
|
+
? {
|
|
391
|
+
(
|
|
392
|
+
component: TComponent[keyof TComponent],
|
|
393
|
+
args?: ArgsObject<TArgs> & Record<string, unknown>,
|
|
394
|
+
options?: RouteQueryOptions,
|
|
395
|
+
): RouteCallResultWithComponent<
|
|
396
|
+
TComponent[keyof TComponent],
|
|
397
|
+
TMethod
|
|
398
|
+
>;
|
|
399
|
+
(
|
|
400
|
+
component: TComponent[keyof TComponent],
|
|
401
|
+
args: (string | number | Record<string, unknown>)[],
|
|
402
|
+
options?: RouteQueryOptions,
|
|
403
|
+
): RouteCallResultWithComponent<
|
|
404
|
+
TComponent[keyof TComponent],
|
|
405
|
+
TMethod
|
|
406
|
+
>;
|
|
407
|
+
(
|
|
408
|
+
component: TComponent[keyof TComponent],
|
|
409
|
+
...args: [...PositionalTuple<TArgs>, RouteQueryOptions]
|
|
410
|
+
): RouteCallResultWithComponent<
|
|
411
|
+
TComponent[keyof TComponent],
|
|
412
|
+
TMethod
|
|
413
|
+
>;
|
|
414
|
+
(
|
|
415
|
+
component: TComponent[keyof TComponent],
|
|
416
|
+
...args: PositionalTuple<TArgs>
|
|
417
|
+
): RouteCallResultWithComponent<
|
|
418
|
+
TComponent[keyof TComponent],
|
|
419
|
+
TMethod
|
|
420
|
+
>;
|
|
421
|
+
}
|
|
422
|
+
: {
|
|
423
|
+
(
|
|
424
|
+
component: TComponent[keyof TComponent],
|
|
425
|
+
args: ArgsObject<TArgs> & Record<string, unknown>,
|
|
426
|
+
options?: RouteQueryOptions,
|
|
427
|
+
): RouteCallResultWithComponent<
|
|
428
|
+
TComponent[keyof TComponent],
|
|
429
|
+
TMethod
|
|
430
|
+
>;
|
|
431
|
+
(
|
|
432
|
+
component: TComponent[keyof TComponent],
|
|
433
|
+
args: (string | number | Record<string, unknown>)[],
|
|
434
|
+
options?: RouteQueryOptions,
|
|
435
|
+
): RouteCallResultWithComponent<
|
|
436
|
+
TComponent[keyof TComponent],
|
|
437
|
+
TMethod
|
|
438
|
+
>;
|
|
439
|
+
(
|
|
440
|
+
component: TComponent[keyof TComponent],
|
|
441
|
+
...args: [...PositionalTuple<TArgs>, RouteQueryOptions]
|
|
442
|
+
): RouteCallResultWithComponent<
|
|
443
|
+
TComponent[keyof TComponent],
|
|
444
|
+
TMethod
|
|
445
|
+
>;
|
|
446
|
+
(
|
|
447
|
+
component: TComponent[keyof TComponent],
|
|
448
|
+
...args: PositionalTuple<TArgs>
|
|
449
|
+
): RouteCallResultWithComponent<
|
|
450
|
+
TComponent[keyof TComponent],
|
|
451
|
+
TMethod
|
|
452
|
+
>;
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Mixin that conditionally adds `.component` and `.withComponent` to a route result.
|
|
457
|
+
*
|
|
458
|
+
* - When TComponent is `string`: single-component route with typed `.component` and `.withComponent`.
|
|
459
|
+
* - When TComponent is `Record<string, string>`: multi-component route with component map and selector.
|
|
460
|
+
* - When TComponent is `undefined`: no component properties added (empty intersection).
|
|
461
|
+
*/
|
|
462
|
+
type ComponentMixin<
|
|
463
|
+
TComponent extends RouteComponentType | undefined,
|
|
464
|
+
TMethods extends readonly string[],
|
|
465
|
+
TArgs extends readonly RouteArgMeta[],
|
|
466
|
+
> = TComponent extends string
|
|
467
|
+
? {
|
|
468
|
+
readonly component: TComponent;
|
|
469
|
+
withComponent: [TArgs] extends [readonly []] | [readonly never[]]
|
|
470
|
+
? WithComponentSingleNoArgs<TComponent, TMethods[0]>
|
|
471
|
+
: WithComponentSingleWithArgs<TComponent, TMethods[0], TArgs>;
|
|
472
|
+
}
|
|
473
|
+
: TComponent extends Readonly<Record<string, string>>
|
|
474
|
+
? {
|
|
475
|
+
readonly component: TComponent;
|
|
476
|
+
withComponent: [TArgs] extends [readonly []] | [readonly never[]]
|
|
477
|
+
? WithComponentMultiNoArgs<TComponent, TMethods[0]>
|
|
478
|
+
: WithComponentMultiWithArgs<TComponent, TMethods[0], TArgs>;
|
|
479
|
+
}
|
|
480
|
+
: Record<never, never>;
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Form callable signatures for routes with args.
|
|
484
|
+
*/
|
|
485
|
+
type FormCallableWithArgs<
|
|
486
|
+
TMethod extends string,
|
|
487
|
+
TArgs extends readonly RouteArgMeta[],
|
|
488
|
+
> =
|
|
489
|
+
AllArgsOptional<TArgs> extends true
|
|
490
|
+
? {
|
|
491
|
+
(
|
|
492
|
+
args?: ArgsObject<TArgs> & Record<string, unknown>,
|
|
493
|
+
options?: RouteQueryOptions,
|
|
494
|
+
): RouteFormResult<TMethod>;
|
|
495
|
+
(
|
|
496
|
+
args: (string | number | Record<string, unknown>)[],
|
|
497
|
+
options?: RouteQueryOptions,
|
|
498
|
+
): RouteFormResult<TMethod>;
|
|
499
|
+
(
|
|
500
|
+
...args: [...PositionalTuple<TArgs>, RouteQueryOptions]
|
|
501
|
+
): RouteFormResult<TMethod>;
|
|
502
|
+
(...args: PositionalTuple<TArgs>): RouteFormResult<TMethod>;
|
|
503
|
+
}
|
|
504
|
+
: {
|
|
505
|
+
(
|
|
506
|
+
args: ArgsObject<TArgs> & Record<string, unknown>,
|
|
507
|
+
options?: RouteQueryOptions,
|
|
508
|
+
): RouteFormResult<TMethod>;
|
|
509
|
+
(
|
|
510
|
+
args: (string | number | Record<string, unknown>)[],
|
|
511
|
+
options?: RouteQueryOptions,
|
|
512
|
+
): RouteFormResult<TMethod>;
|
|
513
|
+
(
|
|
514
|
+
...args: [...PositionalTuple<TArgs>, RouteQueryOptions]
|
|
515
|
+
): RouteFormResult<TMethod>;
|
|
516
|
+
(...args: PositionalTuple<TArgs>): RouteFormResult<TMethod>;
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Form callable signatures for routes without args.
|
|
521
|
+
*/
|
|
522
|
+
type FormCallableNoArgs<TMethod extends string> = {
|
|
523
|
+
(options?: RouteQueryOptions): RouteFormResult<TMethod>;
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Per-verb form method types for routes with args.
|
|
528
|
+
*/
|
|
529
|
+
type FormVerbMethodsWithArgs<
|
|
530
|
+
TMethods extends readonly string[],
|
|
531
|
+
TArgs extends readonly RouteArgMeta[],
|
|
532
|
+
> = {
|
|
533
|
+
[K in TMethods[number]]: FormCallableWithArgs<K, TArgs>;
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* Per-verb form method types for routes without args.
|
|
538
|
+
*/
|
|
539
|
+
type FormVerbMethodsNoArgs<TMethods extends readonly string[]> = {
|
|
540
|
+
[K in TMethods[number]]: FormCallableNoArgs<K>;
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* The `.form` property on a route with args — callable + per-verb sub-methods.
|
|
545
|
+
*/
|
|
546
|
+
type FormWithArgs<
|
|
547
|
+
TMethods extends readonly string[],
|
|
548
|
+
TArgs extends readonly RouteArgMeta[],
|
|
549
|
+
> = FormCallableWithArgs<TMethods[0], TArgs> &
|
|
550
|
+
FormVerbMethodsWithArgs<TMethods, TArgs>;
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* The `.form` property on a route without args — callable + per-verb sub-methods.
|
|
554
|
+
*/
|
|
555
|
+
type FormNoArgs<TMethods extends readonly string[]> = FormCallableNoArgs<
|
|
556
|
+
TMethods[0]
|
|
557
|
+
> &
|
|
558
|
+
FormVerbMethodsNoArgs<TMethods>;
|