@tanstack/start-client-core 1.114.4 → 1.114.5

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 (62) hide show
  1. package/dist/cjs/createIsomorphicFn.cjs +7 -0
  2. package/dist/cjs/createIsomorphicFn.cjs.map +1 -0
  3. package/dist/cjs/createIsomorphicFn.d.cts +12 -0
  4. package/dist/cjs/createMiddleware.cjs +34 -0
  5. package/dist/cjs/createMiddleware.cjs.map +1 -0
  6. package/dist/cjs/createMiddleware.d.cts +131 -0
  7. package/dist/cjs/createServerFn.cjs +227 -0
  8. package/dist/cjs/createServerFn.cjs.map +1 -0
  9. package/dist/cjs/createServerFn.d.cts +152 -0
  10. package/dist/cjs/envOnly.cjs +7 -0
  11. package/dist/cjs/envOnly.cjs.map +1 -0
  12. package/dist/cjs/envOnly.d.cts +4 -0
  13. package/dist/cjs/index.cjs +22 -0
  14. package/dist/cjs/index.cjs.map +1 -1
  15. package/dist/cjs/index.d.cts +8 -0
  16. package/dist/cjs/json.cjs +14 -0
  17. package/dist/cjs/json.cjs.map +1 -0
  18. package/dist/cjs/json.d.cts +2 -0
  19. package/dist/cjs/registerGlobalMiddleware.cjs +9 -0
  20. package/dist/cjs/registerGlobalMiddleware.cjs.map +1 -0
  21. package/dist/cjs/registerGlobalMiddleware.d.cts +5 -0
  22. package/dist/cjs/tests/createIsomorphicFn.test-d.d.cts +1 -0
  23. package/dist/cjs/tests/createServerMiddleware.test-d.d.cts +1 -0
  24. package/dist/cjs/tests/envOnly.test-d.d.cts +1 -0
  25. package/dist/cjs/tests/json.test.d.cts +1 -0
  26. package/dist/esm/createIsomorphicFn.d.ts +12 -0
  27. package/dist/esm/createIsomorphicFn.js +7 -0
  28. package/dist/esm/createIsomorphicFn.js.map +1 -0
  29. package/dist/esm/createMiddleware.d.ts +131 -0
  30. package/dist/esm/createMiddleware.js +34 -0
  31. package/dist/esm/createMiddleware.js.map +1 -0
  32. package/dist/esm/createServerFn.d.ts +152 -0
  33. package/dist/esm/createServerFn.js +206 -0
  34. package/dist/esm/createServerFn.js.map +1 -0
  35. package/dist/esm/envOnly.d.ts +4 -0
  36. package/dist/esm/envOnly.js +7 -0
  37. package/dist/esm/envOnly.js.map +1 -0
  38. package/dist/esm/index.d.ts +8 -0
  39. package/dist/esm/index.js +19 -0
  40. package/dist/esm/index.js.map +1 -1
  41. package/dist/esm/json.d.ts +2 -0
  42. package/dist/esm/json.js +14 -0
  43. package/dist/esm/json.js.map +1 -0
  44. package/dist/esm/registerGlobalMiddleware.d.ts +5 -0
  45. package/dist/esm/registerGlobalMiddleware.js +9 -0
  46. package/dist/esm/registerGlobalMiddleware.js.map +1 -0
  47. package/dist/esm/tests/createIsomorphicFn.test-d.d.ts +1 -0
  48. package/dist/esm/tests/createServerMiddleware.test-d.d.ts +1 -0
  49. package/dist/esm/tests/envOnly.test-d.d.ts +1 -0
  50. package/dist/esm/tests/json.test.d.ts +1 -0
  51. package/package.json +2 -1
  52. package/src/createIsomorphicFn.ts +36 -0
  53. package/src/createMiddleware.ts +595 -0
  54. package/src/createServerFn.ts +700 -0
  55. package/src/envOnly.ts +9 -0
  56. package/src/index.tsx +73 -0
  57. package/src/json.ts +15 -0
  58. package/src/registerGlobalMiddleware.ts +9 -0
  59. package/src/tests/createIsomorphicFn.test-d.ts +72 -0
  60. package/src/tests/createServerMiddleware.test-d.ts +611 -0
  61. package/src/tests/envOnly.test-d.ts +34 -0
  62. package/src/tests/json.test.ts +37 -0
@@ -0,0 +1,152 @@
1
+ import { Readable } from 'node:stream';
2
+ import { AnyValidator, Constrain, Expand, ResolveValidatorInput, SerializerParse, SerializerStringify, SerializerStringifyBy, Validator } from '@tanstack/router-core';
3
+ import { AnyMiddleware, AssignAllClientSendContext, AssignAllServerContext, IntersectAllValidatorInputs, IntersectAllValidatorOutputs } from './createMiddleware.cjs';
4
+ export interface JsonResponse<TData> extends Response {
5
+ json: () => Promise<TData>;
6
+ }
7
+ export type CompiledFetcherFnOptions = {
8
+ method: Method;
9
+ data: unknown;
10
+ response?: ServerFnResponseType;
11
+ headers?: HeadersInit;
12
+ signal?: AbortSignal;
13
+ context?: any;
14
+ };
15
+ export type Fetcher<TMiddlewares, TValidator, TResponse, TServerFnResponseType extends ServerFnResponseType> = undefined extends IntersectAllValidatorInputs<TMiddlewares, TValidator> ? OptionalFetcher<TMiddlewares, TValidator, TResponse, TServerFnResponseType> : RequiredFetcher<TMiddlewares, TValidator, TResponse, TServerFnResponseType>;
16
+ export interface FetcherBase {
17
+ url: string;
18
+ __executeServer: (opts: {
19
+ method: Method;
20
+ response?: ServerFnResponseType;
21
+ data: unknown;
22
+ headers?: HeadersInit;
23
+ context?: any;
24
+ signal: AbortSignal;
25
+ }) => Promise<unknown>;
26
+ }
27
+ export type FetchResult<TMiddlewares, TResponse, TServerFnResponseType extends ServerFnResponseType> = TServerFnResponseType extends 'raw' ? Promise<Response> : TServerFnResponseType extends 'full' ? Promise<FullFetcherData<TMiddlewares, TResponse>> : Promise<FetcherData<TResponse>>;
28
+ export interface OptionalFetcher<TMiddlewares, TValidator, TResponse, TServerFnResponseType extends ServerFnResponseType> extends FetcherBase {
29
+ (options?: OptionalFetcherDataOptions<TMiddlewares, TValidator>): FetchResult<TMiddlewares, TResponse, TServerFnResponseType>;
30
+ }
31
+ export interface RequiredFetcher<TMiddlewares, TValidator, TResponse, TServerFnResponseType extends ServerFnResponseType> extends FetcherBase {
32
+ (opts: RequiredFetcherDataOptions<TMiddlewares, TValidator>): FetchResult<TMiddlewares, TResponse, TServerFnResponseType>;
33
+ }
34
+ export type FetcherBaseOptions = {
35
+ headers?: HeadersInit;
36
+ type?: ServerFnType;
37
+ signal?: AbortSignal;
38
+ };
39
+ export type ServerFnType = 'static' | 'dynamic';
40
+ export interface OptionalFetcherDataOptions<TMiddlewares, TValidator> extends FetcherBaseOptions {
41
+ data?: Expand<IntersectAllValidatorInputs<TMiddlewares, TValidator>>;
42
+ }
43
+ export interface RequiredFetcherDataOptions<TMiddlewares, TValidator> extends FetcherBaseOptions {
44
+ data: Expand<IntersectAllValidatorInputs<TMiddlewares, TValidator>>;
45
+ }
46
+ export interface FullFetcherData<TMiddlewares, TResponse> {
47
+ error: unknown;
48
+ result: FetcherData<TResponse>;
49
+ context: AssignAllClientSendContext<TMiddlewares>;
50
+ }
51
+ export type FetcherData<TResponse> = TResponse extends JsonResponse<any> ? SerializerParse<ReturnType<TResponse['json']>> : SerializerParse<TResponse>;
52
+ export type RscStream<T> = {
53
+ __cacheState: T;
54
+ };
55
+ export type Method = 'GET' | 'POST';
56
+ export type ServerFnResponseType = 'data' | 'full' | 'raw';
57
+ export type RawResponse = Response | ReadableStream | Readable | null | string;
58
+ export type ServerFnReturnType<TServerFnResponseType extends ServerFnResponseType, TResponse> = TServerFnResponseType extends 'raw' ? RawResponse | Promise<RawResponse> : Promise<SerializerStringify<TResponse>> | SerializerStringify<TResponse>;
59
+ export type ServerFn<TMethod, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator, TResponse> = (ctx: ServerFnCtx<TMethod, TServerFnResponseType, TMiddlewares, TValidator>) => ServerFnReturnType<TServerFnResponseType, TResponse>;
60
+ export interface ServerFnCtx<TMethod, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> {
61
+ method: TMethod;
62
+ response: TServerFnResponseType;
63
+ data: Expand<IntersectAllValidatorOutputs<TMiddlewares, TValidator>>;
64
+ context: Expand<AssignAllServerContext<TMiddlewares>>;
65
+ signal: AbortSignal;
66
+ }
67
+ export type CompiledFetcherFn<TResponse, TServerFnResponseType extends ServerFnResponseType> = {
68
+ (opts: CompiledFetcherFnOptions & ServerFnBaseOptions<Method, TServerFnResponseType>): Promise<TResponse>;
69
+ url: string;
70
+ };
71
+ export type ServerFnBaseOptions<TMethod extends Method = 'GET', TServerFnResponseType extends ServerFnResponseType = 'data', TResponse = unknown, TMiddlewares = unknown, TInput = unknown> = {
72
+ method: TMethod;
73
+ response?: TServerFnResponseType;
74
+ validateClient?: boolean;
75
+ middleware?: Constrain<TMiddlewares, ReadonlyArray<AnyMiddleware>>;
76
+ validator?: ConstrainValidator<TInput>;
77
+ extractedFn?: CompiledFetcherFn<TResponse, TServerFnResponseType>;
78
+ serverFn?: ServerFn<TMethod, TServerFnResponseType, TMiddlewares, TInput, TResponse>;
79
+ functionId: string;
80
+ type: ServerFnTypeOrTypeFn<TMethod, TServerFnResponseType, TMiddlewares, AnyValidator>;
81
+ };
82
+ export type ValidatorSerializerStringify<TValidator> = Validator<SerializerStringifyBy<ResolveValidatorInput<TValidator>, Date | undefined | FormData>, any>;
83
+ export type ConstrainValidator<TValidator> = unknown extends TValidator ? TValidator : Constrain<TValidator, ValidatorSerializerStringify<TValidator>>;
84
+ export interface ServerFnMiddleware<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TValidator> {
85
+ middleware: <const TNewMiddlewares = undefined>(middlewares: Constrain<TNewMiddlewares, ReadonlyArray<AnyMiddleware>>) => ServerFnAfterMiddleware<TMethod, TServerFnResponseType, TNewMiddlewares, TValidator>;
86
+ }
87
+ export interface ServerFnAfterMiddleware<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> extends ServerFnValidator<TMethod, TServerFnResponseType, TMiddlewares>, ServerFnTyper<TMethod, TServerFnResponseType, TMiddlewares, TValidator>, ServerFnHandler<TMethod, TServerFnResponseType, TMiddlewares, TValidator> {
88
+ }
89
+ export type ValidatorFn<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares> = <TValidator>(validator: ConstrainValidator<TValidator>) => ServerFnAfterValidator<TMethod, TServerFnResponseType, TMiddlewares, TValidator>;
90
+ export interface ServerFnValidator<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares> {
91
+ validator: ValidatorFn<TMethod, TServerFnResponseType, TMiddlewares>;
92
+ }
93
+ export interface ServerFnAfterValidator<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> extends ServerFnMiddleware<TMethod, TServerFnResponseType, TValidator>, ServerFnTyper<TMethod, TServerFnResponseType, TMiddlewares, TValidator>, ServerFnHandler<TMethod, TServerFnResponseType, TMiddlewares, TValidator> {
94
+ }
95
+ export interface ServerFnTyper<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> {
96
+ type: (typer: ServerFnTypeOrTypeFn<TMethod, TServerFnResponseType, TMiddlewares, TValidator>) => ServerFnAfterTyper<TMethod, TServerFnResponseType, TMiddlewares, TValidator>;
97
+ }
98
+ export type ServerFnTypeOrTypeFn<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> = ServerFnType | ((ctx: ServerFnCtx<TMethod, TServerFnResponseType, TMiddlewares, TValidator>) => ServerFnType);
99
+ export interface ServerFnAfterTyper<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> extends ServerFnHandler<TMethod, TServerFnResponseType, TMiddlewares, TValidator> {
100
+ }
101
+ export interface ServerFnHandler<TMethod extends Method, TServerFnResponseType extends ServerFnResponseType, TMiddlewares, TValidator> {
102
+ handler: <TNewResponse>(fn?: ServerFn<TMethod, TServerFnResponseType, TMiddlewares, TValidator, TNewResponse>) => Fetcher<TMiddlewares, TValidator, TNewResponse, TServerFnResponseType>;
103
+ }
104
+ export interface ServerFnBuilder<TMethod extends Method = 'GET', TServerFnResponseType extends ServerFnResponseType = 'data'> extends ServerFnMiddleware<TMethod, TServerFnResponseType, undefined>, ServerFnValidator<TMethod, TServerFnResponseType, undefined>, ServerFnTyper<TMethod, TServerFnResponseType, undefined, undefined>, ServerFnHandler<TMethod, TServerFnResponseType, undefined, undefined> {
105
+ options: ServerFnBaseOptions<TMethod, TServerFnResponseType, unknown, undefined, undefined>;
106
+ }
107
+ export type StaticCachedResult = {
108
+ ctx?: {
109
+ result: any;
110
+ context: any;
111
+ };
112
+ error?: any;
113
+ };
114
+ export type ServerFnStaticCache = {
115
+ getItem: (ctx: ServerFnMiddlewareResult) => StaticCachedResult | Promise<StaticCachedResult | undefined>;
116
+ setItem: (ctx: ServerFnMiddlewareResult, response: StaticCachedResult) => Promise<void>;
117
+ fetchItem: (ctx: ServerFnMiddlewareResult) => StaticCachedResult | Promise<StaticCachedResult | undefined>;
118
+ };
119
+ export declare let serverFnStaticCache: ServerFnStaticCache | undefined;
120
+ export declare function setServerFnStaticCache(cache?: ServerFnStaticCache | (() => ServerFnStaticCache | undefined)): () => void;
121
+ export declare function createServerFnStaticCache(serverFnStaticCache: ServerFnStaticCache): ServerFnStaticCache;
122
+ export declare function extractFormDataContext(formData: FormData): {
123
+ context: unknown;
124
+ data: FormData;
125
+ } | {
126
+ data: FormData;
127
+ context?: undefined;
128
+ };
129
+ export declare function flattenMiddlewares(middlewares: Array<AnyMiddleware>): Array<AnyMiddleware>;
130
+ export type ServerFnMiddlewareOptions = {
131
+ method: Method;
132
+ response?: ServerFnResponseType;
133
+ data: any;
134
+ headers?: HeadersInit;
135
+ signal?: AbortSignal;
136
+ sendContext?: any;
137
+ context?: any;
138
+ type: ServerFnTypeOrTypeFn<any, any, any, any>;
139
+ functionId: string;
140
+ };
141
+ export type ServerFnMiddlewareResult = ServerFnMiddlewareOptions & {
142
+ result?: unknown;
143
+ error?: unknown;
144
+ type: ServerFnTypeOrTypeFn<any, any, any, any>;
145
+ };
146
+ export type NextFn = (ctx: ServerFnMiddlewareResult) => Promise<ServerFnMiddlewareResult>;
147
+ export type MiddlewareFn = (ctx: ServerFnMiddlewareOptions & {
148
+ next: NextFn;
149
+ }) => Promise<ServerFnMiddlewareResult>;
150
+ export declare const applyMiddleware: (middlewareFn: MiddlewareFn, ctx: ServerFnMiddlewareOptions, nextFn: NextFn) => Promise<ServerFnMiddlewareResult>;
151
+ export declare function execValidator(validator: AnyValidator, input: unknown): unknown;
152
+ export declare function serverFnBaseToMiddleware(options: ServerFnBaseOptions<any, any, any, any, any>): AnyMiddleware;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const serverOnly = (fn) => fn;
4
+ const clientOnly = (fn) => fn;
5
+ exports.clientOnly = clientOnly;
6
+ exports.serverOnly = serverOnly;
7
+ //# sourceMappingURL=envOnly.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envOnly.cjs","sources":["../../src/envOnly.ts"],"sourcesContent":["type EnvOnlyFn = <TFn extends (...args: Array<any>) => any>(fn: TFn) => TFn\n\n// A function that will only be available in the server build\n// If called on the client, it will throw an error\nexport const serverOnly: EnvOnlyFn = (fn) => fn\n\n// A function that will only be available in the client build\n// If called on the server, it will throw an error\nexport const clientOnly: EnvOnlyFn = (fn) => fn\n"],"names":[],"mappings":";;AAIa,MAAA,aAAwB,CAAC,OAAO;AAIhC,MAAA,aAAwB,CAAC,OAAO;;;"}
@@ -0,0 +1,4 @@
1
+ type EnvOnlyFn = <TFn extends (...args: Array<any>) => any>(fn: TFn) => TFn;
2
+ export declare const serverOnly: EnvOnlyFn;
3
+ export declare const clientOnly: EnvOnlyFn;
4
+ export {};
@@ -3,7 +3,29 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const headers = require("./headers.cjs");
4
4
  const serializer = require("./serializer.cjs");
