refactor(wallet-toolbox): reduce cognitive complexity in StorageIdb#88
Merged
refactor(wallet-toolbox): reduce cognitive complexity in StorageIdb#88
Conversation
Extract per-entity partial-match helpers into idbHelpers.ts, replace while+firstTime cursor pattern with for-loop in all filter* methods, and extract private helpers (applyDateFields, applyBooleanFields, normalizeEntityValues, applyOptionalDateFields, applyIntegerBooleanFields, normalizeForStorage) to reduce S3776 violations. refs #38 #44 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…ers below threshold Decompose high-CC helpers (especially L143 at CC 46) into smaller per-entity / per-version helpers to satisfy the 15 cognitive-complexity limit. - Replace sequential `if (field !== undefined && record !== field)` guards with CC-free helpers (eq, eqNullable, dateEq, dateEqNullable) so each matcher function's CC drops to 1 (a single && chain in a return). - Split matchesOutputPartial, matchesSyncStatePartial, and matchesTransactionPartial into private Ids/Dates/Scalars/Strings sub-helpers so no public function exceeds ~4 &&-chains. - Extract upgradeAllStoresV1 to collapse the 15-branch upgrade() callback in StorageIdb.initDB (CC 18 → ~3), replacing 15 individual upgrade imports with a single one. - dateEq delegates to the existing dateMatches to avoid duplicating logic. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
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
idbHelpers.tssibling file, eliminating inlineifchains in allfilter*methodswhile (cursor) { if (firstTime) ... firstTime = false; ... cursor = await cursor.continue() }pattern withfor (; cursor != null; cursor = await cursor.continue())throughoutapplyDateFields,applyBooleanFields,normalizeEntityValues,applyOptionalDateFields,applyIntegerBooleanFields,normalizeForStoragefromvalidateEntity/validatePartialForUpdate/validateEntityForInsertupgradeProvenTxs,upgradeUsers, etc.) frominitDBto reduce its complexityFixes #38, #44
Test plan
pnpm --filter @bsv/wallet-toolbox run buildpasses (StorageIdb-specific TS errors: none; pre-existing cross-agent TS errors from WhatsOnChain/StorageProvider helpers not yet merged)StorageIdb.test.tstest suite blocked by pre-existing missingstorageProviderHelpersimport from another wave-2 agent; will pass once that PR merges🤖 Generated with Claude Code