@farm.js/core 0.1.0-beta.1 → 0.1.0-beta.3

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 (230) hide show
  1. package/README.md +1 -1
  2. package/dist/agent-runtime.d.mts +1 -1
  3. package/dist/agent-runtime.d.ts +1 -1
  4. package/dist/api/route-manager.cjs +97 -5
  5. package/dist/api/route-manager.cjs.map +1 -1
  6. package/dist/api/route-manager.d.mts +3 -2
  7. package/dist/api/route-manager.d.ts +3 -2
  8. package/dist/api/route-manager.mjs +8 -8
  9. package/dist/api/runtime.cjs +441 -5
  10. package/dist/api/runtime.cjs.map +1 -1
  11. package/dist/api/runtime.d.mts +2 -16
  12. package/dist/api/runtime.d.ts +2 -16
  13. package/dist/api/runtime.mjs +7 -1
  14. package/dist/api.cjs +579 -263
  15. package/dist/api.cjs.map +1 -1
  16. package/dist/api.d.mts +4 -147
  17. package/dist/api.d.ts +4 -147
  18. package/dist/api.mjs +30 -20
  19. package/dist/{app-BiX4qb-d.d.mts → app-BB3Iu3xh.d.mts} +2 -2
  20. package/dist/{app-CFRNJXP1.d.ts → app-DOKxo-LH.d.ts} +2 -2
  21. package/dist/app-markdown.cjs +1 -1
  22. package/dist/app-markdown.cjs.map +1 -1
  23. package/dist/app-markdown.d.mts +1 -1
  24. package/dist/app-markdown.d.ts +1 -1
  25. package/dist/app-markdown.mjs +1 -1
  26. package/dist/cache.cjs +19 -0
  27. package/dist/cache.cjs.map +1 -1
  28. package/dist/cache.d.mts +21 -1
  29. package/dist/cache.d.ts +21 -1
  30. package/dist/cache.mjs +5 -3
  31. package/dist/{chunk-QF4PHCMA.mjs → chunk-2ED5Q2GH.mjs} +3 -3
  32. package/dist/chunk-2ED5Q2GH.mjs.map +1 -0
  33. package/dist/{chunk-GZP5W4K3.mjs → chunk-32W4QEJP.mjs} +1 -1
  34. package/dist/chunk-32W4QEJP.mjs.map +1 -0
  35. package/dist/{chunk-AGS7UJ52.mjs → chunk-45LKHSHJ.mjs} +2 -2
  36. package/dist/{chunk-TU4YJICB.mjs → chunk-5FW6PQ3J.mjs} +1 -1
  37. package/dist/{chunk-TU4YJICB.mjs.map → chunk-5FW6PQ3J.mjs.map} +1 -1
  38. package/dist/{chunk-TRORP7E4.mjs → chunk-5QH4IKY3.mjs} +2 -2
  39. package/dist/{chunk-RKI6TN3A.mjs → chunk-6VS6CKAV.mjs} +2 -2
  40. package/dist/chunk-6VS6CKAV.mjs.map +1 -0
  41. package/dist/{chunk-25D7G34K.mjs → chunk-6WXJ54TC.mjs} +4 -4
  42. package/dist/{chunk-3QJO55ZF.mjs → chunk-BIOIOWXZ.mjs} +5 -3
  43. package/dist/{chunk-3QJO55ZF.mjs.map → chunk-BIOIOWXZ.mjs.map} +1 -1
  44. package/dist/{chunk-QFQRHRZS.mjs → chunk-C33RALN7.mjs} +75 -11
  45. package/dist/chunk-C33RALN7.mjs.map +1 -0
  46. package/dist/{chunk-B6N4ZB2H.mjs → chunk-CSU4KJJF.mjs} +3 -3
  47. package/dist/{chunk-JN3UU635.mjs → chunk-EJ7T4TPB.mjs} +2 -2
  48. package/dist/chunk-EJ7T4TPB.mjs.map +1 -0
  49. package/dist/{chunk-ZJQNATYV.mjs → chunk-FRPWCMMG.mjs} +3 -3
  50. package/dist/chunk-FRPWCMMG.mjs.map +1 -0
  51. package/dist/{chunk-PRNYWD7K.mjs → chunk-G5I34UA6.mjs} +67 -239
  52. package/dist/chunk-G5I34UA6.mjs.map +1 -0
  53. package/dist/{chunk-QM6VV26B.mjs → chunk-GQVGIUSN.mjs} +3 -3
  54. package/dist/{chunk-QM6VV26B.mjs.map → chunk-GQVGIUSN.mjs.map} +1 -1
  55. package/dist/{chunk-UREJA4GZ.mjs → chunk-GXASWWJU.mjs} +1 -1
  56. package/dist/{chunk-UREJA4GZ.mjs.map → chunk-GXASWWJU.mjs.map} +1 -1
  57. package/dist/{chunk-4PTK6KT4.mjs → chunk-GZWT6VI5.mjs} +22 -4
  58. package/dist/chunk-GZWT6VI5.mjs.map +1 -0
  59. package/dist/{chunk-JLWMCADZ.mjs → chunk-HZYXGV4K.mjs} +2 -2
  60. package/dist/chunk-JNYVN7YP.mjs +10 -0
  61. package/dist/chunk-JNYVN7YP.mjs.map +1 -0
  62. package/dist/{chunk-YHU7SS6L.mjs → chunk-LG3YINQN.mjs} +11 -11
  63. package/dist/chunk-LWMGIEJA.mjs +593 -0
  64. package/dist/chunk-LWMGIEJA.mjs.map +1 -0
  65. package/dist/{chunk-HXP3ZSPC.mjs → chunk-MH6FKW2I.mjs} +3 -3
  66. package/dist/{chunk-O3HADRW6.mjs → chunk-MIUW47JX.mjs} +2 -2
  67. package/dist/{chunk-O3HADRW6.mjs.map → chunk-MIUW47JX.mjs.map} +1 -1
  68. package/dist/{chunk-6XDUHOEM.mjs → chunk-NRRFGX45.mjs} +3 -3
  69. package/dist/{chunk-G3B5BRDY.mjs → chunk-OHC6VCDI.mjs} +24 -25
  70. package/dist/{chunk-G3B5BRDY.mjs.map → chunk-OHC6VCDI.mjs.map} +1 -1
  71. package/dist/{chunk-S2XHZS7W.mjs → chunk-QGQX7SFC.mjs} +2 -2
  72. package/dist/chunk-QGQX7SFC.mjs.map +1 -0
  73. package/dist/{chunk-TXCFGOHW.mjs → chunk-SHRJG6OG.mjs} +25 -1
  74. package/dist/chunk-SHRJG6OG.mjs.map +1 -0
  75. package/dist/{chunk-UHE2TTLK.mjs → chunk-T543TMFY.mjs} +8 -8
  76. package/dist/chunk-T543TMFY.mjs.map +1 -0
  77. package/dist/{chunk-SXZTEK3V.mjs → chunk-UXUAWNO5.mjs} +2 -2
  78. package/dist/{chunk-Y2OJJD7R.mjs → chunk-XIVV5IWN.mjs} +7 -9
  79. package/dist/chunk-XIVV5IWN.mjs.map +1 -0
  80. package/dist/{chunk-CHFHNEMO.mjs → chunk-XJSHJN4M.mjs} +41 -42
  81. package/dist/chunk-XJSHJN4M.mjs.map +1 -0
  82. package/dist/{chunk-Y7A27276.mjs → chunk-XUBZ7JI4.mjs} +178 -15
  83. package/dist/chunk-XUBZ7JI4.mjs.map +1 -0
  84. package/dist/{chunk-OYXO65LI.mjs → chunk-YW7OBE6Q.mjs} +4 -4
  85. package/dist/chunk-YW7OBE6Q.mjs.map +1 -0
  86. package/dist/{chunk-SOU3Q3ZA.mjs → chunk-ZZ57EH5Z.mjs} +1 -1
  87. package/dist/chunk-ZZ57EH5Z.mjs.map +1 -0
  88. package/dist/{client-D_yUjVhe.d.mts → client-DiViK9yK.d.mts} +33 -7
  89. package/dist/{client-Dkc03WP8.d.ts → client-DpEBJbts.d.ts} +33 -7
  90. package/dist/{client-plugins-BZnpeTGA.d.ts → client-plugins-CTnsZz_A.d.ts} +1 -0
  91. package/dist/{client-plugins-g4bzuCmo.d.mts → client-plugins-Cnr0D3kk.d.mts} +1 -0
  92. package/dist/client-plugins.d.mts +1 -1
  93. package/dist/client-plugins.d.ts +1 -1
  94. package/dist/client.cjs +302 -54
  95. package/dist/client.cjs.map +1 -1
  96. package/dist/client.d.mts +54 -2
  97. package/dist/client.d.ts +54 -2
  98. package/dist/client.mjs +20 -16
  99. package/dist/config.d.mts +1 -1
  100. package/dist/config.d.ts +1 -1
  101. package/dist/cron.cjs.map +1 -1
  102. package/dist/cron.mjs +1 -1
  103. package/dist/{devtools-AE4RVXCM.mjs → devtools-HE4FTUDN.mjs} +10 -10
  104. package/dist/{devtools-client-6WPY2AQU.mjs → devtools-client-3XRTBND5.mjs} +2 -11
  105. package/dist/devtools-client-3XRTBND5.mjs.map +1 -0
  106. package/dist/docs.cjs +3 -1
  107. package/dist/docs.cjs.map +1 -1
  108. package/dist/docs.mjs +10 -10
  109. package/dist/i18n/server.cjs +2 -2
  110. package/dist/i18n/server.cjs.map +1 -1
  111. package/dist/i18n/server.mjs +1 -1
  112. package/dist/index.cjs +791 -317
  113. package/dist/index.cjs.map +1 -1
  114. package/dist/index.d.mts +11 -11
  115. package/dist/index.d.ts +11 -11
  116. package/dist/index.mjs +125 -110
  117. package/dist/index.mjs.map +1 -1
  118. package/dist/integrations.d.mts +1 -1
  119. package/dist/integrations.d.ts +1 -1
  120. package/dist/internal/build-runtime.cjs +162 -60
  121. package/dist/internal/build-runtime.cjs.map +1 -1
  122. package/dist/internal/build-runtime.d.mts +3 -3
  123. package/dist/internal/build-runtime.d.ts +3 -3
  124. package/dist/internal/build-runtime.mjs +26 -25
  125. package/dist/internal/client-runtime.cjs.map +1 -1
  126. package/dist/internal/client-runtime.mjs +1 -1
  127. package/dist/internal/config-runtime.cjs +1 -1
  128. package/dist/internal/config-runtime.cjs.map +1 -1
  129. package/dist/internal/config-runtime.d.mts +2 -2
  130. package/dist/internal/config-runtime.d.ts +2 -2
  131. package/dist/internal/config-runtime.mjs +9 -9
  132. package/dist/internal/production-runtime.cjs +3 -3
  133. package/dist/internal/production-runtime.cjs.map +1 -1
  134. package/dist/internal/production-runtime.d.mts +3 -3
  135. package/dist/internal/production-runtime.d.ts +3 -3
  136. package/dist/internal/production-runtime.mjs +8 -8
  137. package/dist/{metadata-C9NZxMDW.d.mts → metadata-Dp8AdvsB.d.mts} +1 -1
  138. package/dist/{metadata-DAXRaOHx.d.ts → metadata-eoVmHoyv.d.ts} +1 -1
  139. package/dist/middleware.cjs +2 -2
  140. package/dist/middleware.cjs.map +1 -1
  141. package/dist/middleware.d.mts +3 -3
  142. package/dist/middleware.d.ts +3 -3
  143. package/dist/middleware.mjs +3 -3
  144. package/dist/navigation.cjs.map +1 -1
  145. package/dist/navigation.mjs +3 -3
  146. package/dist/{nitro-KME62MWG.mjs → nitro-QO5LV6QK.mjs} +11 -13
  147. package/dist/{nitro-KME62MWG.mjs.map → nitro-QO5LV6QK.mjs.map} +1 -1
  148. package/dist/plugin.cjs +119 -39
  149. package/dist/plugin.cjs.map +1 -1
  150. package/dist/plugin.d.mts +1 -1
  151. package/dist/plugin.d.ts +1 -1
  152. package/dist/plugin.mjs +22 -21
  153. package/dist/{production-runtime-DRkCHUvJ.d.ts → production-runtime-BqTnUTai.d.ts} +1 -1
  154. package/dist/{production-runtime-flrjp_nC.d.mts → production-runtime-DtDdG9fc.d.mts} +1 -1
  155. package/dist/routes.cjs.map +1 -1
  156. package/dist/routes.d.mts +1 -1
  157. package/dist/routes.d.ts +1 -1
  158. package/dist/routes.mjs +4 -4
  159. package/dist/runtime-C1B7pSGT.d.mts +207 -0
  160. package/dist/runtime-CdPHt0bv.d.ts +207 -0
  161. package/dist/server-action-security.cjs.map +1 -1
  162. package/dist/server-action-security.mjs +2 -2
  163. package/dist/server-fn-client.cjs.map +1 -1
  164. package/dist/server-fn-client.mjs +1 -1
  165. package/dist/server-fn.cjs.map +1 -1
  166. package/dist/server-fn.mjs +3 -3
  167. package/dist/server-plugins.d.mts +2 -2
  168. package/dist/server-plugins.d.ts +2 -2
  169. package/dist/server-query-client.cjs.map +1 -1
  170. package/dist/server-query-client.mjs +4 -4
  171. package/dist/server-query.cjs.map +1 -1
  172. package/dist/server-query.mjs +5 -5
  173. package/dist/server.cjs +148 -43
  174. package/dist/server.cjs.map +1 -1
  175. package/dist/server.d.mts +6 -6
  176. package/dist/server.d.ts +6 -6
  177. package/dist/server.mjs +36 -31
  178. package/dist/server.mjs.map +1 -1
  179. package/dist/testing.cjs +95 -5
  180. package/dist/testing.cjs.map +1 -1
  181. package/dist/testing.d.mts +3 -3
  182. package/dist/testing.d.ts +3 -3
  183. package/dist/testing.mjs +18 -18
  184. package/dist/{utils-DOXXivjL.d.mts → utils-8USa5BiY.d.mts} +1 -1
  185. package/dist/{utils-DA1yo54_.d.ts → utils-DKJb6K6G.d.ts} +1 -1
  186. package/dist/version.cjs +36 -0
  187. package/dist/version.cjs.map +1 -0
  188. package/dist/version.d.mts +3 -0
  189. package/dist/version.d.ts +3 -0
  190. package/dist/version.mjs +8 -0
  191. package/dist/version.mjs.map +1 -0
  192. package/dist/vite.cjs +126 -40
  193. package/dist/vite.cjs.map +1 -1
  194. package/dist/vite.d.mts +1 -1
  195. package/dist/vite.d.ts +1 -1
  196. package/dist/vite.mjs +22 -21
  197. package/dist/workflows.cjs +6 -8
  198. package/dist/workflows.cjs.map +1 -1
  199. package/dist/workflows.mjs +1 -1
  200. package/package.json +12 -5
  201. package/types/client.d.ts +136 -13
  202. package/dist/chunk-4PTK6KT4.mjs.map +0 -1
  203. package/dist/chunk-CHFHNEMO.mjs.map +0 -1
  204. package/dist/chunk-EVGBEZDF.mjs +0 -215
  205. package/dist/chunk-EVGBEZDF.mjs.map +0 -1
  206. package/dist/chunk-GZP5W4K3.mjs.map +0 -1
  207. package/dist/chunk-JN3UU635.mjs.map +0 -1
  208. package/dist/chunk-OYXO65LI.mjs.map +0 -1
  209. package/dist/chunk-PRNYWD7K.mjs.map +0 -1
  210. package/dist/chunk-QF4PHCMA.mjs.map +0 -1
  211. package/dist/chunk-QFQRHRZS.mjs.map +0 -1
  212. package/dist/chunk-RKI6TN3A.mjs.map +0 -1
  213. package/dist/chunk-S2XHZS7W.mjs.map +0 -1
  214. package/dist/chunk-SOU3Q3ZA.mjs.map +0 -1
  215. package/dist/chunk-TXCFGOHW.mjs.map +0 -1
  216. package/dist/chunk-UHE2TTLK.mjs.map +0 -1
  217. package/dist/chunk-Y2OJJD7R.mjs.map +0 -1
  218. package/dist/chunk-Y7A27276.mjs.map +0 -1
  219. package/dist/chunk-ZJQNATYV.mjs.map +0 -1
  220. package/dist/devtools-client-6WPY2AQU.mjs.map +0 -1
  221. /package/dist/{chunk-AGS7UJ52.mjs.map → chunk-45LKHSHJ.mjs.map} +0 -0
  222. /package/dist/{chunk-TRORP7E4.mjs.map → chunk-5QH4IKY3.mjs.map} +0 -0
  223. /package/dist/{chunk-25D7G34K.mjs.map → chunk-6WXJ54TC.mjs.map} +0 -0
  224. /package/dist/{chunk-B6N4ZB2H.mjs.map → chunk-CSU4KJJF.mjs.map} +0 -0
  225. /package/dist/{chunk-JLWMCADZ.mjs.map → chunk-HZYXGV4K.mjs.map} +0 -0
  226. /package/dist/{chunk-YHU7SS6L.mjs.map → chunk-LG3YINQN.mjs.map} +0 -0
  227. /package/dist/{chunk-HXP3ZSPC.mjs.map → chunk-MH6FKW2I.mjs.map} +0 -0
  228. /package/dist/{chunk-6XDUHOEM.mjs.map → chunk-NRRFGX45.mjs.map} +0 -0
  229. /package/dist/{chunk-SXZTEK3V.mjs.map → chunk-UXUAWNO5.mjs.map} +0 -0
  230. /package/dist/{devtools-AE4RVXCM.mjs.map → devtools-HE4FTUDN.mjs.map} +0 -0
