Skip to content

Reduce duplication in Tasks API layer#805

Merged
EhabY merged 3 commits intomainfrom
reduce-duplication-tasks-api
Feb 24, 2026
Merged

Reduce duplication in Tasks API layer#805
EhabY merged 3 commits intomainfrom
reduce-duplication-tasks-api

Conversation

@EhabY
Copy link
Collaborator

@EhabY EhabY commented Feb 20, 2026

Summary

  • Replace per-definition requestHandler/commandHandler wrappers with buildRequestHandlers and buildCommandHandlers mapped-type builders that enforce compile-time completeness over the full API surface
  • Add buildApiHook and ApiHook<Api> so that useTasksApi is auto-generated from the TasksApi definition object at runtime, eliminating ~60 lines of manual method listings that had to stay in sync
  • Add kind discriminant to RequestDef, CommandDef, and NotificationDef so builders can dispatch by kind at runtime
  • Inline intermediate const declarations in api.ts directly into the TasksApi object and remove unused ParamsOf/ResponseOf utility types
  • Replace raw sendNotification calls in tasksPanelProvider with a typed notify helper

Closes #798

@EhabY EhabY self-assigned this Feb 20, 2026
@EhabY EhabY changed the base branch from main to refactor-tasks-webview February 20, 2026 01:04
@mafredri mafredri self-requested a review February 20, 2026 07:51
Base automatically changed from refactor-tasks-webview to main February 24, 2026 11:14
Replace per-definition requestHandler/commandHandler wrappers with
buildRequestHandlers and buildCommandHandlers that enforce compile-time
completeness over the full API surface.

- Add kind discriminant to RequestDef, CommandDef, and NotificationDef
  interfaces and their factory functions
- Add RequestHandlerMap and CommandHandlerMap mapped types that require
  a handler for every definition of the corresponding kind
- Add buildRequestHandlers and buildCommandHandlers builder functions
  with typed overloads for compile-time completeness checking
- Replace manual method-keyed handler maps in tasksPanelProvider with
  builder calls using property-name keys
- Replace raw sendNotification calls with a typed notify helper
Add buildApiHook and ApiHook<Api> to protocol.ts so that useTasksApi
can be derived from the TasksApi definition object with zero manual sync.

- Add ApiHook<Api> mapped type that derives request, command, and
  notification subscription signatures from an API definition
- Add buildApiHook() that iterates API entries by kind at runtime,
  dispatching to ipc.request/command/onNotification
- Replace ~60 lines of manual method listings in useTasksApi with a
  single buildApiHook(TasksApi, useIpc()) call
- Update 5 consumer call sites from positional args to params objects
- Inline intermediate const declarations in api.ts into TasksApi object
- Remove unused ParamsOf and ResponseOf utility types
@EhabY EhabY force-pushed the reduce-duplication-tasks-api branch from 7077aee to 790ab2d Compare February 24, 2026 11:14
@EhabY EhabY merged commit 13744b2 into main Feb 24, 2026
6 checks passed
@EhabY EhabY deleted the reduce-duplication-tasks-api branch February 24, 2026 11:34
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.

Reduce duplication across TasksApi / useTasksApi / TasksPanel handler maps

3 participants