@tanstack/start-client-core 1.120.7 → 1.121.0-alpha.11

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 (36) hide show
  1. package/README.md +6 -27
  2. package/dist/cjs/createMiddleware.cjs +8 -5
  3. package/dist/cjs/createMiddleware.cjs.map +1 -1
  4. package/dist/cjs/createMiddleware.d.cts +125 -81
  5. package/dist/cjs/createServerFn.cjs +1 -0
  6. package/dist/cjs/createServerFn.cjs.map +1 -1
  7. package/dist/cjs/createServerFn.d.cts +6 -5
  8. package/dist/cjs/index.cjs +1 -0
  9. package/dist/cjs/index.cjs.map +1 -1
  10. package/dist/cjs/index.d.cts +2 -2
  11. package/dist/cjs/registerGlobalMiddleware.cjs.map +1 -1
  12. package/dist/cjs/registerGlobalMiddleware.d.cts +3 -3
  13. package/dist/cjs/ssr-client.cjs +62 -61
  14. package/dist/cjs/ssr-client.cjs.map +1 -1
  15. package/dist/cjs/ssr-client.d.cts +2 -1
  16. package/dist/esm/createMiddleware.d.ts +125 -81
  17. package/dist/esm/createMiddleware.js +8 -5
  18. package/dist/esm/createMiddleware.js.map +1 -1
  19. package/dist/esm/createServerFn.d.ts +6 -5
  20. package/dist/esm/createServerFn.js +1 -0
  21. package/dist/esm/createServerFn.js.map +1 -1
  22. package/dist/esm/index.d.ts +2 -2
  23. package/dist/esm/index.js +2 -1
  24. package/dist/esm/registerGlobalMiddleware.d.ts +3 -3
  25. package/dist/esm/registerGlobalMiddleware.js.map +1 -1
  26. package/dist/esm/ssr-client.d.ts +2 -1
  27. package/dist/esm/ssr-client.js +62 -61
  28. package/dist/esm/ssr-client.js.map +1 -1
  29. package/package.json +2 -2
  30. package/src/createMiddleware.ts +474 -363
  31. package/src/createServerFn.ts +31 -16
  32. package/src/index.tsx +22 -21
  33. package/src/registerGlobalMiddleware.ts +3 -3
  34. package/src/ssr-client.tsx +75 -69
  35. package/src/tests/createServerFn.test-d.ts +20 -13
  36. package/src/tests/createServerMiddleware.test-d.ts +186 -73
package/README.md CHANGED
@@ -1,33 +1,12 @@
1
- > 🤫 we're cooking up something special!
2
-
3
1
  <img src="https://static.scarf.sh/a.png?x-pxid=d988eb79-b0fc-4a2b-8514-6a1ab932d188" />
4
2
 
