@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
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import HealthKit
|
|
2
|
+
import NitroModules
|
|
3
|
+
//
|
|
4
|
+
// Core.swift
|
|
5
|
+
// Pods
|
|
6
|
+
//
|
|
7
|
+
// Created by Robert Herber on 2025-05-28.
|
|
8
|
+
//
|
|
9
|
+
|
|
10
|
+
var store = HKHealthStore.init()
|
|
11
|
+
|
|
12
|
+
var quantityTypeUnitCache = Dictionary<HKQuantityType, HKUnit>()
|
|
13
|
+
|
|
14
|
+
func getUnitToUse(unitOverride: String?, quantityType: HKQuantityType) async throws -> HKUnit {
|
|
15
|
+
if let unitOverride = unitOverride {
|
|
16
|
+
let unit = HKUnit(from: unitOverride)
|
|
17
|
+
|
|
18
|
+
if(!quantityType.is(compatibleWith: unit)){
|
|
19
|
+
throw RuntimeError.error(withMessage: "[react-native-healthkit] Unit \(unitOverride) is incompatible with \(quantityType.identifier)")
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return unit
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if let preferredUnit = try await getPreferredUnitsInternal(quantityTypes: [quantityType]).first?.value {
|
|
26
|
+
return preferredUnit
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
throw RuntimeError.error(withMessage: "[react-native-healthkit] Must specify a unit for \(quantityType.identifier)")
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
func getPreferredUnitsInternal(quantityTypes: [HKQuantityType], forceUpdate: Bool? = false) async throws -> [HKQuantityType: HKUnit] {
|
|
33
|
+
|
|
34
|
+
if(forceUpdate != true){
|
|
35
|
+
let itemsInCache = quantityTypeUnitCache.filter { (quantityType: HKQuantityType, unit: HKUnit) in
|
|
36
|
+
return quantityTypes.contains(where: { $0 == quantityType })
|
|
37
|
+
}
|
|
38
|
+
if(itemsInCache.count == quantityTypes.count){
|
|
39
|
+
return itemsInCache
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
return try await withCheckedThrowingContinuation { continuation in
|
|
45
|
+
store.preferredUnits(for: Set(quantityTypes)) {
|
|
46
|
+
(typePerUnits: [HKQuantityType: HKUnit], error: Error?) in
|
|
47
|
+
if let error = error {
|
|
48
|
+
return continuation.resume(throwing: error)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
typePerUnits.forEach { (type: HKQuantityType, unit: HKUnit) in
|
|
52
|
+
quantityTypeUnitCache.updateValue(unit, forKey: type)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return continuation.resume(returning: typePerUnits)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
class CoreModule : HybridCoreModuleSpec {
|
|
61
|
+
func areObjectTypesAvailable(objectTypeIdentifiers: [ObjectTypeIdentifier]) -> Dictionary<String, Bool> {
|
|
62
|
+
var dict = Dictionary<String, Bool>()
|
|
63
|
+
|
|
64
|
+
for objectTypeIdentifier in objectTypeIdentifiers {
|
|
65
|
+
dict[objectTypeIdentifier.stringValue] = isObjectTypeAvailable(objectTypeIdentifier: objectTypeIdentifier)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return dict
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
func areObjectTypesAvailableAsync(objectTypeIdentifiers: [ObjectTypeIdentifier]) -> Promise<Dictionary<String, Bool>> {
|
|
72
|
+
return Promise.resolved(withResult: areObjectTypesAvailable(objectTypeIdentifiers: objectTypeIdentifiers))
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
func isObjectTypeAvailable(objectTypeIdentifier: ObjectTypeIdentifier) -> Bool {
|
|
78
|
+
do {
|
|
79
|
+
let _ = try objectTypeFrom(objectTypeIdentifier: objectTypeIdentifier)
|
|
80
|
+
return true
|
|
81
|
+
} catch {
|
|
82
|
+
return false
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
func isObjectTypeAvailableAsync(objectTypeIdentifier: ObjectTypeIdentifier) -> Promise<Bool> {
|
|
87
|
+
return Promise.resolved(withResult: isObjectTypeAvailable(objectTypeIdentifier: objectTypeIdentifier))
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
func authorizationStatusFor(
|
|
91
|
+
type: ObjectTypeIdentifier
|
|
92
|
+
) throws -> AuthorizationStatus {
|
|
93
|
+
let objectType = try objectTypeFrom(objectTypeIdentifier: type)
|
|
94
|
+
|
|
95
|
+
let authStatus = store.authorizationStatus(for: objectType)
|
|
96
|
+
|
|
97
|
+
if let authStatus = AuthorizationStatus(rawValue: Int32(authStatus.rawValue)){
|
|
98
|
+
return authStatus
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
throw RuntimeError.error(withMessage: "[react-native-healthkit] got unrecognized AuthorizationStatus with value \(authStatus.rawValue)")
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
func getRequestStatusForAuthorization(toShare: [SampleTypeIdentifierWriteable], toRead: [ObjectTypeIdentifier]) throws -> Promise<AuthorizationRequestStatus> {
|
|
105
|
+
let toShare = sampleTypesFromArray(typeIdentifiersWriteable: toShare)
|
|
106
|
+
let toRead = objectTypesFromArray(typeIdentifiers: toRead)
|
|
107
|
+
|
|
108
|
+
return Promise.async {
|
|
109
|
+
try await withCheckedThrowingContinuation { continuation in
|
|
110
|
+
store.getRequestStatusForAuthorization(toShare: toShare, read: toRead) { status, error in
|
|
111
|
+
if let error = error {
|
|
112
|
+
continuation.resume(throwing: error)
|
|
113
|
+
} else {
|
|
114
|
+
if let authStatus = AuthorizationRequestStatus(rawValue: Int32(status.rawValue)) {
|
|
115
|
+
continuation.resume(returning: authStatus)
|
|
116
|
+
} else {
|
|
117
|
+
continuation.resume(throwing: RuntimeError.error(withMessage: "Unrecognized authStatus returned: \(status.rawValue)"))
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
func requestAuthorization(toShare: [SampleTypeIdentifierWriteable], toRead: [ObjectTypeIdentifier]) throws -> Promise<Bool> {
|
|
127
|
+
let share = sampleTypesFromArray(typeIdentifiersWriteable: toShare)
|
|
128
|
+
let toRead = objectTypesFromArray(typeIdentifiers: toRead)
|
|
129
|
+
|
|
130
|
+
return Promise.async {
|
|
131
|
+
try await withCheckedThrowingContinuation { continuation in
|
|
132
|
+
store.requestAuthorization(toShare: share, read: toRead) { status, error in
|
|
133
|
+
if let error = error {
|
|
134
|
+
continuation.resume(throwing: error)
|
|
135
|
+
} else {
|
|
136
|
+
continuation.resume(returning: status)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
func querySources(identifier: SampleTypeIdentifier) throws -> Promise<[HybridSourceProxySpec]> {
|
|
144
|
+
let sampleType = try sampleTypeFrom(sampleTypeIdentifier: identifier)
|
|
145
|
+
|
|
146
|
+
return Promise.async {
|
|
147
|
+
try await withCheckedThrowingContinuation { continuation in
|
|
148
|
+
let query = HKSourceQuery(
|
|
149
|
+
sampleType: sampleType,
|
|
150
|
+
samplePredicate: nil
|
|
151
|
+
) { (_: HKSourceQuery, sources: Set<HKSource>?, error: Error?) in
|
|
152
|
+
if let error = error {
|
|
153
|
+
continuation.resume(throwing: error)
|
|
154
|
+
return
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
guard let sources = sources else {
|
|
158
|
+
return continuation.resume(throwing: RuntimeError.error(withMessage: "Empty response for sample type \(identifier.stringValue)"))
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
let serializedSources = sources.map { source -> SourceProxy in
|
|
162
|
+
|
|
163
|
+
return SourceProxy(
|
|
164
|
+
source: source
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
continuation.resume(returning: serializedSources)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
store.execute(query)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
func enableBackgroundDelivery(typeIdentifier: ObjectTypeIdentifier, updateFrequency: UpdateFrequency) throws -> Promise<Bool> {
|
|
177
|
+
if let frequency = HKUpdateFrequency(rawValue: Int(updateFrequency.rawValue)) {
|
|
178
|
+
let type = try objectTypeFrom(objectTypeIdentifier: typeIdentifier)
|
|
179
|
+
return Promise.async {
|
|
180
|
+
try await withCheckedThrowingContinuation { continuation in
|
|
181
|
+
store.enableBackgroundDelivery(
|
|
182
|
+
for: type,
|
|
183
|
+
frequency: frequency
|
|
184
|
+
) { (success, error) in
|
|
185
|
+
if let err = error {
|
|
186
|
+
return continuation.resume(throwing: err)
|
|
187
|
+
}
|
|
188
|
+
return continuation.resume(returning: success)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
throw RuntimeError.error(withMessage: "Invalid update frequency value: \(updateFrequency)")
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
func disableBackgroundDelivery(
|
|
198
|
+
typeIdentifier: ObjectTypeIdentifier
|
|
199
|
+
) throws -> Promise<Bool> {
|
|
200
|
+
return Promise.async {
|
|
201
|
+
let type = try objectTypeFrom(objectTypeIdentifier: typeIdentifier)
|
|
202
|
+
return try await withCheckedThrowingContinuation { continuation in
|
|
203
|
+
store.disableBackgroundDelivery(
|
|
204
|
+
for: type
|
|
205
|
+
) { (success, error) in
|
|
206
|
+
if let err = error {
|
|
207
|
+
return continuation.resume(throwing: err)
|
|
208
|
+
}
|
|
209
|
+
return continuation.resume(returning: success)
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
func disableAllBackgroundDelivery() throws -> Promise<Bool> {
|
|
216
|
+
return Promise.async {
|
|
217
|
+
try await withCheckedThrowingContinuation { continuation in
|
|
218
|
+
store.disableAllBackgroundDelivery(completion: { (success, error) in
|
|
219
|
+
guard let err = error else {
|
|
220
|
+
return continuation.resume(returning: success)
|
|
221
|
+
}
|
|
222
|
+
return continuation.resume(throwing: err)
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
func unsubscribeQueryAsync(queryId: String) throws -> Promise<Bool> {
|
|
229
|
+
let result = try self.unsubscribeQuery(queryId: queryId)
|
|
230
|
+
|
|
231
|
+
return Promise.resolved(withResult: result)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
func isHealthDataAvailableAsync() -> Promise<Bool> {
|
|
235
|
+
return Promise.resolved(withResult: HKHealthStore.isHealthDataAvailable())
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
func isProtectedDataAvailableAsync() -> Promise<Bool> {
|
|
239
|
+
return Promise.resolved(withResult: UIApplication.shared.isProtectedDataAvailable)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
func isHealthDataAvailable() throws -> Bool {
|
|
243
|
+
return HKHealthStore.isHealthDataAvailable()
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
func isProtectedDataAvailable() throws -> Bool {
|
|
247
|
+
return UIApplication.shared.isProtectedDataAvailable
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
func getPreferredUnits(identifiers: [QuantityTypeIdentifier], forceUpdate: Bool?) throws -> Promise<[IdentifierWithUnit]> {
|
|
251
|
+
return Promise.async {
|
|
252
|
+
|
|
253
|
+
let quantityTypes = identifiers.compactMap { identifier in
|
|
254
|
+
do {
|
|
255
|
+
let quantityType = try initializeQuantityType(identifier.stringValue)
|
|
256
|
+
return quantityType
|
|
257
|
+
} catch {
|
|
258
|
+
print(error.localizedDescription)
|
|
259
|
+
return nil
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
let typePerUnits = try await getPreferredUnitsInternal(quantityTypes: quantityTypes, forceUpdate: forceUpdate)
|
|
264
|
+
|
|
265
|
+
let dic = typePerUnits.map { typePerUnit in
|
|
266
|
+
return IdentifierWithUnit(
|
|
267
|
+
typeIdentifier: typePerUnit.key.identifier,
|
|
268
|
+
unit: typePerUnit.value.unitString
|
|
269
|
+
)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return dic
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
var _runningQueries: [String: HKQuery] = [:]
|
|
277
|
+
|
|
278
|
+
func deleteObjects(objectTypeIdentifier: ObjectTypeIdentifier, filter: FilterForSamples) throws -> Promise<Double> {
|
|
279
|
+
let predicate = try createPredicateForSamples(filter: filter)
|
|
280
|
+
let of = try objectTypeFrom(objectTypeIdentifier: objectTypeIdentifier)
|
|
281
|
+
|
|
282
|
+
return Promise.async {
|
|
283
|
+
return try await withCheckedThrowingContinuation { continuation in
|
|
284
|
+
store.deleteObjects(of: of, predicate: predicate) { (success, count, error) in
|
|
285
|
+
if let error = error {
|
|
286
|
+
continuation.resume(throwing: error)
|
|
287
|
+
} else {
|
|
288
|
+
continuation.resume(returning: Double(count))
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
func subscribeToObserverQuery(
|
|
296
|
+
typeIdentifier: SampleTypeIdentifier,
|
|
297
|
+
callback: @escaping (OnChangeCallbackArgs) -> Void
|
|
298
|
+
) throws -> String {
|
|
299
|
+
let sampleType = try sampleTypeFrom(sampleTypeIdentifier: typeIdentifier)
|
|
300
|
+
|
|
301
|
+
let predicate = HKQuery.predicateForSamples(
|
|
302
|
+
withStart: Date.init(),
|
|
303
|
+
end: nil,
|
|
304
|
+
options: HKQueryOptions.strictStartDate
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
let queryId = UUID().uuidString
|
|
308
|
+
|
|
309
|
+
func responder(
|
|
310
|
+
query: HKObserverQuery,
|
|
311
|
+
handler: @escaping HKObserverQueryCompletionHandler,
|
|
312
|
+
error: Error?
|
|
313
|
+
) {
|
|
314
|
+
DispatchQueue.main.async {
|
|
315
|
+
callback(OnChangeCallbackArgs(typeIdentifier: typeIdentifier, errorMessage: error?.localizedDescription))
|
|
316
|
+
handler()
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
let query = HKObserverQuery(
|
|
321
|
+
sampleType: sampleType,
|
|
322
|
+
predicate: predicate
|
|
323
|
+
) {
|
|
324
|
+
(query: HKObserverQuery, handler: @escaping HKObserverQueryCompletionHandler, error: Error?)
|
|
325
|
+
in
|
|
326
|
+
|
|
327
|
+
return responder(query: query, handler: handler, error: error)
|
|
328
|
+
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
store.execute(query)
|
|
332
|
+
|
|
333
|
+
self._runningQueries.updateValue(query, forKey: queryId)
|
|
334
|
+
|
|
335
|
+
//resolve(queryId)
|
|
336
|
+
|
|
337
|
+
return queryId
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
func unsubscribeQuery(queryId: String) throws -> Bool {
|
|
341
|
+
guard let query = self._runningQueries[queryId] else {
|
|
342
|
+
throw RuntimeError.error(withMessage: "Query with id \(queryId) not found")
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
store.stop(query)
|
|
346
|
+
|
|
347
|
+
self._runningQueries.removeValue(forKey: queryId)
|
|
348
|
+
|
|
349
|
+
return true
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
func unsubscribeQueriesAsync(queryIds: [String]) throws -> Promise<Double> {
|
|
353
|
+
let successCount = self.unsubscribeQueries(queryIds: queryIds)
|
|
354
|
+
|
|
355
|
+
return Promise.resolved(withResult: successCount)
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
func unsubscribeQueries(queryIds: [String]) -> Double {
|
|
359
|
+
let successCounts = queryIds.map { queryId in
|
|
360
|
+
if let query = self._runningQueries[queryId] {
|
|
361
|
+
store.stop(query)
|
|
362
|
+
|
|
363
|
+
self._runningQueries.removeValue(forKey: queryId)
|
|
364
|
+
|
|
365
|
+
return true
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
print("Query with id \(queryId) not found, skipping unsubscribe")
|
|
369
|
+
|
|
370
|
+
return false
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
return Double(successCounts.filter { $0 }.count)
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import HealthKit
|
|
2
|
+
import NitroModules
|
|
3
|
+
|
|
4
|
+
class CorrelationTypeModule : HybridCorrelationTypeModuleSpec {
|
|
5
|
+
func saveCorrelationSample(
|
|
6
|
+
typeIdentifier: CorrelationTypeIdentifier,
|
|
7
|
+
samples: [SampleForSaving],
|
|
8
|
+
start: Date,
|
|
9
|
+
end: Date,
|
|
10
|
+
metadata: AnyMapHolder
|
|
11
|
+
) throws -> Promise<Bool> {
|
|
12
|
+
let correlationType = try initializeCorrelationType(typeIdentifier.stringValue)
|
|
13
|
+
|
|
14
|
+
var initializedSamples = Set<HKSample>()
|
|
15
|
+
|
|
16
|
+
for sample in samples {
|
|
17
|
+
if let quantitySample = sample as? QuantitySampleForSaving {
|
|
18
|
+
let quantityTypeId = HKQuantityTypeIdentifier(rawValue: quantitySample.quantityType.stringValue)
|
|
19
|
+
guard let quantityType = HKSampleType.quantityType(forIdentifier: quantityTypeId) else {
|
|
20
|
+
continue
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let unit = HKUnit(from: quantitySample.unit)
|
|
24
|
+
let quantity = HKQuantity(unit: unit, doubleValue: quantitySample.quantity)
|
|
25
|
+
let hkQuantitySample = HKQuantitySample(
|
|
26
|
+
type: quantityType,
|
|
27
|
+
quantity: quantity,
|
|
28
|
+
start: start,
|
|
29
|
+
end: end,
|
|
30
|
+
metadata: anyMapToDictionary(quantitySample.metadata)
|
|
31
|
+
)
|
|
32
|
+
initializedSamples.insert(hkQuantitySample)
|
|
33
|
+
|
|
34
|
+
} else if let categorySample = sample as? CategorySampleForSaving {
|
|
35
|
+
let categoryType = try initializeCategoryType(categorySample.categoryType.stringValue)
|
|
36
|
+
|
|
37
|
+
let hkCategorySample = HKCategorySample(
|
|
38
|
+
type: categoryType,
|
|
39
|
+
value: Int(categorySample.value),
|
|
40
|
+
start: categorySample.start,
|
|
41
|
+
end: categorySample.end,
|
|
42
|
+
metadata: anyMapToDictionary(categorySample.metadata)
|
|
43
|
+
)
|
|
44
|
+
initializedSamples.insert(hkCategorySample)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let correlation = HKCorrelation(
|
|
49
|
+
type: correlationType,
|
|
50
|
+
start: start,
|
|
51
|
+
end: end,
|
|
52
|
+
objects: initializedSamples,
|
|
53
|
+
metadata: anyMapToDictionary(metadata)
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
return Promise.async {
|
|
57
|
+
try await withCheckedThrowingContinuation { continuation in
|
|
58
|
+
store.save(correlation) { (success: Bool, error: Error?) in
|
|
59
|
+
if let error = error {
|
|
60
|
+
continuation.resume(throwing: error)
|
|
61
|
+
} else {
|
|
62
|
+
continuation.resume(returning: success)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
func queryCorrelationSamples(
|
|
70
|
+
typeIdentifier: CorrelationTypeIdentifier,
|
|
71
|
+
from: Date,
|
|
72
|
+
to: Date
|
|
73
|
+
) throws -> Promise<[CorrelationSample]> {
|
|
74
|
+
let correlationType = try initializeCorrelationType(typeIdentifier.stringValue)
|
|
75
|
+
let predicate = try createPredicate(
|
|
76
|
+
filter: Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout_FilterForSamplesAnd_FilterForSamplesOr.fourth(
|
|
77
|
+
PredicateWithStartAndEnd(
|
|
78
|
+
startDate: from,
|
|
79
|
+
endDate: to,
|
|
80
|
+
strictEndDate: true,
|
|
81
|
+
strictStartDate: true
|
|
82
|
+
)
|
|
83
|
+
)
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
return Promise.async {
|
|
87
|
+
try await withCheckedThrowingContinuation { continuation in
|
|
88
|
+
let query = HKCorrelationQuery(
|
|
89
|
+
type: correlationType,
|
|
90
|
+
predicate: predicate,
|
|
91
|
+
samplePredicates: nil
|
|
92
|
+
) { (_: HKCorrelationQuery, correlations: [HKCorrelation]?, error: Error?) in
|
|
93
|
+
if let error = error {
|
|
94
|
+
continuation.resume(throwing: error)
|
|
95
|
+
return
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
guard let correlations = correlations else {
|
|
99
|
+
continuation.resume(returning: [])
|
|
100
|
+
return
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Collect all quantity types to get preferred units
|
|
104
|
+
var quantityTypes = Set<HKQuantityType>()
|
|
105
|
+
for correlation in correlations {
|
|
106
|
+
for object in correlation.objects {
|
|
107
|
+
if let quantitySample = object as? HKQuantitySample {
|
|
108
|
+
quantityTypes.insert(quantitySample.quantityType)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
store.preferredUnits(for: quantityTypes) { (unitMap: [HKQuantityType: HKUnit], error: Error?) in
|
|
114
|
+
if let error = error {
|
|
115
|
+
continuation.resume(throwing: error)
|
|
116
|
+
return
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
let serializedCorrelations = correlations.map { correlation -> CorrelationSample in
|
|
120
|
+
let objects = correlation.objects.compactMap { object -> CorrelationObject? in
|
|
121
|
+
if let quantitySample = object as? HKQuantitySample,
|
|
122
|
+
let unit = unitMap[quantitySample.quantityType] {
|
|
123
|
+
do {
|
|
124
|
+
let quantitySample = try serializeQuantitySample(sample: quantitySample, unit: unit)
|
|
125
|
+
return CorrelationObject.second(quantitySample)
|
|
126
|
+
} catch {
|
|
127
|
+
print(error.localizedDescription)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
} else if let categorySample = object as? HKCategorySample {
|
|
131
|
+
return CorrelationObject.first(serializeCategorySample(sample: categorySample))
|
|
132
|
+
}
|
|
133
|
+
return nil
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return CorrelationSample(
|
|
137
|
+
correlationType: CorrelationTypeIdentifier(fromString: correlation.correlationType.identifier)!,
|
|
138
|
+
objects: objects,
|
|
139
|
+
metadata: serializeMetadata(correlation.metadata),
|
|
140
|
+
startDate: correlation.startDate,
|
|
141
|
+
endDate: correlation.endDate
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
continuation.resume(returning: serializedCorrelations)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
store.execute(query)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|