@tanstack/start-server-core 1.121.0-alpha.5 → 1.121.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.
Files changed (48) hide show
  1. package/dist/cjs/createStartHandler.cjs +18 -34
  2. package/dist/cjs/createStartHandler.cjs.map +1 -1
  3. package/dist/cjs/index.cjs +3 -0
  4. package/dist/cjs/index.cjs.map +1 -1
  5. package/dist/cjs/index.d.cts +3 -2
  6. package/dist/cjs/loadVirtualModule.cjs +39 -0
  7. package/dist/cjs/loadVirtualModule.cjs.map +1 -0
  8. package/dist/cjs/loadVirtualModule.d.cts +6 -0
  9. package/dist/cjs/router-manifest.cjs +9 -4
  10. package/dist/cjs/router-manifest.cjs.map +1 -1
  11. package/dist/cjs/router-manifest.d.cts +4 -5
  12. package/dist/cjs/server-functions-handler.cjs +5 -2
  13. package/dist/cjs/server-functions-handler.cjs.map +1 -1
  14. package/dist/cjs/serverRoute.cjs +3 -1
  15. package/dist/cjs/serverRoute.cjs.map +1 -1
  16. package/dist/cjs/serverRoute.d.cts +15 -10
  17. package/dist/cjs/virtual-modules.cjs +9 -0
  18. package/dist/cjs/virtual-modules.cjs.map +1 -0
  19. package/dist/cjs/virtual-modules.d.cts +10 -0
  20. package/dist/esm/createStartHandler.js +18 -12
  21. package/dist/esm/createStartHandler.js.map +1 -1
  22. package/dist/esm/index.d.ts +3 -2
  23. package/dist/esm/index.js +4 -1
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/loadVirtualModule.d.ts +6 -0
  26. package/dist/esm/loadVirtualModule.js +17 -0
  27. package/dist/esm/loadVirtualModule.js.map +1 -0
  28. package/dist/esm/router-manifest.d.ts +4 -5
  29. package/dist/esm/router-manifest.js +9 -4
  30. package/dist/esm/router-manifest.js.map +1 -1
  31. package/dist/esm/server-functions-handler.js +5 -2
  32. package/dist/esm/server-functions-handler.js.map +1 -1
  33. package/dist/esm/serverRoute.d.ts +15 -10
  34. package/dist/esm/serverRoute.js +3 -1
  35. package/dist/esm/serverRoute.js.map +1 -1
  36. package/dist/esm/virtual-modules.d.ts +10 -0
  37. package/dist/esm/virtual-modules.js +9 -0
  38. package/dist/esm/virtual-modules.js.map +1 -0
  39. package/package.json +4 -4
  40. package/src/createStartHandler.ts +25 -14
  41. package/src/global.d.ts +6 -0
  42. package/src/index.tsx +11 -2
  43. package/src/loadVirtualModule.ts +21 -0
  44. package/src/router-manifest.ts +10 -9
  45. package/src/server-functions-handler.ts +6 -11
  46. package/src/serverRoute.ts +85 -29
  47. package/src/tanstack-start.d.ts +14 -1
  48. package/src/virtual-modules.ts +13 -0
