@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
ts 48 lines 1.52 KB
Raw
1 import * as S3 from "@distilled.cloud/aws/s3";
2 import * as Binding from "alchemy/Binding";
3 import * as Effect from "effect/Effect";
4 import type { Bucket } from "./Bucket.ts";
5
6 export interface GetObjectRequest extends Omit<S3.GetObjectRequest, "Bucket"> {}
7
8 /**
9 * Runtime binding for `s3:GetObject`.
10 *
11 * Bind this operation to a bucket in the function's init phase to get a
12 * callable that reads objects — the bucket name is injected automatically and
13 * `s3:GetObject` is granted on the bucket. Provide the implementation with
14 * `Effect.provide(AWS.S3.GetObjectHttp)`.
15 * ### Reading Objects
16 * **Example:** Read an Object and Decode Its Body
17 * ```typescript
18 * // init — bind the operation to the bucket
19 * const getObject = yield* AWS.S3.GetObject(bucket);
20 *
21 * // runtime — the Body is a Stream; decode it to a string
22 * const text = yield* getObject({ Key: "jobs/job-123.json" }).pipe(
23 * Effect.flatMap((result) =>
24 * Stream.mkString(Stream.decodeText(result.Body!)),
25 * ),
26 * );
27 * ```
28 *
29 * **Example:** Treat a Missing Key as Absence
30 * ```typescript
31 * const job = yield* getObject({ Key: `jobs/${jobId}.json` }).pipe(
32 * Effect.catchTag("NoSuchKey", () => Effect.succeed(undefined)),
33 * );
34 * ```
35 *
36 * @binding
37 */
38 export interface GetObject extends Binding.Service<
39 GetObject,
40 "AWS.S3.GetObject",
41 (
42 bucket: Bucket,
43 ) => Effect.Effect<
44 (request: GetObjectRequest) => Effect.Effect<S3.GetObjectOutput, S3.GetObjectError>
45 >
46 > {}
47
48 export const GetObject = Binding.Service<GetObject>("AWS.S3.GetObject");