@farm.js/core 0.1.16 → 0.1.18

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 (390) hide show
  1. package/dist/after.cjs +12 -225
  2. package/dist/agent-runtime.cjs +83 -2800
  3. package/dist/agent-runtime.d.mts +3 -3
  4. package/dist/agent-runtime.d.ts +3 -3
  5. package/dist/api/client.cjs +17 -4026
  6. package/dist/api/client.d.mts +3 -3
  7. package/dist/api/client.d.ts +3 -3
  8. package/dist/api/client.mjs +3 -3
  9. package/dist/api/route-manager.cjs +34 -4317
  10. package/dist/api/route-manager.d.mts +3 -3
  11. package/dist/api/route-manager.d.ts +3 -3
  12. package/dist/api/route-manager.mjs +5 -5
  13. package/dist/api/runtime.cjs +29 -2660
  14. package/dist/api/runtime.d.mts +3 -3
  15. package/dist/api/runtime.d.ts +3 -3
  16. package/dist/api/runtime.mjs +6 -3
  17. package/dist/{api-client-B-n3pm_Q.d.mts → api-client-Cx54IR5g.d.mts} +2 -2
  18. package/dist/{api-client-C0_NZEBl.d.ts → api-client-DykpaKcY.d.ts} +2 -2
  19. package/dist/api.cjs +88 -8361
  20. package/dist/api.d.mts +5 -5
  21. package/dist/api.d.ts +5 -5
  22. package/dist/api.mjs +8 -8
  23. package/dist/{app-AyjEsCBq.d.ts → app-BHY_10Lm.d.ts} +3 -3
  24. package/dist/{app-CYPHeOo_.d.mts → app-BMk0do23.d.mts} +3 -3
  25. package/dist/app-markdown.cjs +39 -280
  26. package/dist/app-markdown.d.mts +4 -4
  27. package/dist/app-markdown.d.ts +4 -4
  28. package/dist/app-markdown.mjs +3 -3
  29. package/dist/cache.cjs +38 -1526
  30. package/dist/cache.d.mts +11 -1
  31. package/dist/cache.d.ts +11 -1
  32. package/dist/cache.mjs +1 -1
  33. package/dist/chunk-22GUSVNJ.cjs +351 -0
  34. package/dist/chunk-2CQ74SP6.cjs +13 -0
  35. package/dist/chunk-2SJ4RQ6P.cjs +57 -0
  36. package/dist/chunk-3376ZTRC.cjs +1 -0
  37. package/dist/{chunk-IL5RWYK7.mjs → chunk-3XG26Z3J.mjs} +1 -1
  38. package/dist/{chunk-7HDZYYS4.mjs → chunk-4OOBRCJX.mjs} +27 -5
  39. package/dist/chunk-4PNUXIVU.cjs +472 -0
  40. package/dist/chunk-4PPEPOZZ.cjs +21 -0
  41. package/dist/chunk-4ZFL5GFN.cjs +520 -0
  42. package/dist/{chunk-B76DT5Y6.mjs → chunk-57J3Y7Y3.mjs} +1 -1
  43. package/dist/chunk-5OVTOKGH.cjs +65 -0
  44. package/dist/chunk-5QIKR7RR.cjs +224 -0
  45. package/dist/{chunk-MOQNHLTS.mjs → chunk-5QOEPUYE.mjs} +5 -2
  46. package/dist/{chunk-HKLRP3BN.mjs → chunk-5SPPCN5J.mjs} +1 -1
  47. package/dist/chunk-5ZSWG4UX.cjs +127 -0
  48. package/dist/chunk-62YJ2IEB.cjs +238 -0
  49. package/dist/chunk-6EODJYCX.cjs +183 -0
  50. package/dist/chunk-6EXBPJ24.cjs +434 -0
  51. package/dist/chunk-6QQDAAAZ.cjs +38 -0
  52. package/dist/chunk-6V4TDWEC.cjs +455 -0
  53. package/dist/{chunk-LUC2FAGW.mjs → chunk-6VQIKZZO.mjs} +1 -1
  54. package/dist/chunk-72ADZ6GQ.cjs +19 -0
  55. package/dist/chunk-75BRBIFP.cjs +172 -0
  56. package/dist/{chunk-7ZWL7XOU.mjs → chunk-76DG3LF3.mjs} +1 -1
  57. package/dist/chunk-7W3CPVXS.cjs +24 -0
  58. package/dist/chunk-A6WIQH5Z.cjs +31 -0
  59. package/dist/{chunk-EWDK36MM.mjs → chunk-A72YEUZ3.mjs} +1 -1
  60. package/dist/chunk-AFOD3LYZ.cjs +377 -0
  61. package/dist/chunk-AMDMVWMI.cjs +39 -0
  62. package/dist/chunk-AORPIPNB.cjs +552 -0
  63. package/dist/chunk-ARJWXNQL.cjs +256 -0
  64. package/dist/{chunk-ZHOIQC6U.mjs → chunk-ATERBVHQ.mjs} +2 -2
  65. package/dist/chunk-AWRISO2H.cjs +2199 -0
  66. package/dist/chunk-AYJR42WX.cjs +711 -0
  67. package/dist/chunk-B4CH33IG.cjs +644 -0
  68. package/dist/chunk-BIDYX3SL.cjs +91 -0
  69. package/dist/chunk-BSTRERPP.cjs +40 -0
  70. package/dist/chunk-BYODCJD6.cjs +663 -0
  71. package/dist/chunk-C3VRMB6H.cjs +85 -0
  72. package/dist/chunk-C5GUTBZK.cjs +173 -0
  73. package/dist/chunk-CIAGU2X4.cjs +337 -0
  74. package/dist/chunk-CMGMGHUZ.cjs +27 -0
  75. package/dist/chunk-CXP5U3RW.cjs +54 -0
  76. package/dist/chunk-D2ULAULS.cjs +166 -0
  77. package/dist/chunk-D7JTOLFK.cjs +285 -0
  78. package/dist/chunk-DVM4FKZL.cjs +169 -0
  79. package/dist/chunk-DYEJQTDN.cjs +49 -0
  80. package/dist/chunk-E2BMSZ2W.cjs +151 -0
  81. package/dist/chunk-E3UK5IIB.cjs +593 -0
  82. package/dist/chunk-EM6SBQKM.cjs +470 -0
  83. package/dist/{chunk-27JNCYEK.mjs → chunk-EN7WTEAY.mjs} +2 -2
  84. package/dist/{chunk-IGO2HEV7.mjs → chunk-F6SJAKFJ.mjs} +62 -28
  85. package/dist/{chunk-GSDIZACQ.mjs → chunk-FG5H2VCJ.mjs} +2 -2
  86. package/dist/chunk-FJSWYIR7.cjs +482 -0
  87. package/dist/chunk-FK6GO24V.cjs +54 -0
  88. package/dist/chunk-FXUUWYAX.cjs +654 -0
  89. package/dist/chunk-G3HRIVEY.cjs +395 -0
  90. package/dist/chunk-G643DQCH.cjs +13 -0
  91. package/dist/chunk-G7HXGLEC.cjs +175 -0
  92. package/dist/chunk-GDSHDTJ4.cjs +152 -0
  93. package/dist/chunk-GNEO2XOF.cjs +2040 -0
  94. package/dist/{chunk-NHHKW2T6.mjs → chunk-GYKJCFTS.mjs} +170 -52
  95. package/dist/chunk-H6G5INWM.cjs +1094 -0
  96. package/dist/chunk-HBTUGXHS.cjs +180 -0
  97. package/dist/chunk-HREOKQWT.cjs +45 -0
  98. package/dist/chunk-I4J452B7.cjs +435 -0
  99. package/dist/chunk-I57LW5VZ.cjs +94 -0
  100. package/dist/chunk-I7PUUDGY.cjs +389 -0
  101. package/dist/chunk-IAMRBF3Z.cjs +86 -0
  102. package/dist/chunk-IKNRN4VS.cjs +14214 -0
  103. package/dist/chunk-IQXFRNY2.cjs +169 -0
  104. package/dist/chunk-IXTFU4PL.cjs +2355 -0
  105. package/dist/chunk-J2OP5GG3.cjs +725 -0
  106. package/dist/chunk-J3LOGE4T.cjs +42 -0
  107. package/dist/chunk-J7FSKED3.cjs +93 -0
  108. package/dist/chunk-JDNHKPTD.cjs +22 -0
  109. package/dist/chunk-JSROZYYO.cjs +164 -0
  110. package/dist/chunk-K6FNHVDR.cjs +696 -0
  111. package/dist/chunk-KGZIORNL.cjs +43 -0
  112. package/dist/{chunk-LZK5CXDW.mjs → chunk-KLSSO6YD.mjs} +2 -2
  113. package/dist/{chunk-TYVVIQ5M.mjs → chunk-KPNVGRBL.mjs} +32 -25
  114. package/dist/chunk-KR6CKSXT.cjs +15 -0
  115. package/dist/chunk-KROWKCUH.cjs +185 -0
  116. package/dist/chunk-KVFPGF2M.cjs +46 -0
  117. package/dist/{chunk-KUO3GBPK.mjs → chunk-L6V3P73N.mjs} +1 -1
  118. package/dist/chunk-LCCBO7PJ.cjs +46 -0
  119. package/dist/chunk-LIUGYUX3.cjs +22 -0
  120. package/dist/chunk-LTNGXMQ6.cjs +55 -0
  121. package/dist/chunk-M2L4MYDQ.cjs +14 -0
  122. package/dist/chunk-MCJLA63J.cjs +1 -0
  123. package/dist/chunk-MKB2EGIR.cjs +148 -0
  124. package/dist/chunk-MQ3H6LT5.cjs +202 -0
  125. package/dist/chunk-MT763TDW.cjs +43 -0
  126. package/dist/chunk-MWSK6C4J.cjs +18 -0
  127. package/dist/chunk-MWWVKDW3.cjs +169 -0
  128. package/dist/{chunk-KTGFMHET.mjs → chunk-N6UROPT7.mjs} +1 -1
  129. package/dist/chunk-NO3WWW3N.cjs +192 -0
  130. package/dist/{chunk-NDD2YVGU.mjs → chunk-NRVGEI5I.mjs} +10 -3
  131. package/dist/chunk-NV3A5DXM.cjs +862 -0
  132. package/dist/chunk-NWOD6NIT.cjs +9 -0
  133. package/dist/chunk-NZKJGRB3.cjs +230 -0
  134. package/dist/chunk-OAVTUMJP.cjs +1496 -0
  135. package/dist/chunk-OHY2ZWUG.cjs +25 -0
  136. package/dist/chunk-OI6CMLWX.cjs +47 -0
  137. package/dist/chunk-OIEOCXKG.cjs +453 -0
  138. package/dist/chunk-OWOUTKIJ.cjs +558 -0
  139. package/dist/chunk-OX6O6WVA.cjs +74 -0
  140. package/dist/chunk-OXSIH4D6.cjs +476 -0
  141. package/dist/chunk-OYEUREB6.cjs +35 -0
  142. package/dist/chunk-PCOTGFSM.cjs +139 -0
  143. package/dist/chunk-PZYCPSCC.cjs +35 -0
  144. package/dist/chunk-QBK2AA4U.cjs +445 -0
  145. package/dist/chunk-QBPXNZGV.cjs +487 -0
  146. package/dist/{chunk-IXTEENRS.mjs → chunk-QGVJVSNX.mjs} +5 -5
  147. package/dist/chunk-QNPEUFHQ.cjs +27 -0
  148. package/dist/chunk-QZRVZSPN.cjs +236 -0
  149. package/dist/chunk-R5A5KNVX.cjs +20 -0
  150. package/dist/chunk-R5JIFR6B.cjs +42 -0
  151. package/dist/chunk-R6AIILII.cjs +193 -0
  152. package/dist/chunk-RG3ZOTG5.cjs +34 -0
  153. package/dist/chunk-ROUTX2E5.cjs +390 -0
  154. package/dist/chunk-RTHIVJ2G.cjs +54 -0
  155. package/dist/chunk-S3A45T7F.cjs +166 -0
  156. package/dist/chunk-S3JO3N4H.cjs +17 -0
  157. package/dist/chunk-SK35NQKK.cjs +27 -0
  158. package/dist/chunk-SU7MH53P.cjs +180 -0
  159. package/dist/chunk-SVRTJOUF.cjs +113 -0
  160. package/dist/chunk-SWN467MP.cjs +18 -0
  161. package/dist/{chunk-6SCB2MXB.mjs → chunk-SXHV42UQ.mjs} +16 -1
  162. package/dist/{chunk-OWTIOHON.mjs → chunk-SYGGPS4A.mjs} +2 -2
  163. package/dist/chunk-SYQ3MOWW.cjs +73 -0
  164. package/dist/chunk-T5CERMEH.cjs +417 -0
  165. package/dist/chunk-TFAXUHWX.cjs +206 -0
  166. package/dist/chunk-TIWHTW3Q.cjs +24 -0
  167. package/dist/chunk-TKJZFIML.cjs +20 -0
  168. package/dist/chunk-TKNSDBBN.cjs +193 -0
  169. package/dist/{chunk-NC333MFA.mjs → chunk-TSWW5BVH.mjs} +7 -4
  170. package/dist/chunk-TWGMSEHX.cjs +525 -0
  171. package/dist/chunk-TYQUSXUG.cjs +1357 -0
  172. package/dist/chunk-U4KT7QP3.cjs +23 -0
  173. package/dist/{chunk-LK6FGAQR.mjs → chunk-UDBJCUPA.mjs} +7 -4
  174. package/dist/chunk-UJ2C4ICS.cjs +277 -0
  175. package/dist/chunk-UN5GHC5V.cjs +10244 -0
  176. package/dist/chunk-UQZ4AYTH.cjs +168 -0
  177. package/dist/chunk-US2QVW3E.cjs +36 -0
  178. package/dist/{chunk-NUD6XBMO.mjs → chunk-UTBVHYS3.mjs} +2 -2
  179. package/dist/{chunk-76MNRHTS.mjs → chunk-UUYF3CHN.mjs} +2 -2
  180. package/dist/chunk-VB6UCX3V.cjs +421 -0
  181. package/dist/chunk-VEKFLAQM.cjs +300 -0
  182. package/dist/chunk-VQDBNVOO.cjs +14 -0
  183. package/dist/chunk-W4E7WMXE.cjs +71 -0
  184. package/dist/{chunk-VVTREAG5.mjs → chunk-WD4YXVLV.mjs} +11 -3
  185. package/dist/{chunk-UQZPTIML.mjs → chunk-WD5PNSOB.mjs} +2 -2
  186. package/dist/chunk-WJ3HK3LJ.cjs +1102 -0
  187. package/dist/chunk-WMAPPDMM.cjs +28 -0
  188. package/dist/chunk-WMOGFOUJ.cjs +223 -0
  189. package/dist/chunk-WPYFSQKK.cjs +37 -0
  190. package/dist/chunk-WZMNW2IW.cjs +1415 -0
  191. package/dist/chunk-XGC343EY.cjs +443 -0
  192. package/dist/{chunk-DPZUDPVJ.mjs → chunk-XP777LRD.mjs} +1 -1
  193. package/dist/chunk-XSKZORAS.cjs +727 -0
  194. package/dist/chunk-XWAWFQFS.cjs +82 -0
  195. package/dist/{chunk-KATQ6I56.mjs → chunk-XWAYMDLB.mjs} +1 -1
  196. package/dist/chunk-Y4YMF2NQ.cjs +460 -0
  197. package/dist/chunk-Y4YWHNKU.cjs +250 -0
  198. package/dist/chunk-Y53ZSFN6.cjs +504 -0
  199. package/dist/chunk-YA6LLTIJ.cjs +411 -0
  200. package/dist/chunk-YFPGHF5F.cjs +202 -0
  201. package/dist/chunk-YJRZR7VU.cjs +28 -0
  202. package/dist/chunk-YTAABQEV.cjs +1 -0
  203. package/dist/chunk-YX3DBN4M.cjs +18 -0
  204. package/dist/chunk-YZTASLPQ.cjs +64 -0
  205. package/dist/chunk-Z5HIWVDP.cjs +2173 -0
  206. package/dist/{chunk-Q3MDL7TM.mjs → chunk-ZCNJKLA2.mjs} +30 -11
  207. package/dist/chunk-ZEG3OPIB.cjs +93 -0
  208. package/dist/chunk-ZMN3H73H.cjs +155 -0
  209. package/dist/client/lifecycle.cjs +6 -35
  210. package/dist/{client-plugins-CqVtZi5X.d.ts → client-plugins-C089bQhN.d.ts} +2 -2
  211. package/dist/{client-plugins-CIPRtSsW.d.mts → client-plugins-JXXmZliS.d.mts} +2 -2
  212. package/dist/client-plugins.cjs +7 -448
  213. package/dist/client-plugins.d.mts +3 -3
  214. package/dist/client-plugins.d.ts +3 -3
  215. package/dist/client.cjs +171 -9774
  216. package/dist/client.d.mts +8 -8
  217. package/dist/client.d.ts +8 -8
  218. package/dist/client.mjs +6 -6
  219. package/dist/config.cjs +8 -36
  220. package/dist/config.d.mts +3 -3
  221. package/dist/config.d.ts +3 -3
  222. package/dist/cron.cjs +24 -491
  223. package/dist/cron.mjs +2 -2
  224. package/dist/deferred.cjs +26 -475
  225. package/dist/deployment.cjs +39 -210
  226. package/dist/devtools-OUIPHVV6.cjs +388 -0
  227. package/dist/{devtools-IU7LKZOH.mjs → devtools-UFVTMQX5.mjs} +7 -7
  228. package/dist/devtools-client-4WAPJY5L.cjs +254 -0
  229. package/dist/devtools-ui-5GBDIGMK.cjs +1296 -0
  230. package/dist/docs.cjs +46 -5649
  231. package/dist/docs.mjs +9 -9
  232. package/dist/{endpoint-kSAxE52R.d.ts → endpoint-1zA994xL.d.ts} +1 -1
  233. package/dist/{endpoint-Bu3XgeMK.d.mts → endpoint-DAc96i93.d.mts} +1 -1
  234. package/dist/env-types.cjs +5 -226
  235. package/dist/env.cjs +23 -306
  236. package/dist/env.d.mts +5 -3
  237. package/dist/env.d.ts +5 -3
  238. package/dist/env.mjs +2 -1
  239. package/dist/environment/vite.cjs +8 -372
  240. package/dist/environment.cjs +12 -94
  241. package/dist/font.cjs +13 -63
  242. package/dist/headers.cjs +7 -123
  243. package/dist/i18n/client.cjs +55 -294
  244. package/dist/i18n/index.cjs +22 -209
  245. package/dist/i18n/server.cjs +22 -745
  246. package/dist/image/server.cjs +13 -729
  247. package/dist/image/sharp.cjs +33 -171
  248. package/dist/image.cjs +41 -85
  249. package/dist/index.cjs +1151 -67862
  250. package/dist/index.d.mts +14 -14
  251. package/dist/index.d.ts +14 -14
  252. package/dist/index.mjs +34 -34
  253. package/dist/instrumentation.cjs +12 -138
  254. package/dist/integration-orm-55F7CII5.cjs +13 -0
  255. package/dist/integrations.cjs +55 -4090
  256. package/dist/integrations.d.mts +3 -3
  257. package/dist/integrations.d.ts +3 -3
  258. package/dist/internal/app-markdown-runtime.cjs +27 -224
  259. package/dist/internal/app-markdown-runtime.d.mts +3 -3
  260. package/dist/internal/app-markdown-runtime.d.ts +3 -3
  261. package/dist/internal/app-markdown-runtime.mjs +2 -2
  262. package/dist/internal/build-runtime.cjs +120 -52038
  263. package/dist/internal/build-runtime.d.mts +5 -5
  264. package/dist/internal/build-runtime.d.ts +5 -5
  265. package/dist/internal/build-runtime.mjs +23 -23
  266. package/dist/internal/cli-runtime.cjs +67 -13765
  267. package/dist/internal/cli-runtime.mjs +13 -13
  268. package/dist/internal/client-error-overlay.cjs +80 -733
  269. package/dist/internal/client-error-overlay.mjs +1 -1
  270. package/dist/internal/client-runtime.cjs +81 -913
  271. package/dist/internal/compression-runtime.cjs +8 -214
  272. package/dist/internal/compression-runtime.d.mts +3 -3
  273. package/dist/internal/compression-runtime.d.ts +3 -3
  274. package/dist/internal/config-runtime.cjs +42 -6535
  275. package/dist/internal/config-runtime.d.mts +4 -4
  276. package/dist/internal/config-runtime.d.ts +4 -4
  277. package/dist/internal/config-runtime.mjs +7 -7
  278. package/dist/internal/docs-precompiled-runtime.cjs +26 -46
  279. package/dist/internal/infra-analytics-runtime.cjs +10 -536
  280. package/dist/internal/isolated-boundary.cjs +14 -414
  281. package/dist/internal/metadata-image-runtime.cjs +7 -285
  282. package/dist/internal/product-telemetry-runtime.cjs +42 -97
  283. package/dist/internal/product-telemetry-runtime.mjs +1 -1
  284. package/dist/internal/production-node-env.cjs +6 -63
  285. package/dist/internal/production-runtime.cjs +418 -7073
  286. package/dist/internal/production-runtime.d.mts +9 -9
  287. package/dist/internal/production-runtime.d.ts +9 -9
  288. package/dist/internal/production-runtime.mjs +6 -6
  289. package/dist/internal/request-cookies.cjs +6 -54
  290. package/dist/json-ld.cjs +24 -50
  291. package/dist/layers-E4WPJNY5.cjs +17 -0
  292. package/dist/manager-G4B2IPYE.cjs +14 -0
  293. package/dist/markdown.cjs +21 -532
  294. package/dist/markdown.mjs +1 -1
  295. package/dist/{metadata-8g__AMPM.d.ts → metadata-BcNJP4fq.d.ts} +1 -1
  296. package/dist/{metadata-OMX6wFNf.d.mts → metadata-C1Z9vLbb.d.mts} +1 -1
  297. package/dist/middleware.cjs +36 -2988
  298. package/dist/middleware.d.mts +5 -5
  299. package/dist/middleware.d.ts +5 -5
  300. package/dist/middleware.mjs +4 -4
  301. package/dist/navigation.cjs +22 -2588
  302. package/dist/nitro-4I2MYLY2.cjs +652 -0
  303. package/dist/{nitro-3N4ZXRYM.mjs → nitro-CVZ36JM5.mjs} +4 -4
  304. package/dist/observability.cjs +22 -614
  305. package/dist/og.cjs +5 -28
  306. package/dist/plugin.cjs +106 -37291
  307. package/dist/plugin.d.mts +3 -3
  308. package/dist/plugin.d.ts +3 -3
  309. package/dist/plugin.mjs +19 -19
  310. package/dist/{production-runtime-W3M0eNDV.d.mts → production-runtime-jcrTlRTb.d.mts} +1 -1
  311. package/dist/{production-runtime-BJh7o6Cr.d.ts → production-runtime-oKmC0WU-.d.ts} +1 -1
  312. package/dist/query/client.cjs +113 -449
  313. package/dist/query/index.cjs +26 -288
  314. package/dist/query/parsers.cjs +23 -247
  315. package/dist/query/server.cjs +36 -298
  316. package/dist/{render-plan-io7pvDNc.d.mts → render-plan-BLIfc4jt.d.mts} +1 -1
  317. package/dist/{render-plan-Be4ZGTJP.d.ts → render-plan-DOB9cV-h.d.ts} +1 -1
  318. package/dist/renderer/react/client.cjs +9 -43
  319. package/dist/renderer/react/server.cjs +40 -103
  320. package/dist/renderer/react/vite.cjs +7 -29
  321. package/dist/renderer-client.cjs +126 -4261
  322. package/dist/renderer-client.d.mts +5 -5
  323. package/dist/renderer-client.d.ts +5 -5
  324. package/dist/renderer-client.mjs +3 -3
  325. package/dist/renderer.cjs +31 -249
  326. package/dist/{request-DZkHYQ89.d.mts → request-Cr53NRHr.d.mts} +1 -1
  327. package/dist/{request-G8JhKr4F.d.ts → request-Dt2gNuQD.d.ts} +1 -1
  328. package/dist/request.cjs +5 -68
  329. package/dist/request.d.mts +4 -4
  330. package/dist/request.d.ts +4 -4
  331. package/dist/{route-C_eLaFTZ.d.mts → route-B0XrsrFk.d.mts} +1 -1
  332. package/dist/{route-BxNJT447.d.ts → route-DOEpbyWZ.d.ts} +1 -1
  333. package/dist/{route-rendering-BcLLPJgN.d.ts → route-rendering-CWYd8Mv1.d.ts} +1 -1
  334. package/dist/{route-rendering-CbAKr1TY.d.mts → route-rendering-CeFBEAoZ.d.mts} +1 -1
  335. package/dist/router.cjs +11 -474
  336. package/dist/routes.cjs +42 -2424
  337. package/dist/routes.d.mts +4 -4
  338. package/dist/routes.d.ts +4 -4
  339. package/dist/routes.mjs +2 -2
  340. package/dist/schema-dev-notice-MXSZMVDG.cjs +56 -0
  341. package/dist/schema.cjs +6 -33
  342. package/dist/search-client-G3RICOFU.cjs +13 -0
  343. package/dist/server-action-security.cjs +25 -541
  344. package/dist/server-fn-client.cjs +6 -337
  345. package/dist/server-fn-client.d.mts +3 -3
  346. package/dist/server-fn-client.d.ts +3 -3
  347. package/dist/server-fn.cjs +32 -1799
  348. package/dist/server-fn.d.mts +1 -1
  349. package/dist/server-fn.d.ts +1 -1
  350. package/dist/server-fn.mjs +2 -2
  351. package/dist/server-plugins.cjs +15 -884
  352. package/dist/server-plugins.d.mts +4 -4
  353. package/dist/server-plugins.d.ts +4 -4
  354. package/dist/server-query-client.cjs +15 -1849
  355. package/dist/server-query-client.d.mts +1 -1
  356. package/dist/server-query-client.d.ts +1 -1
  357. package/dist/server-query-client.mjs +4 -4
  358. package/dist/server-query.cjs +16 -1796
  359. package/dist/server-query.d.mts +1 -1
  360. package/dist/server-query.d.ts +1 -1
  361. package/dist/server-query.mjs +3 -3
  362. package/dist/server.cjs +296 -44522
  363. package/dist/server.d.mts +9 -9
  364. package/dist/server.d.ts +9 -9
  365. package/dist/server.mjs +22 -22
  366. package/dist/{spa-router-BcS_4nqm.d.mts → spa-router-CQWiYGxS.d.mts} +2 -2
  367. package/dist/{spa-router-BzFBUJkn.d.ts → spa-router-Wjiw-8hB.d.ts} +2 -2
  368. package/dist/storage.cjs +57 -576
  369. package/dist/testing.cjs +92 -3148
  370. package/dist/testing.d.mts +3 -3
  371. package/dist/testing.d.ts +3 -3
  372. package/dist/testing.mjs +11 -7
  373. package/dist/theme/client.cjs +13 -108
  374. package/dist/theme/index.cjs +6 -68
  375. package/dist/theme/runtime.cjs +13 -78
  376. package/dist/theme/server.cjs +10 -179
  377. package/dist/{utils-C4yrAhNc.d.ts → utils-B0XJmG_b.d.ts} +1 -1
  378. package/dist/{utils-5kQP1mFR.d.mts → utils-uUxF0K0P.d.mts} +1 -1
  379. package/dist/version.cjs +4 -32
  380. package/dist/version.mjs +1 -1
  381. package/dist/vite.cjs +119 -37622
  382. package/dist/vite.d.mts +3 -3
  383. package/dist/vite.d.ts +3 -3
  384. package/dist/vite.mjs +19 -19
  385. package/dist/workflows.cjs +19 -1040
  386. package/dist/workflows.mjs +2 -2
  387. package/package.json +2 -2
  388. package/dist/{chunk-VO5SCWF5.mjs → chunk-BNGS6KJ6.mjs} +0 -0
  389. package/dist/{chunk-MUUZJLCI.mjs → chunk-EGJDUF4Q.mjs} +3 -3
  390. package/dist/{chunk-4L7SZOHZ.mjs → chunk-YHOCRI4H.mjs} +3 -3
