alchemy-effect 0.1.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/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 +4 -3
- package/lib/aws/account.d.ts.map +1 -1
- package/lib/aws/account.js +2 -2
- package/lib/aws/account.js.map +1 -1
- package/lib/aws/arn.d.ts +1 -5
- package/lib/aws/arn.d.ts.map +1 -1
- package/lib/aws/client.d.ts.map +1 -1
- package/lib/aws/client.js +9 -1
- package/lib/aws/client.js.map +1 -1
- package/lib/aws/credentials.d.ts +1 -1
- package/lib/aws/credentials.d.ts.map +1 -1
- package/lib/aws/credentials.js.map +1 -1
- 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/{sqs/queue.client.js → dynamodb/client.js} +6 -6
- 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/index.d.ts +24 -14
- package/lib/aws/index.d.ts.map +1 -1
- package/lib/aws/index.js +7 -12
- package/lib/aws/index.js.map +1 -1
- 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 +3 -3
- package/lib/aws/lambda/consume.d.ts.map +1 -1
- package/lib/aws/lambda/consume.js.map +1 -1
- package/lib/aws/lambda/function.d.ts +13 -10
- package/lib/aws/lambda/function.d.ts.map +1 -1
- package/lib/aws/lambda/function.invoke.d.ts +2 -2
- package/lib/aws/lambda/function.invoke.d.ts.map +1 -1
- package/lib/aws/lambda/function.invoke.js +2 -2
- package/lib/aws/lambda/function.invoke.js.map +1 -1
- package/lib/aws/lambda/function.js +1 -1
- package/lib/aws/lambda/function.js.map +1 -1
- package/lib/aws/lambda/function.provider.d.ts +3 -3
- package/lib/aws/lambda/function.provider.d.ts.map +1 -1
- package/lib/aws/lambda/function.provider.js +145 -55
- package/lib/aws/lambda/function.provider.js.map +1 -1
- package/lib/aws/lambda/index.d.ts +1 -2
- package/lib/aws/lambda/index.d.ts.map +1 -1
- package/lib/aws/lambda/index.js +1 -1
- package/lib/aws/lambda/index.js.map +1 -1
- package/lib/aws/lambda/serve.d.ts +1 -1
- package/lib/aws/lambda/serve.d.ts.map +1 -1
- package/lib/aws/lambda/serve.js.map +1 -1
- package/lib/aws/region.d.ts +1 -0
- package/lib/aws/region.d.ts.map +1 -1
- package/lib/aws/region.js.map +1 -1
- 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 +2 -1
- package/lib/aws/sqs/index.d.ts.map +1 -1
- package/lib/aws/sqs/index.js +2 -1
- package/lib/aws/sqs/index.js.map +1 -1
- package/lib/aws/sqs/queue.consume.d.ts +1 -10
- package/lib/aws/sqs/queue.consume.d.ts.map +1 -1
- package/lib/aws/sqs/queue.consume.js +1 -19
- package/lib/aws/sqs/queue.consume.js.map +1 -1
- package/lib/aws/sqs/queue.d.ts +2 -10
- package/lib/aws/sqs/queue.d.ts.map +1 -1
- 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.provider.d.ts +4 -3
- package/lib/aws/sqs/queue.provider.d.ts.map +1 -1
- package/lib/aws/sqs/queue.provider.js +4 -4
- package/lib/aws/sqs/queue.provider.js.map +1 -1
- package/lib/aws/sqs/queue.send-message.d.ts +2 -2
- package/lib/aws/sqs/queue.send-message.d.ts.map +1 -1
- package/lib/aws/sqs/queue.send-message.js +2 -2
- package/lib/aws/sqs/queue.send-message.js.map +1 -1
- 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/components/Plan.d.ts.map +1 -1
- package/lib/cli/components/Plan.js +3 -1
- package/lib/cli/components/Plan.js.map +1 -1
- package/lib/cli/index.d.ts +204 -116
- package/lib/cli/index.d.ts.map +1 -1
- package/lib/cli/index.js +25707 -11055
- package/lib/cli/index.js.map +1 -1
- package/lib/cli/progress.d.ts.map +1 -1
- package/lib/cli/progress.js +1 -0
- package/lib/cli/progress.js.map +1 -1
- package/lib/cloudflare/api.d.ts +29 -17
- package/lib/cloudflare/api.d.ts.map +1 -1
- package/lib/cloudflare/api.js +92 -27
- package/lib/cloudflare/api.js.map +1 -1
- 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 +5 -4
- package/lib/cloudflare/index.d.ts.map +1 -1
- package/lib/cloudflare/index.js +4 -4
- package/lib/cloudflare/index.js.map +1 -1
- 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 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -3
- 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 +48 -3
- package/src/app.ts +8 -7
- package/src/apply.ts +251 -93
- package/src/aws/account.ts +6 -4
- package/src/aws/arn.ts +1 -7
- package/src/aws/client.ts +15 -1
- package/src/aws/credentials.ts +1 -0
- package/src/aws/dynamodb/attribute-value.ts +240 -0
- package/src/aws/{sqs/queue.client.ts → dynamodb/client.ts} +9 -9
- 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/index.ts +15 -16
- package/src/aws/lambda/client.ts +14 -0
- package/src/aws/lambda/consume.ts +0 -1
- package/src/aws/lambda/function.invoke.ts +2 -2
- package/src/aws/lambda/function.provider.ts +197 -105
- package/src/aws/lambda/function.ts +16 -10
- package/src/aws/lambda/index.ts +1 -4
- package/src/aws/lambda/serve.ts +1 -1
- package/src/aws/region.ts +3 -1
- package/src/aws/sqs/client.ts +20 -0
- package/src/aws/sqs/index.ts +2 -1
- package/src/aws/sqs/queue.consume.ts +1 -34
- package/src/aws/sqs/queue.event-source.ts +253 -0
- package/src/aws/sqs/queue.provider.ts +4 -4
- package/src/aws/sqs/queue.send-message.ts +2 -2
- package/src/binding.ts +121 -25
- package/src/capability.ts +44 -0
- package/src/cli/components/Plan.tsx +4 -2
- package/src/cli/progress.tsx +1 -0
- package/src/cloudflare/api.ts +141 -61
- package/src/cloudflare/context.ts +49 -0
- package/src/cloudflare/index.ts +6 -4
- 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 -4
- 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
- package/lib/aws/lambda/function.client.d.ts +0 -8
- package/lib/aws/lambda/function.client.d.ts.map +0 -1
- package/lib/aws/lambda/function.client.js +0 -7
- package/lib/aws/lambda/function.client.js.map +0 -1
- package/lib/aws/sqs/queue.client.d.ts +0 -12
- package/lib/aws/sqs/queue.client.d.ts.map +0 -1
- package/lib/aws/sqs/queue.client.js.map +0 -1
- package/lib/cloudflare/kv.d.ts +0 -29
- package/lib/cloudflare/kv.d.ts.map +0 -1
- package/lib/cloudflare/kv.js +0 -3
- package/lib/cloudflare/kv.js.map +0 -1
- package/lib/cloudflare/kv.provider.d.ts +0 -4
- package/lib/cloudflare/kv.provider.d.ts.map +0 -1
- package/lib/cloudflare/kv.provider.js +0 -39
- package/lib/cloudflare/kv.provider.js.map +0 -1
- package/lib/cloudflare/worker.d.ts +0 -33
- package/lib/cloudflare/worker.d.ts.map +0 -1
- package/lib/cloudflare/worker.js +0 -4
- package/lib/cloudflare/worker.js.map +0 -1
- package/src/aws/lambda/function.client.ts +0 -14
- package/src/cloudflare/kv.provider.ts +0 -51
- package/src/cloudflare/kv.ts +0 -20
- package/src/cloudflare/worker.ts +0 -34
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type * as runtime from "@cloudflare/workers-types";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import { replaceEffectStream } from "../stream.ts";
|
|
4
|
+
import { getR2BucketFromEnv, type UploadValue } from "./bucket.client.ts";
|
|
5
|
+
import type { Bucket } from "./bucket.ts";
|
|
6
|
+
|
|
7
|
+
export const createMultipartUpload = Effect.fnUntraced(function* <
|
|
8
|
+
R2Bucket extends Bucket,
|
|
9
|
+
>(bucket: R2Bucket, key: string, options?: runtime.R2MultipartOptions) {
|
|
10
|
+
const client = yield* getR2BucketFromEnv(bucket);
|
|
11
|
+
return yield* Effect.promise(async () =>
|
|
12
|
+
makeMultipartUploadEffectClient(
|
|
13
|
+
await client.createMultipartUpload(key, options),
|
|
14
|
+
),
|
|
15
|
+
);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export const resumeMultipartUpload = Effect.fnUntraced(function* <
|
|
19
|
+
R2Bucket extends Bucket,
|
|
20
|
+
>(bucket: R2Bucket, key: string, uploadId: string) {
|
|
21
|
+
const client = yield* getR2BucketFromEnv(bucket);
|
|
22
|
+
return yield* Effect.sync(() =>
|
|
23
|
+
makeMultipartUploadEffectClient(
|
|
24
|
+
client.resumeMultipartUpload(key, uploadId),
|
|
25
|
+
),
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const makeMultipartUploadEffectClient = (
|
|
30
|
+
multipartUpload: runtime.R2MultipartUpload,
|
|
31
|
+
) => ({
|
|
32
|
+
key: multipartUpload.key,
|
|
33
|
+
uploadId: multipartUpload.uploadId,
|
|
34
|
+
uploadPart: Effect.fnUntraced(function* (
|
|
35
|
+
partNumber: number,
|
|
36
|
+
value: UploadValue,
|
|
37
|
+
options?: runtime.R2UploadPartOptions,
|
|
38
|
+
) {
|
|
39
|
+
return yield* Effect.promise(() =>
|
|
40
|
+
multipartUpload.uploadPart(
|
|
41
|
+
partNumber,
|
|
42
|
+
replaceEffectStream(value),
|
|
43
|
+
options,
|
|
44
|
+
),
|
|
45
|
+
);
|
|
46
|
+
}),
|
|
47
|
+
abort: Effect.fnUntraced(function* () {
|
|
48
|
+
return yield* Effect.promise(() => multipartUpload.abort());
|
|
49
|
+
}),
|
|
50
|
+
complete: Effect.fnUntraced(function* (
|
|
51
|
+
uploadedParts: runtime.R2UploadedPart[],
|
|
52
|
+
) {
|
|
53
|
+
return yield* Effect.promise(() => multipartUpload.complete(uploadedParts));
|
|
54
|
+
}),
|
|
55
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { R2 } from "cloudflare/resources";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import { App } from "../../app";
|
|
4
|
+
import { CloudflareAccountId, CloudflareApi } from "../api";
|
|
5
|
+
import { Bucket, type BucketAttr, type BucketProps } from "./bucket";
|
|
6
|
+
|
|
7
|
+
export const bucketProvider = () =>
|
|
8
|
+
Bucket.provider.effect(
|
|
9
|
+
Effect.gen(function* () {
|
|
10
|
+
const api = yield* CloudflareApi;
|
|
11
|
+
const accountId = yield* CloudflareAccountId;
|
|
12
|
+
const app = yield* App;
|
|
13
|
+
|
|
14
|
+
const createName = (id: string, props: BucketProps) =>
|
|
15
|
+
props.name ?? `${app.name}-${id}-${app.stage}`.toLowerCase();
|
|
16
|
+
|
|
17
|
+
const mapResult = <Props extends BucketProps>(
|
|
18
|
+
bucket: R2.Bucket,
|
|
19
|
+
): BucketAttr<Props> =>
|
|
20
|
+
({
|
|
21
|
+
name: bucket.name,
|
|
22
|
+
storageClass: bucket.storage_class ?? "Standard",
|
|
23
|
+
jurisdiction: bucket.jurisdiction ?? "default",
|
|
24
|
+
location: bucket.location,
|
|
25
|
+
accountId,
|
|
26
|
+
}) as BucketAttr<Props>;
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
diff: ({ id, olds, news, output }) =>
|
|
30
|
+
Effect.sync(() => {
|
|
31
|
+
if (
|
|
32
|
+
output.accountId !== accountId ||
|
|
33
|
+
output.name !== createName(id, news) ||
|
|
34
|
+
output.jurisdiction !== (news.jurisdiction ?? "default") ||
|
|
35
|
+
olds.locationHint !== news.locationHint
|
|
36
|
+
) {
|
|
37
|
+
return { action: "replace" };
|
|
38
|
+
}
|
|
39
|
+
if (output.storageClass !== (news.storageClass ?? "Standard")) {
|
|
40
|
+
return { action: "update" };
|
|
41
|
+
}
|
|
42
|
+
return { action: "noop" };
|
|
43
|
+
}),
|
|
44
|
+
create: Effect.fnUntraced(function* ({ id, news }) {
|
|
45
|
+
const bucket = yield* api.r2.buckets.create({
|
|
46
|
+
account_id: accountId,
|
|
47
|
+
name: createName(id, news),
|
|
48
|
+
storageClass: news.storageClass,
|
|
49
|
+
jurisdiction: news.jurisdiction,
|
|
50
|
+
locationHint: news.locationHint,
|
|
51
|
+
});
|
|
52
|
+
return mapResult<BucketProps>(bucket);
|
|
53
|
+
}),
|
|
54
|
+
update: Effect.fnUntraced(function* ({ id, news, output }) {
|
|
55
|
+
const bucket = yield* api.r2.buckets.edit(output.name, {
|
|
56
|
+
account_id: output.accountId,
|
|
57
|
+
storage_class: news.storageClass ?? output.storageClass,
|
|
58
|
+
jurisdiction: output.jurisdiction,
|
|
59
|
+
});
|
|
60
|
+
return mapResult<BucketProps>(bucket);
|
|
61
|
+
}),
|
|
62
|
+
delete: Effect.fnUntraced(function* ({ output }) {
|
|
63
|
+
yield* api.r2.buckets
|
|
64
|
+
.delete(output.name, {
|
|
65
|
+
account_id: output.accountId,
|
|
66
|
+
})
|
|
67
|
+
.pipe(Effect.catchTag("NotFound", () => Effect.void));
|
|
68
|
+
}),
|
|
69
|
+
read: Effect.fnUntraced(function* ({ id, output, olds }) {
|
|
70
|
+
const params = {
|
|
71
|
+
account_id: output?.accountId ?? accountId,
|
|
72
|
+
name: output?.name ?? createName(id, olds ?? {}),
|
|
73
|
+
};
|
|
74
|
+
return yield* api.r2.buckets
|
|
75
|
+
.get(params.name, { account_id: params.account_id })
|
|
76
|
+
.pipe(
|
|
77
|
+
Effect.map(mapResult<BucketProps>),
|
|
78
|
+
Effect.catchTag("NotFound", () => Effect.succeed(undefined)),
|
|
79
|
+
);
|
|
80
|
+
}),
|
|
81
|
+
};
|
|
82
|
+
}),
|
|
83
|
+
);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type * as runtime from "@cloudflare/workers-types";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import { replaceEffectStream } from "../stream.ts";
|
|
4
|
+
import { getR2BucketFromEnv, type UploadValue } from "./bucket.client.ts";
|
|
5
|
+
import type { Bucket } from "./bucket.ts";
|
|
6
|
+
|
|
7
|
+
export const put = Effect.fnUntraced(function* <B extends Bucket>(
|
|
8
|
+
bucket: B,
|
|
9
|
+
key: string,
|
|
10
|
+
value: UploadValue,
|
|
11
|
+
options?: runtime.R2PutOptions,
|
|
12
|
+
) {
|
|
13
|
+
const client = yield* getR2BucketFromEnv(bucket);
|
|
14
|
+
return yield* Effect.promise(() =>
|
|
15
|
+
client.put(key, replaceEffectStream(value), options),
|
|
16
|
+
);
|
|
17
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Resource } from "../../resource.ts";
|
|
2
|
+
|
|
3
|
+
export type BucketProps = {
|
|
4
|
+
name?: string;
|
|
5
|
+
storageClass?: Bucket.StorageClass;
|
|
6
|
+
jurisdiction?: Bucket.Jurisdiction;
|
|
7
|
+
locationHint?: Bucket.Location;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type BucketAttr<Props extends BucketProps> = {
|
|
11
|
+
name: Props["name"] extends string ? Props["name"] : string;
|
|
12
|
+
storageClass: Props["storageClass"] extends Bucket.StorageClass
|
|
13
|
+
? Props["storageClass"]
|
|
14
|
+
: "Standard";
|
|
15
|
+
jurisdiction: Props["jurisdiction"] extends Bucket.Jurisdiction
|
|
16
|
+
? Props["jurisdiction"]
|
|
17
|
+
: "default";
|
|
18
|
+
location: Bucket.Location | undefined;
|
|
19
|
+
accountId: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export interface Bucket<
|
|
23
|
+
ID extends string = string,
|
|
24
|
+
Props extends BucketProps = BucketProps,
|
|
25
|
+
> extends Resource<"Cloudflare.R2.Bucket", ID, Props, BucketAttr<Props>> {}
|
|
26
|
+
|
|
27
|
+
export const Bucket = Resource<{
|
|
28
|
+
<const ID extends string, const Props extends BucketProps>(
|
|
29
|
+
id: ID,
|
|
30
|
+
props: Props,
|
|
31
|
+
): Bucket<ID, Props>;
|
|
32
|
+
}>("Cloudflare.R2.Bucket");
|
|
33
|
+
|
|
34
|
+
export declare namespace Bucket {
|
|
35
|
+
export type StorageClass = "Standard" | "InfrequentAccess";
|
|
36
|
+
export type Jurisdiction = "default" | "eu" | "fedramp";
|
|
37
|
+
export type Location = "apac" | "eeur" | "enam" | "weur" | "wnam" | "oc";
|
|
38
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./bucket.binding.ts";
|
|
2
|
+
export * from "./bucket.client.ts";
|
|
3
|
+
export * from "./bucket.del.ts";
|
|
4
|
+
export * from "./bucket.get.ts";
|
|
5
|
+
export * from "./bucket.head.ts";
|
|
6
|
+
export * from "./bucket.list.ts";
|
|
7
|
+
export * from "./bucket.multipart.ts";
|
|
8
|
+
export * from "./bucket.put.ts";
|
|
9
|
+
export * from "./bucket.ts";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type * as runtime from "@cloudflare/workers-types";
|
|
2
|
+
import * as Predicate from "effect/Predicate";
|
|
3
|
+
import * as Stream from "effect/Stream";
|
|
4
|
+
|
|
5
|
+
type ReplaceEffectStream<T> =
|
|
6
|
+
T extends Stream.Stream<any> ? runtime.ReadableStream<any> : T;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* If the value is an Effect stream, converts it to a ReadableStream.
|
|
10
|
+
* Otherwise, returns the value unchanged.
|
|
11
|
+
*/
|
|
12
|
+
export function replaceEffectStream<T>(value: T): ReplaceEffectStream<T> {
|
|
13
|
+
if (isEffectStream(value)) {
|
|
14
|
+
return Stream.toReadableStream(value) as ReplaceEffectStream<T>;
|
|
15
|
+
}
|
|
16
|
+
return value as ReplaceEffectStream<T>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function isEffectStream(value: unknown): value is Stream.Stream<any> {
|
|
20
|
+
return Predicate.hasProperty(value, Stream.StreamTypeId);
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type * as runtime from "@cloudflare/workers-types";
|
|
2
|
+
import { Binding, declare, type Capability } from "alchemy-effect";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import { getCloudflareEnvKey } from "../context.ts";
|
|
5
|
+
import { Worker } from "./worker.ts";
|
|
6
|
+
|
|
7
|
+
export interface Fetch extends Capability<"Cloudflare.Assets.Fetch"> {}
|
|
8
|
+
|
|
9
|
+
export const Fetch = Binding<() => Binding<Worker, Fetch>>(
|
|
10
|
+
Worker,
|
|
11
|
+
"Cloudflare.Assets.Fetch",
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export const fetch = Effect.fnUntraced(function* (
|
|
15
|
+
input: RequestInfo | URL,
|
|
16
|
+
init?: RequestInit,
|
|
17
|
+
) {
|
|
18
|
+
yield* declare<Fetch>();
|
|
19
|
+
const fetcher = yield* getCloudflareEnvKey<runtime.Fetcher>("ASSETS");
|
|
20
|
+
return yield* Effect.promise(
|
|
21
|
+
(): Promise<Response> =>
|
|
22
|
+
fetcher.fetch(
|
|
23
|
+
input as URL | runtime.RequestInfo,
|
|
24
|
+
init as runtime.RequestInit<runtime.CfProperties<unknown>>,
|
|
25
|
+
) as any,
|
|
26
|
+
);
|
|
27
|
+
});
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { FileSystem, Path } from "@effect/platform";
|
|
2
|
+
import type { PlatformError } from "@effect/platform/Error";
|
|
3
|
+
import { Context, Data, Layer } from "effect";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import type { ScopedPlanStatusSession } from "../../apply.ts";
|
|
6
|
+
import { sha256 } from "../../sha256.ts";
|
|
7
|
+
import { CloudflareApi, CloudflareApiError } from "../api.ts";
|
|
8
|
+
import type { Worker } from "./worker.ts";
|
|
9
|
+
|
|
10
|
+
const MAX_ASSET_SIZE = 1024 * 1024 * 25; // 25MB
|
|
11
|
+
const MAX_ASSET_COUNT = 20_000;
|
|
12
|
+
|
|
13
|
+
export declare namespace Assets {
|
|
14
|
+
export interface ReadResult {
|
|
15
|
+
directory: string;
|
|
16
|
+
config: Worker.AssetsConfig | undefined;
|
|
17
|
+
manifest: Record<string, { hash: string; size: number }>;
|
|
18
|
+
_headers: string | undefined;
|
|
19
|
+
_redirects: string | undefined;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class Assets extends Context.Tag("Assets")<
|
|
24
|
+
Assets,
|
|
25
|
+
{
|
|
26
|
+
read(
|
|
27
|
+
directory: Worker.AssetsProps,
|
|
28
|
+
): Effect.Effect<Assets.ReadResult, PlatformError | ValidationError>;
|
|
29
|
+
upload(
|
|
30
|
+
accountId: string,
|
|
31
|
+
workerName: string,
|
|
32
|
+
assets: Assets.ReadResult,
|
|
33
|
+
session: ScopedPlanStatusSession,
|
|
34
|
+
): Effect.Effect<
|
|
35
|
+
{ jwt: string | undefined },
|
|
36
|
+
PlatformError | ValidationError | CloudflareApiError
|
|
37
|
+
>;
|
|
38
|
+
}
|
|
39
|
+
>() {}
|
|
40
|
+
|
|
41
|
+
export class AssetTooLargeError extends Data.TaggedError("AssetTooLargeError")<{
|
|
42
|
+
message: string;
|
|
43
|
+
name: string;
|
|
44
|
+
size: number;
|
|
45
|
+
}> {}
|
|
46
|
+
|
|
47
|
+
export class TooManyAssetsError extends Data.TaggedError("TooManyAssetsError")<{
|
|
48
|
+
message: string;
|
|
49
|
+
directory: string;
|
|
50
|
+
count: number;
|
|
51
|
+
}> {}
|
|
52
|
+
|
|
53
|
+
export class AssetNotFoundError extends Data.TaggedError("AssetNotFoundError")<{
|
|
54
|
+
message: string;
|
|
55
|
+
hash: string;
|
|
56
|
+
}> {}
|
|
57
|
+
|
|
58
|
+
export class FailedToReadAssetError extends Data.TaggedError(
|
|
59
|
+
"FailedToReadAssetError",
|
|
60
|
+
)<{
|
|
61
|
+
message: string;
|
|
62
|
+
name: string;
|
|
63
|
+
cause: PlatformError;
|
|
64
|
+
}> {}
|
|
65
|
+
|
|
66
|
+
export type ValidationError =
|
|
67
|
+
| AssetTooLargeError
|
|
68
|
+
| TooManyAssetsError
|
|
69
|
+
| AssetNotFoundError
|
|
70
|
+
| FailedToReadAssetError;
|
|
71
|
+
|
|
72
|
+
export const assetsProvider = () =>
|
|
73
|
+
Layer.effect(
|
|
74
|
+
Assets,
|
|
75
|
+
Effect.gen(function* () {
|
|
76
|
+
const fs = yield* FileSystem.FileSystem;
|
|
77
|
+
const path = yield* Path.Path;
|
|
78
|
+
const api = yield* CloudflareApi;
|
|
79
|
+
|
|
80
|
+
const maybeReadString = Effect.fnUntraced(function* (file: string) {
|
|
81
|
+
return yield* fs.readFileString(file).pipe(
|
|
82
|
+
Effect.catchIf(
|
|
83
|
+
(error) =>
|
|
84
|
+
error._tag === "SystemError" && error.reason === "NotFound",
|
|
85
|
+
() => Effect.succeed(undefined),
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const createIgnoreMatcher = Effect.fnUntraced(function* (
|
|
91
|
+
patterns: string[],
|
|
92
|
+
) {
|
|
93
|
+
const matcher = yield* Effect.promise(() =>
|
|
94
|
+
import("ignore").then(({ default: ignore }) =>
|
|
95
|
+
ignore().add(patterns),
|
|
96
|
+
),
|
|
97
|
+
);
|
|
98
|
+
return (file: string) => matcher.ignores(file);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
read: Effect.fnUntraced(function* (props: Worker.AssetsProps) {
|
|
103
|
+
const resolvedDirectory = path.resolve(props.directory);
|
|
104
|
+
const [files, ignore, _headers, _redirects] = yield* Effect.all([
|
|
105
|
+
fs.readDirectory(resolvedDirectory, { recursive: true }),
|
|
106
|
+
maybeReadString(path.join(resolvedDirectory, ".assetsignore")),
|
|
107
|
+
maybeReadString(path.join(resolvedDirectory, "_headers")),
|
|
108
|
+
maybeReadString(path.join(resolvedDirectory, "_redirects")),
|
|
109
|
+
]);
|
|
110
|
+
const ignores = yield* createIgnoreMatcher([
|
|
111
|
+
".assetsignore",
|
|
112
|
+
"_headers",
|
|
113
|
+
"_redirects",
|
|
114
|
+
...(ignore
|
|
115
|
+
?.split("\n")
|
|
116
|
+
.map((line) => line.trim())
|
|
117
|
+
.filter((line) => line.length > 0 && !line.startsWith("#")) ??
|
|
118
|
+
[]),
|
|
119
|
+
]);
|
|
120
|
+
const manifest = new Map<string, { hash: string; size: number }>();
|
|
121
|
+
let count = 0;
|
|
122
|
+
yield* Effect.forEach(
|
|
123
|
+
files,
|
|
124
|
+
Effect.fnUntraced(function* (name) {
|
|
125
|
+
if (ignores(name)) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const file = path.join(resolvedDirectory, name);
|
|
129
|
+
const stat = yield* fs.stat(file);
|
|
130
|
+
if (stat.type !== "File") {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const size = Number(stat.size);
|
|
134
|
+
if (size > MAX_ASSET_SIZE) {
|
|
135
|
+
return yield* new AssetTooLargeError({
|
|
136
|
+
message: `Asset ${name} is too large (the maximum size is ${MAX_ASSET_SIZE / 1024 / 1024} MB; this asset is ${size / 1024 / 1024} MB)`,
|
|
137
|
+
name,
|
|
138
|
+
size,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
const hash = yield* fs.readFile(file).pipe(
|
|
142
|
+
Effect.flatMap(sha256),
|
|
143
|
+
Effect.map((hash) => hash.slice(0, 32)),
|
|
144
|
+
);
|
|
145
|
+
count++;
|
|
146
|
+
if (count > MAX_ASSET_COUNT) {
|
|
147
|
+
return yield* new TooManyAssetsError({
|
|
148
|
+
message: `Too many assets (the maximum count is ${MAX_ASSET_COUNT}; this directory has ${count} assets)`,
|
|
149
|
+
directory: props.directory,
|
|
150
|
+
count,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
manifest.set(name.startsWith("/") ? name : `/${name}`, {
|
|
154
|
+
hash,
|
|
155
|
+
size,
|
|
156
|
+
});
|
|
157
|
+
}),
|
|
158
|
+
);
|
|
159
|
+
return {
|
|
160
|
+
directory: props.directory,
|
|
161
|
+
config: props.config,
|
|
162
|
+
manifest: Object.fromEntries(
|
|
163
|
+
Array.from(manifest.entries()).sort((a, b) =>
|
|
164
|
+
a[0].localeCompare(b[0]),
|
|
165
|
+
),
|
|
166
|
+
),
|
|
167
|
+
_headers,
|
|
168
|
+
_redirects,
|
|
169
|
+
};
|
|
170
|
+
}),
|
|
171
|
+
upload: Effect.fnUntraced(function* (
|
|
172
|
+
accountId: string,
|
|
173
|
+
workerName: string,
|
|
174
|
+
assets: Assets.ReadResult,
|
|
175
|
+
{ note }: ScopedPlanStatusSession,
|
|
176
|
+
) {
|
|
177
|
+
yield* note("Checking assets...");
|
|
178
|
+
const session = yield* api.workers.scripts.assets.upload.create(
|
|
179
|
+
workerName,
|
|
180
|
+
{
|
|
181
|
+
account_id: accountId,
|
|
182
|
+
manifest: assets.manifest,
|
|
183
|
+
},
|
|
184
|
+
);
|
|
185
|
+
if (!session.buckets?.length) {
|
|
186
|
+
return { jwt: session.jwt };
|
|
187
|
+
}
|
|
188
|
+
let uploaded = 0;
|
|
189
|
+
const total = session.buckets.flat().length;
|
|
190
|
+
yield* note(`Uploaded ${uploaded} of ${total} assets...`);
|
|
191
|
+
const assetsByHash = new Map<string, string>();
|
|
192
|
+
for (const [name, { hash }] of Object.entries(assets.manifest)) {
|
|
193
|
+
assetsByHash.set(hash, name);
|
|
194
|
+
}
|
|
195
|
+
let jwt: string | undefined;
|
|
196
|
+
const directory = path.resolve(assets.directory);
|
|
197
|
+
yield* Effect.forEach(
|
|
198
|
+
session.buckets,
|
|
199
|
+
Effect.fnUntraced(function* (bucket) {
|
|
200
|
+
const body: Record<string, string> = {};
|
|
201
|
+
yield* Effect.forEach(
|
|
202
|
+
bucket,
|
|
203
|
+
Effect.fnUntraced(function* (hash) {
|
|
204
|
+
const name = assetsByHash.get(hash);
|
|
205
|
+
if (!name) {
|
|
206
|
+
return yield* new AssetNotFoundError({
|
|
207
|
+
message: `Asset ${hash} not found in manifest`,
|
|
208
|
+
hash,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
const file = yield* fs
|
|
212
|
+
.readFile(path.join(directory, name))
|
|
213
|
+
.pipe(
|
|
214
|
+
Effect.mapError(
|
|
215
|
+
(error) =>
|
|
216
|
+
new FailedToReadAssetError({
|
|
217
|
+
message: `Failed to read asset ${name}: ${error.message}`,
|
|
218
|
+
name,
|
|
219
|
+
cause: error,
|
|
220
|
+
}),
|
|
221
|
+
),
|
|
222
|
+
);
|
|
223
|
+
body[hash] = Buffer.from(file).toString("base64");
|
|
224
|
+
}),
|
|
225
|
+
);
|
|
226
|
+
const result = yield* api.workers.assets.upload.create(
|
|
227
|
+
{
|
|
228
|
+
account_id: accountId,
|
|
229
|
+
base64: true,
|
|
230
|
+
body,
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
headers: {
|
|
234
|
+
Authorization: `Bearer ${session.jwt}`,
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
);
|
|
238
|
+
uploaded += bucket.length;
|
|
239
|
+
yield* note(`Uploaded ${uploaded} of ${total} assets...`);
|
|
240
|
+
if (result.jwt) {
|
|
241
|
+
jwt = result.jwt;
|
|
242
|
+
}
|
|
243
|
+
}),
|
|
244
|
+
);
|
|
245
|
+
return { jwt };
|
|
246
|
+
}),
|
|
247
|
+
};
|
|
248
|
+
}),
|
|
249
|
+
);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type * as runtime from "@cloudflare/workers-types";
|
|
2
|
+
import type { Capability } from "alchemy-effect";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
import { CloudflareContext } from "../context.ts";
|
|
6
|
+
|
|
7
|
+
type Handler = (
|
|
8
|
+
request: Request,
|
|
9
|
+
env: unknown,
|
|
10
|
+
ctx: runtime.ExecutionContext,
|
|
11
|
+
) => Effect.Effect<Response, any, CloudflareContext>;
|
|
12
|
+
type HandlerFactory<H extends Handler, Req = Capability> = Effect.Effect<
|
|
13
|
+
H,
|
|
14
|
+
any,
|
|
15
|
+
Req
|
|
16
|
+
>;
|
|
17
|
+
|
|
18
|
+
export const toHandler = <H extends Handler>(
|
|
19
|
+
factory: HandlerFactory<H, Capability>,
|
|
20
|
+
) => {
|
|
21
|
+
return {
|
|
22
|
+
fetch: async (
|
|
23
|
+
request: Request,
|
|
24
|
+
env: unknown,
|
|
25
|
+
ctx: runtime.ExecutionContext,
|
|
26
|
+
) => {
|
|
27
|
+
const exit = await Effect.runPromiseExit(
|
|
28
|
+
(factory as HandlerFactory<H, never>).pipe(
|
|
29
|
+
Effect.flatMap((handler) => handler(request, env, ctx)),
|
|
30
|
+
Effect.provide(Layer.succeed(CloudflareContext, { env, ctx })),
|
|
31
|
+
),
|
|
32
|
+
);
|
|
33
|
+
if (exit._tag === "Success") {
|
|
34
|
+
return exit.value;
|
|
35
|
+
}
|
|
36
|
+
return Response.json(exit, { status: 500 });
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
};
|