@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 43 lines 1.51 KB
Raw
1 import * as ds from "@distilled.cloud/aws/directory-service";
2 import * as Effect from "effect/Effect";
3 import * as Stream from "effect/Stream";
4
5 /**
6 * Convert Directory Service's `[{ Key, Value }]` tag list into a plain
7 * record, dropping any entry missing a key or value.
8 */
9 export const toTagRecord = (
10 tags: ReadonlyArray<{ Key?: string; Value?: string }> | undefined,
11 ): Record<string, string> =>
12 Object.fromEntries(
13 (tags ?? [])
14 .filter(
15 (tag): tag is { Key: string; Value: string } =>
16 typeof tag.Key === "string" && typeof tag.Value === "string",
17 )
18 .map((tag) => [tag.Key, tag.Value]),
19 );
20
21 /**
22 * Read the observed tags for a directory by id. A directory mid-transition
23 * (or already deleted out of band) can reject `listTagsForResource`; treat
24 * any failure as "no observed tags" so tag reconciliation still converges on
25 * the next pass.
26 */
27 export const readDirectoryTags = Effect.fn(function* (directoryId: string) {
28 const tags = yield* ds.listTagsForResource.items({ ResourceId: directoryId }).pipe(
29 Stream.runCollect,
30 Effect.orElseSucceed(() => [] as ds.Tag[]),
31 );
32 return toTagRecord(Array.from(tags));
33 });
34
35 /** True when two string sets are equal ignoring order and duplicates. */
36 export const sameStringSet = (
37 a: readonly string[] | undefined,
38 b: readonly string[] | undefined,
39 ): boolean => {
40 const left = [...new Set(a ?? [])].sort();
41 const right = [...new Set(b ?? [])].sort();
42 return left.length === right.length && left.every((v, i) => v === right[i]);
43 };