@tanstack/start-client-core 1.114.4 → 1.114.6

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 +3 -2
  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,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function createIsomorphicFn() {
4
+ return null;
5
+ }
6
+ exports.createIsomorphicFn = createIsomorphicFn;
7
+ //# sourceMappingURL=createIsomorphicFn.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createIsomorphicFn.cjs","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,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,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function createMiddleware(options, __opts) {
4
+ const resolvedOptions = __opts || (options || {});
5
+ return {
6
+ options: resolvedOptions,
7
+ middleware: (middleware) => {
8
+ return createMiddleware(
9
+ void 0,
10
+ Object.assign(resolvedOptions, { middleware })
11
+ );
12
+ },
13
+ validator: (validator) => {
14
+ return createMiddleware(
15
+ void 0,
16
+ Object.assign(resolvedOptions, { validator })
17
+ );
18
+ },
19
+ client: (client) => {
20
+ return createMiddleware(
21
+ void 0,
22
+ Object.assign(resolvedOptions, { client })
23
+ );
24
+ },
25
+ server: (server) => {
26
+ return createMiddleware(
27
+ void 0,
28
+ Object.assign(resolvedOptions, { server })
29
+ );
30
+ }
31
+ };
32
+ }
33
+ exports.createMiddleware = createMiddleware;
34
+ //# sourceMappingURL=createMiddleware.cjs.map
@@ -0,0 +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;;"}
@@ -0,0 +1,131 @@
1
+ import { ConstrainValidator, Method, ServerFnResponseType, ServerFnTypeOrTypeFn } from './createServerFn.cjs';
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,227 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
25
+ const invariant = require("tiny-invariant");
26
+ const warning = require("tiny-warning");
27
+ const serializer = require("./serializer.cjs");
28
+ const headers = require("./headers.cjs");
29
+ exports.serverFnStaticCache = void 0;
30
+ function setServerFnStaticCache(cache) {
31
+ const previousCache = exports.serverFnStaticCache;
32
+ exports.serverFnStaticCache = typeof cache === "function" ? cache() : cache;
33
+ return () => {
34
+ exports.serverFnStaticCache = previousCache;
35
+ };
36
+ }
37
+ function createServerFnStaticCache(serverFnStaticCache2) {
38
+ return serverFnStaticCache2;
39
+ }
40
+ setServerFnStaticCache(() => {
41
+ const getStaticCacheUrl = (options, hash) => {
42
+ return `/__tsr/staticServerFnCache/${options.functionId}__${hash}.json`;
43
+ };
44
+ const jsonToFilenameSafeString = (json) => {
45
+ const sortedKeysReplacer = (key, value) => value && typeof value === "object" && !Array.isArray(value) ? Object.keys(value).sort().reduce((acc, curr) => {
46
+ acc[curr] = value[curr];
47
+ return acc;
48
+ }, {}) : value;
49
+ const jsonString = JSON.stringify(json ?? "", sortedKeysReplacer);
50
+ return jsonString.replace(/[/\\?%*:|"<>]/g, "-").replace(/\s+/g, "_");
51
+ };
52
+ const staticClientCache = typeof document !== "undefined" ? /* @__PURE__ */ new Map() : null;
53
+ return createServerFnStaticCache({
54
+ getItem: async (ctx) => {
55
+ if (typeof document === "undefined") {
56
+ const hash = jsonToFilenameSafeString(ctx.data);
57
+ const url = getStaticCacheUrl(ctx, hash);
58
+ const publicUrl = process.env.TSS_OUTPUT_PUBLIC_DIR;
59
+ const { promises: fs } = await import("node:fs");
60
+ const path = await import("node:path");
61
+ const filePath = path.join(publicUrl, url);
62
+ const [cachedResult, readError] = await fs.readFile(filePath, "utf-8").then((c) => [
63
+ serializer.startSerializer.parse(c),
64
+ null
65
+ ]).catch((e) => [null, e]);
66
+ if (readError && readError.code !== "ENOENT") {
67
+ throw readError;
68
+ }
69
+ return cachedResult;
70
+ }
71
+ return void 0;
72
+ },
73
+ setItem: async (ctx, response) => {
74
+ const { promises: fs } = await import("node:fs");
75
+ const path = await import("node:path");
76
+ const hash = jsonToFilenameSafeString(ctx.data);
77
+ const url = getStaticCacheUrl(ctx, hash);
78
+ const publicUrl = process.env.TSS_OUTPUT_PUBLIC_DIR;
79
+ const filePath = path.join(publicUrl, url);
80
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
81
+ await fs.writeFile(filePath, serializer.startSerializer.stringify(response));
82
+ },
83
+ fetchItem: async (ctx) => {
84
+ const hash = jsonToFilenameSafeString(ctx.data);
85
+ const url = getStaticCacheUrl(ctx, hash);
86
+ let result = staticClientCache == null ? void 0 : staticClientCache.get(url);
87
+ if (!result) {
88
+ result = await fetch(url, {
89
+ method: "GET"
90
+ }).then((r) => r.text()).then((d) => serializer.startSerializer.parse(d));
91
+ staticClientCache == null ? void 0 : staticClientCache.set(url, result);
92
+ }
93
+ return result;
94
+ }
95
+ });
96
+ });
97
+ function extractFormDataContext(formData) {
98
+ const serializedContext = formData.get("__TSR_CONTEXT");
99
+ formData.delete("__TSR_CONTEXT");
100
+ if (typeof serializedContext !== "string") {
101
+ return {
102
+ context: {},
103
+ data: formData
104
+ };
105
+ }
106
+ try {
107
+ const context = serializer.startSerializer.parse(serializedContext);
108
+ return {
109
+ context,
110
+ data: formData
111
+ };
112
+ } catch {
113
+ return {
114
+ data: formData
115
+ };
116
+ }
117
+ }
118
+ function flattenMiddlewares(middlewares) {
119
+ const seen = /* @__PURE__ */ new Set();
120
+ const flattened = [];
121
+ const recurse = (middleware) => {
122
+ middleware.forEach((m) => {
123
+ if (m.options.middleware) {
124
+ recurse(m.options.middleware);
125
+ }
126
+ if (!seen.has(m)) {
127
+ seen.add(m);
128
+ flattened.push(m);
129
+ }
130
+ });
131
+ };
132
+ recurse(middlewares);
133
+ return flattened;
134
+ }
135
+ const applyMiddleware = async (middlewareFn, ctx, nextFn) => {
136
+ return middlewareFn({
137
+ ...ctx,
138
+ next: async (userCtx = {}) => {
139
+ return nextFn({
140
+ ...ctx,
141
+ ...userCtx,
142
+ context: {
143
+ ...ctx.context,
144
+ ...userCtx.context
145
+ },
146
+ sendContext: {
147
+ ...ctx.sendContext,
148
+ ...userCtx.sendContext ?? {}
149
+ },
150
+ headers: headers.mergeHeaders(ctx.headers, userCtx.headers),
151
+ result: userCtx.result !== void 0 ? userCtx.result : ctx.response === "raw" ? userCtx : ctx.result,
152
+ error: userCtx.error ?? ctx.error
153
+ });
154
+ }
155
+ });
156
+ };
157
+ function execValidator(validator, input) {
158
+ if (validator == null) return {};
159
+ if ("~standard" in validator) {
160
+ const result = validator["~standard"].validate(input);
161
+ if (result instanceof Promise)
162
+ throw new Error("Async validation not supported");
163
+ if (result.issues)
164
+ throw new Error(JSON.stringify(result.issues, void 0, 2));
165
+ return result.value;
166
+ }
167
+ if ("parse" in validator) {
168
+ return validator.parse(input);
169
+ }
170
+ if (typeof validator === "function") {
171
+ return validator(input);
172
+ }
173
+ throw new Error("Invalid validator type!");
174
+ }
175
+ function serverFnBaseToMiddleware(options) {
176
+ return {
177
+ _types: void 0,
178
+ options: {
179
+ validator: options.validator,
180
+ validateClient: options.validateClient,
181
+ client: async ({ next, sendContext, ...ctx }) => {
182
+ var _a;
183
+ const payload = {
184
+ ...ctx,
185
+ // switch the sendContext over to context
186
+ context: sendContext,
187
+ type: typeof ctx.type === "function" ? ctx.type(ctx) : ctx.type
188
+ };
189
+ if (ctx.type === "static" && process.env.NODE_ENV === "production" && typeof document !== "undefined") {
190
+ invariant(
191
+ exports.serverFnStaticCache,
192
+ "serverFnStaticCache.fetchItem is not available!"
193
+ );
194
+ const result = await exports.serverFnStaticCache.fetchItem(payload);
195
+ if (result) {
196
+ if (result.error) {
197
+ throw result.error;
198
+ }
199
+ return next(result.ctx);
200
+ }
201
+ warning(
202
+ result,
203
+ `No static cache item found for ${payload.functionId}__${JSON.stringify(payload.data)}, falling back to server function...`
204
+ );
205
+ }
206
+ const res = await ((_a = options.extractedFn) == null ? void 0 : _a.call(options, payload));
207
+ return next(res);
208
+ },
209
+ server: async ({ next, ...ctx }) => {
210
+ var _a;
211
+ const result = await ((_a = options.serverFn) == null ? void 0 : _a.call(options, ctx));
212
+ return next({
213
+ ...ctx,
214
+ result
215
+ });
216
+ }
217
+ }
218
+ };
219
+ }
220
+ exports.applyMiddleware = applyMiddleware;
221
+ exports.createServerFnStaticCache = createServerFnStaticCache;
222
+ exports.execValidator = execValidator;
223
+ exports.extractFormDataContext = extractFormDataContext;
224
+ exports.flattenMiddlewares = flattenMiddlewares;
225
+ exports.serverFnBaseToMiddleware = serverFnBaseToMiddleware;
226
+ exports.setServerFnStaticCache = setServerFnStaticCache;
227
+ //# sourceMappingURL=createServerFn.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createServerFn.cjs","sources":["../../src/createServerFn.ts"],"sourcesContent":["import { default as invariant } from 'tiny-invariant'\nimport { default as warning } from 'tiny-warning'\nimport { startSerializer } from './serializer'\nimport { mergeHeaders } from './headers'\nimport type { Readable } from 'node:stream'\nimport type {\n AnyValidator,\n Constrain,\n Expand,\n ResolveValidatorInput,\n SerializerParse,\n SerializerStringify,\n SerializerStringifyBy,\n Validator,\n} from '@tanstack/router-core'\nimport type {\n AnyMiddleware,\n AssignAllClientSendContext,\n AssignAllServerContext,\n IntersectAllValidatorInputs,\n IntersectAllValidatorOutputs,\n MiddlewareClientFnResult,\n MiddlewareServerFnResult,\n} from './createMiddleware'\n\nexport interface JsonResponse<TData> extends Response {\n json: () => Promise<TData>\n}\n\nexport type CompiledFetcherFnOptions = {\n method: Method\n data: unknown\n response?: ServerFnResponseType\n headers?: HeadersInit\n signal?: AbortSignal\n context?: any\n}\n\nexport type Fetcher<\n TMiddlewares,\n TValidator,\n TResponse,\n TServerFnResponseType extends ServerFnResponseType,\n> =\n undefined extends IntersectAllValidatorInputs<TMiddlewares, TValidator>\n ? OptionalFetcher<\n TMiddlewares,\n TValidator,\n TResponse,\n TServerFnResponseType\n >\n : RequiredFetcher<\n TMiddlewares,\n TValidator,\n TResponse,\n TServerFnResponseType\n >\n\nexport interface FetcherBase {\n url: string\n __executeServer: (opts: {\n method: Method\n response?: ServerFnResponseType\n data: unknown\n headers?: HeadersInit\n context?: any\n signal: AbortSignal\n }) => Promise<unknown>\n}\n\nexport type FetchResult<\n TMiddlewares,\n TResponse,\n TServerFnResponseType extends ServerFnResponseType,\n> = TServerFnResponseType extends 'raw'\n ? Promise<Response>\n : TServerFnResponseType extends 'full'\n ? Promise<FullFetcherData<TMiddlewares, TResponse>>\n : Promise<FetcherData<TResponse>>\n\nexport interface OptionalFetcher<\n TMiddlewares,\n TValidator,\n TResponse,\n TServerFnResponseType extends ServerFnResponseType,\n> extends FetcherBase {\n (\n options?: OptionalFetcherDataOptions<TMiddlewares, TValidator>,\n ): FetchResult<TMiddlewares, TResponse, TServerFnResponseType>\n}\n\nexport interface RequiredFetcher<\n TMiddlewares,\n TValidator,\n TResponse,\n TServerFnResponseType extends ServerFnResponseType,\n> extends FetcherBase {\n (\n opts: RequiredFetcherDataOptions<TMiddlewares, TValidator>,\n ): FetchResult<TMiddlewares, TResponse, TServerFnResponseType>\n}\n\nexport type FetcherBaseOptions = {\n headers?: HeadersInit\n type?: ServerFnType\n signal?: AbortSignal\n}\n\nexport type ServerFnType = 'static' | 'dynamic'\n\nexport interface OptionalFetcherDataOptions<TMiddlewares, TValidator>\n extends FetcherBaseOptions {\n data?: Expand<IntersectAllValidatorInputs<TMiddlewares, TValidator>>\n}\n\nexport interface RequiredFetcherDataOptions<TMiddlewares, TValidator>\n extends FetcherBaseOptions {\n data: Expand<IntersectAllValidatorInputs<TMiddlewares, TValidator>>\n}\n\nexport interface FullFetcherData<TMiddlewares, TResponse> {\n error: unknown\n result: FetcherData<TResponse>\n context: AssignAllClientSendContext<TMiddlewares>\n}\n\nexport type FetcherData<TResponse> =\n TResponse extends JsonResponse<any>\n ? SerializerParse<ReturnType<TResponse['json']>>\n : SerializerParse<TResponse>\n\nexport type RscStream<T> = {\n __cacheState: T\n}\n\nexport type Method = 'GET' | 'POST'\nexport type ServerFnResponseType = 'data' | 'full' | 'raw'\n\n// see https://h3.unjs.io/guide/event-handler#responses-types\nexport type RawResponse = Response | ReadableStream | Readable | null | string\n\nexport type ServerFnReturnType<\n TServerFnResponseType extends ServerFnResponseType,\n TResponse,\n> = TServerFnResponseType extends 'raw'\n ? RawResponse | Promise<RawResponse>\n : Promise<SerializerStringify<TResponse>> | SerializerStringify<TResponse>\nexport type ServerFn<\n TMethod,\n TServerFnResponseType extends ServerFnResponseType,\n TMiddlewares,\n TValidator,\n TResponse,\n> = (\n ctx: ServerFnCtx<TMethod, TServerFnResponseType, TMiddlewares, TValidator>,\n) => ServerFnReturnType<TServerFnResponseType, TResponse>\n\nexport interface ServerFnCtx<\n TMethod,\n TServerFnResponseType extends ServerFnResponseType,\n TMiddlewares,\n TValidator,\n> {\n method: TMethod\n response: TServerFnResponseType\n data: Expand<IntersectAllValidatorOutputs<TMiddlewares, TValidator>>\n context: Expand<AssignAllServerContext<TMiddlewares>>\n signal: AbortSignal\n}\n\nexport type CompiledFetcherFn<\n TResponse,\n TServerFnResponseType extends ServerFnResponseType,\n> = {\n (\n opts: CompiledFetcherFnOptions &\n ServerFnBaseOptions<Method, TServerFnResponseType>,\n ): Promise<TResponse>\n url: string\n}\n\nexport type ServerFnBaseOptions<\n TMethod extends Method = 'GET',\n TServerFnResponseType extends ServerFnResponseType = 'data',\n TResponse = unknown,\n TMiddlewares = unknown,\n TInput = unknown,\n> = {\n method: TMethod\n response?: TServerFnResponseType\n validateClient?: boolean\n middleware?: Constrain<TMiddlewares, ReadonlyArray<AnyMiddleware>>\n validator?: ConstrainValidator<TInput>\n extractedFn?: CompiledFetcherFn<TResponse, TServerFnResponseType>\n serverFn?: ServerFn<\n TMethod,\n TServerFnResponseType,\n TMiddlewares,\n TInput,\n TResponse\n >\n functionId: string\n type: ServerFnTypeOrTypeFn<\n TMethod,\n TServerFnResponseType,\n TMiddlewares,\n AnyValidator\n >\n}\n\nexport type ValidatorSerializerStringify<TValidator> = Validator<\n SerializerStringifyBy<\n ResolveValidatorInput<TValidator>,\n Date | undefined | FormData\n >,\n any\n>\n\nexport type ConstrainValidator<TValidator> = unknown extends TValidator\n ? TValidator\n : Constrain<TValidator, ValidatorSerializerStringify<TValidator>>\n\nexport interface ServerFnMiddleware<\n TMethod extends Method,\n TServerFnResponseType extends ServerFnResponseType,\n TValidator,\n> {\n middleware: <const TNewMiddlewares = undefined>(\n middlewares: Constrain<TNewMiddlewares, ReadonlyArray<AnyMiddleware>>,\n ) => ServerFnAfterMiddleware<\n TMethod,\n TServerFnResponseType,\n TNewMiddlewares,\n TValidator\n >\n}\n\nexport interface ServerFnAfterMiddleware<\n TMethod extends Method,\n TServerFnResponseType extends ServerFnResponseType,\n TMiddlewares,\n TValidator,\n> extends ServerFnValidator<TMethod, TServerFnResponseType, TMiddlewares>,\n ServerFnTyper<TMethod, TServerFnResponseType, TMiddlewares, TValidator>,\n ServerFnHandler<TMethod, TServerFnResponseType, TMiddlewares, TValidator> {}\n\nexport type ValidatorFn<\n TMethod extends Method,\n TServerFnResponseType extends ServerFnResponseType,\n TMiddlewares,\n> = <TValidator>(\n validator: ConstrainValidator<TValidator>,\n) => ServerFnAfterValidator<\n TMethod,\n TServerFnResponseType,\n TMiddlewares,\n TValidator\n>\n\nexport interface ServerFnValidator<\n TMethod extends Method,\n TServerFnResponseType extends ServerFnResponseType,\n TMiddlewares,\n> {\n validator: ValidatorFn<TMethod, TServerFnResponseType, TMiddlewares>\n}\n\nexport interface ServerFnAfterValidator<\n TMethod extends Method,\n TServerFnResponseType extends ServerFnResponseType,\n TMiddlewares,\n TValidator,\n> extends ServerFnMiddleware<TMethod, TServerFnResponseType, TValidator>,\n ServerFnTyper<TMethod, TServerFnResponseType, TMiddlewares, TValidator>,\n ServerFnHandler<TMethod, TServerFnResponseType, TMiddlewares, TValidator> {}\n\n// Typer\nexport interface ServerFnTyper<\n TMethod extends Method,\n TServerFnResponseType extends ServerFnResponseType,\n TMiddlewares,\n TValidator,\n> {\n type: (\n typer: ServerFnTypeOrTypeFn<\n TMethod,\n TServerFnResponseType,\n TMiddlewares,\n TValidator\n >,\n ) => ServerFnAfterTyper<\n TMethod,\n TServerFnResponseType,\n TMiddlewares,\n TValidator\n >\n}\n\nexport type ServerFnTypeOrTypeFn<\n TMethod extends Method,\n TServerFnResponseType extends ServerFnResponseType,\n TMiddlewares,\n TValidator,\n> =\n | ServerFnType\n | ((\n ctx: ServerFnCtx<\n TMethod,\n TServerFnResponseType,\n TMiddlewares,\n TValidator\n >,\n ) => ServerFnType)\n\nexport interface ServerFnAfterTyper<\n TMethod extends Method,\n TServerFnResponseType extends ServerFnResponseType,\n TMiddlewares,\n TValidator,\n> extends ServerFnHandler<\n TMethod,\n TServerFnResponseType,\n TMiddlewares,\n TValidator\n > {}\n\n// Handler\nexport interface ServerFnHandler<\n TMethod extends Method,\n TServerFnResponseType extends ServerFnResponseType,\n TMiddlewares,\n TValidator,\n> {\n handler: <TNewResponse>(\n fn?: ServerFn<\n TMethod,\n TServerFnResponseType,\n TMiddlewares,\n TValidator,\n TNewResponse\n >,\n ) => Fetcher<TMiddlewares, TValidator, TNewResponse, TServerFnResponseType>\n}\n\nexport interface ServerFnBuilder<\n TMethod extends Method = 'GET',\n TServerFnResponseType extends ServerFnResponseType = 'data',\n> extends ServerFnMiddleware<TMethod, TServerFnResponseType, undefined>,\n ServerFnValidator<TMethod, TServerFnResponseType, undefined>,\n ServerFnTyper<TMethod, TServerFnResponseType, undefined, undefined>,\n ServerFnHandler<TMethod, TServerFnResponseType, undefined, undefined> {\n options: ServerFnBaseOptions<\n TMethod,\n TServerFnResponseType,\n unknown,\n undefined,\n undefined\n >\n}\n\nexport type StaticCachedResult = {\n ctx?: {\n result: any\n context: any\n }\n error?: any\n}\n\nexport type ServerFnStaticCache = {\n getItem: (\n ctx: ServerFnMiddlewareResult,\n ) => StaticCachedResult | Promise<StaticCachedResult | undefined>\n setItem: (\n ctx: ServerFnMiddlewareResult,\n response: StaticCachedResult,\n ) => Promise<void>\n fetchItem: (\n ctx: ServerFnMiddlewareResult,\n ) => StaticCachedResult | Promise<StaticCachedResult | undefined>\n}\n\nexport let serverFnStaticCache: ServerFnStaticCache | undefined\n\nexport function setServerFnStaticCache(\n cache?: ServerFnStaticCache | (() => ServerFnStaticCache | undefined),\n) {\n const previousCache = serverFnStaticCache\n serverFnStaticCache = typeof cache === 'function' ? cache() : cache\n\n return () => {\n serverFnStaticCache = previousCache\n }\n}\n\nexport function createServerFnStaticCache(\n serverFnStaticCache: ServerFnStaticCache,\n) {\n return serverFnStaticCache\n}\n\nsetServerFnStaticCache(() => {\n const getStaticCacheUrl = (\n options: ServerFnMiddlewareResult,\n hash: string,\n ) => {\n return `/__tsr/staticServerFnCache/${options.functionId}__${hash}.json`\n }\n\n const jsonToFilenameSafeString = (json: any) => {\n // Custom replacer to sort keys\n const sortedKeysReplacer = (key: string, value: any) =>\n value && typeof value === 'object' && !Array.isArray(value)\n ? Object.keys(value)\n .sort()\n .reduce((acc: any, curr: string) => {\n acc[curr] = value[curr]\n return acc\n }, {})\n : value\n\n // Convert JSON to string with sorted keys\n const jsonString = JSON.stringify(json ?? '', sortedKeysReplacer)\n\n // Replace characters invalid in filenames\n return jsonString\n .replace(/[/\\\\?%*:|\"<>]/g, '-') // Replace invalid characters with a dash\n .replace(/\\s+/g, '_') // Optionally replace whitespace with underscores\n }\n\n const staticClientCache =\n typeof document !== 'undefined' ? new Map<string, any>() : null\n\n return createServerFnStaticCache({\n getItem: async (ctx) => {\n if (typeof document === 'undefined') {\n const hash = jsonToFilenameSafeString(ctx.data)\n const url = getStaticCacheUrl(ctx, hash)\n const publicUrl = process.env.TSS_OUTPUT_PUBLIC_DIR!\n\n // Use fs instead of fetch to read from filesystem\n const { promises: fs } = await import('node:fs')\n const path = await import('node:path')\n const filePath = path.join(publicUrl, url)\n\n const [cachedResult, readError] = await fs\n .readFile(filePath, 'utf-8')\n .then((c) => [\n startSerializer.parse(c) as {\n ctx: unknown\n error: any\n },\n null,\n ])\n .catch((e) => [null, e])\n\n if (readError && readError.code !== 'ENOENT') {\n throw readError\n }\n\n return cachedResult as StaticCachedResult\n }\n\n return undefined\n },\n setItem: async (ctx, response) => {\n const { promises: fs } = await import('node:fs')\n const path = await import('node:path')\n\n const hash = jsonToFilenameSafeString(ctx.data)\n const url = getStaticCacheUrl(ctx, hash)\n const publicUrl = process.env.TSS_OUTPUT_PUBLIC_DIR!\n const filePath = path.join(publicUrl, url)\n\n // Ensure the directory exists\n await fs.mkdir(path.dirname(filePath), { recursive: true })\n\n // Store the result with fs\n await fs.writeFile(filePath, startSerializer.stringify(response))\n },\n fetchItem: async (ctx) => {\n const hash = jsonToFilenameSafeString(ctx.data)\n const url = getStaticCacheUrl(ctx, hash)\n\n let result: any = staticClientCache?.get(url)\n\n if (!result) {\n result = await fetch(url, {\n method: 'GET',\n })\n .then((r) => r.text())\n .then((d) => startSerializer.parse(d))\n\n staticClientCache?.set(url, result)\n }\n\n return result\n },\n })\n})\n\nexport function extractFormDataContext(formData: FormData) {\n const serializedContext = formData.get('__TSR_CONTEXT')\n formData.delete('__TSR_CONTEXT')\n\n if (typeof serializedContext !== 'string') {\n return {\n context: {},\n data: formData,\n }\n }\n\n try {\n const context = startSerializer.parse(serializedContext)\n return {\n context,\n data: formData,\n }\n } catch {\n return {\n data: formData,\n }\n }\n}\n\nexport function flattenMiddlewares(\n middlewares: Array<AnyMiddleware>,\n): Array<AnyMiddleware> {\n const seen = new Set<AnyMiddleware>()\n const flattened: Array<AnyMiddleware> = []\n\n const recurse = (middleware: Array<AnyMiddleware>) => {\n middleware.forEach((m) => {\n if (m.options.middleware) {\n recurse(m.options.middleware)\n }\n\n if (!seen.has(m)) {\n seen.add(m)\n flattened.push(m)\n }\n })\n }\n\n recurse(middlewares)\n\n return flattened\n}\n\nexport type ServerFnMiddlewareOptions = {\n method: Method\n response?: ServerFnResponseType\n data: any\n headers?: HeadersInit\n signal?: AbortSignal\n sendContext?: any\n context?: any\n type: ServerFnTypeOrTypeFn<any, any, any, any>\n functionId: string\n}\n\nexport type ServerFnMiddlewareResult = ServerFnMiddlewareOptions & {\n result?: unknown\n error?: unknown\n type: ServerFnTypeOrTypeFn<any, any, any, any>\n}\n\nexport type NextFn = (\n ctx: ServerFnMiddlewareResult,\n) => Promise<ServerFnMiddlewareResult>\n\nexport type MiddlewareFn = (\n ctx: ServerFnMiddlewareOptions & {\n next: NextFn\n },\n) => Promise<ServerFnMiddlewareResult>\n\nexport const applyMiddleware = async (\n middlewareFn: MiddlewareFn,\n ctx: ServerFnMiddlewareOptions,\n nextFn: NextFn,\n) => {\n return middlewareFn({\n ...ctx,\n next: (async (\n userCtx: ServerFnMiddlewareResult | undefined = {} as any,\n ) => {\n // Return the next middleware\n return nextFn({\n ...ctx,\n ...userCtx,\n context: {\n ...ctx.context,\n ...userCtx.context,\n },\n sendContext: {\n ...ctx.sendContext,\n ...(userCtx.sendContext ?? {}),\n },\n headers: mergeHeaders(ctx.headers, userCtx.headers),\n result:\n userCtx.result !== undefined\n ? userCtx.result\n : ctx.response === 'raw'\n ? userCtx\n : (ctx as any).result,\n error: userCtx.error ?? (ctx as any).error,\n })\n }) as any,\n } as any)\n}\n\nexport function execValidator(\n validator: AnyValidator,\n input: unknown,\n): unknown {\n if (validator == null) return {}\n\n if ('~standard' in validator) {\n const result = validator['~standard'].validate(input)\n\n if (result instanceof Promise)\n throw new Error('Async validation not supported')\n\n if (result.issues)\n throw new Error(JSON.stringify(result.issues, undefined, 2))\n\n return result.value\n }\n\n if ('parse' in validator) {\n return validator.parse(input)\n }\n\n if (typeof validator === 'function') {\n return validator(input)\n }\n\n throw new Error('Invalid validator type!')\n}\n\nexport function serverFnBaseToMiddleware(\n options: ServerFnBaseOptions<any, any, any, any, any>,\n): AnyMiddleware {\n return {\n _types: undefined!,\n options: {\n validator: options.validator,\n validateClient: options.validateClient,\n client: async ({ next, sendContext, ...ctx }) => {\n const payload = {\n ...ctx,\n // switch the sendContext over to context\n context: sendContext,\n type: typeof ctx.type === 'function' ? ctx.type(ctx) : ctx.type,\n } as any\n\n if (\n ctx.type === 'static' &&\n process.env.NODE_ENV === 'production' &&\n typeof document !== 'undefined'\n ) {\n invariant(\n serverFnStaticCache,\n 'serverFnStaticCache.fetchItem is not available!',\n )\n\n const result = await serverFnStaticCache.fetchItem(payload)\n\n if (result) {\n if (result.error) {\n throw result.error\n }\n\n return next(result.ctx)\n }\n\n warning(\n result,\n `No static cache item found for ${payload.functionId}__${JSON.stringify(payload.data)}, falling back to server function...`,\n )\n }\n\n // Execute the extracted function\n // but not before serializing the context\n const res = await options.extractedFn?.(payload)\n\n return next(res) as unknown as MiddlewareClientFnResult<any, any, any>\n },\n server: async ({ next, ...ctx }) => {\n // Execute the server function\n const result = await options.serverFn?.(ctx)\n\n return next({\n ...ctx,\n result,\n } as any) as unknown as MiddlewareServerFnResult<any, any, any, any>\n },\n },\n }\n}\n"],"names":["serverFnStaticCache","startSerializer","mergeHeaders"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6XWA,QAAAA,sBAAAA;AAEJ,SAAS,uBACd,OACA;AACA,QAAM,gBAAgBA,QAAA;AACtBA,UAAAA,sBAAsB,OAAO,UAAU,aAAa,MAAU,IAAA;AAE9D,SAAO,MAAM;AACWA,YAAAA,sBAAA;AAAA,EACxB;AACF;AAEO,SAAS,0BACdA,sBACA;AACOA,SAAAA;AACT;AAEA,uBAAuB,MAAM;AACrB,QAAA,oBAAoB,CACxB,SACA,SACG;AACH,WAAO,8BAA8B,QAAQ,UAAU,KAAK,IAAI;AAAA,EAClE;AAEM,QAAA,2BAA2B,CAAC,SAAc;AAExC,UAAA,qBAAqB,CAAC,KAAa,UACvC,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,IACtD,OAAO,KAAK,KAAK,EACd,OACA,OAAO,CAAC,KAAU,SAAiB;AAC9B,UAAA,IAAI,IAAI,MAAM,I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