@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 66 lines 2.06 KB
Raw
1 import * as redshift from "@distilled.cloud/aws/redshift";
2 import * as Effect from "effect/Effect";
3
4 /**
5 * Convert Redshift's `[{ Key, Value }]` tag list into a plain record,
6 * dropping any entry missing a key or value.
7 */
8 export const toTagRecord = (
9 tags: Array<{ Key?: string; Value?: string }> | undefined,
10 ): Record<string, string> =>
11 Object.fromEntries(
12 (tags ?? [])
13 .filter(
14 (tag): tag is { Key: string; Value: string } =>
15 typeof tag.Key === "string" && typeof tag.Value === "string",
16 )
17 .map((tag) => [tag.Key, tag.Value]),
18 );
19
20 /** True when two string sets are equal ignoring order and duplicates. */
21 export const sameStringSet = (
22 a: readonly string[] | undefined,
23 b: readonly string[] | undefined,
24 ): boolean => {
25 const left = [...new Set(a ?? [])].sort();
26 const right = [...new Set(b ?? [])].sort();
27 return left.length === right.length && left.every((v, i) => v === right[i]);
28 };
29
30 /**
31 * Build the ARN of a provisioned-Redshift resource. Redshift describe
32 * responses do not surface resource ARNs (only the namespace ARN on
33 * clusters), so tag operations construct them from the ambient
34 * account/region.
35 */
36 export const redshiftArn = (
37 region: string,
38 accountId: string,
39 resourceType: "cluster" | "subnetgroup" | "parametergroup" | "eventsubscription",
40 name: string,
41 ): string => `arn:aws:redshift:${region}:${accountId}:${resourceType}:${name}`;
42
43 /**
44 * Apply a tag delta to a provisioned-Redshift resource via the shared
45 * CreateTags/DeleteTags operations. `upsert`/`removed` come from `diffTags`
46 * against OBSERVED cloud tags (Redshift describe responses carry tags
47 * inline).
48 */
49 export const applyRedshiftTagDelta = Effect.fn(function* (input: {
50 arn: string;
51 upsert: Array<{ Key: string; Value: string }>;
52 removed: string[];
53 }) {
54 if (input.upsert.length > 0) {
55 yield* redshift.createTags({
56 ResourceName: input.arn,
57 Tags: input.upsert,
58 });
59 }
60 if (input.removed.length > 0) {
61 yield* redshift.deleteTags({
62 ResourceName: input.arn,
63 TagKeys: input.removed,
64 });
65 }
66 });