@@ -1,1860 +1,26 @@
1
- "use strict";
2
- "use client";
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});"use client";
21
2
 
22
- // src/server-query-client.ts
23
- var server_query_client_exports = {};
24
- __export(server_query_client_exports, {
25
- beginFarmServerQueryAction: () => beginFarmServerQueryAction,
26
- completeFarmServerQueryAction: () => completeFarmServerQueryAction,
27
- fetchServerQuery: () => fetchServerQuery,
28
- prefetchServerQuery: () => prefetchServerQuery,
29
- shouldApplyFarmServerQueryActionResult: () => shouldApplyFarmServerQueryActionResult,
30
- useServerQuery: () => useServerQuery
31
- });
32
- module.exports = __toCommonJS(server_query_client_exports);
33
- var import_react = require("react");
34
3
 
35
- // src/tracing.ts
36
- var import_api = require("@opentelemetry/api");
37
- var FARM_TRACER_NAME = "@farm.js/core";
38
- var ALL_SPAN_KINDS = [
39
- "request",
40
- "render",
41
- "middleware",
42
- "api",
43
- "integration",
44
- "storage",
45
- "ppr",
46
- "build",
47
- "plugin"
48
- ];
49
- var DEFAULT_IGNORED_PATHS = [
50
- "/@vite/",
51
- "/@fs/",
52
- "/@id/",
53
- "/@react-refresh",
54
- "/node_modules/",
55
- "/__vite",
56
- "/.well-known/appspecific/"
57
- ];
58
- var FARM_REQUEST_METHOD_CONTEXT_KEY = (0, import_api.createContextKey)("@farm.js/core/request-method");
59
- var TRACING_RUNTIME = /* @__PURE__ */ Symbol.for("@farm.js/core/tracing-runtime/v1");
60
- var runtime = globalThis;
61
- var tracingState = runtime[TRACING_RUNTIME] ?? (runtime[TRACING_RUNTIME] = normalizeFarmTracingConfig(false));
62
- function normalizeFarmTracingConfig(config) {
63
- if (!config) {
64
- return {
65
- enabled: false,
66
- spans: new Set(ALL_SPAN_KINDS),
67
- recordEvents: true,
68
- attributes: {},
69
- ignorePaths: DEFAULT_IGNORED_PATHS
70
- };
71
- }
72
- if (config === true) {
73
- return {
74
- enabled: true,
75
- spans: new Set(ALL_SPAN_KINDS),
76
- recordEvents: true,
77
- attributes: {},
78
- ignorePaths: DEFAULT_IGNORED_PATHS
79
- };
80
- }
81
- return {
82
- enabled: config.enabled ?? true,
83
- spans: new Set(config.spans ?? ALL_SPAN_KINDS),
84
- recordEvents: config.recordEvents ?? true,
85
- attributes: { ...config.attributes },
86
- ignorePaths: [...DEFAULT_IGNORED_PATHS, ...config.ignorePaths ?? []]
87
- };
88
- }
89
- __name(normalizeFarmTracingConfig, "normalizeFarmTracingConfig");
90
- function recordFarmEventTrace(event) {
91
- if (!tracingState.enabled) return void 0;
92
- const activeContext = import_api.context.active();
93
- const activeSpan = import_api.trace.getSpan(activeContext);
94
- const traceContext = getSpanTraceContext(activeSpan);
95
- if (activeSpan && traceContext) {
96
- if (event.type === "route.matched") {
97
- const method = activeContext.getValue(FARM_REQUEST_METHOD_CONTEXT_KEY) ?? "HTTP";
98
- activeSpan.updateName(`${method} ${event.route}`);
99
- activeSpan.setAttribute("http.route", event.route);
100
- activeSpan.setAttribute("farm.route", event.route);
101
- }
102
- if (tracingState.recordEvents) {
103
- activeSpan.addEvent(event.type, toEventAttributes(event), event.timestamp);
104
- }
105
- const error = event.type === "request.error" ? void 0 : getEventError(event);
106
- if (error !== void 0) {
107
- if (event.type === "render.error") {
108
- recordSpanException(activeSpan, error);
109
- } else {
110
- recordSpanError(activeSpan, error);
111
- }
112
- }
113
- }
114
- const completedTraceContext = recordCompletedEventSpan(event, activeContext);
115
- return traceContext ?? completedTraceContext;
116
- }
117
- __name(recordFarmEventTrace, "recordFarmEventTrace");
118
- function recordCompletedEventSpan(event, parentContext) {
119
- const descriptor = getCompletedSpanDescriptor(event);
120
- if (!descriptor || !tracingState.spans.has(descriptor.kind)) return void 0;
121
- const tracer = import_api.trace.getTracer(FARM_TRACER_NAME);
122
- const span = tracer.startSpan(
123
- descriptor.name,
124
- {
125
- kind: import_api.SpanKind.INTERNAL,
126
- startTime: event.timestamp - descriptor.durationMs,
127
- attributes: {
128
- ...tracingState.attributes,
129
- ...toEventAttributes(event),
130
- "farm.event.type": event.type
131
- }
132
- },
133
- parentContext
134
- );
135
- const status = "status" in event && typeof event.status === "number" ? event.status : void 0;
136
- if (status !== void 0) setResponseStatus(span, status);
137
- const error = getEventError(event);
138
- if (error !== void 0) recordSpanError(span, error);
139
- const traceContext = getSpanTraceContext(span);
140
- span.end(event.timestamp);
141
- return traceContext;
142
- }
143
- __name(recordCompletedEventSpan, "recordCompletedEventSpan");
144
- function getCompletedSpanDescriptor(event) {
145
- if (!("durationMs" in event) || typeof event.durationMs !== "number") return void 0;
146
- switch (event.type) {
147
- case "render.complete":
148
- return { kind: "render", name: `farm.render ${event.route}`, durationMs: event.durationMs };
149
- case "render.stream.shellReady":
150
- return {
151
- kind: "render",
152
- name: `farm.render.shell ${event.route}`,
153
- durationMs: event.durationMs
154
- };
155
- case "render.stream.complete":
156
- return {
157
- kind: "render",
158
- name: `farm.render.stream ${event.route}`,
159
- durationMs: event.durationMs
160
- };
161
- case "middleware.complete":
162
- return {
163
- kind: "middleware",
164
- name: `farm.middleware ${event.name ?? event.route ?? "anonymous"}`,
165
- durationMs: event.durationMs
166
- };
167
- case "api.request.complete":
168
- case "api.error":
169
- return {
170
- kind: "api",
171
- name: `farm.api ${event.method} ${event.route}`,
172
- durationMs: event.durationMs
173
- };
174
- case "integration.api.call.complete":
175
- return {
176
- kind: "integration",
177
- name: `farm.integration ${event.integration}.${event.operation}`,
178
- durationMs: event.durationMs
179
- };
180
- case "storage.query.complete":
181
- return {
182
- kind: "storage",
183
- name: `farm.storage ${event.operation}`,
184
- durationMs: event.durationMs
185
- };
186
- case "ppr.refresh.complete":
187
- return {
188
- kind: "ppr",
189
- name: `farm.ppr.refresh ${event.route}`,
190
- durationMs: event.durationMs
191
- };
192
- case "build.complete":
193
- return {
194
- kind: "build",
195
- name: `farm.build${event.target ? ` ${event.target}` : ""}`,
196
- durationMs: event.durationMs
197
- };
198
- case "plugin.hook.complete":
199
- return {
200
- kind: "plugin",
201
- name: `farm.plugin ${event.plugin}.${event.hook}`,
202
- durationMs: event.durationMs
203
- };
204
- default:
205
- return void 0;
206
- }
207
- }
208
- __name(getCompletedSpanDescriptor, "getCompletedSpanDescriptor");
209
- function hashFarmCacheKey(value) {
210
- let hash = 2166136261;
211
- for (let index = 0; index < value.length; index++) {
212
- hash ^= value.charCodeAt(index);
213
- hash = Math.imul(hash, 16777619);
214
- }
215
- return (hash >>> 0).toString(16).padStart(8, "0");
216
- }
217
- __name(hashFarmCacheKey, "hashFarmCacheKey");
218
- function toEventAttributes(event) {
219
- const attributes = {};
220
- const redactKey = typeof event.type === "string" && event.type.startsWith("cache.");
221
- for (const [key, value] of Object.entries(event)) {
222
- if (key === "timestamp" || key === "level" || key === "error" || key === "traceId" || key === "spanId" || key === "traceSampled" || value === void 0) {
223
- continue;
224
- }
225
- if (redactKey && key === "key" && typeof value === "string") {
226
- attributes["farm.key_hash"] = hashFarmCacheKey(value);
227
- continue;
228
- }
229
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
230
- attributes[`farm.${key}`] = value;
231
- } else if (Array.isArray(value)) {
232
- if (value.every((entry) => typeof entry === "string")) {
233
- attributes[`farm.${key}`] = value;
234
- } else if (value.every((entry) => typeof entry === "number")) {
235
- attributes[`farm.${key}`] = value;
236
- } else if (value.every((entry) => typeof entry === "boolean")) {
237
- attributes[`farm.${key}`] = value;
238
- }
239
- }
240
- }
241
- return attributes;
242
- }
243
- __name(toEventAttributes, "toEventAttributes");
244
- function getEventError(event) {
245
- return "error" in event ? event.error : void 0;
246
- }
247
- __name(getEventError, "getEventError");
248
- function recordSpanException(span, error) {
249
- const normalized = error instanceof Error ? error : new Error(String(error));
250
- span.recordException(normalized);
251
- return normalized;
252
- }
253
- __name(recordSpanException, "recordSpanException");
254
- function recordSpanError(span, error) {
255
- const normalized = recordSpanException(span, error);
256
- span.setStatus({ code: import_api.SpanStatusCode.ERROR, message: normalized.message });
257
- }
258
- __name(recordSpanError, "recordSpanError");
259
- function setResponseStatus(span, status) {
260
- span.setAttribute("http.response.status_code", status);
261
- if (status >= 500) {
262
- span.setStatus({ code: import_api.SpanStatusCode.ERROR });
263
- }
264
- }
265
- __name(setResponseStatus, "setResponseStatus");
266
- function getSpanTraceContext(span) {
267
- if (!span) return void 0;
268
- const spanContext = span.spanContext();
269
- if (!(0, import_api.isSpanContextValid)(spanContext)) return void 0;
270
- return {
271
- traceId: spanContext.traceId,
272
- spanId: spanContext.spanId,
273
- traceSampled: (spanContext.traceFlags & 1) === 1
274
- };
275
- }
276
- __name(getSpanTraceContext, "getSpanTraceContext");
4
+ var _chunkC3VRMB6Hcjs = require('./chunk-C3VRMB6H.cjs');
277
5
 
