| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as Layer from "effect/Layer"; |
| 3 | import { ReadBucket, type ReadBucketClient } from "./ReadBucket.ts"; |
| 4 | import { makeStorageBinding, storageHttpLayer } from "./StorageBinding.ts"; |
| 5 | |
| 6 | export const makeReadBucketClient = ( |
| 7 | client: Effect.Success< |
| 8 | ReturnType<Effect.Success<ReturnType<typeof makeStorageBinding>>> |
| 9 | >, |
| 10 | ): ReadBucketClient => ({ |
| 11 | get: client.get, |
| 12 | head: client.head, |
| 13 | list: client.list, |
| 14 | presignGet: (key, options) => client.presign(key, "GET", options), |
| 15 | }); |
| 16 | |
| 17 | /** |
| 18 | * Use injected same-branch Neon credentials, otherwise manage a scoped credential. |
| 19 | * |
| 20 | * @layer |
| 21 | * @product Bucket |
| 22 | * @provides ReadBucket |
| 23 | */ |
| 24 | export const ReadBucketHttp = Layer.effect( |
| 25 | ReadBucket, |
| 26 | makeStorageBinding("storage:read").pipe( |
| 27 | Effect.map((bind) => |
| 28 | Effect.fn(function* (...args: Parameters<typeof bind>) { |
| 29 | return makeReadBucketClient(yield* bind(...args)); |
| 30 | }), |
| 31 | ), |
| 32 | ), |
| 33 | ).pipe(Layer.provide(storageHttpLayer)); |