Repository navigation
Health-data 1.0: TypeScript, results instead of silent zeros - #5
Merged
Merged
Conversation
- createHealthData(options) replaces the HealthDataService class; frozen, no state, injectable clock. - Every read returns HealthResult: ok with a value, or an error code (unsupported_platform, module_missing, unavailable, not_permitted, native_error) instead of 0, [] or null. - Android reads start Health Connect and check read access first; in 0.x reads before requestPermissions failed as CLIENT_NOT_INITIALIZED and came back as 0. - Same shapes on both platforms: named sleep stages, PermissionStatus (unknown on iOS), availability reasons, durationMinutes. - Built with react-native-builder-bob (CommonJS, ES modules, types, exports map); Metro platform split kept for iOS-only apps. - CI: lint, types, 100% coverage, publint, arethetypeswrong, and the six-package-manager consumer check with iOS and Android bundles. Co-Authored-By: Claude Opus 5 <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.
This is the 1.0 redesign that followed the critical review, using the same setup as scale-reference 1.0 (rn-scale-reference#3). Nothing is published yet, so this is the cheapest time to break the API.
Problems in 0.2.0 this fixes
0,[]ornull, so "no permission" read as "no steps"HealthResult<T>:{ok: true, value}or{ok: false, error: {code, message, cause?}}. Codes:unsupported_platform,module_missing,unavailable,not_permitted,native_error.requestPermissionscalledinitialize(), so reads before it in an app session were rejected withCLIENT_NOT_INITIALIZEDand came back as0initialize()and checks granted permissions first. Missing access isnot_permitted, and nothing is read.requestPermissionsreturned a HealthKit result, a Health Connect list ornull;getSleepDatareturned raw platform samplesPermissionStatus({known: true, granted, denied}on Android,{known: false, requested}on iOS, because HealthKit never reveals read access). Sleep stages use the same names on both platforms.falsefor every reason'available' | 'not_installed' | 'update_required' | 'unsupported_platform' | 'module_missing'new Date()in 8 placesnowoption, and every day-based method takes an optional dayHealthDataServicewithconsole.warn; ESM source that Node, default Jest and TypeScript could not loadcreateHealthData(options)returns a frozen client and logs nothing. TypeScript with the builder-bob dual build and anexportsmap.Kept from 0.x: calendar-day arithmetic (the daylight-saving fix from #4, with its tests ported), Health Connect aggregates for steps and water, paging, time asleep only with overlaps merged, and the Metro platform split so iOS-only apps don't need
react-native-health-connect. builder-bob keeps that import extensionless inlib/, which I checked in bob's source and in the build output.The full rename table is in
CHANGELOG.md. Peer ranges are now bounded:react-native-health ^1.19.0andreact-native-health-connect >=3.5.0 <5. The 4.0 release notes list only Expo packaging as breaking, and the APIs used here are unchanged.Quality gates
These are the same as scale-reference 1.0:
anyrules relaxed for Jest mocks only), Prettier andtscEurope/Londonreact-native, andgetAvailabilitymust answermodule_missing.How it was checked (locally)
ESLint, Prettier and
tscare clean. 51 tests pass at 100% statements, branches, functions and lines. They cover:From a clean copy (no
lib/):publint --strictpasses andattw --packfinds no problems (node10, node16 CJS, node16 ESM, bundler). The tarball allowlist passes on the 81-file package.The six-package-manager check found a real limit, now handled and documented:
requireworked with all six, but a plain-Nodeimportfailed withERR_MODULE_NOT_FOUNDon./healthConnect.healthConnect.ios.js, and Node's ES module loader can't do that.healthConnect.ios.jsand contains norequire("react-native-health-connect"), and the Android bundle does.require, and the ES module build is for bundlers.Consumer check, run locally against the packed tarball:
require, the iOS and Android esbuild bundles, a default-settings Jest project, and strict TypeScript innode16(CommonJS and ESM files) andbundlerresolution.require.For the app
The app uses the 0.x method names through
app/service/HealthDataService.js. After merge, an app PR will move that adapter to 1.0. The plan:requestPermissionson iOS before readingnot_permittedrather than a silent 0🤖 Generated with Claude Code