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