@farm.js/core 0.1.0-beta.0

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 (549) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +11 -0
  3. package/dist/after.cjs +227 -0
  4. package/dist/after.cjs.map +1 -0
  5. package/dist/after.d.mts +25 -0
  6. package/dist/after.d.ts +25 -0
  7. package/dist/after.mjs +14 -0
  8. package/dist/after.mjs.map +1 -0
  9. package/dist/agent-runtime.cjs +2379 -0
  10. package/dist/agent-runtime.cjs.map +1 -0
  11. package/dist/agent-runtime.d.mts +93 -0
  12. package/dist/agent-runtime.d.ts +93 -0
  13. package/dist/agent-runtime.mjs +479 -0
  14. package/dist/agent-runtime.mjs.map +1 -0
  15. package/dist/api/route-manager.cjs +1196 -0
  16. package/dist/api/route-manager.cjs.map +1 -0
  17. package/dist/api/route-manager.d.mts +64 -0
  18. package/dist/api/route-manager.d.ts +64 -0
  19. package/dist/api/route-manager.mjs +34 -0
  20. package/dist/api/route-manager.mjs.map +1 -0
  21. package/dist/api/runtime.cjs +272 -0
  22. package/dist/api/runtime.cjs.map +1 -0
  23. package/dist/api/runtime.d.mts +16 -0
  24. package/dist/api/runtime.d.ts +16 -0
  25. package/dist/api/runtime.mjs +16 -0
  26. package/dist/api/runtime.mjs.map +1 -0
  27. package/dist/api.cjs +3199 -0
  28. package/dist/api.cjs.map +1 -0
  29. package/dist/api.d.mts +190 -0
  30. package/dist/api.d.ts +190 -0
  31. package/dist/api.mjs +63 -0
  32. package/dist/api.mjs.map +1 -0
  33. package/dist/app-BiX4qb-d.d.mts +265 -0
  34. package/dist/app-CFRNJXP1.d.ts +265 -0
  35. package/dist/app-markdown.cjs +220 -0
  36. package/dist/app-markdown.cjs.map +1 -0
  37. package/dist/app-markdown.d.mts +21 -0
  38. package/dist/app-markdown.d.ts +21 -0
  39. package/dist/app-markdown.mjs +26 -0
  40. package/dist/app-markdown.mjs.map +1 -0
  41. package/dist/cache.cjs +543 -0
  42. package/dist/cache.cjs.map +1 -0
  43. package/dist/cache.d.mts +78 -0
  44. package/dist/cache.d.ts +78 -0
  45. package/dist/cache.mjs +38 -0
  46. package/dist/cache.mjs.map +1 -0
  47. package/dist/chunk-25D7G34K.mjs +142 -0
  48. package/dist/chunk-25D7G34K.mjs.map +1 -0
  49. package/dist/chunk-3QJO55ZF.mjs +3548 -0
  50. package/dist/chunk-3QJO55ZF.mjs.map +1 -0
  51. package/dist/chunk-3XNTL3FQ.mjs +452 -0
  52. package/dist/chunk-3XNTL3FQ.mjs.map +1 -0
  53. package/dist/chunk-44ZCFSKE.mjs +84 -0
  54. package/dist/chunk-44ZCFSKE.mjs.map +1 -0
  55. package/dist/chunk-4PTK6KT4.mjs +364 -0
  56. package/dist/chunk-4PTK6KT4.mjs.map +1 -0
  57. package/dist/chunk-4S3ORGFA.mjs +44 -0
  58. package/dist/chunk-4S3ORGFA.mjs.map +1 -0
  59. package/dist/chunk-5BY76U2M.mjs +1 -0
  60. package/dist/chunk-5BY76U2M.mjs.map +1 -0
  61. package/dist/chunk-5ZGPRGWV.mjs +136 -0
  62. package/dist/chunk-5ZGPRGWV.mjs.map +1 -0
  63. package/dist/chunk-6XDUHOEM.mjs +157 -0
  64. package/dist/chunk-6XDUHOEM.mjs.map +1 -0
  65. package/dist/chunk-74YTBPTY.mjs +450 -0
  66. package/dist/chunk-74YTBPTY.mjs.map +1 -0
  67. package/dist/chunk-7HO6AEOP.mjs +74 -0
  68. package/dist/chunk-7HO6AEOP.mjs.map +1 -0
  69. package/dist/chunk-7MABZJIM.mjs +29 -0
  70. package/dist/chunk-7MABZJIM.mjs.map +1 -0
  71. package/dist/chunk-7ZY5AIJO.mjs +161 -0
  72. package/dist/chunk-7ZY5AIJO.mjs.map +1 -0
  73. package/dist/chunk-AGS7UJ52.mjs +446 -0
  74. package/dist/chunk-AGS7UJ52.mjs.map +1 -0
  75. package/dist/chunk-AZ7YUVNR.mjs +65 -0
  76. package/dist/chunk-AZ7YUVNR.mjs.map +1 -0
  77. package/dist/chunk-B232I2GP.mjs +163 -0
  78. package/dist/chunk-B232I2GP.mjs.map +1 -0
  79. package/dist/chunk-B6N4ZB2H.mjs +718 -0
  80. package/dist/chunk-B6N4ZB2H.mjs.map +1 -0
  81. package/dist/chunk-BHG3LVHH.mjs +176 -0
  82. package/dist/chunk-BHG3LVHH.mjs.map +1 -0
  83. package/dist/chunk-C3DLZMBU.mjs +597 -0
  84. package/dist/chunk-C3DLZMBU.mjs.map +1 -0
  85. package/dist/chunk-CGILA3WO.mjs +14 -0
  86. package/dist/chunk-CGILA3WO.mjs.map +1 -0
  87. package/dist/chunk-CHFHNEMO.mjs +7088 -0
  88. package/dist/chunk-CHFHNEMO.mjs.map +1 -0
  89. package/dist/chunk-E2MPIBRE.mjs +149 -0
  90. package/dist/chunk-E2MPIBRE.mjs.map +1 -0
  91. package/dist/chunk-E6EPN5BT.mjs +203 -0
  92. package/dist/chunk-E6EPN5BT.mjs.map +1 -0
  93. package/dist/chunk-EVGBEZDF.mjs +215 -0
  94. package/dist/chunk-EVGBEZDF.mjs.map +1 -0
  95. package/dist/chunk-FQYDHKKU.mjs +128 -0
  96. package/dist/chunk-FQYDHKKU.mjs.map +1 -0
  97. package/dist/chunk-G3B5BRDY.mjs +5763 -0
  98. package/dist/chunk-G3B5BRDY.mjs.map +1 -0
  99. package/dist/chunk-GN72QAIH.mjs +146 -0
  100. package/dist/chunk-GN72QAIH.mjs.map +1 -0
  101. package/dist/chunk-GS6K5OCM.mjs +407 -0
  102. package/dist/chunk-GS6K5OCM.mjs.map +1 -0
  103. package/dist/chunk-GY2STC2S.mjs +180 -0
  104. package/dist/chunk-GY2STC2S.mjs.map +1 -0
  105. package/dist/chunk-GZP5W4K3.mjs +158 -0
  106. package/dist/chunk-GZP5W4K3.mjs.map +1 -0
  107. package/dist/chunk-H2FA2SBS.mjs +51 -0
  108. package/dist/chunk-H2FA2SBS.mjs.map +1 -0
  109. package/dist/chunk-HXP3ZSPC.mjs +211 -0
  110. package/dist/chunk-HXP3ZSPC.mjs.map +1 -0
  111. package/dist/chunk-ITN462YM.mjs +98 -0
  112. package/dist/chunk-ITN462YM.mjs.map +1 -0
  113. package/dist/chunk-J23HNLFY.mjs +72 -0
  114. package/dist/chunk-J23HNLFY.mjs.map +1 -0
  115. package/dist/chunk-J4FNJ5IU.mjs +179 -0
  116. package/dist/chunk-J4FNJ5IU.mjs.map +1 -0
  117. package/dist/chunk-JK25YEN6.mjs +219 -0
  118. package/dist/chunk-JK25YEN6.mjs.map +1 -0
  119. package/dist/chunk-JLWMCADZ.mjs +204 -0
  120. package/dist/chunk-JLWMCADZ.mjs.map +1 -0
  121. package/dist/chunk-JN3UU635.mjs +622 -0
  122. package/dist/chunk-JN3UU635.mjs.map +1 -0
  123. package/dist/chunk-K4667E2Q.mjs +1916 -0
  124. package/dist/chunk-K4667E2Q.mjs.map +1 -0
  125. package/dist/chunk-LGHEOHBU.mjs +218 -0
  126. package/dist/chunk-LGHEOHBU.mjs.map +1 -0
  127. package/dist/chunk-LLC7BNXW.mjs +275 -0
  128. package/dist/chunk-LLC7BNXW.mjs.map +1 -0
  129. package/dist/chunk-LM2YNO4U.mjs +24 -0
  130. package/dist/chunk-LM2YNO4U.mjs.map +1 -0
  131. package/dist/chunk-NNLCAVB6.mjs +391 -0
  132. package/dist/chunk-NNLCAVB6.mjs.map +1 -0
  133. package/dist/chunk-O3HADRW6.mjs +639 -0
  134. package/dist/chunk-O3HADRW6.mjs.map +1 -0
  135. package/dist/chunk-OYXO65LI.mjs +119 -0
  136. package/dist/chunk-OYXO65LI.mjs.map +1 -0
  137. package/dist/chunk-P7QDS5AT.mjs +191 -0
  138. package/dist/chunk-P7QDS5AT.mjs.map +1 -0
  139. package/dist/chunk-PRNYWD7K.mjs +599 -0
  140. package/dist/chunk-PRNYWD7K.mjs.map +1 -0
  141. package/dist/chunk-QF4PHCMA.mjs +422 -0
  142. package/dist/chunk-QF4PHCMA.mjs.map +1 -0
  143. package/dist/chunk-QFQRHRZS.mjs +1224 -0
  144. package/dist/chunk-QFQRHRZS.mjs.map +1 -0
  145. package/dist/chunk-QGOHVJ6J.mjs +63 -0
  146. package/dist/chunk-QGOHVJ6J.mjs.map +1 -0
  147. package/dist/chunk-QKVUNGAH.mjs +39 -0
  148. package/dist/chunk-QKVUNGAH.mjs.map +1 -0
  149. package/dist/chunk-QM6VV26B.mjs +149 -0
  150. package/dist/chunk-QM6VV26B.mjs.map +1 -0
  151. package/dist/chunk-RHIFZZUI.mjs +69 -0
  152. package/dist/chunk-RHIFZZUI.mjs.map +1 -0
  153. package/dist/chunk-RKI6TN3A.mjs +49 -0
  154. package/dist/chunk-RKI6TN3A.mjs.map +1 -0
  155. package/dist/chunk-RSKVYESE.mjs +187 -0
  156. package/dist/chunk-RSKVYESE.mjs.map +1 -0
  157. package/dist/chunk-S2XHZS7W.mjs +180 -0
  158. package/dist/chunk-S2XHZS7W.mjs.map +1 -0
  159. package/dist/chunk-SCFX4UTD.mjs +28 -0
  160. package/dist/chunk-SCFX4UTD.mjs.map +1 -0
  161. package/dist/chunk-SL6HTIOK.mjs +66 -0
  162. package/dist/chunk-SL6HTIOK.mjs.map +1 -0
  163. package/dist/chunk-SOU3Q3ZA.mjs +173 -0
  164. package/dist/chunk-SOU3Q3ZA.mjs.map +1 -0
  165. package/dist/chunk-SPBBQLXI.mjs +207 -0
  166. package/dist/chunk-SPBBQLXI.mjs.map +1 -0
  167. package/dist/chunk-SXZTEK3V.mjs +396 -0
  168. package/dist/chunk-SXZTEK3V.mjs.map +1 -0
  169. package/dist/chunk-T4QJQK76.mjs +459 -0
  170. package/dist/chunk-T4QJQK76.mjs.map +1 -0
  171. package/dist/chunk-TRORP7E4.mjs +41 -0
  172. package/dist/chunk-TRORP7E4.mjs.map +1 -0
  173. package/dist/chunk-TU4YJICB.mjs +728 -0
  174. package/dist/chunk-TU4YJICB.mjs.map +1 -0
  175. package/dist/chunk-TXCFGOHW.mjs +42 -0
  176. package/dist/chunk-TXCFGOHW.mjs.map +1 -0
  177. package/dist/chunk-UHE2TTLK.mjs +466 -0
  178. package/dist/chunk-UHE2TTLK.mjs.map +1 -0
  179. package/dist/chunk-UREJA4GZ.mjs +364 -0
  180. package/dist/chunk-UREJA4GZ.mjs.map +1 -0
  181. package/dist/chunk-USWZZUEH.mjs +25 -0
  182. package/dist/chunk-USWZZUEH.mjs.map +1 -0
  183. package/dist/chunk-UVCIEUJC.mjs +16 -0
  184. package/dist/chunk-UVCIEUJC.mjs.map +1 -0
  185. package/dist/chunk-V6WE6JSZ.mjs +352 -0
  186. package/dist/chunk-V6WE6JSZ.mjs.map +1 -0
  187. package/dist/chunk-V7RBCSDJ.mjs +170 -0
  188. package/dist/chunk-V7RBCSDJ.mjs.map +1 -0
  189. package/dist/chunk-VCANOYFI.mjs +588 -0
  190. package/dist/chunk-VCANOYFI.mjs.map +1 -0
  191. package/dist/chunk-WZ5QFROO.mjs +23 -0
  192. package/dist/chunk-WZ5QFROO.mjs.map +1 -0
  193. package/dist/chunk-Y2OJJD7R.mjs +543 -0
  194. package/dist/chunk-Y2OJJD7R.mjs.map +1 -0
  195. package/dist/chunk-Y7A27276.mjs +538 -0
  196. package/dist/chunk-Y7A27276.mjs.map +1 -0
  197. package/dist/chunk-YHU7SS6L.mjs +365 -0
  198. package/dist/chunk-YHU7SS6L.mjs.map +1 -0
  199. package/dist/chunk-ZBE6MLHL.mjs +230 -0
  200. package/dist/chunk-ZBE6MLHL.mjs.map +1 -0
  201. package/dist/chunk-ZJQNATYV.mjs +299 -0
  202. package/dist/chunk-ZJQNATYV.mjs.map +1 -0
  203. package/dist/client-D_yUjVhe.d.mts +402 -0
  204. package/dist/client-Dkc03WP8.d.ts +402 -0
  205. package/dist/client-cache-CIlyBlmx.d.ts +6 -0
  206. package/dist/client-cache-D-EZ7XVW.d.mts +6 -0
  207. package/dist/client-plugins-BZnpeTGA.d.ts +1848 -0
  208. package/dist/client-plugins-g4bzuCmo.d.mts +1848 -0
  209. package/dist/client-plugins.cjs +415 -0
  210. package/dist/client-plugins.cjs.map +1 -0
  211. package/dist/client-plugins.d.mts +21 -0
  212. package/dist/client-plugins.d.ts +21 -0
  213. package/dist/client-plugins.mjs +10 -0
  214. package/dist/client-plugins.mjs.map +1 -0
  215. package/dist/client.cjs +4571 -0
  216. package/dist/client.cjs.map +1 -0
  217. package/dist/client.d.mts +329 -0
  218. package/dist/client.d.ts +329 -0
  219. package/dist/client.mjs +103 -0
  220. package/dist/client.mjs.map +1 -0
  221. package/dist/config.cjs +38 -0
  222. package/dist/config.cjs.map +1 -0
  223. package/dist/config.d.mts +28 -0
  224. package/dist/config.d.ts +28 -0
  225. package/dist/config.mjs +10 -0
  226. package/dist/config.mjs.map +1 -0
  227. package/dist/cron.cjs +406 -0
  228. package/dist/cron.cjs.map +1 -0
  229. package/dist/cron.d.mts +78 -0
  230. package/dist/cron.d.ts +78 -0
  231. package/dist/cron.mjs +30 -0
  232. package/dist/cron.mjs.map +1 -0
  233. package/dist/deferred.cjs +438 -0
  234. package/dist/deferred.cjs.map +1 -0
  235. package/dist/deferred.d.mts +42 -0
  236. package/dist/deferred.d.ts +42 -0
  237. package/dist/deferred.mjs +28 -0
  238. package/dist/deferred.mjs.map +1 -0
  239. package/dist/deployment.cjs +199 -0
  240. package/dist/deployment.cjs.map +1 -0
  241. package/dist/deployment.d.mts +34 -0
  242. package/dist/deployment.d.ts +34 -0
  243. package/dist/deployment.mjs +38 -0
  244. package/dist/deployment.mjs.map +1 -0
  245. package/dist/devtools-AE4RVXCM.mjs +370 -0
  246. package/dist/devtools-AE4RVXCM.mjs.map +1 -0
  247. package/dist/devtools-client-6WPY2AQU.mjs +225 -0
  248. package/dist/devtools-client-6WPY2AQU.mjs.map +1 -0
  249. package/dist/devtools-ui-NJKFORTG.mjs +1349 -0
  250. package/dist/devtools-ui-NJKFORTG.mjs.map +1 -0
  251. package/dist/docs.cjs +5541 -0
  252. package/dist/docs.cjs.map +1 -0
  253. package/dist/docs.d.mts +69 -0
  254. package/dist/docs.d.ts +69 -0
  255. package/dist/docs.mjs +46 -0
  256. package/dist/docs.mjs.map +1 -0
  257. package/dist/env-types.cjs +223 -0
  258. package/dist/env-types.cjs.map +1 -0
  259. package/dist/env-types.d.mts +11 -0
  260. package/dist/env-types.d.ts +11 -0
  261. package/dist/env-types.mjs +9 -0
  262. package/dist/env-types.mjs.map +1 -0
  263. package/dist/env.cjs +215 -0
  264. package/dist/env.cjs.map +1 -0
  265. package/dist/env.d.mts +45 -0
  266. package/dist/env.d.ts +45 -0
  267. package/dist/env.mjs +22 -0
  268. package/dist/env.mjs.map +1 -0
  269. package/dist/environment/vite.cjs +374 -0
  270. package/dist/environment/vite.cjs.map +1 -0
  271. package/dist/environment/vite.d.mts +22 -0
  272. package/dist/environment/vite.d.ts +22 -0
  273. package/dist/environment/vite.mjs +10 -0
  274. package/dist/environment/vite.mjs.map +1 -0
  275. package/dist/environment.cjs +96 -0
  276. package/dist/environment.cjs.map +1 -0
  277. package/dist/environment.d.mts +18 -0
  278. package/dist/environment.d.ts +18 -0
  279. package/dist/environment.mjs +14 -0
  280. package/dist/environment.mjs.map +1 -0
  281. package/dist/headers.cjs +126 -0
  282. package/dist/headers.cjs.map +1 -0
  283. package/dist/headers.d.mts +22 -0
  284. package/dist/headers.d.ts +22 -0
  285. package/dist/headers.mjs +12 -0
  286. package/dist/headers.mjs.map +1 -0
  287. package/dist/i18n/client.cjs +283 -0
  288. package/dist/i18n/client.cjs.map +1 -0
  289. package/dist/i18n/client.d.mts +32 -0
  290. package/dist/i18n/client.d.ts +32 -0
  291. package/dist/i18n/client.mjs +121 -0
  292. package/dist/i18n/client.mjs.map +1 -0
  293. package/dist/i18n/index.cjs +130 -0
  294. package/dist/i18n/index.cjs.map +1 -0
  295. package/dist/i18n/index.d.mts +20 -0
  296. package/dist/i18n/index.d.ts +20 -0
  297. package/dist/i18n/index.mjs +22 -0
  298. package/dist/i18n/index.mjs.map +1 -0
  299. package/dist/i18n/server.cjs +637 -0
  300. package/dist/i18n/server.cjs.map +1 -0
  301. package/dist/i18n/server.d.mts +30 -0
  302. package/dist/i18n/server.d.ts +30 -0
  303. package/dist/i18n/server.mjs +32 -0
  304. package/dist/i18n/server.mjs.map +1 -0
  305. package/dist/image/server.cjs +477 -0
  306. package/dist/image/server.cjs.map +1 -0
  307. package/dist/image/server.d.mts +37 -0
  308. package/dist/image/server.d.ts +37 -0
  309. package/dist/image/server.mjs +16 -0
  310. package/dist/image/server.mjs.map +1 -0
  311. package/dist/image/sharp.cjs +135 -0
  312. package/dist/image/sharp.cjs.map +1 -0
  313. package/dist/image/sharp.d.mts +7 -0
  314. package/dist/image/sharp.d.ts +7 -0
  315. package/dist/image/sharp.mjs +75 -0
  316. package/dist/image/sharp.mjs.map +1 -0
  317. package/dist/image-config-Duob7wER.d.mts +50 -0
  318. package/dist/image-config-Duob7wER.d.ts +50 -0
  319. package/dist/image.cjs +209 -0
  320. package/dist/image.cjs.map +1 -0
  321. package/dist/image.d.mts +39 -0
  322. package/dist/image.d.ts +39 -0
  323. package/dist/image.mjs +165 -0
  324. package/dist/image.mjs.map +1 -0
  325. package/dist/index.cjs +39433 -0
  326. package/dist/index.cjs.map +1 -0
  327. package/dist/index.d.mts +451 -0
  328. package/dist/index.d.ts +451 -0
  329. package/dist/index.mjs +930 -0
  330. package/dist/index.mjs.map +1 -0
  331. package/dist/integration-api-CHT2OKAf.d.mts +93 -0
  332. package/dist/integration-api-CHT2OKAf.d.ts +93 -0
  333. package/dist/integration-orm-GQLGU66X.mjs +13 -0
  334. package/dist/integration-orm-GQLGU66X.mjs.map +1 -0
  335. package/dist/integrations.cjs +2820 -0
  336. package/dist/integrations.cjs.map +1 -0
  337. package/dist/integrations.d.mts +21 -0
  338. package/dist/integrations.d.ts +21 -0
  339. package/dist/integrations.mjs +51 -0
  340. package/dist/integrations.mjs.map +1 -0
  341. package/dist/internal/build-runtime.cjs +31340 -0
  342. package/dist/internal/build-runtime.cjs.map +1 -0
  343. package/dist/internal/build-runtime.d.mts +38 -0
  344. package/dist/internal/build-runtime.d.ts +38 -0
  345. package/dist/internal/build-runtime.mjs +73 -0
  346. package/dist/internal/build-runtime.mjs.map +1 -0
  347. package/dist/internal/client-runtime.cjs +579 -0
  348. package/dist/internal/client-runtime.cjs.map +1 -0
  349. package/dist/internal/client-runtime.d.mts +2 -0
  350. package/dist/internal/client-runtime.d.ts +2 -0
  351. package/dist/internal/client-runtime.mjs +12 -0
  352. package/dist/internal/client-runtime.mjs.map +1 -0
  353. package/dist/internal/config-runtime.cjs +4172 -0
  354. package/dist/internal/config-runtime.cjs.map +1 -0
  355. package/dist/internal/config-runtime.d.mts +38 -0
  356. package/dist/internal/config-runtime.d.ts +38 -0
  357. package/dist/internal/config-runtime.mjs +38 -0
  358. package/dist/internal/config-runtime.mjs.map +1 -0
  359. package/dist/internal/production-node-env.cjs +65 -0
  360. package/dist/internal/production-node-env.cjs.map +1 -0
  361. package/dist/internal/production-node-env.d.mts +12 -0
  362. package/dist/internal/production-node-env.d.ts +12 -0
  363. package/dist/internal/production-node-env.mjs +8 -0
  364. package/dist/internal/production-node-env.mjs.map +1 -0
  365. package/dist/internal/production-runtime.cjs +1896 -0
  366. package/dist/internal/production-runtime.cjs.map +1 -0
  367. package/dist/internal/production-runtime.d.mts +39 -0
  368. package/dist/internal/production-runtime.d.ts +39 -0
  369. package/dist/internal/production-runtime.mjs +79 -0
  370. package/dist/internal/production-runtime.mjs.map +1 -0
  371. package/dist/layers-VWVDTPUZ.mjs +16 -0
  372. package/dist/layers-VWVDTPUZ.mjs.map +1 -0
  373. package/dist/manager-THKFTOFE.mjs +10 -0
  374. package/dist/manager-THKFTOFE.mjs.map +1 -0
  375. package/dist/markdown.cjs +299 -0
  376. package/dist/markdown.cjs.map +1 -0
  377. package/dist/markdown.d.mts +43 -0
  378. package/dist/markdown.d.ts +43 -0
  379. package/dist/markdown.mjs +14 -0
  380. package/dist/markdown.mjs.map +1 -0
  381. package/dist/metadata-C9NZxMDW.d.mts +22 -0
  382. package/dist/metadata-DAXRaOHx.d.ts +22 -0
  383. package/dist/middleware.cjs +2148 -0
  384. package/dist/middleware.cjs.map +1 -0
  385. package/dist/middleware.d.mts +163 -0
  386. package/dist/middleware.d.ts +163 -0
  387. package/dist/middleware.mjs +49 -0
  388. package/dist/middleware.mjs.map +1 -0
  389. package/dist/navigation-errors-Dvwpzaer.d.mts +13 -0
  390. package/dist/navigation-errors-Dvwpzaer.d.ts +13 -0
  391. package/dist/navigation.cjs +1304 -0
  392. package/dist/navigation.cjs.map +1 -0
  393. package/dist/navigation.d.mts +14 -0
  394. package/dist/navigation.d.ts +14 -0
  395. package/dist/navigation.mjs +33 -0
  396. package/dist/navigation.mjs.map +1 -0
  397. package/dist/nitro-KME62MWG.mjs +691 -0
  398. package/dist/nitro-KME62MWG.mjs.map +1 -0
  399. package/dist/observability.cjs +186 -0
  400. package/dist/observability.cjs.map +1 -0
  401. package/dist/observability.d.mts +335 -0
  402. package/dist/observability.d.ts +335 -0
  403. package/dist/observability.mjs +16 -0
  404. package/dist/observability.mjs.map +1 -0
  405. package/dist/params-BALtrRim.d.ts +15 -0
  406. package/dist/params-ry-lxqmy.d.mts +15 -0
  407. package/dist/plugin-BJDf43dc.d.mts +165 -0
  408. package/dist/plugin-BJDf43dc.d.ts +165 -0
  409. package/dist/plugin.cjs +22285 -0
  410. package/dist/plugin.cjs.map +1 -0
  411. package/dist/plugin.d.mts +21 -0
  412. package/dist/plugin.d.ts +21 -0
  413. package/dist/plugin.mjs +60 -0
  414. package/dist/plugin.mjs.map +1 -0
  415. package/dist/production-runtime-C_B79w2P.d.mts +28 -0
  416. package/dist/production-runtime-DDEM1D2q.d.ts +28 -0
  417. package/dist/production-runtime-DRkCHUvJ.d.ts +79 -0
  418. package/dist/production-runtime-flrjp_nC.d.mts +79 -0
  419. package/dist/query/client.cjs +560 -0
  420. package/dist/query/client.cjs.map +1 -0
  421. package/dist/query/client.d.mts +61 -0
  422. package/dist/query/client.d.ts +61 -0
  423. package/dist/query/client.mjs +364 -0
  424. package/dist/query/client.mjs.map +1 -0
  425. package/dist/query/index.cjs +226 -0
  426. package/dist/query/index.cjs.map +1 -0
  427. package/dist/query/index.d.mts +90 -0
  428. package/dist/query/index.d.ts +90 -0
  429. package/dist/query/index.mjs +31 -0
  430. package/dist/query/index.mjs.map +1 -0
  431. package/dist/query/parsers.cjs +178 -0
  432. package/dist/query/parsers.cjs.map +1 -0
  433. package/dist/query/parsers.d.mts +25 -0
  434. package/dist/query/parsers.d.ts +25 -0
  435. package/dist/query/parsers.mjs +24 -0
  436. package/dist/query/parsers.mjs.map +1 -0
  437. package/dist/query/server.cjs +301 -0
  438. package/dist/query/server.cjs.map +1 -0
  439. package/dist/query/server.d.mts +55 -0
  440. package/dist/query/server.d.ts +55 -0
  441. package/dist/query/server.mjs +105 -0
  442. package/dist/query/server.mjs.map +1 -0
  443. package/dist/request-BrFBuc8G.d.mts +6 -0
  444. package/dist/request-BslSZIRz.d.ts +6 -0
  445. package/dist/request.cjs +71 -0
  446. package/dist/request.cjs.map +1 -0
  447. package/dist/request.d.mts +2 -0
  448. package/dist/request.d.ts +2 -0
  449. package/dist/request.mjs +9 -0
  450. package/dist/request.mjs.map +1 -0
  451. package/dist/resolver-C6iecsDV.d.ts +14 -0
  452. package/dist/resolver-DlOPpjkB.d.mts +14 -0
  453. package/dist/route-runtime-DoOHzCAD.d.mts +38 -0
  454. package/dist/route-runtime-DoOHzCAD.d.ts +38 -0
  455. package/dist/router.cjs +254 -0
  456. package/dist/router.cjs.map +1 -0
  457. package/dist/router.d.mts +36 -0
  458. package/dist/router.d.ts +36 -0
  459. package/dist/router.mjs +14 -0
  460. package/dist/router.mjs.map +1 -0
  461. package/dist/routes.cjs +1213 -0
  462. package/dist/routes.cjs.map +1 -0
  463. package/dist/routes.d.mts +224 -0
  464. package/dist/routes.d.ts +224 -0
  465. package/dist/routes.mjs +52 -0
  466. package/dist/routes.mjs.map +1 -0
  467. package/dist/runtime-B6GvwDS1.d.ts +27 -0
  468. package/dist/runtime-DeAAZ6gO.d.mts +27 -0
  469. package/dist/search-client-6OXIBNYQ.mjs +14 -0
  470. package/dist/search-client-6OXIBNYQ.mjs.map +1 -0
  471. package/dist/server-action-security.cjs +492 -0
  472. package/dist/server-action-security.cjs.map +1 -0
  473. package/dist/server-action-security.d.mts +42 -0
  474. package/dist/server-action-security.d.ts +42 -0
  475. package/dist/server-action-security.mjs +29 -0
  476. package/dist/server-action-security.mjs.map +1 -0
  477. package/dist/server-fn-client.cjs +180 -0
  478. package/dist/server-fn-client.cjs.map +1 -0
  479. package/dist/server-fn-client.d.mts +31 -0
  480. package/dist/server-fn-client.d.ts +31 -0
  481. package/dist/server-fn-client.mjs +9 -0
  482. package/dist/server-fn-client.mjs.map +1 -0
  483. package/dist/server-fn.cjs +284 -0
  484. package/dist/server-fn.cjs.map +1 -0
  485. package/dist/server-fn.d.mts +84 -0
  486. package/dist/server-fn.d.ts +84 -0
  487. package/dist/server-fn.mjs +17 -0
  488. package/dist/server-fn.mjs.map +1 -0
  489. package/dist/server-plugins.cjs +235 -0
  490. package/dist/server-plugins.cjs.map +1 -0
  491. package/dist/server-plugins.d.mts +54 -0
  492. package/dist/server-plugins.d.ts +54 -0
  493. package/dist/server-plugins.mjs +18 -0
  494. package/dist/server-plugins.mjs.map +1 -0
  495. package/dist/server-query-client.cjs +792 -0
  496. package/dist/server-query-client.cjs.map +1 -0
  497. package/dist/server-query-client.d.mts +50 -0
  498. package/dist/server-query-client.d.ts +50 -0
  499. package/dist/server-query-client.mjs +23 -0
  500. package/dist/server-query-client.mjs.map +1 -0
  501. package/dist/server-query.cjs +804 -0
  502. package/dist/server-query.cjs.map +1 -0
  503. package/dist/server-query.d.mts +36 -0
  504. package/dist/server-query.d.ts +36 -0
  505. package/dist/server-query.mjs +18 -0
  506. package/dist/server-query.mjs.map +1 -0
  507. package/dist/server.cjs +25739 -0
  508. package/dist/server.cjs.map +1 -0
  509. package/dist/server.d.mts +47 -0
  510. package/dist/server.d.ts +47 -0
  511. package/dist/server.mjs +511 -0
  512. package/dist/server.mjs.map +1 -0
  513. package/dist/storage.cjs +515 -0
  514. package/dist/storage.cjs.map +1 -0
  515. package/dist/storage.d.mts +52 -0
  516. package/dist/storage.d.ts +52 -0
  517. package/dist/storage.mjs +58 -0
  518. package/dist/storage.mjs.map +1 -0
  519. package/dist/testing.cjs +1882 -0
  520. package/dist/testing.cjs.map +1 -0
  521. package/dist/testing.d.mts +100 -0
  522. package/dist/testing.d.ts +100 -0
  523. package/dist/testing.mjs +324 -0
  524. package/dist/testing.mjs.map +1 -0
  525. package/dist/types-BH1lhg5G.d.mts +81 -0
  526. package/dist/types-BH1lhg5G.d.ts +81 -0
  527. package/dist/types-C9N-nk5R.d.mts +53 -0
  528. package/dist/types-C9N-nk5R.d.ts +53 -0
  529. package/dist/types-D1A6-XvH.d.mts +73 -0
  530. package/dist/types-D1A6-XvH.d.ts +73 -0
  531. package/dist/utils-DA1yo54_.d.ts +23 -0
  532. package/dist/utils-DOXXivjL.d.mts +23 -0
  533. package/dist/vite.cjs +22684 -0
  534. package/dist/vite.cjs.map +1 -0
  535. package/dist/vite.d.mts +21 -0
  536. package/dist/vite.d.ts +21 -0
  537. package/dist/vite.mjs +59 -0
  538. package/dist/vite.mjs.map +1 -0
  539. package/dist/workflows.cjs +586 -0
  540. package/dist/workflows.cjs.map +1 -0
  541. package/dist/workflows.d.mts +110 -0
  542. package/dist/workflows.d.ts +110 -0
  543. package/dist/workflows.mjs +32 -0
  544. package/dist/workflows.mjs.map +1 -0
  545. package/package.json +523 -0
  546. package/types/api.d.ts +88 -0
  547. package/types/client.d.ts +1171 -0
  548. package/types/index.d.ts +17 -0
  549. package/types/middleware.d.ts +266 -0
