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,6 +1,7 @@
|
|
|
1
1
|
import type { Context } from "../context.js";
|
|
2
2
|
import { StaticJsonFile } from "../fs/static-json-file.js";
|
|
3
3
|
import { Resource } from "../resource.js";
|
|
4
|
+
import { assertNever } from "../util/assert-never.js";
|
|
4
5
|
import { Self, type Bindings } from "./bindings.js";
|
|
5
6
|
import type { DurableObjectNamespace } from "./durable-object-namespace.js";
|
|
6
7
|
import type { EventSource } from "./event-source.js";
|
|
@@ -66,7 +67,7 @@ export const WranglerJson = Resource(
|
|
|
66
67
|
"cloudflare::WranglerJson",
|
|
67
68
|
async function (
|
|
68
69
|
this: Context<WranglerJson>,
|
|
69
|
-
|
|
70
|
+
_id: string,
|
|
70
71
|
props: WranglerJsonProps,
|
|
71
72
|
): Promise<WranglerJson> {
|
|
72
73
|
// Default path is wrangler.json in current directory
|
|
@@ -103,6 +104,10 @@ export const WranglerJson = Resource(
|
|
|
103
104
|
spec.vars = { ...worker.env };
|
|
104
105
|
}
|
|
105
106
|
|
|
107
|
+
if (worker.crons && worker.crons.length > 0) {
|
|
108
|
+
spec.triggers = { crons: worker.crons };
|
|
109
|
+
}
|
|
110
|
+
|
|
106
111
|
await StaticJsonFile(filePath, spec);
|
|
107
112
|
|
|
108
113
|
// Return the resource
|
|
@@ -150,6 +155,13 @@ export interface WranglerJsonSpec {
|
|
|
150
155
|
*/
|
|
151
156
|
routes?: string[];
|
|
152
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Scheduled triggers for the worker
|
|
160
|
+
*/
|
|
161
|
+
triggers?: {
|
|
162
|
+
crons: string[];
|
|
163
|
+
};
|
|
164
|
+
|
|
153
165
|
/**
|
|
154
166
|
* AI bindings
|
|
155
167
|
*/
|
|
@@ -291,6 +303,21 @@ export interface WranglerJsonSpec {
|
|
|
291
303
|
* Whether to minify the worker script
|
|
292
304
|
*/
|
|
293
305
|
minify?: boolean;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Analytics Engine datasets
|
|
309
|
+
*/
|
|
310
|
+
analytics_engine_datasets?: { binding: string; dataset: string }[];
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Hyperdrive bindings
|
|
314
|
+
*/
|
|
315
|
+
hyperdrive?: { binding: string; id: string; localConnectionString: string }[];
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Pipelines
|
|
319
|
+
*/
|
|
320
|
+
pipelines?: { binding: string; pipeline: string }[];
|
|
294
321
|
}
|
|
295
322
|
|
|
296
323
|
/**
|
|
@@ -340,6 +367,13 @@ function processBindings(
|
|
|
340
367
|
const new_classes: string[] = [];
|
|
341
368
|
|
|
342
369
|
const vectorizeIndexes: { binding: string; index_name: string }[] = [];
|
|
370
|
+
const analyticsEngineDatasets: { binding: string; dataset: string }[] = [];
|
|
371
|
+
const hyperdrive: {
|
|
372
|
+
binding: string;
|
|
373
|
+
id: string;
|
|
374
|
+
localConnectionString: string;
|
|
375
|
+
}[] = [];
|
|
376
|
+
const pipelines: { binding: string; pipeline: string }[] = [];
|
|
343
377
|
|
|
344
378
|
for (const eventSource of eventSources ?? []) {
|
|
345
379
|
if (isQueueEventSource(eventSource)) {
|
|
@@ -375,7 +409,7 @@ function processBindings(
|
|
|
375
409
|
// Service binding
|
|
376
410
|
services.push({
|
|
377
411
|
binding: bindingName,
|
|
378
|
-
service: binding.
|
|
412
|
+
service: binding.name,
|
|
379
413
|
});
|
|
380
414
|
} else if (binding.type === "kv_namespace") {
|
|
381
415
|
// KV Namespace binding
|
|
@@ -450,6 +484,33 @@ function processBindings(
|
|
|
450
484
|
spec.ai = {
|
|
451
485
|
binding: bindingName,
|
|
452
486
|
};
|
|
487
|
+
} else if (binding.type === "analytics_engine") {
|
|
488
|
+
analyticsEngineDatasets.push({
|
|
489
|
+
binding: bindingName,
|
|
490
|
+
dataset: binding.dataset,
|
|
491
|
+
});
|
|
492
|
+
} else if (binding.type === "ai_gateway") {
|
|
493
|
+
// no-op
|
|
494
|
+
} else if (binding.type === "hyperdrive") {
|
|
495
|
+
const password =
|
|
496
|
+
"password" in binding.origin
|
|
497
|
+
? binding.origin.password.unencrypted
|
|
498
|
+
: binding.origin.access_client_secret.unencrypted;
|
|
499
|
+
hyperdrive.push({
|
|
500
|
+
binding: bindingName,
|
|
501
|
+
id: binding.hyperdriveId,
|
|
502
|
+
localConnectionString: `${binding.origin.scheme || "postgres"}://${binding.origin.user}:${password}@${binding.origin.host}:${binding.origin.port || 5432}/${binding.origin.database}`,
|
|
503
|
+
});
|
|
504
|
+
} else if (binding.type === "pipeline") {
|
|
505
|
+
pipelines.push({
|
|
506
|
+
binding: bindingName,
|
|
507
|
+
pipeline: binding.name,
|
|
508
|
+
});
|
|
509
|
+
} else if (binding.type === "json") {
|
|
510
|
+
// TODO(sam): anything to do here? not sure wrangler.json supports this
|
|
511
|
+
} else {
|
|
512
|
+
// biome-ignore lint/correctness/noVoidTypeReturn: it returns never
|
|
513
|
+
return assertNever(binding);
|
|
453
514
|
}
|
|
454
515
|
}
|
|
455
516
|
|
|
@@ -497,4 +558,16 @@ function processBindings(
|
|
|
497
558
|
if (workflows.length > 0) {
|
|
498
559
|
spec.workflows = workflows;
|
|
499
560
|
}
|
|
561
|
+
|
|
562
|
+
if (analyticsEngineDatasets.length > 0) {
|
|
563
|
+
spec.analytics_engine_datasets = analyticsEngineDatasets;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
if (hyperdrive.length > 0) {
|
|
567
|
+
spec.hyperdrive = hyperdrive;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
if (pipelines.length > 0) {
|
|
571
|
+
spec.pipelines = pipelines;
|
|
572
|
+
}
|
|
500
573
|
}
|
package/src/cloudflare/zone.ts
CHANGED
package/src/destroy.ts
CHANGED
|
@@ -39,11 +39,11 @@ export async function destroy<Type extends string>(
|
|
|
39
39
|
} satisfies DestroyOptions;
|
|
40
40
|
|
|
41
41
|
// destroy all active resources
|
|
42
|
-
await
|
|
42
|
+
await destroyAll(Array.from(scope.resources.values()), options);
|
|
43
43
|
|
|
44
44
|
// then detect orphans and destroy them
|
|
45
45
|
const orphans = await scope.state.all();
|
|
46
|
-
await
|
|
46
|
+
await destroyAll(
|
|
47
47
|
Object.values(orphans).map((orphan) => ({
|
|
48
48
|
...orphan.output,
|
|
49
49
|
Scope: scope,
|
|
@@ -151,27 +151,16 @@ export async function destroy<Type extends string>(
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
export
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
await Promise.all(
|
|
163
|
-
resources.map((resource) => destroy(resource, options)),
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export async function sequentially(
|
|
169
|
-
...resources: (Resource<string> | undefined | null)[]
|
|
170
|
-
) {
|
|
171
|
-
for (const resource of resources) {
|
|
172
|
-
if (resource) {
|
|
173
|
-
await destroy(resource);
|
|
174
|
-
}
|
|
154
|
+
export async function destroyAll(
|
|
155
|
+
resources: Resource[],
|
|
156
|
+
options?: DestroyOptions,
|
|
157
|
+
) {
|
|
158
|
+
if (options?.strategy !== "parallel") {
|
|
159
|
+
const sorted = resources.sort((a, b) => b[ResourceSeq] - a[ResourceSeq]);
|
|
160
|
+
for (const resource of sorted) {
|
|
161
|
+
await destroy(resource, options);
|
|
175
162
|
}
|
|
163
|
+
} else {
|
|
164
|
+
await Promise.all(resources.map((resource) => destroy(resource, options)));
|
|
176
165
|
}
|
|
177
166
|
}
|
package/src/dns/import-dns.ts
CHANGED
|
@@ -133,7 +133,7 @@ export const ImportDnsRecords = Resource(
|
|
|
133
133
|
"dns::ImportDnsRecords",
|
|
134
134
|
async function (
|
|
135
135
|
this: Context<ImportDnsRecords>,
|
|
136
|
-
|
|
136
|
+
_id: string,
|
|
137
137
|
props: ImportDnsRecordsProps,
|
|
138
138
|
): Promise<ImportDnsRecords> {
|
|
139
139
|
// For delete phase, just return destroyed state since this is a read-only resource
|
package/src/encrypt.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import sodium from "libsodium-wrappers";
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Encrypt a value with a symmetric key using libsodium
|
|
5
3
|
*
|
|
@@ -8,6 +6,7 @@ import sodium from "libsodium-wrappers";
|
|
|
8
6
|
* @returns The base64-encoded encrypted value with nonce
|
|
9
7
|
*/
|
|
10
8
|
export async function encrypt(value: string, key: string): Promise<string> {
|
|
9
|
+
const sodium = (await import("libsodium-wrappers")).default;
|
|
11
10
|
// Initialize libsodium
|
|
12
11
|
await sodium.ready;
|
|
13
12
|
|
|
@@ -46,6 +45,7 @@ export async function decryptWithKey(
|
|
|
46
45
|
encryptedValue: string,
|
|
47
46
|
key: string,
|
|
48
47
|
): Promise<string> {
|
|
48
|
+
const sodium = (await import("libsodium-wrappers")).default;
|
|
49
49
|
// Initialize libsodium
|
|
50
50
|
await sodium.ready;
|
|
51
51
|
|
package/src/env.ts
CHANGED
|
@@ -16,16 +16,23 @@ async function _env<T = string>(
|
|
|
16
16
|
if (value !== undefined) {
|
|
17
17
|
return value;
|
|
18
18
|
}
|
|
19
|
+
const env = await resolveEnv();
|
|
20
|
+
if (name in env) {
|
|
21
|
+
return env[name] as T;
|
|
22
|
+
}
|
|
23
|
+
throw new Error(error ?? `Environment variable ${name} is not set`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function resolveEnv(): Promise<Record<string, any>> {
|
|
19
27
|
if (typeof process !== "undefined") {
|
|
20
|
-
|
|
21
|
-
return process.env[name]! as T;
|
|
28
|
+
return process.env;
|
|
22
29
|
}
|
|
23
|
-
// we are in a browser environment
|
|
24
30
|
try {
|
|
25
31
|
const { env } = await import("cloudflare:workers");
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
32
|
+
return env;
|
|
33
|
+
} catch (_error) {}
|
|
34
|
+
if (typeof import.meta !== "undefined") {
|
|
35
|
+
return import.meta.env;
|
|
36
|
+
}
|
|
37
|
+
throw new Error("No environment found");
|
|
31
38
|
}
|
package/src/esbuild/bundle.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import esbuild from "esbuild";
|
|
1
|
+
import type esbuild from "esbuild";
|
|
2
2
|
import crypto from "node:crypto";
|
|
3
3
|
import fs from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
@@ -122,7 +122,7 @@ export const Bundle = Resource(
|
|
|
122
122
|
},
|
|
123
123
|
async function <Props extends BundleProps>(
|
|
124
124
|
this: Context<Bundle<any>>,
|
|
125
|
-
|
|
125
|
+
_id: string,
|
|
126
126
|
props: Props,
|
|
127
127
|
): Promise<Bundle<Props>> {
|
|
128
128
|
if (this.phase === "delete") {
|
|
@@ -193,7 +193,7 @@ export async function bundle(props: BundleProps) {
|
|
|
193
193
|
// write:
|
|
194
194
|
// props.outdir === undefined && props.outfile === undefined ? false : true,
|
|
195
195
|
// write: false,
|
|
196
|
-
entryPoints: [
|
|
196
|
+
entryPoints: [entryPoint],
|
|
197
197
|
outdir: props.outdir ? props.outdir : props.outfile ? undefined : ".out",
|
|
198
198
|
outfile: props.outfile,
|
|
199
199
|
bundle: true,
|
|
@@ -208,5 +208,6 @@ export async function bundle(props: BundleProps) {
|
|
|
208
208
|
if (process.env.DEBUG) {
|
|
209
209
|
console.log(options);
|
|
210
210
|
}
|
|
211
|
+
const esbuild = await import("esbuild");
|
|
211
212
|
return await esbuild.build(options);
|
|
212
213
|
}
|
package/src/fs/copy-file.ts
CHANGED
package/src/github/client.ts
CHANGED
|
@@ -17,7 +17,7 @@ export async function getGitHubTokenFromCLI(): Promise<string | null> {
|
|
|
17
17
|
// Get the auth token
|
|
18
18
|
const { stdout: token } = await execAsync("gh auth token");
|
|
19
19
|
return token?.trim() || null;
|
|
20
|
-
} catch (
|
|
20
|
+
} catch (_error) {
|
|
21
21
|
return null;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -173,7 +173,7 @@ export const RepositoryEnvironment = Resource(
|
|
|
173
173
|
"github::RepositoryEnvironment",
|
|
174
174
|
async function (
|
|
175
175
|
this: Context<RepositoryEnvironment>,
|
|
176
|
-
|
|
176
|
+
_id: string,
|
|
177
177
|
props: RepositoryEnvironmentProps,
|
|
178
178
|
): Promise<RepositoryEnvironment> {
|
|
179
179
|
// Create authenticated Octokit client
|
|
@@ -210,7 +210,7 @@ export const RepositoryEnvironment = Resource(
|
|
|
210
210
|
}
|
|
211
211
|
try {
|
|
212
212
|
// Check if the environment already exists
|
|
213
|
-
let environmentId: number | undefined
|
|
213
|
+
let environmentId: number | undefined; // Use undefined instead of 0
|
|
214
214
|
try {
|
|
215
215
|
const { data: environments } =
|
|
216
216
|
await octokit.rest.repos.getAllEnvironments({
|
package/src/github/secret.ts
CHANGED
|
@@ -134,7 +134,7 @@ export const GitHubSecret = Resource(
|
|
|
134
134
|
"github::Secret",
|
|
135
135
|
async function (
|
|
136
136
|
this: Context<GitHubSecretOutput>,
|
|
137
|
-
|
|
137
|
+
_id: string,
|
|
138
138
|
props: GitHubSecretProps,
|
|
139
139
|
): Promise<GitHubSecretOutput> {
|
|
140
140
|
// Create authenticated Octokit client - will automatically handle token resolution
|
package/src/neon/api-error.ts
CHANGED
|
@@ -53,11 +53,11 @@ export async function handleApiError(
|
|
|
53
53
|
|
|
54
54
|
try {
|
|
55
55
|
errorData = await response.json();
|
|
56
|
-
} catch (
|
|
56
|
+
} catch (_e) {
|
|
57
57
|
// If we can't parse JSON, just use the response text
|
|
58
58
|
try {
|
|
59
59
|
errorData = { message: await response.text() };
|
|
60
|
-
} catch (
|
|
60
|
+
} catch (_textError) {
|
|
61
61
|
errorData = { message: response.statusText };
|
|
62
62
|
}
|
|
63
63
|
}
|
package/src/os/exec.ts
CHANGED
|
@@ -218,7 +218,7 @@ export const Exec = Resource(
|
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
// Wait for the process to complete
|
|
221
|
-
exitCode = await new Promise<number>((resolve,
|
|
221
|
+
exitCode = await new Promise<number>((resolve, _reject) => {
|
|
222
222
|
childProcess.on("close", (code) => {
|
|
223
223
|
resolve(code || 0);
|
|
224
224
|
});
|
package/src/resource.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { apply } from "./apply.js";
|
|
2
2
|
import type { Context } from "./context.js";
|
|
3
|
-
import { Scope as _Scope } from "./scope.js";
|
|
3
|
+
import { Scope as _Scope, type Scope } from "./scope.js";
|
|
4
4
|
|
|
5
5
|
export const PROVIDERS = new Map<ResourceKind, Provider<string, any>>();
|
|
6
6
|
|
|
@@ -11,6 +11,7 @@ export const ResourceFQN = Symbol.for("alchemy::ResourceFQN");
|
|
|
11
11
|
export type ResourceKind = string;
|
|
12
12
|
export const ResourceKind = Symbol.for("alchemy::ResourceKind");
|
|
13
13
|
export const ResourceScope = Symbol.for("alchemy::ResourceScope");
|
|
14
|
+
export const InnerResourceScope = Symbol.for("alchemy::InnerResourceScope");
|
|
14
15
|
export const ResourceSeq = Symbol.for("alchemy::ResourceSeq");
|
|
15
16
|
|
|
16
17
|
export interface ProviderOptions {
|
|
@@ -34,35 +35,21 @@ export type Provider<
|
|
|
34
35
|
handler: F;
|
|
35
36
|
};
|
|
36
37
|
|
|
37
|
-
export
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
FQN extends ResourceFQN = ResourceFQN,
|
|
42
|
-
Scope extends _Scope = _Scope,
|
|
43
|
-
Seq extends number = number,
|
|
44
|
-
> = Promise<Out> & {
|
|
45
|
-
[ResourceKind]: Kind;
|
|
46
|
-
[ResourceID]: ID;
|
|
47
|
-
[ResourceFQN]: FQN;
|
|
38
|
+
export interface PendingResource<Out = unknown> extends Promise<Out> {
|
|
39
|
+
[ResourceKind]: ResourceKind;
|
|
40
|
+
[ResourceID]: ResourceID;
|
|
41
|
+
[ResourceFQN]: ResourceFQN;
|
|
48
42
|
[ResourceScope]: Scope;
|
|
49
|
-
[ResourceSeq]:
|
|
50
|
-
|
|
43
|
+
[ResourceSeq]: number;
|
|
44
|
+
[InnerResourceScope]: Promise<Scope>;
|
|
45
|
+
}
|
|
51
46
|
|
|
52
|
-
export interface Resource<
|
|
53
|
-
// give each name types for syntax highlighting (differentiation)
|
|
54
|
-
Kind extends ResourceKind = ResourceKind,
|
|
55
|
-
ID extends ResourceID = ResourceID,
|
|
56
|
-
FQN extends ResourceFQN = ResourceFQN,
|
|
57
|
-
Scope extends _Scope = _Scope,
|
|
58
|
-
Seq extends number = number,
|
|
59
|
-
> {
|
|
60
|
-
// use capital letters to avoid collision with conventional camelCase typescript properties
|
|
47
|
+
export interface Resource<Kind extends ResourceKind = ResourceKind> {
|
|
61
48
|
[ResourceKind]: Kind;
|
|
62
|
-
[ResourceID]:
|
|
63
|
-
[ResourceFQN]:
|
|
49
|
+
[ResourceID]: ResourceID;
|
|
50
|
+
[ResourceFQN]: ResourceFQN;
|
|
64
51
|
[ResourceScope]: Scope;
|
|
65
|
-
[ResourceSeq]:
|
|
52
|
+
[ResourceSeq]: number;
|
|
66
53
|
}
|
|
67
54
|
|
|
68
55
|
// helper for semantic syntax highlighting (color as a type/class instead of function/value)
|
|
@@ -102,7 +89,7 @@ export function Resource<
|
|
|
102
89
|
|
|
103
90
|
type Out = Awaited<ReturnType<F>>;
|
|
104
91
|
|
|
105
|
-
const provider = ((
|
|
92
|
+
const provider = (async (
|
|
106
93
|
resourceID: string,
|
|
107
94
|
props: ResourceProps,
|
|
108
95
|
): Promise<Resource<string>> => {
|
|
@@ -123,21 +110,25 @@ export function Resource<
|
|
|
123
110
|
`Resource ${resourceID} already exists in the stack and is of a different type: '${otherResource?.[ResourceKind]}' !== '${type}'`,
|
|
124
111
|
);
|
|
125
112
|
}
|
|
126
|
-
// console.warn(
|
|
127
|
-
// `Resource ${resourceID} already exists in the stack: ${scope.chain.join("/")}`,
|
|
128
|
-
// );
|
|
129
113
|
}
|
|
130
114
|
|
|
131
115
|
// get a sequence number (unique within the scope) for the resource
|
|
132
116
|
const seq = scope.seq();
|
|
117
|
+
let resolveInnerScope: ((scope: Scope) => void) | undefined;
|
|
133
118
|
const meta = {
|
|
134
119
|
[ResourceKind]: type,
|
|
135
120
|
[ResourceID]: resourceID,
|
|
136
121
|
[ResourceFQN]: scope.fqn(resourceID),
|
|
137
122
|
[ResourceSeq]: seq,
|
|
138
123
|
[ResourceScope]: scope,
|
|
124
|
+
[InnerResourceScope]: new Promise<Scope>((resolve) => {
|
|
125
|
+
resolveInnerScope = resolve;
|
|
126
|
+
}),
|
|
139
127
|
} as any as PendingResource<Out>;
|
|
140
|
-
const promise = apply(meta, props,
|
|
128
|
+
const promise = apply(meta, props, {
|
|
129
|
+
...options,
|
|
130
|
+
resolveInnerScope,
|
|
131
|
+
});
|
|
141
132
|
const resource = Object.assign(promise, meta);
|
|
142
133
|
scope.resources.set(resourceID, resource);
|
|
143
134
|
return resource;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { isPromise } from "node:util/types";
|
|
2
|
+
import type { Binding as CloudflareBinding } from "../cloudflare/bindings.js";
|
|
3
|
+
import type { Bound as CloudflareBound } from "../cloudflare/bound.js";
|
|
4
|
+
import { isWorkerStub } from "../cloudflare/worker-stub.js";
|
|
5
|
+
import { isWorker } from "../cloudflare/worker.js";
|
|
6
|
+
import { env } from "../env.js";
|
|
7
|
+
import { ResourceFQN, ResourceScope, type Resource } from "../resource.js";
|
|
8
|
+
import { isRuntime } from "./global.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Get a Resource's Binding from the Environment.
|
|
12
|
+
*/
|
|
13
|
+
export function getBinding<T extends Resource>(resource: T): Promise<Bound<T>> {
|
|
14
|
+
return env[getBindKey(resource)] as Promise<Bound<T>>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function tryGetBinding<T extends Resource>(
|
|
18
|
+
resource: T,
|
|
19
|
+
): Promise<Bound<T>> | undefined {
|
|
20
|
+
if (isRuntime) {
|
|
21
|
+
return getBinding(resource);
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Compute a unique key for where to store a Resource's Binding.
|
|
28
|
+
*/
|
|
29
|
+
export function getBindKey(resource: Resource): string {
|
|
30
|
+
if (isWorker(resource) || isWorkerStub(resource)) {
|
|
31
|
+
return `worker:${resource.name}`;
|
|
32
|
+
}
|
|
33
|
+
const fqn = resource[ResourceFQN];
|
|
34
|
+
const scope = resource[ResourceScope];
|
|
35
|
+
const prefix = `${scope.appName}/${scope.stage}`;
|
|
36
|
+
const key = fqn.slice(prefix.length + 1).replace(/[^a-zA-Z0-9-_]/g, "_");
|
|
37
|
+
return key;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type Bound<T> = T extends CloudflareBinding ? CloudflareBound<T> : T;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Create a lazy binding of a Resource to an environment that exposes the Resource's methods
|
|
44
|
+
* throw a Proxy that delays initialization of the binding until the Resource's methods are accessed.
|
|
45
|
+
*
|
|
46
|
+
* This allows us to run the same code during build time and runtime.
|
|
47
|
+
*/
|
|
48
|
+
export async function bind<T extends Resource>(
|
|
49
|
+
resource: T | Promise<T>,
|
|
50
|
+
options?: {
|
|
51
|
+
reify?: (value: T, key: string) => Promise<Bound<T>>;
|
|
52
|
+
/** @default true */
|
|
53
|
+
bindThis?: boolean;
|
|
54
|
+
},
|
|
55
|
+
): Promise<Bound<T>> {
|
|
56
|
+
if (isPromise(resource)) {
|
|
57
|
+
return resource.then((r) => bind(r, options)) as Promise<Bound<T>>;
|
|
58
|
+
}
|
|
59
|
+
let _runtime: [Bound<T>] | undefined;
|
|
60
|
+
const runtime = async (): Promise<Bound<T>> =>
|
|
61
|
+
(_runtime ??= [
|
|
62
|
+
await (options?.reify
|
|
63
|
+
? options.reify(resource, getBindKey(resource))
|
|
64
|
+
: getBinding(resource)),
|
|
65
|
+
])[0];
|
|
66
|
+
|
|
67
|
+
return new Proxy(() => {}, {
|
|
68
|
+
get: (target: any, prop: string) => {
|
|
69
|
+
if (prop in target) {
|
|
70
|
+
return (resource as T)[prop as keyof T];
|
|
71
|
+
} else if (prop === "then" || prop === "catch" || prop === "finally") {
|
|
72
|
+
return target[prop];
|
|
73
|
+
}
|
|
74
|
+
return async (...args: any[]) => {
|
|
75
|
+
const rt: Bound<T> = await runtime();
|
|
76
|
+
if (rt === undefined) {
|
|
77
|
+
throw new Error(`Resource ${resource[ResourceFQN]} is not bound`);
|
|
78
|
+
}
|
|
79
|
+
const method = rt[prop as keyof Bound<T>];
|
|
80
|
+
if (typeof method !== "function") {
|
|
81
|
+
throw new Error(
|
|
82
|
+
`Method ${prop} on '${resource[ResourceFQN]}' is not a function`,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
if (options?.bindThis !== false) {
|
|
86
|
+
return method.bind(rt)(...args);
|
|
87
|
+
}
|
|
88
|
+
return method(...args);
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
// apply: (target, thisArg, argArray) => {
|
|
92
|
+
// return target(thisArg, ...argArray);
|
|
93
|
+
// },
|
|
94
|
+
}) as T & Bound<T>;
|
|
95
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SerializedScope } from "../serde.js";
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
const __ALCHEMY_WORKER_NAME__: string;
|
|
5
|
+
const __ALCHEMY_RUNTIME__: true;
|
|
6
|
+
const __ALCHEMY_SERIALIZED_SCOPE__: SerializedScope;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// __ALCHEMY_SERIALIZED_SCOPE__ is injected by esbuild when bundling a Worker
|
|
10
|
+
export const isRuntime = typeof __ALCHEMY_RUNTIME__ !== "undefined";
|