Skip to content

refactor(frontend): split lib/api.ts by domain - #323

Merged
attson merged 1 commit into
mainfrom
refactor/split-api-by-domain
Aug 4, 2026
Merged

refactor(frontend): split lib/api.ts by domain#323
attson merged 1 commit into
mainfrom
refactor/split-api-by-domain

Conversation

@attson

@attson attson commented Aug 4, 2026

Copy link
Copy Markdown
Owner

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:

  • api.ts: 1098 → 299 (-73%)
  • api/*.ts: ~950 new lines across 7 files (mostly the shared `_bindings.ts`)

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

  • `npm test` 1631/1631
  • `npm run build` (vue-tsc + vite) green
  • Manual: grep all 38 consumers of `./lib/api` — all still typecheck; behavior unchanged (barrel forwards)

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.
@attson
attson merged commit fbc8643 into main Aug 4, 2026
7 checks passed
@attson
attson deleted the refactor/split-api-by-domain branch August 4, 2026 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant