Skip to content

Refactor shared storage/filtering boundaries and introduce typed runtime messaging API#103

Merged
danielchalmers merged 3 commits into
mainfrom
copilot/split-shared-storage
May 29, 2026
Merged

Refactor shared storage/filtering boundaries and introduce typed runtime messaging API#103
danielchalmers merged 3 commits into
mainfrom
copilot/split-shared-storage

Conversation

Copilot AI commented May 29, 2026

Copy link
Copy Markdown
Contributor

This PR reduces cross-cutting complexity in shared storage and filtering by splitting broad modules into focused units while preserving existing runtime semantics (rules version bumping, filter precedence, snooze behavior). It also centralizes extension messaging calls behind a typed API and removes unused message protocol surface.

  • Storage decomposition (src/shared/storage/*)

    • Extracted defaults, guards, normalization, and import/export parsing/validation into dedicated modules:
      • defaults.ts: createDefaultGroup, createDefaultData
      • guards.ts: object/schema guards for groups, filters, whitelist, schedules, snooze
      • normalize.ts: legacy compatibility + normalizeStoredData
      • importExport.ts: serializeDataForExport, parseImportedData, duplicate ID checks, group reference checks, regex validation
    • Kept src/shared/api/storage.ts as the public repository API.
    • Added internal updateData(updater) helper and migrated CRUD methods to a single load/transform/save path.
  • Filtering runtime consolidation (src/shared/filtering/*)

    • Split filtering concerns into:
      • patterns.ts: pattern matching + regex helpers
      • schedules.ts: schedule/snooze/effective-state helpers
      • engine.ts: createFilteringEngine + evaluateFilterDecision
    • Shifted runtime decisioning to the filtering engine path and migrated legacy test expectations to engine-based assertions.
    • Preserved existing semantics around temporary filters, whitelist override behavior, hard-block precedence over warnings, and snooze short-circuiting.
    • Updated src/shared/utils/index.ts and compatibility re-exports to avoid consumer breakage.
  • Typed runtime messaging API

    • Added src/shared/api/messaging.ts:
      export async function sendExtensionMessage<T extends ExtensionMessage>(
        message: T
      ): Promise<MessageResponse<T>> {
        return (await chrome.runtime.sendMessage(message)) as MessageResponse<T>;
      }
    • Replaced raw chrome.runtime.sendMessage casts in blocked/popup flows with sendExtensionMessage.
    • Removed unused DATA_UPDATED and URL_BLOCKED message types/guards from protocol definitions and aligned message guard tests.

Copilot AI changed the title Refactor shared storage, filtering, and messaging APIs Refactor shared storage/filtering boundaries and introduce typed runtime messaging API May 29, 2026
Copilot AI requested a review from danielchalmers May 29, 2026 00:42
@danielchalmers danielchalmers marked this pull request as ready for review May 29, 2026 03:29
@danielchalmers danielchalmers merged commit 0a3dc2d into main May 29, 2026
7 of 8 checks passed
@danielchalmers danielchalmers deleted the copilot/split-shared-storage branch May 29, 2026 03:34
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