@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,122 @@
|
|
|
1
|
+
import { createMiddleware } from './createMiddleware'
|
|
2
|
+
import type {
|
|
3
|
+
AnyFunctionMiddleware,
|
|
4
|
+
AnyRequestMiddleware,
|
|
5
|
+
CreateMiddlewareFn,
|
|
6
|
+
} from './createMiddleware'
|
|
7
|
+
import type {
|
|
8
|
+
AnySerializationAdapter,
|
|
9
|
+
Register,
|
|
10
|
+
SSROption,
|
|
11
|
+
} from '@tanstack/router-core'
|
|
12
|
+
|
|
13
|
+
export interface StartInstanceOptions<
|
|
14
|
+
in out TSerializationAdapters,
|
|
15
|
+
in out TDefaultSsr,
|
|
16
|
+
in out TRequestMiddlewares,
|
|
17
|
+
in out TFunctionMiddlewares,
|
|
18
|
+
> {
|
|
19
|
+
'~types': StartInstanceTypes<
|
|
20
|
+
TSerializationAdapters,
|
|
21
|
+
TDefaultSsr,
|
|
22
|
+
TRequestMiddlewares,
|
|
23
|
+
TFunctionMiddlewares
|
|
24
|
+
>
|
|
25
|
+
serializationAdapters?: TSerializationAdapters
|
|
26
|
+
defaultSsr?: TDefaultSsr
|
|
27
|
+
requestMiddleware?: TRequestMiddlewares
|
|
28
|
+
functionMiddleware?: TFunctionMiddlewares
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface StartInstance<
|
|
32
|
+
in out TSerializationAdapters,
|
|
33
|
+
in out TDefaultSsr,
|
|
34
|
+
in out TRequestMiddlewares,
|
|
35
|
+
in out TFunctionMiddlewares,
|
|
36
|
+
> {
|
|
37
|
+
getOptions: () =>
|
|
38
|
+
| Promise<
|
|
39
|
+
StartInstanceOptions<
|
|
40
|
+
TSerializationAdapters,
|
|
41
|
+
TDefaultSsr,
|
|
42
|
+
TRequestMiddlewares,
|
|
43
|
+
TFunctionMiddlewares
|
|
44
|
+
>
|
|
45
|
+
>
|
|
46
|
+
| StartInstanceOptions<
|
|
47
|
+
TSerializationAdapters,
|
|
48
|
+
TDefaultSsr,
|
|
49
|
+
TRequestMiddlewares,
|
|
50
|
+
TFunctionMiddlewares
|
|
51
|
+
>
|
|
52
|
+
createMiddleware: CreateMiddlewareFn<Register>
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface StartInstanceTypes<
|
|
56
|
+
in out TSerializationAdapters,
|
|
57
|
+
in out TDefaultSsr,
|
|
58
|
+
in out TRequestMiddlewares,
|
|
59
|
+
in out TFunctionMiddlewares,
|
|
60
|
+
> {
|
|
61
|
+
serializationAdapters: TSerializationAdapters
|
|
62
|
+
defaultSsr: TDefaultSsr
|
|
63
|
+
requestMiddleware: TRequestMiddlewares
|
|
64
|
+
functionMiddleware: TFunctionMiddlewares
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const createStart = <
|
|
68
|
+
const TSerializationAdapters extends
|
|
69
|
+
ReadonlyArray<AnySerializationAdapter> = [],
|
|
70
|
+
TDefaultSsr extends SSROption = SSROption,
|
|
71
|
+
const TRequestMiddlewares extends ReadonlyArray<AnyRequestMiddleware> = [],
|
|
72
|
+
const TFunctionMiddlewares extends ReadonlyArray<AnyFunctionMiddleware> = [],
|
|
73
|
+
>(
|
|
74
|
+
getOptions: () =>
|
|
75
|
+
| Promise<
|
|
76
|
+
Omit<
|
|
77
|
+
StartInstanceOptions<
|
|
78
|
+
TSerializationAdapters,
|
|
79
|
+
TDefaultSsr,
|
|
80
|
+
TRequestMiddlewares,
|
|
81
|
+
TFunctionMiddlewares
|
|
82
|
+
>,
|
|
83
|
+
'~types'
|
|
84
|
+
>
|
|
85
|
+
>
|
|
86
|
+
| Omit<
|
|
87
|
+
StartInstanceOptions<
|
|
88
|
+
TSerializationAdapters,
|
|
89
|
+
TDefaultSsr,
|
|
90
|
+
TRequestMiddlewares,
|
|
91
|
+
TFunctionMiddlewares
|
|
92
|
+
>,
|
|
93
|
+
'~types'
|
|
94
|
+
>,
|
|
95
|
+
): StartInstance<
|
|
96
|
+
TSerializationAdapters,
|
|
97
|
+
TDefaultSsr,
|
|
98
|
+
TRequestMiddlewares,
|
|
99
|
+
TFunctionMiddlewares
|
|
100
|
+
> => {
|
|
101
|
+
return {
|
|
102
|
+
getOptions: async () => {
|
|
103
|
+
const options = await getOptions()
|
|
104
|
+
return options
|
|
105
|
+
},
|
|
106
|
+
createMiddleware: createMiddleware as any,
|
|
107
|
+
} as StartInstance<
|
|
108
|
+
TSerializationAdapters,
|
|
109
|
+
TDefaultSsr,
|
|
110
|
+
TRequestMiddlewares,
|
|
111
|
+
TFunctionMiddlewares
|
|
112
|
+
>
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export type AnyStartInstance = StartInstance<any, any, any, any>
|
|
116
|
+
export type AnyStartInstanceOptions = StartInstanceOptions<any, any, any, any>
|
|
117
|
+
|
|
118
|
+
declare module '@tanstack/router-core' {
|
|
119
|
+
interface Register {
|
|
120
|
+
ssr: true
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
makeSerovalPlugin,
|
|
3
|
+
defaultSerovalPlugins as routerDefaultSerovalPlugins,
|
|
4
|
+
} from '@tanstack/router-core'
|
|
5
|
+
import { getStartOptions } from './getStartOptions'
|
|
6
|
+
import type { AnySerializationAdapter } from '@tanstack/router-core'
|
|
7
|
+
|
|
8
|
+
export function getDefaultSerovalPlugins() {
|
|
9
|
+
const start = getStartOptions()
|
|
10
|
+
const adapters = start.serializationAdapters as
|
|
11
|
+
| Array<AnySerializationAdapter>
|
|
12
|
+
| undefined
|
|
13
|
+
return [
|
|
14
|
+
...(adapters?.map(makeSerovalPlugin) ?? []),
|
|
15
|
+
...routerDefaultSerovalPlugins,
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getStartContext } from '@tanstack/start-storage-context'
|
|
2
|
+
import { createIsomorphicFn } from './createIsomorphicFn'
|
|
3
|
+
import type { AssignAllServerRequestContext } from './createMiddleware'
|
|
4
|
+
import type { Expand, Register } from '@tanstack/router-core'
|
|
5
|
+
|
|
6
|
+
export const getGlobalStartContext: () =>
|
|
7
|
+
| Expand<AssignAllServerRequestContext<Register, []>>
|
|
8
|
+
| undefined = createIsomorphicFn()
|
|
9
|
+
.client(() => undefined)
|
|
10
|
+
.server(() => {
|
|
11
|
+
const context = getStartContext().contextAfterGlobalMiddlewares
|
|
12
|
+
if (!context) {
|
|
13
|
+
throw new Error(
|
|
14
|
+
`Global context not set yet, you are calling getGlobalStartContext() before the global middlewares are applied.`,
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
return context
|
|
18
|
+
})
|
package/src/getRouterInstance.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { getStartContext } from '@tanstack/start-storage-context'
|
|
2
2
|
import { createIsomorphicFn } from './createIsomorphicFn'
|
|
3
|
+
import type { Awaitable, RegisteredRouter } from '@tanstack/router-core'
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export const getRouterInstance: () => Awaitable<RegisteredRouter> =
|
|
6
|
+
createIsomorphicFn()
|
|
7
|
+
.client(() => window.__TSR_ROUTER__!)
|
|
8
|
+
.server(() => getStartContext().getRouter())
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { getStartContext } from '@tanstack/start-storage-context'
|
|
2
|
+
import { createServerOnlyFn } from './envOnly'
|
|
3
|
+
|
|
4
|
+
export const getServerContextAfterGlobalMiddlewares = createServerOnlyFn(() => {
|
|
5
|
+
const start = getStartContext()
|
|
6
|
+
return start.contextAfterGlobalMiddlewares
|
|
7
|
+
})
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { getStartContext } from '@tanstack/start-storage-context'
|
|
2
|
+
import { createIsomorphicFn } from './createIsomorphicFn'
|
|
3
|
+
|
|
4
|
+
export const getStartOptions = createIsomorphicFn()
|
|
5
|
+
.client(() => window.__TSS_START_OPTIONS__!)
|
|
6
|
+
.server(() => getStartContext().startOptions)
|
package/src/global.ts
ADDED
package/src/index.tsx
CHANGED
|
@@ -33,7 +33,6 @@ export {
|
|
|
33
33
|
type FunctionClientResultWithContext,
|
|
34
34
|
type AssignAllClientContextBeforeNext,
|
|
35
35
|
type AssignAllMiddleware,
|
|
36
|
-
type AssignAllServerContext,
|
|
37
36
|
type FunctionMiddlewareAfterValidator,
|
|
38
37
|
type FunctionMiddlewareClientFn,
|
|
39
38
|
type FunctionMiddlewareServerFnResult,
|
|
@@ -43,10 +42,6 @@ export {
|
|
|
43
42
|
type FunctionServerResultWithContext,
|
|
44
43
|
type AnyRequestMiddleware,
|
|
45
44
|
} from './createMiddleware'
|
|
46
|
-
export {
|
|
47
|
-
registerGlobalMiddleware,
|
|
48
|
-
globalMiddleware,
|
|
49
|
-
} from './registerGlobalMiddleware'
|
|
50
45
|
export type {
|
|
51
46
|
CompiledFetcherFnOptions,
|
|
52
47
|
CompiledFetcherFn,
|
|
@@ -56,7 +51,6 @@ export type {
|
|
|
56
51
|
FetcherBaseOptions,
|
|
57
52
|
ServerFn,
|
|
58
53
|
ServerFnCtx,
|
|
59
|
-
ServerFnResponseType,
|
|
60
54
|
MiddlewareFn,
|
|
61
55
|
ServerFnMiddlewareOptions,
|
|
62
56
|
ServerFnMiddlewareResult,
|
|
@@ -70,17 +64,24 @@ export type {
|
|
|
70
64
|
export {
|
|
71
65
|
applyMiddleware,
|
|
72
66
|
execValidator,
|
|
73
|
-
serverFnBaseToMiddleware,
|
|
74
67
|
flattenMiddlewares,
|
|
75
68
|
executeMiddleware,
|
|
76
69
|
} from './createServerFn'
|
|
77
70
|
|
|
78
|
-
export { createClientRpc } from './createClientRpc'
|
|
79
|
-
|
|
80
|
-
export { getDefaultSerovalPlugins } from './serializer/getDefaultSerovalPlugins'
|
|
81
|
-
|
|
82
71
|
export {
|
|
83
72
|
TSS_FORMDATA_CONTEXT,
|
|
84
73
|
TSS_SERVER_FUNCTION,
|
|
85
74
|
X_TSS_SERIALIZED,
|
|
86
75
|
} from './constants'
|
|
76
|
+
|
|
77
|
+
export type * from './serverRoute'
|
|
78
|
+
|
|
79
|
+
export type * from './startEntry'
|
|
80
|
+
|
|
81
|
+
export { createStart } from './createStart'
|
|
82
|
+
export type { AnyStartInstance, AnyStartInstanceOptions } from './createStart'
|
|
83
|
+
export type { Register } from '@tanstack/router-core'
|
|
84
|
+
|
|
85
|
+
export { getRouterInstance } from './getRouterInstance'
|
|
86
|
+
export { getDefaultSerovalPlugins } from './getDefaultSerovalPlugins'
|
|
87
|
+
export { getGlobalStartContext } from './getGlobalStartContext'
|