refactor(sync): extract BaseItemHandler<T> + migrate 13 handlers (Phase 4 U8) - #231
Merged
Conversation
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
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.
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
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 (defaultfetchLocal/seedUnclockedstubs + unusedSyncItemHandlertype imports + scatteredresolveClockConflictre-imports) while preserving every handler's behavior.apps/desktop/src/main/sync/item-handlers/base-handler.ts— abstract class withtype/schema/applyUpsertabstract, sensible defaults forapplyDelete/fetchLocal/seedUnclocked, and aprotected resolveClock()helper.settings-handlerimplementsSyncItemHandlerdirectly 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.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.tsitself).Test plan
pnpm test(desktop via turbo) — 5872 passed, 1 pre-existing skip, 0 failurespnpm --dir apps/desktop exec tsc --noEmit -p tsconfig.node.json— cleanpnpm --dir apps/desktop exec tsc --noEmit -p tsconfig.web.json— cleanpnpm ipc:check— RPC bindings + invoke map up to dateNotes
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.this.resolveClock(...)instead of the freeresolveClockConflictimport. Behavior is identical —resolveClockon the base just delegates.