278
- // src/observability.ts
279
- var OBSERVABILITY_RUNTIME = /* @__PURE__ */ Symbol.for("@farm.js/core/observability-runtime/v1");
280
- var runtime2 = globalThis;
281
- var shared = runtime2[OBSERVABILITY_RUNTIME] ?? (runtime2[OBSERVABILITY_RUNTIME] = {
282
- handlers: /* @__PURE__ */ new Set(),
283
- unfilteredHandlers: /* @__PURE__ */ new Set(),
284
- config: { logs: false, handlers: [], tracing: normalizeFarmTracingConfig(false) }
285
- });
286
- var runtimeHandlers = shared.handlers;
287
- var unfilteredRuntimeHandlers = shared.unfilteredHandlers;
288
- var observabilityState = shared.config;
289
- function emitFarmEvent(input) {
290
- const event = {
291
- timestamp: Date.now(),
292
- level: inferFarmEventLevel(input.type),
293
- ...input
294
- };
295
- const traceContext = recordFarmEventTrace(event);
296
- if (traceContext) {
297
- event.traceId = traceContext.traceId;
298
- event.spanId = traceContext.spanId;
299
- event.traceSampled = traceContext.traceSampled;
300
- }
301
- notifyFarmEventHandlers(event, unfilteredRuntimeHandlers);
302
- if (!shouldEmitFarmEvent(event)) return event;
303
- if (observabilityState.logs) {
304
- logFarmEvent(event);
305
- }
306
- notifyFarmEventHandlers(event, [...observabilityState.handlers, ...runtimeHandlers]);
307
- return event;
308
- }
309
- __name(emitFarmEvent, "emitFarmEvent");
310
- function notifyFarmEventHandlers(event, handlers) {
311
- for (const handler of handlers) {
312
- try {
313
- Promise.resolve(handler(event)).catch((error) => {
314
- console.warn(`[farm:observability] event handler failed: ${formatError(error)}`);
315
- });
316
- } catch (error) {
317
- console.warn(`[farm:observability] event handler failed: ${formatError(error)}`);
318
- }
319
- }
320
- }
321
- __name(notifyFarmEventHandlers, "notifyFarmEventHandlers");
322
- function shouldEmitFarmEvent(event) {
323
- if (!observabilityState.logs && observabilityState.handlers.length === 0 && runtimeHandlers.size === 0) {
324
- return false;
325
- }
326
- if (observabilityState.events && !observabilityState.events.has(event.type)) {
327
- return false;
328
- }
329
- return true;
330
- }
331
- __name(shouldEmitFarmEvent, "shouldEmitFarmEvent");
332
- function inferFarmEventLevel(type) {
333
- if (type === "error" || type.endsWith(".error") || type.endsWith(".failed")) {
334
- return "error";
335
- }
336
- if (type.endsWith(".bypass") || type.endsWith(".invalidated") || type.endsWith(".stale") || type.endsWith(".notFound")) {
337
- return "warn";
338
- }
339
- if (type.endsWith(".hit") || type.endsWith(".miss") || type.endsWith(".start") || type.endsWith(".shellReady")) {
340
- return "debug";
341
- }
342
- return "info";
343
- }
344
- __name(inferFarmEventLevel, "inferFarmEventLevel");
345
- function logFarmEvent(event) {
346
- const message = `[farm:${event.level}] ${event.type}${formatFarmEventDetails(event)}`;
347
- switch (event.level) {
348
- case "error":
349
- console.error(message);
350
- break;
351
- case "warn":
352
- console.warn(message);
353
- break;
354
- default:
355
- console.log(message);
356
- break;
357
- }
358
- }
359
- __name(logFarmEvent, "logFarmEvent");
360
- function formatFarmEventDetails(event) {
361
- const details = [];
362
- const record = event;
363
- for (const key of [
364
- "route",
365
- "pathname",
366
- "method",
367
- "status",
368
- "key",
369
- "tag",
370
- "path",
371
- "reason",
372
- "durationMs",
373
- "integration",
374
- "server",
375
- "tool",
376
- "outcome",
377
- "operation",
378
- "plugin",
379
- "hook",
380
- "target",
381
- "count"
382
- ]) {
383
- const value = record[key];
384
- if (value !== void 0) {
385
- details.push(`${key}=${formatDetailValue(value)}`);
386
- }
387
- }
388
- return details.length > 0 ? ` ${details.join(" ")}` : "";
389
- }
390
- __name(formatFarmEventDetails, "formatFarmEventDetails");
391
- function formatDetailValue(value) {
392
- if (typeof value === "string") {
393
- return value;
394
- }
395
- if (typeof value === "number" || typeof value === "boolean") {
396
- return String(value);
397
- }
398
- try {
399
- return JSON.stringify(value);
400
- } catch {
401
- return String(value);
402
- }
403
- }
404
- __name(formatDetailValue, "formatDetailValue");
405
- function formatError(error) {
406
- return error instanceof Error ? error.message : String(error);
407
- }
408
- __name(formatError, "formatError");
409
6
 
