@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 55 lines 1.99 KB
Raw
1 import * as websecurityscanner from "@distilled.cloud/gcp/websecurityscanner_v1";
2 import { createPhysicalName } from "alchemy/PhysicalName";
3 import * as Effect from "effect/Effect";
4
5 export const lastSegment = (value: string) => {
6 const trimmed = value.replace(/\/+$/, "");
7 const parts = trimmed.split("/");
8 return parts[parts.length - 1] || trimmed;
9 };
10
11 export const projectParent = (project: string) => `projects/${project}`;
12
13 export const scanConfigNameOf = (project: string, scanConfigId: string) =>
14 `projects/${project}/scanConfigs/${scanConfigId}`;
15
16 export const sameText = (left: string | undefined, right: string | undefined) =>
17 (left ?? "") === (right ?? "");
18
19 export const jsonEqual = (left: unknown, right: unknown) =>
20 JSON.stringify(left ?? null) === JSON.stringify(right ?? null);
21
22 export const sortedStrings = (values: readonly string[] | undefined) =>
23 [...(values ?? [])].slice().sort();
24
25 export const stringList = (values: readonly (string | undefined)[] | null | undefined): string[] =>
26 (values ?? []).filter((value): value is string => typeof value === "string");
27
28 export const unspecified = (value: string | undefined) =>
29 value === undefined || value.length === 0 || value.endsWith("_UNSPECIFIED") ? "" : value;
30
31 export const updateMaskOf = (...fields: Array<string | undefined>) =>
32 fields.filter((field): field is string => field !== undefined).join(",");
33
34 export const toUserDisplayName = (
35 id: string,
36 requested: string | undefined,
37 existing: string | undefined,
38 maxLength = 80,
39 ) =>
40 Effect.gen(function* () {
41 if (requested !== undefined && requested.length > 0) return requested;
42 if (existing !== undefined && existing.length > 0) return existing;
43 return yield* createPhysicalName({
44 id,
45 maxLength,
46 lowercase: true,
47 });
48 });
49
50 export const getScanConfig = (name: string) =>
51 name.length === 0
52 ? Effect.undefined
53 : websecurityscanner
54 .getProjectsScanConfigs({ name })
55 .pipe(Effect.catchTag("NotFound", () => Effect.undefined));