devflare 1.0.0-next.7 → 1.0.0-next.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/LLM.md +17315 -2144
- package/README.md +398 -607
- package/bin/devflare.js +30 -14
- package/dist/_chunks/account-BHY3fvrA.js +462 -0
- package/dist/_chunks/account-resources-BdKj8q1h.js +159 -0
- package/dist/_chunks/ai-CN_SREim.js +322 -0
- package/dist/_chunks/api-BKClUlUf.js +568 -0
- package/dist/_chunks/build-DplSo6Gc.js +24 -0
- package/dist/_chunks/build-artifacts-CkwCap5N.js +483 -0
- package/dist/_chunks/cli-ZJYtm-lW.js +1214 -0
- package/dist/_chunks/cloudflare-Ic5ubQza.js +157 -0
- package/dist/_chunks/colors-D0NVzAFN.js +13 -0
- package/dist/_chunks/command-utils-DjaaMQX7.js +45 -0
- package/dist/_chunks/compiler-UxXQgEPq.js +521 -0
- package/dist/_chunks/config-path-CYGlwKDs.js +42 -0
- package/dist/_chunks/config-zQd4jmXU.js +78 -0
- package/dist/_chunks/context-DGMev2AF.js +2515 -0
- package/dist/_chunks/decorators-eXNZ1S0N.js +19 -0
- package/dist/_chunks/dependencies-wKqrxKV_.js +57 -0
- package/dist/_chunks/deploy-z1_wbNn2.js +1032 -0
- package/dist/_chunks/dev-BagtFegV.js +952 -0
- package/dist/_chunks/doctor-CAsJ-rSZ.js +219 -0
- package/dist/_chunks/durable-object-DuMPM8re.js +234 -0
- package/dist/_chunks/env-D4uJqqgu.js +125 -0
- package/dist/_chunks/family-BTTpTwUk.js +143 -0
- package/dist/_chunks/generated-artifacts-Bb13pGUG.js +32 -0
- package/dist/_chunks/glob-DRw9sbfF.js +56 -0
- package/dist/_chunks/init-DJ5y3mu5.js +165 -0
- package/dist/_chunks/loader-BC0skbnH.js +1330 -0
- package/dist/_chunks/local-dev-vars-BFLS-HoI.js +81 -0
- package/dist/_chunks/local-hyperdrive-CcORzo76.js +119 -0
- package/dist/_chunks/local-media-bindings-ZQe-epuw.js +335 -0
- package/dist/_chunks/local-secrets-C0n5oRgI.js +123 -0
- package/dist/_chunks/login-CgNcbpEq.js +51 -0
- package/dist/_chunks/package-metadata-CLI488gB.js +39 -0
- package/dist/_chunks/preferences-CbYERA_m.js +241 -0
- package/dist/_chunks/preview-j9Kbx4-G.js +462 -0
- package/dist/_chunks/preview-registry-CTXU4mBc.js +1186 -0
- package/dist/_chunks/preview-resources-CQIu2-NY.js +359 -0
- package/dist/_chunks/previews-BIaw6NVC.js +1133 -0
- package/dist/_chunks/productions-CF8oQcX7.js +504 -0
- package/dist/_chunks/r2-presign-runtime-C75FkLMd.js +291 -0
- package/dist/_chunks/ref-CYJNAAe_.js +178 -0
- package/dist/_chunks/remote-8jEHLVGg.js +79 -0
- package/dist/_chunks/remote-config-Bw6qIVM4.js +132 -0
- package/dist/_chunks/resolve-package-DeJUGxoE.js +152 -0
- package/dist/_chunks/rolldown-runtime-CvQ6eiug.js +14 -0
- package/dist/_chunks/routes-CRXB3-iw.js +851 -0
- package/dist/_chunks/runtime-BlKTWIgD.js +874 -0
- package/dist/_chunks/schema-normalization-CTdiY17P.js +667 -0
- package/dist/_chunks/secrets-BJuEa9Jz.js +95 -0
- package/dist/_chunks/tail-DjGRt8gw.js +239 -0
- package/dist/_chunks/token-wmeF8-IQ.js +333 -0
- package/dist/_chunks/tokens-KaEr4B8e.js +221 -0
- package/dist/_chunks/types-BLGfxIq-.js +484 -0
- package/dist/_chunks/ui-BhCdDC2N.js +103 -0
- package/dist/_chunks/usage-rRusKejc.js +272 -0
- package/dist/_chunks/vite-Bml-Whp8.js +1267 -0
- package/dist/_chunks/vite-process-CDa3yQui.js +2929 -0
- package/dist/_chunks/vite-utils-D8kPPxUy.js +183 -0
- package/dist/_chunks/worker-DgczaXVW.js +410 -0
- package/dist/_chunks/worker-bundler-Isj5jiW6.js +458 -0
- package/dist/_chunks/worker-entrypoint-C8j23t6d.js +247 -0
- package/dist/_chunks/workerName-kEXwmV2m.js +23 -0
- package/dist/_chunks/workspace-CrvqPLTX.js +517 -0
- package/dist/_chunks/workspace-Ds3xMjOE.js +175 -0
- package/dist/bridge/client.d.ts +93 -8
- package/dist/bridge/client.d.ts.map +1 -1
- package/dist/bridge/do-rpc-dispatch.d.ts +23 -0
- package/dist/bridge/do-rpc-dispatch.d.ts.map +1 -0
- package/dist/bridge/do-websocket-connect.d.ts +33 -0
- package/dist/bridge/do-websocket-connect.d.ts.map +1 -0
- package/dist/bridge/gateway-runtime.d.ts +8 -0
- package/dist/bridge/gateway-runtime.d.ts.map +1 -0
- package/dist/bridge/index.d.ts +6 -6
- package/dist/bridge/index.d.ts.map +1 -1
- package/dist/bridge/log.d.ts +5 -0
- package/dist/bridge/log.d.ts.map +1 -0
- package/dist/bridge/miniflare-gateway.d.ts +45 -0
- package/dist/bridge/miniflare-gateway.d.ts.map +1 -0
- package/dist/bridge/miniflare.d.ts +92 -2
- package/dist/bridge/miniflare.d.ts.map +1 -1
- package/dist/bridge/proxy.d.ts +12 -11
- package/dist/bridge/proxy.d.ts.map +1 -1
- package/dist/bridge/r2-presign-runtime.d.ts +9 -0
- package/dist/bridge/r2-presign-runtime.d.ts.map +1 -0
- package/dist/bridge/server.d.ts +2 -1
- package/dist/bridge/server.d.ts.map +1 -1
- package/dist/bridge/v2/body-streams.d.ts +53 -0
- package/dist/bridge/v2/body-streams.d.ts.map +1 -0
- package/dist/bridge/v2/codec.d.ts +106 -0
- package/dist/bridge/v2/codec.d.ts.map +1 -0
- package/dist/bridge/v2/control-messages.d.ts +46 -0
- package/dist/bridge/v2/control-messages.d.ts.map +1 -0
- package/dist/bridge/v2/frames.d.ts +109 -0
- package/dist/bridge/v2/frames.d.ts.map +1 -0
- package/dist/bridge/v2/index.d.ts +11 -0
- package/dist/bridge/v2/index.d.ts.map +1 -0
- package/dist/bridge/v2/serialization.d.ts +48 -0
- package/dist/bridge/v2/serialization.d.ts.map +1 -0
- package/dist/bridge/v2/transport.d.ts +31 -0
- package/dist/bridge/v2/transport.d.ts.map +1 -0
- package/dist/bridge/v2/value-codec.d.ts +61 -0
- package/dist/bridge/v2/value-codec.d.ts.map +1 -0
- package/dist/bridge/v2/value-serialization.d.ts +139 -0
- package/dist/bridge/v2/value-serialization.d.ts.map +1 -0
- package/dist/bridge/{protocol.d.ts → v2/wire.d.ts} +32 -8
- package/dist/bridge/v2/wire.d.ts.map +1 -0
- package/dist/bridge/v2/ws-relay.d.ts +53 -0
- package/dist/bridge/v2/ws-relay.d.ts.map +1 -0
- package/dist/bridge/websocket-constructor.d.ts +38 -0
- package/dist/bridge/websocket-constructor.d.ts.map +1 -0
- package/dist/browser-shim/handler.d.ts +2 -2
- package/dist/browser-shim/handler.d.ts.map +1 -1
- package/dist/browser-shim/index.d.ts +2 -2
- package/dist/browser-shim/server.d.ts +63 -0
- package/dist/browser-shim/server.d.ts.map +1 -1
- package/dist/browser.d.ts +5778 -43
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +73 -142
- package/dist/bundler/defaults.d.ts +23 -0
- package/dist/bundler/defaults.d.ts.map +1 -0
- package/dist/bundler/do-bundler.d.ts +7 -0
- package/dist/bundler/do-bundler.d.ts.map +1 -1
- package/dist/bundler/index.d.ts +3 -1
- package/dist/bundler/index.d.ts.map +1 -1
- package/dist/bundler/rolldown-shared.d.ts +53 -0
- package/dist/bundler/rolldown-shared.d.ts.map +1 -0
- package/dist/bundler/worker-bundler.d.ts +13 -0
- package/dist/bundler/worker-bundler.d.ts.map +1 -0
- package/dist/bundler/worker-compat.d.ts +4 -0
- package/dist/bundler/worker-compat.d.ts.map +1 -0
- package/dist/cli/build-manifest.d.ts +66 -0
- package/dist/cli/build-manifest.d.ts.map +1 -0
- package/dist/cli/command-utils.d.ts +18 -0
- package/dist/cli/command-utils.d.ts.map +1 -0
- package/dist/cli/commands/account.d.ts +2 -2
- package/dist/cli/commands/account.d.ts.map +1 -1
- package/dist/cli/commands/ai.d.ts +1 -1
- package/dist/cli/commands/ai.d.ts.map +1 -1
- package/dist/cli/commands/build-artifacts.d.ts +40 -0
- package/dist/cli/commands/build-artifacts.d.ts.map +1 -0
- package/dist/cli/commands/build.d.ts +2 -2
- package/dist/cli/commands/build.d.ts.map +1 -1
- package/dist/cli/commands/config.d.ts +4 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/deploy/metadata.d.ts +18 -0
- package/dist/cli/commands/deploy/metadata.d.ts.map +1 -0
- package/dist/cli/commands/deploy/prepare.d.ts +23 -0
- package/dist/cli/commands/deploy/prepare.d.ts.map +1 -0
- package/dist/cli/commands/deploy/runtime.d.ts +4 -0
- package/dist/cli/commands/deploy/runtime.d.ts.map +1 -0
- package/dist/cli/commands/deploy/verification.d.ts +36 -0
- package/dist/cli/commands/deploy/verification.d.ts.map +1 -0
- package/dist/cli/commands/deploy.d.ts +2 -2
- package/dist/cli/commands/deploy.d.ts.map +1 -1
- package/dist/cli/commands/dev.d.ts +9 -1
- package/dist/cli/commands/dev.d.ts.map +1 -1
- package/dist/cli/commands/doctor.d.ts +2 -2
- package/dist/cli/commands/doctor.d.ts.map +1 -1
- package/dist/cli/commands/init.d.ts +2 -2
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/login.d.ts +4 -0
- package/dist/cli/commands/login.d.ts.map +1 -0
- package/dist/cli/commands/previews-support/cleanup.d.ts +9 -0
- package/dist/cli/commands/previews-support/cleanup.d.ts.map +1 -0
- package/dist/cli/commands/previews-support/family.d.ts +10 -0
- package/dist/cli/commands/previews-support/family.d.ts.map +1 -0
- package/dist/cli/commands/previews-support/render.d.ts +8 -0
- package/dist/cli/commands/previews-support/render.d.ts.map +1 -0
- package/dist/cli/commands/previews-support/theme.d.ts +10 -0
- package/dist/cli/commands/previews-support/theme.d.ts.map +1 -0
- package/dist/cli/commands/previews-support/types.d.ts +70 -0
- package/dist/cli/commands/previews-support/types.d.ts.map +1 -0
- package/dist/cli/commands/previews.d.ts +4 -0
- package/dist/cli/commands/previews.d.ts.map +1 -0
- package/dist/cli/commands/productions.d.ts +4 -0
- package/dist/cli/commands/productions.d.ts.map +1 -0
- package/dist/cli/commands/remote.d.ts +1 -1
- package/dist/cli/commands/remote.d.ts.map +1 -1
- package/dist/cli/commands/secrets.d.ts +4 -0
- package/dist/cli/commands/secrets.d.ts.map +1 -0
- package/dist/cli/commands/tail.d.ts +44 -0
- package/dist/cli/commands/tail.d.ts.map +1 -0
- package/dist/cli/commands/token.d.ts +4 -0
- package/dist/cli/commands/token.d.ts.map +1 -0
- package/dist/cli/commands/type-generation/discovery.d.ts +7 -0
- package/dist/cli/commands/type-generation/discovery.d.ts.map +1 -0
- package/dist/cli/commands/type-generation/generator.d.ts +121 -0
- package/dist/cli/commands/type-generation/generator.d.ts.map +1 -0
- package/dist/cli/commands/type-generation/models.d.ts +27 -0
- package/dist/cli/commands/type-generation/models.d.ts.map +1 -0
- package/dist/cli/commands/types.d.ts +2 -2
- package/dist/cli/commands/types.d.ts.map +1 -1
- package/dist/cli/commands/worker.d.ts +4 -0
- package/dist/cli/commands/worker.d.ts.map +1 -0
- package/dist/cli/commands/workspace.d.ts +8 -0
- package/dist/cli/commands/workspace.d.ts.map +1 -0
- package/dist/cli/config-path.d.ts +6 -0
- package/dist/cli/config-path.d.ts.map +1 -0
- package/dist/cli/dependencies.d.ts +2 -1
- package/dist/cli/dependencies.d.ts.map +1 -1
- package/dist/cli/deploy-strategy.d.ts +17 -0
- package/dist/cli/deploy-strategy.d.ts.map +1 -0
- package/dist/cli/deploy-target.d.ts +17 -0
- package/dist/cli/deploy-target.d.ts.map +1 -0
- package/dist/cli/generated-artifacts.d.ts +12 -0
- package/dist/cli/generated-artifacts.d.ts.map +1 -0
- package/dist/cli/gradual-deploy.d.ts +49 -0
- package/dist/cli/gradual-deploy.d.ts.map +1 -0
- package/dist/cli/help-pages/pages/account.d.ts +3 -0
- package/dist/cli/help-pages/pages/account.d.ts.map +1 -0
- package/dist/cli/help-pages/pages/core.d.ts +4 -0
- package/dist/cli/help-pages/pages/core.d.ts.map +1 -0
- package/dist/cli/help-pages/pages/index.d.ts +3 -0
- package/dist/cli/help-pages/pages/index.d.ts.map +1 -0
- package/dist/cli/help-pages/pages/misc.d.ts +3 -0
- package/dist/cli/help-pages/pages/misc.d.ts.map +1 -0
- package/dist/cli/help-pages/pages/previews.d.ts +3 -0
- package/dist/cli/help-pages/pages/previews.d.ts.map +1 -0
- package/dist/cli/help-pages/pages/productions.d.ts +3 -0
- package/dist/cli/help-pages/pages/productions.d.ts.map +1 -0
- package/dist/cli/help-pages/render.d.ts +12 -0
- package/dist/cli/help-pages/render.d.ts.map +1 -0
- package/dist/cli/help-pages/shared.d.ts +15 -0
- package/dist/cli/help-pages/shared.d.ts.map +1 -0
- package/dist/cli/help-pages/types.d.ts +23 -0
- package/dist/cli/help-pages/types.d.ts.map +1 -0
- package/dist/cli/help.d.ts +6 -0
- package/dist/cli/help.d.ts.map +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +2 -0
- package/dist/cli/package-metadata.d.ts +16 -0
- package/dist/cli/package-metadata.d.ts.map +1 -0
- package/dist/cli/preview-bindings.d.ts +49 -0
- package/dist/cli/preview-bindings.d.ts.map +1 -0
- package/dist/cli/preview.d.ts +10 -0
- package/dist/cli/preview.d.ts.map +1 -0
- package/dist/cli/ui.d.ts +37 -0
- package/dist/cli/ui.d.ts.map +1 -0
- package/dist/cli/workspace-build-guard.d.ts +14 -0
- package/dist/cli/workspace-build-guard.d.ts.map +1 -0
- package/dist/cli/wrangler-auth.d.ts +1 -1
- package/dist/cloudflare/account-core.d.ts +6 -0
- package/dist/cloudflare/account-core.d.ts.map +1 -0
- package/dist/cloudflare/account-resources.d.ts +40 -0
- package/dist/cloudflare/account-resources.d.ts.map +1 -0
- package/dist/cloudflare/account-status.d.ts +11 -0
- package/dist/cloudflare/account-status.d.ts.map +1 -0
- package/dist/cloudflare/account-workers.d.ts +14 -0
- package/dist/cloudflare/account-workers.d.ts.map +1 -0
- package/dist/cloudflare/account.d.ts +7 -64
- package/dist/cloudflare/account.d.ts.map +1 -1
- package/dist/cloudflare/api.d.ts +71 -3
- package/dist/cloudflare/api.d.ts.map +1 -1
- package/dist/cloudflare/auth.d.ts +1 -1
- package/dist/cloudflare/auth.d.ts.map +1 -1
- package/dist/cloudflare/index.d.ts +61 -6
- package/dist/cloudflare/index.d.ts.map +1 -1
- package/dist/cloudflare/index.js +4 -13
- package/dist/cloudflare/known-permission-group-ids.generated.d.ts +10 -0
- package/dist/cloudflare/known-permission-group-ids.generated.d.ts.map +1 -0
- package/dist/cloudflare/kv-namespace.d.ts +4 -0
- package/dist/cloudflare/kv-namespace.d.ts.map +1 -0
- package/dist/cloudflare/preferences.d.ts +7 -0
- package/dist/cloudflare/preferences.d.ts.map +1 -1
- package/dist/cloudflare/preview-registry-cache.d.ts +6 -0
- package/dist/cloudflare/preview-registry-cache.d.ts.map +1 -0
- package/dist/cloudflare/preview-registry-inference.d.ts +14 -0
- package/dist/cloudflare/preview-registry-inference.d.ts.map +1 -0
- package/dist/cloudflare/preview-registry-records.d.ts +4 -0
- package/dist/cloudflare/preview-registry-records.d.ts.map +1 -0
- package/dist/cloudflare/preview-registry-shape.d.ts +47 -0
- package/dist/cloudflare/preview-registry-shape.d.ts.map +1 -0
- package/dist/cloudflare/preview-registry-store.d.ts +14 -0
- package/dist/cloudflare/preview-registry-store.d.ts.map +1 -0
- package/dist/cloudflare/preview-registry-transport.d.ts +4 -0
- package/dist/cloudflare/preview-registry-transport.d.ts.map +1 -0
- package/dist/cloudflare/preview-registry-types.d.ts +103 -0
- package/dist/cloudflare/preview-registry-types.d.ts.map +1 -0
- package/dist/cloudflare/preview-registry.d.ts +42 -0
- package/dist/cloudflare/preview-registry.d.ts.map +1 -0
- package/dist/cloudflare/preview-urls.d.ts +3 -0
- package/dist/cloudflare/preview-urls.d.ts.map +1 -0
- package/dist/cloudflare/registry-schema.d.ts +253 -0
- package/dist/cloudflare/registry-schema.d.ts.map +1 -0
- package/dist/cloudflare/remote-config.d.ts.map +1 -1
- package/dist/cloudflare/tokens.d.ts +44 -0
- package/dist/cloudflare/tokens.d.ts.map +1 -0
- package/dist/cloudflare/types.d.ts +124 -7
- package/dist/cloudflare/types.d.ts.map +1 -1
- package/dist/cloudflare/usage.d.ts +31 -3
- package/dist/cloudflare/usage.d.ts.map +1 -1
- package/dist/config/binding-resolution-helpers.d.ts +41 -0
- package/dist/config/binding-resolution-helpers.d.ts.map +1 -0
- package/dist/config/compatibility.d.ts +3 -0
- package/dist/config/compatibility.d.ts.map +1 -0
- package/dist/config/compiler/bindings.d.ts +14 -0
- package/dist/config/compiler/bindings.d.ts.map +1 -0
- package/dist/config/compiler/core-helpers.d.ts +6 -0
- package/dist/config/compiler/core-helpers.d.ts.map +1 -0
- package/dist/config/compiler/do-workers.d.ts +34 -0
- package/dist/config/compiler/do-workers.d.ts.map +1 -0
- package/dist/config/compiler/paths.d.ts +18 -0
- package/dist/config/compiler/paths.d.ts.map +1 -0
- package/dist/config/compiler/types.d.ts +308 -0
- package/dist/config/compiler/types.d.ts.map +1 -0
- package/dist/config/compiler.d.ts +22 -134
- package/dist/config/compiler.d.ts.map +1 -1
- package/dist/config/cron.d.ts +19 -0
- package/dist/config/cron.d.ts.map +1 -0
- package/dist/config/define.d.ts +8 -5
- package/dist/config/define.d.ts.map +1 -1
- package/dist/config/deploy-resources.d.ts +58 -0
- package/dist/config/deploy-resources.d.ts.map +1 -0
- package/dist/config/env-vars.d.ts +309 -0
- package/dist/config/env-vars.d.ts.map +1 -0
- package/dist/config/framework-providers.d.ts +9 -0
- package/dist/config/framework-providers.d.ts.map +1 -0
- package/dist/config/index.d.ts +13 -5
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/loader.d.ts +2 -1
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/local-dev-vars.d.ts +15 -0
- package/dist/config/local-dev-vars.d.ts.map +1 -0
- package/dist/config/preview-resources.d.ts +83 -0
- package/dist/config/preview-resources.d.ts.map +1 -0
- package/dist/config/preview.d.ts +29 -0
- package/dist/config/preview.d.ts.map +1 -0
- package/dist/config/ref.d.ts +16 -25
- package/dist/config/ref.d.ts.map +1 -1
- package/dist/config/resolve-phased.d.ts +72 -0
- package/dist/config/resolve-phased.d.ts.map +1 -0
- package/dist/config/resolve.d.ts +11 -0
- package/dist/config/resolve.d.ts.map +1 -0
- package/dist/config/resource-resolution.d.ts +80 -0
- package/dist/config/resource-resolution.d.ts.map +1 -0
- package/dist/config/schema-bindings.d.ts +2124 -0
- package/dist/config/schema-bindings.d.ts.map +1 -0
- package/dist/config/schema-build.d.ts +67 -0
- package/dist/config/schema-build.d.ts.map +1 -0
- package/dist/config/schema-env.d.ts +3821 -0
- package/dist/config/schema-env.d.ts.map +1 -0
- package/dist/config/schema-normalization.d.ts +272 -0
- package/dist/config/schema-normalization.d.ts.map +1 -0
- package/dist/config/schema-runtime.d.ts +597 -0
- package/dist/config/schema-runtime.d.ts.map +1 -0
- package/dist/config/schema-types-bindings-platform.d.ts +520 -0
- package/dist/config/schema-types-bindings-platform.d.ts.map +1 -0
- package/dist/config/schema-types-bindings-resources.d.ts +802 -0
- package/dist/config/schema-types-bindings-resources.d.ts.map +1 -0
- package/dist/config/schema-types-bindings.d.ts +293 -0
- package/dist/config/schema-types-bindings.d.ts.map +1 -0
- package/dist/config/schema-types-build.d.ts +86 -0
- package/dist/config/schema-types-build.d.ts.map +1 -0
- package/dist/config/schema-types-runtime-server.d.ts +196 -0
- package/dist/config/schema-types-runtime-server.d.ts.map +1 -0
- package/dist/config/schema-types-runtime.d.ts +913 -0
- package/dist/config/schema-types-runtime.d.ts.map +1 -0
- package/dist/config/schema-types.d.ts +458 -0
- package/dist/config/schema-types.d.ts.map +1 -0
- package/dist/config/schema.d.ts +5796 -2023
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/service-bindings-validation.d.ts +36 -0
- package/dist/config/service-bindings-validation.d.ts.map +1 -0
- package/dist/config/workspace.d.ts +282 -0
- package/dist/config/workspace.d.ts.map +1 -0
- package/dist/config-entry.d.ts +7 -0
- package/dist/config-entry.d.ts.map +1 -0
- package/dist/config-entry.js +3 -0
- package/dist/decorators/durable-object.d.ts.map +1 -1
- package/dist/decorators/index.d.ts +2 -2
- package/dist/decorators/index.js +2 -9
- package/dist/dev-server/d1-migrations.d.ts +36 -0
- package/dist/dev-server/d1-migrations.d.ts.map +1 -0
- package/dist/dev-server/dev-server-state.d.ts +59 -0
- package/dist/dev-server/dev-server-state.d.ts.map +1 -0
- package/dist/dev-server/gateway-script.d.ts +22 -0
- package/dist/dev-server/gateway-script.d.ts.map +1 -0
- package/dist/dev-server/index.d.ts +1 -1
- package/dist/dev-server/miniflare-bindings.d.ts +90 -0
- package/dist/dev-server/miniflare-bindings.d.ts.map +1 -0
- package/dist/dev-server/miniflare-dev-config.d.ts +57 -0
- package/dist/dev-server/miniflare-dev-config.d.ts.map +1 -0
- package/dist/dev-server/miniflare-log.d.ts +20 -0
- package/dist/dev-server/miniflare-log.d.ts.map +1 -0
- package/dist/dev-server/miniflare-worker-config.d.ts +100 -0
- package/dist/dev-server/miniflare-worker-config.d.ts.map +1 -0
- package/dist/dev-server/reload-queue.d.ts +13 -0
- package/dist/dev-server/reload-queue.d.ts.map +1 -0
- package/dist/dev-server/runtime-health.d.ts +79 -0
- package/dist/dev-server/runtime-health.d.ts.map +1 -0
- package/dist/dev-server/runtime-stdio.d.ts +8 -0
- package/dist/dev-server/runtime-stdio.d.ts.map +1 -0
- package/dist/dev-server/server-startup-helpers.d.ts +84 -0
- package/dist/dev-server/server-startup-helpers.d.ts.map +1 -0
- package/dist/dev-server/server.d.ts +2 -0
- package/dist/dev-server/server.d.ts.map +1 -1
- package/dist/dev-server/vite-process.d.ts +24 -0
- package/dist/dev-server/vite-process.d.ts.map +1 -0
- package/dist/dev-server/vite-utils.d.ts +19 -1
- package/dist/dev-server/vite-utils.d.ts.map +1 -1
- package/dist/dev-server/worker-source-watcher.d.ts +17 -0
- package/dist/dev-server/worker-source-watcher.d.ts.map +1 -0
- package/dist/dev-server/worker-surface-paths.d.ts +6 -0
- package/dist/dev-server/worker-surface-paths.d.ts.map +1 -0
- package/dist/dev-server/workspace/merge-config.d.ts +81 -0
- package/dist/dev-server/workspace/merge-config.d.ts.map +1 -0
- package/dist/dev-server/workspace/prepare-app.d.ts +84 -0
- package/dist/dev-server/workspace/prepare-app.d.ts.map +1 -0
- package/dist/dev-server/workspace/server.d.ts +47 -0
- package/dist/dev-server/workspace/server.d.ts.map +1 -0
- package/dist/env.d.ts +10 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/index.d.ts +8 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -297
- package/dist/runtime/context-events.d.ts +13 -0
- package/dist/runtime/context-events.d.ts.map +1 -0
- package/dist/runtime/context-types.d.ts +82 -0
- package/dist/runtime/context-types.d.ts.map +1 -0
- package/dist/runtime/context.d.ts +20 -44
- package/dist/runtime/context.d.ts.map +1 -1
- package/dist/runtime/exports.d.ts +70 -55
- package/dist/runtime/exports.d.ts.map +1 -1
- package/dist/runtime/index.d.ts +11 -5
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +5 -184
- package/dist/runtime/middleware.d.ts +119 -67
- package/dist/runtime/middleware.d.ts.map +1 -1
- package/dist/runtime/r2-presign.d.ts +164 -0
- package/dist/runtime/r2-presign.d.ts.map +1 -0
- package/dist/runtime/router/index.d.ts +7 -0
- package/dist/runtime/router/index.d.ts.map +1 -0
- package/dist/runtime/router/types.d.ts +24 -0
- package/dist/runtime/router/types.d.ts.map +1 -0
- package/dist/runtime/validation.d.ts +18 -4
- package/dist/runtime/validation.d.ts.map +1 -1
- package/dist/secrets/local-secrets.d.ts +46 -0
- package/dist/secrets/local-secrets.d.ts.map +1 -0
- package/dist/shims/local-hyperdrive.d.ts +12 -0
- package/dist/shims/local-hyperdrive.d.ts.map +1 -0
- package/dist/shims/local-media-bindings.d.ts +19 -0
- package/dist/shims/local-media-bindings.d.ts.map +1 -0
- package/dist/shims/local-worker-loader.d.ts +3 -0
- package/dist/shims/local-worker-loader.d.ts.map +1 -0
- package/dist/sveltekit/index.d.ts +1 -1
- package/dist/sveltekit/index.d.ts.map +1 -1
- package/dist/sveltekit/index.js +377 -169
- package/dist/sveltekit/local-bindings.d.ts +4 -0
- package/dist/sveltekit/local-bindings.d.ts.map +1 -0
- package/dist/sveltekit/platform.d.ts +42 -2
- package/dist/sveltekit/platform.d.ts.map +1 -1
- package/dist/test/ai-search.d.ts +39 -0
- package/dist/test/ai-search.d.ts.map +1 -0
- package/dist/test/alarm.d.ts +55 -0
- package/dist/test/alarm.d.ts.map +1 -0
- package/dist/test/binding-hints.d.ts +10 -0
- package/dist/test/binding-hints.d.ts.map +1 -0
- package/dist/test/cf.d.ts +71 -35
- package/dist/test/cf.d.ts.map +1 -1
- package/dist/test/containers.d.ts +87 -0
- package/dist/test/containers.d.ts.map +1 -0
- package/dist/test/email.d.ts +16 -7
- package/dist/test/email.d.ts.map +1 -1
- package/dist/test/index.d.ts +20 -21
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +5115 -75
- package/dist/test/offline-bindings.d.ts +124 -0
- package/dist/test/offline-bindings.d.ts.map +1 -0
- package/dist/test/queue.d.ts.map +1 -1
- package/dist/test/remote-ai.d.ts.map +1 -1
- package/dist/test/remote-cloudflare.d.ts +13 -0
- package/dist/test/remote-cloudflare.d.ts.map +1 -0
- package/dist/test/remote-vectorize.d.ts.map +1 -1
- package/dist/test/resolve-service-bindings.d.ts +64 -4
- package/dist/test/resolve-service-bindings.d.ts.map +1 -1
- package/dist/test/scheduled.d.ts.map +1 -1
- package/dist/test/should-skip.d.ts +14 -18
- package/dist/test/should-skip.d.ts.map +1 -1
- package/dist/test/simple-context-bindings.d.ts +13 -0
- package/dist/test/simple-context-bindings.d.ts.map +1 -0
- package/dist/test/simple-context-durable-objects.d.ts +6 -0
- package/dist/test/simple-context-durable-objects.d.ts.map +1 -0
- package/dist/test/simple-context-env.d.ts +35 -0
- package/dist/test/simple-context-env.d.ts.map +1 -0
- package/dist/test/simple-context-gateway-script.d.ts +2 -0
- package/dist/test/simple-context-gateway-script.d.ts.map +1 -0
- package/dist/test/simple-context-handlers.d.ts +12 -0
- package/dist/test/simple-context-handlers.d.ts.map +1 -0
- package/dist/test/simple-context-lifecycle.d.ts +32 -0
- package/dist/test/simple-context-lifecycle.d.ts.map +1 -0
- package/dist/test/simple-context-mfconfig.d.ts +18 -0
- package/dist/test/simple-context-mfconfig.d.ts.map +1 -0
- package/dist/test/simple-context-multi-worker.d.ts +16 -0
- package/dist/test/simple-context-multi-worker.d.ts.map +1 -0
- package/dist/test/simple-context-paths.d.ts +40 -0
- package/dist/test/simple-context-paths.d.ts.map +1 -0
- package/dist/test/simple-context-runtime.d.ts +19 -0
- package/dist/test/simple-context-runtime.d.ts.map +1 -0
- package/dist/test/simple-context-startup.d.ts +11 -0
- package/dist/test/simple-context-startup.d.ts.map +1 -0
- package/dist/test/simple-context-transport.d.ts +14 -0
- package/dist/test/simple-context-transport.d.ts.map +1 -0
- package/dist/test/simple-context.d.ts +8 -27
- package/dist/test/simple-context.d.ts.map +1 -1
- package/dist/test/tail.d.ts +3 -2
- package/dist/test/tail.d.ts.map +1 -1
- package/dist/test/utilities/analytics-engine.d.ts +22 -0
- package/dist/test/utilities/analytics-engine.d.ts.map +1 -0
- package/dist/test/utilities/artifacts.d.ts +11 -0
- package/dist/test/utilities/artifacts.d.ts.map +1 -0
- package/dist/test/utilities/context.d.ts +39 -0
- package/dist/test/utilities/context.d.ts.map +1 -0
- package/dist/test/utilities/d1.d.ts +21 -0
- package/dist/test/utilities/d1.d.ts.map +1 -0
- package/dist/test/utilities/env.d.ts +45 -0
- package/dist/test/utilities/env.d.ts.map +1 -0
- package/dist/test/utilities/kv.d.ts +11 -0
- package/dist/test/utilities/kv.d.ts.map +1 -0
- package/dist/test/utilities/media.d.ts +16 -0
- package/dist/test/utilities/media.d.ts.map +1 -0
- package/dist/test/utilities/platform.d.ts +41 -0
- package/dist/test/utilities/platform.d.ts.map +1 -0
- package/dist/test/utilities/queue.d.ts +5 -0
- package/dist/test/utilities/queue.d.ts.map +1 -0
- package/dist/test/utilities/r2.d.ts +2 -0
- package/dist/test/utilities/r2.d.ts.map +1 -0
- package/dist/test/utilities/send-email.d.ts +27 -0
- package/dist/test/utilities/send-email.d.ts.map +1 -0
- package/dist/test/utilities/stream-flagship.d.ts +27 -0
- package/dist/test/utilities/stream-flagship.d.ts.map +1 -0
- package/dist/test/utilities/vectorize.d.ts +38 -0
- package/dist/test/utilities/vectorize.d.ts.map +1 -0
- package/dist/test/utilities/workflows.d.ts +26 -0
- package/dist/test/utilities/workflows.d.ts.map +1 -0
- package/dist/test/utilities.d.ts +14 -98
- package/dist/test/utilities.d.ts.map +1 -1
- package/dist/test/worker.d.ts +6 -0
- package/dist/test/worker.d.ts.map +1 -1
- package/dist/transform/durable-object.d.ts.map +1 -1
- package/dist/transform/index.d.ts +2 -2
- package/dist/transform/worker-entrypoint.d.ts +5 -0
- package/dist/transform/worker-entrypoint.d.ts.map +1 -1
- package/dist/utils/entrypoint-discovery.d.ts +6 -3
- package/dist/utils/entrypoint-discovery.d.ts.map +1 -1
- package/dist/utils/glob.d.ts.map +1 -1
- package/dist/utils/resolve-package.d.ts.map +1 -1
- package/dist/utils/send-email.d.ts +15 -0
- package/dist/utils/send-email.d.ts.map +1 -0
- package/dist/utils/send-email.js +163 -0
- package/dist/vite/config-file.d.ts +25 -0
- package/dist/vite/config-file.d.ts.map +1 -0
- package/dist/vite/index.d.ts +3 -2
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +2 -407
- package/dist/vite/plugin-config-hook.d.ts +28 -0
- package/dist/vite/plugin-config-hook.d.ts.map +1 -0
- package/dist/vite/plugin-context.d.ts +27 -0
- package/dist/vite/plugin-context.d.ts.map +1 -0
- package/dist/vite/plugin-durable-objects.d.ts +18 -0
- package/dist/vite/plugin-durable-objects.d.ts.map +1 -0
- package/dist/vite/plugin-programmatic.d.ts +44 -0
- package/dist/vite/plugin-programmatic.d.ts.map +1 -0
- package/dist/vite/plugin-service-bindings.d.ts +13 -0
- package/dist/vite/plugin-service-bindings.d.ts.map +1 -0
- package/dist/vite/plugin-transform.d.ts +41 -0
- package/dist/vite/plugin-transform.d.ts.map +1 -0
- package/dist/vite/plugin.d.ts +10 -41
- package/dist/vite/plugin.d.ts.map +1 -1
- package/dist/worker-entry/composed-worker.d.ts +5 -8
- package/dist/worker-entry/composed-worker.d.ts.map +1 -1
- package/dist/worker-entry/durable-object-discovery.d.ts +20 -0
- package/dist/worker-entry/durable-object-discovery.d.ts.map +1 -0
- package/dist/worker-entry/extensions.d.ts +5 -0
- package/dist/worker-entry/extensions.d.ts.map +1 -0
- package/dist/worker-entry/routes.d.ts +22 -0
- package/dist/worker-entry/routes.d.ts.map +1 -0
- package/dist/worker-entry/surface-paths.d.ts +26 -0
- package/dist/worker-entry/surface-paths.d.ts.map +1 -0
- package/dist/worker-entry/validate-fetch-style.d.ts +12 -0
- package/dist/worker-entry/validate-fetch-style.d.ts.map +1 -0
- package/dist/workflows/local-workflow-entrypoints.d.ts +7 -0
- package/dist/workflows/local-workflow-entrypoints.d.ts.map +1 -0
- package/package.json +160 -117
- package/R2.md +0 -170
- package/dist/account-rvrj687w.js +0 -397
- package/dist/ai-dx4fr9jh.js +0 -107
- package/dist/bridge/protocol.d.ts.map +0 -1
- package/dist/bridge/serialization.d.ts +0 -83
- package/dist/bridge/serialization.d.ts.map +0 -1
- package/dist/browser-shim/worker.d.ts +0 -14
- package/dist/browser-shim/worker.d.ts.map +0 -1
- package/dist/build-9myaxf07.js +0 -70
- package/dist/deploy-h1wz5p7m.js +0 -86
- package/dist/dev-rsdssknb.js +0 -2707
- package/dist/doctor-v7jy4s3r.js +0 -190
- package/dist/durable-object-t4kbb0yt.js +0 -13
- package/dist/index-18hvb6gb.js +0 -194
- package/dist/index-1xpj0m4r.js +0 -57
- package/dist/index-37x76zdn.js +0 -4
- package/dist/index-3t6rypgc.js +0 -13
- package/dist/index-62b3gt2g.js +0 -12
- package/dist/index-67qcae0f.js +0 -183
- package/dist/index-9ats0s83.js +0 -70
- package/dist/index-a0fjkq68.js +0 -198
- package/dist/index-a855bdsx.js +0 -18
- package/dist/index-ccrh4w3t.js +0 -1133
- package/dist/index-d8bdkx2h.js +0 -109
- package/dist/index-f8qh2tyh.js +0 -2152
- package/dist/index-gz1gndna.js +0 -307
- package/dist/index-hcex3rgh.js +0 -266
- package/dist/index-k7r18na8.js +0 -0
- package/dist/index-n3np2d6t.js +0 -462
- package/dist/index-n7rs26ft.js +0 -77
- package/dist/index-npc1c8jx.js +0 -44
- package/dist/index-p7g30wd2.js +0 -281
- package/dist/index-rbht7m9r.js +0 -36
- package/dist/index-tfyxa77h.js +0 -850
- package/dist/index-tk6ej9dj.js +0 -94
- package/dist/index-v8vvsn9x.js +0 -169
- package/dist/index-z14anrqp.js +0 -226
- package/dist/init-f9mgmew3.js +0 -186
- package/dist/remote-q59qk463.js +0 -97
- package/dist/test/bridge-context.d.ts +0 -76
- package/dist/test/bridge-context.d.ts.map +0 -1
- package/dist/test/multi-worker-context.d.ts +0 -114
- package/dist/test/multi-worker-context.d.ts.map +0 -1
- package/dist/types-wdcpnfvy.js +0 -487
- package/dist/worker-entrypoint-m9th0rg0.js +0 -13
|
@@ -0,0 +1,874 @@
|
|
|
1
|
+
import { D as createFetchEvent, b as createContextProxy, n as getContextOrNull, v as runWithEventContext } from "./context-DGMev2AF.js";
|
|
2
|
+
import { AwsV4Signer } from "aws4fetch";
|
|
3
|
+
//#region src/runtime/exports.ts
|
|
4
|
+
/**
|
|
5
|
+
* Creates a readonly proxy that throws on mutation attempts. Thin wrapper
|
|
6
|
+
* over {@link createContextProxy} with `mutable: false`.
|
|
7
|
+
*/
|
|
8
|
+
function createReadonlyProxy(getter, name) {
|
|
9
|
+
return createContextProxy(getter, name, { mutable: false });
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Access environment bindings (KV, D1, R2, etc.) and variables
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* This is readonly - bindings cannot be reassigned at runtime.
|
|
16
|
+
* Available only within an active Devflare-managed handler or middleware call trail.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { env, type FetchEvent } from 'devflare/runtime'
|
|
21
|
+
*
|
|
22
|
+
* export async function fetch(event: FetchEvent) {
|
|
23
|
+
* const value = await env.MY_KV.get('key')
|
|
24
|
+
* const dbResult = await env.DB.prepare('SELECT * FROM users').all()
|
|
25
|
+
* return new Response(JSON.stringify({
|
|
26
|
+
* path: event.url.pathname,
|
|
27
|
+
* value,
|
|
28
|
+
* dbResult
|
|
29
|
+
* }))
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @throws {ContextAccessError} When accessed outside an active Devflare-managed handler trail
|
|
34
|
+
*/
|
|
35
|
+
const env = createReadonlyProxy(() => getContextOrNull()?.env, "env");
|
|
36
|
+
/**
|
|
37
|
+
* Access typed runtime variables declared with `defineConfig({ vars })`.
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* This proxy reads from the active Worker environment object, just like
|
|
41
|
+
* {@link env}, but its type is generated from the `vars` config lane. Nested
|
|
42
|
+
* values are preserved, so `vars.mongo.database` works when config declares a
|
|
43
|
+
* nested object.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { vars } from 'devflare/runtime'
|
|
48
|
+
*
|
|
49
|
+
* export async function fetch() {
|
|
50
|
+
* return Response.json({
|
|
51
|
+
* database: vars.mongo.database
|
|
52
|
+
* })
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @throws {ContextAccessError} When accessed outside an active Devflare-managed handler trail
|
|
57
|
+
*/
|
|
58
|
+
const vars = createReadonlyProxy(() => getContextOrNull()?.env, "vars");
|
|
59
|
+
/**
|
|
60
|
+
* Access the ExecutionContext for background tasks
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* Provides `waitUntil()` for background processing and
|
|
64
|
+
* `passThroughOnException()` for error handling on worker surfaces.
|
|
65
|
+
* When running inside a Durable Object, this proxy exposes the current
|
|
66
|
+
* `DurableObjectState` instead.
|
|
67
|
+
* This is readonly.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* import { ctx, type FetchEvent } from 'devflare/runtime'
|
|
72
|
+
*
|
|
73
|
+
* export async function fetch(event: FetchEvent) {
|
|
74
|
+
* const response = new Response('OK')
|
|
75
|
+
* ctx.waitUntil(analytics.track(event.url.pathname))
|
|
76
|
+
* return response
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @throws {ContextAccessError} When accessed outside an active Devflare-managed handler trail
|
|
81
|
+
*/
|
|
82
|
+
const ctx = createReadonlyProxy(() => getContextOrNull()?.ctx, "ctx");
|
|
83
|
+
/**
|
|
84
|
+
* Access the current event object.
|
|
85
|
+
*
|
|
86
|
+
* @remarks
|
|
87
|
+
* This is the generic event proxy for the active AsyncLocalStorage context.
|
|
88
|
+
*
|
|
89
|
+
* For strong per-surface typing, prefer `getFetchEvent()`, `getQueueEvent()`,
|
|
90
|
+
* `getScheduledEvent()`, `getEmailEvent()`, and the Durable Object getters
|
|
91
|
+
* from `devflare/runtime`.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { event as runtimeEvent, type FetchEvent, type ScheduledEvent } from 'devflare/runtime'
|
|
96
|
+
*
|
|
97
|
+
* export async function fetch(event: FetchEvent) {
|
|
98
|
+
* console.log(runtimeEvent.type)
|
|
99
|
+
* console.log(event.url.pathname)
|
|
100
|
+
* }
|
|
101
|
+
*
|
|
102
|
+
* export async function scheduled(event: ScheduledEvent) {
|
|
103
|
+
* console.log(runtimeEvent.type)
|
|
104
|
+
* console.log(event.cron)
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @throws {ContextAccessError} When accessed outside an active Devflare-managed handler trail
|
|
109
|
+
*/
|
|
110
|
+
const event = createReadonlyProxy(() => getContextOrNull()?.event, "event");
|
|
111
|
+
/**
|
|
112
|
+
* Mutable request-scoped storage for sharing data between middleware
|
|
113
|
+
*
|
|
114
|
+
* @remarks
|
|
115
|
+
* Unlike `env` and `ctx`, locals can be mutated. Each request gets
|
|
116
|
+
* a fresh locals object. Use this for:
|
|
117
|
+
* - Authentication state
|
|
118
|
+
* - Parsed request data
|
|
119
|
+
* - Computed values shared across middleware
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* import { locals, type FetchEvent } from 'devflare/runtime'
|
|
124
|
+
*
|
|
125
|
+
* // In auth middleware
|
|
126
|
+
* const authMiddleware = async (event: FetchEvent, next: () => Promise<Response>) => {
|
|
127
|
+
* locals.user = await validateToken(event.request?.headers.get('Authorization'))
|
|
128
|
+
* return next()
|
|
129
|
+
* }
|
|
130
|
+
*
|
|
131
|
+
* // In handler
|
|
132
|
+
* export async function fetch(event: FetchEvent) {
|
|
133
|
+
* void event
|
|
134
|
+
* console.log(locals.user)
|
|
135
|
+
* }
|
|
136
|
+
* ```
|
|
137
|
+
*
|
|
138
|
+
* @throws {ContextAccessError} When accessed outside an active Devflare-managed handler trail
|
|
139
|
+
*/
|
|
140
|
+
const locals = createContextProxy(() => getContextOrNull()?.locals, "locals");
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/runtime/middleware.ts
|
|
143
|
+
const FETCH_SEQUENCE_SYMBOL = Symbol.for("devflare.fetch-sequence");
|
|
144
|
+
const FETCH_RESOLVE_STYLE_SYMBOL = Symbol.for("devflare.fetch-resolve-style");
|
|
145
|
+
const FETCH_WORKER_STYLE_SYMBOL = Symbol.for("devflare.fetch-worker-style");
|
|
146
|
+
const QUEUE_WORKER_STYLE_SYMBOL = Symbol.for("devflare.queue-worker-style");
|
|
147
|
+
const SCHEDULED_WORKER_STYLE_SYMBOL = Symbol.for("devflare.scheduled-worker-style");
|
|
148
|
+
function createNotFoundResponse() {
|
|
149
|
+
return new Response("Not Found", { status: 404 });
|
|
150
|
+
}
|
|
151
|
+
function isFunction(value) {
|
|
152
|
+
return typeof value === "function";
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Tag a handler as resolve-style: `(event, resolve) => Response`.
|
|
156
|
+
*
|
|
157
|
+
* Attaches `FETCH_RESOLVE_STYLE_SYMBOL` so detection survives minification
|
|
158
|
+
* (which rewrites parameter names and function source output).
|
|
159
|
+
*/
|
|
160
|
+
function markResolveStyle(handler) {
|
|
161
|
+
Object.defineProperty(handler, FETCH_RESOLVE_STYLE_SYMBOL, {
|
|
162
|
+
value: true,
|
|
163
|
+
enumerable: false,
|
|
164
|
+
configurable: true,
|
|
165
|
+
writable: false
|
|
166
|
+
});
|
|
167
|
+
return handler;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Tag a handler as worker-style: `(request, env)` or `(request, env, ctx)`.
|
|
171
|
+
*
|
|
172
|
+
* Required for 2-argument worker-style handlers because devflare can no
|
|
173
|
+
* longer disambiguate `(event, resolve)` vs `(request, env)` from arity
|
|
174
|
+
* alone — the parameter-name fallback was removed in R1-strict.
|
|
175
|
+
*/
|
|
176
|
+
function markWorkerStyle(handler) {
|
|
177
|
+
Object.defineProperty(handler, FETCH_WORKER_STYLE_SYMBOL, {
|
|
178
|
+
value: true,
|
|
179
|
+
enumerable: false,
|
|
180
|
+
configurable: true,
|
|
181
|
+
writable: false
|
|
182
|
+
});
|
|
183
|
+
return handler;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Explicit escape hatch for declaring a handler's calling convention.
|
|
187
|
+
*
|
|
188
|
+
* - `options.style === 'resolve'` marks the handler so it is dispatched as
|
|
189
|
+
* `(event, resolve) => Response`.
|
|
190
|
+
* - `options.style === 'worker'` marks the handler so it is dispatched as
|
|
191
|
+
* `(request, env[, ctx]) => Response`.
|
|
192
|
+
*
|
|
193
|
+
* The marker is required for 2-argument handlers; 1-arg `(event)` and
|
|
194
|
+
* 3-arg `(request, env, ctx)` handlers do not need to be wrapped.
|
|
195
|
+
*/
|
|
196
|
+
function defineFetchHandler(handler, options) {
|
|
197
|
+
if (options?.style === "resolve") return markResolveStyle(handler);
|
|
198
|
+
if (options?.style === "worker") return markWorkerStyle(handler);
|
|
199
|
+
return handler;
|
|
200
|
+
}
|
|
201
|
+
function hasResolveStyleMarker(handler) {
|
|
202
|
+
const record = handler;
|
|
203
|
+
return Boolean(record[FETCH_RESOLVE_STYLE_SYMBOL] || record[FETCH_SEQUENCE_SYMBOL]);
|
|
204
|
+
}
|
|
205
|
+
function hasWorkerStyleMarker(handler) {
|
|
206
|
+
return Boolean(handler[FETCH_WORKER_STYLE_SYMBOL]);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Detect resolve-style `(event, resolve) => Response` handlers.
|
|
210
|
+
*
|
|
211
|
+
* Symbol-based only — the previous parameter-name fallback was removed in
|
|
212
|
+
* R1-strict. Callers that rely on a 2-argument resolve-style handler must
|
|
213
|
+
* wrap it with `markResolveStyle`, `defineFetchHandler({ style: 'resolve' })`,
|
|
214
|
+
* or compose it via `sequence(...)`.
|
|
215
|
+
*/
|
|
216
|
+
function isResolveStyleFunction(handler) {
|
|
217
|
+
return hasResolveStyleMarker(handler);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Throw a clear error for ambiguous unmarked 2-argument fetch handlers.
|
|
221
|
+
*
|
|
222
|
+
* In R1-strict, devflare no longer guesses the calling convention from
|
|
223
|
+
* parameter names. 2-arg handlers must be marked with
|
|
224
|
+
* `defineFetchHandler(fn, { style: 'resolve' | 'worker' })` (or wrapped via
|
|
225
|
+
* `markResolveStyle` / `markWorkerStyle` / `sequence(...)`) so dispatch is
|
|
226
|
+
* unambiguous and minification-safe.
|
|
227
|
+
*/
|
|
228
|
+
function assertExplicit2ArgStyle(handler) {
|
|
229
|
+
if (handler.length !== 2) return;
|
|
230
|
+
if (hasResolveStyleMarker(handler) || hasWorkerStyleMarker(handler)) return;
|
|
231
|
+
throw new Error("[devflare] Ambiguous 2-argument fetch handler. The calling convention must be declared explicitly via `defineFetchHandler(fn, { style: 'resolve' })` (for `(event, resolve) => Response`) or `defineFetchHandler(fn, { style: 'worker' })` (for `(request, env) => Response`). Single-arg `(event) => Response` and 3-arg worker-style `(request, env, ctx) => Response` handlers do not require wrapping.");
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Tag a queue handler as worker-style: `(batch, env)` or `(batch, env, ctx)`.
|
|
235
|
+
*
|
|
236
|
+
* Required for 2-argument worker-style queue handlers because devflare can
|
|
237
|
+
* no longer disambiguate `(event)` vs `(batch, env)` from arity alone in
|
|
238
|
+
* R1-strict.
|
|
239
|
+
*/
|
|
240
|
+
function defineQueueHandler(handler) {
|
|
241
|
+
Object.defineProperty(handler, QUEUE_WORKER_STYLE_SYMBOL, {
|
|
242
|
+
value: true,
|
|
243
|
+
enumerable: false,
|
|
244
|
+
configurable: true,
|
|
245
|
+
writable: false
|
|
246
|
+
});
|
|
247
|
+
return handler;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Tag a scheduled handler as worker-style: `(controller, env)` or
|
|
251
|
+
* `(controller, env, ctx)`.
|
|
252
|
+
*/
|
|
253
|
+
function defineScheduledHandler(handler) {
|
|
254
|
+
Object.defineProperty(handler, SCHEDULED_WORKER_STYLE_SYMBOL, {
|
|
255
|
+
value: true,
|
|
256
|
+
enumerable: false,
|
|
257
|
+
configurable: true,
|
|
258
|
+
writable: false
|
|
259
|
+
});
|
|
260
|
+
return handler;
|
|
261
|
+
}
|
|
262
|
+
function hasQueueWorkerStyleMarker(handler) {
|
|
263
|
+
return Boolean(handler[QUEUE_WORKER_STYLE_SYMBOL]);
|
|
264
|
+
}
|
|
265
|
+
function hasScheduledWorkerStyleMarker(handler) {
|
|
266
|
+
return Boolean(handler[SCHEDULED_WORKER_STYLE_SYMBOL]);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Throw a clear error for ambiguous unmarked 2-argument queue handlers.
|
|
270
|
+
*
|
|
271
|
+
* Mirrors `assertExplicit2ArgStyle` for the queue surface. 2-arg handlers
|
|
272
|
+
* must be wrapped with `defineQueueHandler(fn)` so dispatch is unambiguous
|
|
273
|
+
* and minification-safe; 1-arg `(event)` and 3-arg `(batch, env, ctx)` do
|
|
274
|
+
* not require wrapping.
|
|
275
|
+
*/
|
|
276
|
+
function assertExplicitQueueHandlerStyle(handler) {
|
|
277
|
+
if (handler.length !== 2) return;
|
|
278
|
+
if (hasQueueWorkerStyleMarker(handler)) return;
|
|
279
|
+
throw new Error("[devflare] Ambiguous 2-argument queue handler. The calling convention must be declared explicitly via `defineQueueHandler(fn)` for `(batch, env) => void` worker-style handlers. Single-arg `(event) => void` and 3-arg `(batch, env, ctx) => void` handlers do not require wrapping.");
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Throw a clear error for ambiguous unmarked 2-argument scheduled handlers.
|
|
283
|
+
*/
|
|
284
|
+
function assertExplicitScheduledHandlerStyle(handler) {
|
|
285
|
+
if (handler.length !== 2) return;
|
|
286
|
+
if (hasScheduledWorkerStyleMarker(handler)) return;
|
|
287
|
+
throw new Error("[devflare] Ambiguous 2-argument scheduled handler. The calling convention must be declared explicitly via `defineScheduledHandler(fn)` for `(controller, env) => void` worker-style handlers. Single-arg `(event) => void` and 3-arg `(controller, env, ctx) => void` handlers do not require wrapping.");
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Detect Cloudflare Worker-style `fetch(request, env[, ctx])` handlers.
|
|
291
|
+
*
|
|
292
|
+
* Returns true when:
|
|
293
|
+
* - arity is `>= 3` (unambiguous worker signature), or
|
|
294
|
+
* - the handler is explicitly marked worker-style via `markWorkerStyle` or
|
|
295
|
+
* `defineFetchHandler({ style: 'worker' })`.
|
|
296
|
+
*
|
|
297
|
+
* In R1-strict, 2-argument worker-style handlers must be marked — there is
|
|
298
|
+
* no parameter-name fallback. Unmarked 2-arg handlers throw via
|
|
299
|
+
* `assertExplicit2ArgStyle` when invoked.
|
|
300
|
+
*/
|
|
301
|
+
function isWorkerStyleFetchFunction(handler) {
|
|
302
|
+
if (isResolveStyleFunction(handler)) return false;
|
|
303
|
+
if (handler.length >= 3) return true;
|
|
304
|
+
return hasWorkerStyleMarker(handler);
|
|
305
|
+
}
|
|
306
|
+
function invokeWorkerStyleFetchFunction(handler, event) {
|
|
307
|
+
return handler(event.request, event.env, event.ctx);
|
|
308
|
+
}
|
|
309
|
+
function bindMethod(target, key) {
|
|
310
|
+
if (!target || typeof target !== "object") return null;
|
|
311
|
+
const value = target[key];
|
|
312
|
+
if (!isFunction(value)) return null;
|
|
313
|
+
const boundHandler = value.bind(target);
|
|
314
|
+
if (isResolveStyleFunction(value)) markResolveStyle(boundHandler);
|
|
315
|
+
if (hasWorkerStyleMarker(value)) markWorkerStyle(boundHandler);
|
|
316
|
+
return boundHandler;
|
|
317
|
+
}
|
|
318
|
+
function createFetchSequence(middlewares) {
|
|
319
|
+
return async (event, resolve = async () => createNotFoundResponse()) => {
|
|
320
|
+
const executeMiddleware = async (index, activeEvent) => {
|
|
321
|
+
if (index >= middlewares.length) return resolve(activeEvent);
|
|
322
|
+
const middleware = middlewares[index];
|
|
323
|
+
return middleware(activeEvent, async (nextEvent = activeEvent) => {
|
|
324
|
+
return executeMiddleware(index + 1, nextEvent);
|
|
325
|
+
});
|
|
326
|
+
};
|
|
327
|
+
return executeMiddleware(0, event);
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Compose request-wide middleware into a single fetch surface.
|
|
332
|
+
*/
|
|
333
|
+
function sequence(...middlewares) {
|
|
334
|
+
const composed = createFetchSequence(middlewares);
|
|
335
|
+
Object.defineProperty(composed, FETCH_SEQUENCE_SYMBOL, {
|
|
336
|
+
value: true,
|
|
337
|
+
enumerable: false,
|
|
338
|
+
configurable: false,
|
|
339
|
+
writable: false
|
|
340
|
+
});
|
|
341
|
+
return markResolveStyle(composed);
|
|
342
|
+
}
|
|
343
|
+
function getDefaultHandleHandler(module) {
|
|
344
|
+
return bindMethod(module.default, "handle");
|
|
345
|
+
}
|
|
346
|
+
function getDefaultFetchHandler(module) {
|
|
347
|
+
const defaultExport = module.default;
|
|
348
|
+
if (isFunction(defaultExport)) return defaultExport;
|
|
349
|
+
return bindMethod(defaultExport, "fetch");
|
|
350
|
+
}
|
|
351
|
+
function getPrimaryFetchEntryCandidates(module) {
|
|
352
|
+
const candidates = [];
|
|
353
|
+
const namedHandle = isFunction(module.handle) ? module.handle : null;
|
|
354
|
+
if (namedHandle) candidates.push({
|
|
355
|
+
name: "handle",
|
|
356
|
+
handler: namedHandle
|
|
357
|
+
});
|
|
358
|
+
const namedFetch = isFunction(module.fetch) ? module.fetch : null;
|
|
359
|
+
if (namedFetch) candidates.push({
|
|
360
|
+
name: "fetch",
|
|
361
|
+
handler: namedFetch
|
|
362
|
+
});
|
|
363
|
+
const defaultHandle = getDefaultHandleHandler(module);
|
|
364
|
+
if (defaultHandle) candidates.push({
|
|
365
|
+
name: "default.handle",
|
|
366
|
+
handler: defaultHandle
|
|
367
|
+
});
|
|
368
|
+
const defaultFetch = getDefaultFetchHandler(module);
|
|
369
|
+
if (defaultFetch) candidates.push({
|
|
370
|
+
name: isFunction(module.default) ? "default" : "default.fetch",
|
|
371
|
+
handler: defaultFetch
|
|
372
|
+
});
|
|
373
|
+
return candidates;
|
|
374
|
+
}
|
|
375
|
+
function assertSinglePrimaryFetchEntry(candidates) {
|
|
376
|
+
if (candidates.length <= 1) return;
|
|
377
|
+
const foundEntries = candidates.map(({ name }) => `"${name}"`).join(", ");
|
|
378
|
+
throw new Error(`Ambiguous fetch entry module. Export exactly one primary fetch entry per module. Use either "fetch" or "handle" (or one default equivalent), not both. Found: ${foundEntries}`);
|
|
379
|
+
}
|
|
380
|
+
function resolveMethodHandler(module, method) {
|
|
381
|
+
const normalizedMethod = method.toUpperCase();
|
|
382
|
+
const directHandler = isFunction(module[normalizedMethod]) ? module[normalizedMethod] : bindMethod(module.default, normalizedMethod);
|
|
383
|
+
if (directHandler) return {
|
|
384
|
+
handler: directHandler,
|
|
385
|
+
stripBody: false
|
|
386
|
+
};
|
|
387
|
+
if (normalizedMethod === "HEAD") {
|
|
388
|
+
const getHandler = isFunction(module.GET) ? module.GET : bindMethod(module.default, "GET");
|
|
389
|
+
if (getHandler) return {
|
|
390
|
+
handler: getHandler,
|
|
391
|
+
stripBody: true
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
const allHandler = isFunction(module.ALL) ? module.ALL : bindMethod(module.default, "ALL");
|
|
395
|
+
if (allHandler) return {
|
|
396
|
+
handler: allHandler,
|
|
397
|
+
stripBody: false
|
|
398
|
+
};
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
async function invokeResolvedFetchHandler(handler, event) {
|
|
402
|
+
if (isResolveStyleFunction(handler)) return handler(event, async () => createNotFoundResponse());
|
|
403
|
+
if (isWorkerStyleFetchFunction(handler)) return invokeWorkerStyleFetchFunction(handler, event);
|
|
404
|
+
assertExplicit2ArgStyle(handler);
|
|
405
|
+
return handler(event);
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Resolve the primary fetch surface for a module.
|
|
409
|
+
*
|
|
410
|
+
* `fetch` and `handle` are treated as aliases for the same primary fetch
|
|
411
|
+
* entry. Exporting more than one primary entry from the same module is
|
|
412
|
+
* rejected as ambiguous.
|
|
413
|
+
*/
|
|
414
|
+
function resolveFetchHandler(module) {
|
|
415
|
+
const candidates = getPrimaryFetchEntryCandidates(module);
|
|
416
|
+
assertSinglePrimaryFetchEntry(candidates);
|
|
417
|
+
return candidates[0]?.handler ?? null;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Invoke a fetch entry handler with the supported calling conventions.
|
|
421
|
+
*
|
|
422
|
+
* This supports:
|
|
423
|
+
* - `fetch(request)`
|
|
424
|
+
* - `fetch(request, env)`
|
|
425
|
+
* - `fetch(request, env, ctx)`
|
|
426
|
+
* - `fetch(event)`
|
|
427
|
+
* - `fetch(event, resolve)` / `handle(event, resolve)`
|
|
428
|
+
*/
|
|
429
|
+
async function invokeFetchHandler(handler, event, resolve = async () => createNotFoundResponse()) {
|
|
430
|
+
if (!isFunction(handler)) return resolve(event);
|
|
431
|
+
if (isResolveStyleFunction(handler)) return await handler(event, resolve) ?? createNotFoundResponse();
|
|
432
|
+
if (isWorkerStyleFetchFunction(handler)) return await invokeWorkerStyleFetchFunction(handler, event) ?? createNotFoundResponse();
|
|
433
|
+
assertExplicit2ArgStyle(handler);
|
|
434
|
+
return await handler(event) ?? createNotFoundResponse();
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Create a SvelteKit-style `resolve(event)` callback for a fetch module.
|
|
438
|
+
*
|
|
439
|
+
* Resolution order is:
|
|
440
|
+
* - matching HTTP method export such as `GET()` / `POST()` / `ALL()`
|
|
441
|
+
* - 404 response
|
|
442
|
+
*/
|
|
443
|
+
function createResolveFetch(module, _currentEntry, initialEvent, options = {}) {
|
|
444
|
+
return async (nextEvent = initialEvent) => {
|
|
445
|
+
return runWithEventContext(nextEvent, async () => {
|
|
446
|
+
const methodResolution = resolveMethodHandler(module, nextEvent.request.method);
|
|
447
|
+
if (methodResolution) {
|
|
448
|
+
const finalResponse = await invokeResolvedFetchHandler(methodResolution.handler, nextEvent) ?? createNotFoundResponse();
|
|
449
|
+
if (methodResolution.stripBody) return new Response(null, finalResponse);
|
|
450
|
+
return finalResponse;
|
|
451
|
+
}
|
|
452
|
+
if (options.fallbackResolve) return options.fallbackResolve(nextEvent);
|
|
453
|
+
return createNotFoundResponse();
|
|
454
|
+
});
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Invoke the resolved fetch surface for a module.
|
|
459
|
+
*
|
|
460
|
+
* This lets runtime wrappers support a single request-wide `handle` or
|
|
461
|
+
* `fetch` export, default exports, and same-module method handlers such as
|
|
462
|
+
* `GET()`.
|
|
463
|
+
*/
|
|
464
|
+
async function invokeFetchModule(module, event, fallbackResolve) {
|
|
465
|
+
const handler = resolveFetchHandler(module);
|
|
466
|
+
if (!handler) return createResolveFetch(module, null, event, { fallbackResolve })(event);
|
|
467
|
+
return invokeFetchHandler(handler, event, createResolveFetch(module, handler, event, { fallbackResolve }));
|
|
468
|
+
}
|
|
469
|
+
//#endregion
|
|
470
|
+
//#region src/runtime/router/index.ts
|
|
471
|
+
function normalizePathname(pathname) {
|
|
472
|
+
if (!pathname || pathname === "/") return "/";
|
|
473
|
+
const trimmed = (pathname.startsWith("/") ? pathname : `/${pathname}`).replace(/\/+$|\/+$/g, "");
|
|
474
|
+
return trimmed === "" ? "/" : trimmed;
|
|
475
|
+
}
|
|
476
|
+
function decodePathSegment(segment) {
|
|
477
|
+
try {
|
|
478
|
+
return decodeURIComponent(segment);
|
|
479
|
+
} catch {
|
|
480
|
+
return segment;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
function getPathSegments(pathname) {
|
|
484
|
+
const normalizedPathname = normalizePathname(pathname);
|
|
485
|
+
if (normalizedPathname === "/") return [];
|
|
486
|
+
return normalizedPathname.slice(1).split("/").filter(Boolean).map(decodePathSegment);
|
|
487
|
+
}
|
|
488
|
+
function getMatchPathname(input) {
|
|
489
|
+
if (input instanceof Request) return new URL(input.url).pathname;
|
|
490
|
+
if (input instanceof URL) return input.pathname;
|
|
491
|
+
if (input.includes("://")) return new URL(input).pathname;
|
|
492
|
+
return input;
|
|
493
|
+
}
|
|
494
|
+
function matchRouteSegments(routeSegments, pathnameSegments) {
|
|
495
|
+
if (routeSegments.length === 0) return pathnameSegments.length === 0 ? {} : null;
|
|
496
|
+
const params = {};
|
|
497
|
+
let routeIndex = 0;
|
|
498
|
+
let pathIndex = 0;
|
|
499
|
+
while (routeIndex < routeSegments.length) {
|
|
500
|
+
const routeSegment = routeSegments[routeIndex];
|
|
501
|
+
if (routeSegment.type === "optional-rest") {
|
|
502
|
+
params[routeSegment.name] = pathnameSegments.slice(pathIndex).join("/");
|
|
503
|
+
pathIndex = pathnameSegments.length;
|
|
504
|
+
routeIndex += 1;
|
|
505
|
+
continue;
|
|
506
|
+
}
|
|
507
|
+
if (routeSegment.type === "rest") {
|
|
508
|
+
if (pathIndex >= pathnameSegments.length) return null;
|
|
509
|
+
params[routeSegment.name] = pathnameSegments.slice(pathIndex).join("/");
|
|
510
|
+
pathIndex = pathnameSegments.length;
|
|
511
|
+
routeIndex += 1;
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
const pathnameSegment = pathnameSegments[pathIndex];
|
|
515
|
+
if (pathnameSegment === void 0) return null;
|
|
516
|
+
if (routeSegment.type === "static") {
|
|
517
|
+
if (pathnameSegment !== routeSegment.value) return null;
|
|
518
|
+
} else params[routeSegment.name] = pathnameSegment;
|
|
519
|
+
pathIndex += 1;
|
|
520
|
+
routeIndex += 1;
|
|
521
|
+
}
|
|
522
|
+
if (pathIndex !== pathnameSegments.length) return null;
|
|
523
|
+
return params;
|
|
524
|
+
}
|
|
525
|
+
function matchFetchRoute(routes, input) {
|
|
526
|
+
const pathnameSegments = getPathSegments(getMatchPathname(input));
|
|
527
|
+
for (const route of routes) {
|
|
528
|
+
const params = matchRouteSegments(route.segments, pathnameSegments);
|
|
529
|
+
if (params) return {
|
|
530
|
+
route,
|
|
531
|
+
params
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
return null;
|
|
535
|
+
}
|
|
536
|
+
async function invokeRouteModules(routes, event) {
|
|
537
|
+
const match = matchFetchRoute(routes, event.request);
|
|
538
|
+
if (!match) return new Response("Not Found", { status: 404 });
|
|
539
|
+
const routeEvent = createFetchEvent(event.request, event.env, event.ctx, {
|
|
540
|
+
params: match.params,
|
|
541
|
+
locals: event.locals
|
|
542
|
+
});
|
|
543
|
+
return runWithEventContext(routeEvent, () => invokeFetchModule(match.route.module, routeEvent));
|
|
544
|
+
}
|
|
545
|
+
function createRouteResolve(routes, initialEvent) {
|
|
546
|
+
return async (nextEvent = initialEvent) => {
|
|
547
|
+
return invokeRouteModules(routes, nextEvent);
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
//#endregion
|
|
551
|
+
//#region src/runtime/r2-presign.ts
|
|
552
|
+
/** URL path prefix of the local presign endpoint served by devflare gateways. */
|
|
553
|
+
const R2_PRESIGN_LOCAL_PATH_PREFIX = "/_devflare/r2/presigned/";
|
|
554
|
+
/** Version tag prepended to the local canonical string (breaks old URLs on format changes). */
|
|
555
|
+
const LOCAL_CANONICAL_VERSION = "devflare:r2-presign:v1";
|
|
556
|
+
/** Env/var names devflare injects in local dev + tests to enable local presigning. */
|
|
557
|
+
const R2_PRESIGN_SECRET_VAR = "DEVFLARE_R2_PRESIGN_SECRET";
|
|
558
|
+
const R2_PRESIGN_ORIGIN_VAR = "DEVFLARE_R2_PRESIGN_ORIGIN";
|
|
559
|
+
/** Var (injected at deploy compile time) mapping R2 binding names to bucket metadata. */
|
|
560
|
+
const R2_BUCKETS_VAR = "DEVFLARE_R2_BUCKETS";
|
|
561
|
+
/** Default env/secret names for R2 S3 API credentials in production. */
|
|
562
|
+
const R2_ACCOUNT_ID_VAR = "R2_ACCOUNT_ID";
|
|
563
|
+
const R2_ACCESS_KEY_ID_VAR = "R2_ACCESS_KEY_ID";
|
|
564
|
+
const R2_SECRET_ACCESS_KEY_VAR = "R2_SECRET_ACCESS_KEY";
|
|
565
|
+
/** Maximum expiry accepted by S3-style presigned URLs (7 days, in seconds). */
|
|
566
|
+
const MAX_EXPIRES_IN_SECONDS = 10080 * 60;
|
|
567
|
+
/** Default presigned URL lifetime (15 minutes, in seconds). */
|
|
568
|
+
const DEFAULT_EXPIRES_IN_SECONDS = 900;
|
|
569
|
+
/**
|
|
570
|
+
* Read a string value by name from the platform `env`, falling back to
|
|
571
|
+
* `process.env`. Handles dev-mode env proxies gracefully: any non-string
|
|
572
|
+
* (e.g. a bridge binding proxy) is treated as absent.
|
|
573
|
+
*/
|
|
574
|
+
function readEnvString(env, name) {
|
|
575
|
+
let own;
|
|
576
|
+
try {
|
|
577
|
+
own = env?.[name];
|
|
578
|
+
} catch {
|
|
579
|
+
own = void 0;
|
|
580
|
+
}
|
|
581
|
+
if (typeof own === "string" && own.length > 0) return own;
|
|
582
|
+
const fromProcess = (globalThis.process?.env)?.[name];
|
|
583
|
+
return typeof fromProcess === "string" && fromProcess.length > 0 ? fromProcess : void 0;
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Resolve the local presign context (origin + secret) injected by devflare in
|
|
587
|
+
* dev/test. Returns `null` outside devflare-managed local environments.
|
|
588
|
+
*/
|
|
589
|
+
function resolveLocalContext(env) {
|
|
590
|
+
const secret = readEnvString(env, R2_PRESIGN_SECRET_VAR);
|
|
591
|
+
const origin = readEnvString(env, R2_PRESIGN_ORIGIN_VAR);
|
|
592
|
+
if (!secret || !origin) return null;
|
|
593
|
+
return {
|
|
594
|
+
origin: origin.replace(/\/$/, ""),
|
|
595
|
+
secret
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* Parse the injected `DEVFLARE_R2_BUCKETS` mapping from `env`. Accepts either
|
|
600
|
+
* a JSON string var or an already-parsed object (wrangler JSON vars).
|
|
601
|
+
*/
|
|
602
|
+
function readBucketsVar(env) {
|
|
603
|
+
let raw;
|
|
604
|
+
try {
|
|
605
|
+
raw = env?.[R2_BUCKETS_VAR];
|
|
606
|
+
} catch {
|
|
607
|
+
return null;
|
|
608
|
+
}
|
|
609
|
+
if (raw === void 0 || raw === null) raw = (globalThis.process?.env)?.[R2_BUCKETS_VAR];
|
|
610
|
+
if (typeof raw === "string") try {
|
|
611
|
+
raw = JSON.parse(raw);
|
|
612
|
+
} catch {
|
|
613
|
+
return null;
|
|
614
|
+
}
|
|
615
|
+
if (!raw || typeof raw !== "object") return null;
|
|
616
|
+
const entries = {};
|
|
617
|
+
for (const [binding, value] of Object.entries(raw)) {
|
|
618
|
+
if (!value || typeof value !== "object") continue;
|
|
619
|
+
const bucketName = value.bucketName;
|
|
620
|
+
if (typeof bucketName !== "string" || bucketName.length === 0) continue;
|
|
621
|
+
const jurisdiction = value.jurisdiction;
|
|
622
|
+
entries[binding] = {
|
|
623
|
+
bucketName,
|
|
624
|
+
...typeof jurisdiction === "string" && jurisdiction.length > 0 && { jurisdiction }
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
return entries;
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Validate the binding/key/options tuple shared by PUT and GET presigning.
|
|
631
|
+
* Returns the effective expiry in seconds.
|
|
632
|
+
*
|
|
633
|
+
* @throws {RangeError} on out-of-range `expiresIn`, `contentLength` or `maxSizeBytes`.
|
|
634
|
+
* @throws {TypeError} on an empty binding or key.
|
|
635
|
+
*/
|
|
636
|
+
function validateCommonInputs(binding, key, options) {
|
|
637
|
+
if (typeof binding !== "string" || binding.length === 0) throw new TypeError("[devflare] presignR2*: `binding` must be a non-empty R2 binding name.");
|
|
638
|
+
if (typeof key !== "string" || key.length === 0) throw new TypeError("[devflare] presignR2*: `key` must be a non-empty object key.");
|
|
639
|
+
if (key.startsWith("/")) throw new TypeError("[devflare] presignR2*: `key` must not start with \"/\".");
|
|
640
|
+
const controlChars = /[\u0000-\u001f\u007f]/;
|
|
641
|
+
if (controlChars.test(key) || controlChars.test(binding)) throw new TypeError("[devflare] presignR2*: `binding`/`key` must not contain control characters.");
|
|
642
|
+
const expiresIn = options.expiresIn ?? DEFAULT_EXPIRES_IN_SECONDS;
|
|
643
|
+
if (!Number.isInteger(expiresIn) || expiresIn < 1 || expiresIn > MAX_EXPIRES_IN_SECONDS) throw new RangeError(`[devflare] presignR2*: \`expiresIn\` must be an integer between 1 and ${MAX_EXPIRES_IN_SECONDS} seconds (got ${expiresIn}).`);
|
|
644
|
+
if (options.contentLength !== void 0) {
|
|
645
|
+
if (!Number.isInteger(options.contentLength) || options.contentLength < 0) throw new RangeError("[devflare] presignR2Put: `contentLength` must be a non-negative integer byte count.");
|
|
646
|
+
}
|
|
647
|
+
if (options.maxSizeBytes !== void 0) {
|
|
648
|
+
if (!Number.isInteger(options.maxSizeBytes) || options.maxSizeBytes < 1) throw new RangeError("[devflare] presignR2Put: `maxSizeBytes` must be a positive integer byte count.");
|
|
649
|
+
}
|
|
650
|
+
if (options.contentLength !== void 0 && options.maxSizeBytes !== void 0 && options.contentLength > options.maxSizeBytes) throw new RangeError(`[devflare] presignR2Put: \`contentLength\` (${options.contentLength}) exceeds \`maxSizeBytes\` (${options.maxSizeBytes}).`);
|
|
651
|
+
return expiresIn;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Percent-encode an object key for use in a URL path, RFC 3986-strict
|
|
655
|
+
* (S3 canonical-URI compatible), preserving `/` as the segment separator.
|
|
656
|
+
*/
|
|
657
|
+
function encodeKeyPath(key) {
|
|
658
|
+
return key.split("/").map((segment) => encodeURIComponent(segment).replace(/[!'()*]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`)).join("/");
|
|
659
|
+
}
|
|
660
|
+
/** Compute a lowercase hex HMAC-SHA256 of `message` with `secret` via WebCrypto. */
|
|
661
|
+
async function hmacSha256Hex(secret, message) {
|
|
662
|
+
const encoder = new TextEncoder();
|
|
663
|
+
const cryptoKey = await crypto.subtle.importKey("raw", encoder.encode(secret), {
|
|
664
|
+
name: "HMAC",
|
|
665
|
+
hash: "SHA-256"
|
|
666
|
+
}, false, ["sign"]);
|
|
667
|
+
const signature = await crypto.subtle.sign("HMAC", cryptoKey, encoder.encode(message));
|
|
668
|
+
return [...new Uint8Array(signature)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
* Build the canonical string covered by the local signature. MUST match
|
|
672
|
+
* `buildCanonicalString` in `src/bridge/r2-presign-runtime.ts` byte-for-byte.
|
|
673
|
+
*/
|
|
674
|
+
function buildLocalCanonicalString(input) {
|
|
675
|
+
return [
|
|
676
|
+
LOCAL_CANONICAL_VERSION,
|
|
677
|
+
input.method,
|
|
678
|
+
input.binding,
|
|
679
|
+
input.key,
|
|
680
|
+
String(input.expires),
|
|
681
|
+
input.contentType ?? "",
|
|
682
|
+
input.contentLength !== void 0 ? String(input.contentLength) : "",
|
|
683
|
+
input.maxSizeBytes !== void 0 ? String(input.maxSizeBytes) : ""
|
|
684
|
+
].join("\n");
|
|
685
|
+
}
|
|
686
|
+
/** Mint a signed URL against the devflare gateway's local presign endpoint. */
|
|
687
|
+
async function presignLocal(input) {
|
|
688
|
+
const expires = Math.floor(Date.now() / 1e3) + input.expiresIn;
|
|
689
|
+
const signature = await hmacSha256Hex(input.secret, buildLocalCanonicalString({
|
|
690
|
+
method: input.method,
|
|
691
|
+
binding: input.binding,
|
|
692
|
+
key: input.key,
|
|
693
|
+
expires,
|
|
694
|
+
contentType: input.contentType,
|
|
695
|
+
contentLength: input.contentLength,
|
|
696
|
+
maxSizeBytes: input.maxSizeBytes
|
|
697
|
+
}));
|
|
698
|
+
const url = new URL(`${input.origin}${R2_PRESIGN_LOCAL_PATH_PREFIX}${encodeURIComponent(input.binding)}/${encodeKeyPath(input.key)}`);
|
|
699
|
+
url.searchParams.set("X-Devflare-Method", input.method);
|
|
700
|
+
url.searchParams.set("X-Devflare-Expires", String(expires));
|
|
701
|
+
if (input.contentType !== void 0) url.searchParams.set("X-Devflare-Content-Type", input.contentType);
|
|
702
|
+
if (input.contentLength !== void 0) url.searchParams.set("X-Devflare-Content-Length", String(input.contentLength));
|
|
703
|
+
if (input.maxSizeBytes !== void 0) url.searchParams.set("X-Devflare-Max-Size", String(input.maxSizeBytes));
|
|
704
|
+
url.searchParams.set("X-Devflare-Signature", signature);
|
|
705
|
+
return {
|
|
706
|
+
url: url.toString(),
|
|
707
|
+
method: input.method,
|
|
708
|
+
headers: input.contentType !== void 0 ? { "content-type": input.contentType } : {},
|
|
709
|
+
expiresAt: /* @__PURE__ */ new Date(expires * 1e3),
|
|
710
|
+
key: input.key,
|
|
711
|
+
mode: "local"
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* Resolve production credentials from options or env.
|
|
716
|
+
*
|
|
717
|
+
* @throws {Error} naming exactly which credential values are missing.
|
|
718
|
+
*/
|
|
719
|
+
function resolveCredentials(env, options) {
|
|
720
|
+
if (options.credentials) return options.credentials;
|
|
721
|
+
const accountId = readEnvString(env, R2_ACCOUNT_ID_VAR);
|
|
722
|
+
const accessKeyId = readEnvString(env, R2_ACCESS_KEY_ID_VAR);
|
|
723
|
+
const secretAccessKey = readEnvString(env, R2_SECRET_ACCESS_KEY_VAR);
|
|
724
|
+
if (accountId && accessKeyId && secretAccessKey) return {
|
|
725
|
+
accountId,
|
|
726
|
+
accessKeyId,
|
|
727
|
+
secretAccessKey
|
|
728
|
+
};
|
|
729
|
+
const missing = [
|
|
730
|
+
!accountId && "R2_ACCOUNT_ID",
|
|
731
|
+
!accessKeyId && "R2_ACCESS_KEY_ID",
|
|
732
|
+
!secretAccessKey && "R2_SECRET_ACCESS_KEY"
|
|
733
|
+
].filter(Boolean);
|
|
734
|
+
throw new Error(`[devflare] presignR2*: missing R2 S3 credentials (${missing.join(", ")}). Provide them as Worker secrets (\`wrangler secret put <NAME>\`) or pass \`options.credentials\`. Create R2 S3 credentials under Cloudflare Dashboard → R2 → Manage R2 API Tokens. In devflare local dev no credentials are needed — this error usually means the code runs in production without the secrets set.`);
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* Resolve the production bucket for a binding from options or the injected
|
|
738
|
+
* `DEVFLARE_R2_BUCKETS` mapping.
|
|
739
|
+
*
|
|
740
|
+
* @throws {Error} when the bucket cannot be resolved.
|
|
741
|
+
*/
|
|
742
|
+
function resolveBucket(env, binding, options) {
|
|
743
|
+
if (options.bucketName) return {
|
|
744
|
+
bucketName: options.bucketName,
|
|
745
|
+
...options.jurisdiction && { jurisdiction: options.jurisdiction }
|
|
746
|
+
};
|
|
747
|
+
const entry = readBucketsVar(env)?.[binding];
|
|
748
|
+
if (entry) return {
|
|
749
|
+
bucketName: entry.bucketName,
|
|
750
|
+
...(options.jurisdiction ?? entry.jurisdiction) && { jurisdiction: options.jurisdiction ?? entry.jurisdiction }
|
|
751
|
+
};
|
|
752
|
+
throw new Error(`[devflare] presignR2*: cannot resolve the bucket name for binding '${binding}'. Deploy through devflare (which injects the ${R2_BUCKETS_VAR} var from \`bindings.r2\`) or pass \`options.bucketName\` explicitly.`);
|
|
753
|
+
}
|
|
754
|
+
/** Mint a real S3 SigV4 presigned URL against the R2 S3 endpoint. */
|
|
755
|
+
async function presignRemote(input) {
|
|
756
|
+
const jurisdictionHost = input.bucket.jurisdiction ? `.${input.bucket.jurisdiction}` : "";
|
|
757
|
+
const endpoint = new URL(`https://${input.credentials.accountId}${jurisdictionHost}.r2.cloudflarestorage.com/${input.bucket.bucketName}/${encodeKeyPath(input.key)}`);
|
|
758
|
+
endpoint.searchParams.set("X-Amz-Expires", String(input.expiresIn));
|
|
759
|
+
const signedHeaders = {};
|
|
760
|
+
if (input.contentType !== void 0) signedHeaders["content-type"] = input.contentType;
|
|
761
|
+
if (input.contentLength !== void 0) signedHeaders["content-length"] = String(input.contentLength);
|
|
762
|
+
return {
|
|
763
|
+
url: (await new AwsV4Signer({
|
|
764
|
+
url: endpoint.toString(),
|
|
765
|
+
method: input.method,
|
|
766
|
+
accessKeyId: input.credentials.accessKeyId,
|
|
767
|
+
secretAccessKey: input.credentials.secretAccessKey,
|
|
768
|
+
region: "auto",
|
|
769
|
+
service: "s3",
|
|
770
|
+
signQuery: true,
|
|
771
|
+
allHeaders: true,
|
|
772
|
+
headers: signedHeaders
|
|
773
|
+
}).sign()).url.toString(),
|
|
774
|
+
method: input.method,
|
|
775
|
+
headers: input.contentType !== void 0 ? { "content-type": input.contentType } : {},
|
|
776
|
+
expiresAt: new Date(Date.now() + input.expiresIn * 1e3),
|
|
777
|
+
key: input.key,
|
|
778
|
+
mode: "remote"
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Presign a direct-to-R2 `PUT` URL for a browser (or any HTTP client) upload.
|
|
783
|
+
*
|
|
784
|
+
* Resolves to a real R2 S3 presigned URL in production and to a signed
|
|
785
|
+
* devflare-gateway URL in local dev and the test harness — same call, same
|
|
786
|
+
* guarantees (signature, expiry, method, content type, size), so upload and
|
|
787
|
+
* quota logic can be exercised identically in every environment.
|
|
788
|
+
*
|
|
789
|
+
* @param env - The platform env (`platform.env` in SvelteKit, `env` in a
|
|
790
|
+
* Worker handler). Used to detect the local dev context and to read
|
|
791
|
+
* production credentials/bucket mapping.
|
|
792
|
+
* @param binding - The R2 binding name from `bindings.r2` (e.g. `'BUCKET'`).
|
|
793
|
+
* @param key - Object key to upload to. Percent-encoding is handled internally.
|
|
794
|
+
* @param options - Expiry, enforcement (content type / length / max size) and
|
|
795
|
+
* production credential overrides.
|
|
796
|
+
* @returns The presigned request: `url` to PUT to, `headers` the client must
|
|
797
|
+
* send, and `expiresAt`.
|
|
798
|
+
* @throws {Error} in production when credentials or the bucket mapping are missing.
|
|
799
|
+
* @throws {TypeError | RangeError} on invalid inputs.
|
|
800
|
+
*
|
|
801
|
+
* @example
|
|
802
|
+
* ```ts
|
|
803
|
+
* // Server (SvelteKit endpoint) — reserve quota first, then presign:
|
|
804
|
+
* const { url, headers } = await presignR2Put(platform.env, 'BUCKET', `media/${id}.png`, {
|
|
805
|
+
* expiresIn: 600,
|
|
806
|
+
* contentType: file.type,
|
|
807
|
+
* contentLength: file.size
|
|
808
|
+
* })
|
|
809
|
+
*
|
|
810
|
+
* // Browser — upload directly to storage:
|
|
811
|
+
* await fetch(url, { method: 'PUT', body: file, headers })
|
|
812
|
+
*
|
|
813
|
+
* // Server — finalize: confirm the object before committing quota:
|
|
814
|
+
* const head = await platform.env.BUCKET.head(`media/${id}.png`)
|
|
815
|
+
* ```
|
|
816
|
+
*/
|
|
817
|
+
async function presignR2Put(env, binding, key, options = {}) {
|
|
818
|
+
const expiresIn = validateCommonInputs(binding, key, options);
|
|
819
|
+
const local = resolveLocalContext(env);
|
|
820
|
+
if (local) return presignLocal({
|
|
821
|
+
...local,
|
|
822
|
+
method: "PUT",
|
|
823
|
+
binding,
|
|
824
|
+
key,
|
|
825
|
+
expiresIn,
|
|
826
|
+
contentType: options.contentType,
|
|
827
|
+
contentLength: options.contentLength,
|
|
828
|
+
maxSizeBytes: options.maxSizeBytes
|
|
829
|
+
});
|
|
830
|
+
return presignRemote({
|
|
831
|
+
credentials: resolveCredentials(env, options),
|
|
832
|
+
bucket: resolveBucket(env, binding, options),
|
|
833
|
+
method: "PUT",
|
|
834
|
+
key,
|
|
835
|
+
expiresIn,
|
|
836
|
+
contentType: options.contentType,
|
|
837
|
+
contentLength: options.contentLength
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
/**
|
|
841
|
+
* Presign a direct-from-R2 `GET` URL (also valid for `HEAD`) so a browser can
|
|
842
|
+
* download an object without routing the bytes through the Worker.
|
|
843
|
+
*
|
|
844
|
+
* Same dev/prod symmetry as {@link presignR2Put}. Note that browser reads
|
|
845
|
+
* from real R2 additionally require CORS rules on the bucket itself.
|
|
846
|
+
*
|
|
847
|
+
* @param env - The platform env (see {@link presignR2Put}).
|
|
848
|
+
* @param binding - The R2 binding name from `bindings.r2`.
|
|
849
|
+
* @param key - Object key to read.
|
|
850
|
+
* @param options - Expiry and production credential overrides.
|
|
851
|
+
* @returns The presigned request; `headers` is always empty for GET.
|
|
852
|
+
* @throws {Error} in production when credentials or the bucket mapping are missing.
|
|
853
|
+
* @throws {TypeError | RangeError} on invalid inputs.
|
|
854
|
+
*/
|
|
855
|
+
async function presignR2Get(env, binding, key, options = {}) {
|
|
856
|
+
const expiresIn = validateCommonInputs(binding, key, options);
|
|
857
|
+
const local = resolveLocalContext(env);
|
|
858
|
+
if (local) return presignLocal({
|
|
859
|
+
...local,
|
|
860
|
+
method: "GET",
|
|
861
|
+
binding,
|
|
862
|
+
key,
|
|
863
|
+
expiresIn
|
|
864
|
+
});
|
|
865
|
+
return presignRemote({
|
|
866
|
+
credentials: resolveCredentials(env, options),
|
|
867
|
+
bucket: resolveBucket(env, binding, options),
|
|
868
|
+
method: "GET",
|
|
869
|
+
key,
|
|
870
|
+
expiresIn
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
//#endregion
|
|
874
|
+
export { vars as C, locals as S, resolveFetchHandler as _, matchFetchRoute as a, env as b, assertExplicitScheduledHandlerStyle as c, defineQueueHandler as d, defineScheduledHandler as f, markWorkerStyle as g, markResolveStyle as h, invokeRouteModules as i, createResolveFetch as l, invokeFetchModule as m, presignR2Put as n, assertExplicit2ArgStyle as o, invokeFetchHandler as p, createRouteResolve as r, assertExplicitQueueHandlerStyle as s, presignR2Get as t, defineFetchHandler as u, sequence as v, event as x, ctx as y };
|