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

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 (103) hide show
  1. package/dist/esm/constants.d.ts +3 -0
  2. package/dist/esm/constants.js +7 -0
  3. package/dist/esm/constants.js.map +1 -0
  4. package/dist/esm/createStartHandler.d.ts +4 -7
  5. package/dist/esm/createStartHandler.js +169 -102
  6. package/dist/esm/createStartHandler.js.map +1 -1
  7. package/dist/esm/index.d.ts +6 -8
  8. package/dist/esm/index.js +10 -97
  9. package/dist/esm/index.js.map +1 -1
  10. package/dist/esm/loadVirtualModule.js +2 -0
  11. package/dist/esm/loadVirtualModule.js.map +1 -1
  12. package/dist/esm/request-response.d.ts +124 -0
  13. package/dist/esm/request-response.js +177 -0
  14. package/dist/esm/request-response.js.map +1 -0
  15. package/dist/esm/router-manifest.d.ts +1 -0
  16. package/dist/esm/router-manifest.js +17 -17
  17. package/dist/esm/router-manifest.js.map +1 -1
  18. package/dist/esm/server-functions-handler.js +6 -7
  19. package/dist/esm/server-functions-handler.js.map +1 -1
  20. package/dist/esm/serverRoute.d.ts +6 -2
  21. package/dist/esm/serverRoute.js +3 -2
  22. package/dist/esm/serverRoute.js.map +1 -1
  23. package/dist/esm/session.d.ts +66 -0
  24. package/dist/esm/virtual-modules.d.ts +2 -0
  25. package/dist/esm/virtual-modules.js +2 -1
  26. package/dist/esm/virtual-modules.js.map +1 -1
  27. package/package.json +9 -19
  28. package/src/constants.ts +3 -0
  29. package/src/createStartHandler.ts +241 -143
  30. package/src/global.d.ts +10 -2
  31. package/src/index.tsx +42 -13
  32. package/src/loadVirtualModule.ts +2 -0
  33. package/src/request-response.ts +335 -0
  34. package/src/router-manifest.ts +17 -38
  35. package/src/server-functions-handler.ts +6 -5
  36. package/src/serverRoute.ts +22 -3
  37. package/src/session.ts +75 -0
  38. package/src/tanstack-start.d.ts +18 -5
  39. package/src/virtual-modules.ts +2 -0
  40. package/dist/cjs/createRequestHandler.cjs +0 -50
  41. package/dist/cjs/createRequestHandler.cjs.map +0 -1
  42. package/dist/cjs/createRequestHandler.d.cts +0 -8
  43. package/dist/cjs/createStartHandler.cjs +0 -274
  44. package/dist/cjs/createStartHandler.cjs.map +0 -1
  45. package/dist/cjs/createStartHandler.d.cts +0 -10
  46. package/dist/cjs/h3.cjs +0 -355
  47. package/dist/cjs/h3.cjs.map +0 -1
  48. package/dist/cjs/h3.d.cts +0 -109
  49. package/dist/cjs/handlerCallback.cjs +0 -7
  50. package/dist/cjs/handlerCallback.cjs.map +0 -1
  51. package/dist/cjs/handlerCallback.d.cts +0 -9
  52. package/dist/cjs/index.cjs +0 -245
  53. package/dist/cjs/index.cjs.map +0 -1
  54. package/dist/cjs/index.d.cts +0 -12
  55. package/dist/cjs/loadVirtualModule.cjs +0 -39
  56. package/dist/cjs/loadVirtualModule.cjs.map +0 -1
  57. package/dist/cjs/loadVirtualModule.d.cts +0 -6
  58. package/dist/cjs/router-manifest.cjs +0 -49
  59. package/dist/cjs/router-manifest.cjs.map +0 -1
  60. package/dist/cjs/router-manifest.d.cts +0 -16
  61. package/dist/cjs/server-functions-handler.cjs +0 -148
  62. package/dist/cjs/server-functions-handler.cjs.map +0 -1
  63. package/dist/cjs/server-functions-handler.d.cts +0 -3
  64. package/dist/cjs/serverRoute.cjs +0 -102
  65. package/dist/cjs/serverRoute.cjs.map +0 -1
  66. package/dist/cjs/serverRoute.d.cts +0 -120
  67. package/dist/cjs/ssr-server.cjs +0 -247
  68. package/dist/cjs/ssr-server.cjs.map +0 -1
  69. package/dist/cjs/ssr-server.d.cts +0 -29
  70. package/dist/cjs/transformStreamWithRouter.cjs +0 -183
  71. package/dist/cjs/transformStreamWithRouter.cjs.map +0 -1
  72. package/dist/cjs/transformStreamWithRouter.d.cts +0 -6
  73. package/dist/cjs/tsrScript.cjs +0 -4
  74. package/dist/cjs/tsrScript.cjs.map +0 -1
  75. package/dist/cjs/tsrScript.d.cts +0 -1
  76. package/dist/cjs/virtual-modules.cjs +0 -9
  77. package/dist/cjs/virtual-modules.cjs.map +0 -1
  78. package/dist/cjs/virtual-modules.d.cts +0 -10
  79. package/dist/esm/createRequestHandler.d.ts +0 -8
  80. package/dist/esm/createRequestHandler.js +0 -50
  81. package/dist/esm/createRequestHandler.js.map +0 -1
  82. package/dist/esm/h3.d.ts +0 -109
  83. package/dist/esm/h3.js +0 -248
  84. package/dist/esm/h3.js.map +0 -1
  85. package/dist/esm/handlerCallback.d.ts +0 -9
  86. package/dist/esm/handlerCallback.js +0 -7
  87. package/dist/esm/handlerCallback.js.map +0 -1
  88. package/dist/esm/ssr-server.d.ts +0 -29
  89. package/dist/esm/ssr-server.js +0 -247
  90. package/dist/esm/ssr-server.js.map +0 -1
  91. package/dist/esm/transformStreamWithRouter.d.ts +0 -6
  92. package/dist/esm/transformStreamWithRouter.js +0 -183
  93. package/dist/esm/transformStreamWithRouter.js.map +0 -1
  94. package/dist/esm/tsrScript.d.ts +0 -1
  95. package/dist/esm/tsrScript.js +0 -5
  96. package/dist/esm/tsrScript.js.map +0 -1
  97. package/src/createRequestHandler.ts +0 -73
  98. package/src/h3.ts +0 -492
  99. package/src/handlerCallback.ts +0 -15
  100. package/src/ssr-server.ts +0 -352
  101. package/src/transformStreamWithRouter.ts +0 -258
  102. package/src/tsrScript.ts +0 -91
  103. package/src/vite-env.d.ts +0 -4
package/dist/esm/index.js CHANGED
@@ -1,137 +1,50 @@
1
- import { transformPipeableStreamWithRouter, transformReadableStreamWithRouter } from "./transformStreamWithRouter.js";
2
- import { createStartHandler, getStartResponseHeaders } from "./createStartHandler.js";
3
- import { createRequestHandler } from "./createRequestHandler.js";
4
- import { defineHandlerCallback } from "./handlerCallback.js";
5
- import { attachRouterServerSsrUtils, dehydrateRouter } from "./ssr-server.js";
1
+ import { createStartHandler } from "./createStartHandler.js";
2
+ import { attachRouterServerSsrUtils, createRequestHandler, defineHandlerCallback, transformPipeableStreamWithRouter, transformReadableStreamWithRouter } from "@tanstack/router-core/ssr/server";
6
3
  import { handleServerAction } from "./server-functions-handler.js";