@@ -1 +1 @@
1
- {"version":3,"file":"serverRoute.js","sources":["../../src/serverRoute.ts"],"sourcesContent":["import { joinPaths, rootRouteId, trimPathLeft } from '@tanstack/router-core'\nimport type {\n Assign,\n Constrain,\n Expand,\n ResolveParams,\n RouteConstraints,\n TrimPathRight,\n} from '@tanstack/router-core'\nimport type {\n AnyRequestMiddleware,\n AssignAllServerContext,\n} from '@tanstack/start-client-core'\n\ntype TODO = any\n\nexport function createServerFileRoute<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TChildren,\n>(__?: never): ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren> {\n return createServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>(\n undefined,\n )\n}\n\nexport interface ServerRouteOptions<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n> {\n id: TId\n path: TPath\n pathname: TFullPath\n originalIndex: number\n getParentRoute?: () => TParentRoute\n middleware: Constrain<TMiddlewares, ReadonlyArray<AnyRequestMiddleware>>\n methods: Record<\n string,\n ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, any, any>\n >\n caseSensitive?: boolean\n}\n\nexport type ServerRouteManifest = {\n middleware: boolean\n methods: Record<string, { middleware: boolean }>\n}\n\nexport function createServerRoute<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TChildren,\n>(\n __?: never,\n __opts?: Partial<\n ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, undefined>\n >,\n): ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren> {\n const options = __opts || {}\n\n const route: ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren> = {\n path: '' as TPath,\n id: '' as TId,\n fullPath: '' as TFullPath,\n to: '' as TrimPathRight<TFullPath>,\n options: options as TODO,\n parentRoute: undefined as unknown as TParentRoute,\n _types: {} as TODO,\n // children: undefined as TChildren,\n middleware: (middlewares: TODO) =>\n createServerRoute(undefined, {\n ...options,\n middleware: middlewares,\n }) as TODO,\n methods: (methodsOrGetMethods: TODO) => {\n const methods = (() => {\n if (typeof methodsOrGetMethods === 'function') {\n return methodsOrGetMethods(createMethodBuilder())\n }\n\n return methodsOrGetMethods\n })()\n\n return createServerRoute(undefined, {\n ...__opts,\n methods,\n }) as TODO\n },\n update: (opts) =>\n createServerRoute(undefined, {\n ...options,\n ...opts,\n }) as TODO,\n init: (opts: { originalIndex: number }): void => {\n options.originalIndex = opts.originalIndex\n\n const isRoot = !options.path && !options.id\n\n route.parentRoute = options.getParentRoute?.() as TParentRoute\n\n if (isRoot) {\n route.path = rootRouteId as TPath\n } else if (!(route.parentRoute as any)) {\n throw new Error(\n `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a ServerRoute instance.`,\n )\n }\n\n let path: undefined | string = isRoot ? rootRouteId : options.path\n\n // If the path is anything other than an index path, trim it up\n if (path && path !== '/') {\n path = trimPathLeft(path)\n }\n\n const customId = options.id || path\n\n // Strip the parentId prefix from the first level of children\n let id = isRoot\n ? rootRouteId\n : joinPaths([\n route.parentRoute.id === rootRouteId ? '' : route.parentRoute.id,\n customId,\n ])\n\n if (path === rootRouteId) {\n path = '/'\n }\n\n if (id !== rootRouteId) {\n id = joinPaths(['/', id])\n }\n\n const fullPath =\n id === rootRouteId ? '/' : joinPaths([route.parentRoute.fullPath, path])\n\n route.path = path as TPath\n route.id = id as TId\n route.fullPath = fullPath as TFullPath\n route.to = fullPath as TrimPathRight<TFullPath>\n },\n\n _addFileChildren: (children) => {\n if (Array.isArray(children)) {\n route.children = children as TChildren as TODO\n }\n\n if (typeof children === 'object' && children !== null) {\n route.children = Object.values(children) as TChildren as TODO\n }\n\n return route as any\n },\n\n _addFileTypes: <TFileTypes>() => route,\n }\n\n return route\n}\n\nexport type ServerRouteAddFileChildrenFn<\n in out TParentRoute extends AnyServerRouteWithTypes,\n in out TId extends RouteConstraints['TId'],\n in out TPath extends RouteConstraints['TPath'],\n in out TFullPath extends RouteConstraints['TFullPath'],\n in out TMiddlewares,\n in out TMethods,\n in out TChildren,\n> = (\n children: TChildren,\n) => ServerRouteWithTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods,\n TChildren\n>\n\nconst createMethodBuilder = <\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n>(\n __opts?: TODO,\n): ServerRouteMethodBuilder<TParentRoute, TFullPath, TMiddlewares> => {\n return {\n _options: __opts || {},\n _types: {} as TODO,\n middleware: (middlewares) =>\n createMethodBuilder({\n ...__opts,\n middlewares,\n }) as TODO,\n handler: (handler) =>\n createMethodBuilder({\n ...__opts,\n handler,\n }) as TODO,\n }\n}\n\nexport type CreateServerFileRoute<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TChildren,\n> = (\n options?: undefined,\n) => ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>\n\nexport type AnyServerRouteWithTypes = ServerRouteWithTypes<\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>\n\nexport interface ServerRouteWithTypes<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n TMethods,\n TChildren,\n> {\n _types: ServerRouteTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods\n >\n path: TPath\n id: TId\n fullPath: TFullPath\n to: TrimPathRight<TFullPath>\n parentRoute: TParentRoute\n children?: TChildren\n options: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, TMiddlewares>\n update: (\n opts: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, undefined>,\n ) => ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>\n init: (opts: { originalIndex: number }) => void\n _addFileChildren: ServerRouteAddFileChildrenFn<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods,\n TChildren\n >\n _addFileTypes: () => ServerRouteWithTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods,\n TChildren\n >\n}\n\nexport interface ServerRouteTypes<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n TMethods,\n> {\n id: TId\n path: TPath\n fullPath: TFullPath\n middlewares: TMiddlewares\n methods: TMethods\n parentRoute: TParentRoute\n allContext: ResolveAllServerContext<TParentRoute, TMiddlewares>\n}\n\nexport type ResolveAllServerContext<\n TParentRoute extends AnyServerRouteWithTypes,\n TMiddlewares,\n> = unknown extends TParentRoute\n ? AssignAllServerContext<TMiddlewares>\n : Assign<\n TParentRoute['_types']['allContext'],\n AssignAllServerContext<TMiddlewares>\n >\n\nexport type AnyServerRoute = AnyServerRouteWithTypes\n\nexport interface ServerRoute<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TChildren,\n> extends ServerRouteWithTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n undefined,\n undefined,\n TChildren\n >,\n ServerRouteMiddleware<TParentRoute, TId, TPath, TFullPath, TChildren>,\n ServerRouteMethods<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n undefined,\n TChildren\n > {}\n\nexport interface ServerRouteMiddleware<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TChildren,\n> {\n middleware: <const TNewMiddleware>(\n middleware: Constrain<TNewMiddleware, ReadonlyArray<AnyRequestMiddleware>>,\n ) => ServerRouteAfterMiddleware<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TNewMiddleware,\n TChildren\n >\n}\n\nexport interface ServerRouteAfterMiddleware<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n TChildren,\n> extends ServerRouteWithTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n undefined,\n TChildren\n >,\n ServerRouteMethods<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TChildren\n > {}\n\nexport interface ServerRouteMethods<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n TChildren,\n> {\n methods: <const TMethods>(\n methodsOrGetMethods: Constrain<\n TMethods,\n ServerRouteMethodsOptions<TParentRoute, TFullPath, TMiddlewares>\n >,\n ) => ServerRouteAfterMethods<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods,\n TChildren\n >\n}\n\nexport type ServerRouteMethodsOptions<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n> =\n | ServerRouteMethodsRecord<TParentRoute, TFullPath, TMiddlewares>\n | ((\n api: ServerRouteMethodBuilder<TParentRoute, TFullPath, TMiddlewares>,\n ) => ServerRouteMethodsRecord<TParentRoute, TFullPath, TMiddlewares>)\n\nexport interface ServerRouteMethodsRecord<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n> {\n GET?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n POST?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n PUT?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n PATCH?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n DELETE?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n OPTIONS?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n HEAD?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n}\n\nexport type ServerRouteMethodRecordValue<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n> =\n | ServerRouteMethodHandlerFn<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n undefined,\n any\n >\n | AnyRouteMethodsBuilder\n\nexport type ServerRouteVerb = (typeof ServerRouteVerbs)[number]\n\nexport const ServerRouteVerbs = [\n 'GET',\n 'POST',\n 'PUT',\n 'PATCH',\n 'DELETE',\n 'OPTIONS',\n 'HEAD',\n] as const\n\nexport type ServerRouteMethodHandlerFn<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse,\n> = (\n ctx: ServerRouteMethodHandlerCtx<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares\n >,\n) => TResponse | Promise<TResponse>\n\nexport interface ServerRouteMethodHandlerCtx<\n in out TParentRoute extends AnyServerRouteWithTypes,\n in out TFullPath extends string,\n in out TMiddlewares,\n in out TMethodMiddlewares,\n> {\n context: Expand<\n AssignAllMethodContext<TParentRoute, TMiddlewares, TMethodMiddlewares>\n >\n request: Request\n params: Expand<ResolveParams<TFullPath>>\n pathname: TFullPath\n}\n\nexport type MergeMethodMiddlewares<TMiddlewares, TMethodMiddlewares> =\n TMiddlewares extends ReadonlyArray<any>\n ? TMethodMiddlewares extends ReadonlyArray<any>\n ? readonly [...TMiddlewares, ...TMethodMiddlewares]\n : TMiddlewares\n : TMethodMiddlewares\n\nexport type AssignAllMethodContext<\n TParentRoute extends AnyServerRouteWithTypes,\n TMiddlewares,\n TMethodMiddlewares,\n> = ResolveAllServerContext<\n TParentRoute,\n MergeMethodMiddlewares<TMiddlewares, TMethodMiddlewares>\n>\n\nexport type AnyRouteMethodsBuilder = ServerRouteMethodBuilderWithTypes<\n any,\n any,\n any,\n any\n>\n\nexport interface ServerRouteMethodBuilder<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n> extends ServerRouteMethodBuilderWithTypes<\n TFullPath,\n TMiddlewares,\n undefined,\n undefined\n >,\n ServerRouteMethodBuilderMiddleware<TParentRoute, TFullPath, TMiddlewares>,\n ServerRouteMethodBuilderHandler<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n undefined\n > {}\n\nexport interface ServerRouteMethodBuilderWithTypes<\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse,\n> {\n _options: TODO\n _types: ServerRouteMethodBuilderTypes<\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse\n >\n}\n\nexport interface ServerRouteMethodBuilderTypes<\n in out TFullPath extends string,\n in out TMiddlewares,\n in out TMethodMiddlewares,\n in out TResponse,\n> {\n middlewares: TMiddlewares\n methodMiddleware: TMethodMiddlewares\n fullPath: TFullPath\n response: TResponse\n}\n\nexport interface ServerRouteMethodBuilderMiddleware<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n> {\n middleware: <const TNewMethodMiddlewares>(\n middleware: Constrain<\n TNewMethodMiddlewares,\n ReadonlyArray<AnyRequestMiddleware>\n >,\n ) => ServerRouteMethodBuilderAfterMiddleware<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TNewMethodMiddlewares\n >\n}\n\nexport interface ServerRouteMethodBuilderAfterMiddleware<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n> extends ServerRouteMethodBuilderWithTypes<\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n undefined\n >,\n ServerRouteMethodBuilderHandler<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares\n > {}\n\nexport interface ServerRouteMethodBuilderHandler<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n> {\n handler: <TResponse>(\n handler: ServerRouteMethodHandlerFn<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse\n >,\n ) => ServerRouteMethodBuilderAfterHandler<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse\n >\n}\n\nexport interface ServerRouteMethodBuilderAfterHandler<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse,\n> extends ServerRouteMethodBuilderWithTypes<\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse\n > {\n opts: ServerRouteMethod<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares\n >\n}\n\nexport interface ServerRouteMethod<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n> {\n middleware?: Constrain<TMiddlewares, Array<AnyRequestMiddleware>>\n handler?: ServerRouteMethodHandlerFn<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n undefined\n >\n}\n\nexport interface ServerRouteAfterMethods<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n TMethods,\n TChildren,\n> extends ServerRouteWithTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods,\n TChildren\n > {\n options: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, TMiddlewares>\n}\n"],"names":[],"mappings":";AAgBO,SAAS,sBAMd,IAAyE;AAClE,SAAA,kBAEP;AACF;AA2BgB,SAAA,kBAOd,IACA,QAG6D;AACvD,QAAA,UAAU,UAAU,CAAC;AAE3B,QAAM,QAAqE;AAAA,IACzE,MAAM;AAAA,IACN,IAAI;AAAA,IACJ,UAAU;AAAA,IACV,IAAI;AAAA,IACJ;AAAA,IACA,aAAa;AAAA,IACb,QAAQ,CAAC;AAAA;AAAA,IAET,YAAY,CAAC,gBACX,kBAAkB,QAAW;AAAA,MAC3B,GAAG;AAAA,MACH,YAAY;AAAA,IAAA,CACb;AAAA,IACH,SAAS,CAAC,wBAA8B;AACtC,YAAM,WAAW,MAAM;AACjB,YAAA,OAAO,wBAAwB,YAAY;AACtC,iBAAA,oBAAoB,qBAAqB;AAAA,QAAA;AAG3C,eAAA;AAAA,MAAA,GACN;AAEH,aAAO,kBAAkB,QAAW;AAAA,QAClC,GAAG;AAAA,QACH;AAAA,MAAA,CACD;AAAA,IACH;AAAA,IACA,QAAQ,CAAC,SACP,kBAAkB,QAAW;AAAA,MAC3B,GAAG;AAAA,MACH,GAAG;AAAA,IAAA,CACJ;AAAA,IACH,MAAM,CAAC,SAA0C;;AAC/C,cAAQ,gBAAgB,KAAK;AAE7B,YAAM,SAAS,CAAC,QAAQ,QAAQ,CAAC,QAAQ;AAEnC,YAAA,eAAc,aAAQ,mBAAR;AAEpB,UAAI,QAAQ;AACV,cAAM,OAAO;AAAA,MAAA,WACJ,CAAE,MAAM,aAAqB;AACtC,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MAAA;AAGE,UAAA,OAA2B,SAAS,cAAc,QAAQ;AAG1D,UAAA,QAAQ,SAAS,KAAK;AACxB,eAAO,aAAa,IAAI;AAAA,MAAA;AAGpB,YAAA,WAAW,QAAQ,MAAM;AAG3B,UAAA,KAAK,SACL,cACA,UAAU;AAAA,QACR,MAAM,YAAY,OAAO,cAAc,KAAK,MAAM,YAAY;AAAA,QAC9D;AAAA,MAAA,CACD;AAEL,UAAI,SAAS,aAAa;AACjB,eAAA;AAAA,MAAA;AAGT,UAAI,OAAO,aAAa;AACtB,aAAK,UAAU,CAAC,KAAK,EAAE,CAAC;AAAA,MAAA;AAGpB,YAAA,WACJ,OAAO,cAAc,MAAM,UAAU,CAAC,MAAM,YAAY,UAAU,IAAI,CAAC;AAEzE,YAAM,OAAO;AACb,YAAM,KAAK;AACX,YAAM,WAAW;AACjB,YAAM,KAAK;AAAA,IACb;AAAA,IAEA,kBAAkB,CAAC,aAAa;AAC1B,UAAA,MAAM,QAAQ,QAAQ,GAAG;AAC3B,cAAM,WAAW;AAAA,MAAA;AAGnB,UAAI,OAAO,aAAa,YAAY,aAAa,MAAM;AAC/C,cAAA,WAAW,OAAO,OAAO,QAAQ;AAAA,MAAA;AAGlC,aAAA;AAAA,IACT;AAAA,IAEA,eAAe,MAAkB;AAAA,EACnC;AAEO,SAAA;AACT;AAsBA,MAAM,sBAAsB,CAK1B,WACoE;AAC7D,SAAA;AAAA,IACL,UAAU,UAAU,CAAC;AAAA,IACrB,QAAQ,CAAC;AAAA,IACT,YAAY,CAAC,gBACX,oBAAoB;AAAA,MAClB,GAAG;AAAA,MACH;AAAA,IAAA,CACD;AAAA,IACH,SAAS,CAAC,YACR,oBAAoB;AAAA,MAClB,GAAG;AAAA,MACH;AAAA,IACD,CAAA;AAAA,EACL;AACF;"}
1
+ {"version":3,"file":"serverRoute.js","sources":["../../src/serverRoute.ts"],"sourcesContent":["import { joinPaths, rootRouteId, trimPathLeft } from '@tanstack/router-core'\nimport type {\n Assign,\n Constrain,\n Expand,\n ResolveParams,\n RouteConstraints,\n TrimPathRight,\n} from '@tanstack/router-core'\nimport type {\n AnyRequestMiddleware,\n AssignAllServerContext,\n} from '@tanstack/start-client-core'\n\nexport function createServerFileRoute<\n TFilePath extends keyof ServerFileRoutesByPath,\n TParentRoute extends\n AnyServerRouteWithTypes = ServerFileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = ServerFileRoutesByPath[TFilePath]['id'],\n TPath extends\n RouteConstraints['TPath'] = ServerFileRoutesByPath[TFilePath]['path'],\n TFullPath extends\n RouteConstraints['TFullPath'] = ServerFileRoutesByPath[TFilePath]['fullPath'],\n TChildren = ServerFileRoutesByPath[TFilePath]['children'],\n>(_: TFilePath): ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren> {\n return createServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>(\n undefined,\n )\n}\n\nexport interface ServerFileRoutesByPath {}\n\nexport interface ServerRouteOptions<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n> {\n id: TId\n path: TPath\n pathname: TFullPath\n originalIndex: number\n getParentRoute?: () => TParentRoute\n middleware: Constrain<TMiddlewares, ReadonlyArray<AnyRequestMiddleware>>\n methods: Record<\n string,\n ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, any, any>\n >\n caseSensitive?: boolean\n}\n\nexport type ServerRouteManifest = {\n middleware: boolean\n methods: Record<string, { middleware: boolean }>\n}\n\nexport function createServerRoute<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TChildren,\n>(\n __?: never,\n __opts?: Partial<\n ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, undefined>\n >,\n): ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren> {\n const options = __opts || {}\n\n const route: ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren> = {\n path: '' as TPath,\n id: '' as TId,\n fullPath: '' as TFullPath,\n to: '' as TrimPathRight<TFullPath>,\n options: options as ServerRouteOptions<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n any\n >,\n parentRoute: undefined as unknown as TParentRoute,\n _types: {} as ServerRouteTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n undefined,\n undefined\n >,\n // children: undefined as TChildren,\n middleware: (middlewares) =>\n createServerRoute(undefined, {\n ...options,\n middleware: middlewares,\n }) as never,\n methods: (methodsOrGetMethods) => {\n const methods = (() => {\n if (typeof methodsOrGetMethods === 'function') {\n return methodsOrGetMethods(createMethodBuilder())\n }\n\n return methodsOrGetMethods\n })()\n\n return createServerRoute(undefined, {\n ...__opts,\n methods: methods as never,\n }) as never\n },\n update: (opts) =>\n createServerRoute(undefined, {\n ...options,\n ...opts,\n }),\n init: (opts: { originalIndex: number }): void => {\n options.originalIndex = opts.originalIndex\n\n const isRoot = !options.path && !options.id\n\n route.parentRoute = options.getParentRoute?.() as TParentRoute\n\n if (isRoot) {\n route.path = rootRouteId as TPath\n } else if (!(route.parentRoute as any)) {\n throw new Error(\n `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a ServerRoute instance.`,\n )\n }\n\n let path: undefined | string = isRoot ? rootRouteId : options.path\n\n // If the path is anything other than an index path, trim it up\n if (path && path !== '/') {\n path = trimPathLeft(path)\n }\n\n const customId = options.id || path\n\n // Strip the parentId prefix from the first level of children\n let id = isRoot\n ? rootRouteId\n : joinPaths([\n route.parentRoute.id === rootRouteId ? '' : route.parentRoute.id,\n customId,\n ])\n\n if (path === rootRouteId) {\n path = '/'\n }\n\n if (id !== rootRouteId) {\n id = joinPaths(['/', id])\n }\n\n const fullPath =\n id === rootRouteId ? '/' : joinPaths([route.parentRoute.fullPath, path])\n\n route.path = path as TPath\n route.id = id as TId\n route.fullPath = fullPath as TFullPath\n route.to = fullPath as TrimPathRight<TFullPath>\n },\n\n _addFileChildren: (children) => {\n if (Array.isArray(children)) {\n route.children = children as TChildren\n }\n\n if (typeof children === 'object' && children !== null) {\n route.children = Object.values(children) as TChildren\n }\n\n return route\n },\n\n _addFileTypes: <TFileTypes>() => route,\n }\n\n return route\n}\n\n// TODO this needs to be restricted to only allow middleware, no methods\n// TODO we also need to restrict pathless server routes to only allow middleware\nexport const createServerRootRoute = createServerRoute\n\nexport type ServerRouteAddFileChildrenFn<\n in out TParentRoute extends AnyServerRouteWithTypes,\n in out TId extends RouteConstraints['TId'],\n in out TPath extends RouteConstraints['TPath'],\n in out TFullPath extends RouteConstraints['TFullPath'],\n in out TMiddlewares,\n in out TMethods,\n in out TChildren,\n> = (\n children: TChildren,\n) => ServerRouteWithTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods,\n TChildren\n>\n\nconst createMethodBuilder = <\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n>(\n __opts?: ServerRouteMethodBuilderOptions<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n unknown,\n unknown\n >,\n): ServerRouteMethodBuilder<TParentRoute, TFullPath, TMiddlewares> => {\n return {\n _options: (__opts || {}) as never,\n _types: {} as never,\n middleware: (middlewares) =>\n createMethodBuilder({\n ...__opts,\n middlewares,\n }) as never,\n handler: (handler) =>\n createMethodBuilder({\n ...__opts,\n handler: handler as never,\n }) as never,\n }\n}\n\nexport interface ServerRouteMethodBuilderOptions<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse,\n> {\n handler?: ServerRouteMethodHandlerFn<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse\n >\n middlewares?: Constrain<\n TMethodMiddlewares,\n ReadonlyArray<AnyRequestMiddleware>\n >\n}\n\nexport type CreateServerFileRoute<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TChildren,\n> = () => ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>\n\nexport type AnyServerRouteWithTypes = ServerRouteWithTypes<\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>\n\nexport interface ServerRouteWithTypes<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n TMethods,\n TChildren,\n> {\n _types: ServerRouteTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods\n >\n path: TPath\n id: TId\n fullPath: TFullPath\n to: TrimPathRight<TFullPath>\n parentRoute: TParentRoute\n children?: TChildren\n options: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, TMiddlewares>\n update: (\n opts: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, undefined>,\n ) => ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>\n init: (opts: { originalIndex: number }) => void\n _addFileChildren: ServerRouteAddFileChildrenFn<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods,\n TChildren\n >\n _addFileTypes: () => ServerRouteWithTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods,\n TChildren\n >\n}\n\nexport interface ServerRouteTypes<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n TMethods,\n> {\n id: TId\n path: TPath\n fullPath: TFullPath\n middlewares: TMiddlewares\n methods: TMethods\n parentRoute: TParentRoute\n allContext: ResolveAllServerContext<TParentRoute, TMiddlewares>\n}\n\nexport type ResolveAllServerContext<\n TParentRoute extends AnyServerRouteWithTypes,\n TMiddlewares,\n> = unknown extends TParentRoute\n ? AssignAllServerContext<TMiddlewares>\n : Assign<\n TParentRoute['_types']['allContext'],\n AssignAllServerContext<TMiddlewares>\n >\n\nexport type AnyServerRoute = AnyServerRouteWithTypes\n\nexport interface ServerRoute<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TChildren,\n> extends ServerRouteWithTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n undefined,\n undefined,\n TChildren\n >,\n ServerRouteMiddleware<TParentRoute, TId, TPath, TFullPath, TChildren>,\n ServerRouteMethods<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n undefined,\n TChildren\n > {}\n\nexport interface ServerRouteMiddleware<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TChildren,\n> {\n middleware: <const TNewMiddleware>(\n middleware: Constrain<TNewMiddleware, ReadonlyArray<AnyRequestMiddleware>>,\n ) => ServerRouteAfterMiddleware<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TNewMiddleware,\n TChildren\n >\n}\n\nexport interface ServerRouteAfterMiddleware<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n TChildren,\n> extends ServerRouteWithTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n undefined,\n TChildren\n >,\n ServerRouteMethods<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TChildren\n > {}\n\nexport interface ServerRouteMethods<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n TChildren,\n> {\n methods: <const TMethods>(\n methodsOrGetMethods: Constrain<\n TMethods,\n ServerRouteMethodsOptions<TParentRoute, TFullPath, TMiddlewares>\n >,\n ) => ServerRouteAfterMethods<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods,\n TChildren\n >\n}\n\nexport type ServerRouteMethodsOptions<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n> =\n | ServerRouteMethodsRecord<TParentRoute, TFullPath, TMiddlewares>\n | ((\n api: ServerRouteMethodBuilder<TParentRoute, TFullPath, TMiddlewares>,\n ) => ServerRouteMethodsRecord<TParentRoute, TFullPath, TMiddlewares>)\n\nexport interface ServerRouteMethodsRecord<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n> {\n GET?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n POST?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n PUT?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n PATCH?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n DELETE?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n OPTIONS?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n HEAD?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n}\n\nexport type ServerRouteMethodRecordValue<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n> =\n | ServerRouteMethodHandlerFn<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n undefined,\n any\n >\n | AnyRouteMethodsBuilder\n\nexport type ServerRouteVerb = (typeof ServerRouteVerbs)[number]\n\nexport const ServerRouteVerbs = [\n 'GET',\n 'POST',\n 'PUT',\n 'PATCH',\n 'DELETE',\n 'OPTIONS',\n 'HEAD',\n] as const\n\nexport type ServerRouteMethodHandlerFn<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse,\n> = (\n ctx: ServerRouteMethodHandlerCtx<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares\n >,\n) => TResponse | Promise<TResponse>\n\nexport interface ServerRouteMethodHandlerCtx<\n in out TParentRoute extends AnyServerRouteWithTypes,\n in out TFullPath extends string,\n in out TMiddlewares,\n in out TMethodMiddlewares,\n> {\n context: Expand<\n AssignAllMethodContext<TParentRoute, TMiddlewares, TMethodMiddlewares>\n >\n request: Request\n params: Expand<ResolveParams<TFullPath>>\n pathname: TFullPath\n}\n\nexport type MergeMethodMiddlewares<TMiddlewares, TMethodMiddlewares> =\n TMiddlewares extends ReadonlyArray<any>\n ? TMethodMiddlewares extends ReadonlyArray<any>\n ? readonly [...TMiddlewares, ...TMethodMiddlewares]\n : TMiddlewares\n : TMethodMiddlewares\n\nexport type AssignAllMethodContext<\n TParentRoute extends AnyServerRouteWithTypes,\n TMiddlewares,\n TMethodMiddlewares,\n> = ResolveAllServerContext<\n TParentRoute,\n MergeMethodMiddlewares<TMiddlewares, TMethodMiddlewares>\n>\n\nexport type AnyRouteMethodsBuilder = ServerRouteMethodBuilderWithTypes<\n any,\n any,\n any,\n any,\n any\n>\n\nexport interface ServerRouteMethodBuilder<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n> extends ServerRouteMethodBuilderWithTypes<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n undefined,\n undefined\n >,\n ServerRouteMethodBuilderMiddleware<TParentRoute, TFullPath, TMiddlewares>,\n ServerRouteMethodBuilderHandler<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n undefined\n > {}\n\nexport interface ServerRouteMethodBuilderWithTypes<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse,\n> {\n _options: ServerRouteMethodBuilderOptions<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse\n >\n _types: ServerRouteMethodBuilderTypes<\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse\n >\n}\n\nexport interface ServerRouteMethodBuilderTypes<\n in out TFullPath extends string,\n in out TMiddlewares,\n in out TMethodMiddlewares,\n in out TResponse,\n> {\n middlewares: TMiddlewares\n methodMiddleware: TMethodMiddlewares\n fullPath: TFullPath\n response: TResponse\n}\n\nexport interface ServerRouteMethodBuilderMiddleware<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n> {\n middleware: <const TNewMethodMiddlewares>(\n middleware: Constrain<\n TNewMethodMiddlewares,\n ReadonlyArray<AnyRequestMiddleware>\n >,\n ) => ServerRouteMethodBuilderAfterMiddleware<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TNewMethodMiddlewares\n >\n}\n\nexport interface ServerRouteMethodBuilderAfterMiddleware<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n> extends ServerRouteMethodBuilderWithTypes<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n undefined\n >,\n ServerRouteMethodBuilderHandler<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares\n > {}\n\nexport interface ServerRouteMethodBuilderHandler<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n> {\n handler: <TResponse>(\n handler: ServerRouteMethodHandlerFn<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse\n >,\n ) => ServerRouteMethodBuilderAfterHandler<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse\n >\n}\n\nexport interface ServerRouteMethodBuilderAfterHandler<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse,\n> extends ServerRouteMethodBuilderWithTypes<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse\n > {\n opts: ServerRouteMethod<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares\n >\n}\n\nexport interface ServerRouteMethod<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n> {\n middleware?: Constrain<TMiddlewares, Array<AnyRequestMiddleware>>\n handler?: ServerRouteMethodHandlerFn<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n undefined\n >\n}\n\nexport interface ServerRouteAfterMethods<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n TMethods,\n TChildren,\n> extends ServerRouteWithTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods,\n TChildren\n > {\n options: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, TMiddlewares>\n}\n"],"names":[],"mappings":";AAcO,SAAS,sBAUd,GAA2E;AACpE,SAAA,kBAEP;AACF;AA6BgB,SAAA,kBAOd,IACA,QAG6D;AACvD,QAAA,UAAU,UAAU,CAAC;AAE3B,QAAM,QAAqE;AAAA,IACzE,MAAM;AAAA,IACN,IAAI;AAAA,IACJ,UAAU;AAAA,IACV,IAAI;AAAA,IACJ;AAAA,IAOA,aAAa;AAAA,IACb,QAAQ,CAAC;AAAA;AAAA,IAST,YAAY,CAAC,gBACX,kBAAkB,QAAW;AAAA,MAC3B,GAAG;AAAA,MACH,YAAY;AAAA,IAAA,CACb;AAAA,IACH,SAAS,CAAC,wBAAwB;AAChC,YAAM,WAAW,MAAM;AACjB,YAAA,OAAO,wBAAwB,YAAY;AACtC,iBAAA,oBAAoB,qBAAqB;AAAA,QAAA;AAG3C,eAAA;AAAA,MAAA,GACN;AAEH,aAAO,kBAAkB,QAAW;AAAA,QAClC,GAAG;AAAA,QACH;AAAA,MAAA,CACD;AAAA,IACH;AAAA,IACA,QAAQ,CAAC,SACP,kBAAkB,QAAW;AAAA,MAC3B,GAAG;AAAA,MACH,GAAG;AAAA,IAAA,CACJ;AAAA,IACH,MAAM,CAAC,SAA0C;;AAC/C,cAAQ,gBAAgB,KAAK;AAE7B,YAAM,SAAS,CAAC,QAAQ,QAAQ,CAAC,QAAQ;AAEnC,YAAA,eAAc,aAAQ,mBAAR;AAEpB,UAAI,QAAQ;AACV,cAAM,OAAO;AAAA,MAAA,WACJ,CAAE,MAAM,aAAqB;AACtC,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MAAA;AAGE,UAAA,OAA2B,SAAS,cAAc,QAAQ;AAG1D,UAAA,QAAQ,SAAS,KAAK;AACxB,eAAO,aAAa,IAAI;AAAA,MAAA;AAGpB,YAAA,WAAW,QAAQ,MAAM;AAG3B,UAAA,KAAK,SACL,cACA,UAAU;AAAA,QACR,MAAM,YAAY,OAAO,cAAc,KAAK,MAAM,YAAY;AAAA,QAC9D;AAAA,MAAA,CACD;AAEL,UAAI,SAAS,aAAa;AACjB,eAAA;AAAA,MAAA;AAGT,UAAI,OAAO,aAAa;AACtB,aAAK,UAAU,CAAC,KAAK,EAAE,CAAC;AAAA,MAAA;AAGpB,YAAA,WACJ,OAAO,cAAc,MAAM,UAAU,CAAC,MAAM,YAAY,UAAU,IAAI,CAAC;AAEzE,YAAM,OAAO;AACb,YAAM,KAAK;AACX,YAAM,WAAW;AACjB,YAAM,KAAK;AAAA,IACb;AAAA,IAEA,kBAAkB,CAAC,aAAa;AAC1B,UAAA,MAAM,QAAQ,QAAQ,GAAG;AAC3B,cAAM,WAAW;AAAA,MAAA;AAGnB,UAAI,OAAO,aAAa,YAAY,aAAa,MAAM;AAC/C,cAAA,WAAW,OAAO,OAAO,QAAQ;AAAA,MAAA;AAGlC,aAAA;AAAA,IACT;AAAA,IAEA,eAAe,MAAkB;AAAA,EACnC;AAEO,SAAA;AACT;AAIO,MAAM,wBAAwB;AAsBrC,MAAM,sBAAsB,CAK1B,WAOoE;AAC7D,SAAA;AAAA,IACL,UAAW,UAAU,CAAC;AAAA,IACtB,QAAQ,CAAC;AAAA,IACT,YAAY,CAAC,gBACX,oBAAoB;AAAA,MAClB,GAAG;AAAA,MACH;AAAA,IAAA,CACD;AAAA,IACH,SAAS,CAAC,YACR,oBAAoB;AAAA,MAClB,GAAG;AAAA,MACH;AAAA,IACD,CAAA;AAAA,EACL;AACF;"}
@@ -0,0 +1,10 @@
1
+ export declare const VIRTUAL_MODULES: {
2
+ readonly routeTree: "tanstack-start-route-tree:v";
3
+ readonly startManifest: "tanstack-start-manifest:v";
4
+ readonly serverFnManifest: "tanstack-start-server-fn-manifest:v";
5
+ };
6
+ export type VirtualModules = {
7
+ [VIRTUAL_MODULES.routeTree]: typeof import('tanstack-start-route-tree:v');
8
+ [VIRTUAL_MODULES.startManifest]: typeof import('tanstack-start-manifest:v');
9
+ [VIRTUAL_MODULES.serverFnManifest]: typeof import('tanstack-start-server-fn-manifest:v');
10
+ };
@@ -0,0 +1,9 @@
1
+ const VIRTUAL_MODULES = {
2
+ routeTree: "tanstack-start-route-tree:v",
3
+ startManifest: "tanstack-start-manifest:v",
4
+ serverFnManifest: "tanstack-start-server-fn-manifest:v"
5
+ };
6
+ export {
7
+ VIRTUAL_MODULES
8
+ };
9
+ //# sourceMappingURL=virtual-modules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"virtual-modules.js","sources":["../../src/virtual-modules.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/consistent-type-imports */\n\nexport const VIRTUAL_MODULES = {\n routeTree: 'tanstack-start-route-tree:v',\n startManifest: 'tanstack-start-manifest:v',\n serverFnManifest: 'tanstack-start-server-fn-manifest:v',\n} as const\n\nexport type VirtualModules = {\n [VIRTUAL_MODULES.routeTree]: typeof import('tanstack-start-route-tree:v')\n [VIRTUAL_MODULES.startManifest]: typeof import('tanstack-start-manifest:v')\n [VIRTUAL_MODULES.serverFnManifest]: typeof import('tanstack-start-server-fn-manifest:v')\n}\n"],"names":[],"mappings":"AAEO,MAAM,kBAAkB;AAAA,EAC7B,WAAW;AAAA,EACX,eAAe;AAAA,EACf,kBAAkB;AACpB;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/start-server-core",
3
- "version": "1.121.0-alpha.5",
3
+ "version": "1.121.0",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -53,9 +53,9 @@
53
53
  "tiny-invariant": "^1.3.3",
