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

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 (424) hide show
  1. package/package.json +1 -1
  2. package/dist/after.cjs +0 -227
  3. package/dist/after.cjs.map +0 -1
  4. package/dist/after.d.mts +0 -25
  5. package/dist/after.d.ts +0 -25
  6. package/dist/after.mjs +0 -14
  7. package/dist/after.mjs.map +0 -1
  8. package/dist/agent-runtime.cjs +0 -2379
  9. package/dist/agent-runtime.cjs.map +0 -1
  10. package/dist/agent-runtime.d.mts +0 -94
  11. package/dist/agent-runtime.d.ts +0 -94
  12. package/dist/agent-runtime.mjs +0 -479
  13. package/dist/agent-runtime.mjs.map +0 -1
  14. package/dist/api/route-manager.d.mts +0 -66
  15. package/dist/api/route-manager.d.ts +0 -66
  16. package/dist/api/runtime.d.mts +0 -3
  17. package/dist/api/runtime.d.ts +0 -3
  18. package/dist/api.cjs +0 -4100
  19. package/dist/api.cjs.map +0 -1
  20. package/dist/api.d.mts +0 -48
  21. package/dist/api.d.ts +0 -48
  22. package/dist/api.mjs +0 -93
  23. package/dist/api.mjs.map +0 -1
  24. package/dist/app-BjN-da13.d.ts +0 -300
  25. package/dist/app-CakAr8Be.d.mts +0 -300
  26. package/dist/app-markdown.cjs +0 -220
  27. package/dist/app-markdown.cjs.map +0 -1
  28. package/dist/app-markdown.d.mts +0 -22
  29. package/dist/app-markdown.d.ts +0 -22
  30. package/dist/app-markdown.mjs +0 -26
  31. package/dist/app-markdown.mjs.map +0 -1
  32. package/dist/cache.cjs +0 -945
  33. package/dist/cache.cjs.map +0 -1
  34. package/dist/cache.d.mts +0 -192
  35. package/dist/cache.d.ts +0 -192
  36. package/dist/cache.mjs +0 -46
  37. package/dist/cache.mjs.map +0 -1
  38. package/dist/chunk-2CUKEMVR.mjs +0 -872
  39. package/dist/chunk-2CUKEMVR.mjs.map +0 -1
  40. package/dist/chunk-2ED5Q2GH.mjs +0 -422
  41. package/dist/chunk-2ED5Q2GH.mjs.map +0 -1
  42. package/dist/chunk-2NHCNRF6.mjs +0 -6241
  43. package/dist/chunk-2NHCNRF6.mjs.map +0 -1
  44. package/dist/chunk-32W4QEJP.mjs +0 -158
  45. package/dist/chunk-32W4QEJP.mjs.map +0 -1
  46. package/dist/chunk-3XNTL3FQ.mjs +0 -452
  47. package/dist/chunk-3XNTL3FQ.mjs.map +0 -1
  48. package/dist/chunk-44ZCFSKE.mjs +0 -84
  49. package/dist/chunk-44ZCFSKE.mjs.map +0 -1
  50. package/dist/chunk-4S3ORGFA.mjs +0 -44
  51. package/dist/chunk-4S3ORGFA.mjs.map +0 -1
  52. package/dist/chunk-5BY76U2M.mjs +0 -1
  53. package/dist/chunk-5BY76U2M.mjs.map +0 -1
  54. package/dist/chunk-5ZGPRGWV.mjs +0 -136
  55. package/dist/chunk-5ZGPRGWV.mjs.map +0 -1
  56. package/dist/chunk-65A7QIKI.mjs +0 -142
  57. package/dist/chunk-65A7QIKI.mjs.map +0 -1
  58. package/dist/chunk-74YTBPTY.mjs +0 -450
  59. package/dist/chunk-74YTBPTY.mjs.map +0 -1
  60. package/dist/chunk-7HO6AEOP.mjs +0 -74
  61. package/dist/chunk-7HO6AEOP.mjs.map +0 -1
  62. package/dist/chunk-7MABZJIM.mjs +0 -29
  63. package/dist/chunk-7MABZJIM.mjs.map +0 -1
  64. package/dist/chunk-7N62DNSO.mjs +0 -41
  65. package/dist/chunk-7N62DNSO.mjs.map +0 -1
  66. package/dist/chunk-7ZY5AIJO.mjs +0 -161
  67. package/dist/chunk-7ZY5AIJO.mjs.map +0 -1
  68. package/dist/chunk-A2LUXHD2.mjs +0 -7631
  69. package/dist/chunk-A2LUXHD2.mjs.map +0 -1
  70. package/dist/chunk-ALCLXXTY.mjs +0 -187
  71. package/dist/chunk-ALCLXXTY.mjs.map +0 -1
  72. package/dist/chunk-AZ7YUVNR.mjs +0 -65
  73. package/dist/chunk-AZ7YUVNR.mjs.map +0 -1
  74. package/dist/chunk-B232I2GP.mjs +0 -163
  75. package/dist/chunk-B232I2GP.mjs.map +0 -1
  76. package/dist/chunk-BHG3LVHH.mjs +0 -176
  77. package/dist/chunk-BHG3LVHH.mjs.map +0 -1
  78. package/dist/chunk-C2ROET2V.mjs +0 -718
  79. package/dist/chunk-C2ROET2V.mjs.map +0 -1
  80. package/dist/chunk-C3DLZMBU.mjs +0 -597
  81. package/dist/chunk-C3DLZMBU.mjs.map +0 -1
  82. package/dist/chunk-CGILA3WO.mjs +0 -14
  83. package/dist/chunk-CGILA3WO.mjs.map +0 -1
  84. package/dist/chunk-E2MPIBRE.mjs +0 -149
  85. package/dist/chunk-E2MPIBRE.mjs.map +0 -1
  86. package/dist/chunk-E6EPN5BT.mjs +0 -203
  87. package/dist/chunk-E6EPN5BT.mjs.map +0 -1
  88. package/dist/chunk-EEABSBKK.mjs +0 -10
  89. package/dist/chunk-EEABSBKK.mjs.map +0 -1
  90. package/dist/chunk-EJ7T4TPB.mjs +0 -622
  91. package/dist/chunk-EJ7T4TPB.mjs.map +0 -1
  92. package/dist/chunk-FQYDHKKU.mjs +0 -128
  93. package/dist/chunk-FQYDHKKU.mjs.map +0 -1
  94. package/dist/chunk-FRPWCMMG.mjs +0 -299
  95. package/dist/chunk-FRPWCMMG.mjs.map +0 -1
  96. package/dist/chunk-GN72QAIH.mjs +0 -146
  97. package/dist/chunk-GN72QAIH.mjs.map +0 -1
  98. package/dist/chunk-GQVGIUSN.mjs +0 -149
  99. package/dist/chunk-GQVGIUSN.mjs.map +0 -1
  100. package/dist/chunk-GS6K5OCM.mjs +0 -407
  101. package/dist/chunk-GS6K5OCM.mjs.map +0 -1
  102. package/dist/chunk-GXASWWJU.mjs +0 -364
  103. package/dist/chunk-GXASWWJU.mjs.map +0 -1
  104. package/dist/chunk-GY2STC2S.mjs +0 -180
  105. package/dist/chunk-GY2STC2S.mjs.map +0 -1
  106. package/dist/chunk-H2FA2SBS.mjs +0 -51
  107. package/dist/chunk-H2FA2SBS.mjs.map +0 -1
  108. package/dist/chunk-HNIQFZKB.mjs +0 -3550
  109. package/dist/chunk-HNIQFZKB.mjs.map +0 -1
  110. package/dist/chunk-ITN462YM.mjs +0 -98
  111. package/dist/chunk-ITN462YM.mjs.map +0 -1
  112. package/dist/chunk-J23HNLFY.mjs +0 -72
  113. package/dist/chunk-J23HNLFY.mjs.map +0 -1
  114. package/dist/chunk-J4FNJ5IU.mjs +0 -179
  115. package/dist/chunk-J4FNJ5IU.mjs.map +0 -1
  116. package/dist/chunk-J5YWQVI5.mjs +0 -211
  117. package/dist/chunk-J5YWQVI5.mjs.map +0 -1
  118. package/dist/chunk-JDEOUK5V.mjs +0 -427
  119. package/dist/chunk-JDEOUK5V.mjs.map +0 -1
  120. package/dist/chunk-JK25YEN6.mjs +0 -219
  121. package/dist/chunk-JK25YEN6.mjs.map +0 -1
  122. package/dist/chunk-K4667E2Q.mjs +0 -1916
  123. package/dist/chunk-K4667E2Q.mjs.map +0 -1
  124. package/dist/chunk-LGHEOHBU.mjs +0 -218
  125. package/dist/chunk-LGHEOHBU.mjs.map +0 -1
  126. package/dist/chunk-LLC7BNXW.mjs +0 -275
  127. package/dist/chunk-LLC7BNXW.mjs.map +0 -1
  128. package/dist/chunk-LM2YNO4U.mjs +0 -24
  129. package/dist/chunk-LM2YNO4U.mjs.map +0 -1
  130. package/dist/chunk-MIUW47JX.mjs +0 -639
  131. package/dist/chunk-MIUW47JX.mjs.map +0 -1
  132. package/dist/chunk-NM3CRAAL.mjs +0 -467
  133. package/dist/chunk-NM3CRAAL.mjs.map +0 -1
  134. package/dist/chunk-NNLCAVB6.mjs +0 -391
  135. package/dist/chunk-NNLCAVB6.mjs.map +0 -1
  136. package/dist/chunk-P7QDS5AT.mjs +0 -191
  137. package/dist/chunk-P7QDS5AT.mjs.map +0 -1
  138. package/dist/chunk-PFE6GMNE.mjs +0 -603
  139. package/dist/chunk-PFE6GMNE.mjs.map +0 -1
  140. package/dist/chunk-QGOHVJ6J.mjs +0 -63
  141. package/dist/chunk-QGOHVJ6J.mjs.map +0 -1
  142. package/dist/chunk-QGQX7SFC.mjs +0 -180
  143. package/dist/chunk-QGQX7SFC.mjs.map +0 -1
  144. package/dist/chunk-QKVUNGAH.mjs +0 -39
  145. package/dist/chunk-QKVUNGAH.mjs.map +0 -1
  146. package/dist/chunk-QM746KUO.mjs +0 -56
  147. package/dist/chunk-QM746KUO.mjs.map +0 -1
  148. package/dist/chunk-QTZZ2ISQ.mjs +0 -753
  149. package/dist/chunk-QTZZ2ISQ.mjs.map +0 -1
  150. package/dist/chunk-RBRLLZL5.mjs +0 -81
  151. package/dist/chunk-RBRLLZL5.mjs.map +0 -1
  152. package/dist/chunk-RHIFZZUI.mjs +0 -69
  153. package/dist/chunk-RHIFZZUI.mjs.map +0 -1
  154. package/dist/chunk-RSKVYESE.mjs +0 -187
  155. package/dist/chunk-RSKVYESE.mjs.map +0 -1
  156. package/dist/chunk-SCFX4UTD.mjs +0 -28
  157. package/dist/chunk-SCFX4UTD.mjs.map +0 -1
  158. package/dist/chunk-SL6HTIOK.mjs +0 -66
  159. package/dist/chunk-SL6HTIOK.mjs.map +0 -1
  160. package/dist/chunk-SPBBQLXI.mjs +0 -207
  161. package/dist/chunk-SPBBQLXI.mjs.map +0 -1
  162. package/dist/chunk-T4QJQK76.mjs +0 -459
  163. package/dist/chunk-T4QJQK76.mjs.map +0 -1
  164. package/dist/chunk-TQAEEJB4.mjs +0 -157
  165. package/dist/chunk-TQAEEJB4.mjs.map +0 -1
  166. package/dist/chunk-UB5UOSHB.mjs +0 -458
  167. package/dist/chunk-UB5UOSHB.mjs.map +0 -1
  168. package/dist/chunk-USWZZUEH.mjs +0 -25
  169. package/dist/chunk-USWZZUEH.mjs.map +0 -1
  170. package/dist/chunk-UVCIEUJC.mjs +0 -16
  171. package/dist/chunk-UVCIEUJC.mjs.map +0 -1
  172. package/dist/chunk-UXUAWNO5.mjs +0 -396
  173. package/dist/chunk-UXUAWNO5.mjs.map +0 -1
  174. package/dist/chunk-V3XURYJO.mjs +0 -756
  175. package/dist/chunk-V3XURYJO.mjs.map +0 -1
  176. package/dist/chunk-V6WE6JSZ.mjs +0 -352
  177. package/dist/chunk-V6WE6JSZ.mjs.map +0 -1
  178. package/dist/chunk-V7RBCSDJ.mjs +0 -170
  179. package/dist/chunk-V7RBCSDJ.mjs.map +0 -1
  180. package/dist/chunk-VCANOYFI.mjs +0 -588
  181. package/dist/chunk-VCANOYFI.mjs.map +0 -1
  182. package/dist/chunk-VY2UYN5R.mjs +0 -224
  183. package/dist/chunk-VY2UYN5R.mjs.map +0 -1
  184. package/dist/chunk-W2CRQFF6.mjs +0 -1352
  185. package/dist/chunk-W2CRQFF6.mjs.map +0 -1
  186. package/dist/chunk-WZ5QFROO.mjs +0 -23
  187. package/dist/chunk-WZ5QFROO.mjs.map +0 -1
  188. package/dist/chunk-XIVV5IWN.mjs +0 -541
  189. package/dist/chunk-XIVV5IWN.mjs.map +0 -1
  190. package/dist/chunk-YW7OBE6Q.mjs +0 -119
  191. package/dist/chunk-YW7OBE6Q.mjs.map +0 -1
  192. package/dist/chunk-Z5CQMP54.mjs +0 -365
  193. package/dist/chunk-Z5CQMP54.mjs.map +0 -1
  194. package/dist/chunk-ZBE6MLHL.mjs +0 -230
  195. package/dist/chunk-ZBE6MLHL.mjs.map +0 -1
  196. package/dist/chunk-ZZ57EH5Z.mjs +0 -173
  197. package/dist/chunk-ZZ57EH5Z.mjs.map +0 -1
  198. package/dist/client-BT1mFQas.d.mts +0 -447
  199. package/dist/client-Nn0q4eO4.d.ts +0 -447
  200. package/dist/client-cache-CIlyBlmx.d.ts +0 -6
  201. package/dist/client-cache-D-EZ7XVW.d.mts +0 -6
  202. package/dist/client-plugins-Cw4qUGsw.d.ts +0 -1855
  203. package/dist/client-plugins-DQQ1adXM.d.mts +0 -1855
  204. package/dist/client-plugins.cjs +0 -415
  205. package/dist/client-plugins.cjs.map +0 -1
  206. package/dist/client-plugins.d.mts +0 -22
  207. package/dist/client-plugins.d.ts +0 -22
  208. package/dist/client-plugins.mjs +0 -10
  209. package/dist/client-plugins.mjs.map +0 -1
  210. package/dist/client.cjs +0 -5402
  211. package/dist/client.cjs.map +0 -1
  212. package/dist/client.d.mts +0 -447
  213. package/dist/client.d.ts +0 -447
  214. package/dist/client.mjs +0 -110
  215. package/dist/client.mjs.map +0 -1
  216. package/dist/config.cjs +0 -38
  217. package/dist/config.cjs.map +0 -1
  218. package/dist/config.d.mts +0 -29
  219. package/dist/config.d.ts +0 -29
  220. package/dist/config.mjs +0 -10
  221. package/dist/config.mjs.map +0 -1
  222. package/dist/cron.cjs +0 -406
  223. package/dist/cron.cjs.map +0 -1
  224. package/dist/cron.d.mts +0 -78
  225. package/dist/cron.d.ts +0 -78
  226. package/dist/cron.mjs +0 -30
  227. package/dist/cron.mjs.map +0 -1
  228. package/dist/deferred.cjs +0 -438
  229. package/dist/deferred.cjs.map +0 -1
  230. package/dist/deferred.d.mts +0 -42
  231. package/dist/deferred.d.ts +0 -42
  232. package/dist/deferred.mjs +0 -28
  233. package/dist/deferred.mjs.map +0 -1
  234. package/dist/deployment.cjs +0 -199
  235. package/dist/deployment.cjs.map +0 -1
  236. package/dist/deployment.d.mts +0 -34
  237. package/dist/deployment.d.ts +0 -34
  238. package/dist/deployment.mjs +0 -38
  239. package/dist/deployment.mjs.map +0 -1
  240. package/dist/devtools-LVC3VB5P.mjs +0 -370
  241. package/dist/devtools-LVC3VB5P.mjs.map +0 -1
  242. package/dist/devtools-client-3XRTBND5.mjs +0 -216
  243. package/dist/devtools-client-3XRTBND5.mjs.map +0 -1
  244. package/dist/devtools-ui-NJKFORTG.mjs +0 -1349
  245. package/dist/devtools-ui-NJKFORTG.mjs.map +0 -1
  246. package/dist/docs.cjs +0 -5553
  247. package/dist/docs.cjs.map +0 -1
  248. package/dist/docs.d.mts +0 -69
  249. package/dist/docs.d.ts +0 -69
  250. package/dist/docs.mjs +0 -46
  251. package/dist/docs.mjs.map +0 -1
  252. package/dist/env-types.cjs +0 -223
  253. package/dist/env-types.cjs.map +0 -1
  254. package/dist/env-types.d.mts +0 -11
  255. package/dist/env-types.d.ts +0 -11
  256. package/dist/env-types.mjs +0 -9
  257. package/dist/env-types.mjs.map +0 -1
  258. package/dist/env.cjs +0 -215
  259. package/dist/env.cjs.map +0 -1
  260. package/dist/env.d.mts +0 -45
  261. package/dist/env.d.ts +0 -45
  262. package/dist/env.mjs +0 -22
  263. package/dist/env.mjs.map +0 -1
  264. package/dist/environment/vite.d.mts +0 -22
  265. package/dist/environment/vite.d.ts +0 -22
  266. package/dist/environment.cjs +0 -96
  267. package/dist/environment.cjs.map +0 -1
  268. package/dist/environment.d.mts +0 -18
  269. package/dist/environment.d.ts +0 -18
  270. package/dist/environment.mjs +0 -14
  271. package/dist/environment.mjs.map +0 -1
  272. package/dist/headers.cjs +0 -126
  273. package/dist/headers.cjs.map +0 -1
  274. package/dist/headers.d.mts +0 -22
  275. package/dist/headers.d.ts +0 -22
  276. package/dist/headers.mjs +0 -12
  277. package/dist/headers.mjs.map +0 -1
  278. package/dist/i18n/client.d.mts +0 -32
  279. package/dist/i18n/client.d.ts +0 -32
  280. package/dist/i18n/index.d.mts +0 -20
  281. package/dist/i18n/index.d.ts +0 -20
  282. package/dist/i18n/server.d.mts +0 -30
  283. package/dist/i18n/server.d.ts +0 -30
  284. package/dist/image/server.d.mts +0 -37
  285. package/dist/image/server.d.ts +0 -37
  286. package/dist/image/sharp.d.mts +0 -7
  287. package/dist/image/sharp.d.ts +0 -7
  288. package/dist/image-config-Duob7wER.d.mts +0 -50
  289. package/dist/image-config-Duob7wER.d.ts +0 -50
  290. package/dist/image.cjs +0 -209
  291. package/dist/image.cjs.map +0 -1
  292. package/dist/image.d.mts +0 -39
  293. package/dist/image.d.ts +0 -39
  294. package/dist/image.mjs +0 -165
  295. package/dist/image.mjs.map +0 -1
  296. package/dist/index.cjs +0 -41822
  297. package/dist/index.cjs.map +0 -1
  298. package/dist/index.d.mts +0 -451
  299. package/dist/index.d.ts +0 -451
  300. package/dist/index.mjs +0 -973
  301. package/dist/index.mjs.map +0 -1
  302. package/dist/integration-api-CHT2OKAf.d.mts +0 -93
  303. package/dist/integration-api-CHT2OKAf.d.ts +0 -93
  304. package/dist/integration-orm-GQLGU66X.mjs +0 -13
  305. package/dist/integration-orm-GQLGU66X.mjs.map +0 -1
  306. package/dist/integrations.cjs +0 -2820
  307. package/dist/integrations.cjs.map +0 -1
  308. package/dist/integrations.d.mts +0 -22
  309. package/dist/integrations.d.ts +0 -22
  310. package/dist/integrations.mjs +0 -51
  311. package/dist/integrations.mjs.map +0 -1
  312. package/dist/internal/build-runtime.d.mts +0 -39
  313. package/dist/internal/build-runtime.d.ts +0 -39
  314. package/dist/internal/client-runtime.d.mts +0 -2
  315. package/dist/internal/client-runtime.d.ts +0 -2
  316. package/dist/internal/config-runtime.d.mts +0 -39
  317. package/dist/internal/config-runtime.d.ts +0 -39
  318. package/dist/internal/production-node-env.d.mts +0 -12
  319. package/dist/internal/production-node-env.d.ts +0 -12
  320. package/dist/internal/production-runtime.d.mts +0 -39
  321. package/dist/internal/production-runtime.d.ts +0 -39
  322. package/dist/layers-VWVDTPUZ.mjs +0 -16
  323. package/dist/layers-VWVDTPUZ.mjs.map +0 -1
  324. package/dist/manager-THKFTOFE.mjs +0 -10
  325. package/dist/manager-THKFTOFE.mjs.map +0 -1
  326. package/dist/markdown.cjs +0 -299
  327. package/dist/markdown.cjs.map +0 -1
  328. package/dist/markdown.d.mts +0 -43
  329. package/dist/markdown.d.ts +0 -43
  330. package/dist/markdown.mjs +0 -14
  331. package/dist/markdown.mjs.map +0 -1
  332. package/dist/metadata-BAPg_Nmo.d.ts +0 -22
  333. package/dist/metadata-_6i9oFG3.d.mts +0 -22
  334. package/dist/middleware.cjs +0 -2148
  335. package/dist/middleware.cjs.map +0 -1
  336. package/dist/middleware.d.mts +0 -164
  337. package/dist/middleware.d.ts +0 -164
  338. package/dist/middleware.mjs +0 -49
  339. package/dist/middleware.mjs.map +0 -1
  340. package/dist/navigation-errors-Dvwpzaer.d.mts +0 -13
  341. package/dist/navigation-errors-Dvwpzaer.d.ts +0 -13
  342. package/dist/navigation.cjs +0 -1329
  343. package/dist/navigation.cjs.map +0 -1
  344. package/dist/navigation.d.mts +0 -14
  345. package/dist/navigation.d.ts +0 -14
  346. package/dist/navigation.mjs +0 -33
  347. package/dist/navigation.mjs.map +0 -1
  348. package/dist/nitro-QO5LV6QK.mjs +0 -689
  349. package/dist/nitro-QO5LV6QK.mjs.map +0 -1
  350. package/dist/observability.cjs +0 -186
  351. package/dist/observability.cjs.map +0 -1
  352. package/dist/observability.d.mts +0 -335
  353. package/dist/observability.d.ts +0 -335
  354. package/dist/observability.mjs +0 -16
  355. package/dist/observability.mjs.map +0 -1
  356. package/dist/params-BALtrRim.d.ts +0 -15
  357. package/dist/params-ry-lxqmy.d.mts +0 -15
  358. package/dist/plugin-BJDf43dc.d.mts +0 -165
  359. package/dist/plugin-BJDf43dc.d.ts +0 -165
  360. package/dist/plugin.cjs +0 -23225
  361. package/dist/plugin.d.mts +0 -22
  362. package/dist/plugin.d.ts +0 -22
  363. package/dist/production-runtime-BoJDc5mc.d.ts +0 -79
  364. package/dist/production-runtime-C_B79w2P.d.mts +0 -28
  365. package/dist/production-runtime-DDEM1D2q.d.ts +0 -28
  366. package/dist/production-runtime-DPfgMV9Y.d.mts +0 -79
  367. package/dist/query/client.d.mts +0 -61
  368. package/dist/query/client.d.ts +0 -61
  369. package/dist/query/index.d.mts +0 -90
  370. package/dist/query/index.d.ts +0 -90
  371. package/dist/query/parsers.d.mts +0 -25
  372. package/dist/query/parsers.d.ts +0 -25
  373. package/dist/query/server.d.mts +0 -55
  374. package/dist/query/server.d.ts +0 -55
  375. package/dist/request-BrFBuc8G.d.mts +0 -6
  376. package/dist/request-BslSZIRz.d.ts +0 -6
  377. package/dist/request.d.mts +0 -2
  378. package/dist/request.d.ts +0 -2
  379. package/dist/resolver-C6iecsDV.d.ts +0 -14
  380. package/dist/resolver-DlOPpjkB.d.mts +0 -14
  381. package/dist/route-runtime-DoOHzCAD.d.mts +0 -38
  382. package/dist/route-runtime-DoOHzCAD.d.ts +0 -38
  383. package/dist/router.d.mts +0 -36
  384. package/dist/router.d.ts +0 -36
  385. package/dist/routes.d.mts +0 -224
  386. package/dist/routes.d.ts +0 -224
  387. package/dist/runtime-9nQjVM7X.d.mts +0 -206
  388. package/dist/runtime-B6GvwDS1.d.ts +0 -27
  389. package/dist/runtime-DeAAZ6gO.d.mts +0 -27
  390. package/dist/runtime-DgeS2skB.d.ts +0 -206
  391. package/dist/server-action-security.d.mts +0 -43
  392. package/dist/server-action-security.d.ts +0 -43
  393. package/dist/server-fn-client.d.mts +0 -32
  394. package/dist/server-fn-client.d.ts +0 -32
  395. package/dist/server-fn.d.mts +0 -93
  396. package/dist/server-fn.d.ts +0 -93
  397. package/dist/server-plugins.d.mts +0 -55
  398. package/dist/server-plugins.d.ts +0 -55
  399. package/dist/server-query-client.d.mts +0 -50
  400. package/dist/server-query-client.d.ts +0 -50
  401. package/dist/server-query.d.mts +0 -36
  402. package/dist/server-query.d.ts +0 -36
  403. package/dist/server.d.mts +0 -48
  404. package/dist/server.d.ts +0 -48
  405. package/dist/storage.d.mts +0 -52
  406. package/dist/storage.d.ts +0 -52
  407. package/dist/testing.d.mts +0 -101
  408. package/dist/testing.d.ts +0 -101
  409. package/dist/transport-BmbGTXA5.d.mts +0 -49
  410. package/dist/transport-BmbGTXA5.d.ts +0 -49
  411. package/dist/types-BH1lhg5G.d.mts +0 -81
  412. package/dist/types-BH1lhg5G.d.ts +0 -81
  413. package/dist/types-C9N-nk5R.d.mts +0 -53
  414. package/dist/types-C9N-nk5R.d.ts +0 -53
  415. package/dist/types-D1A6-XvH.d.mts +0 -73
  416. package/dist/types-D1A6-XvH.d.ts +0 -73
  417. package/dist/utils-CHXlMDkg.d.mts +0 -23
  418. package/dist/utils-Drsyz1Vj.d.ts +0 -23
  419. package/dist/version.d.mts +0 -3
  420. package/dist/version.d.ts +0 -3
  421. package/dist/vite.d.mts +0 -22
  422. package/dist/vite.d.ts +0 -22
  423. package/dist/workflows.d.mts +0 -110
  424. package/dist/workflows.d.ts +0 -110
