@kingstinct/react-native-healthkit 8.7.2 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ReactNativeHealthkit.podspec +36 -0
- package/app.plugin.js +43 -33
- package/ios/Bridge.h +8 -0
- package/ios/CategoryTypeModule.swift +128 -0
- package/ios/CharacteristicTypeModule.swift +78 -0
- package/ios/Constants.swift +2 -0
- package/ios/CoreModule.swift +376 -0
- package/ios/CorrelationTypeModule.swift +153 -0
- package/ios/HeartbeatSeriesModule.swift +189 -0
- package/ios/Helpers.swift +529 -251
- package/ios/QuantityTypeModule.swift +461 -0
- package/ios/Serializers.swift +211 -124
- package/ios/SourceProxy.swift +35 -0
- package/ios/StateOfMindModule.swift +160 -0
- package/ios/WorkoutProxy.swift +405 -0
- package/ios/WorkoutSessionModule.swift +182 -0
- package/ios/WorkoutsModule.swift +357 -0
- package/package.json +43 -127
- package/react-native.config.js +16 -0
- package/src/hooks/useHealthkitAuthorization.test.ts +47 -29
- package/src/hooks/useHealthkitAuthorization.ts +21 -15
- package/src/hooks/useIsHealthDataAvailable.test.ts +17 -7
- package/src/hooks/useIsHealthDataAvailable.ts +7 -7
- package/src/hooks/useMostRecentCategorySample.ts +10 -12
- package/src/hooks/useMostRecentQuantitySample.ts +17 -36
- package/src/hooks/useMostRecentWorkout.ts +16 -38
- package/src/hooks/useSources.ts +8 -12
- package/src/hooks/useStatisticsForQuantity.ts +19 -14
- package/src/hooks/useSubscribeToChanges.ts +9 -13
- package/src/index.ios.ts +232 -0
- package/src/index.ts +444 -0
- package/src/modules.ts +43 -0
- package/src/specs/CategoryTypeModule.nitro.ts +64 -0
- package/src/specs/CharacteristicTypeModule.nitro.ts +22 -0
- package/src/specs/CoreModule.nitro.ts +107 -0
- package/src/specs/CorrelationTypeModule.nitro.ts +23 -0
- package/src/specs/HeartbeatSeriesModule.nitro.ts +19 -0
- package/src/specs/QuantityTypeModule.nitro.ts +60 -0
- package/src/specs/SourceProxy.nitro.ts +13 -0
- package/src/specs/StateOfMindModule.nitro.ts +23 -0
- package/src/specs/WorkoutProxy.nitro.ts +18 -0
- package/src/specs/WorkoutSessionModule.nitro.ts +71 -0
- package/src/specs/WorkoutsModule.nitro.ts +32 -0
- package/src/test-setup.ts +68 -54
- package/src/test-utils.ts +3 -2
- package/src/types/Auth.ts +17 -0
- package/src/types/Background.ts +9 -0
- package/src/types/CategoryType.ts +249 -0
- package/src/types/CategoryTypeIdentifier.ts +99 -0
- package/src/types/Characteristics.ts +53 -0
- package/src/types/Constants.ts +25 -0
- package/src/types/CorrelationType.ts +31 -0
- package/src/types/Device.ts +13 -0
- package/src/types/HeartbeatSeries.ts +29 -0
- package/src/types/InterfaceVerification.ts +164 -0
- package/src/types/InterfaceVerificationExample.ts +89 -0
- package/src/types/QuantitySample.ts +30 -0
- package/src/types/QuantityType.ts +192 -0
- package/src/types/QuantityTypeIdentifier.ts +758 -0
- package/src/types/QueryOptions.ts +69 -0
- package/src/types/README-InterfaceVerification.md +103 -0
- package/src/types/Shared.ts +79 -0
- package/src/types/Source.ts +11 -0
- package/src/types/StateOfMind.ts +110 -0
- package/src/types/Subscriptons.ts +10 -0
- package/src/types/Units.ts +190 -0
- package/src/types/WeatherCondition.ts +31 -0
- package/src/types/WorkoutKit.ts +18 -0
- package/src/types/Workouts.ts +282 -0
- package/src/utils/getMostRecentCategorySample.ts +7 -11
- package/src/utils/getMostRecentQuantitySample.ts +8 -18
- package/src/utils/getMostRecentWorkout.ts +7 -17
- package/src/utils/getPreferredUnit.ts +12 -8
- package/src/utils/subscribeToChanges.ts +9 -26
- package/LICENSE +0 -21
- package/README.md +0 -179
- package/ios/ReactNativeHealthkit-Bridging-Header.h +0 -2
- package/ios/ReactNativeHealthkit.m +0 -271
- package/ios/ReactNativeHealthkit.swift +0 -2333
- package/ios/ReactNativeHealthkit.xcodeproj/project.pbxproj +0 -279
- package/kingstinct-react-native-healthkit.podspec +0 -21
- package/lib/commonjs/hooks/useHealthkitAuthorization.js +0 -39
- package/lib/commonjs/hooks/useHealthkitAuthorization.js.map +0 -1
- package/lib/commonjs/hooks/useHealthkitAuthorization.test.js +0 -72
- package/lib/commonjs/hooks/useHealthkitAuthorization.test.js.map +0 -1
- package/lib/commonjs/hooks/useIsHealthDataAvailable.js +0 -27
- package/lib/commonjs/hooks/useIsHealthDataAvailable.js.map +0 -1
- package/lib/commonjs/hooks/useIsHealthDataAvailable.test.js +0 -41
- package/lib/commonjs/hooks/useIsHealthDataAvailable.test.js.map +0 -1
- package/lib/commonjs/hooks/useMostRecentCategorySample.js +0 -23
- package/lib/commonjs/hooks/useMostRecentCategorySample.js.map +0 -1
- package/lib/commonjs/hooks/useMostRecentQuantitySample.js +0 -37
- package/lib/commonjs/hooks/useMostRecentQuantitySample.js.map +0 -1
- package/lib/commonjs/hooks/useMostRecentWorkout.js +0 -48
- package/lib/commonjs/hooks/useMostRecentWorkout.js.map +0 -1
- package/lib/commonjs/hooks/useSources.js +0 -22
- package/lib/commonjs/hooks/useSources.js.map +0 -1
- package/lib/commonjs/hooks/useStatisticsForQuantity.js +0 -28
- package/lib/commonjs/hooks/useStatisticsForQuantity.js.map +0 -1
- package/lib/commonjs/hooks/useSubscribeToChanges.js +0 -28
- package/lib/commonjs/hooks/useSubscribeToChanges.js.map +0 -1
- package/lib/commonjs/index.ios.js +0 -531
- package/lib/commonjs/index.ios.js.map +0 -1
- package/lib/commonjs/index.js +0 -22
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/index.native.js +0 -235
- package/lib/commonjs/index.native.js.map +0 -1
- package/lib/commonjs/index.web.js +0 -22
- package/lib/commonjs/index.web.js.map +0 -1
- package/lib/commonjs/native-types.js +0 -1575
- package/lib/commonjs/native-types.js.map +0 -1
- package/lib/commonjs/test-setup.js +0 -57
- package/lib/commonjs/test-setup.js.map +0 -1
- package/lib/commonjs/test-utils.js +0 -18
- package/lib/commonjs/test-utils.js.map +0 -1
- package/lib/commonjs/types.js +0 -17
- package/lib/commonjs/types.js.map +0 -1
- package/lib/commonjs/utils/deleteQuantitySample.js +0 -11
- package/lib/commonjs/utils/deleteQuantitySample.js.map +0 -1
- package/lib/commonjs/utils/deleteSamples.js +0 -18
- package/lib/commonjs/utils/deleteSamples.js.map +0 -1
- package/lib/commonjs/utils/deleteWorkoutSample.js +0 -11
- package/lib/commonjs/utils/deleteWorkoutSample.js.map +0 -1
- package/lib/commonjs/utils/deserializeCategorySample.js +0 -13
- package/lib/commonjs/utils/deserializeCategorySample.js.map +0 -1
- package/lib/commonjs/utils/deserializeCategorySample.test.js +0 -26
- package/lib/commonjs/utils/deserializeCategorySample.test.js.map +0 -1
- package/lib/commonjs/utils/deserializeCorrelation.js +0 -26
- package/lib/commonjs/utils/deserializeCorrelation.js.map +0 -1
- package/lib/commonjs/utils/deserializeHeartbeatSeriesSample.js +0 -15
- package/lib/commonjs/utils/deserializeHeartbeatSeriesSample.js.map +0 -1
- package/lib/commonjs/utils/deserializeSample.js +0 -15
- package/lib/commonjs/utils/deserializeSample.js.map +0 -1
- package/lib/commonjs/utils/deserializeWorkout.js +0 -15
- package/lib/commonjs/utils/deserializeWorkout.js.map +0 -1
- package/lib/commonjs/utils/ensureMetadata.js +0 -11
- package/lib/commonjs/utils/ensureMetadata.js.map +0 -1
- package/lib/commonjs/utils/ensureTotals.js +0 -11
- package/lib/commonjs/utils/ensureTotals.js.map +0 -1
- package/lib/commonjs/utils/ensureUnit.js +0 -17
- package/lib/commonjs/utils/ensureUnit.js.map +0 -1
- package/lib/commonjs/utils/getDateOfBirth.js +0 -14
- package/lib/commonjs/utils/getDateOfBirth.js.map +0 -1
- package/lib/commonjs/utils/getMostRecentCategorySample.js +0 -17
- package/lib/commonjs/utils/getMostRecentCategorySample.js.map +0 -1
- package/lib/commonjs/utils/getMostRecentQuantitySample.js +0 -21
- package/lib/commonjs/utils/getMostRecentQuantitySample.js.map +0 -1
- package/lib/commonjs/utils/getMostRecentWorkout.js +0 -19
- package/lib/commonjs/utils/getMostRecentWorkout.js.map +0 -1
- package/lib/commonjs/utils/getPreferredUnit.js +0 -14
- package/lib/commonjs/utils/getPreferredUnit.js.map +0 -1
- package/lib/commonjs/utils/getPreferredUnits.js +0 -14
- package/lib/commonjs/utils/getPreferredUnits.js.map +0 -1
- package/lib/commonjs/utils/getPreferredUnitsTyped.js +0 -33
- package/lib/commonjs/utils/getPreferredUnitsTyped.js.map +0 -1
- package/lib/commonjs/utils/getRequestStatusForAuthorization.js +0 -21
- package/lib/commonjs/utils/getRequestStatusForAuthorization.js.map +0 -1
- package/lib/commonjs/utils/getWorkoutPlanById.js +0 -13
- package/lib/commonjs/utils/getWorkoutPlanById.js.map +0 -1
- package/lib/commonjs/utils/prepareOptions.js +0 -25
- package/lib/commonjs/utils/prepareOptions.js.map +0 -1
- package/lib/commonjs/utils/queryCategorySamples.js +0 -17
- package/lib/commonjs/utils/queryCategorySamples.js.map +0 -1
- package/lib/commonjs/utils/queryCategorySamplesWithAnchor.js +0 -21
- package/lib/commonjs/utils/queryCategorySamplesWithAnchor.js.map +0 -1
- package/lib/commonjs/utils/queryCorrelationSamples.js +0 -17
- package/lib/commonjs/utils/queryCorrelationSamples.js.map +0 -1
- package/lib/commonjs/utils/queryHeartbeatSeriesSamples.js +0 -17
- package/lib/commonjs/utils/queryHeartbeatSeriesSamples.js.map +0 -1
- package/lib/commonjs/utils/queryHeartbeatSeriesSamplesWithAnchor.js +0 -21
- package/lib/commonjs/utils/queryHeartbeatSeriesSamplesWithAnchor.js.map +0 -1
- package/lib/commonjs/utils/queryQuantitySamples.js +0 -19
- package/lib/commonjs/utils/queryQuantitySamples.js.map +0 -1
- package/lib/commonjs/utils/queryQuantitySamplesWithAnchor.js +0 -23
- package/lib/commonjs/utils/queryQuantitySamplesWithAnchor.js.map +0 -1
- package/lib/commonjs/utils/querySources.js +0 -14
- package/lib/commonjs/utils/querySources.js.map +0 -1
- package/lib/commonjs/utils/queryStateOfMindSamples.js +0 -22
- package/lib/commonjs/utils/queryStateOfMindSamples.js.map +0 -1
- package/lib/commonjs/utils/queryStatisticsCollectionForQuantity.js +0 -16
- package/lib/commonjs/utils/queryStatisticsCollectionForQuantity.js.map +0 -1
- package/lib/commonjs/utils/queryStatisticsForQuantity.js +0 -29
- package/lib/commonjs/utils/queryStatisticsForQuantity.js.map +0 -1
- package/lib/commonjs/utils/queryWorkoutSamplesWithAnchor.js +0 -26
- package/lib/commonjs/utils/queryWorkoutSamplesWithAnchor.js.map +0 -1
- package/lib/commonjs/utils/queryWorkouts.js +0 -22
- package/lib/commonjs/utils/queryWorkouts.js.map +0 -1
- package/lib/commonjs/utils/requestAuthorization.js +0 -22
- package/lib/commonjs/utils/requestAuthorization.js.map +0 -1
- package/lib/commonjs/utils/saveCategorySample.js +0 -20
- package/lib/commonjs/utils/saveCategorySample.js.map +0 -1
- package/lib/commonjs/utils/saveCorrelationSample.js +0 -35
- package/lib/commonjs/utils/saveCorrelationSample.js.map +0 -1
- package/lib/commonjs/utils/saveQuantitySample.js +0 -16
- package/lib/commonjs/utils/saveQuantitySample.js.map +0 -1
- package/lib/commonjs/utils/saveStateOfMindSample.js +0 -17
- package/lib/commonjs/utils/saveStateOfMindSample.js.map +0 -1
- package/lib/commonjs/utils/saveWorkoutRoute.js +0 -26
- package/lib/commonjs/utils/saveWorkoutRoute.js.map +0 -1
- package/lib/commonjs/utils/saveWorkoutSample.js +0 -36
- package/lib/commonjs/utils/saveWorkoutSample.js.map +0 -1
- package/lib/commonjs/utils/serializeDate.js +0 -9
- package/lib/commonjs/utils/serializeDate.js.map +0 -1
- package/lib/commonjs/utils/serializeDate.test.js +0 -17
- package/lib/commonjs/utils/serializeDate.test.js.map +0 -1
- package/lib/commonjs/utils/startWatchApp.js +0 -11
- package/lib/commonjs/utils/startWatchApp.js.map +0 -1
- package/lib/commonjs/utils/subscribeToChanges.js +0 -27
- package/lib/commonjs/utils/subscribeToChanges.js.map +0 -1
- package/lib/module/hooks/useHealthkitAuthorization.js +0 -32
- package/lib/module/hooks/useHealthkitAuthorization.js.map +0 -1
- package/lib/module/hooks/useHealthkitAuthorization.test.js +0 -68
- package/lib/module/hooks/useHealthkitAuthorization.test.js.map +0 -1
- package/lib/module/hooks/useIsHealthDataAvailable.js +0 -21
- package/lib/module/hooks/useIsHealthDataAvailable.js.map +0 -1
- package/lib/module/hooks/useIsHealthDataAvailable.test.js +0 -37
- package/lib/module/hooks/useIsHealthDataAvailable.test.js.map +0 -1
- package/lib/module/hooks/useMostRecentCategorySample.js +0 -16
- package/lib/module/hooks/useMostRecentCategorySample.js.map +0 -1
- package/lib/module/hooks/useMostRecentQuantitySample.js +0 -30
- package/lib/module/hooks/useMostRecentQuantitySample.js.map +0 -1
- package/lib/module/hooks/useMostRecentWorkout.js +0 -41
- package/lib/module/hooks/useMostRecentWorkout.js.map +0 -1
- package/lib/module/hooks/useSources.js +0 -15
- package/lib/module/hooks/useSources.js.map +0 -1
- package/lib/module/hooks/useStatisticsForQuantity.js +0 -21
- package/lib/module/hooks/useStatisticsForQuantity.js.map +0 -1
- package/lib/module/hooks/useSubscribeToChanges.js +0 -21
- package/lib/module/hooks/useSubscribeToChanges.js.map +0 -1
- package/lib/module/index.ios.js +0 -209
- package/lib/module/index.ios.js.map +0 -1
- package/lib/module/index.js +0 -4
- package/lib/module/index.js.map +0 -1
- package/lib/module/index.native.js +0 -160
- package/lib/module/index.native.js.map +0 -1
- package/lib/module/index.web.js +0 -4
- package/lib/module/index.web.js.map +0 -1
- package/lib/module/native-types.js +0 -1606
- package/lib/module/native-types.js.map +0 -1
- package/lib/module/test-setup.js +0 -54
- package/lib/module/test-setup.js.map +0 -1
- package/lib/module/test-utils.js +0 -11
- package/lib/module/test-utils.js.map +0 -1
- package/lib/module/types.js +0 -67
- package/lib/module/types.js.map +0 -1
- package/lib/module/utils/deleteQuantitySample.js +0 -4
- package/lib/module/utils/deleteQuantitySample.js.map +0 -1
- package/lib/module/utils/deleteSamples.js +0 -11
- package/lib/module/utils/deleteSamples.js.map +0 -1
- package/lib/module/utils/deleteWorkoutSample.js +0 -4
- package/lib/module/utils/deleteWorkoutSample.js.map +0 -1
- package/lib/module/utils/deserializeCategorySample.js +0 -7
- package/lib/module/utils/deserializeCategorySample.js.map +0 -1
- package/lib/module/utils/deserializeCategorySample.test.js +0 -22
- package/lib/module/utils/deserializeCategorySample.test.js.map +0 -1
- package/lib/module/utils/deserializeCorrelation.js +0 -19
- package/lib/module/utils/deserializeCorrelation.js.map +0 -1
- package/lib/module/utils/deserializeHeartbeatSeriesSample.js +0 -9
- package/lib/module/utils/deserializeHeartbeatSeriesSample.js.map +0 -1
- package/lib/module/utils/deserializeSample.js +0 -9
- package/lib/module/utils/deserializeSample.js.map +0 -1
- package/lib/module/utils/deserializeWorkout.js +0 -9
- package/lib/module/utils/deserializeWorkout.js.map +0 -1
- package/lib/module/utils/ensureMetadata.js +0 -5
- package/lib/module/utils/ensureMetadata.js.map +0 -1
- package/lib/module/utils/ensureTotals.js +0 -5
- package/lib/module/utils/ensureTotals.js.map +0 -1
- package/lib/module/utils/ensureUnit.js +0 -10
- package/lib/module/utils/ensureUnit.js.map +0 -1
- package/lib/module/utils/getDateOfBirth.js +0 -7
- package/lib/module/utils/getDateOfBirth.js.map +0 -1
- package/lib/module/utils/getMostRecentCategorySample.js +0 -10
- package/lib/module/utils/getMostRecentCategorySample.js.map +0 -1
- package/lib/module/utils/getMostRecentQuantitySample.js +0 -14
- package/lib/module/utils/getMostRecentQuantitySample.js.map +0 -1
- package/lib/module/utils/getMostRecentWorkout.js +0 -12
- package/lib/module/utils/getMostRecentWorkout.js.map +0 -1
- package/lib/module/utils/getPreferredUnit.js +0 -7
- package/lib/module/utils/getPreferredUnit.js.map +0 -1
- package/lib/module/utils/getPreferredUnits.js +0 -7
- package/lib/module/utils/getPreferredUnits.js.map +0 -1
- package/lib/module/utils/getPreferredUnitsTyped.js +0 -26
- package/lib/module/utils/getPreferredUnitsTyped.js.map +0 -1
- package/lib/module/utils/getRequestStatusForAuthorization.js +0 -14
- package/lib/module/utils/getRequestStatusForAuthorization.js.map +0 -1
- package/lib/module/utils/getWorkoutPlanById.js +0 -6
- package/lib/module/utils/getWorkoutPlanById.js.map +0 -1
- package/lib/module/utils/prepareOptions.js +0 -18
- package/lib/module/utils/prepareOptions.js.map +0 -1
- package/lib/module/utils/queryCategorySamples.js +0 -10
- package/lib/module/utils/queryCategorySamples.js.map +0 -1
- package/lib/module/utils/queryCategorySamplesWithAnchor.js +0 -14
- package/lib/module/utils/queryCategorySamplesWithAnchor.js.map +0 -1
- package/lib/module/utils/queryCorrelationSamples.js +0 -10
- package/lib/module/utils/queryCorrelationSamples.js.map +0 -1
- package/lib/module/utils/queryHeartbeatSeriesSamples.js +0 -10
- package/lib/module/utils/queryHeartbeatSeriesSamples.js.map +0 -1
- package/lib/module/utils/queryHeartbeatSeriesSamplesWithAnchor.js +0 -14
- package/lib/module/utils/queryHeartbeatSeriesSamplesWithAnchor.js.map +0 -1
- package/lib/module/utils/queryQuantitySamples.js +0 -12
- package/lib/module/utils/queryQuantitySamples.js.map +0 -1
- package/lib/module/utils/queryQuantitySamplesWithAnchor.js +0 -16
- package/lib/module/utils/queryQuantitySamplesWithAnchor.js.map +0 -1
- package/lib/module/utils/querySources.js +0 -7
- package/lib/module/utils/querySources.js.map +0 -1
- package/lib/module/utils/queryStateOfMindSamples.js +0 -14
- package/lib/module/utils/queryStateOfMindSamples.js.map +0 -1
- package/lib/module/utils/queryStatisticsCollectionForQuantity.js +0 -9
- package/lib/module/utils/queryStatisticsCollectionForQuantity.js.map +0 -1
- package/lib/module/utils/queryStatisticsForQuantity.js +0 -22
- package/lib/module/utils/queryStatisticsForQuantity.js.map +0 -1
- package/lib/module/utils/queryWorkoutSamplesWithAnchor.js +0 -19
- package/lib/module/utils/queryWorkoutSamplesWithAnchor.js.map +0 -1
- package/lib/module/utils/queryWorkouts.js +0 -15
- package/lib/module/utils/queryWorkouts.js.map +0 -1
- package/lib/module/utils/requestAuthorization.js +0 -15
- package/lib/module/utils/requestAuthorization.js.map +0 -1
- package/lib/module/utils/saveCategorySample.js +0 -13
- package/lib/module/utils/saveCategorySample.js.map +0 -1
- package/lib/module/utils/saveCorrelationSample.js +0 -28
- package/lib/module/utils/saveCorrelationSample.js.map +0 -1
- package/lib/module/utils/saveQuantitySample.js +0 -9
- package/lib/module/utils/saveQuantitySample.js.map +0 -1
- package/lib/module/utils/saveStateOfMindSample.js +0 -10
- package/lib/module/utils/saveStateOfMindSample.js.map +0 -1
- package/lib/module/utils/saveWorkoutRoute.js +0 -19
- package/lib/module/utils/saveWorkoutRoute.js.map +0 -1
- package/lib/module/utils/saveWorkoutSample.js +0 -29
- package/lib/module/utils/saveWorkoutSample.js.map +0 -1
- package/lib/module/utils/serializeDate.js +0 -3
- package/lib/module/utils/serializeDate.js.map +0 -1
- package/lib/module/utils/serializeDate.test.js +0 -14
- package/lib/module/utils/serializeDate.test.js.map +0 -1
- package/lib/module/utils/startWatchApp.js +0 -4
- package/lib/module/utils/startWatchApp.js.map +0 -1
- package/lib/module/utils/subscribeToChanges.js +0 -20
- package/lib/module/utils/subscribeToChanges.js.map +0 -1
- package/lib/typescript/example-expo/App.d.ts +0 -2
- package/lib/typescript/src/hooks/useHealthkitAuthorization.d.ts +0 -8
- package/lib/typescript/src/hooks/useHealthkitAuthorization.test.d.ts +0 -1
- package/lib/typescript/src/hooks/useIsHealthDataAvailable.d.ts +0 -7
- package/lib/typescript/src/hooks/useIsHealthDataAvailable.test.d.ts +0 -1
- package/lib/typescript/src/hooks/useMostRecentCategorySample.d.ts +0 -7
- package/lib/typescript/src/hooks/useMostRecentQuantitySample.d.ts +0 -7
- package/lib/typescript/src/hooks/useMostRecentWorkout.d.ts +0 -10
- package/lib/typescript/src/hooks/useSources.d.ts +0 -3
- package/lib/typescript/src/hooks/useStatisticsForQuantity.d.ts +0 -4
- package/lib/typescript/src/hooks/useSubscribeToChanges.d.ts +0 -3
- package/lib/typescript/src/index.d.ts +0 -3
- package/lib/typescript/src/index.ios.d.ts +0 -198
- package/lib/typescript/src/index.native.d.ts +0 -41
- package/lib/typescript/src/index.web.d.ts +0 -3
- package/lib/typescript/src/native-types.d.ts +0 -1764
- package/lib/typescript/src/test-setup.d.ts +0 -1
- package/lib/typescript/src/test-utils.d.ts +0 -2
- package/lib/typescript/src/types.d.ts +0 -111
- package/lib/typescript/src/utils/deleteQuantitySample.d.ts +0 -4
- package/lib/typescript/src/utils/deleteSamples.d.ts +0 -8
- package/lib/typescript/src/utils/deleteWorkoutSample.d.ts +0 -3
- package/lib/typescript/src/utils/deserializeCategorySample.d.ts +0 -4
- package/lib/typescript/src/utils/deserializeCategorySample.test.d.ts +0 -1
- package/lib/typescript/src/utils/deserializeCorrelation.d.ts +0 -4
- package/lib/typescript/src/utils/deserializeHeartbeatSeriesSample.d.ts +0 -4
- package/lib/typescript/src/utils/deserializeSample.d.ts +0 -4
- package/lib/typescript/src/utils/deserializeWorkout.d.ts +0 -4
- package/lib/typescript/src/utils/ensureMetadata.d.ts +0 -2
- package/lib/typescript/src/utils/ensureTotals.d.ts +0 -2
- package/lib/typescript/src/utils/ensureUnit.d.ts +0 -3
- package/lib/typescript/src/utils/getDateOfBirth.d.ts +0 -2
- package/lib/typescript/src/utils/getMostRecentCategorySample.d.ts +0 -4
- package/lib/typescript/src/utils/getMostRecentQuantitySample.d.ts +0 -4
- package/lib/typescript/src/utils/getMostRecentWorkout.d.ts +0 -5
- package/lib/typescript/src/utils/getPreferredUnit.d.ts +0 -4
- package/lib/typescript/src/utils/getPreferredUnits.d.ts +0 -4
- package/lib/typescript/src/utils/getPreferredUnitsTyped.d.ts +0 -9
- package/lib/typescript/src/utils/getRequestStatusForAuthorization.d.ts +0 -3
- package/lib/typescript/src/utils/getWorkoutPlanById.d.ts +0 -5
- package/lib/typescript/src/utils/prepareOptions.d.ts +0 -9
- package/lib/typescript/src/utils/queryCategorySamples.d.ts +0 -5
- package/lib/typescript/src/utils/queryCategorySamplesWithAnchor.d.ts +0 -10
- package/lib/typescript/src/utils/queryCorrelationSamples.d.ts +0 -5
- package/lib/typescript/src/utils/queryHeartbeatSeriesSamples.d.ts +0 -10
- package/lib/typescript/src/utils/queryHeartbeatSeriesSamplesWithAnchor.d.ts +0 -10
- package/lib/typescript/src/utils/queryQuantitySamples.d.ts +0 -7
- package/lib/typescript/src/utils/queryQuantitySamplesWithAnchor.d.ts +0 -12
- package/lib/typescript/src/utils/querySources.d.ts +0 -4
- package/lib/typescript/src/utils/queryStateOfMindSamples.d.ts +0 -7
- package/lib/typescript/src/utils/queryStatisticsCollectionForQuantity.d.ts +0 -3
- package/lib/typescript/src/utils/queryStatisticsForQuantity.d.ts +0 -14
- package/lib/typescript/src/utils/queryWorkoutSamplesWithAnchor.d.ts +0 -9
- package/lib/typescript/src/utils/queryWorkouts.d.ts +0 -4
- package/lib/typescript/src/utils/requestAuthorization.d.ts +0 -4
- package/lib/typescript/src/utils/saveCategorySample.d.ts +0 -11
- package/lib/typescript/src/utils/saveCorrelationSample.d.ts +0 -8
- package/lib/typescript/src/utils/saveQuantitySample.d.ts +0 -7
- package/lib/typescript/src/utils/saveStateOfMindSample.d.ts +0 -11
- package/lib/typescript/src/utils/saveWorkoutRoute.d.ts +0 -3
- package/lib/typescript/src/utils/saveWorkoutSample.d.ts +0 -11
- package/lib/typescript/src/utils/serializeDate.d.ts +0 -2
- package/lib/typescript/src/utils/serializeDate.test.d.ts +0 -1
- package/lib/typescript/src/utils/startWatchApp.d.ts +0 -3
- package/lib/typescript/src/utils/subscribeToChanges.d.ts +0 -3
- package/src/index.ios.tsx +0 -292
- package/src/index.native.tsx +0 -233
- package/src/index.tsx +0 -5
- package/src/index.web.tsx +0 -5
- package/src/native-types.ts +0 -2471
- package/src/types.ts +0 -156
- package/src/utils/deleteQuantitySample.ts +0 -14
- package/src/utils/deleteSamples.ts +0 -23
- package/src/utils/deleteWorkoutSample.ts +0 -7
- package/src/utils/deserializeCategorySample.test.ts +0 -24
- package/src/utils/deserializeCategorySample.ts +0 -12
- package/src/utils/deserializeCorrelation.ts +0 -28
- package/src/utils/deserializeHeartbeatSeriesSample.ts +0 -12
- package/src/utils/deserializeSample.ts +0 -17
- package/src/utils/deserializeWorkout.ts +0 -14
- package/src/utils/ensureMetadata.ts +0 -5
- package/src/utils/ensureTotals.ts +0 -5
- package/src/utils/ensureUnit.ts +0 -19
- package/src/utils/getDateOfBirth.ts +0 -8
- package/src/utils/getPreferredUnits.ts +0 -14
- package/src/utils/getPreferredUnitsTyped.ts +0 -38
- package/src/utils/getRequestStatusForAuthorization.ts +0 -21
- package/src/utils/getWorkoutPlanById.ts +0 -7
- package/src/utils/prepareOptions.ts +0 -19
- package/src/utils/queryCategorySamples.ts +0 -29
- package/src/utils/queryCategorySamplesWithAnchor.ts +0 -39
- package/src/utils/queryCorrelationSamples.ts +0 -29
- package/src/utils/queryHeartbeatSeriesSamples.ts +0 -29
- package/src/utils/queryHeartbeatSeriesSamplesWithAnchor.ts +0 -33
- package/src/utils/queryQuantitySamples.ts +0 -38
- package/src/utils/queryQuantitySamplesWithAnchor.ts +0 -46
- package/src/utils/querySources.ts +0 -21
- package/src/utils/queryStateOfMindSamples.ts +0 -14
- package/src/utils/queryStatisticsCollectionForQuantity.ts +0 -38
- package/src/utils/queryStatisticsForQuantity.ts +0 -38
- package/src/utils/queryWorkoutSamplesWithAnchor.ts +0 -46
- package/src/utils/queryWorkouts.ts +0 -28
- package/src/utils/requestAuthorization.ts +0 -19
- package/src/utils/saveCategorySample.ts +0 -31
- package/src/utils/saveCorrelationSample.ts +0 -43
- package/src/utils/saveQuantitySample.ts +0 -29
- package/src/utils/saveStateOfMindSample.ts +0 -38
- package/src/utils/saveWorkoutRoute.ts +0 -21
- package/src/utils/saveWorkoutSample.ts +0 -42
- package/src/utils/serializeDate.test.ts +0 -16
- package/src/utils/serializeDate.ts +0 -5
- package/src/utils/startWatchApp.ts +0 -7
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useCallback, useEffect, useRef, useState,
|
|
3
|
-
} from 'react'
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
4
2
|
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import { Core } from '../modules'
|
|
4
|
+
import type { AuthorizationRequestStatus } from '../types/Auth'
|
|
5
|
+
import type {
|
|
6
|
+
ObjectTypeIdentifier,
|
|
7
|
+
SampleTypeIdentifierWriteable,
|
|
8
|
+
} from '../types/Shared'
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const useHealthkitAuthorization = (
|
|
16
|
-
|
|
11
|
+
* @description Hook to retrieve the current authorization status for the given types, and request authorization if needed.
|
|
12
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614152-requestauthorization Apple Docs - requestAuthorization}
|
|
13
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/authorizing_access_to_health_data Apple Docs - Authorizing access to health data}
|
|
14
|
+
*/
|
|
15
|
+
export const useHealthkitAuthorization = (
|
|
16
|
+
read: ObjectTypeIdentifier[],
|
|
17
|
+
write?: SampleTypeIdentifierWriteable[],
|
|
18
|
+
) => {
|
|
19
|
+
const [status, setStatus] = useState<AuthorizationRequestStatus | null>(null)
|
|
17
20
|
|
|
18
21
|
const readMemo = useRef(read)
|
|
19
22
|
const writeMemo = useRef(write)
|
|
@@ -24,14 +27,17 @@ const useHealthkitAuthorization = (read: readonly HealthkitReadAuthorization[],
|
|
|
24
27
|
}, [read, write])
|
|
25
28
|
|
|
26
29
|
const refreshAuthStatus = useCallback(async () => {
|
|
27
|
-
const auth = await getRequestStatusForAuthorization(
|
|
30
|
+
const auth = await Core.getRequestStatusForAuthorization(
|
|
31
|
+
writeMemo.current ?? [],
|
|
32
|
+
readMemo.current,
|
|
33
|
+
)
|
|
28
34
|
|
|
29
35
|
setStatus(auth)
|
|
30
36
|
return auth
|
|
31
37
|
}, [])
|
|
32
38
|
|
|
33
39
|
const request = useCallback(async () => {
|
|
34
|
-
await requestAuthorization(
|
|
40
|
+
await Core.requestAuthorization(writeMemo.current ?? [], readMemo.current)
|
|
35
41
|
return refreshAuthStatus()
|
|
36
42
|
}, [refreshAuthStatus])
|
|
37
43
|
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
+
import { describe, expect, jest, test } from 'bun:test'
|
|
1
2
|
import { renderHook } from '@testing-library/react-native'
|
|
2
3
|
|
|
4
|
+
import { Core } from '../modules'
|
|
3
5
|
import waitForNextUpdate from '../test-utils'
|
|
4
6
|
|
|
5
7
|
describe('useIsHealthDataAvailable', () => {
|
|
6
8
|
test('should return false', async () => {
|
|
7
|
-
const useIsHealthDataAvailable = (
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
const useIsHealthDataAvailable = (
|
|
10
|
+
await import('./useIsHealthDataAvailable')
|
|
11
|
+
).default
|
|
12
|
+
jest
|
|
13
|
+
.spyOn(Core, 'isHealthDataAvailableAsync')
|
|
14
|
+
.mockReturnValue(Promise.resolve(false))
|
|
10
15
|
|
|
11
16
|
const { result } = renderHook(useIsHealthDataAvailable)
|
|
12
17
|
|
|
@@ -16,9 +21,12 @@ describe('useIsHealthDataAvailable', () => {
|
|
|
16
21
|
})
|
|
17
22
|
|
|
18
23
|
test('should return true', async () => {
|
|
19
|
-
const useIsHealthDataAvailable = (
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
const useIsHealthDataAvailable = (
|
|
25
|
+
await import('./useIsHealthDataAvailable')
|
|
26
|
+
).default
|
|
27
|
+
jest
|
|
28
|
+
.spyOn(Core, 'isHealthDataAvailableAsync')
|
|
29
|
+
.mockReturnValue(Promise.resolve(true))
|
|
22
30
|
|
|
23
31
|
const { result } = renderHook(useIsHealthDataAvailable)
|
|
24
32
|
|
|
@@ -28,7 +36,9 @@ describe('useIsHealthDataAvailable', () => {
|
|
|
28
36
|
})
|
|
29
37
|
|
|
30
38
|
test('should return null before initalizing', async () => {
|
|
31
|
-
const useIsHealthDataAvailable = (
|
|
39
|
+
const useIsHealthDataAvailable = (
|
|
40
|
+
await import('./useIsHealthDataAvailable')
|
|
41
|
+
).default
|
|
32
42
|
const { result } = renderHook(useIsHealthDataAvailable)
|
|
33
43
|
|
|
34
44
|
expect(result.current).toBe(null)
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react'
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { Core } from '../modules'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* @description By default, HealthKit data is available on iOS and watchOS. HealthKit data is also available on iPadOS 17 or later. However, devices running in an enterprise environment may restrict access to HealthKit data.
|
|
7
|
-
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614180-ishealthdataavailable Apple HealthKit isHealthDataAvailable}
|
|
8
|
-
* @returns {boolean | null} true if HealthKit is available; otherwise, false. null while initializing.
|
|
9
|
-
*/
|
|
10
|
-
const useIsHealthDataAvailable = (): boolean | null => {
|
|
6
|
+
* @description Now there is a Core.isHealthDataAvailable() that can be called synchronously. By default, HealthKit data is available on iOS and watchOS. HealthKit data is also available on iPadOS 17 or later. However, devices running in an enterprise environment may restrict access to HealthKit data.
|
|
7
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614180-ishealthdataavailable Apple HealthKit isHealthDataAvailable}
|
|
8
|
+
* @returns {boolean | null} true if HealthKit is available; otherwise, false. null while initializing.
|
|
9
|
+
*/
|
|
10
|
+
export const useIsHealthDataAvailable = (): boolean | null => {
|
|
11
11
|
const [isAvailable, setIsAvailable] = useState<boolean | null>(null)
|
|
12
12
|
|
|
13
13
|
useEffect(() => {
|
|
14
14
|
const init = async () => {
|
|
15
|
-
const res = await
|
|
15
|
+
const res = await Core.isHealthDataAvailableAsync()
|
|
16
16
|
setIsAvailable(res)
|
|
17
17
|
}
|
|
18
18
|
void init()
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
import { useCallback, useState } from 'react'
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import type { CategorySampleTyped } from '../types/CategoryType'
|
|
4
|
+
import type { CategoryTypeIdentifier } from '../types/CategoryTypeIdentifier'
|
|
4
5
|
import getMostRecentCategorySample from '../utils/getMostRecentCategorySample'
|
|
5
|
-
|
|
6
|
-
import type { HKCategoryTypeIdentifier } from '../native-types'
|
|
7
|
-
import type { HKCategorySample } from '../types'
|
|
6
|
+
import useSubscribeToChanges from './useSubscribeToChanges'
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function useMostRecentCategorySample<
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const [category, setCategory] = useState<
|
|
16
|
-
|
|
17
|
-
)
|
|
9
|
+
* @returns the most recent sample for the given category type.
|
|
10
|
+
*/
|
|
11
|
+
export function useMostRecentCategorySample<T extends CategoryTypeIdentifier>(
|
|
12
|
+
identifier: T,
|
|
13
|
+
) {
|
|
14
|
+
const [category, setCategory] = useState<CategorySampleTyped<T>>()
|
|
15
|
+
|
|
18
16
|
const updater = useCallback(() => {
|
|
19
17
|
void getMostRecentCategorySample(identifier).then(setCategory)
|
|
20
18
|
}, [identifier])
|
|
@@ -1,44 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import
|
|
1
|
+
import { useCallback, useState } from 'react'
|
|
2
|
+
import type { QuantitySample } from '../types/QuantitySample'
|
|
3
|
+
import type { QuantityTypeIdentifier } from '../types/QuantityTypeIdentifier'
|
|
4
4
|
import getMostRecentQuantitySample from '../utils/getMostRecentQuantitySample'
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
import type { HKQuantityTypeIdentifier, UnitForIdentifier } from '../native-types'
|
|
8
|
-
import type { HKQuantitySample } from '../types'
|
|
5
|
+
import useSubscribeToChanges from './useSubscribeToChanges'
|
|
9
6
|
|
|
10
7
|
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function useMostRecentQuantitySample
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const [lastSample, setLastSample] = useState<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
let cancelSubscription: (() => Promise<boolean>) | undefined
|
|
23
|
-
|
|
24
|
-
const init = async () => {
|
|
25
|
-
const actualUnit = await ensureUnit(identifier, unit)
|
|
26
|
-
|
|
27
|
-
const value = await getMostRecentQuantitySample(identifier, actualUnit)
|
|
28
|
-
setLastSample(value)
|
|
29
|
-
|
|
30
|
-
cancelSubscription = await subscribeToChanges(identifier, async () => {
|
|
31
|
-
const value = await getMostRecentQuantitySample(identifier, actualUnit)
|
|
32
|
-
setLastSample(value)
|
|
33
|
-
})
|
|
34
|
-
}
|
|
35
|
-
void init()
|
|
36
|
-
|
|
37
|
-
return () => {
|
|
38
|
-
void cancelSubscription?.()
|
|
39
|
-
}
|
|
8
|
+
* @returns the most recent sample for the given quantity type.
|
|
9
|
+
*/
|
|
10
|
+
export function useMostRecentQuantitySample(
|
|
11
|
+
identifier: QuantityTypeIdentifier,
|
|
12
|
+
unit?: string,
|
|
13
|
+
) {
|
|
14
|
+
const [lastSample, setLastSample] = useState<QuantitySample>()
|
|
15
|
+
|
|
16
|
+
const fetchMostRecentSample = useCallback(async () => {
|
|
17
|
+
const value = await getMostRecentQuantitySample(identifier, unit)
|
|
18
|
+
setLastSample(value)
|
|
40
19
|
}, [identifier, unit])
|
|
41
20
|
|
|
21
|
+
useSubscribeToChanges(identifier, fetchMostRecentSample)
|
|
22
|
+
|
|
42
23
|
return lastSample
|
|
43
24
|
}
|
|
44
25
|
|
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from 'react'
|
|
4
|
-
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
2
|
+
import type { WorkoutProxy } from '../specs/WorkoutProxy.nitro'
|
|
5
3
|
import getMostRecentWorkout from '../utils/getMostRecentWorkout'
|
|
6
|
-
import
|
|
7
|
-
import subscribeToChanges from '../utils/subscribeToChanges'
|
|
8
|
-
|
|
9
|
-
import type { EnergyUnit, LengthUnit } from '../native-types'
|
|
10
|
-
import type { HKWorkout } from '../types'
|
|
4
|
+
import useSubscribeToChanges from './useSubscribeToChanges'
|
|
11
5
|
|
|
12
6
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
function useMostRecentWorkout
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const [workout, setWorkout] = useState<
|
|
7
|
+
* @returns the most recent workout sample.
|
|
8
|
+
*/
|
|
9
|
+
export function useMostRecentWorkout(options?: {
|
|
10
|
+
readonly energyUnit?: string
|
|
11
|
+
readonly distanceUnit?: string
|
|
12
|
+
}) {
|
|
13
|
+
const [workout, setWorkout] = useState<WorkoutProxy>()
|
|
20
14
|
|
|
21
15
|
const optionsRef = useRef(options)
|
|
22
16
|
|
|
@@ -25,35 +19,19 @@ function useMostRecentWorkout<
|
|
|
25
19
|
}, [options])
|
|
26
20
|
|
|
27
21
|
const update = useCallback(async () => {
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
setWorkout(
|
|
23
|
+
await getMostRecentWorkout({
|
|
24
|
+
energyUnit: optionsRef.current?.energyUnit,
|
|
25
|
+
distanceUnit: optionsRef.current?.distanceUnit,
|
|
26
|
+
}),
|
|
30
27
|
)
|
|
31
|
-
|
|
32
|
-
setWorkout(await getMostRecentWorkout({
|
|
33
|
-
energyUnit,
|
|
34
|
-
distanceUnit,
|
|
35
|
-
}))
|
|
36
28
|
}, [])
|
|
37
29
|
|
|
38
30
|
useEffect(() => {
|
|
39
31
|
void update()
|
|
40
32
|
}, [update])
|
|
41
33
|
|
|
42
|
-
|
|
43
|
-
let cancelSubscription: (() => Promise<boolean>) | undefined
|
|
44
|
-
|
|
45
|
-
const init = async () => {
|
|
46
|
-
cancelSubscription = await subscribeToChanges(
|
|
47
|
-
'HKWorkoutTypeIdentifier',
|
|
48
|
-
update,
|
|
49
|
-
)
|
|
50
|
-
}
|
|
51
|
-
void init()
|
|
52
|
-
|
|
53
|
-
return () => {
|
|
54
|
-
void cancelSubscription?.()
|
|
55
|
-
}
|
|
56
|
-
}, [update])
|
|
34
|
+
useSubscribeToChanges('HKWorkoutTypeIdentifier', update)
|
|
57
35
|
|
|
58
36
|
return workout
|
|
59
37
|
}
|
package/src/hooks/useSources.ts
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState } from 'react'
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { Core } from '../modules'
|
|
4
|
+
import type { SourceProxy } from '../specs/SourceProxy.nitro'
|
|
5
|
+
import type { SampleTypeIdentifier } from '../types/Shared'
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from '../native-types'
|
|
10
|
-
|
|
11
|
-
function useSources<
|
|
12
|
-
TIdentifier extends HKCategoryTypeIdentifier | HKQuantityTypeIdentifier
|
|
13
|
-
>(identifier: TIdentifier) {
|
|
14
|
-
const [result, setResult] = useState<readonly HKSource[] | null>(null)
|
|
7
|
+
export function useSources<TIdentifier extends SampleTypeIdentifier>(
|
|
8
|
+
identifier: TIdentifier,
|
|
9
|
+
) {
|
|
10
|
+
const [result, setResult] = useState<readonly SourceProxy[] | null>(null)
|
|
15
11
|
|
|
16
12
|
const update = useCallback(async () => {
|
|
17
|
-
const res = await querySources(identifier)
|
|
13
|
+
const res = await Core.querySources(identifier)
|
|
18
14
|
setResult(res)
|
|
19
15
|
}, [identifier])
|
|
20
16
|
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useState, useEffect, useCallback, useRef,
|
|
3
|
-
} from 'react'
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
4
2
|
|
|
5
3
|
import useSubscribeToChanges from './useSubscribeToChanges'
|
|
6
|
-
import queryStatisticsForQuantity from '../utils/queryStatisticsForQuantity'
|
|
7
4
|
|
|
8
|
-
import
|
|
9
|
-
import type {
|
|
5
|
+
import { QuantityTypes } from '../modules'
|
|
6
|
+
import type {
|
|
7
|
+
QueryStatisticsResponse,
|
|
8
|
+
StatisticsOptions,
|
|
9
|
+
} from '../types/QuantityType'
|
|
10
|
+
import type { QuantityTypeIdentifier } from '../types/QuantityTypeIdentifier'
|
|
10
11
|
|
|
11
|
-
function useStatisticsForQuantity<
|
|
12
|
+
export function useStatisticsForQuantity<
|
|
13
|
+
TIdentifier extends QuantityTypeIdentifier,
|
|
14
|
+
>(
|
|
12
15
|
identifier: TIdentifier,
|
|
13
|
-
options: readonly
|
|
16
|
+
options: readonly StatisticsOptions[],
|
|
14
17
|
from: Date,
|
|
15
18
|
to?: Date,
|
|
16
|
-
unit?:
|
|
19
|
+
unit?: string,
|
|
17
20
|
) {
|
|
18
|
-
const [result, setResult] = useState<QueryStatisticsResponse
|
|
21
|
+
const [result, setResult] = useState<QueryStatisticsResponse | null>(null)
|
|
19
22
|
|
|
20
23
|
const optionsRef = useRef(options)
|
|
21
24
|
|
|
@@ -24,11 +27,13 @@ function useStatisticsForQuantity<TIdentifier extends HKQuantityTypeIdentifier,
|
|
|
24
27
|
}, [options])
|
|
25
28
|
|
|
26
29
|
const update = useCallback(async () => {
|
|
27
|
-
const res = await queryStatisticsForQuantity(
|
|
30
|
+
const res = await QuantityTypes.queryStatisticsForQuantity(
|
|
31
|
+
identifier,
|
|
32
|
+
optionsRef.current,
|
|
33
|
+
{ filter: { startDate: from, endDate: to }, unit },
|
|
34
|
+
)
|
|
28
35
|
setResult(res)
|
|
29
|
-
}, [
|
|
30
|
-
identifier, from, to, unit,
|
|
31
|
-
])
|
|
36
|
+
}, [identifier, from, to, unit])
|
|
32
37
|
|
|
33
38
|
useEffect(() => {
|
|
34
39
|
void update()
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react'
|
|
2
|
+
import type { SampleTypeIdentifier } from '../types/Shared'
|
|
3
|
+
import type { OnChangeCallbackArgs } from '../types/Subscriptons'
|
|
4
|
+
import { subscribeToChanges } from '../utils/subscribeToChanges'
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import type { HKSampleTypeIdentifier } from '..'
|
|
6
|
-
|
|
7
|
-
function useSubscribeToChanges<TIdentifier extends HKSampleTypeIdentifier>(
|
|
6
|
+
export function useSubscribeToChanges<TIdentifier extends SampleTypeIdentifier>(
|
|
8
7
|
identifier: TIdentifier,
|
|
9
|
-
onChange: () => void,
|
|
8
|
+
onChange: (args: OnChangeCallbackArgs) => void,
|
|
10
9
|
): void {
|
|
11
10
|
const onChangeRef = useRef(onChange)
|
|
12
11
|
|
|
@@ -15,15 +14,12 @@ function useSubscribeToChanges<TIdentifier extends HKSampleTypeIdentifier>(
|
|
|
15
14
|
}, [onChange])
|
|
16
15
|
|
|
17
16
|
useEffect(() => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
cancelSubscription = await subscribeToChanges(identifier, onChangeRef.current)
|
|
22
|
-
}
|
|
23
|
-
void init()
|
|
17
|
+
const subscription = subscribeToChanges(identifier, (args) => {
|
|
18
|
+
onChangeRef.current(args)
|
|
19
|
+
})
|
|
24
20
|
|
|
25
21
|
return () => {
|
|
26
|
-
|
|
22
|
+
subscription.remove()
|
|
27
23
|
}
|
|
28
24
|
}, [identifier])
|
|
29
25
|
}
|
package/src/index.ios.ts
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { Platform } from 'react-native'
|
|
2
|
+
import useHealthkitAuthorization from './hooks/useHealthkitAuthorization'
|
|
3
|
+
import { useIsHealthDataAvailable } from './hooks/useIsHealthDataAvailable'
|
|
4
|
+
import useMostRecentCategorySample from './hooks/useMostRecentCategorySample'
|
|
5
|
+
import useMostRecentQuantitySample from './hooks/useMostRecentQuantitySample'
|
|
6
|
+
import useMostRecentWorkout from './hooks/useMostRecentWorkout'
|
|
7
|
+
import useSources from './hooks/useSources'
|
|
8
|
+
import useStatisticsForQuantity from './hooks/useStatisticsForQuantity'
|
|
9
|
+
import useSubscribeToChanges from './hooks/useSubscribeToChanges'
|
|
10
|
+
import {
|
|
11
|
+
CategoryTypes,
|
|
12
|
+
Characteristics,
|
|
13
|
+
Core,
|
|
14
|
+
CorrelationTypes,
|
|
15
|
+
HeartbeatSeries,
|
|
16
|
+
QuantityTypes,
|
|
17
|
+
StateOfMind,
|
|
18
|
+
Workouts,
|
|
19
|
+
} from './modules'
|
|
20
|
+
import type { QuantityTypeIdentifier } from './types/QuantityTypeIdentifier'
|
|
21
|
+
import getMostRecentCategorySample from './utils/getMostRecentCategorySample'
|
|
22
|
+
import getMostRecentQuantitySample from './utils/getMostRecentQuantitySample'
|
|
23
|
+
import getMostRecentWorkout from './utils/getMostRecentWorkout'
|
|
24
|
+
import getPreferredUnit from './utils/getPreferredUnit'
|
|
25
|
+
|
|
26
|
+
const currentMajorVersionIOS =
|
|
27
|
+
Platform.OS === 'ios' ? Number.parseInt(Platform.Version, 10) : 0
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Quantity types that are not available before iOS 17
|
|
31
|
+
*/
|
|
32
|
+
type QuantityTypesIOS17Plus =
|
|
33
|
+
| 'HKQuantityTypeIdentifierCyclingCadence'
|
|
34
|
+
| 'HKQuantityTypeIdentifierCyclingFunctionalThresholdPower'
|
|
35
|
+
| 'HKQuantityTypeIdentifierCyclingPower'
|
|
36
|
+
| 'HKQuantityTypeIdentifierCyclingSpeed'
|
|
37
|
+
| 'HKQuantityTypeIdentifierPhysicalEffort'
|
|
38
|
+
| 'HKQuantityTypeIdentifierTimeInDaylight'
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Available quantity types for iOS versions before iOS 17
|
|
42
|
+
*/
|
|
43
|
+
export type AvailableQuantityTypesBeforeIOS17 = Exclude<
|
|
44
|
+
QuantityTypeIdentifier,
|
|
45
|
+
QuantityTypesIOS17Plus
|
|
46
|
+
>
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
getMostRecentCategorySample,
|
|
50
|
+
getMostRecentQuantitySample,
|
|
51
|
+
getMostRecentWorkout,
|
|
52
|
+
getPreferredUnit,
|
|
53
|
+
useMostRecentCategorySample,
|
|
54
|
+
useMostRecentQuantitySample,
|
|
55
|
+
useMostRecentWorkout,
|
|
56
|
+
useSubscribeToChanges,
|
|
57
|
+
useHealthkitAuthorization,
|
|
58
|
+
useIsHealthDataAvailable,
|
|
59
|
+
useSources,
|
|
60
|
+
useStatisticsForQuantity,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Available quantity types for iOS 17 and later (all quantity types)
|
|
65
|
+
*/
|
|
66
|
+
export type AvailableQuantityTypesIOS17Plus = QuantityTypeIdentifier
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Get available quantity types based on iOS version
|
|
70
|
+
* @param majorVersionIOS - iOS major version number (defaults to current iOS version)
|
|
71
|
+
* @returns Available quantity types for the given iOS version
|
|
72
|
+
*/
|
|
73
|
+
export type AvailableQuantityTypes<
|
|
74
|
+
T extends number = typeof currentMajorVersionIOS,
|
|
75
|
+
> = T extends 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25
|
|
76
|
+
? AvailableQuantityTypesIOS17Plus
|
|
77
|
+
: AvailableQuantityTypesBeforeIOS17
|
|
78
|
+
|
|
79
|
+
// Named exports - all functions bound to their respective modules
|
|
80
|
+
export const authorizationStatusFor = Core.authorizationStatusFor.bind(Core)
|
|
81
|
+
export const disableAllBackgroundDelivery =
|
|
82
|
+
Core.disableAllBackgroundDelivery.bind(Core)
|
|
83
|
+
export const disableBackgroundDelivery =
|
|
84
|
+
Core.disableBackgroundDelivery.bind(Core)
|
|
85
|
+
export const enableBackgroundDelivery = Core.enableBackgroundDelivery.bind(Core)
|
|
86
|
+
export const getBiologicalSex =
|
|
87
|
+
Characteristics.getBiologicalSex.bind(Characteristics)
|
|
88
|
+
export const getBloodType = Characteristics.getBloodType.bind(Characteristics)
|
|
89
|
+
export const getDateOfBirth =
|
|
90
|
+
Characteristics.getDateOfBirth.bind(Characteristics)
|
|
91
|
+
export const getFitzpatrickSkinType =
|
|
92
|
+
Characteristics.getFitzpatrickSkinType.bind(Characteristics)
|
|
93
|
+
export const getPreferredUnits = Core.getPreferredUnits.bind(Core)
|
|
94
|
+
export const getRequestStatusForAuthorization =
|
|
95
|
+
Core.getRequestStatusForAuthorization.bind(Core)
|
|
96
|
+
export const getWheelchairUse =
|
|
97
|
+
Characteristics.getWheelchairUse.bind(Characteristics)
|
|
98
|
+
export const isHealthDataAvailable = Core.isHealthDataAvailable.bind(Core)
|
|
99
|
+
export const isHealthDataAvailableAsync =
|
|
100
|
+
Core.isHealthDataAvailableAsync.bind(Core)
|
|
101
|
+
export const queryCategorySamples =
|
|
102
|
+
CategoryTypes.queryCategorySamples.bind(CategoryTypes)
|
|
103
|
+
export const queryCategorySamplesWithAnchor =
|
|
104
|
+
CategoryTypes.queryCategorySamplesWithAnchor.bind(CategoryTypes)
|
|
105
|
+
export const queryCorrelationSamples =
|
|
106
|
+
CorrelationTypes.queryCorrelationSamples.bind(CorrelationTypes)
|
|
107
|
+
export const queryHeartbeatSeriesSamples =
|
|
108
|
+
HeartbeatSeries.queryHeartbeatSeriesSamples.bind(HeartbeatSeries)
|
|
109
|
+
export const queryHeartbeatSeriesSamplesWithAnchor =
|
|
110
|
+
HeartbeatSeries.queryHeartbeatSeriesSamplesWithAnchor.bind(HeartbeatSeries)
|
|
111
|
+
export const queryQuantitySamples =
|
|
112
|
+
QuantityTypes.queryQuantitySamples.bind(QuantityTypes)
|
|
113
|
+
export const queryQuantitySamplesWithAnchor =
|
|
114
|
+
QuantityTypes.queryQuantitySamplesWithAnchor.bind(QuantityTypes)
|
|
115
|
+
export const queryStatisticsForQuantity =
|
|
116
|
+
QuantityTypes.queryStatisticsForQuantity.bind(QuantityTypes)
|
|
117
|
+
export const queryStatisticsCollectionForQuantity =
|
|
118
|
+
QuantityTypes.queryStatisticsCollectionForQuantity.bind(QuantityTypes)
|
|
119
|
+
export const queryWorkoutSamples = Workouts.queryWorkoutSamples.bind(Workouts)
|
|
120
|
+
export const queryWorkoutSamplesWithAnchor =
|
|
121
|
+
Workouts.queryWorkoutSamplesWithAnchor.bind(Workouts)
|
|
122
|
+
export const querySources = Core.querySources.bind(Core)
|
|
123
|
+
export const requestAuthorization = Core.requestAuthorization.bind(Core)
|
|
124
|
+
export const deleteObjects = Core.deleteObjects.bind(Core)
|
|
125
|
+
export const saveCategorySample =
|
|
126
|
+
CategoryTypes.saveCategorySample.bind(CategoryTypes)
|
|
127
|
+
export const saveCorrelationSample =
|
|
128
|
+
CorrelationTypes.saveCorrelationSample.bind(CorrelationTypes)
|
|
129
|
+
export const saveQuantitySample =
|
|
130
|
+
QuantityTypes.saveQuantitySample.bind(QuantityTypes)
|
|
131
|
+
export const saveWorkoutSample = Workouts.saveWorkoutSample.bind(Workouts)
|
|
132
|
+
export const subscribeToChanges = Core.subscribeToObserverQuery.bind(Core)
|
|
133
|
+
export const startWatchApp =
|
|
134
|
+
Workouts.startWatchAppWithWorkoutConfiguration.bind(Workouts)
|
|
135
|
+
export const isProtectedDataAvailable = Core.isProtectedDataAvailable.bind(Core)
|
|
136
|
+
export const queryStateOfMindSamples =
|
|
137
|
+
StateOfMind.queryStateOfMindSamples.bind(StateOfMind)
|
|
138
|
+
export const saveStateOfMindSample =
|
|
139
|
+
StateOfMind.saveStateOfMindSample.bind(StateOfMind)
|
|
140
|
+
export const isQuantityCompatibleWithUnit =
|
|
141
|
+
QuantityTypes.isQuantityCompatibleWithUnit.bind(QuantityTypes)
|
|
142
|
+
export const unsubscribeQueries = Core.unsubscribeQueries.bind(Core)
|
|
143
|
+
|
|
144
|
+
export const isObjectTypeAvailable = Core.isObjectTypeAvailable.bind(Core)
|
|
145
|
+
export const isObjectTypeAvailableAsync =
|
|
146
|
+
Core.isObjectTypeAvailableAsync.bind(Core)
|
|
147
|
+
export const areObjectTypesAvailable = Core.areObjectTypesAvailable.bind(Core)
|
|
148
|
+
export const areObjectTypesAvailableAsync =
|
|
149
|
+
Core.areObjectTypesAvailableAsync.bind(Core)
|
|
150
|
+
|
|
151
|
+
export const getBiologicalSexAsync =
|
|
152
|
+
Characteristics.getBiologicalSexAsync.bind(Characteristics)
|
|
153
|
+
export const getBloodTypeAsync =
|
|
154
|
+
Characteristics.getBloodTypeAsync.bind(Characteristics)
|
|
155
|
+
export const getDateOfBirthAsync =
|
|
156
|
+
Characteristics.getDateOfBirthAsync.bind(Characteristics)
|
|
157
|
+
export const getFitzpatrickSkinTypeAsync =
|
|
158
|
+
Characteristics.getFitzpatrickSkinTypeAsync.bind(Characteristics)
|
|
159
|
+
export const getWheelchairUseAsync =
|
|
160
|
+
Characteristics.getWheelchairUseAsync.bind(Characteristics)
|
|
161
|
+
|
|
162
|
+
export default {
|
|
163
|
+
authorizationStatusFor,
|
|
164
|
+
isObjectTypeAvailable,
|
|
165
|
+
isObjectTypeAvailableAsync,
|
|
166
|
+
areObjectTypesAvailable,
|
|
167
|
+
areObjectTypesAvailableAsync,
|
|
168
|
+
isQuantityCompatibleWithUnit,
|
|
169
|
+
disableAllBackgroundDelivery,
|
|
170
|
+
disableBackgroundDelivery,
|
|
171
|
+
enableBackgroundDelivery,
|
|
172
|
+
getBiologicalSex,
|
|
173
|
+
getBloodType,
|
|
174
|
+
getDateOfBirth,
|
|
175
|
+
getFitzpatrickSkinType,
|
|
176
|
+
getBiologicalSexAsync,
|
|
177
|
+
getBloodTypeAsync,
|
|
178
|
+
getDateOfBirthAsync,
|
|
179
|
+
getFitzpatrickSkinTypeAsync,
|
|
180
|
+
getWheelchairUseAsync,
|
|
181
|
+
getMostRecentCategorySample,
|
|
182
|
+
getMostRecentQuantitySample,
|
|
183
|
+
getMostRecentWorkout,
|
|
184
|
+
getPreferredUnits,
|
|
185
|
+
getPreferredUnit,
|
|
186
|
+
getRequestStatusForAuthorization,
|
|
187
|
+
getWheelchairUse,
|
|
188
|
+
isHealthDataAvailable,
|
|
189
|
+
isHealthDataAvailableAsync,
|
|
190
|
+
queryCategorySamples,
|
|
191
|
+
queryCategorySamplesWithAnchor,
|
|
192
|
+
queryCorrelationSamples,
|
|
193
|
+
queryHeartbeatSeriesSamples,
|
|
194
|
+
queryHeartbeatSeriesSamplesWithAnchor,
|
|
195
|
+
queryQuantitySamples,
|
|
196
|
+
queryQuantitySamplesWithAnchor,
|
|
197
|
+
queryStatisticsForQuantity,
|
|
198
|
+
queryStatisticsCollectionForQuantity,
|
|
199
|
+
queryWorkoutSamples,
|
|
200
|
+
queryWorkoutSamplesWithAnchor,
|
|
201
|
+
querySources,
|
|
202
|
+
requestAuthorization,
|
|
203
|
+
deleteObjects,
|
|
204
|
+
saveCategorySample,
|
|
205
|
+
saveCorrelationSample,
|
|
206
|
+
saveQuantitySample,
|
|
207
|
+
saveWorkoutSample,
|
|
208
|
+
subscribeToChanges,
|
|
209
|
+
unsubscribeQueries,
|
|
210
|
+
startWatchApp,
|
|
211
|
+
isProtectedDataAvailable,
|
|
212
|
+
queryStateOfMindSamples,
|
|
213
|
+
saveStateOfMindSample,
|
|
214
|
+
// Modules
|
|
215
|
+
// Core,
|
|
216
|
+
// Workouts,
|
|
217
|
+
// Characteristics,
|
|
218
|
+
// QuantityTypes,
|
|
219
|
+
// CategoryTypes,
|
|
220
|
+
// CorrelationTypes,
|
|
221
|
+
// HeartbeatSeries,
|
|
222
|
+
// StateOfMind,
|
|
223
|
+
// hooks
|
|
224
|
+
useMostRecentCategorySample,
|
|
225
|
+
useMostRecentQuantitySample,
|
|
226
|
+
useMostRecentWorkout,
|
|
227
|
+
useSubscribeToChanges,
|
|
228
|
+
useHealthkitAuthorization,
|
|
229
|
+
useIsHealthDataAvailable,
|
|
230
|
+
useSources,
|
|
231
|
+
useStatisticsForQuantity,
|
|
232
|
+
}
|