@tanstack/start-server-core 1.132.0-alpha.9 → 1.132.0
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/esm/createStartHandler.d.ts +3 -6
- package/dist/esm/createStartHandler.js +261 -220
- package/dist/esm/createStartHandler.js.map +1 -1
- package/dist/esm/index.d.ts +1 -3
- package/dist/esm/index.js +0 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/loadVirtualModule.js +0 -2
- package/dist/esm/loadVirtualModule.js.map +1 -1
- package/dist/esm/request-handler.d.ts +19 -0
- package/dist/esm/request-response.d.ts +2 -2
- package/dist/esm/request-response.js +5 -2
- package/dist/esm/request-response.js.map +1 -1
- package/dist/esm/serializer/ServerFunctionSerializationAdapter.js +1 -1
- package/dist/esm/serializer/ServerFunctionSerializationAdapter.js.map +1 -1
- package/dist/esm/server-functions-handler.d.ts +2 -1
- package/dist/esm/server-functions-handler.js +16 -13
- package/dist/esm/server-functions-handler.js.map +1 -1
- package/dist/esm/virtual-modules.d.ts +0 -2
- package/dist/esm/virtual-modules.js +0 -1
- package/dist/esm/virtual-modules.js.map +1 -1
- package/package.json +7 -7
- package/src/createStartHandler.ts +353 -326
- package/src/index.tsx +2 -42
- package/src/loadVirtualModule.ts +0 -2
- package/src/request-handler.ts +31 -0
- package/src/request-response.ts +8 -5
- package/src/serializer/ServerFunctionSerializationAdapter.ts +1 -1
- package/src/server-functions-handler.ts +21 -16
- package/src/tanstack-start.d.ts +0 -2
- package/src/virtual-modules.ts +0 -2
- package/dist/esm/serializer/getSerovalPlugins.d.ts +0 -3
- package/dist/esm/serializer/getSerovalPlugins.js +0 -13
- package/dist/esm/serializer/getSerovalPlugins.js.map +0 -1
- package/dist/esm/serverRoute.d.ts +0 -124
- package/dist/esm/serverRoute.js +0 -103
- package/dist/esm/serverRoute.js.map +0 -1
- package/src/serializer/getSerovalPlugins.ts +0 -10
- package/src/serverRoute.ts +0 -736
package/src/index.tsx
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { createStartHandler } from './createStartHandler'
|
|
2
|
-
export type { CustomizeStartHandler } from './createStartHandler'
|
|
3
2
|
|
|
4
3
|
export {
|
|
5
4
|
attachRouterServerSsrUtils,
|
|
@@ -14,49 +13,10 @@ export { handleServerAction } from './server-functions-handler'
|
|
|
14
13
|
|
|
15
14
|
export * from './request-response'
|
|
16
15
|
|
|
17
|
-
export {
|
|
18
|
-
createServerRoute,
|
|
19
|
-
createServerFileRoute,
|
|
20
|
-
createServerRootRoute,
|
|
21
|
-
} from './serverRoute'
|
|
22
|
-
export type {
|
|
23
|
-
CreateServerFileRoute,
|
|
24
|
-
ServerFileRoutesByPath,
|
|
25
|
-
ServerRouteOptions,
|
|
26
|
-
ServerRouteManifest,
|
|
27
|
-
ServerRouteAddFileChildrenFn,
|
|
28
|
-
ServerRouteMethodBuilderOptions,
|
|
29
|
-
AnyServerRouteWithTypes,
|
|
30
|
-
ServerRouteWithTypes,
|
|
31
|
-
ServerRouteTypes,
|
|
32
|
-
ResolveAllServerContext,
|
|
33
|
-
AnyServerRoute,
|
|
34
|
-
ServerRoute,
|
|
35
|
-
ServerRouteMiddleware,
|
|
36
|
-
ServerRouteAfterMiddleware,
|
|
37
|
-
ServerRouteMethods,
|
|
38
|
-
ServerRouteMethodsOptions,
|
|
39
|
-
ServerRouteMethodsRecord,
|
|
40
|
-
ServerRouteMethodRecordValue,
|
|
41
|
-
ServerRouteVerb,
|
|
42
|
-
ServerRouteMethodHandlerFn,
|
|
43
|
-
ServerRouteMethodHandlerCtx,
|
|
44
|
-
MergeMethodMiddlewares,
|
|
45
|
-
AssignAllMethodContext,
|
|
46
|
-
AnyRouteMethodsBuilder,
|
|
47
|
-
ServerRouteMethodBuilder,
|
|
48
|
-
ServerRouteMethodBuilderWithTypes,
|
|
49
|
-
ServerRouteMethodBuilderTypes,
|
|
50
|
-
ServerRouteMethodBuilderMiddleware,
|
|
51
|
-
ServerRouteMethodBuilderAfterMiddleware,
|
|
52
|
-
ServerRouteMethodBuilderHandler,
|
|
53
|
-
ServerRouteMethodBuilderAfterHandler,
|
|
54
|
-
ServerRouteMethod,
|
|
55
|
-
ServerRouteAfterMethods,
|
|
56
|
-
} from './serverRoute'
|
|
57
|
-
|
|
58
16
|
export * from './virtual-modules'
|
|
59
17
|
|
|
60
18
|
export { HEADERS } from './constants'
|
|
61
19
|
|
|
62
20
|
export { createServerRpc } from './createServerRpc'
|
|
21
|
+
|
|
22
|
+
export type { RequestHandler, RequestOptions } from './request-handler'
|
package/src/loadVirtualModule.ts
CHANGED
|
@@ -9,8 +9,6 @@ export async function loadVirtualModule<TId extends keyof VirtualModules>(
|
|
|
9
9
|
id: TId,
|
|
10
10
|
): Promise<VirtualModules[TId]> {
|
|
11
11
|
switch (id) {
|
|
12
|
-
case VIRTUAL_MODULES.routeTree:
|
|
13
|
-
return (await import('tanstack-start-route-tree:v')) as any
|
|
14
12
|
case VIRTUAL_MODULES.startManifest:
|
|
15
13
|
return (await import('tanstack-start-manifest:v')) as any
|
|
16
14
|
case VIRTUAL_MODULES.serverFnManifest:
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
type BaseContext = {
|
|
2
|
+
nonce?: string
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export type RequestOptions<TRegister> = TRegister extends {
|
|
6
|
+
server: { requestContext: infer TRequestContext }
|
|
7
|
+
}
|
|
8
|
+
? TRequestContext extends undefined
|
|
9
|
+
? { context?: TRequestContext & BaseContext }
|
|
10
|
+
: { context: TRequestContext & BaseContext }
|
|
11
|
+
: { context?: BaseContext }
|
|
12
|
+
|
|
13
|
+
// Utility type: true if T has any required keys, else false
|
|
14
|
+
type HasRequired<T> = keyof T extends never
|
|
15
|
+
? false
|
|
16
|
+
: {
|
|
17
|
+
[K in keyof T]-?: undefined extends T[K] ? never : K
|
|
18
|
+
}[keyof T] extends never
|
|
19
|
+
? false
|
|
20
|
+
: true
|
|
21
|
+
|
|
22
|
+
export type RequestHandler<TRegister> =
|
|
23
|
+
HasRequired<RequestOptions<TRegister>> extends true
|
|
24
|
+
? (
|
|
25
|
+
request: Request,
|
|
26
|
+
opts: RequestOptions<TRegister>,
|
|
27
|
+
) => Promise<Response> | Response
|
|
28
|
+
: (
|
|
29
|
+
request: Request,
|
|
30
|
+
opts?: RequestOptions<TRegister>,
|
|
31
|
+
) => Promise<Response> | Response
|
package/src/request-response.ts
CHANGED
|
@@ -37,21 +37,24 @@ import type {
|
|
|
37
37
|
SessionUpdate,
|
|
38
38
|
} from './session'
|
|
39
39
|
import type { StandardSchemaV1 } from '@standard-schema/spec'
|
|
40
|
+
import type { RequestHandler } from './request-handler'
|
|
40
41
|
|
|
41
42
|
interface StartEvent {
|
|
42
43
|
h3Event: H3Event
|
|
43
44
|
}
|
|
44
45
|
const eventStorage = new AsyncLocalStorage<StartEvent>()
|
|
45
46
|
|
|
46
|
-
export type RequestHandler = (request: Request) => Promise<Response> | Response
|
|
47
|
-
|
|
48
47
|
export type { ResponseHeaderName, RequestHeaderName }
|
|
49
48
|
|
|
50
|
-
export function requestHandler
|
|
51
|
-
|
|
49
|
+
export function requestHandler<TRegister = unknown>(
|
|
50
|
+
handler: RequestHandler<TRegister>,
|
|
51
|
+
) {
|
|
52
|
+
return (request: Request, requestOpts: any): Promise<Response> | Response => {
|
|
52
53
|
const h3Event = new H3Event(request)
|
|
53
54
|
|
|
54
|
-
const response = eventStorage.run({ h3Event }, () =>
|
|
55
|
+
const response = eventStorage.run({ h3Event }, () =>
|
|
56
|
+
handler(request, requestOpts),
|
|
57
|
+
)
|
|
55
58
|
return h3_toResponse(response, h3Event)
|
|
56
59
|
}
|
|
57
60
|
}
|
|
@@ -6,7 +6,7 @@ import { getServerFnById } from '../getServerFnById'
|
|
|
6
6
|
export const ServerFunctionSerializationAdapter = createSerializationAdapter({
|
|
7
7
|
key: '$TSS/serverfn',
|
|
8
8
|
test: (v): v is { functionId: string } => {
|
|
9
|
-
if (typeof v !== '
|
|
9
|
+
if (typeof v !== 'function') return false
|
|
10
10
|
|
|
11
11
|
if (!(TSS_SERVER_FUNCTION in v)) return false
|
|
12
12
|
|
|
@@ -3,11 +3,11 @@ import invariant from 'tiny-invariant'
|
|
|
3
3
|
import {
|
|
4
4
|
TSS_FORMDATA_CONTEXT,
|
|
5
5
|
X_TSS_SERIALIZED,
|
|
6
|
+
getDefaultSerovalPlugins,
|
|
6
7
|
} from '@tanstack/start-client-core'
|
|
7
8
|
import { fromJSON, toCrossJSONAsync, toCrossJSONStream } from 'seroval'
|
|
8
9
|
import { getResponse } from './request-response'
|
|
9
10
|
import { getServerFnById } from './getServerFnById'
|
|
10
|
-
import { getSerovalPlugins } from './serializer/getSerovalPlugins'
|
|
11
11
|
|
|
12
12
|
function sanitizeBase(base: string | undefined) {
|
|
13
13
|
if (!base) {
|
|
@@ -19,7 +19,13 @@ function sanitizeBase(base: string | undefined) {
|
|
|
19
19
|
return base.replace(/^\/|\/$/g, '')
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export const handleServerAction = async ({
|
|
22
|
+
export const handleServerAction = async ({
|
|
23
|
+
request,
|
|
24
|
+
context,
|
|
25
|
+
}: {
|
|
26
|
+
request: Request
|
|
27
|
+
context: any
|
|
28
|
+
}) => {
|
|
23
29
|
const controller = new AbortController()
|
|
24
30
|
const signal = controller.signal
|
|
25
31
|
const abort = () => controller.abort()
|
|
@@ -42,7 +48,6 @@ export const handleServerAction = async ({ request }: { request: Request }) => {
|
|
|
42
48
|
}
|
|
43
49
|
|
|
44
50
|
const isCreateServerFn = 'createServerFn' in search
|
|
45
|
-
const isRaw = 'raw' in search
|
|
46
51
|
|
|
47
52
|
if (typeof serverFnId !== 'string') {
|
|
48
53
|
throw new Error('Invalid server action param for serverFnId: ' + serverFnId)
|
|
@@ -57,11 +62,11 @@ export const handleServerAction = async ({ request }: { request: Request }) => {
|
|
|
57
62
|
]
|
|
58
63
|
|
|
59
64
|
const contentType = request.headers.get('Content-Type')
|
|
60
|
-
const serovalPlugins =
|
|
65
|
+
const serovalPlugins = getDefaultSerovalPlugins()
|
|
61
66
|
|
|
62
67
|
function parsePayload(payload: any) {
|
|
63
68
|
const parsedPayload = fromJSON(payload, { plugins: serovalPlugins })
|
|
64
|
-
return parsedPayload
|
|
69
|
+
return parsedPayload as any
|
|
65
70
|
}
|
|
66
71
|
|
|
67
72
|
const response = await (async () => {
|
|
@@ -83,12 +88,15 @@ export const handleServerAction = async ({ request }: { request: Request }) => {
|
|
|
83
88
|
formData.delete(TSS_FORMDATA_CONTEXT)
|
|
84
89
|
|
|
85
90
|
const params = {
|
|
86
|
-
context
|
|
91
|
+
context,
|
|
87
92
|
data: formData,
|
|
88
93
|
}
|
|
89
94
|
if (typeof serializedContext === 'string') {
|
|
90
95
|
try {
|
|
91
|
-
|
|
96
|
+
const parsedContext = JSON.parse(serializedContext)
|
|
97
|
+
if (typeof parsedContext === 'object' && parsedContext) {
|
|
98
|
+
params.context = { ...context, ...parsedContext }
|
|
99
|
+
}
|
|
92
100
|
} catch {}
|
|
93
101
|
}
|
|
94
102
|
|
|
@@ -104,8 +112,8 @@ export const handleServerAction = async ({ request }: { request: Request }) => {
|
|
|
104
112
|
// By default the payload is the search params
|
|
105
113
|
let payload: any = search.payload
|
|
106
114
|
// If there's a payload, we should try to parse it
|
|
107
|
-
payload = payload ?
|
|
108
|
-
|
|
115
|
+
payload = payload ? parsePayload(JSON.parse(payload)) : payload
|
|
116
|
+
payload.context = { ...context, ...payload.context }
|
|
109
117
|
// Send it through!
|
|
110
118
|
return await action(payload, signal)
|
|
111
119
|
}
|
|
@@ -121,9 +129,10 @@ export const handleServerAction = async ({ request }: { request: Request }) => {
|
|
|
121
129
|
const jsonPayload = await request.json()
|
|
122
130
|
|
|
123
131
|
// If this POST request was created by createServerFn,
|
|
124
|
-
// its payload
|
|
132
|
+
// its payload will be the only argument
|
|
125
133
|
if (isCreateServerFn) {
|
|
126
|
-
const payload =
|
|
134
|
+
const payload = parsePayload(jsonPayload)
|
|
135
|
+
payload.context = { ...payload.context, ...context }
|
|
127
136
|
return await action(payload, signal)
|
|
128
137
|
}
|
|
129
138
|
|
|
@@ -296,7 +305,7 @@ export const handleServerAction = async ({ request }: { request: Request }) => {
|
|
|
296
305
|
statusText: response?.statusText,
|
|
297
306
|
headers: {
|
|
298
307
|
'Content-Type': 'application/json',
|
|
299
|
-
|
|
308
|
+
[X_TSS_SERIALIZED]: 'true',
|
|
300
309
|
},
|
|
301
310
|
})
|
|
302
311
|
}
|
|
@@ -304,10 +313,6 @@ export const handleServerAction = async ({ request }: { request: Request }) => {
|
|
|
304
313
|
|
|
305
314
|
request.signal.removeEventListener('abort', abort)
|
|
306
315
|
|
|
307
|
-
if (isRaw) {
|
|
308
|
-
return response
|
|
309
|
-
}
|
|
310
|
-
|
|
311
316
|
return response
|
|
312
317
|
}
|
|
313
318
|
|
package/src/tanstack-start.d.ts
CHANGED
|
@@ -5,11 +5,9 @@ declare module 'tanstack-start-manifest:v' {
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
declare module 'tanstack-start-route-tree:v' {
|
|
8
|
-
import type { AnyServerRouteWithTypes } from '@tanstack/start-server-core'
|
|
9
8
|
import type { AnyRoute } from '@tanstack/router-core'
|
|
10
9
|
|
|
11
10
|
export const routeTree: AnyRoute | undefined
|
|
12
|
-
export const serverRouteTree: AnyServerRouteWithTypes | undefined
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
declare module 'tanstack-start-server-fn-manifest:v' {
|
package/src/virtual-modules.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/consistent-type-imports */
|
|
2
2
|
|
|
3
3
|
export const VIRTUAL_MODULES = {
|
|
4
|
-
routeTree: 'tanstack-start-route-tree:v',
|
|
5
4
|
startManifest: 'tanstack-start-manifest:v',
|
|
6
5
|
serverFnManifest: 'tanstack-start-server-fn-manifest:v',
|
|
7
6
|
injectedHeadScripts: 'tanstack-start-injected-head-scripts:v',
|
|
8
7
|
} as const
|
|
9
8
|
|
|
10
9
|
export type VirtualModules = {
|
|
11
|
-
[VIRTUAL_MODULES.routeTree]: typeof import('tanstack-start-route-tree:v')
|
|
12
10
|
[VIRTUAL_MODULES.startManifest]: typeof import('tanstack-start-manifest:v')
|
|
13
11
|
[VIRTUAL_MODULES.serverFnManifest]: typeof import('tanstack-start-server-fn-manifest:v')
|
|
14
12
|
[VIRTUAL_MODULES.injectedHeadScripts]: typeof import('tanstack-start-injected-head-scripts:v')
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export declare function getSerovalPlugins(): (import('seroval').Plugin<Error, any> | import('seroval').Plugin<ReadableStream<any>, any> | import('seroval').Plugin<FormData, any> | import('seroval').Plugin<any, import('seroval').SerovalNode> | import('seroval').Plugin<{
|
|
2
|
-
functionId: string;
|
|
3
|
-
}, import('seroval').SerovalNode>)[];
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { makeSerovalPlugin } from "@tanstack/router-core";
|
|
2
|
-
import { getDefaultSerovalPlugins } from "@tanstack/start-client-core";
|
|
3
|
-
import { ServerFunctionSerializationAdapter } from "./ServerFunctionSerializationAdapter.js";
|
|
4
|
-
function getSerovalPlugins() {
|
|
5
|
-
return [
|
|
6
|
-
...getDefaultSerovalPlugins(),
|
|
7
|
-
makeSerovalPlugin(ServerFunctionSerializationAdapter)
|
|
8
|
-
];
|
|
9
|
-
}
|
|
10
|
-
export {
|
|
11
|
-
getSerovalPlugins
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=getSerovalPlugins.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getSerovalPlugins.js","sources":["../../../src/serializer/getSerovalPlugins.ts"],"sourcesContent":["import { makeSerovalPlugin } from '@tanstack/router-core'\nimport { getDefaultSerovalPlugins } from '@tanstack/start-client-core'\nimport { ServerFunctionSerializationAdapter } from './ServerFunctionSerializationAdapter'\n\nexport function getSerovalPlugins() {\n return [\n ...getDefaultSerovalPlugins(),\n makeSerovalPlugin(ServerFunctionSerializationAdapter),\n ]\n}\n"],"names":[],"mappings":";;;AAIO,SAAS,oBAAoB;AAClC,SAAO;AAAA,IACL,GAAG,yBAAA;AAAA,IACH,kBAAkB,kCAAkC;AAAA,EAAA;AAExD;"}
|
|
@@ -1,124 +0,0 @@
|
|
|
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
|
-
_options: ServerRouteMethodBuilderOptions<TParentRoute, TFullPath, TMiddlewares, unknown, unknown>;
|
|
15
|
-
}>;
|
|
16
|
-
caseSensitive?: boolean;
|
|
17
|
-
}
|
|
18
|
-
export type ServerRouteManifest = {
|
|
19
|
-
middleware: boolean;
|
|
20
|
-
methods: Record<string, {
|
|
21
|
-
middleware: boolean;
|
|
22
|
-
}>;
|
|
23
|
-
};
|
|
24
|
-
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>;
|
|
25
|
-
export declare const createServerRootRoute: typeof createServerRoute;
|
|
26
|
-
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>;
|
|
27
|
-
export interface ServerRouteMethodBuilderOptions<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares, TResponse> {
|
|
28
|
-
handler?: ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares, TResponse>;
|
|
29
|
-
middlewares?: Constrain<TMethodMiddlewares, ReadonlyArray<AnyRequestMiddleware>>;
|
|
30
|
-
}
|
|
31
|
-
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>;
|
|
32
|
-
export type AnyServerRouteWithTypes = ServerRouteWithTypes<any, any, any, any, any, any, any>;
|
|
33
|
-
export interface ServerRouteWithTypes<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TMiddlewares, TMethods, TChildren> {
|
|
34
|
-
_types: ServerRouteTypes<TParentRoute, TId, TPath, TFullPath, TMiddlewares, TMethods>;
|
|
35
|
-
isRoot: TParentRoute extends AnyServerRouteWithTypes ? true : false;
|
|
36
|
-
path: TPath;
|
|
37
|
-
id: TId;
|
|
38
|
-
fullPath: TFullPath;
|
|
39
|
-
to: TrimPathRight<TFullPath>;
|
|
40
|
-
parentRoute: TParentRoute;
|
|
41
|
-
children?: TChildren;
|
|
42
|
-
options: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, TMiddlewares>;
|
|
43
|
-
update: (opts: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, undefined>) => ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>;
|
|
44
|
-
init: (opts: {
|
|
45
|
-
originalIndex: number;
|
|
46
|
-
}) => void;
|
|
47
|
-
_addFileChildren: ServerRouteAddFileChildrenFn<TParentRoute, TId, TPath, TFullPath, TMiddlewares, TMethods, TChildren>;
|
|
48
|
-
_addFileTypes: () => ServerRouteWithTypes<TParentRoute, TId, TPath, TFullPath, TMiddlewares, TMethods, TChildren>;
|
|
49
|
-
}
|
|
50
|
-
export interface ServerRouteTypes<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TMiddlewares, TMethods> {
|
|
51
|
-
isRoot: TParentRoute extends AnyServerRouteWithTypes ? true : false;
|
|
52
|
-
id: TId;
|
|
53
|
-
path: TPath;
|
|
54
|
-
fullPath: TFullPath;
|
|
55
|
-
middlewares: TMiddlewares;
|
|
56
|
-
methods: TMethods;
|
|
57
|
-
parentRoute: TParentRoute;
|
|
58
|
-
allContext: ResolveAllServerContext<TParentRoute, TMiddlewares>;
|
|
59
|
-
}
|
|
60
|
-
export type ResolveAllServerContext<TParentRoute extends AnyServerRouteWithTypes, TMiddlewares> = unknown extends TParentRoute ? AssignAllServerContext<TMiddlewares> : Assign<TParentRoute['_types']['allContext'], AssignAllServerContext<TMiddlewares>>;
|
|
61
|
-
export type AnyServerRoute = AnyServerRouteWithTypes;
|
|
62
|
-
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> {
|
|
63
|
-
}
|
|
64
|
-
export interface ServerRouteMiddleware<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TChildren> {
|
|
65
|
-
middleware: <const TNewMiddleware>(middleware: Constrain<TNewMiddleware, ReadonlyArray<AnyRequestMiddleware>>) => ServerRouteAfterMiddleware<TParentRoute, TId, TPath, TFullPath, TNewMiddleware, TChildren>;
|
|
66
|
-
}
|
|
67
|
-
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> {
|
|
68
|
-
}
|
|
69
|
-
export interface ServerRouteMethods<TParentRoute extends AnyServerRouteWithTypes, TId extends RouteConstraints['TId'], TPath extends RouteConstraints['TPath'], TFullPath extends RouteConstraints['TFullPath'], TMiddlewares, TChildren> {
|
|
70
|
-
methods: <const TMethods>(methodsOrGetMethods: Constrain<TMethods, ServerRouteMethodsOptions<TParentRoute, TFullPath, TMiddlewares>>) => ServerRouteAfterMethods<TParentRoute, TId, TPath, TFullPath, TMiddlewares, TMethods, TChildren>;
|
|
71
|
-
}
|
|
72
|
-
export type ServerRouteMethodsOptions<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares> = ServerRouteMethodsRecord<TParentRoute, TFullPath, TMiddlewares> | ((api: ServerRouteMethodBuilder<TParentRoute, TFullPath, TMiddlewares>) => ServerRouteMethodsRecord<TParentRoute, TFullPath, TMiddlewares>);
|
|
73
|
-
export interface ServerRouteMethodsRecord<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares> {
|
|
74
|
-
GET?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
75
|
-
POST?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
76
|
-
PUT?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
77
|
-
PATCH?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
78
|
-
DELETE?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
79
|
-
OPTIONS?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
80
|
-
HEAD?: ServerRouteMethodRecordValue<TParentRoute, TFullPath, TMiddlewares>;
|
|
81
|
-
}
|
|
82
|
-
export type ServerRouteMethodRecordValue<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares> = ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, undefined, any> | AnyRouteMethodsBuilder;
|
|
83
|
-
export type ServerRouteVerb = (typeof ServerRouteVerbs)[number];
|
|
84
|
-
export declare const ServerRouteVerbs: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"];
|
|
85
|
-
export type ServerRouteMethodHandlerFn<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares, TResponse> = (ctx: ServerRouteMethodHandlerCtx<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares>) => TResponse | Promise<TResponse>;
|
|
86
|
-
export interface ServerRouteMethodHandlerCtx<in out TParentRoute extends AnyServerRouteWithTypes, in out TFullPath extends string, in out TMiddlewares, in out TMethodMiddlewares> {
|
|
87
|
-
context: Expand<AssignAllMethodContext<TParentRoute, TMiddlewares, TMethodMiddlewares>>;
|
|
88
|
-
request: Request;
|
|
89
|
-
params: Expand<ResolveParams<TFullPath>>;
|
|
90
|
-
pathname: TFullPath;
|
|
91
|
-
}
|
|
92
|
-
export type MergeMethodMiddlewares<TMiddlewares, TMethodMiddlewares> = TMiddlewares extends ReadonlyArray<any> ? TMethodMiddlewares extends ReadonlyArray<any> ? readonly [...TMiddlewares, ...TMethodMiddlewares] : TMiddlewares : TMethodMiddlewares;
|
|
93
|
-
export type AssignAllMethodContext<TParentRoute extends AnyServerRouteWithTypes, TMiddlewares, TMethodMiddlewares> = ResolveAllServerContext<TParentRoute, MergeMethodMiddlewares<TMiddlewares, TMethodMiddlewares>>;
|
|
94
|
-
export type AnyRouteMethodsBuilder = ServerRouteMethodBuilderWithTypes<any, any, any, any, any>;
|
|
95
|
-
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> {
|
|
96
|
-
}
|
|
97
|
-
export interface ServerRouteMethodBuilderWithTypes<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares, TResponse> {
|
|
98
|
-
_options: ServerRouteMethodBuilderOptions<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares, TResponse>;
|
|
99
|
-
_types: ServerRouteMethodBuilderTypes<TFullPath, TMiddlewares, TMethodMiddlewares, TResponse>;
|
|
100
|
-
}
|
|
101
|
-
export interface ServerRouteMethodBuilderTypes<in out TFullPath extends string, in out TMiddlewares, in out TMethodMiddlewares, in out TResponse> {
|
|
102
|
-
middlewares: TMiddlewares;
|
|
103
|
-
methodMiddleware: TMethodMiddlewares;
|
|
104
|
-
fullPath: TFullPath;
|
|
105
|
-
response: TResponse;
|
|
106
|
-
}
|
|
107
|
-
export interface ServerRouteMethodBuilderMiddleware<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares> {
|
|
108
|
-
middleware: <const TNewMethodMiddlewares>(middleware: Constrain<TNewMethodMiddlewares, ReadonlyArray<AnyRequestMiddleware>>) => ServerRouteMethodBuilderAfterMiddleware<TParentRoute, TFullPath, TMiddlewares, TNewMethodMiddlewares>;
|
|
109
|
-
}
|
|
110
|
-
export interface ServerRouteMethodBuilderAfterMiddleware<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares> extends ServerRouteMethodBuilderWithTypes<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares, undefined>, ServerRouteMethodBuilderHandler<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares> {
|
|
111
|
-
}
|
|
112
|
-
export interface ServerRouteMethodBuilderHandler<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares> {
|
|
113
|
-
handler: <TResponse>(handler: ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares, TResponse>) => ServerRouteMethodBuilderAfterHandler<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares, TResponse>;
|
|
114
|
-
}
|
|
115
|
-
export interface ServerRouteMethodBuilderAfterHandler<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares, TResponse> extends ServerRouteMethodBuilderWithTypes<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares, TResponse> {
|
|
116
|
-
opts: ServerRouteMethod<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares>;
|
|
117
|
-
}
|
|
118
|
-
export interface ServerRouteMethod<TParentRoute extends AnyServerRouteWithTypes, TFullPath extends string, TMiddlewares, TMethodMiddlewares> {
|
|
119
|
-
middleware?: Constrain<TMiddlewares, Array<AnyRequestMiddleware>>;
|
|
120
|
-
handler?: ServerRouteMethodHandlerFn<TParentRoute, TFullPath, TMiddlewares, TMethodMiddlewares, undefined>;
|
|
121
|
-
}
|
|
122
|
-
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> {
|
|
123
|
-
options: ServerRouteOptions<TParentRoute, TId, TPath, TFullPath, TMiddlewares>;
|
|
124
|
-
}
|
package/dist/esm/serverRoute.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
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
|
-
isRoot: false,
|
|
9
|
-
path: "",
|
|
10
|
-
id: "",
|
|
11
|
-
fullPath: "",
|
|
12
|
-
to: "",
|
|
13
|
-
options,
|
|
14
|
-
parentRoute: void 0,
|
|
15
|
-
_types: {},
|
|
16
|
-
// children: undefined as TChildren,
|
|
17
|
-
middleware: (middlewares) => createServerRoute(void 0, {
|
|
18
|
-
...options,
|
|
19
|
-
middleware: middlewares
|
|
20
|
-
}),
|
|
21
|
-
methods: (methodsOrGetMethods) => {
|
|
22
|
-
const methods = (() => {
|
|
23
|
-
if (typeof methodsOrGetMethods === "function") {
|
|
24
|
-
return methodsOrGetMethods(createMethodBuilder());
|
|
25
|
-
}
|
|
26
|
-
return methodsOrGetMethods;
|
|
27
|
-
})();
|
|
28
|
-
return createServerRoute(void 0, {
|
|
29
|
-
...__opts,
|
|
30
|
-
methods
|
|
31
|
-
});
|
|
32
|
-
},
|
|
33
|
-
update: (opts) => createServerRoute(void 0, {
|
|
34
|
-
...options,
|
|
35
|
-
...opts
|
|
36
|
-
}),
|
|
37
|
-
init: (opts) => {
|
|
38
|
-
options.originalIndex = opts.originalIndex;
|
|
39
|
-
const isRoot = !options.path && !options.id;
|
|
40
|
-
route.parentRoute = options.getParentRoute?.();
|
|
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
|
-
route.isRoot = isRoot;
|
|
69
|
-
},
|
|
70
|
-
_addFileChildren: (children) => {
|
|
71
|
-
if (Array.isArray(children)) {
|
|
72
|
-
route.children = children;
|
|
73
|
-
}
|
|
74
|
-
if (typeof children === "object" && children !== null) {
|
|
75
|
-
route.children = Object.values(children);
|
|
76
|
-
}
|
|
77
|
-
return route;
|
|
78
|
-
},
|
|
79
|
-
_addFileTypes: () => route
|
|
80
|
-
};
|
|
81
|
-
return route;
|
|
82
|
-
}
|
|
83
|
-
const createServerRootRoute = createServerRoute;
|
|
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
|
-
export {
|
|
99
|
-
createServerFileRoute,
|
|
100
|
-
createServerRootRoute,
|
|
101
|
-
createServerRoute
|
|
102
|
-
};
|
|
103
|
-
//# sourceMappingURL=serverRoute.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serverRoute.js","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\nexport function createServerFileRoute<\n TFilePath extends keyof ServerFileRoutesByPath,\n TParentRoute extends\n AnyServerRouteWithTypes = ServerFileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = ServerFileRoutesByPath[TFilePath]['id'],\n TPath extends\n RouteConstraints['TPath'] = ServerFileRoutesByPath[TFilePath]['path'],\n TFullPath extends\n RouteConstraints['TFullPath'] = ServerFileRoutesByPath[TFilePath]['fullPath'],\n TChildren = ServerFileRoutesByPath[TFilePath]['children'],\n>(_: TFilePath): ServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren> {\n return createServerRoute<TParentRoute, TId, TPath, TFullPath, TChildren>(\n undefined,\n )\n}\n\nexport interface ServerFileRoutesByPath {}\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<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n any,\n any\n >\n | {\n _options: ServerRouteMethodBuilderOptions<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n unknown,\n unknown\n >\n }\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 isRoot: false as any,\n path: '' as TPath,\n id: '' as TId,\n fullPath: '' as TFullPath,\n to: '' as TrimPathRight<TFullPath>,\n options: options as ServerRouteOptions<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n any\n >,\n parentRoute: undefined as unknown as TParentRoute,\n _types: {} as ServerRouteTypes<\n TParentRoute,\n TId,\n TPath,\n TFullPath,\n undefined,\n undefined\n >,\n // children: undefined as TChildren,\n middleware: (middlewares) =>\n createServerRoute(undefined, {\n ...options,\n middleware: middlewares,\n }) as never,\n methods: (methodsOrGetMethods) => {\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: methods as never,\n }) as never\n },\n update: (opts) =>\n createServerRoute(undefined, {\n ...options,\n ...opts,\n }),\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 route.isRoot = isRoot as any\n },\n\n _addFileChildren: (children) => {\n if (Array.isArray(children)) {\n route.children = children as TChildren\n }\n\n if (typeof children === 'object' && children !== null) {\n route.children = Object.values(children) as TChildren\n }\n\n return route\n },\n\n _addFileTypes: <TFileTypes>() => route,\n }\n\n return route\n}\n\n// TODO this needs to be restricted to only allow middleware, no methods\n// TODO we also need to restrict pathless server routes to only allow middleware\nexport const createServerRootRoute = createServerRoute\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?: ServerRouteMethodBuilderOptions<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n unknown,\n unknown\n >,\n): ServerRouteMethodBuilder<TParentRoute, TFullPath, TMiddlewares> => {\n return {\n _options: (__opts || {}) as never,\n _types: {} as never,\n middleware: (middlewares) =>\n createMethodBuilder({\n ...__opts,\n middlewares,\n }) as never,\n handler: (handler) =>\n createMethodBuilder({\n ...__opts,\n handler: handler as never,\n }) as never,\n }\n}\n\nexport interface ServerRouteMethodBuilderOptions<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse,\n> {\n handler?: ServerRouteMethodHandlerFn<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse\n >\n middlewares?: Constrain<\n TMethodMiddlewares,\n ReadonlyArray<AnyRequestMiddleware>\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> = () => 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 isRoot: TParentRoute extends AnyServerRouteWithTypes ? true : false\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 isRoot: TParentRoute extends AnyServerRouteWithTypes ? true : false\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: Expand<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 any\n>\n\nexport interface ServerRouteMethodBuilder<\n TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n> extends ServerRouteMethodBuilderWithTypes<\n TParentRoute,\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 TParentRoute extends AnyServerRouteWithTypes,\n TFullPath extends string,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse,\n> {\n _options: ServerRouteMethodBuilderOptions<\n TParentRoute,\n TFullPath,\n TMiddlewares,\n TMethodMiddlewares,\n TResponse\n >\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 TParentRoute,\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 TParentRoute,\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":[],"mappings":";AAcO,SAAS,sBAUd,GAA2E;AAC3E,SAAO,kBAEP;AACF;AA4CO,SAAS,kBAOd,IACA,QAG6D;AAC7D,QAAM,UAAU,UAAU,CAAA;AAE1B,QAAM,QAAqE;AAAA,IACzE,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,IAAI;AAAA,IACJ,UAAU;AAAA,IACV,IAAI;AAAA,IACJ;AAAA,IAOA,aAAa;AAAA,IACb,QAAQ,CAAA;AAAA;AAAA,IASR,YAAY,CAAC,gBACX,kBAAkB,QAAW;AAAA,MAC3B,GAAG;AAAA,MACH,YAAY;AAAA,IAAA,CACb;AAAA,IACH,SAAS,CAAC,wBAAwB;AAChC,YAAM,WAAW,MAAM;AACrB,YAAI,OAAO,wBAAwB,YAAY;AAC7C,iBAAO,oBAAoB,qBAAqB;AAAA,QAClD;AAEA,eAAO;AAAA,MACT,GAAA;AAEA,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;AAEzC,YAAM,cAAc,QAAQ,iBAAA;AAE5B,UAAI,QAAQ;AACV,cAAM,OAAO;AAAA,MACf,WAAW,CAAE,MAAM,aAAqB;AACtC,cAAM,IAAI;AAAA,UACR;AAAA,QAAA;AAAA,MAEJ;AAEA,UAAI,OAA2B,SAAS,cAAc,QAAQ;AAG9D,UAAI,QAAQ,SAAS,KAAK;AACxB,eAAO,aAAa,IAAI;AAAA,MAC1B;AAEA,YAAM,WAAW,QAAQ,MAAM;AAG/B,UAAI,KAAK,SACL,cACA,UAAU;AAAA,QACR,MAAM,YAAY,OAAO,cAAc,KAAK,MAAM,YAAY;AAAA,QAC9D;AAAA,MAAA,CACD;AAEL,UAAI,SAAS,aAAa;AACxB,eAAO;AAAA,MACT;AAEA,UAAI,OAAO,aAAa;AACtB,aAAK,UAAU,CAAC,KAAK,EAAE,CAAC;AAAA,MAC1B;AAEA,YAAM,WACJ,OAAO,cAAc,MAAM,UAAU,CAAC,MAAM,YAAY,UAAU,IAAI,CAAC;AAEzE,YAAM,OAAO;AACb,YAAM,KAAK;AACX,YAAM,WAAW;AACjB,YAAM,KAAK;AACX,YAAM,SAAS;AAAA,IACjB;AAAA,IAEA,kBAAkB,CAAC,aAAa;AAC9B,UAAI,MAAM,QAAQ,QAAQ,GAAG;AAC3B,cAAM,WAAW;AAAA,MACnB;AAEA,UAAI,OAAO,aAAa,YAAY,aAAa,MAAM;AACrD,cAAM,WAAW,OAAO,OAAO,QAAQ;AAAA,MACzC;AAEA,aAAO;AAAA,IACT;AAAA,IAEA,eAAe,MAAkB;AAAA,EAAA;AAGnC,SAAO;AACT;AAIO,MAAM,wBAAwB;AAsBrC,MAAM,sBAAsB,CAK1B,WAOoE;AACpE,SAAO;AAAA,IACL,UAAW,UAAU,CAAA;AAAA,IACrB,QAAQ,CAAA;AAAA,IACR,YAAY,CAAC,gBACX,oBAAoB;AAAA,MAClB,GAAG;AAAA,MACH;AAAA,IAAA,CACD;AAAA,IACH,SAAS,CAAC,YACR,oBAAoB;AAAA,MAClB,GAAG;AAAA,MACH;AAAA,IAAA,CACD;AAAA,EAAA;AAEP;"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { makeSerovalPlugin } from '@tanstack/router-core'
|
|
2
|
-
import { getDefaultSerovalPlugins } from '@tanstack/start-client-core'
|
|
3
|
-
import { ServerFunctionSerializationAdapter } from './ServerFunctionSerializationAdapter'
|
|
4
|
-
|
|
5
|
-
export function getSerovalPlugins() {
|
|
6
|
-
return [
|
|
7
|
-
...getDefaultSerovalPlugins(),
|
|
8
|
-
makeSerovalPlugin(ServerFunctionSerializationAdapter),
|
|
9
|
-
]
|
|
10
|
-
}
|