Skip to content

refactor: centralize sync dispatch via adapter registry (Phase 5) - #188

Merged
h4yfans merged 9 commits into
mainfrom
memry/simplify-synccore-phase-5
Apr 9, 2026
Merged

refactor: centralize sync dispatch via adapter registry (Phase 5)#188
h4yfans merged 9 commits into
mainfrom
memry/simplify-synccore-phase-5

Conversation

@h4yfans

@h4yfans h4yfans commented Apr 9, 2026

Copy link
Copy Markdown
Collaborator

What

Centralize all domain sync dispatch behind a local-mutations adapter registry, replacing scattered direct sync service calls across 12+ runtime-effects modules.

Why

Phase 5 of the architecture reset plan: make sync adapter-driven instead of feature-driven. Direct getTaskSyncService() / getInboxSyncService() calls were scattered across every runtime-effects module, each with duplicated online/offline fallback logic. This also reverts the premature @memry/domain-inbox extraction from Phase 3 — the domain boundary wasn't ready, and the extraction dropped transaction atomicity, Zod validation, and error handling at the IPC trust boundary.

How

  • New local-mutations.ts: Adapter registry using createSyncAdapterRegistry from @memry/sync-core. Each domain type registers a local sync adapter with enqueueCreate/Update/Delete that handles online service dispatch with offline clock fallback.
  • Consumer migration: All runtime-effects, vault watcher, filing, and handler modules now call enqueueLocalSyncCreate/Update/Delete instead of direct sync services. Removes db parameter from sync effect signatures.
  • Inbox handler fixes: Restored insertItemWithTags transactional helper, added normalizeBinaryInput shared buffer helper, added CaptureVoiceSchema Zod validation, wrapped convertToNote/convertToTask/linkToNote with withErrorHandler.
  • Tag sync fix: Gated enqueueLocalSyncCreate behind snapshot existence check in rename/merge to prevent orphan sync entries.
  • Proxy forwarder: Restored has/ownKeys/getOwnPropertyDescriptor traps removed in prior simplification.
  • React fixes: Restored void prefix on floating promise, setProjects in deps array, stable empty-array refs preventing unnecessary re-renders.

Type

  • feat — new feature
  • fix — bug fix
  • refactor — restructure without behavior change
  • style — visual/UI only
  • perf — performance improvement
  • test — adding or updating tests
  • chore — tooling, deps, config
  • docs — documentation only
  • ci — CI/CD changes

Test plan

  • Unit tests added/updated
  • Manual testing (describe below)

local-mutations.test.ts covers adapter routing, offline fallbacks, note sync removal, and settings field update. window-api-forwarder.test.ts restored with 6 tests for proxy trap behavior. inbox-handlers.test.ts updated with transaction mock support. Full suite: 254 files, 5521 tests pass. pnpm typecheck, pnpm lint (0 errors), pnpm ipc:check all green.

Checklist

  • Self-reviewed the diff
  • No hardcoded secrets or credentials
  • Files stay under ~500 LOC
  • Follows immutable data patterns

h4yfans added 9 commits April 9, 2026 22:50
Centralize all domain sync dispatch behind enqueueLocalSyncCreate/Update/Delete.
Each domain type registers a local sync adapter with online/offline fallback,
replacing scattered direct sync service calls across runtime-effects modules.
…istry

Replace direct sync service calls and offline clock fallbacks in all
runtime-effects modules, vault watcher, filing, and IPC handlers with
unified enqueueLocalSyncCreate/Update/Delete calls. Removes db parameter
from sync effect function signatures.
…g in inbox handlers

Revert premature domain extraction: inline capture logic back into IPC
handlers with fixes from review. Add insertItemWithTags transactional
helper, normalizeBinaryInput shared buffer helper, CaptureVoiceSchema
validation at IPC boundary, and withErrorHandler on convertToNote/
convertToTask/linkToNote. Update test mocks for transaction support.
Re-add has, ownKeys, and getOwnPropertyDescriptor traps removed during
prior simplification. Without these, 'in' operator, Object.keys(), and
JSON.stringify return incorrect results. Restore deleted test file.
…ty-array refs

Restore void on tasksService.reorder() and setProjects in handleDragEnd
deps removed during prior refactor. Add module-level EMPTY_TASKS/
EMPTY_PROJECTS constants in useTaskWorkspaceData to prevent unstable
array references triggering unnecessary TasksProvider re-renders.
Add blocked-pattern rules for direct IPC sync-module imports. Mark Phase 5
sync adapter gate items complete, revert premature Phase 3 checkmarks.
…re-phase-5

# Conflicts:
#	CHANGELOG.md
#	apps/desktop/src/main/ipc/generated-ipc-invoke-map.ts
#	apps/desktop/src/main/ipc/inbox-handlers.ts
#	apps/desktop/src/main/vault/watcher.ts
#	apps/desktop/src/renderer/src/services/window-api-forwarder.test.ts
Restore our branch's config deletions that the merge with origin/main
re-added. Removes @memry/domain-inbox package files and all references
from vitest, vite, package.json, and tsconfig files.
@h4yfans
h4yfans merged commit 9b10c58 into main Apr 9, 2026
4 checks passed
@h4yfans
h4yfans deleted the memry/simplify-synccore-phase-5 branch April 9, 2026 20:13
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