7
- import { HTTPEventSymbol, appendCorsHeaders, appendCorsPreflightHeaders, appendHeader, appendHeaders, appendResponseHeader, appendResponseHeaders, assertMethod, clearResponseHeaders, clearSession, defaultContentType, defineEventHandler, defineMiddleware, deleteCookie, eventHandler, fetchWithEvent, getContext, getCookie, getEvent, getHeader, getHeaders, getProxyRequestHeaders, getQuery, getRequestFingerprint, getRequestHeader, getRequestHeaders, getRequestHost, getRequestIP, getRequestProtocol, getRequestURL, getRequestWebStream, getResponseHeader, getResponseHeaders, getResponseStatus, getResponseStatusText, getRouterParam, getRouterParams, getSession, getValidatedQuery, getValidatedRouterParams, getWebRequest, handleCacheHeaders, handleCors, isEvent, isMethod, isPreflightRequest, parseCookies, proxyRequest, readBody, readFormData, readMultipartFormData, readRawBody, readValidatedBody, removeResponseHeader, requestHandler, runWithEvent, sealSession, send, sendError, sendNoContent, sendProxy, sendRedirect, sendStream, sendWebResponse, setContext, setCookie, setHeader, setHeaders, setResponseHeader, setResponseHeaders, setResponseStatus, unsealSession, updateSession, useSession, writeEarlyHints } from "./h3.js";
4
+ import { clearResponseHeaders, clearSession, deleteCookie, getCookie, getCookies, getRequest, getRequestHeader, getRequestHeaders, getRequestHost, getRequestIP, getRequestProtocol, getRequestUrl, getResponse, getResponseHeader, getResponseHeaders, getResponseStatus, getSession, getValidatedQuery, removeResponseHeader, requestHandler, sealSession, setCookie, setResponseHeader, setResponseHeaders, setResponseStatus, unsealSession, updateSession, useSession } from "./request-response.js";
8
5
  import { createServerFileRoute, createServerRootRoute, createServerRoute } from "./serverRoute.js";
9
6
  import { VIRTUAL_MODULES } from "./virtual-modules.js";
10
- import { H3Error, H3Event, MIMES, callNodeListener, createApp, createAppEventHandler, createError, createEvent, createRouter, defineLazyEventHandler, defineNodeListener, defineNodeMiddleware, defineRequestMiddleware, defineResponseMiddleware, defineWebSocket, dynamicEventHandler, fromNodeMiddleware, fromPlainHandler, fromWebHandler, isCorsOriginAllowed, isError, isEventHandler, isStream, isWebResponse, lazyEventHandler, promisifyNodeListener, sanitizeStatusCode, sanitizeStatusMessage, serveStatic, splitCookiesString, toEventHandler, toNodeListener, toPlainHandler, toWebHandler, toWebRequest, useBase } from "h3";
7
+ import { HEADERS } from "./constants.js";
11
8
  export {
12
- H3Error,
13
- H3Event,
14
- HTTPEventSymbol,
15
- MIMES,
9
+ HEADERS,
16
10
  VIRTUAL_MODULES,
17
- appendCorsHeaders,
18
- appendCorsPreflightHeaders,
19
- appendHeader,
20
- appendHeaders,
21
- appendResponseHeader,
22
- appendResponseHeaders,
23
- assertMethod,
24
11
  attachRouterServerSsrUtils,
25
- callNodeListener,
26
12
  clearResponseHeaders,
27
13
  clearSession,
28
- createApp,
29
- createAppEventHandler,
30
- createError,
31
- createEvent,
32
14
  createRequestHandler,
33
- createRouter,
34
15
  createServerFileRoute,
35
16
  createServerRootRoute,
36
17
  createServerRoute,
37
18
  createStartHandler,
38
- defaultContentType,
39
- defineEventHandler,
40
19
  defineHandlerCallback,
41
- defineLazyEventHandler,
42
- defineMiddleware,
43
- defineNodeListener,
44
- defineNodeMiddleware,
45
- defineRequestMiddleware,
46
- defineResponseMiddleware,
47
- defineWebSocket,
48
- dehydrateRouter,
49
20
  deleteCookie,
50
- dynamicEventHandler,
51
- eventHandler,
52
- fetchWithEvent,
53
- fromNodeMiddleware,
54
- fromPlainHandler,
55
- fromWebHandler,
56
- getContext,
57
21
  getCookie,
58
- getEvent,
59
- getHeader,
60
- getHeaders,
61
- getProxyRequestHeaders,
62
- getQuery,
63
- getRequestFingerprint,
22
+ getCookies,
23
+ getRequest,
64
24
  getRequestHeader,
65
25
  getRequestHeaders,
66
26
  getRequestHost,
67
27
  getRequestIP,
68
28
  getRequestProtocol,
69
- getRequestURL,
70
- getRequestWebStream,
29
+ getRequestUrl,
30
+ getResponse,
71
31
  getResponseHeader,
72
32
  getResponseHeaders,
73
33
  getResponseStatus,
74
- getResponseStatusText,
75
- getRouterParam,
76
- getRouterParams,
77
34
  getSession,
78
- getStartResponseHeaders,
79
35
  getValidatedQuery,
80
- getValidatedRouterParams,
81
- getWebRequest,
82
- handleCacheHeaders,
83
- handleCors,
84
36
  handleServerAction,
85
- isCorsOriginAllowed,
86
- isError,
87
- isEvent,
88
- isEventHandler,
89
- isMethod,
90
- isPreflightRequest,
91
- isStream,
92
- isWebResponse,
93
- lazyEventHandler,
94
- parseCookies,
95
- promisifyNodeListener,
96
- proxyRequest,
97
- readBody,
98
- readFormData,
99
- readMultipartFormData,
100
- readRawBody,
101
- readValidatedBody,
102
37
  removeResponseHeader,
103
38
  requestHandler,
104
- runWithEvent,
105
- sanitizeStatusCode,
106
- sanitizeStatusMessage,
107
39
  sealSession,
108
- send,
109
- sendError,
110
- sendNoContent,
111
- sendProxy,
112
- sendRedirect,
113
- sendStream,
114
- sendWebResponse,
115
- serveStatic,
116
- setContext,
117
40
  setCookie,
118
- setHeader,
119
- setHeaders,
120
41
  setResponseHeader,
121
42
  setResponseHeaders,
122
43
  setResponseStatus,
123
- splitCookiesString,
124
- toEventHandler,
125
- toNodeListener,
126
- toPlainHandler,
127
- toWebHandler,
128
- toWebRequest,
129
44
  transformPipeableStreamWithRouter,
130
45
  transformReadableStreamWithRouter,
131
46
  unsealSession,
132
47
  updateSession,
133
- useBase,
134
- useSession,
135
- writeEarlyHints
48
+ useSession
136
49
  };
