@farm.js/core 0.1.15 → 0.1.16

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 (123) hide show
  1. package/dist/agent-runtime.d.mts +5 -2
  2. package/dist/agent-runtime.d.ts +5 -2
  3. package/dist/api/client.d.mts +3 -2
  4. package/dist/api/client.d.ts +3 -2
  5. package/dist/api/route-manager.d.mts +5 -2
  6. package/dist/api/route-manager.d.ts +5 -2
  7. package/dist/api/runtime.d.mts +3 -2
  8. package/dist/api/runtime.d.ts +3 -2
  9. package/dist/{api-client-C8d7BZNp.d.mts → api-client-B-n3pm_Q.d.mts} +2 -1
  10. package/dist/{api-client-BWrEbxfO.d.ts → api-client-C0_NZEBl.d.ts} +2 -1
  11. package/dist/api.d.mts +7 -4
  12. package/dist/api.d.ts +7 -4
  13. package/dist/{app-wIYse61b.d.ts → app-AyjEsCBq.d.ts} +3 -3
  14. package/dist/{app-B3nVSjen.d.mts → app-CYPHeOo_.d.mts} +3 -3
  15. package/dist/app-markdown.d.mts +6 -3
  16. package/dist/app-markdown.d.ts +6 -3
  17. package/dist/{chunk-FOGLGRDS.mjs → chunk-7HDZYYS4.mjs} +100 -8
  18. package/dist/{chunk-UE75PB52.mjs → chunk-IL5RWYK7.mjs} +1 -1
  19. package/dist/{chunk-GNTPTTLA.mjs → chunk-IXTEENRS.mjs} +1 -1
  20. package/dist/{chunk-JRF3C33L.mjs → chunk-NHHKW2T6.mjs} +5 -4
  21. package/dist/{chunk-NJ47VORC.mjs → chunk-NUD6XBMO.mjs} +1 -1
  22. package/dist/{chunk-FBHGHMOA.mjs → chunk-TYVVIQ5M.mjs} +10 -7
  23. package/dist/{chunk-W7IVHTOP.mjs → chunk-UQZPTIML.mjs} +15 -2
  24. package/dist/{chunk-S3QW3BIS.mjs → chunk-VVTREAG5.mjs} +89 -4
  25. package/dist/{client-plugins-C1EgdoJM.d.mts → client-plugins-CIPRtSsW.d.mts} +16 -4
  26. package/dist/{client-plugins-CslwYp3E.d.ts → client-plugins-CqVtZi5X.d.ts} +16 -4
  27. package/dist/client-plugins.d.mts +5 -2
  28. package/dist/client-plugins.d.ts +5 -2
  29. package/dist/client.d.mts +8 -7
  30. package/dist/client.d.ts +8 -7
  31. package/dist/config.d.mts +5 -2
  32. package/dist/config.d.ts +5 -2
  33. package/dist/{devtools-PCGEBRSC.mjs → devtools-IU7LKZOH.mjs} +2 -2
  34. package/dist/docs.cjs +74 -3
  35. package/dist/docs.mjs +3 -3
  36. package/dist/{route-C6UClI1z.d.mts → endpoint-Bu3XgeMK.d.mts} +3 -128
  37. package/dist/{route-CHBaW55F.d.ts → endpoint-kSAxE52R.d.ts} +3 -128
  38. package/dist/env.cjs +101 -8
  39. package/dist/env.d.mts +20 -2
  40. package/dist/env.d.ts +20 -2
  41. package/dist/env.mjs +3 -1
  42. package/dist/index.cjs +212 -19
  43. package/dist/index.d.mts +16 -15
  44. package/dist/index.d.ts +16 -15
  45. package/dist/index.mjs +20 -8
  46. package/dist/integrations.d.mts +5 -2
  47. package/dist/integrations.d.ts +5 -2
  48. package/dist/internal/app-markdown-runtime.d.mts +5 -2
  49. package/dist/internal/app-markdown-runtime.d.ts +5 -2
  50. package/dist/internal/build-runtime.cjs +264 -169
  51. package/dist/internal/build-runtime.d.mts +7 -4
  52. package/dist/internal/build-runtime.d.ts +7 -4
  53. package/dist/internal/build-runtime.mjs +6 -6
  54. package/dist/internal/cli-runtime.cjs +68 -4
  55. package/dist/internal/cli-runtime.mjs +2 -2
  56. package/dist/internal/client-error-overlay.cjs +1 -1
  57. package/dist/internal/client-error-overlay.mjs +1 -1
  58. package/dist/internal/compression-runtime.d.mts +5 -2
  59. package/dist/internal/compression-runtime.d.ts +5 -2
  60. package/dist/internal/config-runtime.cjs +68 -4
  61. package/dist/internal/config-runtime.d.mts +6 -3
  62. package/dist/internal/config-runtime.d.ts +6 -3
  63. package/dist/internal/config-runtime.mjs +2 -2
  64. package/dist/internal/product-telemetry-runtime.cjs +1 -1
  65. package/dist/internal/product-telemetry-runtime.mjs +1 -1
  66. package/dist/internal/production-runtime.d.mts +11 -8
  67. package/dist/internal/production-runtime.d.ts +11 -8
  68. package/dist/{metadata-BsUcOEXg.d.ts → metadata-8g__AMPM.d.ts} +1 -1
  69. package/dist/{metadata-B1bxCPUY.d.mts → metadata-OMX6wFNf.d.mts} +1 -1
  70. package/dist/middleware.d.mts +7 -4
  71. package/dist/middleware.d.ts +7 -4
  72. package/dist/{nitro-ICBP5APY.mjs → nitro-3N4ZXRYM.mjs} +5 -2
  73. package/dist/plugin.cjs +108 -7
  74. package/dist/plugin.d.mts +5 -2
  75. package/dist/plugin.d.ts +5 -2
  76. package/dist/plugin.mjs +3 -3
  77. package/dist/{production-runtime-CsNn2-zx.d.ts → production-runtime-BJh7o6Cr.d.ts} +1 -1
  78. package/dist/{production-runtime-BDllolVh.d.mts → production-runtime-W3M0eNDV.d.mts} +1 -1
  79. package/dist/{render-plan-EG4hNFjy.d.ts → render-plan-Be4ZGTJP.d.ts} +1 -1
  80. package/dist/{render-plan-CNUlzylR.d.mts → render-plan-io7pvDNc.d.mts} +1 -1
  81. package/dist/renderer-client.d.mts +5 -4
  82. package/dist/renderer-client.d.ts +5 -4
  83. package/dist/{request-Blh_f7Z3.d.mts → request-DZkHYQ89.d.mts} +1 -1
  84. package/dist/{request-DsVSQVfD.d.ts → request-G8JhKr4F.d.ts} +1 -1
  85. package/dist/request.d.mts +6 -3
  86. package/dist/request.d.ts +6 -3
  87. package/dist/route-BxNJT447.d.ts +128 -0
  88. package/dist/route-C_eLaFTZ.d.mts +128 -0
  89. package/dist/{route-rendering-hUETRCbM.d.ts → route-rendering-BcLLPJgN.d.ts} +1 -1
  90. package/dist/{route-rendering-LT4XSoQK.d.mts → route-rendering-CbAKr1TY.d.mts} +1 -1
  91. package/dist/routes.d.mts +4 -2
  92. package/dist/routes.d.ts +4 -2
  93. package/dist/server-fn-client.d.mts +3 -2
  94. package/dist/server-fn-client.d.ts +3 -2
  95. package/dist/server-fn.cjs +141 -3
  96. package/dist/server-fn.d.mts +72 -1
  97. package/dist/server-fn.d.ts +72 -1
  98. package/dist/server-fn.mjs +12 -1
  99. package/dist/server-plugins.d.mts +6 -3
  100. package/dist/server-plugins.d.ts +6 -3
  101. package/dist/server-query-client.d.mts +1 -0
  102. package/dist/server-query-client.d.ts +1 -0
  103. package/dist/server-query.cjs +60 -3
  104. package/dist/server-query.d.mts +6 -1
  105. package/dist/server-query.d.ts +6 -1
  106. package/dist/server-query.mjs +3 -2
  107. package/dist/server.cjs +161 -11
  108. package/dist/server.d.mts +9 -8
  109. package/dist/server.d.ts +9 -8
  110. package/dist/server.mjs +6 -6
  111. package/dist/{spa-router-csKR9Ebj.d.mts → spa-router-BcS_4nqm.d.mts} +2 -2
  112. package/dist/{spa-router-Y_2FSJQK.d.ts → spa-router-BzFBUJkn.d.ts} +2 -2
  113. package/dist/testing.d.mts +5 -3
  114. package/dist/testing.d.ts +5 -3
  115. package/dist/{utils-DR2wfZAn.d.mts → utils-5kQP1mFR.d.mts} +1 -1
  116. package/dist/{utils-jISOE9SD.d.ts → utils-C4yrAhNc.d.ts} +1 -1
  117. package/dist/version.cjs +1 -1
  118. package/dist/version.mjs +1 -1
  119. package/dist/vite.cjs +246 -149
  120. package/dist/vite.d.mts +5 -2
  121. package/dist/vite.d.ts +5 -2
  122. package/dist/vite.mjs +3 -3
  123. package/package.json +1 -1
