@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
|
@@ -0,0 +1,4172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __esm = (fn, res) => function __init() {
|
|
10
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
11
|
+
};
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
30
|
+
mod
|
|
31
|
+
));
|
|
32
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
+
|
|
34
|
+
// src/storage/index.ts
|
|
35
|
+
var storage_exports = {};
|
|
36
|
+
__export(storage_exports, {
|
|
37
|
+
createFarmStorage: () => createFarmStorage,
|
|
38
|
+
createStorageClient: () => createStorageClient,
|
|
39
|
+
databaseStorage: () => databaseStorage,
|
|
40
|
+
defineStorageClient: () => defineStorageClient,
|
|
41
|
+
disposeStorage: () => disposeStorage,
|
|
42
|
+
driverStorage: () => driverStorage,
|
|
43
|
+
getStorage: () => getStorage,
|
|
44
|
+
initStorage: () => initStorage,
|
|
45
|
+
libsqlStorage: () => libsqlStorage,
|
|
46
|
+
localStorage: () => localStorage,
|
|
47
|
+
memoryStorage: () => memoryStorage,
|
|
48
|
+
mongodbStorage: () => mongodbStorage,
|
|
49
|
+
mysql2Storage: () => mysql2Storage,
|
|
50
|
+
mysqlStorage: () => mysqlStorage,
|
|
51
|
+
netlifyBlobsStorage: () => netlifyBlobsStorage,
|
|
52
|
+
pgStorage: () => pgStorage,
|
|
53
|
+
pgliteStorage: () => pgliteStorage,
|
|
54
|
+
planetscaleStorage: () => planetscaleStorage,
|
|
55
|
+
postgresStorage: () => postgresStorage,
|
|
56
|
+
redisStorage: () => redisStorage,
|
|
57
|
+
resolveStorageRuntimeClient: () => resolveStorageRuntimeClient,
|
|
58
|
+
s3Storage: () => s3Storage,
|
|
59
|
+
sqliteStorage: () => sqliteStorage,
|
|
60
|
+
upstashStorage: () => upstashStorage,
|
|
61
|
+
vercelBlobStorage: () => vercelBlobStorage,
|
|
62
|
+
vercelKVStorage: () => vercelKVStorage
|
|
63
|
+
});
|
|
64
|
+
function createMemoryStorage() {
|
|
65
|
+
return (0, import_unstorage.createStorage)({
|
|
66
|
+
driver: (0, import_memory.default)()
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function readGlobalStorage() {
|
|
70
|
+
return globalThis[GLOBAL_STORAGE_KEY];
|
|
71
|
+
}
|
|
72
|
+
function writeGlobalStorage(storage) {
|
|
73
|
+
globalThis[GLOBAL_STORAGE_KEY] = storage;
|
|
74
|
+
return storage;
|
|
75
|
+
}
|
|
76
|
+
function getActiveGlobalStorage() {
|
|
77
|
+
const existing = readGlobalStorage();
|
|
78
|
+
if (existing) {
|
|
79
|
+
return existing;
|
|
80
|
+
}
|
|
81
|
+
return writeGlobalStorage(createMemoryStorage());
|
|
82
|
+
}
|
|
83
|
+
function normalizeMountKey(base) {
|
|
84
|
+
return (base || "").trim().replace(/^[:/\\]+|[:/\\]+$/g, "").replace(/[\\/]+/g, ":");
|
|
85
|
+
}
|
|
86
|
+
function isDriverInstance(value) {
|
|
87
|
+
return !!value && typeof value === "object" && typeof value.getItem === "function" && typeof value.getKeys === "function";
|
|
88
|
+
}
|
|
89
|
+
function isStorageInstance(value) {
|
|
90
|
+
return !!value && typeof value === "object" && typeof value.mount === "function" && typeof value.getMount === "function";
|
|
91
|
+
}
|
|
92
|
+
function isStorageClient(value) {
|
|
93
|
+
return !!value && typeof value === "object" && value.kind === "farm-storage-client" && typeof value.resolveDriver === "function" && typeof value.createStorage === "function";
|
|
94
|
+
}
|
|
95
|
+
function isDatabaseDriverName(name) {
|
|
96
|
+
return name in DATABASE_CONNECTORS;
|
|
97
|
+
}
|
|
98
|
+
function extractDriverOptions(config) {
|
|
99
|
+
const source = config;
|
|
100
|
+
const {
|
|
101
|
+
client: _client,
|
|
102
|
+
driver: _driver,
|
|
103
|
+
mounts: _mounts,
|
|
104
|
+
options,
|
|
105
|
+
tableName: _tableName,
|
|
106
|
+
...inlineOptions
|
|
107
|
+
} = source;
|
|
108
|
+
const hasInlineOptions = Object.keys(inlineOptions).length > 0;
|
|
109
|
+
if (options && typeof options === "object" && !Array.isArray(options)) {
|
|
110
|
+
return hasInlineOptions ? { ...inlineOptions, ...options } : options;
|
|
111
|
+
}
|
|
112
|
+
if (hasInlineOptions) {
|
|
113
|
+
return inlineOptions;
|
|
114
|
+
}
|
|
115
|
+
return options;
|
|
116
|
+
}
|
|
117
|
+
async function loadBuiltinDriver(name, options) {
|
|
118
|
+
const modulePath = import_unstorage.builtinDrivers[name];
|
|
119
|
+
if (!modulePath) {
|
|
120
|
+
throw new Error(`Unsupported storage driver "${name}".`);
|
|
121
|
+
}
|
|
122
|
+
const module2 = await loadModule(modulePath);
|
|
123
|
+
return module2.default(options);
|
|
124
|
+
}
|
|
125
|
+
async function loadDatabaseDriver(config) {
|
|
126
|
+
const connectorEntry = DATABASE_CONNECTORS[config.driver];
|
|
127
|
+
const [{ createDatabase }, connectorModule, db0DriverModule] = await Promise.all([
|
|
128
|
+
loadModule("db0"),
|
|
129
|
+
connectorEntry.load(),
|
|
130
|
+
loadModule("unstorage/drivers/db0")
|
|
131
|
+
]);
|
|
132
|
+
const database = createDatabase(connectorModule.default(extractDriverOptions(config) || {}));
|
|
133
|
+
return db0DriverModule.default({
|
|
134
|
+
database,
|
|
135
|
+
tableName: config.tableName
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
async function resolveDriver(config) {
|
|
139
|
+
if (config && isStorageClient(config)) {
|
|
140
|
+
return config.resolveDriver();
|
|
141
|
+
}
|
|
142
|
+
const driverInput = config?.driver ?? "memory";
|
|
143
|
+
if (typeof driverInput === "function") {
|
|
144
|
+
return await driverInput();
|
|
145
|
+
}
|
|
146
|
+
if (isDriverInstance(driverInput)) {
|
|
147
|
+
return driverInput;
|
|
148
|
+
}
|
|
149
|
+
if (isDatabaseDriverName(driverInput)) {
|
|
150
|
+
return loadDatabaseDriver(config);
|
|
151
|
+
}
|
|
152
|
+
if (driverInput === "local") {
|
|
153
|
+
return loadBuiltinDriver("fs-lite", extractDriverOptions(config));
|
|
154
|
+
}
|
|
155
|
+
return loadBuiltinDriver(
|
|
156
|
+
driverInput,
|
|
157
|
+
extractDriverOptions(config)
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
function createStorageClientFromResolver(resolveDriver2) {
|
|
161
|
+
let driverPromise;
|
|
162
|
+
let storagePromise;
|
|
163
|
+
const ensureDriver = /* @__PURE__ */ __name(async () => {
|
|
164
|
+
driverPromise ?? (driverPromise = Promise.resolve(resolveDriver2()));
|
|
165
|
+
return driverPromise;
|
|
166
|
+
}, "ensureDriver");
|
|
167
|
+
const ensureStorage = /* @__PURE__ */ __name(async () => {
|
|
168
|
+
storagePromise ?? (storagePromise = ensureDriver().then(
|
|
169
|
+
(driver) => (0, import_unstorage.createStorage)({
|
|
170
|
+
driver
|
|
171
|
+
})
|
|
172
|
+
));
|
|
173
|
+
return storagePromise;
|
|
174
|
+
}, "ensureStorage");
|
|
175
|
+
const target = {
|
|
176
|
+
kind: "farm-storage-client",
|
|
177
|
+
ready: ensureStorage,
|
|
178
|
+
createStorage: ensureStorage,
|
|
179
|
+
resolveDriver: ensureDriver
|
|
180
|
+
};
|
|
181
|
+
return new Proxy(target, {
|
|
182
|
+
get(currentTarget, prop, receiver) {
|
|
183
|
+
if (prop === "then") {
|
|
184
|
+
return void 0;
|
|
185
|
+
}
|
|
186
|
+
if (Reflect.has(currentTarget, prop)) {
|
|
187
|
+
return Reflect.get(currentTarget, prop, receiver);
|
|
188
|
+
}
|
|
189
|
+
return (...args) => ensureStorage().then(async (storage) => {
|
|
190
|
+
const member = Reflect.get(storage, prop);
|
|
191
|
+
if (typeof member !== "function") {
|
|
192
|
+
return member;
|
|
193
|
+
}
|
|
194
|
+
const result = Reflect.apply(member, storage, args);
|
|
195
|
+
if (prop === "dispose") {
|
|
196
|
+
return Promise.resolve(result).finally(() => {
|
|
197
|
+
storagePromise = void 0;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
return result;
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
function defineStorageClient(resolveDriver2) {
|
|
206
|
+
return createStorageClientFromResolver(resolveDriver2);
|
|
207
|
+
}
|
|
208
|
+
function createStorageClient(config) {
|
|
209
|
+
return defineStorageClient(() => resolveDriver(config));
|
|
210
|
+
}
|
|
211
|
+
function driverStorage(driver) {
|
|
212
|
+
return defineStorageClient(() => typeof driver === "function" ? driver() : driver);
|
|
213
|
+
}
|
|
214
|
+
function databaseStorage(database, options = {}) {
|
|
215
|
+
return defineStorageClient(async () => {
|
|
216
|
+
const db0DriverModule = await loadModule("unstorage/drivers/db0");
|
|
217
|
+
return db0DriverModule.default({
|
|
218
|
+
database,
|
|
219
|
+
tableName: options.tableName
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
function memoryStorage() {
|
|
224
|
+
return createStorageClient({ driver: "memory" });
|
|
225
|
+
}
|
|
226
|
+
function localStorage(options = {}) {
|
|
227
|
+
return createStorageClient({
|
|
228
|
+
driver: "local",
|
|
229
|
+
...options
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
function sqliteStorage(options) {
|
|
233
|
+
return createStorageClient({
|
|
234
|
+
driver: "sqlite",
|
|
235
|
+
...options
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
function mysqlStorage(options) {
|
|
239
|
+
return createStorageClient({
|
|
240
|
+
driver: "mysql",
|
|
241
|
+
...options
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
function mysql2Storage(options) {
|
|
245
|
+
return mysqlStorage(options);
|
|
246
|
+
}
|
|
247
|
+
function postgresStorage(options) {
|
|
248
|
+
return createStorageClient({
|
|
249
|
+
driver: "postgres",
|
|
250
|
+
...options
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
function pgStorage(options) {
|
|
254
|
+
return postgresStorage(options);
|
|
255
|
+
}
|
|
256
|
+
function pgliteStorage(options) {
|
|
257
|
+
return createStorageClient({
|
|
258
|
+
driver: "pglite",
|
|
259
|
+
...options
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
function planetscaleStorage(options) {
|
|
263
|
+
return createStorageClient({
|
|
264
|
+
driver: "planetscale",
|
|
265
|
+
...options
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
function libsqlStorage(options) {
|
|
269
|
+
return createStorageClient({
|
|
270
|
+
driver: "libsql",
|
|
271
|
+
...options
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
function redisStorage(options) {
|
|
275
|
+
return createStorageClient({
|
|
276
|
+
driver: "redis",
|
|
277
|
+
...options
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
function s3Storage(options) {
|
|
281
|
+
return createStorageClient({
|
|
282
|
+
driver: "s3",
|
|
283
|
+
...options
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
function mongodbStorage(options) {
|
|
287
|
+
return createStorageClient({
|
|
288
|
+
driver: "mongodb",
|
|
289
|
+
...options
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
function upstashStorage(options) {
|
|
293
|
+
return createStorageClient({
|
|
294
|
+
driver: "upstash",
|
|
295
|
+
...options
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
function netlifyBlobsStorage(options) {
|
|
299
|
+
return createStorageClient({
|
|
300
|
+
driver: "netlify-blobs",
|
|
301
|
+
...options
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
function vercelKVStorage(options) {
|
|
305
|
+
return createStorageClient({
|
|
306
|
+
driver: "vercel-kv",
|
|
307
|
+
...options
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
function vercelBlobStorage(options) {
|
|
311
|
+
return createStorageClient({
|
|
312
|
+
driver: "vercel-blob",
|
|
313
|
+
...options
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
async function mountNamespaces(storage, mounts) {
|
|
317
|
+
if (!mounts) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
for (const [base, config] of Object.entries(mounts)) {
|
|
321
|
+
storage.mount(normalizeMountKey(base), await resolveDriver(config));
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
async function createFarmStorage(config = {}) {
|
|
325
|
+
if (isStorageInstance(config)) {
|
|
326
|
+
return config;
|
|
327
|
+
}
|
|
328
|
+
if (isStorageClient(config)) {
|
|
329
|
+
return config.createStorage();
|
|
330
|
+
}
|
|
331
|
+
const rootConfig = isStorageClient(config.client) ? config.client : config;
|
|
332
|
+
const storage = (0, import_unstorage.createStorage)({
|
|
333
|
+
driver: await resolveDriver(rootConfig)
|
|
334
|
+
});
|
|
335
|
+
await mountNamespaces(storage, config.mounts);
|
|
336
|
+
return storage;
|
|
337
|
+
}
|
|
338
|
+
async function resolveStorageRuntimeClient(config) {
|
|
339
|
+
if (!config || isStorageInstance(config) || isStorageClient(config)) {
|
|
340
|
+
return void 0;
|
|
341
|
+
}
|
|
342
|
+
const client = config.client;
|
|
343
|
+
if (!client || isStorageInstance(client) || isStorageClient(client)) {
|
|
344
|
+
return void 0;
|
|
345
|
+
}
|
|
346
|
+
return typeof client === "function" ? await client() : client;
|
|
347
|
+
}
|
|
348
|
+
async function initStorage(config = {}) {
|
|
349
|
+
globalStorage = getActiveGlobalStorage();
|
|
350
|
+
const nextStorage = await createFarmStorage(config);
|
|
351
|
+
const previousStorage = globalStorage;
|
|
352
|
+
globalStorage = writeGlobalStorage(nextStorage);
|
|
353
|
+
if (previousStorage !== nextStorage) {
|
|
354
|
+
await previousStorage.dispose().catch(() => {
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
return globalStorage;
|
|
358
|
+
}
|
|
359
|
+
function getStorage(namespace) {
|
|
360
|
+
globalStorage = getActiveGlobalStorage();
|
|
361
|
+
const base = normalizeMountKey(namespace);
|
|
362
|
+
if (!base) {
|
|
363
|
+
return globalStorage;
|
|
364
|
+
}
|
|
365
|
+
const namespaced = (0, import_unstorage.prefixStorage)(globalStorage, base);
|
|
366
|
+
return {
|
|
367
|
+
...namespaced,
|
|
368
|
+
async clear() {
|
|
369
|
+
const keys = await namespaced.getKeys();
|
|
370
|
+
await Promise.all(keys.map((key) => namespaced.removeItem(key)));
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
async function disposeStorage() {
|
|
375
|
+
globalStorage = getActiveGlobalStorage();
|
|
376
|
+
const previousStorage = globalStorage;
|
|
377
|
+
globalStorage = writeGlobalStorage(createMemoryStorage());
|
|
378
|
+
await previousStorage.dispose().catch(() => {
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
var import_unstorage, import_memory, loadModule, DATABASE_CONNECTORS, GLOBAL_STORAGE_KEY, globalStorage;
|
|
382
|
+
var init_storage = __esm({
|
|
383
|
+
"src/storage/index.ts"() {
|
|
384
|
+
"use strict";
|
|
385
|
+
import_unstorage = require("unstorage");
|
|
386
|
+
import_memory = __toESM(require("unstorage/drivers/memory"));
|
|
387
|
+
loadModule = /* @__PURE__ */ __name((specifier) => import(
|
|
388
|
+
/* @vite-ignore */
|
|
389
|
+
specifier
|
|
390
|
+
), "loadModule");
|
|
391
|
+
DATABASE_CONNECTORS = {
|
|
392
|
+
sqlite: {
|
|
393
|
+
connector: "node-sqlite",
|
|
394
|
+
load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/node-sqlite"), "load")
|
|
395
|
+
},
|
|
396
|
+
"node-sqlite": {
|
|
397
|
+
connector: "node-sqlite",
|
|
398
|
+
load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/node-sqlite"), "load")
|
|
399
|
+
},
|
|
400
|
+
sqlite3: {
|
|
401
|
+
connector: "sqlite3",
|
|
402
|
+
load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/sqlite3"), "load")
|
|
403
|
+
},
|
|
404
|
+
"better-sqlite3": {
|
|
405
|
+
connector: "better-sqlite3",
|
|
406
|
+
load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/better-sqlite3"), "load")
|
|
407
|
+
},
|
|
408
|
+
postgres: {
|
|
409
|
+
connector: "postgresql",
|
|
410
|
+
load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/postgresql"), "load")
|
|
411
|
+
},
|
|
412
|
+
postgresql: {
|
|
413
|
+
connector: "postgresql",
|
|
414
|
+
load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/postgresql"), "load")
|
|
415
|
+
},
|
|
416
|
+
pg: {
|
|
417
|
+
connector: "postgresql",
|
|
418
|
+
load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/postgresql"), "load")
|
|
419
|
+
},
|
|
420
|
+
mysql: {
|
|
421
|
+
connector: "mysql2",
|
|
422
|
+
load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/mysql2"), "load")
|
|
423
|
+
},
|
|
424
|
+
mysql2: {
|
|
425
|
+
connector: "mysql2",
|
|
426
|
+
load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/mysql2"), "load")
|
|
427
|
+
},
|
|
428
|
+
pglite: {
|
|
429
|
+
connector: "pglite",
|
|
430
|
+
load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/pglite"), "load")
|
|
431
|
+
},
|
|
432
|
+
planetscale: {
|
|
433
|
+
connector: "planetscale",
|
|
434
|
+
load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/planetscale"), "load")
|
|
435
|
+
},
|
|
436
|
+
libsql: {
|
|
437
|
+
connector: "libsql",
|
|
438
|
+
load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/libsql/node"), "load")
|
|
439
|
+
},
|
|
440
|
+
"libsql-node": {
|
|
441
|
+
connector: "libsql-node",
|
|
442
|
+
load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/libsql/node"), "load")
|
|
443
|
+
},
|
|
444
|
+
"libsql-http": {
|
|
445
|
+
connector: "libsql-http",
|
|
446
|
+
load: /* @__PURE__ */ __name(() => loadModule("db0/connectors/libsql/http"), "load")
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
__name(createMemoryStorage, "createMemoryStorage");
|
|
450
|
+
GLOBAL_STORAGE_KEY = /* @__PURE__ */ Symbol.for("farmjs.storage.global");
|
|
451
|
+
__name(readGlobalStorage, "readGlobalStorage");
|
|
452
|
+
__name(writeGlobalStorage, "writeGlobalStorage");
|
|
453
|
+
__name(getActiveGlobalStorage, "getActiveGlobalStorage");
|
|
454
|
+
globalStorage = getActiveGlobalStorage();
|
|
455
|
+
__name(normalizeMountKey, "normalizeMountKey");
|
|
456
|
+
__name(isDriverInstance, "isDriverInstance");
|
|
457
|
+
__name(isStorageInstance, "isStorageInstance");
|
|
458
|
+
__name(isStorageClient, "isStorageClient");
|
|
459
|
+
__name(isDatabaseDriverName, "isDatabaseDriverName");
|
|
460
|
+
__name(extractDriverOptions, "extractDriverOptions");
|
|
461
|
+
__name(loadBuiltinDriver, "loadBuiltinDriver");
|
|
462
|
+
__name(loadDatabaseDriver, "loadDatabaseDriver");
|
|
463
|
+
__name(resolveDriver, "resolveDriver");
|
|
464
|
+
__name(createStorageClientFromResolver, "createStorageClientFromResolver");
|
|
465
|
+
__name(defineStorageClient, "defineStorageClient");
|
|
466
|
+
__name(createStorageClient, "createStorageClient");
|
|
467
|
+
__name(driverStorage, "driverStorage");
|
|
468
|
+
__name(databaseStorage, "databaseStorage");
|
|
469
|
+
__name(memoryStorage, "memoryStorage");
|
|
470
|
+
__name(localStorage, "localStorage");
|
|
471
|
+
__name(sqliteStorage, "sqliteStorage");
|
|
472
|
+
__name(mysqlStorage, "mysqlStorage");
|
|
473
|
+
__name(mysql2Storage, "mysql2Storage");
|
|
474
|
+
__name(postgresStorage, "postgresStorage");
|
|
475
|
+
__name(pgStorage, "pgStorage");
|
|
476
|
+
__name(pgliteStorage, "pgliteStorage");
|
|
477
|
+
__name(planetscaleStorage, "planetscaleStorage");
|
|
478
|
+
__name(libsqlStorage, "libsqlStorage");
|
|
479
|
+
__name(redisStorage, "redisStorage");
|
|
480
|
+
__name(s3Storage, "s3Storage");
|
|
481
|
+
__name(mongodbStorage, "mongodbStorage");
|
|
482
|
+
__name(upstashStorage, "upstashStorage");
|
|
483
|
+
__name(netlifyBlobsStorage, "netlifyBlobsStorage");
|
|
484
|
+
__name(vercelKVStorage, "vercelKVStorage");
|
|
485
|
+
__name(vercelBlobStorage, "vercelBlobStorage");
|
|
486
|
+
__name(mountNamespaces, "mountNamespaces");
|
|
487
|
+
__name(createFarmStorage, "createFarmStorage");
|
|
488
|
+
__name(resolveStorageRuntimeClient, "resolveStorageRuntimeClient");
|
|
489
|
+
__name(initStorage, "initStorage");
|
|
490
|
+
__name(getStorage, "getStorage");
|
|
491
|
+
__name(disposeStorage, "disposeStorage");
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
// src/integration-orm.ts
|
|
496
|
+
var integration_orm_exports = {};
|
|
497
|
+
__export(integration_orm_exports, {
|
|
498
|
+
createIntegrationOrm: () => createIntegrationOrm,
|
|
499
|
+
farmIntegrationSchemaToOrmSchema: () => farmIntegrationSchemaToOrmSchema,
|
|
500
|
+
resolveIntegrationOrmRuntimeClient: () => resolveIntegrationOrmRuntimeClient
|
|
501
|
+
});
|
|
502
|
+
async function createIntegrationOrm(options) {
|
|
503
|
+
const [schema, client] = await Promise.all([
|
|
504
|
+
farmIntegrationSchemaToOrmSchema(options.schema),
|
|
505
|
+
resolveIntegrationOrmRuntimeClient(options)
|
|
506
|
+
]);
|
|
507
|
+
if (!client) {
|
|
508
|
+
throw new Error(
|
|
509
|
+
"Schema-backed integration storage requires a runtime client at farm.config storage.client."
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
const { createOrmFromRuntime } = await import("@farming-labs/orm-runtime");
|
|
513
|
+
return createOrmFromRuntime({
|
|
514
|
+
schema,
|
|
515
|
+
client
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
async function resolveIntegrationOrmRuntimeClient(options) {
|
|
519
|
+
if (options.client !== void 0) {
|
|
520
|
+
return typeof options.client === "function" ? await options.client() : options.client;
|
|
521
|
+
}
|
|
522
|
+
return resolveStorageRuntimeClient(options.storage ?? options.config?.storage);
|
|
523
|
+
}
|
|
524
|
+
async function farmIntegrationSchemaToOrmSchema(schema) {
|
|
525
|
+
const orm = await import("@farming-labs/orm");
|
|
526
|
+
const models = {};
|
|
527
|
+
for (const [modelKey, modelSchema] of Object.entries(schema.models)) {
|
|
528
|
+
models[modelKey] = orm.model({
|
|
529
|
+
table: modelSchema.name ?? modelKey,
|
|
530
|
+
fields: createOrmModelFields(orm, modelSchema),
|
|
531
|
+
constraints: createOrmModelConstraints(modelSchema),
|
|
532
|
+
description: modelSchema.description
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
return orm.defineSchema(models);
|
|
536
|
+
}
|
|
537
|
+
function createOrmModelFields(orm, modelSchema) {
|
|
538
|
+
return Object.fromEntries(
|
|
539
|
+
Object.entries(modelSchema.fields).map(([fieldKey, fieldSchema]) => [
|
|
540
|
+
fieldKey,
|
|
541
|
+
createOrmField(orm, fieldKey, fieldSchema)
|
|
542
|
+
])
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
function createOrmField(orm, fieldKey, field) {
|
|
546
|
+
let builder = createOrmFieldBuilder(orm, fieldKey, field);
|
|
547
|
+
if (field.unique) {
|
|
548
|
+
builder = builder.unique();
|
|
549
|
+
}
|
|
550
|
+
if (field.nullable || field.required === false) {
|
|
551
|
+
builder = builder.nullable();
|
|
552
|
+
}
|
|
553
|
+
if (field.default !== void 0) {
|
|
554
|
+
builder = field.type === "datetime" && field.default === "now" ? builder.defaultNow() : builder.default(field.default);
|
|
555
|
+
}
|
|
556
|
+
if (field.reference) {
|
|
557
|
+
builder = builder.references(`${field.reference.model}.${field.reference.field}`);
|
|
558
|
+
}
|
|
559
|
+
if (field.name && field.name !== fieldKey) {
|
|
560
|
+
builder = builder.map(field.name);
|
|
561
|
+
}
|
|
562
|
+
if (field.description) {
|
|
563
|
+
builder = builder.describe(field.description);
|
|
564
|
+
}
|
|
565
|
+
return builder;
|
|
566
|
+
}
|
|
567
|
+
function createOrmFieldBuilder(orm, fieldKey, field) {
|
|
568
|
+
switch (field.type) {
|
|
569
|
+
case "id":
|
|
570
|
+
case "uuid":
|
|
571
|
+
return orm.id();
|
|
572
|
+
case "string":
|
|
573
|
+
case "text":
|
|
574
|
+
return orm.string();
|
|
575
|
+
case "boolean":
|
|
576
|
+
return orm.boolean();
|
|
577
|
+
case "integer":
|
|
578
|
+
return orm.integer();
|
|
579
|
+
case "number":
|
|
580
|
+
return orm.decimal();
|
|
581
|
+
case "datetime":
|
|
582
|
+
return orm.datetime();
|
|
583
|
+
case "json":
|
|
584
|
+
return orm.json();
|
|
585
|
+
case "enum": {
|
|
586
|
+
if (!field.values?.length) {
|
|
587
|
+
throw new Error(`Integration schema enum field "${fieldKey}" must define values.`);
|
|
588
|
+
}
|
|
589
|
+
return orm.enumeration(field.values);
|
|
590
|
+
}
|
|
591
|
+
default:
|
|
592
|
+
throw new Error(
|
|
593
|
+
`Unsupported integration schema field type "${field.type}" for "${fieldKey}".`
|
|
594
|
+
);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
function createOrmModelConstraints(modelSchema) {
|
|
598
|
+
const unique = [];
|
|
599
|
+
const indexes = [];
|
|
600
|
+
for (const constraint of modelSchema.constraints ?? []) {
|
|
601
|
+
if (!constraint.fields.length) {
|
|
602
|
+
continue;
|
|
603
|
+
}
|
|
604
|
+
const fields = constraint.fields;
|
|
605
|
+
if (constraint.type === "unique") {
|
|
606
|
+
unique.push(fields);
|
|
607
|
+
} else {
|
|
608
|
+
indexes.push(fields);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
return {
|
|
612
|
+
unique,
|
|
613
|
+
indexes
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
var init_integration_orm = __esm({
|
|
617
|
+
"src/integration-orm.ts"() {
|
|
618
|
+
"use strict";
|
|
619
|
+
init_storage();
|
|
620
|
+
__name(createIntegrationOrm, "createIntegrationOrm");
|
|
621
|
+
__name(resolveIntegrationOrmRuntimeClient, "resolveIntegrationOrmRuntimeClient");
|
|
622
|
+
__name(farmIntegrationSchemaToOrmSchema, "farmIntegrationSchemaToOrmSchema");
|
|
623
|
+
__name(createOrmModelFields, "createOrmModelFields");
|
|
624
|
+
__name(createOrmField, "createOrmField");
|
|
625
|
+
__name(createOrmFieldBuilder, "createOrmFieldBuilder");
|
|
626
|
+
__name(createOrmModelConstraints, "createOrmModelConstraints");
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
// src/config-runtime.ts
|
|
631
|
+
var config_runtime_exports = {};
|
|
632
|
+
__export(config_runtime_exports, {
|
|
633
|
+
loadConfig: () => loadConfig,
|
|
634
|
+
loadFarmProductionVite: () => loadFarmProductionVite,
|
|
635
|
+
logger: () => logger,
|
|
636
|
+
resolveConfig: () => resolveConfig,
|
|
637
|
+
resolveDeployConfig: () => resolveDeployConfig
|
|
638
|
+
});
|
|
639
|
+
module.exports = __toCommonJS(config_runtime_exports);
|
|
640
|
+
|
|
641
|
+
// src/integration-api.ts
|
|
642
|
+
function defineIntegrationAPIOperation(operation) {
|
|
643
|
+
return {
|
|
644
|
+
kind: "farm-integration-api-operation",
|
|
645
|
+
...operation
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
__name(defineIntegrationAPIOperation, "defineIntegrationAPIOperation");
|
|
649
|
+
|
|
650
|
+
// src/request-context.ts
|
|
651
|
+
var REQUEST_CONTEXT_STORE_KEY = /* @__PURE__ */ Symbol.for("farm.requestContextStore");
|
|
652
|
+
function getRequestContextStore() {
|
|
653
|
+
const globalState2 = globalThis;
|
|
654
|
+
if (!globalState2[REQUEST_CONTEXT_STORE_KEY]) {
|
|
655
|
+
globalState2[REQUEST_CONTEXT_STORE_KEY] = /* @__PURE__ */ new WeakMap();
|
|
656
|
+
}
|
|
657
|
+
return globalState2[REQUEST_CONTEXT_STORE_KEY];
|
|
658
|
+
}
|
|
659
|
+
__name(getRequestContextStore, "getRequestContextStore");
|
|
660
|
+
function getBucket(target) {
|
|
661
|
+
const requestContextStore = getRequestContextStore();
|
|
662
|
+
let bucket = requestContextStore.get(target);
|
|
663
|
+
if (!bucket) {
|
|
664
|
+
bucket = {
|
|
665
|
+
privateData: /* @__PURE__ */ new Map(),
|
|
666
|
+
exposedData: /* @__PURE__ */ new Map()
|
|
667
|
+
};
|
|
668
|
+
requestContextStore.set(target, bucket);
|
|
669
|
+
}
|
|
670
|
+
return bucket;
|
|
671
|
+
}
|
|
672
|
+
__name(getBucket, "getBucket");
|
|
673
|
+
function setRequestContext(target, key, value, options = {}) {
|
|
674
|
+
const bucket = getBucket(target);
|
|
675
|
+
bucket.privateData.set(key, value);
|
|
676
|
+
if (options.exposeToPage) {
|
|
677
|
+
bucket.exposedData.set(key, value);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
__name(setRequestContext, "setRequestContext");
|
|
681
|
+
function getRequestContext(target, key) {
|
|
682
|
+
const requestContextStore = getRequestContextStore();
|
|
683
|
+
const bucket = requestContextStore.get(target);
|
|
684
|
+
return bucket?.privateData.get(key);
|
|
685
|
+
}
|
|
686
|
+
__name(getRequestContext, "getRequestContext");
|
|
687
|
+
function hasRequestContext(target, key) {
|
|
688
|
+
const requestContextStore = getRequestContextStore();
|
|
689
|
+
const bucket = requestContextStore.get(target);
|
|
690
|
+
return bucket?.privateData.has(key) ?? false;
|
|
691
|
+
}
|
|
692
|
+
__name(hasRequestContext, "hasRequestContext");
|
|
693
|
+
function deleteRequestContext(target, key) {
|
|
694
|
+
const requestContextStore = getRequestContextStore();
|
|
695
|
+
const bucket = requestContextStore.get(target);
|
|
696
|
+
if (!bucket) return false;
|
|
697
|
+
const removedPrivate = bucket.privateData.delete(key);
|
|
698
|
+
bucket.exposedData.delete(key);
|
|
699
|
+
return removedPrivate;
|
|
700
|
+
}
|
|
701
|
+
__name(deleteRequestContext, "deleteRequestContext");
|
|
702
|
+
function clearRequestContext(target) {
|
|
703
|
+
const requestContextStore = getRequestContextStore();
|
|
704
|
+
const bucket = requestContextStore.get(target);
|
|
705
|
+
if (!bucket) return;
|
|
706
|
+
bucket.privateData.clear();
|
|
707
|
+
bucket.exposedData.clear();
|
|
708
|
+
}
|
|
709
|
+
__name(clearRequestContext, "clearRequestContext");
|
|
710
|
+
function getRequestContextSnapshot(target, options = {}) {
|
|
711
|
+
const requestContextStore = getRequestContextStore();
|
|
712
|
+
const bucket = requestContextStore.get(target);
|
|
713
|
+
if (!bucket) return /* @__PURE__ */ new Map();
|
|
714
|
+
if (options.exposedOnly) {
|
|
715
|
+
return new Map(bucket.exposedData);
|
|
716
|
+
}
|
|
717
|
+
return new Map(bucket.privateData);
|
|
718
|
+
}
|
|
719
|
+
__name(getRequestContextSnapshot, "getRequestContextSnapshot");
|
|
720
|
+
|
|
721
|
+
// src/server/response.ts
|
|
722
|
+
var import_node_events = require("events");
|
|
723
|
+
async function sendWebResponse(res, response) {
|
|
724
|
+
res.statusCode = response.status;
|
|
725
|
+
const responseHeaders = response.headers;
|
|
726
|
+
const setCookies = responseHeaders.getSetCookie?.() || [];
|
|
727
|
+
if (setCookies.length > 0) {
|
|
728
|
+
res.setHeader("Set-Cookie", setCookies);
|
|
729
|
+
}
|
|
730
|
+
response.headers.forEach((value, key) => {
|
|
731
|
+
if (key.toLowerCase() === "set-cookie" && setCookies.length > 0) {
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
res.setHeader(key, value);
|
|
735
|
+
});
|
|
736
|
+
if (!response.body) {
|
|
737
|
+
res.end();
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
if (typeof res.write !== "function") {
|
|
741
|
+
const body = await response.arrayBuffer();
|
|
742
|
+
res.end(Buffer.from(body));
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
const reader = response.body.getReader();
|
|
746
|
+
try {
|
|
747
|
+
while (true) {
|
|
748
|
+
const { done, value } = await reader.read();
|
|
749
|
+
if (done) {
|
|
750
|
+
break;
|
|
751
|
+
}
|
|
752
|
+
if (!value || value.byteLength === 0) {
|
|
753
|
+
continue;
|
|
754
|
+
}
|
|
755
|
+
if (!res.write(value)) {
|
|
756
|
+
await (0, import_node_events.once)(res, "drain");
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
res.end();
|
|
760
|
+
} catch (error) {
|
|
761
|
+
if (!res.writableEnded) {
|
|
762
|
+
const responseError = error instanceof Error ? error : new Error(String(error));
|
|
763
|
+
if (typeof res.destroy === "function") {
|
|
764
|
+
res.destroy(responseError);
|
|
765
|
+
} else {
|
|
766
|
+
res.end();
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
throw error;
|
|
770
|
+
} finally {
|
|
771
|
+
reader.releaseLock();
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
__name(sendWebResponse, "sendWebResponse");
|
|
775
|
+
|
|
776
|
+
// src/integrations.ts
|
|
777
|
+
var FARM_INTEGRATION_INTERNAL_DISPATCH_CONTEXT_KEY = "farm.integration.internalDispatch";
|
|
778
|
+
var FARM_INTEGRATION_PLUGIN_SERVER_RUNTIME = /* @__PURE__ */ Symbol.for(
|
|
779
|
+
"@farm.js/core/integration-plugin-server-runtime"
|
|
780
|
+
);
|
|
781
|
+
function defineTypedIntegrationRoute(method, path4, input) {
|
|
782
|
+
return {
|
|
783
|
+
path: path4,
|
|
784
|
+
method,
|
|
785
|
+
middleware: input.middleware,
|
|
786
|
+
before: input.before,
|
|
787
|
+
after: input.after,
|
|
788
|
+
rawBody: input.rawBody,
|
|
789
|
+
bodyFormat: input.bodyFormat,
|
|
790
|
+
input: normalizeIntegrationRouteInputSchemas(input),
|
|
791
|
+
handler: input.handler,
|
|
792
|
+
__operation: defineIntegrationAPIOperation({
|
|
793
|
+
path: path4,
|
|
794
|
+
method,
|
|
795
|
+
bodyFormat: input.bodyFormat,
|
|
796
|
+
responseFormat: input.responseFormat,
|
|
797
|
+
headers: input.headers,
|
|
798
|
+
credentials: input.credentials,
|
|
799
|
+
isServer: input.isServer
|
|
800
|
+
})
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
__name(defineTypedIntegrationRoute, "defineTypedIntegrationRoute");
|
|
804
|
+
function createIntegrationRouteFactory() {
|
|
805
|
+
return {
|
|
806
|
+
get(path4, input) {
|
|
807
|
+
return defineTypedIntegrationRoute(
|
|
808
|
+
"GET",
|
|
809
|
+
path4,
|
|
810
|
+
input
|
|
811
|
+
);
|
|
812
|
+
},
|
|
813
|
+
post(path4, input) {
|
|
814
|
+
return defineTypedIntegrationRoute(
|
|
815
|
+
"POST",
|
|
816
|
+
path4,
|
|
817
|
+
{
|
|
818
|
+
bodyFormat: "json",
|
|
819
|
+
...input
|
|
820
|
+
}
|
|
821
|
+
);
|
|
822
|
+
},
|
|
823
|
+
put(path4, input) {
|
|
824
|
+
return defineTypedIntegrationRoute(
|
|
825
|
+
"PUT",
|
|
826
|
+
path4,
|
|
827
|
+
{
|
|
828
|
+
bodyFormat: "json",
|
|
829
|
+
...input
|
|
830
|
+
}
|
|
831
|
+
);
|
|
832
|
+
},
|
|
833
|
+
patch(path4, input) {
|
|
834
|
+
return defineTypedIntegrationRoute("PATCH", path4, {
|
|
835
|
+
bodyFormat: "json",
|
|
836
|
+
...input
|
|
837
|
+
});
|
|
838
|
+
},
|
|
839
|
+
delete(path4, input) {
|
|
840
|
+
return defineTypedIntegrationRoute("DELETE", path4, {
|
|
841
|
+
bodyFormat: "json",
|
|
842
|
+
...input
|
|
843
|
+
});
|
|
844
|
+
},
|
|
845
|
+
options(path4, input) {
|
|
846
|
+
return defineTypedIntegrationRoute("OPTIONS", path4, input);
|
|
847
|
+
},
|
|
848
|
+
head(path4, input) {
|
|
849
|
+
return defineTypedIntegrationRoute(
|
|
850
|
+
"HEAD",
|
|
851
|
+
path4,
|
|
852
|
+
input
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
__name(createIntegrationRouteFactory, "createIntegrationRouteFactory");
|
|
858
|
+
var integrationRoute = createIntegrationRouteFactory();
|
|
859
|
+
var INTEGRATION_RUNTIME_REGISTRY_KEY = /* @__PURE__ */ Symbol.for("farm.integrationRuntimeRegistry");
|
|
860
|
+
var INTEGRATION_REQUEST_DISPATCHER_KEY = /* @__PURE__ */ Symbol.for("farm.integrationRequestDispatcher");
|
|
861
|
+
function getIntegrationRuntimeRegistry() {
|
|
862
|
+
const globalState2 = globalThis;
|
|
863
|
+
if (!globalState2[INTEGRATION_RUNTIME_REGISTRY_KEY]) {
|
|
864
|
+
globalState2[INTEGRATION_RUNTIME_REGISTRY_KEY] = /* @__PURE__ */ new Map();
|
|
865
|
+
}
|
|
866
|
+
return globalState2[INTEGRATION_RUNTIME_REGISTRY_KEY];
|
|
867
|
+
}
|
|
868
|
+
__name(getIntegrationRuntimeRegistry, "getIntegrationRuntimeRegistry");
|
|
869
|
+
function isFarmIntegration(value) {
|
|
870
|
+
return !!value && typeof value === "object" && value.kind === "farm-integration";
|
|
871
|
+
}
|
|
872
|
+
__name(isFarmIntegration, "isFarmIntegration");
|
|
873
|
+
function resolveIntegrationPlugins(integrations) {
|
|
874
|
+
if (!integrations) {
|
|
875
|
+
return [];
|
|
876
|
+
}
|
|
877
|
+
const plugins = [];
|
|
878
|
+
for (const [key, integration] of Object.entries(integrations)) {
|
|
879
|
+
if (!integration || !isFarmIntegration(integration)) {
|
|
880
|
+
continue;
|
|
881
|
+
}
|
|
882
|
+
plugins.push(createIntegrationPlugin(key, integration));
|
|
883
|
+
if (integration.plugins?.length) {
|
|
884
|
+
plugins.push(...integration.plugins);
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
return plugins;
|
|
888
|
+
}
|
|
889
|
+
__name(resolveIntegrationPlugins, "resolveIntegrationPlugins");
|
|
890
|
+
function getIntegrationRuntimeEnv() {
|
|
891
|
+
return typeof process !== "undefined" ? process.env : {};
|
|
892
|
+
}
|
|
893
|
+
__name(getIntegrationRuntimeEnv, "getIntegrationRuntimeEnv");
|
|
894
|
+
function isIntegrationConfigDefinition(value) {
|
|
895
|
+
return !!value && typeof value === "object" && ("schema" in value || "env" in value || "defaults" in value || "input" in value || "resolve" in value);
|
|
896
|
+
}
|
|
897
|
+
__name(isIntegrationConfigDefinition, "isIntegrationConfigDefinition");
|
|
898
|
+
function mergeIntegrationConfigValue(current, next) {
|
|
899
|
+
if (next === void 0) {
|
|
900
|
+
return current;
|
|
901
|
+
}
|
|
902
|
+
if (isPlainIntegrationConfigObject(current) && isPlainIntegrationConfigObject(next)) {
|
|
903
|
+
return {
|
|
904
|
+
...current,
|
|
905
|
+
...next
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
return next;
|
|
909
|
+
}
|
|
910
|
+
__name(mergeIntegrationConfigValue, "mergeIntegrationConfigValue");
|
|
911
|
+
function isPlainIntegrationConfigObject(value) {
|
|
912
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
913
|
+
}
|
|
914
|
+
__name(isPlainIntegrationConfigObject, "isPlainIntegrationConfigObject");
|
|
915
|
+
async function resolveIntegrationConfigPart(value, context) {
|
|
916
|
+
if (typeof value === "function") {
|
|
917
|
+
return value(context);
|
|
918
|
+
}
|
|
919
|
+
return value;
|
|
920
|
+
}
|
|
921
|
+
__name(resolveIntegrationConfigPart, "resolveIntegrationConfigPart");
|
|
922
|
+
function resolveIntegrationEnvConfig(env2) {
|
|
923
|
+
if (!env2) {
|
|
924
|
+
return void 0;
|
|
925
|
+
}
|
|
926
|
+
const runtimeEnv = getIntegrationRuntimeEnv();
|
|
927
|
+
const config = {};
|
|
928
|
+
for (const [key, names] of Object.entries(env2)) {
|
|
929
|
+
const envNames = Array.isArray(names) ? names : [names];
|
|
930
|
+
const value = envNames.map((name) => runtimeEnv[name]).find((entry) => entry !== void 0);
|
|
931
|
+
if (value !== void 0) {
|
|
932
|
+
config[key] = value;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
return config;
|
|
936
|
+
}
|
|
937
|
+
__name(resolveIntegrationEnvConfig, "resolveIntegrationEnvConfig");
|
|
938
|
+
async function parseIntegrationConfigSchema(integration, schema, value) {
|
|
939
|
+
const parser = schema.safeParseAsync || schema.safeParse;
|
|
940
|
+
if (parser) {
|
|
941
|
+
const result = await parser.call(schema, value);
|
|
942
|
+
if (result.success) {
|
|
943
|
+
return result.data;
|
|
944
|
+
}
|
|
945
|
+
throw createIntegrationConfigValidationError(integration, result.error);
|
|
946
|
+
}
|
|
947
|
+
if (schema["~standard"]?.validate) {
|
|
948
|
+
const result = await schema["~standard"].validate(value);
|
|
949
|
+
if ("value" in result) {
|
|
950
|
+
return result.value;
|
|
951
|
+
}
|
|
952
|
+
throw createIntegrationConfigValidationError(integration, {
|
|
953
|
+
issues: result.issues
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
if (schema.parse) {
|
|
957
|
+
try {
|
|
958
|
+
return await schema.parse(value);
|
|
959
|
+
} catch (error) {
|
|
960
|
+
throw createIntegrationConfigValidationError(
|
|
961
|
+
integration,
|
|
962
|
+
normalizeIntegrationValidationError(error)
|
|
963
|
+
);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
throw new Error(
|
|
967
|
+
`Integration "${integration.type}" config schema must expose safeParse, safeParseAsync, parse, or ~standard.validate.`
|
|
968
|
+
);
|
|
969
|
+
}
|
|
970
|
+
__name(parseIntegrationConfigSchema, "parseIntegrationConfigSchema");
|
|
971
|
+
function createIntegrationConfigValidationError(integration, error) {
|
|
972
|
+
const issues = Array.isArray(error.issues) && error.issues.length > 0 ? error.issues.map((issue) => {
|
|
973
|
+
const normalizedPath = normalizeIntegrationValidationPath(issue.path);
|
|
974
|
+
const path4 = normalizedPath.length ? `${normalizedPath.join(".")}: ` : "";
|
|
975
|
+
return `${path4}${issue.message || "Invalid config"}`;
|
|
976
|
+
}).join("; ") : error.message || "Invalid config";
|
|
977
|
+
return new Error(`Integration "${integration.type}" config validation failed: ${issues}`);
|
|
978
|
+
}
|
|
979
|
+
__name(createIntegrationConfigValidationError, "createIntegrationConfigValidationError");
|
|
980
|
+
async function resolveIntegrationConfig(integration, context) {
|
|
981
|
+
const config = integration.config;
|
|
982
|
+
if (!config) {
|
|
983
|
+
return void 0;
|
|
984
|
+
}
|
|
985
|
+
if (!isIntegrationConfigDefinition(config)) {
|
|
986
|
+
return parseIntegrationConfigSchema(integration, config, {});
|
|
987
|
+
}
|
|
988
|
+
let value = {};
|
|
989
|
+
value = mergeIntegrationConfigValue(
|
|
990
|
+
value,
|
|
991
|
+
await resolveIntegrationConfigPart(config.defaults, context)
|
|
992
|
+
);
|
|
993
|
+
value = mergeIntegrationConfigValue(value, resolveIntegrationEnvConfig(config.env));
|
|
994
|
+
value = mergeIntegrationConfigValue(
|
|
995
|
+
value,
|
|
996
|
+
await resolveIntegrationConfigPart(config.input, context)
|
|
997
|
+
);
|
|
998
|
+
value = mergeIntegrationConfigValue(value, await config.resolve?.(context));
|
|
999
|
+
return config.schema ? parseIntegrationConfigSchema(integration, config.schema, value) : value;
|
|
1000
|
+
}
|
|
1001
|
+
__name(resolveIntegrationConfig, "resolveIntegrationConfig");
|
|
1002
|
+
function createIntegrationLifecycleLogger(integration, phase) {
|
|
1003
|
+
const write = /* @__PURE__ */ __name((level, message, meta) => {
|
|
1004
|
+
if (!integration.log) {
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
void Promise.resolve(
|
|
1008
|
+
integration.log({
|
|
1009
|
+
category: integration.category,
|
|
1010
|
+
slot: integration.category,
|
|
1011
|
+
type: integration.type,
|
|
1012
|
+
phase,
|
|
1013
|
+
level,
|
|
1014
|
+
message,
|
|
1015
|
+
meta,
|
|
1016
|
+
context: /* @__PURE__ */ new Map()
|
|
1017
|
+
})
|
|
1018
|
+
).catch(() => {
|
|
1019
|
+
});
|
|
1020
|
+
}, "write");
|
|
1021
|
+
return {
|
|
1022
|
+
info(message, meta) {
|
|
1023
|
+
write("info", message, meta);
|
|
1024
|
+
},
|
|
1025
|
+
warn(message, meta) {
|
|
1026
|
+
write("warn", message, meta);
|
|
1027
|
+
},
|
|
1028
|
+
error(message, meta) {
|
|
1029
|
+
write("error", message, meta);
|
|
1030
|
+
}
|
|
1031
|
+
};
|
|
1032
|
+
}
|
|
1033
|
+
__name(createIntegrationLifecycleLogger, "createIntegrationLifecycleLogger");
|
|
1034
|
+
var INTEGRATION_DATA_HEADER = "x-farm-integration-data";
|
|
1035
|
+
var INTEGRATION_DATA_HEADER_MAX_LENGTH = 16 * 1024;
|
|
1036
|
+
var BLOCKED_INTEGRATION_DATA_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
1037
|
+
function isFarmIntegrationData(value) {
|
|
1038
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
1039
|
+
}
|
|
1040
|
+
__name(isFarmIntegrationData, "isFarmIntegrationData");
|
|
1041
|
+
function isPlainIntegrationDataObject(value) {
|
|
1042
|
+
if (!isFarmIntegrationData(value)) {
|
|
1043
|
+
return false;
|
|
1044
|
+
}
|
|
1045
|
+
const prototype = Object.getPrototypeOf(value);
|
|
1046
|
+
return prototype === Object.prototype || prototype === null;
|
|
1047
|
+
}
|
|
1048
|
+
__name(isPlainIntegrationDataObject, "isPlainIntegrationDataObject");
|
|
1049
|
+
function sanitizeIntegrationDataValue(value) {
|
|
1050
|
+
if (Array.isArray(value)) {
|
|
1051
|
+
return value.map((item) => sanitizeIntegrationDataValue(item));
|
|
1052
|
+
}
|
|
1053
|
+
if (!isPlainIntegrationDataObject(value)) {
|
|
1054
|
+
return value;
|
|
1055
|
+
}
|
|
1056
|
+
const sanitized = {};
|
|
1057
|
+
for (const [key, item] of Object.entries(value)) {
|
|
1058
|
+
if (BLOCKED_INTEGRATION_DATA_KEYS.has(key)) {
|
|
1059
|
+
continue;
|
|
1060
|
+
}
|
|
1061
|
+
sanitized[key] = sanitizeIntegrationDataValue(item);
|
|
1062
|
+
}
|
|
1063
|
+
return sanitized;
|
|
1064
|
+
}
|
|
1065
|
+
__name(sanitizeIntegrationDataValue, "sanitizeIntegrationDataValue");
|
|
1066
|
+
function normalizeIntegrationData(value) {
|
|
1067
|
+
if (!isFarmIntegrationData(value)) {
|
|
1068
|
+
return {};
|
|
1069
|
+
}
|
|
1070
|
+
const sanitized = sanitizeIntegrationDataValue(value);
|
|
1071
|
+
return isFarmIntegrationData(sanitized) ? sanitized : {};
|
|
1072
|
+
}
|
|
1073
|
+
__name(normalizeIntegrationData, "normalizeIntegrationData");
|
|
1074
|
+
function getIntegrationDataHeaderByteLength(value) {
|
|
1075
|
+
return new TextEncoder().encode(value).byteLength;
|
|
1076
|
+
}
|
|
1077
|
+
__name(getIntegrationDataHeaderByteLength, "getIntegrationDataHeaderByteLength");
|
|
1078
|
+
function parseIntegrationDataHeader(request) {
|
|
1079
|
+
const raw = request.headers.get(INTEGRATION_DATA_HEADER);
|
|
1080
|
+
if (!raw) {
|
|
1081
|
+
return {};
|
|
1082
|
+
}
|
|
1083
|
+
if (getIntegrationDataHeaderByteLength(raw) > INTEGRATION_DATA_HEADER_MAX_LENGTH) {
|
|
1084
|
+
return {};
|
|
1085
|
+
}
|
|
1086
|
+
try {
|
|
1087
|
+
const value = JSON.parse(raw);
|
|
1088
|
+
return normalizeIntegrationData(value);
|
|
1089
|
+
} catch {
|
|
1090
|
+
return {};
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
__name(parseIntegrationDataHeader, "parseIntegrationDataHeader");
|
|
1094
|
+
function resolveIntegrationData(request, data) {
|
|
1095
|
+
return {
|
|
1096
|
+
...parseIntegrationDataHeader(request),
|
|
1097
|
+
...normalizeIntegrationData(data)
|
|
1098
|
+
};
|
|
1099
|
+
}
|
|
1100
|
+
__name(resolveIntegrationData, "resolveIntegrationData");
|
|
1101
|
+
function createIntegrationPlugin(integrationKey, integration) {
|
|
1102
|
+
const routes = normalizeIntegrationRoutes(integration.routes || []);
|
|
1103
|
+
const middleware = [...integration.middleware || []];
|
|
1104
|
+
const cleanupCallbacks = [];
|
|
1105
|
+
let integrationConfigPromise;
|
|
1106
|
+
const runCleanup = /* @__PURE__ */ __name(async () => {
|
|
1107
|
+
const callbacks = cleanupCallbacks.splice(0).reverse();
|
|
1108
|
+
for (const callback of callbacks) {
|
|
1109
|
+
await callback();
|
|
1110
|
+
}
|
|
1111
|
+
}, "runCleanup");
|
|
1112
|
+
const createLifecycleContext = /* @__PURE__ */ __name(async (context, phase, options = {}) => {
|
|
1113
|
+
const args = createIntegrationRouteArgs({
|
|
1114
|
+
integration,
|
|
1115
|
+
config: context.config
|
|
1116
|
+
});
|
|
1117
|
+
const configContext = {
|
|
1118
|
+
key: integrationKey,
|
|
1119
|
+
integration,
|
|
1120
|
+
appConfig: context.config,
|
|
1121
|
+
config: context.config,
|
|
1122
|
+
args,
|
|
1123
|
+
env: getIntegrationRuntimeEnv(),
|
|
1124
|
+
isDev: context.isDev,
|
|
1125
|
+
isProd: context.isProd
|
|
1126
|
+
};
|
|
1127
|
+
integrationConfigPromise ?? (integrationConfigPromise = resolveIntegrationConfig(integration, configContext));
|
|
1128
|
+
return {
|
|
1129
|
+
...configContext,
|
|
1130
|
+
integrationConfig: await integrationConfigPromise,
|
|
1131
|
+
log: createIntegrationLifecycleLogger(integration, phase),
|
|
1132
|
+
reason: options.reason,
|
|
1133
|
+
async cleanup(callback) {
|
|
1134
|
+
if (callback) {
|
|
1135
|
+
cleanupCallbacks.push(callback);
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1138
|
+
await runCleanup();
|
|
1139
|
+
}
|
|
1140
|
+
};
|
|
1141
|
+
}, "createLifecycleContext");
|
|
1142
|
+
const plugin = {
|
|
1143
|
+
name: `farm:integration:${integration.category}:${integration.type}`,
|
|
1144
|
+
enforce: "pre",
|
|
1145
|
+
async init(context) {
|
|
1146
|
+
getIntegrationRuntimeRegistry().set(integrationKey, {
|
|
1147
|
+
integration,
|
|
1148
|
+
config: context.config,
|
|
1149
|
+
isDev: context.isDev,
|
|
1150
|
+
isProd: context.isProd
|
|
1151
|
+
});
|
|
1152
|
+
await createLifecycleContext(context, "validate");
|
|
1153
|
+
if (integration.validate) {
|
|
1154
|
+
await integration.validate(await createLifecycleContext(context, "validate"));
|
|
1155
|
+
}
|
|
1156
|
+
if (integration.setup) {
|
|
1157
|
+
await integration.setup(await createLifecycleContext(context, "setup"));
|
|
1158
|
+
}
|
|
1159
|
+
if (!integration.log) {
|
|
1160
|
+
return;
|
|
1161
|
+
}
|
|
1162
|
+
for (const route of routes) {
|
|
1163
|
+
await integration.log({
|
|
1164
|
+
category: integration.category,
|
|
1165
|
+
slot: integration.category,
|
|
1166
|
+
type: integration.type,
|
|
1167
|
+
phase: "registered",
|
|
1168
|
+
route: {
|
|
1169
|
+
kind: "route",
|
|
1170
|
+
path: route.path,
|
|
1171
|
+
methods: route.methods
|
|
1172
|
+
},
|
|
1173
|
+
context: /* @__PURE__ */ new Map()
|
|
1174
|
+
});
|
|
1175
|
+
}
|
|
1176
|
+
for (const entry of middleware) {
|
|
1177
|
+
await integration.log({
|
|
1178
|
+
category: integration.category,
|
|
1179
|
+
slot: integration.category,
|
|
1180
|
+
type: integration.type,
|
|
1181
|
+
phase: "registered",
|
|
1182
|
+
route: {
|
|
1183
|
+
kind: "middleware",
|
|
1184
|
+
path: normalizeMatcher(entry.matcher),
|
|
1185
|
+
methods: ["ALL"]
|
|
1186
|
+
},
|
|
1187
|
+
context: /* @__PURE__ */ new Map()
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
},
|
|
1191
|
+
async ready(context) {
|
|
1192
|
+
if (integration.ready) {
|
|
1193
|
+
await integration.ready(await createLifecycleContext(context, "ready"));
|
|
1194
|
+
}
|
|
1195
|
+
},
|
|
1196
|
+
async shutdown(payload, context) {
|
|
1197
|
+
try {
|
|
1198
|
+
if (integration.dispose) {
|
|
1199
|
+
await integration.dispose(
|
|
1200
|
+
await createLifecycleContext(context, "dispose", {
|
|
1201
|
+
reason: payload.reason
|
|
1202
|
+
})
|
|
1203
|
+
);
|
|
1204
|
+
}
|
|
1205
|
+
} finally {
|
|
1206
|
+
await runCleanup();
|
|
1207
|
+
}
|
|
1208
|
+
},
|
|
1209
|
+
async beforeRequest(req, res, context) {
|
|
1210
|
+
const fullUrl = `http://${req.headers.host || "localhost"}${req.url || "/"}`;
|
|
1211
|
+
const url = new URL(fullUrl);
|
|
1212
|
+
const pathname = url.pathname;
|
|
1213
|
+
const requestId = getRequestId(req);
|
|
1214
|
+
let bodyLoaded = false;
|
|
1215
|
+
let requestBody;
|
|
1216
|
+
const getRequestBody = /* @__PURE__ */ __name(async () => {
|
|
1217
|
+
if (!bodyLoaded) {
|
|
1218
|
+
bodyLoaded = true;
|
|
1219
|
+
if (req.method && req.method !== "GET" && req.method !== "HEAD") {
|
|
1220
|
+
requestBody = await readRequestBody(req);
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
return requestBody;
|
|
1224
|
+
}, "getRequestBody");
|
|
1225
|
+
const createHandlerRequest = /* @__PURE__ */ __name(async () => {
|
|
1226
|
+
return createWebRequest(req, fullUrl, await getRequestBody());
|
|
1227
|
+
}, "createHandlerRequest");
|
|
1228
|
+
for (const entry of middleware) {
|
|
1229
|
+
const params = resolveMatcherParams(entry.matcher, pathname);
|
|
1230
|
+
if (!params) {
|
|
1231
|
+
continue;
|
|
1232
|
+
}
|
|
1233
|
+
const request = await createHandlerRequest();
|
|
1234
|
+
const handlerContext = createIntegrationHandlerContext({
|
|
1235
|
+
integration,
|
|
1236
|
+
route: {
|
|
1237
|
+
kind: "middleware",
|
|
1238
|
+
path: normalizeMatcher(entry.matcher),
|
|
1239
|
+
methods: ["ALL"]
|
|
1240
|
+
},
|
|
1241
|
+
request,
|
|
1242
|
+
rawRequest: req,
|
|
1243
|
+
params,
|
|
1244
|
+
pathname,
|
|
1245
|
+
requestId,
|
|
1246
|
+
pluginContext: context
|
|
1247
|
+
});
|
|
1248
|
+
const startedAt = Date.now();
|
|
1249
|
+
await integration.log?.({
|
|
1250
|
+
category: integration.category,
|
|
1251
|
+
slot: integration.category,
|
|
1252
|
+
type: integration.type,
|
|
1253
|
+
phase: "request:start",
|
|
1254
|
+
route: {
|
|
1255
|
+
kind: "middleware",
|
|
1256
|
+
path: normalizeMatcher(entry.matcher),
|
|
1257
|
+
methods: ["ALL"]
|
|
1258
|
+
},
|
|
1259
|
+
request,
|
|
1260
|
+
requestId,
|
|
1261
|
+
context: handlerContext.req.snapshot()
|
|
1262
|
+
});
|
|
1263
|
+
try {
|
|
1264
|
+
const response = await entry.handler(request, handlerContext);
|
|
1265
|
+
if (response) {
|
|
1266
|
+
await sendWebResponse(res, response);
|
|
1267
|
+
await integration.log?.({
|
|
1268
|
+
category: integration.category,
|
|
1269
|
+
slot: integration.category,
|
|
1270
|
+
type: integration.type,
|
|
1271
|
+
phase: "request:end",
|
|
1272
|
+
route: {
|
|
1273
|
+
kind: "middleware",
|
|
1274
|
+
path: normalizeMatcher(entry.matcher),
|
|
1275
|
+
methods: ["ALL"]
|
|
1276
|
+
},
|
|
1277
|
+
request,
|
|
1278
|
+
response,
|
|
1279
|
+
requestId,
|
|
1280
|
+
durationMs: Date.now() - startedAt,
|
|
1281
|
+
context: handlerContext.req.snapshot()
|
|
1282
|
+
});
|
|
1283
|
+
return;
|
|
1284
|
+
}
|
|
1285
|
+
await integration.log?.({
|
|
1286
|
+
category: integration.category,
|
|
1287
|
+
slot: integration.category,
|
|
1288
|
+
type: integration.type,
|
|
1289
|
+
phase: "request:end",
|
|
1290
|
+
route: {
|
|
1291
|
+
kind: "middleware",
|
|
1292
|
+
path: normalizeMatcher(entry.matcher),
|
|
1293
|
+
methods: ["ALL"]
|
|
1294
|
+
},
|
|
1295
|
+
request,
|
|
1296
|
+
requestId,
|
|
1297
|
+
durationMs: Date.now() - startedAt,
|
|
1298
|
+
context: handlerContext.req.snapshot()
|
|
1299
|
+
});
|
|
1300
|
+
} catch (error) {
|
|
1301
|
+
await integration.log?.({
|
|
1302
|
+
category: integration.category,
|
|
1303
|
+
slot: integration.category,
|
|
1304
|
+
type: integration.type,
|
|
1305
|
+
phase: "request:error",
|
|
1306
|
+
route: {
|
|
1307
|
+
kind: "middleware",
|
|
1308
|
+
path: normalizeMatcher(entry.matcher),
|
|
1309
|
+
methods: ["ALL"]
|
|
1310
|
+
},
|
|
1311
|
+
request,
|
|
1312
|
+
requestId,
|
|
1313
|
+
durationMs: Date.now() - startedAt,
|
|
1314
|
+
error,
|
|
1315
|
+
context: handlerContext.req.snapshot()
|
|
1316
|
+
});
|
|
1317
|
+
throw error;
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
for (const route of routes) {
|
|
1321
|
+
const params = matchesMethod(route.methods, req.method) ? extractPathParams(route.path, pathname) : null;
|
|
1322
|
+
if (!params) {
|
|
1323
|
+
continue;
|
|
1324
|
+
}
|
|
1325
|
+
const request = await createHandlerRequest();
|
|
1326
|
+
const handlerContext = createIntegrationHandlerContext({
|
|
1327
|
+
integration,
|
|
1328
|
+
route: {
|
|
1329
|
+
kind: "route",
|
|
1330
|
+
path: route.path,
|
|
1331
|
+
methods: route.methods
|
|
1332
|
+
},
|
|
1333
|
+
request,
|
|
1334
|
+
rawRequest: req,
|
|
1335
|
+
params,
|
|
1336
|
+
pathname,
|
|
1337
|
+
requestId,
|
|
1338
|
+
pluginContext: context
|
|
1339
|
+
});
|
|
1340
|
+
const startedAt = Date.now();
|
|
1341
|
+
await integration.log?.({
|
|
1342
|
+
category: integration.category,
|
|
1343
|
+
slot: integration.category,
|
|
1344
|
+
type: integration.type,
|
|
1345
|
+
phase: "request:start",
|
|
1346
|
+
route: {
|
|
1347
|
+
kind: "route",
|
|
1348
|
+
path: route.path,
|
|
1349
|
+
methods: route.methods
|
|
1350
|
+
},
|
|
1351
|
+
request,
|
|
1352
|
+
requestId,
|
|
1353
|
+
context: handlerContext.req.snapshot()
|
|
1354
|
+
});
|
|
1355
|
+
try {
|
|
1356
|
+
const validation = await validateIntegrationRouteInput(route, request, url);
|
|
1357
|
+
if (!validation.success) {
|
|
1358
|
+
await sendWebResponse(res, validation.response);
|
|
1359
|
+
await integration.log?.({
|
|
1360
|
+
category: integration.category,
|
|
1361
|
+
slot: integration.category,
|
|
1362
|
+
type: integration.type,
|
|
1363
|
+
phase: "request:end",
|
|
1364
|
+
route: {
|
|
1365
|
+
kind: "route",
|
|
1366
|
+
path: route.path,
|
|
1367
|
+
methods: route.methods
|
|
1368
|
+
},
|
|
1369
|
+
request,
|
|
1370
|
+
response: validation.response,
|
|
1371
|
+
requestId,
|
|
1372
|
+
durationMs: Date.now() - startedAt,
|
|
1373
|
+
context: handlerContext.req.snapshot()
|
|
1374
|
+
});
|
|
1375
|
+
return;
|
|
1376
|
+
}
|
|
1377
|
+
handlerContext.input = validation.input;
|
|
1378
|
+
for (const middlewareEntry of route.middleware || []) {
|
|
1379
|
+
const middlewareResponse = await middlewareEntry.handler(request, handlerContext);
|
|
1380
|
+
if (middlewareResponse) {
|
|
1381
|
+
await sendWebResponse(res, middlewareResponse);
|
|
1382
|
+
await integration.log?.({
|
|
1383
|
+
category: integration.category,
|
|
1384
|
+
slot: integration.category,
|
|
1385
|
+
type: integration.type,
|
|
1386
|
+
phase: "request:end",
|
|
1387
|
+
route: {
|
|
1388
|
+
kind: "route",
|
|
1389
|
+
path: route.path,
|
|
1390
|
+
methods: route.methods
|
|
1391
|
+
},
|
|
1392
|
+
request,
|
|
1393
|
+
response: middlewareResponse,
|
|
1394
|
+
requestId,
|
|
1395
|
+
durationMs: Date.now() - startedAt,
|
|
1396
|
+
context: handlerContext.req.snapshot()
|
|
1397
|
+
});
|
|
1398
|
+
return;
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
const beforeResponse = await runIntegrationRouteBeforeHooks(
|
|
1402
|
+
route,
|
|
1403
|
+
request,
|
|
1404
|
+
handlerContext
|
|
1405
|
+
);
|
|
1406
|
+
if (beforeResponse) {
|
|
1407
|
+
const response2 = await runIntegrationRouteAfterHooks(
|
|
1408
|
+
route,
|
|
1409
|
+
request,
|
|
1410
|
+
handlerContext,
|
|
1411
|
+
beforeResponse
|
|
1412
|
+
);
|
|
1413
|
+
await sendWebResponse(res, response2);
|
|
1414
|
+
await integration.log?.({
|
|
1415
|
+
category: integration.category,
|
|
1416
|
+
slot: integration.category,
|
|
1417
|
+
type: integration.type,
|
|
1418
|
+
phase: "request:end",
|
|
1419
|
+
route: {
|
|
1420
|
+
kind: "route",
|
|
1421
|
+
path: route.path,
|
|
1422
|
+
methods: route.methods
|
|
1423
|
+
},
|
|
1424
|
+
request,
|
|
1425
|
+
response: response2,
|
|
1426
|
+
requestId,
|
|
1427
|
+
durationMs: Date.now() - startedAt,
|
|
1428
|
+
context: handlerContext.req.snapshot()
|
|
1429
|
+
});
|
|
1430
|
+
return;
|
|
1431
|
+
}
|
|
1432
|
+
const handlerResponse = await route.handler(request, handlerContext);
|
|
1433
|
+
const response = await runIntegrationRouteAfterHooks(
|
|
1434
|
+
route,
|
|
1435
|
+
request,
|
|
1436
|
+
handlerContext,
|
|
1437
|
+
handlerResponse
|
|
1438
|
+
);
|
|
1439
|
+
await sendWebResponse(res, response);
|
|
1440
|
+
await integration.log?.({
|
|
1441
|
+
category: integration.category,
|
|
1442
|
+
slot: integration.category,
|
|
1443
|
+
type: integration.type,
|
|
1444
|
+
phase: "request:end",
|
|
1445
|
+
route: {
|
|
1446
|
+
kind: "route",
|
|
1447
|
+
path: route.path,
|
|
1448
|
+
methods: route.methods
|
|
1449
|
+
},
|
|
1450
|
+
request,
|
|
1451
|
+
response,
|
|
1452
|
+
requestId,
|
|
1453
|
+
durationMs: Date.now() - startedAt,
|
|
1454
|
+
context: handlerContext.req.snapshot()
|
|
1455
|
+
});
|
|
1456
|
+
return;
|
|
1457
|
+
} catch (error) {
|
|
1458
|
+
await integration.log?.({
|
|
1459
|
+
category: integration.category,
|
|
1460
|
+
slot: integration.category,
|
|
1461
|
+
type: integration.type,
|
|
1462
|
+
phase: "request:error",
|
|
1463
|
+
route: {
|
|
1464
|
+
kind: "route",
|
|
1465
|
+
path: route.path,
|
|
1466
|
+
methods: route.methods
|
|
1467
|
+
},
|
|
1468
|
+
request,
|
|
1469
|
+
requestId,
|
|
1470
|
+
durationMs: Date.now() - startedAt,
|
|
1471
|
+
error,
|
|
1472
|
+
context: handlerContext.req.snapshot()
|
|
1473
|
+
});
|
|
1474
|
+
throw error;
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
};
|
|
1479
|
+
Object.defineProperty(plugin, FARM_INTEGRATION_PLUGIN_SERVER_RUNTIME, {
|
|
1480
|
+
value: integration.serverRuntime !== false
|
|
1481
|
+
});
|
|
1482
|
+
return plugin;
|
|
1483
|
+
}
|
|
1484
|
+
__name(createIntegrationPlugin, "createIntegrationPlugin");
|
|
1485
|
+
function createIntegrationHandlerContext(input) {
|
|
1486
|
+
const req = createIntegrationRequestContextStore(
|
|
1487
|
+
input.rawRequest,
|
|
1488
|
+
input.request,
|
|
1489
|
+
input.pluginContext
|
|
1490
|
+
);
|
|
1491
|
+
return {
|
|
1492
|
+
request: input.request,
|
|
1493
|
+
requestId: input.requestId,
|
|
1494
|
+
url: new URL(input.request.url),
|
|
1495
|
+
pathname: input.pathname,
|
|
1496
|
+
method: input.request.method,
|
|
1497
|
+
params: input.params,
|
|
1498
|
+
input: {},
|
|
1499
|
+
args: createIntegrationRouteArgs({
|
|
1500
|
+
integration: input.integration,
|
|
1501
|
+
config: input.pluginContext.config
|
|
1502
|
+
}),
|
|
1503
|
+
data: resolveIntegrationData(input.request),
|
|
1504
|
+
integration: {
|
|
1505
|
+
category: input.integration.category,
|
|
1506
|
+
slot: input.integration.category,
|
|
1507
|
+
type: input.integration.type,
|
|
1508
|
+
instance: input.integration.instance
|
|
1509
|
+
},
|
|
1510
|
+
route: input.route,
|
|
1511
|
+
req,
|
|
1512
|
+
requestContext: req,
|
|
1513
|
+
config: input.pluginContext.config,
|
|
1514
|
+
isDev: input.pluginContext.isDev,
|
|
1515
|
+
isProd: input.pluginContext.isProd
|
|
1516
|
+
};
|
|
1517
|
+
}
|
|
1518
|
+
__name(createIntegrationHandlerContext, "createIntegrationHandlerContext");
|
|
1519
|
+
function normalizeIntegrationRoutes(routes) {
|
|
1520
|
+
return routes.map((route) => ({
|
|
1521
|
+
...route,
|
|
1522
|
+
methods: normalizeIntegrationRouteMethods(route),
|
|
1523
|
+
input: normalizeIntegrationRouteInputSchemas(route)
|
|
1524
|
+
}));
|
|
1525
|
+
}
|
|
1526
|
+
__name(normalizeIntegrationRoutes, "normalizeIntegrationRoutes");
|
|
1527
|
+
function normalizeIntegrationRouteMethods(route) {
|
|
1528
|
+
const input = route.methods && route.methods.length > 0 ? [...route.methods] : route.method ? [route.method] : ["ALL"];
|
|
1529
|
+
return input.map((method) => String(method).toUpperCase());
|
|
1530
|
+
}
|
|
1531
|
+
__name(normalizeIntegrationRouteMethods, "normalizeIntegrationRouteMethods");
|
|
1532
|
+
function normalizeIntegrationRouteInputSchemas(route) {
|
|
1533
|
+
const input = {
|
|
1534
|
+
...route.input
|
|
1535
|
+
};
|
|
1536
|
+
if (route.body) {
|
|
1537
|
+
input.body = route.body;
|
|
1538
|
+
}
|
|
1539
|
+
if (route.query) {
|
|
1540
|
+
input.query = route.query;
|
|
1541
|
+
}
|
|
1542
|
+
return input.body || input.query ? input : void 0;
|
|
1543
|
+
}
|
|
1544
|
+
__name(normalizeIntegrationRouteInputSchemas, "normalizeIntegrationRouteInputSchemas");
|
|
1545
|
+
async function validateIntegrationRouteInput(route, request, url) {
|
|
1546
|
+
const schemas = route.input;
|
|
1547
|
+
if (!schemas?.body && !schemas?.query) {
|
|
1548
|
+
return {
|
|
1549
|
+
success: true,
|
|
1550
|
+
input: {}
|
|
1551
|
+
};
|
|
1552
|
+
}
|
|
1553
|
+
const input = {};
|
|
1554
|
+
const issues = [];
|
|
1555
|
+
if (schemas.query) {
|
|
1556
|
+
const queryResult = await parseIntegrationInputSchema(
|
|
1557
|
+
"query",
|
|
1558
|
+
schemas.query,
|
|
1559
|
+
createQueryInput(url.searchParams)
|
|
1560
|
+
);
|
|
1561
|
+
if (queryResult.success) {
|
|
1562
|
+
input.query = queryResult.data;
|
|
1563
|
+
} else {
|
|
1564
|
+
issues.push(...queryResult.issues);
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
if (schemas.body) {
|
|
1568
|
+
const bodyInput = await readIntegrationValidationBody(
|
|
1569
|
+
request,
|
|
1570
|
+
getIntegrationRouteBodyFormat(route)
|
|
1571
|
+
);
|
|
1572
|
+
if (bodyInput.success) {
|
|
1573
|
+
const bodyResult = await parseIntegrationInputSchema("body", schemas.body, bodyInput.data);
|
|
1574
|
+
if (bodyResult.success) {
|
|
1575
|
+
input.body = bodyResult.data;
|
|
1576
|
+
} else {
|
|
1577
|
+
issues.push(...bodyResult.issues);
|
|
1578
|
+
}
|
|
1579
|
+
} else {
|
|
1580
|
+
issues.push(bodyInput.issue);
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
if (issues.length > 0) {
|
|
1584
|
+
return {
|
|
1585
|
+
success: false,
|
|
1586
|
+
response: createIntegrationValidationResponse(issues)
|
|
1587
|
+
};
|
|
1588
|
+
}
|
|
1589
|
+
return {
|
|
1590
|
+
success: true,
|
|
1591
|
+
input
|
|
1592
|
+
};
|
|
1593
|
+
}
|
|
1594
|
+
__name(validateIntegrationRouteInput, "validateIntegrationRouteInput");
|
|
1595
|
+
async function parseIntegrationInputSchema(source, schema, value) {
|
|
1596
|
+
const parser = schema.safeParseAsync || schema.safeParse;
|
|
1597
|
+
if (parser) {
|
|
1598
|
+
const result = await parser.call(schema, value);
|
|
1599
|
+
if (result.success) {
|
|
1600
|
+
return {
|
|
1601
|
+
success: true,
|
|
1602
|
+
data: result.data
|
|
1603
|
+
};
|
|
1604
|
+
}
|
|
1605
|
+
return {
|
|
1606
|
+
success: false,
|
|
1607
|
+
issues: normalizeIntegrationValidationIssues(source, result.error)
|
|
1608
|
+
};
|
|
1609
|
+
}
|
|
1610
|
+
if (schema["~standard"]?.validate) {
|
|
1611
|
+
const result = await schema["~standard"].validate(value);
|
|
1612
|
+
if ("value" in result) {
|
|
1613
|
+
return {
|
|
1614
|
+
success: true,
|
|
1615
|
+
data: result.value
|
|
1616
|
+
};
|
|
1617
|
+
}
|
|
1618
|
+
return {
|
|
1619
|
+
success: false,
|
|
1620
|
+
issues: normalizeIntegrationValidationIssues(source, {
|
|
1621
|
+
issues: result.issues
|
|
1622
|
+
})
|
|
1623
|
+
};
|
|
1624
|
+
}
|
|
1625
|
+
if (schema.parse) {
|
|
1626
|
+
try {
|
|
1627
|
+
return {
|
|
1628
|
+
success: true,
|
|
1629
|
+
data: await schema.parse(value)
|
|
1630
|
+
};
|
|
1631
|
+
} catch (error) {
|
|
1632
|
+
return {
|
|
1633
|
+
success: false,
|
|
1634
|
+
issues: normalizeIntegrationValidationIssues(
|
|
1635
|
+
source,
|
|
1636
|
+
normalizeIntegrationValidationError(error)
|
|
1637
|
+
)
|
|
1638
|
+
};
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
return {
|
|
1642
|
+
success: false,
|
|
1643
|
+
issues: [
|
|
1644
|
+
{
|
|
1645
|
+
source,
|
|
1646
|
+
message: "Input schema must expose safeParse, safeParseAsync, parse, or ~standard.validate."
|
|
1647
|
+
}
|
|
1648
|
+
]
|
|
1649
|
+
};
|
|
1650
|
+
}
|
|
1651
|
+
__name(parseIntegrationInputSchema, "parseIntegrationInputSchema");
|
|
1652
|
+
function createIntegrationValidationResponse(issues) {
|
|
1653
|
+
return Response.json(
|
|
1654
|
+
{
|
|
1655
|
+
error: "Integration route input validation failed",
|
|
1656
|
+
issues
|
|
1657
|
+
},
|
|
1658
|
+
{
|
|
1659
|
+
status: 400
|
|
1660
|
+
}
|
|
1661
|
+
);
|
|
1662
|
+
}
|
|
1663
|
+
__name(createIntegrationValidationResponse, "createIntegrationValidationResponse");
|
|
1664
|
+
function normalizeIntegrationValidationIssues(source, error) {
|
|
1665
|
+
if (Array.isArray(error.issues) && error.issues.length > 0) {
|
|
1666
|
+
return error.issues.map((issue) => ({
|
|
1667
|
+
source,
|
|
1668
|
+
path: normalizeIntegrationValidationPath(issue.path),
|
|
1669
|
+
code: issue.code,
|
|
1670
|
+
message: issue.message || "Invalid input"
|
|
1671
|
+
}));
|
|
1672
|
+
}
|
|
1673
|
+
return [
|
|
1674
|
+
{
|
|
1675
|
+
source,
|
|
1676
|
+
path: [],
|
|
1677
|
+
message: error.message || "Invalid input"
|
|
1678
|
+
}
|
|
1679
|
+
];
|
|
1680
|
+
}
|
|
1681
|
+
__name(normalizeIntegrationValidationIssues, "normalizeIntegrationValidationIssues");
|
|
1682
|
+
function normalizeIntegrationValidationPath(path4) {
|
|
1683
|
+
return (path4 || []).map((segment) => {
|
|
1684
|
+
const key = typeof segment === "object" && segment !== null && "key" in segment ? segment.key : segment;
|
|
1685
|
+
return typeof key === "symbol" ? key.description || key.toString() : key;
|
|
1686
|
+
});
|
|
1687
|
+
}
|
|
1688
|
+
__name(normalizeIntegrationValidationPath, "normalizeIntegrationValidationPath");
|
|
1689
|
+
function normalizeIntegrationValidationError(error) {
|
|
1690
|
+
if (error && typeof error === "object") {
|
|
1691
|
+
return error;
|
|
1692
|
+
}
|
|
1693
|
+
return {
|
|
1694
|
+
message: error instanceof Error ? error.message : String(error || "Invalid input")
|
|
1695
|
+
};
|
|
1696
|
+
}
|
|
1697
|
+
__name(normalizeIntegrationValidationError, "normalizeIntegrationValidationError");
|
|
1698
|
+
async function readIntegrationValidationBody(request, format) {
|
|
1699
|
+
if (request.method === "GET" || request.method === "HEAD" || format === "none") {
|
|
1700
|
+
return {
|
|
1701
|
+
success: true,
|
|
1702
|
+
data: void 0
|
|
1703
|
+
};
|
|
1704
|
+
}
|
|
1705
|
+
try {
|
|
1706
|
+
if (format === "form") {
|
|
1707
|
+
return {
|
|
1708
|
+
success: true,
|
|
1709
|
+
data: createFormInput(await request.clone().formData())
|
|
1710
|
+
};
|
|
1711
|
+
}
|
|
1712
|
+
const text = await request.clone().text();
|
|
1713
|
+
if (text.trim().length === 0) {
|
|
1714
|
+
return {
|
|
1715
|
+
success: true,
|
|
1716
|
+
data: void 0
|
|
1717
|
+
};
|
|
1718
|
+
}
|
|
1719
|
+
return {
|
|
1720
|
+
success: true,
|
|
1721
|
+
data: JSON.parse(text)
|
|
1722
|
+
};
|
|
1723
|
+
} catch (error) {
|
|
1724
|
+
return {
|
|
1725
|
+
success: false,
|
|
1726
|
+
issue: {
|
|
1727
|
+
source: "body",
|
|
1728
|
+
path: [],
|
|
1729
|
+
message: format === "json" ? "Expected a valid JSON request body." : error instanceof Error && error.message ? error.message : "Could not parse request body."
|
|
1730
|
+
}
|
|
1731
|
+
};
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
__name(readIntegrationValidationBody, "readIntegrationValidationBody");
|
|
1735
|
+
function getIntegrationRouteBodyFormat(route) {
|
|
1736
|
+
return route.bodyFormat || route.__operation?.bodyFormat || "json";
|
|
1737
|
+
}
|
|
1738
|
+
__name(getIntegrationRouteBodyFormat, "getIntegrationRouteBodyFormat");
|
|
1739
|
+
function createIntegrationRouteArgs(input) {
|
|
1740
|
+
let clientPromise;
|
|
1741
|
+
let ormPromise;
|
|
1742
|
+
const getClient = /* @__PURE__ */ __name(() => {
|
|
1743
|
+
clientPromise ?? (clientPromise = Promise.resolve().then(() => (init_storage(), storage_exports)).then(
|
|
1744
|
+
({ resolveStorageRuntimeClient: resolveStorageRuntimeClient2 }) => resolveStorageRuntimeClient2(input.config.storage)
|
|
1745
|
+
));
|
|
1746
|
+
return clientPromise;
|
|
1747
|
+
}, "getClient");
|
|
1748
|
+
const getOrm = /* @__PURE__ */ __name(() => {
|
|
1749
|
+
if (!input.integration.schema) {
|
|
1750
|
+
throw new Error(
|
|
1751
|
+
`Integration "${input.integration.type}" does not define a schema for ctx.args.db.`
|
|
1752
|
+
);
|
|
1753
|
+
}
|
|
1754
|
+
ormPromise ?? (ormPromise = Promise.resolve().then(() => (init_integration_orm(), integration_orm_exports)).then(
|
|
1755
|
+
({ createIntegrationOrm: createIntegrationOrm2 }) => createIntegrationOrm2({
|
|
1756
|
+
schema: input.integration.schema,
|
|
1757
|
+
config: input.config
|
|
1758
|
+
})
|
|
1759
|
+
));
|
|
1760
|
+
return ormPromise;
|
|
1761
|
+
}, "getOrm");
|
|
1762
|
+
return {
|
|
1763
|
+
db: createLazyIntegrationOrmClient(getOrm),
|
|
1764
|
+
getDb: getOrm,
|
|
1765
|
+
storage: {
|
|
1766
|
+
getClient,
|
|
1767
|
+
getOrm
|
|
1768
|
+
}
|
|
1769
|
+
};
|
|
1770
|
+
}
|
|
1771
|
+
__name(createIntegrationRouteArgs, "createIntegrationRouteArgs");
|
|
1772
|
+
function createLazyIntegrationOrmClient(resolveOrm) {
|
|
1773
|
+
const modelProxyCache = /* @__PURE__ */ new Map();
|
|
1774
|
+
return new Proxy(
|
|
1775
|
+
{},
|
|
1776
|
+
{
|
|
1777
|
+
get(_target, prop) {
|
|
1778
|
+
if (prop === "then") {
|
|
1779
|
+
return void 0;
|
|
1780
|
+
}
|
|
1781
|
+
if (prop === "transaction" || prop === "batch") {
|
|
1782
|
+
return async (...args) => {
|
|
1783
|
+
const orm = await resolveOrm();
|
|
1784
|
+
const member = orm[prop];
|
|
1785
|
+
if (typeof member !== "function") {
|
|
1786
|
+
throw new Error(`Integration ORM does not expose "${String(prop)}".`);
|
|
1787
|
+
}
|
|
1788
|
+
return member.apply(orm, args);
|
|
1789
|
+
};
|
|
1790
|
+
}
|
|
1791
|
+
if (prop === "$driver") {
|
|
1792
|
+
return void 0;
|
|
1793
|
+
}
|
|
1794
|
+
if (!modelProxyCache.has(prop)) {
|
|
1795
|
+
modelProxyCache.set(prop, createLazyIntegrationOrmModel(resolveOrm, prop));
|
|
1796
|
+
}
|
|
1797
|
+
return modelProxyCache.get(prop);
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
);
|
|
1801
|
+
}
|
|
1802
|
+
__name(createLazyIntegrationOrmClient, "createLazyIntegrationOrmClient");
|
|
1803
|
+
function createLazyIntegrationOrmModel(resolveOrm, modelName) {
|
|
1804
|
+
return new Proxy(
|
|
1805
|
+
{},
|
|
1806
|
+
{
|
|
1807
|
+
get(_target, prop) {
|
|
1808
|
+
if (prop === "then") {
|
|
1809
|
+
return void 0;
|
|
1810
|
+
}
|
|
1811
|
+
return async (...args) => {
|
|
1812
|
+
const orm = await resolveOrm();
|
|
1813
|
+
const model = orm[modelName];
|
|
1814
|
+
const member = model?.[prop];
|
|
1815
|
+
if (typeof member !== "function") {
|
|
1816
|
+
throw new Error(
|
|
1817
|
+
`Integration ORM model "${String(modelName)}" does not expose "${String(prop)}".`
|
|
1818
|
+
);
|
|
1819
|
+
}
|
|
1820
|
+
return member.apply(model, args);
|
|
1821
|
+
};
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
);
|
|
1825
|
+
}
|
|
1826
|
+
__name(createLazyIntegrationOrmModel, "createLazyIntegrationOrmModel");
|
|
1827
|
+
async function runIntegrationRouteBeforeHooks(route, request, context) {
|
|
1828
|
+
const hookContext = context;
|
|
1829
|
+
hookContext.response = void 0;
|
|
1830
|
+
for (const hook of route.before || []) {
|
|
1831
|
+
const response = await hook(request, hookContext);
|
|
1832
|
+
if (response) {
|
|
1833
|
+
hookContext.response = response;
|
|
1834
|
+
return response;
|
|
1835
|
+
}
|
|
1836
|
+
if (hookContext.response) {
|
|
1837
|
+
return hookContext.response;
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
return void 0;
|
|
1841
|
+
}
|
|
1842
|
+
__name(runIntegrationRouteBeforeHooks, "runIntegrationRouteBeforeHooks");
|
|
1843
|
+
async function runIntegrationRouteAfterHooks(route, request, context, response) {
|
|
1844
|
+
const hookContext = context;
|
|
1845
|
+
let currentResponse = response;
|
|
1846
|
+
for (const hook of route.after || []) {
|
|
1847
|
+
hookContext.response = currentResponse;
|
|
1848
|
+
const nextResponse = await hook(request, hookContext);
|
|
1849
|
+
currentResponse = nextResponse || hookContext.response || currentResponse;
|
|
1850
|
+
}
|
|
1851
|
+
hookContext.response = currentResponse;
|
|
1852
|
+
return currentResponse;
|
|
1853
|
+
}
|
|
1854
|
+
__name(runIntegrationRouteAfterHooks, "runIntegrationRouteAfterHooks");
|
|
1855
|
+
function createQueryInput(searchParams) {
|
|
1856
|
+
const input = {};
|
|
1857
|
+
searchParams.forEach((value, key) => {
|
|
1858
|
+
const existing = input[key];
|
|
1859
|
+
if (existing === void 0) {
|
|
1860
|
+
input[key] = value;
|
|
1861
|
+
return;
|
|
1862
|
+
}
|
|
1863
|
+
input[key] = Array.isArray(existing) ? [...existing, value] : [existing, value];
|
|
1864
|
+
});
|
|
1865
|
+
return input;
|
|
1866
|
+
}
|
|
1867
|
+
__name(createQueryInput, "createQueryInput");
|
|
1868
|
+
function createFormInput(formData) {
|
|
1869
|
+
const input = {};
|
|
1870
|
+
formData.forEach((value, key) => {
|
|
1871
|
+
const existing = input[key];
|
|
1872
|
+
if (existing === void 0) {
|
|
1873
|
+
input[key] = value;
|
|
1874
|
+
return;
|
|
1875
|
+
}
|
|
1876
|
+
input[key] = Array.isArray(existing) ? [...existing, value] : [existing, value];
|
|
1877
|
+
});
|
|
1878
|
+
return input;
|
|
1879
|
+
}
|
|
1880
|
+
__name(createFormInput, "createFormInput");
|
|
1881
|
+
async function dispatchIntegrationRequest(runtime, request, options = {}) {
|
|
1882
|
+
const integration = runtime.integration;
|
|
1883
|
+
const url = new URL(request.url);
|
|
1884
|
+
const pathname = url.pathname;
|
|
1885
|
+
const requestId = request.headers.get("x-request-id") || options.currentRequest?.headers.get("x-request-id") || String(Date.now());
|
|
1886
|
+
const routes = normalizeIntegrationRoutes(integration.routes || []);
|
|
1887
|
+
const middleware = [...integration.middleware || []];
|
|
1888
|
+
for (const entry of middleware) {
|
|
1889
|
+
const params = resolveMatcherParams(entry.matcher, pathname);
|
|
1890
|
+
if (!params) {
|
|
1891
|
+
continue;
|
|
1892
|
+
}
|
|
1893
|
+
const handlerContext = createServerIntegrationHandlerContext({
|
|
1894
|
+
runtime,
|
|
1895
|
+
route: {
|
|
1896
|
+
kind: "middleware",
|
|
1897
|
+
path: normalizeMatcher(entry.matcher),
|
|
1898
|
+
methods: ["ALL"]
|
|
1899
|
+
},
|
|
1900
|
+
request,
|
|
1901
|
+
params,
|
|
1902
|
+
pathname,
|
|
1903
|
+
requestId,
|
|
1904
|
+
currentRequest: options.currentRequest,
|
|
1905
|
+
data: options.data,
|
|
1906
|
+
internal: options.internal === true
|
|
1907
|
+
});
|
|
1908
|
+
const startedAt = Date.now();
|
|
1909
|
+
await integration.log?.({
|
|
1910
|
+
category: integration.category,
|
|
1911
|
+
slot: integration.category,
|
|
1912
|
+
type: integration.type,
|
|
1913
|
+
phase: "request:start",
|
|
1914
|
+
route: {
|
|
1915
|
+
kind: "middleware",
|
|
1916
|
+
path: normalizeMatcher(entry.matcher),
|
|
1917
|
+
methods: ["ALL"]
|
|
1918
|
+
},
|
|
1919
|
+
request,
|
|
1920
|
+
requestId,
|
|
1921
|
+
context: handlerContext.req.snapshot()
|
|
1922
|
+
});
|
|
1923
|
+
try {
|
|
1924
|
+
const response = await entry.handler(request, handlerContext);
|
|
1925
|
+
if (response) {
|
|
1926
|
+
await integration.log?.({
|
|
1927
|
+
category: integration.category,
|
|
1928
|
+
slot: integration.category,
|
|
1929
|
+
type: integration.type,
|
|
1930
|
+
phase: "request:end",
|
|
1931
|
+
route: {
|
|
1932
|
+
kind: "middleware",
|
|
1933
|
+
path: normalizeMatcher(entry.matcher),
|
|
1934
|
+
methods: ["ALL"]
|
|
1935
|
+
},
|
|
1936
|
+
request,
|
|
1937
|
+
response,
|
|
1938
|
+
requestId,
|
|
1939
|
+
durationMs: Date.now() - startedAt,
|
|
1940
|
+
context: handlerContext.req.snapshot()
|
|
1941
|
+
});
|
|
1942
|
+
return response;
|
|
1943
|
+
}
|
|
1944
|
+
await integration.log?.({
|
|
1945
|
+
category: integration.category,
|
|
1946
|
+
slot: integration.category,
|
|
1947
|
+
type: integration.type,
|
|
1948
|
+
phase: "request:end",
|
|
1949
|
+
route: {
|
|
1950
|
+
kind: "middleware",
|
|
1951
|
+
path: normalizeMatcher(entry.matcher),
|
|
1952
|
+
methods: ["ALL"]
|
|
1953
|
+
},
|
|
1954
|
+
request,
|
|
1955
|
+
requestId,
|
|
1956
|
+
durationMs: Date.now() - startedAt,
|
|
1957
|
+
context: handlerContext.req.snapshot()
|
|
1958
|
+
});
|
|
1959
|
+
} catch (error) {
|
|
1960
|
+
await integration.log?.({
|
|
1961
|
+
category: integration.category,
|
|
1962
|
+
slot: integration.category,
|
|
1963
|
+
type: integration.type,
|
|
1964
|
+
phase: "request:error",
|
|
1965
|
+
route: {
|
|
1966
|
+
kind: "middleware",
|
|
1967
|
+
path: normalizeMatcher(entry.matcher),
|
|
1968
|
+
methods: ["ALL"]
|
|
1969
|
+
},
|
|
1970
|
+
request,
|
|
1971
|
+
requestId,
|
|
1972
|
+
durationMs: Date.now() - startedAt,
|
|
1973
|
+
error,
|
|
1974
|
+
context: handlerContext.req.snapshot()
|
|
1975
|
+
});
|
|
1976
|
+
throw error;
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
for (const route of routes) {
|
|
1980
|
+
const params = matchesMethod(route.methods, request.method) ? extractPathParams(route.path, pathname) : null;
|
|
1981
|
+
if (!params) {
|
|
1982
|
+
continue;
|
|
1983
|
+
}
|
|
1984
|
+
const handlerContext = createServerIntegrationHandlerContext({
|
|
1985
|
+
runtime,
|
|
1986
|
+
route: {
|
|
1987
|
+
kind: "route",
|
|
1988
|
+
path: route.path,
|
|
1989
|
+
methods: route.methods
|
|
1990
|
+
},
|
|
1991
|
+
request,
|
|
1992
|
+
params,
|
|
1993
|
+
pathname,
|
|
1994
|
+
requestId,
|
|
1995
|
+
currentRequest: options.currentRequest,
|
|
1996
|
+
data: options.data,
|
|
1997
|
+
internal: options.internal === true
|
|
1998
|
+
});
|
|
1999
|
+
const startedAt = Date.now();
|
|
2000
|
+
await integration.log?.({
|
|
2001
|
+
category: integration.category,
|
|
2002
|
+
slot: integration.category,
|
|
2003
|
+
type: integration.type,
|
|
2004
|
+
phase: "request:start",
|
|
2005
|
+
route: {
|
|
2006
|
+
kind: "route",
|
|
2007
|
+
path: route.path,
|
|
2008
|
+
methods: route.methods
|
|
2009
|
+
},
|
|
2010
|
+
request,
|
|
2011
|
+
requestId,
|
|
2012
|
+
context: handlerContext.req.snapshot()
|
|
2013
|
+
});
|
|
2014
|
+
try {
|
|
2015
|
+
const validation = await validateIntegrationRouteInput(route, request, url);
|
|
2016
|
+
if (!validation.success) {
|
|
2017
|
+
await integration.log?.({
|
|
2018
|
+
category: integration.category,
|
|
2019
|
+
slot: integration.category,
|
|
2020
|
+
type: integration.type,
|
|
2021
|
+
phase: "request:end",
|
|
2022
|
+
route: {
|
|
2023
|
+
kind: "route",
|
|
2024
|
+
path: route.path,
|
|
2025
|
+
methods: route.methods
|
|
2026
|
+
},
|
|
2027
|
+
request,
|
|
2028
|
+
response: validation.response,
|
|
2029
|
+
requestId,
|
|
2030
|
+
durationMs: Date.now() - startedAt,
|
|
2031
|
+
context: handlerContext.req.snapshot()
|
|
2032
|
+
});
|
|
2033
|
+
return validation.response;
|
|
2034
|
+
}
|
|
2035
|
+
handlerContext.input = validation.input;
|
|
2036
|
+
for (const middlewareEntry of route.middleware || []) {
|
|
2037
|
+
const middlewareResponse = await middlewareEntry.handler(request, handlerContext);
|
|
2038
|
+
if (middlewareResponse) {
|
|
2039
|
+
await integration.log?.({
|
|
2040
|
+
category: integration.category,
|
|
2041
|
+
slot: integration.category,
|
|
2042
|
+
type: integration.type,
|
|
2043
|
+
phase: "request:end",
|
|
2044
|
+
route: {
|
|
2045
|
+
kind: "route",
|
|
2046
|
+
path: route.path,
|
|
2047
|
+
methods: route.methods
|
|
2048
|
+
},
|
|
2049
|
+
request,
|
|
2050
|
+
response: middlewareResponse,
|
|
2051
|
+
requestId,
|
|
2052
|
+
durationMs: Date.now() - startedAt,
|
|
2053
|
+
context: handlerContext.req.snapshot()
|
|
2054
|
+
});
|
|
2055
|
+
return middlewareResponse;
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
const beforeResponse = await runIntegrationRouteBeforeHooks(route, request, handlerContext);
|
|
2059
|
+
if (beforeResponse) {
|
|
2060
|
+
const response2 = await runIntegrationRouteAfterHooks(
|
|
2061
|
+
route,
|
|
2062
|
+
request,
|
|
2063
|
+
handlerContext,
|
|
2064
|
+
beforeResponse
|
|
2065
|
+
);
|
|
2066
|
+
await integration.log?.({
|
|
2067
|
+
category: integration.category,
|
|
2068
|
+
slot: integration.category,
|
|
2069
|
+
type: integration.type,
|
|
2070
|
+
phase: "request:end",
|
|
2071
|
+
route: {
|
|
2072
|
+
kind: "route",
|
|
2073
|
+
path: route.path,
|
|
2074
|
+
methods: route.methods
|
|
2075
|
+
},
|
|
2076
|
+
request,
|
|
2077
|
+
response: response2,
|
|
2078
|
+
requestId,
|
|
2079
|
+
durationMs: Date.now() - startedAt,
|
|
2080
|
+
context: handlerContext.req.snapshot()
|
|
2081
|
+
});
|
|
2082
|
+
return response2;
|
|
2083
|
+
}
|
|
2084
|
+
const handlerResponse = await route.handler(request, handlerContext);
|
|
2085
|
+
const response = await runIntegrationRouteAfterHooks(
|
|
2086
|
+
route,
|
|
2087
|
+
request,
|
|
2088
|
+
handlerContext,
|
|
2089
|
+
handlerResponse
|
|
2090
|
+
);
|
|
2091
|
+
await integration.log?.({
|
|
2092
|
+
category: integration.category,
|
|
2093
|
+
slot: integration.category,
|
|
2094
|
+
type: integration.type,
|
|
2095
|
+
phase: "request:end",
|
|
2096
|
+
route: {
|
|
2097
|
+
kind: "route",
|
|
2098
|
+
path: route.path,
|
|
2099
|
+
methods: route.methods
|
|
2100
|
+
},
|
|
2101
|
+
request,
|
|
2102
|
+
response,
|
|
2103
|
+
requestId,
|
|
2104
|
+
durationMs: Date.now() - startedAt,
|
|
2105
|
+
context: handlerContext.req.snapshot()
|
|
2106
|
+
});
|
|
2107
|
+
return response;
|
|
2108
|
+
} catch (error) {
|
|
2109
|
+
await integration.log?.({
|
|
2110
|
+
category: integration.category,
|
|
2111
|
+
slot: integration.category,
|
|
2112
|
+
type: integration.type,
|
|
2113
|
+
phase: "request:error",
|
|
2114
|
+
route: {
|
|
2115
|
+
kind: "route",
|
|
2116
|
+
path: route.path,
|
|
2117
|
+
methods: route.methods
|
|
2118
|
+
},
|
|
2119
|
+
request,
|
|
2120
|
+
requestId,
|
|
2121
|
+
durationMs: Date.now() - startedAt,
|
|
2122
|
+
error,
|
|
2123
|
+
context: handlerContext.req.snapshot()
|
|
2124
|
+
});
|
|
2125
|
+
throw error;
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
return null;
|
|
2129
|
+
}
|
|
2130
|
+
__name(dispatchIntegrationRequest, "dispatchIntegrationRequest");
|
|
2131
|
+
globalThis[INTEGRATION_REQUEST_DISPATCHER_KEY] = dispatchIntegrationRequest;
|
|
2132
|
+
function createIntegrationRequestContextStore(rawRequest, request, pluginContext) {
|
|
2133
|
+
return {
|
|
2134
|
+
get(key) {
|
|
2135
|
+
const requestValue = pluginContext.requestContext.get(request, key);
|
|
2136
|
+
if (requestValue !== void 0) {
|
|
2137
|
+
return requestValue;
|
|
2138
|
+
}
|
|
2139
|
+
return pluginContext.requestContext.get(rawRequest, key);
|
|
2140
|
+
},
|
|
2141
|
+
set(key, value, options) {
|
|
2142
|
+
pluginContext.requestContext.set(rawRequest, key, value, options);
|
|
2143
|
+
pluginContext.requestContext.set(request, key, value, options);
|
|
2144
|
+
},
|
|
2145
|
+
has(key) {
|
|
2146
|
+
return pluginContext.requestContext.has(request, key) || pluginContext.requestContext.has(rawRequest, key);
|
|
2147
|
+
},
|
|
2148
|
+
delete(key) {
|
|
2149
|
+
const deletedRequest = pluginContext.requestContext.delete(request, key);
|
|
2150
|
+
const deletedRaw = pluginContext.requestContext.delete(rawRequest, key);
|
|
2151
|
+
return deletedRequest || deletedRaw;
|
|
2152
|
+
},
|
|
2153
|
+
clear() {
|
|
2154
|
+
pluginContext.requestContext.clear(rawRequest);
|
|
2155
|
+
pluginContext.requestContext.clear(request);
|
|
2156
|
+
},
|
|
2157
|
+
snapshot(options) {
|
|
2158
|
+
const merged = pluginContext.requestContext.getAll(rawRequest, options);
|
|
2159
|
+
const requestSnapshot = pluginContext.requestContext.getAll(request, options);
|
|
2160
|
+
for (const [key, value] of requestSnapshot) {
|
|
2161
|
+
merged.set(key, value);
|
|
2162
|
+
}
|
|
2163
|
+
return merged;
|
|
2164
|
+
}
|
|
2165
|
+
};
|
|
2166
|
+
}
|
|
2167
|
+
__name(createIntegrationRequestContextStore, "createIntegrationRequestContextStore");
|
|
2168
|
+
function createServerIntegrationHandlerContext(input) {
|
|
2169
|
+
const req = createServerIntegrationRequestContextStore(input.request, input.currentRequest);
|
|
2170
|
+
if (input.internal) {
|
|
2171
|
+
req.set(FARM_INTEGRATION_INTERNAL_DISPATCH_CONTEXT_KEY, true);
|
|
2172
|
+
}
|
|
2173
|
+
return {
|
|
2174
|
+
request: input.request,
|
|
2175
|
+
requestId: input.requestId,
|
|
2176
|
+
url: new URL(input.request.url),
|
|
2177
|
+
pathname: input.pathname,
|
|
2178
|
+
method: input.request.method,
|
|
2179
|
+
params: input.params,
|
|
2180
|
+
input: {},
|
|
2181
|
+
args: createIntegrationRouteArgs({
|
|
2182
|
+
integration: input.runtime.integration,
|
|
2183
|
+
config: input.runtime.config
|
|
2184
|
+
}),
|
|
2185
|
+
data: resolveIntegrationData(input.request, input.data),
|
|
2186
|
+
integration: {
|
|
2187
|
+
category: input.runtime.integration.category,
|
|
2188
|
+
slot: input.runtime.integration.category,
|
|
2189
|
+
type: input.runtime.integration.type,
|
|
2190
|
+
instance: input.runtime.integration.instance
|
|
2191
|
+
},
|
|
2192
|
+
route: input.route,
|
|
2193
|
+
req,
|
|
2194
|
+
requestContext: req,
|
|
2195
|
+
config: input.runtime.config,
|
|
2196
|
+
isDev: input.runtime.isDev,
|
|
2197
|
+
isProd: input.runtime.isProd
|
|
2198
|
+
};
|
|
2199
|
+
}
|
|
2200
|
+
__name(createServerIntegrationHandlerContext, "createServerIntegrationHandlerContext");
|
|
2201
|
+
function createServerIntegrationRequestContextStore(request, currentRequest) {
|
|
2202
|
+
return {
|
|
2203
|
+
get(key) {
|
|
2204
|
+
const requestValue = getRequestContext(request, key);
|
|
2205
|
+
if (requestValue !== void 0) {
|
|
2206
|
+
return requestValue;
|
|
2207
|
+
}
|
|
2208
|
+
if (currentRequest) {
|
|
2209
|
+
return getRequestContext(currentRequest, key);
|
|
2210
|
+
}
|
|
2211
|
+
return void 0;
|
|
2212
|
+
},
|
|
2213
|
+
set(key, value, options) {
|
|
2214
|
+
setRequestContext(request, key, value, options);
|
|
2215
|
+
if (currentRequest) {
|
|
2216
|
+
setRequestContext(currentRequest, key, value, options);
|
|
2217
|
+
}
|
|
2218
|
+
},
|
|
2219
|
+
has(key) {
|
|
2220
|
+
return hasRequestContext(request, key) || !!currentRequest && hasRequestContext(currentRequest, key);
|
|
2221
|
+
},
|
|
2222
|
+
delete(key) {
|
|
2223
|
+
const deletedRequest = deleteRequestContext(request, key);
|
|
2224
|
+
const deletedCurrent = currentRequest ? deleteRequestContext(currentRequest, key) : false;
|
|
2225
|
+
return deletedRequest || deletedCurrent;
|
|
2226
|
+
},
|
|
2227
|
+
clear() {
|
|
2228
|
+
clearRequestContext(request);
|
|
2229
|
+
if (currentRequest) {
|
|
2230
|
+
clearRequestContext(currentRequest);
|
|
2231
|
+
}
|
|
2232
|
+
},
|
|
2233
|
+
snapshot(options) {
|
|
2234
|
+
const merged = currentRequest ? getRequestContextSnapshot(currentRequest, options) : /* @__PURE__ */ new Map();
|
|
2235
|
+
const requestSnapshot = getRequestContextSnapshot(request, options);
|
|
2236
|
+
for (const [key, value] of requestSnapshot) {
|
|
2237
|
+
merged.set(key, value);
|
|
2238
|
+
}
|
|
2239
|
+
return merged;
|
|
2240
|
+
}
|
|
2241
|
+
};
|
|
2242
|
+
}
|
|
2243
|
+
__name(createServerIntegrationRequestContextStore, "createServerIntegrationRequestContextStore");
|
|
2244
|
+
function createWebRequest(req, fullUrl, body) {
|
|
2245
|
+
const headers = new Headers();
|
|
2246
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
2247
|
+
if (value == null) {
|
|
2248
|
+
continue;
|
|
2249
|
+
}
|
|
2250
|
+
if (Array.isArray(value)) {
|
|
2251
|
+
for (const item of value) {
|
|
2252
|
+
headers.append(key, item);
|
|
2253
|
+
}
|
|
2254
|
+
continue;
|
|
2255
|
+
}
|
|
2256
|
+
headers.set(key, value);
|
|
2257
|
+
}
|
|
2258
|
+
return new Request(fullUrl, {
|
|
2259
|
+
method: req.method,
|
|
2260
|
+
headers,
|
|
2261
|
+
body
|
|
2262
|
+
});
|
|
2263
|
+
}
|
|
2264
|
+
__name(createWebRequest, "createWebRequest");
|
|
2265
|
+
function matchesMethod(methods, method) {
|
|
2266
|
+
if (!method) {
|
|
2267
|
+
return false;
|
|
2268
|
+
}
|
|
2269
|
+
return methods.some((item) => item.toUpperCase() === method.toUpperCase());
|
|
2270
|
+
}
|
|
2271
|
+
__name(matchesMethod, "matchesMethod");
|
|
2272
|
+
function resolveMatcherParams(matcher, pathname) {
|
|
2273
|
+
if (!matcher) {
|
|
2274
|
+
return {};
|
|
2275
|
+
}
|
|
2276
|
+
const list = Array.isArray(matcher) ? matcher : [matcher];
|
|
2277
|
+
for (const item of list) {
|
|
2278
|
+
if (item === "/(.*)" || item === "*") {
|
|
2279
|
+
return {};
|
|
2280
|
+
}
|
|
2281
|
+
if (item.endsWith("(.*)")) {
|
|
2282
|
+
const prefix = item.slice(0, -4);
|
|
2283
|
+
if (pathname === prefix || pathname.startsWith(`${prefix}/`)) {
|
|
2284
|
+
return {};
|
|
2285
|
+
}
|
|
2286
|
+
continue;
|
|
2287
|
+
}
|
|
2288
|
+
const params = extractPathParams(item, pathname);
|
|
2289
|
+
if (params) {
|
|
2290
|
+
return params;
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
return null;
|
|
2294
|
+
}
|
|
2295
|
+
__name(resolveMatcherParams, "resolveMatcherParams");
|
|
2296
|
+
function extractPathParams(pattern, pathname) {
|
|
2297
|
+
const routeSegments = splitPath(pattern);
|
|
2298
|
+
const pathSegments = splitPath(pathname);
|
|
2299
|
+
const params = {};
|
|
2300
|
+
let routeIndex = 0;
|
|
2301
|
+
let pathIndex = 0;
|
|
2302
|
+
while (routeIndex < routeSegments.length && pathIndex < pathSegments.length) {
|
|
2303
|
+
const routeSegment = routeSegments[routeIndex];
|
|
2304
|
+
const pathSegment = pathSegments[pathIndex];
|
|
2305
|
+
if (isCatchAllSegment(routeSegment)) {
|
|
2306
|
+
params[getSegmentParamName(routeSegment)] = pathSegments.slice(pathIndex).map((segment) => decodeURIComponent(segment));
|
|
2307
|
+
return params;
|
|
2308
|
+
}
|
|
2309
|
+
if (isDynamicSegment(routeSegment)) {
|
|
2310
|
+
params[getSegmentParamName(routeSegment)] = decodeURIComponent(pathSegment);
|
|
2311
|
+
routeIndex += 1;
|
|
2312
|
+
pathIndex += 1;
|
|
2313
|
+
continue;
|
|
2314
|
+
}
|
|
2315
|
+
if (routeSegment !== pathSegment) {
|
|
2316
|
+
return null;
|
|
2317
|
+
}
|
|
2318
|
+
routeIndex += 1;
|
|
2319
|
+
pathIndex += 1;
|
|
2320
|
+
}
|
|
2321
|
+
if (routeIndex === routeSegments.length && pathIndex === pathSegments.length) {
|
|
2322
|
+
return params;
|
|
2323
|
+
}
|
|
2324
|
+
if (routeIndex === routeSegments.length - 1 && isCatchAllSegment(routeSegments[routeIndex])) {
|
|
2325
|
+
params[getSegmentParamName(routeSegments[routeIndex])] = [];
|
|
2326
|
+
return params;
|
|
2327
|
+
}
|
|
2328
|
+
return null;
|
|
2329
|
+
}
|
|
2330
|
+
__name(extractPathParams, "extractPathParams");
|
|
2331
|
+
function splitPath(value) {
|
|
2332
|
+
return value.split("/").filter(Boolean);
|
|
2333
|
+
}
|
|
2334
|
+
__name(splitPath, "splitPath");
|
|
2335
|
+
function isDynamicSegment(segment) {
|
|
2336
|
+
return segment.startsWith("[") && segment.endsWith("]");
|
|
2337
|
+
}
|
|
2338
|
+
__name(isDynamicSegment, "isDynamicSegment");
|
|
2339
|
+
function isCatchAllSegment(segment) {
|
|
2340
|
+
return segment.startsWith("[...") && segment.endsWith("]");
|
|
2341
|
+
}
|
|
2342
|
+
__name(isCatchAllSegment, "isCatchAllSegment");
|
|
2343
|
+
function getSegmentParamName(segment) {
|
|
2344
|
+
if (isCatchAllSegment(segment)) {
|
|
2345
|
+
return segment.slice(4, -1);
|
|
2346
|
+
}
|
|
2347
|
+
return segment.slice(1, -1);
|
|
2348
|
+
}
|
|
2349
|
+
__name(getSegmentParamName, "getSegmentParamName");
|
|
2350
|
+
function getRequestId(req) {
|
|
2351
|
+
const headerValue = req.headers["x-request-id"];
|
|
2352
|
+
if (Array.isArray(headerValue)) {
|
|
2353
|
+
return headerValue[0] || String(Date.now());
|
|
2354
|
+
}
|
|
2355
|
+
return headerValue || String(Date.now());
|
|
2356
|
+
}
|
|
2357
|
+
__name(getRequestId, "getRequestId");
|
|
2358
|
+
async function readRequestBody(req) {
|
|
2359
|
+
return await new Promise((resolve, reject) => {
|
|
2360
|
+
const chunks = [];
|
|
2361
|
+
req.on("data", (chunk) => {
|
|
2362
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
2363
|
+
});
|
|
2364
|
+
req.on("end", () => {
|
|
2365
|
+
resolve(Buffer.concat(chunks));
|
|
2366
|
+
});
|
|
2367
|
+
req.on("error", reject);
|
|
2368
|
+
});
|
|
2369
|
+
}
|
|
2370
|
+
__name(readRequestBody, "readRequestBody");
|
|
2371
|
+
function normalizeMatcher(matcher) {
|
|
2372
|
+
if (!matcher) {
|
|
2373
|
+
return "/(.*)";
|
|
2374
|
+
}
|
|
2375
|
+
return typeof matcher === "string" ? matcher : matcher.join(", ");
|
|
2376
|
+
}
|
|
2377
|
+
__name(normalizeMatcher, "normalizeMatcher");
|
|
2378
|
+
|
|
2379
|
+
// src/markdown.ts
|
|
2380
|
+
function resolveMarkdownConfig(config) {
|
|
2381
|
+
if (config === false || config === void 0) {
|
|
2382
|
+
return {
|
|
2383
|
+
enabled: false,
|
|
2384
|
+
expose: [],
|
|
2385
|
+
cache: false,
|
|
2386
|
+
includeMetadata: true
|
|
2387
|
+
};
|
|
2388
|
+
}
|
|
2389
|
+
if (config === true) {
|
|
2390
|
+
return {
|
|
2391
|
+
enabled: true,
|
|
2392
|
+
expose: true,
|
|
2393
|
+
cache: false,
|
|
2394
|
+
includeMetadata: true
|
|
2395
|
+
};
|
|
2396
|
+
}
|
|
2397
|
+
const exposeInput = config.expose ?? config.routes ?? [];
|
|
2398
|
+
const expose = exposeInput === true ? true : Array.isArray(exposeInput) ? exposeInput.map(normalizeMarkdownRouteInput) : [];
|
|
2399
|
+
return {
|
|
2400
|
+
enabled: config.enabled !== false && (expose === true || expose.length > 0),
|
|
2401
|
+
expose,
|
|
2402
|
+
cache: config.cache ?? false,
|
|
2403
|
+
includeMetadata: config.includeMetadata ?? true
|
|
2404
|
+
};
|
|
2405
|
+
}
|
|
2406
|
+
__name(resolveMarkdownConfig, "resolveMarkdownConfig");
|
|
2407
|
+
function normalizeMarkdownRouteInput(input) {
|
|
2408
|
+
if (typeof input === "string") {
|
|
2409
|
+
return {
|
|
2410
|
+
route: normalizeMarkdownRoute(input)
|
|
2411
|
+
};
|
|
2412
|
+
}
|
|
2413
|
+
return {
|
|
2414
|
+
...input,
|
|
2415
|
+
route: normalizeMarkdownRoute(input.route)
|
|
2416
|
+
};
|
|
2417
|
+
}
|
|
2418
|
+
__name(normalizeMarkdownRouteInput, "normalizeMarkdownRouteInput");
|
|
2419
|
+
function normalizeMarkdownRoute(route) {
|
|
2420
|
+
const withoutMarkdownExtension = route.endsWith(".md") ? route.slice(0, -3) : route;
|
|
2421
|
+
const withSlash = withoutMarkdownExtension.startsWith("/") ? withoutMarkdownExtension : `/${withoutMarkdownExtension}`;
|
|
2422
|
+
const normalized = withSlash.replace(/\/+/g, "/").replace(/\/$/g, "");
|
|
2423
|
+
return normalized === "" || normalized === "/index" ? "/" : normalized;
|
|
2424
|
+
}
|
|
2425
|
+
__name(normalizeMarkdownRoute, "normalizeMarkdownRoute");
|
|
2426
|
+
|
|
2427
|
+
// src/workflows.ts
|
|
2428
|
+
var DEFAULT_FARM_WORKFLOW_DIRS = ["src/jobs", "src/workflows", "src/cron"];
|
|
2429
|
+
var DEFAULT_FARM_WORKFLOW_ROUTE = "/api/_farm/workflows";
|
|
2430
|
+
var DEFAULT_FARM_WORKFLOW_SECRET_ENV = "CRON_SECRET";
|
|
2431
|
+
function resolveWorkflowsConfig(workflows) {
|
|
2432
|
+
if (workflows === false) {
|
|
2433
|
+
return {
|
|
2434
|
+
enabled: false,
|
|
2435
|
+
dirs: [...DEFAULT_FARM_WORKFLOW_DIRS],
|
|
2436
|
+
route: DEFAULT_FARM_WORKFLOW_ROUTE,
|
|
2437
|
+
secretEnv: DEFAULT_FARM_WORKFLOW_SECRET_ENV
|
|
2438
|
+
};
|
|
2439
|
+
}
|
|
2440
|
+
const options = workflows && typeof workflows === "object" ? workflows : {};
|
|
2441
|
+
const dirs = normalizeWorkflowDirs(options);
|
|
2442
|
+
return {
|
|
2443
|
+
enabled: options.enabled ?? true,
|
|
2444
|
+
dirs,
|
|
2445
|
+
route: normalizeWorkflowRoute(options.route || DEFAULT_FARM_WORKFLOW_ROUTE),
|
|
2446
|
+
secretEnv: options.secretEnv || DEFAULT_FARM_WORKFLOW_SECRET_ENV,
|
|
2447
|
+
secret: options.secret
|
|
2448
|
+
};
|
|
2449
|
+
}
|
|
2450
|
+
__name(resolveWorkflowsConfig, "resolveWorkflowsConfig");
|
|
2451
|
+
function normalizeWorkflowDirs(options) {
|
|
2452
|
+
const rawDirs = options.dirs || (Array.isArray(options.dir) ? options.dir : options.dir ? [options.dir] : void 0);
|
|
2453
|
+
const dirs = rawDirs && rawDirs.length > 0 ? rawDirs : DEFAULT_FARM_WORKFLOW_DIRS;
|
|
2454
|
+
return [...new Set(dirs.map((dir) => trimSlashes(dir)).filter(Boolean))];
|
|
2455
|
+
}
|
|
2456
|
+
__name(normalizeWorkflowDirs, "normalizeWorkflowDirs");
|
|
2457
|
+
function normalizeWorkflowRoute(route) {
|
|
2458
|
+
const trimmed = route.trim();
|
|
2459
|
+
if (!trimmed || trimmed === "/") return DEFAULT_FARM_WORKFLOW_ROUTE;
|
|
2460
|
+
return `/${trimSlashes(trimmed)}`;
|
|
2461
|
+
}
|
|
2462
|
+
__name(normalizeWorkflowRoute, "normalizeWorkflowRoute");
|
|
2463
|
+
function trimSlashes(value) {
|
|
2464
|
+
return value.replace(/^\/+|\/+$/g, "");
|
|
2465
|
+
}
|
|
2466
|
+
__name(trimSlashes, "trimSlashes");
|
|
2467
|
+
|
|
2468
|
+
// src/cron.ts
|
|
2469
|
+
var DEFAULT_FARM_CRON_SECRET_ENV = "CRON_SECRET";
|
|
2470
|
+
var CRON_FIELD_RANGES = [
|
|
2471
|
+
[0, 59, "minute"],
|
|
2472
|
+
[0, 23, "hour"],
|
|
2473
|
+
[1, 31, "day of month"],
|
|
2474
|
+
[1, 12, "month"],
|
|
2475
|
+
[0, 6, "day of week"]
|
|
2476
|
+
];
|
|
2477
|
+
function resolveCronConfig(cron) {
|
|
2478
|
+
if (isResolvedCronConfig(cron)) return cron;
|
|
2479
|
+
if (!cron) {
|
|
2480
|
+
return {
|
|
2481
|
+
enabled: false,
|
|
2482
|
+
secretEnv: DEFAULT_FARM_CRON_SECRET_ENV,
|
|
2483
|
+
jobs: []
|
|
2484
|
+
};
|
|
2485
|
+
}
|
|
2486
|
+
const jobs = [];
|
|
2487
|
+
for (const [name, job] of Object.entries(cron)) {
|
|
2488
|
+
if (!job || typeof job !== "object" || Array.isArray(job)) {
|
|
2489
|
+
throw new TypeError(`Farm cron ${JSON.stringify(name)} must be a configuration object.`);
|
|
2490
|
+
}
|
|
2491
|
+
if (job.enabled === false) continue;
|
|
2492
|
+
jobs.push(normalizeCronJob(name, job));
|
|
2493
|
+
}
|
|
2494
|
+
return {
|
|
2495
|
+
enabled: jobs.length > 0,
|
|
2496
|
+
secretEnv: DEFAULT_FARM_CRON_SECRET_ENV,
|
|
2497
|
+
jobs
|
|
2498
|
+
};
|
|
2499
|
+
}
|
|
2500
|
+
__name(resolveCronConfig, "resolveCronConfig");
|
|
2501
|
+
function normalizeCronJob(name, job) {
|
|
2502
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(name)) {
|
|
2503
|
+
throw new TypeError(
|
|
2504
|
+
`Farm cron name ${JSON.stringify(name)} must start with a letter or number and contain only letters, numbers, dots, underscores, or hyphens.`
|
|
2505
|
+
);
|
|
2506
|
+
}
|
|
2507
|
+
if (!job || typeof job !== "object" || Array.isArray(job)) {
|
|
2508
|
+
throw new TypeError(`Farm cron ${JSON.stringify(name)} must be a configuration object.`);
|
|
2509
|
+
}
|
|
2510
|
+
const path4 = normalizeCronPath(name, job.path);
|
|
2511
|
+
const rawSchedule = Array.isArray(job.schedule) ? job.schedule : [job.schedule];
|
|
2512
|
+
const schedule = [...new Set(rawSchedule.map((value) => normalizeCronExpression(name, value)))];
|
|
2513
|
+
if (schedule.length === 0) {
|
|
2514
|
+
throw new TypeError(`Farm cron ${JSON.stringify(name)} must define at least one schedule.`);
|
|
2515
|
+
}
|
|
2516
|
+
return {
|
|
2517
|
+
name,
|
|
2518
|
+
schedule,
|
|
2519
|
+
path: path4,
|
|
2520
|
+
description: job.description?.trim() || void 0
|
|
2521
|
+
};
|
|
2522
|
+
}
|
|
2523
|
+
__name(normalizeCronJob, "normalizeCronJob");
|
|
2524
|
+
function normalizeCronPath(name, value) {
|
|
2525
|
+
if (typeof value !== "string" || !value.trim().startsWith("/")) {
|
|
2526
|
+
throw new TypeError(`Farm cron ${JSON.stringify(name)} path must start with "/".`);
|
|
2527
|
+
}
|
|
2528
|
+
const path4 = value.trim();
|
|
2529
|
+
if (path4.startsWith("//") || path4.includes("?") || path4.includes("#")) {
|
|
2530
|
+
throw new TypeError(
|
|
2531
|
+
`Farm cron ${JSON.stringify(name)} path must be an application pathname without a host, query, or hash.`
|
|
2532
|
+
);
|
|
2533
|
+
}
|
|
2534
|
+
return path4.length > 1 ? path4.replace(/\/+$/, "") : path4;
|
|
2535
|
+
}
|
|
2536
|
+
__name(normalizeCronPath, "normalizeCronPath");
|
|
2537
|
+
function normalizeCronExpression(name, value) {
|
|
2538
|
+
if (typeof value !== "string") {
|
|
2539
|
+
throw new TypeError(`Farm cron ${JSON.stringify(name)} schedule must be a string.`);
|
|
2540
|
+
}
|
|
2541
|
+
const expression = value.trim().replace(/\s+/g, " ");
|
|
2542
|
+
const fields = expression.split(" ");
|
|
2543
|
+
if (fields.length !== CRON_FIELD_RANGES.length) {
|
|
2544
|
+
throw new TypeError(
|
|
2545
|
+
`Farm cron ${JSON.stringify(name)} schedule ${JSON.stringify(expression)} must use five fields: minute hour day-of-month month day-of-week.`
|
|
2546
|
+
);
|
|
2547
|
+
}
|
|
2548
|
+
fields.forEach((field, index) => {
|
|
2549
|
+
const [minimum, maximum, label] = CRON_FIELD_RANGES[index];
|
|
2550
|
+
validateCronField(name, expression, field, minimum, maximum, label);
|
|
2551
|
+
});
|
|
2552
|
+
if (fields[2] !== "*" && fields[4] !== "*") {
|
|
2553
|
+
throw new TypeError(
|
|
2554
|
+
`Farm cron ${JSON.stringify(name)} schedule ${JSON.stringify(expression)} cannot constrain both day-of-month and day-of-week.`
|
|
2555
|
+
);
|
|
2556
|
+
}
|
|
2557
|
+
return expression;
|
|
2558
|
+
}
|
|
2559
|
+
__name(normalizeCronExpression, "normalizeCronExpression");
|
|
2560
|
+
function validateCronField(name, expression, field, minimum, maximum, label) {
|
|
2561
|
+
for (const segment of field.split(",")) {
|
|
2562
|
+
const [range, stepText, ...extra] = segment.split("/");
|
|
2563
|
+
if (!range || extra.length > 0 || stepText !== void 0 && !isIntegerInRange(stepText, 1)) {
|
|
2564
|
+
throwInvalidCronField(name, expression, label);
|
|
2565
|
+
}
|
|
2566
|
+
if (range === "*") continue;
|
|
2567
|
+
const bounds = range.split("-");
|
|
2568
|
+
if (bounds.length > 2 || !bounds.every((value) => isIntegerInRange(value, minimum, maximum))) {
|
|
2569
|
+
throwInvalidCronField(name, expression, label);
|
|
2570
|
+
}
|
|
2571
|
+
if (bounds.length === 2 && Number(bounds[0]) > Number(bounds[1])) {
|
|
2572
|
+
throwInvalidCronField(name, expression, label);
|
|
2573
|
+
}
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
__name(validateCronField, "validateCronField");
|
|
2577
|
+
function isIntegerInRange(value, minimum, maximum = Number.MAX_SAFE_INTEGER) {
|
|
2578
|
+
if (!/^\d+$/.test(value)) return false;
|
|
2579
|
+
const parsed = Number(value);
|
|
2580
|
+
return parsed >= minimum && parsed <= maximum;
|
|
2581
|
+
}
|
|
2582
|
+
__name(isIntegerInRange, "isIntegerInRange");
|
|
2583
|
+
function throwInvalidCronField(name, expression, label) {
|
|
2584
|
+
throw new TypeError(
|
|
2585
|
+
`Farm cron ${JSON.stringify(name)} schedule ${JSON.stringify(expression)} has an invalid ${label} field.`
|
|
2586
|
+
);
|
|
2587
|
+
}
|
|
2588
|
+
__name(throwInvalidCronField, "throwInvalidCronField");
|
|
2589
|
+
function isResolvedCronConfig(value) {
|
|
2590
|
+
return !!value && typeof value === "object" && "enabled" in value && typeof value.enabled === "boolean" && "jobs" in value && Array.isArray(value.jobs) && "secretEnv" in value;
|
|
2591
|
+
}
|
|
2592
|
+
__name(isResolvedCronConfig, "isResolvedCronConfig");
|
|
2593
|
+
|
|
2594
|
+
// src/env.ts
|
|
2595
|
+
var FARM_ENV_SYMBOL = /* @__PURE__ */ Symbol.for("farm.env");
|
|
2596
|
+
var farmEnvGlobal = globalThis;
|
|
2597
|
+
var currentEnv = getInitialEnv();
|
|
2598
|
+
function resolveEnv(config, source = getProcessEnv()) {
|
|
2599
|
+
const resolved = {
|
|
2600
|
+
server: resolveEnvScope(config?.server, source, "server"),
|
|
2601
|
+
public: resolveEnvScope(config?.public, source, "public")
|
|
2602
|
+
};
|
|
2603
|
+
return resolved;
|
|
2604
|
+
}
|
|
2605
|
+
__name(resolveEnv, "resolveEnv");
|
|
2606
|
+
function setEnv(env2) {
|
|
2607
|
+
currentEnv = normalizeResolvedEnv(env2);
|
|
2608
|
+
if (typeof window === "undefined") {
|
|
2609
|
+
farmEnvGlobal[FARM_ENV_SYMBOL] = currentEnv;
|
|
2610
|
+
}
|
|
2611
|
+
}
|
|
2612
|
+
__name(setEnv, "setEnv");
|
|
2613
|
+
var env = createEnvProxy("server");
|
|
2614
|
+
var publicEnv = createEnvProxy("public");
|
|
2615
|
+
function resolveEnvScope(shape, source, scope) {
|
|
2616
|
+
if (!shape) {
|
|
2617
|
+
return {};
|
|
2618
|
+
}
|
|
2619
|
+
const resolved = {};
|
|
2620
|
+
for (const [key, parser] of Object.entries(shape)) {
|
|
2621
|
+
try {
|
|
2622
|
+
resolved[key] = parseEnvValue(parser, source[key], key, scope);
|
|
2623
|
+
} catch (error) {
|
|
2624
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2625
|
+
throw new Error(`Invalid ${scope} env "${key}": ${message}`);
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
return resolved;
|
|
2629
|
+
}
|
|
2630
|
+
__name(resolveEnvScope, "resolveEnvScope");
|
|
2631
|
+
function parseEnvValue(parser, value, key, scope) {
|
|
2632
|
+
if (typeof parser === "function") {
|
|
2633
|
+
return parser(value, { key, scope });
|
|
2634
|
+
}
|
|
2635
|
+
if (parser && typeof parser.parse === "function") {
|
|
2636
|
+
return parser.parse(value);
|
|
2637
|
+
}
|
|
2638
|
+
throw new Error("expected a parser function or schema with parse()");
|
|
2639
|
+
}
|
|
2640
|
+
__name(parseEnvValue, "parseEnvValue");
|
|
2641
|
+
function createEnvProxy(scope) {
|
|
2642
|
+
return new Proxy(
|
|
2643
|
+
{},
|
|
2644
|
+
{
|
|
2645
|
+
get(_target, property) {
|
|
2646
|
+
if (typeof property === "symbol") {
|
|
2647
|
+
return void 0;
|
|
2648
|
+
}
|
|
2649
|
+
const env2 = getEnvScope(scope);
|
|
2650
|
+
return env2[property];
|
|
2651
|
+
},
|
|
2652
|
+
ownKeys() {
|
|
2653
|
+
return Reflect.ownKeys(getEnvScope(scope));
|
|
2654
|
+
},
|
|
2655
|
+
getOwnPropertyDescriptor(_target, property) {
|
|
2656
|
+
const env2 = getEnvScope(scope);
|
|
2657
|
+
if (!(property in env2)) {
|
|
2658
|
+
return void 0;
|
|
2659
|
+
}
|
|
2660
|
+
return {
|
|
2661
|
+
enumerable: true,
|
|
2662
|
+
configurable: true,
|
|
2663
|
+
value: env2[property]
|
|
2664
|
+
};
|
|
2665
|
+
},
|
|
2666
|
+
has(_target, property) {
|
|
2667
|
+
return property in getEnvScope(scope);
|
|
2668
|
+
}
|
|
2669
|
+
}
|
|
2670
|
+
);
|
|
2671
|
+
}
|
|
2672
|
+
__name(createEnvProxy, "createEnvProxy");
|
|
2673
|
+
function getEnvScope(scope) {
|
|
2674
|
+
if (scope === "server") {
|
|
2675
|
+
assertServerEnvAccess();
|
|
2676
|
+
}
|
|
2677
|
+
return getCurrentEnv()[scope] || {};
|
|
2678
|
+
}
|
|
2679
|
+
__name(getEnvScope, "getEnvScope");
|
|
2680
|
+
function assertServerEnvAccess() {
|
|
2681
|
+
if (typeof window !== "undefined") {
|
|
2682
|
+
throw new Error("Farm server env is not available in the browser. Use publicEnv.");
|
|
2683
|
+
}
|
|
2684
|
+
}
|
|
2685
|
+
__name(assertServerEnvAccess, "assertServerEnvAccess");
|
|
2686
|
+
function getInitialEnv() {
|
|
2687
|
+
const injectedEnv = getInjectedEnv();
|
|
2688
|
+
if (injectedEnv) {
|
|
2689
|
+
return injectedEnv;
|
|
2690
|
+
}
|
|
2691
|
+
if (typeof window === "undefined" && farmEnvGlobal[FARM_ENV_SYMBOL]) {
|
|
2692
|
+
return normalizeResolvedEnv(farmEnvGlobal[FARM_ENV_SYMBOL]);
|
|
2693
|
+
}
|
|
2694
|
+
return {
|
|
2695
|
+
server: {},
|
|
2696
|
+
public: getInjectedPublicEnv()
|
|
2697
|
+
};
|
|
2698
|
+
}
|
|
2699
|
+
__name(getInitialEnv, "getInitialEnv");
|
|
2700
|
+
function getCurrentEnv() {
|
|
2701
|
+
if (typeof window === "undefined" && farmEnvGlobal[FARM_ENV_SYMBOL]) {
|
|
2702
|
+
return farmEnvGlobal[FARM_ENV_SYMBOL];
|
|
2703
|
+
}
|
|
2704
|
+
return currentEnv;
|
|
2705
|
+
}
|
|
2706
|
+
__name(getCurrentEnv, "getCurrentEnv");
|
|
2707
|
+
function getInjectedEnv() {
|
|
2708
|
+
try {
|
|
2709
|
+
if (typeof __FARM_ENV__ !== "undefined" && __FARM_ENV__) {
|
|
2710
|
+
return normalizeResolvedEnv(__FARM_ENV__);
|
|
2711
|
+
}
|
|
2712
|
+
} catch {
|
|
2713
|
+
}
|
|
2714
|
+
return null;
|
|
2715
|
+
}
|
|
2716
|
+
__name(getInjectedEnv, "getInjectedEnv");
|
|
2717
|
+
function getInjectedPublicEnv() {
|
|
2718
|
+
try {
|
|
2719
|
+
if (typeof __FARM_PUBLIC_ENV__ !== "undefined" && __FARM_PUBLIC_ENV__) {
|
|
2720
|
+
return __FARM_PUBLIC_ENV__;
|
|
2721
|
+
}
|
|
2722
|
+
} catch {
|
|
2723
|
+
}
|
|
2724
|
+
return {};
|
|
2725
|
+
}
|
|
2726
|
+
__name(getInjectedPublicEnv, "getInjectedPublicEnv");
|
|
2727
|
+
function normalizeResolvedEnv(env2) {
|
|
2728
|
+
return {
|
|
2729
|
+
server: isRecord(env2.server) ? env2.server : {},
|
|
2730
|
+
public: isRecord(env2.public) ? env2.public : {}
|
|
2731
|
+
};
|
|
2732
|
+
}
|
|
2733
|
+
__name(normalizeResolvedEnv, "normalizeResolvedEnv");
|
|
2734
|
+
function isRecord(value) {
|
|
2735
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
2736
|
+
}
|
|
2737
|
+
__name(isRecord, "isRecord");
|
|
2738
|
+
function getProcessEnv() {
|
|
2739
|
+
if (typeof process !== "undefined" && process.env) {
|
|
2740
|
+
return process.env;
|
|
2741
|
+
}
|
|
2742
|
+
return {};
|
|
2743
|
+
}
|
|
2744
|
+
__name(getProcessEnv, "getProcessEnv");
|
|
2745
|
+
|
|
2746
|
+
// src/app-markdown.ts
|
|
2747
|
+
var import_react = __toESM(require("react"));
|
|
2748
|
+
function resolveMdxConfig(config) {
|
|
2749
|
+
return {
|
|
2750
|
+
components: config?.components,
|
|
2751
|
+
markdownRoutes: config?.markdownRoutes ?? true,
|
|
2752
|
+
className: config?.className ?? "farm-markdown"
|
|
2753
|
+
};
|
|
2754
|
+
}
|
|
2755
|
+
__name(resolveMdxConfig, "resolveMdxConfig");
|
|
2756
|
+
|
|
2757
|
+
// src/route-runtime.ts
|
|
2758
|
+
function normalizeFarmRouteRuntimeConfig(value, source = "Route configuration") {
|
|
2759
|
+
if (!value) return {};
|
|
2760
|
+
const normalized = {};
|
|
2761
|
+
if (value.runtime !== void 0) {
|
|
2762
|
+
if (value.runtime !== "auto" && value.runtime !== "node" && value.runtime !== "edge") {
|
|
2763
|
+
throw new TypeError(`${source} runtime must be "auto", "node", or "edge"`);
|
|
2764
|
+
}
|
|
2765
|
+
normalized.runtime = value.runtime;
|
|
2766
|
+
}
|
|
2767
|
+
if (value.regions !== void 0) {
|
|
2768
|
+
if (value.regions === "auto") {
|
|
2769
|
+
normalized.regions = "auto";
|
|
2770
|
+
} else {
|
|
2771
|
+
if (!Array.isArray(value.regions) || value.regions.length === 0) {
|
|
2772
|
+
throw new TypeError(`${source} regions must be "auto" or a non-empty string array`);
|
|
2773
|
+
}
|
|
2774
|
+
const regions = Array.from(
|
|
2775
|
+
new Set(
|
|
2776
|
+
value.regions.map((region) => {
|
|
2777
|
+
if (typeof region !== "string" || !region.trim() || /[\u0000-\u001f\u007f]/.test(region)) {
|
|
2778
|
+
throw new TypeError(`${source} regions must contain non-empty region identifiers`);
|
|
2779
|
+
}
|
|
2780
|
+
return region.trim();
|
|
2781
|
+
})
|
|
2782
|
+
)
|
|
2783
|
+
);
|
|
2784
|
+
normalized.regions = regions;
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
if (value.maxDuration !== void 0) {
|
|
2788
|
+
if (value.maxDuration === "auto") {
|
|
2789
|
+
normalized.maxDuration = "auto";
|
|
2790
|
+
} else if (typeof value.maxDuration !== "number" || !Number.isInteger(value.maxDuration) || value.maxDuration <= 0) {
|
|
2791
|
+
throw new TypeError(`${source} maxDuration must be "auto" or a positive integer in seconds`);
|
|
2792
|
+
} else {
|
|
2793
|
+
normalized.maxDuration = value.maxDuration;
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2796
|
+
return normalized;
|
|
2797
|
+
}
|
|
2798
|
+
__name(normalizeFarmRouteRuntimeConfig, "normalizeFarmRouteRuntimeConfig");
|
|
2799
|
+
|
|
2800
|
+
// src/route-rules.ts
|
|
2801
|
+
function normalizeRouteRules(routeRules) {
|
|
2802
|
+
if (!routeRules) return {};
|
|
2803
|
+
const normalized = {};
|
|
2804
|
+
for (const [source, rule] of Object.entries(routeRules)) {
|
|
2805
|
+
if (!source || !rule) continue;
|
|
2806
|
+
const normalizedSource = normalizeRuleSource(source);
|
|
2807
|
+
normalized[normalizedSource] = {
|
|
2808
|
+
...rule,
|
|
2809
|
+
...normalizeFarmRouteRuntimeConfig(rule, `Route rule "${normalizedSource}"`)
|
|
2810
|
+
};
|
|
2811
|
+
}
|
|
2812
|
+
return normalized;
|
|
2813
|
+
}
|
|
2814
|
+
__name(normalizeRouteRules, "normalizeRouteRules");
|
|
2815
|
+
function routeRulesToRedirects(routeRules) {
|
|
2816
|
+
return Object.entries(routeRules).filter(
|
|
2817
|
+
(entry) => Boolean(entry[1].redirect)
|
|
2818
|
+
).map(([source, rule]) => {
|
|
2819
|
+
const redirect = typeof rule.redirect === "string" ? { to: rule.redirect } : rule.redirect;
|
|
2820
|
+
return {
|
|
2821
|
+
source,
|
|
2822
|
+
destination: redirect.to,
|
|
2823
|
+
permanent: redirect.permanent,
|
|
2824
|
+
statusCode: redirect.statusCode ?? (redirect.permanent === true ? 308 : void 0)
|
|
2825
|
+
};
|
|
2826
|
+
});
|
|
2827
|
+
}
|
|
2828
|
+
__name(routeRulesToRedirects, "routeRulesToRedirects");
|
|
2829
|
+
function routeRulesToHeaders(routeRules) {
|
|
2830
|
+
const configs = [];
|
|
2831
|
+
for (const [source, rule] of Object.entries(routeRules)) {
|
|
2832
|
+
const headers = {
|
|
2833
|
+
...normalizeCorsHeaders(rule.cors),
|
|
2834
|
+
...rule.headers || {}
|
|
2835
|
+
};
|
|
2836
|
+
const entries = Object.entries(headers);
|
|
2837
|
+
if (entries.length === 0) continue;
|
|
2838
|
+
configs.push({
|
|
2839
|
+
source,
|
|
2840
|
+
headers: entries.map(([key, value]) => ({ key, value }))
|
|
2841
|
+
});
|
|
2842
|
+
}
|
|
2843
|
+
return configs;
|
|
2844
|
+
}
|
|
2845
|
+
__name(routeRulesToHeaders, "routeRulesToHeaders");
|
|
2846
|
+
function normalizeCorsHeaders(cors) {
|
|
2847
|
+
if (!cors) return {};
|
|
2848
|
+
if (cors === true) {
|
|
2849
|
+
return {
|
|
2850
|
+
"Access-Control-Allow-Origin": "*",
|
|
2851
|
+
"Access-Control-Allow-Methods": "*",
|
|
2852
|
+
"Access-Control-Allow-Headers": "*"
|
|
2853
|
+
};
|
|
2854
|
+
}
|
|
2855
|
+
return {
|
|
2856
|
+
"Access-Control-Allow-Origin": cors.origin ?? "*",
|
|
2857
|
+
"Access-Control-Allow-Methods": normalizeList(cors.methods) ?? "*",
|
|
2858
|
+
"Access-Control-Allow-Headers": normalizeList(cors.headers) ?? "*"
|
|
2859
|
+
};
|
|
2860
|
+
}
|
|
2861
|
+
__name(normalizeCorsHeaders, "normalizeCorsHeaders");
|
|
2862
|
+
function normalizeList(value) {
|
|
2863
|
+
if (!value || typeof value === "string") return value;
|
|
2864
|
+
return value.join(", ");
|
|
2865
|
+
}
|
|
2866
|
+
__name(normalizeList, "normalizeList");
|
|
2867
|
+
function normalizeRuleSource(source) {
|
|
2868
|
+
const trimmed = source.trim();
|
|
2869
|
+
if (!trimmed) return "/";
|
|
2870
|
+
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
2871
|
+
}
|
|
2872
|
+
__name(normalizeRuleSource, "normalizeRuleSource");
|
|
2873
|
+
|
|
2874
|
+
// src/server-action-security.ts
|
|
2875
|
+
var import_node_async_hooks = require("async_hooks");
|
|
2876
|
+
|
|
2877
|
+
// src/cache-invalidation.ts
|
|
2878
|
+
var FARM_CACHE_INVALIDATION_STATE = /* @__PURE__ */ Symbol.for("farm.cacheInvalidationState");
|
|
2879
|
+
var globalState = globalThis;
|
|
2880
|
+
function getFarmCacheInvalidationState() {
|
|
2881
|
+
return globalState[FARM_CACHE_INVALIDATION_STATE] ?? (globalState[FARM_CACHE_INVALIDATION_STATE] = {
|
|
2882
|
+
listeners: /* @__PURE__ */ new Set()
|
|
2883
|
+
});
|
|
2884
|
+
}
|
|
2885
|
+
__name(getFarmCacheInvalidationState, "getFarmCacheInvalidationState");
|
|
2886
|
+
function subscribeFarmCacheInvalidation(listener) {
|
|
2887
|
+
const state = getFarmCacheInvalidationState();
|
|
2888
|
+
state.listeners.add(listener);
|
|
2889
|
+
return () => state.listeners.delete(listener);
|
|
2890
|
+
}
|
|
2891
|
+
__name(subscribeFarmCacheInvalidation, "subscribeFarmCacheInvalidation");
|
|
2892
|
+
|
|
2893
|
+
// src/server-action-security.ts
|
|
2894
|
+
var DEFAULT_SERVER_ACTION_BODY_SIZE_LIMIT = 1e6;
|
|
2895
|
+
var SERVER_ACTION_STORAGE_KEY = /* @__PURE__ */ Symbol.for("farm.serverActionStorage");
|
|
2896
|
+
function resolveServerActionsConfig(config) {
|
|
2897
|
+
const allowedOrigins = (config?.allowedOrigins ?? []).map(normalizeAllowedOriginPattern);
|
|
2898
|
+
const bodySizeLimit = parseBodySizeLimit(
|
|
2899
|
+
config?.bodySizeLimit ?? DEFAULT_SERVER_ACTION_BODY_SIZE_LIMIT
|
|
2900
|
+
);
|
|
2901
|
+
return Object.freeze({
|
|
2902
|
+
allowedOrigins: Object.freeze(allowedOrigins),
|
|
2903
|
+
bodySizeLimit
|
|
2904
|
+
});
|
|
2905
|
+
}
|
|
2906
|
+
__name(resolveServerActionsConfig, "resolveServerActionsConfig");
|
|
2907
|
+
function getServerActionExecutionContext() {
|
|
2908
|
+
return getServerActionStorage().getStore();
|
|
2909
|
+
}
|
|
2910
|
+
__name(getServerActionExecutionContext, "getServerActionExecutionContext");
|
|
2911
|
+
subscribeFarmCacheInvalidation((key) => {
|
|
2912
|
+
getServerActionExecutionContext()?.invalidations.add(key);
|
|
2913
|
+
});
|
|
2914
|
+
function getServerActionStorage() {
|
|
2915
|
+
const globalState2 = globalThis;
|
|
2916
|
+
if (!globalState2[SERVER_ACTION_STORAGE_KEY]) {
|
|
2917
|
+
globalState2[SERVER_ACTION_STORAGE_KEY] = new import_node_async_hooks.AsyncLocalStorage();
|
|
2918
|
+
}
|
|
2919
|
+
return globalState2[SERVER_ACTION_STORAGE_KEY];
|
|
2920
|
+
}
|
|
2921
|
+
__name(getServerActionStorage, "getServerActionStorage");
|
|
2922
|
+
function parseBodySizeLimit(value) {
|
|
2923
|
+
if (typeof value === "number") {
|
|
2924
|
+
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
2925
|
+
throw new TypeError("serverActions.bodySizeLimit must be a positive safe integer");
|
|
2926
|
+
}
|
|
2927
|
+
return value;
|
|
2928
|
+
}
|
|
2929
|
+
const match = value.trim().toLowerCase().match(/^(\d+(?:\.\d+)?)\s*(b|kb|mb|gb|kib|mib|gib)?$/);
|
|
2930
|
+
if (!match) {
|
|
2931
|
+
throw new TypeError(
|
|
2932
|
+
'serverActions.bodySizeLimit must be bytes or a size string such as "500kb" or "1mb"'
|
|
2933
|
+
);
|
|
2934
|
+
}
|
|
2935
|
+
const amount = Number(match[1]);
|
|
2936
|
+
const unit = match[2] ?? "b";
|
|
2937
|
+
const multiplier = {
|
|
2938
|
+
b: 1,
|
|
2939
|
+
kb: 1e3,
|
|
2940
|
+
mb: 1e6,
|
|
2941
|
+
gb: 1e9,
|
|
2942
|
+
kib: 1024,
|
|
2943
|
+
mib: 1048576,
|
|
2944
|
+
gib: 1073741824
|
|
2945
|
+
};
|
|
2946
|
+
const bytes = Math.floor(amount * multiplier[unit]);
|
|
2947
|
+
if (!Number.isSafeInteger(bytes) || bytes <= 0) {
|
|
2948
|
+
throw new TypeError("serverActions.bodySizeLimit must resolve to a positive safe integer");
|
|
2949
|
+
}
|
|
2950
|
+
return bytes;
|
|
2951
|
+
}
|
|
2952
|
+
__name(parseBodySizeLimit, "parseBodySizeLimit");
|
|
2953
|
+
function normalizeAllowedOriginPattern(value) {
|
|
2954
|
+
const pattern = value.trim().toLowerCase();
|
|
2955
|
+
if (!pattern) {
|
|
2956
|
+
throw new TypeError("serverActions.allowedOrigins cannot contain empty values");
|
|
2957
|
+
}
|
|
2958
|
+
if (pattern.includes("*")) {
|
|
2959
|
+
if (!/^(?:https?:\/\/)?\*\.[a-z0-9.-]+(?::\d+)?$/.test(pattern)) {
|
|
2960
|
+
throw new TypeError(`Invalid serverActions.allowedOrigins pattern: ${JSON.stringify(value)}`);
|
|
2961
|
+
}
|
|
2962
|
+
return pattern;
|
|
2963
|
+
}
|
|
2964
|
+
if (pattern.includes("://")) {
|
|
2965
|
+
let parsed;
|
|
2966
|
+
try {
|
|
2967
|
+
parsed = new URL(pattern);
|
|
2968
|
+
} catch {
|
|
2969
|
+
throw new TypeError(`Invalid serverActions.allowedOrigins value: ${JSON.stringify(value)}`);
|
|
2970
|
+
}
|
|
2971
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:" || parsed.username || parsed.password || parsed.pathname !== "/" || parsed.search || parsed.hash) {
|
|
2972
|
+
throw new TypeError(
|
|
2973
|
+
`serverActions.allowedOrigins must contain origins without paths: ${JSON.stringify(value)}`
|
|
2974
|
+
);
|
|
2975
|
+
}
|
|
2976
|
+
return parsed.origin;
|
|
2977
|
+
}
|
|
2978
|
+
if (/[/@?#]/.test(pattern)) {
|
|
2979
|
+
throw new TypeError(
|
|
2980
|
+
`serverActions.allowedOrigins must contain origins or hosts: ${JSON.stringify(value)}`
|
|
2981
|
+
);
|
|
2982
|
+
}
|
|
2983
|
+
try {
|
|
2984
|
+
return new URL(`http://${pattern}`).host;
|
|
2985
|
+
} catch {
|
|
2986
|
+
throw new TypeError(`Invalid serverActions.allowedOrigins value: ${JSON.stringify(value)}`);
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
__name(normalizeAllowedOriginPattern, "normalizeAllowedOriginPattern");
|
|
2990
|
+
|
|
2991
|
+
// src/layers.ts
|
|
2992
|
+
var import_node_fs = require("fs");
|
|
2993
|
+
var import_promises = require("fs/promises");
|
|
2994
|
+
var import_node_module = require("module");
|
|
2995
|
+
var import_node_path = __toESM(require("path"));
|
|
2996
|
+
var import_node_url = require("url");
|
|
2997
|
+
var FARM_CORE_PACKAGE = "@farm.js/core";
|
|
2998
|
+
var FARM_CONFIG_ENTRY = "@farm.js/core/config";
|
|
2999
|
+
var FARM_CORE_REFERENCE_RE = /(["'])@farm.js\/core\1/g;
|
|
3000
|
+
var FARM_CONFIG_HELPER_IMPORT_RE = /(?:^|\n)[\t ]*import[\t ]*\{([^{}]*)\}[\t ]*from[\t ]*(["'])@farm.js\/core\2[\t ]*;?[\t ]*(?:\n|$)/g;
|
|
3001
|
+
var FARM_CONFIG_HELPER_SPECIFIER_RE = /^(?:defineConfig|defineFarmConfig)(?:\s+as\s+[$A-Z_a-z][$\w]*)?$/;
|
|
3002
|
+
var CONFIG_FILENAMES = [
|
|
3003
|
+
"farm.config.ts",
|
|
3004
|
+
"farm.config.tsx",
|
|
3005
|
+
"farm.config.mts",
|
|
3006
|
+
"farm.config.cts",
|
|
3007
|
+
"farm.config.js",
|
|
3008
|
+
"farm.config.jsx",
|
|
3009
|
+
"farm.config.mjs",
|
|
3010
|
+
"farm.config.cjs",
|
|
3011
|
+
"config.ts",
|
|
3012
|
+
"config.tsx",
|
|
3013
|
+
"config.mts",
|
|
3014
|
+
"config.cts",
|
|
3015
|
+
"config.js",
|
|
3016
|
+
"config.jsx",
|
|
3017
|
+
"config.mjs",
|
|
3018
|
+
"config.cjs"
|
|
3019
|
+
];
|
|
3020
|
+
var LAYER_LOCAL_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
3021
|
+
"root",
|
|
3022
|
+
"srcDir",
|
|
3023
|
+
"outDir",
|
|
3024
|
+
"distDir",
|
|
3025
|
+
"deploy",
|
|
3026
|
+
"output",
|
|
3027
|
+
"preset",
|
|
3028
|
+
"publicDir",
|
|
3029
|
+
"generateBuildId"
|
|
3030
|
+
]);
|
|
3031
|
+
async function resolveFarmLayers(projectConfig, options) {
|
|
3032
|
+
const projectRoot = import_node_path.default.resolve(options.root);
|
|
3033
|
+
const entries = normalizeLayerEntries(projectConfig.extends, "project config");
|
|
3034
|
+
if (entries.length === 0) {
|
|
3035
|
+
return {
|
|
3036
|
+
config: {
|
|
3037
|
+
...projectConfig,
|
|
3038
|
+
layers: []
|
|
3039
|
+
},
|
|
3040
|
+
layers: []
|
|
3041
|
+
};
|
|
3042
|
+
}
|
|
3043
|
+
const loadedLayers = [];
|
|
3044
|
+
const visited = /* @__PURE__ */ new Set();
|
|
3045
|
+
const aliases = /* @__PURE__ */ new Map();
|
|
3046
|
+
const visit = /* @__PURE__ */ __name(async (source, ownerRoot, stack) => {
|
|
3047
|
+
const resolvedSource = resolveLayerSource(source, ownerRoot);
|
|
3048
|
+
const cycleIndex = stack.findIndex((entry) => entry.root === resolvedSource.root);
|
|
3049
|
+
if (cycleIndex !== -1) {
|
|
3050
|
+
const cycle = [...stack.slice(cycleIndex).map((entry) => entry.source), source];
|
|
3051
|
+
throw new Error(`Farm layer cycle detected: ${cycle.join(" -> ")}`);
|
|
3052
|
+
}
|
|
3053
|
+
if (visited.has(resolvedSource.root)) return;
|
|
3054
|
+
const configFile = findFarmConfigFile(resolvedSource.root, resolvedSource.configFile);
|
|
3055
|
+
const config = configFile ? await loadFarmConfigFile(configFile, {
|
|
3056
|
+
cacheRoot: projectRoot,
|
|
3057
|
+
root: resolvedSource.root
|
|
3058
|
+
}) : {};
|
|
3059
|
+
const nestedEntries = normalizeLayerEntries(config.extends, `layer ${JSON.stringify(source)}`);
|
|
3060
|
+
const nextStack = [...stack, { root: resolvedSource.root, source }];
|
|
3061
|
+
for (const nestedSource of nestedEntries) {
|
|
3062
|
+
await visit(nestedSource, resolvedSource.root, nextStack);
|
|
3063
|
+
}
|
|
3064
|
+
if (visited.has(resolvedSource.root)) return;
|
|
3065
|
+
const name = getLayerName(source, resolvedSource.root);
|
|
3066
|
+
const conflictingRoot = aliases.get(name);
|
|
3067
|
+
if (conflictingRoot && conflictingRoot !== resolvedSource.root) {
|
|
3068
|
+
throw new Error(
|
|
3069
|
+
`Farm layer alias "#layers/${name}" is ambiguous between ${conflictingRoot} and ${resolvedSource.root}`
|
|
3070
|
+
);
|
|
3071
|
+
}
|
|
3072
|
+
aliases.set(name, resolvedSource.root);
|
|
3073
|
+
visited.add(resolvedSource.root);
|
|
3074
|
+
loadedLayers.push({
|
|
3075
|
+
source,
|
|
3076
|
+
name,
|
|
3077
|
+
root: resolvedSource.root,
|
|
3078
|
+
srcDir: normalizeLayerSrcDir(config.srcDir),
|
|
3079
|
+
configFile,
|
|
3080
|
+
config
|
|
3081
|
+
});
|
|
3082
|
+
}, "visit");
|
|
3083
|
+
for (const source of entries) {
|
|
3084
|
+
await visit(source, projectRoot, []);
|
|
3085
|
+
}
|
|
3086
|
+
let mergedConfig = {};
|
|
3087
|
+
for (const layer of loadedLayers) {
|
|
3088
|
+
mergedConfig = mergeFarmLayerConfig(mergedConfig, getLayerDefaults(layer.config));
|
|
3089
|
+
}
|
|
3090
|
+
mergedConfig = mergeFarmLayerConfig(mergedConfig, projectConfig);
|
|
3091
|
+
const layers = loadedLayers.map(({ config: _config, ...layer }) => layer);
|
|
3092
|
+
return {
|
|
3093
|
+
config: {
|
|
3094
|
+
...mergedConfig,
|
|
3095
|
+
root: projectConfig.root,
|
|
3096
|
+
srcDir: projectConfig.srcDir,
|
|
3097
|
+
extends: projectConfig.extends,
|
|
3098
|
+
layers
|
|
3099
|
+
},
|
|
3100
|
+
layers
|
|
3101
|
+
};
|
|
3102
|
+
}
|
|
3103
|
+
__name(resolveFarmLayers, "resolveFarmLayers");
|
|
3104
|
+
async function loadFarmConfigFile(configPath, options) {
|
|
3105
|
+
const { build, transform } = await import("esbuild");
|
|
3106
|
+
const cacheRoot = import_node_path.default.resolve(options.cacheRoot || options.root);
|
|
3107
|
+
const configCacheDir = import_node_path.default.join(cacheRoot, ".farm", ".config-loader");
|
|
3108
|
+
const configEntryChecks = /* @__PURE__ */ new Map();
|
|
3109
|
+
await (0, import_promises.mkdir)(configCacheDir, { recursive: true });
|
|
3110
|
+
const modulePath = import_node_path.default.join(
|
|
3111
|
+
configCacheDir,
|
|
3112
|
+
`farm-config-${Date.now()}-${Math.random().toString(36).slice(2)}.mjs`
|
|
3113
|
+
);
|
|
3114
|
+
await build({
|
|
3115
|
+
absWorkingDir: import_node_path.default.resolve(options.root),
|
|
3116
|
+
entryPoints: [import_node_path.default.resolve(configPath)],
|
|
3117
|
+
outfile: modulePath,
|
|
3118
|
+
bundle: true,
|
|
3119
|
+
format: "esm",
|
|
3120
|
+
platform: "node",
|
|
3121
|
+
target: `node${process.versions.node.split(".")[0]}`,
|
|
3122
|
+
plugins: [
|
|
3123
|
+
{
|
|
3124
|
+
name: "farm-config-package-resolution",
|
|
3125
|
+
setup(pluginBuild) {
|
|
3126
|
+
pluginBuild.onResolve({ filter: /^@farm.js\/core$/ }, async (args) => {
|
|
3127
|
+
if (args.pluginData?.farmConfigExternal || args.kind !== "import-statement" || !args.importer) {
|
|
3128
|
+
return;
|
|
3129
|
+
}
|
|
3130
|
+
let configEntryCheck = configEntryChecks.get(args.importer);
|
|
3131
|
+
if (!configEntryCheck) {
|
|
3132
|
+
configEntryCheck = onlyImportsFarmConfigHelpers(args.importer, transform);
|
|
3133
|
+
configEntryChecks.set(args.importer, configEntryCheck);
|
|
3134
|
+
}
|
|
3135
|
+
if (!await configEntryCheck) return;
|
|
3136
|
+
const resolved = await pluginBuild.resolve(FARM_CONFIG_ENTRY, {
|
|
3137
|
+
importer: args.importer,
|
|
3138
|
+
kind: args.kind,
|
|
3139
|
+
namespace: args.namespace,
|
|
3140
|
+
resolveDir: args.resolveDir,
|
|
3141
|
+
pluginData: { farmConfigExternal: true }
|
|
3142
|
+
});
|
|
3143
|
+
if (resolved.errors.length > 0 || !resolved.path) return;
|
|
3144
|
+
return {
|
|
3145
|
+
path: resolved.path,
|
|
3146
|
+
external: true,
|
|
3147
|
+
warnings: resolved.warnings
|
|
3148
|
+
};
|
|
3149
|
+
});
|
|
3150
|
+
pluginBuild.onResolve({ filter: /^[^./]/ }, async (args) => {
|
|
3151
|
+
if (args.pluginData?.farmConfigExternal) return;
|
|
3152
|
+
const resolved = await pluginBuild.resolve(args.path, {
|
|
3153
|
+
importer: args.importer,
|
|
3154
|
+
kind: args.kind,
|
|
3155
|
+
namespace: args.namespace,
|
|
3156
|
+
resolveDir: args.resolveDir,
|
|
3157
|
+
pluginData: { farmConfigExternal: true }
|
|
3158
|
+
});
|
|
3159
|
+
if (resolved.errors.length > 0 || !resolved.path) {
|
|
3160
|
+
return { path: args.path, external: true };
|
|
3161
|
+
}
|
|
3162
|
+
return {
|
|
3163
|
+
path: resolved.path,
|
|
3164
|
+
external: true,
|
|
3165
|
+
warnings: resolved.warnings
|
|
3166
|
+
};
|
|
3167
|
+
});
|
|
3168
|
+
}
|
|
3169
|
+
}
|
|
3170
|
+
],
|
|
3171
|
+
jsx: "automatic",
|
|
3172
|
+
logLevel: "silent",
|
|
3173
|
+
sourcemap: "inline"
|
|
3174
|
+
});
|
|
3175
|
+
const moduleUrl = `${(0, import_node_url.pathToFileURL)(modulePath).href}?t=${Date.now()}`;
|
|
3176
|
+
try {
|
|
3177
|
+
const loaded = await import(
|
|
3178
|
+
/* @vite-ignore */
|
|
3179
|
+
moduleUrl
|
|
3180
|
+
);
|
|
3181
|
+
const config = loaded.default || loaded;
|
|
3182
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) {
|
|
3183
|
+
throw new TypeError(`Farm config ${configPath} must export an object`);
|
|
3184
|
+
}
|
|
3185
|
+
return config;
|
|
3186
|
+
} finally {
|
|
3187
|
+
await (0, import_promises.unlink)(modulePath).catch(() => void 0);
|
|
3188
|
+
}
|
|
3189
|
+
}
|
|
3190
|
+
__name(loadFarmConfigFile, "loadFarmConfigFile");
|
|
3191
|
+
async function onlyImportsFarmConfigHelpers(importer, transform) {
|
|
3192
|
+
try {
|
|
3193
|
+
const source = (0, import_node_fs.readFileSync)(importer, "utf8");
|
|
3194
|
+
if (!source.includes(FARM_CORE_PACKAGE)) return false;
|
|
3195
|
+
const transformed = await transform(source, {
|
|
3196
|
+
format: "esm",
|
|
3197
|
+
jsx: "automatic",
|
|
3198
|
+
loader: getEsbuildLoader(importer),
|
|
3199
|
+
sourcefile: importer
|
|
3200
|
+
});
|
|
3201
|
+
const references = [...transformed.code.matchAll(FARM_CORE_REFERENCE_RE)];
|
|
3202
|
+
if (references.length === 0) return false;
|
|
3203
|
+
const safeImportRanges = [];
|
|
3204
|
+
for (const match of transformed.code.matchAll(FARM_CONFIG_HELPER_IMPORT_RE)) {
|
|
3205
|
+
const specifiers = match[1].split(",").map((specifier) => specifier.trim()).filter(Boolean);
|
|
3206
|
+
if (specifiers.length === 0 || !specifiers.every((specifier) => FARM_CONFIG_HELPER_SPECIFIER_RE.test(specifier))) {
|
|
3207
|
+
continue;
|
|
3208
|
+
}
|
|
3209
|
+
const start = match.index ?? 0;
|
|
3210
|
+
safeImportRanges.push({ start, end: start + match[0].length });
|
|
3211
|
+
}
|
|
3212
|
+
return references.every((reference) => {
|
|
3213
|
+
const index = reference.index ?? -1;
|
|
3214
|
+
return safeImportRanges.some((range) => index >= range.start && index < range.end);
|
|
3215
|
+
});
|
|
3216
|
+
} catch {
|
|
3217
|
+
return false;
|
|
3218
|
+
}
|
|
3219
|
+
}
|
|
3220
|
+
__name(onlyImportsFarmConfigHelpers, "onlyImportsFarmConfigHelpers");
|
|
3221
|
+
function getEsbuildLoader(file) {
|
|
3222
|
+
switch (import_node_path.default.extname(file)) {
|
|
3223
|
+
case ".ts":
|
|
3224
|
+
case ".mts":
|
|
3225
|
+
case ".cts":
|
|
3226
|
+
return "ts";
|
|
3227
|
+
case ".tsx":
|
|
3228
|
+
return "tsx";
|
|
3229
|
+
case ".jsx":
|
|
3230
|
+
return "jsx";
|
|
3231
|
+
default:
|
|
3232
|
+
return "js";
|
|
3233
|
+
}
|
|
3234
|
+
}
|
|
3235
|
+
__name(getEsbuildLoader, "getEsbuildLoader");
|
|
3236
|
+
function normalizeLayerEntries(value, owner) {
|
|
3237
|
+
if (value === void 0) return [];
|
|
3238
|
+
if (!Array.isArray(value)) {
|
|
3239
|
+
throw new TypeError(`${owner} "extends" must be an array of layer paths or package names`);
|
|
3240
|
+
}
|
|
3241
|
+
return value.map((entry, index) => {
|
|
3242
|
+
if (typeof entry !== "string" || entry.trim() === "") {
|
|
3243
|
+
throw new TypeError(`${owner} "extends" entry ${index} must be a non-empty string`);
|
|
3244
|
+
}
|
|
3245
|
+
return entry.trim();
|
|
3246
|
+
});
|
|
3247
|
+
}
|
|
3248
|
+
__name(normalizeLayerEntries, "normalizeLayerEntries");
|
|
3249
|
+
function resolveLayerSource(source, ownerRoot) {
|
|
3250
|
+
if (isPathLayerSource(source)) {
|
|
3251
|
+
const target = source.startsWith("file:") ? import_node_path.default.resolve(ownerRoot, source.slice("file:".length)) : import_node_path.default.resolve(ownerRoot, source);
|
|
3252
|
+
if (!(0, import_node_fs.existsSync)(target)) {
|
|
3253
|
+
throw new Error(`Cannot resolve Farm layer ${JSON.stringify(source)} from ${ownerRoot}`);
|
|
3254
|
+
}
|
|
3255
|
+
const stats = (0, import_node_fs.statSync)(target);
|
|
3256
|
+
const root = stats.isDirectory() ? target : import_node_path.default.dirname(target);
|
|
3257
|
+
return {
|
|
3258
|
+
root: normalizeRealPath(root),
|
|
3259
|
+
configFile: stats.isFile() ? normalizeRealPath(target) : void 0
|
|
3260
|
+
};
|
|
3261
|
+
}
|
|
3262
|
+
const requireFromOwner = (0, import_node_module.createRequire)(import_node_path.default.join(ownerRoot, "package.json"));
|
|
3263
|
+
let packageJsonPath;
|
|
3264
|
+
try {
|
|
3265
|
+
packageJsonPath = requireFromOwner.resolve(`${source}/package.json`);
|
|
3266
|
+
} catch {
|
|
3267
|
+
}
|
|
3268
|
+
if (packageJsonPath) {
|
|
3269
|
+
return { root: normalizeRealPath(import_node_path.default.dirname(packageJsonPath)) };
|
|
3270
|
+
}
|
|
3271
|
+
try {
|
|
3272
|
+
const entryPath = requireFromOwner.resolve(source);
|
|
3273
|
+
const packageRoot = findNearestPackageRoot(entryPath);
|
|
3274
|
+
if (packageRoot) return { root: normalizeRealPath(packageRoot) };
|
|
3275
|
+
} catch {
|
|
3276
|
+
}
|
|
3277
|
+
throw new Error(`Cannot resolve Farm layer package ${JSON.stringify(source)} from ${ownerRoot}`);
|
|
3278
|
+
}
|
|
3279
|
+
__name(resolveLayerSource, "resolveLayerSource");
|
|
3280
|
+
function findNearestPackageRoot(entryPath) {
|
|
3281
|
+
let current = (0, import_node_fs.statSync)(entryPath).isDirectory() ? entryPath : import_node_path.default.dirname(entryPath);
|
|
3282
|
+
while (true) {
|
|
3283
|
+
if ((0, import_node_fs.existsSync)(import_node_path.default.join(current, "package.json"))) return current;
|
|
3284
|
+
const parent = import_node_path.default.dirname(current);
|
|
3285
|
+
if (parent === current) return null;
|
|
3286
|
+
current = parent;
|
|
3287
|
+
}
|
|
3288
|
+
}
|
|
3289
|
+
__name(findNearestPackageRoot, "findNearestPackageRoot");
|
|
3290
|
+
function findFarmConfigFile(root, explicitPath) {
|
|
3291
|
+
if (explicitPath) return explicitPath;
|
|
3292
|
+
for (const fileName of CONFIG_FILENAMES) {
|
|
3293
|
+
const candidate = import_node_path.default.join(root, fileName);
|
|
3294
|
+
if ((0, import_node_fs.existsSync)(candidate)) return candidate;
|
|
3295
|
+
}
|
|
3296
|
+
return void 0;
|
|
3297
|
+
}
|
|
3298
|
+
__name(findFarmConfigFile, "findFarmConfigFile");
|
|
3299
|
+
function getLayerName(source, root) {
|
|
3300
|
+
if (!isPathLayerSource(source)) {
|
|
3301
|
+
const packageName = source.split("/").filter(Boolean).pop();
|
|
3302
|
+
if (packageName) return sanitizeLayerName(packageName);
|
|
3303
|
+
}
|
|
3304
|
+
try {
|
|
3305
|
+
const packageJson = JSON.parse((0, import_node_fs.readFileSync)(import_node_path.default.join(root, "package.json"), "utf8"));
|
|
3306
|
+
if (typeof packageJson.name === "string") {
|
|
3307
|
+
return sanitizeLayerName(packageJson.name.split("/").pop() || packageJson.name);
|
|
3308
|
+
}
|
|
3309
|
+
} catch {
|
|
3310
|
+
}
|
|
3311
|
+
return sanitizeLayerName(import_node_path.default.basename(root));
|
|
3312
|
+
}
|
|
3313
|
+
__name(getLayerName, "getLayerName");
|
|
3314
|
+
function sanitizeLayerName(value) {
|
|
3315
|
+
const name = value.trim().replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
3316
|
+
if (!name) throw new Error(`Cannot derive a name for Farm layer ${JSON.stringify(value)}`);
|
|
3317
|
+
return name;
|
|
3318
|
+
}
|
|
3319
|
+
__name(sanitizeLayerName, "sanitizeLayerName");
|
|
3320
|
+
function normalizeLayerSrcDir(value) {
|
|
3321
|
+
if (value === void 0) return "src";
|
|
3322
|
+
if (typeof value !== "string" || value.trim() === "" || import_node_path.default.isAbsolute(value)) {
|
|
3323
|
+
throw new TypeError("A Farm layer srcDir must be a non-empty relative path");
|
|
3324
|
+
}
|
|
3325
|
+
const normalized = import_node_path.default.normalize(value.trim());
|
|
3326
|
+
if (normalized === ".." || normalized.startsWith(`..${import_node_path.default.sep}`)) {
|
|
3327
|
+
throw new TypeError("A Farm layer srcDir cannot leave the layer root");
|
|
3328
|
+
}
|
|
3329
|
+
return normalized;
|
|
3330
|
+
}
|
|
3331
|
+
__name(normalizeLayerSrcDir, "normalizeLayerSrcDir");
|
|
3332
|
+
function getLayerDefaults(config) {
|
|
3333
|
+
return Object.fromEntries(
|
|
3334
|
+
Object.entries(config).filter(
|
|
3335
|
+
([key, value]) => key !== "extends" && value !== void 0 && !LAYER_LOCAL_CONFIG_KEYS.has(key)
|
|
3336
|
+
)
|
|
3337
|
+
);
|
|
3338
|
+
}
|
|
3339
|
+
__name(getLayerDefaults, "getLayerDefaults");
|
|
3340
|
+
function mergeFarmLayerConfig(base, override) {
|
|
3341
|
+
const output = { ...base };
|
|
3342
|
+
for (const [key, value] of Object.entries(override)) {
|
|
3343
|
+
if (value === void 0 || key === "layers") continue;
|
|
3344
|
+
if (key === "plugins") {
|
|
3345
|
+
output[key] = [...toArray(output[key]), ...toArray(value)];
|
|
3346
|
+
continue;
|
|
3347
|
+
}
|
|
3348
|
+
if (key === "middleware" && output[key] !== void 0) {
|
|
3349
|
+
output[key] = [...toArray(output[key]), ...toArray(value)];
|
|
3350
|
+
continue;
|
|
3351
|
+
}
|
|
3352
|
+
if ((key === "redirects" || key === "rewrites" || key === "headers") && output[key]) {
|
|
3353
|
+
output[key] = mergeConfigListResolvers(output[key], value);
|
|
3354
|
+
continue;
|
|
3355
|
+
}
|
|
3356
|
+
if (isPlainObject(output[key]) && isPlainObject(value)) {
|
|
3357
|
+
output[key] = mergePlainObjects(output[key], value);
|
|
3358
|
+
continue;
|
|
3359
|
+
}
|
|
3360
|
+
output[key] = value;
|
|
3361
|
+
}
|
|
3362
|
+
return output;
|
|
3363
|
+
}
|
|
3364
|
+
__name(mergeFarmLayerConfig, "mergeFarmLayerConfig");
|
|
3365
|
+
function mergePlainObjects(base, override) {
|
|
3366
|
+
const output = { ...base };
|
|
3367
|
+
for (const [key, value] of Object.entries(override)) {
|
|
3368
|
+
if (value === void 0) continue;
|
|
3369
|
+
output[key] = isPlainObject(output[key]) && isPlainObject(value) ? mergePlainObjects(output[key], value) : value;
|
|
3370
|
+
}
|
|
3371
|
+
return output;
|
|
3372
|
+
}
|
|
3373
|
+
__name(mergePlainObjects, "mergePlainObjects");
|
|
3374
|
+
function mergeConfigListResolvers(base, override) {
|
|
3375
|
+
return async () => [...await resolveConfigList(base), ...await resolveConfigList(override)];
|
|
3376
|
+
}
|
|
3377
|
+
__name(mergeConfigListResolvers, "mergeConfigListResolvers");
|
|
3378
|
+
async function resolveConfigList(value) {
|
|
3379
|
+
const resolved = typeof value === "function" ? await value() : value;
|
|
3380
|
+
return toArray(resolved);
|
|
3381
|
+
}
|
|
3382
|
+
__name(resolveConfigList, "resolveConfigList");
|
|
3383
|
+
function toArray(value) {
|
|
3384
|
+
if (value === void 0 || value === null) return [];
|
|
3385
|
+
return Array.isArray(value) ? value : [value];
|
|
3386
|
+
}
|
|
3387
|
+
__name(toArray, "toArray");
|
|
3388
|
+
function isPlainObject(value) {
|
|
3389
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
3390
|
+
const prototype = Object.getPrototypeOf(value);
|
|
3391
|
+
return prototype === Object.prototype || prototype === null;
|
|
3392
|
+
}
|
|
3393
|
+
__name(isPlainObject, "isPlainObject");
|
|
3394
|
+
function isPathLayerSource(source) {
|
|
3395
|
+
return source.startsWith(".") || source.startsWith("/") || source.startsWith("file:") || /^[a-zA-Z]:[\\/]/.test(source);
|
|
3396
|
+
}
|
|
3397
|
+
__name(isPathLayerSource, "isPathLayerSource");
|
|
3398
|
+
function normalizeRealPath(value) {
|
|
3399
|
+
return import_node_path.default.resolve((0, import_node_fs.realpathSync)(value));
|
|
3400
|
+
}
|
|
3401
|
+
__name(normalizeRealPath, "normalizeRealPath");
|
|
3402
|
+
|
|
3403
|
+
// src/config.ts
|
|
3404
|
+
var import_path = __toESM(require("path"));
|
|
3405
|
+
|
|
3406
|
+
// src/deployment.ts
|
|
3407
|
+
function normalizeFarmDeploymentId(value) {
|
|
3408
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
3409
|
+
throw new TypeError("Farm deploymentId must be a non-empty string");
|
|
3410
|
+
}
|
|
3411
|
+
const normalized = value.trim();
|
|
3412
|
+
if (normalized.length > 200 || /[\u0000-\u001f\u007f]/.test(normalized)) {
|
|
3413
|
+
throw new TypeError("Farm deploymentId must be at most 200 characters without control bytes");
|
|
3414
|
+
}
|
|
3415
|
+
return normalized;
|
|
3416
|
+
}
|
|
3417
|
+
__name(normalizeFarmDeploymentId, "normalizeFarmDeploymentId");
|
|
3418
|
+
|
|
3419
|
+
// src/devtools-config.ts
|
|
3420
|
+
var DEFAULT_FARM_DEVTOOLS_SHORTCUT = "mod+shift+.";
|
|
3421
|
+
function resolveFarmDevtoolsConfig(config, mode = "development") {
|
|
3422
|
+
if (mode !== "development" || config === false) {
|
|
3423
|
+
return { enabled: false, shortcut: false };
|
|
3424
|
+
}
|
|
3425
|
+
const options = config === true || config === void 0 ? {} : config;
|
|
3426
|
+
const enabled = options.enabled ?? true;
|
|
3427
|
+
if (!enabled) {
|
|
3428
|
+
return { enabled: false, shortcut: false };
|
|
3429
|
+
}
|
|
3430
|
+
const shortcut = typeof options.shortcut === "string" && options.shortcut.trim() ? options.shortcut.toLowerCase().split("+").map((part) => part.trim()).filter(Boolean).join("+") : options.shortcut === false ? false : DEFAULT_FARM_DEVTOOLS_SHORTCUT;
|
|
3431
|
+
return { enabled: true, shortcut };
|
|
3432
|
+
}
|
|
3433
|
+
__name(resolveFarmDevtoolsConfig, "resolveFarmDevtoolsConfig");
|
|
3434
|
+
|
|
3435
|
+
// src/image-config.ts
|
|
3436
|
+
var DEFAULT_FARM_IMAGE_PATH = "/_farm/image";
|
|
3437
|
+
var DEFAULT_FARM_IMAGE_DEVICE_SIZES = [
|
|
3438
|
+
640,
|
|
3439
|
+
750,
|
|
3440
|
+
828,
|
|
3441
|
+
1080,
|
|
3442
|
+
1200,
|
|
3443
|
+
1920,
|
|
3444
|
+
2048,
|
|
3445
|
+
3840
|
|
3446
|
+
];
|
|
3447
|
+
var DEFAULT_FARM_IMAGE_SIZES = [16, 32, 48, 64, 96, 128, 256, 384];
|
|
3448
|
+
var DEFAULT_FARM_IMAGE_QUALITIES = [75];
|
|
3449
|
+
var DEFAULT_FARM_IMAGE_FORMATS = ["image/webp"];
|
|
3450
|
+
var SIZE_UNITS = {
|
|
3451
|
+
b: 1,
|
|
3452
|
+
kb: 1e3,
|
|
3453
|
+
mb: 1e6,
|
|
3454
|
+
gb: 1e9,
|
|
3455
|
+
kib: 1024,
|
|
3456
|
+
mib: 1048576,
|
|
3457
|
+
gib: 1073741824
|
|
3458
|
+
};
|
|
3459
|
+
function resolveFarmImageConfig(config) {
|
|
3460
|
+
const path4 = normalizeImagePath(config?.path ?? DEFAULT_FARM_IMAGE_PATH);
|
|
3461
|
+
const deviceSizes = normalizeIntegerList(
|
|
3462
|
+
config?.deviceSizes ?? DEFAULT_FARM_IMAGE_DEVICE_SIZES,
|
|
3463
|
+
"images.deviceSizes"
|
|
3464
|
+
);
|
|
3465
|
+
const imageSizes = normalizeIntegerList(
|
|
3466
|
+
config?.imageSizes ?? DEFAULT_FARM_IMAGE_SIZES,
|
|
3467
|
+
"images.imageSizes"
|
|
3468
|
+
);
|
|
3469
|
+
const qualities = normalizeIntegerList(
|
|
3470
|
+
config?.qualities ?? DEFAULT_FARM_IMAGE_QUALITIES,
|
|
3471
|
+
"images.qualities",
|
|
3472
|
+
100
|
|
3473
|
+
);
|
|
3474
|
+
const formats = [...new Set(config?.formats ?? DEFAULT_FARM_IMAGE_FORMATS)];
|
|
3475
|
+
if (formats.some((format) => format !== "image/avif" && format !== "image/webp")) {
|
|
3476
|
+
throw new TypeError('images.formats only supports "image/avif" and "image/webp"');
|
|
3477
|
+
}
|
|
3478
|
+
const minimumCacheTTL = normalizeNonNegativeInteger(
|
|
3479
|
+
config?.minimumCacheTTL ?? 60,
|
|
3480
|
+
"images.minimumCacheTTL"
|
|
3481
|
+
);
|
|
3482
|
+
const maximumRedirects = normalizeNonNegativeInteger(
|
|
3483
|
+
config?.maximumRedirects ?? 3,
|
|
3484
|
+
"images.maximumRedirects"
|
|
3485
|
+
);
|
|
3486
|
+
return Object.freeze({
|
|
3487
|
+
provider: config?.provider ?? "auto",
|
|
3488
|
+
path: path4,
|
|
3489
|
+
domains: Object.freeze([
|
|
3490
|
+
...new Set(
|
|
3491
|
+
(config?.domains ?? []).map((domain) => domain.trim().toLowerCase()).filter(Boolean)
|
|
3492
|
+
)
|
|
3493
|
+
]),
|
|
3494
|
+
remotePatterns: Object.freeze(
|
|
3495
|
+
(config?.remotePatterns ?? []).map((pattern) => normalizeRemotePattern(pattern))
|
|
3496
|
+
),
|
|
3497
|
+
localPatterns: Object.freeze(
|
|
3498
|
+
(config?.localPatterns ?? [{ pathname: "/**" }]).map(
|
|
3499
|
+
(pattern) => normalizeLocalPattern(pattern)
|
|
3500
|
+
)
|
|
3501
|
+
),
|
|
3502
|
+
deviceSizes: Object.freeze(deviceSizes),
|
|
3503
|
+
imageSizes: Object.freeze(imageSizes),
|
|
3504
|
+
qualities: Object.freeze(qualities),
|
|
3505
|
+
formats: Object.freeze(formats),
|
|
3506
|
+
minimumCacheTTL,
|
|
3507
|
+
maximumResponseBody: parseSize(
|
|
3508
|
+
config?.maximumResponseBody ?? "10mb",
|
|
3509
|
+
"images.maximumResponseBody"
|
|
3510
|
+
),
|
|
3511
|
+
maximumRedirects,
|
|
3512
|
+
dangerouslyAllowSVG: config?.dangerouslyAllowSVG ?? false,
|
|
3513
|
+
dangerouslyAllowLocalIP: config?.dangerouslyAllowLocalIP ?? false
|
|
3514
|
+
});
|
|
3515
|
+
}
|
|
3516
|
+
__name(resolveFarmImageConfig, "resolveFarmImageConfig");
|
|
3517
|
+
function normalizeImagePath(value) {
|
|
3518
|
+
const path4 = value.trim().replace(/\/+$/, "") || "/";
|
|
3519
|
+
if (!path4.startsWith("/") || path4.includes("?") || path4.includes("#")) {
|
|
3520
|
+
throw new TypeError("images.path must be an absolute pathname without a query or hash");
|
|
3521
|
+
}
|
|
3522
|
+
return path4;
|
|
3523
|
+
}
|
|
3524
|
+
__name(normalizeImagePath, "normalizeImagePath");
|
|
3525
|
+
function normalizeIntegerList(values, name, max) {
|
|
3526
|
+
if (values.length === 0) {
|
|
3527
|
+
throw new TypeError(`${name} must contain at least one value`);
|
|
3528
|
+
}
|
|
3529
|
+
const normalized = [...new Set(values)].sort((left, right) => left - right);
|
|
3530
|
+
for (const value of normalized) {
|
|
3531
|
+
if (!Number.isSafeInteger(value) || value <= 0 || max !== void 0 && value > max) {
|
|
3532
|
+
throw new TypeError(
|
|
3533
|
+
`${name} must contain positive integers${max ? ` no greater than ${max}` : ""}`
|
|
3534
|
+
);
|
|
3535
|
+
}
|
|
3536
|
+
}
|
|
3537
|
+
return normalized;
|
|
3538
|
+
}
|
|
3539
|
+
__name(normalizeIntegerList, "normalizeIntegerList");
|
|
3540
|
+
function normalizeNonNegativeInteger(value, name) {
|
|
3541
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
3542
|
+
throw new TypeError(`${name} must be a non-negative safe integer`);
|
|
3543
|
+
}
|
|
3544
|
+
return value;
|
|
3545
|
+
}
|
|
3546
|
+
__name(normalizeNonNegativeInteger, "normalizeNonNegativeInteger");
|
|
3547
|
+
function parseSize(value, name) {
|
|
3548
|
+
if (typeof value === "number") {
|
|
3549
|
+
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
3550
|
+
throw new TypeError(`${name} must be a positive safe integer`);
|
|
3551
|
+
}
|
|
3552
|
+
return value;
|
|
3553
|
+
}
|
|
3554
|
+
const match = value.trim().toLowerCase().match(/^(\d+(?:\.\d+)?)\s*(b|kb|mb|gb|kib|mib|gib)$/);
|
|
3555
|
+
if (!match) {
|
|
3556
|
+
throw new TypeError(`${name} must be bytes or a size string such as "5mb"`);
|
|
3557
|
+
}
|
|
3558
|
+
const bytes = Number(match[1]) * SIZE_UNITS[match[2]];
|
|
3559
|
+
if (!Number.isSafeInteger(bytes) || bytes <= 0) {
|
|
3560
|
+
throw new TypeError(`${name} must resolve to a positive safe integer`);
|
|
3561
|
+
}
|
|
3562
|
+
return bytes;
|
|
3563
|
+
}
|
|
3564
|
+
__name(parseSize, "parseSize");
|
|
3565
|
+
function normalizeRemotePattern(pattern) {
|
|
3566
|
+
const hostname = pattern.hostname.trim().toLowerCase();
|
|
3567
|
+
if (!hostname || hostname.includes("/") || hostname.includes(":")) {
|
|
3568
|
+
throw new TypeError("images.remotePatterns[].hostname must be a hostname or wildcard hostname");
|
|
3569
|
+
}
|
|
3570
|
+
if (pattern.pathname && !pattern.pathname.startsWith("/")) {
|
|
3571
|
+
throw new TypeError("images.remotePatterns[].pathname must start with /");
|
|
3572
|
+
}
|
|
3573
|
+
if (pattern.search && !pattern.search.startsWith("?")) {
|
|
3574
|
+
throw new TypeError("images.remotePatterns[].search must start with ?");
|
|
3575
|
+
}
|
|
3576
|
+
return Object.freeze({ ...pattern, hostname });
|
|
3577
|
+
}
|
|
3578
|
+
__name(normalizeRemotePattern, "normalizeRemotePattern");
|
|
3579
|
+
function normalizeLocalPattern(pattern) {
|
|
3580
|
+
if (!pattern.pathname.startsWith("/")) {
|
|
3581
|
+
throw new TypeError("images.localPatterns[].pathname must start with /");
|
|
3582
|
+
}
|
|
3583
|
+
if (pattern.search && !pattern.search.startsWith("?")) {
|
|
3584
|
+
throw new TypeError("images.localPatterns[].search must start with ?");
|
|
3585
|
+
}
|
|
3586
|
+
return Object.freeze({ ...pattern });
|
|
3587
|
+
}
|
|
3588
|
+
__name(normalizeLocalPattern, "normalizeLocalPattern");
|
|
3589
|
+
|
|
3590
|
+
// src/i18n/config.ts
|
|
3591
|
+
var import_node_path2 = __toESM(require("path"));
|
|
3592
|
+
var DEFAULT_FARM_I18N_COOKIE = "farm_locale";
|
|
3593
|
+
var DEFAULT_FARM_I18N_COOKIE_MAX_AGE = 60 * 60 * 24 * 365;
|
|
3594
|
+
var DEFAULT_DETECTION = ["url", "cookie", "accept-language"];
|
|
3595
|
+
function resolveFarmI18nConfig(input, options = {}) {
|
|
3596
|
+
const root = options.root || process.cwd();
|
|
3597
|
+
const strictByDefault = options.mode === "production";
|
|
3598
|
+
if (!input) {
|
|
3599
|
+
return {
|
|
3600
|
+
enabled: false,
|
|
3601
|
+
locales: ["en"],
|
|
3602
|
+
defaultLocale: "en",
|
|
3603
|
+
messages: import_node_path2.default.join(root, "src/messages"),
|
|
3604
|
+
routing: "none",
|
|
3605
|
+
detection: [],
|
|
3606
|
+
fallbackLocale: "en",
|
|
3607
|
+
strict: strictByDefault,
|
|
3608
|
+
cookie: {
|
|
3609
|
+
name: DEFAULT_FARM_I18N_COOKIE,
|
|
3610
|
+
maxAge: DEFAULT_FARM_I18N_COOKIE_MAX_AGE,
|
|
3611
|
+
path: "/",
|
|
3612
|
+
sameSite: "lax",
|
|
3613
|
+
secure: options.mode === "production"
|
|
3614
|
+
},
|
|
3615
|
+
direction: {}
|
|
3616
|
+
};
|
|
3617
|
+
}
|
|
3618
|
+
if (!Array.isArray(input.locales) || input.locales.length === 0) {
|
|
3619
|
+
throw new Error("i18n.locales must contain at least one locale.");
|
|
3620
|
+
}
|
|
3621
|
+
const locales = input.locales.map(canonicalizeLocale);
|
|
3622
|
+
if (new Set(locales).size !== locales.length) {
|
|
3623
|
+
throw new Error("i18n.locales must not contain duplicate locales.");
|
|
3624
|
+
}
|
|
3625
|
+
const defaultLocale = canonicalizeLocale(input.defaultLocale);
|
|
3626
|
+
if (!locales.includes(defaultLocale)) {
|
|
3627
|
+
throw new Error(`i18n.defaultLocale "${defaultLocale}" must be included in i18n.locales.`);
|
|
3628
|
+
}
|
|
3629
|
+
const fallbackLocale = canonicalizeLocale(input.fallbackLocale || defaultLocale);
|
|
3630
|
+
if (!locales.includes(fallbackLocale)) {
|
|
3631
|
+
throw new Error(`i18n.fallbackLocale "${fallbackLocale}" must be included in i18n.locales.`);
|
|
3632
|
+
}
|
|
3633
|
+
const detection = resolveDetection(input);
|
|
3634
|
+
const direction = {};
|
|
3635
|
+
for (const [rawLocale, value] of Object.entries(input.direction || {})) {
|
|
3636
|
+
const locale = canonicalizeLocale(rawLocale);
|
|
3637
|
+
if (!locales.includes(locale)) {
|
|
3638
|
+
throw new Error(`i18n.direction contains unknown locale "${rawLocale}".`);
|
|
3639
|
+
}
|
|
3640
|
+
if (value !== "ltr" && value !== "rtl") {
|
|
3641
|
+
throw new Error(`i18n.direction.${rawLocale} must be "ltr" or "rtl".`);
|
|
3642
|
+
}
|
|
3643
|
+
direction[locale] = value;
|
|
3644
|
+
}
|
|
3645
|
+
return {
|
|
3646
|
+
enabled: true,
|
|
3647
|
+
locales,
|
|
3648
|
+
defaultLocale,
|
|
3649
|
+
messages: import_node_path2.default.resolve(root, input.messages || "src/messages"),
|
|
3650
|
+
routing: input.routing || "prefix-except-default",
|
|
3651
|
+
detection,
|
|
3652
|
+
fallbackLocale,
|
|
3653
|
+
strict: input.strict ?? strictByDefault,
|
|
3654
|
+
cookie: {
|
|
3655
|
+
name: input.cookie?.name?.trim() || DEFAULT_FARM_I18N_COOKIE,
|
|
3656
|
+
maxAge: normalizePositiveInteger(
|
|
3657
|
+
input.cookie?.maxAge,
|
|
3658
|
+
DEFAULT_FARM_I18N_COOKIE_MAX_AGE,
|
|
3659
|
+
"i18n.cookie.maxAge"
|
|
3660
|
+
),
|
|
3661
|
+
path: input.cookie?.path || "/",
|
|
3662
|
+
sameSite: input.cookie?.sameSite || "lax",
|
|
3663
|
+
secure: input.cookie?.secure ?? options.mode === "production"
|
|
3664
|
+
},
|
|
3665
|
+
direction
|
|
3666
|
+
};
|
|
3667
|
+
}
|
|
3668
|
+
__name(resolveFarmI18nConfig, "resolveFarmI18nConfig");
|
|
3669
|
+
function canonicalizeLocale(locale) {
|
|
3670
|
+
if (!locale || typeof locale !== "string") {
|
|
3671
|
+
throw new Error("Farm i18n locales must be non-empty strings.");
|
|
3672
|
+
}
|
|
3673
|
+
try {
|
|
3674
|
+
return Intl.getCanonicalLocales(locale)[0];
|
|
3675
|
+
} catch {
|
|
3676
|
+
throw new Error(`Invalid i18n locale "${locale}".`);
|
|
3677
|
+
}
|
|
3678
|
+
}
|
|
3679
|
+
__name(canonicalizeLocale, "canonicalizeLocale");
|
|
3680
|
+
function resolveDetection(input) {
|
|
3681
|
+
if (input.detection === false || input.localeDetection === false) {
|
|
3682
|
+
return ["url"];
|
|
3683
|
+
}
|
|
3684
|
+
const detection = input.detection || DEFAULT_DETECTION;
|
|
3685
|
+
const allowed = /* @__PURE__ */ new Set(["url", "cookie", "accept-language"]);
|
|
3686
|
+
const unique = [];
|
|
3687
|
+
for (const signal of detection) {
|
|
3688
|
+
if (!allowed.has(signal)) {
|
|
3689
|
+
throw new Error(`Unsupported i18n detection signal "${signal}".`);
|
|
3690
|
+
}
|
|
3691
|
+
if (!unique.includes(signal)) unique.push(signal);
|
|
3692
|
+
}
|
|
3693
|
+
return unique;
|
|
3694
|
+
}
|
|
3695
|
+
__name(resolveDetection, "resolveDetection");
|
|
3696
|
+
function normalizePositiveInteger(value, fallback, name) {
|
|
3697
|
+
if (value === void 0) return fallback;
|
|
3698
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
3699
|
+
throw new Error(`${name} must be a positive integer.`);
|
|
3700
|
+
}
|
|
3701
|
+
return value;
|
|
3702
|
+
}
|
|
3703
|
+
__name(normalizePositiveInteger, "normalizePositiveInteger");
|
|
3704
|
+
|
|
3705
|
+
// src/config.ts
|
|
3706
|
+
var FARM_RESOLVED_CUSTOM_CONTEXT = /* @__PURE__ */ Symbol.for("farm.resolvedCustomContext");
|
|
3707
|
+
function normalizeDeployTarget(target) {
|
|
3708
|
+
if (!target) return void 0;
|
|
3709
|
+
if (target === "cloudflare-pages" || target === "cloudflare_pages") return "cloudflare";
|
|
3710
|
+
if (target === "node-server" || target === "nitro") return "node";
|
|
3711
|
+
return target;
|
|
3712
|
+
}
|
|
3713
|
+
__name(normalizeDeployTarget, "normalizeDeployTarget");
|
|
3714
|
+
function getPresetForDeployTarget(target) {
|
|
3715
|
+
switch (normalizeDeployTarget(target)) {
|
|
3716
|
+
case "vercel":
|
|
3717
|
+
return "vercel";
|
|
3718
|
+
case "cloudflare":
|
|
3719
|
+
return "cloudflare-pages";
|
|
3720
|
+
case "netlify":
|
|
3721
|
+
return "netlify";
|
|
3722
|
+
case "node":
|
|
3723
|
+
return "node-server";
|
|
3724
|
+
default:
|
|
3725
|
+
return void 0;
|
|
3726
|
+
}
|
|
3727
|
+
}
|
|
3728
|
+
__name(getPresetForDeployTarget, "getPresetForDeployTarget");
|
|
3729
|
+
function getDeployTargetForPreset(preset) {
|
|
3730
|
+
if (!preset) return void 0;
|
|
3731
|
+
if (preset === "vercel" || preset === "vercel-edge") return "vercel";
|
|
3732
|
+
if (preset === "cloudflare" || preset === "cloudflare-pages" || preset === "cloudflare-module") {
|
|
3733
|
+
return "cloudflare";
|
|
3734
|
+
}
|
|
3735
|
+
if (preset === "netlify" || preset === "netlify-edge") return "netlify";
|
|
3736
|
+
if (preset === "node-server") return "node";
|
|
3737
|
+
return void 0;
|
|
3738
|
+
}
|
|
3739
|
+
__name(getDeployTargetForPreset, "getDeployTargetForPreset");
|
|
3740
|
+
function getDefaultDeployOutputDir(target, preset, distDir) {
|
|
3741
|
+
const normalizedTarget = normalizeDeployTarget(target) || getDeployTargetForPreset(preset);
|
|
3742
|
+
if (normalizedTarget === "vercel") return ".vercel/output";
|
|
3743
|
+
return `${distDir}/.output`;
|
|
3744
|
+
}
|
|
3745
|
+
__name(getDefaultDeployOutputDir, "getDefaultDeployOutputDir");
|
|
3746
|
+
function resolveDeployConfig(config, overrides = {}) {
|
|
3747
|
+
const deploy = config.deploy || {};
|
|
3748
|
+
const distDir = config.distDir || ".farm";
|
|
3749
|
+
const target = normalizeDeployTarget(overrides.target || deploy.target);
|
|
3750
|
+
const preset = overrides.preset || deploy.preset || config.preset || getPresetForDeployTarget(target) || "node-server";
|
|
3751
|
+
const resolvedTarget = target || getDeployTargetForPreset(preset);
|
|
3752
|
+
const platformOutput = resolvedTarget === "vercel" ? deploy.vercel?.outputDirectory : resolvedTarget === "cloudflare" ? deploy.cloudflare?.outputDir : resolvedTarget === "netlify" ? deploy.netlify?.outputDir : void 0;
|
|
3753
|
+
const outputDir = overrides.outputDir || deploy.outputDir || deploy.output || platformOutput || getDefaultDeployOutputDir(resolvedTarget, preset, distDir);
|
|
3754
|
+
return {
|
|
3755
|
+
...deploy,
|
|
3756
|
+
target: resolvedTarget,
|
|
3757
|
+
preset,
|
|
3758
|
+
outputDir
|
|
3759
|
+
};
|
|
3760
|
+
}
|
|
3761
|
+
__name(resolveDeployConfig, "resolveDeployConfig");
|
|
3762
|
+
function resolveMigrationsConfig(migrations) {
|
|
3763
|
+
if (!migrations) return { commands: [] };
|
|
3764
|
+
if (Array.isArray(migrations)) return { commands: migrations };
|
|
3765
|
+
return { commands: migrations.commands || [] };
|
|
3766
|
+
}
|
|
3767
|
+
__name(resolveMigrationsConfig, "resolveMigrationsConfig");
|
|
3768
|
+
var DOCS_CONFIG_FILENAMES = [
|
|
3769
|
+
"docs.config.ts",
|
|
3770
|
+
"docs.config.tsx",
|
|
3771
|
+
"docs.config.mts",
|
|
3772
|
+
"docs.config.cts",
|
|
3773
|
+
"docs.config.js",
|
|
3774
|
+
"docs.config.jsx",
|
|
3775
|
+
"docs.config.mjs",
|
|
3776
|
+
"docs.config.cjs",
|
|
3777
|
+
"docs.json"
|
|
3778
|
+
];
|
|
3779
|
+
function normalizeDocsRoute(value, fallback = "/docs") {
|
|
3780
|
+
const raw = (value || fallback).trim();
|
|
3781
|
+
if (!raw || raw === "/") return "/";
|
|
3782
|
+
const normalized = raw.replace(/\\/g, "/").replace(/\/+/g, "/").replace(/^\/?/, "/").replace(/\/+$/, "");
|
|
3783
|
+
return normalized || "/";
|
|
3784
|
+
}
|
|
3785
|
+
__name(normalizeDocsRoute, "normalizeDocsRoute");
|
|
3786
|
+
function docsRouteToEntry(route) {
|
|
3787
|
+
const entry = route.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
3788
|
+
return entry || "docs";
|
|
3789
|
+
}
|
|
3790
|
+
__name(docsRouteToEntry, "docsRouteToEntry");
|
|
3791
|
+
function normalizeDocsContentDir(value) {
|
|
3792
|
+
if (!value) return void 0;
|
|
3793
|
+
const normalized = value.replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/+$/, "");
|
|
3794
|
+
return normalized || void 0;
|
|
3795
|
+
}
|
|
3796
|
+
__name(normalizeDocsContentDir, "normalizeDocsContentDir");
|
|
3797
|
+
function isRecord2(value) {
|
|
3798
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
3799
|
+
}
|
|
3800
|
+
__name(isRecord2, "isRecord");
|
|
3801
|
+
function cloneSerializable(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
3802
|
+
if (value === null) return null;
|
|
3803
|
+
const valueType = typeof value;
|
|
3804
|
+
if (valueType === "string" || valueType === "number" || valueType === "boolean") {
|
|
3805
|
+
return value;
|
|
3806
|
+
}
|
|
3807
|
+
if (valueType === "undefined" || valueType === "function" || valueType === "symbol") {
|
|
3808
|
+
return void 0;
|
|
3809
|
+
}
|
|
3810
|
+
if (Array.isArray(value)) {
|
|
3811
|
+
return value.map((item) => cloneSerializable(item, seen)).filter((item) => item !== void 0);
|
|
3812
|
+
}
|
|
3813
|
+
if (value instanceof Date) {
|
|
3814
|
+
return value.toISOString();
|
|
3815
|
+
}
|
|
3816
|
+
if (isRecord2(value)) {
|
|
3817
|
+
if (seen.has(value)) return void 0;
|
|
3818
|
+
seen.add(value);
|
|
3819
|
+
const output = {};
|
|
3820
|
+
for (const [key, nestedValue] of Object.entries(value)) {
|
|
3821
|
+
const clonedValue = cloneSerializable(nestedValue, seen);
|
|
3822
|
+
if (clonedValue !== void 0) {
|
|
3823
|
+
output[key] = clonedValue;
|
|
3824
|
+
}
|
|
3825
|
+
}
|
|
3826
|
+
return output;
|
|
3827
|
+
}
|
|
3828
|
+
return void 0;
|
|
3829
|
+
}
|
|
3830
|
+
__name(cloneSerializable, "cloneSerializable");
|
|
3831
|
+
function sanitizeDocsConfig(config) {
|
|
3832
|
+
return cloneSerializable(config) || {};
|
|
3833
|
+
}
|
|
3834
|
+
__name(sanitizeDocsConfig, "sanitizeDocsConfig");
|
|
3835
|
+
async function findDocsConfigPath(rootDir, configPath) {
|
|
3836
|
+
const { existsSync: existsSync2 } = await import("fs");
|
|
3837
|
+
const root = import_path.default.resolve(rootDir || process.cwd());
|
|
3838
|
+
if (configPath) {
|
|
3839
|
+
const resolvedPath = import_path.default.isAbsolute(configPath) ? configPath : import_path.default.join(root, configPath);
|
|
3840
|
+
if (!existsSync2(resolvedPath)) {
|
|
3841
|
+
throw new Error(`Could not find docs config at ${configPath}.`);
|
|
3842
|
+
}
|
|
3843
|
+
return import_path.default.resolve(resolvedPath);
|
|
3844
|
+
}
|
|
3845
|
+
for (const filename of DOCS_CONFIG_FILENAMES) {
|
|
3846
|
+
const resolvedPath = import_path.default.join(root, filename);
|
|
3847
|
+
if (existsSync2(resolvedPath)) {
|
|
3848
|
+
return resolvedPath;
|
|
3849
|
+
}
|
|
3850
|
+
}
|
|
3851
|
+
return void 0;
|
|
3852
|
+
}
|
|
3853
|
+
__name(findDocsConfigPath, "findDocsConfigPath");
|
|
3854
|
+
async function loadDocsConfig(rootDir, configPath) {
|
|
3855
|
+
const fs = await import("fs/promises");
|
|
3856
|
+
const { pathToFileURL: pathToFileURL2 } = await import("url");
|
|
3857
|
+
const root = import_path.default.resolve(rootDir || process.cwd());
|
|
3858
|
+
const resolvedPath = await findDocsConfigPath(root, configPath);
|
|
3859
|
+
if (!resolvedPath) return void 0;
|
|
3860
|
+
try {
|
|
3861
|
+
if (resolvedPath.endsWith(".json")) {
|
|
3862
|
+
const content = await fs.readFile(resolvedPath, "utf8");
|
|
3863
|
+
return { config: JSON.parse(content), configPath: resolvedPath };
|
|
3864
|
+
}
|
|
3865
|
+
const { build } = await import("esbuild");
|
|
3866
|
+
const configCacheDir = import_path.default.join(root, ".farm", ".config-loader");
|
|
3867
|
+
await fs.mkdir(configCacheDir, { recursive: true });
|
|
3868
|
+
const modulePath = import_path.default.join(
|
|
3869
|
+
configCacheDir,
|
|
3870
|
+
`docs-config-${Date.now()}-${Math.random().toString(36).slice(2)}.mjs`
|
|
3871
|
+
);
|
|
3872
|
+
await build({
|
|
3873
|
+
absWorkingDir: root,
|
|
3874
|
+
entryPoints: [resolvedPath],
|
|
3875
|
+
outfile: modulePath,
|
|
3876
|
+
bundle: true,
|
|
3877
|
+
format: "esm",
|
|
3878
|
+
platform: "node",
|
|
3879
|
+
target: `node${process.versions.node.split(".")[0]}`,
|
|
3880
|
+
packages: "external",
|
|
3881
|
+
jsx: "automatic",
|
|
3882
|
+
logLevel: "silent",
|
|
3883
|
+
sourcemap: "inline"
|
|
3884
|
+
});
|
|
3885
|
+
const moduleUrl = pathToFileURL2(modulePath).href + `?t=${Date.now()}`;
|
|
3886
|
+
let importedConfig;
|
|
3887
|
+
try {
|
|
3888
|
+
importedConfig = await import(
|
|
3889
|
+
/* @vite-ignore */
|
|
3890
|
+
moduleUrl
|
|
3891
|
+
);
|
|
3892
|
+
} finally {
|
|
3893
|
+
await fs.unlink(modulePath).catch(() => void 0);
|
|
3894
|
+
}
|
|
3895
|
+
return {
|
|
3896
|
+
config: importedConfig.default || importedConfig,
|
|
3897
|
+
configPath: resolvedPath
|
|
3898
|
+
};
|
|
3899
|
+
} catch (error) {
|
|
3900
|
+
const relativePath = import_path.default.relative(root, resolvedPath) || resolvedPath;
|
|
3901
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3902
|
+
throw new Error(`Failed to load docs config from ${relativePath}: ${message}`);
|
|
3903
|
+
}
|
|
3904
|
+
}
|
|
3905
|
+
__name(loadDocsConfig, "loadDocsConfig");
|
|
3906
|
+
async function resolveDocsConfig(userDocs, options = {}) {
|
|
3907
|
+
const root = options.root || process.cwd();
|
|
3908
|
+
if (userDocs === false) {
|
|
3909
|
+
return {
|
|
3910
|
+
enabled: false,
|
|
3911
|
+
entry: "/docs",
|
|
3912
|
+
config: { entry: "docs", docsPath: "/docs" }
|
|
3913
|
+
};
|
|
3914
|
+
}
|
|
3915
|
+
const docsOptions = isRecord2(userDocs) ? userDocs : {};
|
|
3916
|
+
if (docsOptions.enabled === false) {
|
|
3917
|
+
return {
|
|
3918
|
+
enabled: false,
|
|
3919
|
+
entry: "/docs",
|
|
3920
|
+
config: { entry: "docs", docsPath: "/docs" }
|
|
3921
|
+
};
|
|
3922
|
+
}
|
|
3923
|
+
const loadedConfig = await loadDocsConfig(root, docsOptions.configPath);
|
|
3924
|
+
const hasExplicitDocsConfig = userDocs === true || isRecord2(userDocs);
|
|
3925
|
+
if (!hasExplicitDocsConfig && !loadedConfig) {
|
|
3926
|
+
return {
|
|
3927
|
+
enabled: false,
|
|
3928
|
+
entry: "/docs",
|
|
3929
|
+
config: { entry: "docs", docsPath: "/docs" }
|
|
3930
|
+
};
|
|
3931
|
+
}
|
|
3932
|
+
const inlineDocsConfig = sanitizeDocsConfig(docsOptions.config || {});
|
|
3933
|
+
const directDocsConfig = sanitizeDocsConfig({
|
|
3934
|
+
...docsOptions,
|
|
3935
|
+
enabled: void 0,
|
|
3936
|
+
config: void 0,
|
|
3937
|
+
configPath: void 0
|
|
3938
|
+
});
|
|
3939
|
+
const loadedDocsConfig = sanitizeDocsConfig(loadedConfig?.config || {});
|
|
3940
|
+
const mergedDocsConfig = {
|
|
3941
|
+
...loadedDocsConfig,
|
|
3942
|
+
...inlineDocsConfig,
|
|
3943
|
+
...directDocsConfig
|
|
3944
|
+
};
|
|
3945
|
+
const explicitRoute = typeof docsOptions.entry === "string" ? docsOptions.entry : void 0;
|
|
3946
|
+
const configuredDocsPath = typeof mergedDocsConfig.docsPath === "string" ? mergedDocsConfig.docsPath : void 0;
|
|
3947
|
+
const configuredEntry = typeof mergedDocsConfig.entry === "string" ? mergedDocsConfig.entry : void 0;
|
|
3948
|
+
const entryRoute = normalizeDocsRoute(
|
|
3949
|
+
configuredDocsPath || explicitRoute || (configuredEntry ? `/${configuredEntry}` : void 0)
|
|
3950
|
+
);
|
|
3951
|
+
const docsEntry = explicitRoute && explicitRoute.startsWith("/") ? docsRouteToEntry(explicitRoute) : docsRouteToEntry(configuredEntry || entryRoute);
|
|
3952
|
+
const contentDir = normalizeDocsContentDir(docsOptions.contentDir || mergedDocsConfig.contentDir);
|
|
3953
|
+
return {
|
|
3954
|
+
enabled: true,
|
|
3955
|
+
entry: entryRoute,
|
|
3956
|
+
contentDir,
|
|
3957
|
+
configPath: loadedConfig?.configPath,
|
|
3958
|
+
config: {
|
|
3959
|
+
...mergedDocsConfig,
|
|
3960
|
+
entry: docsEntry,
|
|
3961
|
+
docsPath: entryRoute,
|
|
3962
|
+
...contentDir ? { contentDir } : {}
|
|
3963
|
+
}
|
|
3964
|
+
};
|
|
3965
|
+
}
|
|
3966
|
+
__name(resolveDocsConfig, "resolveDocsConfig");
|
|
3967
|
+
async function resolveConfig(userConfig, mode) {
|
|
3968
|
+
const projectRoot = userConfig.root || process.cwd();
|
|
3969
|
+
const layerResolution = await resolveFarmLayers(userConfig, {
|
|
3970
|
+
root: projectRoot,
|
|
3971
|
+
mode
|
|
3972
|
+
});
|
|
3973
|
+
userConfig = layerResolution.config;
|
|
3974
|
+
const redirects = typeof userConfig.redirects === "function" ? await userConfig.redirects() : userConfig.redirects || [];
|
|
3975
|
+
const rewrites = typeof userConfig.rewrites === "function" ? await userConfig.rewrites() : userConfig.rewrites || [];
|
|
3976
|
+
const headers = typeof userConfig.headers === "function" ? await userConfig.headers() : userConfig.headers || [];
|
|
3977
|
+
const routeRules = normalizeRouteRules(userConfig.routeRules);
|
|
3978
|
+
const routeRuleRedirects = routeRulesToRedirects(routeRules);
|
|
3979
|
+
const routeRuleHeaders = routeRulesToHeaders(routeRules);
|
|
3980
|
+
const deploy = resolveDeployConfig(userConfig);
|
|
3981
|
+
const root = userConfig.root || process.cwd();
|
|
3982
|
+
const srcDir = userConfig.srcDir || "src";
|
|
3983
|
+
const docs = await resolveDocsConfig(userConfig.docs, { root, srcDir });
|
|
3984
|
+
const md = resolveMarkdownConfig(userConfig.md);
|
|
3985
|
+
const mdx = resolveMdxConfig(userConfig.mdx);
|
|
3986
|
+
const env2 = resolveEnv(userConfig.env, process.env);
|
|
3987
|
+
setEnv(env2);
|
|
3988
|
+
const generateBuildId = userConfig.generateBuildId || (() => `build-${Date.now()}`);
|
|
3989
|
+
const deploymentId = normalizeFarmDeploymentId(
|
|
3990
|
+
userConfig.deploymentId || process.env.FARM_DEPLOYMENT_ID || process.env.VERCEL_GIT_COMMIT_SHA || process.env.CF_PAGES_COMMIT_SHA || (mode === "production" ? await generateBuildId() : "development")
|
|
3991
|
+
);
|
|
3992
|
+
const resolved = {
|
|
3993
|
+
[FARM_RESOLVED_CUSTOM_CONTEXT]: typeof userConfig.context === "function",
|
|
3994
|
+
root,
|
|
3995
|
+
srcDir,
|
|
3996
|
+
extends: userConfig.extends || [],
|
|
3997
|
+
layers: layerResolution.layers,
|
|
3998
|
+
outDir: userConfig.outDir || "dist",
|
|
3999
|
+
basePath: userConfig.basePath || "/",
|
|
4000
|
+
preset: deploy.preset || "node-server",
|
|
4001
|
+
deploy,
|
|
4002
|
+
docs,
|
|
4003
|
+
md,
|
|
4004
|
+
mdx,
|
|
4005
|
+
migrations: resolveMigrationsConfig(userConfig.migrations),
|
|
4006
|
+
cron: resolveCronConfig(userConfig.cron),
|
|
4007
|
+
workflows: resolveWorkflowsConfig(userConfig.workflows),
|
|
4008
|
+
observability: userConfig.observability ?? false,
|
|
4009
|
+
devtools: resolveFarmDevtoolsConfig(userConfig.devtools, mode),
|
|
4010
|
+
storage: userConfig.storage || {},
|
|
4011
|
+
suppressLintOnLink: userConfig.suppressLintOnLink ?? false,
|
|
4012
|
+
experimental: {
|
|
4013
|
+
serverComponents: false,
|
|
4014
|
+
serverActions: false,
|
|
4015
|
+
...userConfig.experimental
|
|
4016
|
+
},
|
|
4017
|
+
plugins: [...resolveIntegrationPlugins(userConfig.integrations), ...userConfig.plugins || []],
|
|
4018
|
+
integrations: userConfig.integrations || {},
|
|
4019
|
+
trailingSlash: userConfig.trailingSlash ?? false,
|
|
4020
|
+
redirects: /* @__PURE__ */ __name(() => [...redirects, ...routeRuleRedirects], "redirects"),
|
|
4021
|
+
rewrites: /* @__PURE__ */ __name(() => rewrites, "rewrites"),
|
|
4022
|
+
headers: /* @__PURE__ */ __name(() => [...headers, ...routeRuleHeaders], "headers"),
|
|
4023
|
+
routeRules,
|
|
4024
|
+
images: resolveFarmImageConfig(userConfig.images),
|
|
4025
|
+
publicDir: userConfig.publicDir || "public",
|
|
4026
|
+
i18n: resolveFarmI18nConfig(userConfig.i18n, { root, mode }),
|
|
4027
|
+
openapi: {
|
|
4028
|
+
enabled: false,
|
|
4029
|
+
route: "/docs/reference",
|
|
4030
|
+
title: "API Documentation",
|
|
4031
|
+
description: "Auto-generated API documentation",
|
|
4032
|
+
version: "1.0.0",
|
|
4033
|
+
servers: [{ url: "http://localhost:3000", description: "Development server" }],
|
|
4034
|
+
...userConfig.openapi
|
|
4035
|
+
},
|
|
4036
|
+
middleware: userConfig.middleware || {},
|
|
4037
|
+
notFound: userConfig.notFound || {},
|
|
4038
|
+
context: userConfig.context || (() => void 0),
|
|
4039
|
+
serverActions: resolveServerActionsConfig(userConfig.serverActions),
|
|
4040
|
+
deploymentId,
|
|
4041
|
+
output: userConfig.output || "standalone",
|
|
4042
|
+
distDir: userConfig.distDir || ".farm",
|
|
4043
|
+
generateBuildId,
|
|
4044
|
+
compress: userConfig.compress ?? true,
|
|
4045
|
+
devIndicators: {
|
|
4046
|
+
buildActivity: true,
|
|
4047
|
+
buildActivityPosition: "bottom-right",
|
|
4048
|
+
...userConfig.devIndicators
|
|
4049
|
+
},
|
|
4050
|
+
serverRuntimeConfig: userConfig.serverRuntimeConfig || {},
|
|
4051
|
+
publicRuntimeConfig: userConfig.publicRuntimeConfig || {},
|
|
4052
|
+
env: env2,
|
|
4053
|
+
typescript: {
|
|
4054
|
+
tsconfigPath: "tsconfig.json",
|
|
4055
|
+
ignoreBuildErrors: false,
|
|
4056
|
+
...userConfig.typescript
|
|
4057
|
+
},
|
|
4058
|
+
vite: typeof userConfig.vite === "function" ? userConfig.vite({}) : userConfig.vite || {}
|
|
4059
|
+
};
|
|
4060
|
+
return resolved;
|
|
4061
|
+
}
|
|
4062
|
+
__name(resolveConfig, "resolveConfig");
|
|
4063
|
+
async function loadConfig(rootDir, configPath, mode = process.env.NODE_ENV === "production" ? "production" : "development", loadEnvironment) {
|
|
4064
|
+
const { existsSync: existsSync2 } = await import("fs");
|
|
4065
|
+
const loadEnv = loadEnvironment || (await import("vite")).loadEnv;
|
|
4066
|
+
const root = rootDir || process.cwd();
|
|
4067
|
+
const loadedEnv = loadEnv(mode, root, "");
|
|
4068
|
+
for (const [key, value] of Object.entries(loadedEnv)) {
|
|
4069
|
+
if (process.env[key] === void 0) {
|
|
4070
|
+
process.env[key] = value;
|
|
4071
|
+
}
|
|
4072
|
+
}
|
|
4073
|
+
const searchPaths = [
|
|
4074
|
+
configPath,
|
|
4075
|
+
"farm.config.ts",
|
|
4076
|
+
"farm.config.mts",
|
|
4077
|
+
"farm.config.js",
|
|
4078
|
+
"farm.config.mjs",
|
|
4079
|
+
"config.ts",
|
|
4080
|
+
"config.mts",
|
|
4081
|
+
"config.js",
|
|
4082
|
+
"config.mjs"
|
|
4083
|
+
].filter(Boolean);
|
|
4084
|
+
for (const relativePath of searchPaths) {
|
|
4085
|
+
try {
|
|
4086
|
+
const absolutePath = relativePath.startsWith("/") ? relativePath : import_path.default.join(root, relativePath);
|
|
4087
|
+
const normalizedPath = import_path.default.resolve(absolutePath);
|
|
4088
|
+
if (!existsSync2(normalizedPath)) {
|
|
4089
|
+
continue;
|
|
4090
|
+
}
|
|
4091
|
+
const loadedConfig = await loadFarmConfigFile(normalizedPath, { root });
|
|
4092
|
+
return loadedConfig.root === void 0 ? { ...loadedConfig, root } : loadedConfig;
|
|
4093
|
+
} catch (error) {
|
|
4094
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
4095
|
+
throw new Error(`Failed to load config from ${relativePath}: ${message}`);
|
|
4096
|
+
}
|
|
4097
|
+
}
|
|
4098
|
+
return void 0;
|
|
4099
|
+
}
|
|
4100
|
+
__name(loadConfig, "loadConfig");
|
|
4101
|
+
|
|
4102
|
+
// src/build/production-vite.ts
|
|
4103
|
+
function supportsRolldownVite(nodeVersion = process.versions.node) {
|
|
4104
|
+
const [major = 0, minor = 0] = nodeVersion.split(".").map(Number);
|
|
4105
|
+
return major === 20 && minor >= 19 || major > 22 || major === 22 && minor >= 12;
|
|
4106
|
+
}
|
|
4107
|
+
__name(supportsRolldownVite, "supportsRolldownVite");
|
|
4108
|
+
function requestedProductionViteBuilder() {
|
|
4109
|
+
const requested = process.env.FARM_VITE_BUILDER?.trim().toLowerCase();
|
|
4110
|
+
if (!requested) return void 0;
|
|
4111
|
+
if (requested === "rollup" || requested === "rolldown") return requested;
|
|
4112
|
+
throw new Error('FARM_VITE_BUILDER must be either "rolldown" or "rollup"');
|
|
4113
|
+
}
|
|
4114
|
+
__name(requestedProductionViteBuilder, "requestedProductionViteBuilder");
|
|
4115
|
+
async function loadRollupVite() {
|
|
4116
|
+
const runtime = await import("vite");
|
|
4117
|
+
return {
|
|
4118
|
+
build: runtime.build,
|
|
4119
|
+
createServer: runtime.createServer,
|
|
4120
|
+
loadEnv: runtime.loadEnv,
|
|
4121
|
+
builder: "rollup"
|
|
4122
|
+
};
|
|
4123
|
+
}
|
|
4124
|
+
__name(loadRollupVite, "loadRollupVite");
|
|
4125
|
+
async function loadFarmProductionVite() {
|
|
4126
|
+
const requested = requestedProductionViteBuilder();
|
|
4127
|
+
if (requested === "rollup" || !supportsRolldownVite()) {
|
|
4128
|
+
if (requested === "rolldown") {
|
|
4129
|
+
throw new Error(
|
|
4130
|
+
"FARM_VITE_BUILDER=rolldown requires Node 20.19+, Node 22.12+, or a newer release"
|
|
4131
|
+
);
|
|
4132
|
+
}
|
|
4133
|
+
return loadRollupVite();
|
|
4134
|
+
}
|
|
4135
|
+
try {
|
|
4136
|
+
const runtime = await import("vite-rolldown");
|
|
4137
|
+
return {
|
|
4138
|
+
build: runtime.build,
|
|
4139
|
+
createServer: runtime.createServer,
|
|
4140
|
+
loadEnv: runtime.loadEnv,
|
|
4141
|
+
builder: "rolldown"
|
|
4142
|
+
};
|
|
4143
|
+
} catch (error) {
|
|
4144
|
+
if (requested === "rolldown") {
|
|
4145
|
+
const detail = error instanceof Error ? `: ${error.message}` : "";
|
|
4146
|
+
throw new Error(
|
|
4147
|
+
`FARM_VITE_BUILDER=rolldown was requested, but the optional Vite Rolldown runtime could not be loaded${detail}`
|
|
4148
|
+
);
|
|
4149
|
+
}
|
|
4150
|
+
return loadRollupVite();
|
|
4151
|
+
}
|
|
4152
|
+
}
|
|
4153
|
+
__name(loadFarmProductionVite, "loadFarmProductionVite");
|
|
4154
|
+
|
|
4155
|
+
// src/utils.ts
|
|
4156
|
+
var logger = {
|
|
4157
|
+
info: /* @__PURE__ */ __name((message) => console.log(`[info] ${message}`), "info"),
|
|
4158
|
+
success: /* @__PURE__ */ __name((message) => console.log(`[success] ${message}`), "success"),
|
|
4159
|
+
warn: /* @__PURE__ */ __name((message) => console.warn(`\u26A0\uFE0F ${message}`), "warn"),
|
|
4160
|
+
error: /* @__PURE__ */ __name((message) => console.error(`\u274C ${message}`), "error"),
|
|
4161
|
+
ready: /* @__PURE__ */ __name((message) => console.log(`${message}`), "ready"),
|
|
4162
|
+
event: /* @__PURE__ */ __name((message) => console.log(` ${message}`), "event")
|
|
4163
|
+
};
|
|
4164
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
4165
|
+
0 && (module.exports = {
|
|
4166
|
+
loadConfig,
|
|
4167
|
+
loadFarmProductionVite,
|
|
4168
|
+
logger,
|
|
4169
|
+
resolveConfig,
|
|
4170
|
+
resolveDeployConfig
|
|
4171
|
+
});
|
|
4172
|
+
//# sourceMappingURL=config-runtime.cjs.map
|