sailfork / t3code-github / .repos/ alchemy-effect/ packages/ prisma/ src/ internal/ HttpClient.ts

import * as NodeHttpClient from "@effect/platform-node/NodeHttpClient";
import * as EffectContext from "effect/Context";
import * as HttpClient from "effect/http/HttpClient";
import * as Layer from "effect/Layer";

/** Node transport preserves explicit Content-Length on file-backed uploads. */
export const PrismaHttpClientLive = NodeHttpClient.layerNodeHttp;

/**
 * The HTTP client Prisma artifact uploads run on. Kept as a Prisma-scoped
 * service — overriding the global `HttpClient.HttpClient` from
 * `Prisma.providers()` would hijack every other provider in the stack (e.g.
 * Cloudflare Worker script uploads break on node's chunked multipart
 * bodies). Live wiring provides the node transport here because the
 * S3-style presigned upload URLs require an explicit Content-Length, while
 * tests that stub the ambient `HttpClient` simply omit this service and the
 * upload falls back to the ambient client.
 */
export class PrismaUploadClient extends EffectContext.Service<
  PrismaUploadClient,
  HttpClient.HttpClient
>()("alchemy/Prisma/UploadClient") {}

export const PrismaUploadClientLive = Layer.effect(PrismaUploadClient, HttpClient.HttpClient).pipe(
  Layer.provide(PrismaHttpClientLive),
);