UNPKG

@tanstack/start-server-core

Version:

Modern and scalable routing for React applications

30 lines (29 loc) • 1.09 kB
import { getServerFnById } from "../getServerFnById.js"; import { TSS_SERVER_FUNCTION } from "@tanstack/start-client-core"; import { createSerializationAdapter } from "@tanstack/router-core"; //#region src/serializer/ServerFunctionSerializationAdapter.ts var ServerFunctionSerializationAdapter = createSerializationAdapter({ key: "$TSS/serverfn", test: (v) => { if (typeof v !== "function") return false; if (!(TSS_SERVER_FUNCTION in v)) return false; return !!v[TSS_SERVER_FUNCTION]; }, toSerializable: ({ serverFnMeta }) => ({ functionId: serverFnMeta.id }), fromSerializable: ({ functionId }) => { const fn = async (opts, signal) => { const serverFn = await getServerFnById(functionId, { origin: "client" }); const result = await serverFn({ data: opts?.data, context: opts?.context, method: serverFn.method ?? "GET" }, signal); if (result.error !== void 0) throw result.error; return result.result; }; return fn; } }); //#endregion export { ServerFunctionSerializationAdapter }; //# sourceMappingURL=ServerFunctionSerializationAdapter.js.map