@@ -0,0 +1,128 @@
1
+ import { E as EndpointMiddlewareResult, R as RouteSchema, a as RouteSchemaOutput, b as EndpointMCPOptions, A as AnyEndpointMiddleware, I as InferEndpointMiddlewareContext, T as TypedEndpoint, c as RouteSchemaInput } from './endpoint-Bu3XgeMK.mjs';
2
+
3
+ type RouteMethod = "GET" | "HEAD" | "QUERY" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS";
4
+ type RoutePathParams<Path extends string> = Path extends `${infer Head}/${infer Tail}` ? RoutePathParams<Head> & RoutePathParams<Tail> : Path extends `[[...${infer Name}]]` ? {
5
+ [K in Name]?: string[];
6
+ } : Path extends `[...${infer Name}]` ? {
7
+ [K in Name]: string[];
8
+ } : Path extends `[${infer Name}]` ? {
9
+ [K in Name]: string;
10
+ } : {};
11
+ interface RouteInputSchemas {
12
+ body?: RouteSchema;
13
+ query?: RouteSchema;
14
+ params?: RouteSchema;
15
+ headers?: RouteSchema;
16
+ }
17
+ type Input<I, K extends PropertyKey> = K extends keyof I ? RouteSchemaInput<I[K]> : never;
18
+ type Output<I, K extends PropertyKey, Fallback = unknown> = K extends keyof I ? RouteSchemaOutput<I[K]> : Fallback;
19
+ /** JSON responses have wire types, not server-side instances such as Date. */
20
+ type RouteJSON<T> = T extends Response ? unknown : T extends {
21
+ toJSON(): infer J;
22
+ } ? RouteJSON<J> : T extends bigint | symbol | ((...args: any[]) => any) ? never : T extends readonly (infer V)[] ? RouteJSON<V>[] : T extends object ? {
23
+ [K in keyof T]: RouteJSON<T[K]>;
24
+ } : T;
25
+ type RouteDefinition<P extends string = string, M extends RouteMethod = RouteMethod, E = any> = {
26
+ readonly path: P;
27
+ readonly method: M;
28
+ readonly endpoint: E;
29
+ };
30
+ type RouteEndpoint<P extends string, I extends RouteInputSchemas, R> = TypedEndpoint<Output<I, "body">, Input<I, "query">, RouteJSON<R>, Input<I, "headers">, never, Input<I, "body">> & {
31
+ __types: {
32
+ params: RoutePathParams<P>;
33
+ inputHeaders: Input<I, "headers">;
34
+ };
35
+ };
36
+ type TrimStart<P extends string> = P extends `/${infer Rest}` ? TrimStart<Rest> : P;
37
+ type Join<P extends string, C extends string> = C extends "" ? P : `${P}/${TrimStart<C>}`;
38
+ type ParamsCheck<P extends string, I extends RouteInputSchemas> = I extends {
39
+ params: infer S;
40
+ } ? Exclude<keyof RoutePathParams<P>, keyof RouteSchemaOutput<S>> extends never ? Exclude<keyof RouteSchemaOutput<S>, keyof RoutePathParams<P>> extends never ? unknown : {
41
+ __error_unknown_route_params: never;
42
+ } : {
43
+ __error_missing_route_params: never;
44
+ } : unknown;
45
+ type RouteMiddlewareResults = readonly (EndpointMiddlewareResult | Promise<EndpointMiddlewareResult>)[];
46
+ type RouteMiddlewares<Results extends readonly unknown[]> = {
47
+ readonly [K in keyof Results]: (context: Parameters<AnyEndpointMiddleware>[0]) => Results[K];
48
+ };
49
+ type RouteOptions<P extends string, I extends RouteInputSchemas, O extends RouteSchema | undefined, R, MiddlewareResults extends RouteMiddlewareResults = RouteMiddlewareResults> = {
50
+ input?: I & ParamsCheck<P, I>;
51
+ /** Validate plain JSON handler results. Raw Response/stream results are never buffered. */
52
+ output?: O;
53
+ /** Opt this app-owned endpoint into an installed MCP transport. */
54
+ mcp?: EndpointMCPOptions;
55
+ middleware?: RouteMiddlewares<MiddlewareResults>;
56
+ handler(request: Request, context: {
57
+ input: {
58
+ body: Output<I, "body">;
59
+ query: Output<I, "query", Record<string, string | string[]>>;
60
+ headers: Output<I, "headers", Record<string, string>>;
61
+ params: Output<I, "params", RoutePathParams<P>>;
62
+ };
63
+ params: Output<I, "params", RoutePathParams<P>>;
64
+ context: Readonly<InferEndpointMiddlewareContext<RouteMiddlewares<MiddlewareResults>>>;
65
+ }): R | Promise<R>;
66
+ };
67
+ type RouteBuilder<P extends string, M extends RouteMethod> = <const C extends string, const MiddlewareResults extends RouteMiddlewareResults, const I extends RouteInputSchemas = {}, O extends RouteSchema | undefined = undefined, R = unknown>(path: C, options: RouteOptions<Join<P, C>, I, O, R, MiddlewareResults>) => RouteDefinition<Join<P, C>, M, RouteEndpoint<Join<P, C>, I, Extract<Awaited<R>, Response> extends never ? O extends RouteSchema ? RouteSchemaOutput<O> : Awaited<R> : unknown>>;
68
+ type RouteFactory<P extends string = ""> = {
69
+ [M in Lowercase<RouteMethod>]: RouteBuilder<P, Uppercase<M> & RouteMethod>;
70
+ } & {
71
+ /** Return a new builder; never mutate the parent scope. */
72
+ scope<const C extends string>(path: C): RouteFactory<Join<P, C>>;
73
+ };
74
+ type PluginRoutes = readonly RouteDefinition[];
75
+ interface PluginLocalAPIEndpoint {
76
+ readonly path: string;
77
+ readonly method: RouteMethod;
78
+ readonly input: Readonly<RouteInputSchemas>;
79
+ readonly output?: RouteSchema;
80
+ readonly mcp?: EndpointMCPOptions;
81
+ invoke(request: Request, params?: Readonly<Record<string, string | string[]>>): Promise<Response>;
82
+ }
83
+ /**
84
+ * Read-only access to app-owned API endpoints while plugin routes are mounted.
85
+ * Plugin routes are intentionally excluded so a plugin cannot recurse through
86
+ * itself or depend on plugin registration order.
87
+ */
88
+ interface PluginLocalAPI {
89
+ /** False during type-only route discovery, where app endpoint modules are unavailable. */
90
+ readonly available: boolean;
91
+ get(method: RouteMethod, path: string): PluginLocalAPIEndpoint | undefined;
92
+ /** Enumerate app-owned endpoints. Plugin routes are excluded. */
93
+ list(): readonly PluginLocalAPIEndpoint[];
94
+ }
95
+ type PluginRoutesFactory<R extends PluginRoutes = PluginRoutes> = (context: {
96
+ route: RouteFactory;
97
+ api: PluginLocalAPI;
98
+ }) => R;
99
+ declare function createRouteFactory(): RouteFactory;
100
+ type UnionToIntersection<U> = (U extends unknown ? (v: U) => void : never) extends (v: infer I) => void ? I : never;
101
+ type RouteTree<P extends string, M extends string, E> = P extends `${infer Head}/${infer Tail}` ? {
102
+ [K in Head]: RouteTree<Tail, M, E>;
103
+ } : P extends "" ? {
104
+ [K in Lowercase<M>]: E;
105
+ } : {
106
+ [K in P]: {
107
+ [Method in Lowercase<M>]: E;
108
+ };
109
+ };
110
+ type HasMethodSegment<P extends string> = P extends `${infer H}/${infer T}` ? H extends Lowercase<RouteMethod> ? true : HasMethodSegment<T> : P extends Lowercase<RouteMethod> ? true : false;
111
+ type DefinitionTree<D> = D extends RouteDefinition<infer P, infer M, infer E> ? string extends P ? {} : (P extends `/api/integrations${string}` ? true : HasMethodSegment<P>) extends true ? {
112
+ [K in P extends `/api/${infer C}` ? `/${C}` : "/"]: {
113
+ [Method in Lowercase<M>]: E;
114
+ };
115
+ } : RouteTree<P extends `/api/${infer C}` ? C : "", M, E> : {};
116
+ type PluginAPIRouter<C> = C extends {
117
+ plugins: readonly (infer P)[];
118
+ } ? UnionToIntersection<P extends {
119
+ routes?: PluginRoutesFactory<infer R>;
120
+ } ? DefinitionTree<R[number]> : {}> : {};
121
+ declare function resolvePluginRoutes(plugins?: readonly {
122
+ name: string;
123
+ routes?: PluginRoutesFactory;
124
+ }[], context?: {
125
+ api?: PluginLocalAPI;
126
+ }): PluginRoutes;
127
+
128
+ export { type PluginRoutesFactory as P, type RouteMethod as R, type RoutePathParams as a, type RouteInputSchemas as b, type RouteJSON as c, type RouteDefinition as d, type RouteOptions as e, type RouteFactory as f, type PluginRoutes as g, type PluginLocalAPIEndpoint as h, type PluginLocalAPI as i, createRouteFactory as j, type PluginAPIRouter as k, resolvePluginRoutes as r };
@@ -1,4 +1,4 @@
1
- import { k as RouteModule } from './client-plugins-CslwYp3E.js';
1
+ import { k as RouteModule } from './client-plugins-CqVtZi5X.js';
2
2
 
