@farm.js/core 0.1.0-beta.6 → 0.1.0-beta.8

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 (447) hide show
  1. package/dist/after.cjs +227 -0
  2. package/dist/after.cjs.map +1 -0
  3. package/dist/after.d.mts +25 -0
  4. package/dist/after.d.ts +25 -0
  5. package/dist/after.mjs +14 -0
  6. package/dist/after.mjs.map +1 -0
  7. package/dist/agent-runtime.cjs +2379 -0
  8. package/dist/agent-runtime.cjs.map +1 -0
  9. package/dist/agent-runtime.d.mts +94 -0
  10. package/dist/agent-runtime.d.ts +94 -0
  11. package/dist/agent-runtime.mjs +479 -0
  12. package/dist/agent-runtime.mjs.map +1 -0
  13. package/dist/api/route-manager.d.mts +66 -0
  14. package/dist/api/route-manager.d.ts +66 -0
  15. package/dist/api/runtime.d.mts +3 -0
  16. package/dist/api/runtime.d.ts +3 -0
  17. package/dist/api.cjs +4100 -0
  18. package/dist/api.cjs.map +1 -0
  19. package/dist/api.d.mts +48 -0
  20. package/dist/api.d.ts +48 -0
  21. package/dist/api.mjs +93 -0
  22. package/dist/api.mjs.map +1 -0
  23. package/dist/app-BWtqQu3R.d.mts +302 -0
  24. package/dist/app-markdown.cjs +244 -0
  25. package/dist/app-markdown.cjs.map +1 -0
  26. package/dist/app-markdown.d.mts +22 -0
  27. package/dist/app-markdown.d.ts +22 -0
  28. package/dist/app-markdown.mjs +27 -0
  29. package/dist/app-markdown.mjs.map +1 -0
  30. package/dist/app-xltejvLY.d.ts +302 -0
  31. package/dist/cache.cjs +945 -0
  32. package/dist/cache.cjs.map +1 -0
  33. package/dist/cache.d.mts +192 -0
  34. package/dist/cache.d.ts +192 -0
  35. package/dist/cache.mjs +46 -0
  36. package/dist/cache.mjs.map +1 -0
  37. package/dist/chunk-2ED5Q2GH.mjs +422 -0
  38. package/dist/chunk-2ED5Q2GH.mjs.map +1 -0
  39. package/dist/chunk-32W4QEJP.mjs +158 -0
  40. package/dist/chunk-32W4QEJP.mjs.map +1 -0
  41. package/dist/chunk-3XNTL3FQ.mjs +452 -0
  42. package/dist/chunk-3XNTL3FQ.mjs.map +1 -0
  43. package/dist/chunk-44ZCFSKE.mjs +84 -0
  44. package/dist/chunk-44ZCFSKE.mjs.map +1 -0
  45. package/dist/chunk-4MGVSBRP.mjs +7787 -0
  46. package/dist/chunk-4MGVSBRP.mjs.map +1 -0
  47. package/dist/chunk-4S3ORGFA.mjs +44 -0
  48. package/dist/chunk-4S3ORGFA.mjs.map +1 -0
  49. package/dist/chunk-5BY76U2M.mjs +1 -0
  50. package/dist/chunk-5BY76U2M.mjs.map +1 -0
  51. package/dist/chunk-5ZGPRGWV.mjs +136 -0
  52. package/dist/chunk-5ZGPRGWV.mjs.map +1 -0
  53. package/dist/chunk-65A7QIKI.mjs +142 -0
  54. package/dist/chunk-65A7QIKI.mjs.map +1 -0
  55. package/dist/chunk-74YTBPTY.mjs +450 -0
  56. package/dist/chunk-74YTBPTY.mjs.map +1 -0
  57. package/dist/chunk-7FBJLMQH.mjs +338 -0
  58. package/dist/chunk-7FBJLMQH.mjs.map +1 -0
  59. package/dist/chunk-7HO6AEOP.mjs +74 -0
  60. package/dist/chunk-7HO6AEOP.mjs.map +1 -0
  61. package/dist/chunk-7MABZJIM.mjs +29 -0
  62. package/dist/chunk-7MABZJIM.mjs.map +1 -0
  63. package/dist/chunk-7N62DNSO.mjs +41 -0
  64. package/dist/chunk-7N62DNSO.mjs.map +1 -0
  65. package/dist/chunk-7ZY5AIJO.mjs +161 -0
  66. package/dist/chunk-7ZY5AIJO.mjs.map +1 -0
  67. package/dist/chunk-ALCLXXTY.mjs +187 -0
  68. package/dist/chunk-ALCLXXTY.mjs.map +1 -0
  69. package/dist/chunk-AZ7YUVNR.mjs +65 -0
  70. package/dist/chunk-AZ7YUVNR.mjs.map +1 -0
  71. package/dist/chunk-B232I2GP.mjs +163 -0
  72. package/dist/chunk-B232I2GP.mjs.map +1 -0
  73. package/dist/chunk-B4W3BNTL.mjs +483 -0
  74. package/dist/chunk-B4W3BNTL.mjs.map +1 -0
  75. package/dist/chunk-C2ROET2V.mjs +718 -0
  76. package/dist/chunk-C2ROET2V.mjs.map +1 -0
  77. package/dist/chunk-CGILA3WO.mjs +14 -0
  78. package/dist/chunk-CGILA3WO.mjs.map +1 -0
  79. package/dist/chunk-CGIXMLSY.mjs +184 -0
  80. package/dist/chunk-CGIXMLSY.mjs.map +1 -0
  81. package/dist/chunk-DJSGLHCN.mjs +597 -0
  82. package/dist/chunk-DJSGLHCN.mjs.map +1 -0
  83. package/dist/chunk-E2MPIBRE.mjs +149 -0
  84. package/dist/chunk-E2MPIBRE.mjs.map +1 -0
  85. package/dist/chunk-E6EPN5BT.mjs +203 -0
  86. package/dist/chunk-E6EPN5BT.mjs.map +1 -0
  87. package/dist/chunk-EI43C4RA.mjs +6277 -0
  88. package/dist/chunk-EI43C4RA.mjs.map +1 -0
  89. package/dist/chunk-EJ7T4TPB.mjs +622 -0
  90. package/dist/chunk-EJ7T4TPB.mjs.map +1 -0
  91. package/dist/chunk-FQYDHKKU.mjs +128 -0
  92. package/dist/chunk-FQYDHKKU.mjs.map +1 -0
  93. package/dist/chunk-FRPWCMMG.mjs +299 -0
  94. package/dist/chunk-FRPWCMMG.mjs.map +1 -0
  95. package/dist/chunk-GN72QAIH.mjs +146 -0
  96. package/dist/chunk-GN72QAIH.mjs.map +1 -0
  97. package/dist/chunk-GQVGIUSN.mjs +149 -0
  98. package/dist/chunk-GQVGIUSN.mjs.map +1 -0
  99. package/dist/chunk-GS6K5OCM.mjs +407 -0
  100. package/dist/chunk-GS6K5OCM.mjs.map +1 -0
  101. package/dist/chunk-GXASWWJU.mjs +364 -0
  102. package/dist/chunk-GXASWWJU.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-H2FA2SBS.mjs +51 -0
  106. package/dist/chunk-H2FA2SBS.mjs.map +1 -0
  107. package/dist/chunk-I4CUBGVF.mjs +93 -0
  108. package/dist/chunk-I4CUBGVF.mjs.map +1 -0
  109. package/dist/chunk-ITN462YM.mjs +98 -0
  110. package/dist/chunk-ITN462YM.mjs.map +1 -0
  111. package/dist/chunk-J23HNLFY.mjs +72 -0
  112. package/dist/chunk-J23HNLFY.mjs.map +1 -0
  113. package/dist/chunk-J4FNJ5IU.mjs +179 -0
  114. package/dist/chunk-J4FNJ5IU.mjs.map +1 -0
  115. package/dist/chunk-J5YWQVI5.mjs +211 -0
  116. package/dist/chunk-J5YWQVI5.mjs.map +1 -0
  117. package/dist/chunk-JDEOUK5V.mjs +427 -0
  118. package/dist/chunk-JDEOUK5V.mjs.map +1 -0
  119. package/dist/chunk-JK25YEN6.mjs +219 -0
  120. package/dist/chunk-JK25YEN6.mjs.map +1 -0
  121. package/dist/chunk-K4667E2Q.mjs +1916 -0
  122. package/dist/chunk-K4667E2Q.mjs.map +1 -0
  123. package/dist/chunk-LGHEOHBU.mjs +218 -0
  124. package/dist/chunk-LGHEOHBU.mjs.map +1 -0
  125. package/dist/chunk-LM2YNO4U.mjs +24 -0
  126. package/dist/chunk-LM2YNO4U.mjs.map +1 -0
  127. package/dist/chunk-ME4MO2RJ.mjs +3540 -0
  128. package/dist/chunk-ME4MO2RJ.mjs.map +1 -0
  129. package/dist/chunk-MIUW47JX.mjs +639 -0
  130. package/dist/chunk-MIUW47JX.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-P7QDS5AT.mjs +191 -0
  134. package/dist/chunk-P7QDS5AT.mjs.map +1 -0
  135. package/dist/chunk-PFE6GMNE.mjs +603 -0
  136. package/dist/chunk-PFE6GMNE.mjs.map +1 -0
  137. package/dist/chunk-QGOHVJ6J.mjs +63 -0
  138. package/dist/chunk-QGOHVJ6J.mjs.map +1 -0
  139. package/dist/chunk-QKVUNGAH.mjs +39 -0
  140. package/dist/chunk-QKVUNGAH.mjs.map +1 -0
  141. package/dist/chunk-QM746KUO.mjs +56 -0
  142. package/dist/chunk-QM746KUO.mjs.map +1 -0
  143. package/dist/chunk-QTZZ2ISQ.mjs +753 -0
  144. package/dist/chunk-QTZZ2ISQ.mjs.map +1 -0
  145. package/dist/chunk-RBRLLZL5.mjs +81 -0
  146. package/dist/chunk-RBRLLZL5.mjs.map +1 -0
  147. package/dist/chunk-RHIFZZUI.mjs +69 -0
  148. package/dist/chunk-RHIFZZUI.mjs.map +1 -0
  149. package/dist/chunk-RQ633A5I.mjs +187 -0
  150. package/dist/chunk-RQ633A5I.mjs.map +1 -0
  151. package/dist/chunk-SCFX4UTD.mjs +28 -0
  152. package/dist/chunk-SCFX4UTD.mjs.map +1 -0
  153. package/dist/chunk-SL6HTIOK.mjs +66 -0
  154. package/dist/chunk-SL6HTIOK.mjs.map +1 -0
  155. package/dist/chunk-SPBBQLXI.mjs +207 -0
  156. package/dist/chunk-SPBBQLXI.mjs.map +1 -0
  157. package/dist/chunk-SSA7THPX.mjs +10 -0
  158. package/dist/chunk-SSA7THPX.mjs.map +1 -0
  159. package/dist/chunk-T4QJQK76.mjs +459 -0
  160. package/dist/chunk-T4QJQK76.mjs.map +1 -0
  161. package/dist/chunk-TQAEEJB4.mjs +157 -0
  162. package/dist/chunk-TQAEEJB4.mjs.map +1 -0
  163. package/dist/chunk-UB5UOSHB.mjs +458 -0
  164. package/dist/chunk-UB5UOSHB.mjs.map +1 -0
  165. package/dist/chunk-USWZZUEH.mjs +25 -0
  166. package/dist/chunk-USWZZUEH.mjs.map +1 -0
  167. package/dist/chunk-UVCIEUJC.mjs +16 -0
  168. package/dist/chunk-UVCIEUJC.mjs.map +1 -0
  169. package/dist/chunk-UXUAWNO5.mjs +396 -0
  170. package/dist/chunk-UXUAWNO5.mjs.map +1 -0
  171. package/dist/chunk-V3XURYJO.mjs +756 -0
  172. package/dist/chunk-V3XURYJO.mjs.map +1 -0
  173. package/dist/chunk-V6WE6JSZ.mjs +352 -0
  174. package/dist/chunk-V6WE6JSZ.mjs.map +1 -0
  175. package/dist/chunk-V7RBCSDJ.mjs +170 -0
  176. package/dist/chunk-V7RBCSDJ.mjs.map +1 -0
  177. package/dist/chunk-VCANOYFI.mjs +588 -0
  178. package/dist/chunk-VCANOYFI.mjs.map +1 -0
  179. package/dist/chunk-VY2UYN5R.mjs +224 -0
  180. package/dist/chunk-VY2UYN5R.mjs.map +1 -0
  181. package/dist/chunk-W2CRQFF6.mjs +1352 -0
  182. package/dist/chunk-W2CRQFF6.mjs.map +1 -0
  183. package/dist/chunk-WDU6QXNK.mjs +872 -0
  184. package/dist/chunk-WDU6QXNK.mjs.map +1 -0
  185. package/dist/chunk-WZ5QFROO.mjs +23 -0
  186. package/dist/chunk-WZ5QFROO.mjs.map +1 -0
  187. package/dist/chunk-XIVV5IWN.mjs +541 -0
  188. package/dist/chunk-XIVV5IWN.mjs.map +1 -0
  189. package/dist/chunk-YW7OBE6Q.mjs +119 -0
  190. package/dist/chunk-YW7OBE6Q.mjs.map +1 -0
  191. package/dist/chunk-Z5CQMP54.mjs +365 -0
  192. package/dist/chunk-Z5CQMP54.mjs.map +1 -0
  193. package/dist/chunk-ZBE6MLHL.mjs +230 -0
  194. package/dist/chunk-ZBE6MLHL.mjs.map +1 -0
  195. package/dist/chunk-ZVWA4ZQ3.mjs +189 -0
  196. package/dist/chunk-ZVWA4ZQ3.mjs.map +1 -0
  197. package/dist/chunk-ZZ57EH5Z.mjs +173 -0
  198. package/dist/chunk-ZZ57EH5Z.mjs.map +1 -0
  199. package/dist/client-BT1mFQas.d.mts +447 -0
  200. package/dist/client-Nn0q4eO4.d.ts +447 -0
  201. package/dist/client-cache-CIlyBlmx.d.ts +6 -0
  202. package/dist/client-cache-D-EZ7XVW.d.mts +6 -0
  203. package/dist/client-plugins-BI2R6Eae.d.mts +1926 -0
  204. package/dist/client-plugins-DU9oMspX.d.ts +1926 -0
  205. package/dist/client-plugins.cjs +415 -0
  206. package/dist/client-plugins.cjs.map +1 -0
  207. package/dist/client-plugins.d.mts +22 -0
  208. package/dist/client-plugins.d.ts +22 -0
  209. package/dist/client-plugins.mjs +10 -0
  210. package/dist/client-plugins.mjs.map +1 -0
  211. package/dist/client.cjs +5402 -0
  212. package/dist/client.cjs.map +1 -0
  213. package/dist/client.d.mts +447 -0
  214. package/dist/client.d.ts +447 -0
  215. package/dist/client.mjs +110 -0
  216. package/dist/client.mjs.map +1 -0
  217. package/dist/config.cjs +38 -0
  218. package/dist/config.cjs.map +1 -0
  219. package/dist/config.d.mts +29 -0
  220. package/dist/config.d.ts +29 -0
  221. package/dist/config.mjs +10 -0
  222. package/dist/config.mjs.map +1 -0
  223. package/dist/cron.cjs +406 -0
  224. package/dist/cron.cjs.map +1 -0
  225. package/dist/cron.d.mts +78 -0
  226. package/dist/cron.d.ts +78 -0
  227. package/dist/cron.mjs +30 -0
  228. package/dist/cron.mjs.map +1 -0
  229. package/dist/deferred.cjs +438 -0
  230. package/dist/deferred.cjs.map +1 -0
  231. package/dist/deferred.d.mts +42 -0
  232. package/dist/deferred.d.ts +42 -0
  233. package/dist/deferred.mjs +28 -0
  234. package/dist/deferred.mjs.map +1 -0
  235. package/dist/deployment.cjs +199 -0
  236. package/dist/deployment.cjs.map +1 -0
  237. package/dist/deployment.d.mts +34 -0
  238. package/dist/deployment.d.ts +34 -0
  239. package/dist/deployment.mjs +38 -0
  240. package/dist/deployment.mjs.map +1 -0
  241. package/dist/devtools-REQTS3I7.mjs +371 -0
  242. package/dist/devtools-REQTS3I7.mjs.map +1 -0
  243. package/dist/devtools-client-3XRTBND5.mjs +216 -0
  244. package/dist/devtools-client-3XRTBND5.mjs.map +1 -0
  245. package/dist/devtools-ui-NJKFORTG.mjs +1349 -0
  246. package/dist/devtools-ui-NJKFORTG.mjs.map +1 -0
  247. package/dist/docs.cjs +5548 -0
  248. package/dist/docs.cjs.map +1 -0
  249. package/dist/docs.d.mts +69 -0
  250. package/dist/docs.d.ts +69 -0
  251. package/dist/docs.mjs +47 -0
  252. package/dist/docs.mjs.map +1 -0
  253. package/dist/env-types.cjs +232 -0
  254. package/dist/env-types.cjs.map +1 -0
  255. package/dist/env-types.d.mts +12 -0
  256. package/dist/env-types.d.ts +12 -0
  257. package/dist/env-types.mjs +11 -0
  258. package/dist/env-types.mjs.map +1 -0
  259. package/dist/env.cjs +215 -0
  260. package/dist/env.cjs.map +1 -0
  261. package/dist/env.d.mts +45 -0
  262. package/dist/env.d.ts +45 -0
  263. package/dist/env.mjs +22 -0
  264. package/dist/env.mjs.map +1 -0
  265. package/dist/environment/vite.d.mts +22 -0
  266. package/dist/environment/vite.d.ts +22 -0
  267. package/dist/environment.cjs +96 -0
  268. package/dist/environment.cjs.map +1 -0
  269. package/dist/environment.d.mts +18 -0
  270. package/dist/environment.d.ts +18 -0
  271. package/dist/environment.mjs +14 -0
  272. package/dist/environment.mjs.map +1 -0
  273. package/dist/headers.cjs +126 -0
  274. package/dist/headers.cjs.map +1 -0
  275. package/dist/headers.d.mts +22 -0
  276. package/dist/headers.d.ts +22 -0
  277. package/dist/headers.mjs +12 -0
  278. package/dist/headers.mjs.map +1 -0
  279. package/dist/i18n/client.d.mts +32 -0
  280. package/dist/i18n/client.d.ts +32 -0
  281. package/dist/i18n/index.d.mts +20 -0
  282. package/dist/i18n/index.d.ts +20 -0
  283. package/dist/i18n/server.d.mts +30 -0
  284. package/dist/i18n/server.d.ts +30 -0
  285. package/dist/image/server.d.mts +37 -0
  286. package/dist/image/server.d.ts +37 -0
  287. package/dist/image/sharp.d.mts +7 -0
  288. package/dist/image/sharp.d.ts +7 -0
  289. package/dist/image-config-Duob7wER.d.mts +50 -0
  290. package/dist/image-config-Duob7wER.d.ts +50 -0
  291. package/dist/image.cjs +209 -0
  292. package/dist/image.cjs.map +1 -0
  293. package/dist/image.d.mts +39 -0
  294. package/dist/image.d.ts +39 -0
  295. package/dist/image.mjs +165 -0
  296. package/dist/image.mjs.map +1 -0
  297. package/dist/index.cjs +42186 -0
  298. package/dist/index.cjs.map +1 -0
  299. package/dist/index.d.mts +454 -0
  300. package/dist/index.d.ts +454 -0
  301. package/dist/index.mjs +980 -0
  302. package/dist/index.mjs.map +1 -0
  303. package/dist/integration-api-CHT2OKAf.d.mts +93 -0
  304. package/dist/integration-api-CHT2OKAf.d.ts +93 -0
  305. package/dist/integration-orm-GQLGU66X.mjs +13 -0
  306. package/dist/integration-orm-GQLGU66X.mjs.map +1 -0
  307. package/dist/integrations.cjs +2820 -0
  308. package/dist/integrations.cjs.map +1 -0
  309. package/dist/integrations.d.mts +22 -0
  310. package/dist/integrations.d.ts +22 -0
  311. package/dist/integrations.mjs +51 -0
  312. package/dist/integrations.mjs.map +1 -0
  313. package/dist/internal/build-runtime.cjs +643 -322
  314. package/dist/internal/build-runtime.cjs.map +1 -1
  315. package/dist/internal/build-runtime.d.mts +39 -0
  316. package/dist/internal/build-runtime.d.ts +39 -0
  317. package/dist/internal/build-runtime.mjs +11 -10
  318. package/dist/internal/client-runtime.d.mts +2 -0
  319. package/dist/internal/client-runtime.d.ts +2 -0
  320. package/dist/internal/config-runtime.cjs +135 -39
  321. package/dist/internal/config-runtime.cjs.map +1 -1
  322. package/dist/internal/config-runtime.d.mts +39 -0
  323. package/dist/internal/config-runtime.d.ts +39 -0
  324. package/dist/internal/config-runtime.mjs +5 -4
  325. package/dist/internal/production-node-env.d.mts +12 -0
  326. package/dist/internal/production-node-env.d.ts +12 -0
  327. package/dist/internal/production-runtime.d.mts +39 -0
  328. package/dist/internal/production-runtime.d.ts +39 -0
  329. package/dist/layers-VWVDTPUZ.mjs +16 -0
  330. package/dist/layers-VWVDTPUZ.mjs.map +1 -0
  331. package/dist/manager-THKFTOFE.mjs +10 -0
  332. package/dist/manager-THKFTOFE.mjs.map +1 -0
  333. package/dist/markdown.cjs +364 -0
  334. package/dist/markdown.cjs.map +1 -0
  335. package/dist/markdown.d.mts +60 -0
  336. package/dist/markdown.d.ts +60 -0
  337. package/dist/markdown.mjs +18 -0
  338. package/dist/markdown.mjs.map +1 -0
  339. package/dist/metadata-Cm9ujH4I.d.ts +22 -0
  340. package/dist/metadata-DacXbnLA.d.mts +22 -0
  341. package/dist/middleware.cjs +2148 -0
  342. package/dist/middleware.cjs.map +1 -0
  343. package/dist/middleware.d.mts +164 -0
  344. package/dist/middleware.d.ts +164 -0
  345. package/dist/middleware.mjs +49 -0
  346. package/dist/middleware.mjs.map +1 -0
  347. package/dist/navigation-errors-Dvwpzaer.d.mts +13 -0
  348. package/dist/navigation-errors-Dvwpzaer.d.ts +13 -0
  349. package/dist/navigation.cjs +1329 -0
  350. package/dist/navigation.cjs.map +1 -0
  351. package/dist/navigation.d.mts +14 -0
  352. package/dist/navigation.d.ts +14 -0
  353. package/dist/navigation.mjs +33 -0
  354. package/dist/navigation.mjs.map +1 -0
  355. package/dist/nitro-QO5LV6QK.mjs +689 -0
  356. package/dist/nitro-QO5LV6QK.mjs.map +1 -0
  357. package/dist/observability.cjs +186 -0
  358. package/dist/observability.cjs.map +1 -0
  359. package/dist/observability.d.mts +335 -0
  360. package/dist/observability.d.ts +335 -0
  361. package/dist/observability.mjs +16 -0
  362. package/dist/observability.mjs.map +1 -0
  363. package/dist/params-BALtrRim.d.ts +15 -0
  364. package/dist/params-ry-lxqmy.d.mts +15 -0
  365. package/dist/plugin-BJDf43dc.d.mts +165 -0
  366. package/dist/plugin-BJDf43dc.d.ts +165 -0
  367. package/dist/plugin.cjs +23470 -0
  368. package/dist/plugin.cjs.map +1 -1
  369. package/dist/plugin.d.mts +22 -0
  370. package/dist/plugin.d.ts +22 -0
  371. package/dist/plugin.mjs +8 -7
  372. package/dist/production-runtime-4KKq1AVC.d.mts +79 -0
  373. package/dist/production-runtime-C_B79w2P.d.mts +28 -0
  374. package/dist/production-runtime-DDEM1D2q.d.ts +28 -0
  375. package/dist/production-runtime-DRsWDN2x.d.ts +79 -0
  376. package/dist/query/client.d.mts +61 -0
  377. package/dist/query/client.d.ts +61 -0
  378. package/dist/query/index.d.mts +90 -0
  379. package/dist/query/index.d.ts +90 -0
  380. package/dist/query/parsers.d.mts +25 -0
  381. package/dist/query/parsers.d.ts +25 -0
  382. package/dist/query/server.d.mts +55 -0
  383. package/dist/query/server.d.ts +55 -0
  384. package/dist/request-Dsq4kGW0.d.mts +6 -0
  385. package/dist/request-udtobOLv.d.ts +6 -0
  386. package/dist/request.d.mts +2 -0
  387. package/dist/request.d.ts +2 -0
  388. package/dist/resolver-DJqjLMg_.d.mts +14 -0
  389. package/dist/resolver-IH4RmPEl.d.ts +14 -0
  390. package/dist/route-runtime-DoOHzCAD.d.mts +38 -0
  391. package/dist/route-runtime-DoOHzCAD.d.ts +38 -0
  392. package/dist/router.d.mts +36 -0
  393. package/dist/router.d.ts +36 -0
  394. package/dist/routes.d.mts +224 -0
  395. package/dist/routes.d.ts +224 -0
  396. package/dist/runtime-9nQjVM7X.d.mts +206 -0
  397. package/dist/runtime-Cxpq6xZN.d.mts +27 -0
  398. package/dist/runtime-DgeS2skB.d.ts +206 -0
  399. package/dist/runtime-bv63eUiO.d.ts +27 -0
  400. package/dist/server-action-security.d.mts +43 -0
  401. package/dist/server-action-security.d.ts +43 -0
  402. package/dist/server-fn-client.d.mts +32 -0
  403. package/dist/server-fn-client.d.ts +32 -0
  404. package/dist/server-fn.d.mts +93 -0
  405. package/dist/server-fn.d.ts +93 -0
  406. package/dist/server-plugins.d.mts +55 -0
  407. package/dist/server-plugins.d.ts +55 -0
  408. package/dist/server-query-client.d.mts +50 -0
  409. package/dist/server-query-client.d.ts +50 -0
  410. package/dist/server-query.d.mts +36 -0
  411. package/dist/server-query.d.ts +36 -0
  412. package/dist/server.cjs +731 -447
  413. package/dist/server.cjs.map +1 -1
  414. package/dist/server.d.mts +48 -0
  415. package/dist/server.d.ts +48 -0
  416. package/dist/server.mjs +9 -8
  417. package/dist/server.mjs.map +1 -1
  418. package/dist/storage.d.mts +52 -0
  419. package/dist/storage.d.ts +52 -0
  420. package/dist/testing.d.mts +101 -0
  421. package/dist/testing.d.ts +101 -0
  422. package/dist/transport-BmbGTXA5.d.mts +49 -0
  423. package/dist/transport-BmbGTXA5.d.ts +49 -0
  424. package/dist/types-BMxWr97v.d.mts +81 -0
  425. package/dist/types-BMxWr97v.d.ts +81 -0
  426. package/dist/types-C9N-nk5R.d.mts +53 -0
  427. package/dist/types-C9N-nk5R.d.ts +53 -0
  428. package/dist/types-D1A6-XvH.d.mts +73 -0
  429. package/dist/types-D1A6-XvH.d.ts +73 -0
  430. package/dist/utils-B-cUHwoK.d.ts +23 -0
  431. package/dist/utils-Cm41AefV.d.mts +23 -0
  432. package/dist/version.cjs +1 -1
  433. package/dist/version.cjs.map +1 -1
  434. package/dist/version.d.mts +3 -0
  435. package/dist/version.d.ts +3 -0
  436. package/dist/version.mjs +1 -1
  437. package/dist/vite.cjs +682 -437
  438. package/dist/vite.cjs.map +1 -1
  439. package/dist/vite.d.mts +22 -0
  440. package/dist/vite.d.ts +22 -0
  441. package/dist/vite.mjs +6 -5
  442. package/dist/workflows.d.mts +110 -0
  443. package/dist/workflows.d.ts +110 -0
  444. package/package.json +3 -2
  445. package/types/client.d.ts +1 -1
  446. package/types/image.d.ts +4 -0
  447. package/types/images.d.ts +59 -0
