@tanstack/start-server-core 1.120.7 → 1.121.0-alpha.11

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.
Files changed (60) hide show
  1. package/README.md +6 -27
  2. package/dist/cjs/createRequestHandler.cjs +1 -3
  3. package/dist/cjs/createRequestHandler.cjs.map +1 -1
  4. package/dist/cjs/createStartHandler.cjs +268 -31
  5. package/dist/cjs/createStartHandler.cjs.map +1 -1
  6. package/dist/cjs/createStartHandler.d.cts +8 -6
  7. package/dist/cjs/h3.cjs +30 -73
  8. package/dist/cjs/h3.cjs.map +1 -1
  9. package/dist/cjs/h3.d.cts +11 -7
  10. package/dist/cjs/handlerCallback.cjs.map +1 -1
  11. package/dist/cjs/handlerCallback.d.cts +3 -4
  12. package/dist/cjs/index.cjs +17 -14
  13. package/dist/cjs/index.cjs.map +1 -1
  14. package/dist/cjs/index.d.cts +6 -1
  15. package/dist/cjs/router-manifest.cjs +44 -0
  16. package/dist/cjs/router-manifest.cjs.map +1 -0
  17. package/dist/cjs/router-manifest.d.cts +17 -0
  18. package/dist/cjs/server-functions-handler.cjs +145 -0
  19. package/dist/cjs/server-functions-handler.cjs.map +1 -0
  20. package/dist/cjs/server-functions-handler.d.cts +3 -0
  21. package/dist/cjs/serverRoute.cjs +100 -0
  22. package/dist/cjs/serverRoute.cjs.map +1 -0
  23. package/dist/cjs/serverRoute.d.cts +115 -0
  24. package/dist/cjs/ssr-server.cjs +3 -2
  25. package/dist/cjs/ssr-server.cjs.map +1 -1
  26. package/dist/esm/createRequestHandler.js +1 -3
  27. package/dist/esm/createRequestHandler.js.map +1 -1
  28. package/dist/esm/createStartHandler.d.ts +8 -6
  29. package/dist/esm/createStartHandler.js +248 -33
  30. package/dist/esm/createStartHandler.js.map +1 -1
  31. package/dist/esm/h3.d.ts +11 -7
  32. package/dist/esm/h3.js +26 -63
  33. package/dist/esm/h3.js.map +1 -1
  34. package/dist/esm/handlerCallback.d.ts +3 -4
  35. package/dist/esm/handlerCallback.js.map +1 -1
  36. package/dist/esm/index.d.ts +6 -1
  37. package/dist/esm/index.js +14 -5
  38. package/dist/esm/index.js.map +1 -1
  39. package/dist/esm/router-manifest.d.ts +17 -0
  40. package/dist/esm/router-manifest.js +44 -0
  41. package/dist/esm/router-manifest.js.map +1 -0
  42. package/dist/esm/server-functions-handler.d.ts +3 -0
  43. package/dist/esm/server-functions-handler.js +145 -0
  44. package/dist/esm/server-functions-handler.js.map +1 -0
  45. package/dist/esm/serverRoute.d.ts +115 -0
  46. package/dist/esm/serverRoute.js +100 -0
  47. package/dist/esm/serverRoute.js.map +1 -0
  48. package/dist/esm/ssr-server.js +3 -2
  49. package/dist/esm/ssr-server.js.map +1 -1
  50. package/package.json +8 -6
  51. package/src/createRequestHandler.ts +1 -3
  52. package/src/createStartHandler.ts +373 -47
  53. package/src/h3.ts +71 -78
  54. package/src/handlerCallback.ts +5 -12
  55. package/src/index.tsx +11 -1
  56. package/src/router-manifest.ts +79 -0
  57. package/src/server-functions-handler.ts +260 -0
  58. package/src/serverRoute.ts +661 -0
  59. package/src/ssr-server.ts +2 -0
  60. package/src/tanstack-start.d.ts +5 -0
