refactor(data): consolidate bundled-asset loading behind BundledAssetReader#5921
Merged
Conversation
…Reader
Each bundled JSON asset previously needed three near-identical pieces: a
1-method commonMain interface, an androidMain impl that copy-pasted the same
tolerant Json config + assets.open().decodeFromStream(), and a desktop Koin
stub returning empty. The Json {} config was duplicated 4x and the desktop
stub 4x.
Replace all of it with a single seam:
- BundledAssetReader { open(name): okio.Source? } + a generic reified
decode<T>() extension (kotlinx-serialization-json-okio).
- AndroidBundledAssetReader serves assets/, returns null if absent.
- Desktop/non-Android gets one BundledAssetReader { null }.
- Repositories inject BundledAssetReader + the existing shared tolerant Json
@single (core:network), instead of per-asset datasources.
Deletes 4 interfaces + 4 androidMain impls + 4 desktop stubs (and 3 redundant
Json copies). Behavior-preserving: tolerant parse, seed-then-SWR, desktop
yields empty, bootloader quirks still swallow errors to empty.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Why
Every bundled JSON asset in
androidApp/src/main/assets/needed three near-identical pieces: a 1-method commonMain*JsonDataSourceinterface, an androidMain impl that copy-pasted the same tolerantJson {}config +assets.open(...).decodeFromStream(...), and a desktop Koin stub returning empty. With 4 assets today (device_hardware,device_links,firmware_releases,device_bootloader_ota_quirks), theJson {}config was duplicated 4× and the desktop stub 4×, and each interface existed only so desktop could stub it.This lands the DRY cleanup before wiring the upcoming event-firmware metadata API (a 5th consumer) so that work builds on the consolidated helper instead of adding a 5th copy.
🛠️ Changes
Replaces all of it with a single seam:
BundledAssetReader(commonMain) —fun interface { open(name): okio.Source? };null= asset absent. Plus a genericinline fun <reified T> decode(name, json): T?viakotlinx-serialization-json-okio.AndroidBundledAssetReader(androidMain,@Single) — servesassets/, returnsnullif the asset is missing.BundledAssetReader { null }, replacing the 4 per-asset stubs.BundledAssetReader+ the existing shared tolerantJson@Single(fromcore:network), instead of per-asset datasources — no newJsonbean.BootloaderOtaQuirksResponseenvelope tocore:model(was a private wrapper in the deleted impl).🧹 Cleanup
Deletes 4
*JsonDataSourceinterfaces + 4 androidMain impls + 4 desktop stubs + 3 redundantJsoncopies. +115 / −294 (net −179).Behavior
Behavior-preserving: tolerant parsing (
ignoreUnknownKeys/isLenient), repositories still seed Room from the bundled asset then stale-while-revalidate, desktop/non-Android still yields empty (no asset access), and the bootloader-quirks loader still swallows errors → empty.Notes:
decode()uses explicit try/finally rather than.use {}— okio'sSourcedoesn't extendAutoCloseablein commonMain (would break the iOS target).🧪 Testing Performed
DeviceLinkRepositoryImplTestmigrated to a fakeBundledAssetReaderthat serializes through the realdecode()path.spotlessApply spotlessCheck detekt assembleDebug test allTests kmpSmokeCompile— BUILD SUCCESSFUL.🤖 Generated with Claude Code