@tanstack/start-server-core 1.120.3 → 1.120.4-alpha.1
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/README.md +6 -27
- package/dist/cjs/createRequestHandler.cjs +1 -3
- package/dist/cjs/createRequestHandler.cjs.map +1 -1
- package/dist/cjs/createStartHandler.cjs +228 -30
- package/dist/cjs/createStartHandler.cjs.map +1 -1
- package/dist/cjs/createStartHandler.d.cts +8 -6
- package/dist/cjs/h3.cjs +30 -73
- package/dist/cjs/h3.cjs.map +1 -1
- package/dist/cjs/h3.d.cts +11 -7
- package/dist/cjs/handlerCallback.cjs.map +1 -1
- package/dist/cjs/handlerCallback.d.cts +3 -4
- package/dist/cjs/index.cjs +20 -14
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +7 -1
- package/dist/cjs/router-manifest.cjs +44 -0
- package/dist/cjs/router-manifest.cjs.map +1 -0
- package/dist/cjs/router-manifest.d.cts +17 -0
- package/dist/cjs/server-functions-handler.cjs +154 -0
- package/dist/cjs/server-functions-handler.cjs.map +1 -0
- package/dist/cjs/server-functions-handler.d.cts +4 -0
- package/dist/cjs/serverRoute.cjs +100 -0
- package/dist/cjs/serverRoute.cjs.map +1 -0
- package/dist/cjs/serverRoute.d.cts +115 -0
- package/dist/cjs/undici.cjs +14 -0
- package/dist/cjs/undici.cjs.map +1 -0
- package/dist/cjs/undici.d.cts +43 -0
- package/dist/esm/createRequestHandler.js +1 -3
- package/dist/esm/createRequestHandler.js.map +1 -1
- package/dist/esm/createStartHandler.d.ts +8 -6
- package/dist/esm/createStartHandler.js +208 -32
- package/dist/esm/createStartHandler.js.map +1 -1
- package/dist/esm/h3.d.ts +11 -7
- package/dist/esm/h3.js +26 -63
- package/dist/esm/h3.js.map +1 -1
- package/dist/esm/handlerCallback.d.ts +3 -4
- package/dist/esm/handlerCallback.js.map +1 -1
- package/dist/esm/index.d.ts +7 -1
- package/dist/esm/index.js +17 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/router-manifest.d.ts +17 -0
- package/dist/esm/router-manifest.js +44 -0
- package/dist/esm/router-manifest.js.map +1 -0
- package/dist/esm/server-functions-handler.d.ts +4 -0
- package/dist/esm/server-functions-handler.js +154 -0
- package/dist/esm/server-functions-handler.js.map +1 -0
- package/dist/esm/serverRoute.d.ts +115 -0
- package/dist/esm/serverRoute.js +100 -0
- package/dist/esm/serverRoute.js.map +1 -0
- package/dist/esm/undici.d.ts +43 -0
- package/dist/esm/undici.js +14 -0
- package/dist/esm/undici.js.map +1 -0
- package/package.json +9 -6
- package/src/createRequestHandler.ts +1 -3
- package/src/createStartHandler.ts +313 -47
- package/src/h3.ts +71 -78
- package/src/handlerCallback.ts +5 -12
- package/src/index.tsx +13 -1
- package/src/router-manifest.ts +79 -0
- package/src/server-functions-handler.ts +273 -0
- package/src/serverRoute.ts +661 -0
- package/src/tanstack-start.d.ts +5 -0
- package/src/undici.ts +60 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const routerCore = require("@tanstack/router-core");
|
|
4
|
+
function createServerFileRoute(__) {
|
|
5
|
+
return createServerRoute();
|
|
6
|
+
}
|
|
7
|
+
function createServerRoute(__, __opts) {
|
|
8
|
+
const options = __opts || {};
|
|
9
|
+
const route = {
|
|
10
|
+
path: "",
|
|
11
|
+
id: "",
|
|
12
|
+
fullPath: "",
|
|
13
|
+
to: "",
|
|
14
|
+
options,
|
|
15
|
+
parentRoute: void 0,
|
|
16
|
+
_types: {},
|
|
17
|
+
// children: undefined as TChildren,
|
|
18
|
+
middleware: (middlewares) => createServerRoute(void 0, {
|
|
19
|
+
...options,
|
|
20
|
+
middleware: middlewares
|
|
21
|
+
}),
|
|
22
|
+
methods: (methodsOrGetMethods) => {
|
|
23
|
+
const methods = (() => {
|
|
24
|
+
if (typeof methodsOrGetMethods === "function") {
|
|
25
|
+
return methodsOrGetMethods(createMethodBuilder());
|
|
26
|
+
}
|
|
27
|
+
return methodsOrGetMethods;
|
|
28
|
+
})();
|
|
29
|
+
return createServerRoute(void 0, {
|
|
30
|
+
...__opts,
|
|
31
|
+
methods
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
update: (opts) => createServerRoute(void 0, {
|
|
35
|
+
...options,
|
|
36
|
+
...opts
|
|
37
|
+
}),
|
|
38
|
+
init: (opts) => {
|
|
39
|
+
var _a;
|
|
40
|
+
options.originalIndex = opts.originalIndex;
|
|
41
|
+
const isRoot = !options.path && !options.id;
|
|
42
|
+
route.parentRoute = (_a = options.getParentRoute) == null ? void 0 : _a.call(options);
|
|
43
|
+
if (isRoot) {
|
|
44
|
+
route.path = routerCore.rootRouteId;
|
|
45
|
+
} else if (!route.parentRoute) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
`Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a ServerRoute instance.`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
let path = isRoot ? routerCore.rootRouteId : options.path;
|
|
51
|
+
if (path && path !== "/") {
|
|
52
|
+
path = routerCore.trimPathLeft(path);
|
|
53
|
+
}
|
|
54
|
+
const customId = options.id || path;
|
|
55
|
+
let id = isRoot ? routerCore.rootRouteId : routerCore.joinPaths([
|
|
56
|
+
route.parentRoute.id === routerCore.rootRouteId ? "" : route.parentRoute.id,
|
|
57
|
+
customId
|
|
58
|
+
]);
|
|
59
|
+
if (path === routerCore.rootRouteId) {
|
|
60
|
+
path = "/";
|
|
61
|
+
}
|
|
62
|
+
if (id !== routerCore.rootRouteId) {
|
|
63
|
+
id = routerCore.joinPaths(["/", id]);
|
|
64
|
+
}
|
|
65
|
+
const fullPath = id === routerCore.rootRouteId ? "/" : routerCore.joinPaths([route.parentRoute.fullPath, path]);
|
|
66
|
+
route.path = path;
|
|
67
|
+
route.id = id;
|
|
68
|
+
route.fullPath = fullPath;
|
|
69
|
+
route.to = fullPath;
|
|
70
|
+
},
|
|
71
|
+
_addFileChildren: (children) => {
|
|
72
|
+
if (Array.isArray(children)) {
|
|
73
|
+
route.children = children;
|
|
74
|
+
}
|
|
75
|
+
if (typeof children === "object" && children !== null) {
|
|
76
|
+
route.children = Object.values(children);
|
|
77
|
+
}
|
|
78
|
+
return route;
|
|
79
|
+
},
|
|
80
|
+
_addFileTypes: () => route
|
|
81
|
+
};
|
|
82
|
+
return route;
|
|
83
|
+
}
|
|
84
|
+
const createMethodBuilder = (__opts) => {
|
|
85
|
+
return {
|
|
86
|
+
_options: __opts || {},
|
|
87
|
+
_types: {},
|
|
88
|
+
middleware: (middlewares) => createMethodBuilder({
|
|
89
|
+
...__opts,
|
|
90
|
+
middlewares
|
|
91
|
+
}),
|
|
92
|
+
handler: (handler) => createMethodBuilder({
|
|
93
|
+
...__opts,
|
|
94
|
+
handler
|
|
95
|
+
})
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
exports.createServerFileRoute = createServerFileRoute;
|
|
99
|
+
exports.createServerRoute = createServerRoute;
|
|
100
|
+
//# sourceMappingURL=serverRoute.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverRoute.cjs","sources":["../../src/serverRoute.ts"],"sourcesContent":["import { joinPaths, rootRouteId, trimPathLeft } from '@tanstack/router-core'\nimport type {\n Assign,\n Constrain,\n Expand,\n ResolveParams,\n RouteConstraints,\n TrimPathRight,\n} from '@tanstack/router-core'\nimport type {\n AnyRequestMiddleware,\n AssignAllServerContext,\n} from '@tanstack/start-client-core'\n\ntype TODO = any\n\nexport function createServerFileRoute<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TChildren,\n>(__?: never): ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren> {\n return createServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>(\n undefined,\n )\n}\n\nexport interface ServerRouteOptions<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n> {\n id: TId\n path: TPath\n pathname: TFullPath\n originalIndex: number\n getParentRoute?: () => TParentRoute\n middleware: Constrain<TMiddlewares, ReadonlyArray<AnyRequestMiddleware>>\n methods: Record<\n string,\n ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, any, any>\n >\n caseSensitive?: boolean\n}\n\nexport type ServerRouteManifest = {\n middleware: boolean\n methods: Record<string, { middleware: boolean }>\n}\n\nexport function createServerRoute<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TChildren,\n>(\n __?: never,\n __opts?: Partial<\n ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, undefined>\n >,\n): ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren> {\n const options = __opts || {}\n\n const route: ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren> = {\n path: '' as TPath,\n id: '' as TId,\n fullPath: '' as TFullPath,\n to: '' as TrimPathRight<TFullPath>,\n options: options as TODO,\n parentRoute: undefined as unknown as TParentRoute,\n _types: {} as TODO,\n // children: undefined as TChildren,\n middleware: (middlewares: TODO) =>\n createServerRoute(undefined, {\n ...options,\n middleware: middlewares,\n }) as TODO,\n methods: (methodsOrGetMethods: TODO) => {\n const methods = (() => {\n if (typeof methodsOrGetMethods === 'function') {\n return methodsOrGetMethods(createMethodBuilder())\n }\n\n return methodsOrGetMethods\n })()\n\n return createServerRoute(undefined, {\n ...__opts,\n methods,\n }) as TODO\n },\n update: (opts) =>\n createServerRoute(undefined, {\n ...options,\n ...opts,\n }) as TODO,\n init: (opts: { originalIndex: number }): void => {\n options.originalIndex = opts.originalIndex\n\n const isRoot = !options.path && !options.id\n\n route.parentRoute = options.getParentRoute?.() as TParentRoute\n\n if (isRoot) {\n route.path = rootRouteId as TPath\n } else if (!(route.parentRoute as any)) {\n throw new Error(\n `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a ServerRoute instance.`,\n )\n }\n\n let path: undefined | string = isRoot ? rootRouteId : options.path\n\n // If the path is anything other than an index path, trim it up\n if (path && path !== '/') {\n path = trimPathLeft(path)\n }\n\n const customId = options.id || path\n\n // Strip the parentId prefix from the first level of children\n let id = isRoot\n ? rootRouteId\n : joinPaths([\n route.parentRoute.id === rootRouteId ? '' : route.parentRoute.id,\n customId,\n ])\n\n if (path === rootRouteId) {\n path = '/'\n }\n\n if (id !== rootRouteId) {\n id = joinPaths(['/', id])\n }\n\n const fullPath =\n id === rootRouteId ? '/' : joinPaths([route.parentRoute.fullPath, path])\n\n route.path = path as TPath\n route.id = id as TId\n route.fullPath = fullPath as TFullPath\n route.to = fullPath as TrimPathRight<TFullPath>\n },\n\n _addFileChildren: (children) => {\n if (Array.isArray(children)) {\n route.children = children as TChildren as TODO\n }\n\n if (typeof children === 'object' && children !== null) {\n route.children = Object.values(children) as TChildren as TODO\n }\n\n return route as any\n },\n\n _addFileTypes: <TFileTypes>() => route,\n }\n\n return route\n}\n\nexport type ServerRouteAddFileChildrenFn<\n in out TParentRoute extends AnyServerRouteWithTypes,\n in out TId extends RouteConstraints['TId'],\n in out TPath extends RouteConstraints['TPath'],\n in out TFullPath extends RouteConstraints['TFullPath'],\n in out TMiddlewares,\n in out TMethods,\n in out TChildren,\n> = (\n children: TChildren,\n) => ServerRouteWithTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods,\n TChildren\n>\n\nconst createMethodBuilder = <\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n>(\n __opts?: TODO,\n): ServerRouteMethodBuilder<TParentRoute, TFullPath, TMiddlewares> => {\n return {\n _options: __opts || {},\n _types: {} as TODO,\n middleware: (middlewares) =>\n createMethodBuilder({\n ...__opts,\n middlewares,\n }) as TODO,\n handler: (handler) =>\n createMethodBuilder({\n ...__opts,\n handler,\n }) as TODO,\n }\n}\n\nexport type CreateServerFileRoute<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TChildren,\n> = (\n options?: undefined,\n) => ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>\n\nexport type AnyServerRouteWithTypes = ServerRouteWithTypes<\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>\n\nexport interface ServerRouteWithTypes<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n TMethods,\n TChildren,\n> {\n _types: ServerRouteTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods\n >\n path: TPath\n id: TId\n fullPath: TFullPath\n to: TrimPathRight<TFullPath>\n parentRoute: TParentRoute\n children?: TChildren\n options: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, TMiddlewares>\n update: (\n opts: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, undefined>,\n ) => ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>\n init: (opts: { originalIndex: number }) => void\n _addFileChildren: ServerRouteAddFileChildrenFn<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods,\n TChildren\n >\n _addFileTypes: () => ServerRouteWithTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods,\n TChildren\n >\n}\n\nexport interface ServerRouteTypes<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n TMethods,\n> {\n id: TId\n path: TPath\n fullPath: TFullPath\n middlewares: TMiddlewares\n methods: TMethods\n parentRoute: TParentRoute\n allContext: ResolveAllServerContext<TParentRoute, TMiddlewares>\n}\n\nexport type ResolveAllServerContext<\n TParentRoute extends AnyServerRouteWithTypes,\n TMiddlewares,\n> = unknown extends TParentRoute\n ? AssignAllServerContext<TMiddlewares>\n : Assign<\n TParentRoute['_types']['allContext'],\n AssignAllServerContext<TMiddlewares>\n >\n\nexport type AnyServerRoute = AnyServerRouteWithTypes\n\nexport interface ServerRoute<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TChildren,\n> extends ServerRouteWithTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n undefined,\n undefined,\n TChildren\n >,\n ServerRouteMiddleware<TParentRoute, TId, TPath, TFullPath, TChildren>,\n ServerRouteMethods<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n undefined,\n TChildren\n > {}\n\nexport interface ServerRouteMiddleware<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TChildren,\n> {\n middleware: <const TNewMiddleware>(\n middleware: Constrain<TNewMiddleware, ReadonlyArray<AnyRequestMiddleware>>,\n ) => ServerRouteAfterMiddleware<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TNewMiddleware,\n TChildren\n >\n}\n\nexport interface ServerRouteAfterMiddleware<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n TChildren,\n> extends ServerRouteWithTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n undefined,\n TChildren\n >,\n ServerRouteMethods<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TChildren\n > {}\n\nexport interface ServerRouteMethods<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n TChildren,\n> {\n methods: <const TMethods>(\n methodsOrGetMethods: Constrain<\n TMethods,\n ServerRouteMethodsOptions<TParentRoute, TFullPath, TMiddlewares>\n >,\n ) => ServerRouteAfterMethods<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods,\n TChildren\n >\n}\n\nexport type ServerRouteMethodsOptions<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n> =\n | ServerRouteMethodsRecord<TParentRoute, TFullPath, TMiddlewares>\n | ((\n api: ServerRouteMethodBuilder<TParentRoute, TFullPath, TMiddlewares>,\n ) => ServerRouteMethodsRecord<TParentRoute, TFullPath, TMiddlewares>)\n\nexport interface ServerRouteMethodsRecord<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n> {\n GET?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n POST?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n PUT?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n PATCH?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n DELETE?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n OPTIONS?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n HEAD?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>\n}\n\nexport type ServerRouteMethodRecordValue<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n> =\n | ServerRouteMethodHandlerFn<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n undefined,\n any\n >\n | AnyRouteMethodsBuilder\n\nexport type ServerRouteVerb = (typeof ServerRouteVerbs)[number]\n\nexport const ServerRouteVerbs = [\n 'GET',\n 'POST',\n 'PUT',\n 'PATCH',\n 'DELETE',\n 'OPTIONS',\n 'HEAD',\n] as const\n\nexport type ServerRouteMethodHandlerFn<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse,\n> = (\n ctx: ServerRouteMethodHandlerCtx<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares\n >,\n) => TResponse | Promise<TResponse>\n\nexport interface ServerRouteMethodHandlerCtx<\n in out TParentRoute extends AnyServerRouteWithTypes,\n in out TFullPath extends string,\n in out TMiddlewares,\n in out TMethodMiddlewares,\n> {\n context: Expand<\n AssignAllMethodContext<TParentRoute, TMiddlewares, TMethodMiddlewares>\n >\n request: Request\n params: ResolveParams<TFullPath>\n pathname: TFullPath\n}\n\nexport type MergeMethodMiddlewares<TMiddlewares, TMethodMiddlewares> =\n TMiddlewares extends ReadonlyArray<any>\n ? TMethodMiddlewares extends ReadonlyArray<any>\n ? readonly [...TMiddlewares, ...TMethodMiddlewares]\n : TMiddlewares\n : TMethodMiddlewares\n\nexport type AssignAllMethodContext<\n TParentRoute extends AnyServerRouteWithTypes,\n TMiddlewares,\n TMethodMiddlewares,\n> = ResolveAllServerContext<\n TParentRoute,\n MergeMethodMiddlewares<TMiddlewares, TMethodMiddlewares>\n>\n\nexport type AnyRouteMethodsBuilder = ServerRouteMethodBuilderWithTypes<\n any,\n any,\n any,\n any\n>\n\nexport interface ServerRouteMethodBuilder<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n> extends ServerRouteMethodBuilderWithTypes<\n TFullPath,\n TMiddlewares,\n undefined,\n undefined\n >,\n ServerRouteMethodBuilderMiddleware<TParentRoute, TFullPath, TMiddlewares>,\n ServerRouteMethodBuilderHandler<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n undefined\n > {}\n\nexport interface ServerRouteMethodBuilderWithTypes<\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse,\n> {\n _options: TODO\n _types: ServerRouteMethodBuilderTypes<\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse\n >\n}\n\nexport interface ServerRouteMethodBuilderTypes<\n in out TFullPath extends string,\n in out TMiddlewares,\n in out TMethodMiddlewares,\n in out TResponse,\n> {\n middlewares: TMiddlewares\n methodMiddleware: TMethodMiddlewares\n fullPath: TFullPath\n response: TResponse\n}\n\nexport interface ServerRouteMethodBuilderMiddleware<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n> {\n middleware: <const TNewMethodMiddlewares>(\n middleware: Constrain<\n TNewMethodMiddlewares,\n ReadonlyArray<AnyRequestMiddleware>\n >,\n ) => ServerRouteMethodBuilderAfterMiddleware<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TNewMethodMiddlewares\n >\n}\n\nexport interface ServerRouteMethodBuilderAfterMiddleware<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n> extends ServerRouteMethodBuilderWithTypes<\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n undefined\n >,\n ServerRouteMethodBuilderHandler<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares\n > {}\n\nexport interface ServerRouteMethodBuilderHandler<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n> {\n handler: <TResponse>(\n handler: ServerRouteMethodHandlerFn<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse\n >,\n ) => ServerRouteMethodBuilderAfterHandler<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse\n >\n}\n\nexport interface ServerRouteMethodBuilderAfterHandler<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse,\n> extends ServerRouteMethodBuilderWithTypes<\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse\n > {\n opts: ServerRouteMethod<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares\n >\n}\n\nexport interface ServerRouteMethod<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n> {\n middleware?: Constrain<TMiddlewares, Array<AnyRequestMiddleware>>\n handler?: ServerRouteMethodHandlerFn<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n undefined\n >\n}\n\nexport interface ServerRouteAfterMethods<\n TParentRoute extends AnyServerRouteWithTypes,\n TId extends RouteConstraints['TId'],\n TPath extends RouteConstraints['TPath'],\n TFullPath extends RouteConstraints['TFullPath'],\n TMiddlewares,\n TMethods,\n TChildren,\n> extends ServerRouteWithTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n TMiddlewares,\n TMethods,\n TChildren\n > {\n options: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, TMiddlewares>\n}\n"],"names":["rootRouteId","trimPathLeft","joinPaths"],"mappings":";;;AAgBO,SAAS,sBAMd,IAAyE;AAClE,SAAA,kBAEP;AACF;AA2BgB,SAAA,kBAOd,IACA,QAG6D;AACvD,QAAA,UAAU,UAAU,CAAC;AAE3B,QAAM,QAAqE;AAAA,IACzE,MAAM;AAAA,IACN,IAAI;AAAA,IACJ,UAAU;AAAA,IACV,IAAI;AAAA,IACJ;AAAA,IACA,aAAa;AAAA,IACb,QAAQ,CAAC;AAAA;AAAA,IAET,YAAY,CAAC,gBACX,kBAAkB,QAAW;AAAA,MAC3B,GAAG;AAAA,MACH,YAAY;AAAA,IAAA,CACb;AAAA,IACH,SAAS,CAAC,wBAA8B;AACtC,YAAM,WAAW,MAAM;AACjB,YAAA,OAAO,wBAAwB,YAAY;AACtC,iBAAA,oBAAoB,qBAAqB;AAAA,QAAA;AAG3C,eAAA;AAAA,MAAA,GACN;AAEH,aAAO,kBAAkB,QAAW;AAAA,QAClC,GAAG;AAAA,QACH;AAAA,MAAA,CACD;AAAA,IACH;AAAA,IACA,QAAQ,CAAC,SACP,kBAAkB,QAAW;AAAA,MAC3B,GAAG;AAAA,MACH,GAAG;AAAA,IAAA,CACJ;AAAA,IACH,MAAM,CAAC,SAA0C;;AAC/C,cAAQ,gBAAgB,KAAK;AAE7B,YAAM,SAAS,CAAC,QAAQ,QAAQ,CAAC,QAAQ;AAEnC,YAAA,eAAc,aAAQ,mBAAR;AAEpB,UAAI,QAAQ;AACV,cAAM,OAAOA,WAAA;AAAA,MAAA,WACJ,CAAE,MAAM,aAAqB;AACtC,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MAAA;AAGE,UAAA,OAA2B,SAASA,WAAA,cAAc,QAAQ;AAG1D,UAAA,QAAQ,SAAS,KAAK;AACxB,eAAOC,wBAAa,IAAI;AAAA,MAAA;AAGpB,YAAA,WAAW,QAAQ,MAAM;AAG3B,UAAA,KAAK,SACLD,WAAA,cACAE,qBAAU;AAAA,QACR,MAAM,YAAY,OAAOF,WAAAA,cAAc,KAAK,MAAM,YAAY;AAAA,QAC9D;AAAA,MAAA,CACD;AAEL,UAAI,SAASA,WAAAA,aAAa;AACjB,eAAA;AAAA,MAAA;AAGT,UAAI,OAAOA,WAAAA,aAAa;AACtB,aAAKE,WAAU,UAAA,CAAC,KAAK,EAAE,CAAC;AAAA,MAAA;AAGpB,YAAA,WACJ,OAAOF,WAAA,cAAc,MAAME,WAAAA,UAAU,CAAC,MAAM,YAAY,UAAU,IAAI,CAAC;AAEzE,YAAM,OAAO;AACb,YAAM,KAAK;AACX,YAAM,WAAW;AACjB,YAAM,KAAK;AAAA,IACb;AAAA,IAEA,kBAAkB,CAAC,aAAa;AAC1B,UAAA,MAAM,QAAQ,QAAQ,GAAG;AAC3B,cAAM,WAAW;AAAA,MAAA;AAGnB,UAAI,OAAO,aAAa,YAAY,aAAa,MAAM;AAC/C,cAAA,WAAW,OAAO,OAAO,QAAQ;AAAA,MAAA;AAGlC,aAAA;AAAA,IACT;AAAA,IAEA,eAAe,MAAkB;AAAA,EACnC;AAEO,SAAA;AACT;AAsBA,MAAM,sBAAsB,CAK1B,WACoE;AAC7D,SAAA;AAAA,IACL,UAAU,UAAU,CAAC;AAAA,IACrB,QAAQ,CAAC;AAAA,IACT,YAAY,CAAC,gBACX,oBAAoB;AAAA,MAClB,GAAG;AAAA,MACH;AAAA,IAAA,CACD;AAAA,IACH,SAAS,CAAC,YACR,oBAAoB;AAAA,MAClB,GAAG;AAAA,MACH;AAAA,IACD,CAAA;AAAA,EACL;AACF;;;"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { Assign, Constrain, Expand, ResolveParams, RouteConstraints, TrimPathRight } from '@tanstack/router-core';
|
|
2
|
+
import { AnyRequestMiddleware, AssignAllServerContext } from '@tanstack/start-client-core';
|
|
3
|
+
type TODO = any;
|
|
4
|
+
export declare function createServerFileRoute<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TChildren>(__?: never): ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>;
|
|
5
|
+
export interface ServerRouteOptions<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TMiddlewares> {
|
|
6
|
+
id: TId;
|
|
7
|
+
path: TPath;
|
|
8
|
+
pathname: TFullPath;
|
|
9
|
+
originalIndex: number;
|
|
10
|
+
getParentRoute?: () => TParentRoute;
|
|
11
|
+
middleware: Constrain<TMiddlewares, ReadonlyArray<AnyRequestMiddleware>>;
|
|
12
|
+
methods: Record<string, ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, any, any>>;
|
|
13
|
+
caseSensitive?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export type ServerRouteManifest = {
|
|
16
|
+
middleware: boolean;
|
|
17
|
+
methods: Record<string, {
|
|
18
|
+
middleware: boolean;
|
|
19
|
+
}>;
|
|
20
|
+
};
|
|
21
|
+
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>;
|
|
22
|
+
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>;
|
|
23
|
+
export type CreateServerFileRoute<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TChildren> = (options?: undefined) => ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>;
|
|
24
|
+
export type AnyServerRouteWithTypes = ServerRouteWithTypes<any, any, any, any, any, any, any>;
|
|
25
|
+
export interface ServerRouteWithTypes<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TMiddlewares, TMethods, TChildren> {
|
|
26
|
+
_types: ServerRouteTypes<TParentRoute, TId, TPath, TFullPath, TMiddlewares, TMethods>;
|
|
27
|
+
path: TPath;
|
|
28
|
+
id: TId;
|
|
29
|
+
fullPath: TFullPath;
|
|
30
|
+
to: TrimPathRight<TFullPath>;
|
|
31
|
+
parentRoute: TParentRoute;
|
|
32
|
+
children?: TChildren;
|
|
33
|
+
options: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, TMiddlewares>;
|
|
34
|
+
update: (opts: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, undefined>) => ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>;
|
|
35
|
+
init: (opts: {
|
|
36
|
+
originalIndex: number;
|
|
37
|
+
}) => void;
|
|
38
|
+
_addFileChildren: ServerRouteAddFileChildrenFn<TParentRoute, TId, TPath, TFullPath, TMiddlewares, TMethods, TChildren>;
|
|
39
|
+
_addFileTypes: () => ServerRouteWithTypes<TParentRoute, TId, TPath, TFullPath, TMiddlewares, TMethods, TChildren>;
|
|
40
|
+
}
|
|
41
|
+
export interface ServerRouteTypes<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TMiddlewares, TMethods> {
|
|
42
|
+
id: TId;
|
|
43
|
+
path: TPath;
|
|
44
|
+
fullPath: TFullPath;
|
|
45
|
+
middlewares: TMiddlewares;
|
|
46
|
+
methods: TMethods;
|
|
47
|
+
parentRoute: TParentRoute;
|
|
48
|
+
allContext: ResolveAllServerContext<TParentRoute, TMiddlewares>;
|
|
49
|
+
}
|
|
50
|
+
export type ResolveAllServerContext<TParentRoute extends AnyServerRouteWithTypes, TMiddlewares> = unknown extends TParentRoute ? AssignAllServerContext<TMiddlewares> : Assign<TParentRoute['_types']['allContext'], AssignAllServerContext<TMiddlewares>>;
|
|
51
|
+
export type AnyServerRoute = AnyServerRouteWithTypes;
|
|
52
|
+
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> {
|
|
53
|
+
}
|
|
54
|
+
export interface ServerRouteMiddleware<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TChildren> {
|
|
55
|
+
middleware: <const TNewMiddleware>(middleware: Constrain<TNewMiddleware, ReadonlyArray<AnyRequestMiddleware>>) => ServerRouteAfterMiddleware<TParentRoute, TId, TPath, TFullPath, TNewMiddleware, TChildren>;
|
|
56
|
+
}
|
|
57
|
+
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> {
|
|
58
|
+
}
|
|
59
|
+
export interface ServerRouteMethods<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TMiddlewares, TChildren> {
|
|
60
|
+
methods: <const TMethods>(methodsOrGetMethods: Constrain<TMethods, ServerRouteMethodsOptions<TParentRoute, TFullPath, TMiddlewares>>) => ServerRouteAfterMethods<TParentRoute, TId, TPath, TFullPath, TMiddlewares, TMethods, TChildren>;
|
|
61
|
+
}
|
|
62
|
+
export type ServerRouteMethodsOptions<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares> = ServerRouteMethodsRecord<TParentRoute, TFullPath, TMiddlewares> | ((api: ServerRouteMethodBuilder<TParentRoute, TFullPath, TMiddlewares>) => ServerRouteMethodsRecord<TParentRoute, TFullPath, TMiddlewares>);
|
|
63
|
+
export interface ServerRouteMethodsRecord<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares> {
|
|
64
|
+
GET?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
65
|
+
POST?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
66
|
+
PUT?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
67
|
+
PATCH?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
68
|
+
DELETE?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
69
|
+
OPTIONS?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
70
|
+
HEAD?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
71
|
+
}
|
|
72
|
+
export type ServerRouteMethodRecordValue<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares> = ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, undefined, any> | AnyRouteMethodsBuilder;
|
|
73
|
+
export type ServerRouteVerb = (typeof ServerRouteVerbs)[number];
|
|
74
|
+
export declare const ServerRouteVerbs: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"];
|
|
75
|
+
export type ServerRouteMethodHandlerFn<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares, TResponse> = (ctx: ServerRouteMethodHandlerCtx<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares>) => TResponse | Promise<TResponse>;
|
|
76
|
+
export interface ServerRouteMethodHandlerCtx<in out TParentRoute extends AnyServerRouteWithTypes, in out TFullPath extends string, in out TMiddlewares, in out TMethodMiddlewares> {
|
|
77
|
+
context: Expand<AssignAllMethodContext<TParentRoute, TMiddlewares, TMethodMiddlewares>>;
|
|
78
|
+
request: Request;
|
|
79
|
+
params: ResolveParams<TFullPath>;
|
|
80
|
+
pathname: TFullPath;
|
|
81
|
+
}
|
|
82
|
+
export type MergeMethodMiddlewares<TMiddlewares, TMethodMiddlewares> = TMiddlewares extends ReadonlyArray<any> ? TMethodMiddlewares extends ReadonlyArray<any> ? readonly [...TMiddlewares, ...TMethodMiddlewares] : TMiddlewares : TMethodMiddlewares;
|
|
83
|
+
export type AssignAllMethodContext<TParentRoute extends AnyServerRouteWithTypes, TMiddlewares, TMethodMiddlewares> = ResolveAllServerContext<TParentRoute, MergeMethodMiddlewares<TMiddlewares, TMethodMiddlewares>>;
|
|
84
|
+
export type AnyRouteMethodsBuilder = ServerRouteMethodBuilderWithTypes<any, any, any, any>;
|
|
85
|
+
export interface ServerRouteMethodBuilder<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares> extends ServerRouteMethodBuilderWithTypes<TFullPath, TMiddlewares, undefined, undefined>, ServerRouteMethodBuilderMiddleware<TParentRoute, TFullPath, TMiddlewares>, ServerRouteMethodBuilderHandler<TParentRoute, TFullPath, TMiddlewares, undefined> {
|
|
86
|
+
}
|
|
87
|
+
export interface ServerRouteMethodBuilderWithTypes<TFullPath extends string, TMiddlewares, TMethodMiddlewares, TResponse> {
|
|
88
|
+
_options: TODO;
|
|
89
|
+
_types: ServerRouteMethodBuilderTypes<TFullPath, TMiddlewares, TMethodMiddlewares, TResponse>;
|
|
90
|
+
}
|
|
91
|
+
export interface ServerRouteMethodBuilderTypes<in out TFullPath extends string, in out TMiddlewares, in out TMethodMiddlewares, in out TResponse> {
|
|
92
|
+
middlewares: TMiddlewares;
|
|
93
|
+
methodMiddleware: TMethodMiddlewares;
|
|
94
|
+
fullPath: TFullPath;
|
|
95
|
+
response: TResponse;
|
|
96
|
+
}
|
|
97
|
+
export interface ServerRouteMethodBuilderMiddleware<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares> {
|
|
98
|
+
middleware: <const TNewMethodMiddlewares>(middleware: Constrain<TNewMethodMiddlewares, ReadonlyArray<AnyRequestMiddleware>>) => ServerRouteMethodBuilderAfterMiddleware<TParentRoute, TFullPath, TMiddlewares, TNewMethodMiddlewares>;
|
|
99
|
+
}
|
|
100
|
+
export interface ServerRouteMethodBuilderAfterMiddleware<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares> extends ServerRouteMethodBuilderWithTypes<TFullPath, TMiddlewares, TMethodMiddlewares, undefined>, ServerRouteMethodBuilderHandler<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares> {
|
|
101
|
+
}
|
|
102
|
+
export interface ServerRouteMethodBuilderHandler<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares> {
|
|
103
|
+
handler: <TResponse>(handler: ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares, TResponse>) => ServerRouteMethodBuilderAfterHandler<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares, TResponse>;
|
|
104
|
+
}
|
|
105
|
+
export interface ServerRouteMethodBuilderAfterHandler<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares, TResponse> extends ServerRouteMethodBuilderWithTypes<TFullPath, TMiddlewares, TMethodMiddlewares, TResponse> {
|
|
106
|
+
opts: ServerRouteMethod<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares>;
|
|
107
|
+
}
|
|
108
|
+
export interface ServerRouteMethod<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares> {
|
|
109
|
+
middleware?: Constrain<TMiddlewares, Array<AnyRequestMiddleware>>;
|
|
110
|
+
handler?: ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares, undefined>;
|
|
111
|
+
}
|
|
112
|
+
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> {
|
|
113
|
+
options: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, TMiddlewares>;
|
|
114
|
+
}
|
|
115
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const undici = require("undici");
|
|
4
|
+
const __setGlobalOrigin = undici.setGlobalOrigin;
|
|
5
|
+
function __getAbsoluteUrl(req, options = { trustProxy: false }) {
|
|
6
|
+
const headers = req.headers;
|
|
7
|
+
const host = options.trustProxy ? headers.get("x-forwarded-host") || headers.get("host") : headers.get("host");
|
|
8
|
+
const protocol = options.trustProxy ? headers.get("x-forwarded-proto") || "http" : "http";
|
|
9
|
+
if (!host) throw new Error("Cannot determine host from request headers");
|
|
10
|
+
return `${protocol}://${host}`;
|
|
11
|
+
}
|
|
12
|
+
exports.__getAbsoluteUrl = __getAbsoluteUrl;
|
|
13
|
+
exports.__setGlobalOrigin = __setGlobalOrigin;
|
|
14
|
+
//# sourceMappingURL=undici.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"undici.cjs","sources":["../../src/undici.ts"],"sourcesContent":["import { setGlobalOrigin } from 'undici'\n\n/**\n * DO NOT USE THIS FUNCTION. THIS FUNCTION IS FOR INTERNAL USE ONLY.\n *\n * @internal\n */\nexport const __setGlobalOrigin = setGlobalOrigin\n\n/**\n * DO NOT USE THIS FUNCTION. THIS FUNCTION IS FOR INTERNAL USE ONLY.\n *\n * Constructs an absolute URL from the given request object and options.\n *\n * @internal\n * @param req - The `Request` object containing the headers to extract the host and protocol.\n * @param options - Configuration options for determining the trust level of proxy headers.\n * @param options.trustProxy - If `true`, the function will trust the `x-forwarded-host` and `x-forwarded-proto` headers\n * to determine the host and protocol. Defaults to `false`.\n * @returns The absolute URL constructed from the request headers as a string.\n * @throws Will throw an error if the `host` cannot be determined from the request headers.\n *\n * @example\n * ```ts\n * // Example usage:\n * const req = new Request('http://example.com', {\n * headers: {\n * 'host': 'example.com',\n * 'x-forwarded-host': 'proxy.example.com',\n * 'x-forwarded-proto': 'https',\n * },\n * });\n *\n * // Without trusting proxy headers\n * const url1 = getAbsoluteUrl(req);\n * console.log(url1); // Output: \"http://example.com\"\n *\n * // With trusting proxy headers\n * const url2 = getAbsoluteUrl(req, { trustProxy: true });\n * console.log(url2); // Output: \"https://proxy.example.com\"\n * ```\n */\nexport function __getAbsoluteUrl(\n req: Request,\n options: { trustProxy: boolean } = { trustProxy: false },\n): string {\n const headers = req.headers\n\n const host = options.trustProxy\n ? headers.get('x-forwarded-host') || headers.get('host')\n : headers.get('host')\n\n const protocol = options.trustProxy\n ? headers.get('x-forwarded-proto') || 'http'\n : 'http'\n\n if (!host) throw new Error('Cannot determine host from request headers')\n\n return `${protocol}://${host}`\n}\n"],"names":["setGlobalOrigin"],"mappings":";;;AAOO,MAAM,oBAAoBA,OAAAA;AAmC1B,SAAS,iBACd,KACA,UAAmC,EAAE,YAAY,SACzC;AACR,QAAM,UAAU,IAAI;AAEpB,QAAM,OAAO,QAAQ,aACjB,QAAQ,IAAI,kBAAkB,KAAK,QAAQ,IAAI,MAAM,IACrD,QAAQ,IAAI,MAAM;AAEtB,QAAM,WAAW,QAAQ,aACrB,QAAQ,IAAI,mBAAmB,KAAK,SACpC;AAEJ,MAAI,CAAC,KAAY,OAAA,IAAI,MAAM,4CAA4C;AAEhE,SAAA,GAAG,QAAQ,MAAM,IAAI;AAC9B;;;"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { setGlobalOrigin } from 'undici';
|
|
2
|
+
/**
|
|
3
|
+
* DO NOT USE THIS FUNCTION. THIS FUNCTION IS FOR INTERNAL USE ONLY.
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare const __setGlobalOrigin: typeof setGlobalOrigin;
|
|
8
|
+
/**
|
|
9
|
+
* DO NOT USE THIS FUNCTION. THIS FUNCTION IS FOR INTERNAL USE ONLY.
|
|
10
|
+
*
|
|
11
|
+
* Constructs an absolute URL from the given request object and options.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
* @param req - The `Request` object containing the headers to extract the host and protocol.
|
|
15
|
+
* @param options - Configuration options for determining the trust level of proxy headers.
|
|
16
|
+
* @param options.trustProxy - If `true`, the function will trust the `x-forwarded-host` and `x-forwarded-proto` headers
|
|
17
|
+
* to determine the host and protocol. Defaults to `false`.
|
|
18
|
+
* @returns The absolute URL constructed from the request headers as a string.
|
|
19
|
+
* @throws Will throw an error if the `host` cannot be determined from the request headers.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* // Example usage:
|
|
24
|
+
* const req = new Request('http://example.com', {
|
|
25
|
+
* headers: {
|
|
26
|
+
* 'host': 'example.com',
|
|
27
|
+
* 'x-forwarded-host': 'proxy.example.com',
|
|
28
|
+
* 'x-forwarded-proto': 'https',
|
|
29
|
+
* },
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // Without trusting proxy headers
|
|
33
|
+
* const url1 = getAbsoluteUrl(req);
|
|
34
|
+
* console.log(url1); // Output: "http://example.com"
|
|
35
|
+
*
|
|
36
|
+
* // With trusting proxy headers
|
|
37
|
+
* const url2 = getAbsoluteUrl(req, { trustProxy: true });
|
|
38
|
+
* console.log(url2); // Output: "https://proxy.example.com"
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function __getAbsoluteUrl(req: Request, options?: {
|
|
42
|
+
trustProxy: boolean;
|
|
43
|
+
}): string;
|
|
@@ -40,9 +40,7 @@ function getRequestHeaders(opts) {
|
|
|
40
40
|
);
|
|
41
41
|
const { redirect } = opts.router.state;
|
|
42
42
|
if (redirect) {
|
|
43
|
-
headers = mergeHeaders(headers, redirect.headers
|
|
44
|
-
Location: redirect.href
|
|
45
|
-
});
|
|
43
|
+
headers = mergeHeaders(headers, redirect.headers);
|
|
46
44
|
}
|
|
47
45
|
return headers;
|
|
48
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRequestHandler.js","sources":["../../src/createRequestHandler.ts"],"sourcesContent":["import { createMemoryHistory } from '@tanstack/history'\nimport { mergeHeaders } from '@tanstack/start-client-core'\nimport { attachRouterServerSsrUtils, dehydrateRouter } from './ssr-server'\nimport type { HandlerCallback } from './handlerCallback'\nimport type { AnyRouter, Manifest } from '@tanstack/router-core'\n\nexport type RequestHandler<TRouter extends AnyRouter> = (\n cb: HandlerCallback<TRouter>,\n) => Promise<Response>\n\nexport function createRequestHandler<TRouter extends AnyRouter>({\n createRouter,\n request,\n getRouterManifest,\n}: {\n createRouter: () => TRouter\n request: Request\n getRouterManifest?: () => Manifest | Promise<Manifest>\n}): RequestHandler<TRouter> {\n return async (cb) => {\n const router = createRouter()\n\n attachRouterServerSsrUtils(router, await getRouterManifest?.())\n\n const url = new URL(request.url, 'http://localhost')\n\n const href = url.href.replace(url.origin, '')\n\n // Create a history for the router\n const history = createMemoryHistory({\n initialEntries: [href],\n })\n\n // Update the router with the history and context\n router.update({\n history,\n })\n\n await router.load()\n\n dehydrateRouter(router)\n\n const responseHeaders = getRequestHeaders({\n router,\n })\n\n return cb({\n request,\n router,\n responseHeaders,\n } as any)\n }\n}\n\nfunction getRequestHeaders(opts: { router: AnyRouter }): Headers {\n let headers = mergeHeaders(\n {\n 'Content-Type': 'text/html; charset=UTF-8',\n },\n ...opts.router.state.matches.map((match) => {\n return match.headers\n }),\n )\n\n // Handle Redirects\n const { redirect } = opts.router.state\n\n if (redirect) {\n headers = mergeHeaders(headers, redirect.headers
|
|
1
|
+
{"version":3,"file":"createRequestHandler.js","sources":["../../src/createRequestHandler.ts"],"sourcesContent":["import { createMemoryHistory } from '@tanstack/history'\nimport { mergeHeaders } from '@tanstack/start-client-core'\nimport { attachRouterServerSsrUtils, dehydrateRouter } from './ssr-server'\nimport type { HandlerCallback } from './handlerCallback'\nimport type { AnyRouter, Manifest } from '@tanstack/router-core'\n\nexport type RequestHandler<TRouter extends AnyRouter> = (\n cb: HandlerCallback<TRouter>,\n) => Promise<Response>\n\nexport function createRequestHandler<TRouter extends AnyRouter>({\n createRouter,\n request,\n getRouterManifest,\n}: {\n createRouter: () => TRouter\n request: Request\n getRouterManifest?: () => Manifest | Promise<Manifest>\n}): RequestHandler<TRouter> {\n return async (cb) => {\n const router = createRouter()\n\n attachRouterServerSsrUtils(router, await getRouterManifest?.())\n\n const url = new URL(request.url, 'http://localhost')\n\n const href = url.href.replace(url.origin, '')\n\n // Create a history for the router\n const history = createMemoryHistory({\n initialEntries: [href],\n })\n\n // Update the router with the history and context\n router.update({\n history,\n })\n\n await router.load()\n\n dehydrateRouter(router)\n\n const responseHeaders = getRequestHeaders({\n router,\n })\n\n return cb({\n request,\n router,\n responseHeaders,\n } as any)\n }\n}\n\nfunction getRequestHeaders(opts: { router: AnyRouter }): Headers {\n let headers = mergeHeaders(\n {\n 'Content-Type': 'text/html; charset=UTF-8',\n },\n ...opts.router.state.matches.map((match) => {\n return match.headers\n }),\n )\n\n // Handle Redirects\n const { redirect } = opts.router.state\n\n if (redirect) {\n headers = mergeHeaders(headers, redirect.headers)\n }\n\n return headers\n}\n"],"names":[],"mappings":";;;AAUO,SAAS,qBAAgD;AAAA,EAC9D;AAAA,EACA;AAAA,EACA;AACF,GAI4B;AAC1B,SAAO,OAAO,OAAO;AACnB,UAAM,SAAS,aAAa;AAED,+BAAA,QAAQ,OAAM,yDAAqB;AAE9D,UAAM,MAAM,IAAI,IAAI,QAAQ,KAAK,kBAAkB;AAEnD,UAAM,OAAO,IAAI,KAAK,QAAQ,IAAI,QAAQ,EAAE;AAG5C,UAAM,UAAU,oBAAoB;AAAA,MAClC,gBAAgB,CAAC,IAAI;AAAA,IAAA,CACtB;AAGD,WAAO,OAAO;AAAA,MACZ;AAAA,IAAA,CACD;AAED,UAAM,OAAO,KAAK;AAElB,oBAAgB,MAAM;AAEtB,UAAM,kBAAkB,kBAAkB;AAAA,MACxC;AAAA,IAAA,CACD;AAED,WAAO,GAAG;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACM;AAAA,EACV;AACF;AAEA,SAAS,kBAAkB,MAAsC;AAC/D,MAAI,UAAU;AAAA,IACZ;AAAA,MACE,gBAAgB;AAAA,IAClB;AAAA,IACA,GAAG,KAAK,OAAO,MAAM,QAAQ,IAAI,CAAC,UAAU;AAC1C,aAAO,MAAM;AAAA,IACd,CAAA;AAAA,EACH;AAGA,QAAM,EAAE,SAAA,IAAa,KAAK,OAAO;AAEjC,MAAI,UAAU;AACF,cAAA,aAAa,SAAS,SAAS,OAAO;AAAA,EAAA;AAG3C,SAAA;AACT;"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RequestHandler } from './h3.js';
|
|
2
|
+
import { AnyRouter } from '@tanstack/router-core';
|
|
2
3
|
import { HandlerCallback } from './handlerCallback.js';
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
4
|
+
export type CustomizeStartHandler<TRouter extends AnyRouter> = (cb: HandlerCallback<TRouter>) => RequestHandler;
|
|
5
|
+
export declare function getStartResponseHeaders(opts: {
|
|
6
|
+
router: AnyRouter;
|
|
7
|
+
}): Headers;
|
|
8
|
+
export declare function createStartHandler<TRouter extends AnyRouter>({ createRouter, }: {
|
|
6
9
|
createRouter: () => TRouter;
|
|
7
|
-
|
|
8
|
-
}): CustomizeStartHandler<TRouter, TResponse>;
|
|
10
|
+
}): CustomizeStartHandler<TRouter>;
|
|
@@ -1,56 +1,232 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
import { createMemoryHistory } from "@tanstack/history";
|
|
2
|
-
import { mergeHeaders } from "@tanstack/start-client-core";
|
|
3
|
-
import {
|
|
3
|
+
import { mergeHeaders, json, flattenMiddlewares } from "@tanstack/start-client-core";
|
|
4
|
+
import { isRedirect, tsrRedirectHeaderKey, processRouteTree, getMatchedRoutes, rootRouteId } from "@tanstack/router-core";
|
|
5
|
+
import { getResponseHeaders, requestHandler } from "./h3.js";
|
|
4
6
|
import { attachRouterServerSsrUtils, dehydrateRouter } from "./ssr-server.js";
|
|
7
|
+
import { getStartManifest } from "./router-manifest.js";
|
|
8
|
+
import { handleServerAction } from "./server-functions-handler.js";
|
|
9
|
+
function getStartResponseHeaders(opts) {
|
|
10
|
+
let headers = mergeHeaders(
|
|
11
|
+
getResponseHeaders(),
|
|
12
|
+
{
|
|
13
|
+
"Content-Type": "text/html; charset=UTF-8"
|
|
14
|
+
},
|
|
15
|
+
...opts.router.state.matches.map((match) => {
|
|
16
|
+
return match.headers;
|
|
17
|
+
})
|
|
18
|
+
);
|
|
19
|
+
const { redirect } = opts.router.state;
|
|
20
|
+
if (redirect) {
|
|
21
|
+
headers = mergeHeaders(headers, redirect.headers);
|
|
22
|
+
}
|
|
23
|
+
return headers;
|
|
24
|
+
}
|
|
5
25
|
function createStartHandler({
|
|
6
|
-
createRouter
|
|
7
|
-
getRouterManifest
|
|
26
|
+
createRouter
|
|
8
27
|
}) {
|
|
9
28
|
return (cb) => {
|
|
10
|
-
return
|
|
11
|
-
const request = toWebRequest(event);
|
|
29
|
+
return requestHandler(async ({ request }) => {
|
|
12
30
|
const url = new URL(request.url);
|
|
13
31
|
const href = url.href.replace(url.origin, "");
|
|
14
32
|
const history = createMemoryHistory({
|
|
15
33
|
initialEntries: [href]
|
|
16
34
|
});
|
|
17
35
|
const router = createRouter();
|
|
18
|
-
attachRouterServerSsrUtils(router,
|
|
36
|
+
attachRouterServerSsrUtils(router, getStartManifest());
|
|
19
37
|
router.update({
|
|
20
38
|
history
|
|
21
39
|
});
|
|
22
|
-
await
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
40
|
+
const response = await (async () => {
|
|
41
|
+
try {
|
|
42
|
+
if (!process.env.TSS_SERVER_FN_BASE) {
|
|
43
|
+
throw new Error(
|
|
44
|
+
"tanstack/start-server-core: TSS_SERVER_FN_BASE must be defined in your environment for createStartHandler()"
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
if (href.startsWith(path.join("/", process.env.TSS_SERVER_FN_BASE, "/"))) {
|
|
48
|
+
return await handleServerAction({ request });
|
|
49
|
+
}
|
|
50
|
+
const serverRouteTreeModule = await (async () => {
|
|
51
|
+
try {
|
|
52
|
+
return await import("tanstack:server-routes");
|
|
53
|
+
} catch (e) {
|
|
54
|
+
console.log(e);
|
|
55
|
+
return void 0;
|
|
56
|
+
}
|
|
57
|
+
})();
|
|
58
|
+
if (serverRouteTreeModule) {
|
|
59
|
+
const [matchedRoutes, response3] = await handleServerRoutes({
|
|
60
|
+
routeTree: serverRouteTreeModule.routeTree,
|
|
61
|
+
request
|
|
62
|
+
});
|
|
63
|
+
if (response3) return response3;
|
|
64
|
+
}
|
|
65
|
+
const requestAcceptHeader = request.headers.get("Accept") || "*/*";
|
|
66
|
+
const splitRequestAcceptHeader = requestAcceptHeader.split(",");
|
|
67
|
+
const supportedMimeTypes = ["*/*", "text/html"];
|
|
68
|
+
const isRouterAcceptSupported = supportedMimeTypes.some(
|
|
69
|
+
(mimeType) => splitRequestAcceptHeader.some(
|
|
70
|
+
(acceptedMimeType) => acceptedMimeType.trim().startsWith(mimeType)
|
|
71
|
+
)
|
|
72
|
+
);
|
|
73
|
+
if (!isRouterAcceptSupported) {
|
|
74
|
+
return json(
|
|
75
|
+
{
|
|
76
|
+
error: "Only HTML requests are supported here"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
status: 500
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
await router.load();
|
|
84
|
+
if (router.state.redirect) return router.state.redirect;
|
|
85
|
+
dehydrateRouter(router);
|
|
86
|
+
const responseHeaders = getStartResponseHeaders({ router });
|
|
87
|
+
const response2 = await cb({
|
|
88
|
+
request,
|
|
89
|
+
router,
|
|
90
|
+
responseHeaders
|
|
91
|
+
});
|
|
92
|
+
return response2;
|
|
93
|
+
} catch (err) {
|
|
94
|
+
if (err instanceof Response) {
|
|
95
|
+
return err;
|
|
96
|
+
}
|
|
97
|
+
throw err;
|
|
98
|
+
}
|
|
99
|
+
})();
|
|
100
|
+
if (isRedirect(response)) {
|
|
101
|
+
if (response.options.to && typeof response.options.to === "string" && !response.options.to.startsWith("/")) {
|
|
102
|
+
throw new Error(
|
|
103
|
+
`Server side redirects must use absolute paths via the 'href' or 'to' options. Received: ${JSON.stringify(response.options)}`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
if (["params", "search", "hash"].some(
|
|
107
|
+
(d) => typeof response.options[d] === "function"
|
|
108
|
+
)) {
|
|
109
|
+
throw new Error(
|
|
110
|
+
`Server side redirects must use static search, params, and hash values and do not support functional values. Received functional values for: ${Object.keys(
|
|
111
|
+
response.options
|
|
112
|
+
).filter((d) => typeof response.options[d] === "function").map((d) => `"${d}"`).join(", ")}`
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
const redirect = router.resolveRedirect(response);
|
|
116
|
+
if (request.headers.get("x-tsr-redirect") === "manual") {
|
|
117
|
+
return json(
|
|
118
|
+
{
|
|
119
|
+
...response.options,
|
|
120
|
+
isSerializedRedirect: true
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
headers: redirect.headers
|
|
124
|
+
}
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
return redirect;
|
|
128
|
+
}
|
|
129
|
+
response.headers.append(
|
|
130
|
+
"Access-Control-Expose-Headers",
|
|
131
|
+
tsrRedirectHeaderKey
|
|
132
|
+
);
|
|
30
133
|
return response;
|
|
31
134
|
});
|
|
32
135
|
};
|
|
33
136
|
}
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
137
|
+
async function handleServerRoutes({
|
|
138
|
+
routeTree,
|
|
139
|
+
request
|
|
140
|
+
}) {
|
|
141
|
+
const { flatRoutes, routesById, routesByPath } = processRouteTree({
|
|
142
|
+
routeTree,
|
|
143
|
+
initRoute: (route, i) => {
|
|
144
|
+
route.init({
|
|
145
|
+
originalIndex: i
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
const url = new URL(request.url);
|
|
150
|
+
const pathname = url.pathname;
|
|
151
|
+
const history = createMemoryHistory({
|
|
152
|
+
initialEntries: [pathname]
|
|
153
|
+
});
|
|
154
|
+
const { matchedRoutes, foundRoute, routeParams } = getMatchedRoutes({
|
|
155
|
+
pathname: history.location.pathname,
|
|
156
|
+
basepath: "/",
|
|
157
|
+
caseSensitive: true,
|
|
158
|
+
routesByPath,
|
|
159
|
+
routesById,
|
|
160
|
+
flatRoutes
|
|
161
|
+
});
|
|
162
|
+
let response;
|
|
163
|
+
if (foundRoute && foundRoute.id !== rootRouteId) {
|
|
164
|
+
const method = Object.keys(foundRoute.options.methods).find(
|
|
165
|
+
(method2) => method2.toLowerCase() === request.method.toLowerCase()
|
|
166
|
+
);
|
|
167
|
+
if (method) {
|
|
168
|
+
const handler = foundRoute.options.methods[method];
|
|
169
|
+
if (handler) {
|
|
170
|
+
const middlewares = flattenMiddlewares(
|
|
171
|
+
matchedRoutes.flatMap((r) => r.options.middleware).filter(Boolean)
|
|
172
|
+
).map((d) => d.options.server);
|
|
173
|
+
middlewares.push(handlerToMiddleware(handler));
|
|
174
|
+
const ctx = await executeMiddleware(middlewares, {
|
|
175
|
+
request,
|
|
176
|
+
context: {},
|
|
177
|
+
params: routeParams,
|
|
178
|
+
pathname: history.location.pathname
|
|
179
|
+
});
|
|
180
|
+
response = ctx.response;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return [matchedRoutes, response];
|
|
185
|
+
}
|
|
186
|
+
function handlerToMiddleware(handler) {
|
|
187
|
+
return async ({ next, ...rest }) => ({
|
|
188
|
+
response: await handler(rest)
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
function executeMiddleware(middlewares, ctx) {
|
|
192
|
+
let index = -1;
|
|
193
|
+
const next = async (ctx2) => {
|
|
194
|
+
index++;
|
|
195
|
+
const middleware = middlewares[index];
|
|
196
|
+
if (!middleware) return ctx2;
|
|
197
|
+
const result = await middleware({
|
|
198
|
+
...ctx2,
|
|
199
|
+
// Allow the middleware to call the next middleware in the chain
|
|
200
|
+
next: async (nextCtx) => {
|
|
201
|
+
const nextResult = await next({ ...ctx2, ...nextCtx });
|
|
202
|
+
return Object.assign(ctx2, handleCtxResult(nextResult));
|
|
203
|
+
}
|
|
204
|
+
// Allow the middleware result to extend the return context
|
|
205
|
+
}).catch((err) => {
|
|
206
|
+
if (isSpecialResponse(err)) {
|
|
207
|
+
return {
|
|
208
|
+
response: err
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
throw err;
|
|
49
212
|
});
|
|
213
|
+
return Object.assign(ctx2, handleCtxResult(result));
|
|
214
|
+
};
|
|
215
|
+
return handleCtxResult(next(ctx));
|
|
216
|
+
}
|
|
217
|
+
function handleCtxResult(result) {
|
|
218
|
+
if (isSpecialResponse(result)) {
|
|
219
|
+
return {
|
|
220
|
+
response: result
|
|
221
|
+
};
|
|
50
222
|
}
|
|
51
|
-
return
|
|
223
|
+
return result;
|
|
224
|
+
}
|
|
225
|
+
function isSpecialResponse(err) {
|
|
226
|
+
return err instanceof Response || isRedirect(err);
|
|
52
227
|
}
|
|
53
228
|
export {
|
|
54
|
-
createStartHandler
|
|
229
|
+
createStartHandler,
|
|
230
|
+
getStartResponseHeaders
|
|
55
231
|
};
|
|
56
232
|
//# sourceMappingURL=createStartHandler.js.map
|