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