@tanstack/start-server-core 1.121.0-alpha.22 → 1.121.0-alpha.26

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 +8 -31
  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 +5 -23
  10. package/dist/cjs/router-manifest.cjs.map +1 -1
  11. package/dist/cjs/router-manifest.d.cts +0 -3
  12. package/dist/cjs/server-functions-handler.cjs +4 -25
  13. package/dist/cjs/server-functions-handler.cjs.map +1 -1
  14. package/dist/cjs/serverRoute.cjs +2 -0
  15. package/dist/cjs/serverRoute.cjs.map +1 -1
  16. package/dist/cjs/serverRoute.d.cts +3 -2
  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 +8 -9
  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 +0 -3
  29. package/dist/esm/router-manifest.js +5 -1
  30. package/dist/esm/router-manifest.js.map +1 -1
  31. package/dist/esm/server-functions-handler.js +4 -3
  32. package/dist/esm/server-functions-handler.js.map +1 -1
  33. package/dist/esm/serverRoute.d.ts +3 -2
  34. package/dist/esm/serverRoute.js +2 -0
  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 +3 -3
  40. package/src/createStartHandler.ts +15 -10
  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 +5 -6
  45. package/src/server-functions-handler.ts +5 -13
  46. package/src/serverRoute.ts +12 -7
  47. package/src/tanstack-start.d.ts +14 -1
  48. package/src/virtual-modules.ts +13 -0
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, FileRoutesByPath } 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,9 +1,6 @@
1
1
  import { joinPaths, rootRouteId } from '@tanstack/router-core'
2
-
3
- declare global {
4
- // eslint-disable-next-line no-var
5
- var TSS_INJECTED_HEAD_SCRIPTS: string | undefined
6
- }
2
+ import { VIRTUAL_MODULES } from './virtual-modules'
3
+ import { loadVirtualModule } from './loadVirtualModule'
7
4
 
8
5
  /**
9
6
  * @description Returns the router manifest that should be sent to the client.
@@ -12,7 +9,9 @@ declare global {
12
9
  * between routes or any other data that is not needed for the client.
13
10
  */
14
11
  export async function getStartManifest(opts: { basePath: string }) {
15
- const { tsrStartManifest } = await import('tanstack-start-router-manifest:v')
12
+ const { tsrStartManifest } = await loadVirtualModule(
13
+ VIRTUAL_MODULES.startManifest,
14
+ )
16
15
  const startManifest = tsrStartManifest()
17
16
 
18
17
  const rootRoute = (startManifest.routes[rootRouteId] =
@@ -2,6 +2,8 @@ import { isNotFound } from '@tanstack/router-core'
2
2
  import invariant from 'tiny-invariant'
3
3
  import { startSerializer } from '@tanstack/start-client-core'
4
4
  import { getEvent, getResponseStatus } from './h3'
5
+ import { VIRTUAL_MODULES } from './virtual-modules'
6
+ import { loadVirtualModule } from './loadVirtualModule'
5
7
 
6
8
  function sanitizeBase(base: string | undefined) {
7
9
  if (!base) {
@@ -42,19 +44,9 @@ export const handleServerAction = async ({ request }: { request: Request }) => {
42
44
  throw new Error('Invalid server action param for serverFnId: ' + serverFnId)
43
45
  }
44
46
 
45
- const { default: serverFnManifest } = (await import(
46
- // @ts-expect-error
47
- 'tanstack-start-server-fn-manifest:v'
48
- )) as {
49
- default: Record<
50
- string,
51
- {
52
- functionName: string
53
- extractedFilename: string
54
- importer: () => Promise<any>
55
- }
56
- >
57
- }
47
+ const { default: serverFnManifest } = await loadVirtualModule(
48
+ VIRTUAL_MODULES.serverFnManifest,
49
+ )
58
50
 
59
51
  const serverFnInfo = serverFnManifest[serverFnId]
60
52
 
@@ -13,21 +13,22 @@ import type {
13
13
  } from '@tanstack/start-client-core'
14
14
 
15
15
  export function createServerFileRoute<
16
- TFilePath extends keyof FileRoutesByPath,
16
+ TFilePath extends keyof ServerFileRoutesByPath,
17
17
  TParentRoute extends
18
- AnyServerRouteWithTypes = FileRoutesByPath[TFilePath]['parentRoute'],
19
- TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'],
20
- TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'],
18
+ AnyServerRouteWithTypes = ServerFileRoutesByPath[TFilePath]['parentRoute'],
19
+ TId extends RouteConstraints['TId'] = ServerFileRoutesByPath[TFilePath]['id'],
20
+ TPath extends
21
+ RouteConstraints['TPath'] = ServerFileRoutesByPath[TFilePath]['path'],
21
22
  TFullPath extends
22
- RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath'],
23
- TChildren = FileRoutesByPath[TFilePath]['children'],
23
+ RouteConstraints['TFullPath'] = ServerFileRoutesByPath[TFilePath]['fullPath'],
24
+ TChildren = ServerFileRoutesByPath[TFilePath]['children'],
24
25
  >(_: TFilePath): ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren> {
25
26
  return createServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>(
26
27
  undefined,
27
28
  )
28
29
  }
29
30
 
30
- export interface FileRoutesByPath {}
31
+ export interface ServerFileRoutesByPath {}
31
32
 
32
33
  export interface ServerRouteOptions<
33
34
  TParentRoute extends AnyServerRouteWithTypes,
@@ -181,6 +182,10 @@ export function createServerRoute<
181
182
  return route
182
183
  }
183
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
+
184
189
  export type ServerRouteAddFileChildrenFn<
185
190
  in out TParentRoute extends AnyServerRouteWithTypes,
186
191
  in out TId extends RouteConstraints['TId'],
@@ -1,5 +1,18 @@
1
- declare module 'tanstack-start-router-manifest:v' {
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
+ }