sailfork / t3code-github / .repos/ alchemy-effect/ packages/ fly/ src/ PutObject.ts

import type * as S3 from "@distilled.cloud/aws/s3";
import * as Binding from "alchemy/Binding";
import type { RuntimeContext } from "alchemy/RuntimeContext";
import type * as Effect from "effect/Effect";
import type { Bucket } from "./Bucket.ts";
import type { TigrisCredentialsMissing } from "./Errors.ts";

export interface PutObjectRequest extends Omit<S3.PutObjectRequest, "Bucket"> {}

/**
 * Runtime binding for Tigris `PutObject` over the S3 API.
 *
 * Bind this operation to a {@link Bucket} in Service init. The Tigris
 * bucket name, endpoint, and credentials are injected automatically.
 * Provide {@link PutObjectHttp}.
 *
 *
 * ### Writing Objects
 * **Example:** Put an Object
 * ```typescript
 * const putObject = yield* Fly.PutObject(Data);
 *
 * yield* putObject({
 *   Key: "hello.txt",
 *   Body: "Hello, world!",
 *   ContentType: "text/plain",
 * });
 * ```
 *
 * @binding
 * @product Bucket
 */
export interface PutObject extends Binding.Service<
  PutObject,
  "Fly.PutObject",
  (
    bucket: Bucket,
  ) => Effect.Effect<
    (
      request: PutObjectRequest,
    ) => Effect.Effect<
      S3.PutObjectOutput,
      S3.PutObjectError | TigrisCredentialsMissing,
      RuntimeContext
    >
  >
> {}

export const PutObject = Binding.Service<PutObject>("Fly.PutObject");