@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,357 @@
|
|
|
1
|
+
import HealthKit
|
|
2
|
+
import CoreLocation
|
|
3
|
+
import NitroModules
|
|
4
|
+
|
|
5
|
+
#if canImport(WorkoutKit)
|
|
6
|
+
import WorkoutKit
|
|
7
|
+
#endif
|
|
8
|
+
|
|
9
|
+
/*func tryParseWeatherCondition(_ weatherCondition: Int?) -> WeatherCondition? {
|
|
10
|
+
if let weatherCondition = weatherCondition {
|
|
11
|
+
return WeatherCondition.init(rawValue: Int32(weatherCondition))
|
|
12
|
+
}
|
|
13
|
+
return nil
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
func deserializeWorkoutMetadata(_ metadata: WorkoutMetadata?) -> [String: Any]? {
|
|
17
|
+
if let metadata = metadata {
|
|
18
|
+
var dict = metadata.allMetadata != nil
|
|
19
|
+
? anyMapToDictionary(metadata.allMetadata!)
|
|
20
|
+
: Dictionary<String, Any>()
|
|
21
|
+
// todo (important): hmm, not sure about the typed props here
|
|
22
|
+
// dict[""]
|
|
23
|
+
return dict
|
|
24
|
+
}
|
|
25
|
+
return nil
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
func serializeWorkoutMetadata(_ metadata: [String: Any]?) -> WorkoutMetadata? {
|
|
29
|
+
if let metadata = metadata {
|
|
30
|
+
return WorkoutMetadata(
|
|
31
|
+
// todo: figure out conversions here
|
|
32
|
+
HKWeatherCondition: tryParseWeatherCondition(metadata["HKWeatherCondition"] as? Int),
|
|
33
|
+
HKWeatherHumidity: serializeUnknownQuantityTyped(quantity: metadata["HKWeatherHumidity"] as? HKQuantity),
|
|
34
|
+
HKWeatherTemperature: serializeUnknownQuantityTyped(quantity: metadata["HKWeatherTemperature"] as? HKQuantity),
|
|
35
|
+
HKAverageMETs: serializeUnknownQuantityTyped(quantity: metadata["HKAverageMETs"] as? HKQuantity),
|
|
36
|
+
HKElevationAscended: serializeUnknownQuantityTyped(quantity: metadata["HKElevationAscended"] as? HKQuantity),
|
|
37
|
+
HKIndoorWorkout: metadata["HKIndoorWorkout"] as? Bool,
|
|
38
|
+
HKExternalUUID: metadata["HKExternalUUID"] as? String,
|
|
39
|
+
HKTimeZone: metadata["HKTimeZone"] as? String,
|
|
40
|
+
HKWasUserEntered: metadata["HKWasUserEntered"] as? Bool,
|
|
41
|
+
HKDeviceSerialNumber: metadata["HKDeviceSerialNumber"] as? String,
|
|
42
|
+
HKUDIDeviceIdentifier: metadata["HKUDIDeviceIdentifier"] as? String,
|
|
43
|
+
HKUDIProductionIdentifier: metadata["HKUDIProductionIdentifier"] as? String,
|
|
44
|
+
HKDigitalSignature: metadata["HKDigitalSignature"] as? String,
|
|
45
|
+
HKDeviceName: metadata["HKDeviceName"] as? String,
|
|
46
|
+
HKDeviceManufacturerName: metadata["HKDeviceManufacturerName"] as? String,
|
|
47
|
+
HKSyncIdentifier: metadata["HKSyncIdentifier"] as? String,
|
|
48
|
+
HKSyncVersion: metadata["HKSyncVersion"] as? Double,
|
|
49
|
+
HKWasTakenInLab: metadata["HKWasTakenInLab"] as? Bool,
|
|
50
|
+
HKReferenceRangeLowerLimit: metadata["HKReferenceRangeLowerLimit"] as? Double,
|
|
51
|
+
HKReferenceRangeUpperLimit: metadata["HKReferenceRangeUpperLimit"] as? Double,
|
|
52
|
+
allMetadata: serializeAllMetadata(metadata)
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
return nil
|
|
56
|
+
}*/
|
|
57
|
+
|
|
58
|
+
func mapLocations(from locations: [LocationForSaving]) -> [CLLocation] {
|
|
59
|
+
return locations.compactMap { location in
|
|
60
|
+
let latitude = location.latitude
|
|
61
|
+
let longitude = location.longitude
|
|
62
|
+
let altitude = location.altitude
|
|
63
|
+
let horizontalAccuracy = location.horizontalAccuracy
|
|
64
|
+
let verticalAccuracy = location.verticalAccuracy
|
|
65
|
+
let course = location.course
|
|
66
|
+
let speed = location.speed
|
|
67
|
+
let timestamp = location.date
|
|
68
|
+
|
|
69
|
+
let clLocation = CLLocation(
|
|
70
|
+
coordinate: CLLocationCoordinate2D(
|
|
71
|
+
latitude: latitude,
|
|
72
|
+
longitude: longitude
|
|
73
|
+
),
|
|
74
|
+
altitude: altitude,
|
|
75
|
+
horizontalAccuracy: horizontalAccuracy,
|
|
76
|
+
verticalAccuracy: verticalAccuracy,
|
|
77
|
+
course: course,
|
|
78
|
+
speed: speed,
|
|
79
|
+
timestamp: timestamp,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
return clLocation
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
class WorkoutsModule : HybridWorkoutsModuleSpec {
|
|
87
|
+
func queryWorkoutSamples(options: WorkoutQueryOptions) throws -> Promise<[HybridWorkoutProxySpec]> {
|
|
88
|
+
let predicate = try createPredicateForWorkout(filter: options.filter)
|
|
89
|
+
|
|
90
|
+
let limit = getQueryLimit(options.limit)
|
|
91
|
+
|
|
92
|
+
return Promise.async {
|
|
93
|
+
let energyUnit = try await getUnitToUse(unitOverride: options.energyUnit, quantityType: HKQuantityType(.activeEnergyBurned))
|
|
94
|
+
|
|
95
|
+
let distanceUnit = try await getUnitToUse(unitOverride: options.distanceUnit, quantityType: HKQuantityType(.distanceWalkingRunning))
|
|
96
|
+
|
|
97
|
+
return try await withCheckedThrowingContinuation { continuation in
|
|
98
|
+
let q = HKSampleQuery(
|
|
99
|
+
sampleType: .workoutType(),
|
|
100
|
+
predicate: predicate,
|
|
101
|
+
limit: limit,
|
|
102
|
+
sortDescriptors: getSortDescriptors(ascending: options.ascending ?? true)
|
|
103
|
+
) { (_: HKSampleQuery, samples: [HKSample]?, error: Error?) in
|
|
104
|
+
if let error = error {
|
|
105
|
+
return continuation.resume(throwing: error)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
guard let samples = samples else {
|
|
109
|
+
return continuation.resume(throwing: RuntimeError.error(withMessage: "Empty response"))
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
let workoutProxies = samples.compactMap { s in
|
|
113
|
+
if let workout = s as? HKWorkout {
|
|
114
|
+
return WorkoutProxy.init(
|
|
115
|
+
workout: workout,
|
|
116
|
+
distanceUnit: distanceUnit,
|
|
117
|
+
energyUnit: energyUnit
|
|
118
|
+
)
|
|
119
|
+
}
|
|
120
|
+
return nil
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return continuation.resume(returning: workoutProxies)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
store.execute(q)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
func saveWorkoutSample(
|
|
132
|
+
workoutActivityType: WorkoutActivityType,
|
|
133
|
+
quantities: [QuantitySampleForSaving],
|
|
134
|
+
startDate: Date,
|
|
135
|
+
endDate: Date,
|
|
136
|
+
totals: WorkoutTotals,
|
|
137
|
+
metadata: AnyMapHolder
|
|
138
|
+
) throws -> Promise<String> {
|
|
139
|
+
|
|
140
|
+
let type = try initializeWorkoutActivityType(UInt(workoutActivityType.rawValue))
|
|
141
|
+
|
|
142
|
+
// if start and end both exist, ensure that start date is before end date
|
|
143
|
+
if let startDate = startDate as Date?, let endDate = endDate as Date? {
|
|
144
|
+
if startDate > endDate {
|
|
145
|
+
throw RuntimeError.error(withMessage: "endDate must not be less than startDate")
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
let metadataDeserialized = anyMapToDictionary(metadata)
|
|
150
|
+
|
|
151
|
+
var totalEnergyBurned: HKQuantity?
|
|
152
|
+
var totalDistance: HKQuantity?
|
|
153
|
+
var totalSwimmingStrokeCount: HKQuantity?
|
|
154
|
+
var totalFlightsClimbed: HKQuantity?
|
|
155
|
+
// generating quantity samples
|
|
156
|
+
let initializedSamples = try quantities.map { quantity in
|
|
157
|
+
let type = try initializeQuantityType(quantity.quantityType.stringValue)
|
|
158
|
+
let unitStr = quantity.unit
|
|
159
|
+
let quantityVal = quantity.quantity
|
|
160
|
+
let quantityStart = quantity.startDate
|
|
161
|
+
let quantityEnd = quantity.endDate
|
|
162
|
+
let unit = HKUnit.init(from: unitStr)
|
|
163
|
+
let quantity = HKQuantity.init(unit: unit, doubleValue: quantityVal)
|
|
164
|
+
|
|
165
|
+
if quantity.is(compatibleWith: HKUnit.kilocalorie()) {
|
|
166
|
+
totalEnergyBurned = quantity
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if quantity.is(compatibleWith: HKUnit.meter()) {
|
|
170
|
+
totalDistance = quantity
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if type.identifier == HKWorkoutSortIdentifierTotalSwimmingStrokeCount {
|
|
174
|
+
totalSwimmingStrokeCount = quantity
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if type.identifier == HKWorkoutSortIdentifierTotalFlightsClimbed {
|
|
178
|
+
totalFlightsClimbed = quantity
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return HKQuantitySample.init(
|
|
182
|
+
type: type,
|
|
183
|
+
quantity: quantity,
|
|
184
|
+
start: quantityStart,
|
|
185
|
+
end: quantityEnd,
|
|
186
|
+
metadata: metadataDeserialized
|
|
187
|
+
)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// if totals are provided override samples
|
|
191
|
+
let rawTotalDistance = totals.distance ?? 0.0
|
|
192
|
+
let rawTotalEnergy = totals.energyBurned ?? 0.0
|
|
193
|
+
|
|
194
|
+
if rawTotalDistance != 0.0 {
|
|
195
|
+
totalDistance = HKQuantity(unit: .meter(), doubleValue: rawTotalDistance)
|
|
196
|
+
}
|
|
197
|
+
if rawTotalEnergy != 0.0 {
|
|
198
|
+
totalEnergyBurned = HKQuantity(unit: .kilocalorie(), doubleValue: rawTotalEnergy)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// creating workout
|
|
202
|
+
var workout: HKWorkout?
|
|
203
|
+
|
|
204
|
+
if totalSwimmingStrokeCount != nil {
|
|
205
|
+
workout = HKWorkout.init(
|
|
206
|
+
activityType: type,
|
|
207
|
+
start: startDate,
|
|
208
|
+
end: endDate,
|
|
209
|
+
workoutEvents: nil,
|
|
210
|
+
totalEnergyBurned: totalEnergyBurned,
|
|
211
|
+
totalDistance: totalDistance,
|
|
212
|
+
totalSwimmingStrokeCount: totalSwimmingStrokeCount,
|
|
213
|
+
device: nil,
|
|
214
|
+
metadata: metadataDeserialized
|
|
215
|
+
)
|
|
216
|
+
} else {
|
|
217
|
+
if #available(iOS 11, *) {
|
|
218
|
+
if totalFlightsClimbed != nil {
|
|
219
|
+
workout = HKWorkout.init(
|
|
220
|
+
activityType: type,
|
|
221
|
+
start: startDate,
|
|
222
|
+
end: endDate,
|
|
223
|
+
workoutEvents: nil,
|
|
224
|
+
totalEnergyBurned: totalEnergyBurned,
|
|
225
|
+
totalDistance: totalDistance,
|
|
226
|
+
totalFlightsClimbed: totalFlightsClimbed,
|
|
227
|
+
device: nil,
|
|
228
|
+
metadata: metadataDeserialized
|
|
229
|
+
)
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if workout == nil {
|
|
235
|
+
workout = HKWorkout.init(
|
|
236
|
+
activityType: type,
|
|
237
|
+
start: startDate,
|
|
238
|
+
end: endDate,
|
|
239
|
+
workoutEvents: nil,
|
|
240
|
+
totalEnergyBurned: totalEnergyBurned,
|
|
241
|
+
totalDistance: totalDistance,
|
|
242
|
+
metadata: metadataDeserialized
|
|
243
|
+
)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
guard let workout = workout else {
|
|
247
|
+
throw RuntimeError.error(withMessage: "Could not create workout")
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return Promise.async {
|
|
251
|
+
try await withCheckedThrowingContinuation { continuation in
|
|
252
|
+
// saving workout, samples and route
|
|
253
|
+
store.save(workout) { (_: Bool, error: Error?) in
|
|
254
|
+
if let error = error {
|
|
255
|
+
return continuation.resume(throwing: error)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if initializedSamples.isEmpty {
|
|
259
|
+
return continuation.resume(returning: workout.uuid.uuidString)
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
store.add(initializedSamples, to: workout) { (_, error: Error?) in
|
|
263
|
+
if let error = error {
|
|
264
|
+
return continuation.resume(throwing: error)
|
|
265
|
+
}
|
|
266
|
+
return continuation.resume(returning: workout.uuid.uuidString)
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
func startWatchAppWithWorkoutConfiguration(workoutConfiguration: WorkoutConfiguration) -> Promise<Bool>
|
|
275
|
+
{
|
|
276
|
+
let configuration = parseWorkoutConfiguration(workoutConfiguration)
|
|
277
|
+
|
|
278
|
+
return Promise.async {
|
|
279
|
+
try await withCheckedThrowingContinuation { continuation in
|
|
280
|
+
store.startWatchApp(with: configuration) { success, error in
|
|
281
|
+
if let error {
|
|
282
|
+
continuation.resume(throwing: error)
|
|
283
|
+
} else {
|
|
284
|
+
continuation.resume(returning: success)
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
func queryWorkoutSamplesWithAnchor(options: WorkoutQueryOptionsWithAnchor) throws -> Promise<QueryWorkoutSamplesWithAnchorResponse> {
|
|
292
|
+
let predicate = try createPredicateForWorkout(filter: options.filter)
|
|
293
|
+
|
|
294
|
+
let limit = getQueryLimit(options.limit)
|
|
295
|
+
|
|
296
|
+
let actualAnchor = try deserializeHKQueryAnchor(base64String: options.anchor)
|
|
297
|
+
|
|
298
|
+
return Promise.async {
|
|
299
|
+
let energyUnit = try await getUnitToUse(unitOverride: options.energyUnit, quantityType: HKQuantityType(.activeEnergyBurned))
|
|
300
|
+
|
|
301
|
+
let distanceUnit = try await getUnitToUse(unitOverride: options.energyUnit, quantityType: HKQuantityType(.distanceWalkingRunning))
|
|
302
|
+
|
|
303
|
+
return try await withCheckedThrowingContinuation { continuation in
|
|
304
|
+
let q = HKAnchoredObjectQuery(
|
|
305
|
+
type: .workoutType(),
|
|
306
|
+
predicate: predicate,
|
|
307
|
+
anchor: actualAnchor,
|
|
308
|
+
limit: limit
|
|
309
|
+
) {
|
|
310
|
+
(
|
|
311
|
+
_: HKAnchoredObjectQuery,
|
|
312
|
+
s: [HKSample]?,
|
|
313
|
+
deletedSamples: [HKDeletedObject]?,
|
|
314
|
+
newAnchor: HKQueryAnchor?,
|
|
315
|
+
error: Error?
|
|
316
|
+
) in
|
|
317
|
+
if let error = error {
|
|
318
|
+
return continuation.resume(throwing: error)
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
guard let samples = s, let newAnchor = newAnchor else {
|
|
322
|
+
return continuation.resume(
|
|
323
|
+
throwing: RuntimeError.error(
|
|
324
|
+
withMessage: "Empty response"
|
|
325
|
+
)
|
|
326
|
+
)
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
let workoutProxies = samples.compactMap { s in
|
|
330
|
+
if let workout = s as? HKWorkout {
|
|
331
|
+
return WorkoutProxy.init(
|
|
332
|
+
workout: workout,
|
|
333
|
+
distanceUnit: distanceUnit,
|
|
334
|
+
energyUnit: energyUnit
|
|
335
|
+
)
|
|
336
|
+
}
|
|
337
|
+
return nil
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
let deletedSamples = deletedSamples?.map({ sample in
|
|
341
|
+
return serializeDeletedSample(sample: sample)
|
|
342
|
+
}) ?? []
|
|
343
|
+
|
|
344
|
+
let returnValue = QueryWorkoutSamplesWithAnchorResponse(
|
|
345
|
+
workouts: workoutProxies,
|
|
346
|
+
deletedSamples: deletedSamples,
|
|
347
|
+
newAnchor: serializeAnchor(anchor: newAnchor)!
|
|
348
|
+
)
|
|
349
|
+
|
|
350
|
+
return continuation.resume(returning: returnValue)
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
store.execute(q)
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
package/package.json
CHANGED
|
@@ -1,152 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kingstinct/react-native-healthkit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "React Native bindings for HealthKit",
|
|
5
|
-
"main": "lib/
|
|
6
|
-
"module": "lib/
|
|
7
|
-
"types": "lib/
|
|
5
|
+
"main": "lib/index",
|
|
6
|
+
"module": "lib/index",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
8
|
"react-native": "src/index",
|
|
9
9
|
"source": "src/index",
|
|
10
10
|
"files": [
|
|
11
11
|
"src",
|
|
12
|
+
"react-native.config.js",
|
|
12
13
|
"lib",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
14
|
+
"nitrogen/**/*",
|
|
15
|
+
"android/build.gradle",
|
|
16
|
+
"android/gradle.properties",
|
|
17
|
+
"android/CMakeLists.txt",
|
|
18
|
+
"android/src",
|
|
19
|
+
"ios/**/*.h",
|
|
20
|
+
"ios/**/*.m",
|
|
21
|
+
"ios/**/*.mm",
|
|
22
|
+
"ios/**/*.cpp",
|
|
23
|
+
"ios/**/*.swift",
|
|
24
|
+
"app.plugin.js",
|
|
25
|
+
"*.podspec",
|
|
26
|
+
"README.md"
|
|
21
27
|
],
|
|
22
28
|
"scripts": {
|
|
23
|
-
"test-only": "bun test --preload ./src/test-setup.ts src",
|
|
24
|
-
"test": "concurrently \"bun test-only\" \"bun typecheck\" \"bun lint\"",
|
|
25
29
|
"typecheck": "tsc --noEmit",
|
|
26
|
-
"lint": "
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"bootstrap": "cd example && bun install && bun pods",
|
|
31
|
-
"upgrade-interactive": "bunx npm-check-updates --format group -i"
|
|
30
|
+
"lint": "bunx @biomejs/biome format --write",
|
|
31
|
+
"typescript": "tsc",
|
|
32
|
+
"codegen": "tsc && nitro-codegen --logLevel=\"debug\"",
|
|
33
|
+
"test": "bun test"
|
|
32
34
|
},
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"*.json": "eslint --fix"
|
|
35
|
+
"keywords": ["react-native", "nitro", "healthkit", "ios", "typescript"],
|
|
36
|
+
"funding": {
|
|
37
|
+
"type": "github",
|
|
38
|
+
"url": "https://github.com/sponsors/kingstinct"
|
|
38
39
|
},
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"healthkit",
|
|
43
|
-
"typescript",
|
|
44
|
-
"react-hooks"
|
|
45
|
-
],
|
|
46
|
-
"repository": "https://github.com/kingstinct/react-native-healthkit",
|
|
47
|
-
"funding": [
|
|
48
|
-
"https://github.com/sponsors/kingstinct",
|
|
49
|
-
"https://github.com/sponsors/robertherber"
|
|
50
|
-
],
|
|
51
|
-
"author": {
|
|
52
|
-
"name": "Robert Herber",
|
|
53
|
-
"email": "robert@kingstinct.com",
|
|
54
|
-
"url": "https://github.com/robertherber"
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/kingstinct/react-native-healthkit.git"
|
|
55
43
|
},
|
|
44
|
+
"author": "Robert Herber <robert@kingstinct.com> (https://github.com/robertherber)",
|
|
56
45
|
"license": "MIT",
|
|
57
46
|
"bugs": {
|
|
58
47
|
"url": "https://github.com/kingstinct/react-native-healthkit/issues"
|
|
59
48
|
},
|
|
60
49
|
"homepage": "https://github.com/kingstinct/react-native-healthkit#readme",
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"registry": "https://registry.npmjs.org/",
|
|
52
|
+
"access": "public"
|
|
53
|
+
},
|
|
61
54
|
"devDependencies": {
|
|
62
|
-
"@
|
|
63
|
-
"@
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"@types/bun": "^1.1.3",
|
|
70
|
-
"@types/node": "^18.7.14",
|
|
71
|
-
"@types/react": "~18.0.27",
|
|
72
|
-
"@typescript-eslint/eslint-plugin": "7",
|
|
73
|
-
"@typescript-eslint/parser": "7",
|
|
74
|
-
"commitlint": "^17.1.1",
|
|
75
|
-
"concurrently": "8",
|
|
76
|
-
"eslint": "8",
|
|
77
|
-
"eslint-config-airbnb": "19",
|
|
78
|
-
"eslint-config-airbnb-base": "15",
|
|
79
|
-
"eslint-config-kingstinct": "^5.1.1",
|
|
80
|
-
"eslint-import-resolver-typescript": "3",
|
|
81
|
-
"eslint-plugin-comment-length": "0",
|
|
82
|
-
"eslint-plugin-functional": "4",
|
|
83
|
-
"eslint-plugin-import": "2",
|
|
84
|
-
"eslint-plugin-jest": "26",
|
|
85
|
-
"eslint-plugin-jsonc": "2",
|
|
86
|
-
"eslint-plugin-jsx-a11y": "6",
|
|
87
|
-
"eslint-plugin-react": "7",
|
|
88
|
-
"eslint-plugin-react-hooks": "4",
|
|
89
|
-
"eslint-plugin-react-native": "4",
|
|
90
|
-
"eslint-plugin-react-native-a11y": "3",
|
|
91
|
-
"eslint-plugin-unicorn": "50",
|
|
92
|
-
"eslint-plugin-yml": "1",
|
|
93
|
-
"expo": ">=45",
|
|
94
|
-
"graphql": ">=16",
|
|
95
|
-
"husky": "8",
|
|
96
|
-
"lint-staged": "^13.2.2",
|
|
97
|
-
"metro-react-native-babel-preset": "^0.70.3",
|
|
98
|
-
"pod-install": "^0.1.0",
|
|
99
|
-
"react": "18.2.0",
|
|
100
|
-
"react-native": "0.71.8",
|
|
101
|
-
"react-native-builder-bob": "^0.18.1",
|
|
102
|
-
"react-test-renderer": "18",
|
|
103
|
-
"release-it": "14",
|
|
104
|
-
"solidarity": "^3.0.4",
|
|
105
|
-
"solidarity-react-native": "^2.1.2",
|
|
106
|
-
"typescript": "^5.8.3"
|
|
55
|
+
"@testing-library/react-native": "^13.2.0",
|
|
56
|
+
"@types/react": "~19.0.14",
|
|
57
|
+
"nitro-codegen": "^0.26.2",
|
|
58
|
+
"react": "19.0.0",
|
|
59
|
+
"react-native": "^0.79.3",
|
|
60
|
+
"react-native-nitro-modules": "^0.26.2",
|
|
61
|
+
"typescript": "~5.8.3"
|
|
107
62
|
},
|
|
108
63
|
"peerDependencies": {
|
|
109
64
|
"react": "*",
|
|
110
|
-
"react-native": "*"
|
|
111
|
-
|
|
112
|
-
"commitlint": {
|
|
113
|
-
"extends": [
|
|
114
|
-
"@commitlint/config-conventional"
|
|
115
|
-
]
|
|
116
|
-
},
|
|
117
|
-
"publishConfig": {
|
|
118
|
-
"access": "public",
|
|
119
|
-
"registry": "https://registry.npmjs.org/"
|
|
120
|
-
},
|
|
121
|
-
"release-it": {
|
|
122
|
-
"git": {
|
|
123
|
-
"commitMessage": "chore: release ${version}",
|
|
124
|
-
"tagName": "v${version}"
|
|
125
|
-
},
|
|
126
|
-
"npm": {
|
|
127
|
-
"publish": true
|
|
128
|
-
},
|
|
129
|
-
"github": {
|
|
130
|
-
"release": true
|
|
131
|
-
},
|
|
132
|
-
"plugins": {
|
|
133
|
-
"@release-it/conventional-changelog": {
|
|
134
|
-
"preset": "angular",
|
|
135
|
-
"infile": "CHANGELOG.md"
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
"eslintIgnore": [
|
|
140
|
-
"node_modules/",
|
|
141
|
-
"lib/"
|
|
142
|
-
],
|
|
143
|
-
"react-native-builder-bob": {
|
|
144
|
-
"source": "src",
|
|
145
|
-
"output": "lib",
|
|
146
|
-
"targets": [
|
|
147
|
-
"commonjs",
|
|
148
|
-
"module",
|
|
149
|
-
"typescript"
|
|
150
|
-
]
|
|
65
|
+
"react-native": "*",
|
|
66
|
+
"react-native-nitro-modules": "*"
|
|
151
67
|
}
|
|
152
68
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// https://github.com/react-native-community/cli/blob/main/docs/dependencies.md
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
dependency: {
|
|
5
|
+
platforms: {
|
|
6
|
+
/**
|
|
7
|
+
* @type {import('@react-native-community/cli-types').IOSDependencyParams}
|
|
8
|
+
*/
|
|
9
|
+
ios: {},
|
|
10
|
+
/**
|
|
11
|
+
* @type {import('@react-native-community/cli-types').AndroidDependencyParams}
|
|
12
|
+
*/
|
|
13
|
+
android: {},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
}
|
|
@@ -1,65 +1,83 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { beforeAll, describe, expect, jest, test } from 'bun:test'
|
|
2
2
|
|
|
3
|
+
import { act, renderHook } from '@testing-library/react-native'
|
|
4
|
+
|
|
5
|
+
import { Core } from '../modules'
|
|
3
6
|
import waitForNextUpdate from '../test-utils'
|
|
7
|
+
import { AuthorizationRequestStatus } from '../types/Auth'
|
|
8
|
+
import type UseHealthkitAuthorization from './useHealthkitAuthorization'
|
|
4
9
|
|
|
5
10
|
describe('useHealthkitAuthorization', () => {
|
|
6
|
-
let
|
|
7
|
-
|
|
11
|
+
let useHealthkitAuthorization: typeof UseHealthkitAuthorization
|
|
12
|
+
|
|
8
13
|
beforeAll(async () => {
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
useHealthkitAuthorization = (await import('./useHealthkitAuthorization'))
|
|
15
|
+
.default
|
|
11
16
|
})
|
|
12
17
|
|
|
13
18
|
test('should return shouldRequest', async () => {
|
|
14
|
-
|
|
19
|
+
jest
|
|
20
|
+
.spyOn(Core, 'getRequestStatusForAuthorization')
|
|
21
|
+
.mockReturnValue(
|
|
22
|
+
Promise.resolve(AuthorizationRequestStatus.shouldRequest),
|
|
23
|
+
)
|
|
15
24
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
25
|
+
const { result } = renderHook(() =>
|
|
26
|
+
useHealthkitAuthorization(['HKCategoryTypeIdentifierAbdominalCramps']),
|
|
27
|
+
)
|
|
19
28
|
|
|
20
29
|
await waitForNextUpdate()
|
|
21
30
|
|
|
22
|
-
expect(result.current[0]).toBe(
|
|
31
|
+
expect(result.current[0]).toBe(AuthorizationRequestStatus.shouldRequest)
|
|
23
32
|
})
|
|
24
33
|
|
|
25
34
|
test('should request permissions', async () => {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
const spy = jest
|
|
36
|
+
.spyOn(Core, 'getRequestStatusForAuthorization')
|
|
37
|
+
.mockReturnValue(
|
|
38
|
+
Promise.resolve(AuthorizationRequestStatus.shouldRequest),
|
|
39
|
+
)
|
|
40
|
+
jest
|
|
41
|
+
.spyOn(Core, 'requestAuthorization')
|
|
42
|
+
.mockReturnValue(Promise.resolve(true))
|
|
43
|
+
|
|
44
|
+
const { result } = renderHook(() =>
|
|
45
|
+
useHealthkitAuthorization(['HKCategoryTypeIdentifierAbdominalCramps']),
|
|
46
|
+
)
|
|
32
47
|
|
|
33
48
|
await waitForNextUpdate()
|
|
34
49
|
|
|
35
|
-
spy.mockReturnValue(Promise.resolve(
|
|
50
|
+
spy.mockReturnValue(Promise.resolve(AuthorizationRequestStatus.unnecessary))
|
|
36
51
|
|
|
37
|
-
let retVal:
|
|
52
|
+
let retVal: AuthorizationRequestStatus | undefined
|
|
38
53
|
await act(async () => {
|
|
39
|
-
const r =
|
|
54
|
+
const r =
|
|
55
|
+
(await result.current[1]()) as unknown as AuthorizationRequestStatus
|
|
40
56
|
retVal = r
|
|
41
57
|
})
|
|
42
58
|
|
|
43
|
-
expect(result.current[0]).toBe(
|
|
44
|
-
expect(retVal).toBe(
|
|
59
|
+
expect(result.current[0]).toBe(AuthorizationRequestStatus.unnecessary)
|
|
60
|
+
expect(retVal).toBe(AuthorizationRequestStatus.unnecessary)
|
|
45
61
|
})
|
|
46
62
|
|
|
47
63
|
test('should return unnecessary', async () => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
64
|
+
jest
|
|
65
|
+
.spyOn(Core, 'getRequestStatusForAuthorization')
|
|
66
|
+
.mockReturnValue(Promise.resolve(AuthorizationRequestStatus.unnecessary))
|
|
51
67
|
|
|
52
|
-
const { result } = renderHook(() =>
|
|
68
|
+
const { result } = renderHook(() =>
|
|
69
|
+
useHealthkitAuthorization(['HKCategoryTypeIdentifierAbdominalCramps']),
|
|
70
|
+
)
|
|
53
71
|
|
|
54
72
|
await waitForNextUpdate()
|
|
55
73
|
|
|
56
|
-
expect(result.current[0]).toBe(
|
|
74
|
+
expect(result.current[0]).toBe(AuthorizationRequestStatus.unnecessary)
|
|
57
75
|
})
|
|
58
76
|
|
|
59
77
|
test('should return null before initalizing', async () => {
|
|
60
|
-
const {
|
|
61
|
-
|
|
62
|
-
|
|
78
|
+
const { result } = renderHook(() =>
|
|
79
|
+
useHealthkitAuthorization(['HKCategoryTypeIdentifierAbdominalCramps']),
|
|
80
|
+
)
|
|
63
81
|
|
|
64
82
|
expect(result.current[0]).toBe(null)
|
|
65
83
|
|