137
50
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
@@ -7,6 +7,8 @@ async function loadVirtualModule(id) {
7
7
  return await import("tanstack-start-manifest:v");
8
8
  case VIRTUAL_MODULES.serverFnManifest:
9
9
  return await import("tanstack-start-server-fn-manifest:v");
10
+ case VIRTUAL_MODULES.injectedHeadScripts:
11
+ return await import("tanstack-start-injected-head-scripts:v");
10
12
  default:
11
13
  throw new Error(`Unknown virtual module: ${id}`);
12
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"loadVirtualModule.js","sources":["../../src/loadVirtualModule.ts"],"sourcesContent":["import { VIRTUAL_MODULES } from './virtual-modules'\nimport type { VirtualModules } from './virtual-modules'\n\n/**\n * we need to explicitly enumerate all imports with string literals,\n * otherwise vite will not pick them up during build\n */\nexport async function loadVirtualModule<TId extends keyof VirtualModules>(\n id: TId,\n): Promise<VirtualModules[TId]> {\n switch (id) {\n case VIRTUAL_MODULES.routeTree:\n return (await import('tanstack-start-route-tree:v')) as any\n case VIRTUAL_MODULES.startManifest:\n return (await import('tanstack-start-manifest:v')) as any\n case VIRTUAL_MODULES.serverFnManifest:\n return (await import('tanstack-start-server-fn-manifest:v')) as any\n default:\n throw new Error(`Unknown virtual module: ${id}`)\n }\n}\n"],"names":[],"mappings":";AAOA,eAAsB,kBACpB,IAC8B;AAC9B,UAAQ,IAAI;AAAA,IACV,KAAK,gBAAgB;AACX,aAAA,MAAM,OAAO,6BAA6B;AAAA,IACpD,KAAK,gBAAgB;AACX,aAAA,MAAM,OAAO,2BAA2B;AAAA,IAClD,KAAK,gBAAgB;AACX,aAAA,MAAM,OAAO,qCAAqC;AAAA,IAC5D;AACE,YAAM,IAAI,MAAM,2BAA2B,EAAE,EAAE;AAAA,EAAA;AAErD;"}
1
+ {"version":3,"file":"loadVirtualModule.js","sources":["../../src/loadVirtualModule.ts"],"sourcesContent":["import { VIRTUAL_MODULES } from './virtual-modules'\nimport type { VirtualModules } from './virtual-modules'\n\n/**\n * we need to explicitly enumerate all imports with string literals,\n * otherwise vite will not pick them up during build\n */\nexport async function loadVirtualModule<TId extends keyof VirtualModules>(\n id: TId,\n): Promise<VirtualModules[TId]> {\n switch (id) {\n case VIRTUAL_MODULES.routeTree:\n return (await import('tanstack-start-route-tree:v')) as any\n case VIRTUAL_MODULES.startManifest:\n return (await import('tanstack-start-manifest:v')) as any\n case VIRTUAL_MODULES.serverFnManifest:\n return (await import('tanstack-start-server-fn-manifest:v')) as any\n case VIRTUAL_MODULES.injectedHeadScripts:\n return (await import('tanstack-start-injected-head-scripts:v')) as any\n default:\n throw new Error(`Unknown virtual module: ${id}`)\n }\n}\n"],"names":[],"mappings":";AAOA,eAAsB,kBACpB,IAC8B;AAC9B,UAAQ,IAAA;AAAA,IACN,KAAK,gBAAgB;AACnB,aAAQ,MAAM,OAAO,6BAA6B;AAAA,IACpD,KAAK,gBAAgB;AACnB,aAAQ,MAAM,OAAO,2BAA2B;AAAA,IAClD,KAAK,gBAAgB;AACnB,aAAQ,MAAM,OAAO,qCAAqC;AAAA,IAC5D,KAAK,gBAAgB;AACnB,aAAQ,MAAM,OAAO,wCAAwC;AAAA,IAC/D;AACE,YAAM,IAAI,MAAM,2BAA2B,EAAE,EAAE;AAAA,EAAA;AAErD;"}
@@ -0,0 +1,124 @@
1
+ import { RequestHeaderMap, RequestHeaderName, ResponseHeaderMap, ResponseHeaderName, TypedHeaders } from 'fetchdts';
2
+ import { CookieSerializeOptions } from 'cookie-es';
3
+ import { Session, SessionConfig, SessionData, SessionManager, SessionUpdate } from './session.js';
4
+ import { StandardSchemaV1 } from '@standard-schema/spec';
5
+ export type RequestHandler = (request: Request) => Promise<Response> | Response;
6
+ export type { ResponseHeaderName, RequestHeaderName };
7
+ export declare function requestHandler(handler: RequestHandler): (request: Request) => Promise<Response> | Response;
8
+ export declare function getRequest(): Request;
9
+ export declare function getRequestHeaders(): TypedHeaders<RequestHeaderMap>;
10
+ export declare function getRequestHeader(name: RequestHeaderName): string | undefined;
11
+ export declare function getRequestIP(opts?: {
12
+ /**
13
+ * Use the X-Forwarded-For HTTP header set by proxies.
14
+ *
15
+ * Note: Make sure that this header can be trusted (your application running behind a CDN or reverse proxy) before enabling.
16
+ */
17
+ xForwardedFor?: boolean;
18
+ }): string | undefined;
19
+ /**
20
+ * Get the request hostname.
21
+ *
22
+ * If `xForwardedHost` is `true`, it will use the `x-forwarded-host` header if it exists.
23
+ *
24
+ * If no host header is found, it will default to "localhost".
25
+ */
26
+ export declare function getRequestHost(opts?: {
27
+ xForwardedHost?: boolean;
28
+ }): string;
29
+ /**
30
+ * Get the full incoming request URL.
31
+ *
32
+ * If `xForwardedHost` is `true`, it will use the `x-forwarded-host` header if it exists.
33
+ *
34
+ * If `xForwardedProto` is `false`, it will not use the `x-forwarded-proto` header.
35
+ */
36
+ export declare function getRequestUrl(opts?: {
37
+ xForwardedHost?: boolean;
38
+ xForwardedProto?: boolean;
39
+ }): URL;
40
+ /**
41
+ * Get the request protocol.
42
+ *
43
+ * If `x-forwarded-proto` header is set to "https", it will return "https". You can disable this behavior by setting `xForwardedProto` to `false`.
44
+ *
45
+ * If protocol cannot be determined, it will default to "http".
46
+ */
47
+ export declare function getRequestProtocol(opts?: {
48
+ xForwardedProto?: boolean;
49
+ }): 'http' | 'https' | (string & {});
50
+ export declare function setResponseHeaders(headers: TypedHeaders<ResponseHeaderMap>): void;
51
+ export declare function getResponseHeaders(): TypedHeaders<ResponseHeaderMap>;
52
+ export declare function getResponseHeader(name: ResponseHeaderName): string | undefined;
53
+ export declare function setResponseHeader(name: ResponseHeaderName, value: string | Array<string>): void;
54
+ export declare function removeResponseHeader(name: ResponseHeaderName): void;
55
+ export declare function clearResponseHeaders(headerNames?: Array<ResponseHeaderName>): void;
56
+ export declare function getResponseStatus(): number;
57
+ export declare function setResponseStatus(code?: number, text?: string): void;
58
+ /**
59
+ * Parse the request to get HTTP Cookie header string and return an object of all cookie name-value pairs.
60
+ * @returns Object of cookie name-value pairs
61
+ * ```ts
62
+ * const cookies = getCookies()
63
+ * ```
64
+ */
65
+ export declare function getCookies(): Record<string, string>;
66
+ /**
67
+ * Get a cookie value by name.
68
+ * @param name Name of the cookie to get
69
+ * @returns {*} Value of the cookie (String or undefined)
70
+ * ```ts
71
+ * const authorization = getCookie('Authorization')
72
+ * ```
73
+ */
74
+ export declare function getCookie(name: string): string | undefined;
75
+ /**
76
+ * Set a cookie value by name.
77
+ * @param name Name of the cookie to set
78
+ * @param value Value of the cookie to set
79
+ * @param options {CookieSerializeOptions} Options for serializing the cookie
80
+ * ```ts
81
+ * setCookie('Authorization', '1234567')
82
+ * ```
83
+ */
84
+ export declare function setCookie(name: string, value: string, options?: CookieSerializeOptions): void;
85
+ /**
86
+ * Remove a cookie by name.
87
+ * @param name Name of the cookie to delete
88
+ * @param serializeOptions {CookieSerializeOptions} Cookie options
89
+ * ```ts
90
+ * deleteCookie('SessionId')
91
+ * ```
92
+ */
93
+ export declare function deleteCookie(name: string, options?: CookieSerializeOptions): void;
94
+ /**
95
+ * Create a session manager for the current request.
96
+ */
97
+ export declare function useSession<TSessionData extends SessionData = SessionData>(config: SessionConfig): Promise<SessionManager<TSessionData>>;
98
+ /**
99
+ * Get the session for the current request
100
+ */
101
+ export declare function getSession<TSessionData extends SessionData = SessionData>(config: SessionConfig): Promise<Session<TSessionData>>;
102
+ /**
103
+ * Update the session data for the current request.
104
+ */
105
+ export declare function updateSession<TSessionData extends SessionData = SessionData>(config: SessionConfig, update?: SessionUpdate<TSessionData>): Promise<Session<TSessionData>>;
106
+ /**
107
+ * Encrypt and sign the session data for the current request.
108
+ */
109
+ export declare function sealSession(config: SessionConfig): Promise<string>;
110
+ /**
111
+ * Decrypt and verify the session data for the current request.
112
+ */
113
+ export declare function unsealSession(config: SessionConfig, sealed: string): Promise<Partial<Session>>;
114
+ /**
115
+ * Clear the session data for the current request.
116
+ */
117
+ export declare function clearSession(config: Partial<SessionConfig>): Promise<void>;
118
+ export declare function getResponse(): {
119
+ status?: number;
120
+ statusText?: string;
121
+ _headers?: Headers;
122
+ get headers(): Headers;
123
+ } | undefined;
124
+ export declare function getValidatedQuery<TSchema extends StandardSchemaV1>(schema: StandardSchemaV1): Promise<StandardSchemaV1.InferOutput<TSchema>>;
@@ -0,0 +1,177 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { H3Event, toResponse, getRequestIP as getRequestIP$1, getRequestHost as getRequestHost$1, getRequestURL, getRequestProtocol as getRequestProtocol$1, sanitizeStatusCode, sanitizeStatusMessage, parseCookies, setCookie as setCookie$1, deleteCookie as deleteCookie$1, useSession as useSession$1, getSession as getSession$1, updateSession as updateSession$1, sealSession as sealSession$1, unsealSession as unsealSession$1, clearSession as clearSession$1, getValidatedQuery as getValidatedQuery$1 } from "h3";
3
+ const eventStorage = new AsyncLocalStorage();
4
+ function requestHandler(handler) {
5
+ return (request) => {
6
+ const h3Event = new H3Event(request);
7
+ const response = eventStorage.run({ h3Event }, () => handler(request));
8
+ return toResponse(response, h3Event);
9
+ };
10
+ }
11
+ function getH3Event() {
12
+ const event = eventStorage.getStore();
13
+ if (!event) {
14
+ throw new Error(
15
+ `No StartEvent found in AsyncLocalStorage. Make sure you are using the function within the server runtime.`
16
+ );
17
+ }
18
+ return event.h3Event;
19
+ }
20
+ function getRequest() {
21
+ const event = getH3Event();
22
+ return event.req;
23
+ }
24
+ function getRequestHeaders() {
25
+ return getH3Event().req.headers;
26
+ }
27
+ function getRequestHeader(name) {
28
+ return getRequestHeaders().get(name) || void 0;
29
+ }
30
+ function getRequestIP(opts) {
31
+ return getRequestIP$1(getH3Event(), opts);
32
+ }
33
+ function getRequestHost(opts) {
34
+ return getRequestHost$1(getH3Event(), opts);
35
+ }
36
+ function getRequestUrl(opts) {
37
+ return getRequestURL(getH3Event(), opts);
38
+ }
39
+ function getRequestProtocol(opts) {
40
+ return getRequestProtocol$1(getH3Event(), opts);
41
+ }
42
+ function setResponseHeaders(headers) {
43
+ const event = getH3Event();
44
+ for (const [name, value] of Object.entries(headers)) {
45
+ event.res.headers.set(name, value);
46
+ }
47
+ }
48
+ function getResponseHeaders() {
49
+ const event = getH3Event();
50
+ return Object.fromEntries(event.res.headers.entries());
51
+ }
52
+ function getResponseHeader(name) {
53
+ const event = getH3Event();
54
+ return event.res.headers.get(name) || void 0;
55
+ }
56
+ function setResponseHeader(name, value) {
57
+ const event = getH3Event();
58
+ if (Array.isArray(value)) {
59
+ event.res.headers.delete(name);
60
+ for (const valueItem of value) {
61
+ event.res.headers.append(name, valueItem);
62
+ }
63
+ } else {
64
+ event.res.headers.set(name, value);
65
+ }
66
+ }
67
+ function removeResponseHeader(name) {
68
+ const event = getH3Event();
69
+ event.res.headers.delete(name);
70
+ }
71
+ function clearResponseHeaders(headerNames) {
72
+ const event = getH3Event();
73
+ if (headerNames && headerNames.length > 0) {
74
+ for (const name of headerNames) {
75
+ event.res.headers.delete(name);
76
+ }
77
+ } else {
78
+ for (const name of event.res.headers.keys()) {
79
+ event.res.headers.delete(name);
80
+ }
81
+ }
82
+ }
83
+ function getResponseStatus() {
84
+ return getH3Event().res.status || 200;
85
+ }
86
+ function setResponseStatus(code, text) {
87
+ const event = getH3Event();
88
+ if (code) {
89
+ event.res.status = sanitizeStatusCode(code, event.res.status);
90
+ }
91
+ if (text) {
92
+ event.res.statusText = sanitizeStatusMessage(text);
93
+ }
94
+ }
95
+ function getCookies() {
96
+ const event = getH3Event();
97
+ return parseCookies(event);
98
+ }
99
+ function getCookie(name) {
100
+ return getCookies()[name] || void 0;
101
+ }
102
+ function setCookie(name, value, options) {
103
+ const event = getH3Event();
104
+ setCookie$1(event, name, value, options);
105
+ }
106
+ function deleteCookie(name, options) {
107
+ const event = getH3Event();
108
+ deleteCookie$1(event, name, options);
109
+ }
110
+ function getDefaultSessionConfig(config) {
111
+ return {
112
+ name: "start",
113
+ ...config
114
+ };
115
+ }
116
+ function useSession(config) {
117
+ const event = getH3Event();
118
+ return useSession$1(event, getDefaultSessionConfig(config));
119
+ }
120
+ function getSession(config) {
121
+ const event = getH3Event();
122
+ return getSession$1(event, getDefaultSessionConfig(config));
123
+ }
124
+ function updateSession(config, update) {
125
+ const event = getH3Event();
126
+ return updateSession$1(event, getDefaultSessionConfig(config), update);
127
+ }
128
+ function sealSession(config) {
129
+ const event = getH3Event();
130
+ return sealSession$1(event, getDefaultSessionConfig(config));
131
+ }
132
+ function unsealSession(config, sealed) {
133
+ const event = getH3Event();
134
+ return unsealSession$1(event, getDefaultSessionConfig(config), sealed);
135
+ }
136
+ function clearSession(config) {
137
+ const event = getH3Event();
138
+ return clearSession$1(event, { name: "start", ...config });
139
+ }
140
+ function getResponse() {
141
+ const event = getH3Event();
142
+ return event._res;
143
+ }
144
+ function getValidatedQuery(schema) {
145
+ return getValidatedQuery$1(getH3Event(), schema);
146
+ }
147
+ export {
148
+ clearResponseHeaders,
149
+ clearSession,
150
+ deleteCookie,
151
+ getCookie,
152
+ getCookies,
153
+ getRequest,
154
+ getRequestHeader,
155
+ getRequestHeaders,
156
+ getRequestHost,
157
+ getRequestIP,
158
+ getRequestProtocol,
159
+ getRequestUrl,
160
+ getResponse,
161
+ getResponseHeader,
162
+ getResponseHeaders,
163
+ getResponseStatus,
164
+ getSession,
165
+ getValidatedQuery,
166
+ removeResponseHeader,
167
+ requestHandler,
168
+ sealSession,
169
+ setCookie,
170
+ setResponseHeader,
171
+ setResponseHeaders,
172
+ setResponseStatus,
173
+ unsealSession,
174
+ updateSession,
175
+ useSession
176
+ };
177
+ //# sourceMappingURL=request-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-response.js","sources":["../../src/request-response.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks'\n\nimport {\n H3Event,\n clearSession as h3_clearSession,\n deleteCookie as h3_deleteCookie,\n getRequestHost as h3_getRequestHost,\n getRequestIP as h3_getRequestIP,\n getRequestProtocol as h3_getRequestProtocol,\n getRequestURL as h3_getRequestURL,\n getSession as h3_getSession,\n getValidatedQuery as h3_getValidatedQuery,\n parseCookies as h3_parseCookies,\n sanitizeStatusCode as h3_sanitizeStatusCode,\n sanitizeStatusMessage as h3_sanitizeStatusMessage,\n sealSession as h3_sealSession,\n setCookie as h3_setCookie,\n toResponse as h3_toResponse,\n unsealSession as h3_unsealSession,\n updateSession as h3_updateSession,\n useSession as h3_useSession,\n} from 'h3'\nimport type {\n RequestHeaderMap,\n RequestHeaderName,\n ResponseHeaderMap,\n ResponseHeaderName,\n TypedHeaders,\n} from 'fetchdts'\n\nimport type { CookieSerializeOptions } from 'cookie-es'\nimport type {\n Session,\n SessionConfig,\n SessionData,\n SessionManager,\n SessionUpdate,\n} from './session'\nimport type { StandardSchemaV1 } from '@standard-schema/spec'\n\ninterface StartEvent {\n h3Event: H3Event\n}\nconst eventStorage = new AsyncLocalStorage<StartEvent>()\n\nexport type RequestHandler = (request: Request) => Promise<Response> | Response\n\nexport type { ResponseHeaderName, RequestHeaderName }\n\nexport function requestHandler(handler: RequestHandler) {\n return (request: Request): Promise<Response> | Response => {\n const h3Event = new H3Event(request)\n\n const response = eventStorage.run({ h3Event }, () => handler(request))\n return h3_toResponse(response, h3Event)\n }\n}\n\nfunction getH3Event() {\n const event = eventStorage.getStore()\n if (!event) {\n throw new Error(\n `No StartEvent found in AsyncLocalStorage. Make sure you are using the function within the server runtime.`,\n )\n }\n return event.h3Event\n}\n\nexport function getRequest(): Request {\n const event = getH3Event()\n return event.req\n}\n\nexport function getRequestHeaders(): TypedHeaders<RequestHeaderMap> {\n // TODO `as any` not needed when fetchdts is updated\n return getH3Event().req.headers as any\n}\n\nexport function getRequestHeader(name: RequestHeaderName): string | undefined {\n return getRequestHeaders().get(name) || undefined\n}\n\nexport function getRequestIP(opts?: {\n /**\n * Use the X-Forwarded-For HTTP header set by proxies.\n *\n * Note: Make sure that this header can be trusted (your application running behind a CDN or reverse proxy) before enabling.\n */\n xForwardedFor?: boolean\n}) {\n return h3_getRequestIP(getH3Event(), opts)\n}\n\n/**\n * Get the request hostname.\n *\n * If `xForwardedHost` is `true`, it will use the `x-forwarded-host` header if it exists.\n *\n * If no host header is found, it will default to \"localhost\".\n */\nexport function getRequestHost(opts?: { xForwardedHost?: boolean }) {\n return h3_getRequestHost(getH3Event(), opts)\n}\n\n/**\n * Get the full incoming request URL.\n *\n * If `xForwardedHost` is `true`, it will use the `x-forwarded-host` header if it exists.\n *\n * If `xForwardedProto` is `false`, it will not use the `x-forwarded-proto` header.\n */\nexport function getRequestUrl(opts?: {\n xForwardedHost?: boolean\n xForwardedProto?: boolean\n}) {\n return h3_getRequestURL(getH3Event(), opts)\n}\n\n/**\n * Get the request protocol.\n *\n * If `x-forwarded-proto` header is set to \"https\", it will return \"https\". You can disable this behavior by setting `xForwardedProto` to `false`.\n *\n * If protocol cannot be determined, it will default to \"http\".\n */\nexport function getRequestProtocol(opts?: {\n xForwardedProto?: boolean\n}): 'http' | 'https' | (string & {}) {\n return h3_getRequestProtocol(getH3Event(), opts)\n}\n\nexport function setResponseHeaders(\n headers: TypedHeaders<ResponseHeaderMap>,\n): void {\n const event = getH3Event()\n for (const [name, value] of Object.entries(headers)) {\n event.res.headers.set(name, value)\n }\n}\n\nexport function getResponseHeaders(): TypedHeaders<ResponseHeaderMap> {\n const event = getH3Event()\n return Object.fromEntries(event.res.headers.entries()) as any\n}\n\nexport function getResponseHeader(\n name: ResponseHeaderName,\n): string | undefined {\n const event = getH3Event()\n return event.res.headers.get(name) || undefined\n}\n\nexport function setResponseHeader(\n name: ResponseHeaderName,\n value: string | Array<string>,\n): void {\n const event = getH3Event()\n if (Array.isArray(value)) {\n event.res.headers.delete(name)\n for (const valueItem of value) {\n event.res.headers.append(name, valueItem)\n }\n } else {\n event.res.headers.set(name, value)\n }\n}\nexport function removeResponseHeader(name: ResponseHeaderName): void {\n const event = getH3Event()\n event.res.headers.delete(name)\n}\n\nexport function clearResponseHeaders(\n headerNames?: Array<ResponseHeaderName>,\n): void {\n const event = getH3Event()\n // If headerNames is provided, clear only those headers\n if (headerNames && headerNames.length > 0) {\n for (const name of headerNames) {\n event.res.headers.delete(name)\n }\n // Otherwise, clear all headers\n } else {\n for (const name of event.res.headers.keys()) {\n event.res.headers.delete(name)\n }\n }\n}\n\nexport function getResponseStatus(): number {\n return getH3Event().res.status || 200\n}\n\nexport function setResponseStatus(code?: number, text?: string): void {\n const event = getH3Event()\n if (code) {\n event.res.status = h3_sanitizeStatusCode(code, event.res.status)\n }\n if (text) {\n event.res.statusText = h3_sanitizeStatusMessage(text)\n }\n}\n\n/**\n * Parse the request to get HTTP Cookie header string and return an object of all cookie name-value pairs.\n * @returns Object of cookie name-value pairs\n * ```ts\n * const cookies = getCookies()\n * ```\n */\nexport function getCookies(): Record<string, string> {\n const event = getH3Event()\n return h3_parseCookies(event)\n}\n\n/**\n * Get a cookie value by name.\n * @param name Name of the cookie to get\n * @returns {*} Value of the cookie (String or undefined)\n * ```ts\n * const authorization = getCookie('Authorization')\n * ```\n */\nexport function getCookie(name: string): string | undefined {\n return getCookies()[name] || undefined\n}\n\n/**\n * Set a cookie value by name.\n * @param name Name of the cookie to set\n * @param value Value of the cookie to set\n * @param options {CookieSerializeOptions} Options for serializing the cookie\n * ```ts\n * setCookie('Authorization', '1234567')\n * ```\n */\nexport function setCookie(\n name: string,\n value: string,\n options?: CookieSerializeOptions,\n): void {\n const event = getH3Event()\n h3_setCookie(event, name, value, options)\n}\n\n/**\n * Remove a cookie by name.\n * @param name Name of the cookie to delete\n * @param serializeOptions {CookieSerializeOptions} Cookie options\n * ```ts\n * deleteCookie('SessionId')\n * ```\n */\nexport function deleteCookie(\n name: string,\n options?: CookieSerializeOptions,\n): void {\n const event = getH3Event()\n h3_deleteCookie(event, name, options)\n}\n\nfunction getDefaultSessionConfig(config: SessionConfig): SessionConfig {\n return {\n name: 'start',\n ...config,\n }\n}\n\n/**\n * Create a session manager for the current request.\n */\nexport function useSession<TSessionData extends SessionData = SessionData>(\n config: SessionConfig,\n): Promise<SessionManager<TSessionData>> {\n const event = getH3Event()\n return h3_useSession(event, getDefaultSessionConfig(config))\n}\n/**\n * Get the session for the current request\n */\nexport function getSession<TSessionData extends SessionData = SessionData>(\n config: SessionConfig,\n): Promise<Session<TSessionData>> {\n const event = getH3Event()\n return h3_getSession(event, getDefaultSessionConfig(config))\n}\n\n/**\n * Update the session data for the current request.\n */\nexport function updateSession<TSessionData extends SessionData = SessionData>(\n config: SessionConfig,\n update?: SessionUpdate<TSessionData>,\n): Promise<Session<TSessionData>> {\n const event = getH3Event()\n return h3_updateSession(event, getDefaultSessionConfig(config), update)\n}\n\n/**\n * Encrypt and sign the session data for the current request.\n */\nexport function sealSession(config: SessionConfig): Promise<string> {\n const event = getH3Event()\n return h3_sealSession(event, getDefaultSessionConfig(config))\n}\n/**\n * Decrypt and verify the session data for the current request.\n */\nexport function unsealSession(\n config: SessionConfig,\n sealed: string,\n): Promise<Partial<Session>> {\n const event = getH3Event()\n return h3_unsealSession(event, getDefaultSessionConfig(config), sealed)\n}\n\n/**\n * Clear the session data for the current request.\n */\nexport function clearSession(config: Partial<SessionConfig>): Promise<void> {\n const event = getH3Event()\n return h3_clearSession(event, { name: 'start', ...config })\n}\n\n// not public API\nexport function getResponse() {\n const event = getH3Event()\n return event._res\n}\n\n// not public API (yet)\nexport function getValidatedQuery<TSchema extends StandardSchemaV1>(\n schema: StandardSchemaV1,\n): Promise<StandardSchemaV1.InferOutput<TSchema>> {\n return h3_getValidatedQuery(getH3Event(), schema)\n}\n"],"names":["h3_toResponse","h3_getRequestIP","h3_getRequestHost","h3_getRequestURL","h3_getRequestProtocol","h3_sanitizeStatusCode","h3_sanitizeStatusMessage","h3_parseCookies","h3_setCookie","h3_deleteCookie","h3_useSession","h3_getSession","h3_updateSession","h3_sealSession","h3_unsealSession","h3_clearSession","h3_getValidatedQuery"],"mappings":";;AA2CA,MAAM,eAAe,IAAI,kBAAA;AAMlB,SAAS,eAAe,SAAyB;AACtD,SAAO,CAAC,YAAmD;AACzD,UAAM,UAAU,IAAI,QAAQ,OAAO;AAEnC,UAAM,WAAW,aAAa,IAAI,EAAE,WAAW,MAAM,QAAQ,OAAO,CAAC;AACrE,WAAOA,WAAc,UAAU,OAAO;AAAA,EACxC;AACF;AAEA,SAAS,aAAa;AACpB,QAAM,QAAQ,aAAa,SAAA;AAC3B,MAAI,CAAC,OAAO;AACV,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AACA,SAAO,MAAM;AACf;AAEO,SAAS,aAAsB;AACpC,QAAM,QAAQ,WAAA;AACd,SAAO,MAAM;AACf;AAEO,SAAS,oBAAoD;AAElE,SAAO,WAAA,EAAa,IAAI;AAC1B;AAEO,SAAS,iBAAiB,MAA6C;AAC5E,SAAO,kBAAA,EAAoB,IAAI,IAAI,KAAK;AAC1C;AAEO,SAAS,aAAa,MAO1B;AACD,SAAOC,eAAgB,WAAA,GAAc,IAAI;AAC3C;AASO,SAAS,eAAe,MAAqC;AAClE,SAAOC,iBAAkB,WAAA,GAAc,IAAI;AAC7C;AASO,SAAS,cAAc,MAG3B;AACD,SAAOC,cAAiB,WAAA,GAAc,IAAI;AAC5C;AASO,SAAS,mBAAmB,MAEE;AACnC,SAAOC,qBAAsB,WAAA,GAAc,IAAI;AACjD;AAEO,SAAS,mBACd,SACM;AACN,QAAM,QAAQ,WAAA;AACd,aAAW,CAAC,MAAM,KAAK,KAAK,OAAO,QAAQ,OAAO,GAAG;AACnD,UAAM,IAAI,QAAQ,IAAI,MAAM,KAAK;AAAA,EACnC;AACF;AAEO,SAAS,qBAAsD;AACpE,QAAM,QAAQ,WAAA;AACd,SAAO,OAAO,YAAY,MAAM,IAAI,QAAQ,SAAS;AACvD;AAEO,SAAS,kBACd,MACoB;AACpB,QAAM,QAAQ,WAAA;AACd,SAAO,MAAM,IAAI,QAAQ,IAAI,IAAI,KAAK;AACxC;AAEO,SAAS,kBACd,MACA,OACM;AACN,QAAM,QAAQ,WAAA;AACd,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,UAAM,IAAI,QAAQ,OAAO,IAAI;AAC7B,eAAW,aAAa,OAAO;AAC7B,YAAM,IAAI,QAAQ,OAAO,MAAM,SAAS;AAAA,IAC1C;AAAA,EACF,OAAO;AACL,UAAM,IAAI,QAAQ,IAAI,MAAM,KAAK;AAAA,EACnC;AACF;AACO,SAAS,qBAAqB,MAAgC;AACnE,QAAM,QAAQ,WAAA;AACd,QAAM,IAAI,QAAQ,OAAO,IAAI;AAC/B;AAEO,SAAS,qBACd,aACM;AACN,QAAM,QAAQ,WAAA;AAEd,MAAI,eAAe,YAAY,SAAS,GAAG;AACzC,eAAW,QAAQ,aAAa;AAC9B,YAAM,IAAI,QAAQ,OAAO,IAAI;AAAA,IAC/B;AAAA,EAEF,OAAO;AACL,eAAW,QAAQ,MAAM,IAAI,QAAQ,QAAQ;AAC3C,YAAM,IAAI,QAAQ,OAAO,IAAI;AAAA,IAC/B;AAAA,EACF;AACF;AAEO,SAAS,oBAA4B;AAC1C,SAAO,WAAA,EAAa,IAAI,UAAU;AACpC;AAEO,SAAS,kBAAkB,MAAe,MAAqB;AACpE,QAAM,QAAQ,WAAA;AACd,MAAI,MAAM;AACR,UAAM,IAAI,SAASC,mBAAsB,MAAM,MAAM,IAAI,MAAM;AAAA,EACjE;AACA,MAAI,MAAM;AACR,UAAM,IAAI,aAAaC,sBAAyB,IAAI;AAAA,EACtD;AACF;AASO,SAAS,aAAqC;AACnD,QAAM,QAAQ,WAAA;AACd,SAAOC,aAAgB,KAAK;AAC9B;AAUO,SAAS,UAAU,MAAkC;AAC1D,SAAO,WAAA,EAAa,IAAI,KAAK;AAC/B;AAWO,SAAS,UACd,MACA,OACA,SACM;AACN,QAAM,QAAQ,WAAA;AACdC,cAAa,OAAO,MAAM,OAAO,OAAO;AAC1C;AAUO,SAAS,aACd,MACA,SACM;AACN,QAAM,QAAQ,WAAA;AACdC,iBAAgB,OAAO,MAAM,OAAO;AACtC;AAEA,SAAS,wBAAwB,QAAsC;AACrE,SAAO;AAAA,IACL,MAAM;AAAA,IACN,GAAG;AAAA,EAAA;AAEP;AAKO,SAAS,WACd,QACuC;AACvC,QAAM,QAAQ,WAAA;AACd,SAAOC,aAAc,OAAO,wBAAwB,MAAM,CAAC;AAC7D;AAIO,SAAS,WACd,QACgC;AAChC,QAAM,QAAQ,WAAA;AACd,SAAOC,aAAc,OAAO,wBAAwB,MAAM,CAAC;AAC7D;AAKO,SAAS,cACd,QACA,QACgC;AAChC,QAAM,QAAQ,WAAA;AACd,SAAOC,gBAAiB,OAAO,wBAAwB,MAAM,GAAG,MAAM;AACxE;AAKO,SAAS,YAAY,QAAwC;AAClE,QAAM,QAAQ,WAAA;AACd,SAAOC,cAAe,OAAO,wBAAwB,MAAM,CAAC;AAC9D;AAIO,SAAS,cACd,QACA,QAC2B;AAC3B,QAAM,QAAQ,WAAA;AACd,SAAOC,gBAAiB,OAAO,wBAAwB,MAAM,GAAG,MAAM;AACxE;AAKO,SAAS,aAAa,QAA+C;AAC1E,QAAM,QAAQ,WAAA;AACd,SAAOC,eAAgB,OAAO,EAAE,MAAM,SAAS,GAAG,QAAQ;AAC5D;AAGO,SAAS,cAAc;AAC5B,QAAM,QAAQ,WAAA;AACd,SAAO,MAAM;AACf;AAGO,SAAS,kBACd,QACgD;AAChD,SAAOC,oBAAqB,WAAA,GAAc,MAAM;AAClD;"}
@@ -13,4 +13,5 @@ export declare function getStartManifest(opts: {
13
13
  assets: import('@tanstack/router-core').RouterManagedTag[] | undefined;
14
14
  };
15
15
  };
