@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, 06:00 UTC

main
ts 34 lines 1.17 KB
Raw
1 import * as elasticache from "@distilled.cloud/aws/elasticache";
2 import * as Effect from "effect/Effect";
3
4 export const toTagRecord = (
5 tags: Array<{ Key?: string; Value?: string }> | undefined,
6 ): Record<string, string> =>
7 Object.fromEntries(
8 (tags ?? [])
9 .filter(
10 (tag): tag is { Key: string; Value: string } =>
11 tag.Key !== undefined && tag.Value !== undefined,
12 )
13 .map((tag) => [tag.Key, tag.Value]),
14 );
15
16 /** Read tags after a resource has reached an observable state. */
17 export const readElastiCacheTags = Effect.fn(function* (arn: string) {
18 const response = yield* elasticache
19 .listTagsForResource({ ResourceName: arn })
20 .pipe(Effect.orElseSucceed(() => undefined));
21 return toTagRecord(response?.TagList);
22 });
23
24 export const sameStringSet = (
25 a: readonly string[] | undefined,
26 b: readonly string[] | undefined,
27 ): boolean => {
28 const left = [...new Set(a ?? [])].sort();
29 const right = [...new Set(b ?? [])].sort();
30 return left.length === right.length && left.every((value, i) => value === right[i]);
31 };
32
33 export const tagsToWire = (tags: Record<string, string>) =>
34 Object.entries(tags).map(([Key, Value]) => ({ Key, Value }));