@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,2820 @@
|
|
|
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/integrations.ts
|
|
631
|
+
var integrations_exports = {};
|
|
632
|
+
__export(integrations_exports, {
|
|
633
|
+
FARM_INTEGRATION_INTERNAL_DISPATCH_CONTEXT_KEY: () => FARM_INTEGRATION_INTERNAL_DISPATCH_CONTEXT_KEY,
|
|
634
|
+
api: () => api,
|
|
635
|
+
createIntegrationRoute: () => createIntegrationRoute,
|
|
636
|
+
defineIntegration: () => defineIntegration,
|
|
637
|
+
defineIntegrationAPI: () => defineIntegrationAPI,
|
|
638
|
+
defineIntegrationAPIOperation: () => defineIntegrationAPIOperation,
|
|
639
|
+
defineIntegrationSchema: () => defineIntegrationSchema,
|
|
640
|
+
dispatchIntegrationRequest: () => dispatchIntegrationRequest,
|
|
641
|
+
getFarmIntegrationPluginServerRuntime: () => getFarmIntegrationPluginServerRuntime,
|
|
642
|
+
getIntegrationDocumentNavigationMatchers: () => getIntegrationDocumentNavigationMatchers,
|
|
643
|
+
getIntegrationProviders: () => getIntegrationProviders,
|
|
644
|
+
getIntegrationSchemas: () => getIntegrationSchemas,
|
|
645
|
+
getRegisteredIntegrationAPIManifest: () => getRegisteredIntegrationAPIManifest,
|
|
646
|
+
getRegisteredIntegrationRuntime: () => getRegisteredIntegrationRuntime,
|
|
647
|
+
getRegisteredIntegrationSchemas: () => getRegisteredIntegrationSchemas,
|
|
648
|
+
getRegisteredIntegrations: () => getRegisteredIntegrations,
|
|
649
|
+
integrationRoute: () => integrationRoute,
|
|
650
|
+
isFarmIntegration: () => isFarmIntegration,
|
|
651
|
+
matchIntegrationRoute: () => matchIntegrationRoute,
|
|
652
|
+
matchRegisteredIntegrationRoute: () => matchRegisteredIntegrationRoute,
|
|
653
|
+
resolveIntegrationPlugins: () => resolveIntegrationPlugins
|
|
654
|
+
});
|
|
655
|
+
module.exports = __toCommonJS(integrations_exports);
|
|
656
|
+
|
|
657
|
+
// src/integration-api.ts
|
|
658
|
+
function defineIntegrationAPIOperation(operation2) {
|
|
659
|
+
return {
|
|
660
|
+
kind: "farm-integration-api-operation",
|
|
661
|
+
...operation2
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
__name(defineIntegrationAPIOperation, "defineIntegrationAPIOperation");
|
|
665
|
+
function defineIntegrationAPI(api2) {
|
|
666
|
+
return api2;
|
|
667
|
+
}
|
|
668
|
+
__name(defineIntegrationAPI, "defineIntegrationAPI");
|
|
669
|
+
function operation(method, pathOrOptions, maybeOptions = {}) {
|
|
670
|
+
const hasExplicitPath = typeof pathOrOptions === "string";
|
|
671
|
+
const path = hasExplicitPath ? pathOrOptions : "";
|
|
672
|
+
const options = hasExplicitPath ? maybeOptions : {
|
|
673
|
+
...maybeOptions,
|
|
674
|
+
...pathOrOptions
|
|
675
|
+
};
|
|
676
|
+
return defineIntegrationAPIOperation({
|
|
677
|
+
path,
|
|
678
|
+
method,
|
|
679
|
+
__pathless: !hasExplicitPath,
|
|
680
|
+
...options
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
__name(operation, "operation");
|
|
684
|
+
function get(pathOrOptions, maybeOptions = {}) {
|
|
685
|
+
return operation("GET", pathOrOptions, maybeOptions);
|
|
686
|
+
}
|
|
687
|
+
__name(get, "get");
|
|
688
|
+
function isOperation(value) {
|
|
689
|
+
return !!value && typeof value === "object" && value.kind === "farm-integration-api-operation";
|
|
690
|
+
}
|
|
691
|
+
__name(isOperation, "isOperation");
|
|
692
|
+
function bindRoutePath(path, api2) {
|
|
693
|
+
const entries = Object.entries(api2).map(([key, value]) => {
|
|
694
|
+
if (isOperation(value)) {
|
|
695
|
+
return [
|
|
696
|
+
key,
|
|
697
|
+
{
|
|
698
|
+
...value,
|
|
699
|
+
path,
|
|
700
|
+
__pathless: false
|
|
701
|
+
}
|
|
702
|
+
];
|
|
703
|
+
}
|
|
704
|
+
if (value && typeof value === "object") {
|
|
705
|
+
return [key, bindRoutePath(path, value)];
|
|
706
|
+
}
|
|
707
|
+
return [key, value];
|
|
708
|
+
});
|
|
709
|
+
return Object.fromEntries(entries);
|
|
710
|
+
}
|
|
711
|
+
__name(bindRoutePath, "bindRoutePath");
|
|
712
|
+
function route(path, definitionOrOperation, ...operations) {
|
|
713
|
+
if (isOperation(definitionOrOperation)) {
|
|
714
|
+
const allOperations = [definitionOrOperation, ...operations];
|
|
715
|
+
return Object.fromEntries(
|
|
716
|
+
allOperations.map((operation2) => [
|
|
717
|
+
operation2.method.toLowerCase(),
|
|
718
|
+
{
|
|
719
|
+
...operation2,
|
|
720
|
+
path,
|
|
721
|
+
__pathless: false
|
|
722
|
+
}
|
|
723
|
+
])
|
|
724
|
+
);
|
|
725
|
+
}
|
|
726
|
+
return bindRoutePath(path, definitionOrOperation);
|
|
727
|
+
}
|
|
728
|
+
__name(route, "route");
|
|
729
|
+
function normalizeRouteSegment(segment) {
|
|
730
|
+
if (!segment) {
|
|
731
|
+
return "index";
|
|
732
|
+
}
|
|
733
|
+
if (segment.startsWith("[...") && segment.endsWith("]")) {
|
|
734
|
+
return segment.slice(4, -1) || "index";
|
|
735
|
+
}
|
|
736
|
+
if (segment.startsWith("[") && segment.endsWith("]")) {
|
|
737
|
+
return segment.slice(1, -1) || "index";
|
|
738
|
+
}
|
|
739
|
+
const matcherIndex = segment.indexOf("(");
|
|
740
|
+
if (matcherIndex > 0) {
|
|
741
|
+
return segment.slice(0, matcherIndex);
|
|
742
|
+
}
|
|
743
|
+
return camelCaseRouteSegment(segment);
|
|
744
|
+
}
|
|
745
|
+
__name(normalizeRouteSegment, "normalizeRouteSegment");
|
|
746
|
+
function camelCaseRouteSegment(segment) {
|
|
747
|
+
return segment.replace(/-([a-zA-Z0-9])/g, (_match, value) => value.toUpperCase());
|
|
748
|
+
}
|
|
749
|
+
__name(camelCaseRouteSegment, "camelCaseRouteSegment");
|
|
750
|
+
function getRouteClientSegments(path) {
|
|
751
|
+
const segments = path.split("/").filter(Boolean);
|
|
752
|
+
if (segments.length === 0) {
|
|
753
|
+
return ["index"];
|
|
754
|
+
}
|
|
755
|
+
const stripped = segments[0] === "api" && segments.length > 2 ? segments.slice(2) : segments.length > 1 ? segments.slice(1) : [segments[segments.length - 1]];
|
|
756
|
+
return stripped.map(normalizeRouteSegment).filter(Boolean);
|
|
757
|
+
}
|
|
758
|
+
__name(getRouteClientSegments, "getRouteClientSegments");
|
|
759
|
+
function setRouteOperation(target, pathSegments, operation2) {
|
|
760
|
+
const [head, ...tail] = pathSegments;
|
|
761
|
+
if (!head) {
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
if (tail.length === 0) {
|
|
765
|
+
const leaf = target[head] || {};
|
|
766
|
+
leaf[operation2.method.toLowerCase()] = {
|
|
767
|
+
...operation2,
|
|
768
|
+
path: operation2.path,
|
|
769
|
+
__pathless: false
|
|
770
|
+
};
|
|
771
|
+
target[head] = leaf;
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
const branch = target[head] || {};
|
|
775
|
+
target[head] = branch;
|
|
776
|
+
setRouteOperation(branch, tail, operation2);
|
|
777
|
+
}
|
|
778
|
+
__name(setRouteOperation, "setRouteOperation");
|
|
779
|
+
function fromRoutes(routes) {
|
|
780
|
+
const definition = {};
|
|
781
|
+
for (const route2 of routes) {
|
|
782
|
+
if (!isOperation(route2.__operation)) {
|
|
783
|
+
continue;
|
|
784
|
+
}
|
|
785
|
+
setRouteOperation(definition, getRouteClientSegments(route2.path), {
|
|
786
|
+
...route2.__operation,
|
|
787
|
+
path: route2.path,
|
|
788
|
+
__pathless: false
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
return definition;
|
|
792
|
+
}
|
|
793
|
+
__name(fromRoutes, "fromRoutes");
|
|
794
|
+
var api = {
|
|
795
|
+
get,
|
|
796
|
+
route,
|
|
797
|
+
fromRoutes,
|
|
798
|
+
post(pathOrOptions, maybeOptions = {}) {
|
|
799
|
+
return operation("POST", pathOrOptions, {
|
|
800
|
+
bodyFormat: "json",
|
|
801
|
+
...typeof pathOrOptions === "string" ? maybeOptions : pathOrOptions
|
|
802
|
+
});
|
|
803
|
+
},
|
|
804
|
+
put(pathOrOptions, maybeOptions = {}) {
|
|
805
|
+
return operation("PUT", pathOrOptions, {
|
|
806
|
+
bodyFormat: "json",
|
|
807
|
+
...typeof pathOrOptions === "string" ? maybeOptions : pathOrOptions
|
|
808
|
+
});
|
|
809
|
+
},
|
|
810
|
+
patch(pathOrOptions, maybeOptions = {}) {
|
|
811
|
+
return operation("PATCH", pathOrOptions, {
|
|
812
|
+
bodyFormat: "json",
|
|
813
|
+
...typeof pathOrOptions === "string" ? maybeOptions : pathOrOptions
|
|
814
|
+
});
|
|
815
|
+
},
|
|
816
|
+
delete(pathOrOptions, maybeOptions = {}) {
|
|
817
|
+
return operation("DELETE", pathOrOptions, {
|
|
818
|
+
bodyFormat: "json",
|
|
819
|
+
...typeof pathOrOptions === "string" ? maybeOptions : pathOrOptions
|
|
820
|
+
});
|
|
821
|
+
},
|
|
822
|
+
options(pathOrOptions, maybeOptions = {}) {
|
|
823
|
+
return operation(
|
|
824
|
+
"OPTIONS",
|
|
825
|
+
pathOrOptions,
|
|
826
|
+
maybeOptions
|
|
827
|
+
);
|
|
828
|
+
},
|
|
829
|
+
head(pathOrOptions, maybeOptions = {}) {
|
|
830
|
+
return operation(
|
|
831
|
+
"HEAD",
|
|
832
|
+
pathOrOptions,
|
|
833
|
+
maybeOptions
|
|
834
|
+
);
|
|
835
|
+
},
|
|
836
|
+
form: {
|
|
837
|
+
post(pathOrOptions, maybeOptions = {}) {
|
|
838
|
+
return operation("POST", pathOrOptions, {
|
|
839
|
+
bodyFormat: "form",
|
|
840
|
+
...typeof pathOrOptions === "string" ? maybeOptions : pathOrOptions
|
|
841
|
+
});
|
|
842
|
+
},
|
|
843
|
+
put(pathOrOptions, maybeOptions = {}) {
|
|
844
|
+
return operation("PUT", pathOrOptions, {
|
|
845
|
+
bodyFormat: "form",
|
|
846
|
+
...typeof pathOrOptions === "string" ? maybeOptions : pathOrOptions
|
|
847
|
+
});
|
|
848
|
+
},
|
|
849
|
+
patch(pathOrOptions, maybeOptions = {}) {
|
|
850
|
+
return operation("PATCH", pathOrOptions, {
|
|
851
|
+
bodyFormat: "form",
|
|
852
|
+
...typeof pathOrOptions === "string" ? maybeOptions : pathOrOptions
|
|
853
|
+
});
|
|
854
|
+
},
|
|
855
|
+
delete(pathOrOptions, maybeOptions = {}) {
|
|
856
|
+
return operation("DELETE", pathOrOptions, {
|
|
857
|
+
bodyFormat: "form",
|
|
858
|
+
...typeof pathOrOptions === "string" ? maybeOptions : pathOrOptions
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
|
|
864
|
+
// src/request-context.ts
|
|
865
|
+
var REQUEST_CONTEXT_STORE_KEY = /* @__PURE__ */ Symbol.for("farm.requestContextStore");
|
|
866
|
+
function getRequestContextStore() {
|
|
867
|
+
const globalState = globalThis;
|
|
868
|
+
if (!globalState[REQUEST_CONTEXT_STORE_KEY]) {
|
|
869
|
+
globalState[REQUEST_CONTEXT_STORE_KEY] = /* @__PURE__ */ new WeakMap();
|
|
870
|
+
}
|
|
871
|
+
return globalState[REQUEST_CONTEXT_STORE_KEY];
|
|
872
|
+
}
|
|
873
|
+
__name(getRequestContextStore, "getRequestContextStore");
|
|
874
|
+
function getBucket(target) {
|
|
875
|
+
const requestContextStore = getRequestContextStore();
|
|
876
|
+
let bucket = requestContextStore.get(target);
|
|
877
|
+
if (!bucket) {
|
|
878
|
+
bucket = {
|
|
879
|
+
privateData: /* @__PURE__ */ new Map(),
|
|
880
|
+
exposedData: /* @__PURE__ */ new Map()
|
|
881
|
+
};
|
|
882
|
+
requestContextStore.set(target, bucket);
|
|
883
|
+
}
|
|
884
|
+
return bucket;
|
|
885
|
+
}
|
|
886
|
+
__name(getBucket, "getBucket");
|
|
887
|
+
function setRequestContext(target, key, value, options = {}) {
|
|
888
|
+
const bucket = getBucket(target);
|
|
889
|
+
bucket.privateData.set(key, value);
|
|
890
|
+
if (options.exposeToPage) {
|
|
891
|
+
bucket.exposedData.set(key, value);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
__name(setRequestContext, "setRequestContext");
|
|
895
|
+
function getRequestContext(target, key) {
|
|
896
|
+
const requestContextStore = getRequestContextStore();
|
|
897
|
+
const bucket = requestContextStore.get(target);
|
|
898
|
+
return bucket?.privateData.get(key);
|
|
899
|
+
}
|
|
900
|
+
__name(getRequestContext, "getRequestContext");
|
|
901
|
+
function hasRequestContext(target, key) {
|
|
902
|
+
const requestContextStore = getRequestContextStore();
|
|
903
|
+
const bucket = requestContextStore.get(target);
|
|
904
|
+
return bucket?.privateData.has(key) ?? false;
|
|
905
|
+
}
|
|
906
|
+
__name(hasRequestContext, "hasRequestContext");
|
|
907
|
+
function deleteRequestContext(target, key) {
|
|
908
|
+
const requestContextStore = getRequestContextStore();
|
|
909
|
+
const bucket = requestContextStore.get(target);
|
|
910
|
+
if (!bucket) return false;
|
|
911
|
+
const removedPrivate = bucket.privateData.delete(key);
|
|
912
|
+
bucket.exposedData.delete(key);
|
|
913
|
+
return removedPrivate;
|
|
914
|
+
}
|
|
915
|
+
__name(deleteRequestContext, "deleteRequestContext");
|
|
916
|
+
function clearRequestContext(target) {
|
|
917
|
+
const requestContextStore = getRequestContextStore();
|
|
918
|
+
const bucket = requestContextStore.get(target);
|
|
919
|
+
if (!bucket) return;
|
|
920
|
+
bucket.privateData.clear();
|
|
921
|
+
bucket.exposedData.clear();
|
|
922
|
+
}
|
|
923
|
+
__name(clearRequestContext, "clearRequestContext");
|
|
924
|
+
function getRequestContextSnapshot(target, options = {}) {
|
|
925
|
+
const requestContextStore = getRequestContextStore();
|
|
926
|
+
const bucket = requestContextStore.get(target);
|
|
927
|
+
if (!bucket) return /* @__PURE__ */ new Map();
|
|
928
|
+
if (options.exposedOnly) {
|
|
929
|
+
return new Map(bucket.exposedData);
|
|
930
|
+
}
|
|
931
|
+
return new Map(bucket.privateData);
|
|
932
|
+
}
|
|
933
|
+
__name(getRequestContextSnapshot, "getRequestContextSnapshot");
|
|
934
|
+
|
|
935
|
+
// src/server/response.ts
|
|
936
|
+
var import_node_events = require("events");
|
|
937
|
+
async function sendWebResponse(res, response) {
|
|
938
|
+
res.statusCode = response.status;
|
|
939
|
+
const responseHeaders = response.headers;
|
|
940
|
+
const setCookies = responseHeaders.getSetCookie?.() || [];
|
|
941
|
+
if (setCookies.length > 0) {
|
|
942
|
+
res.setHeader("Set-Cookie", setCookies);
|
|
943
|
+
}
|
|
944
|
+
response.headers.forEach((value, key) => {
|
|
945
|
+
if (key.toLowerCase() === "set-cookie" && setCookies.length > 0) {
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
res.setHeader(key, value);
|
|
949
|
+
});
|
|
950
|
+
if (!response.body) {
|
|
951
|
+
res.end();
|
|
952
|
+
return;
|
|
953
|
+
}
|
|
954
|
+
if (typeof res.write !== "function") {
|
|
955
|
+
const body = await response.arrayBuffer();
|
|
956
|
+
res.end(Buffer.from(body));
|
|
957
|
+
return;
|
|
958
|
+
}
|
|
959
|
+
const reader = response.body.getReader();
|
|
960
|
+
try {
|
|
961
|
+
while (true) {
|
|
962
|
+
const { done, value } = await reader.read();
|
|
963
|
+
if (done) {
|
|
964
|
+
break;
|
|
965
|
+
}
|
|
966
|
+
if (!value || value.byteLength === 0) {
|
|
967
|
+
continue;
|
|
968
|
+
}
|
|
969
|
+
if (!res.write(value)) {
|
|
970
|
+
await (0, import_node_events.once)(res, "drain");
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
res.end();
|
|
974
|
+
} catch (error) {
|
|
975
|
+
if (!res.writableEnded) {
|
|
976
|
+
const responseError = error instanceof Error ? error : new Error(String(error));
|
|
977
|
+
if (typeof res.destroy === "function") {
|
|
978
|
+
res.destroy(responseError);
|
|
979
|
+
} else {
|
|
980
|
+
res.end();
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
throw error;
|
|
984
|
+
} finally {
|
|
985
|
+
reader.releaseLock();
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
__name(sendWebResponse, "sendWebResponse");
|
|
989
|
+
|
|
990
|
+
// src/integrations.ts
|
|
991
|
+
var FARM_INTEGRATION_INTERNAL_DISPATCH_CONTEXT_KEY = "farm.integration.internalDispatch";
|
|
992
|
+
function defineIntegrationSchema(schema) {
|
|
993
|
+
return schema;
|
|
994
|
+
}
|
|
995
|
+
__name(defineIntegrationSchema, "defineIntegrationSchema");
|
|
996
|
+
var FARM_INTEGRATION_PLUGIN_SERVER_RUNTIME = /* @__PURE__ */ Symbol.for(
|
|
997
|
+
"@farm.js/core/integration-plugin-server-runtime"
|
|
998
|
+
);
|
|
999
|
+
function getFarmIntegrationPluginServerRuntime(plugin) {
|
|
1000
|
+
const value = plugin[FARM_INTEGRATION_PLUGIN_SERVER_RUNTIME];
|
|
1001
|
+
return typeof value === "boolean" ? value : void 0;
|
|
1002
|
+
}
|
|
1003
|
+
__name(getFarmIntegrationPluginServerRuntime, "getFarmIntegrationPluginServerRuntime");
|
|
1004
|
+
function defineTypedIntegrationRoute(method, path, input) {
|
|
1005
|
+
return {
|
|
1006
|
+
path,
|
|
1007
|
+
method,
|
|
1008
|
+
middleware: input.middleware,
|
|
1009
|
+
before: input.before,
|
|
1010
|
+
after: input.after,
|
|
1011
|
+
rawBody: input.rawBody,
|
|
1012
|
+
bodyFormat: input.bodyFormat,
|
|
1013
|
+
input: normalizeIntegrationRouteInputSchemas(input),
|
|
1014
|
+
handler: input.handler,
|
|
1015
|
+
__operation: defineIntegrationAPIOperation({
|
|
1016
|
+
path,
|
|
1017
|
+
method,
|
|
1018
|
+
bodyFormat: input.bodyFormat,
|
|
1019
|
+
responseFormat: input.responseFormat,
|
|
1020
|
+
headers: input.headers,
|
|
1021
|
+
credentials: input.credentials,
|
|
1022
|
+
isServer: input.isServer
|
|
1023
|
+
})
|
|
1024
|
+
};
|
|
1025
|
+
}
|
|
1026
|
+
__name(defineTypedIntegrationRoute, "defineTypedIntegrationRoute");
|
|
1027
|
+
function createIntegrationRouteFactory() {
|
|
1028
|
+
return {
|
|
1029
|
+
get(path, input) {
|
|
1030
|
+
return defineTypedIntegrationRoute(
|
|
1031
|
+
"GET",
|
|
1032
|
+
path,
|
|
1033
|
+
input
|
|
1034
|
+
);
|
|
1035
|
+
},
|
|
1036
|
+
post(path, input) {
|
|
1037
|
+
return defineTypedIntegrationRoute(
|
|
1038
|
+
"POST",
|
|
1039
|
+
path,
|
|
1040
|
+
{
|
|
1041
|
+
bodyFormat: "json",
|
|
1042
|
+
...input
|
|
1043
|
+
}
|
|
1044
|
+
);
|
|
1045
|
+
},
|
|
1046
|
+
put(path, input) {
|
|
1047
|
+
return defineTypedIntegrationRoute(
|
|
1048
|
+
"PUT",
|
|
1049
|
+
path,
|
|
1050
|
+
{
|
|
1051
|
+
bodyFormat: "json",
|
|
1052
|
+
...input
|
|
1053
|
+
}
|
|
1054
|
+
);
|
|
1055
|
+
},
|
|
1056
|
+
patch(path, input) {
|
|
1057
|
+
return defineTypedIntegrationRoute("PATCH", path, {
|
|
1058
|
+
bodyFormat: "json",
|
|
1059
|
+
...input
|
|
1060
|
+
});
|
|
1061
|
+
},
|
|
1062
|
+
delete(path, input) {
|
|
1063
|
+
return defineTypedIntegrationRoute("DELETE", path, {
|
|
1064
|
+
bodyFormat: "json",
|
|
1065
|
+
...input
|
|
1066
|
+
});
|
|
1067
|
+
},
|
|
1068
|
+
options(path, input) {
|
|
1069
|
+
return defineTypedIntegrationRoute("OPTIONS", path, input);
|
|
1070
|
+
},
|
|
1071
|
+
head(path, input) {
|
|
1072
|
+
return defineTypedIntegrationRoute(
|
|
1073
|
+
"HEAD",
|
|
1074
|
+
path,
|
|
1075
|
+
input
|
|
1076
|
+
);
|
|
1077
|
+
}
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
__name(createIntegrationRouteFactory, "createIntegrationRouteFactory");
|
|
1081
|
+
function createIntegrationRoute(_schema) {
|
|
1082
|
+
return createIntegrationRouteFactory();
|
|
1083
|
+
}
|
|
1084
|
+
__name(createIntegrationRoute, "createIntegrationRoute");
|
|
1085
|
+
var integrationRoute = createIntegrationRouteFactory();
|
|
1086
|
+
var INTEGRATION_RUNTIME_REGISTRY_KEY = /* @__PURE__ */ Symbol.for("farm.integrationRuntimeRegistry");
|
|
1087
|
+
var INTEGRATION_REQUEST_DISPATCHER_KEY = /* @__PURE__ */ Symbol.for("farm.integrationRequestDispatcher");
|
|
1088
|
+
function getIntegrationRuntimeRegistry() {
|
|
1089
|
+
const globalState = globalThis;
|
|
1090
|
+
if (!globalState[INTEGRATION_RUNTIME_REGISTRY_KEY]) {
|
|
1091
|
+
globalState[INTEGRATION_RUNTIME_REGISTRY_KEY] = /* @__PURE__ */ new Map();
|
|
1092
|
+
}
|
|
1093
|
+
return globalState[INTEGRATION_RUNTIME_REGISTRY_KEY];
|
|
1094
|
+
}
|
|
1095
|
+
__name(getIntegrationRuntimeRegistry, "getIntegrationRuntimeRegistry");
|
|
1096
|
+
function isIntegrationEndpointRoute(value) {
|
|
1097
|
+
return !!value && typeof value === "object" && typeof value.path === "string" && typeof value.handler === "function";
|
|
1098
|
+
}
|
|
1099
|
+
__name(isIntegrationEndpointRoute, "isIntegrationEndpointRoute");
|
|
1100
|
+
function flattenIntegrationEndpoints(endpoints) {
|
|
1101
|
+
if (!endpoints) {
|
|
1102
|
+
return [];
|
|
1103
|
+
}
|
|
1104
|
+
if (Array.isArray(endpoints)) {
|
|
1105
|
+
return endpoints.flatMap((endpoint) => flattenIntegrationEndpoints(endpoint));
|
|
1106
|
+
}
|
|
1107
|
+
if (isIntegrationEndpointRoute(endpoints)) {
|
|
1108
|
+
return [endpoints];
|
|
1109
|
+
}
|
|
1110
|
+
if (typeof endpoints === "object") {
|
|
1111
|
+
return Object.values(endpoints).flatMap((endpoint) => flattenIntegrationEndpoints(endpoint));
|
|
1112
|
+
}
|
|
1113
|
+
return [];
|
|
1114
|
+
}
|
|
1115
|
+
__name(flattenIntegrationEndpoints, "flattenIntegrationEndpoints");
|
|
1116
|
+
function defineIntegration(integration) {
|
|
1117
|
+
const category = integration.category ?? integration.slot;
|
|
1118
|
+
if (!category) {
|
|
1119
|
+
throw new Error("Integration category is required.");
|
|
1120
|
+
}
|
|
1121
|
+
if (integration.category && integration.slot && integration.category !== integration.slot) {
|
|
1122
|
+
throw new Error("Integration category and slot must match when both are provided.");
|
|
1123
|
+
}
|
|
1124
|
+
const routeFactory = createIntegrationRoute(integration.schema);
|
|
1125
|
+
const routes = typeof integration.routes === "function" ? integration.routes({
|
|
1126
|
+
route: routeFactory,
|
|
1127
|
+
integrationRoute: routeFactory
|
|
1128
|
+
}) : integration.routes;
|
|
1129
|
+
const endpoints = typeof integration.endpoints === "function" ? integration.endpoints({
|
|
1130
|
+
endpoint: routeFactory,
|
|
1131
|
+
route: routeFactory,
|
|
1132
|
+
integrationRoute: routeFactory
|
|
1133
|
+
}) : integration.endpoints;
|
|
1134
|
+
const endpointRoutes = flattenIntegrationEndpoints(endpoints);
|
|
1135
|
+
const allRoutes = routes?.length || endpointRoutes.length ? [...routes || [], ...endpointRoutes] : void 0;
|
|
1136
|
+
const derivedApi = integration.api || (allRoutes?.length ? api.fromRoutes(
|
|
1137
|
+
allRoutes
|
|
1138
|
+
) : void 0);
|
|
1139
|
+
return {
|
|
1140
|
+
kind: "farm-integration",
|
|
1141
|
+
...integration,
|
|
1142
|
+
endpoints,
|
|
1143
|
+
routes: allRoutes,
|
|
1144
|
+
api: derivedApi,
|
|
1145
|
+
category,
|
|
1146
|
+
slot: category
|
|
1147
|
+
};
|
|
1148
|
+
}
|
|
1149
|
+
__name(defineIntegration, "defineIntegration");
|
|
1150
|
+
function isFarmIntegration(value) {
|
|
1151
|
+
return !!value && typeof value === "object" && value.kind === "farm-integration";
|
|
1152
|
+
}
|
|
1153
|
+
__name(isFarmIntegration, "isFarmIntegration");
|
|
1154
|
+
function resolveIntegrationPlugins(integrations) {
|
|
1155
|
+
if (!integrations) {
|
|
1156
|
+
return [];
|
|
1157
|
+
}
|
|
1158
|
+
const plugins = [];
|
|
1159
|
+
for (const [key, integration] of Object.entries(integrations)) {
|
|
1160
|
+
if (!integration || !isFarmIntegration(integration)) {
|
|
1161
|
+
continue;
|
|
1162
|
+
}
|
|
1163
|
+
plugins.push(createIntegrationPlugin(key, integration));
|
|
1164
|
+
if (integration.plugins?.length) {
|
|
1165
|
+
plugins.push(...integration.plugins);
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
return plugins;
|
|
1169
|
+
}
|
|
1170
|
+
__name(resolveIntegrationPlugins, "resolveIntegrationPlugins");
|
|
1171
|
+
function getIntegrationProviders(integrations) {
|
|
1172
|
+
if (!integrations) {
|
|
1173
|
+
return [];
|
|
1174
|
+
}
|
|
1175
|
+
const providers = [];
|
|
1176
|
+
for (const integration of Object.values(integrations)) {
|
|
1177
|
+
if (!integration || !isFarmIntegration(integration) || !integration.providers?.length) {
|
|
1178
|
+
continue;
|
|
1179
|
+
}
|
|
1180
|
+
for (const provider of integration.providers) {
|
|
1181
|
+
providers.push({
|
|
1182
|
+
name: provider.name,
|
|
1183
|
+
type: provider.type,
|
|
1184
|
+
props: provider.props
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
return providers;
|
|
1189
|
+
}
|
|
1190
|
+
__name(getIntegrationProviders, "getIntegrationProviders");
|
|
1191
|
+
function getIntegrationDocumentNavigationMatchers(integrations) {
|
|
1192
|
+
if (!integrations) {
|
|
1193
|
+
return [];
|
|
1194
|
+
}
|
|
1195
|
+
const matchers = [];
|
|
1196
|
+
for (const integration of Object.values(integrations)) {
|
|
1197
|
+
if (!integration || !isFarmIntegration(integration) || !integration.documentNavigations?.length) {
|
|
1198
|
+
continue;
|
|
1199
|
+
}
|
|
1200
|
+
for (const navigation of integration.documentNavigations) {
|
|
1201
|
+
const items = Array.isArray(navigation.matcher) ? navigation.matcher : [navigation.matcher];
|
|
1202
|
+
for (const item of items) {
|
|
1203
|
+
matchers.push(item);
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
return matchers;
|
|
1208
|
+
}
|
|
1209
|
+
__name(getIntegrationDocumentNavigationMatchers, "getIntegrationDocumentNavigationMatchers");
|
|
1210
|
+
function getIntegrationSchemas(integrations) {
|
|
1211
|
+
if (!integrations) {
|
|
1212
|
+
return {};
|
|
1213
|
+
}
|
|
1214
|
+
const schemaEntries = Object.entries(integrations).map(([key, integration]) => {
|
|
1215
|
+
const schema = integration && isFarmIntegration(integration) ? integration.schema : void 0;
|
|
1216
|
+
return schema ? [key, schema] : null;
|
|
1217
|
+
}).filter((value) => value !== null);
|
|
1218
|
+
return Object.fromEntries(schemaEntries);
|
|
1219
|
+
}
|
|
1220
|
+
__name(getIntegrationSchemas, "getIntegrationSchemas");
|
|
1221
|
+
function getRegisteredIntegrationRuntime(key) {
|
|
1222
|
+
return getIntegrationRuntimeRegistry().get(key);
|
|
1223
|
+
}
|
|
1224
|
+
__name(getRegisteredIntegrationRuntime, "getRegisteredIntegrationRuntime");
|
|
1225
|
+
function getRegisteredIntegrations() {
|
|
1226
|
+
return Object.fromEntries(
|
|
1227
|
+
Array.from(getIntegrationRuntimeRegistry().entries()).map(([key, runtime]) => [
|
|
1228
|
+
key,
|
|
1229
|
+
runtime.integration
|
|
1230
|
+
])
|
|
1231
|
+
);
|
|
1232
|
+
}
|
|
1233
|
+
__name(getRegisteredIntegrations, "getRegisteredIntegrations");
|
|
1234
|
+
function getRegisteredIntegrationSchemas() {
|
|
1235
|
+
return getIntegrationSchemas(getRegisteredIntegrations());
|
|
1236
|
+
}
|
|
1237
|
+
__name(getRegisteredIntegrationSchemas, "getRegisteredIntegrationSchemas");
|
|
1238
|
+
function matchIntegrationRoute(integrations, input) {
|
|
1239
|
+
if (!integrations) {
|
|
1240
|
+
return null;
|
|
1241
|
+
}
|
|
1242
|
+
for (const [key, integration] of Object.entries(integrations)) {
|
|
1243
|
+
if (!integration || !isFarmIntegration(integration)) {
|
|
1244
|
+
continue;
|
|
1245
|
+
}
|
|
1246
|
+
const routes = normalizeIntegrationRoutes(integration.routes || []);
|
|
1247
|
+
for (const route2 of routes) {
|
|
1248
|
+
if (!matchesMethod(route2.methods, input.method)) {
|
|
1249
|
+
continue;
|
|
1250
|
+
}
|
|
1251
|
+
const params = extractPathParams(route2.path, input.pathname);
|
|
1252
|
+
if (!params) {
|
|
1253
|
+
continue;
|
|
1254
|
+
}
|
|
1255
|
+
return {
|
|
1256
|
+
key,
|
|
1257
|
+
integration,
|
|
1258
|
+
route: {
|
|
1259
|
+
path: route2.path,
|
|
1260
|
+
methods: route2.methods
|
|
1261
|
+
},
|
|
1262
|
+
params
|
|
1263
|
+
};
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
return null;
|
|
1267
|
+
}
|
|
1268
|
+
__name(matchIntegrationRoute, "matchIntegrationRoute");
|
|
1269
|
+
function matchRegisteredIntegrationRoute(input) {
|
|
1270
|
+
return matchIntegrationRoute(getRegisteredIntegrations(), input);
|
|
1271
|
+
}
|
|
1272
|
+
__name(matchRegisteredIntegrationRoute, "matchRegisteredIntegrationRoute");
|
|
1273
|
+
function createClientSafeIntegrationAPI(api2) {
|
|
1274
|
+
if (!api2) {
|
|
1275
|
+
return void 0;
|
|
1276
|
+
}
|
|
1277
|
+
const entries = Object.entries(api2).map(([key, value]) => {
|
|
1278
|
+
if (value && typeof value === "object" && value.kind === "farm-integration-api-operation") {
|
|
1279
|
+
const operation2 = value;
|
|
1280
|
+
return [
|
|
1281
|
+
key,
|
|
1282
|
+
defineIntegrationAPIOperation({
|
|
1283
|
+
path: operation2.path,
|
|
1284
|
+
method: operation2.method,
|
|
1285
|
+
bodyFormat: operation2.bodyFormat,
|
|
1286
|
+
responseFormat: operation2.responseFormat,
|
|
1287
|
+
credentials: operation2.credentials,
|
|
1288
|
+
isServer: operation2.isServer
|
|
1289
|
+
})
|
|
1290
|
+
];
|
|
1291
|
+
}
|
|
1292
|
+
if (value && typeof value === "object") {
|
|
1293
|
+
return [key, createClientSafeIntegrationAPI(value)];
|
|
1294
|
+
}
|
|
1295
|
+
return [key, value];
|
|
1296
|
+
});
|
|
1297
|
+
return Object.fromEntries(entries);
|
|
1298
|
+
}
|
|
1299
|
+
__name(createClientSafeIntegrationAPI, "createClientSafeIntegrationAPI");
|
|
1300
|
+
function getRegisteredIntegrationAPIManifest() {
|
|
1301
|
+
const manifestEntries = Object.entries(getRegisteredIntegrations()).map(([key, integration]) => {
|
|
1302
|
+
const api2 = createClientSafeIntegrationAPI(integration.api);
|
|
1303
|
+
return api2 ? [key, api2] : null;
|
|
1304
|
+
}).filter((value) => value !== null);
|
|
1305
|
+
return Object.fromEntries(manifestEntries);
|
|
1306
|
+
}
|
|
1307
|
+
__name(getRegisteredIntegrationAPIManifest, "getRegisteredIntegrationAPIManifest");
|
|
1308
|
+
function getIntegrationRuntimeEnv() {
|
|
1309
|
+
return typeof process !== "undefined" ? process.env : {};
|
|
1310
|
+
}
|
|
1311
|
+
__name(getIntegrationRuntimeEnv, "getIntegrationRuntimeEnv");
|
|
1312
|
+
function isIntegrationConfigDefinition(value) {
|
|
1313
|
+
return !!value && typeof value === "object" && ("schema" in value || "env" in value || "defaults" in value || "input" in value || "resolve" in value);
|
|
1314
|
+
}
|
|
1315
|
+
__name(isIntegrationConfigDefinition, "isIntegrationConfigDefinition");
|
|
1316
|
+
function mergeIntegrationConfigValue(current, next) {
|
|
1317
|
+
if (next === void 0) {
|
|
1318
|
+
return current;
|
|
1319
|
+
}
|
|
1320
|
+
if (isPlainIntegrationConfigObject(current) && isPlainIntegrationConfigObject(next)) {
|
|
1321
|
+
return {
|
|
1322
|
+
...current,
|
|
1323
|
+
...next
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1326
|
+
return next;
|
|
1327
|
+
}
|
|
1328
|
+
__name(mergeIntegrationConfigValue, "mergeIntegrationConfigValue");
|
|
1329
|
+
function isPlainIntegrationConfigObject(value) {
|
|
1330
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
1331
|
+
}
|
|
1332
|
+
__name(isPlainIntegrationConfigObject, "isPlainIntegrationConfigObject");
|
|
1333
|
+
async function resolveIntegrationConfigPart(value, context) {
|
|
1334
|
+
if (typeof value === "function") {
|
|
1335
|
+
return value(context);
|
|
1336
|
+
}
|
|
1337
|
+
return value;
|
|
1338
|
+
}
|
|
1339
|
+
__name(resolveIntegrationConfigPart, "resolveIntegrationConfigPart");
|
|
1340
|
+
function resolveIntegrationEnvConfig(env) {
|
|
1341
|
+
if (!env) {
|
|
1342
|
+
return void 0;
|
|
1343
|
+
}
|
|
1344
|
+
const runtimeEnv = getIntegrationRuntimeEnv();
|
|
1345
|
+
const config = {};
|
|
1346
|
+
for (const [key, names] of Object.entries(env)) {
|
|
1347
|
+
const envNames = Array.isArray(names) ? names : [names];
|
|
1348
|
+
const value = envNames.map((name) => runtimeEnv[name]).find((entry) => entry !== void 0);
|
|
1349
|
+
if (value !== void 0) {
|
|
1350
|
+
config[key] = value;
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1353
|
+
return config;
|
|
1354
|
+
}
|
|
1355
|
+
__name(resolveIntegrationEnvConfig, "resolveIntegrationEnvConfig");
|
|
1356
|
+
async function parseIntegrationConfigSchema(integration, schema, value) {
|
|
1357
|
+
const parser = schema.safeParseAsync || schema.safeParse;
|
|
1358
|
+
if (parser) {
|
|
1359
|
+
const result = await parser.call(schema, value);
|
|
1360
|
+
if (result.success) {
|
|
1361
|
+
return result.data;
|
|
1362
|
+
}
|
|
1363
|
+
throw createIntegrationConfigValidationError(integration, result.error);
|
|
1364
|
+
}
|
|
1365
|
+
if (schema["~standard"]?.validate) {
|
|
1366
|
+
const result = await schema["~standard"].validate(value);
|
|
1367
|
+
if ("value" in result) {
|
|
1368
|
+
return result.value;
|
|
1369
|
+
}
|
|
1370
|
+
throw createIntegrationConfigValidationError(integration, {
|
|
1371
|
+
issues: result.issues
|
|
1372
|
+
});
|
|
1373
|
+
}
|
|
1374
|
+
if (schema.parse) {
|
|
1375
|
+
try {
|
|
1376
|
+
return await schema.parse(value);
|
|
1377
|
+
} catch (error) {
|
|
1378
|
+
throw createIntegrationConfigValidationError(
|
|
1379
|
+
integration,
|
|
1380
|
+
normalizeIntegrationValidationError(error)
|
|
1381
|
+
);
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
throw new Error(
|
|
1385
|
+
`Integration "${integration.type}" config schema must expose safeParse, safeParseAsync, parse, or ~standard.validate.`
|
|
1386
|
+
);
|
|
1387
|
+
}
|
|
1388
|
+
__name(parseIntegrationConfigSchema, "parseIntegrationConfigSchema");
|
|
1389
|
+
function createIntegrationConfigValidationError(integration, error) {
|
|
1390
|
+
const issues = Array.isArray(error.issues) && error.issues.length > 0 ? error.issues.map((issue) => {
|
|
1391
|
+
const normalizedPath = normalizeIntegrationValidationPath(issue.path);
|
|
1392
|
+
const path = normalizedPath.length ? `${normalizedPath.join(".")}: ` : "";
|
|
1393
|
+
return `${path}${issue.message || "Invalid config"}`;
|
|
1394
|
+
}).join("; ") : error.message || "Invalid config";
|
|
1395
|
+
return new Error(`Integration "${integration.type}" config validation failed: ${issues}`);
|
|
1396
|
+
}
|
|
1397
|
+
__name(createIntegrationConfigValidationError, "createIntegrationConfigValidationError");
|
|
1398
|
+
async function resolveIntegrationConfig(integration, context) {
|
|
1399
|
+
const config = integration.config;
|
|
1400
|
+
if (!config) {
|
|
1401
|
+
return void 0;
|
|
1402
|
+
}
|
|
1403
|
+
if (!isIntegrationConfigDefinition(config)) {
|
|
1404
|
+
return parseIntegrationConfigSchema(integration, config, {});
|
|
1405
|
+
}
|
|
1406
|
+
let value = {};
|
|
1407
|
+
value = mergeIntegrationConfigValue(
|
|
1408
|
+
value,
|
|
1409
|
+
await resolveIntegrationConfigPart(config.defaults, context)
|
|
1410
|
+
);
|
|
1411
|
+
value = mergeIntegrationConfigValue(value, resolveIntegrationEnvConfig(config.env));
|
|
1412
|
+
value = mergeIntegrationConfigValue(
|
|
1413
|
+
value,
|
|
1414
|
+
await resolveIntegrationConfigPart(config.input, context)
|
|
1415
|
+
);
|
|
1416
|
+
value = mergeIntegrationConfigValue(value, await config.resolve?.(context));
|
|
1417
|
+
return config.schema ? parseIntegrationConfigSchema(integration, config.schema, value) : value;
|
|
1418
|
+
}
|
|
1419
|
+
__name(resolveIntegrationConfig, "resolveIntegrationConfig");
|
|
1420
|
+
function createIntegrationLifecycleLogger(integration, phase) {
|
|
1421
|
+
const write = /* @__PURE__ */ __name((level, message, meta) => {
|
|
1422
|
+
if (!integration.log) {
|
|
1423
|
+
return;
|
|
1424
|
+
}
|
|
1425
|
+
void Promise.resolve(
|
|
1426
|
+
integration.log({
|
|
1427
|
+
category: integration.category,
|
|
1428
|
+
slot: integration.category,
|
|
1429
|
+
type: integration.type,
|
|
1430
|
+
phase,
|
|
1431
|
+
level,
|
|
1432
|
+
message,
|
|
1433
|
+
meta,
|
|
1434
|
+
context: /* @__PURE__ */ new Map()
|
|
1435
|
+
})
|
|
1436
|
+
).catch(() => {
|
|
1437
|
+
});
|
|
1438
|
+
}, "write");
|
|
1439
|
+
return {
|
|
1440
|
+
info(message, meta) {
|
|
1441
|
+
write("info", message, meta);
|
|
1442
|
+
},
|
|
1443
|
+
warn(message, meta) {
|
|
1444
|
+
write("warn", message, meta);
|
|
1445
|
+
},
|
|
1446
|
+
error(message, meta) {
|
|
1447
|
+
write("error", message, meta);
|
|
1448
|
+
}
|
|
1449
|
+
};
|
|
1450
|
+
}
|
|
1451
|
+
__name(createIntegrationLifecycleLogger, "createIntegrationLifecycleLogger");
|
|
1452
|
+
var INTEGRATION_DATA_HEADER = "x-farm-integration-data";
|
|
1453
|
+
var INTEGRATION_DATA_HEADER_MAX_LENGTH = 16 * 1024;
|
|
1454
|
+
var BLOCKED_INTEGRATION_DATA_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
1455
|
+
function isFarmIntegrationData(value) {
|
|
1456
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
1457
|
+
}
|
|
1458
|
+
__name(isFarmIntegrationData, "isFarmIntegrationData");
|
|
1459
|
+
function isPlainIntegrationDataObject(value) {
|
|
1460
|
+
if (!isFarmIntegrationData(value)) {
|
|
1461
|
+
return false;
|
|
1462
|
+
}
|
|
1463
|
+
const prototype = Object.getPrototypeOf(value);
|
|
1464
|
+
return prototype === Object.prototype || prototype === null;
|
|
1465
|
+
}
|
|
1466
|
+
__name(isPlainIntegrationDataObject, "isPlainIntegrationDataObject");
|
|
1467
|
+
function sanitizeIntegrationDataValue(value) {
|
|
1468
|
+
if (Array.isArray(value)) {
|
|
1469
|
+
return value.map((item) => sanitizeIntegrationDataValue(item));
|
|
1470
|
+
}
|
|
1471
|
+
if (!isPlainIntegrationDataObject(value)) {
|
|
1472
|
+
return value;
|
|
1473
|
+
}
|
|
1474
|
+
const sanitized = {};
|
|
1475
|
+
for (const [key, item] of Object.entries(value)) {
|
|
1476
|
+
if (BLOCKED_INTEGRATION_DATA_KEYS.has(key)) {
|
|
1477
|
+
continue;
|
|
1478
|
+
}
|
|
1479
|
+
sanitized[key] = sanitizeIntegrationDataValue(item);
|
|
1480
|
+
}
|
|
1481
|
+
return sanitized;
|
|
1482
|
+
}
|
|
1483
|
+
__name(sanitizeIntegrationDataValue, "sanitizeIntegrationDataValue");
|
|
1484
|
+
function normalizeIntegrationData(value) {
|
|
1485
|
+
if (!isFarmIntegrationData(value)) {
|
|
1486
|
+
return {};
|
|
1487
|
+
}
|
|
1488
|
+
const sanitized = sanitizeIntegrationDataValue(value);
|
|
1489
|
+
return isFarmIntegrationData(sanitized) ? sanitized : {};
|
|
1490
|
+
}
|
|
1491
|
+
__name(normalizeIntegrationData, "normalizeIntegrationData");
|
|
1492
|
+
function getIntegrationDataHeaderByteLength(value) {
|
|
1493
|
+
return new TextEncoder().encode(value).byteLength;
|
|
1494
|
+
}
|
|
1495
|
+
__name(getIntegrationDataHeaderByteLength, "getIntegrationDataHeaderByteLength");
|
|
1496
|
+
function parseIntegrationDataHeader(request) {
|
|
1497
|
+
const raw = request.headers.get(INTEGRATION_DATA_HEADER);
|
|
1498
|
+
if (!raw) {
|
|
1499
|
+
return {};
|
|
1500
|
+
}
|
|
1501
|
+
if (getIntegrationDataHeaderByteLength(raw) > INTEGRATION_DATA_HEADER_MAX_LENGTH) {
|
|
1502
|
+
return {};
|
|
1503
|
+
}
|
|
1504
|
+
try {
|
|
1505
|
+
const value = JSON.parse(raw);
|
|
1506
|
+
return normalizeIntegrationData(value);
|
|
1507
|
+
} catch {
|
|
1508
|
+
return {};
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
__name(parseIntegrationDataHeader, "parseIntegrationDataHeader");
|
|
1512
|
+
function resolveIntegrationData(request, data) {
|
|
1513
|
+
return {
|
|
1514
|
+
...parseIntegrationDataHeader(request),
|
|
1515
|
+
...normalizeIntegrationData(data)
|
|
1516
|
+
};
|
|
1517
|
+
}
|
|
1518
|
+
__name(resolveIntegrationData, "resolveIntegrationData");
|
|
1519
|
+
function createIntegrationPlugin(integrationKey, integration) {
|
|
1520
|
+
const routes = normalizeIntegrationRoutes(integration.routes || []);
|
|
1521
|
+
const middleware = [...integration.middleware || []];
|
|
1522
|
+
const cleanupCallbacks = [];
|
|
1523
|
+
let integrationConfigPromise;
|
|
1524
|
+
const runCleanup = /* @__PURE__ */ __name(async () => {
|
|
1525
|
+
const callbacks = cleanupCallbacks.splice(0).reverse();
|
|
1526
|
+
for (const callback of callbacks) {
|
|
1527
|
+
await callback();
|
|
1528
|
+
}
|
|
1529
|
+
}, "runCleanup");
|
|
1530
|
+
const createLifecycleContext = /* @__PURE__ */ __name(async (context, phase, options = {}) => {
|
|
1531
|
+
const args = createIntegrationRouteArgs({
|
|
1532
|
+
integration,
|
|
1533
|
+
config: context.config
|
|
1534
|
+
});
|
|
1535
|
+
const configContext = {
|
|
1536
|
+
key: integrationKey,
|
|
1537
|
+
integration,
|
|
1538
|
+
appConfig: context.config,
|
|
1539
|
+
config: context.config,
|
|
1540
|
+
args,
|
|
1541
|
+
env: getIntegrationRuntimeEnv(),
|
|
1542
|
+
isDev: context.isDev,
|
|
1543
|
+
isProd: context.isProd
|
|
1544
|
+
};
|
|
1545
|
+
integrationConfigPromise ?? (integrationConfigPromise = resolveIntegrationConfig(integration, configContext));
|
|
1546
|
+
return {
|
|
1547
|
+
...configContext,
|
|
1548
|
+
integrationConfig: await integrationConfigPromise,
|
|
1549
|
+
log: createIntegrationLifecycleLogger(integration, phase),
|
|
1550
|
+
reason: options.reason,
|
|
1551
|
+
async cleanup(callback) {
|
|
1552
|
+
if (callback) {
|
|
1553
|
+
cleanupCallbacks.push(callback);
|
|
1554
|
+
return;
|
|
1555
|
+
}
|
|
1556
|
+
await runCleanup();
|
|
1557
|
+
}
|
|
1558
|
+
};
|
|
1559
|
+
}, "createLifecycleContext");
|
|
1560
|
+
const plugin = {
|
|
1561
|
+
name: `farm:integration:${integration.category}:${integration.type}`,
|
|
1562
|
+
enforce: "pre",
|
|
1563
|
+
async init(context) {
|
|
1564
|
+
getIntegrationRuntimeRegistry().set(integrationKey, {
|
|
1565
|
+
integration,
|
|
1566
|
+
config: context.config,
|
|
1567
|
+
isDev: context.isDev,
|
|
1568
|
+
isProd: context.isProd
|
|
1569
|
+
});
|
|
1570
|
+
await createLifecycleContext(context, "validate");
|
|
1571
|
+
if (integration.validate) {
|
|
1572
|
+
await integration.validate(await createLifecycleContext(context, "validate"));
|
|
1573
|
+
}
|
|
1574
|
+
if (integration.setup) {
|
|
1575
|
+
await integration.setup(await createLifecycleContext(context, "setup"));
|
|
1576
|
+
}
|
|
1577
|
+
if (!integration.log) {
|
|
1578
|
+
return;
|
|
1579
|
+
}
|
|
1580
|
+
for (const route2 of routes) {
|
|
1581
|
+
await integration.log({
|
|
1582
|
+
category: integration.category,
|
|
1583
|
+
slot: integration.category,
|
|
1584
|
+
type: integration.type,
|
|
1585
|
+
phase: "registered",
|
|
1586
|
+
route: {
|
|
1587
|
+
kind: "route",
|
|
1588
|
+
path: route2.path,
|
|
1589
|
+
methods: route2.methods
|
|
1590
|
+
},
|
|
1591
|
+
context: /* @__PURE__ */ new Map()
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
for (const entry of middleware) {
|
|
1595
|
+
await integration.log({
|
|
1596
|
+
category: integration.category,
|
|
1597
|
+
slot: integration.category,
|
|
1598
|
+
type: integration.type,
|
|
1599
|
+
phase: "registered",
|
|
1600
|
+
route: {
|
|
1601
|
+
kind: "middleware",
|
|
1602
|
+
path: normalizeMatcher(entry.matcher),
|
|
1603
|
+
methods: ["ALL"]
|
|
1604
|
+
},
|
|
1605
|
+
context: /* @__PURE__ */ new Map()
|
|
1606
|
+
});
|
|
1607
|
+
}
|
|
1608
|
+
},
|
|
1609
|
+
async ready(context) {
|
|
1610
|
+
if (integration.ready) {
|
|
1611
|
+
await integration.ready(await createLifecycleContext(context, "ready"));
|
|
1612
|
+
}
|
|
1613
|
+
},
|
|
1614
|
+
async shutdown(payload, context) {
|
|
1615
|
+
try {
|
|
1616
|
+
if (integration.dispose) {
|
|
1617
|
+
await integration.dispose(
|
|
1618
|
+
await createLifecycleContext(context, "dispose", {
|
|
1619
|
+
reason: payload.reason
|
|
1620
|
+
})
|
|
1621
|
+
);
|
|
1622
|
+
}
|
|
1623
|
+
} finally {
|
|
1624
|
+
await runCleanup();
|
|
1625
|
+
}
|
|
1626
|
+
},
|
|
1627
|
+
async beforeRequest(req, res, context) {
|
|
1628
|
+
const fullUrl = `http://${req.headers.host || "localhost"}${req.url || "/"}`;
|
|
1629
|
+
const url = new URL(fullUrl);
|
|
1630
|
+
const pathname = url.pathname;
|
|
1631
|
+
const requestId = getRequestId(req);
|
|
1632
|
+
let bodyLoaded = false;
|
|
1633
|
+
let requestBody;
|
|
1634
|
+
const getRequestBody = /* @__PURE__ */ __name(async () => {
|
|
1635
|
+
if (!bodyLoaded) {
|
|
1636
|
+
bodyLoaded = true;
|
|
1637
|
+
if (req.method && req.method !== "GET" && req.method !== "HEAD") {
|
|
1638
|
+
requestBody = await readRequestBody(req);
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
return requestBody;
|
|
1642
|
+
}, "getRequestBody");
|
|
1643
|
+
const createHandlerRequest = /* @__PURE__ */ __name(async () => {
|
|
1644
|
+
return createWebRequest(req, fullUrl, await getRequestBody());
|
|
1645
|
+
}, "createHandlerRequest");
|
|
1646
|
+
for (const entry of middleware) {
|
|
1647
|
+
const params = resolveMatcherParams(entry.matcher, pathname);
|
|
1648
|
+
if (!params) {
|
|
1649
|
+
continue;
|
|
1650
|
+
}
|
|
1651
|
+
const request = await createHandlerRequest();
|
|
1652
|
+
const handlerContext = createIntegrationHandlerContext({
|
|
1653
|
+
integration,
|
|
1654
|
+
route: {
|
|
1655
|
+
kind: "middleware",
|
|
1656
|
+
path: normalizeMatcher(entry.matcher),
|
|
1657
|
+
methods: ["ALL"]
|
|
1658
|
+
},
|
|
1659
|
+
request,
|
|
1660
|
+
rawRequest: req,
|
|
1661
|
+
params,
|
|
1662
|
+
pathname,
|
|
1663
|
+
requestId,
|
|
1664
|
+
pluginContext: context
|
|
1665
|
+
});
|
|
1666
|
+
const startedAt = Date.now();
|
|
1667
|
+
await integration.log?.({
|
|
1668
|
+
category: integration.category,
|
|
1669
|
+
slot: integration.category,
|
|
1670
|
+
type: integration.type,
|
|
1671
|
+
phase: "request:start",
|
|
1672
|
+
route: {
|
|
1673
|
+
kind: "middleware",
|
|
1674
|
+
path: normalizeMatcher(entry.matcher),
|
|
1675
|
+
methods: ["ALL"]
|
|
1676
|
+
},
|
|
1677
|
+
request,
|
|
1678
|
+
requestId,
|
|
1679
|
+
context: handlerContext.req.snapshot()
|
|
1680
|
+
});
|
|
1681
|
+
try {
|
|
1682
|
+
const response = await entry.handler(request, handlerContext);
|
|
1683
|
+
if (response) {
|
|
1684
|
+
await sendWebResponse(res, response);
|
|
1685
|
+
await integration.log?.({
|
|
1686
|
+
category: integration.category,
|
|
1687
|
+
slot: integration.category,
|
|
1688
|
+
type: integration.type,
|
|
1689
|
+
phase: "request:end",
|
|
1690
|
+
route: {
|
|
1691
|
+
kind: "middleware",
|
|
1692
|
+
path: normalizeMatcher(entry.matcher),
|
|
1693
|
+
methods: ["ALL"]
|
|
1694
|
+
},
|
|
1695
|
+
request,
|
|
1696
|
+
response,
|
|
1697
|
+
requestId,
|
|
1698
|
+
durationMs: Date.now() - startedAt,
|
|
1699
|
+
context: handlerContext.req.snapshot()
|
|
1700
|
+
});
|
|
1701
|
+
return;
|
|
1702
|
+
}
|
|
1703
|
+
await integration.log?.({
|
|
1704
|
+
category: integration.category,
|
|
1705
|
+
slot: integration.category,
|
|
1706
|
+
type: integration.type,
|
|
1707
|
+
phase: "request:end",
|
|
1708
|
+
route: {
|
|
1709
|
+
kind: "middleware",
|
|
1710
|
+
path: normalizeMatcher(entry.matcher),
|
|
1711
|
+
methods: ["ALL"]
|
|
1712
|
+
},
|
|
1713
|
+
request,
|
|
1714
|
+
requestId,
|
|
1715
|
+
durationMs: Date.now() - startedAt,
|
|
1716
|
+
context: handlerContext.req.snapshot()
|
|
1717
|
+
});
|
|
1718
|
+
} catch (error) {
|
|
1719
|
+
await integration.log?.({
|
|
1720
|
+
category: integration.category,
|
|
1721
|
+
slot: integration.category,
|
|
1722
|
+
type: integration.type,
|
|
1723
|
+
phase: "request:error",
|
|
1724
|
+
route: {
|
|
1725
|
+
kind: "middleware",
|
|
1726
|
+
path: normalizeMatcher(entry.matcher),
|
|
1727
|
+
methods: ["ALL"]
|
|
1728
|
+
},
|
|
1729
|
+
request,
|
|
1730
|
+
requestId,
|
|
1731
|
+
durationMs: Date.now() - startedAt,
|
|
1732
|
+
error,
|
|
1733
|
+
context: handlerContext.req.snapshot()
|
|
1734
|
+
});
|
|
1735
|
+
throw error;
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
for (const route2 of routes) {
|
|
1739
|
+
const params = matchesMethod(route2.methods, req.method) ? extractPathParams(route2.path, pathname) : null;
|
|
1740
|
+
if (!params) {
|
|
1741
|
+
continue;
|
|
1742
|
+
}
|
|
1743
|
+
const request = await createHandlerRequest();
|
|
1744
|
+
const handlerContext = createIntegrationHandlerContext({
|
|
1745
|
+
integration,
|
|
1746
|
+
route: {
|
|
1747
|
+
kind: "route",
|
|
1748
|
+
path: route2.path,
|
|
1749
|
+
methods: route2.methods
|
|
1750
|
+
},
|
|
1751
|
+
request,
|
|
1752
|
+
rawRequest: req,
|
|
1753
|
+
params,
|
|
1754
|
+
pathname,
|
|
1755
|
+
requestId,
|
|
1756
|
+
pluginContext: context
|
|
1757
|
+
});
|
|
1758
|
+
const startedAt = Date.now();
|
|
1759
|
+
await integration.log?.({
|
|
1760
|
+
category: integration.category,
|
|
1761
|
+
slot: integration.category,
|
|
1762
|
+
type: integration.type,
|
|
1763
|
+
phase: "request:start",
|
|
1764
|
+
route: {
|
|
1765
|
+
kind: "route",
|
|
1766
|
+
path: route2.path,
|
|
1767
|
+
methods: route2.methods
|
|
1768
|
+
},
|
|
1769
|
+
request,
|
|
1770
|
+
requestId,
|
|
1771
|
+
context: handlerContext.req.snapshot()
|
|
1772
|
+
});
|
|
1773
|
+
try {
|
|
1774
|
+
const validation = await validateIntegrationRouteInput(route2, request, url);
|
|
1775
|
+
if (!validation.success) {
|
|
1776
|
+
await sendWebResponse(res, validation.response);
|
|
1777
|
+
await integration.log?.({
|
|
1778
|
+
category: integration.category,
|
|
1779
|
+
slot: integration.category,
|
|
1780
|
+
type: integration.type,
|
|
1781
|
+
phase: "request:end",
|
|
1782
|
+
route: {
|
|
1783
|
+
kind: "route",
|
|
1784
|
+
path: route2.path,
|
|
1785
|
+
methods: route2.methods
|
|
1786
|
+
},
|
|
1787
|
+
request,
|
|
1788
|
+
response: validation.response,
|
|
1789
|
+
requestId,
|
|
1790
|
+
durationMs: Date.now() - startedAt,
|
|
1791
|
+
context: handlerContext.req.snapshot()
|
|
1792
|
+
});
|
|
1793
|
+
return;
|
|
1794
|
+
}
|
|
1795
|
+
handlerContext.input = validation.input;
|
|
1796
|
+
for (const middlewareEntry of route2.middleware || []) {
|
|
1797
|
+
const middlewareResponse = await middlewareEntry.handler(request, handlerContext);
|
|
1798
|
+
if (middlewareResponse) {
|
|
1799
|
+
await sendWebResponse(res, middlewareResponse);
|
|
1800
|
+
await integration.log?.({
|
|
1801
|
+
category: integration.category,
|
|
1802
|
+
slot: integration.category,
|
|
1803
|
+
type: integration.type,
|
|
1804
|
+
phase: "request:end",
|
|
1805
|
+
route: {
|
|
1806
|
+
kind: "route",
|
|
1807
|
+
path: route2.path,
|
|
1808
|
+
methods: route2.methods
|
|
1809
|
+
},
|
|
1810
|
+
request,
|
|
1811
|
+
response: middlewareResponse,
|
|
1812
|
+
requestId,
|
|
1813
|
+
durationMs: Date.now() - startedAt,
|
|
1814
|
+
context: handlerContext.req.snapshot()
|
|
1815
|
+
});
|
|
1816
|
+
return;
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
const beforeResponse = await runIntegrationRouteBeforeHooks(
|
|
1820
|
+
route2,
|
|
1821
|
+
request,
|
|
1822
|
+
handlerContext
|
|
1823
|
+
);
|
|
1824
|
+
if (beforeResponse) {
|
|
1825
|
+
const response2 = await runIntegrationRouteAfterHooks(
|
|
1826
|
+
route2,
|
|
1827
|
+
request,
|
|
1828
|
+
handlerContext,
|
|
1829
|
+
beforeResponse
|
|
1830
|
+
);
|
|
1831
|
+
await sendWebResponse(res, response2);
|
|
1832
|
+
await integration.log?.({
|
|
1833
|
+
category: integration.category,
|
|
1834
|
+
slot: integration.category,
|
|
1835
|
+
type: integration.type,
|
|
1836
|
+
phase: "request:end",
|
|
1837
|
+
route: {
|
|
1838
|
+
kind: "route",
|
|
1839
|
+
path: route2.path,
|
|
1840
|
+
methods: route2.methods
|
|
1841
|
+
},
|
|
1842
|
+
request,
|
|
1843
|
+
response: response2,
|
|
1844
|
+
requestId,
|
|
1845
|
+
durationMs: Date.now() - startedAt,
|
|
1846
|
+
context: handlerContext.req.snapshot()
|
|
1847
|
+
});
|
|
1848
|
+
return;
|
|
1849
|
+
}
|
|
1850
|
+
const handlerResponse = await route2.handler(request, handlerContext);
|
|
1851
|
+
const response = await runIntegrationRouteAfterHooks(
|
|
1852
|
+
route2,
|
|
1853
|
+
request,
|
|
1854
|
+
handlerContext,
|
|
1855
|
+
handlerResponse
|
|
1856
|
+
);
|
|
1857
|
+
await sendWebResponse(res, response);
|
|
1858
|
+
await integration.log?.({
|
|
1859
|
+
category: integration.category,
|
|
1860
|
+
slot: integration.category,
|
|
1861
|
+
type: integration.type,
|
|
1862
|
+
phase: "request:end",
|
|
1863
|
+
route: {
|
|
1864
|
+
kind: "route",
|
|
1865
|
+
path: route2.path,
|
|
1866
|
+
methods: route2.methods
|
|
1867
|
+
},
|
|
1868
|
+
request,
|
|
1869
|
+
response,
|
|
1870
|
+
requestId,
|
|
1871
|
+
durationMs: Date.now() - startedAt,
|
|
1872
|
+
context: handlerContext.req.snapshot()
|
|
1873
|
+
});
|
|
1874
|
+
return;
|
|
1875
|
+
} catch (error) {
|
|
1876
|
+
await integration.log?.({
|
|
1877
|
+
category: integration.category,
|
|
1878
|
+
slot: integration.category,
|
|
1879
|
+
type: integration.type,
|
|
1880
|
+
phase: "request:error",
|
|
1881
|
+
route: {
|
|
1882
|
+
kind: "route",
|
|
1883
|
+
path: route2.path,
|
|
1884
|
+
methods: route2.methods
|
|
1885
|
+
},
|
|
1886
|
+
request,
|
|
1887
|
+
requestId,
|
|
1888
|
+
durationMs: Date.now() - startedAt,
|
|
1889
|
+
error,
|
|
1890
|
+
context: handlerContext.req.snapshot()
|
|
1891
|
+
});
|
|
1892
|
+
throw error;
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
};
|
|
1897
|
+
Object.defineProperty(plugin, FARM_INTEGRATION_PLUGIN_SERVER_RUNTIME, {
|
|
1898
|
+
value: integration.serverRuntime !== false
|
|
1899
|
+
});
|
|
1900
|
+
return plugin;
|
|
1901
|
+
}
|
|
1902
|
+
__name(createIntegrationPlugin, "createIntegrationPlugin");
|
|
1903
|
+
function createIntegrationHandlerContext(input) {
|
|
1904
|
+
const req = createIntegrationRequestContextStore(
|
|
1905
|
+
input.rawRequest,
|
|
1906
|
+
input.request,
|
|
1907
|
+
input.pluginContext
|
|
1908
|
+
);
|
|
1909
|
+
return {
|
|
1910
|
+
request: input.request,
|
|
1911
|
+
requestId: input.requestId,
|
|
1912
|
+
url: new URL(input.request.url),
|
|
1913
|
+
pathname: input.pathname,
|
|
1914
|
+
method: input.request.method,
|
|
1915
|
+
params: input.params,
|
|
1916
|
+
input: {},
|
|
1917
|
+
args: createIntegrationRouteArgs({
|
|
1918
|
+
integration: input.integration,
|
|
1919
|
+
config: input.pluginContext.config
|
|
1920
|
+
}),
|
|
1921
|
+
data: resolveIntegrationData(input.request),
|
|
1922
|
+
integration: {
|
|
1923
|
+
category: input.integration.category,
|
|
1924
|
+
slot: input.integration.category,
|
|
1925
|
+
type: input.integration.type,
|
|
1926
|
+
instance: input.integration.instance
|
|
1927
|
+
},
|
|
1928
|
+
route: input.route,
|
|
1929
|
+
req,
|
|
1930
|
+
requestContext: req,
|
|
1931
|
+
config: input.pluginContext.config,
|
|
1932
|
+
isDev: input.pluginContext.isDev,
|
|
1933
|
+
isProd: input.pluginContext.isProd
|
|
1934
|
+
};
|
|
1935
|
+
}
|
|
1936
|
+
__name(createIntegrationHandlerContext, "createIntegrationHandlerContext");
|
|
1937
|
+
function normalizeIntegrationRoutes(routes) {
|
|
1938
|
+
return routes.map((route2) => ({
|
|
1939
|
+
...route2,
|
|
1940
|
+
methods: normalizeIntegrationRouteMethods(route2),
|
|
1941
|
+
input: normalizeIntegrationRouteInputSchemas(route2)
|
|
1942
|
+
}));
|
|
1943
|
+
}
|
|
1944
|
+
__name(normalizeIntegrationRoutes, "normalizeIntegrationRoutes");
|
|
1945
|
+
function normalizeIntegrationRouteMethods(route2) {
|
|
1946
|
+
const input = route2.methods && route2.methods.length > 0 ? [...route2.methods] : route2.method ? [route2.method] : ["ALL"];
|
|
1947
|
+
return input.map((method) => String(method).toUpperCase());
|
|
1948
|
+
}
|
|
1949
|
+
__name(normalizeIntegrationRouteMethods, "normalizeIntegrationRouteMethods");
|
|
1950
|
+
function normalizeIntegrationRouteInputSchemas(route2) {
|
|
1951
|
+
const input = {
|
|
1952
|
+
...route2.input
|
|
1953
|
+
};
|
|
1954
|
+
if (route2.body) {
|
|
1955
|
+
input.body = route2.body;
|
|
1956
|
+
}
|
|
1957
|
+
if (route2.query) {
|
|
1958
|
+
input.query = route2.query;
|
|
1959
|
+
}
|
|
1960
|
+
return input.body || input.query ? input : void 0;
|
|
1961
|
+
}
|
|
1962
|
+
__name(normalizeIntegrationRouteInputSchemas, "normalizeIntegrationRouteInputSchemas");
|
|
1963
|
+
async function validateIntegrationRouteInput(route2, request, url) {
|
|
1964
|
+
const schemas = route2.input;
|
|
1965
|
+
if (!schemas?.body && !schemas?.query) {
|
|
1966
|
+
return {
|
|
1967
|
+
success: true,
|
|
1968
|
+
input: {}
|
|
1969
|
+
};
|
|
1970
|
+
}
|
|
1971
|
+
const input = {};
|
|
1972
|
+
const issues = [];
|
|
1973
|
+
if (schemas.query) {
|
|
1974
|
+
const queryResult = await parseIntegrationInputSchema(
|
|
1975
|
+
"query",
|
|
1976
|
+
schemas.query,
|
|
1977
|
+
createQueryInput(url.searchParams)
|
|
1978
|
+
);
|
|
1979
|
+
if (queryResult.success) {
|
|
1980
|
+
input.query = queryResult.data;
|
|
1981
|
+
} else {
|
|
1982
|
+
issues.push(...queryResult.issues);
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
if (schemas.body) {
|
|
1986
|
+
const bodyInput = await readIntegrationValidationBody(
|
|
1987
|
+
request,
|
|
1988
|
+
getIntegrationRouteBodyFormat(route2)
|
|
1989
|
+
);
|
|
1990
|
+
if (bodyInput.success) {
|
|
1991
|
+
const bodyResult = await parseIntegrationInputSchema("body", schemas.body, bodyInput.data);
|
|
1992
|
+
if (bodyResult.success) {
|
|
1993
|
+
input.body = bodyResult.data;
|
|
1994
|
+
} else {
|
|
1995
|
+
issues.push(...bodyResult.issues);
|
|
1996
|
+
}
|
|
1997
|
+
} else {
|
|
1998
|
+
issues.push(bodyInput.issue);
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
if (issues.length > 0) {
|
|
2002
|
+
return {
|
|
2003
|
+
success: false,
|
|
2004
|
+
response: createIntegrationValidationResponse(issues)
|
|
2005
|
+
};
|
|
2006
|
+
}
|
|
2007
|
+
return {
|
|
2008
|
+
success: true,
|
|
2009
|
+
input
|
|
2010
|
+
};
|
|
2011
|
+
}
|
|
2012
|
+
__name(validateIntegrationRouteInput, "validateIntegrationRouteInput");
|
|
2013
|
+
async function parseIntegrationInputSchema(source, schema, value) {
|
|
2014
|
+
const parser = schema.safeParseAsync || schema.safeParse;
|
|
2015
|
+
if (parser) {
|
|
2016
|
+
const result = await parser.call(schema, value);
|
|
2017
|
+
if (result.success) {
|
|
2018
|
+
return {
|
|
2019
|
+
success: true,
|
|
2020
|
+
data: result.data
|
|
2021
|
+
};
|
|
2022
|
+
}
|
|
2023
|
+
return {
|
|
2024
|
+
success: false,
|
|
2025
|
+
issues: normalizeIntegrationValidationIssues(source, result.error)
|
|
2026
|
+
};
|
|
2027
|
+
}
|
|
2028
|
+
if (schema["~standard"]?.validate) {
|
|
2029
|
+
const result = await schema["~standard"].validate(value);
|
|
2030
|
+
if ("value" in result) {
|
|
2031
|
+
return {
|
|
2032
|
+
success: true,
|
|
2033
|
+
data: result.value
|
|
2034
|
+
};
|
|
2035
|
+
}
|
|
2036
|
+
return {
|
|
2037
|
+
success: false,
|
|
2038
|
+
issues: normalizeIntegrationValidationIssues(source, {
|
|
2039
|
+
issues: result.issues
|
|
2040
|
+
})
|
|
2041
|
+
};
|
|
2042
|
+
}
|
|
2043
|
+
if (schema.parse) {
|
|
2044
|
+
try {
|
|
2045
|
+
return {
|
|
2046
|
+
success: true,
|
|
2047
|
+
data: await schema.parse(value)
|
|
2048
|
+
};
|
|
2049
|
+
} catch (error) {
|
|
2050
|
+
return {
|
|
2051
|
+
success: false,
|
|
2052
|
+
issues: normalizeIntegrationValidationIssues(
|
|
2053
|
+
source,
|
|
2054
|
+
normalizeIntegrationValidationError(error)
|
|
2055
|
+
)
|
|
2056
|
+
};
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
return {
|
|
2060
|
+
success: false,
|
|
2061
|
+
issues: [
|
|
2062
|
+
{
|
|
2063
|
+
source,
|
|
2064
|
+
message: "Input schema must expose safeParse, safeParseAsync, parse, or ~standard.validate."
|
|
2065
|
+
}
|
|
2066
|
+
]
|
|
2067
|
+
};
|
|
2068
|
+
}
|
|
2069
|
+
__name(parseIntegrationInputSchema, "parseIntegrationInputSchema");
|
|
2070
|
+
function createIntegrationValidationResponse(issues) {
|
|
2071
|
+
return Response.json(
|
|
2072
|
+
{
|
|
2073
|
+
error: "Integration route input validation failed",
|
|
2074
|
+
issues
|
|
2075
|
+
},
|
|
2076
|
+
{
|
|
2077
|
+
status: 400
|
|
2078
|
+
}
|
|
2079
|
+
);
|
|
2080
|
+
}
|
|
2081
|
+
__name(createIntegrationValidationResponse, "createIntegrationValidationResponse");
|
|
2082
|
+
function normalizeIntegrationValidationIssues(source, error) {
|
|
2083
|
+
if (Array.isArray(error.issues) && error.issues.length > 0) {
|
|
2084
|
+
return error.issues.map((issue) => ({
|
|
2085
|
+
source,
|
|
2086
|
+
path: normalizeIntegrationValidationPath(issue.path),
|
|
2087
|
+
code: issue.code,
|
|
2088
|
+
message: issue.message || "Invalid input"
|
|
2089
|
+
}));
|
|
2090
|
+
}
|
|
2091
|
+
return [
|
|
2092
|
+
{
|
|
2093
|
+
source,
|
|
2094
|
+
path: [],
|
|
2095
|
+
message: error.message || "Invalid input"
|
|
2096
|
+
}
|
|
2097
|
+
];
|
|
2098
|
+
}
|
|
2099
|
+
__name(normalizeIntegrationValidationIssues, "normalizeIntegrationValidationIssues");
|
|
2100
|
+
function normalizeIntegrationValidationPath(path) {
|
|
2101
|
+
return (path || []).map((segment) => {
|
|
2102
|
+
const key = typeof segment === "object" && segment !== null && "key" in segment ? segment.key : segment;
|
|
2103
|
+
return typeof key === "symbol" ? key.description || key.toString() : key;
|
|
2104
|
+
});
|
|
2105
|
+
}
|
|
2106
|
+
__name(normalizeIntegrationValidationPath, "normalizeIntegrationValidationPath");
|
|
2107
|
+
function normalizeIntegrationValidationError(error) {
|
|
2108
|
+
if (error && typeof error === "object") {
|
|
2109
|
+
return error;
|
|
2110
|
+
}
|
|
2111
|
+
return {
|
|
2112
|
+
message: error instanceof Error ? error.message : String(error || "Invalid input")
|
|
2113
|
+
};
|
|
2114
|
+
}
|
|
2115
|
+
__name(normalizeIntegrationValidationError, "normalizeIntegrationValidationError");
|
|
2116
|
+
async function readIntegrationValidationBody(request, format) {
|
|
2117
|
+
if (request.method === "GET" || request.method === "HEAD" || format === "none") {
|
|
2118
|
+
return {
|
|
2119
|
+
success: true,
|
|
2120
|
+
data: void 0
|
|
2121
|
+
};
|
|
2122
|
+
}
|
|
2123
|
+
try {
|
|
2124
|
+
if (format === "form") {
|
|
2125
|
+
return {
|
|
2126
|
+
success: true,
|
|
2127
|
+
data: createFormInput(await request.clone().formData())
|
|
2128
|
+
};
|
|
2129
|
+
}
|
|
2130
|
+
const text = await request.clone().text();
|
|
2131
|
+
if (text.trim().length === 0) {
|
|
2132
|
+
return {
|
|
2133
|
+
success: true,
|
|
2134
|
+
data: void 0
|
|
2135
|
+
};
|
|
2136
|
+
}
|
|
2137
|
+
return {
|
|
2138
|
+
success: true,
|
|
2139
|
+
data: JSON.parse(text)
|
|
2140
|
+
};
|
|
2141
|
+
} catch (error) {
|
|
2142
|
+
return {
|
|
2143
|
+
success: false,
|
|
2144
|
+
issue: {
|
|
2145
|
+
source: "body",
|
|
2146
|
+
path: [],
|
|
2147
|
+
message: format === "json" ? "Expected a valid JSON request body." : error instanceof Error && error.message ? error.message : "Could not parse request body."
|
|
2148
|
+
}
|
|
2149
|
+
};
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
__name(readIntegrationValidationBody, "readIntegrationValidationBody");
|
|
2153
|
+
function getIntegrationRouteBodyFormat(route2) {
|
|
2154
|
+
return route2.bodyFormat || route2.__operation?.bodyFormat || "json";
|
|
2155
|
+
}
|
|
2156
|
+
__name(getIntegrationRouteBodyFormat, "getIntegrationRouteBodyFormat");
|
|
2157
|
+
function createIntegrationRouteArgs(input) {
|
|
2158
|
+
let clientPromise;
|
|
2159
|
+
let ormPromise;
|
|
2160
|
+
const getClient = /* @__PURE__ */ __name(() => {
|
|
2161
|
+
clientPromise ?? (clientPromise = Promise.resolve().then(() => (init_storage(), storage_exports)).then(
|
|
2162
|
+
({ resolveStorageRuntimeClient: resolveStorageRuntimeClient2 }) => resolveStorageRuntimeClient2(input.config.storage)
|
|
2163
|
+
));
|
|
2164
|
+
return clientPromise;
|
|
2165
|
+
}, "getClient");
|
|
2166
|
+
const getOrm = /* @__PURE__ */ __name(() => {
|
|
2167
|
+
if (!input.integration.schema) {
|
|
2168
|
+
throw new Error(
|
|
2169
|
+
`Integration "${input.integration.type}" does not define a schema for ctx.args.db.`
|
|
2170
|
+
);
|
|
2171
|
+
}
|
|
2172
|
+
ormPromise ?? (ormPromise = Promise.resolve().then(() => (init_integration_orm(), integration_orm_exports)).then(
|
|
2173
|
+
({ createIntegrationOrm: createIntegrationOrm2 }) => createIntegrationOrm2({
|
|
2174
|
+
schema: input.integration.schema,
|
|
2175
|
+
config: input.config
|
|
2176
|
+
})
|
|
2177
|
+
));
|
|
2178
|
+
return ormPromise;
|
|
2179
|
+
}, "getOrm");
|
|
2180
|
+
return {
|
|
2181
|
+
db: createLazyIntegrationOrmClient(getOrm),
|
|
2182
|
+
getDb: getOrm,
|
|
2183
|
+
storage: {
|
|
2184
|
+
getClient,
|
|
2185
|
+
getOrm
|
|
2186
|
+
}
|
|
2187
|
+
};
|
|
2188
|
+
}
|
|
2189
|
+
__name(createIntegrationRouteArgs, "createIntegrationRouteArgs");
|
|
2190
|
+
function createLazyIntegrationOrmClient(resolveOrm) {
|
|
2191
|
+
const modelProxyCache = /* @__PURE__ */ new Map();
|
|
2192
|
+
return new Proxy(
|
|
2193
|
+
{},
|
|
2194
|
+
{
|
|
2195
|
+
get(_target, prop) {
|
|
2196
|
+
if (prop === "then") {
|
|
2197
|
+
return void 0;
|
|
2198
|
+
}
|
|
2199
|
+
if (prop === "transaction" || prop === "batch") {
|
|
2200
|
+
return async (...args) => {
|
|
2201
|
+
const orm = await resolveOrm();
|
|
2202
|
+
const member = orm[prop];
|
|
2203
|
+
if (typeof member !== "function") {
|
|
2204
|
+
throw new Error(`Integration ORM does not expose "${String(prop)}".`);
|
|
2205
|
+
}
|
|
2206
|
+
return member.apply(orm, args);
|
|
2207
|
+
};
|
|
2208
|
+
}
|
|
2209
|
+
if (prop === "$driver") {
|
|
2210
|
+
return void 0;
|
|
2211
|
+
}
|
|
2212
|
+
if (!modelProxyCache.has(prop)) {
|
|
2213
|
+
modelProxyCache.set(prop, createLazyIntegrationOrmModel(resolveOrm, prop));
|
|
2214
|
+
}
|
|
2215
|
+
return modelProxyCache.get(prop);
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
);
|
|
2219
|
+
}
|
|
2220
|
+
__name(createLazyIntegrationOrmClient, "createLazyIntegrationOrmClient");
|
|
2221
|
+
function createLazyIntegrationOrmModel(resolveOrm, modelName) {
|
|
2222
|
+
return new Proxy(
|
|
2223
|
+
{},
|
|
2224
|
+
{
|
|
2225
|
+
get(_target, prop) {
|
|
2226
|
+
if (prop === "then") {
|
|
2227
|
+
return void 0;
|
|
2228
|
+
}
|
|
2229
|
+
return async (...args) => {
|
|
2230
|
+
const orm = await resolveOrm();
|
|
2231
|
+
const model = orm[modelName];
|
|
2232
|
+
const member = model?.[prop];
|
|
2233
|
+
if (typeof member !== "function") {
|
|
2234
|
+
throw new Error(
|
|
2235
|
+
`Integration ORM model "${String(modelName)}" does not expose "${String(prop)}".`
|
|
2236
|
+
);
|
|
2237
|
+
}
|
|
2238
|
+
return member.apply(model, args);
|
|
2239
|
+
};
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
);
|
|
2243
|
+
}
|
|
2244
|
+
__name(createLazyIntegrationOrmModel, "createLazyIntegrationOrmModel");
|
|
2245
|
+
async function runIntegrationRouteBeforeHooks(route2, request, context) {
|
|
2246
|
+
const hookContext = context;
|
|
2247
|
+
hookContext.response = void 0;
|
|
2248
|
+
for (const hook of route2.before || []) {
|
|
2249
|
+
const response = await hook(request, hookContext);
|
|
2250
|
+
if (response) {
|
|
2251
|
+
hookContext.response = response;
|
|
2252
|
+
return response;
|
|
2253
|
+
}
|
|
2254
|
+
if (hookContext.response) {
|
|
2255
|
+
return hookContext.response;
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
return void 0;
|
|
2259
|
+
}
|
|
2260
|
+
__name(runIntegrationRouteBeforeHooks, "runIntegrationRouteBeforeHooks");
|
|
2261
|
+
async function runIntegrationRouteAfterHooks(route2, request, context, response) {
|
|
2262
|
+
const hookContext = context;
|
|
2263
|
+
let currentResponse = response;
|
|
2264
|
+
for (const hook of route2.after || []) {
|
|
2265
|
+
hookContext.response = currentResponse;
|
|
2266
|
+
const nextResponse = await hook(request, hookContext);
|
|
2267
|
+
currentResponse = nextResponse || hookContext.response || currentResponse;
|
|
2268
|
+
}
|
|
2269
|
+
hookContext.response = currentResponse;
|
|
2270
|
+
return currentResponse;
|
|
2271
|
+
}
|
|
2272
|
+
__name(runIntegrationRouteAfterHooks, "runIntegrationRouteAfterHooks");
|
|
2273
|
+
function createQueryInput(searchParams) {
|
|
2274
|
+
const input = {};
|
|
2275
|
+
searchParams.forEach((value, key) => {
|
|
2276
|
+
const existing = input[key];
|
|
2277
|
+
if (existing === void 0) {
|
|
2278
|
+
input[key] = value;
|
|
2279
|
+
return;
|
|
2280
|
+
}
|
|
2281
|
+
input[key] = Array.isArray(existing) ? [...existing, value] : [existing, value];
|
|
2282
|
+
});
|
|
2283
|
+
return input;
|
|
2284
|
+
}
|
|
2285
|
+
__name(createQueryInput, "createQueryInput");
|
|
2286
|
+
function createFormInput(formData) {
|
|
2287
|
+
const input = {};
|
|
2288
|
+
formData.forEach((value, key) => {
|
|
2289
|
+
const existing = input[key];
|
|
2290
|
+
if (existing === void 0) {
|
|
2291
|
+
input[key] = value;
|
|
2292
|
+
return;
|
|
2293
|
+
}
|
|
2294
|
+
input[key] = Array.isArray(existing) ? [...existing, value] : [existing, value];
|
|
2295
|
+
});
|
|
2296
|
+
return input;
|
|
2297
|
+
}
|
|
2298
|
+
__name(createFormInput, "createFormInput");
|
|
2299
|
+
async function dispatchIntegrationRequest(runtime, request, options = {}) {
|
|
2300
|
+
const integration = runtime.integration;
|
|
2301
|
+
const url = new URL(request.url);
|
|
2302
|
+
const pathname = url.pathname;
|
|
2303
|
+
const requestId = request.headers.get("x-request-id") || options.currentRequest?.headers.get("x-request-id") || String(Date.now());
|
|
2304
|
+
const routes = normalizeIntegrationRoutes(integration.routes || []);
|
|
2305
|
+
const middleware = [...integration.middleware || []];
|
|
2306
|
+
for (const entry of middleware) {
|
|
2307
|
+
const params = resolveMatcherParams(entry.matcher, pathname);
|
|
2308
|
+
if (!params) {
|
|
2309
|
+
continue;
|
|
2310
|
+
}
|
|
2311
|
+
const handlerContext = createServerIntegrationHandlerContext({
|
|
2312
|
+
runtime,
|
|
2313
|
+
route: {
|
|
2314
|
+
kind: "middleware",
|
|
2315
|
+
path: normalizeMatcher(entry.matcher),
|
|
2316
|
+
methods: ["ALL"]
|
|
2317
|
+
},
|
|
2318
|
+
request,
|
|
2319
|
+
params,
|
|
2320
|
+
pathname,
|
|
2321
|
+
requestId,
|
|
2322
|
+
currentRequest: options.currentRequest,
|
|
2323
|
+
data: options.data,
|
|
2324
|
+
internal: options.internal === true
|
|
2325
|
+
});
|
|
2326
|
+
const startedAt = Date.now();
|
|
2327
|
+
await integration.log?.({
|
|
2328
|
+
category: integration.category,
|
|
2329
|
+
slot: integration.category,
|
|
2330
|
+
type: integration.type,
|
|
2331
|
+
phase: "request:start",
|
|
2332
|
+
route: {
|
|
2333
|
+
kind: "middleware",
|
|
2334
|
+
path: normalizeMatcher(entry.matcher),
|
|
2335
|
+
methods: ["ALL"]
|
|
2336
|
+
},
|
|
2337
|
+
request,
|
|
2338
|
+
requestId,
|
|
2339
|
+
context: handlerContext.req.snapshot()
|
|
2340
|
+
});
|
|
2341
|
+
try {
|
|
2342
|
+
const response = await entry.handler(request, handlerContext);
|
|
2343
|
+
if (response) {
|
|
2344
|
+
await integration.log?.({
|
|
2345
|
+
category: integration.category,
|
|
2346
|
+
slot: integration.category,
|
|
2347
|
+
type: integration.type,
|
|
2348
|
+
phase: "request:end",
|
|
2349
|
+
route: {
|
|
2350
|
+
kind: "middleware",
|
|
2351
|
+
path: normalizeMatcher(entry.matcher),
|
|
2352
|
+
methods: ["ALL"]
|
|
2353
|
+
},
|
|
2354
|
+
request,
|
|
2355
|
+
response,
|
|
2356
|
+
requestId,
|
|
2357
|
+
durationMs: Date.now() - startedAt,
|
|
2358
|
+
context: handlerContext.req.snapshot()
|
|
2359
|
+
});
|
|
2360
|
+
return response;
|
|
2361
|
+
}
|
|
2362
|
+
await integration.log?.({
|
|
2363
|
+
category: integration.category,
|
|
2364
|
+
slot: integration.category,
|
|
2365
|
+
type: integration.type,
|
|
2366
|
+
phase: "request:end",
|
|
2367
|
+
route: {
|
|
2368
|
+
kind: "middleware",
|
|
2369
|
+
path: normalizeMatcher(entry.matcher),
|
|
2370
|
+
methods: ["ALL"]
|
|
2371
|
+
},
|
|
2372
|
+
request,
|
|
2373
|
+
requestId,
|
|
2374
|
+
durationMs: Date.now() - startedAt,
|
|
2375
|
+
context: handlerContext.req.snapshot()
|
|
2376
|
+
});
|
|
2377
|
+
} catch (error) {
|
|
2378
|
+
await integration.log?.({
|
|
2379
|
+
category: integration.category,
|
|
2380
|
+
slot: integration.category,
|
|
2381
|
+
type: integration.type,
|
|
2382
|
+
phase: "request:error",
|
|
2383
|
+
route: {
|
|
2384
|
+
kind: "middleware",
|
|
2385
|
+
path: normalizeMatcher(entry.matcher),
|
|
2386
|
+
methods: ["ALL"]
|
|
2387
|
+
},
|
|
2388
|
+
request,
|
|
2389
|
+
requestId,
|
|
2390
|
+
durationMs: Date.now() - startedAt,
|
|
2391
|
+
error,
|
|
2392
|
+
context: handlerContext.req.snapshot()
|
|
2393
|
+
});
|
|
2394
|
+
throw error;
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
for (const route2 of routes) {
|
|
2398
|
+
const params = matchesMethod(route2.methods, request.method) ? extractPathParams(route2.path, pathname) : null;
|
|
2399
|
+
if (!params) {
|
|
2400
|
+
continue;
|
|
2401
|
+
}
|
|
2402
|
+
const handlerContext = createServerIntegrationHandlerContext({
|
|
2403
|
+
runtime,
|
|
2404
|
+
route: {
|
|
2405
|
+
kind: "route",
|
|
2406
|
+
path: route2.path,
|
|
2407
|
+
methods: route2.methods
|
|
2408
|
+
},
|
|
2409
|
+
request,
|
|
2410
|
+
params,
|
|
2411
|
+
pathname,
|
|
2412
|
+
requestId,
|
|
2413
|
+
currentRequest: options.currentRequest,
|
|
2414
|
+
data: options.data,
|
|
2415
|
+
internal: options.internal === true
|
|
2416
|
+
});
|
|
2417
|
+
const startedAt = Date.now();
|
|
2418
|
+
await integration.log?.({
|
|
2419
|
+
category: integration.category,
|
|
2420
|
+
slot: integration.category,
|
|
2421
|
+
type: integration.type,
|
|
2422
|
+
phase: "request:start",
|
|
2423
|
+
route: {
|
|
2424
|
+
kind: "route",
|
|
2425
|
+
path: route2.path,
|
|
2426
|
+
methods: route2.methods
|
|
2427
|
+
},
|
|
2428
|
+
request,
|
|
2429
|
+
requestId,
|
|
2430
|
+
context: handlerContext.req.snapshot()
|
|
2431
|
+
});
|
|
2432
|
+
try {
|
|
2433
|
+
const validation = await validateIntegrationRouteInput(route2, request, url);
|
|
2434
|
+
if (!validation.success) {
|
|
2435
|
+
await integration.log?.({
|
|
2436
|
+
category: integration.category,
|
|
2437
|
+
slot: integration.category,
|
|
2438
|
+
type: integration.type,
|
|
2439
|
+
phase: "request:end",
|
|
2440
|
+
route: {
|
|
2441
|
+
kind: "route",
|
|
2442
|
+
path: route2.path,
|
|
2443
|
+
methods: route2.methods
|
|
2444
|
+
},
|
|
2445
|
+
request,
|
|
2446
|
+
response: validation.response,
|
|
2447
|
+
requestId,
|
|
2448
|
+
durationMs: Date.now() - startedAt,
|
|
2449
|
+
context: handlerContext.req.snapshot()
|
|
2450
|
+
});
|
|
2451
|
+
return validation.response;
|
|
2452
|
+
}
|
|
2453
|
+
handlerContext.input = validation.input;
|
|
2454
|
+
for (const middlewareEntry of route2.middleware || []) {
|
|
2455
|
+
const middlewareResponse = await middlewareEntry.handler(request, handlerContext);
|
|
2456
|
+
if (middlewareResponse) {
|
|
2457
|
+
await integration.log?.({
|
|
2458
|
+
category: integration.category,
|
|
2459
|
+
slot: integration.category,
|
|
2460
|
+
type: integration.type,
|
|
2461
|
+
phase: "request:end",
|
|
2462
|
+
route: {
|
|
2463
|
+
kind: "route",
|
|
2464
|
+
path: route2.path,
|
|
2465
|
+
methods: route2.methods
|
|
2466
|
+
},
|
|
2467
|
+
request,
|
|
2468
|
+
response: middlewareResponse,
|
|
2469
|
+
requestId,
|
|
2470
|
+
durationMs: Date.now() - startedAt,
|
|
2471
|
+
context: handlerContext.req.snapshot()
|
|
2472
|
+
});
|
|
2473
|
+
return middlewareResponse;
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
const beforeResponse = await runIntegrationRouteBeforeHooks(route2, request, handlerContext);
|
|
2477
|
+
if (beforeResponse) {
|
|
2478
|
+
const response2 = await runIntegrationRouteAfterHooks(
|
|
2479
|
+
route2,
|
|
2480
|
+
request,
|
|
2481
|
+
handlerContext,
|
|
2482
|
+
beforeResponse
|
|
2483
|
+
);
|
|
2484
|
+
await integration.log?.({
|
|
2485
|
+
category: integration.category,
|
|
2486
|
+
slot: integration.category,
|
|
2487
|
+
type: integration.type,
|
|
2488
|
+
phase: "request:end",
|
|
2489
|
+
route: {
|
|
2490
|
+
kind: "route",
|
|
2491
|
+
path: route2.path,
|
|
2492
|
+
methods: route2.methods
|
|
2493
|
+
},
|
|
2494
|
+
request,
|
|
2495
|
+
response: response2,
|
|
2496
|
+
requestId,
|
|
2497
|
+
durationMs: Date.now() - startedAt,
|
|
2498
|
+
context: handlerContext.req.snapshot()
|
|
2499
|
+
});
|
|
2500
|
+
return response2;
|
|
2501
|
+
}
|
|
2502
|
+
const handlerResponse = await route2.handler(request, handlerContext);
|
|
2503
|
+
const response = await runIntegrationRouteAfterHooks(
|
|
2504
|
+
route2,
|
|
2505
|
+
request,
|
|
2506
|
+
handlerContext,
|
|
2507
|
+
handlerResponse
|
|
2508
|
+
);
|
|
2509
|
+
await integration.log?.({
|
|
2510
|
+
category: integration.category,
|
|
2511
|
+
slot: integration.category,
|
|
2512
|
+
type: integration.type,
|
|
2513
|
+
phase: "request:end",
|
|
2514
|
+
route: {
|
|
2515
|
+
kind: "route",
|
|
2516
|
+
path: route2.path,
|
|
2517
|
+
methods: route2.methods
|
|
2518
|
+
},
|
|
2519
|
+
request,
|
|
2520
|
+
response,
|
|
2521
|
+
requestId,
|
|
2522
|
+
durationMs: Date.now() - startedAt,
|
|
2523
|
+
context: handlerContext.req.snapshot()
|
|
2524
|
+
});
|
|
2525
|
+
return response;
|
|
2526
|
+
} catch (error) {
|
|
2527
|
+
await integration.log?.({
|
|
2528
|
+
category: integration.category,
|
|
2529
|
+
slot: integration.category,
|
|
2530
|
+
type: integration.type,
|
|
2531
|
+
phase: "request:error",
|
|
2532
|
+
route: {
|
|
2533
|
+
kind: "route",
|
|
2534
|
+
path: route2.path,
|
|
2535
|
+
methods: route2.methods
|
|
2536
|
+
},
|
|
2537
|
+
request,
|
|
2538
|
+
requestId,
|
|
2539
|
+
durationMs: Date.now() - startedAt,
|
|
2540
|
+
error,
|
|
2541
|
+
context: handlerContext.req.snapshot()
|
|
2542
|
+
});
|
|
2543
|
+
throw error;
|
|
2544
|
+
}
|
|
2545
|
+
}
|
|
2546
|
+
return null;
|
|
2547
|
+
}
|
|
2548
|
+
__name(dispatchIntegrationRequest, "dispatchIntegrationRequest");
|
|
2549
|
+
globalThis[INTEGRATION_REQUEST_DISPATCHER_KEY] = dispatchIntegrationRequest;
|
|
2550
|
+
function createIntegrationRequestContextStore(rawRequest, request, pluginContext) {
|
|
2551
|
+
return {
|
|
2552
|
+
get(key) {
|
|
2553
|
+
const requestValue = pluginContext.requestContext.get(request, key);
|
|
2554
|
+
if (requestValue !== void 0) {
|
|
2555
|
+
return requestValue;
|
|
2556
|
+
}
|
|
2557
|
+
return pluginContext.requestContext.get(rawRequest, key);
|
|
2558
|
+
},
|
|
2559
|
+
set(key, value, options) {
|
|
2560
|
+
pluginContext.requestContext.set(rawRequest, key, value, options);
|
|
2561
|
+
pluginContext.requestContext.set(request, key, value, options);
|
|
2562
|
+
},
|
|
2563
|
+
has(key) {
|
|
2564
|
+
return pluginContext.requestContext.has(request, key) || pluginContext.requestContext.has(rawRequest, key);
|
|
2565
|
+
},
|
|
2566
|
+
delete(key) {
|
|
2567
|
+
const deletedRequest = pluginContext.requestContext.delete(request, key);
|
|
2568
|
+
const deletedRaw = pluginContext.requestContext.delete(rawRequest, key);
|
|
2569
|
+
return deletedRequest || deletedRaw;
|
|
2570
|
+
},
|
|
2571
|
+
clear() {
|
|
2572
|
+
pluginContext.requestContext.clear(rawRequest);
|
|
2573
|
+
pluginContext.requestContext.clear(request);
|
|
2574
|
+
},
|
|
2575
|
+
snapshot(options) {
|
|
2576
|
+
const merged = pluginContext.requestContext.getAll(rawRequest, options);
|
|
2577
|
+
const requestSnapshot = pluginContext.requestContext.getAll(request, options);
|
|
2578
|
+
for (const [key, value] of requestSnapshot) {
|
|
2579
|
+
merged.set(key, value);
|
|
2580
|
+
}
|
|
2581
|
+
return merged;
|
|
2582
|
+
}
|
|
2583
|
+
};
|
|
2584
|
+
}
|
|
2585
|
+
__name(createIntegrationRequestContextStore, "createIntegrationRequestContextStore");
|
|
2586
|
+
function createServerIntegrationHandlerContext(input) {
|
|
2587
|
+
const req = createServerIntegrationRequestContextStore(input.request, input.currentRequest);
|
|
2588
|
+
if (input.internal) {
|
|
2589
|
+
req.set(FARM_INTEGRATION_INTERNAL_DISPATCH_CONTEXT_KEY, true);
|
|
2590
|
+
}
|
|
2591
|
+
return {
|
|
2592
|
+
request: input.request,
|
|
2593
|
+
requestId: input.requestId,
|
|
2594
|
+
url: new URL(input.request.url),
|
|
2595
|
+
pathname: input.pathname,
|
|
2596
|
+
method: input.request.method,
|
|
2597
|
+
params: input.params,
|
|
2598
|
+
input: {},
|
|
2599
|
+
args: createIntegrationRouteArgs({
|
|
2600
|
+
integration: input.runtime.integration,
|
|
2601
|
+
config: input.runtime.config
|
|
2602
|
+
}),
|
|
2603
|
+
data: resolveIntegrationData(input.request, input.data),
|
|
2604
|
+
integration: {
|
|
2605
|
+
category: input.runtime.integration.category,
|
|
2606
|
+
slot: input.runtime.integration.category,
|
|
2607
|
+
type: input.runtime.integration.type,
|
|
2608
|
+
instance: input.runtime.integration.instance
|
|
2609
|
+
},
|
|
2610
|
+
route: input.route,
|
|
2611
|
+
req,
|
|
2612
|
+
requestContext: req,
|
|
2613
|
+
config: input.runtime.config,
|
|
2614
|
+
isDev: input.runtime.isDev,
|
|
2615
|
+
isProd: input.runtime.isProd
|
|
2616
|
+
};
|
|
2617
|
+
}
|
|
2618
|
+
__name(createServerIntegrationHandlerContext, "createServerIntegrationHandlerContext");
|
|
2619
|
+
function createServerIntegrationRequestContextStore(request, currentRequest) {
|
|
2620
|
+
return {
|
|
2621
|
+
get(key) {
|
|
2622
|
+
const requestValue = getRequestContext(request, key);
|
|
2623
|
+
if (requestValue !== void 0) {
|
|
2624
|
+
return requestValue;
|
|
2625
|
+
}
|
|
2626
|
+
if (currentRequest) {
|
|
2627
|
+
return getRequestContext(currentRequest, key);
|
|
2628
|
+
}
|
|
2629
|
+
return void 0;
|
|
2630
|
+
},
|
|
2631
|
+
set(key, value, options) {
|
|
2632
|
+
setRequestContext(request, key, value, options);
|
|
2633
|
+
if (currentRequest) {
|
|
2634
|
+
setRequestContext(currentRequest, key, value, options);
|
|
2635
|
+
}
|
|
2636
|
+
},
|
|
2637
|
+
has(key) {
|
|
2638
|
+
return hasRequestContext(request, key) || !!currentRequest && hasRequestContext(currentRequest, key);
|
|
2639
|
+
},
|
|
2640
|
+
delete(key) {
|
|
2641
|
+
const deletedRequest = deleteRequestContext(request, key);
|
|
2642
|
+
const deletedCurrent = currentRequest ? deleteRequestContext(currentRequest, key) : false;
|
|
2643
|
+
return deletedRequest || deletedCurrent;
|
|
2644
|
+
},
|
|
2645
|
+
clear() {
|
|
2646
|
+
clearRequestContext(request);
|
|
2647
|
+
if (currentRequest) {
|
|
2648
|
+
clearRequestContext(currentRequest);
|
|
2649
|
+
}
|
|
2650
|
+
},
|
|
2651
|
+
snapshot(options) {
|
|
2652
|
+
const merged = currentRequest ? getRequestContextSnapshot(currentRequest, options) : /* @__PURE__ */ new Map();
|
|
2653
|
+
const requestSnapshot = getRequestContextSnapshot(request, options);
|
|
2654
|
+
for (const [key, value] of requestSnapshot) {
|
|
2655
|
+
merged.set(key, value);
|
|
2656
|
+
}
|
|
2657
|
+
return merged;
|
|
2658
|
+
}
|
|
2659
|
+
};
|
|
2660
|
+
}
|
|
2661
|
+
__name(createServerIntegrationRequestContextStore, "createServerIntegrationRequestContextStore");
|
|
2662
|
+
function createWebRequest(req, fullUrl, body) {
|
|
2663
|
+
const headers = new Headers();
|
|
2664
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
2665
|
+
if (value == null) {
|
|
2666
|
+
continue;
|
|
2667
|
+
}
|
|
2668
|
+
if (Array.isArray(value)) {
|
|
2669
|
+
for (const item of value) {
|
|
2670
|
+
headers.append(key, item);
|
|
2671
|
+
}
|
|
2672
|
+
continue;
|
|
2673
|
+
}
|
|
2674
|
+
headers.set(key, value);
|
|
2675
|
+
}
|
|
2676
|
+
return new Request(fullUrl, {
|
|
2677
|
+
method: req.method,
|
|
2678
|
+
headers,
|
|
2679
|
+
body
|
|
2680
|
+
});
|
|
2681
|
+
}
|
|
2682
|
+
__name(createWebRequest, "createWebRequest");
|
|
2683
|
+
function matchesMethod(methods, method) {
|
|
2684
|
+
if (!method) {
|
|
2685
|
+
return false;
|
|
2686
|
+
}
|
|
2687
|
+
return methods.some((item) => item.toUpperCase() === method.toUpperCase());
|
|
2688
|
+
}
|
|
2689
|
+
__name(matchesMethod, "matchesMethod");
|
|
2690
|
+
function resolveMatcherParams(matcher, pathname) {
|
|
2691
|
+
if (!matcher) {
|
|
2692
|
+
return {};
|
|
2693
|
+
}
|
|
2694
|
+
const list = Array.isArray(matcher) ? matcher : [matcher];
|
|
2695
|
+
for (const item of list) {
|
|
2696
|
+
if (item === "/(.*)" || item === "*") {
|
|
2697
|
+
return {};
|
|
2698
|
+
}
|
|
2699
|
+
if (item.endsWith("(.*)")) {
|
|
2700
|
+
const prefix = item.slice(0, -4);
|
|
2701
|
+
if (pathname === prefix || pathname.startsWith(`${prefix}/`)) {
|
|
2702
|
+
return {};
|
|
2703
|
+
}
|
|
2704
|
+
continue;
|
|
2705
|
+
}
|
|
2706
|
+
const params = extractPathParams(item, pathname);
|
|
2707
|
+
if (params) {
|
|
2708
|
+
return params;
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
return null;
|
|
2712
|
+
}
|
|
2713
|
+
__name(resolveMatcherParams, "resolveMatcherParams");
|
|
2714
|
+
function extractPathParams(pattern, pathname) {
|
|
2715
|
+
const routeSegments = splitPath(pattern);
|
|
2716
|
+
const pathSegments = splitPath(pathname);
|
|
2717
|
+
const params = {};
|
|
2718
|
+
let routeIndex = 0;
|
|
2719
|
+
let pathIndex = 0;
|
|
2720
|
+
while (routeIndex < routeSegments.length && pathIndex < pathSegments.length) {
|
|
2721
|
+
const routeSegment = routeSegments[routeIndex];
|
|
2722
|
+
const pathSegment = pathSegments[pathIndex];
|
|
2723
|
+
if (isCatchAllSegment(routeSegment)) {
|
|
2724
|
+
params[getSegmentParamName(routeSegment)] = pathSegments.slice(pathIndex).map((segment) => decodeURIComponent(segment));
|
|
2725
|
+
return params;
|
|
2726
|
+
}
|
|
2727
|
+
if (isDynamicSegment(routeSegment)) {
|
|
2728
|
+
params[getSegmentParamName(routeSegment)] = decodeURIComponent(pathSegment);
|
|
2729
|
+
routeIndex += 1;
|
|
2730
|
+
pathIndex += 1;
|
|
2731
|
+
continue;
|
|
2732
|
+
}
|
|
2733
|
+
if (routeSegment !== pathSegment) {
|
|
2734
|
+
return null;
|
|
2735
|
+
}
|
|
2736
|
+
routeIndex += 1;
|
|
2737
|
+
pathIndex += 1;
|
|
2738
|
+
}
|
|
2739
|
+
if (routeIndex === routeSegments.length && pathIndex === pathSegments.length) {
|
|
2740
|
+
return params;
|
|
2741
|
+
}
|
|
2742
|
+
if (routeIndex === routeSegments.length - 1 && isCatchAllSegment(routeSegments[routeIndex])) {
|
|
2743
|
+
params[getSegmentParamName(routeSegments[routeIndex])] = [];
|
|
2744
|
+
return params;
|
|
2745
|
+
}
|
|
2746
|
+
return null;
|
|
2747
|
+
}
|
|
2748
|
+
__name(extractPathParams, "extractPathParams");
|
|
2749
|
+
function splitPath(value) {
|
|
2750
|
+
return value.split("/").filter(Boolean);
|
|
2751
|
+
}
|
|
2752
|
+
__name(splitPath, "splitPath");
|
|
2753
|
+
function isDynamicSegment(segment) {
|
|
2754
|
+
return segment.startsWith("[") && segment.endsWith("]");
|
|
2755
|
+
}
|
|
2756
|
+
__name(isDynamicSegment, "isDynamicSegment");
|
|
2757
|
+
function isCatchAllSegment(segment) {
|
|
2758
|
+
return segment.startsWith("[...") && segment.endsWith("]");
|
|
2759
|
+
}
|
|
2760
|
+
__name(isCatchAllSegment, "isCatchAllSegment");
|
|
2761
|
+
function getSegmentParamName(segment) {
|
|
2762
|
+
if (isCatchAllSegment(segment)) {
|
|
2763
|
+
return segment.slice(4, -1);
|
|
2764
|
+
}
|
|
2765
|
+
return segment.slice(1, -1);
|
|
2766
|
+
}
|
|
2767
|
+
__name(getSegmentParamName, "getSegmentParamName");
|
|
2768
|
+
function getRequestId(req) {
|
|
2769
|
+
const headerValue = req.headers["x-request-id"];
|
|
2770
|
+
if (Array.isArray(headerValue)) {
|
|
2771
|
+
return headerValue[0] || String(Date.now());
|
|
2772
|
+
}
|
|
2773
|
+
return headerValue || String(Date.now());
|
|
2774
|
+
}
|
|
2775
|
+
__name(getRequestId, "getRequestId");
|
|
2776
|
+
async function readRequestBody(req) {
|
|
2777
|
+
return await new Promise((resolve, reject) => {
|
|
2778
|
+
const chunks = [];
|
|
2779
|
+
req.on("data", (chunk) => {
|
|
2780
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
2781
|
+
});
|
|
2782
|
+
req.on("end", () => {
|
|
2783
|
+
resolve(Buffer.concat(chunks));
|
|
2784
|
+
});
|
|
2785
|
+
req.on("error", reject);
|
|
2786
|
+
});
|
|
2787
|
+
}
|
|
2788
|
+
__name(readRequestBody, "readRequestBody");
|
|
2789
|
+
function normalizeMatcher(matcher) {
|
|
2790
|
+
if (!matcher) {
|
|
2791
|
+
return "/(.*)";
|
|
2792
|
+
}
|
|
2793
|
+
return typeof matcher === "string" ? matcher : matcher.join(", ");
|
|
2794
|
+
}
|
|
2795
|
+
__name(normalizeMatcher, "normalizeMatcher");
|
|
2796
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2797
|
+
0 && (module.exports = {
|
|
2798
|
+
FARM_INTEGRATION_INTERNAL_DISPATCH_CONTEXT_KEY,
|
|
2799
|
+
api,
|
|
2800
|
+
createIntegrationRoute,
|
|
2801
|
+
defineIntegration,
|
|
2802
|
+
defineIntegrationAPI,
|
|
2803
|
+
defineIntegrationAPIOperation,
|
|
2804
|
+
defineIntegrationSchema,
|
|
2805
|
+
dispatchIntegrationRequest,
|
|
2806
|
+
getFarmIntegrationPluginServerRuntime,
|
|
2807
|
+
getIntegrationDocumentNavigationMatchers,
|
|
2808
|
+
getIntegrationProviders,
|
|
2809
|
+
getIntegrationSchemas,
|
|
2810
|
+
getRegisteredIntegrationAPIManifest,
|
|
2811
|
+
getRegisteredIntegrationRuntime,
|
|
2812
|
+
getRegisteredIntegrationSchemas,
|
|
2813
|
+
getRegisteredIntegrations,
|
|
2814
|
+
integrationRoute,
|
|
2815
|
+
isFarmIntegration,
|
|
2816
|
+
matchIntegrationRoute,
|
|
2817
|
+
matchRegisteredIntegrationRoute,
|
|
2818
|
+
resolveIntegrationPlugins
|
|
2819
|
+
});
|
|
2820
|
+
//# sourceMappingURL=integrations.cjs.map
|