@tanstack/start-server-core 1.121.20 → 1.121.23
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/dist/cjs/createRequestHandler.cjs +50 -0
- package/dist/cjs/createRequestHandler.cjs.map +1 -0
- package/dist/cjs/createRequestHandler.d.cts +8 -0
- package/dist/cjs/createStartHandler.cjs +313 -0
- package/dist/cjs/createStartHandler.cjs.map +1 -0
- package/dist/cjs/createStartHandler.d.cts +7 -0
- package/dist/cjs/h3.cjs +355 -0
- package/dist/cjs/h3.cjs.map +1 -0
- package/dist/cjs/h3.d.cts +109 -0
- package/dist/cjs/handlerCallback.cjs +7 -0
- package/dist/cjs/handlerCallback.cjs.map +1 -0
- package/dist/cjs/handlerCallback.d.cts +9 -0
- package/dist/cjs/index.cjs +244 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +12 -0
- package/dist/cjs/loadVirtualModule.cjs +39 -0
- package/dist/cjs/loadVirtualModule.cjs.map +1 -0
- package/dist/cjs/loadVirtualModule.d.cts +6 -0
- package/dist/cjs/router-manifest.cjs +49 -0
- package/dist/cjs/router-manifest.cjs.map +1 -0
- package/dist/cjs/router-manifest.d.cts +16 -0
- package/dist/cjs/server-functions-handler.cjs +148 -0
- package/dist/cjs/server-functions-handler.cjs.map +1 -0
- package/dist/cjs/server-functions-handler.d.cts +3 -0
- package/dist/cjs/serverRoute.cjs +102 -0
- package/dist/cjs/serverRoute.cjs.map +1 -0
- package/dist/cjs/serverRoute.d.cts +120 -0
- package/dist/cjs/ssr-server.cjs +247 -0
- package/dist/cjs/ssr-server.cjs.map +1 -0
- package/dist/cjs/ssr-server.d.cts +29 -0
- package/dist/cjs/transformStreamWithRouter.cjs +183 -0
- package/dist/cjs/transformStreamWithRouter.cjs.map +1 -0
- package/dist/cjs/transformStreamWithRouter.d.cts +6 -0
- package/dist/cjs/tsrScript.cjs +4 -0
- package/dist/cjs/tsrScript.cjs.map +1 -0
- package/dist/cjs/tsrScript.d.cts +1 -0
- package/dist/cjs/virtual-modules.cjs +9 -0
- package/dist/cjs/virtual-modules.cjs.map +1 -0
- package/dist/cjs/virtual-modules.d.cts +10 -0
- package/dist/esm/createRequestHandler.d.ts +8 -0
- package/dist/esm/createRequestHandler.js +50 -0
- package/dist/esm/createRequestHandler.js.map +1 -0
- package/dist/esm/createStartHandler.d.ts +7 -0
- package/dist/esm/createStartHandler.js +313 -0
- package/dist/esm/createStartHandler.js.map +1 -0
- package/dist/esm/h3.d.ts +109 -0
- package/dist/esm/h3.js +248 -0
- package/dist/esm/h3.js.map +1 -0
- package/dist/esm/handlerCallback.d.ts +9 -0
- package/dist/esm/handlerCallback.js +7 -0
- package/dist/esm/handlerCallback.js.map +1 -0
- package/dist/esm/index.d.ts +12 -0
- package/dist/esm/index.js +136 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/loadVirtualModule.d.ts +6 -0
- package/dist/esm/loadVirtualModule.js +17 -0
- package/dist/esm/loadVirtualModule.js.map +1 -0
- package/dist/esm/router-manifest.d.ts +16 -0
- package/dist/esm/router-manifest.js +49 -0
- package/dist/esm/router-manifest.js.map +1 -0
- package/dist/esm/server-functions-handler.d.ts +3 -0
- package/dist/esm/server-functions-handler.js +148 -0
- package/dist/esm/server-functions-handler.js.map +1 -0
- package/dist/esm/serverRoute.d.ts +120 -0
- package/dist/esm/serverRoute.js +102 -0
- package/dist/esm/serverRoute.js.map +1 -0
- package/dist/esm/ssr-server.d.ts +29 -0
- package/dist/esm/ssr-server.js +247 -0
- package/dist/esm/ssr-server.js.map +1 -0
- package/dist/esm/transformStreamWithRouter.d.ts +6 -0
- package/dist/esm/transformStreamWithRouter.js +183 -0
- package/dist/esm/transformStreamWithRouter.js.map +1 -0
- package/dist/esm/tsrScript.d.ts +1 -0
- package/dist/esm/tsrScript.js +5 -0
- package/dist/esm/tsrScript.js.map +1 -0
- package/dist/esm/virtual-modules.d.ts +10 -0
- package/dist/esm/virtual-modules.js +9 -0
- package/dist/esm/virtual-modules.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { transformPipeableStreamWithRouter, transformReadableStreamWithRouter } from "./transformStreamWithRouter.js";
|
|
2
|
+
import { createStartHandler } from "./createStartHandler.js";
|
|
3
|
+
import { createRequestHandler } from "./createRequestHandler.js";
|
|
4
|
+
import { defineHandlerCallback } from "./handlerCallback.js";
|
|
5
|
+
import { attachRouterServerSsrUtils, dehydrateRouter } from "./ssr-server.js";
|
|
6
|
+
import { handleServerAction } from "./server-functions-handler.js";
|
|
7
|
+
import { HTTPEventSymbol, appendCorsHeaders, appendCorsPreflightHeaders, appendHeader, appendHeaders, appendResponseHeader, appendResponseHeaders, assertMethod, clearResponseHeaders, clearSession, defaultContentType, defineEventHandler, defineMiddleware, deleteCookie, eventHandler, fetchWithEvent, getContext, getCookie, getEvent, getHeader, getHeaders, getProxyRequestHeaders, getQuery, getRequestFingerprint, getRequestHeader, getRequestHeaders, getRequestHost, getRequestIP, getRequestProtocol, getRequestURL, getRequestWebStream, getResponseHeader, getResponseHeaders, getResponseStatus, getResponseStatusText, getRouterParam, getRouterParams, getSession, getValidatedQuery, getValidatedRouterParams, getWebRequest, handleCacheHeaders, handleCors, isEvent, isMethod, isPreflightRequest, parseCookies, proxyRequest, readBody, readFormData, readMultipartFormData, readRawBody, readValidatedBody, removeResponseHeader, requestHandler, runWithEvent, sealSession, send, sendError, sendNoContent, sendProxy, sendRedirect, sendStream, sendWebResponse, setContext, setCookie, setHeader, setHeaders, setResponseHeader, setResponseHeaders, setResponseStatus, unsealSession, updateSession, useSession, writeEarlyHints } from "./h3.js";
|
|
8
|
+
import { createServerFileRoute, createServerRootRoute, createServerRoute } from "./serverRoute.js";
|
|
9
|
+
import { VIRTUAL_MODULES } from "./virtual-modules.js";
|
|
10
|
+
import { H3Error, H3Event, MIMES, callNodeListener, createApp, createAppEventHandler, createError, createEvent, createRouter, defineLazyEventHandler, defineNodeListener, defineNodeMiddleware, defineRequestMiddleware, defineResponseMiddleware, defineWebSocket, dynamicEventHandler, fromNodeMiddleware, fromPlainHandler, fromWebHandler, isCorsOriginAllowed, isError, isEventHandler, isStream, isWebResponse, lazyEventHandler, promisifyNodeListener, sanitizeStatusCode, sanitizeStatusMessage, serveStatic, splitCookiesString, toEventHandler, toNodeListener, toPlainHandler, toWebHandler, toWebRequest, useBase } from "h3";
|
|
11
|
+
export {
|
|
12
|
+
H3Error,
|
|
13
|
+
H3Event,
|
|
14
|
+
HTTPEventSymbol,
|
|
15
|
+
MIMES,
|
|
16
|
+
VIRTUAL_MODULES,
|
|
17
|
+
appendCorsHeaders,
|
|
18
|
+
appendCorsPreflightHeaders,
|
|
19
|
+
appendHeader,
|
|
20
|
+
appendHeaders,
|
|
21
|
+
appendResponseHeader,
|
|
22
|
+
appendResponseHeaders,
|
|
23
|
+
assertMethod,
|
|
24
|
+
attachRouterServerSsrUtils,
|
|
25
|
+
callNodeListener,
|
|
26
|
+
clearResponseHeaders,
|
|
27
|
+
clearSession,
|
|
28
|
+
createApp,
|
|
29
|
+
createAppEventHandler,
|
|
30
|
+
createError,
|
|
31
|
+
createEvent,
|
|
32
|
+
createRequestHandler,
|
|
33
|
+
createRouter,
|
|
34
|
+
createServerFileRoute,
|
|
35
|
+
createServerRootRoute,
|
|
36
|
+
createServerRoute,
|
|
37
|
+
createStartHandler,
|
|
38
|
+
defaultContentType,
|
|
39
|
+
defineEventHandler,
|
|
40
|
+
defineHandlerCallback,
|
|
41
|
+
defineLazyEventHandler,
|
|
42
|
+
defineMiddleware,
|
|
43
|
+
defineNodeListener,
|
|
44
|
+
defineNodeMiddleware,
|
|
45
|
+
defineRequestMiddleware,
|
|
46
|
+
defineResponseMiddleware,
|
|
47
|
+
defineWebSocket,
|
|
48
|
+
dehydrateRouter,
|
|
49
|
+
deleteCookie,
|
|
50
|
+
dynamicEventHandler,
|
|
51
|
+
eventHandler,
|
|
52
|
+
fetchWithEvent,
|
|
53
|
+
fromNodeMiddleware,
|
|
54
|
+
fromPlainHandler,
|
|
55
|
+
fromWebHandler,
|
|
56
|
+
getContext,
|
|
57
|
+
getCookie,
|
|
58
|
+
getEvent,
|
|
59
|
+
getHeader,
|
|
60
|
+
getHeaders,
|
|
61
|
+
getProxyRequestHeaders,
|
|
62
|
+
getQuery,
|
|
63
|
+
getRequestFingerprint,
|
|
64
|
+
getRequestHeader,
|
|
65
|
+
getRequestHeaders,
|
|
66
|
+
getRequestHost,
|
|
67
|
+
getRequestIP,
|
|
68
|
+
getRequestProtocol,
|
|
69
|
+
getRequestURL,
|
|
70
|
+
getRequestWebStream,
|
|
71
|
+
getResponseHeader,
|
|
72
|
+
getResponseHeaders,
|
|
73
|
+
getResponseStatus,
|
|
74
|
+
getResponseStatusText,
|
|
75
|
+
getRouterParam,
|
|
76
|
+
getRouterParams,
|
|
77
|
+
getSession,
|
|
78
|
+
getValidatedQuery,
|
|
79
|
+
getValidatedRouterParams,
|
|
80
|
+
getWebRequest,
|
|
81
|
+
handleCacheHeaders,
|
|
82
|
+
handleCors,
|
|
83
|
+
handleServerAction,
|
|
84
|
+
isCorsOriginAllowed,
|
|
85
|
+
isError,
|
|
86
|
+
isEvent,
|
|
87
|
+
isEventHandler,
|
|
88
|
+
isMethod,
|
|
89
|
+
isPreflightRequest,
|
|
90
|
+
isStream,
|
|
91
|
+
isWebResponse,
|
|
92
|
+
lazyEventHandler,
|
|
93
|
+
parseCookies,
|
|
94
|
+
promisifyNodeListener,
|
|
95
|
+
proxyRequest,
|
|
96
|
+
readBody,
|
|
97
|
+
readFormData,
|
|
98
|
+
readMultipartFormData,
|
|
99
|
+
readRawBody,
|
|
100
|
+
readValidatedBody,
|
|
101
|
+
removeResponseHeader,
|
|
102
|
+
requestHandler,
|
|
103
|
+
runWithEvent,
|
|
104
|
+
sanitizeStatusCode,
|
|
105
|
+
sanitizeStatusMessage,
|
|
106
|
+
sealSession,
|
|
107
|
+
send,
|
|
108
|
+
sendError,
|
|
109
|
+
sendNoContent,
|
|
110
|
+
sendProxy,
|
|
111
|
+
sendRedirect,
|
|
112
|
+
sendStream,
|
|
113
|
+
sendWebResponse,
|
|
114
|
+
serveStatic,
|
|
115
|
+
setContext,
|
|
116
|
+
setCookie,
|
|
117
|
+
setHeader,
|
|
118
|
+
setHeaders,
|
|
119
|
+
setResponseHeader,
|
|
120
|
+
setResponseHeaders,
|
|
121
|
+
setResponseStatus,
|
|
122
|
+
splitCookiesString,
|
|
123
|
+
toEventHandler,
|
|
124
|
+
toNodeListener,
|
|
125
|
+
toPlainHandler,
|
|
126
|
+
toWebHandler,
|
|
127
|
+
toWebRequest,
|
|
128
|
+
transformPipeableStreamWithRouter,
|
|
129
|
+
transformReadableStreamWithRouter,
|
|
130
|
+
unsealSession,
|
|
131
|
+
updateSession,
|
|
132
|
+
useBase,
|
|
133
|
+
useSession,
|
|
134
|
+
writeEarlyHints
|
|
135
|
+
};
|
|
136
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { VirtualModules } from './virtual-modules.js';
|
|
2
|
+
/**
|
|
3
|
+
* we need to explicitly enumerate all imports with string literals,
|
|
4
|
+
* otherwise vite will not pick them up during build
|
|
5
|
+
*/
|
|
6
|
+
export declare function loadVirtualModule<TId extends keyof VirtualModules>(id: TId): Promise<VirtualModules[TId]>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { VIRTUAL_MODULES } from "./virtual-modules.js";
|
|
2
|
+
async function loadVirtualModule(id) {
|
|
3
|
+
switch (id) {
|
|
4
|
+
case VIRTUAL_MODULES.routeTree:
|
|
5
|
+
return await import("tanstack-start-route-tree:v");
|
|
6
|
+
case VIRTUAL_MODULES.startManifest:
|
|
7
|
+
return await import("tanstack-start-manifest:v");
|
|
8
|
+
case VIRTUAL_MODULES.serverFnManifest:
|
|
9
|
+
return await import("tanstack-start-server-fn-manifest:v");
|
|
10
|
+
default:
|
|
11
|
+
throw new Error(`Unknown virtual module: ${id}`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
loadVirtualModule
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=loadVirtualModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadVirtualModule.js","sources":["../../src/loadVirtualModule.ts"],"sourcesContent":["import { VIRTUAL_MODULES } from './virtual-modules'\nimport type { VirtualModules } from './virtual-modules'\n\n/**\n * we need to explicitly enumerate all imports with string literals,\n * otherwise vite will not pick them up during build\n */\nexport async function loadVirtualModule<TId extends keyof VirtualModules>(\n id: TId,\n): Promise<VirtualModules[TId]> {\n switch (id) {\n case VIRTUAL_MODULES.routeTree:\n return (await import('tanstack-start-route-tree:v')) as any\n case VIRTUAL_MODULES.startManifest:\n return (await import('tanstack-start-manifest:v')) as any\n case VIRTUAL_MODULES.serverFnManifest:\n return (await import('tanstack-start-server-fn-manifest:v')) as any\n default:\n throw new Error(`Unknown virtual module: ${id}`)\n }\n}\n"],"names":[],"mappings":";AAOA,eAAsB,kBACpB,IAC8B;AAC9B,UAAQ,IAAI;AAAA,IACV,KAAK,gBAAgB;AACX,aAAA,MAAM,OAAO,6BAA6B;AAAA,IACpD,KAAK,gBAAgB;AACX,aAAA,MAAM,OAAO,2BAA2B;AAAA,IAClD,KAAK,gBAAgB;AACX,aAAA,MAAM,OAAO,qCAAqC;AAAA,IAC5D;AACE,YAAM,IAAI,MAAM,2BAA2B,EAAE,EAAE;AAAA,EAAA;AAErD;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Returns the router manifest that should be sent to the client.
|
|
3
|
+
* This includes only the assets and preloads for the current route and any
|
|
4
|
+
* special assets that are needed for the client. It does not include relationships
|
|
5
|
+
* between routes or any other data that is not needed for the client.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getStartManifest(opts: {
|
|
8
|
+
basePath: string;
|
|
9
|
+
}): Promise<{
|
|
10
|
+
routes: {
|
|
11
|
+
[k: string]: {
|
|
12
|
+
preloads: string[] | undefined;
|
|
13
|
+
assets: import('@tanstack/router-core').RouterManagedTag[] | undefined;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { rootRouteId, joinPaths } from "@tanstack/router-core";
|
|
2
|
+
import { VIRTUAL_MODULES } from "./virtual-modules.js";
|
|
3
|
+
import { loadVirtualModule } from "./loadVirtualModule.js";
|
|
4
|
+
async function getStartManifest(opts) {
|
|
5
|
+
const { tsrStartManifest } = await loadVirtualModule(
|
|
6
|
+
VIRTUAL_MODULES.startManifest
|
|
7
|
+
);
|
|
8
|
+
const startManifest = tsrStartManifest();
|
|
9
|
+
const rootRoute = startManifest.routes[rootRouteId] = startManifest.routes[rootRouteId] || {};
|
|
10
|
+
rootRoute.assets = rootRoute.assets || [];
|
|
11
|
+
if (process.env.NODE_ENV === "development" && !process.env.TSS_CLIENT_ENTRY) {
|
|
12
|
+
throw new Error(
|
|
13
|
+
"tanstack/start-server-core: TSS_CLIENT_ENTRY must be defined in your environment for getStartManifest()"
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
if (process.env.NODE_ENV === "development") {
|
|
17
|
+
const clientEntry = joinPaths([opts.basePath, process.env.TSS_CLIENT_ENTRY]);
|
|
18
|
+
const script = `${globalThis.TSS_INJECTED_HEAD_SCRIPTS ? globalThis.TSS_INJECTED_HEAD_SCRIPTS + "; " : ""}import('${clientEntry}')`;
|
|
19
|
+
rootRoute.assets.push({
|
|
20
|
+
tag: "script",
|
|
21
|
+
attrs: {
|
|
22
|
+
type: "module",
|
|
23
|
+
suppressHydrationWarning: true,
|
|
24
|
+
async: true
|
|
25
|
+
},
|
|
26
|
+
children: script
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const manifest = {
|
|
30
|
+
...startManifest,
|
|
31
|
+
routes: Object.fromEntries(
|
|
32
|
+
Object.entries(startManifest.routes).map(([k, v]) => {
|
|
33
|
+
const { preloads, assets } = v;
|
|
34
|
+
return [
|
|
35
|
+
k,
|
|
36
|
+
{
|
|
37
|
+
preloads,
|
|
38
|
+
assets
|
|
39
|
+
}
|
|
40
|
+
];
|
|
41
|
+
})
|
|
42
|
+
)
|
|
43
|
+
};
|
|
44
|
+
return manifest;
|
|
45
|
+
}
|
|
46
|
+
export {
|
|
47
|
+
getStartManifest
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=router-manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-manifest.js","sources":["../../src/router-manifest.ts"],"sourcesContent":["import { joinPaths, rootRouteId } from '@tanstack/router-core'\nimport { VIRTUAL_MODULES } from './virtual-modules'\nimport { loadVirtualModule } from './loadVirtualModule'\n\n/**\n * @description Returns the router manifest that should be sent to the client.\n * This includes only the assets and preloads for the current route and any\n * special assets that are needed for the client. It does not include relationships\n * between routes or any other data that is not needed for the client.\n */\nexport async function getStartManifest(opts: { basePath: string }) {\n const { tsrStartManifest } = await loadVirtualModule(\n VIRTUAL_MODULES.startManifest,\n )\n const startManifest = tsrStartManifest()\n\n const rootRoute = (startManifest.routes[rootRouteId] =\n startManifest.routes[rootRouteId] || {})\n\n rootRoute.assets = rootRoute.assets || []\n\n // Get the entry for the client\n // const ClientManifest = getManifest('client')\n\n // const importPath =\n // ClientManifest.inputs[ClientManifest.handler]?.output.path\n // if (!importPath) {\n // invariant(importPath, 'Could not find client entry in manifest')\n // }\n\n if (process.env.NODE_ENV === 'development' && !process.env.TSS_CLIENT_ENTRY) {\n throw new Error(\n 'tanstack/start-server-core: TSS_CLIENT_ENTRY must be defined in your environment for getStartManifest()',\n )\n }\n\n if (process.env.NODE_ENV === 'development') {\n // Always fake that HMR is ready\n // const CLIENT_BASE = sanitizeBase(process.env.TSS_CLIENT_BASE || '')\n\n // if (!CLIENT_BASE) {\n // throw new Error(\n // 'tanstack/start-router-manifest: TSS_CLIENT_BASE must be defined in your environment for getFullRouterManifest()',\n // )\n // }\n\n const clientEntry = joinPaths([opts.basePath, process.env.TSS_CLIENT_ENTRY])\n\n const script = `${globalThis.TSS_INJECTED_HEAD_SCRIPTS ? globalThis.TSS_INJECTED_HEAD_SCRIPTS + '; ' : ''}import('${clientEntry}')`\n\n rootRoute.assets.push({\n tag: 'script',\n attrs: {\n type: 'module',\n suppressHydrationWarning: true,\n async: true,\n },\n children: script,\n })\n }\n\n const manifest = {\n ...startManifest,\n routes: Object.fromEntries(\n Object.entries(startManifest.routes).map(([k, v]) => {\n const { preloads, assets } = v\n return [\n k,\n {\n preloads,\n assets,\n },\n ]\n }),\n ),\n }\n\n // Strip out anything that isn't needed for the client\n return manifest\n}\n"],"names":[],"mappings":";;;AAUA,eAAsB,iBAAiB,MAA4B;AAC3D,QAAA,EAAE,iBAAiB,IAAI,MAAM;AAAA,IACjC,gBAAgB;AAAA,EAClB;AACA,QAAM,gBAAgB,iBAAiB;AAEjC,QAAA,YAAa,cAAc,OAAO,WAAW,IACjD,cAAc,OAAO,WAAW,KAAK,CAAC;AAE9B,YAAA,SAAS,UAAU,UAAU,CAAC;AAWxC,MAAI,QAAQ,IAAI,aAAa,iBAAiB,CAAC,QAAQ,IAAI,kBAAkB;AAC3E,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EAAA;AAGE,MAAA,QAAQ,IAAI,aAAa,eAAe;AAUpC,UAAA,cAAc,UAAU,CAAC,KAAK,UAAU,QAAQ,IAAI,gBAAgB,CAAC;AAErE,UAAA,SAAS,GAAG,WAAW,4BAA4B,WAAW,4BAA4B,OAAO,EAAE,WAAW,WAAW;AAE/H,cAAU,OAAO,KAAK;AAAA,MACpB,KAAK;AAAA,MACL,OAAO;AAAA,QACL,MAAM;AAAA,QACN,0BAA0B;AAAA,QAC1B,OAAO;AAAA,MACT;AAAA,MACA,UAAU;AAAA,IAAA,CACX;AAAA,EAAA;AAGH,QAAM,WAAW;AAAA,IACf,GAAG;AAAA,IACH,QAAQ,OAAO;AAAA,MACb,OAAO,QAAQ,cAAc,MAAM,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,MAAM;AAC7C,cAAA,EAAE,UAAU,OAAA,IAAW;AACtB,eAAA;AAAA,UACL;AAAA,UACA;AAAA,YACE;AAAA,YACA;AAAA,UAAA;AAAA,QAEJ;AAAA,MACD,CAAA;AAAA,IAAA;AAAA,EAEL;AAGO,SAAA;AACT;"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { isNotFound } from "@tanstack/router-core";
|
|
2
|
+
import invariant from "tiny-invariant";
|
|
3
|
+
import { startSerializer } from "@tanstack/start-client-core";
|
|
4
|
+
import { getResponseStatus, getEvent } from "./h3.js";
|
|
5
|
+
import { VIRTUAL_MODULES } from "./virtual-modules.js";
|
|
6
|
+
import { loadVirtualModule } from "./loadVirtualModule.js";
|
|
7
|
+
function sanitizeBase(base) {
|
|
8
|
+
if (!base) {
|
|
9
|
+
throw new Error(
|
|
10
|
+
"🚨 process.env.TSS_SERVER_FN_BASE is required in start/server-handler/index"
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
return base.replace(/^\/|\/$/g, "");
|
|
14
|
+
}
|
|
15
|
+
const handleServerAction = async ({ request }) => {
|
|
16
|
+
const controller = new AbortController();
|
|
17
|
+
const signal = controller.signal;
|
|
18
|
+
const abort = () => controller.abort();
|
|
19
|
+
request.signal.addEventListener("abort", abort);
|
|
20
|
+
const method = request.method;
|
|
21
|
+
const url = new URL(request.url, "http://localhost:3000");
|
|
22
|
+
const regex = new RegExp(
|
|
23
|
+
`${sanitizeBase(process.env.TSS_SERVER_FN_BASE)}/([^/?#]+)`
|
|
24
|
+
);
|
|
25
|
+
const match = url.pathname.match(regex);
|
|
26
|
+
const serverFnId = match ? match[1] : null;
|
|
27
|
+
const search = Object.fromEntries(url.searchParams.entries());
|
|
28
|
+
const isCreateServerFn = "createServerFn" in search;
|
|
29
|
+
const isRaw = "raw" in search;
|
|
30
|
+
if (typeof serverFnId !== "string") {
|
|
31
|
+
throw new Error("Invalid server action param for serverFnId: " + serverFnId);
|
|
32
|
+
}
|
|
33
|
+
const { default: serverFnManifest } = await loadVirtualModule(
|
|
34
|
+
VIRTUAL_MODULES.serverFnManifest
|
|
35
|
+
);
|
|
36
|
+
const serverFnInfo = serverFnManifest[serverFnId];
|
|
37
|
+
if (!serverFnInfo) {
|
|
38
|
+
console.info("serverFnManifest", serverFnManifest);
|
|
39
|
+
throw new Error("Server function info not found for " + serverFnId);
|
|
40
|
+
}
|
|
41
|
+
const fnModule = await serverFnInfo.importer();
|
|
42
|
+
if (!fnModule) {
|
|
43
|
+
console.info("serverFnInfo", serverFnInfo);
|
|
44
|
+
throw new Error("Server function module not resolved for " + serverFnId);
|
|
45
|
+
}
|
|
46
|
+
const action = fnModule[serverFnInfo.functionName];
|
|
47
|
+
if (!action) {
|
|
48
|
+
console.info("serverFnInfo", serverFnInfo);
|
|
49
|
+
console.info("fnModule", fnModule);
|
|
50
|
+
throw new Error(
|
|
51
|
+
`Server function module export not resolved for serverFn ID: ${serverFnId}`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
const formDataContentTypes = [
|
|
55
|
+
"multipart/form-data",
|
|
56
|
+
"application/x-www-form-urlencoded"
|
|
57
|
+
];
|
|
58
|
+
const response = await (async () => {
|
|
59
|
+
try {
|
|
60
|
+
let result = await (async () => {
|
|
61
|
+
if (request.headers.get("Content-Type") && formDataContentTypes.some(
|
|
62
|
+
(type) => {
|
|
63
|
+
var _a;
|
|
64
|
+
return (_a = request.headers.get("Content-Type")) == null ? void 0 : _a.includes(type);
|
|
65
|
+
}
|
|
66
|
+
)) {
|
|
67
|
+
invariant(
|
|
68
|
+
method.toLowerCase() !== "get",
|
|
69
|
+
"GET requests with FormData payloads are not supported"
|
|
70
|
+
);
|
|
71
|
+
return await action(await request.formData(), signal);
|
|
72
|
+
}
|
|
73
|
+
if (method.toLowerCase() === "get") {
|
|
74
|
+
let payload2 = search;
|
|
75
|
+
if (isCreateServerFn) {
|
|
76
|
+
payload2 = search.payload;
|
|
77
|
+
}
|
|
78
|
+
payload2 = payload2 ? startSerializer.parse(payload2) : payload2;
|
|
79
|
+
return await action(payload2, signal);
|
|
80
|
+
}
|
|
81
|
+
const jsonPayloadAsString = await request.text();
|
|
82
|
+
const payload = startSerializer.parse(jsonPayloadAsString);
|
|
83
|
+
if (isCreateServerFn) {
|
|
84
|
+
return await action(payload, signal);
|
|
85
|
+
}
|
|
86
|
+
return await action(...payload, signal);
|
|
87
|
+
})();
|
|
88
|
+
if (result.result instanceof Response) {
|
|
89
|
+
return result.result;
|
|
90
|
+
}
|
|
91
|
+
if (!isCreateServerFn) {
|
|
92
|
+
result = result.result;
|
|
93
|
+
if (result instanceof Response) {
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (isNotFound(result)) {
|
|
98
|
+
return isNotFoundResponse(result);
|
|
99
|
+
}
|
|
100
|
+
return new Response(
|
|
101
|
+
result !== void 0 ? startSerializer.stringify(result) : void 0,
|
|
102
|
+
{
|
|
103
|
+
status: getResponseStatus(getEvent()),
|
|
104
|
+
headers: {
|
|
105
|
+
"Content-Type": "application/json"
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if (error instanceof Response) {
|
|
111
|
+
return error;
|
|
112
|
+
}
|
|
113
|
+
if (isNotFound(error)) {
|
|
114
|
+
return isNotFoundResponse(error);
|
|
115
|
+
}
|
|
116
|
+
console.info();
|
|
117
|
+
console.info("Server Fn Error!");
|
|
118
|
+
console.info();
|
|
119
|
+
console.error(error);
|
|
120
|
+
console.info();
|
|
121
|
+
return new Response(startSerializer.stringify(error), {
|
|
122
|
+
status: 500,
|
|
123
|
+
headers: {
|
|
124
|
+
"Content-Type": "application/json"
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
})();
|
|
129
|
+
request.signal.removeEventListener("abort", abort);
|
|
130
|
+
if (isRaw) {
|
|
131
|
+
return response;
|
|
132
|
+
}
|
|
133
|
+
return response;
|
|
134
|
+
};
|
|
135
|
+
function isNotFoundResponse(error) {
|
|
136
|
+
const { headers, ...rest } = error;
|
|
137
|
+
return new Response(JSON.stringify(rest), {
|
|
138
|
+
status: 200,
|
|
139
|
+
headers: {
|
|
140
|
+
"Content-Type": "application/json",
|
|
141
|
+
...headers || {}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
export {
|
|
146
|
+
handleServerAction
|
|
147
|
+
};
|
|
148
|
+
//# sourceMappingURL=server-functions-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-functions-handler.js","sources":["../../src/server-functions-handler.ts"],"sourcesContent":["import { isNotFound } from '@tanstack/router-core'\nimport invariant from 'tiny-invariant'\nimport { startSerializer } from '@tanstack/start-client-core'\nimport { getEvent, getResponseStatus } from './h3'\nimport { VIRTUAL_MODULES } from './virtual-modules'\nimport { loadVirtualModule } from './loadVirtualModule'\n\nfunction sanitizeBase(base: string | undefined) {\n if (!base) {\n throw new Error(\n '🚨 process.env.TSS_SERVER_FN_BASE is required in start/server-handler/index',\n )\n }\n\n return base.replace(/^\\/|\\/$/g, '')\n}\n\nexport const handleServerAction = async ({ request }: { request: Request }) => {\n const controller = new AbortController()\n const signal = controller.signal\n const abort = () => controller.abort()\n request.signal.addEventListener('abort', abort)\n\n const method = request.method\n const url = new URL(request.url, 'http://localhost:3000')\n // extract the serverFnId from the url as host/_serverFn/:serverFnId\n // Define a regex to match the path and extract the :thing part\n const regex = new RegExp(\n `${sanitizeBase(process.env.TSS_SERVER_FN_BASE)}/([^/?#]+)`,\n )\n\n // Execute the regex\n const match = url.pathname.match(regex)\n const serverFnId = match ? match[1] : null\n const search = Object.fromEntries(url.searchParams.entries()) as {\n payload?: any\n createServerFn?: boolean\n }\n\n const isCreateServerFn = 'createServerFn' in search\n const isRaw = 'raw' in search\n\n if (typeof serverFnId !== 'string') {\n throw new Error('Invalid server action param for serverFnId: ' + serverFnId)\n }\n\n const { default: serverFnManifest } = await loadVirtualModule(\n VIRTUAL_MODULES.serverFnManifest,\n )\n\n const serverFnInfo = serverFnManifest[serverFnId]\n\n if (!serverFnInfo) {\n console.info('serverFnManifest', serverFnManifest)\n throw new Error('Server function info not found for ' + serverFnId)\n }\n\n const fnModule: undefined | { [key: string]: any } =\n await serverFnInfo.importer()\n\n if (!fnModule) {\n console.info('serverFnInfo', serverFnInfo)\n throw new Error('Server function module not resolved for ' + serverFnId)\n }\n\n const action = fnModule[serverFnInfo.functionName]\n\n if (!action) {\n console.info('serverFnInfo', serverFnInfo)\n console.info('fnModule', fnModule)\n throw new Error(\n `Server function module export not resolved for serverFn ID: ${serverFnId}`,\n )\n }\n\n // Known FormData 'Content-Type' header values\n const formDataContentTypes = [\n 'multipart/form-data',\n 'application/x-www-form-urlencoded',\n ]\n\n const response = await (async () => {\n try {\n let result = await (async () => {\n // FormData\n if (\n request.headers.get('Content-Type') &&\n formDataContentTypes.some((type) =>\n request.headers.get('Content-Type')?.includes(type),\n )\n ) {\n // We don't support GET requests with FormData payloads... that seems impossible\n invariant(\n method.toLowerCase() !== 'get',\n 'GET requests with FormData payloads are not supported',\n )\n\n return await action(await request.formData(), signal)\n }\n\n // Get requests use the query string\n if (method.toLowerCase() === 'get') {\n // By default the payload is the search params\n let payload: any = search\n\n // If this GET request was created by createServerFn,\n // then the payload will be on the payload param\n if (isCreateServerFn) {\n payload = search.payload\n }\n\n // If there's a payload, we should try to parse it\n payload = payload ? startSerializer.parse(payload) : payload\n\n // Send it through!\n return await action(payload, signal)\n }\n\n // This must be a POST request, likely JSON???\n const jsonPayloadAsString = await request.text()\n\n // We should probably try to deserialize the payload\n // as JSON, but we'll just pass it through for now.\n const payload = startSerializer.parse(jsonPayloadAsString)\n\n // If this POST request was created by createServerFn,\n // it's payload will be the only argument\n if (isCreateServerFn) {\n return await action(payload, signal)\n }\n\n // Otherwise, we'll spread the payload. Need to\n // support `use server` functions that take multiple\n // arguments.\n return await action(...(payload as any), signal)\n })()\n\n // Any time we get a Response back, we should just\n // return it immediately.\n if (result.result instanceof Response) {\n return result.result\n }\n\n // If this is a non createServerFn request, we need to\n // pull out the result from the result object\n if (!isCreateServerFn) {\n result = result.result\n\n // The result might again be a response,\n // and if it is, return it.\n if (result instanceof Response) {\n return result\n }\n }\n\n // if (!search.createServerFn) {\n // result = result.result\n // }\n\n // else if (\n // isPlainObject(result) &&\n // 'result' in result &&\n // result.result instanceof Response\n // ) {\n // return result.result\n // }\n\n // TODO: RSCs Where are we getting this package?\n // if (isValidElement(result)) {\n // const { renderToPipeableStream } = await import(\n // // @ts-expect-error\n // 'react-server-dom/server'\n // )\n\n // const pipeableStream = renderToPipeableStream(result)\n\n // setHeaders(event, {\n // 'Content-Type': 'text/x-component',\n // } as any)\n\n // sendStream(event, response)\n // event._handled = true\n\n // return new Response(null, { status: 200 })\n // }\n\n if (isNotFound(result)) {\n return isNotFoundResponse(result)\n }\n\n return new Response(\n result !== undefined ? startSerializer.stringify(result) : undefined,\n {\n status: getResponseStatus(getEvent()),\n headers: {\n 'Content-Type': 'application/json',\n },\n },\n )\n } catch (error: any) {\n if (error instanceof Response) {\n return error\n }\n // else if (\n // isPlainObject(error) &&\n // 'result' in error &&\n // error.result instanceof Response\n // ) {\n // return error.result\n // }\n\n // Currently this server-side context has no idea how to\n // build final URLs, so we need to defer that to the client.\n // The client will check for __redirect and __notFound keys,\n // and if they exist, it will handle them appropriately.\n\n if (isNotFound(error)) {\n return isNotFoundResponse(error)\n }\n\n console.info()\n console.info('Server Fn Error!')\n console.info()\n console.error(error)\n console.info()\n\n return new Response(startSerializer.stringify(error), {\n status: 500,\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n }\n })()\n\n request.signal.removeEventListener('abort', abort)\n\n if (isRaw) {\n return response\n }\n\n return response\n}\n\nfunction isNotFoundResponse(error: any) {\n const { headers, ...rest } = error\n\n return new Response(JSON.stringify(rest), {\n status: 200,\n headers: {\n 'Content-Type': 'application/json',\n ...(headers || {}),\n },\n })\n}\n"],"names":["payload"],"mappings":"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"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Assign, Constrain, Expand, ResolveParams, RouteConstraints, TrimPathRight } from '@tanstack/router-core';
|
|
2
|
+
import { AnyRequestMiddleware, AssignAllServerContext } from '@tanstack/start-client-core';
|
|
3
|
+
export declare function createServerFileRoute<TFilePath extends keyof ServerFileRoutesByPath, TParentRoute extends AnyServerRouteWithTypes = ServerFileRoutesByPath[TFilePath]['parentRoute'], TId extends RouteConstraints['TId'] = ServerFileRoutesByPath[TFilePath]['id'], TPath extends RouteConstraints['TPath'] = ServerFileRoutesByPath[TFilePath]['path'], TFullPath extends RouteConstraints['TFullPath'] = ServerFileRoutesByPath[TFilePath]['fullPath'], TChildren = ServerFileRoutesByPath[TFilePath]['children']>(_: TFilePath): ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>;
|
|
4
|
+
export interface ServerFileRoutesByPath {
|
|
5
|
+
}
|
|
6
|
+
export interface ServerRouteOptions<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TMiddlewares> {
|
|
7
|
+
id: TId;
|
|
8
|
+
path: TPath;
|
|
9
|
+
pathname: TFullPath;
|
|
10
|
+
originalIndex: number;
|
|
11
|
+
getParentRoute?: () => TParentRoute;
|
|
12
|
+
middleware?: Constrain<TMiddlewares, ReadonlyArray<AnyRequestMiddleware>>;
|
|
13
|
+
methods?: Record<string, ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, any, any>>;
|
|
14
|
+
caseSensitive?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export type ServerRouteManifest = {
|
|
17
|
+
middleware: boolean;
|
|
18
|
+
methods: Record<string, {
|
|
19
|
+
middleware: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
};
|
|
22
|
+
export declare function createServerRoute<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TChildren>(__?: never, __opts?: Partial<ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, undefined>>): ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>;
|
|
23
|
+
export declare const createServerRootRoute: typeof createServerRoute;
|
|
24
|
+
export type ServerRouteAddFileChildrenFn<in out TParentRoute extends AnyServerRouteWithTypes, in out TId extends RouteConstraints['TId'], in out TPath extends RouteConstraints['TPath'], in out TFullPath extends RouteConstraints['TFullPath'], in out TMiddlewares, in out TMethods, in out TChildren> = (children: TChildren) => ServerRouteWithTypes<TParentRoute, TId, TPath, TFullPath, TMiddlewares, TMethods, TChildren>;
|
|
25
|
+
export interface ServerRouteMethodBuilderOptions<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares, TResponse> {
|
|
26
|
+
handler?: ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares, TResponse>;
|
|
27
|
+
middlewares?: Constrain<TMethodMiddlewares, ReadonlyArray<AnyRequestMiddleware>>;
|
|
28
|
+
}
|
|
29
|
+
export type CreateServerFileRoute<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TChildren> = () => ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>;
|
|
30
|
+
export type AnyServerRouteWithTypes = ServerRouteWithTypes<any, any, any, any, any, any, any>;
|
|
31
|
+
export interface ServerRouteWithTypes<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TMiddlewares, TMethods, TChildren> {
|
|
32
|
+
_types: ServerRouteTypes<TParentRoute, TId, TPath, TFullPath, TMiddlewares, TMethods>;
|
|
33
|
+
path: TPath;
|
|
34
|
+
id: TId;
|
|
35
|
+
fullPath: TFullPath;
|
|
36
|
+
to: TrimPathRight<TFullPath>;
|
|
37
|
+
parentRoute: TParentRoute;
|
|
38
|
+
children?: TChildren;
|
|
39
|
+
options: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, TMiddlewares>;
|
|
40
|
+
update: (opts: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, undefined>) => ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>;
|
|
41
|
+
init: (opts: {
|
|
42
|
+
originalIndex: number;
|
|
43
|
+
}) => void;
|
|
44
|
+
_addFileChildren: ServerRouteAddFileChildrenFn<TParentRoute, TId, TPath, TFullPath, TMiddlewares, TMethods, TChildren>;
|
|
45
|
+
_addFileTypes: () => ServerRouteWithTypes<TParentRoute, TId, TPath, TFullPath, TMiddlewares, TMethods, TChildren>;
|
|
46
|
+
}
|
|
47
|
+
export interface ServerRouteTypes<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TMiddlewares, TMethods> {
|
|
48
|
+
id: TId;
|
|
49
|
+
path: TPath;
|
|
50
|
+
fullPath: TFullPath;
|
|
51
|
+
middlewares: TMiddlewares;
|
|
52
|
+
methods: TMethods;
|
|
53
|
+
parentRoute: TParentRoute;
|
|
54
|
+
allContext: ResolveAllServerContext<TParentRoute, TMiddlewares>;
|
|
55
|
+
}
|
|
56
|
+
export type ResolveAllServerContext<TParentRoute extends AnyServerRouteWithTypes, TMiddlewares> = unknown extends TParentRoute ? AssignAllServerContext<TMiddlewares> : Assign<TParentRoute['_types']['allContext'], AssignAllServerContext<TMiddlewares>>;
|
|
57
|
+
export type AnyServerRoute = AnyServerRouteWithTypes;
|
|
58
|
+
export interface ServerRoute<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TChildren> extends ServerRouteWithTypes<TParentRoute, TId, TPath, TFullPath, undefined, undefined, TChildren>, ServerRouteMiddleware<TParentRoute, TId, TPath, TFullPath, TChildren>, ServerRouteMethods<TParentRoute, TId, TPath, TFullPath, undefined, TChildren> {
|
|
59
|
+
}
|
|
60
|
+
export interface ServerRouteMiddleware<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TChildren> {
|
|
61
|
+
middleware: <const TNewMiddleware>(middleware: Constrain<TNewMiddleware, ReadonlyArray<AnyRequestMiddleware>>) => ServerRouteAfterMiddleware<TParentRoute, TId, TPath, TFullPath, TNewMiddleware, TChildren>;
|
|
62
|
+
}
|
|
63
|
+
export interface ServerRouteAfterMiddleware<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TMiddlewares, TChildren> extends ServerRouteWithTypes<TParentRoute, TId, TPath, TFullPath, TMiddlewares, undefined, TChildren>, ServerRouteMethods<TParentRoute, TId, TPath, TFullPath, TMiddlewares, TChildren> {
|
|
64
|
+
}
|
|
65
|
+
export interface ServerRouteMethods<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TMiddlewares, TChildren> {
|
|
66
|
+
methods: <const TMethods>(methodsOrGetMethods: Constrain<TMethods, ServerRouteMethodsOptions<TParentRoute, TFullPath, TMiddlewares>>) => ServerRouteAfterMethods<TParentRoute, TId, TPath, TFullPath, TMiddlewares, TMethods, TChildren>;
|
|
67
|
+
}
|
|
68
|
+
export type ServerRouteMethodsOptions<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares> = ServerRouteMethodsRecord<TParentRoute, TFullPath, TMiddlewares> | ((api: ServerRouteMethodBuilder<TParentRoute, TFullPath, TMiddlewares>) => ServerRouteMethodsRecord<TParentRoute, TFullPath, TMiddlewares>);
|
|
69
|
+
export interface ServerRouteMethodsRecord<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares> {
|
|
70
|
+
GET?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
71
|
+
POST?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
72
|
+
PUT?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
73
|
+
PATCH?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
74
|
+
DELETE?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
75
|
+
OPTIONS?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
76
|
+
HEAD?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
77
|
+
}
|
|
78
|
+
export type ServerRouteMethodRecordValue<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares> = ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, undefined, any> | AnyRouteMethodsBuilder;
|
|
79
|
+
export type ServerRouteVerb = (typeof ServerRouteVerbs)[number];
|
|
80
|
+
export declare const ServerRouteVerbs: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"];
|
|
81
|
+
export type ServerRouteMethodHandlerFn<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares, TResponse> = (ctx: ServerRouteMethodHandlerCtx<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares>) => TResponse | Promise<TResponse>;
|
|
82
|
+
export interface ServerRouteMethodHandlerCtx<in out TParentRoute extends AnyServerRouteWithTypes, in out TFullPath extends string, in out TMiddlewares, in out TMethodMiddlewares> {
|
|
83
|
+
context: Expand<AssignAllMethodContext<TParentRoute, TMiddlewares, TMethodMiddlewares>>;
|
|
84
|
+
request: Request;
|
|
85
|
+
params: Expand<ResolveParams<TFullPath>>;
|
|
86
|
+
pathname: TFullPath;
|
|
87
|
+
}
|
|
88
|
+
export type MergeMethodMiddlewares<TMiddlewares, TMethodMiddlewares> = TMiddlewares extends ReadonlyArray<any> ? TMethodMiddlewares extends ReadonlyArray<any> ? readonly [...TMiddlewares, ...TMethodMiddlewares] : TMiddlewares : TMethodMiddlewares;
|
|
89
|
+
export type AssignAllMethodContext<TParentRoute extends AnyServerRouteWithTypes, TMiddlewares, TMethodMiddlewares> = ResolveAllServerContext<TParentRoute, MergeMethodMiddlewares<TMiddlewares, TMethodMiddlewares>>;
|
|
90
|
+
export type AnyRouteMethodsBuilder = ServerRouteMethodBuilderWithTypes<any, any, any, any, any>;
|
|
91
|
+
export interface ServerRouteMethodBuilder<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares> extends ServerRouteMethodBuilderWithTypes<TParentRoute, TFullPath, TMiddlewares, undefined, undefined>, ServerRouteMethodBuilderMiddleware<TParentRoute, TFullPath, TMiddlewares>, ServerRouteMethodBuilderHandler<TParentRoute, TFullPath, TMiddlewares, undefined> {
|
|
92
|
+
}
|
|
93
|
+
export interface ServerRouteMethodBuilderWithTypes<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares, TResponse> {
|
|
94
|
+
_options: ServerRouteMethodBuilderOptions<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares, TResponse>;
|
|
95
|
+
_types: ServerRouteMethodBuilderTypes<TFullPath, TMiddlewares, TMethodMiddlewares, TResponse>;
|
|
96
|
+
}
|
|
97
|
+
export interface ServerRouteMethodBuilderTypes<in out TFullPath extends string, in out TMiddlewares, in out TMethodMiddlewares, in out TResponse> {
|
|
98
|
+
middlewares: TMiddlewares;
|
|
99
|
+
methodMiddleware: TMethodMiddlewares;
|
|
100
|
+
fullPath: TFullPath;
|
|
101
|
+
response: TResponse;
|
|
102
|
+
}
|
|
103
|
+
export interface ServerRouteMethodBuilderMiddleware<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares> {
|
|
104
|
+
middleware: <const TNewMethodMiddlewares>(middleware: Constrain<TNewMethodMiddlewares, ReadonlyArray<AnyRequestMiddleware>>) => ServerRouteMethodBuilderAfterMiddleware<TParentRoute, TFullPath, TMiddlewares, TNewMethodMiddlewares>;
|
|
105
|
+
}
|
|
106
|
+
export interface ServerRouteMethodBuilderAfterMiddleware<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares> extends ServerRouteMethodBuilderWithTypes<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares, undefined>, ServerRouteMethodBuilderHandler<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares> {
|
|
107
|
+
}
|
|
108
|
+
export interface ServerRouteMethodBuilderHandler<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares> {
|
|
109
|
+
handler: <TResponse>(handler: ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares, TResponse>) => ServerRouteMethodBuilderAfterHandler<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares, TResponse>;
|
|
110
|
+
}
|
|
111
|
+
export interface ServerRouteMethodBuilderAfterHandler<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares, TResponse> extends ServerRouteMethodBuilderWithTypes<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares, TResponse> {
|
|
112
|
+
opts: ServerRouteMethod<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares>;
|
|
113
|
+
}
|
|
114
|
+
export interface ServerRouteMethod<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares> {
|
|
115
|
+
middleware?: Constrain<TMiddlewares, Array<AnyRequestMiddleware>>;
|
|
116
|
+
handler?: ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares, undefined>;
|
|
117
|
+
}
|
|
118
|
+
export interface ServerRouteAfterMethods<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TMiddlewares, TMethods, TChildren> extends ServerRouteWithTypes<TParentRoute, TId, TPath, TFullPath, TMiddlewares, TMethods, TChildren> {
|
|
119
|
+
options: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, TMiddlewares>;
|
|
120
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { rootRouteId, trimPathLeft, joinPaths } from "@tanstack/router-core";
|
|
2
|
+
function createServerFileRoute(_) {
|
|
3
|
+
return createServerRoute();
|
|
4
|
+
}
|
|
5
|
+
function createServerRoute(__, __opts) {
|
|
6
|
+
const options = __opts || {};
|
|
7
|
+
const route = {
|
|
8
|
+
path: "",
|
|
9
|
+
id: "",
|
|
10
|
+
fullPath: "",
|
|
11
|
+
to: "",
|
|
12
|
+
options,
|
|
13
|
+
parentRoute: void 0,
|
|
14
|
+
_types: {},
|
|
15
|
+
// children: undefined as TChildren,
|
|
16
|
+
middleware: (middlewares) => createServerRoute(void 0, {
|
|
17
|
+
...options,
|
|
18
|
+
middleware: middlewares
|
|
19
|
+
}),
|
|
20
|
+
methods: (methodsOrGetMethods) => {
|
|
21
|
+
const methods = (() => {
|
|
22
|
+
if (typeof methodsOrGetMethods === "function") {
|
|
23
|
+
return methodsOrGetMethods(createMethodBuilder());
|
|
24
|
+
}
|
|
25
|
+
return methodsOrGetMethods;
|
|
26
|
+
})();
|
|
27
|
+
return createServerRoute(void 0, {
|
|
28
|
+
...__opts,
|
|
29
|
+
methods
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
update: (opts) => createServerRoute(void 0, {
|
|
33
|
+
...options,
|
|
34
|
+
...opts
|
|
35
|
+
}),
|
|
36
|
+
init: (opts) => {
|
|
37
|
+
var _a;
|
|
38
|
+
options.originalIndex = opts.originalIndex;
|
|
39
|
+
const isRoot = !options.path && !options.id;
|
|
40
|
+
route.parentRoute = (_a = options.getParentRoute) == null ? void 0 : _a.call(options);
|
|
41
|
+
if (isRoot) {
|
|
42
|
+
route.path = rootRouteId;
|
|
43
|
+
} else if (!route.parentRoute) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
`Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a ServerRoute instance.`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
let path = isRoot ? rootRouteId : options.path;
|
|
49
|
+
if (path && path !== "/") {
|
|
50
|
+
path = trimPathLeft(path);
|
|
51
|
+
}
|
|
52
|
+
const customId = options.id || path;
|
|
53
|
+
let id = isRoot ? rootRouteId : joinPaths([
|
|
54
|
+
route.parentRoute.id === rootRouteId ? "" : route.parentRoute.id,
|
|
55
|
+
customId
|
|
56
|
+
]);
|
|
57
|
+
if (path === rootRouteId) {
|
|
58
|
+
path = "/";
|
|
59
|
+
}
|
|
60
|
+
if (id !== rootRouteId) {
|
|
61
|
+
id = joinPaths(["/", id]);
|
|
62
|
+
}
|
|
63
|
+
const fullPath = id === rootRouteId ? "/" : joinPaths([route.parentRoute.fullPath, path]);
|
|
64
|
+
route.path = path;
|
|
65
|
+
route.id = id;
|
|
66
|
+
route.fullPath = fullPath;
|
|
67
|
+
route.to = fullPath;
|
|
68
|
+
},
|
|
69
|
+
_addFileChildren: (children) => {
|
|
70
|
+
if (Array.isArray(children)) {
|
|
71
|
+
route.children = children;
|
|
72
|
+
}
|
|
73
|
+
if (typeof children === "object" && children !== null) {
|
|
74
|
+
route.children = Object.values(children);
|
|
75
|
+
}
|
|
76
|
+
return route;
|
|
77
|
+
},
|
|
78
|
+
_addFileTypes: () => route
|
|
79
|
+
};
|
|
80
|
+
return route;
|
|
81
|
+
}
|
|
82
|
+
const createServerRootRoute = createServerRoute;
|
|
83
|
+
const createMethodBuilder = (__opts) => {
|
|
84
|
+
return {
|
|
85
|
+
_options: __opts || {},
|
|
86
|
+
_types: {},
|
|
87
|
+
middleware: (middlewares) => createMethodBuilder({
|
|
88
|
+
...__opts,
|
|
89
|
+
middlewares
|
|
90
|
+
}),
|
|
91
|
+
handler: (handler) => createMethodBuilder({
|
|
92
|
+
...__opts,
|
|
93
|
+
handler
|
|
94
|
+
})
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
export {
|
|
98
|
+
createServerFileRoute,
|
|
99
|
+
createServerRootRoute,
|
|
100
|
+
createServerRoute
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=serverRoute.js.map
|