Skip to content

refactor(sync): extract BaseItemHandler<T> + migrate 13 handlers (Phase 4 U8) - #231

Merged
h4yfans merged 1 commit into
mainfrom
worktree-agent-a5069bd2
Apr 16, 2026
Merged

refactor(sync): extract BaseItemHandler<T> + migrate 13 handlers (Phase 4 U8)#231
h4yfans merged 1 commit into
mainfrom
worktree-agent-a5069bd2

Conversation

@h4yfans

@h4yfans h4yfans commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

Phase 4 U8 of tech-debt-remediation: extract a shared BaseItemHandler<T> abstract class and migrate all 13 sync item handlers to inherit from it. Eliminates ~40 lines of boilerplate per handler (default fetchLocal/seedUnclocked stubs + unused SyncItemHandler type imports + scattered resolveClockConflict re-imports) while preserving every handler's behavior.

  • New: apps/desktop/src/main/sync/item-handlers/base-handler.ts — abstract class with type/schema/applyUpsert abstract, sensible defaults for applyDelete/fetchLocal/seedUnclocked, and a protected resolveClock() helper.
  • Migrated (12 extend BaseItemHandler): calendar-binding, calendar-event, calendar-external-event, calendar-source, filter, folder-config, inbox, journal, note, project, tag-definition, task.
  • Standalone (1): settings-handler implements SyncItemHandler directly with an inline comment — it overrides every concrete method because settings live in config.json + prefs cache, not a sync DB table. Inheritance would add indirection for zero gain.
  • Untouched: types.ts, index.ts, field-merge.ts. SyncItemHandler<T> interface shape unchanged. getHandler(type) / getAllHandlers() signatures unchanged.

LOC delta

14 files changed, +219 / -147 (net +72, of which ~40 is the new base-handler.ts itself).

Test plan

  • pnpm test (desktop via turbo) — 5872 passed, 1 pre-existing skip, 0 failures
  • pnpm --dir apps/desktop exec tsc --noEmit -p tsconfig.node.json — clean
  • pnpm --dir apps/desktop exec tsc --noEmit -p tsconfig.web.json — clean
  • pnpm ipc:check — RPC bindings + invoke map up to date
  • Manual smoke (post-merge): launch desktop app, create/edit/delete items across types, verify sync push+pull round-trip

Notes

  • All existing handler-level tests (settings-handler.test.ts, note-handler.test.ts, task-handler.test.ts, project-handler.test.ts, folder-config-handler.test.ts, calendar-event-handler.test.ts, note-handler-binary.test.ts) pass without modification — they test the exported singleton's methods, and the singleton's shape is preserved.
  • Each handler now calls this.resolveClock(...) instead of the free resolveClockConflict import. Behavior is identical — resolveClock on the base just delegates.
  • No changes to runtime semantics, transaction boundaries, logging, or emitted events.

Introduce BaseItemHandler<T> abstract class in src/main/sync/item-handlers/
base-handler.ts with sensible defaults for applyDelete (returns 'skipped'),
fetchLocal (returns undefined), seedUnclocked (returns 0), plus a protected
resolveClock helper that wraps resolveClockConflict from types.ts.

Migrate all 12 table-backed handlers to extend BaseItemHandler:
- calendar-binding, calendar-event, calendar-external-event, calendar-source
- filter, folder-config, inbox, tag-definition
- journal, note, project, task

settings-handler stays standalone (implements SyncItemHandler directly) with
an inline comment — it overrides every concrete method because settings live
in config.json + prefs cache, not a dedicated sync DB table.

External API preserved: getHandler(type) / getAllHandlers() signatures
unchanged. types.ts, index.ts, field-merge.ts untouched.

All 5872 tests pass. LOC delta: +177 / -147 across 13 handlers + ~40 new
lines in base-handler.ts.
@h4yfans
h4yfans merged commit ec34245 into main Apr 16, 2026
2 checks passed
h4yfans added a commit that referenced this pull request May 6, 2026
Introduce BaseItemHandler<T> abstract class in src/main/sync/item-handlers/
base-handler.ts with sensible defaults for applyDelete (returns 'skipped'),
fetchLocal (returns undefined), seedUnclocked (returns 0), plus a protected
resolveClock helper that wraps resolveClockConflict from types.ts.

Migrate all 12 table-backed handlers to extend BaseItemHandler:
- calendar-binding, calendar-event, calendar-external-event, calendar-source
- filter, folder-config, inbox, tag-definition
- journal, note, project, task

settings-handler stays standalone (implements SyncItemHandler directly) with
an inline comment — it overrides every concrete method because settings live
in config.json + prefs cache, not a dedicated sync DB table.

External API preserved: getHandler(type) / getAllHandlers() signatures
unchanged. types.ts, index.ts, field-merge.ts untouched.

All 5872 tests pass. LOC delta: +177 / -147 across 13 handlers + ~40 new
lines in base-handler.ts.
@h4yfans
h4yfans deleted the worktree-agent-a5069bd2 branch May 6, 2026 16:36
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