@farm.js/core 0.1.14 → 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-DNCKVMSV.mjs → chunk-IL5RWYK7.mjs} +1 -1
  19. package/dist/{chunk-GNTPTTLA.mjs → chunk-IXTEENRS.mjs} +1 -1
  20. package/dist/{chunk-J2F5LFQ2.mjs → chunk-NHHKW2T6.mjs} +175 -8
  21. package/dist/{chunk-NJ47VORC.mjs → chunk-NUD6XBMO.mjs} +1 -1
  22. package/dist/{chunk-U6CRU23N.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 +383 -24
  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 +435 -174
  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 +278 -11
  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 +331 -15
  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 +416 -153
  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 +3 -3
package/dist/request.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- export { g as getCurrentRequest } from './request-DsVSQVfD.js';
2
- import './client-plugins-CslwYp3E.js';
1
+ export { g as getCurrentRequest } from './request-G8JhKr4F.js';
2
+ import './client-plugins-CqVtZi5X.js';
3
3
  import './lifecycle-DK06VuKP.js';
4
- import './route-CHBaW55F.js';
4
+ import './route-BxNJT447.js';
5
+ import './endpoint-kSAxE52R.js';
5
6
  import './cache.js';
6
7
  import './renderer.js';
7
8
  import './deployment.js';
@@ -28,6 +29,8 @@ import './server-fn-error-DDh14a0V.js';
28
29
  import 'esbuild';
29
30
  import './image-config-Duob7wER.js';
30
31
  import './types-Z0aotQ8w.js';
32
+ import './server-fn.js';
33
+ import './server-query.js';
31
34
  import './types-DQnyD3VD.js';
32
35
  import './font.js';
33
36
  import './after.js';
@@ -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-kSAxE52R.js';
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 };
@@ -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
  });