Skip to content

chore: single-source the smart-to-storage category map#935

Open
gorkem2020 wants to merge 1 commit into
CortexReach:masterfrom
gorkem2020:chore/single-source-category-map
Open

chore: single-source the smart-to-storage category map#935
gorkem2020 wants to merge 1 commit into
CortexReach:masterfrom
gorkem2020:chore/single-source-category-map

Conversation

@gorkem2020

Copy link
Copy Markdown
Contributor

Problem

The smart-to-storage category mapping is hand-maintained in two places: a switch in the extractor (mapToStoreCategory) and the SMART_TO_STORAGE_CATEGORY object in memory-categories. The two currently agree, but nothing keeps them agreeing.

Fix

The extractor delegates to the shared map (getStorageCategoryForMemoryCategory(category) ?? "other"), preserving the old switch's defensive default for untyped runtime callers. To keep the delegation type-safe without a cast, the shared getter's return type is tightened via a new exported SmartStorageCategory type (type-only change, zero emitted-JS difference in memory-categories). A comment documents that reflection is minted only by the reflection writer and is deliberately absent from this map.

Byte-identical mapping behavior; no schema or store-format change.

Tests

Existing suites pass unchanged (the mapping itself is pinned by the extractor tests).

mapToStoreCategory duplicated the SMART_TO_STORAGE_CATEGORY mapping in
memory-categories as a hand-maintained switch. Delegate to the shared
constant via getStorageCategoryForMemoryCategory, whose return type is
tightened (type-only) to the storage categories smart registers can
actually map onto: reflection is minted only by the reflection writer
and is deliberately absent from this map. The old switch's defensive
default arm is preserved for non-union values arriving from untyped
callers at runtime. Byte-identical mapping, one source of truth.
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.

1 participant