5
5
  const ssrClient = require("./ssr-client.cjs");
6
+ const createIsomorphicFn = require("./createIsomorphicFn.cjs");
7
+ const envOnly = require("./envOnly.cjs");
8
+ const json = require("./json.cjs");
9
+ const createMiddleware = require("./createMiddleware.cjs");
10
+ const registerGlobalMiddleware = require("./registerGlobalMiddleware.cjs");
11
+ const createServerFn = require("./createServerFn.cjs");
6
12
  exports.mergeHeaders = headers.mergeHeaders;
7
13
  exports.startSerializer = serializer.startSerializer;
8
14
  exports.hydrate = ssrClient.hydrate;
15
+ exports.createIsomorphicFn = createIsomorphicFn.createIsomorphicFn;
16
+ exports.clientOnly = envOnly.clientOnly;
17
+ exports.serverOnly = envOnly.serverOnly;
18
+ exports.json = json.json;
19
+ exports.createMiddleware = createMiddleware.createMiddleware;
20
+ exports.globalMiddleware = registerGlobalMiddleware.globalMiddleware;
21
+ exports.registerGlobalMiddleware = registerGlobalMiddleware.registerGlobalMiddleware;
22
+ exports.applyMiddleware = createServerFn.applyMiddleware;
23
+ exports.execValidator = createServerFn.execValidator;
24
+ exports.extractFormDataContext = createServerFn.extractFormDataContext;
25
+ exports.flattenMiddlewares = createServerFn.flattenMiddlewares;
26
+ exports.serverFnBaseToMiddleware = createServerFn.serverFnBaseToMiddleware;
27
+ Object.defineProperty(exports, "serverFnStaticCache", {
28
+ enumerable: true,
29
+ get: () => createServerFn.serverFnStaticCache
30
+ });
9
31
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,3 +1,11 @@
1
1
  export { mergeHeaders } from './headers.cjs';
