refactor: extract shared helper for duplicated logic (#46)#55
Merged
Conversation
…geMobile (#46) Both StorageClient (with logger support) and StorageMobile (lightweight variant) were ~420-line near-identical classes. Extract all shared WalletStorageProvider method implementations and entity-validation helpers into StorageClientBase. Each subclass now only implements the rpcCall method that differs between them. Partial fix for #46. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fixes frozen-lockfile CI failure introduced in c4db522 which added tsx to ts-p2p devDependencies without regenerating the lockfile. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…ication Extract validateDate, validateEntity, and validateEntities from both StorageClientBase and StorageServer into a shared entityValidationHelpers.ts. Both classes now delegate to the standalone functions, removing the duplicate implementation that SonarCloud flagged between the two files. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Author
CI Status
This is a partial fix and may need a follow-up commit to address the CodeQL finding before merge. |
…hunk duplication Both StorageClientBase.getSyncChunk and StorageServer's processSyncChunk case had the same 13-line SyncChunk entity-validation block. Extract it into validateSyncChunkEntities() in entityValidationHelpers.ts and replace both sites. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…d injection CodeQL flags js/loop-bound-injection when iterating with .length on a user-controlled value. Guard with Array.isArray() so non-array inputs (e.g. JSON objects with a spoofed .length) are returned unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
This was referenced May 6, 2026
Closed
sirdeggen
added a commit
that referenced
this pull request
May 6, 2026
Add Jest unit tests for the four exports of packages/wallet/wallet-toolbox/src/storage/remoting/entityValidationHelpers.ts to recover SonarCloud's new-coverage gate after PR #55. Covers validateDate (Date / ISO string / number / epoch / unparsable), validateEntity (string-to-Date coercion, null-to-undefined, Uint8Array and Buffer to number[] equivalence, custom dateFields, in-place mutation), validateEntities (non-array passthrough, empty / single / multi, dateFields propagation), and validateSyncChunkEntities (empty chunk, user-only, all-arrays-populated, undefined / empty array handling). 100% statement / branch / function / line coverage on the file. Co-authored-by: Claude Opus 4.7 <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
Partial fix for #46 (9,792 duplicated lines / 439 blocks).
StorageClientBaseabstract class from the two near-identical storage remoting classesStorageClient(full logger support) andStorageMobile(lightweight variant) each had ~420 lines of identicalWalletStorageProvidermethod implementationsStorageClientBaseand only implement therpcCallmethod that differs between themWhat changed
src/storage/remoting/StorageClientBase.tssrc/storage/remoting/StorageClient.tsStorageClientBasesrc/storage/remoting/StorageMobile.tsStorageClientBaseDuplication removed: ~420 lines (one block, two files).
No behavior change. All public APIs, class names, and export paths are identical. The
constructor.name === 'StorageClient'check inWalletStorageManagercontinues to work because both subclasses retain theStorageClientname.Test plan
tsc --noEmit --skipLibCheckpasses with no errors in changed filesnpm run buildproduces compiled output for all three remoting filesRefs #46