Skip to content

refactor: Split log-query into focused modules (#173) - #192

Merged
will-lamerton merged 1 commit into
mainfrom
refactor/log-query-split
Dec 21, 2025
Merged

will-lamerton merged 1 commit into
mainfrom
refactor/log-query-split

Conversation

@will-lamerton

Copy link
Copy Markdown
Member

Summary

Split the 911-line log-query.ts file into a well-organized directory structure with focused, single-responsibility modules. This is PR #3 in the series of refactorings to address issue #173.

Changes Made

Directory Structure

Created source/utils/logging/log-query/ with the following organization:

  • types.ts - All type definitions
  • storage/ - Storage implementation (circular buffer, indexing, main storage class)
  • query/ - Query execution and filtering
  • aggregation/ - Log aggregation and facet generation
  • utils/ - Sorting utilities and helper functions
  • index.ts - Public API re-exports

New Modules (12 total)

Storage (3 modules + tests)

  • circular-buffer.ts - O(1) circular buffer for log entries
  • index-manager.ts - Efficient indexing for lookups
  • log-storage.ts - Main storage class orchestrating buffer and indexes

Query (3 modules + tests)

  • filter-predicates.ts - Log entry filtering logic
  • query-engine.ts - Query execution engine
  • query-builder.ts - Fluent query builder API

Aggregation (2 modules + tests)

  • aggregator.ts - Log aggregation engine
  • facet-generator.ts - Facet generation for query results

Utils (2 modules + tests)

  • sorting.ts - Sorting utilities for log entries
  • helpers.ts - Common query helper functions

Bug Fixes

  • Fixed getLevelPriority returning incorrect value for 'fatal' level (changed from || to ?? operator to handle 0 correctly)
  • Fixed memory threshold filter semantics in filter predicates

Test Coverage

  • Added comprehensive test suites for all 12 new modules
  • 155 new tests added covering all functionality
  • ✅ All tests passing
  • ✅ No knip warnings
  • ✅ TypeScript strict mode passing
  • ✅ Biome linting passing

Breaking Changes

  • Import paths updated:
    • ./log-query.js → ./log-query/index.js
  • Removed unused exports from public API to clean up knip warnings
  • Deleted original log-query.ts and log-query.spec.ts files

Test plan

  • All existing tests pass
  • 155 new tests added and passing
  • Build succeeds
  • No knip warnings
  • TypeScript type checking passes
  • Biome linting passes
  • Application runs without errors

Split the 911-line log-query.ts file into a well-organized directory
structure with focused, single-responsibility modules. This is PR #3
in the series of refactorings to address issue #173.

## Changes

### Directory Structure
Created `source/utils/logging/log-query/` with the following organization:
- `types.ts` - All type definitions
- `storage/` - Storage implementation (circular buffer, indexing, main storage class)
- `query/` - Query execution and filtering
- `aggregation/` - Log aggregation and facet generation
- `utils/` - Sorting utilities and helper functions
- `index.ts` - Public API re-exports

### Modules Created
**Storage** (3 modules + tests):
- `circular-buffer.ts` - O(1) circular buffer for log entries
- `index-manager.ts` - Efficient indexing for lookups
- `log-storage.ts` - Main storage class orchestrating buffer and indexes

**Query** (3 modules + tests):
- `filter-predicates.ts` - Log entry filtering logic
- `query-engine.ts` - Query execution engine
- `query-builder.ts` - Fluent query builder API

**Aggregation** (2 modules + tests):
- `aggregator.ts` - Log aggregation engine
- `facet-generator.ts` - Facet generation for query results

**Utils** (2 modules + tests):
- `sorting.ts` - Sorting utilities for log entries
- `helpers.ts` - Common query helper functions

### Bug Fixes
- Fixed `getLevelPriority` returning incorrect value for 'fatal' level
  (changed from `||` to `??` operator to handle 0 correctly)
- Fixed memory threshold filter semantics in filter predicates

### Test Coverage
- Added comprehensive test suites for all 12 new modules
- 155 new tests added covering all functionality
- All tests passing

### Breaking Changes
- Import paths updated:
  - `./log-query.js` → `./log-query/index.js`
- Removed unused exports from public API to clean up knip warnings
- Deleted original `log-query.ts` and `log-query.spec.ts` files
@will-lamerton
will-lamerton merged commit ffccbdb into main Dec 21, 2025
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.

2 participants