@tanstack/start-client-core 1.132.0-alpha.7 → 1.132.0-alpha.9

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.
@@ -1,20 +1,19 @@
1
1
  import { ConstrainValidator, Method, ServerFnResponseType } from './createServerFn.js';
2
- import { AnyRouter, Assign, Constrain, Expand, IntersectAssign, RegisteredRouter, ResolveValidatorInput, ResolveValidatorOutput } from '@tanstack/router-core';
3
- import { SerializerStringify } from './serializer.js';
4
- export declare function createMiddleware<TType extends MiddlewareType>(options: {
2
+ import { AnyRouter, Assign, Constrain, Expand, IntersectAssign, Register, RegisteredRouter, ResolveValidatorInput, ResolveValidatorOutput, ValidateSerializableInput } from '@tanstack/router-core';
3
+ export declare function createMiddleware<TRegister extends Register, TType extends MiddlewareType>(options: {
5
4
  type: TType;
6
5
  validateClient?: boolean;
7
- }, __opts?: FunctionMiddlewareOptions<unknown, undefined, undefined, undefined, ServerFnResponseType>): CreateMiddlewareResult<TType>;
6
+ }, __opts?: FunctionMiddlewareOptions<TRegister, unknown, undefined, undefined, undefined, ServerFnResponseType>): CreateMiddlewareResult<TRegister, TType>;
8
7
  export type MiddlewareType = 'request' | 'function';
