| 1 | import * as NodeHttpClient from "@effect/platform-node/NodeHttpClient"; |
| 2 | import * as EffectContext from "effect/Context"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as Layer from "effect/Layer"; |
| 5 | import * as HttpClient from "effect/http/HttpClient"; |
| 6 | |
| 7 | /** Node transport preserves explicit Content-Length on file-backed uploads. */ |
| 8 | export const PrismaHttpClientLive = NodeHttpClient.layerNodeHttp; |
| 9 | |
| 10 | /** |
| 11 | * The HTTP client Prisma artifact uploads run on. Kept as a Prisma-scoped |
| 12 | * service — overriding the global `HttpClient.HttpClient` from |
| 13 | * `Prisma.providers()` would hijack every other provider in the stack (e.g. |
| 14 | * Cloudflare Worker script uploads break on node's chunked multipart |
| 15 | * bodies). Live wiring provides the node transport here because the |
| 16 | * S3-style presigned upload URLs require an explicit Content-Length, while |
| 17 | * tests that stub the ambient `HttpClient` simply omit this service and the |
| 18 | * upload falls back to the ambient client. |
| 19 | */ |
| 20 | export class PrismaUploadClient extends EffectContext.Service< |
| 21 | PrismaUploadClient, |
| 22 | HttpClient.HttpClient |
| 23 | >()("alchemy/Prisma/UploadClient") {} |
| 24 | |
| 25 | export const PrismaUploadClientLive = Layer.effect( |
| 26 | PrismaUploadClient, |
| 27 | Effect.gen(function* () { |
| 28 | return yield* HttpClient.HttpClient; |
| 29 | }), |
| 30 | ).pipe(Layer.provide(PrismaHttpClientLive)); |