@@ -2946,7 +2946,11 @@ async function prepareFarmWorkflowsForNitro(config) {
2946
2946
  };
2947
2947
  }
2948
2948
  const handlerPath = path27.join(generatedDir, "http-handler.mjs");
2949
- await fs8.writeFile(handlerPath, createNitroWorkflowHTTPHandler(workflowConfig, workflows), "utf8");
2949
+ await fs8.writeFile(
2950
+ handlerPath,
2951
+ createNitroWorkflowHTTPHandler(workflowConfig, workflows),
2952
+ "utf8"
2953
+ );
2950
2954
  const manifestPath = path27.join(generatedDir, "manifest.json");
2951
2955
  await fs8.writeFile(
2952
2956
  manifestPath,
@@ -3020,13 +3024,7 @@ function normalizeSchedule(schedule) {
3020
3024
  return (Array.isArray(schedule) ? schedule : [schedule]).map((value) => value.trim()).filter(Boolean);
3021
3025
  }
3022
3026
  function resolveWorkflowDefinition(module2) {
3023
- const candidates = [
3024
- module2.default,
3025
- module2.workflow,
3026
- module2.cron,
3027
- module2.task,
3028
- module2.job
3029
- ];
3027
+ const candidates = [module2.default, module2.workflow, module2.cron, module2.task, module2.job];
3030
3028
  for (const candidate of candidates) {
3031
3029
  if (candidate && typeof candidate === "object" && typeof candidate.run === "function") {
3032
3030
  return candidate;
@@ -3892,7 +3890,7 @@ function createFarmMarkdownRouteModule(input) {
3892
3890
  ...props,
3893
3891
  components: {
3894
3892
  ...components,
3895
- ...props?.components || {}
3893
+ ...props?.components
3896
3894
  }
3897
3895
  })
3898
3896
  );
@@ -4082,8 +4080,8 @@ function compareFarmRouteRuleSpecificity(left, right) {
4082
4080
  }
4083
4081
  function getFarmRouteRuleSpecificity(pattern) {
4084
4082
  return normalizeRoutePattern(pattern).split("/").filter(Boolean).reduce((score, segment) => {
4085
- if (segment === "**" || /^\[\[\.\.\./.test(segment)) return score + 1;
4086
- if (segment === "*" || /^\[\.\.\./.test(segment)) return score + 10;
4083
+ if (segment === "**" || segment.startsWith("[[...")) return score + 1;
4084
+ if (segment === "*" || segment.startsWith("[...")) return score + 10;
4087
4085
  if (/^\[.+\]$/.test(segment) || /^:.+$/.test(segment)) return score + 50;
4088
4086
  return score + 100;
4089
4087
  }, 0);
@@ -4145,7 +4143,7 @@ function routeRulesToHeaders(routeRules) {
4145
4143
  for (const [source, rule] of Object.entries(routeRules)) {
4146
4144
  const headers = {
4147
4145
  ...normalizeCorsHeaders(rule.cors),
4148
- ...rule.headers || {}
4146
+ ...rule.headers
4149
4147
  };
4150
4148
  const entries = Object.entries(headers);
4151
4149
  if (entries.length === 0) continue;
@@ -4175,7 +4173,7 @@ function routeRulesToNitroRouteRules(routeRules) {
4175
4173
  nitroRule.cors = true;
4176
4174
  nitroRule.headers = {
4177
4175
  ...normalizeCorsHeaders(rule.cors),
4178
- ...rule.headers || {}
4176
+ ...rule.headers
4179
4177
  };
4180
4178
  }
4181
4179
  delete nitroRule.render;
@@ -4230,18 +4228,39 @@ function getFarmCacheInvalidationState() {
4230
4228
  listeners: /* @__PURE__ */ new Set()
4231
4229
  });
4232
4230
  }
4231
+ function encodeFarmCacheInvalidations(keys) {
4232
+ const normalized = Array.from(
4233
+ new Set(keys.filter((key) => typeof key === "string" && key.length > 0))
4234
+ );
4235
+ if (normalized.length === 0) return null;
4236
+ return encodeURIComponent(JSON.stringify(normalized));
4237
+ }
4238
+ function decodeFarmCacheInvalidations(value) {
4239
+ if (!value) return [];
4240
+ try {
4241
+ const parsed = JSON.parse(decodeURIComponent(value));
4242
+ return Array.isArray(parsed) ? Array.from(
4243
+ new Set(parsed.filter((key) => typeof key === "string" && key.length > 0))
4244
+ ) : [];
4245
+ } catch {
4246
+ return [];
4247
+ }
4248
+ }
4233
4249
  function subscribeFarmCacheInvalidation(listener) {
4234
4250
  const state = getFarmCacheInvalidationState();
4235
4251
  state.listeners.add(listener);
4236
4252
  return () => state.listeners.delete(listener);
4237
4253
  }
4238
- var FARM_CACHE_INVALIDATION_STATE, globalState;
4254
+ var FARM_CACHE_INVALIDATION_HEADER, FARM_CACHE_INVALIDATION_STATE, globalState;
4239
4255
  var init_cache_invalidation = __esm({
4240
4256
  "src/cache-invalidation.ts"() {
4241
4257
  "use strict";
4258
+ FARM_CACHE_INVALIDATION_HEADER = "x-farm-cache-invalidations";
4242
4259
  FARM_CACHE_INVALIDATION_STATE = /* @__PURE__ */ Symbol.for("farm.cacheInvalidationState");
4243
4260
  globalState = globalThis;
4244
4261
  __name(getFarmCacheInvalidationState, "getFarmCacheInvalidationState");
4262
+ __name(encodeFarmCacheInvalidations, "encodeFarmCacheInvalidations");
4263
+ __name(decodeFarmCacheInvalidations, "decodeFarmCacheInvalidations");
4245
4264
  __name(subscribeFarmCacheInvalidation, "subscribeFarmCacheInvalidation");
4246
4265
  }
4247
4266
  });
@@ -8869,7 +8888,7 @@ function mergeMetadata(base, next) {
8869
8888
  }
8870
8889
  function addMetadataImageReference(metadata, reference) {
8871
8890
  if (reference.kind === "opengraph") {
8872
- const openGraph = { ...metadata.openGraph || {} };
8891
+ const openGraph = { ...metadata.openGraph };
8873
8892
  if (!hasMetadataImages(openGraph.images) && !hasMetadataImages(openGraph.image)) {
8874
8893
  openGraph.images = [
8875
8894
  {
@@ -8886,7 +8905,7 @@ function addMetadataImageReference(metadata, reference) {
8886
8905
  openGraph
8887
8906
  };
8888
8907
  }
8889
- const twitter = { ...metadata.twitter || {} };
8908
+ const twitter = { ...metadata.twitter };
8890
8909
  if (!hasMetadataImages(twitter.images)) {
8891
8910
  twitter.images = [reference.href];
8892
8911
  twitter.card = twitter.card || "summary_large_image";
@@ -9512,8 +9531,8 @@ var init_runtime = __esm({
9512
9531
  cookie: this.config.cookie,
9513
9532
  direction: getFarmLocaleDirection(resolution.locale, this.config.direction),
9514
9533
  messages: {
9515
- ...this.catalogs[this.config.fallbackLocale] || {},
9516
- ...this.catalogs[resolution.locale] || {}
9534
+ ...this.catalogs[this.config.fallbackLocale],
9535
+ ...this.catalogs[resolution.locale]
9517
9536
  }
9518
9537
  };
9519
9538
  }
@@ -11048,11 +11067,7 @@ var init_app = __esm({
11048
11067
  _setDefaultFarmI18nRuntime(this.i18nRuntime);
11049
11068
  this.viteServer = viteServer;
11050
11069
  this.routeManager = new RouteManager(this.config, viteServer);
11051
- this.serverRenderer = new ServerRenderer(
11052
- this.config,
11053
- this.routeManager,
11054
- this.i18nRuntime
11055
- );
11070
+ this.serverRenderer = new ServerRenderer(this.config, this.routeManager, this.i18nRuntime);
11056
11071
  }
11057
11072
  async initialize() {
11058
11073
  if (process.env.FARM_VERBOSE) {
@@ -11163,6 +11178,33 @@ var init_app = __esm({
11163
11178
  }
11164
11179
  });
11165
11180
 
11181
+ // src/api/endpoint.ts
11182
+ function isEndpointFailure(value) {
11183
+ return value instanceof EndpointFailure;
11184
+ }
11185
+ var import_better_call, _EndpointFailure, EndpointFailure, EMPTY_ENDPOINT_MIDDLEWARE, EMPTY_ENDPOINT_CONTEXT;
11186
+ var init_endpoint = __esm({
11187
+ "src/api/endpoint.ts"() {
11188
+ "use strict";
11189
+ import_better_call = require("better-call");
11190
+ init_cache();
11191
+ _EndpointFailure = class _EndpointFailure extends Error {
11192
+ constructor(code, data, options) {
11193
+ super(options.message);
11194
+ this.name = "EndpointFailure";
11195
+ this.code = code;
11196
+ this.data = data;
11197
+ this.status = options.status;
11198
+ }
11199
+ };
11200
+ __name(_EndpointFailure, "EndpointFailure");
11201
+ EndpointFailure = _EndpointFailure;
11202
+ __name(isEndpointFailure, "isEndpointFailure");
11203
+ EMPTY_ENDPOINT_MIDDLEWARE = Object.freeze([]);
11204
+ EMPTY_ENDPOINT_CONTEXT = Object.freeze(/* @__PURE__ */ Object.create(null));
11205
+ }
11206
+ });
11207
+
11166
11208
  // src/api/runtime.ts
11167
11209
  function matchAPIRoute(routes, pathname) {
11168
11210
  const exactRoute = routes.get(pathname);
@@ -11193,10 +11235,10 @@ async function invokeAPIRouteEndpoint(endpoint, request, params = {}) {
11193
11235
  async function invokeAPIRouteEndpointInContext(endpoint, request, params) {
11194
11236
  const farmHandler = endpoint.__handler || (isFarmContextHandler(endpoint) ? endpoint : null);
11195
11237
  if (!farmHandler) {
11196
- const result2 = await endpoint(request, {
11238
+ const result = await endpoint(request, {
11197
11239
  params: Promise.resolve(params)
11198
11240
  });
11199
- return normalizeRouteResponse(result2);
11241
+ return normalizeRouteResponse(result);
11200
11242
  }
11201
11243
  const url = new URL(request.url);
11202
11244
  const query = {};
@@ -11221,15 +11263,30 @@ async function invokeAPIRouteEndpointInContext(endpoint, request, params) {
11221
11263
  if (headersValidation instanceof Response) {
11222
11264
  return headersValidation;
11223
11265
  }
11224
- const result = await farmHandler({
11266
+ const handlerContext = {
11225
11267
  query: queryValidation,
11226
11268
  body: bodyValidation,
11227
11269
  headers: headersValidation,
11228
11270
  request,
11229
11271
  context: {},
11230
11272
  params
11231
- });
11232
- return normalizeRouteResponse(result);
11273
+ };
11274
+ let execution;
11275
+ try {
11276
+ execution = typeof endpoint.__farmInvoke === "function" ? await endpoint.__farmInvoke(handlerContext) : {
11277
+ result: await farmHandler(handlerContext),
11278
+ context: handlerContext.context,
11279
+ handlerExecuted: true,
11280
+ invalidations: []
11281
+ };
11282
+ } catch (error) {
11283
+ if (isEndpointFailure(error)) {
11284
+ return createEndpointFailureResponse(error);
11285
+ }
11286
+ throw error;
11287
+ }
11288
+ const response = normalizeRouteResponse(execution.result);
11289
+ return attachEndpointInvalidations(response, execution.invalidations);
11233
11290
  }
11234
11291
  function normalizeRouteResponse(result) {
11235
11292
  if (isWebResponse2(result)) {
@@ -11246,6 +11303,38 @@ function normalizeRouteResponse(result) {
11246
11303
  function isWebResponse2(value) {
11247
11304
  return value instanceof Response || typeof value === "object" && value !== null && "headers" in value && "status" in value && typeof value.arrayBuffer === "function";
11248
11305
  }
11306
+ function attachEndpointInvalidations(response, keys) {
11307
+ const existing = decodeFarmCacheInvalidations(
11308
+ response.headers.get(FARM_CACHE_INVALIDATION_HEADER)
11309
+ );
11310
+ const encoded = encodeFarmCacheInvalidations([...existing, ...keys]);
11311
+ if (!encoded) return response;
11312
+ const headers = new Headers(response.headers);
11313
+ headers.set(FARM_CACHE_INVALIDATION_HEADER, encoded);
11314
+ return new Response(response.body, {
11315
+ status: response.status,
11316
+ statusText: response.statusText,
11317
+ headers
11318
+ });
11319
+ }
11320
+ function createEndpointFailureResponse(failure) {
11321
+ return new Response(
11322
+ JSON.stringify({
11323
+ error: {
11324
+ code: failure.code,
11325
+ message: failure.message,
11326
+ data: failure.data
11327
+ }
11328
+ }),
11329
+ {
11330
+ status: failure.status,
11331
+ headers: {
11332
+ "cache-control": "no-store",
11333
+ "content-type": "application/json"
11334
+ }
11335
+ }
11336
+ );
11337
+ }
11249
11338
  function isFarmContextHandler(endpoint) {
11250
11339
  if (typeof endpoint !== "function") {
11251
11340
  return false;
@@ -11354,11 +11443,15 @@ var init_runtime2 = __esm({
11354
11443
  "src/api/runtime.ts"() {
11355
11444
  "use strict";
11356
11445
  init_request();
11446
+ init_cache_invalidation();
11447
+ init_endpoint();
11357
11448
  __name(matchAPIRoute, "matchAPIRoute");
11358
11449
  __name(invokeAPIRouteEndpoint, "invokeAPIRouteEndpoint");
11359
11450
  __name(invokeAPIRouteEndpointInContext, "invokeAPIRouteEndpointInContext");
11360
11451
  __name(normalizeRouteResponse, "normalizeRouteResponse");
11361
11452
  __name(isWebResponse2, "isWebResponse");
11453
+ __name(attachEndpointInvalidations, "attachEndpointInvalidations");
11454
+ __name(createEndpointFailureResponse, "createEndpointFailureResponse");
11362
11455
  __name(isFarmContextHandler, "isFarmContextHandler");
11363
11456
  __name(readJSONBody, "readJSONBody");
11364
11457
  __name(validateInput, "validateInput");
@@ -12329,7 +12422,9 @@ function readManifest(contentDir) {
12329
12422
  const manifestPath = import_node_path4.default.join(contentDir, FARM_DOCS_LAST_MODIFIED_MANIFEST);
12330
12423
  if (!(0, import_node_fs2.existsSync)(manifestPath)) return null;
12331
12424
  try {
12332
- const parsed = JSON.parse((0, import_node_fs2.readFileSync)(manifestPath, "utf8"));
12425
+ const parsed = JSON.parse(
12426
+ (0, import_node_fs2.readFileSync)(manifestPath, "utf8")
12427
+ );
12333
12428
  if (parsed.version !== 1 || !parsed.pages || typeof parsed.pages !== "object") return null;
12334
12429
  const pages = Object.fromEntries(
12335
12430
  Object.entries(parsed.pages).filter(
@@ -13341,7 +13436,7 @@ var init_manager = __esm({
13341
13436
  if (!nestedMatch.matched) {
13342
13437
  return { matched: false };
13343
13438
  }
13344
- const params = { ...nestedMatch.params || {} };
13439
+ const params = { ...nestedMatch.params };
13345
13440
  delete params.__farmRest;
13346
13441
  return {
13347
13442
  matched: true,
@@ -14144,6 +14239,24 @@ var init_type_artifacts = __esm({
14144
14239
  }
14145
14240
  });
14146
14241
 
14242
+ // package.json
14243
+ var version;
14244
+ var init_package = __esm({
14245
+ "package.json"() {
14246
+ version = "0.1.0-beta.3";
14247
+ }
14248
+ });
14249
+
14250
+ // src/version.ts
14251
+ var FARM_VERSION;
14252
+ var init_version = __esm({
14253
+ "src/version.ts"() {
14254
+ "use strict";
14255
+ init_package();
14256
+ FARM_VERSION = version;
14257
+ }
14258
+ });
14259
+
14147
14260
  // src/after.ts
14148
14261
  function getAfterStorage() {
14149
14262
  const runtime = globalThis;
@@ -20432,16 +20545,7 @@ __export(devtools_client_exports, {
20432
20545
  function parseShortcut(shortcut) {
20433
20546
  const tokens = shortcut.toLowerCase().split("+").map((token) => token.trim()).filter(Boolean);
20434
20547
  const key = tokens.find(
20435
- (token) => ![
20436
- "alt",
20437
- "ctrl",
20438
- "control",
20439
- "meta",
20440
- "cmd",
20441
- "command",
20442
- "mod",
20443
- "shift"
20444
- ].includes(token)
20548
+ (token) => !["alt", "ctrl", "control", "meta", "cmd", "command", "mod", "shift"].includes(token)
20445
20549
  );
20446
20550
  if (!key) {
20447
20551
  return null;
@@ -20872,7 +20976,7 @@ function isResolvedEnvScope(value) {
20872
20976
  );
20873
20977
  }
20874
20978
  function isPotentialProgrammaticRouteSourceFile(normalizedFile, srcDirSlug) {
20875
- return normalizedFile.startsWith(`${srcDirSlug}/`) && /\.(ts|tsx|js|jsx)$/.test(normalizedFile) && !/\.d\.ts$/.test(normalizedFile) && !normalizedFile.endsWith("/farm-routes.d.ts") && !normalizedFile.endsWith("/farm-env.d.ts") && !normalizedFile.endsWith("/lib/api.generated.ts");
20979
+ return normalizedFile.startsWith(`${srcDirSlug}/`) && /\.(ts|tsx|js|jsx)$/.test(normalizedFile) && !normalizedFile.endsWith(".d.ts") && !normalizedFile.endsWith("/farm-routes.d.ts") && !normalizedFile.endsWith("/farm-env.d.ts") && !normalizedFile.endsWith("/lib/api.generated.ts");
20876
20980
  }
20877
20981
  function fileContainsProgrammaticPageRoute(file) {
20878
20982
  if (!fs7.existsSync(file)) {
@@ -23983,7 +24087,7 @@ async function defineConfig2(config = {}) {
23983
24087
  const isExposed = hostConfig === true || hostConfig === "0.0.0.0";
23984
24088
  console.log("");
23985
24089
  console.log(
23986
- ` ${pc.bold(pc.green("Farm.js"))} ${pc.dim("v1.0.0")} ${pc.dim(`ready in ${elapsed}ms`)}`
24090
+ ` ${pc.bold(pc.green("Farm.js"))} ${pc.dim(`v${FARM_VERSION}`)} ${pc.dim(`ready in ${elapsed}ms`)}`
23987
24091
  );
23988
24092
  console.log("");
23989
24093
  console.log(
@@ -24107,6 +24211,7 @@ var init_vite = __esm({
24107
24211
  path23 = __toESM(require("path"));
24108
24212
  init_layers();
24109
24213
  init_environment_vite();
24214
+ init_version();
24110
24215
  init_deferred();
24111
24216
  init_after();
24112
24217
  init_deployment();
@@ -25322,14 +25427,12 @@ export default defineEventHandler(async (event: H3Event) => {
25322
25427
  ...preset === "cloudflare-module" && cloudflareCronConfig ? {
25323
25428
  cloudflare: cloudflareCronConfig
25324
25429
  } : {},
25325
- handlers: [
25326
- ...farmWorkflows.handlerPath ? [
25327
- {
25328
- route: `${config.workflows.route}/**`,
25329
- handler: farmWorkflows.handlerPath
25330
- }
25331
- ] : []
25332
- ],
25430
+ handlers: farmWorkflows.handlerPath ? [
25431
+ {
25432
+ route: `${config.workflows.route}/**`,
25433
+ handler: farmWorkflows.handlerPath
25434
+ }
25435
+ ] : [],
25333
25436
  // Route rules for Vercel
25334
25437
  routeRules: {
25335
25438
  "/api/**": {
@@ -25723,8 +25826,8 @@ function compareRuntimeRoutes(left, right) {
25723
25826
  __name(compareRuntimeRoutes, "compareRuntimeRoutes");
25724
25827
  function getPatternSpecificity(pattern) {
25725
25828
  return normalizePattern(pattern).split("/").filter(Boolean).reduce((score, segment) => {
25726
- if (segment === "**" || /^\[\[\.\.\./.test(segment)) return score + 1;
25727
- if (segment === "*" || /^\[\.\.\./.test(segment)) return score + 10;
25829
+ if (segment === "**" || segment.startsWith("[[...")) return score + 1;
25830
+ if (segment === "*" || segment.startsWith("[...")) return score + 10;
25728
25831
  if (/^\[.+\]$/.test(segment)) return score + 50;
25729
25832
  return score + 100;
25730
25833
  }, 0);
@@ -30362,9 +30465,8 @@ async function buildNitroUniversal(config, routeManager, apiRouteManager, server
30362
30465
  const nitroEntryPath = import_path12.default.join(ssrOutputDir, "nitro-entry.mjs");
30363
30466
  const nitroEntryCode = `
30364
30467
  // Farm.js Nitro Entry
30365
- // This file imports h3 and the SSR handler, wrapping it for Nitro
30468
+ // This file adapts Farm's Web fetch handler to Nitro's event handler contract.
30366
30469
 
30367
- import { defineEventHandler } from 'h3'
30368
30470
  import handler from './${ssrEntryFile}'
30369
30471
 
30370
30472
  function mergeVaryHeaders(target, source) {
@@ -30402,8 +30504,8 @@ function createResponseFinishedHook(event) {
30402
30504
  }
30403
30505
  }
30404
30506
 
30405
- // Export the wrapped handler for Nitro
30406
- export default defineEventHandler(async (event) => {
30507
+ // Export the event handler for Nitro
30508
+ export default async function farmNitroEventHandler(event) {
30407
30509
  const response = await handler.fetch(event.req, {
30408
30510
  waitUntil: (promise) => event.waitUntil(promise),
30409
30511
  onResponseFinished: createResponseFinishedHook(event),
@@ -30414,7 +30516,7 @@ export default defineEventHandler(async (event) => {
30414
30516
  const farmVary = response.headers.get('Vary')
30415
30517
  if (farmVary) mergeVaryHeaders(event.res.headers, farmVary)
30416
30518
  return response
30417
- })
30519
+ }
30418
30520
  `.trim();
30419
30521
  await fs8.writeFile(nitroEntryPath, nitroEntryCode);
30420
30522
  const prebuiltSSRPlugin = createExternalSSRBundlePlugin(
@@ -30832,8 +30934,8 @@ async function copySharpRuntime(config, root, nitroFuncDir, fs8) {
30832
30934
  await fs8.mkdir(import_path12.default.dirname(targetDir), { recursive: true });
30833
30935
  const packageRequire = (0, import_module2.createRequire)(packageJsonPath);
30834
30936
  const dependencies = {
30835
- ...packageJson.dependencies || {},
30836
- ...packageJson.optionalDependencies || {}
30937
+ ...packageJson.dependencies,
30938
+ ...packageJson.optionalDependencies
30837
30939
  };
30838
30940
  await Promise.all([
30839
30941
  fs8.cp(packageDir, targetDir, {
@@ -30926,7 +31028,7 @@ init_environment_vite();
30926
31028
  // src/server/vite-config.ts
30927
31029
  function mergeNoExternal(farmValue, userValue) {
30928
31030
  if (farmValue === true || userValue === true) return true;
30929
- const normalize = /* @__PURE__ */ __name((value) => value == null ? [] : Array.isArray(value) ? value : [value], "normalize");
31031
+ const normalize = /* @__PURE__ */ __name((value) => value == null || value === true ? [] : Array.isArray(value) ? value : [value], "normalize");
30930
31032
  return Array.from(/* @__PURE__ */ new Set([...normalize(farmValue), ...normalize(userValue)]));
30931
31033
  }
30932
31034
  __name(mergeNoExternal, "mergeNoExternal");