5
- # TanStack Start
6
-
7
- ![TanStack Router Header](https://github.com/tanstack/router/raw/main/media/header.png)
3
+ # TanStack Start - Client Core
8
4
 
9
- 🤖 Type-safe router w/ built-in caching & URL state management for React!
5
+ This package is not meant to be used directly. It is a dependency of the TanStack Start framework-specific packages:
10
6
 
11
- <a href="https://twitter.com/intent/tweet?button_hashtag=TanStack" target="\_parent">
12
- <img alt="#TanStack" src="https://img.shields.io/twitter/url?color=%2308a0e9&label=%23TanStack&style=social&url=https%3A%2F%2Ftwitter.com%2Fintent%2Ftweet%3Fbutton_hashtag%3DTanStack">
13
- </a><a href="https://discord.com/invite/WrRKjPJ" target="\_parent">
14
- <img alt="" src="https://img.shields.io/badge/Discord-TanStack-%235865F2" />
15
- </a><a href="https://npmjs.com/package/@tanstack/solid-router" target="\_parent">
16
- <img alt="" src="https://img.shields.io/npm/dm/@tanstack/router.svg" />
17
- </a><a href="https://bundlephobia.com/result?p=@tanstack/solid-router" target="\_parent">
18
- <img alt="" src="https://badgen.net/bundlephobia/minzip/@tanstack/solid-router" />
19
- </a><a href="#badge">
20
- <img alt="semantic-release" src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg">
21
- </a><a href="https://github.com/tanstack/router/discussions">
22
- <img alt="Join the discussion on Github" src="https://img.shields.io/badge/Github%20Discussions%20%26%20Support-Chat%20now!-blue" />
23
- </a><a href="https://bestofjs.org/projects/router"><img alt="Best of JS" src="https://img.shields.io/endpoint?url=https://bestofjs-serverless.now.sh/api/project-badge?fullName=tanstack%2Frouter%26since=daily" /></a><a href="https://github.com/tanstack/router" target="\_parent">
24
- <img alt="" src="https://img.shields.io/github/stars/tanstack/router.svg?style=social&label=Star" />
25
- </a><a href="https://twitter.com/tan_stack" target="\_parent">
26
- <img alt="" src="https://img.shields.io/twitter/follow/tan_stack.svg?style=social&label=Follow @TanStack" />
27
- </a><a href="https://twitter.com/tannerlinsley" target="\_parent">
28
- <img alt="" src="https://img.shields.io/twitter/follow/tannerlinsley.svg?style=social&label=Follow @TannerLinsley" />
29
- </a>
7
+ - [`@tanstack/react-start`](https://www.npmjs.com/package/@tanstack/react-start)
8
+ - [`@tanstack/solid-start`](https://www.npmjs.com/package/@tanstack/solid-start).
30
9
 
31
- Enjoy this library? Try the entire [TanStack](https://tanstack.com)! [React Query](https://github.com/tannerlinsley/react-query), [React Table](https://github.com/tanstack/react-table), [React Charts](https://github.com/tannerlinsley/react-charts), [React Virtual](https://github.com/tannerlinsley/react-virtual)
10
+ It provides the core functionality for TanStack Start, which is a fullstack-framework made for SSR, Streaming, Server Functions, API Routes, bundling and more powered by [TanStack Router](https://tanstack.com/router).
32
11
 
33
- ## Visit [tanstack.com/router](https://tanstack.com/router) for docs, guides, API and more!
12
+ Head over to [tanstack.com/start](https://tanstack.com/start) for more information about getting started.
@@ -1,30 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  function createMiddleware(options, __opts) {
4
- const resolvedOptions = __opts || (options || {});
4
+ const resolvedOptions = {
5
+ type: "function",
6
+ ...__opts || options
7
+ };
5
8
  return {
6
9
  options: resolvedOptions,
7
10
  middleware: (middleware) => {
8
11
  return createMiddleware(
9
- void 0,
12
+ {},
10
13
  Object.assign(resolvedOptions, { middleware })
11
14
  );
12
15
  },
13
16
  validator: (validator) => {
14
17
  return createMiddleware(
15
- void 0,
18
+ {},
16
19
  Object.assign(resolvedOptions, { validator })
17
20
  );
18
21
  },
19
22
  client: (client) => {
20
23
  return createMiddleware(
21
- void 0,
24
+ {},
22
25
  Object.assign(resolvedOptions, { client })
23
26
  );
24
27
  },
25
28
  server: (server) => {
26
29
  return createMiddleware(
27
- void 0,
30
+ {},
28
31
  Object.assign(resolvedOptions, { server })
29
32
  );
30
33
  }
@@ -1 +1 @@
1
- {"version":3,"file":"createMiddleware.cjs","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 type AssignAllMiddleware<\n TMiddlewares,\n TType extends keyof AnyMiddleware['_types'],\n TAcc = undefined,\n> = TMiddlewares extends readonly [\n infer TMiddleware extends AnyMiddleware,\n ...infer TRest,\n]\n ? AssignAllMiddleware<\n TRest,\n TType,\n Assign<TAcc, TMiddleware['_types'][TType]>\n >\n : TAcc\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 AssignAllClientSendContext<\n TMiddlewares,\n TSendContext = undefined,\n> = unknown extends TSendContext\n ? TSendContext\n : Assign<\n AssignAllMiddleware<TMiddlewares, 'allClientSendContext'>,\n TSendContext\n >\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\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 AssignAllServerSendContext<\n TMiddlewares,\n TSendContext = undefined,\n> = unknown extends TSendContext\n ? TSendContext\n : Assign<\n AssignAllMiddleware<TMiddlewares, 'allServerSendContext'>,\n TSendContext\n >\n\nexport type IntersectAllMiddleware<\n TMiddlewares,\n TType extends keyof AnyMiddleware['_types'],\n TAcc = undefined,\n> = TMiddlewares extends readonly [\n infer TMiddleware extends AnyMiddleware,\n ...infer TRest,\n]\n ? IntersectAllMiddleware<\n TRest,\n TType,\n IntersectAssign<TAcc, TMiddleware['_types'][TType]>\n >\n : TAcc\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 : IntersectAssign<\n IntersectAllMiddleware<TMiddlewares, 'allInput'>,\n TValidator extends undefined\n ? undefined\n : ResolveValidatorInput<TValidator>\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 : IntersectAssign<\n IntersectAllMiddleware<TMiddlewares, 'allOutput'>,\n TValidator extends undefined\n ? undefined\n : ResolveValidatorOutput<TValidator>\n >\n\nexport interface MiddlewareOptions<\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?: MiddlewareClientFn<\n TMiddlewares,\n TValidator,\n TServerContext,\n TClientContext,\n TServerFnResponseType\n >\n server?: MiddlewareServerFn<\n TMiddlewares,\n TValidator,\n TServerContext,\n unknown,\n unknown,\n TServerFnResponseType\n >\n}\n\nexport type MiddlewareServerNextFn<TMiddlewares, TServerSendContext> = <\n TNewServerContext = undefined,\n TSendContext = undefined,\n>(ctx?: {\n context?: TNewServerContext\n sendContext?: SerializerStringify<TSendContext>\n}) => Promise<\n ServerResultWithContext<\n TMiddlewares,\n TServerSendContext,\n TNewServerContext,\n TSendContext\n >\n>\n\nexport interface MiddlewareServerFnOptions<\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: MiddlewareServerNextFn<TMiddlewares, TServerSendContext>\n response: TServerFnResponseType\n method: Method\n filename: string\n functionId: string\n signal: AbortSignal\n}\n\nexport type MiddlewareServerFn<\n TMiddlewares,\n TValidator,\n TServerSendContext,\n TNewServerContext,\n TSendContext,\n TServerFnResponseType extends ServerFnResponseType,\n> = (\n options: MiddlewareServerFnOptions<\n TMiddlewares,\n TValidator,\n TServerSendContext,\n TServerFnResponseType\n >,\n) => MiddlewareServerFnResult<\n TMiddlewares,\n TServerSendContext,\n TNewServerContext,\n TSendContext\n>\n\nexport type MiddlewareServerFnResult<\n TMiddlewares,\n TServerSendContext,\n TServerContext,\n TSendContext,\n> =\n | Promise<\n ServerResultWithContext<\n TMiddlewares,\n TServerSendContext,\n TServerContext,\n TSendContext\n >\n >\n | ServerResultWithContext<\n TMiddlewares,\n TServerSendContext,\n TServerContext,\n TSendContext\n >\n\nexport type MiddlewareClientNextFn<TMiddlewares> = <\n TSendContext = undefined,\n TNewClientContext = undefined,\n>(ctx?: {\n context?: TNewClientContext\n sendContext?: SerializerStringify<TSendContext>\n headers?: HeadersInit\n}) => Promise<\n ClientResultWithContext<TMiddlewares, TSendContext, TNewClientContext>\n>\n\nexport interface MiddlewareClientFnOptions<\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: MiddlewareClientNextFn<TMiddlewares>\n filename: string\n functionId: string\n type: ServerFnTypeOrTypeFn<\n Method,\n TServerFnResponseType,\n TMiddlewares,\n TValidator\n >\n}\n\nexport type MiddlewareClientFn<\n TMiddlewares,\n TValidator,\n TSendContext,\n TClientContext,\n TServerFnResponseType extends ServerFnResponseType,\n> = (\n options: MiddlewareClientFnOptions<\n TMiddlewares,\n TValidator,\n TServerFnResponseType\n >,\n) => MiddlewareClientFnResult<TMiddlewares, TSendContext, TClientContext>\n\nexport type MiddlewareClientFnResult<\n TMiddlewares,\n TSendContext,\n TClientContext,\n> =\n | Promise<ClientResultWithContext<TMiddlewares, TSendContext, TClientContext>>\n | ClientResultWithContext<TMiddlewares, TSendContext, TClientContext>\n\nexport type ServerResultWithContext<\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 type ClientResultWithContext<\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 type AnyMiddleware = MiddlewareWithTypes<\n any,\n any,\n any,\n any,\n any,\n any,\n any\n>\n\nexport interface MiddlewareTypes<\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 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\nexport interface MiddlewareWithTypes<\n TMiddlewares,\n TValidator,\n TServerContext,\n TServerSendContext,\n TClientContext,\n TClientSendContext,\n TServerFnResponseType extends ServerFnResponseType,\n> {\n _types: MiddlewareTypes<\n TMiddlewares,\n TValidator,\n TServerContext,\n TServerSendContext,\n TClientContext,\n TClientSendContext\n >\n options: MiddlewareOptions<\n TMiddlewares,\n TValidator,\n TServerContext,\n TClientContext,\n TServerFnResponseType\n >\n}\n\nexport interface MiddlewareAfterValidator<\n TMiddlewares,\n TValidator,\n TServerFnResponseType extends ServerFnResponseType,\n> extends MiddlewareWithTypes<\n TMiddlewares,\n TValidator,\n undefined,\n undefined,\n undefined,\n undefined,\n ServerFnResponseType\n >,\n MiddlewareServer<\n TMiddlewares,\n TValidator,\n undefined,\n undefined,\n TServerFnResponseType\n >,\n MiddlewareClient<TMiddlewares, TValidator, ServerFnResponseType> {}\n\nexport interface MiddlewareValidator<\n TMiddlewares,\n TServerFnResponseType extends ServerFnResponseType,\n> {\n validator: <TNewValidator>(\n input: ConstrainValidator<TNewValidator>,\n ) => MiddlewareAfterValidator<\n TMiddlewares,\n TNewValidator,\n TServerFnResponseType\n >\n}\n\nexport interface MiddlewareAfterServer<\n TMiddlewares,\n TValidator,\n TServerContext,\n TServerSendContext,\n TClientContext,\n TClientSendContext,\n TServerFnResponseType extends ServerFnResponseType,\n> extends MiddlewareWithTypes<\n TMiddlewares,\n TValidator,\n TServerContext,\n TServerSendContext,\n TClientContext,\n TClientSendContext,\n TServerFnResponseType\n > {}\n\nexport interface MiddlewareServer<\n TMiddlewares,\n TValidator,\n TServerSendContext,\n TClientContext,\n TServerFnResponseType extends ServerFnResponseType,\n> {\n server: <TNewServerContext = undefined, TSendContext = undefined>(\n server: MiddlewareServerFn<\n TMiddlewares,\n TValidator,\n TServerSendContext,\n TNewServerContext,\n TSendContext,\n TServerFnResponseType\n >,\n ) => MiddlewareAfterServer<\n TMiddlewares,\n TValidator,\n TNewServerContext,\n TServerSendContext,\n TClientContext,\n TSendContext,\n ServerFnResponseType\n >\n}\n\nexport interface MiddlewareAfterClient<\n TMiddlewares,\n TValidator,\n TServerSendContext,\n TClientContext,\n TServerFnResponseType extends ServerFnResponseType,\n> extends MiddlewareWithTypes<\n TMiddlewares,\n TValidator,\n undefined,\n TServerSendContext,\n TClientContext,\n undefined,\n TServerFnResponseType\n >,\n MiddlewareServer<\n TMiddlewares,\n TValidator,\n TServerSendContext,\n TClientContext,\n TServerFnResponseType\n > {}\n\nexport interface MiddlewareClient<\n TMiddlewares,\n TValidator,\n TServerFnResponseType extends ServerFnResponseType,\n> {\n client: <TSendServerContext = undefined, TNewClientContext = undefined>(\n client: MiddlewareClientFn<\n TMiddlewares,\n TValidator,\n TSendServerContext,\n TNewClientContext,\n TServerFnResponseType\n >,\n ) => MiddlewareAfterClient<\n TMiddlewares,\n TValidator,\n TSendServerContext,\n TNewClientContext,\n ServerFnResponseType\n >\n}\n\nexport interface MiddlewareAfterMiddleware<\n TMiddlewares,\n TServerFnResponseType extends ServerFnResponseType,\n> extends MiddlewareWithTypes<\n TMiddlewares,\n undefined,\n undefined,\n undefined,\n undefined,\n undefined,\n TServerFnResponseType\n >,\n MiddlewareServer<\n TMiddlewares,\n undefined,\n undefined,\n undefined,\n TServerFnResponseType\n >,\n MiddlewareClient<TMiddlewares, undefined, TServerFnResponseType>,\n MiddlewareValidator<TMiddlewares, TServerFnResponseType> {}\n\nexport interface Middleware<TServerFnResponseType extends ServerFnResponseType>\n extends MiddlewareAfterMiddleware<unknown, TServerFnResponseType> {\n middleware: <const TNewMiddlewares = undefined>(\n middlewares: Constrain<TNewMiddlewares, ReadonlyArray<AnyMiddleware>>,\n ) => MiddlewareAfterMiddleware<TNewMiddlewares, TServerFnResponseType>\n}\n\nexport function createMiddleware(\n options?: {\n validateClient?: boolean\n },\n __opts?: MiddlewareOptions<\n unknown,\n undefined,\n undefined,\n undefined,\n ServerFnResponseType\n >,\n): Middleware<ServerFnResponseType> {\n // const resolvedOptions = (__opts || options) as MiddlewareOptions<\n const resolvedOptions =\n __opts ||\n ((options || {}) as MiddlewareOptions<\n unknown,\n undefined,\n undefined,\n undefined,\n ServerFnResponseType\n >)\n\n return {\n options: resolvedOptions as any,\n middleware: (middleware: any) => {\n return createMiddleware(\n undefined,\n Object.assign(resolvedOptions, { middleware }),\n ) as any\n },\n validator: (validator: any) => {\n return createMiddleware(\n undefined,\n Object.assign(resolvedOptions, { validator }),\n ) as any\n },\n client: (client: any) => {\n return createMiddleware(\n undefined,\n Object.assign(resolvedOptions, { client }),\n ) as any\n },\n server: (server: any) => {\n return createMiddleware(\n undefined,\n Object.assign(resolvedOptions, { server }),\n ) as any\n },\n } as unknown as Middleware<ServerFnResponseType>\n}\n"],"names":[],"mappings":";;AAgiBgB,SAAA,iBACd,SAGA,QAOkC;AAE5B,QAAA,kBACJ,WACE,WAAW;AAQR,SAAA;AAAA,IACL,SAAS;AAAA,IACT,YAAY,CAAC,eAAoB;AACxB,aAAA;AAAA,QACL;AAAA,QACA,OAAO,OAAO,iBAAiB,EAAE,WAAY,CAAA;AAAA,MAC/C;AAAA,IACF;AAAA,IACA,WAAW,CAAC,cAAmB;AACtB,aAAA;AAAA,QACL;AAAA,QACA,OAAO,OAAO,iBAAiB,EAAE,UAAW,CAAA;AAAA,MAC9C;AAAA,IACF;AAAA,IACA,QAAQ,CAAC,WAAgB;AAChB,aAAA;AAAA,QACL;AAAA,QACA,OAAO,OAAO,iBAAiB,EAAE,OAAQ,CAAA;AAAA,MAC3C;AAAA,IACF;AAAA,IACA,QAAQ,CAAC,WAAgB;AAChB,aAAA;AAAA,QACL;AAAA,QACA,OAAO,OAAO,iBAAiB,EAAE,OAAQ,CAAA;AAAA,MAC3C;AAAA,IAAA;AAAA,EAEJ;AACF;;"}
1
+ {"version":3,"file":"createMiddleware.cjs","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;;"}
@@ -1,131 +1,175 @@
1
1
  import { ConstrainValidator, Method, ServerFnResponseType, ServerFnTypeOrTypeFn } from './createServerFn.cjs';
2
2
  import { Assign, Constrain, Expand, IntersectAssign, ResolveValidatorInput, ResolveValidatorOutput, SerializerStringify } from '@tanstack/router-core';
3
- export type AssignAllMiddleware<TMiddlewares, TType extends keyof AnyMiddleware['_types'], TAcc = undefined> = TMiddlewares extends readonly [
4
- infer TMiddleware extends AnyMiddleware,
5
- ...infer TRest
6
- ] ? AssignAllMiddleware<TRest, TType, Assign<TAcc, TMiddleware['_types'][TType]>> : TAcc;
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>>;
7
46
  /**
8
47
  * Recursively resolve the client context type produced by a sequence of middleware
9
48
  */
10
49
  export type AssignAllClientContextBeforeNext<TMiddlewares, TClientContext = undefined> = unknown extends TClientContext ? TClientContext : Assign<AssignAllMiddleware<TMiddlewares, 'allClientContextBeforeNext'>, TClientContext>;
11
- export type AssignAllClientSendContext<TMiddlewares, TSendContext = undefined> = unknown extends TSendContext ? TSendContext : Assign<AssignAllMiddleware<TMiddlewares, 'allClientSendContext'>, TSendContext>;
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;
12
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>;
13
53
  /**
14
54
  * Recursively resolve the server context type produced by a sequence of middleware
15
55
  */
16
56
  export type AssignAllServerContext<TMiddlewares, TSendContext = undefined, TServerContext = undefined> = unknown extends TSendContext ? Assign<TSendContext, TServerContext> : Assign<AssignAllMiddleware<TMiddlewares, 'allServerContext'>, Assign<TSendContext, TServerContext>>;
17
- export type AssignAllServerSendContext<TMiddlewares, TSendContext = undefined> = unknown extends TSendContext ? TSendContext : Assign<AssignAllMiddleware<TMiddlewares, 'allServerSendContext'>, TSendContext>;
18
- export type IntersectAllMiddleware<TMiddlewares, TType extends keyof AnyMiddleware['_types'], TAcc = undefined> = TMiddlewares extends readonly [
19
- infer TMiddleware extends AnyMiddleware,
20
- ...infer TRest
21
- ] ? IntersectAllMiddleware<TRest, TType, IntersectAssign<TAcc, TMiddleware['_types'][TType]>> : TAcc;
22
- /**
23
- * Recursively resolve the input type produced by a sequence of middleware
24
- */
25
- export type IntersectAllValidatorInputs<TMiddlewares, TValidator> = unknown extends TValidator ? TValidator : IntersectAssign<IntersectAllMiddleware<TMiddlewares, 'allInput'>, TValidator extends undefined ? undefined : ResolveValidatorInput<TValidator>>;
26
- /**
27
- * Recursively merge the output type produced by a sequence of middleware
28
- */
29
- export type IntersectAllValidatorOutputs<TMiddlewares, TValidator> = unknown extends TValidator ? TValidator : IntersectAssign<IntersectAllMiddleware<TMiddlewares, 'allOutput'>, TValidator extends undefined ? undefined : ResolveValidatorOutput<TValidator>>;
30
- export interface MiddlewareOptions<in out TMiddlewares, in out TValidator, in out TServerContext, in out TClientContext, in out TServerFnResponseType extends ServerFnResponseType> {
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> {
31
59
  validateClient?: boolean;
32
60
  middleware?: TMiddlewares;
33
61
  validator?: ConstrainValidator<TValidator>;
34
- client?: MiddlewareClientFn<TMiddlewares, TValidator, TServerContext, TClientContext, TServerFnResponseType>;
35
- server?: MiddlewareServerFn<TMiddlewares, TValidator, TServerContext, unknown, unknown, TServerFnResponseType>;
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>;
36
72
  }
37
- export type MiddlewareServerNextFn<TMiddlewares, TServerSendContext> = <TNewServerContext = undefined, TSendContext = undefined>(ctx?: {
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?: {
38
83
  context?: TNewServerContext;
39
84
  sendContext?: SerializerStringify<TSendContext>;
40
- }) => Promise<ServerResultWithContext<TMiddlewares, TServerSendContext, TNewServerContext, TSendContext>>;
41
- export interface MiddlewareServerFnOptions<in out TMiddlewares, in out TValidator, in out TServerSendContext, in out TServerFnResponseType> {
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> {
42
96
  data: Expand<IntersectAllValidatorOutputs<TMiddlewares, TValidator>>;
43
97
  context: Expand<AssignAllServerContext<TMiddlewares, TServerSendContext>>;
44
- next: MiddlewareServerNextFn<TMiddlewares, TServerSendContext>;
98
+ next: FunctionMiddlewareServerNextFn<TMiddlewares, TServerSendContext>;
45
99
  response: TServerFnResponseType;
46
100
  method: Method;
47
101
  filename: string;
48
102
  functionId: string;
49
103
  signal: AbortSignal;
50
104
  }
51
- export type MiddlewareServerFn<TMiddlewares, TValidator, TServerSendContext, TNewServerContext, TSendContext, TServerFnResponseType extends ServerFnResponseType> = (options: MiddlewareServerFnOptions<TMiddlewares, TValidator, TServerSendContext, TServerFnResponseType>) => MiddlewareServerFnResult<TMiddlewares, TServerSendContext, TNewServerContext, TSendContext>;
52
- export type MiddlewareServerFnResult<TMiddlewares, TServerSendContext, TServerContext, TSendContext> = Promise<ServerResultWithContext<TMiddlewares, TServerSendContext, TServerContext, TSendContext>> | ServerResultWithContext<TMiddlewares, TServerSendContext, TServerContext, TSendContext>;
53
- export type MiddlewareClientNextFn<TMiddlewares> = <TSendContext = undefined, TNewClientContext = undefined>(ctx?: {
54
- context?: TNewClientContext;
55
- sendContext?: SerializerStringify<TSendContext>;
56
- headers?: HeadersInit;
57
- }) => Promise<ClientResultWithContext<TMiddlewares, TSendContext, TNewClientContext>>;
58
- export interface MiddlewareClientFnOptions<in out TMiddlewares, in out TValidator, in out TServerFnResponseType extends ServerFnResponseType> {
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> {
59
113
  data: Expand<IntersectAllValidatorInputs<TMiddlewares, TValidator>>;
60
114
  context: Expand<AssignAllClientContextBeforeNext<TMiddlewares>>;
61
115
  sendContext: Expand<AssignAllServerSendContext<TMiddlewares>>;
62
116
  method: Method;
63
117
  response: TServerFnResponseType;
64
118
  signal: AbortSignal;
65
- next: MiddlewareClientNextFn<TMiddlewares>;
119
+ next: FunctionMiddlewareClientNextFn<TMiddlewares>;
66
120
  filename: string;
67
121
  functionId: string;
68
122
  type: ServerFnTypeOrTypeFn<Method, TServerFnResponseType, TMiddlewares, TValidator>;
69
123
  }
70
- export type MiddlewareClientFn<TMiddlewares, TValidator, TSendContext, TClientContext, TServerFnResponseType extends ServerFnResponseType> = (options: MiddlewareClientFnOptions<TMiddlewares, TValidator, TServerFnResponseType>) => MiddlewareClientFnResult<TMiddlewares, TSendContext, TClientContext>;
71
- export type MiddlewareClientFnResult<TMiddlewares, TSendContext, TClientContext> = Promise<ClientResultWithContext<TMiddlewares, TSendContext, TClientContext>> | ClientResultWithContext<TMiddlewares, TSendContext, TClientContext>;
72
- export type ServerResultWithContext<in out TMiddlewares, in out TServerSendContext, in out TServerContext, in out TSendContext> = {
73
- 'use functions must return the result of next()': true;
74
- _types: {
75
- context: TServerContext;
76
- sendContext: TSendContext;
77
- };
78
- context: Expand<AssignAllServerContext<TMiddlewares, TServerSendContext, TServerContext>>;
79
- sendContext: Expand<AssignAllClientSendContext<TMiddlewares, TSendContext>>;
80
- };
81
- export type ClientResultWithContext<in out TMiddlewares, in out TSendContext, in out TClientContext> = {
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> = {
82
126
  'use functions must return the result of next()': true;
83
127
  context: Expand<AssignAllClientContextAfterNext<TMiddlewares, TClientContext>>;
84
128
  sendContext: Expand<AssignAllServerSendContext<TMiddlewares, TSendContext>>;
85
129
  headers: HeadersInit;
86
130
  };
87
- export type AnyMiddleware = MiddlewareWithTypes<any, any, any, any, any, any, any>;
88
- export interface MiddlewareTypes<in out TMiddlewares, in out TValidator, in out TServerContext, in out TServerSendContext, in out TClientContext, in out TClientSendContext> {
89
- middlewares: TMiddlewares;
90
- input: ResolveValidatorInput<TValidator>;
91
- allInput: IntersectAllValidatorInputs<TMiddlewares, TValidator>;
92
- output: ResolveValidatorOutput<TValidator>;
93
- allOutput: IntersectAllValidatorOutputs<TMiddlewares, TValidator>;
94
- clientContext: TClientContext;
95
- allClientContextBeforeNext: AssignAllClientContextBeforeNext<TMiddlewares, TClientContext>;
96
- allClientContextAfterNext: AssignAllClientContextAfterNext<TMiddlewares, TClientContext, TClientSendContext>;
97
- serverContext: TServerContext;
98
- serverSendContext: TServerSendContext;
99
- allServerSendContext: AssignAllServerSendContext<TMiddlewares, TServerSendContext>;
100
- allServerContext: AssignAllServerContext<TMiddlewares, TServerSendContext, TServerContext>;
101
- clientSendContext: TClientSendContext;
102
- allClientSendContext: AssignAllClientSendContext<TMiddlewares, TClientSendContext>;
103
- validator: TValidator;
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> {
104
132
  }
105
- export interface MiddlewareWithTypes<TMiddlewares, TValidator, TServerContext, TServerSendContext, TClientContext, TClientSendContext, TServerFnResponseType extends ServerFnResponseType> {
106
- _types: MiddlewareTypes<TMiddlewares, TValidator, TServerContext, TServerSendContext, TClientContext, TClientSendContext>;
107
- options: MiddlewareOptions<TMiddlewares, TValidator, TServerContext, TClientContext, TServerFnResponseType>;
133
+ export interface FunctionMiddlewareValidator<TMiddlewares, TServerFnResponseType extends ServerFnResponseType> {
134
+ validator: <TNewValidator>(input: ConstrainValidator<TNewValidator>) => FunctionMiddlewareAfterValidator<TMiddlewares, TNewValidator, TServerFnResponseType>;
108
135
  }
109
- export interface MiddlewareAfterValidator<TMiddlewares, TValidator, TServerFnResponseType extends ServerFnResponseType> extends MiddlewareWithTypes<TMiddlewares, TValidator, undefined, undefined, undefined, undefined, ServerFnResponseType>, MiddlewareServer<TMiddlewares, TValidator, undefined, undefined, TServerFnResponseType>, MiddlewareClient<TMiddlewares, TValidator, ServerFnResponseType> {
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> {
110
137
  }
111
- export interface MiddlewareValidator<TMiddlewares, TServerFnResponseType extends ServerFnResponseType> {
112
- validator: <TNewValidator>(input: ConstrainValidator<TNewValidator>) => MiddlewareAfterValidator<TMiddlewares, TNewValidator, TServerFnResponseType>;
138
+ export interface RequestMiddleware extends RequestMiddlewareAfterMiddleware<undefined> {
139
+ middleware: <const TMiddlewares = undefined>(middlewares: Constrain<TMiddlewares, ReadonlyArray<AnyRequestMiddleware>>) => RequestMiddlewareAfterMiddleware<TMiddlewares>;
113
140
  }
114
- export interface MiddlewareAfterServer<TMiddlewares, TValidator, TServerContext, TServerSendContext, TClientContext, TClientSendContext, TServerFnResponseType extends ServerFnResponseType> extends MiddlewareWithTypes<TMiddlewares, TValidator, TServerContext, TServerSendContext, TClientContext, TClientSendContext, TServerFnResponseType> {
141
+ export type AnyRequestMiddleware = RequestMiddlewareWithTypes<any, any>;
142
+ export interface RequestMiddlewareWithTypes<TMiddlewares, TServerContext> {
143
+ _types: RequestMiddlewareTypes<TMiddlewares, TServerContext>;
115
144
  }
116
- export interface MiddlewareServer<TMiddlewares, TValidator, TServerSendContext, TClientContext, TServerFnResponseType extends ServerFnResponseType> {
117
- server: <TNewServerContext = undefined, TSendContext = undefined>(server: MiddlewareServerFn<TMiddlewares, TValidator, TServerSendContext, TNewServerContext, TSendContext, TServerFnResponseType>) => MiddlewareAfterServer<TMiddlewares, TValidator, TNewServerContext, TServerSendContext, TClientContext, TSendContext, ServerFnResponseType>;
145
+ export interface RequestMiddlewareTypes<TMiddlewares, TServerContext> {
146
+ type: 'request';
147
+ middlewares: TMiddlewares;
148
+ serverContext: TServerContext;
149
+ allServerContext: AssignAllServerContext<TMiddlewares, undefined, TServerContext>;
118
150
  }
119
- export interface MiddlewareAfterClient<TMiddlewares, TValidator, TServerSendContext, TClientContext, TServerFnResponseType extends ServerFnResponseType> extends MiddlewareWithTypes<TMiddlewares, TValidator, undefined, TServerSendContext, TClientContext, undefined, TServerFnResponseType>, MiddlewareServer<TMiddlewares, TValidator, TServerSendContext, TClientContext, TServerFnResponseType> {
151
+ export interface RequestMiddlewareAfterMiddleware<TMiddlewares> extends RequestMiddlewareWithTypes<TMiddlewares, undefined>, RequestMiddlewareServer<TMiddlewares> {
120
152
  }
121
- export interface MiddlewareClient<TMiddlewares, TValidator, TServerFnResponseType extends ServerFnResponseType> {
122
- client: <TSendServerContext = undefined, TNewClientContext = undefined>(client: MiddlewareClientFn<TMiddlewares, TValidator, TSendServerContext, TNewClientContext, TServerFnResponseType>) => MiddlewareAfterClient<TMiddlewares, TValidator, TSendServerContext, TNewClientContext, ServerFnResponseType>;
153
+ export interface RequestMiddlewareServer<TMiddlewares> {
154
+ server: <TServerContext = undefined>(fn: RequestServerFn<TMiddlewares, TServerContext>) => RequestMiddlewareAfterServer<TMiddlewares, TServerContext>;
123
155
  }
124
- export interface MiddlewareAfterMiddleware<TMiddlewares, TServerFnResponseType extends ServerFnResponseType> extends MiddlewareWithTypes<TMiddlewares, undefined, undefined, undefined, undefined, undefined, TServerFnResponseType>, MiddlewareServer<TMiddlewares, undefined, undefined, undefined, TServerFnResponseType>, MiddlewareClient<TMiddlewares, undefined, TServerFnResponseType>, MiddlewareValidator<TMiddlewares, TServerFnResponseType> {
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>;
125
162
  }
126
- export interface Middleware<TServerFnResponseType extends ServerFnResponseType> extends MiddlewareAfterMiddleware<unknown, TServerFnResponseType> {
127
- middleware: <const TNewMiddlewares = undefined>(middlewares: Constrain<TNewMiddlewares, ReadonlyArray<AnyMiddleware>>) => MiddlewareAfterMiddleware<TNewMiddlewares, TServerFnResponseType>;
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> {
128
175
  }
129
- export declare function createMiddleware(options?: {
130
- validateClient?: boolean;
131
- }, __opts?: MiddlewareOptions<unknown, undefined, undefined, undefined, ServerFnResponseType>): Middleware<ServerFnResponseType>;
@@ -370,6 +370,7 @@ exports.applyMiddleware = applyMiddleware;
370
370
  exports.createServerFn = createServerFn;
371
371
  exports.createServerFnStaticCache = createServerFnStaticCache;
372
372
  exports.execValidator = execValidator;
373
+ exports.executeMiddleware = executeMiddleware;
373
374
  exports.extractFormDataContext = extractFormDataContext;
374
375
  exports.flattenMiddlewares = flattenMiddlewares;
375
376
  exports.serverFnBaseToMiddleware = serverFnBaseToMiddleware;