3
3
  /**
4
4
  * The rendering-mode merge shared by every consumer of route directives.
@@ -1,4 +1,4 @@
1
- import { k as RouteModule } from './client-plugins-C1EgdoJM.mjs';
1
+ import { k as RouteModule } from './client-plugins-CIPRtSsW.mjs';
2
2
 
3
3
  /**
4
4
  * The rendering-mode merge shared by every consumer of route directives.
package/dist/routes.d.mts CHANGED
@@ -1,10 +1,11 @@
1
- import { F as FarmRouteRuntimeConfig, L as LayoutProps, M as Metadata, e as FarmRouteRuntime, f as FarmRouteRegions, g as FarmRouteMaxDuration, h as FarmAppContext, i as PageProps, j as PluginContextProps, k as RouteModule, P as ParsedRoute } from './client-plugins-C1EgdoJM.mjs';
1
+ import { F as FarmRouteRuntimeConfig, L as LayoutProps, M as Metadata, e as FarmRouteRuntime, f as FarmRouteRegions, g as FarmRouteMaxDuration, h as FarmAppContext, i as PageProps, j as PluginContextProps, k as RouteModule, P as ParsedRoute } from './client-plugins-CIPRtSsW.mjs';
2
2
  import { ComponentType } from 'react';
3
3
  import { RouteDataCacheKey } from './cache.mjs';
4
4
  import { ServerFn } from './server-fn.mjs';
5
5
  import { FarmServerRendererRuntime } from './renderer.mjs';
6
6
  import './lifecycle-DK06VuKP.mjs';
7
- import './route-C6UClI1z.mjs';
7
+ import './route-C_eLaFTZ.mjs';
8
+ import './endpoint-Bu3XgeMK.mjs';
8
9
  import 'http';
9
10
  import './markdown.mjs';
10
11
  import './types-Cc8l9IqS.mjs';
@@ -27,6 +28,7 @@ import './server-fn-error-DDh14a0V.mjs';
27
28
  import 'esbuild';
28
29
  import './image-config-Duob7wER.mjs';
29
30
  import './types-Z0aotQ8w.mjs';
31
+ import './server-query.mjs';
30
32
  import './types-DQnyD3VD.mjs';
31
33
  import './font.mjs';
32
34
  import './after.mjs';
package/dist/routes.d.ts CHANGED
@@ -1,10 +1,11 @@
1
- import { F as FarmRouteRuntimeConfig, L as LayoutProps, M as Metadata, e as FarmRouteRuntime, f as FarmRouteRegions, g as FarmRouteMaxDuration, h as FarmAppContext, i as PageProps, j as PluginContextProps, k as RouteModule, P as ParsedRoute } from './client-plugins-CslwYp3E.js';
1
+ import { F as FarmRouteRuntimeConfig, L as LayoutProps, M as Metadata, e as FarmRouteRuntime, f as FarmRouteRegions, g as FarmRouteMaxDuration, h as FarmAppContext, i as PageProps, j as PluginContextProps, k as RouteModule, P as ParsedRoute } from './client-plugins-CqVtZi5X.js';
2
2
  import { ComponentType } from 'react';
3
3
  import { RouteDataCacheKey } from './cache.js';
4
4
  import { ServerFn } from './server-fn.js';
5
5
  import { FarmServerRendererRuntime } from './renderer.js';
6
6
  import './lifecycle-DK06VuKP.js';
7
- import './route-CHBaW55F.js';
7
+ import './route-BxNJT447.js';
8
+ import './endpoint-kSAxE52R.js';
8
9
  import 'http';
9
10
  import './markdown.js';
10
11
  import './types-Cc8l9IqS.js';
@@ -27,6 +28,7 @@ import './server-fn-error-DDh14a0V.js';
27
28
  import 'esbuild';
28
29
  import './image-config-Duob7wER.js';
29
30
  import './types-Z0aotQ8w.js';
31
+ import './server-query.js';
30
32
  import './types-DQnyD3VD.js';
31
33
  import './font.js';
32
34
  import './after.js';
@@ -1,11 +1,12 @@
1
1
  import { FormHTMLAttributes, ComponentType } from 'react';
2
2
  import { ServerFn } from './server-fn.mjs';
3
- import { R as RetryOptions } from './api-client-C8d7BZNp.mjs';
3
+ import { R as RetryOptions } from './api-client-B-n3pm_Q.mjs';
4
4
  import './cache.mjs';
5
5
  import './server-fn-error-DDh14a0V.mjs';
6
+ import './endpoint-Bu3XgeMK.mjs';
6
7
  import './integration-api-BbaiokCC.mjs';
7
8
  import './client-cache-di_Nasxa.mjs';
8
- import './route-C6UClI1z.mjs';
9
+ import './route-C_eLaFTZ.mjs';
9
10
 
10
11
  type ServerFnActionStatus = "idle" | "pending" | "success" | "error";
11
12
  type ServerFnSubmit<TInput, TResult> = [unknown] extends [TInput] ? (input?: TInput | FormData) => Promise<TResult> : (input: TInput | FormData) => Promise<TResult>;
@@ -1,11 +1,12 @@
1
1
  import { FormHTMLAttributes, ComponentType } from 'react';
2
2
  import { ServerFn } from './server-fn.js';
3
- import { R as RetryOptions } from './api-client-BWrEbxfO.js';
3
+ import { R as RetryOptions } from './api-client-C0_NZEBl.js';
4
4
  import './cache.js';
5
5
  import './server-fn-error-DDh14a0V.js';
6
+ import './endpoint-kSAxE52R.js';
6
7
  import './integration-api-BbaiokCC.js';
7
8
  import './client-cache-Deoqq-nM.js';
8
- import './route-CHBaW55F.js';
9
+ import './route-BxNJT447.js';
9
10
 
10
11
  type ServerFnActionStatus = "idle" | "pending" | "success" | "error";
11
12
  type ServerFnSubmit<TInput, TResult> = [unknown] extends [TInput] ? (input?: TInput | FormData) => Promise<TResult> : (input: TInput | FormData) => Promise<TResult>;
@@ -25,9 +25,14 @@ __export(server_fn_exports, {
25
25
  FARM_SERVER_FN_SYMBOL: () => FARM_SERVER_FN_SYMBOL,
26
26
  ServerActionError: () => ServerActionError,
27
27
  ServerFnFailure: () => ServerFnFailure,
28
+ _attachServerFunctionDescriptor: () => _attachServerFunctionDescriptor,
29
+ _describeServerFunction: () => _describeServerFunction,
30
+ _invokeServerFunction: () => _invokeServerFunction,
28
31
  _parseServerFnSchema: () => _parseServerFnSchema,
32
+ _runServerFunctionForCaller: () => _runServerFunctionForCaller,
29
33
  createServerFn: () => createServerFn,
30
34
  createServerFnTransportError: () => createServerFnTransportError,
35
+ createServerFunctionDescriptor: () => createServerFunctionDescriptor,
31
36
  createServerMiddleware: () => createServerMiddleware,
32
37
  isServerFnFailure: () => isServerFnFailure
33
38
  });
@@ -137,6 +142,26 @@ __name(isSerializedServerFnFailure, "isSerializedServerFnFailure");
137
142
  // src/server-action-security.ts
138
143
  var SERVER_ACTION_STORAGE_KEY = /* @__PURE__ */ Symbol.for("farm.serverActionStorage");
