devflare 1.0.0-next.5 → 1.0.0-next.51
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 +17312 -2139
- package/README.md +397 -605
- package/bin/devflare.js +30 -14
- package/dist/_chunks/account-Csog80ie.js +462 -0
- package/dist/_chunks/account-resources-CsmVowJp.js +159 -0
- package/dist/_chunks/ai-CBEuLdoP.js +322 -0
- package/dist/_chunks/api-TzdliH-6.js +568 -0
- package/dist/_chunks/build-Ccza8VQz.js +24 -0
- package/dist/_chunks/build-artifacts-BNssqhxE.js +483 -0
- package/dist/_chunks/cli-CU7wSG1-.js +1163 -0
- package/dist/_chunks/cloudflare-BaloqI3H.js +157 -0
- package/dist/_chunks/colors-DiK6wPJ5.js +13 -0
- package/dist/_chunks/command-utils-_bGRraDR.js +45 -0
- package/dist/_chunks/compiler-BtLp9T9N.js +500 -0
- package/dist/_chunks/config-QU8UEWmA.js +78 -0
- package/dist/_chunks/config-path-1yI7BiDU.js +42 -0
- package/dist/_chunks/context-CX50Y2Kb.js +2250 -0
- package/dist/_chunks/decorators-QmV57ixr.js +19 -0
- package/dist/_chunks/dependencies-C2oxFjU_.js +57 -0
- package/dist/_chunks/deploy-aifBaMVv.js +1032 -0
- package/dist/_chunks/dev-DF_3baGr.js +3483 -0
- package/dist/_chunks/doctor-tR9kGT_Z.js +219 -0
- package/dist/_chunks/durable-object-DMtH0XYX.js +234 -0
- package/dist/_chunks/env-S0_nMVz1.js +125 -0
- package/dist/_chunks/family-DKPp4wqj.js +143 -0
- package/dist/_chunks/generated-artifacts-dMJY4KAt.js +32 -0
- package/dist/_chunks/glob-CmQOvunB.js +56 -0
- package/dist/_chunks/init-DnkJOmpW.js +165 -0
- package/dist/_chunks/loader-OQ2AWpqm.js +1308 -0
- package/dist/_chunks/local-dev-vars-CTSa-wvF.js +81 -0
- package/dist/_chunks/local-hyperdrive-CJ90j46O.js +119 -0
- package/dist/_chunks/local-media-bindings-DsAW4AMF.js +335 -0
- package/dist/_chunks/local-secrets-CYoHfvQ1.js +123 -0
- package/dist/_chunks/local-workflow-entrypoints-8d_mXh8T.js +90 -0
- package/dist/_chunks/login-rVWUZOKC.js +51 -0
- package/dist/_chunks/package-metadata-DjHBLB-z.js +39 -0
- package/dist/_chunks/preferences-BKp_7XJx.js +241 -0
- package/dist/_chunks/preview-C3Cdr8an.js +462 -0
- package/dist/_chunks/preview-registry-ClAbLTHH.js +1186 -0
- package/dist/_chunks/preview-resources-DRWR0gaB.js +359 -0
- package/dist/_chunks/previews-BxNq8Y_J.js +1134 -0
- package/dist/_chunks/productions-DK7xwbEs.js +411 -0
- package/dist/_chunks/ref-CYJNAAe_.js +178 -0
- package/dist/_chunks/remote-CZnP-HLJ.js +79 -0
- package/dist/_chunks/remote-config-D39BY9ji.js +132 -0
- package/dist/_chunks/resolve-package-qizBfCIm.js +152 -0
- package/dist/_chunks/rolldown-runtime-CvQ6eiug.js +14 -0
- package/dist/_chunks/routes-B6XiI8Sa.js +851 -0
- package/dist/_chunks/runtime-DL-Nz3k8.js +550 -0
- package/dist/_chunks/schema-normalization-GjhTATHL.js +666 -0
- package/dist/_chunks/secrets-qT1JaBGt.js +95 -0
- package/dist/_chunks/tail-CuWI04BL.js +239 -0
- package/dist/_chunks/token-Dmi0KXyX.js +333 -0
- package/dist/_chunks/tokens-iVcgNXi-.js +221 -0
- package/dist/_chunks/types-BquPXsFg.js +484 -0
- package/dist/_chunks/ui-BUoZApvE.js +103 -0
- package/dist/_chunks/usage-BBTGzjon.js +272 -0
- package/dist/_chunks/vite-D_wLDGBs.js +1267 -0
- package/dist/_chunks/vite-utils-OVLMV605.js +183 -0
- package/dist/_chunks/worker-DEF-e8LL.js +410 -0
- package/dist/_chunks/worker-bundler-dTTnYU3n.js +458 -0
- package/dist/_chunks/worker-entrypoint-CQW77lG8.js +247 -0
- package/dist/_chunks/workerName-CFJsLZA-.js +23 -0
- package/dist/bridge/client.d.ts +49 -7
- package/dist/bridge/client.d.ts.map +1 -1
- 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.d.ts +85 -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/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/{serialization.d.ts → v2/value-serialization.d.ts} +40 -18
- 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/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 +5705 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +80 -0
- 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/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 +309 -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 +12 -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 +2087 -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 +3771 -0
- package/dist/config/schema-env.d.ts.map +1 -0
- package/dist/config/schema-normalization.d.ts +267 -0
- package/dist/config/schema-normalization.d.ts.map +1 -0
- package/dist/config/schema-runtime.d.ts +557 -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 +122 -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 +5699 -2021
- 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-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 +21 -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 +36 -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 +93 -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-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 +15 -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/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 +9 -298
- 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 +10 -3
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +5 -111
- package/dist/runtime/middleware.d.ts +119 -67
- package/dist/runtime/middleware.d.ts.map +1 -1
- 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 +313 -167
- 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 +20 -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 +4981 -70
- package/dist/test/offline-bindings.d.ts +115 -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 +10 -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 +43 -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/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 +13 -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 -339
- 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 +7 -0
- package/dist/worker-entry/composed-worker.d.ts.map +1 -0
- 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 +159 -116
- 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.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-mnf6v8gd.js +0 -53
- package/dist/deploy-nhceck39.js +0 -70
- package/dist/dev-b9dmrj7b.js +0 -2417
- package/dist/doctor-fmgb3d28.js +0 -190
- package/dist/durable-object-t4kbb0yt.js +0 -13
- package/dist/index-07q6yxyc.js +0 -168
- 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-67qcae0f.js +0 -183
- package/dist/index-a855bdsx.js +0 -18
- package/dist/index-d8bdkx2h.js +0 -109
- package/dist/index-ep3445yc.js +0 -2225
- package/dist/index-gz1gndna.js +0 -307
- package/dist/index-hcex3rgh.js +0 -266
- package/dist/index-m2q41jwa.js +0 -462
- package/dist/index-n7rs26ft.js +0 -77
- package/dist/index-pf5s73n9.js +0 -1413
- package/dist/index-rbht7m9r.js +0 -36
- package/dist/index-tfyxa77h.js +0 -850
- package/dist/index-tk6ej9dj.js +0 -94
- 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-5nyrz1sz.js +0 -454
- package/dist/worker-entrypoint-m9th0rg0.js +0 -13
|
@@ -0,0 +1,1186 @@
|
|
|
1
|
+
import { a as apiGetAll, i as apiGet, n as CloudflareAPIError, o as apiPatch, r as apiDelete } from "./api-TzdliH-6.js";
|
|
2
|
+
import { p as listD1Databases, t as createD1Database, y as queryD1Database } from "./account-resources-CsmVowJp.js";
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { z } from "zod/v4";
|
|
7
|
+
//#region src/cloudflare/account-workers.ts
|
|
8
|
+
async function listWorkers(accountId, options) {
|
|
9
|
+
return (await apiGetAll(`/accounts/${accountId}/workers/scripts`, options)).map((script) => ({
|
|
10
|
+
name: script.name ?? script.id,
|
|
11
|
+
createdOn: new Date(script.created_on),
|
|
12
|
+
modifiedOn: new Date(script.modified_on)
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
async function renameWorker(accountId, workerId, newName, options) {
|
|
16
|
+
const result = await apiPatch(`/accounts/${accountId}/workers/workers/${encodeURIComponent(workerId)}`, { name: newName }, options);
|
|
17
|
+
return {
|
|
18
|
+
id: result.id,
|
|
19
|
+
name: result.name
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
async function deleteWorker(accountId, scriptName, options) {
|
|
23
|
+
await apiDelete(`/accounts/${accountId}/workers/scripts/${encodeURIComponent(scriptName)}`, options);
|
|
24
|
+
}
|
|
25
|
+
function mapWorkerVersionInfo(version) {
|
|
26
|
+
return {
|
|
27
|
+
id: version.id ?? "",
|
|
28
|
+
number: version.number,
|
|
29
|
+
metadata: {
|
|
30
|
+
authorEmail: version.metadata?.author_email,
|
|
31
|
+
authorId: version.metadata?.author_id,
|
|
32
|
+
createdOn: version.metadata?.created_on ? new Date(version.metadata.created_on) : void 0,
|
|
33
|
+
modifiedOn: version.metadata?.modified_on ? new Date(version.metadata.modified_on) : void 0,
|
|
34
|
+
hasPreview: version.metadata?.has_preview === true || version.metadata?.hasPreview === true,
|
|
35
|
+
source: version.metadata?.source
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async function listWorkerVersions(accountId, scriptName, options) {
|
|
40
|
+
const versions = [];
|
|
41
|
+
const encodedScriptName = encodeURIComponent(scriptName);
|
|
42
|
+
for (let page = 1; page <= 100; page++) {
|
|
43
|
+
const items = (await apiGet(`/accounts/${accountId}/workers/scripts/${encodedScriptName}/versions?page=${page}&per_page=100`, options)).items ?? [];
|
|
44
|
+
versions.push(...items.map((item) => mapWorkerVersionInfo(item)));
|
|
45
|
+
if (items.length < 100) break;
|
|
46
|
+
}
|
|
47
|
+
return versions;
|
|
48
|
+
}
|
|
49
|
+
async function getWorkerVersionDetail(accountId, scriptName, versionId, options) {
|
|
50
|
+
return mapWorkerVersionInfo(await apiGet(`/accounts/${accountId}/workers/scripts/${encodeURIComponent(scriptName)}/versions/${versionId}`, options));
|
|
51
|
+
}
|
|
52
|
+
async function listWorkerDeployments(accountId, scriptName, options) {
|
|
53
|
+
return ((await apiGet(`/accounts/${accountId}/workers/scripts/${encodeURIComponent(scriptName)}/deployments`, options)).deployments ?? []).map((deployment) => ({
|
|
54
|
+
id: deployment.id,
|
|
55
|
+
createdOn: new Date(deployment.created_on),
|
|
56
|
+
source: deployment.source,
|
|
57
|
+
strategy: deployment.strategy,
|
|
58
|
+
versions: deployment.versions.map((version) => ({
|
|
59
|
+
percentage: version.percentage,
|
|
60
|
+
versionId: version.version_id
|
|
61
|
+
})),
|
|
62
|
+
message: deployment.annotations?.["workers/message"],
|
|
63
|
+
triggeredBy: deployment.annotations?.["workers/triggered_by"],
|
|
64
|
+
authorEmail: deployment.author_email
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
async function getWorkersSubdomain(accountId, options) {
|
|
68
|
+
try {
|
|
69
|
+
return (await apiGet(`/accounts/${accountId}/workers/subdomain`, options)).subdomain || null;
|
|
70
|
+
} catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region src/cloudflare/preview-registry-types.ts
|
|
76
|
+
const DEVFLARE_PREVIEW_REGISTRY_DATABASE = "devflare-registry";
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/cloudflare/preview-registry-cache.ts
|
|
79
|
+
const DEVFLARE_CACHE_DIR = ".devflare";
|
|
80
|
+
const PREVIEW_REGISTRY_CACHE_FILE = "preview-registry.json";
|
|
81
|
+
function getDevflareCacheDir() {
|
|
82
|
+
const override = process.env.DEVFLARE_CACHE_DIR?.trim();
|
|
83
|
+
if (override) return override;
|
|
84
|
+
return join(homedir(), DEVFLARE_CACHE_DIR);
|
|
85
|
+
}
|
|
86
|
+
function getPreviewRegistryCachePath() {
|
|
87
|
+
return join(getDevflareCacheDir(), PREVIEW_REGISTRY_CACHE_FILE);
|
|
88
|
+
}
|
|
89
|
+
function getPreviewRegistryCacheKey(accountId, databaseName) {
|
|
90
|
+
return `${accountId}:${databaseName}`;
|
|
91
|
+
}
|
|
92
|
+
function readPreviewRegistryCache() {
|
|
93
|
+
const cachePath = getPreviewRegistryCachePath();
|
|
94
|
+
if (!existsSync(cachePath)) return {};
|
|
95
|
+
try {
|
|
96
|
+
const content = readFileSync(cachePath, "utf-8");
|
|
97
|
+
return JSON.parse(content);
|
|
98
|
+
} catch {
|
|
99
|
+
return {};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function writePreviewRegistryCache(cache) {
|
|
103
|
+
try {
|
|
104
|
+
const cacheDir = getDevflareCacheDir();
|
|
105
|
+
if (!existsSync(cacheDir)) mkdirSync(cacheDir, { recursive: true });
|
|
106
|
+
writeFileSync(getPreviewRegistryCachePath(), JSON.stringify(cache, null, " "), "utf-8");
|
|
107
|
+
} catch {}
|
|
108
|
+
}
|
|
109
|
+
function getRegistryDatabaseName(databaseName) {
|
|
110
|
+
return databaseName?.trim() || "devflare-registry";
|
|
111
|
+
}
|
|
112
|
+
function getCachedPreviewRegistryContext(accountId, databaseName) {
|
|
113
|
+
const entry = readPreviewRegistryCache().registries?.[getPreviewRegistryCacheKey(accountId, databaseName)];
|
|
114
|
+
if (!entry?.databaseId) return null;
|
|
115
|
+
return {
|
|
116
|
+
accountId: entry.accountId,
|
|
117
|
+
databaseId: entry.databaseId,
|
|
118
|
+
databaseName: entry.databaseName,
|
|
119
|
+
created: false
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function cachePreviewRegistryContext(registry) {
|
|
123
|
+
const cache = readPreviewRegistryCache();
|
|
124
|
+
const registries = cache.registries ?? {};
|
|
125
|
+
registries[getPreviewRegistryCacheKey(registry.accountId, registry.databaseName)] = {
|
|
126
|
+
accountId: registry.accountId,
|
|
127
|
+
databaseId: registry.databaseId,
|
|
128
|
+
databaseName: registry.databaseName,
|
|
129
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
130
|
+
};
|
|
131
|
+
writePreviewRegistryCache({
|
|
132
|
+
...cache,
|
|
133
|
+
registries
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
function clearCachedPreviewRegistryContext(accountId, databaseName) {
|
|
137
|
+
const cache = readPreviewRegistryCache();
|
|
138
|
+
if (!cache.registries) return;
|
|
139
|
+
delete cache.registries[getPreviewRegistryCacheKey(accountId, databaseName)];
|
|
140
|
+
writePreviewRegistryCache(cache);
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region src/cloudflare/preview-registry-inference.ts
|
|
144
|
+
function toIsoString(date) {
|
|
145
|
+
return date ? date.toISOString() : null;
|
|
146
|
+
}
|
|
147
|
+
function inferRecordSource(explicitSource, fallbackSource) {
|
|
148
|
+
if (explicitSource) return explicitSource;
|
|
149
|
+
if (fallbackSource === "dashboard") return "dashboard";
|
|
150
|
+
if (fallbackSource === "workers-builds") return "workers-builds";
|
|
151
|
+
if (fallbackSource === "wrangler") return process.env.GITHUB_ACTIONS === "true" ? "github-action" : "cli";
|
|
152
|
+
return "unknown";
|
|
153
|
+
}
|
|
154
|
+
function getPreviewRecordId(workerName, versionId) {
|
|
155
|
+
return `preview:${workerName}:${versionId}`;
|
|
156
|
+
}
|
|
157
|
+
function getPreviewScopeRecordId(workerName, scope) {
|
|
158
|
+
return `previewScope:${workerName}:${scope}`;
|
|
159
|
+
}
|
|
160
|
+
function getPreviewDeploymentId(workerName, versionId) {
|
|
161
|
+
return `preview:${workerName}:${versionId}`;
|
|
162
|
+
}
|
|
163
|
+
function getDeploymentRecordId(workerName, deploymentId) {
|
|
164
|
+
return `deployment:${workerName}:${deploymentId}`;
|
|
165
|
+
}
|
|
166
|
+
function hasRetireSelector(options) {
|
|
167
|
+
return Boolean(options.branchName || options.previewScope || options.versionId || options.commitSha);
|
|
168
|
+
}
|
|
169
|
+
function matchesRetireSelector(options, candidate) {
|
|
170
|
+
return options.branchName !== void 0 && candidate.branchName === options.branchName || options.previewScope !== void 0 && candidate.previewScope === options.previewScope || options.versionId !== void 0 && candidate.versionId === options.versionId || options.commitSha !== void 0 && candidate.commitSha === options.commitSha;
|
|
171
|
+
}
|
|
172
|
+
function getPreviewRetireCandidate(record) {
|
|
173
|
+
return {
|
|
174
|
+
branchName: record.branchName,
|
|
175
|
+
previewScope: record.scope,
|
|
176
|
+
versionId: record.versionId,
|
|
177
|
+
commitSha: record.commitSha
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function matchesPreviewRetireTarget(record, options) {
|
|
181
|
+
return matchesRetireSelector(options, getPreviewRetireCandidate(record));
|
|
182
|
+
}
|
|
183
|
+
function matchesPreviewScopeRetireTarget(record, options) {
|
|
184
|
+
return matchesRetireSelector(options, getPreviewRetireCandidate(record));
|
|
185
|
+
}
|
|
186
|
+
function matchesPreviewDeploymentRetireTarget(record, options) {
|
|
187
|
+
return record.channel === "preview" && matchesRetireSelector(options, {
|
|
188
|
+
versionId: record.versionId,
|
|
189
|
+
commitSha: record.commitSha
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function getExplicitPreviewSyncOverrides(options, versionId) {
|
|
193
|
+
if (versionId !== options.versionId) return {};
|
|
194
|
+
return {
|
|
195
|
+
previewScope: options.previewScope,
|
|
196
|
+
previewUrl: options.previewUrl,
|
|
197
|
+
previewScopeUrl: options.previewScopeUrl,
|
|
198
|
+
branchName: options.branchName,
|
|
199
|
+
commitSha: options.commitSha
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
//#endregion
|
|
203
|
+
//#region src/cloudflare/preview-urls.ts
|
|
204
|
+
function normalizeWorkersSubdomain(accountSubdomain) {
|
|
205
|
+
return accountSubdomain.trim().replace(/^https?:\/\//i, "").replace(/\.workers\.dev\/?$/i, "");
|
|
206
|
+
}
|
|
207
|
+
function formatWorkersDevUrl(workerName, accountSubdomain) {
|
|
208
|
+
return `https://${workerName}.${normalizeWorkersSubdomain(accountSubdomain)}.workers.dev`;
|
|
209
|
+
}
|
|
210
|
+
function formatVersionPreviewUrl(versionId, workerName, accountSubdomain) {
|
|
211
|
+
const normalizedSubdomain = normalizeWorkersSubdomain(accountSubdomain);
|
|
212
|
+
return `https://${versionId.split("-")[0] || versionId}-${workerName}.${normalizedSubdomain}.workers.dev`;
|
|
213
|
+
}
|
|
214
|
+
//#endregion
|
|
215
|
+
//#region src/cloudflare/registry-schema.ts
|
|
216
|
+
const recordIdSchema = z.string().min(1);
|
|
217
|
+
const cloudflareAccountIdSchema = z.string().min(1);
|
|
218
|
+
const cloudflareVersionIdSchema = z.string().uuid();
|
|
219
|
+
const workerNameSchema = z.string().min(1);
|
|
220
|
+
const timestampSchema = z.coerce.date();
|
|
221
|
+
const urlSchema = z.string().url();
|
|
222
|
+
const branchNameSchema = z.string().min(1);
|
|
223
|
+
const commitShaSchema = z.string().regex(/^[a-f0-9]{7,40}$/i, { message: "Commit SHA must be 7 to 40 hexadecimal characters" });
|
|
224
|
+
const previewScopeSchema = z.string().regex(/^[a-z][a-z0-9-]*$/, { message: "Preview names must start with a lowercase letter and contain only lowercase letters, numbers, and dashes" });
|
|
225
|
+
const cloudflareUserIdSchema = z.union([z.string().min(1), z.number().int().nonnegative().transform((value) => String(value))]);
|
|
226
|
+
const devflareAccountRecordSchema = z.object({
|
|
227
|
+
id: recordIdSchema,
|
|
228
|
+
ver: z.number().int().min(1),
|
|
229
|
+
createdAt: timestampSchema,
|
|
230
|
+
updatedAt: timestampSchema.optional(),
|
|
231
|
+
deletedAt: timestampSchema.optional(),
|
|
232
|
+
createdBy: cloudflareUserIdSchema
|
|
233
|
+
}).strict();
|
|
234
|
+
function createDevflareAccountRecordSchema(shape) {
|
|
235
|
+
return devflareAccountRecordSchema.extend(shape);
|
|
236
|
+
}
|
|
237
|
+
const devflareRecordSourceSchema = z.enum([
|
|
238
|
+
"cli",
|
|
239
|
+
"github-action",
|
|
240
|
+
"workers-builds",
|
|
241
|
+
"dashboard",
|
|
242
|
+
"unknown"
|
|
243
|
+
]);
|
|
244
|
+
const devflarePreviewStatusSchema = z.enum([
|
|
245
|
+
"active",
|
|
246
|
+
"superseded",
|
|
247
|
+
"orphaned",
|
|
248
|
+
"deleted"
|
|
249
|
+
]);
|
|
250
|
+
const devflarePreviewScopeStatusSchema = z.enum([
|
|
251
|
+
"active",
|
|
252
|
+
"reassigned",
|
|
253
|
+
"deleted"
|
|
254
|
+
]);
|
|
255
|
+
const devflareDeploymentChannelSchema = z.enum(["production", "preview"]);
|
|
256
|
+
const devflareDeploymentStatusSchema = z.enum([
|
|
257
|
+
"active",
|
|
258
|
+
"superseded",
|
|
259
|
+
"rolled_back",
|
|
260
|
+
"deleted"
|
|
261
|
+
]);
|
|
262
|
+
const devflarePreviewRecordSchema = createDevflareAccountRecordSchema({
|
|
263
|
+
kind: z.literal("preview"),
|
|
264
|
+
accountId: cloudflareAccountIdSchema,
|
|
265
|
+
workerName: workerNameSchema,
|
|
266
|
+
versionId: cloudflareVersionIdSchema,
|
|
267
|
+
previewUrl: urlSchema,
|
|
268
|
+
scope: previewScopeSchema.optional(),
|
|
269
|
+
scopeUrl: urlSchema.optional(),
|
|
270
|
+
branchName: branchNameSchema.optional(),
|
|
271
|
+
commitSha: commitShaSchema.optional(),
|
|
272
|
+
deploymentId: recordIdSchema.optional(),
|
|
273
|
+
source: devflareRecordSourceSchema.default("unknown"),
|
|
274
|
+
status: devflarePreviewStatusSchema.default("active")
|
|
275
|
+
}).superRefine((record, ctx) => {
|
|
276
|
+
if (record.scopeUrl && !record.scope) ctx.addIssue({
|
|
277
|
+
code: "custom",
|
|
278
|
+
path: ["scopeUrl"],
|
|
279
|
+
message: "scopeUrl requires scope to be set"
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
const devflarePreviewScopeRecordSchema = createDevflareAccountRecordSchema({
|
|
283
|
+
kind: z.literal("previewScope"),
|
|
284
|
+
accountId: cloudflareAccountIdSchema,
|
|
285
|
+
workerName: workerNameSchema,
|
|
286
|
+
scope: previewScopeSchema,
|
|
287
|
+
scopeUrl: urlSchema,
|
|
288
|
+
versionId: cloudflareVersionIdSchema,
|
|
289
|
+
previewId: recordIdSchema.optional(),
|
|
290
|
+
branchName: branchNameSchema.optional(),
|
|
291
|
+
commitSha: commitShaSchema.optional(),
|
|
292
|
+
source: devflareRecordSourceSchema.default("unknown"),
|
|
293
|
+
status: devflarePreviewScopeStatusSchema.default("active")
|
|
294
|
+
});
|
|
295
|
+
const devflareDeploymentRecordSchema = createDevflareAccountRecordSchema({
|
|
296
|
+
kind: z.literal("deployment"),
|
|
297
|
+
accountId: cloudflareAccountIdSchema,
|
|
298
|
+
workerName: workerNameSchema,
|
|
299
|
+
deploymentId: recordIdSchema,
|
|
300
|
+
channel: devflareDeploymentChannelSchema,
|
|
301
|
+
status: devflareDeploymentStatusSchema.default("active"),
|
|
302
|
+
versionId: cloudflareVersionIdSchema,
|
|
303
|
+
previewId: recordIdSchema.optional(),
|
|
304
|
+
environment: z.string().min(1).optional(),
|
|
305
|
+
url: urlSchema.optional(),
|
|
306
|
+
message: z.string().min(1).optional(),
|
|
307
|
+
commitSha: commitShaSchema.optional(),
|
|
308
|
+
source: devflareRecordSourceSchema.default("unknown")
|
|
309
|
+
}).superRefine((record, ctx) => {
|
|
310
|
+
if (record.channel === "preview" && !record.previewId) ctx.addIssue({
|
|
311
|
+
code: "custom",
|
|
312
|
+
path: ["previewId"],
|
|
313
|
+
message: "Preview deployments must reference the preview record they materialize"
|
|
314
|
+
});
|
|
315
|
+
if (record.channel === "production" && record.previewId) ctx.addIssue({
|
|
316
|
+
code: "custom",
|
|
317
|
+
path: ["previewId"],
|
|
318
|
+
message: "Production deployments should not reference previewId"
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
const devflareAccountLayerRecordSchema = z.discriminatedUnion("kind", [
|
|
322
|
+
devflarePreviewRecordSchema,
|
|
323
|
+
devflarePreviewScopeRecordSchema,
|
|
324
|
+
devflareDeploymentRecordSchema
|
|
325
|
+
]);
|
|
326
|
+
//#endregion
|
|
327
|
+
//#region src/cloudflare/preview-registry-shape.ts
|
|
328
|
+
function markRecordDeleted(record, now, parser) {
|
|
329
|
+
return parser.parse({
|
|
330
|
+
...record,
|
|
331
|
+
updatedAt: now,
|
|
332
|
+
deletedAt: now,
|
|
333
|
+
status: "deleted"
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
function getVersionAuthorId(version, existingCreatedBy) {
|
|
337
|
+
return version?.metadata.authorId || existingCreatedBy || "unknown";
|
|
338
|
+
}
|
|
339
|
+
function createPreviewLinkedRecordBase(options) {
|
|
340
|
+
return {
|
|
341
|
+
createdAt: options.existingCreatedAt ?? options.previewRecord.createdAt,
|
|
342
|
+
updatedAt: options.now,
|
|
343
|
+
deletedAt: void 0,
|
|
344
|
+
createdBy: options.previewRecord.createdBy,
|
|
345
|
+
accountId: options.accountId,
|
|
346
|
+
workerName: options.workerName,
|
|
347
|
+
versionId: options.previewRecord.versionId,
|
|
348
|
+
previewId: options.previewRecord.id,
|
|
349
|
+
commitSha: options.previewRecord.commitSha,
|
|
350
|
+
source: options.previewRecord.source,
|
|
351
|
+
status: "active"
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
function buildPreviewRecord(options) {
|
|
355
|
+
const scope = options.previewScope ?? options.existing?.scope;
|
|
356
|
+
const previewUrl = options.previewUrl ?? options.existing?.previewUrl ?? (options.workersSubdomain ? formatVersionPreviewUrl(options.version.id, options.workerName, options.workersSubdomain) : void 0);
|
|
357
|
+
const scopeChanged = options.previewScope !== void 0 && options.previewScope !== options.existing?.scope;
|
|
358
|
+
const scopeUrl = options.previewScopeUrl ?? (options.previewScope !== void 0 ? options.previewUrl : void 0) ?? (!scopeChanged ? options.existing?.scopeUrl : void 0);
|
|
359
|
+
if (!previewUrl) return null;
|
|
360
|
+
return devflarePreviewRecordSchema.parse({
|
|
361
|
+
id: getPreviewRecordId(options.workerName, options.version.id),
|
|
362
|
+
kind: "preview",
|
|
363
|
+
ver: 1,
|
|
364
|
+
createdAt: options.existing?.createdAt ?? options.version.metadata.createdOn ?? options.now,
|
|
365
|
+
updatedAt: options.now,
|
|
366
|
+
deletedAt: void 0,
|
|
367
|
+
createdBy: getVersionAuthorId(options.version, options.existing?.createdBy),
|
|
368
|
+
accountId: options.accountId,
|
|
369
|
+
workerName: options.workerName,
|
|
370
|
+
versionId: options.version.id,
|
|
371
|
+
previewUrl,
|
|
372
|
+
scope,
|
|
373
|
+
scopeUrl,
|
|
374
|
+
branchName: options.branchName ?? options.existing?.branchName,
|
|
375
|
+
commitSha: options.commitSha ?? options.existing?.commitSha,
|
|
376
|
+
deploymentId: options.existing?.deploymentId,
|
|
377
|
+
source: inferRecordSource(options.source, options.version.metadata.source),
|
|
378
|
+
status: "active"
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
function buildPreviewScopeRecord(options) {
|
|
382
|
+
if (!options.previewRecord.scope || !options.previewRecord.scopeUrl) return null;
|
|
383
|
+
return devflarePreviewScopeRecordSchema.parse({
|
|
384
|
+
id: getPreviewScopeRecordId(options.workerName, options.previewRecord.scope),
|
|
385
|
+
kind: "previewScope",
|
|
386
|
+
ver: 1,
|
|
387
|
+
...createPreviewLinkedRecordBase({
|
|
388
|
+
accountId: options.accountId,
|
|
389
|
+
workerName: options.workerName,
|
|
390
|
+
previewRecord: options.previewRecord,
|
|
391
|
+
existingCreatedAt: options.existing?.createdAt,
|
|
392
|
+
now: options.now
|
|
393
|
+
}),
|
|
394
|
+
scope: options.previewRecord.scope,
|
|
395
|
+
scopeUrl: options.previewRecord.scopeUrl,
|
|
396
|
+
branchName: options.previewRecord.branchName
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
function buildPreviewDeploymentRecord(options) {
|
|
400
|
+
const deploymentId = getPreviewDeploymentId(options.workerName, options.previewRecord.versionId);
|
|
401
|
+
return devflareDeploymentRecordSchema.parse({
|
|
402
|
+
id: getDeploymentRecordId(options.workerName, deploymentId),
|
|
403
|
+
kind: "deployment",
|
|
404
|
+
ver: 1,
|
|
405
|
+
...createPreviewLinkedRecordBase({
|
|
406
|
+
accountId: options.accountId,
|
|
407
|
+
workerName: options.workerName,
|
|
408
|
+
previewRecord: options.previewRecord,
|
|
409
|
+
existingCreatedAt: options.existing?.createdAt,
|
|
410
|
+
now: options.now
|
|
411
|
+
}),
|
|
412
|
+
deploymentId,
|
|
413
|
+
channel: "preview",
|
|
414
|
+
environment: "preview",
|
|
415
|
+
url: options.previewRecord.scopeUrl ?? options.previewRecord.previewUrl,
|
|
416
|
+
message: options.existing?.message
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
function buildProductionDeploymentRecord(options) {
|
|
420
|
+
const versionId = options.deployment.versions[0]?.versionId;
|
|
421
|
+
if (!versionId) return null;
|
|
422
|
+
const productionUrl = options.workersSubdomain ? `https://${options.workerName}.${options.workersSubdomain}.workers.dev` : options.existing?.url;
|
|
423
|
+
return devflareDeploymentRecordSchema.parse({
|
|
424
|
+
id: getDeploymentRecordId(options.workerName, options.deployment.id),
|
|
425
|
+
kind: "deployment",
|
|
426
|
+
ver: 1,
|
|
427
|
+
createdAt: options.existing?.createdAt ?? options.deployment.createdOn,
|
|
428
|
+
updatedAt: options.now,
|
|
429
|
+
deletedAt: void 0,
|
|
430
|
+
createdBy: getVersionAuthorId(options.version, options.existing?.createdBy),
|
|
431
|
+
accountId: options.accountId,
|
|
432
|
+
workerName: options.workerName,
|
|
433
|
+
deploymentId: options.deployment.id,
|
|
434
|
+
channel: "production",
|
|
435
|
+
status: options.status,
|
|
436
|
+
versionId,
|
|
437
|
+
environment: "production",
|
|
438
|
+
url: productionUrl,
|
|
439
|
+
message: options.deploymentMessage ?? options.deployment.message ?? options.existing?.message,
|
|
440
|
+
commitSha: options.commitSha ?? options.existing?.commitSha,
|
|
441
|
+
source: inferRecordSource(options.source, options.version?.metadata.source ?? options.deployment.source)
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
function markPreviewRecordDeleted(record, now) {
|
|
445
|
+
return markRecordDeleted(record, now, devflarePreviewRecordSchema);
|
|
446
|
+
}
|
|
447
|
+
function markPreviewScopeRecordDeleted(record, now) {
|
|
448
|
+
return markRecordDeleted(record, now, devflarePreviewScopeRecordSchema);
|
|
449
|
+
}
|
|
450
|
+
function markDeploymentRecordDeleted(record, now) {
|
|
451
|
+
return markRecordDeleted(record, now, devflareDeploymentRecordSchema);
|
|
452
|
+
}
|
|
453
|
+
//#endregion
|
|
454
|
+
//#region src/cloudflare/preview-registry-transport.ts
|
|
455
|
+
async function getVersionInfoById(accountId, workerName, versionId, versionMap, apiOptions) {
|
|
456
|
+
const existing = versionMap.get(versionId);
|
|
457
|
+
if (existing) return existing;
|
|
458
|
+
try {
|
|
459
|
+
const version = await getWorkerVersionDetail(accountId, workerName, versionId, apiOptions);
|
|
460
|
+
versionMap.set(versionId, version);
|
|
461
|
+
return version;
|
|
462
|
+
} catch {
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
//#endregion
|
|
467
|
+
//#region src/cloudflare/preview-registry-store.ts
|
|
468
|
+
const REGISTRY_TABLES = [
|
|
469
|
+
{
|
|
470
|
+
name: "devflare_preview_records",
|
|
471
|
+
createStatement: `CREATE TABLE IF NOT EXISTS devflare_preview_records (
|
|
472
|
+
id TEXT PRIMARY KEY,
|
|
473
|
+
ver INTEGER NOT NULL,
|
|
474
|
+
account_id TEXT NOT NULL,
|
|
475
|
+
worker_name TEXT NOT NULL,
|
|
476
|
+
version_id TEXT NOT NULL UNIQUE,
|
|
477
|
+
preview_url TEXT NOT NULL,
|
|
478
|
+
scope TEXT,
|
|
479
|
+
scope_url TEXT,
|
|
480
|
+
branch_name TEXT,
|
|
481
|
+
commit_sha TEXT,
|
|
482
|
+
deployment_id TEXT,
|
|
483
|
+
source TEXT NOT NULL,
|
|
484
|
+
status TEXT NOT NULL,
|
|
485
|
+
created_by TEXT NOT NULL,
|
|
486
|
+
created_at TEXT NOT NULL,
|
|
487
|
+
updated_at TEXT,
|
|
488
|
+
deleted_at TEXT,
|
|
489
|
+
payload_json TEXT NOT NULL
|
|
490
|
+
)`,
|
|
491
|
+
migrationColumns: {
|
|
492
|
+
id: "id TEXT",
|
|
493
|
+
ver: "ver INTEGER NOT NULL DEFAULT 1",
|
|
494
|
+
account_id: `account_id TEXT NOT NULL DEFAULT ''`,
|
|
495
|
+
worker_name: `worker_name TEXT NOT NULL DEFAULT ''`,
|
|
496
|
+
version_id: `version_id TEXT NOT NULL DEFAULT ''`,
|
|
497
|
+
preview_url: `preview_url TEXT NOT NULL DEFAULT ''`,
|
|
498
|
+
scope: "scope TEXT",
|
|
499
|
+
scope_url: "scope_url TEXT",
|
|
500
|
+
branch_name: "branch_name TEXT",
|
|
501
|
+
commit_sha: "commit_sha TEXT",
|
|
502
|
+
deployment_id: "deployment_id TEXT",
|
|
503
|
+
source: `source TEXT NOT NULL DEFAULT ''`,
|
|
504
|
+
status: `status TEXT NOT NULL DEFAULT ''`,
|
|
505
|
+
created_by: `created_by TEXT NOT NULL DEFAULT ''`,
|
|
506
|
+
created_at: `created_at TEXT NOT NULL DEFAULT ''`,
|
|
507
|
+
updated_at: "updated_at TEXT",
|
|
508
|
+
deleted_at: "deleted_at TEXT",
|
|
509
|
+
payload_json: `payload_json TEXT NOT NULL DEFAULT '{}'`
|
|
510
|
+
},
|
|
511
|
+
indexStatements: [
|
|
512
|
+
"CREATE INDEX IF NOT EXISTS idx_devflare_preview_records_account_worker ON devflare_preview_records(account_id, worker_name)",
|
|
513
|
+
"CREATE INDEX IF NOT EXISTS idx_devflare_preview_records_status ON devflare_preview_records(status)",
|
|
514
|
+
"CREATE UNIQUE INDEX IF NOT EXISTS idx_devflare_preview_records_version_id ON devflare_preview_records(version_id)"
|
|
515
|
+
]
|
|
516
|
+
},
|
|
517
|
+
{
|
|
518
|
+
name: "devflare_preview_scope_records",
|
|
519
|
+
createStatement: `CREATE TABLE IF NOT EXISTS devflare_preview_scope_records (
|
|
520
|
+
id TEXT PRIMARY KEY,
|
|
521
|
+
ver INTEGER NOT NULL,
|
|
522
|
+
account_id TEXT NOT NULL,
|
|
523
|
+
worker_name TEXT NOT NULL,
|
|
524
|
+
scope TEXT NOT NULL,
|
|
525
|
+
scope_url TEXT NOT NULL,
|
|
526
|
+
version_id TEXT NOT NULL,
|
|
527
|
+
preview_id TEXT,
|
|
528
|
+
branch_name TEXT,
|
|
529
|
+
commit_sha TEXT,
|
|
530
|
+
source TEXT NOT NULL,
|
|
531
|
+
status TEXT NOT NULL,
|
|
532
|
+
created_by TEXT NOT NULL,
|
|
533
|
+
created_at TEXT NOT NULL,
|
|
534
|
+
updated_at TEXT,
|
|
535
|
+
deleted_at TEXT,
|
|
536
|
+
payload_json TEXT NOT NULL
|
|
537
|
+
)`,
|
|
538
|
+
migrationColumns: {
|
|
539
|
+
id: "id TEXT",
|
|
540
|
+
ver: "ver INTEGER NOT NULL DEFAULT 1",
|
|
541
|
+
account_id: `account_id TEXT NOT NULL DEFAULT ''`,
|
|
542
|
+
worker_name: `worker_name TEXT NOT NULL DEFAULT ''`,
|
|
543
|
+
scope: `scope TEXT NOT NULL DEFAULT ''`,
|
|
544
|
+
scope_url: `scope_url TEXT NOT NULL DEFAULT ''`,
|
|
545
|
+
version_id: `version_id TEXT NOT NULL DEFAULT ''`,
|
|
546
|
+
preview_id: "preview_id TEXT",
|
|
547
|
+
branch_name: "branch_name TEXT",
|
|
548
|
+
commit_sha: "commit_sha TEXT",
|
|
549
|
+
source: `source TEXT NOT NULL DEFAULT ''`,
|
|
550
|
+
status: `status TEXT NOT NULL DEFAULT ''`,
|
|
551
|
+
created_by: `created_by TEXT NOT NULL DEFAULT ''`,
|
|
552
|
+
created_at: `created_at TEXT NOT NULL DEFAULT ''`,
|
|
553
|
+
updated_at: "updated_at TEXT",
|
|
554
|
+
deleted_at: "deleted_at TEXT",
|
|
555
|
+
payload_json: `payload_json TEXT NOT NULL DEFAULT '{}'`
|
|
556
|
+
},
|
|
557
|
+
indexStatements: ["CREATE INDEX IF NOT EXISTS idx_devflare_preview_scope_records_account_worker ON devflare_preview_scope_records(account_id, worker_name)", "CREATE INDEX IF NOT EXISTS idx_devflare_preview_scope_records_scope ON devflare_preview_scope_records(scope)"]
|
|
558
|
+
},
|
|
559
|
+
{
|
|
560
|
+
name: "devflare_deployment_records",
|
|
561
|
+
createStatement: `CREATE TABLE IF NOT EXISTS devflare_deployment_records (
|
|
562
|
+
id TEXT PRIMARY KEY,
|
|
563
|
+
ver INTEGER NOT NULL,
|
|
564
|
+
account_id TEXT NOT NULL,
|
|
565
|
+
worker_name TEXT NOT NULL,
|
|
566
|
+
deployment_id TEXT NOT NULL UNIQUE,
|
|
567
|
+
channel TEXT NOT NULL,
|
|
568
|
+
status TEXT NOT NULL,
|
|
569
|
+
version_id TEXT NOT NULL,
|
|
570
|
+
preview_id TEXT,
|
|
571
|
+
environment TEXT,
|
|
572
|
+
url TEXT,
|
|
573
|
+
message TEXT,
|
|
574
|
+
commit_sha TEXT,
|
|
575
|
+
source TEXT NOT NULL,
|
|
576
|
+
created_by TEXT NOT NULL,
|
|
577
|
+
created_at TEXT NOT NULL,
|
|
578
|
+
updated_at TEXT,
|
|
579
|
+
deleted_at TEXT,
|
|
580
|
+
payload_json TEXT NOT NULL
|
|
581
|
+
)`,
|
|
582
|
+
migrationColumns: {
|
|
583
|
+
id: "id TEXT",
|
|
584
|
+
ver: "ver INTEGER NOT NULL DEFAULT 1",
|
|
585
|
+
account_id: `account_id TEXT NOT NULL DEFAULT ''`,
|
|
586
|
+
worker_name: `worker_name TEXT NOT NULL DEFAULT ''`,
|
|
587
|
+
deployment_id: `deployment_id TEXT NOT NULL DEFAULT ''`,
|
|
588
|
+
channel: `channel TEXT NOT NULL DEFAULT ''`,
|
|
589
|
+
status: `status TEXT NOT NULL DEFAULT ''`,
|
|
590
|
+
version_id: `version_id TEXT NOT NULL DEFAULT ''`,
|
|
591
|
+
preview_id: "preview_id TEXT",
|
|
592
|
+
environment: "environment TEXT",
|
|
593
|
+
url: "url TEXT",
|
|
594
|
+
message: "message TEXT",
|
|
595
|
+
commit_sha: "commit_sha TEXT",
|
|
596
|
+
source: `source TEXT NOT NULL DEFAULT ''`,
|
|
597
|
+
created_by: `created_by TEXT NOT NULL DEFAULT ''`,
|
|
598
|
+
created_at: `created_at TEXT NOT NULL DEFAULT ''`,
|
|
599
|
+
updated_at: "updated_at TEXT",
|
|
600
|
+
deleted_at: "deleted_at TEXT",
|
|
601
|
+
payload_json: `payload_json TEXT NOT NULL DEFAULT '{}'`
|
|
602
|
+
},
|
|
603
|
+
indexStatements: [
|
|
604
|
+
"CREATE INDEX IF NOT EXISTS idx_devflare_deployment_records_account_worker ON devflare_deployment_records(account_id, worker_name)",
|
|
605
|
+
"CREATE INDEX IF NOT EXISTS idx_devflare_deployment_records_channel_status ON devflare_deployment_records(channel, status)",
|
|
606
|
+
"CREATE UNIQUE INDEX IF NOT EXISTS idx_devflare_deployment_records_deployment_id ON devflare_deployment_records(deployment_id)"
|
|
607
|
+
]
|
|
608
|
+
}
|
|
609
|
+
];
|
|
610
|
+
const schemaEnsuredRegistryIds = /* @__PURE__ */ new Set();
|
|
611
|
+
async function runQuery(registry, sql, params = [], apiOptions) {
|
|
612
|
+
return (await queryD1Database(registry.accountId, registry.databaseId, {
|
|
613
|
+
sql,
|
|
614
|
+
params
|
|
615
|
+
}, apiOptions))[0]?.results ?? [];
|
|
616
|
+
}
|
|
617
|
+
async function runStatement(registry, sql, params = [], apiOptions) {
|
|
618
|
+
await queryD1Database(registry.accountId, registry.databaseId, {
|
|
619
|
+
sql,
|
|
620
|
+
params
|
|
621
|
+
}, apiOptions);
|
|
622
|
+
}
|
|
623
|
+
function quoteSqlIdentifier(value) {
|
|
624
|
+
return `"${value.replaceAll("\"", "\"\"")}"`;
|
|
625
|
+
}
|
|
626
|
+
async function readTableColumnNames(registry, tableName, apiOptions) {
|
|
627
|
+
const rows = await runQuery(registry, `PRAGMA table_info(${quoteSqlIdentifier(tableName)})`, [], apiOptions);
|
|
628
|
+
return new Set(rows.map((row) => typeof row.name === "string" ? row.name : void 0).filter((value) => Boolean(value)));
|
|
629
|
+
}
|
|
630
|
+
async function ensureTableColumns(registry, table, apiOptions) {
|
|
631
|
+
const existingColumnNames = await readTableColumnNames(registry, table.name, apiOptions);
|
|
632
|
+
for (const [columnName, definition] of Object.entries(table.migrationColumns)) {
|
|
633
|
+
if (existingColumnNames.has(columnName)) continue;
|
|
634
|
+
await runStatement(registry, `ALTER TABLE ${quoteSqlIdentifier(table.name)} ADD COLUMN ${definition}`, [], apiOptions);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
async function ensurePreviewRegistrySchema(registry, apiOptions) {
|
|
638
|
+
if (schemaEnsuredRegistryIds.has(registry.databaseId)) return;
|
|
639
|
+
for (const table of REGISTRY_TABLES) {
|
|
640
|
+
await runStatement(registry, table.createStatement, [], apiOptions);
|
|
641
|
+
await ensureTableColumns(registry, table, apiOptions);
|
|
642
|
+
for (const statement of table.indexStatements) await runStatement(registry, statement, [], apiOptions);
|
|
643
|
+
}
|
|
644
|
+
schemaEnsuredRegistryIds.add(registry.databaseId);
|
|
645
|
+
}
|
|
646
|
+
function clearPreviewRegistrySchemaCache(databaseId) {
|
|
647
|
+
schemaEnsuredRegistryIds.delete(databaseId);
|
|
648
|
+
}
|
|
649
|
+
function isMissingRegistrySchemaError(error) {
|
|
650
|
+
if (error instanceof CloudflareAPIError) {
|
|
651
|
+
const message = error.message.toLowerCase();
|
|
652
|
+
return message.includes("no such table") || message.includes("no such column");
|
|
653
|
+
}
|
|
654
|
+
if (error instanceof Error) {
|
|
655
|
+
const message = error.message.toLowerCase();
|
|
656
|
+
return message.includes("no such table") || message.includes("no such column");
|
|
657
|
+
}
|
|
658
|
+
return false;
|
|
659
|
+
}
|
|
660
|
+
function isUnavailableRegistryContextError(error) {
|
|
661
|
+
if (error instanceof CloudflareAPIError) {
|
|
662
|
+
const message = error.message.toLowerCase();
|
|
663
|
+
return error.code === 404 || (message.includes("database") || message.includes("d1")) && (message.includes("not found") || message.includes("does not exist") || message.includes("unknown"));
|
|
664
|
+
}
|
|
665
|
+
if (error instanceof Error) {
|
|
666
|
+
const message = error.message.toLowerCase();
|
|
667
|
+
return (message.includes("database") || message.includes("d1")) && (message.includes("not found") || message.includes("does not exist"));
|
|
668
|
+
}
|
|
669
|
+
return false;
|
|
670
|
+
}
|
|
671
|
+
function normalizeLegacyStoredRecordPayload(value) {
|
|
672
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return value;
|
|
673
|
+
const { alias, aliasPreviewUrl, ...record } = value;
|
|
674
|
+
if (record.scope === void 0 && typeof alias === "string") record.scope = alias;
|
|
675
|
+
if (record.scopeUrl === void 0 && typeof aliasPreviewUrl === "string") record.scopeUrl = aliasPreviewUrl;
|
|
676
|
+
return record;
|
|
677
|
+
}
|
|
678
|
+
function parseStoredRecordPayload(row) {
|
|
679
|
+
return normalizeLegacyStoredRecordPayload(JSON.parse(row.payload_json));
|
|
680
|
+
}
|
|
681
|
+
function parseStoredPreviewRecord(row) {
|
|
682
|
+
return devflarePreviewRecordSchema.parse(parseStoredRecordPayload(row));
|
|
683
|
+
}
|
|
684
|
+
function parseStoredPreviewScopeRecord(row) {
|
|
685
|
+
return devflarePreviewScopeRecordSchema.parse(parseStoredRecordPayload(row));
|
|
686
|
+
}
|
|
687
|
+
function parseStoredDeploymentRecord(row) {
|
|
688
|
+
return devflareDeploymentRecordSchema.parse(parseStoredRecordPayload(row));
|
|
689
|
+
}
|
|
690
|
+
async function readPreviewRows(registry, workerName, apiOptions) {
|
|
691
|
+
return (await runQuery(registry, workerName ? "SELECT payload_json FROM devflare_preview_records WHERE account_id = ? AND worker_name = ? ORDER BY created_at DESC" : "SELECT payload_json FROM devflare_preview_records WHERE account_id = ? ORDER BY created_at DESC", workerName ? [registry.accountId, workerName] : [registry.accountId], apiOptions)).map((row) => parseStoredPreviewRecord(row));
|
|
692
|
+
}
|
|
693
|
+
async function readPreviewScopeRows(registry, workerName, apiOptions) {
|
|
694
|
+
return (await runQuery(registry, workerName ? "SELECT payload_json FROM devflare_preview_scope_records WHERE account_id = ? AND worker_name = ? ORDER BY created_at DESC" : "SELECT payload_json FROM devflare_preview_scope_records WHERE account_id = ? ORDER BY created_at DESC", workerName ? [registry.accountId, workerName] : [registry.accountId], apiOptions)).map((row) => parseStoredPreviewScopeRecord(row));
|
|
695
|
+
}
|
|
696
|
+
async function readDeploymentRows(registry, workerName, apiOptions) {
|
|
697
|
+
return (await runQuery(registry, workerName ? "SELECT payload_json FROM devflare_deployment_records WHERE account_id = ? AND worker_name = ? ORDER BY created_at DESC" : "SELECT payload_json FROM devflare_deployment_records WHERE account_id = ? ORDER BY created_at DESC", workerName ? [registry.accountId, workerName] : [registry.accountId], apiOptions)).map((row) => parseStoredDeploymentRecord(row));
|
|
698
|
+
}
|
|
699
|
+
async function upsertPreviewRecord(registry, record, apiOptions) {
|
|
700
|
+
const normalizedRecord = devflarePreviewRecordSchema.parse(record);
|
|
701
|
+
await runStatement(registry, `INSERT INTO devflare_preview_records (
|
|
702
|
+
id,
|
|
703
|
+
ver,
|
|
704
|
+
account_id,
|
|
705
|
+
worker_name,
|
|
706
|
+
version_id,
|
|
707
|
+
preview_url,
|
|
708
|
+
scope,
|
|
709
|
+
scope_url,
|
|
710
|
+
branch_name,
|
|
711
|
+
commit_sha,
|
|
712
|
+
deployment_id,
|
|
713
|
+
source,
|
|
714
|
+
status,
|
|
715
|
+
created_by,
|
|
716
|
+
created_at,
|
|
717
|
+
updated_at,
|
|
718
|
+
deleted_at,
|
|
719
|
+
payload_json
|
|
720
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
721
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
722
|
+
ver = excluded.ver,
|
|
723
|
+
account_id = excluded.account_id,
|
|
724
|
+
worker_name = excluded.worker_name,
|
|
725
|
+
version_id = excluded.version_id,
|
|
726
|
+
preview_url = excluded.preview_url,
|
|
727
|
+
scope = excluded.scope,
|
|
728
|
+
scope_url = excluded.scope_url,
|
|
729
|
+
branch_name = excluded.branch_name,
|
|
730
|
+
commit_sha = excluded.commit_sha,
|
|
731
|
+
deployment_id = excluded.deployment_id,
|
|
732
|
+
source = excluded.source,
|
|
733
|
+
status = excluded.status,
|
|
734
|
+
created_by = excluded.created_by,
|
|
735
|
+
created_at = excluded.created_at,
|
|
736
|
+
updated_at = excluded.updated_at,
|
|
737
|
+
deleted_at = excluded.deleted_at,
|
|
738
|
+
payload_json = excluded.payload_json`, [
|
|
739
|
+
normalizedRecord.id,
|
|
740
|
+
normalizedRecord.ver,
|
|
741
|
+
normalizedRecord.accountId,
|
|
742
|
+
normalizedRecord.workerName,
|
|
743
|
+
normalizedRecord.versionId,
|
|
744
|
+
normalizedRecord.previewUrl,
|
|
745
|
+
normalizedRecord.scope ?? null,
|
|
746
|
+
normalizedRecord.scopeUrl ?? null,
|
|
747
|
+
normalizedRecord.branchName ?? null,
|
|
748
|
+
normalizedRecord.commitSha ?? null,
|
|
749
|
+
normalizedRecord.deploymentId ?? null,
|
|
750
|
+
normalizedRecord.source,
|
|
751
|
+
normalizedRecord.status,
|
|
752
|
+
normalizedRecord.createdBy,
|
|
753
|
+
normalizedRecord.createdAt.toISOString(),
|
|
754
|
+
toIsoString(normalizedRecord.updatedAt),
|
|
755
|
+
toIsoString(normalizedRecord.deletedAt),
|
|
756
|
+
JSON.stringify(normalizedRecord)
|
|
757
|
+
], apiOptions);
|
|
758
|
+
}
|
|
759
|
+
async function upsertPreviewScopeRecord(registry, record, apiOptions) {
|
|
760
|
+
const normalizedRecord = devflarePreviewScopeRecordSchema.parse(record);
|
|
761
|
+
await runStatement(registry, `INSERT INTO devflare_preview_scope_records (
|
|
762
|
+
id,
|
|
763
|
+
ver,
|
|
764
|
+
account_id,
|
|
765
|
+
worker_name,
|
|
766
|
+
scope,
|
|
767
|
+
scope_url,
|
|
768
|
+
version_id,
|
|
769
|
+
preview_id,
|
|
770
|
+
branch_name,
|
|
771
|
+
commit_sha,
|
|
772
|
+
source,
|
|
773
|
+
status,
|
|
774
|
+
created_by,
|
|
775
|
+
created_at,
|
|
776
|
+
updated_at,
|
|
777
|
+
deleted_at,
|
|
778
|
+
payload_json
|
|
779
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
780
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
781
|
+
ver = excluded.ver,
|
|
782
|
+
account_id = excluded.account_id,
|
|
783
|
+
worker_name = excluded.worker_name,
|
|
784
|
+
scope = excluded.scope,
|
|
785
|
+
scope_url = excluded.scope_url,
|
|
786
|
+
version_id = excluded.version_id,
|
|
787
|
+
preview_id = excluded.preview_id,
|
|
788
|
+
branch_name = excluded.branch_name,
|
|
789
|
+
commit_sha = excluded.commit_sha,
|
|
790
|
+
source = excluded.source,
|
|
791
|
+
status = excluded.status,
|
|
792
|
+
created_by = excluded.created_by,
|
|
793
|
+
created_at = excluded.created_at,
|
|
794
|
+
updated_at = excluded.updated_at,
|
|
795
|
+
deleted_at = excluded.deleted_at,
|
|
796
|
+
payload_json = excluded.payload_json`, [
|
|
797
|
+
normalizedRecord.id,
|
|
798
|
+
normalizedRecord.ver,
|
|
799
|
+
normalizedRecord.accountId,
|
|
800
|
+
normalizedRecord.workerName,
|
|
801
|
+
normalizedRecord.scope,
|
|
802
|
+
normalizedRecord.scopeUrl,
|
|
803
|
+
normalizedRecord.versionId,
|
|
804
|
+
normalizedRecord.previewId ?? null,
|
|
805
|
+
normalizedRecord.branchName ?? null,
|
|
806
|
+
normalizedRecord.commitSha ?? null,
|
|
807
|
+
normalizedRecord.source,
|
|
808
|
+
normalizedRecord.status,
|
|
809
|
+
normalizedRecord.createdBy,
|
|
810
|
+
normalizedRecord.createdAt.toISOString(),
|
|
811
|
+
toIsoString(normalizedRecord.updatedAt),
|
|
812
|
+
toIsoString(normalizedRecord.deletedAt),
|
|
813
|
+
JSON.stringify(normalizedRecord)
|
|
814
|
+
], apiOptions);
|
|
815
|
+
}
|
|
816
|
+
async function upsertDeploymentRecord(registry, record, apiOptions) {
|
|
817
|
+
const normalizedRecord = devflareDeploymentRecordSchema.parse(record);
|
|
818
|
+
await runStatement(registry, `INSERT INTO devflare_deployment_records (
|
|
819
|
+
id,
|
|
820
|
+
ver,
|
|
821
|
+
account_id,
|
|
822
|
+
worker_name,
|
|
823
|
+
deployment_id,
|
|
824
|
+
channel,
|
|
825
|
+
status,
|
|
826
|
+
version_id,
|
|
827
|
+
preview_id,
|
|
828
|
+
environment,
|
|
829
|
+
url,
|
|
830
|
+
message,
|
|
831
|
+
commit_sha,
|
|
832
|
+
source,
|
|
833
|
+
created_by,
|
|
834
|
+
created_at,
|
|
835
|
+
updated_at,
|
|
836
|
+
deleted_at,
|
|
837
|
+
payload_json
|
|
838
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
839
|
+
ON CONFLICT(id) DO UPDATE SET
|
|
840
|
+
ver = excluded.ver,
|
|
841
|
+
account_id = excluded.account_id,
|
|
842
|
+
worker_name = excluded.worker_name,
|
|
843
|
+
deployment_id = excluded.deployment_id,
|
|
844
|
+
channel = excluded.channel,
|
|
845
|
+
status = excluded.status,
|
|
846
|
+
version_id = excluded.version_id,
|
|
847
|
+
preview_id = excluded.preview_id,
|
|
848
|
+
environment = excluded.environment,
|
|
849
|
+
url = excluded.url,
|
|
850
|
+
message = excluded.message,
|
|
851
|
+
commit_sha = excluded.commit_sha,
|
|
852
|
+
source = excluded.source,
|
|
853
|
+
created_by = excluded.created_by,
|
|
854
|
+
created_at = excluded.created_at,
|
|
855
|
+
updated_at = excluded.updated_at,
|
|
856
|
+
deleted_at = excluded.deleted_at,
|
|
857
|
+
payload_json = excluded.payload_json`, [
|
|
858
|
+
normalizedRecord.id,
|
|
859
|
+
normalizedRecord.ver,
|
|
860
|
+
normalizedRecord.accountId,
|
|
861
|
+
normalizedRecord.workerName,
|
|
862
|
+
normalizedRecord.deploymentId,
|
|
863
|
+
normalizedRecord.channel,
|
|
864
|
+
normalizedRecord.status,
|
|
865
|
+
normalizedRecord.versionId,
|
|
866
|
+
normalizedRecord.previewId ?? null,
|
|
867
|
+
normalizedRecord.environment ?? null,
|
|
868
|
+
normalizedRecord.url ?? null,
|
|
869
|
+
normalizedRecord.message ?? null,
|
|
870
|
+
normalizedRecord.commitSha ?? null,
|
|
871
|
+
normalizedRecord.source,
|
|
872
|
+
normalizedRecord.createdBy,
|
|
873
|
+
normalizedRecord.createdAt.toISOString(),
|
|
874
|
+
toIsoString(normalizedRecord.updatedAt),
|
|
875
|
+
toIsoString(normalizedRecord.deletedAt),
|
|
876
|
+
JSON.stringify(normalizedRecord)
|
|
877
|
+
], apiOptions);
|
|
878
|
+
}
|
|
879
|
+
//#endregion
|
|
880
|
+
//#region src/cloudflare/preview-registry.ts
|
|
881
|
+
async function withRegistryReadRecovery(registry, apiOptions, operation) {
|
|
882
|
+
try {
|
|
883
|
+
return {
|
|
884
|
+
registry,
|
|
885
|
+
result: await operation(registry)
|
|
886
|
+
};
|
|
887
|
+
} catch (error) {
|
|
888
|
+
if (isMissingRegistrySchemaError(error)) {
|
|
889
|
+
clearPreviewRegistrySchemaCache(registry.databaseId);
|
|
890
|
+
await ensurePreviewRegistrySchema(registry, apiOptions);
|
|
891
|
+
return {
|
|
892
|
+
registry,
|
|
893
|
+
result: await operation(registry)
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
if (!isUnavailableRegistryContextError(error)) throw error;
|
|
897
|
+
clearCachedPreviewRegistryContext(registry.accountId, registry.databaseName);
|
|
898
|
+
const refreshedRegistry = await ensurePreviewRegistry({
|
|
899
|
+
accountId: registry.accountId,
|
|
900
|
+
databaseName: registry.databaseName,
|
|
901
|
+
apiOptions,
|
|
902
|
+
skipContextCache: true
|
|
903
|
+
});
|
|
904
|
+
return {
|
|
905
|
+
registry: refreshedRegistry,
|
|
906
|
+
result: await operation(refreshedRegistry)
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
async function loadTrackedRegistryRows(registry, workerName, apiOptions) {
|
|
911
|
+
const [previews, scopes, deployments] = await Promise.all([
|
|
912
|
+
readPreviewRows(registry, workerName, apiOptions),
|
|
913
|
+
readPreviewScopeRows(registry, workerName, apiOptions),
|
|
914
|
+
readDeploymentRows(registry, workerName, apiOptions)
|
|
915
|
+
]);
|
|
916
|
+
return {
|
|
917
|
+
previews,
|
|
918
|
+
scopes,
|
|
919
|
+
deployments
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
async function applyDeletedRecords(registry, options) {
|
|
923
|
+
for (const preview of options.previews) await upsertPreviewRecord(registry, markPreviewRecordDeleted(preview, options.now), options.apiOptions);
|
|
924
|
+
for (const scope of options.scopes) await upsertPreviewScopeRecord(registry, markPreviewScopeRecordDeleted(scope, options.now), options.apiOptions);
|
|
925
|
+
for (const deployment of options.deployments) await upsertDeploymentRecord(registry, markDeploymentRecordDeleted(deployment, options.now), options.apiOptions);
|
|
926
|
+
}
|
|
927
|
+
async function getPreviewRegistryContext(options) {
|
|
928
|
+
const databaseName = getRegistryDatabaseName(options.databaseName);
|
|
929
|
+
if (options.skipContextCache !== true) {
|
|
930
|
+
const cached = getCachedPreviewRegistryContext(options.accountId, databaseName);
|
|
931
|
+
if (cached) return cached;
|
|
932
|
+
}
|
|
933
|
+
const existing = (await listD1Databases(options.accountId, options.apiOptions)).find((database) => database.name === databaseName);
|
|
934
|
+
if (!existing) return null;
|
|
935
|
+
const registry = {
|
|
936
|
+
accountId: options.accountId,
|
|
937
|
+
databaseId: existing.id,
|
|
938
|
+
databaseName,
|
|
939
|
+
created: false
|
|
940
|
+
};
|
|
941
|
+
cachePreviewRegistryContext(registry);
|
|
942
|
+
return registry;
|
|
943
|
+
}
|
|
944
|
+
async function ensurePreviewRegistry(options) {
|
|
945
|
+
let registry = await getPreviewRegistryContext(options);
|
|
946
|
+
if (!registry) {
|
|
947
|
+
const created = await createD1Database(options.accountId, getRegistryDatabaseName(options.databaseName), options.apiOptions);
|
|
948
|
+
registry = {
|
|
949
|
+
accountId: options.accountId,
|
|
950
|
+
databaseId: created.id,
|
|
951
|
+
databaseName: created.name,
|
|
952
|
+
created: true
|
|
953
|
+
};
|
|
954
|
+
cachePreviewRegistryContext(registry);
|
|
955
|
+
options.logger?.info?.(`Created Devflare preview registry D1 database: ${registry.databaseName}`);
|
|
956
|
+
}
|
|
957
|
+
if (registry.created || options.skipSchemaIfExisting !== true) await ensurePreviewRegistrySchema(registry, options.apiOptions);
|
|
958
|
+
return registry;
|
|
959
|
+
}
|
|
960
|
+
async function listTrackedRegistryState(options) {
|
|
961
|
+
const { result } = await withRegistryReadRecovery(options.registry, options.apiOptions, async (registry) => {
|
|
962
|
+
return loadTrackedRegistryRows(registry, options.workerName, options.apiOptions);
|
|
963
|
+
});
|
|
964
|
+
return result;
|
|
965
|
+
}
|
|
966
|
+
async function listTrackedPreviewRecords(options) {
|
|
967
|
+
const { registry: resolvedRegistry, result } = await withRegistryReadRecovery(await ensurePreviewRegistry({
|
|
968
|
+
accountId: options.accountId,
|
|
969
|
+
databaseName: options.databaseName,
|
|
970
|
+
apiOptions: options.apiOptions,
|
|
971
|
+
skipSchemaIfExisting: true
|
|
972
|
+
}), options.apiOptions, (activeRegistry) => readPreviewRows(activeRegistry, options.workerName, options.apiOptions));
|
|
973
|
+
return {
|
|
974
|
+
registry: resolvedRegistry,
|
|
975
|
+
records: result
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
async function listTrackedPreviewScopeRecords(options) {
|
|
979
|
+
const { registry: resolvedRegistry, result } = await withRegistryReadRecovery(await ensurePreviewRegistry({
|
|
980
|
+
accountId: options.accountId,
|
|
981
|
+
databaseName: options.databaseName,
|
|
982
|
+
apiOptions: options.apiOptions,
|
|
983
|
+
skipSchemaIfExisting: true
|
|
984
|
+
}), options.apiOptions, (activeRegistry) => readPreviewScopeRows(activeRegistry, options.workerName, options.apiOptions));
|
|
985
|
+
return {
|
|
986
|
+
registry: resolvedRegistry,
|
|
987
|
+
records: result
|
|
988
|
+
};
|
|
989
|
+
}
|
|
990
|
+
async function listTrackedDeploymentRecords(options) {
|
|
991
|
+
const { registry: resolvedRegistry, result } = await withRegistryReadRecovery(await ensurePreviewRegistry({
|
|
992
|
+
accountId: options.accountId,
|
|
993
|
+
databaseName: options.databaseName,
|
|
994
|
+
apiOptions: options.apiOptions,
|
|
995
|
+
skipSchemaIfExisting: true
|
|
996
|
+
}), options.apiOptions, (activeRegistry) => readDeploymentRows(activeRegistry, options.workerName, options.apiOptions));
|
|
997
|
+
return {
|
|
998
|
+
registry: resolvedRegistry,
|
|
999
|
+
records: result
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
async function reconcilePreviewRegistry(options) {
|
|
1003
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
1004
|
+
const registry = await ensurePreviewRegistry({
|
|
1005
|
+
accountId: options.accountId,
|
|
1006
|
+
databaseName: options.databaseName,
|
|
1007
|
+
apiOptions: options.apiOptions,
|
|
1008
|
+
logger: options.logger
|
|
1009
|
+
});
|
|
1010
|
+
const workersSubdomain = await getWorkersSubdomain(options.accountId, options.apiOptions);
|
|
1011
|
+
const liveVersions = await listWorkerVersions(options.accountId, options.workerName, options.apiOptions);
|
|
1012
|
+
const liveDeployments = await listWorkerDeployments(options.accountId, options.workerName, options.apiOptions);
|
|
1013
|
+
const { previews: previewRecords, scopes: scopeRecords, deployments: deploymentRecords } = await loadTrackedRegistryRows(registry, options.workerName, options.apiOptions);
|
|
1014
|
+
const previewRecordByVersionId = new Map(previewRecords.map((record) => [record.versionId, record]));
|
|
1015
|
+
const previewScopeRecordByScope = new Map(scopeRecords.map((record) => [record.scope, record]));
|
|
1016
|
+
const deploymentRecordById = new Map(deploymentRecords.map((record) => [record.deploymentId, record]));
|
|
1017
|
+
const syncedPreviews = [];
|
|
1018
|
+
const syncedScopes = [];
|
|
1019
|
+
const syncedDeployments = [];
|
|
1020
|
+
const versionMetadataMap = new Map(liveVersions.map((version) => [version.id, version]));
|
|
1021
|
+
const previewVersions = [...liveVersions.filter((candidate) => candidate.metadata.hasPreview)];
|
|
1022
|
+
if (options.versionId && (options.previewUrl || options.previewScopeUrl || options.previewScope) && !previewVersions.some((version) => version.id === options.versionId)) {
|
|
1023
|
+
const explicitPreviewVersion = await getVersionInfoById(options.accountId, options.workerName, options.versionId, versionMetadataMap, options.apiOptions);
|
|
1024
|
+
if (explicitPreviewVersion) previewVersions.unshift({
|
|
1025
|
+
...explicitPreviewVersion,
|
|
1026
|
+
metadata: {
|
|
1027
|
+
...explicitPreviewVersion.metadata,
|
|
1028
|
+
hasPreview: true
|
|
1029
|
+
}
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
for (const version of previewVersions) {
|
|
1033
|
+
const previewRecord = buildPreviewRecord({
|
|
1034
|
+
accountId: options.accountId,
|
|
1035
|
+
workerName: options.workerName,
|
|
1036
|
+
version,
|
|
1037
|
+
existing: previewRecordByVersionId.get(version.id),
|
|
1038
|
+
workersSubdomain,
|
|
1039
|
+
...getExplicitPreviewSyncOverrides(options, version.id),
|
|
1040
|
+
source: options.source,
|
|
1041
|
+
now
|
|
1042
|
+
});
|
|
1043
|
+
if (!previewRecord) {
|
|
1044
|
+
options.logger?.warn?.(`Skipping preview registry sync for ${version.id} because no preview URL could be determined.`);
|
|
1045
|
+
continue;
|
|
1046
|
+
}
|
|
1047
|
+
await upsertPreviewRecord(registry, previewRecord, options.apiOptions);
|
|
1048
|
+
syncedPreviews.push(previewRecord);
|
|
1049
|
+
const scopeRecord = buildPreviewScopeRecord({
|
|
1050
|
+
accountId: options.accountId,
|
|
1051
|
+
workerName: options.workerName,
|
|
1052
|
+
previewRecord,
|
|
1053
|
+
existing: previewRecord.scope ? previewScopeRecordByScope.get(previewRecord.scope) : void 0,
|
|
1054
|
+
now
|
|
1055
|
+
});
|
|
1056
|
+
if (scopeRecord) {
|
|
1057
|
+
await upsertPreviewScopeRecord(registry, scopeRecord, options.apiOptions);
|
|
1058
|
+
syncedScopes.push(scopeRecord);
|
|
1059
|
+
}
|
|
1060
|
+
const previewDeploymentRecord = buildPreviewDeploymentRecord({
|
|
1061
|
+
accountId: options.accountId,
|
|
1062
|
+
workerName: options.workerName,
|
|
1063
|
+
previewRecord,
|
|
1064
|
+
existing: deploymentRecordById.get(getPreviewDeploymentId(options.workerName, previewRecord.versionId)),
|
|
1065
|
+
now
|
|
1066
|
+
});
|
|
1067
|
+
await upsertDeploymentRecord(registry, previewDeploymentRecord, options.apiOptions);
|
|
1068
|
+
syncedDeployments.push(previewDeploymentRecord);
|
|
1069
|
+
}
|
|
1070
|
+
for (const [index, deployment] of liveDeployments.entries()) {
|
|
1071
|
+
const versionId = deployment.versions[0]?.versionId;
|
|
1072
|
+
const version = versionId ? await getVersionInfoById(options.accountId, options.workerName, versionId, versionMetadataMap, options.apiOptions) : void 0;
|
|
1073
|
+
const deploymentRecord = buildProductionDeploymentRecord({
|
|
1074
|
+
accountId: options.accountId,
|
|
1075
|
+
workerName: options.workerName,
|
|
1076
|
+
deployment,
|
|
1077
|
+
version,
|
|
1078
|
+
existing: deploymentRecordById.get(deployment.id),
|
|
1079
|
+
workersSubdomain,
|
|
1080
|
+
source: options.source,
|
|
1081
|
+
commitSha: versionId === options.versionId ? options.commitSha : void 0,
|
|
1082
|
+
deploymentMessage: index === 0 ? options.deploymentMessage : void 0,
|
|
1083
|
+
status: index === 0 ? "active" : "superseded",
|
|
1084
|
+
now
|
|
1085
|
+
});
|
|
1086
|
+
if (!deploymentRecord) continue;
|
|
1087
|
+
await upsertDeploymentRecord(registry, deploymentRecord, options.apiOptions);
|
|
1088
|
+
syncedDeployments.push(deploymentRecord);
|
|
1089
|
+
}
|
|
1090
|
+
return {
|
|
1091
|
+
registry,
|
|
1092
|
+
previews: syncedPreviews,
|
|
1093
|
+
previewScopes: syncedScopes,
|
|
1094
|
+
deployments: syncedDeployments
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
1097
|
+
async function cleanupPreviewRegistry(options) {
|
|
1098
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
1099
|
+
const registry = await ensurePreviewRegistry({
|
|
1100
|
+
accountId: options.accountId,
|
|
1101
|
+
databaseName: options.databaseName,
|
|
1102
|
+
apiOptions: options.apiOptions,
|
|
1103
|
+
logger: options.logger
|
|
1104
|
+
});
|
|
1105
|
+
const { previews, scopes, deployments } = await loadTrackedRegistryRows(registry, options.workerName, options.apiOptions);
|
|
1106
|
+
const cutoff = /* @__PURE__ */ new Date(now.getTime() - Math.max(options.days ?? 7, 0) * 24 * 60 * 60 * 1e3);
|
|
1107
|
+
const previewCandidates = previews.filter((record) => !record.deletedAt && record.createdAt <= cutoff && record.status !== "active");
|
|
1108
|
+
const scopeCandidates = scopes.filter((record) => !record.deletedAt && record.createdAt <= cutoff && record.status !== "active");
|
|
1109
|
+
const deploymentCandidates = deployments.filter((record) => !record.deletedAt && record.createdAt <= cutoff && record.status !== "active");
|
|
1110
|
+
if (options.apply) await applyDeletedRecords(registry, {
|
|
1111
|
+
previews: previewCandidates,
|
|
1112
|
+
scopes: scopeCandidates,
|
|
1113
|
+
deployments: deploymentCandidates,
|
|
1114
|
+
now,
|
|
1115
|
+
apiOptions: options.apiOptions
|
|
1116
|
+
});
|
|
1117
|
+
return {
|
|
1118
|
+
registry,
|
|
1119
|
+
previews,
|
|
1120
|
+
scopes,
|
|
1121
|
+
deployments,
|
|
1122
|
+
candidates: {
|
|
1123
|
+
previews: previewCandidates,
|
|
1124
|
+
scopes: scopeCandidates,
|
|
1125
|
+
deployments: deploymentCandidates
|
|
1126
|
+
},
|
|
1127
|
+
applied: options.apply === true
|
|
1128
|
+
};
|
|
1129
|
+
}
|
|
1130
|
+
async function retirePreviewRegistry(options) {
|
|
1131
|
+
if (!hasRetireSelector(options)) throw new Error("Retiring preview registry records requires at least one selector: branchName, previewScope, versionId, or commitSha.");
|
|
1132
|
+
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
1133
|
+
const registry = await ensurePreviewRegistry({
|
|
1134
|
+
accountId: options.accountId,
|
|
1135
|
+
databaseName: options.databaseName,
|
|
1136
|
+
apiOptions: options.apiOptions,
|
|
1137
|
+
logger: options.logger
|
|
1138
|
+
});
|
|
1139
|
+
const { previews, scopes, deployments } = await loadTrackedRegistryRows(registry, options.workerName, options.apiOptions);
|
|
1140
|
+
const directlyMatchedPreviews = previews.filter((record) => !record.deletedAt && matchesPreviewRetireTarget(record, options));
|
|
1141
|
+
const directlyMatchedScopes = scopes.filter((record) => !record.deletedAt && matchesPreviewScopeRetireTarget(record, options));
|
|
1142
|
+
const directlyMatchedDeployments = deployments.filter((record) => !record.deletedAt && matchesPreviewDeploymentRetireTarget(record, options));
|
|
1143
|
+
const candidatePreviewIds = new Set([...directlyMatchedPreviews.map((record) => record.id), ...directlyMatchedScopes.flatMap((record) => record.previewId ? [record.previewId] : [])]);
|
|
1144
|
+
const candidateVersionIds = new Set([
|
|
1145
|
+
...directlyMatchedPreviews.map((record) => record.versionId),
|
|
1146
|
+
...directlyMatchedScopes.map((record) => record.versionId),
|
|
1147
|
+
...directlyMatchedDeployments.map((record) => record.versionId),
|
|
1148
|
+
...options.versionId ? [options.versionId] : []
|
|
1149
|
+
]);
|
|
1150
|
+
const previewCandidates = previews.filter((record) => {
|
|
1151
|
+
return !record.deletedAt && (matchesPreviewRetireTarget(record, options) || candidatePreviewIds.has(record.id) || candidateVersionIds.has(record.versionId));
|
|
1152
|
+
});
|
|
1153
|
+
const resolvedPreviewIds = new Set(previewCandidates.map((record) => record.id));
|
|
1154
|
+
const resolvedVersionIds = new Set([...candidateVersionIds, ...previewCandidates.map((record) => record.versionId)]);
|
|
1155
|
+
const scopeCandidates = scopes.filter((record) => {
|
|
1156
|
+
return !record.deletedAt && (matchesPreviewScopeRetireTarget(record, options) || resolvedVersionIds.has(record.versionId) || record.previewId !== void 0 && resolvedPreviewIds.has(record.previewId));
|
|
1157
|
+
});
|
|
1158
|
+
for (const record of scopeCandidates) {
|
|
1159
|
+
resolvedVersionIds.add(record.versionId);
|
|
1160
|
+
if (record.previewId) resolvedPreviewIds.add(record.previewId);
|
|
1161
|
+
}
|
|
1162
|
+
const deploymentCandidates = deployments.filter((record) => {
|
|
1163
|
+
return !record.deletedAt && record.channel === "preview" && (matchesPreviewDeploymentRetireTarget(record, options) || resolvedVersionIds.has(record.versionId) || record.previewId !== void 0 && resolvedPreviewIds.has(record.previewId));
|
|
1164
|
+
});
|
|
1165
|
+
if (options.apply) await applyDeletedRecords(registry, {
|
|
1166
|
+
previews: previewCandidates,
|
|
1167
|
+
scopes: scopeCandidates,
|
|
1168
|
+
deployments: deploymentCandidates,
|
|
1169
|
+
now,
|
|
1170
|
+
apiOptions: options.apiOptions
|
|
1171
|
+
});
|
|
1172
|
+
return {
|
|
1173
|
+
registry,
|
|
1174
|
+
previews,
|
|
1175
|
+
scopes,
|
|
1176
|
+
deployments,
|
|
1177
|
+
candidates: {
|
|
1178
|
+
previews: previewCandidates,
|
|
1179
|
+
scopes: scopeCandidates,
|
|
1180
|
+
deployments: deploymentCandidates
|
|
1181
|
+
},
|
|
1182
|
+
applied: options.apply === true
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
//#endregion
|
|
1186
|
+
export { deleteWorker as C, listWorkerVersions as D, listWorkerDeployments as E, listWorkers as O, DEVFLARE_PREVIEW_REGISTRY_DATABASE as S, getWorkersSubdomain as T, devflarePreviewScopeRecordSchema as _, listTrackedPreviewRecords as a, devflareRecordSourceSchema as b, reconcilePreviewRegistry as c, devflareAccountLayerRecordSchema as d, devflareAccountRecordSchema as f, devflarePreviewRecordSchema as g, devflareDeploymentStatusSchema as h, listTrackedDeploymentRecords as i, renameWorker as k, retirePreviewRegistry as l, devflareDeploymentRecordSchema as m, ensurePreviewRegistry as n, listTrackedPreviewScopeRecords as o, devflareDeploymentChannelSchema as p, getPreviewRegistryContext as r, listTrackedRegistryState as s, cleanupPreviewRegistry as t, createDevflareAccountRecordSchema as u, devflarePreviewScopeStatusSchema as v, getWorkerVersionDetail as w, formatWorkersDevUrl as x, devflarePreviewStatusSchema as y };
|