@@ -0,0 +1,1196 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/api/route-manager.ts
32
+ var route_manager_exports = {};
33
+ __export(route_manager_exports, {
34
+ APIRouteManager: () => APIRouteManager,
35
+ API_ROUTE_METHODS: () => API_ROUTE_METHODS,
36
+ invokeAPIRouteEndpoint: () => invokeAPIRouteEndpoint,
37
+ isWebResponse: () => isWebResponse,
38
+ matchAPIRoute: () => matchAPIRoute,
39
+ normalizeRouteResponse: () => normalizeRouteResponse
40
+ });
41
+ module.exports = __toCommonJS(route_manager_exports);
42
+ var fs = __toESM(require("fs"));
43
+ var path2 = __toESM(require("path"));
44
+
45
+ // src/utils.ts
46
+ var logger = {
47
+ info: /* @__PURE__ */ __name((message) => console.log(`[info] ${message}`), "info"),
48
+ success: /* @__PURE__ */ __name((message) => console.log(`[success] ${message}`), "success"),
49
+ warn: /* @__PURE__ */ __name((message) => console.warn(`\u26A0\uFE0F ${message}`), "warn"),
50
+ error: /* @__PURE__ */ __name((message) => console.error(`\u274C ${message}`), "error"),
51
+ ready: /* @__PURE__ */ __name((message) => console.log(`${message}`), "ready"),
52
+ event: /* @__PURE__ */ __name((message) => console.log(` ${message}`), "event")
53
+ };
54
+
55
+ // src/routes.ts
56
+ var import_react = require("react");
57
+
58
+ // src/observability.ts
59
+ var runtimeHandlers = /* @__PURE__ */ new Set();
60
+ var observabilityState = {
61
+ logs: false,
62
+ handlers: []
63
+ };
64
+ function emitFarmEvent(input) {
65
+ const event = {
66
+ timestamp: Date.now(),
67
+ level: inferFarmEventLevel(input.type),
68
+ ...input
69
+ };
70
+ if (!shouldEmitFarmEvent(event)) {
71
+ return event;
72
+ }
73
+ if (observabilityState.logs) {
74
+ logFarmEvent(event);
75
+ }
76
+ for (const handler of [...observabilityState.handlers, ...runtimeHandlers]) {
77
+ try {
78
+ Promise.resolve(handler(event)).catch((error) => {
79
+ console.warn(`[farm:observability] event handler failed: ${formatError(error)}`);
80
+ });
81
+ } catch (error) {
82
+ console.warn(`[farm:observability] event handler failed: ${formatError(error)}`);
83
+ }
84
+ }
85
+ return event;
86
+ }
87
+ __name(emitFarmEvent, "emitFarmEvent");
88
+ function shouldEmitFarmEvent(event) {
89
+ if (!observabilityState.logs && observabilityState.handlers.length === 0 && runtimeHandlers.size === 0) {
90
+ return false;
91
+ }
92
+ if (observabilityState.events && !observabilityState.events.has(event.type)) {
93
+ return false;
94
+ }
95
+ return true;
96
+ }
97
+ __name(shouldEmitFarmEvent, "shouldEmitFarmEvent");
98
+ function inferFarmEventLevel(type) {
99
+ if (type === "error" || type.endsWith(".error") || type.endsWith(".failed")) {
100
+ return "error";
101
+ }
102
+ if (type.endsWith(".bypass") || type.endsWith(".invalidated") || type.endsWith(".stale") || type.endsWith(".notFound")) {
103
+ return "warn";
104
+ }
105
+ if (type.endsWith(".hit") || type.endsWith(".miss") || type.endsWith(".start") || type.endsWith(".shellReady")) {
106
+ return "debug";
107
+ }
108
+ return "info";
109
+ }
110
+ __name(inferFarmEventLevel, "inferFarmEventLevel");
111
+ function logFarmEvent(event) {
112
+ const message = `[farm:${event.level}] ${event.type}${formatFarmEventDetails(event)}`;
113
+ switch (event.level) {
114
+ case "error":
115
+ console.error(message);
116
+ break;
117
+ case "warn":
118
+ console.warn(message);
119
+ break;
120
+ default:
121
+ console.log(message);
122
+ break;
123
+ }
124
+ }
125
+ __name(logFarmEvent, "logFarmEvent");
126
+ function formatFarmEventDetails(event) {
127
+ const details = [];
128
+ const record = event;
129
+ for (const key of [
130
+ "route",
131
+ "pathname",
132
+ "method",
133
+ "status",
134
+ "key",
135
+ "tag",
136
+ "path",
137
+ "reason",
138
+ "durationMs",
139
+ "integration",
140
+ "operation",
141
+ "plugin",
142
+ "hook",
143
+ "target",
144
+ "count"
145
+ ]) {
146
+ const value = record[key];
147
+ if (value !== void 0) {
148
+ details.push(`${key}=${formatDetailValue(value)}`);
149
+ }
150
+ }
151
+ return details.length > 0 ? ` ${details.join(" ")}` : "";
152
+ }
153
+ __name(formatFarmEventDetails, "formatFarmEventDetails");
154
+ function formatDetailValue(value) {
155
+ if (typeof value === "string") {
156
+ return value;
157
+ }
158
+ if (typeof value === "number" || typeof value === "boolean") {
159
+ return String(value);
160
+ }
161
+ try {
162
+ return JSON.stringify(value);
163
+ } catch {
164
+ return String(value);
165
+ }
166
+ }
167
+ __name(formatDetailValue, "formatDetailValue");
168
+ function formatError(error) {
169
+ return error instanceof Error ? error.message : String(error);
170
+ }
171
+ __name(formatError, "formatError");
172
+
173
+ // src/i18n/bridge.ts
174
+ var FARM_I18N_SNAPSHOT_RESOLVER = /* @__PURE__ */ Symbol.for("farm.i18n.snapshotResolver");
175
+ function _setFarmI18nSnapshotResolver(resolver) {
176
+ globalThis[FARM_I18N_SNAPSHOT_RESOLVER] = resolver;
177
+ }
178
+ __name(_setFarmI18nSnapshotResolver, "_setFarmI18nSnapshotResolver");
179
+
180
+ // src/cache.ts
181
+ var _FarmDataCache = class _FarmDataCache {
182
+ constructor() {
183
+ this.entries = /* @__PURE__ */ new Map();
184
+ this.inflight = /* @__PURE__ */ new Map();
185
+ this.invalidatedTagVersions = /* @__PURE__ */ new Map();
186
+ this.version = 0;
187
+ }
188
+ get size() {
189
+ return this.entries.size;
190
+ }
191
+ get(key, options = {}) {
192
+ return this.getEntry(key, options)?.value;
193
+ }
194
+ getEntry(key, options = {}) {
195
+ const entry = this.entries.get(key);
196
+ if (!entry) {
197
+ emitFarmEvent({ type: "cache.miss", key });
198
+ return void 0;
199
+ }
200
+ const stale = this.isStale(entry, options.now);
201
+ if (stale) {
202
+ emitFarmEvent({
203
+ type: "cache.stale",
204
+ key,
205
+ tags: Array.from(entry.tags),
206
+ revalidate: entry.revalidate
207
+ });
208
+ }
209
+ if (!options.allowStale && stale) {
210
+ emitFarmEvent({ type: "cache.miss", key, reason: "stale" });
211
+ return void 0;
212
+ }
213
+ emitFarmEvent({
214
+ type: "cache.hit",
215
+ key,
216
+ tags: Array.from(entry.tags),
217
+ revalidate: entry.revalidate,
218
+ stale
219
+ });
220
+ return this.toPublicEntry(entry);
221
+ }
222
+ set(key, value, options = {}) {
223
+ const tags = /* @__PURE__ */ new Set();
224
+ for (const tag of options.tags ?? []) {
225
+ tags.add(normalizeCacheTag(tag));
226
+ }
227
+ for (const routePath of options.paths ?? []) {
228
+ tags.add(createPathCacheTag(routePath));
229
+ }
230
+ const entry = {
231
+ key,
232
+ value,
233
+ tags,
234
+ createdAt: options.createdAt ?? Date.now(),
235
+ createdVersion: ++this.version,
236
+ revalidate: normalizeRevalidate(options.revalidate)
237
+ };
238
+ this.entries.set(key, entry);
239
+ emitFarmEvent({
240
+ type: "cache.set",
241
+ key,
242
+ tags: Array.from(tags),
243
+ revalidate: entry.revalidate
244
+ });
245
+ return this.toPublicEntry(entry);
246
+ }
247
+ delete(key) {
248
+ const deleted = this.entries.delete(key);
249
+ emitFarmEvent({ type: "cache.delete", key, deleted });
250
+ return deleted;
251
+ }
252
+ clear() {
253
+ const count = this.entries.size;
254
+ this.entries.clear();
255
+ this.inflight.clear();
256
+ this.invalidatedTagVersions.clear();
257
+ this.version = 0;
258
+ emitFarmEvent({ type: "cache.clear", count });
259
+ }
260
+ isStale(entry, now = Date.now()) {
261
+ if (typeof entry.revalidate === "number" && entry.revalidate > 0 && now - entry.createdAt >= entry.revalidate * 1e3) {
262
+ return true;
263
+ }
264
+ for (const tag of entry.tags) {
265
+ const invalidatedVersion = this.invalidatedTagVersions.get(normalizeCacheTag(tag));
266
+ if (typeof invalidatedVersion === "number" && typeof entry.createdVersion === "number" && invalidatedVersion > entry.createdVersion) {
267
+ return true;
268
+ }
269
+ }
270
+ return false;
271
+ }
272
+ revalidateTag(tag, options = {}) {
273
+ const normalized = normalizeCacheTag(tag);
274
+ const count = this.invalidateTag(normalized);
275
+ emitFarmEvent(
276
+ options.source === "updateTag" ? { type: "cache.updateTag", tag: normalized, count } : { type: "cache.revalidateTag", tag: normalized, profile: options.profile, count }
277
+ );
278
+ return count;
279
+ }
280
+ revalidatePath(routePath) {
281
+ const normalizedPath = normalizeRevalidatePath(routePath);
282
+ const pathTag = createPathCacheTag(normalizedPath);
283
+ const pprCount = this.countEntriesForTags([pathTag, "ppr"]);
284
+ const count = this.invalidateTag(pathTag);
285
+ emitFarmEvent({ type: "cache.revalidatePath", path: normalizedPath, count });
286
+ if (pprCount > 0) {
287
+ emitFarmEvent({
288
+ type: "ppr.shell.invalidated",
289
+ route: normalizedPath,
290
+ reason: "revalidatePath",
291
+ count: pprCount
292
+ });
293
+ }
294
+ return count;
295
+ }
296
+ async getOrSet(key, producer, options = {}) {
297
+ const cached = this.getEntry(key);
298
+ if (cached) {
299
+ return cached.value;
300
+ }
301
+ const inflight = this.inflight.get(key);
302
+ if (inflight) {
303
+ emitFarmEvent({ type: "cache.dedupe", key });
304
+ return inflight;
305
+ }
306
+ const promise = Promise.resolve().then(producer).then((value) => {
307
+ this.set(key, value, options);
308
+ return value;
309
+ }).catch((error) => {
310
+ emitFarmEvent({ type: "cache.error", key, operation: "set", error });
311
+ throw error;
312
+ }).finally(() => {
313
+ this.inflight.delete(key);
314
+ });
315
+ this.inflight.set(key, promise);
316
+ return promise;
317
+ }
318
+ countEntriesForTag(tag) {
319
+ let count = 0;
320
+ for (const entry of this.entries.values()) {
321
+ if (entry.tags.has(tag)) {
322
+ count++;
323
+ }
324
+ }
325
+ return count;
326
+ }
327
+ countEntriesForTags(tags) {
328
+ let count = 0;
329
+ for (const entry of this.entries.values()) {
330
+ if (tags.every((tag) => entry.tags.has(tag))) {
331
+ count++;
332
+ }
333
+ }
334
+ return count;
335
+ }
336
+ invalidateTag(normalizedTag) {
337
+ this.invalidatedTagVersions.set(normalizedTag, ++this.version);
338
+ return this.countEntriesForTag(normalizedTag);
339
+ }
340
+ toPublicEntry(entry) {
341
+ return {
342
+ key: entry.key,
343
+ value: entry.value,
344
+ tags: Array.from(entry.tags),
345
+ createdAt: entry.createdAt,
346
+ createdVersion: entry.createdVersion,
347
+ revalidate: entry.revalidate
348
+ };
349
+ }
350
+ };
351
+ __name(_FarmDataCache, "FarmDataCache");
352
+ var FarmDataCache = _FarmDataCache;
353
+ var FARM_DATA_CACHE_SYMBOL = /* @__PURE__ */ Symbol.for("farm.dataCache");
354
+ var farmDataCacheGlobal = globalThis;
355
+ var sharedFarmDataCache = farmDataCacheGlobal[FARM_DATA_CACHE_SYMBOL] ?? (farmDataCacheGlobal[FARM_DATA_CACHE_SYMBOL] = new FarmDataCache());
356
+ function createPathCacheTag(routePath) {
357
+ return `path:${normalizeRevalidatePath(routePath)}`;
358
+ }
359
+ __name(createPathCacheTag, "createPathCacheTag");
360
+ function normalizeRevalidatePath(routePath) {
361
+ if (typeof routePath !== "string") {
362
+ throw new TypeError("revalidatePath expects a path string.");
363
+ }
364
+ let normalized = routePath.trim();
365
+ if (!normalized) {
366
+ throw new Error("revalidatePath expects a non-empty path.");
367
+ }
368
+ try {
369
+ if (/^https?:\/\//.test(normalized)) {
370
+ normalized = new URL(normalized).pathname;
371
+ }
372
+ } catch {
373
+ }
374
+ normalized = normalized.split("?")[0] ?? normalized;
375
+ normalized = normalized.startsWith("/") ? normalized : `/${normalized}`;
376
+ normalized = normalized.replace(/\/{2,}/g, "/");
377
+ if (normalized.length > 1) {
378
+ normalized = normalized.replace(/\/+$/, "");
379
+ }
380
+ return normalized || "/";
381
+ }
382
+ __name(normalizeRevalidatePath, "normalizeRevalidatePath");
383
+ function normalizeRevalidate(revalidate) {
384
+ if (revalidate === false || revalidate === void 0) {
385
+ return revalidate;
386
+ }
387
+ if (!Number.isFinite(revalidate) || revalidate <= 0) {
388
+ return void 0;
389
+ }
390
+ return revalidate;
391
+ }
392
+ __name(normalizeRevalidate, "normalizeRevalidate");
393
+ function normalizeCacheTag(tag) {
394
+ if (typeof tag !== "string") {
395
+ throw new TypeError("Cache tags must be strings.");
396
+ }
397
+ const normalized = tag.trim();
398
+ if (!normalized) {
399
+ throw new Error("Cache tags cannot be empty.");
400
+ }
401
+ return normalized;
402
+ }
403
+ __name(normalizeCacheTag, "normalizeCacheTag");
404
+
405
+ // src/route-runtime.ts
406
+ function normalizeFarmRouteRuntimeConfig(value, source = "Route configuration") {
407
+ if (!value) return {};
408
+ const normalized = {};
409
+ if (value.runtime !== void 0) {
410
+ if (value.runtime !== "auto" && value.runtime !== "node" && value.runtime !== "edge") {
411
+ throw new TypeError(`${source} runtime must be "auto", "node", or "edge"`);
412
+ }
413
+ normalized.runtime = value.runtime;
414
+ }
415
+ if (value.regions !== void 0) {
416
+ if (value.regions === "auto") {
417
+ normalized.regions = "auto";
418
+ } else {
419
+ if (!Array.isArray(value.regions) || value.regions.length === 0) {
420
+ throw new TypeError(`${source} regions must be "auto" or a non-empty string array`);
421
+ }
422
+ const regions = Array.from(
423
+ new Set(
424
+ value.regions.map((region) => {
425
+ if (typeof region !== "string" || !region.trim() || /[\u0000-\u001f\u007f]/.test(region)) {
426
+ throw new TypeError(`${source} regions must contain non-empty region identifiers`);
427
+ }
428
+ return region.trim();
429
+ })
430
+ )
431
+ );
432
+ normalized.regions = regions;
433
+ }
434
+ }
435
+ if (value.maxDuration !== void 0) {
436
+ if (value.maxDuration === "auto") {
437
+ normalized.maxDuration = "auto";
438
+ } else if (typeof value.maxDuration !== "number" || !Number.isInteger(value.maxDuration) || value.maxDuration <= 0) {
439
+ throw new TypeError(`${source} maxDuration must be "auto" or a positive integer in seconds`);
440
+ } else {
441
+ normalized.maxDuration = value.maxDuration;
442
+ }
443
+ }
444
+ return normalized;
445
+ }
446
+ __name(normalizeFarmRouteRuntimeConfig, "normalizeFarmRouteRuntimeConfig");
447
+ function getFarmRouteRuntimeConfig(value) {
448
+ if (!value || typeof value !== "object") return {};
449
+ const route = value;
450
+ return {
451
+ ...route.runtime !== void 0 ? { runtime: route.runtime } : {},
452
+ ...route.regions !== void 0 ? { regions: route.regions } : {},
453
+ ...route.maxDuration !== void 0 ? { maxDuration: route.maxDuration } : {}
454
+ };
455
+ }
456
+ __name(getFarmRouteRuntimeConfig, "getFarmRouteRuntimeConfig");
457
+
458
+ // src/routes.ts
459
+ var FARM_ROUTES_BRAND = /* @__PURE__ */ Symbol.for("farm.routes");
460
+ var PROGRAMMATIC_ROUTE_FILE_NAMES = [
461
+ "farm.route.ts",
462
+ "farm.route.tsx",
463
+ "farm.route.js",
464
+ "farm.route.jsx",
465
+ "farm.routes.ts",
466
+ "farm.routes.tsx",
467
+ "farm.routes.js",
468
+ "farm.routes.jsx",
469
+ "routes.ts",
470
+ "routes.tsx",
471
+ "routes.js",
472
+ "routes.jsx"
473
+ ];
474
+ function defineRoutes(input) {
475
+ const routes = typeof input === "function" ? input(routesBuilder) : input;
476
+ const manifest = {
477
+ __farmRoutes: true,
478
+ routes: routes.map(normalizeProgrammaticRoute)
479
+ };
480
+ Object.defineProperty(manifest, FARM_ROUTES_BRAND, {
481
+ value: true,
482
+ enumerable: false
483
+ });
484
+ return manifest;
485
+ }
486
+ __name(defineRoutes, "defineRoutes");
487
+ var routesBuilder = {
488
+ page(path3, options) {
489
+ return normalizeProgrammaticRoute({
490
+ kind: "page",
491
+ path: path3,
492
+ ...options
493
+ });
494
+ },
495
+ layout(path3, options) {
496
+ return normalizeProgrammaticRoute({
497
+ kind: "layout",
498
+ path: path3,
499
+ ...options
500
+ });
501
+ },
502
+ api(path3, options) {
503
+ const { render, runtime, regions, maxDuration, ...methods } = options;
504
+ return normalizeProgrammaticRoute({
505
+ kind: "api",
506
+ path: path3,
507
+ render,
508
+ runtime,
509
+ regions,
510
+ maxDuration,
511
+ methods: normalizeApiMethods(methods)
512
+ });
513
+ },
514
+ redirect(source, destination, options = {}) {
515
+ return normalizeProgrammaticRoute({
516
+ kind: "redirect",
517
+ source,
518
+ destination,
519
+ ...options
520
+ });
521
+ }
522
+ };
523
+ var page = routesBuilder.page;
524
+ var layout = routesBuilder.layout;
525
+ var api = routesBuilder.api;
526
+ var redirect = routesBuilder.redirect;
527
+ function getProgrammaticRouteManifest(mod) {
528
+ if (!mod) return null;
529
+ const candidates = [mod.default, mod.routes, mod.Route];
530
+ for (const candidate of candidates) {
531
+ if (isProgrammaticRouteManifest(candidate)) {
532
+ return candidate;
533
+ }
534
+ if (isProgrammaticRouteDefinition(candidate)) {
535
+ return defineRoutes([candidate]);
536
+ }
537
+ if (Array.isArray(candidate)) {
538
+ return defineRoutes(candidate);
539
+ }
540
+ }
541
+ const routeDefinitions = Object.values(mod).filter(isProgrammaticRouteDefinition);
542
+ if (routeDefinitions.length > 0) {
543
+ return defineRoutes(routeDefinitions);
544
+ }
545
+ return null;
546
+ }
547
+ __name(getProgrammaticRouteManifest, "getProgrammaticRouteManifest");
548
+ function isProgrammaticRouteManifest(value) {
549
+ return !!value && typeof value === "object" && value.__farmRoutes === true && Array.isArray(value.routes);
550
+ }
551
+ __name(isProgrammaticRouteManifest, "isProgrammaticRouteManifest");
552
+ function isProgrammaticRouteDefinition(value) {
553
+ if (!value || typeof value !== "object") {
554
+ return false;
555
+ }
556
+ const kind = value.kind;
557
+ return kind === "page" || kind === "layout" || kind === "api" || kind === "redirect";
558
+ }
559
+ __name(isProgrammaticRouteDefinition, "isProgrammaticRouteDefinition");
560
+ function createProgrammaticRouteModuleId(filePath, kind, routePath) {
561
+ return `${filePath}?farm-route=${kind}:${encodeURIComponent(normalizeRoutePath(routePath))}`;
562
+ }
563
+ __name(createProgrammaticRouteModuleId, "createProgrammaticRouteModuleId");
564
+ function normalizeProgrammaticRoute(route) {
565
+ if (route.kind === "redirect") {
566
+ return {
567
+ ...route,
568
+ source: normalizeRoutePath(route.source)
569
+ };
570
+ }
571
+ if (route.kind === "api") {
572
+ return {
573
+ ...route,
574
+ ...normalizeFarmRouteRuntimeConfig(route, `API route "${route.path}"`),
575
+ path: normalizeRoutePath(route.path),
576
+ methods: normalizeApiMethods(route.methods)
577
+ };
578
+ }
579
+ return {
580
+ ...route,
581
+ ...normalizeFarmRouteRuntimeConfig(
582
+ route,
583
+ `${route.kind === "layout" ? "Layout" : "Route"} "${route.path}"`
584
+ ),
585
+ path: normalizeRoutePath(route.path)
586
+ };
587
+ }
588
+ __name(normalizeProgrammaticRoute, "normalizeProgrammaticRoute");
589
+ function normalizeRoutePath(routePath) {
590
+ const withSlash = routePath.startsWith("/") ? routePath : `/${routePath}`;
591
+ const withoutTrailing = withSlash.length > 1 ? withSlash.replace(/\/+$/, "") : withSlash;
592
+ return withoutTrailing || "/";
593
+ }
594
+ __name(normalizeRoutePath, "normalizeRoutePath");
595
+ function normalizeApiMethods(methods) {
596
+ const normalized = {};
597
+ for (const [method, handler] of Object.entries(methods)) {
598
+ const normalizedMethod = method.toUpperCase();
599
+ if (handler && isProgrammaticRouteMethod(normalizedMethod)) {
600
+ normalized[normalizedMethod] = handler;
601
+ }
602
+ }
603
+ return normalized;
604
+ }
605
+ __name(normalizeApiMethods, "normalizeApiMethods");
606
+ function isProgrammaticRouteMethod(method) {
607
+ return method === "GET" || method === "HEAD" || method === "POST" || method === "PUT" || method === "DELETE" || method === "PATCH" || method === "OPTIONS";
608
+ }
609
+ __name(isProgrammaticRouteMethod, "isProgrammaticRouteMethod");
610
+
611
+ // src/routes.server.ts
612
+ var import_fs = require("fs");
613
+ var import_path = require("path");
614
+ function findProgrammaticRouteFilesInDir(srcRoot) {
615
+ const files = [];
616
+ for (const fileName of PROGRAMMATIC_ROUTE_FILE_NAMES) {
617
+ const filePath = (0, import_path.join)(srcRoot, fileName);
618
+ if ((0, import_fs.existsSync)(filePath)) {
619
+ files.push(filePath);
620
+ }
621
+ }
622
+ return files;
623
+ }
624
+ __name(findProgrammaticRouteFilesInDir, "findProgrammaticRouteFilesInDir");
625
+
626
+ // src/i18n/server.ts
627
+ var import_node_async_hooks = require("async_hooks");
628
+
629
+ // src/i18n/runtime.ts
630
+ var import_intl_messageformat = __toESM(require("intl-messageformat"));
631
+
632
+ // src/i18n/catalog.ts
633
+ var import_promises = require("fs/promises");
634
+ var import_icu_messageformat_parser = require("@formatjs/icu-messageformat-parser");
635
+
636
+ // src/i18n/config.ts
637
+ var import_node_path = __toESM(require("path"));
638
+ var DEFAULT_FARM_I18N_COOKIE_MAX_AGE = 60 * 60 * 24 * 365;
639
+
640
+ // src/i18n/server.ts
641
+ var FARM_I18N_REQUEST_STORE = /* @__PURE__ */ Symbol.for("farm.i18n.requestStore");
642
+ function getRequestStore() {
643
+ const state = globalThis;
644
+ return state[FARM_I18N_REQUEST_STORE] ?? (state[FARM_I18N_REQUEST_STORE] = new import_node_async_hooks.AsyncLocalStorage());
645
+ }
646
+ __name(getRequestStore, "getRequestStore");
647
+ function getState() {
648
+ const state = getRequestStore().getStore();
649
+ if (!state) {
650
+ throw new Error(
651
+ "No Farm i18n request context is active. Use this API while rendering, inside an API route, or use createTranslator(locale)."
652
+ );
653
+ }
654
+ return state;
655
+ }
656
+ __name(getState, "getState");
657
+ async function _runWithFarmI18nRequest(runtime, request, fn, options = {}) {
658
+ const resolution = runtime.resolveRequest(request, options);
659
+ const state = {
660
+ runtime,
661
+ resolution,
662
+ snapshot: runtime.getClientSnapshot(resolution)
663
+ };
664
+ return getRequestStore().run(state, () => fn(resolution));
665
+ }
666
+ __name(_runWithFarmI18nRequest, "_runWithFarmI18nRequest");
667
+ var t = createTranslatorFromState(() => getState());
668
+ function getFarmI18nClientSnapshot() {
669
+ return getRequestStore().getStore()?.snapshot;
670
+ }
671
+ __name(getFarmI18nClientSnapshot, "getFarmI18nClientSnapshot");
672
+ function createTranslatorFromState(resolveState) {
673
+ const translator = /* @__PURE__ */ __name(((key, values) => {
674
+ const state = resolveState();
675
+ return state.runtime.translate(state.resolution.locale, key, values);
676
+ }), "translator");
677
+ translator.rich = (key, values) => {
678
+ const state = resolveState();
679
+ return state.runtime.translateRich(state.resolution.locale, key, values);
680
+ };
681
+ translator.raw = (key) => {
682
+ const state = resolveState();
683
+ return state.runtime.getRawMessage(state.resolution.locale, key);
684
+ };
685
+ translator.has = (key) => {
686
+ const state = resolveState();
687
+ return state.runtime.hasMessage(state.resolution.locale, key);
688
+ };
689
+ return translator;
690
+ }
691
+ __name(createTranslatorFromState, "createTranslatorFromState");
692
+ _setFarmI18nSnapshotResolver(() => getFarmI18nClientSnapshot());
693
+
694
+ // src/server/request.ts
695
+ var import_node_async_hooks2 = require("async_hooks");
696
+
697
+ // src/server/request-bridge.ts
698
+ var CURRENT_REQUEST_RESOLVER_KEY = /* @__PURE__ */ Symbol.for("farm.currentRequestResolver");
699
+ function getGlobalState() {
700
+ return globalThis;
701
+ }
702
+ __name(getGlobalState, "getGlobalState");
703
+ function _setCurrentRequestResolver(resolver) {
704
+ getGlobalState()[CURRENT_REQUEST_RESOLVER_KEY] = resolver;
705
+ }
706
+ __name(_setCurrentRequestResolver, "_setCurrentRequestResolver");
707
+
708
+ // src/server/request.ts
709
+ var REQUEST_STORAGE_KEY = /* @__PURE__ */ Symbol.for("@farm.js/core/request-storage");
710
+ function getRequestStore2() {
711
+ const runtime = globalThis;
712
+ const existing = runtime[REQUEST_STORAGE_KEY];
713
+ if (existing instanceof import_node_async_hooks2.AsyncLocalStorage) {
714
+ return existing;
715
+ }
716
+ const storage = new import_node_async_hooks2.AsyncLocalStorage();
717
+ runtime[REQUEST_STORAGE_KEY] = storage;
718
+ return storage;
719
+ }
720
+ __name(getRequestStore2, "getRequestStore");
721
+ var requestStore = getRequestStore2();
722
+ _setCurrentRequestResolver(() => requestStore.getStore());
723
+ async function _runWithCurrentRequest(request, fn) {
724
+ return requestStore.run(request, fn);
725
+ }
726
+ __name(_runWithCurrentRequest, "_runWithCurrentRequest");
727
+
728
+ // src/api/runtime.ts
729
+ function matchAPIRoute(routes, pathname) {
730
+ const exactRoute = routes.get(pathname);
731
+ if (exactRoute) {
732
+ return { route: exactRoute, params: {} };
733
+ }
734
+ const normalizedPathname = normalizePathname(pathname);
735
+ if (normalizedPathname !== pathname) {
736
+ const normalizedRoute = routes.get(normalizedPathname);
737
+ if (normalizedRoute) {
738
+ return { route: normalizedRoute, params: {} };
739
+ }
740
+ }
741
+ for (const route of routes.values()) {
742
+ const params = matchRoutePath(route.path, pathname);
743
+ if (params) {
744
+ return { route, params };
745
+ }
746
+ }
747
+ return null;
748
+ }
749
+ __name(matchAPIRoute, "matchAPIRoute");
750
+ async function invokeAPIRouteEndpoint(endpoint, request, params = {}) {
751
+ return _runWithCurrentRequest(
752
+ request,
753
+ () => invokeAPIRouteEndpointInContext(endpoint, request, params)
754
+ );
755
+ }
756
+ __name(invokeAPIRouteEndpoint, "invokeAPIRouteEndpoint");
757
+ async function invokeAPIRouteEndpointInContext(endpoint, request, params) {
758
+ const farmHandler = endpoint.__handler || (isFarmContextHandler(endpoint) ? endpoint : null);
759
+ if (!farmHandler) {
760
+ const result2 = await endpoint(request, {
761
+ params: Promise.resolve(params)
762
+ });
763
+ return normalizeRouteResponse(result2);
764
+ }
765
+ const url = new URL(request.url);
766
+ const query = {};
767
+ url.searchParams.forEach((value, key) => {
768
+ query[key] = value;
769
+ });
770
+ let body = void 0;
771
+ if (request.method.toUpperCase() !== "GET" && request.method.toUpperCase() !== "HEAD") {
772
+ body = await readJSONBody(request);
773
+ }
774
+ const headers = Object.fromEntries(request.headers.entries());
775
+ const types = endpoint.__types || {};
776
+ const queryValidation = validateInput(types.query, query, "Invalid query parameters");
777
+ if (queryValidation instanceof Response) {
778
+ return queryValidation;
779
+ }
780
+ const bodyValidation = validateInput(types.body, body, "Invalid request body");
781
+ if (bodyValidation instanceof Response) {
782
+ return bodyValidation;
783
+ }
784
+ const headersValidation = validateInput(types.headers, headers, "Invalid request headers");
785
+ if (headersValidation instanceof Response) {
786
+ return headersValidation;
787
+ }
788
+ const result = await farmHandler({
789
+ query: queryValidation,
790
+ body: bodyValidation,
791
+ headers: headersValidation,
792
+ request,
793
+ context: {},
794
+ params
795
+ });
796
+ return normalizeRouteResponse(result);
797
+ }
798
+ __name(invokeAPIRouteEndpointInContext, "invokeAPIRouteEndpointInContext");
799
+ function normalizeRouteResponse(result) {
800
+ if (isWebResponse(result)) {
801
+ return result;
802
+ }
803
+ if (result === void 0) {
804
+ return new Response(null, { status: 204 });
805
+ }
806
+ return new Response(JSON.stringify(result), {
807
+ status: 200,
808
+ headers: { "Content-Type": "application/json" }
809
+ });
810
+ }
811
+ __name(normalizeRouteResponse, "normalizeRouteResponse");
812
+ function isWebResponse(value) {
813
+ return value instanceof Response || typeof value === "object" && value !== null && "headers" in value && "status" in value && typeof value.arrayBuffer === "function";
814
+ }
815
+ __name(isWebResponse, "isWebResponse");
816
+ function isFarmContextHandler(endpoint) {
817
+ if (typeof endpoint !== "function") {
818
+ return false;
819
+ }
820
+ const source = Function.prototype.toString.call(endpoint).trim();
821
+ const arrowMatch = source.match(/^(?:async\s*)?(?:\(([^)]*)\)|([A-Za-z_$][\w$]*))\s*=>/);
822
+ const functionMatch = source.match(/^(?:async\s*)?function[^(]*\(([^)]*)\)/);
823
+ const firstParameter = (arrowMatch?.[1] || arrowMatch?.[2] || functionMatch?.[1] || "").split(",")[0].trim();
824
+ return firstParameter === "ctx" || firstParameter === "context" || firstParameter.startsWith("{");
825
+ }
826
+ __name(isFarmContextHandler, "isFarmContextHandler");
827
+ async function readJSONBody(request) {
828
+ try {
829
+ const text = await request.clone().text();
830
+ if (text) {
831
+ return JSON.parse(text);
832
+ }
833
+ } catch {
834
+ }
835
+ return void 0;
836
+ }
837
+ __name(readJSONBody, "readJSONBody");
838
+ function validateInput(schema, value, error) {
839
+ if (!schema || typeof schema.parse !== "function") {
840
+ return value;
841
+ }
842
+ try {
843
+ return schema.parse(value);
844
+ } catch (validationError) {
845
+ return new Response(
846
+ JSON.stringify({
847
+ error,
848
+ details: validationError.errors || validationError.issues || validationError.message
849
+ }),
850
+ {
851
+ status: 400,
852
+ headers: { "Content-Type": "application/json" }
853
+ }
854
+ );
855
+ }
856
+ }
857
+ __name(validateInput, "validateInput");
858
+ function matchRoutePath(routePath, pathname) {
859
+ const routeSegments = getPathSegments(routePath);
860
+ const pathnameSegments = getPathSegments(pathname);
861
+ const params = {};
862
+ let pathIndex = 0;
863
+ for (const routeSegment of routeSegments) {
864
+ const dynamicSegment = parseDynamicSegment(routeSegment);
865
+ if (dynamicSegment?.catchAll) {
866
+ const remainingSegments = pathnameSegments.slice(pathIndex).map(decodePathSegment);
867
+ if (remainingSegments.length === 0 && !dynamicSegment.optional) {
868
+ return null;
869
+ }
870
+ if (remainingSegments.length > 0) {
871
+ params[dynamicSegment.name] = remainingSegments;
872
+ }
873
+ pathIndex = pathnameSegments.length;
874
+ continue;
875
+ }
876
+ const pathnameSegment = pathnameSegments[pathIndex];
877
+ if (pathnameSegment === void 0) {
878
+ return null;
879
+ }
880
+ if (dynamicSegment) {
881
+ params[dynamicSegment.name] = decodePathSegment(pathnameSegment);
882
+ pathIndex++;
883
+ continue;
884
+ }
885
+ if (routeSegment !== pathnameSegment) {
886
+ return null;
887
+ }
888
+ pathIndex++;
889
+ }
890
+ return pathIndex === pathnameSegments.length ? params : null;
891
+ }
892
+ __name(matchRoutePath, "matchRoutePath");
893
+ function getPathSegments(pathname) {
894
+ return normalizePathname(pathname).split("/").filter((segment) => segment.length > 0);
895
+ }
896
+ __name(getPathSegments, "getPathSegments");
897
+ function normalizePathname(pathname) {
898
+ if (pathname.length > 1 && pathname.endsWith("/")) {
899
+ return pathname.replace(/\/+$/, "");
900
+ }
901
+ return pathname;
902
+ }
903
+ __name(normalizePathname, "normalizePathname");
904
+ function parseDynamicSegment(segment) {
905
+ const optionalCatchAll = segment.match(/^\[\[\.\.\.(.+)\]\]$/);
906
+ if (optionalCatchAll?.[1]) {
907
+ return { name: optionalCatchAll[1], catchAll: true, optional: true };
908
+ }
909
+ const catchAll = segment.match(/^\[\.\.\.(.+)\]$/);
910
+ if (catchAll?.[1]) {
911
+ return { name: catchAll[1], catchAll: true, optional: false };
912
+ }
913
+ const dynamic = segment.match(/^\[(.+)\]$/);
914
+ if (dynamic?.[1]) {
915
+ return { name: dynamic[1], catchAll: false, optional: false };
916
+ }
917
+ return null;
918
+ }
919
+ __name(parseDynamicSegment, "parseDynamicSegment");
920
+ function decodePathSegment(segment) {
921
+ try {
922
+ return decodeURIComponent(segment);
923
+ } catch {
924
+ return segment;
925
+ }
926
+ }
927
+ __name(decodePathSegment, "decodePathSegment");
928
+
929
+ // src/api/route-manager.ts
930
+ var API_ROUTE_METHODS = [
931
+ "GET",
932
+ "HEAD",
933
+ "POST",
934
+ "PUT",
935
+ "DELETE",
936
+ "PATCH",
937
+ "OPTIONS"
938
+ ];
939
+ var _APIRouteManager = class _APIRouteManager {
940
+ constructor(appDir, viteServer, options = {}) {
941
+ this.routes = /* @__PURE__ */ new Map();
942
+ this.appDirs = Array.isArray(appDir) ? [...appDir] : [appDir];
943
+ this.viteServer = viteServer;
944
+ this.throwOnLoadError = options.throwOnLoadError === true;
945
+ this.i18n = options.i18n;
946
+ }
947
+ /**
948
+ * Discover route.ts files in /app/api and explicit endpoints in root routes.ts
949
+ */
950
+ async discoverRoutes() {
951
+ this.routes.clear();
952
+ for (const appDir of this.appDirs) {
953
+ const apiDir = path2.join(appDir, "api");
954
+ let routeFiles = [];
955
+ if (fs.existsSync(apiDir)) {
956
+ routeFiles = this.findRouteFiles(apiDir);
957
+ }
958
+ for (const filePath of routeFiles) {
959
+ await this.loadRoute(filePath, appDir);
960
+ }
961
+ await this.loadRootRoutes(appDir);
962
+ await this.loadProgrammaticApiRoutes(appDir);
963
+ }
964
+ if (process.env.FARM_VERBOSE) {
965
+ logger.success(`Discovered ${this.routes.size} API routes`);
966
+ for (const [routePath, route] of this.routes) {
967
+ logger.info(` ${route.methods.join(", ")} ${routePath}`);
968
+ }
969
+ }
970
+ }
971
+ /**
972
+ * Recursively find all route.ts files
973
+ */
974
+ findRouteFiles(dir) {
975
+ const files = [];
976
+ if (!fs.existsSync(dir)) {
977
+ return files;
978
+ }
979
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
980
+ for (const entry of entries) {
981
+ const fullPath = path2.join(dir, entry.name);
982
+ if (entry.isDirectory()) {
983
+ files.push(...this.findRouteFiles(fullPath));
984
+ } else if (entry.name === "route.ts" || entry.name === "route.tsx" || entry.name === "route.js") {
985
+ files.push(fullPath);
986
+ }
987
+ }
988
+ return files;
989
+ }
990
+ /**
991
+ * Load a route.ts file and extract HTTP method exports
992
+ */
993
+ async loadRoute(filePath, appDir) {
994
+ try {
995
+ const apiDir = path2.join(appDir, "api");
996
+ const relativePath = path2.relative(apiDir, path2.dirname(filePath));
997
+ const routePath = "/api/" + (relativePath === "." ? "" : relativePath.replace(/\\/g, "/"));
998
+ const routeModule = await this.loadModule(filePath);
999
+ const endpoints = {};
1000
+ const availableMethods = [];
1001
+ for (const method of API_ROUTE_METHODS) {
1002
+ if (routeModule[method]) {
1003
+ endpoints[method] = routeModule[method];
1004
+ availableMethods.push(method);
1005
+ }
1006
+ }
1007
+ if (availableMethods.length > 0) {
1008
+ const runtimeConfig = normalizeFarmRouteRuntimeConfig(
1009
+ getFarmRouteRuntimeConfig(routeModule),
1010
+ `API route "${routePath}"`
1011
+ );
1012
+ this.routes.set(routePath, {
1013
+ path: routePath,
1014
+ filePath,
1015
+ methods: availableMethods,
1016
+ endpoints,
1017
+ ...runtimeConfig
1018
+ });
1019
+ }
1020
+ } catch (error) {
1021
+ this.handleLoadError(`Error loading route ${filePath}`, error);
1022
+ }
1023
+ }
1024
+ /**
1025
+ * Load explicit-path endpoints from src/routes.ts-style files.
1026
+ */
1027
+ async loadRootRoutes(appDir) {
1028
+ const routesFile = this.findRootRoutesFile(appDir);
1029
+ if (!routesFile) {
1030
+ return;
1031
+ }
1032
+ try {
1033
+ const routesModule = await this.loadModule(routesFile);
1034
+ for (const exportValue of Object.values(routesModule)) {
1035
+ const endpoint = exportValue;
1036
+ if (!endpoint?.__path) {
1037
+ continue;
1038
+ }
1039
+ const method = String(endpoint.__method || "GET").toUpperCase();
1040
+ this.addEndpoint(endpoint.__path, routesFile, method, endpoint);
1041
+ }
1042
+ } catch (error) {
1043
+ this.handleLoadError(`Error loading root API routes ${routesFile}`, error);
1044
+ }
1045
+ }
1046
+ async loadProgrammaticApiRoutes(appDir) {
1047
+ const candidateRoots = [path2.dirname(appDir), appDir];
1048
+ const routeFiles = Array.from(
1049
+ new Set(candidateRoots.flatMap((srcRoot) => findProgrammaticRouteFilesInDir(srcRoot)))
1050
+ );
1051
+ for (const routeFile of routeFiles) {
1052
+ try {
1053
+ const routesModule = await this.loadModule(routeFile);
1054
+ const manifest = getProgrammaticRouteManifest(routesModule);
1055
+ if (!manifest) continue;
1056
+ for (const definition of manifest.routes) {
1057
+ if (definition.kind !== "api") continue;
1058
+ this.addProgrammaticApiRoute(routeFile, definition);
1059
+ }
1060
+ } catch (error) {
1061
+ this.handleLoadError(`Error loading programmatic API routes ${routeFile}`, error);
1062
+ }
1063
+ }
1064
+ }
1065
+ handleLoadError(message, error) {
1066
+ logger.error(`${message}: ${error}`);
1067
+ if (this.throwOnLoadError) {
1068
+ throw error;
1069
+ }
1070
+ }
1071
+ findRootRoutesFile(appDir) {
1072
+ const routeNames = ["routes.ts", "routes.tsx", "routes.js"];
1073
+ const candidateDirs = [path2.dirname(appDir), appDir];
1074
+ const seen = /* @__PURE__ */ new Set();
1075
+ for (const dir of candidateDirs) {
1076
+ for (const routeName of routeNames) {
1077
+ const routesFile = path2.join(dir, routeName);
1078
+ if (seen.has(routesFile)) {
1079
+ continue;
1080
+ }
1081
+ seen.add(routesFile);
1082
+ if (fs.existsSync(routesFile)) {
1083
+ return routesFile;
1084
+ }
1085
+ }
1086
+ }
1087
+ return null;
1088
+ }
1089
+ async loadModule(filePath) {
1090
+ if (this.viteServer) {
1091
+ return await this.viteServer.ssrLoadModule(filePath);
1092
+ }
1093
+ const fileUrl = `file://${filePath}`;
1094
+ return await import(
1095
+ /* @vite-ignore */
1096
+ fileUrl
1097
+ );
1098
+ }
1099
+ addEndpoint(routePath, filePath, method, endpoint, runtimeConfig = {}) {
1100
+ const normalizedMethod = method.toUpperCase();
1101
+ const existingRoute = this.routes.get(routePath);
1102
+ if (existingRoute) {
1103
+ if (!existingRoute.methods.includes(normalizedMethod)) {
1104
+ existingRoute.methods.push(normalizedMethod);
1105
+ }
1106
+ existingRoute.endpoints[normalizedMethod] = endpoint;
1107
+ Object.assign(existingRoute, runtimeConfig);
1108
+ return;
1109
+ }
1110
+ this.routes.set(routePath, {
1111
+ path: routePath,
1112
+ filePath,
1113
+ methods: [normalizedMethod],
1114
+ endpoints: { [normalizedMethod]: endpoint },
1115
+ ...runtimeConfig
1116
+ });
1117
+ }
1118
+ addProgrammaticApiRoute(filePath, route) {
1119
+ const modulePath = createProgrammaticRouteModuleId(filePath, "api", route.path);
1120
+ const runtimeConfig = normalizeFarmRouteRuntimeConfig(route, `API route "${route.path}"`);
1121
+ for (const [method, endpoint] of Object.entries(route.methods)) {
1122
+ if (endpoint) {
1123
+ this.addEndpoint(route.path, modulePath, method, endpoint, runtimeConfig);
1124
+ }
1125
+ }
1126
+ }
1127
+ /**
1128
+ * Get the handler that directly invokes endpoint handlers
1129
+ */
1130
+ getHandler() {
1131
+ if (this.routes.size === 0) {
1132
+ return null;
1133
+ }
1134
+ return async (request) => {
1135
+ const url = new URL(request.url);
1136
+ const pathname = url.pathname;
1137
+ const method = request.method.toUpperCase();
1138
+ const match = matchAPIRoute(this.routes, pathname);
1139
+ if (!match) {
1140
+ return new Response(JSON.stringify({ error: "Not Found" }), {
1141
+ status: 404,
1142
+ headers: { "Content-Type": "application/json" }
1143
+ });
1144
+ }
1145
+ const { route, params } = match;
1146
+ const endpoint = route.endpoints[method];
1147
+ if (!endpoint) {
1148
+ return new Response(JSON.stringify({ error: "Method Not Allowed" }), {
1149
+ status: 405,
1150
+ headers: { "Content-Type": "application/json" }
1151
+ });
1152
+ }
1153
+ const invoke = /* @__PURE__ */ __name(async () => {
1154
+ try {
1155
+ return await invokeAPIRouteEndpoint(endpoint, request, params);
1156
+ } catch (error) {
1157
+ console.error(`[API Error] ${pathname}:`, error);
1158
+ return new Response(JSON.stringify({ error: "Internal Server Error" }), {
1159
+ status: 500,
1160
+ headers: { "Content-Type": "application/json" }
1161
+ });
1162
+ }
1163
+ }, "invoke");
1164
+ return this.i18n?.config.enabled ? _runWithFarmI18nRequest(this.i18n, request, invoke, {
1165
+ redirect: false
1166
+ }) : invoke();
1167
+ };
1168
+ }
1169
+ /**
1170
+ * Check if a path is an API route
1171
+ */
1172
+ isAPIRoute(pathname) {
1173
+ return Boolean(this.matchRoute(pathname));
1174
+ }
1175
+ matchRoute(pathname) {
1176
+ return matchAPIRoute(this.routes, pathname);
1177
+ }
1178
+ /**
1179
+ * Get all routes for client type generation
1180
+ */
1181
+ getRoutes() {
1182
+ return this.routes;
1183
+ }
1184
+ };
1185
+ __name(_APIRouteManager, "APIRouteManager");
1186
+ var APIRouteManager = _APIRouteManager;
1187
+ // Annotate the CommonJS export names for ESM import in node:
1188
+ 0 && (module.exports = {
1189
+ APIRouteManager,
1190
+ API_ROUTE_METHODS,
1191
+ invokeAPIRouteEndpoint,
1192
+ isWebResponse,
1193
+ matchAPIRoute,
1194
+ normalizeRouteResponse
1195
+ });
1196
+ //# sourceMappingURL=route-manager.cjs.map