139
144
  var FALLBACK_ABORT_CONTROLLER_KEY = /* @__PURE__ */ Symbol.for("farm.serverActionFallbackAbortController");
145
+ async function runWithServerActionRequest(request, callback) {
146
+ throwIfAborted(request.signal);
147
+ const context2 = {
148
+ request,
149
+ signal: request.signal,
150
+ invalidations: /* @__PURE__ */ new Set(),
151
+ cacheTasks: /* @__PURE__ */ new Set()
152
+ };
153
+ return getServerActionStorage().run(context2, async () => {
154
+ try {
155
+ const result = await callback();
156
+ await Promise.all(context2.cacheTasks);
157
+ return result;
158
+ } catch (error) {
159
+ await Promise.allSettled(context2.cacheTasks);
160
+ throw error;
161
+ }
162
+ });
163
+ }
164
+ __name(runWithServerActionRequest, "runWithServerActionRequest");
140
165
  function getServerActionExecutionContext() {
141
166
  return getServerActionStorage().getStore();
142
167
  }
@@ -167,6 +192,12 @@ function getFallbackAbortController() {
167
192
  return globalState2[FALLBACK_ABORT_CONTROLLER_KEY];
168
193
  }
169
194
  __name(getFallbackAbortController, "getFallbackAbortController");
