Open History to see the last commit
1import { createSerializationAdapter } from '@tanstack/router-core'
2import { TSS_SERVER_FUNCTION } from '@tanstack/start-client-core'
3import { createServerRpc } from '../createServerRpc'
4import { getServerFnById } from '../getServerFnById'
5β
6export const ServerFunctionSerializationAdapter = createSerializationAdapter({
7 key: '$TSS/serverfn',
8 test: (v): v is { functionId: string } => {
9 if (typeof v !== 'function') return false
10β
11 if (!(TSS_SERVER_FUNCTION in v)) return false
12β
13 return !!v[TSS_SERVER_FUNCTION]
14 },
15 toSerializable: ({ functionId }) => ({ functionId }),
16 fromSerializable: ({ functionId }) => {
17 const fn = async (opts: any, signal: any): Promise<any> => {
18 const serverFn = await getServerFnById(functionId)
19 const result = await serverFn(opts ?? {}, signal)
20 return result.result
21 }
22 return createServerRpc(functionId, fn)
23 },
24})