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,5 +1,6 @@
|
|
|
1
1
|
import type { Context } from "../context.js";
|
|
2
|
-
import { Resource } from "../resource.js";
|
|
2
|
+
import { Resource, ResourceKind } from "../resource.js";
|
|
3
|
+
import { bind, type Bound } from "../runtime/bind.js";
|
|
3
4
|
import { CloudflareApiError, handleApiError } from "./api-error.js";
|
|
4
5
|
import {
|
|
5
6
|
createCloudflareApi,
|
|
@@ -93,10 +94,16 @@ export interface D1DatabaseProps extends CloudflareApiOptions {
|
|
|
93
94
|
migrationsDir?: string;
|
|
94
95
|
}
|
|
95
96
|
|
|
97
|
+
export function isD1Database(
|
|
98
|
+
resource: Resource,
|
|
99
|
+
): resource is D1DatabaseResource {
|
|
100
|
+
return resource[ResourceKind] === "cloudflare::D1Database";
|
|
101
|
+
}
|
|
102
|
+
|
|
96
103
|
/**
|
|
97
104
|
* Output returned after D1 Database creation/update
|
|
98
105
|
*/
|
|
99
|
-
export type
|
|
106
|
+
export type D1DatabaseResource = Resource<"cloudflare::D1Database"> &
|
|
100
107
|
D1DatabaseProps & {
|
|
101
108
|
type: "d1";
|
|
102
109
|
/**
|
|
@@ -135,6 +142,34 @@ export type D1Database = Resource<"cloudflare::D1Database"> &
|
|
|
135
142
|
};
|
|
136
143
|
};
|
|
137
144
|
|
|
145
|
+
export type D1Database = D1DatabaseResource & Bound<D1DatabaseResource>;
|
|
146
|
+
|
|
147
|
+
export async function D1Database(
|
|
148
|
+
id: string,
|
|
149
|
+
props: Omit<D1DatabaseProps, "migrationsFiles">,
|
|
150
|
+
): Promise<D1Database> {
|
|
151
|
+
const migrationsFiles = props.migrationsDir
|
|
152
|
+
? await listMigrationsFiles(props.migrationsDir)
|
|
153
|
+
: [];
|
|
154
|
+
|
|
155
|
+
const db = await D1DatabaseResource(id, {
|
|
156
|
+
...props,
|
|
157
|
+
migrationsFiles,
|
|
158
|
+
});
|
|
159
|
+
const binding = await bind(db);
|
|
160
|
+
return {
|
|
161
|
+
...db,
|
|
162
|
+
batch: binding.batch,
|
|
163
|
+
exec: binding.exec,
|
|
164
|
+
prepare: binding.prepare,
|
|
165
|
+
withSession: binding.withSession,
|
|
166
|
+
/**
|
|
167
|
+
* @deprecated
|
|
168
|
+
*/
|
|
169
|
+
dump: binding.dump,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
138
173
|
/**
|
|
139
174
|
* Creates and manages Cloudflare D1 Databases.
|
|
140
175
|
*
|
|
@@ -194,27 +229,13 @@ export type D1Database = Resource<"cloudflare::D1Database"> &
|
|
|
194
229
|
*
|
|
195
230
|
* @see https://developers.cloudflare.com/d1/
|
|
196
231
|
*/
|
|
197
|
-
|
|
198
|
-
id: string,
|
|
199
|
-
props: Omit<D1DatabaseProps, "migrationsFiles">,
|
|
200
|
-
) {
|
|
201
|
-
const migrationsFiles = props.migrationsDir
|
|
202
|
-
? await listMigrationsFiles(props.migrationsDir)
|
|
203
|
-
: [];
|
|
204
|
-
|
|
205
|
-
return D1DatabaseResource(id, {
|
|
206
|
-
...props,
|
|
207
|
-
migrationsFiles,
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export const D1DatabaseResource = Resource(
|
|
232
|
+
const D1DatabaseResource = Resource(
|
|
212
233
|
"cloudflare::D1Database",
|
|
213
234
|
async function (
|
|
214
|
-
this: Context<
|
|
235
|
+
this: Context<D1DatabaseResource>,
|
|
215
236
|
id: string,
|
|
216
237
|
props: D1DatabaseProps = {},
|
|
217
|
-
): Promise<
|
|
238
|
+
): Promise<D1DatabaseResource> {
|
|
218
239
|
const api = await createCloudflareApi(props);
|
|
219
240
|
const databaseName = props.name ?? id;
|
|
220
241
|
|
|
@@ -127,7 +127,7 @@ export const DnsRecords = Resource(
|
|
|
127
127
|
"cloudflare::DnsRecords",
|
|
128
128
|
async function (
|
|
129
129
|
this: Context<DnsRecords>,
|
|
130
|
-
|
|
130
|
+
_id: string,
|
|
131
131
|
props: DnsRecordsProps,
|
|
132
132
|
): Promise<DnsRecords> {
|
|
133
133
|
// Create Cloudflare API client
|
|
@@ -307,7 +307,7 @@ async function createOrUpdateRecord(
|
|
|
307
307
|
zoneId,
|
|
308
308
|
);
|
|
309
309
|
}
|
|
310
|
-
} catch (
|
|
310
|
+
} catch (_err) {
|
|
311
311
|
// Fall through to the original error
|
|
312
312
|
}
|
|
313
313
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { QueueConsumerSettings } from "./queue-consumer.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { QueueResource } from "./queue.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Base interface for event sources that can be bound to a Worker
|
|
6
6
|
*/
|
|
7
|
-
export type EventSource = QueueEventSource |
|
|
7
|
+
export type EventSource = QueueEventSource | QueueResource;
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Configuration for a Queue as an event source for a Worker
|
|
@@ -13,7 +13,7 @@ export interface QueueEventSource {
|
|
|
13
13
|
/**
|
|
14
14
|
* The queue to consume messages from
|
|
15
15
|
*/
|
|
16
|
-
readonly queue:
|
|
16
|
+
readonly queue: QueueResource;
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Optional settings for configuring how the Worker consumes the queue
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { Context } from "../context.js";
|
|
2
2
|
import { Resource } from "../resource.js";
|
|
3
|
+
import { tryGetBinding } from "../runtime/bind.js";
|
|
3
4
|
import type { Secret } from "../secret.js";
|
|
4
5
|
import { handleApiError } from "./api-error.js";
|
|
5
6
|
import { createCloudflareApi, type CloudflareApiOptions } from "./api.js";
|
|
7
|
+
import type { Bound } from "./bound.js";
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Origin configuration for a PostgreSQL database connection
|
|
@@ -153,7 +155,7 @@ export interface HyperdriveProps extends CloudflareApiOptions {
|
|
|
153
155
|
* Output returned after Cloudflare Hyperdrive creation/update.
|
|
154
156
|
* IMPORTANT: The interface name MUST match the exported resource name.
|
|
155
157
|
*/
|
|
156
|
-
export interface
|
|
158
|
+
export interface HyperdriveResource
|
|
157
159
|
extends Resource<"cloudflare::Hyperdrive">,
|
|
158
160
|
Omit<HyperdriveProps, "origin"> {
|
|
159
161
|
/**
|
|
@@ -178,6 +180,8 @@ export interface Hyperdrive
|
|
|
178
180
|
type: "hyperdrive";
|
|
179
181
|
}
|
|
180
182
|
|
|
183
|
+
export type Hyperdrive = HyperdriveResource & Bound<HyperdriveResource>;
|
|
184
|
+
|
|
181
185
|
/**
|
|
182
186
|
* Represents a Cloudflare Hyperdrive configuration.
|
|
183
187
|
*
|
|
@@ -242,13 +246,24 @@ export interface Hyperdrive
|
|
|
242
246
|
* }
|
|
243
247
|
* });
|
|
244
248
|
*/
|
|
245
|
-
export
|
|
249
|
+
export async function Hyperdrive(
|
|
250
|
+
name: string,
|
|
251
|
+
props: HyperdriveProps,
|
|
252
|
+
): Promise<Hyperdrive> {
|
|
253
|
+
const resource = await HyperdriveResource(name, props);
|
|
254
|
+
return {
|
|
255
|
+
...resource,
|
|
256
|
+
...tryGetBinding(resource),
|
|
257
|
+
} as Hyperdrive;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const HyperdriveResource = Resource(
|
|
246
261
|
"cloudflare::Hyperdrive",
|
|
247
262
|
async function (
|
|
248
|
-
this: Context<
|
|
263
|
+
this: Context<HyperdriveResource>,
|
|
249
264
|
id: string,
|
|
250
265
|
props: HyperdriveProps,
|
|
251
|
-
): Promise<
|
|
266
|
+
): Promise<HyperdriveResource> {
|
|
252
267
|
const api = await createCloudflareApi(props);
|
|
253
268
|
const configsPath = `/accounts/${api.accountId}/hyperdrive/configs`;
|
|
254
269
|
|
|
@@ -1,5 +1,6 @@
|
|
|
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 { withExponentialBackoff } from "../util/retry.js";
|
|
4
5
|
import { handleApiError } from "./api-error.js";
|
|
5
6
|
import {
|
|
@@ -7,6 +8,7 @@ import {
|
|
|
7
8
|
type CloudflareApi,
|
|
8
9
|
type CloudflareApiOptions,
|
|
9
10
|
} from "./api.js";
|
|
11
|
+
import type { Bound } from "./bound.js";
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* Properties for creating or updating a KV Namespace
|
|
@@ -15,7 +17,7 @@ export interface KVNamespaceProps extends CloudflareApiOptions {
|
|
|
15
17
|
/**
|
|
16
18
|
* Title of the namespace
|
|
17
19
|
*/
|
|
18
|
-
title
|
|
20
|
+
title?: string;
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* KV pairs to store in the namespace
|
|
@@ -70,12 +72,18 @@ export interface KVPair {
|
|
|
70
72
|
metadata?: any;
|
|
71
73
|
}
|
|
72
74
|
|
|
75
|
+
export function isKVNamespace(
|
|
76
|
+
resource: Resource,
|
|
77
|
+
): resource is KVNamespaceResource {
|
|
78
|
+
return resource[ResourceKind] === "cloudflare::KVNamespace";
|
|
79
|
+
}
|
|
80
|
+
|
|
73
81
|
/**
|
|
74
82
|
* Output returned after KV Namespace creation/update
|
|
75
83
|
*/
|
|
76
|
-
export interface
|
|
84
|
+
export interface KVNamespaceResource
|
|
77
85
|
extends Resource<"cloudflare::KVNamespace">,
|
|
78
|
-
KVNamespaceProps {
|
|
86
|
+
Omit<KVNamespaceProps, "delete"> {
|
|
79
87
|
type: "kv_namespace";
|
|
80
88
|
/**
|
|
81
89
|
* The ID of the namespace
|
|
@@ -93,6 +101,8 @@ export interface KVNamespace
|
|
|
93
101
|
modifiedAt: number;
|
|
94
102
|
}
|
|
95
103
|
|
|
104
|
+
export type KVNamespace = KVNamespaceResource & Bound<KVNamespaceResource>;
|
|
105
|
+
|
|
96
106
|
/**
|
|
97
107
|
* A Cloudflare KV Namespace is a key-value store that can be used to store data for your application.
|
|
98
108
|
*
|
|
@@ -147,16 +157,35 @@ export interface KVNamespace
|
|
|
147
157
|
* delete: false
|
|
148
158
|
* });
|
|
149
159
|
*/
|
|
150
|
-
|
|
160
|
+
|
|
161
|
+
export async function KVNamespace(
|
|
162
|
+
name: string,
|
|
163
|
+
props: KVNamespaceProps = {},
|
|
164
|
+
): Promise<KVNamespace> {
|
|
165
|
+
const kv = await _KVNamespace(name, props);
|
|
166
|
+
const binding = await bind(kv);
|
|
167
|
+
return {
|
|
168
|
+
...kv,
|
|
169
|
+
delete: binding.delete,
|
|
170
|
+
get: binding.get,
|
|
171
|
+
getWithMetadata: binding.getWithMetadata,
|
|
172
|
+
list: binding.list,
|
|
173
|
+
put: binding.put,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const _KVNamespace = Resource(
|
|
151
178
|
"cloudflare::KVNamespace",
|
|
152
179
|
async function (
|
|
153
|
-
this: Context<
|
|
180
|
+
this: Context<KVNamespaceResource>,
|
|
154
181
|
id: string,
|
|
155
182
|
props: KVNamespaceProps,
|
|
156
|
-
) {
|
|
183
|
+
): Promise<KVNamespaceResource> {
|
|
157
184
|
// Create Cloudflare API client with automatic account discovery
|
|
158
185
|
const api = await createCloudflareApi(props);
|
|
159
186
|
|
|
187
|
+
const title = props.title ?? id;
|
|
188
|
+
|
|
160
189
|
if (this.phase === "delete") {
|
|
161
190
|
// For delete operations, we need to check if the namespace ID exists in the output
|
|
162
191
|
const namespaceId = this.output?.namespaceId;
|
|
@@ -181,7 +210,10 @@ export const KVNamespace = Resource(
|
|
|
181
210
|
} else {
|
|
182
211
|
try {
|
|
183
212
|
// Try to create the KV namespace
|
|
184
|
-
const { id } = await createKVNamespace(api,
|
|
213
|
+
const { id } = await createKVNamespace(api, {
|
|
214
|
+
...props,
|
|
215
|
+
title,
|
|
216
|
+
});
|
|
185
217
|
createdAt = Date.now();
|
|
186
218
|
namespaceId = id;
|
|
187
219
|
} catch (error) {
|
|
@@ -191,16 +223,13 @@ export const KVNamespace = Resource(
|
|
|
191
223
|
error instanceof Error &&
|
|
192
224
|
error.message.includes("already exists")
|
|
193
225
|
) {
|
|
194
|
-
console.log(`Namespace '${
|
|
226
|
+
console.log(`Namespace '${title}' already exists, adopting it`);
|
|
195
227
|
// Find the existing namespace by title
|
|
196
|
-
const existingNamespace = await findKVNamespaceByTitle(
|
|
197
|
-
api,
|
|
198
|
-
props.title,
|
|
199
|
-
);
|
|
228
|
+
const existingNamespace = await findKVNamespaceByTitle(api, title);
|
|
200
229
|
|
|
201
230
|
if (!existingNamespace) {
|
|
202
231
|
throw new Error(
|
|
203
|
-
`Failed to find existing namespace '${
|
|
232
|
+
`Failed to find existing namespace '${title}' for adoption`,
|
|
204
233
|
);
|
|
205
234
|
}
|
|
206
235
|
|
|
@@ -229,7 +258,9 @@ export const KVNamespace = Resource(
|
|
|
229
258
|
|
|
230
259
|
export async function createKVNamespace(
|
|
231
260
|
api: CloudflareApi,
|
|
232
|
-
props: KVNamespaceProps
|
|
261
|
+
props: KVNamespaceProps & {
|
|
262
|
+
title: string;
|
|
263
|
+
},
|
|
233
264
|
): Promise<{ id: string }> {
|
|
234
265
|
const createResponse = await api.post(
|
|
235
266
|
`/accounts/${api.accountId}/storage/kv/namespaces`,
|
|
@@ -110,7 +110,7 @@ export const PermissionGroups = Resource(
|
|
|
110
110
|
"cloudflare::PermissionGroups",
|
|
111
111
|
async function (
|
|
112
112
|
this: Context<PermissionGroups>,
|
|
113
|
-
|
|
113
|
+
_id: string,
|
|
114
114
|
options: CloudflareApiOptions = {},
|
|
115
115
|
): Promise<PermissionGroups> {
|
|
116
116
|
// Only create and update phases are supported
|
|
@@ -1,12 +1,14 @@
|
|
|
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 type { Secret } from "../secret.js";
|
|
4
5
|
import { CloudflareApiError, handleApiError } from "./api-error.js";
|
|
5
6
|
import {
|
|
6
|
-
type CloudflareApi,
|
|
7
7
|
createCloudflareApi,
|
|
8
|
+
type CloudflareApi,
|
|
8
9
|
type CloudflareApiOptions,
|
|
9
10
|
} from "./api.js";
|
|
11
|
+
import type { Bound } from "./bound.js";
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* Settings for compression of pipeline output
|
|
@@ -221,7 +223,7 @@ export interface PipelineRecord {
|
|
|
221
223
|
/**
|
|
222
224
|
* Output returned after Pipeline creation/update
|
|
223
225
|
*/
|
|
224
|
-
export interface
|
|
226
|
+
export interface PipelineResource<_T extends PipelineRecord = PipelineRecord>
|
|
225
227
|
extends Resource<"cloudflare::Pipeline">,
|
|
226
228
|
PipelineProps {
|
|
227
229
|
/**
|
|
@@ -250,6 +252,13 @@ export interface Pipeline<T extends PipelineRecord = PipelineRecord>
|
|
|
250
252
|
version: number;
|
|
251
253
|
}
|
|
252
254
|
|
|
255
|
+
export function isPipeline(resource: Resource): resource is PipelineResource {
|
|
256
|
+
return resource[ResourceKind] === "cloudflare::Pipeline";
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export type Pipeline<T extends PipelineRecord = PipelineRecord> =
|
|
260
|
+
PipelineResource<T> & Bound<PipelineResource<T>>;
|
|
261
|
+
|
|
253
262
|
/**
|
|
254
263
|
* Creates and manages Cloudflare Pipelines.
|
|
255
264
|
*
|
|
@@ -316,10 +325,24 @@ export interface Pipeline<T extends PipelineRecord = PipelineRecord>
|
|
|
316
325
|
*
|
|
317
326
|
* @see https://developers.cloudflare.com/pipelines/
|
|
318
327
|
*/
|
|
319
|
-
export
|
|
328
|
+
export async function Pipeline<T extends PipelineRecord = PipelineRecord>(
|
|
329
|
+
name: string,
|
|
330
|
+
props: PipelineProps,
|
|
331
|
+
): Promise<Pipeline<T>> {
|
|
332
|
+
const pipeline = await PipelineResource(name, props);
|
|
333
|
+
const binding = await bind(pipeline, {
|
|
334
|
+
bindThis: false,
|
|
335
|
+
});
|
|
336
|
+
return {
|
|
337
|
+
...pipeline,
|
|
338
|
+
send: binding.send,
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const PipelineResource = Resource("cloudflare::Pipeline", async function <
|
|
320
343
|
T extends PipelineRecord = PipelineRecord,
|
|
321
|
-
>(this: Context<
|
|
322
|
-
|
|
344
|
+
>(this: Context<PipelineResource<T>>, id: string, props: PipelineProps): Promise<
|
|
345
|
+
PipelineResource<T>
|
|
323
346
|
> {
|
|
324
347
|
const api = await createCloudflareApi(props);
|
|
325
348
|
const pipelineName = props.name ?? id;
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
type CloudflareApi,
|
|
7
7
|
type CloudflareApiOptions,
|
|
8
8
|
} from "./api.js";
|
|
9
|
-
import type {
|
|
9
|
+
import type { QueueResource } from "./queue.js";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Settings for configuring a Queue Consumer
|
|
@@ -51,7 +51,7 @@ export interface QueueConsumerProps extends CloudflareApiOptions {
|
|
|
51
51
|
* The queue to consume
|
|
52
52
|
* Either queue or queueId must be provided
|
|
53
53
|
*/
|
|
54
|
-
queue?:
|
|
54
|
+
queue?: QueueResource;
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* The queue ID to consume (alternative to providing a queue)
|
|
@@ -138,7 +138,7 @@ export const QueueConsumer = Resource(
|
|
|
138
138
|
"cloudflare::QueueConsumer",
|
|
139
139
|
async function (
|
|
140
140
|
this: Context<QueueConsumer>,
|
|
141
|
-
|
|
141
|
+
_id: string,
|
|
142
142
|
props: QueueConsumerProps,
|
|
143
143
|
): Promise<QueueConsumer> {
|
|
144
144
|
const api = await createCloudflareApi(props);
|
package/src/cloudflare/queue.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { Context } from "../context.js";
|
|
2
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
|
* Settings for a Cloudflare Queue
|
|
@@ -56,6 +58,14 @@ export interface QueueProps extends CloudflareApiOptions {
|
|
|
56
58
|
* @default true
|
|
57
59
|
*/
|
|
58
60
|
delete?: boolean;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Whether to adopt an existing queue with the same name if it exists
|
|
64
|
+
* If true, during creation, if a queue with the same name exists, it will be adopted instead of creating a new one
|
|
65
|
+
*
|
|
66
|
+
* @default false
|
|
67
|
+
*/
|
|
68
|
+
adopt?: boolean;
|
|
59
69
|
}
|
|
60
70
|
|
|
61
71
|
export function isQueue(eventSource: any): eventSource is Queue {
|
|
@@ -68,7 +78,7 @@ export function isQueue(eventSource: any): eventSource is Queue {
|
|
|
68
78
|
/**
|
|
69
79
|
* Output returned after Cloudflare Queue creation/update
|
|
70
80
|
*/
|
|
71
|
-
export interface
|
|
81
|
+
export interface QueueResource<Body = unknown>
|
|
72
82
|
extends Resource<"cloudflare::Queue">,
|
|
73
83
|
QueueProps {
|
|
74
84
|
/**
|
|
@@ -104,22 +114,8 @@ export interface Queue<Body = unknown>
|
|
|
104
114
|
Batch: MessageBatch<Body>;
|
|
105
115
|
}
|
|
106
116
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
queue_id?: string;
|
|
110
|
-
queue_name: string;
|
|
111
|
-
created_on?: string;
|
|
112
|
-
modified_on?: string;
|
|
113
|
-
settings?: {
|
|
114
|
-
delivery_delay?: number;
|
|
115
|
-
delivery_paused?: boolean;
|
|
116
|
-
message_retention_period?: number;
|
|
117
|
-
};
|
|
118
|
-
};
|
|
119
|
-
success: boolean;
|
|
120
|
-
errors: Array<{ code: number; message: string }>;
|
|
121
|
-
messages: string[];
|
|
122
|
-
}
|
|
117
|
+
export type Queue<Body = unknown> = QueueResource<Body> &
|
|
118
|
+
Bound<QueueResource<Body>>;
|
|
123
119
|
|
|
124
120
|
/**
|
|
125
121
|
* Creates and manages Cloudflare Queues.
|
|
@@ -154,10 +150,23 @@ interface CloudflareQueueResponse {
|
|
|
154
150
|
*
|
|
155
151
|
* @see https://developers.cloudflare.com/queues/
|
|
156
152
|
*/
|
|
157
|
-
export
|
|
153
|
+
export async function Queue<Body = unknown>(
|
|
154
|
+
name: string,
|
|
155
|
+
props: QueueProps = {},
|
|
156
|
+
): Promise<Queue<Body>> {
|
|
157
|
+
const queue = await QueueResource<Body>(name, props);
|
|
158
|
+
const binding = await bind(queue);
|
|
159
|
+
return {
|
|
160
|
+
...queue,
|
|
161
|
+
send: binding.send,
|
|
162
|
+
sendBatch: binding.sendBatch,
|
|
163
|
+
} as Queue<Body>;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const QueueResource = Resource("cloudflare::Queue", async function <
|
|
158
167
|
T = unknown,
|
|
159
|
-
>(this: Context<
|
|
160
|
-
|
|
168
|
+
>(this: Context<QueueResource<T>>, id: string, props: QueueProps = {}): Promise<
|
|
169
|
+
QueueResource<T>
|
|
161
170
|
> {
|
|
162
171
|
const api = await createCloudflareApi(props);
|
|
163
172
|
const queueName = props.name ?? id;
|
|
@@ -166,6 +175,9 @@ export const Queue = Resource("cloudflare::Queue", async function <
|
|
|
166
175
|
console.log("Deleting Cloudflare Queue:", queueName);
|
|
167
176
|
if (props.delete !== false) {
|
|
168
177
|
// Delete Queue
|
|
178
|
+
if (!this.output?.id) {
|
|
179
|
+
console.log(this.output);
|
|
180
|
+
}
|
|
169
181
|
await deleteQueue(api, this.output?.id);
|
|
170
182
|
}
|
|
171
183
|
|
|
@@ -176,16 +188,35 @@ export const Queue = Resource("cloudflare::Queue", async function <
|
|
|
176
188
|
|
|
177
189
|
if (this.phase === "create") {
|
|
178
190
|
console.log("Creating Cloudflare Queue:", queueName);
|
|
179
|
-
|
|
191
|
+
try {
|
|
192
|
+
queueData = await createQueue(api, queueName, props);
|
|
193
|
+
} catch (error) {
|
|
194
|
+
if (error instanceof CloudflareApiError && error.status === 409) {
|
|
195
|
+
if (!props.adopt) {
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
// Queue already exists, try to find it by name
|
|
199
|
+
const existingQueue = await findQueueByName(api, queueName);
|
|
200
|
+
if (!existingQueue) {
|
|
201
|
+
throw new Error(
|
|
202
|
+
`Queue with name ${queueName} not found despite 409 conflict`,
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
queueData = existingQueue;
|
|
206
|
+
queueData = await updateQueue(api, queueData.result.queue_id!, props);
|
|
207
|
+
} else {
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
180
211
|
} else {
|
|
181
212
|
// Update operation
|
|
182
213
|
if (this.output?.id) {
|
|
183
214
|
console.log("Updating Cloudflare Queue:", queueName);
|
|
184
215
|
|
|
185
216
|
// Check if name is being changed, which is not allowed
|
|
186
|
-
if (
|
|
217
|
+
if (queueName !== this.output.name) {
|
|
187
218
|
throw new Error(
|
|
188
|
-
|
|
219
|
+
`Cannot update Queue name after creation. Queue name is immutable. Before: ${this.output.name}, After: ${queueName}`,
|
|
189
220
|
);
|
|
190
221
|
}
|
|
191
222
|
|
|
@@ -222,6 +253,23 @@ export const Queue = Resource("cloudflare::Queue", async function <
|
|
|
222
253
|
});
|
|
223
254
|
});
|
|
224
255
|
|
|
256
|
+
interface CloudflareQueueResponse {
|
|
257
|
+
result: {
|
|
258
|
+
queue_id?: string;
|
|
259
|
+
queue_name: string;
|
|
260
|
+
created_on?: string;
|
|
261
|
+
modified_on?: string;
|
|
262
|
+
settings?: {
|
|
263
|
+
delivery_delay?: number;
|
|
264
|
+
delivery_paused?: boolean;
|
|
265
|
+
message_retention_period?: number;
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
success: boolean;
|
|
269
|
+
errors: Array<{ code: number; message: string }>;
|
|
270
|
+
messages: string[];
|
|
271
|
+
}
|
|
272
|
+
|
|
225
273
|
/**
|
|
226
274
|
* Create a new Cloudflare Queue
|
|
227
275
|
*/
|
|
@@ -391,3 +439,56 @@ export async function listQueues(
|
|
|
391
439
|
id: queue.queue_id,
|
|
392
440
|
}));
|
|
393
441
|
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Find a Cloudflare Queue by name
|
|
445
|
+
*/
|
|
446
|
+
export async function findQueueByName(
|
|
447
|
+
api: CloudflareApi,
|
|
448
|
+
queueName: string,
|
|
449
|
+
): Promise<CloudflareQueueResponse | null> {
|
|
450
|
+
const response = await api.get(`/accounts/${api.accountId}/queues`);
|
|
451
|
+
|
|
452
|
+
if (!response.ok) {
|
|
453
|
+
return await handleApiError(response, "listing", "Queues", "");
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
const data = (await response.json()) as {
|
|
457
|
+
success: boolean;
|
|
458
|
+
errors?: Array<{ code: number; message: string }>;
|
|
459
|
+
result?: Array<{
|
|
460
|
+
queue_name: string;
|
|
461
|
+
queue_id: string;
|
|
462
|
+
created_on?: string;
|
|
463
|
+
modified_on?: string;
|
|
464
|
+
settings?: {
|
|
465
|
+
delivery_delay?: number;
|
|
466
|
+
delivery_paused?: boolean;
|
|
467
|
+
message_retention_period?: number;
|
|
468
|
+
};
|
|
469
|
+
}>;
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
if (!data.success) {
|
|
473
|
+
const errorMessage = data.errors?.[0]?.message || "Unknown error";
|
|
474
|
+
throw new Error(`Failed to list queues: ${errorMessage}`);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
const queue = data.result?.find((q) => q.queue_name === queueName);
|
|
478
|
+
if (!queue) {
|
|
479
|
+
return null;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
return {
|
|
483
|
+
result: {
|
|
484
|
+
queue_id: queue.queue_id,
|
|
485
|
+
queue_name: queue.queue_name,
|
|
486
|
+
created_on: queue.created_on,
|
|
487
|
+
modified_on: queue.modified_on,
|
|
488
|
+
settings: queue.settings,
|
|
489
|
+
},
|
|
490
|
+
success: true,
|
|
491
|
+
errors: [],
|
|
492
|
+
messages: [],
|
|
493
|
+
};
|
|
494
|
+
}
|
package/src/cloudflare/route.ts
CHANGED
package/src/cloudflare/types.ts
CHANGED
|
@@ -64,7 +64,7 @@ export async function extractCloudflareError(
|
|
|
64
64
|
return data.errors.map((e) => `Error ${e.code}: ${e.message}`).join(", ");
|
|
65
65
|
}
|
|
66
66
|
return `HTTP ${response.status}: ${response.statusText}`;
|
|
67
|
-
} catch
|
|
67
|
+
} catch {
|
|
68
68
|
return `HTTP ${response.status}: ${response.statusText}`;
|
|
69
69
|
}
|
|
70
70
|
}
|