195
+ function throwIfAborted(signal) {
196
+ if (!signal.aborted) return;
197
+ if (signal.reason !== void 0) throw signal.reason;
198
+ throw new DOMException("The operation was aborted", "AbortError");
199
+ }
200
+ __name(throwIfAborted, "throwIfAborted");
170
201
 
171
202
  // src/server/request-bridge.ts
172
203
  var CURRENT_REQUEST_RESOLVER_KEY = /* @__PURE__ */ Symbol.for("farm.currentRequestResolver");
@@ -1379,8 +1410,100 @@ function stableSerialize(value, seen = /* @__PURE__ */ new WeakSet()) {
1379
1410
  }
1380
1411
  __name(stableSerialize, "stableSerialize");
1381
1412
 
1413
+ // src/navigation-errors.ts
1414
+ var REDIRECT_ERROR_CODE = "FARM_REDIRECT";
1415
+ var REDIRECT_ERROR_SYMBOL = /* @__PURE__ */ Symbol.for("farm.navigation.redirect");
1416
+ function getFarmRedirectError(error) {
1417
+ if (!error || typeof error !== "object") return null;
1418
+ const candidate = error;
1419
+ if (candidate[REDIRECT_ERROR_SYMBOL]) {
1420
+ return candidate[REDIRECT_ERROR_SYMBOL];
1421
+ }
1422
+ if (typeof candidate.digest === "string" && candidate.digest.startsWith(`${REDIRECT_ERROR_CODE};`)) {
1423
+ const [, status, ...urlParts] = candidate.digest.split(";");
1424
+ const parsedStatus = Number(status);
1425
+ if (isFarmRedirectStatus(parsedStatus)) {
1426
+ return {
1427
+ status: parsedStatus,
1428
+ url: urlParts.join(";")
1429
+ };
1430
+ }
1431
+ }
1432
+ return null;
1433
+ }
1434
+ __name(getFarmRedirectError, "getFarmRedirectError");
1435
+ function isFarmRedirectStatus(status) {
1436
+ return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
1437
+ }
1438
+ __name(isFarmRedirectStatus, "isFarmRedirectStatus");
1439
+
1382
1440
  // src/server-fn.ts
1383
1441
  var FARM_SERVER_FN_SYMBOL = /* @__PURE__ */ Symbol.for("farm.server-fn");
