@farm.js/core 0.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +11 -0
- package/dist/after.cjs +227 -0
- package/dist/after.cjs.map +1 -0
- package/dist/after.d.mts +25 -0
- package/dist/after.d.ts +25 -0
- package/dist/after.mjs +14 -0
- package/dist/after.mjs.map +1 -0
- package/dist/agent-runtime.cjs +2379 -0
- package/dist/agent-runtime.cjs.map +1 -0
- package/dist/agent-runtime.d.mts +93 -0
- package/dist/agent-runtime.d.ts +93 -0
- package/dist/agent-runtime.mjs +479 -0
- package/dist/agent-runtime.mjs.map +1 -0
- package/dist/api/route-manager.cjs +1196 -0
- package/dist/api/route-manager.cjs.map +1 -0
- package/dist/api/route-manager.d.mts +64 -0
- package/dist/api/route-manager.d.ts +64 -0
- package/dist/api/route-manager.mjs +34 -0
- package/dist/api/route-manager.mjs.map +1 -0
- package/dist/api/runtime.cjs +272 -0
- package/dist/api/runtime.cjs.map +1 -0
- package/dist/api/runtime.d.mts +16 -0
- package/dist/api/runtime.d.ts +16 -0
- package/dist/api/runtime.mjs +16 -0
- package/dist/api/runtime.mjs.map +1 -0
- package/dist/api.cjs +3199 -0
- package/dist/api.cjs.map +1 -0
- package/dist/api.d.mts +190 -0
- package/dist/api.d.ts +190 -0
- package/dist/api.mjs +63 -0
- package/dist/api.mjs.map +1 -0
- package/dist/app-BiX4qb-d.d.mts +265 -0
- package/dist/app-CFRNJXP1.d.ts +265 -0
- package/dist/app-markdown.cjs +220 -0
- package/dist/app-markdown.cjs.map +1 -0
- package/dist/app-markdown.d.mts +21 -0
- package/dist/app-markdown.d.ts +21 -0
- package/dist/app-markdown.mjs +26 -0
- package/dist/app-markdown.mjs.map +1 -0
- package/dist/cache.cjs +543 -0
- package/dist/cache.cjs.map +1 -0
- package/dist/cache.d.mts +78 -0
- package/dist/cache.d.ts +78 -0
- package/dist/cache.mjs +38 -0
- package/dist/cache.mjs.map +1 -0
- package/dist/chunk-25D7G34K.mjs +142 -0
- package/dist/chunk-25D7G34K.mjs.map +1 -0
- package/dist/chunk-3QJO55ZF.mjs +3548 -0
- package/dist/chunk-3QJO55ZF.mjs.map +1 -0
- package/dist/chunk-3XNTL3FQ.mjs +452 -0
- package/dist/chunk-3XNTL3FQ.mjs.map +1 -0
- package/dist/chunk-44ZCFSKE.mjs +84 -0
- package/dist/chunk-44ZCFSKE.mjs.map +1 -0
- package/dist/chunk-4PTK6KT4.mjs +364 -0
- package/dist/chunk-4PTK6KT4.mjs.map +1 -0
- package/dist/chunk-4S3ORGFA.mjs +44 -0
- package/dist/chunk-4S3ORGFA.mjs.map +1 -0
- package/dist/chunk-5BY76U2M.mjs +1 -0
- package/dist/chunk-5BY76U2M.mjs.map +1 -0
- package/dist/chunk-5ZGPRGWV.mjs +136 -0
- package/dist/chunk-5ZGPRGWV.mjs.map +1 -0
- package/dist/chunk-6XDUHOEM.mjs +157 -0
- package/dist/chunk-6XDUHOEM.mjs.map +1 -0
- package/dist/chunk-74YTBPTY.mjs +450 -0
- package/dist/chunk-74YTBPTY.mjs.map +1 -0
- package/dist/chunk-7HO6AEOP.mjs +74 -0
- package/dist/chunk-7HO6AEOP.mjs.map +1 -0
- package/dist/chunk-7MABZJIM.mjs +29 -0
- package/dist/chunk-7MABZJIM.mjs.map +1 -0
- package/dist/chunk-7ZY5AIJO.mjs +161 -0
- package/dist/chunk-7ZY5AIJO.mjs.map +1 -0
- package/dist/chunk-AGS7UJ52.mjs +446 -0
- package/dist/chunk-AGS7UJ52.mjs.map +1 -0
- package/dist/chunk-AZ7YUVNR.mjs +65 -0
- package/dist/chunk-AZ7YUVNR.mjs.map +1 -0
- package/dist/chunk-B232I2GP.mjs +163 -0
- package/dist/chunk-B232I2GP.mjs.map +1 -0
- package/dist/chunk-B6N4ZB2H.mjs +718 -0
- package/dist/chunk-B6N4ZB2H.mjs.map +1 -0
- package/dist/chunk-BHG3LVHH.mjs +176 -0
- package/dist/chunk-BHG3LVHH.mjs.map +1 -0
- package/dist/chunk-C3DLZMBU.mjs +597 -0
- package/dist/chunk-C3DLZMBU.mjs.map +1 -0
- package/dist/chunk-CGILA3WO.mjs +14 -0
- package/dist/chunk-CGILA3WO.mjs.map +1 -0
- package/dist/chunk-CHFHNEMO.mjs +7088 -0
- package/dist/chunk-CHFHNEMO.mjs.map +1 -0
- package/dist/chunk-E2MPIBRE.mjs +149 -0
- package/dist/chunk-E2MPIBRE.mjs.map +1 -0
- package/dist/chunk-E6EPN5BT.mjs +203 -0
- package/dist/chunk-E6EPN5BT.mjs.map +1 -0
- package/dist/chunk-EVGBEZDF.mjs +215 -0
- package/dist/chunk-EVGBEZDF.mjs.map +1 -0
- package/dist/chunk-FQYDHKKU.mjs +128 -0
- package/dist/chunk-FQYDHKKU.mjs.map +1 -0
- package/dist/chunk-G3B5BRDY.mjs +5763 -0
- package/dist/chunk-G3B5BRDY.mjs.map +1 -0
- package/dist/chunk-GN72QAIH.mjs +146 -0
- package/dist/chunk-GN72QAIH.mjs.map +1 -0
- package/dist/chunk-GS6K5OCM.mjs +407 -0
- package/dist/chunk-GS6K5OCM.mjs.map +1 -0
- package/dist/chunk-GY2STC2S.mjs +180 -0
- package/dist/chunk-GY2STC2S.mjs.map +1 -0
- package/dist/chunk-GZP5W4K3.mjs +158 -0
- package/dist/chunk-GZP5W4K3.mjs.map +1 -0
- package/dist/chunk-H2FA2SBS.mjs +51 -0
- package/dist/chunk-H2FA2SBS.mjs.map +1 -0
- package/dist/chunk-HXP3ZSPC.mjs +211 -0
- package/dist/chunk-HXP3ZSPC.mjs.map +1 -0
- package/dist/chunk-ITN462YM.mjs +98 -0
- package/dist/chunk-ITN462YM.mjs.map +1 -0
- package/dist/chunk-J23HNLFY.mjs +72 -0
- package/dist/chunk-J23HNLFY.mjs.map +1 -0
- package/dist/chunk-J4FNJ5IU.mjs +179 -0
- package/dist/chunk-J4FNJ5IU.mjs.map +1 -0
- package/dist/chunk-JK25YEN6.mjs +219 -0
- package/dist/chunk-JK25YEN6.mjs.map +1 -0
- package/dist/chunk-JLWMCADZ.mjs +204 -0
- package/dist/chunk-JLWMCADZ.mjs.map +1 -0
- package/dist/chunk-JN3UU635.mjs +622 -0
- package/dist/chunk-JN3UU635.mjs.map +1 -0
- package/dist/chunk-K4667E2Q.mjs +1916 -0
- package/dist/chunk-K4667E2Q.mjs.map +1 -0
- package/dist/chunk-LGHEOHBU.mjs +218 -0
- package/dist/chunk-LGHEOHBU.mjs.map +1 -0
- package/dist/chunk-LLC7BNXW.mjs +275 -0
- package/dist/chunk-LLC7BNXW.mjs.map +1 -0
- package/dist/chunk-LM2YNO4U.mjs +24 -0
- package/dist/chunk-LM2YNO4U.mjs.map +1 -0
- package/dist/chunk-NNLCAVB6.mjs +391 -0
- package/dist/chunk-NNLCAVB6.mjs.map +1 -0
- package/dist/chunk-O3HADRW6.mjs +639 -0
- package/dist/chunk-O3HADRW6.mjs.map +1 -0
- package/dist/chunk-OYXO65LI.mjs +119 -0
- package/dist/chunk-OYXO65LI.mjs.map +1 -0
- package/dist/chunk-P7QDS5AT.mjs +191 -0
- package/dist/chunk-P7QDS5AT.mjs.map +1 -0
- package/dist/chunk-PRNYWD7K.mjs +599 -0
- package/dist/chunk-PRNYWD7K.mjs.map +1 -0
- package/dist/chunk-QF4PHCMA.mjs +422 -0
- package/dist/chunk-QF4PHCMA.mjs.map +1 -0
- package/dist/chunk-QFQRHRZS.mjs +1224 -0
- package/dist/chunk-QFQRHRZS.mjs.map +1 -0
- package/dist/chunk-QGOHVJ6J.mjs +63 -0
- package/dist/chunk-QGOHVJ6J.mjs.map +1 -0
- package/dist/chunk-QKVUNGAH.mjs +39 -0
- package/dist/chunk-QKVUNGAH.mjs.map +1 -0
- package/dist/chunk-QM6VV26B.mjs +149 -0
- package/dist/chunk-QM6VV26B.mjs.map +1 -0
- package/dist/chunk-RHIFZZUI.mjs +69 -0
- package/dist/chunk-RHIFZZUI.mjs.map +1 -0
- package/dist/chunk-RKI6TN3A.mjs +49 -0
- package/dist/chunk-RKI6TN3A.mjs.map +1 -0
- package/dist/chunk-RSKVYESE.mjs +187 -0
- package/dist/chunk-RSKVYESE.mjs.map +1 -0
- package/dist/chunk-S2XHZS7W.mjs +180 -0
- package/dist/chunk-S2XHZS7W.mjs.map +1 -0
- package/dist/chunk-SCFX4UTD.mjs +28 -0
- package/dist/chunk-SCFX4UTD.mjs.map +1 -0
- package/dist/chunk-SL6HTIOK.mjs +66 -0
- package/dist/chunk-SL6HTIOK.mjs.map +1 -0
- package/dist/chunk-SOU3Q3ZA.mjs +173 -0
- package/dist/chunk-SOU3Q3ZA.mjs.map +1 -0
- package/dist/chunk-SPBBQLXI.mjs +207 -0
- package/dist/chunk-SPBBQLXI.mjs.map +1 -0
- package/dist/chunk-SXZTEK3V.mjs +396 -0
- package/dist/chunk-SXZTEK3V.mjs.map +1 -0
- package/dist/chunk-T4QJQK76.mjs +459 -0
- package/dist/chunk-T4QJQK76.mjs.map +1 -0
- package/dist/chunk-TRORP7E4.mjs +41 -0
- package/dist/chunk-TRORP7E4.mjs.map +1 -0
- package/dist/chunk-TU4YJICB.mjs +728 -0
- package/dist/chunk-TU4YJICB.mjs.map +1 -0
- package/dist/chunk-TXCFGOHW.mjs +42 -0
- package/dist/chunk-TXCFGOHW.mjs.map +1 -0
- package/dist/chunk-UHE2TTLK.mjs +466 -0
- package/dist/chunk-UHE2TTLK.mjs.map +1 -0
- package/dist/chunk-UREJA4GZ.mjs +364 -0
- package/dist/chunk-UREJA4GZ.mjs.map +1 -0
- package/dist/chunk-USWZZUEH.mjs +25 -0
- package/dist/chunk-USWZZUEH.mjs.map +1 -0
- package/dist/chunk-UVCIEUJC.mjs +16 -0
- package/dist/chunk-UVCIEUJC.mjs.map +1 -0
- package/dist/chunk-V6WE6JSZ.mjs +352 -0
- package/dist/chunk-V6WE6JSZ.mjs.map +1 -0
- package/dist/chunk-V7RBCSDJ.mjs +170 -0
- package/dist/chunk-V7RBCSDJ.mjs.map +1 -0
- package/dist/chunk-VCANOYFI.mjs +588 -0
- package/dist/chunk-VCANOYFI.mjs.map +1 -0
- package/dist/chunk-WZ5QFROO.mjs +23 -0
- package/dist/chunk-WZ5QFROO.mjs.map +1 -0
- package/dist/chunk-Y2OJJD7R.mjs +543 -0
- package/dist/chunk-Y2OJJD7R.mjs.map +1 -0
- package/dist/chunk-Y7A27276.mjs +538 -0
- package/dist/chunk-Y7A27276.mjs.map +1 -0
- package/dist/chunk-YHU7SS6L.mjs +365 -0
- package/dist/chunk-YHU7SS6L.mjs.map +1 -0
- package/dist/chunk-ZBE6MLHL.mjs +230 -0
- package/dist/chunk-ZBE6MLHL.mjs.map +1 -0
- package/dist/chunk-ZJQNATYV.mjs +299 -0
- package/dist/chunk-ZJQNATYV.mjs.map +1 -0
- package/dist/client-D_yUjVhe.d.mts +402 -0
- package/dist/client-Dkc03WP8.d.ts +402 -0
- package/dist/client-cache-CIlyBlmx.d.ts +6 -0
- package/dist/client-cache-D-EZ7XVW.d.mts +6 -0
- package/dist/client-plugins-BZnpeTGA.d.ts +1848 -0
- package/dist/client-plugins-g4bzuCmo.d.mts +1848 -0
- package/dist/client-plugins.cjs +415 -0
- package/dist/client-plugins.cjs.map +1 -0
- package/dist/client-plugins.d.mts +21 -0
- package/dist/client-plugins.d.ts +21 -0
- package/dist/client-plugins.mjs +10 -0
- package/dist/client-plugins.mjs.map +1 -0
- package/dist/client.cjs +4571 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.mts +329 -0
- package/dist/client.d.ts +329 -0
- package/dist/client.mjs +103 -0
- package/dist/client.mjs.map +1 -0
- package/dist/config.cjs +38 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.mts +28 -0
- package/dist/config.d.ts +28 -0
- package/dist/config.mjs +10 -0
- package/dist/config.mjs.map +1 -0
- package/dist/cron.cjs +406 -0
- package/dist/cron.cjs.map +1 -0
- package/dist/cron.d.mts +78 -0
- package/dist/cron.d.ts +78 -0
- package/dist/cron.mjs +30 -0
- package/dist/cron.mjs.map +1 -0
- package/dist/deferred.cjs +438 -0
- package/dist/deferred.cjs.map +1 -0
- package/dist/deferred.d.mts +42 -0
- package/dist/deferred.d.ts +42 -0
- package/dist/deferred.mjs +28 -0
- package/dist/deferred.mjs.map +1 -0
- package/dist/deployment.cjs +199 -0
- package/dist/deployment.cjs.map +1 -0
- package/dist/deployment.d.mts +34 -0
- package/dist/deployment.d.ts +34 -0
- package/dist/deployment.mjs +38 -0
- package/dist/deployment.mjs.map +1 -0
- package/dist/devtools-AE4RVXCM.mjs +370 -0
- package/dist/devtools-AE4RVXCM.mjs.map +1 -0
- package/dist/devtools-client-6WPY2AQU.mjs +225 -0
- package/dist/devtools-client-6WPY2AQU.mjs.map +1 -0
- package/dist/devtools-ui-NJKFORTG.mjs +1349 -0
- package/dist/devtools-ui-NJKFORTG.mjs.map +1 -0
- package/dist/docs.cjs +5541 -0
- package/dist/docs.cjs.map +1 -0
- package/dist/docs.d.mts +69 -0
- package/dist/docs.d.ts +69 -0
- package/dist/docs.mjs +46 -0
- package/dist/docs.mjs.map +1 -0
- package/dist/env-types.cjs +223 -0
- package/dist/env-types.cjs.map +1 -0
- package/dist/env-types.d.mts +11 -0
- package/dist/env-types.d.ts +11 -0
- package/dist/env-types.mjs +9 -0
- package/dist/env-types.mjs.map +1 -0
- package/dist/env.cjs +215 -0
- package/dist/env.cjs.map +1 -0
- package/dist/env.d.mts +45 -0
- package/dist/env.d.ts +45 -0
- package/dist/env.mjs +22 -0
- package/dist/env.mjs.map +1 -0
- package/dist/environment/vite.cjs +374 -0
- package/dist/environment/vite.cjs.map +1 -0
- package/dist/environment/vite.d.mts +22 -0
- package/dist/environment/vite.d.ts +22 -0
- package/dist/environment/vite.mjs +10 -0
- package/dist/environment/vite.mjs.map +1 -0
- package/dist/environment.cjs +96 -0
- package/dist/environment.cjs.map +1 -0
- package/dist/environment.d.mts +18 -0
- package/dist/environment.d.ts +18 -0
- package/dist/environment.mjs +14 -0
- package/dist/environment.mjs.map +1 -0
- package/dist/headers.cjs +126 -0
- package/dist/headers.cjs.map +1 -0
- package/dist/headers.d.mts +22 -0
- package/dist/headers.d.ts +22 -0
- package/dist/headers.mjs +12 -0
- package/dist/headers.mjs.map +1 -0
- package/dist/i18n/client.cjs +283 -0
- package/dist/i18n/client.cjs.map +1 -0
- package/dist/i18n/client.d.mts +32 -0
- package/dist/i18n/client.d.ts +32 -0
- package/dist/i18n/client.mjs +121 -0
- package/dist/i18n/client.mjs.map +1 -0
- package/dist/i18n/index.cjs +130 -0
- package/dist/i18n/index.cjs.map +1 -0
- package/dist/i18n/index.d.mts +20 -0
- package/dist/i18n/index.d.ts +20 -0
- package/dist/i18n/index.mjs +22 -0
- package/dist/i18n/index.mjs.map +1 -0
- package/dist/i18n/server.cjs +637 -0
- package/dist/i18n/server.cjs.map +1 -0
- package/dist/i18n/server.d.mts +30 -0
- package/dist/i18n/server.d.ts +30 -0
- package/dist/i18n/server.mjs +32 -0
- package/dist/i18n/server.mjs.map +1 -0
- package/dist/image/server.cjs +477 -0
- package/dist/image/server.cjs.map +1 -0
- package/dist/image/server.d.mts +37 -0
- package/dist/image/server.d.ts +37 -0
- package/dist/image/server.mjs +16 -0
- package/dist/image/server.mjs.map +1 -0
- package/dist/image/sharp.cjs +135 -0
- package/dist/image/sharp.cjs.map +1 -0
- package/dist/image/sharp.d.mts +7 -0
- package/dist/image/sharp.d.ts +7 -0
- package/dist/image/sharp.mjs +75 -0
- package/dist/image/sharp.mjs.map +1 -0
- package/dist/image-config-Duob7wER.d.mts +50 -0
- package/dist/image-config-Duob7wER.d.ts +50 -0
- package/dist/image.cjs +209 -0
- package/dist/image.cjs.map +1 -0
- package/dist/image.d.mts +39 -0
- package/dist/image.d.ts +39 -0
- package/dist/image.mjs +165 -0
- package/dist/image.mjs.map +1 -0
- package/dist/index.cjs +39433 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +451 -0
- package/dist/index.d.ts +451 -0
- package/dist/index.mjs +930 -0
- package/dist/index.mjs.map +1 -0
- package/dist/integration-api-CHT2OKAf.d.mts +93 -0
- package/dist/integration-api-CHT2OKAf.d.ts +93 -0
- package/dist/integration-orm-GQLGU66X.mjs +13 -0
- package/dist/integration-orm-GQLGU66X.mjs.map +1 -0
- package/dist/integrations.cjs +2820 -0
- package/dist/integrations.cjs.map +1 -0
- package/dist/integrations.d.mts +21 -0
- package/dist/integrations.d.ts +21 -0
- package/dist/integrations.mjs +51 -0
- package/dist/integrations.mjs.map +1 -0
- package/dist/internal/build-runtime.cjs +31340 -0
- package/dist/internal/build-runtime.cjs.map +1 -0
- package/dist/internal/build-runtime.d.mts +38 -0
- package/dist/internal/build-runtime.d.ts +38 -0
- package/dist/internal/build-runtime.mjs +73 -0
- package/dist/internal/build-runtime.mjs.map +1 -0
- package/dist/internal/client-runtime.cjs +579 -0
- package/dist/internal/client-runtime.cjs.map +1 -0
- package/dist/internal/client-runtime.d.mts +2 -0
- package/dist/internal/client-runtime.d.ts +2 -0
- package/dist/internal/client-runtime.mjs +12 -0
- package/dist/internal/client-runtime.mjs.map +1 -0
- package/dist/internal/config-runtime.cjs +4172 -0
- package/dist/internal/config-runtime.cjs.map +1 -0
- package/dist/internal/config-runtime.d.mts +38 -0
- package/dist/internal/config-runtime.d.ts +38 -0
- package/dist/internal/config-runtime.mjs +38 -0
- package/dist/internal/config-runtime.mjs.map +1 -0
- package/dist/internal/production-node-env.cjs +65 -0
- package/dist/internal/production-node-env.cjs.map +1 -0
- package/dist/internal/production-node-env.d.mts +12 -0
- package/dist/internal/production-node-env.d.ts +12 -0
- package/dist/internal/production-node-env.mjs +8 -0
- package/dist/internal/production-node-env.mjs.map +1 -0
- package/dist/internal/production-runtime.cjs +1896 -0
- package/dist/internal/production-runtime.cjs.map +1 -0
- package/dist/internal/production-runtime.d.mts +39 -0
- package/dist/internal/production-runtime.d.ts +39 -0
- package/dist/internal/production-runtime.mjs +79 -0
- package/dist/internal/production-runtime.mjs.map +1 -0
- package/dist/layers-VWVDTPUZ.mjs +16 -0
- package/dist/layers-VWVDTPUZ.mjs.map +1 -0
- package/dist/manager-THKFTOFE.mjs +10 -0
- package/dist/manager-THKFTOFE.mjs.map +1 -0
- package/dist/markdown.cjs +299 -0
- package/dist/markdown.cjs.map +1 -0
- package/dist/markdown.d.mts +43 -0
- package/dist/markdown.d.ts +43 -0
- package/dist/markdown.mjs +14 -0
- package/dist/markdown.mjs.map +1 -0
- package/dist/metadata-C9NZxMDW.d.mts +22 -0
- package/dist/metadata-DAXRaOHx.d.ts +22 -0
- package/dist/middleware.cjs +2148 -0
- package/dist/middleware.cjs.map +1 -0
- package/dist/middleware.d.mts +163 -0
- package/dist/middleware.d.ts +163 -0
- package/dist/middleware.mjs +49 -0
- package/dist/middleware.mjs.map +1 -0
- package/dist/navigation-errors-Dvwpzaer.d.mts +13 -0
- package/dist/navigation-errors-Dvwpzaer.d.ts +13 -0
- package/dist/navigation.cjs +1304 -0
- package/dist/navigation.cjs.map +1 -0
- package/dist/navigation.d.mts +14 -0
- package/dist/navigation.d.ts +14 -0
- package/dist/navigation.mjs +33 -0
- package/dist/navigation.mjs.map +1 -0
- package/dist/nitro-KME62MWG.mjs +691 -0
- package/dist/nitro-KME62MWG.mjs.map +1 -0
- package/dist/observability.cjs +186 -0
- package/dist/observability.cjs.map +1 -0
- package/dist/observability.d.mts +335 -0
- package/dist/observability.d.ts +335 -0
- package/dist/observability.mjs +16 -0
- package/dist/observability.mjs.map +1 -0
- package/dist/params-BALtrRim.d.ts +15 -0
- package/dist/params-ry-lxqmy.d.mts +15 -0
- package/dist/plugin-BJDf43dc.d.mts +165 -0
- package/dist/plugin-BJDf43dc.d.ts +165 -0
- package/dist/plugin.cjs +22285 -0
- package/dist/plugin.cjs.map +1 -0
- package/dist/plugin.d.mts +21 -0
- package/dist/plugin.d.ts +21 -0
- package/dist/plugin.mjs +60 -0
- package/dist/plugin.mjs.map +1 -0
- package/dist/production-runtime-C_B79w2P.d.mts +28 -0
- package/dist/production-runtime-DDEM1D2q.d.ts +28 -0
- package/dist/production-runtime-DRkCHUvJ.d.ts +79 -0
- package/dist/production-runtime-flrjp_nC.d.mts +79 -0
- package/dist/query/client.cjs +560 -0
- package/dist/query/client.cjs.map +1 -0
- package/dist/query/client.d.mts +61 -0
- package/dist/query/client.d.ts +61 -0
- package/dist/query/client.mjs +364 -0
- package/dist/query/client.mjs.map +1 -0
- package/dist/query/index.cjs +226 -0
- package/dist/query/index.cjs.map +1 -0
- package/dist/query/index.d.mts +90 -0
- package/dist/query/index.d.ts +90 -0
- package/dist/query/index.mjs +31 -0
- package/dist/query/index.mjs.map +1 -0
- package/dist/query/parsers.cjs +178 -0
- package/dist/query/parsers.cjs.map +1 -0
- package/dist/query/parsers.d.mts +25 -0
- package/dist/query/parsers.d.ts +25 -0
- package/dist/query/parsers.mjs +24 -0
- package/dist/query/parsers.mjs.map +1 -0
- package/dist/query/server.cjs +301 -0
- package/dist/query/server.cjs.map +1 -0
- package/dist/query/server.d.mts +55 -0
- package/dist/query/server.d.ts +55 -0
- package/dist/query/server.mjs +105 -0
- package/dist/query/server.mjs.map +1 -0
- package/dist/request-BrFBuc8G.d.mts +6 -0
- package/dist/request-BslSZIRz.d.ts +6 -0
- package/dist/request.cjs +71 -0
- package/dist/request.cjs.map +1 -0
- package/dist/request.d.mts +2 -0
- package/dist/request.d.ts +2 -0
- package/dist/request.mjs +9 -0
- package/dist/request.mjs.map +1 -0
- package/dist/resolver-C6iecsDV.d.ts +14 -0
- package/dist/resolver-DlOPpjkB.d.mts +14 -0
- package/dist/route-runtime-DoOHzCAD.d.mts +38 -0
- package/dist/route-runtime-DoOHzCAD.d.ts +38 -0
- package/dist/router.cjs +254 -0
- package/dist/router.cjs.map +1 -0
- package/dist/router.d.mts +36 -0
- package/dist/router.d.ts +36 -0
- package/dist/router.mjs +14 -0
- package/dist/router.mjs.map +1 -0
- package/dist/routes.cjs +1213 -0
- package/dist/routes.cjs.map +1 -0
- package/dist/routes.d.mts +224 -0
- package/dist/routes.d.ts +224 -0
- package/dist/routes.mjs +52 -0
- package/dist/routes.mjs.map +1 -0
- package/dist/runtime-B6GvwDS1.d.ts +27 -0
- package/dist/runtime-DeAAZ6gO.d.mts +27 -0
- package/dist/search-client-6OXIBNYQ.mjs +14 -0
- package/dist/search-client-6OXIBNYQ.mjs.map +1 -0
- package/dist/server-action-security.cjs +492 -0
- package/dist/server-action-security.cjs.map +1 -0
- package/dist/server-action-security.d.mts +42 -0
- package/dist/server-action-security.d.ts +42 -0
- package/dist/server-action-security.mjs +29 -0
- package/dist/server-action-security.mjs.map +1 -0
- package/dist/server-fn-client.cjs +180 -0
- package/dist/server-fn-client.cjs.map +1 -0
- package/dist/server-fn-client.d.mts +31 -0
- package/dist/server-fn-client.d.ts +31 -0
- package/dist/server-fn-client.mjs +9 -0
- package/dist/server-fn-client.mjs.map +1 -0
- package/dist/server-fn.cjs +284 -0
- package/dist/server-fn.cjs.map +1 -0
- package/dist/server-fn.d.mts +84 -0
- package/dist/server-fn.d.ts +84 -0
- package/dist/server-fn.mjs +17 -0
- package/dist/server-fn.mjs.map +1 -0
- package/dist/server-plugins.cjs +235 -0
- package/dist/server-plugins.cjs.map +1 -0
- package/dist/server-plugins.d.mts +54 -0
- package/dist/server-plugins.d.ts +54 -0
- package/dist/server-plugins.mjs +18 -0
- package/dist/server-plugins.mjs.map +1 -0
- package/dist/server-query-client.cjs +792 -0
- package/dist/server-query-client.cjs.map +1 -0
- package/dist/server-query-client.d.mts +50 -0
- package/dist/server-query-client.d.ts +50 -0
- package/dist/server-query-client.mjs +23 -0
- package/dist/server-query-client.mjs.map +1 -0
- package/dist/server-query.cjs +804 -0
- package/dist/server-query.cjs.map +1 -0
- package/dist/server-query.d.mts +36 -0
- package/dist/server-query.d.ts +36 -0
- package/dist/server-query.mjs +18 -0
- package/dist/server-query.mjs.map +1 -0
- package/dist/server.cjs +25739 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.mts +47 -0
- package/dist/server.d.ts +47 -0
- package/dist/server.mjs +511 -0
- package/dist/server.mjs.map +1 -0
- package/dist/storage.cjs +515 -0
- package/dist/storage.cjs.map +1 -0
- package/dist/storage.d.mts +52 -0
- package/dist/storage.d.ts +52 -0
- package/dist/storage.mjs +58 -0
- package/dist/storage.mjs.map +1 -0
- package/dist/testing.cjs +1882 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.mts +100 -0
- package/dist/testing.d.ts +100 -0
- package/dist/testing.mjs +324 -0
- package/dist/testing.mjs.map +1 -0
- package/dist/types-BH1lhg5G.d.mts +81 -0
- package/dist/types-BH1lhg5G.d.ts +81 -0
- package/dist/types-C9N-nk5R.d.mts +53 -0
- package/dist/types-C9N-nk5R.d.ts +53 -0
- package/dist/types-D1A6-XvH.d.mts +73 -0
- package/dist/types-D1A6-XvH.d.ts +73 -0
- package/dist/utils-DA1yo54_.d.ts +23 -0
- package/dist/utils-DOXXivjL.d.mts +23 -0
- package/dist/vite.cjs +22684 -0
- package/dist/vite.cjs.map +1 -0
- package/dist/vite.d.mts +21 -0
- package/dist/vite.d.ts +21 -0
- package/dist/vite.mjs +59 -0
- package/dist/vite.mjs.map +1 -0
- package/dist/workflows.cjs +586 -0
- package/dist/workflows.cjs.map +1 -0
- package/dist/workflows.d.mts +110 -0
- package/dist/workflows.d.ts +110 -0
- package/dist/workflows.mjs +32 -0
- package/dist/workflows.mjs.map +1 -0
- package/package.json +523 -0
- package/types/api.d.ts +88 -0
- package/types/client.d.ts +1171 -0
- package/types/index.d.ts +17 -0
- package/types/middleware.d.ts +266 -0
package/dist/testing.cjs
ADDED
|
@@ -0,0 +1,1882 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/testing.ts
|
|
32
|
+
var testing_exports = {};
|
|
33
|
+
__export(testing_exports, {
|
|
34
|
+
createFarmTestHarness: () => createFarmTestHarness,
|
|
35
|
+
createTestRequest: () => createTestRequest
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(testing_exports);
|
|
38
|
+
var import_react2 = require("react");
|
|
39
|
+
|
|
40
|
+
// src/routes.ts
|
|
41
|
+
var import_react = require("react");
|
|
42
|
+
|
|
43
|
+
// src/observability.ts
|
|
44
|
+
var runtimeHandlers = /* @__PURE__ */ new Set();
|
|
45
|
+
var observabilityState = {
|
|
46
|
+
logs: false,
|
|
47
|
+
handlers: []
|
|
48
|
+
};
|
|
49
|
+
function emitFarmEvent(input) {
|
|
50
|
+
const event = {
|
|
51
|
+
timestamp: Date.now(),
|
|
52
|
+
level: inferFarmEventLevel(input.type),
|
|
53
|
+
...input
|
|
54
|
+
};
|
|
55
|
+
if (!shouldEmitFarmEvent(event)) {
|
|
56
|
+
return event;
|
|
57
|
+
}
|
|
58
|
+
if (observabilityState.logs) {
|
|
59
|
+
logFarmEvent(event);
|
|
60
|
+
}
|
|
61
|
+
for (const handler of [...observabilityState.handlers, ...runtimeHandlers]) {
|
|
62
|
+
try {
|
|
63
|
+
Promise.resolve(handler(event)).catch((error) => {
|
|
64
|
+
console.warn(`[farm:observability] event handler failed: ${formatError(error)}`);
|
|
65
|
+
});
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.warn(`[farm:observability] event handler failed: ${formatError(error)}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return event;
|
|
71
|
+
}
|
|
72
|
+
__name(emitFarmEvent, "emitFarmEvent");
|
|
73
|
+
function shouldEmitFarmEvent(event) {
|
|
74
|
+
if (!observabilityState.logs && observabilityState.handlers.length === 0 && runtimeHandlers.size === 0) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
if (observabilityState.events && !observabilityState.events.has(event.type)) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
__name(shouldEmitFarmEvent, "shouldEmitFarmEvent");
|
|
83
|
+
function inferFarmEventLevel(type) {
|
|
84
|
+
if (type === "error" || type.endsWith(".error") || type.endsWith(".failed")) {
|
|
85
|
+
return "error";
|
|
86
|
+
}
|
|
87
|
+
if (type.endsWith(".bypass") || type.endsWith(".invalidated") || type.endsWith(".stale") || type.endsWith(".notFound")) {
|
|
88
|
+
return "warn";
|
|
89
|
+
}
|
|
90
|
+
if (type.endsWith(".hit") || type.endsWith(".miss") || type.endsWith(".start") || type.endsWith(".shellReady")) {
|
|
91
|
+
return "debug";
|
|
92
|
+
}
|
|
93
|
+
return "info";
|
|
94
|
+
}
|
|
95
|
+
__name(inferFarmEventLevel, "inferFarmEventLevel");
|
|
96
|
+
function logFarmEvent(event) {
|
|
97
|
+
const message = `[farm:${event.level}] ${event.type}${formatFarmEventDetails(event)}`;
|
|
98
|
+
switch (event.level) {
|
|
99
|
+
case "error":
|
|
100
|
+
console.error(message);
|
|
101
|
+
break;
|
|
102
|
+
case "warn":
|
|
103
|
+
console.warn(message);
|
|
104
|
+
break;
|
|
105
|
+
default:
|
|
106
|
+
console.log(message);
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
__name(logFarmEvent, "logFarmEvent");
|
|
111
|
+
function formatFarmEventDetails(event) {
|
|
112
|
+
const details = [];
|
|
113
|
+
const record = event;
|
|
114
|
+
for (const key of [
|
|
115
|
+
"route",
|
|
116
|
+
"pathname",
|
|
117
|
+
"method",
|
|
118
|
+
"status",
|
|
119
|
+
"key",
|
|
120
|
+
"tag",
|
|
121
|
+
"path",
|
|
122
|
+
"reason",
|
|
123
|
+
"durationMs",
|
|
124
|
+
"integration",
|
|
125
|
+
"operation",
|
|
126
|
+
"plugin",
|
|
127
|
+
"hook",
|
|
128
|
+
"target",
|
|
129
|
+
"count"
|
|
130
|
+
]) {
|
|
131
|
+
const value = record[key];
|
|
132
|
+
if (value !== void 0) {
|
|
133
|
+
details.push(`${key}=${formatDetailValue(value)}`);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return details.length > 0 ? ` ${details.join(" ")}` : "";
|
|
137
|
+
}
|
|
138
|
+
__name(formatFarmEventDetails, "formatFarmEventDetails");
|
|
139
|
+
function formatDetailValue(value) {
|
|
140
|
+
if (typeof value === "string") {
|
|
141
|
+
return value;
|
|
142
|
+
}
|
|
143
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
144
|
+
return String(value);
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
return JSON.stringify(value);
|
|
148
|
+
} catch {
|
|
149
|
+
return String(value);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
__name(formatDetailValue, "formatDetailValue");
|
|
153
|
+
function formatError(error) {
|
|
154
|
+
return error instanceof Error ? error.message : String(error);
|
|
155
|
+
}
|
|
156
|
+
__name(formatError, "formatError");
|
|
157
|
+
|
|
158
|
+
// src/cache-invalidation.ts
|
|
159
|
+
var FARM_CACHE_INVALIDATION_STATE = /* @__PURE__ */ Symbol.for("farm.cacheInvalidationState");
|
|
160
|
+
var globalState = globalThis;
|
|
161
|
+
function getFarmCacheInvalidationState() {
|
|
162
|
+
return globalState[FARM_CACHE_INVALIDATION_STATE] ?? (globalState[FARM_CACHE_INVALIDATION_STATE] = {
|
|
163
|
+
listeners: /* @__PURE__ */ new Set()
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
__name(getFarmCacheInvalidationState, "getFarmCacheInvalidationState");
|
|
167
|
+
function subscribeFarmCacheInvalidation(listener) {
|
|
168
|
+
const state = getFarmCacheInvalidationState();
|
|
169
|
+
state.listeners.add(listener);
|
|
170
|
+
return () => state.listeners.delete(listener);
|
|
171
|
+
}
|
|
172
|
+
__name(subscribeFarmCacheInvalidation, "subscribeFarmCacheInvalidation");
|
|
173
|
+
|
|
174
|
+
// src/i18n/bridge.ts
|
|
175
|
+
var FARM_I18N_SNAPSHOT_RESOLVER = /* @__PURE__ */ Symbol.for("farm.i18n.snapshotResolver");
|
|
176
|
+
function _setFarmI18nSnapshotResolver(resolver) {
|
|
177
|
+
globalThis[FARM_I18N_SNAPSHOT_RESOLVER] = resolver;
|
|
178
|
+
}
|
|
179
|
+
__name(_setFarmI18nSnapshotResolver, "_setFarmI18nSnapshotResolver");
|
|
180
|
+
|
|
181
|
+
// src/cache.ts
|
|
182
|
+
var _FarmDataCache = class _FarmDataCache {
|
|
183
|
+
constructor() {
|
|
184
|
+
this.entries = /* @__PURE__ */ new Map();
|
|
185
|
+
this.inflight = /* @__PURE__ */ new Map();
|
|
186
|
+
this.invalidatedTagVersions = /* @__PURE__ */ new Map();
|
|
187
|
+
this.version = 0;
|
|
188
|
+
}
|
|
189
|
+
get size() {
|
|
190
|
+
return this.entries.size;
|
|
191
|
+
}
|
|
192
|
+
get(key, options = {}) {
|
|
193
|
+
return this.getEntry(key, options)?.value;
|
|
194
|
+
}
|
|
195
|
+
getEntry(key, options = {}) {
|
|
196
|
+
const entry = this.entries.get(key);
|
|
197
|
+
if (!entry) {
|
|
198
|
+
emitFarmEvent({ type: "cache.miss", key });
|
|
199
|
+
return void 0;
|
|
200
|
+
}
|
|
201
|
+
const stale = this.isStale(entry, options.now);
|
|
202
|
+
if (stale) {
|
|
203
|
+
emitFarmEvent({
|
|
204
|
+
type: "cache.stale",
|
|
205
|
+
key,
|
|
206
|
+
tags: Array.from(entry.tags),
|
|
207
|
+
revalidate: entry.revalidate
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
if (!options.allowStale && stale) {
|
|
211
|
+
emitFarmEvent({ type: "cache.miss", key, reason: "stale" });
|
|
212
|
+
return void 0;
|
|
213
|
+
}
|
|
214
|
+
emitFarmEvent({
|
|
215
|
+
type: "cache.hit",
|
|
216
|
+
key,
|
|
217
|
+
tags: Array.from(entry.tags),
|
|
218
|
+
revalidate: entry.revalidate,
|
|
219
|
+
stale
|
|
220
|
+
});
|
|
221
|
+
return this.toPublicEntry(entry);
|
|
222
|
+
}
|
|
223
|
+
set(key, value, options = {}) {
|
|
224
|
+
const tags = /* @__PURE__ */ new Set();
|
|
225
|
+
for (const tag of options.tags ?? []) {
|
|
226
|
+
tags.add(normalizeCacheTag(tag));
|
|
227
|
+
}
|
|
228
|
+
for (const routePath of options.paths ?? []) {
|
|
229
|
+
tags.add(createPathCacheTag(routePath));
|
|
230
|
+
}
|
|
231
|
+
const entry = {
|
|
232
|
+
key,
|
|
233
|
+
value,
|
|
234
|
+
tags,
|
|
235
|
+
createdAt: options.createdAt ?? Date.now(),
|
|
236
|
+
createdVersion: ++this.version,
|
|
237
|
+
revalidate: normalizeRevalidate(options.revalidate)
|
|
238
|
+
};
|
|
239
|
+
this.entries.set(key, entry);
|
|
240
|
+
emitFarmEvent({
|
|
241
|
+
type: "cache.set",
|
|
242
|
+
key,
|
|
243
|
+
tags: Array.from(tags),
|
|
244
|
+
revalidate: entry.revalidate
|
|
245
|
+
});
|
|
246
|
+
return this.toPublicEntry(entry);
|
|
247
|
+
}
|
|
248
|
+
delete(key) {
|
|
249
|
+
const deleted = this.entries.delete(key);
|
|
250
|
+
emitFarmEvent({ type: "cache.delete", key, deleted });
|
|
251
|
+
return deleted;
|
|
252
|
+
}
|
|
253
|
+
clear() {
|
|
254
|
+
const count = this.entries.size;
|
|
255
|
+
this.entries.clear();
|
|
256
|
+
this.inflight.clear();
|
|
257
|
+
this.invalidatedTagVersions.clear();
|
|
258
|
+
this.version = 0;
|
|
259
|
+
emitFarmEvent({ type: "cache.clear", count });
|
|
260
|
+
}
|
|
261
|
+
isStale(entry, now = Date.now()) {
|
|
262
|
+
if (typeof entry.revalidate === "number" && entry.revalidate > 0 && now - entry.createdAt >= entry.revalidate * 1e3) {
|
|
263
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
for (const tag of entry.tags) {
|
|
266
|
+
const invalidatedVersion = this.invalidatedTagVersions.get(normalizeCacheTag(tag));
|
|
267
|
+
if (typeof invalidatedVersion === "number" && typeof entry.createdVersion === "number" && invalidatedVersion > entry.createdVersion) {
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
revalidateTag(tag, options = {}) {
|
|
274
|
+
const normalized = normalizeCacheTag(tag);
|
|
275
|
+
const count = this.invalidateTag(normalized);
|
|
276
|
+
emitFarmEvent(
|
|
277
|
+
options.source === "updateTag" ? { type: "cache.updateTag", tag: normalized, count } : { type: "cache.revalidateTag", tag: normalized, profile: options.profile, count }
|
|
278
|
+
);
|
|
279
|
+
return count;
|
|
280
|
+
}
|
|
281
|
+
revalidatePath(routePath) {
|
|
282
|
+
const normalizedPath = normalizeRevalidatePath(routePath);
|
|
283
|
+
const pathTag = createPathCacheTag(normalizedPath);
|
|
284
|
+
const pprCount = this.countEntriesForTags([pathTag, "ppr"]);
|
|
285
|
+
const count = this.invalidateTag(pathTag);
|
|
286
|
+
emitFarmEvent({ type: "cache.revalidatePath", path: normalizedPath, count });
|
|
287
|
+
if (pprCount > 0) {
|
|
288
|
+
emitFarmEvent({
|
|
289
|
+
type: "ppr.shell.invalidated",
|
|
290
|
+
route: normalizedPath,
|
|
291
|
+
reason: "revalidatePath",
|
|
292
|
+
count: pprCount
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
return count;
|
|
296
|
+
}
|
|
297
|
+
async getOrSet(key, producer, options = {}) {
|
|
298
|
+
const cached = this.getEntry(key);
|
|
299
|
+
if (cached) {
|
|
300
|
+
return cached.value;
|
|
301
|
+
}
|
|
302
|
+
const inflight = this.inflight.get(key);
|
|
303
|
+
if (inflight) {
|
|
304
|
+
emitFarmEvent({ type: "cache.dedupe", key });
|
|
305
|
+
return inflight;
|
|
306
|
+
}
|
|
307
|
+
const promise = Promise.resolve().then(producer).then((value) => {
|
|
308
|
+
this.set(key, value, options);
|
|
309
|
+
return value;
|
|
310
|
+
}).catch((error) => {
|
|
311
|
+
emitFarmEvent({ type: "cache.error", key, operation: "set", error });
|
|
312
|
+
throw error;
|
|
313
|
+
}).finally(() => {
|
|
314
|
+
this.inflight.delete(key);
|
|
315
|
+
});
|
|
316
|
+
this.inflight.set(key, promise);
|
|
317
|
+
return promise;
|
|
318
|
+
}
|
|
319
|
+
countEntriesForTag(tag) {
|
|
320
|
+
let count = 0;
|
|
321
|
+
for (const entry of this.entries.values()) {
|
|
322
|
+
if (entry.tags.has(tag)) {
|
|
323
|
+
count++;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
return count;
|
|
327
|
+
}
|
|
328
|
+
countEntriesForTags(tags) {
|
|
329
|
+
let count = 0;
|
|
330
|
+
for (const entry of this.entries.values()) {
|
|
331
|
+
if (tags.every((tag) => entry.tags.has(tag))) {
|
|
332
|
+
count++;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return count;
|
|
336
|
+
}
|
|
337
|
+
invalidateTag(normalizedTag) {
|
|
338
|
+
this.invalidatedTagVersions.set(normalizedTag, ++this.version);
|
|
339
|
+
return this.countEntriesForTag(normalizedTag);
|
|
340
|
+
}
|
|
341
|
+
toPublicEntry(entry) {
|
|
342
|
+
return {
|
|
343
|
+
key: entry.key,
|
|
344
|
+
value: entry.value,
|
|
345
|
+
tags: Array.from(entry.tags),
|
|
346
|
+
createdAt: entry.createdAt,
|
|
347
|
+
createdVersion: entry.createdVersion,
|
|
348
|
+
revalidate: entry.revalidate
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
__name(_FarmDataCache, "FarmDataCache");
|
|
353
|
+
var FarmDataCache = _FarmDataCache;
|
|
354
|
+
var FARM_DATA_CACHE_SYMBOL = /* @__PURE__ */ Symbol.for("farm.dataCache");
|
|
355
|
+
var farmDataCacheGlobal = globalThis;
|
|
356
|
+
var sharedFarmDataCache = farmDataCacheGlobal[FARM_DATA_CACHE_SYMBOL] ?? (farmDataCacheGlobal[FARM_DATA_CACHE_SYMBOL] = new FarmDataCache());
|
|
357
|
+
var functionIds = /* @__PURE__ */ new WeakMap();
|
|
358
|
+
var nextFunctionId = 0;
|
|
359
|
+
function getFarmDataCache() {
|
|
360
|
+
return sharedFarmDataCache;
|
|
361
|
+
}
|
|
362
|
+
__name(getFarmDataCache, "getFarmDataCache");
|
|
363
|
+
function createPathCacheTag(routePath) {
|
|
364
|
+
return `path:${normalizeRevalidatePath(routePath)}`;
|
|
365
|
+
}
|
|
366
|
+
__name(createPathCacheTag, "createPathCacheTag");
|
|
367
|
+
function createRouteDataCacheTag(key) {
|
|
368
|
+
return `route-data:${createRouteDataCacheKey(key)}`;
|
|
369
|
+
}
|
|
370
|
+
__name(createRouteDataCacheTag, "createRouteDataCacheTag");
|
|
371
|
+
function createRouteDataCacheKey(key) {
|
|
372
|
+
return createFarmCacheKey(Array.isArray(key) ? key : [key]);
|
|
373
|
+
}
|
|
374
|
+
__name(createRouteDataCacheKey, "createRouteDataCacheKey");
|
|
375
|
+
function normalizeRevalidatePath(routePath) {
|
|
376
|
+
if (typeof routePath !== "string") {
|
|
377
|
+
throw new TypeError("revalidatePath expects a path string.");
|
|
378
|
+
}
|
|
379
|
+
let normalized = routePath.trim();
|
|
380
|
+
if (!normalized) {
|
|
381
|
+
throw new Error("revalidatePath expects a non-empty path.");
|
|
382
|
+
}
|
|
383
|
+
try {
|
|
384
|
+
if (/^https?:\/\//.test(normalized)) {
|
|
385
|
+
normalized = new URL(normalized).pathname;
|
|
386
|
+
}
|
|
387
|
+
} catch {
|
|
388
|
+
}
|
|
389
|
+
normalized = normalized.split("?")[0] ?? normalized;
|
|
390
|
+
normalized = normalized.startsWith("/") ? normalized : `/${normalized}`;
|
|
391
|
+
normalized = normalized.replace(/\/{2,}/g, "/");
|
|
392
|
+
if (normalized.length > 1) {
|
|
393
|
+
normalized = normalized.replace(/\/+$/, "");
|
|
394
|
+
}
|
|
395
|
+
return normalized || "/";
|
|
396
|
+
}
|
|
397
|
+
__name(normalizeRevalidatePath, "normalizeRevalidatePath");
|
|
398
|
+
function createFarmCacheKey(parts) {
|
|
399
|
+
return stableSerialize(parts);
|
|
400
|
+
}
|
|
401
|
+
__name(createFarmCacheKey, "createFarmCacheKey");
|
|
402
|
+
function normalizeRevalidate(revalidate) {
|
|
403
|
+
if (revalidate === false || revalidate === void 0) {
|
|
404
|
+
return revalidate;
|
|
405
|
+
}
|
|
406
|
+
if (!Number.isFinite(revalidate) || revalidate <= 0) {
|
|
407
|
+
return void 0;
|
|
408
|
+
}
|
|
409
|
+
return revalidate;
|
|
410
|
+
}
|
|
411
|
+
__name(normalizeRevalidate, "normalizeRevalidate");
|
|
412
|
+
function normalizeCacheTag(tag) {
|
|
413
|
+
if (typeof tag !== "string") {
|
|
414
|
+
throw new TypeError("Cache tags must be strings.");
|
|
415
|
+
}
|
|
416
|
+
const normalized = tag.trim();
|
|
417
|
+
if (!normalized) {
|
|
418
|
+
throw new Error("Cache tags cannot be empty.");
|
|
419
|
+
}
|
|
420
|
+
return normalized;
|
|
421
|
+
}
|
|
422
|
+
__name(normalizeCacheTag, "normalizeCacheTag");
|
|
423
|
+
function getFunctionCacheIdentity(fn) {
|
|
424
|
+
if (fn.name) {
|
|
425
|
+
return `name:${fn.name}`;
|
|
426
|
+
}
|
|
427
|
+
let id = functionIds.get(fn);
|
|
428
|
+
if (!id) {
|
|
429
|
+
id = ++nextFunctionId;
|
|
430
|
+
functionIds.set(fn, id);
|
|
431
|
+
}
|
|
432
|
+
return `anonymous:${id}`;
|
|
433
|
+
}
|
|
434
|
+
__name(getFunctionCacheIdentity, "getFunctionCacheIdentity");
|
|
435
|
+
function stableSerialize(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
436
|
+
if (value === null) return "null";
|
|
437
|
+
if (value === void 0) return "undefined";
|
|
438
|
+
const valueType = typeof value;
|
|
439
|
+
if (valueType === "string") return JSON.stringify(value);
|
|
440
|
+
if (valueType === "number" || valueType === "boolean" || valueType === "bigint") {
|
|
441
|
+
return `${valueType}:${String(value)}`;
|
|
442
|
+
}
|
|
443
|
+
if (valueType === "symbol") {
|
|
444
|
+
return `symbol:${String(value)}`;
|
|
445
|
+
}
|
|
446
|
+
if (valueType === "function") {
|
|
447
|
+
return `function:${getFunctionCacheIdentity(value)}`;
|
|
448
|
+
}
|
|
449
|
+
if (value instanceof Date) {
|
|
450
|
+
return `date:${value.toISOString()}`;
|
|
451
|
+
}
|
|
452
|
+
if (value instanceof URL) {
|
|
453
|
+
return `url:${value.toString()}`;
|
|
454
|
+
}
|
|
455
|
+
if (value instanceof RegExp) {
|
|
456
|
+
return `regexp:${value.toString()}`;
|
|
457
|
+
}
|
|
458
|
+
if (Array.isArray(value)) {
|
|
459
|
+
return `[${value.map((item) => stableSerialize(item, seen)).join(",")}]`;
|
|
460
|
+
}
|
|
461
|
+
if (value && typeof value === "object") {
|
|
462
|
+
if (seen.has(value)) {
|
|
463
|
+
return "[Circular]";
|
|
464
|
+
}
|
|
465
|
+
seen.add(value);
|
|
466
|
+
const entries = Object.entries(value).sort(
|
|
467
|
+
([a], [b]) => a.localeCompare(b)
|
|
468
|
+
);
|
|
469
|
+
const serialized = entries.map(([key, item]) => `${JSON.stringify(key)}:${stableSerialize(item, seen)}`).join(",");
|
|
470
|
+
seen.delete(value);
|
|
471
|
+
return `{${serialized}}`;
|
|
472
|
+
}
|
|
473
|
+
return String(value);
|
|
474
|
+
}
|
|
475
|
+
__name(stableSerialize, "stableSerialize");
|
|
476
|
+
|
|
477
|
+
// src/route-context.ts
|
|
478
|
+
var FARM_ROUTE_CONTEXT_SYMBOL = /* @__PURE__ */ Symbol.for("farm.routeContext");
|
|
479
|
+
async function resolveFarmRouteContext(config, input) {
|
|
480
|
+
if (typeof config.context !== "function") {
|
|
481
|
+
return void 0;
|
|
482
|
+
}
|
|
483
|
+
return config.context(input);
|
|
484
|
+
}
|
|
485
|
+
__name(resolveFarmRouteContext, "resolveFarmRouteContext");
|
|
486
|
+
function withFarmRouteContext(props, context) {
|
|
487
|
+
if (context === void 0) {
|
|
488
|
+
return props;
|
|
489
|
+
}
|
|
490
|
+
Object.defineProperty(props, FARM_ROUTE_CONTEXT_SYMBOL, {
|
|
491
|
+
value: context,
|
|
492
|
+
enumerable: false,
|
|
493
|
+
configurable: true
|
|
494
|
+
});
|
|
495
|
+
return props;
|
|
496
|
+
}
|
|
497
|
+
__name(withFarmRouteContext, "withFarmRouteContext");
|
|
498
|
+
function getFarmRouteContext(props) {
|
|
499
|
+
if (!props || typeof props !== "object") {
|
|
500
|
+
return void 0;
|
|
501
|
+
}
|
|
502
|
+
return props[FARM_ROUTE_CONTEXT_SYMBOL];
|
|
503
|
+
}
|
|
504
|
+
__name(getFarmRouteContext, "getFarmRouteContext");
|
|
505
|
+
|
|
506
|
+
// src/route-runtime.ts
|
|
507
|
+
function normalizeFarmRouteRuntimeConfig(value, source = "Route configuration") {
|
|
508
|
+
if (!value) return {};
|
|
509
|
+
const normalized = {};
|
|
510
|
+
if (value.runtime !== void 0) {
|
|
511
|
+
if (value.runtime !== "auto" && value.runtime !== "node" && value.runtime !== "edge") {
|
|
512
|
+
throw new TypeError(`${source} runtime must be "auto", "node", or "edge"`);
|
|
513
|
+
}
|
|
514
|
+
normalized.runtime = value.runtime;
|
|
515
|
+
}
|
|
516
|
+
if (value.regions !== void 0) {
|
|
517
|
+
if (value.regions === "auto") {
|
|
518
|
+
normalized.regions = "auto";
|
|
519
|
+
} else {
|
|
520
|
+
if (!Array.isArray(value.regions) || value.regions.length === 0) {
|
|
521
|
+
throw new TypeError(`${source} regions must be "auto" or a non-empty string array`);
|
|
522
|
+
}
|
|
523
|
+
const regions = Array.from(
|
|
524
|
+
new Set(
|
|
525
|
+
value.regions.map((region) => {
|
|
526
|
+
if (typeof region !== "string" || !region.trim() || /[\u0000-\u001f\u007f]/.test(region)) {
|
|
527
|
+
throw new TypeError(`${source} regions must contain non-empty region identifiers`);
|
|
528
|
+
}
|
|
529
|
+
return region.trim();
|
|
530
|
+
})
|
|
531
|
+
)
|
|
532
|
+
);
|
|
533
|
+
normalized.regions = regions;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
if (value.maxDuration !== void 0) {
|
|
537
|
+
if (value.maxDuration === "auto") {
|
|
538
|
+
normalized.maxDuration = "auto";
|
|
539
|
+
} else if (typeof value.maxDuration !== "number" || !Number.isInteger(value.maxDuration) || value.maxDuration <= 0) {
|
|
540
|
+
throw new TypeError(`${source} maxDuration must be "auto" or a positive integer in seconds`);
|
|
541
|
+
} else {
|
|
542
|
+
normalized.maxDuration = value.maxDuration;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
return normalized;
|
|
546
|
+
}
|
|
547
|
+
__name(normalizeFarmRouteRuntimeConfig, "normalizeFarmRouteRuntimeConfig");
|
|
548
|
+
|
|
549
|
+
// src/routes.ts
|
|
550
|
+
var routesBuilder = {
|
|
551
|
+
page(path2, options) {
|
|
552
|
+
return normalizeProgrammaticRoute({
|
|
553
|
+
kind: "page",
|
|
554
|
+
path: path2,
|
|
555
|
+
...options
|
|
556
|
+
});
|
|
557
|
+
},
|
|
558
|
+
layout(path2, options) {
|
|
559
|
+
return normalizeProgrammaticRoute({
|
|
560
|
+
kind: "layout",
|
|
561
|
+
path: path2,
|
|
562
|
+
...options
|
|
563
|
+
});
|
|
564
|
+
},
|
|
565
|
+
api(path2, options) {
|
|
566
|
+
const { render, runtime, regions, maxDuration, ...methods } = options;
|
|
567
|
+
return normalizeProgrammaticRoute({
|
|
568
|
+
kind: "api",
|
|
569
|
+
path: path2,
|
|
570
|
+
render,
|
|
571
|
+
runtime,
|
|
572
|
+
regions,
|
|
573
|
+
maxDuration,
|
|
574
|
+
methods: normalizeApiMethods(methods)
|
|
575
|
+
});
|
|
576
|
+
},
|
|
577
|
+
redirect(source, destination, options = {}) {
|
|
578
|
+
return normalizeProgrammaticRoute({
|
|
579
|
+
kind: "redirect",
|
|
580
|
+
source,
|
|
581
|
+
destination,
|
|
582
|
+
...options
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
var page = routesBuilder.page;
|
|
587
|
+
var layout = routesBuilder.layout;
|
|
588
|
+
var api = routesBuilder.api;
|
|
589
|
+
var redirect = routesBuilder.redirect;
|
|
590
|
+
function getProgrammaticRouteSearchSchema(search) {
|
|
591
|
+
if (!search) return void 0;
|
|
592
|
+
if (isProgrammaticRouteSchema(search)) return search;
|
|
593
|
+
return search.schema;
|
|
594
|
+
}
|
|
595
|
+
__name(getProgrammaticRouteSearchSchema, "getProgrammaticRouteSearchSchema");
|
|
596
|
+
function getProgrammaticRouteSearchClientOptions(search) {
|
|
597
|
+
if (!search || isProgrammaticRouteSchema(search)) return void 0;
|
|
598
|
+
const options = {};
|
|
599
|
+
if (typeof search.stripDefaults !== "undefined") options.stripDefaults = search.stripDefaults;
|
|
600
|
+
if (search.preserve?.length) options.preserve = [...search.preserve];
|
|
601
|
+
if (search.temporary?.length) options.temporary = [...search.temporary];
|
|
602
|
+
return Object.keys(options).length > 0 ? options : void 0;
|
|
603
|
+
}
|
|
604
|
+
__name(getProgrammaticRouteSearchClientOptions, "getProgrammaticRouteSearchClientOptions");
|
|
605
|
+
function resolveProgrammaticRouteSearch(searchConfig, rawSearch, path2, routePath) {
|
|
606
|
+
const schema = getProgrammaticRouteSearchSchema(searchConfig);
|
|
607
|
+
const search = parseProgrammaticSchema(schema, rawSearch, "search", routePath);
|
|
608
|
+
const options = getProgrammaticRouteSearchOptions(searchConfig);
|
|
609
|
+
const canonicalPath = resolveProgrammaticRouteCanonicalPath({
|
|
610
|
+
options,
|
|
611
|
+
schema,
|
|
612
|
+
rawSearch,
|
|
613
|
+
parsedSearch: search,
|
|
614
|
+
path: path2
|
|
615
|
+
});
|
|
616
|
+
return { search, canonicalPath };
|
|
617
|
+
}
|
|
618
|
+
__name(resolveProgrammaticRouteSearch, "resolveProgrammaticRouteSearch");
|
|
619
|
+
function getProgrammaticRouteSearchOptions(search) {
|
|
620
|
+
if (!search || isProgrammaticRouteSchema(search)) return void 0;
|
|
621
|
+
return search;
|
|
622
|
+
}
|
|
623
|
+
__name(getProgrammaticRouteSearchOptions, "getProgrammaticRouteSearchOptions");
|
|
624
|
+
function isProgrammaticRouteSchema(value) {
|
|
625
|
+
return !!value && typeof value === "object" && typeof value.parse === "function";
|
|
626
|
+
}
|
|
627
|
+
__name(isProgrammaticRouteSchema, "isProgrammaticRouteSchema");
|
|
628
|
+
function resolveProgrammaticRouteCanonicalPath(input) {
|
|
629
|
+
const options = input.options;
|
|
630
|
+
if (!options?.temporary?.length && !options?.stripDefaults) {
|
|
631
|
+
return void 0;
|
|
632
|
+
}
|
|
633
|
+
const params = createSearchParams(input.rawSearch);
|
|
634
|
+
const original = params.toString();
|
|
635
|
+
for (const key of options.temporary || []) {
|
|
636
|
+
params.delete(key);
|
|
637
|
+
}
|
|
638
|
+
if (options.stripDefaults) {
|
|
639
|
+
const defaultSearch = parseDefaultSearch(input.schema);
|
|
640
|
+
if (defaultSearch !== void 0) {
|
|
641
|
+
const keys = options.stripDefaults === true ? Array.from(new Set(Array.from(params.keys()))) : [...options.stripDefaults];
|
|
642
|
+
for (const key of keys) {
|
|
643
|
+
if (params.has(key) && searchValuesEqual(
|
|
644
|
+
readSearchValue(input.parsedSearch, key),
|
|
645
|
+
readSearchValue(defaultSearch, key)
|
|
646
|
+
)) {
|
|
647
|
+
params.delete(key);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
const next = params.toString();
|
|
653
|
+
if (next === original) {
|
|
654
|
+
return void 0;
|
|
655
|
+
}
|
|
656
|
+
return next ? `${input.path}?${next}` : input.path;
|
|
657
|
+
}
|
|
658
|
+
__name(resolveProgrammaticRouteCanonicalPath, "resolveProgrammaticRouteCanonicalPath");
|
|
659
|
+
function createSearchParams(value) {
|
|
660
|
+
const params = new URLSearchParams();
|
|
661
|
+
for (const [key, item] of Object.entries(value)) {
|
|
662
|
+
if (item == null) continue;
|
|
663
|
+
const values = Array.isArray(item) ? item : [item];
|
|
664
|
+
for (const entry of values) {
|
|
665
|
+
if (entry != null) params.append(key, String(entry));
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
return params;
|
|
669
|
+
}
|
|
670
|
+
__name(createSearchParams, "createSearchParams");
|
|
671
|
+
function parseDefaultSearch(schema) {
|
|
672
|
+
if (!schema) return void 0;
|
|
673
|
+
try {
|
|
674
|
+
const value = schema.parse({});
|
|
675
|
+
return value && typeof value === "object" ? value : void 0;
|
|
676
|
+
} catch {
|
|
677
|
+
return void 0;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
__name(parseDefaultSearch, "parseDefaultSearch");
|
|
681
|
+
function readSearchValue(value, key) {
|
|
682
|
+
return value && typeof value === "object" ? value[key] : void 0;
|
|
683
|
+
}
|
|
684
|
+
__name(readSearchValue, "readSearchValue");
|
|
685
|
+
function searchValuesEqual(left, right) {
|
|
686
|
+
return JSON.stringify(normalizeComparableValue(left)) === JSON.stringify(normalizeComparableValue(right));
|
|
687
|
+
}
|
|
688
|
+
__name(searchValuesEqual, "searchValuesEqual");
|
|
689
|
+
function normalizeComparableValue(value) {
|
|
690
|
+
if (Array.isArray(value)) {
|
|
691
|
+
return value.map(normalizeComparableValue);
|
|
692
|
+
}
|
|
693
|
+
if (value && typeof value === "object") {
|
|
694
|
+
return Object.keys(value).sort().reduce((output, key) => {
|
|
695
|
+
output[key] = normalizeComparableValue(value[key]);
|
|
696
|
+
return output;
|
|
697
|
+
}, {});
|
|
698
|
+
}
|
|
699
|
+
return value;
|
|
700
|
+
}
|
|
701
|
+
__name(normalizeComparableValue, "normalizeComparableValue");
|
|
702
|
+
function parseProgrammaticRoutePath(routePath, type = "page") {
|
|
703
|
+
const fileName = type === "layout" ? "layout.tsx" : "page.tsx";
|
|
704
|
+
const normalized = normalizeRoutePath(routePath);
|
|
705
|
+
const filePath = normalized === "/" ? fileName : `${normalized.slice(1).replace(/\/+$/, "")}/${fileName}`;
|
|
706
|
+
return {
|
|
707
|
+
filePath,
|
|
708
|
+
type,
|
|
709
|
+
segments: normalized === "/" ? [] : normalized.slice(1).split("/").map(parseRouteSegment)
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
__name(parseProgrammaticRoutePath, "parseProgrammaticRoutePath");
|
|
713
|
+
function createRouteModuleFromProgrammaticPage(route) {
|
|
714
|
+
const mod = {
|
|
715
|
+
default: createProgrammaticPageComponent(route),
|
|
716
|
+
...normalizeFarmRouteRuntimeConfig(route, `Route "${route.path}"`)
|
|
717
|
+
};
|
|
718
|
+
if (route.params || route.search || route.guard || route.data) {
|
|
719
|
+
mod.__farmRouteSchemas = {
|
|
720
|
+
params: route.params,
|
|
721
|
+
search: getProgrammaticRouteSearchSchema(route.search)
|
|
722
|
+
};
|
|
723
|
+
mod.__farmRouteSearch = getProgrammaticRouteSearchClientOptions(route.search);
|
|
724
|
+
mod.__farmRouteGuard = route.guard;
|
|
725
|
+
mod.__farmRouteData = route.data;
|
|
726
|
+
mod.__farmRouteParsesProps = true;
|
|
727
|
+
mod.__farmResolveRouteProps = (props) => resolveProgrammaticRouteProps(route, props);
|
|
728
|
+
mod.__farmResolveRouteCanonicalPath = (rawSearch, path2) => resolveProgrammaticRouteSearch(route.search, rawSearch, path2, route.path).canonicalPath;
|
|
729
|
+
}
|
|
730
|
+
if (route.pending || route.error || route.notFound) {
|
|
731
|
+
mod.__farmRouteComponents = {
|
|
732
|
+
pending: route.pending,
|
|
733
|
+
error: route.error,
|
|
734
|
+
notFound: route.notFound
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
if (route.render === "static" || route.staticPaths) {
|
|
738
|
+
mod.ssg = true;
|
|
739
|
+
mod.dynamic = "force-static";
|
|
740
|
+
} else if (route.render === "dynamic") {
|
|
741
|
+
mod.ssg = false;
|
|
742
|
+
mod.dynamic = "force-dynamic";
|
|
743
|
+
}
|
|
744
|
+
if (typeof route.revalidate !== "undefined") {
|
|
745
|
+
mod.revalidate = route.revalidate;
|
|
746
|
+
}
|
|
747
|
+
if (route.ppr) {
|
|
748
|
+
mod.ppr = true;
|
|
749
|
+
}
|
|
750
|
+
if (route.metadata) {
|
|
751
|
+
mod.metadata = route.metadata;
|
|
752
|
+
}
|
|
753
|
+
if (route.generateMetadata) {
|
|
754
|
+
mod.generateMetadata = route.generateMetadata;
|
|
755
|
+
}
|
|
756
|
+
if (route.staticPaths) {
|
|
757
|
+
mod.getStaticPaths = async () => normalizeStaticPaths(route.path, await route.staticPaths());
|
|
758
|
+
}
|
|
759
|
+
return mod;
|
|
760
|
+
}
|
|
761
|
+
__name(createRouteModuleFromProgrammaticPage, "createRouteModuleFromProgrammaticPage");
|
|
762
|
+
function createProgrammaticPageComponent(route) {
|
|
763
|
+
if (!route.params && !route.search && !route.guard && !route.data && !route.pending && !route.error && !route.notFound) {
|
|
764
|
+
return route.component;
|
|
765
|
+
}
|
|
766
|
+
const Component = route.component;
|
|
767
|
+
if (route.pending) {
|
|
768
|
+
const PendingComponent = route.pending;
|
|
769
|
+
const routePropsResources = /* @__PURE__ */ new WeakMap();
|
|
770
|
+
const FarmProgrammaticPageContent2 = /* @__PURE__ */ __name(function FarmProgrammaticPageContent3(props) {
|
|
771
|
+
try {
|
|
772
|
+
const resolvedProps = readProgrammaticRouteProps(route, props, routePropsResources);
|
|
773
|
+
return (0, import_react.createElement)(Component, stripProgrammaticRoutePropsMarker(resolvedProps));
|
|
774
|
+
} catch (error) {
|
|
775
|
+
if (isPromiseLike(error) || isProgrammaticRedirectSignal(error)) {
|
|
776
|
+
throw error;
|
|
777
|
+
}
|
|
778
|
+
if (isProgrammaticNotFoundSignal(error) && route.notFound) {
|
|
779
|
+
return (0, import_react.createElement)(route.notFound, createProgrammaticRouteErrorProps(error, props));
|
|
780
|
+
}
|
|
781
|
+
if (route.error) {
|
|
782
|
+
return (0, import_react.createElement)(route.error, createProgrammaticRouteErrorProps(error, props));
|
|
783
|
+
}
|
|
784
|
+
throw error;
|
|
785
|
+
}
|
|
786
|
+
}, "FarmProgrammaticPageContent");
|
|
787
|
+
const PageContent = FarmProgrammaticPageContent2;
|
|
788
|
+
const FarmProgrammaticPage = /* @__PURE__ */ __name(function FarmProgrammaticPage2(props) {
|
|
789
|
+
return (0, import_react.createElement)(
|
|
790
|
+
import_react.Suspense,
|
|
791
|
+
{
|
|
792
|
+
fallback: (0, import_react.createElement)(PendingComponent, createProgrammaticRoutePendingProps(props))
|
|
793
|
+
},
|
|
794
|
+
(0, import_react.createElement)(PageContent, props)
|
|
795
|
+
);
|
|
796
|
+
}, "FarmProgrammaticPage");
|
|
797
|
+
return FarmProgrammaticPage;
|
|
798
|
+
}
|
|
799
|
+
const FarmProgrammaticPageContent = /* @__PURE__ */ __name(async function FarmProgrammaticPageContent2(props) {
|
|
800
|
+
try {
|
|
801
|
+
const resolvedProps = isProgrammaticRoutePropsResolved(props) ? props : await resolveProgrammaticRouteProps(route, props);
|
|
802
|
+
return (0, import_react.createElement)(Component, stripProgrammaticRoutePropsMarker(resolvedProps));
|
|
803
|
+
} catch (error) {
|
|
804
|
+
if (isProgrammaticRedirectSignal(error)) {
|
|
805
|
+
throw error;
|
|
806
|
+
}
|
|
807
|
+
if (isProgrammaticNotFoundSignal(error) && route.notFound) {
|
|
808
|
+
return (0, import_react.createElement)(route.notFound, createProgrammaticRouteErrorProps(error, props));
|
|
809
|
+
}
|
|
810
|
+
if (route.error) {
|
|
811
|
+
return (0, import_react.createElement)(route.error, createProgrammaticRouteErrorProps(error, props));
|
|
812
|
+
}
|
|
813
|
+
throw error;
|
|
814
|
+
}
|
|
815
|
+
}, "FarmProgrammaticPageContent");
|
|
816
|
+
return FarmProgrammaticPageContent;
|
|
817
|
+
}
|
|
818
|
+
__name(createProgrammaticPageComponent, "createProgrammaticPageComponent");
|
|
819
|
+
function readProgrammaticRouteProps(route, props, resources) {
|
|
820
|
+
if (isProgrammaticRoutePropsResolved(props)) {
|
|
821
|
+
return props;
|
|
822
|
+
}
|
|
823
|
+
let resource = resources.get(props);
|
|
824
|
+
if (!resource) {
|
|
825
|
+
const deferredRouteProps = props.__farmRoutePropsPromise;
|
|
826
|
+
const promise = Promise.resolve(
|
|
827
|
+
isPromiseLike(deferredRouteProps) ? deferredRouteProps : resolveProgrammaticRouteProps(route, props)
|
|
828
|
+
);
|
|
829
|
+
resource = { status: "pending", promise };
|
|
830
|
+
resources.set(props, resource);
|
|
831
|
+
promise.then(
|
|
832
|
+
(value) => resources.set(props, { status: "resolved", value }),
|
|
833
|
+
(error) => resources.set(props, { status: "rejected", error })
|
|
834
|
+
);
|
|
835
|
+
}
|
|
836
|
+
if (resource.status === "pending") throw resource.promise;
|
|
837
|
+
if (resource.status === "rejected") throw resource.error;
|
|
838
|
+
return resource.value;
|
|
839
|
+
}
|
|
840
|
+
__name(readProgrammaticRouteProps, "readProgrammaticRouteProps");
|
|
841
|
+
function isPromiseLike(value) {
|
|
842
|
+
return Boolean(
|
|
843
|
+
value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function"
|
|
844
|
+
);
|
|
845
|
+
}
|
|
846
|
+
__name(isPromiseLike, "isPromiseLike");
|
|
847
|
+
function createProgrammaticRoutePendingProps(props) {
|
|
848
|
+
return {
|
|
849
|
+
params: props.params,
|
|
850
|
+
searchParams: props.searchParams,
|
|
851
|
+
path: props.path
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
__name(createProgrammaticRoutePendingProps, "createProgrammaticRoutePendingProps");
|
|
855
|
+
function createProgrammaticRouteErrorProps(error, props) {
|
|
856
|
+
return {
|
|
857
|
+
error,
|
|
858
|
+
params: props.params,
|
|
859
|
+
searchParams: props.searchParams,
|
|
860
|
+
path: props.path
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
__name(createProgrammaticRouteErrorProps, "createProgrammaticRouteErrorProps");
|
|
864
|
+
function isProgrammaticRedirectSignal(error) {
|
|
865
|
+
if (!error || typeof error !== "object") return false;
|
|
866
|
+
const digest = error.digest;
|
|
867
|
+
return typeof digest === "string" && digest.startsWith("FARM_REDIRECT;");
|
|
868
|
+
}
|
|
869
|
+
__name(isProgrammaticRedirectSignal, "isProgrammaticRedirectSignal");
|
|
870
|
+
function isProgrammaticNotFoundSignal(error) {
|
|
871
|
+
if (!error || typeof error !== "object") return false;
|
|
872
|
+
const digest = error.digest;
|
|
873
|
+
return digest === "FARM_NOT_FOUND";
|
|
874
|
+
}
|
|
875
|
+
__name(isProgrammaticNotFoundSignal, "isProgrammaticNotFoundSignal");
|
|
876
|
+
async function resolveProgrammaticRouteProps(route, props) {
|
|
877
|
+
const rawSearch = await props.searchParams;
|
|
878
|
+
const params = parseProgrammaticSchema(route.params, props.params, "params", route.path);
|
|
879
|
+
const { search, canonicalPath } = resolveProgrammaticRouteSearch(
|
|
880
|
+
route.search,
|
|
881
|
+
rawSearch,
|
|
882
|
+
props.path,
|
|
883
|
+
route.path
|
|
884
|
+
);
|
|
885
|
+
const routeContextValue = getFarmRouteContext(props);
|
|
886
|
+
const pluginContext = props.context;
|
|
887
|
+
const baseProps = {
|
|
888
|
+
...props,
|
|
889
|
+
params,
|
|
890
|
+
search,
|
|
891
|
+
searchParams: Promise.resolve(search)
|
|
892
|
+
};
|
|
893
|
+
const routeContextProps = {
|
|
894
|
+
...baseProps,
|
|
895
|
+
context: routeContextValue,
|
|
896
|
+
pluginContext
|
|
897
|
+
};
|
|
898
|
+
if (route.guard) {
|
|
899
|
+
await route.guard(routeContextProps);
|
|
900
|
+
}
|
|
901
|
+
if (!route.data) {
|
|
902
|
+
return markProgrammaticRoutePropsResolved(addCanonicalPath(baseProps, canonicalPath));
|
|
903
|
+
}
|
|
904
|
+
const before = route.data.before ? await route.data.before(routeContextProps) : void 0;
|
|
905
|
+
const dataContext = {
|
|
906
|
+
...routeContextProps,
|
|
907
|
+
before
|
|
908
|
+
};
|
|
909
|
+
const data = await resolveProgrammaticRouteData(route, route.data, dataContext);
|
|
910
|
+
if (route.data.after) {
|
|
911
|
+
await route.data.after({
|
|
912
|
+
...routeContextProps,
|
|
913
|
+
before,
|
|
914
|
+
data
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
return markProgrammaticRoutePropsResolved({
|
|
918
|
+
...baseProps,
|
|
919
|
+
data,
|
|
920
|
+
...canonicalPath ? { __farmCanonicalPath: canonicalPath } : {}
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
__name(resolveProgrammaticRouteProps, "resolveProgrammaticRouteProps");
|
|
924
|
+
async function resolveProgrammaticRouteData(route, dataHooks, context) {
|
|
925
|
+
if (!dataHooks?.key) {
|
|
926
|
+
return dataHooks.main(context);
|
|
927
|
+
}
|
|
928
|
+
const routeDataKey = await dataHooks.key(context);
|
|
929
|
+
if (routeDataKey == null) {
|
|
930
|
+
return dataHooks.main(context);
|
|
931
|
+
}
|
|
932
|
+
const cacheKey = createFarmCacheKey(["route-data", routeDataKey]);
|
|
933
|
+
const cacheOptions = {
|
|
934
|
+
tags: [
|
|
935
|
+
createRouteDataCacheTag(routeDataKey),
|
|
936
|
+
...await resolveProgrammaticRouteDataKeys(dataHooks.tags, context)
|
|
937
|
+
],
|
|
938
|
+
paths: [
|
|
939
|
+
...typeof context.path === "string" ? [context.path] : [],
|
|
940
|
+
...await resolveProgrammaticRouteDataKeys(dataHooks.paths, context)
|
|
941
|
+
],
|
|
942
|
+
revalidate: normalizeProgrammaticRouteStaleTime(dataHooks.staleTime)
|
|
943
|
+
};
|
|
944
|
+
return getFarmDataCache().getOrSet(cacheKey, () => dataHooks.main(context), cacheOptions);
|
|
945
|
+
}
|
|
946
|
+
__name(resolveProgrammaticRouteData, "resolveProgrammaticRouteData");
|
|
947
|
+
async function resolveProgrammaticRouteDataKeys(input, context) {
|
|
948
|
+
if (!input) return [];
|
|
949
|
+
const value = typeof input === "function" ? await input(context) : input;
|
|
950
|
+
return value.filter((item) => typeof item === "string" && item.trim().length > 0);
|
|
951
|
+
}
|
|
952
|
+
__name(resolveProgrammaticRouteDataKeys, "resolveProgrammaticRouteDataKeys");
|
|
953
|
+
function normalizeProgrammaticRouteStaleTime(staleTime) {
|
|
954
|
+
if (staleTime === void 0) return void 0;
|
|
955
|
+
if (staleTime === false) return false;
|
|
956
|
+
if (typeof staleTime === "number") {
|
|
957
|
+
if (!Number.isFinite(staleTime) || staleTime <= 0) return void 0;
|
|
958
|
+
return Math.max(1, Math.ceil(staleTime / 1e3));
|
|
959
|
+
}
|
|
960
|
+
const match = staleTime.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)$/);
|
|
961
|
+
if (!match) return void 0;
|
|
962
|
+
const value = Number(match[1]);
|
|
963
|
+
if (!Number.isFinite(value) || value <= 0) return void 0;
|
|
964
|
+
const unit = match[2];
|
|
965
|
+
const milliseconds = unit === "ms" ? value : unit === "s" ? value * 1e3 : unit === "m" ? value * 6e4 : value * 36e5;
|
|
966
|
+
return Math.max(1, Math.ceil(milliseconds / 1e3));
|
|
967
|
+
}
|
|
968
|
+
__name(normalizeProgrammaticRouteStaleTime, "normalizeProgrammaticRouteStaleTime");
|
|
969
|
+
function isProgrammaticRoutePropsResolved(value) {
|
|
970
|
+
return !!value && typeof value === "object" && value.__farmRoutePropsResolved === true;
|
|
971
|
+
}
|
|
972
|
+
__name(isProgrammaticRoutePropsResolved, "isProgrammaticRoutePropsResolved");
|
|
973
|
+
function markProgrammaticRoutePropsResolved(props) {
|
|
974
|
+
return {
|
|
975
|
+
...props,
|
|
976
|
+
__farmRoutePropsResolved: true
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
__name(markProgrammaticRoutePropsResolved, "markProgrammaticRoutePropsResolved");
|
|
980
|
+
function addCanonicalPath(props, canonicalPath) {
|
|
981
|
+
return canonicalPath ? { ...props, __farmCanonicalPath: canonicalPath } : props;
|
|
982
|
+
}
|
|
983
|
+
__name(addCanonicalPath, "addCanonicalPath");
|
|
984
|
+
function stripProgrammaticRoutePropsMarker(props) {
|
|
985
|
+
if (!isProgrammaticRoutePropsResolved(props)) {
|
|
986
|
+
return props;
|
|
987
|
+
}
|
|
988
|
+
const {
|
|
989
|
+
__farmRoutePropsResolved,
|
|
990
|
+
__farmCanonicalPath,
|
|
991
|
+
__farmRoutePropsPromise,
|
|
992
|
+
...componentProps
|
|
993
|
+
} = props;
|
|
994
|
+
return componentProps;
|
|
995
|
+
}
|
|
996
|
+
__name(stripProgrammaticRoutePropsMarker, "stripProgrammaticRoutePropsMarker");
|
|
997
|
+
function parseProgrammaticSchema(schema, value, label, routePath) {
|
|
998
|
+
if (!schema) {
|
|
999
|
+
return value;
|
|
1000
|
+
}
|
|
1001
|
+
try {
|
|
1002
|
+
return schema.parse(value);
|
|
1003
|
+
} catch (error) {
|
|
1004
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1005
|
+
throw new Error(`Invalid ${label} for route "${routePath}": ${message}`);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
__name(parseProgrammaticSchema, "parseProgrammaticSchema");
|
|
1009
|
+
function normalizeProgrammaticRoute(route) {
|
|
1010
|
+
if (route.kind === "redirect") {
|
|
1011
|
+
return {
|
|
1012
|
+
...route,
|
|
1013
|
+
source: normalizeRoutePath(route.source)
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
if (route.kind === "api") {
|
|
1017
|
+
return {
|
|
1018
|
+
...route,
|
|
1019
|
+
...normalizeFarmRouteRuntimeConfig(route, `API route "${route.path}"`),
|
|
1020
|
+
path: normalizeRoutePath(route.path),
|
|
1021
|
+
methods: normalizeApiMethods(route.methods)
|
|
1022
|
+
};
|
|
1023
|
+
}
|
|
1024
|
+
return {
|
|
1025
|
+
...route,
|
|
1026
|
+
...normalizeFarmRouteRuntimeConfig(
|
|
1027
|
+
route,
|
|
1028
|
+
`${route.kind === "layout" ? "Layout" : "Route"} "${route.path}"`
|
|
1029
|
+
),
|
|
1030
|
+
path: normalizeRoutePath(route.path)
|
|
1031
|
+
};
|
|
1032
|
+
}
|
|
1033
|
+
__name(normalizeProgrammaticRoute, "normalizeProgrammaticRoute");
|
|
1034
|
+
function normalizeRoutePath(routePath) {
|
|
1035
|
+
const withSlash = routePath.startsWith("/") ? routePath : `/${routePath}`;
|
|
1036
|
+
const withoutTrailing = withSlash.length > 1 ? withSlash.replace(/\/+$/, "") : withSlash;
|
|
1037
|
+
return withoutTrailing || "/";
|
|
1038
|
+
}
|
|
1039
|
+
__name(normalizeRoutePath, "normalizeRoutePath");
|
|
1040
|
+
function parseRouteSegment(segment) {
|
|
1041
|
+
if (segment.startsWith("[") && segment.endsWith("]")) {
|
|
1042
|
+
let name = segment.slice(1, -1);
|
|
1043
|
+
let isOptional = false;
|
|
1044
|
+
let isCatchAll = false;
|
|
1045
|
+
if (name.startsWith("[") && name.endsWith("]")) {
|
|
1046
|
+
isOptional = true;
|
|
1047
|
+
name = name.slice(1, -1);
|
|
1048
|
+
}
|
|
1049
|
+
if (name.startsWith("...")) {
|
|
1050
|
+
isCatchAll = true;
|
|
1051
|
+
name = name.slice(3);
|
|
1052
|
+
}
|
|
1053
|
+
return {
|
|
1054
|
+
segment: name,
|
|
1055
|
+
isDynamic: true,
|
|
1056
|
+
isOptional,
|
|
1057
|
+
isCatchAll
|
|
1058
|
+
};
|
|
1059
|
+
}
|
|
1060
|
+
return {
|
|
1061
|
+
segment,
|
|
1062
|
+
isDynamic: false,
|
|
1063
|
+
isOptional: false,
|
|
1064
|
+
isCatchAll: false
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
__name(parseRouteSegment, "parseRouteSegment");
|
|
1068
|
+
function normalizeApiMethods(methods) {
|
|
1069
|
+
const normalized = {};
|
|
1070
|
+
for (const [method, handler] of Object.entries(methods)) {
|
|
1071
|
+
const normalizedMethod = method.toUpperCase();
|
|
1072
|
+
if (handler && isProgrammaticRouteMethod(normalizedMethod)) {
|
|
1073
|
+
normalized[normalizedMethod] = handler;
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
return normalized;
|
|
1077
|
+
}
|
|
1078
|
+
__name(normalizeApiMethods, "normalizeApiMethods");
|
|
1079
|
+
function isProgrammaticRouteMethod(method) {
|
|
1080
|
+
return method === "GET" || method === "HEAD" || method === "POST" || method === "PUT" || method === "DELETE" || method === "PATCH" || method === "OPTIONS";
|
|
1081
|
+
}
|
|
1082
|
+
__name(isProgrammaticRouteMethod, "isProgrammaticRouteMethod");
|
|
1083
|
+
function normalizeStaticPaths(routePath, paths) {
|
|
1084
|
+
const dynamicSegments = parseProgrammaticRoutePath(routePath).segments.filter(
|
|
1085
|
+
(segment) => segment.isDynamic
|
|
1086
|
+
);
|
|
1087
|
+
return paths.map((entry) => {
|
|
1088
|
+
if (typeof entry === "string" || Array.isArray(entry)) {
|
|
1089
|
+
if (dynamicSegments.length !== 1) {
|
|
1090
|
+
throw new Error(
|
|
1091
|
+
`staticPaths for "${routePath}" must return objects when the route has ${dynamicSegments.length} dynamic params.`
|
|
1092
|
+
);
|
|
1093
|
+
}
|
|
1094
|
+
const value = Array.isArray(entry) ? entry.join("/") : entry;
|
|
1095
|
+
return { [dynamicSegments[0].segment]: String(value) };
|
|
1096
|
+
}
|
|
1097
|
+
return Object.fromEntries(
|
|
1098
|
+
Object.entries(entry).map(([key, value]) => [
|
|
1099
|
+
key,
|
|
1100
|
+
Array.isArray(value) ? value.map(String).join("/") : String(value)
|
|
1101
|
+
])
|
|
1102
|
+
);
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
__name(normalizeStaticPaths, "normalizeStaticPaths");
|
|
1106
|
+
|
|
1107
|
+
// src/i18n/server.ts
|
|
1108
|
+
var import_node_async_hooks = require("async_hooks");
|
|
1109
|
+
|
|
1110
|
+
// src/i18n/runtime.ts
|
|
1111
|
+
var import_intl_messageformat = __toESM(require("intl-messageformat"));
|
|
1112
|
+
|
|
1113
|
+
// src/i18n/catalog.ts
|
|
1114
|
+
var import_promises = require("fs/promises");
|
|
1115
|
+
var import_icu_messageformat_parser = require("@formatjs/icu-messageformat-parser");
|
|
1116
|
+
|
|
1117
|
+
// src/i18n/config.ts
|
|
1118
|
+
var import_node_path = __toESM(require("path"));
|
|
1119
|
+
var DEFAULT_FARM_I18N_COOKIE_MAX_AGE = 60 * 60 * 24 * 365;
|
|
1120
|
+
|
|
1121
|
+
// src/i18n/server.ts
|
|
1122
|
+
var FARM_I18N_REQUEST_STORE = /* @__PURE__ */ Symbol.for("farm.i18n.requestStore");
|
|
1123
|
+
function getRequestStore() {
|
|
1124
|
+
const state = globalThis;
|
|
1125
|
+
return state[FARM_I18N_REQUEST_STORE] ?? (state[FARM_I18N_REQUEST_STORE] = new import_node_async_hooks.AsyncLocalStorage());
|
|
1126
|
+
}
|
|
1127
|
+
__name(getRequestStore, "getRequestStore");
|
|
1128
|
+
function getState() {
|
|
1129
|
+
const state = getRequestStore().getStore();
|
|
1130
|
+
if (!state) {
|
|
1131
|
+
throw new Error(
|
|
1132
|
+
"No Farm i18n request context is active. Use this API while rendering, inside an API route, or use createTranslator(locale)."
|
|
1133
|
+
);
|
|
1134
|
+
}
|
|
1135
|
+
return state;
|
|
1136
|
+
}
|
|
1137
|
+
__name(getState, "getState");
|
|
1138
|
+
var t = createTranslatorFromState(() => getState());
|
|
1139
|
+
function getFarmI18nClientSnapshot() {
|
|
1140
|
+
return getRequestStore().getStore()?.snapshot;
|
|
1141
|
+
}
|
|
1142
|
+
__name(getFarmI18nClientSnapshot, "getFarmI18nClientSnapshot");
|
|
1143
|
+
function createTranslatorFromState(resolveState) {
|
|
1144
|
+
const translator = /* @__PURE__ */ __name(((key, values) => {
|
|
1145
|
+
const state = resolveState();
|
|
1146
|
+
return state.runtime.translate(state.resolution.locale, key, values);
|
|
1147
|
+
}), "translator");
|
|
1148
|
+
translator.rich = (key, values) => {
|
|
1149
|
+
const state = resolveState();
|
|
1150
|
+
return state.runtime.translateRich(state.resolution.locale, key, values);
|
|
1151
|
+
};
|
|
1152
|
+
translator.raw = (key) => {
|
|
1153
|
+
const state = resolveState();
|
|
1154
|
+
return state.runtime.getRawMessage(state.resolution.locale, key);
|
|
1155
|
+
};
|
|
1156
|
+
translator.has = (key) => {
|
|
1157
|
+
const state = resolveState();
|
|
1158
|
+
return state.runtime.hasMessage(state.resolution.locale, key);
|
|
1159
|
+
};
|
|
1160
|
+
return translator;
|
|
1161
|
+
}
|
|
1162
|
+
__name(createTranslatorFromState, "createTranslatorFromState");
|
|
1163
|
+
_setFarmI18nSnapshotResolver(() => getFarmI18nClientSnapshot());
|
|
1164
|
+
|
|
1165
|
+
// src/server/request.ts
|
|
1166
|
+
var import_node_async_hooks2 = require("async_hooks");
|
|
1167
|
+
|
|
1168
|
+
// src/server/request-bridge.ts
|
|
1169
|
+
var CURRENT_REQUEST_RESOLVER_KEY = /* @__PURE__ */ Symbol.for("farm.currentRequestResolver");
|
|
1170
|
+
function getGlobalState() {
|
|
1171
|
+
return globalThis;
|
|
1172
|
+
}
|
|
1173
|
+
__name(getGlobalState, "getGlobalState");
|
|
1174
|
+
function _setCurrentRequestResolver(resolver) {
|
|
1175
|
+
getGlobalState()[CURRENT_REQUEST_RESOLVER_KEY] = resolver;
|
|
1176
|
+
}
|
|
1177
|
+
__name(_setCurrentRequestResolver, "_setCurrentRequestResolver");
|
|
1178
|
+
|
|
1179
|
+
// src/server/request.ts
|
|
1180
|
+
var REQUEST_STORAGE_KEY = /* @__PURE__ */ Symbol.for("@farm.js/core/request-storage");
|
|
1181
|
+
function getRequestStore2() {
|
|
1182
|
+
const runtime = globalThis;
|
|
1183
|
+
const existing = runtime[REQUEST_STORAGE_KEY];
|
|
1184
|
+
if (existing instanceof import_node_async_hooks2.AsyncLocalStorage) {
|
|
1185
|
+
return existing;
|
|
1186
|
+
}
|
|
1187
|
+
const storage = new import_node_async_hooks2.AsyncLocalStorage();
|
|
1188
|
+
runtime[REQUEST_STORAGE_KEY] = storage;
|
|
1189
|
+
return storage;
|
|
1190
|
+
}
|
|
1191
|
+
__name(getRequestStore2, "getRequestStore");
|
|
1192
|
+
var requestStore = getRequestStore2();
|
|
1193
|
+
_setCurrentRequestResolver(() => requestStore.getStore());
|
|
1194
|
+
async function _runWithCurrentRequest(request, fn) {
|
|
1195
|
+
return requestStore.run(request, fn);
|
|
1196
|
+
}
|
|
1197
|
+
__name(_runWithCurrentRequest, "_runWithCurrentRequest");
|
|
1198
|
+
|
|
1199
|
+
// src/api/runtime.ts
|
|
1200
|
+
function matchAPIRoute(routes, pathname) {
|
|
1201
|
+
const exactRoute = routes.get(pathname);
|
|
1202
|
+
if (exactRoute) {
|
|
1203
|
+
return { route: exactRoute, params: {} };
|
|
1204
|
+
}
|
|
1205
|
+
const normalizedPathname = normalizePathname(pathname);
|
|
1206
|
+
if (normalizedPathname !== pathname) {
|
|
1207
|
+
const normalizedRoute = routes.get(normalizedPathname);
|
|
1208
|
+
if (normalizedRoute) {
|
|
1209
|
+
return { route: normalizedRoute, params: {} };
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
for (const route of routes.values()) {
|
|
1213
|
+
const params = matchRoutePath(route.path, pathname);
|
|
1214
|
+
if (params) {
|
|
1215
|
+
return { route, params };
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
return null;
|
|
1219
|
+
}
|
|
1220
|
+
__name(matchAPIRoute, "matchAPIRoute");
|
|
1221
|
+
async function invokeAPIRouteEndpoint(endpoint, request, params = {}) {
|
|
1222
|
+
return _runWithCurrentRequest(
|
|
1223
|
+
request,
|
|
1224
|
+
() => invokeAPIRouteEndpointInContext(endpoint, request, params)
|
|
1225
|
+
);
|
|
1226
|
+
}
|
|
1227
|
+
__name(invokeAPIRouteEndpoint, "invokeAPIRouteEndpoint");
|
|
1228
|
+
async function invokeAPIRouteEndpointInContext(endpoint, request, params) {
|
|
1229
|
+
const farmHandler = endpoint.__handler || (isFarmContextHandler(endpoint) ? endpoint : null);
|
|
1230
|
+
if (!farmHandler) {
|
|
1231
|
+
const result2 = await endpoint(request, {
|
|
1232
|
+
params: Promise.resolve(params)
|
|
1233
|
+
});
|
|
1234
|
+
return normalizeRouteResponse(result2);
|
|
1235
|
+
}
|
|
1236
|
+
const url = new URL(request.url);
|
|
1237
|
+
const query = {};
|
|
1238
|
+
url.searchParams.forEach((value, key) => {
|
|
1239
|
+
query[key] = value;
|
|
1240
|
+
});
|
|
1241
|
+
let body = void 0;
|
|
1242
|
+
if (request.method.toUpperCase() !== "GET" && request.method.toUpperCase() !== "HEAD") {
|
|
1243
|
+
body = await readJSONBody(request);
|
|
1244
|
+
}
|
|
1245
|
+
const headers = Object.fromEntries(request.headers.entries());
|
|
1246
|
+
const types = endpoint.__types || {};
|
|
1247
|
+
const queryValidation = validateInput(types.query, query, "Invalid query parameters");
|
|
1248
|
+
if (queryValidation instanceof Response) {
|
|
1249
|
+
return queryValidation;
|
|
1250
|
+
}
|
|
1251
|
+
const bodyValidation = validateInput(types.body, body, "Invalid request body");
|
|
1252
|
+
if (bodyValidation instanceof Response) {
|
|
1253
|
+
return bodyValidation;
|
|
1254
|
+
}
|
|
1255
|
+
const headersValidation = validateInput(types.headers, headers, "Invalid request headers");
|
|
1256
|
+
if (headersValidation instanceof Response) {
|
|
1257
|
+
return headersValidation;
|
|
1258
|
+
}
|
|
1259
|
+
const result = await farmHandler({
|
|
1260
|
+
query: queryValidation,
|
|
1261
|
+
body: bodyValidation,
|
|
1262
|
+
headers: headersValidation,
|
|
1263
|
+
request,
|
|
1264
|
+
context: {},
|
|
1265
|
+
params
|
|
1266
|
+
});
|
|
1267
|
+
return normalizeRouteResponse(result);
|
|
1268
|
+
}
|
|
1269
|
+
__name(invokeAPIRouteEndpointInContext, "invokeAPIRouteEndpointInContext");
|
|
1270
|
+
function normalizeRouteResponse(result) {
|
|
1271
|
+
if (isWebResponse(result)) {
|
|
1272
|
+
return result;
|
|
1273
|
+
}
|
|
1274
|
+
if (result === void 0) {
|
|
1275
|
+
return new Response(null, { status: 204 });
|
|
1276
|
+
}
|
|
1277
|
+
return new Response(JSON.stringify(result), {
|
|
1278
|
+
status: 200,
|
|
1279
|
+
headers: { "Content-Type": "application/json" }
|
|
1280
|
+
});
|
|
1281
|
+
}
|
|
1282
|
+
__name(normalizeRouteResponse, "normalizeRouteResponse");
|
|
1283
|
+
function isWebResponse(value) {
|
|
1284
|
+
return value instanceof Response || typeof value === "object" && value !== null && "headers" in value && "status" in value && typeof value.arrayBuffer === "function";
|
|
1285
|
+
}
|
|
1286
|
+
__name(isWebResponse, "isWebResponse");
|
|
1287
|
+
function isFarmContextHandler(endpoint) {
|
|
1288
|
+
if (typeof endpoint !== "function") {
|
|
1289
|
+
return false;
|
|
1290
|
+
}
|
|
1291
|
+
const source = Function.prototype.toString.call(endpoint).trim();
|
|
1292
|
+
const arrowMatch = source.match(/^(?:async\s*)?(?:\(([^)]*)\)|([A-Za-z_$][\w$]*))\s*=>/);
|
|
1293
|
+
const functionMatch = source.match(/^(?:async\s*)?function[^(]*\(([^)]*)\)/);
|
|
1294
|
+
const firstParameter = (arrowMatch?.[1] || arrowMatch?.[2] || functionMatch?.[1] || "").split(",")[0].trim();
|
|
1295
|
+
return firstParameter === "ctx" || firstParameter === "context" || firstParameter.startsWith("{");
|
|
1296
|
+
}
|
|
1297
|
+
__name(isFarmContextHandler, "isFarmContextHandler");
|
|
1298
|
+
async function readJSONBody(request) {
|
|
1299
|
+
try {
|
|
1300
|
+
const text = await request.clone().text();
|
|
1301
|
+
if (text) {
|
|
1302
|
+
return JSON.parse(text);
|
|
1303
|
+
}
|
|
1304
|
+
} catch {
|
|
1305
|
+
}
|
|
1306
|
+
return void 0;
|
|
1307
|
+
}
|
|
1308
|
+
__name(readJSONBody, "readJSONBody");
|
|
1309
|
+
function validateInput(schema, value, error) {
|
|
1310
|
+
if (!schema || typeof schema.parse !== "function") {
|
|
1311
|
+
return value;
|
|
1312
|
+
}
|
|
1313
|
+
try {
|
|
1314
|
+
return schema.parse(value);
|
|
1315
|
+
} catch (validationError) {
|
|
1316
|
+
return new Response(
|
|
1317
|
+
JSON.stringify({
|
|
1318
|
+
error,
|
|
1319
|
+
details: validationError.errors || validationError.issues || validationError.message
|
|
1320
|
+
}),
|
|
1321
|
+
{
|
|
1322
|
+
status: 400,
|
|
1323
|
+
headers: { "Content-Type": "application/json" }
|
|
1324
|
+
}
|
|
1325
|
+
);
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
__name(validateInput, "validateInput");
|
|
1329
|
+
function matchRoutePath(routePath, pathname) {
|
|
1330
|
+
const routeSegments = getPathSegments(routePath);
|
|
1331
|
+
const pathnameSegments = getPathSegments(pathname);
|
|
1332
|
+
const params = {};
|
|
1333
|
+
let pathIndex = 0;
|
|
1334
|
+
for (const routeSegment of routeSegments) {
|
|
1335
|
+
const dynamicSegment = parseDynamicSegment(routeSegment);
|
|
1336
|
+
if (dynamicSegment?.catchAll) {
|
|
1337
|
+
const remainingSegments = pathnameSegments.slice(pathIndex).map(decodePathSegment);
|
|
1338
|
+
if (remainingSegments.length === 0 && !dynamicSegment.optional) {
|
|
1339
|
+
return null;
|
|
1340
|
+
}
|
|
1341
|
+
if (remainingSegments.length > 0) {
|
|
1342
|
+
params[dynamicSegment.name] = remainingSegments;
|
|
1343
|
+
}
|
|
1344
|
+
pathIndex = pathnameSegments.length;
|
|
1345
|
+
continue;
|
|
1346
|
+
}
|
|
1347
|
+
const pathnameSegment = pathnameSegments[pathIndex];
|
|
1348
|
+
if (pathnameSegment === void 0) {
|
|
1349
|
+
return null;
|
|
1350
|
+
}
|
|
1351
|
+
if (dynamicSegment) {
|
|
1352
|
+
params[dynamicSegment.name] = decodePathSegment(pathnameSegment);
|
|
1353
|
+
pathIndex++;
|
|
1354
|
+
continue;
|
|
1355
|
+
}
|
|
1356
|
+
if (routeSegment !== pathnameSegment) {
|
|
1357
|
+
return null;
|
|
1358
|
+
}
|
|
1359
|
+
pathIndex++;
|
|
1360
|
+
}
|
|
1361
|
+
return pathIndex === pathnameSegments.length ? params : null;
|
|
1362
|
+
}
|
|
1363
|
+
__name(matchRoutePath, "matchRoutePath");
|
|
1364
|
+
function getPathSegments(pathname) {
|
|
1365
|
+
return normalizePathname(pathname).split("/").filter((segment) => segment.length > 0);
|
|
1366
|
+
}
|
|
1367
|
+
__name(getPathSegments, "getPathSegments");
|
|
1368
|
+
function normalizePathname(pathname) {
|
|
1369
|
+
if (pathname.length > 1 && pathname.endsWith("/")) {
|
|
1370
|
+
return pathname.replace(/\/+$/, "");
|
|
1371
|
+
}
|
|
1372
|
+
return pathname;
|
|
1373
|
+
}
|
|
1374
|
+
__name(normalizePathname, "normalizePathname");
|
|
1375
|
+
function parseDynamicSegment(segment) {
|
|
1376
|
+
const optionalCatchAll = segment.match(/^\[\[\.\.\.(.+)\]\]$/);
|
|
1377
|
+
if (optionalCatchAll?.[1]) {
|
|
1378
|
+
return { name: optionalCatchAll[1], catchAll: true, optional: true };
|
|
1379
|
+
}
|
|
1380
|
+
const catchAll = segment.match(/^\[\.\.\.(.+)\]$/);
|
|
1381
|
+
if (catchAll?.[1]) {
|
|
1382
|
+
return { name: catchAll[1], catchAll: true, optional: false };
|
|
1383
|
+
}
|
|
1384
|
+
const dynamic = segment.match(/^\[(.+)\]$/);
|
|
1385
|
+
if (dynamic?.[1]) {
|
|
1386
|
+
return { name: dynamic[1], catchAll: false, optional: false };
|
|
1387
|
+
}
|
|
1388
|
+
return null;
|
|
1389
|
+
}
|
|
1390
|
+
__name(parseDynamicSegment, "parseDynamicSegment");
|
|
1391
|
+
function decodePathSegment(segment) {
|
|
1392
|
+
try {
|
|
1393
|
+
return decodeURIComponent(segment);
|
|
1394
|
+
} catch {
|
|
1395
|
+
return segment;
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
__name(decodePathSegment, "decodePathSegment");
|
|
1399
|
+
|
|
1400
|
+
// src/router.ts
|
|
1401
|
+
function matchFarmRoute(pattern, pathname) {
|
|
1402
|
+
return matchSegments(parseRoutePattern(pattern), normalizePathname2(pathname));
|
|
1403
|
+
}
|
|
1404
|
+
__name(matchFarmRoute, "matchFarmRoute");
|
|
1405
|
+
function buildFarmRoutePath(pattern, params = {}, options = {}) {
|
|
1406
|
+
const parts = [];
|
|
1407
|
+
for (const segment of parseRoutePattern(pattern)) {
|
|
1408
|
+
if (segment.type === "static") {
|
|
1409
|
+
parts.push(encodePathSegment(segment.value));
|
|
1410
|
+
continue;
|
|
1411
|
+
}
|
|
1412
|
+
const value = params[segment.name];
|
|
1413
|
+
const values = Array.isArray(value) ? value : value == null ? [] : [value];
|
|
1414
|
+
if (values.length === 0) {
|
|
1415
|
+
if (segment.optional) continue;
|
|
1416
|
+
throw new Error(`Missing route param "${segment.name}" for ${pattern}.`);
|
|
1417
|
+
}
|
|
1418
|
+
if (!segment.catchAll && values.length > 1) {
|
|
1419
|
+
throw new Error(`Route param "${segment.name}" for ${pattern} expects a single value.`);
|
|
1420
|
+
}
|
|
1421
|
+
parts.push(...values.map((item) => encodePathSegment(String(item))));
|
|
1422
|
+
}
|
|
1423
|
+
let pathname = parts.length ? `/${parts.join("/")}` : "/";
|
|
1424
|
+
if (options.trailingSlash && pathname !== "/") {
|
|
1425
|
+
pathname = `${pathname}/`;
|
|
1426
|
+
}
|
|
1427
|
+
return appendQueryAndHash(pathname, options);
|
|
1428
|
+
}
|
|
1429
|
+
__name(buildFarmRoutePath, "buildFarmRoutePath");
|
|
1430
|
+
function parseRoutePattern(pattern) {
|
|
1431
|
+
return splitPathname(pattern).filter((part) => !isRouteGroup(part)).map((part) => {
|
|
1432
|
+
const optionalCatchAll = part.match(/^\[\[\.\.\.([A-Za-z0-9_$-]+)\]\]$/);
|
|
1433
|
+
if (optionalCatchAll) {
|
|
1434
|
+
return {
|
|
1435
|
+
type: "dynamic",
|
|
1436
|
+
name: optionalCatchAll[1],
|
|
1437
|
+
catchAll: true,
|
|
1438
|
+
optional: true
|
|
1439
|
+
};
|
|
1440
|
+
}
|
|
1441
|
+
const catchAll = part.match(/^\[\.\.\.([A-Za-z0-9_$-]+)\]$/);
|
|
1442
|
+
if (catchAll) {
|
|
1443
|
+
return {
|
|
1444
|
+
type: "dynamic",
|
|
1445
|
+
name: catchAll[1],
|
|
1446
|
+
catchAll: true,
|
|
1447
|
+
optional: false
|
|
1448
|
+
};
|
|
1449
|
+
}
|
|
1450
|
+
const dynamic = part.match(/^\[([A-Za-z0-9_$-]+)\]$/) || part.match(/^:([A-Za-z0-9_$-]+)$/);
|
|
1451
|
+
if (dynamic) {
|
|
1452
|
+
return {
|
|
1453
|
+
type: "dynamic",
|
|
1454
|
+
name: dynamic[1],
|
|
1455
|
+
catchAll: false,
|
|
1456
|
+
optional: false
|
|
1457
|
+
};
|
|
1458
|
+
}
|
|
1459
|
+
const star = part.match(/^\*([A-Za-z0-9_$-]+)(\?)?$/);
|
|
1460
|
+
if (star) {
|
|
1461
|
+
return {
|
|
1462
|
+
type: "dynamic",
|
|
1463
|
+
name: star[1],
|
|
1464
|
+
catchAll: true,
|
|
1465
|
+
optional: !!star[2]
|
|
1466
|
+
};
|
|
1467
|
+
}
|
|
1468
|
+
return {
|
|
1469
|
+
type: "static",
|
|
1470
|
+
value: decodePathSegment2(part)
|
|
1471
|
+
};
|
|
1472
|
+
});
|
|
1473
|
+
}
|
|
1474
|
+
__name(parseRoutePattern, "parseRoutePattern");
|
|
1475
|
+
function matchSegments(segments, pathname) {
|
|
1476
|
+
const parts = splitPathname(pathname);
|
|
1477
|
+
const params = {};
|
|
1478
|
+
if (segments.length === 0) {
|
|
1479
|
+
return parts.length === 0 ? params : null;
|
|
1480
|
+
}
|
|
1481
|
+
let pathIndex = 0;
|
|
1482
|
+
for (const segment of segments) {
|
|
1483
|
+
if (segment.type === "static") {
|
|
1484
|
+
if (decodePathSegment2(parts[pathIndex] || "") !== segment.value) return null;
|
|
1485
|
+
pathIndex++;
|
|
1486
|
+
continue;
|
|
1487
|
+
}
|
|
1488
|
+
if (segment.catchAll) {
|
|
1489
|
+
const remaining = parts.slice(pathIndex).map(decodePathSegment2);
|
|
1490
|
+
if (remaining.length === 0 && !segment.optional) return null;
|
|
1491
|
+
params[segment.name] = remaining.join("/");
|
|
1492
|
+
pathIndex = parts.length;
|
|
1493
|
+
continue;
|
|
1494
|
+
}
|
|
1495
|
+
const value = parts[pathIndex];
|
|
1496
|
+
if (!value) return null;
|
|
1497
|
+
params[segment.name] = decodePathSegment2(value);
|
|
1498
|
+
pathIndex++;
|
|
1499
|
+
}
|
|
1500
|
+
return pathIndex === parts.length ? params : null;
|
|
1501
|
+
}
|
|
1502
|
+
__name(matchSegments, "matchSegments");
|
|
1503
|
+
function normalizePathname2(value) {
|
|
1504
|
+
const raw = value || "/";
|
|
1505
|
+
let pathname = raw;
|
|
1506
|
+
try {
|
|
1507
|
+
pathname = new URL(raw, "http://farm.local").pathname;
|
|
1508
|
+
} catch {
|
|
1509
|
+
pathname = raw.split(/[?#]/, 1)[0] || "/";
|
|
1510
|
+
}
|
|
1511
|
+
pathname = pathname.replace(/\\/g, "/").replace(/\/+/g, "/");
|
|
1512
|
+
if (!pathname.startsWith("/")) pathname = `/${pathname}`;
|
|
1513
|
+
if (pathname.length > 1) pathname = pathname.replace(/\/+$/, "");
|
|
1514
|
+
return pathname || "/";
|
|
1515
|
+
}
|
|
1516
|
+
__name(normalizePathname2, "normalizePathname");
|
|
1517
|
+
function splitPathname(pathname) {
|
|
1518
|
+
return normalizePathname2(pathname).split("/").filter(Boolean);
|
|
1519
|
+
}
|
|
1520
|
+
__name(splitPathname, "splitPathname");
|
|
1521
|
+
function isRouteGroup(part) {
|
|
1522
|
+
return part.startsWith("(") && part.endsWith(")");
|
|
1523
|
+
}
|
|
1524
|
+
__name(isRouteGroup, "isRouteGroup");
|
|
1525
|
+
function decodePathSegment2(value) {
|
|
1526
|
+
try {
|
|
1527
|
+
return decodeURIComponent(value);
|
|
1528
|
+
} catch {
|
|
1529
|
+
return value;
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
__name(decodePathSegment2, "decodePathSegment");
|
|
1533
|
+
function encodePathSegment(value) {
|
|
1534
|
+
return encodeURIComponent(value);
|
|
1535
|
+
}
|
|
1536
|
+
__name(encodePathSegment, "encodePathSegment");
|
|
1537
|
+
function appendQueryAndHash(pathname, options) {
|
|
1538
|
+
const search = createSearchParams2(options.query);
|
|
1539
|
+
const hash = options.hash ? `#${options.hash.replace(/^#/, "")}` : "";
|
|
1540
|
+
const query = search.toString();
|
|
1541
|
+
return `${pathname}${query ? `?${query}` : ""}${hash}`;
|
|
1542
|
+
}
|
|
1543
|
+
__name(appendQueryAndHash, "appendQueryAndHash");
|
|
1544
|
+
function createSearchParams2(query) {
|
|
1545
|
+
if (query instanceof URLSearchParams) return query;
|
|
1546
|
+
const search = new URLSearchParams();
|
|
1547
|
+
if (!query) return search;
|
|
1548
|
+
for (const [key, value] of Object.entries(query)) {
|
|
1549
|
+
const values = Array.isArray(value) ? value : [value];
|
|
1550
|
+
for (const item of values) {
|
|
1551
|
+
if (item == null) continue;
|
|
1552
|
+
search.append(key, String(item));
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
return search;
|
|
1556
|
+
}
|
|
1557
|
+
__name(createSearchParams2, "createSearchParams");
|
|
1558
|
+
|
|
1559
|
+
// src/server-action-security.ts
|
|
1560
|
+
var import_node_async_hooks3 = require("async_hooks");
|
|
1561
|
+
var SERVER_ACTION_STORAGE_KEY = /* @__PURE__ */ Symbol.for("farm.serverActionStorage");
|
|
1562
|
+
function runWithServerActionRequest(request, callback) {
|
|
1563
|
+
throwIfAborted(request.signal);
|
|
1564
|
+
return getServerActionStorage().run(
|
|
1565
|
+
{
|
|
1566
|
+
request,
|
|
1567
|
+
signal: request.signal,
|
|
1568
|
+
invalidations: /* @__PURE__ */ new Set()
|
|
1569
|
+
},
|
|
1570
|
+
callback
|
|
1571
|
+
);
|
|
1572
|
+
}
|
|
1573
|
+
__name(runWithServerActionRequest, "runWithServerActionRequest");
|
|
1574
|
+
function getServerActionExecutionContext() {
|
|
1575
|
+
return getServerActionStorage().getStore();
|
|
1576
|
+
}
|
|
1577
|
+
__name(getServerActionExecutionContext, "getServerActionExecutionContext");
|
|
1578
|
+
subscribeFarmCacheInvalidation((key) => {
|
|
1579
|
+
getServerActionExecutionContext()?.invalidations.add(key);
|
|
1580
|
+
});
|
|
1581
|
+
function getServerActionStorage() {
|
|
1582
|
+
const globalState2 = globalThis;
|
|
1583
|
+
if (!globalState2[SERVER_ACTION_STORAGE_KEY]) {
|
|
1584
|
+
globalState2[SERVER_ACTION_STORAGE_KEY] = new import_node_async_hooks3.AsyncLocalStorage();
|
|
1585
|
+
}
|
|
1586
|
+
return globalState2[SERVER_ACTION_STORAGE_KEY];
|
|
1587
|
+
}
|
|
1588
|
+
__name(getServerActionStorage, "getServerActionStorage");
|
|
1589
|
+
function throwIfAborted(signal) {
|
|
1590
|
+
if (!signal.aborted) return;
|
|
1591
|
+
if (signal.reason !== void 0) throw signal.reason;
|
|
1592
|
+
throw new DOMException("The operation was aborted", "AbortError");
|
|
1593
|
+
}
|
|
1594
|
+
__name(throwIfAborted, "throwIfAborted");
|
|
1595
|
+
|
|
1596
|
+
// src/testing.ts
|
|
1597
|
+
function createTestRequest(path2 = "/", options = {}) {
|
|
1598
|
+
const url = resolveTestURL(path2, options.origin);
|
|
1599
|
+
applyQuery(url.searchParams, options.query);
|
|
1600
|
+
const headers = new Headers(options.headers);
|
|
1601
|
+
applyCookies(headers, options.cookies);
|
|
1602
|
+
const { body, hasBody } = resolveRequestBody(options, headers);
|
|
1603
|
+
const method = (options.method ?? (hasBody ? "POST" : "GET")).toUpperCase();
|
|
1604
|
+
if ((method === "GET" || method === "HEAD") && body != null) {
|
|
1605
|
+
throw new TypeError(`Farm test requests cannot send a body with ${method}`);
|
|
1606
|
+
}
|
|
1607
|
+
const {
|
|
1608
|
+
origin: _origin,
|
|
1609
|
+
query: _query,
|
|
1610
|
+
cookies: _cookies,
|
|
1611
|
+
json: _json,
|
|
1612
|
+
form: _form,
|
|
1613
|
+
body: _body,
|
|
1614
|
+
headers: _headers,
|
|
1615
|
+
...requestInit
|
|
1616
|
+
} = options;
|
|
1617
|
+
return new Request(url, {
|
|
1618
|
+
...requestInit,
|
|
1619
|
+
method,
|
|
1620
|
+
headers,
|
|
1621
|
+
body
|
|
1622
|
+
});
|
|
1623
|
+
}
|
|
1624
|
+
__name(createTestRequest, "createTestRequest");
|
|
1625
|
+
function createFarmTestHarness(options = {}) {
|
|
1626
|
+
const origin = normalizeOrigin(options.origin);
|
|
1627
|
+
const request = /* @__PURE__ */ __name((path2 = "/", requestOptions = {}) => createTestRequest(path2, mergeRequestDefaults(options, origin, requestOptions)), "request");
|
|
1628
|
+
return {
|
|
1629
|
+
request,
|
|
1630
|
+
async route(route, routeOptions = {}) {
|
|
1631
|
+
const requestPath = routeOptions.path ?? buildFarmRoutePath(route.path, routeOptions.params ?? {});
|
|
1632
|
+
const routeRequest = request(requestPath, {
|
|
1633
|
+
origin: routeOptions.origin,
|
|
1634
|
+
headers: routeOptions.headers,
|
|
1635
|
+
cookies: routeOptions.cookies,
|
|
1636
|
+
signal: routeOptions.signal,
|
|
1637
|
+
query: routeOptions.search
|
|
1638
|
+
});
|
|
1639
|
+
const url = new URL(routeRequest.url);
|
|
1640
|
+
const params = resolvePageParams(route.path, url.pathname, routeOptions.params);
|
|
1641
|
+
const search = readSearchParams(url.searchParams);
|
|
1642
|
+
const routeContext = Object.prototype.hasOwnProperty.call(routeOptions, "context") ? routeOptions.context : await resolveFarmRouteContext(
|
|
1643
|
+
{ context: options.context },
|
|
1644
|
+
{
|
|
1645
|
+
request: routeRequest,
|
|
1646
|
+
params,
|
|
1647
|
+
search,
|
|
1648
|
+
path: url.pathname
|
|
1649
|
+
}
|
|
1650
|
+
);
|
|
1651
|
+
const rawProps = withFarmRouteContext(
|
|
1652
|
+
{
|
|
1653
|
+
params,
|
|
1654
|
+
searchParams: Promise.resolve(search),
|
|
1655
|
+
path: url.pathname,
|
|
1656
|
+
middleware: routeOptions.middleware,
|
|
1657
|
+
context: routeOptions.pluginContext
|
|
1658
|
+
},
|
|
1659
|
+
routeContext
|
|
1660
|
+
);
|
|
1661
|
+
const routeModule = createRouteModuleFromProgrammaticPage(route);
|
|
1662
|
+
const resolveProps = routeModule.__farmResolveRouteProps;
|
|
1663
|
+
const resolvedProps = resolveProps ? await resolveProps(rawProps) : { ...rawProps, search, searchParams: Promise.resolve(search) };
|
|
1664
|
+
const canonicalPath = readCanonicalPath(resolvedProps);
|
|
1665
|
+
const componentProps = stripInternalRouteProps(resolvedProps);
|
|
1666
|
+
return {
|
|
1667
|
+
route,
|
|
1668
|
+
module: routeModule,
|
|
1669
|
+
request: routeRequest,
|
|
1670
|
+
props: componentProps,
|
|
1671
|
+
element: (0, import_react2.createElement)(route.component, componentProps),
|
|
1672
|
+
canonicalPath
|
|
1673
|
+
};
|
|
1674
|
+
},
|
|
1675
|
+
async api(route, apiOptions = {}) {
|
|
1676
|
+
const requestPath = apiOptions.path ?? buildFarmRoutePath(route.path, apiOptions.params ?? {});
|
|
1677
|
+
const method = apiOptions.method ?? getDefaultApiMethod(route);
|
|
1678
|
+
const apiRequest = request(requestPath, omitApiControlOptions({ ...apiOptions, method }));
|
|
1679
|
+
const match = matchAPIRoute(/* @__PURE__ */ new Map([[route.path, route]]), new URL(apiRequest.url).pathname);
|
|
1680
|
+
if (!match) {
|
|
1681
|
+
return jsonErrorResponse("Not Found", 404);
|
|
1682
|
+
}
|
|
1683
|
+
const endpoint = match.route.methods[apiRequest.method];
|
|
1684
|
+
if (!endpoint) {
|
|
1685
|
+
return jsonErrorResponse("Method Not Allowed", 405);
|
|
1686
|
+
}
|
|
1687
|
+
return invokeTestEndpoint(endpoint, apiRequest, match.params, apiOptions.throwOnError);
|
|
1688
|
+
},
|
|
1689
|
+
async endpoint(endpoint, endpointOptions = {}) {
|
|
1690
|
+
const endpointRecord = endpoint;
|
|
1691
|
+
const endpointPath = endpointOptions.path ?? endpointRecord.__path ?? "/__farm/test/endpoint";
|
|
1692
|
+
const endpointRequest = request(endpointPath, {
|
|
1693
|
+
...omitEndpointControlOptions(endpointOptions),
|
|
1694
|
+
method: endpointOptions.method ?? endpointRecord.__method ?? "GET"
|
|
1695
|
+
});
|
|
1696
|
+
return invokeTestEndpoint(
|
|
1697
|
+
endpoint,
|
|
1698
|
+
endpointRequest,
|
|
1699
|
+
endpointOptions.params,
|
|
1700
|
+
endpointOptions.throwOnError
|
|
1701
|
+
);
|
|
1702
|
+
},
|
|
1703
|
+
async serverFn(serverFn, ...args) {
|
|
1704
|
+
const [input, serverFnOptions = {}] = args;
|
|
1705
|
+
const actionRequest = serverFnOptions.request ?? request(serverFnOptions.path ?? "/__farm/test/server-fn", {
|
|
1706
|
+
origin: serverFnOptions.origin,
|
|
1707
|
+
headers: serverFnOptions.headers,
|
|
1708
|
+
cookies: serverFnOptions.cookies,
|
|
1709
|
+
signal: serverFnOptions.signal,
|
|
1710
|
+
method: "POST"
|
|
1711
|
+
});
|
|
1712
|
+
return await runWithServerActionRequest(actionRequest, () => serverFn(input));
|
|
1713
|
+
},
|
|
1714
|
+
clearCache() {
|
|
1715
|
+
getFarmDataCache().clear();
|
|
1716
|
+
}
|
|
1717
|
+
};
|
|
1718
|
+
}
|
|
1719
|
+
__name(createFarmTestHarness, "createFarmTestHarness");
|
|
1720
|
+
function resolveTestURL(path2, origin) {
|
|
1721
|
+
const url = path2 instanceof URL ? new URL(path2) : new URL(path2, `${normalizeOrigin(origin)}/`);
|
|
1722
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
1723
|
+
throw new TypeError(`Farm test requests require an HTTP(S) URL, received ${url.protocol}`);
|
|
1724
|
+
}
|
|
1725
|
+
return url;
|
|
1726
|
+
}
|
|
1727
|
+
__name(resolveTestURL, "resolveTestURL");
|
|
1728
|
+
function normalizeOrigin(origin = "http://farm.test") {
|
|
1729
|
+
let url;
|
|
1730
|
+
try {
|
|
1731
|
+
url = new URL(origin);
|
|
1732
|
+
} catch {
|
|
1733
|
+
throw new TypeError(`Invalid Farm test origin: ${JSON.stringify(origin)}`);
|
|
1734
|
+
}
|
|
1735
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
1736
|
+
throw new TypeError(`Farm test origins must use HTTP(S), received ${url.protocol}`);
|
|
1737
|
+
}
|
|
1738
|
+
return url.origin;
|
|
1739
|
+
}
|
|
1740
|
+
__name(normalizeOrigin, "normalizeOrigin");
|
|
1741
|
+
function mergeRequestDefaults(harnessOptions, origin, requestOptions) {
|
|
1742
|
+
const headers = new Headers(harnessOptions.headers);
|
|
1743
|
+
new Headers(requestOptions.headers).forEach((value, key) => headers.set(key, value));
|
|
1744
|
+
return {
|
|
1745
|
+
...requestOptions,
|
|
1746
|
+
origin: requestOptions.origin ?? origin,
|
|
1747
|
+
headers,
|
|
1748
|
+
cookies: {
|
|
1749
|
+
...harnessOptions.cookies,
|
|
1750
|
+
...requestOptions.cookies
|
|
1751
|
+
}
|
|
1752
|
+
};
|
|
1753
|
+
}
|
|
1754
|
+
__name(mergeRequestDefaults, "mergeRequestDefaults");
|
|
1755
|
+
function applyQuery(searchParams, query) {
|
|
1756
|
+
if (!query) return;
|
|
1757
|
+
if (query instanceof URLSearchParams) {
|
|
1758
|
+
for (const key of new Set(query.keys())) {
|
|
1759
|
+
searchParams.delete(key);
|
|
1760
|
+
for (const value of query.getAll(key)) searchParams.append(key, value);
|
|
1761
|
+
}
|
|
1762
|
+
return;
|
|
1763
|
+
}
|
|
1764
|
+
for (const [key, rawValue] of Object.entries(query)) {
|
|
1765
|
+
searchParams.delete(key);
|
|
1766
|
+
const values = Array.isArray(rawValue) ? rawValue : [rawValue];
|
|
1767
|
+
for (const value of values) {
|
|
1768
|
+
if (value == null) continue;
|
|
1769
|
+
if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") {
|
|
1770
|
+
throw new TypeError(`Invalid query value for ${JSON.stringify(key)}`);
|
|
1771
|
+
}
|
|
1772
|
+
searchParams.append(key, String(value));
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
__name(applyQuery, "applyQuery");
|
|
1777
|
+
function applyCookies(headers, cookies) {
|
|
1778
|
+
if (!cookies || Object.keys(cookies).length === 0) return;
|
|
1779
|
+
const value = Object.entries(cookies).map(([name, cookieValue]) => `${encodeURIComponent(name)}=${encodeURIComponent(cookieValue)}`).join("; ");
|
|
1780
|
+
const current = headers.get("cookie");
|
|
1781
|
+
headers.set("cookie", current ? `${current}; ${value}` : value);
|
|
1782
|
+
}
|
|
1783
|
+
__name(applyCookies, "applyCookies");
|
|
1784
|
+
function resolveRequestBody(options, headers) {
|
|
1785
|
+
const sources = [
|
|
1786
|
+
options.json !== void 0,
|
|
1787
|
+
options.form !== void 0,
|
|
1788
|
+
options.body !== void 0
|
|
1789
|
+
];
|
|
1790
|
+
if (sources.filter(Boolean).length > 1) {
|
|
1791
|
+
throw new TypeError("Farm test requests accept only one of json, form, or body");
|
|
1792
|
+
}
|
|
1793
|
+
if (options.json !== void 0) {
|
|
1794
|
+
if (!headers.has("content-type")) headers.set("content-type", "application/json");
|
|
1795
|
+
return { body: JSON.stringify(options.json), hasBody: true };
|
|
1796
|
+
}
|
|
1797
|
+
if (options.form !== void 0) {
|
|
1798
|
+
const formData = options.form instanceof FormData ? options.form : createFormData(options.form);
|
|
1799
|
+
return { body: formData, hasBody: true };
|
|
1800
|
+
}
|
|
1801
|
+
return {
|
|
1802
|
+
body: options.body ?? null,
|
|
1803
|
+
hasBody: options.body !== void 0
|
|
1804
|
+
};
|
|
1805
|
+
}
|
|
1806
|
+
__name(resolveRequestBody, "resolveRequestBody");
|
|
1807
|
+
function createFormData(values) {
|
|
1808
|
+
const formData = new FormData();
|
|
1809
|
+
for (const [key, rawValue] of Object.entries(values)) {
|
|
1810
|
+
const entries = Array.isArray(rawValue) ? rawValue : [rawValue];
|
|
1811
|
+
for (const value of entries) formData.append(key, value);
|
|
1812
|
+
}
|
|
1813
|
+
return formData;
|
|
1814
|
+
}
|
|
1815
|
+
__name(createFormData, "createFormData");
|
|
1816
|
+
function resolvePageParams(pattern, pathname, explicitParams) {
|
|
1817
|
+
const matchedParams = matchFarmRoute(pattern, pathname);
|
|
1818
|
+
if (!matchedParams) {
|
|
1819
|
+
throw new Error(
|
|
1820
|
+
`Path ${JSON.stringify(pathname)} does not match route ${JSON.stringify(pattern)}`
|
|
1821
|
+
);
|
|
1822
|
+
}
|
|
1823
|
+
if (!explicitParams) return matchedParams;
|
|
1824
|
+
return Object.fromEntries(
|
|
1825
|
+
Object.entries(explicitParams).map(([key, value]) => [
|
|
1826
|
+
key,
|
|
1827
|
+
Array.isArray(value) ? value.map(String).join("/") : String(value)
|
|
1828
|
+
])
|
|
1829
|
+
);
|
|
1830
|
+
}
|
|
1831
|
+
__name(resolvePageParams, "resolvePageParams");
|
|
1832
|
+
function readSearchParams(searchParams) {
|
|
1833
|
+
const search = {};
|
|
1834
|
+
searchParams.forEach((value, key) => {
|
|
1835
|
+
search[key] = value;
|
|
1836
|
+
});
|
|
1837
|
+
return search;
|
|
1838
|
+
}
|
|
1839
|
+
__name(readSearchParams, "readSearchParams");
|
|
1840
|
+
function readCanonicalPath(props) {
|
|
1841
|
+
return typeof props.__farmCanonicalPath === "string" ? props.__farmCanonicalPath : void 0;
|
|
1842
|
+
}
|
|
1843
|
+
__name(readCanonicalPath, "readCanonicalPath");
|
|
1844
|
+
function stripInternalRouteProps(props) {
|
|
1845
|
+
const { __farmRoutePropsResolved, __farmCanonicalPath, ...componentProps } = props;
|
|
1846
|
+
return componentProps;
|
|
1847
|
+
}
|
|
1848
|
+
__name(stripInternalRouteProps, "stripInternalRouteProps");
|
|
1849
|
+
function getDefaultApiMethod(route) {
|
|
1850
|
+
if (route.methods.GET) return "GET";
|
|
1851
|
+
return Object.keys(route.methods)[0] ?? "GET";
|
|
1852
|
+
}
|
|
1853
|
+
__name(getDefaultApiMethod, "getDefaultApiMethod");
|
|
1854
|
+
function omitApiControlOptions(options) {
|
|
1855
|
+
const { path: _path, params: _params, throwOnError: _throwOnError, ...requestOptions } = options;
|
|
1856
|
+
return requestOptions;
|
|
1857
|
+
}
|
|
1858
|
+
__name(omitApiControlOptions, "omitApiControlOptions");
|
|
1859
|
+
function omitEndpointControlOptions(options) {
|
|
1860
|
+
const { path: _path, params: _params, throwOnError: _throwOnError, ...requestOptions } = options;
|
|
1861
|
+
return requestOptions;
|
|
1862
|
+
}
|
|
1863
|
+
__name(omitEndpointControlOptions, "omitEndpointControlOptions");
|
|
1864
|
+
async function invokeTestEndpoint(endpoint, request, params = {}, throwOnError = false) {
|
|
1865
|
+
try {
|
|
1866
|
+
return await invokeAPIRouteEndpoint(endpoint, request, params);
|
|
1867
|
+
} catch (error) {
|
|
1868
|
+
if (throwOnError) throw error;
|
|
1869
|
+
return jsonErrorResponse(error instanceof Error ? error.message : "Internal Server Error", 500);
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
__name(invokeTestEndpoint, "invokeTestEndpoint");
|
|
1873
|
+
function jsonErrorResponse(error, status) {
|
|
1874
|
+
return Response.json({ error }, { status });
|
|
1875
|
+
}
|
|
1876
|
+
__name(jsonErrorResponse, "jsonErrorResponse");
|
|
1877
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1878
|
+
0 && (module.exports = {
|
|
1879
|
+
createFarmTestHarness,
|
|
1880
|
+
createTestRequest
|
|
1881
|
+
});
|
|
1882
|
+
//# sourceMappingURL=testing.cjs.map
|