@@ -12,20 +12,23 @@ import type {
12
12
AssignAllServerContext ,
13
13
} from '@tanstack/start-client-core'
14
14
15
- type TODO = any
16
-
17
15
export function createServerFileRoute <
18
- TParentRoute extends AnyServerRouteWithTypes ,
19
- TId extends RouteConstraints [ 'TId' ] ,
20
- TPath extends RouteConstraints [ 'TPath' ] ,
21
- TFullPath extends RouteConstraints [ 'TFullPath' ] ,
22
- TChildren ,
23
- > ( __ ?: never ) : ServerRoute < TParentRoute , TId , TPath , TFullPath , TChildren > {
16
+ TFilePath extends keyof FileRoutesByPath ,
17
+ TParentRoute extends
18
+ AnyServerRouteWithTypes = FileRoutesByPath [ TFilePath ] [ 'parentRoute' ] ,
19
+ TId extends RouteConstraints [ 'TId' ] = FileRoutesByPath [ TFilePath ] [ 'id' ] ,
20
+ TPath extends RouteConstraints [ 'TPath' ] = FileRoutesByPath [ TFilePath ] [ 'path' ] ,
21
+ TFullPath extends
22
+ RouteConstraints [ 'TFullPath' ] = FileRoutesByPath [ TFilePath ] [ 'fullPath' ] ,
23
+ TChildren = FileRoutesByPath [ TFilePath ] [ 'children' ] ,
24
+ > ( _ : TFilePath ) : ServerRoute < TParentRoute , TId , TPath , TFullPath , TChildren > {
24
25
return createServerRoute < TParentRoute , TId , TPath , TFullPath , TChildren > (
25
26
undefined ,
26
27
)
27
28
}
28
29
30
+ export interface FileRoutesByPath { }
31
+
29
32
export interface ServerRouteOptions <
30
33
TParentRoute extends AnyServerRouteWithTypes ,
31
34
TId extends RouteConstraints [ 'TId' ] ,
@@ -70,16 +73,29 @@ export function createServerRoute<
70
73
id : '' as TId ,
71
74
fullPath : '' as TFullPath ,
72
75
to : '' as TrimPathRight < TFullPath > ,
73
- options : options as TODO ,
76
+ options : options as ServerRouteOptions <
77
+ TParentRoute ,
78
+ TId ,
79
+ TPath ,
80
+ TFullPath ,
81
+ any
82
+ > ,
74
83
parentRoute : undefined as unknown as TParentRoute ,
75
- _types : { } as TODO ,
84
+ _types : { } as ServerRouteTypes <
85
+ TParentRoute ,
86
+ TId ,
87
+ TPath ,
88
+ TFullPath ,
89
+ undefined ,
90
+ undefined
91
+ > ,
76
92
// children: undefined as TChildren,
77
- middleware : ( middlewares : TODO ) =>
93
+ middleware : ( middlewares ) =>
78
94
createServerRoute ( undefined , {
79
95
...options ,
80
96
middleware : middlewares ,
81
- } ) as TODO ,
82
- methods : ( methodsOrGetMethods : TODO ) => {
97
+ } ) as never ,
98
+ methods : ( methodsOrGetMethods ) => {
83
99
const methods = ( ( ) => {
84
100
if ( typeof methodsOrGetMethods === 'function' ) {
85
101
return methodsOrGetMethods ( createMethodBuilder ( ) )
@@ -90,14 +106,14 @@ export function createServerRoute<
90
106
91
107
return createServerRoute ( undefined , {
92
108
...__opts ,
93
- methods,
94
- } ) as TODO
109
+ methods : methods as never ,
110
+ } ) as never
95
111
} ,
96
112
update : ( opts ) =>
97
113
createServerRoute ( undefined , {
98
114
...options ,
99
115
...opts ,
100
- } ) as TODO ,
116
+ } ) ,
101
117
init : ( opts : { originalIndex : number } ) : void => {
102
118
options . originalIndex = opts . originalIndex
103
119
@@ -149,14 +165,14 @@ export function createServerRoute<
149
165
150
166
_addFileChildren : ( children ) => {
151
167
if ( Array . isArray ( children ) ) {
152
- route . children = children as TChildren as TODO
168
+ route . children = children as TChildren
153
169
}
154
170
155
171
if ( typeof children === 'object' && children !== null ) {
156
- route . children = Object . values ( children ) as TChildren as TODO
172
+ route . children = Object . values ( children ) as TChildren
157
173
}
158
174
159
- return route as any
175
+ return route
160
176
} ,
161
177
162
178
_addFileTypes : < TFileTypes > ( ) => route ,
@@ -190,33 +206,57 @@ const createMethodBuilder = <
190
206
TFullPath extends string ,
191
207
TMiddlewares ,
192
208
> (
193
- __opts ?: TODO ,
209
+ __opts ?: ServerRouteMethodBuilderOptions <
210
+ TParentRoute ,
211
+ TFullPath ,
212
+ TMiddlewares ,
213
+ unknown ,
214
+ unknown
215
+ > ,
194
216
) : ServerRouteMethodBuilder < TParentRoute , TFullPath , TMiddlewares > => {
195
217
return {
196
- _options : __opts || { } ,
197
- _types : { } as TODO ,
218
+ _options : ( __opts || { } ) as never ,
219
+ _types : { } as never ,
198
220
middleware : ( middlewares ) =>
199
221
createMethodBuilder ( {
200
222
...__opts ,
201
223
middlewares,
202
- } ) as TODO ,
224
+ } ) as never ,
203
225
handler : ( handler ) =>
204
226
createMethodBuilder ( {
205
227
...__opts ,
206
- handler,
207
- } ) as TODO ,
228
+ handler : handler as never ,
229
+ } ) as never ,
208
230
}
209
231
}
210
232
233
+ export interface ServerRouteMethodBuilderOptions <
234
+ TParentRoute extends AnyServerRouteWithTypes ,
235
+ TFullPath extends string ,
236
+ TMiddlewares ,
237
+ TMethodMiddlewares ,
238
+ TResponse ,
239
+ > {
240
+ handler ?: ServerRouteMethodHandlerFn <
241
+ TParentRoute ,
242
+ TFullPath ,
243
+ TMiddlewares ,
244
+ TMethodMiddlewares ,
245
+ TResponse
246
+ >
247
+ middlewares ?: Constrain <
248
+ TMethodMiddlewares ,
249
+ ReadonlyArray < AnyRequestMiddleware >
250
+ >
251
+ }
252
+
211
253
export type CreateServerFileRoute <
212
254
TParentRoute extends AnyServerRouteWithTypes ,
213
255
TId extends RouteConstraints [ 'TId' ] ,
214
256
TPath extends RouteConstraints [ 'TPath' ] ,
215
257
TFullPath extends RouteConstraints [ 'TFullPath' ] ,
216
258
TChildren ,
217
- > = (
218
- options ?: undefined ,
219
- ) => ServerRoute < TParentRoute , TId , TPath , TFullPath , TChildren >
259
+ > = ( ) => ServerRoute < TParentRoute , TId , TPath , TFullPath , TChildren >
220
260
221
261
export type AnyServerRouteWithTypes = ServerRouteWithTypes <
222
262
any ,
@@ -497,6 +537,7 @@ export type AnyRouteMethodsBuilder = ServerRouteMethodBuilderWithTypes<
497
537
any ,
498
538
any ,
499
539
any ,
540
+ any ,
500
541
any
501
542
>
502
543
@@ -505,6 +546,7 @@ export interface ServerRouteMethodBuilder<
505
546
TFullPath extends string ,
506
547
TMiddlewares ,
507
548
> extends ServerRouteMethodBuilderWithTypes <
549
+ TParentRoute ,
508
550
TFullPath ,
509
551
TMiddlewares ,
510
552
undefined ,
@@ -519,12 +561,19 @@ export interface ServerRouteMethodBuilder<
519
561
> { }
520
562
521
563
export interface ServerRouteMethodBuilderWithTypes <
564
+ TParentRoute extends AnyServerRouteWithTypes ,
522
565
TFullPath extends string ,
523
566
TMiddlewares ,
524
567
TMethodMiddlewares ,
525
568
TResponse ,
526
569
> {
527
- _options : TODO
570
+ _options : ServerRouteMethodBuilderOptions <
571
+ TParentRoute ,
572
+ TFullPath ,
573
+ TMiddlewares ,
574
+ TMethodMiddlewares ,
575
+ TResponse
576
+ >
528
577
_types : ServerRouteMethodBuilderTypes <
529
578
TFullPath ,
530
579
TMiddlewares ,
@@ -569,6 +618,7 @@ export interface ServerRouteMethodBuilderAfterMiddleware<
569
618
TMiddlewares ,
570
619
TMethodMiddlewares ,
571
620
> extends ServerRouteMethodBuilderWithTypes <
621
+ TParentRoute ,
572
622
TFullPath ,
573
623
TMiddlewares ,
574
624
TMethodMiddlewares ,
@@ -611,6 +661,7 @@ export interface ServerRouteMethodBuilderAfterHandler<
611
661
TMethodMiddlewares ,
612
662
TResponse ,
613
663
> extends ServerRouteMethodBuilderWithTypes <
664
+ TParentRoute ,
614
665
TFullPath ,
615
666
TMiddlewares ,
616
667
TMethodMiddlewares ,
0 commit comments