alchemy 0.16.9 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ai/astro-file.d.ts +1 -1
- package/lib/ai/astro-file.d.ts.map +1 -1
- package/lib/ai/astro-file.js +1 -1
- package/lib/ai/astro-file.js.map +1 -1
- package/lib/ai/client.js +2 -2
- package/lib/ai/client.js.map +1 -1
- package/lib/ai/css-file.d.ts +1 -1
- package/lib/ai/css-file.d.ts.map +1 -1
- package/lib/ai/css-file.js +1 -1
- package/lib/ai/css-file.js.map +1 -1
- package/lib/ai/data.d.ts +1 -1
- package/lib/ai/data.d.ts.map +1 -1
- package/lib/ai/data.js +1 -1
- package/lib/ai/data.js.map +1 -1
- package/lib/ai/html-file.d.ts +1 -1
- package/lib/ai/html-file.d.ts.map +1 -1
- package/lib/ai/html-file.js +1 -1
- package/lib/ai/html-file.js.map +1 -1
- package/lib/ai/json-file.d.ts +1 -1
- package/lib/ai/json-file.d.ts.map +1 -1
- package/lib/ai/json-file.js +1 -1
- package/lib/ai/json-file.js.map +1 -1
- package/lib/ai/typescript-file.d.ts +1 -1
- package/lib/ai/typescript-file.d.ts.map +1 -1
- package/lib/ai/typescript-file.js +1 -1
- package/lib/ai/typescript-file.js.map +1 -1
- package/lib/ai/vue-file.d.ts +1 -1
- package/lib/ai/vue-file.d.ts.map +1 -1
- package/lib/ai/vue-file.js +1 -1
- package/lib/ai/vue-file.js.map +1 -1
- package/lib/ai/yaml-file.d.ts +1 -1
- package/lib/ai/yaml-file.d.ts.map +1 -1
- package/lib/ai/yaml-file.js +2 -2
- package/lib/ai/yaml-file.js.map +1 -1
- package/lib/alchemy.d.ts +4 -0
- package/lib/alchemy.d.ts.map +1 -1
- package/lib/alchemy.js +14 -4
- package/lib/alchemy.js.map +1 -1
- package/lib/apply.d.ts +2 -0
- package/lib/apply.d.ts.map +1 -1
- package/lib/apply.js +17 -2
- package/lib/apply.js.map +1 -1
- package/lib/aws/bucket.d.ts +1 -1
- package/lib/aws/bucket.d.ts.map +1 -1
- package/lib/aws/bucket.js +1 -1
- package/lib/aws/bucket.js.map +1 -1
- package/lib/aws/function.d.ts +1 -1
- package/lib/aws/function.d.ts.map +1 -1
- package/lib/aws/function.js +2 -2
- package/lib/aws/function.js.map +1 -1
- package/lib/aws/oidc/oidc-provider.d.ts +1 -1
- package/lib/aws/oidc/oidc-provider.d.ts.map +1 -1
- package/lib/aws/oidc/oidc-provider.js +1 -1
- package/lib/aws/oidc/oidc-provider.js.map +1 -1
- package/lib/aws/policy-attachment.d.ts +1 -1
- package/lib/aws/policy-attachment.d.ts.map +1 -1
- package/lib/aws/policy-attachment.js +1 -1
- package/lib/aws/policy-attachment.js.map +1 -1
- package/lib/aws/policy.d.ts +1 -1
- package/lib/aws/policy.d.ts.map +1 -1
- package/lib/aws/policy.js +1 -1
- package/lib/aws/policy.js.map +1 -1
- package/lib/aws/queue.d.ts +1 -1
- package/lib/aws/queue.d.ts.map +1 -1
- package/lib/aws/queue.js +20 -25
- package/lib/aws/queue.js.map +1 -1
- package/lib/aws/role.d.ts +1 -1
- package/lib/aws/role.d.ts.map +1 -1
- package/lib/aws/role.js +1 -1
- package/lib/aws/role.js.map +1 -1
- package/lib/aws/ses.d.ts +1 -1
- package/lib/aws/ses.d.ts.map +1 -1
- package/lib/aws/ses.js +1 -1
- package/lib/aws/ses.js.map +1 -1
- package/lib/aws/table.d.ts +1 -1
- package/lib/aws/table.d.ts.map +1 -1
- package/lib/aws/table.js +1 -1
- package/lib/aws/table.js.map +1 -1
- package/lib/cloudflare/account-api-token.d.ts +1 -1
- package/lib/cloudflare/account-api-token.d.ts.map +1 -1
- package/lib/cloudflare/account-api-token.js +1 -1
- package/lib/cloudflare/account-api-token.js.map +1 -1
- package/lib/cloudflare/ai-gateway.d.ts +4 -3
- package/lib/cloudflare/ai-gateway.d.ts.map +1 -1
- package/lib/cloudflare/ai-gateway.js +13 -1
- package/lib/cloudflare/ai-gateway.js.map +1 -1
- package/lib/cloudflare/analytics-engine.d.ts +21 -0
- package/lib/cloudflare/analytics-engine.d.ts.map +1 -0
- package/lib/cloudflare/analytics-engine.js +17 -0
- package/lib/cloudflare/analytics-engine.js.map +1 -0
- package/lib/cloudflare/api-error.js +1 -1
- package/lib/cloudflare/api-error.js.map +1 -1
- package/lib/cloudflare/assets.js +2 -2
- package/lib/cloudflare/assets.js.map +1 -1
- package/lib/cloudflare/auth.js +1 -1
- package/lib/cloudflare/auth.js.map +1 -1
- package/lib/cloudflare/bindings.d.ts +18 -11
- package/lib/cloudflare/bindings.d.ts.map +1 -1
- package/lib/cloudflare/bindings.js +6 -0
- package/lib/cloudflare/bindings.js.map +1 -1
- package/lib/cloudflare/bound.d.ts +12 -10
- package/lib/cloudflare/bound.d.ts.map +1 -1
- package/lib/cloudflare/bucket.d.ts +6 -4
- package/lib/cloudflare/bucket.d.ts.map +1 -1
- package/lib/cloudflare/bucket.js +22 -2
- package/lib/cloudflare/bucket.js.map +1 -1
- package/lib/cloudflare/bundle/bundle-worker.d.ts +1 -0
- package/lib/cloudflare/bundle/bundle-worker.d.ts.map +1 -1
- package/lib/cloudflare/bundle/bundle-worker.js +4 -2
- package/lib/cloudflare/bundle/bundle-worker.js.map +1 -1
- package/lib/cloudflare/bundle/nodejs-compat-mode.d.ts +1 -1
- package/lib/cloudflare/bundle/nodejs-compat-mode.d.ts.map +1 -1
- package/lib/cloudflare/bundle/nodejs-compat-mode.js +2 -2
- package/lib/cloudflare/bundle/nodejs-compat-mode.js.map +1 -1
- package/lib/cloudflare/bundle/nodejs-compat.js +1 -1
- package/lib/cloudflare/bundle/nodejs-compat.js.map +1 -1
- package/lib/cloudflare/custom-domain.js +1 -1
- package/lib/cloudflare/custom-domain.js.map +1 -1
- package/lib/cloudflare/d1-database.d.ts +4 -62
- package/lib/cloudflare/d1-database.d.ts.map +1 -1
- package/lib/cloudflare/d1-database.js +27 -11
- package/lib/cloudflare/d1-database.js.map +1 -1
- package/lib/cloudflare/dns-records.d.ts +1 -1
- package/lib/cloudflare/dns-records.d.ts.map +1 -1
- package/lib/cloudflare/dns-records.js +2 -2
- package/lib/cloudflare/dns-records.js.map +1 -1
- package/lib/cloudflare/event-source.d.ts +3 -3
- package/lib/cloudflare/event-source.d.ts.map +1 -1
- package/lib/cloudflare/hyperdrive.d.ts +4 -3
- package/lib/cloudflare/hyperdrive.d.ts.map +1 -1
- package/lib/cloudflare/hyperdrive.js +9 -1
- package/lib/cloudflare/hyperdrive.js.map +1 -1
- package/lib/cloudflare/kv-namespace.d.ts +9 -5
- package/lib/cloudflare/kv-namespace.d.ts.map +1 -1
- package/lib/cloudflare/kv-namespace.js +26 -6
- package/lib/cloudflare/kv-namespace.js.map +1 -1
- package/lib/cloudflare/permission-groups.d.ts +1 -1
- package/lib/cloudflare/permission-groups.d.ts.map +1 -1
- package/lib/cloudflare/permission-groups.js +1 -1
- package/lib/cloudflare/permission-groups.js.map +1 -1
- package/lib/cloudflare/pipeline.d.ts +5 -3
- package/lib/cloudflare/pipeline.d.ts.map +1 -1
- package/lib/cloudflare/pipeline.js +16 -2
- package/lib/cloudflare/pipeline.js.map +1 -1
- package/lib/cloudflare/queue-consumer.d.ts +3 -3
- package/lib/cloudflare/queue-consumer.d.ts.map +1 -1
- package/lib/cloudflare/queue-consumer.js +1 -1
- package/lib/cloudflare/queue-consumer.js.map +1 -1
- package/lib/cloudflare/queue.d.ts +34 -22
- package/lib/cloudflare/queue.d.ts.map +1 -1
- package/lib/cloudflare/queue.js +66 -4
- package/lib/cloudflare/queue.js.map +1 -1
- package/lib/cloudflare/route.d.ts +1 -1
- package/lib/cloudflare/route.d.ts.map +1 -1
- package/lib/cloudflare/route.js +1 -1
- package/lib/cloudflare/route.js.map +1 -1
- package/lib/cloudflare/types.js +1 -1
- package/lib/cloudflare/types.js.map +1 -1
- package/lib/cloudflare/vectorize-index.d.ts +6 -4
- package/lib/cloudflare/vectorize-index.d.ts.map +1 -1
- package/lib/cloudflare/vectorize-index.js +20 -3
- package/lib/cloudflare/vectorize-index.js.map +1 -1
- package/lib/cloudflare/vectorize-metadata-index.d.ts +4 -3
- package/lib/cloudflare/vectorize-metadata-index.d.ts.map +1 -1
- package/lib/cloudflare/vectorize-metadata-index.js +5 -2
- package/lib/cloudflare/vectorize-metadata-index.js.map +1 -1
- package/lib/cloudflare/website.d.ts.map +1 -1
- package/lib/cloudflare/website.js +3 -0
- package/lib/cloudflare/website.js.map +1 -1
- package/lib/cloudflare/worker-assets.d.ts +32 -0
- package/lib/cloudflare/worker-assets.d.ts.map +1 -0
- package/lib/cloudflare/worker-assets.js +143 -0
- package/lib/cloudflare/worker-assets.js.map +1 -0
- package/lib/cloudflare/worker-metadata.d.ts +31 -0
- package/lib/cloudflare/worker-metadata.d.ts.map +1 -1
- package/lib/cloudflare/worker-metadata.js +248 -0
- package/lib/cloudflare/worker-metadata.js.map +1 -1
- package/lib/cloudflare/worker-stub.d.ts +40 -0
- package/lib/cloudflare/worker-stub.d.ts.map +1 -0
- package/lib/cloudflare/worker-stub.js +86 -0
- package/lib/cloudflare/worker-stub.js.map +1 -0
- package/lib/cloudflare/worker.d.ts +57 -28
- package/lib/cloudflare/worker.d.ts.map +1 -1
- package/lib/cloudflare/worker.js +203 -472
- package/lib/cloudflare/worker.js.map +1 -1
- package/lib/cloudflare/wrangler.json.d.ts +29 -1
- package/lib/cloudflare/wrangler.json.d.ts.map +1 -1
- package/lib/cloudflare/wrangler.json.js +50 -2
- package/lib/cloudflare/wrangler.json.js.map +1 -1
- package/lib/cloudflare/zone.d.ts +1 -1
- package/lib/cloudflare/zone.d.ts.map +1 -1
- package/lib/cloudflare/zone.js +1 -1
- package/lib/cloudflare/zone.js.map +1 -1
- package/lib/destroy.d.ts +1 -4
- package/lib/destroy.d.ts.map +1 -1
- package/lib/destroy.js +10 -21
- package/lib/destroy.js.map +1 -1
- package/lib/dns/import-dns.d.ts +1 -1
- package/lib/dns/import-dns.d.ts.map +1 -1
- package/lib/dns/import-dns.js +1 -1
- package/lib/dns/import-dns.js.map +1 -1
- package/lib/encrypt.d.ts.map +1 -1
- package/lib/encrypt.js +2 -1
- package/lib/encrypt.js.map +1 -1
- package/lib/env.js +14 -8
- package/lib/env.js.map +1 -1
- package/lib/esbuild/bundle.d.ts +2 -2
- package/lib/esbuild/bundle.d.ts.map +1 -1
- package/lib/esbuild/bundle.js +3 -3
- package/lib/esbuild/bundle.js.map +1 -1
- package/lib/fs/copy-file.d.ts +1 -1
- package/lib/fs/copy-file.d.ts.map +1 -1
- package/lib/fs/copy-file.js +1 -1
- package/lib/fs/copy-file.js.map +1 -1
- package/lib/github/client.js +1 -1
- package/lib/github/client.js.map +1 -1
- package/lib/github/repository-environment.d.ts +1 -1
- package/lib/github/repository-environment.d.ts.map +1 -1
- package/lib/github/repository-environment.js +2 -2
- package/lib/github/repository-environment.js.map +1 -1
- package/lib/github/secret.d.ts +1 -1
- package/lib/github/secret.d.ts.map +1 -1
- package/lib/github/secret.js +1 -1
- package/lib/github/secret.js.map +1 -1
- package/lib/internal/docs/providers.d.ts +1 -1
- package/lib/internal/docs/providers.d.ts.map +1 -1
- package/lib/internal/docs/providers.js +3 -1
- package/lib/internal/docs/providers.js.map +1 -1
- package/lib/neon/api-error.js +2 -2
- package/lib/neon/api-error.js.map +1 -1
- package/lib/os/exec.js +1 -1
- package/lib/os/exec.js.map +1 -1
- package/lib/resource.d.ts +13 -11
- package/lib/resource.d.ts.map +1 -1
- package/lib/resource.js +10 -5
- package/lib/resource.js.map +1 -1
- package/lib/runtime/bind.d.ts +25 -0
- package/lib/runtime/bind.d.ts.map +1 -0
- package/lib/runtime/bind.js +76 -0
- package/lib/runtime/bind.js.map +1 -0
- package/lib/runtime/global.d.ts +8 -0
- package/lib/runtime/global.d.ts.map +1 -0
- package/lib/runtime/global.js +3 -0
- package/lib/runtime/global.js.map +1 -0
- package/lib/runtime/plugin.d.ts +35 -0
- package/lib/runtime/plugin.d.ts.map +1 -0
- package/lib/runtime/plugin.js +133 -0
- package/lib/runtime/plugin.js.map +1 -0
- package/lib/runtime/shims.d.ts +6 -0
- package/lib/runtime/shims.d.ts.map +1 -0
- package/lib/runtime/shims.js +27 -0
- package/lib/runtime/shims.js.map +1 -0
- package/lib/runtime/state.d.ts +5 -0
- package/lib/runtime/state.d.ts.map +1 -0
- package/lib/runtime/state.js +4 -0
- package/lib/runtime/state.js.map +1 -0
- package/lib/scope.d.ts +16 -2
- package/lib/scope.d.ts.map +1 -1
- package/lib/scope.js +56 -9
- package/lib/scope.js.map +1 -1
- package/lib/secret.d.ts +7 -2
- package/lib/secret.d.ts.map +1 -1
- package/lib/secret.js +19 -4
- package/lib/secret.js.map +1 -1
- package/lib/sentry/client-key.d.ts +1 -1
- package/lib/sentry/client-key.d.ts.map +1 -1
- package/lib/sentry/client-key.js +1 -1
- package/lib/sentry/client-key.js.map +1 -1
- package/lib/sentry/project.d.ts +1 -1
- package/lib/sentry/project.d.ts.map +1 -1
- package/lib/sentry/project.js +1 -1
- package/lib/sentry/project.js.map +1 -1
- package/lib/sentry/team.d.ts +1 -1
- package/lib/sentry/team.d.ts.map +1 -1
- package/lib/sentry/team.js +1 -1
- package/lib/sentry/team.js.map +1 -1
- package/lib/serde.d.ts +26 -1
- package/lib/serde.d.ts.map +1 -1
- package/lib/serde.js +53 -8
- package/lib/serde.js.map +1 -1
- package/lib/stripe/meter.d.ts +1 -1
- package/lib/stripe/meter.d.ts.map +1 -1
- package/lib/stripe/meter.js +1 -1
- package/lib/stripe/meter.js.map +1 -1
- package/lib/stripe/price.d.ts +1 -1
- package/lib/stripe/price.d.ts.map +1 -1
- package/lib/stripe/price.js +1 -1
- package/lib/stripe/price.js.map +1 -1
- package/lib/stripe/product.d.ts +1 -1
- package/lib/stripe/product.d.ts.map +1 -1
- package/lib/stripe/product.js +1 -1
- package/lib/stripe/product.js.map +1 -1
- package/lib/stripe/webhook.d.ts +1 -1
- package/lib/stripe/webhook.d.ts.map +1 -1
- package/lib/stripe/webhook.js +1 -1
- package/lib/stripe/webhook.js.map +1 -1
- package/lib/test/bun.js +1 -1
- package/lib/test/bun.js.map +1 -1
- package/lib/test/prune.js +1 -1
- package/lib/test/prune.js.map +1 -1
- package/lib/upstash/redis.d.ts +1 -1
- package/lib/upstash/redis.d.ts.map +1 -1
- package/lib/upstash/redis.js +1 -1
- package/lib/upstash/redis.js.map +1 -1
- package/lib/util/assert-never.d.ts +2 -0
- package/lib/util/assert-never.d.ts.map +1 -0
- package/lib/util/assert-never.js +4 -0
- package/lib/util/assert-never.js.map +1 -0
- package/lib/util/content-type.d.ts +1 -1
- package/lib/util/content-type.d.ts.map +1 -1
- package/lib/util/content-type.js +1 -2
- package/lib/util/content-type.js.map +1 -1
- package/lib/util/retry.d.ts.map +1 -1
- package/lib/util/retry.js +1 -0
- package/lib/util/retry.js.map +1 -1
- package/lib/vercel/project-domain.d.ts +1 -1
- package/lib/vercel/project-domain.d.ts.map +1 -1
- package/lib/vercel/project-domain.js +1 -1
- package/lib/vercel/project-domain.js.map +1 -1
- package/lib/vercel/project.js +1 -1
- package/lib/vercel/project.js.map +1 -1
- package/lib/web/shadcn-component.d.ts +1 -1
- package/lib/web/shadcn-component.d.ts.map +1 -1
- package/lib/web/shadcn-component.js +1 -1
- package/lib/web/shadcn-component.js.map +1 -1
- package/lib/web/shadcn.d.ts +1 -1
- package/lib/web/shadcn.d.ts.map +1 -1
- package/lib/web/shadcn.js +1 -1
- package/lib/web/shadcn.js.map +1 -1
- package/lib/web/vitepress/dependencies.d.ts +1 -1
- package/lib/web/vitepress/dependencies.d.ts.map +1 -1
- package/lib/web/vitepress/dependencies.js +1 -1
- package/lib/web/vitepress/dependencies.js.map +1 -1
- package/lib/web/vitepress/vitepress.js +1 -1
- package/lib/web/vitepress/vitepress.js.map +1 -1
- package/package.json +2 -1
- package/src/ai/astro-file.ts +1 -1
- package/src/ai/client.ts +2 -2
- package/src/ai/css-file.ts +1 -1
- package/src/ai/data.ts +1 -1
- package/src/ai/html-file.ts +1 -1
- package/src/ai/json-file.ts +1 -1
- package/src/ai/typescript-file.ts +1 -1
- package/src/ai/vue-file.ts +1 -1
- package/src/ai/yaml-file.ts +2 -2
- package/src/alchemy.ts +18 -4
- package/src/apply.ts +27 -2
- package/src/aws/bucket.ts +1 -1
- package/src/aws/function.ts +2 -2
- package/src/aws/oidc/oidc-provider.ts +1 -1
- package/src/aws/policy-attachment.ts +1 -1
- package/src/aws/policy.ts +1 -1
- package/src/aws/queue.ts +28 -29
- package/src/aws/role.ts +1 -1
- package/src/aws/ses.ts +1 -1
- package/src/aws/table.ts +1 -1
- package/src/cloudflare/account-api-token.ts +1 -1
- package/src/cloudflare/ai-gateway.ts +23 -4
- package/src/cloudflare/analytics-engine.ts +26 -0
- package/src/cloudflare/api-error.ts +1 -1
- package/src/cloudflare/assets.ts +2 -2
- package/src/cloudflare/auth.ts +1 -1
- package/src/cloudflare/bindings.ts +35 -18
- package/src/cloudflare/bound.ts +27 -23
- package/src/cloudflare/bucket.ts +52 -24
- package/src/cloudflare/bundle/bundle-worker.ts +5 -2
- package/src/cloudflare/bundle/nodejs-compat-mode.ts +3 -3
- package/src/cloudflare/bundle/nodejs-compat.ts +1 -1
- package/src/cloudflare/custom-domain.ts +1 -1
- package/src/cloudflare/d1-database.ts +40 -19
- package/src/cloudflare/dns-records.ts +2 -2
- package/src/cloudflare/event-source.ts +3 -3
- package/src/cloudflare/hyperdrive.ts +19 -4
- package/src/cloudflare/kv-namespace.ts +46 -15
- package/src/cloudflare/permission-groups.ts +1 -1
- package/src/cloudflare/pipeline.ts +29 -6
- package/src/cloudflare/queue-consumer.ts +3 -3
- package/src/cloudflare/queue.ts +124 -23
- package/src/cloudflare/route.ts +1 -1
- package/src/cloudflare/types.ts +1 -1
- package/src/cloudflare/vectorize-index.ts +36 -8
- package/src/cloudflare/vectorize-metadata-index.ts +10 -4
- package/src/cloudflare/website.ts +3 -0
- package/src/cloudflare/worker-assets.ts +237 -0
- package/src/cloudflare/worker-metadata.ts +287 -0
- package/src/cloudflare/worker-stub.ts +153 -0
- package/src/cloudflare/worker.ts +386 -586
- package/src/cloudflare/wrangler.json.ts +75 -2
- package/src/cloudflare/zone.ts +1 -1
- package/src/destroy.ts +12 -23
- package/src/dns/import-dns.ts +1 -1
- package/src/encrypt.ts +2 -2
- package/src/env.ts +15 -8
- package/src/esbuild/bundle.ts +4 -3
- package/src/fs/copy-file.ts +1 -1
- package/src/github/client.ts +1 -1
- package/src/github/repository-environment.ts +2 -2
- package/src/github/secret.ts +1 -1
- package/src/internal/docs/providers.ts +1 -1
- package/src/neon/api-error.ts +2 -2
- package/src/os/exec.ts +1 -1
- package/src/resource.ts +22 -31
- package/src/runtime/bind.ts +95 -0
- package/src/runtime/global.ts +10 -0
- package/src/runtime/plugin.ts +162 -0
- package/src/runtime/shims.js +34 -0
- package/src/runtime/state.ts +9 -0
- package/src/scope.ts +72 -11
- package/src/secret.ts +29 -4
- package/src/sentry/client-key.ts +1 -1
- package/src/sentry/project.ts +1 -1
- package/src/sentry/team.ts +1 -1
- package/src/serde.ts +126 -10
- package/src/stripe/meter.ts +1 -1
- package/src/stripe/price.ts +1 -1
- package/src/stripe/product.ts +1 -1
- package/src/stripe/webhook.ts +1 -1
- package/src/test/bun.ts +1 -1
- package/src/test/prune.ts +1 -1
- package/src/upstash/redis.ts +1 -1
- package/src/util/assert-never.ts +3 -0
- package/src/util/content-type.ts +2 -3
- package/src/util/retry.ts +1 -0
- package/src/vercel/project-domain.ts +1 -1
- package/src/vercel/project.ts +1 -1
- package/src/web/shadcn-component.ts +1 -1
- package/src/web/shadcn.ts +1 -1
- package/src/web/vitepress/dependencies.ts +1 -1
- package/src/web/vitepress/vitepress.ts +1 -1
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { Context } from "../context.js";
|
|
2
|
-
import { Resource } from "../resource.js";
|
|
2
|
+
import { Resource, ResourceKind } from "../resource.js";
|
|
3
|
+
import { bind } from "../runtime/bind.js";
|
|
3
4
|
import { CloudflareApiError, handleApiError } from "./api-error.js";
|
|
4
5
|
import {
|
|
5
6
|
createCloudflareApi,
|
|
6
7
|
type CloudflareApi,
|
|
7
8
|
type CloudflareApiOptions,
|
|
8
9
|
} from "./api.js";
|
|
10
|
+
import type { Bound } from "./bound.js";
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Properties for creating or updating a Vectorize Index
|
|
@@ -48,10 +50,16 @@ export interface VectorizeIndexProps extends CloudflareApiOptions {
|
|
|
48
50
|
adopt?: boolean;
|
|
49
51
|
}
|
|
50
52
|
|
|
53
|
+
export function isVectorizeIndex(
|
|
54
|
+
resource: Resource,
|
|
55
|
+
): resource is VectorizeIndexResource {
|
|
56
|
+
return resource[ResourceKind] === "cloudflare::VectorizeIndex";
|
|
57
|
+
}
|
|
58
|
+
|
|
51
59
|
/**
|
|
52
60
|
* Output returned after Vectorize Index creation/update
|
|
53
61
|
*/
|
|
54
|
-
export interface
|
|
62
|
+
export interface VectorizeIndexResource
|
|
55
63
|
extends Resource<"cloudflare::VectorizeIndex">,
|
|
56
64
|
VectorizeIndexProps {
|
|
57
65
|
type: "vectorize";
|
|
@@ -67,6 +75,9 @@ export interface VectorizeIndex
|
|
|
67
75
|
createdAt?: number;
|
|
68
76
|
}
|
|
69
77
|
|
|
78
|
+
export type VectorizeIndex = VectorizeIndexResource &
|
|
79
|
+
Bound<VectorizeIndexResource>;
|
|
80
|
+
|
|
70
81
|
/**
|
|
71
82
|
* Creates and manages Cloudflare Vectorize Indexes.
|
|
72
83
|
*
|
|
@@ -106,13 +117,30 @@ export interface VectorizeIndex
|
|
|
106
117
|
*
|
|
107
118
|
* @see https://developers.cloudflare.com/vectorize/
|
|
108
119
|
*/
|
|
109
|
-
export
|
|
120
|
+
export async function VectorizeIndex(
|
|
121
|
+
name: string,
|
|
122
|
+
props: VectorizeIndexProps,
|
|
123
|
+
): Promise<VectorizeIndex> {
|
|
124
|
+
const index = await _VectorizeIndex(name, props);
|
|
125
|
+
const binding = await bind(index);
|
|
126
|
+
return {
|
|
127
|
+
...index,
|
|
128
|
+
describe: binding.describe,
|
|
129
|
+
query: binding.query,
|
|
130
|
+
insert: binding.insert,
|
|
131
|
+
upsert: binding.upsert,
|
|
132
|
+
deleteByIds: binding.deleteByIds,
|
|
133
|
+
getByIds: binding.getByIds,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const _VectorizeIndex = Resource(
|
|
110
138
|
"cloudflare::VectorizeIndex",
|
|
111
139
|
async function (
|
|
112
|
-
this: Context<
|
|
140
|
+
this: Context<VectorizeIndexResource>,
|
|
113
141
|
id: string,
|
|
114
142
|
props: VectorizeIndexProps,
|
|
115
|
-
): Promise<
|
|
143
|
+
): Promise<VectorizeIndexResource> {
|
|
116
144
|
const api = await createCloudflareApi(props);
|
|
117
145
|
const indexName = props.name || id;
|
|
118
146
|
|
|
@@ -348,9 +376,9 @@ export async function listIndexes(
|
|
|
348
376
|
* This function will always throw an error.
|
|
349
377
|
*/
|
|
350
378
|
export async function updateIndex(
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
379
|
+
_api: CloudflareApi,
|
|
380
|
+
_indexName: string,
|
|
381
|
+
_props: VectorizeIndexProps,
|
|
354
382
|
): Promise<CloudflareVectorizeResponse> {
|
|
355
383
|
throw new Error(
|
|
356
384
|
"Updating Vectorize indexes is not supported by the Cloudflare API. To change an index, delete it and create a new one.",
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Context } from "../context.js";
|
|
2
|
-
import { Resource } from "../resource.js";
|
|
2
|
+
import { Resource, ResourceKind } from "../resource.js";
|
|
3
3
|
import { CloudflareApiError, handleApiError } from "./api-error.js";
|
|
4
4
|
import {
|
|
5
5
|
createCloudflareApi,
|
|
6
6
|
type CloudflareApi,
|
|
7
7
|
type CloudflareApiOptions,
|
|
8
8
|
} from "./api.js";
|
|
9
|
-
import type {
|
|
9
|
+
import type { VectorizeIndexResource } from "./vectorize-index.js";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Properties for creating or deleting a Vectorize Metadata Index
|
|
@@ -15,7 +15,7 @@ export interface VectorizeMetadataIndexProps extends CloudflareApiOptions {
|
|
|
15
15
|
/**
|
|
16
16
|
* Parent Vectorize Index
|
|
17
17
|
*/
|
|
18
|
-
index:
|
|
18
|
+
index: VectorizeIndexResource;
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Name of the property in the metadata to create an index for
|
|
@@ -28,6 +28,12 @@ export interface VectorizeMetadataIndexProps extends CloudflareApiOptions {
|
|
|
28
28
|
indexType: "string" | "number" | "boolean";
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
export function isVectorizeMetadataIndex(
|
|
32
|
+
resource: Resource,
|
|
33
|
+
): resource is VectorizeMetadataIndex {
|
|
34
|
+
return resource[ResourceKind] === "cloudflare::VectorizeMetadataIndex";
|
|
35
|
+
}
|
|
36
|
+
|
|
31
37
|
/**
|
|
32
38
|
* Output returned after Vectorize Metadata Index creation/deletion
|
|
33
39
|
*/
|
|
@@ -82,7 +88,7 @@ export const VectorizeMetadataIndex = Resource(
|
|
|
82
88
|
"cloudflare::VectorizeMetadataIndex",
|
|
83
89
|
async function (
|
|
84
90
|
this: Context<VectorizeMetadataIndex>,
|
|
85
|
-
|
|
91
|
+
_id: string,
|
|
86
92
|
props: VectorizeMetadataIndexProps,
|
|
87
93
|
): Promise<VectorizeMetadataIndex> {
|
|
88
94
|
const api = await createCloudflareApi(props);
|
|
@@ -96,6 +96,7 @@ export async function Website<B extends Bindings>(
|
|
|
96
96
|
name: id,
|
|
97
97
|
main: wranglerMain,
|
|
98
98
|
compatibility_date: new Date().toISOString().split("T")[0],
|
|
99
|
+
compatibility_flags: props.compatibilityFlags ?? [],
|
|
99
100
|
},
|
|
100
101
|
null,
|
|
101
102
|
2,
|
|
@@ -105,9 +106,11 @@ export async function Website<B extends Bindings>(
|
|
|
105
106
|
}
|
|
106
107
|
|
|
107
108
|
await Exec("build", {
|
|
109
|
+
cwd,
|
|
108
110
|
command: props.command,
|
|
109
111
|
});
|
|
110
112
|
|
|
113
|
+
// @ts-expect-error - the WorkerProps union type not happy
|
|
111
114
|
const worker = await Worker("worker", {
|
|
112
115
|
...props,
|
|
113
116
|
name: props.name ?? id,
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { getContentType } from "../util/content-type.js";
|
|
5
|
+
import type { CloudflareApi } from "./api.js";
|
|
6
|
+
import type { Assets } from "./assets.js";
|
|
7
|
+
import type { AssetsConfig, WorkerProps } from "./worker.js";
|
|
8
|
+
|
|
9
|
+
export interface AssetUploadResult {
|
|
10
|
+
completionToken: string;
|
|
11
|
+
assetConfig?: AssetsConfig;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Interface for a file's metadata to be uploaded
|
|
16
|
+
*/
|
|
17
|
+
interface FileMetadata {
|
|
18
|
+
hash: string;
|
|
19
|
+
size: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Response from the assets upload session API
|
|
24
|
+
*/
|
|
25
|
+
interface UploadSessionResponse {
|
|
26
|
+
result: {
|
|
27
|
+
jwt: string;
|
|
28
|
+
buckets: string[][];
|
|
29
|
+
};
|
|
30
|
+
success: boolean;
|
|
31
|
+
errors: any[];
|
|
32
|
+
messages: any[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Response from the file upload API
|
|
37
|
+
*/
|
|
38
|
+
interface UploadResponse {
|
|
39
|
+
result: {
|
|
40
|
+
jwt: string;
|
|
41
|
+
buckets?: string[][];
|
|
42
|
+
};
|
|
43
|
+
success: boolean;
|
|
44
|
+
errors: any[];
|
|
45
|
+
messages: any[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Uploads assets to Cloudflare and returns a completion token
|
|
50
|
+
*
|
|
51
|
+
* @param api CloudflareApi instance
|
|
52
|
+
* @param workerName Name of the worker
|
|
53
|
+
* @param assets Assets resource containing files to upload
|
|
54
|
+
* @param assetConfig Configuration for the assets
|
|
55
|
+
* @returns Completion token for the assets upload
|
|
56
|
+
*/
|
|
57
|
+
export async function uploadAssets(
|
|
58
|
+
api: CloudflareApi,
|
|
59
|
+
workerName: string,
|
|
60
|
+
assets: Assets,
|
|
61
|
+
assetConfig?: WorkerProps["assets"],
|
|
62
|
+
): Promise<AssetUploadResult> {
|
|
63
|
+
// Process the assets configuration once at the beginning
|
|
64
|
+
const processedConfig = createAssetConfig(assetConfig);
|
|
65
|
+
|
|
66
|
+
// Generate the file manifest
|
|
67
|
+
const fileMetadata: Record<string, FileMetadata> = {};
|
|
68
|
+
|
|
69
|
+
// Process each file in the assets
|
|
70
|
+
for (const file of assets.files) {
|
|
71
|
+
const { hash, size } = await calculateFileMetadata(file.filePath);
|
|
72
|
+
// Use the relative path as the key, ensuring it starts with a slash
|
|
73
|
+
const key = file.path.startsWith("/") ? file.path : `/${file.path}`;
|
|
74
|
+
fileMetadata[key] = { hash, size };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Start the upload session
|
|
78
|
+
const uploadSessionUrl = `/accounts/${api.accountId}/workers/scripts/${workerName}/assets-upload-session`;
|
|
79
|
+
const uploadSessionResponse = await api.post(
|
|
80
|
+
uploadSessionUrl,
|
|
81
|
+
JSON.stringify({ manifest: fileMetadata }),
|
|
82
|
+
{
|
|
83
|
+
headers: { "Content-Type": "application/json" },
|
|
84
|
+
},
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
if (!uploadSessionResponse.ok) {
|
|
88
|
+
throw new Error(
|
|
89
|
+
`Failed to start assets upload session: ${uploadSessionResponse.status} ${uploadSessionResponse.statusText}`,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const sessionData =
|
|
94
|
+
(await uploadSessionResponse.json()) as UploadSessionResponse;
|
|
95
|
+
|
|
96
|
+
// If there are no buckets, assets are already uploaded or empty
|
|
97
|
+
if (!sessionData.result.buckets || sessionData.result.buckets.length === 0) {
|
|
98
|
+
return {
|
|
99
|
+
completionToken: sessionData.result.jwt,
|
|
100
|
+
assetConfig: processedConfig,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Upload the files in batches as specified by the API
|
|
105
|
+
let completionToken = sessionData.result.jwt;
|
|
106
|
+
const buckets = sessionData.result.buckets;
|
|
107
|
+
|
|
108
|
+
// Process each bucket of files
|
|
109
|
+
for (const bucket of buckets) {
|
|
110
|
+
const formData = new FormData();
|
|
111
|
+
|
|
112
|
+
// Add each file in the bucket to the form
|
|
113
|
+
for (const fileHash of bucket) {
|
|
114
|
+
// Find the file with this hash
|
|
115
|
+
const file = assets.files.find((f) => {
|
|
116
|
+
const filePath = f.path.startsWith("/") ? f.path : `/${f.path}`;
|
|
117
|
+
return fileMetadata[filePath]?.hash === fileHash;
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
if (!file) {
|
|
121
|
+
throw new Error(`Could not find file with hash ${fileHash}`);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Read the file content
|
|
125
|
+
const fileContent = await fs.readFile(file.filePath);
|
|
126
|
+
|
|
127
|
+
// Convert to base64 as required by the API when using base64=true
|
|
128
|
+
const base64Content = fileContent.toString("base64");
|
|
129
|
+
|
|
130
|
+
// Add the file to the form with the hash as the key and set the correct content type
|
|
131
|
+
const blob = new Blob([base64Content], {
|
|
132
|
+
// if you set application/octet-stream, you get weird `-1` errors with a message to contact support
|
|
133
|
+
type: getContentType(file.filePath) ?? "application/null",
|
|
134
|
+
});
|
|
135
|
+
formData.append(fileHash, blob, fileHash);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Upload this batch of files
|
|
139
|
+
const uploadResponse = await api.post(
|
|
140
|
+
`/accounts/${api.accountId}/workers/assets/upload?base64=true`,
|
|
141
|
+
formData,
|
|
142
|
+
{
|
|
143
|
+
headers: {
|
|
144
|
+
Authorization: `Bearer ${completionToken}`,
|
|
145
|
+
"Content-Type": "multipart/form-data",
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
if (!uploadResponse.ok) {
|
|
151
|
+
throw new Error(
|
|
152
|
+
`Failed to upload asset files: ${uploadResponse.status} ${uploadResponse.statusText}`,
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const uploadData = (await uploadResponse.json()) as UploadResponse;
|
|
157
|
+
if (!uploadData.success) {
|
|
158
|
+
const error = uploadData.errors[0];
|
|
159
|
+
const message = error.message;
|
|
160
|
+
const code = error.code;
|
|
161
|
+
throw new Error(
|
|
162
|
+
`Failed to upload asset files: ${message} (Code: ${code})`,
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Update the completion token for the next batch
|
|
167
|
+
if (uploadData.result.jwt) {
|
|
168
|
+
completionToken = uploadData.result.jwt;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Return the final completion token with asset configuration
|
|
173
|
+
return {
|
|
174
|
+
completionToken,
|
|
175
|
+
assetConfig: processedConfig,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Creates asset configuration object from provided config or defaults
|
|
181
|
+
*/
|
|
182
|
+
export function createAssetConfig(config?: AssetsConfig): AssetsConfig {
|
|
183
|
+
const assetConfig: AssetsConfig = {
|
|
184
|
+
html_handling: "auto-trailing-slash",
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
if (config) {
|
|
188
|
+
if (config._headers !== undefined) {
|
|
189
|
+
assetConfig._headers = config._headers;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (config._redirects !== undefined) {
|
|
193
|
+
assetConfig._redirects = config._redirects;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (config.html_handling !== undefined) {
|
|
197
|
+
assetConfig.html_handling = config.html_handling;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (config.not_found_handling !== undefined) {
|
|
201
|
+
assetConfig.not_found_handling = config.not_found_handling;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (config.run_worker_first !== undefined) {
|
|
205
|
+
assetConfig.run_worker_first = config.run_worker_first;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (config.serve_directly !== undefined) {
|
|
209
|
+
assetConfig.serve_directly = config.serve_directly;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return assetConfig;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Calculate the SHA-256 hash and size of a file
|
|
218
|
+
*
|
|
219
|
+
* @param filePath Path to the file
|
|
220
|
+
* @returns Hash (first 32 chars of SHA-256) and size of the file
|
|
221
|
+
*/
|
|
222
|
+
export async function calculateFileMetadata(
|
|
223
|
+
filePath: string,
|
|
224
|
+
): Promise<{ hash: string; size: number }> {
|
|
225
|
+
const contents = await fs.readFile(filePath);
|
|
226
|
+
|
|
227
|
+
const hash = crypto.createHash("sha256");
|
|
228
|
+
hash.update(contents);
|
|
229
|
+
|
|
230
|
+
const extension = path.extname(filePath).substring(1);
|
|
231
|
+
hash.update(extension);
|
|
232
|
+
|
|
233
|
+
return {
|
|
234
|
+
hash: hash.digest("hex").slice(0, 32),
|
|
235
|
+
size: contents.length,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import type { Context } from "../context.js";
|
|
2
|
+
import { slugify } from "../util/slugify.js";
|
|
3
|
+
import { Self, type Bindings, type WorkerBindingSpec } from "./bindings.js";
|
|
4
|
+
import type { DurableObjectNamespace } from "./durable-object-namespace.js";
|
|
5
|
+
import { createAssetConfig, type AssetUploadResult } from "./worker-assets.js";
|
|
6
|
+
import type { SingleStepMigration } from "./worker-migration.js";
|
|
7
|
+
import type { AssetsConfig, Worker, WorkerProps } from "./worker.js";
|
|
8
|
+
import type { Workflow } from "./workflow.js";
|
|
9
|
+
|
|
1
10
|
/**
|
|
2
11
|
* Metadata returned by Cloudflare API for a worker script
|
|
3
12
|
*/
|
|
@@ -152,3 +161,281 @@ export interface WorkerDefaultEnvironment extends WorkerEnvironment {
|
|
|
152
161
|
*/
|
|
153
162
|
script: WorkerScriptInfo;
|
|
154
163
|
}
|
|
164
|
+
|
|
165
|
+
export interface WorkerMetadata {
|
|
166
|
+
compatibility_date: string;
|
|
167
|
+
compatibility_flags?: string[];
|
|
168
|
+
bindings: WorkerBindingSpec[];
|
|
169
|
+
observability: {
|
|
170
|
+
enabled: boolean;
|
|
171
|
+
};
|
|
172
|
+
migrations?: SingleStepMigration;
|
|
173
|
+
main_module?: string;
|
|
174
|
+
body_part?: string;
|
|
175
|
+
tags?: string[];
|
|
176
|
+
assets?: {
|
|
177
|
+
jwt?: string;
|
|
178
|
+
keep_assets?: boolean;
|
|
179
|
+
config?: AssetsConfig;
|
|
180
|
+
};
|
|
181
|
+
cron_triggers?: {
|
|
182
|
+
cron: string;
|
|
183
|
+
suspended: boolean;
|
|
184
|
+
}[];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export async function prepareWorkerMetadata<B extends Bindings>(
|
|
188
|
+
ctx: Context<Worker<B>>,
|
|
189
|
+
oldBindings: Bindings | undefined,
|
|
190
|
+
props: WorkerProps & {
|
|
191
|
+
compatibilityDate: string;
|
|
192
|
+
compatibilityFlags: string[];
|
|
193
|
+
workerName: string;
|
|
194
|
+
},
|
|
195
|
+
assetUploadResult?: AssetUploadResult,
|
|
196
|
+
): Promise<WorkerMetadata> {
|
|
197
|
+
const deletedClasses = Object.entries(oldBindings ?? {})
|
|
198
|
+
.filter(([key]) => !props.bindings?.[key])
|
|
199
|
+
.flatMap(([_, binding]) => {
|
|
200
|
+
if (
|
|
201
|
+
binding &&
|
|
202
|
+
typeof binding === "object" &&
|
|
203
|
+
binding.type === "durable_object_namespace"
|
|
204
|
+
) {
|
|
205
|
+
return [binding.className];
|
|
206
|
+
}
|
|
207
|
+
return [];
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
// Prepare metadata with bindings
|
|
211
|
+
const meta: WorkerMetadata = {
|
|
212
|
+
compatibility_date: props.compatibilityDate,
|
|
213
|
+
compatibility_flags: props.compatibilityFlags,
|
|
214
|
+
bindings: [],
|
|
215
|
+
observability: {
|
|
216
|
+
enabled: props.observability?.enabled !== false,
|
|
217
|
+
},
|
|
218
|
+
// TODO(sam): base64 encode instead? 0 collision risk vs readability.
|
|
219
|
+
tags: [`alchemy:id:${slugify(ctx.fqn)}`],
|
|
220
|
+
migrations: {
|
|
221
|
+
new_classes: props.migrations?.new_classes ?? [],
|
|
222
|
+
deleted_classes: [
|
|
223
|
+
...deletedClasses,
|
|
224
|
+
...(props.migrations?.deleted_classes ?? []),
|
|
225
|
+
],
|
|
226
|
+
renamed_classes: props.migrations?.renamed_classes ?? [],
|
|
227
|
+
transferred_classes: props.migrations?.transferred_classes ?? [],
|
|
228
|
+
new_sqlite_classes: props.migrations?.new_sqlite_classes ?? [],
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
// If we have asset upload results, add them to the metadata
|
|
233
|
+
if (assetUploadResult) {
|
|
234
|
+
meta.assets = {
|
|
235
|
+
jwt: assetUploadResult.completionToken,
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
// Initialize config from assetUploadResult if it exists
|
|
239
|
+
if (assetUploadResult.assetConfig) {
|
|
240
|
+
meta.assets.config = {
|
|
241
|
+
...assetUploadResult.assetConfig,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// If there's no config from assetUploadResult but we have props.assets,
|
|
246
|
+
// we need to create the config ourselves (this handles the case when no assets were uploaded)
|
|
247
|
+
if (!meta.assets.config && props.assets) {
|
|
248
|
+
meta.assets.config = createAssetConfig(props.assets);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const bindings = (props.bindings ?? {}) as Bindings;
|
|
253
|
+
|
|
254
|
+
// Convert bindings to the format expected by the API
|
|
255
|
+
for (const [bindingName, binding] of Object.entries(bindings)) {
|
|
256
|
+
// Create a copy of the binding to avoid modifying the original
|
|
257
|
+
|
|
258
|
+
if (typeof binding === "string") {
|
|
259
|
+
meta.bindings.push({
|
|
260
|
+
type: "plain_text",
|
|
261
|
+
name: bindingName,
|
|
262
|
+
text: binding,
|
|
263
|
+
});
|
|
264
|
+
} else if (binding === Self) {
|
|
265
|
+
meta.bindings.push({
|
|
266
|
+
type: "service",
|
|
267
|
+
name: bindingName,
|
|
268
|
+
service: props.workerName,
|
|
269
|
+
});
|
|
270
|
+
} else if (binding.type === "d1") {
|
|
271
|
+
meta.bindings.push({
|
|
272
|
+
type: "d1",
|
|
273
|
+
name: bindingName,
|
|
274
|
+
id: binding.id,
|
|
275
|
+
});
|
|
276
|
+
} else if (binding.type === "kv_namespace") {
|
|
277
|
+
meta.bindings.push({
|
|
278
|
+
type: "kv_namespace",
|
|
279
|
+
name: bindingName,
|
|
280
|
+
namespace_id:
|
|
281
|
+
"namespaceId" in binding ? binding.namespaceId : binding.id,
|
|
282
|
+
});
|
|
283
|
+
} else if (binding.type === "service") {
|
|
284
|
+
meta.bindings.push({
|
|
285
|
+
type: "service",
|
|
286
|
+
name: bindingName,
|
|
287
|
+
service: binding.name,
|
|
288
|
+
});
|
|
289
|
+
} else if (binding.type === "durable_object_namespace") {
|
|
290
|
+
meta.bindings.push({
|
|
291
|
+
type: "durable_object_namespace",
|
|
292
|
+
name: bindingName,
|
|
293
|
+
class_name: binding.className,
|
|
294
|
+
script_name: binding.scriptName,
|
|
295
|
+
environment: binding.environment,
|
|
296
|
+
namespace_id: binding.namespaceId,
|
|
297
|
+
});
|
|
298
|
+
configureClassMigration(binding, binding.id, binding.className);
|
|
299
|
+
} else if (binding.type === "r2_bucket") {
|
|
300
|
+
meta.bindings.push({
|
|
301
|
+
type: "r2_bucket",
|
|
302
|
+
name: bindingName,
|
|
303
|
+
bucket_name: binding.name,
|
|
304
|
+
});
|
|
305
|
+
} else if (binding.type === "assets") {
|
|
306
|
+
meta.bindings.push({
|
|
307
|
+
type: "assets",
|
|
308
|
+
name: bindingName,
|
|
309
|
+
});
|
|
310
|
+
} else if (binding.type === "secret") {
|
|
311
|
+
meta.bindings.push({
|
|
312
|
+
type: "secret_text",
|
|
313
|
+
name: bindingName,
|
|
314
|
+
text: binding.unencrypted,
|
|
315
|
+
});
|
|
316
|
+
} else if (binding.type === "workflow") {
|
|
317
|
+
meta.bindings.push({
|
|
318
|
+
type: "workflow",
|
|
319
|
+
name: bindingName,
|
|
320
|
+
workflow_name: binding.workflowName,
|
|
321
|
+
class_name: binding.className,
|
|
322
|
+
// this should be set if the Workflow is in another script ...
|
|
323
|
+
// script_name: ??,
|
|
324
|
+
});
|
|
325
|
+
// it's unclear whether this is needed, but it works both ways
|
|
326
|
+
// configureClassMigration(binding, binding.id, binding.className);
|
|
327
|
+
} else if (binding.type === "queue") {
|
|
328
|
+
meta.bindings.push({
|
|
329
|
+
type: "queue",
|
|
330
|
+
name: bindingName,
|
|
331
|
+
queue_name: binding.name,
|
|
332
|
+
});
|
|
333
|
+
} else if (binding.type === "pipeline") {
|
|
334
|
+
meta.bindings.push({
|
|
335
|
+
type: "pipelines",
|
|
336
|
+
name: bindingName,
|
|
337
|
+
pipeline: binding.name,
|
|
338
|
+
});
|
|
339
|
+
} else if (binding.type === "vectorize") {
|
|
340
|
+
meta.bindings.push({
|
|
341
|
+
type: "vectorize",
|
|
342
|
+
name: bindingName,
|
|
343
|
+
index_name: binding.name,
|
|
344
|
+
});
|
|
345
|
+
} else if (binding.type === "ai_gateway") {
|
|
346
|
+
// AI Gateway binding - just needs the name property
|
|
347
|
+
meta.bindings.push({
|
|
348
|
+
type: "ai",
|
|
349
|
+
name: bindingName,
|
|
350
|
+
});
|
|
351
|
+
} else if (binding.type === "hyperdrive") {
|
|
352
|
+
// Hyperdrive binding
|
|
353
|
+
meta.bindings.push({
|
|
354
|
+
type: "hyperdrive",
|
|
355
|
+
name: bindingName,
|
|
356
|
+
id: binding.hyperdriveId,
|
|
357
|
+
});
|
|
358
|
+
} else if (binding.type === "browser") {
|
|
359
|
+
meta.bindings.push({
|
|
360
|
+
type: "browser",
|
|
361
|
+
name: bindingName,
|
|
362
|
+
});
|
|
363
|
+
} else if (binding.type === "ai") {
|
|
364
|
+
meta.bindings.push({
|
|
365
|
+
type: "ai",
|
|
366
|
+
name: bindingName,
|
|
367
|
+
});
|
|
368
|
+
} else if (binding.type === "json") {
|
|
369
|
+
meta.bindings.push({
|
|
370
|
+
type: "json",
|
|
371
|
+
name: bindingName,
|
|
372
|
+
json: JSON.stringify(binding.json),
|
|
373
|
+
});
|
|
374
|
+
} else if (binding.type === "analytics_engine") {
|
|
375
|
+
meta.bindings.push({
|
|
376
|
+
type: "analytics_engine",
|
|
377
|
+
name: bindingName,
|
|
378
|
+
dataset: binding.dataset,
|
|
379
|
+
});
|
|
380
|
+
} else {
|
|
381
|
+
// @ts-expect-error - we should never reach here
|
|
382
|
+
throw new Error(`Unsupported binding type: ${binding.type}`);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function configureClassMigration(
|
|
387
|
+
binding: DurableObjectNamespace | Workflow,
|
|
388
|
+
stableId: string,
|
|
389
|
+
className: string,
|
|
390
|
+
) {
|
|
391
|
+
const oldBinding: DurableObjectNamespace | Workflow | undefined =
|
|
392
|
+
Object.values(oldBindings ?? {})
|
|
393
|
+
?.filter(
|
|
394
|
+
(b) =>
|
|
395
|
+
typeof b === "object" &&
|
|
396
|
+
(b.type === "durable_object_namespace" || b.type === "workflow"),
|
|
397
|
+
)
|
|
398
|
+
?.find((b) => b.id === stableId);
|
|
399
|
+
|
|
400
|
+
if (!oldBinding) {
|
|
401
|
+
if (binding.type === "durable_object_namespace" && binding.sqlite) {
|
|
402
|
+
meta.migrations!.new_sqlite_classes!.push(className);
|
|
403
|
+
} else {
|
|
404
|
+
meta.migrations!.new_classes!.push(className);
|
|
405
|
+
}
|
|
406
|
+
} else if (oldBinding.className !== className) {
|
|
407
|
+
meta.migrations!.renamed_classes!.push({
|
|
408
|
+
from: oldBinding.className,
|
|
409
|
+
to: className,
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// Convert env variables to plain_text bindings
|
|
415
|
+
// TODO(sam): remove Worker.env in favor of always bindings
|
|
416
|
+
if (props.env) {
|
|
417
|
+
for (const [key, value] of Object.entries(props.env)) {
|
|
418
|
+
meta.bindings.push({
|
|
419
|
+
name: key,
|
|
420
|
+
type: "plain_text",
|
|
421
|
+
text: value,
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// Determine if we're using ESM or service worker format
|
|
427
|
+
const isEsModule = props.format !== "cjs"; // Default to ESM unless CJS is specified
|
|
428
|
+
const scriptName = isEsModule ? "worker.js" : "script";
|
|
429
|
+
|
|
430
|
+
if (isEsModule) {
|
|
431
|
+
// For ES modules format
|
|
432
|
+
meta.main_module = scriptName;
|
|
433
|
+
} else {
|
|
434
|
+
// For service worker format (CJS)
|
|
435
|
+
meta.body_part = scriptName;
|
|
436
|
+
}
|
|
437
|
+
if (process.env.DEBUG) {
|
|
438
|
+
console.log(meta);
|
|
439
|
+
}
|
|
440
|
+
return meta;
|
|
441
|
+
}
|