16
+ clientEntry: string;
16
17
  }>;
@@ -1,4 +1,4 @@
1
- import { rootRouteId, joinPaths } from "@tanstack/router-core";
1
+ import { rootRouteId } from "@tanstack/router-core";
2
2
  import { VIRTUAL_MODULES } from "./virtual-modules.js";
3
3
  import { loadVirtualModule } from "./loadVirtualModule.js";
4
4
  async function getStartManifest(opts) {
@@ -8,24 +8,24 @@ async function getStartManifest(opts) {
8
8
  const startManifest = tsrStartManifest();
9
9
  const rootRoute = startManifest.routes[rootRouteId] = startManifest.routes[rootRouteId] || {};
10
10
  rootRoute.assets = rootRoute.assets || [];
11
- if (process.env.NODE_ENV === "development" && !process.env.TSS_CLIENT_ENTRY) {
12
- throw new Error(
13
- "tanstack/start-server-core: TSS_CLIENT_ENTRY must be defined in your environment for getStartManifest()"
11
+ let script = `import('${startManifest.clientEntry}')`;
12
+ if (process.env.TSS_DEV_SERVER === "true") {
13
+ const { injectedHeadScripts } = await loadVirtualModule(
14
+ VIRTUAL_MODULES.injectedHeadScripts
14
15
  );
16
+ if (injectedHeadScripts) {
17
+ script = `${injectedHeadScripts + ";"}${script}`;
18
+ }
15
19
  }
16
- if (process.env.NODE_ENV === "development") {
17
- const clientEntry = joinPaths([opts.basePath, process.env.TSS_CLIENT_ENTRY]);
18
- const script = `${globalThis.TSS_INJECTED_HEAD_SCRIPTS ? globalThis.TSS_INJECTED_HEAD_SCRIPTS + "; " : ""}import('${clientEntry}')`;
19
- rootRoute.assets.push({
20
- tag: "script",
21
- attrs: {
22
- type: "module",
23
- suppressHydrationWarning: true,
24
- async: true
25
- },
26
- children: script
27
- });
28
- }
20
+ rootRoute.assets.push({
21
+ tag: "script",
22
+ attrs: {
23
+ type: "module",
24
+ suppressHydrationWarning: true,
25
+ async: true
26
+ },
27
+ children: script
28
+ });
29
29
  const manifest = {
30
30
  ...startManifest,
31
31
  routes: Object.fromEntries(
@@ -1 +1 @@
1
- {"version":3,"file":"router-manifest.js","sources":["../../src/router-manifest.ts"],"sourcesContent":["import { joinPaths, rootRouteId } from '@tanstack/router-core'\nimport { VIRTUAL_MODULES } from './virtual-modules'\nimport { loadVirtualModule } from './loadVirtualModule'\n\n/**\n * @description Returns the router manifest that should be sent to the client.\n * This includes only the assets and preloads for the current route and any\n * special assets that are needed for the client. It does not include relationships\n * between routes or any other data that is not needed for the client.\n */\nexport async function getStartManifest(opts: { basePath: string }) {\n const { tsrStartManifest } = await loadVirtualModule(\n VIRTUAL_MODULES.startManifest,\n )\n const startManifest = tsrStartManifest()\n\n const rootRoute = (startManifest.routes[rootRouteId] =\n startManifest.routes[rootRouteId] || {})\n\n rootRoute.assets = rootRoute.assets || []\n\n // Get the entry for the client\n // const ClientManifest = getManifest('client')\n\n // const importPath =\n // ClientManifest.inputs[ClientManifest.handler]?.output.path\n // if (!importPath) {\n // invariant(importPath, 'Could not find client entry in manifest')\n // }\n\n if (process.env.NODE_ENV === 'development' && !process.env.TSS_CLIENT_ENTRY) {\n throw new Error(\n 'tanstack/start-server-core: TSS_CLIENT_ENTRY must be defined in your environment for getStartManifest()',\n )\n }\n\n if (process.env.NODE_ENV === 'development') {\n // Always fake that HMR is ready\n // const CLIENT_BASE = sanitizeBase(process.env.TSS_CLIENT_BASE || '')\n\n // if (!CLIENT_BASE) {\n // throw new Error(\n // 'tanstack/start-router-manifest: TSS_CLIENT_BASE must be defined in your environment for getFullRouterManifest()',\n // )\n // }\n\n const clientEntry = joinPaths([opts.basePath, process.env.TSS_CLIENT_ENTRY])\n\n const script = `${globalThis.TSS_INJECTED_HEAD_SCRIPTS ? globalThis.TSS_INJECTED_HEAD_SCRIPTS + '; ' : ''}import('${clientEntry}')`\n\n rootRoute.assets.push({\n tag: 'script',\n attrs: {\n type: 'module',\n suppressHydrationWarning: true,\n async: true,\n },\n children: script,\n })\n }\n\n const manifest = {\n ...startManifest,\n routes: Object.fromEntries(\n Object.entries(startManifest.routes).map(([k, v]) => {\n const { preloads, assets } = v\n return [\n k,\n {\n preloads,\n assets,\n },\n ]\n }),\n ),\n }\n\n // Strip out anything that isn't needed for the client\n return manifest\n}\n"],"names":[],"mappings":";;;AAUA,eAAsB,iBAAiB,MAA4B;AAC3D,QAAA,EAAE,iBAAiB,IAAI,MAAM;AAAA,IACjC,gBAAgB;AAAA,EAClB;AACA,QAAM,gBAAgB,iBAAiB;AAEjC,QAAA,YAAa,cAAc,OAAO,WAAW,IACjD,cAAc,OAAO,WAAW,KAAK,CAAC;AAE9B,YAAA,SAAS,UAAU,UAAU,CAAC;AAWxC,MAAI,QAAQ,IAAI,aAAa,iBAAiB,CAAC,QAAQ,IAAI,kBAAkB;AAC3E,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EAAA;AAGE,MAAA,QAAQ,IAAI,aAAa,eAAe;AAUpC,UAAA,cAAc,UAAU,CAAC,KAAK,UAAU,QAAQ,IAAI,gBAAgB,CAAC;AAErE,UAAA,SAAS,GAAG,WAAW,4BAA4B,WAAW,4BAA4B,OAAO,EAAE,WAAW,WAAW;AAE/H,cAAU,OAAO,KAAK;AAAA,MACpB,KAAK;AAAA,MACL,OAAO;AAAA,QACL,MAAM;AAAA,QACN,0BAA0B;AAAA,QAC1B,OAAO;AAAA,MACT;AAAA,MACA,UAAU;AAAA,IAAA,CACX;AAAA,EAAA;AAGH,QAAM,WAAW;AAAA,IACf,GAAG;AAAA,IACH,QAAQ,OAAO;AAAA,MACb,OAAO,QAAQ,cAAc,MAAM,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM;AAC7C,cAAA,EAAE,UAAU,OAAA,IAAW;AACtB,eAAA;AAAA,UACL;AAAA,UACA;AAAA,YACE;AAAA,YACA;AAAA,UAAA;AAAA,QAEJ;AAAA,MACD,CAAA;AAAA,IAAA;AAAA,EAEL;AAGO,SAAA;AACT;"}
1
+ {"version":3,"file":"router-manifest.js","sources":["../../src/router-manifest.ts"],"sourcesContent":["import { rootRouteId } from '@tanstack/router-core'\nimport { VIRTUAL_MODULES } from './virtual-modules'\nimport { loadVirtualModule } from './loadVirtualModule'\n\n/**\n * @description Returns the router manifest that should be sent to the client.\n * This includes only the assets and preloads for the current route and any\n * special assets that are needed for the client. It does not include relationships\n * between routes or any other data that is not needed for the client.\n */\nexport async function getStartManifest(opts: { basePath: string }) {\n const { tsrStartManifest } = await loadVirtualModule(\n VIRTUAL_MODULES.startManifest,\n )\n const startManifest = tsrStartManifest()\n\n const rootRoute = (startManifest.routes[rootRouteId] =\n startManifest.routes[rootRouteId] || {})\n\n rootRoute.assets = rootRoute.assets || []\n\n let script = `import('${startManifest.clientEntry}')`\n if (process.env.TSS_DEV_SERVER === 'true') {\n const { injectedHeadScripts } = await loadVirtualModule(\n VIRTUAL_MODULES.injectedHeadScripts,\n )\n if (injectedHeadScripts) {\n script = `${injectedHeadScripts + ';'}${script}`\n }\n }\n rootRoute.assets.push({\n tag: 'script',\n attrs: {\n type: 'module',\n suppressHydrationWarning: true,\n async: true,\n },\n children: script,\n })\n\n const manifest = {\n ...startManifest,\n routes: Object.fromEntries(\n Object.entries(startManifest.routes).map(([k, v]) => {\n const { preloads, assets } = v\n return [\n k,\n {\n preloads,\n assets,\n },\n ]\n }),\n ),\n }\n\n // Strip out anything that isn't needed for the client\n return manifest\n}\n"],"names":[],"mappings":";;;AAUA,eAAsB,iBAAiB,MAA4B;AACjE,QAAM,EAAE,iBAAA,IAAqB,MAAM;AAAA,IACjC,gBAAgB;AAAA,EAAA;AAElB,QAAM,gBAAgB,iBAAA;AAEtB,QAAM,YAAa,cAAc,OAAO,WAAW,IACjD,cAAc,OAAO,WAAW,KAAK,CAAA;AAEvC,YAAU,SAAS,UAAU,UAAU,CAAA;AAEvC,MAAI,SAAS,WAAW,cAAc,WAAW;AACjD,MAAI,QAAQ,IAAI,mBAAmB,QAAQ;AACzC,UAAM,EAAE,oBAAA,IAAwB,MAAM;AAAA,MACpC,gBAAgB;AAAA,IAAA;AAElB,QAAI,qBAAqB;AACvB,eAAS,GAAG,sBAAsB,GAAG,GAAG,MAAM;AAAA,IAChD;AAAA,EACF;AACA,YAAU,OAAO,KAAK;AAAA,IACpB,KAAK;AAAA,IACL,OAAO;AAAA,MACL,MAAM;AAAA,MACN,0BAA0B;AAAA,MAC1B,OAAO;AAAA,IAAA;AAAA,IAET,UAAU;AAAA,EAAA,CACX;AAED,QAAM,WAAW;AAAA,IACf,GAAG;AAAA,IACH,QAAQ,OAAO;AAAA,MACb,OAAO,QAAQ,cAAc,MAAM,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM;AACnD,cAAM,EAAE,UAAU,OAAA,IAAW;AAC7B,eAAO;AAAA,UACL;AAAA,UACA;AAAA,YACE;AAAA,YACA;AAAA,UAAA;AAAA,QACF;AAAA,MAEJ,CAAC;AAAA,IAAA;AAAA,EACH;AAIF,SAAO;AACT;"}
@@ -1,9 +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
- import { getResponseStatus, getEvent } from "./h3.js";
5
4
  import { VIRTUAL_MODULES } from "./virtual-modules.js";
6
5
  import { loadVirtualModule } from "./loadVirtualModule.js";
6
+ import { getResponse } from "./request-response.js";
7
7
  function sanitizeBase(base) {
8
8
  if (!base) {
9
9
  throw new Error(
@@ -59,10 +59,7 @@ const handleServerAction = async ({ request }) => {
59
59
  try {
60
60
  let result = await (async () => {
61
61
  if (request.headers.get("Content-Type") && formDataContentTypes.some(
62
- (type) => {
63
- var _a;
64
- return (_a = request.headers.get("Content-Type")) == null ? void 0 : _a.includes(type);
65
- }
62
+ (type) => request.headers.get("Content-Type")?.includes(type)
66
63
  )) {
67
64
  invariant(
68
65
  method.toLowerCase() !== "get",
@@ -97,10 +94,12 @@ const handleServerAction = async ({ request }) => {
97
94
  if (isNotFound(result)) {
98
95
  return isNotFoundResponse(result);
99
96
  }
97
+ const response2 = getResponse();
100
98
  return new Response(
101
99
  result !== void 0 ? startSerializer.stringify(result) : void 0,
102
100
  {
103
- status: getResponseStatus(getEvent()),
101
+ status: response2?.status,
102
+ statusText: response2?.statusText,
104
103
  headers: {
105
104
  "Content-Type": "application/json"
106
105
  }
@@ -135,7 +134,7 @@ const handleServerAction = async ({ request }) => {
135
134
  function isNotFoundResponse(error) {
136
135
  const { headers, ...rest } = error;
137
136
  return new Response(JSON.stringify(rest), {
138
- status: 200,
137
+ status: 404,
139
138
  headers: {
140
139
  "Content-Type": "application/json",
141
140
  ...headers || {}