@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,1896 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/nitro/production-runtime.ts
22
+ var production_runtime_exports = {};
23
+ __export(production_runtime_exports, {
24
+ _runWithAfterRequest: () => _runWithAfterRequest,
25
+ _runWithCurrentRequest: () => _runWithCurrentRequest,
26
+ _runWithMiddlewareContext: () => _runWithMiddlewareContext,
27
+ _runWithMiddlewareData: () => _runWithMiddlewareData,
28
+ addMetadataImageReference: () => addMetadataImageReference,
29
+ applyProductionMiddlewareHeaders: () => applyProductionMiddlewareHeaders,
30
+ configureFarmObservability: () => configureFarmObservability,
31
+ createFarmCacheKey: () => createFarmCacheKey,
32
+ createFarmLocaleCookie: () => createFarmLocaleCookie,
33
+ createProductionMiddlewareRunner: () => createProductionMiddlewareRunner,
34
+ emitFarmEvent: () => emitFarmEvent,
35
+ getCurrentRequest: () => getCurrentRequest,
36
+ getFarmDataCache: () => getFarmDataCache,
37
+ getFarmLocaleVaryHeaders: () => getFarmLocaleVaryHeaders,
38
+ getFarmRedirectError: () => getFarmRedirectError,
39
+ isFarmNotFoundError: () => isFarmNotFoundError,
40
+ isFarmRedirectError: () => isFarmRedirectError,
41
+ localizeFarmHref: () => localizeFarmHref,
42
+ localizeFarmPathname: () => localizeFarmPathname,
43
+ mergeMetadata: () => mergeMetadata,
44
+ normalizeRevalidatePath: () => normalizeRevalidatePath,
45
+ renderMetadataHead: () => renderMetadataHead,
46
+ resolveFarmRouteContext: () => resolveFarmRouteContext,
47
+ stripFarmLocaleFromPathname: () => stripFarmLocaleFromPathname,
48
+ withFarmRouteContext: () => withFarmRouteContext
49
+ });
50
+ module.exports = __toCommonJS(production_runtime_exports);
51
+
52
+ // src/after.ts
53
+ var import_node_async_hooks = require("async_hooks");
54
+ var AFTER_STORAGE = /* @__PURE__ */ Symbol.for("@farm.js/core/after-storage");
55
+ function getAfterStorage() {
56
+ const runtime = globalThis;
57
+ const existing = runtime[AFTER_STORAGE];
58
+ if (existing instanceof import_node_async_hooks.AsyncLocalStorage) {
59
+ return existing;
60
+ }
61
+ const storage = new import_node_async_hooks.AsyncLocalStorage();
62
+ runtime[AFTER_STORAGE] = storage;
63
+ return storage;
64
+ }
65
+ __name(getAfterStorage, "getAfterStorage");
66
+ var afterStorage = getAfterStorage();
67
+ function defaultAfterErrorReporter(error) {
68
+ console.error("[Farm.js] after() callback failed:", error);
69
+ }
70
+ __name(defaultAfterErrorReporter, "defaultAfterErrorReporter");
71
+ function reportAfterError(state, error) {
72
+ try {
73
+ state.reportError(error);
74
+ } catch {
75
+ }
76
+ }
77
+ __name(reportAfterError, "reportAfterError");
78
+ function createAfterRequestState(reportError = defaultAfterErrorReporter) {
79
+ let resolveResponseFinished;
80
+ let responseFinished = false;
81
+ const responseFinishedPromise = new Promise((resolve) => {
82
+ resolveResponseFinished = resolve;
83
+ });
84
+ const state = {
85
+ completion: Promise.resolve(),
86
+ finishResponse: /* @__PURE__ */ __name(() => {
87
+ if (responseFinished) return;
88
+ responseFinished = true;
89
+ resolveResponseFinished();
90
+ }, "finishResponse"),
91
+ phase: "open",
92
+ reportError,
93
+ tasks: []
94
+ };
95
+ state.completion = responseFinishedPromise.then(
96
+ () => afterStorage.run(state, async () => {
97
+ state.phase = "running";
98
+ for (let index = 0; index < state.tasks.length; index++) {
99
+ const task = state.tasks[index];
100
+ task.start();
101
+ try {
102
+ await task.result;
103
+ } catch (error) {
104
+ reportAfterError(state, error);
105
+ }
106
+ }
107
+ state.phase = "closed";
108
+ })
109
+ );
110
+ return state;
111
+ }
112
+ __name(createAfterRequestState, "createAfterRequestState");
113
+ function registerPlatformLifetime(state, context) {
114
+ if (!context?.waitUntil) return;
115
+ try {
116
+ context.waitUntil(state.completion);
117
+ } catch (error) {
118
+ reportAfterError(state, error);
119
+ }
120
+ }
121
+ __name(registerPlatformLifetime, "registerPlatformLifetime");
122
+ function registerResponseFinishedHook(state, context) {
123
+ if (!context?.onResponseFinished) return false;
124
+ try {
125
+ context.onResponseFinished(state.finishResponse);
126
+ return true;
127
+ } catch (error) {
128
+ reportAfterError(state, error);
129
+ return false;
130
+ }
131
+ }
132
+ __name(registerResponseFinishedHook, "registerResponseFinishedHook");
133
+ function finishSoon(state) {
134
+ setTimeout(state.finishResponse, 0);
135
+ }
136
+ __name(finishSoon, "finishSoon");
137
+ function wrapResponseBody(response, request, state) {
138
+ if (request.method === "HEAD" || response.status < 200 || response.status > 599 || !response.body || response.bodyUsed || response.body.locked) {
139
+ finishSoon(state);
140
+ return response;
141
+ }
142
+ const reader = response.body.getReader();
143
+ let released = false;
144
+ const releaseReader = /* @__PURE__ */ __name(() => {
145
+ if (released) return;
146
+ released = true;
147
+ reader.releaseLock();
148
+ }, "releaseReader");
149
+ const body = new ReadableStream({
150
+ async pull(controller) {
151
+ try {
152
+ const chunk = await reader.read();
153
+ if (chunk.done) {
154
+ releaseReader();
155
+ controller.close();
156
+ finishSoon(state);
157
+ return;
158
+ }
159
+ controller.enqueue(chunk.value);
160
+ } catch (error) {
161
+ releaseReader();
162
+ controller.error(error);
163
+ finishSoon(state);
164
+ }
165
+ },
166
+ async cancel(reason) {
167
+ try {
168
+ await reader.cancel(reason);
169
+ } finally {
170
+ releaseReader();
171
+ finishSoon(state);
172
+ }
173
+ }
174
+ });
175
+ return new Response(body, {
176
+ headers: response.headers,
177
+ status: response.status,
178
+ statusText: response.statusText
179
+ });
180
+ }
181
+ __name(wrapResponseBody, "wrapResponseBody");
182
+ async function _runWithAfterRequest(request, handler, context) {
183
+ if (afterStorage.getStore()) {
184
+ return await handler();
185
+ }
186
+ const state = createAfterRequestState();
187
+ registerPlatformLifetime(state, context);
188
+ const hasResponseHook = registerResponseFinishedHook(state, context);
189
+ try {
190
+ const response = await afterStorage.run(state, handler);
191
+ return hasResponseHook ? response : wrapResponseBody(response, request, state);
192
+ } catch (error) {
193
+ if (!hasResponseHook) finishSoon(state);
194
+ throw error;
195
+ }
196
+ }
197
+ __name(_runWithAfterRequest, "_runWithAfterRequest");
198
+
199
+ // src/server/request.ts
200
+ var import_node_async_hooks2 = require("async_hooks");
201
+
202
+ // src/server/request-bridge.ts
203
+ var CURRENT_REQUEST_RESOLVER_KEY = /* @__PURE__ */ Symbol.for("farm.currentRequestResolver");
204
+ function getGlobalState() {
205
+ return globalThis;
206
+ }
207
+ __name(getGlobalState, "getGlobalState");
208
+ function _setCurrentRequestResolver(resolver) {
209
+ getGlobalState()[CURRENT_REQUEST_RESOLVER_KEY] = resolver;
210
+ }
211
+ __name(_setCurrentRequestResolver, "_setCurrentRequestResolver");
212
+
213
+ // src/server/request.ts
214
+ var REQUEST_STORAGE_KEY = /* @__PURE__ */ Symbol.for("@farm.js/core/request-storage");
215
+ function getRequestStore() {
216
+ const runtime = globalThis;
217
+ const existing = runtime[REQUEST_STORAGE_KEY];
218
+ if (existing instanceof import_node_async_hooks2.AsyncLocalStorage) {
219
+ return existing;
220
+ }
221
+ const storage = new import_node_async_hooks2.AsyncLocalStorage();
222
+ runtime[REQUEST_STORAGE_KEY] = storage;
223
+ return storage;
224
+ }
225
+ __name(getRequestStore, "getRequestStore");
226
+ var requestStore = getRequestStore();
227
+ _setCurrentRequestResolver(() => requestStore.getStore());
228
+ function createWebRequestFromFarmRequest(req) {
229
+ const forwardedHost = req.headers["x-forwarded-host"];
230
+ const host = Array.isArray(forwardedHost) ? forwardedHost[0] : forwardedHost || req.headers.host || "localhost";
231
+ const forwardedProto = req.headers["x-forwarded-proto"];
232
+ const proto = Array.isArray(forwardedProto) ? forwardedProto[0] : forwardedProto || "http";
233
+ const fullUrl = new URL(req.url || "/", `${proto}://${host}`).toString();
234
+ const headers = new Headers();
235
+ for (const [key, value] of Object.entries(req.headers)) {
236
+ if (value == null) {
237
+ continue;
238
+ }
239
+ if (Array.isArray(value)) {
240
+ for (const item of value) {
241
+ headers.append(key, item);
242
+ }
243
+ continue;
244
+ }
245
+ headers.set(key, value);
246
+ }
247
+ return new Request(fullUrl, {
248
+ method: req.method,
249
+ headers
250
+ });
251
+ }
252
+ __name(createWebRequestFromFarmRequest, "createWebRequestFromFarmRequest");
253
+ async function _runWithCurrentRequest(request, fn) {
254
+ return requestStore.run(request, fn);
255
+ }
256
+ __name(_runWithCurrentRequest, "_runWithCurrentRequest");
257
+ function getCurrentRequest() {
258
+ const request = requestStore.getStore();
259
+ if (!request) {
260
+ throw new Error(
261
+ "No current request is available. getCurrentRequest() can only be used during server rendering."
262
+ );
263
+ }
264
+ return request;
265
+ }
266
+ __name(getCurrentRequest, "getCurrentRequest");
267
+
268
+ // src/observability.ts
269
+ var runtimeHandlers = /* @__PURE__ */ new Set();
270
+ var observabilityState = {
271
+ logs: false,
272
+ handlers: []
273
+ };
274
+ function configureFarmObservability(config) {
275
+ observabilityState = normalizeFarmObservabilityConfig(config);
276
+ }
277
+ __name(configureFarmObservability, "configureFarmObservability");
278
+ function normalizeFarmObservabilityConfig(config) {
279
+ if (config === void 0 || config === false) {
280
+ return { logs: false, handlers: [] };
281
+ }
282
+ if (config === true) {
283
+ return { logs: true, handlers: [] };
284
+ }
285
+ const handlers = config.onEvent ? Array.isArray(config.onEvent) ? [...config.onEvent] : [config.onEvent] : [];
286
+ return {
287
+ logs: config.logs ?? false,
288
+ handlers,
289
+ events: config.events ? new Set(config.events) : void 0
290
+ };
291
+ }
292
+ __name(normalizeFarmObservabilityConfig, "normalizeFarmObservabilityConfig");
293
+ function emitFarmEvent(input) {
294
+ const event = {
295
+ timestamp: Date.now(),
296
+ level: inferFarmEventLevel(input.type),
297
+ ...input
298
+ };
299
+ if (!shouldEmitFarmEvent(event)) {
300
+ return event;
301
+ }
302
+ if (observabilityState.logs) {
303
+ logFarmEvent(event);
304
+ }
305
+ for (const handler of [...observabilityState.handlers, ...runtimeHandlers]) {
306
+ try {
307
+ Promise.resolve(handler(event)).catch((error) => {
308
+ console.warn(`[farm:observability] event handler failed: ${formatError(error)}`);
309
+ });
310
+ } catch (error) {
311
+ console.warn(`[farm:observability] event handler failed: ${formatError(error)}`);
312
+ }
313
+ }
314
+ return event;
315
+ }
316
+ __name(emitFarmEvent, "emitFarmEvent");
317
+ function shouldEmitFarmEvent(event) {
318
+ if (!observabilityState.logs && observabilityState.handlers.length === 0 && runtimeHandlers.size === 0) {
319
+ return false;
320
+ }
321
+ if (observabilityState.events && !observabilityState.events.has(event.type)) {
322
+ return false;
323
+ }
324
+ return true;
325
+ }
326
+ __name(shouldEmitFarmEvent, "shouldEmitFarmEvent");
327
+ function inferFarmEventLevel(type) {
328
+ if (type === "error" || type.endsWith(".error") || type.endsWith(".failed")) {
329
+ return "error";
330
+ }
331
+ if (type.endsWith(".bypass") || type.endsWith(".invalidated") || type.endsWith(".stale") || type.endsWith(".notFound")) {
332
+ return "warn";
333
+ }
334
+ if (type.endsWith(".hit") || type.endsWith(".miss") || type.endsWith(".start") || type.endsWith(".shellReady")) {
335
+ return "debug";
336
+ }
337
+ return "info";
338
+ }
339
+ __name(inferFarmEventLevel, "inferFarmEventLevel");
340
+ function logFarmEvent(event) {
341
+ const message = `[farm:${event.level}] ${event.type}${formatFarmEventDetails(event)}`;
342
+ switch (event.level) {
343
+ case "error":
344
+ console.error(message);
345
+ break;
346
+ case "warn":
347
+ console.warn(message);
348
+ break;
349
+ default:
350
+ console.log(message);
351
+ break;
352
+ }
353
+ }
354
+ __name(logFarmEvent, "logFarmEvent");
355
+ function formatFarmEventDetails(event) {
356
+ const details = [];
357
+ const record = event;
358
+ for (const key of [
359
+ "route",
360
+ "pathname",
361
+ "method",
362
+ "status",
363
+ "key",
364
+ "tag",
365
+ "path",
366
+ "reason",
367
+ "durationMs",
368
+ "integration",
369
+ "operation",
370
+ "plugin",
371
+ "hook",
372
+ "target",
373
+ "count"
374
+ ]) {
375
+ const value = record[key];
376
+ if (value !== void 0) {
377
+ details.push(`${key}=${formatDetailValue(value)}`);
378
+ }
379
+ }
380
+ return details.length > 0 ? ` ${details.join(" ")}` : "";
381
+ }
382
+ __name(formatFarmEventDetails, "formatFarmEventDetails");
383
+ function formatDetailValue(value) {
384
+ if (typeof value === "string") {
385
+ return value;
386
+ }
387
+ if (typeof value === "number" || typeof value === "boolean") {
388
+ return String(value);
389
+ }
390
+ try {
391
+ return JSON.stringify(value);
392
+ } catch {
393
+ return String(value);
394
+ }
395
+ }
396
+ __name(formatDetailValue, "formatDetailValue");
397
+ function formatError(error) {
398
+ return error instanceof Error ? error.message : String(error);
399
+ }
400
+ __name(formatError, "formatError");
401
+
402
+ // src/cache.ts
403
+ var _FarmDataCache = class _FarmDataCache {
404
+ constructor() {
405
+ this.entries = /* @__PURE__ */ new Map();
406
+ this.inflight = /* @__PURE__ */ new Map();
407
+ this.invalidatedTagVersions = /* @__PURE__ */ new Map();
408
+ this.version = 0;
409
+ }
410
+ get size() {
411
+ return this.entries.size;
412
+ }
413
+ get(key, options = {}) {
414
+ return this.getEntry(key, options)?.value;
415
+ }
416
+ getEntry(key, options = {}) {
417
+ const entry = this.entries.get(key);
418
+ if (!entry) {
419
+ emitFarmEvent({ type: "cache.miss", key });
420
+ return void 0;
421
+ }
422
+ const stale = this.isStale(entry, options.now);
423
+ if (stale) {
424
+ emitFarmEvent({
425
+ type: "cache.stale",
426
+ key,
427
+ tags: Array.from(entry.tags),
428
+ revalidate: entry.revalidate
429
+ });
430
+ }
431
+ if (!options.allowStale && stale) {
432
+ emitFarmEvent({ type: "cache.miss", key, reason: "stale" });
433
+ return void 0;
434
+ }
435
+ emitFarmEvent({
436
+ type: "cache.hit",
437
+ key,
438
+ tags: Array.from(entry.tags),
439
+ revalidate: entry.revalidate,
440
+ stale
441
+ });
442
+ return this.toPublicEntry(entry);
443
+ }
444
+ set(key, value, options = {}) {
445
+ const tags = /* @__PURE__ */ new Set();
446
+ for (const tag of options.tags ?? []) {
447
+ tags.add(normalizeCacheTag(tag));
448
+ }
449
+ for (const routePath of options.paths ?? []) {
450
+ tags.add(createPathCacheTag(routePath));
451
+ }
452
+ const entry = {
453
+ key,
454
+ value,
455
+ tags,
456
+ createdAt: options.createdAt ?? Date.now(),
457
+ createdVersion: ++this.version,
458
+ revalidate: normalizeRevalidate(options.revalidate)
459
+ };
460
+ this.entries.set(key, entry);
461
+ emitFarmEvent({
462
+ type: "cache.set",
463
+ key,
464
+ tags: Array.from(tags),
465
+ revalidate: entry.revalidate
466
+ });
467
+ return this.toPublicEntry(entry);
468
+ }
469
+ delete(key) {
470
+ const deleted = this.entries.delete(key);
471
+ emitFarmEvent({ type: "cache.delete", key, deleted });
472
+ return deleted;
473
+ }
474
+ clear() {
475
+ const count = this.entries.size;
476
+ this.entries.clear();
477
+ this.inflight.clear();
478
+ this.invalidatedTagVersions.clear();
479
+ this.version = 0;
480
+ emitFarmEvent({ type: "cache.clear", count });
481
+ }
482
+ isStale(entry, now = Date.now()) {
483
+ if (typeof entry.revalidate === "number" && entry.revalidate > 0 && now - entry.createdAt >= entry.revalidate * 1e3) {
484
+ return true;
485
+ }
486
+ for (const tag of entry.tags) {
487
+ const invalidatedVersion = this.invalidatedTagVersions.get(normalizeCacheTag(tag));
488
+ if (typeof invalidatedVersion === "number" && typeof entry.createdVersion === "number" && invalidatedVersion > entry.createdVersion) {
489
+ return true;
490
+ }
491
+ }
492
+ return false;
493
+ }
494
+ revalidateTag(tag, options = {}) {
495
+ const normalized = normalizeCacheTag(tag);
496
+ const count = this.invalidateTag(normalized);
497
+ emitFarmEvent(
498
+ options.source === "updateTag" ? { type: "cache.updateTag", tag: normalized, count } : { type: "cache.revalidateTag", tag: normalized, profile: options.profile, count }
499
+ );
500
+ return count;
501
+ }
502
+ revalidatePath(routePath) {
503
+ const normalizedPath = normalizeRevalidatePath(routePath);
504
+ const pathTag = createPathCacheTag(normalizedPath);
505
+ const pprCount = this.countEntriesForTags([pathTag, "ppr"]);
506
+ const count = this.invalidateTag(pathTag);
507
+ emitFarmEvent({ type: "cache.revalidatePath", path: normalizedPath, count });
508
+ if (pprCount > 0) {
509
+ emitFarmEvent({
510
+ type: "ppr.shell.invalidated",
511
+ route: normalizedPath,
512
+ reason: "revalidatePath",
513
+ count: pprCount
514
+ });
515
+ }
516
+ return count;
517
+ }
518
+ async getOrSet(key, producer, options = {}) {
519
+ const cached = this.getEntry(key);
520
+ if (cached) {
521
+ return cached.value;
522
+ }
523
+ const inflight = this.inflight.get(key);
524
+ if (inflight) {
525
+ emitFarmEvent({ type: "cache.dedupe", key });
526
+ return inflight;
527
+ }
528
+ const promise = Promise.resolve().then(producer).then((value) => {
529
+ this.set(key, value, options);
530
+ return value;
531
+ }).catch((error) => {
532
+ emitFarmEvent({ type: "cache.error", key, operation: "set", error });
533
+ throw error;
534
+ }).finally(() => {
535
+ this.inflight.delete(key);
536
+ });
537
+ this.inflight.set(key, promise);
538
+ return promise;
539
+ }
540
+ countEntriesForTag(tag) {
541
+ let count = 0;
542
+ for (const entry of this.entries.values()) {
543
+ if (entry.tags.has(tag)) {
544
+ count++;
545
+ }
546
+ }
547
+ return count;
548
+ }
549
+ countEntriesForTags(tags) {
550
+ let count = 0;
551
+ for (const entry of this.entries.values()) {
552
+ if (tags.every((tag) => entry.tags.has(tag))) {
553
+ count++;
554
+ }
555
+ }
556
+ return count;
557
+ }
558
+ invalidateTag(normalizedTag) {
559
+ this.invalidatedTagVersions.set(normalizedTag, ++this.version);
560
+ return this.countEntriesForTag(normalizedTag);
561
+ }
562
+ toPublicEntry(entry) {
563
+ return {
564
+ key: entry.key,
565
+ value: entry.value,
566
+ tags: Array.from(entry.tags),
567
+ createdAt: entry.createdAt,
568
+ createdVersion: entry.createdVersion,
569
+ revalidate: entry.revalidate
570
+ };
571
+ }
572
+ };
573
+ __name(_FarmDataCache, "FarmDataCache");
574
+ var FarmDataCache = _FarmDataCache;
575
+ var FARM_DATA_CACHE_SYMBOL = /* @__PURE__ */ Symbol.for("farm.dataCache");
576
+ var farmDataCacheGlobal = globalThis;
577
+ var sharedFarmDataCache = farmDataCacheGlobal[FARM_DATA_CACHE_SYMBOL] ?? (farmDataCacheGlobal[FARM_DATA_CACHE_SYMBOL] = new FarmDataCache());
578
+ var functionIds = /* @__PURE__ */ new WeakMap();
579
+ var nextFunctionId = 0;
580
+ function getFarmDataCache() {
581
+ return sharedFarmDataCache;
582
+ }
583
+ __name(getFarmDataCache, "getFarmDataCache");
584
+ function createPathCacheTag(routePath) {
585
+ return `path:${normalizeRevalidatePath(routePath)}`;
586
+ }
587
+ __name(createPathCacheTag, "createPathCacheTag");
588
+ function normalizeRevalidatePath(routePath) {
589
+ if (typeof routePath !== "string") {
590
+ throw new TypeError("revalidatePath expects a path string.");
591
+ }
592
+ let normalized = routePath.trim();
593
+ if (!normalized) {
594
+ throw new Error("revalidatePath expects a non-empty path.");
595
+ }
596
+ try {
597
+ if (/^https?:\/\//.test(normalized)) {
598
+ normalized = new URL(normalized).pathname;
599
+ }
600
+ } catch {
601
+ }
602
+ normalized = normalized.split("?")[0] ?? normalized;
603
+ normalized = normalized.startsWith("/") ? normalized : `/${normalized}`;
604
+ normalized = normalized.replace(/\/{2,}/g, "/");
605
+ if (normalized.length > 1) {
606
+ normalized = normalized.replace(/\/+$/, "");
607
+ }
608
+ return normalized || "/";
609
+ }
610
+ __name(normalizeRevalidatePath, "normalizeRevalidatePath");
611
+ function createFarmCacheKey(parts) {
612
+ return stableSerialize(parts);
613
+ }
614
+ __name(createFarmCacheKey, "createFarmCacheKey");
615
+ function normalizeRevalidate(revalidate) {
616
+ if (revalidate === false || revalidate === void 0) {
617
+ return revalidate;
618
+ }
619
+ if (!Number.isFinite(revalidate) || revalidate <= 0) {
620
+ return void 0;
621
+ }
622
+ return revalidate;
623
+ }
624
+ __name(normalizeRevalidate, "normalizeRevalidate");
625
+ function normalizeCacheTag(tag) {
626
+ if (typeof tag !== "string") {
627
+ throw new TypeError("Cache tags must be strings.");
628
+ }
629
+ const normalized = tag.trim();
630
+ if (!normalized) {
631
+ throw new Error("Cache tags cannot be empty.");
632
+ }
633
+ return normalized;
634
+ }
635
+ __name(normalizeCacheTag, "normalizeCacheTag");
636
+ function getFunctionCacheIdentity(fn) {
637
+ if (fn.name) {
638
+ return `name:${fn.name}`;
639
+ }
640
+ let id = functionIds.get(fn);
641
+ if (!id) {
642
+ id = ++nextFunctionId;
643
+ functionIds.set(fn, id);
644
+ }
645
+ return `anonymous:${id}`;
646
+ }
647
+ __name(getFunctionCacheIdentity, "getFunctionCacheIdentity");
648
+ function stableSerialize(value, seen = /* @__PURE__ */ new WeakSet()) {
649
+ if (value === null) return "null";
650
+ if (value === void 0) return "undefined";
651
+ const valueType = typeof value;
652
+ if (valueType === "string") return JSON.stringify(value);
653
+ if (valueType === "number" || valueType === "boolean" || valueType === "bigint") {
654
+ return `${valueType}:${String(value)}`;
655
+ }
656
+ if (valueType === "symbol") {
657
+ return `symbol:${String(value)}`;
658
+ }
659
+ if (valueType === "function") {
660
+ return `function:${getFunctionCacheIdentity(value)}`;
661
+ }
662
+ if (value instanceof Date) {
663
+ return `date:${value.toISOString()}`;
664
+ }
665
+ if (value instanceof URL) {
666
+ return `url:${value.toString()}`;
667
+ }
668
+ if (value instanceof RegExp) {
669
+ return `regexp:${value.toString()}`;
670
+ }
671
+ if (Array.isArray(value)) {
672
+ return `[${value.map((item) => stableSerialize(item, seen)).join(",")}]`;
673
+ }
674
+ if (value && typeof value === "object") {
675
+ if (seen.has(value)) {
676
+ return "[Circular]";
677
+ }
678
+ seen.add(value);
679
+ const entries = Object.entries(value).sort(
680
+ ([a], [b]) => a.localeCompare(b)
681
+ );
682
+ const serialized = entries.map(([key, item]) => `${JSON.stringify(key)}:${stableSerialize(item, seen)}`).join(",");
683
+ seen.delete(value);
684
+ return `{${serialized}}`;
685
+ }
686
+ return String(value);
687
+ }
688
+ __name(stableSerialize, "stableSerialize");
689
+
690
+ // src/i18n/routing.ts
691
+ function resolveFarmLocalePath(pathname, config) {
692
+ const normalized = normalizePathname(pathname);
693
+ if (config.routing === "none") {
694
+ return { pathname: normalized, explicit: false };
695
+ }
696
+ const segments = normalized.split("/").filter(Boolean);
697
+ const firstSegment = segments[0];
698
+ const locale = config.locales.find(
699
+ (candidate) => candidate.toLowerCase() === firstSegment?.toLowerCase()
700
+ );
701
+ if (!locale) {
702
+ return { pathname: normalized, explicit: false };
703
+ }
704
+ const remaining = segments.slice(1);
705
+ return {
706
+ locale,
707
+ pathname: remaining.length > 0 ? `/${remaining.join("/")}` : "/",
708
+ explicit: true
709
+ };
710
+ }
711
+ __name(resolveFarmLocalePath, "resolveFarmLocalePath");
712
+ function stripFarmLocaleFromPathname(pathname, config) {
713
+ return resolveFarmLocalePath(pathname, config).pathname;
714
+ }
715
+ __name(stripFarmLocaleFromPathname, "stripFarmLocaleFromPathname");
716
+ function localizeFarmPathname(pathname, locale, config) {
717
+ const internalPathname = resolveFarmLocalePath(pathname, config).pathname;
718
+ if (config.routing === "none") return internalPathname;
719
+ if (config.routing === "prefix-except-default" && locale === config.defaultLocale) {
720
+ return internalPathname;
721
+ }
722
+ return internalPathname === "/" ? `/${locale}` : `/${locale}${internalPathname}`;
723
+ }
724
+ __name(localizeFarmPathname, "localizeFarmPathname");
725
+ function localizeFarmHref(href, locale, config) {
726
+ if (!href.startsWith("/") || href.startsWith("//")) return href;
727
+ const url = new URL(href, "http://farm.local");
728
+ url.pathname = localizeFarmPathname(url.pathname, locale, config);
729
+ return `${url.pathname}${url.search}${url.hash}`;
730
+ }
731
+ __name(localizeFarmHref, "localizeFarmHref");
732
+ function normalizePathname(pathname) {
733
+ const withLeadingSlash = pathname.startsWith("/") ? pathname : `/${pathname}`;
734
+ if (withLeadingSlash === "/") return "/";
735
+ return withLeadingSlash.replace(/\/{2,}/g, "/").replace(/\/$/, "") || "/";
736
+ }
737
+ __name(normalizePathname, "normalizePathname");
738
+
739
+ // src/i18n/resolver.ts
740
+ function getFarmLocaleVaryHeaders(config, resolution) {
741
+ if (!config.enabled || resolution.source === "url") return [];
742
+ const headers = [];
743
+ if (config.detection.includes("cookie")) headers.push("Cookie");
744
+ if (config.detection.includes("accept-language")) headers.push("Accept-Language");
745
+ return headers;
746
+ }
747
+ __name(getFarmLocaleVaryHeaders, "getFarmLocaleVaryHeaders");
748
+ function createFarmLocaleCookie(locale, config) {
749
+ const cookie = config.cookie;
750
+ let value = `${encodeURIComponent(cookie.name)}=${encodeURIComponent(locale)}`;
751
+ value += `; Max-Age=${cookie.maxAge}`;
752
+ value += `; Path=${cookie.path}`;
753
+ value += `; SameSite=${capitalize(cookie.sameSite)}`;
754
+ if (cookie.secure) value += "; Secure";
755
+ return value;
756
+ }
757
+ __name(createFarmLocaleCookie, "createFarmLocaleCookie");
758
+ function capitalize(value) {
759
+ return value.charAt(0).toUpperCase() + value.slice(1);
760
+ }
761
+ __name(capitalize, "capitalize");
762
+
763
+ // src/metadata.ts
764
+ function mergeMetadata(base, next) {
765
+ if (!base) return next ? { ...next } : {};
766
+ if (!next) return { ...base };
767
+ return {
768
+ ...base,
769
+ ...next,
770
+ openGraph: mergeNestedMetadata(base.openGraph, next.openGraph),
771
+ twitter: mergeNestedMetadata(base.twitter, next.twitter),
772
+ alternates: mergeNestedMetadata(base.alternates, next.alternates),
773
+ icons: mergeNestedMetadata(base.icons, next.icons)
774
+ };
775
+ }
776
+ __name(mergeMetadata, "mergeMetadata");
777
+ function addMetadataImageReference(metadata, reference) {
778
+ if (reference.kind === "opengraph") {
779
+ const openGraph = { ...metadata.openGraph || {} };
780
+ if (!hasMetadataImages(openGraph.images) && !hasMetadataImages(openGraph.image)) {
781
+ openGraph.images = [
782
+ {
783
+ url: reference.href,
784
+ width: reference.width,
785
+ height: reference.height,
786
+ alt: reference.alt,
787
+ type: reference.contentType
788
+ }
789
+ ];
790
+ }
791
+ return {
792
+ ...metadata,
793
+ openGraph
794
+ };
795
+ }
796
+ const twitter = { ...metadata.twitter || {} };
797
+ if (!hasMetadataImages(twitter.images)) {
798
+ twitter.images = [reference.href];
799
+ twitter.card = twitter.card || "summary_large_image";
800
+ }
801
+ return {
802
+ ...metadata,
803
+ twitter
804
+ };
805
+ }
806
+ __name(addMetadataImageReference, "addMetadataImageReference");
807
+ function renderMetadataHead(metadata) {
808
+ const resolvedMetadata = metadata || {};
809
+ const metadataBase = resolveMetadataBase(resolvedMetadata);
810
+ const title = resolveMetadataTitle(resolvedMetadata.title) || "Farm.js App";
811
+ const tags = [];
812
+ appendMetaName(tags, "description", resolvedMetadata.description);
813
+ appendMetaName(tags, "keywords", normalizeKeywords(resolvedMetadata.keywords));
814
+ appendMetaName(tags, "author", resolvedMetadata.author);
815
+ if (Array.isArray(resolvedMetadata.authors)) {
816
+ for (const author of resolvedMetadata.authors) {
817
+ appendMetaName(tags, "author", author?.name);
818
+ if (author?.url) {
819
+ appendLink(tags, "author", resolveMetadataUrl(author.url, metadataBase));
820
+ }
821
+ }
822
+ }
823
+ appendMetaName(tags, "creator", resolvedMetadata.creator);
824
+ appendMetaName(tags, "publisher", resolvedMetadata.publisher);
825
+ appendMetaName(tags, "robots", normalizeRobots(resolvedMetadata.robots));
826
+ const alternates = resolvedMetadata.alternates;
827
+ if (isRecord(alternates)) {
828
+ appendLink(tags, "canonical", resolveMetadataUrl(alternates.canonical, metadataBase));
829
+ if (isRecord(alternates.languages)) {
830
+ for (const [language, href] of Object.entries(alternates.languages)) {
831
+ appendLink(tags, "alternate", resolveMetadataUrl(href, metadataBase), {
832
+ hreflang: language
833
+ });
834
+ }
835
+ }
836
+ }
837
+ const hasFavicon = appendIcons(tags, resolvedMetadata.icons, metadataBase);
838
+ if (resolvedMetadata.manifest) {
839
+ appendLink(
840
+ tags,
841
+ "manifest",
842
+ resolveMetadataUrl(resolvedMetadata.manifest, metadataBase)
843
+ );
844
+ }
845
+ appendOpenGraph(tags, resolvedMetadata.openGraph, metadataBase);
846
+ appendTwitter(tags, resolvedMetadata.twitter, metadataBase);
847
+ return {
848
+ title: escapeText(title),
849
+ tags: tags.length > 0 ? `
850
+ ${tags.join("\n ")}` : "",
851
+ hasFavicon
852
+ };
853
+ }
854
+ __name(renderMetadataHead, "renderMetadataHead");
855
+ function mergeNestedMetadata(base, next) {
856
+ if (isRecord(base) && isRecord(next)) {
857
+ return {
858
+ ...base,
859
+ ...next
860
+ };
861
+ }
862
+ return next ?? base;
863
+ }
864
+ __name(mergeNestedMetadata, "mergeNestedMetadata");
865
+ function appendOpenGraph(tags, openGraph, metadataBase) {
866
+ if (!isRecord(openGraph)) return;
867
+ appendMetaProperty(tags, "og:title", openGraph.title);
868
+ appendMetaProperty(tags, "og:description", openGraph.description);
869
+ appendMetaProperty(tags, "og:url", resolveMetadataUrl(openGraph.url, metadataBase));
870
+ appendMetaProperty(tags, "og:site_name", openGraph.siteName);
871
+ appendMetaProperty(tags, "og:type", openGraph.type);
872
+ appendMetaProperty(tags, "og:locale", openGraph.locale);
873
+ const images = normalizeMetadataImages(
874
+ openGraph.images ?? openGraph.image,
875
+ metadataBase
876
+ );
877
+ for (const image of images) {
878
+ appendMetaProperty(tags, "og:image", image.url);
879
+ appendMetaProperty(tags, "og:image:width", image.width);
880
+ appendMetaProperty(tags, "og:image:height", image.height);
881
+ appendMetaProperty(tags, "og:image:alt", image.alt);
882
+ appendMetaProperty(tags, "og:image:type", image.type);
883
+ }
884
+ }
885
+ __name(appendOpenGraph, "appendOpenGraph");
886
+ function appendTwitter(tags, twitter, metadataBase) {
887
+ if (!isRecord(twitter)) return;
888
+ appendMetaName(tags, "twitter:card", twitter.card);
889
+ appendMetaName(tags, "twitter:site", twitter.site);
890
+ appendMetaName(tags, "twitter:creator", twitter.creator);
891
+ appendMetaName(tags, "twitter:title", twitter.title);
892
+ appendMetaName(tags, "twitter:description", twitter.description);
893
+ for (const image of normalizeMetadataImages(twitter.images, metadataBase)) {
894
+ appendMetaName(tags, "twitter:image", image.url);
895
+ appendMetaName(tags, "twitter:image:alt", image.alt);
896
+ }
897
+ }
898
+ __name(appendTwitter, "appendTwitter");
899
+ function appendIcons(tags, icons, metadataBase) {
900
+ if (!icons) return false;
901
+ if (typeof icons === "string") {
902
+ const initialTagCount2 = tags.length;
903
+ appendLink(tags, "icon", resolveMetadataUrl(icons, metadataBase));
904
+ return tags.length > initialTagCount2;
905
+ }
906
+ if (!isRecord(icons)) return false;
907
+ const initialTagCount = tags.length;
908
+ appendIconList(tags, "icon", icons.icon, metadataBase);
909
+ appendIconList(tags, "shortcut icon", icons.shortcut, metadataBase);
910
+ const hasFavicon = tags.length > initialTagCount;
911
+ appendIconList(tags, "apple-touch-icon", icons.apple, metadataBase);
912
+ return hasFavicon;
913
+ }
914
+ __name(appendIcons, "appendIcons");
915
+ function appendIconList(tags, rel, value, metadataBase) {
916
+ for (const icon of normalizeArray(value)) {
917
+ if (typeof icon === "string") {
918
+ appendLink(tags, rel, resolveMetadataUrl(icon, metadataBase));
919
+ continue;
920
+ }
921
+ if (!isRecord(icon)) continue;
922
+ appendLink(tags, rel, resolveMetadataUrl(icon.url, metadataBase), {
923
+ sizes: icon.sizes,
924
+ type: icon.type
925
+ });
926
+ }
927
+ }
928
+ __name(appendIconList, "appendIconList");
929
+ function appendMetaName(tags, name, content) {
930
+ const normalized = normalizeContent(content);
931
+ if (!normalized) return;
932
+ tags.push(`<meta name="${escapeAttribute(name)}" content="${escapeAttribute(normalized)}">`);
933
+ }
934
+ __name(appendMetaName, "appendMetaName");
935
+ function appendMetaProperty(tags, property, content) {
936
+ const normalized = normalizeContent(content);
937
+ if (!normalized) return;
938
+ tags.push(
939
+ `<meta property="${escapeAttribute(property)}" content="${escapeAttribute(normalized)}">`
940
+ );
941
+ }
942
+ __name(appendMetaProperty, "appendMetaProperty");
943
+ function appendLink(tags, rel, href, attrs = {}) {
944
+ const normalizedHref = normalizeContent(href);
945
+ if (!normalizedHref) return;
946
+ const attrText = Object.entries(attrs).map(([key, value]) => {
947
+ const normalized = normalizeContent(value);
948
+ return normalized ? ` ${key}="${escapeAttribute(normalized)}"` : "";
949
+ }).join("");
950
+ tags.push(
951
+ `<link rel="${escapeAttribute(rel)}" href="${escapeAttribute(normalizedHref)}"${attrText}>`
952
+ );
953
+ }
954
+ __name(appendLink, "appendLink");
955
+ function normalizeMetadataImages(value, metadataBase) {
956
+ return normalizeArray(value).map((item) => {
957
+ if (typeof item === "string") {
958
+ return { url: resolveMetadataUrl(item, metadataBase) || item };
959
+ }
960
+ if (!isRecord(item)) return null;
961
+ const rawUrl = item.url || item.src;
962
+ const url = resolveMetadataUrl(rawUrl, metadataBase);
963
+ if (!url) return null;
964
+ return {
965
+ url,
966
+ width: normalizeNumber(item.width),
967
+ height: normalizeNumber(item.height),
968
+ alt: typeof item.alt === "string" ? item.alt : void 0,
969
+ type: typeof item.type === "string" ? item.type : void 0
970
+ };
971
+ }).filter((item) => item !== null);
972
+ }
973
+ __name(normalizeMetadataImages, "normalizeMetadataImages");
974
+ function normalizeArray(value) {
975
+ if (value == null) return [];
976
+ return Array.isArray(value) ? value : [value];
977
+ }
978
+ __name(normalizeArray, "normalizeArray");
979
+ function hasMetadataImages(value) {
980
+ return normalizeMetadataImages(value).length > 0;
981
+ }
982
+ __name(hasMetadataImages, "hasMetadataImages");
983
+ function resolveMetadataTitle(title) {
984
+ if (typeof title === "string") return title;
985
+ if (isRecord(title)) {
986
+ return normalizeContent(title.default);
987
+ }
988
+ return void 0;
989
+ }
990
+ __name(resolveMetadataTitle, "resolveMetadataTitle");
991
+ function normalizeKeywords(keywords) {
992
+ if (Array.isArray(keywords)) return keywords.filter(Boolean).join(", ");
993
+ return keywords;
994
+ }
995
+ __name(normalizeKeywords, "normalizeKeywords");
996
+ function normalizeRobots(robots) {
997
+ if (typeof robots === "string") return robots;
998
+ if (!isRecord(robots)) return void 0;
999
+ const values = [];
1000
+ if (typeof robots.index === "boolean") values.push(robots.index ? "index" : "noindex");
1001
+ if (typeof robots.follow === "boolean") values.push(robots.follow ? "follow" : "nofollow");
1002
+ return values.join(", ") || void 0;
1003
+ }
1004
+ __name(normalizeRobots, "normalizeRobots");
1005
+ function resolveMetadataBase(metadata) {
1006
+ const base = metadata.metadataBase;
1007
+ if (!base) return void 0;
1008
+ return String(base);
1009
+ }
1010
+ __name(resolveMetadataBase, "resolveMetadataBase");
1011
+ function resolveMetadataUrl(value, metadataBase) {
1012
+ const normalized = normalizeContent(value);
1013
+ if (!normalized) return void 0;
1014
+ if (!metadataBase) return normalized;
1015
+ try {
1016
+ return new URL(normalized, metadataBase).toString();
1017
+ } catch {
1018
+ return normalized;
1019
+ }
1020
+ }
1021
+ __name(resolveMetadataUrl, "resolveMetadataUrl");
1022
+ function normalizeNumber(value) {
1023
+ if (typeof value === "number" && Number.isFinite(value)) return value;
1024
+ if (typeof value === "string") {
1025
+ const parsed = Number(value);
1026
+ return Number.isFinite(parsed) ? parsed : void 0;
1027
+ }
1028
+ return void 0;
1029
+ }
1030
+ __name(normalizeNumber, "normalizeNumber");
1031
+ function normalizeContent(value) {
1032
+ if (value == null) return void 0;
1033
+ if (typeof value === "string") return value;
1034
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
1035
+ if (value instanceof URL) return value.toString();
1036
+ return void 0;
1037
+ }
1038
+ __name(normalizeContent, "normalizeContent");
1039
+ function isRecord(value) {
1040
+ return !!value && typeof value === "object" && !Array.isArray(value);
1041
+ }
1042
+ __name(isRecord, "isRecord");
1043
+ function escapeText(value) {
1044
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1045
+ }
1046
+ __name(escapeText, "escapeText");
1047
+ function escapeAttribute(value) {
1048
+ return escapeText(value).replace(/"/g, "&quot;");
1049
+ }
1050
+ __name(escapeAttribute, "escapeAttribute");
1051
+
1052
+ // src/middleware/module.ts
1053
+ function isWebRequest(request) {
1054
+ return typeof Request !== "undefined" && request instanceof Request;
1055
+ }
1056
+ __name(isWebRequest, "isWebRequest");
1057
+ function toWebRequest(ctx) {
1058
+ if (isWebRequest(ctx.request)) {
1059
+ return ctx.request;
1060
+ }
1061
+ return createWebRequestFromFarmRequest(ctx.request);
1062
+ }
1063
+ __name(toWebRequest, "toWebRequest");
1064
+ function createRequestMiddlewareContext(ctx) {
1065
+ const context = {
1066
+ get url() {
1067
+ return ctx.url;
1068
+ },
1069
+ get pathname() {
1070
+ return ctx.pathname;
1071
+ },
1072
+ get searchParams() {
1073
+ return ctx.searchParams;
1074
+ },
1075
+ get method() {
1076
+ return ctx.method;
1077
+ },
1078
+ get params() {
1079
+ return ctx.params;
1080
+ },
1081
+ get route() {
1082
+ return ctx.route;
1083
+ },
1084
+ get locals() {
1085
+ return ctx.locals;
1086
+ },
1087
+ get data() {
1088
+ return ctx.data;
1089
+ },
1090
+ get headers() {
1091
+ return ctx.headers;
1092
+ },
1093
+ get cookies() {
1094
+ return ctx.cookies;
1095
+ },
1096
+ get(key) {
1097
+ return ctx.locals.get(key);
1098
+ },
1099
+ has(key) {
1100
+ return ctx.locals.has(key);
1101
+ },
1102
+ set(key, value) {
1103
+ ctx.locals.set(key, value);
1104
+ },
1105
+ delete(key) {
1106
+ return ctx.locals.delete(key);
1107
+ },
1108
+ redirect(url, status) {
1109
+ ctx.redirect(url, status);
1110
+ },
1111
+ rewrite(url) {
1112
+ ctx.rewrite(url);
1113
+ },
1114
+ json(data, status) {
1115
+ ctx.json(data, status);
1116
+ },
1117
+ text(content, status) {
1118
+ ctx.text(content, status);
1119
+ },
1120
+ html(content, status) {
1121
+ ctx.html(content, status);
1122
+ }
1123
+ };
1124
+ return context;
1125
+ }
1126
+ __name(createRequestMiddlewareContext, "createRequestMiddlewareContext");
1127
+ function normalizeMiddlewareModule(middlewareModule, routePath) {
1128
+ const module2 = middlewareModule;
1129
+ const defaultExport = module2.default;
1130
+ const namedExport = module2.middleware;
1131
+ const hasNamedExport = typeof namedExport === "function";
1132
+ if (namedExport !== void 0 && !hasNamedExport) {
1133
+ throw new TypeError("The named middleware export must be a function");
1134
+ }
1135
+ if (defaultExport && hasNamedExport) {
1136
+ throw new Error(
1137
+ "A middleware file cannot export both a default handler and a named middleware handler"
1138
+ );
1139
+ }
1140
+ if (hasNamedExport) {
1141
+ return {
1142
+ handlers: [
1143
+ async (ctx) => {
1144
+ return namedExport(toWebRequest(ctx), createRequestMiddlewareContext(ctx));
1145
+ }
1146
+ ],
1147
+ config: module2.config
1148
+ };
1149
+ }
1150
+ if (defaultExport && typeof defaultExport === "object" && "build" in defaultExport) {
1151
+ if (typeof defaultExport.setBasePath === "function") {
1152
+ defaultExport.setBasePath(routePath);
1153
+ }
1154
+ const built = defaultExport.build();
1155
+ const handlers = Array.isArray(built?.handlers) ? built.handlers.filter((handler) => typeof handler === "function") : [];
1156
+ return handlers.length > 0 ? {
1157
+ handlers,
1158
+ config: module2.config || built?.config
1159
+ } : null;
1160
+ }
1161
+ if (typeof defaultExport === "function") {
1162
+ return {
1163
+ handlers: [defaultExport],
1164
+ config: module2.config
1165
+ };
1166
+ }
1167
+ return null;
1168
+ }
1169
+ __name(normalizeMiddlewareModule, "normalizeMiddlewareModule");
1170
+
1171
+ // src/middleware/production-runtime.ts
1172
+ function parseCookies(cookieHeader) {
1173
+ if (!cookieHeader) return {};
1174
+ return cookieHeader.split(";").reduce(
1175
+ (cookies, cookie) => {
1176
+ const [name, ...rest] = cookie.split("=");
1177
+ const value = rest.join("=").trim();
1178
+ if (name && value) {
1179
+ cookies[name.trim()] = decodeURIComponent(value);
1180
+ }
1181
+ return cookies;
1182
+ },
1183
+ {}
1184
+ );
1185
+ }
1186
+ __name(parseCookies, "parseCookies");
1187
+ function serializeCookie(name, value, options = {}) {
1188
+ let cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
1189
+ if (options.maxAge) cookie += `; Max-Age=${options.maxAge}`;
1190
+ if (options.expires) cookie += `; Expires=${options.expires.toUTCString()}`;
1191
+ cookie += `; Path=${options.path || "/"}`;
1192
+ if (options.domain) cookie += `; Domain=${options.domain}`;
1193
+ if (options.secure) cookie += "; Secure";
1194
+ if (options.httpOnly) cookie += "; HttpOnly";
1195
+ if (options.sameSite) {
1196
+ cookie += `; SameSite=${options.sameSite.charAt(0).toUpperCase()}${options.sameSite.slice(1)}`;
1197
+ }
1198
+ return cookie;
1199
+ }
1200
+ __name(serializeCookie, "serializeCookie");
1201
+ var _WebCookieJar = class _WebCookieJar {
1202
+ constructor(request, headers) {
1203
+ this.headers = headers;
1204
+ this.setCookies = [];
1205
+ this.cookies = parseCookies(request.headers.get("cookie"));
1206
+ }
1207
+ get(name) {
1208
+ return this.cookies[name];
1209
+ }
1210
+ set(name, value, options = {}) {
1211
+ this.cookies[name] = value;
1212
+ const cookieString = serializeCookie(name, value, options);
1213
+ this.setCookies.push(cookieString);
1214
+ this.headers.set("Set-Cookie", this.setCookies.join(", "));
1215
+ }
1216
+ delete(name) {
1217
+ delete this.cookies[name];
1218
+ const cookieString = serializeCookie(name, "", {
1219
+ maxAge: 0,
1220
+ expires: /* @__PURE__ */ new Date(0)
1221
+ });
1222
+ this.setCookies.push(cookieString);
1223
+ this.headers.set("Set-Cookie", this.setCookies.join(", "));
1224
+ }
1225
+ getAll() {
1226
+ return { ...this.cookies };
1227
+ }
1228
+ };
1229
+ __name(_WebCookieJar, "WebCookieJar");
1230
+ var WebCookieJar = _WebCookieJar;
1231
+ function mapToHeaders(map) {
1232
+ const headers = new Headers();
1233
+ for (const [key, value] of map) {
1234
+ if (key.toLowerCase() === "set-cookie") {
1235
+ headers.append(key, value);
1236
+ } else {
1237
+ headers.set(key, value);
1238
+ }
1239
+ }
1240
+ return headers;
1241
+ }
1242
+ __name(mapToHeaders, "mapToHeaders");
1243
+ function headersToRecord(headers) {
1244
+ return Object.fromEntries(headers);
1245
+ }
1246
+ __name(headersToRecord, "headersToRecord");
1247
+ function isMiddlewareResponse(value) {
1248
+ return value instanceof Response;
1249
+ }
1250
+ __name(isMiddlewareResponse, "isMiddlewareResponse");
1251
+ function createResponseShim(headers) {
1252
+ return {
1253
+ headersSent: false,
1254
+ writableEnded: false,
1255
+ setHeader(name, value) {
1256
+ headers.set(name, Array.isArray(value) ? value.join(", ") : String(value));
1257
+ },
1258
+ getHeader(name) {
1259
+ return headers.get(name);
1260
+ },
1261
+ writeHead(status, responseHeaders) {
1262
+ this.statusCode = status;
1263
+ if (responseHeaders) {
1264
+ for (const [key, value] of Object.entries(responseHeaders)) {
1265
+ headers.set(key, value);
1266
+ }
1267
+ }
1268
+ this.headersSent = true;
1269
+ },
1270
+ end() {
1271
+ this.writableEnded = true;
1272
+ }
1273
+ };
1274
+ }
1275
+ __name(createResponseShim, "createResponseShim");
1276
+ function withNodeRequestShape(request) {
1277
+ const requestWithShape = request;
1278
+ if (!requestWithShape.socket) {
1279
+ const forwardedFor = request.headers.get("x-forwarded-for")?.split(",")[0]?.trim();
1280
+ try {
1281
+ requestWithShape.socket = {
1282
+ remoteAddress: forwardedFor || "127.0.0.1"
1283
+ };
1284
+ } catch {
1285
+ }
1286
+ }
1287
+ return requestWithShape;
1288
+ }
1289
+ __name(withNodeRequestShape, "withNodeRequestShape");
1290
+ function createHandledResponse(body, init, headers) {
1291
+ const responseHeaders = new Headers(init.headers);
1292
+ for (const [key, value] of headers) {
1293
+ if (key.toLowerCase() === "set-cookie") {
1294
+ responseHeaders.append(key, value);
1295
+ } else {
1296
+ responseHeaders.set(key, value);
1297
+ }
1298
+ }
1299
+ return new Response(body, { ...init, headers: responseHeaders });
1300
+ }
1301
+ __name(createHandledResponse, "createHandledResponse");
1302
+ function createWebMiddlewareContext(request, parent) {
1303
+ let currentRequest = withNodeRequestShape(request);
1304
+ let handledResponse = null;
1305
+ const url = new URL(currentRequest.url);
1306
+ const data = parent?.data ? new Map(parent.data) : /* @__PURE__ */ new Map();
1307
+ const locals = parent?.locals ? new Map(parent.locals) : /* @__PURE__ */ new Map();
1308
+ const headers = /* @__PURE__ */ new Map();
1309
+ if (parent?.headers) {
1310
+ for (const [key, value] of Object.entries(parent.headers)) {
1311
+ headers.set(key, value);
1312
+ }
1313
+ }
1314
+ const ctx = {
1315
+ request: currentRequest,
1316
+ response: createResponseShim(headers),
1317
+ url,
1318
+ pathname: url.pathname,
1319
+ searchParams: url.searchParams,
1320
+ method: currentRequest.method || "GET",
1321
+ params: {},
1322
+ route: url.pathname,
1323
+ parent,
1324
+ vite: {
1325
+ isDev: false,
1326
+ hmr: false
1327
+ },
1328
+ data,
1329
+ locals,
1330
+ headers,
1331
+ cookies: new WebCookieJar(currentRequest, headers),
1332
+ _handled: false,
1333
+ _redirectUrl: void 0,
1334
+ _rewriteUrl: void 0,
1335
+ redirect(redirectUrl, status = 307) {
1336
+ ctx._redirectUrl = redirectUrl;
1337
+ ctx._handled = true;
1338
+ handledResponse = createHandledResponse(
1339
+ `Redirecting to ${redirectUrl}`,
1340
+ {
1341
+ status,
1342
+ headers: {
1343
+ Location: redirectUrl,
1344
+ "Content-Type": "text/plain"
1345
+ }
1346
+ },
1347
+ headers
1348
+ );
1349
+ },
1350
+ rewrite(rewriteUrl) {
1351
+ ctx._rewriteUrl = rewriteUrl;
1352
+ const nextUrl = new URL(rewriteUrl, currentRequest.url);
1353
+ currentRequest = withNodeRequestShape(new Request(nextUrl, currentRequest));
1354
+ ctx.request = currentRequest;
1355
+ ctx.url = nextUrl;
1356
+ ctx.pathname = nextUrl.pathname;
1357
+ ctx.searchParams = nextUrl.searchParams;
1358
+ ctx.route = nextUrl.pathname;
1359
+ },
1360
+ json(jsonData, status = 200) {
1361
+ ctx._handled = true;
1362
+ handledResponse = createHandledResponse(
1363
+ JSON.stringify(jsonData),
1364
+ {
1365
+ status,
1366
+ headers: {
1367
+ "Content-Type": "application/json"
1368
+ }
1369
+ },
1370
+ headers
1371
+ );
1372
+ },
1373
+ text(content, status = 200) {
1374
+ ctx._handled = true;
1375
+ handledResponse = createHandledResponse(
1376
+ content,
1377
+ {
1378
+ status,
1379
+ headers: {
1380
+ "Content-Type": "text/plain"
1381
+ }
1382
+ },
1383
+ headers
1384
+ );
1385
+ },
1386
+ html(content, status = 200) {
1387
+ ctx._handled = true;
1388
+ handledResponse = createHandledResponse(
1389
+ content,
1390
+ {
1391
+ status,
1392
+ headers: {
1393
+ "Content-Type": "text/html"
1394
+ }
1395
+ },
1396
+ headers
1397
+ );
1398
+ }
1399
+ };
1400
+ return {
1401
+ ctx,
1402
+ getRequest: /* @__PURE__ */ __name(() => currentRequest, "getRequest"),
1403
+ getResponse: /* @__PURE__ */ __name(() => handledResponse, "getResponse")
1404
+ };
1405
+ }
1406
+ __name(createWebMiddlewareContext, "createWebMiddlewareContext");
1407
+ function toMatcherList(matcher) {
1408
+ if (!matcher) return [];
1409
+ return Array.isArray(matcher) ? matcher : [matcher];
1410
+ }
1411
+ __name(toMatcherList, "toMatcherList");
1412
+ function escapeRegex(value) {
1413
+ return value.replace(/[|\\{}()[\]^$+?.]/g, "\\$&");
1414
+ }
1415
+ __name(escapeRegex, "escapeRegex");
1416
+ function parseColonParam(segment) {
1417
+ const raw = segment.slice(1);
1418
+ const last = raw[raw.length - 1];
1419
+ const modifier = last === "*" || last === "+" || last === "?" ? last : void 0;
1420
+ return {
1421
+ name: modifier ? raw.slice(0, -1) : raw,
1422
+ modifier
1423
+ };
1424
+ }
1425
+ __name(parseColonParam, "parseColonParam");
1426
+ function compilePathPattern(pattern) {
1427
+ const params = [];
1428
+ const segments = pattern.split("/").filter(Boolean);
1429
+ if (segments.length === 0) {
1430
+ return { regex: /^\/$/, params };
1431
+ }
1432
+ const parts = segments.map((segment) => {
1433
+ if (segment === "**") {
1434
+ return "(?:/.*)?";
1435
+ }
1436
+ if (segment === "*") {
1437
+ return "/[^/]+";
1438
+ }
1439
+ if (segment.startsWith(":")) {
1440
+ const { name, modifier } = parseColonParam(segment);
1441
+ params.push(name);
1442
+ if (modifier === "*") {
1443
+ return "(?:/(.*))?";
1444
+ }
1445
+ if (modifier === "+") {
1446
+ return "/(.+)";
1447
+ }
1448
+ return "/([^/]+)";
1449
+ }
1450
+ if (segment.startsWith("[...") && segment.endsWith("]")) {
1451
+ params.push(segment.slice(4, -1));
1452
+ return "(?:/(.*))?";
1453
+ }
1454
+ if (segment.startsWith("[") && segment.endsWith("]")) {
1455
+ params.push(segment.slice(1, -1));
1456
+ return "/([^/]+)";
1457
+ }
1458
+ return `/${escapeRegex(segment).replace(/\\\*/g, "[^/]*")}`;
1459
+ });
1460
+ return {
1461
+ regex: new RegExp(`^${parts.join("")}$`),
1462
+ params
1463
+ };
1464
+ }
1465
+ __name(compilePathPattern, "compilePathPattern");
1466
+ function matchPattern(pattern, pathname) {
1467
+ if (pattern instanceof RegExp) {
1468
+ pattern.lastIndex = 0;
1469
+ const match2 = pattern.exec(pathname);
1470
+ return {
1471
+ matched: !!match2,
1472
+ params: match2?.groups ? { ...match2.groups } : void 0
1473
+ };
1474
+ }
1475
+ if (pattern === "*" || pattern === "/(.*)") {
1476
+ return { matched: true };
1477
+ }
1478
+ if (pattern.endsWith("(.*)")) {
1479
+ const prefix = pattern.slice(0, -4);
1480
+ return { matched: pathname === prefix || pathname.startsWith(`${prefix}/`) };
1481
+ }
1482
+ const { regex, params } = compilePathPattern(pattern);
1483
+ const match = regex.exec(pathname);
1484
+ if (!match) {
1485
+ return { matched: false };
1486
+ }
1487
+ const values = {};
1488
+ params.forEach((param, index) => {
1489
+ values[param] = decodeURIComponent(match[index + 1] || "");
1490
+ });
1491
+ return {
1492
+ matched: true,
1493
+ params: Object.keys(values).length > 0 ? values : void 0
1494
+ };
1495
+ }
1496
+ __name(matchPattern, "matchPattern");
1497
+ function matchesConfig(pathname, config, ctx) {
1498
+ if (config.exclude) {
1499
+ for (const pattern of config.exclude) {
1500
+ if (matchPattern(pattern, pathname).matched) {
1501
+ return { matched: false };
1502
+ }
1503
+ }
1504
+ }
1505
+ if (config.matcher) {
1506
+ for (const matcher of toMatcherList(config.matcher)) {
1507
+ if (typeof matcher === "string" || matcher instanceof RegExp) {
1508
+ const result = matchPattern(matcher, pathname);
1509
+ if (result.matched) {
1510
+ return result;
1511
+ }
1512
+ } else if (typeof matcher === "function") {
1513
+ return { matched: matcher(ctx) };
1514
+ }
1515
+ }
1516
+ return { matched: false };
1517
+ }
1518
+ return { matched: true };
1519
+ }
1520
+ __name(matchesConfig, "matchesConfig");
1521
+ function matchRoutePath(pathname, middlewarePath) {
1522
+ if (middlewarePath === "/") return { matched: true };
1523
+ const exactMatch = matchPattern(middlewarePath, pathname);
1524
+ if (exactMatch.matched) {
1525
+ return exactMatch;
1526
+ }
1527
+ const nestedMatch = matchPattern(`${middlewarePath}/:__farmRest*`, pathname);
1528
+ if (!nestedMatch.matched) {
1529
+ return { matched: false };
1530
+ }
1531
+ const params = { ...nestedMatch.params || {} };
1532
+ delete params.__farmRest;
1533
+ return {
1534
+ matched: true,
1535
+ params: Object.keys(params).length > 0 ? params : void 0
1536
+ };
1537
+ }
1538
+ __name(matchRoutePath, "matchRoutePath");
1539
+ function getConfigHandlers(entry) {
1540
+ const handlers = [];
1541
+ if ("handler" in entry && typeof entry.handler === "function") {
1542
+ handlers.push(entry.handler);
1543
+ }
1544
+ if ("handlers" in entry && Array.isArray(entry.handlers)) {
1545
+ handlers.push(...entry.handlers.filter((handler) => typeof handler === "function"));
1546
+ }
1547
+ return handlers;
1548
+ }
1549
+ __name(getConfigHandlers, "getConfigHandlers");
1550
+ function toMiddlewareConfig(entry) {
1551
+ const { matcher, exclude, runtime } = entry;
1552
+ return { matcher, exclude, runtime };
1553
+ }
1554
+ __name(toMiddlewareConfig, "toMiddlewareConfig");
1555
+ function normalizeConfigMiddleware(config) {
1556
+ const entries = [];
1557
+ let globalConfig;
1558
+ if (!config) {
1559
+ return { entries, globalConfig };
1560
+ }
1561
+ const configEntries = Array.isArray(config) ? config : [config];
1562
+ for (const [index, entry] of configEntries.entries()) {
1563
+ const handlers = getConfigHandlers(entry);
1564
+ const middlewareConfig = toMiddlewareConfig(entry);
1565
+ if (handlers.length === 0) {
1566
+ globalConfig = middlewareConfig;
1567
+ continue;
1568
+ }
1569
+ entries.push({
1570
+ path: "/",
1571
+ filePath: `farm.config.ts#middleware-${index}`,
1572
+ handlers,
1573
+ config: middlewareConfig,
1574
+ source: "config"
1575
+ });
1576
+ }
1577
+ return { entries, globalConfig };
1578
+ }
1579
+ __name(normalizeConfigMiddleware, "normalizeConfigMiddleware");
1580
+ function normalizeFileMiddleware(modules = []) {
1581
+ const entries = [];
1582
+ for (const moduleEntry of modules) {
1583
+ const normalized = normalizeMiddlewareModule(moduleEntry.module, moduleEntry.path);
1584
+ if (!normalized) {
1585
+ continue;
1586
+ }
1587
+ entries.push({
1588
+ path: moduleEntry.path,
1589
+ filePath: moduleEntry.filePath || moduleEntry.path,
1590
+ handlers: normalized.handlers,
1591
+ config: normalized.config,
1592
+ source: "file"
1593
+ });
1594
+ }
1595
+ return entries;
1596
+ }
1597
+ __name(normalizeFileMiddleware, "normalizeFileMiddleware");
1598
+ async function executeHandlers(handlers, ctx) {
1599
+ let handlerIndex = 0;
1600
+ let returnedResponse;
1601
+ const executeNext = /* @__PURE__ */ __name(async () => {
1602
+ if (handlerIndex < handlers.length) {
1603
+ const handler = handlers[handlerIndex++];
1604
+ const result2 = await handler(ctx, executeNext);
1605
+ if (isMiddlewareResponse(result2)) {
1606
+ returnedResponse = result2;
1607
+ return result2;
1608
+ }
1609
+ }
1610
+ return returnedResponse;
1611
+ }, "executeNext");
1612
+ const result = await executeNext();
1613
+ return isMiddlewareResponse(result) ? result : returnedResponse;
1614
+ }
1615
+ __name(executeHandlers, "executeHandlers");
1616
+ function emptyResult(request) {
1617
+ return {
1618
+ request,
1619
+ response: null,
1620
+ data: /* @__PURE__ */ new Map(),
1621
+ context: /* @__PURE__ */ new Map(),
1622
+ headers: new Headers(),
1623
+ handled: false
1624
+ };
1625
+ }
1626
+ __name(emptyResult, "emptyResult");
1627
+ function createProductionMiddlewareRunner(options = {}) {
1628
+ const configMiddleware = normalizeConfigMiddleware(options.config);
1629
+ const fileMiddleware = normalizeFileMiddleware(options.modules);
1630
+ const entries = [...configMiddleware.entries, ...fileMiddleware];
1631
+ const globalConfig = configMiddleware.globalConfig;
1632
+ return /* @__PURE__ */ __name(async function runProductionMiddleware(request) {
1633
+ if (!globalConfig && entries.length === 0) {
1634
+ return emptyResult(request);
1635
+ }
1636
+ let contextState = createWebMiddlewareContext(request);
1637
+ let ctx = contextState.ctx;
1638
+ let currentRequest = contextState.getRequest();
1639
+ const initialPathname = options.i18n?.enabled ? stripFarmLocaleFromPathname(ctx.pathname, options.i18n) : ctx.pathname;
1640
+ let parentData;
1641
+ if (globalConfig) {
1642
+ const globalMatch = matchesConfig(initialPathname, globalConfig, ctx);
1643
+ if (!globalMatch.matched) {
1644
+ return emptyResult(request);
1645
+ }
1646
+ if (globalMatch.params) {
1647
+ ctx.params = { ...ctx.params, ...globalMatch.params };
1648
+ }
1649
+ }
1650
+ const applicable = entries.map((entry) => ({
1651
+ entry,
1652
+ routeMatch: entry.source === "config" ? { matched: true } : matchRoutePath(initialPathname, entry.path)
1653
+ })).filter((candidate) => candidate.routeMatch.matched);
1654
+ if (applicable.length === 0) {
1655
+ return {
1656
+ request: currentRequest,
1657
+ response: null,
1658
+ data: new Map(ctx.data),
1659
+ context: new Map(ctx.locals),
1660
+ headers: mapToHeaders(ctx.headers),
1661
+ handled: false
1662
+ };
1663
+ }
1664
+ for (const candidate of applicable) {
1665
+ const { entry, routeMatch } = candidate;
1666
+ const configMatch = entry.config ? matchesConfig(initialPathname, entry.config, ctx) : { matched: true };
1667
+ if (!configMatch.matched) {
1668
+ continue;
1669
+ }
1670
+ if (parentData) {
1671
+ contextState = createWebMiddlewareContext(currentRequest, parentData);
1672
+ ctx = contextState.ctx;
1673
+ }
1674
+ if (routeMatch.params) {
1675
+ ctx.params = { ...ctx.params, ...routeMatch.params };
1676
+ }
1677
+ if (configMatch.params) {
1678
+ ctx.params = { ...ctx.params, ...configMatch.params };
1679
+ }
1680
+ const middlewareStartTime = Date.now();
1681
+ const middlewareEvent = {
1682
+ route: entry.path,
1683
+ pathname: initialPathname,
1684
+ name: entry.filePath
1685
+ };
1686
+ emitFarmEvent({ type: "middleware.start", ...middlewareEvent });
1687
+ try {
1688
+ const returnedResponse = await executeHandlers(entry.handlers, ctx);
1689
+ currentRequest = contextState.getRequest();
1690
+ if (returnedResponse) {
1691
+ const response = applyProductionMiddlewareHeaders(
1692
+ returnedResponse,
1693
+ mapToHeaders(ctx.headers)
1694
+ );
1695
+ emitFarmEvent({
1696
+ type: "middleware.shortCircuit",
1697
+ ...middlewareEvent,
1698
+ status: response.status
1699
+ });
1700
+ return {
1701
+ request: currentRequest,
1702
+ response,
1703
+ data: new Map(ctx.data),
1704
+ context: new Map(ctx.locals),
1705
+ headers: mapToHeaders(ctx.headers),
1706
+ handled: true
1707
+ };
1708
+ }
1709
+ if (ctx._handled) {
1710
+ const response = contextState.getResponse() || new Response(null);
1711
+ emitFarmEvent({
1712
+ type: "middleware.shortCircuit",
1713
+ ...middlewareEvent,
1714
+ status: response.status
1715
+ });
1716
+ return {
1717
+ request: currentRequest,
1718
+ response,
1719
+ data: new Map(ctx.data),
1720
+ context: new Map(ctx.locals),
1721
+ headers: mapToHeaders(ctx.headers),
1722
+ handled: true
1723
+ };
1724
+ }
1725
+ emitFarmEvent({
1726
+ type: "middleware.complete",
1727
+ ...middlewareEvent,
1728
+ durationMs: Date.now() - middlewareStartTime
1729
+ });
1730
+ } catch (error) {
1731
+ emitFarmEvent({
1732
+ type: "middleware.error",
1733
+ ...middlewareEvent,
1734
+ error
1735
+ });
1736
+ throw error;
1737
+ }
1738
+ parentData = {
1739
+ data: new Map(ctx.data),
1740
+ locals: new Map(ctx.locals),
1741
+ headers: headersToRecord(ctx.headers)
1742
+ };
1743
+ }
1744
+ return {
1745
+ request: currentRequest,
1746
+ response: null,
1747
+ data: new Map(ctx.data),
1748
+ context: new Map(ctx.locals),
1749
+ headers: mapToHeaders(ctx.headers),
1750
+ handled: false
1751
+ };
1752
+ }, "runProductionMiddleware");
1753
+ }
1754
+ __name(createProductionMiddlewareRunner, "createProductionMiddlewareRunner");
1755
+ function applyProductionMiddlewareHeaders(response, middlewareHeaders) {
1756
+ if (!middlewareHeaders || Array.from(middlewareHeaders.keys()).length === 0) {
1757
+ return response;
1758
+ }
1759
+ const headers = new Headers(response.headers);
1760
+ for (const [key, value] of middlewareHeaders) {
1761
+ if (key.toLowerCase() === "set-cookie") {
1762
+ headers.append(key, value);
1763
+ } else {
1764
+ headers.set(key, value);
1765
+ }
1766
+ }
1767
+ return new Response(response.body, {
1768
+ status: response.status,
1769
+ statusText: response.statusText,
1770
+ headers
1771
+ });
1772
+ }
1773
+ __name(applyProductionMiddlewareHeaders, "applyProductionMiddlewareHeaders");
1774
+
1775
+ // src/middleware/server.ts
1776
+ var import_async_hooks = require("async_hooks");
1777
+ var MIDDLEWARE_DATA_STORE_KEY = /* @__PURE__ */ Symbol.for("farm.middlewareDataStore");
1778
+ var MIDDLEWARE_CONTEXT_STORE_KEY = /* @__PURE__ */ Symbol.for("farm.middlewareContextStore");
1779
+ function getGlobalMiddlewareStore(key) {
1780
+ const state = globalThis;
1781
+ const existing = state[key];
1782
+ if (existing instanceof import_async_hooks.AsyncLocalStorage) {
1783
+ return existing;
1784
+ }
1785
+ const store = new import_async_hooks.AsyncLocalStorage();
1786
+ state[key] = store;
1787
+ return store;
1788
+ }
1789
+ __name(getGlobalMiddlewareStore, "getGlobalMiddlewareStore");
1790
+ var middlewareStore = getGlobalMiddlewareStore(MIDDLEWARE_DATA_STORE_KEY);
1791
+ var middlewareContextStore = getGlobalMiddlewareStore(MIDDLEWARE_CONTEXT_STORE_KEY);
1792
+ function toMiddlewareMap(data) {
1793
+ if (data instanceof Map) {
1794
+ return new Map(data);
1795
+ }
1796
+ return new Map(Object.entries(data));
1797
+ }
1798
+ __name(toMiddlewareMap, "toMiddlewareMap");
1799
+ async function _runWithMiddlewareData(data, fn) {
1800
+ return middlewareStore.run(toMiddlewareMap(data), fn);
1801
+ }
1802
+ __name(_runWithMiddlewareData, "_runWithMiddlewareData");
1803
+ async function _runWithMiddlewareContext(context, fn) {
1804
+ return middlewareContextStore.run(toMiddlewareMap(context), fn);
1805
+ }
1806
+ __name(_runWithMiddlewareContext, "_runWithMiddlewareContext");
1807
+
1808
+ // src/navigation-errors.ts
1809
+ var REDIRECT_ERROR_CODE = "FARM_REDIRECT";
1810
+ var NOT_FOUND_ERROR_CODE = "FARM_NOT_FOUND";
1811
+ var REDIRECT_ERROR_SYMBOL = /* @__PURE__ */ Symbol.for("farm.navigation.redirect");
1812
+ var NOT_FOUND_ERROR_SYMBOL = /* @__PURE__ */ Symbol.for("farm.navigation.notFound");
1813
+ function isFarmRedirectError(error) {
1814
+ return Boolean(getFarmRedirectError(error));
1815
+ }
1816
+ __name(isFarmRedirectError, "isFarmRedirectError");
1817
+ function getFarmRedirectError(error) {
1818
+ if (!error || typeof error !== "object") return null;
1819
+ const candidate = error;
1820
+ if (candidate[REDIRECT_ERROR_SYMBOL]) {
1821
+ return candidate[REDIRECT_ERROR_SYMBOL];
1822
+ }
1823
+ if (typeof candidate.digest === "string" && candidate.digest.startsWith(`${REDIRECT_ERROR_CODE};`)) {
1824
+ const [, status, ...urlParts] = candidate.digest.split(";");
1825
+ const parsedStatus = Number(status);
1826
+ if (isRedirectStatus(parsedStatus)) {
1827
+ return {
1828
+ status: parsedStatus,
1829
+ url: urlParts.join(";")
1830
+ };
1831
+ }
1832
+ }
1833
+ return null;
1834
+ }
1835
+ __name(getFarmRedirectError, "getFarmRedirectError");
1836
+ function isFarmNotFoundError(error) {
1837
+ if (!error || typeof error !== "object") return false;
1838
+ const candidate = error;
1839
+ return Boolean(candidate[NOT_FOUND_ERROR_SYMBOL] || candidate.digest === NOT_FOUND_ERROR_CODE);
1840
+ }
1841
+ __name(isFarmNotFoundError, "isFarmNotFoundError");
1842
+ function isRedirectStatus(status) {
1843
+ return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
1844
+ }
1845
+ __name(isRedirectStatus, "isRedirectStatus");
1846
+
1847
+ // src/route-context.ts
1848
+ var FARM_ROUTE_CONTEXT_SYMBOL = /* @__PURE__ */ Symbol.for("farm.routeContext");
1849
+ async function resolveFarmRouteContext(config, input) {
1850
+ if (typeof config.context !== "function") {
1851
+ return void 0;
1852
+ }
1853
+ return config.context(input);
1854
+ }
1855
+ __name(resolveFarmRouteContext, "resolveFarmRouteContext");
1856
+ function withFarmRouteContext(props, context) {
1857
+ if (context === void 0) {
1858
+ return props;
1859
+ }
1860
+ Object.defineProperty(props, FARM_ROUTE_CONTEXT_SYMBOL, {
1861
+ value: context,
1862
+ enumerable: false,
1863
+ configurable: true
1864
+ });
1865
+ return props;
1866
+ }
1867
+ __name(withFarmRouteContext, "withFarmRouteContext");
1868
+ // Annotate the CommonJS export names for ESM import in node:
1869
+ 0 && (module.exports = {
1870
+ _runWithAfterRequest,
1871
+ _runWithCurrentRequest,
1872
+ _runWithMiddlewareContext,
1873
+ _runWithMiddlewareData,
1874
+ addMetadataImageReference,
1875
+ applyProductionMiddlewareHeaders,
1876
+ configureFarmObservability,
1877
+ createFarmCacheKey,
1878
+ createFarmLocaleCookie,
1879
+ createProductionMiddlewareRunner,
1880
+ emitFarmEvent,
1881
+ getCurrentRequest,
1882
+ getFarmDataCache,
1883
+ getFarmLocaleVaryHeaders,
1884
+ getFarmRedirectError,
1885
+ isFarmNotFoundError,
1886
+ isFarmRedirectError,
1887
+ localizeFarmHref,
1888
+ localizeFarmPathname,
1889
+ mergeMetadata,
1890
+ normalizeRevalidatePath,
1891
+ renderMetadataHead,
1892
+ resolveFarmRouteContext,
1893
+ stripFarmLocaleFromPathname,
1894
+ withFarmRouteContext
1895
+ });
1896
+ //# sourceMappingURL=production-runtime.cjs.map