1442
+ var FARM_SERVER_FUNCTION_DESCRIPTOR = /* @__PURE__ */ Symbol.for("farm.server-function.descriptor");
1443
+ var _ServerFnInputError = class _ServerFnInputError extends Error {
1444
+ constructor(cause) {
1445
+ super("Server function input is invalid");
1446
+ this.cause = cause;
1447
+ }
1448
+ };
1449
+ __name(_ServerFnInputError, "ServerFnInputError");
1450
+ var ServerFnInputError = _ServerFnInputError;
1451
+ function createServerFunctionDescriptor(kind, options, run) {
1452
+ return Object.freeze({
1453
+ kind,
1454
+ input: options.input,
1455
+ output: options.output,
1456
+ mcp: options.mcp === void 0 ? void 0 : Object.freeze({ ...options.mcp }),
1457
+ run
1458
+ });
1459
+ }
1460
+ __name(createServerFunctionDescriptor, "createServerFunctionDescriptor");
1461
+ function _attachServerFunctionDescriptor(target, descriptor) {
1462
+ Object.defineProperty(target, FARM_SERVER_FUNCTION_DESCRIPTOR, {
1463
+ value: descriptor,
1464
+ enumerable: false
1465
+ });
1466
+ }
1467
+ __name(_attachServerFunctionDescriptor, "_attachServerFunctionDescriptor");
1468
+ function getServerFunctionRunner(value) {
1469
+ if (typeof value !== "function") return void 0;
1470
+ return value[FARM_SERVER_FUNCTION_DESCRIPTOR];
1471
+ }
1472
+ __name(getServerFunctionRunner, "getServerFunctionRunner");
1473
+ function _runServerFunctionForCaller(value, input) {
1474
+ const runner = getServerFunctionRunner(value);
1475
+ if (!runner) throw new TypeError("Expected a function created with createServerFn");
1476
+ return runner.run(input);
1477
+ }
1478
+ __name(_runServerFunctionForCaller, "_runServerFunctionForCaller");
1479
+ function _describeServerFunction(value) {
1480
+ const runner = getServerFunctionRunner(value);
1481
+ if (!runner) return void 0;
1482
+ const { kind, input, output, mcp } = runner;
1483
+ return Object.freeze({ kind, input, output, mcp });
1484
+ }
1485
+ __name(_describeServerFunction, "_describeServerFunction");
1486
+ async function _invokeServerFunction(value, input, request) {
1487
+ const runner = getServerFunctionRunner(value);
1488
+ if (!runner) {
1489
+ throw new TypeError("Expected a function created with createServerFn or createServerQuery");
1490
+ }
1491
+ try {
1492
+ const data = await runWithServerActionRequest(request, () => runner.run(input));
1493
+ return { ok: true, data };
1494
+ } catch (error) {
1495
+ if (error instanceof ServerFnInputError) {
1496
+ return { ok: false, reason: "input", error: error.cause };
1497
+ }
1498
+ if (isServerFnFailure(error)) return { ok: false, reason: "failure", failure: error };
1499
+ const redirect = getFarmRedirectError(error);
1500
+ if (redirect) {
1501
+ return { ok: false, reason: "redirect", url: redirect.url, status: redirect.status };
1502
+ }
1503
+ return { ok: false, reason: "error", error };
1504
+ }
1505
+ }
1506
+ __name(_invokeServerFunction, "_invokeServerFunction");
1384
1507
  var UNSAFE_FORM_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
