[0.6] refactor(ipc): extract registerCommand wrapper + migrate notes handlers - #212
Merged
Conversation
…lers
Extract a `registerCommand(channel, schema, command, fallback?)` helper
that composes `createValidatedHandler` and `withErrorHandler` in a single
call, collapsing the repeated triple-nested pattern
ipcMain.handle(channel, createValidatedHandler(schema, withErrorHandler(fn, fallback)))
to a single line. Migrate 15 matching handler sites in notes-handlers.ts
(create, update, rename, move, rename-folder, create/update property
definitions, delete-attachment, set-folder-config, export-pdf, export-html,
get-positions, reorder, import-files, set-local-only). Handlers that take
no input or a bare string (createHandler/createStringHandler) are left
unchanged per the wrapper's scope.
Teach the IPC invoke-map generator to recognise `registerCommand` calls
alongside `ipcMain.handle`, read the raw input type from the schema
(so defaulted fields remain optional at the boundary), and augment the
handler return type with the `{ success: false; error: string }` branch
that `withErrorHandler` injects at runtime. This keeps the generated
invoke map and RPC bindings stable after the refactor.
Add `register-command.test.ts` covering the five behavioural contracts:
registration, validated input forwarding, schema rejection, thrown-error
envelope, and fallback message handling.
9 tasks
h4yfans
added a commit
that referenced
this pull request
May 6, 2026
[0.6] refactor(ipc): extract registerCommand wrapper + migrate notes handlers
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
Unit 0.6 of the IPC tech-debt cleanup. Extracts the repeated triple-nested IPC handler registration pattern into a single
registerCommandhelper and migrates the qualifying notes handler sites to use it.What changed
apps/desktop/src/main/ipc/lib/register-command.ts—registerCommand(channel, schema, command, fallback?)composescreateValidatedHandler+withErrorHandler+ipcMain.handlein a single call. Handler callback retains full control over its return shape; no envelope is imposed.apps/desktop/src/main/ipc/lib/register-command.test.ts— 5 tests covering registration, validated input forwarding, schema rejection, thrown-error envelope, fallback message.apps/desktop/src/main/ipc/notes-handlers.ts:create,update,rename,moverename-foldercreate-property-definition,update-property-definitiondelete-attachment,set-folder-configexport-pdf,export-htmlget-positions,reorder,import-files,set-local-onlycreateHandler(no input) orcreateStringHandler(bare string input), and barecreateValidatedHandlercalls without nestedwithErrorHandler.Line deltas
notes-handlers.ts: 951 → 942 (-9 net, diff shows +236 / -249 of migrated content)IPC generator updates
The migration caused two regressions in
generated-ipc-invoke-map.tsthat had to be fixed inscripts/generate-ipc-invoke-map.js:ipcMain.handle(...)calls. Added detection forregisterCommand(...).rawInput: z.input<TSchema>(defaulted fields optional). WithregisterCommand, the command callback is typed(input: z.infer<TSchema>) => TResult(defaulted fields required), which narrowed the boundary type and broke callers. Generator now readsz.inputfrom the schema's own type via its_inputproperty forregisterCommandcalls, matching previous semantics.{ success: false; error: string }branch thatwithErrorHandleradds at runtime. Generator now unions that branch into the awaited return forregisterCommandcalls, matching the previous union shape.E2E smoke
pnpm test:e2e -- --grep "note"was launched but did not complete end-to-end within the available run window (Playwright was still iterating throughbody-crdt-*,note-sync-helpers, andnotes.e2e.tssuites after ~10 minutes with no failures reported, then stopped producing new artifacts with no output written to stdout). The run was terminated without a full pass/fail summary. Cannot confirm e2e end-to-end.Instead, the final
npx electron-vite buildsucceeded cleanly — evidence below (last 20 lines):Verification
pnpm ipc:check- passpnpm lint- 0 errors, 1420 pre-existing warnings (none introduced by this PR in notes-handlers.ts)pnpm --filter @memry/desktop typecheck:node- passpnpm --filter @memry/desktop typecheck:web- passpnpm typecheck:packages- pass (FULL TURBO)pnpm test- 5691/5692 pass; single failure is the knowncalendar-page.test.tsx:258"Due draft" flakenpx electron-vite build- passregister-command.test.ts- 5/5 passTest plan