@@ -14,7 +14,6 @@ import type {
14
14
ResolveValidatorInput ,
15
15
ValidateSerializable ,
16
16
ValidateSerializableInput ,
17
- ValidateSerializableInputResult ,
18
17
Validator ,
19
18
} from '@tanstack/router-core'
20
19
import type { JsonResponse } from '@tanstack/router-core/ssr/client'
@@ -174,7 +173,7 @@ export async function executeMiddleware(
174
173
env : 'client' | 'server' ,
175
174
opts : ServerFnMiddlewareOptions ,
176
175
) : Promise < ServerFnMiddlewareResult > {
177
- const globalMiddlewares = getStartOptions ( ) . functionMiddleware || [ ]
176
+ const globalMiddlewares = getStartOptions ( ) ? .functionMiddleware || [ ]
178
177
const flattenedMiddlewares = flattenMiddlewares ( [
179
178
...globalMiddlewares ,
180
179
...middlewares ,
@@ -243,10 +242,10 @@ export type CompiledFetcherFnOptions = {
243
242
context ?: any
244
243
}
245
244
246
- export type Fetcher < TRegister , TMiddlewares , TInputValidator , TResponse > =
245
+ export type Fetcher < TMiddlewares , TInputValidator , TResponse > =
247
246
undefined extends IntersectAllValidatorInputs < TMiddlewares , TInputValidator >
248
- ? OptionalFetcher < TRegister , TMiddlewares , TInputValidator , TResponse >
249
- : RequiredFetcher < TRegister , TMiddlewares , TInputValidator , TResponse >
247
+ ? OptionalFetcher < TMiddlewares , TInputValidator , TResponse >
248
+ : RequiredFetcher < TMiddlewares , TInputValidator , TResponse >
250
249
251
250
export interface FetcherBase {
252
251
[ TSS_SERVER_FUNCTION ] : true
@@ -260,26 +259,18 @@ export interface FetcherBase {
260
259
} ) => Promise < unknown >
261
260
}
262
261
263
- export interface OptionalFetcher <
264
- TRegister ,
265
- TMiddlewares ,
266
- TInputValidator ,
267
- TResponse ,
268
- > extends FetcherBase {
262
+ export interface OptionalFetcher < TMiddlewares , TInputValidator , TResponse >
263
+ extends FetcherBase {
269
264
(
270
265
options ?: OptionalFetcherDataOptions < TMiddlewares , TInputValidator > ,
271
- ) : Promise < FetcherData < TRegister , TResponse > >
266
+ ) : Promise < FetcherData < TResponse > >
272
267
}
273
268
274
- export interface RequiredFetcher <
275
- TRegister ,
276
- TMiddlewares ,
277
- TInputValidator ,
278
- TResponse ,
279
- > extends FetcherBase {
269
+ export interface RequiredFetcher < TMiddlewares , TInputValidator , TResponse >
270
+ extends FetcherBase {
280
271
(
281
272
opts : RequiredFetcherDataOptions < TMiddlewares , TInputValidator > ,
282
- ) : Promise < FetcherData < TRegister , TResponse > >
273
+ ) : Promise < FetcherData < TResponse > >
283
274
}
284
275
285
276
export type FetcherBaseOptions = {
@@ -297,22 +288,23 @@ export interface RequiredFetcherDataOptions<TMiddlewares, TInputValidator>
297
288
data : Expand < IntersectAllValidatorInputs < TMiddlewares , TInputValidator > >
298
289
}
299
290
300
- export type FetcherData < TRegister , TResponse > = TResponse extends Response
301
- ? Response
302
- : TResponse extends JsonResponse < any >
303
- ? ValidateSerializableInputResult < TRegister , ReturnType < TResponse [ 'json' ] > >
304
- : ValidateSerializableInputResult < TRegister , TResponse >
305
-
306
291
export type RscStream < T > = {
307
292
__cacheState : T
308
293
}
309
294
310
295
export type Method = 'GET' | 'POST'
311
296
297
+ export type FetcherData < TResponse > =
298
+ Awaited < TResponse > extends Response
299
+ ? Awaited < TResponse >
300
+ : Awaited < TResponse > extends JsonResponse < any >
301
+ ? ReturnType < Awaited < TResponse > [ 'json' ] >
302
+ : Awaited < TResponse >
303
+
312
304
export type ServerFnReturnType < TRegister , TResponse > =
313
- | Response
314
- | Promise < ValidateSerializableInput < TRegister , TResponse > >
315
- | ValidateSerializableInput < TRegister , TResponse >
305
+ Awaited < TResponse > extends Response
306
+ ? TResponse
307
+ : ValidateSerializableInput < TRegister , TResponse >
316
308
317
309
export type ServerFn <
318
310
TRegister ,
@@ -521,7 +513,7 @@ export interface ServerFnHandler<
521
513
TInputValidator ,
522
514
TNewResponse
523
515
> ,
524
- ) => Fetcher < TRegister , TMiddlewares , TInputValidator , TNewResponse >
516
+ ) => Fetcher < TMiddlewares , TInputValidator , TNewResponse >
525
517
}
526
518
527
519
export interface ServerFnBuilder < TRegister , TMethod extends Method = 'GET' >
0 commit comments