@tolki/types 1.1.5 → 1.3.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolki/types",
3
- "version": "1.1.5",
3
+ "version": "1.3.0",
4
4
  "description": "Utility TypeScript types for @tolki packages and Laravel HTTP responses.",
5
5
  "author": "Abraham Arango <https://github.com/abetwothree>",
6
6
  "license": "MIT",
package/src/index.d.ts CHANGED
@@ -7,5 +7,6 @@ export type * from "./objects";
7
7
  export type * from "./pagination";
8
8
  export type * from "./path-resolve";
9
9
  export type * from "./resource-responses";
10
+ export type * from "./routes";
10
11
  export type * from "./strings";
11
12
  export type * from "./utils";
@@ -1,5 +1,10 @@
1
1
  import type { PaginatorLink } from "./pagination";
2
2
 
3
+ /**
4
+ * Interface representing the pagination structure of a JSON resource collection response, following Laravel's default JSON Resource format.
5
+ *
6
+ * @see https://laravel.com/docs/master/eloquent-resources#pagination
7
+ */
3
8
  export interface JsonResourceMeta {
4
9
  current_page: number;
5
10
  from: number;
@@ -11,6 +16,9 @@ export interface JsonResourceMeta {
11
16
  total: number;
12
17
  }
13
18
 
19
+ /**
20
+ * Interface representing the structure of a JSON resource collection response with pagination links, following Laravel's default JSON Resource format.
21
+ */
14
22
  export interface JsonResourceLinks {
15
23
  first: string | null;
16
24
  last: string | null;
@@ -18,8 +26,30 @@ export interface JsonResourceLinks {
18
26
  next: string | null;
19
27
  }
20
28
 
29
+ /**
30
+ * Interface representing a paginated JSON resource collection response, following Laravel's default JSON Resource format.
31
+ *
32
+ * This structure includes the paginated data array, along with the pagination metadata and links as defined by Laravel's default JSON Resource responses.
33
+ */
21
34
  export interface JsonResourcePaginator<T> {
22
35
  data: T[];
23
36
  meta: JsonResourceMeta;
24
37
  links: JsonResourceLinks;
25
38
  }
39
+
40
+ /**
41
+ * Interface representing an anonymous JSON resource collection response, following Laravel's default JSON Resource format.
42
+ */
43
+ export interface AnonymousResourceCollection<T> {
44
+ data: T[];
45
+ }
46
+
47
+ /**
48
+ * Interface representing a paginated JSON resource collection response with pagination metadata and links, following Laravel's default JSON Resource format.
49
+ *
50
+ * This interface is meant to extend basic collection resources with pagination information.
51
+ */
52
+ export interface ResourcePagination {
53
+ meta: JsonResourceMeta;
54
+ links: JsonResourceLinks;
55
+ }
@@ -0,0 +1,599 @@
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
+ * `TPageProps` is a phantom generic — it is not present in the object shape.
130
+ * It is carried by `DefineRouteResult` and readable via `InferPageProps<T>`.
131
+ */
132
+ export type RouteMetadata<
133
+ TMethods extends readonly string[] = readonly string[],
134
+ TArgs extends readonly RouteArgMeta[] = readonly RouteArgMeta[],
135
+ TComponent extends RouteComponentType | undefined = undefined,
136
+ TPageProps = never,
137
+ > = {
138
+ readonly name?: string | null;
139
+ readonly url: string;
140
+ readonly domain?: string | null;
141
+ readonly methods: TMethods;
142
+ readonly args?: TArgs;
143
+ readonly component?: TComponent;
144
+ };
145
+
146
+ /**
147
+ * Helper type: check if all args in a tuple are optional.
148
+ */
149
+ type AllArgsOptional<TArgs extends readonly RouteArgMeta[]> = {
150
+ [I in keyof TArgs]: TArgs[I] extends { readonly required: false }
151
+ ? true
152
+ : false;
153
+ }[number] extends true
154
+ ? true
155
+ : false;
156
+
157
+ /**
158
+ * Callable signatures for routes with args.
159
+ */
160
+ type RouteCallableWithArgs<
161
+ TMethod extends string,
162
+ TArgs extends readonly RouteArgMeta[],
163
+ > =
164
+ AllArgsOptional<TArgs> extends true
165
+ ? {
166
+ (
167
+ args?: ArgsObject<TArgs> & Record<string, unknown>,
168
+ options?: RouteQueryOptions,
169
+ ): RouteCallResult<TMethod>;
170
+ (
171
+ args: (string | number | Record<string, unknown>)[],
172
+ options?: RouteQueryOptions,
173
+ ): RouteCallResult<TMethod>;
174
+ (
175
+ ...args: [...PositionalTuple<TArgs>, RouteQueryOptions]
176
+ ): RouteCallResult<TMethod>;
177
+ (...args: PositionalTuple<TArgs>): RouteCallResult<TMethod>;
178
+ }
179
+ : {
180
+ (
181
+ args: ArgsObject<TArgs> & Record<string, unknown>,
182
+ options?: RouteQueryOptions,
183
+ ): RouteCallResult<TMethod>;
184
+ (
185
+ args: (string | number | Record<string, unknown>)[],
186
+ options?: RouteQueryOptions,
187
+ ): RouteCallResult<TMethod>;
188
+ (
189
+ ...args: [...PositionalTuple<TArgs>, RouteQueryOptions]
190
+ ): RouteCallResult<TMethod>;
191
+ (...args: PositionalTuple<TArgs>): RouteCallResult<TMethod>;
192
+ };
193
+
194
+ /**
195
+ * Callable signatures for routes without args.
196
+ */
197
+ type RouteCallableNoArgs<TMethod extends string> = {
198
+ (options?: RouteQueryOptions): RouteCallResult<TMethod>;
199
+ };
200
+
201
+ /**
202
+ * URL method signatures for routes with args.
203
+ */
204
+ type RouteUrlWithArgs<TArgs extends readonly RouteArgMeta[]> =
205
+ AllArgsOptional<TArgs> extends true
206
+ ? {
207
+ (
208
+ args?: ArgsObject<TArgs> & Record<string, unknown>,
209
+ options?: RouteQueryOptions,
210
+ ): string;
211
+ (
212
+ args: (string | number | Record<string, unknown>)[],
213
+ options?: RouteQueryOptions,
214
+ ): string;
215
+ (...args: [...PositionalTuple<TArgs>, RouteQueryOptions]): string;
216
+ (...args: PositionalTuple<TArgs>): string;
217
+ }
218
+ : {
219
+ (
220
+ args: ArgsObject<TArgs> & Record<string, unknown>,
221
+ options?: RouteQueryOptions,
222
+ ): string;
223
+ (
224
+ args: (string | number | Record<string, unknown>)[],
225
+ options?: RouteQueryOptions,
226
+ ): string;
227
+ (...args: [...PositionalTuple<TArgs>, RouteQueryOptions]): string;
228
+ (...args: PositionalTuple<TArgs>): string;
229
+ };
230
+
231
+ /**
232
+ * URL method signatures for routes without args.
233
+ */
234
+ type RouteUrlNoArgs = {
235
+ (options?: RouteQueryOptions): string;
236
+ };
237
+
238
+ /**
239
+ * Per-verb method types for routes with args.
240
+ */
241
+ type VerbMethodsWithArgs<
242
+ TMethods extends readonly string[],
243
+ TArgs extends readonly RouteArgMeta[],
244
+ > = {
245
+ [K in TMethods[number]]: RouteCallableWithArgs<K, TArgs>;
246
+ };
247
+
248
+ /**
249
+ * Per-verb method types for routes without args.
250
+ */
251
+ type VerbMethodsNoArgs<TMethods extends readonly string[]> = {
252
+ [K in TMethods[number]]: RouteCallableNoArgs<K>;
253
+ };
254
+
255
+ /**
256
+ * The full return type of `defineRoute` for routes with args.
257
+ */
258
+ export type DefineRouteResultWithArgs<
259
+ TMethods extends readonly string[],
260
+ TArgs extends readonly RouteArgMeta[],
261
+ TComponent extends RouteComponentType | undefined = undefined,
262
+ TPageProps = never,
263
+ > = RouteCallableWithArgs<TMethods[0], TArgs> & {
264
+ url: RouteUrlWithArgs<TArgs>;
265
+ definition: RouteMetadata<TMethods, TArgs, TComponent, TPageProps>;
266
+ form: FormWithArgs<TMethods, TArgs>;
267
+ toString(): string;
268
+ readonly _pageProps?: TPageProps;
269
+ } & VerbMethodsWithArgs<TMethods, TArgs> &
270
+ ComponentMixin<TComponent, TMethods, TArgs>;
271
+
272
+ /**
273
+ * The full return type of `defineRoute` for routes without args.
274
+ */
275
+ export type DefineRouteResultNoArgs<
276
+ TMethods extends readonly string[],
277
+ TComponent extends RouteComponentType | undefined = undefined,
278
+ TPageProps = never,
279
+ > = RouteCallableNoArgs<TMethods[0]> & {
280
+ url: RouteUrlNoArgs;
281
+ definition: RouteMetadata<TMethods, readonly [], TComponent, TPageProps>;
282
+ form: FormNoArgs<TMethods>;
283
+ toString(): string;
284
+ readonly _pageProps?: TPageProps;
285
+ } & VerbMethodsNoArgs<TMethods> &
286
+ ComponentMixin<TComponent, TMethods, readonly []>;
287
+
288
+ /**
289
+ * The full return type of `defineRoute`.
290
+ * Discriminates on whether `args` is present in metadata.
291
+ *
292
+ * `TPageProps` is a phantom generic for Inertia page prop typing.
293
+ * It defaults to `never` and is populated when a generated route file
294
+ * emits an explicit type annotation:
295
+ * ```typescript
296
+ * export const dashboard: DefineRouteResult<readonly ['get'], readonly [], 'Dashboard', DashboardPageProps> = defineRoute({...})
297
+ * ```
298
+ */
299
+ export type DefineRouteResult<
300
+ TMethods extends readonly string[] = readonly string[],
301
+ TArgs extends readonly RouteArgMeta[] = readonly RouteArgMeta[],
302
+ TComponent extends RouteComponentType | undefined = undefined,
303
+ TPageProps = never,
304
+ > = [TArgs] extends [readonly []] | [readonly never[]]
305
+ ? DefineRouteResultNoArgs<TMethods, TComponent, TPageProps>
306
+ : DefineRouteResultWithArgs<TMethods, TArgs, TComponent, TPageProps>;
307
+
308
+ /**
309
+ * The result of calling `.form()` — contains action (URL), method, and toString().
310
+ */
311
+ export type RouteFormResult<TMethod extends string = string> = {
312
+ readonly action: string;
313
+ readonly method: TMethod extends "get" | "head" ? "get" : "post";
314
+ toString(): string;
315
+ };
316
+
317
+ /**
318
+ * The result of calling `.withComponent()` — route call result enriched with a component.
319
+ */
320
+ export type RouteCallResultWithComponent<
321
+ TComponent extends string = string,
322
+ TMethod extends string = string,
323
+ > = RouteCallResult<TMethod> & {
324
+ readonly component: TComponent;
325
+ };
326
+
327
+ /**
328
+ * WithComponent callable for single-component routes without args.
329
+ */
330
+ type WithComponentSingleNoArgs<
331
+ TComponent extends string,
332
+ TMethod extends string,
333
+ > = {
334
+ (
335
+ options?: RouteQueryOptions,
336
+ ): RouteCallResultWithComponent<TComponent, TMethod>;
337
+ };
338
+
339
+ /**
340
+ * WithComponent callable for single-component routes with args.
341
+ */
342
+ type WithComponentSingleWithArgs<
343
+ TComponent extends string,
344
+ TMethod extends string,
345
+ TArgs extends readonly RouteArgMeta[],
346
+ > =
347
+ AllArgsOptional<TArgs> extends true
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
+ args: ArgsObject<TArgs> & Record<string, unknown>,
367
+ options?: RouteQueryOptions,
368
+ ): RouteCallResultWithComponent<TComponent, TMethod>;
369
+ (
370
+ args: (string | number | Record<string, unknown>)[],
371
+ options?: RouteQueryOptions,
372
+ ): RouteCallResultWithComponent<TComponent, TMethod>;
373
+ (
374
+ ...args: [...PositionalTuple<TArgs>, RouteQueryOptions]
375
+ ): RouteCallResultWithComponent<TComponent, TMethod>;
376
+ (
377
+ ...args: PositionalTuple<TArgs>
378
+ ): RouteCallResultWithComponent<TComponent, TMethod>;
379
+ };
380
+
381
+ /**
382
+ * WithComponent callable for multi-component routes without args.
383
+ * First argument selects which component to use.
384
+ */
385
+ type WithComponentMultiNoArgs<
386
+ TComponent extends Readonly<Record<string, string>>,
387
+ TMethod extends string,
388
+ > = {
389
+ (
390
+ component: TComponent[keyof TComponent],
391
+ options?: RouteQueryOptions,
392
+ ): RouteCallResultWithComponent<TComponent[keyof TComponent], TMethod>;
393
+ };
394
+
395
+ /**
396
+ * WithComponent callable for multi-component routes with args.
397
+ * First argument selects which component, followed by the same calling
398
+ * conventions as the route itself (named object, array, positional spread).
399
+ */
400
+ type WithComponentMultiWithArgs<
401
+ TComponent extends Readonly<Record<string, string>>,
402
+ TMethod extends string,
403
+ TArgs extends readonly RouteArgMeta[],
404
+ > =
405
+ AllArgsOptional<TArgs> extends true
406
+ ? {
407
+ (
408
+ component: TComponent[keyof TComponent],
409
+ args?: ArgsObject<TArgs> & Record<string, unknown>,
410
+ options?: RouteQueryOptions,
411
+ ): RouteCallResultWithComponent<
412
+ TComponent[keyof TComponent],
413
+ TMethod
414
+ >;
415
+ (
416
+ component: TComponent[keyof TComponent],
417
+ args: (string | number | Record<string, unknown>)[],
418
+ options?: RouteQueryOptions,
419
+ ): RouteCallResultWithComponent<
420
+ TComponent[keyof TComponent],
421
+ TMethod
422
+ >;
423
+ (
424
+ component: TComponent[keyof TComponent],
425
+ ...args: [...PositionalTuple<TArgs>, RouteQueryOptions]
426
+ ): RouteCallResultWithComponent<
427
+ TComponent[keyof TComponent],
428
+ TMethod
429
+ >;
430
+ (
431
+ component: TComponent[keyof TComponent],
432
+ ...args: PositionalTuple<TArgs>
433
+ ): RouteCallResultWithComponent<
434
+ TComponent[keyof TComponent],
435
+ TMethod
436
+ >;
437
+ }
438
+ : {
439
+ (
440
+ component: TComponent[keyof TComponent],
441
+ args: ArgsObject<TArgs> & Record<string, unknown>,
442
+ options?: RouteQueryOptions,
443
+ ): RouteCallResultWithComponent<
444
+ TComponent[keyof TComponent],
445
+ TMethod
446
+ >;
447
+ (
448
+ component: TComponent[keyof TComponent],
449
+ args: (string | number | Record<string, unknown>)[],
450
+ options?: RouteQueryOptions,
451
+ ): RouteCallResultWithComponent<
452
+ TComponent[keyof TComponent],
453
+ TMethod
454
+ >;
455
+ (
456
+ component: TComponent[keyof TComponent],
457
+ ...args: [...PositionalTuple<TArgs>, RouteQueryOptions]
458
+ ): RouteCallResultWithComponent<
459
+ TComponent[keyof TComponent],
460
+ TMethod
461
+ >;
462
+ (
463
+ component: TComponent[keyof TComponent],
464
+ ...args: PositionalTuple<TArgs>
465
+ ): RouteCallResultWithComponent<
466
+ TComponent[keyof TComponent],
467
+ TMethod
468
+ >;
469
+ };
470
+
471
+ /**
472
+ * Mixin that conditionally adds `.component` and `.withComponent` to a route result.
473
+ *
474
+ * - When TComponent is `string`: single-component route with typed `.component` and `.withComponent`.
475
+ * - When TComponent is `Record<string, string>`: multi-component route with component map and selector.
476
+ * - When TComponent is `undefined`: no component properties added (empty intersection).
477
+ */
478
+ type ComponentMixin<
479
+ TComponent extends RouteComponentType | undefined,
480
+ TMethods extends readonly string[],
481
+ TArgs extends readonly RouteArgMeta[],
482
+ > = TComponent extends string
483
+ ? {
484
+ readonly component: TComponent;
485
+ withComponent: [TArgs] extends [readonly []] | [readonly never[]]
486
+ ? WithComponentSingleNoArgs<TComponent, TMethods[0]>
487
+ : WithComponentSingleWithArgs<TComponent, TMethods[0], TArgs>;
488
+ }
489
+ : TComponent extends Readonly<Record<string, string>>
490
+ ? {
491
+ readonly component: TComponent;
492
+ withComponent: [TArgs] extends [readonly []] | [readonly never[]]
493
+ ? WithComponentMultiNoArgs<TComponent, TMethods[0]>
494
+ : WithComponentMultiWithArgs<TComponent, TMethods[0], TArgs>;
495
+ }
496
+ : Record<never, never>;
497
+
498
+ /**
499
+ * Form callable signatures for routes with args.
500
+ */
501
+ type FormCallableWithArgs<
502
+ TMethod extends string,
503
+ TArgs extends readonly RouteArgMeta[],
504
+ > =
505
+ AllArgsOptional<TArgs> extends true
506
+ ? {
507
+ (
508
+ args?: ArgsObject<TArgs> & Record<string, unknown>,
509
+ options?: RouteQueryOptions,
510
+ ): RouteFormResult<TMethod>;
511
+ (
512
+ args: (string | number | Record<string, unknown>)[],
513
+ options?: RouteQueryOptions,
514
+ ): RouteFormResult<TMethod>;
515
+ (
516
+ ...args: [...PositionalTuple<TArgs>, RouteQueryOptions]
517
+ ): RouteFormResult<TMethod>;
518
+ (...args: PositionalTuple<TArgs>): RouteFormResult<TMethod>;
519
+ }
520
+ : {
521
+ (
522
+ args: ArgsObject<TArgs> & Record<string, unknown>,
523
+ options?: RouteQueryOptions,
524
+ ): RouteFormResult<TMethod>;
525
+ (
526
+ args: (string | number | Record<string, unknown>)[],
527
+ options?: RouteQueryOptions,
528
+ ): RouteFormResult<TMethod>;
529
+ (
530
+ ...args: [...PositionalTuple<TArgs>, RouteQueryOptions]
531
+ ): RouteFormResult<TMethod>;
532
+ (...args: PositionalTuple<TArgs>): RouteFormResult<TMethod>;
533
+ };
534
+
535
+ /**
536
+ * Form callable signatures for routes without args.
537
+ */
538
+ type FormCallableNoArgs<TMethod extends string> = {
539
+ (options?: RouteQueryOptions): RouteFormResult<TMethod>;
540
+ };
541
+
542
+ /**
543
+ * Per-verb form method types for routes with args.
544
+ */
545
+ type FormVerbMethodsWithArgs<
546
+ TMethods extends readonly string[],
547
+ TArgs extends readonly RouteArgMeta[],
548
+ > = {
549
+ [K in TMethods[number]]: FormCallableWithArgs<K, TArgs>;
550
+ };
551
+
552
+ /**
553
+ * Per-verb form method types for routes without args.
554
+ */
555
+ type FormVerbMethodsNoArgs<TMethods extends readonly string[]> = {
556
+ [K in TMethods[number]]: FormCallableNoArgs<K>;
557
+ };
558
+
559
+ /**
560
+ * The `.form` property on a route with args — callable + per-verb sub-methods.
561
+ */
562
+ type FormWithArgs<
563
+ TMethods extends readonly string[],
564
+ TArgs extends readonly RouteArgMeta[],
565
+ > = FormCallableWithArgs<TMethods[0], TArgs> &
566
+ FormVerbMethodsWithArgs<TMethods, TArgs>;
567
+
568
+ /**
569
+ * The `.form` property on a route without args — callable + per-verb sub-methods.
570
+ */
571
+ type FormNoArgs<TMethods extends readonly string[]> = FormCallableNoArgs<
572
+ TMethods[0]
573
+ > &
574
+ FormVerbMethodsNoArgs<TMethods>;
575
+
576
+ /**
577
+ * Infer the Inertia page props type from a `DefineRouteResult`.
578
+ *
579
+ * Returns the `TPageProps` generic. Returns `never` when the route const was
580
+ * not annotated with an explicit page props type (i.e., the default).
581
+ *
582
+ * Reads the `_pageProps` phantom property directly to avoid TypeScript's
583
+ * deferred conditional-type inference limitations with `DefineRouteResult`.
584
+ *
585
+ * @example
586
+ * ```typescript
587
+ * import type { DashboardPageProps } from './inertia-controller';
588
+ * import type { InferPageProps } from '@tolki/ts';
589
+ *
590
+ * type Props = InferPageProps<typeof dashboard>; // DashboardPageProps
591
+ * ```
592
+ */
593
+ export type InferPageProps<T> = T extends {
594
+ readonly _pageProps?: infer TPageProps;
595
+ }
596
+ ? [TPageProps] extends [never]
597
+ ? never
598
+ : TPageProps
599
+ : never;
package/src/utils.d.ts CHANGED
@@ -0,0 +1 @@
1
+ export {};