Refactor: split large files, extract shared patterns, improve type safety#3
Open
Refactor: split large files, extract shared patterns, improve type safety#3
Conversation
Every WRITE and RECEIPT tier command repeated the same pattern: if (!confirm) return needsConfirm(null, plan) else execute(). New shared/with-confirm.ts provides withConfirm() that encapsulates this branching. Applied to 9 command files: contacts add/edit/import, donations add/void, receipts generate/batch/void, orgs add, config set. https://claude.ai/code/session_01D3rGyrcsVT96ZepUP66rjT
cli.ts (396 lines) → 23 lines + 10 command modules in commands/. Each domain (contacts, donations, receipts, reports, orgs, config, jobs, search, stubs) registers its own subcommands via a register*Commands() function. createProgram() composes them all. cli.ts now only calls createProgram().parseAsync(). https://claude.ai/code/session_01D3rGyrcsVT96ZepUP66rjT
- Add resolveSortColumn() helper to replace (schema.table as any)[field] in contacts/list.ts and donations/list.ts - Type condition arrays as SQL[] instead of any[] - Add PdfConfig interface for receipt PDF generation - Type raw SQL query results (sequence, search, summary) - Replace (existing as any)[colName] with typed access in config/set.ts Production code now has zero `as any` (remaining are in test helpers). https://claude.ai/code/session_01D3rGyrcsVT96ZepUP66rjT
- container-mounts.ts: buildVolumeMounts() + buildContainerArgs() (210 lines) - ipc-snapshots.ts: writeTasksSnapshot() + writeGroupsSnapshot() (70 lines) - container-runner.ts: runContainerAgent() stays, imports from new modules Re-exports from container-runner.ts preserve all existing import paths. https://claude.ai/code/session_01D3rGyrcsVT96ZepUP66rjT
- db-messages.ts: storeMessage, getNewMessages, getMessagesSince (110 lines) - db-tasks.ts: createTask, updateTask, deleteTask, getDueTasks, etc. (130 lines) - db-state.ts: chat metadata, router state, sessions, registered groups (250 lines) - db.ts: schema, init, migration, getDb() accessor + re-exports (240 lines) All existing imports from './db.js' continue to work via re-exports. https://claude.ai/code/session_01D3rGyrcsVT96ZepUP66rjT
Column mapping (COLUMN_ALIASES, SALESFORCE_PRESET, buildColumnMap) and row validation (parseRows) extracted from import.ts (386→210 lines) into import-parser.ts (170 lines). Parser is now independently testable without DB mocks. https://claude.ai/code/session_01D3rGyrcsVT96ZepUP66rjT
Both contacts/list.ts and donations/list.ts had identical 4-line
sort parsing blocks. New parseSortOption() in db/sort.ts returns
{ descending, column, orderFn } in one call.
https://claude.ai/code/session_01D3rGyrcsVT96ZepUP66rjT
Replace `any` with Partial<typeof schema.*.inferSelect> for donation, receipt, and receiptConfig fixture factories. Catches typos in test overrides at compile time. https://claude.ai/code/session_01D3rGyrcsVT96ZepUP66rjT
… retry The test used mockImplementationOnce which only threw on the first docker info call. On the second retry, the mock returned undefined (no throw), so the function succeeded instead of exhausting retries. Changed to mockImplementation with a cmd filter so all docker info calls throw while sleep calls succeed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
withConfirm()wrapper — eliminates confirm/plan boilerplate across 9 command filescli.ts(396→23 lines) into 10 domain-specific command modulesas anywith typed sort resolution, SQL conditions, PdfConfig interfacecontainer-runner.ts(708→380) into container-mounts.ts + ipc-snapshots.tsdb.ts(698→240) into db-messages.ts, db-tasks.ts, db-state.tsimport-parser.tsfrom contacts/import.ts for independent testabilityparseSortOption()to deduplicate sort logic in list commandsTest plan
🤖 Generated with Claude Code