410
- // src/cache-invalidation.ts
411
- var FARM_CACHE_INVALIDATION_STATE = /* @__PURE__ */ Symbol.for("farm.cacheInvalidationState");
412
- var globalState = globalThis;
413
- function getFarmCacheInvalidationState() {
414
- return globalState[FARM_CACHE_INVALIDATION_STATE] ?? (globalState[FARM_CACHE_INVALIDATION_STATE] = {
415
- listeners: /* @__PURE__ */ new Set(),
416
- taskListeners: /* @__PURE__ */ new Set()
417
- });
418
- }
419
- __name(getFarmCacheInvalidationState, "getFarmCacheInvalidationState");
420
- function subscribeFarmCacheInvalidation(listener) {
421
- const state = getFarmCacheInvalidationState();
422
- state.listeners.add(listener);
423
- return () => state.listeners.delete(listener);
424
- }
425
- __name(subscribeFarmCacheInvalidation, "subscribeFarmCacheInvalidation");
426
7
 
427
- // src/cache-invalidation-stream.ts
428
- var MAX_BUFFERED_BYTES = 64 * 1024;
429
- var textEncoder = new TextEncoder();
430
8
 
431
- // src/cache.ts
432
- var _FarmDataCache = class _FarmDataCache {
433
- constructor(config = {}) {
434
- this.entries = /* @__PURE__ */ new Map();
435
- this.inflight = /* @__PURE__ */ new Map();
436
- this.invalidatedTagVersions = /* @__PURE__ */ new Map();
437
- this.activeGenerations = /* @__PURE__ */ new Set();
438
- this.version = 0;
439
- this.generation = 0;
440
- this.namespace = "farm";
441
- this.local = true;
442
- this.maxEntries = 1024;
443
- this.lease = {
444
- enabled: true,
445
- ttlMs: 1e4,
446
- waitTimeoutMs: 1e4,
447
- pollIntervalMs: 25
448
- };
449
- this.configure(config);
450
- }
451
- configure(config = {}) {
452
- this.generation++;
453
- this.entries.clear();
454
- this.inflight.clear();
455
- this.invalidatedTagVersions.clear();
456
- this.activeGenerations.clear();
457
- this.version = 0;
458
- this.adapter = config.adapter;
459
- this.namespace = normalizeCacheNamespace(config.namespace || "farm");
460
- this.local = !config.adapter;
461
- this.maxEntries = normalizePositiveInteger(config.maxEntries, 1024, "cache.maxEntries");
462
- this.lease = config.lease === false ? { ...this.lease, enabled: false } : {
463
- enabled: true,
464
- ttlMs: normalizePositiveDuration(config.lease?.ttlMs, 1e4, "cache.lease.ttlMs"),
465
- waitTimeoutMs: normalizePositiveDuration(
466
- config.lease?.waitTimeoutMs,
467
- 1e4,
468
- "cache.lease.waitTimeoutMs"
469
- ),
470
- pollIntervalMs: normalizePositiveDuration(
471
- config.lease?.pollIntervalMs,
472
- 25,
473
- "cache.lease.pollIntervalMs"
474
- )
475
- };
476
- }
477
- get adapterName() {
478
- return this.adapter?.name || (this.adapter ? "custom" : "memory");
479
- }
480
- get hasAdapter() {
481
- return this.adapter !== void 0;
482
- }
483
- get size() {
484
- return this.entries.size;
485
- }
486
- get(key, options = {}) {
487
- return this.getEntry(key, options)?.value;
488
- }
489
- getEntry(key, options = {}) {
490
- const entry = this.entries.get(key);
491
- if (!entry) {
492
- emitFarmEvent({ type: "cache.miss", key });
493
- return void 0;
494
- }
495
- const stale = this.isStale(entry, options.now);
496
- if (stale) {
497
- emitFarmEvent({
498
- type: "cache.stale",
499
- key,
500
- tags: Array.from(entry.tags),
501
- revalidate: entry.revalidate
502
- });
503
- }
504
- if (!options.allowStale && stale) {
505
- emitFarmEvent({ type: "cache.miss", key, reason: "stale" });
506
- return void 0;
507
- }
508
- this.touchEntry(key, entry);
509
- emitFarmEvent({
510
- type: "cache.hit",
511
- key,
512
- tags: Array.from(entry.tags),
513
- revalidate: entry.revalidate,
514
- stale
515
- });
516
- return this.toPublicEntry(entry);
517
- }
518
- async getEntryAsync(key, options = {}) {
519
- if (this.local) {
520
- const localEntry = this.getEntry(key, options);
521
- if (localEntry) return localEntry;
522
- }
523
- if (!this.adapter) {
524
- return this.local ? void 0 : this.getEntry(key, options);
525
- }
526
- const generation = this.generation;
527
- const adapter = this.adapter;
528
- const namespace = this.namespace;
529
- const entry = await adapter.get(`${namespace}:entry:${key}`);
530
- if (generation !== this.generation) return void 0;
531
- if (!entry) {
532
- emitFarmEvent({ type: "cache.miss", key });
533
- return void 0;
534
- }
535
- assertFarmCacheEntry(entry, key);
536
- const stale = await this.isAdapterEntryStale(entry, options.now, adapter, namespace);
537
- if (generation !== this.generation) return void 0;
538
- if (stale) {
539
- emitFarmEvent({
540
- type: "cache.stale",
541
- key,
542
- tags: [...entry.tags],
543
- revalidate: entry.revalidate
544
- });
545
- if (!options.allowStale) {
546
- emitFarmEvent({ type: "cache.miss", key, reason: "stale" });
547
- return void 0;
548
- }
549
- }
550
- emitFarmEvent({
551
- type: "cache.hit",
552
- key,
553
- tags: [...entry.tags],
554
- revalidate: entry.revalidate,
555
- stale
556
- });
557
- if (this.local && !stale) {
558
- this.hydrateLocalEntry(entry);
559
- }
560
- return { ...entry, key };
561
- }
562
- set(key, value, options = {}) {
563
- const revalidate = normalizeRevalidate(options.revalidate);
564
- const tags = /* @__PURE__ */ new Set();
565
- for (const tag of options.tags ?? []) {
566
- tags.add(normalizeCacheTag(tag));
567
- }
568
- for (const routePath of options.paths ?? []) {
569
- tags.add(createPathCacheTag(routePath));
570
- }
571
- const entry = {
572
- key,
573
- value,
574
- tags,
575
- tagVersions: void 0,
576
- createdAt: options.createdAt ?? Date.now(),
577
- createdVersion: ++this.version,
578
- revalidate
579
- };
580
- this.storeLocalEntry(entry);
581
- emitFarmEvent({
582
- type: "cache.set",
583
- key,
584
- tags: Array.from(tags),
585
- revalidate: entry.revalidate
586
- });
587
- return this.toPublicEntry(entry);
588
- }
589
- async setAsync(key, value, options = {}, tagVersions) {
590
- return this.writeAsync(key, value, options, tagVersions);
591
- }
592
- async writeAsync(key, value, options, tagVersions, createdVersion) {
593
- const revalidate = normalizeRevalidate(options.revalidate);
594
- const tags = normalizeCacheOptionsTags(options);
595
- const capturedVersions = tagVersions ?? await this.getAdapterTagVersions(Array.from(tags.values()));
596
- const entry = {
597
- key,
598
- value,
599
- tags: Array.from(tags),
600
- tagVersions: capturedVersions,
601
- createdAt: options.createdAt ?? Date.now(),
602
- createdVersion: createdVersion ?? ++this.version,
603
- revalidate
604
- };
605
- if (this.local) {
606
- this.hydrateLocalEntry(entry);
607
- }
608
- if (this.adapter) {
609
- await this.adapter.set(this.createAdapterKey(key), entry);
610
- }
611
- emitFarmEvent({
612
- type: "cache.set",
613
- key,
614
- tags: [...entry.tags],
615
- revalidate: entry.revalidate
616
- });
617
- return entry;
618
- }
619
- delete(key) {
620
- const deleted = this.entries.delete(key);
621
- if (deleted) this.pruneInvalidatedTagVersions();
622
- emitFarmEvent({ type: "cache.delete", key, deleted });
623
- return deleted;
624
- }
625
- async deleteAsync(key) {
626
- const deleted = this.entries.delete(key);
627
- if (deleted) this.pruneInvalidatedTagVersions();
628
- if (this.adapter) {
629
- await this.adapter.delete(this.createAdapterKey(key));
630
- }
631
- emitFarmEvent({ type: "cache.delete", key, deleted: this.adapter ? true : deleted });
632
- return this.adapter ? true : deleted;
633
- }
634
- clear() {
635
- const count = this.entries.size;
636
- this.generation++;
637
- this.entries.clear();
638
- this.inflight.clear();
639
- this.invalidatedTagVersions.clear();
640
- this.activeGenerations.clear();
641
- this.version = 0;
642
- emitFarmEvent({ type: "cache.clear", count });
643
- }
644
- async clearAsync() {
645
- this.clear();
646
- await this.adapter?.clear?.();
647
- }
648
- isStale(entry, now = Date.now()) {
649
- if (typeof entry.revalidate === "number" && entry.revalidate >= 0 && now - entry.createdAt >= entry.revalidate * 1e3) {
650
- return true;
651
- }
652
- for (const tag of entry.tags) {
653
- const invalidatedVersion = this.invalidatedTagVersions.get(normalizeCacheTag(tag));
654
- if (typeof invalidatedVersion === "number" && typeof entry.createdVersion === "number" && invalidatedVersion > entry.createdVersion) {
655
- return true;
656
- }
657
- }
658
- return false;
659
- }
660
- async isStaleAsync(entry, now = Date.now()) {
661
- if (this.adapter) {
662
- return this.isAdapterEntryStale(entry, now);
663
- }
664
- return this.isStale(entry, now);
665
- }
666
- revalidateTag(tag, options = {}) {
667
- const normalized = normalizeCacheTag(tag);
668
- const count = this.invalidateTag(normalized);
669
- emitFarmEvent(
670
- options.source === "updateTag" ? { type: "cache.updateTag", tag: normalized, count } : { type: "cache.revalidateTag", tag: normalized, profile: options.profile, count }
671
- );
672
- return count;
673
- }
674
- async revalidateTagAsync(tag, options = {}) {
675
- const normalized = normalizeCacheTag(tag);
676
- const count = this.invalidateTag(normalized);
677
- await this.adapter?.invalidateTags?.([this.createAdapterTag(normalized)]);
678
- emitFarmEvent(
679
- options.source === "updateTag" ? { type: "cache.updateTag", tag: normalized, count } : { type: "cache.revalidateTag", tag: normalized, profile: options.profile, count }
680
- );
681
- return count;
682
- }
683
- revalidatePath(routePath) {
684
- const normalizedPath = normalizeRevalidatePath(routePath);
685
- const pathTag = createPathCacheTag(normalizedPath);
686
- const pprCount = this.countEntriesForTags([pathTag, "ppr"]);
687
- const count = this.invalidateTag(pathTag);
688
- emitFarmEvent({ type: "cache.revalidatePath", path: normalizedPath, count });
689
- if (pprCount > 0) {
690
- emitFarmEvent({
691
- type: "ppr.shell.invalidated",
692
- route: normalizedPath,
693
- reason: "revalidatePath",
694
- count: pprCount
695
- });
696
- }
697
- return count;
698
- }
699
- async revalidatePathAsync(routePath) {
700
- const normalizedPath = normalizeRevalidatePath(routePath);
701
- const pathTag = createPathCacheTag(normalizedPath);
702
- const pprCount = this.countEntriesForTags([pathTag, "ppr"]);
703
- const count = this.invalidateTag(pathTag);
704
- await this.adapter?.invalidateTags?.([this.createAdapterTag(pathTag)]);
705
- emitFarmEvent({ type: "cache.revalidatePath", path: normalizedPath, count });
706
- if (pprCount > 0) {
707
- emitFarmEvent({
708
- type: "ppr.shell.invalidated",
709
- route: normalizedPath,
710
- reason: "revalidatePath",
711
- count: pprCount
712
- });
713
- }
714
- return count;
715
- }
716
- async getOrSet(key, producer, options = {}) {
717
- normalizeRevalidate(options.revalidate);
718
- const cached = await this.getEntryAsync(key);
719
- if (cached) {
720
- return cached.value;
721
- }
722
- const inflight = this.inflight.get(key);
723
- if (inflight) {
724
- emitFarmEvent({ type: "cache.dedupe", key });
725
- return inflight;
726
- }
727
- const tags = Array.from(normalizeCacheOptionsTags(options));
728
- const generation = this.generation;
729
- const promise = this.fillCacheEntry(key, producer, options, tags, generation).catch((error) => {
730
- emitFarmEvent({ type: "cache.error", key, operation: "set", error });
731
- throw error;
732
- }).finally(() => {
733
- if (this.inflight.get(key) === promise) {
734
- this.inflight.delete(key);
735
- }
736
- });
737
- this.inflight.set(key, promise);
738
- return promise;
739
- }
740
- async fillCacheEntry(key, producer, options, tags, generation) {
741
- const adapter = this.adapter;
742
- const namespace = this.namespace;
743
- const lease = { ...this.lease };
744
- const leaseKey = `${namespace}:lease:${key}`;
745
- let leaseToken;
746
- if (adapter?.acquireLease && adapter.releaseLease && lease.enabled) {
747
- leaseToken = await adapter.acquireLease(leaseKey, lease.ttlMs);
748
- if (!leaseToken) {
749
- const shared2 = await this.waitForAdapterEntry(
750
- key,
751
- adapter,
752
- namespace,
753
- lease,
754
- generation
755
- );
756
- if (shared2) {
757
- emitFarmEvent({ type: "cache.dedupe", key });
758
- return shared2.value;
759
- }
760
- if (generation === this.generation) {
761
- leaseToken = await adapter.acquireLease(leaseKey, lease.ttlMs);
762
- }
763
- }
764
- }
765
- const initialCreatedVersion = this.version;
766
- const activeGeneration = {
767
- tags: new Set(tags),
768
- createdVersion: initialCreatedVersion
769
- };
770
- this.activeGenerations.add(activeGeneration);
771
- try {
772
- const initialTagVersions = await this.getAdapterTagVersions(tags, adapter, namespace);
773
- const value = await producer();
774
- if (generation === this.generation) {
775
- await this.writeAsync(key, value, options, initialTagVersions, initialCreatedVersion);
776
- }
777
- return value;
778
- } finally {
779
- this.activeGenerations.delete(activeGeneration);
780
- this.pruneInvalidatedTagVersions();
781
- if (leaseToken && adapter?.releaseLease) {
782
- try {
783
- await adapter.releaseLease(leaseKey, leaseToken);
784
- } catch (error) {
785
- emitFarmEvent({ type: "cache.error", key, operation: "set", error });
786
- }
787
- }
788
- }
789
- }
790
- async waitForAdapterEntry(key, adapter, namespace, lease, generation) {
791
- const deadline = Date.now() + lease.waitTimeoutMs;
792
- while (Date.now() < deadline) {
793
- await delay(lease.pollIntervalMs);
794
- if (generation !== this.generation) return void 0;
795
- const entry = await adapter.get(`${namespace}:entry:${key}`);
796
- if (generation !== this.generation) return void 0;
797
- if (!entry) {
798
- emitFarmEvent({ type: "cache.miss", key });
799
- continue;
800
- }
801
- assertFarmCacheEntry(entry, key);
802
- const stale = await this.isAdapterEntryStale(entry, Date.now(), adapter, namespace);
803
- if (generation !== this.generation) return void 0;
804
- if (stale) {
805
- emitFarmEvent({
806
- type: "cache.stale",
807
- key,
808
- tags: [...entry.tags],
809
- revalidate: entry.revalidate
810
- });
811
- emitFarmEvent({ type: "cache.miss", key, reason: "stale" });
812
- } else {
813
- emitFarmEvent({
814
- type: "cache.hit",
815
- key,
816
- tags: [...entry.tags],
817
- revalidate: entry.revalidate,
818
- stale: false
819
- });
820
- return { ...entry, key };
821
- }
822
- }
823
- return void 0;
824
- }
825
- countEntriesForTag(tag) {
826
- let count = 0;
827
- for (const entry of this.entries.values()) {
828
- if (entry.tags.has(tag)) {
829
- count++;
830
- }
831
- }
832
- return count;
833
- }
834
- countEntriesForTags(tags) {
835
- let count = 0;
836
- for (const entry of this.entries.values()) {
837
- if (tags.every((tag) => entry.tags.has(tag))) {
838
- count++;
839
- }
840
- }
841
- return count;
842
- }
843
- invalidateTag(normalizedTag) {
844
- const count = this.countEntriesForTag(normalizedTag);
845
- this.invalidatedTagVersions.delete(normalizedTag);
846
- this.invalidatedTagVersions.set(normalizedTag, ++this.version);
847
- this.pruneInvalidatedTagVersions();
848
- return count;
849
- }
850
- toPublicEntry(entry) {
851
- return {
852
- key: entry.key,
853
- value: entry.value,
854
- tags: Array.from(entry.tags),
855
- tagVersions: entry.tagVersions,
856
- createdAt: entry.createdAt,
857
- createdVersion: entry.createdVersion,
858
- revalidate: entry.revalidate
859
- };
860
- }
861
- hydrateLocalEntry(entry) {
862
- this.storeLocalEntry({
863
- key: entry.key,
864
- value: entry.value,
865
- tags: new Set(entry.tags.map(normalizeCacheTag)),
866
- tagVersions: entry.tagVersions,
867
- createdAt: entry.createdAt,
868
- createdVersion: entry.createdVersion ?? ++this.version,
869
- revalidate: normalizeRevalidate(entry.revalidate)
870
- });
871
- }
872
- touchEntry(key, entry) {
873
- this.entries.delete(key);
874
- this.entries.set(key, entry);
875
- }
876
- storeLocalEntry(entry) {
877
- this.entries.delete(entry.key);
878
- this.entries.set(entry.key, entry);
879
- while (this.entries.size > this.maxEntries) {
880
- const oldestKey = this.entries.keys().next().value;
881
- if (oldestKey === void 0) break;
882
- this.entries.delete(oldestKey);
883
- }
884
- this.pruneInvalidatedTagVersions();
885
- }
886
- pruneInvalidatedTagVersions() {
887
- tags: for (const [tag, invalidatedVersion] of this.invalidatedTagVersions) {
888
- for (const entry of this.entries.values()) {
889
- if (entry.tags.has(tag) && entry.createdVersion < invalidatedVersion) continue tags;
890
- }
891
- for (const generation of this.activeGenerations) {
892
- if (generation.tags.has(tag) && generation.createdVersion < invalidatedVersion)
893
- continue tags;
894
- }
895
- this.invalidatedTagVersions.delete(tag);
896
- }
897
- }
898
- createAdapterKey(key) {
899
- return `${this.namespace}:entry:${key}`;
900
- }
901
- createAdapterTag(tag) {
902
- return `${this.namespace}:tag:${tag}`;
903
- }
904
- async getAdapterTagVersions(tags, adapter = this.adapter, namespace = this.namespace) {
905
- if (!adapter?.getTagVersions || tags.length === 0) return {};
906
- const normalized = tags.map(normalizeCacheTag);
907
- const physicalTags = normalized.map((tag) => `${namespace}:tag:${tag}`);
908
- const versions = await adapter.getTagVersions(physicalTags);
909
- return Object.fromEntries(
910
- normalized.map((tag, index) => [
911
- tag,
912
- normalizeAdapterVersion(versions[physicalTags[index]])
913
- ])
914
- );
915
- }
916
- async isAdapterEntryStale(entry, now = Date.now(), adapter = this.adapter, namespace = this.namespace) {
917
- if (typeof entry.revalidate === "number" && entry.revalidate >= 0 && now - entry.createdAt >= entry.revalidate * 1e3) {
918
- return true;
919
- }
920
- const currentVersions = await this.getAdapterTagVersions(entry.tags, adapter, namespace);
921
- for (const tag of entry.tags) {
922
- if (normalizeAdapterVersion(currentVersions[tag]) > normalizeAdapterVersion(entry.tagVersions?.[tag])) {
923
- return true;
924
- }
925
- }
926
- return false;
927
- }
928
- };
929
- __name(_FarmDataCache, "FarmDataCache");
930
- var FarmDataCache = _FarmDataCache;
931
- var FARM_DATA_CACHE_SYMBOL = /* @__PURE__ */ Symbol.for("farm.dataCache");
932
- var farmDataCacheGlobal = globalThis;
933
- var sharedFarmDataCache = farmDataCacheGlobal[FARM_DATA_CACHE_SYMBOL] ?? (farmDataCacheGlobal[FARM_DATA_CACHE_SYMBOL] = new FarmDataCache());
934
- function createPathCacheTag(routePath) {
935
- return `path:${normalizeRevalidatePath(routePath)}`;
936
- }
937
- __name(createPathCacheTag, "createPathCacheTag");
938
- function normalizeRevalidatePath(routePath) {
939
- if (typeof routePath !== "string") {
940
- throw new TypeError("revalidatePath expects a path string.");
941
- }
942
- let normalized = routePath.trim();
943
- if (!normalized) {
944
- throw new Error("revalidatePath expects a non-empty path.");
945
- }
946
- try {
947
- if (/^https?:\/\//i.test(normalized)) {
948
- normalized = new URL(normalized).pathname;
949
- }
950
- } catch {
951
- }
952
- normalized = normalized.split(/[?#]/, 1)[0] ?? normalized;
953
- normalized = normalized.startsWith("/") ? normalized : `/${normalized}`;
954
- normalized = normalized.replace(/\/{2,}/g, "/");
955
- normalized = new URL(normalized, "http://farm.invalid").pathname;
956
- if (normalized.length > 1) {
957
- normalized = normalized.replace(/\/+$/, "");
958
- }
959
- return normalized || "/";
960
- }
961
- __name(normalizeRevalidatePath, "normalizeRevalidatePath");
962
- function createFarmCacheKey(parts) {
963
- return stableSerialize(parts);
964
- }
965
- __name(createFarmCacheKey, "createFarmCacheKey");
966
- function normalizeRevalidate(revalidate) {
967
- if (revalidate === false || revalidate === void 0) {
968
- return revalidate;
969
- }
970
- if (!Number.isFinite(revalidate) || revalidate < 0) {
971
- throw new TypeError("Cache revalidate must be false or a finite, non-negative number.");
972
- }
973
- return revalidate;
974
- }
975
- __name(normalizeRevalidate, "normalizeRevalidate");
976
- function normalizeCacheTag(tag) {
977
- if (typeof tag !== "string") {
978
- throw new TypeError("Cache tags must be strings.");
979
- }
980
- const normalized = tag.trim();
981
- if (!normalized) {
982
- throw new Error("Cache tags cannot be empty.");
983
- }
984
- return normalized;
985
- }
986
- __name(normalizeCacheTag, "normalizeCacheTag");
987
- function normalizeCacheNamespace(namespace) {
988
- if (typeof namespace !== "string") {
989
- throw new TypeError("Cache namespace must be a string.");
990
- }
991
- const normalized = namespace.trim().replace(/:+$/g, "");
992
- if (!normalized) {
993
- throw new Error("Cache namespace cannot be empty.");
994
- }
995
- return normalized;
996
- }
997
- __name(normalizeCacheNamespace, "normalizeCacheNamespace");
998
- function normalizeAdapterVersion(value) {
999
- return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 0;
1000
- }
1001
- __name(normalizeAdapterVersion, "normalizeAdapterVersion");
1002
- function normalizePositiveDuration(value, fallback, name) {
1003
- if (value === void 0) return fallback;
1004
- if (!Number.isFinite(value) || value <= 0) {
1005
- throw new TypeError(`${name} must be a positive number of milliseconds.`);
1006
- }
1007
- return Math.floor(value);
1008
- }
1009
- __name(normalizePositiveDuration, "normalizePositiveDuration");
1010
- function normalizePositiveInteger(value, fallback, name) {
1011
- if (value === void 0) return fallback;
1012
- if (!Number.isSafeInteger(value) || value <= 0) {
1013
- throw new TypeError(`${name} must be a positive integer.`);
1014
- }
1015
- return value;
1016
- }
1017
- __name(normalizePositiveInteger, "normalizePositiveInteger");
1018
- function delay(ms) {
1019
- return new Promise((resolve) => setTimeout(resolve, ms));
1020
- }
1021
- __name(delay, "delay");
1022
- function normalizeCacheOptionsTags(options) {
1023
- const tags = /* @__PURE__ */ new Set();
1024
- for (const tag of options.tags ?? []) {
1025
- tags.add(normalizeCacheTag(tag));
1026
- }
1027
- for (const routePath of options.paths ?? []) {
1028
- tags.add(createPathCacheTag(routePath));
1029
- }
1030
- return tags;
1031
- }
1032
- __name(normalizeCacheOptionsTags, "normalizeCacheOptionsTags");
1033
- function assertFarmCacheEntry(entry, expectedKey) {
1034
- if (!entry || typeof entry !== "object" || entry.key !== expectedKey || !Array.isArray(entry.tags) || typeof entry.createdAt !== "number") {
1035
- throw new TypeError(
1036
- `Cache adapter returned an invalid entry for ${JSON.stringify(expectedKey)}.`
1037
- );
1038
- }
1039
- }
1040
- __name(assertFarmCacheEntry, "assertFarmCacheEntry");
1041
- function getFunctionCacheIdentity(fn) {
1042
- const name = fn.name || "anonymous";
1043
- return `${name}:${hashFunctionSource(String(fn))}`;
1044
- }
1045
- __name(getFunctionCacheIdentity, "getFunctionCacheIdentity");
1046
- function hashFunctionSource(source) {
1047
- let hash = 2166136261;
1048
- for (let index = 0; index < source.length; index++) {
1049
- hash ^= source.charCodeAt(index);
1050
- hash = Math.imul(hash, 16777619);
1051
- }
1052
- return (hash >>> 0).toString(36);
1053
- }
1054
- __name(hashFunctionSource, "hashFunctionSource");
1055
- function compareCodepoint(a, b) {
1056
- return a < b ? -1 : a > b ? 1 : 0;
1057
- }
1058
- __name(compareCodepoint, "compareCodepoint");
1059
- function serializeBinaryBytes(bytes) {
1060
- return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
1061
- }
1062
- __name(serializeBinaryBytes, "serializeBinaryBytes");
1063
- function serializeCanonicalStringEntries(entries, seen) {
1064
- const valuesByKey = /* @__PURE__ */ new Map();
1065
- for (const [key, item] of entries) {
1066
- const values = valuesByKey.get(key);
1067
- if (values) values.push(item);
1068
- else valuesByKey.set(key, [item]);
1069
- }
1070
- return Array.from(valuesByKey.keys()).sort(compareCodepoint).flatMap(
1071
- (key) => valuesByKey.get(key).map((item) => `[${stableSerialize(key, seen)},${stableSerialize(item, seen)}]`)
1072
- ).join(",");
1073
- }
1074
- __name(serializeCanonicalStringEntries, "serializeCanonicalStringEntries");
1075
- function isPlainCacheKeyObject(value) {
1076
- const prototype = Object.getPrototypeOf(value);
1077
- if (prototype === null) return true;
1078
- const constructor = Object.getOwnPropertyDescriptor(prototype, "constructor")?.value;
1079
- return Object.getPrototypeOf(prototype) === null && typeof constructor === "function" && constructor.name === "Object";
1080
- }
1081
- __name(isPlainCacheKeyObject, "isPlainCacheKeyObject");
1082
- function getCacheKeyValueType(value) {
1083
- const prototype = Object.getPrototypeOf(value);
1084
- const constructor = prototype ? Object.getOwnPropertyDescriptor(prototype, "constructor")?.value : void 0;
1085
- if (typeof constructor === "function" && constructor.name) {
1086
- return constructor.name;
1087
- }
1088
- return Object.prototype.toString.call(value).slice(8, -1) || "object";
1089
- }
1090
- __name(getCacheKeyValueType, "getCacheKeyValueType");
1091
- function stableSerialize(value, seen = /* @__PURE__ */ new WeakSet()) {
1092
- if (value === null) return "null";
1093
- if (value === void 0) return "undefined";
1094
- const valueType = typeof value;
1095
- if (valueType === "string") return JSON.stringify(value);
1096
- if (valueType === "number" || valueType === "boolean" || valueType === "bigint") {
1097
- return `${valueType}:${String(value)}`;
1098
- }
1099
- if (valueType === "symbol") {
1100
- return `symbol:${String(value)}`;
1101
- }
1102
- if (valueType === "function") {
1103
- return `function:${getFunctionCacheIdentity(value)}`;
1104
- }
1105
- if (value instanceof Date) {
1106
- return Number.isNaN(value.getTime()) ? "date:invalid" : `date:${value.toISOString()}`;
1107
- }
1108
- if (value instanceof URL) {
1109
- return `url:${value.toString()}`;
1110
- }
1111
- if (value instanceof RegExp) {
1112
- return `regexp:${value.toString()}`;
1113
- }
1114
- if (value instanceof ArrayBuffer) {
1115
- return `arraybuffer:${serializeBinaryBytes(new Uint8Array(value))}`;
1116
- }
1117
- if (typeof SharedArrayBuffer !== "undefined" && value instanceof SharedArrayBuffer) {
1118
- return `sharedarraybuffer:${serializeBinaryBytes(new Uint8Array(value))}`;
1119
- }
1120
- if (ArrayBuffer.isView(value)) {
1121
- const viewType = Object.prototype.toString.call(value).slice(8, -1);
1122
- const bytes = new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
1123
- return `binary:${viewType}:${serializeBinaryBytes(bytes)}`;
1124
- }
1125
- if (value && typeof value === "object") {
1126
- if (seen.has(value)) {
1127
- return "[Circular]";
1128
- }
1129
- seen.add(value);
1130
- if (Array.isArray(value)) {
1131
- const items = [];
1132
- for (let index = 0; index < value.length; index++) {
1133
- items.push(
1134
- Object.prototype.hasOwnProperty.call(value, index) ? stableSerialize(value[index], seen) : "[Hole]"
1135
- );
1136
- }
1137
- seen.delete(value);
1138
- return `[${items.join(",")}]`;
1139
- }
1140
- if (value instanceof Set) {
1141
- const items = Array.from(value, (item) => stableSerialize(item, seen)).sort(compareCodepoint);
1142
- seen.delete(value);
1143
- return `set:[${items.join(",")}]`;
1144
- }
1145
- if (value instanceof Map) {
1146
- const items = Array.from(
1147
- value,
1148
- ([key, item]) => `[${stableSerialize(key, seen)},${stableSerialize(item, seen)}]`
1149
- ).sort(compareCodepoint);
1150
- seen.delete(value);
1151
- return `map:[${items.join(",")}]`;
1152
- }
1153
- if (value instanceof URLSearchParams) {
1154
- const serialized2 = serializeCanonicalStringEntries(value, seen);
1155
- seen.delete(value);
1156
- return `urlsearchparams:[${serialized2}]`;
1157
- }
1158
- if (value instanceof Headers) {
1159
- const serialized2 = serializeCanonicalStringEntries(value, seen);
1160
- seen.delete(value);
1161
- return `headers:[${serialized2}]`;
1162
- }
1163
- if (!isPlainCacheKeyObject(value)) {
1164
- throw new TypeError(
1165
- `Cache keys do not support ${getCacheKeyValueType(value)} values. Convert the value to an explicit stable string or structured key before caching.`
1166
- );
1167
- }
1168
- const entries = Object.entries(value).sort(
1169
- ([a], [b]) => compareCodepoint(a, b)
1170
- );
1171
- const serialized = entries.map(([key, item]) => `${JSON.stringify(key)}:${stableSerialize(item, seen)}`).join(",");
1172
- seen.delete(value);
1173
- return `{${serialized}}`;
1174
- }
1175
- return String(value);
1176
- }
1177
- __name(stableSerialize, "stableSerialize");
1178
9
 
1179
- // src/client-cache.ts
1180
- var invalidationTrackers = /* @__PURE__ */ new WeakMap();
1181
- function trackFarmClientCacheInvalidations(cache) {
1182
- let trackers = invalidationTrackers.get(cache);
1183
- if (!trackers) {
1184
- trackers = /* @__PURE__ */ new Set();
1185
- invalidationTrackers.set(cache, trackers);
1186
- }
1187
- const keys = /* @__PURE__ */ new Set();
1188
- trackers.add(keys);
1189
- return {
1190
- has(key) {
1191
- const resolved = cache.resolveKey(key);
1192
- for (const invalidated of keys) {
1193
- if (cache.resolveKey(invalidated) === resolved) return true;
1194
- }
1195
- return false;
1196
- },
1197
- dispose() {
1198
- if (!trackers.delete(keys)) return;
1199
- keys.clear();
1200
- if (trackers.size === 0) invalidationTrackers.delete(cache);
1201
- }
1202
- };
1203
- }
1204
- __name(trackFarmClientCacheInvalidations, "trackFarmClientCacheInvalidations");
1205
- var cacheFinalizer = typeof FinalizationRegistry === "function" ? new FinalizationRegistry((unsubscribe) => unsubscribe()) : void 0;
1206
- var DEFAULT_GC_SWEEP_INTERVAL_MS = 3e4;
1207
- var _FarmClientDataCache = class _FarmClientDataCache {
1208
- constructor(options = {}) {
1209
- this.entries = /* @__PURE__ */ new Map();
1210
- this.aliases = /* @__PURE__ */ new Map();
1211
- this.aliasesByTarget = /* @__PURE__ */ new Map();
1212
- this.invalidatedAt = /* @__PURE__ */ new Map();
1213
- this.listeners = /* @__PURE__ */ new Map();
1214
- this.inflight = /* @__PURE__ */ new Map();
1215
- this.pendingMetadataSweeps = /* @__PURE__ */ new Set();
1216
- this.gcSweepIntervalMs = options.gcSweepIntervalMs ?? DEFAULT_GC_SWEEP_INTERVAL_MS;
1217
- if (options.subscribeToInvalidation !== false) {
1218
- if (typeof WeakRef === "function") {
1219
- const reference = new WeakRef(this);
1220
- const unsubscribe = _FarmClientDataCache.subscribeWeakCache(reference);
1221
- cacheFinalizer?.register(this, unsubscribe, reference);
1222
- this.unsubscribeInvalidation = unsubscribe;
1223
- } else {
1224
- this.unsubscribeInvalidation = subscribeFarmCacheInvalidation(
1225
- (key) => this.applyInvalidation(key, Date.now(), false)
1226
- );
1227
- }
1228
- }
1229
- }
1230
- // This closure must only capture a weak reference, never the cache itself.
1231
- static subscribeWeakCache(reference) {
1232
- const unsubscribe = subscribeFarmCacheInvalidation((key) => {
1233
- const cache = reference.deref();
1234
- if (cache) cache.applyInvalidation(key, Date.now(), false);
1235
- else dispose();
1236
- });
1237
- function dispose() {
1238
- unsubscribe();
1239
- cacheFinalizer?.unregister(reference);
1240
- }
1241
- __name(dispose, "dispose");
1242
- return dispose;
1243
- }
1244
- get size() {
1245
- return this.entries.size;
1246
- }
1247
- /** @internal Attach or detach the persistence engine's observation sink. */
1248
- attachPersistence(sink) {
1249
- this.persistence = sink;
1250
- }
1251
- resolveKey(key) {
1252
- let resolved = key;
1253
- const seen = /* @__PURE__ */ new Set();
1254
- while (this.aliases.has(resolved) && !seen.has(resolved)) {
1255
- seen.add(resolved);
1256
- resolved = this.aliases.get(resolved);
1257
- }
1258
- return resolved;
1259
- }
1260
- get(key, now = Date.now()) {
1261
- const resolved = this.resolveKey(key);
1262
- const entry = this.entries.get(resolved);
1263
- if (!entry) return void 0;
1264
- if (entry.gcAt !== void 0 && now >= entry.gcAt) {
1265
- if (entry.fetching) return void 0;
1266
- this.entries.delete(resolved);
1267
- this.persistence?.onDelete(resolved);
1268
- this.sweepEntryMetadata(/* @__PURE__ */ new Set([resolved]));
1269
- this.emit(resolved);
1270
- return void 0;
1271
- }
1272
- return entry;
1273
- }
1274
- set(key, entry) {
1275
- const resolved = this.resolveKey(key);
1276
- const invalidatedAt = this.invalidatedAt.get(resolved);
1277
- const nextEntry = invalidatedAt !== void 0 && invalidatedAt > entry.updatedAt ? { ...entry, staleAt: 0, invalidatedAt } : { ...entry, invalidatedAt: void 0 };
1278
- if (invalidatedAt === void 0 || entry.updatedAt >= invalidatedAt) {
1279
- this.invalidatedAt.delete(resolved);
1280
- }
1281
- this.entries.set(resolved, nextEntry);
1282
- this.pendingMetadataSweeps.delete(resolved);
1283
- if (nextEntry.gcAt !== void 0) this.scheduleGcSweep();
1284
- this.persistence?.onSet(resolved, nextEntry);
1285
- this.emit(resolved);
1286
- return this;
1287
- }
1288
- delete(key) {
1289
- const resolved = this.resolveKey(key);
1290
- const deleted = this.entries.delete(resolved);
1291
- this.inflight.delete(resolved);
1292
- if (deleted) this.persistence?.onDelete(resolved);
1293
- if (deleted || this.pendingMetadataSweeps.has(resolved)) {
1294
- this.sweepEntryMetadata(/* @__PURE__ */ new Set([resolved]));
1295
- }
1296
- this.emit(resolved);
1297
- return deleted;
1298
- }
1299
- clear() {
1300
- const keys = /* @__PURE__ */ new Set([...this.entries.keys(), ...this.listeners.keys()]);
1301
- this.entries.clear();
1302
- this.aliases.clear();
1303
- this.aliasesByTarget.clear();
1304
- this.invalidatedAt.clear();
1305
- this.inflight.clear();
1306
- this.pendingMetadataSweeps.clear();
1307
- this.persistence?.onClear();
1308
- for (const key of keys) this.emit(key);
1309
- }
1310
- dispose() {
1311
- this.unsubscribeInvalidation?.();
1312
- this.unsubscribeInvalidation = void 0;
1313
- if (this.gcTimer !== void 0) {
1314
- clearTimeout(this.gcTimer);
1315
- this.gcTimer = void 0;
1316
- }
1317
- this.clear();
1318
- }
1319
- isStale(key, now = Date.now()) {
1320
- const entry = this.get(key, now);
1321
- return !entry || entry.invalidatedAt !== void 0 || now >= entry.staleAt;
1322
- }
1323
- invalidate(key, now = Date.now()) {
1324
- this.applyInvalidation(key, now, true);
1325
- }
1326
- applyInvalidation(key, now, retainUnowned) {
1327
- const resolved = this.resolveKey(key);
1328
- for (const keys of invalidationTrackers.get(this) ?? []) keys.add(resolved);
1329
- const entry = this.entries.get(resolved);
1330
- const alreadyRetained = this.invalidatedAt.has(resolved);
1331
- if (retainUnowned || entry || alreadyRetained || this.hasMetadataOwner(resolved)) {
1332
- this.invalidatedAt.set(resolved, now);
1333
- if (!entry && !retainUnowned && !alreadyRetained) this.pendingMetadataSweeps.add(resolved);
1334
- }
1335
- if (entry) {
1336
- this.entries.set(resolved, {
1337
- ...entry,
1338
- staleAt: 0,
1339
- invalidatedAt: now
1340
- });
1341
- }
1342
- this.emit(resolved, "invalidate");
1343
- }
1344
- hasMetadataOwner(key) {
1345
- const related = /* @__PURE__ */ new Set([key]);
1346
- for (const target of related) {
1347
- if (this.listeners.has(target) || this.inflight.has(target)) return true;
1348
- for (const alias of this.aliasesByTarget.get(target) ?? []) related.add(alias);
1349
- }
1350
- return false;
1351
- }
1352
- alias(alias, key) {
1353
- const resolved = this.resolveKey(key);
1354
- if (alias === resolved) return;
1355
- const aliasEntry = this.entries.get(alias);
1356
- const aliasInvalidatedAt = this.invalidatedAt.get(alias) ?? aliasEntry?.invalidatedAt;
1357
- const resolvedInvalidatedAt = this.invalidatedAt.get(resolved);
1358
- if (aliasEntry && !this.entries.has(resolved)) {
1359
- this.entries.set(resolved, aliasEntry);
1360
- this.persistence?.onSet(resolved, aliasEntry);
1361
- }
1362
- if (this.entries.delete(alias)) this.persistence?.onDelete(alias);
1363
- this.invalidatedAt.delete(alias);
1364
- const invalidatedAt = [aliasInvalidatedAt, resolvedInvalidatedAt].reduce(
1365
- (latest, value) => value === void 0 ? latest : latest === void 0 ? value : Math.max(latest, value),
1366
- void 0
1367
- );
1368
- const resolvedEntry = this.entries.get(resolved);
1369
- if (invalidatedAt !== void 0 && (!resolvedEntry || invalidatedAt > resolvedEntry.updatedAt)) {
1370
- this.invalidatedAt.set(resolved, invalidatedAt);
1371
- if (resolvedEntry) {
1372
- this.entries.set(resolved, {
1373
- ...resolvedEntry,
1374
- staleAt: 0,
1375
- invalidatedAt
1376
- });
1377
- }
1378
- } else if (invalidatedAt !== void 0) {
1379
- this.invalidatedAt.delete(resolved);
1380
- if (resolvedEntry?.invalidatedAt !== void 0) {
1381
- this.entries.set(resolved, { ...resolvedEntry, invalidatedAt: void 0 });
1382
- }
1383
- }
1384
- const aliasInflight = this.inflight.get(alias);
1385
- if (aliasInflight && !this.inflight.has(resolved)) {
1386
- this.inflight.set(resolved, aliasInflight);
1387
- }
1388
- this.inflight.delete(alias);
1389
- if (this.pendingMetadataSweeps.delete(alias) && !this.entries.has(resolved)) {
1390
- this.pendingMetadataSweeps.add(resolved);
1391
- }
1392
- const previousTarget = this.aliases.get(alias);
1393
- if (previousTarget !== resolved) {
1394
- const previousResolved = previousTarget !== void 0 && this.pendingMetadataSweeps.size > 0 ? this.resolveKey(alias) : void 0;
1395
- this.removeAlias(alias);
1396
- this.aliases.set(alias, resolved);
1397
- let aliases = this.aliasesByTarget.get(resolved);
1398
- if (!aliases) this.aliasesByTarget.set(resolved, aliases = /* @__PURE__ */ new Set());
1399
- aliases.add(alias);
1400
- if (previousResolved !== void 0) this.sweepPendingEntryMetadata(previousResolved);
1401
- }
1402
- this.emit(alias);
1403
- this.emit(resolved, this.invalidatedAt.has(resolved) ? "invalidate" : void 0);
1404
- }
1405
- subscribe(key, listener) {
1406
- let listeners = this.listeners.get(key);
1407
- if (!listeners) {
1408
- listeners = /* @__PURE__ */ new Set();
1409
- this.listeners.set(key, listeners);
1410
- }
1411
- listeners.add(listener);
1412
- return () => {
1413
- listeners.delete(listener);
1414
- if (listeners.size === 0 && this.listeners.get(key) === listeners) {
1415
- this.listeners.delete(key);
1416
- this.sweepPendingEntryMetadata(key);
1417
- }
1418
- };
1419
- }
1420
- getInflight(key) {
1421
- return this.inflight.get(this.resolveKey(key));
1422
- }
1423
- setInflight(key, promise) {
1424
- this.inflight.set(this.resolveKey(key), promise);
1425
- }
1426
- deleteInflight(key) {
1427
- const resolved = this.resolveKey(key);
1428
- if (this.inflight.delete(resolved)) this.sweepPendingEntryMetadata(resolved);
1429
- }
1430
- scheduleGcSweep() {
1431
- if (this.gcSweepIntervalMs === false || this.gcTimer !== void 0) return;
1432
- const timer = setTimeout(() => {
1433
- this.gcTimer = void 0;
1434
- this.sweepExpiredEntries();
1435
- }, this.gcSweepIntervalMs);
1436
- timer.unref?.();
1437
- this.gcTimer = timer;
1438
- }
1439
- sweepExpiredEntries(now = Date.now()) {
1440
- const watched = /* @__PURE__ */ new Set();
1441
- for (const key of this.listeners.keys()) watched.add(this.resolveKey(key));
1442
- let remaining = false;
1443
- const swept = /* @__PURE__ */ new Set();
1444
- for (const [key, entry] of this.entries) {
1445
- if (entry.gcAt === void 0) continue;
1446
- if (now < entry.gcAt || entry.fetching || this.inflight.has(key) || watched.has(key)) {
1447
- remaining = true;
1448
- continue;
1449
- }
1450
- this.entries.delete(key);
1451
- this.persistence?.onDelete(key);
1452
- swept.add(key);
1453
- }
1454
- if (swept.size > 0) this.sweepEntryMetadata(swept);
1455
- if (remaining) this.scheduleGcSweep();
1456
- }
1457
- /**
1458
- * Entry eviction alone leaves the per-key metadata behind. `invalidatedAt`
1459
- * marks and provisional aliases are created per query invocation, so with
1460
- * dynamic keys they accumulate for the lifetime of the page even though the
1461
- * entries they describe are long gone.
1462
- */
1463
- sweepEntryMetadata(swept) {
1464
- const protectedKeys = /* @__PURE__ */ new Set();
1465
- for (const key of swept) if (this.hasMetadataOwner(key)) protectedKeys.add(key);
1466
- for (const key of swept) {
1467
- if (this.entries.has(key)) {
1468
- this.pendingMetadataSweeps.delete(key);
1469
- } else if (protectedKeys.has(key)) {
1470
- this.pendingMetadataSweeps.add(key);
1471
- } else {
1472
- this.pendingMetadataSweeps.delete(key);
1473
- this.invalidatedAt.delete(key);
1474
- }
1475
- }
1476
- const related = /* @__PURE__ */ new Set();
1477
- const targets = new Set(swept);
1478
- for (const target of targets) {
1479
- for (const alias of this.aliasesByTarget.get(target) ?? []) {
1480
- related.add(alias);
1481
- targets.add(alias);
1482
- }
1483
- }
1484
- const removable = [];
1485
- for (const alias of related) {
1486
- if (this.entries.has(alias) || this.listeners.has(alias) || this.inflight.has(alias))
1487
- continue;
1488
- const resolved = this.resolveKey(alias);
1489
- if (!swept.has(resolved)) continue;
1490
- if (this.entries.has(resolved) || protectedKeys.has(resolved)) continue;
1491
- removable.push(alias);
1492
- }
1493
- for (const alias of removable) {
1494
- this.removeAlias(alias);
1495
- this.invalidatedAt.delete(alias);
1496
- }
1497
- }
1498
- removeAlias(alias) {
1499
- const target = this.aliases.get(alias);
1500
- if (target === void 0) return;
1501
- this.aliases.delete(alias);
1502
- const aliases = this.aliasesByTarget.get(target);
1503
- aliases?.delete(alias);
1504
- if (aliases?.size === 0) this.aliasesByTarget.delete(target);
1505
- }
1506
- sweepPendingEntryMetadata(key) {
1507
- if (this.pendingMetadataSweeps.size === 0) return;
1508
- if (key !== void 0) {
1509
- const resolved = this.resolveKey(key);
1510
- if (this.pendingMetadataSweeps.has(resolved)) {
1511
- this.sweepEntryMetadata(/* @__PURE__ */ new Set([resolved]));
1512
- }
1513
- return;
1514
- }
1515
- this.sweepEntryMetadata(new Set(this.pendingMetadataSweeps));
1516
- }
1517
- emit(key, event) {
1518
- this.notifyListeners(key, event);
1519
- if (this.listeners.size === 0) return;
1520
- for (const [alias, target] of this.aliases) {
1521
- if (!this.listeners.has(alias)) continue;
1522
- if (this.resolveKey(target) === key) {
1523
- this.notifyListeners(alias, event);
1524
- }
1525
- }
1526
- }
1527
- notifyListeners(key, event) {
1528
- for (const listener of this.listeners.get(key) ?? []) {
1529
- try {
1530
- listener(event);
1531
- } catch (error) {
1532
- const detail = error instanceof Error ? error.stack ?? error.message : String(error);
1533
- console.warn(`[farm:client-cache] cache listener failed: ${detail}`);
1534
- }
1535
- }
1536
- }
1537
- };
1538
- __name(_FarmClientDataCache, "FarmClientDataCache");
1539
- var FarmClientDataCache = _FarmClientDataCache;
1540
- var FARM_CLIENT_DATA_CACHE = /* @__PURE__ */ Symbol.for("farm.clientDataCache");
1541
- var clientCacheGlobal = globalThis;
1542
- var sharedFarmClientDataCache = clientCacheGlobal[FARM_CLIENT_DATA_CACHE] ?? (clientCacheGlobal[FARM_CLIENT_DATA_CACHE] = new FarmClientDataCache());
1543
- function getFarmClientDataCache() {
1544
- return sharedFarmClientDataCache;
1545
- }
1546
- __name(getFarmClientDataCache, "getFarmClientDataCache");
1547
10
 
1548
- // src/client-revalidation.ts
1549
- function attachRevalidationListeners(refresh, options = {}) {
1550
- if (typeof window === "undefined") return () => {
1551
- };
1552
- const onFocus = options.refetchOnWindowFocus === false ? void 0 : refresh;
1553
- const onOnline = options.refetchOnReconnect === false ? void 0 : refresh;
1554
- if (onFocus) window.addEventListener("focus", onFocus);
1555
- if (onOnline) window.addEventListener("online", onOnline);
1556
- return () => {
1557
- if (onFocus) window.removeEventListener("focus", onFocus);
1558
- if (onOnline) window.removeEventListener("online", onOnline);
1559
- };
1560
- }
1561
- __name(attachRevalidationListeners, "attachRevalidationListeners");
11
+ var _chunkY4YWHNKUcjs = require('./chunk-Y4YWHNKU.cjs');
12
+ require('./chunk-I7PUUDGY.cjs');
13
+ require('./chunk-SK35NQKK.cjs');
14
+ require('./chunk-H6G5INWM.cjs');
15
+ require('./chunk-ZEG3OPIB.cjs');
16
+ require('./chunk-LIUGYUX3.cjs');
17
+ require('./chunk-E3UK5IIB.cjs');
18
+ require('./chunk-S3JO3N4H.cjs');
1562
19
 
1563
- // src/server-query-protocol.ts
1564
- var FARM_SERVER_QUERY_RESULT_VERSION = 1;
1565
- function isFarmServerQueryResult(value) {
1566
- if (!value || typeof value !== "object") return false;
1567
- const metadata = value.__farmServerQuery;
1568
- return metadata?.version === FARM_SERVER_QUERY_RESULT_VERSION && typeof metadata.key === "string" && (metadata.staleTime === false || typeof metadata.staleTime === "number") && typeof metadata.updatedAt === "number" && "data" in value;
1569
- }
1570
- __name(isFarmServerQueryResult, "isFarmServerQueryResult");
1571
20
 
1572
- // src/server-query-runtime.ts
1573
- var FARM_SERVER_QUERY_CLIENT_STATE = /* @__PURE__ */ Symbol.for("farm.serverQueryClientState");
1574
- var serverQueryClientGlobal = globalThis;
1575
- var serverQueryClientState = serverQueryClientGlobal[FARM_SERVER_QUERY_CLIENT_STATE] ?? (serverQueryClientGlobal[FARM_SERVER_QUERY_CLIENT_STATE] = {
1576
- functionIds: /* @__PURE__ */ new WeakMap(),
1577
- nextFunctionId: 0,
1578
- active: [],
1579
- latestOwners: /* @__PURE__ */ new Map(),
1580
- owners: /* @__PURE__ */ new Set()
1581
- });
1582
- serverQueryClientState.latestOwners ?? (serverQueryClientState.latestOwners = /* @__PURE__ */ new Map());
1583
- serverQueryClientState.owners ?? (serverQueryClientState.owners = /* @__PURE__ */ new Set());
1584
- function isServerQueryOwnerSuperseded(owner, key) {
1585
- const cache = getFarmClientDataCache();
1586
- const resolved = cache.resolveKey(key);
1587
- for (const superseded of owner.supersededKeys ?? []) {
1588
- if (cache.resolveKey(superseded) === resolved) return true;
1589
- }
1590
- return false;
1591
- }
1592
- __name(isServerQueryOwnerSuperseded, "isServerQueryOwnerSuperseded");
1593
- function claimServerQueryKey(owner, key) {
1594
- if (isServerQueryOwnerSuperseded(owner, key)) return false;
1595
- const resolved = getFarmClientDataCache().resolveKey(key);
1596
- for (const older of serverQueryClientState.owners) {
1597
- if (older === owner) break;
1598
- older.supersededKeys.add(resolved);
1599
- }
1600
- return true;
1601
- }
1602
- __name(claimServerQueryKey, "claimServerQueryKey");
1603
- var RAW_SERVER_QUERY_SYMBOL = /* @__PURE__ */ Symbol.for("farm.server-query");
1604
- function assertNotRawServerQueryInBrowser(query) {
1605
- if (typeof window === "undefined" || typeof document === "undefined") return;
1606
- if (!query?.[RAW_SERVER_QUERY_SYMBOL]) return;
1607
- throw new Error(
1608
- [
1609
- "useServerQuery received a raw server query implementation in the browser.",
1610
- "Server query handlers run only on the server. Enable the server-function transform (add @farm.js/plugin/rsc and set experimental.serverActions: true in farm.config.ts) so client imports become server references,",
1611
- "or call the query from server code / an API route (createAPIClient) instead."
1612
- ].join("\n")
1613
- );
1614
- }
1615
- __name(assertNotRawServerQueryInBrowser, "assertNotRawServerQueryInBrowser");
1616
- function beginFarmServerQueryAction(actionId, args) {
1617
- const active = serverQueryClientState.active.at(-1);
1618
- return {
1619
- actionId,
1620
- args,
1621
- provisionalKey: active?.provisionalKey,
1622
- owner: active?.owner
1623
- };
1624
- }
1625
- __name(beginFarmServerQueryAction, "beginFarmServerQueryAction");
1626
- function completeFarmServerQueryAction(invocation, value) {
1627
- if (!isFarmServerQueryResult(value)) return value;
1628
- const cache = getFarmClientDataCache();
1629
- const metadata = value.__farmServerQuery;
1630
- if (!shouldApplyFarmServerQueryActionResult(invocation)) {
1631
- return value.data;
1632
- }
1633
- if (invocation.provisionalKey) {
1634
- cache.alias(invocation.provisionalKey, metadata.key);
1635
- }
1636
- const owner = invocation.owner;
1637
- if (owner && serverQueryClientState.owners.has(owner) && !claimServerQueryKey(owner, metadata.key)) {
1638
- return value.data;
1639
- }
1640
- const invalidated = invocation.owner?.invalidations?.has(
1641
- metadata.key
1642
- );
1643
- cache.set(metadata.key, {
1644
- data: value.data,
1645
- updatedAt: metadata.updatedAt,
1646
- staleAt: invalidated ? 0 : metadata.staleTime === false ? Number.POSITIVE_INFINITY : metadata.updatedAt + metadata.staleTime,
1647
- status: "success",
1648
- error: null,
1649
- fetching: false,
1650
- persist: metadata.persist === true ? true : void 0
1651
- });
1652
- return value.data;
1653
- }
1654
- __name(completeFarmServerQueryAction, "completeFarmServerQueryAction");
1655
- function shouldApplyFarmServerQueryActionResult(invocation) {
1656
- if (!invocation.provisionalKey || !invocation.owner) return true;
1657
- return isCurrentServerQueryOwner(invocation.provisionalKey, invocation.owner);
1658
- }
1659
- __name(shouldApplyFarmServerQueryActionResult, "shouldApplyFarmServerQueryActionResult");
1660
- function isCurrentServerQueryOwner(provisionalKey, owner) {
1661
- return serverQueryClientState.latestOwners.get(provisionalKey) === owner && !isServerQueryOwnerSuperseded(owner, provisionalKey);
1662
- }
1663
- __name(isCurrentServerQueryOwner, "isCurrentServerQueryOwner");
1664
- function createServerQueryCallKey(query, input) {
1665
- let id = serverQueryClientState.functionIds.get(query);
1666
- if (!id) {
1667
- id = ++serverQueryClientState.nextFunctionId;
1668
- serverQueryClientState.functionIds.set(query, id);
1669
- }
1670
- return createFarmCacheKey(["server-query-call", id, input]);
1671
- }
1672
- __name(createServerQueryCallKey, "createServerQueryCallKey");
1673
- async function fetchServerQuery(query, input, options = {}) {
1674
- const cache = getFarmClientDataCache();
1675
- const provisionalKey = createServerQueryCallKey(query, input);
1676
- const entry = cache.get(provisionalKey);
1677
- const stale = cache.isStale(provisionalKey);
1678
- const inflight = cache.getInflight(provisionalKey);
1679
- if (!options.force && entry && stale && (entry.status !== "pending" || entry.updatedAt !== 0) && entry.status !== "error" && (options.swr ?? true)) {
1680
- if (!inflight) {
1681
- void executeServerQuery(query, input, provisionalKey, options).catch(() => void 0);
1682
- }
1683
- return entry.data;
1684
- }
1685
- if (inflight && !options.force) return inflight;
1686
- if (!options.force && entry && !stale && entry.status !== "error") return entry.data;
1687
- return executeServerQuery(query, input, provisionalKey, options);
1688
- }
1689
- __name(fetchServerQuery, "fetchServerQuery");
1690
- function prefetchServerQuery(query, input, options = {}) {
1691
- return fetchServerQuery(query, input, options);
1692
- }
1693
- __name(prefetchServerQuery, "prefetchServerQuery");
1694
- async function executeServerQuery(query, input, provisionalKey, options) {
1695
- assertNotRawServerQueryInBrowser(query);
1696
- const cache = getFarmClientDataCache();
1697
- const inflight = cache.getInflight(provisionalKey);
1698
- if (inflight && !options.force) return inflight;
1699
- const owner = {
1700
- invalidations: trackFarmClientCacheInvalidations(cache),
1701
- supersededKeys: /* @__PURE__ */ new Set()
1702
- };
1703
- serverQueryClientState.latestOwners.set(provisionalKey, owner);
1704
- serverQueryClientState.owners.add(owner);
1705
- claimServerQueryKey(owner, provisionalKey);
1706
- const previous = cache.get(provisionalKey);
1707
- cache.set(provisionalKey, {
1708
- data: previous?.data,
1709
- updatedAt: previous?.updatedAt ?? 0,
1710
- staleAt: previous?.staleAt ?? 0,
1711
- gcAt: previous?.gcAt,
1712
- invalidatedAt: previous?.invalidatedAt,
1713
- status: "pending",
1714
- error: null,
1715
- fetching: true
1716
- });
1717
- let promise;
1718
- promise = (async () => {
1719
- await Promise.resolve();
1720
- try {
1721
- serverQueryClientState.active.push({ provisionalKey, owner });
1722
- let pending;
1723
- try {
1724
- pending = query(input);
1725
- } finally {
1726
- serverQueryClientState.active.pop();
1727
- }
1728
- const data = await pending;
1729
- const transported = cache.get(provisionalKey);
1730
- if (isCurrentServerQueryOwner(provisionalKey, owner) && (!transported || transported.fetching)) {
1731
- const updatedAt = Date.now();
1732
- cache.set(provisionalKey, {
1733
- data,
1734
- updatedAt,
1735
- staleAt: owner.invalidations.has(provisionalKey) ? 0 : options.staleTime === false ? Number.POSITIVE_INFINITY : updatedAt + (options.staleTime ?? 0),
1736
- status: "success",
1737
- error: null,
1738
- fetching: false
1739
- });
1740
- }
1741
- return data;
1742
- } catch (cause) {
1743
- const error = normalizeServerQueryError(cause);
1744
- if (isCurrentServerQueryOwner(provisionalKey, owner)) {
1745
- const current = cache.get(provisionalKey);
1746
- cache.set(provisionalKey, {
1747
- data: current?.data,
1748
- updatedAt: current?.updatedAt ?? 0,
1749
- staleAt: current?.staleAt ?? 0,
1750
- gcAt: current?.gcAt,
1751
- invalidatedAt: current?.invalidatedAt,
1752
- status: "error",
1753
- error,
1754
- fetching: false
1755
- });
1756
- }
1757
- throw error;
1758
- } finally {
1759
- const invalidated = isCurrentServerQueryOwner(provisionalKey, owner) && owner.invalidations.has(provisionalKey);
1760
- owner.invalidations.dispose();
1761
- serverQueryClientState.owners.delete(owner);
1762
- owner.supersededKeys.clear();
1763
- if (cache.getInflight(provisionalKey) === promise) {
1764
- cache.deleteInflight(provisionalKey);
1765
- }
1766
- if (serverQueryClientState.latestOwners.get(provisionalKey) === owner) {
1767
- serverQueryClientState.latestOwners.delete(provisionalKey);
1768
- }
1769
- if (invalidated) cache.invalidate(provisionalKey);
1770
- }
1771
- })();
1772
- cache.setInflight(provisionalKey, promise);
1773
- return promise;
1774
- }
1775
- __name(executeServerQuery, "executeServerQuery");
1776
- function normalizeServerQueryError(cause) {
1777
- if (cause instanceof Error) return cause;
1778
- const error = new Error(typeof cause === "string" ? cause : "Server query failed");
1779
- error.cause = cause;
1780
- return error;
1781
- }
1782
- __name(normalizeServerQueryError, "normalizeServerQueryError");
1783
21
 
1784
- // src/server-query-client.ts
1785
- function useServerQuery(query, input, options = {}) {
1786
- const cache = getFarmClientDataCache();
1787
- const key = createServerQueryCallKey(query, input);
1788
- const inputRef = (0, import_react.useRef)(input);
1789
- const optionsRef = (0, import_react.useRef)(options);
1790
- const mountedKeyRef = (0, import_react.useRef)(void 0);
1791
- const pendingInvalidationRef = (0, import_react.useRef)(false);
1792
- inputRef.current = input;
1793
- optionsRef.current = options;
1794
- const subscribe = (0, import_react.useCallback)(
1795
- (listener) => cache.subscribe(key, (event) => {
1796
- if (event === "invalidate") pendingInvalidationRef.current = true;
1797
- else if (cache.get(key)?.fetching) {
1798
- pendingInvalidationRef.current = false;
1799
- }
1800
- listener();
1801
- }),
1802
- [cache, key]
1803
- );
1804
- const getSnapshot = (0, import_react.useCallback)(() => cache.get(key), [cache, key]);
1805
- const entry = (0, import_react.useSyncExternalStore)(subscribe, getSnapshot, () => void 0);
1806
- const run = (0, import_react.useCallback)(
1807
- (force = false) => {
1808
- pendingInvalidationRef.current = false;
1809
- return fetchServerQuery(query, inputRef.current, {
1810
- ...optionsRef.current,
1811
- force
1812
- });
1813
- },
1814
- [query]
1815
- );
1816
- (0, import_react.useEffect)(() => {
1817
- if (options.enabled === false) {
1818
- mountedKeyRef.current = void 0;
1819
- return;
1820
- }
1821
- const firstReadForKey = mountedKeyRef.current !== key;
1822
- if (firstReadForKey) mountedKeyRef.current = key;
1823
- if (firstReadForKey && (!entry || cache.isStale(key)) || pendingInvalidationRef.current && entry?.invalidatedAt !== void 0 && !entry.fetching) {
1824
- void run().catch(() => void 0);
1825
- }
1826
- }, [cache, entry, key, options.enabled, run]);
1827
- (0, import_react.useEffect)(() => {
1828
- if (options.enabled === false) return;
1829
- return attachRevalidationListeners(
1830
- () => {
1831
- if (cache.isStale(key)) void run().catch(() => void 0);
1832
- },
1833
- {
1834
- refetchOnWindowFocus: options.refetchOnWindowFocus,
1835
- refetchOnReconnect: options.refetchOnReconnect
1836
- }
1837
- );
1838
- }, [cache, key, options.enabled, options.refetchOnReconnect, options.refetchOnWindowFocus, run]);
1839
- const status = entry?.status ?? (entry ? "success" : "idle");
1840
- const fetching = entry?.fetching ?? false;
1841
- return {
1842
- data: entry?.data,
1843
- error: entry?.error ?? null,
1844
- status,
1845
- pending: status === "pending" && (entry?.updatedAt ?? 0) === 0,
1846
- fetching,
1847
- stale: cache.isStale(key),
1848
- refetch: /* @__PURE__ */ __name(() => run(true), "refetch")
1849
- };
1850
- }
1851
- __name(useServerQuery, "useServerQuery");
1852
- // Annotate the CommonJS export names for ESM import in node:
1853
- 0 && (module.exports = {
1854
- beginFarmServerQueryAction,
1855
- completeFarmServerQueryAction,
1856
- fetchServerQuery,
1857
- prefetchServerQuery,
1858
- shouldApplyFarmServerQueryActionResult,
1859
- useServerQuery
1860
- });
22
+
23
+
24
+
25
+
26
+ exports.beginFarmServerQueryAction = _chunkY4YWHNKUcjs.beginFarmServerQueryAction; exports.completeFarmServerQueryAction = _chunkY4YWHNKUcjs.completeFarmServerQueryAction; exports.fetchServerQuery = _chunkY4YWHNKUcjs.fetchServerQuery; exports.prefetchServerQuery = _chunkY4YWHNKUcjs.prefetchServerQuery; exports.shouldApplyFarmServerQueryActionResult = _chunkY4YWHNKUcjs.shouldApplyFarmServerQueryActionResult; exports.useServerQuery = _chunkC3VRMB6Hcjs.useServerQuery;