54
54
  "tiny-warning": "^1.0.3",
55
55
  "unctx": "^2.4.1",
56
- "@tanstack/history": "^1.121.0-alpha.1",
57
- "@tanstack/router-core": "^1.121.0-alpha.5",
58
- "@tanstack/start-client-core": "^1.121.0-alpha.5"
56
+ "@tanstack/history": "^1.120.17",
57
+ "@tanstack/router-core": "^1.121.0",
58
+ "@tanstack/start-client-core": "^1.121.0"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/jsesc": "^3.0.3",
@@ -17,6 +17,8 @@ import { getResponseHeaders, requestHandler } from './h3'
17
17
  import { attachRouterServerSsrUtils, dehydrateRouter } from './ssr-server'
18
18
  import { getStartManifest } from './router-manifest'
19
19
  import { handleServerAction } from './server-functions-handler'
20
+ import { VIRTUAL_MODULES } from './virtual-modules'
21
+ import { loadVirtualModule } from './loadVirtualModule'
20
22
  import type { AnyServerRoute, AnyServerRouteWithTypes } from './serverRoute'
21
23
  import type { RequestHandler } from './h3'
22
24
  import type { AnyRouter } from '@tanstack/router-core'
@@ -52,6 +54,8 @@ export function createStartHandler<TRouter extends AnyRouter>({
52
54
  }: {
53
55
  createRouter: () => TRouter
54
56
  }): CustomizeStartHandler<TRouter> {
57
+ let serverRouteTree: AnyServerRoute | undefined | null = null
58
+
55
59
  return (cb) => {
56
60
  const originalFetch = globalThis.fetch
57
61
 
@@ -102,11 +106,16 @@ export function createStartHandler<TRouter extends AnyRouter>({
102
106
  initialEntries: [href],
103
107
  })
104
108
 
109
+ const APP_BASE = process.env.TSS_APP_BASE || '/'
110
+
111
+ // TODO do not create a router instance before we need it
105
112
  // Create the client-side router
106
113
  const router = createRouter()
107
114
 
115
+ // TODO only build startRoutesManifest once, not per request
108
116
  // Attach the server-side SSR utils to the client-side router
109
- attachRouterServerSsrUtils(router, getStartManifest())
117
+ const startRoutesManifest = await getStartManifest({ basePath: APP_BASE })
118
+ attachRouterServerSsrUtils(router, startRoutesManifest)
110
119
 
111
120
  // Update the client-side router with the history and context
112
121
  router.update({
@@ -124,7 +133,7 @@ export function createStartHandler<TRouter extends AnyRouter>({
124
133
  // First, let's attempt to handle server functions
125
134
  // Add trailing slash to sanitise user defined TSS_SERVER_FN_BASE
126
135
  const serverFnBase = joinPaths([
127
- '/',
136
+ APP_BASE,
128
137
  trimPath(process.env.TSS_SERVER_FN_BASE),
129
138
  '/',
130
139
  ])
@@ -132,25 +141,23 @@ export function createStartHandler<TRouter extends AnyRouter>({
132
141
  return await handleServerAction({ request })
133
142
  }
134
143
 
135
- // Then move on to attempting to load server routes
136
- const serverRouteTreeModule = await (async () => {
144
+ if (serverRouteTree === null) {
137
145
  try {
138
- // @ts-expect-error
139
- return (await import('tanstack:server-routes')) as {
140
- routeTree: AnyServerRoute
141
- }
146
+ serverRouteTree = (
147
+ await loadVirtualModule(VIRTUAL_MODULES.routeTree)
148
+ ).serverRouteTree
142
149
  } catch (e) {
143
150
  console.log(e)
144
- return undefined
145
151
  }
146
- })()
152
+ }
147
153
 
148
154
  // If we have a server route tree, then we try matching to see if we have a
149
155
  // server route that matches the request.
150
- if (serverRouteTreeModule) {
156
+ if (serverRouteTree) {
151
157
  const [_matchedRoutes, response] = await handleServerRoutes({
152
- routeTree: serverRouteTreeModule.routeTree,
158
+ routeTree: serverRouteTree,
153
159
  request,
160
+ basePath: APP_BASE,
154
161
  })
155
162
 
156
163
  if (response) return response
@@ -271,10 +278,13 @@ export function createStartHandler<TRouter extends AnyRouter>({
271
278
  async function handleServerRoutes({
272
279
  routeTree,
273
280
  request,
281
+ basePath,
274
282
  }: {
275
283
  routeTree: AnyServerRouteWithTypes
276
284
  request: Request
285
+ basePath: string
277
286
  }) {
287
+ // TODO only process server route tree once, not per request
278
288
  const { flatRoutes, routesById, routesByPath } = processRouteTree({
279
289
  routeTree,
280
290
  initRoute: (route, i) => {
@@ -287,6 +297,7 @@ async function handleServerRoutes({
287
297
  const url = new URL(request.url)
288
298
  const pathname = url.pathname
289
299
 
300
+ // TODO history seems not to be needed, we can just use the pathname
290
301
  const history = createMemoryHistory({
291
302
  initialEntries: [pathname],
292
303
  })
@@ -294,7 +305,7 @@ async function handleServerRoutes({
294
305
  const { matchedRoutes, foundRoute, routeParams } =
295
306
  getMatchedRoutes<AnyServerRouteWithTypes>({
296
307
  pathname: history.location.pathname,
297
- basepath: '/',
308
+ basepath: basePath,
298
309
  caseSensitive: true,
299
310
  routesByPath,
300
311
  routesById,
@@ -347,7 +358,7 @@ async function handleServerRoutes({
347
358
  function handlerToMiddleware(
348
359
  handler: AnyServerRouteWithTypes['options']['methods'][string],
349
360
  ) {
350
- return async ({ next, ...rest }: TODO) => ({
361
+ return async ({ next: _next, ...rest }: TODO) => ({
351
362
  response: await handler(rest),
352
363
  })
353
364
  }
@@ -0,0 +1,6 @@
1
+ declare global {
2
+ // eslint-disable-next-line no-var
3
+ var TSS_INJECTED_HEAD_SCRIPTS: string | undefined
4
+ }
5
+
6
+ export {}
package/src/index.tsx CHANGED
@@ -18,5 +18,14 @@ export { handleServerAction } from './server-functions-handler'
18
18
 
19
19
  export * from './h3'
20
20
 
21
- export { createServerRoute, createServerFileRoute } from './serverRoute'
22
- export type { CreateServerFileRoute } from './serverRoute'
21
+ export {
22
+ createServerRoute,
23
+ createServerFileRoute,
24
+ createServerRootRoute,
25
+ } from './serverRoute'
26
+ export type {
27
+ CreateServerFileRoute,
28
+ ServerFileRoutesByPath,
29
+ } from './serverRoute'
30
+
31
+ export * from './virtual-modules'
@@ -0,0 +1,21 @@
1
+ import { VIRTUAL_MODULES } from './virtual-modules'
2
+ import type { VirtualModules } from './virtual-modules'
3
+
4
+ /**
5
+ * we need to explicitly enumerate all imports with string literals,
6
+ * otherwise vite will not pick them up during build
7
+ */
8
+ export async function loadVirtualModule<TId extends keyof VirtualModules>(
9
+ id: TId,
10
+ ): Promise<VirtualModules[TId]> {
11
+ switch (id) {
12
+ case VIRTUAL_MODULES.routeTree:
13
+ return (await import('tanstack-start-route-tree:v')) as any
14
+ case VIRTUAL_MODULES.startManifest:
15
+ return (await import('tanstack-start-manifest:v')) as any
16
+ case VIRTUAL_MODULES.serverFnManifest:
17
+ return (await import('tanstack-start-server-fn-manifest:v')) as any
18
+ default:
19
+ throw new Error(`Unknown virtual module: ${id}`)
20
+ }
21
+ }
@@ -1,10 +1,6 @@
1
- import { tsrStartManifest } from 'tanstack:start-manifest'
2
- import { rootRouteId } from '@tanstack/router-core'
3
-
4
- declare global {
5
- // eslint-disable-next-line no-var
6
- var TSS_INJECTED_HEAD_SCRIPTS: string | undefined
7
- }
1
+ import { joinPaths, rootRouteId } from '@tanstack/router-core'
2
+ import { VIRTUAL_MODULES } from './virtual-modules'
3
+ import { loadVirtualModule } from './loadVirtualModule'
8
4
 
9
5
  /**
10
6
  * @description Returns the router manifest that should be sent to the client.
@@ -12,7 +8,10 @@ declare global {
12
8
  * special assets that are needed for the client. It does not include relationships
13
9
  * between routes or any other data that is not needed for the client.
14
10
  */
15
- export function getStartManifest() {
11
+ export async function getStartManifest(opts: { basePath: string }) {
12
+ const { tsrStartManifest } = await loadVirtualModule(
13
+ VIRTUAL_MODULES.startManifest,
14
+ )
16
15
  const startManifest = tsrStartManifest()
17
16
 
18
17
  const rootRoute = (startManifest.routes[rootRouteId] =
@@ -45,7 +44,9 @@ export function getStartManifest() {
45
44
  // )
46
45
  // }
47
46
 
48
- const script = `${globalThis.TSS_INJECTED_HEAD_SCRIPTS ? globalThis.TSS_INJECTED_HEAD_SCRIPTS + '; ' : ''}import(${JSON.stringify(process.env.TSS_CLIENT_ENTRY)})`
47
+ const clientEntry = joinPaths([opts.basePath, process.env.TSS_CLIENT_ENTRY])
48
+
49
+ const script = `${globalThis.TSS_INJECTED_HEAD_SCRIPTS ? globalThis.TSS_INJECTED_HEAD_SCRIPTS + '; ' : ''}import('${clientEntry}')`
49
50
 
50
51
  rootRoute.assets.push({
51
52
  tag: 'script',
@@ -1,18 +1,9 @@
1
1
  import { isNotFound } from '@tanstack/router-core'
2
2
  import invariant from 'tiny-invariant'
3
3
  import { startSerializer } from '@tanstack/start-client-core'
4
- // @ts-expect-error
5
- import _serverFnManifest from 'tanstack:server-fn-manifest'
6
4
  import { getEvent, getResponseStatus } from './h3'
7
-
8
- const serverFnManifest = _serverFnManifest as Record<
9
- string,
10
- {
11
- functionName: string
12
- extractedFilename: string
13
- importer: () => Promise<any>
14
- }
15
- >
5
+ import { VIRTUAL_MODULES } from './virtual-modules'
6
+ import { loadVirtualModule } from './loadVirtualModule'
16
7
 
17
8
  function sanitizeBase(base: string | undefined) {
18
9
  if (!base) {
@@ -53,6 +44,10 @@ export const handleServerAction = async ({ request }: { request: Request }) => {
53
44
  throw new Error('Invalid server action param for serverFnId: ' + serverFnId)
54
45
  }
55
46
 
47
+ const { default: serverFnManifest } = await loadVirtualModule(
48
+ VIRTUAL_MODULES.serverFnManifest,
49
+ )
50
+
56
51
  const serverFnInfo = serverFnManifest[serverFnId]
57
52
 
58
53
  if (!serverFnInfo) {
@@ -12,20 +12,24 @@ 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 ServerFileRoutesByPath,
17
+ TParentRoute extends
18
+ AnyServerRouteWithTypes = ServerFileRoutesByPath[TFilePath]['parentRoute'],
19
+ TId extends RouteConstraints['TId'] = ServerFileRoutesByPath[TFilePath]['id'],
20
+ TPath extends
21
+ RouteConstraints['TPath'] = ServerFileRoutesByPath[TFilePath]['path'],
22
+ TFullPath extends
23
+ RouteConstraints['TFullPath'] = ServerFileRoutesByPath[TFilePath]['fullPath'],
24
+ TChildren = ServerFileRoutesByPath[TFilePath]['children'],
25
+ >(_: TFilePath): ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren> {
24
26
  return createServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>(
25
27
  undefined,
26
28
  )
27
29
  }
28
30
 
31
+ export interface ServerFileRoutesByPath {}
32
+
29
33
  export interface ServerRouteOptions<
30
34
  TParentRoute extends AnyServerRouteWithTypes,
31
35
  TId extends RouteConstraints['TId'],
@@ -70,16 +74,29 @@ export function createServerRoute<
70
74
  id: '' as TId,
71
75
  fullPath: '' as TFullPath,
72
76
  to: '' as TrimPathRight<TFullPath>,
73
- options: options as TODO,
77
+ options: options as ServerRouteOptions<
78
+ TParentRoute,
79
+ TId,
80
+ TPath,
81
+ TFullPath,
82
+ any
83
+ >,
74
84
  parentRoute: undefined as unknown as TParentRoute,
75
- _types: {} as TODO,
85
+ _types: {} as ServerRouteTypes<
86
+ TParentRoute,
87
+ TId,
88
+ TPath,
89
+ TFullPath,
90
+ undefined,
91
+ undefined
92
+ >,
76
93
  // children: undefined as TChildren,
77
- middleware: (middlewares: TODO) =>
94
+ middleware: (middlewares) =>
78
95
  createServerRoute(undefined, {
79
96
  ...options,
80
97
  middleware: middlewares,
81
- }) as TODO,
82
- methods: (methodsOrGetMethods: TODO) => {
98
+ }) as never,
99
+ methods: (methodsOrGetMethods) => {
83
100
  const methods = (() => {
84
101
  if (typeof methodsOrGetMethods === 'function') {
85
102
  return methodsOrGetMethods(createMethodBuilder())
@@ -90,14 +107,14 @@ export function createServerRoute<
90
107
 
91
108
  return createServerRoute(undefined, {
92
109
  ...__opts,
93
- methods,
94
- }) as TODO
110
+ methods: methods as never,
111
+ }) as never
95
112
  },
96
113
  update: (opts) =>
97
114
  createServerRoute(undefined, {
98
115
  ...options,
99
116
  ...opts,
100
- }) as TODO,
117
+ }),
101
118
  init: (opts: { originalIndex: number }): void => {
102
119
  options.originalIndex = opts.originalIndex
103
120
 
@@ -149,14 +166,14 @@ export function createServerRoute<
149
166
 
150
167
  _addFileChildren: (children) => {
151
168
  if (Array.isArray(children)) {
152
- route.children = children as TChildren as TODO
169
+ route.children = children as TChildren
153
170
  }
154
171
 
155
172
  if (typeof children === 'object' && children !== null) {
156
- route.children = Object.values(children) as TChildren as TODO
173
+ route.children = Object.values(children) as TChildren
157
174
  }
158
175
 
159
- return route as any
176
+ return route
160
177
  },
161
178
 
162
179
  _addFileTypes: <TFileTypes>() => route,
@@ -165,6 +182,10 @@ export function createServerRoute<
165
182
  return route
166
183
  }
167
184
 
185
+ // TODO this needs to be restricted to only allow middleware, no methods
186
+ // TODO we also need to restrict pathless server routes to only allow middleware
187
+ export const createServerRootRoute = createServerRoute
188
+
168
189
  export type ServerRouteAddFileChildrenFn<
169
190
  in out TParentRoute extends AnyServerRouteWithTypes,
170
191
  in out TId extends RouteConstraints['TId'],
@@ -190,33 +211,57 @@ const createMethodBuilder = <
190
211
  TFullPath extends string,
191
212
  TMiddlewares,
192
213
  >(
193
- __opts?: TODO,
214
+ __opts?: ServerRouteMethodBuilderOptions<
215
+ TParentRoute,
216
+ TFullPath,
217
+ TMiddlewares,
218
+ unknown,
219
+ unknown
220
+ >,
194
221
  ): ServerRouteMethodBuilder<TParentRoute, TFullPath, TMiddlewares> => {
195
222
  return {
196
- _options: __opts || {},
197
- _types: {} as TODO,
223
+ _options: (__opts || {}) as never,
224
+ _types: {} as never,
198
225
  middleware: (middlewares) =>
199
226
  createMethodBuilder({
200
227
  ...__opts,
201
228
  middlewares,
202
- }) as TODO,
229
+ }) as never,
203
230
  handler: (handler) =>
204
231
  createMethodBuilder({
205
232
  ...__opts,
206
- handler,
207
- }) as TODO,
233
+ handler: handler as never,
234
+ }) as never,
208
235
  }
209
236
  }
210
237
 
238
+ export interface ServerRouteMethodBuilderOptions<
239
+ TParentRoute extends AnyServerRouteWithTypes,
240
+ TFullPath extends string,
241
+ TMiddlewares,
242
+ TMethodMiddlewares,
243
+ TResponse,
244
+ > {
245
+ handler?: ServerRouteMethodHandlerFn<
246
+ TParentRoute,
247
+ TFullPath,
248
+ TMiddlewares,
249
+ TMethodMiddlewares,
250
+ TResponse
251
+ >
252
+ middlewares?: Constrain<
253
+ TMethodMiddlewares,
254
+ ReadonlyArray<AnyRequestMiddleware>
255
+ >
256
+ }
257
+
211
258
  export type CreateServerFileRoute<
212
259
  TParentRoute extends AnyServerRouteWithTypes,
213
260
  TId extends RouteConstraints['TId'],
214
261
  TPath extends RouteConstraints['TPath'],
215
262
  TFullPath extends RouteConstraints['TFullPath'],
216
263
  TChildren,
217
- > = (
218
- options?: undefined,
219
- ) => ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>
264
+ > = () => ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>
220
265
 
221
266
  export type AnyServerRouteWithTypes = ServerRouteWithTypes<
222
267
  any,
@@ -497,6 +542,7 @@ export type AnyRouteMethodsBuilder = ServerRouteMethodBuilderWithTypes<
497
542
  any,
498
543
  any,
499
544
  any,
545
+ any,
500
546
  any
501
547
  >
502
548
 
@@ -505,6 +551,7 @@ export interface ServerRouteMethodBuilder<
505
551
  TFullPath extends string,
506
552
  TMiddlewares,
507
553
  > extends ServerRouteMethodBuilderWithTypes<
554
+ TParentRoute,
508
555
  TFullPath,
509
556
  TMiddlewares,
510
557
  undefined,
@@ -519,12 +566,19 @@ export interface ServerRouteMethodBuilder<
519
566
  > {}
520
567
 
521
568
  export interface ServerRouteMethodBuilderWithTypes<
569
+ TParentRoute extends AnyServerRouteWithTypes,
522
570
  TFullPath extends string,
523
571
  TMiddlewares,
524
572
  TMethodMiddlewares,
525
573
  TResponse,
526
574
  > {
527
- _options: TODO
575
+ _options: ServerRouteMethodBuilderOptions<
576
+ TParentRoute,
577
+ TFullPath,
578
+ TMiddlewares,
579
+ TMethodMiddlewares,
580
+ TResponse
581
+ >
528
582
  _types: ServerRouteMethodBuilderTypes<
529
583
  TFullPath,
530
584
  TMiddlewares,
@@ -569,6 +623,7 @@ export interface ServerRouteMethodBuilderAfterMiddleware<
569
623
  TMiddlewares,
570
624
  TMethodMiddlewares,
571
625
  > extends ServerRouteMethodBuilderWithTypes<
626
+ TParentRoute,
572
627
  TFullPath,
573
628
  TMiddlewares,
574
629
  TMethodMiddlewares,
@@ -611,6 +666,7 @@ export interface ServerRouteMethodBuilderAfterHandler<
611
666
  TMethodMiddlewares,
612
667
  TResponse,
613
668
  > extends ServerRouteMethodBuilderWithTypes<
669
+ TParentRoute,
614
670
  TFullPath,
615
671
  TMiddlewares,
616
672
  TMethodMiddlewares,
@@ -1,5 +1,18 @@
1
- declare module 'tanstack:start-manifest' {
1
+ declare module 'tanstack-start-manifest:v' {
2
2
  import type { Manifest } from '@tanstack/router-core'
3
3
 
4
4
  export const tsrStartManifest: () => Manifest
5
5
  }
6
+
7
+ declare module 'tanstack-start-route-tree:v' {
8
+ import type { AnyServerRoute } from '@tanstack/start-server-core'
9
+
10
+ export const serverRouteTree: AnyServerRoute | undefined
11
+ }
12
+
13
+ declare module 'tanstack-start-server-fn-manifest:v' {
14
+ import type { DirectiveFn } from '@tanstack/directive-functions-plugin'
15
+
16
+ const serverFnManifest: Record<string, DirectiveFn>
17
+ export default serverFnManifest
18
+ }
@@ -0,0 +1,13 @@
1
+ /* eslint-disable @typescript-eslint/consistent-type-imports */
2
+
3
+ export const VIRTUAL_MODULES = {
4
+ routeTree: 'tanstack-start-route-tree:v',
5
+ startManifest: 'tanstack-start-manifest:v',
6
+ serverFnManifest: 'tanstack-start-server-fn-manifest:v',
7
+ } as const
8
+
9
+ export type VirtualModules = {
10
+ [VIRTUAL_MODULES.routeTree]: typeof import('tanstack-start-route-tree:v')
11
+ [VIRTUAL_MODULES.startManifest]: typeof import('tanstack-start-manifest:v')
12
+ [VIRTUAL_MODULES.serverFnManifest]: typeof import('tanstack-start-server-fn-manifest:v')
13
+ }