Skip to content

Reduce cyclomatic complexity in raw-stream hotspots and consolidate utilities under src/utils#318

Merged
albe merged 11 commits into
mainfrom
copilot/refactor-codebase-maintainability
May 27, 2026
Merged

Reduce cyclomatic complexity in raw-stream hotspots and consolidate utilities under src/utils#318
albe merged 11 commits into
mainfrom
copilot/refactor-codebase-maintainability

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 27, 2026

Recent raw stream support increased complexity in core storage/event modules, creating maintainability hotspots (notably metadataUtil, EventStore, and partition/storage writers). This change set reduces branch-heavy logic where it adds value and centralizes reusable utilities under src/utils.

  • Utility module consolidation

    • Moved utility files from src/*Util.js/src/util.js to src/utils/*.
    • Updated all internal imports, affected tests, package file inclusion, and publish-workflow packed-file expectations to the new paths.
  • metadataUtil refinements

    • Kept low-complexity hot-path checks inline with Array.some(...) where dedicated helpers did not improve clarity.
    • Extracted binary JSON same-level matching/scanning logic into a dedicated reusable utility: src/utils/jsonUtil.js.
    • Preserved matcher behavior while simplifying object-branch handling in matcher tree construction.
  • EventStore branch simplification

    • Extracted repeated predicate/raw argument normalization into a shared helper used by stream-access APIs.
    • Consolidated delegated hook-event handling (preCommit/preRead) into shared delegation methods to remove duplicated conditional branches.
    • Isolated query-type existence resolution into a dedicated method.
  • WritableStorage / partition refactors

    • WritableStorage: extracted partition id/config/directory creation paths and streamlined secondary-index add paths to keep index.add(...) explicit without unnecessary delegation.
    • ReadablePartition: extracted iteration position resolution, reader selection, and header output assignment helpers.
    • WritablePartition: extracted write metadata/argument normalization and unbuffered-write threshold decision.
function normalizePredicateRaw(predicate, raw) {
  if (typeof predicate === 'boolean' && raw === false) {
    return { predicate: null, raw: predicate };
  }
  return { predicate, raw };
}

Copy link
Copy Markdown
Owner

@albe albe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot We do not aim towards single digit complexity per function, but rather a low two digit value (20-30 is okayish) with occasional functions especially in the hot path being allowed to go higher. So avoid extracting methods from methods that are already low in complexity, unless it allows to extract logic into a generic util.

Comment thread src/utils/metadataUtil.js Outdated
Comment thread src/utils/metadataUtil.js Outdated
Comment thread src/utils/metadataUtil.js Outdated
Comment thread src/utils/metadataUtil.js Outdated
Comment thread src/Storage/WritableStorage.js Outdated
Comment thread src/Storage/WritableStorage.js
Copilot finished work on behalf of albe May 27, 2026 12:24
Copilot AI requested a review from albe May 27, 2026 12:24
Comment thread src/Storage/WritableStorage.js Outdated
Comment thread src/Storage/WritableStorage.js Outdated
Comment thread src/utils/metadataUtil.js Outdated
Comment thread src/utils/metadataUtil.js Outdated
Copilot finished work on behalf of albe May 27, 2026 13:16
Copilot AI requested a review from albe May 27, 2026 13:16
Comment thread src/utils/metadataUtil.js Outdated
Comment thread src/utils/metadataUtil.js
Comment on lines +5 to +7
function isPlainObject(value) {
return value !== null && typeof value === 'object' && !Array.isArray(value);
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function isPlainObject(value) {
return value !== null && typeof value === 'object' && !Array.isArray(value);
}

Comment thread src/Storage/WritableStorage.js Outdated
Comment thread src/Storage/WritableStorage.js Outdated
Copilot finished work on behalf of albe May 27, 2026 15:30
Copilot AI requested a review from albe May 27, 2026 15:30
@albe
Copy link
Copy Markdown
Owner

albe commented May 27, 2026

@copilot resolve the merge conflicts in this pull request

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 27, 2026

@copilot resolve the merge conflicts in this pull request

Merge conflicts are resolved in commit 4aac3f9.

Copilot finished work on behalf of albe May 27, 2026 17:19
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 27, 2026

@copilot resolve the merge conflicts in this pull request

Resolved in 0c5d557 by merging origin/main and fixing all resulting conflicts in the PR branch.

Copilot finished work on behalf of albe May 27, 2026 17:22
Co-authored-by: Alexander Berl <a.berl@outlook.com>
@coveralls
Copy link
Copy Markdown

coveralls commented May 27, 2026

Coverage Status

coverage: 98.42% (-0.04%) from 98.459% — copilot/refactor-codebase-maintainability into main

Comment thread src/Storage/WritableStorage.js Outdated
Copilot finished work on behalf of albe May 27, 2026 17:30
Copilot AI requested a review from albe May 27, 2026 17:30
@albe
Copy link
Copy Markdown
Owner

albe commented May 27, 2026

@copilot where is the -0.04% coverage coming from?

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 27, 2026

@copilot where is the -0.04% coverage coming from?

It’s mainly from src/utils/metadataUtil.js: coverage there dropped from 99.67% on main to 98.78% in this branch due to 2 additional uncovered lines (5-7, the isPlainObject helper). There’s also 1 uncovered line in the new src/utils/jsonUtil.js path. Net effect is the small overall -0.04%.

Copilot finished work on behalf of albe May 27, 2026 18:03
Copilot AI requested a review from albe May 27, 2026 18:03
@albe albe marked this pull request as ready for review May 27, 2026 18:11
@albe albe merged commit ca58e77 into main May 27, 2026
14 checks passed
@albe albe deleted the copilot/refactor-codebase-maintainability branch May 27, 2026 18:14
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.

3 participants