alchemy-effect 0.0.0 → 0.2.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/README.md +179 -0
- package/bin/alchemy-effect.js +15 -0
- package/bin/alchemy-effect.js.map +1 -0
- package/bin/alchemy-effect.ts +10 -0
- package/lib/app.d.ts +7 -2
- package/lib/app.d.ts.map +1 -1
- package/lib/app.js +1 -0
- package/lib/app.js.map +1 -1
- package/lib/apply.d.ts +57 -1
- package/lib/apply.d.ts.map +1 -1
- package/lib/apply.js +141 -55
- package/lib/apply.js.map +1 -1
- package/lib/aws/account.d.ts +18 -0
- package/lib/aws/account.d.ts.map +1 -0
- package/lib/aws/account.js +18 -0
- package/lib/aws/account.js.map +1 -0
- package/lib/aws/arn.d.ts +2 -0
- package/lib/aws/arn.d.ts.map +1 -0
- package/lib/aws/arn.js +1 -0
- package/lib/aws/arn.js.map +1 -0
- package/lib/aws/assets.d.ts +8 -0
- package/lib/aws/assets.d.ts.map +1 -0
- package/lib/aws/assets.js +4 -0
- package/lib/aws/assets.js.map +1 -0
- package/lib/aws/bundle.d.ts +4 -0
- package/lib/aws/bundle.d.ts.map +1 -0
- package/lib/aws/bundle.js +4 -0
- package/lib/aws/bundle.js.map +1 -0
- package/lib/aws/client.d.ts +8 -0
- package/lib/aws/client.d.ts.map +1 -0
- package/lib/aws/client.js +28 -0
- package/lib/aws/client.js.map +1 -0
- package/lib/aws/credentials.d.ts +146 -0
- package/lib/aws/credentials.d.ts.map +1 -0
- package/lib/aws/credentials.js +170 -0
- package/lib/aws/credentials.js.map +1 -0
- package/lib/aws/dynamodb/attribute-value.d.ts +20 -0
- package/lib/aws/dynamodb/attribute-value.d.ts.map +1 -0
- package/lib/aws/dynamodb/attribute-value.js +217 -0
- package/lib/aws/dynamodb/attribute-value.js.map +1 -0
- package/lib/aws/dynamodb/client.d.ts +12 -0
- package/lib/aws/dynamodb/client.d.ts.map +1 -0
- package/lib/aws/dynamodb/client.js +11 -0
- package/lib/aws/dynamodb/client.js.map +1 -0
- package/lib/aws/dynamodb/expr.d.ts +41 -0
- package/lib/aws/dynamodb/expr.d.ts.map +1 -0
- package/lib/aws/dynamodb/expr.js +1 -0
- package/lib/aws/dynamodb/expr.js.map +1 -0
- package/lib/aws/dynamodb/index.d.ts +9 -0
- package/lib/aws/dynamodb/index.d.ts.map +1 -0
- package/lib/aws/dynamodb/index.js +10 -0
- package/lib/aws/dynamodb/index.js.map +1 -0
- package/lib/aws/dynamodb/projection.d.ts +25 -0
- package/lib/aws/dynamodb/projection.d.ts.map +1 -0
- package/lib/aws/dynamodb/projection.js +1 -0
- package/lib/aws/dynamodb/projection.js.map +1 -0
- package/lib/aws/dynamodb/secondary-index.d.ts +25 -0
- package/lib/aws/dynamodb/secondary-index.d.ts.map +1 -0
- package/lib/aws/dynamodb/secondary-index.js +4 -0
- package/lib/aws/dynamodb/secondary-index.js.map +1 -0
- package/lib/aws/dynamodb/table.d.ts +56 -0
- package/lib/aws/dynamodb/table.d.ts.map +1 -0
- package/lib/aws/dynamodb/table.get-item.d.ts +55 -0
- package/lib/aws/dynamodb/table.get-item.d.ts.map +1 -0
- package/lib/aws/dynamodb/table.get-item.js +75 -0
- package/lib/aws/dynamodb/table.get-item.js.map +1 -0
- package/lib/aws/dynamodb/table.js +4 -0
- package/lib/aws/dynamodb/table.js.map +1 -0
- package/lib/aws/dynamodb/table.provider.d.ts +8 -0
- package/lib/aws/dynamodb/table.provider.d.ts.map +1 -0
- package/lib/aws/dynamodb/table.provider.js +199 -0
- package/lib/aws/dynamodb/table.provider.js.map +1 -0
- package/lib/aws/ec2/client.d.ts +12 -0
- package/lib/aws/ec2/client.d.ts.map +1 -0
- package/lib/aws/ec2/client.js +11 -0
- package/lib/aws/ec2/client.js.map +1 -0
- package/lib/aws/ec2/index.d.ts +4 -0
- package/lib/aws/ec2/index.d.ts.map +1 -0
- package/lib/aws/ec2/index.js +4 -0
- package/lib/aws/ec2/index.js.map +1 -0
- package/lib/aws/ec2/vpc.d.ts +131 -0
- package/lib/aws/ec2/vpc.d.ts.map +1 -0
- package/lib/aws/ec2/vpc.js +3 -0
- package/lib/aws/ec2/vpc.js.map +1 -0
- package/lib/aws/ec2/vpc.provider.d.ts +7 -0
- package/lib/aws/ec2/vpc.provider.d.ts.map +1 -0
- package/lib/aws/ec2/vpc.provider.js +198 -0
- package/lib/aws/ec2/vpc.provider.js.map +1 -0
- package/lib/aws/iam.d.ts +23 -0
- package/lib/aws/iam.d.ts.map +1 -0
- package/lib/aws/iam.js +7 -0
- package/lib/aws/iam.js.map +1 -0
- package/lib/aws/index.d.ts +32 -0
- package/lib/aws/index.d.ts.map +1 -0
- package/lib/aws/index.js +23 -0
- package/lib/aws/index.js.map +1 -0
- package/lib/aws/lambda/client.d.ts +8 -0
- package/lib/aws/lambda/client.d.ts.map +1 -0
- package/lib/aws/lambda/client.js +7 -0
- package/lib/aws/lambda/client.js.map +1 -0
- package/lib/aws/lambda/consume.d.ts +17 -0
- package/lib/aws/lambda/consume.d.ts.map +1 -0
- package/lib/aws/lambda/consume.js +30 -0
- package/lib/aws/lambda/consume.js.map +1 -0
- package/lib/aws/lambda/function.d.ts +41 -0
- package/lib/aws/lambda/function.d.ts.map +1 -0
- package/lib/aws/lambda/function.handler.d.ts +7 -0
- package/lib/aws/lambda/function.handler.d.ts.map +1 -0
- package/lib/aws/lambda/function.handler.js +8 -0
- package/lib/aws/lambda/function.handler.js.map +1 -0
- package/lib/aws/lambda/function.invoke.d.ts +10 -0
- package/lib/aws/lambda/function.invoke.d.ts.map +1 -0
- package/lib/aws/lambda/function.invoke.js +31 -0
- package/lib/aws/lambda/function.invoke.js.map +1 -0
- package/lib/aws/lambda/function.js +3 -0
- package/lib/aws/lambda/function.js.map +1 -0
- package/lib/aws/lambda/function.provider.d.ts +9 -0
- package/lib/aws/lambda/function.provider.d.ts.map +1 -0
- package/lib/aws/lambda/function.provider.js +465 -0
- package/lib/aws/lambda/function.provider.js.map +1 -0
- package/lib/aws/lambda/index.d.ts +8 -0
- package/lib/aws/lambda/index.d.ts.map +1 -0
- package/lib/aws/lambda/index.js +9 -0
- package/lib/aws/lambda/index.js.map +1 -0
- package/lib/aws/lambda/serve.d.ts +14 -0
- package/lib/aws/lambda/serve.d.ts.map +1 -0
- package/lib/aws/lambda/serve.js +7 -0
- package/lib/aws/lambda/serve.js.map +1 -0
- package/lib/aws/parse-ini.d.ts +4 -0
- package/lib/aws/parse-ini.d.ts.map +1 -0
- package/lib/aws/parse-ini.js +67 -0
- package/lib/aws/parse-ini.js.map +1 -0
- package/lib/aws/profile.d.ts +6 -0
- package/lib/aws/profile.d.ts.map +1 -0
- package/lib/aws/profile.js +4 -0
- package/lib/aws/profile.js.map +1 -0
- package/lib/aws/region.d.ts +19 -0
- package/lib/aws/region.d.ts.map +1 -0
- package/lib/aws/region.js +21 -0
- package/lib/aws/region.js.map +1 -0
- package/lib/aws/s3.d.ts +8 -0
- package/lib/aws/s3.d.ts.map +1 -0
- package/lib/aws/s3.js +7 -0
- package/lib/aws/s3.js.map +1 -0
- package/lib/aws/sqs/client.d.ts +12 -0
- package/lib/aws/sqs/client.d.ts.map +1 -0
- package/lib/aws/sqs/client.js +11 -0
- package/lib/aws/sqs/client.js.map +1 -0
- package/lib/aws/sqs/index.d.ts +7 -0
- package/lib/aws/sqs/index.d.ts.map +1 -0
- package/lib/aws/sqs/index.js +7 -0
- package/lib/aws/sqs/index.js.map +1 -0
- package/lib/aws/sqs/queue.consume.d.ts +12 -0
- package/lib/aws/sqs/queue.consume.d.ts.map +1 -0
- package/lib/aws/sqs/queue.consume.js +3 -0
- package/lib/aws/sqs/queue.consume.js.map +1 -0
- package/lib/aws/sqs/queue.d.ts +79 -0
- package/lib/aws/sqs/queue.d.ts.map +1 -0
- package/lib/aws/sqs/queue.event-source.d.ts +20 -0
- package/lib/aws/sqs/queue.event-source.d.ts.map +1 -0
- package/lib/aws/sqs/queue.event-source.js +148 -0
- package/lib/aws/sqs/queue.event-source.js.map +1 -0
- package/lib/aws/sqs/queue.js +3 -0
- package/lib/aws/sqs/queue.js.map +1 -0
- package/lib/aws/sqs/queue.provider.d.ts +7 -0
- package/lib/aws/sqs/queue.provider.d.ts.map +1 -0
- package/lib/aws/sqs/queue.provider.js +79 -0
- package/lib/aws/sqs/queue.provider.js.map +1 -0
- package/lib/aws/sqs/queue.send-message.d.ts +11 -0
- package/lib/aws/sqs/queue.send-message.d.ts.map +1 -0
- package/lib/aws/sqs/queue.send-message.js +32 -0
- package/lib/aws/sqs/queue.send-message.js.map +1 -0
- package/lib/aws/sts.d.ts +8 -0
- package/lib/aws/sts.d.ts.map +1 -0
- package/lib/aws/sts.js +7 -0
- package/lib/aws/sts.js.map +1 -0
- package/lib/aws/zip.d.ts +3 -0
- package/lib/aws/zip.d.ts.map +1 -0
- package/lib/aws/zip.js +12 -0
- package/lib/aws/zip.js.map +1 -0
- package/lib/binding.d.ts +70 -22
- package/lib/binding.d.ts.map +1 -1
- package/lib/binding.js.map +1 -1
- package/lib/capability.d.ts +38 -0
- package/lib/capability.d.ts.map +1 -1
- package/lib/cli/approve.d.ts +4 -0
- package/lib/cli/approve.d.ts.map +1 -0
- package/lib/cli/approve.js +18 -0
- package/lib/cli/approve.js.map +1 -0
- package/lib/cli/clack.d.ts +14 -0
- package/lib/cli/clack.d.ts.map +1 -0
- package/lib/cli/clack.js +12 -0
- package/lib/cli/clack.js.map +1 -0
- package/lib/cli/components/ApprovePlan.d.ts +8 -0
- package/lib/cli/components/ApprovePlan.d.ts.map +1 -0
- package/lib/cli/components/ApprovePlan.js +30 -0
- package/lib/cli/components/ApprovePlan.js.map +1 -0
- package/lib/cli/components/Plan.d.ts +7 -0
- package/lib/cli/components/Plan.d.ts.map +1 -0
- package/lib/cli/components/Plan.js +100 -0
- package/lib/cli/components/Plan.js.map +1 -0
- package/lib/cli/components/PlanProgress.d.ts +9 -0
- package/lib/cli/components/PlanProgress.d.ts.map +1 -0
- package/lib/cli/components/PlanProgress.js +166 -0
- package/lib/cli/components/PlanProgress.js.map +1 -0
- package/lib/cli/index.d.ts +449 -0
- package/lib/cli/index.d.ts.map +1 -0
- package/lib/cli/index.js +39912 -0
- package/lib/cli/index.js.map +1 -0
- package/lib/cli/main.d.ts +2 -0
- package/lib/cli/main.d.ts.map +1 -0
- package/lib/cli/main.js +1 -0
- package/lib/cli/main.js.map +1 -0
- package/lib/cli/plan.d.ts +13 -0
- package/lib/cli/plan.d.ts.map +1 -0
- package/lib/cli/plan.js +1 -0
- package/lib/cli/plan.js.map +1 -0
- package/lib/cli/progress.d.ts +7 -0
- package/lib/cli/progress.d.ts.map +1 -0
- package/lib/cli/progress.js +30 -0
- package/lib/cli/progress.js.map +1 -0
- package/lib/cli/spinner.d.ts +2 -0
- package/lib/cli/spinner.d.ts.map +1 -0
- package/lib/cli/spinner.js +13 -0
- package/lib/cli/spinner.js.map +1 -0
- package/lib/cloudflare/api.d.ts +36 -0
- package/lib/cloudflare/api.d.ts.map +1 -0
- package/lib/cloudflare/api.js +99 -0
- package/lib/cloudflare/api.js.map +1 -0
- package/lib/cloudflare/context.d.ts +27 -0
- package/lib/cloudflare/context.d.ts.map +1 -0
- package/lib/cloudflare/context.js +24 -0
- package/lib/cloudflare/context.js.map +1 -0
- package/lib/cloudflare/index.d.ts +6 -0
- package/lib/cloudflare/index.d.ts.map +1 -0
- package/lib/cloudflare/index.js +5 -0
- package/lib/cloudflare/index.js.map +1 -0
- package/lib/cloudflare/kv/index.d.ts +4 -0
- package/lib/cloudflare/kv/index.d.ts.map +1 -0
- package/lib/cloudflare/kv/index.js +4 -0
- package/lib/cloudflare/kv/index.js.map +1 -0
- package/lib/cloudflare/kv/namespace.binding.d.ts +8 -0
- package/lib/cloudflare/kv/namespace.binding.d.ts.map +1 -0
- package/lib/cloudflare/kv/namespace.binding.js +15 -0
- package/lib/cloudflare/kv/namespace.binding.js.map +1 -0
- package/lib/cloudflare/kv/namespace.client.d.ts +11 -0
- package/lib/cloudflare/kv/namespace.client.d.ts.map +1 -0
- package/lib/cloudflare/kv/namespace.client.js +31 -0
- package/lib/cloudflare/kv/namespace.client.js.map +1 -0
- package/lib/cloudflare/kv/namespace.d.ts +23 -0
- package/lib/cloudflare/kv/namespace.d.ts.map +1 -0
- package/lib/cloudflare/kv/namespace.js +3 -0
- package/lib/cloudflare/kv/namespace.js.map +1 -0
- package/lib/cloudflare/kv/namespace.provider.d.ts +5 -0
- package/lib/cloudflare/kv/namespace.provider.d.ts.map +1 -0
- package/lib/cloudflare/kv/namespace.provider.js +80 -0
- package/lib/cloudflare/kv/namespace.provider.js.map +1 -0
- package/lib/cloudflare/live.d.ts +11 -0
- package/lib/cloudflare/live.d.ts.map +1 -0
- package/lib/cloudflare/live.js +18 -0
- package/lib/cloudflare/live.js.map +1 -0
- package/lib/cloudflare/r2/bucket.binding.d.ts +8 -0
- package/lib/cloudflare/r2/bucket.binding.d.ts.map +1 -0
- package/lib/cloudflare/r2/bucket.binding.js +18 -0
- package/lib/cloudflare/r2/bucket.binding.js.map +1 -0
- package/lib/cloudflare/r2/bucket.client.d.ts +8 -0
- package/lib/cloudflare/r2/bucket.client.d.ts.map +1 -0
- package/lib/cloudflare/r2/bucket.client.js +9 -0
- package/lib/cloudflare/r2/bucket.client.js.map +1 -0
- package/lib/cloudflare/r2/bucket.d.ts +32 -0
- package/lib/cloudflare/r2/bucket.d.ts.map +1 -0
- package/lib/cloudflare/r2/bucket.del.d.ts +4 -0
- package/lib/cloudflare/r2/bucket.del.d.ts.map +1 -0
- package/lib/cloudflare/r2/bucket.del.js +7 -0
- package/lib/cloudflare/r2/bucket.del.js.map +1 -0
- package/lib/cloudflare/r2/bucket.get.d.ts +5 -0
- package/lib/cloudflare/r2/bucket.get.d.ts.map +1 -0
- package/lib/cloudflare/r2/bucket.get.js +7 -0
- package/lib/cloudflare/r2/bucket.get.js.map +1 -0
- package/lib/cloudflare/r2/bucket.head.d.ts +4 -0
- package/lib/cloudflare/r2/bucket.head.d.ts.map +1 -0
- package/lib/cloudflare/r2/bucket.head.js +7 -0
- package/lib/cloudflare/r2/bucket.head.js.map +1 -0
- package/lib/cloudflare/r2/bucket.js +3 -0
- package/lib/cloudflare/r2/bucket.js.map +1 -0
- package/lib/cloudflare/r2/bucket.list.d.ts +5 -0
- package/lib/cloudflare/r2/bucket.list.d.ts.map +1 -0
- package/lib/cloudflare/r2/bucket.list.js +7 -0
- package/lib/cloudflare/r2/bucket.list.js.map +1 -0
- package/lib/cloudflare/r2/bucket.multipart.d.ts +19 -0
- package/lib/cloudflare/r2/bucket.multipart.d.ts.map +1 -0
- package/lib/cloudflare/r2/bucket.multipart.js +25 -0
- package/lib/cloudflare/r2/bucket.multipart.js.map +1 -0
- package/lib/cloudflare/r2/bucket.provider.d.ts +5 -0
- package/lib/cloudflare/r2/bucket.provider.d.ts.map +1 -0
- package/lib/cloudflare/r2/bucket.provider.js +66 -0
- package/lib/cloudflare/r2/bucket.provider.js.map +1 -0
- package/lib/cloudflare/r2/bucket.put.d.ts +6 -0
- package/lib/cloudflare/r2/bucket.put.d.ts.map +1 -0
- package/lib/cloudflare/r2/bucket.put.js +8 -0
- package/lib/cloudflare/r2/bucket.put.js.map +1 -0
- package/lib/cloudflare/r2/index.d.ts +10 -0
- package/lib/cloudflare/r2/index.d.ts.map +1 -0
- package/lib/cloudflare/r2/index.js +10 -0
- package/lib/cloudflare/r2/index.js.map +1 -0
- package/lib/cloudflare/stream.d.ts +10 -0
- package/lib/cloudflare/stream.d.ts.map +1 -0
- package/lib/cloudflare/stream.js +16 -0
- package/lib/cloudflare/stream.js.map +1 -0
- package/lib/cloudflare/worker/assets.fetch.d.ts +8 -0
- package/lib/cloudflare/worker/assets.fetch.d.ts.map +1 -0
- package/lib/cloudflare/worker/assets.fetch.js +11 -0
- package/lib/cloudflare/worker/assets.fetch.js.map +1 -0
- package/lib/cloudflare/worker/assets.provider.d.ts +66 -0
- package/lib/cloudflare/worker/assets.provider.d.ts.map +1 -0
- package/lib/cloudflare/worker/assets.provider.js +145 -0
- package/lib/cloudflare/worker/assets.provider.js.map +1 -0
- package/lib/cloudflare/worker/index.d.ts +6 -0
- package/lib/cloudflare/worker/index.d.ts.map +1 -0
- package/lib/cloudflare/worker/index.js +5 -0
- package/lib/cloudflare/worker/index.js.map +1 -0
- package/lib/cloudflare/worker/worker.d.ts +67 -0
- package/lib/cloudflare/worker/worker.d.ts.map +1 -0
- package/lib/cloudflare/worker/worker.handler.d.ts +11 -0
- package/lib/cloudflare/worker/worker.handler.d.ts.map +1 -0
- package/lib/cloudflare/worker/worker.handler.js +15 -0
- package/lib/cloudflare/worker/worker.handler.js.map +1 -0
- package/lib/cloudflare/worker/worker.js +4 -0
- package/lib/cloudflare/worker/worker.js.map +1 -0
- package/lib/cloudflare/worker/worker.provider.d.ts +10 -0
- package/lib/cloudflare/worker/worker.provider.d.ts.map +1 -0
- package/lib/cloudflare/worker/worker.provider.js +193 -0
- package/lib/cloudflare/worker/worker.provider.js.map +1 -0
- package/lib/cloudflare/worker/worker.serve.d.ts +39 -0
- package/lib/cloudflare/worker/worker.serve.d.ts.map +1 -0
- package/lib/cloudflare/worker/worker.serve.js +4 -0
- package/lib/cloudflare/worker/worker.serve.js.map +1 -0
- package/lib/destroy.d.ts +1 -3
- package/lib/destroy.d.ts.map +1 -1
- package/lib/destroy.js +5 -0
- package/lib/destroy.js.map +1 -1
- package/lib/dot-alchemy.d.ts +3 -2
- package/lib/dot-alchemy.d.ts.map +1 -1
- package/lib/dot-alchemy.js +3 -2
- package/lib/dot-alchemy.js.map +1 -1
- package/lib/esbuild.d.ts +28 -0
- package/lib/esbuild.d.ts.map +1 -0
- package/lib/esbuild.js +63 -0
- package/lib/esbuild.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -1
- package/lib/plan.d.ts +19 -8
- package/lib/plan.d.ts.map +1 -1
- package/lib/plan.js +144 -72
- package/lib/plan.js.map +1 -1
- package/lib/policy.d.ts +19 -1
- package/lib/policy.d.ts.map +1 -1
- package/lib/policy.js +10 -1
- package/lib/policy.js.map +1 -1
- package/lib/provider.d.ts +2 -2
- package/lib/provider.d.ts.map +1 -1
- package/lib/resource.d.ts +2 -10
- package/lib/resource.d.ts.map +1 -1
- package/lib/resource.js +1 -0
- package/lib/resource.js.map +1 -1
- package/lib/runtime.d.ts +1 -1
- package/lib/runtime.d.ts.map +1 -1
- package/lib/schema.d.ts +37 -0
- package/lib/schema.d.ts.map +1 -0
- package/lib/schema.js +61 -0
- package/lib/schema.js.map +1 -0
- package/lib/sha256.d.ts +5 -0
- package/lib/sha256.d.ts.map +1 -0
- package/lib/sha256.js +16 -0
- package/lib/sha256.js.map +1 -0
- package/lib/state.d.ts +3 -2
- package/lib/state.d.ts.map +1 -1
- package/lib/state.js +3 -2
- package/lib/state.js.map +1 -1
- package/lib/tags.d.ts +17 -0
- package/lib/tags.d.ts.map +1 -0
- package/lib/tags.js +22 -0
- package/lib/tags.js.map +1 -0
- package/lib/test.d.ts +14 -0
- package/lib/test.d.ts.map +1 -0
- package/lib/test.js +28 -0
- package/lib/test.js.map +1 -0
- package/lib/tsconfig.test.tsbuildinfo +1 -0
- package/lib/type.d.ts +3 -0
- package/lib/type.d.ts.map +1 -0
- package/lib/type.js +3 -0
- package/lib/type.js.map +1 -0
- package/package.json +115 -3
- package/src/app.ts +8 -7
- package/src/apply.ts +251 -93
- package/src/aws/account.ts +37 -0
- package/src/aws/arn.ts +1 -0
- package/src/aws/assets.ts +8 -0
- package/src/aws/bundle.ts +5 -0
- package/src/aws/client.ts +47 -0
- package/src/aws/credentials.ts +409 -0
- package/src/aws/dynamodb/attribute-value.ts +240 -0
- package/src/aws/dynamodb/client.ts +20 -0
- package/src/aws/dynamodb/expr.ts +90 -0
- package/src/aws/dynamodb/index.ts +12 -0
- package/src/aws/dynamodb/projection.ts +159 -0
- package/src/aws/dynamodb/secondary-index.ts +45 -0
- package/src/aws/dynamodb/table.get-item.ts +177 -0
- package/src/aws/dynamodb/table.provider.ts +280 -0
- package/src/aws/dynamodb/table.ts +156 -0
- package/src/aws/ec2/client.ts +20 -0
- package/src/aws/ec2/index.ts +3 -0
- package/src/aws/ec2/vpc.provider.ts +285 -0
- package/src/aws/ec2/vpc.ts +152 -0
- package/src/aws/iam.ts +30 -0
- package/src/aws/index.ts +54 -0
- package/src/aws/lambda/client.ts +14 -0
- package/src/aws/lambda/consume.ts +63 -0
- package/src/aws/lambda/function.handler.ts +30 -0
- package/src/aws/lambda/function.invoke.ts +40 -0
- package/src/aws/lambda/function.provider.ts +655 -0
- package/src/aws/lambda/function.ts +45 -0
- package/src/aws/lambda/index.ts +9 -0
- package/src/aws/lambda/serve.ts +29 -0
- package/src/aws/parse-ini.ts +80 -0
- package/src/aws/profile.ts +6 -0
- package/src/aws/region.ts +37 -0
- package/src/aws/s3.ts +10 -0
- package/src/aws/sqs/client.ts +20 -0
- package/src/aws/sqs/index.ts +6 -0
- package/src/aws/sqs/queue.consume.ts +13 -0
- package/src/aws/sqs/queue.event-source.ts +253 -0
- package/src/aws/sqs/queue.provider.ts +94 -0
- package/src/aws/sqs/queue.send-message.ts +51 -0
- package/src/aws/sqs/queue.ts +86 -0
- package/src/aws/sts.ts +13 -0
- package/src/aws/zip.ts +17 -0
- package/src/binding.ts +121 -25
- package/src/capability.ts +44 -0
- package/src/cli/approve.tsx +30 -0
- package/src/cli/clack.ts +22 -0
- package/src/cli/components/ApprovePlan.tsx +44 -0
- package/src/cli/components/Plan.tsx +154 -0
- package/src/cli/components/PlanProgress.tsx +206 -0
- package/src/cli/index.ts +6 -0
- package/src/cli/main.ts +0 -0
- package/src/cli/plan.ts +16 -0
- package/src/cli/progress.tsx +46 -0
- package/src/cli/spinner.ts +14 -0
- package/src/cloudflare/api.ts +152 -0
- package/src/cloudflare/context.ts +49 -0
- package/src/cloudflare/index.ts +6 -0
- package/src/cloudflare/kv/index.ts +3 -0
- package/src/cloudflare/kv/namespace.binding.ts +25 -0
- package/src/cloudflare/kv/namespace.client.ts +70 -0
- package/src/cloudflare/kv/namespace.provider.ts +99 -0
- package/src/cloudflare/kv/namespace.ts +29 -0
- package/src/cloudflare/live.ts +38 -0
- package/src/cloudflare/r2/bucket.binding.ts +27 -0
- package/src/cloudflare/r2/bucket.client.ts +22 -0
- package/src/cloudflare/r2/bucket.del.ts +11 -0
- package/src/cloudflare/r2/bucket.get.ts +13 -0
- package/src/cloudflare/r2/bucket.head.ts +11 -0
- package/src/cloudflare/r2/bucket.list.ts +12 -0
- package/src/cloudflare/r2/bucket.multipart.ts +55 -0
- package/src/cloudflare/r2/bucket.provider.ts +83 -0
- package/src/cloudflare/r2/bucket.put.ts +17 -0
- package/src/cloudflare/r2/bucket.ts +38 -0
- package/src/cloudflare/r2/index.ts +9 -0
- package/src/cloudflare/stream.ts +21 -0
- package/src/cloudflare/worker/assets.fetch.ts +27 -0
- package/src/cloudflare/worker/assets.provider.ts +249 -0
- package/src/cloudflare/worker/index.ts +6 -0
- package/src/cloudflare/worker/worker.handler.ts +39 -0
- package/src/cloudflare/worker/worker.provider.ts +246 -0
- package/src/cloudflare/worker/worker.serve.ts +19 -0
- package/src/cloudflare/worker/worker.ts +76 -0
- package/src/destroy.ts +6 -3
- package/src/dot-alchemy.ts +3 -2
- package/src/esbuild.ts +98 -0
- package/src/index.ts +5 -0
- package/src/plan.ts +233 -120
- package/src/policy.ts +55 -2
- package/src/provider.ts +2 -2
- package/src/resource.ts +3 -2
- package/src/runtime.ts +1 -1
- package/src/schema.ts +102 -0
- package/src/sha256.ts +23 -0
- package/src/state.ts +3 -2
- package/src/tags.ts +38 -0
- package/src/test.ts +71 -0
- package/src/type.ts +2 -0
|
@@ -0,0 +1,655 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { FileSystem } from "@effect/platform";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Schedule from "effect/Schedule";
|
|
7
|
+
|
|
8
|
+
import { App, DotAlchemy, type ProviderService } from "alchemy-effect";
|
|
9
|
+
|
|
10
|
+
import type {
|
|
11
|
+
CreateFunctionRequest,
|
|
12
|
+
CreateFunctionUrlConfigRequest,
|
|
13
|
+
UpdateFunctionUrlConfigRequest,
|
|
14
|
+
} from "itty-aws/lambda";
|
|
15
|
+
import { createTagger, createTagsList, hasTags } from "../../tags.ts";
|
|
16
|
+
import { Account } from "../account.ts";
|
|
17
|
+
import * as IAM from "../iam.ts";
|
|
18
|
+
import { Region } from "../region.ts";
|
|
19
|
+
import { zipCode } from "../zip.ts";
|
|
20
|
+
import { LambdaClient } from "./client.ts";
|
|
21
|
+
import { Function, type FunctionAttr, type FunctionProps } from "./function.ts";
|
|
22
|
+
|
|
23
|
+
export const functionProvider = () =>
|
|
24
|
+
Function.provider.effect(
|
|
25
|
+
Effect.gen(function* () {
|
|
26
|
+
const lambda = yield* LambdaClient;
|
|
27
|
+
const iam = yield* IAM.IAMClient;
|
|
28
|
+
const accountId = yield* Account;
|
|
29
|
+
const region = yield* Region;
|
|
30
|
+
const app = yield* App;
|
|
31
|
+
const dotAlchemy = yield* DotAlchemy;
|
|
32
|
+
const fs = yield* FileSystem.FileSystem;
|
|
33
|
+
|
|
34
|
+
// const assets = yield* Assets;
|
|
35
|
+
|
|
36
|
+
const createFunctionName = (id: string) =>
|
|
37
|
+
`${app.name}-${app.stage}-${id}-${region}`;
|
|
38
|
+
const createRoleName = (id: string) =>
|
|
39
|
+
`${app.name}-${app.stage}-${id}-${region}`;
|
|
40
|
+
const createPolicyName = (id: string) =>
|
|
41
|
+
`${app.name}-${app.stage}-${id}-${region}`;
|
|
42
|
+
|
|
43
|
+
const createPhysicalNames = (id: string) => {
|
|
44
|
+
const roleName = createRoleName(id);
|
|
45
|
+
const policyName = createPolicyName(id);
|
|
46
|
+
const functionName = createFunctionName(id);
|
|
47
|
+
return {
|
|
48
|
+
roleName,
|
|
49
|
+
policyName,
|
|
50
|
+
functionName,
|
|
51
|
+
roleArn: `arn:aws:iam::${accountId}:role/${roleName}`,
|
|
52
|
+
functionArn: `arn:aws:lambda:${region}:${accountId}:function:${functionName}`,
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const attachBindings = Effect.fn(function* ({
|
|
57
|
+
roleName,
|
|
58
|
+
policyName,
|
|
59
|
+
// functionArn,
|
|
60
|
+
// functionName,
|
|
61
|
+
bindings,
|
|
62
|
+
}: {
|
|
63
|
+
roleName: string;
|
|
64
|
+
policyName: string;
|
|
65
|
+
functionArn: string;
|
|
66
|
+
functionName: string;
|
|
67
|
+
bindings: Function["binding"][];
|
|
68
|
+
}) {
|
|
69
|
+
const env = bindings
|
|
70
|
+
.map((binding) => binding?.env)
|
|
71
|
+
.reduce((acc, env) => ({ ...acc, ...(env ?? {}) }), {});
|
|
72
|
+
const policyStatements = bindings.flatMap(
|
|
73
|
+
(binding) =>
|
|
74
|
+
binding?.policyStatements?.map((stmt: IAM.PolicyStatement) => ({
|
|
75
|
+
...stmt,
|
|
76
|
+
Sid: stmt.Sid?.replace(/[^A-Za-z0-9]+/gi, ""),
|
|
77
|
+
})) ?? [],
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
if (policyStatements.length > 0) {
|
|
81
|
+
yield* iam.putRolePolicy({
|
|
82
|
+
RoleName: roleName,
|
|
83
|
+
PolicyName: policyName,
|
|
84
|
+
PolicyDocument: JSON.stringify({
|
|
85
|
+
Version: "2012-10-17",
|
|
86
|
+
Statement: policyStatements,
|
|
87
|
+
} satisfies IAM.PolicyDocument),
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
yield* iam
|
|
91
|
+
.deleteRolePolicy({
|
|
92
|
+
RoleName: roleName,
|
|
93
|
+
PolicyName: policyName,
|
|
94
|
+
})
|
|
95
|
+
.pipe(Effect.catchTag("NoSuchEntityException", () => Effect.void));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return env;
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const createRoleIfNotExists = Effect.fn(function* ({
|
|
102
|
+
id,
|
|
103
|
+
roleName,
|
|
104
|
+
}: {
|
|
105
|
+
id: string;
|
|
106
|
+
roleName: string;
|
|
107
|
+
}) {
|
|
108
|
+
yield* Effect.logDebug(`creating role ${id}`);
|
|
109
|
+
const role = yield* iam
|
|
110
|
+
.createRole({
|
|
111
|
+
RoleName: roleName,
|
|
112
|
+
AssumeRolePolicyDocument: JSON.stringify({
|
|
113
|
+
Version: "2012-10-17",
|
|
114
|
+
Statement: [
|
|
115
|
+
{
|
|
116
|
+
Effect: "Allow",
|
|
117
|
+
Principal: {
|
|
118
|
+
Service: "lambda.amazonaws.com",
|
|
119
|
+
},
|
|
120
|
+
Action: "sts:AssumeRole",
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
}),
|
|
124
|
+
Tags: createTagsList(tagged(id)),
|
|
125
|
+
})
|
|
126
|
+
.pipe(
|
|
127
|
+
Effect.catchTag("EntityAlreadyExistsException", () =>
|
|
128
|
+
iam
|
|
129
|
+
.getRole({
|
|
130
|
+
RoleName: roleName,
|
|
131
|
+
})
|
|
132
|
+
.pipe(
|
|
133
|
+
Effect.filterOrFail(
|
|
134
|
+
(role) => hasTags(tagged(id), role.Role?.Tags),
|
|
135
|
+
() =>
|
|
136
|
+
new Error(
|
|
137
|
+
`Role ${roleName} exists but has incorrect tags`,
|
|
138
|
+
),
|
|
139
|
+
),
|
|
140
|
+
),
|
|
141
|
+
),
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
yield* Effect.logDebug(`attaching policy ${id}`);
|
|
145
|
+
yield* iam
|
|
146
|
+
.attachRolePolicy({
|
|
147
|
+
RoleName: roleName,
|
|
148
|
+
PolicyArn:
|
|
149
|
+
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole",
|
|
150
|
+
})
|
|
151
|
+
.pipe(Effect.tapError(Effect.logDebug), Effect.tap(Effect.logDebug));
|
|
152
|
+
|
|
153
|
+
yield* Effect.logDebug(`attached policy ${id}`);
|
|
154
|
+
return role;
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const bundleCode = Effect.fn(function* (
|
|
158
|
+
id: string,
|
|
159
|
+
props: FunctionProps,
|
|
160
|
+
) {
|
|
161
|
+
const handler = props.handler ?? "default";
|
|
162
|
+
let file = path.relative(process.cwd(), props.main);
|
|
163
|
+
if (!file.startsWith(".")) {
|
|
164
|
+
file = `./${file}`;
|
|
165
|
+
}
|
|
166
|
+
const { bundle } = yield* Effect.promise(() => import("../bundle.ts"));
|
|
167
|
+
const outfile = path.join(
|
|
168
|
+
dotAlchemy,
|
|
169
|
+
"out",
|
|
170
|
+
`${app.name}-${app.stage}-${id}.ts`,
|
|
171
|
+
);
|
|
172
|
+
yield* bundle({
|
|
173
|
+
// entryPoints: [props.main],
|
|
174
|
+
// we use a virtual entry point so that we can pluck out the user's handler closure and only its dependencies (not the whole module)
|
|
175
|
+
stdin: {
|
|
176
|
+
contents: `import { ${handler} as handler } from "${file}";\nexport default handler;`,
|
|
177
|
+
resolveDir: process.cwd(),
|
|
178
|
+
loader: "ts",
|
|
179
|
+
sourcefile: "__index.ts",
|
|
180
|
+
},
|
|
181
|
+
bundle: true,
|
|
182
|
+
format: "esm",
|
|
183
|
+
platform: "node",
|
|
184
|
+
target: "node22",
|
|
185
|
+
sourcemap: true,
|
|
186
|
+
treeShaking: true,
|
|
187
|
+
write: true,
|
|
188
|
+
outfile,
|
|
189
|
+
minify: true,
|
|
190
|
+
external: ["@aws-sdk/*", "@smithy/*"],
|
|
191
|
+
logLevel: "error",
|
|
192
|
+
});
|
|
193
|
+
const code = yield* fs
|
|
194
|
+
.readFile(outfile)
|
|
195
|
+
.pipe(Effect.catchAll(Effect.die));
|
|
196
|
+
return {
|
|
197
|
+
code,
|
|
198
|
+
hash: yield* hashCode(code),
|
|
199
|
+
};
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
const hashCode = (code: string | Uint8Array<ArrayBufferLike>) =>
|
|
203
|
+
Effect.sync(() =>
|
|
204
|
+
crypto.createHash("sha256").update(code).digest("hex"),
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
const tagged = yield* createTagger();
|
|
208
|
+
|
|
209
|
+
const createOrUpdateFunction = Effect.fn(function* ({
|
|
210
|
+
id,
|
|
211
|
+
news,
|
|
212
|
+
roleArn,
|
|
213
|
+
code,
|
|
214
|
+
env,
|
|
215
|
+
functionName,
|
|
216
|
+
}: {
|
|
217
|
+
id: string;
|
|
218
|
+
news: FunctionProps;
|
|
219
|
+
roleArn: string;
|
|
220
|
+
code: string | Uint8Array<ArrayBufferLike>;
|
|
221
|
+
env: Record<string, string> | undefined;
|
|
222
|
+
functionName: string;
|
|
223
|
+
}) {
|
|
224
|
+
yield* Effect.logDebug(`creating function ${id}`);
|
|
225
|
+
const createFunctionRequest: CreateFunctionRequest = {
|
|
226
|
+
FunctionName: functionName,
|
|
227
|
+
Handler: `index.${news.handler ?? "default"}`,
|
|
228
|
+
Role: roleArn,
|
|
229
|
+
Code: {
|
|
230
|
+
// TODO(sam): upload to assets
|
|
231
|
+
ZipFile: yield* zipCode(code),
|
|
232
|
+
},
|
|
233
|
+
Runtime: news.runtime ?? "nodejs22.x",
|
|
234
|
+
Environment: env
|
|
235
|
+
? {
|
|
236
|
+
Variables: env,
|
|
237
|
+
}
|
|
238
|
+
: undefined,
|
|
239
|
+
Tags: tagged(id),
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const getAndUpdate = lambda
|
|
243
|
+
.getFunction({
|
|
244
|
+
FunctionName: functionName,
|
|
245
|
+
})
|
|
246
|
+
.pipe(
|
|
247
|
+
Effect.filterOrFail(
|
|
248
|
+
// if it exists and contains these tags, we will assume it was created by alchemy
|
|
249
|
+
// but state was lost, so if it exists, let's adopt it
|
|
250
|
+
(f) => hasTags(tagged(id), f.Tags),
|
|
251
|
+
() =>
|
|
252
|
+
// TODO(sam): add custom
|
|
253
|
+
new Error("Function tags do not match expected values"),
|
|
254
|
+
),
|
|
255
|
+
Effect.flatMap(() =>
|
|
256
|
+
Effect.gen(function* () {
|
|
257
|
+
yield* Effect.logDebug(`updating function code ${id}`);
|
|
258
|
+
yield* lambda
|
|
259
|
+
.updateFunctionCode({
|
|
260
|
+
FunctionName: createFunctionRequest.FunctionName,
|
|
261
|
+
Architectures: createFunctionRequest.Architectures,
|
|
262
|
+
ZipFile: createFunctionRequest.Code.ZipFile,
|
|
263
|
+
// TODO(sam): support uploading via S3
|
|
264
|
+
})
|
|
265
|
+
.pipe(
|
|
266
|
+
Effect.retry({
|
|
267
|
+
while: (e) => {
|
|
268
|
+
console.log({ e });
|
|
269
|
+
return (
|
|
270
|
+
e._tag === "ResourceConflictException" ||
|
|
271
|
+
(e._tag === "InvalidParameterValueException" &&
|
|
272
|
+
e.message?.includes(
|
|
273
|
+
"The role defined for the function cannot be assumed by Lambda.",
|
|
274
|
+
))
|
|
275
|
+
);
|
|
276
|
+
},
|
|
277
|
+
schedule: Schedule.fixed(100),
|
|
278
|
+
}),
|
|
279
|
+
);
|
|
280
|
+
yield* Effect.logDebug(`updated function code ${id}`);
|
|
281
|
+
yield* lambda
|
|
282
|
+
.updateFunctionConfiguration({
|
|
283
|
+
FunctionName: createFunctionRequest.FunctionName,
|
|
284
|
+
DeadLetterConfig: createFunctionRequest.DeadLetterConfig,
|
|
285
|
+
Description: createFunctionRequest.Description,
|
|
286
|
+
Environment: createFunctionRequest.Environment,
|
|
287
|
+
EphemeralStorage: createFunctionRequest.EphemeralStorage,
|
|
288
|
+
FileSystemConfigs: createFunctionRequest.FileSystemConfigs,
|
|
289
|
+
Handler: createFunctionRequest.Handler,
|
|
290
|
+
ImageConfig: createFunctionRequest.ImageConfig,
|
|
291
|
+
KMSKeyArn: createFunctionRequest.KMSKeyArn,
|
|
292
|
+
Layers: createFunctionRequest.Layers,
|
|
293
|
+
LoggingConfig: createFunctionRequest.LoggingConfig,
|
|
294
|
+
MemorySize: createFunctionRequest.MemorySize,
|
|
295
|
+
// RevisionId: "???"
|
|
296
|
+
Role: createFunctionRequest.Role,
|
|
297
|
+
Runtime: createFunctionRequest.Runtime,
|
|
298
|
+
SnapStart: createFunctionRequest.SnapStart,
|
|
299
|
+
Timeout: createFunctionRequest.Timeout,
|
|
300
|
+
TracingConfig: createFunctionRequest.TracingConfig,
|
|
301
|
+
VpcConfig: createFunctionRequest.VpcConfig,
|
|
302
|
+
})
|
|
303
|
+
.pipe(
|
|
304
|
+
Effect.retry({
|
|
305
|
+
while: (e) =>
|
|
306
|
+
e._tag === "ResourceConflictException" ||
|
|
307
|
+
(e._tag === "InvalidParameterValueException" &&
|
|
308
|
+
e.message?.includes(
|
|
309
|
+
"The role defined for the function cannot be assumed by Lambda.",
|
|
310
|
+
)),
|
|
311
|
+
schedule: Schedule.exponential(100),
|
|
312
|
+
}),
|
|
313
|
+
);
|
|
314
|
+
yield* Effect.logDebug(`updated function configuration ${id}`);
|
|
315
|
+
}),
|
|
316
|
+
),
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
yield* lambda.createFunction(createFunctionRequest).pipe(
|
|
320
|
+
Effect.tapError(Effect.logDebug),
|
|
321
|
+
Effect.retry({
|
|
322
|
+
while: (e) =>
|
|
323
|
+
e._tag === "InvalidParameterValueException" &&
|
|
324
|
+
e.message?.includes("cannot be assumed by Lambda"),
|
|
325
|
+
schedule: Schedule.exponential(10),
|
|
326
|
+
}),
|
|
327
|
+
Effect.catchTags({
|
|
328
|
+
ResourceConflictException: () => getAndUpdate,
|
|
329
|
+
}),
|
|
330
|
+
);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
const createOrUpdateFunctionUrl = Effect.fn(function* ({
|
|
334
|
+
functionName,
|
|
335
|
+
url,
|
|
336
|
+
oldUrl,
|
|
337
|
+
}: {
|
|
338
|
+
functionName: string;
|
|
339
|
+
url: FunctionProps["url"];
|
|
340
|
+
oldUrl?: FunctionProps["url"];
|
|
341
|
+
}) {
|
|
342
|
+
// TODO(sam): support AWS_IAM
|
|
343
|
+
const authType = "NONE";
|
|
344
|
+
yield* Effect.logDebug(`creating function url config ${functionName}`);
|
|
345
|
+
if (url) {
|
|
346
|
+
const config = {
|
|
347
|
+
FunctionName: functionName,
|
|
348
|
+
AuthType: authType, // | AWS_IAM
|
|
349
|
+
// Cors: {
|
|
350
|
+
// AllowCredentials: true,
|
|
351
|
+
// AllowHeaders: ["*"],
|
|
352
|
+
// AllowMethods: ["*"],
|
|
353
|
+
// AllowOrigins: ["*"],
|
|
354
|
+
// ExposeHeaders: ["*"],
|
|
355
|
+
// MaxAge: 86400,
|
|
356
|
+
// },
|
|
357
|
+
InvokeMode: "BUFFERED", // | RESPONSE_STREAM
|
|
358
|
+
// Qualifier: "$LATEST"
|
|
359
|
+
} satisfies
|
|
360
|
+
| CreateFunctionUrlConfigRequest
|
|
361
|
+
| UpdateFunctionUrlConfigRequest;
|
|
362
|
+
const permission = {
|
|
363
|
+
FunctionName: functionName,
|
|
364
|
+
StatementId: "FunctionURLAllowPublicAccess",
|
|
365
|
+
Action: "lambda:InvokeFunctionUrl",
|
|
366
|
+
Principal: "*",
|
|
367
|
+
FunctionUrlAuthType: "NONE",
|
|
368
|
+
} as const;
|
|
369
|
+
const [{ FunctionUrl }] = yield* Effect.all([
|
|
370
|
+
lambda
|
|
371
|
+
.createFunctionUrlConfig(config)
|
|
372
|
+
.pipe(
|
|
373
|
+
Effect.catchTag("ResourceConflictException", () =>
|
|
374
|
+
lambda.updateFunctionUrlConfig(config),
|
|
375
|
+
),
|
|
376
|
+
),
|
|
377
|
+
authType === "NONE"
|
|
378
|
+
? lambda.addPermission(permission).pipe(
|
|
379
|
+
Effect.catchTag("ResourceConflictException", () =>
|
|
380
|
+
Effect.gen(function* () {
|
|
381
|
+
yield* lambda.removePermission({
|
|
382
|
+
FunctionName: functionName,
|
|
383
|
+
StatementId: "FunctionURLAllowPublicAccess",
|
|
384
|
+
});
|
|
385
|
+
yield* lambda.addPermission(permission);
|
|
386
|
+
}),
|
|
387
|
+
),
|
|
388
|
+
)
|
|
389
|
+
: Effect.void,
|
|
390
|
+
]);
|
|
391
|
+
yield* Effect.logDebug(`created function url config ${functionName}`);
|
|
392
|
+
return FunctionUrl;
|
|
393
|
+
} else if (oldUrl) {
|
|
394
|
+
yield* Effect.logDebug(
|
|
395
|
+
`deleting function url config ${functionName}`,
|
|
396
|
+
);
|
|
397
|
+
yield* Effect.all([
|
|
398
|
+
lambda
|
|
399
|
+
.deleteFunctionUrlConfig({
|
|
400
|
+
FunctionName: functionName,
|
|
401
|
+
})
|
|
402
|
+
.pipe(
|
|
403
|
+
Effect.catchTag("ResourceNotFoundException", () => Effect.void),
|
|
404
|
+
),
|
|
405
|
+
lambda
|
|
406
|
+
.removePermission({
|
|
407
|
+
FunctionName: functionName,
|
|
408
|
+
StatementId: "FunctionURLAllowPublicAccess",
|
|
409
|
+
})
|
|
410
|
+
.pipe(
|
|
411
|
+
Effect.catchTag("ResourceNotFoundException", () => Effect.void),
|
|
412
|
+
),
|
|
413
|
+
]);
|
|
414
|
+
yield* Effect.logDebug(`deleted function url config ${functionName}`);
|
|
415
|
+
}
|
|
416
|
+
return undefined;
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
const summary = ({ code }: { code: Uint8Array<ArrayBufferLike> }) =>
|
|
420
|
+
`${
|
|
421
|
+
code.length >= 1024 * 1024
|
|
422
|
+
? `${(code.length / (1024 * 1024)).toFixed(2)}MB`
|
|
423
|
+
: code.length >= 1024
|
|
424
|
+
? `${(code.length / 1024).toFixed(2)}KB`
|
|
425
|
+
: `${code.length}B`
|
|
426
|
+
}`;
|
|
427
|
+
|
|
428
|
+
return {
|
|
429
|
+
read: Effect.fn(function* ({ id, output }) {
|
|
430
|
+
if (output) {
|
|
431
|
+
yield* Effect.logDebug(`reading function ${id}`);
|
|
432
|
+
// example: refresh the function URL from the API
|
|
433
|
+
return {
|
|
434
|
+
...output,
|
|
435
|
+
functionUrl: (yield* lambda
|
|
436
|
+
.getFunctionUrlConfig({
|
|
437
|
+
FunctionName: createFunctionName(id),
|
|
438
|
+
})
|
|
439
|
+
.pipe(
|
|
440
|
+
Effect.map((f) => f.FunctionUrl),
|
|
441
|
+
Effect.retry({
|
|
442
|
+
// error: ResourceConflictException: The operation cannot be performed at this time.
|
|
443
|
+
// An update is in progress for resource: arn:aws:lambda:us-west-2:084828582823:function:my-app-dev-Consumer-us-west-2
|
|
444
|
+
while: (e) => e.name === "ResourceConflictException",
|
|
445
|
+
schedule: Schedule.exponential(100),
|
|
446
|
+
}),
|
|
447
|
+
Effect.catchTag("ResourceNotFoundException", () =>
|
|
448
|
+
Effect.succeed(undefined),
|
|
449
|
+
),
|
|
450
|
+
)) as any,
|
|
451
|
+
} satisfies FunctionAttr<FunctionProps>;
|
|
452
|
+
}
|
|
453
|
+
return output;
|
|
454
|
+
}),
|
|
455
|
+
diff: Effect.fn(function* ({ id, olds, news, output }) {
|
|
456
|
+
if (
|
|
457
|
+
// function name changed
|
|
458
|
+
output.functionName !==
|
|
459
|
+
(news.functionName ?? createFunctionName(id)) ||
|
|
460
|
+
// url changed
|
|
461
|
+
olds.url !== news.url
|
|
462
|
+
) {
|
|
463
|
+
return { action: "replace" };
|
|
464
|
+
} else if (output.code.hash !== (yield* bundleCode(id, news)).hash) {
|
|
465
|
+
// code changed
|
|
466
|
+
return { action: "update" };
|
|
467
|
+
}
|
|
468
|
+
}),
|
|
469
|
+
precreate: Effect.fn(function* ({ id, news, session }) {
|
|
470
|
+
const { roleName, functionName, roleArn } = createPhysicalNames(id);
|
|
471
|
+
|
|
472
|
+
const role = yield* createRoleIfNotExists({ id, roleName });
|
|
473
|
+
|
|
474
|
+
// mock code
|
|
475
|
+
const code = "export default () => {}";
|
|
476
|
+
yield* createOrUpdateFunction({
|
|
477
|
+
id,
|
|
478
|
+
news,
|
|
479
|
+
roleArn: role.Role.Arn,
|
|
480
|
+
code,
|
|
481
|
+
functionName,
|
|
482
|
+
env: {},
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
return {
|
|
486
|
+
functionArn: `arn:aws:lambda:${region}:${accountId}:function:${functionName}`,
|
|
487
|
+
functionName,
|
|
488
|
+
functionUrl: undefined,
|
|
489
|
+
roleName: createRoleName(id),
|
|
490
|
+
code: {
|
|
491
|
+
hash: yield* hashCode(code),
|
|
492
|
+
},
|
|
493
|
+
roleArn,
|
|
494
|
+
} satisfies FunctionAttr<FunctionProps>;
|
|
495
|
+
}),
|
|
496
|
+
create: Effect.fn(function* ({ id, news, bindings, session }) {
|
|
497
|
+
const roleName = createRoleName(id);
|
|
498
|
+
const policyName = createPolicyName(id);
|
|
499
|
+
// const policyArn = `arn:aws:iam::${accountId}:policy/${policyName}`;
|
|
500
|
+
const functionName = news.functionName ?? createFunctionName(id);
|
|
501
|
+
const functionArn = `arn:aws:lambda:${region}:${accountId}:function:${functionName}`;
|
|
502
|
+
|
|
503
|
+
const role = yield* createRoleIfNotExists({ id, roleName });
|
|
504
|
+
|
|
505
|
+
const env = yield* attachBindings({
|
|
506
|
+
roleName,
|
|
507
|
+
policyName,
|
|
508
|
+
functionArn,
|
|
509
|
+
functionName,
|
|
510
|
+
bindings,
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
const { code, hash } = yield* bundleCode(id, news);
|
|
514
|
+
|
|
515
|
+
yield* createOrUpdateFunction({
|
|
516
|
+
id,
|
|
517
|
+
news,
|
|
518
|
+
roleArn: role.Role.Arn,
|
|
519
|
+
// TODO(sam): upload to assets
|
|
520
|
+
code,
|
|
521
|
+
env,
|
|
522
|
+
functionName,
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
const functionUrl = yield* createOrUpdateFunctionUrl({
|
|
526
|
+
functionName,
|
|
527
|
+
url: news.url,
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
yield* session.note(summary({ code }));
|
|
531
|
+
|
|
532
|
+
return {
|
|
533
|
+
functionArn,
|
|
534
|
+
functionName,
|
|
535
|
+
functionUrl: functionUrl as any,
|
|
536
|
+
roleName,
|
|
537
|
+
roleArn: role.Role.Arn,
|
|
538
|
+
code: {
|
|
539
|
+
hash,
|
|
540
|
+
},
|
|
541
|
+
} satisfies FunctionAttr<FunctionProps>;
|
|
542
|
+
}),
|
|
543
|
+
update: Effect.fn(function* ({
|
|
544
|
+
id,
|
|
545
|
+
news,
|
|
546
|
+
olds,
|
|
547
|
+
bindings,
|
|
548
|
+
output,
|
|
549
|
+
session,
|
|
550
|
+
}) {
|
|
551
|
+
const roleName = createRoleName(id);
|
|
552
|
+
const policyName = createPolicyName(id);
|
|
553
|
+
const functionName = news.functionName ?? createFunctionName(id);
|
|
554
|
+
const functionArn = `arn:aws:lambda:${region}:${accountId}:function:${functionName}`;
|
|
555
|
+
|
|
556
|
+
const env = yield* attachBindings({
|
|
557
|
+
roleName,
|
|
558
|
+
policyName,
|
|
559
|
+
functionArn,
|
|
560
|
+
functionName,
|
|
561
|
+
bindings,
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
const { code, hash } = yield* bundleCode(id, news);
|
|
565
|
+
|
|
566
|
+
yield* createOrUpdateFunction({
|
|
567
|
+
id,
|
|
568
|
+
news,
|
|
569
|
+
roleArn: output.roleArn,
|
|
570
|
+
// TODO(sam): upload to assets
|
|
571
|
+
code,
|
|
572
|
+
env,
|
|
573
|
+
functionName,
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
const functionUrl = yield* createOrUpdateFunctionUrl({
|
|
577
|
+
functionName,
|
|
578
|
+
url: news.url,
|
|
579
|
+
oldUrl: olds.url,
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
yield* session.note(summary({ code }));
|
|
583
|
+
|
|
584
|
+
return {
|
|
585
|
+
...output,
|
|
586
|
+
functionArn,
|
|
587
|
+
functionName,
|
|
588
|
+
functionUrl: functionUrl as any,
|
|
589
|
+
roleName,
|
|
590
|
+
roleArn: output.roleArn,
|
|
591
|
+
code: {
|
|
592
|
+
hash,
|
|
593
|
+
},
|
|
594
|
+
} satisfies FunctionAttr<FunctionProps>;
|
|
595
|
+
}),
|
|
596
|
+
delete: Effect.fn(function* ({ output }) {
|
|
597
|
+
yield* iam
|
|
598
|
+
.listRolePolicies({
|
|
599
|
+
RoleName: output.roleName,
|
|
600
|
+
})
|
|
601
|
+
.pipe(
|
|
602
|
+
Effect.flatMap((policies) =>
|
|
603
|
+
Effect.all(
|
|
604
|
+
(policies.PolicyNames ?? []).map((policyName) =>
|
|
605
|
+
iam.deleteRolePolicy({
|
|
606
|
+
RoleName: output.roleName,
|
|
607
|
+
PolicyName: policyName,
|
|
608
|
+
}),
|
|
609
|
+
),
|
|
610
|
+
),
|
|
611
|
+
),
|
|
612
|
+
);
|
|
613
|
+
|
|
614
|
+
yield* iam
|
|
615
|
+
.listAttachedRolePolicies({
|
|
616
|
+
RoleName: output.roleName,
|
|
617
|
+
})
|
|
618
|
+
.pipe(
|
|
619
|
+
Effect.flatMap((policies) =>
|
|
620
|
+
Effect.all(
|
|
621
|
+
(policies.AttachedPolicies ?? []).map((policy) =>
|
|
622
|
+
iam
|
|
623
|
+
.detachRolePolicy({
|
|
624
|
+
RoleName: output.roleName,
|
|
625
|
+
PolicyArn: policy.PolicyArn!,
|
|
626
|
+
})
|
|
627
|
+
.pipe(
|
|
628
|
+
Effect.catchTag(
|
|
629
|
+
"NoSuchEntityException",
|
|
630
|
+
() => Effect.void,
|
|
631
|
+
),
|
|
632
|
+
),
|
|
633
|
+
),
|
|
634
|
+
),
|
|
635
|
+
),
|
|
636
|
+
);
|
|
637
|
+
|
|
638
|
+
yield* lambda
|
|
639
|
+
.deleteFunction({
|
|
640
|
+
FunctionName: output.functionName,
|
|
641
|
+
})
|
|
642
|
+
.pipe(
|
|
643
|
+
Effect.catchTag("ResourceNotFoundException", () => Effect.void),
|
|
644
|
+
);
|
|
645
|
+
|
|
646
|
+
yield* iam
|
|
647
|
+
.deleteRole({
|
|
648
|
+
RoleName: output.roleName,
|
|
649
|
+
})
|
|
650
|
+
.pipe(Effect.catchTag("NoSuchEntityException", () => Effect.void));
|
|
651
|
+
return null as any;
|
|
652
|
+
}),
|
|
653
|
+
} satisfies ProviderService<Function>;
|
|
654
|
+
}),
|
|
655
|
+
);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Runtime, type Capability, type RuntimeProps } from "alchemy-effect";
|
|
2
|
+
import type * as IAM from "../iam.ts";
|
|
3
|
+
|
|
4
|
+
export type { Context } from "aws-lambda";
|
|
5
|
+
|
|
6
|
+
export interface FunctionProps<Req = any> extends RuntimeProps<Function, Req> {
|
|
7
|
+
functionName?: string;
|
|
8
|
+
functionArn?: string;
|
|
9
|
+
main: string;
|
|
10
|
+
handler?: string;
|
|
11
|
+
memory?: number;
|
|
12
|
+
runtime?: "nodejs20.x" | "nodejs22.x";
|
|
13
|
+
architecture?: "x86_64" | "arm64";
|
|
14
|
+
url?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare namespace FunctionProps {
|
|
17
|
+
export type Simplified<Req> = FunctionProps<
|
|
18
|
+
Capability.Simplify<Extract<Req, Capability>>
|
|
19
|
+
>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type FunctionAttr<Props extends FunctionProps = FunctionProps> = {
|
|
23
|
+
functionArn: string;
|
|
24
|
+
functionName: string;
|
|
25
|
+
functionUrl: Props["url"] extends true ? string : undefined;
|
|
26
|
+
roleName: string;
|
|
27
|
+
roleArn: string;
|
|
28
|
+
code: {
|
|
29
|
+
hash: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export interface FunctionBinding {
|
|
34
|
+
env?: {
|
|
35
|
+
[key: string]: string;
|
|
36
|
+
};
|
|
37
|
+
policyStatements?: IAM.PolicyStatement[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface Function extends Runtime<"AWS.Lambda.Function"> {
|
|
41
|
+
props: FunctionProps;
|
|
42
|
+
attr: FunctionAttr<Extract<this["props"], FunctionProps>>;
|
|
43
|
+
binding: FunctionBinding;
|
|
44
|
+
}
|
|
45
|
+
export const Function = Runtime("AWS.Lambda.Function")<Function>();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./client.ts";
|
|
2
|
+
export * from "./function.handler.ts";
|
|
3
|
+
export * from "./function.invoke.ts";
|
|
4
|
+
export * from "./function.provider.ts";
|
|
5
|
+
export * from "./function.ts";
|
|
6
|
+
export * from "./serve.ts";
|
|
7
|
+
export * from "./consume.ts";
|
|
8
|
+
|
|
9
|
+
// export type * as lambda from "aws-lambda";
|