@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
package/dist/plugin.cjs CHANGED
@@ -32,8 +32,27 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
32
32
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
33
 
34
34
  // src/env.ts
35
+ function createBundledEnv(env2, source = getProcessEnv()) {
36
+ const resolved = normalizeResolvedEnv(env2 ?? {});
37
+ const server = {};
38
+ const runtime3 = {};
39
+ for (const [key, value] of Object.entries(resolved.server)) {
40
+ if (source[key] === void 0) {
41
+ server[key] = value;
42
+ } else {
43
+ runtime3[key] = getRuntimeEnvType(value);
44
+ }
45
+ }
46
+ return {
47
+ server,
48
+ public: resolved.public,
49
+ ...Object.keys(runtime3).length > 0 ? { runtime: { server: runtime3 } } : {}
50
+ };
51
+ }
35
52
  function getResolvedEnv() {
36
- return getCurrentEnv();
53
+ const env2 = getCurrentEnv();
54
+ if (typeof window === "undefined") readRuntimeServerEnv(env2);
55
+ return env2;
37
56
  }
38
57
  function createEnvProxy(scope) {
39
58
  return new Proxy(
@@ -44,7 +63,7 @@ function createEnvProxy(scope) {
44
63
  return void 0;
45
64
  }
46
65
  const env2 = getEnvScope(scope);
47
- return env2[property];
66
+ return scope === "server" ? readServerEnvKey(env2, property) : env2[property];
48
67
  },
49
68
  ownKeys() {
50
69
  return Reflect.ownKeys(getEnvScope(scope));
@@ -67,10 +86,75 @@ function createEnvProxy(scope) {
67
86
  );
68
87
  }
69
88
  function getEnvScope(scope) {
89
+ const env2 = getCurrentEnv();
70
90
  if (scope === "server") {
71
91
  assertServerEnvAccess();
92
+ readRuntimeServerEnv(env2);
93
+ }
94
+ return env2[scope] || {};
95
+ }
96
+ function readServerEnvKey(server, key) {
97
+ const value = server[key];
98
+ if (value === void 0) {
99
+ const state = getCurrentEnv()[FARM_ENV_RUNTIME_SYMBOL];
100
+ if (state && key in state.pending && !state.warned.has(key)) {
101
+ state.warned.add(key);
102
+ console.warn(
103
+ `[Farm] Server env "${key}" was set when this app was built but is not set where the server runs, so it reads as undefined. Farm reads server env at runtime and does not store it in the build output; set "${key}" in the server's environment.`
104
+ );
105
+ }
72
106
  }
73
- return getCurrentEnv()[scope] || {};
107
+ return value;
108
+ }
109
+ function readRuntimeServerEnv(env2) {
110
+ const state = env2[FARM_ENV_RUNTIME_SYMBOL];
111
+ if (!state) return;
112
+ const source = getProcessEnv();
113
+ for (const [key, type] of Object.entries(state.pending)) {
114
+ const raw = source[key];
115
+ if (raw === void 0) continue;
116
+ env2.server[key] = coerceRuntimeEnvValue(raw, type);
117
+ delete state.pending[key];
118
+ }
119
+ }
120
+ function getRuntimeEnvType(value) {
121
+ if (typeof value === "number") return "number";
122
+ if (typeof value === "boolean") return "boolean";
123
+ if (value !== null && typeof value === "object" && !(value instanceof Date)) return "json";
124
+ return "string";
125
+ }
126
+ function coerceRuntimeEnvValue(raw, type) {
127
+ if (type === "number") {
128
+ const value = Number(raw);
129
+ return raw.trim() !== "" && Number.isFinite(value) ? value : raw;
130
+ }
131
+ if (type === "boolean") {
132
+ if (/^(true|1)$/i.test(raw.trim())) return true;
133
+ if (/^(false|0|)$/i.test(raw.trim())) return false;
134
+ return raw;
135
+ }
136
+ if (type === "json") {
137
+ try {
138
+ return JSON.parse(raw);
139
+ } catch {
140
+ return raw;
141
+ }
142
+ }
143
+ return raw;
144
+ }
145
+ function prepareEnv(env2) {
146
+ const normalized = normalizeResolvedEnv(env2);
147
+ const runtime3 = env2.runtime?.server;
148
+ if (!isRecord(runtime3) || Object.keys(runtime3).length === 0) return normalized;
149
+ const prepared = { server: { ...normalized.server }, public: normalized.public };
150
+ Object.defineProperty(prepared, FARM_ENV_RUNTIME_SYMBOL, {
151
+ value: {
152
+ pending: { ...runtime3 },
153
+ warned: /* @__PURE__ */ new Set()
154
+ },
155
+ enumerable: false
156
+ });
157
+ return prepared;
74
158
  }
75
159
  function assertServerEnvAccess() {
76
160
  if (typeof window !== "undefined") {
@@ -99,7 +183,7 @@ function getCurrentEnv() {
99
183
  function getInjectedEnv() {
100
184
  try {
101
185
  if (typeof __FARM_ENV__ !== "undefined" && __FARM_ENV__) {
102
- return normalizeResolvedEnv(__FARM_ENV__);
186
+ return prepareEnv(__FARM_ENV__);
103
187
  }
104
188
  } catch {
105
189
  }
@@ -123,18 +207,31 @@ function normalizeResolvedEnv(env2) {
123
207
  function isRecord(value) {
124
208
  return !!value && typeof value === "object" && !Array.isArray(value);
125
209
  }
126
- var FARM_ENV_SYMBOL, farmEnvGlobal, currentEnv, env, publicEnv;
210
+ function getProcessEnv() {
211
+ if (typeof process !== "undefined" && process.env) {
212
+ return process.env;
213
+ }
214
+ return {};
215
+ }
216
+ var FARM_ENV_SYMBOL, FARM_ENV_RUNTIME_SYMBOL, farmEnvGlobal, currentEnv, env, publicEnv;
127
217
  var init_env = __esm({
128
218
  "src/env.ts"() {
129
219
  "use strict";
130
220
  FARM_ENV_SYMBOL = /* @__PURE__ */ Symbol.for("farm.env");
221
+ FARM_ENV_RUNTIME_SYMBOL = /* @__PURE__ */ Symbol.for("farm.env.runtime");
131
222
  farmEnvGlobal = globalThis;
132
223
  currentEnv = getInitialEnv();
224
+ __name(createBundledEnv, "createBundledEnv");
133
225
  __name(getResolvedEnv, "getResolvedEnv");
134
226
  env = createEnvProxy("server");
135
227
  publicEnv = createEnvProxy("public");
136
228
  __name(createEnvProxy, "createEnvProxy");
137
229
  __name(getEnvScope, "getEnvScope");
230
+ __name(readServerEnvKey, "readServerEnvKey");
231
+ __name(readRuntimeServerEnv, "readRuntimeServerEnv");
232
+ __name(getRuntimeEnvType, "getRuntimeEnvType");
233
+ __name(coerceRuntimeEnvValue, "coerceRuntimeEnvValue");
234
+ __name(prepareEnv, "prepareEnv");
138
235
  __name(assertServerEnvAccess, "assertServerEnvAccess");
139
236
  __name(getInitialEnv, "getInitialEnv");
140
237
  __name(getCurrentEnv, "getCurrentEnv");
@@ -142,6 +239,7 @@ var init_env = __esm({
142
239
  __name(getInjectedPublicEnv, "getInjectedPublicEnv");
143
240
  __name(normalizeResolvedEnv, "normalizeResolvedEnv");
144
241
  __name(isRecord, "isRecord");
242
+ __name(getProcessEnv, "getProcessEnv");
145
243
  }
146
244
  });
147
245
 
@@ -17249,6 +17347,9 @@ function normalizeRuntimeEndpointRequestPath(pathname) {
17249
17347
  }
17250
17348
  __name(normalizeRuntimeEndpointRequestPath, "normalizeRuntimeEndpointRequestPath");
17251
17349
 
17350
+ // src/vite.ts
17351
+ init_env();
17352
+
17252
17353
  // src/app.ts
17253
17354
  init_app_markdown_config();
17254
17355
  init_markdown();
@@ -24874,7 +24975,7 @@ _setFarmThemeServerSnapshotResolver(() => {
24874
24975
  });
24875
24976
 
24876
24977
  // package.json
24877
- var version = "0.1.15";
24978
+ var version = "0.1.16";
24878
24979
 
24879
24980
  // src/version.ts
24880
24981
  var FARM_VERSION = version;
@@ -32151,7 +32252,7 @@ function getEnvDefines(config, configEnv) {
32151
32252
  )
32152
32253
  };
32153
32254
  if (configEnv?.isSsrBuild) {
32154
- defines.__FARM_ENV__ = JSON.stringify(getFullEnvDefine(config));
32255
+ defines.__FARM_ENV__ = JSON.stringify(createBundledEnv(getFullEnvDefine(config)));
32155
32256
  }
32156
32257
  return defines;
32157
32258
  }
package/dist/plugin.d.mts CHANGED
@@ -1,5 +1,6 @@
1
- export { r as EndpointMCPMetadata, s as EndpointMCPOptions, a as EndpointOpenAPIMetadata, a3 as PluginLocalAPI, a2 as PluginLocalAPIEndpoint, a1 as PluginRoutes, P as PluginRoutesFactory, _ as RouteDefinition, W as RouteMethod, a7 as RouteSchema } from './route-C6UClI1z.mjs';
2
- export { c9 as APIHandlerLifecyclePayload, c5 as APIRouteDiscoveredPayload, cc as BundleLifecyclePayload, B as BundleResultPayload, ca as ErrorLifecyclePayload, fa as FARM_NODE_RESPONSE_END_PENDING, a as FarmPlugin, b$ as FarmPluginBuildHooks, c1 as FarmPluginClientConfig, d as FarmPluginContext, aV as FarmPluginDatabase, aW as FarmPluginDefinition, c0 as FarmPluginDevHooks, bY as FarmPluginDiscoveredRoute, bD as FarmPluginIntegrationContext, bE as FarmPluginLifecycle, b_ as FarmPluginRenderHooks, bI as FarmPluginRouteRuntimePayload, bZ as FarmPluginRouterHooks, bQ as FarmPluginRuntimeAfterEvent, bL as FarmPluginRuntimeBaseEvent, bP as FarmPluginRuntimeBeforeEvent, bT as FarmPluginRuntimeCloseEvent, bM as FarmPluginRuntimeContextEvent, bN as FarmPluginRuntimeEndpoint, bO as FarmPluginRuntimeEndpointEvent, bR as FarmPluginRuntimeErrorEvent, bU as FarmPluginRuntimeHooks, bH as FarmPluginRuntimeKind, bW as FarmPluginRuntimeRequestHandler, bV as FarmPluginRuntimeRequestOptions, bX as FarmPluginRuntimeSession, bS as FarmPluginRuntimeStartEvent, bJ as FarmPluginSetupContext, bK as FarmPluginStateContext, bF as FarmRequestPluginContext, bG as FarmRequestStore, aT as FarmRuntimeShutdownError, cb as HMRUpdatePayload, c4 as MiddlewareDiscoveredPayload, cd as NitroBuildLifecyclePayload, aU as PluginManager, bC as PluginRequestContext, c8 as RenderLifecyclePayload, c2 as RouteDiscoveredPayload, c6 as RouteMatchPayload, c7 as RouteMatchResultPayload, c3 as RoutesGeneratedPayload, ce as ShutdownPayload, aS as definePlugin, x as farmPlugin } from './client-plugins-C1EgdoJM.mjs';
1
+ export { i as PluginLocalAPI, h as PluginLocalAPIEndpoint, g as PluginRoutes, P as PluginRoutesFactory, d as RouteDefinition, R as RouteMethod } from './route-C_eLaFTZ.mjs';
2
+ export { d as EndpointMCPMetadata, b as EndpointMCPOptions, f as EndpointOpenAPIMetadata, R as RouteSchema } from './endpoint-Bu3XgeMK.mjs';
3
+ export { ca as APIHandlerLifecyclePayload, c6 as APIRouteDiscoveredPayload, cd as BundleLifecyclePayload, B as BundleResultPayload, cb as ErrorLifecyclePayload, fb as FARM_NODE_RESPONSE_END_PENDING, a as FarmPlugin, c0 as FarmPluginBuildHooks, c2 as FarmPluginClientConfig, d as FarmPluginContext, aV as FarmPluginDatabase, aW as FarmPluginDefinition, c1 as FarmPluginDevHooks, bZ as FarmPluginDiscoveredRoute, bE as FarmPluginIntegrationContext, bF as FarmPluginLifecycle, b$ as FarmPluginRenderHooks, bJ as FarmPluginRouteRuntimePayload, b_ as FarmPluginRouterHooks, bR as FarmPluginRuntimeAfterEvent, bM as FarmPluginRuntimeBaseEvent, bQ as FarmPluginRuntimeBeforeEvent, bU as FarmPluginRuntimeCloseEvent, bN as FarmPluginRuntimeContextEvent, bO as FarmPluginRuntimeEndpoint, bP as FarmPluginRuntimeEndpointEvent, bS as FarmPluginRuntimeErrorEvent, bV as FarmPluginRuntimeHooks, bI as FarmPluginRuntimeKind, bX as FarmPluginRuntimeRequestHandler, bW as FarmPluginRuntimeRequestOptions, bY as FarmPluginRuntimeSession, bT as FarmPluginRuntimeStartEvent, bK as FarmPluginSetupContext, bL as FarmPluginStateContext, bG as FarmRequestPluginContext, bH as FarmRequestStore, aT as FarmRuntimeShutdownError, cc as HMRUpdatePayload, c5 as MiddlewareDiscoveredPayload, ce as NitroBuildLifecyclePayload, aU as PluginManager, bD as PluginRequestContext, c9 as RenderLifecyclePayload, c3 as RouteDiscoveredPayload, c7 as RouteMatchPayload, c8 as RouteMatchResultPayload, c4 as RoutesGeneratedPayload, cf as ShutdownPayload, aS as definePlugin, x as farmPlugin } from './client-plugins-CIPRtSsW.mjs';
3
4
  import 'vite';
4
5
  import './lifecycle-DK06VuKP.mjs';
5
6
  import './env.mjs';
@@ -27,6 +28,8 @@ 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-fn.mjs';
32
+ import './server-query.mjs';
30
33
  import './types-DQnyD3VD.mjs';
31
34
  import './font.mjs';
32
35
  import './after.mjs';
package/dist/plugin.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- export { r as EndpointMCPMetadata, s as EndpointMCPOptions, a as EndpointOpenAPIMetadata, a3 as PluginLocalAPI, a2 as PluginLocalAPIEndpoint, a1 as PluginRoutes, P as PluginRoutesFactory, _ as RouteDefinition, W as RouteMethod, a7 as RouteSchema } from './route-CHBaW55F.js';
2
- export { c9 as APIHandlerLifecyclePayload, c5 as APIRouteDiscoveredPayload, cc as BundleLifecyclePayload, B as BundleResultPayload, ca as ErrorLifecyclePayload, fa as FARM_NODE_RESPONSE_END_PENDING, a as FarmPlugin, b$ as FarmPluginBuildHooks, c1 as FarmPluginClientConfig, d as FarmPluginContext, aV as FarmPluginDatabase, aW as FarmPluginDefinition, c0 as FarmPluginDevHooks, bY as FarmPluginDiscoveredRoute, bD as FarmPluginIntegrationContext, bE as FarmPluginLifecycle, b_ as FarmPluginRenderHooks, bI as FarmPluginRouteRuntimePayload, bZ as FarmPluginRouterHooks, bQ as FarmPluginRuntimeAfterEvent, bL as FarmPluginRuntimeBaseEvent, bP as FarmPluginRuntimeBeforeEvent, bT as FarmPluginRuntimeCloseEvent, bM as FarmPluginRuntimeContextEvent, bN as FarmPluginRuntimeEndpoint, bO as FarmPluginRuntimeEndpointEvent, bR as FarmPluginRuntimeErrorEvent, bU as FarmPluginRuntimeHooks, bH as FarmPluginRuntimeKind, bW as FarmPluginRuntimeRequestHandler, bV as FarmPluginRuntimeRequestOptions, bX as FarmPluginRuntimeSession, bS as FarmPluginRuntimeStartEvent, bJ as FarmPluginSetupContext, bK as FarmPluginStateContext, bF as FarmRequestPluginContext, bG as FarmRequestStore, aT as FarmRuntimeShutdownError, cb as HMRUpdatePayload, c4 as MiddlewareDiscoveredPayload, cd as NitroBuildLifecyclePayload, aU as PluginManager, bC as PluginRequestContext, c8 as RenderLifecyclePayload, c2 as RouteDiscoveredPayload, c6 as RouteMatchPayload, c7 as RouteMatchResultPayload, c3 as RoutesGeneratedPayload, ce as ShutdownPayload, aS as definePlugin, x as farmPlugin } from './client-plugins-CslwYp3E.js';
1
+ export { i as PluginLocalAPI, h as PluginLocalAPIEndpoint, g as PluginRoutes, P as PluginRoutesFactory, d as RouteDefinition, R as RouteMethod } from './route-BxNJT447.js';
2
+ export { d as EndpointMCPMetadata, b as EndpointMCPOptions, f as EndpointOpenAPIMetadata, R as RouteSchema } from './endpoint-kSAxE52R.js';
3
+ export { ca as APIHandlerLifecyclePayload, c6 as APIRouteDiscoveredPayload, cd as BundleLifecyclePayload, B as BundleResultPayload, cb as ErrorLifecyclePayload, fb as FARM_NODE_RESPONSE_END_PENDING, a as FarmPlugin, c0 as FarmPluginBuildHooks, c2 as FarmPluginClientConfig, d as FarmPluginContext, aV as FarmPluginDatabase, aW as FarmPluginDefinition, c1 as FarmPluginDevHooks, bZ as FarmPluginDiscoveredRoute, bE as FarmPluginIntegrationContext, bF as FarmPluginLifecycle, b$ as FarmPluginRenderHooks, bJ as FarmPluginRouteRuntimePayload, b_ as FarmPluginRouterHooks, bR as FarmPluginRuntimeAfterEvent, bM as FarmPluginRuntimeBaseEvent, bQ as FarmPluginRuntimeBeforeEvent, bU as FarmPluginRuntimeCloseEvent, bN as FarmPluginRuntimeContextEvent, bO as FarmPluginRuntimeEndpoint, bP as FarmPluginRuntimeEndpointEvent, bS as FarmPluginRuntimeErrorEvent, bV as FarmPluginRuntimeHooks, bI as FarmPluginRuntimeKind, bX as FarmPluginRuntimeRequestHandler, bW as FarmPluginRuntimeRequestOptions, bY as FarmPluginRuntimeSession, bT as FarmPluginRuntimeStartEvent, bK as FarmPluginSetupContext, bL as FarmPluginStateContext, bG as FarmRequestPluginContext, bH as FarmRequestStore, aT as FarmRuntimeShutdownError, cc as HMRUpdatePayload, c5 as MiddlewareDiscoveredPayload, ce as NitroBuildLifecyclePayload, aU as PluginManager, bD as PluginRequestContext, c9 as RenderLifecyclePayload, c3 as RouteDiscoveredPayload, c7 as RouteMatchPayload, c8 as RouteMatchResultPayload, c4 as RoutesGeneratedPayload, cf as ShutdownPayload, aS as definePlugin, x as farmPlugin } from './client-plugins-CqVtZi5X.js';
3
4
  import 'vite';
4
5
  import './lifecycle-DK06VuKP.js';
5
6
  import './env.js';
@@ -27,6 +28,8 @@ 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-fn.js';
32
+ import './server-query.js';
30
33
  import './types-DQnyD3VD.js';
31
34
  import './font.js';
32
35
  import './after.js';
package/dist/plugin.mjs CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  PluginManager,
5
5
  definePlugin,
6
6
  farmPlugin
7
- } from "./chunk-JRF3C33L.mjs";
7
+ } from "./chunk-NHHKW2T6.mjs";
8
8
  import "./chunk-27JNCYEK.mjs";
9
9
  import "./chunk-DHDVMXYK.mjs";
10
10
  import "./chunk-ZMSZZXOR.mjs";
@@ -31,7 +31,7 @@ import "./chunk-Q3MDL7TM.mjs";
31
31
  import "./chunk-G2KY33I6.mjs";
32
32
  import "./chunk-4L7SZOHZ.mjs";
33
33
  import "./chunk-QCFFHV5H.mjs";
34
- import "./chunk-FOGLGRDS.mjs";
34
+ import "./chunk-7HDZYYS4.mjs";
35
35
  import "./chunk-KATQ6I56.mjs";
36
36
  import "./chunk-LUC2FAGW.mjs";
37
37
  import "./chunk-FA2W42OV.mjs";
@@ -69,7 +69,7 @@ import "./chunk-YMCXWPWK.mjs";
69
69
  import "./chunk-KI3MESHB.mjs";
70
70
  import "./chunk-QVKYGNVM.mjs";
71
71
  import "./chunk-Z2RZJZIZ.mjs";
72
- import "./chunk-UE75PB52.mjs";
72
+ import "./chunk-IL5RWYK7.mjs";
73
73
  import "./chunk-54UPOYFS.mjs";
74
74
  import "./chunk-WNSDDRNU.mjs";
75
75
  import "./chunk-JPLUGGRV.mjs";
@@ -1,4 +1,4 @@
1
- import { aj as ReadonlyMiddlewareStore, ak as FarmMiddlewareConfig, al as MiddlewareModule, am as MiddlewareConfig, an as MiddlewareContext } from './client-plugins-CslwYp3E.js';
1
+ import { aj as ReadonlyMiddlewareStore, ak as FarmMiddlewareConfig, al as MiddlewareModule, am as MiddlewareConfig, an as MiddlewareContext } from './client-plugins-CqVtZi5X.js';
2
2
  import { R as ResolvedFarmI18nConfig } from './types-Z0aotQ8w.js';
3
3
  import { R as ResolvedFarmServerConfig } from './workflows-CR9ex-gz.js';
4
4
 
@@ -1,4 +1,4 @@
1
- import { aj as ReadonlyMiddlewareStore, ak as FarmMiddlewareConfig, al as MiddlewareModule, am as MiddlewareConfig, an as MiddlewareContext } from './client-plugins-C1EgdoJM.mjs';
1
+ import { aj as ReadonlyMiddlewareStore, ak as FarmMiddlewareConfig, al as MiddlewareModule, am as MiddlewareConfig, an as MiddlewareContext } from './client-plugins-CIPRtSsW.mjs';
2
2
  import { R as ResolvedFarmI18nConfig } from './types-Z0aotQ8w.mjs';
3
3
  import { R as ResolvedFarmServerConfig } from './workflows-CR9ex-gz.mjs';
4
4
 
@@ -1,5 +1,5 @@
1
1
  import { F as FarmIslandStrategy } from './island-CfGru1MO.js';
2
- import './client-plugins-CslwYp3E.js';
2
+ import './client-plugins-CqVtZi5X.js';
3
3
 
4
4
  /**
5
5
  * A build-time rendering decision consumed by the browser router.
@@ -1,5 +1,5 @@
1
1
  import { F as FarmIslandStrategy } from './island-CfGru1MO.mjs';
2
- import './client-plugins-C1EgdoJM.mjs';
2
+ import './client-plugins-CIPRtSsW.mjs';
3
3
 
4
4
  /**
5
5
  * A build-time rendering decision consumed by the browser router.
@@ -1,14 +1,15 @@
1
1
  import { FarmRouterRouteInput } from './router.mjs';
2
- import { F as FarmNavigationState, a as FarmNavigateOptions } from './spa-router-csKR9Ebj.mjs';
2
+ import { F as FarmNavigationState, a as FarmNavigateOptions } from './spa-router-BcS_4nqm.mjs';
3
3
  import { F as FarmClientCacheStatus } from './client-cache-di_Nasxa.mjs';
4
4
  import { ServerFn } from './server-fn.mjs';
5
5
  import { ServerQuery } from './server-query.mjs';
6
6
  import { S as ServerQueryFetchOptions } from './server-query-runtime-aP52iuL5.mjs';
7
7
  import { F as FarmThemeSnapshot, a as FarmThemePreference } from './types-DQnyD3VD.mjs';
8
8
  import { F as FarmI18nClientSnapshot, a as FarmTranslator, b as FarmI18nLocale } from './types-Z0aotQ8w.mjs';
9
- import './client-plugins-C1EgdoJM.mjs';
9
+ import './client-plugins-CIPRtSsW.mjs';
10
10
  import './lifecycle-DK06VuKP.mjs';
11
- import './route-C6UClI1z.mjs';
11
+ import './route-C_eLaFTZ.mjs';
12
+ import './endpoint-Bu3XgeMK.mjs';
12
13
  import './cache.mjs';
13
14
  import './renderer.mjs';
14
15
  import './deployment.mjs';
@@ -38,7 +39,7 @@ import './font.mjs';
38
39
  import './after.mjs';
39
40
  import 'node:http';
40
41
  import './island-CfGru1MO.mjs';
41
- import './render-plan-CNUlzylR.mjs';
42
+ import './render-plan-io7pvDNc.mjs';
42
43
 
43
44
  interface FarmClientStore<TSnapshot> {
44
45
  getSnapshot(): TSnapshot;
@@ -1,14 +1,15 @@
1
1
  import { FarmRouterRouteInput } from './router.js';
2
- import { F as FarmNavigationState, a as FarmNavigateOptions } from './spa-router-Y_2FSJQK.js';
2
+ import { F as FarmNavigationState, a as FarmNavigateOptions } from './spa-router-BzFBUJkn.js';
3
3
  import { F as FarmClientCacheStatus } from './client-cache-Deoqq-nM.js';
4
4
  import { ServerFn } from './server-fn.js';
5
5
  import { ServerQuery } from './server-query.js';
6
6
  import { S as ServerQueryFetchOptions } from './server-query-runtime-DXRNhX_3.js';
7
7
  import { F as FarmThemeSnapshot, a as FarmThemePreference } from './types-DQnyD3VD.js';
8
8
  import { F as FarmI18nClientSnapshot, a as FarmTranslator, b as FarmI18nLocale } from './types-Z0aotQ8w.js';
9
- import './client-plugins-CslwYp3E.js';
9
+ import './client-plugins-CqVtZi5X.js';
10
10
  import './lifecycle-DK06VuKP.js';
11
- import './route-CHBaW55F.js';
11
+ import './route-BxNJT447.js';
12
+ import './endpoint-kSAxE52R.js';
12
13
  import './cache.js';
13
14
  import './renderer.js';
14
15
  import './deployment.js';
@@ -38,7 +39,7 @@ import './font.js';
38
39
  import './after.js';
39
40
  import 'node:http';
40
41
  import './island-CfGru1MO.js';
41
- import './render-plan-EG4hNFjy.js';
42
+ import './render-plan-Be4ZGTJP.js';
42
43
 
43
44
  interface FarmClientStore<TSnapshot> {
44
45
  getSnapshot(): TSnapshot;
@@ -1,4 +1,4 @@
1
- import './client-plugins-C1EgdoJM.mjs';
1
+ import './client-plugins-CIPRtSsW.mjs';
2
2
 
3
3
  interface FarmRequestURLOptions {
4
4
  origin?: string | URL;
@@ -1,4 +1,4 @@
1
- import './client-plugins-CslwYp3E.js';
1
+ import './client-plugins-CqVtZi5X.js';
2
2
 
3
3
  interface FarmRequestURLOptions {
4
4
  origin?: string | URL;
@@ -1,7 +1,8 @@
1
- export { g as getCurrentRequest } from './request-Blh_f7Z3.mjs';
2
- import './client-plugins-C1EgdoJM.mjs';
1
+ export { g as getCurrentRequest } from './request-DZkHYQ89.mjs';
2
+ import './client-plugins-CIPRtSsW.mjs';
3
3
  import './lifecycle-DK06VuKP.mjs';
4
- import './route-C6UClI1z.mjs';
4
+ import './route-C_eLaFTZ.mjs';
5
+ import './endpoint-Bu3XgeMK.mjs';
5
6
  import './cache.mjs';
6
7
  import './renderer.mjs';
7
8
  import './deployment.mjs';
@@ -28,6 +29,8 @@ import './server-fn-error-DDh14a0V.mjs';
28
29
  import 'esbuild';
29
30
  import './image-config-Duob7wER.mjs';
30
31
  import './types-Z0aotQ8w.mjs';
32
+ import './server-fn.mjs';
33
+ import './server-query.mjs';
31
34
  import './types-DQnyD3VD.mjs';
32
35
  import './font.mjs';
33
36
  import './after.mjs';
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 };