@@ -1,2379 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- var __esm = (fn, res) => function __init() {
10
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
11
- };
12
- var __export = (target, all) => {
13
- for (var name in all)
14
- __defProp(target, name, { get: all[name], enumerable: true });
15
- };
16
- var __copyProps = (to, from, except, desc) => {
17
- if (from && typeof from === "object" || typeof from === "function") {
18
- for (let key of __getOwnPropNames(from))
19
- if (!__hasOwnProp.call(to, key) && key !== except)
20
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
- }
22
- return to;
23
- };
24
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
- // If the importer is in node compatibility mode or this is not an ESM
26
- // file that has been converted to a CommonJS file using a Babel-
27
- // compatible transform (i.e. "__esModule" has not been set), then set
28
- // "default" to the CommonJS "module.exports" for node compatibility.
29
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
- mod
31
- ));
32
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
-
34
- // src/storage/index.ts
35
- var storage_exports = {};
36
- __export(storage_exports, {
37
- createFarmStorage: () => createFarmStorage,
38
- createStorageClient: () => createStorageClient,
39
- databaseStorage: () => databaseStorage,
40
- defineStorageClient: () => defineStorageClient,
41
- disposeStorage: () => disposeStorage,
42
- driverStorage: () => driverStorage,
43
- getStorage: () => getStorage,
44
- initStorage: () => initStorage,
45
- libsqlStorage: () => libsqlStorage,
46
- localStorage: () => localStorage,
47
- memoryStorage: () => memoryStorage,
48
- mongodbStorage: () => mongodbStorage,
49
- mysql2Storage: () => mysql2Storage,
50
- mysqlStorage: () => mysqlStorage,
51
- netlifyBlobsStorage: () => netlifyBlobsStorage,
52
- pgStorage: () => pgStorage,
53
- pgliteStorage: () => pgliteStorage,
54
- planetscaleStorage: () => planetscaleStorage,
55
- postgresStorage: () => postgresStorage,
56
- redisStorage: () => redisStorage,
57
- resolveStorageRuntimeClient: () => resolveStorageRuntimeClient,
58
- s3Storage: () => s3Storage,
59
- sqliteStorage: () => sqliteStorage,
60
- upstashStorage: () => upstashStorage,
61
- vercelBlobStorage: () => vercelBlobStorage,
62
- vercelKVStorage: () => vercelKVStorage
63
- });
64
- function createMemoryStorage() {
65
- return (0, import_unstorage.createStorage)({
66
- driver: (0, import_memory.default)()
67
- });
68
- }
69
- function readGlobalStorage() {
70
- return globalThis[GLOBAL_STORAGE_KEY];
71
- }
72
- function writeGlobalStorage(storage) {
73
- globalThis[GLOBAL_STORAGE_KEY] = storage;
74
- return storage;
75
- }
76
- function getActiveGlobalStorage() {
77
- const existing = readGlobalStorage();
78
- if (existing) {
79
- return existing;
80
- }
81
- return writeGlobalStorage(createMemoryStorage());
82
- }
83
- function normalizeMountKey(base) {
84
- return (base || "").trim().replace(/^[:/\\]+|[:/\\]+$/g, "").replace(/[\\/]+/g, ":");
85
- }
86
- function isDriverInstance(value) {
87
- return !!value && typeof value === "object" && typeof value.getItem === "function" && typeof value.getKeys === "function";
88
- }
89
- function isStorageInstance(value) {
90
- return !!value && typeof value === "object" && typeof value.mount === "function" && typeof value.getMount === "function";
91
- }
92
- function isStorageClient(value) {
93
- return !!value && typeof value === "object" && value.kind === "farm-storage-client" && typeof value.resolveDriver === "function" && typeof value.createStorage === "function";
94
- }
95
- function isDatabaseDriverName(name) {
96
- return name in DATABASE_CONNECTORS;
97
- }
98
- function extractDriverOptions(config) {
99
- const source = config;
100
- const {
101
- client: _client,
102
- driver: _driver,
103
- mounts: _mounts,
104
- options,
105
- tableName: _tableName,
106
- ...inlineOptions
107
- } = source;
108
- const hasInlineOptions = Object.keys(inlineOptions).length > 0;
109
- if (options && typeof options === "object" && !Array.isArray(options)) {
110
- return hasInlineOptions ? { ...inlineOptions, ...options } : options;
111
- }
112
- if (hasInlineOptions) {
113
- return inlineOptions;
114
- }
115
- return options;
116
- }
117
- async function loadBuiltinDriver(name, options) {
118
- const modulePath = import_unstorage.builtinDrivers[name];
119
- if (!modulePath) {
120
- throw new Error(`Unsupported storage driver "${name}".`);
121
- }
122
- const module2 = await loadModule(modulePath);
123
- return module2.default(options);
124
- }
125
- async function loadDatabaseDriver(config) {
126
- const connectorEntry = DATABASE_CONNECTORS[config.driver];
127
- const [{ createDatabase }, connectorModule, db0DriverModule] = await Promise.all([
128
- loadModule("db0"),
129
- connectorEntry.load(),
130
- loadModule("unstorage/drivers/db0")
131
- ]);
132
- const database = createDatabase(connectorModule.default(extractDriverOptions(config) || {}));
133
- return db0DriverModule.default({
134
- database,
135
- tableName: config.tableName
136
- });
137
- }
138
- async function resolveDriver(config) {
139
- if (config && isStorageClient(config)) {
140
- return config.resolveDriver();
141
- }
142
- const driverInput = config?.driver ?? "memory";
143
- if (typeof driverInput === "function") {
144
- return await driverInput();
145
- }
146
- if (isDriverInstance(driverInput)) {
147
- return driverInput;
148
- }
149
- if (isDatabaseDriverName(driverInput)) {
150
- return loadDatabaseDriver(config);
151
- }
152
- if (driverInput === "local") {
153
- return loadBuiltinDriver("fs-lite", extractDriverOptions(config));
154
- }
155
- return loadBuiltinDriver(
156
- driverInput,
157
- extractDriverOptions(config)
158
- );
159
- }
160
- function createStorageClientFromResolver(resolveDriver2) {
161
- let driverPromise;
162
- let storagePromise;
163
- const ensureDriver = /* @__PURE__ */ __name(async () => {
164
- driverPromise ?? (driverPromise = Promise.resolve(resolveDriver2()));
165
- return driverPromise;
166
- }, "ensureDriver");
167
- const ensureStorage = /* @__PURE__ */ __name(async () => {
168
- storagePromise ?? (storagePromise = ensureDriver().then(
169
- (driver) => (0, import_unstorage.createStorage)({
170
- driver
171
- })
172
- ));
173
- return storagePromise;
174
- }, "ensureStorage");
175
- const target = {
176
- kind: "farm-storage-client",
177
- ready: ensureStorage,
178
- createStorage: ensureStorage,
179
- resolveDriver: ensureDriver
180
- };
181
- return new Proxy(target, {
182
- get(currentTarget, prop, receiver) {
183
- if (prop === "then") {
184
- return void 0;
185
- }
186
- if (Reflect.has(currentTarget, prop)) {
187
- return Reflect.get(currentTarget, prop, receiver);
188
- }
189
- return (...args) => ensureStorage().then(async (storage) => {
190
- const member = Reflect.get(storage, prop);
191
- if (typeof member !== "function") {
192
- return member;
193
- }
194
- const result = Reflect.apply(member, storage, args);
195
- if (prop === "dispose") {
196
- return Promise.resolve(result).finally(() => {
197
- storagePromise = void 0;
198
- });
199
- }
200
- return result;
201
- });
202
- }
203
- });
204
- }
205
- function defineStorageClient(resolveDriver2) {
206
- return createStorageClientFromResolver(resolveDriver2);
207
- }
208
- function createStorageClient(config) {
209
- return defineStorageClient(() => resolveDriver(config));
210
- }
211
- function driverStorage(driver) {
212
- return defineStorageClient(() => typeof driver === "function" ? driver() : driver);
213
- }
214
- function databaseStorage(database, options = {}) {
215
- return defineStorageClient(async () => {
216
- const db0DriverModule = await loadModule("unstorage/drivers/db0");
217
- return db0DriverModule.default({
218
- database,
219
- tableName: options.tableName
220
- });
221
- });
222
- }
223
- function memoryStorage() {
224
- return createStorageClient({ driver: "memory" });
225
- }
226
- function localStorage(options = {}) {
227
- return createStorageClient({
228
- driver: "local",
229
- ...options
230
- });
231
- }
232
- function sqliteStorage(options) {
233
- return createStorageClient({
234
- driver: "sqlite",
235
- ...options
236
- });
237
- }
238
- function mysqlStorage(options) {
239
- return createStorageClient({
240
- driver: "mysql",
241
- ...options
242
- });
243
- }
244
- function mysql2Storage(options) {
245
- return mysqlStorage(options);
246
- }
247
- function postgresStorage(options) {
248
- return createStorageClient({
249
- driver: "postgres",
250
- ...options
251
- });
252
- }
253
- function pgStorage(options) {
254
- return postgresStorage(options);
255
- }
256
- function pgliteStorage(options) {
257
- return createStorageClient({
258
- driver: "pglite",
259
- ...options
260
- });
261
- }
262
- function planetscaleStorage(options) {
263
- return createStorageClient({
264
- driver: "planetscale",
265
- ...options
266
- });
267
- }
268
- function libsqlStorage(options) {
269
- return createStorageClient({
270
- driver: "libsql",
271
- ...options
272
- });
273
- }
274
- function redisStorage(options) {
275
- return createStorageClient({
276
- driver: "redis",
277
- ...options
278
- });
279
- }
280
- function s3Storage(options) {
281
- return createStorageClient({
282
- driver: "s3",
283
- ...options
284
- });
285
- }
286
- function mongodbStorage(options) {
287
- return createStorageClient({
288
- driver: "mongodb",
289
- ...options
290
- });
291
- }
292
- function upstashStorage(options) {
293
- return createStorageClient({
294
- driver: "upstash",
295
- ...options
296
- });
297
- }
298
- function netlifyBlobsStorage(options) {
299
- return createStorageClient({
300
- driver: "netlify-blobs",
301
- ...options
302
- });
303
- }
304
- function vercelKVStorage(options) {
305
- return createStorageClient({
306
- driver: "vercel-kv",
307
- ...options
308
- });
309
- }
310
- function vercelBlobStorage(options) {
311
- return createStorageClient({
312
- driver: "vercel-blob",
313
- ...options
314
- });
315
- }
316
- async function mountNamespaces(storage, mounts) {
317
- if (!mounts) {
318
- return;
319
- }
320
- for (const [base, config] of Object.entries(mounts)) {
321
- storage.mount(normalizeMountKey(base), await resolveDriver(config));
322
- }
323
- }
324
- async function createFarmStorage(config = {}) {
325
- if (isStorageInstance(config)) {
326
- return config;
327
- }
328
- if (isStorageClient(config)) {
329
- return config.createStorage();
330
- }
331
- const rootConfig = isStorageClient(config.client) ? config.client : config;
332
- const storage = (0, import_unstorage.createStorage)({
333
- driver: await resolveDriver(rootConfig)
334
- });
335
- await mountNamespaces(storage, config.mounts);
336
- return storage;
337
- }
338
- async function resolveStorageRuntimeClient(config) {
339
- if (!config || isStorageInstance(config) || isStorageClient(config)) {
340
- return void 0;
341
- }
342
- const client = config.client;
343
- if (!client || isStorageInstance(client) || isStorageClient(client)) {
344
- return void 0;
345
- }
346
- return typeof client === "function" ? await client() : client;
347
- }
348
- async function initStorage(config = {}) {
349
- globalStorage = getActiveGlobalStorage();
350
- const nextStorage = await createFarmStorage(config);
351
- const previousStorage = globalStorage;
352
- globalStorage = writeGlobalStorage(nextStorage);
353
- if (previousStorage !== nextStorage) {
354
- await previousStorage.dispose().catch(() => {
355
- });
356
- }
357
- return globalStorage;
358
- }
359
- function getStorage(namespace) {
360
- globalStorage = getActiveGlobalStorage();
361
- const base = normalizeMountKey(namespace);
362
- if (!base) {
363
- return globalStorage;
364
- }
365
- const namespaced = (0, import_unstorage.prefixStorage)(globalStorage, base);
366
- return {
367
- ...namespaced,
368
- async clear() {
369
- const keys = await namespaced.getKeys();
370
- await Promise.all(keys.map((key) => namespaced.removeItem(key)));
371
- }
372
- };
373
- }
374
- async function disposeStorage() {
375
- globalStorage = getActiveGlobalStorage();
376
- const previousStorage = globalStorage;
377
- globalStorage = writeGlobalStorage(createMemoryStorage());
378
- await previousStorage.dispose().catch(() => {
379
- });
380
- }
381
- var import_unstorage, import_memory, loadModule, DATABASE_CONNECTORS, GLOBAL_STORAGE_KEY, globalStorage;
382
- var init_storage = __esm({
383
- "src/storage/index.ts"() {
384
- "use strict";
385
- import_unstorage = require("unstorage");
386
- import_memory = __toESM(require("unstorage/drivers/memory"));
387
- loadModule = /* @__PURE__ */ __name((specifier) => import(
388
- /* @vite-ignore */
389
- specifier
390
- ), "loadModule");
391
- DATABASE_CONNECTORS = {
392
- sqlite: {
393
- connector: "node-sqlite",
394
- load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/node-sqlite"), "load")
395
- },
396
- "node-sqlite": {
397
- connector: "node-sqlite",
398
- load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/node-sqlite"), "load")
399
- },
400
- sqlite3: {
401
- connector: "sqlite3",
402
- load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/sqlite3"), "load")
403
- },
404
- "better-sqlite3": {
405
- connector: "better-sqlite3",
406
- load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/better-sqlite3"), "load")
407
- },
408
- postgres: {
409
- connector: "postgresql",
410
- load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/postgresql"), "load")
411
- },
412
- postgresql: {
413
- connector: "postgresql",
414
- load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/postgresql"), "load")
415
- },
416
- pg: {
417
- connector: "postgresql",
418
- load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/postgresql"), "load")
419
- },
420
- mysql: {
421
- connector: "mysql2",
422
- load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/mysql2"), "load")
423
- },
424
- mysql2: {
425
- connector: "mysql2",
426
- load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/mysql2"), "load")
427
- },
428
- pglite: {
429
- connector: "pglite",
430
- load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/pglite"), "load")
431
- },
432
- planetscale: {
433
- connector: "planetscale",
434
- load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/planetscale"), "load")
435
- },
436
- libsql: {
437
- connector: "libsql",
438
- load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/libsql/node"), "load")
439
- },
440
- "libsql-node": {
441
- connector: "libsql-node",
442
- load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/libsql/node"), "load")
443
- },
444
- "libsql-http": {
445
- connector: "libsql-http",
446
- load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/libsql/http"), "load")
447
- }
448
- };
449
- __name(createMemoryStorage, "createMemoryStorage");
450
- GLOBAL_STORAGE_KEY = /* @__PURE__ */ Symbol.for("farmjs.storage.global");
451
- __name(readGlobalStorage, "readGlobalStorage");
452
- __name(writeGlobalStorage, "writeGlobalStorage");
453
- __name(getActiveGlobalStorage, "getActiveGlobalStorage");
454
- globalStorage = getActiveGlobalStorage();
455
- __name(normalizeMountKey, "normalizeMountKey");
456
- __name(isDriverInstance, "isDriverInstance");
457
- __name(isStorageInstance, "isStorageInstance");
458
- __name(isStorageClient, "isStorageClient");
459
- __name(isDatabaseDriverName, "isDatabaseDriverName");
460
- __name(extractDriverOptions, "extractDriverOptions");
461
- __name(loadBuiltinDriver, "loadBuiltinDriver");
462
- __name(loadDatabaseDriver, "loadDatabaseDriver");
463
- __name(resolveDriver, "resolveDriver");
464
- __name(createStorageClientFromResolver, "createStorageClientFromResolver");
465
- __name(defineStorageClient, "defineStorageClient");
466
- __name(createStorageClient, "createStorageClient");
467
- __name(driverStorage, "driverStorage");
468
- __name(databaseStorage, "databaseStorage");
469
- __name(memoryStorage, "memoryStorage");
470
- __name(localStorage, "localStorage");
471
- __name(sqliteStorage, "sqliteStorage");
472
- __name(mysqlStorage, "mysqlStorage");
473
- __name(mysql2Storage, "mysql2Storage");
474
- __name(postgresStorage, "postgresStorage");
475
- __name(pgStorage, "pgStorage");
476
- __name(pgliteStorage, "pgliteStorage");
477
- __name(planetscaleStorage, "planetscaleStorage");
478
- __name(libsqlStorage, "libsqlStorage");
479
- __name(redisStorage, "redisStorage");
480
- __name(s3Storage, "s3Storage");
481
- __name(mongodbStorage, "mongodbStorage");
482
- __name(upstashStorage, "upstashStorage");
483
- __name(netlifyBlobsStorage, "netlifyBlobsStorage");
484
- __name(vercelKVStorage, "vercelKVStorage");
485
- __name(vercelBlobStorage, "vercelBlobStorage");
486
- __name(mountNamespaces, "mountNamespaces");
487
- __name(createFarmStorage, "createFarmStorage");
488
- __name(resolveStorageRuntimeClient, "resolveStorageRuntimeClient");
489
- __name(initStorage, "initStorage");
490
- __name(getStorage, "getStorage");
491
- __name(disposeStorage, "disposeStorage");
492
- }
493
- });
494
-
495
- // src/integration-orm.ts
496
- var integration_orm_exports = {};
497
- __export(integration_orm_exports, {
498
- createIntegrationOrm: () => createIntegrationOrm,
499
- farmIntegrationSchemaToOrmSchema: () => farmIntegrationSchemaToOrmSchema,
500
- resolveIntegrationOrmRuntimeClient: () => resolveIntegrationOrmRuntimeClient
501
- });
502
- async function createIntegrationOrm(options) {
503
- const [schema, client] = await Promise.all([
504
- farmIntegrationSchemaToOrmSchema(options.schema),
505
- resolveIntegrationOrmRuntimeClient(options)
506
- ]);
507
- if (!client) {
508
- throw new Error(
509
- "Schema-backed integration storage requires a runtime client at farm.config storage.client."
510
- );
511
- }
512
- const { createOrmFromRuntime } = await import("@farming-labs/orm-runtime");
513
- return createOrmFromRuntime({
514
- schema,
515
- client
516
- });
517
- }
518
- async function resolveIntegrationOrmRuntimeClient(options) {
519
- if (options.client !== void 0) {
520
- return typeof options.client === "function" ? await options.client() : options.client;
521
- }
522
- return resolveStorageRuntimeClient(options.storage ?? options.config?.storage);
523
- }
524
- async function farmIntegrationSchemaToOrmSchema(schema) {
525
- const orm = await import("@farming-labs/orm");
526
- const models = {};
527
- for (const [modelKey, modelSchema] of Object.entries(schema.models)) {
528
- models[modelKey] = orm.model({
529
- table: modelSchema.name ?? modelKey,
530
- fields: createOrmModelFields(orm, modelSchema),
531
- constraints: createOrmModelConstraints(modelSchema),
532
- description: modelSchema.description
533
- });
534
- }
535
- return orm.defineSchema(models);
536
- }
537
- function createOrmModelFields(orm, modelSchema) {
538
- return Object.fromEntries(
539
- Object.entries(modelSchema.fields).map(([fieldKey, fieldSchema]) => [
540
- fieldKey,
541
- createOrmField(orm, fieldKey, fieldSchema)
542
- ])
543
- );
544
- }
545
- function createOrmField(orm, fieldKey, field) {
546
- let builder = createOrmFieldBuilder(orm, fieldKey, field);
547
- if (field.unique) {
548
- builder = builder.unique();
549
- }
550
- if (field.nullable || field.required === false) {
551
- builder = builder.nullable();
552
- }
553
- if (field.default !== void 0) {
554
- builder = field.type === "datetime" && field.default === "now" ? builder.defaultNow() : builder.default(field.default);
555
- }
556
- if (field.reference) {
557
- builder = builder.references(`${field.reference.model}.${field.reference.field}`);
558
- }
559
- if (field.name && field.name !== fieldKey) {
560
- builder = builder.map(field.name);
561
- }
562
- if (field.description) {
563
- builder = builder.describe(field.description);
564
- }
565
- return builder;
566
- }
567
- function createOrmFieldBuilder(orm, fieldKey, field) {
568
- switch (field.type) {
569
- case "id":
570
- case "uuid":
571
- return orm.id();
572
- case "string":
573
- case "text":
574
- return orm.string();
575
- case "boolean":
576
- return orm.boolean();
577
- case "integer":
578
- return orm.integer();
579
- case "number":
580
- return orm.decimal();
581
- case "datetime":
582
- return orm.datetime();
583
- case "json":
584
- return orm.json();
585
- case "enum": {
586
- if (!field.values?.length) {
587
- throw new Error(`Integration schema enum field "${fieldKey}" must define values.`);
588
- }
589
- return orm.enumeration(field.values);
590
- }
591
- default:
592
- throw new Error(
593
- `Unsupported integration schema field type "${field.type}" for "${fieldKey}".`
594
- );
595
- }
596
- }
597
- function createOrmModelConstraints(modelSchema) {
598
- const unique = [];
599
- const indexes = [];
600
- for (const constraint of modelSchema.constraints ?? []) {
601
- if (!constraint.fields.length) {
602
- continue;
603
- }
604
- const fields = constraint.fields;
605
- if (constraint.type === "unique") {
606
- unique.push(fields);
607
- } else {
608
- indexes.push(fields);
609
- }
610
- }
611
- return {
612
- unique,
613
- indexes
614
- };
615
- }
616
- var init_integration_orm = __esm({
617
- "src/integration-orm.ts"() {
618
- "use strict";
619
- init_storage();
620
- __name(createIntegrationOrm, "createIntegrationOrm");
621
- __name(resolveIntegrationOrmRuntimeClient, "resolveIntegrationOrmRuntimeClient");
622
- __name(farmIntegrationSchemaToOrmSchema, "farmIntegrationSchemaToOrmSchema");
623
- __name(createOrmModelFields, "createOrmModelFields");
624
- __name(createOrmField, "createOrmField");
625
- __name(createOrmFieldBuilder, "createOrmFieldBuilder");
626
- __name(createOrmModelConstraints, "createOrmModelConstraints");
627
- }
628
- });
629
-
630
- // src/agent-runtime.ts
631
- var agent_runtime_exports = {};
632
- __export(agent_runtime_exports, {
633
- applyAgentRuntimeViteProxy: () => applyAgentRuntimeViteProxy,
634
- createAgentRuntimeIntegration: () => createAgentRuntimeIntegration,
635
- findAvailableAgentRuntimePort: () => findAvailableAgentRuntimePort,
636
- normalizeAgentOrigin: () => normalizeAgentOrigin,
637
- normalizeAgentRoutePrefix: () => normalizeAgentRoutePrefix,
638
- proxyAgentRuntimeRequest: () => proxyAgentRuntimeRequest,
639
- resolveProjectPackageBin: () => resolveProjectPackageBin,
640
- startManagedAgentRuntime: () => startManagedAgentRuntime
641
- });
642
- module.exports = __toCommonJS(agent_runtime_exports);
643
- var import_node_child_process = require("child_process");
644
- var import_promises = require("fs/promises");
645
- var import_node_module = require("module");
646
- var import_node_net = require("net");
647
- var import_node_path = require("path");
648
-
649
- // src/integration-api.ts
650
- function defineIntegrationAPIOperation(operation2) {
651
- return {
652
- kind: "farm-integration-api-operation",
653
- ...operation2
654
- };
655
- }
656
- __name(defineIntegrationAPIOperation, "defineIntegrationAPIOperation");
657
- function operation(method, pathOrOptions, maybeOptions = {}) {
658
- const hasExplicitPath = typeof pathOrOptions === "string";
659
- const path = hasExplicitPath ? pathOrOptions : "";
660
- const options = hasExplicitPath ? maybeOptions : {
661
- ...maybeOptions,
662
- ...pathOrOptions
663
- };
664
- return defineIntegrationAPIOperation({
665
- path,
666
- method,
667
- __pathless: !hasExplicitPath,
668
- ...options
669
- });
670
- }
671
- __name(operation, "operation");
672
- function get(pathOrOptions, maybeOptions = {}) {
673
- return operation("GET", pathOrOptions, maybeOptions);
674
- }
675
- __name(get, "get");
676
- function isOperation(value) {
677
- return !!value && typeof value === "object" && value.kind === "farm-integration-api-operation";
678
- }
679
- __name(isOperation, "isOperation");
680
- function bindRoutePath(path, api2) {
681
- const entries = Object.entries(api2).map(([key, value]) => {
682
- if (isOperation(value)) {
683
- return [
684
- key,
685
- {
686
- ...value,
687
- path,
688
- __pathless: false
689
- }
690
- ];
691
- }
692
- if (value && typeof value === "object") {
693
- return [key, bindRoutePath(path, value)];
694
- }
695
- return [key, value];
696
- });
697
- return Object.fromEntries(entries);
698
- }
699
- __name(bindRoutePath, "bindRoutePath");
700
- function route(path, definitionOrOperation, ...operations) {
701
- if (isOperation(definitionOrOperation)) {
702
- const allOperations = [definitionOrOperation, ...operations];
703
- return Object.fromEntries(
704
- allOperations.map((operation2) => [
705
- operation2.method.toLowerCase(),
706
- {
707
- ...operation2,
708
- path,
709
- __pathless: false
710
- }
711
- ])
712
- );
713
- }
714
- return bindRoutePath(path, definitionOrOperation);
715
- }
716
- __name(route, "route");
717
- function normalizeRouteSegment(segment) {
718
- if (!segment) {
719
- return "index";
720
- }
721
- if (segment.startsWith("[...") && segment.endsWith("]")) {
722
- return segment.slice(4, -1) || "index";
723
- }
724
- if (segment.startsWith("[") && segment.endsWith("]")) {
725
- return segment.slice(1, -1) || "index";
726
- }
727
- const matcherIndex = segment.indexOf("(");
728
- if (matcherIndex > 0) {
729
- return segment.slice(0, matcherIndex);
730
- }
731
- return camelCaseRouteSegment(segment);
732
- }
733
- __name(normalizeRouteSegment, "normalizeRouteSegment");
734
- function camelCaseRouteSegment(segment) {
735
- return segment.replace(/-([a-zA-Z0-9])/g, (_match, value) => value.toUpperCase());
736
- }
737
- __name(camelCaseRouteSegment, "camelCaseRouteSegment");
738
- function getRouteClientSegments(path) {
739
- const segments = path.split("/").filter(Boolean);
740
- if (segments.length === 0) {
741
- return ["index"];
742
- }
743
- const stripped = segments[0] === "api" && segments.length > 2 ? segments.slice(2) : segments.length > 1 ? segments.slice(1) : [segments[segments.length - 1]];
744
- return stripped.map(normalizeRouteSegment).filter(Boolean);
745
- }
746
- __name(getRouteClientSegments, "getRouteClientSegments");
747
- function setRouteOperation(target, pathSegments, operation2) {
748
- const [head, ...tail] = pathSegments;
749
- if (!head) {
750
- return;
751
- }
752
- if (tail.length === 0) {
753
- const leaf = target[head] || {};
754
- leaf[operation2.method.toLowerCase()] = {
755
- ...operation2,
756
- path: operation2.path,
757
- __pathless: false
758
- };
759
- target[head] = leaf;
760
- return;
761
- }
762
- const branch = target[head] || {};
763
- target[head] = branch;
764
- setRouteOperation(branch, tail, operation2);
765
- }
766
- __name(setRouteOperation, "setRouteOperation");
767
- function fromRoutes(routes) {
768
- const definition = {};
769
- for (const route2 of routes) {
770
- if (!isOperation(route2.__operation)) {
771
- continue;
772
- }
773
- setRouteOperation(definition, getRouteClientSegments(route2.path), {
774
- ...route2.__operation,
775
- path: route2.path,
776
- __pathless: false
777
- });
778
- }
779
- return definition;
780
- }
781
- __name(fromRoutes, "fromRoutes");
782
- var api = {
783
- get,
784
- route,
785
- fromRoutes,
786
- post(pathOrOptions, maybeOptions = {}) {
787
- return operation("POST", pathOrOptions, {
788
- bodyFormat: "json",
789
- ...typeof pathOrOptions === "string" ? maybeOptions : pathOrOptions
790
- });
791
- },
792
- put(pathOrOptions, maybeOptions = {}) {
793
- return operation("PUT", pathOrOptions, {
794
- bodyFormat: "json",
795
- ...typeof pathOrOptions === "string" ? maybeOptions : pathOrOptions
796
- });
797
- },
798
- patch(pathOrOptions, maybeOptions = {}) {
799
- return operation("PATCH", pathOrOptions, {
800
- bodyFormat: "json",
801
- ...typeof pathOrOptions === "string" ? maybeOptions : pathOrOptions
802
- });
803
- },
804
- delete(pathOrOptions, maybeOptions = {}) {
805
- return operation("DELETE", pathOrOptions, {
806
- bodyFormat: "json",
807
- ...typeof pathOrOptions === "string" ? maybeOptions : pathOrOptions
808
- });
809
- },
810
- options(pathOrOptions, maybeOptions = {}) {
811
- return operation(
812
- "OPTIONS",
813
- pathOrOptions,
814
- maybeOptions
815
- );
816
- },
817
- head(pathOrOptions, maybeOptions = {}) {
818
- return operation(
819
- "HEAD",
820
- pathOrOptions,
821
- maybeOptions
822
- );
823
- },
824
- form: {
825
- post(pathOrOptions, maybeOptions = {}) {
826
- return operation("POST", pathOrOptions, {
827
- bodyFormat: "form",
828
- ...typeof pathOrOptions === "string" ? maybeOptions : pathOrOptions
829
- });
830
- },
831
- put(pathOrOptions, maybeOptions = {}) {
832
- return operation("PUT", pathOrOptions, {
833
- bodyFormat: "form",
834
- ...typeof pathOrOptions === "string" ? maybeOptions : pathOrOptions
835
- });
836
- },
837
- patch(pathOrOptions, maybeOptions = {}) {
838
- return operation("PATCH", pathOrOptions, {
839
- bodyFormat: "form",
840
- ...typeof pathOrOptions === "string" ? maybeOptions : pathOrOptions
841
- });
842
- },
843
- delete(pathOrOptions, maybeOptions = {}) {
844
- return operation("DELETE", pathOrOptions, {
845
- bodyFormat: "form",
846
- ...typeof pathOrOptions === "string" ? maybeOptions : pathOrOptions
847
- });
848
- }
849
- }
850
- };
851
-
852
- // src/request-context.ts
853
- var REQUEST_CONTEXT_STORE_KEY = /* @__PURE__ */ Symbol.for("farm.requestContextStore");
854
- function getRequestContextStore() {
855
- const globalState = globalThis;
856
- if (!globalState[REQUEST_CONTEXT_STORE_KEY]) {
857
- globalState[REQUEST_CONTEXT_STORE_KEY] = /* @__PURE__ */ new WeakMap();
858
- }
859
- return globalState[REQUEST_CONTEXT_STORE_KEY];
860
- }
861
- __name(getRequestContextStore, "getRequestContextStore");
862
- function getBucket(target) {
863
- const requestContextStore = getRequestContextStore();
864
- let bucket = requestContextStore.get(target);
865
- if (!bucket) {
866
- bucket = {
867
- privateData: /* @__PURE__ */ new Map(),
868
- exposedData: /* @__PURE__ */ new Map()
869
- };
870
- requestContextStore.set(target, bucket);
871
- }
872
- return bucket;
873
- }
874
- __name(getBucket, "getBucket");
875
- function setRequestContext(target, key, value, options = {}) {
876
- const bucket = getBucket(target);
877
- bucket.privateData.set(key, value);
878
- if (options.exposeToPage) {
879
- bucket.exposedData.set(key, value);
880
- }
881
- }
882
- __name(setRequestContext, "setRequestContext");
883
- function getRequestContext(target, key) {
884
- const requestContextStore = getRequestContextStore();
885
- const bucket = requestContextStore.get(target);
886
- return bucket?.privateData.get(key);
887
- }
888
- __name(getRequestContext, "getRequestContext");
889
- function hasRequestContext(target, key) {
890
- const requestContextStore = getRequestContextStore();
891
- const bucket = requestContextStore.get(target);
892
- return bucket?.privateData.has(key) ?? false;
893
- }
894
- __name(hasRequestContext, "hasRequestContext");
895
- function deleteRequestContext(target, key) {
896
- const requestContextStore = getRequestContextStore();
897
- const bucket = requestContextStore.get(target);
898
- if (!bucket) return false;
899
- const removedPrivate = bucket.privateData.delete(key);
900
- bucket.exposedData.delete(key);
901
- return removedPrivate;
902
- }
903
- __name(deleteRequestContext, "deleteRequestContext");
904
- function clearRequestContext(target) {
905
- const requestContextStore = getRequestContextStore();
906
- const bucket = requestContextStore.get(target);
907
- if (!bucket) return;
908
- bucket.privateData.clear();
909
- bucket.exposedData.clear();
910
- }
911
- __name(clearRequestContext, "clearRequestContext");
912
- function getRequestContextSnapshot(target, options = {}) {
913
- const requestContextStore = getRequestContextStore();
914
- const bucket = requestContextStore.get(target);
915
- if (!bucket) return /* @__PURE__ */ new Map();
916
- if (options.exposedOnly) {
917
- return new Map(bucket.exposedData);
918
- }
919
- return new Map(bucket.privateData);
920
- }
921
- __name(getRequestContextSnapshot, "getRequestContextSnapshot");
922
-
923
- // src/server/response.ts
924
- var import_node_events = require("events");
925
-
926
- // src/integrations.ts
927
- var FARM_INTEGRATION_INTERNAL_DISPATCH_CONTEXT_KEY = "farm.integration.internalDispatch";
928
- function defineTypedIntegrationRoute(method, path, input) {
929
- return {
930
- path,
931
- method,
932
- middleware: input.middleware,
933
- before: input.before,
934
- after: input.after,
935
- rawBody: input.rawBody,
936
- bodyFormat: input.bodyFormat,
937
- input: normalizeIntegrationRouteInputSchemas(input),
938
- handler: input.handler,
939
- __operation: defineIntegrationAPIOperation({
940
- path,
941
- method,
942
- bodyFormat: input.bodyFormat,
943
- responseFormat: input.responseFormat,
944
- headers: input.headers,
945
- credentials: input.credentials,
946
- isServer: input.isServer
947
- })
948
- };
949
- }
950
- __name(defineTypedIntegrationRoute, "defineTypedIntegrationRoute");
951
- function createIntegrationRouteFactory() {
952
- return {
953
- get(path, input) {
954
- return defineTypedIntegrationRoute(
955
- "GET",
956
- path,
957
- input
958
- );
959
- },
960
- post(path, input) {
961
- return defineTypedIntegrationRoute(
962
- "POST",
963
- path,
964
- {
965
- bodyFormat: "json",
966
- ...input
967
- }
968
- );
969
- },
970
- put(path, input) {
971
- return defineTypedIntegrationRoute(
972
- "PUT",
973
- path,
974
- {
975
- bodyFormat: "json",
976
- ...input
977
- }
978
- );
979
- },
980
- patch(path, input) {
981
- return defineTypedIntegrationRoute("PATCH", path, {
982
- bodyFormat: "json",
983
- ...input
984
- });
985
- },
986
- delete(path, input) {
987
- return defineTypedIntegrationRoute("DELETE", path, {
988
- bodyFormat: "json",
989
- ...input
990
- });
991
- },
992
- options(path, input) {
993
- return defineTypedIntegrationRoute("OPTIONS", path, input);
994
- },
995
- head(path, input) {
996
- return defineTypedIntegrationRoute(
997
- "HEAD",
998
- path,
999
- input
1000
- );
1001
- }
1002
- };
1003
- }
1004
- __name(createIntegrationRouteFactory, "createIntegrationRouteFactory");
1005
- function createIntegrationRoute(_schema) {
1006
- return createIntegrationRouteFactory();
1007
- }
1008
- __name(createIntegrationRoute, "createIntegrationRoute");
1009
- var integrationRoute = createIntegrationRouteFactory();
1010
- var INTEGRATION_REQUEST_DISPATCHER_KEY = /* @__PURE__ */ Symbol.for("farm.integrationRequestDispatcher");
1011
- function isIntegrationEndpointRoute(value) {
1012
- return !!value && typeof value === "object" && typeof value.path === "string" && typeof value.handler === "function";
1013
- }
1014
- __name(isIntegrationEndpointRoute, "isIntegrationEndpointRoute");
1015
- function flattenIntegrationEndpoints(endpoints) {
1016
- if (!endpoints) {
1017
- return [];
1018
- }
1019
- if (Array.isArray(endpoints)) {
1020
- return endpoints.flatMap((endpoint) => flattenIntegrationEndpoints(endpoint));
1021
- }
1022
- if (isIntegrationEndpointRoute(endpoints)) {
1023
- return [endpoints];
1024
- }
1025
- if (typeof endpoints === "object") {
1026
- return Object.values(endpoints).flatMap((endpoint) => flattenIntegrationEndpoints(endpoint));
1027
- }
1028
- return [];
1029
- }
1030
- __name(flattenIntegrationEndpoints, "flattenIntegrationEndpoints");
1031
- function defineIntegration(integration) {
1032
- const category = integration.category ?? integration.slot;
1033
- if (!category) {
1034
- throw new Error("Integration category is required.");
1035
- }
1036
- if (integration.category && integration.slot && integration.category !== integration.slot) {
1037
- throw new Error("Integration category and slot must match when both are provided.");
1038
- }
1039
- const routeFactory = createIntegrationRoute(integration.schema);
1040
- const routes = typeof integration.routes === "function" ? integration.routes({
1041
- route: routeFactory,
1042
- integrationRoute: routeFactory
1043
- }) : integration.routes;
1044
- const endpoints = typeof integration.endpoints === "function" ? integration.endpoints({
1045
- endpoint: routeFactory,
1046
- route: routeFactory,
1047
- integrationRoute: routeFactory
1048
- }) : integration.endpoints;
1049
- const endpointRoutes = flattenIntegrationEndpoints(endpoints);
1050
- const allRoutes = routes?.length || endpointRoutes.length ? [...routes || [], ...endpointRoutes] : void 0;
1051
- const derivedApi = integration.api || (allRoutes?.length ? api.fromRoutes(
1052
- allRoutes
1053
- ) : void 0);
1054
- return {
1055
- kind: "farm-integration",
1056
- ...integration,
1057
- endpoints,
1058
- routes: allRoutes,
1059
- api: derivedApi,
1060
- category,
1061
- slot: category
1062
- };
1063
- }
1064
- __name(defineIntegration, "defineIntegration");
1065
- var INTEGRATION_DATA_HEADER = "x-farm-integration-data";
1066
- var INTEGRATION_DATA_HEADER_MAX_LENGTH = 16 * 1024;
1067
- var BLOCKED_INTEGRATION_DATA_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
1068
- function isFarmIntegrationData(value) {
1069
- return !!value && typeof value === "object" && !Array.isArray(value);
1070
- }
1071
- __name(isFarmIntegrationData, "isFarmIntegrationData");
1072
- function isPlainIntegrationDataObject(value) {
1073
- if (!isFarmIntegrationData(value)) {
1074
- return false;
1075
- }
1076
- const prototype = Object.getPrototypeOf(value);
1077
- return prototype === Object.prototype || prototype === null;
1078
- }
1079
- __name(isPlainIntegrationDataObject, "isPlainIntegrationDataObject");
1080
- function sanitizeIntegrationDataValue(value) {
1081
- if (Array.isArray(value)) {
1082
- return value.map((item) => sanitizeIntegrationDataValue(item));
1083
- }
1084
- if (!isPlainIntegrationDataObject(value)) {
1085
- return value;
1086
- }
1087
- const sanitized = {};
1088
- for (const [key, item] of Object.entries(value)) {
1089
- if (BLOCKED_INTEGRATION_DATA_KEYS.has(key)) {
1090
- continue;
1091
- }
1092
- sanitized[key] = sanitizeIntegrationDataValue(item);
1093
- }
1094
- return sanitized;
1095
- }
1096
- __name(sanitizeIntegrationDataValue, "sanitizeIntegrationDataValue");
1097
- function normalizeIntegrationData(value) {
1098
- if (!isFarmIntegrationData(value)) {
1099
- return {};
1100
- }
1101
- const sanitized = sanitizeIntegrationDataValue(value);
1102
- return isFarmIntegrationData(sanitized) ? sanitized : {};
1103
- }
1104
- __name(normalizeIntegrationData, "normalizeIntegrationData");
1105
- function getIntegrationDataHeaderByteLength(value) {
1106
- return new TextEncoder().encode(value).byteLength;
1107
- }
1108
- __name(getIntegrationDataHeaderByteLength, "getIntegrationDataHeaderByteLength");
1109
- function parseIntegrationDataHeader(request) {
1110
- const raw = request.headers.get(INTEGRATION_DATA_HEADER);
1111
- if (!raw) {
1112
- return {};
1113
- }
1114
- if (getIntegrationDataHeaderByteLength(raw) > INTEGRATION_DATA_HEADER_MAX_LENGTH) {
1115
- return {};
1116
- }
1117
- try {
1118
- const value = JSON.parse(raw);
1119
- return normalizeIntegrationData(value);
1120
- } catch {
1121
- return {};
1122
- }
1123
- }
1124
- __name(parseIntegrationDataHeader, "parseIntegrationDataHeader");
1125
- function resolveIntegrationData(request, data) {
1126
- return {
1127
- ...parseIntegrationDataHeader(request),
1128
- ...normalizeIntegrationData(data)
1129
- };
1130
- }
1131
- __name(resolveIntegrationData, "resolveIntegrationData");
1132
- function normalizeIntegrationRoutes(routes) {
1133
- return routes.map((route2) => ({
1134
- ...route2,
1135
- methods: normalizeIntegrationRouteMethods(route2),
1136
- input: normalizeIntegrationRouteInputSchemas(route2)
1137
- }));
1138
- }
1139
- __name(normalizeIntegrationRoutes, "normalizeIntegrationRoutes");
1140
- function normalizeIntegrationRouteMethods(route2) {
1141
- const input = route2.methods && route2.methods.length > 0 ? [...route2.methods] : route2.method ? [route2.method] : ["ALL"];
1142
- return input.map((method) => String(method).toUpperCase());
1143
- }
1144
- __name(normalizeIntegrationRouteMethods, "normalizeIntegrationRouteMethods");
1145
- function normalizeIntegrationRouteInputSchemas(route2) {
1146
- const input = {
1147
- ...route2.input
1148
- };
1149
- if (route2.body) {
1150
- input.body = route2.body;
1151
- }
1152
- if (route2.query) {
1153
- input.query = route2.query;
1154
- }
1155
- return input.body || input.query ? input : void 0;
1156
- }
1157
- __name(normalizeIntegrationRouteInputSchemas, "normalizeIntegrationRouteInputSchemas");
1158
- async function validateIntegrationRouteInput(route2, request, url) {
1159
- const schemas = route2.input;
1160
- if (!schemas?.body && !schemas?.query) {
1161
- return {
1162
- success: true,
1163
- input: {}
1164
- };
1165
- }
1166
- const input = {};
1167
- const issues = [];
1168
- if (schemas.query) {
1169
- const queryResult = await parseIntegrationInputSchema(
1170
- "query",
1171
- schemas.query,
1172
- createQueryInput(url.searchParams)
1173
- );
1174
- if (queryResult.success) {
1175
- input.query = queryResult.data;
1176
- } else {
1177
- issues.push(...queryResult.issues);
1178
- }
1179
- }
1180
- if (schemas.body) {
1181
- const bodyInput = await readIntegrationValidationBody(
1182
- request,
1183
- getIntegrationRouteBodyFormat(route2)
1184
- );
1185
- if (bodyInput.success) {
1186
- const bodyResult = await parseIntegrationInputSchema("body", schemas.body, bodyInput.data);
1187
- if (bodyResult.success) {
1188
- input.body = bodyResult.data;
1189
- } else {
1190
- issues.push(...bodyResult.issues);
1191
- }
1192
- } else {
1193
- issues.push(bodyInput.issue);
1194
- }
1195
- }
1196
- if (issues.length > 0) {
1197
- return {
1198
- success: false,
1199
- response: createIntegrationValidationResponse(issues)
1200
- };
1201
- }
1202
- return {
1203
- success: true,
1204
- input
1205
- };
1206
- }
1207
- __name(validateIntegrationRouteInput, "validateIntegrationRouteInput");
1208
- async function parseIntegrationInputSchema(source, schema, value) {
1209
- const parser = schema.safeParseAsync || schema.safeParse;
1210
- if (parser) {
1211
- const result = await parser.call(schema, value);
1212
- if (result.success) {
1213
- return {
1214
- success: true,
1215
- data: result.data
1216
- };
1217
- }
1218
- return {
1219
- success: false,
1220
- issues: normalizeIntegrationValidationIssues(source, result.error)
1221
- };
1222
- }
1223
- if (schema["~standard"]?.validate) {
1224
- const result = await schema["~standard"].validate(value);
1225
- if ("value" in result) {
1226
- return {
1227
- success: true,
1228
- data: result.value
1229
- };
1230
- }
1231
- return {
1232
- success: false,
1233
- issues: normalizeIntegrationValidationIssues(source, {
1234
- issues: result.issues
1235
- })
1236
- };
1237
- }
1238
- if (schema.parse) {
1239
- try {
1240
- return {
1241
- success: true,
1242
- data: await schema.parse(value)
1243
- };
1244
- } catch (error) {
1245
- return {
1246
- success: false,
1247
- issues: normalizeIntegrationValidationIssues(
1248
- source,
1249
- normalizeIntegrationValidationError(error)
1250
- )
1251
- };
1252
- }
1253
- }
1254
- return {
1255
- success: false,
1256
- issues: [
1257
- {
1258
- source,
1259
- message: "Input schema must expose safeParse, safeParseAsync, parse, or ~standard.validate."
1260
- }
1261
- ]
1262
- };
1263
- }
1264
- __name(parseIntegrationInputSchema, "parseIntegrationInputSchema");
1265
- function createIntegrationValidationResponse(issues) {
1266
- return Response.json(
1267
- {
1268
- error: "Integration route input validation failed",
1269
- issues
1270
- },
1271
- {
1272
- status: 400
1273
- }
1274
- );
1275
- }
1276
- __name(createIntegrationValidationResponse, "createIntegrationValidationResponse");
1277
- function normalizeIntegrationValidationIssues(source, error) {
1278
- if (Array.isArray(error.issues) && error.issues.length > 0) {
1279
- return error.issues.map((issue) => ({
1280
- source,
1281
- path: normalizeIntegrationValidationPath(issue.path),
1282
- code: issue.code,
1283
- message: issue.message || "Invalid input"
1284
- }));
1285
- }
1286
- return [
1287
- {
1288
- source,
1289
- path: [],
1290
- message: error.message || "Invalid input"
1291
- }
1292
- ];
1293
- }
1294
- __name(normalizeIntegrationValidationIssues, "normalizeIntegrationValidationIssues");
1295
- function normalizeIntegrationValidationPath(path) {
1296
- return (path || []).map((segment) => {
1297
- const key = typeof segment === "object" && segment !== null && "key" in segment ? segment.key : segment;
1298
- return typeof key === "symbol" ? key.description || key.toString() : key;
1299
- });
1300
- }
1301
- __name(normalizeIntegrationValidationPath, "normalizeIntegrationValidationPath");
1302
- function normalizeIntegrationValidationError(error) {
1303
- if (error && typeof error === "object") {
1304
- return error;
1305
- }
1306
- return {
1307
- message: error instanceof Error ? error.message : String(error || "Invalid input")
1308
- };
1309
- }
1310
- __name(normalizeIntegrationValidationError, "normalizeIntegrationValidationError");
1311
- async function readIntegrationValidationBody(request, format) {
1312
- if (request.method === "GET" || request.method === "HEAD" || format === "none") {
1313
- return {
1314
- success: true,
1315
- data: void 0
1316
- };
1317
- }
1318
- try {
1319
- if (format === "form") {
1320
- return {
1321
- success: true,
1322
- data: createFormInput(await request.clone().formData())
1323
- };
1324
- }
1325
- const text = await request.clone().text();
1326
- if (text.trim().length === 0) {
1327
- return {
1328
- success: true,
1329
- data: void 0
1330
- };
1331
- }
1332
- return {
1333
- success: true,
1334
- data: JSON.parse(text)
1335
- };
1336
- } catch (error) {
1337
- return {
1338
- success: false,
1339
- issue: {
1340
- source: "body",
1341
- path: [],
1342
- message: format === "json" ? "Expected a valid JSON request body." : error instanceof Error && error.message ? error.message : "Could not parse request body."
1343
- }
1344
- };
1345
- }
1346
- }
1347
- __name(readIntegrationValidationBody, "readIntegrationValidationBody");
1348
- function getIntegrationRouteBodyFormat(route2) {
1349
- return route2.bodyFormat || route2.__operation?.bodyFormat || "json";
1350
- }
1351
- __name(getIntegrationRouteBodyFormat, "getIntegrationRouteBodyFormat");
1352
- function createIntegrationRouteArgs(input) {
1353
- let clientPromise;
1354
- let ormPromise;
1355
- const getClient = /* @__PURE__ */ __name(() => {
1356
- clientPromise ?? (clientPromise = Promise.resolve().then(() => (init_storage(), storage_exports)).then(
1357
- ({ resolveStorageRuntimeClient: resolveStorageRuntimeClient2 }) => resolveStorageRuntimeClient2(input.config.storage)
1358
- ));
1359
- return clientPromise;
1360
- }, "getClient");
1361
- const getOrm = /* @__PURE__ */ __name(() => {
1362
- if (!input.integration.schema) {
1363
- throw new Error(
1364
- `Integration "${input.integration.type}" does not define a schema for ctx.args.db.`
1365
- );
1366
- }
1367
- ormPromise ?? (ormPromise = Promise.resolve().then(() => (init_integration_orm(), integration_orm_exports)).then(
1368
- ({ createIntegrationOrm: createIntegrationOrm2 }) => createIntegrationOrm2({
1369
- schema: input.integration.schema,
1370
- config: input.config
1371
- })
1372
- ));
1373
- return ormPromise;
1374
- }, "getOrm");
1375
- return {
1376
- db: createLazyIntegrationOrmClient(getOrm),
1377
- getDb: getOrm,
1378
- storage: {
1379
- getClient,
1380
- getOrm
1381
- }
1382
- };
1383
- }
1384
- __name(createIntegrationRouteArgs, "createIntegrationRouteArgs");
1385
- function createLazyIntegrationOrmClient(resolveOrm) {
1386
- const modelProxyCache = /* @__PURE__ */ new Map();
1387
- return new Proxy(
1388
- {},
1389
- {
1390
- get(_target, prop) {
1391
- if (prop === "then") {
1392
- return void 0;
1393
- }
1394
- if (prop === "transaction" || prop === "batch") {
1395
- return async (...args) => {
1396
- const orm = await resolveOrm();
1397
- const member = orm[prop];
1398
- if (typeof member !== "function") {
1399
- throw new Error(`Integration ORM does not expose "${String(prop)}".`);
1400
- }
1401
- return member.apply(orm, args);
1402
- };
1403
- }
1404
- if (prop === "$driver") {
1405
- return void 0;
1406
- }
1407
- if (!modelProxyCache.has(prop)) {
1408
- modelProxyCache.set(prop, createLazyIntegrationOrmModel(resolveOrm, prop));
1409
- }
1410
- return modelProxyCache.get(prop);
1411
- }
1412
- }
1413
- );
1414
- }
1415
- __name(createLazyIntegrationOrmClient, "createLazyIntegrationOrmClient");
1416
- function createLazyIntegrationOrmModel(resolveOrm, modelName) {
1417
- return new Proxy(
1418
- {},
1419
- {
1420
- get(_target, prop) {
1421
- if (prop === "then") {
1422
- return void 0;
1423
- }
1424
- return async (...args) => {
1425
- const orm = await resolveOrm();
1426
- const model = orm[modelName];
1427
- const member = model?.[prop];
1428
- if (typeof member !== "function") {
1429
- throw new Error(
1430
- `Integration ORM model "${String(modelName)}" does not expose "${String(prop)}".`
1431
- );
1432
- }
1433
- return member.apply(model, args);
1434
- };
1435
- }
1436
- }
1437
- );
1438
- }
1439
- __name(createLazyIntegrationOrmModel, "createLazyIntegrationOrmModel");
1440
- async function runIntegrationRouteBeforeHooks(route2, request, context) {
1441
- const hookContext = context;
1442
- hookContext.response = void 0;
1443
- for (const hook of route2.before || []) {
1444
- const response = await hook(request, hookContext);
1445
- if (response) {
1446
- hookContext.response = response;
1447
- return response;
1448
- }
1449
- if (hookContext.response) {
1450
- return hookContext.response;
1451
- }
1452
- }
1453
- return void 0;
1454
- }
1455
- __name(runIntegrationRouteBeforeHooks, "runIntegrationRouteBeforeHooks");
1456
- async function runIntegrationRouteAfterHooks(route2, request, context, response) {
1457
- const hookContext = context;
1458
- let currentResponse = response;
1459
- for (const hook of route2.after || []) {
1460
- hookContext.response = currentResponse;
1461
- const nextResponse = await hook(request, hookContext);
1462
- currentResponse = nextResponse || hookContext.response || currentResponse;
1463
- }
1464
- hookContext.response = currentResponse;
1465
- return currentResponse;
1466
- }
1467
- __name(runIntegrationRouteAfterHooks, "runIntegrationRouteAfterHooks");
1468
- function createQueryInput(searchParams) {
1469
- const input = {};
1470
- searchParams.forEach((value, key) => {
1471
- const existing = input[key];
1472
- if (existing === void 0) {
1473
- input[key] = value;
1474
- return;
1475
- }
1476
- input[key] = Array.isArray(existing) ? [...existing, value] : [existing, value];
1477
- });
1478
- return input;
1479
- }
1480
- __name(createQueryInput, "createQueryInput");
1481
- function createFormInput(formData) {
1482
- const input = {};
1483
- formData.forEach((value, key) => {
1484
- const existing = input[key];
1485
- if (existing === void 0) {
1486
- input[key] = value;
1487
- return;
1488
- }
1489
- input[key] = Array.isArray(existing) ? [...existing, value] : [existing, value];
1490
- });
1491
- return input;
1492
- }
1493
- __name(createFormInput, "createFormInput");
1494
- async function dispatchIntegrationRequest(runtime, request, options = {}) {
1495
- const integration = runtime.integration;
1496
- const url = new URL(request.url);
1497
- const pathname = url.pathname;
1498
- const requestId = request.headers.get("x-request-id") || options.currentRequest?.headers.get("x-request-id") || String(Date.now());
1499
- const routes = normalizeIntegrationRoutes(integration.routes || []);
1500
- const middleware = [...integration.middleware || []];
1501
- for (const entry of middleware) {
1502
- const params = resolveMatcherParams(entry.matcher, pathname);
1503
- if (!params) {
1504
- continue;
1505
- }
1506
- const handlerContext = createServerIntegrationHandlerContext({
1507
- runtime,
1508
- route: {
1509
- kind: "middleware",
1510
- path: normalizeMatcher(entry.matcher),
1511
- methods: ["ALL"]
1512
- },
1513
- request,
1514
- params,
1515
- pathname,
1516
- requestId,
1517
- currentRequest: options.currentRequest,
1518
- data: options.data,
1519
- internal: options.internal === true
1520
- });
1521
- const startedAt = Date.now();
1522
- await integration.log?.({
1523
- category: integration.category,
1524
- slot: integration.category,
1525
- type: integration.type,
1526
- phase: "request:start",
1527
- route: {
1528
- kind: "middleware",
1529
- path: normalizeMatcher(entry.matcher),
1530
- methods: ["ALL"]
1531
- },
1532
- request,
1533
- requestId,
1534
- context: handlerContext.req.snapshot()
1535
- });
1536
- try {
1537
- const response = await entry.handler(request, handlerContext);
1538
- if (response) {
1539
- await integration.log?.({
1540
- category: integration.category,
1541
- slot: integration.category,
1542
- type: integration.type,
1543
- phase: "request:end",
1544
- route: {
1545
- kind: "middleware",
1546
- path: normalizeMatcher(entry.matcher),
1547
- methods: ["ALL"]
1548
- },
1549
- request,
1550
- response,
1551
- requestId,
1552
- durationMs: Date.now() - startedAt,
1553
- context: handlerContext.req.snapshot()
1554
- });
1555
- return response;
1556
- }
1557
- await integration.log?.({
1558
- category: integration.category,
1559
- slot: integration.category,
1560
- type: integration.type,
1561
- phase: "request:end",
1562
- route: {
1563
- kind: "middleware",
1564
- path: normalizeMatcher(entry.matcher),
1565
- methods: ["ALL"]
1566
- },
1567
- request,
1568
- requestId,
1569
- durationMs: Date.now() - startedAt,
1570
- context: handlerContext.req.snapshot()
1571
- });
1572
- } catch (error) {
1573
- await integration.log?.({
1574
- category: integration.category,
1575
- slot: integration.category,
1576
- type: integration.type,
1577
- phase: "request:error",
1578
- route: {
1579
- kind: "middleware",
1580
- path: normalizeMatcher(entry.matcher),
1581
- methods: ["ALL"]
1582
- },
1583
- request,
1584
- requestId,
1585
- durationMs: Date.now() - startedAt,
1586
- error,
1587
- context: handlerContext.req.snapshot()
1588
- });
1589
- throw error;
1590
- }
1591
- }
1592
- for (const route2 of routes) {
1593
- const params = matchesMethod(route2.methods, request.method) ? extractPathParams(route2.path, pathname) : null;
1594
- if (!params) {
1595
- continue;
1596
- }
1597
- const handlerContext = createServerIntegrationHandlerContext({
1598
- runtime,
1599
- route: {
1600
- kind: "route",
1601
- path: route2.path,
1602
- methods: route2.methods
1603
- },
1604
- request,
1605
- params,
1606
- pathname,
1607
- requestId,
1608
- currentRequest: options.currentRequest,
1609
- data: options.data,
1610
- internal: options.internal === true
1611
- });
1612
- const startedAt = Date.now();
1613
- await integration.log?.({
1614
- category: integration.category,
1615
- slot: integration.category,
1616
- type: integration.type,
1617
- phase: "request:start",
1618
- route: {
1619
- kind: "route",
1620
- path: route2.path,
1621
- methods: route2.methods
1622
- },
1623
- request,
1624
- requestId,
1625
- context: handlerContext.req.snapshot()
1626
- });
1627
- try {
1628
- const validation = await validateIntegrationRouteInput(route2, request, url);
1629
- if (!validation.success) {
1630
- await integration.log?.({
1631
- category: integration.category,
1632
- slot: integration.category,
1633
- type: integration.type,
1634
- phase: "request:end",
1635
- route: {
1636
- kind: "route",
1637
- path: route2.path,
1638
- methods: route2.methods
1639
- },
1640
- request,
1641
- response: validation.response,
1642
- requestId,
1643
- durationMs: Date.now() - startedAt,
1644
- context: handlerContext.req.snapshot()
1645
- });
1646
- return validation.response;
1647
- }
1648
- handlerContext.input = validation.input;
1649
- for (const middlewareEntry of route2.middleware || []) {
1650
- const middlewareResponse = await middlewareEntry.handler(request, handlerContext);
1651
- if (middlewareResponse) {
1652
- await integration.log?.({
1653
- category: integration.category,
1654
- slot: integration.category,
1655
- type: integration.type,
1656
- phase: "request:end",
1657
- route: {
1658
- kind: "route",
1659
- path: route2.path,
1660
- methods: route2.methods
1661
- },
1662
- request,
1663
- response: middlewareResponse,
1664
- requestId,
1665
- durationMs: Date.now() - startedAt,
1666
- context: handlerContext.req.snapshot()
1667
- });
1668
- return middlewareResponse;
1669
- }
1670
- }
1671
- const beforeResponse = await runIntegrationRouteBeforeHooks(route2, request, handlerContext);
1672
- if (beforeResponse) {
1673
- const response2 = await runIntegrationRouteAfterHooks(
1674
- route2,
1675
- request,
1676
- handlerContext,
1677
- beforeResponse
1678
- );
1679
- await integration.log?.({
1680
- category: integration.category,
1681
- slot: integration.category,
1682
- type: integration.type,
1683
- phase: "request:end",
1684
- route: {
1685
- kind: "route",
1686
- path: route2.path,
1687
- methods: route2.methods
1688
- },
1689
- request,
1690
- response: response2,
1691
- requestId,
1692
- durationMs: Date.now() - startedAt,
1693
- context: handlerContext.req.snapshot()
1694
- });
1695
- return response2;
1696
- }
1697
- const handlerResponse = await route2.handler(request, handlerContext);
1698
- const response = await runIntegrationRouteAfterHooks(
1699
- route2,
1700
- request,
1701
- handlerContext,
1702
- handlerResponse
1703
- );
1704
- await integration.log?.({
1705
- category: integration.category,
1706
- slot: integration.category,
1707
- type: integration.type,
1708
- phase: "request:end",
1709
- route: {
1710
- kind: "route",
1711
- path: route2.path,
1712
- methods: route2.methods
1713
- },
1714
- request,
1715
- response,
1716
- requestId,
1717
- durationMs: Date.now() - startedAt,
1718
- context: handlerContext.req.snapshot()
1719
- });
1720
- return response;
1721
- } catch (error) {
1722
- await integration.log?.({
1723
- category: integration.category,
1724
- slot: integration.category,
1725
- type: integration.type,
1726
- phase: "request:error",
1727
- route: {
1728
- kind: "route",
1729
- path: route2.path,
1730
- methods: route2.methods
1731
- },
1732
- request,
1733
- requestId,
1734
- durationMs: Date.now() - startedAt,
1735
- error,
1736
- context: handlerContext.req.snapshot()
1737
- });
1738
- throw error;
1739
- }
1740
- }
1741
- return null;
1742
- }
1743
- __name(dispatchIntegrationRequest, "dispatchIntegrationRequest");
1744
- globalThis[INTEGRATION_REQUEST_DISPATCHER_KEY] = dispatchIntegrationRequest;
1745
- function createServerIntegrationHandlerContext(input) {
1746
- const req = createServerIntegrationRequestContextStore(input.request, input.currentRequest);
1747
- if (input.internal) {
1748
- req.set(FARM_INTEGRATION_INTERNAL_DISPATCH_CONTEXT_KEY, true);
1749
- }
1750
- return {
1751
- request: input.request,
1752
- requestId: input.requestId,
1753
- url: new URL(input.request.url),
1754
- pathname: input.pathname,
1755
- method: input.request.method,
1756
- params: input.params,
1757
- input: {},
1758
- args: createIntegrationRouteArgs({
1759
- integration: input.runtime.integration,
1760
- config: input.runtime.config
1761
- }),
1762
- data: resolveIntegrationData(input.request, input.data),
1763
- integration: {
1764
- category: input.runtime.integration.category,
1765
- slot: input.runtime.integration.category,
1766
- type: input.runtime.integration.type,
1767
- instance: input.runtime.integration.instance
1768
- },
1769
- route: input.route,
1770
- req,
1771
- requestContext: req,
1772
- config: input.runtime.config,
1773
- isDev: input.runtime.isDev,
1774
- isProd: input.runtime.isProd
1775
- };
1776
- }
1777
- __name(createServerIntegrationHandlerContext, "createServerIntegrationHandlerContext");
1778
- function createServerIntegrationRequestContextStore(request, currentRequest) {
1779
- return {
1780
- get(key) {
1781
- const requestValue = getRequestContext(request, key);
1782
- if (requestValue !== void 0) {
1783
- return requestValue;
1784
- }
1785
- if (currentRequest) {
1786
- return getRequestContext(currentRequest, key);
1787
- }
1788
- return void 0;
1789
- },
1790
- set(key, value, options) {
1791
- setRequestContext(request, key, value, options);
1792
- if (currentRequest) {
1793
- setRequestContext(currentRequest, key, value, options);
1794
- }
1795
- },
1796
- has(key) {
1797
- return hasRequestContext(request, key) || !!currentRequest && hasRequestContext(currentRequest, key);
1798
- },
1799
- delete(key) {
1800
- const deletedRequest = deleteRequestContext(request, key);
1801
- const deletedCurrent = currentRequest ? deleteRequestContext(currentRequest, key) : false;
1802
- return deletedRequest || deletedCurrent;
1803
- },
1804
- clear() {
1805
- clearRequestContext(request);
1806
- if (currentRequest) {
1807
- clearRequestContext(currentRequest);
1808
- }
1809
- },
1810
- snapshot(options) {
1811
- const merged = currentRequest ? getRequestContextSnapshot(currentRequest, options) : /* @__PURE__ */ new Map();
1812
- const requestSnapshot = getRequestContextSnapshot(request, options);
1813
- for (const [key, value] of requestSnapshot) {
1814
- merged.set(key, value);
1815
- }
1816
- return merged;
1817
- }
1818
- };
1819
- }
1820
- __name(createServerIntegrationRequestContextStore, "createServerIntegrationRequestContextStore");
1821
- function matchesMethod(methods, method) {
1822
- if (!method) {
1823
- return false;
1824
- }
1825
- return methods.some((item) => item.toUpperCase() === method.toUpperCase());
1826
- }
1827
- __name(matchesMethod, "matchesMethod");
1828
- function resolveMatcherParams(matcher, pathname) {
1829
- if (!matcher) {
1830
- return {};
1831
- }
1832
- const list = Array.isArray(matcher) ? matcher : [matcher];
1833
- for (const item of list) {
1834
- if (item === "/(.*)" || item === "*") {
1835
- return {};
1836
- }
1837
- if (item.endsWith("(.*)")) {
1838
- const prefix = item.slice(0, -4);
1839
- if (pathname === prefix || pathname.startsWith(`${prefix}/`)) {
1840
- return {};
1841
- }
1842
- continue;
1843
- }
1844
- const params = extractPathParams(item, pathname);
1845
- if (params) {
1846
- return params;
1847
- }
1848
- }
1849
- return null;
1850
- }
1851
- __name(resolveMatcherParams, "resolveMatcherParams");
1852
- function extractPathParams(pattern, pathname) {
1853
- const routeSegments = splitPath(pattern);
1854
- const pathSegments = splitPath(pathname);
1855
- const params = {};
1856
- let routeIndex = 0;
1857
- let pathIndex = 0;
1858
- while (routeIndex < routeSegments.length && pathIndex < pathSegments.length) {
1859
- const routeSegment = routeSegments[routeIndex];
1860
- const pathSegment = pathSegments[pathIndex];
1861
- if (isCatchAllSegment(routeSegment)) {
1862
- params[getSegmentParamName(routeSegment)] = pathSegments.slice(pathIndex).map((segment) => decodeURIComponent(segment));
1863
- return params;
1864
- }
1865
- if (isDynamicSegment(routeSegment)) {
1866
- params[getSegmentParamName(routeSegment)] = decodeURIComponent(pathSegment);
1867
- routeIndex += 1;
1868
- pathIndex += 1;
1869
- continue;
1870
- }
1871
- if (routeSegment !== pathSegment) {
1872
- return null;
1873
- }
1874
- routeIndex += 1;
1875
- pathIndex += 1;
1876
- }
1877
- if (routeIndex === routeSegments.length && pathIndex === pathSegments.length) {
1878
- return params;
1879
- }
1880
- if (routeIndex === routeSegments.length - 1 && isCatchAllSegment(routeSegments[routeIndex])) {
1881
- params[getSegmentParamName(routeSegments[routeIndex])] = [];
1882
- return params;
1883
- }
1884
- return null;
1885
- }
1886
- __name(extractPathParams, "extractPathParams");
1887
- function splitPath(value) {
1888
- return value.split("/").filter(Boolean);
1889
- }
1890
- __name(splitPath, "splitPath");
1891
- function isDynamicSegment(segment) {
1892
- return segment.startsWith("[") && segment.endsWith("]");
1893
- }
1894
- __name(isDynamicSegment, "isDynamicSegment");
1895
- function isCatchAllSegment(segment) {
1896
- return segment.startsWith("[...") && segment.endsWith("]");
1897
- }
1898
- __name(isCatchAllSegment, "isCatchAllSegment");
1899
- function getSegmentParamName(segment) {
1900
- if (isCatchAllSegment(segment)) {
1901
- return segment.slice(4, -1);
1902
- }
1903
- return segment.slice(1, -1);
1904
- }
1905
- __name(getSegmentParamName, "getSegmentParamName");
1906
- function normalizeMatcher(matcher) {
1907
- if (!matcher) {
1908
- return "/(.*)";
1909
- }
1910
- return typeof matcher === "string" ? matcher : matcher.join(", ");
1911
- }
1912
- __name(normalizeMatcher, "normalizeMatcher");
1913
-
1914
- // src/agent-runtime.ts
1915
- var AGENT_RUNTIME_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "HEAD"];
1916
- var HOP_BY_HOP_HEADERS = [
1917
- "connection",
1918
- "keep-alive",
1919
- "proxy-authenticate",
1920
- "proxy-authorization",
1921
- "te",
1922
- "trailer",
1923
- "transfer-encoding",
1924
- "upgrade"
1925
- ];
1926
- function createAgentRuntimeIntegration(options) {
1927
- const provider = normalizeProviderName(options.provider);
1928
- const routePrefix = normalizeAgentRoutePrefix(options.routePrefix);
1929
- const routePrefixes = [
1930
- routePrefix,
1931
- ...(options.additionalRoutePrefixes || []).map(normalizeAgentRoutePrefix)
1932
- ].filter((prefix, index, values) => values.indexOf(prefix) === index);
1933
- const originEnv = normalizeOriginEnv(options.originEnv);
1934
- const state = {
1935
- origin: resolveConfiguredOrigin(options.origin, originEnv)
1936
- };
1937
- const runtimeInstance = {
1938
- ...options.instance,
1939
- provider,
1940
- routePrefix,
1941
- routePrefixes,
1942
- getOrigin: /* @__PURE__ */ __name(() => state.origin ?? resolveConfiguredOrigin(options.origin, originEnv), "getOrigin")
1943
- };
1944
- const runtimePlugin = {
1945
- name: `farm:agent-runtime:${provider}`,
1946
- config(config, context) {
1947
- if (!context.isDev) {
1948
- return config;
1949
- }
1950
- const origin = runtimeInstance.getOrigin();
1951
- if (!origin) {
1952
- return config;
1953
- }
1954
- for (const prefix of routePrefixes) {
1955
- applyAgentRuntimeViteProxy(config, {
1956
- origin,
1957
- routePrefix: prefix,
1958
- webSockets: options.webSockets
1959
- });
1960
- }
1961
- return config;
1962
- },
1963
- async afterBundle(result) {
1964
- if (!result.success || !options.afterBuild) {
1965
- return;
1966
- }
1967
- await options.afterBuild({
1968
- ...result,
1969
- provider,
1970
- routePrefix,
1971
- routePrefixes
1972
- });
1973
- }
1974
- };
1975
- return defineIntegration({
1976
- category: "agent",
1977
- type: provider,
1978
- serverRuntime: options.serverRuntime,
1979
- instance: runtimeInstance,
1980
- async setup(context) {
1981
- if (!context.isDev || state.origin || !options.startDev) {
1982
- return;
1983
- }
1984
- state.managed = await options.startDev({
1985
- root: context.appConfig.root || process.cwd(),
1986
- log: context.log
1987
- });
1988
- state.origin = normalizeAgentOrigin(state.managed.origin);
1989
- context.log.info(`${provider} runtime ready`, {
1990
- origin: state.origin
1991
- });
1992
- await context.cleanup(async () => {
1993
- await state.managed?.stop();
1994
- state.managed = void 0;
1995
- state.origin = void 0;
1996
- });
1997
- },
1998
- routes: routePrefixes.map((prefix) => ({
1999
- path: `${prefix}/[...farmAgentRuntimePath]`,
2000
- methods: AGENT_RUNTIME_METHODS,
2001
- rawBody: true,
2002
- async handler(request) {
2003
- const origin = runtimeInstance.getOrigin();
2004
- if (!origin) {
2005
- return Response.json(
2006
- {
2007
- error: "Agent runtime unavailable",
2008
- provider
2009
- },
2010
- { status: 503 }
2011
- );
2012
- }
2013
- return proxyAgentRuntimeRequest(request, origin);
2014
- }
2015
- })),
2016
- plugins: [runtimePlugin, ...options.plugins || []]
2017
- });
2018
- }
2019
- __name(createAgentRuntimeIntegration, "createAgentRuntimeIntegration");
2020
- function applyAgentRuntimeViteProxy(config, input) {
2021
- const origin = normalizeAgentOrigin(input.origin);
2022
- const routePrefix = normalizeAgentRoutePrefix(input.routePrefix);
2023
- const vite = config.vite || {};
2024
- const server = vite.server || {};
2025
- const proxy = server.proxy || {};
2026
- if (proxy[routePrefix]) {
2027
- throw new Error(
2028
- `Farm agent runtime cannot own ${routePrefix} because vite.server.proxy already defines it.`
2029
- );
2030
- }
2031
- config.vite = {
2032
- ...vite,
2033
- server: {
2034
- ...server,
2035
- proxy: {
2036
- ...proxy,
2037
- [routePrefix]: {
2038
- target: origin,
2039
- changeOrigin: true,
2040
- ws: input.webSockets === true
2041
- }
2042
- }
2043
- }
2044
- };
2045
- }
2046
- __name(applyAgentRuntimeViteProxy, "applyAgentRuntimeViteProxy");
2047
- async function proxyAgentRuntimeRequest(request, origin, options = {}) {
2048
- const upstreamOrigin = normalizeAgentOrigin(origin);
2049
- const incomingUrl = new URL(request.url);
2050
- const targetUrl = new URL(`${incomingUrl.pathname}${incomingUrl.search}`, upstreamOrigin);
2051
- const headers = createProxyRequestHeaders(request.headers, incomingUrl);
2052
- const method = request.method.toUpperCase();
2053
- const init = {
2054
- method,
2055
- headers,
2056
- redirect: "manual",
2057
- signal: request.signal
2058
- };
2059
- if (method !== "GET" && method !== "HEAD" && request.body) {
2060
- init.body = request.body;
2061
- init.duplex = "half";
2062
- }
2063
- try {
2064
- const upstream = await (options.fetch || globalThis.fetch)(targetUrl, init);
2065
- const responseHeaders = new Headers(upstream.headers);
2066
- removeHopByHopHeaders(responseHeaders);
2067
- rewriteProxyLocation(responseHeaders, upstreamOrigin, incomingUrl.origin);
2068
- return new Response(upstream.body, {
2069
- status: upstream.status,
2070
- statusText: upstream.statusText,
2071
- headers: responseHeaders
2072
- });
2073
- } catch (error) {
2074
- if (request.signal.aborted || isAbortError(error)) {
2075
- throw error;
2076
- }
2077
- return Response.json(
2078
- {
2079
- error: "Agent runtime request failed"
2080
- },
2081
- { status: 502 }
2082
- );
2083
- }
2084
- }
2085
- __name(proxyAgentRuntimeRequest, "proxyAgentRuntimeRequest");
2086
- async function startManagedAgentRuntime(options) {
2087
- const timeoutMs = options.timeoutMs ?? 3e4;
2088
- const stopTimeoutMs = options.stopTimeoutMs ?? 2e3;
2089
- const fixedOrigin = options.origin ? normalizeAgentOrigin(options.origin) : void 0;
2090
- let output = "";
2091
- let settled = false;
2092
- let checkingReadiness = false;
2093
- const child = (0, import_node_child_process.spawn)(options.command, [...options.args || []], {
2094
- cwd: options.cwd,
2095
- env: {
2096
- ...process.env,
2097
- ...options.env
2098
- },
2099
- stdio: ["ignore", "pipe", "pipe"]
2100
- });
2101
- const origin = await new Promise((resolveOrigin, reject) => {
2102
- let timer;
2103
- const finish = /* @__PURE__ */ __name(() => {
2104
- if (settled) return;
2105
- settled = true;
2106
- clearTimeout(timer);
2107
- child.off("error", onError);
2108
- child.off("exit", onExit);
2109
- }, "finish");
2110
- const succeed = /* @__PURE__ */ __name(async (candidate) => {
2111
- if (settled || checkingReadiness) return;
2112
- checkingReadiness = true;
2113
- try {
2114
- const normalized = normalizeAgentOrigin(candidate);
2115
- await waitForAgentRuntime(normalized, options.healthPath, timeoutMs, child);
2116
- finish();
2117
- resolveOrigin(normalized);
2118
- } catch (error) {
2119
- finish();
2120
- terminateChild(child);
2121
- reject(error);
2122
- }
2123
- }, "succeed");
2124
- timer = setTimeout(() => {
2125
- finish();
2126
- terminateChild(child);
2127
- reject(new Error(`${options.label} did not become ready within ${timeoutMs}ms.`));
2128
- }, timeoutMs);
2129
- const onError = /* @__PURE__ */ __name((error) => {
2130
- finish();
2131
- reject(error);
2132
- }, "onError");
2133
- const onExit = /* @__PURE__ */ __name((code, signal) => {
2134
- finish();
2135
- reject(
2136
- new Error(
2137
- `${options.label} exited before it was ready (code ${String(code)}, signal ${String(signal)}).`
2138
- )
2139
- );
2140
- }, "onExit");
2141
- const onData = /* @__PURE__ */ __name((chunk, stream) => {
2142
- const text = chunk.toString("utf8");
2143
- output = `${output}${text}`.slice(-16384);
2144
- emitProcessOutput(text, stream, options.onOutput);
2145
- if (!fixedOrigin && options.resolveOrigin) {
2146
- const candidate = options.resolveOrigin(output);
2147
- if (candidate) {
2148
- void succeed(candidate);
2149
- }
2150
- }
2151
- }, "onData");
2152
- child.once("error", onError);
2153
- child.once("exit", onExit);
2154
- child.stdout?.on("data", (chunk) => onData(chunk, "stdout"));
2155
- child.stderr?.on("data", (chunk) => onData(chunk, "stderr"));
2156
- if (fixedOrigin) {
2157
- void succeed(fixedOrigin);
2158
- }
2159
- });
2160
- return {
2161
- origin,
2162
- process: child,
2163
- async stop() {
2164
- if (child.exitCode !== null || child.signalCode !== null) {
2165
- return;
2166
- }
2167
- child.kill("SIGTERM");
2168
- const exited = await waitForChildExit(child, stopTimeoutMs);
2169
- if (!exited && child.exitCode === null && child.signalCode === null) {
2170
- child.kill("SIGKILL");
2171
- await waitForChildExit(child, stopTimeoutMs);
2172
- }
2173
- }
2174
- };
2175
- }
2176
- __name(startManagedAgentRuntime, "startManagedAgentRuntime");
2177
- async function findAvailableAgentRuntimePort(host = "127.0.0.1") {
2178
- return await new Promise((resolvePort, reject) => {
2179
- const server = (0, import_node_net.createServer)();
2180
- server.unref();
2181
- server.once("error", reject);
2182
- server.listen(0, host, () => {
2183
- const address = server.address();
2184
- if (!address || typeof address === "string") {
2185
- server.close();
2186
- reject(new Error("Unable to allocate an agent runtime port."));
2187
- return;
2188
- }
2189
- const port = address.port;
2190
- server.close((error) => {
2191
- if (error) reject(error);
2192
- else resolvePort(port);
2193
- });
2194
- });
2195
- });
2196
- }
2197
- __name(findAvailableAgentRuntimePort, "findAvailableAgentRuntimePort");
2198
- async function resolveProjectPackageBin(projectRoot, packageName, binName) {
2199
- const root = (0, import_node_path.resolve)(projectRoot);
2200
- const projectRequire = (0, import_node_module.createRequire)((0, import_node_path.join)(root, "package.json"));
2201
- let packageJsonPath;
2202
- try {
2203
- packageJsonPath = projectRequire.resolve(`${packageName}/package.json`);
2204
- } catch {
2205
- throw new Error(
2206
- `${packageName} is required by this agent integration. Install it in ${root} and try again.`
2207
- );
2208
- }
2209
- const packageJson = JSON.parse(await (0, import_promises.readFile)(packageJsonPath, "utf8"));
2210
- const bin = typeof packageJson.bin === "string" ? packageJson.bin : packageJson.bin?.[binName || packageName.split("/").at(-1) || packageName];
2211
- if (!bin) {
2212
- throw new Error(
2213
- `${packageName} does not expose the expected ${binName || packageName} binary.`
2214
- );
2215
- }
2216
- const packageRoot = (0, import_node_path.dirname)(packageJsonPath);
2217
- const binaryPath = (0, import_node_path.resolve)(packageRoot, bin);
2218
- if ((0, import_node_path.relative)(packageRoot, binaryPath).startsWith("..") || (0, import_node_path.isAbsolute)((0, import_node_path.relative)(packageRoot, binaryPath))) {
2219
- throw new Error(`${packageName} exposes a binary outside its package root.`);
2220
- }
2221
- return binaryPath;
2222
- }
2223
- __name(resolveProjectPackageBin, "resolveProjectPackageBin");
2224
- function normalizeAgentOrigin(value) {
2225
- const input = value.trim();
2226
- if (!input) {
2227
- throw new Error("Agent runtime origin cannot be empty.");
2228
- }
2229
- const url = new URL(input);
2230
- if (url.protocol !== "http:" && url.protocol !== "https:") {
2231
- throw new Error("Agent runtime origin must use http or https.");
2232
- }
2233
- if (url.username || url.password) {
2234
- throw new Error("Agent runtime origin cannot contain credentials.");
2235
- }
2236
- if (url.pathname !== "/" || url.search || url.hash) {
2237
- throw new Error("Agent runtime origin must not contain a path, query, or hash.");
2238
- }
2239
- return url.origin;
2240
- }
2241
- __name(normalizeAgentOrigin, "normalizeAgentOrigin");
2242
- function normalizeAgentRoutePrefix(value) {
2243
- const normalized = `/${value.trim()}`.replace(/\/{2,}/g, "/");
2244
- if (normalized === "/") {
2245
- throw new Error("Agent runtime route prefix cannot own the application root.");
2246
- }
2247
- return normalized.replace(/\/$/, "");
2248
- }
2249
- __name(normalizeAgentRoutePrefix, "normalizeAgentRoutePrefix");
2250
- function normalizeProviderName(value) {
2251
- const provider = value.trim();
2252
- if (!provider || !/^[a-z0-9][a-z0-9._-]*$/i.test(provider)) {
2253
- throw new Error("Agent runtime provider must be a non-empty package-style name.");
2254
- }
2255
- return provider;
2256
- }
2257
- __name(normalizeProviderName, "normalizeProviderName");
2258
- function normalizeOriginEnv(value) {
2259
- if (!value) return [];
2260
- return (Array.isArray(value) ? value : [value]).map((entry) => entry.trim()).filter(Boolean);
2261
- }
2262
- __name(normalizeOriginEnv, "normalizeOriginEnv");
2263
- function resolveConfiguredOrigin(configuredOrigin, envNames) {
2264
- if (configuredOrigin) {
2265
- return normalizeAgentOrigin(configuredOrigin);
2266
- }
2267
- for (const envName of envNames) {
2268
- const value = process.env[envName];
2269
- if (value?.trim()) {
2270
- return normalizeAgentOrigin(value);
2271
- }
2272
- }
2273
- return void 0;
2274
- }
2275
- __name(resolveConfiguredOrigin, "resolveConfiguredOrigin");
2276
- function createProxyRequestHeaders(input, incomingUrl) {
2277
- const headers = new Headers(input);
2278
- removeHopByHopHeaders(headers);
2279
- headers.delete("host");
2280
- headers.delete("content-length");
2281
- headers.delete("accept-encoding");
2282
- if (!headers.has("x-forwarded-host")) headers.set("x-forwarded-host", incomingUrl.host);
2283
- if (!headers.has("x-forwarded-proto")) {
2284
- headers.set("x-forwarded-proto", incomingUrl.protocol.replace(":", ""));
2285
- }
2286
- return headers;
2287
- }
2288
- __name(createProxyRequestHeaders, "createProxyRequestHeaders");
2289
- function removeHopByHopHeaders(headers) {
2290
- for (const header of HOP_BY_HOP_HEADERS) {
2291
- headers.delete(header);
2292
- }
2293
- }
2294
- __name(removeHopByHopHeaders, "removeHopByHopHeaders");
2295
- function rewriteProxyLocation(headers, upstreamOrigin, incomingOrigin) {
2296
- const location = headers.get("location");
2297
- if (!location) return;
2298
- try {
2299
- const url = new URL(location, upstreamOrigin);
2300
- if (url.origin === upstreamOrigin) {
2301
- headers.set("location", `${incomingOrigin}${url.pathname}${url.search}${url.hash}`);
2302
- }
2303
- } catch {
2304
- }
2305
- }
2306
- __name(rewriteProxyLocation, "rewriteProxyLocation");
2307
- function isAbortError(error) {
2308
- return error instanceof Error && error.name === "AbortError";
2309
- }
2310
- __name(isAbortError, "isAbortError");
2311
- async function waitForAgentRuntime(origin, healthPath, timeoutMs, child) {
2312
- const deadline = Date.now() + timeoutMs;
2313
- const healthUrl = new URL(healthPath || "/", origin);
2314
- while (Date.now() < deadline) {
2315
- if (child.exitCode !== null || child.signalCode !== null) {
2316
- throw new Error("Agent runtime exited while Farm was waiting for it to become ready.");
2317
- }
2318
- const controller = new AbortController();
2319
- const timer = setTimeout(() => controller.abort(), 750);
2320
- try {
2321
- await fetch(healthUrl, {
2322
- signal: controller.signal,
2323
- redirect: "manual"
2324
- });
2325
- return;
2326
- } catch {
2327
- await delay(100);
2328
- } finally {
2329
- clearTimeout(timer);
2330
- }
2331
- }
2332
- throw new Error(`Agent runtime at ${origin} did not answer before the startup timeout.`);
2333
- }
2334
- __name(waitForAgentRuntime, "waitForAgentRuntime");
2335
- function emitProcessOutput(text, stream, onOutput) {
2336
- if (!onOutput) return;
2337
- for (const line of text.split(/\r?\n/)) {
2338
- const value = line.trimEnd();
2339
- if (value) onOutput(value, stream);
2340
- }
2341
- }
2342
- __name(emitProcessOutput, "emitProcessOutput");
2343
- function terminateChild(child) {
2344
- if (child.exitCode === null && child.signalCode === null) {
2345
- child.kill("SIGTERM");
2346
- }
2347
- }
2348
- __name(terminateChild, "terminateChild");
2349
- async function waitForChildExit(child, timeoutMs) {
2350
- if (child.exitCode !== null || child.signalCode !== null) return true;
2351
- return await new Promise((resolveExit) => {
2352
- const timer = setTimeout(() => {
2353
- child.off("exit", onExit);
2354
- resolveExit(false);
2355
- }, timeoutMs);
2356
- const onExit = /* @__PURE__ */ __name(() => {
2357
- clearTimeout(timer);
2358
- resolveExit(true);
2359
- }, "onExit");
2360
- child.once("exit", onExit);
2361
- });
2362
- }
2363
- __name(waitForChildExit, "waitForChildExit");
2364
- function delay(ms) {
2365
- return new Promise((resolveDelay) => setTimeout(resolveDelay, ms));
2366
- }
2367
- __name(delay, "delay");
2368
- // Annotate the CommonJS export names for ESM import in node:
2369
- 0 && (module.exports = {
2370
- applyAgentRuntimeViteProxy,
2371
- createAgentRuntimeIntegration,
2372
- findAvailableAgentRuntimePort,
2373
- normalizeAgentOrigin,
2374
- normalizeAgentRoutePrefix,
2375
- proxyAgentRuntimeRequest,
2376
- resolveProjectPackageBin,
2377
- startManagedAgentRuntime
2378
- });
2379
- //# sourceMappingURL=agent-runtime.cjs.map