9
- export type CreateMiddlewareResult<TType extends MiddlewareType> = 'function' extends TType ? FunctionMiddleware<ServerFnResponseType> : RequestMiddleware;
10
- export interface FunctionMiddleware<TServerFnResponseType extends ServerFnResponseType> extends FunctionMiddlewareAfterMiddleware<unknown, TServerFnResponseType> {
11
- middleware: <const TNewMiddlewares = undefined>(middlewares: Constrain<TNewMiddlewares, ReadonlyArray<AnyFunctionMiddleware>>) => FunctionMiddlewareAfterMiddleware<TNewMiddlewares, TServerFnResponseType>;
8
+ export type CreateMiddlewareResult<TRegister extends Register, TType extends MiddlewareType> = 'function' extends TType ? FunctionMiddleware<TRegister, ServerFnResponseType> : RequestMiddleware;
9
+ export interface FunctionMiddleware<TRegister extends Register, TServerFnResponseType extends ServerFnResponseType> extends FunctionMiddlewareAfterMiddleware<TRegister, unknown, TServerFnResponseType> {
10
+ middleware: <const TNewMiddlewares = undefined>(middlewares: Constrain<TNewMiddlewares, ReadonlyArray<AnyFunctionMiddleware>>) => FunctionMiddlewareAfterMiddleware<TRegister, TNewMiddlewares, TServerFnResponseType>;
12
11
  }
13
- 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> {
12
+ export interface FunctionMiddlewareAfterMiddleware<TRegister extends Register, TMiddlewares, TServerFnResponseType extends ServerFnResponseType> extends FunctionMiddlewareWithTypes<TRegister, TMiddlewares, undefined, undefined, undefined, undefined, undefined, TServerFnResponseType>, FunctionMiddlewareServer<TRegister, TMiddlewares, undefined, undefined, undefined, TServerFnResponseType>, FunctionMiddlewareClient<TRegister, TMiddlewares, undefined, TServerFnResponseType>, FunctionMiddlewareValidator<TRegister, TMiddlewares, TServerFnResponseType> {
14
13
  }
15
- export interface FunctionMiddlewareWithTypes<TMiddlewares, TValidator, TServerContext, TServerSendContext, TClientContext, TClientSendContext, TServerFnResponseType extends ServerFnResponseType> {
14
+ export interface FunctionMiddlewareWithTypes<TRegister extends Register, TMiddlewares, TValidator, TServerContext, TServerSendContext, TClientContext, TClientSendContext, TServerFnResponseType extends ServerFnResponseType> {
16
15
  _types: FunctionMiddlewareTypes<TMiddlewares, TValidator, TServerContext, TServerSendContext, TClientContext, TClientSendContext>;
17
- options: FunctionMiddlewareOptions<TMiddlewares, TValidator, TServerContext, TClientContext, TServerFnResponseType>;
16
+ options: FunctionMiddlewareOptions<TRegister, TMiddlewares, TValidator, TServerContext, TClientContext, TServerFnResponseType>;
18
17
  }
19
18
  export interface FunctionMiddlewareTypes<in out TMiddlewares, in out TValidator, in out TServerContext, in out TServerSendContext, in out TClientContext, in out TClientSendContext> {
20
19
  type: 'function';
@@ -39,7 +38,7 @@ export interface FunctionMiddlewareTypes<in out TMiddlewares, in out TValidator,
39
38
  */
40
39
  export type IntersectAllValidatorInputs<TMiddlewares, TValidator> = unknown extends TValidator ? TValidator : TValidator extends undefined ? IntersectAllMiddleware<TMiddlewares, 'allInput'> : IntersectAssign<IntersectAllMiddleware<TMiddlewares, 'allInput'>, ResolveValidatorInput<TValidator>>;
41
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;
42
- export type AnyFunctionMiddleware = FunctionMiddlewareWithTypes<any, any, any, any, any, any, any>;
41
+ export type AnyFunctionMiddleware = FunctionMiddlewareWithTypes<any, any, any, any, any, any, any, any>;
43
42
  /**
44
43
  * Recursively merge the output type produced by a sequence of middleware
45
44
  */
@@ -56,33 +55,33 @@ export type AssignAllServerSendContext<TMiddlewares, TSendContext = undefined> =
56
55
  */
57
56
  export type AssignAllServerContext<TMiddlewares, TSendContext = undefined, TServerContext = undefined> = unknown extends TSendContext ? Assign<TSendContext, TServerContext> : Assign<AssignAllMiddleware<TMiddlewares, 'allServerContext'>, Assign<TSendContext, TServerContext>>;
58
57
  export type AssignAllClientSendContext<TMiddlewares, TSendContext = undefined> = unknown extends TSendContext ? TSendContext : Assign<AssignAllMiddleware<TMiddlewares, 'allClientSendContext'>, TSendContext>;
59
- export interface FunctionMiddlewareOptions<in out TMiddlewares, in out TValidator, in out TServerContext, in out TClientContext, in out TServerFnResponseType extends ServerFnResponseType> {
58
+ export interface FunctionMiddlewareOptions<in out TRegister extends Register, in out TMiddlewares, in out TValidator, in out TServerContext, in out TClientContext, in out TServerFnResponseType extends ServerFnResponseType> {
60
59
  validateClient?: boolean;
61
60
  middleware?: TMiddlewares;
62
- validator?: ConstrainValidator<TValidator>;
63
- client?: FunctionMiddlewareClientFn<TMiddlewares, TValidator, TServerContext, TClientContext, TServerFnResponseType>;
64
- server?: FunctionMiddlewareServerFn<TMiddlewares, TValidator, TServerContext, unknown, unknown, TServerFnResponseType>;
61
+ validator?: ConstrainValidator<TRegister, TValidator>;
62
+ client?: FunctionMiddlewareClientFn<TRegister, TMiddlewares, TValidator, TServerContext, TClientContext, TServerFnResponseType>;
63
+ server?: FunctionMiddlewareServerFn<TRegister, TMiddlewares, TValidator, TServerContext, unknown, unknown, TServerFnResponseType>;
65
64
  }
66
- export type FunctionMiddlewareClientNextFn<TMiddlewares> = <TSendContext = undefined, TNewClientContext = undefined>(ctx?: {
65
+ export type FunctionMiddlewareClientNextFn<TRegister extends Register, TMiddlewares> = <TSendContext = undefined, TNewClientContext = undefined>(ctx?: {
67
66
  context?: TNewClientContext;
68
- sendContext?: SerializerStringify<TSendContext>;
67
+ sendContext?: ValidateSerializableInput<TRegister, TSendContext>;
69
68
  headers?: HeadersInit;
70
69
  }) => Promise<FunctionClientResultWithContext<TMiddlewares, TSendContext, TNewClientContext>>;
71
- export interface FunctionMiddlewareServer<TMiddlewares, TValidator, TServerSendContext, TClientContext, TServerFnResponseType extends ServerFnResponseType> {
72
- server: <TNewServerContext = undefined, TSendContext = undefined>(server: FunctionMiddlewareServerFn<TMiddlewares, TValidator, TServerSendContext, TNewServerContext, TSendContext, TServerFnResponseType>) => FunctionMiddlewareAfterServer<TMiddlewares, TValidator, TNewServerContext, TServerSendContext, TClientContext, TSendContext, ServerFnResponseType>;
70
+ export interface FunctionMiddlewareServer<TRegister extends Register, TMiddlewares, TValidator, TServerSendContext, TClientContext, TServerFnResponseType extends ServerFnResponseType> {
71
+ server: <TNewServerContext = undefined, TSendContext = undefined>(server: FunctionMiddlewareServerFn<TRegister, TMiddlewares, TValidator, TServerSendContext, TNewServerContext, TSendContext, TServerFnResponseType>) => FunctionMiddlewareAfterServer<TRegister, TMiddlewares, TValidator, TNewServerContext, TServerSendContext, TClientContext, TSendContext, ServerFnResponseType>;
73
72
  }
74
- export type FunctionMiddlewareServerFn<TMiddlewares, TValidator, TServerSendContext, TNewServerContext, TSendContext, TServerFnResponseType extends ServerFnResponseType> = (options: FunctionMiddlewareServerFnOptions<TMiddlewares, TValidator, TServerSendContext, TServerFnResponseType>) => FunctionMiddlewareServerFnResult<TMiddlewares, TServerSendContext, TNewServerContext, TSendContext>;
75
- export interface RequestMiddlewareServerFnOptions<in out TMiddlewares, in out TServerSendContext> {
73
+ export type FunctionMiddlewareServerFn<TRegister extends Register, TMiddlewares, TValidator, TServerSendContext, TNewServerContext, TSendContext, TServerFnResponseType extends ServerFnResponseType> = (options: FunctionMiddlewareServerFnOptions<TRegister, TMiddlewares, TValidator, TServerSendContext, TServerFnResponseType>) => FunctionMiddlewareServerFnResult<TMiddlewares, TServerSendContext, TNewServerContext, TSendContext>;
74
+ export interface RequestMiddlewareServerFnOptions<in out TRegister extends Register, in out TMiddlewares, in out TServerSendContext> {
76
75
  request: Request;
77
76
  context: Expand<AssignAllServerContext<TMiddlewares, TServerSendContext>>;
78
- next: FunctionMiddlewareServerNextFn<TMiddlewares, TServerSendContext>;
77
+ next: FunctionMiddlewareServerNextFn<TRegister, TMiddlewares, TServerSendContext>;
79
78
  response: Response;
80
79
  method: Method;
81
80
  signal: AbortSignal;
82
81
  }
83
- export type FunctionMiddlewareServerNextFn<TMiddlewares, TServerSendContext> = <TNewServerContext = undefined, TSendContext = undefined>(ctx?: {
82
+ export type FunctionMiddlewareServerNextFn<TRegister extends Register, TMiddlewares, TServerSendContext> = <TNewServerContext = undefined, TSendContext = undefined>(ctx?: {
84
83
  context?: TNewServerContext;
85
- sendContext?: SerializerStringify<TSendContext>;
84
+ sendContext?: ValidateSerializableInput<TRegister, TSendContext>;
86
85
  }) => Promise<FunctionServerResultWithContext<TMiddlewares, TServerSendContext, TNewServerContext, TSendContext>>;
87
86
  export type FunctionServerResultWithContext<in out TMiddlewares, in out TServerSendContext, in out TServerContext, in out TSendContext> = {
88
87
  'use functions must return the result of next()': true;
@@ -93,10 +92,10 @@ export type FunctionServerResultWithContext<in out TMiddlewares, in out TServerS
93
92
  context: Expand<AssignAllServerContext<TMiddlewares, TServerSendContext, TServerContext>>;
94
93
  sendContext: Expand<AssignAllClientSendContext<TMiddlewares, TSendContext>>;
95
94
  };
96
- export interface FunctionMiddlewareServerFnOptions<in out TMiddlewares, in out TValidator, in out TServerSendContext, in out TServerFnResponseType> {
95
+ export interface FunctionMiddlewareServerFnOptions<in out TRegister extends Register, in out TMiddlewares, in out TValidator, in out TServerSendContext, in out TServerFnResponseType> {
97
96
  data: Expand<IntersectAllValidatorOutputs<TMiddlewares, TValidator>>;
98
97
  context: Expand<AssignAllServerContext<TMiddlewares, TServerSendContext>>;
99
- next: FunctionMiddlewareServerNextFn<TMiddlewares, TServerSendContext>;
98
+ next: FunctionMiddlewareServerNextFn<TRegister, TMiddlewares, TServerSendContext>;
100
99
  response: TServerFnResponseType;
101
100
  method: Method;
102
101
  filename: string;
@@ -104,20 +103,20 @@ export interface FunctionMiddlewareServerFnOptions<in out TMiddlewares, in out T
104
103
  signal: AbortSignal;
105
104
  }
106
105
  export type FunctionMiddlewareServerFnResult<TMiddlewares, TServerSendContext, TServerContext, TSendContext> = Promise<FunctionServerResultWithContext<TMiddlewares, TServerSendContext, TServerContext, TSendContext>> | FunctionServerResultWithContext<TMiddlewares, TServerSendContext, TServerContext, TSendContext>;
107
- export interface FunctionMiddlewareAfterServer<TMiddlewares, TValidator, TServerContext, TServerSendContext, TClientContext, TClientSendContext, TServerFnResponseType extends ServerFnResponseType> extends FunctionMiddlewareWithTypes<TMiddlewares, TValidator, TServerContext, TServerSendContext, TClientContext, TClientSendContext, TServerFnResponseType> {
106
+ export interface FunctionMiddlewareAfterServer<TRegister extends Register, TMiddlewares, TValidator, TServerContext, TServerSendContext, TClientContext, TClientSendContext, TServerFnResponseType extends ServerFnResponseType> extends FunctionMiddlewareWithTypes<TRegister, TMiddlewares, TValidator, TServerContext, TServerSendContext, TClientContext, TClientSendContext, TServerFnResponseType> {
108
107
  }
109
- export interface FunctionMiddlewareClient<TMiddlewares, TValidator, TServerFnResponseType extends ServerFnResponseType, TRouter extends AnyRouter = RegisteredRouter> {
110
- client: <TSendServerContext = undefined, TNewClientContext = undefined>(client: FunctionMiddlewareClientFn<TMiddlewares, TValidator, TSendServerContext, TNewClientContext, TServerFnResponseType, TRouter>) => FunctionMiddlewareAfterClient<TMiddlewares, TValidator, TSendServerContext, TNewClientContext, ServerFnResponseType>;
108
+ export interface FunctionMiddlewareClient<TRegister extends Register, TMiddlewares, TValidator, TServerFnResponseType extends ServerFnResponseType, TRouter extends AnyRouter = RegisteredRouter> {
109
+ client: <TSendServerContext = undefined, TNewClientContext = undefined>(client: FunctionMiddlewareClientFn<TRegister, TMiddlewares, TValidator, TSendServerContext, TNewClientContext, TServerFnResponseType, TRouter>) => FunctionMiddlewareAfterClient<TRegister, TMiddlewares, TValidator, TSendServerContext, TNewClientContext, ServerFnResponseType>;
111
110
  }
112
- export type FunctionMiddlewareClientFn<TMiddlewares, TValidator, TSendContext, TClientContext, TServerFnResponseType extends ServerFnResponseType, TRouter extends AnyRouter = RegisteredRouter> = (options: FunctionMiddlewareClientFnOptions<TMiddlewares, TValidator, TServerFnResponseType, TRouter>) => FunctionMiddlewareClientFnResult<TMiddlewares, TSendContext, TClientContext>;
113
- export interface FunctionMiddlewareClientFnOptions<in out TMiddlewares, in out TValidator, in out TServerFnResponseType extends ServerFnResponseType, in out TRouter extends AnyRouter> {
111
+ export type FunctionMiddlewareClientFn<TRegister extends Register, TMiddlewares, TValidator, TSendContext, TClientContext, TServerFnResponseType extends ServerFnResponseType, TRouter extends AnyRouter = RegisteredRouter> = (options: FunctionMiddlewareClientFnOptions<TRegister, TMiddlewares, TValidator, TServerFnResponseType, TRouter>) => FunctionMiddlewareClientFnResult<TMiddlewares, TSendContext, TClientContext>;
112
+ export interface FunctionMiddlewareClientFnOptions<in out TRegister extends Register, in out TMiddlewares, in out TValidator, in out TServerFnResponseType extends ServerFnResponseType, in out TRouter extends AnyRouter> {
114
113
  data: Expand<IntersectAllValidatorInputs<TMiddlewares, TValidator>>;
115
114
  context: Expand<AssignAllClientContextBeforeNext<TMiddlewares>>;
116
115
  sendContext: Expand<AssignAllServerSendContext<TMiddlewares>>;
117
116
  method: Method;
118
117
  response: TServerFnResponseType;
119
118
  signal: AbortSignal;
120
- next: FunctionMiddlewareClientNextFn<TMiddlewares>;
119
+ next: FunctionMiddlewareClientNextFn<TRegister, TMiddlewares>;
121
120
  filename: string;
122
121
  functionId: string;
123
122
  router: TRouter;
@@ -129,12 +128,12 @@ export type FunctionClientResultWithContext<in out TMiddlewares, in out TSendCon
129
128
  sendContext: Expand<AssignAllServerSendContext<TMiddlewares, TSendContext>>;
130
129
  headers: HeadersInit;
131
130
  };
132
- 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> {
131
+ export interface FunctionMiddlewareAfterClient<TRegister extends Register, TMiddlewares, TValidator, TServerSendContext, TClientContext, TServerFnResponseType extends ServerFnResponseType> extends FunctionMiddlewareWithTypes<TRegister, TMiddlewares, TValidator, undefined, TServerSendContext, TClientContext, undefined, TServerFnResponseType>, FunctionMiddlewareServer<TRegister, TMiddlewares, TValidator, TServerSendContext, TClientContext, TServerFnResponseType> {
133
132
  }
134
- export interface FunctionMiddlewareValidator<TMiddlewares, TServerFnResponseType extends ServerFnResponseType> {
135
- validator: <TNewValidator>(input: ConstrainValidator<TNewValidator>) => FunctionMiddlewareAfterValidator<TMiddlewares, TNewValidator, TServerFnResponseType>;
133
+ export interface FunctionMiddlewareValidator<TRegister extends Register, TMiddlewares, TServerFnResponseType extends ServerFnResponseType> {
134
+ validator: <TNewValidator>(input: ConstrainValidator<TRegister, TNewValidator>) => FunctionMiddlewareAfterValidator<TRegister, TMiddlewares, TNewValidator, TServerFnResponseType>;
136
135
  }
137
- 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> {
136
+ export interface FunctionMiddlewareAfterValidator<TRegister extends Register, TMiddlewares, TValidator, TServerFnResponseType extends ServerFnResponseType> extends FunctionMiddlewareWithTypes<TRegister, TMiddlewares, TValidator, undefined, undefined, undefined, undefined, ServerFnResponseType>, FunctionMiddlewareServer<TRegister, TMiddlewares, TValidator, undefined, undefined, TServerFnResponseType>, FunctionMiddlewareClient<TRegister, TMiddlewares, TValidator, ServerFnResponseType> {
138
137
  }
139
138
  export interface RequestMiddleware extends RequestMiddlewareAfterMiddleware<undefined> {
140
139
  middleware: <const TMiddlewares = undefined>(middlewares: Constrain<TMiddlewares, ReadonlyArray<AnyRequestMiddleware>>) => RequestMiddlewareAfterMiddleware<TMiddlewares>;
@@ -1 +1 @@
1
- {"version":3,"file":"createMiddleware.js","sources":["../../src/createMiddleware.ts"],"sourcesContent":["import type {\n ConstrainValidator,\n Method,\n ServerFnResponseType,\n} from './createServerFn'\nimport type {\n AnyRouter,\n Assign,\n Constrain,\n Expand,\n IntersectAssign,\n RegisteredRouter,\n ResolveValidatorInput,\n ResolveValidatorOutput,\n} from '@tanstack/router-core'\nimport type { SerializerStringify } from './serializer'\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 TRouter extends AnyRouter = RegisteredRouter,\n> {\n client: <TSendServerContext = undefined, TNewClientContext = undefined>(\n client: FunctionMiddlewareClientFn<\n TMiddlewares,\n TValidator,\n TSendServerContext,\n TNewClientContext,\n TServerFnResponseType,\n TRouter\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 TRouter extends AnyRouter = RegisteredRouter,\n> = (\n options: FunctionMiddlewareClientFnOptions<\n TMiddlewares,\n TValidator,\n TServerFnResponseType,\n TRouter\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 in out TRouter extends AnyRouter,\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 router: TRouter\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":"AAiBO,SAAS,iBACd,SAIA,QAO+B;AAE/B,QAAM,kBAAkB;AAAA,IACtB,MAAM;AAAA,IACN,GAAI,UACD;AAAA,EAAA;AASL,SAAO;AAAA,IACL,SAAS;AAAA,IACT,YAAY,CAAC,eAAoB;AAC/B,aAAO;AAAA,QACL,CAAA;AAAA,QACA,OAAO,OAAO,iBAAiB,EAAE,YAAY;AAAA,MAAA;AAAA,IAEjD;AAAA,IACA,WAAW,CAAC,cAAmB;AAC7B,aAAO;AAAA,QACL,CAAA;AAAA,QACA,OAAO,OAAO,iBAAiB,EAAE,WAAW;AAAA,MAAA;AAAA,IAEhD;AAAA,IACA,QAAQ,CAAC,WAAgB;AACvB,aAAO;AAAA,QACL,CAAA;AAAA,QACA,OAAO,OAAO,iBAAiB,EAAE,QAAQ;AAAA,MAAA;AAAA,IAE7C;AAAA,IACA,QAAQ,CAAC,WAAgB;AACvB,aAAO;AAAA,QACL,CAAA;AAAA,QACA,OAAO,OAAO,iBAAiB,EAAE,QAAQ;AAAA,MAAA;AAAA,IAE7C;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"createMiddleware.js","sources":["../../src/createMiddleware.ts"],"sourcesContent":["import type {\n ConstrainValidator,\n Method,\n ServerFnResponseType,\n} from './createServerFn'\nimport type {\n AnyRouter,\n Assign,\n Constrain,\n Expand,\n IntersectAssign,\n Register,\n RegisteredRouter,\n ResolveValidatorInput,\n ResolveValidatorOutput,\n ValidateSerializableInput,\n} from '@tanstack/router-core'\n\nexport function createMiddleware<\n TRegister extends Register,\n TType extends MiddlewareType,\n>(\n options: {\n type: TType\n validateClient?: boolean\n },\n __opts?: FunctionMiddlewareOptions<\n TRegister,\n unknown,\n undefined,\n undefined,\n undefined,\n ServerFnResponseType\n >,\n): CreateMiddlewareResult<TRegister, TType> {\n // const resolvedOptions = (__opts || options) as MiddlewareOptions<\n const resolvedOptions = {\n type: 'function',\n ...(__opts ||\n (options as FunctionMiddlewareOptions<\n TRegister,\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<TRegister, TType>\n}\n\nexport type MiddlewareType = 'request' | 'function'\n\nexport type CreateMiddlewareResult<\n TRegister extends Register,\n TType extends MiddlewareType,\n> = 'function' extends TType\n ? FunctionMiddleware<TRegister, ServerFnResponseType>\n : RequestMiddleware\n\nexport interface FunctionMiddleware<\n TRegister extends Register,\n TServerFnResponseType extends ServerFnResponseType,\n> extends FunctionMiddlewareAfterMiddleware<\n TRegister,\n unknown,\n TServerFnResponseType\n > {\n middleware: <const TNewMiddlewares = undefined>(\n middlewares: Constrain<\n TNewMiddlewares,\n ReadonlyArray<AnyFunctionMiddleware>\n >,\n ) => FunctionMiddlewareAfterMiddleware<\n TRegister,\n TNewMiddlewares,\n TServerFnResponseType\n >\n}\n\nexport interface FunctionMiddlewareAfterMiddleware<\n TRegister extends Register,\n TMiddlewares,\n TServerFnResponseType extends ServerFnResponseType,\n> extends FunctionMiddlewareWithTypes<\n TRegister,\n TMiddlewares,\n undefined,\n undefined,\n undefined,\n undefined,\n undefined,\n TServerFnResponseType\n >,\n FunctionMiddlewareServer<\n TRegister,\n TMiddlewares,\n undefined,\n undefined,\n undefined,\n TServerFnResponseType\n >,\n FunctionMiddlewareClient<\n TRegister,\n TMiddlewares,\n undefined,\n TServerFnResponseType\n >,\n FunctionMiddlewareValidator<\n TRegister,\n TMiddlewares,\n TServerFnResponseType\n > {}\n\nexport interface FunctionMiddlewareWithTypes<\n TRegister extends Register,\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 TRegister,\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 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 TRegister extends Register,\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<TRegister, TValidator>\n client?: FunctionMiddlewareClientFn<\n TRegister,\n TMiddlewares,\n TValidator,\n TServerContext,\n TClientContext,\n TServerFnResponseType\n >\n server?: FunctionMiddlewareServerFn<\n TRegister,\n TMiddlewares,\n TValidator,\n TServerContext,\n unknown,\n unknown,\n TServerFnResponseType\n >\n}\n\nexport type FunctionMiddlewareClientNextFn<\n TRegister extends Register,\n TMiddlewares,\n> = <TSendContext = undefined, TNewClientContext = undefined>(ctx?: {\n context?: TNewClientContext\n sendContext?: ValidateSerializableInput<TRegister, TSendContext>\n headers?: HeadersInit\n}) => Promise<\n FunctionClientResultWithContext<TMiddlewares, TSendContext, TNewClientContext>\n>\n\nexport interface FunctionMiddlewareServer<\n TRegister extends Register,\n TMiddlewares,\n TValidator,\n TServerSendContext,\n TClientContext,\n TServerFnResponseType extends ServerFnResponseType,\n> {\n server: <TNewServerContext = undefined, TSendContext = undefined>(\n server: FunctionMiddlewareServerFn<\n TRegister,\n TMiddlewares,\n TValidator,\n TServerSendContext,\n TNewServerContext,\n TSendContext,\n TServerFnResponseType\n >,\n ) => FunctionMiddlewareAfterServer<\n TRegister,\n TMiddlewares,\n TValidator,\n TNewServerContext,\n TServerSendContext,\n TClientContext,\n TSendContext,\n ServerFnResponseType\n >\n}\n\nexport type FunctionMiddlewareServerFn<\n TRegister extends Register,\n TMiddlewares,\n TValidator,\n TServerSendContext,\n TNewServerContext,\n TSendContext,\n TServerFnResponseType extends ServerFnResponseType,\n> = (\n options: FunctionMiddlewareServerFnOptions<\n TRegister,\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 TRegister extends Register,\n in out TMiddlewares,\n in out TServerSendContext,\n> {\n request: Request\n context: Expand<AssignAllServerContext<TMiddlewares, TServerSendContext>>\n next: FunctionMiddlewareServerNextFn<\n TRegister,\n TMiddlewares,\n TServerSendContext\n >\n response: Response\n method: Method\n signal: AbortSignal\n}\n\nexport type FunctionMiddlewareServerNextFn<\n TRegister extends Register,\n TMiddlewares,\n TServerSendContext,\n> = <TNewServerContext = undefined, TSendContext = undefined>(ctx?: {\n context?: TNewServerContext\n sendContext?: ValidateSerializableInput<TRegister, 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 TRegister extends Register,\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<\n TRegister,\n TMiddlewares,\n TServerSendContext\n >\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 TRegister extends Register,\n TMiddlewares,\n TValidator,\n TServerContext,\n TServerSendContext,\n TClientContext,\n TClientSendContext,\n TServerFnResponseType extends ServerFnResponseType,\n> extends FunctionMiddlewareWithTypes<\n TRegister,\n TMiddlewares,\n TValidator,\n TServerContext,\n TServerSendContext,\n TClientContext,\n TClientSendContext,\n TServerFnResponseType\n > {}\n\nexport interface FunctionMiddlewareClient<\n TRegister extends Register,\n TMiddlewares,\n TValidator,\n TServerFnResponseType extends ServerFnResponseType,\n TRouter extends AnyRouter = RegisteredRouter,\n> {\n client: <TSendServerContext = undefined, TNewClientContext = undefined>(\n client: FunctionMiddlewareClientFn<\n TRegister,\n TMiddlewares,\n TValidator,\n TSendServerContext,\n TNewClientContext,\n TServerFnResponseType,\n TRouter\n >,\n ) => FunctionMiddlewareAfterClient<\n TRegister,\n TMiddlewares,\n TValidator,\n TSendServerContext,\n TNewClientContext,\n ServerFnResponseType\n >\n}\n\nexport type FunctionMiddlewareClientFn<\n TRegister extends Register,\n TMiddlewares,\n TValidator,\n TSendContext,\n TClientContext,\n TServerFnResponseType extends ServerFnResponseType,\n TRouter extends AnyRouter = RegisteredRouter,\n> = (\n options: FunctionMiddlewareClientFnOptions<\n TRegister,\n TMiddlewares,\n TValidator,\n TServerFnResponseType,\n TRouter\n >,\n) => FunctionMiddlewareClientFnResult<\n TMiddlewares,\n TSendContext,\n TClientContext\n>\n\nexport interface FunctionMiddlewareClientFnOptions<\n in out TRegister extends Register,\n in out TMiddlewares,\n in out TValidator,\n in out TServerFnResponseType extends ServerFnResponseType,\n in out TRouter extends AnyRouter,\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<TRegister, TMiddlewares>\n filename: string\n functionId: string\n router: TRouter\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 TRegister extends Register,\n TMiddlewares,\n TValidator,\n TServerSendContext,\n TClientContext,\n TServerFnResponseType extends ServerFnResponseType,\n> extends FunctionMiddlewareWithTypes<\n TRegister,\n TMiddlewares,\n TValidator,\n undefined,\n TServerSendContext,\n TClientContext,\n undefined,\n TServerFnResponseType\n >,\n FunctionMiddlewareServer<\n TRegister,\n TMiddlewares,\n TValidator,\n TServerSendContext,\n TClientContext,\n TServerFnResponseType\n > {}\n\nexport interface FunctionMiddlewareValidator<\n TRegister extends Register,\n TMiddlewares,\n TServerFnResponseType extends ServerFnResponseType,\n> {\n validator: <TNewValidator>(\n input: ConstrainValidator<TRegister, TNewValidator>,\n ) => FunctionMiddlewareAfterValidator<\n TRegister,\n TMiddlewares,\n TNewValidator,\n TServerFnResponseType\n >\n}\n\nexport interface FunctionMiddlewareAfterValidator<\n TRegister extends Register,\n TMiddlewares,\n TValidator,\n TServerFnResponseType extends ServerFnResponseType,\n> extends FunctionMiddlewareWithTypes<\n TRegister,\n TMiddlewares,\n TValidator,\n undefined,\n undefined,\n undefined,\n undefined,\n ServerFnResponseType\n >,\n FunctionMiddlewareServer<\n TRegister,\n TMiddlewares,\n TValidator,\n undefined,\n undefined,\n TServerFnResponseType\n >,\n FunctionMiddlewareClient<\n TRegister,\n TMiddlewares,\n TValidator,\n ServerFnResponseType\n > {}\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":"AAkBO,SAAS,iBAId,SAIA,QAQ0C;AAE1C,QAAM,kBAAkB;AAAA,IACtB,MAAM;AAAA,IACN,GAAI,UACD;AAAA,EAAA;AAUL,SAAO;AAAA,IACL,SAAS;AAAA,IACT,YAAY,CAAC,eAAoB;AAC/B,aAAO;AAAA,QACL,CAAA;AAAA,QACA,OAAO,OAAO,iBAAiB,EAAE,YAAY;AAAA,MAAA;AAAA,IAEjD;AAAA,IACA,WAAW,CAAC,cAAmB;AAC7B,aAAO;AAAA,QACL,CAAA;AAAA,QACA,OAAO,OAAO,iBAAiB,EAAE,WAAW;AAAA,MAAA;AAAA,IAEhD;AAAA,IACA,QAAQ,CAAC,WAAgB;AACvB,aAAO;AAAA,QACL,CAAA;AAAA,QACA,OAAO,OAAO,iBAAiB,EAAE,QAAQ;AAAA,MAAA;AAAA,IAE7C;AAAA,IACA,QAAQ,CAAC,WAAgB;AACvB,aAAO;AAAA,QACL,CAAA;AAAA,QACA,OAAO,OAAO,iBAAiB,EAAE,QAAQ;AAAA,MAAA;AAAA,IAE7C;AAAA,EAAA;AAEJ;"}
@@ -1,12 +1,11 @@
1
- import { SerializerParse, SerializerStringify, SerializerStringifyBy } from './serializer.js';
2
- import { AnyRouter, AnyValidator, Constrain, Expand, ResolveValidatorInput, Validator } from '@tanstack/router-core';
1
+ import { AnyRouter, AnyValidator, Constrain, Expand, Register, RegisteredSerializableInput, ResolveValidatorInput, ValidateSerializable, ValidateSerializableInput, ValidateSerializableInputResult, Validator } from '@tanstack/router-core';
3
2
  import { JsonResponse } from '@tanstack/router-core/ssr/client';
4
3
  import { Readable } from 'node:stream';
5
4
  import { AnyFunctionMiddleware, AssignAllClientSendContext, AssignAllServerContext, IntersectAllValidatorInputs, IntersectAllValidatorOutputs } from './createMiddleware.js';
6
- export declare function createServerFn<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType = 'data', TResponse = unknown, TMiddlewares = undefined, TValidator = undefined>(options?: {
5
+ export declare function createServerFn<TRegister extends Register, TMethod extends Method, TServerFnResponseType extends ServerFnResponseType = 'data', TResponse = unknown, TMiddlewares = undefined, TValidator = undefined>(options?: {
7
6
  method?: TMethod;
8
7
  response?: TServerFnResponseType;
9
- }, __opts?: ServerFnBaseOptions<TMethod, TServerFnResponseType, TResponse, TMiddlewares, TValidator>): ServerFnBuilder<TMethod, TServerFnResponseType>;
8
+ }, __opts?: ServerFnBaseOptions<TRegister, TMethod, TServerFnResponseType, TResponse, TMiddlewares, TValidator>): ServerFnBuilder<TRegister, TMethod, TServerFnResponseType>;
10
9
  export declare function executeMiddleware(middlewares: Array<AnyFunctionMiddleware>, env: 'client' | 'server', opts: ServerFnMiddlewareOptions): Promise<ServerFnMiddlewareResult>;
11
10
  export type CompiledFetcherFnOptions = {
12
11
  method: Method;
@@ -16,7 +15,7 @@ export type CompiledFetcherFnOptions = {
16
15
  signal?: AbortSignal;
17
16
  context?: any;
18
17
  };
19
- export type Fetcher<TMiddlewares, TValidator, TResponse, TServerFnResponseType extends ServerFnResponseType> = undefined extends IntersectAllValidatorInputs<TMiddlewares, TValidator> ? OptionalFetcher<TMiddlewares, TValidator, TResponse, TServerFnResponseType> : RequiredFetcher<TMiddlewares, TValidator, TResponse, TServerFnResponseType>;
18
+ export type Fetcher<TRegister extends Register, TMiddlewares, TValidator, TResponse, TServerFnResponseType extends ServerFnResponseType> = undefined extends IntersectAllValidatorInputs<TMiddlewares, TValidator> ? OptionalFetcher<TRegister, TMiddlewares, TValidator, TResponse, TServerFnResponseType> : RequiredFetcher<TRegister, TMiddlewares, TValidator, TResponse, TServerFnResponseType>;
20
19
  export interface FetcherBase {
21
20
  url: string;
22
21
  __executeServer: (opts: {
@@ -28,12 +27,12 @@ export interface FetcherBase {
28
27
  signal: AbortSignal;
29
28
  }) => Promise<unknown>;
30
29
  }
31
- export type FetchResult<TMiddlewares, TResponse, TServerFnResponseType extends ServerFnResponseType> = TServerFnResponseType extends 'raw' ? Promise<Response> : TServerFnResponseType extends 'full' ? Promise<FullFetcherData<TMiddlewares, TResponse>> : Promise<FetcherData<TResponse>>;
32
- export interface OptionalFetcher<TMiddlewares, TValidator, TResponse, TServerFnResponseType extends ServerFnResponseType> extends FetcherBase {
33
- (options?: OptionalFetcherDataOptions<TMiddlewares, TValidator>): FetchResult<TMiddlewares, TResponse, TServerFnResponseType>;
30
+ export type FetchResult<TRegister extends Register, TMiddlewares, TResponse, TServerFnResponseType extends ServerFnResponseType> = TServerFnResponseType extends 'raw' ? Promise<Response> : TServerFnResponseType extends 'full' ? Promise<FullFetcherData<TRegister, TMiddlewares, TResponse>> : Promise<FetcherData<TRegister, TResponse>>;
31
+ export interface OptionalFetcher<TRegister extends Register, TMiddlewares, TValidator, TResponse, TServerFnResponseType extends ServerFnResponseType> extends FetcherBase {
32
+ (options?: OptionalFetcherDataOptions<TMiddlewares, TValidator>): FetchResult<TRegister, TMiddlewares, TResponse, TServerFnResponseType>;
34
33
  }
35
- export interface RequiredFetcher<TMiddlewares, TValidator, TResponse, TServerFnResponseType extends ServerFnResponseType> extends FetcherBase {
36
- (opts: RequiredFetcherDataOptions<TMiddlewares, TValidator>): FetchResult<TMiddlewares, TResponse, TServerFnResponseType>;
34
+ export interface RequiredFetcher<TRegister extends Register, TMiddlewares, TValidator, TResponse, TServerFnResponseType extends ServerFnResponseType> extends FetcherBase {
35
+ (opts: RequiredFetcherDataOptions<TMiddlewares, TValidator>): FetchResult<TRegister, TMiddlewares, TResponse, TServerFnResponseType>;
37
36
  }
38
37
  export type FetcherBaseOptions = {
39
38
  headers?: HeadersInit;
@@ -45,20 +44,20 @@ export interface OptionalFetcherDataOptions<TMiddlewares, TValidator> extends Fe
45
44
  export interface RequiredFetcherDataOptions<TMiddlewares, TValidator> extends FetcherBaseOptions {
46
45
  data: Expand<IntersectAllValidatorInputs<TMiddlewares, TValidator>>;
47
46
  }
48
- export interface FullFetcherData<TMiddlewares, TResponse> {
47
+ export interface FullFetcherData<TRegister extends Register, TMiddlewares, TResponse> {
49
48
  error: unknown;
50
- result: FetcherData<TResponse>;
49
+ result: FetcherData<TRegister, TResponse>;
51
50
  context: AssignAllClientSendContext<TMiddlewares>;
52
51
  }
53
- export type FetcherData<TResponse> = TResponse extends JsonResponse<any> ? SerializerParse<ReturnType<TResponse['json']>> : SerializerParse<TResponse>;
52
+ export type FetcherData<TRegister extends Register, TResponse> = TResponse extends JsonResponse<any> ? ValidateSerializableInputResult<TRegister, ReturnType<TResponse['json']>> : ValidateSerializableInputResult<TRegister, TResponse>;
54
53
  export type RscStream<T> = {
55
54
  __cacheState: T;
56
55
  };
57
56
  export type Method = 'GET' | 'POST';
58
57
  export type ServerFnResponseType = 'data' | 'full' | 'raw';
59
58
  export type RawResponse = Response | ReadableStream | Readable | null | string;
60
- export type ServerFnReturnType<TServerFnResponseType extends ServerFnResponseType, TResponse> = TServerFnResponseType extends 'raw' ? RawResponse | Promise<RawResponse> : Promise<SerializerStringify<TResponse>> | SerializerStringify<TResponse>;
61
- export type ServerFn<TMethod, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator, TResponse> = (ctx: ServerFnCtx<TMethod, TServerFnResponseType, TMiddlewares, TValidator>) => ServerFnReturnType<TServerFnResponseType, TResponse>;
59
+ export type ServerFnReturnType<TRegister extends Register, TServerFnResponseType extends ServerFnResponseType, TResponse> = TServerFnResponseType extends 'raw' ? RawResponse | Promise<RawResponse> : Promise<ValidateSerializableInput<TRegister, TResponse>> | ValidateSerializableInput<TRegister, TResponse>;
60
+ export type ServerFn<TRegister extends Register, TMethod, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator, TResponse> = (ctx: ServerFnCtx<TMethod, TServerFnResponseType, TMiddlewares, TValidator>) => ServerFnReturnType<TRegister, TServerFnResponseType, TResponse>;
62
61
  export interface ServerFnCtx<TMethod, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> {
63
62
  method: TMethod;
64
63
  response: TServerFnResponseType;
@@ -66,41 +65,49 @@ export interface ServerFnCtx<TMethod, TServerFnResponseType extends ServerFnResp
66
65
  context: Expand<AssignAllServerContext<TMiddlewares>>;
67
66
  signal: AbortSignal;
68
67
  }
69
- export type CompiledFetcherFn<TResponse, TServerFnResponseType extends ServerFnResponseType> = {
70
- (opts: CompiledFetcherFnOptions & ServerFnBaseOptions<Method, TServerFnResponseType>): Promise<TResponse>;
68
+ export type CompiledFetcherFn<TRegister extends Register, TResponse, TServerFnResponseType extends ServerFnResponseType> = {
69
+ (opts: CompiledFetcherFnOptions & ServerFnBaseOptions<TRegister, Method, TServerFnResponseType>): Promise<TResponse>;
71
70
  url: string;
72
71
  };
73
- export type ServerFnBaseOptions<TMethod extends Method = 'GET', TServerFnResponseType extends ServerFnResponseType = 'data', TResponse = unknown, TMiddlewares = unknown, TInput = unknown> = {
72
+ export type ServerFnBaseOptions<TRegister extends Register, TMethod extends Method = 'GET', TServerFnResponseType extends ServerFnResponseType = 'data', TResponse = unknown, TMiddlewares = unknown, TInput = unknown> = {
74
73
  method: TMethod;
75
74
  response?: TServerFnResponseType;
76
75
  validateClient?: boolean;
77
76
  middleware?: Constrain<TMiddlewares, ReadonlyArray<AnyFunctionMiddleware>>;
78
- validator?: ConstrainValidator<TInput>;
79
- extractedFn?: CompiledFetcherFn<TResponse, TServerFnResponseType>;
80
- serverFn?: ServerFn<TMethod, TServerFnResponseType, TMiddlewares, TInput, TResponse>;
77
+ validator?: ConstrainValidator<TRegister, TInput>;
78
+ extractedFn?: CompiledFetcherFn<TRegister, TResponse, TServerFnResponseType>;
79
+ serverFn?: ServerFn<TRegister, TMethod, TServerFnResponseType, TMiddlewares, TInput, TResponse>;
81
80
  functionId: string;
82
81
  };
83
- export type ValidatorInputStringify<TValidator> = SerializerStringifyBy<ResolveValidatorInput<TValidator>, Date | undefined | FormData>;
84
- export type ValidatorSerializerStringify<TValidator> = ValidatorInputStringify<TValidator> extends infer TInput ? Validator<TInput, any> : never;
85
- export type ConstrainValidator<TValidator> = (unknown extends TValidator ? TValidator : ResolveValidatorInput<TValidator> extends ValidatorInputStringify<TValidator> ? TValidator : never) | ValidatorSerializerStringify<TValidator>;
86
- export interface ServerFnMiddleware<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TValidator> {
87
- middleware: <const TNewMiddlewares = undefined>(middlewares: Constrain<TNewMiddlewares, ReadonlyArray<AnyFunctionMiddleware>>) => ServerFnAfterMiddleware<TMethod, TServerFnResponseType, TNewMiddlewares, TValidator>;
82
+ export type ValidateValidatorInput<TRegister extends Register, TValidator> = ValidateSerializable<ResolveValidatorInput<TValidator>, RegisteredSerializableInput<TRegister> | FormData>;
83
+ export type ValidateValidator<TRegister extends Register, TValidator> = ValidateValidatorInput<TRegister, TValidator> extends infer TInput ? Validator<TInput, any> : never;
84
+ export type ConstrainValidator<TRegister extends Register, TValidator> = (unknown extends TValidator ? TValidator : ResolveValidatorInput<TValidator> extends ValidateValidator<TRegister, TValidator> ? TValidator : never) | ValidateValidator<TRegister, TValidator>;
85
+ type ToTuple<T> = T extends ReadonlyArray<infer U> ? T : T extends undefined ? [] : [T];
86
+ export interface ServerFnMiddleware<TRegister extends Register, TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> {
87
+ middleware: <const TNewMiddlewares = undefined>(middlewares: Constrain<TNewMiddlewares, ReadonlyArray<AnyFunctionMiddleware>>) => ServerFnAfterMiddleware<TRegister, TMethod, TServerFnResponseType, [
88
+ ...ToTuple<TMiddlewares>,
89
+ ...ToTuple<TNewMiddlewares>
90
+ ], TValidator>;
88
91
  }
89
- export interface ServerFnAfterMiddleware<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> extends ServerFnValidator<TMethod, TServerFnResponseType, TMiddlewares>, ServerFnHandler<TMethod, TServerFnResponseType, TMiddlewares, TValidator> {
92
+ export interface ServerFnAfterMiddleware<TRegister extends Register, TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> extends ServerFnMiddleware<TRegister, TMethod, TServerFnResponseType, TMiddlewares, undefined>, ServerFnValidator<TRegister, TMethod, TServerFnResponseType, TMiddlewares>, ServerFnHandler<TRegister, TMethod, TServerFnResponseType, TMiddlewares, TValidator> {
93
+ <TNewMethod extends Method = TMethod, TNewServerFnResponseType extends ServerFnResponseType = TServerFnResponseType>(options?: {
94
+ method?: TNewMethod;
95
+ response?: TNewServerFnResponseType;
96
+ }): ServerFnAfterMiddleware<TRegister, TNewMethod, TNewServerFnResponseType, TMiddlewares, TValidator>;
90
97
  }
91
- export type ValidatorFn<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares> = <TValidator>(validator: ConstrainValidator<TValidator>) => ServerFnAfterValidator<TMethod, TServerFnResponseType, TMiddlewares, TValidator>;
92
- export interface ServerFnValidator<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares> {
93
- validator: ValidatorFn<TMethod, TServerFnResponseType, TMiddlewares>;
98
+ export type ValidatorFn<TRegister extends Register, TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares> = <TValidator>(validator: ConstrainValidator<TRegister, TValidator>) => ServerFnAfterValidator<TRegister, TMethod, TServerFnResponseType, TMiddlewares, TValidator>;
99
+ export interface ServerFnValidator<TRegister extends Register, TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares> {
100
+ validator: ValidatorFn<TRegister, TMethod, TServerFnResponseType, TMiddlewares>;
94
101
  }
95
- export interface ServerFnAfterValidator<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> extends ServerFnMiddleware<TMethod, TServerFnResponseType, TValidator>, ServerFnHandler<TMethod, TServerFnResponseType, TMiddlewares, TValidator> {
102
+ export interface ServerFnAfterValidator<TRegister extends Register, TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> extends ServerFnMiddleware<TRegister, TMethod, TServerFnResponseType, TMiddlewares, TValidator>, ServerFnHandler<TRegister, TMethod, TServerFnResponseType, TMiddlewares, TValidator> {
96
103
  }
97
- export interface ServerFnAfterTyper<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> extends ServerFnHandler<TMethod, TServerFnResponseType, TMiddlewares, TValidator> {
104
+ export interface ServerFnAfterTyper<TRegister extends Register, TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> extends ServerFnHandler<TRegister, TMethod, TServerFnResponseType, TMiddlewares, TValidator> {
98
105
  }
99
- export interface ServerFnHandler<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> {
100
- handler: <TNewResponse>(fn?: ServerFn<TMethod, TServerFnResponseType, TMiddlewares, TValidator, TNewResponse>) => Fetcher<TMiddlewares, TValidator, TNewResponse, TServerFnResponseType>;
106
+ export interface ServerFnHandler<TRegister extends Register, TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> {
107
+ handler: <TNewResponse>(fn?: ServerFn<TRegister, TMethod, TServerFnResponseType, TMiddlewares, TValidator, TNewResponse>) => Fetcher<TRegister, TMiddlewares, TValidator, TNewResponse, TServerFnResponseType>;
101
108
  }
102
- export interface ServerFnBuilder<TMethod extends Method = 'GET', TServerFnResponseType extends ServerFnResponseType = 'data'> extends ServerFnMiddleware<TMethod, TServerFnResponseType, undefined>, ServerFnValidator<TMethod, TServerFnResponseType, undefined>, ServerFnHandler<TMethod, TServerFnResponseType, undefined, undefined> {
103
- options: ServerFnBaseOptions<TMethod, TServerFnResponseType, unknown, undefined, undefined>;
109
+ export interface ServerFnBuilder<TRegister extends Register, TMethod extends Method = 'GET', TServerFnResponseType extends ServerFnResponseType = 'data'> extends ServerFnMiddleware<TRegister, TMethod, TServerFnResponseType, undefined, undefined>, ServerFnValidator<TRegister, TMethod, TServerFnResponseType, undefined>, ServerFnHandler<TRegister, TMethod, TServerFnResponseType, undefined, undefined> {
110
+ options: ServerFnBaseOptions<TRegister, TMethod, TServerFnResponseType, unknown, undefined, undefined>;
104
111
  }
105
112
  export declare function flattenMiddlewares(middlewares: Array<AnyFunctionMiddleware>): Array<AnyFunctionMiddleware>;
106
113
  export type ServerFnMiddlewareOptions = {
@@ -124,4 +131,5 @@ export type MiddlewareFn = (ctx: ServerFnMiddlewareOptions & {
124
131
  }) => Promise<ServerFnMiddlewareResult>;
125
132
  export declare const applyMiddleware: (middlewareFn: MiddlewareFn, ctx: ServerFnMiddlewareOptions, nextFn: NextFn) => Promise<ServerFnMiddlewareResult>;
126
133
  export declare function execValidator(validator: AnyValidator, input: unknown): unknown;
127
- export declare function serverFnBaseToMiddleware(options: ServerFnBaseOptions<any, any, any, any, any>): AnyFunctionMiddleware;
134
+ export declare function serverFnBaseToMiddleware(options: ServerFnBaseOptions<any, any, any, any, any, any>): AnyFunctionMiddleware;
135
+ export {};
@@ -7,37 +7,38 @@ function createServerFn(options, __opts) {
7
7
  if (typeof resolvedOptions.method === "undefined") {
8
8
  resolvedOptions.method = "GET";
9
9
  }
10
- return {
10
+ const res = {
11
11
  options: resolvedOptions,
12
12
  middleware: (middleware) => {
13
- return createServerFn(void 0, Object.assign(resolvedOptions, { middleware }));
13
+ const newOptions = {
14
+ ...resolvedOptions,
15
+ middleware: [...resolvedOptions.middleware || [], ...middleware]
16
+ };
17
+ return createServerFn(void 0, newOptions);
14
18
  },
15
19
  validator: (validator) => {
16
- return createServerFn(void 0, Object.assign(resolvedOptions, { validator }));
20
+ const newOptions = { ...resolvedOptions, validator };
21
+ return createServerFn(void 0, newOptions);
17
22
  },
18
23
  handler: (...args) => {
19
24
  const [extractedFn, serverFn] = args;
20
- Object.assign(resolvedOptions, {
21
- ...extractedFn,
22
- extractedFn,
23
- serverFn
24
- });
25
+ const newOptions = { ...resolvedOptions, extractedFn, serverFn };
25
26
  const resolvedMiddleware = [
26
- ...resolvedOptions.middleware || [],
27
- serverFnBaseToMiddleware(resolvedOptions)
27
+ ...newOptions.middleware || [],
28
+ serverFnBaseToMiddleware(newOptions)
28
29
  ];
29
30
  return Object.assign(
30
31
  async (opts) => {
31
32
  return executeMiddleware(resolvedMiddleware, "client", {
32
33
  ...extractedFn,
33
- ...resolvedOptions,
34
+ ...newOptions,
34
35
  data: opts?.data,
35
36
  headers: opts?.headers,
36
37
  signal: opts?.signal,
37
38
  context: {},
38
39
  router: getRouterInstance()
39
40
  }).then((d) => {
40
- if (resolvedOptions.response === "full") {
41
+ if (newOptions.response === "full") {
41
42
  return d;
42
43
  }
43
44
  if (d.error) throw d.error;
@@ -68,6 +69,16 @@ function createServerFn(options, __opts) {
68
69
  );
69
70
  }
70
71
  };
72
+ const fun = (options2) => {
73
+ return {
74
+ ...res,
75
+ options: {
76
+ ...res.options,
77
+ ...options2
78
+ }
79
+ };
80
+ };
81
+ return Object.assign(fun, res);
71
82
  }
72
83
  async function executeMiddleware(middlewares, env, opts) {
73
84
  const flattenedMiddlewares = flattenMiddlewares([