@tanstack/start-client-core 1.121.20 → 1.121.21

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.
Files changed (73) hide show
  1. package/dist/cjs/createIsomorphicFn.cjs +7 -0
  2. package/dist/cjs/createIsomorphicFn.cjs.map +1 -0
  3. package/dist/cjs/createIsomorphicFn.d.cts +12 -0
  4. package/dist/cjs/createMiddleware.cjs +37 -0
  5. package/dist/cjs/createMiddleware.cjs.map +1 -0
  6. package/dist/cjs/createMiddleware.d.cts +175 -0
  7. package/dist/cjs/createServerFn.cjs +378 -0
  8. package/dist/cjs/createServerFn.cjs.map +1 -0
  9. package/dist/cjs/createServerFn.d.cts +159 -0
  10. package/dist/cjs/envOnly.cjs +7 -0
  11. package/dist/cjs/envOnly.cjs.map +1 -0
  12. package/dist/cjs/envOnly.d.cts +4 -0
  13. package/dist/cjs/headers.cjs +30 -0
  14. package/dist/cjs/headers.cjs.map +1 -0
  15. package/dist/cjs/headers.d.cts +5 -0
  16. package/dist/cjs/index.cjs +33 -0
  17. package/dist/cjs/index.cjs.map +1 -0
  18. package/dist/cjs/index.d.cts +11 -0
  19. package/dist/cjs/json.cjs +14 -0
  20. package/dist/cjs/json.cjs.map +1 -0
  21. package/dist/cjs/json.d.cts +2 -0
  22. package/dist/cjs/registerGlobalMiddleware.cjs +9 -0
  23. package/dist/cjs/registerGlobalMiddleware.cjs.map +1 -0
  24. package/dist/cjs/registerGlobalMiddleware.d.cts +5 -0
  25. package/dist/cjs/serializer.cjs +152 -0
  26. package/dist/cjs/serializer.cjs.map +1 -0
  27. package/dist/cjs/serializer.d.cts +2 -0
  28. package/dist/cjs/ssr-client.cjs +131 -0
  29. package/dist/cjs/ssr-client.cjs.map +1 -0
  30. package/dist/cjs/ssr-client.d.cts +65 -0
  31. package/dist/cjs/tests/createIsomorphicFn.test-d.d.cts +1 -0
  32. package/dist/cjs/tests/createServerFn.test-d.d.cts +1 -0
  33. package/dist/cjs/tests/createServerMiddleware.test-d.d.cts +1 -0
  34. package/dist/cjs/tests/envOnly.test-d.d.cts +1 -0
  35. package/dist/cjs/tests/json.test.d.cts +1 -0
  36. package/dist/cjs/tests/transformer.test.d.cts +1 -0
  37. package/dist/esm/createIsomorphicFn.d.ts +12 -0
  38. package/dist/esm/createIsomorphicFn.js +7 -0
  39. package/dist/esm/createIsomorphicFn.js.map +1 -0
  40. package/dist/esm/createMiddleware.d.ts +175 -0
  41. package/dist/esm/createMiddleware.js +37 -0
  42. package/dist/esm/createMiddleware.js.map +1 -0
  43. package/dist/esm/createServerFn.d.ts +159 -0
  44. package/dist/esm/createServerFn.js +356 -0
  45. package/dist/esm/createServerFn.js.map +1 -0
  46. package/dist/esm/envOnly.d.ts +4 -0
  47. package/dist/esm/envOnly.js +7 -0
  48. package/dist/esm/envOnly.js.map +1 -0
  49. package/dist/esm/headers.d.ts +5 -0
  50. package/dist/esm/headers.js +30 -0
  51. package/dist/esm/headers.js.map +1 -0
  52. package/dist/esm/index.d.ts +11 -0
  53. package/dist/esm/index.js +30 -0
  54. package/dist/esm/index.js.map +1 -0
  55. package/dist/esm/json.d.ts +2 -0
  56. package/dist/esm/json.js +14 -0
  57. package/dist/esm/json.js.map +1 -0
  58. package/dist/esm/registerGlobalMiddleware.d.ts +5 -0
  59. package/dist/esm/registerGlobalMiddleware.js +9 -0
  60. package/dist/esm/registerGlobalMiddleware.js.map +1 -0
  61. package/dist/esm/serializer.d.ts +2 -0
  62. package/dist/esm/serializer.js +152 -0
  63. package/dist/esm/serializer.js.map +1 -0
  64. package/dist/esm/ssr-client.d.ts +65 -0
  65. package/dist/esm/ssr-client.js +131 -0
  66. package/dist/esm/ssr-client.js.map +1 -0
  67. package/dist/esm/tests/createIsomorphicFn.test-d.d.ts +1 -0
  68. package/dist/esm/tests/createServerFn.test-d.d.ts +1 -0
  69. package/dist/esm/tests/createServerMiddleware.test-d.d.ts +1 -0
  70. package/dist/esm/tests/envOnly.test-d.d.ts +1 -0
  71. package/dist/esm/tests/json.test.d.ts +1 -0
  72. package/dist/esm/tests/transformer.test.d.ts +1 -0
  73. package/package.json +2 -2