2
2
  export { startSerializer } from './serializer.cjs';
3
3
  export { type DehydratedRouter, type ClientExtractedBaseEntry, type StartSsrGlobal, type ClientExtractedEntry, type SsrMatch, type ClientExtractedPromise, type ClientExtractedStream, type ResolvePromiseState, hydrate, } from './ssr-client.cjs';
4
+ export { createIsomorphicFn, type IsomorphicFn, type ServerOnlyFn, type ClientOnlyFn, type IsomorphicFnBase, } from './createIsomorphicFn.cjs';
5
+ export { serverOnly, clientOnly } from './envOnly.cjs';
6
+ export { type JsonResponse } from './createServerFn.cjs';
7
+ export { json } from './json.cjs';
8
+ export { createMiddleware, type IntersectAllValidatorInputs, type IntersectAllValidatorOutputs, type MiddlewareServerFn, type AnyMiddleware, type MiddlewareOptions, type MiddlewareWithTypes, type MiddlewareValidator, type MiddlewareServer, type MiddlewareAfterClient, type MiddlewareAfterMiddleware, type MiddlewareAfterServer, type Middleware, type MiddlewareClientFnOptions, type MiddlewareClientFnResult, type MiddlewareClientNextFn, type ClientResultWithContext, type AssignAllClientContextBeforeNext, type AssignAllMiddleware, type AssignAllServerContext, type MiddlewareAfterValidator, type MiddlewareClientFn, type MiddlewareServerFnResult, type MiddlewareClient, type MiddlewareServerFnOptions, type MiddlewareServerNextFn, type ServerResultWithContext, } from './createMiddleware.cjs';
9
+ export { registerGlobalMiddleware, globalMiddleware, } from './registerGlobalMiddleware.cjs';
10
+ export type { ServerFn as FetchFn, ServerFnCtx as FetchFnCtx, CompiledFetcherFnOptions, CompiledFetcherFn, Fetcher, RscStream, FetcherData, FetcherBaseOptions, ServerFn, ServerFnCtx, ServerFnResponseType, MiddlewareFn, ServerFnMiddlewareOptions, ServerFnMiddlewareResult, ServerFnBuilder, ServerFnType, ServerFnBaseOptions, NextFn, Method, StaticCachedResult, } from './createServerFn.cjs';
11
+ export { applyMiddleware, execValidator, serverFnBaseToMiddleware, extractFormDataContext, flattenMiddlewares, serverFnStaticCache, } from './createServerFn.cjs';
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const headers = require("./headers.cjs");
4
+ function json(payload, init) {
5
+ return new Response(JSON.stringify(payload), {
6
+ ...init,
7
+ headers: headers.mergeHeaders(
8
+ { "content-type": "application/json" },
9
+ init == null ? void 0 : init.headers
10
+ )
11
+ });
12
+ }
13
+ exports.json = json;
14
+ //# sourceMappingURL=json.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json.cjs","sources":["../../src/json.ts"],"sourcesContent":["import { mergeHeaders } from './headers'\nimport type { JsonResponse } from './createServerFn'\n\nexport function json<TData>(\n payload: TData,\n init?: ResponseInit,\n): JsonResponse<TData> {\n return new Response(JSON.stringify(payload), {\n ...init,\n headers: mergeHeaders(\n { 'content-type': 'application/json' },\n init?.headers,\n ),\n })\n}\n"],"names":["mergeHeaders"],"mappings":";;;AAGgB,SAAA,KACd,SACA,MACqB;AACrB,SAAO,IAAI,SAAS,KAAK,UAAU,OAAO,GAAG;AAAA,IAC3C,GAAG;AAAA,IACH,SAASA,QAAA;AAAA,MACP,EAAE,gBAAgB,mBAAmB;AAAA,MACrC,6BAAM;AAAA,IAAA;AAAA,EACR,CACD;AACH;;"}
@@ -0,0 +1,2 @@
1
+ import { JsonResponse } from './createServerFn.cjs';
2
+ export declare function json<TData>(payload: TData, init?: ResponseInit): JsonResponse<TData>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const globalMiddleware = [];
4
+ function registerGlobalMiddleware(options) {
5
+ globalMiddleware.push(...options.middleware);
6
+ }
7
+ exports.globalMiddleware = globalMiddleware;
8
+ exports.registerGlobalMiddleware = registerGlobalMiddleware;
9
+ //# sourceMappingURL=registerGlobalMiddleware.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registerGlobalMiddleware.cjs","sources":["../../src/registerGlobalMiddleware.ts"],"sourcesContent":["import type { AnyMiddleware } from './createMiddleware'\n\nexport const globalMiddleware: Array<AnyMiddleware> = []\n\nexport function registerGlobalMiddleware(options: {\n middleware: Array<AnyMiddleware>\n}) {\n globalMiddleware.push(...options.middleware)\n}\n"],"names":[],"mappings":";;AAEO,MAAM,mBAAyC,CAAA;AAE/C,SAAS,yBAAyB,SAEtC;AACgB,mBAAA,KAAK,GAAG,QAAQ,UAAU;AAC7C;;;"}
@@ -0,0 +1,5 @@
1
+ import { AnyMiddleware } from './createMiddleware.cjs';
2
+ export declare const globalMiddleware: Array<AnyMiddleware>;
3
+ export declare function registerGlobalMiddleware(options: {
4
+ middleware: Array<AnyMiddleware>;
5
+ }): void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ export type IsomorphicFn<TArgs extends Array<any> = [], TServer = undefined, TClient = undefined> = (...args: TArgs) => TServer | TClient;
2
+ export interface ServerOnlyFn<TArgs extends Array<any>, TServer> extends IsomorphicFn<TArgs, TServer> {
3
+ client: <TClient>(clientImpl: (...args: TArgs) => TClient) => IsomorphicFn<TArgs, TServer, TClient>;
4
+ }
5
+ export interface ClientOnlyFn<TArgs extends Array<any>, TClient> extends IsomorphicFn<TArgs, undefined, TClient> {
6
+ server: <TServer>(serverImpl: (...args: TArgs) => TServer) => IsomorphicFn<TArgs, TServer, TClient>;
7
+ }
8
+ export interface IsomorphicFnBase extends IsomorphicFn {
9
+ server: <TArgs extends Array<any>, TServer>(serverImpl: (...args: TArgs) => TServer) => ServerOnlyFn<TArgs, TServer>;
10
+ client: <TArgs extends Array<any>, TClient>(clientImpl: (...args: TArgs) => TClient) => ClientOnlyFn<TArgs, TClient>;
11
+ }
12
+ export declare function createIsomorphicFn(): IsomorphicFnBase;
@@ -0,0 +1,7 @@
1
+ function createIsomorphicFn() {
2
+ return null;
3
+ }
4
+ export {
5
+ createIsomorphicFn
6
+ };
7
+ //# sourceMappingURL=createIsomorphicFn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createIsomorphicFn.js","sources":["../../src/createIsomorphicFn.ts"],"sourcesContent":["// a function that can have different implementations on the client and server.\n// implementations not provided will default to a no-op function.\n\nexport type IsomorphicFn<\n TArgs extends Array<any> = [],\n TServer = undefined,\n TClient = undefined,\n> = (...args: TArgs) => TServer | TClient\n\nexport interface ServerOnlyFn<TArgs extends Array<any>, TServer>\n extends IsomorphicFn<TArgs, TServer> {\n client: <TClient>(\n clientImpl: (...args: TArgs) => TClient,\n ) => IsomorphicFn<TArgs, TServer, TClient>\n}\n\nexport interface ClientOnlyFn<TArgs extends Array<any>, TClient>\n extends IsomorphicFn<TArgs, undefined, TClient> {\n server: <TServer>(\n serverImpl: (...args: TArgs) => TServer,\n ) => IsomorphicFn<TArgs, TServer, TClient>\n}\n\nexport interface IsomorphicFnBase extends IsomorphicFn {\n server: <TArgs extends Array<any>, TServer>(\n serverImpl: (...args: TArgs) => TServer,\n ) => ServerOnlyFn<TArgs, TServer>\n client: <TArgs extends Array<any>, TClient>(\n clientImpl: (...args: TArgs) => TClient,\n ) => ClientOnlyFn<TArgs, TClient>\n}\n\n// this is a dummy function, it will be replaced by the transformer\nexport function createIsomorphicFn(): IsomorphicFnBase {\n return null!\n}\n"],"names":[],"mappings":"AAiCO,SAAS,qBAAuC;AAC9C,SAAA;AACT;"}
@@ -0,0 +1,131 @@
1
+ import { ConstrainValidator, Method, ServerFnResponseType, ServerFnTypeOrTypeFn } from './createServerFn.js';
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;
7
+ /**
8
+ * Recursively resolve the client context type produced by a sequence of middleware
9
+ */
10
+ 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>;
12
+ export type AssignAllClientContextAfterNext<TMiddlewares, TClientContext = undefined, TSendContext = undefined> = unknown extends TClientContext ? Assign<TClientContext, TSendContext> : Assign<AssignAllMiddleware<TMiddlewares, 'allClientContextAfterNext'>, Assign<TClientContext, TSendContext>>;
13
+ /**
14
+ * Recursively resolve the server context type produced by a sequence of middleware
15
+ */
16
+ 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> {
31
+ validateClient?: boolean;
32
+ middleware?: TMiddlewares;
33
+ validator?: ConstrainValidator<TValidator>;
34
+ client?: MiddlewareClientFn<TMiddlewares, TValidator, TServerContext, TClientContext, TServerFnResponseType>;
35
+ server?: MiddlewareServerFn<TMiddlewares, TValidator, TServerContext, unknown, unknown, TServerFnResponseType>;
36
+ }
37
+ export type MiddlewareServerNextFn<TMiddlewares, TServerSendContext> = <TNewServerContext = undefined, TSendContext = undefined>(ctx?: {
38
+ context?: TNewServerContext;
39
+ 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> {
42
+ data: Expand<IntersectAllValidatorOutputs<TMiddlewares, TValidator>>;
43
+ context: Expand<AssignAllServerContext<TMiddlewares, TServerSendContext>>;
44
+ next: MiddlewareServerNextFn<TMiddlewares, TServerSendContext>;
45
+ response: TServerFnResponseType;
46
+ method: Method;
47
+ filename: string;
48
+ functionId: string;
49
+ signal: AbortSignal;
50
+ }
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> {
59
+ data: Expand<IntersectAllValidatorInputs<TMiddlewares, TValidator>>;
60
+ context: Expand<AssignAllClientContextBeforeNext<TMiddlewares>>;
61
+ sendContext: Expand<AssignAllServerSendContext<TMiddlewares>>;
62
+ method: Method;
63
+ response: TServerFnResponseType;
64
+ signal: AbortSignal;
65
+ next: MiddlewareClientNextFn<TMiddlewares>;
66
+ filename: string;
67
+ functionId: string;
68
+ type: ServerFnTypeOrTypeFn<Method, TServerFnResponseType, TMiddlewares, TValidator>;
69
+ }
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> = {
82
+ 'use functions must return the result of next()': true;
83
+ context: Expand<AssignAllClientContextAfterNext<TMiddlewares, TClientContext>>;
84
+ sendContext: Expand<AssignAllServerSendContext<TMiddlewares, TSendContext>>;
85
+ headers: HeadersInit;
86
+ };
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;
104
+ }
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>;
108
+ }
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> {
110
+ }
111
+ export interface MiddlewareValidator<TMiddlewares, TServerFnResponseType extends ServerFnResponseType> {
112
+ validator: <TNewValidator>(input: ConstrainValidator<TNewValidator>) => MiddlewareAfterValidator<TMiddlewares, TNewValidator, TServerFnResponseType>;
113
+ }
114
+ export interface MiddlewareAfterServer<TMiddlewares, TValidator, TServerContext, TServerSendContext, TClientContext, TClientSendContext, TServerFnResponseType extends ServerFnResponseType> extends MiddlewareWithTypes<TMiddlewares, TValidator, TServerContext, TServerSendContext, TClientContext, TClientSendContext, TServerFnResponseType> {
115
+ }
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>;
118
+ }
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> {
120
+ }
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>;
123
+ }
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> {
125
+ }
126
+ export interface Middleware<TServerFnResponseType extends ServerFnResponseType> extends MiddlewareAfterMiddleware<unknown, TServerFnResponseType> {
127
+ middleware: <const TNewMiddlewares = undefined>(middlewares: Constrain<TNewMiddlewares, ReadonlyArray<AnyMiddleware>>) => MiddlewareAfterMiddleware<TNewMiddlewares, TServerFnResponseType>;
128
+ }
129
+ export declare function createMiddleware(options?: {
130
+ validateClient?: boolean;
131
+ }, __opts?: MiddlewareOptions<unknown, undefined, undefined, undefined, ServerFnResponseType>): Middleware<ServerFnResponseType>;
@@ -0,0 +1,34 @@
1
+ function createMiddleware(options, __opts) {
2
+ const resolvedOptions = __opts || (options || {});
3
+ return {
4
+ options: resolvedOptions,
5
+ middleware: (middleware) => {
6
+ return createMiddleware(
7
+ void 0,
8
+ Object.assign(resolvedOptions, { middleware })
9
+ );
10
+ },
11
+ validator: (validator) => {
12
+ return createMiddleware(
13
+ void 0,
14
+ Object.assign(resolvedOptions, { validator })
15
+ );
16
+ },
17
+ client: (client) => {
18
+ return createMiddleware(
19
+ void 0,
20
+ Object.assign(resolvedOptions, { client })
21
+ );
22
+ },
23
+ server: (server) => {
24
+ return createMiddleware(
25
+ void 0,
26
+ Object.assign(resolvedOptions, { server })
27
+ );
28
+ }
29
+ };
30
+ }
31
+ export {
32
+ createMiddleware
33
+ };
34
+ //# sourceMappingURL=createMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createMiddleware.js","sources":["../../src/createMiddleware.ts"],"sourcesContent":["import type {\n ConstrainValidator,\n Method,\n ServerFnResponseType,\n ServerFnTypeOrTypeFn,\n} from './createServerFn'\nimport type {\n Assign,\n Constrain,\n Expand,\n IntersectAssign,\n ResolveValidatorInput,\n ResolveValidatorOutput,\n SerializerStringify,\n} from '@tanstack/router-core'\n\nexport 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;"}