The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type * as s3files from "@distilled.cloud/aws/s3files"; |
| 2 | import * as Data from "effect/Data"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as Schedule from "effect/Schedule"; |
| 5 | |
| 6 | /** |
| 7 | * Raised when an S3 Files file system or access point fails to settle into |
| 8 | * `available` within the bounded polling budget, or when the API returns a |
| 9 | * structurally incomplete description. |
| 10 | */ |
| 11 | export class S3FilesNotConverged extends Data.TaggedError("S3FilesNotConverged")<{ |
| 12 | readonly resource: string; |
| 13 | readonly status: string | undefined; |
| 14 | }> {} |
| 15 | |
| 16 | /** |
| 17 | * Bounded retry through transient `ConflictException` states — e.g. deleting |
| 18 | * a file system or access point whose previous lifecycle transition is still |
| 19 | * settling. |
| 20 | * |
| 21 | * Expressed as an explicitly-typed module-scope helper: inlining |
| 22 | * `Effect.retry` in lifecycle code leaves its conditional return type |
| 23 | * unresolved in the provider's declaration emit, which widens the |
| 24 | * `AWS.providers()` layer type for every downstream consumer. |
| 25 | */ |
| 26 | export const retryWhileConflict = <A, E extends { readonly _tag: string }, R>( |
| 27 | self: Effect.Effect<A, E, R>, |
| 28 | ): Effect.Effect<A, E, R> => |
| 29 | Effect.retry(self, { |
| 30 | while: (e) => e._tag === "ConflictException", |
| 31 | schedule: Schedule.max([Schedule.fixed("3 seconds"), Schedule.recurs(10)]), |
| 32 | }); |
| 33 | |
| 34 | /** |
| 35 | * Repeat an observe poll until `done` holds (bounded — file systems and |
| 36 | * access points typically become `available` within seconds). Explicitly |
| 37 | * typed for the declaration-emit reason above. |
| 38 | */ |
| 39 | export const untilSettled = <A, E, R>( |
| 40 | self: Effect.Effect<A, E, R>, |
| 41 | done: (a: A) => boolean, |
| 42 | ): Effect.Effect<A, E, R> => |
| 43 | Effect.repeat(self, { |
| 44 | schedule: Schedule.spaced("3 seconds"), |
| 45 | until: done, |
| 46 | times: 30, |
| 47 | }); |
| 48 | |
| 49 | /** |
| 50 | * Convert the wire tag list (`[{ key, value }]`) into a plain record for |
| 51 | * diffing with `diffTags`. |
| 52 | */ |
| 53 | export const toTagRecord = (tags: readonly s3files.Tag[] | undefined): Record<string, string> => { |
| 54 | const out: Record<string, string> = {}; |
| 55 | for (const tag of tags ?? []) { |
| 56 | out[tag.key] = tag.value; |
| 57 | } |
| 58 | return out; |
| 59 | }; |
| 60 | |
| 61 | /** |
| 62 | * Convert a plain tag record into the wire tag list shape. |
| 63 | */ |
| 64 | export const toTagList = (tags: Record<string, string>): s3files.Tag[] => |
| 65 | Object.entries(tags).map(([key, value]) => ({ key, value })); |