@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 27 lines 1017 Bytes
Raw
1 import type { SearchMiddleware } from "@tanstack/react-router";
2
3 import { validateSettingsScopeSearch, type SettingsScopeSearch } from "./settingsScope";
4
5 export function validateSettingsRouteSearch(raw: Record<string, unknown>) {
6 return validateSettingsScopeSearch(
7 typeof raw.environmentId === "string" && raw.machine === undefined && raw.project === undefined
8 ? { ...raw, machine: raw.environmentId }
9 : raw,
10 );
11 }
12
13 const SCOPE_KEYS = [
14 "project",
15 "machine",
16 "checkout",
17 ] as const satisfies readonly (keyof SettingsScopeSearch)[];
18 const TARGET_INPUT_KEYS = [...SCOPE_KEYS, "environmentId"];
19
20 export const retainSettingsScope: SearchMiddleware<SettingsScopeSearch> = ({ search, next }) => {
21 const result = next(search);
22 if (TARGET_INPUT_KEYS.some((key) => Object.hasOwn(result, key))) return result;
23 const previousScope = Object.fromEntries(
24 SCOPE_KEYS.filter((key) => search[key] !== undefined).map((key) => [key, search[key]]),
25 );
26 return { ...previousScope, ...result };
27 };