@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.46 KB
Raw
1 import * as datazone from "@distilled.cloud/aws/datazone";
2 import { diffTags } from "alchemy/Tags";
3 import * as Effect from "effect/Effect";
4 import * as Redacted from "effect/Redacted";
5
6 /**
7 * Unwrap a DataZone `SensitiveString` (decoded as `Redacted`) to its plain
8 * string value. `String(redacted)` would yield `"<redacted>"`, not the value.
9 */
10 export const unredact = (value: string | Redacted.Redacted<string>): string =>
11 Redacted.isRedacted(value) ? Redacted.value(value) : value;
12
13 /**
14 * Coerce a DataZone wire tag map (values may be `undefined` on the wire) into
15 * a plain `Record<string, string>`.
16 */
17 export const toTagRecord = (
18 tags: { [key: string]: string | undefined } | undefined,
19 ): Record<string, string> =>
20 Object.fromEntries(
21 Object.entries(tags ?? {}).filter((entry): entry is [string, string] => entry[1] !== undefined),
22 );
23
24 /**
25 * Sync tags on a DataZone resource by ARN: diff the OBSERVED cloud tags
26 * against the desired set and apply only the delta.
27 */
28 export const syncDataZoneTags = Effect.fn(function* (
29 resourceArn: string,
30 observedTags: Record<string, string>,
31 desiredTags: Record<string, string>,
32 ) {
33 const { upsert, removed } = diffTags(observedTags, desiredTags);
34 if (upsert.length > 0) {
35 yield* datazone.tagResource({
36 resourceArn,
37 tags: Object.fromEntries(upsert.map(({ Key, Value }) => [Key, Value])),
38 });
39 }
40 if (removed.length > 0) {
41 yield* datazone.untagResource({ resourceArn, tagKeys: removed });
42 }
43 });