refactor(frontend): split lib/api.ts by domain - #323
Merged
Conversation
M7-c. api.ts was 1098 lines wrapping ~140 window.go.main.App calls in
one file: every domain (relay, ssh, feishu, tasks, updates, recovery)
lived side-by-side with generic prefs and session lifecycle. Anyone
touching one relay method had to skim 1000 unrelated lines to find it.
Split into a domain subdir:
lib/api/
_bindings.ts — AppBindings interface + Window decl + bindings() +
every wire type (moved from api.ts so domain files
can reference them without an api.ts import cycle)
relay.ts — 20 fns: config, login, register, me, pairing,
diagnostics, sessions listing, uplink health
ssh.ts — 9 fns: connect + hosts + keys
feishu.ts — 10 fns: mode + status + credentials + hook install
tasks.ts — 10 fns: preset/groupBy/sidebar + pins + templates +
mark-seen + broadcast-command-finished
updates.ts — 10 fns: updater state + download + install +
GH proxy + auto-check toggle
recovery.ts — 5 fns: load/save/discard + dialog-enabled toggle
api.ts — barrel `export *` for the 6 slices + "everything
else" (session lifecycle, generic prefs, notif
wrappers, logging, WebGL/shell-integration toggles)
Every existing consumer keeps `import { X } from "./lib/api"` unchanged
because api.ts re-exports everything. No caller was renamed.
Sizes:
api.ts 1098 → 299 (-73%)
api/*.ts new ~950 across 7 files (mostly the shared _bindings.ts)
Test update: App.theme.test.ts scanned api.ts?raw for two AppBindings
signatures ("GetTerminalTheme(): Promise<string>"). After the split
those live in api/_bindings.ts; the test now imports both files and
scans the right one for interface signatures vs wrapper functions.
`npm test` 1631/1631; `npm run build` (vue-tsc + vite) green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Milestone 7-c. `api.ts` was 1098 lines wrapping ~140 `window.go.main.App` calls in one file: every domain (relay, ssh, feishu, tasks, updates, recovery) lived side-by-side with generic prefs and session lifecycle. Anyone touching one relay method had to skim 1000 unrelated lines to find it.
Split into a domain subdir:
```
lib/api/
_bindings.ts — AppBindings interface + Window decl + bindings() +
every wire type (moved from api.ts so domain files
can reference them without an api.ts import cycle)
relay.ts — 20 fns: config, login, register, me, pairing,
diagnostics, sessions listing, uplink health
ssh.ts — 9 fns: connect + hosts + keys
feishu.ts — 10 fns: mode + status + credentials + hook install
tasks.ts — 10 fns: preset/groupBy/sidebar + pins + templates +
mark-seen + broadcast-command-finished
updates.ts — 10 fns: updater state + download + install +
GH proxy + auto-check toggle
recovery.ts — 5 fns: load/save/discard + dialog-enabled toggle
api.ts — barrel `export *` for the 6 slices + "everything
else" (session lifecycle, generic prefs, notif
wrappers, logging, WebGL/shell-integration toggles)
```
Every existing consumer keeps `import { X } from "./lib/api"` unchanged because api.ts re-exports everything. No caller was renamed.
Sizes:
Test update: `App.theme.test.ts` scanned `api.ts?raw` for two AppBindings signatures (`"GetTerminalTheme(): Promise"`). After the split those live in `api/_bindings.ts`; the test now imports both files and scans the right one for interface signatures vs wrapper functions.
Test plan