1385
1508
  function createServerMiddleware(options) {
1386
1509
  if (!options || typeof options.handler !== "function") {
@@ -1404,10 +1527,15 @@ function createServerFn(options) {
1404
1527
  const middleware = resolveServerFnMiddleware(options.middleware);
1405
1528
  const errors = normalizeServerFnErrors(options.errors);
1406
1529
  const error = createServerFnErrorHandler(errors);
1407
- const serverFn = /* @__PURE__ */ __name(async (value) => {
1530
+ const run = /* @__PURE__ */ __name(async (value, labelInputErrors) => {
1408
1531
  const formData = isFormData(value) ? value : void 0;
1409
1532
  const rawInput = formData ? formDataToObject(formData) : value;
1410
- const input = await _parseServerFnSchema(options.input, rawInput, "input");
1533
+ let input;
1534
+ try {
1535
+ input = await _parseServerFnSchema(options.input, rawInput, "input");
1536
+ } catch (cause) {
1537
+ throw labelInputErrors ? new ServerFnInputError(cause) : cause;
1538
+ }
1411
1539
  const executionContext = getServerActionExecutionContext();
1412
1540
  const request = executionContext?.request ?? _resolveCurrentRequest();
1413
1541
  const signal = executionContext?.signal ?? request?.signal ?? getServerActionSignal();
@@ -1433,7 +1561,8 @@ function createServerFn(options) {
1433
1561
  await applyFarmCacheInvalidationTargets(declaration);
1434
1562
  }
1435
1563
  return parsedResult;
1436
- }, "serverFn");
1564
+ }, "run");
1565
+ const serverFn = /* @__PURE__ */ __name((value) => run(value, false), "serverFn");
1437
1566
  Object.defineProperties(serverFn, {
1438
1567
  [FARM_SERVER_FN_SYMBOL]: {
1439
1568
  value: true,
@@ -1464,6 +1593,10 @@ function createServerFn(options) {
1464
1593
  enumerable: false
1465
1594
  }
1466
1595
  });
1596
+ _attachServerFunctionDescriptor(
1597
+ serverFn,
1598
+ createServerFunctionDescriptor("action", options, (value) => run(value, true))
1599
+ );
1467
1600
  return serverFn;
1468
1601
  }
1469
1602
  __name(createServerFn, "createServerFn");
@@ -1665,9 +1798,14 @@ __name(isFormData, "isFormData");
1665
1798
  FARM_SERVER_FN_SYMBOL,
1666
1799
  ServerActionError,
1667
1800
  ServerFnFailure,
1801
+ _attachServerFunctionDescriptor,
1802
+ _describeServerFunction,
1803
+ _invokeServerFunction,
1668
1804
  _parseServerFnSchema,
1805
+ _runServerFunctionForCaller,
1669
1806
  createServerFn,
1670
1807
  createServerFnTransportError,
1808
+ createServerFunctionDescriptor,
1671
1809
  createServerMiddleware,
1672
1810
  isServerFnFailure
1673
1811
  });
@@ -1,6 +1,7 @@
1
1
  import { FarmCacheInvalidationTarget } from './cache.mjs';
2
2
  import { S as ServerFnFailure, a as ServerActionError } from './server-fn-error-DDh14a0V.mjs';
3
3
  export { F as FARM_SERVER_FN_FAILURE_SYMBOL, b as SerializedServerFnFailure, c as createServerFnTransportError, i as isServerFnFailure } from './server-fn-error-DDh14a0V.mjs';
4
+ import { d as EndpointMCPMetadata } from './endpoint-Bu3XgeMK.mjs';
4
5
 
5
6
  type MaybePromise<T> = T | Promise<T>;
6
7
  type ServerFnSchema = {
@@ -38,6 +39,10 @@ type ServerFnDeclaredError<TErrors extends ServerFnErrorDefinitions> = {
38
39
  type ServerFnError<TErrors extends ServerFnErrorDefinitions> = keyof TErrors extends never ? Error : ServerActionError | ServerFnDeclaredError<TErrors>;
39
40
  type ServerFnErrorHandler<TErrors extends ServerFnErrorDefinitions> = <TCode extends keyof TErrors & string>(code: TCode, data: InferServerFnSchemaInput<TErrors[TCode]["data"]>) => never;
40
41
  type ServerFnFormInput = FormData;
42
+ /** MCP tool metadata for a server function or query. Server functions have no path to derive a name from. */
43
+ type ServerFnMCPMetadata = EndpointMCPMetadata & {
44
+ name: string;
45
+ };
41
46
  type Simplify<T> = {
42
47
  [TKey in keyof T]: T[TKey];
43
48
  } & {};
@@ -92,6 +97,8 @@ type ServerFnOptions<TSchema extends ServerFnSchema | undefined, TResult, TMiddl
92
97
  output?: undefined;
93
98
  middleware?: TMiddlewares;
94
99
  errors?: TErrors;
100
+ /** Expose this function as an MCP tool when it is listed in `mcp.tools`. `name` is required. */
101
+ mcp?: ServerFnMCPMetadata;
95
102
  invalidates?: ServerFnInvalidations<TSchema extends ServerFnSchema ? InferServerFnSchemaOutput<TSchema> : unknown, Awaited<TResult>, ServerFnMiddlewareContext<TMiddlewares>>;
96
103
  handler: ServerFnHandler<TSchema extends ServerFnSchema ? InferServerFnSchemaOutput<TSchema> : unknown, TResult, ServerFnMiddlewareContext<TMiddlewares>, TErrors>;
97
104
  };
@@ -100,6 +107,8 @@ type ServerFnOutputOptions<TInputSchema extends ServerFnSchema | undefined, TOut
100
107
  output: TOutputSchema;
101
108
  middleware?: TMiddlewares;
102
109
  errors?: TErrors;
110
+ /** Expose this function as an MCP tool when it is listed in `mcp.tools`. `name` is required. */
111
+ mcp?: ServerFnMCPMetadata;
103
112
  invalidates?: ServerFnInvalidations<TInputSchema extends ServerFnSchema ? InferServerFnSchemaOutput<TInputSchema> : unknown, Awaited<InferServerFnSchemaOutput<TOutputSchema>>, ServerFnMiddlewareContext<TMiddlewares>>;
104
113
  handler: ServerFnHandler<TInputSchema extends ServerFnSchema ? InferServerFnSchemaOutput<TInputSchema> : unknown, unknown, ServerFnMiddlewareContext<TMiddlewares>, TErrors>;
105
114
  };
@@ -111,6 +120,68 @@ type ServerFn<TInput, TResult, TError extends Error = Error> = ([unknown] extend
111
120
  };
112
121
  type InferServerFnError<TServerFn> = TServerFn extends ServerFn<any, any, infer TError> ? TError : Error;
113
122
  declare const FARM_SERVER_FN_SYMBOL: unique symbol;
123
+ /** @internal What a non-browser caller, such as an MCP tool, needs to know about a server function. */
124
+ interface ServerFunctionDescriptor {
125
+ /** Queries only read data; actions may change it. */
126
+ readonly kind: "action" | "query";
127
+ readonly input: ServerFnSchema | undefined;
128
+ readonly output: ServerFnSchema | undefined;
129
+ readonly mcp: Readonly<ServerFnMCPMetadata> | undefined;
130
+ }
131
+ interface ServerFunctionRunner extends ServerFunctionDescriptor {
132
+ /** Runs the full pipeline and labels input validation failures with ServerFnInputError. */
133
+ readonly run: (input: unknown) => Promise<unknown>;
134
+ }
135
+ /** @internal Shared by createServerFn and createServerQuery. */
136
+ declare function createServerFunctionDescriptor(kind: ServerFunctionDescriptor["kind"], options: {
137
+ input?: ServerFnSchema;
138
+ output?: ServerFnSchema;
139
+ mcp?: ServerFnMCPMetadata;
140
+ }, run: ServerFunctionRunner["run"]): ServerFunctionRunner;
141
+ /** @internal Attaches the descriptor that `_describeServerFunction` reads. */
142
+ declare function _attachServerFunctionDescriptor(target: object, descriptor: ServerFunctionRunner): void;
143
+ /** @internal Runs a server function's pipeline with input failures labelled, for createServerQuery. */
144
+ declare function _runServerFunctionForCaller(value: unknown, input: unknown): Promise<unknown>;
145
+ /**
146
+ * @internal Describes a createServerFn or createServerQuery function, or returns undefined for
147
+ * anything else. Exposes schemas and metadata, never the handler.
148
+ */
149
+ declare function _describeServerFunction(value: unknown): ServerFunctionDescriptor | undefined;
150
+ /** @internal How a server function call ended, for callers that are not the browser action transport. */
151
+ type ServerFunctionInvocation = {
152
+ readonly ok: true;
153
+ readonly data: unknown;
154
+ }
155
+ /** The caller's input failed the input schema. The validator's error describes the caller's own data. */
156
+ | {
157
+ readonly ok: false;
158
+ readonly reason: "input";
159
+ readonly error: unknown;
160
+ }
161
+ /** A failure declared in `errors`, public by design. */
162
+ | {
163
+ readonly ok: false;
164
+ readonly reason: "failure";
165
+ readonly failure: ServerFnFailure;
166
+ } | {
167
+ readonly ok: false;
168
+ readonly reason: "redirect";
169
+ readonly url: string;
170
+ readonly status: number;
171
+ }
172
+ /** Anything else. Can contain private data, so callers must not expose it. */
173
+ | {
174
+ readonly ok: false;
175
+ readonly reason: "error";
176
+ readonly error: unknown;
177
+ };
178
+ /**
179
+ * @internal Runs a server function or query on behalf of a non-browser caller, such as an MCP
180
+ * tool call. Runs the same pipeline as a browser action (input schema, middleware, handler,
181
+ * output schema, invalidations) with `request` as the action request, so middleware reads the
182
+ * caller's headers. A query resolves to its data rather than the client cache envelope.
183
+ */
184
+ declare function _invokeServerFunction(value: unknown, input: unknown, request: Request): Promise<ServerFunctionInvocation>;
114
185
  declare function createServerMiddleware<const TMiddlewares extends readonly AnyServerFnMiddleware[] = readonly [], TProvidedContext extends object = {}>(options: ServerFnMiddlewareOptions<TMiddlewares, TProvidedContext>): ServerFnMiddleware<AssignContext<ServerFnMiddlewareContext<TMiddlewares>, TProvidedContext>>;
115
186
  declare function createServerFn<TInputSchema extends ServerFnSchema, TOutputSchema extends ServerFnSchema, const TMiddlewares extends readonly AnyServerFnMiddleware[] = readonly [], const TErrors extends ServerFnErrorDefinitions = {}>(options: ServerFnOutputOptions<TInputSchema, TOutputSchema, TMiddlewares, TErrors>): ServerFn<InferServerFnSchemaInput<TInputSchema>, Awaited<InferServerFnSchemaOutput<TOutputSchema>>, ServerFnError<TErrors>>;
116
187
  declare function createServerFn<TOutputSchema extends ServerFnSchema, const TMiddlewares extends readonly AnyServerFnMiddleware[] = readonly [], const TErrors extends ServerFnErrorDefinitions = {}>(options: ServerFnOutputOptions<undefined, TOutputSchema, TMiddlewares, TErrors>): ServerFn<unknown, Awaited<InferServerFnSchemaOutput<TOutputSchema>>, ServerFnError<TErrors>>;
@@ -118,4 +189,4 @@ declare function createServerFn<TSchema extends ServerFnSchema, TResult, const T
118
189
  declare function createServerFn<TResult, const TMiddlewares extends readonly AnyServerFnMiddleware[] = readonly [], const TErrors extends ServerFnErrorDefinitions = {}>(options: ServerFnOptions<undefined, TResult, TMiddlewares, TErrors>): ServerFn<unknown, Awaited<TResult>, ServerFnError<TErrors>>;
119
190
  declare function _parseServerFnSchema(schema: ServerFnSchema | undefined, value: unknown, contract: "input" | "output", owner?: string): Promise<any>;
120
191
 
121
- export { type AnyServerFnMiddleware, FARM_SERVER_FN_SYMBOL, type InferServerFnError, type InferServerFnSchemaInput, type InferServerFnSchemaOutput, ServerActionError, type ServerFn, type ServerFnContext, type ServerFnDeclaredError, type ServerFnError, type ServerFnErrorDefinition, type ServerFnErrorDefinitions, type ServerFnErrorHandler, type ServerFnErrorSchema, ServerFnFailure, type ServerFnFormInput, type ServerFnHandler, type ServerFnHandlerContext, type ServerFnInvalidationContext, type ServerFnInvalidations, type ServerFnMiddleware, type ServerFnMiddlewareContext, type ServerFnMiddlewareContinuation, type ServerFnMiddlewareHandler, type ServerFnMiddlewareHandlerContext, type ServerFnMiddlewareNext, type ServerFnMiddlewareOptions, type ServerFnOptions, type ServerFnOutputOptions, type ServerFnSchema, _parseServerFnSchema, createServerFn, createServerMiddleware };
192
+ export { type AnyServerFnMiddleware, FARM_SERVER_FN_SYMBOL, type InferServerFnError, type InferServerFnSchemaInput, type InferServerFnSchemaOutput, ServerActionError, type ServerFn, type ServerFnContext, type ServerFnDeclaredError, type ServerFnError, type ServerFnErrorDefinition, type ServerFnErrorDefinitions, type ServerFnErrorHandler, type ServerFnErrorSchema, ServerFnFailure, type ServerFnFormInput, type ServerFnHandler, type ServerFnHandlerContext, type ServerFnInvalidationContext, type ServerFnInvalidations, type ServerFnMCPMetadata, type ServerFnMiddleware, type ServerFnMiddlewareContext, type ServerFnMiddlewareContinuation, type ServerFnMiddlewareHandler, type ServerFnMiddlewareHandlerContext, type ServerFnMiddlewareNext, type ServerFnMiddlewareOptions, type ServerFnOptions, type ServerFnOutputOptions, type ServerFnSchema, type ServerFunctionDescriptor, type ServerFunctionInvocation, _attachServerFunctionDescriptor, _describeServerFunction, _invokeServerFunction, _parseServerFnSchema, _runServerFunctionForCaller, createServerFn, createServerFunctionDescriptor, createServerMiddleware };