@tanstack/start-client-core 1.132.0-alpha.8 → 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/{serializer → client}/ServerFunctionSerializationAdapter.js +2 -2
- package/dist/esm/client/ServerFunctionSerializationAdapter.js.map +1 -0
- package/dist/esm/client/createClientRpc.d.ts +6 -0
- package/dist/esm/{createClientRpc.js → client/createClientRpc.js} +4 -4
- package/dist/esm/client/createClientRpc.js.map +1 -0
- package/dist/esm/client/hydrateStart.d.ts +2 -0
- package/dist/esm/client/hydrateStart.js +29 -0
- package/dist/esm/client/hydrateStart.js.map +1 -0
- package/dist/esm/client/index.d.ts +2 -0
- package/dist/esm/client/index.js +7 -0
- package/dist/esm/client/index.js.map +1 -0
- package/dist/esm/{serverFnFetcher.js → client/serverFnFetcher.js} +6 -6
- package/dist/esm/client/serverFnFetcher.js.map +1 -0
- package/dist/esm/constants.d.ts +1 -0
- package/dist/esm/constants.js +4 -0
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/createMiddleware.d.ts +95 -86
- package/dist/esm/createMiddleware.js +5 -5
- package/dist/esm/createMiddleware.js.map +1 -1
- package/dist/esm/createServerFn.d.ts +64 -61
- package/dist/esm/createServerFn.js +57 -30
- package/dist/esm/createServerFn.js.map +1 -1
- package/dist/esm/createStart.d.ts +27 -0
- package/dist/esm/createStart.js +14 -0
- package/dist/esm/createStart.js.map +1 -0
- package/dist/esm/fake-start-entry.d.ts +5 -0
- package/dist/esm/fake-start-entry.js +11 -0
- package/dist/esm/fake-start-entry.js.map +1 -0
- package/dist/esm/getDefaultSerovalPlugins.d.ts +1 -0
- package/dist/esm/getDefaultSerovalPlugins.js +14 -0
- package/dist/esm/getDefaultSerovalPlugins.js.map +1 -0
- package/dist/esm/getGlobalStartContext.d.ts +3 -0
- package/dist/esm/getGlobalStartContext.js +15 -0
- package/dist/esm/getGlobalStartContext.js.map +1 -0
- package/dist/esm/getRouterInstance.d.ts +2 -1
- package/dist/esm/getRouterInstance.js +1 -1
- package/dist/esm/getRouterInstance.js.map +1 -1
- package/dist/esm/getServerContextAfterGlobalMiddlewares.d.ts +1 -0
- package/dist/esm/getServerContextAfterGlobalMiddlewares.js +10 -0
- package/dist/esm/getServerContextAfterGlobalMiddlewares.js.map +1 -0
- package/dist/esm/getStartOptions.d.ts +1 -0
- package/dist/esm/getStartOptions.js +7 -0
- package/dist/esm/getStartOptions.js.map +1 -0
- package/dist/esm/global.d.ts +7 -0
- package/dist/esm/index.d.ts +11 -6
- package/dist/esm/index.js +9 -9
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/serverRoute.d.ts +66 -0
- package/dist/esm/startEntry.d.ts +8 -0
- package/package.json +18 -5
- package/src/{serializer → client}/ServerFunctionSerializationAdapter.ts +2 -2
- package/src/{createClientRpc.ts → client/createClientRpc.ts} +5 -3
- package/src/client/hydrateStart.ts +33 -0
- package/src/client/index.ts +3 -0
- package/src/{serverFnFetcher.ts → client/serverFnFetcher.ts} +11 -16
- package/src/constants.ts +3 -0
- package/src/createMiddleware.ts +269 -255
- package/src/createServerFn.ts +277 -290
- package/src/createStart.ts +122 -0
- package/src/fake-start-entry.ts +4 -0
- package/src/getDefaultSerovalPlugins.ts +17 -0
- package/src/getGlobalStartContext.ts +18 -0
- package/src/getRouterInstance.ts +5 -4
- package/src/getServerContextAfterGlobalMiddlewares.ts +7 -0
- package/src/getStartOptions.ts +6 -0
- package/src/global.ts +9 -0
- package/src/index.tsx +12 -11
- package/src/serverRoute.ts +474 -0
- package/src/start-entry.d.ts +11 -0
- package/src/startEntry.ts +10 -0
- package/src/tests/createServerFn.test-d.ts +147 -123
- package/src/tests/createServerMiddleware.test-d.ts +22 -17
- package/dist/esm/createClientRpc.d.ts +0 -6
- package/dist/esm/createClientRpc.js.map +0 -1
- package/dist/esm/registerGlobalMiddleware.d.ts +0 -5
- package/dist/esm/registerGlobalMiddleware.js +0 -9
- package/dist/esm/registerGlobalMiddleware.js.map +0 -1
- package/dist/esm/serializer/ServerFunctionSerializationAdapter.js.map +0 -1
- package/dist/esm/serializer/getClientSerovalPlugins.d.ts +0 -3
- package/dist/esm/serializer/getClientSerovalPlugins.js +0 -13
- package/dist/esm/serializer/getClientSerovalPlugins.js.map +0 -1
- package/dist/esm/serializer/getDefaultSerovalPlugins.d.ts +0 -3
- package/dist/esm/serializer/getDefaultSerovalPlugins.js +0 -19
- package/dist/esm/serializer/getDefaultSerovalPlugins.js.map +0 -1
- package/dist/esm/serverFnFetcher.js.map +0 -1
- package/src/registerGlobalMiddleware.ts +0 -9
- package/src/serializer/getClientSerovalPlugins.ts +0 -10
- package/src/serializer/getDefaultSerovalPlugins.ts +0 -24
- /package/dist/esm/{serializer → client}/ServerFunctionSerializationAdapter.d.ts +0 -0
- /package/dist/esm/{serverFnFetcher.d.ts → client/serverFnFetcher.d.ts} +0 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AnyFunctionMiddleware, AnyRequestMiddleware, CreateMiddlewareFn } from './createMiddleware.js';
|
|
2
|
+
import { AnySerializationAdapter, Register, SSROption } from '@tanstack/router-core';
|
|
3
|
+
export interface StartInstanceOptions<in out TSerializationAdapters, in out TDefaultSsr, in out TRequestMiddlewares, in out TFunctionMiddlewares> {
|
|
4
|
+
'~types': StartInstanceTypes<TSerializationAdapters, TDefaultSsr, TRequestMiddlewares, TFunctionMiddlewares>;
|
|
5
|
+
serializationAdapters?: TSerializationAdapters;
|
|
6
|
+
defaultSsr?: TDefaultSsr;
|
|
7
|
+
requestMiddleware?: TRequestMiddlewares;
|
|
8
|
+
functionMiddleware?: TFunctionMiddlewares;
|
|
9
|
+
}
|
|
10
|
+
export interface StartInstance<in out TSerializationAdapters, in out TDefaultSsr, in out TRequestMiddlewares, in out TFunctionMiddlewares> {
|
|
11
|
+
getOptions: () => Promise<StartInstanceOptions<TSerializationAdapters, TDefaultSsr, TRequestMiddlewares, TFunctionMiddlewares>> | StartInstanceOptions<TSerializationAdapters, TDefaultSsr, TRequestMiddlewares, TFunctionMiddlewares>;
|
|
12
|
+
createMiddleware: CreateMiddlewareFn<Register>;
|
|
13
|
+
}
|
|
14
|
+
export interface StartInstanceTypes<in out TSerializationAdapters, in out TDefaultSsr, in out TRequestMiddlewares, in out TFunctionMiddlewares> {
|
|
15
|
+
serializationAdapters: TSerializationAdapters;
|
|
16
|
+
defaultSsr: TDefaultSsr;
|
|
17
|
+
requestMiddleware: TRequestMiddlewares;
|
|
18
|
+
functionMiddleware: TFunctionMiddlewares;
|
|
19
|
+
}
|
|
20
|
+
export declare const createStart: <const TSerializationAdapters extends ReadonlyArray<AnySerializationAdapter> = [], TDefaultSsr extends SSROption = SSROption, const TRequestMiddlewares extends ReadonlyArray<AnyRequestMiddleware> = [], const TFunctionMiddlewares extends ReadonlyArray<AnyFunctionMiddleware> = []>(getOptions: () => Promise<Omit<StartInstanceOptions<TSerializationAdapters, TDefaultSsr, TRequestMiddlewares, TFunctionMiddlewares>, "~types">> | Omit<StartInstanceOptions<TSerializationAdapters, TDefaultSsr, TRequestMiddlewares, TFunctionMiddlewares>, "~types">) => StartInstance<TSerializationAdapters, TDefaultSsr, TRequestMiddlewares, TFunctionMiddlewares>;
|
|
21
|
+
export type AnyStartInstance = StartInstance<any, any, any, any>;
|
|
22
|
+
export type AnyStartInstanceOptions = StartInstanceOptions<any, any, any, any>;
|
|
23
|
+
declare module '@tanstack/router-core' {
|
|
24
|
+
interface Register {
|
|
25
|
+
ssr: true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createMiddleware } from "./createMiddleware.js";
|
|
2
|
+
const createStart = (getOptions) => {
|
|
3
|
+
return {
|
|
4
|
+
getOptions: async () => {
|
|
5
|
+
const options = await getOptions();
|
|
6
|
+
return options;
|
|
7
|
+
},
|
|
8
|
+
createMiddleware
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
createStart
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=createStart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createStart.js","sources":["../../src/createStart.ts"],"sourcesContent":["import { createMiddleware } from './createMiddleware'\nimport type {\n AnyFunctionMiddleware,\n AnyRequestMiddleware,\n CreateMiddlewareFn,\n} from './createMiddleware'\nimport type {\n AnySerializationAdapter,\n Register,\n SSROption,\n} from '@tanstack/router-core'\n\nexport interface StartInstanceOptions<\n in out TSerializationAdapters,\n in out TDefaultSsr,\n in out TRequestMiddlewares,\n in out TFunctionMiddlewares,\n> {\n '~types': StartInstanceTypes<\n TSerializationAdapters,\n TDefaultSsr,\n TRequestMiddlewares,\n TFunctionMiddlewares\n >\n serializationAdapters?: TSerializationAdapters\n defaultSsr?: TDefaultSsr\n requestMiddleware?: TRequestMiddlewares\n functionMiddleware?: TFunctionMiddlewares\n}\n\nexport interface StartInstance<\n in out TSerializationAdapters,\n in out TDefaultSsr,\n in out TRequestMiddlewares,\n in out TFunctionMiddlewares,\n> {\n getOptions: () =>\n | Promise<\n StartInstanceOptions<\n TSerializationAdapters,\n TDefaultSsr,\n TRequestMiddlewares,\n TFunctionMiddlewares\n >\n >\n | StartInstanceOptions<\n TSerializationAdapters,\n TDefaultSsr,\n TRequestMiddlewares,\n TFunctionMiddlewares\n >\n createMiddleware: CreateMiddlewareFn<Register>\n}\n\nexport interface StartInstanceTypes<\n in out TSerializationAdapters,\n in out TDefaultSsr,\n in out TRequestMiddlewares,\n in out TFunctionMiddlewares,\n> {\n serializationAdapters: TSerializationAdapters\n defaultSsr: TDefaultSsr\n requestMiddleware: TRequestMiddlewares\n functionMiddleware: TFunctionMiddlewares\n}\n\nexport const createStart = <\n const TSerializationAdapters extends\n ReadonlyArray<AnySerializationAdapter> = [],\n TDefaultSsr extends SSROption = SSROption,\n const TRequestMiddlewares extends ReadonlyArray<AnyRequestMiddleware> = [],\n const TFunctionMiddlewares extends ReadonlyArray<AnyFunctionMiddleware> = [],\n>(\n getOptions: () =>\n | Promise<\n Omit<\n StartInstanceOptions<\n TSerializationAdapters,\n TDefaultSsr,\n TRequestMiddlewares,\n TFunctionMiddlewares\n >,\n '~types'\n >\n >\n | Omit<\n StartInstanceOptions<\n TSerializationAdapters,\n TDefaultSsr,\n TRequestMiddlewares,\n TFunctionMiddlewares\n >,\n '~types'\n >,\n): StartInstance<\n TSerializationAdapters,\n TDefaultSsr,\n TRequestMiddlewares,\n TFunctionMiddlewares\n> => {\n return {\n getOptions: async () => {\n const options = await getOptions()\n return options\n },\n createMiddleware: createMiddleware as any,\n } as StartInstance<\n TSerializationAdapters,\n TDefaultSsr,\n TRequestMiddlewares,\n TFunctionMiddlewares\n >\n}\n\nexport type AnyStartInstance = StartInstance<any, any, any, any>\nexport type AnyStartInstanceOptions = StartInstanceOptions<any, any, any, any>\n\ndeclare module '@tanstack/router-core' {\n interface Register {\n ssr: true\n }\n}\n"],"names":[],"mappings":";AAkEO,MAAM,cAAc,CAOzB,eA0BG;AACH,SAAO;AAAA,IACL,YAAY,YAAY;AACtB,YAAM,UAAU,MAAM,WAAA;AACtB,aAAO;AAAA,IACT;AAAA,IACA;AAAA,EAAA;AAOJ;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake-start-entry.js","sources":["../../src/fake-start-entry.ts"],"sourcesContent":["export default {\n startInstance: () => {},\n}\nexport const getRouter = () => {}\n"],"names":[],"mappings":"AAAA,MAAA,iBAAe;AAAA,EACb,eAAe,MAAM;AAAA,EAAC;AACxB;AACO,MAAM,YAAY,MAAM;AAAC;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getDefaultSerovalPlugins(): (import('seroval').Plugin<any, import('seroval').SerovalNode> | import('seroval').Plugin<Error, any> | import('seroval').Plugin<ReadableStream<any>, any>)[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { defaultSerovalPlugins, makeSerovalPlugin } from "@tanstack/router-core";
|
|
2
|
+
import { getStartOptions } from "./getStartOptions.js";
|
|
3
|
+
function getDefaultSerovalPlugins() {
|
|
4
|
+
const start = getStartOptions();
|
|
5
|
+
const adapters = start.serializationAdapters;
|
|
6
|
+
return [
|
|
7
|
+
...adapters?.map(makeSerovalPlugin) ?? [],
|
|
8
|
+
...defaultSerovalPlugins
|
|
9
|
+
];
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
getDefaultSerovalPlugins
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=getDefaultSerovalPlugins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getDefaultSerovalPlugins.js","sources":["../../src/getDefaultSerovalPlugins.ts"],"sourcesContent":["import {\n makeSerovalPlugin,\n defaultSerovalPlugins as routerDefaultSerovalPlugins,\n} from '@tanstack/router-core'\nimport { getStartOptions } from './getStartOptions'\nimport type { AnySerializationAdapter } from '@tanstack/router-core'\n\nexport function getDefaultSerovalPlugins() {\n const start = getStartOptions()\n const adapters = start.serializationAdapters as\n | Array<AnySerializationAdapter>\n | undefined\n return [\n ...(adapters?.map(makeSerovalPlugin) ?? []),\n ...routerDefaultSerovalPlugins,\n ]\n}\n"],"names":["routerDefaultSerovalPlugins"],"mappings":";;AAOO,SAAS,2BAA2B;AACzC,QAAM,QAAQ,gBAAA;AACd,QAAM,WAAW,MAAM;AAGvB,SAAO;AAAA,IACL,GAAI,UAAU,IAAI,iBAAiB,KAAK,CAAA;AAAA,IACxC,GAAGA;AAAAA,EAAA;AAEP;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getStartContext } from "@tanstack/start-storage-context";
|
|
2
|
+
import { createIsomorphicFn } from "./createIsomorphicFn.js";
|
|
3
|
+
const getGlobalStartContext = createIsomorphicFn().client(() => void 0).server(() => {
|
|
4
|
+
const context = getStartContext().contextAfterGlobalMiddlewares;
|
|
5
|
+
if (!context) {
|
|
6
|
+
throw new Error(
|
|
7
|
+
`Global context not set yet, you are calling getGlobalStartContext() before the global middlewares are applied.`
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
return context;
|
|
11
|
+
});
|
|
12
|
+
export {
|
|
13
|
+
getGlobalStartContext
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=getGlobalStartContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getGlobalStartContext.js","sources":["../../src/getGlobalStartContext.ts"],"sourcesContent":["import { getStartContext } from '@tanstack/start-storage-context'\nimport { createIsomorphicFn } from './createIsomorphicFn'\nimport type { AssignAllServerRequestContext } from './createMiddleware'\nimport type { Expand, Register } from '@tanstack/router-core'\n\nexport const getGlobalStartContext: () =>\n | Expand<AssignAllServerRequestContext<Register, []>>\n | undefined = createIsomorphicFn()\n .client(() => undefined)\n .server(() => {\n const context = getStartContext().contextAfterGlobalMiddlewares\n if (!context) {\n throw new Error(\n `Global context not set yet, you are calling getGlobalStartContext() before the global middlewares are applied.`,\n )\n }\n return context\n })\n"],"names":[],"mappings":";;AAKO,MAAM,wBAEG,qBACb,OAAO,MAAM,MAAS,EACtB,OAAO,MAAM;AACZ,QAAM,UAAU,kBAAkB;AAClC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AACA,SAAO;AACT,CAAC;"}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { Awaitable, RegisteredRouter } from '@tanstack/router-core';
|
|
2
|
+
export declare const getRouterInstance: () => Awaitable<RegisteredRouter>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getStartContext } from "@tanstack/start-storage-context";
|
|
2
2
|
import { createIsomorphicFn } from "./createIsomorphicFn.js";
|
|
3
|
-
const getRouterInstance = createIsomorphicFn().client(() => window.__TSR_ROUTER__).server(() => getStartContext().
|
|
3
|
+
const getRouterInstance = createIsomorphicFn().client(() => window.__TSR_ROUTER__).server(() => getStartContext().getRouter());
|
|
4
4
|
export {
|
|
5
5
|
getRouterInstance
|
|
6
6
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRouterInstance.js","sources":["../../src/getRouterInstance.ts"],"sourcesContent":["import { getStartContext } from '@tanstack/start-storage-context'\nimport { createIsomorphicFn } from './createIsomorphicFn'\
|
|
1
|
+
{"version":3,"file":"getRouterInstance.js","sources":["../../src/getRouterInstance.ts"],"sourcesContent":["import { getStartContext } from '@tanstack/start-storage-context'\nimport { createIsomorphicFn } from './createIsomorphicFn'\nimport type { Awaitable, RegisteredRouter } from '@tanstack/router-core'\n\nexport const getRouterInstance: () => Awaitable<RegisteredRouter> =\n createIsomorphicFn()\n .client(() => window.__TSR_ROUTER__!)\n .server(() => getStartContext().getRouter())\n"],"names":[],"mappings":";;AAIO,MAAM,oBACX,mBAAA,EACG,OAAO,MAAM,OAAO,cAAe,EACnC,OAAO,MAAM,gBAAA,EAAkB,WAAW;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getServerContextAfterGlobalMiddlewares: () => any;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { getStartContext } from "@tanstack/start-storage-context";
|
|
2
|
+
import { createServerOnlyFn } from "./envOnly.js";
|
|
3
|
+
const getServerContextAfterGlobalMiddlewares = createServerOnlyFn(() => {
|
|
4
|
+
const start = getStartContext();
|
|
5
|
+
return start.contextAfterGlobalMiddlewares;
|
|
6
|
+
});
|
|
7
|
+
export {
|
|
8
|
+
getServerContextAfterGlobalMiddlewares
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=getServerContextAfterGlobalMiddlewares.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getServerContextAfterGlobalMiddlewares.js","sources":["../../src/getServerContextAfterGlobalMiddlewares.ts"],"sourcesContent":["import { getStartContext } from '@tanstack/start-storage-context'\nimport { createServerOnlyFn } from './envOnly'\n\nexport const getServerContextAfterGlobalMiddlewares = createServerOnlyFn(() => {\n const start = getStartContext()\n return start.contextAfterGlobalMiddlewares\n})\n"],"names":[],"mappings":";;AAGO,MAAM,yCAAyC,mBAAmB,MAAM;AAC7E,QAAM,QAAQ,gBAAA;AACd,SAAO,MAAM;AACf,CAAC;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getStartOptions: import('./createIsomorphicFn.js').IsomorphicFn<[], any, import('./createStart.js').AnyStartInstanceOptions>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { getStartContext } from "@tanstack/start-storage-context";
|
|
2
|
+
import { createIsomorphicFn } from "./createIsomorphicFn.js";
|
|
3
|
+
const getStartOptions = createIsomorphicFn().client(() => window.__TSS_START_OPTIONS__).server(() => getStartContext().startOptions);
|
|
4
|
+
export {
|
|
5
|
+
getStartOptions
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=getStartOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getStartOptions.js","sources":["../../src/getStartOptions.ts"],"sourcesContent":["import { getStartContext } from '@tanstack/start-storage-context'\nimport { createIsomorphicFn } from './createIsomorphicFn'\n\nexport const getStartOptions = createIsomorphicFn()\n .client(() => window.__TSS_START_OPTIONS__!)\n .server(() => getStartContext().startOptions)\n"],"names":[],"mappings":";;AAGO,MAAM,kBAAkB,qBAC5B,OAAO,MAAM,OAAO,qBAAsB,EAC1C,OAAO,MAAM,gBAAA,EAAkB,YAAY;"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -3,10 +3,15 @@ export { hydrate, json, mergeHeaders } from '@tanstack/router-core/ssr/client';
|
|
|
3
3
|
export { createIsomorphicFn, type IsomorphicFn, type ServerOnlyFn, type ClientOnlyFn, type IsomorphicFnBase, } from './createIsomorphicFn.js';
|
|
4
4
|
export { createServerOnlyFn, createClientOnlyFn } from './envOnly.js';
|
|
5
5
|
export { createServerFn } from './createServerFn.js';
|
|
6
|
-
export { createMiddleware, type IntersectAllValidatorInputs, type IntersectAllValidatorOutputs, type FunctionMiddlewareServerFn, type AnyFunctionMiddleware, type FunctionMiddlewareOptions, type FunctionMiddlewareWithTypes, type FunctionMiddlewareValidator, type FunctionMiddlewareServer, type FunctionMiddlewareAfterClient, type FunctionMiddlewareAfterServer, type FunctionMiddleware, type FunctionMiddlewareClientFnOptions, type FunctionMiddlewareClientFnResult, type FunctionMiddlewareClientNextFn, type FunctionClientResultWithContext, type AssignAllClientContextBeforeNext, type AssignAllMiddleware, type
|
|
7
|
-
export {
|
|
8
|
-
export
|
|
9
|
-
export { applyMiddleware, execValidator, serverFnBaseToMiddleware, flattenMiddlewares, executeMiddleware, } from './createServerFn.js';
|
|
10
|
-
export { createClientRpc } from './createClientRpc.js';
|
|
11
|
-
export { getDefaultSerovalPlugins } from './serializer/getDefaultSerovalPlugins.js';
|
|
6
|
+
export { createMiddleware, type IntersectAllValidatorInputs, type IntersectAllValidatorOutputs, type FunctionMiddlewareServerFn, type AnyFunctionMiddleware, type FunctionMiddlewareOptions, type FunctionMiddlewareWithTypes, type FunctionMiddlewareValidator, type FunctionMiddlewareServer, type FunctionMiddlewareAfterClient, type FunctionMiddlewareAfterServer, type FunctionMiddleware, type FunctionMiddlewareClientFnOptions, type FunctionMiddlewareClientFnResult, type FunctionMiddlewareClientNextFn, type FunctionClientResultWithContext, type AssignAllClientContextBeforeNext, type AssignAllMiddleware, type FunctionMiddlewareAfterValidator, type FunctionMiddlewareClientFn, type FunctionMiddlewareServerFnResult, type FunctionMiddlewareClient, type FunctionMiddlewareServerFnOptions, type FunctionMiddlewareServerNextFn, type FunctionServerResultWithContext, type AnyRequestMiddleware, } from './createMiddleware.js';
|
|
7
|
+
export type { CompiledFetcherFnOptions, CompiledFetcherFn, Fetcher, RscStream, FetcherData, FetcherBaseOptions, ServerFn, ServerFnCtx, MiddlewareFn, ServerFnMiddlewareOptions, ServerFnMiddlewareResult, ServerFnBuilder, ServerFnBaseOptions, NextFn, Method, OptionalFetcher, RequiredFetcher, } from './createServerFn.js';
|
|
8
|
+
export { applyMiddleware, execValidator, flattenMiddlewares, executeMiddleware, } from './createServerFn.js';
|
|
12
9
|
export { TSS_FORMDATA_CONTEXT, TSS_SERVER_FUNCTION, X_TSS_SERIALIZED, } from './constants.js';
|
|
10
|
+
export type * from './serverRoute.js';
|
|
11
|
+
export type * from './startEntry.js';
|
|
12
|
+
export { createStart } from './createStart.js';
|
|
13
|
+
export type { AnyStartInstance, AnyStartInstanceOptions } from './createStart.js';
|
|
14
|
+
export type { Register } from '@tanstack/router-core';
|
|
15
|
+
export { getRouterInstance } from './getRouterInstance.js';
|
|
16
|
+
export { getDefaultSerovalPlugins } from './getDefaultSerovalPlugins.js';
|
|
17
|
+
export { getGlobalStartContext } from './getGlobalStartContext.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import { hydrate, json, mergeHeaders } from "@tanstack/router-core/ssr/client";
|
|
2
2
|
import { createIsomorphicFn } from "./createIsomorphicFn.js";
|
|
3
3
|
import { createClientOnlyFn, createServerOnlyFn } from "./envOnly.js";
|
|
4
|
-
import { applyMiddleware, createServerFn, execValidator, executeMiddleware, flattenMiddlewares
|
|
4
|
+
import { applyMiddleware, createServerFn, execValidator, executeMiddleware, flattenMiddlewares } from "./createServerFn.js";
|
|
5
5
|
import { createMiddleware } from "./createMiddleware.js";
|
|
6
|
-
import { globalMiddleware, registerGlobalMiddleware } from "./registerGlobalMiddleware.js";
|
|
7
|
-
import { createClientRpc } from "./createClientRpc.js";
|
|
8
|
-
import { getDefaultSerovalPlugins } from "./serializer/getDefaultSerovalPlugins.js";
|
|
9
6
|
import { TSS_FORMDATA_CONTEXT, TSS_SERVER_FUNCTION, X_TSS_SERIALIZED } from "./constants.js";
|
|
7
|
+
import { createStart } from "./createStart.js";
|
|
8
|
+
import { getRouterInstance } from "./getRouterInstance.js";
|
|
9
|
+
import { getDefaultSerovalPlugins } from "./getDefaultSerovalPlugins.js";
|
|
10
|
+
import { getGlobalStartContext } from "./getGlobalStartContext.js";
|
|
10
11
|
export {
|
|
11
12
|
TSS_FORMDATA_CONTEXT,
|
|
12
13
|
TSS_SERVER_FUNCTION,
|
|
13
14
|
X_TSS_SERIALIZED,
|
|
14
15
|
applyMiddleware,
|
|
15
16
|
createClientOnlyFn,
|
|
16
|
-
createClientRpc,
|
|
17
17
|
createIsomorphicFn,
|
|
18
18
|
createMiddleware,
|
|
19
19
|
createServerFn,
|
|
20
20
|
createServerOnlyFn,
|
|
21
|
+
createStart,
|
|
21
22
|
execValidator,
|
|
22
23
|
executeMiddleware,
|
|
23
24
|
flattenMiddlewares,
|
|
24
25
|
getDefaultSerovalPlugins,
|
|
25
|
-
|
|
26
|
+
getGlobalStartContext,
|
|
27
|
+
getRouterInstance,
|
|
26
28
|
hydrate,
|
|
27
29
|
json,
|
|
28
|
-
mergeHeaders
|
|
29
|
-
registerGlobalMiddleware,
|
|
30
|
-
serverFnBaseToMiddleware
|
|
30
|
+
mergeHeaders
|
|
31
31
|
};
|
|
32
32
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { AnyContext, AnyRoute, Assign, Constrain, Expand, ResolveParams, UnionToIntersection } from '@tanstack/router-core';
|
|
2
|
+
import { AnyRequestMiddleware, AssignAllServerRequestContext } from './createMiddleware.js';
|
|
3
|
+
declare module '@tanstack/router-core' {
|
|
4
|
+
interface FilebaseRouteOptionsInterface<TRegister, TParentRoute extends AnyRoute = AnyRoute, TId extends string = string, TPath extends string = string, TSearchValidator = undefined, TParams = {}, TLoaderDeps extends Record<string, any> = {}, TLoaderFn = undefined, TRouterContext = {}, TRouteContextFn = AnyContext, TBeforeLoadFn = AnyContext, TRemountDepsFn = AnyContext, TSSR = unknown, TServerMiddlewares = unknown, THandlers = undefined> {
|
|
5
|
+
server?: RouteServerOptions<TRegister, AnyRoute, TPath, TParams, TLoaderDeps, TLoaderFn, TRouterContext, TRouteContextFn, TBeforeLoadFn, TServerMiddlewares, THandlers>;
|
|
6
|
+
}
|
|
7
|
+
interface RouteTypes<in out TRegister, in out TParentRoute extends AnyRoute, in out TPath extends string, in out TFullPath extends string, in out TCustomId extends string, in out TId extends string, in out TSearchValidator, in out TParams, in out TRouterContext, in out TRouteContextFn, in out TBeforeLoadFn, in out TLoaderDeps, in out TLoaderFn, in out TChildren, in out TFileRouteTypes, in out TSSR, in out TServerMiddlewares, in out THandlers> {
|
|
8
|
+
middleware: TServerMiddlewares;
|
|
9
|
+
allServerContext: ResolveAllServerContext<TRegister, TParentRoute, TServerMiddlewares>;
|
|
10
|
+
}
|
|
11
|
+
interface BeforeLoadContextOptions<in out TRegister, in out TParentRoute extends AnyRoute, in out TSearchValidator, in out TParams, in out TRouterContext, in out TRouteContextFn, in out TServerMiddlewares, in out THandlers> {
|
|
12
|
+
serverContext?: Expand<Assign<ResolveAllServerContext<TRegister, TParentRoute, TServerMiddlewares>, ExtractHandlersContext<THandlers>>>;
|
|
13
|
+
}
|
|
14
|
+
interface LoaderFnContext<in out TRegister, in out TParentRoute extends AnyRoute = AnyRoute, in out TId extends string = string, in out TParams = {}, in out TLoaderDeps = {}, in out TRouterContext = {}, in out TRouteContextFn = AnyContext, in out TBeforeLoadFn = AnyContext, in out TServerMiddlewares = unknown, in out THandlers = undefined> {
|
|
15
|
+
serverContext?: Expand<Assign<ResolveAllServerContext<TRegister, TParentRoute, TServerMiddlewares>, ExtractHandlersContext<THandlers>>>;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
type ExtractHandlersContext<THandlers> = THandlers extends (...args: any) => CustomHandlerFunctionsRecord<any, any, any, any, any, infer TServerContext> ? UnionToIntersection<TServerContext> : THandlers extends Record<string, RouteMethodHandler<any, any, any, any, any, infer TServerContext>> ? UnionToIntersection<TServerContext> : undefined;
|
|
19
|
+
export interface RouteServerOptions<TRegister, TParentRoute extends AnyRoute, TPath extends string, TParams, TLoaderDeps, TLoaderFn, TRouterContext, TRouteContextFn, TBeforeLoadFn, TServerMiddlewares, THandlers> {
|
|
20
|
+
middleware?: Constrain<TServerMiddlewares, ReadonlyArray<AnyRequestMiddleware>>;
|
|
21
|
+
handlers?: Constrain<THandlers, Partial<Record<RouteMethod, RouteMethodHandlerFn<TRegister, TParentRoute, TPath, TServerMiddlewares, any, any>>> | ((opts: HandlersFnOpts<TRegister, TParentRoute, TPath, TServerMiddlewares>) => CustomHandlerFunctionsRecord<TRegister, TParentRoute, TPath, TServerMiddlewares, any, any>)>;
|
|
22
|
+
test?: (test: Expand<ExtractHandlersContext<THandlers>>) => void;
|
|
23
|
+
}
|
|
24
|
+
declare const createHandlersSymbol: unique symbol;
|
|
25
|
+
type CustomHandlerFunctionsRecord<TRegister, TParentRoute extends AnyRoute, TPath extends string, TServerMiddlewares, TMethodMiddlewares, TServerContext> = {
|
|
26
|
+
[createHandlersSymbol]: true;
|
|
27
|
+
} & Partial<Record<RouteMethod, RouteMethodHandler<TRegister, TParentRoute, TPath, TServerMiddlewares, TMethodMiddlewares, TServerContext>>>;
|
|
28
|
+
export interface HandlersFnOpts<TRegister, TParentRoute extends AnyRoute, TPath extends string, TServerMiddlewares> {
|
|
29
|
+
createHandlers: CreateHandlersFn<TRegister, TParentRoute, TPath, TServerMiddlewares>;
|
|
30
|
+
}
|
|
31
|
+
export type CreateHandlersFn<TRegister, TParentRoute extends AnyRoute, TPath extends string, TServerMiddlewares> = <const TMethodAllMiddlewares, const TMethodGetMiddlewares, const TMethodPostMiddlewares, const TMethodPutMiddlewares, const TMethodPatchMiddlewares, const TMethodDeleteMiddlewares, const TMethodOptionsMiddlewares, const TMethodHeadMiddlewares, TServerContext>(opts: CreateMethodFnOpts<TRegister, TParentRoute, TPath, TServerMiddlewares, TMethodAllMiddlewares, TMethodGetMiddlewares, TMethodPostMiddlewares, TMethodPutMiddlewares, TMethodPatchMiddlewares, TMethodDeleteMiddlewares, TMethodOptionsMiddlewares, TMethodHeadMiddlewares, TServerContext>) => CustomHandlerFunctionsRecord<TRegister, TParentRoute, TPath, TServerMiddlewares, any, TServerContext>;
|
|
32
|
+
export interface CreateMethodFnOpts<TRegister, TParentRoute extends AnyRoute, TPath extends string, TServerMiddlewares, TMethodAllMiddlewares, TMethodGetMiddlewares, TMethodPostMiddlewares, TMethodPutMiddlewares, TMethodPatchMiddlewares, TMethodDeleteMiddlewares, TMethodOptionsMiddlewares, TMethodHeadMiddlewares, TServerContext> {
|
|
33
|
+
ALL?: RouteMethodHandler<TRegister, TParentRoute, TPath, TServerMiddlewares, TMethodAllMiddlewares, TServerContext>;
|
|
34
|
+
GET?: RouteMethodHandler<TRegister, TParentRoute, TPath, TServerMiddlewares, TMethodGetMiddlewares, TServerContext>;
|
|
35
|
+
POST?: RouteMethodHandler<TRegister, TParentRoute, TPath, TServerMiddlewares, TMethodPostMiddlewares, TServerContext>;
|
|
36
|
+
PUT?: RouteMethodHandler<TRegister, TParentRoute, TPath, TServerMiddlewares, TMethodPutMiddlewares, TServerContext>;
|
|
37
|
+
PATCH?: RouteMethodHandler<TRegister, TParentRoute, TPath, TServerMiddlewares, TMethodPatchMiddlewares, TServerContext>;
|
|
38
|
+
DELETE?: RouteMethodHandler<TRegister, TParentRoute, TPath, TServerMiddlewares, TMethodDeleteMiddlewares, TServerContext>;
|
|
39
|
+
OPTIONS?: RouteMethodHandler<TRegister, TParentRoute, TPath, TServerMiddlewares, TMethodOptionsMiddlewares, TServerContext>;
|
|
40
|
+
HEAD?: RouteMethodHandler<TRegister, TParentRoute, TPath, TServerMiddlewares, TMethodHeadMiddlewares, TServerContext>;
|
|
41
|
+
}
|
|
42
|
+
export type RouteMethodHandler<TRegister, TParentRoute extends AnyRoute, TPath extends string, TServerMiddlewares, TMethodMiddlewares, TServerContext> = RouteMethodHandlerFn<TRegister, TParentRoute, TPath, TServerMiddlewares, TMethodMiddlewares, TServerContext> | RouteMethodBuilderOptions<TRegister, TParentRoute, TPath, TServerMiddlewares, TMethodMiddlewares, TServerContext>;
|
|
43
|
+
export interface RouteMethodBuilderOptions<TRegister, TParentRoute extends AnyRoute, TFullPath extends string, TServerMiddlewares, TMethodMiddlewares, TResponse> {
|
|
44
|
+
handler?: RouteMethodHandlerFn<TRegister, TParentRoute, TFullPath, TServerMiddlewares, TMethodMiddlewares, TResponse>;
|
|
45
|
+
middleware?: Constrain<TMethodMiddlewares, ReadonlyArray<AnyRequestMiddleware>>;
|
|
46
|
+
}
|
|
47
|
+
export type ResolveAllServerContext<TRegister, TParentRoute extends AnyRoute, TServerMiddlewares> = unknown extends TParentRoute ? AssignAllServerRequestContext<TRegister, TServerMiddlewares, {}> : Assign<TParentRoute['types']['allServerContext'], AssignAllServerRequestContext<TRegister, TServerMiddlewares, {}>>;
|
|
48
|
+
export type RouteMethod = 'ALL' | 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
|
|
49
|
+
export type RouteMethodHandlerFn<TRegister, TParentRoute extends AnyRoute, TFullPath extends string, TServerMiddlewares, TMethodMiddlewares, TServerContext> = (ctx: RouteMethodHandlerCtx<TRegister, TParentRoute, TFullPath, TServerMiddlewares, TMethodMiddlewares>) => RouteMethodResult<TServerContext> | Promise<RouteMethodResult<TServerContext>>;
|
|
50
|
+
export type RouteMethodResult<TContext> = Response | undefined | RouteMethodNextResult<TContext>;
|
|
51
|
+
export type RouteMethodNextResult<TContext> = {
|
|
52
|
+
isNext: true;
|
|
53
|
+
context: TContext;
|
|
54
|
+
};
|
|
55
|
+
export interface RouteMethodHandlerCtx<in out TRegister, in out TParentRoute extends AnyRoute, in out TFullPath extends string, in out TServerMiddlewares, in out TMethodMiddlewares> {
|
|
56
|
+
context: Expand<AssignAllMethodContext<TRegister, TParentRoute, TServerMiddlewares, TMethodMiddlewares>>;
|
|
57
|
+
request: Request;
|
|
58
|
+
params: Expand<ResolveParams<TFullPath>>;
|
|
59
|
+
pathname: TFullPath;
|
|
60
|
+
next: <TContext = undefined>(options?: {
|
|
61
|
+
context?: TContext;
|
|
62
|
+
}) => RouteMethodNextResult<TContext>;
|
|
63
|
+
}
|
|
64
|
+
export type MergeMethodMiddlewares<TServerMiddlewares, TMethodMiddlewares> = TServerMiddlewares extends ReadonlyArray<any> ? TMethodMiddlewares extends ReadonlyArray<any> ? readonly [...TServerMiddlewares, ...TMethodMiddlewares] : TServerMiddlewares : TMethodMiddlewares;
|
|
65
|
+
export type AssignAllMethodContext<TRegister, TParentRoute extends AnyRoute, TServerMiddlewares, TMethodMiddlewares> = ResolveAllServerContext<TRegister, TParentRoute, MergeMethodMiddlewares<TServerMiddlewares, TMethodMiddlewares>>;
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AnyRouter, Awaitable } from '@tanstack/router-core';
|
|
2
|
+
import { AnyStartInstance } from './createStart.js';
|
|
3
|
+
export interface StartEntry {
|
|
4
|
+
startInstance: AnyStartInstance | undefined;
|
|
5
|
+
}
|
|
6
|
+
export interface RouterEntry {
|
|
7
|
+
getRouter: () => Awaitable<AnyRouter>;
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/start-client-core",
|
|
3
|
-
"version": "1.132.0
|
|
3
|
+
"version": "1.132.0",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,24 +32,37 @@
|
|
|
32
32
|
"default": "./dist/esm/index.js"
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
|
+
"./client": {
|
|
36
|
+
"import": {
|
|
37
|
+
"types": "./dist/esm/client/index.d.ts",
|
|
38
|
+
"default": "./dist/esm/client/index.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
35
41
|
"./package.json": "./package.json"
|
|
36
42
|
},
|
|
43
|
+
"imports": {
|
|
44
|
+
"#tanstack-start-entry": {
|
|
45
|
+
"default": "./dist/esm/fake-start-entry.js"
|
|
46
|
+
},
|
|
47
|
+
"#tanstack-router-entry": {
|
|
48
|
+
"default": "./dist/esm/fake-start-entry.js"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
37
51
|
"sideEffects": false,
|
|
38
52
|
"files": [
|
|
39
53
|
"dist",
|
|
40
54
|
"src"
|
|
41
55
|
],
|
|
42
56
|
"engines": {
|
|
43
|
-
"node": ">=12"
|
|
57
|
+
"node": ">=22.12.0"
|
|
44
58
|
},
|
|
45
59
|
"dependencies": {
|
|
46
60
|
"cookie-es": "^1.2.2",
|
|
47
61
|
"seroval": "^1.3.2",
|
|
48
|
-
"seroval-plugins": "^1.3.2",
|
|
49
62
|
"tiny-invariant": "^1.3.3",
|
|
50
63
|
"tiny-warning": "^1.0.3",
|
|
51
|
-
"@tanstack/router-core": "1.132.0
|
|
52
|
-
"@tanstack/start-storage-context": "1.132.0
|
|
64
|
+
"@tanstack/router-core": "1.132.0",
|
|
65
|
+
"@tanstack/start-storage-context": "1.132.0"
|
|
53
66
|
},
|
|
54
67
|
"scripts": {}
|
|
55
68
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createSerializationAdapter } from '@tanstack/router-core'
|
|
2
|
-
import { createClientRpc } from '../createClientRpc'
|
|
3
2
|
import { TSS_SERVER_FUNCTION } from '../constants'
|
|
3
|
+
import { createClientRpc } from './createClientRpc'
|
|
4
4
|
|
|
5
5
|
export const ServerFunctionSerializationAdapter = createSerializationAdapter({
|
|
6
6
|
key: '$TSS/serverfn',
|
|
7
7
|
test: (v): v is { functionId: string } => {
|
|
8
|
-
if (typeof v !== '
|
|
8
|
+
if (typeof v !== 'function') return false
|
|
9
9
|
|
|
10
10
|
if (!(TSS_SERVER_FUNCTION in v)) return false
|
|
11
11
|
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { TSS_SERVER_FUNCTION } from '
|
|
1
|
+
import { TSS_SERVER_FUNCTION } from '../constants'
|
|
2
2
|
import { serverFnFetcher } from './serverFnFetcher'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// make sure this get's hoisted
|
|
5
|
+
// eslint-disable-next-line no-var
|
|
6
|
+
var baseUrl: string
|
|
5
7
|
function sanitizeBase(base: string) {
|
|
6
8
|
return base.replace(/^\/|\/$/g, '')
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
export
|
|
11
|
+
export function createClientRpc(functionId: string) {
|
|
10
12
|
if (!baseUrl) {
|
|
11
13
|
const sanitizedAppBase = sanitizeBase(process.env.TSS_APP_BASE || '/')
|
|
12
14
|
const sanitizedServerBase = sanitizeBase(process.env.TSS_SERVER_FN_BASE!)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { hydrate } from '@tanstack/router-core/ssr/client'
|
|
2
|
+
|
|
3
|
+
import { ServerFunctionSerializationAdapter } from './ServerFunctionSerializationAdapter'
|
|
4
|
+
import type { AnyStartInstanceOptions } from '../createStart'
|
|
5
|
+
import type { AnyRouter, AnySerializationAdapter } from '@tanstack/router-core'
|
|
6
|
+
import * as startEntry from '#tanstack-start-entry'
|
|
7
|
+
import { getRouter } from '#tanstack-router-entry'
|
|
8
|
+
|
|
9
|
+
export async function hydrateStart(): Promise<AnyRouter> {
|
|
10
|
+
const router = await getRouter()
|
|
11
|
+
|
|
12
|
+
let serializationAdapters: Array<AnySerializationAdapter>
|
|
13
|
+
if (startEntry.startInstance) {
|
|
14
|
+
const startOptions = await startEntry.startInstance.getOptions()
|
|
15
|
+
window.__TSS_START_OPTIONS__ = startOptions as AnyStartInstanceOptions
|
|
16
|
+
serializationAdapters = startOptions.serializationAdapters
|
|
17
|
+
router.options.defaultSsr = startOptions.defaultSsr
|
|
18
|
+
} else {
|
|
19
|
+
serializationAdapters = []
|
|
20
|
+
window.__TSS_START_OPTIONS__ = {
|
|
21
|
+
serializationAdapters,
|
|
22
|
+
} as AnyStartInstanceOptions
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
serializationAdapters.push(ServerFunctionSerializationAdapter)
|
|
26
|
+
router.options.serializationAdapters = serializationAdapters
|
|
27
|
+
|
|
28
|
+
if (!router.state.matches.length) {
|
|
29
|
+
await hydrate(router)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return router
|
|
33
|
+
}
|
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
} from '@tanstack/router-core'
|
|
7
7
|
import { fromCrossJSON, toJSONAsync } from 'seroval'
|
|
8
8
|
import invariant from 'tiny-invariant'
|
|
9
|
-
import {
|
|
10
|
-
import { TSS_FORMDATA_CONTEXT, X_TSS_SERIALIZED } from '
|
|
11
|
-
import type { FunctionMiddlewareClientFnOptions } from '
|
|
9
|
+
import { getDefaultSerovalPlugins } from '../getDefaultSerovalPlugins'
|
|
10
|
+
import { TSS_FORMDATA_CONTEXT, X_TSS_SERIALIZED } from '../constants'
|
|
11
|
+
import type { FunctionMiddlewareClientFnOptions } from '../createMiddleware'
|
|
12
12
|
import type { Plugin as SerovalPlugin } from 'seroval'
|
|
13
13
|
|
|
14
14
|
let serovalPlugins: Array<SerovalPlugin<any, any>> | null = null
|
|
@@ -19,20 +19,14 @@ export async function serverFnFetcher(
|
|
|
19
19
|
handler: (url: string, requestInit: RequestInit) => Promise<Response>,
|
|
20
20
|
) {
|
|
21
21
|
if (!serovalPlugins) {
|
|
22
|
-
serovalPlugins =
|
|
22
|
+
serovalPlugins = getDefaultSerovalPlugins()
|
|
23
23
|
}
|
|
24
24
|
const _first = args[0]
|
|
25
25
|
|
|
26
26
|
// If createServerFn was used to wrap the fetcher,
|
|
27
27
|
// We need to handle the arguments differently
|
|
28
28
|
if (isPlainObject(_first) && _first.method) {
|
|
29
|
-
const first = _first as FunctionMiddlewareClientFnOptions<
|
|
30
|
-
any,
|
|
31
|
-
any,
|
|
32
|
-
any,
|
|
33
|
-
any,
|
|
34
|
-
any
|
|
35
|
-
> & {
|
|
29
|
+
const first = _first as FunctionMiddlewareClientFnOptions<any, any, any> & {
|
|
36
30
|
headers: HeadersInit
|
|
37
31
|
}
|
|
38
32
|
const type = first.data instanceof FormData ? 'formData' : 'payload'
|
|
@@ -53,6 +47,9 @@ export async function serverFnFetcher(
|
|
|
53
47
|
|
|
54
48
|
// If the method is GET, we need to move the payload to the query string
|
|
55
49
|
if (first.method === 'GET') {
|
|
50
|
+
if (type === 'formData') {
|
|
51
|
+
throw new Error('FormData is not supported with GET requests')
|
|
52
|
+
}
|
|
56
53
|
const encodedPayload = encode({
|
|
57
54
|
payload: await serializePayload(first),
|
|
58
55
|
})
|
|
@@ -71,9 +68,6 @@ export async function serverFnFetcher(
|
|
|
71
68
|
} else {
|
|
72
69
|
url += `?createServerFn`
|
|
73
70
|
}
|
|
74
|
-
if (first.response === 'raw') {
|
|
75
|
-
url += `&raw`
|
|
76
|
-
}
|
|
77
71
|
|
|
78
72
|
return await getResponse(async () =>
|
|
79
73
|
handler(url, {
|
|
@@ -101,12 +95,13 @@ export async function serverFnFetcher(
|
|
|
101
95
|
}
|
|
102
96
|
|
|
103
97
|
async function serializePayload(
|
|
104
|
-
opts: FunctionMiddlewareClientFnOptions<any, any, any
|
|
98
|
+
opts: FunctionMiddlewareClientFnOptions<any, any, any>,
|
|
105
99
|
) {
|
|
106
100
|
const payloadToSerialize: any = {}
|
|
107
101
|
if (opts.data) {
|
|
108
102
|
payloadToSerialize['data'] = opts.data
|
|
109
103
|
}
|
|
104
|
+
|
|
110
105
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
111
106
|
if (opts.context && Object.keys(opts.context).length > 0) {
|
|
112
107
|
payloadToSerialize['context'] = opts.context
|
|
@@ -122,7 +117,7 @@ async function serialize(data: any) {
|
|
|
122
117
|
}
|
|
123
118
|
|
|
124
119
|
async function getFetcherRequestOptions(
|
|
125
|
-
opts: FunctionMiddlewareClientFnOptions<any, any, any
|
|
120
|
+
opts: FunctionMiddlewareClientFnOptions<any, any, any>,
|
|
126
121
|
) {
|
|
127
122
|
if (opts.method === 'POST') {
|
|
128
123
|
if (opts.data instanceof FormData) {
|
package/src/constants.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export const TSS_FORMDATA_CONTEXT = '__TSS_CONTEXT'
|
|
2
2
|
export const TSS_SERVER_FUNCTION = Symbol.for('TSS_SERVER_FUNCTION')
|
|
3
|
+
export const TSS_SERVER_FUNCTION_FACTORY = Symbol.for(
|
|
4
|
+
'TSS_SERVER_FUNCTION_FACTORY',
|
|
5
|
+
)
|
|
3
6
|
|
|
4
7
|
export const X_TSS_SERIALIZED = 'x-tss-serialized'
|
|
5
8
|
export {}
|