@@ -0,0 +1,1352 @@
1
+ import {
2
+ getFarmClientDataCache,
3
+ normalizeFarmClientCacheKey
4
+ } from "./chunk-TQAEEJB4.mjs";
5
+ import {
6
+ isFarmAPIStream,
7
+ isJSONStreamResponse,
8
+ readJSONStream
9
+ } from "./chunk-ALCLXXTY.mjs";
10
+ import {
11
+ FARM_CACHE_INVALIDATION_HEADER,
12
+ applyFarmCacheInvalidations,
13
+ decodeFarmCacheInvalidations
14
+ } from "./chunk-RBRLLZL5.mjs";
15
+ import {
16
+ __name
17
+ } from "./chunk-CGILA3WO.mjs";
18
+
19
+ // src/integration-client.ts
20
+ var _IntegrationClientError = class _IntegrationClientError extends Error {
21
+ constructor(message, response, data) {
22
+ super(message);
23
+ this.name = "IntegrationClientError";
24
+ this.status = response.status;
25
+ this.response = response;
26
+ this.data = data;
27
+ }
28
+ };
29
+ __name(_IntegrationClientError, "IntegrationClientError");
30
+ var IntegrationClientError = _IntegrationClientError;
31
+ var INTEGRATION_RUNTIME_REGISTRY_KEY = /* @__PURE__ */ Symbol.for("farm.integrationRuntimeRegistry");
32
+ var CURRENT_REQUEST_RESOLVER_KEY = /* @__PURE__ */ Symbol.for("farm.currentRequestResolver");
33
+ var INTEGRATION_REQUEST_DISPATCHER_KEY = /* @__PURE__ */ Symbol.for("farm.integrationRequestDispatcher");
34
+ function isOperation(value) {
35
+ return !!value && typeof value === "object" && value.kind === "farm-integration-api-operation";
36
+ }
37
+ __name(isOperation, "isOperation");
38
+ function tryResolveSourceAPI(source) {
39
+ if ("kind" in source && source.kind === "farm-integration") {
40
+ if (!source.api) {
41
+ return null;
42
+ }
43
+ return source.api;
44
+ }
45
+ return source;
46
+ }
47
+ __name(tryResolveSourceAPI, "tryResolveSourceAPI");
48
+ function getIntegrationRuntimeRegistry() {
49
+ const globalState = globalThis;
50
+ return globalState[INTEGRATION_RUNTIME_REGISTRY_KEY] || /* @__PURE__ */ new Map();
51
+ }
52
+ __name(getIntegrationRuntimeRegistry, "getIntegrationRuntimeRegistry");
53
+ function getRegisteredIntegrationRuntimeLocal(key) {
54
+ return getIntegrationRuntimeRegistry().get(key);
55
+ }
56
+ __name(getRegisteredIntegrationRuntimeLocal, "getRegisteredIntegrationRuntimeLocal");
57
+ function getRegisteredIntegrationsLocal() {
58
+ return Object.fromEntries(
59
+ Array.from(getIntegrationRuntimeRegistry().entries()).map(([key, runtime]) => [
60
+ key,
61
+ runtime.integration
62
+ ])
63
+ );
64
+ }
65
+ __name(getRegisteredIntegrationsLocal, "getRegisteredIntegrationsLocal");
66
+ function resolveCurrentRequestLocal() {
67
+ const globalState = globalThis;
68
+ return globalState[CURRENT_REQUEST_RESOLVER_KEY]?.();
69
+ }
70
+ __name(resolveCurrentRequestLocal, "resolveCurrentRequestLocal");
71
+ function resolveIntegrationRequestDispatcherLocal() {
72
+ const globalState = globalThis;
73
+ return globalState[INTEGRATION_REQUEST_DISPATCHER_KEY];
74
+ }
75
+ __name(resolveIntegrationRequestDispatcherLocal, "resolveIntegrationRequestDispatcherLocal");
76
+ var INTEGRATION_DATA_HEADER = "x-farm-integration-data";
77
+ var INTEGRATION_DATA_HEADER_MAX_LENGTH = 16 * 1024;
78
+ var BLOCKED_INTEGRATION_DATA_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
79
+ function isIntegrationClientData(value) {
80
+ return !!value && typeof value === "object" && !Array.isArray(value);
81
+ }
82
+ __name(isIntegrationClientData, "isIntegrationClientData");
83
+ function isPlainIntegrationDataObject(value) {
84
+ if (!isIntegrationClientData(value)) {
85
+ return false;
86
+ }
87
+ const prototype = Object.getPrototypeOf(value);
88
+ return prototype === Object.prototype || prototype === null;
89
+ }
90
+ __name(isPlainIntegrationDataObject, "isPlainIntegrationDataObject");
91
+ function sanitizeIntegrationClientDataValue(value) {
92
+ if (Array.isArray(value)) {
93
+ return value.map((item) => sanitizeIntegrationClientDataValue(item));
94
+ }
95
+ if (!isPlainIntegrationDataObject(value)) {
96
+ return value;
97
+ }
98
+ const sanitized = {};
99
+ for (const [key, item] of Object.entries(value)) {
100
+ if (BLOCKED_INTEGRATION_DATA_KEYS.has(key)) {
101
+ continue;
102
+ }
103
+ sanitized[key] = sanitizeIntegrationClientDataValue(item);
104
+ }
105
+ return sanitized;
106
+ }
107
+ __name(sanitizeIntegrationClientDataValue, "sanitizeIntegrationClientDataValue");
108
+ function normalizeIntegrationClientData(value) {
109
+ if (!isIntegrationClientData(value)) {
110
+ return void 0;
111
+ }
112
+ const sanitized = sanitizeIntegrationClientDataValue(value);
113
+ return isIntegrationClientData(sanitized) && Object.keys(sanitized).length > 0 ? sanitized : void 0;
114
+ }
115
+ __name(normalizeIntegrationClientData, "normalizeIntegrationClientData");
116
+ function getIntegrationDataHeaderByteLength(value) {
117
+ return new TextEncoder().encode(value).byteLength;
118
+ }
119
+ __name(getIntegrationDataHeaderByteLength, "getIntegrationDataHeaderByteLength");
120
+ function mergeIntegrationClientData(...values) {
121
+ let merged;
122
+ for (const value of values) {
123
+ const data = normalizeIntegrationClientData(value);
124
+ if (!data) {
125
+ continue;
126
+ }
127
+ merged = {
128
+ ...merged,
129
+ ...data
130
+ };
131
+ }
132
+ return merged && Object.keys(merged).length > 0 ? merged : void 0;
133
+ }
134
+ __name(mergeIntegrationClientData, "mergeIntegrationClientData");
135
+ function serializeIntegrationClientData(data) {
136
+ const serialized = JSON.stringify(data);
137
+ if (getIntegrationDataHeaderByteLength(serialized) > INTEGRATION_DATA_HEADER_MAX_LENGTH) {
138
+ throw new Error(
139
+ `Integration client data must be smaller than ${INTEGRATION_DATA_HEADER_MAX_LENGTH} bytes when sent over HTTP headers.`
140
+ );
141
+ }
142
+ return serialized;
143
+ }
144
+ __name(serializeIntegrationClientData, "serializeIntegrationClientData");
145
+ function appendIntegrationClientDataHeader(headers, data) {
146
+ if (!data) {
147
+ return;
148
+ }
149
+ headers.set(INTEGRATION_DATA_HEADER, serializeIntegrationClientData(data));
150
+ }
151
+ __name(appendIntegrationClientDataHeader, "appendIntegrationClientDataHeader");
152
+ function resolveAutomaticClientNamespaces() {
153
+ const globalState = globalThis;
154
+ const manifest = globalState.window?.__FARM_INTEGRATION_API_MANIFEST__ || globalState.__FARM_INTEGRATION_API_MANIFEST__ || {};
155
+ return Object.entries(manifest).map(([key, api]) => [key, api, api]);
156
+ }
157
+ __name(resolveAutomaticClientNamespaces, "resolveAutomaticClientNamespaces");
158
+ function resolveAutomaticServerNamespaces() {
159
+ return Object.entries(getRegisteredIntegrationsLocal()).flatMap(([key, source]) => {
160
+ const api = tryResolveSourceAPI(source);
161
+ return api ? [[key, api, source]] : [];
162
+ });
163
+ }
164
+ __name(resolveAutomaticServerNamespaces, "resolveAutomaticServerNamespaces");
165
+ function appendQuery(url, query) {
166
+ if (!query) {
167
+ return;
168
+ }
169
+ for (const [key, value] of Object.entries(query)) {
170
+ if (value == null) {
171
+ continue;
172
+ }
173
+ if (Array.isArray(value)) {
174
+ for (const item of value) {
175
+ if (item != null) {
176
+ url.searchParams.append(key, String(item));
177
+ }
178
+ }
179
+ continue;
180
+ }
181
+ url.searchParams.set(key, String(value));
182
+ }
183
+ }
184
+ __name(appendQuery, "appendQuery");
185
+ function appendHeaders(target, source) {
186
+ if (!source) {
187
+ return;
188
+ }
189
+ const headers = new Headers(source);
190
+ headers.forEach((value, key) => {
191
+ target.set(key, value);
192
+ });
193
+ }
194
+ __name(appendHeaders, "appendHeaders");
195
+ var DEFAULT_FORWARDED_HEADERS = [
196
+ "authorization",
197
+ "cookie",
198
+ "x-client-ip",
199
+ "x-forwarded-for",
200
+ "x-forwarded-host",
201
+ "x-forwarded-proto",
202
+ "x-real-ip"
203
+ ];
204
+ function resolveRequestLike(request) {
205
+ if (!request) {
206
+ return void 0;
207
+ }
208
+ if (request instanceof Request) {
209
+ return {
210
+ url: request.url,
211
+ headers: request.headers
212
+ };
213
+ }
214
+ return {
215
+ url: request.url,
216
+ headers: request.headers ? new Headers(request.headers) : void 0
217
+ };
218
+ }
219
+ __name(resolveRequestLike, "resolveRequestLike");
220
+ function resolveServerBaseURL(explicitBaseURL, request) {
221
+ if (explicitBaseURL) {
222
+ return explicitBaseURL;
223
+ }
224
+ if (request?.url) {
225
+ try {
226
+ return new URL(request.url).origin;
227
+ } catch {
228
+ }
229
+ }
230
+ const headers = request?.headers;
231
+ const host = headers?.get("x-forwarded-host") || headers?.get("host");
232
+ if (host) {
233
+ const proto = headers?.get("x-forwarded-proto") || "http";
234
+ return `${proto}://${host}`;
235
+ }
236
+ return "http://localhost:3000";
237
+ }
238
+ __name(resolveServerBaseURL, "resolveServerBaseURL");
239
+ function resolveForwardHeaders(request, forwardHeaders) {
240
+ if (!request?.headers || forwardHeaders === false) {
241
+ return new Headers();
242
+ }
243
+ const allowed = Array.isArray(forwardHeaders) && forwardHeaders.length > 0 ? new Set(forwardHeaders.map((item) => item.toLowerCase())) : new Set(DEFAULT_FORWARDED_HEADERS);
244
+ const headers = new Headers();
245
+ request.headers.forEach((value, key) => {
246
+ if (allowed.has(key.toLowerCase())) {
247
+ headers.set(key, value);
248
+ }
249
+ });
250
+ return headers;
251
+ }
252
+ __name(resolveForwardHeaders, "resolveForwardHeaders");
253
+ function createBody(format, body, headers) {
254
+ if (body == null || format === "none") {
255
+ return void 0;
256
+ }
257
+ if (format === "form") {
258
+ if (body instanceof FormData || body instanceof URLSearchParams) {
259
+ return body;
260
+ }
261
+ const form = new URLSearchParams();
262
+ for (const [key, value] of Object.entries(body)) {
263
+ if (value == null) {
264
+ continue;
265
+ }
266
+ if (Array.isArray(value)) {
267
+ for (const item of value) {
268
+ if (item != null) {
269
+ form.append(key, String(item));
270
+ }
271
+ }
272
+ continue;
273
+ }
274
+ form.set(key, String(value));
275
+ }
276
+ headers.set("content-type", "application/x-www-form-urlencoded;charset=UTF-8");
277
+ return form;
278
+ }
279
+ headers.set("content-type", "application/json");
280
+ return JSON.stringify(body);
281
+ }
282
+ __name(createBody, "createBody");
283
+ async function parseResponseData(response) {
284
+ if (response.status === 204 || response.status === 205) {
285
+ return void 0;
286
+ }
287
+ const contentType = response.headers.get("content-type") || "";
288
+ if (contentType.includes("application/json")) {
289
+ return await response.json();
290
+ }
291
+ return await response.text();
292
+ }
293
+ __name(parseResponseData, "parseResponseData");
294
+ async function safeParseResponseData(response) {
295
+ try {
296
+ return await parseResponseData(response);
297
+ } catch {
298
+ return void 0;
299
+ }
300
+ }
301
+ __name(safeParseResponseData, "safeParseResponseData");
302
+ function createResponseError(response, errorData) {
303
+ const message = typeof errorData === "string" ? errorData : typeof errorData === "object" && errorData ? String(
304
+ errorData.error || errorData.message || response.statusText
305
+ ) : response.statusText || "Integration request failed.";
306
+ return new IntegrationClientError(message, response, errorData);
307
+ }
308
+ __name(createResponseError, "createResponseError");
309
+ function normalizeExecutionError(error) {
310
+ if (error instanceof Error) {
311
+ return error;
312
+ }
313
+ if (typeof error === "string" && error.length > 0) {
314
+ return new Error(error);
315
+ }
316
+ return new Error("Integration request failed.");
317
+ }
318
+ __name(normalizeExecutionError, "normalizeExecutionError");
319
+ async function finalizeOperationResponse(operation, response) {
320
+ if (!response.ok) {
321
+ const errorData = await safeParseResponseData(response);
322
+ return {
323
+ data: null,
324
+ error: createResponseError(response, errorData)
325
+ };
326
+ }
327
+ if (operation.responseFormat === "response") {
328
+ return {
329
+ data: response,
330
+ error: null
331
+ };
332
+ }
333
+ return {
334
+ data: await parseResponseData(response),
335
+ error: null
336
+ };
337
+ }
338
+ __name(finalizeOperationResponse, "finalizeOperationResponse");
339
+ async function executeClientOperation(operation, input, options, requestOptions) {
340
+ try {
341
+ if (!operation.path) {
342
+ return {
343
+ data: null,
344
+ error: new Error(
345
+ "Integration API operation path is missing. Pass a path to api.get/post/... or wrap pathless methods with api.route(path, { ... })."
346
+ )
347
+ };
348
+ }
349
+ const baseURL = options.baseURL || (typeof window !== "undefined" ? window.location.origin : "http://localhost:3000");
350
+ const url = new URL(operation.path, baseURL);
351
+ appendQuery(url, input.query);
352
+ const headers = new Headers({
353
+ "x-farm-integration-client": "1",
354
+ ...options.headers,
355
+ ...operation.headers,
356
+ ...requestOptions?.headers
357
+ });
358
+ if (operation.responseFormat !== "response") {
359
+ headers.set("accept", "application/json");
360
+ }
361
+ appendIntegrationClientDataHeader(
362
+ headers,
363
+ mergeIntegrationClientData(options.data, requestOptions?.data)
364
+ );
365
+ const response = await fetch(url.toString(), {
366
+ method: operation.method,
367
+ headers,
368
+ body: createBody(operation.bodyFormat, input.body, headers),
369
+ credentials: requestOptions?.credentials ?? operation.credentials ?? options.credentials ?? "include",
370
+ signal: requestOptions?.signal
371
+ });
372
+ if (!response.ok) {
373
+ const errorData = await safeParseResponseData(response);
374
+ return {
375
+ data: null,
376
+ error: createResponseError(response, errorData)
377
+ };
378
+ }
379
+ if (operation.responseFormat === "response") {
380
+ return {
381
+ data: response,
382
+ error: null
383
+ };
384
+ }
385
+ return {
386
+ data: await parseResponseData(response),
387
+ error: null
388
+ };
389
+ } catch (error) {
390
+ return {
391
+ data: null,
392
+ error: normalizeExecutionError(error)
393
+ };
394
+ }
395
+ }
396
+ __name(executeClientOperation, "executeClientOperation");
397
+ async function executeServerOperation(operation, input, options, requestOptions, integrationKey, source) {
398
+ try {
399
+ if (!operation.path) {
400
+ return {
401
+ data: null,
402
+ error: new Error(
403
+ "Integration API operation path is missing. Pass a path to api.get/post/... or wrap pathless methods with api.route(path, { ... })."
404
+ )
405
+ };
406
+ }
407
+ const serverRequestOptions = requestOptions && ("request" in requestOptions || "baseURL" in requestOptions || "forwardHeaders" in requestOptions) ? requestOptions : void 0;
408
+ const currentRequest = serverRequestOptions?.request instanceof Request ? serverRequestOptions.request : options.request instanceof Request ? options.request : resolveCurrentRequestLocal();
409
+ const request = resolveRequestLike(
410
+ serverRequestOptions?.request ?? options.request ?? currentRequest
411
+ );
412
+ const baseURL = resolveServerBaseURL(serverRequestOptions?.baseURL ?? options.baseURL, request);
413
+ const url = new URL(operation.path, baseURL);
414
+ appendQuery(url, input.query);
415
+ const headers = new Headers();
416
+ appendHeaders(
417
+ headers,
418
+ resolveForwardHeaders(
419
+ request,
420
+ serverRequestOptions?.forwardHeaders ?? options.forwardHeaders
421
+ )
422
+ );
423
+ appendHeaders(headers, options.headers);
424
+ appendHeaders(headers, operation.headers);
425
+ appendHeaders(headers, requestOptions?.headers);
426
+ headers.set("x-farm-integration-client", "1");
427
+ if (operation.responseFormat !== "response") {
428
+ headers.set("accept", "application/json");
429
+ }
430
+ const data = mergeIntegrationClientData(options.data, requestOptions?.data);
431
+ if (integrationKey) {
432
+ const runtime = "kind" in (source || {}) && source.kind === "farm-integration" ? getRegisteredIntegrationRuntimeLocal(integrationKey) || {
433
+ integration: source,
434
+ config: {},
435
+ isDev: process.env.NODE_ENV !== "production",
436
+ isProd: process.env.NODE_ENV === "production"
437
+ } : getRegisteredIntegrationRuntimeLocal(integrationKey);
438
+ if (runtime) {
439
+ const dispatchIntegrationRequest = resolveIntegrationRequestDispatcherLocal();
440
+ const directResponse = dispatchIntegrationRequest ? await dispatchIntegrationRequest(
441
+ runtime,
442
+ new Request(url.toString(), {
443
+ method: operation.method,
444
+ headers,
445
+ body: createBody(operation.bodyFormat, input.body, headers)
446
+ }),
447
+ {
448
+ currentRequest,
449
+ data,
450
+ internal: true
451
+ }
452
+ ) : null;
453
+ if (directResponse) {
454
+ return await finalizeOperationResponse(operation, directResponse);
455
+ }
456
+ }
457
+ }
458
+ appendIntegrationClientDataHeader(headers, data);
459
+ const response = await fetch(url.toString(), {
460
+ method: operation.method,
461
+ headers,
462
+ body: createBody(operation.bodyFormat, input.body, headers),
463
+ credentials: requestOptions?.credentials ?? operation.credentials ?? options.credentials ?? "include",
464
+ signal: requestOptions?.signal
465
+ });
466
+ return await finalizeOperationResponse(operation, response);
467
+ } catch (error) {
468
+ return {
469
+ data: null,
470
+ error: normalizeExecutionError(error)
471
+ };
472
+ }
473
+ }
474
+ __name(executeServerOperation, "executeServerOperation");
475
+ function createIntegrationClient(sources, options = {}) {
476
+ const rawSources = "integrations" in sources ? sources.integrations : sources;
477
+ const isServer = options.isServer === true;
478
+ const namespaces = Object.entries(rawSources).map(([key, source]) => {
479
+ const api = tryResolveSourceAPI(source);
480
+ if (!api) {
481
+ return null;
482
+ }
483
+ return [key, api, source];
484
+ }).filter(
485
+ (value) => value !== null
486
+ );
487
+ const cache = /* @__PURE__ */ new Map();
488
+ const integrationNamespaces = new Proxy(
489
+ {},
490
+ {
491
+ get(target, property) {
492
+ if (typeof property !== "string") {
493
+ return void 0;
494
+ }
495
+ if (Reflect.has(target, property)) {
496
+ return Reflect.get(target, property);
497
+ }
498
+ if (cache.has(property)) {
499
+ return cache.get(property);
500
+ }
501
+ const match = namespaces.find(([key]) => key === property);
502
+ if (!match) {
503
+ return void 0;
504
+ }
505
+ const namespace = isServer ? createServerNamespaceProxy(
506
+ match[0],
507
+ match[2],
508
+ match[1],
509
+ options
510
+ ) : createNamespaceProxy(match[1], options);
511
+ cache.set(property, namespace);
512
+ return namespace;
513
+ }
514
+ }
515
+ );
516
+ if ("integrations" in sources) {
517
+ Object.defineProperty(integrationNamespaces, "integrations", {
518
+ value: integrationNamespaces,
519
+ enumerable: false,
520
+ configurable: false,
521
+ writable: false
522
+ });
523
+ return integrationNamespaces;
524
+ }
525
+ return integrationNamespaces;
526
+ }
527
+ __name(createIntegrationClient, "createIntegrationClient");
528
+ function createAutomaticIntegrationAliases(isServer, options = {}) {
529
+ const cache = isServer ? /* @__PURE__ */ new Map() : null;
530
+ const integrationNamespaces = new Proxy(
531
+ {},
532
+ {
533
+ get(_target, property) {
534
+ if (typeof property !== "string") {
535
+ return void 0;
536
+ }
537
+ if (property === "integrations") {
538
+ return integrationNamespaces;
539
+ }
540
+ if (cache?.has(property)) {
541
+ return cache.get(property);
542
+ }
543
+ const namespaces = isServer ? resolveAutomaticServerNamespaces() : resolveAutomaticClientNamespaces();
544
+ const match = namespaces.find(([key]) => key === property);
545
+ if (!match) {
546
+ return void 0;
547
+ }
548
+ const namespace = isServer ? createServerNamespaceProxy(
549
+ match[0],
550
+ match[2],
551
+ match[1],
552
+ options
553
+ ) : createNamespaceProxy(match[1], options);
554
+ cache?.set(property, namespace);
555
+ return namespace;
556
+ }
557
+ }
558
+ );
559
+ Object.defineProperty(integrationNamespaces, "integrations", {
560
+ value: integrationNamespaces,
561
+ enumerable: false,
562
+ configurable: false,
563
+ writable: false
564
+ });
565
+ return integrationNamespaces;
566
+ }
567
+ __name(createAutomaticIntegrationAliases, "createAutomaticIntegrationAliases");
568
+ function integrationsClient(options = {}) {
569
+ return createAutomaticIntegrationAliases(
570
+ false,
571
+ options
572
+ );
573
+ }
574
+ __name(integrationsClient, "integrationsClient");
575
+ function integrationsServer(options = {}) {
576
+ return createAutomaticIntegrationAliases(true, {
577
+ ...options,
578
+ isServer: true
579
+ });
580
+ }
581
+ __name(integrationsServer, "integrationsServer");
582
+ function createIntegrationServerClient(sources, options = {}) {
583
+ return createIntegrationClient(sources, {
584
+ ...options,
585
+ isServer: true
586
+ });
587
+ }
588
+ __name(createIntegrationServerClient, "createIntegrationServerClient");
589
+ function createIntegrationApi(sources, options = {}) {
590
+ const client = createIntegrationClient(sources, options);
591
+ return {
592
+ ...client,
593
+ server(serverOptions = {}) {
594
+ return createIntegrationServerClient(sources, {
595
+ ...options,
596
+ ...serverOptions
597
+ });
598
+ }
599
+ };
600
+ }
601
+ __name(createIntegrationApi, "createIntegrationApi");
602
+ function isIntegrationClientOptionsInput(value) {
603
+ return !!value && typeof value === "object" && !Array.isArray(value) && ("baseURL" in value || "headers" in value || "credentials" in value || "data" in value || "isServer" in value);
604
+ }
605
+ __name(isIntegrationClientOptionsInput, "isIntegrationClientOptionsInput");
606
+ function resolveIntegrationServerOptions(clientOptions = {}, serverOptions = {}) {
607
+ const data = mergeIntegrationClientData(clientOptions.data, serverOptions.data);
608
+ return {
609
+ baseURL: clientOptions.baseURL,
610
+ headers: clientOptions.headers,
611
+ credentials: clientOptions.credentials,
612
+ ...serverOptions,
613
+ ...data ? { data } : {}
614
+ };
615
+ }
616
+ __name(resolveIntegrationServerOptions, "resolveIntegrationServerOptions");
617
+ function createIntegrationClients(sources, clientOptions, serverOptions) {
618
+ if (arguments.length === 0 || isIntegrationClientOptionsInput(sources)) {
619
+ const automaticClientOptions = isIntegrationClientOptionsInput(sources) ? sources : {};
620
+ const automaticServerOptions = arguments.length > 1 ? clientOptions : void 0;
621
+ return {
622
+ api: integrationsServer(
623
+ resolveIntegrationServerOptions(
624
+ automaticClientOptions,
625
+ automaticServerOptions
626
+ )
627
+ ),
628
+ apiClient: integrationsClient(automaticClientOptions)
629
+ };
630
+ }
631
+ const explicitSources = sources && "integrations" in sources ? sources.integrations : sources;
632
+ return {
633
+ api: createIntegrationServerClient(
634
+ {
635
+ integrations: explicitSources
636
+ },
637
+ resolveIntegrationServerOptions(clientOptions, serverOptions)
638
+ ),
639
+ apiClient: createIntegrationClient(
640
+ {
641
+ integrations: explicitSources
642
+ },
643
+ clientOptions
644
+ )
645
+ };
646
+ }
647
+ __name(createIntegrationClients, "createIntegrationClients");
648
+ function createIntegrations(sources, clientOptions, serverOptions) {
649
+ if (arguments.length === 0) {
650
+ return createIntegrationClients();
651
+ }
652
+ return createIntegrationClients(
653
+ sources,
654
+ clientOptions,
655
+ serverOptions
656
+ );
657
+ }
658
+ __name(createIntegrations, "createIntegrations");
659
+ function createClientSafeIntegrationAPI(api) {
660
+ if (!api) {
661
+ return void 0;
662
+ }
663
+ const entries = Object.entries(api).map(([key, value]) => {
664
+ if (isOperation(value)) {
665
+ return [
666
+ key,
667
+ {
668
+ kind: value.kind,
669
+ path: value.path,
670
+ method: value.method,
671
+ bodyFormat: value.bodyFormat,
672
+ responseFormat: value.responseFormat,
673
+ credentials: value.credentials,
674
+ isServer: value.isServer,
675
+ __pathless: value.__pathless
676
+ }
677
+ ];
678
+ }
679
+ if (value && typeof value === "object") {
680
+ return [key, createClientSafeIntegrationAPI(value)];
681
+ }
682
+ return [key, value];
683
+ });
684
+ return Object.fromEntries(entries);
685
+ }
686
+ __name(createClientSafeIntegrationAPI, "createClientSafeIntegrationAPI");
687
+ function getIntegrationAPIManifest() {
688
+ const manifestEntries = Object.entries(getRegisteredIntegrationsLocal()).map(([key, integration]) => {
689
+ const api = createClientSafeIntegrationAPI(integration.api);
690
+ return api ? [key, api] : null;
691
+ }).filter((value) => value !== null);
692
+ return Object.fromEntries(manifestEntries);
693
+ }
694
+ __name(getIntegrationAPIManifest, "getIntegrationAPIManifest");
695
+ function integrationClients(sources, clientOptions, serverOptions) {
696
+ if (arguments.length === 0) {
697
+ return createIntegrationClients();
698
+ }
699
+ return createIntegrationClients(
700
+ sources,
701
+ clientOptions,
702
+ serverOptions
703
+ );
704
+ }
705
+ __name(integrationClients, "integrationClients");
706
+ function resolveSingleNamespaceOperation(api) {
707
+ const entries = Object.entries(api);
708
+ if (entries.length !== 1) {
709
+ return null;
710
+ }
711
+ const [, value] = entries[0];
712
+ return isOperation(value) ? value : null;
713
+ }
714
+ __name(resolveSingleNamespaceOperation, "resolveSingleNamespaceOperation");
715
+ function createClientOperationCaller(operation, property, options) {
716
+ if (operation.isServer === true) {
717
+ return async () => {
718
+ throw new Error(
719
+ `Integration method "${property}" is registered with isServer: true and is only available from a server integration client.`
720
+ );
721
+ };
722
+ }
723
+ return async (input = {}, requestOptions) => {
724
+ if (typeof window === "undefined") {
725
+ throw new Error(
726
+ "Client integration API cannot be called on the server. Pass { isServer: true } to createIntegrationClient(...) during server rendering, or provide { isServer: true, request } outside it."
727
+ );
728
+ }
729
+ return executeClientOperation(operation, input, options, requestOptions);
730
+ };
731
+ }
732
+ __name(createClientOperationCaller, "createClientOperationCaller");
733
+ function createServerOperationCaller(operation, options, integrationKey, source) {
734
+ return async (input = {}, requestOptions) => {
735
+ if (typeof window !== "undefined") {
736
+ throw new Error(
737
+ "Server integration API cannot be called in the browser. Remove { isServer: true } and create a client integration API instead."
738
+ );
739
+ }
740
+ return executeServerOperation(
741
+ operation,
742
+ input,
743
+ options,
744
+ requestOptions,
745
+ integrationKey,
746
+ source
747
+ );
748
+ };
749
+ }
750
+ __name(createServerOperationCaller, "createServerOperationCaller");
751
+ function createNamespaceProxy(api, options) {
752
+ const cache = /* @__PURE__ */ new Map();
753
+ const directOperation = resolveSingleNamespaceOperation(api);
754
+ const target = directOperation ? createClientOperationCaller(directOperation, directOperation.method.toLowerCase(), options) : {};
755
+ return new Proxy(target, {
756
+ get(targetObject, property, receiver) {
757
+ if (typeof property !== "string") {
758
+ return Reflect.get(targetObject, property, receiver);
759
+ }
760
+ if (cache.has(property)) {
761
+ return cache.get(property);
762
+ }
763
+ const value = api[property];
764
+ if (!value) {
765
+ return Reflect.get(targetObject, property, receiver);
766
+ }
767
+ if (isOperation(value)) {
768
+ const caller = createClientOperationCaller(value, property, options);
769
+ cache.set(property, caller);
770
+ return caller;
771
+ }
772
+ const namespace = createNamespaceProxy(value, options);
773
+ cache.set(property, namespace);
774
+ return namespace;
775
+ }
776
+ });
777
+ }
778
+ __name(createNamespaceProxy, "createNamespaceProxy");
779
+ function createServerNamespaceProxy(integrationKey, source, api, options) {
780
+ const cache = /* @__PURE__ */ new Map();
781
+ const directOperation = resolveSingleNamespaceOperation(api);
782
+ const target = directOperation ? createServerOperationCaller(directOperation, options, integrationKey, source) : {};
783
+ return new Proxy(target, {
784
+ get(targetObject, property, receiver) {
785
+ if (typeof property !== "string") {
786
+ return Reflect.get(targetObject, property, receiver);
787
+ }
788
+ if (cache.has(property)) {
789
+ return cache.get(property);
790
+ }
791
+ const value = api[property];
792
+ if (!value) {
793
+ return Reflect.get(targetObject, property, receiver);
794
+ }
795
+ if (isOperation(value)) {
796
+ const caller = createServerOperationCaller(value, options, integrationKey, source);
797
+ cache.set(property, caller);
798
+ return caller;
799
+ }
800
+ const namespace = createServerNamespaceProxy(
801
+ integrationKey,
802
+ source,
803
+ value,
804
+ options
805
+ );
806
+ cache.set(property, namespace);
807
+ return namespace;
808
+ }
809
+ });
810
+ }
811
+ __name(createServerNamespaceProxy, "createServerNamespaceProxy");
812
+
813
+ // src/api/client.ts
814
+ var FARM_API_ROUTE_REF_SYMBOL = /* @__PURE__ */ Symbol.for("farm.api.route-ref");
815
+ var FARM_API_ROUTE_META_SYMBOL = /* @__PURE__ */ Symbol.for("farm.api.route-meta");
816
+ var _APIClientError = class _APIClientError extends Error {
817
+ constructor(code, data, options) {
818
+ super(options.message);
819
+ this.name = "APIClientError";
820
+ this.code = code;
821
+ this.data = data;
822
+ this.status = options.status;
823
+ this.response = options.response;
824
+ }
825
+ };
826
+ __name(_APIClientError, "APIClientError");
827
+ var APIClientError = _APIClientError;
828
+ function createAPIClient(options = {}) {
829
+ options ?? (options = {});
830
+ const baseURL = options.baseURL || (typeof window !== "undefined" ? window.location.origin : "http://localhost:3000");
831
+ const integrationOptions = options.integrations === false ? false : {
832
+ baseURL: options.baseURL,
833
+ headers: options.headers,
834
+ credentials: options.credentials,
835
+ ...typeof options.integrations === "object" ? options.integrations : {}
836
+ };
837
+ const rootAliases = integrationOptions === false ? void 0 : {
838
+ integrations: integrationsClient(integrationOptions)
839
+ };
840
+ const cacheState = getFarmClientDataCache();
841
+ const inflightState = /* @__PURE__ */ new Map();
842
+ const routeMeta = /* @__PURE__ */ new WeakMap();
843
+ let requestCounter = 0;
844
+ const fetchClient = /* @__PURE__ */ __name(async (path, requestOptions = {}) => {
845
+ const url = new URL(path, baseURL);
846
+ if (requestOptions.query) {
847
+ Object.entries(requestOptions.query).forEach(([key, value]) => {
848
+ if (value !== void 0 && value !== null) {
849
+ url.searchParams.set(key, String(value));
850
+ }
851
+ });
852
+ }
853
+ const headers = {
854
+ "Content-Type": "application/json",
855
+ ...options.headers,
856
+ ...requestOptions.headers
857
+ };
858
+ const fetchOptions = {
859
+ method: requestOptions.method || "GET",
860
+ headers
861
+ };
862
+ if (requestOptions.body !== void 0) {
863
+ if (isFormData(requestOptions.body)) {
864
+ deleteHeader(headers, "content-type");
865
+ fetchOptions.body = requestOptions.body;
866
+ } else {
867
+ fetchOptions.body = JSON.stringify(requestOptions.body);
868
+ }
869
+ }
870
+ const response = await fetch(url.toString(), fetchOptions);
871
+ applyFarmCacheInvalidations(
872
+ decodeFarmCacheInvalidations(response.headers?.get?.(FARM_CACHE_INVALIDATION_HEADER))
873
+ );
874
+ let data = void 0;
875
+ if (response.status !== 204 && response.status !== 205) {
876
+ data = isJSONStreamResponse(response) ? readJSONStream(response) : await response.json();
877
+ }
878
+ return { response, data };
879
+ }, "fetchClient");
880
+ const request = /* @__PURE__ */ __name(async (path, method, input = {}, clientOptions) => {
881
+ const methodUpper = method.toUpperCase();
882
+ const requestId = `${Date.now()}-${++requestCounter}`;
883
+ const cacheOptions = clientOptions?.cache ? {
884
+ ...options.cacheDefaults,
885
+ ...clientOptions.cache
886
+ } : void 0;
887
+ const configuredCacheKey = clientOptions?.key ?? cacheOptions?.key;
888
+ const cacheKey = normalizeFarmClientCacheKey(
889
+ configuredCacheKey ?? buildCacheKey(methodUpper, path, input, baseURL)
890
+ );
891
+ const now = Date.now();
892
+ const emitStatus = /* @__PURE__ */ __name((phase, payload) => {
893
+ clientOptions?.onStatus?.({
894
+ phase,
895
+ requestId,
896
+ method: methodUpper,
897
+ key: cacheKey,
898
+ input,
899
+ timestamp: Date.now(),
900
+ ...payload
901
+ });
902
+ }, "emitStatus");
903
+ const entry = getValidCacheEntry(cacheState, cacheKey, now);
904
+ const policy = cacheOptions?.policy ?? (cacheOptions ? "cache-first" : "network-only");
905
+ const staleTime = cacheOptions?.staleTime ?? 0;
906
+ const isCacheEnabled = Boolean(cacheOptions) && methodUpper === "GET";
907
+ const isStale = entry ? isEntryStale(entry, now) : true;
908
+ const applyOptimisticUpdates = /* @__PURE__ */ __name(() => {
909
+ if (!clientOptions?.optimistic?.update?.length) return [];
910
+ const snapshots = [];
911
+ for (const update of clientOptions.optimistic.update) {
912
+ const [target, targetInput, updater] = update.length === 2 ? [update[0], void 0, update[1]] : [update[0], update[1], update[2]];
913
+ const targetKey = resolveTargetKey(routeMeta, target, targetInput, baseURL);
914
+ if (!targetKey) continue;
915
+ const targetEntry = getValidCacheEntry(cacheState, targetKey, now);
916
+ const previousEntry = targetEntry ? { ...targetEntry } : void 0;
917
+ const previousData = targetEntry?.data;
918
+ const nextData = updater(previousData);
919
+ cacheState.set(targetKey, {
920
+ data: nextData,
921
+ updatedAt: now,
922
+ staleAt: targetEntry?.staleAt ?? now + (cacheOptions?.staleTime ?? options.cacheDefaults?.staleTime ?? 0),
923
+ gcAt: targetEntry?.gcAt ?? getGcAt(now, cacheOptions?.gcTime ?? options.cacheDefaults?.gcTime),
924
+ invalidatedAt: targetEntry?.invalidatedAt
925
+ });
926
+ snapshots.push({ key: targetKey, entry: previousEntry });
927
+ }
928
+ return snapshots;
929
+ }, "applyOptimisticUpdates");
930
+ const rollbackOptimisticUpdates = /* @__PURE__ */ __name((snapshots) => {
931
+ if (!clientOptions?.optimistic?.rollbackOnError) return;
932
+ for (const snapshot of snapshots) {
933
+ if (!snapshot.entry) {
934
+ cacheState.delete(snapshot.key);
935
+ continue;
936
+ }
937
+ cacheState.set(snapshot.key, { ...snapshot.entry });
938
+ }
939
+ }, "rollbackOptimisticUpdates");
940
+ const executeNetwork = /* @__PURE__ */ __name(async (opts) => {
941
+ const dedupeMs = cacheOptions?.dedupeMs ?? 0;
942
+ const inflight = inflightState.get(cacheKey);
943
+ const allowDedupe = isCacheEnabled && dedupeMs > 0;
944
+ if (allowDedupe && inflight && now - inflight.startedAt < dedupeMs) {
945
+ emitStatus("pending", { isBackground: opts?.isBackground, data: entry?.data });
946
+ const result2 = await inflight.promise;
947
+ if (result2.error) {
948
+ emitStatus("error", { error: result2.error, isBackground: opts?.isBackground });
949
+ if (opts?.callCallbacks !== false) {
950
+ clientOptions?.onError?.(result2.error);
951
+ }
952
+ } else {
953
+ emitStatus("success", { data: result2.data, isBackground: opts?.isBackground });
954
+ if (opts?.callCallbacks !== false) {
955
+ clientOptions?.onSuccess?.(result2.data);
956
+ }
957
+ }
958
+ return result2;
959
+ }
960
+ emitStatus(opts?.isBackground ? "revalidating" : "pending", {
961
+ isBackground: opts?.isBackground
962
+ });
963
+ const promise = (async () => {
964
+ const maxRetries = Math.max(0, clientOptions?.retry?.count ?? 0);
965
+ let attempt = 0;
966
+ while (true) {
967
+ clientOptions?.onRequest?.({
968
+ requestId,
969
+ method: methodUpper,
970
+ key: cacheKey,
971
+ path,
972
+ input,
973
+ attempt,
974
+ timestamp: Date.now()
975
+ });
976
+ try {
977
+ const { response, data } = await fetchClient(path, {
978
+ ...input,
979
+ method: methodUpper
980
+ });
981
+ const error = response.ok ? null : createResponseError2(response, data);
982
+ const responseEvent = {
983
+ requestId,
984
+ method: methodUpper,
985
+ key: cacheKey,
986
+ path,
987
+ input,
988
+ attempt,
989
+ timestamp: Date.now(),
990
+ response,
991
+ data: response.ok ? data : void 0,
992
+ error: error ?? void 0,
993
+ ok: response.ok,
994
+ status: response.status
995
+ };
996
+ clientOptions?.onResponse?.(response.ok ? data : void 0, error, responseEvent);
997
+ if (!error) {
998
+ return { data, error: null, key: cacheKey };
999
+ }
1000
+ if (attempt >= maxRetries) {
1001
+ return { data: void 0, error, key: cacheKey };
1002
+ }
1003
+ } catch (err) {
1004
+ const error = normalizeError(err);
1005
+ const responseEvent = {
1006
+ requestId,
1007
+ method: methodUpper,
1008
+ key: cacheKey,
1009
+ path,
1010
+ input,
1011
+ attempt,
1012
+ timestamp: Date.now(),
1013
+ error,
1014
+ ok: false
1015
+ };
1016
+ clientOptions?.onResponse?.(void 0, error, responseEvent);
1017
+ if (attempt >= maxRetries) {
1018
+ return { data: void 0, error, key: cacheKey };
1019
+ }
1020
+ }
1021
+ attempt += 1;
1022
+ const delay = typeof clientOptions?.retry?.delay === "function" ? clientOptions.retry.delay(attempt) : clientOptions?.retry?.delay ?? 0;
1023
+ if (delay > 0) {
1024
+ await new Promise((resolve) => setTimeout(resolve, delay));
1025
+ }
1026
+ }
1027
+ })();
1028
+ inflightState.set(cacheKey, { promise, startedAt: now });
1029
+ try {
1030
+ const result2 = await promise;
1031
+ if (!result2.error && isCacheEnabled && !isFarmAPIStream(result2.data)) {
1032
+ const updatedAt = Date.now();
1033
+ cacheState.set(cacheKey, {
1034
+ data: result2.data,
1035
+ updatedAt,
1036
+ staleAt: updatedAt + staleTime,
1037
+ gcAt: getGcAt(updatedAt, cacheOptions?.gcTime),
1038
+ invalidatedAt: void 0
1039
+ });
1040
+ }
1041
+ if (result2.error) {
1042
+ emitStatus("error", { error: result2.error, isBackground: opts?.isBackground });
1043
+ if (opts?.callCallbacks !== false) {
1044
+ clientOptions?.onError?.(result2.error);
1045
+ }
1046
+ } else {
1047
+ emitStatus("success", { data: result2.data, isBackground: opts?.isBackground });
1048
+ if (opts?.callCallbacks !== false) {
1049
+ clientOptions?.onSuccess?.(result2.data);
1050
+ }
1051
+ }
1052
+ return result2;
1053
+ } finally {
1054
+ inflightState.delete(cacheKey);
1055
+ }
1056
+ }, "executeNetwork");
1057
+ const invalidateTargets = /* @__PURE__ */ __name(async () => {
1058
+ if (!clientOptions?.invalidate) return;
1059
+ const invalidateOptions = Array.isArray(clientOptions.invalidate) ? { targets: clientOptions.invalidate, refetch: false } : {
1060
+ targets: clientOptions.invalidate.targets,
1061
+ refetch: clientOptions.invalidate.refetch ?? false
1062
+ };
1063
+ for (const target of invalidateOptions.targets) {
1064
+ const targetKey = resolveTargetKey(routeMeta, target, void 0, baseURL);
1065
+ if (!targetKey) continue;
1066
+ const existing = cacheState.get(targetKey);
1067
+ if (existing) {
1068
+ cacheState.set(targetKey, {
1069
+ ...existing,
1070
+ staleAt: 0,
1071
+ invalidatedAt: Date.now()
1072
+ });
1073
+ }
1074
+ emitStatus("invalidated", { key: targetKey });
1075
+ if (invalidateOptions.refetch && existing && targetKey === cacheKey) {
1076
+ void executeNetwork({ isBackground: true, callCallbacks: false });
1077
+ }
1078
+ }
1079
+ }, "invalidateTargets");
1080
+ const optimisticSnapshots = applyOptimisticUpdates();
1081
+ if (isCacheEnabled) {
1082
+ if (entry && !isStale && policy !== "network-only") {
1083
+ emitStatus("success", { data: entry.data });
1084
+ clientOptions?.onSuccess?.(entry.data);
1085
+ clientOptions?.onSettled?.(entry.data, null);
1086
+ return { data: entry.data, error: null, key: cacheKey };
1087
+ }
1088
+ if (entry && isStale && policy === "stale-while-revalidate") {
1089
+ emitStatus("success", { data: entry.data });
1090
+ clientOptions?.onSuccess?.(entry.data);
1091
+ clientOptions?.onSettled?.(entry.data, null);
1092
+ void executeNetwork({ isBackground: true, callCallbacks: false });
1093
+ return { data: entry.data, error: null, key: cacheKey };
1094
+ }
1095
+ }
1096
+ const result = await executeNetwork();
1097
+ if (result.error) {
1098
+ rollbackOptimisticUpdates(optimisticSnapshots);
1099
+ }
1100
+ await invalidateTargets();
1101
+ clientOptions?.onSettled?.(result.data, result.error);
1102
+ return result;
1103
+ }, "request");
1104
+ return createNestedProxy(
1105
+ [],
1106
+ request,
1107
+ routeMeta,
1108
+ baseURL,
1109
+ options.baseURL === void 0,
1110
+ rootAliases
1111
+ );
1112
+ }
1113
+ __name(createAPIClient, "createAPIClient");
1114
+ function createNestedProxy(path, client, routeMeta, baseURL, sameOrigin, rootAliases) {
1115
+ const target = /* @__PURE__ */ __name(() => {
1116
+ }, "target");
1117
+ const proxy = new Proxy(target, {
1118
+ // When accessing a property (api.hello)
1119
+ get(_target, prop) {
1120
+ if (prop === FARM_API_ROUTE_REF_SYMBOL) {
1121
+ return path.length > 0;
1122
+ }
1123
+ if (prop === FARM_API_ROUTE_META_SYMBOL) {
1124
+ const metadata = resolveRouteMeta({ path, baseURL });
1125
+ return Object.freeze({
1126
+ path: metadata.routePath,
1127
+ method: metadata.method,
1128
+ baseURL,
1129
+ sameOrigin
1130
+ });
1131
+ }
1132
+ if (path.length === 0 && typeof prop === "string" && rootAliases && prop in rootAliases) {
1133
+ return rootAliases[prop];
1134
+ }
1135
+ if (typeof prop !== "string") {
1136
+ return Reflect.get(_target, prop);
1137
+ }
1138
+ return createNestedProxy(
1139
+ [...path, prop],
1140
+ client,
1141
+ routeMeta,
1142
+ baseURL,
1143
+ sameOrigin,
1144
+ rootAliases
1145
+ );
1146
+ },
1147
+ // When calling as a function
1148
+ apply(_target, _thisArg, args) {
1149
+ const lastPart = path[path.length - 1];
1150
+ const httpMethods = ["get", "post", "put", "delete", "patch", "options", "head"];
1151
+ if (httpMethods.includes(lastPart)) {
1152
+ const routePath = "/api/" + path.slice(0, -1).join("/");
1153
+ const method = lastPart.toUpperCase();
1154
+ const [options, clientOptions] = args;
1155
+ return client(routePath, method, options, clientOptions);
1156
+ } else {
1157
+ const routePath = "/api/" + path.join("/");
1158
+ const [options, clientOptions] = args;
1159
+ return client(routePath, options?.method || "GET", options, clientOptions);
1160
+ }
1161
+ }
1162
+ });
1163
+ routeMeta.set(proxy, { path: [...path], baseURL });
1164
+ return proxy;
1165
+ }
1166
+ __name(createNestedProxy, "createNestedProxy");
1167
+ function isAPIRouteRef(value) {
1168
+ return typeof value === "function" && value[FARM_API_ROUTE_REF_SYMBOL] === true;
1169
+ }
1170
+ __name(isAPIRouteRef, "isAPIRouteRef");
1171
+ function getAPIRouteRefMetadata(value) {
1172
+ if (!isAPIRouteRef(value)) return null;
1173
+ const metadata = value[FARM_API_ROUTE_META_SYMBOL];
1174
+ if (!metadata || typeof metadata !== "object") return null;
1175
+ const candidate = metadata;
1176
+ if (typeof candidate.path !== "string" || typeof candidate.method !== "string" || typeof candidate.baseURL !== "string" || typeof candidate.sameOrigin !== "boolean") {
1177
+ return null;
1178
+ }
1179
+ return {
1180
+ path: candidate.path,
1181
+ method: candidate.method,
1182
+ baseURL: candidate.baseURL,
1183
+ sameOrigin: candidate.sameOrigin
1184
+ };
1185
+ }
1186
+ __name(getAPIRouteRefMetadata, "getAPIRouteRefMetadata");
1187
+ function createServerAPIClient(endpoints, options = {}) {
1188
+ if (options.integrations === false || Object.prototype.hasOwnProperty.call(endpoints, "integrations")) {
1189
+ return endpoints;
1190
+ }
1191
+ Object.defineProperty(endpoints, "integrations", {
1192
+ get() {
1193
+ return integrationsServer(
1194
+ typeof options.integrations === "object" ? options.integrations : {}
1195
+ );
1196
+ },
1197
+ enumerable: false,
1198
+ configurable: true
1199
+ });
1200
+ return endpoints;
1201
+ }
1202
+ __name(createServerAPIClient, "createServerAPIClient");
1203
+ function buildCacheKey(method, path, input, baseURL) {
1204
+ const keyInput = input && typeof input === "object" ? { query: input.query, body: input.body } : input;
1205
+ const url = new URL(path, baseURL);
1206
+ return `${method}:${url.origin}${url.pathname}:${stableStringify(keyInput ?? {})}`;
1207
+ }
1208
+ __name(buildCacheKey, "buildCacheKey");
1209
+ function stableStringify(value) {
1210
+ if (value === null || value === void 0) return String(value);
1211
+ if (value instanceof Date) return value.toISOString();
1212
+ if (typeof value !== "object") return JSON.stringify(value);
1213
+ if (Array.isArray(value)) {
1214
+ return `[${value.map((item) => stableStringify(item)).join(",")}]`;
1215
+ }
1216
+ const keys = Object.keys(value).sort();
1217
+ const entries = keys.map((key) => `${JSON.stringify(key)}:${stableStringify(value[key])}`);
1218
+ return `{${entries.join(",")}}`;
1219
+ }
1220
+ __name(stableStringify, "stableStringify");
1221
+ function getGcAt(now, gcTime) {
1222
+ if (gcTime === void 0) return void 0;
1223
+ if (!Number.isFinite(gcTime) || gcTime <= 0) return now;
1224
+ return now + gcTime;
1225
+ }
1226
+ __name(getGcAt, "getGcAt");
1227
+ function getValidCacheEntry(cacheState, key, now) {
1228
+ const entry = cacheState.get(key);
1229
+ if (!entry) return void 0;
1230
+ if (entry.gcAt !== void 0 && now >= entry.gcAt) {
1231
+ cacheState.delete(key);
1232
+ return void 0;
1233
+ }
1234
+ return entry;
1235
+ }
1236
+ __name(getValidCacheEntry, "getValidCacheEntry");
1237
+ function isEntryStale(entry, now) {
1238
+ if (entry.invalidatedAt !== void 0) return true;
1239
+ return now >= entry.staleAt;
1240
+ }
1241
+ __name(isEntryStale, "isEntryStale");
1242
+ function resolveTargetKey(routeMeta, target, input, baseURL = "http://localhost:3000") {
1243
+ if (!target) return null;
1244
+ if (typeof target === "string") return target;
1245
+ if (typeof target === "function") {
1246
+ const meta = routeMeta.get(target);
1247
+ if (!meta) return null;
1248
+ const { method, routePath } = resolveRouteMeta(meta);
1249
+ return buildCacheKey(method, routePath, input ?? {}, meta.baseURL);
1250
+ }
1251
+ if (Array.isArray(target)) {
1252
+ const [route, routeInput] = target;
1253
+ if (typeof route === "function") {
1254
+ return resolveTargetKey(routeMeta, route, routeInput, baseURL);
1255
+ }
1256
+ return normalizeFarmClientCacheKey(target);
1257
+ }
1258
+ if ("key" in target) return normalizeFarmClientCacheKey(target.key);
1259
+ if ("path" in target) {
1260
+ const method = target.method ?? "GET";
1261
+ return buildCacheKey(method, target.path, target.input ?? {}, baseURL);
1262
+ }
1263
+ return null;
1264
+ }
1265
+ __name(resolveTargetKey, "resolveTargetKey");
1266
+ function resolveRouteMeta(meta) {
1267
+ const httpMethods = ["get", "post", "put", "delete", "patch", "options", "head"];
1268
+ const lastPart = meta.path[meta.path.length - 1];
1269
+ if (lastPart && httpMethods.includes(lastPart)) {
1270
+ return {
1271
+ routePath: "/api/" + meta.path.slice(0, -1).join("/"),
1272
+ method: lastPart.toUpperCase()
1273
+ };
1274
+ }
1275
+ return {
1276
+ routePath: "/api/" + meta.path.join("/"),
1277
+ method: "GET"
1278
+ };
1279
+ }
1280
+ __name(resolveRouteMeta, "resolveRouteMeta");
1281
+ function normalizeError(error) {
1282
+ if (error instanceof APIClientError) return error;
1283
+ const normalized = new APIClientError("network_error", void 0, {
1284
+ status: 0,
1285
+ message: error instanceof Error ? error.message : typeof error === "string" ? error : "Network request failed"
1286
+ });
1287
+ normalized.cause = error;
1288
+ return normalized;
1289
+ }
1290
+ __name(normalizeError, "normalizeError");
1291
+ function isFormData(value) {
1292
+ return typeof value === "object" && value !== null && (typeof FormData !== "undefined" && value instanceof FormData || Object.prototype.toString.call(value) === "[object FormData]" && typeof value.entries === "function");
1293
+ }
1294
+ __name(isFormData, "isFormData");
1295
+ function deleteHeader(headers, name) {
1296
+ const normalized = name.toLowerCase();
1297
+ for (const key of Object.keys(headers)) {
1298
+ if (key.toLowerCase() === normalized) delete headers[key];
1299
+ }
1300
+ }
1301
+ __name(deleteHeader, "deleteHeader");
1302
+ function createResponseError2(response, data) {
1303
+ const expected = readEndpointErrorEnvelope(data);
1304
+ if (expected) {
1305
+ return new APIClientError(expected.code, expected.data, {
1306
+ status: response.status,
1307
+ message: expected.message,
1308
+ response
1309
+ });
1310
+ }
1311
+ return new APIClientError("http_error", data, {
1312
+ status: response.status,
1313
+ message: `HTTP ${response.status}: ${response.statusText}`,
1314
+ response
1315
+ });
1316
+ }
1317
+ __name(createResponseError2, "createResponseError");
1318
+ function readEndpointErrorEnvelope(data) {
1319
+ if (!data || typeof data !== "object") return null;
1320
+ const error = data.error;
1321
+ if (!error || typeof error !== "object") return null;
1322
+ const code = error.code;
1323
+ const message = error.message;
1324
+ if (typeof code !== "string" || typeof message !== "string") return null;
1325
+ return {
1326
+ code,
1327
+ message,
1328
+ data: error.data
1329
+ };
1330
+ }
1331
+ __name(readEndpointErrorEnvelope, "readEndpointErrorEnvelope");
1332
+
1333
+ export {
1334
+ IntegrationClientError,
1335
+ createIntegrationClient,
1336
+ integrationsClient,
1337
+ integrationsServer,
1338
+ createIntegrationServerClient,
1339
+ createIntegrationApi,
1340
+ createIntegrationClients,
1341
+ createIntegrations,
1342
+ getIntegrationAPIManifest,
1343
+ integrationClients,
1344
+ FARM_API_ROUTE_REF_SYMBOL,
1345
+ FARM_API_ROUTE_META_SYMBOL,
1346
+ APIClientError,
1347
+ createAPIClient,
1348
+ isAPIRouteRef,
1349
+ getAPIRouteRefMetadata,
1350
+ createServerAPIClient
1351
+ };
1352
+ //# sourceMappingURL=chunk-W2CRQFF6.mjs.map