@@ -0,0 +1,175 @@
1
+ import { ConstrainValidator, Method, ServerFnResponseType, ServerFnTypeOrTypeFn } from './createServerFn.js';
2
+ import { Assign, Constrain, Expand, IntersectAssign, ResolveValidatorInput, ResolveValidatorOutput, SerializerStringify } from '@tanstack/router-core';
3
+ export declare function createMiddleware<TType extends MiddlewareType>(options: {
4
+ type: TType;
5
+ validateClient?: boolean;
6
+ }, __opts?: FunctionMiddlewareOptions<unknown, undefined, undefined, undefined, ServerFnResponseType>): CreateMiddlewareResult<TType>;
7
+ export type MiddlewareType = 'request' | 'function';
8
+ export type CreateMiddlewareResult<TType extends MiddlewareType> = 'function' extends TType ? FunctionMiddleware<ServerFnResponseType> : RequestMiddleware;
9
+ export interface FunctionMiddleware<TServerFnResponseType extends ServerFnResponseType> extends FunctionMiddlewareAfterMiddleware<unknown, TServerFnResponseType> {
10
+ middleware: <const TNewMiddlewares = undefined>(middlewares: Constrain<TNewMiddlewares, ReadonlyArray<AnyFunctionMiddleware>>) => FunctionMiddlewareAfterMiddleware<TNewMiddlewares, TServerFnResponseType>;
11
+ }
12
+ export interface FunctionMiddlewareAfterMiddleware<TMiddlewares, TServerFnResponseType extends ServerFnResponseType> extends FunctionMiddlewareWithTypes<TMiddlewares, undefined, undefined, undefined, undefined, undefined, TServerFnResponseType>, FunctionMiddlewareServer<TMiddlewares, undefined, undefined, undefined, TServerFnResponseType>, FunctionMiddlewareClient<TMiddlewares, undefined, TServerFnResponseType>, FunctionMiddlewareValidator<TMiddlewares, TServerFnResponseType> {
13
+ }
14
+ export interface FunctionMiddlewareWithTypes<TMiddlewares, TValidator, TServerContext, TServerSendContext, TClientContext, TClientSendContext, TServerFnResponseType extends ServerFnResponseType> {
15
+ _types: FunctionMiddlewareTypes<TMiddlewares, TValidator, TServerContext, TServerSendContext, TClientContext, TClientSendContext>;
16
+ options: FunctionMiddlewareOptions<TMiddlewares, TValidator, TServerContext, TClientContext, TServerFnResponseType>;
17
+ }
18
+ export interface FunctionMiddlewareTypes<in out TMiddlewares, in out TValidator, in out TServerContext, in out TServerSendContext, in out TClientContext, in out TClientSendContext> {
19
+ type: 'function';
20
+ middlewares: TMiddlewares;
21
+ input: ResolveValidatorInput<TValidator>;
22
+ allInput: IntersectAllValidatorInputs<TMiddlewares, TValidator>;
23
+ output: ResolveValidatorOutput<TValidator>;
24
+ allOutput: IntersectAllValidatorOutputs<TMiddlewares, TValidator>;
25
+ clientContext: TClientContext;
26
+ allClientContextBeforeNext: AssignAllClientContextBeforeNext<TMiddlewares, TClientContext>;
27
+ allClientContextAfterNext: AssignAllClientContextAfterNext<TMiddlewares, TClientContext, TClientSendContext>;
28
+ serverContext: TServerContext;
29
+ serverSendContext: TServerSendContext;
30
+ allServerSendContext: AssignAllServerSendContext<TMiddlewares, TServerSendContext>;
31
+ allServerContext: AssignAllServerContext<TMiddlewares, TServerSendContext, TServerContext>;
32
+ clientSendContext: TClientSendContext;
33
+ allClientSendContext: AssignAllClientSendContext<TMiddlewares, TClientSendContext>;
34
+ validator: TValidator;
35
+ }
36
+ /**
37
+ * Recursively resolve the input type produced by a sequence of middleware
38
+ */
39
+ export type IntersectAllValidatorInputs<TMiddlewares, TValidator> = unknown extends TValidator ? TValidator : TValidator extends undefined ? IntersectAllMiddleware<TMiddlewares, 'allInput'> : IntersectAssign<IntersectAllMiddleware<TMiddlewares, 'allInput'>, ResolveValidatorInput<TValidator>>;
40
+ export type IntersectAllMiddleware<TMiddlewares, TType extends keyof AnyFunctionMiddleware['_types'] | keyof AnyRequestMiddleware['_types'], TAcc = undefined> = TMiddlewares extends readonly [infer TMiddleware, ...infer TRest] ? TMiddleware extends AnyFunctionMiddleware | AnyRequestMiddleware ? IntersectAllMiddleware<TRest, TType, IntersectAssign<TAcc, TMiddleware['_types'][TType & keyof TMiddleware['_types']]>> : TAcc : TAcc;
41
+ export type AnyFunctionMiddleware = FunctionMiddlewareWithTypes<any, any, any, any, any, any, any>;
42
+ /**
43
+ * Recursively merge the output type produced by a sequence of middleware
44
+ */
45
+ export type IntersectAllValidatorOutputs<TMiddlewares, TValidator> = unknown extends TValidator ? TValidator : TValidator extends undefined ? IntersectAllMiddleware<TMiddlewares, 'allOutput'> : IntersectAssign<IntersectAllMiddleware<TMiddlewares, 'allOutput'>, ResolveValidatorOutput<TValidator>>;
46
+ /**
47
+ * Recursively resolve the client context type produced by a sequence of middleware
48
+ */
49
+ export type AssignAllClientContextBeforeNext<TMiddlewares, TClientContext = undefined> = unknown extends TClientContext ? TClientContext : Assign<AssignAllMiddleware<TMiddlewares, 'allClientContextBeforeNext'>, TClientContext>;
50
+ export type AssignAllMiddleware<TMiddlewares, TType extends keyof AnyFunctionMiddleware['_types'] | keyof AnyRequestMiddleware['_types'], TAcc = undefined> = TMiddlewares extends readonly [infer TMiddleware, ...infer TRest] ? TMiddleware extends AnyFunctionMiddleware | AnyRequestMiddleware ? AssignAllMiddleware<TRest, TType, Assign<TAcc, TMiddleware['_types'][TType & keyof TMiddleware['_types']]>> : TAcc : TAcc;
51
+ export type AssignAllClientContextAfterNext<TMiddlewares, TClientContext = undefined, TSendContext = undefined> = unknown extends TClientContext ? Assign<TClientContext, TSendContext> : Assign<AssignAllMiddleware<TMiddlewares, 'allClientContextAfterNext'>, Assign<TClientContext, TSendContext>>;
52
+ export type AssignAllServerSendContext<TMiddlewares, TSendContext = undefined> = unknown extends TSendContext ? TSendContext : Assign<AssignAllMiddleware<TMiddlewares, 'allServerSendContext'>, TSendContext>;
53
+ /**
54
+ * Recursively resolve the server context type produced by a sequence of middleware
55
+ */
56
+ export type AssignAllServerContext<TMiddlewares, TSendContext = undefined, TServerContext = undefined> = unknown extends TSendContext ? Assign<TSendContext, TServerContext> : Assign<AssignAllMiddleware<TMiddlewares, 'allServerContext'>, Assign<TSendContext, TServerContext>>;
57
+ export type AssignAllClientSendContext<TMiddlewares, TSendContext = undefined> = unknown extends TSendContext ? TSendContext : Assign<AssignAllMiddleware<TMiddlewares, 'allClientSendContext'>, TSendContext>;
58
+ export interface FunctionMiddlewareOptions<in out TMiddlewares, in out TValidator, in out TServerContext, in out TClientContext, in out TServerFnResponseType extends ServerFnResponseType> {
59
+ validateClient?: boolean;
60
+ middleware?: TMiddlewares;
61
+ validator?: ConstrainValidator<TValidator>;
62
+ client?: FunctionMiddlewareClientFn<TMiddlewares, TValidator, TServerContext, TClientContext, TServerFnResponseType>;
63
+ server?: FunctionMiddlewareServerFn<TMiddlewares, TValidator, TServerContext, unknown, unknown, TServerFnResponseType>;
64
+ }
65
+ export type FunctionMiddlewareClientNextFn<TMiddlewares> = <TSendContext = undefined, TNewClientContext = undefined>(ctx?: {
66
+ context?: TNewClientContext;
67
+ sendContext?: SerializerStringify<TSendContext>;
68
+ headers?: HeadersInit;
69
+ }) => Promise<FunctionClientResultWithContext<TMiddlewares, TSendContext, TNewClientContext>>;
70
+ export interface FunctionMiddlewareServer<TMiddlewares, TValidator, TServerSendContext, TClientContext, TServerFnResponseType extends ServerFnResponseType> {
71
+ server: <TNewServerContext = undefined, TSendContext = undefined>(server: FunctionMiddlewareServerFn<TMiddlewares, TValidator, TServerSendContext, TNewServerContext, TSendContext, TServerFnResponseType>) => FunctionMiddlewareAfterServer<TMiddlewares, TValidator, TNewServerContext, TServerSendContext, TClientContext, TSendContext, ServerFnResponseType>;
72
+ }
73
+ export type FunctionMiddlewareServerFn<TMiddlewares, TValidator, TServerSendContext, TNewServerContext, TSendContext, TServerFnResponseType extends ServerFnResponseType> = (options: FunctionMiddlewareServerFnOptions<TMiddlewares, TValidator, TServerSendContext, TServerFnResponseType>) => FunctionMiddlewareServerFnResult<TMiddlewares, TServerSendContext, TNewServerContext, TSendContext>;
74
+ export interface RequestMiddlewareServerFnOptions<in out TMiddlewares, in out TServerSendContext> {
75
+ request: Request;
76
+ context: Expand<AssignAllServerContext<TMiddlewares, TServerSendContext>>;
77
+ next: FunctionMiddlewareServerNextFn<TMiddlewares, TServerSendContext>;
78
+ response: Response;
79
+ method: Method;
80
+ signal: AbortSignal;
81
+ }
82
+ export type FunctionMiddlewareServerNextFn<TMiddlewares, TServerSendContext> = <TNewServerContext = undefined, TSendContext = undefined>(ctx?: {
83
+ context?: TNewServerContext;
84
+ sendContext?: SerializerStringify<TSendContext>;
85
+ }) => Promise<FunctionServerResultWithContext<TMiddlewares, TServerSendContext, TNewServerContext, TSendContext>>;
86
+ export type FunctionServerResultWithContext<in out TMiddlewares, in out TServerSendContext, in out TServerContext, in out TSendContext> = {
87
+ 'use functions must return the result of next()': true;
88
+ _types: {
89
+ context: TServerContext;
90
+ sendContext: TSendContext;
91
+ };
92
+ context: Expand<AssignAllServerContext<TMiddlewares, TServerSendContext, TServerContext>>;
93
+ sendContext: Expand<AssignAllClientSendContext<TMiddlewares, TSendContext>>;
94
+ };
95
+ export interface FunctionMiddlewareServerFnOptions<in out TMiddlewares, in out TValidator, in out TServerSendContext, in out TServerFnResponseType> {
96
+ data: Expand<IntersectAllValidatorOutputs<TMiddlewares, TValidator>>;
97
+ context: Expand<AssignAllServerContext<TMiddlewares, TServerSendContext>>;
98
+ next: FunctionMiddlewareServerNextFn<TMiddlewares, TServerSendContext>;
99
+ response: TServerFnResponseType;
100
+ method: Method;
101
+ filename: string;
102
+ functionId: string;
103
+ signal: AbortSignal;
104
+ }
105
+ export type FunctionMiddlewareServerFnResult<TMiddlewares, TServerSendContext, TServerContext, TSendContext> = Promise<FunctionServerResultWithContext<TMiddlewares, TServerSendContext, TServerContext, TSendContext>> | FunctionServerResultWithContext<TMiddlewares, TServerSendContext, TServerContext, TSendContext>;
106
+ export interface FunctionMiddlewareAfterServer<TMiddlewares, TValidator, TServerContext, TServerSendContext, TClientContext, TClientSendContext, TServerFnResponseType extends ServerFnResponseType> extends FunctionMiddlewareWithTypes<TMiddlewares, TValidator, TServerContext, TServerSendContext, TClientContext, TClientSendContext, TServerFnResponseType> {
107
+ }
108
+ export interface FunctionMiddlewareClient<TMiddlewares, TValidator, TServerFnResponseType extends ServerFnResponseType> {
109
+ client: <TSendServerContext = undefined, TNewClientContext = undefined>(client: FunctionMiddlewareClientFn<TMiddlewares, TValidator, TSendServerContext, TNewClientContext, TServerFnResponseType>) => FunctionMiddlewareAfterClient<TMiddlewares, TValidator, TSendServerContext, TNewClientContext, ServerFnResponseType>;
110
+ }
111
+ export type FunctionMiddlewareClientFn<TMiddlewares, TValidator, TSendContext, TClientContext, TServerFnResponseType extends ServerFnResponseType> = (options: FunctionMiddlewareClientFnOptions<TMiddlewares, TValidator, TServerFnResponseType>) => FunctionMiddlewareClientFnResult<TMiddlewares, TSendContext, TClientContext>;
112
+ export interface FunctionMiddlewareClientFnOptions<in out TMiddlewares, in out TValidator, in out TServerFnResponseType extends ServerFnResponseType> {
113
+ data: Expand<IntersectAllValidatorInputs<TMiddlewares, TValidator>>;
114
+ context: Expand<AssignAllClientContextBeforeNext<TMiddlewares>>;
115
+ sendContext: Expand<AssignAllServerSendContext<TMiddlewares>>;
116
+ method: Method;
117
+ response: TServerFnResponseType;
118
+ signal: AbortSignal;
119
+ next: FunctionMiddlewareClientNextFn<TMiddlewares>;
120
+ filename: string;
121
+ functionId: string;
122
+ type: ServerFnTypeOrTypeFn<Method, TServerFnResponseType, TMiddlewares, TValidator>;
123
+ }
124
+ export type FunctionMiddlewareClientFnResult<TMiddlewares, TSendContext, TClientContext> = Promise<FunctionClientResultWithContext<TMiddlewares, TSendContext, TClientContext>> | FunctionClientResultWithContext<TMiddlewares, TSendContext, TClientContext>;
125
+ export type FunctionClientResultWithContext<in out TMiddlewares, in out TSendContext, in out TClientContext> = {
126
+ 'use functions must return the result of next()': true;
127
+ context: Expand<AssignAllClientContextAfterNext<TMiddlewares, TClientContext>>;
128
+ sendContext: Expand<AssignAllServerSendContext<TMiddlewares, TSendContext>>;
129
+ headers: HeadersInit;
130
+ };
131
+ export interface FunctionMiddlewareAfterClient<TMiddlewares, TValidator, TServerSendContext, TClientContext, TServerFnResponseType extends ServerFnResponseType> extends FunctionMiddlewareWithTypes<TMiddlewares, TValidator, undefined, TServerSendContext, TClientContext, undefined, TServerFnResponseType>, FunctionMiddlewareServer<TMiddlewares, TValidator, TServerSendContext, TClientContext, TServerFnResponseType> {
132
+ }
133
+ export interface FunctionMiddlewareValidator<TMiddlewares, TServerFnResponseType extends ServerFnResponseType> {
134
+ validator: <TNewValidator>(input: ConstrainValidator<TNewValidator>) => FunctionMiddlewareAfterValidator<TMiddlewares, TNewValidator, TServerFnResponseType>;
135
+ }
136
+ export interface FunctionMiddlewareAfterValidator<TMiddlewares, TValidator, TServerFnResponseType extends ServerFnResponseType> extends FunctionMiddlewareWithTypes<TMiddlewares, TValidator, undefined, undefined, undefined, undefined, ServerFnResponseType>, FunctionMiddlewareServer<TMiddlewares, TValidator, undefined, undefined, TServerFnResponseType>, FunctionMiddlewareClient<TMiddlewares, TValidator, ServerFnResponseType> {
137
+ }
138
+ export interface RequestMiddleware extends RequestMiddlewareAfterMiddleware<undefined> {
139
+ middleware: <const TMiddlewares = undefined>(middlewares: Constrain<TMiddlewares, ReadonlyArray<AnyRequestMiddleware>>) => RequestMiddlewareAfterMiddleware<TMiddlewares>;
140
+ }
141
+ export type AnyRequestMiddleware = RequestMiddlewareWithTypes<any, any>;
142
+ export interface RequestMiddlewareWithTypes<TMiddlewares, TServerContext> {
143
+ _types: RequestMiddlewareTypes<TMiddlewares, TServerContext>;
144
+ }
145
+ export interface RequestMiddlewareTypes<TMiddlewares, TServerContext> {
146
+ type: 'request';
147
+ middlewares: TMiddlewares;
148
+ serverContext: TServerContext;
149
+ allServerContext: AssignAllServerContext<TMiddlewares, undefined, TServerContext>;
150
+ }
151
+ export interface RequestMiddlewareAfterMiddleware<TMiddlewares> extends RequestMiddlewareWithTypes<TMiddlewares, undefined>, RequestMiddlewareServer<TMiddlewares> {
152
+ }
153
+ export interface RequestMiddlewareServer<TMiddlewares> {
154
+ server: <TServerContext = undefined>(fn: RequestServerFn<TMiddlewares, TServerContext>) => RequestMiddlewareAfterServer<TMiddlewares, TServerContext>;
155
+ }
156
+ export type RequestServerFn<TMiddlewares, TServerContext> = (options: RequestServerOptions<TMiddlewares>) => RequestMiddlewareServerFnResult<TMiddlewares, TServerContext>;
157
+ export interface RequestServerOptions<TMiddlewares> {
158
+ request: Request;
159
+ pathname: string;
160
+ context: AssignAllServerContext<TMiddlewares>;
161
+ next: RequestServerNextFn<TMiddlewares>;
162
+ }
163
+ export type RequestServerNextFn<TMiddlewares> = <TServerContext = undefined>(options?: RequestServerNextFnOptions<TServerContext>) => RequestMiddlewareServerFnResult<TMiddlewares, TServerContext>;
164
+ export interface RequestServerNextFnOptions<TServerContext> {
165
+ context?: TServerContext;
166
+ }
167
+ export type RequestMiddlewareServerFnResult<TMiddlewares, TServerContext> = Promise<RequestServerResult<TMiddlewares, TServerContext>> | RequestServerResult<TMiddlewares, TServerContext>;
168
+ export interface RequestServerResult<TMiddlewares, TServerContext> {
169
+ request: Request;
170
+ pathname: string;
171
+ context: Expand<AssignAllServerContext<TMiddlewares, undefined, TServerContext>>;
172
+ response: Response;
173
+ }
174
+ export interface RequestMiddlewareAfterServer<TMiddlewares, TServerContext> extends RequestMiddlewareWithTypes<TMiddlewares, TServerContext> {
175
+ }
@@ -0,0 +1,37 @@
1
+ function createMiddleware(options, __opts) {
2
+ const resolvedOptions = {
3
+ type: "function",
4
+ ...__opts || options
5
+ };
6
+ return {
7
+ options: resolvedOptions,
8
+ middleware: (middleware) => {
9
+ return createMiddleware(
10
+ {},
11
+ Object.assign(resolvedOptions, { middleware })
12
+ );
13
+ },
14
+ validator: (validator) => {
15
+ return createMiddleware(
16
+ {},
17
+ Object.assign(resolvedOptions, { validator })
18
+ );
19
+ },
20
+ client: (client) => {
21
+ return createMiddleware(
22
+ {},
23
+ Object.assign(resolvedOptions, { client })
24
+ );
25
+ },
26
+ server: (server) => {
27
+ return createMiddleware(
28
+ {},
29
+ Object.assign(resolvedOptions, { server })
30
+ );
31
+ }
32
+ };
33
+ }
34
+ export {
35
+ createMiddleware
36
+ };
37
+ //# sourceMappingURL=createMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createMiddleware.js","sources":["../../src/createMiddleware.ts"],"sourcesContent":["import type {\n ConstrainValidator,\n Method,\n ServerFnResponseType,\n ServerFnTypeOrTypeFn,\n} from './createServerFn'\nimport type {\n Assign,\n Constrain,\n Expand,\n IntersectAssign,\n ResolveValidatorInput,\n ResolveValidatorOutput,\n SerializerStringify,\n} from '@tanstack/router-core'\n\nexport function createMiddleware<TType extends MiddlewareType>(\n options: {\n type: TType\n validateClient?: boolean\n },\n __opts?: FunctionMiddlewareOptions<\n unknown,\n undefined,\n undefined,\n undefined,\n ServerFnResponseType\n >,\n): CreateMiddlewareResult<TType> {\n // const resolvedOptions = (__opts || options) as MiddlewareOptions<\n const resolvedOptions = {\n type: 'function',\n ...(__opts ||\n (options as FunctionMiddlewareOptions<\n unknown,\n undefined,\n undefined,\n undefined,\n ServerFnResponseType\n >)),\n }\n\n return {\n options: resolvedOptions,\n middleware: (middleware: any) => {\n return createMiddleware(\n {} as any,\n Object.assign(resolvedOptions, { middleware }),\n ) as any\n },\n validator: (validator: any) => {\n return createMiddleware(\n {} as any,\n Object.assign(resolvedOptions, { validator }),\n ) as any\n },\n client: (client: any) => {\n return createMiddleware(\n {} as any,\n Object.assign(resolvedOptions, { client }),\n ) as any\n },\n server: (server: any) => {\n return createMiddleware(\n {} as any,\n Object.assign(resolvedOptions, { server }),\n ) as any\n },\n } as unknown as CreateMiddlewareResult<TType>\n}\n\nexport type MiddlewareType = 'request' | 'function'\n\nexport type CreateMiddlewareResult<TType extends MiddlewareType> =\n 'function' extends TType\n ? FunctionMiddleware<ServerFnResponseType>\n : RequestMiddleware\n\nexport interface FunctionMiddleware<\n TServerFnResponseType extends ServerFnResponseType,\n> extends FunctionMiddlewareAfterMiddleware<unknown, TServerFnResponseType> {\n middleware: <const TNewMiddlewares = undefined>(\n middlewares: Constrain<\n TNewMiddlewares,\n ReadonlyArray<AnyFunctionMiddleware>\n >,\n ) => FunctionMiddlewareAfterMiddleware<TNewMiddlewares, TServerFnResponseType>\n}\n\nexport interface FunctionMiddlewareAfterMiddleware<\n TMiddlewares,\n TServerFnResponseType extends ServerFnResponseType,\n> extends FunctionMiddlewareWithTypes<\n TMiddlewares,\n undefined,\n undefined,\n undefined,\n undefined,\n undefined,\n TServerFnResponseType\n >,\n FunctionMiddlewareServer<\n TMiddlewares,\n undefined,\n undefined,\n undefined,\n TServerFnResponseType\n >,\n FunctionMiddlewareClient<TMiddlewares, undefined, TServerFnResponseType>,\n FunctionMiddlewareValidator<TMiddlewares, TServerFnResponseType> {}\n\nexport interface FunctionMiddlewareWithTypes<\n TMiddlewares,\n TValidator,\n TServerContext,\n TServerSendContext,\n TClientContext,\n TClientSendContext,\n TServerFnResponseType extends ServerFnResponseType,\n> {\n _types: FunctionMiddlewareTypes<\n TMiddlewares,\n TValidator,\n TServerContext,\n TServerSendContext,\n TClientContext,\n TClientSendContext\n >\n options: FunctionMiddlewareOptions<\n TMiddlewares,\n TValidator,\n TServerContext,\n TClientContext,\n TServerFnResponseType\n >\n}\n\nexport interface FunctionMiddlewareTypes<\n in out TMiddlewares,\n in out TValidator,\n in out TServerContext,\n in out TServerSendContext,\n in out TClientContext,\n in out TClientSendContext,\n> {\n type: 'function'\n middlewares: TMiddlewares\n input: ResolveValidatorInput<TValidator>\n allInput: IntersectAllValidatorInputs<TMiddlewares, TValidator>\n output: ResolveValidatorOutput<TValidator>\n allOutput: IntersectAllValidatorOutputs<TMiddlewares, TValidator>\n clientContext: TClientContext\n allClientContextBeforeNext: AssignAllClientContextBeforeNext<\n TMiddlewares,\n TClientContext\n >\n allClientContextAfterNext: AssignAllClientContextAfterNext<\n TMiddlewares,\n TClientContext,\n TClientSendContext\n >\n serverContext: TServerContext\n serverSendContext: TServerSendContext\n allServerSendContext: AssignAllServerSendContext<\n TMiddlewares,\n TServerSendContext\n >\n allServerContext: AssignAllServerContext<\n TMiddlewares,\n TServerSendContext,\n TServerContext\n >\n clientSendContext: TClientSendContext\n allClientSendContext: AssignAllClientSendContext<\n TMiddlewares,\n TClientSendContext\n >\n validator: TValidator\n}\n\n/**\n * Recursively resolve the input type produced by a sequence of middleware\n */\nexport type IntersectAllValidatorInputs<TMiddlewares, TValidator> =\n unknown extends TValidator\n ? TValidator\n : TValidator extends undefined\n ? IntersectAllMiddleware<TMiddlewares, 'allInput'>\n : IntersectAssign<\n IntersectAllMiddleware<TMiddlewares, 'allInput'>,\n ResolveValidatorInput<TValidator>\n >\n\nexport type IntersectAllMiddleware<\n TMiddlewares,\n TType extends\n | keyof AnyFunctionMiddleware['_types']\n | keyof AnyRequestMiddleware['_types'],\n TAcc = undefined,\n> = TMiddlewares extends readonly [infer TMiddleware, ...infer TRest]\n ? TMiddleware extends AnyFunctionMiddleware | AnyRequestMiddleware\n ? IntersectAllMiddleware<\n TRest,\n TType,\n IntersectAssign<\n TAcc,\n TMiddleware['_types'][TType & keyof TMiddleware['_types']]\n >\n >\n : TAcc\n : TAcc\n\nexport type AnyFunctionMiddleware = FunctionMiddlewareWithTypes<\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>\n\n/**\n * Recursively merge the output type produced by a sequence of middleware\n */\nexport type IntersectAllValidatorOutputs<TMiddlewares, TValidator> =\n unknown extends TValidator\n ? TValidator\n : TValidator extends undefined\n ? IntersectAllMiddleware<TMiddlewares, 'allOutput'>\n : IntersectAssign<\n IntersectAllMiddleware<TMiddlewares, 'allOutput'>,\n ResolveValidatorOutput<TValidator>\n >\n\n/**\n * Recursively resolve the client context type produced by a sequence of middleware\n */\nexport type AssignAllClientContextBeforeNext<\n TMiddlewares,\n TClientContext = undefined,\n> = unknown extends TClientContext\n ? TClientContext\n : Assign<\n AssignAllMiddleware<TMiddlewares, 'allClientContextBeforeNext'>,\n TClientContext\n >\n\nexport type AssignAllMiddleware<\n TMiddlewares,\n TType extends\n | keyof AnyFunctionMiddleware['_types']\n | keyof AnyRequestMiddleware['_types'],\n TAcc = undefined,\n> = TMiddlewares extends readonly [infer TMiddleware, ...infer TRest]\n ? TMiddleware extends AnyFunctionMiddleware | AnyRequestMiddleware\n ? AssignAllMiddleware<\n TRest,\n TType,\n Assign<TAcc, TMiddleware['_types'][TType & keyof TMiddleware['_types']]>\n >\n : TAcc\n : TAcc\n\nexport type AssignAllClientContextAfterNext<\n TMiddlewares,\n TClientContext = undefined,\n TSendContext = undefined,\n> = unknown extends TClientContext\n ? Assign<TClientContext, TSendContext>\n : Assign<\n AssignAllMiddleware<TMiddlewares, 'allClientContextAfterNext'>,\n Assign<TClientContext, TSendContext>\n >\n\nexport type AssignAllServerSendContext<\n TMiddlewares,\n TSendContext = undefined,\n> = unknown extends TSendContext\n ? TSendContext\n : Assign<\n AssignAllMiddleware<TMiddlewares, 'allServerSendContext'>,\n TSendContext\n >\n\n/**\n * Recursively resolve the server context type produced by a sequence of middleware\n */\nexport type AssignAllServerContext<\n TMiddlewares,\n TSendContext = undefined,\n TServerContext = undefined,\n> = unknown extends TSendContext\n ? Assign<TSendContext, TServerContext>\n : Assign<\n AssignAllMiddleware<TMiddlewares, 'allServerContext'>,\n Assign<TSendContext, TServerContext>\n >\n\nexport type AssignAllClientSendContext<\n TMiddlewares,\n TSendContext = undefined,\n> = unknown extends TSendContext\n ? TSendContext\n : Assign<\n AssignAllMiddleware<TMiddlewares, 'allClientSendContext'>,\n TSendContext\n >\n\nexport interface FunctionMiddlewareOptions<\n in out TMiddlewares,\n in out TValidator,\n in out TServerContext,\n in out TClientContext,\n in out TServerFnResponseType extends ServerFnResponseType,\n> {\n validateClient?: boolean\n middleware?: TMiddlewares\n validator?: ConstrainValidator<TValidator>\n client?: FunctionMiddlewareClientFn<\n TMiddlewares,\n TValidator,\n TServerContext,\n TClientContext,\n TServerFnResponseType\n >\n server?: FunctionMiddlewareServerFn<\n TMiddlewares,\n TValidator,\n TServerContext,\n unknown,\n unknown,\n TServerFnResponseType\n >\n}\n\nexport type FunctionMiddlewareClientNextFn<TMiddlewares> = <\n TSendContext = undefined,\n TNewClientContext = undefined,\n>(ctx?: {\n context?: TNewClientContext\n sendContext?: SerializerStringify<TSendContext>\n headers?: HeadersInit\n}) => Promise<\n FunctionClientResultWithContext<TMiddlewares, TSendContext, TNewClientContext>\n>\n\nexport interface FunctionMiddlewareServer<\n TMiddlewares,\n TValidator,\n TServerSendContext,\n TClientContext,\n TServerFnResponseType extends ServerFnResponseType,\n> {\n server: <TNewServerContext = undefined, TSendContext = undefined>(\n server: FunctionMiddlewareServerFn<\n TMiddlewares,\n TValidator,\n TServerSendContext,\n TNewServerContext,\n TSendContext,\n TServerFnResponseType\n >,\n ) => FunctionMiddlewareAfterServer<\n TMiddlewares,\n TValidator,\n TNewServerContext,\n TServerSendContext,\n TClientContext,\n TSendContext,\n ServerFnResponseType\n >\n}\nexport type FunctionMiddlewareServerFn<\n TMiddlewares,\n TValidator,\n TServerSendContext,\n TNewServerContext,\n TSendContext,\n TServerFnResponseType extends ServerFnResponseType,\n> = (\n options: FunctionMiddlewareServerFnOptions<\n TMiddlewares,\n TValidator,\n TServerSendContext,\n TServerFnResponseType\n >,\n) => FunctionMiddlewareServerFnResult<\n TMiddlewares,\n TServerSendContext,\n TNewServerContext,\n TSendContext\n>\n\nexport interface RequestMiddlewareServerFnOptions<\n in out TMiddlewares,\n in out TServerSendContext,\n> {\n request: Request\n context: Expand<AssignAllServerContext<TMiddlewares, TServerSendContext>>\n next: FunctionMiddlewareServerNextFn<TMiddlewares, TServerSendContext>\n response: Response\n method: Method\n signal: AbortSignal\n}\n\nexport type FunctionMiddlewareServerNextFn<TMiddlewares, TServerSendContext> = <\n TNewServerContext = undefined,\n TSendContext = undefined,\n>(ctx?: {\n context?: TNewServerContext\n sendContext?: SerializerStringify<TSendContext>\n}) => Promise<\n FunctionServerResultWithContext<\n TMiddlewares,\n TServerSendContext,\n TNewServerContext,\n TSendContext\n >\n>\n\nexport type FunctionServerResultWithContext<\n in out TMiddlewares,\n in out TServerSendContext,\n in out TServerContext,\n in out TSendContext,\n> = {\n 'use functions must return the result of next()': true\n _types: {\n context: TServerContext\n sendContext: TSendContext\n }\n context: Expand<\n AssignAllServerContext<TMiddlewares, TServerSendContext, TServerContext>\n >\n sendContext: Expand<AssignAllClientSendContext<TMiddlewares, TSendContext>>\n}\n\nexport interface FunctionMiddlewareServerFnOptions<\n in out TMiddlewares,\n in out TValidator,\n in out TServerSendContext,\n in out TServerFnResponseType,\n> {\n data: Expand<IntersectAllValidatorOutputs<TMiddlewares, TValidator>>\n context: Expand<AssignAllServerContext<TMiddlewares, TServerSendContext>>\n next: FunctionMiddlewareServerNextFn<TMiddlewares, TServerSendContext>\n response: TServerFnResponseType\n method: Method\n filename: string\n functionId: string\n signal: AbortSignal\n}\n\nexport type FunctionMiddlewareServerFnResult<\n TMiddlewares,\n TServerSendContext,\n TServerContext,\n TSendContext,\n> =\n | Promise<\n FunctionServerResultWithContext<\n TMiddlewares,\n TServerSendContext,\n TServerContext,\n TSendContext\n >\n >\n | FunctionServerResultWithContext<\n TMiddlewares,\n TServerSendContext,\n TServerContext,\n TSendContext\n >\n\nexport interface FunctionMiddlewareAfterServer<\n TMiddlewares,\n TValidator,\n TServerContext,\n TServerSendContext,\n TClientContext,\n TClientSendContext,\n TServerFnResponseType extends ServerFnResponseType,\n> extends FunctionMiddlewareWithTypes<\n TMiddlewares,\n TValidator,\n TServerContext,\n TServerSendContext,\n TClientContext,\n TClientSendContext,\n TServerFnResponseType\n > {}\n\nexport interface FunctionMiddlewareClient<\n TMiddlewares,\n TValidator,\n TServerFnResponseType extends ServerFnResponseType,\n> {\n client: <TSendServerContext = undefined, TNewClientContext = undefined>(\n client: FunctionMiddlewareClientFn<\n TMiddlewares,\n TValidator,\n TSendServerContext,\n TNewClientContext,\n TServerFnResponseType\n >,\n ) => FunctionMiddlewareAfterClient<\n TMiddlewares,\n TValidator,\n TSendServerContext,\n TNewClientContext,\n ServerFnResponseType\n >\n}\n\nexport type FunctionMiddlewareClientFn<\n TMiddlewares,\n TValidator,\n TSendContext,\n TClientContext,\n TServerFnResponseType extends ServerFnResponseType,\n> = (\n options: FunctionMiddlewareClientFnOptions<\n TMiddlewares,\n TValidator,\n TServerFnResponseType\n >,\n) => FunctionMiddlewareClientFnResult<\n TMiddlewares,\n TSendContext,\n TClientContext\n>\n\nexport interface FunctionMiddlewareClientFnOptions<\n in out TMiddlewares,\n in out TValidator,\n in out TServerFnResponseType extends ServerFnResponseType,\n> {\n data: Expand<IntersectAllValidatorInputs<TMiddlewares, TValidator>>\n context: Expand<AssignAllClientContextBeforeNext<TMiddlewares>>\n sendContext: Expand<AssignAllServerSendContext<TMiddlewares>>\n method: Method\n response: TServerFnResponseType\n signal: AbortSignal\n next: FunctionMiddlewareClientNextFn<TMiddlewares>\n filename: string\n functionId: string\n type: ServerFnTypeOrTypeFn<\n Method,\n TServerFnResponseType,\n TMiddlewares,\n TValidator\n >\n}\n\nexport type FunctionMiddlewareClientFnResult<\n TMiddlewares,\n TSendContext,\n TClientContext,\n> =\n | Promise<\n FunctionClientResultWithContext<\n TMiddlewares,\n TSendContext,\n TClientContext\n >\n >\n | FunctionClientResultWithContext<TMiddlewares, TSendContext, TClientContext>\n\nexport type FunctionClientResultWithContext<\n in out TMiddlewares,\n in out TSendContext,\n in out TClientContext,\n> = {\n 'use functions must return the result of next()': true\n context: Expand<AssignAllClientContextAfterNext<TMiddlewares, TClientContext>>\n sendContext: Expand<AssignAllServerSendContext<TMiddlewares, TSendContext>>\n headers: HeadersInit\n}\n\nexport interface FunctionMiddlewareAfterClient<\n TMiddlewares,\n TValidator,\n TServerSendContext,\n TClientContext,\n TServerFnResponseType extends ServerFnResponseType,\n> extends FunctionMiddlewareWithTypes<\n TMiddlewares,\n TValidator,\n undefined,\n TServerSendContext,\n TClientContext,\n undefined,\n TServerFnResponseType\n >,\n FunctionMiddlewareServer<\n TMiddlewares,\n TValidator,\n TServerSendContext,\n TClientContext,\n TServerFnResponseType\n > {}\n\nexport interface FunctionMiddlewareValidator<\n TMiddlewares,\n TServerFnResponseType extends ServerFnResponseType,\n> {\n validator: <TNewValidator>(\n input: ConstrainValidator<TNewValidator>,\n ) => FunctionMiddlewareAfterValidator<\n TMiddlewares,\n TNewValidator,\n TServerFnResponseType\n >\n}\n\nexport interface FunctionMiddlewareAfterValidator<\n TMiddlewares,\n TValidator,\n TServerFnResponseType extends ServerFnResponseType,\n> extends FunctionMiddlewareWithTypes<\n TMiddlewares,\n TValidator,\n undefined,\n undefined,\n undefined,\n undefined,\n ServerFnResponseType\n >,\n FunctionMiddlewareServer<\n TMiddlewares,\n TValidator,\n undefined,\n undefined,\n TServerFnResponseType\n >,\n FunctionMiddlewareClient<TMiddlewares, TValidator, ServerFnResponseType> {}\n\nexport interface RequestMiddleware\n extends RequestMiddlewareAfterMiddleware<undefined> {\n middleware: <const TMiddlewares = undefined>(\n middlewares: Constrain<TMiddlewares, ReadonlyArray<AnyRequestMiddleware>>,\n ) => RequestMiddlewareAfterMiddleware<TMiddlewares>\n}\n\nexport type AnyRequestMiddleware = RequestMiddlewareWithTypes<any, any>\n\nexport interface RequestMiddlewareWithTypes<TMiddlewares, TServerContext> {\n _types: RequestMiddlewareTypes<TMiddlewares, TServerContext>\n}\n\nexport interface RequestMiddlewareTypes<TMiddlewares, TServerContext> {\n type: 'request'\n middlewares: TMiddlewares\n serverContext: TServerContext\n allServerContext: AssignAllServerContext<\n TMiddlewares,\n undefined,\n TServerContext\n >\n}\n\nexport interface RequestMiddlewareAfterMiddleware<TMiddlewares>\n extends RequestMiddlewareWithTypes<TMiddlewares, undefined>,\n RequestMiddlewareServer<TMiddlewares> {}\n\nexport interface RequestMiddlewareServer<TMiddlewares> {\n server: <TServerContext = undefined>(\n fn: RequestServerFn<TMiddlewares, TServerContext>,\n ) => RequestMiddlewareAfterServer<TMiddlewares, TServerContext>\n}\n\nexport type RequestServerFn<TMiddlewares, TServerContext> = (\n options: RequestServerOptions<TMiddlewares>,\n) => RequestMiddlewareServerFnResult<TMiddlewares, TServerContext>\n\nexport interface RequestServerOptions<TMiddlewares> {\n request: Request\n pathname: string\n context: AssignAllServerContext<TMiddlewares>\n next: RequestServerNextFn<TMiddlewares>\n}\n\nexport type RequestServerNextFn<TMiddlewares> = <TServerContext = undefined>(\n options?: RequestServerNextFnOptions<TServerContext>,\n) => RequestMiddlewareServerFnResult<TMiddlewares, TServerContext>\n\nexport interface RequestServerNextFnOptions<TServerContext> {\n context?: TServerContext\n}\n\nexport type RequestMiddlewareServerFnResult<TMiddlewares, TServerContext> =\n | Promise<RequestServerResult<TMiddlewares, TServerContext>>\n | RequestServerResult<TMiddlewares, TServerContext>\n\nexport interface RequestServerResult<TMiddlewares, TServerContext> {\n request: Request\n pathname: string\n context: Expand<\n AssignAllServerContext<TMiddlewares, undefined, TServerContext>\n >\n response: Response\n}\n\nexport interface RequestMiddlewareAfterServer<TMiddlewares, TServerContext>\n extends RequestMiddlewareWithTypes<TMiddlewares, TServerContext> {}\n"],"names":[],"mappings":"AAgBgB,SAAA,iBACd,SAIA,QAO+B;AAE/B,QAAM,kBAAkB;AAAA,IACtB,MAAM;AAAA,IACN,GAAI,UACD;AAAA,EAOL;AAEO,SAAA;AAAA,IACL,SAAS;AAAA,IACT,YAAY,CAAC,eAAoB;AACxB,aAAA;AAAA,QACL,CAAC;AAAA,QACD,OAAO,OAAO,iBAAiB,EAAE,WAAY,CAAA;AAAA,MAC/C;AAAA,IACF;AAAA,IACA,WAAW,CAAC,cAAmB;AACtB,aAAA;AAAA,QACL,CAAC;AAAA,QACD,OAAO,OAAO,iBAAiB,EAAE,UAAW,CAAA;AAAA,MAC9C;AAAA,IACF;AAAA,IACA,QAAQ,CAAC,WAAgB;AAChB,aAAA;AAAA,QACL,CAAC;AAAA,QACD,OAAO,OAAO,iBAAiB,EAAE,OAAQ,CAAA;AAAA,MAC3C;AAAA,IACF;AAAA,IACA,QAAQ,CAAC,WAAgB;AAChB,aAAA;AAAA,QACL,CAAC;AAAA,QACD,OAAO,OAAO,iBAAiB,EAAE,OAAQ,CAAA;AAAA,MAC3C;AAAA,IAAA;AAAA,EAEJ;AACF;"}
@@ -0,0 +1,159 @@
1
+ import { AnyValidator, Constrain, Expand, ResolveValidatorInput, SerializerParse, SerializerStringify, SerializerStringifyBy, Validator } from '@tanstack/router-core';
2
+ import { Readable } from 'node:stream';
3
+ import { AnyFunctionMiddleware, AssignAllClientSendContext, AssignAllServerContext, IntersectAllValidatorInputs, IntersectAllValidatorOutputs } from './createMiddleware.js';
4
+ export declare function createServerFn<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType = 'data', TResponse = unknown, TMiddlewares = undefined, TValidator = undefined>(options?: {
5
+ method?: TMethod;
6
+ response?: TServerFnResponseType;
7
+ type?: ServerFnType;
8
+ }, __opts?: ServerFnBaseOptions<TMethod, TServerFnResponseType, TResponse, TMiddlewares, TValidator>): ServerFnBuilder<TMethod, TServerFnResponseType>;
9
+ export declare function executeMiddleware(middlewares: Array<AnyFunctionMiddleware>, env: 'client' | 'server', opts: ServerFnMiddlewareOptions): Promise<ServerFnMiddlewareResult>;
10
+ export interface JsonResponse<TData> extends Response {
11
+ json: () => Promise<TData>;
12
+ }
13
+ export type CompiledFetcherFnOptions = {
14
+ method: Method;
15
+ data: unknown;
16
+ response?: ServerFnResponseType;
17
+ headers?: HeadersInit;
18
+ signal?: AbortSignal;
19
+ context?: any;
20
+ };
21
+ export type Fetcher<TMiddlewares, TValidator, TResponse, TServerFnResponseType extends ServerFnResponseType> = undefined extends IntersectAllValidatorInputs<TMiddlewares, TValidator> ? OptionalFetcher<TMiddlewares, TValidator, TResponse, TServerFnResponseType> : RequiredFetcher<TMiddlewares, TValidator, TResponse, TServerFnResponseType>;
22
+ export interface FetcherBase {
23
+ url: string;
24
+ __executeServer: (opts: {
25
+ method: Method;
26
+ response?: ServerFnResponseType;
27
+ data: unknown;
28
+ headers?: HeadersInit;
29
+ context?: any;
30
+ signal: AbortSignal;
31
+ }) => Promise<unknown>;
32
+ }
33
+ export type FetchResult<TMiddlewares, TResponse, TServerFnResponseType extends ServerFnResponseType> = TServerFnResponseType extends 'raw' ? Promise<Response> : TServerFnResponseType extends 'full' ? Promise<FullFetcherData<TMiddlewares, TResponse>> : Promise<FetcherData<TResponse>>;
34
+ export interface OptionalFetcher<TMiddlewares, TValidator, TResponse, TServerFnResponseType extends ServerFnResponseType> extends FetcherBase {
35
+ (options?: OptionalFetcherDataOptions<TMiddlewares, TValidator>): FetchResult<TMiddlewares, TResponse, TServerFnResponseType>;
36
+ }
37
+ export interface RequiredFetcher<TMiddlewares, TValidator, TResponse, TServerFnResponseType extends ServerFnResponseType> extends FetcherBase {
38
+ (opts: RequiredFetcherDataOptions<TMiddlewares, TValidator>): FetchResult<TMiddlewares, TResponse, TServerFnResponseType>;
39
+ }
40
+ export type FetcherBaseOptions = {
41
+ headers?: HeadersInit;
42
+ type?: ServerFnType;
43
+ signal?: AbortSignal;
44
+ };
45
+ export type ServerFnType = 'static' | 'dynamic';
46
+ export interface OptionalFetcherDataOptions<TMiddlewares, TValidator> extends FetcherBaseOptions {
47
+ data?: Expand<IntersectAllValidatorInputs<TMiddlewares, TValidator>>;
48
+ }
49
+ export interface RequiredFetcherDataOptions<TMiddlewares, TValidator> extends FetcherBaseOptions {
50
+ data: Expand<IntersectAllValidatorInputs<TMiddlewares, TValidator>>;
51
+ }
52
+ export interface FullFetcherData<TMiddlewares, TResponse> {
53
+ error: unknown;
54
+ result: FetcherData<TResponse>;
55
+ context: AssignAllClientSendContext<TMiddlewares>;
56
+ }
57
+ export type FetcherData<TResponse> = TResponse extends JsonResponse<any> ? SerializerParse<ReturnType<TResponse['json']>> : SerializerParse<TResponse>;
58
+ export type RscStream<T> = {
59
+ __cacheState: T;
60
+ };
61
+ export type Method = 'GET' | 'POST';
62
+ export type ServerFnResponseType = 'data' | 'full' | 'raw';
63
+ export type RawResponse = Response | ReadableStream | Readable | null | string;
64
+ export type ServerFnReturnType<TServerFnResponseType extends ServerFnResponseType, TResponse> = TServerFnResponseType extends 'raw' ? RawResponse | Promise<RawResponse> : Promise<SerializerStringify<TResponse>> | SerializerStringify<TResponse>;
65
+ export type ServerFn<TMethod, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator, TResponse> = (ctx: ServerFnCtx<TMethod, TServerFnResponseType, TMiddlewares, TValidator>) => ServerFnReturnType<TServerFnResponseType, TResponse>;
66
+ export interface ServerFnCtx<TMethod, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> {
67
+ method: TMethod;
68
+ response: TServerFnResponseType;
69
+ data: Expand<IntersectAllValidatorOutputs<TMiddlewares, TValidator>>;
70
+ context: Expand<AssignAllServerContext<TMiddlewares>>;
71
+ signal: AbortSignal;
72
+ }
73
+ export type CompiledFetcherFn<TResponse, TServerFnResponseType extends ServerFnResponseType> = {
74
+ (opts: CompiledFetcherFnOptions & ServerFnBaseOptions<Method, TServerFnResponseType>): Promise<TResponse>;
75
+ url: string;
76
+ };
77
+ export type ServerFnBaseOptions<TMethod extends Method = 'GET', TServerFnResponseType extends ServerFnResponseType = 'data', TResponse = unknown, TMiddlewares = unknown, TInput = unknown> = {
78
+ method: TMethod;
79
+ response?: TServerFnResponseType;
80
+ validateClient?: boolean;
81
+ middleware?: Constrain<TMiddlewares, ReadonlyArray<AnyFunctionMiddleware>>;
82
+ validator?: ConstrainValidator<TInput>;
83
+ extractedFn?: CompiledFetcherFn<TResponse, TServerFnResponseType>;
84
+ serverFn?: ServerFn<TMethod, TServerFnResponseType, TMiddlewares, TInput, TResponse>;
85
+ functionId: string;
86
+ type: ServerFnTypeOrTypeFn<TMethod, TServerFnResponseType, TMiddlewares, AnyValidator>;
87
+ };
88
+ export type ValidatorInputStringify<TValidator> = SerializerStringifyBy<ResolveValidatorInput<TValidator>, Date | undefined | FormData>;
89
+ export type ValidatorSerializerStringify<TValidator> = ValidatorInputStringify<TValidator> extends infer TInput ? Validator<TInput, any> : never;
90
+ export type ConstrainValidator<TValidator> = (unknown extends TValidator ? TValidator : ResolveValidatorInput<TValidator> extends ValidatorInputStringify<TValidator> ? TValidator : never) | ValidatorSerializerStringify<TValidator>;
91
+ export interface ServerFnMiddleware<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TValidator> {
92
+ middleware: <const TNewMiddlewares = undefined>(middlewares: Constrain<TNewMiddlewares, ReadonlyArray<AnyFunctionMiddleware>>) => ServerFnAfterMiddleware<TMethod, TServerFnResponseType, TNewMiddlewares, TValidator>;
93
+ }
94
+ export interface ServerFnAfterMiddleware<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> extends ServerFnValidator<TMethod, TServerFnResponseType, TMiddlewares>, ServerFnTyper<TMethod, TServerFnResponseType, TMiddlewares, TValidator>, ServerFnHandler<TMethod, TServerFnResponseType, TMiddlewares, TValidator> {
95
+ }
96
+ export type ValidatorFn<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares> = <TValidator>(validator: ConstrainValidator<TValidator>) => ServerFnAfterValidator<TMethod, TServerFnResponseType, TMiddlewares, TValidator>;
97
+ export interface ServerFnValidator<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares> {
98
+ validator: ValidatorFn<TMethod, TServerFnResponseType, TMiddlewares>;
99
+ }
100
+ export interface ServerFnAfterValidator<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> extends ServerFnMiddleware<TMethod, TServerFnResponseType, TValidator>, ServerFnTyper<TMethod, TServerFnResponseType, TMiddlewares, TValidator>, ServerFnHandler<TMethod, TServerFnResponseType, TMiddlewares, TValidator> {
101
+ }
102
+ export interface ServerFnTyper<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> {
103
+ type: (typer: ServerFnTypeOrTypeFn<TMethod, TServerFnResponseType, TMiddlewares, TValidator>) => ServerFnAfterTyper<TMethod, TServerFnResponseType, TMiddlewares, TValidator>;
104
+ }
105
+ export type ServerFnTypeOrTypeFn<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> = ServerFnType | ((ctx: ServerFnCtx<TMethod, TServerFnResponseType, TMiddlewares, TValidator>) => ServerFnType);
106
+ export interface ServerFnAfterTyper<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> extends ServerFnHandler<TMethod, TServerFnResponseType, TMiddlewares, TValidator> {
107
+ }
108
+ export interface ServerFnHandler<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> {
109
+ handler: <TNewResponse>(fn?: ServerFn<TMethod, TServerFnResponseType, TMiddlewares, TValidator, TNewResponse>) => Fetcher<TMiddlewares, TValidator, TNewResponse, TServerFnResponseType>;
110
+ }
111
+ export interface ServerFnBuilder<TMethod extends Method = 'GET', TServerFnResponseType extends ServerFnResponseType = 'data'> extends ServerFnMiddleware<TMethod, TServerFnResponseType, undefined>, ServerFnValidator<TMethod, TServerFnResponseType, undefined>, ServerFnTyper<TMethod, TServerFnResponseType, undefined, undefined>, ServerFnHandler<TMethod, TServerFnResponseType, undefined, undefined> {
112
+ options: ServerFnBaseOptions<TMethod, TServerFnResponseType, unknown, undefined, undefined>;
113
+ }
114
+ export type StaticCachedResult = {
115
+ ctx?: {
116
+ result: any;
117
+ context: any;
118
+ };
119
+ error?: any;
120
+ };
121
+ export type ServerFnStaticCache = {
122
+ getItem: (ctx: ServerFnMiddlewareResult) => StaticCachedResult | Promise<StaticCachedResult | undefined>;
123
+ setItem: (ctx: ServerFnMiddlewareResult, response: StaticCachedResult) => Promise<void>;
124
+ fetchItem: (ctx: ServerFnMiddlewareResult) => StaticCachedResult | Promise<StaticCachedResult | undefined>;
125
+ };
126
+ export declare let serverFnStaticCache: ServerFnStaticCache | undefined;
127
+ export declare function setServerFnStaticCache(cache?: ServerFnStaticCache | (() => ServerFnStaticCache | undefined)): () => void;
128
+ export declare function createServerFnStaticCache(serverFnStaticCache: ServerFnStaticCache): ServerFnStaticCache;
129
+ export declare function extractFormDataContext(formData: FormData): {
130
+ context: unknown;
131
+ data: FormData;
132
+ } | {
133
+ data: FormData;
134
+ context?: undefined;
135
+ };
136
+ export declare function flattenMiddlewares(middlewares: Array<AnyFunctionMiddleware>): Array<AnyFunctionMiddleware>;
137
+ export type ServerFnMiddlewareOptions = {
138
+ method: Method;
139
+ response?: ServerFnResponseType;
140
+ data: any;
141
+ headers?: HeadersInit;
142
+ signal?: AbortSignal;
143
+ sendContext?: any;
144
+ context?: any;
145
+ type: ServerFnTypeOrTypeFn<any, any, any, any>;
146
+ functionId: string;
147
+ };
148
+ export type ServerFnMiddlewareResult = ServerFnMiddlewareOptions & {
149
+ result?: unknown;
150
+ error?: unknown;
151
+ type: ServerFnTypeOrTypeFn<any, any, any, any>;
152
+ };
153
+ export type NextFn = (ctx: ServerFnMiddlewareResult) => Promise<ServerFnMiddlewareResult>;
154
+ export type MiddlewareFn = (ctx: ServerFnMiddlewareOptions & {
155
+ next: NextFn;
156
+ }) => Promise<ServerFnMiddlewareResult>;
157
+ export declare const applyMiddleware: (middlewareFn: MiddlewareFn, ctx: ServerFnMiddlewareOptions, nextFn: NextFn) => Promise<ServerFnMiddlewareResult>;
158
+ export declare function execValidator(validator: AnyValidator, input: unknown): unknown;
159
+ export declare function serverFnBaseToMiddleware(options: ServerFnBaseOptions<any, any, any, any, any>): AnyFunctionMiddleware;