@@ -0,0 +1,661 @@
1
+ import { joinPaths, rootRouteId, trimPathLeft } from '@tanstack/router-core'
2
+ import type {
3
+ Assign,
4
+ Constrain,
5
+ Expand,
6
+ ResolveParams,
7
+ RouteConstraints,
8
+ TrimPathRight,
9
+ } from '@tanstack/router-core'
10
+ import type {
11
+ AnyRequestMiddleware,
12
+ AssignAllServerContext,
13
+ } from '@tanstack/start-client-core'
14
+
15
+ type TODO = any
16
+
17
+ 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> {
24
+ return createServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>(
25
+ undefined,
26
+ )
27
+ }
28
+
29
+ export interface ServerRouteOptions<
30
+ TParentRoute extends AnyServerRouteWithTypes,
31
+ TId extends RouteConstraints['TId'],
32
+ TPath extends RouteConstraints['TPath'],
33
+ TFullPath extends RouteConstraints['TFullPath'],
34
+ TMiddlewares,
35
+ > {
36
+ id: TId
37
+ path: TPath
38
+ pathname: TFullPath
39
+ originalIndex: number
40
+ getParentRoute?: () => TParentRoute
41
+ middleware: Constrain<TMiddlewares, ReadonlyArray<AnyRequestMiddleware>>
42
+ methods: Record<
43
+ string,
44
+ ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, any, any>
45
+ >
46
+ caseSensitive?: boolean
47
+ }
48
+
49
+ export type ServerRouteManifest = {
50
+ middleware: boolean
51
+ methods: Record<string, { middleware: boolean }>
52
+ }
53
+
54
+ export function createServerRoute<
55
+ TParentRoute extends AnyServerRouteWithTypes,
56
+ TId extends RouteConstraints['TId'],
57
+ TPath extends RouteConstraints['TPath'],
58
+ TFullPath extends RouteConstraints['TFullPath'],
59
+ TChildren,
60
+ >(
61
+ __?: never,
62
+ __opts?: Partial<
63
+ ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, undefined>
64
+ >,
65
+ ): ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren> {
66
+ const options = __opts || {}
67
+
68
+ const route: ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren> = {
69
+ path: '' as TPath,
70
+ id: '' as TId,
71
+ fullPath: '' as TFullPath,
72
+ to: '' as TrimPathRight<TFullPath>,
73
+ options: options as TODO,
74
+ parentRoute: undefined as unknown as TParentRoute,
75
+ _types: {} as TODO,
76
+ // children: undefined as TChildren,
77
+ middleware: (middlewares: TODO) =>
78
+ createServerRoute(undefined, {
79
+ ...options,
80
+ middleware: middlewares,
81
+ }) as TODO,
82
+ methods: (methodsOrGetMethods: TODO) => {
83
+ const methods = (() => {
84
+ if (typeof methodsOrGetMethods === 'function') {
85
+ return methodsOrGetMethods(createMethodBuilder())
86
+ }
87
+
88
+ return methodsOrGetMethods
89
+ })()
90
+
91
+ return createServerRoute(undefined, {
92
+ ...__opts,
93
+ methods,
94
+ }) as TODO
95
+ },
96
+ update: (opts) =>
97
+ createServerRoute(undefined, {
98
+ ...options,
99
+ ...opts,
100
+ }) as TODO,
101
+ init: (opts: { originalIndex: number }): void => {
102
+ options.originalIndex = opts.originalIndex
103
+
104
+ const isRoot = !options.path && !options.id
105
+
106
+ route.parentRoute = options.getParentRoute?.() as TParentRoute
107
+
108
+ if (isRoot) {
109
+ route.path = rootRouteId as TPath
110
+ } else if (!(route.parentRoute as any)) {
111
+ throw new Error(
112
+ `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a ServerRoute instance.`,
113
+ )
114
+ }
115
+
116
+ let path: undefined | string = isRoot ? rootRouteId : options.path
117
+
118
+ // If the path is anything other than an index path, trim it up
119
+ if (path && path !== '/') {
120
+ path = trimPathLeft(path)
121
+ }
122
+
123
+ const customId = options.id || path
124
+
125
+ // Strip the parentId prefix from the first level of children
126
+ let id = isRoot
127
+ ? rootRouteId
128
+ : joinPaths([
129
+ route.parentRoute.id === rootRouteId ? '' : route.parentRoute.id,
130
+ customId,
131
+ ])
132
+
133
+ if (path === rootRouteId) {
134
+ path = '/'
135
+ }
136
+
137
+ if (id !== rootRouteId) {
138
+ id = joinPaths(['/', id])
139
+ }
140
+
141
+ const fullPath =
142
+ id === rootRouteId ? '/' : joinPaths([route.parentRoute.fullPath, path])
143
+
144
+ route.path = path as TPath
145
+ route.id = id as TId
146
+ route.fullPath = fullPath as TFullPath
147
+ route.to = fullPath as TrimPathRight<TFullPath>
148
+ },
149
+
150
+ _addFileChildren: (children) => {
151
+ if (Array.isArray(children)) {
152
+ route.children = children as TChildren as TODO
153
+ }
154
+
155
+ if (typeof children === 'object' && children !== null) {
156
+ route.children = Object.values(children) as TChildren as TODO
157
+ }
158
+
159
+ return route as any
160
+ },
161
+
162
+ _addFileTypes: <TFileTypes>() => route,
163
+ }
164
+
165
+ return route
166
+ }
167
+
168
+ export type ServerRouteAddFileChildrenFn<
169
+ in out TParentRoute extends AnyServerRouteWithTypes,
170
+ in out TId extends RouteConstraints['TId'],
171
+ in out TPath extends RouteConstraints['TPath'],
172
+ in out TFullPath extends RouteConstraints['TFullPath'],
173
+ in out TMiddlewares,
174
+ in out TMethods,
175
+ in out TChildren,
176
+ > = (
177
+ children: TChildren,
178
+ ) => ServerRouteWithTypes<
179
+ TParentRoute,
180
+ TId,
181
+ TPath,
182
+ TFullPath,
183
+ TMiddlewares,
184
+ TMethods,
185
+ TChildren
186
+ >
187
+
188
+ const createMethodBuilder = <
189
+ TParentRoute extends AnyServerRouteWithTypes,
190
+ TFullPath extends string,
191
+ TMiddlewares,
192
+ >(
193
+ __opts?: TODO,
194
+ ): ServerRouteMethodBuilder<TParentRoute, TFullPath, TMiddlewares> => {
195
+ return {
196
+ _options: __opts || {},
197
+ _types: {} as TODO,
198
+ middleware: (middlewares) =>
199
+ createMethodBuilder({
200
+ ...__opts,
201
+ middlewares,
202
+ }) as TODO,
203
+ handler: (handler) =>
204
+ createMethodBuilder({
205
+ ...__opts,
206
+ handler,
207
+ }) as TODO,
208
+ }
209
+ }
210
+
211
+ export type CreateServerFileRoute<
212
+ TParentRoute extends AnyServerRouteWithTypes,
213
+ TId extends RouteConstraints['TId'],
214
+ TPath extends RouteConstraints['TPath'],
215
+ TFullPath extends RouteConstraints['TFullPath'],
216
+ TChildren,
217
+ > = (
218
+ options?: undefined,
219
+ ) => ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>
220
+
221
+ export type AnyServerRouteWithTypes = ServerRouteWithTypes<
222
+ any,
223
+ any,
224
+ any,
225
+ any,
226
+ any,
227
+ any,
228
+ any
229
+ >
230
+
231
+ export interface ServerRouteWithTypes<
232
+ TParentRoute extends AnyServerRouteWithTypes,
233
+ TId extends RouteConstraints['TId'],
234
+ TPath extends RouteConstraints['TPath'],
235
+ TFullPath extends RouteConstraints['TFullPath'],
236
+ TMiddlewares,
237
+ TMethods,
238
+ TChildren,
239
+ > {
240
+ _types: ServerRouteTypes<
241
+ TParentRoute,
242
+ TId,
243
+ TPath,
244
+ TFullPath,
245
+ TMiddlewares,
246
+ TMethods
247
+ >
248
+ path: TPath
249
+ id: TId
250
+ fullPath: TFullPath
251
+ to: TrimPathRight<TFullPath>
252
+ parentRoute: TParentRoute
253
+ children?: TChildren
254
+ options: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, TMiddlewares>
255
+ update: (
256
+ opts: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, undefined>,
257
+ ) => ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>
258
+ init: (opts: { originalIndex: number }) => void
259
+ _addFileChildren: ServerRouteAddFileChildrenFn<
260
+ TParentRoute,
261
+ TId,
262
+ TPath,
263
+ TFullPath,
264
+ TMiddlewares,
265
+ TMethods,
266
+ TChildren
267
+ >
268
+ _addFileTypes: () => ServerRouteWithTypes<
269
+ TParentRoute,
270
+ TId,
271
+ TPath,
272
+ TFullPath,
273
+ TMiddlewares,
274
+ TMethods,
275
+ TChildren
276
+ >
277
+ }
278
+
279
+ export interface ServerRouteTypes<
280
+ TParentRoute extends AnyServerRouteWithTypes,
281
+ TId extends RouteConstraints['TId'],
282
+ TPath extends RouteConstraints['TPath'],
283
+ TFullPath extends RouteConstraints['TFullPath'],
284
+ TMiddlewares,
285
+ TMethods,
286
+ > {
287
+ id: TId
288
+ path: TPath
289
+ fullPath: TFullPath
290
+ middlewares: TMiddlewares
291
+ methods: TMethods
292
+ parentRoute: TParentRoute
293
+ allContext: ResolveAllServerContext<TParentRoute, TMiddlewares>
294
+ }
295
+
296
+ export type ResolveAllServerContext<
297
+ TParentRoute extends AnyServerRouteWithTypes,
298
+ TMiddlewares,
299
+ > = unknown extends TParentRoute
300
+ ? AssignAllServerContext<TMiddlewares>
301
+ : Assign<
302
+ TParentRoute['_types']['allContext'],
303
+ AssignAllServerContext<TMiddlewares>
304
+ >
305
+
306
+ export type AnyServerRoute = AnyServerRouteWithTypes
307
+
308
+ export interface ServerRoute<
309
+ TParentRoute extends AnyServerRouteWithTypes,
310
+ TId extends RouteConstraints['TId'],
311
+ TPath extends RouteConstraints['TPath'],
312
+ TFullPath extends RouteConstraints['TFullPath'],
313
+ TChildren,
314
+ > extends ServerRouteWithTypes<
315
+ TParentRoute,
316
+ TId,
317
+ TPath,
318
+ TFullPath,
319
+ undefined,
320
+ undefined,
321
+ TChildren
322
+ >,
323
+ ServerRouteMiddleware<TParentRoute, TId, TPath, TFullPath, TChildren>,
324
+ ServerRouteMethods<
325
+ TParentRoute,
326
+ TId,
327
+ TPath,
328
+ TFullPath,
329
+ undefined,
330
+ TChildren
331
+ > {}
332
+
333
+ export interface ServerRouteMiddleware<
334
+ TParentRoute extends AnyServerRouteWithTypes,
335
+ TId extends RouteConstraints['TId'],
336
+ TPath extends RouteConstraints['TPath'],
337
+ TFullPath extends RouteConstraints['TFullPath'],
338
+ TChildren,
339
+ > {
340
+ middleware: <const TNewMiddleware>(
341
+ middleware: Constrain<TNewMiddleware, ReadonlyArray<AnyRequestMiddleware>>,
342
+ ) => ServerRouteAfterMiddleware<
343
+ TParentRoute,
344
+ TId,
345
+ TPath,
346
+ TFullPath,
347
+ TNewMiddleware,
348
+ TChildren
349
+ >
350
+ }
351
+
352
+ export interface ServerRouteAfterMiddleware<
353
+ TParentRoute extends AnyServerRouteWithTypes,
354
+ TId extends RouteConstraints['TId'],
355
+ TPath extends RouteConstraints['TPath'],
356
+ TFullPath extends RouteConstraints['TFullPath'],
357
+ TMiddlewares,
358
+ TChildren,
359
+ > extends ServerRouteWithTypes<
360
+ TParentRoute,
361
+ TId,
362
+ TPath,
363
+ TFullPath,
364
+ TMiddlewares,
365
+ undefined,
366
+ TChildren
367
+ >,
368
+ ServerRouteMethods<
369
+ TParentRoute,
370
+ TId,
371
+ TPath,
372
+ TFullPath,
373
+ TMiddlewares,
374
+ TChildren
375
+ > {}
376
+
377
+ export interface ServerRouteMethods<
378
+ TParentRoute extends AnyServerRouteWithTypes,
379
+ TId extends RouteConstraints['TId'],
380
+ TPath extends RouteConstraints['TPath'],
381
+ TFullPath extends RouteConstraints['TFullPath'],
382
+ TMiddlewares,
383
+ TChildren,
384
+ > {
385
+ methods: <const TMethods>(
386
+ methodsOrGetMethods: Constrain<
387
+ TMethods,
388
+ ServerRouteMethodsOptions<TParentRoute, TFullPath, TMiddlewares>
389
+ >,
390
+ ) => ServerRouteAfterMethods<
391
+ TParentRoute,
392
+ TId,
393
+ TPath,
394
+ TFullPath,
395
+ TMiddlewares,
396
+ TMethods,
397
+ TChildren
398
+ >
399
+ }
400
+
401
+ export type ServerRouteMethodsOptions<
402
+ TParentRoute extends AnyServerRouteWithTypes,
403
+ TFullPath extends string,
404
+ TMiddlewares,
405
+ > =
406
+ | ServerRouteMethodsRecord<TParentRoute, TFullPath, TMiddlewares>
407
+ | ((
408
+ api: ServerRouteMethodBuilder<TParentRoute, TFullPath, TMiddlewares>,
409
+ ) => ServerRouteMethodsRecord<TParentRoute, TFullPath, TMiddlewares>)
410
+
411
+ export interface ServerRouteMethodsRecord<
412
+ TParentRoute extends AnyServerRouteWithTypes,
413
+ TFullPath extends string,
414
+ TMiddlewares,
415
+ > {
416
+ GET?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>
417
+ POST?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>
418
+ PUT?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>
419
+ PATCH?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>
420
+ DELETE?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>
421
+ OPTIONS?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>
422
+ HEAD?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>
423
+ }
424
+
425
+ export type ServerRouteMethodRecordValue<
426
+ TParentRoute extends AnyServerRouteWithTypes,
427
+ TFullPath extends string,
428
+ TMiddlewares,
429
+ > =
430
+ | ServerRouteMethodHandlerFn<
431
+ TParentRoute,
432
+ TFullPath,
433
+ TMiddlewares,
434
+ undefined,
435
+ any
436
+ >
437
+ | AnyRouteMethodsBuilder
438
+
439
+ export type ServerRouteVerb = (typeof ServerRouteVerbs)[number]
440
+
441
+ export const ServerRouteVerbs = [
442
+ 'GET',
443
+ 'POST',
444
+ 'PUT',
445
+ 'PATCH',
446
+ 'DELETE',
447
+ 'OPTIONS',
448
+ 'HEAD',
449
+ ] as const
450
+
451
+ export type ServerRouteMethodHandlerFn<
452
+ TParentRoute extends AnyServerRouteWithTypes,
453
+ TFullPath extends string,
454
+ TMiddlewares,
455
+ TMethodMiddlewares,
456
+ TResponse,
457
+ > = (
458
+ ctx: ServerRouteMethodHandlerCtx<
459
+ TParentRoute,
460
+ TFullPath,
461
+ TMiddlewares,
462
+ TMethodMiddlewares
463
+ >,
464
+ ) => TResponse | Promise<TResponse>
465
+
466
+ export interface ServerRouteMethodHandlerCtx<
467
+ in out TParentRoute extends AnyServerRouteWithTypes,
468
+ in out TFullPath extends string,
469
+ in out TMiddlewares,
470
+ in out TMethodMiddlewares,
471
+ > {
472
+ context: Expand<
473
+ AssignAllMethodContext<TParentRoute, TMiddlewares, TMethodMiddlewares>
474
+ >
475
+ request: Request
476
+ params: Expand<ResolveParams<TFullPath>>
477
+ pathname: TFullPath
478
+ }
479
+
480
+ export type MergeMethodMiddlewares<TMiddlewares, TMethodMiddlewares> =
481
+ TMiddlewares extends ReadonlyArray<any>
482
+ ? TMethodMiddlewares extends ReadonlyArray<any>
483
+ ? readonly [...TMiddlewares, ...TMethodMiddlewares]
484
+ : TMiddlewares
485
+ : TMethodMiddlewares
486
+
487
+ export type AssignAllMethodContext<
488
+ TParentRoute extends AnyServerRouteWithTypes,
489
+ TMiddlewares,
490
+ TMethodMiddlewares,
491
+ > = ResolveAllServerContext<
492
+ TParentRoute,
493
+ MergeMethodMiddlewares<TMiddlewares, TMethodMiddlewares>
494
+ >
495
+
496
+ export type AnyRouteMethodsBuilder = ServerRouteMethodBuilderWithTypes<
497
+ any,
498
+ any,
499
+ any,
500
+ any
501
+ >
502
+
503
+ export interface ServerRouteMethodBuilder<
504
+ TParentRoute extends AnyServerRouteWithTypes,
505
+ TFullPath extends string,
506
+ TMiddlewares,
507
+ > extends ServerRouteMethodBuilderWithTypes<
508
+ TFullPath,
509
+ TMiddlewares,
510
+ undefined,
511
+ undefined
512
+ >,
513
+ ServerRouteMethodBuilderMiddleware<TParentRoute, TFullPath, TMiddlewares>,
514
+ ServerRouteMethodBuilderHandler<
515
+ TParentRoute,
516
+ TFullPath,
517
+ TMiddlewares,
518
+ undefined
519
+ > {}
520
+
521
+ export interface ServerRouteMethodBuilderWithTypes<
522
+ TFullPath extends string,
523
+ TMiddlewares,
524
+ TMethodMiddlewares,
525
+ TResponse,
526
+ > {
527
+ _options: TODO
528
+ _types: ServerRouteMethodBuilderTypes<
529
+ TFullPath,
530
+ TMiddlewares,
531
+ TMethodMiddlewares,
532
+ TResponse
533
+ >
534
+ }
535
+
536
+ export interface ServerRouteMethodBuilderTypes<
537
+ in out TFullPath extends string,
538
+ in out TMiddlewares,
539
+ in out TMethodMiddlewares,
540
+ in out TResponse,
541
+ > {
542
+ middlewares: TMiddlewares
543
+ methodMiddleware: TMethodMiddlewares
544
+ fullPath: TFullPath
545
+ response: TResponse
546
+ }
547
+
548
+ export interface ServerRouteMethodBuilderMiddleware<
549
+ TParentRoute extends AnyServerRouteWithTypes,
550
+ TFullPath extends string,
551
+ TMiddlewares,
552
+ > {
553
+ middleware: <const TNewMethodMiddlewares>(
554
+ middleware: Constrain<
555
+ TNewMethodMiddlewares,
556
+ ReadonlyArray<AnyRequestMiddleware>
557
+ >,
558
+ ) => ServerRouteMethodBuilderAfterMiddleware<
559
+ TParentRoute,
560
+ TFullPath,
561
+ TMiddlewares,
562
+ TNewMethodMiddlewares
563
+ >
564
+ }
565
+
566
+ export interface ServerRouteMethodBuilderAfterMiddleware<
567
+ TParentRoute extends AnyServerRouteWithTypes,
568
+ TFullPath extends string,
569
+ TMiddlewares,
570
+ TMethodMiddlewares,
571
+ > extends ServerRouteMethodBuilderWithTypes<
572
+ TFullPath,
573
+ TMiddlewares,
574
+ TMethodMiddlewares,
575
+ undefined
576
+ >,
577
+ ServerRouteMethodBuilderHandler<
578
+ TParentRoute,
579
+ TFullPath,
580
+ TMiddlewares,
581
+ TMethodMiddlewares
582
+ > {}
583
+
584
+ export interface ServerRouteMethodBuilderHandler<
585
+ TParentRoute extends AnyServerRouteWithTypes,
586
+ TFullPath extends string,
587
+ TMiddlewares,
588
+ TMethodMiddlewares,
589
+ > {
590
+ handler: <TResponse>(
591
+ handler: ServerRouteMethodHandlerFn<
592
+ TParentRoute,
593
+ TFullPath,
594
+ TMiddlewares,
595
+ TMethodMiddlewares,
596
+ TResponse
597
+ >,
598
+ ) => ServerRouteMethodBuilderAfterHandler<
599
+ TParentRoute,
600
+ TFullPath,
601
+ TMiddlewares,
602
+ TMethodMiddlewares,
603
+ TResponse
604
+ >
605
+ }
606
+
607
+ export interface ServerRouteMethodBuilderAfterHandler<
608
+ TParentRoute extends AnyServerRouteWithTypes,
609
+ TFullPath extends string,
610
+ TMiddlewares,
611
+ TMethodMiddlewares,
612
+ TResponse,
613
+ > extends ServerRouteMethodBuilderWithTypes<
614
+ TFullPath,
615
+ TMiddlewares,
616
+ TMethodMiddlewares,
617
+ TResponse
618
+ > {
619
+ opts: ServerRouteMethod<
620
+ TParentRoute,
621
+ TFullPath,
622
+ TMiddlewares,
623
+ TMethodMiddlewares
624
+ >
625
+ }
626
+
627
+ export interface ServerRouteMethod<
628
+ TParentRoute extends AnyServerRouteWithTypes,
629
+ TFullPath extends string,
630
+ TMiddlewares,
631
+ TMethodMiddlewares,
632
+ > {
633
+ middleware?: Constrain<TMiddlewares, Array<AnyRequestMiddleware>>
634
+ handler?: ServerRouteMethodHandlerFn<
635
+ TParentRoute,
636
+ TFullPath,
637
+ TMiddlewares,
638
+ TMethodMiddlewares,
639
+ undefined
640
+ >
641
+ }
642
+
643
+ export interface ServerRouteAfterMethods<
644
+ TParentRoute extends AnyServerRouteWithTypes,
645
+ TId extends RouteConstraints['TId'],
646
+ TPath extends RouteConstraints['TPath'],
647
+ TFullPath extends RouteConstraints['TFullPath'],
648
+ TMiddlewares,
649
+ TMethods,
650
+ TChildren,
651
+ > extends ServerRouteWithTypes<
652
+ TParentRoute,
653
+ TId,
654
+ TPath,
655
+ TFullPath,
656
+ TMiddlewares,
657
+ TMethods,
658
+ TChildren
659
+ > {
660
+ options: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, TMiddlewares>
661
+ }
package/src/ssr-server.ts CHANGED
@@ -105,6 +105,8 @@ export function dehydrateRouter(router: AnyRouter) {
105
105
  const dehydratedRouter: DehydratedRouter = {
106
106
  manifest: router.ssr!.manifest,
107
107
  dehydratedData: router.options.dehydrate?.(),
108
+ lastMatchId:
109
+ router.state.matches[router.state.matches.length - 1]?.id || '',
108
110
  }
109
111
 
110
112
  router.serverSsr!.injectScript(
@@ -0,0 +1,5 @@
1
+ declare module 'tanstack-start-router-manifest:v' {
2
+ import type { Manifest } from '@tanstack/router-core'
3
+
4
+ export const tsrStartManifest: () => Manifest
5
+ }