@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, 04:45 UTC

main
ts 44 lines 1.92 KB
Raw
1 import type * as NFW from "@distilled.cloud/aws/network-firewall";
2 import * as Effect from "effect/Effect";
3 import * as Schedule from "effect/Schedule";
4
5 /** Convert a Network Firewall `Tag[]` list into a plain record. */
6 export const nfwTagsToRecord = (tags: readonly NFW.Tag[] | undefined): Record<string, string> =>
7 Object.fromEntries((tags ?? []).map((t) => [t.Key, t.Value]));
8
9 /** Convert a plain record into a Network Firewall `Tag[]` list. */
10 export const recordToNfwTags = (record: Record<string, string>): NFW.Tag[] =>
11 Object.entries(record).map(([Key, Value]) => ({ Key, Value }));
12
13 // Explicitly-typed pipeable retry helpers. Inlining `Effect.retry` in a
14 // provider lifecycle op leaks `Retry.Return`'s conditional into declaration
15 // emit and widens the provider layer to `unknown` R for every consumer of
16 // `AWS.providers()`.
17
18 /**
19 * Network Firewall rejects deletion of a rule group / firewall policy that is
20 * still referenced (or was referenced moments ago) with
21 * `InvalidOperationException`. Dependents are deleted first by the engine,
22 * but the service releases the reference asynchronously — retry through a
23 * short window.
24 */
25 export const retryWhileNfwInUse = <A, E extends { readonly _tag: string }, R>(
26 self: Effect.Effect<A, E, R>,
27 ): Effect.Effect<A, E, R> =>
28 Effect.retry(self, {
29 while: (e) => e._tag === "InvalidOperationException",
30 schedule: Schedule.max([Schedule.fixed("5 seconds"), Schedule.recurs(12)]),
31 });
32
33 /**
34 * A freshly-created rule group / policy can transiently return
35 * `ResourceNotFoundException` from a follow-up describe. Bounded retry
36 * through the eventual-consistency window.
37 */
38 export const retryWhileNfwNotFound = <A, E extends { readonly _tag: string }, R>(
39 self: Effect.Effect<A, E, R>,
40 ): Effect.Effect<A, E, R> =>
41 Effect.retry(self, {
42 while: (e) => e._tag === "ResourceNotFoundException",
43 schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(10)]),
44 });