chore: single-source the smart-to-storage category map#935
Open
gorkem2020 wants to merge 1 commit into
Open
Conversation
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.
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.
Problem
The smart-to-storage category mapping is hand-maintained in two places: a switch in the extractor (
mapToStoreCategory) and theSMART_TO_STORAGE_CATEGORYobject inmemory-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 exportedSmartStorageCategorytype (type-only change, zero emitted-JS difference inmemory-categories). A comment documents thatreflectionis 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).