@tonyclaw/agent-inspector 3.0.18 → 3.0.20
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.
- package/.output/cli.js +1257 -506
- package/.output/nitro.json +3 -3
- package/.output/public/assets/CompareDrawer-CV7rBBty.js +1 -0
- package/.output/public/assets/ProxyViewerContainer-CqRfBWJ3.js +127 -0
- package/.output/public/assets/ReplayDialog-yDeF-z9y.js +1 -0
- package/.output/public/assets/RequestAnatomy-BXxKNdgk.js +1 -0
- package/.output/public/assets/ResponseView-BIYNgUNB.js +3 -0
- package/.output/public/assets/StreamingChunkSequence-C1faiChu.js +1 -0
- package/.output/public/assets/_sessionId-B34PrfCQ.js +1 -0
- package/.output/public/assets/index-B3YOj8-_.css +1 -0
- package/.output/public/assets/index-BLwqIxup.js +12 -0
- package/.output/public/assets/{index-ClQ7Vi3J.js → index-DOspyaW6.js} +1 -1
- package/.output/public/assets/index-DT476lno.js +1 -0
- package/.output/public/assets/json-viewer-C1S08J_2.js +1 -0
- package/.output/server/_chunks/ssr-renderer.mjs +18 -2
- package/.output/server/_libs/@radix-ui/react-dismissable-layer+[...].mjs +165 -31
- package/.output/server/_libs/@radix-ui/react-use-callback-ref+[...].mjs +1 -1
- package/.output/server/_libs/@radix-ui/react-use-controllable-state+[...].mjs +2 -2
- package/.output/server/_libs/@radix-ui/react-use-is-hydrated+[...].mjs +28 -1
- package/.output/server/_libs/mistralai__mistralai.mjs +1 -1
- package/.output/server/_libs/modelcontextprotocol__server.mjs +11571 -8127
- package/.output/server/_libs/radix-ui__primitive.mjs +1 -1
- package/.output/server/_libs/radix-ui__react-collapsible.mjs +1 -1
- package/.output/server/_libs/radix-ui__react-collection.mjs +8 -8
- package/.output/server/_libs/radix-ui__react-compose-refs.mjs +0 -1
- package/.output/server/_libs/radix-ui__react-context.mjs +4 -18
- package/.output/server/_libs/radix-ui__react-dialog.mjs +41 -88
- package/.output/server/_libs/radix-ui__react-focus-guards.mjs +15 -5
- package/.output/server/_libs/radix-ui__react-focus-scope.mjs +6 -2
- package/.output/server/_libs/radix-ui__react-id.mjs +3 -3
- package/.output/server/_libs/radix-ui__react-popper.mjs +62 -8
- package/.output/server/_libs/radix-ui__react-portal.mjs +2 -2
- package/.output/server/_libs/radix-ui__react-presence.mjs +50 -5
- package/.output/server/_libs/radix-ui__react-roving-focus.mjs +15 -4
- package/.output/server/_libs/radix-ui__react-scroll-area.mjs +30 -20
- package/.output/server/_libs/radix-ui__react-select.mjs +167 -123
- package/.output/server/_libs/radix-ui__react-slot.mjs +74 -41
- package/.output/server/_libs/radix-ui__react-tabs.mjs +6 -1
- package/.output/server/_libs/radix-ui__react-tooltip.mjs +6 -3
- package/.output/server/_libs/react-dom.mjs +13 -15
- package/.output/server/_libs/react.mjs +45 -45
- package/.output/server/_libs/srvx.mjs +409 -53
- package/.output/server/_libs/swr.mjs +10 -2
- package/.output/server/_libs/tailwind-merge.mjs +286 -41
- package/.output/server/_libs/tanstack__history.mjs +9 -13
- package/.output/server/_libs/tanstack__react-router.mjs +788 -1092
- package/.output/server/_libs/tanstack__react-store.mjs +1 -1
- package/.output/server/_libs/tanstack__react-virtual.mjs +82 -7
- package/.output/server/_libs/tanstack__router-core.mjs +1841 -2060
- package/.output/server/_libs/tanstack__virtual-core.mjs +116 -45
- package/.output/server/_libs/use-sync-external-store.mjs +1 -1
- package/.output/server/_libs/zod-to-json-schema.mjs +1 -1
- package/.output/server/_libs/zod.mjs +5085 -200
- package/.output/server/{_sessionId-Bi3ZIrqT.mjs → _sessionId-CmoBbtKT.mjs} +30 -32
- package/.output/server/_ssr/{CompareDrawer-BYZS_hCR.mjs → CompareDrawer-BsXnVK4e.mjs} +29 -31
- package/.output/server/_ssr/{ProxyViewerContainer-BE4umfVs.mjs → ProxyViewerContainer-D-_7pyfx.mjs} +54 -52
- package/.output/server/_ssr/{ReplayDialog-BlID2ZH4.mjs → ReplayDialog-deDQA2M5.mjs} +30 -32
- package/.output/server/_ssr/{RequestAnatomy-CGJ2lkzT.mjs → RequestAnatomy-CX-cCRdX.mjs} +29 -31
- package/.output/server/_ssr/{ResponseView-DDjcGf7M.mjs → ResponseView-D0LJR1qj.mjs} +29 -31
- package/.output/server/_ssr/{StreamingChunkSequence-G7B8M5G2.mjs → StreamingChunkSequence-CJRECetE.mjs} +29 -31
- package/.output/server/_ssr/empty-plugin-adapters-BFgPZ6_d.mjs +6 -0
- package/.output/server/_ssr/{index-ClQ9FvRJ.mjs → index-CYWOXS4d.mjs} +31 -33
- package/.output/server/_ssr/index.mjs +1102 -784
- package/.output/server/_ssr/{json-viewer-CFbpkiBJ.mjs → json-viewer-CCneYiCn.mjs} +29 -31
- package/.output/server/_ssr/{router-Cq8LEvhE.mjs → router-D-PAN8IK.mjs} +182 -67
- package/.output/server/_tanstack-start-manifest_v-CVZ9yh4R.mjs +4 -0
- package/.output/server/index.mjs +74 -92
- package/README.md +4 -4
- package/package.json +17 -8
- package/src/cli/onboard.ts +1 -1
- package/src/cli.ts +2 -2
- package/src/components/clients/ClientLogo.tsx +5 -1
- package/src/components/proxy-viewer/RequestToolsPanel.tsx +1 -0
- package/src/components/proxy-viewer/ResponseView.tsx +1 -0
- package/src/components/proxy-viewer/StreamingChunkSequence.tsx +1 -0
- package/src/components/proxy-viewer/TurnGroup.tsx +1 -0
- package/src/components/proxy-viewer/anatomy/SegmentBar.tsx +1 -0
- package/src/components/proxy-viewer/formats/anthropic/ContentBlocks.tsx +4 -0
- package/src/components/proxy-viewer/formats/anthropic/ResponseView.tsx +1 -0
- package/src/components/proxy-viewer/formats/openai/ResponseView.tsx +2 -0
- package/src/components/ui/dialog.tsx +1 -1
- package/src/components/ui/json-viewer.tsx +2 -0
- package/src/components/ui/select.tsx +1 -1
- package/src/contracts/json.ts +7 -2
- package/src/lib/providerContract.ts +25 -5
- package/src/mcp/server.ts +12 -3
- package/src/mcp/toolHandlers.ts +6 -1
- package/src/proxy/handler.ts +17 -7
- package/src/proxy/logFinalizer.ts +76 -8
- package/src/proxy/logIndex.ts +16 -32
- package/src/proxy/providers.ts +22 -1
- package/src/proxy/sessionProcess.ts +15 -1
- package/src/proxy/upstream.ts +4 -2
- package/src/router.tsx +9 -0
- package/.output/public/assets/CompareDrawer-Daj03-RL.js +0 -1
- package/.output/public/assets/ProxyViewerContainer-BLCRQtU_.js +0 -106
- package/.output/public/assets/ReplayDialog-5FR5crdo.js +0 -1
- package/.output/public/assets/RequestAnatomy-DF0hHdQY.js +0 -1
- package/.output/public/assets/ResponseView-BwkMSsUa.js +0 -3
- package/.output/public/assets/StreamingChunkSequence-CKeUd58x.js +0 -1
- package/.output/public/assets/_sessionId-CThgXa41.js +0 -1
- package/.output/public/assets/index-BHXN1Fsx.css +0 -1
- package/.output/public/assets/index-gm3A0idN.js +0 -1
- package/.output/public/assets/json-viewer-BA-W-PZq.js +0 -1
- package/.output/public/assets/main-BnRC1932.js +0 -18
- package/.output/server/_libs/@radix-ui/react-use-escape-keydown+[...].mjs +0 -17
- package/.output/server/_libs/cfworker__json-schema.mjs +0 -1
- package/.output/server/_libs/tiny-invariant.mjs +0 -12
- package/.output/server/_libs/tiny-warning.mjs +0 -5
- package/.output/server/_tanstack-start-manifest_v-p7J0QCMh.mjs +0 -4
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
import { c as createMemoryHistory } from "../_libs/tanstack__history.mjs";
|
|
2
|
-
import { o as rootRouteId, p as getNormalizedURL, q as getOrigin, u as attachRouterServerSsrUtils, v as defineHandlerCallback, w as createSerializationAdapter, x as createRawStreamRPCPlugin, y as isNotFound, z as isRedirect, A as isResolvedRedirect, C as mergeHeaders, D as executeRewriteInput, E as defaultSerovalPlugins, F as makeSerovalPlugin } from "../_libs/tanstack__router-core.mjs";
|
|
3
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
4
2
|
import { H as H3Event, t as toResponse } from "../_libs/h3-v2.mjs";
|
|
3
|
+
import { y as resolveManifestAssetLink, z as resolveManifestCssLink, A as rootRouteId, C as getNormalizedURL, D as getOrigin, E as normalizeSsrResponse, F as attachRouterServerSsrUtils, G as defineHandlerCallback, H as createSerializationAdapter, I as createRawStreamRPCPlugin, J as invariant, K as isNotFound, L as isRedirect, M as isResolvedRedirect, N as replaceSsrResponse, O as mergeHeaders, P as executeRewriteInput, Q as stripSsrResponseBody, S as defaultSerovalPlugins, T as makeSerovalPlugin, U as getScriptPreloadAttrs, V as getStylesheetHref, W as isSsrResponse } from "../_libs/tanstack__router-core.mjs";
|
|
5
4
|
import { i as iu, P as Pu, s as su } from "../_libs/seroval.mjs";
|
|
5
|
+
import { c as createMemoryHistory } from "../_libs/tanstack__history.mjs";
|
|
6
6
|
import { j as jsxRuntimeExports } from "../_libs/react.mjs";
|
|
7
7
|
import { r as renderRouterToStream, R as RouterProvider } from "../_libs/tanstack__react-router.mjs";
|
|
8
|
-
import "../_libs/cookie-es.mjs";
|
|
9
|
-
import "../_libs/seroval-plugins.mjs";
|
|
10
|
-
import "node:stream";
|
|
11
|
-
import "../_libs/tiny-invariant.mjs";
|
|
12
|
-
import "node:stream/web";
|
|
13
8
|
import "../_libs/rou3.mjs";
|
|
14
9
|
import "../_libs/srvx.mjs";
|
|
15
10
|
import "node:http";
|
|
11
|
+
import "node:stream";
|
|
16
12
|
import "node:stream/promises";
|
|
17
13
|
import "node:https";
|
|
18
14
|
import "node:http2";
|
|
19
|
-
import "../_libs/
|
|
15
|
+
import "../_libs/cookie-es.mjs";
|
|
16
|
+
import "../_libs/seroval-plugins.mjs";
|
|
17
|
+
import "node:stream/web";
|
|
20
18
|
import "../_libs/react-dom.mjs";
|
|
21
19
|
import "util";
|
|
22
20
|
import "crypto";
|
|
@@ -26,20 +24,108 @@ import "../_libs/isbot.mjs";
|
|
|
26
24
|
function StartServer(props) {
|
|
27
25
|
return /* @__PURE__ */ jsxRuntimeExports.jsx(RouterProvider, { router: props.router });
|
|
28
26
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
27
|
+
var defaultStreamHandler = defineHandlerCallback(({ request, router, responseHeaders }) => renderRouterToStream({
|
|
28
|
+
request,
|
|
29
|
+
router,
|
|
30
|
+
responseHeaders,
|
|
31
|
+
children: /* @__PURE__ */ jsxRuntimeExports.jsx(StartServer, { router })
|
|
32
|
+
}));
|
|
33
|
+
var GLOBAL_EVENT_STORAGE_KEY = /* @__PURE__ */ Symbol.for("tanstack-start:event-storage");
|
|
34
|
+
var globalObj$1 = globalThis;
|
|
35
|
+
if (!globalObj$1[GLOBAL_EVENT_STORAGE_KEY]) globalObj$1[GLOBAL_EVENT_STORAGE_KEY] = new AsyncLocalStorage();
|
|
36
|
+
var eventStorage = globalObj$1[GLOBAL_EVENT_STORAGE_KEY];
|
|
37
|
+
function isPromiseLike(value) {
|
|
38
|
+
return typeof value.then === "function";
|
|
39
|
+
}
|
|
40
|
+
function getSetCookieValues(headers) {
|
|
41
|
+
const headersWithSetCookie = headers;
|
|
42
|
+
if (typeof headersWithSetCookie.getSetCookie === "function") return headersWithSetCookie.getSetCookie();
|
|
43
|
+
const value = headers.get("set-cookie");
|
|
44
|
+
return value ? [value] : [];
|
|
45
|
+
}
|
|
46
|
+
function mergeEventResponseHeaders(response, event) {
|
|
47
|
+
if (response.ok) return;
|
|
48
|
+
const eventSetCookies = getSetCookieValues(event.res.headers);
|
|
49
|
+
if (eventSetCookies.length === 0) return;
|
|
50
|
+
const responseSetCookies = getSetCookieValues(response.headers);
|
|
51
|
+
response.headers.delete("set-cookie");
|
|
52
|
+
for (const cookie of responseSetCookies) response.headers.append("set-cookie", cookie);
|
|
53
|
+
for (const cookie of eventSetCookies) response.headers.append("set-cookie", cookie);
|
|
54
|
+
}
|
|
55
|
+
function attachResponseHeaders(value, event) {
|
|
56
|
+
if (isPromiseLike(value)) return value.then((resolved) => {
|
|
57
|
+
if (resolved instanceof Response) mergeEventResponseHeaders(resolved, event);
|
|
58
|
+
return resolved;
|
|
59
|
+
});
|
|
60
|
+
if (value instanceof Response) mergeEventResponseHeaders(value, event);
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
function requestHandler(handler) {
|
|
64
|
+
return (request, requestOpts) => {
|
|
65
|
+
let h3Event;
|
|
66
|
+
try {
|
|
67
|
+
h3Event = new H3Event(request);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (error instanceof URIError) return new Response(null, {
|
|
70
|
+
status: 400,
|
|
71
|
+
statusText: "Bad Request"
|
|
72
|
+
});
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
return toResponse(attachResponseHeaders(eventStorage.run({ h3Event }, () => handler(request, requestOpts)), h3Event), h3Event);
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function getH3Event() {
|
|
79
|
+
const event = eventStorage.getStore();
|
|
80
|
+
if (!event) throw new Error(`No StartEvent found in AsyncLocalStorage. Make sure you are using the function within the server runtime.`);
|
|
81
|
+
return event.h3Event;
|
|
82
|
+
}
|
|
83
|
+
function getResponse() {
|
|
84
|
+
return getH3Event().res;
|
|
85
|
+
}
|
|
86
|
+
var HEADERS = { TSS_SHELL: "X-TSS_SHELL" };
|
|
87
|
+
async function getStartManifest(matchedRoutes) {
|
|
88
|
+
const { tsrStartManifest } = await import("../_tanstack-start-manifest_v-CVZ9yh4R.mjs");
|
|
89
|
+
const startManifest = tsrStartManifest();
|
|
90
|
+
let routes = startManifest.routes;
|
|
91
|
+
routes[rootRouteId];
|
|
92
|
+
const manifestRoutes = {};
|
|
93
|
+
for (const k in routes) {
|
|
94
|
+
const v = routes[k];
|
|
95
|
+
const result = {};
|
|
96
|
+
if (v.preloads && v.preloads.length > 0) result.preloads = v.preloads;
|
|
97
|
+
if (v.scripts && v.scripts.length > 0) result.scripts = v.scripts;
|
|
98
|
+
if (v.css?.length) result.css = v.css;
|
|
99
|
+
if (result.preloads || result.scripts || result.css) manifestRoutes[k] = result;
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
...startManifest.scriptFormat ? { scriptFormat: startManifest.scriptFormat } : {},
|
|
103
|
+
...startManifest.inlineCss ? { inlineCss: startManifest.inlineCss } : {},
|
|
104
|
+
routes: manifestRoutes
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const manifest = {};
|
|
108
|
+
async function getServerFnById(id, access) {
|
|
109
|
+
const serverFnInfo = manifest[id];
|
|
110
|
+
if (!serverFnInfo) {
|
|
111
|
+
throw new Error("Server function info not found for " + id);
|
|
112
|
+
}
|
|
113
|
+
const fnModule = serverFnInfo.module ?? await serverFnInfo.importer();
|
|
114
|
+
if (!fnModule) {
|
|
115
|
+
throw new Error("Server function module not resolved for " + id);
|
|
116
|
+
}
|
|
117
|
+
const action = fnModule[serverFnInfo.functionName];
|
|
118
|
+
if (!action) {
|
|
119
|
+
throw new Error("Server function module export not resolved for serverFn ID: " + id);
|
|
120
|
+
}
|
|
121
|
+
return action;
|
|
122
|
+
}
|
|
123
|
+
var TSS_FORMDATA_CONTEXT = "__TSS_CONTEXT";
|
|
124
|
+
var TSS_SERVER_FUNCTION = /* @__PURE__ */ Symbol.for("TSS_SERVER_FUNCTION");
|
|
125
|
+
var X_TSS_SERIALIZED = "x-tss-serialized";
|
|
126
|
+
var X_TSS_RAW_RESPONSE = "x-tss-raw";
|
|
127
|
+
var TSS_CONTENT_TYPE_FRAMED = "application/x-tss-framed";
|
|
128
|
+
var FrameType = {
|
|
43
129
|
/** Seroval JSON chunk (NDJSON line) */
|
|
44
130
|
JSON: 0,
|
|
45
131
|
/** Raw stream data chunk */
|
|
@@ -49,66 +135,47 @@ const FrameType = {
|
|
|
49
135
|
/** Raw stream error */
|
|
50
136
|
ERROR: 3
|
|
51
137
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const TSS_CONTENT_TYPE_FRAMED_VERSIONED = `${TSS_CONTENT_TYPE_FRAMED}; v=${TSS_FRAMED_PROTOCOL_VERSION}`;
|
|
55
|
-
const GLOBAL_STORAGE_KEY = /* @__PURE__ */ Symbol.for("tanstack-start:start-storage-context");
|
|
56
|
-
const globalObj$1 = globalThis;
|
|
57
|
-
if (!globalObj$1[GLOBAL_STORAGE_KEY]) {
|
|
58
|
-
globalObj$1[GLOBAL_STORAGE_KEY] = new AsyncLocalStorage();
|
|
59
|
-
}
|
|
60
|
-
const startStorage = globalObj$1[GLOBAL_STORAGE_KEY];
|
|
61
|
-
async function runWithStartContext(context, fn) {
|
|
62
|
-
return startStorage.run(context, fn);
|
|
63
|
-
}
|
|
64
|
-
function getStartContext(opts) {
|
|
65
|
-
const context = startStorage.getStore();
|
|
66
|
-
if (!context && opts?.throwIfNotFound !== false) {
|
|
67
|
-
throw new Error(
|
|
68
|
-
`No Start context found in AsyncLocalStorage. Make sure you are using the function within the server runtime.`
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
return context;
|
|
72
|
-
}
|
|
73
|
-
const getStartOptions = () => getStartContext().startOptions;
|
|
138
|
+
var FRAME_HEADER_SIZE = 9;
|
|
139
|
+
var TSS_CONTENT_TYPE_FRAMED_VERSIONED = `${TSS_CONTENT_TYPE_FRAMED}; v=1`;
|
|
74
140
|
function isSafeKey(key) {
|
|
75
141
|
return key !== "__proto__" && key !== "constructor" && key !== "prototype";
|
|
76
142
|
}
|
|
77
143
|
function safeObjectMerge(target, source) {
|
|
78
144
|
const result = /* @__PURE__ */ Object.create(null);
|
|
79
145
|
if (target) {
|
|
80
|
-
for (const key of Object.keys(target))
|
|
81
|
-
if (isSafeKey(key)) result[key] = target[key];
|
|
82
|
-
}
|
|
146
|
+
for (const key of Object.keys(target)) if (isSafeKey(key)) result[key] = target[key];
|
|
83
147
|
}
|
|
84
148
|
if (source && typeof source === "object") {
|
|
85
|
-
for (const key of Object.keys(source))
|
|
86
|
-
if (isSafeKey(key)) result[key] = source[key];
|
|
87
|
-
}
|
|
149
|
+
for (const key of Object.keys(source)) if (isSafeKey(key)) result[key] = source[key];
|
|
88
150
|
}
|
|
89
151
|
return result;
|
|
90
152
|
}
|
|
91
153
|
function createNullProtoObject(source) {
|
|
92
154
|
if (!source) return /* @__PURE__ */ Object.create(null);
|
|
93
155
|
const obj = /* @__PURE__ */ Object.create(null);
|
|
94
|
-
for (const key of Object.keys(source))
|
|
95
|
-
if (isSafeKey(key)) obj[key] = source[key];
|
|
96
|
-
}
|
|
156
|
+
for (const key of Object.keys(source)) if (isSafeKey(key)) obj[key] = source[key];
|
|
97
157
|
return obj;
|
|
98
158
|
}
|
|
159
|
+
var GLOBAL_STORAGE_KEY = /* @__PURE__ */ Symbol.for("tanstack-start:start-storage-context");
|
|
160
|
+
var globalObj = globalThis;
|
|
161
|
+
if (!globalObj[GLOBAL_STORAGE_KEY]) globalObj[GLOBAL_STORAGE_KEY] = new AsyncLocalStorage();
|
|
162
|
+
var startStorage = globalObj[GLOBAL_STORAGE_KEY];
|
|
163
|
+
async function runWithStartContext(context, fn) {
|
|
164
|
+
return startStorage.run(context, fn);
|
|
165
|
+
}
|
|
166
|
+
function getStartContext(opts) {
|
|
167
|
+
const context = startStorage.getStore();
|
|
168
|
+
if (!context && opts?.throwIfNotFound !== false) throw new Error(`No Start context found in AsyncLocalStorage. Make sure you are using the function within the server runtime.`);
|
|
169
|
+
return context;
|
|
170
|
+
}
|
|
171
|
+
var getStartOptions = () => getStartContext().startOptions;
|
|
99
172
|
function flattenMiddlewares(middlewares, maxDepth = 100) {
|
|
100
173
|
const seen = /* @__PURE__ */ new Set();
|
|
101
174
|
const flattened = [];
|
|
102
175
|
const recurse = (middleware, depth) => {
|
|
103
|
-
if (depth > maxDepth) {
|
|
104
|
-
throw new Error(
|
|
105
|
-
`Middleware nesting depth exceeded maximum of ${maxDepth}. Check for circular references.`
|
|
106
|
-
);
|
|
107
|
-
}
|
|
176
|
+
if (depth > maxDepth) throw new Error(`Middleware nesting depth exceeded maximum of ${maxDepth}. Check for circular references.`);
|
|
108
177
|
middleware.forEach((m) => {
|
|
109
|
-
if (m.options.middleware)
|
|
110
|
-
recurse(m.options.middleware, depth + 1);
|
|
111
|
-
}
|
|
178
|
+
if (m.options.middleware) recurse(m.options.middleware, depth + 1);
|
|
112
179
|
if (!seen.has(m)) {
|
|
113
180
|
seen.add(m);
|
|
114
181
|
flattened.push(m);
|
|
@@ -118,128 +185,93 @@ function flattenMiddlewares(middlewares, maxDepth = 100) {
|
|
|
118
185
|
recurse(middlewares, 0);
|
|
119
186
|
return flattened;
|
|
120
187
|
}
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
response.headers.append("set-cookie", cookie);
|
|
161
|
-
}
|
|
188
|
+
var createMiddleware = (options, __opts) => {
|
|
189
|
+
const resolvedOptions = {
|
|
190
|
+
type: "request",
|
|
191
|
+
...__opts || options
|
|
192
|
+
};
|
|
193
|
+
const setValidator = (validator) => {
|
|
194
|
+
return createMiddleware({}, Object.assign(resolvedOptions, {
|
|
195
|
+
validator,
|
|
196
|
+
inputValidator: validator
|
|
197
|
+
}));
|
|
198
|
+
};
|
|
199
|
+
return {
|
|
200
|
+
options: resolvedOptions,
|
|
201
|
+
middleware: (middleware) => {
|
|
202
|
+
return createMiddleware({}, Object.assign(resolvedOptions, { middleware }));
|
|
203
|
+
},
|
|
204
|
+
validator: setValidator,
|
|
205
|
+
inputValidator: setValidator,
|
|
206
|
+
client: (client) => {
|
|
207
|
+
return createMiddleware({}, Object.assign(resolvedOptions, { client }));
|
|
208
|
+
},
|
|
209
|
+
server: (server2) => {
|
|
210
|
+
return createMiddleware({}, Object.assign(resolvedOptions, { server: server2 }));
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
var innerCreateCsrfMiddleware = (opts = {}) => {
|
|
215
|
+
const middleware = createMiddleware().server(async (ctx) => {
|
|
216
|
+
const csrfCtx = ctx;
|
|
217
|
+
if (opts.filter && !await opts.filter(csrfCtx)) return ctx.next();
|
|
218
|
+
if (await isCsrfRequestAllowed(opts, csrfCtx)) return ctx.next();
|
|
219
|
+
return getFailureResponse(opts, csrfCtx);
|
|
220
|
+
});
|
|
221
|
+
return middleware;
|
|
222
|
+
};
|
|
223
|
+
var createCsrfMiddleware = innerCreateCsrfMiddleware;
|
|
224
|
+
async function isCsrfRequestAllowed(opts, ctx) {
|
|
225
|
+
const result = await getCsrfRequestValidationResult(opts, ctx);
|
|
226
|
+
return result === true || result === void 0 && opts.allowRequestsWithoutOriginCheck === true;
|
|
162
227
|
}
|
|
163
|
-
function
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
});
|
|
228
|
+
async function getCsrfRequestValidationResult(opts, ctx) {
|
|
229
|
+
const fetchSite = ctx.request.headers.get("Sec-Fetch-Site");
|
|
230
|
+
if (fetchSite !== null) return matchValue(opts.secFetchSite ?? "same-origin", fetchSite, ctx);
|
|
231
|
+
const origin = ctx.request.headers.get("Origin");
|
|
232
|
+
if (origin !== null) {
|
|
233
|
+
if (opts.origin) return matchValue(opts.origin, origin, ctx);
|
|
234
|
+
return origin === new URL(ctx.request.url).origin;
|
|
171
235
|
}
|
|
172
|
-
|
|
173
|
-
|
|
236
|
+
const referer = ctx.request.headers.get("Referer");
|
|
237
|
+
if (referer === null || opts.referer === false) return;
|
|
238
|
+
if (typeof opts.referer === "function") return opts.referer(referer, ctx);
|
|
239
|
+
if (opts.origin) {
|
|
240
|
+
const refererOrigin = getOriginFromUrl(referer);
|
|
241
|
+
return refererOrigin !== void 0 && matchValue(opts.origin, refererOrigin, ctx);
|
|
174
242
|
}
|
|
175
|
-
return
|
|
243
|
+
return isRefererSameOrigin(referer, new URL(ctx.request.url).origin);
|
|
176
244
|
}
|
|
177
|
-
function
|
|
178
|
-
return (
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
{ h3Event },
|
|
182
|
-
() => handler(request, requestOpts)
|
|
183
|
-
);
|
|
184
|
-
return toResponse(attachResponseHeaders(response, h3Event), h3Event);
|
|
185
|
-
};
|
|
245
|
+
async function matchValue(matcher, value, ctx) {
|
|
246
|
+
if (typeof matcher === "function") return matcher(value, ctx);
|
|
247
|
+
if (Array.isArray(matcher)) return matcher.includes(value);
|
|
248
|
+
return value === matcher;
|
|
186
249
|
}
|
|
187
|
-
function
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
);
|
|
250
|
+
function getOriginFromUrl(url) {
|
|
251
|
+
try {
|
|
252
|
+
return new URL(url).origin;
|
|
253
|
+
} catch {
|
|
254
|
+
return;
|
|
193
255
|
}
|
|
194
|
-
return event.h3Event;
|
|
195
256
|
}
|
|
196
|
-
function
|
|
197
|
-
|
|
198
|
-
return
|
|
257
|
+
function isRefererSameOrigin(referer, requestOrigin) {
|
|
258
|
+
if (referer === requestOrigin) return true;
|
|
259
|
+
if (!referer.startsWith(requestOrigin)) return false;
|
|
260
|
+
if (referer.length === requestOrigin.length) return true;
|
|
261
|
+
const code = referer.charCodeAt(requestOrigin.length);
|
|
262
|
+
return code === 47 || code === 63 || code === 35;
|
|
199
263
|
}
|
|
200
|
-
async function
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
let injectedHeadScripts;
|
|
206
|
-
const manifest2 = {
|
|
207
|
-
routes: Object.fromEntries(
|
|
208
|
-
Object.entries(startManifest.routes).flatMap(([k, v]) => {
|
|
209
|
-
const result = {};
|
|
210
|
-
let hasData = false;
|
|
211
|
-
if (v.preloads && v.preloads.length > 0) {
|
|
212
|
-
result["preloads"] = v.preloads;
|
|
213
|
-
hasData = true;
|
|
214
|
-
}
|
|
215
|
-
if (v.assets && v.assets.length > 0) {
|
|
216
|
-
result["assets"] = v.assets;
|
|
217
|
-
hasData = true;
|
|
218
|
-
}
|
|
219
|
-
if (!hasData) {
|
|
220
|
-
return [];
|
|
221
|
-
}
|
|
222
|
-
return [[k, result]];
|
|
223
|
-
})
|
|
224
|
-
)
|
|
225
|
-
};
|
|
226
|
-
return {
|
|
227
|
-
manifest: manifest2,
|
|
228
|
-
clientEntry: startManifest.clientEntry,
|
|
229
|
-
injectedHeadScripts
|
|
230
|
-
};
|
|
264
|
+
async function getFailureResponse(opts, ctx) {
|
|
265
|
+
if (typeof opts.failureResponse === "function") return opts.failureResponse(ctx);
|
|
266
|
+
return opts.failureResponse?.clone() ?? new Response("Forbidden", {
|
|
267
|
+
status: 403
|
|
268
|
+
});
|
|
231
269
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
if (condition) {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
{
|
|
238
|
-
throw new Error(prefix);
|
|
239
|
-
}
|
|
270
|
+
function getDefaultSerovalPlugins() {
|
|
271
|
+
return [...getStartOptions()?.serializationAdapters?.map(makeSerovalPlugin) ?? [], ...defaultSerovalPlugins];
|
|
240
272
|
}
|
|
241
|
-
|
|
242
|
-
|
|
273
|
+
var textEncoder = new TextEncoder();
|
|
274
|
+
var EMPTY_PAYLOAD = new Uint8Array(0);
|
|
243
275
|
function encodeFrame(type, streamId, payload) {
|
|
244
276
|
const frame = new Uint8Array(FRAME_HEADER_SIZE + payload.length);
|
|
245
277
|
frame[0] = type;
|
|
@@ -255,7 +287,7 @@ function encodeFrame(type, streamId, payload) {
|
|
|
255
287
|
return frame;
|
|
256
288
|
}
|
|
257
289
|
function encodeJSONFrame(json) {
|
|
258
|
-
return encodeFrame(FrameType.JSON, 0, textEncoder
|
|
290
|
+
return encodeFrame(FrameType.JSON, 0, textEncoder.encode(json));
|
|
259
291
|
}
|
|
260
292
|
function encodeChunkFrame(streamId, chunk) {
|
|
261
293
|
return encodeFrame(FrameType.CHUNK, streamId, chunk);
|
|
@@ -265,162 +297,151 @@ function encodeEndFrame(streamId) {
|
|
|
265
297
|
}
|
|
266
298
|
function encodeErrorFrame(streamId, error) {
|
|
267
299
|
const message = error instanceof Error ? error.message : String(error ?? "Unknown error");
|
|
268
|
-
return encodeFrame(FrameType.ERROR, streamId, textEncoder
|
|
300
|
+
return encodeFrame(FrameType.ERROR, streamId, textEncoder.encode(message));
|
|
269
301
|
}
|
|
270
|
-
function createMultiplexedStream(jsonStream, rawStreams) {
|
|
271
|
-
let
|
|
272
|
-
let controllerRef = null;
|
|
302
|
+
function createMultiplexedStream(jsonStream, rawStreams, lateStreamSource) {
|
|
303
|
+
let controller;
|
|
273
304
|
let cancelled = false;
|
|
274
|
-
const
|
|
275
|
-
const
|
|
276
|
-
if (cancelled
|
|
305
|
+
const readers = [];
|
|
306
|
+
const enqueue = (frame) => {
|
|
307
|
+
if (cancelled) return false;
|
|
277
308
|
try {
|
|
278
|
-
|
|
309
|
+
controller.enqueue(frame);
|
|
310
|
+
return true;
|
|
279
311
|
} catch {
|
|
312
|
+
return false;
|
|
280
313
|
}
|
|
281
314
|
};
|
|
282
|
-
const
|
|
283
|
-
if (cancelled
|
|
315
|
+
const errorOutput = (error) => {
|
|
316
|
+
if (cancelled) return;
|
|
317
|
+
cancelled = true;
|
|
284
318
|
try {
|
|
285
|
-
|
|
319
|
+
controller.error(error);
|
|
286
320
|
} catch {
|
|
287
321
|
}
|
|
322
|
+
for (const reader of readers) reader.cancel().catch(() => {
|
|
323
|
+
});
|
|
288
324
|
};
|
|
289
|
-
|
|
290
|
-
|
|
325
|
+
async function pumpRawStream(streamId, stream) {
|
|
326
|
+
const reader = stream.getReader();
|
|
327
|
+
readers.push(reader);
|
|
291
328
|
try {
|
|
292
|
-
|
|
293
|
-
|
|
329
|
+
while (!cancelled) {
|
|
330
|
+
const { done, value } = await reader.read();
|
|
331
|
+
if (done) {
|
|
332
|
+
enqueue(encodeEndFrame(streamId));
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
if (!enqueue(encodeChunkFrame(streamId, value))) return;
|
|
336
|
+
}
|
|
337
|
+
} catch (error) {
|
|
338
|
+
enqueue(encodeErrorFrame(streamId, error));
|
|
339
|
+
} finally {
|
|
340
|
+
reader.releaseLock();
|
|
294
341
|
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
342
|
+
}
|
|
343
|
+
async function pumpJSON() {
|
|
344
|
+
const reader = jsonStream.getReader();
|
|
345
|
+
readers.push(reader);
|
|
346
|
+
try {
|
|
347
|
+
while (!cancelled) {
|
|
348
|
+
const { done, value } = await reader.read();
|
|
349
|
+
if (done) return;
|
|
350
|
+
if (!enqueue(encodeJSONFrame(value))) return;
|
|
351
|
+
}
|
|
352
|
+
} catch (error) {
|
|
353
|
+
errorOutput(error);
|
|
354
|
+
throw error;
|
|
355
|
+
} finally {
|
|
356
|
+
reader.releaseLock();
|
|
300
357
|
}
|
|
301
|
-
}
|
|
358
|
+
}
|
|
359
|
+
async function pumpLateStreams() {
|
|
360
|
+
if (!lateStreamSource) return [];
|
|
361
|
+
const lateStreamPumps = [];
|
|
362
|
+
const reader = lateStreamSource.getReader();
|
|
363
|
+
readers.push(reader);
|
|
364
|
+
try {
|
|
365
|
+
while (!cancelled) {
|
|
366
|
+
const { done, value } = await reader.read();
|
|
367
|
+
if (done) break;
|
|
368
|
+
lateStreamPumps.push(pumpRawStream(value.id, value.stream));
|
|
369
|
+
}
|
|
370
|
+
} finally {
|
|
371
|
+
reader.releaseLock();
|
|
372
|
+
}
|
|
373
|
+
return lateStreamPumps;
|
|
374
|
+
}
|
|
302
375
|
return new ReadableStream({
|
|
303
|
-
start(
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
const { done, value } = await reader.read();
|
|
315
|
-
if (cancelled) break;
|
|
316
|
-
if (done) break;
|
|
317
|
-
safeEnqueue(encodeJSONFrame(value));
|
|
318
|
-
}
|
|
319
|
-
} catch (error) {
|
|
320
|
-
safeError(error);
|
|
321
|
-
} finally {
|
|
322
|
-
reader.releaseLock();
|
|
323
|
-
checkComplete();
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
|
-
const pumpRawStream = async (streamId, stream) => {
|
|
327
|
-
const reader = stream.getReader();
|
|
328
|
-
cancelReaders.push(() => {
|
|
329
|
-
reader.cancel().catch(() => {
|
|
330
|
-
});
|
|
331
|
-
});
|
|
332
|
-
try {
|
|
333
|
-
while (true) {
|
|
334
|
-
const { done, value } = await reader.read();
|
|
335
|
-
if (cancelled) break;
|
|
336
|
-
if (done) {
|
|
337
|
-
safeEnqueue(encodeEndFrame(streamId));
|
|
338
|
-
break;
|
|
339
|
-
}
|
|
340
|
-
safeEnqueue(encodeChunkFrame(streamId, value));
|
|
341
|
-
}
|
|
342
|
-
} catch (error) {
|
|
343
|
-
safeEnqueue(encodeErrorFrame(streamId, error));
|
|
344
|
-
} finally {
|
|
345
|
-
reader.releaseLock();
|
|
346
|
-
checkComplete();
|
|
376
|
+
async start(ctrl) {
|
|
377
|
+
controller = ctrl;
|
|
378
|
+
const pumps = [pumpJSON()];
|
|
379
|
+
for (const [streamId, stream] of rawStreams) pumps.push(pumpRawStream(streamId, stream));
|
|
380
|
+
if (lateStreamSource) pumps.push(pumpLateStreams());
|
|
381
|
+
try {
|
|
382
|
+
const latePumps = (await Promise.all(pumps)).find(Array.isArray);
|
|
383
|
+
if (latePumps && latePumps.length > 0) await Promise.all(latePumps);
|
|
384
|
+
if (!cancelled) try {
|
|
385
|
+
controller.close();
|
|
386
|
+
} catch {
|
|
347
387
|
}
|
|
348
|
-
}
|
|
349
|
-
pumpJSON();
|
|
350
|
-
for (const [streamId, stream] of rawStreams) {
|
|
351
|
-
pumpRawStream(streamId, stream);
|
|
388
|
+
} catch {
|
|
352
389
|
}
|
|
353
390
|
},
|
|
354
391
|
cancel() {
|
|
355
392
|
cancelled = true;
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
cancelReaders.length = 0;
|
|
393
|
+
for (const reader of readers) reader.cancel().catch(() => {
|
|
394
|
+
});
|
|
395
|
+
readers.length = 0;
|
|
361
396
|
}
|
|
362
397
|
});
|
|
363
398
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
370
|
-
const fnModule = await serverFnInfo.importer();
|
|
371
|
-
if (!fnModule) {
|
|
372
|
-
console.info("serverFnInfo", serverFnInfo);
|
|
373
|
-
throw new Error("Server function module not resolved for " + id);
|
|
374
|
-
}
|
|
375
|
-
const action = fnModule[serverFnInfo.functionName];
|
|
376
|
-
if (!action) {
|
|
377
|
-
console.info("serverFnInfo", serverFnInfo);
|
|
378
|
-
console.info("fnModule", fnModule);
|
|
379
|
-
throw new Error(
|
|
380
|
-
`Server function module export not resolved for serverFn ID: ${id}`
|
|
381
|
-
);
|
|
382
|
-
}
|
|
383
|
-
return action;
|
|
384
|
-
}
|
|
385
|
-
let serovalPlugins = void 0;
|
|
386
|
-
const textEncoder = new TextEncoder();
|
|
387
|
-
const FORM_DATA_CONTENT_TYPES = [
|
|
388
|
-
"multipart/form-data",
|
|
389
|
-
"application/x-www-form-urlencoded"
|
|
390
|
-
];
|
|
391
|
-
const MAX_PAYLOAD_SIZE = 1e6;
|
|
392
|
-
const handleServerAction = async ({
|
|
393
|
-
request,
|
|
394
|
-
context,
|
|
395
|
-
serverFnId
|
|
396
|
-
}) => {
|
|
397
|
-
const method = request.method;
|
|
398
|
-
const methodUpper = method.toUpperCase();
|
|
399
|
-
const methodLower = method.toLowerCase();
|
|
399
|
+
var serovalPlugins = void 0;
|
|
400
|
+
var FORM_DATA_CONTENT_TYPES = ["multipart/form-data", "application/x-www-form-urlencoded"];
|
|
401
|
+
var MAX_PAYLOAD_SIZE = 1e6;
|
|
402
|
+
var handleServerAction = async ({ request, context, serverFnId }) => {
|
|
403
|
+
const methodUpper = request.method.toUpperCase();
|
|
400
404
|
const url = new URL(request.url);
|
|
401
405
|
const action = await getServerFnById(serverFnId);
|
|
406
|
+
if (action.method && methodUpper !== action.method) return new Response(`expected ${action.method} method. Got ${methodUpper}`, {
|
|
407
|
+
status: 405,
|
|
408
|
+
headers: { Allow: action.method }
|
|
409
|
+
});
|
|
402
410
|
const isServerFn = request.headers.get("x-tsr-serverFn") === "true";
|
|
403
|
-
if (!serovalPlugins)
|
|
404
|
-
serovalPlugins = getDefaultSerovalPlugins();
|
|
405
|
-
}
|
|
411
|
+
if (!serovalPlugins) serovalPlugins = getDefaultSerovalPlugins();
|
|
406
412
|
const contentType = request.headers.get("Content-Type");
|
|
407
413
|
function parsePayload(payload) {
|
|
408
|
-
|
|
409
|
-
return parsedPayload;
|
|
414
|
+
return Pu(payload, { plugins: serovalPlugins });
|
|
410
415
|
}
|
|
411
|
-
|
|
416
|
+
return await (async () => {
|
|
412
417
|
try {
|
|
413
418
|
let serializeResult = function(res2) {
|
|
414
419
|
let nonStreamingBody = void 0;
|
|
415
420
|
const alsResponse = getResponse();
|
|
416
421
|
if (res2 !== void 0) {
|
|
417
422
|
const rawStreams = /* @__PURE__ */ new Map();
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
423
|
+
let initialPhase = true;
|
|
424
|
+
let lateStreamWriter;
|
|
425
|
+
let lateStreamReadable = void 0;
|
|
426
|
+
const pendingLateStreams = [];
|
|
427
|
+
const plugins = [createRawStreamRPCPlugin((id, stream) => {
|
|
428
|
+
if (initialPhase) {
|
|
429
|
+
rawStreams.set(id, stream);
|
|
430
|
+
return;
|
|
421
431
|
}
|
|
422
|
-
|
|
423
|
-
|
|
432
|
+
if (lateStreamWriter) {
|
|
433
|
+
lateStreamWriter.write({
|
|
434
|
+
id,
|
|
435
|
+
stream
|
|
436
|
+
}).catch(() => {
|
|
437
|
+
});
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
pendingLateStreams.push({
|
|
441
|
+
id,
|
|
442
|
+
stream
|
|
443
|
+
});
|
|
444
|
+
}), ...serovalPlugins || []];
|
|
424
445
|
let done = false;
|
|
425
446
|
const callbacks = {
|
|
426
447
|
onParse: (value) => {
|
|
@@ -446,73 +467,57 @@ const handleServerAction = async ({
|
|
|
446
467
|
callbacks.onError(error);
|
|
447
468
|
}
|
|
448
469
|
});
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
callbacks.onParse = (value) => {
|
|
466
|
-
controller.enqueue(JSON.stringify(value) + "\n");
|
|
467
|
-
};
|
|
468
|
-
callbacks.onDone = () => {
|
|
469
|
-
try {
|
|
470
|
-
controller.close();
|
|
471
|
-
} catch {
|
|
472
|
-
}
|
|
473
|
-
};
|
|
474
|
-
callbacks.onError = (error) => controller.error(error);
|
|
475
|
-
if (nonStreamingBody !== void 0) {
|
|
476
|
-
callbacks.onParse(nonStreamingBody);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
});
|
|
480
|
-
const multiplexedStream = createMultiplexedStream(
|
|
481
|
-
jsonStream,
|
|
482
|
-
rawStreams
|
|
483
|
-
);
|
|
484
|
-
return new Response(multiplexedStream, {
|
|
485
|
-
status: alsResponse.status,
|
|
486
|
-
statusText: alsResponse.statusText,
|
|
487
|
-
headers: {
|
|
488
|
-
"Content-Type": TSS_CONTENT_TYPE_FRAMED_VERSIONED,
|
|
489
|
-
[X_TSS_SERIALIZED]: "true"
|
|
490
|
-
}
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
const stream = new ReadableStream({
|
|
470
|
+
initialPhase = false;
|
|
471
|
+
if (done && rawStreams.size === 0) return new Response(nonStreamingBody ? JSON.stringify(nonStreamingBody) : void 0, {
|
|
472
|
+
status: alsResponse.status,
|
|
473
|
+
statusText: alsResponse.statusText,
|
|
474
|
+
headers: {
|
|
475
|
+
"Content-Type": "application/json",
|
|
476
|
+
[X_TSS_SERIALIZED]: "true"
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
const { readable, writable } = new TransformStream();
|
|
480
|
+
lateStreamReadable = readable;
|
|
481
|
+
lateStreamWriter = writable.getWriter();
|
|
482
|
+
for (const registration of pendingLateStreams) lateStreamWriter.write(registration).catch(() => {
|
|
483
|
+
});
|
|
484
|
+
pendingLateStreams.length = 0;
|
|
485
|
+
const multiplexedStream = createMultiplexedStream(new ReadableStream({
|
|
494
486
|
start(controller) {
|
|
495
|
-
callbacks.onParse = (value) =>
|
|
496
|
-
|
|
497
|
-
|
|
487
|
+
callbacks.onParse = (value) => {
|
|
488
|
+
controller.enqueue(JSON.stringify(value) + "\n");
|
|
489
|
+
};
|
|
498
490
|
callbacks.onDone = () => {
|
|
499
491
|
try {
|
|
500
492
|
controller.close();
|
|
501
|
-
} catch
|
|
502
|
-
controller.error(error);
|
|
493
|
+
} catch {
|
|
503
494
|
}
|
|
495
|
+
lateStreamWriter?.close().catch(() => {
|
|
496
|
+
}).finally(() => {
|
|
497
|
+
lateStreamWriter = void 0;
|
|
498
|
+
});
|
|
499
|
+
};
|
|
500
|
+
callbacks.onError = (error) => {
|
|
501
|
+
controller.error(error);
|
|
502
|
+
lateStreamWriter?.abort(error).catch(() => {
|
|
503
|
+
}).finally(() => {
|
|
504
|
+
lateStreamWriter = void 0;
|
|
505
|
+
});
|
|
504
506
|
};
|
|
505
|
-
|
|
506
|
-
if (
|
|
507
|
-
|
|
508
|
-
|
|
507
|
+
if (nonStreamingBody !== void 0) callbacks.onParse(nonStreamingBody);
|
|
508
|
+
if (done) callbacks.onDone();
|
|
509
|
+
},
|
|
510
|
+
cancel() {
|
|
511
|
+
lateStreamWriter?.abort().catch(() => {
|
|
512
|
+
});
|
|
513
|
+
lateStreamWriter = void 0;
|
|
509
514
|
}
|
|
510
|
-
});
|
|
511
|
-
return new Response(
|
|
515
|
+
}), rawStreams, lateStreamReadable);
|
|
516
|
+
return new Response(multiplexedStream, {
|
|
512
517
|
status: alsResponse.status,
|
|
513
518
|
statusText: alsResponse.statusText,
|
|
514
519
|
headers: {
|
|
515
|
-
"Content-Type":
|
|
520
|
+
"Content-Type": TSS_CONTENT_TYPE_FRAMED_VERSIONED,
|
|
516
521
|
[X_TSS_SERIALIZED]: "true"
|
|
517
522
|
}
|
|
518
523
|
});
|
|
@@ -523,13 +528,11 @@ const handleServerAction = async ({
|
|
|
523
528
|
});
|
|
524
529
|
};
|
|
525
530
|
let res = await (async () => {
|
|
526
|
-
if (FORM_DATA_CONTENT_TYPES.some(
|
|
527
|
-
(
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
"GET requests with FormData payloads are not supported"
|
|
532
|
-
);
|
|
531
|
+
if (FORM_DATA_CONTENT_TYPES.some((type) => contentType && contentType.includes(type))) {
|
|
532
|
+
if (methodUpper === "GET") {
|
|
533
|
+
if (false) ;
|
|
534
|
+
invariant();
|
|
535
|
+
}
|
|
533
536
|
const formData = await request.formData();
|
|
534
537
|
const serializedContext = formData.get(TSS_FORMDATA_CONTEXT);
|
|
535
538
|
formData.delete(TSS_FORMDATA_CONTEXT);
|
|
@@ -538,85 +541,54 @@ const handleServerAction = async ({
|
|
|
538
541
|
data: formData,
|
|
539
542
|
method: methodUpper
|
|
540
543
|
};
|
|
541
|
-
if (typeof serializedContext === "string") {
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
});
|
|
547
|
-
if (typeof deserializedContext === "object" && deserializedContext) {
|
|
548
|
-
params.context = safeObjectMerge(
|
|
549
|
-
context,
|
|
550
|
-
deserializedContext
|
|
551
|
-
);
|
|
552
|
-
}
|
|
553
|
-
} catch (e) {
|
|
554
|
-
if (false) ;
|
|
555
|
-
}
|
|
544
|
+
if (typeof serializedContext === "string") try {
|
|
545
|
+
const deserializedContext = Pu(JSON.parse(serializedContext), { plugins: serovalPlugins });
|
|
546
|
+
if (typeof deserializedContext === "object" && deserializedContext) params.context = safeObjectMerge(deserializedContext, context);
|
|
547
|
+
} catch (e) {
|
|
548
|
+
if (false) ;
|
|
556
549
|
}
|
|
557
550
|
return await action(params);
|
|
558
551
|
}
|
|
559
|
-
if (
|
|
552
|
+
if (methodUpper === "GET") {
|
|
560
553
|
const payloadParam = url.searchParams.get("payload");
|
|
561
|
-
if (payloadParam && payloadParam.length > MAX_PAYLOAD_SIZE)
|
|
562
|
-
throw new Error("Payload too large");
|
|
563
|
-
}
|
|
554
|
+
if (payloadParam && payloadParam.length > MAX_PAYLOAD_SIZE) throw new Error("Payload too large");
|
|
564
555
|
const payload2 = payloadParam ? parsePayload(JSON.parse(payloadParam)) : {};
|
|
565
|
-
payload2.context = safeObjectMerge(context,
|
|
556
|
+
payload2.context = safeObjectMerge(payload2.context, context);
|
|
566
557
|
payload2.method = methodUpper;
|
|
567
558
|
return await action(payload2);
|
|
568
559
|
}
|
|
569
|
-
if (methodLower !== "post") {
|
|
570
|
-
throw new Error("expected POST method");
|
|
571
|
-
}
|
|
572
560
|
let jsonPayload;
|
|
573
|
-
if (contentType?.includes("application/json"))
|
|
574
|
-
jsonPayload = await request.json();
|
|
575
|
-
}
|
|
561
|
+
if (contentType?.includes("application/json")) jsonPayload = await request.json();
|
|
576
562
|
const payload = jsonPayload ? parsePayload(jsonPayload) : {};
|
|
577
563
|
payload.context = safeObjectMerge(payload.context, context);
|
|
578
564
|
payload.method = methodUpper;
|
|
579
565
|
return await action(payload);
|
|
580
566
|
})();
|
|
581
567
|
const unwrapped = res.result || res.error;
|
|
582
|
-
if (isNotFound(res))
|
|
583
|
-
|
|
584
|
-
}
|
|
585
|
-
if (!isServerFn) {
|
|
586
|
-
return unwrapped;
|
|
587
|
-
}
|
|
568
|
+
if (isNotFound(res)) res = isNotFoundResponse(res);
|
|
569
|
+
if (!isServerFn) return unwrapped;
|
|
588
570
|
if (unwrapped instanceof Response) {
|
|
589
|
-
if (isRedirect(unwrapped))
|
|
590
|
-
return unwrapped;
|
|
591
|
-
}
|
|
571
|
+
if (isRedirect(unwrapped)) return unwrapped;
|
|
592
572
|
unwrapped.headers.set(X_TSS_RAW_RESPONSE, "true");
|
|
593
573
|
return unwrapped;
|
|
594
574
|
}
|
|
595
575
|
return serializeResult(res);
|
|
596
576
|
} catch (error) {
|
|
597
|
-
if (error instanceof Response)
|
|
598
|
-
|
|
599
|
-
}
|
|
600
|
-
if (isNotFound(error)) {
|
|
601
|
-
return isNotFoundResponse(error);
|
|
602
|
-
}
|
|
577
|
+
if (error instanceof Response) return error;
|
|
578
|
+
if (isNotFound(error)) return isNotFoundResponse(error);
|
|
603
579
|
console.info();
|
|
604
580
|
console.info("Server Fn Error!");
|
|
605
581
|
console.info();
|
|
606
582
|
console.error(error);
|
|
607
583
|
console.info();
|
|
608
|
-
const serializedError = JSON.stringify(
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
})
|
|
614
|
-
)
|
|
615
|
-
);
|
|
616
|
-
const response2 = getResponse();
|
|
584
|
+
const serializedError = JSON.stringify(await Promise.resolve(su(error, {
|
|
585
|
+
refs: /* @__PURE__ */ new Map(),
|
|
586
|
+
plugins: serovalPlugins
|
|
587
|
+
})));
|
|
588
|
+
const response = getResponse();
|
|
617
589
|
return new Response(serializedError, {
|
|
618
|
-
status:
|
|
619
|
-
statusText:
|
|
590
|
+
status: response.status ?? 500,
|
|
591
|
+
statusText: response.statusText,
|
|
620
592
|
headers: {
|
|
621
593
|
"Content-Type": "application/json",
|
|
622
594
|
[X_TSS_SERIALIZED]: "true"
|
|
@@ -624,7 +596,6 @@ const handleServerAction = async ({
|
|
|
624
596
|
});
|
|
625
597
|
}
|
|
626
598
|
})();
|
|
627
|
-
return response;
|
|
628
599
|
};
|
|
629
600
|
function isNotFoundResponse(error) {
|
|
630
601
|
const { headers, ...rest } = error;
|
|
@@ -636,115 +607,534 @@ function isNotFoundResponse(error) {
|
|
|
636
607
|
}
|
|
637
608
|
});
|
|
638
609
|
}
|
|
639
|
-
|
|
610
|
+
var LINK_PARAM_TOKEN_RE = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
|
|
611
|
+
var PRELOAD_AS_VALUES = /* @__PURE__ */ new Set([
|
|
612
|
+
"fetch",
|
|
613
|
+
"font",
|
|
614
|
+
"image",
|
|
615
|
+
"script",
|
|
616
|
+
"style",
|
|
617
|
+
"track"
|
|
618
|
+
]);
|
|
619
|
+
function buildLinkParam(name, value) {
|
|
620
|
+
if (value === void 0) return name;
|
|
621
|
+
if (LINK_PARAM_TOKEN_RE.test(value)) return `${name}=${value}`;
|
|
622
|
+
return `${name}=${JSON.stringify(value)}`;
|
|
623
|
+
}
|
|
624
|
+
function serializeEarlyHint(hint) {
|
|
625
|
+
const parts = [`<${hint.href}>`, buildLinkParam("rel", hint.rel)];
|
|
626
|
+
if (hint.as) parts.push(buildLinkParam("as", hint.as));
|
|
627
|
+
if (hint.crossOrigin !== void 0) parts.push(buildLinkParam("crossorigin", hint.crossOrigin || void 0));
|
|
628
|
+
if (hint.type) parts.push(buildLinkParam("type", hint.type));
|
|
629
|
+
if (hint.integrity) parts.push(buildLinkParam("integrity", hint.integrity));
|
|
630
|
+
if (hint.referrerPolicy) parts.push(buildLinkParam("referrerpolicy", hint.referrerPolicy));
|
|
631
|
+
if (hint.fetchPriority) parts.push(buildLinkParam("fetchpriority", hint.fetchPriority));
|
|
632
|
+
return parts.join("; ");
|
|
633
|
+
}
|
|
634
|
+
function getStringAttr(attrs, name, fallbackName) {
|
|
635
|
+
const value = attrs?.[name] ?? (fallbackName ? attrs?.[fallbackName] : void 0);
|
|
636
|
+
return typeof value === "string" ? value : void 0;
|
|
637
|
+
}
|
|
638
|
+
function getPreloadAs(attrs) {
|
|
639
|
+
const as = getStringAttr(attrs, "as");
|
|
640
|
+
return as && PRELOAD_AS_VALUES.has(as) ? as : void 0;
|
|
641
|
+
}
|
|
642
|
+
function addEarlyHintFetchAttrs(hint, attrs) {
|
|
643
|
+
const crossOrigin = getStringAttr(attrs, "crossOrigin", "crossorigin");
|
|
644
|
+
const type = getStringAttr(attrs, "type");
|
|
645
|
+
const integrity = getStringAttr(attrs, "integrity");
|
|
646
|
+
const referrerPolicy = getStringAttr(attrs, "referrerPolicy", "referrerpolicy");
|
|
647
|
+
const fetchPriority = getStringAttr(attrs, "fetchPriority", "fetchpriority");
|
|
648
|
+
if (crossOrigin !== void 0) hint.crossOrigin = crossOrigin;
|
|
649
|
+
if (type) hint.type = type;
|
|
650
|
+
if (integrity) hint.integrity = integrity;
|
|
651
|
+
if (referrerPolicy) hint.referrerPolicy = referrerPolicy;
|
|
652
|
+
if (fetchPriority) hint.fetchPriority = fetchPriority;
|
|
653
|
+
}
|
|
654
|
+
function linkAttrsToEarlyHint(attrs) {
|
|
655
|
+
const href = getStringAttr(attrs, "href");
|
|
656
|
+
const rel = getStringAttr(attrs, "rel");
|
|
657
|
+
if (!href || !rel) return void 0;
|
|
658
|
+
const relTokens = rel.split(/\s+/);
|
|
659
|
+
let hintRel;
|
|
660
|
+
let hintAs;
|
|
661
|
+
if (relTokens.includes("modulepreload")) {
|
|
662
|
+
hintRel = "modulepreload";
|
|
663
|
+
hintAs = "script";
|
|
664
|
+
} else if (relTokens.includes("stylesheet")) {
|
|
665
|
+
hintRel = "preload";
|
|
666
|
+
hintAs = "style";
|
|
667
|
+
} else if (relTokens.includes("preload")) {
|
|
668
|
+
hintAs = getPreloadAs(attrs);
|
|
669
|
+
if (!hintAs) return void 0;
|
|
670
|
+
hintRel = "preload";
|
|
671
|
+
} else if (relTokens.includes("preconnect")) {
|
|
672
|
+
hintRel = "preconnect";
|
|
673
|
+
hintAs = void 0;
|
|
674
|
+
} else if (relTokens.includes("dns-prefetch")) {
|
|
675
|
+
hintRel = "dns-prefetch";
|
|
676
|
+
hintAs = void 0;
|
|
677
|
+
}
|
|
678
|
+
if (!hintRel) return void 0;
|
|
679
|
+
const hint = {
|
|
680
|
+
href,
|
|
681
|
+
rel: hintRel
|
|
682
|
+
};
|
|
683
|
+
if (hintAs) hint.as = hintAs;
|
|
684
|
+
addEarlyHintFetchAttrs(hint, attrs);
|
|
685
|
+
return hint;
|
|
686
|
+
}
|
|
687
|
+
function collectStaticHintsFromManifest(manifest2, matchedRoutes) {
|
|
688
|
+
const hints = [];
|
|
689
|
+
for (const route of matchedRoutes) {
|
|
690
|
+
const routeManifest = manifest2.routes[route.id];
|
|
691
|
+
if (!routeManifest) continue;
|
|
692
|
+
for (const link of routeManifest.preloads ?? []) {
|
|
693
|
+
const attrs = getScriptPreloadAttrs(manifest2, link);
|
|
694
|
+
const hint = {
|
|
695
|
+
href: attrs.href,
|
|
696
|
+
rel: attrs.rel,
|
|
697
|
+
as: "script"
|
|
698
|
+
};
|
|
699
|
+
if (attrs.crossOrigin !== void 0) hint.crossOrigin = attrs.crossOrigin;
|
|
700
|
+
hints.push(hint);
|
|
701
|
+
}
|
|
702
|
+
for (const link of routeManifest.css ?? []) {
|
|
703
|
+
const stylesheetHref = getStylesheetHref(link);
|
|
704
|
+
if (manifest2.inlineCss?.styles[stylesheetHref] !== void 0) continue;
|
|
705
|
+
const resolvedLink = resolveManifestCssLink(link);
|
|
706
|
+
const hint = {
|
|
707
|
+
href: stylesheetHref,
|
|
708
|
+
rel: "preload",
|
|
709
|
+
as: "style"
|
|
710
|
+
};
|
|
711
|
+
if (resolvedLink.crossOrigin !== void 0) hint.crossOrigin = resolvedLink.crossOrigin;
|
|
712
|
+
hints.push(hint);
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
return hints;
|
|
716
|
+
}
|
|
717
|
+
function collectDynamicHintsFromMatches(matches) {
|
|
718
|
+
const hints = [];
|
|
719
|
+
for (const match of matches) {
|
|
720
|
+
const links = match.links;
|
|
721
|
+
if (!Array.isArray(links)) continue;
|
|
722
|
+
for (const link of links) {
|
|
723
|
+
const hint = linkAttrsToEarlyHint(link);
|
|
724
|
+
if (hint) hints.push(hint);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
return hints;
|
|
728
|
+
}
|
|
729
|
+
function createEarlyHintsEvent(opts) {
|
|
730
|
+
const nextHints = [];
|
|
731
|
+
const nextLinks = [];
|
|
732
|
+
for (const hint of opts.hints) {
|
|
733
|
+
const link = serializeEarlyHint(hint);
|
|
734
|
+
if (opts.sentLinks.has(link)) continue;
|
|
735
|
+
opts.sentLinks.add(link);
|
|
736
|
+
opts.sentHints.push(hint);
|
|
737
|
+
nextHints.push(hint);
|
|
738
|
+
nextLinks.push(link);
|
|
739
|
+
}
|
|
740
|
+
if (!nextHints.length && opts.phase !== "dynamic") return void 0;
|
|
741
|
+
return {
|
|
742
|
+
phase: opts.phase,
|
|
743
|
+
hints: nextHints,
|
|
744
|
+
links: nextLinks,
|
|
745
|
+
allHints: opts.sentHints.slice(),
|
|
746
|
+
allLinks: Array.from(opts.sentLinks)
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
function createResponseLinkHeaderEntries(opts) {
|
|
750
|
+
for (const hint of opts.hints) {
|
|
751
|
+
const link = serializeEarlyHint(hint);
|
|
752
|
+
if (opts.sentLinks.has(link)) continue;
|
|
753
|
+
opts.sentLinks.add(link);
|
|
754
|
+
opts.entries.push({
|
|
755
|
+
phase: opts.phase,
|
|
756
|
+
hint,
|
|
757
|
+
link
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
function getResponseLinkHeaderEntries(opts) {
|
|
762
|
+
if (!opts.filter) return opts.entries.map((entry) => entry.link);
|
|
763
|
+
try {
|
|
764
|
+
const links = [];
|
|
765
|
+
for (const entry of opts.entries) if (opts.filter(entry)) links.push(entry.link);
|
|
766
|
+
return links;
|
|
767
|
+
} catch (err) {
|
|
768
|
+
console.error("Error filtering response Link headers:", err);
|
|
769
|
+
return [];
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
function notifyEarlyHints(phase, event, onEarlyHints) {
|
|
773
|
+
try {
|
|
774
|
+
const result = onEarlyHints(event);
|
|
775
|
+
if (result) Promise.resolve(result).catch((err) => {
|
|
776
|
+
console.error(`Error sending ${phase} early hints:`, err);
|
|
777
|
+
});
|
|
778
|
+
} catch (err) {
|
|
779
|
+
console.error(`Error sending ${phase} early hints:`, err);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
function getResponseLinkHeaderFilter(responseLinkHeader) {
|
|
783
|
+
if (typeof responseLinkHeader !== "object") return;
|
|
784
|
+
return responseLinkHeader.filter;
|
|
785
|
+
}
|
|
786
|
+
function appendResponseLinkHeaders(opts) {
|
|
787
|
+
for (const link of getResponseLinkHeaderEntries(opts)) opts.responseHeaders.append("Link", link);
|
|
788
|
+
}
|
|
789
|
+
function collectResponseLinkHeaderEntries(opts) {
|
|
790
|
+
for (let index = 0; index < opts.event.hints.length; index++) opts.entries.push({
|
|
791
|
+
phase: opts.phase,
|
|
792
|
+
hint: opts.event.hints[index],
|
|
793
|
+
link: opts.event.links[index]
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
function collectEarlyHintsPhase(opts) {
|
|
797
|
+
const event = opts.onEarlyHints ? createEarlyHintsEvent({
|
|
798
|
+
phase: opts.phase,
|
|
799
|
+
hints: opts.hints,
|
|
800
|
+
sentLinks: opts.sentLinks,
|
|
801
|
+
sentHints: opts.sentHints
|
|
802
|
+
}) : void 0;
|
|
803
|
+
if (event) notifyEarlyHints(opts.phase, event, opts.onEarlyHints);
|
|
804
|
+
if (!opts.responseLinkHeaderEntries) return;
|
|
805
|
+
if (event) {
|
|
806
|
+
collectResponseLinkHeaderEntries({
|
|
807
|
+
phase: opts.phase,
|
|
808
|
+
event,
|
|
809
|
+
entries: opts.responseLinkHeaderEntries
|
|
810
|
+
});
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
createResponseLinkHeaderEntries({
|
|
814
|
+
phase: opts.phase,
|
|
815
|
+
hints: opts.hints,
|
|
816
|
+
sentLinks: opts.sentLinks,
|
|
817
|
+
entries: opts.responseLinkHeaderEntries
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
function createEarlyHintsCollector(opts) {
|
|
821
|
+
if (!opts?.onEarlyHints && !opts?.responseLinkHeader) return;
|
|
822
|
+
const sentLinks = /* @__PURE__ */ new Set();
|
|
823
|
+
const sentHints = opts.onEarlyHints ? new Array() : void 0;
|
|
824
|
+
const responseLinkHeaderEntries = opts.responseLinkHeader ? new Array() : void 0;
|
|
825
|
+
const responseLinkHeaderFilter = getResponseLinkHeaderFilter(opts.responseLinkHeader);
|
|
826
|
+
return {
|
|
827
|
+
collectStatic: ({ manifest: manifest2, matchedRoutes }) => {
|
|
828
|
+
if (!matchedRoutes?.length) return;
|
|
829
|
+
collectEarlyHintsPhase({
|
|
830
|
+
phase: "static",
|
|
831
|
+
hints: collectStaticHintsFromManifest(manifest2, matchedRoutes),
|
|
832
|
+
sentLinks,
|
|
833
|
+
sentHints,
|
|
834
|
+
onEarlyHints: opts.onEarlyHints,
|
|
835
|
+
responseLinkHeaderEntries
|
|
836
|
+
});
|
|
837
|
+
},
|
|
838
|
+
collectDynamic: (matches) => {
|
|
839
|
+
collectEarlyHintsPhase({
|
|
840
|
+
phase: "dynamic",
|
|
841
|
+
hints: collectDynamicHintsFromMatches(matches),
|
|
842
|
+
sentLinks,
|
|
843
|
+
sentHints,
|
|
844
|
+
onEarlyHints: opts.onEarlyHints,
|
|
845
|
+
responseLinkHeaderEntries
|
|
846
|
+
});
|
|
847
|
+
},
|
|
848
|
+
appendResponseHeaders: (headers) => {
|
|
849
|
+
if (!responseLinkHeaderEntries?.length) return;
|
|
850
|
+
appendResponseLinkHeaders({
|
|
851
|
+
responseHeaders: headers,
|
|
852
|
+
entries: responseLinkHeaderEntries,
|
|
853
|
+
filter: responseLinkHeaderFilter
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
function normalizeTransformAssetResult(result) {
|
|
859
|
+
if (typeof result === "string") return { href: result };
|
|
860
|
+
return result;
|
|
861
|
+
}
|
|
862
|
+
function escapeCssString(value) {
|
|
863
|
+
return value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\a ").replace(/\r/g, "\\d ").replace(/\f/g, "\\c ");
|
|
864
|
+
}
|
|
865
|
+
async function transformInlineCssTemplate(options) {
|
|
866
|
+
const { strings, urls } = options.template;
|
|
867
|
+
if (strings.length !== urls.length + 1) throw new Error(`TanStack Start inlineCss template for ${options.stylesheetHref} is invalid`);
|
|
868
|
+
let css = strings[0];
|
|
869
|
+
for (let index = 0; index < urls.length; index++) {
|
|
870
|
+
const transformed = normalizeTransformAssetResult(await options.transformFn({
|
|
871
|
+
kind: "css-url",
|
|
872
|
+
url: urls[index],
|
|
873
|
+
stylesheetHref: options.stylesheetHref
|
|
874
|
+
}));
|
|
875
|
+
css += escapeCssString(transformed.href) + strings[index + 1];
|
|
876
|
+
}
|
|
877
|
+
return css;
|
|
878
|
+
}
|
|
879
|
+
async function transformInlineCssStyles(inlineCss, transformFn) {
|
|
880
|
+
const transformedStyles = {};
|
|
881
|
+
const transformedEntries = await Promise.all(Object.entries(inlineCss.styles).map(async ([stylesheetHref, css]) => {
|
|
882
|
+
const template = inlineCss.templates?.[stylesheetHref];
|
|
883
|
+
return [stylesheetHref, template ? await transformInlineCssTemplate({
|
|
884
|
+
stylesheetHref,
|
|
885
|
+
template,
|
|
886
|
+
transformFn
|
|
887
|
+
}) : css];
|
|
888
|
+
}));
|
|
889
|
+
for (const [stylesheetHref, css] of transformedEntries) transformedStyles[stylesheetHref] = css;
|
|
890
|
+
return {
|
|
891
|
+
styles: transformedStyles,
|
|
892
|
+
...inlineCss.templates ? { templates: inlineCss.templates } : {}
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
function resolveTransformAssetsCrossOrigin(config, kind) {
|
|
896
|
+
if (!config) return void 0;
|
|
897
|
+
if (typeof config === "string") return config;
|
|
898
|
+
return config[kind];
|
|
899
|
+
}
|
|
900
|
+
function isObjectShorthand(transform) {
|
|
901
|
+
return "prefix" in transform;
|
|
902
|
+
}
|
|
903
|
+
function resolveTransformAssetsConfig(transform) {
|
|
640
904
|
if (typeof transform === "string") {
|
|
641
|
-
const
|
|
905
|
+
const prefix = transform;
|
|
642
906
|
return {
|
|
643
907
|
type: "transform",
|
|
644
|
-
transformFn: ({ url }) => `${
|
|
908
|
+
transformFn: ({ url }) => ({ href: `${prefix}${url}` }),
|
|
645
909
|
cache: true
|
|
646
910
|
};
|
|
647
911
|
}
|
|
648
|
-
if (typeof transform === "function") {
|
|
912
|
+
if (typeof transform === "function") return {
|
|
913
|
+
type: "transform",
|
|
914
|
+
transformFn: transform,
|
|
915
|
+
cache: true
|
|
916
|
+
};
|
|
917
|
+
if (isObjectShorthand(transform)) {
|
|
918
|
+
const { prefix, crossOrigin } = transform;
|
|
649
919
|
return {
|
|
650
920
|
type: "transform",
|
|
651
|
-
transformFn:
|
|
921
|
+
transformFn: ({ url, kind }) => {
|
|
922
|
+
const href = `${prefix}${url}`;
|
|
923
|
+
if (kind === "css-url") return { href };
|
|
924
|
+
const co = resolveTransformAssetsCrossOrigin(crossOrigin, kind);
|
|
925
|
+
return co ? {
|
|
926
|
+
href,
|
|
927
|
+
crossOrigin: co
|
|
928
|
+
} : { href };
|
|
929
|
+
},
|
|
652
930
|
cache: true
|
|
653
931
|
};
|
|
654
932
|
}
|
|
655
|
-
if ("createTransform" in transform && transform.createTransform) {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
};
|
|
661
|
-
}
|
|
662
|
-
const transformFn = typeof transform.transform === "string" ? (({ url }) => `${transform.transform}${url}`) : transform.transform;
|
|
933
|
+
if ("createTransform" in transform && transform.createTransform) return {
|
|
934
|
+
type: "createTransform",
|
|
935
|
+
createTransform: transform.createTransform,
|
|
936
|
+
cache: transform.cache !== false
|
|
937
|
+
};
|
|
663
938
|
return {
|
|
664
939
|
type: "transform",
|
|
665
|
-
transformFn,
|
|
940
|
+
transformFn: typeof transform.transform === "string" ? (({ url }) => ({ href: `${transform.transform}${url}` })) : transform.transform,
|
|
666
941
|
cache: transform.cache !== false
|
|
667
942
|
};
|
|
668
943
|
}
|
|
669
|
-
function
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
944
|
+
function assignManifestLink(link, next) {
|
|
945
|
+
if (typeof link === "string") return next.crossOrigin ? next : next.href;
|
|
946
|
+
const nextLink = {
|
|
947
|
+
...link,
|
|
948
|
+
href: next.href
|
|
949
|
+
};
|
|
950
|
+
if (next.crossOrigin) nextLink.crossOrigin = next.crossOrigin;
|
|
951
|
+
else delete nextLink.crossOrigin;
|
|
952
|
+
return nextLink;
|
|
953
|
+
}
|
|
954
|
+
async function transformManifestAssets(source, transformFn, _opts) {
|
|
955
|
+
const manifest2 = structuredClone(source);
|
|
956
|
+
const inlineCssEnabled = _opts?.inlineCss !== false;
|
|
957
|
+
const scriptTransforms = /* @__PURE__ */ new Map();
|
|
958
|
+
const transformScript = (url) => {
|
|
959
|
+
const cached = scriptTransforms.get(url);
|
|
960
|
+
if (cached) return cached;
|
|
961
|
+
const transformed = Promise.resolve(transformFn({
|
|
962
|
+
url,
|
|
963
|
+
kind: "script"
|
|
964
|
+
})).then(normalizeTransformAssetResult);
|
|
965
|
+
scriptTransforms.set(url, transformed);
|
|
966
|
+
return transformed;
|
|
967
|
+
};
|
|
968
|
+
if (!inlineCssEnabled) delete manifest2.inlineCss;
|
|
969
|
+
else if (manifest2.inlineCss) manifest2.inlineCss = await transformInlineCssStyles(manifest2.inlineCss, transformFn);
|
|
970
|
+
for (const route of Object.values(manifest2.routes)) {
|
|
971
|
+
if (route.preloads?.length) route.preloads = await Promise.all(route.preloads.map(async (link) => {
|
|
972
|
+
const result = await transformScript(resolveManifestAssetLink(link).href);
|
|
973
|
+
return assignManifestLink(link, {
|
|
974
|
+
href: result.href,
|
|
975
|
+
crossOrigin: result.crossOrigin
|
|
976
|
+
});
|
|
977
|
+
}));
|
|
978
|
+
if (route.css?.length && !manifest2.inlineCss) route.css = await Promise.all(route.css.map(async (link) => {
|
|
979
|
+
const result = normalizeTransformAssetResult(await transformFn({
|
|
980
|
+
url: resolveManifestCssLink(link).href,
|
|
981
|
+
kind: "stylesheet"
|
|
982
|
+
}));
|
|
983
|
+
return assignManifestLink(link, {
|
|
984
|
+
href: result.href,
|
|
985
|
+
crossOrigin: result.crossOrigin
|
|
986
|
+
});
|
|
987
|
+
}));
|
|
988
|
+
if (route.scripts?.length) for (const script of route.scripts) {
|
|
989
|
+
const src = script.attrs?.src;
|
|
990
|
+
if (typeof src !== "string") continue;
|
|
991
|
+
const result = await transformScript(src);
|
|
992
|
+
script.attrs = {
|
|
993
|
+
...script.attrs,
|
|
994
|
+
src: result.href
|
|
995
|
+
};
|
|
996
|
+
if (result.crossOrigin) script.attrs.crossOrigin = result.crossOrigin;
|
|
997
|
+
else delete script.attrs.crossOrigin;
|
|
998
|
+
}
|
|
674
999
|
}
|
|
1000
|
+
return manifest2;
|
|
1001
|
+
}
|
|
1002
|
+
function buildManifest(source, opts) {
|
|
675
1003
|
return {
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
async: true
|
|
680
|
-
},
|
|
681
|
-
children: script
|
|
1004
|
+
...source.scriptFormat ? { scriptFormat: source.scriptFormat } : {},
|
|
1005
|
+
...opts?.inlineCss !== false && source.inlineCss ? { inlineCss: structuredClone(source.inlineCss) } : {},
|
|
1006
|
+
routes: { ...source.routes }
|
|
682
1007
|
};
|
|
683
1008
|
}
|
|
684
|
-
function
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
);
|
|
1009
|
+
function getStaticHandlerInlineCssDefault(handlerInlineCss) {
|
|
1010
|
+
if (typeof handlerInlineCss === "function") return;
|
|
1011
|
+
return handlerInlineCss ?? true;
|
|
1012
|
+
}
|
|
1013
|
+
async function resolveInlineCssForRequest(opts) {
|
|
1014
|
+
if (opts.requestInlineCss !== void 0) return opts.requestInlineCss;
|
|
1015
|
+
if (typeof opts.handlerInlineCss === "function") return await opts.handlerInlineCss({ request: opts.request });
|
|
1016
|
+
return opts.handlerInlineCss ?? true;
|
|
1017
|
+
}
|
|
1018
|
+
function createCachedBaseManifestLoader(loadBaseManifest) {
|
|
1019
|
+
let baseManifestPromise;
|
|
1020
|
+
return () => {
|
|
1021
|
+
if (!baseManifestPromise) baseManifestPromise = loadBaseManifest().catch((error) => {
|
|
1022
|
+
baseManifestPromise = void 0;
|
|
1023
|
+
throw error;
|
|
1024
|
+
});
|
|
1025
|
+
return baseManifestPromise;
|
|
1026
|
+
};
|
|
1027
|
+
}
|
|
1028
|
+
function createFinalManifestTransformResolver(transformAssets, opts) {
|
|
1029
|
+
const transformConfig = transformAssets !== void 0 ? resolveTransformAssetsConfig(transformAssets) : void 0;
|
|
1030
|
+
const cache = transformConfig ? transformConfig.cache : true;
|
|
1031
|
+
const warmup = !!transformAssets && typeof transformAssets === "object" && "warmup" in transformAssets && transformAssets.warmup === true;
|
|
1032
|
+
let cachedCreateTransformPromise;
|
|
1033
|
+
const clearCachedCreateTransform = () => {
|
|
1034
|
+
cachedCreateTransformPromise = void 0;
|
|
1035
|
+
};
|
|
1036
|
+
return {
|
|
1037
|
+
cache,
|
|
1038
|
+
warmup,
|
|
1039
|
+
clearCachedCreateTransform,
|
|
1040
|
+
getTransformFn: async (ctx) => {
|
|
1041
|
+
if (!transformConfig) return void 0;
|
|
1042
|
+
if (transformConfig.type !== "createTransform") return transformConfig.transformFn;
|
|
1043
|
+
if (!cache || false) return transformConfig.createTransform(ctx);
|
|
1044
|
+
if (!cachedCreateTransformPromise) cachedCreateTransformPromise = Promise.resolve(transformConfig.createTransform(ctx)).catch((error) => {
|
|
1045
|
+
clearCachedCreateTransform();
|
|
1046
|
+
throw error;
|
|
1047
|
+
});
|
|
1048
|
+
return cachedCreateTransformPromise;
|
|
723
1049
|
}
|
|
724
|
-
|
|
725
|
-
})();
|
|
1050
|
+
};
|
|
726
1051
|
}
|
|
727
|
-
function
|
|
728
|
-
const
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
)
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
}
|
|
1052
|
+
function createFinalManifestResolver(opts) {
|
|
1053
|
+
const finalManifestCache = /* @__PURE__ */ new Map();
|
|
1054
|
+
const transformResolver = createFinalManifestTransformResolver(opts.transformAssets);
|
|
1055
|
+
const handlerDefaultInlineCss = getStaticHandlerInlineCssDefault(opts.inlineCss);
|
|
1056
|
+
const getRequestManifestOptions = async (requestOpts) => {
|
|
1057
|
+
const transformFn = await transformResolver.getTransformFn({
|
|
1058
|
+
warmup: false,
|
|
1059
|
+
request: requestOpts.request
|
|
1060
|
+
});
|
|
1061
|
+
const inlineCss = await resolveInlineCssForRequest({
|
|
1062
|
+
request: requestOpts.request,
|
|
1063
|
+
handlerInlineCss: opts.inlineCss,
|
|
1064
|
+
requestInlineCss: requestOpts.requestInlineCss
|
|
1065
|
+
});
|
|
1066
|
+
return {
|
|
1067
|
+
getBaseManifest: requestOpts.getBaseManifest,
|
|
1068
|
+
transformFn,
|
|
1069
|
+
cache: transformResolver.cache,
|
|
1070
|
+
inlineCss
|
|
1071
|
+
};
|
|
1072
|
+
};
|
|
1073
|
+
const resolveRequest = async (requestOpts, cache) => {
|
|
1074
|
+
return resolveFinalManifest({
|
|
1075
|
+
...await getRequestManifestOptions(requestOpts),
|
|
1076
|
+
finalManifestCache: cache
|
|
1077
|
+
});
|
|
1078
|
+
};
|
|
1079
|
+
return {
|
|
1080
|
+
warmup: ({ getBaseManifest: getBaseManifest2 }) => warmupFinalManifest({
|
|
1081
|
+
enabled: transformResolver.warmup,
|
|
1082
|
+
handlerDefaultInlineCss,
|
|
1083
|
+
cache: transformResolver.cache,
|
|
1084
|
+
finalManifestCache,
|
|
1085
|
+
getBaseManifest: getBaseManifest2,
|
|
1086
|
+
getTransformFn: () => transformResolver.getTransformFn({ warmup: true }),
|
|
1087
|
+
onError: transformResolver.clearCachedCreateTransform
|
|
1088
|
+
}),
|
|
1089
|
+
resolveCached: (requestOpts) => resolveRequest(requestOpts, finalManifestCache),
|
|
1090
|
+
resolveUncached: (requestOpts) => resolveRequest(requestOpts, void 0)
|
|
741
1091
|
};
|
|
742
|
-
return { routes };
|
|
743
1092
|
}
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
}
|
|
747
|
-
|
|
1093
|
+
function getFinalManifestCacheKey(inlineCss) {
|
|
1094
|
+
return inlineCss ? "inline-css" : "linked-css";
|
|
1095
|
+
}
|
|
1096
|
+
function cacheFinalManifestPromise(cachedFinalManifestPromises, cacheKey, promise) {
|
|
1097
|
+
const cachedFinalManifestPromise = promise.catch((error) => {
|
|
1098
|
+
if (cachedFinalManifestPromises.get(cacheKey) === cachedFinalManifestPromise) cachedFinalManifestPromises.delete(cacheKey);
|
|
1099
|
+
throw error;
|
|
1100
|
+
});
|
|
1101
|
+
cachedFinalManifestPromises.set(cacheKey, cachedFinalManifestPromise);
|
|
1102
|
+
return cachedFinalManifestPromise;
|
|
1103
|
+
}
|
|
1104
|
+
function getOrCreateCachedFinalManifestPromise(cachedFinalManifestPromises, cacheKey, computeFinalManifest) {
|
|
1105
|
+
const cachedFinalManifestPromise = cachedFinalManifestPromises.get(cacheKey);
|
|
1106
|
+
if (cachedFinalManifestPromise) return cachedFinalManifestPromise;
|
|
1107
|
+
return cacheFinalManifestPromise(cachedFinalManifestPromises, cacheKey, Promise.resolve().then(computeFinalManifest));
|
|
1108
|
+
}
|
|
1109
|
+
async function buildFinalManifest(opts) {
|
|
1110
|
+
return opts.transformFn ? await transformManifestAssets(opts.base, opts.transformFn, { inlineCss: opts.inlineCss }) : buildManifest(opts.base, { inlineCss: opts.inlineCss });
|
|
1111
|
+
}
|
|
1112
|
+
async function resolveFinalManifest(opts) {
|
|
1113
|
+
const computeFinalManifest = async () => {
|
|
1114
|
+
return buildFinalManifest({
|
|
1115
|
+
base: await opts.getBaseManifest(),
|
|
1116
|
+
transformFn: opts.transformFn,
|
|
1117
|
+
inlineCss: opts.inlineCss
|
|
1118
|
+
});
|
|
1119
|
+
};
|
|
1120
|
+
if (opts.finalManifestCache && (!opts.transformFn || opts.cache)) return getOrCreateCachedFinalManifestPromise(opts.finalManifestCache, getFinalManifestCacheKey(opts.inlineCss), computeFinalManifest);
|
|
1121
|
+
return computeFinalManifest();
|
|
1122
|
+
}
|
|
1123
|
+
function warmupFinalManifest(opts) {
|
|
1124
|
+
if (!opts.enabled || opts.handlerDefaultInlineCss === void 0 || !opts.cache) return;
|
|
1125
|
+
const inlineCss = opts.handlerDefaultInlineCss;
|
|
1126
|
+
const warmupPromise = getOrCreateCachedFinalManifestPromise(opts.finalManifestCache, getFinalManifestCacheKey(inlineCss), async () => {
|
|
1127
|
+
const [base, transformFn] = await Promise.all([opts.getBaseManifest(), opts.getTransformFn()]);
|
|
1128
|
+
return buildFinalManifest({
|
|
1129
|
+
base,
|
|
1130
|
+
transformFn,
|
|
1131
|
+
inlineCss
|
|
1132
|
+
});
|
|
1133
|
+
});
|
|
1134
|
+
if (opts.onError) warmupPromise.catch(opts.onError);
|
|
1135
|
+
return warmupPromise;
|
|
1136
|
+
}
|
|
1137
|
+
var ServerFunctionSerializationAdapter = createSerializationAdapter({
|
|
748
1138
|
key: "$TSS/serverfn",
|
|
749
1139
|
test: (v) => {
|
|
750
1140
|
if (typeof v !== "function") return false;
|
|
@@ -754,63 +1144,44 @@ const ServerFunctionSerializationAdapter = createSerializationAdapter({
|
|
|
754
1144
|
toSerializable: ({ serverFnMeta }) => ({ functionId: serverFnMeta.id }),
|
|
755
1145
|
fromSerializable: ({ functionId }) => {
|
|
756
1146
|
const fn = async (opts, signal) => {
|
|
757
|
-
|
|
758
|
-
const result = await serverFn(opts ?? {}, signal);
|
|
759
|
-
return result.result;
|
|
1147
|
+
return (await (await getServerFnById(functionId))(opts ?? {}, signal)).result;
|
|
760
1148
|
};
|
|
761
1149
|
return fn;
|
|
762
1150
|
}
|
|
763
1151
|
});
|
|
764
1152
|
function getStartResponseHeaders(opts) {
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
let entriesPromise;
|
|
776
|
-
let baseManifestPromise;
|
|
777
|
-
let cachedFinalManifestPromise;
|
|
1153
|
+
return mergeHeaders({ "Content-Type": "text/html; charset=utf-8" }, ...opts.router.stores.matches.get().map((match) => {
|
|
1154
|
+
return match.headers;
|
|
1155
|
+
}));
|
|
1156
|
+
}
|
|
1157
|
+
var entriesPromise;
|
|
1158
|
+
var defaultCsrfMiddleware = createCsrfMiddleware({ filter: (ctx) => ctx.handlerType === "serverFn" });
|
|
1159
|
+
var getCachedBaseManifest = createCachedBaseManifestLoader(() => getStartManifest());
|
|
1160
|
+
var getProdBaseManifest = () => getCachedBaseManifest();
|
|
1161
|
+
var getBaseManifest = getProdBaseManifest;
|
|
1162
|
+
var createEarlyHintsForRequest = createEarlyHintsCollector;
|
|
778
1163
|
async function loadEntries() {
|
|
779
|
-
const routerEntry = await
|
|
780
|
-
|
|
781
|
-
|
|
1164
|
+
const [routerEntry, startEntry, pluginAdapters] = await Promise.all([
|
|
1165
|
+
import("./router-D-PAN8IK.mjs").then((n) => n.V),
|
|
1166
|
+
import("./start-HYkvq4Ni.mjs"),
|
|
1167
|
+
import("./empty-plugin-adapters-BFgPZ6_d.mjs")
|
|
1168
|
+
]);
|
|
1169
|
+
return {
|
|
1170
|
+
routerEntry,
|
|
1171
|
+
startEntry,
|
|
1172
|
+
pluginAdapters
|
|
1173
|
+
};
|
|
782
1174
|
}
|
|
783
1175
|
function getEntries() {
|
|
784
|
-
if (!entriesPromise)
|
|
785
|
-
entriesPromise = loadEntries();
|
|
786
|
-
}
|
|
1176
|
+
if (!entriesPromise) entriesPromise = loadEntries();
|
|
787
1177
|
return entriesPromise;
|
|
788
1178
|
}
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
async function resolveManifest(matchedRoutes, transformFn, cache) {
|
|
796
|
-
const base = await getBaseManifest();
|
|
797
|
-
const computeFinalManifest = async () => {
|
|
798
|
-
return transformFn ? await transformManifestUrls(base, transformFn, { clone: !cache }) : buildManifestWithClientEntry(base);
|
|
799
|
-
};
|
|
800
|
-
if (!transformFn || cache) {
|
|
801
|
-
if (!cachedFinalManifestPromise) {
|
|
802
|
-
cachedFinalManifestPromise = computeFinalManifest();
|
|
803
|
-
}
|
|
804
|
-
return cachedFinalManifestPromise;
|
|
805
|
-
}
|
|
806
|
-
return computeFinalManifest();
|
|
807
|
-
}
|
|
808
|
-
const ROUTER_BASEPATH = "/";
|
|
809
|
-
const SERVER_FN_BASE = "/_serverFn/";
|
|
810
|
-
const IS_PRERENDERING = process.env.TSS_PRERENDERING === "true";
|
|
811
|
-
const IS_SHELL_ENV = process.env.TSS_SHELL === "true";
|
|
812
|
-
const ERR_NO_RESPONSE = "Internal Server Error";
|
|
813
|
-
const ERR_NO_DEFER = "Internal Server Error";
|
|
1179
|
+
var ROUTER_BASEPATH = "/";
|
|
1180
|
+
var SERVER_FN_BASE = "/_serverFn/";
|
|
1181
|
+
var IS_PRERENDERING = process.env.TSS_PRERENDERING === "true";
|
|
1182
|
+
var IS_SHELL_ENV = process.env.TSS_SHELL === "true";
|
|
1183
|
+
var ERR_NO_RESPONSE = "Internal Server Error";
|
|
1184
|
+
var ERR_NO_DEFER = "Internal Server Error";
|
|
814
1185
|
function throwRouteHandlerError() {
|
|
815
1186
|
throw new Error(ERR_NO_RESPONSE);
|
|
816
1187
|
}
|
|
@@ -821,316 +1192,267 @@ function isSpecialResponse(value) {
|
|
|
821
1192
|
return value instanceof Response || isRedirect(value);
|
|
822
1193
|
}
|
|
823
1194
|
function handleCtxResult(result) {
|
|
824
|
-
if (isSpecialResponse(result)) {
|
|
825
|
-
return { response: result };
|
|
826
|
-
}
|
|
1195
|
+
if (isSsrResponse(result) || isSpecialResponse(result)) return { response: result };
|
|
827
1196
|
return result;
|
|
828
1197
|
}
|
|
829
|
-
function executeMiddleware(middlewares, ctx) {
|
|
1198
|
+
async function executeMiddleware(middlewares, ctx) {
|
|
830
1199
|
let index = -1;
|
|
1200
|
+
let streamResponse;
|
|
1201
|
+
const setResponse = (response) => {
|
|
1202
|
+
if (isSsrResponse(response)) {
|
|
1203
|
+
if (response.serverSsrCleanup === "stream") streamResponse = response;
|
|
1204
|
+
ctx.response = response.response;
|
|
1205
|
+
return;
|
|
1206
|
+
}
|
|
1207
|
+
ctx.response = response;
|
|
1208
|
+
};
|
|
1209
|
+
const disposeStreamResponse = async (reason) => {
|
|
1210
|
+
const response = streamResponse;
|
|
1211
|
+
if (!response) return;
|
|
1212
|
+
streamResponse = void 0;
|
|
1213
|
+
const currentResponse = ctx.response;
|
|
1214
|
+
if (currentResponse === response.response || currentResponse instanceof Response && response.response.body !== null && currentResponse.body === response.response.body) ctx.response = void 0;
|
|
1215
|
+
await response.dispose(reason);
|
|
1216
|
+
};
|
|
1217
|
+
const getFinalResponse = async () => {
|
|
1218
|
+
const response = ctx.response;
|
|
1219
|
+
if (!response) throwRouteHandlerError();
|
|
1220
|
+
if (!streamResponse) return response;
|
|
1221
|
+
if (response === streamResponse.response) return streamResponse;
|
|
1222
|
+
if (streamResponse.response.body !== null && response.body === streamResponse.response.body) return {
|
|
1223
|
+
...streamResponse,
|
|
1224
|
+
response
|
|
1225
|
+
};
|
|
1226
|
+
await disposeStreamResponse("middleware response replaced");
|
|
1227
|
+
return response;
|
|
1228
|
+
};
|
|
831
1229
|
const next = async (nextCtx) => {
|
|
832
1230
|
if (nextCtx) {
|
|
833
|
-
if (nextCtx.context)
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
for (const key of Object.keys(nextCtx)) {
|
|
837
|
-
if (key !== "context") {
|
|
838
|
-
ctx[key] = nextCtx[key];
|
|
839
|
-
}
|
|
840
|
-
}
|
|
1231
|
+
if (nextCtx.context) ctx.context = safeObjectMerge(ctx.context, nextCtx.context);
|
|
1232
|
+
for (const key of Object.keys(nextCtx)) if (key === "response") setResponse(nextCtx.response);
|
|
1233
|
+
else if (key !== "context") ctx[key] = nextCtx[key];
|
|
841
1234
|
}
|
|
842
1235
|
index++;
|
|
843
1236
|
const middleware = middlewares[index];
|
|
844
1237
|
if (!middleware) return ctx;
|
|
845
1238
|
let result;
|
|
846
1239
|
try {
|
|
847
|
-
result = await middleware({
|
|
1240
|
+
result = await middleware({
|
|
1241
|
+
...ctx,
|
|
1242
|
+
next
|
|
1243
|
+
});
|
|
848
1244
|
} catch (err) {
|
|
849
1245
|
if (isSpecialResponse(err)) {
|
|
850
|
-
|
|
1246
|
+
setResponse(err);
|
|
851
1247
|
return ctx;
|
|
852
1248
|
}
|
|
1249
|
+
await disposeStreamResponse("middleware error");
|
|
853
1250
|
throw err;
|
|
854
1251
|
}
|
|
855
1252
|
const normalized = handleCtxResult(result);
|
|
856
1253
|
if (normalized) {
|
|
857
|
-
if (normalized.response !== void 0)
|
|
858
|
-
|
|
859
|
-
}
|
|
860
|
-
if (normalized.context) {
|
|
861
|
-
ctx.context = safeObjectMerge(ctx.context, normalized.context);
|
|
862
|
-
}
|
|
1254
|
+
if (normalized.response !== void 0) setResponse(normalized.response);
|
|
1255
|
+
if (normalized.context) ctx.context = safeObjectMerge(ctx.context, normalized.context);
|
|
863
1256
|
}
|
|
864
1257
|
return ctx;
|
|
865
1258
|
};
|
|
866
|
-
|
|
1259
|
+
await next();
|
|
1260
|
+
return {
|
|
1261
|
+
ctx,
|
|
1262
|
+
response: await getFinalResponse()
|
|
1263
|
+
};
|
|
867
1264
|
}
|
|
868
1265
|
function handlerToMiddleware(handler, mayDefer = false) {
|
|
869
|
-
if (mayDefer)
|
|
870
|
-
return handler;
|
|
871
|
-
}
|
|
1266
|
+
if (mayDefer) return handler;
|
|
872
1267
|
return async (ctx) => {
|
|
873
|
-
const response = await handler({
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
}
|
|
1268
|
+
const response = await handler({
|
|
1269
|
+
...ctx,
|
|
1270
|
+
next: throwIfMayNotDefer
|
|
1271
|
+
});
|
|
1272
|
+
if (!response) throwRouteHandlerError();
|
|
877
1273
|
return response;
|
|
878
1274
|
};
|
|
879
1275
|
}
|
|
880
1276
|
function createStartHandler(cbOrOptions) {
|
|
1277
|
+
const handlerOptions = typeof cbOrOptions === "function" ? {} : cbOrOptions;
|
|
881
1278
|
const cb = typeof cbOrOptions === "function" ? cbOrOptions : cbOrOptions.handler;
|
|
882
|
-
const
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
const
|
|
886
|
-
|
|
887
|
-
const getTransformFn = async (opts) => {
|
|
888
|
-
if (!resolvedTransformConfig) return void 0;
|
|
889
|
-
if (resolvedTransformConfig.type === "createTransform") {
|
|
890
|
-
if (cache) {
|
|
891
|
-
if (!cachedCreateTransformPromise) {
|
|
892
|
-
cachedCreateTransformPromise = Promise.resolve(
|
|
893
|
-
resolvedTransformConfig.createTransform(opts)
|
|
894
|
-
);
|
|
895
|
-
}
|
|
896
|
-
return cachedCreateTransformPromise;
|
|
897
|
-
}
|
|
898
|
-
return resolvedTransformConfig.createTransform(opts);
|
|
899
|
-
}
|
|
900
|
-
return resolvedTransformConfig.transformFn;
|
|
901
|
-
};
|
|
902
|
-
if (warmupTransformManifest && cache && true && !cachedFinalManifestPromise) {
|
|
903
|
-
const warmupPromise = (async () => {
|
|
904
|
-
const base = await getBaseManifest();
|
|
905
|
-
const transformFn = await getTransformFn({ warmup: true });
|
|
906
|
-
return transformFn ? await transformManifestUrls(base, transformFn, { clone: false }) : buildManifestWithClientEntry(base);
|
|
907
|
-
})();
|
|
908
|
-
cachedFinalManifestPromise = warmupPromise;
|
|
909
|
-
warmupPromise.catch(() => {
|
|
910
|
-
if (cachedFinalManifestPromise === warmupPromise) {
|
|
911
|
-
cachedFinalManifestPromise = void 0;
|
|
912
|
-
}
|
|
913
|
-
cachedCreateTransformPromise = void 0;
|
|
914
|
-
});
|
|
915
|
-
}
|
|
1279
|
+
const finalManifestResolver = createFinalManifestResolver({
|
|
1280
|
+
...handlerOptions
|
|
1281
|
+
});
|
|
1282
|
+
const resolveManifestForRequest = finalManifestResolver.resolveCached;
|
|
1283
|
+
finalManifestResolver.warmup({ getBaseManifest: () => getBaseManifest() });
|
|
916
1284
|
const startRequestResolver = async (request, requestOpts) => {
|
|
917
1285
|
let router = null;
|
|
918
|
-
let
|
|
1286
|
+
let responseOwnsCleanup = false;
|
|
919
1287
|
try {
|
|
920
1288
|
const { url, handledProtocolRelativeURL } = getNormalizedURL(request.url);
|
|
921
1289
|
const href = url.pathname + url.search + url.hash;
|
|
922
1290
|
const origin = getOrigin(request);
|
|
923
|
-
if (handledProtocolRelativeURL)
|
|
924
|
-
return Response.redirect(url, 308);
|
|
925
|
-
}
|
|
1291
|
+
if (handledProtocolRelativeURL) return Response.redirect(url, 308);
|
|
926
1292
|
const entries = await getEntries();
|
|
1293
|
+
const hasStartInstance = !!entries.startEntry.startInstance;
|
|
927
1294
|
const startOptions = await entries.startEntry.startInstance?.getOptions() || {};
|
|
1295
|
+
const { hasPluginAdapters, pluginSerializationAdapters } = entries.pluginAdapters;
|
|
928
1296
|
const serializationAdapters = [
|
|
929
1297
|
...startOptions.serializationAdapters || [],
|
|
1298
|
+
...hasPluginAdapters ? pluginSerializationAdapters : [],
|
|
930
1299
|
ServerFunctionSerializationAdapter
|
|
931
1300
|
];
|
|
932
1301
|
const requestStartOptions = {
|
|
933
1302
|
...startOptions,
|
|
1303
|
+
requestMiddleware: hasStartInstance ? startOptions.requestMiddleware : [defaultCsrfMiddleware],
|
|
934
1304
|
serializationAdapters
|
|
935
1305
|
};
|
|
936
|
-
const flattenedRequestMiddlewares =
|
|
937
|
-
const executedRequestMiddlewares = new Set(
|
|
938
|
-
flattenedRequestMiddlewares
|
|
939
|
-
);
|
|
1306
|
+
const flattenedRequestMiddlewares = requestStartOptions.requestMiddleware ? flattenMiddlewares(requestStartOptions.requestMiddleware) : [];
|
|
1307
|
+
const executedRequestMiddlewares = new Set(flattenedRequestMiddlewares);
|
|
940
1308
|
const getRouter = async () => {
|
|
941
1309
|
if (router) return router;
|
|
942
1310
|
router = await entries.routerEntry.getRouter();
|
|
943
1311
|
let isShell = IS_SHELL_ENV;
|
|
944
|
-
if (IS_PRERENDERING && !isShell)
|
|
945
|
-
|
|
946
|
-
}
|
|
947
|
-
const history = createMemoryHistory({
|
|
948
|
-
initialEntries: [href]
|
|
949
|
-
});
|
|
1312
|
+
if (IS_PRERENDERING && !isShell) isShell = request.headers.get(HEADERS.TSS_SHELL) === "true";
|
|
1313
|
+
const history = createMemoryHistory({ initialEntries: [href] });
|
|
950
1314
|
router.update({
|
|
951
1315
|
history,
|
|
952
1316
|
isShell,
|
|
953
1317
|
isPrerendering: IS_PRERENDERING,
|
|
954
1318
|
origin: router.options.origin ?? origin,
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
serializationAdapters: [
|
|
958
|
-
...requestStartOptions.serializationAdapters,
|
|
959
|
-
...router.options.serializationAdapters || []
|
|
960
|
-
]
|
|
961
|
-
},
|
|
1319
|
+
defaultSsr: requestStartOptions.defaultSsr,
|
|
1320
|
+
serializationAdapters: [...requestStartOptions.serializationAdapters, ...router.options.serializationAdapters || []],
|
|
962
1321
|
basepath: ROUTER_BASEPATH
|
|
963
1322
|
});
|
|
964
1323
|
return router;
|
|
965
1324
|
};
|
|
966
1325
|
if (SERVER_FN_BASE && url.pathname.startsWith(SERVER_FN_BASE)) {
|
|
1326
|
+
if (false) ;
|
|
967
1327
|
const serverFnId = url.pathname.slice(SERVER_FN_BASE.length).split("/")[0];
|
|
968
|
-
if (!serverFnId)
|
|
969
|
-
throw new Error("Invalid server action param for serverFnId");
|
|
970
|
-
}
|
|
1328
|
+
if (!serverFnId) throw new Error("Invalid server action param for serverFnId");
|
|
971
1329
|
const serverFnHandler = async ({ context }) => {
|
|
972
|
-
return runWithStartContext(
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
})
|
|
985
|
-
);
|
|
1330
|
+
return runWithStartContext({
|
|
1331
|
+
getRouter,
|
|
1332
|
+
startOptions: requestStartOptions,
|
|
1333
|
+
contextAfterGlobalMiddlewares: context,
|
|
1334
|
+
request,
|
|
1335
|
+
executedRequestMiddlewares,
|
|
1336
|
+
handlerType: "serverFn"
|
|
1337
|
+
}, () => handleServerAction({
|
|
1338
|
+
request,
|
|
1339
|
+
context: requestOpts?.context,
|
|
1340
|
+
serverFnId
|
|
1341
|
+
}));
|
|
986
1342
|
};
|
|
987
|
-
const
|
|
988
|
-
(d) => d.options.server
|
|
989
|
-
);
|
|
990
|
-
const ctx2 = await executeMiddleware([...middlewares2, serverFnHandler], {
|
|
1343
|
+
const { response: middlewareResponse2 } = await executeMiddleware([...flattenedRequestMiddlewares.map((d) => d.options.server), serverFnHandler], {
|
|
991
1344
|
request,
|
|
992
1345
|
pathname: url.pathname,
|
|
1346
|
+
handlerType: "serverFn",
|
|
993
1347
|
context: createNullProtoObject(requestOpts?.context)
|
|
994
1348
|
});
|
|
995
|
-
|
|
1349
|
+
const result = await handleRedirectResponse(middlewareResponse2, request, getRouter);
|
|
1350
|
+
responseOwnsCleanup = result.serverSsrCleanup === "stream";
|
|
1351
|
+
return result.response;
|
|
996
1352
|
}
|
|
997
1353
|
const executeRouter = async (serverContext, matchedRoutes) => {
|
|
998
|
-
const
|
|
999
|
-
|
|
1000
|
-
const
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
matchedRoutes
|
|
1012
|
-
|
|
1013
|
-
cache
|
|
1014
|
-
);
|
|
1354
|
+
const acceptParts = (request.headers.get("Accept") || "*/*").split(",");
|
|
1355
|
+
if (!["*/*", "text/html"].some((mimeType) => acceptParts.some((part) => part.trim().startsWith(mimeType)))) return normalizeSsrResponse(Response.json({ error: "Only HTML requests are supported here" }, { status: 500 }));
|
|
1356
|
+
const manifest2 = await resolveManifestForRequest({
|
|
1357
|
+
request,
|
|
1358
|
+
requestInlineCss: requestOpts?.inlineCss,
|
|
1359
|
+
getBaseManifest: () => getBaseManifest(matchedRoutes)
|
|
1360
|
+
});
|
|
1361
|
+
const earlyHints = createEarlyHintsForRequest({
|
|
1362
|
+
onEarlyHints: requestOpts?.onEarlyHints,
|
|
1363
|
+
responseLinkHeader: requestOpts?.responseLinkHeader
|
|
1364
|
+
});
|
|
1365
|
+
earlyHints?.collectStatic({
|
|
1366
|
+
manifest: manifest2,
|
|
1367
|
+
matchedRoutes
|
|
1368
|
+
});
|
|
1015
1369
|
const routerInstance = await getRouter();
|
|
1016
1370
|
attachRouterServerSsrUtils({
|
|
1017
1371
|
router: routerInstance,
|
|
1018
|
-
manifest: manifest2
|
|
1372
|
+
manifest: manifest2,
|
|
1373
|
+
getRequestAssets: () => getStartContext({ throwIfNotFound: false })?.requestAssets
|
|
1019
1374
|
});
|
|
1020
|
-
routerInstance.
|
|
1375
|
+
routerInstance.options.additionalContext = { serverContext };
|
|
1021
1376
|
await routerInstance.load();
|
|
1022
|
-
if (routerInstance.state.redirect)
|
|
1023
|
-
|
|
1024
|
-
}
|
|
1025
|
-
await routerInstance.serverSsr.dehydrate();
|
|
1026
|
-
const responseHeaders = getStartResponseHeaders({
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
cbWillCleanup = true;
|
|
1030
|
-
return cb({
|
|
1377
|
+
if (routerInstance.state.redirect) return normalizeSsrResponse(routerInstance.state.redirect);
|
|
1378
|
+
earlyHints?.collectDynamic(routerInstance.stores.matches.get());
|
|
1379
|
+
const ctx = getStartContext({ throwIfNotFound: false });
|
|
1380
|
+
await routerInstance.serverSsr.dehydrate({ requestAssets: ctx?.requestAssets });
|
|
1381
|
+
const responseHeaders = getStartResponseHeaders({ router: routerInstance });
|
|
1382
|
+
earlyHints?.appendResponseHeaders(responseHeaders);
|
|
1383
|
+
return normalizeSsrResponse(await cb({
|
|
1031
1384
|
request,
|
|
1032
1385
|
router: routerInstance,
|
|
1033
1386
|
responseHeaders
|
|
1034
|
-
});
|
|
1387
|
+
}));
|
|
1035
1388
|
};
|
|
1036
1389
|
const requestHandlerMiddleware = async ({ context }) => {
|
|
1037
|
-
return runWithStartContext(
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
return err;
|
|
1058
|
-
}
|
|
1059
|
-
throw err;
|
|
1060
|
-
}
|
|
1390
|
+
return runWithStartContext({
|
|
1391
|
+
getRouter,
|
|
1392
|
+
startOptions: requestStartOptions,
|
|
1393
|
+
contextAfterGlobalMiddlewares: context,
|
|
1394
|
+
request,
|
|
1395
|
+
executedRequestMiddlewares,
|
|
1396
|
+
handlerType: "router"
|
|
1397
|
+
}, async () => {
|
|
1398
|
+
try {
|
|
1399
|
+
return await handleServerRoutes({
|
|
1400
|
+
getRouter,
|
|
1401
|
+
request,
|
|
1402
|
+
url,
|
|
1403
|
+
executeRouter,
|
|
1404
|
+
context,
|
|
1405
|
+
executedRequestMiddlewares
|
|
1406
|
+
});
|
|
1407
|
+
} catch (err) {
|
|
1408
|
+
if (err instanceof Response) return err;
|
|
1409
|
+
throw err;
|
|
1061
1410
|
}
|
|
1062
|
-
);
|
|
1411
|
+
});
|
|
1063
1412
|
};
|
|
1064
|
-
const
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
}
|
|
1074
|
-
);
|
|
1075
|
-
return handleRedirectResponse(ctx.response, request, getRouter);
|
|
1413
|
+
const { response: middlewareResponse } = await executeMiddleware([...flattenedRequestMiddlewares.map((d) => d.options.server), requestHandlerMiddleware], {
|
|
1414
|
+
request,
|
|
1415
|
+
pathname: url.pathname,
|
|
1416
|
+
handlerType: "router",
|
|
1417
|
+
context: createNullProtoObject(requestOpts?.context)
|
|
1418
|
+
});
|
|
1419
|
+
const response = await handleRedirectResponse(middlewareResponse, request, getRouter);
|
|
1420
|
+
responseOwnsCleanup = response.serverSsrCleanup === "stream";
|
|
1421
|
+
return response.response;
|
|
1076
1422
|
} finally {
|
|
1077
|
-
if (router && !
|
|
1078
|
-
router.serverSsr?.cleanup();
|
|
1079
|
-
}
|
|
1423
|
+
if (router?.serverSsr && !responseOwnsCleanup) router.serverSsr.cleanup();
|
|
1080
1424
|
router = null;
|
|
1081
1425
|
}
|
|
1082
1426
|
};
|
|
1083
1427
|
return requestHandler(startRequestResolver);
|
|
1084
1428
|
}
|
|
1085
1429
|
async function handleRedirectResponse(response, request, getRouter) {
|
|
1086
|
-
|
|
1087
|
-
|
|
1430
|
+
const ssrResponse = normalizeSsrResponse(response);
|
|
1431
|
+
if (!isRedirect(ssrResponse.response)) return ssrResponse;
|
|
1432
|
+
if (isResolvedRedirect(ssrResponse.response)) {
|
|
1433
|
+
if (request.headers.get("x-tsr-serverFn") === "true") return replaceSsrResponse(ssrResponse, Response.json({
|
|
1434
|
+
...ssrResponse.response.options,
|
|
1435
|
+
isSerializedRedirect: true
|
|
1436
|
+
}, { headers: ssrResponse.response.headers }), "redirect response replaced");
|
|
1437
|
+
return ssrResponse;
|
|
1088
1438
|
}
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
);
|
|
1103
|
-
}
|
|
1104
|
-
if (["params", "search", "hash"].some(
|
|
1105
|
-
(d) => typeof opts[d] === "function"
|
|
1106
|
-
)) {
|
|
1107
|
-
throw new Error(
|
|
1108
|
-
`Server side redirects must use static search, params, and hash values and do not support functional values. Received functional values for: ${Object.keys(
|
|
1109
|
-
opts
|
|
1110
|
-
).filter((d) => typeof opts[d] === "function").map((d) => `"${d}"`).join(", ")}`
|
|
1111
|
-
);
|
|
1112
|
-
}
|
|
1113
|
-
const router = await getRouter();
|
|
1114
|
-
const redirect = router.resolveRedirect(response);
|
|
1115
|
-
if (request.headers.get("x-tsr-serverFn") === "true") {
|
|
1116
|
-
return Response.json(
|
|
1117
|
-
{ ...response.options, isSerializedRedirect: true },
|
|
1118
|
-
{ headers: response.headers }
|
|
1119
|
-
);
|
|
1120
|
-
}
|
|
1121
|
-
return redirect;
|
|
1439
|
+
const opts = ssrResponse.response.options;
|
|
1440
|
+
if (opts.to && typeof opts.to === "string" && !opts.to.startsWith("/")) throw new Error(`Server side redirects must use absolute paths via the 'href' or 'to' options. The redirect() method's "to" property accepts an internal path only. Use the "href" property to provide an external URL. Received: ${JSON.stringify(opts)}`);
|
|
1441
|
+
if ([
|
|
1442
|
+
"params",
|
|
1443
|
+
"search",
|
|
1444
|
+
"hash"
|
|
1445
|
+
].some((d) => typeof opts[d] === "function")) throw new Error(`Server side redirects must use static search, params, and hash values and do not support functional values. Received functional values for: ${Object.keys(opts).filter((d) => typeof opts[d] === "function").map((d) => `"${d}"`).join(", ")}`);
|
|
1446
|
+
const redirect = (await getRouter()).resolveRedirect(ssrResponse.response);
|
|
1447
|
+
if (request.headers.get("x-tsr-serverFn") === "true") return replaceSsrResponse(ssrResponse, Response.json({
|
|
1448
|
+
...ssrResponse.response.options,
|
|
1449
|
+
isSerializedRedirect: true
|
|
1450
|
+
}, { headers: ssrResponse.response.headers }), "redirect response replaced");
|
|
1451
|
+
return replaceSsrResponse(ssrResponse, redirect, "redirect response replaced");
|
|
1122
1452
|
}
|
|
1123
|
-
async function handleServerRoutes({
|
|
1124
|
-
getRouter,
|
|
1125
|
-
request,
|
|
1126
|
-
url,
|
|
1127
|
-
executeRouter,
|
|
1128
|
-
context,
|
|
1129
|
-
executedRequestMiddlewares
|
|
1130
|
-
}) {
|
|
1453
|
+
async function handleServerRoutes({ getRouter, request, url, executeRouter, context, executedRequestMiddlewares }) {
|
|
1131
1454
|
const router = await getRouter();
|
|
1132
|
-
const
|
|
1133
|
-
const pathname = rewrittenUrl.pathname;
|
|
1455
|
+
const pathname = executeRewriteInput(router.rewrite, url).pathname;
|
|
1134
1456
|
const { matchedRoutes, foundRoute, routeParams } = router.getMatchedRoutes(pathname);
|
|
1135
1457
|
const isExactMatch = foundRoute && routeParams["**"] === void 0;
|
|
1136
1458
|
const routeMiddlewares = [];
|
|
@@ -1138,45 +1460,41 @@ async function handleServerRoutes({
|
|
|
1138
1460
|
const serverMiddleware = route.options.server?.middleware;
|
|
1139
1461
|
if (serverMiddleware) {
|
|
1140
1462
|
const flattened = flattenMiddlewares(serverMiddleware);
|
|
1141
|
-
for (const m of flattened)
|
|
1142
|
-
if (!executedRequestMiddlewares.has(m)) {
|
|
1143
|
-
routeMiddlewares.push(m.options.server);
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1463
|
+
for (const m of flattened) if (!executedRequestMiddlewares.has(m)) routeMiddlewares.push(m.options.server);
|
|
1146
1464
|
}
|
|
1147
1465
|
}
|
|
1148
1466
|
const server2 = foundRoute?.options.server;
|
|
1467
|
+
let isHeadFallback = false;
|
|
1149
1468
|
if (server2?.handlers && isExactMatch) {
|
|
1150
1469
|
const handlers = typeof server2.handlers === "function" ? server2.handlers({ createHandlers: (d) => d }) : server2.handlers;
|
|
1151
1470
|
const requestMethod = request.method.toUpperCase();
|
|
1152
|
-
const handler = handlers[requestMethod] ?? handlers["ANY"];
|
|
1471
|
+
const handler = requestMethod === "HEAD" ? handlers["HEAD"] ?? handlers["GET"] ?? handlers["ANY"] : handlers[requestMethod] ?? handlers["ANY"];
|
|
1472
|
+
isHeadFallback = requestMethod === "HEAD" && handler !== void 0 && !handlers["HEAD"];
|
|
1153
1473
|
if (handler) {
|
|
1154
1474
|
const mayDefer = !!foundRoute.options.component;
|
|
1155
|
-
if (typeof handler === "function")
|
|
1156
|
-
|
|
1157
|
-
} else {
|
|
1475
|
+
if (typeof handler === "function") routeMiddlewares.push(handlerToMiddleware(handler, mayDefer));
|
|
1476
|
+
else {
|
|
1158
1477
|
if (handler.middleware?.length) {
|
|
1159
1478
|
const handlerMiddlewares = flattenMiddlewares(handler.middleware);
|
|
1160
|
-
for (const m of handlerMiddlewares)
|
|
1161
|
-
routeMiddlewares.push(m.options.server);
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
if (handler.handler) {
|
|
1165
|
-
routeMiddlewares.push(handlerToMiddleware(handler.handler, mayDefer));
|
|
1479
|
+
for (const m of handlerMiddlewares) routeMiddlewares.push(m.options.server);
|
|
1166
1480
|
}
|
|
1481
|
+
if (handler.handler) routeMiddlewares.push(handlerToMiddleware(handler.handler, mayDefer));
|
|
1167
1482
|
}
|
|
1168
1483
|
}
|
|
1169
1484
|
}
|
|
1170
|
-
routeMiddlewares.push(
|
|
1171
|
-
|
|
1172
|
-
);
|
|
1173
|
-
const ctx = await executeMiddleware(routeMiddlewares, {
|
|
1485
|
+
routeMiddlewares.push(((ctx2) => executeRouter(ctx2.context, matchedRoutes)));
|
|
1486
|
+
const { ctx, response } = await executeMiddleware(routeMiddlewares, {
|
|
1174
1487
|
request,
|
|
1175
1488
|
context,
|
|
1176
1489
|
params: routeParams,
|
|
1177
|
-
pathname
|
|
1490
|
+
pathname,
|
|
1491
|
+
handlerType: "router"
|
|
1178
1492
|
});
|
|
1179
|
-
|
|
1493
|
+
if (isHeadFallback) {
|
|
1494
|
+
if (!ctx.response) throwRouteHandlerError();
|
|
1495
|
+
return stripSsrResponseBody(await handleRedirectResponse(response, request, getRouter), "HEAD body stripped");
|
|
1496
|
+
}
|
|
1497
|
+
return normalizeSsrResponse(response);
|
|
1180
1498
|
}
|
|
1181
1499
|
const fetch = createStartHandler(defaultStreamHandler);
|
|
1182
1500
|
function createServerEntry(entry) {
|